@pixerate/editor-react 0.179.0 → 0.180.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 → brushes}/BrushEditor.d.cts +14 -5
- package/dist/{paint-editor → brushes}/BrushEditor.d.ts +14 -5
- package/dist/brushes/BrushLibraryEditor.d.cts +26 -0
- package/dist/brushes/BrushLibraryEditor.d.ts +26 -0
- package/dist/brushes/index.cjs +289 -20
- package/dist/brushes/index.d.cts +2 -0
- package/dist/brushes/index.d.ts +2 -0
- package/dist/brushes/index.js +6 -2
- package/dist/chunk-76JBZXLM.js +263 -0
- package/dist/chunk-QIJJCDYW.js +119 -0
- package/dist/{chunk-UR4KL7WE.js → chunk-XAPJMT3W.js} +26 -6
- package/dist/image-editor/BrushOptionsBar.d.cts +6 -1
- package/dist/image-editor/BrushOptionsBar.d.ts +6 -1
- package/dist/image-editor/index.cjs +1178 -894
- package/dist/image-editor/index.js +3 -3
- package/dist/index.cjs +1719 -1435
- package/dist/index.js +3 -3
- package/dist/paint-editor/index.cjs +20 -23
- package/dist/paint-editor/index.d.cts +1 -1
- package/dist/paint-editor/index.d.ts +1 -1
- package/dist/paint-editor/index.js +413 -609
- package/dist/vector/VectorAppearancePanel.d.cts +8 -2
- package/dist/vector/VectorAppearancePanel.d.ts +8 -2
- package/dist/vector/index.cjs +1110 -748
- package/dist/vector/index.js +90 -59
- package/package.json +3 -3
- package/dist/chunk-62FMEDGG.js +0 -54
- package/dist/chunk-PQK2UMAY.js +0 -23
|
@@ -8,12 +8,19 @@ type Pixels = {
|
|
|
8
8
|
export interface BrushEditorProps {
|
|
9
9
|
/** The brush being edited, as facets. */
|
|
10
10
|
brush: Brush;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* What the host renders (default the paint editor): only its sections, controls and options
|
|
13
|
+
* are shown. Facets of the brush it can't use stay as they are, named in a note.
|
|
14
|
+
*/
|
|
12
15
|
profile?: BrushHostProfile;
|
|
13
16
|
/** Called with the whole brush after each change (normalised). */
|
|
14
17
|
onChange: (brush: Brush) => void;
|
|
15
|
-
/** A live preview stroke of `brush
|
|
16
|
-
preview?: Pixels | null;
|
|
18
|
+
/** A live preview stroke of `brush`: pixels (e.g. `controller.brushThumbnail`) or an image URL. */
|
|
19
|
+
preview?: Pixels | string | null;
|
|
20
|
+
/** With it, a "Save" button (labelled `saveLabel`) saves the brush in place. */
|
|
21
|
+
onSave?: () => unknown;
|
|
22
|
+
/** The Save button's label (default "Save"; e.g. "Save a copy" for a built-in). */
|
|
23
|
+
saveLabel?: string;
|
|
17
24
|
/** With it, a name field and "Save brush" save the brush under that name. */
|
|
18
25
|
onSaveAs?: (name: string) => unknown;
|
|
19
26
|
/** Extra controls a host adds to a section (e.g. the sticker picker for stamps). */
|
|
@@ -22,8 +29,10 @@ export interface BrushEditorProps {
|
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
31
|
* Edits a brush by its facets (`brushEditorSections`): Medium, Shape, Marks, Feel, Behaviour,
|
|
25
|
-
* Light, Motion and Colour, each control a facet, with a live preview stroke and "Save
|
|
26
|
-
*
|
|
32
|
+
* Light, Motion and Colour, each control a facet, with a live preview stroke, "Save" and "Save
|
|
33
|
+
* as". It needs no editor controller, so every host that paints uses it. Only what the host
|
|
34
|
+
* profile uses is shown; what the brush has for other hosts is kept and named
|
|
35
|
+
* (`brushEditorScope`). `BrushLibraryEditor` wires it to a brush library.
|
|
27
36
|
*/
|
|
28
37
|
export declare const BrushEditor: React.FC<BrushEditorProps>;
|
|
29
38
|
export {};
|
|
@@ -8,12 +8,19 @@ type Pixels = {
|
|
|
8
8
|
export interface BrushEditorProps {
|
|
9
9
|
/** The brush being edited, as facets. */
|
|
10
10
|
brush: Brush;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* What the host renders (default the paint editor): only its sections, controls and options
|
|
13
|
+
* are shown. Facets of the brush it can't use stay as they are, named in a note.
|
|
14
|
+
*/
|
|
12
15
|
profile?: BrushHostProfile;
|
|
13
16
|
/** Called with the whole brush after each change (normalised). */
|
|
14
17
|
onChange: (brush: Brush) => void;
|
|
15
|
-
/** A live preview stroke of `brush
|
|
16
|
-
preview?: Pixels | null;
|
|
18
|
+
/** A live preview stroke of `brush`: pixels (e.g. `controller.brushThumbnail`) or an image URL. */
|
|
19
|
+
preview?: Pixels | string | null;
|
|
20
|
+
/** With it, a "Save" button (labelled `saveLabel`) saves the brush in place. */
|
|
21
|
+
onSave?: () => unknown;
|
|
22
|
+
/** The Save button's label (default "Save"; e.g. "Save a copy" for a built-in). */
|
|
23
|
+
saveLabel?: string;
|
|
17
24
|
/** With it, a name field and "Save brush" save the brush under that name. */
|
|
18
25
|
onSaveAs?: (name: string) => unknown;
|
|
19
26
|
/** Extra controls a host adds to a section (e.g. the sticker picker for stamps). */
|
|
@@ -22,8 +29,10 @@ export interface BrushEditorProps {
|
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
31
|
* Edits a brush by its facets (`brushEditorSections`): Medium, Shape, Marks, Feel, Behaviour,
|
|
25
|
-
* Light, Motion and Colour, each control a facet, with a live preview stroke and "Save
|
|
26
|
-
*
|
|
32
|
+
* Light, Motion and Colour, each control a facet, with a live preview stroke, "Save" and "Save
|
|
33
|
+
* as". It needs no editor controller, so every host that paints uses it. Only what the host
|
|
34
|
+
* profile uses is shown; what the brush has for other hosts is kept and named
|
|
35
|
+
* (`brushEditorScope`). `BrushLibraryEditor` wires it to a brush library.
|
|
27
36
|
*/
|
|
28
37
|
export declare const BrushEditor: React.FC<BrushEditorProps>;
|
|
29
38
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Brush, type BrushHostProfile, type BrushLibrary, type BrushPreviewRenderer } from '@pixerate/editor/brushes';
|
|
3
|
+
export interface BrushLibraryEditorProps {
|
|
4
|
+
/** The shared brush library: saves go here, so every editor on it gets the brush. */
|
|
5
|
+
library: BrushLibrary;
|
|
6
|
+
/** The brush to edit (a library id); `null` or absent starts a new brush for the host. */
|
|
7
|
+
brushId?: string | null;
|
|
8
|
+
/** The host the brush is edited for: the editor shows only what it uses. */
|
|
9
|
+
profile: BrushHostProfile;
|
|
10
|
+
/** Draws the preview stroke (the host's renderer, as for `preview_brush`). Without it there is no preview. */
|
|
11
|
+
renderPreview?: BrushPreviewRenderer;
|
|
12
|
+
/** The preview colour for brushes with no solid default colour (default slate). */
|
|
13
|
+
previewColor?: string;
|
|
14
|
+
/** Called with the brush as saved (a copy has a new id): e.g. pick it in the host. */
|
|
15
|
+
onSaved?: (brush: Brush) => void;
|
|
16
|
+
/** With it, a Close button. */
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `BrushEditor` on a brush library for one host: loads the brush, edits a draft and saves it with
|
|
22
|
+
* `saveBrushEdit`. A saved brush is changed in place, a built-in is saved as a copy, "Save brush"
|
|
23
|
+
* saves under a new name, and "New brush" starts from the current one with only what the host
|
|
24
|
+
* uses. Facets the host can't use are kept on save; a new brush must pass the host's check.
|
|
25
|
+
*/
|
|
26
|
+
export declare const BrushLibraryEditor: React.FC<BrushLibraryEditorProps>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Brush, type BrushHostProfile, type BrushLibrary, type BrushPreviewRenderer } from '@pixerate/editor/brushes';
|
|
3
|
+
export interface BrushLibraryEditorProps {
|
|
4
|
+
/** The shared brush library: saves go here, so every editor on it gets the brush. */
|
|
5
|
+
library: BrushLibrary;
|
|
6
|
+
/** The brush to edit (a library id); `null` or absent starts a new brush for the host. */
|
|
7
|
+
brushId?: string | null;
|
|
8
|
+
/** The host the brush is edited for: the editor shows only what it uses. */
|
|
9
|
+
profile: BrushHostProfile;
|
|
10
|
+
/** Draws the preview stroke (the host's renderer, as for `preview_brush`). Without it there is no preview. */
|
|
11
|
+
renderPreview?: BrushPreviewRenderer;
|
|
12
|
+
/** The preview colour for brushes with no solid default colour (default slate). */
|
|
13
|
+
previewColor?: string;
|
|
14
|
+
/** Called with the brush as saved (a copy has a new id): e.g. pick it in the host. */
|
|
15
|
+
onSaved?: (brush: Brush) => void;
|
|
16
|
+
/** With it, a Close button. */
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `BrushEditor` on a brush library for one host: loads the brush, edits a draft and saves it with
|
|
22
|
+
* `saveBrushEdit`. A saved brush is changed in place, a built-in is saved as a copy, "Save brush"
|
|
23
|
+
* saves under a new name, and "New brush" starts from the current one with only what the host
|
|
24
|
+
* uses. Facets the host can't use are kept on save; a new brush must pass the host's check.
|
|
25
|
+
*/
|
|
26
|
+
export declare const BrushLibraryEditor: React.FC<BrushLibraryEditorProps>;
|
package/dist/brushes/index.cjs
CHANGED
|
@@ -20,18 +20,195 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/brushes/index.ts
|
|
21
21
|
var brushes_exports = {};
|
|
22
22
|
__export(brushes_exports, {
|
|
23
|
+
BrushEditor: () => BrushEditor,
|
|
23
24
|
BrushLibraryBrowser: () => BrushLibraryBrowser,
|
|
25
|
+
BrushLibraryEditor: () => BrushLibraryEditor,
|
|
24
26
|
useBrushLibrary: () => useBrushLibrary
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(brushes_exports);
|
|
27
29
|
|
|
28
|
-
// src/brushes/
|
|
29
|
-
var
|
|
30
|
+
// src/brushes/BrushEditor.tsx
|
|
31
|
+
var import_react2 = require("react");
|
|
30
32
|
var import_brushes = require("@pixerate/editor/brushes");
|
|
33
|
+
|
|
34
|
+
// src/paint-editor/shared.tsx
|
|
35
|
+
var import_react = require("react");
|
|
31
36
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
-
var
|
|
37
|
+
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"}`;
|
|
38
|
+
var button = "px-2 py-1 rounded text-[11px] bg-slate-800 text-slate-200 hover:bg-slate-700 disabled:opacity-40";
|
|
39
|
+
var PixelCanvas = ({ pixels, label, className, style }) => {
|
|
40
|
+
const ref = (0, import_react.useRef)(null);
|
|
41
|
+
(0, import_react.useEffect)(() => {
|
|
42
|
+
const canvas = ref.current;
|
|
43
|
+
const ctx = canvas?.getContext("2d");
|
|
44
|
+
if (!canvas || !ctx || !pixels || typeof ctx.createImageData !== "function") return;
|
|
45
|
+
canvas.width = pixels.width;
|
|
46
|
+
canvas.height = pixels.height;
|
|
47
|
+
const img = ctx.createImageData(pixels.width, pixels.height);
|
|
48
|
+
img.data.set(pixels.data);
|
|
49
|
+
ctx.putImageData(img, 0, 0);
|
|
50
|
+
}, [pixels]);
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("canvas", { ref, role: "img", "aria-label": label, className, style, width: pixels?.width, height: pixels?.height });
|
|
52
|
+
};
|
|
53
|
+
var fmt = (c, v) => c.step >= 1 ? String(Math.round(v)) : v.toFixed(2);
|
|
54
|
+
var PaintSlider = ({ control, value, onChange, onCommit }) => {
|
|
55
|
+
const [draft, setDraft] = (0, import_react.useState)(null);
|
|
33
56
|
const ref = (0, import_react.useRef)(null);
|
|
57
|
+
const commit = (0, import_react.useRef)(onCommit);
|
|
58
|
+
commit.current = onCommit;
|
|
34
59
|
(0, import_react.useEffect)(() => {
|
|
60
|
+
const el = ref.current;
|
|
61
|
+
if (!el) return;
|
|
62
|
+
const done = () => {
|
|
63
|
+
commit.current?.(Number(el.value));
|
|
64
|
+
setDraft(null);
|
|
65
|
+
};
|
|
66
|
+
el.addEventListener("change", done);
|
|
67
|
+
return () => el.removeEventListener("change", done);
|
|
68
|
+
}, []);
|
|
69
|
+
const shown = draft ?? value;
|
|
70
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "flex flex-col gap-0.5", "data-path": control.path, children: [
|
|
71
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "flex justify-between text-slate-400", children: [
|
|
72
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: control.label }),
|
|
73
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: fmt(control, shown) })
|
|
74
|
+
] }),
|
|
75
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
+
"input",
|
|
77
|
+
{
|
|
78
|
+
ref,
|
|
79
|
+
type: "range",
|
|
80
|
+
"aria-label": control.label,
|
|
81
|
+
min: control.min,
|
|
82
|
+
max: control.max,
|
|
83
|
+
step: control.step,
|
|
84
|
+
value: shown,
|
|
85
|
+
onChange: (e) => {
|
|
86
|
+
const v = Number(e.target.value);
|
|
87
|
+
if (onCommit) setDraft(v);
|
|
88
|
+
onChange?.(v);
|
|
89
|
+
},
|
|
90
|
+
className: "w-full accent-indigo-500"
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
] });
|
|
94
|
+
};
|
|
95
|
+
var ErrorLine = ({ error }) => error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
|
|
96
|
+
|
|
97
|
+
// src/brushes/BrushEditor.tsx
|
|
98
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
99
|
+
var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, preview, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
100
|
+
const sections = (0, import_react2.useMemo)(() => (0, import_brushes.brushEditorSections)(brush, profile), [brush, profile]);
|
|
101
|
+
const scope = (0, import_react2.useMemo)(() => (0, import_brushes.brushEditorScope)(brush, profile), [brush, profile]);
|
|
102
|
+
const [problems, setProblems] = (0, import_react2.useState)(null);
|
|
103
|
+
const [name, setName] = (0, import_react2.useState)("");
|
|
104
|
+
const save = async (fn, after) => {
|
|
105
|
+
try {
|
|
106
|
+
await fn();
|
|
107
|
+
after?.();
|
|
108
|
+
setProblems(null);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
setProblems(e.message);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const set = (path, value) => {
|
|
114
|
+
const r = (0, import_brushes.setBrushEditorValue)(brush, path, value);
|
|
115
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
116
|
+
if (r.brush !== brush) onChange(r.brush);
|
|
117
|
+
};
|
|
118
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
119
|
+
typeof preview === "string" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1" } }) : preview !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
|
|
120
|
+
scope.note && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-[10px] text-amber-400", "data-testid": "brush-editor-scope", title: `${profile.name} shows only what it can use; these are kept unchanged when you save.`, children: scope.note }),
|
|
121
|
+
sections.map((s) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
|
|
122
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "font-medium text-slate-300", children: s.title }),
|
|
123
|
+
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditorControl, { control: c, onSet: set }, c.path)),
|
|
124
|
+
renderExtra?.(s.id)
|
|
125
|
+
] }, s.id)),
|
|
126
|
+
(onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
127
|
+
onSave && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: button, onClick: () => save(onSave), children: saveLabel }),
|
|
128
|
+
onSaveAs && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: name, placeholder: "Brush name", "aria-label": "Brush name", onChange: (e) => setName(e.target.value), className: "w-28 rounded bg-slate-800 px-1.5 py-0.5" }),
|
|
130
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: button, disabled: !name.trim(), onClick: () => save(() => onSaveAs(name.trim()), () => setName("")), children: "Save brush" })
|
|
131
|
+
] })
|
|
132
|
+
] }),
|
|
133
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorLine, { error: problems })
|
|
134
|
+
] });
|
|
135
|
+
};
|
|
136
|
+
var EditorControl = ({ control: c, onSet }) => {
|
|
137
|
+
const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
138
|
+
switch (c.kind) {
|
|
139
|
+
case "slider":
|
|
140
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { title: c.note, children: [
|
|
141
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PaintSlider, { control: c, value: c.value, onChange: (v) => onSet(c.path, v) }),
|
|
142
|
+
note
|
|
143
|
+
] });
|
|
144
|
+
case "choice":
|
|
145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "flex items-center justify-between gap-2", title: c.note, children: [
|
|
146
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("select", { "aria-label": c.ariaLabel, value: c.value, onChange: (e) => onSet(c.path, e.target.value), className: "max-w-[60%] rounded bg-slate-800 px-1 py-0.5", children: c.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: o.value, children: o.label }, o.value)) })
|
|
148
|
+
] });
|
|
149
|
+
case "toggle":
|
|
150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "flex items-center gap-2", title: c.note, children: [
|
|
151
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "checkbox", "aria-label": c.ariaLabel, checked: c.value, onChange: (e) => onSet(c.path, e.target.checked) }),
|
|
152
|
+
" ",
|
|
153
|
+
c.label
|
|
154
|
+
] });
|
|
155
|
+
case "text":
|
|
156
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "flex items-center justify-between gap-2", children: [
|
|
157
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
158
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.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)
|
|
159
|
+
] });
|
|
160
|
+
case "colour": {
|
|
161
|
+
const set = (light, dark) => onSet(c.path, dark === null ? light : { light, dark });
|
|
162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-col gap-1", children: [
|
|
163
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center justify-between gap-2", children: [
|
|
164
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
165
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "flex items-center gap-1", children: [
|
|
166
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.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" }),
|
|
167
|
+
c.dark !== null && /* @__PURE__ */ (0, import_jsx_runtime2.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" }),
|
|
168
|
+
(c.value || c.gradient) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: button, onClick: () => onSet(c.path, void 0), children: "None" })
|
|
169
|
+
] })
|
|
170
|
+
] }),
|
|
171
|
+
c.gradient ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[10px] text-slate-500", children: "A gradient (its own paint)." }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "flex items-center gap-2", children: [
|
|
172
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.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) }),
|
|
173
|
+
" Light / dark"
|
|
174
|
+
] })
|
|
175
|
+
] });
|
|
176
|
+
}
|
|
177
|
+
case "palette": {
|
|
178
|
+
const at = (i, entry) => onSet(c.path, c.value.map((x, j) => j === i ? entry : x));
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-col gap-1", role: "group", "aria-label": c.ariaLabel, children: [
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-slate-400", children: c.label }),
|
|
181
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
182
|
+
c.value.map((col, i) => {
|
|
183
|
+
const light = typeof col === "string" ? col : col.light;
|
|
184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "flex items-center gap-0.5 rounded bg-slate-900 p-0.5", children: [
|
|
185
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.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" }),
|
|
186
|
+
typeof col !== "string" && /* @__PURE__ */ (0, import_jsx_runtime2.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" }),
|
|
187
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.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" })
|
|
188
|
+
] }, i);
|
|
189
|
+
}),
|
|
190
|
+
c.value.length < c.max && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
191
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.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" }),
|
|
192
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: button, onClick: () => onSet(c.path, [...c.value, { light: "#334155", dark: "#e2e8f0" }]), children: "Add light / dark pair" })
|
|
193
|
+
] })
|
|
194
|
+
] })
|
|
195
|
+
] });
|
|
196
|
+
}
|
|
197
|
+
case "stamps":
|
|
198
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex flex-wrap gap-1", role: "group", "aria-label": c.ariaLabel, title: `Up to ${c.max}`, children: c.options.map((o) => {
|
|
199
|
+
const on = c.value.includes(o.value);
|
|
200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-pressed": on, className: chip(on), onClick: () => onSet(c.path, on ? c.value.filter((v) => v !== o.value) : [...c.value, o.value].slice(-c.max)), children: o.label }, o.value);
|
|
201
|
+
}) });
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/brushes/BrushLibraryBrowser.tsx
|
|
206
|
+
var import_react3 = require("react");
|
|
207
|
+
var import_brushes2 = require("@pixerate/editor/brushes");
|
|
208
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
209
|
+
var Thumbnail = ({ image, label, style }) => {
|
|
210
|
+
const ref = (0, import_react3.useRef)(null);
|
|
211
|
+
(0, import_react3.useEffect)(() => {
|
|
35
212
|
const canvas = ref.current;
|
|
36
213
|
const ctx = canvas?.getContext("2d");
|
|
37
214
|
if (!canvas || !ctx || !image || typeof image === "string" || typeof ctx.createImageData !== "function") return;
|
|
@@ -41,19 +218,19 @@ var Thumbnail = ({ image, label, style }) => {
|
|
|
41
218
|
img.data.set(image.data);
|
|
42
219
|
ctx.putImageData(img, 0, 0);
|
|
43
220
|
}, [image]);
|
|
44
|
-
if (typeof image === "string") return /* @__PURE__ */ (0,
|
|
45
|
-
return /* @__PURE__ */ (0,
|
|
221
|
+
if (typeof image === "string") return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: image, alt: label, className: "rounded object-contain", style });
|
|
222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("canvas", { ref, role: "img", "aria-label": label, className: "rounded", style, width: image?.width, height: image?.height });
|
|
46
223
|
};
|
|
47
224
|
var BrushLibraryBrowser = ({ entries, activeId, onSelect, profile, thumbnail, thumbnailWidth = 112, thumbnailHeight = 32, className }) => {
|
|
48
|
-
const [text, setText] = (0,
|
|
49
|
-
const groups = (0,
|
|
50
|
-
return /* @__PURE__ */ (0,
|
|
51
|
-
/* @__PURE__ */ (0,
|
|
52
|
-
/* @__PURE__ */ (0,
|
|
53
|
-
groups.map((g) => /* @__PURE__ */ (0,
|
|
54
|
-
/* @__PURE__ */ (0,
|
|
55
|
-
/* @__PURE__ */ (0,
|
|
56
|
-
(v) => v.entries.map((e) => /* @__PURE__ */ (0,
|
|
225
|
+
const [text, setText] = (0, import_react3.useState)("");
|
|
226
|
+
const groups = (0, import_react3.useMemo)(() => (0, import_brushes2.brushLibraryGroups)(entries, { text, profile }), [entries, text, profile]);
|
|
227
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `flex flex-col gap-1 ${className ?? ""}`, "data-testid": "brush-library", children: [
|
|
228
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "search", value: text, placeholder: "Find a brush", "aria-label": "Find a brush", onChange: (e) => setText(e.target.value), className: "rounded bg-slate-800 px-1.5 py-0.5" }),
|
|
229
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex flex-col gap-1.5", role: "listbox", "aria-label": "Brushes", children: [
|
|
230
|
+
groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { role: "group", "aria-label": g.title, className: "flex flex-col gap-0.5", children: [
|
|
231
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[10px] uppercase tracking-wide text-slate-500", children: g.title }),
|
|
232
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "grid grid-cols-2 gap-1", children: g.varieties.flatMap(
|
|
233
|
+
(v) => v.entries.map((e) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
57
234
|
"button",
|
|
58
235
|
{
|
|
59
236
|
type: "button",
|
|
@@ -63,26 +240,116 @@ var BrushLibraryBrowser = ({ entries, activeId, onSelect, profile, thumbnail, th
|
|
|
63
240
|
className: `flex flex-col items-start gap-0.5 rounded p-1 text-left ${activeId === e.brush.id ? "bg-indigo-600/30 ring-1 ring-indigo-500" : "bg-slate-900 hover:bg-slate-800"}`,
|
|
64
241
|
onClick: () => onSelect(e.brush.id),
|
|
65
242
|
children: [
|
|
66
|
-
thumbnail && /* @__PURE__ */ (0,
|
|
67
|
-
/* @__PURE__ */ (0,
|
|
243
|
+
thumbnail && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Thumbnail, { image: thumbnail(e.brush.id) ?? null, label: `${e.brush.name} thumbnail`, style: { width: "100%", aspectRatio: `${thumbnailWidth} / ${thumbnailHeight}` } }),
|
|
244
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "truncate text-[10px] text-slate-300", children: e.brush.name })
|
|
68
245
|
]
|
|
69
246
|
},
|
|
70
247
|
e.brush.id
|
|
71
248
|
))
|
|
72
249
|
) })
|
|
73
250
|
] }, g.id)),
|
|
74
|
-
!groups.length && /* @__PURE__ */ (0,
|
|
251
|
+
!groups.length && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-slate-500", children: "No brush matches." })
|
|
75
252
|
] })
|
|
76
253
|
] });
|
|
77
254
|
};
|
|
78
255
|
|
|
256
|
+
// src/brushes/BrushLibraryEditor.tsx
|
|
257
|
+
var import_react4 = require("react");
|
|
258
|
+
var import_brushes3 = require("@pixerate/editor/brushes");
|
|
259
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
260
|
+
var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewColor = "#64748b", onSaved, onClose, className }) => {
|
|
261
|
+
const [original, setOriginal] = (0, import_react4.useState)(null);
|
|
262
|
+
const [builtin, setBuiltin] = (0, import_react4.useState)(false);
|
|
263
|
+
const [draft, setDraft] = (0, import_react4.useState)(null);
|
|
264
|
+
const [status, setStatus] = (0, import_react4.useState)(null);
|
|
265
|
+
const [preview, setPreview] = (0, import_react4.useState)(null);
|
|
266
|
+
(0, import_react4.useEffect)(() => {
|
|
267
|
+
let live = true;
|
|
268
|
+
setStatus(null);
|
|
269
|
+
void (async () => {
|
|
270
|
+
const entry = brushId ? await library.get(brushId) : null;
|
|
271
|
+
if (!live) return;
|
|
272
|
+
setOriginal(entry?.brush ?? null);
|
|
273
|
+
setBuiltin(!!entry?.builtin);
|
|
274
|
+
setDraft(entry?.brush ?? (0, import_brushes3.newBrushFor)(profile));
|
|
275
|
+
})();
|
|
276
|
+
return () => {
|
|
277
|
+
live = false;
|
|
278
|
+
};
|
|
279
|
+
}, [library, brushId, profile]);
|
|
280
|
+
const colour = draft && (0, import_brushes3.brushColourHex)(draft.colour?.default ?? "", "light") || previewColor;
|
|
281
|
+
(0, import_react4.useEffect)(() => {
|
|
282
|
+
if (!draft || !renderPreview) return;
|
|
283
|
+
let live = true;
|
|
284
|
+
Promise.resolve(renderPreview(draft, { width: 240, height: 60, color: colour.slice(0, 7) })).then((img) => live && setPreview(img.data ? `data:${img.mimeType};base64,${img.data}` : null)).catch(() => live && setPreview(null));
|
|
285
|
+
return () => {
|
|
286
|
+
live = false;
|
|
287
|
+
};
|
|
288
|
+
}, [draft, renderPreview, colour]);
|
|
289
|
+
const check = (0, import_react4.useMemo)(() => draft ? (0, import_brushes3.checkBrushEdit)(original, draft, profile) : null, [original, draft, profile]);
|
|
290
|
+
if (!draft) return null;
|
|
291
|
+
const save = async (name) => {
|
|
292
|
+
const saved = await (0, import_brushes3.saveBrushEdit)(library, { original, brush: draft, profile, ...name !== void 0 ? { name } : {} });
|
|
293
|
+
setOriginal(saved.brush);
|
|
294
|
+
setBuiltin(false);
|
|
295
|
+
setDraft(saved.brush);
|
|
296
|
+
setStatus(`Saved \u201C${saved.brush.name}\u201D${saved.kept.length ? `, keeping what ${profile.name} can't use` : ""}.`);
|
|
297
|
+
onSaved?.(saved.brush);
|
|
298
|
+
};
|
|
299
|
+
const errors = check?.issues.filter((i) => i.severity === "error") ?? [];
|
|
300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `flex flex-col gap-2 text-xs text-slate-200 ${className ?? ""}`, "data-testid": "brush-library-editor", children: [
|
|
301
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center justify-between gap-2", children: [
|
|
302
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "font-medium", "data-testid": "brush-library-editor-title", children: original ? `${draft.name}${builtin ? " (built in: saves a copy)" : ""}` : "New brush" }),
|
|
303
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "flex gap-1", children: [
|
|
304
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
305
|
+
"button",
|
|
306
|
+
{
|
|
307
|
+
type: "button",
|
|
308
|
+
className: button,
|
|
309
|
+
title: `A new brush from this one, with only what ${profile.name} uses`,
|
|
310
|
+
onClick: () => {
|
|
311
|
+
setOriginal(null);
|
|
312
|
+
setBuiltin(false);
|
|
313
|
+
setDraft((0, import_brushes3.newBrushFor)(profile, draft));
|
|
314
|
+
setStatus(null);
|
|
315
|
+
},
|
|
316
|
+
children: "New brush"
|
|
317
|
+
}
|
|
318
|
+
),
|
|
319
|
+
onClose && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: button, onClick: onClose, children: "Close" })
|
|
320
|
+
] })
|
|
321
|
+
] }),
|
|
322
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
323
|
+
BrushEditor,
|
|
324
|
+
{
|
|
325
|
+
brush: draft,
|
|
326
|
+
profile,
|
|
327
|
+
preview: renderPreview ? preview : void 0,
|
|
328
|
+
onChange: (next) => {
|
|
329
|
+
setDraft(next);
|
|
330
|
+
setStatus(null);
|
|
331
|
+
},
|
|
332
|
+
onSave: original ? () => save() : void 0,
|
|
333
|
+
saveLabel: builtin ? "Save a copy" : "Save",
|
|
334
|
+
onSaveAs: (name) => save(name)
|
|
335
|
+
}
|
|
336
|
+
),
|
|
337
|
+
errors.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "text-[11px] text-rose-400", "data-testid": "brush-library-editor-issues", children: errors.map((i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
|
|
338
|
+
i.reason,
|
|
339
|
+
" ",
|
|
340
|
+
i.fix
|
|
341
|
+
] }, i.facet)) }),
|
|
342
|
+
status && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "status", className: "text-[11px] text-emerald-400", children: status })
|
|
343
|
+
] });
|
|
344
|
+
};
|
|
345
|
+
|
|
79
346
|
// src/brushes/useBrushLibrary.ts
|
|
80
|
-
var
|
|
347
|
+
var import_react5 = require("react");
|
|
81
348
|
function useBrushLibrary(library, filter = {}) {
|
|
82
|
-
const [entries, setEntries] = (0,
|
|
349
|
+
const [entries, setEntries] = (0, import_react5.useState)([]);
|
|
83
350
|
const { profile, ...rest } = filter;
|
|
84
351
|
const key = `${profile?.id ?? ""}:${JSON.stringify(rest)}`;
|
|
85
|
-
(0,
|
|
352
|
+
(0, import_react5.useEffect)(() => {
|
|
86
353
|
if (!library) return;
|
|
87
354
|
let live = true;
|
|
88
355
|
const read = () => void library.list(filter).then((list) => live && setEntries(list), () => void 0);
|
|
@@ -97,6 +364,8 @@ function useBrushLibrary(library, filter = {}) {
|
|
|
97
364
|
}
|
|
98
365
|
// Annotate the CommonJS export names for ESM import in node:
|
|
99
366
|
0 && (module.exports = {
|
|
367
|
+
BrushEditor,
|
|
100
368
|
BrushLibraryBrowser,
|
|
369
|
+
BrushLibraryEditor,
|
|
101
370
|
useBrushLibrary
|
|
102
371
|
});
|
package/dist/brushes/index.d.cts
CHANGED
package/dist/brushes/index.d.ts
CHANGED
package/dist/brushes/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BrushLibraryEditor,
|
|
2
3
|
useBrushLibrary
|
|
3
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-QIJJCDYW.js";
|
|
4
5
|
import {
|
|
6
|
+
BrushEditor,
|
|
5
7
|
BrushLibraryBrowser
|
|
6
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-76JBZXLM.js";
|
|
7
9
|
export {
|
|
10
|
+
BrushEditor,
|
|
8
11
|
BrushLibraryBrowser,
|
|
12
|
+
BrushLibraryEditor,
|
|
9
13
|
useBrushLibrary
|
|
10
14
|
};
|