@pixerate/editor-react 0.100.0 → 0.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation-editor/index.cjs +3 -1
- package/dist/animation-editor/index.js +5 -2
- package/dist/animation-editor/useAnimationEditor.d.cts +4 -1
- package/dist/animation-editor/useAnimationEditor.d.ts +4 -1
- package/dist/chart/index.cjs +3 -1
- package/dist/chart/index.js +1 -1
- package/dist/chart/useChartEditor.d.cts +4 -1
- package/dist/chart/useChartEditor.d.ts +4 -1
- package/dist/{chunk-OTDAEVHW.js → chunk-GJ2TYERJ.js} +45 -49
- package/dist/{chunk-GDPWLGPD.js → chunk-ZHMATFBB.js} +5 -2
- package/dist/image-editor/index.cjs +42 -48
- package/dist/image-editor/index.js +1 -1
- package/dist/index.cjs +42 -48
- package/dist/index.js +2 -2
- package/dist/parameters/index.cjs +3 -1
- package/dist/parameters/index.js +5 -2
- package/dist/parameters/useParameters.d.cts +4 -1
- package/dist/parameters/useParameters.d.ts +4 -1
- package/dist/vector/index.cjs +3 -1
- package/dist/vector/index.js +5 -2
- package/dist/vector/useVectorEditor.d.cts +4 -1
- package/dist/vector/useVectorEditor.d.ts +4 -1
- package/dist/video-editor/index.cjs +3 -1
- package/dist/video-editor/index.js +5 -2
- package/dist/video-editor/useVideoEditor.d.cts +4 -1
- package/dist/video-editor/useVideoEditor.d.ts +4 -1
- package/package.json +5 -5
|
@@ -85,7 +85,9 @@ function useAnimationEditor(controllerOrOptions = {}) {
|
|
|
85
85
|
}),
|
|
86
86
|
[controller]
|
|
87
87
|
);
|
|
88
|
-
|
|
88
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_animation_editor.createAnimationEditorDocument)(controller), [controller]);
|
|
89
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
90
|
+
return { controller, editorDocument, state, ...actions };
|
|
89
91
|
}
|
|
90
92
|
function useAnimationEditorTools(registry, controller, options = {}) {
|
|
91
93
|
const { id, namespace, readOnly, rasterize, playbackSurface } = options;
|
|
@@ -18,7 +18,8 @@ import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
|
18
18
|
import {
|
|
19
19
|
AnimationEditorController,
|
|
20
20
|
createAnimationEditorToolProvider,
|
|
21
|
-
createAnimationEffectsToolProvider
|
|
21
|
+
createAnimationEffectsToolProvider,
|
|
22
|
+
createAnimationEditorDocument
|
|
22
23
|
} from "@pixerate/editor/animation-editor";
|
|
23
24
|
function useAnimationEditorController(options = {}) {
|
|
24
25
|
const ref = useRef(null);
|
|
@@ -52,7 +53,9 @@ function useAnimationEditor(controllerOrOptions = {}) {
|
|
|
52
53
|
}),
|
|
53
54
|
[controller]
|
|
54
55
|
);
|
|
55
|
-
|
|
56
|
+
const editorDocument = useMemo(() => createAnimationEditorDocument(controller), [controller]);
|
|
57
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
58
|
+
return { controller, editorDocument, state, ...actions };
|
|
56
59
|
}
|
|
57
60
|
function useAnimationEditorTools(registry, controller, options = {}) {
|
|
58
61
|
const { id, namespace, readOnly, rasterize, playbackSurface } = options;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnimationEditorController, type AnimationEffectsToolProviderOptions, type AnimationEditorOptions, type AnimationEditorState, type AnimationEditorToolProviderOptions } from '@pixerate/editor/animation-editor';
|
|
1
|
+
import { AnimationEditorController, type AnimationEffectsToolProviderOptions, type AnimationEditorOptions, type AnimationEditorState, type AnimationEditorToolProviderOptions, type MotionScene } from '@pixerate/editor/animation-editor';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
3
4
|
/** An `AnimationEditorController` created once for the component's lifetime (destroyed on unmount). */
|
|
4
5
|
export declare function useAnimationEditorController(options?: AnimationEditorOptions): AnimationEditorController;
|
|
@@ -6,6 +7,8 @@ export declare function useAnimationEditorController(options?: AnimationEditorOp
|
|
|
6
7
|
export declare function useAnimationEditorState(controller: AnimationEditorController): AnimationEditorState;
|
|
7
8
|
export interface UseAnimationEditorResult {
|
|
8
9
|
controller: AnimationEditorController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<MotionScene>;
|
|
9
12
|
state: AnimationEditorState;
|
|
10
13
|
play: () => void;
|
|
11
14
|
pause: () => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnimationEditorController, type AnimationEffectsToolProviderOptions, type AnimationEditorOptions, type AnimationEditorState, type AnimationEditorToolProviderOptions } from '@pixerate/editor/animation-editor';
|
|
1
|
+
import { AnimationEditorController, type AnimationEffectsToolProviderOptions, type AnimationEditorOptions, type AnimationEditorState, type AnimationEditorToolProviderOptions, type MotionScene } from '@pixerate/editor/animation-editor';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
3
4
|
/** An `AnimationEditorController` created once for the component's lifetime (destroyed on unmount). */
|
|
4
5
|
export declare function useAnimationEditorController(options?: AnimationEditorOptions): AnimationEditorController;
|
|
@@ -6,6 +7,8 @@ export declare function useAnimationEditorController(options?: AnimationEditorOp
|
|
|
6
7
|
export declare function useAnimationEditorState(controller: AnimationEditorController): AnimationEditorState;
|
|
7
8
|
export interface UseAnimationEditorResult {
|
|
8
9
|
controller: AnimationEditorController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<MotionScene>;
|
|
9
12
|
state: AnimationEditorState;
|
|
10
13
|
play: () => void;
|
|
11
14
|
pause: () => void;
|
package/dist/chart/index.cjs
CHANGED
|
@@ -88,7 +88,9 @@ function useChartEditor(controllerOrOptions = {}) {
|
|
|
88
88
|
}),
|
|
89
89
|
[controller]
|
|
90
90
|
);
|
|
91
|
-
|
|
91
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_chart.createChartEditorDocument)(controller), [controller]);
|
|
92
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
93
|
+
return { controller, editorDocument, state, spec: state.spec, selection: state.selection, ...actions };
|
|
92
94
|
}
|
|
93
95
|
function useChartCommands(registry, controller, options = {}) {
|
|
94
96
|
const { prefix, group, scope } = options;
|
package/dist/chart/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
2
|
-
import { ChartController, ChartDirector, ChartPresence, type OfficeChartToolProviderOptions, type ChartScene, type ChartToolProviderOptions, type ChartActionResult, type ChartCommandOptions, type ChartControllerOptions, type ChartSelection, type ChartSpecPatch, type ChartState, type ChartType } from '@pixerate/editor/chart';
|
|
2
|
+
import { ChartController, ChartDirector, ChartPresence, type OfficeChartToolProviderOptions, type ChartScene, type ChartToolProviderOptions, type ChartActionResult, type ChartCommandOptions, type ChartControllerOptions, type ChartSelection, type ChartSpecPatch, type ChartState, type ChartType, type ChartSpec } from '@pixerate/editor/chart';
|
|
3
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
4
|
/** A `ChartController` created once for the component's lifetime. */
|
|
4
5
|
export declare function useChartController(options?: ChartControllerOptions): ChartController;
|
|
5
6
|
/** The controller's state (re-renders on every change). */
|
|
6
7
|
export declare function useChartState(controller: ChartController): ChartState;
|
|
7
8
|
export interface UseChartEditorResult {
|
|
8
9
|
controller: ChartController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<ChartSpec>;
|
|
9
12
|
state: ChartState;
|
|
10
13
|
spec: ChartState['spec'];
|
|
11
14
|
selection: ChartSelection | null;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
2
|
-
import { ChartController, ChartDirector, ChartPresence, type OfficeChartToolProviderOptions, type ChartScene, type ChartToolProviderOptions, type ChartActionResult, type ChartCommandOptions, type ChartControllerOptions, type ChartSelection, type ChartSpecPatch, type ChartState, type ChartType } from '@pixerate/editor/chart';
|
|
2
|
+
import { ChartController, ChartDirector, ChartPresence, type OfficeChartToolProviderOptions, type ChartScene, type ChartToolProviderOptions, type ChartActionResult, type ChartCommandOptions, type ChartControllerOptions, type ChartSelection, type ChartSpecPatch, type ChartState, type ChartType, type ChartSpec } from '@pixerate/editor/chart';
|
|
3
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
4
|
/** A `ChartController` created once for the component's lifetime. */
|
|
4
5
|
export declare function useChartController(options?: ChartControllerOptions): ChartController;
|
|
5
6
|
/** The controller's state (re-renders on every change). */
|
|
6
7
|
export declare function useChartState(controller: ChartController): ChartState;
|
|
7
8
|
export interface UseChartEditorResult {
|
|
8
9
|
controller: ChartController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<ChartSpec>;
|
|
9
12
|
state: ChartState;
|
|
10
13
|
spec: ChartState['spec'];
|
|
11
14
|
selection: ChartSelection | null;
|
|
@@ -212,6 +212,8 @@ import {
|
|
|
212
212
|
pointerPressure,
|
|
213
213
|
FreeTransformTool,
|
|
214
214
|
getViewportProjection,
|
|
215
|
+
measureCanvasViewport,
|
|
216
|
+
watchCanvasViewport,
|
|
215
217
|
ShapeDrawGesture,
|
|
216
218
|
TypeToolGesture,
|
|
217
219
|
DEFAULT_SHAPE_TOOL_OPTIONS,
|
|
@@ -247,6 +249,7 @@ var ImageEditorCanvas = ({
|
|
|
247
249
|
const canvasRef = useRef2(null);
|
|
248
250
|
const containerRef = useRef2(null);
|
|
249
251
|
const rootRef = useRef2(null);
|
|
252
|
+
const viewRef = useRef2({ width: 0, height: 0 });
|
|
250
253
|
const modeRef = useRef2(mode);
|
|
251
254
|
modeRef.current = mode;
|
|
252
255
|
const latest = useRef2({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
|
|
@@ -258,19 +261,19 @@ var ImageEditorCanvas = ({
|
|
|
258
261
|
const docToRoot = (p) => {
|
|
259
262
|
const canvas = canvasRef.current;
|
|
260
263
|
const root = rootRef.current;
|
|
261
|
-
if (!canvas || !root || !
|
|
264
|
+
if (!canvas || !root || !viewRef.current.width) return p;
|
|
262
265
|
const r = canvas.getBoundingClientRect();
|
|
263
266
|
const box = root.getBoundingClientRect();
|
|
264
|
-
const c = imageToCanvasPoint(p, controller.getState(),
|
|
265
|
-
return { x: r.left - box.left + c.x * r.width /
|
|
267
|
+
const c = imageToCanvasPoint(p, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
|
|
268
|
+
return { x: r.left - box.left + c.x * r.width / viewRef.current.width, y: r.top - box.top + c.y * r.height / viewRef.current.height };
|
|
266
269
|
};
|
|
267
270
|
const clientToDoc = (p) => {
|
|
268
271
|
const canvas = canvasRef.current;
|
|
269
|
-
if (!canvas || !
|
|
272
|
+
if (!canvas || !viewRef.current.width) return p;
|
|
270
273
|
const r = canvas.getBoundingClientRect();
|
|
271
|
-
const sx = r.width > 0 ?
|
|
272
|
-
const sy = r.height > 0 ?
|
|
273
|
-
return canvasToImagePoint({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(),
|
|
274
|
+
const sx = r.width > 0 ? viewRef.current.width / r.width : 1;
|
|
275
|
+
const sy = r.height > 0 ? viewRef.current.height / r.height : 1;
|
|
276
|
+
return canvasToImagePoint({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
|
|
274
277
|
};
|
|
275
278
|
const clientRect = (r) => {
|
|
276
279
|
if (!r || r.width <= 0) return null;
|
|
@@ -369,11 +372,12 @@ var ImageEditorCanvas = ({
|
|
|
369
372
|
const canvas = canvasRef.current;
|
|
370
373
|
const container = containerRef.current;
|
|
371
374
|
if (!canvas || !container) return;
|
|
372
|
-
const
|
|
373
|
-
|
|
375
|
+
const viewport = measureCanvasViewport(container);
|
|
376
|
+
viewRef.current = { width: viewport.width, height: viewport.height };
|
|
374
377
|
await controller.render(canvas, {
|
|
375
|
-
viewportWidth:
|
|
376
|
-
viewportHeight:
|
|
378
|
+
viewportWidth: viewport.width,
|
|
379
|
+
viewportHeight: viewport.height,
|
|
380
|
+
pixelRatio: viewport.pixelRatio,
|
|
377
381
|
fit,
|
|
378
382
|
showCropOverlay: mode === "crop",
|
|
379
383
|
showSelectionOverlay: true,
|
|
@@ -456,12 +460,12 @@ var ImageEditorCanvas = ({
|
|
|
456
460
|
const transformPoint = (e) => {
|
|
457
461
|
const canvas = canvasRef.current;
|
|
458
462
|
const rect = canvas.getBoundingClientRect();
|
|
459
|
-
const sx = rect.width > 0 ?
|
|
460
|
-
const sy = rect.height > 0 ?
|
|
463
|
+
const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
464
|
+
const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
461
465
|
const s = controller.getState();
|
|
462
466
|
const cropping = mode === "crop";
|
|
463
|
-
const projection = getViewportProjection(s,
|
|
464
|
-
const pt = canvasToImagePoint({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s,
|
|
467
|
+
const projection = getViewportProjection(s, viewRef.current.width, viewRef.current.height, cropping);
|
|
468
|
+
const pt = canvasToImagePoint({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, cropping);
|
|
465
469
|
transformTool.setView(projection.scale);
|
|
466
470
|
return { pt, tolerance: 6 / (projection.scale || 1) };
|
|
467
471
|
};
|
|
@@ -511,24 +515,16 @@ var ImageEditorCanvas = ({
|
|
|
511
515
|
useEffect2(() => {
|
|
512
516
|
const container = containerRef.current;
|
|
513
517
|
if (!container) return;
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
});
|
|
518
|
-
observer.observe(container);
|
|
519
|
-
return () => observer.disconnect();
|
|
520
|
-
} else {
|
|
521
|
-
const handleResize = () => renderCanvas();
|
|
522
|
-
window.addEventListener("resize", handleResize);
|
|
523
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
524
|
-
}
|
|
518
|
+
const { width, height } = measureCanvasViewport(container);
|
|
519
|
+
viewRef.current = { width, height };
|
|
520
|
+
return watchCanvasViewport(container, () => renderCanvas());
|
|
525
521
|
}, [renderCanvas]);
|
|
526
522
|
const getCanvasEventPoint = (e) => {
|
|
527
523
|
const canvas = canvasRef.current;
|
|
528
524
|
if (!canvas) return { x: 0, y: 0 };
|
|
529
525
|
const rect = canvas.getBoundingClientRect();
|
|
530
|
-
const scaleX = rect.width > 0 ?
|
|
531
|
-
const scaleY = rect.height > 0 ?
|
|
526
|
+
const scaleX = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
527
|
+
const scaleY = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
532
528
|
return {
|
|
533
529
|
x: (e.clientX - rect.left) * scaleX,
|
|
534
530
|
y: (e.clientY - rect.top) * scaleY
|
|
@@ -540,11 +536,11 @@ var ImageEditorCanvas = ({
|
|
|
540
536
|
const events = typeof native.getCoalescedEvents === "function" ? native.getCoalescedEvents() : [];
|
|
541
537
|
const list = events.length ? events : [native];
|
|
542
538
|
const rect = canvas.getBoundingClientRect();
|
|
543
|
-
const sx = rect.width > 0 ?
|
|
544
|
-
const sy = rect.height > 0 ?
|
|
539
|
+
const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
540
|
+
const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
545
541
|
const s = controller.getState();
|
|
546
542
|
return list.map((ev) => ({
|
|
547
|
-
...canvasToImagePoint({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s,
|
|
543
|
+
...canvasToImagePoint({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, false),
|
|
548
544
|
pressure: pointerPressure(ev)
|
|
549
545
|
}));
|
|
550
546
|
};
|
|
@@ -590,7 +586,7 @@ var ImageEditorCanvas = ({
|
|
|
590
586
|
const canvasPt = getCanvasEventPoint(e);
|
|
591
587
|
if (mode === "select") {
|
|
592
588
|
const gesture = selectionGestureRef.current;
|
|
593
|
-
const imgPt = canvasToImagePoint(canvasPt, state,
|
|
589
|
+
const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
594
590
|
void gesture.begin(imgPt, e).then(() => report("select", gesture.error));
|
|
595
591
|
return;
|
|
596
592
|
}
|
|
@@ -601,8 +597,8 @@ var ImageEditorCanvas = ({
|
|
|
601
597
|
width: state.imageDimensions.width,
|
|
602
598
|
height: state.imageDimensions.height
|
|
603
599
|
};
|
|
604
|
-
const handle = hitTestCrop(canvasPt, state,
|
|
605
|
-
const startImgPt = canvasToImagePoint(canvasPt, state,
|
|
600
|
+
const handle = hitTestCrop(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
|
|
601
|
+
const startImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
|
|
606
602
|
if (handle) {
|
|
607
603
|
cropDragInfoRef.current = {
|
|
608
604
|
handle,
|
|
@@ -621,7 +617,7 @@ var ImageEditorCanvas = ({
|
|
|
621
617
|
return;
|
|
622
618
|
}
|
|
623
619
|
if (mode === "annotate" && (state.activeTool === "shape" || state.activeTool === "type")) {
|
|
624
|
-
const imgPt = canvasToImagePoint(canvasPt, state,
|
|
620
|
+
const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
625
621
|
report(state.activeTool, null);
|
|
626
622
|
if (state.activeTool === "shape") shapeGestureRef.current.down(imgPt);
|
|
627
623
|
else {
|
|
@@ -632,7 +628,7 @@ var ImageEditorCanvas = ({
|
|
|
632
628
|
return;
|
|
633
629
|
}
|
|
634
630
|
if (mode === "annotate") {
|
|
635
|
-
const imgPt = canvasToImagePoint(canvasPt, state,
|
|
631
|
+
const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
636
632
|
dragStartPointRef.current = imgPt;
|
|
637
633
|
if (state.activeTool === "select") {
|
|
638
634
|
for (let i = state.annotations.length - 1; i >= 0; i--) {
|
|
@@ -673,7 +669,7 @@ var ImageEditorCanvas = ({
|
|
|
673
669
|
const canvasPt = getCanvasEventPoint(e);
|
|
674
670
|
if (mode === "select") {
|
|
675
671
|
const gesture = selectionGestureRef.current;
|
|
676
|
-
if (gesture.active && gesture.move(canvasToImagePoint(canvasPt, state,
|
|
672
|
+
if (gesture.active && gesture.move(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
|
|
677
673
|
selectionDraftRef.current = gesture.draftPath;
|
|
678
674
|
renderCanvas();
|
|
679
675
|
}
|
|
@@ -682,7 +678,7 @@ var ImageEditorCanvas = ({
|
|
|
682
678
|
if (mode === "crop") {
|
|
683
679
|
const drag = cropDragInfoRef.current;
|
|
684
680
|
if (drag) {
|
|
685
|
-
const currentImgPt = canvasToImagePoint(canvasPt, state,
|
|
681
|
+
const currentImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
|
|
686
682
|
let newCrop;
|
|
687
683
|
if (drag.handle === "new") {
|
|
688
684
|
const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
|
|
@@ -716,7 +712,7 @@ var ImageEditorCanvas = ({
|
|
|
716
712
|
width: state.imageDimensions.width,
|
|
717
713
|
height: state.imageDimensions.height
|
|
718
714
|
};
|
|
719
|
-
const handle = hitTestCrop(canvasPt, state,
|
|
715
|
+
const handle = hitTestCrop(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
|
|
720
716
|
canvas.style.cursor = getCropCursor(handle, state.transform);
|
|
721
717
|
}
|
|
722
718
|
return;
|
|
@@ -724,7 +720,7 @@ var ImageEditorCanvas = ({
|
|
|
724
720
|
if (mode === "annotate" && state.activeTool === "shape") {
|
|
725
721
|
const g = shapeGestureRef.current;
|
|
726
722
|
if (g.active) {
|
|
727
|
-
g.move(canvasToImagePoint(canvasPt, state,
|
|
723
|
+
g.move(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false), { shift: e.shiftKey, alt: e.altKey });
|
|
728
724
|
if (g.error) report("shape", g.error);
|
|
729
725
|
}
|
|
730
726
|
return;
|
|
@@ -732,7 +728,7 @@ var ImageEditorCanvas = ({
|
|
|
732
728
|
if (mode === "annotate") {
|
|
733
729
|
if (annotationDragInfoRef.current) {
|
|
734
730
|
const drag = annotationDragInfoRef.current;
|
|
735
|
-
const currentImgPt2 = canvasToImagePoint(canvasPt, state,
|
|
731
|
+
const currentImgPt2 = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
736
732
|
const dx = currentImgPt2.x - drag.startImgPt.x;
|
|
737
733
|
const dy = currentImgPt2.y - drag.startImgPt.y;
|
|
738
734
|
editor.updateAnnotation(drag.annId, {
|
|
@@ -744,7 +740,7 @@ var ImageEditorCanvas = ({
|
|
|
744
740
|
const startPt = dragStartPointRef.current;
|
|
745
741
|
if (!startPt) {
|
|
746
742
|
if (state.activeTool === "select") {
|
|
747
|
-
const imgPt = canvasToImagePoint(canvasPt, state,
|
|
743
|
+
const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
748
744
|
let hovered = false;
|
|
749
745
|
for (let i = state.annotations.length - 1; i >= 0; i--) {
|
|
750
746
|
if (hitTestAnnotation(imgPt, state.annotations[i])) {
|
|
@@ -758,7 +754,7 @@ var ImageEditorCanvas = ({
|
|
|
758
754
|
}
|
|
759
755
|
return;
|
|
760
756
|
}
|
|
761
|
-
const currentImgPt = canvasToImagePoint(canvasPt, state,
|
|
757
|
+
const currentImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
762
758
|
const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
|
|
763
759
|
if (state.activeTool === "pen" && isDrawingRef.current) {
|
|
764
760
|
currentPathRef.current.push(currentImgPt);
|
|
@@ -815,7 +811,7 @@ var ImageEditorCanvas = ({
|
|
|
815
811
|
if (mode === "select") {
|
|
816
812
|
const gesture = selectionGestureRef.current;
|
|
817
813
|
if (gesture.active) {
|
|
818
|
-
gesture.end(canvasToImagePoint(canvasPt, state,
|
|
814
|
+
gesture.end(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
|
|
819
815
|
selectionDraftRef.current = null;
|
|
820
816
|
renderCanvas();
|
|
821
817
|
}
|
|
@@ -838,7 +834,7 @@ var ImageEditorCanvas = ({
|
|
|
838
834
|
}
|
|
839
835
|
if (mode === "annotate" && state.activeTool === "type") {
|
|
840
836
|
const tool = typeToolRef.current;
|
|
841
|
-
tool.up(canvasToImagePoint(canvasPt, state,
|
|
837
|
+
tool.up(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false));
|
|
842
838
|
setTypeSession(tool.session);
|
|
843
839
|
if (tool.error) report("type", tool.error);
|
|
844
840
|
void renderCanvas();
|
|
@@ -852,7 +848,7 @@ var ImageEditorCanvas = ({
|
|
|
852
848
|
}
|
|
853
849
|
const startPt = dragStartPointRef.current;
|
|
854
850
|
if (startPt) {
|
|
855
|
-
const currentImgPt = canvasToImagePoint(canvasPt, state,
|
|
851
|
+
const currentImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
856
852
|
const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
|
|
857
853
|
if (state.activeTool === "pen" && isDrawingRef.current) {
|
|
858
854
|
if (currentPathRef.current.length > 1) {
|
|
@@ -919,7 +915,7 @@ var ImageEditorCanvas = ({
|
|
|
919
915
|
onPointerUp: handlePaintPointerUp,
|
|
920
916
|
onPointerCancel: () => paintGestureRef.current?.cancel(),
|
|
921
917
|
"data-testid": "image-editor-canvas",
|
|
922
|
-
style: transformTool.active ? { cursor: transformCursor } :
|
|
918
|
+
style: transformTool.active ? { width: "100%", height: "100%", cursor: transformCursor } : { width: "100%", height: "100%" },
|
|
923
919
|
className: `absolute inset-0 w-full h-full block ${transformTool.active ? "touch-none" : mode === "paint" ? "touch-none cursor-crosshair" : mode === "annotate" && state.activeTool === "type" ? "cursor-text" : mode === "annotate" && state.activeTool === "shape" ? "cursor-crosshair" : ""}`
|
|
924
920
|
}
|
|
925
921
|
),
|
|
@@ -2195,7 +2191,7 @@ import {
|
|
|
2195
2191
|
rgbUnitToHex,
|
|
2196
2192
|
setRetouchChoice
|
|
2197
2193
|
} from "@pixerate/editor/image-editor";
|
|
2198
|
-
import { DEFAULT_PAINT_GRADIENT } from "@pixerate/editor/image-editor";
|
|
2194
|
+
import { DEFAULT_PAINT_GRADIENT, userErrorMessage } from "@pixerate/editor/image-editor";
|
|
2199
2195
|
|
|
2200
2196
|
// src/image-editor/PaintGradientEditor.tsx
|
|
2201
2197
|
import { PAINT_GRADIENT_KIT } from "@pixerate/editor/image-editor";
|
|
@@ -2216,7 +2212,7 @@ var BrushOptionsBar = ({ controller, className }) => {
|
|
|
2216
2212
|
setError(null);
|
|
2217
2213
|
fn();
|
|
2218
2214
|
} catch (err) {
|
|
2219
|
-
setError(
|
|
2215
|
+
setError(userErrorMessage(err));
|
|
2220
2216
|
}
|
|
2221
2217
|
};
|
|
2222
2218
|
return /* @__PURE__ */ jsxs10("div", { className: `flex flex-col gap-2 text-xs text-foreground ${className ?? ""}`, "data-testid": "brush-options", children: [
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
createChartRasterizer,
|
|
9
9
|
createChartToolProvider,
|
|
10
10
|
createOfficeChartToolProvider,
|
|
11
|
-
layoutChart
|
|
11
|
+
layoutChart,
|
|
12
|
+
createChartEditorDocument
|
|
12
13
|
} from "@pixerate/editor/chart";
|
|
13
14
|
function useChartController(options = {}) {
|
|
14
15
|
const ref = useRef(null);
|
|
@@ -38,7 +39,9 @@ function useChartEditor(controllerOrOptions = {}) {
|
|
|
38
39
|
}),
|
|
39
40
|
[controller]
|
|
40
41
|
);
|
|
41
|
-
|
|
42
|
+
const editorDocument = useMemo(() => createChartEditorDocument(controller), [controller]);
|
|
43
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
44
|
+
return { controller, editorDocument, state, spec: state.spec, selection: state.selection, ...actions };
|
|
42
45
|
}
|
|
43
46
|
function useChartCommands(registry, controller, options = {}) {
|
|
44
47
|
const { prefix, group, scope } = options;
|
|
@@ -352,6 +352,7 @@ var ImageEditorCanvas = ({
|
|
|
352
352
|
const canvasRef = (0, import_react5.useRef)(null);
|
|
353
353
|
const containerRef = (0, import_react5.useRef)(null);
|
|
354
354
|
const rootRef = (0, import_react5.useRef)(null);
|
|
355
|
+
const viewRef = (0, import_react5.useRef)({ width: 0, height: 0 });
|
|
355
356
|
const modeRef = (0, import_react5.useRef)(mode);
|
|
356
357
|
modeRef.current = mode;
|
|
357
358
|
const latest = (0, import_react5.useRef)({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
|
|
@@ -363,19 +364,19 @@ var ImageEditorCanvas = ({
|
|
|
363
364
|
const docToRoot = (p) => {
|
|
364
365
|
const canvas = canvasRef.current;
|
|
365
366
|
const root = rootRef.current;
|
|
366
|
-
if (!canvas || !root || !
|
|
367
|
+
if (!canvas || !root || !viewRef.current.width) return p;
|
|
367
368
|
const r = canvas.getBoundingClientRect();
|
|
368
369
|
const box = root.getBoundingClientRect();
|
|
369
|
-
const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(),
|
|
370
|
-
return { x: r.left - box.left + c.x * r.width /
|
|
370
|
+
const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
|
|
371
|
+
return { x: r.left - box.left + c.x * r.width / viewRef.current.width, y: r.top - box.top + c.y * r.height / viewRef.current.height };
|
|
371
372
|
};
|
|
372
373
|
const clientToDoc = (p) => {
|
|
373
374
|
const canvas = canvasRef.current;
|
|
374
|
-
if (!canvas || !
|
|
375
|
+
if (!canvas || !viewRef.current.width) return p;
|
|
375
376
|
const r = canvas.getBoundingClientRect();
|
|
376
|
-
const sx = r.width > 0 ?
|
|
377
|
-
const sy = r.height > 0 ?
|
|
378
|
-
return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(),
|
|
377
|
+
const sx = r.width > 0 ? viewRef.current.width / r.width : 1;
|
|
378
|
+
const sy = r.height > 0 ? viewRef.current.height / r.height : 1;
|
|
379
|
+
return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
|
|
379
380
|
};
|
|
380
381
|
const clientRect = (r) => {
|
|
381
382
|
if (!r || r.width <= 0) return null;
|
|
@@ -474,11 +475,12 @@ var ImageEditorCanvas = ({
|
|
|
474
475
|
const canvas = canvasRef.current;
|
|
475
476
|
const container = containerRef.current;
|
|
476
477
|
if (!canvas || !container) return;
|
|
477
|
-
const
|
|
478
|
-
|
|
478
|
+
const viewport = (0, import_image_editor2.measureCanvasViewport)(container);
|
|
479
|
+
viewRef.current = { width: viewport.width, height: viewport.height };
|
|
479
480
|
await controller.render(canvas, {
|
|
480
|
-
viewportWidth:
|
|
481
|
-
viewportHeight:
|
|
481
|
+
viewportWidth: viewport.width,
|
|
482
|
+
viewportHeight: viewport.height,
|
|
483
|
+
pixelRatio: viewport.pixelRatio,
|
|
482
484
|
fit,
|
|
483
485
|
showCropOverlay: mode === "crop",
|
|
484
486
|
showSelectionOverlay: true,
|
|
@@ -561,12 +563,12 @@ var ImageEditorCanvas = ({
|
|
|
561
563
|
const transformPoint = (e) => {
|
|
562
564
|
const canvas = canvasRef.current;
|
|
563
565
|
const rect = canvas.getBoundingClientRect();
|
|
564
|
-
const sx = rect.width > 0 ?
|
|
565
|
-
const sy = rect.height > 0 ?
|
|
566
|
+
const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
567
|
+
const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
566
568
|
const s = controller.getState();
|
|
567
569
|
const cropping = mode === "crop";
|
|
568
|
-
const projection = (0, import_image_editor2.getViewportProjection)(s,
|
|
569
|
-
const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s,
|
|
570
|
+
const projection = (0, import_image_editor2.getViewportProjection)(s, viewRef.current.width, viewRef.current.height, cropping);
|
|
571
|
+
const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, cropping);
|
|
570
572
|
transformTool.setView(projection.scale);
|
|
571
573
|
return { pt, tolerance: 6 / (projection.scale || 1) };
|
|
572
574
|
};
|
|
@@ -616,24 +618,16 @@ var ImageEditorCanvas = ({
|
|
|
616
618
|
(0, import_react5.useEffect)(() => {
|
|
617
619
|
const container = containerRef.current;
|
|
618
620
|
if (!container) return;
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
});
|
|
623
|
-
observer.observe(container);
|
|
624
|
-
return () => observer.disconnect();
|
|
625
|
-
} else {
|
|
626
|
-
const handleResize = () => renderCanvas();
|
|
627
|
-
window.addEventListener("resize", handleResize);
|
|
628
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
629
|
-
}
|
|
621
|
+
const { width, height } = (0, import_image_editor2.measureCanvasViewport)(container);
|
|
622
|
+
viewRef.current = { width, height };
|
|
623
|
+
return (0, import_image_editor2.watchCanvasViewport)(container, () => renderCanvas());
|
|
630
624
|
}, [renderCanvas]);
|
|
631
625
|
const getCanvasEventPoint = (e) => {
|
|
632
626
|
const canvas = canvasRef.current;
|
|
633
627
|
if (!canvas) return { x: 0, y: 0 };
|
|
634
628
|
const rect = canvas.getBoundingClientRect();
|
|
635
|
-
const scaleX = rect.width > 0 ?
|
|
636
|
-
const scaleY = rect.height > 0 ?
|
|
629
|
+
const scaleX = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
630
|
+
const scaleY = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
637
631
|
return {
|
|
638
632
|
x: (e.clientX - rect.left) * scaleX,
|
|
639
633
|
y: (e.clientY - rect.top) * scaleY
|
|
@@ -645,11 +639,11 @@ var ImageEditorCanvas = ({
|
|
|
645
639
|
const events = typeof native.getCoalescedEvents === "function" ? native.getCoalescedEvents() : [];
|
|
646
640
|
const list = events.length ? events : [native];
|
|
647
641
|
const rect = canvas.getBoundingClientRect();
|
|
648
|
-
const sx = rect.width > 0 ?
|
|
649
|
-
const sy = rect.height > 0 ?
|
|
642
|
+
const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
643
|
+
const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
650
644
|
const s = controller.getState();
|
|
651
645
|
return list.map((ev) => ({
|
|
652
|
-
...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s,
|
|
646
|
+
...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, false),
|
|
653
647
|
pressure: (0, import_image_editor2.pointerPressure)(ev)
|
|
654
648
|
}));
|
|
655
649
|
};
|
|
@@ -695,7 +689,7 @@ var ImageEditorCanvas = ({
|
|
|
695
689
|
const canvasPt = getCanvasEventPoint(e);
|
|
696
690
|
if (mode === "select") {
|
|
697
691
|
const gesture = selectionGestureRef.current;
|
|
698
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
692
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
699
693
|
void gesture.begin(imgPt, e).then(() => report("select", gesture.error));
|
|
700
694
|
return;
|
|
701
695
|
}
|
|
@@ -706,8 +700,8 @@ var ImageEditorCanvas = ({
|
|
|
706
700
|
width: state.imageDimensions.width,
|
|
707
701
|
height: state.imageDimensions.height
|
|
708
702
|
};
|
|
709
|
-
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state,
|
|
710
|
-
const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
703
|
+
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
|
|
704
|
+
const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
|
|
711
705
|
if (handle) {
|
|
712
706
|
cropDragInfoRef.current = {
|
|
713
707
|
handle,
|
|
@@ -726,7 +720,7 @@ var ImageEditorCanvas = ({
|
|
|
726
720
|
return;
|
|
727
721
|
}
|
|
728
722
|
if (mode === "annotate" && (state.activeTool === "shape" || state.activeTool === "type")) {
|
|
729
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
723
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
730
724
|
report(state.activeTool, null);
|
|
731
725
|
if (state.activeTool === "shape") shapeGestureRef.current.down(imgPt);
|
|
732
726
|
else {
|
|
@@ -737,7 +731,7 @@ var ImageEditorCanvas = ({
|
|
|
737
731
|
return;
|
|
738
732
|
}
|
|
739
733
|
if (mode === "annotate") {
|
|
740
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
734
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
741
735
|
dragStartPointRef.current = imgPt;
|
|
742
736
|
if (state.activeTool === "select") {
|
|
743
737
|
for (let i = state.annotations.length - 1; i >= 0; i--) {
|
|
@@ -778,7 +772,7 @@ var ImageEditorCanvas = ({
|
|
|
778
772
|
const canvasPt = getCanvasEventPoint(e);
|
|
779
773
|
if (mode === "select") {
|
|
780
774
|
const gesture = selectionGestureRef.current;
|
|
781
|
-
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
775
|
+
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
|
|
782
776
|
selectionDraftRef.current = gesture.draftPath;
|
|
783
777
|
renderCanvas();
|
|
784
778
|
}
|
|
@@ -787,7 +781,7 @@ var ImageEditorCanvas = ({
|
|
|
787
781
|
if (mode === "crop") {
|
|
788
782
|
const drag = cropDragInfoRef.current;
|
|
789
783
|
if (drag) {
|
|
790
|
-
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
784
|
+
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
|
|
791
785
|
let newCrop;
|
|
792
786
|
if (drag.handle === "new") {
|
|
793
787
|
const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
|
|
@@ -821,7 +815,7 @@ var ImageEditorCanvas = ({
|
|
|
821
815
|
width: state.imageDimensions.width,
|
|
822
816
|
height: state.imageDimensions.height
|
|
823
817
|
};
|
|
824
|
-
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state,
|
|
818
|
+
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
|
|
825
819
|
canvas.style.cursor = (0, import_image_editor2.getCropCursor)(handle, state.transform);
|
|
826
820
|
}
|
|
827
821
|
return;
|
|
@@ -829,7 +823,7 @@ var ImageEditorCanvas = ({
|
|
|
829
823
|
if (mode === "annotate" && state.activeTool === "shape") {
|
|
830
824
|
const g = shapeGestureRef.current;
|
|
831
825
|
if (g.active) {
|
|
832
|
-
g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
826
|
+
g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), { shift: e.shiftKey, alt: e.altKey });
|
|
833
827
|
if (g.error) report("shape", g.error);
|
|
834
828
|
}
|
|
835
829
|
return;
|
|
@@ -837,7 +831,7 @@ var ImageEditorCanvas = ({
|
|
|
837
831
|
if (mode === "annotate") {
|
|
838
832
|
if (annotationDragInfoRef.current) {
|
|
839
833
|
const drag = annotationDragInfoRef.current;
|
|
840
|
-
const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
834
|
+
const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
841
835
|
const dx = currentImgPt2.x - drag.startImgPt.x;
|
|
842
836
|
const dy = currentImgPt2.y - drag.startImgPt.y;
|
|
843
837
|
editor.updateAnnotation(drag.annId, {
|
|
@@ -849,7 +843,7 @@ var ImageEditorCanvas = ({
|
|
|
849
843
|
const startPt = dragStartPointRef.current;
|
|
850
844
|
if (!startPt) {
|
|
851
845
|
if (state.activeTool === "select") {
|
|
852
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
846
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
853
847
|
let hovered = false;
|
|
854
848
|
for (let i = state.annotations.length - 1; i >= 0; i--) {
|
|
855
849
|
if ((0, import_image_editor2.hitTestAnnotation)(imgPt, state.annotations[i])) {
|
|
@@ -863,7 +857,7 @@ var ImageEditorCanvas = ({
|
|
|
863
857
|
}
|
|
864
858
|
return;
|
|
865
859
|
}
|
|
866
|
-
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
860
|
+
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
867
861
|
const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
|
|
868
862
|
if (state.activeTool === "pen" && isDrawingRef.current) {
|
|
869
863
|
currentPathRef.current.push(currentImgPt);
|
|
@@ -920,7 +914,7 @@ var ImageEditorCanvas = ({
|
|
|
920
914
|
if (mode === "select") {
|
|
921
915
|
const gesture = selectionGestureRef.current;
|
|
922
916
|
if (gesture.active) {
|
|
923
|
-
gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
917
|
+
gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
|
|
924
918
|
selectionDraftRef.current = null;
|
|
925
919
|
renderCanvas();
|
|
926
920
|
}
|
|
@@ -943,7 +937,7 @@ var ImageEditorCanvas = ({
|
|
|
943
937
|
}
|
|
944
938
|
if (mode === "annotate" && state.activeTool === "type") {
|
|
945
939
|
const tool = typeToolRef.current;
|
|
946
|
-
tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
940
|
+
tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false));
|
|
947
941
|
setTypeSession(tool.session);
|
|
948
942
|
if (tool.error) report("type", tool.error);
|
|
949
943
|
void renderCanvas();
|
|
@@ -957,7 +951,7 @@ var ImageEditorCanvas = ({
|
|
|
957
951
|
}
|
|
958
952
|
const startPt = dragStartPointRef.current;
|
|
959
953
|
if (startPt) {
|
|
960
|
-
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
954
|
+
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
961
955
|
const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
|
|
962
956
|
if (state.activeTool === "pen" && isDrawingRef.current) {
|
|
963
957
|
if (currentPathRef.current.length > 1) {
|
|
@@ -1024,7 +1018,7 @@ var ImageEditorCanvas = ({
|
|
|
1024
1018
|
onPointerUp: handlePaintPointerUp,
|
|
1025
1019
|
onPointerCancel: () => paintGestureRef.current?.cancel(),
|
|
1026
1020
|
"data-testid": "image-editor-canvas",
|
|
1027
|
-
style: transformTool.active ? { cursor: transformCursor } :
|
|
1021
|
+
style: transformTool.active ? { width: "100%", height: "100%", cursor: transformCursor } : { width: "100%", height: "100%" },
|
|
1028
1022
|
className: `absolute inset-0 w-full h-full block ${transformTool.active ? "touch-none" : mode === "paint" ? "touch-none cursor-crosshair" : mode === "annotate" && state.activeTool === "type" ? "cursor-text" : mode === "annotate" && state.activeTool === "shape" ? "cursor-crosshair" : ""}`
|
|
1029
1023
|
}
|
|
1030
1024
|
),
|
|
@@ -4016,7 +4010,7 @@ var BrushOptionsBar = ({ controller, className }) => {
|
|
|
4016
4010
|
setError(null);
|
|
4017
4011
|
fn();
|
|
4018
4012
|
} catch (err) {
|
|
4019
|
-
setError(
|
|
4013
|
+
setError((0, import_image_editor12.userErrorMessage)(err));
|
|
4020
4014
|
}
|
|
4021
4015
|
};
|
|
4022
4016
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: `flex flex-col gap-2 text-xs text-foreground ${className ?? ""}`, "data-testid": "brush-options", children: [
|
package/dist/index.cjs
CHANGED
|
@@ -4045,6 +4045,7 @@ var ImageEditorCanvas = ({
|
|
|
4045
4045
|
const canvasRef = (0, import_react40.useRef)(null);
|
|
4046
4046
|
const containerRef = (0, import_react40.useRef)(null);
|
|
4047
4047
|
const rootRef = (0, import_react40.useRef)(null);
|
|
4048
|
+
const viewRef = (0, import_react40.useRef)({ width: 0, height: 0 });
|
|
4048
4049
|
const modeRef = (0, import_react40.useRef)(mode);
|
|
4049
4050
|
modeRef.current = mode;
|
|
4050
4051
|
const latest = (0, import_react40.useRef)({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
|
|
@@ -4056,19 +4057,19 @@ var ImageEditorCanvas = ({
|
|
|
4056
4057
|
const docToRoot = (p) => {
|
|
4057
4058
|
const canvas = canvasRef.current;
|
|
4058
4059
|
const root = rootRef.current;
|
|
4059
|
-
if (!canvas || !root || !
|
|
4060
|
+
if (!canvas || !root || !viewRef.current.width) return p;
|
|
4060
4061
|
const r = canvas.getBoundingClientRect();
|
|
4061
4062
|
const box = root.getBoundingClientRect();
|
|
4062
|
-
const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(),
|
|
4063
|
-
return { x: r.left - box.left + c.x * r.width /
|
|
4063
|
+
const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
|
|
4064
|
+
return { x: r.left - box.left + c.x * r.width / viewRef.current.width, y: r.top - box.top + c.y * r.height / viewRef.current.height };
|
|
4064
4065
|
};
|
|
4065
4066
|
const clientToDoc = (p) => {
|
|
4066
4067
|
const canvas = canvasRef.current;
|
|
4067
|
-
if (!canvas || !
|
|
4068
|
+
if (!canvas || !viewRef.current.width) return p;
|
|
4068
4069
|
const r = canvas.getBoundingClientRect();
|
|
4069
|
-
const sx = r.width > 0 ?
|
|
4070
|
-
const sy = r.height > 0 ?
|
|
4071
|
-
return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(),
|
|
4070
|
+
const sx = r.width > 0 ? viewRef.current.width / r.width : 1;
|
|
4071
|
+
const sy = r.height > 0 ? viewRef.current.height / r.height : 1;
|
|
4072
|
+
return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
|
|
4072
4073
|
};
|
|
4073
4074
|
const clientRect = (r) => {
|
|
4074
4075
|
if (!r || r.width <= 0) return null;
|
|
@@ -4167,11 +4168,12 @@ var ImageEditorCanvas = ({
|
|
|
4167
4168
|
const canvas = canvasRef.current;
|
|
4168
4169
|
const container = containerRef.current;
|
|
4169
4170
|
if (!canvas || !container) return;
|
|
4170
|
-
const
|
|
4171
|
-
|
|
4171
|
+
const viewport = (0, import_image_editor2.measureCanvasViewport)(container);
|
|
4172
|
+
viewRef.current = { width: viewport.width, height: viewport.height };
|
|
4172
4173
|
await controller.render(canvas, {
|
|
4173
|
-
viewportWidth:
|
|
4174
|
-
viewportHeight:
|
|
4174
|
+
viewportWidth: viewport.width,
|
|
4175
|
+
viewportHeight: viewport.height,
|
|
4176
|
+
pixelRatio: viewport.pixelRatio,
|
|
4175
4177
|
fit,
|
|
4176
4178
|
showCropOverlay: mode === "crop",
|
|
4177
4179
|
showSelectionOverlay: true,
|
|
@@ -4254,12 +4256,12 @@ var ImageEditorCanvas = ({
|
|
|
4254
4256
|
const transformPoint = (e) => {
|
|
4255
4257
|
const canvas = canvasRef.current;
|
|
4256
4258
|
const rect = canvas.getBoundingClientRect();
|
|
4257
|
-
const sx = rect.width > 0 ?
|
|
4258
|
-
const sy = rect.height > 0 ?
|
|
4259
|
+
const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
4260
|
+
const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
4259
4261
|
const s = controller.getState();
|
|
4260
4262
|
const cropping = mode === "crop";
|
|
4261
|
-
const projection = (0, import_image_editor2.getViewportProjection)(s,
|
|
4262
|
-
const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s,
|
|
4263
|
+
const projection = (0, import_image_editor2.getViewportProjection)(s, viewRef.current.width, viewRef.current.height, cropping);
|
|
4264
|
+
const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, cropping);
|
|
4263
4265
|
transformTool.setView(projection.scale);
|
|
4264
4266
|
return { pt, tolerance: 6 / (projection.scale || 1) };
|
|
4265
4267
|
};
|
|
@@ -4309,24 +4311,16 @@ var ImageEditorCanvas = ({
|
|
|
4309
4311
|
(0, import_react40.useEffect)(() => {
|
|
4310
4312
|
const container = containerRef.current;
|
|
4311
4313
|
if (!container) return;
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
});
|
|
4316
|
-
observer.observe(container);
|
|
4317
|
-
return () => observer.disconnect();
|
|
4318
|
-
} else {
|
|
4319
|
-
const handleResize = () => renderCanvas();
|
|
4320
|
-
window.addEventListener("resize", handleResize);
|
|
4321
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
4322
|
-
}
|
|
4314
|
+
const { width, height } = (0, import_image_editor2.measureCanvasViewport)(container);
|
|
4315
|
+
viewRef.current = { width, height };
|
|
4316
|
+
return (0, import_image_editor2.watchCanvasViewport)(container, () => renderCanvas());
|
|
4323
4317
|
}, [renderCanvas]);
|
|
4324
4318
|
const getCanvasEventPoint = (e) => {
|
|
4325
4319
|
const canvas = canvasRef.current;
|
|
4326
4320
|
if (!canvas) return { x: 0, y: 0 };
|
|
4327
4321
|
const rect = canvas.getBoundingClientRect();
|
|
4328
|
-
const scaleX = rect.width > 0 ?
|
|
4329
|
-
const scaleY = rect.height > 0 ?
|
|
4322
|
+
const scaleX = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
4323
|
+
const scaleY = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
4330
4324
|
return {
|
|
4331
4325
|
x: (e.clientX - rect.left) * scaleX,
|
|
4332
4326
|
y: (e.clientY - rect.top) * scaleY
|
|
@@ -4338,11 +4332,11 @@ var ImageEditorCanvas = ({
|
|
|
4338
4332
|
const events = typeof native.getCoalescedEvents === "function" ? native.getCoalescedEvents() : [];
|
|
4339
4333
|
const list = events.length ? events : [native];
|
|
4340
4334
|
const rect = canvas.getBoundingClientRect();
|
|
4341
|
-
const sx = rect.width > 0 ?
|
|
4342
|
-
const sy = rect.height > 0 ?
|
|
4335
|
+
const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
|
|
4336
|
+
const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
|
|
4343
4337
|
const s = controller.getState();
|
|
4344
4338
|
return list.map((ev) => ({
|
|
4345
|
-
...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s,
|
|
4339
|
+
...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, false),
|
|
4346
4340
|
pressure: (0, import_image_editor2.pointerPressure)(ev)
|
|
4347
4341
|
}));
|
|
4348
4342
|
};
|
|
@@ -4388,7 +4382,7 @@ var ImageEditorCanvas = ({
|
|
|
4388
4382
|
const canvasPt = getCanvasEventPoint(e);
|
|
4389
4383
|
if (mode === "select") {
|
|
4390
4384
|
const gesture = selectionGestureRef.current;
|
|
4391
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4385
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4392
4386
|
void gesture.begin(imgPt, e).then(() => report("select", gesture.error));
|
|
4393
4387
|
return;
|
|
4394
4388
|
}
|
|
@@ -4399,8 +4393,8 @@ var ImageEditorCanvas = ({
|
|
|
4399
4393
|
width: state.imageDimensions.width,
|
|
4400
4394
|
height: state.imageDimensions.height
|
|
4401
4395
|
};
|
|
4402
|
-
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state,
|
|
4403
|
-
const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4396
|
+
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
|
|
4397
|
+
const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
|
|
4404
4398
|
if (handle) {
|
|
4405
4399
|
cropDragInfoRef.current = {
|
|
4406
4400
|
handle,
|
|
@@ -4419,7 +4413,7 @@ var ImageEditorCanvas = ({
|
|
|
4419
4413
|
return;
|
|
4420
4414
|
}
|
|
4421
4415
|
if (mode === "annotate" && (state.activeTool === "shape" || state.activeTool === "type")) {
|
|
4422
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4416
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4423
4417
|
report(state.activeTool, null);
|
|
4424
4418
|
if (state.activeTool === "shape") shapeGestureRef.current.down(imgPt);
|
|
4425
4419
|
else {
|
|
@@ -4430,7 +4424,7 @@ var ImageEditorCanvas = ({
|
|
|
4430
4424
|
return;
|
|
4431
4425
|
}
|
|
4432
4426
|
if (mode === "annotate") {
|
|
4433
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4427
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4434
4428
|
dragStartPointRef.current = imgPt;
|
|
4435
4429
|
if (state.activeTool === "select") {
|
|
4436
4430
|
for (let i = state.annotations.length - 1; i >= 0; i--) {
|
|
@@ -4471,7 +4465,7 @@ var ImageEditorCanvas = ({
|
|
|
4471
4465
|
const canvasPt = getCanvasEventPoint(e);
|
|
4472
4466
|
if (mode === "select") {
|
|
4473
4467
|
const gesture = selectionGestureRef.current;
|
|
4474
|
-
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4468
|
+
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
|
|
4475
4469
|
selectionDraftRef.current = gesture.draftPath;
|
|
4476
4470
|
renderCanvas();
|
|
4477
4471
|
}
|
|
@@ -4480,7 +4474,7 @@ var ImageEditorCanvas = ({
|
|
|
4480
4474
|
if (mode === "crop") {
|
|
4481
4475
|
const drag = cropDragInfoRef.current;
|
|
4482
4476
|
if (drag) {
|
|
4483
|
-
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4477
|
+
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
|
|
4484
4478
|
let newCrop;
|
|
4485
4479
|
if (drag.handle === "new") {
|
|
4486
4480
|
const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
|
|
@@ -4514,7 +4508,7 @@ var ImageEditorCanvas = ({
|
|
|
4514
4508
|
width: state.imageDimensions.width,
|
|
4515
4509
|
height: state.imageDimensions.height
|
|
4516
4510
|
};
|
|
4517
|
-
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state,
|
|
4511
|
+
const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
|
|
4518
4512
|
canvas.style.cursor = (0, import_image_editor2.getCropCursor)(handle, state.transform);
|
|
4519
4513
|
}
|
|
4520
4514
|
return;
|
|
@@ -4522,7 +4516,7 @@ var ImageEditorCanvas = ({
|
|
|
4522
4516
|
if (mode === "annotate" && state.activeTool === "shape") {
|
|
4523
4517
|
const g = shapeGestureRef.current;
|
|
4524
4518
|
if (g.active) {
|
|
4525
|
-
g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4519
|
+
g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), { shift: e.shiftKey, alt: e.altKey });
|
|
4526
4520
|
if (g.error) report("shape", g.error);
|
|
4527
4521
|
}
|
|
4528
4522
|
return;
|
|
@@ -4530,7 +4524,7 @@ var ImageEditorCanvas = ({
|
|
|
4530
4524
|
if (mode === "annotate") {
|
|
4531
4525
|
if (annotationDragInfoRef.current) {
|
|
4532
4526
|
const drag = annotationDragInfoRef.current;
|
|
4533
|
-
const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4527
|
+
const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4534
4528
|
const dx = currentImgPt2.x - drag.startImgPt.x;
|
|
4535
4529
|
const dy = currentImgPt2.y - drag.startImgPt.y;
|
|
4536
4530
|
editor.updateAnnotation(drag.annId, {
|
|
@@ -4542,7 +4536,7 @@ var ImageEditorCanvas = ({
|
|
|
4542
4536
|
const startPt = dragStartPointRef.current;
|
|
4543
4537
|
if (!startPt) {
|
|
4544
4538
|
if (state.activeTool === "select") {
|
|
4545
|
-
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4539
|
+
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4546
4540
|
let hovered = false;
|
|
4547
4541
|
for (let i = state.annotations.length - 1; i >= 0; i--) {
|
|
4548
4542
|
if ((0, import_image_editor2.hitTestAnnotation)(imgPt, state.annotations[i])) {
|
|
@@ -4556,7 +4550,7 @@ var ImageEditorCanvas = ({
|
|
|
4556
4550
|
}
|
|
4557
4551
|
return;
|
|
4558
4552
|
}
|
|
4559
|
-
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4553
|
+
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4560
4554
|
const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
|
|
4561
4555
|
if (state.activeTool === "pen" && isDrawingRef.current) {
|
|
4562
4556
|
currentPathRef.current.push(currentImgPt);
|
|
@@ -4613,7 +4607,7 @@ var ImageEditorCanvas = ({
|
|
|
4613
4607
|
if (mode === "select") {
|
|
4614
4608
|
const gesture = selectionGestureRef.current;
|
|
4615
4609
|
if (gesture.active) {
|
|
4616
|
-
gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4610
|
+
gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
|
|
4617
4611
|
selectionDraftRef.current = null;
|
|
4618
4612
|
renderCanvas();
|
|
4619
4613
|
}
|
|
@@ -4636,7 +4630,7 @@ var ImageEditorCanvas = ({
|
|
|
4636
4630
|
}
|
|
4637
4631
|
if (mode === "annotate" && state.activeTool === "type") {
|
|
4638
4632
|
const tool = typeToolRef.current;
|
|
4639
|
-
tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4633
|
+
tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false));
|
|
4640
4634
|
setTypeSession(tool.session);
|
|
4641
4635
|
if (tool.error) report("type", tool.error);
|
|
4642
4636
|
void renderCanvas();
|
|
@@ -4650,7 +4644,7 @@ var ImageEditorCanvas = ({
|
|
|
4650
4644
|
}
|
|
4651
4645
|
const startPt = dragStartPointRef.current;
|
|
4652
4646
|
if (startPt) {
|
|
4653
|
-
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state,
|
|
4647
|
+
const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4654
4648
|
const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
|
|
4655
4649
|
if (state.activeTool === "pen" && isDrawingRef.current) {
|
|
4656
4650
|
if (currentPathRef.current.length > 1) {
|
|
@@ -4717,7 +4711,7 @@ var ImageEditorCanvas = ({
|
|
|
4717
4711
|
onPointerUp: handlePaintPointerUp,
|
|
4718
4712
|
onPointerCancel: () => paintGestureRef.current?.cancel(),
|
|
4719
4713
|
"data-testid": "image-editor-canvas",
|
|
4720
|
-
style: transformTool.active ? { cursor: transformCursor } :
|
|
4714
|
+
style: transformTool.active ? { width: "100%", height: "100%", cursor: transformCursor } : { width: "100%", height: "100%" },
|
|
4721
4715
|
className: `absolute inset-0 w-full h-full block ${transformTool.active ? "touch-none" : mode === "paint" ? "touch-none cursor-crosshair" : mode === "annotate" && state.activeTool === "type" ? "cursor-text" : mode === "annotate" && state.activeTool === "shape" ? "cursor-crosshair" : ""}`
|
|
4722
4716
|
}
|
|
4723
4717
|
),
|
|
@@ -7709,7 +7703,7 @@ var BrushOptionsBar = ({ controller, className }) => {
|
|
|
7709
7703
|
setError(null);
|
|
7710
7704
|
fn();
|
|
7711
7705
|
} catch (err) {
|
|
7712
|
-
setError(
|
|
7706
|
+
setError((0, import_image_editor12.userErrorMessage)(err));
|
|
7713
7707
|
}
|
|
7714
7708
|
};
|
|
7715
7709
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: `flex flex-col gap-2 text-xs text-foreground ${className ?? ""}`, "data-testid": "brush-options", children: [
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ChartDataGrid,
|
|
7
7
|
ChartInspector,
|
|
8
8
|
chartButtonClass
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ZHMATFBB.js";
|
|
10
10
|
import {
|
|
11
11
|
FormulaHints,
|
|
12
12
|
NameManager,
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
useImageEditor,
|
|
45
45
|
useImageEffectsTools,
|
|
46
46
|
useImageHistogram
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-GJ2TYERJ.js";
|
|
48
48
|
import "./chunk-AJCWF6SN.js";
|
|
49
49
|
import "./chunk-Q7LAFHGP.js";
|
|
50
50
|
import "./chunk-5LFQ2UQZ.js";
|
|
@@ -92,7 +92,9 @@ function useParameters(controllerOrOptions) {
|
|
|
92
92
|
}),
|
|
93
93
|
[controller]
|
|
94
94
|
);
|
|
95
|
-
|
|
95
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_parameters.createParametersEditorDocument)(controller), [controller]);
|
|
96
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
97
|
+
return { controller, editorDocument, state, values: state.values, ...actions };
|
|
96
98
|
}
|
|
97
99
|
function useParameterCommands(registry, controller, options = {}) {
|
|
98
100
|
const { prefix, group, scope } = options;
|
package/dist/parameters/index.js
CHANGED
|
@@ -27,7 +27,8 @@ import {
|
|
|
27
27
|
import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
28
28
|
import {
|
|
29
29
|
ParametersController,
|
|
30
|
-
createParameterCommands
|
|
30
|
+
createParameterCommands,
|
|
31
|
+
createParametersEditorDocument
|
|
31
32
|
} from "@pixerate/editor/parameters";
|
|
32
33
|
function useParametersController(options) {
|
|
33
34
|
const ref = useRef(null);
|
|
@@ -66,7 +67,9 @@ function useParameters(controllerOrOptions) {
|
|
|
66
67
|
}),
|
|
67
68
|
[controller]
|
|
68
69
|
);
|
|
69
|
-
|
|
70
|
+
const editorDocument = useMemo(() => createParametersEditorDocument(controller), [controller]);
|
|
71
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
72
|
+
return { controller, editorDocument, state, values: state.values, ...actions };
|
|
70
73
|
}
|
|
71
74
|
function useParameterCommands(registry, controller, options = {}) {
|
|
72
75
|
const { prefix, group, scope } = options;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ParametersController, type ParameterCommandOptions, type ParametersControllerOptions, type ParametersState, type ParameterValue, type ParameterSetResult } from '@pixerate/editor/parameters';
|
|
1
|
+
import { ParametersController, type ParameterCommandOptions, type ParametersControllerOptions, type ParametersState, type ParameterValue, type ParameterSetResult, type ParametersSnapshot } from '@pixerate/editor/parameters';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
/**
|
|
3
4
|
* A `ParametersController` created once for the component's lifetime. When `options.schema`
|
|
4
5
|
* changes (a new object), the controller's schema is replaced and fitting values are kept.
|
|
@@ -8,6 +9,8 @@ export declare function useParametersController(options: ParametersControllerOpt
|
|
|
8
9
|
export declare function useParametersState(controller: ParametersController): ParametersState;
|
|
9
10
|
export interface UseParametersResult {
|
|
10
11
|
controller: ParametersController;
|
|
12
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
13
|
+
editorDocument: EditorDocument<ParametersSnapshot>;
|
|
11
14
|
state: ParametersState;
|
|
12
15
|
values: ParametersState['values'];
|
|
13
16
|
setValue: (id: string, value: ParameterValue) => ParameterSetResult;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ParametersController, type ParameterCommandOptions, type ParametersControllerOptions, type ParametersState, type ParameterValue, type ParameterSetResult } from '@pixerate/editor/parameters';
|
|
1
|
+
import { ParametersController, type ParameterCommandOptions, type ParametersControllerOptions, type ParametersState, type ParameterValue, type ParameterSetResult, type ParametersSnapshot } from '@pixerate/editor/parameters';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
/**
|
|
3
4
|
* A `ParametersController` created once for the component's lifetime. When `options.schema`
|
|
4
5
|
* changes (a new object), the controller's schema is replaced and fitting values are kept.
|
|
@@ -8,6 +9,8 @@ export declare function useParametersController(options: ParametersControllerOpt
|
|
|
8
9
|
export declare function useParametersState(controller: ParametersController): ParametersState;
|
|
9
10
|
export interface UseParametersResult {
|
|
10
11
|
controller: ParametersController;
|
|
12
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
13
|
+
editorDocument: EditorDocument<ParametersSnapshot>;
|
|
11
14
|
state: ParametersState;
|
|
12
15
|
values: ParametersState['values'];
|
|
13
16
|
setValue: (id: string, value: ParameterValue) => ParameterSetResult;
|
package/dist/vector/index.cjs
CHANGED
|
@@ -101,7 +101,9 @@ function useVectorEditor(controllerOrOptions = {}) {
|
|
|
101
101
|
}),
|
|
102
102
|
[controller]
|
|
103
103
|
);
|
|
104
|
-
|
|
104
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_vector.createVectorEditorDocument)(controller), [controller]);
|
|
105
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
106
|
+
return { controller, editorDocument, state, ...actions };
|
|
105
107
|
}
|
|
106
108
|
function useVectorCommands(registry, controller, options = {}) {
|
|
107
109
|
const { prefix, group, scope } = options;
|
package/dist/vector/index.js
CHANGED
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
VectorEditorController,
|
|
20
20
|
createVectorCommands,
|
|
21
21
|
createVectorEffectsToolProvider,
|
|
22
|
-
createVectorGenerationToolProvider
|
|
22
|
+
createVectorGenerationToolProvider,
|
|
23
|
+
createVectorEditorDocument
|
|
23
24
|
} from "@pixerate/editor/vector";
|
|
24
25
|
function useVectorEditorController(options = {}) {
|
|
25
26
|
const ref = useRef(null);
|
|
@@ -50,7 +51,9 @@ function useVectorEditor(controllerOrOptions = {}) {
|
|
|
50
51
|
}),
|
|
51
52
|
[controller]
|
|
52
53
|
);
|
|
53
|
-
|
|
54
|
+
const editorDocument = useMemo(() => createVectorEditorDocument(controller), [controller]);
|
|
55
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
56
|
+
return { controller, editorDocument, state, ...actions };
|
|
54
57
|
}
|
|
55
58
|
function useVectorCommands(registry, controller, options = {}) {
|
|
56
59
|
const { prefix, group, scope } = options;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { VectorEditorController, type VectorEffectsToolProviderOptions, type VectorGenerationToolProviderOptions, type VectorCommandOptions, type VectorEditorOptions, type VectorEditorState, type VectorTool } from '@pixerate/editor/vector';
|
|
1
|
+
import { VectorEditorController, type VectorEffectsToolProviderOptions, type VectorGenerationToolProviderOptions, type VectorCommandOptions, type VectorEditorOptions, type VectorEditorState, type VectorTool, type VectorDocument } from '@pixerate/editor/vector';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
3
4
|
/** A `VectorEditorController` created once for the component's lifetime (destroyed on unmount). */
|
|
4
5
|
export declare function useVectorEditorController(options?: VectorEditorOptions): VectorEditorController;
|
|
@@ -6,6 +7,8 @@ export declare function useVectorEditorController(options?: VectorEditorOptions)
|
|
|
6
7
|
export declare function useVectorEditorState(controller: VectorEditorController): VectorEditorState;
|
|
7
8
|
export interface UseVectorEditorResult {
|
|
8
9
|
controller: VectorEditorController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<VectorDocument>;
|
|
9
12
|
state: VectorEditorState;
|
|
10
13
|
setTool: (tool: VectorTool) => void;
|
|
11
14
|
undo: () => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { VectorEditorController, type VectorEffectsToolProviderOptions, type VectorGenerationToolProviderOptions, type VectorCommandOptions, type VectorEditorOptions, type VectorEditorState, type VectorTool } from '@pixerate/editor/vector';
|
|
1
|
+
import { VectorEditorController, type VectorEffectsToolProviderOptions, type VectorGenerationToolProviderOptions, type VectorCommandOptions, type VectorEditorOptions, type VectorEditorState, type VectorTool, type VectorDocument } from '@pixerate/editor/vector';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
3
4
|
/** A `VectorEditorController` created once for the component's lifetime (destroyed on unmount). */
|
|
4
5
|
export declare function useVectorEditorController(options?: VectorEditorOptions): VectorEditorController;
|
|
@@ -6,6 +7,8 @@ export declare function useVectorEditorController(options?: VectorEditorOptions)
|
|
|
6
7
|
export declare function useVectorEditorState(controller: VectorEditorController): VectorEditorState;
|
|
7
8
|
export interface UseVectorEditorResult {
|
|
8
9
|
controller: VectorEditorController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<VectorDocument>;
|
|
9
12
|
state: VectorEditorState;
|
|
10
13
|
setTool: (tool: VectorTool) => void;
|
|
11
14
|
undo: () => void;
|
|
@@ -85,7 +85,9 @@ function useVideoEditor(controllerOrOptions = {}) {
|
|
|
85
85
|
}),
|
|
86
86
|
[controller]
|
|
87
87
|
);
|
|
88
|
-
|
|
88
|
+
const editorDocument = (0, import_react.useMemo)(() => (0, import_video_editor.createVideoEditorDocument)(controller), [controller]);
|
|
89
|
+
(0, import_react.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
90
|
+
return { controller, editorDocument, state, ...actions };
|
|
89
91
|
}
|
|
90
92
|
function useVideoEditorTools(registry, controller, options = {}) {
|
|
91
93
|
const { id, namespace, readOnly, rasterize, framePixels, framePixelsTimeout, playbackSurface } = options;
|
|
@@ -18,7 +18,8 @@ import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
|
18
18
|
import {
|
|
19
19
|
VideoEditorController,
|
|
20
20
|
createVideoEditorToolProvider,
|
|
21
|
-
createVideoEffectsToolProvider
|
|
21
|
+
createVideoEffectsToolProvider,
|
|
22
|
+
createVideoEditorDocument
|
|
22
23
|
} from "@pixerate/editor/video-editor";
|
|
23
24
|
function useVideoEditorController(options = {}) {
|
|
24
25
|
const ref = useRef(null);
|
|
@@ -54,7 +55,9 @@ function useVideoEditor(controllerOrOptions = {}) {
|
|
|
54
55
|
}),
|
|
55
56
|
[controller]
|
|
56
57
|
);
|
|
57
|
-
|
|
58
|
+
const editorDocument = useMemo(() => createVideoEditorDocument(controller), [controller]);
|
|
59
|
+
useEffect(() => () => editorDocument.destroy(), [editorDocument]);
|
|
60
|
+
return { controller, editorDocument, state, ...actions };
|
|
58
61
|
}
|
|
59
62
|
function useVideoEditorTools(registry, controller, options = {}) {
|
|
60
63
|
const { id, namespace, readOnly, rasterize, framePixels, framePixelsTimeout, playbackSurface } = options;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { VideoEditorController, type VideoEffectsToolProviderOptions, type VideoEditResult, type VideoEditorOptions, type VideoEditorState, type VideoEditorToolProviderOptions } from '@pixerate/editor/video-editor';
|
|
1
|
+
import { VideoEditorController, type VideoEffectsToolProviderOptions, type VideoEditResult, type VideoEditorOptions, type VideoEditorState, type VideoEditorToolProviderOptions, type VideoProject } from '@pixerate/editor/video-editor';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
3
4
|
/** A `VideoEditorController` created once for the component's lifetime (destroyed on unmount). */
|
|
4
5
|
export declare function useVideoEditorController(options?: VideoEditorOptions): VideoEditorController;
|
|
@@ -6,6 +7,8 @@ export declare function useVideoEditorController(options?: VideoEditorOptions):
|
|
|
6
7
|
export declare function useVideoEditorState(controller: VideoEditorController): VideoEditorState;
|
|
7
8
|
export interface UseVideoEditorResult {
|
|
8
9
|
controller: VideoEditorController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<VideoProject>;
|
|
9
12
|
state: VideoEditorState;
|
|
10
13
|
play: () => void;
|
|
11
14
|
pause: () => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { VideoEditorController, type VideoEffectsToolProviderOptions, type VideoEditResult, type VideoEditorOptions, type VideoEditorState, type VideoEditorToolProviderOptions } from '@pixerate/editor/video-editor';
|
|
1
|
+
import { VideoEditorController, type VideoEffectsToolProviderOptions, type VideoEditResult, type VideoEditorOptions, type VideoEditorState, type VideoEditorToolProviderOptions, type VideoProject } from '@pixerate/editor/video-editor';
|
|
2
|
+
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
2
3
|
import type { ToolRegistry } from '@pixerate/editor/tools';
|
|
3
4
|
/** A `VideoEditorController` created once for the component's lifetime (destroyed on unmount). */
|
|
4
5
|
export declare function useVideoEditorController(options?: VideoEditorOptions): VideoEditorController;
|
|
@@ -6,6 +7,8 @@ export declare function useVideoEditorController(options?: VideoEditorOptions):
|
|
|
6
7
|
export declare function useVideoEditorState(controller: VideoEditorController): VideoEditorState;
|
|
7
8
|
export interface UseVideoEditorResult {
|
|
8
9
|
controller: VideoEditorController;
|
|
10
|
+
/** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
|
|
11
|
+
editorDocument: EditorDocument<VideoProject>;
|
|
9
12
|
state: VideoEditorState;
|
|
10
13
|
play: () => void;
|
|
11
14
|
pause: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
},
|
|
246
246
|
"peerDependencies": {
|
|
247
247
|
"@dagrejs/dagre": "^1.1.8",
|
|
248
|
-
"@pixerate/editor": ">=0.
|
|
248
|
+
"@pixerate/editor": ">=0.151.0 <1.0.0-0",
|
|
249
249
|
"@tiptap/core": "^2.27.3",
|
|
250
250
|
"@tiptap/pm": "^2.27.3",
|
|
251
251
|
"@tiptap/react": "^2.27.3",
|
|
@@ -267,12 +267,12 @@
|
|
|
267
267
|
"@tiptap/react": "^2.27.3",
|
|
268
268
|
"@types/react": "^19.3.0",
|
|
269
269
|
"@types/react-dom": "^19.3.0",
|
|
270
|
-
"react": "^19.3.
|
|
271
|
-
"react-dom": "^19.3.
|
|
270
|
+
"react": "^19.3.1",
|
|
271
|
+
"react-dom": "^19.3.1",
|
|
272
272
|
"tsup": "^9.0.0",
|
|
273
273
|
"typescript": "^5.7.3",
|
|
274
274
|
"vitest": "^5.0.5",
|
|
275
|
-
"@pixerate/editor": "0.
|
|
275
|
+
"@pixerate/editor": "0.151.0"
|
|
276
276
|
},
|
|
277
277
|
"scripts": {
|
|
278
278
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|