@pixerate/editor-react 0.152.0 → 0.153.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/canvas/index.cjs
CHANGED
|
@@ -1688,6 +1688,7 @@ function useCanvasDraw(options) {
|
|
|
1688
1688
|
cancelStroke: controller.cancelStroke,
|
|
1689
1689
|
eraseAt: controller.eraseAt,
|
|
1690
1690
|
drawStroke: controller.drawStroke,
|
|
1691
|
+
nodeBounds: controller.nodeBounds,
|
|
1691
1692
|
listBrushes: controller.listBrushes
|
|
1692
1693
|
}),
|
|
1693
1694
|
[tool, style, activeStroke, controller]
|
|
@@ -3740,20 +3741,23 @@ var useCanvasEffectsProviderContext = () => (0, import_react30.useContext)(Provi
|
|
|
3740
3741
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
3741
3742
|
const provider = useCanvasEffectsProviderContext();
|
|
3742
3743
|
const ref = (0, import_react30.useRef)(null);
|
|
3743
|
-
const [failed, setFailed] = (0, import_react30.useState)(
|
|
3744
|
+
const [failed, setFailed] = (0, import_react30.useState)(null);
|
|
3744
3745
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
3745
3746
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
3746
3747
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
3747
3748
|
const key = JSON.stringify(effect);
|
|
3749
|
+
const status = provider ? (0, import_canvas16.canvasEffectStatus)(effect, provider) : null;
|
|
3748
3750
|
(0, import_react30.useEffect)(() => {
|
|
3749
3751
|
const canvas2 = ref.current;
|
|
3750
|
-
if (!provider || !canvas2) return;
|
|
3751
|
-
setFailed(
|
|
3752
|
-
const run = (0, import_canvas16.runCanvasNodeEffect)({ provider, effect, target: canvas2, onError: () => setFailed(
|
|
3752
|
+
if (!provider || !canvas2 || !(0, import_canvas16.canvasEffectStatus)(effect, provider).ok) return;
|
|
3753
|
+
setFailed(null);
|
|
3754
|
+
const run = (0, import_canvas16.runCanvasNodeEffect)({ provider, effect, target: canvas2, onError: (e) => setFailed((0, import_canvas16.canvasEffectErrorReason)(effect, e)) });
|
|
3753
3755
|
return () => run.stop();
|
|
3754
3756
|
}, [provider, key, pw, ph]);
|
|
3755
3757
|
const clipId = (0, import_react30.useMemo)(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
3756
|
-
if (!provider ||
|
|
3758
|
+
if (!provider || !status || !(width > 0 && height > 0)) return null;
|
|
3759
|
+
const missing = !status.ok ? status.reason : failed;
|
|
3760
|
+
if (missing) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CanvasEffectMissing, { reason: missing, effect, width, height, clipPath, clipTransform });
|
|
3757
3761
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
3758
3762
|
const canvas = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
|
|
3759
3763
|
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { style, children: canvas });
|
|
@@ -3762,6 +3766,16 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
|
|
|
3762
3766
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("foreignObject", { x: 0, y: 0, width, height, clipPath: `url(#${clipId})`, children: canvas })
|
|
3763
3767
|
] });
|
|
3764
3768
|
}
|
|
3769
|
+
function CanvasEffectMissing({ reason, effect, width, height, clipPath, clipTransform }) {
|
|
3770
|
+
const id = (0, import_react30.useMemo)(() => `pixerate-effect-missing-${Math.random().toString(36).slice(2)}`, []);
|
|
3771
|
+
const common = { role: "img", "aria-label": reason, "data-canvas-effect-missing": effect.effect };
|
|
3772
|
+
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { ...common, title: reason, style: { position: "absolute", inset: 0, pointerEvents: "none", background: import_canvas16.CANVAS_EFFECT_MISSING_PATTERN } });
|
|
3773
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("svg", { ...common, style: { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none" }, viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", children: [
|
|
3774
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("title", { children: reason }),
|
|
3775
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("pattern", { id, width: 8, height: 8, patternUnits: "userSpaceOnUse", patternTransform: "rotate(45)", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("rect", { width: 2, height: 8, fill: "rgba(128,128,128,0.28)" }) }) }),
|
|
3776
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("path", { d: clipPath, transform: clipTransform, fill: `url(#${id})` })
|
|
3777
|
+
] });
|
|
3778
|
+
}
|
|
3765
3779
|
function useCanvasEffects(options) {
|
|
3766
3780
|
const opts = (0, import_react30.useRef)(options);
|
|
3767
3781
|
opts.current = options;
|
|
@@ -3810,6 +3824,11 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
3810
3824
|
message && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
3811
3825
|
] });
|
|
3812
3826
|
}
|
|
3827
|
+
function EffectControlsOrReason({ controller, nodeId, effect }) {
|
|
3828
|
+
const status = controller.status(effect);
|
|
3829
|
+
if (!status.ok) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { className: "text-[11px] text-amber-500", "data-canvas-effect-unavailable": "", children: status.reason });
|
|
3830
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Controls, { controller, nodeId, effect });
|
|
3831
|
+
}
|
|
3813
3832
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
3814
3833
|
const [, setTick] = (0, import_react30.useState)(0);
|
|
3815
3834
|
(0, import_react30.useEffect)(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
@@ -3852,7 +3871,7 @@ function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = ""
|
|
|
3852
3871
|
] }),
|
|
3853
3872
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: btn, "aria-label": "Remove effect", onClick: () => run(() => controller.removeNodeEffect(nodeId)), children: "\u2715" })
|
|
3854
3873
|
] }),
|
|
3855
|
-
provider && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3874
|
+
provider && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(EffectControlsOrReason, { controller, nodeId, effect })
|
|
3856
3875
|
] }),
|
|
3857
3876
|
sceneId && transition && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex items-center gap-1", "data-canvas-scene-transition": sceneId, children: [
|
|
3858
3877
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "min-w-0 flex-1 truncate", children: [
|
package/dist/canvas/index.js
CHANGED
|
@@ -1234,6 +1234,7 @@ function useCanvasDraw(options) {
|
|
|
1234
1234
|
cancelStroke: controller.cancelStroke,
|
|
1235
1235
|
eraseAt: controller.eraseAt,
|
|
1236
1236
|
drawStroke: controller.drawStroke,
|
|
1237
|
+
nodeBounds: controller.nodeBounds,
|
|
1237
1238
|
listBrushes: controller.listBrushes
|
|
1238
1239
|
}),
|
|
1239
1240
|
[tool, style, activeStroke, controller]
|
|
@@ -1582,6 +1583,9 @@ function useCanvasBrushes(options = {}) {
|
|
|
1582
1583
|
// src/canvas/CanvasEffects.tsx
|
|
1583
1584
|
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect11, useMemo as useMemo10, useRef as useRef14, useState as useState8 } from "react";
|
|
1584
1585
|
import {
|
|
1586
|
+
CANVAS_EFFECT_MISSING_PATTERN,
|
|
1587
|
+
canvasEffectErrorReason,
|
|
1588
|
+
canvasEffectStatus,
|
|
1585
1589
|
createCanvasEffectsController,
|
|
1586
1590
|
createCanvasEffectsToolProvider,
|
|
1587
1591
|
isShapeDescription,
|
|
@@ -1596,20 +1600,23 @@ var useCanvasEffectsProviderContext = () => useContext2(ProviderContext);
|
|
|
1596
1600
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
1597
1601
|
const provider = useCanvasEffectsProviderContext();
|
|
1598
1602
|
const ref = useRef14(null);
|
|
1599
|
-
const [failed, setFailed] = useState8(
|
|
1603
|
+
const [failed, setFailed] = useState8(null);
|
|
1600
1604
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
1601
1605
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
1602
1606
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
1603
1607
|
const key = JSON.stringify(effect);
|
|
1608
|
+
const status = provider ? canvasEffectStatus(effect, provider) : null;
|
|
1604
1609
|
useEffect11(() => {
|
|
1605
1610
|
const canvas2 = ref.current;
|
|
1606
|
-
if (!provider || !canvas2) return;
|
|
1607
|
-
setFailed(
|
|
1608
|
-
const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: () => setFailed(
|
|
1611
|
+
if (!provider || !canvas2 || !canvasEffectStatus(effect, provider).ok) return;
|
|
1612
|
+
setFailed(null);
|
|
1613
|
+
const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: (e) => setFailed(canvasEffectErrorReason(effect, e)) });
|
|
1609
1614
|
return () => run.stop();
|
|
1610
1615
|
}, [provider, key, pw, ph]);
|
|
1611
1616
|
const clipId = useMemo10(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
1612
|
-
if (!provider ||
|
|
1617
|
+
if (!provider || !status || !(width > 0 && height > 0)) return null;
|
|
1618
|
+
const missing = !status.ok ? status.reason : failed;
|
|
1619
|
+
if (missing) return /* @__PURE__ */ jsx5(CanvasEffectMissing, { reason: missing, effect, width, height, clipPath, clipTransform });
|
|
1613
1620
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
1614
1621
|
const canvas = /* @__PURE__ */ jsx5("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
|
|
1615
1622
|
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ jsx5("div", { style, children: canvas });
|
|
@@ -1618,6 +1625,16 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
|
|
|
1618
1625
|
/* @__PURE__ */ jsx5("foreignObject", { x: 0, y: 0, width, height, clipPath: `url(#${clipId})`, children: canvas })
|
|
1619
1626
|
] });
|
|
1620
1627
|
}
|
|
1628
|
+
function CanvasEffectMissing({ reason, effect, width, height, clipPath, clipTransform }) {
|
|
1629
|
+
const id = useMemo10(() => `pixerate-effect-missing-${Math.random().toString(36).slice(2)}`, []);
|
|
1630
|
+
const common = { role: "img", "aria-label": reason, "data-canvas-effect-missing": effect.effect };
|
|
1631
|
+
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ jsx5("div", { ...common, title: reason, style: { position: "absolute", inset: 0, pointerEvents: "none", background: CANVAS_EFFECT_MISSING_PATTERN } });
|
|
1632
|
+
return /* @__PURE__ */ jsxs4("svg", { ...common, style: { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none" }, viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", children: [
|
|
1633
|
+
/* @__PURE__ */ jsx5("title", { children: reason }),
|
|
1634
|
+
/* @__PURE__ */ jsx5("defs", { children: /* @__PURE__ */ jsx5("pattern", { id, width: 8, height: 8, patternUnits: "userSpaceOnUse", patternTransform: "rotate(45)", children: /* @__PURE__ */ jsx5("rect", { width: 2, height: 8, fill: "rgba(128,128,128,0.28)" }) }) }),
|
|
1635
|
+
/* @__PURE__ */ jsx5("path", { d: clipPath, transform: clipTransform, fill: `url(#${id})` })
|
|
1636
|
+
] });
|
|
1637
|
+
}
|
|
1621
1638
|
function useCanvasEffects(options) {
|
|
1622
1639
|
const opts = useRef14(options);
|
|
1623
1640
|
opts.current = options;
|
|
@@ -1666,6 +1683,11 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
1666
1683
|
message && /* @__PURE__ */ jsx5("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
1667
1684
|
] });
|
|
1668
1685
|
}
|
|
1686
|
+
function EffectControlsOrReason({ controller, nodeId, effect }) {
|
|
1687
|
+
const status = controller.status(effect);
|
|
1688
|
+
if (!status.ok) return /* @__PURE__ */ jsx5("p", { className: "text-[11px] text-amber-500", "data-canvas-effect-unavailable": "", children: status.reason });
|
|
1689
|
+
return /* @__PURE__ */ jsx5(Controls, { controller, nodeId, effect });
|
|
1690
|
+
}
|
|
1669
1691
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
1670
1692
|
const [, setTick] = useState8(0);
|
|
1671
1693
|
useEffect11(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
@@ -1708,7 +1730,7 @@ function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = ""
|
|
|
1708
1730
|
] }),
|
|
1709
1731
|
/* @__PURE__ */ jsx5("button", { type: "button", className: btn, "aria-label": "Remove effect", onClick: () => run(() => controller.removeNodeEffect(nodeId)), children: "\u2715" })
|
|
1710
1732
|
] }),
|
|
1711
|
-
provider && /* @__PURE__ */ jsx5(
|
|
1733
|
+
provider && /* @__PURE__ */ jsx5(EffectControlsOrReason, { controller, nodeId, effect })
|
|
1712
1734
|
] }),
|
|
1713
1735
|
sceneId && transition && /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-1", "data-canvas-scene-transition": sceneId, children: [
|
|
1714
1736
|
/* @__PURE__ */ jsxs4("span", { className: "min-w-0 flex-1 truncate", children: [
|
|
@@ -27,6 +27,13 @@ export interface CanvasDrawActions<TNode extends CanvasNode = CanvasNode> {
|
|
|
27
27
|
eraseAt: (point: [number, number], radius?: number) => TNode[];
|
|
28
28
|
/** Draws a whole stroke at once (agents, code); validates the brush first. One undo step. */
|
|
29
29
|
drawStroke: (input: DrawStrokeInput) => Promise<DrawStrokeResult<TNode>>;
|
|
30
|
+
/** A node's box in canvas coordinates (lets gesture commands such as `canvas.circle` take `{ nodeId }`). */
|
|
31
|
+
nodeBounds: (id: string) => {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
} | undefined;
|
|
30
37
|
/** The dry paint presets `style.brush` accepts (loads the paint engine). */
|
|
31
38
|
listBrushes: () => Promise<CanvasBrushPreset[]>;
|
|
32
39
|
}
|
|
@@ -27,6 +27,13 @@ export interface CanvasDrawActions<TNode extends CanvasNode = CanvasNode> {
|
|
|
27
27
|
eraseAt: (point: [number, number], radius?: number) => TNode[];
|
|
28
28
|
/** Draws a whole stroke at once (agents, code); validates the brush first. One undo step. */
|
|
29
29
|
drawStroke: (input: DrawStrokeInput) => Promise<DrawStrokeResult<TNode>>;
|
|
30
|
+
/** A node's box in canvas coordinates (lets gesture commands such as `canvas.circle` take `{ nodeId }`). */
|
|
31
|
+
nodeBounds: (id: string) => {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
} | undefined;
|
|
30
37
|
/** The dry paint presets `style.brush` accepts (loads the paint engine). */
|
|
31
38
|
listBrushes: () => Promise<CanvasBrushPreset[]>;
|
|
32
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.153.0",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
"dependencies": {},
|
|
255
255
|
"peerDependencies": {
|
|
256
256
|
"@dagrejs/dagre": "^1.1.8",
|
|
257
|
-
"@pixerate/editor": ">=0.
|
|
257
|
+
"@pixerate/editor": ">=0.228.0 <1.0.0-0",
|
|
258
258
|
"@tiptap/core": "^2.27.3",
|
|
259
259
|
"@tiptap/extension-bubble-menu": "^2.27.3",
|
|
260
260
|
"@tiptap/extension-placeholder": "^2.27.3",
|
|
@@ -305,7 +305,7 @@
|
|
|
305
305
|
"tsup": "^9.0.0",
|
|
306
306
|
"typescript": "^5.7.3",
|
|
307
307
|
"vitest": "^5.0.5",
|
|
308
|
-
"@pixerate/editor": "0.
|
|
308
|
+
"@pixerate/editor": "0.228.0"
|
|
309
309
|
},
|
|
310
310
|
"scripts": {
|
|
311
311
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|