@pixerate/editor-react 0.91.1 → 0.93.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation-editor/AnimationEditor.d.cts +11 -1
- package/dist/animation-editor/AnimationEditor.d.ts +11 -1
- package/dist/animation-editor/index.cjs +494 -366
- package/dist/animation-editor/index.js +48 -4
- package/dist/canvas/AgentPresenceLayer.d.cts +3 -0
- package/dist/canvas/AgentPresenceLayer.d.ts +3 -0
- package/dist/canvas/index.cjs +1033 -893
- package/dist/canvas/index.d.cts +2 -0
- package/dist/canvas/index.d.ts +2 -0
- package/dist/canvas/index.js +125 -74
- package/dist/canvas/useCanvasPlaybackSurface.d.cts +28 -0
- package/dist/canvas/useCanvasPlaybackSurface.d.ts +28 -0
- package/dist/chart/ChartEditor.d.cts +12 -1
- package/dist/chart/ChartEditor.d.ts +12 -1
- package/dist/chart/index.cjs +187 -29
- package/dist/chart/index.js +74 -10
- package/dist/{chunk-SMMO7CZB.js → chunk-6YRSQW2V.js} +84 -2
- package/dist/chunk-7I73DW4V.js +43 -0
- package/dist/{chunk-GML6BYCN.js → chunk-GECXTPSH.js} +53 -3
- package/dist/chunk-IPVWWVSF.js +96 -0
- package/dist/hooks/useAgentToolProvider.d.cts +6 -2
- package/dist/hooks/useAgentToolProvider.d.ts +6 -2
- package/dist/image-editor/ImageEditor.d.cts +10 -0
- package/dist/image-editor/ImageEditor.d.ts +10 -0
- package/dist/image-editor/index.cjs +1028 -864
- package/dist/image-editor/index.js +2 -1
- package/dist/index.cjs +2070 -1812
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +21 -3
- package/dist/paint-editor/PaintEditor.d.cts +12 -1
- package/dist/paint-editor/PaintEditor.d.ts +12 -1
- package/dist/paint-editor/index.cjs +319 -164
- package/dist/paint-editor/index.js +84 -11
- package/dist/parameters/ParametersPanel.d.cts +11 -1
- package/dist/parameters/ParametersPanel.d.ts +11 -1
- package/dist/parameters/index.cjs +190 -41
- package/dist/parameters/index.js +23 -4
- package/dist/playback/AgentPlaybackContext.d.cts +9 -0
- package/dist/playback/AgentPlaybackContext.d.ts +9 -0
- package/dist/playback/PresenceLayer.d.cts +28 -0
- package/dist/playback/PresenceLayer.d.ts +28 -0
- package/dist/playback/index.d.cts +4 -0
- package/dist/playback/index.d.ts +4 -0
- package/dist/playback/useElementPlaybackSurface.d.cts +19 -0
- package/dist/playback/useElementPlaybackSurface.d.ts +19 -0
- package/dist/playback/usePlaybackSurface.d.cts +11 -0
- package/dist/playback/usePlaybackSurface.d.ts +11 -0
- package/dist/spreadsheet/SpreadsheetEditor.d.cts +10 -0
- package/dist/spreadsheet/SpreadsheetEditor.d.ts +10 -0
- package/dist/spreadsheet/index.cjs +443 -313
- package/dist/spreadsheet/index.js +2 -1
- package/dist/vector/VectorCanvas.d.cts +11 -1
- package/dist/vector/VectorCanvas.d.ts +11 -1
- package/dist/vector/index.cjs +946 -826
- package/dist/vector/index.js +42 -3
- package/dist/video-editor/VideoEditor.d.cts +6 -1
- package/dist/video-editor/VideoEditor.d.ts +6 -1
- package/dist/video-editor/VideoTimeline.d.cts +11 -1
- package/dist/video-editor/VideoTimeline.d.ts +11 -1
- package/dist/video-editor/index.cjs +463 -332
- package/dist/video-editor/index.js +53 -5
- package/package.json +3 -3
|
@@ -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;
|
package/dist/chart/index.cjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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,
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
/* @__PURE__ */ (0,
|
|
791
|
-
/* @__PURE__ */ (0,
|
|
792
|
-
/* @__PURE__ */ (0,
|
|
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,
|
|
795
|
-
state.issues.length > 0 && /* @__PURE__ */ (0,
|
|
796
|
-
/* @__PURE__ */ (0,
|
|
797
|
-
/* @__PURE__ */ (0,
|
|
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,
|
|
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,
|
|
959
|
+
showDataGrid && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartDataGrid, { controller })
|
|
802
960
|
] });
|
|
803
961
|
}
|
|
804
962
|
|
|
805
963
|
// src/chart/ChartStreamingView.tsx
|
|
806
|
-
var
|
|
964
|
+
var import_react9 = require("react");
|
|
807
965
|
var import_chart6 = require("@pixerate/editor/chart");
|
|
808
|
-
var
|
|
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,
|
|
811
|
-
const fullTheme = (0,
|
|
812
|
-
const [scene, setScene] = (0,
|
|
813
|
-
const shown = (0,
|
|
814
|
-
const lastAdopt = (0,
|
|
815
|
-
const frame = (0,
|
|
816
|
-
const pending = (0,
|
|
817
|
-
(0,
|
|
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,
|
|
1007
|
+
(0, import_react9.useEffect)(() => () => {
|
|
850
1008
|
if (frame.current !== null) cancelAnimationFrame(frame.current);
|
|
851
1009
|
}, []);
|
|
852
|
-
return /* @__PURE__ */ (0,
|
|
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,
|
|
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,
|
|
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 = {
|
package/dist/chart/index.js
CHANGED
|
@@ -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 =
|
|
70
|
-
const lastAdopt =
|
|
71
|
-
const frame =
|
|
72
|
-
const pending =
|
|
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);
|
|
@@ -7,6 +7,11 @@ import {
|
|
|
7
7
|
useEffectDescription,
|
|
8
8
|
useEffects
|
|
9
9
|
} from "./chunk-5R67YSSD.js";
|
|
10
|
+
import {
|
|
11
|
+
PresenceLayer,
|
|
12
|
+
useAgentPlayback,
|
|
13
|
+
usePlaybackSurface
|
|
14
|
+
} from "./chunk-IPVWWVSF.js";
|
|
10
15
|
|
|
11
16
|
// src/image-editor/useImageEditor.ts
|
|
12
17
|
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
@@ -180,6 +185,8 @@ function useImageEffectsTools(registry, controller, options = {}) {
|
|
|
180
185
|
import React14, { useRef as useRef5, useEffect as useEffect12, useState as useState15, useCallback as useCallback2 } from "react";
|
|
181
186
|
import {
|
|
182
187
|
canvasToImagePoint,
|
|
188
|
+
imageToCanvasPoint,
|
|
189
|
+
createImagePlaybackLocator,
|
|
183
190
|
hitTestCrop,
|
|
184
191
|
getCropCursor,
|
|
185
192
|
calculateCropDrag,
|
|
@@ -2364,7 +2371,10 @@ var ImageEditor = ({
|
|
|
2364
2371
|
onInpaint,
|
|
2365
2372
|
onRemoveBackground,
|
|
2366
2373
|
aiHooks,
|
|
2367
|
-
effects
|
|
2374
|
+
effects,
|
|
2375
|
+
playback,
|
|
2376
|
+
playbackId = "image",
|
|
2377
|
+
onPlaybackReveal
|
|
2368
2378
|
}) => {
|
|
2369
2379
|
const internalEditor = useImageEditor({ image: src });
|
|
2370
2380
|
const editor = externalEditor || internalEditor;
|
|
@@ -2377,6 +2387,68 @@ var ImageEditor = ({
|
|
|
2377
2387
|
const canvasRef = useRef5(null);
|
|
2378
2388
|
const containerRef = useRef5(null);
|
|
2379
2389
|
const [activeTab, setActiveTab] = useState15("crop");
|
|
2390
|
+
const rootRef = useRef5(null);
|
|
2391
|
+
const activeTabRef = useRef5(activeTab);
|
|
2392
|
+
activeTabRef.current = activeTab;
|
|
2393
|
+
const ambientPlayback = useAgentPlayback();
|
|
2394
|
+
const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
|
|
2395
|
+
const [locateLayer] = useState15(() => createImagePlaybackLocator(controller));
|
|
2396
|
+
const docToRoot = (p) => {
|
|
2397
|
+
const canvas = canvasRef.current;
|
|
2398
|
+
const root = rootRef.current;
|
|
2399
|
+
if (!canvas || !root || !canvas.width) return p;
|
|
2400
|
+
const r = canvas.getBoundingClientRect();
|
|
2401
|
+
const box = root.getBoundingClientRect();
|
|
2402
|
+
const c = imageToCanvasPoint(p, controller.getState(), canvas.width, canvas.height, activeTabRef.current === "crop");
|
|
2403
|
+
return { x: r.left - box.left + c.x * r.width / canvas.width, y: r.top - box.top + c.y * r.height / canvas.height };
|
|
2404
|
+
};
|
|
2405
|
+
const clientToDoc = (p) => {
|
|
2406
|
+
const canvas = canvasRef.current;
|
|
2407
|
+
if (!canvas || !canvas.width) return p;
|
|
2408
|
+
const r = canvas.getBoundingClientRect();
|
|
2409
|
+
const sx = r.width > 0 ? canvas.width / r.width : 1;
|
|
2410
|
+
const sy = r.height > 0 ? canvas.height / r.height : 1;
|
|
2411
|
+
return canvasToImagePoint({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), canvas.width, canvas.height, activeTabRef.current === "crop");
|
|
2412
|
+
};
|
|
2413
|
+
const elementRect = (selector) => {
|
|
2414
|
+
const el = rootRef.current?.querySelector(selector);
|
|
2415
|
+
const r = el?.getBoundingClientRect();
|
|
2416
|
+
if (!r || r.width <= 0) return null;
|
|
2417
|
+
const a = clientToDoc({ x: r.left, y: r.top });
|
|
2418
|
+
const b = clientToDoc({ x: r.right, y: r.bottom });
|
|
2419
|
+
return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), width: Math.abs(b.x - a.x), height: Math.abs(b.y - a.y) };
|
|
2420
|
+
};
|
|
2421
|
+
const agentPresence = usePlaybackSurface(playing, playbackId, {
|
|
2422
|
+
defaultKind: "layer",
|
|
2423
|
+
locate: (ref) => {
|
|
2424
|
+
if (ref.kind === "panel") return elementRect(`[data-image-tab="${CSS.escape(ref.id)}"]`);
|
|
2425
|
+
if (ref.kind === "control") return elementRect(`[data-control-id="${CSS.escape(ref.id)}"]`);
|
|
2426
|
+
return locateLayer(ref) ?? (ref.kind === "layer" || ref.kind === "item" ? elementRect(`[data-layer-id="${CSS.escape(ref.id)}"]`) : null);
|
|
2427
|
+
},
|
|
2428
|
+
open: async (ref) => {
|
|
2429
|
+
if (ref.kind !== "panel" || activeTabRef.current === ref.id) return;
|
|
2430
|
+
rootRef.current?.querySelector(`[data-image-tab="${CSS.escape(ref.id)}"]`)?.click();
|
|
2431
|
+
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
2432
|
+
},
|
|
2433
|
+
bounds: () => {
|
|
2434
|
+
const r = canvasRef.current?.getBoundingClientRect();
|
|
2435
|
+
if (!r || r.width <= 0) return null;
|
|
2436
|
+
const a = clientToDoc({ x: r.left, y: r.top });
|
|
2437
|
+
const b = clientToDoc({ x: r.right, y: r.bottom });
|
|
2438
|
+
return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), width: Math.abs(b.x - a.x), height: Math.abs(b.y - a.y) };
|
|
2439
|
+
},
|
|
2440
|
+
visible: () => {
|
|
2441
|
+
const r = rootRef.current?.getBoundingClientRect();
|
|
2442
|
+
return !!r && r.width > 0 && r.height > 0 && !(typeof document !== "undefined" && document.visibilityState === "hidden");
|
|
2443
|
+
},
|
|
2444
|
+
toViewport: (p) => {
|
|
2445
|
+
const box = rootRef.current?.getBoundingClientRect();
|
|
2446
|
+
const q = docToRoot(p);
|
|
2447
|
+
return { x: (box?.left ?? 0) + q.x, y: (box?.top ?? 0) + q.y };
|
|
2448
|
+
},
|
|
2449
|
+
fromViewport: clientToDoc,
|
|
2450
|
+
reveal: () => onPlaybackReveal?.()
|
|
2451
|
+
});
|
|
2380
2452
|
const [activeCropRatio, setActiveCropRatio] = useState15(null);
|
|
2381
2453
|
const [selectionOptions, setSelectionOptions] = useState15(DEFAULT_SELECTION_TOOL_OPTIONS);
|
|
2382
2454
|
const selectionOptionsRef = useRef5(selectionOptions);
|
|
@@ -3094,15 +3166,18 @@ var ImageEditor = ({
|
|
|
3094
3166
|
return /* @__PURE__ */ jsxs15(
|
|
3095
3167
|
"div",
|
|
3096
3168
|
{
|
|
3097
|
-
|
|
3169
|
+
ref: rootRef,
|
|
3170
|
+
className: `relative flex flex-col bg-slate-900 border border-slate-800 rounded-xl overflow-hidden shadow-2xl text-slate-100 ${className}`,
|
|
3098
3171
|
style,
|
|
3099
3172
|
children: [
|
|
3173
|
+
playing && /* @__PURE__ */ jsx16(PresenceLayer, { presence: agentPresence, viewport: docToRoot }),
|
|
3100
3174
|
/* @__PURE__ */ jsxs15("div", { className: "flex flex-wrap items-center justify-between px-4 py-3 bg-slate-950/80 border-b border-slate-800 gap-3", children: [
|
|
3101
3175
|
/* @__PURE__ */ jsxs15("div", { className: "flex items-center gap-1 bg-slate-900 p-1 rounded-lg border border-slate-800 text-xs", children: [
|
|
3102
3176
|
/* @__PURE__ */ jsx16(
|
|
3103
3177
|
"button",
|
|
3104
3178
|
{
|
|
3105
3179
|
type: "button",
|
|
3180
|
+
"data-image-tab": "crop",
|
|
3106
3181
|
onClick: () => {
|
|
3107
3182
|
setActiveTab("crop");
|
|
3108
3183
|
editor.setTool("crop");
|
|
@@ -3115,6 +3190,7 @@ var ImageEditor = ({
|
|
|
3115
3190
|
"button",
|
|
3116
3191
|
{
|
|
3117
3192
|
type: "button",
|
|
3193
|
+
"data-image-tab": "adjust",
|
|
3118
3194
|
onClick: () => {
|
|
3119
3195
|
setActiveTab("adjust");
|
|
3120
3196
|
editor.setTool("select");
|
|
@@ -3127,6 +3203,7 @@ var ImageEditor = ({
|
|
|
3127
3203
|
"button",
|
|
3128
3204
|
{
|
|
3129
3205
|
type: "button",
|
|
3206
|
+
"data-image-tab": "layers",
|
|
3130
3207
|
onClick: () => {
|
|
3131
3208
|
setActiveTab("layers");
|
|
3132
3209
|
editor.setTool("select");
|
|
@@ -3139,6 +3216,7 @@ var ImageEditor = ({
|
|
|
3139
3216
|
"button",
|
|
3140
3217
|
{
|
|
3141
3218
|
type: "button",
|
|
3219
|
+
"data-image-tab": "paint",
|
|
3142
3220
|
onClick: () => {
|
|
3143
3221
|
setActiveTab("paint");
|
|
3144
3222
|
editor.setTool("brush");
|
|
@@ -3151,6 +3229,7 @@ var ImageEditor = ({
|
|
|
3151
3229
|
"button",
|
|
3152
3230
|
{
|
|
3153
3231
|
type: "button",
|
|
3232
|
+
"data-image-tab": "select",
|
|
3154
3233
|
onClick: () => {
|
|
3155
3234
|
setActiveTab("select");
|
|
3156
3235
|
editor.setTool("select");
|
|
@@ -3163,6 +3242,7 @@ var ImageEditor = ({
|
|
|
3163
3242
|
"button",
|
|
3164
3243
|
{
|
|
3165
3244
|
type: "button",
|
|
3245
|
+
"data-image-tab": "annotate",
|
|
3166
3246
|
onClick: () => {
|
|
3167
3247
|
setActiveTab("annotate");
|
|
3168
3248
|
editor.setTool("pen");
|
|
@@ -3175,6 +3255,7 @@ var ImageEditor = ({
|
|
|
3175
3255
|
"button",
|
|
3176
3256
|
{
|
|
3177
3257
|
type: "button",
|
|
3258
|
+
"data-image-tab": "depth",
|
|
3178
3259
|
onClick: () => {
|
|
3179
3260
|
setActiveTab("depth");
|
|
3180
3261
|
editor.setTool("select");
|
|
@@ -3187,6 +3268,7 @@ var ImageEditor = ({
|
|
|
3187
3268
|
"button",
|
|
3188
3269
|
{
|
|
3189
3270
|
type: "button",
|
|
3271
|
+
"data-image-tab": "ai",
|
|
3190
3272
|
onClick: () => {
|
|
3191
3273
|
setActiveTab("ai");
|
|
3192
3274
|
editor.setTool("select");
|
|
@@ -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
|
+
};
|