@sixb/app 0.2.3 → 0.2.4

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.
Files changed (133) hide show
  1. package/dist/agent/activity-label.d.ts.map +1 -1
  2. package/dist/agent/agent-chat.d.ts.map +1 -1
  3. package/dist/agent/background/background-tool-row.d.ts.map +1 -1
  4. package/dist/agent/background/interpret.d.ts +1 -1
  5. package/dist/agent/background/interpret.d.ts.map +1 -1
  6. package/dist/agent/components/conversation-panel.d.ts +4 -1
  7. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  8. package/dist/agent/components/message-parts.d.ts.map +1 -1
  9. package/dist/agent/components/transcript.d.ts +5 -0
  10. package/dist/agent/components/transcript.d.ts.map +1 -1
  11. package/dist/agent/delegation/agent-exchange.d.ts +16 -0
  12. package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
  13. package/dist/agent/delegation/child-card.d.ts +3 -3
  14. package/dist/agent/delegation/child-card.d.ts.map +1 -1
  15. package/dist/agent/delegation/child-parts.d.ts +1 -10
  16. package/dist/agent/delegation/child-parts.d.ts.map +1 -1
  17. package/dist/agent/delegation/child-work.d.ts.map +1 -1
  18. package/dist/agent/delegation/interpret.d.ts +4 -10
  19. package/dist/agent/delegation/interpret.d.ts.map +1 -1
  20. package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
  21. package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
  22. package/dist/agent/file-edits/interpret.d.ts +25 -0
  23. package/dist/agent/file-edits/interpret.d.ts.map +1 -0
  24. package/dist/agent/hooks/use-agent-conversation.d.ts +6 -0
  25. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  26. package/dist/agent/i18n/en.d.ts +46 -5
  27. package/dist/agent/i18n/en.d.ts.map +1 -1
  28. package/dist/agent/i18n/fr.d.ts.map +1 -1
  29. package/dist/agent/i18n/index.d.ts +76 -8
  30. package/dist/agent/i18n/index.d.ts.map +1 -1
  31. package/dist/agent/message-agent/interpret.d.ts +2 -2
  32. package/dist/agent/message-agent/interpret.d.ts.map +1 -1
  33. package/dist/agent/publish-artifact/interpret.d.ts +1 -1
  34. package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
  35. package/dist/agent/questions/interpret.d.ts +31 -0
  36. package/dist/agent/questions/interpret.d.ts.map +1 -0
  37. package/dist/agent/questions/question-card.d.ts +16 -0
  38. package/dist/agent/questions/question-card.d.ts.map +1 -0
  39. package/dist/agent/questions/question-composer.d.ts +15 -0
  40. package/dist/agent/questions/question-composer.d.ts.map +1 -0
  41. package/dist/agent/read/interpret.d.ts +8 -1
  42. package/dist/agent/read/interpret.d.ts.map +1 -1
  43. package/dist/agent/read/read-tool-view.d.ts.map +1 -1
  44. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  45. package/dist/agent/waits.d.ts +14 -0
  46. package/dist/agent/waits.d.ts.map +1 -0
  47. package/dist/artifacts/edit-session.d.ts +11 -1
  48. package/dist/artifacts/edit-session.d.ts.map +1 -1
  49. package/dist/artifacts/frame.d.ts.map +1 -1
  50. package/dist/artifacts/messages.d.ts +52 -0
  51. package/dist/artifacts/messages.d.ts.map +1 -1
  52. package/dist/artifacts/renderers/canvas/board-editor.d.ts +11 -4
  53. package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
  54. package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
  55. package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
  56. package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
  57. package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
  58. package/dist/artifacts/renderers/canvas/controls.d.ts +15 -4
  59. package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
  60. package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
  61. package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
  62. package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
  63. package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
  64. package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
  65. package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
  66. package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
  67. package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
  68. package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
  69. package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
  70. package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
  71. package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
  72. package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
  73. package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
  74. package/dist/{chunk-kes4ygmz.js → chunk-970s5nkn.js} +1 -1
  75. package/dist/{chunk-001c4gnk.js → chunk-kymx9y5e.js} +3117 -2363
  76. package/dist/{chunk-001c4gnk.js.map → chunk-kymx9y5e.js.map} +36 -29
  77. package/dist/{chunk-fwb9mxwm.js → chunk-pxd07kvx.js} +1 -1
  78. package/dist/{chunk-5crvhjp2.js → chunk-yrcm1pbg.js} +1504 -233
  79. package/dist/chunk-yrcm1pbg.js.map +34 -0
  80. package/dist/index.d.ts +2 -0
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +4 -2
  83. package/dist/index.js.map +3 -3
  84. package/dist/pages.js +2 -2
  85. package/package.json +2 -2
  86. package/src/agent/activity-label.ts +6 -1
  87. package/src/agent/agent-chat.tsx +1 -0
  88. package/src/agent/background/background-tool-row.tsx +24 -10
  89. package/src/agent/background/interpret.ts +60 -51
  90. package/src/agent/components/conversation-panel.tsx +27 -8
  91. package/src/agent/components/message-parts.tsx +23 -5
  92. package/src/agent/components/transcript.tsx +45 -27
  93. package/src/agent/delegation/agent-exchange.tsx +53 -0
  94. package/src/agent/delegation/child-card.tsx +6 -40
  95. package/src/agent/delegation/child-parts.tsx +1 -84
  96. package/src/agent/delegation/child-work.tsx +19 -5
  97. package/src/agent/delegation/interpret.ts +33 -54
  98. package/src/agent/delegation/model.ts +1 -1
  99. package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
  100. package/src/agent/file-edits/interpret.ts +120 -0
  101. package/src/agent/hooks/use-agent-conversation.ts +20 -0
  102. package/src/agent/i18n/en.ts +47 -5
  103. package/src/agent/i18n/fr.ts +39 -4
  104. package/src/agent/message-agent/interpret.ts +4 -3
  105. package/src/agent/publish-artifact/interpret.ts +14 -5
  106. package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
  107. package/src/agent/questions/interpret.ts +90 -0
  108. package/src/agent/questions/question-card.tsx +57 -0
  109. package/src/agent/questions/question-composer.tsx +257 -0
  110. package/src/agent/read/interpret.ts +34 -1
  111. package/src/agent/read/read-tool-view.tsx +20 -4
  112. package/src/agent/tool-views/built-in.tsx +19 -8
  113. package/src/agent/waits.ts +50 -0
  114. package/src/artifacts/artifacts.css +36 -0
  115. package/src/artifacts/edit-session.tsx +15 -1
  116. package/src/artifacts/frame.tsx +3 -2
  117. package/src/artifacts/messages.ts +54 -0
  118. package/src/artifacts/renderers/canvas/board-editor.tsx +37 -15
  119. package/src/artifacts/renderers/canvas/board.tsx +70 -8
  120. package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
  121. package/src/artifacts/renderers/canvas/controls.tsx +64 -30
  122. package/src/artifacts/renderers/canvas/focus.tsx +200 -56
  123. package/src/artifacts/renderers/canvas/gestures.ts +265 -0
  124. package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
  125. package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
  126. package/src/artifacts/renderers/canvas/page-size.ts +218 -0
  127. package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
  128. package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
  129. package/src/artifacts/viewer.tsx +15 -1
  130. package/src/index.ts +2 -0
  131. package/dist/chunk-5crvhjp2.js.map +0 -28
  132. /package/dist/{chunk-kes4ygmz.js.map → chunk-970s5nkn.js.map} +0 -0
  133. /package/dist/{chunk-fwb9mxwm.js.map → chunk-pxd07kvx.js.map} +0 -0
@@ -10,6 +10,7 @@ import {
10
10
  useBoardPreviews,
11
11
  boardPreviewSize,
12
12
  boardPreviewUrl,
13
+ useStartEditing,
13
14
  livePersonName,
14
15
  useLivePresence,
15
16
  moveItems,
@@ -30,28 +31,28 @@ import {
30
31
  canvasGraph,
31
32
  ArtifactLink,
32
33
  ArtifactEmbed
33
- } from "./chunk-001c4gnk.js";
34
+ } from "./chunk-kymx9y5e.js";
34
35
 
35
36
  // src/artifacts/renderers/canvas/canvas.tsx
36
37
  import { CANVAS_FIT_PADDING } from "@sixb/core/artifacts";
37
- import { cn as cn11 } from "@sixb/ui/lib/utils";
38
+ import { cn as cn15 } from "@sixb/ui/lib/utils";
38
39
  import {
39
40
  Background,
40
41
  BackgroundVariant,
41
42
  Panel as Panel3,
42
43
  ReactFlow,
43
44
  ReactFlowProvider,
44
- useReactFlow as useReactFlow2,
45
+ useReactFlow as useReactFlow3,
45
46
  useStore as useStore4,
46
- useStoreApi as useStoreApi4
47
+ useStoreApi as useStoreApi5
47
48
  } from "@xyflow/react";
48
49
  import {
49
50
  memo as memo5,
50
- useCallback as useCallback8,
51
- useEffect as useEffect8,
52
- useMemo as useMemo6,
53
- useRef as useRef8,
54
- useState as useState11
51
+ useCallback as useCallback11,
52
+ useEffect as useEffect12,
53
+ useMemo as useMemo9,
54
+ useRef as useRef13,
55
+ useState as useState14
55
56
  } from "react";
56
57
 
57
58
  // src/artifacts/renderers/canvas/arrows.tsx
@@ -71,7 +72,7 @@ import { AppWindow, ArrowUpRight, Link2, Maximize2 } from "lucide-react";
71
72
  import { memo, useSyncExternalStore as useSyncExternalStore2 } from "react";
72
73
 
73
74
  // src/artifacts/renderers/canvas/board.tsx
74
- import { CANVAS_FILE } from "@sixb/core/artifacts";
75
+ import { CANVAS_FILE, parseFrameEvent } from "@sixb/core/artifacts";
75
76
  import { cn } from "@sixb/ui/lib/utils";
76
77
  import { useStoreApi } from "@xyflow/react";
77
78
  import {
@@ -260,14 +261,21 @@ function LiveBoard({
260
261
  title,
261
262
  tile
262
263
  }) {
263
- const { version } = useContext(LiveBoardsContext);
264
+ const { version, interactive = false, gestures = null } = useContext(LiveBoardsContext);
264
265
  const live = useLive(id);
265
266
  const pages = usePagesVersion(version);
266
267
  const [ready, setReady] = useState(null);
267
268
  const running = live && pages !== null && ready === pages;
269
+ const usable = running && interactive;
270
+ const page = useRef(null);
271
+ const handle = useRef(null);
272
+ const [loads, setLoads] = useState(0);
273
+ useCanvasPort(id, gestures, handle, loads, page);
268
274
  return /* @__PURE__ */ jsxs("div", {
275
+ ref: page,
269
276
  className: "group/board relative size-full",
270
277
  "data-running": running ? "" : undefined,
278
+ "data-interactive": usable ? "" : undefined,
271
279
  children: [
272
280
  /* @__PURE__ */ jsx("div", {
273
281
  className: "size-full transition-[visibility] delay-300 group-data-[running]/board:invisible",
@@ -277,16 +285,40 @@ function LiveBoard({
277
285
  version: pages,
278
286
  entry: file,
279
287
  title,
280
- decorative: true,
288
+ decorative: !usable,
289
+ handle,
281
290
  className: "absolute inset-0 overflow-hidden rounded-[10px]",
282
291
  onEvent: (event) => {
283
- if (event.event === "ready")
284
- setReady(pages);
292
+ if (event.event !== "ready")
293
+ return;
294
+ setReady(pages);
295
+ setLoads((count) => count + 1);
285
296
  }
286
297
  }) : null
287
298
  ]
288
299
  });
289
300
  }
301
+ function useCanvasPort(id, gestures, handle, loads, page) {
302
+ useEffect(() => {
303
+ if (loads === 0 || !gestures)
304
+ return;
305
+ const channel = new MessageChannel;
306
+ channel.port1.onmessage = (message) => {
307
+ const event = parseFrameEvent(message.data);
308
+ if (event)
309
+ gestures.receive(id, event, page.current);
310
+ };
311
+ const tell = (moving, transfer = []) => {
312
+ handle.current?.send("canvas", { moving }, transfer).catch(() => {});
313
+ };
314
+ tell(gestures.moving(), [channel.port2]);
315
+ const stop = gestures.onMoving((moving) => tell(moving));
316
+ return () => {
317
+ stop();
318
+ channel.port1.close();
319
+ };
320
+ }, [id, gestures, handle, loads, page]);
321
+ }
290
322
 
291
323
  // src/artifacts/renderers/canvas/editing.tsx
292
324
  import { ARTIFACT_LIMITS } from "@sixb/core/artifacts";
@@ -2192,6 +2224,7 @@ var IconButton = forwardRef(function IconButton({ label, children, ...props }, r
2192
2224
  });
2193
2225
 
2194
2226
  // src/artifacts/renderers/canvas/controls.tsx
2227
+ import { cn as cn8 } from "@sixb/ui/lib/utils";
2195
2228
  import { Panel, useReactFlow, useStore as useStore2 } from "@xyflow/react";
2196
2229
  import { Maximize, Minus, Plus } from "lucide-react";
2197
2230
  import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
@@ -2203,65 +2236,84 @@ function CanvasControls({ padding }) {
2203
2236
  return /* @__PURE__ */ jsx9(Panel, {
2204
2237
  position: "bottom-left",
2205
2238
  className: "!m-3",
2206
- children: /* @__PURE__ */ jsxs8("div", {
2207
- className: "flex items-center gap-0.5 rounded-xl border border-border bg-background/90 p-1 shadow-[0_1px_2px_rgb(0_0_0/0.06),0_8px_24px_-12px_rgb(0_0_0/0.25)] backdrop-blur",
2208
- children: [
2209
- /* @__PURE__ */ jsx9(Control, {
2210
- label: messages.zoomOut,
2211
- onClick: () => zoomOut({ duration: DURATION }),
2212
- children: /* @__PURE__ */ jsx9(Minus, {
2213
- className: "size-4",
2214
- "aria-hidden": "true"
2215
- })
2216
- }),
2217
- /* @__PURE__ */ jsxs8("button", {
2218
- type: "button",
2219
- title: messages.actualSize,
2220
- onClick: () => void zoomTo(1, { duration: DURATION }),
2221
- className: "h-8 w-12 rounded-lg text-center text-xs font-medium text-muted-foreground tabular-nums outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
2222
- children: [
2223
- /* @__PURE__ */ jsx9("span", {
2224
- "aria-live": "polite",
2225
- children: messages.zoom(Math.round(zoom * 100))
2226
- }),
2227
- /* @__PURE__ */ jsxs8("span", {
2228
- className: "sr-only",
2229
- children: [
2230
- ", ",
2231
- messages.actualSize
2232
- ]
2233
- })
2234
- ]
2235
- }),
2236
- /* @__PURE__ */ jsx9(Control, {
2237
- label: messages.zoomIn,
2238
- onClick: () => zoomIn({ duration: DURATION }),
2239
- children: /* @__PURE__ */ jsx9(Plus, {
2240
- className: "size-4",
2241
- "aria-hidden": "true"
2239
+ children: /* @__PURE__ */ jsx9(ZoomBar, {
2240
+ zoom,
2241
+ fitLabel: messages.fitView,
2242
+ onZoomOut: () => zoomOut({ duration: DURATION }),
2243
+ onActualSize: () => void zoomTo(1, { duration: DURATION }),
2244
+ onZoomIn: () => zoomIn({ duration: DURATION }),
2245
+ onFit: () => void fitView({ padding, duration: DURATION })
2246
+ })
2247
+ });
2248
+ }
2249
+ function ZoomBar({
2250
+ zoom,
2251
+ fitLabel,
2252
+ onZoomOut,
2253
+ onActualSize,
2254
+ onZoomIn,
2255
+ onFit,
2256
+ className
2257
+ }) {
2258
+ const messages = useArtifactMessages().canvas;
2259
+ return /* @__PURE__ */ jsxs8("div", {
2260
+ className: cn8("flex items-center gap-0.5 rounded-xl border border-border bg-background/90 p-1 shadow-[0_1px_2px_rgb(0_0_0/0.06),0_8px_24px_-12px_rgb(0_0_0/0.25)] backdrop-blur", className),
2261
+ children: [
2262
+ /* @__PURE__ */ jsx9(Control, {
2263
+ label: messages.zoomOut,
2264
+ onClick: onZoomOut,
2265
+ children: /* @__PURE__ */ jsx9(Minus, {
2266
+ className: "size-4",
2267
+ "aria-hidden": "true"
2268
+ })
2269
+ }),
2270
+ /* @__PURE__ */ jsxs8("button", {
2271
+ type: "button",
2272
+ title: messages.actualSize,
2273
+ onClick: onActualSize,
2274
+ className: "h-8 w-12 rounded-lg text-center text-xs font-medium text-muted-foreground tabular-nums outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
2275
+ children: [
2276
+ /* @__PURE__ */ jsx9("span", {
2277
+ "aria-live": "polite",
2278
+ children: messages.zoom(Math.round(zoom * 100))
2279
+ }),
2280
+ /* @__PURE__ */ jsxs8("span", {
2281
+ className: "sr-only",
2282
+ children: [
2283
+ ", ",
2284
+ messages.actualSize
2285
+ ]
2242
2286
  })
2243
- }),
2244
- /* @__PURE__ */ jsx9("span", {
2245
- className: "mx-1 h-5 w-px bg-border",
2287
+ ]
2288
+ }),
2289
+ /* @__PURE__ */ jsx9(Control, {
2290
+ label: messages.zoomIn,
2291
+ onClick: onZoomIn,
2292
+ children: /* @__PURE__ */ jsx9(Plus, {
2293
+ className: "size-4",
2246
2294
  "aria-hidden": "true"
2247
- }),
2248
- /* @__PURE__ */ jsxs8(Control, {
2249
- label: messages.fitView,
2250
- onClick: () => void fitView({ padding, duration: DURATION }),
2251
- wide: true,
2252
- children: [
2253
- /* @__PURE__ */ jsx9(Maximize, {
2254
- className: "size-3.5",
2255
- "aria-hidden": "true"
2256
- }),
2257
- /* @__PURE__ */ jsx9("span", {
2258
- className: "text-xs font-medium",
2259
- children: messages.fit
2260
- })
2261
- ]
2262
2295
  })
2263
- ]
2264
- })
2296
+ }),
2297
+ /* @__PURE__ */ jsx9("span", {
2298
+ className: "mx-1 h-5 w-px bg-border",
2299
+ "aria-hidden": "true"
2300
+ }),
2301
+ /* @__PURE__ */ jsxs8(Control, {
2302
+ label: fitLabel,
2303
+ onClick: onFit,
2304
+ wide: true,
2305
+ children: [
2306
+ /* @__PURE__ */ jsx9(Maximize, {
2307
+ className: "size-3.5",
2308
+ "aria-hidden": "true"
2309
+ }),
2310
+ /* @__PURE__ */ jsx9("span", {
2311
+ className: "text-xs font-medium",
2312
+ children: messages.fit
2313
+ })
2314
+ ]
2315
+ })
2316
+ ]
2265
2317
  });
2266
2318
  }
2267
2319
  function Control({
@@ -2302,7 +2354,7 @@ import {
2302
2354
  DropdownMenuItem as DropdownMenuItem2,
2303
2355
  DropdownMenuTrigger as DropdownMenuTrigger2
2304
2356
  } from "@sixb/ui/components";
2305
- import { cn as cn8 } from "@sixb/ui/lib/utils";
2357
+ import { cn as cn9 } from "@sixb/ui/lib/utils";
2306
2358
  import { Panel as Panel2 } from "@xyflow/react";
2307
2359
  import {
2308
2360
  ChevronDown,
@@ -2383,7 +2435,7 @@ function CanvasToolbar({
2383
2435
  /* @__PURE__ */ jsxs9(DropdownMenuTrigger2, {
2384
2436
  "aria-label": messages.shape,
2385
2437
  title: messages.shape,
2386
- className: cn8(TOOL, "w-auto gap-0.5 px-1.5"),
2438
+ className: cn9(TOOL, "w-auto gap-0.5 px-1.5"),
2387
2439
  children: [
2388
2440
  /* @__PURE__ */ jsx10(RectangleHorizontal, {}),
2389
2441
  /* @__PURE__ */ jsx10(ChevronDown, {
@@ -2427,7 +2479,7 @@ function CanvasToolbar({
2427
2479
  className: "flex size-6 items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring",
2428
2480
  children: /* @__PURE__ */ jsx10("span", {
2429
2481
  "aria-hidden": "true",
2430
- className: cn8("size-[18px] rounded-full ring-1 ring-[color-mix(in_oklab,var(--foreground)_14%,transparent)] transition-shadow", tone === entry && "ring-2 ring-foreground ring-offset-2 ring-offset-background"),
2482
+ className: cn9("size-[18px] rounded-full ring-1 ring-[color-mix(in_oklab,var(--foreground)_14%,transparent)] transition-shadow", tone === entry && "ring-2 ring-foreground ring-offset-2 ring-offset-background"),
2431
2483
  style: { background: swatch(entry, toned) }
2432
2484
  })
2433
2485
  }, entry ?? "default"))
@@ -2560,7 +2612,7 @@ function Segment({
2560
2612
  title: label,
2561
2613
  "aria-pressed": pressed,
2562
2614
  onClick,
2563
- className: cn8("flex h-7 min-w-7 items-center justify-center rounded-md px-1.5 text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4", pressed && "bg-background text-foreground shadow-sm"),
2615
+ className: cn9("flex h-7 min-w-7 items-center justify-center rounded-md px-1.5 text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4", pressed && "bg-background text-foreground shadow-sm"),
2564
2616
  children
2565
2617
  });
2566
2618
  }
@@ -2870,14 +2922,15 @@ function useReadGraph(graph, store) {
2870
2922
  }
2871
2923
 
2872
2924
  // src/artifacts/renderers/canvas/focus.tsx
2925
+ import { cn as cn14 } from "@sixb/ui/lib/utils";
2873
2926
  import { ArrowLeft, ChevronLeft, ChevronRight } from "lucide-react";
2874
- import { useCallback as useCallback6, useEffect as useEffect7, useState as useState10 } from "react";
2927
+ import { useCallback as useCallback9, useEffect as useEffect10, useMemo as useMemo7, useState as useState13 } from "react";
2875
2928
 
2876
2929
  // src/artifacts/renderers/canvas/board-editor.tsx
2877
2930
  import { uploadFile } from "@sixb/client";
2878
2931
  import {
2879
2932
  ARTIFACT_LIMITS as ARTIFACT_LIMITS3,
2880
- parseFrameEvent
2933
+ parseFrameEvent as parseFrameEvent2
2881
2934
  } from "@sixb/core/artifacts";
2882
2935
  import {
2883
2936
  boardFilePath,
@@ -2888,7 +2941,7 @@ import {
2888
2941
  } from "@sixb/core/artifacts/live";
2889
2942
  import { Popover, PopoverContent, PopoverTrigger } from "@sixb/ui/components";
2890
2943
  import { useLocale as useLocale2 } from "@sixb/ui/lib/i18n";
2891
- import { cn as cn10 } from "@sixb/ui/lib/utils";
2944
+ import { cn as cn11 } from "@sixb/ui/lib/utils";
2892
2945
  import { Code2, ImageIcon as ImageIcon2, LoaderCircle as LoaderCircle3, MessageSquarePlus as MessageSquarePlus3, Paintbrush } from "lucide-react";
2893
2946
  import {
2894
2947
  forwardRef as forwardRef2,
@@ -2901,7 +2954,7 @@ import {
2901
2954
  } from "react";
2902
2955
 
2903
2956
  // src/artifacts/renderers/canvas/board-properties.tsx
2904
- import { cn as cn9 } from "@sixb/ui/lib/utils";
2957
+ import { cn as cn10 } from "@sixb/ui/lib/utils";
2905
2958
  import {
2906
2959
  AlignCenter,
2907
2960
  AlignLeft,
@@ -3081,7 +3134,7 @@ function ColorField({
3081
3134
  className: "flex size-5 items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring",
3082
3135
  children: /* @__PURE__ */ jsx12("span", {
3083
3136
  "aria-hidden": "true",
3084
- className: cn9("size-4 rounded-full ring-1 ring-[color-mix(in_oklab,var(--foreground)_16%,transparent)]", value?.toLowerCase() === color && "ring-2 ring-foreground ring-offset-1 ring-offset-popover"),
3137
+ className: cn10("size-4 rounded-full ring-1 ring-[color-mix(in_oklab,var(--foreground)_16%,transparent)]", value?.toLowerCase() === color && "ring-2 ring-foreground ring-offset-1 ring-offset-popover"),
3085
3138
  style: { background: color }
3086
3139
  })
3087
3140
  }, color))
@@ -3132,7 +3185,7 @@ function ValueField({
3132
3185
  className: "flex items-center gap-1",
3133
3186
  children: [
3134
3187
  /* @__PURE__ */ jsxs10("div", {
3135
- className: cn9("flex h-7 w-[8.5rem] items-center gap-1.5 rounded-md border bg-background px-1.5 text-xs focus-within:ring-2 focus-within:ring-ring", invalid ? "border-destructive" : "border-border"),
3188
+ className: cn10("flex h-7 w-[8.5rem] items-center gap-1.5 rounded-md border bg-background px-1.5 text-xs focus-within:ring-2 focus-within:ring-ring", invalid ? "border-destructive" : "border-border"),
3136
3189
  children: [
3137
3190
  swatch !== undefined ? /* @__PURE__ */ jsx12("span", {
3138
3191
  "aria-hidden": "true",
@@ -3195,7 +3248,7 @@ function Segment2({
3195
3248
  title: label,
3196
3249
  "aria-pressed": pressed,
3197
3250
  onClick,
3198
- className: cn9("flex h-6 min-w-7 items-center justify-center rounded-md px-1.5 text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5", pressed && "bg-background text-foreground shadow-sm"),
3251
+ className: cn10("flex h-6 min-w-7 items-center justify-center rounded-md px-1.5 text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5", pressed && "bg-background text-foreground shadow-sm"),
3199
3252
  children
3200
3253
  });
3201
3254
  }
@@ -3475,6 +3528,7 @@ function useBoardFrame({
3475
3528
  function BoardStage({
3476
3529
  version,
3477
3530
  board,
3531
+ size,
3478
3532
  title,
3479
3533
  scale,
3480
3534
  live,
@@ -3489,7 +3543,9 @@ function BoardStage({
3489
3543
  onPick,
3490
3544
  onOpenPin,
3491
3545
  onSubmitDraft,
3492
- onCancelDraft
3546
+ onCancelDraft,
3547
+ onContentHeight,
3548
+ onZoom
3493
3549
  }) {
3494
3550
  const messages = useArtifactMessages().canvas;
3495
3551
  const frame = useBoardFrame({ version, board, live });
@@ -3521,13 +3577,17 @@ function BoardStage({
3521
3577
  }, [draft]);
3522
3578
  const port = useRef7(null);
3523
3579
  const onEditRef = useRef7(() => {});
3580
+ const onZoomRef = useRef7(onZoom);
3581
+ onZoomRef.current = onZoom;
3524
3582
  useEffect6(() => {
3525
3583
  if (frame.loads === 0)
3526
3584
  return;
3527
3585
  const channel = new MessageChannel;
3528
3586
  channel.port1.onmessage = (message) => {
3529
- const event = parseFrameEvent(message.data);
3530
- if (event?.event.startsWith("edit."))
3587
+ const event = parseFrameEvent2(message.data);
3588
+ if (event?.event === "zoom")
3589
+ onZoomRef.current?.(event.params);
3590
+ else if (event?.event.startsWith("edit."))
3531
3591
  onEditRef.current(event);
3532
3592
  };
3533
3593
  port.current = { mine: channel.port1, handed: channel.port2 };
@@ -3546,10 +3606,10 @@ function BoardStage({
3546
3606
  const x = at?.x ?? rect.x + rect.width;
3547
3607
  const y = at?.y ?? rect.y;
3548
3608
  return {
3549
- x: Math.min(1, Math.max(0, x / board.w)),
3550
- y: Math.min(1, Math.max(0, y / board.h))
3609
+ x: Math.min(1, Math.max(0, x / size.w)),
3610
+ y: Math.min(1, Math.max(0, y / size.h))
3551
3611
  };
3552
- }, [board.w, board.h]);
3612
+ }, [size.w, size.h]);
3553
3613
  const onEvent = useCallback5((event) => {
3554
3614
  if (event.event === "ready") {
3555
3615
  picked.current = null;
@@ -3558,8 +3618,10 @@ function BoardStage({
3558
3618
  frame.ready();
3559
3619
  } else if (event.event === "press") {
3560
3620
  onPress(event.params.text);
3621
+ } else if (event.event === "size") {
3622
+ onContentHeight?.(event.params.height);
3561
3623
  }
3562
- }, [frame, onPress]);
3624
+ }, [frame, onPress, onContentHeight]);
3563
3625
  onEditRef.current = (event) => {
3564
3626
  if (moved.current)
3565
3627
  return;
@@ -3581,7 +3643,7 @@ function BoardStage({
3581
3643
  ...target.label ? { label: target.label } : {},
3582
3644
  ...target.address === "body" ? { anchor: title } : {},
3583
3645
  point: point(at, target.rect),
3584
- under: Math.min(1, (target.rect.y + target.rect.height) / board.h)
3646
+ under: Math.min(1, (target.rect.y + target.rect.height) / size.h)
3585
3647
  });
3586
3648
  return;
3587
3649
  }
@@ -3616,7 +3678,7 @@ function BoardStage({
3616
3678
  className: "absolute inset-0 overflow-hidden rounded-[inherit]",
3617
3679
  children: /* @__PURE__ */ jsx13("div", {
3618
3680
  className: "absolute top-0 left-0 origin-top-left",
3619
- style: { width: board.w, height: board.h, transform: `scale(${scale})` },
3681
+ style: { width: size.w, height: size.h, transform: `scale(${scale})` },
3620
3682
  children: /* @__PURE__ */ jsx13(ArtifactFrame, {
3621
3683
  version: frame.shows,
3622
3684
  entry: board.file,
@@ -3631,14 +3693,14 @@ function BoardStage({
3631
3693
  })
3632
3694
  }),
3633
3695
  /* @__PURE__ */ jsxs11("div", {
3634
- className: "pointer-events-none absolute inset-0",
3696
+ className: "pointer-events-none absolute inset-0 z-10",
3635
3697
  "data-board-overlay": "",
3636
3698
  children: [
3637
3699
  pins.map((pin, index) => {
3638
3700
  const at = pinPoint(pin, pin.point ? 0 : index);
3639
3701
  return /* @__PURE__ */ jsx13("div", {
3640
3702
  className: "absolute",
3641
- style: { left: at.x * board.w * scale, top: at.y * board.h * scale },
3703
+ style: { left: at.x * size.w * scale, top: at.y * size.h * scale },
3642
3704
  children: /* @__PURE__ */ jsx13(CommentPin, {
3643
3705
  number: pin.number,
3644
3706
  label: pin.label,
@@ -3654,7 +3716,7 @@ function BoardStage({
3654
3716
  }) : null,
3655
3717
  draft ? /* @__PURE__ */ jsxs11("div", {
3656
3718
  className: "absolute",
3657
- style: { left: draft.point.x * board.w * scale, top: draft.point.y * board.h * scale },
3719
+ style: { left: draft.point.x * size.w * scale, top: draft.point.y * size.h * scale },
3658
3720
  children: [
3659
3721
  /* @__PURE__ */ jsx13(CommentPin, {
3660
3722
  label: messages.comments.newPin,
@@ -3663,11 +3725,11 @@ function BoardStage({
3663
3725
  draft: true
3664
3726
  }),
3665
3727
  /* @__PURE__ */ jsx13("div", {
3666
- className: cn10("absolute", draftAbove(draft) ? "bottom-9" : null),
3728
+ className: cn11("absolute", draftAbove(draft) ? "bottom-9" : null),
3667
3729
  style: {
3668
- ...cardPlace(draft.point.x * board.w * scale, board.w * scale),
3730
+ ...cardPlace(draft.point.x * size.w * scale, size.w * scale),
3669
3731
  ...draftAbove(draft) ? {} : {
3670
- top: Math.max(0, ((draft.under ?? draft.point.y) - draft.point.y) * board.h * scale) + 10
3732
+ top: Math.max(0, ((draft.under ?? draft.point.y) - draft.point.y) * size.h * scale) + 10
3671
3733
  }
3672
3734
  },
3673
3735
  children: /* @__PURE__ */ jsx13(DraftCard, {
@@ -3681,6 +3743,7 @@ function BoardStage({
3681
3743
  editing && selected ? /* @__PURE__ */ jsx13(ElementTools, {
3682
3744
  target: selected,
3683
3745
  scale,
3746
+ width: size.w,
3684
3747
  board,
3685
3748
  version,
3686
3749
  live,
@@ -3717,7 +3780,7 @@ function HoverTag({ target, scale }) {
3717
3780
  const top = target.rect.y * scale;
3718
3781
  return /* @__PURE__ */ jsx13("div", {
3719
3782
  "aria-hidden": "true",
3720
- className: cn10("absolute max-w-64 truncate rounded-md bg-[#0a84ff] px-1.5 py-0.5 text-[11px] leading-4 font-medium text-white shadow-sm", top < 24 ? "translate-y-1" : "-translate-y-[calc(100%+5px)]"),
3783
+ className: cn11("absolute max-w-64 truncate rounded-md bg-[#0a84ff] px-1.5 py-0.5 text-[11px] leading-4 font-medium text-white shadow-sm", top < 24 ? "translate-y-1" : "-translate-y-[calc(100%+5px)]"),
3721
3784
  style: { left: target.rect.x * scale - 3, top },
3722
3785
  children: name
3723
3786
  });
@@ -3725,6 +3788,7 @@ function HoverTag({ target, scale }) {
3725
3788
  function ElementTools({
3726
3789
  target,
3727
3790
  scale,
3791
+ width: pageWidth,
3728
3792
  board,
3729
3793
  version,
3730
3794
  live,
@@ -3740,7 +3804,7 @@ function ElementTools({
3740
3804
  useLayoutEffect2(() => {
3741
3805
  setWidth(toolbar.current?.offsetWidth ?? 0);
3742
3806
  });
3743
- const left = Math.max(4, Math.min(rect.x * scale, board.w * scale - width - 4));
3807
+ const left = Math.max(4, Math.min(rect.x * scale, pageWidth * scale - width - 4));
3744
3808
  const above = rect.y * scale >= 44;
3745
3809
  const top = above ? rect.y * scale - 40 : (rect.y + rect.height) * scale + 8;
3746
3810
  return /* @__PURE__ */ jsxs11("div", {
@@ -3989,8 +4053,883 @@ var ToolButton = forwardRef2(function ToolButton({ label, children, ...props },
3989
4053
  });
3990
4054
  });
3991
4055
 
3992
- // src/artifacts/renderers/canvas/focus.tsx
4056
+ // src/artifacts/renderers/canvas/page-resize.tsx
4057
+ import { cn as cn12 } from "@sixb/ui/lib/utils";
4058
+ import {
4059
+ useCallback as useCallback6,
4060
+ useEffect as useEffect7,
4061
+ useRef as useRef8,
4062
+ useState as useState10
4063
+ } from "react";
4064
+
4065
+ // src/artifacts/renderers/canvas/page-size.ts
4066
+ import { ARTIFACT_LIMITS as ARTIFACT_LIMITS4 } from "@sixb/core/artifacts";
4067
+ var SCREENS = [
4068
+ { name: "phone", w: 390, h: 844 },
4069
+ { name: "tablet", w: 768, h: 1024 },
4070
+ { name: "laptop", w: 1280 },
4071
+ { name: "desktop", w: 1440, h: 900 }
4072
+ ];
4073
+ function isScreen(name) {
4074
+ return SCREENS.some((screen) => screen.name === name);
4075
+ }
4076
+ var PAGE_MIN = { w: 240, h: 160 };
4077
+ var PAGE_MAX = ARTIFACT_LIMITS4.maxCanvasItemSize;
4078
+ var GRID2 = 8;
4079
+ var SNAP_REACH = 8;
4080
+ var ZOOM_MIN = 0.1;
4081
+ var ZOOM_MAX = 2.5;
4082
+ var ZOOM_STEP = 1.2;
4083
+ function clampSize(size, least = PAGE_MIN) {
4084
+ return {
4085
+ w: Math.round(Math.min(PAGE_MAX, Math.max(least.w, size.w))),
4086
+ h: Math.round(Math.min(PAGE_MAX, Math.max(least.h, size.h)))
4087
+ };
4088
+ }
4089
+ function sizeSuggestions(board, content) {
4090
+ const least = { w: Math.min(PAGE_MIN.w, board.w), h: Math.min(PAGE_MIN.h, board.h) };
4091
+ const full = content === null ? [] : [{ name: "full", h: clampSize({ ...board, h: content }, least).h }];
4092
+ const widths = distinct([{ name: "board", w: board.w }, ...SCREENS], (each) => each.w);
4093
+ const heights = distinct([{ name: "board", h: board.h }, ...full], (each) => each.h);
4094
+ const sizes = distinct([{ name: "board", w: board.w, h: board.h }, ...SCREENS.filter((screen) => ("h" in screen))], (each) => `${each.w}\xD7${each.h}`);
4095
+ return { widths, heights, sizes, least };
4096
+ }
4097
+ function distinct(suggestions, key) {
4098
+ const seen = new Set;
4099
+ return suggestions.filter((suggestion) => {
4100
+ const value = key(suggestion);
4101
+ if (seen.has(value))
4102
+ return false;
4103
+ seen.add(value);
4104
+ return true;
4105
+ });
4106
+ }
4107
+ function snapSize(raw, edges, suggestions, reach, free = false) {
4108
+ const { least } = suggestions;
4109
+ if (free)
4110
+ return { size: clampSize(raw, least), w: null, h: null };
4111
+ if (edges.w && edges.h) {
4112
+ const size = nearest(suggestions.sizes, (each) => Math.abs((each.w ?? 0) - raw.w) <= reach && Math.abs((each.h ?? 0) - raw.h) <= reach ? Math.hypot((each.w ?? 0) - raw.w, (each.h ?? 0) - raw.h) : null);
4113
+ if (size?.w !== undefined && size.h !== undefined) {
4114
+ return { size: clampSize({ w: size.w, h: size.h }, least), w: size, h: size };
4115
+ }
4116
+ }
4117
+ const w = edges.w ? nearestOn(suggestions.widths, "w", raw.w, reach) : null;
4118
+ const h = edges.h ? nearestOn(suggestions.heights, "h", raw.h, reach) : null;
4119
+ const size = clampSize({
4120
+ w: edges.w ? w?.w ?? onGrid(raw.w) : raw.w,
4121
+ h: edges.h ? h?.h ?? onGrid(raw.h) : raw.h
4122
+ }, least);
4123
+ return { size, w, h };
4124
+ }
4125
+ function nearestOn(suggestions, axis, value, reach) {
4126
+ return nearest(suggestions, (each) => {
4127
+ const at = each[axis];
4128
+ return at !== undefined && Math.abs(at - value) <= reach ? Math.abs(at - value) : null;
4129
+ });
4130
+ }
4131
+ function nearest(suggestions, distance) {
4132
+ let best = null;
4133
+ let least = Number.POSITIVE_INFINITY;
4134
+ for (const suggestion of suggestions) {
4135
+ const away = distance(suggestion);
4136
+ if (away === null || away >= least)
4137
+ continue;
4138
+ best = suggestion;
4139
+ least = away;
4140
+ }
4141
+ return best;
4142
+ }
4143
+ function onGrid(value) {
4144
+ return Math.round(value / GRID2) * GRID2;
4145
+ }
4146
+ function fitScale(page, room, how) {
4147
+ const whole = clampZoom(Math.min(room.width / page.w, room.height / page.h));
4148
+ if (how === "whole" || page.h <= page.w)
4149
+ return whole;
4150
+ const width = clampZoom(Math.min(room.width / page.w, Math.max(whole, 1)));
4151
+ return whole >= width * 0.8 ? whole : width;
4152
+ }
4153
+ function zoomStep(scale, direction) {
4154
+ return clampZoom(direction === "in" ? scale * ZOOM_STEP : scale / ZOOM_STEP);
4155
+ }
4156
+ function clampZoom(scale) {
4157
+ return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, scale));
4158
+ }
4159
+ function sameSize(left, right) {
4160
+ return left.w === right.w && left.h === right.h;
4161
+ }
4162
+
4163
+ // src/artifacts/renderers/canvas/page-resize.tsx
3993
4164
  import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
4165
+ var EDGES = {
4166
+ right: { w: true, h: false },
4167
+ bottom: { w: false, h: true },
4168
+ corner: { w: true, h: true }
4169
+ };
4170
+ var KEY_STEP = 8;
4171
+ var KEY_LEAP = 64;
4172
+ var SCROLL_ZONE = 40;
4173
+ var SCROLL_SPEED = SNAP_REACH * 2;
4174
+ var DETENT_MS = 500;
4175
+ function PageResizer({
4176
+ size,
4177
+ scale,
4178
+ suggestions,
4179
+ stage,
4180
+ onStart,
4181
+ onResize,
4182
+ onEnd
4183
+ }) {
4184
+ const messages = useArtifactMessages().canvas.size;
4185
+ const [drag, setDrag] = useState10(null);
4186
+ const dragging = useRef8(null);
4187
+ const update = useCallback6((next) => {
4188
+ dragging.current = next;
4189
+ setDrag(next);
4190
+ }, []);
4191
+ const move = useCallback6((at, free) => {
4192
+ const current = dragging.current;
4193
+ if (!current)
4194
+ return;
4195
+ const edges = EDGES[current.edge];
4196
+ const dx = at.x - current.x + (stage ? stage.scrollLeft - current.scrolled.x : 0);
4197
+ const dy = at.y - current.y + (stage ? stage.scrollTop - current.scrolled.y : 0);
4198
+ const raw = {
4199
+ w: current.from.w + (edges.w ? dx / scale : 0),
4200
+ h: current.from.h + (edges.h ? dy / scale : 0)
4201
+ };
4202
+ const snapped = snapSize(raw, edges, suggestions, SNAP_REACH / scale, free);
4203
+ update({ ...current, at, free, snapped });
4204
+ onResize(snapped.size);
4205
+ }, [stage, scale, suggestions, onResize, update]);
4206
+ const end = useCallback6((cancel) => {
4207
+ const current = dragging.current;
4208
+ if (!current)
4209
+ return;
4210
+ if (cancel)
4211
+ onResize(current.from);
4212
+ update(null);
4213
+ onEnd(cancel ? null : current.snapped);
4214
+ }, [onResize, onEnd, update]);
4215
+ const edge = drag?.edge;
4216
+ useEffect7(() => {
4217
+ if (!edge || !stage)
4218
+ return;
4219
+ const edges = EDGES[edge];
4220
+ let frame = 0;
4221
+ let resting = null;
4222
+ const roll = (now) => {
4223
+ frame = requestAnimationFrame(roll);
4224
+ const current = dragging.current;
4225
+ if (!current)
4226
+ return;
4227
+ const held = current.snapped.h ?? current.snapped.w;
4228
+ if (held && held !== resting?.at)
4229
+ resting = { at: held, until: now + DETENT_MS };
4230
+ if (held && resting && now < resting.until)
4231
+ return;
4232
+ const rect = stage.getBoundingClientRect();
4233
+ const speed = (past) => Math.min(1, Math.max(0, past / SCROLL_ZONE)) * SCROLL_SPEED;
4234
+ const x = edges.w ? speed(current.at.x - Math.max(rect.right - SCROLL_ZONE, current.x)) : 0;
4235
+ const y = edges.h ? speed(current.at.y - Math.max(rect.bottom - SCROLL_ZONE, current.y)) : 0;
4236
+ if (x === 0 && y === 0)
4237
+ return;
4238
+ stage.scrollBy(x, y);
4239
+ move(current.at, current.free);
4240
+ };
4241
+ frame = requestAnimationFrame(roll);
4242
+ return () => cancelAnimationFrame(frame);
4243
+ }, [edge, stage, move]);
4244
+ useEffect7(() => {
4245
+ if (!drag)
4246
+ return;
4247
+ const onKey = (event) => {
4248
+ if (event.key === "Escape") {
4249
+ event.preventDefault();
4250
+ event.stopPropagation();
4251
+ end(true);
4252
+ } else if (event.key === "Alt") {
4253
+ const current = dragging.current;
4254
+ if (current)
4255
+ move(current.at, event.type === "keydown");
4256
+ }
4257
+ };
4258
+ window.addEventListener("keydown", onKey, true);
4259
+ window.addEventListener("keyup", onKey, true);
4260
+ return () => {
4261
+ window.removeEventListener("keydown", onKey, true);
4262
+ window.removeEventListener("keyup", onKey, true);
4263
+ };
4264
+ }, [drag, end, move]);
4265
+ const start = (edge) => (event) => {
4266
+ if (event.button !== 0)
4267
+ return;
4268
+ event.preventDefault();
4269
+ event.stopPropagation();
4270
+ event.currentTarget.setPointerCapture(event.pointerId);
4271
+ onStart();
4272
+ const at = { x: event.clientX, y: event.clientY };
4273
+ update({
4274
+ edge,
4275
+ from: size,
4276
+ x: at.x,
4277
+ y: at.y,
4278
+ pointer: event.pointerId,
4279
+ scrolled: { x: stage?.scrollLeft ?? 0, y: stage?.scrollTop ?? 0 },
4280
+ at,
4281
+ free: event.altKey,
4282
+ snapped: { size, w: null, h: null }
4283
+ });
4284
+ };
4285
+ const handlers = (edge) => ({
4286
+ onPointerDown: start(edge),
4287
+ onPointerMove: (event) => {
4288
+ if (dragging.current?.pointer !== event.pointerId)
4289
+ return;
4290
+ move({ x: event.clientX, y: event.clientY }, event.altKey);
4291
+ },
4292
+ onPointerUp: (event) => {
4293
+ if (dragging.current?.pointer === event.pointerId)
4294
+ end(false);
4295
+ },
4296
+ onPointerCancel: (event) => {
4297
+ if (dragging.current?.pointer === event.pointerId)
4298
+ end(true);
4299
+ }
4300
+ });
4301
+ const set = (next, by = {}) => {
4302
+ const size = clampSize(next, suggestions.least);
4303
+ onStart();
4304
+ onResize(size);
4305
+ onEnd({ size, w: by.w ?? null, h: by.h ?? null });
4306
+ };
4307
+ const onKeyDown = (edge) => (event) => {
4308
+ const edges = EDGES[edge];
4309
+ const by = event.shiftKey ? KEY_LEAP : KEY_STEP;
4310
+ const moves = edges.w ? { ArrowLeft: { ...size, w: size.w - by }, ArrowRight: { ...size, w: size.w + by } } : {};
4311
+ if (edges.h) {
4312
+ moves.ArrowUp = { ...size, h: size.h - by };
4313
+ moves.ArrowDown = { ...size, h: size.h + by };
4314
+ }
4315
+ const next = moves[event.key];
4316
+ if (!next)
4317
+ return;
4318
+ event.preventDefault();
4319
+ event.stopPropagation();
4320
+ set(next);
4321
+ };
4322
+ const full = suggestions.heights.find((each) => each.name === "full");
4323
+ const edges = edge ? EDGES[edge] : null;
4324
+ return /* @__PURE__ */ jsxs12("div", {
4325
+ className: "pointer-events-none absolute inset-0 z-[5]",
4326
+ "data-page-resizer": "",
4327
+ children: [
4328
+ drag ? /* @__PURE__ */ jsx14("div", {
4329
+ className: "absolute inset-0 rounded-[inherit] ring-1 ring-primary",
4330
+ "aria-hidden": true
4331
+ }) : null,
4332
+ drag && edges ? /* @__PURE__ */ jsx14(Guides, {
4333
+ size: drag.snapped.size,
4334
+ scale,
4335
+ edges,
4336
+ drag,
4337
+ suggestions
4338
+ }) : null,
4339
+ /* @__PURE__ */ jsx14(Handle3, {
4340
+ edge: "right",
4341
+ label: messages.resizeWidth,
4342
+ value: size.w,
4343
+ active: edge === "right",
4344
+ dragging: drag !== null,
4345
+ size,
4346
+ scale,
4347
+ chips: suggestions.widths,
4348
+ onKeyDown: onKeyDown("right"),
4349
+ onPick: (suggestion) => set({ ...size, w: suggestion.w ?? size.w }, { w: suggestion }),
4350
+ ...handlers("right")
4351
+ }),
4352
+ /* @__PURE__ */ jsx14(Handle3, {
4353
+ edge: "bottom",
4354
+ label: messages.resizeHeight,
4355
+ value: size.h,
4356
+ active: edge === "bottom",
4357
+ dragging: drag !== null,
4358
+ size,
4359
+ scale,
4360
+ chips: suggestions.heights,
4361
+ onKeyDown: onKeyDown("bottom"),
4362
+ onPick: (suggestion) => set({ ...size, h: suggestion.h ?? size.h }, { h: suggestion }),
4363
+ onDoubleClick: full?.h === undefined ? undefined : () => set({ ...size, h: full.h ?? size.h }, { h: full }),
4364
+ ...handlers("bottom")
4365
+ }),
4366
+ /* @__PURE__ */ jsx14(Handle3, {
4367
+ edge: "corner",
4368
+ label: messages.resizeBoth,
4369
+ value: size.w,
4370
+ active: edge === "corner",
4371
+ dragging: drag !== null,
4372
+ size,
4373
+ scale,
4374
+ chips: suggestions.sizes,
4375
+ onKeyDown: onKeyDown("corner"),
4376
+ onPick: (suggestion) => set({ w: suggestion.w ?? size.w, h: suggestion.h ?? size.h }, { w: suggestion, h: suggestion }),
4377
+ ...handlers("corner")
4378
+ }),
4379
+ drag ? /* @__PURE__ */ jsx14(Readout, {
4380
+ drag,
4381
+ scale
4382
+ }) : null
4383
+ ]
4384
+ });
4385
+ }
4386
+ var HANDLE_PLACES = {
4387
+ right: "top-0 -right-[7px] h-full w-3.5 cursor-ew-resize",
4388
+ bottom: "left-0 -bottom-[7px] h-3.5 w-full cursor-ns-resize",
4389
+ corner: "-right-2.5 -bottom-2.5 size-5 cursor-nwse-resize"
4390
+ };
4391
+ function Handle3({
4392
+ edge,
4393
+ label,
4394
+ value,
4395
+ active,
4396
+ dragging,
4397
+ size,
4398
+ scale,
4399
+ chips,
4400
+ onKeyDown,
4401
+ onPick,
4402
+ onDoubleClick,
4403
+ ...pointer
4404
+ }) {
4405
+ const messages = useArtifactMessages().canvas.size;
4406
+ const [offering, setOffering] = useState10(false);
4407
+ const onFocus = (event) => {
4408
+ if (event.target.matches(":focus-visible"))
4409
+ setOffering(true);
4410
+ };
4411
+ const onBlur = (event) => {
4412
+ if (!event.currentTarget.contains(event.relatedTarget))
4413
+ setOffering(false);
4414
+ };
4415
+ return /* @__PURE__ */ jsxs12("div", {
4416
+ onFocus,
4417
+ onBlur,
4418
+ children: [
4419
+ /* @__PURE__ */ jsxs12("div", {
4420
+ role: "separator",
4421
+ tabIndex: 0,
4422
+ "aria-label": label,
4423
+ "aria-orientation": edge === "bottom" ? "horizontal" : "vertical",
4424
+ "aria-valuenow": value,
4425
+ "aria-valuetext": messages.dimensions(size.w, size.h),
4426
+ title: edge === "bottom" ? messages.bottomHint : label,
4427
+ "data-edge": edge,
4428
+ "data-active": active ? "" : undefined,
4429
+ className: cn12("group/edge pointer-events-auto absolute touch-none outline-none", HANDLE_PLACES[edge]),
4430
+ onKeyDown,
4431
+ onDoubleClick: (event) => {
4432
+ event.stopPropagation();
4433
+ onDoubleClick?.();
4434
+ },
4435
+ ...pointer,
4436
+ children: [
4437
+ edge === "corner" ? null : /* @__PURE__ */ jsx14("span", {
4438
+ "aria-hidden": true,
4439
+ className: cn12("absolute bg-primary opacity-0 transition-opacity duration-150 group-hover/edge:opacity-60 group-data-[active]/edge:opacity-0", edge === "right" ? "inset-y-0 left-1/2 w-px" : "inset-x-0 top-1/2 h-px")
4440
+ }),
4441
+ /* @__PURE__ */ jsx14("span", {
4442
+ "aria-hidden": true,
4443
+ className: cn12("sixb-resize-handle absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 transition-opacity duration-150 group-focus-visible/edge:opacity-100 group-focus-visible/edge:ring-2 group-focus-visible/edge:ring-ring group-hover/page:opacity-100 [@media(hover:none)]:opacity-100", dragging ? "opacity-100" : "opacity-0")
4444
+ })
4445
+ ]
4446
+ }),
4447
+ offering && !dragging ? /* @__PURE__ */ jsx14("div", {
4448
+ role: "group",
4449
+ "aria-label": messages.suggestions,
4450
+ className: "pointer-events-auto absolute z-10 flex max-w-72 flex-wrap justify-end gap-1",
4451
+ style: chipsPlace(edge, size, scale),
4452
+ children: chips.map((chip) => /* @__PURE__ */ jsxs12("button", {
4453
+ type: "button",
4454
+ onClick: () => onPick(chip),
4455
+ className: "rounded-md border border-border bg-background/95 px-1.5 py-0.5 text-[11px] leading-4 font-medium whitespace-nowrap text-foreground shadow-sm outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring",
4456
+ children: [
4457
+ messages.names[chip.name],
4458
+ /* @__PURE__ */ jsx14("span", {
4459
+ className: "ml-1 text-muted-foreground tabular-nums",
4460
+ children: messages.dimension(edge === "bottom" ? undefined : chip.w, edge === "right" ? undefined : chip.h)
4461
+ })
4462
+ ]
4463
+ }, `${chip.name}-${chip.w ?? ""}-${chip.h ?? ""}`))
4464
+ }) : null
4465
+ ]
4466
+ });
4467
+ }
4468
+ function chipsPlace(edge, size, scale) {
4469
+ const right = size.w * scale;
4470
+ const bottom = size.h * scale;
4471
+ if (edge === "right")
4472
+ return { left: right - 14, top: bottom / 2, transform: "translate(-100%, -50%)" };
4473
+ if (edge === "bottom")
4474
+ return { left: right / 2, top: bottom - 14, transform: "translate(-50%, -100%)" };
4475
+ return { left: right - 14, top: bottom - 14, transform: "translate(-100%, -100%)" };
4476
+ }
4477
+ function Guides({
4478
+ size,
4479
+ scale,
4480
+ edges,
4481
+ drag,
4482
+ suggestions
4483
+ }) {
4484
+ const width = size.w * scale;
4485
+ const height = size.h * scale;
4486
+ const { w, h } = drag.snapped;
4487
+ return /* @__PURE__ */ jsxs12("div", {
4488
+ "aria-hidden": true,
4489
+ className: "absolute inset-0",
4490
+ children: [
4491
+ edges.w ? suggestions.widths.map((each) => each.w === undefined || each === w ? null : /* @__PURE__ */ jsx14("span", {
4492
+ className: "absolute -top-3.5 h-2 w-px bg-muted-foreground/50",
4493
+ style: { left: each.w * scale }
4494
+ }, `w-${each.name}`)) : null,
4495
+ edges.h ? suggestions.heights.map((each) => each.h === undefined || each === h ? null : /* @__PURE__ */ jsx14("span", {
4496
+ className: "absolute -right-3.5 h-px w-2 bg-muted-foreground/50",
4497
+ style: { top: each.h * scale }
4498
+ }, `h-${each.name}`)) : null,
4499
+ w ? /* @__PURE__ */ jsx14("span", {
4500
+ className: "absolute -top-4 -bottom-4 w-px bg-primary motion-safe:animate-in motion-safe:fade-in",
4501
+ style: { left: width }
4502
+ }) : null,
4503
+ h ? /* @__PURE__ */ jsx14("span", {
4504
+ className: "absolute -right-4 -left-4 h-px bg-primary motion-safe:animate-in motion-safe:fade-in",
4505
+ style: { top: height }
4506
+ }) : null
4507
+ ]
4508
+ });
4509
+ }
4510
+ function Readout({ drag, scale }) {
4511
+ const messages = useArtifactMessages().canvas.size;
4512
+ const { size, w, h } = drag.snapped;
4513
+ const width = size.w * scale;
4514
+ const height = size.h * scale;
4515
+ const place = drag.edge === "right" ? { left: width - 12, top: height / 2, transform: "translate(-100%, -50%)" } : drag.edge === "bottom" ? { left: width / 2, top: height - 12, transform: "translate(-50%, -100%)" } : { left: width - 12, top: height - 12, transform: "translate(-100%, -100%)" };
4516
+ const names = [...new Set([w?.name, h?.name])].filter((name) => name !== undefined);
4517
+ return /* @__PURE__ */ jsxs12("span", {
4518
+ role: "status",
4519
+ className: "absolute flex items-center gap-1",
4520
+ style: place,
4521
+ children: [
4522
+ names.map((name) => /* @__PURE__ */ jsx14("span", {
4523
+ className: "rounded-md bg-primary px-1.5 py-0.5 text-[11px] leading-4 font-medium whitespace-nowrap text-primary-foreground shadow-sm motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-95",
4524
+ children: messages.names[name]
4525
+ }, name)),
4526
+ /* @__PURE__ */ jsx14("span", {
4527
+ className: "rounded-md bg-foreground px-1.5 py-0.5 text-[11px] leading-4 font-medium whitespace-nowrap text-background tabular-nums shadow-sm",
4528
+ children: messages.dimensions(size.w, size.h)
4529
+ })
4530
+ ]
4531
+ });
4532
+ }
4533
+
4534
+ // src/artifacts/renderers/canvas/page-size-controls.tsx
4535
+ import {
4536
+ DropdownMenu as DropdownMenu3,
4537
+ DropdownMenuContent as DropdownMenuContent3,
4538
+ DropdownMenuItem as DropdownMenuItem3,
4539
+ DropdownMenuLabel,
4540
+ DropdownMenuSeparator,
4541
+ DropdownMenuTrigger as DropdownMenuTrigger3
4542
+ } from "@sixb/ui/components";
4543
+ import { cn as cn13 } from "@sixb/ui/lib/utils";
4544
+ import { Check as Check2, Proportions, RotateCcw as RotateCcw3 } from "lucide-react";
4545
+ import { useRef as useRef9 } from "react";
4546
+ import { jsx as jsx15, jsxs as jsxs13, Fragment as Fragment7 } from "react/jsx-runtime";
4547
+ var MENU = ["board", "full", "phone", "tablet", "desktop"];
4548
+ function menuSize(name, shown, board, suggestions) {
4549
+ if (name === "board")
4550
+ return board;
4551
+ if (name === "full") {
4552
+ const full = suggestions.heights.find((each) => each.name === "full")?.h;
4553
+ return full === undefined ? null : { w: shown.w, h: full };
4554
+ }
4555
+ const screen = SCREENS.find((each) => each.name === name);
4556
+ return screen && "h" in screen ? { w: screen.w, h: screen.h } : null;
4557
+ }
4558
+ function SizeControls({
4559
+ shown,
4560
+ board,
4561
+ suggestions,
4562
+ kept,
4563
+ onPick,
4564
+ onReset,
4565
+ onKeep
4566
+ }) {
4567
+ const messages = useArtifactMessages().canvas.size;
4568
+ const resized = !sameSize(shown, board);
4569
+ const pointer = useRef9(false);
4570
+ const sizes = MENU.map((name) => ({ name, size: menuSize(name, shown, board, suggestions) }));
4571
+ const current = sizes.find(({ size }) => size !== null && sameSize(size, shown))?.name;
4572
+ return /* @__PURE__ */ jsxs13("div", {
4573
+ className: "flex shrink-0 items-center gap-1",
4574
+ children: [
4575
+ kept ? /* @__PURE__ */ jsxs13("span", {
4576
+ role: "status",
4577
+ className: "flex items-center gap-1.5 px-2 text-xs font-medium text-foreground motion-safe:animate-in motion-safe:fade-in",
4578
+ children: [
4579
+ /* @__PURE__ */ jsx15(Check2, {
4580
+ className: "size-3.5 text-primary",
4581
+ "aria-hidden": "true"
4582
+ }),
4583
+ /* @__PURE__ */ jsx15("span", {
4584
+ className: "@max-3xl/canvas:sr-only",
4585
+ children: messages.kept(kept.w, kept.h)
4586
+ })
4587
+ ]
4588
+ }) : null,
4589
+ /* @__PURE__ */ jsxs13(DropdownMenu3, {
4590
+ modal: false,
4591
+ children: [
4592
+ /* @__PURE__ */ jsxs13(DropdownMenuTrigger3, {
4593
+ onPointerDown: () => {
4594
+ pointer.current = true;
4595
+ },
4596
+ onKeyDown: () => {
4597
+ pointer.current = false;
4598
+ },
4599
+ "aria-label": resized ? `${messages.menu}, ${messages.dimensions(shown.w, shown.h)}` : messages.menu,
4600
+ title: resized ? messages.yoursOnly : messages.menu,
4601
+ className: cn13("flex h-8 shrink-0 items-center gap-1.5 rounded-lg px-2 text-sm font-medium outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-muted", resized ? "bg-primary/10 text-primary hover:bg-primary/15 data-[state=open]:bg-primary/15" : "text-muted-foreground hover:text-foreground data-[state=open]:text-foreground"),
4602
+ children: [
4603
+ /* @__PURE__ */ jsx15(Proportions, {
4604
+ className: "size-4",
4605
+ "aria-hidden": "true"
4606
+ }),
4607
+ resized ? /* @__PURE__ */ jsx15("span", {
4608
+ className: "text-xs tabular-nums max-sm:hidden",
4609
+ children: messages.dimensions(shown.w, shown.h)
4610
+ }) : /* @__PURE__ */ jsx15("span", {
4611
+ className: "max-md:hidden",
4612
+ children: messages.label
4613
+ })
4614
+ ]
4615
+ }),
4616
+ /* @__PURE__ */ jsxs13(DropdownMenuContent3, {
4617
+ align: "end",
4618
+ sideOffset: 6,
4619
+ className: "w-[min(17rem,calc(100vw-2rem))] p-1.5",
4620
+ onPointerDown: () => {
4621
+ pointer.current = true;
4622
+ },
4623
+ onKeyDown: () => {
4624
+ pointer.current = false;
4625
+ },
4626
+ onCloseAutoFocus: (event) => {
4627
+ if (pointer.current)
4628
+ event.preventDefault();
4629
+ },
4630
+ children: [
4631
+ /* @__PURE__ */ jsx15(DropdownMenuLabel, {
4632
+ className: "px-2 pt-1 pb-1.5 text-[11px] font-medium tracking-wide text-muted-foreground uppercase",
4633
+ children: messages.menu
4634
+ }),
4635
+ sizes.map(({ name, size }) => /* @__PURE__ */ jsxs13(DropdownMenuItem3, {
4636
+ disabled: size === null,
4637
+ onSelect: () => {
4638
+ if (name === "board")
4639
+ onReset();
4640
+ else if (size)
4641
+ onPick(size, name);
4642
+ },
4643
+ className: "gap-2 rounded-md py-1.5",
4644
+ children: [
4645
+ /* @__PURE__ */ jsx15(Check2, {
4646
+ className: cn13("size-3.5", name === current ? "text-foreground" : "invisible"),
4647
+ "aria-hidden": "true"
4648
+ }),
4649
+ /* @__PURE__ */ jsx15("span", {
4650
+ className: "flex-1 text-[13px]",
4651
+ children: messages.names[name]
4652
+ }),
4653
+ /* @__PURE__ */ jsx15("span", {
4654
+ className: "text-xs text-muted-foreground tabular-nums",
4655
+ children: size ? messages.dimensions(size.w, size.h) : messages.measuring
4656
+ })
4657
+ ]
4658
+ }, name)),
4659
+ resized ? /* @__PURE__ */ jsxs13(Fragment7, {
4660
+ children: [
4661
+ /* @__PURE__ */ jsx15(DropdownMenuSeparator, {
4662
+ className: "my-1"
4663
+ }),
4664
+ /* @__PURE__ */ jsx15("p", {
4665
+ className: "px-2 pt-0.5 pb-1 text-xs text-muted-foreground",
4666
+ children: onKeep ? messages.yoursUntilKept : messages.yoursOnly
4667
+ }),
4668
+ onKeep ? /* @__PURE__ */ jsx15(DropdownMenuItem3, {
4669
+ onSelect: onKeep,
4670
+ className: "rounded-md py-1.5 pl-[30px] text-[13px] font-medium text-primary focus:text-primary",
4671
+ children: messages.keep
4672
+ }) : null
4673
+ ]
4674
+ }) : null
4675
+ ]
4676
+ })
4677
+ ]
4678
+ }),
4679
+ resized ? /* @__PURE__ */ jsxs13("span", {
4680
+ className: "hidden items-center gap-1 @3xl/canvas:flex",
4681
+ children: [
4682
+ /* @__PURE__ */ jsx15("button", {
4683
+ type: "button",
4684
+ "aria-label": messages.reset,
4685
+ title: messages.reset,
4686
+ onClick: onReset,
4687
+ className: "flex size-8 items-center justify-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
4688
+ children: /* @__PURE__ */ jsx15(RotateCcw3, {
4689
+ className: "size-3.5",
4690
+ "aria-hidden": "true"
4691
+ })
4692
+ }),
4693
+ onKeep ? /* @__PURE__ */ jsx15("button", {
4694
+ type: "button",
4695
+ onClick: onKeep,
4696
+ className: "h-7 shrink-0 rounded-lg bg-primary px-2.5 text-xs font-medium whitespace-nowrap text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
4697
+ children: messages.keep
4698
+ }) : null
4699
+ ]
4700
+ }) : null
4701
+ ]
4702
+ });
4703
+ }
4704
+
4705
+ // src/artifacts/renderers/canvas/page-zoom.ts
4706
+ import { useCallback as useCallback7, useEffect as useEffect8, useLayoutEffect as useLayoutEffect3, useRef as useRef10, useState as useState11 } from "react";
4707
+ var OPEN = { fit: "open" };
4708
+ var SETTLE_MS = 220;
4709
+ function pagePlacement(view, box, pad, held = null) {
4710
+ const left = held?.left ?? Math.max(pad.side, (view.width - box.width) / 2);
4711
+ const top = held?.top ?? Math.max(pad.top, pad.top + (view.height - pad.top - pad.bottom - box.height) / 2);
4712
+ return {
4713
+ left,
4714
+ top,
4715
+ width: Math.max(view.width, left + box.width + pad.side),
4716
+ height: Math.max(view.height, top + box.height + pad.bottom)
4717
+ };
4718
+ }
4719
+ function stagePadding(view) {
4720
+ return view.width < 640 ? { side: 12, top: 12, bottom: 64 } : { side: 24, top: 24, bottom: 24 };
4721
+ }
4722
+ function usePageZoom({
4723
+ id,
4724
+ page,
4725
+ view,
4726
+ stage
4727
+ }) {
4728
+ const [state, setState] = useState11({
4729
+ id,
4730
+ zoom: OPEN
4731
+ });
4732
+ const zoom = state.id === id ? state.zoom : OPEN;
4733
+ const [held, setHeld] = useState11(null);
4734
+ const [settling, setSettling] = useState11(false);
4735
+ const pad = view ? stagePadding(view) : null;
4736
+ const room = view && pad ? {
4737
+ width: Math.max(1, view.width - pad.side * 2),
4738
+ height: Math.max(1, view.height - pad.top - pad.bottom)
4739
+ } : null;
4740
+ const scale = !room ? 0 : ("scale" in zoom) ? zoom.scale : fitScale(page, room, zoom.fit);
4741
+ const box = { width: page.w * scale, height: page.h * scale };
4742
+ const placement = view && pad ? pagePlacement(view, box, pad, held) : null;
4743
+ const anchor = useRef10(null);
4744
+ const latest = useRef10({ id, scale, placement, view });
4745
+ latest.current = { id, scale, placement, view };
4746
+ useLayoutEffect3(() => {
4747
+ const point = anchor.current;
4748
+ if (!point || !stage || !placement)
4749
+ return;
4750
+ anchor.current = null;
4751
+ stage.scrollLeft = placement.left + point.x * scale - point.vx;
4752
+ stage.scrollTop = placement.top + point.y * scale - point.vy;
4753
+ }, [stage, placement, scale]);
4754
+ const fitted = "fit" in zoom ? zoom.fit : null;
4755
+ useLayoutEffect3(() => {
4756
+ if (fitted === null || !stage)
4757
+ return;
4758
+ stage.scrollTop = 0;
4759
+ stage.scrollLeft = 0;
4760
+ }, [stage, fitted, id]);
4761
+ const zoomTo = useCallback7((next, at = null) => {
4762
+ const { id, scale, placement, view } = latest.current;
4763
+ if (!stage || !placement || !view || scale === 0)
4764
+ return;
4765
+ const pending = anchor.current;
4766
+ const from = pending?.scale ?? scale;
4767
+ const target = clampZoom(next);
4768
+ if (Math.abs(target - from) < 0.0001)
4769
+ return;
4770
+ if (!pending) {
4771
+ const vx = at ? placement.left + at.x * scale - stage.scrollLeft : view.width / 2;
4772
+ const vy = at ? placement.top + at.y * scale - stage.scrollTop : view.height / 2;
4773
+ anchor.current = {
4774
+ x: (stage.scrollLeft + vx - placement.left) / scale,
4775
+ y: (stage.scrollTop + vy - placement.top) / scale,
4776
+ vx,
4777
+ vy,
4778
+ scale: target
4779
+ };
4780
+ } else {
4781
+ anchor.current = { ...pending, scale: target };
4782
+ }
4783
+ setState({ id, zoom: { scale: target } });
4784
+ }, [stage]);
4785
+ const current = useCallback7(() => anchor.current?.scale ?? latest.current.scale, []);
4786
+ const zoomBy = useCallback7((factor, at = null) => zoomTo(current() * factor, at), [zoomTo, current]);
4787
+ const step = useCallback7((direction) => zoomTo(zoomStep(current(), direction)), [zoomTo, current]);
4788
+ const fit = useCallback7((how = "whole") => {
4789
+ anchor.current = null;
4790
+ setState({ id: latest.current.id, zoom: { fit: how } });
4791
+ }, []);
4792
+ const toggle = useCallback7((at) => {
4793
+ if (Math.abs(current() - 1) < 0.01)
4794
+ fit("whole");
4795
+ else
4796
+ zoomTo(1, at);
4797
+ }, [fit, zoomTo, current]);
4798
+ const pageAt = useCallback7((clientX, clientY) => {
4799
+ const { scale, placement } = latest.current;
4800
+ if (!stage || !placement || scale === 0)
4801
+ return null;
4802
+ const rect = stage.getBoundingClientRect();
4803
+ return {
4804
+ x: (stage.scrollLeft + clientX - rect.left - placement.left) / scale,
4805
+ y: (stage.scrollTop + clientY - rect.top - placement.top) / scale
4806
+ };
4807
+ }, [stage]);
4808
+ const hold = useCallback7(() => {
4809
+ const { id, scale, placement } = latest.current;
4810
+ if (!placement)
4811
+ return;
4812
+ setState({ id, zoom: { scale } });
4813
+ setHeld({ left: placement.left, top: placement.top });
4814
+ }, []);
4815
+ const release = useCallback7(() => {
4816
+ setHeld(null);
4817
+ setSettling(true);
4818
+ }, []);
4819
+ useEffect8(() => {
4820
+ if (!settling)
4821
+ return;
4822
+ const timer = window.setTimeout(() => setSettling(false), SETTLE_MS);
4823
+ return () => window.clearTimeout(timer);
4824
+ }, [settling]);
4825
+ useEffect8(() => {
4826
+ if (!stage)
4827
+ return;
4828
+ const mac = /Mac|iPhone|iPad/.test(navigator.platform);
4829
+ const onWheel = (event) => {
4830
+ if (!(event.ctrlKey || event.metaKey))
4831
+ return;
4832
+ event.preventDefault();
4833
+ const unit = event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002;
4834
+ const factor = 2 ** (-event.deltaY * unit * (event.ctrlKey && mac ? 10 : 1));
4835
+ zoomBy(factor, pageAt(event.clientX, event.clientY));
4836
+ };
4837
+ let spread = 0;
4838
+ const spreadOf = (touches) => {
4839
+ const [one, two] = [touches[0], touches[1]];
4840
+ return one && two ? Math.hypot(one.clientX - two.clientX, one.clientY - two.clientY) : 0;
4841
+ };
4842
+ const onTouchStart = (event) => {
4843
+ spread = event.touches.length === 2 ? spreadOf(event.touches) : 0;
4844
+ };
4845
+ const onTouchMove = (event) => {
4846
+ const [one, two] = [event.touches[0], event.touches[1]];
4847
+ if (!one || !two || event.touches.length !== 2 || spread === 0)
4848
+ return;
4849
+ event.preventDefault();
4850
+ const next = spreadOf(event.touches);
4851
+ zoomBy(next / spread, pageAt((one.clientX + two.clientX) / 2, (one.clientY + two.clientY) / 2));
4852
+ spread = next;
4853
+ };
4854
+ stage.addEventListener("wheel", onWheel, { passive: false });
4855
+ stage.addEventListener("touchstart", onTouchStart, { passive: true });
4856
+ stage.addEventListener("touchmove", onTouchMove, { passive: false });
4857
+ return () => {
4858
+ stage.removeEventListener("wheel", onWheel);
4859
+ stage.removeEventListener("touchstart", onTouchStart);
4860
+ stage.removeEventListener("touchmove", onTouchMove);
4861
+ };
4862
+ }, [stage, zoomBy, pageAt]);
4863
+ return {
4864
+ scale,
4865
+ placement,
4866
+ held: held !== null,
4867
+ settling,
4868
+ zoomTo,
4869
+ zoomBy,
4870
+ step,
4871
+ fit,
4872
+ toggle,
4873
+ pageAt,
4874
+ hold,
4875
+ release
4876
+ };
4877
+ }
4878
+
4879
+ // src/artifacts/renderers/canvas/shown-size.ts
4880
+ import { useCallback as useCallback8, useEffect as useEffect9, useMemo as useMemo6, useRef as useRef11, useState as useState12 } from "react";
4881
+ function useShownSize(id, own) {
4882
+ const [sizes, setSizes] = useState12({});
4883
+ const [screen, setScreen] = useState12(null);
4884
+ const [heights, setHeights] = useState12({});
4885
+ const height = heights[id] ?? null;
4886
+ const suggestions = useMemo6(() => sizeSuggestions(own, height), [own, height]);
4887
+ const chosen = sizes[id] ?? (screen ? clampSize({ w: screen.w, h: screen.full && height !== null ? height : own.h }, suggestions.least) : null);
4888
+ const shown = chosen && !sameSize(chosen, own) ? chosen : own;
4889
+ const onContentHeight = useCallback8((next) => setHeights((last) => last[id] === next ? last : { ...last, [id]: next }), [id]);
4890
+ const resize = useCallback8((size) => setSizes((last) => ({ ...last, [id]: size })), [id]);
4891
+ const set = (size, name, full) => {
4892
+ if (name !== null && isScreen(name)) {
4893
+ setSizes({ [id]: size });
4894
+ setScreen({ w: size.w, full: full ?? screen?.full ?? false });
4895
+ return;
4896
+ }
4897
+ resize(size);
4898
+ if (screen && full !== null)
4899
+ setScreen({ ...screen, full });
4900
+ };
4901
+ const keeping = useRef11(null);
4902
+ useEffect9(() => {
4903
+ const kept = keeping.current;
4904
+ if (!kept || kept.id !== id || !sameSize(kept.size, own))
4905
+ return;
4906
+ keeping.current = null;
4907
+ setSizes(({ [id]: _, ...others }) => others);
4908
+ }, [id, own]);
4909
+ return {
4910
+ shown,
4911
+ resized: shown !== own,
4912
+ suggestions,
4913
+ onContentHeight,
4914
+ resize,
4915
+ pick: (size, name) => set(size, name, name === "full" ? true : isScreen(name) ? false : null),
4916
+ settle: (snapped) => {
4917
+ const width = snapped.w && isScreen(snapped.w.name) ? snapped.w.name : null;
4918
+ set(snapped.size, width, snapped.h ? snapped.h.name === "full" : null);
4919
+ },
4920
+ reset: () => {
4921
+ setSizes({});
4922
+ setScreen(null);
4923
+ },
4924
+ keep: () => {
4925
+ keeping.current = { id, size: shown };
4926
+ }
4927
+ };
4928
+ }
4929
+
4930
+ // src/artifacts/renderers/canvas/focus.tsx
4931
+ import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
4932
+ var KEPT_MS = 2400;
3994
4933
  function BoardFocus({
3995
4934
  version,
3996
4935
  boards,
@@ -4010,29 +4949,72 @@ function BoardFocus({
4010
4949
  onPick,
4011
4950
  onOpenPin,
4012
4951
  onSubmitDraft,
4013
- onCancelDraft
4952
+ onCancelDraft,
4953
+ onResizeBoard
4014
4954
  }) {
4015
4955
  const messages = useArtifactMessages().canvas;
4016
4956
  const index = boards.findIndex((board) => board.id === id);
4017
4957
  const board = boards[index];
4018
4958
  const previous = boards[index - 1];
4019
4959
  const next = boards[index + 1];
4020
- const [stage, setStage] = useState10(null);
4021
- const room = useSize(stage);
4022
- const onPress = useCallback6((text) => {
4960
+ const [kept, setKept] = useState13(null);
4961
+ const own = useMemo7(() => ({ w: board?.w ?? 1, h: board?.h ?? 1 }), [board?.w, board?.h]);
4962
+ const size = useShownSize(id, own);
4963
+ const { shown, resized, suggestions } = size;
4964
+ const [stage, setStage] = useState13(null);
4965
+ const view = useSize(stage);
4966
+ const zoom = usePageZoom({ id, page: shown, view, stage });
4967
+ const pickSize = (picked, name) => {
4968
+ size.pick(picked, name);
4969
+ zoom.fit("open");
4970
+ };
4971
+ const reset = () => {
4972
+ size.reset();
4973
+ zoom.fit("open");
4974
+ };
4975
+ const resizedBy = (snapped) => {
4976
+ zoom.release();
4977
+ if (snapped)
4978
+ size.settle(snapped);
4979
+ };
4980
+ const keep = onResizeBoard && board ? () => {
4981
+ onResizeBoard(board.id, { x: board.x, y: board.y, w: shown.w, h: shown.h });
4982
+ size.keep();
4983
+ setKept(shown);
4984
+ } : undefined;
4985
+ useEffect10(() => {
4986
+ if (!kept)
4987
+ return;
4988
+ const timer = window.setTimeout(() => setKept(null), KEPT_MS);
4989
+ return () => window.clearTimeout(timer);
4990
+ }, [kept]);
4991
+ const { step, zoomTo, zoomBy } = zoom;
4992
+ const zoomStep = useCallback9((to) => to === "actual" ? zoomTo(1) : step(to), [step, zoomTo]);
4993
+ const onZoom = useCallback9((by) => ("step" in by) ? zoomStep(by.step) : zoomBy(by.factor, by.at), [zoomStep, zoomBy]);
4994
+ const onPress = useCallback9((text) => {
4023
4995
  const to = followedArrow(arrows, boards, id, text);
4024
4996
  if (to)
4025
4997
  onOpen(to);
4026
4998
  }, [arrows, boards, id, onOpen]);
4027
- const pick = useCallback6((place) => onPick?.(id, place), [onPick, id]);
4028
- useEffect7(() => {
4999
+ const pick = useCallback9((place) => onPick?.(id, place), [onPick, id]);
5000
+ useEffect10(() => {
4029
5001
  const onKey = (event) => {
4030
- if (event.metaKey || event.ctrlKey || event.altKey)
5002
+ if (event.metaKey || event.ctrlKey) {
5003
+ const to = zoomKey(event);
5004
+ if (to) {
5005
+ event.preventDefault();
5006
+ zoomStep(to);
5007
+ }
4031
5008
  return;
4032
- const target = event.target;
4033
- if (target instanceof Element && target.closest("input, textarea, select, [contenteditable], [data-board-tools]")) {
5009
+ }
5010
+ if (event.altKey)
5011
+ return;
5012
+ const target = event.target instanceof Element ? event.target : null;
5013
+ if (target?.closest("input, textarea, select, [contenteditable], [data-board-tools], [role=menu]")) {
4034
5014
  return;
4035
5015
  }
5016
+ if (event.key !== "Escape" && target?.closest("[data-page-resizer]"))
5017
+ return;
4036
5018
  if (event.key === "Escape") {
4037
5019
  if (!onEscape?.())
4038
5020
  onClose();
@@ -4046,118 +5028,183 @@ function BoardFocus({
4046
5028
  };
4047
5029
  window.addEventListener("keydown", onKey);
4048
5030
  return () => window.removeEventListener("keydown", onKey);
4049
- }, [previous, next, onOpen, onClose, onEscape]);
5031
+ }, [previous, next, onOpen, onClose, onEscape, zoomStep]);
4050
5032
  if (!board)
4051
5033
  return null;
4052
5034
  const title = board.title ?? board.id;
4053
- const scale = room ? Math.min(MAX_SCALE, room.width / board.w, room.height / board.h) : 0;
4054
- const picture = pictureOf?.(board.id);
4055
- return /* @__PURE__ */ jsxs12("div", {
5035
+ const { scale, placement } = zoom;
5036
+ const picture = resized ? undefined : pictureOf?.(board.id);
5037
+ return /* @__PURE__ */ jsxs14("div", {
4056
5038
  role: "dialog",
4057
5039
  "aria-label": messages.focused(title),
4058
5040
  className: "absolute inset-0 z-10 flex flex-col bg-background motion-safe:animate-in motion-safe:fade-in motion-safe:duration-200",
4059
5041
  children: [
4060
- /* @__PURE__ */ jsxs12("div", {
5042
+ /* @__PURE__ */ jsxs14("div", {
4061
5043
  className: "flex h-12 shrink-0 items-center gap-2 border-b border-border/70 px-2",
4062
5044
  children: [
4063
- /* @__PURE__ */ jsxs12("button", {
5045
+ /* @__PURE__ */ jsxs14("button", {
4064
5046
  type: "button",
4065
5047
  onClick: onClose,
4066
5048
  className: "flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-sm font-medium text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
4067
5049
  children: [
4068
- /* @__PURE__ */ jsx14(ArrowLeft, {
5050
+ /* @__PURE__ */ jsx16(ArrowLeft, {
4069
5051
  className: "size-4",
4070
5052
  "aria-hidden": "true"
4071
5053
  }),
4072
5054
  messages.back
4073
5055
  ]
4074
5056
  }),
4075
- /* @__PURE__ */ jsx14("span", {
5057
+ /* @__PURE__ */ jsx16("span", {
4076
5058
  className: "h-5 w-px bg-border",
4077
5059
  "aria-hidden": "true"
4078
5060
  }),
4079
- /* @__PURE__ */ jsx14("span", {
5061
+ /* @__PURE__ */ jsx16("span", {
4080
5062
  className: "min-w-0 truncate px-1 text-sm font-semibold",
4081
5063
  children: title
4082
5064
  }),
4083
- mode === "edit" || mode === "comment" ? /* @__PURE__ */ jsx14("span", {
5065
+ mode === "edit" || mode === "comment" ? /* @__PURE__ */ jsx16("span", {
4084
5066
  className: "hidden min-w-0 truncate text-xs text-muted-foreground @5xl/canvas:inline",
4085
5067
  children: mode === "edit" ? messages.edit.hint : messages.comments.modeHint
4086
5068
  }) : null,
4087
- tools ? /* @__PURE__ */ jsx14("div", {
5069
+ /* @__PURE__ */ jsxs14("div", {
4088
5070
  className: "ml-auto flex shrink-0 items-center",
4089
- children: tools
4090
- }) : null,
4091
- /* @__PURE__ */ jsx14("span", {
4092
- className: `${tools ? "" : "ml-auto "}shrink-0 text-xs whitespace-nowrap text-muted-foreground tabular-nums max-sm:hidden`,
5071
+ children: [
5072
+ /* @__PURE__ */ jsx16(SizeControls, {
5073
+ shown,
5074
+ board: own,
5075
+ suggestions,
5076
+ kept,
5077
+ onPick: pickSize,
5078
+ onReset: reset,
5079
+ onKeep: keep
5080
+ }),
5081
+ tools
5082
+ ]
5083
+ }),
5084
+ /* @__PURE__ */ jsx16("span", {
5085
+ className: "shrink-0 text-xs whitespace-nowrap text-muted-foreground tabular-nums max-sm:hidden",
4093
5086
  children: messages.position(index + 1, boards.length)
4094
5087
  }),
4095
- /* @__PURE__ */ jsx14(Step, {
5088
+ /* @__PURE__ */ jsx16(Step, {
4096
5089
  label: messages.previousBoard,
4097
5090
  disabled: !previous,
4098
5091
  onClick: () => previous && onOpen(previous.id),
4099
- children: /* @__PURE__ */ jsx14(ChevronLeft, {
5092
+ children: /* @__PURE__ */ jsx16(ChevronLeft, {
4100
5093
  className: "size-4",
4101
5094
  "aria-hidden": "true"
4102
5095
  })
4103
5096
  }),
4104
- /* @__PURE__ */ jsx14(Step, {
5097
+ /* @__PURE__ */ jsx16(Step, {
4105
5098
  label: messages.nextBoard,
4106
5099
  disabled: !next,
4107
5100
  onClick: () => next && onOpen(next.id),
4108
- children: /* @__PURE__ */ jsx14(ChevronRight, {
5101
+ children: /* @__PURE__ */ jsx16(ChevronRight, {
4109
5102
  className: "size-4",
4110
5103
  "aria-hidden": "true"
4111
5104
  })
4112
5105
  })
4113
5106
  ]
4114
5107
  }),
4115
- /* @__PURE__ */ jsx14("div", {
4116
- className: "flex min-h-0 flex-1 overflow-hidden bg-muted/40 p-3 sm:p-6",
4117
- children: /* @__PURE__ */ jsx14("div", {
4118
- ref: setStage,
4119
- className: "flex min-h-0 min-w-0 flex-1 items-center justify-center",
4120
- children: scale > 0 ? /* @__PURE__ */ jsx14("div", {
4121
- className: "sixb-canvas-surface relative shrink-0 motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-97 motion-safe:duration-300 motion-safe:ease-out",
4122
- style: { width: board.w * scale, height: board.h * scale },
4123
- children: /* @__PURE__ */ jsx14(BoardStage, {
4124
- version,
4125
- board,
4126
- title,
4127
- scale,
4128
- live,
4129
- canvas,
4130
- mode,
4131
- pins: pins.filter((pin) => pin.board === board.id),
4132
- activePin,
4133
- draft: draft?.board === board.id ? draft : null,
4134
- fallback: picture ? /* @__PURE__ */ jsx14(BoardPicture, {
4135
- src: picture
4136
- }) : undefined,
4137
- failure: /* @__PURE__ */ jsxs12("div", {
4138
- className: "relative size-full",
5108
+ /* @__PURE__ */ jsxs14("div", {
5109
+ className: "relative min-h-0 flex-1 bg-muted/40",
5110
+ children: [
5111
+ /* @__PURE__ */ jsx16("div", {
5112
+ ref: setStage,
5113
+ "data-board-stage": "",
5114
+ className: "absolute inset-0 touch-pan-x touch-pan-y overflow-auto overscroll-contain",
5115
+ onDoubleClick: (event) => {
5116
+ if (event.target.closest("[data-board-page]"))
5117
+ return;
5118
+ const at = zoom.pageAt(event.clientX, event.clientY);
5119
+ if (at)
5120
+ zoom.toggle(at);
5121
+ },
5122
+ children: placement && scale > 0 ? /* @__PURE__ */ jsx16("div", {
5123
+ className: "relative",
5124
+ style: { width: placement.width, height: placement.height },
5125
+ children: /* @__PURE__ */ jsxs14("div", {
5126
+ "data-board-page": "",
5127
+ className: cn14("group/page sixb-canvas-surface absolute motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-97 motion-safe:duration-300 motion-safe:ease-out", zoom.settling ? "motion-safe:transition-[left,top] motion-safe:ease-out" : null),
5128
+ style: {
5129
+ left: placement.left,
5130
+ top: placement.top,
5131
+ width: shown.w * scale,
5132
+ height: shown.h * scale
5133
+ },
4139
5134
  children: [
4140
- picture ? /* @__PURE__ */ jsx14(BoardPicture, {
4141
- src: picture
4142
- }) : null,
4143
- /* @__PURE__ */ jsx14("p", {
4144
- className: "absolute inset-x-0 bottom-0 m-0 bg-background/90 px-4 py-2 text-sm text-muted-foreground",
4145
- children: messages.boardFailed
5135
+ /* @__PURE__ */ jsx16(BoardStage, {
5136
+ version,
5137
+ board,
5138
+ size: shown,
5139
+ title,
5140
+ scale,
5141
+ live,
5142
+ canvas,
5143
+ mode,
5144
+ pins: pins.filter((pin) => pin.board === board.id),
5145
+ activePin,
5146
+ draft: draft?.board === board.id ? draft : null,
5147
+ fallback: picture ? /* @__PURE__ */ jsx16(BoardPicture, {
5148
+ src: picture
5149
+ }) : undefined,
5150
+ failure: /* @__PURE__ */ jsxs14("div", {
5151
+ className: "relative size-full",
5152
+ children: [
5153
+ picture ? /* @__PURE__ */ jsx16(BoardPicture, {
5154
+ src: picture
5155
+ }) : null,
5156
+ /* @__PURE__ */ jsx16("p", {
5157
+ className: "absolute inset-x-0 bottom-0 m-0 bg-background/90 px-4 py-2 text-sm text-muted-foreground",
5158
+ children: messages.boardFailed
5159
+ })
5160
+ ]
5161
+ }),
5162
+ onPress,
5163
+ onPick: pick,
5164
+ onOpenPin: (pin) => onOpenPin?.(pin),
5165
+ onSubmitDraft: (body) => onSubmitDraft?.(body) ?? Promise.resolve(),
5166
+ onCancelDraft: () => onCancelDraft?.(),
5167
+ onContentHeight: size.onContentHeight,
5168
+ onZoom
5169
+ }),
5170
+ /* @__PURE__ */ jsx16(PageResizer, {
5171
+ size: shown,
5172
+ scale,
5173
+ suggestions,
5174
+ stage,
5175
+ onStart: zoom.hold,
5176
+ onResize: size.resize,
5177
+ onEnd: resizedBy
4146
5178
  })
4147
5179
  ]
4148
- }),
4149
- onPress,
4150
- onPick: pick,
4151
- onOpenPin: (pin) => onOpenPin?.(pin),
4152
- onSubmitDraft: (body) => onSubmitDraft?.(body) ?? Promise.resolve(),
4153
- onCancelDraft: () => onCancelDraft?.()
4154
- })
4155
- }, board.id) : null
4156
- })
5180
+ }, board.id)
5181
+ }) : null
5182
+ }),
5183
+ /* @__PURE__ */ jsx16(ZoomBar, {
5184
+ zoom: scale,
5185
+ fitLabel: messages.fitPage,
5186
+ onZoomOut: () => zoom.step("out"),
5187
+ onActualSize: () => zoom.zoomTo(1),
5188
+ onZoomIn: () => zoom.step("in"),
5189
+ onFit: () => zoom.fit("whole"),
5190
+ className: "absolute bottom-3 left-3 z-20"
5191
+ })
5192
+ ]
4157
5193
  })
4158
5194
  ]
4159
5195
  });
4160
5196
  }
5197
+ function zoomKey(event) {
5198
+ if (event.altKey)
5199
+ return null;
5200
+ if (event.key === "=" || event.key === "+")
5201
+ return "in";
5202
+ if (event.key === "-")
5203
+ return "out";
5204
+ if (event.key === "0")
5205
+ return "actual";
5206
+ return null;
5207
+ }
4161
5208
  function followedArrow(arrows, boards, from, pressed) {
4162
5209
  const words = wordsOf(pressed);
4163
5210
  for (const arrow of arrows) {
@@ -4174,9 +5221,8 @@ function followedArrow(arrows, boards, from, pressed) {
4174
5221
  function wordsOf(text) {
4175
5222
  return text.replace(/\s+/g, " ").trim().toLowerCase();
4176
5223
  }
4177
- var MAX_SCALE = 2.5;
4178
5224
  function BoardPicture({ src }) {
4179
- return /* @__PURE__ */ jsx14("img", {
5225
+ return /* @__PURE__ */ jsx16("img", {
4180
5226
  src,
4181
5227
  alt: "",
4182
5228
  decoding: "async",
@@ -4185,8 +5231,8 @@ function BoardPicture({ src }) {
4185
5231
  });
4186
5232
  }
4187
5233
  function useSize(element) {
4188
- const [size, setSize] = useState10(null);
4189
- useEffect7(() => {
5234
+ const [size, setSize] = useState13(null);
5235
+ useEffect10(() => {
4190
5236
  if (!element)
4191
5237
  return;
4192
5238
  const measure = () => {
@@ -4207,7 +5253,7 @@ function Step({
4207
5253
  onClick,
4208
5254
  children
4209
5255
  }) {
4210
- return /* @__PURE__ */ jsx14("button", {
5256
+ return /* @__PURE__ */ jsx16("button", {
4211
5257
  type: "button",
4212
5258
  "aria-label": label,
4213
5259
  title: label,
@@ -4218,11 +5264,198 @@ function Step({
4218
5264
  });
4219
5265
  }
4220
5266
 
5267
+ // src/artifacts/renderers/canvas/gestures.ts
5268
+ import { useReactFlow as useReactFlow2, useStoreApi as useStoreApi4 } from "@xyflow/react";
5269
+ import { useEffect as useEffect11, useMemo as useMemo8, useRef as useRef12 } from "react";
5270
+ var WHEEL_PAN_SPEED = 0.5;
5271
+ var WHEEL_PAUSE_MS = 150;
5272
+ var GLIDE_MS = 420;
5273
+ var STEP_MS = 220;
5274
+ var GLIDE_MARGIN = 32;
5275
+ var KEYED = "input, textarea, select, button, a[href], [contenteditable], [role=menu]";
5276
+ function glideView(box, view, zoom, padding) {
5277
+ const fit = Math.min(view.width / (box.w * (1 + padding)), view.height / (box.h * (1 + padding)));
5278
+ const next = Math.min(zoom, Math.max(fit, Math.min(zoom, LIVE_FROM_SCALE)));
5279
+ const width = box.w * next;
5280
+ const height = box.h * next;
5281
+ const left = width <= view.width ? (view.width - width) / 2 : GLIDE_MARGIN;
5282
+ const top = height <= view.height ? (view.height - height) / 2 : GLIDE_MARGIN;
5283
+ return { x: left - box.x * next, y: top - box.y * next, zoom: next };
5284
+ }
5285
+ function useBoardGestures({
5286
+ root,
5287
+ pointed,
5288
+ reading,
5289
+ opened,
5290
+ padding,
5291
+ onPress
5292
+ }) {
5293
+ const store = useStoreApi4();
5294
+ const { setViewport, zoomIn, zoomOut, zoomTo } = useReactFlow2();
5295
+ const pressRef = useRef12(onPress);
5296
+ pressRef.current = onPress;
5297
+ const gestures = useMemo8(() => {
5298
+ let moving = false;
5299
+ let pause;
5300
+ const listeners = new Set;
5301
+ const tell = (next) => {
5302
+ if (moving === next)
5303
+ return;
5304
+ moving = next;
5305
+ for (const listener of listeners)
5306
+ listener(next);
5307
+ };
5308
+ const wheeled = () => {
5309
+ tell(true);
5310
+ clearTimeout(pause);
5311
+ pause = setTimeout(() => tell(false), WHEEL_PAUSE_MS);
5312
+ };
5313
+ const view = () => {
5314
+ const [x, y, zoom] = store.getState().transform;
5315
+ return { x, y, zoom };
5316
+ };
5317
+ const zoomAround = (factor, at) => {
5318
+ const { minZoom, maxZoom, domNode } = store.getState();
5319
+ const bounds = domNode?.getBoundingClientRect();
5320
+ if (!bounds)
5321
+ return;
5322
+ const { x, y, zoom } = view();
5323
+ const next = Math.min(maxZoom, Math.max(minZoom, zoom * factor));
5324
+ const left = at.x - bounds.left;
5325
+ const top = at.y - bounds.top;
5326
+ setViewport({
5327
+ x: left - (left - x) * next / zoom,
5328
+ y: top - (top - y) * next / zoom,
5329
+ zoom: next
5330
+ });
5331
+ };
5332
+ const pan = ({ x: right, y: down, by }) => {
5333
+ const speed = by === "wheel" ? WHEEL_PAN_SPEED : 1;
5334
+ const { x, y, zoom } = view();
5335
+ setViewport({ x: x - right * speed, y: y - down * speed, zoom });
5336
+ if (by === "wheel")
5337
+ wheeled();
5338
+ };
5339
+ const step = (to) => {
5340
+ if (to === "in")
5341
+ zoomIn({ duration: STEP_MS });
5342
+ else if (to === "out")
5343
+ zoomOut({ duration: STEP_MS });
5344
+ else
5345
+ zoomTo(1, { duration: STEP_MS });
5346
+ };
5347
+ const hold = (down) => {
5348
+ root.current?.toggleAttribute("data-panning", down);
5349
+ };
5350
+ return {
5351
+ wheeled,
5352
+ step,
5353
+ hold,
5354
+ moving: () => moving,
5355
+ onMoving: (listener) => {
5356
+ listeners.add(listener);
5357
+ return () => {
5358
+ listeners.delete(listener);
5359
+ };
5360
+ },
5361
+ receive: (board, event, page) => {
5362
+ switch (event.event) {
5363
+ case "zoom": {
5364
+ if ("step" in event.params) {
5365
+ step(event.params.step);
5366
+ return;
5367
+ }
5368
+ const bounds = page?.getBoundingClientRect();
5369
+ if (!bounds)
5370
+ return;
5371
+ const { zoom } = view();
5372
+ const { factor, at } = event.params;
5373
+ zoomAround(factor, { x: bounds.left + at.x * zoom, y: bounds.top + at.y * zoom });
5374
+ return;
5375
+ }
5376
+ case "pan":
5377
+ pan(event.params);
5378
+ return;
5379
+ case "space":
5380
+ hold(event.params.down);
5381
+ return;
5382
+ case "press":
5383
+ pressRef.current(board, event.params.text);
5384
+ return;
5385
+ default:
5386
+ return;
5387
+ }
5388
+ },
5389
+ glide: (box) => {
5390
+ const { width, height } = store.getState();
5391
+ const still = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
5392
+ setViewport(glideView(box, { width, height }, view().zoom, padding), {
5393
+ duration: still ? 0 : GLIDE_MS
5394
+ });
5395
+ },
5396
+ stop: () => {
5397
+ clearTimeout(pause);
5398
+ tell(false);
5399
+ }
5400
+ };
5401
+ }, [store, setViewport, zoomIn, zoomOut, zoomTo, root, padding]);
5402
+ useEffect11(() => gestures.stop, [gestures]);
5403
+ useEffect11(() => {
5404
+ const here = root.current;
5405
+ if (!here)
5406
+ return;
5407
+ const onWheel = (event) => {
5408
+ if (event.target instanceof Element && event.target.closest(".react-flow"))
5409
+ gestures.wheeled();
5410
+ };
5411
+ here.addEventListener("wheel", onWheel, { capture: true, passive: true });
5412
+ return () => here.removeEventListener("wheel", onWheel, { capture: true });
5413
+ }, [root, gestures]);
5414
+ useEffect11(() => {
5415
+ if (opened)
5416
+ return;
5417
+ const here = () => {
5418
+ const canvas = root.current;
5419
+ return canvas !== null && (pointed.current || canvas.contains(document.activeElement));
5420
+ };
5421
+ const onKey = (event) => {
5422
+ if (event.metaKey || event.ctrlKey) {
5423
+ const to = event.type === "keydown" ? zoomKey(event) : null;
5424
+ if (!to || !here())
5425
+ return;
5426
+ event.preventDefault();
5427
+ gestures.step(to);
5428
+ return;
5429
+ }
5430
+ if (!reading || event.key !== " " || event.altKey)
5431
+ return;
5432
+ const down = event.type === "keydown";
5433
+ if (down) {
5434
+ if (!here() || event.target instanceof Element && event.target.closest(KEYED))
5435
+ return;
5436
+ event.preventDefault();
5437
+ }
5438
+ gestures.hold(down);
5439
+ };
5440
+ const release = () => gestures.hold(false);
5441
+ window.addEventListener("keydown", onKey);
5442
+ window.addEventListener("keyup", onKey);
5443
+ window.addEventListener("blur", release);
5444
+ return () => {
5445
+ window.removeEventListener("keydown", onKey);
5446
+ window.removeEventListener("keyup", onKey);
5447
+ window.removeEventListener("blur", release);
5448
+ release();
5449
+ };
5450
+ }, [opened, reading, root, pointed, gestures]);
5451
+ return gestures;
5452
+ }
5453
+
4221
5454
  // src/artifacts/renderers/canvas/presence.tsx
4222
5455
  import { useStore as useStore3, ViewportPortal as ViewportPortal2 } from "@xyflow/react";
4223
5456
  import { Sparkles as Sparkles2 } from "lucide-react";
4224
- import { memo as memo4, useCallback as useCallback7 } from "react";
4225
- import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
5457
+ import { memo as memo4, useCallback as useCallback10 } from "react";
5458
+ import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
4226
5459
  var NAME_CLEARANCE = 96;
4227
5460
  function nameBelow(box, transform) {
4228
5461
  const [, panY = 0, zoom = 1] = transform;
@@ -4244,33 +5477,33 @@ var PresenceLayer = memo4(function PresenceLayer({
4244
5477
  }
4245
5478
  const changing = [...new Set(agents.flatMap((agent) => agent.boards))];
4246
5479
  const boxes = useBoxes([...selected.keys(), ...changing]);
4247
- const below = useStore3(useCallback7((state) => [...boxes].filter(([, box]) => nameBelow(box, state.transform)).map(([id]) => id).join(`
5480
+ const below = useStore3(useCallback10((state) => [...boxes].filter(([, box]) => nameBelow(box, state.transform)).map(([id]) => id).join(`
4248
5481
  `), [boxes]));
4249
5482
  if (boxes.size === 0)
4250
5483
  return null;
4251
- return /* @__PURE__ */ jsxs13(ViewportPortal2, {
5484
+ return /* @__PURE__ */ jsxs15(ViewportPortal2, {
4252
5485
  children: [
4253
5486
  changing.map((id) => {
4254
5487
  const box = boxes.get(id);
4255
- return box ? /* @__PURE__ */ jsx15("div", {
5488
+ return box ? /* @__PURE__ */ jsx17("div", {
4256
5489
  "data-agent-board": id,
4257
5490
  className: "sixb-agent-board pointer-events-none absolute rounded-[12px]",
4258
5491
  style: place(box, 4),
4259
- children: /* @__PURE__ */ jsx15("div", {
5492
+ children: /* @__PURE__ */ jsx17("div", {
4260
5493
  className: "@container absolute top-3 right-3 flex origin-top-right justify-end",
4261
5494
  style: {
4262
5495
  width: `calc(${Math.max(box.w - 16, 0)}px / ${NAME_SCALE_VALUE})`,
4263
5496
  transform: `scale(${NAME_SCALE_VALUE})`
4264
5497
  },
4265
- children: /* @__PURE__ */ jsxs13("span", {
5498
+ children: /* @__PURE__ */ jsxs15("span", {
4266
5499
  title: messages.agentChanging,
4267
5500
  className: "flex max-w-full min-w-0 items-center gap-1.5 rounded-full bg-background/95 px-2.5 py-1 text-[12px] font-medium whitespace-nowrap text-primary shadow-[0_1px_2px_rgb(0_0_0/0.08),0_6px_16px_-8px_rgb(0_0_0/0.3)] ring-1 ring-[color-mix(in_oklab,var(--primary)_25%,transparent)] @max-[8rem]:px-1.5",
4268
5501
  children: [
4269
- /* @__PURE__ */ jsx15(Sparkles2, {
5502
+ /* @__PURE__ */ jsx17(Sparkles2, {
4270
5503
  className: "size-3.5 shrink-0 motion-safe:animate-pulse",
4271
5504
  "aria-hidden": "true"
4272
5505
  }),
4273
- /* @__PURE__ */ jsx15("span", {
5506
+ /* @__PURE__ */ jsx17("span", {
4274
5507
  className: "min-w-0 truncate @max-[8rem]:sr-only",
4275
5508
  children: messages.agentChanging
4276
5509
  })
@@ -4281,21 +5514,21 @@ var PresenceLayer = memo4(function PresenceLayer({
4281
5514
  }),
4282
5515
  [...selected].map(([id, user]) => {
4283
5516
  const box = boxes.get(id);
4284
- return box ? /* @__PURE__ */ jsx15("div", {
5517
+ return box ? /* @__PURE__ */ jsx17("div", {
4285
5518
  "data-peer-selection": id,
4286
5519
  className: "pointer-events-none absolute rounded-[6px]",
4287
5520
  style: {
4288
5521
  ...place(box, 3),
4289
5522
  boxShadow: `0 0 0 calc(2px * ${NAME_SCALE_VALUE}) ${user.color}`
4290
5523
  },
4291
- children: /* @__PURE__ */ jsxs13("span", {
5524
+ children: /* @__PURE__ */ jsxs15("span", {
4292
5525
  "data-name": below.split(`
4293
5526
  `).includes(id) ? "below" : "above",
4294
5527
  className: "absolute left-0 rounded-[4px] px-1.5 py-px text-[11px] leading-4 font-medium whitespace-nowrap text-white data-[name=above]:bottom-full data-[name=above]:mb-1 data-[name=above]:origin-bottom-left data-[name=below]:top-1 data-[name=below]:left-1 data-[name=below]:origin-top-left",
4295
5528
  style: { backgroundColor: user.color, transform: `scale(${NAME_SCALE_VALUE})` },
4296
5529
  children: [
4297
5530
  livePersonName(user, labels),
4298
- user.guest && user.name ? /* @__PURE__ */ jsxs13("span", {
5531
+ user.guest && user.name ? /* @__PURE__ */ jsxs15("span", {
4299
5532
  className: "opacity-75",
4300
5533
  children: [
4301
5534
  " \xB7 ",
@@ -4319,7 +5552,7 @@ function place(box, margin) {
4319
5552
  function useBoxes(ids) {
4320
5553
  const key = ids.join(`
4321
5554
  `);
4322
- const select = useCallback7((state) => {
5555
+ const select = useCallback10((state) => {
4323
5556
  const boxes = new Map;
4324
5557
  for (const id of key ? key.split(`
4325
5558
  `) : []) {
@@ -4353,7 +5586,7 @@ function sameBoxes2(left, right) {
4353
5586
  }
4354
5587
 
4355
5588
  // src/artifacts/renderers/canvas/canvas.tsx
4356
- import { jsx as jsx16, jsxs as jsxs14, Fragment as Fragment7 } from "react/jsx-runtime";
5589
+ import { jsx as jsx18, jsxs as jsxs16, Fragment as Fragment8 } from "react/jsx-runtime";
4357
5590
  var canvas_default = memo5(function CanvasBoard({
4358
5591
  canvas,
4359
5592
  version,
@@ -4364,8 +5597,8 @@ var canvas_default = memo5(function CanvasBoard({
4364
5597
  live,
4365
5598
  theme
4366
5599
  }) {
4367
- return /* @__PURE__ */ jsx16(ReactFlowProvider, {
4368
- children: /* @__PURE__ */ jsx16(Board, {
5600
+ return /* @__PURE__ */ jsx18(ReactFlowProvider, {
5601
+ children: /* @__PURE__ */ jsx18(Board, {
4369
5602
  canvas,
4370
5603
  title,
4371
5604
  mode,
@@ -4388,32 +5621,26 @@ function Board({
4388
5621
  theme
4389
5622
  }) {
4390
5623
  const messages = useArtifactMessages().canvas;
4391
- const boards = useMemo6(() => canvas.items.filter((item) => item.type === "board"), [canvas]);
4392
- const arrows = useMemo6(() => canvas.items.filter((item) => item.type === "arrow"), [canvas]);
5624
+ const boards = useMemo9(() => canvas.items.filter((item) => item.type === "board"), [canvas]);
5625
+ const arrows = useMemo9(() => canvas.items.filter((item) => item.type === "arrow"), [canvas]);
4393
5626
  const previews = useBoardPreviews(version);
4394
- const places = useMemo6(() => canvas.items.flatMap((item) => item.type === "board" || item.type === "embed" ? [{ ...item, pictured: previews[item.id] === "ready" }] : []), [canvas, previews]);
5627
+ const places = useMemo9(() => canvas.items.flatMap((item) => item.type === "board" || item.type === "embed" ? [{ ...item, pictured: previews[item.id] === "ready" }] : []), [canvas, previews]);
4395
5628
  const running = useLiveSet(places);
4396
- const [opened, setOpened] = useState11(() => focus && boards.some((board) => board.id === focus) ? focus : null);
4397
- const { fitView } = useReactFlow2();
4398
- const close = useCallback8(() => {
5629
+ const [opened, setOpened] = useState14(() => focus && boards.some((board) => board.id === focus) ? focus : null);
5630
+ const { fitView } = useReactFlow3();
5631
+ const close = useCallback11(() => {
4399
5632
  const id = opened;
4400
5633
  setOpened(null);
4401
5634
  if (!id)
4402
5635
  return;
4403
5636
  fitView({ nodes: [{ id }], padding: CANVAS_FIT_PADDING, maxZoom: 1, duration: 220 });
4404
5637
  }, [opened, fitView]);
4405
- const live = useMemo6(() => ({
4406
- version: version ?? null,
4407
- live: running,
4408
- previews,
4409
- mode,
4410
- ...version ? { open: setOpened } : {}
4411
- }), [version, running, previews, mode]);
4412
- const pictureOf = useCallback8((id) => version && previews[id] === "ready" ? boardPreviewUrl(version, id, mode) : undefined, [version, previews, mode]);
5638
+ const pictureOf = useCallback11((id) => version && previews[id] === "ready" ? boardPreviewUrl(version, id, mode) : undefined, [version, previews, mode]);
4413
5639
  const board = useBoardEditing(canvas, edit, version ? setOpened : undefined);
5640
+ const resizeBoard = useResizeBoard(board.editing ? board.items : null);
4414
5641
  const editBoard = edit?.live?.editBoard;
4415
5642
  const stopCapturing = edit?.live?.stopCapturing;
4416
- const boardEditor = useMemo6(() => editBoard && stopCapturing ? { editBoard, stopCapturing } : null, [editBoard, stopCapturing]);
5643
+ const boardEditor = useMemo9(() => editBoard && stopCapturing ? { editBoard, stopCapturing } : null, [editBoard, stopCapturing]);
4417
5644
  useNameScaleVariable(board.root);
4418
5645
  const view = useArtifactView();
4419
5646
  const commenting = useCanvasCommenting({
@@ -4423,10 +5650,10 @@ function Board({
4423
5650
  boards,
4424
5651
  revision: view?.revision ?? version?.revision ?? 1
4425
5652
  });
4426
- const { getInternalNode, screenToFlowPosition } = useReactFlow2();
5653
+ const { getInternalNode, screenToFlowPosition } = useReactFlow3();
4427
5654
  const { setCommenting, cancelDraft, draft } = commenting;
4428
- const pointed = useRef8(false);
4429
- useEffect8(() => {
5655
+ const pointed = useRef13(false);
5656
+ useEffect12(() => {
4430
5657
  if (!commenting.enabled)
4431
5658
  return;
4432
5659
  const onKey = (event) => {
@@ -4453,7 +5680,7 @@ function Board({
4453
5680
  window.addEventListener("keydown", onKey);
4454
5681
  return () => window.removeEventListener("keydown", onKey);
4455
5682
  }, [commenting, opened, draft, cancelDraft, setCommenting, board.root]);
4456
- const placing = useMemo6(() => commenting.commenting ? {
5683
+ const placing = useMemo9(() => commenting.commenting ? {
4457
5684
  nodesDraggable: false,
4458
5685
  nodesConnectable: false,
4459
5686
  elementsSelectable: false,
@@ -4475,7 +5702,7 @@ function Board({
4475
5702
  },
4476
5703
  onPaneClick: () => cancelDraft()
4477
5704
  } : {}, [commenting, getInternalNode, screenToFlowPosition, boards, cancelDraft]);
4478
- const showThread = useCallback8((id) => {
5705
+ const showThread = useCallback11((id) => {
4479
5706
  commenting.setActive(id);
4480
5707
  const thread = commenting.threads.find((each) => each.comment.id === id);
4481
5708
  const on = thread?.comment.anchor.board;
@@ -4488,8 +5715,33 @@ function Board({
4488
5715
  }
4489
5716
  fitView({ nodes: [{ id: on }], padding: CANVAS_FIT_PADDING, maxZoom: 1, duration: 260 });
4490
5717
  }, [commenting, boards, opened, fitView]);
5718
+ const reads = !board.editing && !commenting.commenting && opened === null;
5719
+ const follow = useRef13(() => {});
5720
+ const gestures = useBoardGestures({
5721
+ root: board.root,
5722
+ pointed,
5723
+ reading: reads,
5724
+ opened: opened !== null,
5725
+ padding: CANVAS_FIT_PADDING,
5726
+ onPress: (from, text) => follow.current(from, text)
5727
+ });
5728
+ follow.current = (from, text) => {
5729
+ const to = followedArrow(arrows, boards, from, text);
5730
+ const target = boards.find((each) => each.id === to);
5731
+ if (target)
5732
+ gestures.glide(target);
5733
+ };
5734
+ const live = useMemo9(() => ({
5735
+ version: version ?? null,
5736
+ live: running,
5737
+ previews,
5738
+ mode,
5739
+ interactive: reads && version !== undefined,
5740
+ gestures,
5741
+ ...version ? { open: setOpened } : {}
5742
+ }), [version, running, previews, mode, reads, gestures]);
4491
5743
  const open = live.open;
4492
- const reading = useMemo6(() => ({
5744
+ const reading = useMemo9(() => ({
4493
5745
  nodesDraggable: false,
4494
5746
  nodesConnectable: false,
4495
5747
  elementsSelectable: false,
@@ -4498,16 +5750,16 @@ function Board({
4498
5750
  open?.(node.id);
4499
5751
  }
4500
5752
  }), [open]);
4501
- const framed = useMemo6(() => {
5753
+ const framed = useMemo9(() => {
4502
5754
  const item = focus ? canvas.items.find((candidate) => candidate.id === focus) : undefined;
4503
5755
  return item && item.type !== "arrow" && item.type !== "text" ? item.id : undefined;
4504
5756
  }, [canvas, focus]);
4505
- const fitOptions = useMemo6(() => ({
5757
+ const fitOptions = useMemo9(() => ({
4506
5758
  padding: CANVAS_FIT_PADDING,
4507
5759
  maxZoom: 1,
4508
5760
  ...framed ? { nodes: [{ id: framed }] } : {}
4509
5761
  }), [framed]);
4510
- return /* @__PURE__ */ jsxs14("div", {
5762
+ return /* @__PURE__ */ jsxs16("div", {
4511
5763
  ref: board.root,
4512
5764
  tabIndex: board.editing ? -1 : undefined,
4513
5765
  className: "sixb-canvas sixb-artboard @container/canvas relative flex size-full bg-background outline-none",
@@ -4536,15 +5788,15 @@ function Board({
4536
5788
  live.open(id);
4537
5789
  },
4538
5790
  children: [
4539
- /* @__PURE__ */ jsxs14("div", {
4540
- className: cn11("relative h-full min-w-0 flex-1 bg-background text-foreground", theme?.className),
5791
+ /* @__PURE__ */ jsxs16("div", {
5792
+ className: cn15("relative h-full min-w-0 flex-1 bg-background text-foreground", theme?.className),
4541
5793
  style: theme?.style,
4542
5794
  children: [
4543
- /* @__PURE__ */ jsx16(LiveBoardsProvider, {
5795
+ /* @__PURE__ */ jsx18(LiveBoardsProvider, {
4544
5796
  value: live,
4545
- children: /* @__PURE__ */ jsx16(CanvasEditingProvider, {
5797
+ children: /* @__PURE__ */ jsx18(CanvasEditingProvider, {
4546
5798
  value: board.editing ? board.items : null,
4547
- children: /* @__PURE__ */ jsxs14(ReactFlow, {
5799
+ children: /* @__PURE__ */ jsxs16(ReactFlow, {
4548
5800
  nodes: board.nodes,
4549
5801
  edges: board.edges,
4550
5802
  nodeTypes: CANVAS_NODE_TYPES,
@@ -4565,21 +5817,21 @@ function Board({
4565
5817
  ...placing,
4566
5818
  proOptions: { hideAttribution: true },
4567
5819
  children: [
4568
- /* @__PURE__ */ jsx16(Background, {
5820
+ /* @__PURE__ */ jsx18(Background, {
4569
5821
  variant: BackgroundVariant.Dots,
4570
5822
  gap: 24,
4571
5823
  size: 1.3
4572
5824
  }),
4573
- /* @__PURE__ */ jsx16(CanvasControls, {
5825
+ /* @__PURE__ */ jsx18(CanvasControls, {
4574
5826
  padding: CANVAS_FIT_PADDING
4575
5827
  }),
4576
- liveArtifact ? /* @__PURE__ */ jsx16(PresenceLayer, {
5828
+ liveArtifact ? /* @__PURE__ */ jsx18(PresenceLayer, {
4577
5829
  live: liveArtifact
4578
5830
  }) : null,
4579
5831
  board.editing ? board.toolbar : null,
4580
- commenting.enabled ? /* @__PURE__ */ jsxs14(Fragment7, {
5832
+ commenting.enabled ? /* @__PURE__ */ jsxs16(Fragment8, {
4581
5833
  children: [
4582
- /* @__PURE__ */ jsx16(CanvasCommentPins, {
5834
+ /* @__PURE__ */ jsx18(CanvasCommentPins, {
4583
5835
  pins: commenting.pins,
4584
5836
  active: commenting.active,
4585
5837
  draft: draft?.where === "canvas" ? draft : null,
@@ -4590,14 +5842,14 @@ function Board({
4590
5842
  onSubmitDraft: commenting.submitDraft,
4591
5843
  onCancelDraft: cancelDraft
4592
5844
  }),
4593
- /* @__PURE__ */ jsx16(Panel3, {
5845
+ /* @__PURE__ */ jsx18(Panel3, {
4594
5846
  position: "top-right",
4595
5847
  className: "!m-3",
4596
- children: /* @__PURE__ */ jsx16(CommentTools, {
5848
+ children: /* @__PURE__ */ jsx18(CommentTools, {
4597
5849
  commenting
4598
5850
  })
4599
5851
  }),
4600
- commenting.commenting ? /* @__PURE__ */ jsx16(ZoomVariable, {
5852
+ commenting.commenting ? /* @__PURE__ */ jsx18(ZoomVariable, {
4601
5853
  root: board.root
4602
5854
  }) : null
4603
5855
  ]
@@ -4606,13 +5858,13 @@ function Board({
4606
5858
  })
4607
5859
  })
4608
5860
  }),
4609
- commenting.enabled && commenting.commenting && !draft && !opened ? /* @__PURE__ */ jsx16("div", {
5861
+ commenting.enabled && commenting.commenting && !draft && !opened ? /* @__PURE__ */ jsx18("div", {
4610
5862
  className: "pointer-events-none absolute inset-x-0 bottom-4 z-20 flex justify-center px-4 max-sm:bottom-20",
4611
- children: /* @__PURE__ */ jsx16(CommentModeHint, {
5863
+ children: /* @__PURE__ */ jsx18(CommentModeHint, {
4612
5864
  onExit: () => setCommenting(false)
4613
5865
  })
4614
5866
  }) : null,
4615
- opened && version ? /* @__PURE__ */ jsx16(BoardFocus, {
5867
+ opened && version ? /* @__PURE__ */ jsx18(BoardFocus, {
4616
5868
  version,
4617
5869
  boards,
4618
5870
  arrows,
@@ -4623,11 +5875,12 @@ function Board({
4623
5875
  live: liveArtifact ?? null,
4624
5876
  canvas: boardEditor,
4625
5877
  mode: commenting.commenting ? "comment" : boardEditor ? "edit" : "read",
5878
+ ...resizeBoard ? { onResizeBoard: resizeBoard } : {},
4626
5879
  ...commenting.enabled ? {
4627
5880
  pins: commenting.pins,
4628
5881
  activePin: commenting.active,
4629
5882
  draft: draft?.where === "focus" ? draft : null,
4630
- tools: /* @__PURE__ */ jsx16(CommentTools, {
5883
+ tools: /* @__PURE__ */ jsx18(CommentTools, {
4631
5884
  commenting,
4632
5885
  className: "border-0 bg-transparent p-0 shadow-none"
4633
5886
  }),
@@ -4651,7 +5904,7 @@ function Board({
4651
5904
  }) : null
4652
5905
  ]
4653
5906
  }),
4654
- commenting.enabled && commenting.panel ? /* @__PURE__ */ jsx16(CommentsPanel, {
5907
+ commenting.enabled && commenting.panel ? /* @__PURE__ */ jsx18(CommentsPanel, {
4655
5908
  threads: commenting.threads,
4656
5909
  loading: commenting.loading,
4657
5910
  failed: commenting.failed,
@@ -4671,10 +5924,28 @@ function Board({
4671
5924
  ]
4672
5925
  });
4673
5926
  }
5927
+ function useResizeBoard(items) {
5928
+ const start = useStartEditing();
5929
+ const [waiting, setWaiting] = useState14(null);
5930
+ useEffect12(() => {
5931
+ if (!waiting || !items)
5932
+ return;
5933
+ items.resize(waiting.id, waiting.box);
5934
+ setWaiting(null);
5935
+ }, [waiting, items]);
5936
+ if (items)
5937
+ return items.resize;
5938
+ if (!start)
5939
+ return null;
5940
+ return (id, box) => {
5941
+ setWaiting({ id, box });
5942
+ start();
5943
+ };
5944
+ }
4674
5945
  var COMMENTS = "[data-comments-panel], [data-comment-pin], [data-board-tools]";
4675
5946
  function useNameScaleVariable(root) {
4676
- const store = useStoreApi4();
4677
- useEffect8(() => {
5947
+ const store = useStoreApi5();
5948
+ useEffect12(() => {
4678
5949
  let last = "";
4679
5950
  const update = () => {
4680
5951
  const element = root.current;
@@ -4692,7 +5963,7 @@ function useNameScaleVariable(root) {
4692
5963
  }
4693
5964
  function ZoomVariable({ root }) {
4694
5965
  const zoom = useStore4((state) => state.transform[2]);
4695
- useEffect8(() => {
5966
+ useEffect12(() => {
4696
5967
  root.current?.style.setProperty("--sixb-zoom", String(zoom));
4697
5968
  }, [root, zoom]);
4698
5969
  return null;
@@ -4701,4 +5972,4 @@ export {
4701
5972
  canvas_default as default
4702
5973
  };
4703
5974
 
4704
- //# debugId=061BF88EBA02626C64756E2164756E21
5975
+ //# debugId=2ADFB45359DBA36F64756E2164756E21