@pixerate/editor-react 0.172.1 → 0.173.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}/BrushLibraryBrowser.d.cts +2 -2
- package/dist/{paint-editor → brushes}/BrushLibraryBrowser.d.ts +2 -2
- package/dist/brushes/index.cjs +102 -0
- package/dist/brushes/index.d.cts +2 -0
- package/dist/brushes/index.d.ts +2 -0
- package/dist/brushes/index.js +10 -0
- package/dist/brushes/useBrushLibrary.d.cts +7 -0
- package/dist/brushes/useBrushLibrary.d.ts +7 -0
- package/dist/canvas/index.cjs +7 -2
- package/dist/canvas/index.js +7 -2
- package/dist/canvas/useCanvasDraw.d.cts +4 -2
- package/dist/canvas/useCanvasDraw.d.ts +4 -2
- package/dist/canvas/useShapeBrushstroke.d.cts +6 -2
- package/dist/canvas/useShapeBrushstroke.d.ts +6 -2
- package/dist/chunk-62FMEDGG.js +54 -0
- package/dist/chunk-PQK2UMAY.js +23 -0
- package/dist/{chunk-NQ22NA7S.js → chunk-UR4KL7WE.js} +28 -0
- package/dist/image-editor/BrushOptionsBar.d.cts +2 -1
- package/dist/image-editor/BrushOptionsBar.d.ts +2 -1
- package/dist/image-editor/index.cjs +964 -869
- package/dist/image-editor/index.js +3 -1
- package/dist/index.cjs +1484 -1389
- package/dist/index.js +12 -10
- package/dist/paint-editor/index.cjs +17 -2
- package/dist/paint-editor/index.d.cts +1 -1
- package/dist/paint-editor/index.d.ts +1 -1
- package/dist/paint-editor/index.js +325 -358
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.js +3 -4
- package/package.json +16 -3
|
@@ -13,8 +13,8 @@ export interface BrushLibraryBrowserProps {
|
|
|
13
13
|
onSelect: (id: string) => void;
|
|
14
14
|
/** Only brushes this host renders. */
|
|
15
15
|
profile?: BrushHostProfile;
|
|
16
|
-
/** A thumbnail for a brush (a test stroke). */
|
|
17
|
-
thumbnail?: (id: string) => Pixels | null;
|
|
16
|
+
/** A thumbnail for a brush (a test stroke): pixels, or an image URL. */
|
|
17
|
+
thumbnail?: (id: string) => Pixels | string | null | undefined;
|
|
18
18
|
thumbnailWidth?: number;
|
|
19
19
|
thumbnailHeight?: number;
|
|
20
20
|
className?: string;
|
|
@@ -13,8 +13,8 @@ export interface BrushLibraryBrowserProps {
|
|
|
13
13
|
onSelect: (id: string) => void;
|
|
14
14
|
/** Only brushes this host renders. */
|
|
15
15
|
profile?: BrushHostProfile;
|
|
16
|
-
/** A thumbnail for a brush (a test stroke). */
|
|
17
|
-
thumbnail?: (id: string) => Pixels | null;
|
|
16
|
+
/** A thumbnail for a brush (a test stroke): pixels, or an image URL. */
|
|
17
|
+
thumbnail?: (id: string) => Pixels | string | null | undefined;
|
|
18
18
|
thumbnailWidth?: number;
|
|
19
19
|
thumbnailHeight?: number;
|
|
20
20
|
className?: string;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/brushes/index.ts
|
|
21
|
+
var brushes_exports = {};
|
|
22
|
+
__export(brushes_exports, {
|
|
23
|
+
BrushLibraryBrowser: () => BrushLibraryBrowser,
|
|
24
|
+
useBrushLibrary: () => useBrushLibrary
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(brushes_exports);
|
|
27
|
+
|
|
28
|
+
// src/brushes/BrushLibraryBrowser.tsx
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var import_brushes = require("@pixerate/editor/brushes");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var Thumbnail = ({ image, label, style }) => {
|
|
33
|
+
const ref = (0, import_react.useRef)(null);
|
|
34
|
+
(0, import_react.useEffect)(() => {
|
|
35
|
+
const canvas = ref.current;
|
|
36
|
+
const ctx = canvas?.getContext("2d");
|
|
37
|
+
if (!canvas || !ctx || !image || typeof image === "string" || typeof ctx.createImageData !== "function") return;
|
|
38
|
+
canvas.width = image.width;
|
|
39
|
+
canvas.height = image.height;
|
|
40
|
+
const img = ctx.createImageData(image.width, image.height);
|
|
41
|
+
img.data.set(image.data);
|
|
42
|
+
ctx.putImageData(img, 0, 0);
|
|
43
|
+
}, [image]);
|
|
44
|
+
if (typeof image === "string") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: image, alt: label, className: "rounded object-contain", style });
|
|
45
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("canvas", { ref, role: "img", "aria-label": label, className: "rounded", style, width: image?.width, height: image?.height });
|
|
46
|
+
};
|
|
47
|
+
var BrushLibraryBrowser = ({ entries, activeId, onSelect, profile, thumbnail, thumbnailWidth = 112, thumbnailHeight = 32, className }) => {
|
|
48
|
+
const [text, setText] = (0, import_react.useState)("");
|
|
49
|
+
const groups = (0, import_react.useMemo)(() => (0, import_brushes.brushLibraryGroups)(entries, { text, profile }), [entries, text, profile]);
|
|
50
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `flex flex-col gap-1 ${className ?? ""}`, "data-testid": "brush-library", children: [
|
|
51
|
+
/* @__PURE__ */ (0, import_jsx_runtime.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" }),
|
|
52
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-1.5", role: "listbox", "aria-label": "Brushes", children: [
|
|
53
|
+
groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { role: "group", "aria-label": g.title, className: "flex flex-col gap-0.5", children: [
|
|
54
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-[10px] uppercase tracking-wide text-slate-500", children: g.title }),
|
|
55
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "grid grid-cols-2 gap-1", children: g.varieties.flatMap(
|
|
56
|
+
(v) => v.entries.map((e) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
57
|
+
"button",
|
|
58
|
+
{
|
|
59
|
+
type: "button",
|
|
60
|
+
role: "option",
|
|
61
|
+
"aria-selected": activeId === e.brush.id,
|
|
62
|
+
title: [e.brush.name, v.title.toLowerCase() === e.brush.name.toLowerCase() ? "" : v.title, e.builtin ? "" : "saved"].filter(Boolean).join(" \xB7 "),
|
|
63
|
+
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
|
+
onClick: () => onSelect(e.brush.id),
|
|
65
|
+
children: [
|
|
66
|
+
thumbnail && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Thumbnail, { image: thumbnail(e.brush.id) ?? null, label: `${e.brush.name} thumbnail`, style: { width: "100%", aspectRatio: `${thumbnailWidth} / ${thumbnailHeight}` } }),
|
|
67
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "truncate text-[10px] text-slate-300", children: e.brush.name })
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
e.brush.id
|
|
71
|
+
))
|
|
72
|
+
) })
|
|
73
|
+
] }, g.id)),
|
|
74
|
+
!groups.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-slate-500", children: "No brush matches." })
|
|
75
|
+
] })
|
|
76
|
+
] });
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/brushes/useBrushLibrary.ts
|
|
80
|
+
var import_react2 = require("react");
|
|
81
|
+
function useBrushLibrary(library, filter = {}) {
|
|
82
|
+
const [entries, setEntries] = (0, import_react2.useState)([]);
|
|
83
|
+
const { profile, ...rest } = filter;
|
|
84
|
+
const key = `${profile?.id ?? ""}:${JSON.stringify(rest)}`;
|
|
85
|
+
(0, import_react2.useEffect)(() => {
|
|
86
|
+
if (!library) return;
|
|
87
|
+
let live = true;
|
|
88
|
+
const read = () => void library.list(filter).then((list) => live && setEntries(list), () => void 0);
|
|
89
|
+
read();
|
|
90
|
+
const unsubscribe = library.subscribe(read);
|
|
91
|
+
return () => {
|
|
92
|
+
live = false;
|
|
93
|
+
unsubscribe();
|
|
94
|
+
};
|
|
95
|
+
}, [library, key]);
|
|
96
|
+
return entries;
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
BrushLibraryBrowser,
|
|
101
|
+
useBrushLibrary
|
|
102
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BrushFilter, BrushLibrary, BrushLibraryEntry } from '@pixerate/editor/brushes';
|
|
2
|
+
/**
|
|
3
|
+
* The brushes of a brush library (`filter`: e.g. `{ profile: CANVAS_PROFILE }` for what a host can
|
|
4
|
+
* paint), read again after every change to the library: a brush saved in another editor sharing
|
|
5
|
+
* it shows up. Empty until the first read.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useBrushLibrary(library: Pick<BrushLibrary, 'list' | 'subscribe'> | null | undefined, filter?: BrushFilter): BrushLibraryEntry[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BrushFilter, BrushLibrary, BrushLibraryEntry } from '@pixerate/editor/brushes';
|
|
2
|
+
/**
|
|
3
|
+
* The brushes of a brush library (`filter`: e.g. `{ profile: CANVAS_PROFILE }` for what a host can
|
|
4
|
+
* paint), read again after every change to the library: a brush saved in another editor sharing
|
|
5
|
+
* it shows up. Empty until the first read.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useBrushLibrary(library: Pick<BrushLibrary, 'list' | 'subscribe'> | null | undefined, filter?: BrushFilter): BrushLibraryEntry[];
|
package/dist/canvas/index.cjs
CHANGED
|
@@ -1672,6 +1672,7 @@ function useCanvasDraw(options) {
|
|
|
1672
1672
|
style: options.initialStyle,
|
|
1673
1673
|
drawOptions: options.drawOptions,
|
|
1674
1674
|
generateNodeId: options.generateNodeId,
|
|
1675
|
+
brushLibrary: options.brushLibrary,
|
|
1675
1676
|
onToolChange: setToolState,
|
|
1676
1677
|
onStyleChange: (s) => setStyleState(s),
|
|
1677
1678
|
onActiveStrokeChange: setActiveStroke,
|
|
@@ -1964,17 +1965,21 @@ function useShapeBrushstroke(shape, width, height, position) {
|
|
|
1964
1965
|
function useCanvasBrushes(options = {}) {
|
|
1965
1966
|
const [state, setState] = (0, import_react20.useState)({ brushes: [], loading: true, error: null });
|
|
1966
1967
|
const swatches = options.swatches ? JSON.stringify(options.swatches) : "";
|
|
1968
|
+
const library = options.library ?? null;
|
|
1967
1969
|
(0, import_react20.useEffect)(() => {
|
|
1968
1970
|
let live = true;
|
|
1969
1971
|
const opts = swatches ? JSON.parse(swatches) : null;
|
|
1970
|
-
(0, import_canvas15.listCanvasBrushes)().then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await (0, import_canvas15.renderCanvasBrushSwatch)(b.id, opts) }))) : list).then(
|
|
1972
|
+
const read = () => (0, import_canvas15.listCanvasBrushes)(library ?? void 0).then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await (0, import_canvas15.renderCanvasBrushSwatch)(b.id, opts, b.spec) }))) : list).then(
|
|
1971
1973
|
(brushes) => live && setState({ brushes, loading: false, error: null }),
|
|
1972
1974
|
(error) => live && setState({ brushes: [], loading: false, error: error instanceof Error ? error.message : String(error) })
|
|
1973
1975
|
);
|
|
1976
|
+
void read();
|
|
1977
|
+
const unsubscribe = library?.subscribe(() => void read());
|
|
1974
1978
|
return () => {
|
|
1975
1979
|
live = false;
|
|
1980
|
+
unsubscribe?.();
|
|
1976
1981
|
};
|
|
1977
|
-
}, [swatches]);
|
|
1982
|
+
}, [swatches, library]);
|
|
1978
1983
|
return (0, import_react20.useMemo)(() => state, [state]);
|
|
1979
1984
|
}
|
|
1980
1985
|
|
package/dist/canvas/index.js
CHANGED
|
@@ -1213,6 +1213,7 @@ function useCanvasDraw(options) {
|
|
|
1213
1213
|
style: options.initialStyle,
|
|
1214
1214
|
drawOptions: options.drawOptions,
|
|
1215
1215
|
generateNodeId: options.generateNodeId,
|
|
1216
|
+
brushLibrary: options.brushLibrary,
|
|
1216
1217
|
onToolChange: setToolState,
|
|
1217
1218
|
onStyleChange: (s) => setStyleState(s),
|
|
1218
1219
|
onActiveStrokeChange: setActiveStroke,
|
|
@@ -1573,17 +1574,21 @@ function useShapeBrushstroke(shape, width, height, position) {
|
|
|
1573
1574
|
function useCanvasBrushes(options = {}) {
|
|
1574
1575
|
const [state, setState] = useState7({ brushes: [], loading: true, error: null });
|
|
1575
1576
|
const swatches = options.swatches ? JSON.stringify(options.swatches) : "";
|
|
1577
|
+
const library = options.library ?? null;
|
|
1576
1578
|
useEffect10(() => {
|
|
1577
1579
|
let live = true;
|
|
1578
1580
|
const opts = swatches ? JSON.parse(swatches) : null;
|
|
1579
|
-
listCanvasBrushes().then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await renderCanvasBrushSwatch(b.id, opts) }))) : list).then(
|
|
1581
|
+
const read = () => listCanvasBrushes(library ?? void 0).then(async (list) => opts ? Promise.all(list.map(async (b) => ({ ...b, swatch: await renderCanvasBrushSwatch(b.id, opts, b.spec) }))) : list).then(
|
|
1580
1582
|
(brushes) => live && setState({ brushes, loading: false, error: null }),
|
|
1581
1583
|
(error) => live && setState({ brushes: [], loading: false, error: error instanceof Error ? error.message : String(error) })
|
|
1582
1584
|
);
|
|
1585
|
+
void read();
|
|
1586
|
+
const unsubscribe = library?.subscribe(() => void read());
|
|
1583
1587
|
return () => {
|
|
1584
1588
|
live = false;
|
|
1589
|
+
unsubscribe?.();
|
|
1585
1590
|
};
|
|
1586
|
-
}, [swatches]);
|
|
1591
|
+
}, [swatches, library]);
|
|
1587
1592
|
return useMemo9(() => state, [state]);
|
|
1588
1593
|
}
|
|
1589
1594
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ArrangeHistoryTarget, type CanvasBrushPreset, type CanvasNode, type DrawStrokeInput, type DrawStrokeResult, type FreehandDrawOptions, type FreehandPenSample, type FreehandStroke, type FreehandStrokeStyle, type FreehandTool } from '@pixerate/editor/canvas';
|
|
1
|
+
import { type CanvasDrawControllerOptions, type ArrangeHistoryTarget, type CanvasBrushPreset, type CanvasNode, type DrawStrokeInput, type DrawStrokeResult, type FreehandDrawOptions, type FreehandPenSample, type FreehandStroke, type FreehandStrokeStyle, type FreehandTool } from '@pixerate/editor/canvas';
|
|
2
2
|
export interface UseCanvasDrawOptions<TNode extends CanvasNode = CanvasNode> {
|
|
3
3
|
nodes: TNode[];
|
|
4
4
|
setNodes: (updater: TNode[] | ((prev: TNode[]) => TNode[])) => void;
|
|
@@ -7,6 +7,8 @@ export interface UseCanvasDrawOptions<TNode extends CanvasNode = CanvasNode> {
|
|
|
7
7
|
initialStyle?: Partial<FreehandStrokeStyle>;
|
|
8
8
|
drawOptions?: FreehandDrawOptions;
|
|
9
9
|
generateNodeId?: () => string;
|
|
10
|
+
/** The brush library whose saved brushes strokes may use besides the presets (the canvas profile decides which); read once, on mount. */
|
|
11
|
+
brushLibrary?: CanvasDrawControllerOptions<TNode>['brushLibrary'];
|
|
10
12
|
onStrokeComplete?: (node: TNode) => void;
|
|
11
13
|
onNodesErase?: (erasedNodes: TNode[]) => void;
|
|
12
14
|
}
|
|
@@ -34,7 +36,7 @@ export interface CanvasDrawActions<TNode extends CanvasNode = CanvasNode> {
|
|
|
34
36
|
width: number;
|
|
35
37
|
height: number;
|
|
36
38
|
} | undefined;
|
|
37
|
-
/** The
|
|
39
|
+
/** The presets and saved brushes `style.brush` accepts (loads the paint engine). */
|
|
38
40
|
listBrushes: () => Promise<CanvasBrushPreset[]>;
|
|
39
41
|
}
|
|
40
42
|
export type CanvasDraw<TNode extends CanvasNode = CanvasNode> = CanvasDrawState & CanvasDrawActions<TNode>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ArrangeHistoryTarget, type CanvasBrushPreset, type CanvasNode, type DrawStrokeInput, type DrawStrokeResult, type FreehandDrawOptions, type FreehandPenSample, type FreehandStroke, type FreehandStrokeStyle, type FreehandTool } from '@pixerate/editor/canvas';
|
|
1
|
+
import { type CanvasDrawControllerOptions, type ArrangeHistoryTarget, type CanvasBrushPreset, type CanvasNode, type DrawStrokeInput, type DrawStrokeResult, type FreehandDrawOptions, type FreehandPenSample, type FreehandStroke, type FreehandStrokeStyle, type FreehandTool } from '@pixerate/editor/canvas';
|
|
2
2
|
export interface UseCanvasDrawOptions<TNode extends CanvasNode = CanvasNode> {
|
|
3
3
|
nodes: TNode[];
|
|
4
4
|
setNodes: (updater: TNode[] | ((prev: TNode[]) => TNode[])) => void;
|
|
@@ -7,6 +7,8 @@ export interface UseCanvasDrawOptions<TNode extends CanvasNode = CanvasNode> {
|
|
|
7
7
|
initialStyle?: Partial<FreehandStrokeStyle>;
|
|
8
8
|
drawOptions?: FreehandDrawOptions;
|
|
9
9
|
generateNodeId?: () => string;
|
|
10
|
+
/** The brush library whose saved brushes strokes may use besides the presets (the canvas profile decides which); read once, on mount. */
|
|
11
|
+
brushLibrary?: CanvasDrawControllerOptions<TNode>['brushLibrary'];
|
|
10
12
|
onStrokeComplete?: (node: TNode) => void;
|
|
11
13
|
onNodesErase?: (erasedNodes: TNode[]) => void;
|
|
12
14
|
}
|
|
@@ -34,7 +36,7 @@ export interface CanvasDrawActions<TNode extends CanvasNode = CanvasNode> {
|
|
|
34
36
|
width: number;
|
|
35
37
|
height: number;
|
|
36
38
|
} | undefined;
|
|
37
|
-
/** The
|
|
39
|
+
/** The presets and saved brushes `style.brush` accepts (loads the paint engine). */
|
|
38
40
|
listBrushes: () => Promise<CanvasBrushPreset[]>;
|
|
39
41
|
}
|
|
40
42
|
export type CanvasDraw<TNode extends CanvasNode = CanvasNode> = CanvasDrawState & CanvasDrawActions<TNode>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type CanvasBrushSwatchOptions, type CanvasBrushPreset, type CanvasBrushstrokeImage, type ShapeDescription } from '@pixerate/editor/canvas';
|
|
3
|
+
import type { BrushLibrary } from '@pixerate/editor/brushes';
|
|
3
4
|
/** The canvas zoom bucket brushed shape nodes render at (1 without a provider). */
|
|
4
5
|
export declare const ShapeNodeZoomContext: React.Context<number>;
|
|
5
6
|
/**
|
|
@@ -23,11 +24,14 @@ export declare function useShapeBrushstroke(shape: ShapeDescription | null | und
|
|
|
23
24
|
y: number;
|
|
24
25
|
}): CanvasBrushstrokeImage | null;
|
|
25
26
|
/**
|
|
26
|
-
* The
|
|
27
|
-
* with `
|
|
27
|
+
* The brushes a freehand stroke can be brushed with (loads the paint engine on mount): the dry
|
|
28
|
+
* presets and, with `library`, its saved brushes the canvas can paint (each with its `spec`; pass
|
|
29
|
+
* it as the stroke style's `brushSpec`), read again when the library changes. With `swatches`,
|
|
30
|
+
* each has a preview image (`renderCanvasBrushSwatch`) for a brush menu.
|
|
28
31
|
*/
|
|
29
32
|
export declare function useCanvasBrushes(options?: {
|
|
30
33
|
swatches?: CanvasBrushSwatchOptions;
|
|
34
|
+
library?: Pick<BrushLibrary, 'list' | 'subscribe'> | null;
|
|
31
35
|
}): {
|
|
32
36
|
brushes: Array<CanvasBrushPreset & {
|
|
33
37
|
swatch?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type CanvasBrushSwatchOptions, type CanvasBrushPreset, type CanvasBrushstrokeImage, type ShapeDescription } from '@pixerate/editor/canvas';
|
|
3
|
+
import type { BrushLibrary } from '@pixerate/editor/brushes';
|
|
3
4
|
/** The canvas zoom bucket brushed shape nodes render at (1 without a provider). */
|
|
4
5
|
export declare const ShapeNodeZoomContext: React.Context<number>;
|
|
5
6
|
/**
|
|
@@ -23,11 +24,14 @@ export declare function useShapeBrushstroke(shape: ShapeDescription | null | und
|
|
|
23
24
|
y: number;
|
|
24
25
|
}): CanvasBrushstrokeImage | null;
|
|
25
26
|
/**
|
|
26
|
-
* The
|
|
27
|
-
* with `
|
|
27
|
+
* The brushes a freehand stroke can be brushed with (loads the paint engine on mount): the dry
|
|
28
|
+
* presets and, with `library`, its saved brushes the canvas can paint (each with its `spec`; pass
|
|
29
|
+
* it as the stroke style's `brushSpec`), read again when the library changes. With `swatches`,
|
|
30
|
+
* each has a preview image (`renderCanvasBrushSwatch`) for a brush menu.
|
|
28
31
|
*/
|
|
29
32
|
export declare function useCanvasBrushes(options?: {
|
|
30
33
|
swatches?: CanvasBrushSwatchOptions;
|
|
34
|
+
library?: Pick<BrushLibrary, 'list' | 'subscribe'> | null;
|
|
31
35
|
}): {
|
|
32
36
|
brushes: Array<CanvasBrushPreset & {
|
|
33
37
|
swatch?: string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/brushes/BrushLibraryBrowser.tsx
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { brushLibraryGroups } from "@pixerate/editor/brushes";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
var Thumbnail = ({ image, label, style }) => {
|
|
6
|
+
const ref = useRef(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const canvas = ref.current;
|
|
9
|
+
const ctx = canvas?.getContext("2d");
|
|
10
|
+
if (!canvas || !ctx || !image || typeof image === "string" || typeof ctx.createImageData !== "function") return;
|
|
11
|
+
canvas.width = image.width;
|
|
12
|
+
canvas.height = image.height;
|
|
13
|
+
const img = ctx.createImageData(image.width, image.height);
|
|
14
|
+
img.data.set(image.data);
|
|
15
|
+
ctx.putImageData(img, 0, 0);
|
|
16
|
+
}, [image]);
|
|
17
|
+
if (typeof image === "string") return /* @__PURE__ */ jsx("img", { src: image, alt: label, className: "rounded object-contain", style });
|
|
18
|
+
return /* @__PURE__ */ jsx("canvas", { ref, role: "img", "aria-label": label, className: "rounded", style, width: image?.width, height: image?.height });
|
|
19
|
+
};
|
|
20
|
+
var BrushLibraryBrowser = ({ entries, activeId, onSelect, profile, thumbnail, thumbnailWidth = 112, thumbnailHeight = 32, className }) => {
|
|
21
|
+
const [text, setText] = useState("");
|
|
22
|
+
const groups = useMemo(() => brushLibraryGroups(entries, { text, profile }), [entries, text, profile]);
|
|
23
|
+
return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-1 ${className ?? ""}`, "data-testid": "brush-library", children: [
|
|
24
|
+
/* @__PURE__ */ 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" }),
|
|
25
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", role: "listbox", "aria-label": "Brushes", children: [
|
|
26
|
+
groups.map((g) => /* @__PURE__ */ jsxs("div", { role: "group", "aria-label": g.title, className: "flex flex-col gap-0.5", children: [
|
|
27
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] uppercase tracking-wide text-slate-500", children: g.title }),
|
|
28
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-1", children: g.varieties.flatMap(
|
|
29
|
+
(v) => v.entries.map((e) => /* @__PURE__ */ jsxs(
|
|
30
|
+
"button",
|
|
31
|
+
{
|
|
32
|
+
type: "button",
|
|
33
|
+
role: "option",
|
|
34
|
+
"aria-selected": activeId === e.brush.id,
|
|
35
|
+
title: [e.brush.name, v.title.toLowerCase() === e.brush.name.toLowerCase() ? "" : v.title, e.builtin ? "" : "saved"].filter(Boolean).join(" \xB7 "),
|
|
36
|
+
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"}`,
|
|
37
|
+
onClick: () => onSelect(e.brush.id),
|
|
38
|
+
children: [
|
|
39
|
+
thumbnail && /* @__PURE__ */ jsx(Thumbnail, { image: thumbnail(e.brush.id) ?? null, label: `${e.brush.name} thumbnail`, style: { width: "100%", aspectRatio: `${thumbnailWidth} / ${thumbnailHeight}` } }),
|
|
40
|
+
/* @__PURE__ */ jsx("span", { className: "truncate text-[10px] text-slate-300", children: e.brush.name })
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
e.brush.id
|
|
44
|
+
))
|
|
45
|
+
) })
|
|
46
|
+
] }, g.id)),
|
|
47
|
+
!groups.length && /* @__PURE__ */ jsx("span", { className: "text-slate-500", children: "No brush matches." })
|
|
48
|
+
] })
|
|
49
|
+
] });
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
BrushLibraryBrowser
|
|
54
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/brushes/useBrushLibrary.ts
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
function useBrushLibrary(library, filter = {}) {
|
|
4
|
+
const [entries, setEntries] = useState([]);
|
|
5
|
+
const { profile, ...rest } = filter;
|
|
6
|
+
const key = `${profile?.id ?? ""}:${JSON.stringify(rest)}`;
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!library) return;
|
|
9
|
+
let live = true;
|
|
10
|
+
const read = () => void library.list(filter).then((list) => live && setEntries(list), () => void 0);
|
|
11
|
+
read();
|
|
12
|
+
const unsubscribe = library.subscribe(read);
|
|
13
|
+
return () => {
|
|
14
|
+
live = false;
|
|
15
|
+
unsubscribe();
|
|
16
|
+
};
|
|
17
|
+
}, [library, key]);
|
|
18
|
+
return entries;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
useBrushLibrary
|
|
23
|
+
};
|
|
@@ -41,6 +41,12 @@ import {
|
|
|
41
41
|
useAgentPlayback,
|
|
42
42
|
usePlaybackSurface
|
|
43
43
|
} from "./chunk-W5CMGX3I.js";
|
|
44
|
+
import {
|
|
45
|
+
useBrushLibrary
|
|
46
|
+
} from "./chunk-PQK2UMAY.js";
|
|
47
|
+
import {
|
|
48
|
+
BrushLibraryBrowser
|
|
49
|
+
} from "./chunk-62FMEDGG.js";
|
|
44
50
|
|
|
45
51
|
// src/image-editor/useImageEditor.ts
|
|
46
52
|
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
@@ -2412,6 +2418,7 @@ import { jsx as jsx12 } from "react/jsx-runtime";
|
|
|
2412
2418
|
var PaintGradientEditor = (props) => /* @__PURE__ */ jsx12(PaintGradientEditorView, { ...props, kit: PAINT_GRADIENT_KIT });
|
|
2413
2419
|
|
|
2414
2420
|
// src/image-editor/BrushOptionsBar.tsx
|
|
2421
|
+
import { IMAGE_PROFILE } from "@pixerate/editor/brushes";
|
|
2415
2422
|
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2416
2423
|
var BrushOptionsBar = ({ controller, showTools = true, className }) => {
|
|
2417
2424
|
const [, setTick] = useState10(0);
|
|
@@ -2420,6 +2427,9 @@ var BrushOptionsBar = ({ controller, showTools = true, className }) => {
|
|
|
2420
2427
|
const state = controller.getState();
|
|
2421
2428
|
const { brush, foreground, background, mixer, mixerLoad, retouch, cloneSource, paint } = state.paint;
|
|
2422
2429
|
const tool = state.activeTool;
|
|
2430
|
+
const [presetsOpen, setPresetsOpen] = useState10(false);
|
|
2431
|
+
const presets = useBrushLibrary(presetsOpen ? controller.brushLibrary : null, { profile: IMAGE_PROFILE });
|
|
2432
|
+
const presetName = presets.find((e) => e.brush.id === state.paint.brushPreset)?.brush.name ?? state.paint.brushPreset;
|
|
2423
2433
|
const attempt = (fn) => {
|
|
2424
2434
|
try {
|
|
2425
2435
|
setError(null);
|
|
@@ -2441,6 +2451,24 @@ var BrushOptionsBar = ({ controller, showTools = true, className }) => {
|
|
|
2441
2451
|
},
|
|
2442
2452
|
t.id
|
|
2443
2453
|
)) }),
|
|
2454
|
+
(tool === "brush" || tool === "mixer" || tool === "eraser") && /* @__PURE__ */ jsxs11("div", { className: "flex flex-col gap-1", "data-testid": "brush-presets", children: [
|
|
2455
|
+
/* @__PURE__ */ jsxs11("button", { type: "button", "aria-expanded": presetsOpen, className: imageChipClass(presetsOpen), onClick: () => setPresetsOpen((o) => !o), title: "Paint with a brush from the brush library", children: [
|
|
2456
|
+
"Brush presets",
|
|
2457
|
+
presetName ? `: ${presetName}` : ""
|
|
2458
|
+
] }),
|
|
2459
|
+
presetsOpen && /* @__PURE__ */ jsx13(
|
|
2460
|
+
BrushLibraryBrowser,
|
|
2461
|
+
{
|
|
2462
|
+
entries: presets,
|
|
2463
|
+
activeId: state.paint.brushPreset ?? void 0,
|
|
2464
|
+
profile: IMAGE_PROFILE,
|
|
2465
|
+
onSelect: (id) => {
|
|
2466
|
+
setError(null);
|
|
2467
|
+
controller.setBrushPreset(id).catch((err) => setError(userErrorMessage(err)));
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
)
|
|
2471
|
+
] }),
|
|
2444
2472
|
/* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2", role: "group", "aria-label": "Colours", children: [
|
|
2445
2473
|
/* @__PURE__ */ jsxs11("label", { className: "flex items-center gap-1", children: [
|
|
2446
2474
|
/* @__PURE__ */ jsx13(ImageColor, { label: "Foreground colour", value: foreground, onChange: (fg) => controller.setPaintOptions({ foreground: fg }) }),
|
|
@@ -7,7 +7,8 @@ export interface BrushOptionsBarProps {
|
|
|
7
7
|
className?: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* The paint tools: Move / Brush / Mixer / Eraser, the
|
|
10
|
+
* The paint tools: Move / Brush / Mixer / Eraser, brush presets from the editor's brush library
|
|
11
|
+
* (`BrushLibraryBrowser` with `IMAGE_PROFILE`: choosing one sets the tool and brush), the brush's size, hardness, opacity, flow and
|
|
11
12
|
* smoothing, pressure toggles, the foreground and background colours (D resets, X swaps) and
|
|
12
13
|
* Edit › Fill / Clear on the active layer, and gradient paint for the brush (the colour changes as
|
|
13
14
|
* the stroke goes; `PaintGradientEditor`). With the Mixer Brush: its load (Load brush / Clean
|
|
@@ -7,7 +7,8 @@ export interface BrushOptionsBarProps {
|
|
|
7
7
|
className?: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* The paint tools: Move / Brush / Mixer / Eraser, the
|
|
10
|
+
* The paint tools: Move / Brush / Mixer / Eraser, brush presets from the editor's brush library
|
|
11
|
+
* (`BrushLibraryBrowser` with `IMAGE_PROFILE`: choosing one sets the tool and brush), the brush's size, hardness, opacity, flow and
|
|
11
12
|
* smoothing, pressure toggles, the foreground and background colours (D resets, X swaps) and
|
|
12
13
|
* Edit › Fill / Clear on the active layer, and gradient paint for the brush (the colour changes as
|
|
13
14
|
* the stroke goes; `PaintGradientEditor`). With the Mixer Brush: its load (Load brush / Clean
|