@pixerate/editor-react 0.151.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
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: [
|
|
@@ -12,8 +12,9 @@ export declare function usePaintEffectsProvider(controller: PaintEditorControlle
|
|
|
12
12
|
export declare function usePaintEffectsTools(registry: ToolRegistry | null | undefined, controller: PaintEditorController, options?: PaintEffectsToolProviderOptions): void;
|
|
13
13
|
/**
|
|
14
14
|
* Provider effects in the paint editor: effect paper (a generator over the sheet, multiplied so
|
|
15
|
-
* the grain shows), effect layers, effect fills
|
|
16
|
-
* paint
|
|
15
|
+
* the grain shows), effect layers, effect fills, light baked onto the active layer's dried paint
|
|
16
|
+
* and effect paint (brushes take their colours from the effect); plus the controls of the effect
|
|
17
|
+
* paper, of an active effect layer and of the effect paint. Each change is one
|
|
17
18
|
* undo step (a slider drag is one). Without a provider it says why nothing can be added.
|
|
18
19
|
*/
|
|
19
20
|
export declare const PaintEffectsPanel: React.FC<PaintEffectsPanelProps>;
|
|
@@ -12,8 +12,9 @@ export declare function usePaintEffectsProvider(controller: PaintEditorControlle
|
|
|
12
12
|
export declare function usePaintEffectsTools(registry: ToolRegistry | null | undefined, controller: PaintEditorController, options?: PaintEffectsToolProviderOptions): void;
|
|
13
13
|
/**
|
|
14
14
|
* Provider effects in the paint editor: effect paper (a generator over the sheet, multiplied so
|
|
15
|
-
* the grain shows), effect layers, effect fills
|
|
16
|
-
* paint
|
|
15
|
+
* the grain shows), effect layers, effect fills, light baked onto the active layer's dried paint
|
|
16
|
+
* and effect paint (brushes take their colours from the effect); plus the controls of the effect
|
|
17
|
+
* paper, of an active effect layer and of the effect paint. Each change is one
|
|
17
18
|
* undo step (a slider drag is one). Without a provider it says why nothing can be added.
|
|
18
19
|
*/
|
|
19
20
|
export declare const PaintEffectsPanel: React.FC<PaintEffectsPanelProps>;
|
|
@@ -946,6 +946,7 @@ var ColorPanel = ({ controller, wheelSize = 168, mixingPad = true, className })
|
|
|
946
946
|
const harmony = (0, import_react8.useMemo)(() => controller.harmony(kind, { color, wheel }), [controller, kind, color, wheel]);
|
|
947
947
|
const [r, g, b] = (0, import_paint_editor8.parseHexColor)(color);
|
|
948
948
|
const hsv = (0, import_paint_editor8.rgbToHsv)(r, g, b);
|
|
949
|
+
const effectWell = (0, import_react8.useMemo)(() => state.effectPaint && !state.effectPaintRendering ? controller.effectPaintThumbnail(64) : null, [controller, state.effectPaint, state.effectPaintRendering]);
|
|
949
950
|
const pad = (0, import_react8.useMemo)(() => ({ width: import_paint_editor8.MIXING_PAD_WIDTH, height: import_paint_editor8.MIXING_PAD_HEIGHT, data: controller.mixingPad.pixels() }), [controller, state.mixingPadVersion]);
|
|
950
951
|
const R = wheelSize / 2;
|
|
951
952
|
const mid = R * 0.82;
|
|
@@ -1003,9 +1004,10 @@ var ColorPanel = ({ controller, wheelSize = 168, mixingPad = true, className })
|
|
|
1003
1004
|
"span",
|
|
1004
1005
|
{
|
|
1005
1006
|
className: "h-5 flex-1 rounded ring-1 ring-slate-700",
|
|
1006
|
-
"aria-label": state.paint.type === "gradient" ? "Gradient paint" : "Paint colour",
|
|
1007
|
+
"aria-label": state.effectPaint ? `Effect paint: ${state.effectPaint.effect}` : state.paint.type === "gradient" ? "Gradient paint" : "Paint colour",
|
|
1007
1008
|
"data-testid": "paint-well",
|
|
1008
|
-
|
|
1009
|
+
"data-effect-paint": state.effectPaint ? state.effectPaint.effect : void 0,
|
|
1010
|
+
style: { background: effectWell ? `center / cover no-repeat url("${effectWell}")` : (0, import_paint_editor9.paintSourceCss)(state.paint, { paint: color, secondary: state.secondaryColor }) }
|
|
1009
1011
|
}
|
|
1010
1012
|
),
|
|
1011
1013
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
@@ -3243,7 +3245,8 @@ var BROWSERS = {
|
|
|
3243
3245
|
paper: { uses: ["generator"], title: "Effect paper" },
|
|
3244
3246
|
layer: { uses: ["generator", "overlay", "title"], title: "Effect layer" },
|
|
3245
3247
|
fill: { uses: ["generator", "overlay", "title"], title: "Fill the layer" },
|
|
3246
|
-
light: { uses: ["filter"], title: "Light on the paint" }
|
|
3248
|
+
light: { uses: ["filter"], title: "Light on the paint" },
|
|
3249
|
+
paint: { uses: ["generator", "overlay", "title"], title: "Paint with an effect" }
|
|
3247
3250
|
};
|
|
3248
3251
|
var PaintEffectsPanel = ({ controller, className }) => {
|
|
3249
3252
|
const state = usePaintEditorState(controller);
|
|
@@ -3255,6 +3258,8 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
3255
3258
|
const activeId = state.document.activeLayerId;
|
|
3256
3259
|
const layerEffect = activeId ? controller.getEffectLayer(activeId) : void 0;
|
|
3257
3260
|
const active = activeId ? controller.getLayer(activeId) : void 0;
|
|
3261
|
+
const effectPaint = state.effectPaint;
|
|
3262
|
+
const thumbnail = (0, import_react23.useMemo)(() => effectPaint && !state.effectPaintRendering ? controller.effectPaintThumbnail(48) : null, [controller, effectPaint, state.effectPaintRendering]);
|
|
3258
3263
|
const run = (work) => attempt(() => {
|
|
3259
3264
|
setBusy(true);
|
|
3260
3265
|
return work().finally(() => setBusy(false));
|
|
@@ -3266,6 +3271,7 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
3266
3271
|
else if (kind === "layer") run(() => controller.addEffectLayer(id));
|
|
3267
3272
|
else if (kind === "fill") run(() => controller.fillLayerWithEffect(id));
|
|
3268
3273
|
else if (kind === "light" && activeId) run(() => controller.applyLightEffect(activeId, id));
|
|
3274
|
+
else if (kind === "paint") run(() => controller.setEffectPaint({ effect: id }));
|
|
3269
3275
|
};
|
|
3270
3276
|
const toggle = (b) => setBrowse(browse === b ? null : b);
|
|
3271
3277
|
const pixel = active?.type === "pixel";
|
|
@@ -3275,7 +3281,8 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
3275
3281
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "paper", onClick: () => toggle("paper"), children: "Paper\u2026" }),
|
|
3276
3282
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "layer", onClick: () => toggle("layer"), children: "Layer\u2026" }),
|
|
3277
3283
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "fill", onClick: () => toggle("fill"), children: "Fill\u2026" }),
|
|
3278
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "light", onClick: () => toggle("light"), title: "Bake a light, glow or grade into the active layer's dried paint", children: "Light\u2026" })
|
|
3284
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "light", onClick: () => toggle("light"), title: "Bake a light, glow or grade into the active layer's dried paint", children: "Light\u2026" }),
|
|
3285
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "paint", onClick: () => toggle("paint"), title: "Paint with an effect: brushes take each pixel's colour from it", children: "Paint\u2026" })
|
|
3279
3286
|
] }),
|
|
3280
3287
|
!provider && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-[11px] text-slate-400", children: "No effects provider is registered. Effects in the painting are kept." }),
|
|
3281
3288
|
browse && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(EffectsBrowser, { provider, uses: BROWSERS[browse].uses, title: BROWSERS[browse].title, onPick: (e) => pick(e.id) }),
|
|
@@ -3320,6 +3327,18 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
3320
3327
|
] }),
|
|
3321
3328
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Controls, { provider, effect: paper.effect, name: paper.name, values: paper.values, apply: (values, commit) => run(() => controller.updatePaperEffect({ values }, commit)) })
|
|
3322
3329
|
] }),
|
|
3330
|
+
effectPaint && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "paint", children: [
|
|
3331
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3332
|
+
thumbnail ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("img", { src: thumbnail, alt: "", className: "h-5 w-8 rounded object-cover ring-1 ring-slate-700", "data-testid": "effect-paint-thumbnail" }) : null,
|
|
3333
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "flex-1 truncate", children: [
|
|
3334
|
+
"Paint: ",
|
|
3335
|
+
effectPaint.effect,
|
|
3336
|
+
state.effectPaintRendering ? " (rendering\u2026)" : ""
|
|
3337
|
+
] }),
|
|
3338
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: button, "aria-label": "Stop painting with the effect", onClick: () => attempt(() => controller.setColor(state.color)), children: "\u2715" })
|
|
3339
|
+
] }),
|
|
3340
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Controls, { provider, effect: effectPaint.effect, values: effectPaint.values, apply: (values) => run(() => controller.setEffectPaint({ effect: effectPaint.effect, values: { ...effectPaint.values, ...values }, time: effectPaint.time })) })
|
|
3341
|
+
] }),
|
|
3323
3342
|
layerEffect && activeId && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "layer", children: [
|
|
3324
3343
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3325
3344
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "flex-1 truncate", children: [
|
|
@@ -833,6 +833,7 @@ var ColorPanel = ({ controller, wheelSize = 168, mixingPad = true, className })
|
|
|
833
833
|
const harmony = useMemo5(() => controller.harmony(kind, { color, wheel }), [controller, kind, color, wheel]);
|
|
834
834
|
const [r, g, b] = parseHexColor(color);
|
|
835
835
|
const hsv = rgbToHsv(r, g, b);
|
|
836
|
+
const effectWell = useMemo5(() => state.effectPaint && !state.effectPaintRendering ? controller.effectPaintThumbnail(64) : null, [controller, state.effectPaint, state.effectPaintRendering]);
|
|
836
837
|
const pad = useMemo5(() => ({ width: MIXING_PAD_WIDTH, height: MIXING_PAD_HEIGHT, data: controller.mixingPad.pixels() }), [controller, state.mixingPadVersion]);
|
|
837
838
|
const R = wheelSize / 2;
|
|
838
839
|
const mid = R * 0.82;
|
|
@@ -890,9 +891,10 @@ var ColorPanel = ({ controller, wheelSize = 168, mixingPad = true, className })
|
|
|
890
891
|
"span",
|
|
891
892
|
{
|
|
892
893
|
className: "h-5 flex-1 rounded ring-1 ring-slate-700",
|
|
893
|
-
"aria-label": state.paint.type === "gradient" ? "Gradient paint" : "Paint colour",
|
|
894
|
+
"aria-label": state.effectPaint ? `Effect paint: ${state.effectPaint.effect}` : state.paint.type === "gradient" ? "Gradient paint" : "Paint colour",
|
|
894
895
|
"data-testid": "paint-well",
|
|
895
|
-
|
|
896
|
+
"data-effect-paint": state.effectPaint ? state.effectPaint.effect : void 0,
|
|
897
|
+
style: { background: effectWell ? `center / cover no-repeat url("${effectWell}")` : paintSourceCss(state.paint, { paint: color, secondary: state.secondaryColor }) }
|
|
896
898
|
}
|
|
897
899
|
),
|
|
898
900
|
/* @__PURE__ */ jsx7(
|
|
@@ -1228,7 +1230,7 @@ import { useRef as useRef7, useState as useState10 } from "react";
|
|
|
1228
1230
|
import { PaintPresence as PaintPresence2, documentToScreen as documentToScreen2, screenToDocument } from "@pixerate/editor/paint-editor";
|
|
1229
1231
|
|
|
1230
1232
|
// src/paint-editor/PaintEffectsPanel.tsx
|
|
1231
|
-
import { useEffect as useEffect4, useRef as useRef6, useState as useState9 } from "react";
|
|
1233
|
+
import { useEffect as useEffect4, useMemo as useMemo6, useRef as useRef6, useState as useState9 } from "react";
|
|
1232
1234
|
import { createPaintEffectsToolProvider, PAPER_EFFECT_BLENDS } from "@pixerate/editor/paint-editor";
|
|
1233
1235
|
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1234
1236
|
function usePaintEffectsProvider(controller) {
|
|
@@ -1276,7 +1278,8 @@ var BROWSERS = {
|
|
|
1276
1278
|
paper: { uses: ["generator"], title: "Effect paper" },
|
|
1277
1279
|
layer: { uses: ["generator", "overlay", "title"], title: "Effect layer" },
|
|
1278
1280
|
fill: { uses: ["generator", "overlay", "title"], title: "Fill the layer" },
|
|
1279
|
-
light: { uses: ["filter"], title: "Light on the paint" }
|
|
1281
|
+
light: { uses: ["filter"], title: "Light on the paint" },
|
|
1282
|
+
paint: { uses: ["generator", "overlay", "title"], title: "Paint with an effect" }
|
|
1280
1283
|
};
|
|
1281
1284
|
var PaintEffectsPanel = ({ controller, className }) => {
|
|
1282
1285
|
const state = usePaintEditorState(controller);
|
|
@@ -1288,6 +1291,8 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
1288
1291
|
const activeId = state.document.activeLayerId;
|
|
1289
1292
|
const layerEffect = activeId ? controller.getEffectLayer(activeId) : void 0;
|
|
1290
1293
|
const active = activeId ? controller.getLayer(activeId) : void 0;
|
|
1294
|
+
const effectPaint = state.effectPaint;
|
|
1295
|
+
const thumbnail = useMemo6(() => effectPaint && !state.effectPaintRendering ? controller.effectPaintThumbnail(48) : null, [controller, effectPaint, state.effectPaintRendering]);
|
|
1291
1296
|
const run = (work) => attempt(() => {
|
|
1292
1297
|
setBusy(true);
|
|
1293
1298
|
return work().finally(() => setBusy(false));
|
|
@@ -1299,6 +1304,7 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
1299
1304
|
else if (kind === "layer") run(() => controller.addEffectLayer(id));
|
|
1300
1305
|
else if (kind === "fill") run(() => controller.fillLayerWithEffect(id));
|
|
1301
1306
|
else if (kind === "light" && activeId) run(() => controller.applyLightEffect(activeId, id));
|
|
1307
|
+
else if (kind === "paint") run(() => controller.setEffectPaint({ effect: id }));
|
|
1302
1308
|
};
|
|
1303
1309
|
const toggle = (b) => setBrowse(browse === b ? null : b);
|
|
1304
1310
|
const pixel = active?.type === "pixel";
|
|
@@ -1308,7 +1314,8 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
1308
1314
|
/* @__PURE__ */ jsx11("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "paper", onClick: () => toggle("paper"), children: "Paper\u2026" }),
|
|
1309
1315
|
/* @__PURE__ */ jsx11("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "layer", onClick: () => toggle("layer"), children: "Layer\u2026" }),
|
|
1310
1316
|
/* @__PURE__ */ jsx11("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "fill", onClick: () => toggle("fill"), children: "Fill\u2026" }),
|
|
1311
|
-
/* @__PURE__ */ jsx11("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "light", onClick: () => toggle("light"), title: "Bake a light, glow or grade into the active layer's dried paint", children: "Light\u2026" })
|
|
1317
|
+
/* @__PURE__ */ jsx11("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "light", onClick: () => toggle("light"), title: "Bake a light, glow or grade into the active layer's dried paint", children: "Light\u2026" }),
|
|
1318
|
+
/* @__PURE__ */ jsx11("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "paint", onClick: () => toggle("paint"), title: "Paint with an effect: brushes take each pixel's colour from it", children: "Paint\u2026" })
|
|
1312
1319
|
] }),
|
|
1313
1320
|
!provider && /* @__PURE__ */ jsx11("p", { className: "text-[11px] text-slate-400", children: "No effects provider is registered. Effects in the painting are kept." }),
|
|
1314
1321
|
browse && /* @__PURE__ */ jsx11(EffectsBrowser, { provider, uses: BROWSERS[browse].uses, title: BROWSERS[browse].title, onPick: (e) => pick(e.id) }),
|
|
@@ -1353,6 +1360,18 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
1353
1360
|
] }),
|
|
1354
1361
|
/* @__PURE__ */ jsx11(Controls, { provider, effect: paper.effect, name: paper.name, values: paper.values, apply: (values, commit) => run(() => controller.updatePaperEffect({ values }, commit)) })
|
|
1355
1362
|
] }),
|
|
1363
|
+
effectPaint && /* @__PURE__ */ jsxs10("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "paint", children: [
|
|
1364
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-1", children: [
|
|
1365
|
+
thumbnail ? /* @__PURE__ */ jsx11("img", { src: thumbnail, alt: "", className: "h-5 w-8 rounded object-cover ring-1 ring-slate-700", "data-testid": "effect-paint-thumbnail" }) : null,
|
|
1366
|
+
/* @__PURE__ */ jsxs10("span", { className: "flex-1 truncate", children: [
|
|
1367
|
+
"Paint: ",
|
|
1368
|
+
effectPaint.effect,
|
|
1369
|
+
state.effectPaintRendering ? " (rendering\u2026)" : ""
|
|
1370
|
+
] }),
|
|
1371
|
+
/* @__PURE__ */ jsx11("button", { type: "button", className: button, "aria-label": "Stop painting with the effect", onClick: () => attempt(() => controller.setColor(state.color)), children: "\u2715" })
|
|
1372
|
+
] }),
|
|
1373
|
+
/* @__PURE__ */ jsx11(Controls, { provider, effect: effectPaint.effect, values: effectPaint.values, apply: (values) => run(() => controller.setEffectPaint({ effect: effectPaint.effect, values: { ...effectPaint.values, ...values }, time: effectPaint.time })) })
|
|
1374
|
+
] }),
|
|
1356
1375
|
layerEffect && activeId && /* @__PURE__ */ jsxs10("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "layer", children: [
|
|
1357
1376
|
/* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-1", children: [
|
|
1358
1377
|
/* @__PURE__ */ jsxs10("span", { className: "flex-1 truncate", children: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
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.
|
|
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.
|
|
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",
|