@pixerate/editor-react 0.152.0 → 0.152.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/canvas/index.cjs +24 -6
- package/dist/canvas/index.js +27 -6
- package/package.json +3 -3
package/dist/canvas/index.cjs
CHANGED
|
@@ -3740,20 +3740,23 @@ var useCanvasEffectsProviderContext = () => (0, import_react30.useContext)(Provi
|
|
|
3740
3740
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
3741
3741
|
const provider = useCanvasEffectsProviderContext();
|
|
3742
3742
|
const ref = (0, import_react30.useRef)(null);
|
|
3743
|
-
const [failed, setFailed] = (0, import_react30.useState)(
|
|
3743
|
+
const [failed, setFailed] = (0, import_react30.useState)(null);
|
|
3744
3744
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
3745
3745
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
3746
3746
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
3747
3747
|
const key = JSON.stringify(effect);
|
|
3748
|
+
const status = provider ? (0, import_canvas16.canvasEffectStatus)(effect, provider) : null;
|
|
3748
3749
|
(0, import_react30.useEffect)(() => {
|
|
3749
3750
|
const canvas2 = ref.current;
|
|
3750
|
-
if (!provider || !canvas2) return;
|
|
3751
|
-
setFailed(
|
|
3752
|
-
const run = (0, import_canvas16.runCanvasNodeEffect)({ provider, effect, target: canvas2, onError: () => setFailed(
|
|
3751
|
+
if (!provider || !canvas2 || !(0, import_canvas16.canvasEffectStatus)(effect, provider).ok) return;
|
|
3752
|
+
setFailed(null);
|
|
3753
|
+
const run = (0, import_canvas16.runCanvasNodeEffect)({ provider, effect, target: canvas2, onError: (e) => setFailed((0, import_canvas16.canvasEffectErrorReason)(effect, e)) });
|
|
3753
3754
|
return () => run.stop();
|
|
3754
3755
|
}, [provider, key, pw, ph]);
|
|
3755
3756
|
const clipId = (0, import_react30.useMemo)(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
3756
|
-
if (!provider ||
|
|
3757
|
+
if (!provider || !status || !(width > 0 && height > 0)) return null;
|
|
3758
|
+
const missing = !status.ok ? status.reason : failed;
|
|
3759
|
+
if (missing) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CanvasEffectMissing, { reason: missing, effect, width, height, clipPath, clipTransform });
|
|
3757
3760
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
3758
3761
|
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
3762
|
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { style, children: canvas });
|
|
@@ -3762,6 +3765,16 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
|
|
|
3762
3765
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("foreignObject", { x: 0, y: 0, width, height, clipPath: `url(#${clipId})`, children: canvas })
|
|
3763
3766
|
] });
|
|
3764
3767
|
}
|
|
3768
|
+
function CanvasEffectMissing({ reason, effect, width, height, clipPath, clipTransform }) {
|
|
3769
|
+
const id = (0, import_react30.useMemo)(() => `pixerate-effect-missing-${Math.random().toString(36).slice(2)}`, []);
|
|
3770
|
+
const common = { role: "img", "aria-label": reason, "data-canvas-effect-missing": effect.effect };
|
|
3771
|
+
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 } });
|
|
3772
|
+
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: [
|
|
3773
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("title", { children: reason }),
|
|
3774
|
+
/* @__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)" }) }) }),
|
|
3775
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("path", { d: clipPath, transform: clipTransform, fill: `url(#${id})` })
|
|
3776
|
+
] });
|
|
3777
|
+
}
|
|
3765
3778
|
function useCanvasEffects(options) {
|
|
3766
3779
|
const opts = (0, import_react30.useRef)(options);
|
|
3767
3780
|
opts.current = options;
|
|
@@ -3810,6 +3823,11 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
3810
3823
|
message && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
3811
3824
|
] });
|
|
3812
3825
|
}
|
|
3826
|
+
function EffectControlsOrReason({ controller, nodeId, effect }) {
|
|
3827
|
+
const status = controller.status(effect);
|
|
3828
|
+
if (!status.ok) return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { className: "text-[11px] text-amber-500", "data-canvas-effect-unavailable": "", children: status.reason });
|
|
3829
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Controls, { controller, nodeId, effect });
|
|
3830
|
+
}
|
|
3813
3831
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
3814
3832
|
const [, setTick] = (0, import_react30.useState)(0);
|
|
3815
3833
|
(0, import_react30.useEffect)(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
@@ -3852,7 +3870,7 @@ function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = ""
|
|
|
3852
3870
|
] }),
|
|
3853
3871
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: btn, "aria-label": "Remove effect", onClick: () => run(() => controller.removeNodeEffect(nodeId)), children: "\u2715" })
|
|
3854
3872
|
] }),
|
|
3855
|
-
provider && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3873
|
+
provider && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(EffectControlsOrReason, { controller, nodeId, effect })
|
|
3856
3874
|
] }),
|
|
3857
3875
|
sceneId && transition && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex items-center gap-1", "data-canvas-scene-transition": sceneId, children: [
|
|
3858
3876
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "min-w-0 flex-1 truncate", children: [
|
package/dist/canvas/index.js
CHANGED
|
@@ -1582,6 +1582,9 @@ function useCanvasBrushes(options = {}) {
|
|
|
1582
1582
|
// src/canvas/CanvasEffects.tsx
|
|
1583
1583
|
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect11, useMemo as useMemo10, useRef as useRef14, useState as useState8 } from "react";
|
|
1584
1584
|
import {
|
|
1585
|
+
CANVAS_EFFECT_MISSING_PATTERN,
|
|
1586
|
+
canvasEffectErrorReason,
|
|
1587
|
+
canvasEffectStatus,
|
|
1585
1588
|
createCanvasEffectsController,
|
|
1586
1589
|
createCanvasEffectsToolProvider,
|
|
1587
1590
|
isShapeDescription,
|
|
@@ -1596,20 +1599,23 @@ var useCanvasEffectsProviderContext = () => useContext2(ProviderContext);
|
|
|
1596
1599
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
1597
1600
|
const provider = useCanvasEffectsProviderContext();
|
|
1598
1601
|
const ref = useRef14(null);
|
|
1599
|
-
const [failed, setFailed] = useState8(
|
|
1602
|
+
const [failed, setFailed] = useState8(null);
|
|
1600
1603
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
1601
1604
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
1602
1605
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
1603
1606
|
const key = JSON.stringify(effect);
|
|
1607
|
+
const status = provider ? canvasEffectStatus(effect, provider) : null;
|
|
1604
1608
|
useEffect11(() => {
|
|
1605
1609
|
const canvas2 = ref.current;
|
|
1606
|
-
if (!provider || !canvas2) return;
|
|
1607
|
-
setFailed(
|
|
1608
|
-
const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: () => setFailed(
|
|
1610
|
+
if (!provider || !canvas2 || !canvasEffectStatus(effect, provider).ok) return;
|
|
1611
|
+
setFailed(null);
|
|
1612
|
+
const run = runCanvasNodeEffect({ provider, effect, target: canvas2, onError: (e) => setFailed(canvasEffectErrorReason(effect, e)) });
|
|
1609
1613
|
return () => run.stop();
|
|
1610
1614
|
}, [provider, key, pw, ph]);
|
|
1611
1615
|
const clipId = useMemo10(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
1612
|
-
if (!provider ||
|
|
1616
|
+
if (!provider || !status || !(width > 0 && height > 0)) return null;
|
|
1617
|
+
const missing = !status.ok ? status.reason : failed;
|
|
1618
|
+
if (missing) return /* @__PURE__ */ jsx5(CanvasEffectMissing, { reason: missing, effect, width, height, clipPath, clipTransform });
|
|
1613
1619
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
1614
1620
|
const canvas = /* @__PURE__ */ jsx5("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
|
|
1615
1621
|
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ jsx5("div", { style, children: canvas });
|
|
@@ -1618,6 +1624,16 @@ function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform
|
|
|
1618
1624
|
/* @__PURE__ */ jsx5("foreignObject", { x: 0, y: 0, width, height, clipPath: `url(#${clipId})`, children: canvas })
|
|
1619
1625
|
] });
|
|
1620
1626
|
}
|
|
1627
|
+
function CanvasEffectMissing({ reason, effect, width, height, clipPath, clipTransform }) {
|
|
1628
|
+
const id = useMemo10(() => `pixerate-effect-missing-${Math.random().toString(36).slice(2)}`, []);
|
|
1629
|
+
const common = { role: "img", "aria-label": reason, "data-canvas-effect-missing": effect.effect };
|
|
1630
|
+
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ jsx5("div", { ...common, title: reason, style: { position: "absolute", inset: 0, pointerEvents: "none", background: CANVAS_EFFECT_MISSING_PATTERN } });
|
|
1631
|
+
return /* @__PURE__ */ jsxs4("svg", { ...common, style: { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none" }, viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", children: [
|
|
1632
|
+
/* @__PURE__ */ jsx5("title", { children: reason }),
|
|
1633
|
+
/* @__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)" }) }) }),
|
|
1634
|
+
/* @__PURE__ */ jsx5("path", { d: clipPath, transform: clipTransform, fill: `url(#${id})` })
|
|
1635
|
+
] });
|
|
1636
|
+
}
|
|
1621
1637
|
function useCanvasEffects(options) {
|
|
1622
1638
|
const opts = useRef14(options);
|
|
1623
1639
|
opts.current = options;
|
|
@@ -1666,6 +1682,11 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
1666
1682
|
message && /* @__PURE__ */ jsx5("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
1667
1683
|
] });
|
|
1668
1684
|
}
|
|
1685
|
+
function EffectControlsOrReason({ controller, nodeId, effect }) {
|
|
1686
|
+
const status = controller.status(effect);
|
|
1687
|
+
if (!status.ok) return /* @__PURE__ */ jsx5("p", { className: "text-[11px] text-amber-500", "data-canvas-effect-unavailable": "", children: status.reason });
|
|
1688
|
+
return /* @__PURE__ */ jsx5(Controls, { controller, nodeId, effect });
|
|
1689
|
+
}
|
|
1669
1690
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
1670
1691
|
const [, setTick] = useState8(0);
|
|
1671
1692
|
useEffect11(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
@@ -1708,7 +1729,7 @@ function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = ""
|
|
|
1708
1729
|
] }),
|
|
1709
1730
|
/* @__PURE__ */ jsx5("button", { type: "button", className: btn, "aria-label": "Remove effect", onClick: () => run(() => controller.removeNodeEffect(nodeId)), children: "\u2715" })
|
|
1710
1731
|
] }),
|
|
1711
|
-
provider && /* @__PURE__ */ jsx5(
|
|
1732
|
+
provider && /* @__PURE__ */ jsx5(EffectControlsOrReason, { controller, nodeId, effect })
|
|
1712
1733
|
] }),
|
|
1713
1734
|
sceneId && transition && /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-1", "data-canvas-scene-transition": sceneId, children: [
|
|
1714
1735
|
/* @__PURE__ */ jsxs4("span", { className: "min-w-0 flex-1 truncate", children: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.152.
|
|
3
|
+
"version": "0.152.1",
|
|
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.227.
|
|
257
|
+
"@pixerate/editor": ">=0.227.1 <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.227.
|
|
308
|
+
"@pixerate/editor": "0.227.1"
|
|
309
309
|
},
|
|
310
310
|
"scripts": {
|
|
311
311
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|