@pixerate/editor-react 0.182.0 → 0.183.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/brushes/BrushEditor.d.cts +8 -1
- package/dist/brushes/BrushEditor.d.ts +8 -1
- package/dist/brushes/BrushLibraryEditor.d.cts +1 -1
- package/dist/brushes/BrushLibraryEditor.d.ts +1 -1
- package/dist/brushes/index.cjs +57 -5
- package/dist/brushes/index.js +2 -2
- package/dist/{chunk-THMOZMEE.js → chunk-2QXGKOVK.js} +16 -3
- package/dist/{chunk-WCSMREA4.js → chunk-BICTULEJ.js} +2 -2
- package/dist/{chunk-XORL5PGL.js → chunk-GUBRH2OO.js} +34 -5
- package/dist/image-editor/index.cjs +47 -5
- package/dist/image-editor/index.js +3 -3
- package/dist/index.cjs +47 -5
- package/dist/index.js +3 -3
- package/dist/paint-editor/BrushPanel.d.cts +2 -1
- package/dist/paint-editor/BrushPanel.d.ts +2 -1
- package/dist/paint-editor/index.cjs +35 -4
- package/dist/paint-editor/index.js +4 -2
- package/dist/vector/index.cjs +47 -5
- package/dist/vector/index.js +2 -2
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type Brush, type BrushHostProfile } from '@pixerate/editor/brushes';
|
|
2
|
+
import { type Brush, type BrushHostProfile, type BrushSource } from '@pixerate/editor/brushes';
|
|
3
3
|
type Pixels = {
|
|
4
4
|
width: number;
|
|
5
5
|
height: number;
|
|
@@ -27,6 +27,13 @@ export interface BrushEditorProps {
|
|
|
27
27
|
onSaveAs?: (name: string) => unknown;
|
|
28
28
|
/** Extra controls a host adds to a section (e.g. the sticker picker for stamps). */
|
|
29
29
|
renderExtra?: (section: string) => React.ReactNode;
|
|
30
|
+
/** The library's image sources, offered as stamps and as grain. */
|
|
31
|
+
sources?: ReadonlyArray<Pick<BrushSource, 'id' | 'name'>>;
|
|
32
|
+
/**
|
|
33
|
+
* With it, "Add image…" buttons for an image tip and for grain: it stores the picked file as a
|
|
34
|
+
* source (e.g. `addBrushSourceFromFile`) and returns its `source:<id>` ref.
|
|
35
|
+
*/
|
|
36
|
+
onAddSource?: (file: File) => Promise<string>;
|
|
30
37
|
className?: string;
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type Brush, type BrushHostProfile } from '@pixerate/editor/brushes';
|
|
2
|
+
import { type Brush, type BrushHostProfile, type BrushSource } from '@pixerate/editor/brushes';
|
|
3
3
|
type Pixels = {
|
|
4
4
|
width: number;
|
|
5
5
|
height: number;
|
|
@@ -27,6 +27,13 @@ export interface BrushEditorProps {
|
|
|
27
27
|
onSaveAs?: (name: string) => unknown;
|
|
28
28
|
/** Extra controls a host adds to a section (e.g. the sticker picker for stamps). */
|
|
29
29
|
renderExtra?: (section: string) => React.ReactNode;
|
|
30
|
+
/** The library's image sources, offered as stamps and as grain. */
|
|
31
|
+
sources?: ReadonlyArray<Pick<BrushSource, 'id' | 'name'>>;
|
|
32
|
+
/**
|
|
33
|
+
* With it, "Add image…" buttons for an image tip and for grain: it stores the picked file as a
|
|
34
|
+
* source (e.g. `addBrushSourceFromFile`) and returns its `source:<id>` ref.
|
|
35
|
+
*/
|
|
36
|
+
onAddSource?: (file: File) => Promise<string>;
|
|
30
37
|
className?: string;
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
@@ -24,7 +24,7 @@ export interface BrushLibraryEditorProps {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* `BrushEditor` on a brush library for one host: loads the brush, edits a draft and saves it with
|
|
27
|
-
* `saveBrushEdit`. A saved brush is changed in place, a built-in is saved as a copy, "Save brush"
|
|
27
|
+
* `saveBrushEdit`. Images added for an image tip or grain are stored in the library as sources. A saved brush is changed in place, a built-in is saved as a copy, "Save brush"
|
|
28
28
|
* saves under a new name, and "New brush" starts from the current one with only what the host
|
|
29
29
|
* uses. Facets the host can't use are kept on save; a new brush must pass the host's check.
|
|
30
30
|
*/
|
|
@@ -24,7 +24,7 @@ export interface BrushLibraryEditorProps {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* `BrushEditor` on a brush library for one host: loads the brush, edits a draft and saves it with
|
|
27
|
-
* `saveBrushEdit`. A saved brush is changed in place, a built-in is saved as a copy, "Save brush"
|
|
27
|
+
* `saveBrushEdit`. Images added for an image tip or grain are stored in the library as sources. A saved brush is changed in place, a built-in is saved as a copy, "Save brush"
|
|
28
28
|
* saves under a new name, and "New brush" starts from the current one with only what the host
|
|
29
29
|
* uses. Facets the host can't use are kept on save; a new brush must pass the host's check.
|
|
30
30
|
*/
|
package/dist/brushes/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/brushes/index.ts
|
|
@@ -28,7 +38,7 @@ __export(brushes_exports, {
|
|
|
28
38
|
module.exports = __toCommonJS(brushes_exports);
|
|
29
39
|
|
|
30
40
|
// src/brushes/BrushEditor.tsx
|
|
31
|
-
var import_react2 = require("react");
|
|
41
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
32
42
|
var import_brushes = require("@pixerate/editor/brushes");
|
|
33
43
|
|
|
34
44
|
// src/paint-editor/shared.tsx
|
|
@@ -96,8 +106,8 @@ var ErrorLine = ({ error }) => error ? /* @__PURE__ */ (0, import_jsx_runtime.js
|
|
|
96
106
|
|
|
97
107
|
// src/brushes/BrushEditor.tsx
|
|
98
108
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
99
|
-
var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
100
|
-
const sections = (0, import_react2.useMemo)(() => (0, import_brushes.brushEditorSections)(brush, profile), [brush, profile]);
|
|
109
|
+
var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
|
|
110
|
+
const sections = (0, import_react2.useMemo)(() => (0, import_brushes.brushEditorSections)(brush, profile, { sources }), [brush, profile, sources]);
|
|
101
111
|
const scope = (0, import_react2.useMemo)(() => (0, import_brushes.brushEditorScope)(brush, profile), [brush, profile]);
|
|
102
112
|
const [problems, setProblems] = (0, import_react2.useState)(null);
|
|
103
113
|
const [name, setName] = (0, import_react2.useState)("");
|
|
@@ -115,12 +125,24 @@ var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, pr
|
|
|
115
125
|
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
116
126
|
if (r.brush !== brush) onChange(r.brush);
|
|
117
127
|
};
|
|
128
|
+
const addSource = onAddSource ? async (file, as) => {
|
|
129
|
+
try {
|
|
130
|
+
const r = (0, import_brushes.withBrushSource)(brush, await onAddSource(file), as);
|
|
131
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
132
|
+
onChange(r.brush);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
setProblems(e.message);
|
|
135
|
+
}
|
|
136
|
+
} : void 0;
|
|
118
137
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
119
138
|
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", ...previewBackground ? { background: previewBackground } : {} } }) : 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
139
|
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
140
|
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
141
|
/* @__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.
|
|
142
|
+
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react2.default.Fragment, { children: [
|
|
143
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditorControl, { control: c, onSet: set }),
|
|
144
|
+
addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
|
|
145
|
+
] }, c.path)),
|
|
124
146
|
renderExtra?.(s.id)
|
|
125
147
|
] }, s.id)),
|
|
126
148
|
(onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
@@ -133,6 +155,23 @@ var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, pr
|
|
|
133
155
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorLine, { error: problems })
|
|
134
156
|
] });
|
|
135
157
|
};
|
|
158
|
+
var AddImage = ({ label, onFile }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: `${button} cursor-pointer self-start`, children: [
|
|
159
|
+
label,
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
161
|
+
"input",
|
|
162
|
+
{
|
|
163
|
+
type: "file",
|
|
164
|
+
accept: "image/*",
|
|
165
|
+
"aria-label": label,
|
|
166
|
+
className: "sr-only",
|
|
167
|
+
onChange: (e) => {
|
|
168
|
+
const file = e.target.files?.[0];
|
|
169
|
+
e.target.value = "";
|
|
170
|
+
if (file) onFile(file);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
] });
|
|
136
175
|
var EditorControl = ({ control: c, onSet }) => {
|
|
137
176
|
const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
138
177
|
switch (c.kind) {
|
|
@@ -263,6 +302,17 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
263
302
|
const [draft, setDraft] = (0, import_react4.useState)(null);
|
|
264
303
|
const [status, setStatus] = (0, import_react4.useState)(null);
|
|
265
304
|
const [preview, setPreview] = (0, import_react4.useState)(null);
|
|
305
|
+
const [sources, setSources] = (0, import_react4.useState)([]);
|
|
306
|
+
(0, import_react4.useEffect)(() => {
|
|
307
|
+
let live = true;
|
|
308
|
+
const read = () => void library.listSources().then((list) => live && setSources(list), () => void 0);
|
|
309
|
+
read();
|
|
310
|
+
const off = library.subscribe(read);
|
|
311
|
+
return () => {
|
|
312
|
+
live = false;
|
|
313
|
+
off();
|
|
314
|
+
};
|
|
315
|
+
}, [library]);
|
|
266
316
|
(0, import_react4.useEffect)(() => {
|
|
267
317
|
let live = true;
|
|
268
318
|
setStatus(null);
|
|
@@ -334,7 +384,9 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
334
384
|
},
|
|
335
385
|
onSave: original ? () => save() : void 0,
|
|
336
386
|
saveLabel: builtin ? "Save a copy" : "Save",
|
|
337
|
-
onSaveAs: (name) => save(name)
|
|
387
|
+
onSaveAs: (name) => save(name),
|
|
388
|
+
sources,
|
|
389
|
+
onAddSource: async (file) => (await (0, import_brushes3.addBrushSourceFromFile)(library, file)).ref
|
|
338
390
|
}
|
|
339
391
|
),
|
|
340
392
|
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: [
|
package/dist/brushes/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BrushLibraryEditor,
|
|
3
3
|
useBrushLibrary
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-2QXGKOVK.js";
|
|
5
5
|
import {
|
|
6
6
|
BrushEditor,
|
|
7
7
|
BrushLibraryBrowser
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-GUBRH2OO.js";
|
|
9
9
|
export {
|
|
10
10
|
BrushEditor,
|
|
11
11
|
BrushLibraryBrowser,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BrushEditor,
|
|
3
3
|
button
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GUBRH2OO.js";
|
|
5
5
|
|
|
6
6
|
// src/brushes/BrushLibraryEditor.tsx
|
|
7
7
|
import { useEffect, useMemo, useState } from "react";
|
|
8
|
-
import { brushPreviewColours, checkBrushEdit, newBrushFor, saveBrushEdit } from "@pixerate/editor/brushes";
|
|
8
|
+
import { addBrushSourceFromFile, brushPreviewColours, checkBrushEdit, newBrushFor, saveBrushEdit } from "@pixerate/editor/brushes";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPaper = "#ffffff", previewColor, onSaved, onClose, className }) => {
|
|
11
11
|
const [original, setOriginal] = useState(null);
|
|
@@ -13,6 +13,17 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
13
13
|
const [draft, setDraft] = useState(null);
|
|
14
14
|
const [status, setStatus] = useState(null);
|
|
15
15
|
const [preview, setPreview] = useState(null);
|
|
16
|
+
const [sources, setSources] = useState([]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let live = true;
|
|
19
|
+
const read = () => void library.listSources().then((list) => live && setSources(list), () => void 0);
|
|
20
|
+
read();
|
|
21
|
+
const off = library.subscribe(read);
|
|
22
|
+
return () => {
|
|
23
|
+
live = false;
|
|
24
|
+
off();
|
|
25
|
+
};
|
|
26
|
+
}, [library]);
|
|
16
27
|
useEffect(() => {
|
|
17
28
|
let live = true;
|
|
18
29
|
setStatus(null);
|
|
@@ -84,7 +95,9 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
84
95
|
},
|
|
85
96
|
onSave: original ? () => save() : void 0,
|
|
86
97
|
saveLabel: builtin ? "Save a copy" : "Save",
|
|
87
|
-
onSaveAs: (name) => save(name)
|
|
98
|
+
onSaveAs: (name) => save(name),
|
|
99
|
+
sources,
|
|
100
|
+
onAddSource: async (file) => (await addBrushSourceFromFile(library, file)).ref
|
|
88
101
|
}
|
|
89
102
|
),
|
|
90
103
|
errors.length > 0 && /* @__PURE__ */ jsx("ul", { className: "text-[11px] text-rose-400", "data-testid": "brush-library-editor-issues", children: errors.map((i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
@@ -44,10 +44,10 @@ import {
|
|
|
44
44
|
import {
|
|
45
45
|
BrushLibraryEditor,
|
|
46
46
|
useBrushLibrary
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-2QXGKOVK.js";
|
|
48
48
|
import {
|
|
49
49
|
BrushLibraryBrowser
|
|
50
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-GUBRH2OO.js";
|
|
51
51
|
|
|
52
52
|
// src/image-editor/useImageEditor.ts
|
|
53
53
|
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
@@ -140,11 +140,11 @@ var CommitColorInput = ({ value, label, onCommit, className }) => {
|
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
// src/brushes/BrushEditor.tsx
|
|
143
|
-
import { useMemo as useMemo2, useState as useState3 } from "react";
|
|
144
|
-
import { brushEditorScope, brushEditorSections, PAINT_PROFILE, setBrushEditorValue } from "@pixerate/editor/brushes";
|
|
143
|
+
import React3, { useMemo as useMemo2, useState as useState3 } from "react";
|
|
144
|
+
import { brushEditorScope, brushEditorSections, PAINT_PROFILE, setBrushEditorValue, withBrushSource } from "@pixerate/editor/brushes";
|
|
145
145
|
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
146
|
-
var BrushEditor = ({ brush, profile = PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
147
|
-
const sections = useMemo2(() => brushEditorSections(brush, profile), [brush, profile]);
|
|
146
|
+
var BrushEditor = ({ brush, profile = PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
|
|
147
|
+
const sections = useMemo2(() => brushEditorSections(brush, profile, { sources }), [brush, profile, sources]);
|
|
148
148
|
const scope = useMemo2(() => brushEditorScope(brush, profile), [brush, profile]);
|
|
149
149
|
const [problems, setProblems] = useState3(null);
|
|
150
150
|
const [name, setName] = useState3("");
|
|
@@ -162,12 +162,24 @@ var BrushEditor = ({ brush, profile = PAINT_PROFILE, onChange, preview, previewB
|
|
|
162
162
|
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
163
163
|
if (r.brush !== brush) onChange(r.brush);
|
|
164
164
|
};
|
|
165
|
+
const addSource = onAddSource ? async (file, as) => {
|
|
166
|
+
try {
|
|
167
|
+
const r = withBrushSource(brush, await onAddSource(file), as);
|
|
168
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
169
|
+
onChange(r.brush);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
setProblems(e.message);
|
|
172
|
+
}
|
|
173
|
+
} : void 0;
|
|
165
174
|
return /* @__PURE__ */ jsxs3("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
166
175
|
typeof preview === "string" ? /* @__PURE__ */ jsx3("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1", ...previewBackground ? { background: previewBackground } : {} } }) : preview !== void 0 && /* @__PURE__ */ jsx3(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
|
|
167
176
|
scope.note && /* @__PURE__ */ jsx3("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 }),
|
|
168
177
|
sections.map((s) => /* @__PURE__ */ jsxs3("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
|
|
169
178
|
/* @__PURE__ */ jsx3("span", { className: "font-medium text-slate-300", children: s.title }),
|
|
170
|
-
s.controls.map((c) => /* @__PURE__ */
|
|
179
|
+
s.controls.map((c) => /* @__PURE__ */ jsxs3(React3.Fragment, { children: [
|
|
180
|
+
/* @__PURE__ */ jsx3(EditorControl, { control: c, onSet: set }),
|
|
181
|
+
addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ jsx3(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
|
|
182
|
+
] }, c.path)),
|
|
171
183
|
renderExtra?.(s.id)
|
|
172
184
|
] }, s.id)),
|
|
173
185
|
(onSave || onSaveAs) && /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
@@ -180,6 +192,23 @@ var BrushEditor = ({ brush, profile = PAINT_PROFILE, onChange, preview, previewB
|
|
|
180
192
|
/* @__PURE__ */ jsx3(ErrorLine, { error: problems })
|
|
181
193
|
] });
|
|
182
194
|
};
|
|
195
|
+
var AddImage = ({ label, onFile }) => /* @__PURE__ */ jsxs3("label", { className: `${button} cursor-pointer self-start`, children: [
|
|
196
|
+
label,
|
|
197
|
+
/* @__PURE__ */ jsx3(
|
|
198
|
+
"input",
|
|
199
|
+
{
|
|
200
|
+
type: "file",
|
|
201
|
+
accept: "image/*",
|
|
202
|
+
"aria-label": label,
|
|
203
|
+
className: "sr-only",
|
|
204
|
+
onChange: (e) => {
|
|
205
|
+
const file = e.target.files?.[0];
|
|
206
|
+
e.target.value = "";
|
|
207
|
+
if (file) onFile(file);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
] });
|
|
183
212
|
var EditorControl = ({ control: c, onSet }) => {
|
|
184
213
|
const note = c.note ? /* @__PURE__ */ jsx3("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
185
214
|
switch (c.kind) {
|
|
@@ -4710,11 +4710,11 @@ var PaintSlider = ({ control, value, onChange, onCommit }) => {
|
|
|
4710
4710
|
var ErrorLine = ({ error }) => error ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
|
|
4711
4711
|
|
|
4712
4712
|
// src/brushes/BrushEditor.tsx
|
|
4713
|
-
var import_react27 = require("react");
|
|
4713
|
+
var import_react27 = __toESM(require("react"), 1);
|
|
4714
4714
|
var import_brushes2 = require("@pixerate/editor/brushes");
|
|
4715
4715
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
4716
|
-
var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
4717
|
-
const sections = (0, import_react27.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile), [brush, profile]);
|
|
4716
|
+
var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
|
|
4717
|
+
const sections = (0, import_react27.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile, { sources }), [brush, profile, sources]);
|
|
4718
4718
|
const scope = (0, import_react27.useMemo)(() => (0, import_brushes2.brushEditorScope)(brush, profile), [brush, profile]);
|
|
4719
4719
|
const [problems, setProblems] = (0, import_react27.useState)(null);
|
|
4720
4720
|
const [name, setName] = (0, import_react27.useState)("");
|
|
@@ -4732,12 +4732,24 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
|
|
|
4732
4732
|
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
4733
4733
|
if (r.brush !== brush) onChange(r.brush);
|
|
4734
4734
|
};
|
|
4735
|
+
const addSource = onAddSource ? async (file, as) => {
|
|
4736
|
+
try {
|
|
4737
|
+
const r = (0, import_brushes2.withBrushSource)(brush, await onAddSource(file), as);
|
|
4738
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
4739
|
+
onChange(r.brush);
|
|
4740
|
+
} catch (e) {
|
|
4741
|
+
setProblems(e.message);
|
|
4742
|
+
}
|
|
4743
|
+
} : void 0;
|
|
4735
4744
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
4736
4745
|
typeof preview === "string" ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1", ...previewBackground ? { background: previewBackground } : {} } }) : preview !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
|
|
4737
4746
|
scope.note && /* @__PURE__ */ (0, import_jsx_runtime27.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 }),
|
|
4738
4747
|
sections.map((s) => /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
|
|
4739
4748
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "font-medium text-slate-300", children: s.title }),
|
|
4740
|
-
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime27.
|
|
4749
|
+
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(import_react27.default.Fragment, { children: [
|
|
4750
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(EditorControl, { control: c, onSet: set }),
|
|
4751
|
+
addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
|
|
4752
|
+
] }, c.path)),
|
|
4741
4753
|
renderExtra?.(s.id)
|
|
4742
4754
|
] }, s.id)),
|
|
4743
4755
|
(onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
@@ -4750,6 +4762,23 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
|
|
|
4750
4762
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(ErrorLine, { error: problems })
|
|
4751
4763
|
] });
|
|
4752
4764
|
};
|
|
4765
|
+
var AddImage = ({ label, onFile }) => /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("label", { className: `${button2} cursor-pointer self-start`, children: [
|
|
4766
|
+
label,
|
|
4767
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
4768
|
+
"input",
|
|
4769
|
+
{
|
|
4770
|
+
type: "file",
|
|
4771
|
+
accept: "image/*",
|
|
4772
|
+
"aria-label": label,
|
|
4773
|
+
className: "sr-only",
|
|
4774
|
+
onChange: (e) => {
|
|
4775
|
+
const file = e.target.files?.[0];
|
|
4776
|
+
e.target.value = "";
|
|
4777
|
+
if (file) onFile(file);
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
)
|
|
4781
|
+
] });
|
|
4753
4782
|
var EditorControl = ({ control: c, onSet }) => {
|
|
4754
4783
|
const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
4755
4784
|
switch (c.kind) {
|
|
@@ -4827,6 +4856,17 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
4827
4856
|
const [draft, setDraft] = (0, import_react28.useState)(null);
|
|
4828
4857
|
const [status, setStatus] = (0, import_react28.useState)(null);
|
|
4829
4858
|
const [preview, setPreview] = (0, import_react28.useState)(null);
|
|
4859
|
+
const [sources, setSources] = (0, import_react28.useState)([]);
|
|
4860
|
+
(0, import_react28.useEffect)(() => {
|
|
4861
|
+
let live = true;
|
|
4862
|
+
const read = () => void library.listSources().then((list) => live && setSources(list), () => void 0);
|
|
4863
|
+
read();
|
|
4864
|
+
const off = library.subscribe(read);
|
|
4865
|
+
return () => {
|
|
4866
|
+
live = false;
|
|
4867
|
+
off();
|
|
4868
|
+
};
|
|
4869
|
+
}, [library]);
|
|
4830
4870
|
(0, import_react28.useEffect)(() => {
|
|
4831
4871
|
let live = true;
|
|
4832
4872
|
setStatus(null);
|
|
@@ -4898,7 +4938,9 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
4898
4938
|
},
|
|
4899
4939
|
onSave: original ? () => save() : void 0,
|
|
4900
4940
|
saveLabel: builtin ? "Save a copy" : "Save",
|
|
4901
|
-
onSaveAs: (name) => save(name)
|
|
4941
|
+
onSaveAs: (name) => save(name),
|
|
4942
|
+
sources,
|
|
4943
|
+
onAddSource: async (file) => (await (0, import_brushes3.addBrushSourceFromFile)(library, file)).ref
|
|
4902
4944
|
}
|
|
4903
4945
|
),
|
|
4904
4946
|
errors.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("ul", { className: "text-[11px] text-rose-400", "data-testid": "brush-library-editor-issues", children: errors.map((i) => /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("li", { children: [
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
useImageEditor,
|
|
30
30
|
useImageEffectsTools,
|
|
31
31
|
useImageHistogram
|
|
32
|
-
} from "../chunk-
|
|
32
|
+
} from "../chunk-BICTULEJ.js";
|
|
33
33
|
import {
|
|
34
34
|
ImageCheckbox,
|
|
35
35
|
ImageColor,
|
|
@@ -44,8 +44,8 @@ import "../chunk-5RPB4WGT.js";
|
|
|
44
44
|
import "../chunk-KIRIU53A.js";
|
|
45
45
|
import "../chunk-3I7FOSLF.js";
|
|
46
46
|
import "../chunk-W5CMGX3I.js";
|
|
47
|
-
import "../chunk-
|
|
48
|
-
import "../chunk-
|
|
47
|
+
import "../chunk-2QXGKOVK.js";
|
|
48
|
+
import "../chunk-GUBRH2OO.js";
|
|
49
49
|
export {
|
|
50
50
|
AdjustmentLayersPanel,
|
|
51
51
|
BrushOptionsBar,
|
package/dist/index.cjs
CHANGED
|
@@ -8474,11 +8474,11 @@ var PaintSlider = ({ control, value, onChange, onCommit }) => {
|
|
|
8474
8474
|
var ErrorLine = ({ error }) => error ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
|
|
8475
8475
|
|
|
8476
8476
|
// src/brushes/BrushEditor.tsx
|
|
8477
|
-
var import_react63 = require("react");
|
|
8477
|
+
var import_react63 = __toESM(require("react"), 1);
|
|
8478
8478
|
var import_brushes2 = require("@pixerate/editor/brushes");
|
|
8479
8479
|
var import_jsx_runtime44 = require("react/jsx-runtime");
|
|
8480
|
-
var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
8481
|
-
const sections = (0, import_react63.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile), [brush, profile]);
|
|
8480
|
+
var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
|
|
8481
|
+
const sections = (0, import_react63.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile, { sources }), [brush, profile, sources]);
|
|
8482
8482
|
const scope = (0, import_react63.useMemo)(() => (0, import_brushes2.brushEditorScope)(brush, profile), [brush, profile]);
|
|
8483
8483
|
const [problems, setProblems] = (0, import_react63.useState)(null);
|
|
8484
8484
|
const [name, setName] = (0, import_react63.useState)("");
|
|
@@ -8496,12 +8496,24 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
|
|
|
8496
8496
|
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
8497
8497
|
if (r.brush !== brush) onChange(r.brush);
|
|
8498
8498
|
};
|
|
8499
|
+
const addSource = onAddSource ? async (file, as) => {
|
|
8500
|
+
try {
|
|
8501
|
+
const r = (0, import_brushes2.withBrushSource)(brush, await onAddSource(file), as);
|
|
8502
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
8503
|
+
onChange(r.brush);
|
|
8504
|
+
} catch (e) {
|
|
8505
|
+
setProblems(e.message);
|
|
8506
|
+
}
|
|
8507
|
+
} : void 0;
|
|
8499
8508
|
return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
8500
8509
|
typeof preview === "string" ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1", ...previewBackground ? { background: previewBackground } : {} } }) : preview !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
|
|
8501
8510
|
scope.note && /* @__PURE__ */ (0, import_jsx_runtime44.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 }),
|
|
8502
8511
|
sections.map((s) => /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
|
|
8503
8512
|
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: "font-medium text-slate-300", children: s.title }),
|
|
8504
|
-
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime44.
|
|
8513
|
+
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(import_react63.default.Fragment, { children: [
|
|
8514
|
+
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(EditorControl, { control: c, onSet: set }),
|
|
8515
|
+
addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
|
|
8516
|
+
] }, c.path)),
|
|
8505
8517
|
renderExtra?.(s.id)
|
|
8506
8518
|
] }, s.id)),
|
|
8507
8519
|
(onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
@@ -8514,6 +8526,23 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
|
|
|
8514
8526
|
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(ErrorLine, { error: problems })
|
|
8515
8527
|
] });
|
|
8516
8528
|
};
|
|
8529
|
+
var AddImage = ({ label, onFile }) => /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("label", { className: `${button2} cursor-pointer self-start`, children: [
|
|
8530
|
+
label,
|
|
8531
|
+
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
|
|
8532
|
+
"input",
|
|
8533
|
+
{
|
|
8534
|
+
type: "file",
|
|
8535
|
+
accept: "image/*",
|
|
8536
|
+
"aria-label": label,
|
|
8537
|
+
className: "sr-only",
|
|
8538
|
+
onChange: (e) => {
|
|
8539
|
+
const file = e.target.files?.[0];
|
|
8540
|
+
e.target.value = "";
|
|
8541
|
+
if (file) onFile(file);
|
|
8542
|
+
}
|
|
8543
|
+
}
|
|
8544
|
+
)
|
|
8545
|
+
] });
|
|
8517
8546
|
var EditorControl = ({ control: c, onSet }) => {
|
|
8518
8547
|
const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
8519
8548
|
switch (c.kind) {
|
|
@@ -8591,6 +8620,17 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
8591
8620
|
const [draft, setDraft] = (0, import_react64.useState)(null);
|
|
8592
8621
|
const [status, setStatus] = (0, import_react64.useState)(null);
|
|
8593
8622
|
const [preview, setPreview] = (0, import_react64.useState)(null);
|
|
8623
|
+
const [sources, setSources] = (0, import_react64.useState)([]);
|
|
8624
|
+
(0, import_react64.useEffect)(() => {
|
|
8625
|
+
let live = true;
|
|
8626
|
+
const read = () => void library.listSources().then((list) => live && setSources(list), () => void 0);
|
|
8627
|
+
read();
|
|
8628
|
+
const off = library.subscribe(read);
|
|
8629
|
+
return () => {
|
|
8630
|
+
live = false;
|
|
8631
|
+
off();
|
|
8632
|
+
};
|
|
8633
|
+
}, [library]);
|
|
8594
8634
|
(0, import_react64.useEffect)(() => {
|
|
8595
8635
|
let live = true;
|
|
8596
8636
|
setStatus(null);
|
|
@@ -8662,7 +8702,9 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
8662
8702
|
},
|
|
8663
8703
|
onSave: original ? () => save() : void 0,
|
|
8664
8704
|
saveLabel: builtin ? "Save a copy" : "Save",
|
|
8665
|
-
onSaveAs: (name) => save(name)
|
|
8705
|
+
onSaveAs: (name) => save(name),
|
|
8706
|
+
sources,
|
|
8707
|
+
onAddSource: async (file) => (await (0, import_brushes3.addBrushSourceFromFile)(library, file)).ref
|
|
8666
8708
|
}
|
|
8667
8709
|
),
|
|
8668
8710
|
errors.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("ul", { className: "text-[11px] text-rose-400", "data-testid": "brush-library-editor-issues", children: errors.map((i) => /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("li", { children: [
|
package/dist/index.js
CHANGED
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
useImageEditor,
|
|
63
63
|
useImageEffectsTools,
|
|
64
64
|
useImageHistogram
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-BICTULEJ.js";
|
|
66
66
|
import {
|
|
67
67
|
ImageCheckbox,
|
|
68
68
|
ImageColor,
|
|
@@ -82,8 +82,8 @@ import {
|
|
|
82
82
|
useAgentPlayback,
|
|
83
83
|
usePlaybackSurface
|
|
84
84
|
} from "./chunk-W5CMGX3I.js";
|
|
85
|
-
import "./chunk-
|
|
86
|
-
import "./chunk-
|
|
85
|
+
import "./chunk-2QXGKOVK.js";
|
|
86
|
+
import "./chunk-GUBRH2OO.js";
|
|
87
87
|
import {
|
|
88
88
|
CommandPalette,
|
|
89
89
|
useCommandPalette,
|
|
@@ -12,6 +12,7 @@ export interface BrushPanelProps {
|
|
|
12
12
|
* grouped by medium and variety, tools apart) and the active brush in the `BrushEditor`: its
|
|
13
13
|
* facets with a live preview, and "Save brush" into the editor's brush library. The paint
|
|
14
14
|
* editor adds the brush's own gradient, the sticker stamps, what the brush carries (Load /
|
|
15
|
-
* Clean), and import and export of library files.
|
|
15
|
+
* Clean), and import and export of library files. Images picked for an image tip or grain are
|
|
16
|
+
* added to the brush library as sources.
|
|
16
17
|
*/
|
|
17
18
|
export declare const BrushPanel: React.FC<BrushPanelProps>;
|
|
@@ -12,6 +12,7 @@ export interface BrushPanelProps {
|
|
|
12
12
|
* grouped by medium and variety, tools apart) and the active brush in the `BrushEditor`: its
|
|
13
13
|
* facets with a live preview, and "Save brush" into the editor's brush library. The paint
|
|
14
14
|
* editor adds the brush's own gradient, the sticker stamps, what the brush carries (Load /
|
|
15
|
-
* Clean), and import and export of library files.
|
|
15
|
+
* Clean), and import and export of library files. Images picked for an image tip or grain are
|
|
16
|
+
* added to the brush library as sources.
|
|
16
17
|
*/
|
|
17
18
|
export declare const BrushPanel: React.FC<BrushPanelProps>;
|
|
@@ -664,11 +664,11 @@ var import_paint_editor5 = require("@pixerate/editor/paint-editor");
|
|
|
664
664
|
var import_brushes3 = require("@pixerate/editor/brushes");
|
|
665
665
|
|
|
666
666
|
// src/brushes/BrushEditor.tsx
|
|
667
|
-
var import_react5 = require("react");
|
|
667
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
668
668
|
var import_brushes = require("@pixerate/editor/brushes");
|
|
669
669
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
670
|
-
var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
671
|
-
const sections = (0, import_react5.useMemo)(() => (0, import_brushes.brushEditorSections)(brush, profile), [brush, profile]);
|
|
670
|
+
var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
|
|
671
|
+
const sections = (0, import_react5.useMemo)(() => (0, import_brushes.brushEditorSections)(brush, profile, { sources }), [brush, profile, sources]);
|
|
672
672
|
const scope = (0, import_react5.useMemo)(() => (0, import_brushes.brushEditorScope)(brush, profile), [brush, profile]);
|
|
673
673
|
const [problems, setProblems] = (0, import_react5.useState)(null);
|
|
674
674
|
const [name, setName] = (0, import_react5.useState)("");
|
|
@@ -686,12 +686,24 @@ var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, pr
|
|
|
686
686
|
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
687
687
|
if (r.brush !== brush) onChange(r.brush);
|
|
688
688
|
};
|
|
689
|
+
const addSource = onAddSource ? async (file, as) => {
|
|
690
|
+
try {
|
|
691
|
+
const r = (0, import_brushes.withBrushSource)(brush, await onAddSource(file), as);
|
|
692
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
693
|
+
onChange(r.brush);
|
|
694
|
+
} catch (e) {
|
|
695
|
+
setProblems(e.message);
|
|
696
|
+
}
|
|
697
|
+
} : void 0;
|
|
689
698
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
690
699
|
typeof preview === "string" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1", ...previewBackground ? { background: previewBackground } : {} } }) : preview !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
|
|
691
700
|
scope.note && /* @__PURE__ */ (0, import_jsx_runtime4.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 }),
|
|
692
701
|
sections.map((s) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
|
|
693
702
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "font-medium text-slate-300", children: s.title }),
|
|
694
|
-
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime4.
|
|
703
|
+
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react5.default.Fragment, { children: [
|
|
704
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EditorControl, { control: c, onSet: set }),
|
|
705
|
+
addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
|
|
706
|
+
] }, c.path)),
|
|
695
707
|
renderExtra?.(s.id)
|
|
696
708
|
] }, s.id)),
|
|
697
709
|
(onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
@@ -704,6 +716,23 @@ var BrushEditor = ({ brush, profile = import_brushes.PAINT_PROFILE, onChange, pr
|
|
|
704
716
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorLine, { error: problems })
|
|
705
717
|
] });
|
|
706
718
|
};
|
|
719
|
+
var AddImage = ({ label, onFile }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: `${button} cursor-pointer self-start`, children: [
|
|
720
|
+
label,
|
|
721
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
722
|
+
"input",
|
|
723
|
+
{
|
|
724
|
+
type: "file",
|
|
725
|
+
accept: "image/*",
|
|
726
|
+
"aria-label": label,
|
|
727
|
+
className: "sr-only",
|
|
728
|
+
onChange: (e) => {
|
|
729
|
+
const file = e.target.files?.[0];
|
|
730
|
+
e.target.value = "";
|
|
731
|
+
if (file) onFile(file);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
)
|
|
735
|
+
] });
|
|
707
736
|
var EditorControl = ({ control: c, onSet }) => {
|
|
708
737
|
const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
709
738
|
switch (c.kind) {
|
|
@@ -1070,6 +1099,8 @@ var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, clas
|
|
|
1070
1099
|
preview,
|
|
1071
1100
|
onChange: (next) => attempt(() => controller.setBrushSpec(next)),
|
|
1072
1101
|
onSaveAs: (name) => controller.saveBrush({ id: slug(name), name }),
|
|
1102
|
+
sources: controller.brushSources.all(),
|
|
1103
|
+
onAddSource: async (file) => (await (0, import_brushes3.addBrushSourceFromFile)(controller.brushLibrary, file)).ref,
|
|
1073
1104
|
renderExtra: (section) => {
|
|
1074
1105
|
if (section === "shape" && brush.engine === "sticker")
|
|
1075
1106
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(StickerPicker, { controller, label: "Sticker stamps", selected: brush.sticker.stamps, onPick: (ref) => controller.setBrush({ sticker: { stamps: (0, import_paint_editor5.toggleStickerRef)(brush.sticker.stamps, ref) } }) });
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
chip,
|
|
30
30
|
panel,
|
|
31
31
|
useAttempt
|
|
32
|
-
} from "../chunk-
|
|
32
|
+
} from "../chunk-GUBRH2OO.js";
|
|
33
33
|
|
|
34
34
|
// src/paint-editor/usePaintEditor.ts
|
|
35
35
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
@@ -559,7 +559,7 @@ var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", cla
|
|
|
559
559
|
// src/paint-editor/BrushPanel.tsx
|
|
560
560
|
import { useMemo as useMemo3, useRef as useRef4 } from "react";
|
|
561
561
|
import { brushLoadColor, brushTakesPaint, downloadBytes as downloadBytes2, toggleStickerRef, DEFAULT_PAINT_GRADIENT } from "@pixerate/editor/paint-editor";
|
|
562
|
-
import { brushColourHex, brushPreviewColours, PAINT_PROFILE } from "@pixerate/editor/brushes";
|
|
562
|
+
import { addBrushSourceFromFile, brushColourHex, brushPreviewColours, PAINT_PROFILE } from "@pixerate/editor/brushes";
|
|
563
563
|
|
|
564
564
|
// src/paint-editor/PaintGradientEditor.tsx
|
|
565
565
|
import { PAINT_GRADIENT_KIT } from "@pixerate/editor/paint-editor";
|
|
@@ -622,6 +622,8 @@ var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, clas
|
|
|
622
622
|
preview,
|
|
623
623
|
onChange: (next) => attempt(() => controller.setBrushSpec(next)),
|
|
624
624
|
onSaveAs: (name) => controller.saveBrush({ id: slug(name), name }),
|
|
625
|
+
sources: controller.brushSources.all(),
|
|
626
|
+
onAddSource: async (file) => (await addBrushSourceFromFile(controller.brushLibrary, file)).ref,
|
|
625
627
|
renderExtra: (section) => {
|
|
626
628
|
if (section === "shape" && brush.engine === "sticker")
|
|
627
629
|
return /* @__PURE__ */ jsx5(StickerPicker, { controller, label: "Sticker stamps", selected: brush.sticker.stamps, onPick: (ref) => controller.setBrush({ sticker: { stamps: toggleStickerRef(brush.sticker.stamps, ref) } }) });
|
package/dist/vector/index.cjs
CHANGED
|
@@ -1272,11 +1272,11 @@ var PaintSlider = ({ control, value, onChange, onCommit }) => {
|
|
|
1272
1272
|
var ErrorLine = ({ error }) => error ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
|
|
1273
1273
|
|
|
1274
1274
|
// src/brushes/BrushEditor.tsx
|
|
1275
|
-
var import_react9 = require("react");
|
|
1275
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
1276
1276
|
var import_brushes2 = require("@pixerate/editor/brushes");
|
|
1277
1277
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1278
|
-
var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, className }) => {
|
|
1279
|
-
const sections = (0, import_react9.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile), [brush, profile]);
|
|
1278
|
+
var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, preview, previewBackground, onSave, saveLabel = "Save", onSaveAs, renderExtra, sources, onAddSource, className }) => {
|
|
1279
|
+
const sections = (0, import_react9.useMemo)(() => (0, import_brushes2.brushEditorSections)(brush, profile, { sources }), [brush, profile, sources]);
|
|
1280
1280
|
const scope = (0, import_react9.useMemo)(() => (0, import_brushes2.brushEditorScope)(brush, profile), [brush, profile]);
|
|
1281
1281
|
const [problems, setProblems] = (0, import_react9.useState)(null);
|
|
1282
1282
|
const [name, setName] = (0, import_react9.useState)("");
|
|
@@ -1294,12 +1294,24 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
|
|
|
1294
1294
|
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
1295
1295
|
if (r.brush !== brush) onChange(r.brush);
|
|
1296
1296
|
};
|
|
1297
|
+
const addSource = onAddSource ? async (file, as) => {
|
|
1298
|
+
try {
|
|
1299
|
+
const r = (0, import_brushes2.withBrushSource)(brush, await onAddSource(file), as);
|
|
1300
|
+
setProblems(r.problems.length ? r.problems.join(" ") : null);
|
|
1301
|
+
onChange(r.brush);
|
|
1302
|
+
} catch (e) {
|
|
1303
|
+
setProblems(e.message);
|
|
1304
|
+
}
|
|
1305
|
+
} : void 0;
|
|
1297
1306
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-testid": "brush-editor", children: [
|
|
1298
1307
|
typeof preview === "string" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: preview, alt: "Brush preview", className: "rounded object-contain", style: { width: "100%", aspectRatio: "4 / 1", ...previewBackground ? { background: previewBackground } : {} } }) : preview !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PixelCanvas, { pixels: preview, label: "Brush preview", className: "rounded", style: { width: "100%", aspectRatio: preview ? `${preview.width} / ${preview.height}` : "4 / 1" } }),
|
|
1299
1308
|
scope.note && /* @__PURE__ */ (0, import_jsx_runtime8.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 }),
|
|
1300
1309
|
sections.map((s) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { className: "flex flex-col gap-1.5", "data-section": s.id, ...s.id === "behaviour" ? { "data-testid": "brush-engine" } : {}, children: [
|
|
1301
1310
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "font-medium text-slate-300", children: s.title }),
|
|
1302
|
-
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime8.
|
|
1311
|
+
s.controls.map((c) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react9.default.Fragment, { children: [
|
|
1312
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EditorControl, { control: c, onSet: set }),
|
|
1313
|
+
addSource && (c.path === "tip.stamps" || c.path === "tip.grain.source") && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AddImage, { label: c.path === "tip.stamps" ? "Add image tip\u2026" : "Add grain image\u2026", onFile: (f) => addSource(f, c.path === "tip.stamps" ? "tip" : "grain") })
|
|
1314
|
+
] }, c.path)),
|
|
1303
1315
|
renderExtra?.(s.id)
|
|
1304
1316
|
] }, s.id)),
|
|
1305
1317
|
(onSave || onSaveAs) && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
@@ -1312,6 +1324,23 @@ var BrushEditor = ({ brush, profile = import_brushes2.PAINT_PROFILE, onChange, p
|
|
|
1312
1324
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ErrorLine, { error: problems })
|
|
1313
1325
|
] });
|
|
1314
1326
|
};
|
|
1327
|
+
var AddImage = ({ label, onFile }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: `${button} cursor-pointer self-start`, children: [
|
|
1328
|
+
label,
|
|
1329
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1330
|
+
"input",
|
|
1331
|
+
{
|
|
1332
|
+
type: "file",
|
|
1333
|
+
accept: "image/*",
|
|
1334
|
+
"aria-label": label,
|
|
1335
|
+
className: "sr-only",
|
|
1336
|
+
onChange: (e) => {
|
|
1337
|
+
const file = e.target.files?.[0];
|
|
1338
|
+
e.target.value = "";
|
|
1339
|
+
if (file) onFile(file);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
)
|
|
1343
|
+
] });
|
|
1315
1344
|
var EditorControl = ({ control: c, onSet }) => {
|
|
1316
1345
|
const note = c.note ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-[10px] text-amber-400", children: c.note }) : null;
|
|
1317
1346
|
switch (c.kind) {
|
|
@@ -1389,6 +1418,17 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
1389
1418
|
const [draft, setDraft] = (0, import_react10.useState)(null);
|
|
1390
1419
|
const [status, setStatus] = (0, import_react10.useState)(null);
|
|
1391
1420
|
const [preview, setPreview] = (0, import_react10.useState)(null);
|
|
1421
|
+
const [sources, setSources] = (0, import_react10.useState)([]);
|
|
1422
|
+
(0, import_react10.useEffect)(() => {
|
|
1423
|
+
let live = true;
|
|
1424
|
+
const read = () => void library.listSources().then((list) => live && setSources(list), () => void 0);
|
|
1425
|
+
read();
|
|
1426
|
+
const off = library.subscribe(read);
|
|
1427
|
+
return () => {
|
|
1428
|
+
live = false;
|
|
1429
|
+
off();
|
|
1430
|
+
};
|
|
1431
|
+
}, [library]);
|
|
1392
1432
|
(0, import_react10.useEffect)(() => {
|
|
1393
1433
|
let live = true;
|
|
1394
1434
|
setStatus(null);
|
|
@@ -1460,7 +1500,9 @@ var BrushLibraryEditor = ({ library, brushId, profile, renderPreview, previewPap
|
|
|
1460
1500
|
},
|
|
1461
1501
|
onSave: original ? () => save() : void 0,
|
|
1462
1502
|
saveLabel: builtin ? "Save a copy" : "Save",
|
|
1463
|
-
onSaveAs: (name) => save(name)
|
|
1503
|
+
onSaveAs: (name) => save(name),
|
|
1504
|
+
sources,
|
|
1505
|
+
onAddSource: async (file) => (await (0, import_brushes3.addBrushSourceFromFile)(library, file)).ref
|
|
1464
1506
|
}
|
|
1465
1507
|
),
|
|
1466
1508
|
errors.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { className: "text-[11px] text-rose-400", "data-testid": "brush-library-editor-issues", children: errors.map((i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("li", { children: [
|
package/dist/vector/index.js
CHANGED
|
@@ -15,10 +15,10 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
BrushLibraryEditor,
|
|
17
17
|
useBrushLibrary
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-2QXGKOVK.js";
|
|
19
19
|
import {
|
|
20
20
|
BrushLibraryBrowser
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-GUBRH2OO.js";
|
|
22
22
|
|
|
23
23
|
// src/vector/useVectorEditor.ts
|
|
24
24
|
import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.183.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.268.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.268.0"
|
|
332
332
|
},
|
|
333
333
|
"scripts": {
|
|
334
334
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|