@particle-academy/fancy-3d 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
- var jsxRuntime = require('react/jsx-runtime');
3
+ var chunkIU7B7Y63_cjs = require('./chunk-IU7B7Y63.cjs');
4
+ var chunkPBKOUAUY_cjs = require('./chunk-PBKOUAUY.cjs');
5
5
 
6
6
  // src/scene.ts
7
7
  var _seq = 1e3;
@@ -13,746 +13,567 @@ function renderScene(scene, adapter, ctxFor) {
13
13
  return scene.nodes.map((node) => ({ node, rendered: adapter.render(node.widget, ctxFor(node)) }));
14
14
  }
15
15
 
16
- // src/utils/cn.ts
17
- function flatten(value) {
18
- if (!value) return "";
19
- if (typeof value === "string" || typeof value === "number") return String(value);
20
- if (Array.isArray(value)) return value.map(flatten).filter(Boolean).join(" ");
21
- if (typeof value === "object") {
22
- return Object.entries(value).filter(([, v]) => Boolean(v)).map(([k]) => k).join(" ");
16
+ // src/theme.ts
17
+ var SCENE_PALETTES = {
18
+ light: {
19
+ canvas: "#fafafa",
20
+ grid: "rgba(161, 161, 170, 0.3)",
21
+ card: "#ffffff",
22
+ cardBorder: "#e4e4e7",
23
+ edge: "#d4d4d8",
24
+ text: "#18181b",
25
+ body: "#3f3f46",
26
+ muted: "#71717a",
27
+ subtle: "#f4f4f5",
28
+ accent: "#6366f1",
29
+ onAccent: "#ffffff",
30
+ avatar: "#e4e4e7",
31
+ avatarText: "#3f3f46",
32
+ success: "#059669",
33
+ warning: "#d97706",
34
+ danger: "#e11d48",
35
+ info: "#2563eb",
36
+ code: "#18181b",
37
+ codeText: "#f4f4f5"
38
+ },
39
+ dark: {
40
+ canvas: "#09090b",
41
+ grid: "rgba(161, 161, 170, 0.3)",
42
+ card: "#18181b",
43
+ cardBorder: "#3f3f46",
44
+ edge: "#27272a",
45
+ text: "#f4f4f5",
46
+ body: "#d4d4d8",
47
+ muted: "#a1a1aa",
48
+ subtle: "#27272a",
49
+ accent: "#818cf8",
50
+ onAccent: "#ffffff",
51
+ avatar: "#3f3f46",
52
+ avatarText: "#e4e4e7",
53
+ success: "#10b981",
54
+ warning: "#f59e0b",
55
+ danger: "#f43f5e",
56
+ info: "#60a5fa",
57
+ code: "#09090b",
58
+ codeText: "#f4f4f5"
23
59
  }
24
- return "";
60
+ };
61
+ var DARK_THEME_SELECTOR = '.dark, [data-theme="dark"]';
62
+ function resolveSceneTheme(theme, el) {
63
+ if (theme === "light" || theme === "dark") return theme;
64
+ const start = el ?? (typeof document !== "undefined" ? document.documentElement : null);
65
+ if (!start) return "light";
66
+ return start.closest(DARK_THEME_SELECTOR) ? "dark" : "light";
25
67
  }
26
- function cn(...inputs) {
27
- return inputs.map(flatten).filter(Boolean).join(" ");
68
+ function scenePalette(theme, el) {
69
+ return SCENE_PALETTES[resolveSceneTheme(theme, el)];
28
70
  }
29
- function useControllableState(controlledValue, defaultValue, onChange) {
30
- const [uncontrolledValue, setUncontrolledValue] = react.useState(defaultValue);
31
- const isControlled = controlledValue !== void 0;
32
- const value = isControlled ? controlledValue : uncontrolledValue;
33
- const onChangeRef = react.useRef(onChange);
34
- onChangeRef.current = onChange;
35
- const setValue = react.useCallback(
36
- (next) => {
37
- const nextValue = typeof next === "function" ? next(value) : next;
38
- if (!isControlled) {
39
- setUncontrolledValue(nextValue);
40
- }
41
- onChangeRef.current?.(nextValue);
42
- },
43
- [isControlled, value]
44
- );
45
- return [value, setValue];
71
+
72
+ // src/paint.ts
73
+ var SANS = "ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif";
74
+ var MONO = "ui-monospace, SFMono-Regular, Menlo, monospace";
75
+ var PAD = 16;
76
+ var RADIUS = 12;
77
+ function font(weight, px, family = SANS) {
78
+ return `${weight} ${px}px ${family}`;
46
79
  }
47
- function usePanZoom({
48
- viewport,
49
- setViewport,
50
- minZoom,
51
- maxZoom,
52
- pannable,
53
- zoomable,
54
- containerRef
55
- }) {
56
- const isPanningRef = react.useRef(false);
57
- const startRef = react.useRef({ x: 0, y: 0, panX: 0, panY: 0 });
58
- const viewportRef = react.useRef(viewport);
59
- viewportRef.current = viewport;
60
- const setViewportRef = react.useRef(setViewport);
61
- setViewportRef.current = setViewport;
62
- const zoomableRef = react.useRef(zoomable);
63
- zoomableRef.current = zoomable;
64
- const minZoomRef = react.useRef(minZoom);
65
- minZoomRef.current = minZoom;
66
- const maxZoomRef = react.useRef(maxZoom);
67
- maxZoomRef.current = maxZoom;
68
- react.useEffect(() => {
69
- const container = containerRef.current;
70
- if (!container) return;
71
- function handleWheel(e) {
72
- if (!zoomableRef.current) return;
73
- if (!e.ctrlKey && !e.metaKey) return;
74
- e.preventDefault();
75
- const rect = container.getBoundingClientRect();
76
- const mouseX = e.clientX - rect.left;
77
- const mouseY = e.clientY - rect.top;
78
- setViewportRef.current((prev) => {
79
- const factor = 1 - e.deltaY * 1e-3;
80
- const newZoom = Math.min(maxZoomRef.current, Math.max(minZoomRef.current, prev.zoom * factor));
81
- const ratio = newZoom / prev.zoom;
82
- return {
83
- zoom: newZoom,
84
- panX: mouseX - (mouseX - prev.panX) * ratio,
85
- panY: mouseY - (mouseY - prev.panY) * ratio
86
- };
87
- });
88
- }
89
- container.addEventListener("wheel", handleWheel, { passive: false });
90
- return () => {
91
- container.removeEventListener("wheel", handleWheel);
92
- };
93
- }, [containerRef]);
94
- const onPointerDown = react.useCallback(
95
- (e) => {
96
- if (!pannable) return;
97
- if (e.button !== 0) return;
98
- const target = e.target;
99
- if (target !== containerRef.current && !target.hasAttribute("data-canvas-bg")) return;
100
- isPanningRef.current = true;
101
- startRef.current = { x: e.clientX, y: e.clientY, panX: viewport.panX, panY: viewport.panY };
102
- e.target.setPointerCapture(e.pointerId);
103
- e.preventDefault();
104
- },
105
- [pannable, viewport.panX, viewport.panY, containerRef]
106
- );
107
- const onPointerMove = react.useCallback(
108
- (e) => {
109
- if (!isPanningRef.current) return;
110
- const dx = e.clientX - startRef.current.x;
111
- const dy = e.clientY - startRef.current.y;
112
- setViewport((prev) => ({
113
- ...prev,
114
- panX: startRef.current.panX + dx,
115
- panY: startRef.current.panY + dy
116
- }));
117
- },
118
- [setViewport]
119
- );
120
- const onPointerUp = react.useCallback(() => {
121
- isPanningRef.current = false;
122
- }, []);
123
- return {
124
- containerProps: { onPointerDown, onPointerMove, onPointerUp },
125
- isPanning: isPanningRef.current
126
- };
80
+ function roundRect(ctx, x, y, w, h, r) {
81
+ const rr = Math.max(0, Math.min(r, w / 2, h / 2));
82
+ ctx.beginPath();
83
+ ctx.moveTo(x + rr, y);
84
+ ctx.arcTo(x + w, y, x + w, y + h, rr);
85
+ ctx.arcTo(x + w, y + h, x, y + h, rr);
86
+ ctx.arcTo(x, y + h, x, y, rr);
87
+ ctx.arcTo(x, y, x + w, y, rr);
88
+ ctx.closePath();
127
89
  }
128
- function useNodeRegistry() {
129
- const rectsRef = react.useRef(/* @__PURE__ */ new Map());
130
- const [version, setVersion] = react.useState(0);
131
- const registerNode = react.useCallback((id, rect) => {
132
- rectsRef.current.set(id, rect);
133
- setVersion((v) => v + 1);
134
- }, []);
135
- const unregisterNode = react.useCallback((id) => {
136
- rectsRef.current.delete(id);
137
- setVersion((v) => v + 1);
138
- }, []);
139
- return { registerNode, unregisterNode, nodeRects: rectsRef.current, version };
90
+ function paintCard(ctx, w, h, p, selected) {
91
+ roundRect(ctx, 0.5, 0.5, w - 1, h - 1, RADIUS);
92
+ ctx.fillStyle = p.card;
93
+ ctx.fill();
94
+ ctx.strokeStyle = selected ? p.accent : p.cardBorder;
95
+ ctx.lineWidth = selected ? 2 : 1;
96
+ ctx.stroke();
140
97
  }
141
- var CanvasContext = react.createContext(null);
142
- function useCanvas() {
143
- const ctx = react.useContext(CanvasContext);
144
- if (!ctx) throw new Error("useCanvas must be used within a Canvas component");
145
- return ctx;
98
+ function paintLabel(ctx, text, x, y, p) {
99
+ ctx.fillStyle = p.muted;
100
+ ctx.font = font(500, 12);
101
+ ctx.textBaseline = "top";
102
+ ctx.fillText(text.toUpperCase(), x, y);
146
103
  }
147
- function CanvasNode({ children, id, x, y, draggable, onPositionChange, className, style }) {
148
- const { registerNode, unregisterNode, viewport, gridSize, snapToGrid } = useCanvas();
149
- const nodeRef = react.useRef(null);
150
- const isDragging = react.useRef(false);
151
- const dragStart = react.useRef({ mouseX: 0, mouseY: 0, nodeX: 0, nodeY: 0 });
152
- react.useEffect(() => {
153
- const el = nodeRef.current;
154
- if (!el) return;
155
- const updateRect = () => {
156
- registerNode(id, { x, y, width: el.offsetWidth, height: el.offsetHeight });
157
- };
158
- updateRect();
159
- const observer = new ResizeObserver(updateRect);
160
- observer.observe(el);
161
- return () => {
162
- observer.disconnect();
163
- unregisterNode(id);
164
- };
165
- }, [id, x, y, registerNode, unregisterNode]);
166
- const handlePointerDown = react.useCallback(
167
- (e) => {
168
- if (!draggable || e.button !== 0) return;
169
- e.stopPropagation();
170
- isDragging.current = true;
171
- dragStart.current = { mouseX: e.clientX, mouseY: e.clientY, nodeX: x, nodeY: y };
172
- e.target.setPointerCapture(e.pointerId);
173
- },
174
- [draggable, x, y]
175
- );
176
- const handlePointerMove = react.useCallback(
177
- (e) => {
178
- if (!isDragging.current) return;
179
- const dx = (e.clientX - dragStart.current.mouseX) / viewport.zoom;
180
- const dy = (e.clientY - dragStart.current.mouseY) / viewport.zoom;
181
- let nx = dragStart.current.nodeX + dx;
182
- let ny = dragStart.current.nodeY + dy;
183
- if (snapToGrid && gridSize > 0) {
184
- nx = Math.round(nx / gridSize) * gridSize;
185
- ny = Math.round(ny / gridSize) * gridSize;
186
- }
187
- onPositionChange?.(nx, ny);
188
- },
189
- [viewport.zoom, onPositionChange, snapToGrid, gridSize]
190
- );
191
- const handlePointerUp = react.useCallback(() => {
192
- isDragging.current = false;
193
- }, []);
194
- return /* @__PURE__ */ jsxRuntime.jsx(
195
- "div",
196
- {
197
- ref: nodeRef,
198
- "data-react-fancy-canvas-node": "",
199
- "data-node-id": id,
200
- className: cn("absolute", draggable && "cursor-grab active:cursor-grabbing", className),
201
- style: { left: x, top: y, ...style },
202
- onPointerDown: handlePointerDown,
203
- onPointerMove: handlePointerMove,
204
- onPointerUp: handlePointerUp,
205
- children
206
- }
207
- );
104
+ function withAlpha(hex, alpha) {
105
+ const m = /^#([0-9a-f]{6})$/i.exec(hex);
106
+ if (!m) return hex;
107
+ const n = parseInt(m[1], 16);
108
+ return `rgba(${n >> 16 & 255}, ${n >> 8 & 255}, ${n & 255}, ${alpha})`;
208
109
  }
209
- CanvasNode.displayName = "CanvasNode";
210
-
211
- // src/canvas/canvas.utils.ts
212
- function getAnchorPoint(rect, anchor, otherRect) {
213
- const cx = rect.x + rect.width / 2;
214
- const cy = rect.y + rect.height / 2;
215
- if (anchor === "auto" && otherRect) {
216
- const ocx = otherRect.x + otherRect.width / 2;
217
- const ocy = otherRect.y + otherRect.height / 2;
218
- const dx = ocx - cx;
219
- const dy = ocy - cy;
220
- if (Math.abs(dx) > Math.abs(dy)) {
221
- return dx > 0 ? { x: rect.x + rect.width, y: cy } : { x: rect.x, y: cy };
222
- }
223
- return dy > 0 ? { x: cx, y: rect.y + rect.height } : { x: cx, y: rect.y };
110
+ function paintSparkline(ctx, values, x, y, w, h, variant, color) {
111
+ if (values.length === 0 || w <= 0 || h <= 0) return;
112
+ const max = Math.max(...values, 1);
113
+ const min = Math.min(...values, 0);
114
+ const range = max - min || 1;
115
+ const step = w / Math.max(values.length - 1, 1);
116
+ const yOf = (v) => y + h - (v - min) / range * h;
117
+ if (variant === "bar") {
118
+ const gap = 2;
119
+ const bw = w / values.length - gap;
120
+ ctx.fillStyle = color;
121
+ values.forEach((v, i) => {
122
+ const bh = Math.max((v - min) / range * h, 0.5);
123
+ roundRect(ctx, x + i * (bw + gap), y + h - bh, bw, bh, 1);
124
+ ctx.fill();
125
+ });
126
+ return;
224
127
  }
225
- switch (anchor) {
226
- case "top":
227
- return { x: cx, y: rect.y };
228
- case "bottom":
229
- return { x: cx, y: rect.y + rect.height };
230
- case "left":
231
- return { x: rect.x, y: cy };
232
- case "right":
233
- return { x: rect.x + rect.width, y: cy };
234
- case "center":
235
- return { x: cx, y: cy };
236
- default:
237
- return { x: cx, y: cy };
128
+ const trace = () => {
129
+ ctx.beginPath();
130
+ values.forEach((v, i) => i === 0 ? ctx.moveTo(x + i * step, yOf(v)) : ctx.lineTo(x + i * step, yOf(v)));
131
+ };
132
+ if (variant === "area") {
133
+ trace();
134
+ ctx.lineTo(x + w, y + h);
135
+ ctx.lineTo(x, y + h);
136
+ ctx.closePath();
137
+ ctx.fillStyle = withAlpha(color, 0.18);
138
+ ctx.fill();
238
139
  }
140
+ trace();
141
+ ctx.strokeStyle = color;
142
+ ctx.lineWidth = 1.5;
143
+ ctx.lineJoin = "round";
144
+ ctx.stroke();
239
145
  }
240
- function bezierPath(from, to) {
241
- const dx = Math.abs(to.x - from.x);
242
- const dy = Math.abs(to.y - from.y);
243
- if (dx > dy) {
244
- const offset2 = dx * 0.5;
245
- const cp1x = from.x + (to.x > from.x ? offset2 : -offset2);
246
- const cp2x = to.x + (to.x > from.x ? -offset2 : offset2);
247
- return `M${from.x},${from.y} C${cp1x},${from.y} ${cp2x},${to.y} ${to.x},${to.y}`;
146
+ function wrapText(ctx, text, x, y, maxW, lineH, maxY) {
147
+ const words = text.split(" ");
148
+ let line = "";
149
+ let yy = y;
150
+ for (const word of words) {
151
+ const test = line ? `${line} ${word}` : word;
152
+ if (ctx.measureText(test).width > maxW && line) {
153
+ if (maxY !== void 0 && yy > maxY) return;
154
+ ctx.fillText(line, x, yy);
155
+ line = word;
156
+ yy += lineH;
157
+ } else {
158
+ line = test;
159
+ }
248
160
  }
249
- const offset = Math.max(dy * 0.5, 30);
250
- const cp1y = from.y + (to.y > from.y ? offset : -offset);
251
- const cp2y = to.y + (to.y > from.y ? -offset : offset);
252
- return `M${from.x},${from.y} C${from.x},${cp1y} ${to.x},${cp2y} ${to.x},${to.y}`;
253
- }
254
- function stepPath(from, to) {
255
- const midX = (from.x + to.x) / 2;
256
- return `M${from.x},${from.y} H${midX} V${to.y} H${to.x}`;
257
- }
258
- function straightPath(from, to) {
259
- return `M${from.x},${from.y} L${to.x},${to.y}`;
161
+ if (line && (maxY === void 0 || yy <= maxY)) ctx.fillText(line, x, yy);
260
162
  }
261
- function getEdgePath(from, to, curve = "bezier") {
262
- switch (curve) {
263
- case "bezier":
264
- return bezierPath(from, to);
265
- case "step":
266
- return stepPath(from, to);
267
- case "straight":
268
- return straightPath(from, to);
163
+ function paintAtScenePx(ctx, spec, w, h, selected, p) {
164
+ ctx.textAlign = "left";
165
+ ctx.textBaseline = "top";
166
+ if (spec.kind === "screen") {
167
+ paintScreen(ctx, spec, w, h);
168
+ return;
269
169
  }
270
- }
271
- function CanvasEdge({
272
- from,
273
- to,
274
- fromAnchor = "auto",
275
- toAnchor = "auto",
276
- curve = "bezier",
277
- color = "currentColor",
278
- strokeWidth = 2,
279
- dashed = false,
280
- animated = false,
281
- label,
282
- className,
283
- markerStart,
284
- markerEnd
285
- }) {
286
- const { nodeRects, registryVersion } = useCanvas();
287
- const path = react.useMemo(() => {
288
- const fromRect = nodeRects.get(from);
289
- const toRect = nodeRects.get(to);
290
- if (!fromRect || !toRect) return null;
291
- const fromPt = getAnchorPoint(fromRect, fromAnchor, toRect);
292
- const toPt = getAnchorPoint(toRect, toAnchor, fromRect);
293
- return {
294
- d: getEdgePath(fromPt, toPt, curve),
295
- midX: (fromPt.x + toPt.x) / 2,
296
- midY: (fromPt.y + toPt.y) / 2
297
- };
298
- }, [from, to, fromAnchor, toAnchor, curve, nodeRects, registryVersion]);
299
- if (!path) return null;
300
- return /* @__PURE__ */ jsxRuntime.jsxs("g", { "data-react-fancy-canvas-edge": "", className: cn("text-zinc-300 dark:text-zinc-600", className), children: [
301
- /* @__PURE__ */ jsxRuntime.jsx(
302
- "path",
303
- {
304
- d: path.d,
305
- fill: "none",
306
- stroke: color,
307
- strokeWidth,
308
- strokeDasharray: dashed ? "6 4" : void 0,
309
- markerStart: markerStart ? `url(#${markerStart})` : void 0,
310
- markerEnd: markerEnd ? `url(#${markerEnd})` : void 0,
311
- className: animated ? "animate-[dash_1s_linear_infinite]" : "",
312
- style: animated ? { strokeDasharray: "8 4" } : void 0
170
+ if (spec.kind === "callout") {
171
+ const tone = spec.tone === "danger" ? p.danger : spec.tone === "warning" ? p.warning : spec.tone === "success" ? p.success : p.info;
172
+ roundRect(ctx, 0.5, 0.5, w - 1, h - 1, RADIUS);
173
+ ctx.fillStyle = p.card;
174
+ ctx.fill();
175
+ ctx.fillStyle = withAlpha(tone, 0.1);
176
+ ctx.fill();
177
+ ctx.strokeStyle = selected ? p.accent : withAlpha(tone, 0.35);
178
+ ctx.lineWidth = selected ? 2 : 1;
179
+ ctx.stroke();
180
+ ctx.fillStyle = tone;
181
+ ctx.font = font(600, 14);
182
+ ctx.fillText(spec.title, PAD, PAD);
183
+ ctx.fillStyle = p.body;
184
+ ctx.font = font(400, 12);
185
+ wrapText(ctx, spec.body, PAD, PAD + 22, w - PAD * 2, 16, h - PAD - 12);
186
+ return;
187
+ }
188
+ paintCard(ctx, w, h, p, selected);
189
+ switch (spec.kind) {
190
+ case "kpi": {
191
+ paintLabel(ctx, spec.label, PAD, PAD, p);
192
+ ctx.textBaseline = "alphabetic";
193
+ const baseline = PAD + 44;
194
+ ctx.fillStyle = p.text;
195
+ ctx.font = font(700, 24);
196
+ ctx.fillText(spec.value, PAD, baseline);
197
+ if (spec.delta) {
198
+ const valueW = ctx.measureText(spec.value).width;
199
+ ctx.fillStyle = spec.trend === "up" ? p.success : spec.trend === "down" ? p.danger : p.muted;
200
+ ctx.font = font(500, 12);
201
+ ctx.fillText(spec.delta, PAD + valueW + 8, baseline);
313
202
  }
314
- ),
315
- label && /* @__PURE__ */ jsxRuntime.jsx("foreignObject", { x: path.midX - 40, y: path.midY - 12, width: 80, height: 24, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center text-xs text-zinc-500", children: label }) })
316
- ] });
317
- }
318
- CanvasEdge.displayName = "CanvasEdge";
319
- function CanvasMinimap({ width = 150, height = 100, className }) {
320
- const { nodeRects, registryVersion, viewport } = useCanvas();
321
- const bounds = react.useMemo(() => {
322
- if (nodeRects.size === 0) return { minX: 0, minY: 0, maxX: 500, maxY: 300 };
323
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
324
- nodeRects.forEach((r) => {
325
- minX = Math.min(minX, r.x);
326
- minY = Math.min(minY, r.y);
327
- maxX = Math.max(maxX, r.x + r.width);
328
- maxY = Math.max(maxY, r.y + r.height);
329
- });
330
- const padding = 50;
331
- return { minX: minX - padding, minY: minY - padding, maxX: maxX + padding, maxY: maxY + padding };
332
- }, [nodeRects, registryVersion]);
333
- const scaleX = width / (bounds.maxX - bounds.minX || 1);
334
- const scaleY = height / (bounds.maxY - bounds.minY || 1);
335
- const scale = Math.min(scaleX, scaleY);
336
- return /* @__PURE__ */ jsxRuntime.jsx(
337
- "div",
338
- {
339
- "data-react-fancy-canvas-minimap": "",
340
- className: cn(
341
- "absolute right-3 bottom-3 overflow-hidden rounded-lg border border-zinc-200 bg-white/90 dark:border-zinc-700 dark:bg-zinc-900/90",
342
- className
343
- ),
344
- style: { width, height },
345
- children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width, height, children: [
346
- Array.from(nodeRects.entries()).map(([id, rect]) => /* @__PURE__ */ jsxRuntime.jsx(
347
- "rect",
348
- {
349
- x: (rect.x - bounds.minX) * scale,
350
- y: (rect.y - bounds.minY) * scale,
351
- width: Math.max(rect.width * scale, 4),
352
- height: Math.max(rect.height * scale, 3),
353
- rx: 1,
354
- className: "fill-blue-400/60"
355
- },
356
- id
357
- )),
358
- /* @__PURE__ */ jsxRuntime.jsx(
359
- "rect",
360
- {
361
- x: (-viewport.panX / viewport.zoom - bounds.minX) * scale,
362
- y: (-viewport.panY / viewport.zoom - bounds.minY) * scale,
363
- width: (width / viewport.zoom / scale > 0 ? width / viewport.zoom : width) * scale / (bounds.maxX - bounds.minX || 1) * (bounds.maxX - bounds.minX),
364
- height: (height / viewport.zoom / scale > 0 ? height / viewport.zoom : height) * scale / (bounds.maxY - bounds.minY || 1) * (bounds.maxY - bounds.minY),
365
- fill: "none",
366
- stroke: "currentColor",
367
- strokeWidth: 1,
368
- className: "text-blue-500"
369
- }
370
- )
371
- ] })
203
+ break;
372
204
  }
373
- );
374
- }
375
- CanvasMinimap.displayName = "CanvasMinimap";
376
-
377
- // node_modules/lucide-react/dist/esm/shared/src/utils.js
378
- var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
379
- var toCamelCase = (string) => string.replace(
380
- /^([A-Z])|[\s-_]+(\w)/g,
381
- (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()
382
- );
383
- var toPascalCase = (string) => {
384
- const camelCase = toCamelCase(string);
385
- return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
386
- };
387
- var mergeClasses = (...classes) => classes.filter((className, index, array) => {
388
- return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
389
- }).join(" ").trim();
390
- var hasA11yProp = (props) => {
391
- for (const prop in props) {
392
- if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
393
- return true;
394
- }
395
- }
396
- };
397
-
398
- // node_modules/lucide-react/dist/esm/defaultAttributes.js
399
- var defaultAttributes = {
400
- xmlns: "http://www.w3.org/2000/svg",
401
- width: 24,
402
- height: 24,
403
- viewBox: "0 0 24 24",
404
- fill: "none",
405
- stroke: "currentColor",
406
- strokeWidth: 2,
407
- strokeLinecap: "round",
408
- strokeLinejoin: "round"
409
- };
410
-
411
- // node_modules/lucide-react/dist/esm/Icon.js
412
- var Icon = react.forwardRef(
413
- ({
414
- color = "currentColor",
415
- size = 24,
416
- strokeWidth = 2,
417
- absoluteStrokeWidth,
418
- className = "",
419
- children,
420
- iconNode,
421
- ...rest
422
- }, ref) => react.createElement(
423
- "svg",
424
- {
425
- ref,
426
- ...defaultAttributes,
427
- width: size,
428
- height: size,
429
- stroke: color,
430
- strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
431
- className: mergeClasses("lucide", className),
432
- ...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
433
- ...rest
434
- },
435
- [
436
- ...iconNode.map(([tag, attrs]) => react.createElement(tag, attrs)),
437
- ...Array.isArray(children) ? children : [children]
438
- ]
439
- )
440
- );
441
-
442
- // node_modules/lucide-react/dist/esm/createLucideIcon.js
443
- var createLucideIcon = (iconName, iconNode) => {
444
- const Component = react.forwardRef(
445
- ({ className, ...props }, ref) => react.createElement(Icon, {
446
- ref,
447
- iconNode,
448
- className: mergeClasses(
449
- `lucide-${toKebabCase(toPascalCase(iconName))}`,
450
- `lucide-${iconName}`,
451
- className
452
- ),
453
- ...props
454
- })
455
- );
456
- Component.displayName = toPascalCase(iconName);
457
- return Component;
458
- };
459
-
460
- // node_modules/lucide-react/dist/esm/icons/maximize.js
461
- var __iconNode = [
462
- ["path", { d: "M8 3H5a2 2 0 0 0-2 2v3", key: "1dcmit" }],
463
- ["path", { d: "M21 8V5a2 2 0 0 0-2-2h-3", key: "1e4gt3" }],
464
- ["path", { d: "M3 16v3a2 2 0 0 0 2 2h3", key: "wsl5sc" }],
465
- ["path", { d: "M16 21h3a2 2 0 0 0 2-2v-3", key: "18trek" }]
466
- ];
467
- var Maximize = createLucideIcon("maximize", __iconNode);
468
-
469
- // node_modules/lucide-react/dist/esm/icons/rotate-ccw.js
470
- var __iconNode2 = [
471
- ["path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", key: "1357e3" }],
472
- ["path", { d: "M3 3v5h5", key: "1xhq8a" }]
473
- ];
474
- var RotateCcw = createLucideIcon("rotate-ccw", __iconNode2);
475
-
476
- // node_modules/lucide-react/dist/esm/icons/zoom-in.js
477
- var __iconNode3 = [
478
- ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
479
- ["line", { x1: "21", x2: "16.65", y1: "21", y2: "16.65", key: "13gj7c" }],
480
- ["line", { x1: "11", x2: "11", y1: "8", y2: "14", key: "1vmskp" }],
481
- ["line", { x1: "8", x2: "14", y1: "11", y2: "11", key: "durymu" }]
482
- ];
483
- var ZoomIn = createLucideIcon("zoom-in", __iconNode3);
484
-
485
- // node_modules/lucide-react/dist/esm/icons/zoom-out.js
486
- var __iconNode4 = [
487
- ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
488
- ["line", { x1: "21", x2: "16.65", y1: "21", y2: "16.65", key: "13gj7c" }],
489
- ["line", { x1: "8", x2: "14", y1: "11", y2: "11", key: "durymu" }]
490
- ];
491
- var ZoomOut = createLucideIcon("zoom-out", __iconNode4);
492
- function CanvasControls({
493
- className,
494
- showZoomIn = true,
495
- showZoomOut = true,
496
- showReset = true,
497
- showFitAll = true
498
- }) {
499
- const { setViewport, nodeRects, containerRef } = useCanvas();
500
- const zoomIn = () => setViewport((v) => ({ ...v, zoom: Math.min(3, v.zoom * 1.25) }));
501
- const zoomOut = () => setViewport((v) => ({ ...v, zoom: Math.max(0.1, v.zoom / 1.25) }));
502
- const reset = () => setViewport({ panX: 0, panY: 0, zoom: 1 });
503
- const fitAll = () => {
504
- const container = containerRef.current;
505
- if (!container || nodeRects.size === 0) return reset();
506
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
507
- nodeRects.forEach((r) => {
508
- minX = Math.min(minX, r.x);
509
- minY = Math.min(minY, r.y);
510
- maxX = Math.max(maxX, r.x + r.width);
511
- maxY = Math.max(maxY, r.y + r.height);
512
- });
513
- const padding = 40;
514
- const contentW = maxX - minX + padding * 2;
515
- const contentH = maxY - minY + padding * 2;
516
- const cw = container.clientWidth;
517
- const ch = container.clientHeight;
518
- const zoom = Math.min(cw / contentW, ch / contentH, 1.5);
519
- const panX = (cw - contentW * zoom) / 2 - minX * zoom + padding * zoom;
520
- const panY = (ch - contentH * zoom) / 2 - minY * zoom + padding * zoom;
521
- setViewport({ panX, panY, zoom });
522
- };
523
- const btnClass = "flex h-8 w-8 items-center justify-center rounded-md text-zinc-500 hover:bg-zinc-100 hover:text-zinc-700 dark:hover:bg-zinc-800 dark:hover:text-zinc-300 transition-colors";
524
- return /* @__PURE__ */ jsxRuntime.jsxs(
525
- "div",
526
- {
527
- "data-react-fancy-canvas-controls": "",
528
- className: cn(
529
- "absolute bottom-3 left-3 flex gap-1 rounded-lg border border-zinc-200 bg-white/90 p-1 shadow-sm dark:border-zinc-700 dark:bg-zinc-900/90",
530
- className
531
- ),
532
- children: [
533
- showZoomIn && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: zoomIn, className: btnClass, "aria-label": "Zoom in", children: /* @__PURE__ */ jsxRuntime.jsx(ZoomIn, { size: 16 }) }),
534
- showZoomOut && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: zoomOut, className: btnClass, "aria-label": "Zoom out", children: /* @__PURE__ */ jsxRuntime.jsx(ZoomOut, { size: 16 }) }),
535
- showReset && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: reset, className: btnClass, "aria-label": "Reset view", children: /* @__PURE__ */ jsxRuntime.jsx(RotateCcw, { size: 16 }) }),
536
- showFitAll && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: fitAll, className: btnClass, "aria-label": "Fit all", children: /* @__PURE__ */ jsxRuntime.jsx(Maximize, { size: 16 }) })
537
- ]
205
+ case "chart": {
206
+ paintLabel(ctx, spec.title, PAD, PAD, p);
207
+ const top = PAD + 16 + 8;
208
+ paintSparkline(ctx, spec.series, PAD, top, w - PAD * 2, h - PAD - top, spec.variant, spec.color ?? p.accent);
209
+ break;
538
210
  }
539
- );
540
- }
541
- CanvasControls.displayName = "CanvasControls";
542
-
543
- // src/canvas/engines/dom.ts
544
- var domEngine = {
545
- name: "dom",
546
- mount(host, _viewport) {
547
- return {
548
- name: "dom",
549
- root: host,
550
- updateViewport: () => {
551
- },
552
- dispose: () => {
211
+ case "profile": {
212
+ const r = 20;
213
+ const cx = PAD + r;
214
+ const cy = PAD + r;
215
+ ctx.fillStyle = p.avatar;
216
+ ctx.beginPath();
217
+ ctx.arc(cx, cy, r, 0, Math.PI * 2);
218
+ ctx.fill();
219
+ ctx.fillStyle = p.avatarText;
220
+ ctx.font = font(500, 14);
221
+ ctx.textAlign = "center";
222
+ ctx.textBaseline = "middle";
223
+ ctx.fillText(spec.initials, cx, cy);
224
+ ctx.textAlign = "left";
225
+ if (spec.status) {
226
+ const dot = spec.status === "online" ? p.success : spec.status === "away" ? p.warning : p.muted;
227
+ ctx.fillStyle = p.card;
228
+ ctx.beginPath();
229
+ ctx.arc(cx + r * 0.72, cy + r * 0.72, 6, 0, Math.PI * 2);
230
+ ctx.fill();
231
+ ctx.fillStyle = dot;
232
+ ctx.beginPath();
233
+ ctx.arc(cx + r * 0.72, cy + r * 0.72, 4.5, 0, Math.PI * 2);
234
+ ctx.fill();
553
235
  }
554
- };
555
- }
556
- };
557
- function resolveEngine(spec) {
558
- if (!spec || spec === "dom") return domEngine;
559
- return spec;
560
- }
561
- var DEFAULT_VIEWPORT = { panX: 0, panY: 0, zoom: 1 };
562
- function CanvasRoot({
563
- children,
564
- viewport: controlledViewport,
565
- defaultViewport = DEFAULT_VIEWPORT,
566
- onViewportChange,
567
- minZoom = 0.1,
568
- maxZoom = 3,
569
- pannable = true,
570
- zoomable = true,
571
- showGrid = false,
572
- gridStyle = "dots",
573
- gridSize = 20,
574
- gridColor = "rgb(161 161 170 / 0.3)",
575
- snapToGrid = false,
576
- fitOnMount = false,
577
- engine: engineSpec,
578
- className,
579
- style
580
- }) {
581
- const containerRef = react.useRef(null);
582
- const [viewport, setViewport] = useControllableState(controlledViewport, defaultViewport, onViewportChange);
583
- const { registerNode, unregisterNode, nodeRects, version: registryVersion } = useNodeRegistry();
584
- const [engineHandle, setEngineHandle] = react.useState(null);
585
- react.useEffect(() => {
586
- const host = containerRef.current;
587
- if (!host) return;
588
- const resolved = resolveEngine(engineSpec);
589
- let handle = null;
590
- try {
591
- handle = resolved.mount(host, viewport);
592
- setEngineHandle(handle);
593
- } catch (err) {
594
- console.error(`[fancy-3d] Canvas engine "${resolved.name}" failed to mount:`, err);
595
- setEngineHandle(null);
236
+ const tx = PAD + r * 2 + 12;
237
+ ctx.textBaseline = "alphabetic";
238
+ ctx.fillStyle = p.text;
239
+ ctx.font = font(500, 16);
240
+ ctx.fillText(spec.name, tx, cy - 2);
241
+ ctx.fillStyle = p.muted;
242
+ ctx.font = font(400, 14);
243
+ ctx.fillText(spec.role, tx, cy + 16);
244
+ break;
596
245
  }
597
- return () => {
598
- try {
599
- handle?.dispose();
600
- } catch (err) {
601
- console.error(`[fancy-3d] Canvas engine "${handle?.name}" failed to dispose:`, err);
602
- }
603
- setEngineHandle(null);
604
- };
605
- }, [engineSpec]);
606
- react.useEffect(() => {
607
- engineHandle?.updateViewport(viewport);
608
- }, [engineHandle, viewport]);
609
- const { containerProps } = usePanZoom({
610
- viewport,
611
- setViewport,
612
- minZoom,
613
- maxZoom,
614
- pannable,
615
- zoomable,
616
- containerRef
617
- });
618
- const ctx = react.useMemo(
619
- () => ({ viewport, setViewport, registerNode, unregisterNode, nodeRects, registryVersion, containerRef, gridSize, snapToGrid, engine: engineHandle }),
620
- [viewport, setViewport, registerNode, unregisterNode, nodeRects, registryVersion, gridSize, snapToGrid, engineHandle]
621
- );
622
- const hasFitted = react.useRef(false);
623
- react.useEffect(() => {
624
- if (!fitOnMount || hasFitted.current || nodeRects.size === 0) return;
625
- const container = containerRef.current;
626
- if (!container || container.clientWidth === 0) return;
627
- hasFitted.current = true;
628
- requestAnimationFrame(() => {
629
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
630
- nodeRects.forEach((r) => {
631
- minX = Math.min(minX, r.x);
632
- minY = Math.min(minY, r.y);
633
- maxX = Math.max(maxX, r.x + r.width);
634
- maxY = Math.max(maxY, r.y + r.height);
246
+ case "kanban": {
247
+ const gap = 8;
248
+ const n = Math.max(spec.columns.length, 1);
249
+ const colW = (w - PAD * 2 - (n - 1) * gap) / n;
250
+ spec.columns.forEach((col, i) => {
251
+ const x = PAD + i * (colW + gap);
252
+ ctx.fillStyle = p.subtle;
253
+ roundRect(ctx, x, PAD, colW, h - PAD * 2, 8);
254
+ ctx.fill();
255
+ ctx.fillStyle = p.muted;
256
+ ctx.font = font(600, 10);
257
+ ctx.textBaseline = "top";
258
+ ctx.fillText(col.title.toUpperCase(), x + 8, PAD + 8);
259
+ col.cards.forEach((c, j) => {
260
+ const y = PAD + 28 + j * 32;
261
+ ctx.fillStyle = p.card;
262
+ roundRect(ctx, x + 8, y, colW - 16, 26, 4);
263
+ ctx.fill();
264
+ ctx.strokeStyle = p.cardBorder;
265
+ ctx.lineWidth = 1;
266
+ ctx.stroke();
267
+ ctx.fillStyle = p.body;
268
+ ctx.font = font(400, 12);
269
+ ctx.fillText(c, x + 16, y + 7);
270
+ });
635
271
  });
636
- const padding = 40;
637
- const contentW = maxX - minX + padding * 2;
638
- const contentH = maxY - minY + padding * 2;
639
- const cw = container.clientWidth;
640
- const ch = container.clientHeight;
641
- const zoom = Math.min(cw / contentW, ch / contentH, 1.5);
642
- const panX = (cw - contentW * zoom) / 2 - minX * zoom + padding * zoom;
643
- const panY = (ch - contentH * zoom) / 2 - minY * zoom + padding * zoom;
644
- setViewport({ panX, panY, zoom });
645
- });
646
- }, [fitOnMount, nodeRects, registryVersion, setViewport]);
647
- const edges = [];
648
- const others = [];
649
- const overlays = [];
650
- react.Children.forEach(children, (child) => {
651
- const el = child;
652
- if (!el || !el.type) return;
653
- const elType = el.type;
654
- if (elType === CanvasEdge || elType?._isCanvasEdge) {
655
- edges.push(el);
656
- } else if (elType === CanvasMinimap || elType === CanvasControls) {
657
- overlays.push(el);
658
- } else {
659
- others.push(el);
272
+ break;
273
+ }
274
+ case "table": {
275
+ paintLabel(ctx, spec.title, PAD, PAD, p);
276
+ const n = Math.max(spec.columns.length, 1);
277
+ const colW = (w - PAD * 2) / n;
278
+ ctx.fillStyle = p.muted;
279
+ ctx.font = font(500, 12);
280
+ spec.columns.forEach((c, i) => ctx.fillText(c, PAD + i * colW, PAD + 30));
281
+ ctx.fillStyle = p.body;
282
+ ctx.font = font(400, 12);
283
+ spec.rows.forEach((row, ri) => {
284
+ row.forEach((cell, ci) => ctx.fillText(String(cell), PAD + ci * colW, PAD + 56 + ri * 26));
285
+ });
286
+ break;
660
287
  }
661
- });
662
- return /* @__PURE__ */ jsxRuntime.jsx(CanvasContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxRuntime.jsxs(
663
- "div",
664
- {
665
- ref: containerRef,
666
- "data-react-fancy-canvas": "",
667
- className: cn("relative overflow-hidden", className),
668
- style: { touchAction: "none", ...style },
669
- ...containerProps,
670
- children: [
671
- /* @__PURE__ */ jsxRuntime.jsx(
672
- "div",
673
- {
674
- "data-canvas-bg": "",
675
- className: "absolute inset-0",
676
- style: showGrid && gridStyle !== "none" ? gridStyle === "lines" ? {
677
- backgroundImage: `linear-gradient(to right, ${gridColor} 1px, transparent 1px), linear-gradient(to bottom, ${gridColor} 1px, transparent 1px)`,
678
- backgroundSize: `${gridSize * viewport.zoom}px ${gridSize * viewport.zoom}px`,
679
- backgroundPosition: `${viewport.panX}px ${viewport.panY}px`
680
- } : {
681
- backgroundImage: `radial-gradient(circle, ${gridColor} 1px, transparent 1px)`,
682
- backgroundSize: `${gridSize * viewport.zoom}px ${gridSize * viewport.zoom}px`,
683
- backgroundPosition: `${viewport.panX}px ${viewport.panY}px`
684
- } : void 0
685
- }
686
- ),
687
- /* @__PURE__ */ jsxRuntime.jsx(
688
- "div",
689
- {
690
- className: "absolute origin-top-left",
691
- style: {
692
- transform: `translate(${viewport.panX}px, ${viewport.panY}px) scale(${viewport.zoom})`
693
- },
694
- children: others
695
- }
696
- ),
697
- /* @__PURE__ */ jsxRuntime.jsxs(
698
- "svg",
699
- {
700
- className: "pointer-events-none absolute inset-0 h-full w-full",
701
- style: {
702
- transform: `translate(${viewport.panX}px, ${viewport.panY}px) scale(${viewport.zoom})`,
703
- transformOrigin: "0 0"
704
- },
705
- children: [
706
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
707
- /* @__PURE__ */ jsxRuntime.jsx("marker", { id: "canvas-arrow", viewBox: "0 0 10 10", refX: "10", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M0,0 L10,5 L0,10 Z", fill: "#71717a" }) }),
708
- /* @__PURE__ */ jsxRuntime.jsx("marker", { id: "canvas-circle", viewBox: "0 0 10 10", refX: "5", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto", children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "5", cy: "5", r: "3.5", fill: "#71717a" }) }),
709
- /* @__PURE__ */ jsxRuntime.jsx("marker", { id: "canvas-diamond", viewBox: "0 0 12 12", refX: "6", refY: "6", markerWidth: "10", markerHeight: "10", orient: "auto", children: /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "6,0 12,6 6,12 0,6", fill: "none", stroke: "#71717a", strokeWidth: "1.5" }) }),
710
- /* @__PURE__ */ jsxRuntime.jsx("marker", { id: "canvas-one", viewBox: "0 0 2 16", refX: "1", refY: "8", markerWidth: "2", markerHeight: "14", orient: "auto", children: /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "1", y1: "0", x2: "1", y2: "16", stroke: "#71717a", strokeWidth: "2" }) }),
711
- /* @__PURE__ */ jsxRuntime.jsxs("marker", { id: "canvas-crow-foot", viewBox: "0 0 16 16", refX: "16", refY: "8", markerWidth: "14", markerHeight: "14", orient: "auto", children: [
712
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "16", y1: "8", x2: "0", y2: "0", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" }),
713
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "16", y1: "8", x2: "0", y2: "8", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" }),
714
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "16", y1: "8", x2: "0", y2: "16", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" }),
715
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "16", y1: "0", x2: "16", y2: "16", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" })
716
- ] })
717
- ] }),
718
- edges
719
- ]
720
- }
721
- ),
722
- overlays
723
- ]
288
+ case "form": {
289
+ paintLabel(ctx, spec.title, PAD, PAD, p);
290
+ spec.fields.forEach((f, i) => {
291
+ const y = PAD + 28 + i * 34;
292
+ ctx.fillStyle = p.body;
293
+ ctx.font = font(400, 12);
294
+ ctx.fillText(f.label, PAD, y + 7);
295
+ if (f.type === "switch") {
296
+ ctx.fillStyle = p.accent;
297
+ roundRect(ctx, w - PAD - 36, y + 2, 36, 20, 10);
298
+ ctx.fill();
299
+ ctx.fillStyle = p.onAccent;
300
+ ctx.beginPath();
301
+ ctx.arc(w - PAD - 12, y + 12, 8, 0, Math.PI * 2);
302
+ ctx.fill();
303
+ } else {
304
+ ctx.fillStyle = p.card;
305
+ roundRect(ctx, w - PAD - 112, y, 112, 26, 4);
306
+ ctx.fill();
307
+ ctx.strokeStyle = p.cardBorder;
308
+ ctx.lineWidth = 1;
309
+ ctx.stroke();
310
+ }
311
+ });
312
+ break;
313
+ }
314
+ case "action": {
315
+ paintLabel(ctx, spec.title, PAD, PAD, p);
316
+ let bx = PAD;
317
+ const by = PAD + 26;
318
+ ctx.font = font(500, 12);
319
+ spec.buttons.forEach((b) => {
320
+ const tw = ctx.measureText(b.label).width + 20;
321
+ if (b.variant === "primary") {
322
+ ctx.fillStyle = p.accent;
323
+ roundRect(ctx, bx, by, tw, 28, 6);
324
+ ctx.fill();
325
+ } else if (b.variant !== "ghost") {
326
+ ctx.fillStyle = p.card;
327
+ roundRect(ctx, bx, by, tw, 28, 6);
328
+ ctx.fill();
329
+ ctx.strokeStyle = p.cardBorder;
330
+ ctx.lineWidth = 1;
331
+ ctx.stroke();
332
+ }
333
+ ctx.fillStyle = b.variant === "primary" ? p.onAccent : p.text;
334
+ ctx.fillText(b.label, bx + 10, by + 8);
335
+ bx += tw + 8;
336
+ });
337
+ break;
338
+ }
339
+ case "timeline": {
340
+ paintLabel(ctx, spec.title, PAD, PAD, p);
341
+ spec.events.forEach((e, i) => {
342
+ const y = PAD + 28 + i * 28;
343
+ ctx.fillStyle = p.accent;
344
+ ctx.beginPath();
345
+ ctx.arc(PAD + 4, y + 7, 4, 0, Math.PI * 2);
346
+ ctx.fill();
347
+ if (i < spec.events.length - 1) {
348
+ ctx.strokeStyle = p.cardBorder;
349
+ ctx.lineWidth = 1;
350
+ ctx.beginPath();
351
+ ctx.moveTo(PAD + 4, y + 12);
352
+ ctx.lineTo(PAD + 4, y + 28);
353
+ ctx.stroke();
354
+ }
355
+ ctx.fillStyle = p.muted;
356
+ ctx.font = font(500, 11, MONO);
357
+ ctx.fillText(e.at, PAD + 16, y);
358
+ ctx.fillStyle = p.body;
359
+ ctx.font = font(400, 12);
360
+ ctx.fillText(e.label, PAD + 64, y);
361
+ });
362
+ break;
724
363
  }
725
- ) });
364
+ case "code": {
365
+ paintLabel(ctx, spec.title, PAD, PAD, p);
366
+ const top = PAD + 24;
367
+ ctx.fillStyle = p.code;
368
+ roundRect(ctx, PAD, top, w - PAD * 2, h - PAD - top, 4);
369
+ ctx.fill();
370
+ ctx.fillStyle = p.codeText;
371
+ ctx.font = font(400, 11, MONO);
372
+ spec.code.split("\n").forEach((ln, i) => ctx.fillText(ln, PAD + 8, top + 8 + i * 18));
373
+ break;
374
+ }
375
+ case "image": {
376
+ ctx.fillStyle = p.subtle;
377
+ roundRect(ctx, 1, 1, w - 2, h - 2, RADIUS - 1);
378
+ ctx.fill();
379
+ ctx.fillStyle = p.muted;
380
+ ctx.font = font(400, 12);
381
+ ctx.textAlign = "center";
382
+ ctx.textBaseline = "middle";
383
+ ctx.fillText(spec.alt, w / 2, h / 2);
384
+ ctx.textAlign = "left";
385
+ break;
386
+ }
387
+ case "text": {
388
+ ctx.fillStyle = p.text;
389
+ ctx.font = font(600, 14);
390
+ ctx.fillText(spec.heading, PAD, PAD);
391
+ ctx.fillStyle = p.body;
392
+ ctx.font = font(400, 12);
393
+ wrapText(ctx, spec.body, PAD, PAD + 22, w - PAD * 2, 16, h - PAD - 12);
394
+ break;
395
+ }
396
+ case "demoPage": {
397
+ const headerH = 34;
398
+ ctx.save();
399
+ roundRect(ctx, 0.5, 0.5, w - 1, h - 1, RADIUS);
400
+ ctx.clip();
401
+ ctx.fillStyle = spec.accent;
402
+ ctx.fillRect(0, 0, w, headerH);
403
+ ctx.restore();
404
+ ctx.font = font(700, 10);
405
+ const chip = spec.category.toUpperCase();
406
+ const chipW = ctx.measureText(chip).width + 16;
407
+ ctx.fillStyle = "rgba(255,255,255,0.2)";
408
+ roundRect(ctx, 12, 8, chipW, 18, 9);
409
+ ctx.fill();
410
+ ctx.fillStyle = "#ffffff";
411
+ ctx.fillText(chip, 20, 12);
412
+ ctx.fillStyle = "rgba(255,255,255,0.85)";
413
+ ctx.font = font(400, 10, MONO);
414
+ ctx.textAlign = "right";
415
+ ctx.fillText(spec.path, w - 12, 12);
416
+ ctx.textAlign = "left";
417
+ ctx.fillStyle = p.text;
418
+ ctx.font = font(800, 16);
419
+ ctx.fillText(spec.name, PAD, headerH + PAD);
420
+ ctx.fillStyle = p.muted;
421
+ ctx.font = font(400, 12);
422
+ const ctaH = 22;
423
+ const ctaY = h - PAD - ctaH;
424
+ wrapText(ctx, spec.description, PAD, headerH + PAD + 26, w - PAD * 2, 16, ctaY - 20);
425
+ ctx.font = font(600, 11);
426
+ const cta = "Open demo \u2192";
427
+ ctx.fillStyle = spec.accent;
428
+ roundRect(ctx, PAD, ctaY, ctx.measureText(cta).width + 16, ctaH, 6);
429
+ ctx.fill();
430
+ ctx.fillStyle = "#0f172a";
431
+ ctx.fillText(cta, PAD + 8, ctaY + 6);
432
+ break;
433
+ }
434
+ }
435
+ }
436
+ function paintScreen(ctx, spec, w, h) {
437
+ const bezel = spec.bezel ?? "#0b0f17";
438
+ const t = spec.bezelThickness ?? 14;
439
+ const on = spec.on ?? true;
440
+ const brightness = spec.brightness ?? (on ? 1 : 0.06);
441
+ const bg = spec.background ?? "#020617";
442
+ ctx.fillStyle = bezel;
443
+ roundRect(ctx, 0, 0, w, h, 16);
444
+ ctx.fill();
445
+ const sw = w - t * 2;
446
+ const sh = h - t * 2;
447
+ ctx.save();
448
+ ctx.fillStyle = bg;
449
+ roundRect(ctx, t, t, sw, sh, 6);
450
+ ctx.fill();
451
+ roundRect(ctx, t, t, sw, sh, 6);
452
+ ctx.clip();
453
+ ctx.translate(t, t);
454
+ ctx.globalAlpha = brightness;
455
+ const c = spec.content;
456
+ if (c.type === "label") {
457
+ ctx.fillStyle = "#f4f4f5";
458
+ ctx.font = font(700, 18);
459
+ ctx.textAlign = "center";
460
+ ctx.textBaseline = "middle";
461
+ ctx.fillText(c.title, sw / 2, sh / 2 - (c.subtitle ? 10 : 0));
462
+ if (c.subtitle) {
463
+ ctx.fillStyle = "#a1a1aa";
464
+ ctx.font = font(400, 12);
465
+ ctx.fillText(c.subtitle, sw / 2, sh / 2 + 12);
466
+ }
467
+ } else if (c.type === "paint") {
468
+ c.paint(ctx, sw, sh);
469
+ } else {
470
+ ctx.fillStyle = "#71717a";
471
+ ctx.font = font(500, 12);
472
+ ctx.textAlign = "center";
473
+ ctx.textBaseline = "middle";
474
+ ctx.fillText(c.alt ?? "image", sw / 2, sh / 2);
475
+ }
476
+ ctx.globalAlpha = 1;
477
+ ctx.restore();
478
+ ctx.textAlign = "left";
479
+ ctx.fillStyle = on ? "#10b981" : "#475569";
480
+ ctx.beginPath();
481
+ ctx.arc(w - t / 2 - 3, h - t / 2 - 3, 3, 0, Math.PI * 2);
482
+ ctx.fill();
483
+ }
484
+ function paletteOf(theme) {
485
+ if (theme && typeof theme === "object") return theme;
486
+ return theme === "light" || theme === "dark" ? SCENE_PALETTES[theme] : scenePalette();
487
+ }
488
+ function paintWidget(ctx, spec, w, h, opts = {}) {
489
+ const p = paletteOf(opts.theme);
490
+ const scenePx = opts.scenePx ?? (h >= chunkIU7B7Y63_cjs.DEFAULT_NODE_SIZE.h ? { w, h } : { w: w * chunkIU7B7Y63_cjs.DEFAULT_NODE_SIZE.h / h, h: chunkIU7B7Y63_cjs.DEFAULT_NODE_SIZE.h });
491
+ const sx = w / scenePx.w;
492
+ const sy = h / scenePx.h;
493
+ ctx.save();
494
+ ctx.scale(sx, sy);
495
+ paintAtScenePx(ctx, spec, scenePx.w, scenePx.h, opts.selected ?? false, p);
496
+ ctx.restore();
726
497
  }
727
- var Canvas = Object.assign(CanvasRoot, {
728
- Node: CanvasNode,
729
- Edge: CanvasEdge,
730
- Minimap: CanvasMinimap,
731
- Controls: CanvasControls
732
- });
733
- /*! Bundled license information:
734
-
735
- lucide-react/dist/esm/shared/src/utils.js:
736
- lucide-react/dist/esm/defaultAttributes.js:
737
- lucide-react/dist/esm/Icon.js:
738
- lucide-react/dist/esm/createLucideIcon.js:
739
- lucide-react/dist/esm/icons/maximize.js:
740
- lucide-react/dist/esm/icons/rotate-ccw.js:
741
- lucide-react/dist/esm/icons/zoom-in.js:
742
- lucide-react/dist/esm/icons/zoom-out.js:
743
- lucide-react/dist/esm/lucide-react.js:
744
- (**
745
- * @license lucide-react v0.511.0 - ISC
746
- *
747
- * This source code is licensed under the ISC license.
748
- * See the LICENSE file in the root directory of this source tree.
749
- *)
750
- */
751
498
 
752
- exports.Canvas = Canvas;
753
- exports.domEngine = domEngine;
499
+ Object.defineProperty(exports, "Canvas", {
500
+ enumerable: true,
501
+ get: function () { return chunkIU7B7Y63_cjs.Canvas; }
502
+ });
503
+ Object.defineProperty(exports, "DEFAULT_NODE_SIZE", {
504
+ enumerable: true,
505
+ get: function () { return chunkIU7B7Y63_cjs.DEFAULT_NODE_SIZE; }
506
+ });
507
+ Object.defineProperty(exports, "FIT_MAX_ZOOM", {
508
+ enumerable: true,
509
+ get: function () { return chunkIU7B7Y63_cjs.FIT_MAX_ZOOM; }
510
+ });
511
+ Object.defineProperty(exports, "FIT_PADDING", {
512
+ enumerable: true,
513
+ get: function () { return chunkIU7B7Y63_cjs.FIT_PADDING; }
514
+ });
515
+ Object.defineProperty(exports, "PX_PER_UNIT", {
516
+ enumerable: true,
517
+ get: function () { return chunkIU7B7Y63_cjs.PX_PER_UNIT; }
518
+ });
519
+ Object.defineProperty(exports, "domEngine", {
520
+ enumerable: true,
521
+ get: function () { return chunkIU7B7Y63_cjs.domEngine; }
522
+ });
523
+ Object.defineProperty(exports, "fitZoom", {
524
+ enumerable: true,
525
+ get: function () { return chunkIU7B7Y63_cjs.fitZoom; }
526
+ });
527
+ Object.defineProperty(exports, "frameScene", {
528
+ enumerable: true,
529
+ get: function () { return chunkIU7B7Y63_cjs.frameScene; }
530
+ });
531
+ Object.defineProperty(exports, "nodeSize", {
532
+ enumerable: true,
533
+ get: function () { return chunkIU7B7Y63_cjs.nodeSize; }
534
+ });
535
+ Object.defineProperty(exports, "sceneBounds", {
536
+ enumerable: true,
537
+ get: function () { return chunkIU7B7Y63_cjs.sceneBounds; }
538
+ });
539
+ Object.defineProperty(exports, "sceneToWorld", {
540
+ enumerable: true,
541
+ get: function () { return chunkIU7B7Y63_cjs.sceneToWorld; }
542
+ });
543
+ Object.defineProperty(exports, "useCanvas", {
544
+ enumerable: true,
545
+ get: function () { return chunkIU7B7Y63_cjs.useCanvas; }
546
+ });
547
+ Object.defineProperty(exports, "DEFAULT_FULLSCREEN_LABELS", {
548
+ enumerable: true,
549
+ get: function () { return chunkPBKOUAUY_cjs.DEFAULT_FULLSCREEN_LABELS; }
550
+ });
551
+ Object.defineProperty(exports, "FullscreenButton", {
552
+ enumerable: true,
553
+ get: function () { return chunkPBKOUAUY_cjs.FullscreenButton; }
554
+ });
555
+ Object.defineProperty(exports, "FullscreenContext", {
556
+ enumerable: true,
557
+ get: function () { return chunkPBKOUAUY_cjs.FullscreenContext; }
558
+ });
559
+ Object.defineProperty(exports, "nativeFullscreenSupported", {
560
+ enumerable: true,
561
+ get: function () { return chunkPBKOUAUY_cjs.nativeFullscreenSupported; }
562
+ });
563
+ Object.defineProperty(exports, "useFullscreen", {
564
+ enumerable: true,
565
+ get: function () { return chunkPBKOUAUY_cjs.useFullscreen; }
566
+ });
567
+ Object.defineProperty(exports, "useFullscreenContext", {
568
+ enumerable: true,
569
+ get: function () { return chunkPBKOUAUY_cjs.useFullscreenContext; }
570
+ });
571
+ exports.DARK_THEME_SELECTOR = DARK_THEME_SELECTOR;
572
+ exports.SCENE_PALETTES = SCENE_PALETTES;
754
573
  exports.nextId = nextId;
574
+ exports.paintWidget = paintWidget;
755
575
  exports.renderScene = renderScene;
756
- exports.useCanvas = useCanvas;
576
+ exports.resolveSceneTheme = resolveSceneTheme;
577
+ exports.scenePalette = scenePalette;
757
578
  //# sourceMappingURL=index.cjs.map
758
579
  //# sourceMappingURL=index.cjs.map