@pixerate/editor-react 0.173.0 → 0.175.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/paint-editor/PaintCanvas.d.cts +9 -1
- package/dist/paint-editor/PaintCanvas.d.ts +9 -1
- package/dist/paint-editor/PaintEditor.d.cts +3 -1
- package/dist/paint-editor/PaintEditor.d.ts +3 -1
- package/dist/paint-editor/index.cjs +107 -21
- package/dist/paint-editor/index.js +146 -55
- package/dist/paint-editor/usePaintEditor.d.cts +30 -1
- package/dist/paint-editor/usePaintEditor.d.ts +30 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type PaintEditorController, type PaintPresence, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
|
|
2
|
+
import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
|
|
3
3
|
export interface PaintCanvasProps {
|
|
4
4
|
controller: PaintEditorController;
|
|
5
5
|
/** The active tool (default brush). */
|
|
@@ -12,6 +12,8 @@ export interface PaintCanvasProps {
|
|
|
12
12
|
onError?: (message: string | null) => void;
|
|
13
13
|
/** Agent cursors to draw over the canvas (see `PaintDirector` and `usePaintDirector`). */
|
|
14
14
|
presence?: PaintPresence;
|
|
15
|
+
/** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
|
|
16
|
+
proposals?: PaintProposals;
|
|
15
17
|
className?: string;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
@@ -38,3 +40,9 @@ export declare const PaintPresenceLayer: React.FC<{
|
|
|
38
40
|
height: number;
|
|
39
41
|
};
|
|
40
42
|
}>;
|
|
43
|
+
/** Pending paint proposals drawn over the canvas: each ghost where its paint would go, translucent with a dashed edge. */
|
|
44
|
+
export declare const PaintProposalGhosts: React.FC<{
|
|
45
|
+
proposals: PaintProposals;
|
|
46
|
+
transform: string;
|
|
47
|
+
zoom: number;
|
|
48
|
+
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type PaintEditorController, type PaintPresence, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
|
|
2
|
+
import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
|
|
3
3
|
export interface PaintCanvasProps {
|
|
4
4
|
controller: PaintEditorController;
|
|
5
5
|
/** The active tool (default brush). */
|
|
@@ -12,6 +12,8 @@ export interface PaintCanvasProps {
|
|
|
12
12
|
onError?: (message: string | null) => void;
|
|
13
13
|
/** Agent cursors to draw over the canvas (see `PaintDirector` and `usePaintDirector`). */
|
|
14
14
|
presence?: PaintPresence;
|
|
15
|
+
/** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
|
|
16
|
+
proposals?: PaintProposals;
|
|
15
17
|
className?: string;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
@@ -38,3 +40,9 @@ export declare const PaintPresenceLayer: React.FC<{
|
|
|
38
40
|
height: number;
|
|
39
41
|
};
|
|
40
42
|
}>;
|
|
43
|
+
/** Pending paint proposals drawn over the canvas: each ghost where its paint would go, translucent with a dashed edge. */
|
|
44
|
+
export declare const PaintProposalGhosts: React.FC<{
|
|
45
|
+
proposals: PaintProposals;
|
|
46
|
+
transform: string;
|
|
47
|
+
zoom: number;
|
|
48
|
+
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { PaintPresence, type PaintEditorController } from '@pixerate/editor/paint-editor';
|
|
2
|
+
import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
|
|
3
3
|
import type { AgentPlayback } from '@pixerate/editor/tools';
|
|
4
4
|
export interface PaintEditorProps {
|
|
5
5
|
controller: PaintEditorController;
|
|
@@ -9,6 +9,8 @@ export interface PaintEditorProps {
|
|
|
9
9
|
height?: number | string;
|
|
10
10
|
/** Agent cursors to draw over the canvas (see `usePaintDirector`). */
|
|
11
11
|
presence?: PaintPresence;
|
|
12
|
+
/** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
|
|
13
|
+
proposals?: PaintProposals;
|
|
12
14
|
className?: string;
|
|
13
15
|
/**
|
|
14
16
|
* Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { PaintPresence, type PaintEditorController } from '@pixerate/editor/paint-editor';
|
|
2
|
+
import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
|
|
3
3
|
import type { AgentPlayback } from '@pixerate/editor/tools';
|
|
4
4
|
export interface PaintEditorProps {
|
|
5
5
|
controller: PaintEditorController;
|
|
@@ -9,6 +9,8 @@ export interface PaintEditorProps {
|
|
|
9
9
|
height?: number | string;
|
|
10
10
|
/** Agent cursors to draw over the canvas (see `usePaintDirector`). */
|
|
11
11
|
presence?: PaintPresence;
|
|
12
|
+
/** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
|
|
13
|
+
proposals?: PaintProposals;
|
|
12
14
|
className?: string;
|
|
13
15
|
/**
|
|
14
16
|
* Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
|
|
@@ -41,6 +41,7 @@ __export(paint_editor_exports, {
|
|
|
41
41
|
PaintGradientEditor: () => PaintGradientEditor,
|
|
42
42
|
PaintLayersPanel: () => PaintLayersPanel,
|
|
43
43
|
PaintPresenceLayer: () => PaintPresenceLayer,
|
|
44
|
+
PaintProposalGhosts: () => PaintProposalGhosts,
|
|
44
45
|
PaintSlider: () => PaintSlider,
|
|
45
46
|
PaintToolbar: () => PaintToolbar,
|
|
46
47
|
PaperPanel: () => PaperPanel,
|
|
@@ -48,11 +49,13 @@ __export(paint_editor_exports, {
|
|
|
48
49
|
StickerPicker: () => StickerPicker,
|
|
49
50
|
StrokePanel: () => StrokePanel,
|
|
50
51
|
WetPanel: () => WetPanel,
|
|
52
|
+
usePaintChangeFeed: () => usePaintChangeFeed,
|
|
51
53
|
usePaintDirector: () => usePaintDirector,
|
|
52
54
|
usePaintEditor: () => usePaintEditor,
|
|
53
55
|
usePaintEditorState: () => usePaintEditorState,
|
|
54
56
|
usePaintEffectsProvider: () => usePaintEffectsProvider,
|
|
55
|
-
usePaintEffectsTools: () => usePaintEffectsTools
|
|
57
|
+
usePaintEffectsTools: () => usePaintEffectsTools,
|
|
58
|
+
usePaintProposals: () => usePaintProposals
|
|
56
59
|
});
|
|
57
60
|
module.exports = __toCommonJS(paint_editor_exports);
|
|
58
61
|
|
|
@@ -80,12 +83,33 @@ function usePaintDirector(controller, options = {}) {
|
|
|
80
83
|
});
|
|
81
84
|
return value;
|
|
82
85
|
}
|
|
86
|
+
function usePaintProposals(controller, options = {}) {
|
|
87
|
+
const [store] = (0, import_react.useState)(() => (0, import_paint_editor.createPaintProposals)({ ...options, controller }));
|
|
88
|
+
const state = (0, import_react.useSyncExternalStore)(store.subscribe, store.getState, store.getState);
|
|
89
|
+
return (0, import_react.useMemo)(() => ({ store, proposals: state.proposals, propose: store.propose, accept: store.accept, reject: store.reject, clear: store.clear }), [store, state]);
|
|
90
|
+
}
|
|
91
|
+
function usePaintChangeFeed(controller, options = {}) {
|
|
92
|
+
const onChange = (0, import_react.useRef)(options.onChange);
|
|
93
|
+
onChange.current = options.onChange;
|
|
94
|
+
const [last, setLast] = (0, import_react.useState)(null);
|
|
95
|
+
const [feed, setFeed] = (0, import_react.useState)(null);
|
|
96
|
+
(0, import_react.useEffect)(() => {
|
|
97
|
+
const next = (0, import_paint_editor.createPaintChangeFeed)(controller);
|
|
98
|
+
next.subscribe((change) => {
|
|
99
|
+
setLast(change);
|
|
100
|
+
onChange.current?.(change);
|
|
101
|
+
});
|
|
102
|
+
setFeed(next);
|
|
103
|
+
return () => next.dispose();
|
|
104
|
+
}, [controller]);
|
|
105
|
+
return { feed, last };
|
|
106
|
+
}
|
|
83
107
|
|
|
84
108
|
// src/paint-editor/PaintCanvas.tsx
|
|
85
109
|
var import_react2 = require("react");
|
|
86
110
|
var import_paint_editor2 = require("@pixerate/editor/paint-editor");
|
|
87
111
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
88
|
-
var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, className }) => {
|
|
112
|
+
var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
|
|
89
113
|
const state = usePaintEditorState(controller);
|
|
90
114
|
const viewport = (0, import_react2.useRef)(null);
|
|
91
115
|
const canvas = (0, import_react2.useRef)(null);
|
|
@@ -226,6 +250,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
|
|
|
226
250
|
predicted.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: predicted.map((p) => `${p.x},${p.y}`).join(" "), fill: "none", stroke: state.color, strokeOpacity: 0.5, strokeWidth: Math.max(1, state.brush.tip.size / 2), strokeLinecap: "round" })
|
|
227
251
|
] }),
|
|
228
252
|
state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReferencePanel, { controller, id: r.id }, r.id)),
|
|
253
|
+
proposals && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintProposalGhosts, { proposals, transform, zoom: state.view.zoom }),
|
|
229
254
|
presence && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintPresenceLayer, { presence, view: state.view, canvas: doc, viewport: size }),
|
|
230
255
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "absolute bottom-1 right-2 text-[10px] text-slate-500 pointer-events-none", "data-testid": "paint-view-status", children: [
|
|
231
256
|
Math.round(state.view.zoom * 100),
|
|
@@ -301,6 +326,33 @@ var ReferencePanel = ({ controller, id }) => {
|
|
|
301
326
|
}
|
|
302
327
|
);
|
|
303
328
|
};
|
|
329
|
+
var PaintProposalGhosts = ({ proposals, transform, zoom }) => {
|
|
330
|
+
const { proposals: pending } = (0, import_react2.useSyncExternalStore)(proposals.subscribe, proposals.getState, proposals.getState);
|
|
331
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: pending.map((p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintProposalGhost, { proposal: p, transform, zoom }, p.id)) });
|
|
332
|
+
};
|
|
333
|
+
var PaintProposalGhost = ({ proposal, transform, zoom }) => {
|
|
334
|
+
const ref = (0, import_react2.useRef)(null);
|
|
335
|
+
const ghost = (0, import_paint_editor2.paintProposalGhost)(proposal);
|
|
336
|
+
(0, import_react2.useEffect)(() => {
|
|
337
|
+
const ctx = ref.current?.getContext("2d");
|
|
338
|
+
if (!ctx || !ghost || typeof ImageData === "undefined") return;
|
|
339
|
+
ctx.putImageData(new ImageData(new Uint8ClampedArray(ghost.data), ghost.width, ghost.height), 0, 0);
|
|
340
|
+
}, [ghost?.data]);
|
|
341
|
+
if (!ghost) return null;
|
|
342
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
343
|
+
"canvas",
|
|
344
|
+
{
|
|
345
|
+
ref,
|
|
346
|
+
width: ghost.width,
|
|
347
|
+
height: ghost.height,
|
|
348
|
+
"data-paint-proposal": proposal.id,
|
|
349
|
+
title: proposal.rationale ? `${proposal.title}: ${proposal.rationale}` : proposal.title,
|
|
350
|
+
"aria-label": `Suggested: ${proposal.title}`,
|
|
351
|
+
className: "absolute left-0 top-0 pointer-events-none",
|
|
352
|
+
style: { transform: `${transform} translate(${ghost.x}px, ${ghost.y}px)`, transformOrigin: "0 0", opacity: 0.7, outline: `${1.5 / zoom}px dashed #a78bfa`, outlineOffset: `${2 / zoom}px` }
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
};
|
|
304
356
|
|
|
305
357
|
// src/paint-editor/PaintToolbar.tsx
|
|
306
358
|
var import_react4 = require("react");
|
|
@@ -673,20 +725,43 @@ var EditorControl = ({ control: c, onSet }) => {
|
|
|
673
725
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
674
726
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { "aria-label": c.ariaLabel, defaultValue: c.value, placeholder: c.placeholder, onBlur: (e) => e.target.value !== c.value && onSet(c.path, e.target.value.trim().toLowerCase()), className: "w-28 rounded bg-slate-800 px-1.5 py-0.5" }, c.value)
|
|
675
727
|
] });
|
|
676
|
-
case "colour":
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("
|
|
680
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("
|
|
681
|
-
|
|
728
|
+
case "colour": {
|
|
729
|
+
const set = (light, dark) => onSet(c.path, dark === null ? light : { light, dark });
|
|
730
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col gap-1", children: [
|
|
731
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center justify-between gap-2", children: [
|
|
732
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
733
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "flex items-center gap-1", children: [
|
|
734
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "color", "aria-label": c.ariaLabel, title: c.dark !== null ? "On light backgrounds" : void 0, value: c.value ?? "#000000", onChange: (e) => set(e.target.value, c.dark), className: "h-5 w-8" }),
|
|
735
|
+
c.dark !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "color", "aria-label": `${c.ariaLabel} (dark)`, title: "On dark backgrounds", value: c.dark, onChange: (e) => set(c.value ?? "#000000", e.target.value), className: "h-5 w-8" }),
|
|
736
|
+
(c.value || c.gradient) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: button, onClick: () => onSet(c.path, void 0), children: "None" })
|
|
737
|
+
] })
|
|
738
|
+
] }),
|
|
739
|
+
c.gradient ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-[10px] text-slate-500", children: "A gradient (its own paint)." }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "flex items-center gap-2", children: [
|
|
740
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "checkbox", "aria-label": `${c.ariaLabel}: light and dark`, checked: c.dark !== null, onChange: (e) => set(c.value ?? "#000000", e.target.checked ? c.value ?? "#ffffff" : null) }),
|
|
741
|
+
" Light / dark"
|
|
682
742
|
] })
|
|
683
743
|
] });
|
|
684
|
-
|
|
685
|
-
|
|
744
|
+
}
|
|
745
|
+
case "palette": {
|
|
746
|
+
const at = (i, entry) => onSet(c.path, c.value.map((x, j) => j === i ? entry : x));
|
|
747
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col gap-1", role: "group", "aria-label": c.ariaLabel, children: [
|
|
686
748
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
687
|
-
|
|
688
|
-
|
|
749
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
750
|
+
c.value.map((col, i) => {
|
|
751
|
+
const light = typeof col === "string" ? col : col.light;
|
|
752
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "flex items-center gap-0.5 rounded bg-slate-900 p-0.5", children: [
|
|
753
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "color", "aria-label": `Palette colour ${i + 1}`, value: light, onChange: (e) => at(i, typeof col === "string" ? e.target.value : { ...col, light: e.target.value }), className: "h-4 w-5" }),
|
|
754
|
+
typeof col !== "string" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "color", "aria-label": `Palette colour ${i + 1} (dark)`, value: col.dark, onChange: (e) => at(i, { ...col, dark: e.target.value }), className: "h-4 w-5" }),
|
|
755
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", "aria-label": `Remove palette colour ${i + 1}`, className: "px-0.5 text-slate-400 hover:text-white", onClick: () => onSet(c.path, c.value.filter((_, j) => j !== i)), children: "\xD7" })
|
|
756
|
+
] }, i);
|
|
757
|
+
}),
|
|
758
|
+
c.value.length < c.max && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
759
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "color", "aria-label": "Add a palette colour", onChange: (e) => onSet(c.path, [...c.value, e.target.value]), className: "h-4 w-6" }),
|
|
760
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: button, onClick: () => onSet(c.path, [...c.value, { light: "#334155", dark: "#e2e8f0" }]), children: "Add light / dark pair" })
|
|
761
|
+
] })
|
|
762
|
+
] })
|
|
689
763
|
] });
|
|
764
|
+
}
|
|
690
765
|
case "stamps":
|
|
691
766
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex flex-wrap gap-1", role: "group", "aria-label": c.ariaLabel, title: `Up to ${c.max}`, children: c.options.map((o) => {
|
|
692
767
|
const on = c.value.includes(o.value);
|
|
@@ -967,6 +1042,7 @@ var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, clas
|
|
|
967
1042
|
const own = typeof spec.colour?.default === "string" && /^#[0-9a-f]{6}/i.test(spec.colour.default) ? spec.colour.default.slice(0, 7) : void 0;
|
|
968
1043
|
const preview = (0, import_react10.useMemo)(() => controller.brushThumbnail(brush.id, { width: 240, height: 64, color: own }), [controller, brush, paper, state.color, own]);
|
|
969
1044
|
const carried = (0, import_paint_editor5.brushLoadColor)(state.mixerLoad);
|
|
1045
|
+
const palette = (spec.colour?.palette ?? []).flatMap((c) => (0, import_brushes3.brushColourHex)(c, state.colorScheme) ?? []);
|
|
970
1046
|
const slug = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "brush";
|
|
971
1047
|
const loads = ["dab", "mixer", "impasto"].includes(brush.engine) || brush.engine === "wet" && brush.wet.tool === "paint";
|
|
972
1048
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `${panel} ${className ?? ""}`, "data-testid": "brush-panel", children: [
|
|
@@ -989,13 +1065,20 @@ var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, clas
|
|
|
989
1065
|
brush.engine === "mixer" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: button, onClick: () => controller.loadMixerBrush(), children: "Load" }),
|
|
990
1066
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: button, onClick: () => controller.cleanMixerBrush(brush.engine === "mixer"), children: "Clean" })
|
|
991
1067
|
] });
|
|
992
|
-
if (section === "colour"
|
|
993
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
994
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.
|
|
995
|
-
|
|
996
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("
|
|
1068
|
+
if (section === "colour")
|
|
1069
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
1070
|
+
palette.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex flex-wrap items-center gap-1", role: "group", "aria-label": "Paint with a palette colour", children: palette.map((hex, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-label": `Paint with ${hex}`, title: hex, "aria-pressed": state.color === hex, className: `h-5 w-5 rounded ring-1 ${state.color === hex ? "ring-white" : "ring-slate-700"}`, style: { background: hex }, onClick: () => controller.setColor(hex) }, `${hex}-${i}`)) }),
|
|
1071
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { className: "flex items-center gap-2", title: "Choosing a brush with a default colour (the highlighter's yellow) makes it your colour unless this is on", children: [
|
|
1072
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("input", { type: "checkbox", "aria-label": "Keep my colour", checked: state.colorLocked, onChange: (e) => controller.setColorLocked(e.target.checked) }),
|
|
1073
|
+
" Keep my colour when choosing a brush"
|
|
997
1074
|
] }),
|
|
998
|
-
brush
|
|
1075
|
+
(0, import_paint_editor5.brushTakesPaint)(brush) && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex flex-col gap-1.5", "data-testid": "brush-gradient", children: [
|
|
1076
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex items-center justify-between gap-2", children: [
|
|
1077
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "text-slate-400", title: "A gradient of the brush's own, used instead of the paint (the multi-colour brush)", children: "Brush gradient" }),
|
|
1078
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-pressed": brush.paint !== null, className: chip(brush.paint !== null), onClick: () => attempt(() => controller.setBrush({ paint: brush.paint ? null : import_paint_editor5.DEFAULT_PAINT_GRADIENT })), children: brush.paint ? "On" : "Off" })
|
|
1079
|
+
] }),
|
|
1080
|
+
brush.paint && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PaintGradientEditor, { value: brush.paint, colors: { paint: state.color, secondary: state.secondaryColor }, onChange: (g) => attempt(() => controller.setBrush({ paint: g })) })
|
|
1081
|
+
] })
|
|
999
1082
|
] });
|
|
1000
1083
|
return null;
|
|
1001
1084
|
}
|
|
@@ -3913,7 +3996,7 @@ var PAINT_CONTROLS = {
|
|
|
3913
3996
|
lighting: '[data-testid="light-panel"]',
|
|
3914
3997
|
symmetry: '[aria-label="Symmetry"]'
|
|
3915
3998
|
};
|
|
3916
|
-
var PaintEditor = ({ controller, fileName, height = 720, presence, className, playback, playbackId = "paint", onPlaybackReveal }) => {
|
|
3999
|
+
var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
|
|
3917
4000
|
const [tool, setTool] = (0, import_react29.useState)("brush");
|
|
3918
4001
|
const [tab, setTab] = (0, import_react29.useState)("color");
|
|
3919
4002
|
const tabRef = (0, import_react29.useRef)(tab);
|
|
@@ -3984,7 +4067,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
|
|
|
3984
4067
|
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-h-0 flex-1 gap-2", children: [
|
|
3985
4068
|
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
|
|
3986
4069
|
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
3987
|
-
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, className: "flex-1 rounded-lg" }),
|
|
4070
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
|
|
3988
4071
|
error && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
|
|
3989
4072
|
] }),
|
|
3990
4073
|
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
|
|
@@ -4014,6 +4097,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
|
|
|
4014
4097
|
PaintGradientEditor,
|
|
4015
4098
|
PaintLayersPanel,
|
|
4016
4099
|
PaintPresenceLayer,
|
|
4100
|
+
PaintProposalGhosts,
|
|
4017
4101
|
PaintSlider,
|
|
4018
4102
|
PaintToolbar,
|
|
4019
4103
|
PaperPanel,
|
|
@@ -4021,9 +4105,11 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
|
|
|
4021
4105
|
StickerPicker,
|
|
4022
4106
|
StrokePanel,
|
|
4023
4107
|
WetPanel,
|
|
4108
|
+
usePaintChangeFeed,
|
|
4024
4109
|
usePaintDirector,
|
|
4025
4110
|
usePaintEditor,
|
|
4026
4111
|
usePaintEditorState,
|
|
4027
4112
|
usePaintEffectsProvider,
|
|
4028
|
-
usePaintEffectsTools
|
|
4113
|
+
usePaintEffectsTools,
|
|
4114
|
+
usePaintProposals
|
|
4029
4115
|
});
|
|
@@ -23,8 +23,15 @@ import {
|
|
|
23
23
|
} from "../chunk-62FMEDGG.js";
|
|
24
24
|
|
|
25
25
|
// src/paint-editor/usePaintEditor.ts
|
|
26
|
-
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
27
|
-
import {
|
|
26
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
27
|
+
import {
|
|
28
|
+
PaintDirector,
|
|
29
|
+
PaintEditorController,
|
|
30
|
+
PaintPresence,
|
|
31
|
+
createPaintChangeFeed,
|
|
32
|
+
createPaintEditorDocument,
|
|
33
|
+
createPaintProposals
|
|
34
|
+
} from "@pixerate/editor/paint-editor";
|
|
28
35
|
function usePaintEditor(options = {}) {
|
|
29
36
|
const [controller] = useState(() => options instanceof PaintEditorController ? options : new PaintEditorController(options));
|
|
30
37
|
const state = usePaintEditorState(controller);
|
|
@@ -46,9 +53,30 @@ function usePaintDirector(controller, options = {}) {
|
|
|
46
53
|
});
|
|
47
54
|
return value;
|
|
48
55
|
}
|
|
56
|
+
function usePaintProposals(controller, options = {}) {
|
|
57
|
+
const [store] = useState(() => createPaintProposals({ ...options, controller }));
|
|
58
|
+
const state = useSyncExternalStore(store.subscribe, store.getState, store.getState);
|
|
59
|
+
return useMemo(() => ({ store, proposals: state.proposals, propose: store.propose, accept: store.accept, reject: store.reject, clear: store.clear }), [store, state]);
|
|
60
|
+
}
|
|
61
|
+
function usePaintChangeFeed(controller, options = {}) {
|
|
62
|
+
const onChange = useRef(options.onChange);
|
|
63
|
+
onChange.current = options.onChange;
|
|
64
|
+
const [last, setLast] = useState(null);
|
|
65
|
+
const [feed, setFeed] = useState(null);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const next = createPaintChangeFeed(controller);
|
|
68
|
+
next.subscribe((change) => {
|
|
69
|
+
setLast(change);
|
|
70
|
+
onChange.current?.(change);
|
|
71
|
+
});
|
|
72
|
+
setFeed(next);
|
|
73
|
+
return () => next.dispose();
|
|
74
|
+
}, [controller]);
|
|
75
|
+
return { feed, last };
|
|
76
|
+
}
|
|
49
77
|
|
|
50
78
|
// src/paint-editor/PaintCanvas.tsx
|
|
51
|
-
import { useEffect as useEffect2, useMemo as useMemo2, useRef, useState as useState2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
79
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
52
80
|
import {
|
|
53
81
|
PaintCanvasPresenter,
|
|
54
82
|
PaintGesture,
|
|
@@ -58,16 +86,17 @@ import {
|
|
|
58
86
|
fitZoom,
|
|
59
87
|
guideOverlay,
|
|
60
88
|
handlePaintShortcut,
|
|
61
|
-
viewCssTransform
|
|
89
|
+
viewCssTransform,
|
|
90
|
+
paintProposalGhost
|
|
62
91
|
} from "@pixerate/editor/paint-editor";
|
|
63
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
64
|
-
var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, className }) => {
|
|
92
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
93
|
+
var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
|
|
65
94
|
const state = usePaintEditorState(controller);
|
|
66
|
-
const viewport =
|
|
67
|
-
const canvas =
|
|
68
|
-
const water =
|
|
95
|
+
const viewport = useRef2(null);
|
|
96
|
+
const canvas = useRef2(null);
|
|
97
|
+
const water = useRef2(null);
|
|
69
98
|
const [size, setSize] = useState2({ width: 800, height: 600 });
|
|
70
|
-
const measured =
|
|
99
|
+
const measured = useRef2(false);
|
|
71
100
|
const [predicted, setPredicted] = useState2([]);
|
|
72
101
|
const [strokeDrag, setStrokeDrag] = useState2(null);
|
|
73
102
|
const presenter = useMemo2(() => new PaintCanvasPresenter(controller), [controller]);
|
|
@@ -93,7 +122,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
|
|
|
93
122
|
ro.observe(el);
|
|
94
123
|
return () => ro.disconnect();
|
|
95
124
|
}, []);
|
|
96
|
-
const fitted =
|
|
125
|
+
const fitted = useRef2(null);
|
|
97
126
|
useEffect2(() => {
|
|
98
127
|
const key = `${doc.width}x${doc.height}`;
|
|
99
128
|
if (!fitOnMount || fitted.current === key) return;
|
|
@@ -202,6 +231,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
|
|
|
202
231
|
predicted.length > 0 && /* @__PURE__ */ jsx("polyline", { points: predicted.map((p) => `${p.x},${p.y}`).join(" "), fill: "none", stroke: state.color, strokeOpacity: 0.5, strokeWidth: Math.max(1, state.brush.tip.size / 2), strokeLinecap: "round" })
|
|
203
232
|
] }),
|
|
204
233
|
state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ jsx(ReferencePanel, { controller, id: r.id }, r.id)),
|
|
234
|
+
proposals && /* @__PURE__ */ jsx(PaintProposalGhosts, { proposals, transform, zoom: state.view.zoom }),
|
|
205
235
|
presence && /* @__PURE__ */ jsx(PaintPresenceLayer, { presence, view: state.view, canvas: doc, viewport: size }),
|
|
206
236
|
/* @__PURE__ */ jsxs("div", { className: "absolute bottom-1 right-2 text-[10px] text-slate-500 pointer-events-none", "data-testid": "paint-view-status", children: [
|
|
207
237
|
Math.round(state.view.zoom * 100),
|
|
@@ -227,7 +257,7 @@ var PaintPresenceLayer = ({ presence, view, canvas, viewport }) => {
|
|
|
227
257
|
var ReferencePanel = ({ controller, id }) => {
|
|
228
258
|
const state = usePaintEditorState(controller);
|
|
229
259
|
const ref = state.guides.references.find((r) => r.id === id);
|
|
230
|
-
const drag =
|
|
260
|
+
const drag = useRef2(null);
|
|
231
261
|
if (!ref) return null;
|
|
232
262
|
const h = ref.height / ref.width * ref.displayWidth;
|
|
233
263
|
return /* @__PURE__ */ jsxs(
|
|
@@ -277,19 +307,46 @@ var ReferencePanel = ({ controller, id }) => {
|
|
|
277
307
|
}
|
|
278
308
|
);
|
|
279
309
|
};
|
|
310
|
+
var PaintProposalGhosts = ({ proposals, transform, zoom }) => {
|
|
311
|
+
const { proposals: pending } = useSyncExternalStore2(proposals.subscribe, proposals.getState, proposals.getState);
|
|
312
|
+
return /* @__PURE__ */ jsx(Fragment, { children: pending.map((p) => /* @__PURE__ */ jsx(PaintProposalGhost, { proposal: p, transform, zoom }, p.id)) });
|
|
313
|
+
};
|
|
314
|
+
var PaintProposalGhost = ({ proposal, transform, zoom }) => {
|
|
315
|
+
const ref = useRef2(null);
|
|
316
|
+
const ghost = paintProposalGhost(proposal);
|
|
317
|
+
useEffect2(() => {
|
|
318
|
+
const ctx = ref.current?.getContext("2d");
|
|
319
|
+
if (!ctx || !ghost || typeof ImageData === "undefined") return;
|
|
320
|
+
ctx.putImageData(new ImageData(new Uint8ClampedArray(ghost.data), ghost.width, ghost.height), 0, 0);
|
|
321
|
+
}, [ghost?.data]);
|
|
322
|
+
if (!ghost) return null;
|
|
323
|
+
return /* @__PURE__ */ jsx(
|
|
324
|
+
"canvas",
|
|
325
|
+
{
|
|
326
|
+
ref,
|
|
327
|
+
width: ghost.width,
|
|
328
|
+
height: ghost.height,
|
|
329
|
+
"data-paint-proposal": proposal.id,
|
|
330
|
+
title: proposal.rationale ? `${proposal.title}: ${proposal.rationale}` : proposal.title,
|
|
331
|
+
"aria-label": `Suggested: ${proposal.title}`,
|
|
332
|
+
className: "absolute left-0 top-0 pointer-events-none",
|
|
333
|
+
style: { transform: `${transform} translate(${ghost.x}px, ${ghost.y}px)`, transformOrigin: "0 0", opacity: 0.7, outline: `${1.5 / zoom}px dashed #a78bfa`, outlineOffset: `${2 / zoom}px` }
|
|
334
|
+
}
|
|
335
|
+
);
|
|
336
|
+
};
|
|
280
337
|
|
|
281
338
|
// src/paint-editor/PaintToolbar.tsx
|
|
282
|
-
import { useRef as
|
|
339
|
+
import { useRef as useRef4, useState as useState4 } from "react";
|
|
283
340
|
import { PAINT_TOOLS, SYMMETRY_MODES, decodeImageBlob, downloadBytes, quickStencil, timeLapseZip } from "@pixerate/editor/paint-editor";
|
|
284
341
|
|
|
285
342
|
// src/paint-editor/shared.tsx
|
|
286
|
-
import { useEffect as useEffect3, useRef as
|
|
343
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
287
344
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
288
345
|
var chip = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
|
|
289
346
|
var button = "px-2 py-1 rounded text-[11px] bg-slate-800 text-slate-200 hover:bg-slate-700 disabled:opacity-40";
|
|
290
347
|
var panel = "flex flex-col gap-2 text-xs text-slate-200";
|
|
291
348
|
var PixelCanvas = ({ pixels, label, className, style }) => {
|
|
292
|
-
const ref =
|
|
349
|
+
const ref = useRef3(null);
|
|
293
350
|
useEffect3(() => {
|
|
294
351
|
const canvas = ref.current;
|
|
295
352
|
const ctx = canvas?.getContext("2d");
|
|
@@ -305,8 +362,8 @@ var PixelCanvas = ({ pixels, label, className, style }) => {
|
|
|
305
362
|
var fmt = (c, v) => c.step >= 1 ? String(Math.round(v)) : v.toFixed(2);
|
|
306
363
|
var PaintSlider = ({ control, value, onChange, onCommit }) => {
|
|
307
364
|
const [draft, setDraft] = useState3(null);
|
|
308
|
-
const ref =
|
|
309
|
-
const commit =
|
|
365
|
+
const ref = useRef3(null);
|
|
366
|
+
const commit = useRef3(onCommit);
|
|
310
367
|
commit.current = onCommit;
|
|
311
368
|
useEffect3(() => {
|
|
312
369
|
const el = ref.current;
|
|
@@ -359,8 +416,8 @@ function useAttempt() {
|
|
|
359
416
|
}
|
|
360
417
|
var ErrorLine = ({ error }) => error ? /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
|
|
361
418
|
var CommitColorInput = ({ value, label, onCommit, className }) => {
|
|
362
|
-
const ref =
|
|
363
|
-
const commit =
|
|
419
|
+
const ref = useRef3(null);
|
|
420
|
+
const commit = useRef3(onCommit);
|
|
364
421
|
commit.current = onCommit;
|
|
365
422
|
useEffect3(() => {
|
|
366
423
|
const el = ref.current;
|
|
@@ -373,15 +430,15 @@ var CommitColorInput = ({ value, label, onCommit, className }) => {
|
|
|
373
430
|
};
|
|
374
431
|
|
|
375
432
|
// src/paint-editor/PaintToolbar.tsx
|
|
376
|
-
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
433
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
377
434
|
var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", className }) => {
|
|
378
435
|
const state = usePaintEditorState(controller);
|
|
379
436
|
const [error, attempt] = useAttempt();
|
|
380
437
|
const [busy, setBusy] = useState4(null);
|
|
381
438
|
const [note, setNote] = useState4(null);
|
|
382
|
-
const openRef =
|
|
383
|
-
const tracingRef =
|
|
384
|
-
const refRef =
|
|
439
|
+
const openRef = useRef4(null);
|
|
440
|
+
const tracingRef = useRef4(null);
|
|
441
|
+
const refRef = useRef4(null);
|
|
385
442
|
const { symmetry, perspective, tracing } = state.guides;
|
|
386
443
|
const { canvas } = state.document;
|
|
387
444
|
const exportImage = (format) => attempt(async () => downloadBytes(await controller.exportImage({ format }), `${fileName}.${format === "image/png" ? "png" : "jpg"}`, format));
|
|
@@ -456,7 +513,7 @@ var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", cla
|
|
|
456
513
|
),
|
|
457
514
|
/* @__PURE__ */ jsx3("span", { className: "mx-1 h-4 w-px bg-slate-700" }),
|
|
458
515
|
/* @__PURE__ */ jsx3("button", { type: "button", className: button, onClick: () => tracingRef.current?.click(), children: "Tracing image\u2026" }),
|
|
459
|
-
tracing && /* @__PURE__ */ jsxs3(
|
|
516
|
+
tracing && /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
460
517
|
/* @__PURE__ */ jsx3(
|
|
461
518
|
"input",
|
|
462
519
|
{
|
|
@@ -577,14 +634,14 @@ var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", cla
|
|
|
577
634
|
};
|
|
578
635
|
|
|
579
636
|
// src/paint-editor/BrushPanel.tsx
|
|
580
|
-
import { useMemo as useMemo4, useRef as
|
|
637
|
+
import { useMemo as useMemo4, useRef as useRef5 } from "react";
|
|
581
638
|
import { brushLoadColor, brushTakesPaint, downloadBytes as downloadBytes2, toggleStickerRef, DEFAULT_PAINT_GRADIENT } from "@pixerate/editor/paint-editor";
|
|
582
|
-
import { PAINT_PROFILE as PAINT_PROFILE2 } from "@pixerate/editor/brushes";
|
|
639
|
+
import { brushColourHex, PAINT_PROFILE as PAINT_PROFILE2 } from "@pixerate/editor/brushes";
|
|
583
640
|
|
|
584
641
|
// src/paint-editor/BrushEditor.tsx
|
|
585
642
|
import { useMemo as useMemo3, useState as useState5 } from "react";
|
|
586
643
|
import { brushEditorSections, PAINT_PROFILE, setBrushEditorValue } from "@pixerate/editor/brushes";
|
|
587
|
-
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
644
|
+
import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
588
645
|
var BrushEditor = ({ brush, profile = PAINT_PROFILE, onChange, preview, onSaveAs, renderExtra, className }) => {
|
|
589
646
|
const sections = useMemo3(() => brushEditorSections(brush, profile), [brush, profile]);
|
|
590
647
|
const [problems, setProblems] = useState5(null);
|
|
@@ -649,20 +706,43 @@ var EditorControl = ({ control: c, onSet }) => {
|
|
|
649
706
|
/* @__PURE__ */ jsx4("span", { className: "text-slate-400", children: c.label }),
|
|
650
707
|
/* @__PURE__ */ jsx4("input", { "aria-label": c.ariaLabel, defaultValue: c.value, placeholder: c.placeholder, onBlur: (e) => e.target.value !== c.value && onSet(c.path, e.target.value.trim().toLowerCase()), className: "w-28 rounded bg-slate-800 px-1.5 py-0.5" }, c.value)
|
|
651
708
|
] });
|
|
652
|
-
case "colour":
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
/* @__PURE__ */ jsxs4("
|
|
656
|
-
/* @__PURE__ */ jsx4("
|
|
657
|
-
|
|
709
|
+
case "colour": {
|
|
710
|
+
const set = (light, dark) => onSet(c.path, dark === null ? light : { light, dark });
|
|
711
|
+
return /* @__PURE__ */ jsxs4("div", { className: "flex flex-col gap-1", children: [
|
|
712
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between gap-2", children: [
|
|
713
|
+
/* @__PURE__ */ jsx4("span", { className: "text-slate-400", children: c.label }),
|
|
714
|
+
/* @__PURE__ */ jsxs4("span", { className: "flex items-center gap-1", children: [
|
|
715
|
+
/* @__PURE__ */ jsx4("input", { type: "color", "aria-label": c.ariaLabel, title: c.dark !== null ? "On light backgrounds" : void 0, value: c.value ?? "#000000", onChange: (e) => set(e.target.value, c.dark), className: "h-5 w-8" }),
|
|
716
|
+
c.dark !== null && /* @__PURE__ */ jsx4("input", { type: "color", "aria-label": `${c.ariaLabel} (dark)`, title: "On dark backgrounds", value: c.dark, onChange: (e) => set(c.value ?? "#000000", e.target.value), className: "h-5 w-8" }),
|
|
717
|
+
(c.value || c.gradient) && /* @__PURE__ */ jsx4("button", { type: "button", className: button, onClick: () => onSet(c.path, void 0), children: "None" })
|
|
718
|
+
] })
|
|
719
|
+
] }),
|
|
720
|
+
c.gradient ? /* @__PURE__ */ jsx4("span", { className: "text-[10px] text-slate-500", children: "A gradient (its own paint)." }) : /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-2", children: [
|
|
721
|
+
/* @__PURE__ */ jsx4("input", { type: "checkbox", "aria-label": `${c.ariaLabel}: light and dark`, checked: c.dark !== null, onChange: (e) => set(c.value ?? "#000000", e.target.checked ? c.value ?? "#ffffff" : null) }),
|
|
722
|
+
" Light / dark"
|
|
658
723
|
] })
|
|
659
724
|
] });
|
|
660
|
-
|
|
661
|
-
|
|
725
|
+
}
|
|
726
|
+
case "palette": {
|
|
727
|
+
const at = (i, entry) => onSet(c.path, c.value.map((x, j) => j === i ? entry : x));
|
|
728
|
+
return /* @__PURE__ */ jsxs4("div", { className: "flex flex-col gap-1", role: "group", "aria-label": c.ariaLabel, children: [
|
|
662
729
|
/* @__PURE__ */ jsx4("span", { className: "text-slate-400", children: c.label }),
|
|
663
|
-
|
|
664
|
-
|
|
730
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
731
|
+
c.value.map((col, i) => {
|
|
732
|
+
const light = typeof col === "string" ? col : col.light;
|
|
733
|
+
return /* @__PURE__ */ jsxs4("span", { className: "flex items-center gap-0.5 rounded bg-slate-900 p-0.5", children: [
|
|
734
|
+
/* @__PURE__ */ jsx4("input", { type: "color", "aria-label": `Palette colour ${i + 1}`, value: light, onChange: (e) => at(i, typeof col === "string" ? e.target.value : { ...col, light: e.target.value }), className: "h-4 w-5" }),
|
|
735
|
+
typeof col !== "string" && /* @__PURE__ */ jsx4("input", { type: "color", "aria-label": `Palette colour ${i + 1} (dark)`, value: col.dark, onChange: (e) => at(i, { ...col, dark: e.target.value }), className: "h-4 w-5" }),
|
|
736
|
+
/* @__PURE__ */ jsx4("button", { type: "button", "aria-label": `Remove palette colour ${i + 1}`, className: "px-0.5 text-slate-400 hover:text-white", onClick: () => onSet(c.path, c.value.filter((_, j) => j !== i)), children: "\xD7" })
|
|
737
|
+
] }, i);
|
|
738
|
+
}),
|
|
739
|
+
c.value.length < c.max && /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
740
|
+
/* @__PURE__ */ jsx4("input", { type: "color", "aria-label": "Add a palette colour", onChange: (e) => onSet(c.path, [...c.value, e.target.value]), className: "h-4 w-6" }),
|
|
741
|
+
/* @__PURE__ */ jsx4("button", { type: "button", className: button, onClick: () => onSet(c.path, [...c.value, { light: "#334155", dark: "#e2e8f0" }]), children: "Add light / dark pair" })
|
|
742
|
+
] })
|
|
743
|
+
] })
|
|
665
744
|
] });
|
|
745
|
+
}
|
|
666
746
|
case "stamps":
|
|
667
747
|
return /* @__PURE__ */ jsx4("div", { className: "flex flex-wrap gap-1", role: "group", "aria-label": c.ariaLabel, title: `Up to ${c.max}`, children: c.options.map((o) => {
|
|
668
748
|
const on = c.value.includes(o.value);
|
|
@@ -700,11 +780,11 @@ var StickerPicker = ({ controller, selected, onPick, label = "Stickers" }) => {
|
|
|
700
780
|
};
|
|
701
781
|
|
|
702
782
|
// src/paint-editor/BrushPanel.tsx
|
|
703
|
-
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
783
|
+
import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
704
784
|
var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, className }) => {
|
|
705
785
|
const state = usePaintEditorState(controller);
|
|
706
786
|
const [error, attempt] = useAttempt();
|
|
707
|
-
const fileRef =
|
|
787
|
+
const fileRef = useRef5(null);
|
|
708
788
|
const { brush, brushes } = state;
|
|
709
789
|
const paper = state.document.paper;
|
|
710
790
|
const thumbs = useMemo4(
|
|
@@ -718,6 +798,7 @@ var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, clas
|
|
|
718
798
|
const own = typeof spec.colour?.default === "string" && /^#[0-9a-f]{6}/i.test(spec.colour.default) ? spec.colour.default.slice(0, 7) : void 0;
|
|
719
799
|
const preview = useMemo4(() => controller.brushThumbnail(brush.id, { width: 240, height: 64, color: own }), [controller, brush, paper, state.color, own]);
|
|
720
800
|
const carried = brushLoadColor(state.mixerLoad);
|
|
801
|
+
const palette = (spec.colour?.palette ?? []).flatMap((c) => brushColourHex(c, state.colorScheme) ?? []);
|
|
721
802
|
const slug = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "brush";
|
|
722
803
|
const loads = ["dab", "mixer", "impasto"].includes(brush.engine) || brush.engine === "wet" && brush.wet.tool === "paint";
|
|
723
804
|
return /* @__PURE__ */ jsxs6("div", { className: `${panel} ${className ?? ""}`, "data-testid": "brush-panel", children: [
|
|
@@ -740,13 +821,20 @@ var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, clas
|
|
|
740
821
|
brush.engine === "mixer" && /* @__PURE__ */ jsx7("button", { type: "button", className: button, onClick: () => controller.loadMixerBrush(), children: "Load" }),
|
|
741
822
|
/* @__PURE__ */ jsx7("button", { type: "button", className: button, onClick: () => controller.cleanMixerBrush(brush.engine === "mixer"), children: "Clean" })
|
|
742
823
|
] });
|
|
743
|
-
if (section === "colour"
|
|
744
|
-
return /* @__PURE__ */ jsxs6(
|
|
745
|
-
/* @__PURE__ */
|
|
746
|
-
|
|
747
|
-
/* @__PURE__ */ jsx7("
|
|
824
|
+
if (section === "colour")
|
|
825
|
+
return /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
|
826
|
+
palette.length > 0 && /* @__PURE__ */ jsx7("div", { className: "flex flex-wrap items-center gap-1", role: "group", "aria-label": "Paint with a palette colour", children: palette.map((hex, i) => /* @__PURE__ */ jsx7("button", { type: "button", "aria-label": `Paint with ${hex}`, title: hex, "aria-pressed": state.color === hex, className: `h-5 w-5 rounded ring-1 ${state.color === hex ? "ring-white" : "ring-slate-700"}`, style: { background: hex }, onClick: () => controller.setColor(hex) }, `${hex}-${i}`)) }),
|
|
827
|
+
/* @__PURE__ */ jsxs6("label", { className: "flex items-center gap-2", title: "Choosing a brush with a default colour (the highlighter's yellow) makes it your colour unless this is on", children: [
|
|
828
|
+
/* @__PURE__ */ jsx7("input", { type: "checkbox", "aria-label": "Keep my colour", checked: state.colorLocked, onChange: (e) => controller.setColorLocked(e.target.checked) }),
|
|
829
|
+
" Keep my colour when choosing a brush"
|
|
748
830
|
] }),
|
|
749
|
-
brush
|
|
831
|
+
brushTakesPaint(brush) && /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-1.5", "data-testid": "brush-gradient", children: [
|
|
832
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between gap-2", children: [
|
|
833
|
+
/* @__PURE__ */ jsx7("span", { className: "text-slate-400", title: "A gradient of the brush's own, used instead of the paint (the multi-colour brush)", children: "Brush gradient" }),
|
|
834
|
+
/* @__PURE__ */ jsx7("button", { type: "button", "aria-pressed": brush.paint !== null, className: chip(brush.paint !== null), onClick: () => attempt(() => controller.setBrush({ paint: brush.paint ? null : DEFAULT_PAINT_GRADIENT })), children: brush.paint ? "On" : "Off" })
|
|
835
|
+
] }),
|
|
836
|
+
brush.paint && /* @__PURE__ */ jsx7(PaintGradientEditor, { value: brush.paint, colors: { paint: state.color, secondary: state.secondaryColor }, onChange: (g) => attempt(() => controller.setBrush({ paint: g })) })
|
|
837
|
+
] })
|
|
750
838
|
] });
|
|
751
839
|
return null;
|
|
752
840
|
}
|
|
@@ -827,7 +915,7 @@ var PaperPanel = ({ controller, className }) => {
|
|
|
827
915
|
};
|
|
828
916
|
|
|
829
917
|
// src/paint-editor/ColorPanel.tsx
|
|
830
|
-
import { useMemo as useMemo6, useRef as
|
|
918
|
+
import { useMemo as useMemo6, useRef as useRef6, useState as useState7 } from "react";
|
|
831
919
|
import {
|
|
832
920
|
HARMONY_KINDS,
|
|
833
921
|
MIXING_PAD_HEIGHT,
|
|
@@ -854,7 +942,7 @@ var ColorPanel = ({ controller, wheelSize = 168, mixingPad = true, className })
|
|
|
854
942
|
const [sample, setSample] = useState7(3);
|
|
855
943
|
const [parts, setParts] = useState7([1, 1]);
|
|
856
944
|
const [padName, setPadName] = useState7("");
|
|
857
|
-
const padPoints =
|
|
945
|
+
const padPoints = useRef6(null);
|
|
858
946
|
const ring = useMemo6(() => renderColorWheel(wheelSize, wheel), [wheelSize, wheel]);
|
|
859
947
|
const color = state.color;
|
|
860
948
|
const harmony = useMemo6(() => controller.harmony(kind, { color, wheel }), [controller, kind, color, wheel]);
|
|
@@ -1368,11 +1456,11 @@ var StrokePanel = ({ controller, className }) => {
|
|
|
1368
1456
|
};
|
|
1369
1457
|
|
|
1370
1458
|
// src/paint-editor/PaintEditor.tsx
|
|
1371
|
-
import { useRef as
|
|
1459
|
+
import { useRef as useRef8, useState as useState10 } from "react";
|
|
1372
1460
|
import { PaintPresence as PaintPresence2, documentToScreen as documentToScreen2, screenToDocument } from "@pixerate/editor/paint-editor";
|
|
1373
1461
|
|
|
1374
1462
|
// src/paint-editor/PaintEffectsPanel.tsx
|
|
1375
|
-
import { useEffect as useEffect5, useMemo as useMemo7, useRef as
|
|
1463
|
+
import { useEffect as useEffect5, useMemo as useMemo7, useRef as useRef7, useState as useState9 } from "react";
|
|
1376
1464
|
import { createPaintEffectsToolProvider, PAPER_EFFECT_BLENDS } from "@pixerate/editor/paint-editor";
|
|
1377
1465
|
import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1378
1466
|
function usePaintEffectsProvider(controller) {
|
|
@@ -1392,7 +1480,7 @@ function usePaintEffectsTools(registry, controller, options = {}) {
|
|
|
1392
1480
|
}
|
|
1393
1481
|
function Controls({ provider, effect, name, values, apply }) {
|
|
1394
1482
|
const { description, error } = useEffectDescription(provider, effect);
|
|
1395
|
-
const drags =
|
|
1483
|
+
const drags = useRef7(/* @__PURE__ */ new Set());
|
|
1396
1484
|
if (!provider) return /* @__PURE__ */ jsxs13("p", { className: "text-[11px] text-slate-400", children: [
|
|
1397
1485
|
'No effects provider: "',
|
|
1398
1486
|
name ?? effect,
|
|
@@ -1587,12 +1675,12 @@ var PAINT_CONTROLS = {
|
|
|
1587
1675
|
lighting: '[data-testid="light-panel"]',
|
|
1588
1676
|
symmetry: '[aria-label="Symmetry"]'
|
|
1589
1677
|
};
|
|
1590
|
-
var PaintEditor = ({ controller, fileName, height = 720, presence, className, playback, playbackId = "paint", onPlaybackReveal }) => {
|
|
1678
|
+
var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
|
|
1591
1679
|
const [tool, setTool] = useState10("brush");
|
|
1592
1680
|
const [tab, setTab] = useState10("color");
|
|
1593
|
-
const tabRef =
|
|
1681
|
+
const tabRef = useRef8(tab);
|
|
1594
1682
|
tabRef.current = tab;
|
|
1595
|
-
const rootRef =
|
|
1683
|
+
const rootRef = useRef8(null);
|
|
1596
1684
|
const [ownPresence] = useState10(() => new PaintPresence2());
|
|
1597
1685
|
const ambientPlayback = useAgentPlayback();
|
|
1598
1686
|
const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
|
|
@@ -1658,7 +1746,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
|
|
|
1658
1746
|
/* @__PURE__ */ jsxs14("div", { className: "flex min-h-0 flex-1 gap-2", children: [
|
|
1659
1747
|
/* @__PURE__ */ jsx15(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
|
|
1660
1748
|
/* @__PURE__ */ jsxs14("div", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
1661
|
-
/* @__PURE__ */ jsx15(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, className: "flex-1 rounded-lg" }),
|
|
1749
|
+
/* @__PURE__ */ jsx15(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
|
|
1662
1750
|
error && /* @__PURE__ */ jsx15("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
|
|
1663
1751
|
] }),
|
|
1664
1752
|
/* @__PURE__ */ jsxs14("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
|
|
@@ -1687,6 +1775,7 @@ export {
|
|
|
1687
1775
|
PaintGradientEditor,
|
|
1688
1776
|
PaintLayersPanel,
|
|
1689
1777
|
PaintPresenceLayer,
|
|
1778
|
+
PaintProposalGhosts,
|
|
1690
1779
|
PaintSlider,
|
|
1691
1780
|
PaintToolbar,
|
|
1692
1781
|
PaperPanel,
|
|
@@ -1694,9 +1783,11 @@ export {
|
|
|
1694
1783
|
StickerPicker,
|
|
1695
1784
|
StrokePanel,
|
|
1696
1785
|
WetPanel,
|
|
1786
|
+
usePaintChangeFeed,
|
|
1697
1787
|
usePaintDirector,
|
|
1698
1788
|
usePaintEditor,
|
|
1699
1789
|
usePaintEditorState,
|
|
1700
1790
|
usePaintEffectsProvider,
|
|
1701
|
-
usePaintEffectsTools
|
|
1791
|
+
usePaintEffectsTools,
|
|
1792
|
+
usePaintProposals
|
|
1702
1793
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
|
|
1
|
+
import { PaintDirector, PaintEditorController, PaintPresence, type PaintChange, type PaintChangeFeed, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type PaintProposal, type PaintProposals, type PaintProposalsOptions, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
|
|
2
2
|
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
3
|
export interface UsePaintEditorReturn {
|
|
4
4
|
controller: PaintEditorController;
|
|
@@ -23,3 +23,32 @@ export declare function usePaintDirector(controller: PaintEditorController, opti
|
|
|
23
23
|
presence: PaintPresence;
|
|
24
24
|
director: PaintDirector;
|
|
25
25
|
};
|
|
26
|
+
export interface PaintProposalsHandle {
|
|
27
|
+
/** The framework-free store (for `createPaintProposalToolProvider` and agents). */
|
|
28
|
+
readonly store: PaintProposals;
|
|
29
|
+
/** Pending proposals; pass `store` to `PaintCanvas` (`proposals`) to draw them as ghosts. */
|
|
30
|
+
proposals: readonly PaintProposal[];
|
|
31
|
+
propose: PaintProposals['propose'];
|
|
32
|
+
accept: PaintProposals['accept'];
|
|
33
|
+
reject: PaintProposals['reject'];
|
|
34
|
+
clear: PaintProposals['clear'];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Paint an agent suggests without painting it: ghosts the user accepts (painted on a layer of
|
|
38
|
+
* their own as one undo step, made by the proposer) or dismisses. Pass `store` to `PaintCanvas`
|
|
39
|
+
* as `proposals` to draw the ghosts, and to `createPaintProposalToolProvider` for agents. Options
|
|
40
|
+
* are read on the first render. The same API as the Svelte `createPaintProposalState`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function usePaintProposals(controller: PaintEditorController, options?: Omit<PaintProposalsOptions, 'controller'>): PaintProposalsHandle;
|
|
43
|
+
/**
|
|
44
|
+
* What changed in the painting, after each change: strokes, fills and layers added, removed or
|
|
45
|
+
* changed, and the start and end of each stroke, with who made it. For agents that paint
|
|
46
|
+
* alongside the user. Returns the feed (`null` until mounted) and the latest change. The same API
|
|
47
|
+
* as the Svelte `createPaintChangeWatcher`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function usePaintChangeFeed(controller: PaintEditorController, options?: {
|
|
50
|
+
onChange?: (change: PaintChange) => void;
|
|
51
|
+
}): {
|
|
52
|
+
feed: PaintChangeFeed | null;
|
|
53
|
+
last: PaintChange | null;
|
|
54
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
|
|
1
|
+
import { PaintDirector, PaintEditorController, PaintPresence, type PaintChange, type PaintChangeFeed, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type PaintProposal, type PaintProposals, type PaintProposalsOptions, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
|
|
2
2
|
import type { EditorDocument } from '@pixerate/editor/persistence';
|
|
3
3
|
export interface UsePaintEditorReturn {
|
|
4
4
|
controller: PaintEditorController;
|
|
@@ -23,3 +23,32 @@ export declare function usePaintDirector(controller: PaintEditorController, opti
|
|
|
23
23
|
presence: PaintPresence;
|
|
24
24
|
director: PaintDirector;
|
|
25
25
|
};
|
|
26
|
+
export interface PaintProposalsHandle {
|
|
27
|
+
/** The framework-free store (for `createPaintProposalToolProvider` and agents). */
|
|
28
|
+
readonly store: PaintProposals;
|
|
29
|
+
/** Pending proposals; pass `store` to `PaintCanvas` (`proposals`) to draw them as ghosts. */
|
|
30
|
+
proposals: readonly PaintProposal[];
|
|
31
|
+
propose: PaintProposals['propose'];
|
|
32
|
+
accept: PaintProposals['accept'];
|
|
33
|
+
reject: PaintProposals['reject'];
|
|
34
|
+
clear: PaintProposals['clear'];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Paint an agent suggests without painting it: ghosts the user accepts (painted on a layer of
|
|
38
|
+
* their own as one undo step, made by the proposer) or dismisses. Pass `store` to `PaintCanvas`
|
|
39
|
+
* as `proposals` to draw the ghosts, and to `createPaintProposalToolProvider` for agents. Options
|
|
40
|
+
* are read on the first render. The same API as the Svelte `createPaintProposalState`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function usePaintProposals(controller: PaintEditorController, options?: Omit<PaintProposalsOptions, 'controller'>): PaintProposalsHandle;
|
|
43
|
+
/**
|
|
44
|
+
* What changed in the painting, after each change: strokes, fills and layers added, removed or
|
|
45
|
+
* changed, and the start and end of each stroke, with who made it. For agents that paint
|
|
46
|
+
* alongside the user. Returns the feed (`null` until mounted) and the latest change. The same API
|
|
47
|
+
* as the Svelte `createPaintChangeWatcher`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function usePaintChangeFeed(controller: PaintEditorController, options?: {
|
|
50
|
+
onChange?: (change: PaintChange) => void;
|
|
51
|
+
}): {
|
|
52
|
+
feed: PaintChangeFeed | null;
|
|
53
|
+
last: PaintChange | null;
|
|
54
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.175.0",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -277,7 +277,7 @@
|
|
|
277
277
|
"dependencies": {},
|
|
278
278
|
"peerDependencies": {
|
|
279
279
|
"@dagrejs/dagre": "^1.1.8",
|
|
280
|
-
"@pixerate/editor": ">=0.
|
|
280
|
+
"@pixerate/editor": ">=0.257.0 <1.0.0-0",
|
|
281
281
|
"@tiptap/core": "^2.27.3",
|
|
282
282
|
"@tiptap/extension-bubble-menu": "^2.27.3",
|
|
283
283
|
"@tiptap/extension-placeholder": "^2.27.3",
|
|
@@ -328,7 +328,7 @@
|
|
|
328
328
|
"tsup": "^9.0.0",
|
|
329
329
|
"typescript": "^5.7.3",
|
|
330
330
|
"vitest": "^5.0.5",
|
|
331
|
-
"@pixerate/editor": "0.
|
|
331
|
+
"@pixerate/editor": "0.257.0"
|
|
332
332
|
},
|
|
333
333
|
"scripts": {
|
|
334
334
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|