@pixerate/editor-react 0.91.0 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/canvas/AgentPresenceLayer.d.cts +3 -0
  2. package/dist/canvas/AgentPresenceLayer.d.ts +3 -0
  3. package/dist/canvas/index.cjs +1032 -893
  4. package/dist/canvas/index.d.cts +2 -0
  5. package/dist/canvas/index.d.ts +2 -0
  6. package/dist/canvas/index.js +125 -74
  7. package/dist/canvas/useCanvasPlaybackSurface.d.cts +28 -0
  8. package/dist/canvas/useCanvasPlaybackSurface.d.ts +28 -0
  9. package/dist/{chunk-SMMO7CZB.js → chunk-6MDTFAPY.js} +84 -2
  10. package/dist/chunk-ECBC4HD7.js +95 -0
  11. package/dist/hooks/useAgentToolProvider.d.cts +6 -2
  12. package/dist/hooks/useAgentToolProvider.d.ts +6 -2
  13. package/dist/image-editor/ImageEditor.d.cts +10 -0
  14. package/dist/image-editor/ImageEditor.d.ts +10 -0
  15. package/dist/image-editor/index.cjs +1027 -864
  16. package/dist/image-editor/index.js +2 -1
  17. package/dist/index.cjs +1986 -1810
  18. package/dist/index.d.cts +1 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +16 -2
  21. package/dist/playback/AgentPlaybackContext.d.cts +9 -0
  22. package/dist/playback/AgentPlaybackContext.d.ts +9 -0
  23. package/dist/playback/PresenceLayer.d.cts +28 -0
  24. package/dist/playback/PresenceLayer.d.ts +28 -0
  25. package/dist/playback/index.d.cts +3 -0
  26. package/dist/playback/index.d.ts +3 -0
  27. package/dist/playback/usePlaybackSurface.d.cts +9 -0
  28. package/dist/playback/usePlaybackSurface.d.ts +9 -0
  29. package/dist/vector/VectorCanvas.d.cts +11 -1
  30. package/dist/vector/VectorCanvas.d.ts +11 -1
  31. package/dist/vector/index.cjs +945 -826
  32. package/dist/vector/index.js +42 -3
  33. package/package.json +13 -13
@@ -1,4 +1,6 @@
1
1
  export { AgentPresenceLayer, type AgentPresenceLayerProps } from './AgentPresenceLayer.cjs';
2
+ export { PresenceLayer, type PresenceLayerProps } from '../playback/PresenceLayer.cjs';
3
+ export { useCanvasPlaybackSurface, type UseCanvasPlaybackSurfaceOptions } from './useCanvasPlaybackSurface.cjs';
2
4
  export { useStreamingCanvas, type UseStreamingCanvasOptions } from './useStreamingCanvas.cjs';
3
5
  export { useCanvasGraph, type UseCanvasGraphOptions } from './useCanvasGraph.cjs';
4
6
  export { useCanvasLayout, type UseCanvasLayoutOptions } from './useCanvasLayout.cjs';
@@ -1,4 +1,6 @@
1
1
  export { AgentPresenceLayer, type AgentPresenceLayerProps } from './AgentPresenceLayer.js';
2
+ export { PresenceLayer, type PresenceLayerProps } from '../playback/PresenceLayer.js';
3
+ export { useCanvasPlaybackSurface, type UseCanvasPlaybackSurfaceOptions } from './useCanvasPlaybackSurface.js';
2
4
  export { useStreamingCanvas, type UseStreamingCanvasOptions } from './useStreamingCanvas.js';
3
5
  export { useCanvasGraph, type UseCanvasGraphOptions } from './useCanvasGraph.js';
4
6
  export { useCanvasLayout, type UseCanvasLayoutOptions } from './useCanvasLayout.js';
@@ -1,3 +1,7 @@
1
+ import {
2
+ PresenceLayer,
3
+ usePlaybackSurface
4
+ } from "../chunk-ECBC4HD7.js";
1
5
  import {
2
6
  EffectParameters,
3
7
  EffectsBrowser,
@@ -69,13 +73,58 @@ function AgentPresenceLayer({ presences, className = "" }) {
69
73
  );
70
74
  }
71
75
 
76
+ // src/canvas/useCanvasPlaybackSurface.ts
77
+ import { useMemo, useRef } from "react";
78
+ import { createCanvasPlaybackLocator } from "@pixerate/editor/canvas";
79
+ function useCanvasPlaybackSurface(playback, id, options) {
80
+ const latest = useRef(options);
81
+ latest.current = options;
82
+ const locate = useMemo(
83
+ () => createCanvasPlaybackLocator({
84
+ getNodes: () => latest.current.getNodes(),
85
+ getEdges: () => latest.current.getEdges?.() ?? [],
86
+ get rectOptions() {
87
+ return latest.current.rectOptions;
88
+ }
89
+ }),
90
+ []
91
+ );
92
+ const box = () => latest.current.container.current?.getBoundingClientRect() ?? null;
93
+ return usePlaybackSurface(playback, id, {
94
+ defaultKind: "node",
95
+ locate,
96
+ bounds: () => {
97
+ const r = box();
98
+ const { x, y, zoom } = latest.current.viewport;
99
+ return r && r.width > 0 ? { x: -x / zoom, y: -y / zoom, width: r.width / zoom, height: r.height / zoom } : null;
100
+ },
101
+ visible: () => {
102
+ if (latest.current.visible) return latest.current.visible();
103
+ const r = box();
104
+ const hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
105
+ return !!r && r.width > 0 && r.height > 0 && !hidden;
106
+ },
107
+ toViewport: (p) => {
108
+ const r = box();
109
+ const { x, y, zoom } = latest.current.viewport;
110
+ return { x: (r?.left ?? 0) + p.x * zoom + x, y: (r?.top ?? 0) + p.y * zoom + y };
111
+ },
112
+ fromViewport: (p) => {
113
+ const r = box();
114
+ const { x, y, zoom } = latest.current.viewport;
115
+ return { x: (p.x - (r?.left ?? 0) - x) / zoom, y: (p.y - (r?.top ?? 0) - y) / zoom };
116
+ },
117
+ reveal: () => latest.current.reveal?.()
118
+ });
119
+ }
120
+
72
121
  // src/canvas/useStreamingCanvas.ts
73
- import { useEffect, useRef, useCallback } from "react";
122
+ import { useEffect, useRef as useRef2, useCallback } from "react";
74
123
  import {
75
124
  StreamingLayoutManager
76
125
  } from "@pixerate/editor/canvas";
77
126
  function useStreamingCanvas(options) {
78
- const managerRef = useRef(null);
127
+ const managerRef = useRef2(null);
79
128
  useEffect(() => {
80
129
  const manager = new StreamingLayoutManager({
81
130
  throttleMs: options.throttleMs,
@@ -116,12 +165,12 @@ function useStreamingCanvas(options) {
116
165
  }
117
166
 
118
167
  // src/canvas/useCanvasGraph.ts
119
- import { useState, useCallback as useCallback2, useRef as useRef2 } from "react";
168
+ import { useState, useCallback as useCallback2, useRef as useRef3 } from "react";
120
169
  function useCanvasGraph(options = {}) {
121
170
  const [nodes, setNodesState] = useState(options.initialNodes ?? []);
122
171
  const [edges, setEdgesState] = useState(options.initialEdges ?? []);
123
- const baselineNodesRef = useRef2(options.initialNodes ?? []);
124
- const baselineEdgesRef = useRef2(options.initialEdges ?? []);
172
+ const baselineNodesRef = useRef3(options.initialNodes ?? []);
173
+ const baselineEdgesRef = useRef3(options.initialEdges ?? []);
125
174
  const setNodes = useCallback2(
126
175
  (updater) => {
127
176
  setNodesState((prev) => {
@@ -508,7 +557,7 @@ function useCanvasShortcuts(options = {}) {
508
557
  }
509
558
 
510
559
  // src/canvas/useCanvasDocking.ts
511
- import { useCallback as useCallback5, useRef as useRef3 } from "react";
560
+ import { useCallback as useCallback5, useRef as useRef4 } from "react";
512
561
  function useCanvasDocking(options = {}) {
513
562
  const {
514
563
  strategy = "center-point",
@@ -518,7 +567,7 @@ function useCanvasDocking(options = {}) {
518
567
  onDockLeave,
519
568
  onDockDrop
520
569
  } = options;
521
- const activeDockTargetRef = useRef3(null);
570
+ const activeDockTargetRef = useRef4(null);
522
571
  const isDockable = useCallback5(
523
572
  (node) => {
524
573
  if (!dockableTypes || dockableTypes.length === 0) return true;
@@ -625,7 +674,7 @@ function useCanvasDocking(options = {}) {
625
674
  }
626
675
 
627
676
  // src/canvas/useCanvasExplosion.ts
628
- import { useCallback as useCallback6, useRef as useRef4 } from "react";
677
+ import { useCallback as useCallback6, useRef as useRef5 } from "react";
629
678
  import {
630
679
  calculateDirectionalDisplacement,
631
680
  createFanOutTrajectory,
@@ -638,7 +687,7 @@ function mergeById(base, updated) {
638
687
  return base.map((n) => byId.get(n.id) ?? n);
639
688
  }
640
689
  function useCanvasExplosion(target) {
641
- const snapshotsRef = useRef4(/* @__PURE__ */ new Map());
690
+ const snapshotsRef = useRef5(/* @__PURE__ */ new Map());
642
691
  const explodeNode = useCallback6(
643
692
  (parentNodeId, options) => {
644
693
  const { nodes, edges, setNodes, setEdges } = target;
@@ -766,18 +815,18 @@ function useCanvasExplosion(target) {
766
815
  }
767
816
 
768
817
  // src/canvas/useCanvasArrange.ts
769
- import { useEffect as useEffect3, useMemo, useRef as useRef5, useState as useState2 } from "react";
818
+ import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef6, useState as useState2 } from "react";
770
819
  import {
771
820
  createCanvasArrangeController,
772
821
  matchArrangeShortcut
773
822
  } from "@pixerate/editor/canvas";
774
823
  function useCanvasArrange(options) {
775
824
  const [guides, setGuides] = useState2([]);
776
- const nodesRef = useRef5(options.nodes);
825
+ const nodesRef = useRef6(options.nodes);
777
826
  nodesRef.current = options.nodes;
778
- const optionsRef = useRef5(options);
827
+ const optionsRef = useRef6(options);
779
828
  optionsRef.current = options;
780
- const controller = useMemo(
829
+ const controller = useMemo2(
781
830
  () => createCanvasArrangeController({
782
831
  getNodes: () => nodesRef.current,
783
832
  setNodes: (next) => {
@@ -805,10 +854,10 @@ function useCanvasArrange(options) {
805
854
  }),
806
855
  []
807
856
  );
808
- return useMemo(() => ({ ...controller, guides }), [controller, guides]);
857
+ return useMemo2(() => ({ ...controller, guides }), [controller, guides]);
809
858
  }
810
859
  function useCanvasArrangeShortcuts(options) {
811
- const optionsRef = useRef5(options);
860
+ const optionsRef = useRef6(options);
812
861
  optionsRef.current = options;
813
862
  const { targetElement, enabled = true } = options;
814
863
  useEffect3(() => {
@@ -836,16 +885,16 @@ function useCanvasArrangeShortcuts(options) {
836
885
  }
837
886
 
838
887
  // src/canvas/useCanvasScenes.ts
839
- import { useMemo as useMemo2, useRef as useRef6, useSyncExternalStore } from "react";
888
+ import { useMemo as useMemo3, useRef as useRef7, useSyncExternalStore } from "react";
840
889
  import {
841
890
  CanvasScenesStore,
842
891
  fitViewportToNodes,
843
892
  transitionCanvasView
844
893
  } from "@pixerate/editor/canvas";
845
894
  function useCanvasScenes(options = {}) {
846
- const optionsRef = useRef6(options);
895
+ const optionsRef = useRef7(options);
847
896
  optionsRef.current = options;
848
- const storeRef = useRef6(null);
897
+ const storeRef = useRef7(null);
849
898
  if (!storeRef.current) storeRef.current = options.store ?? new CanvasScenesStore(options);
850
899
  const store = storeRef.current;
851
900
  const state = useSyncExternalStore(
@@ -853,7 +902,7 @@ function useCanvasScenes(options = {}) {
853
902
  () => store.getState(),
854
903
  () => store.getState()
855
904
  );
856
- const actions = useMemo2(() => {
905
+ const actions = useMemo3(() => {
857
906
  const show = (scene) => {
858
907
  if (!scene) return scene;
859
908
  const o = optionsRef.current;
@@ -906,16 +955,16 @@ function useCanvasScenes(options = {}) {
906
955
  }
907
956
 
908
957
  // src/canvas/useCanvasCapture.ts
909
- import { useMemo as useMemo3, useRef as useRef7 } from "react";
958
+ import { useMemo as useMemo4, useRef as useRef8 } from "react";
910
959
  import {
911
960
  canvasNodeCaptureRect,
912
961
  createCanvasCaptureToolProvider
913
962
  } from "@pixerate/editor/canvas";
914
963
  import { rasterizeElement } from "@pixerate/editor/tools";
915
964
  function useCanvasCapture(options) {
916
- const optionsRef = useRef7(options);
965
+ const optionsRef = useRef8(options);
917
966
  optionsRef.current = options;
918
- return useMemo3(() => {
967
+ return useMemo4(() => {
919
968
  const latest = () => optionsRef.current;
920
969
  return createCanvasCaptureToolProvider({
921
970
  ...options,
@@ -1017,18 +1066,18 @@ function CanvasGuidesLayer({
1017
1066
  }
1018
1067
 
1019
1068
  // src/canvas/useCanvasDraw.ts
1020
- import { useEffect as useEffect4, useMemo as useMemo4, useRef as useRef8, useState as useState3 } from "react";
1069
+ import { useEffect as useEffect4, useMemo as useMemo5, useRef as useRef9, useState as useState3 } from "react";
1021
1070
  import {
1022
1071
  createCanvasDrawController
1023
1072
  } from "@pixerate/editor/canvas";
1024
1073
  function useCanvasDraw(options) {
1025
- const nodesRef = useRef8(options.nodes);
1074
+ const nodesRef = useRef9(options.nodes);
1026
1075
  nodesRef.current = options.nodes;
1027
- const optionsRef = useRef8(options);
1076
+ const optionsRef = useRef9(options);
1028
1077
  optionsRef.current = options;
1029
1078
  const [tool, setToolState] = useState3(options.initialTool ?? "select");
1030
1079
  const [activeStroke, setActiveStroke] = useState3(null);
1031
- const controller = useMemo4(
1080
+ const controller = useMemo5(
1032
1081
  () => createCanvasDrawController({
1033
1082
  getNodes: () => nodesRef.current,
1034
1083
  setNodes: (next) => {
@@ -1056,7 +1105,7 @@ function useCanvasDraw(options) {
1056
1105
  controller.setTool(options.initialTool);
1057
1106
  }
1058
1107
  }, [options.initialTool, controller]);
1059
- return useMemo4(
1108
+ return useMemo5(
1060
1109
  () => ({
1061
1110
  tool,
1062
1111
  style,
@@ -1077,7 +1126,7 @@ function useCanvasDraw(options) {
1077
1126
  }
1078
1127
 
1079
1128
  // src/canvas/CanvasDrawLayer.tsx
1080
- import { useCallback as useCallback7, useEffect as useEffect5, useRef as useRef9, useState as useState4 } from "react";
1129
+ import { useCallback as useCallback7, useEffect as useEffect5, useRef as useRef10, useState as useState4 } from "react";
1081
1130
  import {
1082
1131
  pointerPenSample,
1083
1132
  strokePointsToPathData,
@@ -1094,7 +1143,7 @@ function CanvasDrawLayer({
1094
1143
  cursor,
1095
1144
  eraserRadius = 12
1096
1145
  }) {
1097
- const svgRef = useRef9(null);
1146
+ const svgRef = useRef10(null);
1098
1147
  const [spaceHeld, setSpaceHeld] = useState4(false);
1099
1148
  const [eraserPos, setEraserPos] = useState4(null);
1100
1149
  useEffect5(() => {
@@ -1234,7 +1283,7 @@ function CanvasDrawLayer({
1234
1283
  }
1235
1284
 
1236
1285
  // src/canvas/useCanvasMeasure.ts
1237
- import { useCallback as useCallback8, useEffect as useEffect6, useMemo as useMemo5, useRef as useRef10, useState as useState5 } from "react";
1286
+ import { useCallback as useCallback8, useEffect as useEffect6, useMemo as useMemo6, useRef as useRef11, useState as useState5 } from "react";
1238
1287
  import {
1239
1288
  isMeasureModifierHeld,
1240
1289
  measureSelection
@@ -1244,7 +1293,7 @@ function useCanvasMeasure(options) {
1244
1293
  const { nodes, enabled = true, requireModifier = true, targetElement, rectOptions } = options;
1245
1294
  const [hoveredId, setHoveredId] = useState5(null);
1246
1295
  const [modifier, setModifier] = useState5(false);
1247
- const optionsRef = useRef10(options);
1296
+ const optionsRef = useRef11(options);
1248
1297
  optionsRef.current = options;
1249
1298
  useEffect6(() => {
1250
1299
  if (!enabled) return;
@@ -1263,7 +1312,7 @@ function useCanvasMeasure(options) {
1263
1312
  };
1264
1313
  }, [enabled, targetElement]);
1265
1314
  const active = enabled && (!requireModifier || modifier);
1266
- const result = useMemo5(() => {
1315
+ const result = useMemo6(() => {
1267
1316
  if (!active) return EMPTY;
1268
1317
  const ids = optionsRef.current.getSelectedIds?.() ?? nodes.filter((n) => n.selected).map((n) => n.id);
1269
1318
  return measureSelection(nodes, ids, hoveredId, rectOptions);
@@ -1353,7 +1402,7 @@ import {
1353
1402
  import { getShapeRenderData, isShapeDescription as isShapeDescription2 } from "@pixerate/editor/canvas";
1354
1403
 
1355
1404
  // src/canvas/useShapeBrushstroke.tsx
1356
- import { createContext, useContext, useEffect as useEffect7, useMemo as useMemo6, useState as useState6 } from "react";
1405
+ import { createContext, useContext, useEffect as useEffect7, useMemo as useMemo7, useState as useState6 } from "react";
1357
1406
  import {
1358
1407
  brushstrokeScaleBucket,
1359
1408
  isBrushedShape,
@@ -1412,11 +1461,11 @@ function useCanvasBrushes(options = {}) {
1412
1461
  live = false;
1413
1462
  };
1414
1463
  }, [swatches]);
1415
- return useMemo6(() => state, [state]);
1464
+ return useMemo7(() => state, [state]);
1416
1465
  }
1417
1466
 
1418
1467
  // src/canvas/CanvasEffects.tsx
1419
- import { createContext as createContext2, useContext as useContext2, useEffect as useEffect8, useMemo as useMemo7, useRef as useRef11, useState as useState7 } from "react";
1468
+ import { createContext as createContext2, useContext as useContext2, useEffect as useEffect8, useMemo as useMemo8, useRef as useRef12, useState as useState7 } from "react";
1420
1469
  import {
1421
1470
  createCanvasEffectsController,
1422
1471
  createCanvasEffectsToolProvider,
@@ -1431,7 +1480,7 @@ function CanvasEffectsProvider({ provider, children }) {
1431
1480
  var useCanvasEffectsProviderContext = () => useContext2(ProviderContext);
1432
1481
  function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
1433
1482
  const provider = useCanvasEffectsProviderContext();
1434
- const ref = useRef11(null);
1483
+ const ref = useRef12(null);
1435
1484
  const [failed, setFailed] = useState7(false);
1436
1485
  const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
1437
1486
  const pw = Math.max(1, Math.round(width * dpr));
@@ -1444,7 +1493,7 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
1444
1493
  const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: () => setFailed(true) });
1445
1494
  return () => run.stop();
1446
1495
  }, [provider, key, pw, ph]);
1447
- const clipId = useMemo7(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
1496
+ const clipId = useMemo8(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
1448
1497
  if (!provider || failed || !(width > 0 && height > 0)) return null;
1449
1498
  const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
1450
1499
  const canvas = /* @__PURE__ */ jsx5("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
@@ -1455,9 +1504,9 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
1455
1504
  ] });
1456
1505
  }
1457
1506
  function useCanvasEffects(options) {
1458
- const opts = useRef11(options);
1507
+ const opts = useRef12(options);
1459
1508
  opts.current = options;
1460
- const controller = useMemo7(
1509
+ const controller = useMemo8(
1461
1510
  () => createCanvasEffectsController({
1462
1511
  getNodes: () => opts.current.getNodes(),
1463
1512
  setNodes: (n) => opts.current.setNodes(n),
@@ -1755,17 +1804,17 @@ import {
1755
1804
  } from "@pixerate/editor/canvas";
1756
1805
 
1757
1806
  // src/canvas/useCanvasAutoLayout.ts
1758
- import { useLayoutEffect, useMemo as useMemo8, useRef as useRef12, useState as useState8 } from "react";
1807
+ import { useLayoutEffect, useMemo as useMemo9, useRef as useRef13, useState as useState8 } from "react";
1759
1808
  import {
1760
1809
  createCanvasAutoLayoutController
1761
1810
  } from "@pixerate/editor/canvas";
1762
1811
  function useCanvasAutoLayout(options) {
1763
1812
  const [guides, setGuides] = useState8([]);
1764
- const nodesRef = useRef12(options.nodes);
1813
+ const nodesRef = useRef13(options.nodes);
1765
1814
  nodesRef.current = options.nodes;
1766
- const optionsRef = useRef12(options);
1815
+ const optionsRef = useRef13(options);
1767
1816
  optionsRef.current = options;
1768
- const controller = useMemo8(
1817
+ const controller = useMemo9(
1769
1818
  () => createCanvasAutoLayoutController({
1770
1819
  getNodes: () => nodesRef.current,
1771
1820
  setNodes: (next) => {
@@ -1794,7 +1843,7 @@ function useCanvasAutoLayout(options) {
1794
1843
  useLayoutEffect(() => {
1795
1844
  if (controller.hasPending) controller.flush();
1796
1845
  }, [options.nodes, controller]);
1797
- return useMemo8(
1846
+ return useMemo9(
1798
1847
  () => ({
1799
1848
  ...controller,
1800
1849
  /** Drop marker of the active reorder drag (flow coordinates). */
@@ -1808,7 +1857,7 @@ function useCanvasAutoLayout(options) {
1808
1857
  }
1809
1858
 
1810
1859
  // src/canvas/useCanvasTokens.ts
1811
- import { useCallback as useCallback9, useEffect as useEffect9, useRef as useRef13, useSyncExternalStore as useSyncExternalStore2 } from "react";
1860
+ import { useCallback as useCallback9, useEffect as useEffect9, useRef as useRef14, useSyncExternalStore as useSyncExternalStore2 } from "react";
1812
1861
  import {
1813
1862
  bindCanvasToken,
1814
1863
  detachTokenBindings,
@@ -1819,7 +1868,7 @@ import {
1819
1868
  function useCanvasTokens(options) {
1820
1869
  const { store, nodes, setNodes, modes, properties } = options;
1821
1870
  const state = useSyncExternalStore2(store.subscribe, store.getState, store.getState);
1822
- const latest = useRef13({ nodes, setNodes, modes, properties });
1871
+ const latest = useRef14({ nodes, setNodes, modes, properties });
1823
1872
  latest.current = { nodes, setNodes, modes, properties };
1824
1873
  const opts = () => ({ modes: latest.current.modes, properties: latest.current.properties });
1825
1874
  useEffect9(
@@ -2002,16 +2051,16 @@ import {
2002
2051
  } from "@pixerate/editor/canvas";
2003
2052
 
2004
2053
  // src/canvas/useCanvasAnimation.ts
2005
- import { useEffect as useEffect10, useMemo as useMemo9, useRef as useRef14, useSyncExternalStore as useSyncExternalStore3 } from "react";
2054
+ import { useEffect as useEffect10, useMemo as useMemo10, useRef as useRef15, useSyncExternalStore as useSyncExternalStore3 } from "react";
2006
2055
  import {
2007
2056
  createCanvasAnimationController
2008
2057
  } from "@pixerate/editor/canvas";
2009
2058
  function useCanvasAnimation(options) {
2010
- const nodesRef = useRef14(options.nodes);
2059
+ const nodesRef = useRef15(options.nodes);
2011
2060
  nodesRef.current = options.nodes;
2012
- const optionsRef = useRef14(options);
2061
+ const optionsRef = useRef15(options);
2013
2062
  optionsRef.current = options;
2014
- const controller = useMemo9(
2063
+ const controller = useMemo10(
2015
2064
  () => createCanvasAnimationController({
2016
2065
  getNodes: () => nodesRef.current,
2017
2066
  setNodes: (next) => {
@@ -2056,8 +2105,8 @@ function useCanvasAnimation(options) {
2056
2105
  useEffect10(() => {
2057
2106
  controller.refresh();
2058
2107
  }, [controller, options.nodes]);
2059
- const displayNodes = useMemo9(() => controller.display(options.nodes), [controller, options.nodes, state.time]);
2060
- return useMemo9(
2108
+ const displayNodes = useMemo10(() => controller.display(options.nodes), [controller, options.nodes, state.time]);
2109
+ return useMemo10(
2061
2110
  () => ({
2062
2111
  ...controller,
2063
2112
  state,
@@ -2078,7 +2127,7 @@ function useCanvasAnimation(options) {
2078
2127
  }
2079
2128
 
2080
2129
  // src/canvas/AnimationTimeline.tsx
2081
- import { useEffect as useEffect11, useRef as useRef15 } from "react";
2130
+ import { useEffect as useEffect11, useRef as useRef16 } from "react";
2082
2131
  import {
2083
2132
  ANIMATION_EASING_LABELS,
2084
2133
  ANIMATION_EASING_PRESETS,
@@ -2101,7 +2150,7 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
2101
2150
  for (const row of rows) for (const k of row.keyframes) if (k.selected && k.ref.property === first.property && k.ref.nodeId === first.nodeId) return easingValue(k.easing);
2102
2151
  return "";
2103
2152
  })();
2104
- const dragRef = useRef15(null);
2153
+ const dragRef = useRef16(null);
2105
2154
  useEffect11(() => {
2106
2155
  const onKey = (event) => {
2107
2156
  if (event.key === "Escape" && dragRef.current) {
@@ -2340,16 +2389,16 @@ import {
2340
2389
  } from "@pixerate/editor/canvas";
2341
2390
 
2342
2391
  // src/canvas/useCanvasComponents.ts
2343
- import { useLayoutEffect as useLayoutEffect2, useMemo as useMemo10, useRef as useRef16 } from "react";
2392
+ import { useLayoutEffect as useLayoutEffect2, useMemo as useMemo11, useRef as useRef17 } from "react";
2344
2393
  import {
2345
2394
  createCanvasComponentsController
2346
2395
  } from "@pixerate/editor/canvas";
2347
2396
  function useCanvasComponents(options) {
2348
- const nodesRef = useRef16(options.nodes);
2397
+ const nodesRef = useRef17(options.nodes);
2349
2398
  nodesRef.current = options.nodes;
2350
- const optionsRef = useRef16(options);
2399
+ const optionsRef = useRef17(options);
2351
2400
  optionsRef.current = options;
2352
- const controller = useMemo10(
2401
+ const controller = useMemo11(
2353
2402
  () => createCanvasComponentsController({
2354
2403
  getNodes: () => nodesRef.current,
2355
2404
  setNodes: (next) => {
@@ -2946,7 +2995,7 @@ function MermaidFamilyScene({
2946
2995
  }
2947
2996
 
2948
2997
  // src/canvas/useMermaidDiagram.ts
2949
- import { useEffect as useEffect12, useMemo as useMemo11, useRef as useRef17, useState as useState10, useSyncExternalStore as useSyncExternalStore4 } from "react";
2998
+ import { useEffect as useEffect12, useMemo as useMemo12, useRef as useRef18, useState as useState10, useSyncExternalStore as useSyncExternalStore4 } from "react";
2950
2999
  import {
2951
3000
  DiagramController
2952
3001
  } from "@pixerate/editor/diagram";
@@ -2964,7 +3013,7 @@ function useDiagramState(controller) {
2964
3013
  return useSyncExternalStore4(controller.subscribe, controller.getState, controller.getState);
2965
3014
  }
2966
3015
  function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
2967
- const own = useRef17(null);
3016
+ const own = useRef18(null);
2968
3017
  let controller;
2969
3018
  if (controllerOrOptions instanceof DiagramController) controller = controllerOrOptions;
2970
3019
  else {
@@ -2974,19 +3023,19 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
2974
3023
  const layoutOptions = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.layoutOptions) ?? view.layoutOptions;
2975
3024
  const sceneTheme = (controllerOrOptions instanceof DiagramController ? void 0 : controllerOrOptions.sceneTheme) ?? view.sceneTheme;
2976
3025
  const state = useDiagramState(controller);
2977
- const canvas = useMemo11(
3026
+ const canvas = useMemo12(
2978
3027
  () => mermaidToCanvas(state.document, { ...layoutOptions, editable: state.editable }),
2979
3028
  // eslint-disable-next-line react-hooks/exhaustive-deps
2980
3029
  [state.document, state.editable]
2981
3030
  );
2982
- const scene = useMemo11(
3031
+ const scene = useMemo12(
2983
3032
  () => state.document.tier === "editable" ? familySceneFromLayout(state.document.family, state.document.graph, canvas.layout, { theme: { ...CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme }, selection: state.selection }) : null,
2984
3033
  // eslint-disable-next-line react-hooks/exhaustive-deps
2985
3034
  [state.document, canvas.layout, state.selection]
2986
3035
  );
2987
- const layoutRef = useRef17(canvas.layout);
3036
+ const layoutRef = useRef18(canvas.layout);
2988
3037
  layoutRef.current = canvas.layout;
2989
- const actions = useMemo11(
3038
+ const actions = useMemo12(
2990
3039
  () => ({
2991
3040
  apply: (ops, label) => controller.apply(ops, label),
2992
3041
  load: (source, options) => controller.load(source, options),
@@ -3023,11 +3072,11 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3023
3072
  }
3024
3073
  function useMermaidStream(source, options = {}) {
3025
3074
  const { complete = false, duration = 300, ...layoutOptions } = options;
3026
- const stream = useRef17(null);
3075
+ const stream = useRef18(null);
3027
3076
  if (!stream.current) stream.current = new DiagramStream(layoutOptions);
3028
- const result = useMemo11(() => stream.current.update(source, complete), [source, complete]);
3077
+ const result = useMemo12(() => stream.current.update(source, complete), [source, complete]);
3029
3078
  const [shown, setShown] = useState10({ layout: result.layout, settled: true });
3030
- const shownRef = useRef17(shown.layout);
3079
+ const shownRef = useRef18(shown.layout);
3031
3080
  shownRef.current = shown.layout;
3032
3081
  useEffect12(() => {
3033
3082
  const target = result.layout;
@@ -3046,7 +3095,7 @@ function useMermaidStream(source, options = {}) {
3046
3095
  return () => cancelAnimationFrame(frame);
3047
3096
  }, [result.layout, duration]);
3048
3097
  const doc = result.document.tier === "editable" ? result.document : null;
3049
- const canvas = useMemo11(() => {
3098
+ const canvas = useMemo12(() => {
3050
3099
  if (!doc || !shown.layout) return { nodes: [], edges: [] };
3051
3100
  const placed = new Set(Object.keys(shown.layout.positions));
3052
3101
  const graph = {
@@ -3122,14 +3171,14 @@ function MermaidDiagramGroup({ data, selected, className = "", children }) {
3122
3171
  }
3123
3172
 
3124
3173
  // src/canvas/MermaidThumbnail.tsx
3125
- import { useMemo as useMemo12 } from "react";
3174
+ import { useMemo as useMemo13 } from "react";
3126
3175
  import { parseMermaid } from "@pixerate/editor/diagram";
3127
3176
  import { mermaidThumbnailSvg } from "@pixerate/editor/canvas";
3128
3177
  import { Fragment as Fragment3, jsx as jsx12 } from "react/jsx-runtime";
3129
3178
  function MermaidThumbnail({ source, className = "", fallback = null, ...options }) {
3130
- const doc = useMemo12(() => typeof source === "string" ? parseMermaid(source) : source, [source]);
3179
+ const doc = useMemo13(() => typeof source === "string" ? parseMermaid(source) : source, [source]);
3131
3180
  const key = JSON.stringify(options);
3132
- const drawn = useMemo12(
3181
+ const drawn = useMemo13(
3133
3182
  () => doc.tier === "editable" && doc.graph.nodes.length ? mermaidThumbnailSvg(doc, options) : null,
3134
3183
  // eslint-disable-next-line react-hooks/exhaustive-deps
3135
3184
  [doc, key]
@@ -3139,12 +3188,12 @@ function MermaidThumbnail({ source, className = "", fallback = null, ...options
3139
3188
  }
3140
3189
 
3141
3190
  // src/canvas/useDiagramDirector.ts
3142
- import { useRef as useRef18, useSyncExternalStore as useSyncExternalStore5 } from "react";
3191
+ import { useRef as useRef19, useSyncExternalStore as useSyncExternalStore5 } from "react";
3143
3192
  import { DiagramDirector, PresenceStore } from "@pixerate/editor/diagram";
3144
3193
  function useDiagramDirector(controller, options) {
3145
- const placement = useRef18(options.placement);
3194
+ const placement = useRef19(options.placement);
3146
3195
  placement.current = options.placement;
3147
- const ref = useRef18(null);
3196
+ const ref = useRef19(null);
3148
3197
  if (!ref.current) {
3149
3198
  const presence = new PresenceStore();
3150
3199
  ref.current = {
@@ -3202,6 +3251,7 @@ export {
3202
3251
  MermaidDiagramNode,
3203
3252
  MermaidFamilyScene,
3204
3253
  MermaidThumbnail,
3254
+ PresenceLayer,
3205
3255
  RESIZE_HANDLES,
3206
3256
  SHAPE_DATA_KEY,
3207
3257
  SHAPE_KINDS,
@@ -3516,6 +3566,7 @@ export {
3516
3566
  useCanvasGraph,
3517
3567
  useCanvasLayout,
3518
3568
  useCanvasMeasure,
3569
+ useCanvasPlaybackSurface,
3519
3570
  useCanvasScenes,
3520
3571
  useCanvasShortcuts,
3521
3572
  useCanvasTokens,
@@ -0,0 +1,28 @@
1
+ import { type RefObject } from 'react';
2
+ import { type CanvasEdge, type CanvasNode, type NodeRectOptions } from '@pixerate/editor/canvas';
3
+ import type { AgentPlayback, PresenceStore } from '@pixerate/editor/tools';
4
+ export interface UseCanvasPlaybackSurfaceOptions<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> {
5
+ /** The flow's nodes and edges now (e.g. React Flow's `getNodes` / `getEdges`). */
6
+ getNodes: () => readonly TNode[];
7
+ getEdges?: () => readonly TEdge[];
8
+ /** The flow viewport (`useViewport()`). Cursors are placed in flow coordinates through it. */
9
+ viewport: {
10
+ x: number;
11
+ y: number;
12
+ zoom: number;
13
+ };
14
+ /** The element the flow fills (and the `<PresenceLayer>` sits in); for bounds and screen mapping. */
15
+ container: RefObject<HTMLElement | null>;
16
+ /** Node size resolution (match the canvas' own). */
17
+ rectOptions?: NodeRectOptions;
18
+ /** Bring the canvas on screen (switch to its tab) before the agent acts. */
19
+ reveal?: () => void | Promise<void>;
20
+ /** Whether the canvas is on screen (default: the container has a size and the page is visible). */
21
+ visible?: () => boolean;
22
+ }
23
+ /**
24
+ * Attaches the node canvas as an agent playback surface under `id` (the canvas tool provider's id)
25
+ * and returns its cursors. Draw them with `<PresenceLayer presence={presence} viewport={viewport} />`
26
+ * inside `container`. Node and edge ids in tool calls are found from the flow's own geometry.
27
+ */
28
+ export declare function useCanvasPlaybackSurface<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(playback: AgentPlayback | null | undefined, id: string | null | undefined, options: UseCanvasPlaybackSurfaceOptions<TNode, TEdge>): PresenceStore;
@@ -0,0 +1,28 @@
1
+ import { type RefObject } from 'react';
2
+ import { type CanvasEdge, type CanvasNode, type NodeRectOptions } from '@pixerate/editor/canvas';
3
+ import type { AgentPlayback, PresenceStore } from '@pixerate/editor/tools';
4
+ export interface UseCanvasPlaybackSurfaceOptions<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> {
5
+ /** The flow's nodes and edges now (e.g. React Flow's `getNodes` / `getEdges`). */
6
+ getNodes: () => readonly TNode[];
7
+ getEdges?: () => readonly TEdge[];
8
+ /** The flow viewport (`useViewport()`). Cursors are placed in flow coordinates through it. */
9
+ viewport: {
10
+ x: number;
11
+ y: number;
12
+ zoom: number;
13
+ };
14
+ /** The element the flow fills (and the `<PresenceLayer>` sits in); for bounds and screen mapping. */
15
+ container: RefObject<HTMLElement | null>;
16
+ /** Node size resolution (match the canvas' own). */
17
+ rectOptions?: NodeRectOptions;
18
+ /** Bring the canvas on screen (switch to its tab) before the agent acts. */
19
+ reveal?: () => void | Promise<void>;
20
+ /** Whether the canvas is on screen (default: the container has a size and the page is visible). */
21
+ visible?: () => boolean;
22
+ }
23
+ /**
24
+ * Attaches the node canvas as an agent playback surface under `id` (the canvas tool provider's id)
25
+ * and returns its cursors. Draw them with `<PresenceLayer presence={presence} viewport={viewport} />`
26
+ * inside `container`. Node and edge ids in tool calls are found from the flow's own geometry.
27
+ */
28
+ export declare function useCanvasPlaybackSurface<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(playback: AgentPlayback | null | undefined, id: string | null | undefined, options: UseCanvasPlaybackSurfaceOptions<TNode, TEdge>): PresenceStore;