@pixerate/editor-react 0.92.0 → 0.94.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 (51) hide show
  1. package/dist/animation-editor/AnimationEditor.d.cts +14 -3
  2. package/dist/animation-editor/AnimationEditor.d.ts +14 -3
  3. package/dist/animation-editor/AnimationRecordPanel.d.cts +17 -0
  4. package/dist/animation-editor/AnimationRecordPanel.d.ts +17 -0
  5. package/dist/animation-editor/AnimationStage.d.cts +8 -2
  6. package/dist/animation-editor/AnimationStage.d.ts +8 -2
  7. package/dist/animation-editor/index.cjs +607 -405
  8. package/dist/animation-editor/index.d.cts +1 -0
  9. package/dist/animation-editor/index.d.ts +1 -0
  10. package/dist/animation-editor/index.js +359 -242
  11. package/dist/canvas/index.cjs +3 -2
  12. package/dist/canvas/index.js +4 -4
  13. package/dist/chart/ChartEditor.d.cts +12 -1
  14. package/dist/chart/ChartEditor.d.ts +12 -1
  15. package/dist/chart/index.cjs +187 -29
  16. package/dist/chart/index.js +74 -10
  17. package/dist/{chunk-6MDTFAPY.js → chunk-6YRSQW2V.js} +5 -5
  18. package/dist/chunk-7I73DW4V.js +43 -0
  19. package/dist/{chunk-GML6BYCN.js → chunk-GECXTPSH.js} +53 -3
  20. package/dist/{chunk-ECBC4HD7.js → chunk-IPVWWVSF.js} +3 -2
  21. package/dist/image-editor/index.cjs +3 -2
  22. package/dist/image-editor/index.js +2 -2
  23. package/dist/index.cjs +609 -527
  24. package/dist/index.js +10 -6
  25. package/dist/paint-editor/PaintEditor.d.cts +12 -1
  26. package/dist/paint-editor/PaintEditor.d.ts +12 -1
  27. package/dist/paint-editor/index.cjs +319 -164
  28. package/dist/paint-editor/index.js +84 -11
  29. package/dist/parameters/ParametersPanel.d.cts +11 -1
  30. package/dist/parameters/ParametersPanel.d.ts +11 -1
  31. package/dist/parameters/index.cjs +190 -41
  32. package/dist/parameters/index.js +23 -4
  33. package/dist/playback/index.d.cts +1 -0
  34. package/dist/playback/index.d.ts +1 -0
  35. package/dist/playback/useElementPlaybackSurface.d.cts +19 -0
  36. package/dist/playback/useElementPlaybackSurface.d.ts +19 -0
  37. package/dist/playback/usePlaybackSurface.d.cts +3 -1
  38. package/dist/playback/usePlaybackSurface.d.ts +3 -1
  39. package/dist/spreadsheet/SpreadsheetEditor.d.cts +10 -0
  40. package/dist/spreadsheet/SpreadsheetEditor.d.ts +10 -0
  41. package/dist/spreadsheet/index.cjs +443 -313
  42. package/dist/spreadsheet/index.js +2 -1
  43. package/dist/vector/index.cjs +3 -2
  44. package/dist/vector/index.js +5 -5
  45. package/dist/video-editor/VideoEditor.d.cts +6 -1
  46. package/dist/video-editor/VideoEditor.d.ts +6 -1
  47. package/dist/video-editor/VideoTimeline.d.cts +11 -1
  48. package/dist/video-editor/VideoTimeline.d.ts +11 -1
  49. package/dist/video-editor/index.cjs +463 -332
  50. package/dist/video-editor/index.js +53 -5
  51. package/package.json +3 -3
@@ -524,10 +524,11 @@ function useAgentPlayback() {
524
524
  }
525
525
 
526
526
  // src/playback/usePlaybackSurface.ts
527
- function usePlaybackSurface(playback, id, options = {}) {
527
+ function usePlaybackSurface(playback, id, options = {}, sharedPresence) {
528
528
  const ambient = useAgentPlayback();
529
529
  const target = playback === void 0 ? ambient : playback;
530
- const [presence] = (0, import_react3.useState)(() => new import_tools.PresenceStore());
530
+ const [ownPresence] = (0, import_react3.useState)(() => new import_tools.PresenceStore());
531
+ const presence = sharedPresence ?? ownPresence;
531
532
  const latest = (0, import_react3.useRef)(options);
532
533
  latest.current = options;
533
534
  (0, import_react3.useEffect)(() => {
@@ -1,13 +1,13 @@
1
- import {
2
- PresenceLayer,
3
- usePlaybackSurface
4
- } from "../chunk-ECBC4HD7.js";
5
1
  import {
6
2
  EffectParameters,
7
3
  EffectsBrowser,
8
4
  useEffectDescription
9
5
  } from "../chunk-5R67YSSD.js";
10
6
  import "../chunk-OTGJEYHV.js";
7
+ import {
8
+ PresenceLayer,
9
+ usePlaybackSurface
10
+ } from "../chunk-IPVWWVSF.js";
11
11
 
12
12
  // src/canvas/AgentPresenceLayer.tsx
13
13
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { type ChartController, type DownloadChartPngOptions } from '@pixerate/editor/chart';
3
+ import type { AgentPlayback } from '@pixerate/editor/tools';
3
4
  import { type ChartCanvasProps } from './ChartCanvas.cjs';
4
5
  export interface ChartEditorProps {
5
6
  controller: ChartController;
@@ -15,6 +16,16 @@ export interface ChartEditorProps {
15
16
  height?: number;
16
17
  canvasProps?: Omit<ChartCanvasProps, 'controller' | 'height'>;
17
18
  className?: string;
19
+ /**
20
+ * Agent playback: act out the chart tools' calls here with the agent's cursor, on the inspector,
21
+ * the data grid and the toolbar (default: the nearest `AgentPlaybackProvider`; `null` turns it
22
+ * off). With `canvasProps.presence` (a `ChartDirector`'s), the director's drags share the cursor.
23
+ */
24
+ playback?: AgentPlayback | null;
25
+ /** The playback surface id (default `chart`, where the chart tool provider plays). */
26
+ playbackId?: string;
27
+ /** Bring the editor on screen (switch to its tab) before the agent acts. */
28
+ onPlaybackReveal?: () => void | Promise<void>;
18
29
  }
19
30
  /** Toolbar, chart, settings sidebar and data grid for a `ChartController`. */
20
- export declare function ChartEditor({ controller, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className }: ChartEditorProps): React.JSX.Element;
31
+ export declare function ChartEditor({ controller, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className, playback, playbackId, onPlaybackReveal }: ChartEditorProps): React.JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { type ChartController, type DownloadChartPngOptions } from '@pixerate/editor/chart';
3
+ import type { AgentPlayback } from '@pixerate/editor/tools';
3
4
  import { type ChartCanvasProps } from './ChartCanvas.js';
4
5
  export interface ChartEditorProps {
5
6
  controller: ChartController;
@@ -15,6 +16,16 @@ export interface ChartEditorProps {
15
16
  height?: number;
16
17
  canvasProps?: Omit<ChartCanvasProps, 'controller' | 'height'>;
17
18
  className?: string;
19
+ /**
20
+ * Agent playback: act out the chart tools' calls here with the agent's cursor, on the inspector,
21
+ * the data grid and the toolbar (default: the nearest `AgentPlaybackProvider`; `null` turns it
22
+ * off). With `canvasProps.presence` (a `ChartDirector`'s), the director's drags share the cursor.
23
+ */
24
+ playback?: AgentPlayback | null;
25
+ /** The playback surface id (default `chart`, where the chart tool provider plays). */
26
+ playbackId?: string;
27
+ /** Bring the editor on screen (switch to its tab) before the agent acts. */
28
+ onPlaybackReveal?: () => void | Promise<void>;
18
29
  }
19
30
  /** Toolbar, chart, settings sidebar and data grid for a `ChartController`. */
20
- export declare function ChartEditor({ controller, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className }: ChartEditorProps): React.JSX.Element;
31
+ export declare function ChartEditor({ controller, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className, playback, playbackId, onPlaybackReveal }: ChartEditorProps): React.JSX.Element;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/chart/index.ts
@@ -774,47 +784,195 @@ function ChartInspector({ controller, sections, className }) {
774
784
  }
775
785
 
776
786
  // src/chart/ChartEditor.tsx
777
- var import_react5 = require("react");
787
+ var import_react8 = require("react");
778
788
  var import_chart5 = require("@pixerate/editor/chart");
789
+
790
+ // src/playback/AgentPlaybackContext.tsx
791
+ var import_react5 = require("react");
779
792
  var import_jsx_runtime4 = require("react/jsx-runtime");
780
- function ChartEditor({ controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className }) {
793
+ var AgentPlaybackContext = (0, import_react5.createContext)(null);
794
+ function useAgentPlayback() {
795
+ return (0, import_react5.useContext)(AgentPlaybackContext);
796
+ }
797
+
798
+ // src/playback/usePlaybackSurface.ts
799
+ var import_react6 = require("react");
800
+ var import_tools = require("@pixerate/editor/tools");
801
+ function usePlaybackSurface(playback, id, options = {}, sharedPresence) {
802
+ const ambient = useAgentPlayback();
803
+ const target = playback === void 0 ? ambient : playback;
804
+ const [ownPresence] = (0, import_react6.useState)(() => new import_tools.PresenceStore());
805
+ const presence = sharedPresence ?? ownPresence;
806
+ const latest = (0, import_react6.useRef)(options);
807
+ latest.current = options;
808
+ (0, import_react6.useEffect)(() => {
809
+ if (!target || !id) return;
810
+ const o = () => latest.current;
811
+ const surface = {
812
+ presence,
813
+ locate: (ref) => o().locate?.(ref) ?? null,
814
+ bounds: () => o().bounds?.() ?? null,
815
+ visible: () => o().visible?.() ?? true,
816
+ toViewport: (p) => o().toViewport?.(p) ?? p,
817
+ fromViewport: (p) => o().fromViewport?.(p) ?? p,
818
+ beginGesture: (key) => o().beginGesture?.(key),
819
+ endGesture: () => o().endGesture?.(),
820
+ reveal: () => o().reveal?.(),
821
+ open: (ref) => o().open?.(ref),
822
+ get defaultKind() {
823
+ return o().defaultKind;
824
+ }
825
+ };
826
+ const detach = target.attach(id, surface);
827
+ return () => {
828
+ detach();
829
+ for (const a of presence.getState().actors) presence.remove(a.id);
830
+ };
831
+ }, [target, id, presence]);
832
+ return presence;
833
+ }
834
+
835
+ // src/playback/PresenceLayer.tsx
836
+ var import_react7 = __toESM(require("react"), 1);
837
+ var import_jsx_runtime5 = require("react/jsx-runtime");
838
+ function PresenceLayer({ presence, viewport, className = "" }) {
839
+ const { actors } = (0, import_react7.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
840
+ if (!actors.length) return null;
841
+ const map = typeof viewport === "function" ? viewport : viewport ? (p) => ({ x: p.x * viewport.zoom + viewport.x, y: p.y * viewport.zoom + viewport.y }) : (p) => p;
842
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
843
+ "div",
844
+ {
845
+ className: `pixerate-presence ${className}`.trim(),
846
+ "aria-hidden": "true",
847
+ "data-testid": "presence-layer",
848
+ style: { position: "absolute", inset: 0, pointerEvents: "none", overflow: "hidden", zIndex: 50 },
849
+ children: actors.map((a) => {
850
+ const at = map(a);
851
+ const ring = a.focus && (() => {
852
+ const tl = map(a.focus);
853
+ const br = map({ x: a.focus.x + a.focus.width, y: a.focus.y + a.focus.height });
854
+ return { left: tl.x - 4, top: tl.y - 4, width: br.x - tl.x + 8, height: br.y - tl.y + 8 };
855
+ })();
856
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react7.default.Fragment, { children: [
857
+ ring && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
858
+ "div",
859
+ {
860
+ "data-actor-focus": a.id,
861
+ style: { position: "absolute", ...ring, borderRadius: 8, border: `2px solid ${a.color}`, background: `${a.color}14`, transition: "all 160ms ease-out" }
862
+ }
863
+ ),
864
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { "data-actor": a.id, style: { position: "absolute", left: 0, top: 0, transform: `translate(${at.x}px, ${at.y}px)` }, children: [
865
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { width: "18", height: "20", viewBox: "0 0 12 18", style: { display: "block", transform: a.pressed ? "scale(0.85)" : void 0, transformOrigin: "0 0", filter: "drop-shadow(0 1px 2px rgba(0,0,0,.35))" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 } }) }),
866
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { position: "absolute", left: 14, top: 16, display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 4 }, children: [
867
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { whiteSpace: "nowrap", borderRadius: 999, padding: "1px 7px", fontSize: 11, fontWeight: 600, color: "#ffffff", background: a.color }, children: a.name }),
868
+ a.message && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-actor-message": a.id, style: { width: "max-content", maxWidth: 240, borderRadius: 8, borderTopLeftRadius: 0, padding: "4px 8px", fontSize: 12, color: "#1e293b", background: "#ffffff", boxShadow: "0 4px 12px rgba(15,23,42,.18)" }, children: a.message })
869
+ ] })
870
+ ] })
871
+ ] }, a.id);
872
+ })
873
+ }
874
+ );
875
+ }
876
+
877
+ // src/chart/ChartEditor.tsx
878
+ var import_jsx_runtime6 = require("react/jsx-runtime");
879
+ function ChartEditor({ controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className, playback, playbackId = "chart", onPlaybackReveal }) {
781
880
  const state = useChartState(controller);
782
- const [pngError, setPngError] = (0, import_react5.useState)(null);
881
+ const rootRef = (0, import_react8.useRef)(null);
882
+ const ownScene = (0, import_react8.useRef)(null);
883
+ const sceneRef = canvasProps?.sceneRef ?? ownScene;
884
+ const [ownPresence] = (0, import_react8.useState)(() => new import_chart5.ChartPresence());
885
+ const ambientPlayback = useAgentPlayback();
886
+ const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
887
+ const svgBox = () => {
888
+ const svg = rootRef.current?.querySelector("[data-chart-canvas] svg");
889
+ const r = svg?.getBoundingClientRect();
890
+ const vb = svg?.viewBox?.baseVal;
891
+ if (!svg || !r || !vb || !vb.width || !vb.height) return null;
892
+ return { left: r.left, top: r.top, sx: r.width / vb.width, sy: r.height / vb.height, vx: vb.x, vy: vb.y };
893
+ };
894
+ const sceneToClient = (p) => {
895
+ const b = svgBox();
896
+ return b ? { x: b.left + (p.x - b.vx) * b.sx, y: b.top + (p.y - b.vy) * b.sy } : null;
897
+ };
898
+ const clientToScene = (p) => {
899
+ const b = svgBox();
900
+ return b && b.sx && b.sy ? { x: (p.x - b.left) / b.sx + b.vx, y: (p.y - b.top) / b.sy + b.vy } : null;
901
+ };
902
+ const elementRect = (selector) => {
903
+ const el = rootRef.current?.querySelector(selector);
904
+ el?.scrollIntoView?.({ block: "nearest" });
905
+ const r = el?.getBoundingClientRect();
906
+ if (!r || r.width <= 0) return null;
907
+ const a = clientToScene({ x: r.left, y: r.top });
908
+ const b = clientToScene({ x: r.right, y: r.bottom });
909
+ return a && b ? { x: a.x, y: a.y, width: b.x - a.x, height: b.y - a.y } : null;
910
+ };
911
+ const SELECTORS = {
912
+ control: (id) => `[data-option="${CSS.escape(id)}"]`,
913
+ "chart-type": (id) => `[data-chart-type="${CSS.escape(id)}"]`,
914
+ action: (id) => `[data-action="${CSS.escape(id)}"]`,
915
+ grid: () => "[data-chart-grid]"
916
+ };
917
+ const presence = usePlaybackSurface(playing, playbackId, {
918
+ defaultKind: "point",
919
+ locate: (ref) => {
920
+ if (ref.kind === "point") return sceneRef.current ? (0, import_chart5.locateChartPoint)(controller.getSpec(), sceneRef.current, ref) : null;
921
+ const selector = SELECTORS[ref.kind]?.(ref.id);
922
+ return selector ? elementRect(selector) : null;
923
+ },
924
+ bounds: () => sceneRef.current ? { x: 0, y: 0, width: sceneRef.current.width, height: sceneRef.current.height } : null,
925
+ visible: () => {
926
+ const r = rootRef.current?.getBoundingClientRect();
927
+ return !!r && r.width > 0 && r.height > 0 && !(typeof document !== "undefined" && document.visibilityState === "hidden");
928
+ },
929
+ toViewport: (p) => sceneToClient(p) ?? p,
930
+ fromViewport: (p) => clientToScene(p) ?? p,
931
+ reveal: () => onPlaybackReveal?.()
932
+ // A director's presence store when there is one, so its cursor and this one are the same.
933
+ }, canvasProps?.presence ?? ownPresence);
934
+ const sceneToRoot = (p) => {
935
+ const c = sceneToClient(p);
936
+ const box = rootRef.current?.getBoundingClientRect();
937
+ return c && box ? { x: c.x - box.left, y: c.y - box.top } : p;
938
+ };
939
+ const [pngError, setPngError] = (0, import_react8.useState)(null);
783
940
  const downloadPng = () => {
784
941
  setPngError(null);
785
942
  (0, import_chart5.downloadChartPng)(controller.toJSON(), pngOptions).catch((error) => setPngError(error instanceof Error ? error.message : String(error)));
786
943
  };
787
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-chart-editor": "", children: [
788
- showToolbar && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center gap-1", "data-chart-toolbar": "", children: [
789
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: chartButtonClass, disabled: !state.canUndo, title: state.undoLabel ? `Undo ${state.undoLabel}` : "Undo", "data-action": "undo", onClick: () => controller.undo(), children: "Undo" }),
790
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: chartButtonClass, disabled: !state.canRedo, title: state.redoLabel ? `Redo ${state.redoLabel}` : "Redo", "data-action": "redo", onClick: () => controller.redo(), children: "Redo" }),
791
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: chartButtonClass, title: "Download the chart as a PNG image", "data-action": "download-png", onClick: downloadPng, children: "Download PNG" }),
792
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ml-2 truncate text-xs text-muted-foreground", "data-chart-selection": "", "aria-live": "polite", children: (0, import_chart5.describeChartSelection)(controller, state.selection) })
944
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { ref: rootRef, className: `relative flex flex-col gap-2 ${className ?? ""}`, "data-chart-editor": "", children: [
945
+ playing && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PresenceLayer, { presence, viewport: sceneToRoot }),
946
+ showToolbar && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-1", "data-chart-toolbar": "", children: [
947
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: chartButtonClass, disabled: !state.canUndo, title: state.undoLabel ? `Undo ${state.undoLabel}` : "Undo", "data-action": "undo", onClick: () => controller.undo(), children: "Undo" }),
948
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: chartButtonClass, disabled: !state.canRedo, title: state.redoLabel ? `Redo ${state.redoLabel}` : "Redo", "data-action": "redo", onClick: () => controller.redo(), children: "Redo" }),
949
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: chartButtonClass, title: "Download the chart as a PNG image", "data-action": "download-png", onClick: downloadPng, children: "Download PNG" }),
950
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "ml-2 truncate text-xs text-muted-foreground", "data-chart-selection": "", "aria-live": "polite", children: (0, import_chart5.describeChartSelection)(controller, state.selection) })
793
951
  ] }),
794
- pngError && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", "data-chart-png-error": "", children: pngError }),
795
- state.issues.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", "data-chart-issues": "", children: state.issues.map((i) => i.message).join(" ") }),
796
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex min-h-0 flex-col gap-2 md:flex-row", children: [
797
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "min-w-0 flex-1 rounded-md border border-border bg-background p-1", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartCanvas, { controller, height, ...canvasProps }) }),
952
+ pngError && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "alert", className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", "data-chart-png-error": "", children: pngError }),
953
+ state.issues.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "alert", className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", "data-chart-issues": "", children: state.issues.map((i) => i.message).join(" ") }),
954
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex min-h-0 flex-col gap-2 md:flex-row", children: [
955
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "min-w-0 flex-1 rounded-md border border-border bg-background p-1", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartCanvas, { controller, height, ...canvasProps, sceneRef, presence: playing ? void 0 : canvasProps?.presence }) }),
798
956
  showInspector && // Side by side, the canvas sets the row's height and the inspector scrolls within it.
799
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartInspector, { controller, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
957
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartInspector, { controller, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
800
958
  ] }),
801
- showDataGrid && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartDataGrid, { controller })
959
+ showDataGrid && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartDataGrid, { controller })
802
960
  ] });
803
961
  }
804
962
 
805
963
  // src/chart/ChartStreamingView.tsx
806
- var import_react6 = require("react");
964
+ var import_react9 = require("react");
807
965
  var import_chart6 = require("@pixerate/editor/chart");
808
- var import_jsx_runtime5 = require("react/jsx-runtime");
966
+ var import_jsx_runtime7 = require("react/jsx-runtime");
809
967
  function ChartStreamingView({ source, complete = false, format = "auto", width = 640, height = 360, theme, adoptInterval = 300, tween = 450, placeholder, onIssues, className }) {
810
- const stream = (0, import_react6.useMemo)(() => new import_chart6.ChartStream(format), [format]);
811
- const fullTheme = (0, import_react6.useMemo)(() => ({ ...import_chart6.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
812
- const [scene, setScene] = (0, import_react6.useState)(null);
813
- const shown = (0, import_react6.useRef)(null);
814
- const lastAdopt = (0, import_react6.useRef)(0);
815
- const frame = (0, import_react6.useRef)(null);
816
- const pending = (0, import_react6.useRef)(null);
817
- (0, import_react6.useEffect)(() => {
968
+ const stream = (0, import_react9.useMemo)(() => new import_chart6.ChartStream(format), [format]);
969
+ const fullTheme = (0, import_react9.useMemo)(() => ({ ...import_chart6.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
970
+ const [scene, setScene] = (0, import_react9.useState)(null);
971
+ const shown = (0, import_react9.useRef)(null);
972
+ const lastAdopt = (0, import_react9.useRef)(0);
973
+ const frame = (0, import_react9.useRef)(null);
974
+ const pending = (0, import_react9.useRef)(null);
975
+ (0, import_react9.useEffect)(() => {
818
976
  const adopt = () => {
819
977
  const read = stream.update(source, complete);
820
978
  if (complete && onIssues) onIssues(read.issues);
@@ -846,15 +1004,15 @@ function ChartStreamingView({ source, complete = false, format = "auto", width =
846
1004
  if (pending.current) clearTimeout(pending.current);
847
1005
  };
848
1006
  }, [source, complete, stream, width, height, fullTheme, adoptInterval, tween, onIssues]);
849
- (0, import_react6.useEffect)(() => () => {
1007
+ (0, import_react9.useEffect)(() => () => {
850
1008
  if (frame.current !== null) cancelAnimationFrame(frame.current);
851
1009
  }, []);
852
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className, "data-chart-streaming": complete ? "complete" : "streaming", "aria-busy": !complete, children: scene ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartSceneSvg, { scene, label: complete ? void 0 : "Chart loading" }) : placeholder ?? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { height }, className: "flex items-center justify-center text-xs text-muted-foreground", children: "Drawing chart\u2026" }) });
1010
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className, "data-chart-streaming": complete ? "complete" : "streaming", "aria-busy": !complete, children: scene ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ChartSceneSvg, { scene, label: complete ? void 0 : "Chart loading" }) : placeholder ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { height }, className: "flex items-center justify-center text-xs text-muted-foreground", children: "Drawing chart\u2026" }) });
853
1011
  }
854
1012
  function ChartSparkline({ values, width = 80, height = 20, label, className, ...options }) {
855
- const scene = (0, import_react6.useMemo)(() => (0, import_chart6.layoutSparkline)(values, { ...options, width, height }), [values, width, height, options.kind, options.color, options.negativeColor, options.markers, options.highLow, options.min, options.max]);
1013
+ const scene = (0, import_react9.useMemo)(() => (0, import_chart6.layoutSparkline)(values, { ...options, width, height }), [values, width, height, options.kind, options.color, options.negativeColor, options.markers, options.highLow, options.min, options.max]);
856
1014
  const present = values.filter((v) => v !== null);
857
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartSceneSvg, { scene, label: label ?? (present.length ? `Trend from ${present[0]} to ${present[present.length - 1]}` : "No data"), className: `inline-block align-middle ${className ?? ""}` });
1015
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ChartSceneSvg, { scene, label: label ?? (present.length ? `Trend from ${present[0]} to ${present[present.length - 1]}` : "No data"), className: `inline-block align-middle ${className ?? ""}` });
858
1016
  }
859
1017
  // Annotate the CommonJS export names for ESM import in node:
860
1018
  0 && (module.exports = {
@@ -21,19 +21,83 @@ import {
21
21
  useChartToolProvider,
22
22
  useOfficeChartToolProvider
23
23
  } from "../chunk-AILJ4JOW.js";
24
+ import {
25
+ PresenceLayer,
26
+ useAgentPlayback,
27
+ usePlaybackSurface
28
+ } from "../chunk-IPVWWVSF.js";
24
29
 
25
30
  // src/chart/ChartEditor.tsx
26
- import { useState } from "react";
27
- import { describeChartSelection, downloadChartPng } from "@pixerate/editor/chart";
31
+ import { useRef, useState } from "react";
32
+ import { describeChartSelection, downloadChartPng, locateChartPoint, ChartPresence } from "@pixerate/editor/chart";
28
33
  import { jsx, jsxs } from "react/jsx-runtime";
29
- function ChartEditor({ controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className }) {
34
+ function ChartEditor({ controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className, playback, playbackId = "chart", onPlaybackReveal }) {
30
35
  const state = useChartState(controller);
36
+ const rootRef = useRef(null);
37
+ const ownScene = useRef(null);
38
+ const sceneRef = canvasProps?.sceneRef ?? ownScene;
39
+ const [ownPresence] = useState(() => new ChartPresence());
40
+ const ambientPlayback = useAgentPlayback();
41
+ const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
42
+ const svgBox = () => {
43
+ const svg = rootRef.current?.querySelector("[data-chart-canvas] svg");
44
+ const r = svg?.getBoundingClientRect();
45
+ const vb = svg?.viewBox?.baseVal;
46
+ if (!svg || !r || !vb || !vb.width || !vb.height) return null;
47
+ return { left: r.left, top: r.top, sx: r.width / vb.width, sy: r.height / vb.height, vx: vb.x, vy: vb.y };
48
+ };
49
+ const sceneToClient = (p) => {
50
+ const b = svgBox();
51
+ return b ? { x: b.left + (p.x - b.vx) * b.sx, y: b.top + (p.y - b.vy) * b.sy } : null;
52
+ };
53
+ const clientToScene = (p) => {
54
+ const b = svgBox();
55
+ return b && b.sx && b.sy ? { x: (p.x - b.left) / b.sx + b.vx, y: (p.y - b.top) / b.sy + b.vy } : null;
56
+ };
57
+ const elementRect = (selector) => {
58
+ const el = rootRef.current?.querySelector(selector);
59
+ el?.scrollIntoView?.({ block: "nearest" });
60
+ const r = el?.getBoundingClientRect();
61
+ if (!r || r.width <= 0) return null;
62
+ const a = clientToScene({ x: r.left, y: r.top });
63
+ const b = clientToScene({ x: r.right, y: r.bottom });
64
+ return a && b ? { x: a.x, y: a.y, width: b.x - a.x, height: b.y - a.y } : null;
65
+ };
66
+ const SELECTORS = {
67
+ control: (id) => `[data-option="${CSS.escape(id)}"]`,
68
+ "chart-type": (id) => `[data-chart-type="${CSS.escape(id)}"]`,
69
+ action: (id) => `[data-action="${CSS.escape(id)}"]`,
70
+ grid: () => "[data-chart-grid]"
71
+ };
72
+ const presence = usePlaybackSurface(playing, playbackId, {
73
+ defaultKind: "point",
74
+ locate: (ref) => {
75
+ if (ref.kind === "point") return sceneRef.current ? locateChartPoint(controller.getSpec(), sceneRef.current, ref) : null;
76
+ const selector = SELECTORS[ref.kind]?.(ref.id);
77
+ return selector ? elementRect(selector) : null;
78
+ },
79
+ bounds: () => sceneRef.current ? { x: 0, y: 0, width: sceneRef.current.width, height: sceneRef.current.height } : null,
80
+ visible: () => {
81
+ const r = rootRef.current?.getBoundingClientRect();
82
+ return !!r && r.width > 0 && r.height > 0 && !(typeof document !== "undefined" && document.visibilityState === "hidden");
83
+ },
84
+ toViewport: (p) => sceneToClient(p) ?? p,
85
+ fromViewport: (p) => clientToScene(p) ?? p,
86
+ reveal: () => onPlaybackReveal?.()
87
+ // A director's presence store when there is one, so its cursor and this one are the same.
88
+ }, canvasProps?.presence ?? ownPresence);
89
+ const sceneToRoot = (p) => {
90
+ const c = sceneToClient(p);
91
+ const box = rootRef.current?.getBoundingClientRect();
92
+ return c && box ? { x: c.x - box.left, y: c.y - box.top } : p;
93
+ };
31
94
  const [pngError, setPngError] = useState(null);
32
95
  const downloadPng = () => {
33
96
  setPngError(null);
34
97
  downloadChartPng(controller.toJSON(), pngOptions).catch((error) => setPngError(error instanceof Error ? error.message : String(error)));
35
98
  };
36
- return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-chart-editor": "", children: [
99
+ return /* @__PURE__ */ jsxs("div", { ref: rootRef, className: `relative flex flex-col gap-2 ${className ?? ""}`, "data-chart-editor": "", children: [
100
+ playing && /* @__PURE__ */ jsx(PresenceLayer, { presence, viewport: sceneToRoot }),
37
101
  showToolbar && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", "data-chart-toolbar": "", children: [
38
102
  /* @__PURE__ */ jsx("button", { type: "button", className: chartButtonClass, disabled: !state.canUndo, title: state.undoLabel ? `Undo ${state.undoLabel}` : "Undo", "data-action": "undo", onClick: () => controller.undo(), children: "Undo" }),
39
103
  /* @__PURE__ */ jsx("button", { type: "button", className: chartButtonClass, disabled: !state.canRedo, title: state.redoLabel ? `Redo ${state.redoLabel}` : "Redo", "data-action": "redo", onClick: () => controller.redo(), children: "Redo" }),
@@ -43,7 +107,7 @@ function ChartEditor({ controller, showInspector = true, showDataGrid = true, sh
43
107
  pngError && /* @__PURE__ */ jsx("p", { role: "alert", className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", "data-chart-png-error": "", children: pngError }),
44
108
  state.issues.length > 0 && /* @__PURE__ */ jsx("p", { role: "alert", className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", "data-chart-issues": "", children: state.issues.map((i) => i.message).join(" ") }),
45
109
  /* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-col gap-2 md:flex-row", children: [
46
- /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1 rounded-md border border-border bg-background p-1", children: /* @__PURE__ */ jsx(ChartCanvas, { controller, height, ...canvasProps }) }),
110
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1 rounded-md border border-border bg-background p-1", children: /* @__PURE__ */ jsx(ChartCanvas, { controller, height, ...canvasProps, sceneRef, presence: playing ? void 0 : canvasProps?.presence }) }),
47
111
  showInspector && // Side by side, the canvas sets the row's height and the inspector scrolls within it.
48
112
  /* @__PURE__ */ jsx("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ jsx(ChartInspector, { controller, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
49
113
  ] }),
@@ -52,7 +116,7 @@ function ChartEditor({ controller, showInspector = true, showDataGrid = true, sh
52
116
  }
53
117
 
54
118
  // src/chart/ChartStreamingView.tsx
55
- import { useEffect, useMemo, useRef, useState as useState2 } from "react";
119
+ import { useEffect, useMemo, useRef as useRef2, useState as useState2 } from "react";
56
120
  import {
57
121
  CSS_VARIABLE_CHART_THEME,
58
122
  ChartStream,
@@ -66,10 +130,10 @@ function ChartStreamingView({ source, complete = false, format = "auto", width =
66
130
  const stream = useMemo(() => new ChartStream(format), [format]);
67
131
  const fullTheme = useMemo(() => ({ ...CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
68
132
  const [scene, setScene] = useState2(null);
69
- const shown = useRef(null);
70
- const lastAdopt = useRef(0);
71
- const frame = useRef(null);
72
- const pending = useRef(null);
133
+ const shown = useRef2(null);
134
+ const lastAdopt = useRef2(0);
135
+ const frame = useRef2(null);
136
+ const pending = useRef2(null);
73
137
  useEffect(() => {
74
138
  const adopt = () => {
75
139
  const read = stream.update(source, complete);
@@ -1,8 +1,3 @@
1
- import {
2
- PresenceLayer,
3
- useAgentPlayback,
4
- usePlaybackSurface
5
- } from "./chunk-ECBC4HD7.js";
6
1
  import {
7
2
  PaintGradientEditorView
8
3
  } from "./chunk-AJCWF6SN.js";
@@ -12,6 +7,11 @@ import {
12
7
  useEffectDescription,
13
8
  useEffects
14
9
  } from "./chunk-5R67YSSD.js";
10
+ import {
11
+ PresenceLayer,
12
+ useAgentPlayback,
13
+ usePlaybackSurface
14
+ } from "./chunk-IPVWWVSF.js";
15
15
 
16
16
  // src/image-editor/useImageEditor.ts
17
17
  import { useRef, useState, useEffect, useCallback, useMemo } from "react";
@@ -0,0 +1,43 @@
1
+ import {
2
+ usePlaybackSurface
3
+ } from "./chunk-IPVWWVSF.js";
4
+
5
+ // src/playback/useElementPlaybackSurface.ts
6
+ import { useRef } from "react";
7
+ function useElementPlaybackSurface(playback, id, element, options) {
8
+ const latest = useRef(options);
9
+ latest.current = options;
10
+ const box = () => element.current?.getBoundingClientRect() ?? null;
11
+ return usePlaybackSurface(playback, id, {
12
+ get defaultKind() {
13
+ return latest.current.defaultKind;
14
+ },
15
+ locate: (ref) => {
16
+ const selector = latest.current.selectors[ref.kind]?.(ref.id);
17
+ const b = box();
18
+ const r = selector ? element.current?.querySelector(selector)?.getBoundingClientRect() : null;
19
+ return b && r && r.width > 0 ? { x: r.left - b.left, y: r.top - b.top, width: r.width, height: r.height } : null;
20
+ },
21
+ bounds: () => {
22
+ const r = box();
23
+ return r && r.width > 0 ? { x: 0, y: 0, width: r.width, height: r.height } : null;
24
+ },
25
+ visible: () => {
26
+ const r = box();
27
+ return !!r && r.width > 0 && r.height > 0 && !(typeof document !== "undefined" && document.visibilityState === "hidden");
28
+ },
29
+ toViewport: (p) => {
30
+ const r = box();
31
+ return { x: (r?.left ?? 0) + p.x, y: (r?.top ?? 0) + p.y };
32
+ },
33
+ fromViewport: (p) => {
34
+ const r = box();
35
+ return { x: p.x - (r?.left ?? 0), y: p.y - (r?.top ?? 0) };
36
+ },
37
+ reveal: () => latest.current.reveal?.()
38
+ });
39
+ }
40
+
41
+ export {
42
+ useElementPlaybackSurface
43
+ };
@@ -1,3 +1,9 @@
1
+ import {
2
+ PresenceLayer,
3
+ useAgentPlayback,
4
+ usePlaybackSurface
5
+ } from "./chunk-IPVWWVSF.js";
6
+
1
7
  // src/spreadsheet/useSpreadsheetEditor.ts
2
8
  import { useState, useRef, useCallback, useMemo } from "react";
3
9
  import {
@@ -248,7 +254,8 @@ import {
248
254
  numberFormatColorToCss,
249
255
  getConditionalFormatCss as getConditionalFormatCss2,
250
256
  getConditionalFormatIcon,
251
- getDataBarCss
257
+ getDataBarCss,
258
+ parseSpreadsheetPlaybackRef
252
259
  } from "@pixerate/editor/spreadsheet";
253
260
 
254
261
  // src/spreadsheet/SpreadsheetContextMenu.tsx
@@ -1209,11 +1216,53 @@ var SpreadsheetEditor = ({
1209
1216
  onColumnHeaderClick,
1210
1217
  onColumnResize,
1211
1218
  showSheetTabs = false,
1212
- virtualize = "auto"
1219
+ virtualize = "auto",
1220
+ playback,
1221
+ playbackId = "spreadsheet",
1222
+ onPlaybackReveal
1213
1223
  }) => {
1214
1224
  const defaultState = useSpreadsheetEditor();
1215
1225
  const state = externalState || defaultState;
1216
1226
  const gridRef = useRef8(null);
1227
+ const ambientPlayback = useAgentPlayback();
1228
+ const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
1229
+ const agentPresence = usePlaybackSurface(playing, playbackId, {
1230
+ defaultKind: "cell",
1231
+ locate: (ref) => {
1232
+ const grid2 = gridRef.current;
1233
+ const range = parseSpreadsheetPlaybackRef(ref);
1234
+ if (!grid2 || !range) return null;
1235
+ const box = grid2.getBoundingClientRect();
1236
+ const inside = (v, a, b) => (a === null || v >= a) && (b === null || v <= b);
1237
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
1238
+ for (const td of grid2.querySelectorAll("td[data-row][data-col]")) {
1239
+ if (!inside(Number(td.dataset.row), range.startRow, range.endRow) || !inside(Number(td.dataset.col), range.startCol, range.endCol)) continue;
1240
+ const r = td.getBoundingClientRect();
1241
+ minX = Math.min(minX, r.left - box.left);
1242
+ minY = Math.min(minY, r.top - box.top);
1243
+ maxX = Math.max(maxX, r.right - box.left);
1244
+ maxY = Math.max(maxY, r.bottom - box.top);
1245
+ }
1246
+ return minX < maxX ? { x: minX, y: minY, width: maxX - minX, height: maxY - minY } : null;
1247
+ },
1248
+ bounds: () => {
1249
+ const r = gridRef.current?.getBoundingClientRect();
1250
+ return r && r.width > 0 ? { x: 0, y: 0, width: r.width, height: r.height } : null;
1251
+ },
1252
+ visible: () => {
1253
+ const r = gridRef.current?.getBoundingClientRect();
1254
+ return !!r && r.width > 0 && r.height > 0 && !(typeof document !== "undefined" && document.visibilityState === "hidden");
1255
+ },
1256
+ toViewport: (p) => {
1257
+ const r = gridRef.current?.getBoundingClientRect();
1258
+ return { x: (r?.left ?? 0) + p.x, y: (r?.top ?? 0) + p.y };
1259
+ },
1260
+ fromViewport: (p) => {
1261
+ const r = gridRef.current?.getBoundingClientRect();
1262
+ return { x: p.x - (r?.left ?? 0), y: p.y - (r?.top ?? 0) };
1263
+ },
1264
+ reveal: () => onPlaybackReveal?.()
1265
+ });
1217
1266
  const scrollRef = useRef8(null);
1218
1267
  const formulaBarRef = useRef8(null);
1219
1268
  const cellInputRef = useRef8(null);
@@ -1607,7 +1656,7 @@ var SpreadsheetEditor = ({
1607
1656
  "div",
1608
1657
  {
1609
1658
  ref: gridRef,
1610
- className: "flex flex-col h-full w-full overflow-hidden border border-border bg-background select-none outline-none text-foreground font-sans text-xs",
1659
+ className: "relative flex flex-col h-full w-full overflow-hidden border border-border bg-background select-none outline-none text-foreground font-sans text-xs",
1611
1660
  tabIndex: 0,
1612
1661
  onKeyDown: handleKeyDown,
1613
1662
  role: "grid",
@@ -1944,6 +1993,7 @@ var SpreadsheetEditor = ({
1944
1993
  }
1945
1994
  ),
1946
1995
  state.validationPrompt && /* @__PURE__ */ jsx7(SpreadsheetValidationDialog, { prompt: state.validationPrompt, onResolve: resolveValidation }),
1996
+ playing && /* @__PURE__ */ jsx7(PresenceLayer, { presence: agentPresence }),
1947
1997
  /* @__PURE__ */ jsx7("style", { children: `
1948
1998
  .col-resize-handle:hover .col-resize-handle-line {
1949
1999
  background-color: var(--primary, #6366f1);