"use client" import type React from "react" import { useEffect, useRef, useState } from "react" import Link from "next/link" type Tool = "select" | "draw" | "erase" | "rectangle" | "text" | "arrow" interface Shape { id: string type: "rectangle" | "ellipse" | "line" | "text" x: number y: number width?: number height?: number x2?: number y2?: number text?: string color: string } export default function ItalismPage() { const canvasRef = useRef(null) const [tool, setTool] = useState("select") const [shapes, setShapes] = useState([ { id: "1", type: "rectangle", x: 100, y: 100, width: 750, height: 50, color: "#6366f1", text: "Digital Liberation", }, { id: "2", type: "rectangle", x: 360, y: 180, width: 480, height: 50, color: "#6366f1", text: "Post-Appitalism" }, { id: "3", type: "rectangle", x: 50, y: 340, width: 1110, height: 50, color: "#10b981", text: "Collaborative Economy", }, { id: "4", type: "ellipse", x: 270, y: 430, width: 1020, height: 40, color: "#10b981", text: "Decentralized" }, { id: "5", type: "ellipse", x: 310, y: 530, width: 1110, height: 40, color: "#10b981", text: "Future" }, { id: "6", type: "rectangle", x: 80, y: 605, width: 1110, height: 50, color: "#6366f1", text: "Community" }, { id: "7", type: "rectangle", x: 290, y: 710, width: 630, height: 50, color: "#8b5cf6", text: "Innovation" }, ]) const [isDrawing, setIsDrawing] = useState(false) const [currentShape, setCurrentShape] = useState | null>(null) const [selectedShape, setSelectedShape] = useState(null) const [isFullscreen, setIsFullscreen] = useState(false) useEffect(() => { const canvas = canvasRef.current if (!canvas) return const ctx = canvas.getContext("2d") if (!ctx) return // Set canvas size canvas.width = canvas.offsetWidth canvas.height = canvas.offsetHeight // Clear canvas ctx.fillStyle = "#0f172a" ctx.fillRect(0, 0, canvas.width, canvas.height) // Draw shapes shapes.forEach((shape) => { ctx.strokeStyle = shape.color ctx.lineWidth = 2 ctx.fillStyle = shape.color ctx.font = "16px sans-serif" if (shape.type === "rectangle" && shape.width && shape.height) { ctx.strokeRect(shape.x, shape.y, shape.width, shape.height) if (shape.text) { ctx.fillText(shape.text, shape.x + 10, shape.y + shape.height / 2 + 5) } } else if (shape.type === "ellipse" && shape.width && shape.height) { ctx.beginPath() ctx.ellipse( shape.x + shape.width / 2, shape.y + shape.height / 2, shape.width / 2, shape.height / 2, 0, 0, 2 * Math.PI, ) ctx.stroke() if (shape.text) { ctx.fillText(shape.text, shape.x + shape.width / 2 - 50, shape.y + shape.height / 2 + 5) } } else if (shape.type === "line" && shape.x2 && shape.y2) { ctx.beginPath() ctx.moveTo(shape.x, shape.y) ctx.lineTo(shape.x2, shape.y2) ctx.stroke() } // Highlight selected shape if (selectedShape === shape.id && shape.width && shape.height) { ctx.strokeStyle = "#22d3ee" ctx.lineWidth = 3 ctx.strokeRect(shape.x - 5, shape.y - 5, shape.width + 10, shape.height + 10) } }) }, [shapes, selectedShape]) const handleMouseDown = (e: React.MouseEvent) => { const canvas = canvasRef.current if (!canvas) return const rect = canvas.getBoundingClientRect() const x = e.clientX - rect.left const y = e.clientY - rect.top if (tool === "select") { // Find clicked shape const clicked = shapes.find((shape) => { if (shape.width && shape.height) { return x >= shape.x && x <= shape.x + shape.width && y >= shape.y && y <= shape.y + shape.height } return false }) setSelectedShape(clicked?.id || null) } else if (tool === "draw" || tool === "rectangle") { setIsDrawing(true) setCurrentShape({ id: Date.now().toString(), type: tool === "rectangle" ? "rectangle" : "line", x, y, color: "#6366f1", }) } } const handleMouseMove = (e: React.MouseEvent) => { if (!isDrawing || !currentShape) return const canvas = canvasRef.current if (!canvas) return const rect = canvas.getBoundingClientRect() const x = e.clientX - rect.left const y = e.clientY - rect.top if (currentShape.type === "rectangle") { setCurrentShape({ ...currentShape, width: x - (currentShape.x || 0), height: y - (currentShape.y || 0), }) } else if (currentShape.type === "line") { setCurrentShape({ ...currentShape, x2: x, y2: y, }) } } const handleMouseUp = () => { if (isDrawing && currentShape) { setShapes([...shapes, currentShape as Shape]) setCurrentShape(null) } setIsDrawing(false) } const toggleFullscreen = () => { if (!document.fullscreenElement) { document.documentElement.requestFullscreen() setIsFullscreen(true) } else { document.exitFullscreen() setIsFullscreen(false) } } return (
{/* Header */}

Interactive Canvas

← Back to Home
{/* Main Content */}
{/* Canvas */}
{currentShape && (
Drawing {currentShape.type}...
)}
{/* Sidebar */}

FolkJS Canvas

  • • Use toolbar to draw and create shapes
  • • Click and drag to move elements
  • • Double-click text to edit
  • • Use select tool to interact
  • • Press Space for{" "} fullscreen
{/* Toolbar */}

Tools

{[ { id: "select", label: "Select" }, { id: "draw", label: "Draw" }, { id: "erase", label: "Erase" }, { id: "rectangle", label: "Rectangle" }, { id: "text", label: "Text" }, { id: "arrow", label: "Arrow" }, ].map((t) => ( ))}
{/* Actions */}
) }