@bwp-web/canvas 0.8.3 → 0.9.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/context/CanvasRefContext.d.ts +17 -0
- package/dist/context/CanvasRefContext.d.ts.map +1 -0
- package/dist/context/EditCanvasContext.d.ts +37 -5
- package/dist/context/EditCanvasContext.d.ts.map +1 -1
- package/dist/context/ViewCanvasContext.d.ts +37 -5
- package/dist/context/ViewCanvasContext.d.ts.map +1 -1
- package/dist/context/index.d.ts +4 -4
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/useCanvasRef.d.ts +4 -2
- package/dist/context/useCanvasRef.d.ts.map +1 -1
- package/dist/hooks/useViewCanvas.d.ts +2 -0
- package/dist/hooks/useViewCanvas.d.ts.map +1 -1
- package/dist/index.cjs +194 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +163 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { Canvas as FabricCanvas } from 'fabric';
|
|
3
|
+
/**
|
|
4
|
+
* Shared context for the canvas ref. Provided by both
|
|
5
|
+
* {@link EditCanvasProvider} and {@link ViewCanvasProvider}.
|
|
6
|
+
*
|
|
7
|
+
* The value is a stable `RefObject` that never changes identity after
|
|
8
|
+
* mount, so consumers of this context will **not** re-render when
|
|
9
|
+
* canvas state (zoom, selection, etc.) changes.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CanvasRefContext: import("react").Context<RefObject<FabricCanvas | null> | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Read `canvasRef` from the nearest {@link CanvasRefContext} provider.
|
|
14
|
+
* Returns `null` if no provider is present.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useCanvasRefContext(): RefObject<FabricCanvas | null> | null;
|
|
17
|
+
//# sourceMappingURL=CanvasRefContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasRefContext.d.ts","sourceRoot":"","sources":["../../src/context/CanvasRefContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,gEAC+B,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,IAAI,CAE3E"}
|
|
@@ -2,6 +2,10 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import { useEditCanvas, type UseEditCanvasOptions } from '../hooks/useEditCanvas';
|
|
3
3
|
/** The full return value of {@link useEditCanvas}, exposed via context. */
|
|
4
4
|
export type EditCanvasContextValue = ReturnType<typeof useEditCanvas>;
|
|
5
|
+
/** Viewport slice — changes on every zoom/scroll. */
|
|
6
|
+
export type EditCanvasViewportValue = Pick<EditCanvasContextValue, 'zoom' | 'viewport'>;
|
|
7
|
+
/** State slice — everything except canvasRef and viewport. */
|
|
8
|
+
export type EditCanvasStateValue = Omit<EditCanvasContextValue, 'canvasRef' | 'zoom' | 'viewport'>;
|
|
5
9
|
export interface EditCanvasProviderProps {
|
|
6
10
|
/** Options forwarded to the underlying {@link useEditCanvas} hook. */
|
|
7
11
|
options?: UseEditCanvasOptions;
|
|
@@ -11,10 +15,14 @@ export interface EditCanvasProviderProps {
|
|
|
11
15
|
* Calls {@link useEditCanvas} internally and provides the full canvas API
|
|
12
16
|
* to all descendants via React context.
|
|
13
17
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Internally splits state into three contexts (ref, viewport, state) so
|
|
19
|
+
* that helper hooks like {@link useCanvasRef} and components like
|
|
20
|
+
* {@link ObjectOverlay} do not re-render on unrelated state changes.
|
|
21
|
+
*
|
|
22
|
+
* Use {@link useEditCanvasContext} in any descendant to access the full
|
|
23
|
+
* combined value, or use the fine-grained hooks
|
|
24
|
+
* {@link useEditCanvasViewport} / {@link useEditCanvasState} for better
|
|
25
|
+
* performance.
|
|
18
26
|
*
|
|
19
27
|
* Descendant components can also use {@link ObjectOverlay},
|
|
20
28
|
* {@link useCanvasEvents}, {@link useCanvasTooltip}, and
|
|
@@ -40,7 +48,7 @@ export interface EditCanvasProviderProps {
|
|
|
40
48
|
* }
|
|
41
49
|
*
|
|
42
50
|
* function MySidebar() {
|
|
43
|
-
* const { isDirty, resetDirty } =
|
|
51
|
+
* const { isDirty, resetDirty } = useEditCanvasState();
|
|
44
52
|
* return <SaveButton disabled={!isDirty} onClick={() => { save(); resetDirty(); }} />;
|
|
45
53
|
* }
|
|
46
54
|
* ```
|
|
@@ -50,6 +58,10 @@ export declare function EditCanvasProvider({ options, children, }: EditCanvasPro
|
|
|
50
58
|
* Access the full {@link useEditCanvas} API from any descendant of
|
|
51
59
|
* {@link EditCanvasProvider}.
|
|
52
60
|
*
|
|
61
|
+
* This subscribes to all three internal contexts, so the component will
|
|
62
|
+
* re-render on any state change. For better performance, prefer
|
|
63
|
+
* {@link useEditCanvasViewport} or {@link useEditCanvasState}.
|
|
64
|
+
*
|
|
53
65
|
* Throws if called outside of a provider.
|
|
54
66
|
*/
|
|
55
67
|
export declare function useEditCanvasContext(): EditCanvasContextValue;
|
|
@@ -58,4 +70,24 @@ export declare function useEditCanvasContext(): EditCanvasContextValue;
|
|
|
58
70
|
* when called outside of an {@link EditCanvasProvider}.
|
|
59
71
|
*/
|
|
60
72
|
export declare function useEditCanvasContextSafe(): EditCanvasContextValue | null;
|
|
73
|
+
/**
|
|
74
|
+
* Access only the viewport slice (zoom level and viewport controls) from
|
|
75
|
+
* the nearest {@link EditCanvasProvider}.
|
|
76
|
+
*
|
|
77
|
+
* This subscribes only to viewport changes — the component will **not**
|
|
78
|
+
* re-render when selection, dirty state, or other non-viewport state changes.
|
|
79
|
+
*
|
|
80
|
+
* Throws if called outside of a provider.
|
|
81
|
+
*/
|
|
82
|
+
export declare function useEditCanvasViewport(): EditCanvasViewportValue;
|
|
83
|
+
/**
|
|
84
|
+
* Access only the non-viewport state slice from the nearest
|
|
85
|
+
* {@link EditCanvasProvider}.
|
|
86
|
+
*
|
|
87
|
+
* This subscribes only to state changes (selection, dirty, history, etc.) —
|
|
88
|
+
* the component will **not** re-render on zoom/scroll changes.
|
|
89
|
+
*
|
|
90
|
+
* Throws if called outside of a provider.
|
|
91
|
+
*/
|
|
92
|
+
export declare function useEditCanvasState(): EditCanvasStateValue;
|
|
61
93
|
//# sourceMappingURL=EditCanvasContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditCanvasContext.d.ts","sourceRoot":"","sources":["../../src/context/EditCanvasContext.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"EditCanvasContext.d.ts","sourceRoot":"","sources":["../../src/context/EditCanvasContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAC;AAGhC,2EAA2E;AAC3E,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAEtE,qDAAqD;AACrD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,sBAAsB,EACtB,MAAM,GAAG,UAAU,CACpB,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,sBAAsB,EACtB,WAAW,GAAG,MAAM,GAAG,UAAU,CAClC,CAAC;AAOF,MAAM,WAAW,uBAAuB;IACtC,sEAAsE;IACtE,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,QAAQ,GACT,EAAE,uBAAuB,2CAkDzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,sBAAsB,CAe7D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,sBAAsB,GAAG,IAAI,CAcxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,uBAAuB,CAQ/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,oBAAoB,CAQzD"}
|
|
@@ -2,6 +2,10 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import { useViewCanvas, type UseViewCanvasOptions } from '../hooks/useViewCanvas';
|
|
3
3
|
/** The full return value of {@link useViewCanvas}, exposed via context. */
|
|
4
4
|
export type ViewCanvasContextValue = ReturnType<typeof useViewCanvas>;
|
|
5
|
+
/** Viewport slice — changes on every zoom/scroll. */
|
|
6
|
+
export type ViewCanvasViewportValue = Pick<ViewCanvasContextValue, 'zoom' | 'viewport'>;
|
|
7
|
+
/** State slice — everything except canvasRef and viewport. */
|
|
8
|
+
export type ViewCanvasStateValue = Omit<ViewCanvasContextValue, 'canvasRef' | 'zoom' | 'viewport'>;
|
|
5
9
|
export interface ViewCanvasProviderProps {
|
|
6
10
|
/** Options forwarded to the underlying {@link useViewCanvas} hook. */
|
|
7
11
|
options?: UseViewCanvasOptions;
|
|
@@ -11,10 +15,14 @@ export interface ViewCanvasProviderProps {
|
|
|
11
15
|
* Calls {@link useViewCanvas} internally and provides the full canvas API
|
|
12
16
|
* to all descendants via React context.
|
|
13
17
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Internally splits state into three contexts (ref, viewport, state) so
|
|
19
|
+
* that helper hooks like {@link useCanvasRef} and components like
|
|
20
|
+
* {@link ObjectOverlay} do not re-render on unrelated state changes.
|
|
21
|
+
*
|
|
22
|
+
* Use {@link useViewCanvasContext} in any descendant to access the full
|
|
23
|
+
* combined value, or use the fine-grained hooks
|
|
24
|
+
* {@link useViewCanvasViewport} / {@link useViewCanvasState} for better
|
|
25
|
+
* performance.
|
|
18
26
|
*
|
|
19
27
|
* Descendant components can also use {@link ObjectOverlay},
|
|
20
28
|
* {@link useCanvasEvents}, {@link useCanvasTooltip}, and
|
|
@@ -38,7 +46,7 @@ export interface ViewCanvasProviderProps {
|
|
|
38
46
|
* }
|
|
39
47
|
*
|
|
40
48
|
* function MyToolbar() {
|
|
41
|
-
* const { viewport } =
|
|
49
|
+
* const { viewport } = useViewCanvasViewport();
|
|
42
50
|
* return <ZoomControls onZoomIn={viewport.zoomIn} onZoomOut={viewport.zoomOut} />;
|
|
43
51
|
* }
|
|
44
52
|
* ```
|
|
@@ -48,6 +56,10 @@ export declare function ViewCanvasProvider({ options, children, }: ViewCanvasPro
|
|
|
48
56
|
* Access the full {@link useViewCanvas} API from any descendant of
|
|
49
57
|
* {@link ViewCanvasProvider}.
|
|
50
58
|
*
|
|
59
|
+
* This subscribes to all three internal contexts, so the component will
|
|
60
|
+
* re-render on any state change. For better performance, prefer
|
|
61
|
+
* {@link useViewCanvasViewport} or {@link useViewCanvasState}.
|
|
62
|
+
*
|
|
51
63
|
* Throws if called outside of a provider.
|
|
52
64
|
*/
|
|
53
65
|
export declare function useViewCanvasContext(): ViewCanvasContextValue;
|
|
@@ -56,4 +68,24 @@ export declare function useViewCanvasContext(): ViewCanvasContextValue;
|
|
|
56
68
|
* when called outside of a {@link ViewCanvasProvider}.
|
|
57
69
|
*/
|
|
58
70
|
export declare function useViewCanvasContextSafe(): ViewCanvasContextValue | null;
|
|
71
|
+
/**
|
|
72
|
+
* Access only the viewport slice (zoom level and viewport controls) from
|
|
73
|
+
* the nearest {@link ViewCanvasProvider}.
|
|
74
|
+
*
|
|
75
|
+
* This subscribes only to viewport changes — the component will **not**
|
|
76
|
+
* re-render when objects or loading state changes.
|
|
77
|
+
*
|
|
78
|
+
* Throws if called outside of a provider.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useViewCanvasViewport(): ViewCanvasViewportValue;
|
|
81
|
+
/**
|
|
82
|
+
* Access only the non-viewport state slice from the nearest
|
|
83
|
+
* {@link ViewCanvasProvider}.
|
|
84
|
+
*
|
|
85
|
+
* This subscribes only to state changes (objects, loading, etc.) —
|
|
86
|
+
* the component will **not** re-render on zoom/scroll changes.
|
|
87
|
+
*
|
|
88
|
+
* Throws if called outside of a provider.
|
|
89
|
+
*/
|
|
90
|
+
export declare function useViewCanvasState(): ViewCanvasStateValue;
|
|
59
91
|
//# sourceMappingURL=ViewCanvasContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewCanvasContext.d.ts","sourceRoot":"","sources":["../../src/context/ViewCanvasContext.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ViewCanvasContext.d.ts","sourceRoot":"","sources":["../../src/context/ViewCanvasContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAC;AAGhC,2EAA2E;AAC3E,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAEtE,qDAAqD;AACrD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,sBAAsB,EACtB,MAAM,GAAG,UAAU,CACpB,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,sBAAsB,EACtB,WAAW,GAAG,MAAM,GAAG,UAAU,CAClC,CAAC;AAOF,MAAM,WAAW,uBAAuB;IACtC,sEAAsE;IACtE,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,QAAQ,GACT,EAAE,uBAAuB,2CAgCzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,sBAAsB,CAe7D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,sBAAsB,GAAG,IAAI,CAcxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,uBAAuB,CAQ/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,oBAAoB,CAQzD"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { EditCanvasProvider, useEditCanvasContext } from './EditCanvasContext';
|
|
2
|
-
export type { EditCanvasProviderProps, EditCanvasContextValue, } from './EditCanvasContext';
|
|
3
|
-
export { ViewCanvasProvider, useViewCanvasContext } from './ViewCanvasContext';
|
|
4
|
-
export type { ViewCanvasProviderProps, ViewCanvasContextValue, } from './ViewCanvasContext';
|
|
1
|
+
export { EditCanvasProvider, useEditCanvasContext, useEditCanvasContextSafe, useEditCanvasViewport, useEditCanvasState, } from './EditCanvasContext';
|
|
2
|
+
export type { EditCanvasProviderProps, EditCanvasContextValue, EditCanvasViewportValue, EditCanvasStateValue, } from './EditCanvasContext';
|
|
3
|
+
export { ViewCanvasProvider, useViewCanvasContext, useViewCanvasContextSafe, useViewCanvasViewport, useViewCanvasState, } from './ViewCanvasContext';
|
|
4
|
+
export type { ViewCanvasProviderProps, ViewCanvasContextValue, ViewCanvasViewportValue, ViewCanvasStateValue, } from './ViewCanvasContext';
|
|
5
5
|
export { useCanvasRef } from './useCanvasRef';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -6,8 +6,10 @@ import type { Canvas as FabricCanvas } from 'fabric';
|
|
|
6
6
|
*
|
|
7
7
|
* Returns `null` if neither provider is present in the tree.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* This hook reads from the shared {@link CanvasRefContext}, which holds a
|
|
10
|
+
* stable `RefObject` that never changes identity. Consumers of this hook
|
|
11
|
+
* will **not** re-render when canvas state (zoom, selection, etc.) changes
|
|
12
|
+
* — only when the provider mounts/unmounts.
|
|
11
13
|
*/
|
|
12
14
|
export declare function useCanvasRef(): RefObject<FabricCanvas | null> | null;
|
|
13
15
|
//# sourceMappingURL=useCanvasRef.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCanvasRef.d.ts","sourceRoot":"","sources":["../../src/context/useCanvasRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"useCanvasRef.d.ts","sourceRoot":"","sources":["../../src/context/useCanvasRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGrD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,IAAI,CAEpE"}
|
|
@@ -93,5 +93,7 @@ export declare function useViewCanvas(options?: UseViewCanvasOptions): {
|
|
|
93
93
|
setObjectStyles: (styles: Record<string, ViewObjectStyle>) => void;
|
|
94
94
|
/** Apply a visual style to all objects whose `data.type` matches. */
|
|
95
95
|
setObjectStyleByType: (type: string, style: ViewObjectStyle) => void;
|
|
96
|
+
/** Whether the canvas is locked to light mode. Read from loaded canvas data. */
|
|
97
|
+
lockLightMode: boolean | undefined;
|
|
96
98
|
};
|
|
97
99
|
//# sourceMappingURL=useViewCanvas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useViewCanvas.d.ts","sourceRoot":"","sources":["../../src/hooks/useViewCanvas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAEL,KAAK,iBAAiB,EAEvB,MAAM,aAAa,CAAC;AASrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,oEAAoE;AACpE,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,kGAAkG;IAClG,UAAU,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IACzC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qEAAqE;IACrE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC9B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC;IACxC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"useViewCanvas.d.ts","sourceRoot":"","sources":["../../src/hooks/useViewCanvas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAEL,KAAK,iBAAiB,EAEvB,MAAM,aAAa,CAAC;AASrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,oEAAoE;AACpE,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,kGAAkG;IAClG,UAAU,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IACzC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qEAAqE;IACrE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC9B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC;IACxC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB;IAiLtD,8CAA8C;sBAnKvC,YAAY;IAqKnB,oDAAoD;;IAEpD,qCAAqC;;IAErC,0EAA0E;;IAE1E,qDAAqD;;IAErD,yBAAyB;;QAjFzB,wFAAwF;;QAExF,2DAA2D;;QAE3D,0DAA0D;;QAE1D,uDAAuD;;QAEvD,6DAA6D;;;IA2E7D,8DAA8D;yBA7D1B,MAAM,SAAS,eAAe;IA+DlE,sFAAsF;8BAtD/E,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAwDtC,qEAAqE;iCAjChE,MAAM,SAAS,eAAe;IAmCnC,gFAAgF;;EAOrF"}
|
package/dist/index.cjs
CHANGED
|
@@ -83,8 +83,12 @@ __export(index_exports, {
|
|
|
83
83
|
useCanvasTooltip: () => useCanvasTooltip,
|
|
84
84
|
useEditCanvas: () => useEditCanvas,
|
|
85
85
|
useEditCanvasContext: () => useEditCanvasContext,
|
|
86
|
+
useEditCanvasState: () => useEditCanvasState,
|
|
87
|
+
useEditCanvasViewport: () => useEditCanvasViewport,
|
|
86
88
|
useViewCanvas: () => useViewCanvas,
|
|
87
89
|
useViewCanvasContext: () => useViewCanvasContext,
|
|
90
|
+
useViewCanvasState: () => useViewCanvasState,
|
|
91
|
+
useViewCanvasViewport: () => useViewCanvasViewport,
|
|
88
92
|
util: () => import_fabric19.util
|
|
89
93
|
});
|
|
90
94
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -2900,6 +2904,9 @@ function useViewCanvas(options) {
|
|
|
2900
2904
|
const [zoom, setZoom] = (0, import_react4.useState)(1);
|
|
2901
2905
|
const [objects, setObjects] = (0, import_react4.useState)([]);
|
|
2902
2906
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
2907
|
+
const [lockLightMode, setLockLightMode] = (0, import_react4.useState)(
|
|
2908
|
+
void 0
|
|
2909
|
+
);
|
|
2903
2910
|
const onReady = (0, import_react4.useCallback)(
|
|
2904
2911
|
(canvas) => {
|
|
2905
2912
|
canvasRef.current = canvas;
|
|
@@ -2947,6 +2954,9 @@ function useViewCanvas(options) {
|
|
|
2947
2954
|
if (opts?.invertBackground !== void 0) {
|
|
2948
2955
|
setBackgroundInverted(canvas, opts.invertBackground);
|
|
2949
2956
|
}
|
|
2957
|
+
if (canvas.lockLightMode !== void 0) {
|
|
2958
|
+
setLockLightMode(canvas.lockLightMode);
|
|
2959
|
+
}
|
|
2950
2960
|
if (opts?.autoFitToBackground !== false && canvas.backgroundImage) {
|
|
2951
2961
|
fitViewportToBackground(canvas);
|
|
2952
2962
|
syncZoom(canvasRef, setZoom);
|
|
@@ -3043,70 +3053,29 @@ function useViewCanvas(options) {
|
|
|
3043
3053
|
/** Batch-update multiple objects' visual styles in one render. Keyed by `data.id`. */
|
|
3044
3054
|
setObjectStyles,
|
|
3045
3055
|
/** Apply a visual style to all objects whose `data.type` matches. */
|
|
3046
|
-
setObjectStyleByType
|
|
3056
|
+
setObjectStyleByType,
|
|
3057
|
+
/** Whether the canvas is locked to light mode. Read from loaded canvas data. */
|
|
3058
|
+
lockLightMode
|
|
3047
3059
|
}),
|
|
3048
3060
|
// Only reactive state in deps — refs and stable callbacks are omitted
|
|
3049
3061
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3050
|
-
[zoom, objects, isLoading, viewport]
|
|
3062
|
+
[zoom, objects, isLoading, viewport, lockLightMode]
|
|
3051
3063
|
);
|
|
3052
3064
|
}
|
|
3053
3065
|
|
|
3054
3066
|
// src/hooks/useCanvasEvents.ts
|
|
3055
|
-
var
|
|
3067
|
+
var import_react6 = require("react");
|
|
3056
3068
|
|
|
3057
|
-
// src/context/
|
|
3069
|
+
// src/context/CanvasRefContext.ts
|
|
3058
3070
|
var import_react5 = require("react");
|
|
3059
|
-
var
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
options,
|
|
3063
|
-
children
|
|
3064
|
-
}) {
|
|
3065
|
-
const canvas = useViewCanvas(options);
|
|
3066
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ViewCanvasContext.Provider, { value: canvas, children });
|
|
3067
|
-
}
|
|
3068
|
-
function useViewCanvasContext() {
|
|
3069
|
-
const ctx = (0, import_react5.useContext)(ViewCanvasContext);
|
|
3070
|
-
if (ctx === null) {
|
|
3071
|
-
throw new Error(
|
|
3072
|
-
"useViewCanvasContext must be used within a <ViewCanvasProvider>"
|
|
3073
|
-
);
|
|
3074
|
-
}
|
|
3075
|
-
return ctx;
|
|
3076
|
-
}
|
|
3077
|
-
function useViewCanvasContextSafe() {
|
|
3078
|
-
return (0, import_react5.useContext)(ViewCanvasContext);
|
|
3079
|
-
}
|
|
3080
|
-
|
|
3081
|
-
// src/context/EditCanvasContext.tsx
|
|
3082
|
-
var import_react6 = require("react");
|
|
3083
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3084
|
-
var EditCanvasContext = (0, import_react6.createContext)(null);
|
|
3085
|
-
function EditCanvasProvider({
|
|
3086
|
-
options,
|
|
3087
|
-
children
|
|
3088
|
-
}) {
|
|
3089
|
-
const canvas = useEditCanvas(options);
|
|
3090
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(EditCanvasContext.Provider, { value: canvas, children });
|
|
3091
|
-
}
|
|
3092
|
-
function useEditCanvasContext() {
|
|
3093
|
-
const ctx = (0, import_react6.useContext)(EditCanvasContext);
|
|
3094
|
-
if (ctx === null) {
|
|
3095
|
-
throw new Error(
|
|
3096
|
-
"useEditCanvasContext must be used within an <EditCanvasProvider>"
|
|
3097
|
-
);
|
|
3098
|
-
}
|
|
3099
|
-
return ctx;
|
|
3100
|
-
}
|
|
3101
|
-
function useEditCanvasContextSafe() {
|
|
3102
|
-
return (0, import_react6.useContext)(EditCanvasContext);
|
|
3071
|
+
var CanvasRefContext = (0, import_react5.createContext)(null);
|
|
3072
|
+
function useCanvasRefContext() {
|
|
3073
|
+
return (0, import_react5.useContext)(CanvasRefContext);
|
|
3103
3074
|
}
|
|
3104
3075
|
|
|
3105
3076
|
// src/context/useCanvasRef.ts
|
|
3106
3077
|
function useCanvasRef() {
|
|
3107
|
-
|
|
3108
|
-
const editCtx = useEditCanvasContextSafe();
|
|
3109
|
-
return viewCtx?.canvasRef ?? editCtx?.canvasRef ?? null;
|
|
3078
|
+
return useCanvasRefContext();
|
|
3110
3079
|
}
|
|
3111
3080
|
|
|
3112
3081
|
// src/hooks/useCanvasEvents.ts
|
|
@@ -3115,9 +3084,9 @@ function useCanvasEvents(canvasRefOrEvents, maybeEvents) {
|
|
|
3115
3084
|
const contextCanvasRef = useCanvasRef();
|
|
3116
3085
|
const resolvedCanvasRef = isContextOverload ? contextCanvasRef : canvasRefOrEvents;
|
|
3117
3086
|
const events = isContextOverload ? canvasRefOrEvents : maybeEvents;
|
|
3118
|
-
const eventsRef = (0,
|
|
3087
|
+
const eventsRef = (0, import_react6.useRef)(events);
|
|
3119
3088
|
eventsRef.current = events;
|
|
3120
|
-
(0,
|
|
3089
|
+
(0, import_react6.useEffect)(() => {
|
|
3121
3090
|
const canvas = resolvedCanvasRef?.current;
|
|
3122
3091
|
if (!canvas) return;
|
|
3123
3092
|
const wrappers = /* @__PURE__ */ new Map();
|
|
@@ -3138,21 +3107,21 @@ function useCanvasEvents(canvasRefOrEvents, maybeEvents) {
|
|
|
3138
3107
|
}
|
|
3139
3108
|
|
|
3140
3109
|
// src/hooks/useCanvasTooltip.ts
|
|
3141
|
-
var
|
|
3110
|
+
var import_react7 = require("react");
|
|
3142
3111
|
function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
3143
3112
|
const isContextOverload = maybeOptions === void 0;
|
|
3144
3113
|
const contextCanvasRef = useCanvasRef();
|
|
3145
3114
|
const resolvedCanvasRef = isContextOverload ? contextCanvasRef : canvasRefOrOptions;
|
|
3146
3115
|
const options = isContextOverload ? canvasRefOrOptions : maybeOptions;
|
|
3147
|
-
const [state, setState] = (0,
|
|
3116
|
+
const [state, setState] = (0, import_react7.useState)({
|
|
3148
3117
|
visible: false,
|
|
3149
3118
|
content: null,
|
|
3150
3119
|
position: { x: 0, y: 0 }
|
|
3151
3120
|
});
|
|
3152
|
-
const hoveredObjectRef = (0,
|
|
3153
|
-
const optionsRef = (0,
|
|
3121
|
+
const hoveredObjectRef = (0, import_react7.useRef)(null);
|
|
3122
|
+
const optionsRef = (0, import_react7.useRef)(options);
|
|
3154
3123
|
optionsRef.current = options;
|
|
3155
|
-
(0,
|
|
3124
|
+
(0, import_react7.useEffect)(() => {
|
|
3156
3125
|
const canvas = resolvedCanvasRef?.current;
|
|
3157
3126
|
if (!canvas) return;
|
|
3158
3127
|
function calculatePosition(target) {
|
|
@@ -3206,18 +3175,18 @@ function useCanvasTooltip(canvasRefOrOptions, maybeOptions) {
|
|
|
3206
3175
|
}
|
|
3207
3176
|
|
|
3208
3177
|
// src/hooks/useCanvasClick.ts
|
|
3209
|
-
var
|
|
3178
|
+
var import_react8 = require("react");
|
|
3210
3179
|
function useCanvasClick(canvasRefOrOnClick, onClickOrOptions, maybeOptions) {
|
|
3211
3180
|
const isContextOverload = typeof canvasRefOrOnClick === "function";
|
|
3212
3181
|
const contextCanvasRef = useCanvasRef();
|
|
3213
3182
|
const resolvedCanvasRef = isContextOverload ? contextCanvasRef : canvasRefOrOnClick;
|
|
3214
3183
|
const onClick = isContextOverload ? canvasRefOrOnClick : onClickOrOptions;
|
|
3215
3184
|
const options = isContextOverload ? onClickOrOptions : maybeOptions;
|
|
3216
|
-
const onClickRef = (0,
|
|
3185
|
+
const onClickRef = (0, import_react8.useRef)(onClick);
|
|
3217
3186
|
onClickRef.current = onClick;
|
|
3218
|
-
const optionsRef = (0,
|
|
3187
|
+
const optionsRef = (0, import_react8.useRef)(options);
|
|
3219
3188
|
optionsRef.current = options;
|
|
3220
|
-
(0,
|
|
3189
|
+
(0, import_react8.useEffect)(() => {
|
|
3221
3190
|
const canvas = resolvedCanvasRef?.current;
|
|
3222
3191
|
if (!canvas) return;
|
|
3223
3192
|
let mouseDown = null;
|
|
@@ -3261,8 +3230,152 @@ function useCanvasClick(canvasRefOrOnClick, onClickOrOptions, maybeOptions) {
|
|
|
3261
3230
|
}, [resolvedCanvasRef]);
|
|
3262
3231
|
}
|
|
3263
3232
|
|
|
3264
|
-
// src/
|
|
3233
|
+
// src/context/EditCanvasContext.tsx
|
|
3234
|
+
var import_react9 = require("react");
|
|
3235
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
3236
|
+
var EditViewportContext = (0, import_react9.createContext)(null);
|
|
3237
|
+
var EditStateContext = (0, import_react9.createContext)(null);
|
|
3238
|
+
function EditCanvasProvider({
|
|
3239
|
+
options,
|
|
3240
|
+
children
|
|
3241
|
+
}) {
|
|
3242
|
+
const canvas = useEditCanvas(options);
|
|
3243
|
+
const viewportValue = (0, import_react9.useMemo)(
|
|
3244
|
+
() => ({ zoom: canvas.zoom, viewport: canvas.viewport }),
|
|
3245
|
+
[canvas.zoom, canvas.viewport]
|
|
3246
|
+
);
|
|
3247
|
+
const stateValue = (0, import_react9.useMemo)(
|
|
3248
|
+
() => ({
|
|
3249
|
+
onReady: canvas.onReady,
|
|
3250
|
+
objects: canvas.objects,
|
|
3251
|
+
isLoading: canvas.isLoading,
|
|
3252
|
+
selected: canvas.selected,
|
|
3253
|
+
isEditingVertices: canvas.isEditingVertices,
|
|
3254
|
+
setMode: canvas.setMode,
|
|
3255
|
+
setBackground: canvas.setBackground,
|
|
3256
|
+
isDirty: canvas.isDirty,
|
|
3257
|
+
resetDirty: canvas.resetDirty,
|
|
3258
|
+
markDirty: canvas.markDirty,
|
|
3259
|
+
undo: canvas.undo,
|
|
3260
|
+
redo: canvas.redo,
|
|
3261
|
+
canUndo: canvas.canUndo,
|
|
3262
|
+
canRedo: canvas.canRedo,
|
|
3263
|
+
lockLightMode: canvas.lockLightMode,
|
|
3264
|
+
setLockLightMode: canvas.setLockLightMode
|
|
3265
|
+
}),
|
|
3266
|
+
// Only reactive state — stable callbacks omitted
|
|
3267
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3268
|
+
[
|
|
3269
|
+
canvas.objects,
|
|
3270
|
+
canvas.isLoading,
|
|
3271
|
+
canvas.selected,
|
|
3272
|
+
canvas.isEditingVertices,
|
|
3273
|
+
canvas.isDirty,
|
|
3274
|
+
canvas.canUndo,
|
|
3275
|
+
canvas.canRedo,
|
|
3276
|
+
canvas.lockLightMode
|
|
3277
|
+
]
|
|
3278
|
+
);
|
|
3279
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CanvasRefContext.Provider, { value: canvas.canvasRef, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditViewportContext.Provider, { value: viewportValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditStateContext.Provider, { value: stateValue, children }) }) });
|
|
3280
|
+
}
|
|
3281
|
+
function useEditCanvasContext() {
|
|
3282
|
+
const canvasRef = (0, import_react9.useContext)(CanvasRefContext);
|
|
3283
|
+
const viewport = (0, import_react9.useContext)(EditViewportContext);
|
|
3284
|
+
const state = (0, import_react9.useContext)(EditStateContext);
|
|
3285
|
+
if (canvasRef === null || viewport === null || state === null) {
|
|
3286
|
+
throw new Error(
|
|
3287
|
+
"useEditCanvasContext must be used within an <EditCanvasProvider>"
|
|
3288
|
+
);
|
|
3289
|
+
}
|
|
3290
|
+
return (0, import_react9.useMemo)(
|
|
3291
|
+
() => ({ canvasRef, ...viewport, ...state }),
|
|
3292
|
+
[canvasRef, viewport, state]
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
function useEditCanvasViewport() {
|
|
3296
|
+
const ctx = (0, import_react9.useContext)(EditViewportContext);
|
|
3297
|
+
if (ctx === null) {
|
|
3298
|
+
throw new Error(
|
|
3299
|
+
"useEditCanvasViewport must be used within an <EditCanvasProvider>"
|
|
3300
|
+
);
|
|
3301
|
+
}
|
|
3302
|
+
return ctx;
|
|
3303
|
+
}
|
|
3304
|
+
function useEditCanvasState() {
|
|
3305
|
+
const ctx = (0, import_react9.useContext)(EditStateContext);
|
|
3306
|
+
if (ctx === null) {
|
|
3307
|
+
throw new Error(
|
|
3308
|
+
"useEditCanvasState must be used within an <EditCanvasProvider>"
|
|
3309
|
+
);
|
|
3310
|
+
}
|
|
3311
|
+
return ctx;
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
// src/context/ViewCanvasContext.tsx
|
|
3265
3315
|
var import_react10 = require("react");
|
|
3316
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3317
|
+
var ViewViewportContext = (0, import_react10.createContext)(null);
|
|
3318
|
+
var ViewStateContext = (0, import_react10.createContext)(null);
|
|
3319
|
+
function ViewCanvasProvider({
|
|
3320
|
+
options,
|
|
3321
|
+
children
|
|
3322
|
+
}) {
|
|
3323
|
+
const canvas = useViewCanvas(options);
|
|
3324
|
+
const viewportValue = (0, import_react10.useMemo)(
|
|
3325
|
+
() => ({ zoom: canvas.zoom, viewport: canvas.viewport }),
|
|
3326
|
+
[canvas.zoom, canvas.viewport]
|
|
3327
|
+
);
|
|
3328
|
+
const stateValue = (0, import_react10.useMemo)(
|
|
3329
|
+
() => ({
|
|
3330
|
+
onReady: canvas.onReady,
|
|
3331
|
+
objects: canvas.objects,
|
|
3332
|
+
isLoading: canvas.isLoading,
|
|
3333
|
+
setObjectStyle: canvas.setObjectStyle,
|
|
3334
|
+
setObjectStyles: canvas.setObjectStyles,
|
|
3335
|
+
setObjectStyleByType: canvas.setObjectStyleByType,
|
|
3336
|
+
lockLightMode: canvas.lockLightMode
|
|
3337
|
+
}),
|
|
3338
|
+
// Only reactive state — stable callbacks omitted
|
|
3339
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3340
|
+
[canvas.objects, canvas.isLoading, canvas.lockLightMode]
|
|
3341
|
+
);
|
|
3342
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CanvasRefContext.Provider, { value: canvas.canvasRef, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewViewportContext.Provider, { value: viewportValue, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewStateContext.Provider, { value: stateValue, children }) }) });
|
|
3343
|
+
}
|
|
3344
|
+
function useViewCanvasContext() {
|
|
3345
|
+
const canvasRef = (0, import_react10.useContext)(CanvasRefContext);
|
|
3346
|
+
const viewport = (0, import_react10.useContext)(ViewViewportContext);
|
|
3347
|
+
const state = (0, import_react10.useContext)(ViewStateContext);
|
|
3348
|
+
if (canvasRef === null || viewport === null || state === null) {
|
|
3349
|
+
throw new Error(
|
|
3350
|
+
"useViewCanvasContext must be used within a <ViewCanvasProvider>"
|
|
3351
|
+
);
|
|
3352
|
+
}
|
|
3353
|
+
return (0, import_react10.useMemo)(
|
|
3354
|
+
() => ({ canvasRef, ...viewport, ...state }),
|
|
3355
|
+
[canvasRef, viewport, state]
|
|
3356
|
+
);
|
|
3357
|
+
}
|
|
3358
|
+
function useViewCanvasViewport() {
|
|
3359
|
+
const ctx = (0, import_react10.useContext)(ViewViewportContext);
|
|
3360
|
+
if (ctx === null) {
|
|
3361
|
+
throw new Error(
|
|
3362
|
+
"useViewCanvasViewport must be used within a <ViewCanvasProvider>"
|
|
3363
|
+
);
|
|
3364
|
+
}
|
|
3365
|
+
return ctx;
|
|
3366
|
+
}
|
|
3367
|
+
function useViewCanvasState() {
|
|
3368
|
+
const ctx = (0, import_react10.useContext)(ViewStateContext);
|
|
3369
|
+
if (ctx === null) {
|
|
3370
|
+
throw new Error(
|
|
3371
|
+
"useViewCanvasState must be used within a <ViewCanvasProvider>"
|
|
3372
|
+
);
|
|
3373
|
+
}
|
|
3374
|
+
return ctx;
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
// src/overlay/ObjectOverlay.tsx
|
|
3378
|
+
var import_react11 = require("react");
|
|
3266
3379
|
var import_material = require("@mui/material");
|
|
3267
3380
|
var import_fabric18 = require("fabric");
|
|
3268
3381
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -3275,8 +3388,8 @@ function ObjectOverlay({
|
|
|
3275
3388
|
}) {
|
|
3276
3389
|
const contextCanvasRef = useCanvasRef();
|
|
3277
3390
|
const canvasRef = canvasRefProp ?? contextCanvasRef;
|
|
3278
|
-
const stackRef = (0,
|
|
3279
|
-
(0,
|
|
3391
|
+
const stackRef = (0, import_react11.useRef)(null);
|
|
3392
|
+
(0, import_react11.useEffect)(() => {
|
|
3280
3393
|
const canvas = canvasRef?.current;
|
|
3281
3394
|
if (!canvas || !object) return;
|
|
3282
3395
|
function update() {
|
|
@@ -3331,7 +3444,7 @@ function ObjectOverlay({
|
|
|
3331
3444
|
|
|
3332
3445
|
// src/overlay/OverlayContent.tsx
|
|
3333
3446
|
var import_material2 = require("@mui/material");
|
|
3334
|
-
var
|
|
3447
|
+
var import_react12 = require("react");
|
|
3335
3448
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
3336
3449
|
function OverlayContent({
|
|
3337
3450
|
children,
|
|
@@ -3340,9 +3453,9 @@ function OverlayContent({
|
|
|
3340
3453
|
sx,
|
|
3341
3454
|
...rest
|
|
3342
3455
|
}) {
|
|
3343
|
-
const outerRef = (0,
|
|
3344
|
-
const innerRef = (0,
|
|
3345
|
-
(0,
|
|
3456
|
+
const outerRef = (0, import_react12.useRef)(null);
|
|
3457
|
+
const innerRef = (0, import_react12.useRef)(null);
|
|
3458
|
+
(0, import_react12.useEffect)(() => {
|
|
3346
3459
|
const outer = outerRef.current;
|
|
3347
3460
|
const inner = innerRef.current;
|
|
3348
3461
|
if (!outer || !inner) return;
|
|
@@ -3403,7 +3516,7 @@ function OverlayContent({
|
|
|
3403
3516
|
|
|
3404
3517
|
// src/overlay/FixedSizeContent.tsx
|
|
3405
3518
|
var import_material3 = require("@mui/material");
|
|
3406
|
-
var
|
|
3519
|
+
var import_react13 = require("react");
|
|
3407
3520
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
3408
3521
|
function FixedSizeContent({
|
|
3409
3522
|
children,
|
|
@@ -3412,9 +3525,9 @@ function FixedSizeContent({
|
|
|
3412
3525
|
sx,
|
|
3413
3526
|
...rest
|
|
3414
3527
|
}) {
|
|
3415
|
-
const ref = (0,
|
|
3416
|
-
const totalContentHeightRef = (0,
|
|
3417
|
-
(0,
|
|
3528
|
+
const ref = (0, import_react13.useRef)(null);
|
|
3529
|
+
const totalContentHeightRef = (0, import_react13.useRef)(0);
|
|
3530
|
+
(0, import_react13.useEffect)(() => {
|
|
3418
3531
|
const el = ref.current;
|
|
3419
3532
|
if (!el) return;
|
|
3420
3533
|
let clipAncestor = el.parentElement;
|
|
@@ -3477,7 +3590,7 @@ function FixedSizeContent({
|
|
|
3477
3590
|
|
|
3478
3591
|
// src/overlay/OverlayBadge.tsx
|
|
3479
3592
|
var import_material4 = require("@mui/material");
|
|
3480
|
-
var
|
|
3593
|
+
var import_react14 = require("react");
|
|
3481
3594
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
3482
3595
|
function toPx(v) {
|
|
3483
3596
|
if (v === void 0) return void 0;
|
|
@@ -3520,9 +3633,9 @@ function OverlayBadge({
|
|
|
3520
3633
|
sx,
|
|
3521
3634
|
...rest
|
|
3522
3635
|
}) {
|
|
3523
|
-
const ref = (0,
|
|
3524
|
-
const baseSize = (0,
|
|
3525
|
-
(0,
|
|
3636
|
+
const ref = (0, import_react14.useRef)(null);
|
|
3637
|
+
const baseSize = (0, import_react14.useRef)(null);
|
|
3638
|
+
(0, import_react14.useEffect)(() => {
|
|
3526
3639
|
const el = ref.current;
|
|
3527
3640
|
if (!el) return;
|
|
3528
3641
|
const ancestor = el.parentElement;
|
|
@@ -3661,8 +3774,12 @@ var import_fabric19 = require("fabric");
|
|
|
3661
3774
|
useCanvasTooltip,
|
|
3662
3775
|
useEditCanvas,
|
|
3663
3776
|
useEditCanvasContext,
|
|
3777
|
+
useEditCanvasState,
|
|
3778
|
+
useEditCanvasViewport,
|
|
3664
3779
|
useViewCanvas,
|
|
3665
3780
|
useViewCanvasContext,
|
|
3781
|
+
useViewCanvasState,
|
|
3782
|
+
useViewCanvasViewport,
|
|
3666
3783
|
util
|
|
3667
3784
|
});
|
|
3668
3785
|
//# sourceMappingURL=index.cjs.map
|