@pixerate/editor-react 0.172.1 → 0.174.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.
Files changed (36) hide show
  1. package/dist/{paint-editor → brushes}/BrushLibraryBrowser.d.cts +2 -2
  2. package/dist/{paint-editor → brushes}/BrushLibraryBrowser.d.ts +2 -2
  3. package/dist/brushes/index.cjs +102 -0
  4. package/dist/brushes/index.d.cts +2 -0
  5. package/dist/brushes/index.d.ts +2 -0
  6. package/dist/brushes/index.js +10 -0
  7. package/dist/brushes/useBrushLibrary.d.cts +7 -0
  8. package/dist/brushes/useBrushLibrary.d.ts +7 -0
  9. package/dist/canvas/index.cjs +7 -2
  10. package/dist/canvas/index.js +7 -2
  11. package/dist/canvas/useCanvasDraw.d.cts +4 -2
  12. package/dist/canvas/useCanvasDraw.d.ts +4 -2
  13. package/dist/canvas/useShapeBrushstroke.d.cts +6 -2
  14. package/dist/canvas/useShapeBrushstroke.d.ts +6 -2
  15. package/dist/chunk-62FMEDGG.js +54 -0
  16. package/dist/chunk-PQK2UMAY.js +23 -0
  17. package/dist/{chunk-NQ22NA7S.js → chunk-UR4KL7WE.js} +28 -0
  18. package/dist/image-editor/BrushOptionsBar.d.cts +2 -1
  19. package/dist/image-editor/BrushOptionsBar.d.ts +2 -1
  20. package/dist/image-editor/index.cjs +964 -869
  21. package/dist/image-editor/index.js +3 -1
  22. package/dist/index.cjs +1484 -1389
  23. package/dist/index.js +12 -10
  24. package/dist/paint-editor/PaintCanvas.d.cts +9 -1
  25. package/dist/paint-editor/PaintCanvas.d.ts +9 -1
  26. package/dist/paint-editor/PaintEditor.d.cts +3 -1
  27. package/dist/paint-editor/PaintEditor.d.ts +3 -1
  28. package/dist/paint-editor/index.cjs +77 -7
  29. package/dist/paint-editor/index.d.cts +1 -1
  30. package/dist/paint-editor/index.d.ts +1 -1
  31. package/dist/paint-editor/index.js +416 -389
  32. package/dist/paint-editor/usePaintEditor.d.cts +30 -1
  33. package/dist/paint-editor/usePaintEditor.d.ts +30 -1
  34. package/dist/vector/index.cjs +2 -2
  35. package/dist/vector/index.js +3 -4
  36. package/package.json +16 -3
package/dist/index.js CHANGED
@@ -1,3 +1,12 @@
1
+ import {
2
+ AssetMentionChips,
3
+ GenerationHistory,
4
+ GenerationSettings,
5
+ JobProgress,
6
+ useGenerationPlan,
7
+ useGenerationRecords,
8
+ useJobProgress
9
+ } from "./chunk-FLS7Q32M.js";
1
10
  import {
2
11
  useElementPlaybackSurface
3
12
  } from "./chunk-6CJEJTQB.js";
@@ -53,7 +62,7 @@ import {
53
62
  useImageEditor,
54
63
  useImageEffectsTools,
55
64
  useImageHistogram
56
- } from "./chunk-NQ22NA7S.js";
65
+ } from "./chunk-UR4KL7WE.js";
57
66
  import {
58
67
  ImageCheckbox,
59
68
  ImageColor,
@@ -73,6 +82,8 @@ import {
73
82
  useAgentPlayback,
74
83
  usePlaybackSurface
75
84
  } from "./chunk-W5CMGX3I.js";
85
+ import "./chunk-PQK2UMAY.js";
86
+ import "./chunk-62FMEDGG.js";
76
87
  import {
77
88
  CommandPalette,
78
89
  useCommandPalette,
@@ -84,15 +95,6 @@ import {
84
95
  useAutosave,
85
96
  useEditorAutosave
86
97
  } from "./chunk-2JNRWM6S.js";
87
- import {
88
- AssetMentionChips,
89
- GenerationHistory,
90
- GenerationSettings,
91
- JobProgress,
92
- useGenerationPlan,
93
- useGenerationRecords,
94
- useJobProgress
95
- } from "./chunk-FLS7Q32M.js";
96
98
 
97
99
  // src/hooks/usePromptEditor.ts
98
100
  import React, { useMemo, useEffect, useRef } from "react";
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController, type PaintPresence, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
2
+ import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
3
3
  export interface PaintCanvasProps {
4
4
  controller: PaintEditorController;
5
5
  /** The active tool (default brush). */
@@ -12,6 +12,8 @@ export interface PaintCanvasProps {
12
12
  onError?: (message: string | null) => void;
13
13
  /** Agent cursors to draw over the canvas (see `PaintDirector` and `usePaintDirector`). */
14
14
  presence?: PaintPresence;
15
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
16
+ proposals?: PaintProposals;
15
17
  className?: string;
16
18
  }
17
19
  /**
@@ -38,3 +40,9 @@ export declare const PaintPresenceLayer: React.FC<{
38
40
  height: number;
39
41
  };
40
42
  }>;
43
+ /** Pending paint proposals drawn over the canvas: each ghost where its paint would go, translucent with a dashed edge. */
44
+ export declare const PaintProposalGhosts: React.FC<{
45
+ proposals: PaintProposals;
46
+ transform: string;
47
+ zoom: number;
48
+ }>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController, type PaintPresence, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
2
+ import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
3
3
  export interface PaintCanvasProps {
4
4
  controller: PaintEditorController;
5
5
  /** The active tool (default brush). */
@@ -12,6 +12,8 @@ export interface PaintCanvasProps {
12
12
  onError?: (message: string | null) => void;
13
13
  /** Agent cursors to draw over the canvas (see `PaintDirector` and `usePaintDirector`). */
14
14
  presence?: PaintPresence;
15
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
16
+ proposals?: PaintProposals;
15
17
  className?: string;
16
18
  }
17
19
  /**
@@ -38,3 +40,9 @@ export declare const PaintPresenceLayer: React.FC<{
38
40
  height: number;
39
41
  };
40
42
  }>;
43
+ /** Pending paint proposals drawn over the canvas: each ghost where its paint would go, translucent with a dashed edge. */
44
+ export declare const PaintProposalGhosts: React.FC<{
45
+ proposals: PaintProposals;
46
+ transform: string;
47
+ zoom: number;
48
+ }>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PaintPresence, type PaintEditorController } from '@pixerate/editor/paint-editor';
2
+ import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
3
3
  import type { AgentPlayback } from '@pixerate/editor/tools';
4
4
  export interface PaintEditorProps {
5
5
  controller: PaintEditorController;
@@ -9,6 +9,8 @@ export interface PaintEditorProps {
9
9
  height?: number | string;
10
10
  /** Agent cursors to draw over the canvas (see `usePaintDirector`). */
11
11
  presence?: PaintPresence;
12
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
13
+ proposals?: PaintProposals;
12
14
  className?: string;
13
15
  /**
14
16
  * Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PaintPresence, type PaintEditorController } from '@pixerate/editor/paint-editor';
2
+ import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
3
3
  import type { AgentPlayback } from '@pixerate/editor/tools';
4
4
  export interface PaintEditorProps {
5
5
  controller: PaintEditorController;
@@ -9,6 +9,8 @@ export interface PaintEditorProps {
9
9
  height?: number | string;
10
10
  /** Agent cursors to draw over the canvas (see `usePaintDirector`). */
11
11
  presence?: PaintPresence;
12
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
13
+ proposals?: PaintProposals;
12
14
  className?: string;
13
15
  /**
14
16
  * Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
@@ -41,6 +41,7 @@ __export(paint_editor_exports, {
41
41
  PaintGradientEditor: () => PaintGradientEditor,
42
42
  PaintLayersPanel: () => PaintLayersPanel,
43
43
  PaintPresenceLayer: () => PaintPresenceLayer,
44
+ PaintProposalGhosts: () => PaintProposalGhosts,
44
45
  PaintSlider: () => PaintSlider,
45
46
  PaintToolbar: () => PaintToolbar,
46
47
  PaperPanel: () => PaperPanel,
@@ -48,11 +49,13 @@ __export(paint_editor_exports, {
48
49
  StickerPicker: () => StickerPicker,
49
50
  StrokePanel: () => StrokePanel,
50
51
  WetPanel: () => WetPanel,
52
+ usePaintChangeFeed: () => usePaintChangeFeed,
51
53
  usePaintDirector: () => usePaintDirector,
52
54
  usePaintEditor: () => usePaintEditor,
53
55
  usePaintEditorState: () => usePaintEditorState,
54
56
  usePaintEffectsProvider: () => usePaintEffectsProvider,
55
- usePaintEffectsTools: () => usePaintEffectsTools
57
+ usePaintEffectsTools: () => usePaintEffectsTools,
58
+ usePaintProposals: () => usePaintProposals
56
59
  });
57
60
  module.exports = __toCommonJS(paint_editor_exports);
58
61
 
@@ -80,12 +83,33 @@ function usePaintDirector(controller, options = {}) {
80
83
  });
81
84
  return value;
82
85
  }
86
+ function usePaintProposals(controller, options = {}) {
87
+ const [store] = (0, import_react.useState)(() => (0, import_paint_editor.createPaintProposals)({ ...options, controller }));
88
+ const state = (0, import_react.useSyncExternalStore)(store.subscribe, store.getState, store.getState);
89
+ return (0, import_react.useMemo)(() => ({ store, proposals: state.proposals, propose: store.propose, accept: store.accept, reject: store.reject, clear: store.clear }), [store, state]);
90
+ }
91
+ function usePaintChangeFeed(controller, options = {}) {
92
+ const onChange = (0, import_react.useRef)(options.onChange);
93
+ onChange.current = options.onChange;
94
+ const [last, setLast] = (0, import_react.useState)(null);
95
+ const [feed, setFeed] = (0, import_react.useState)(null);
96
+ (0, import_react.useEffect)(() => {
97
+ const next = (0, import_paint_editor.createPaintChangeFeed)(controller);
98
+ next.subscribe((change) => {
99
+ setLast(change);
100
+ onChange.current?.(change);
101
+ });
102
+ setFeed(next);
103
+ return () => next.dispose();
104
+ }, [controller]);
105
+ return { feed, last };
106
+ }
83
107
 
84
108
  // src/paint-editor/PaintCanvas.tsx
85
109
  var import_react2 = require("react");
86
110
  var import_paint_editor2 = require("@pixerate/editor/paint-editor");
87
111
  var import_jsx_runtime = require("react/jsx-runtime");
88
- var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, className }) => {
112
+ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
89
113
  const state = usePaintEditorState(controller);
90
114
  const viewport = (0, import_react2.useRef)(null);
91
115
  const canvas = (0, import_react2.useRef)(null);
@@ -226,6 +250,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
226
250
  predicted.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: predicted.map((p) => `${p.x},${p.y}`).join(" "), fill: "none", stroke: state.color, strokeOpacity: 0.5, strokeWidth: Math.max(1, state.brush.tip.size / 2), strokeLinecap: "round" })
227
251
  ] }),
228
252
  state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReferencePanel, { controller, id: r.id }, r.id)),
253
+ proposals && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintProposalGhosts, { proposals, transform, zoom: state.view.zoom }),
229
254
  presence && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintPresenceLayer, { presence, view: state.view, canvas: doc, viewport: size }),
230
255
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "absolute bottom-1 right-2 text-[10px] text-slate-500 pointer-events-none", "data-testid": "paint-view-status", children: [
231
256
  Math.round(state.view.zoom * 100),
@@ -301,6 +326,33 @@ var ReferencePanel = ({ controller, id }) => {
301
326
  }
302
327
  );
303
328
  };
329
+ var PaintProposalGhosts = ({ proposals, transform, zoom }) => {
330
+ const { proposals: pending } = (0, import_react2.useSyncExternalStore)(proposals.subscribe, proposals.getState, proposals.getState);
331
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: pending.map((p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintProposalGhost, { proposal: p, transform, zoom }, p.id)) });
332
+ };
333
+ var PaintProposalGhost = ({ proposal, transform, zoom }) => {
334
+ const ref = (0, import_react2.useRef)(null);
335
+ const ghost = (0, import_paint_editor2.paintProposalGhost)(proposal);
336
+ (0, import_react2.useEffect)(() => {
337
+ const ctx = ref.current?.getContext("2d");
338
+ if (!ctx || !ghost || typeof ImageData === "undefined") return;
339
+ ctx.putImageData(new ImageData(new Uint8ClampedArray(ghost.data), ghost.width, ghost.height), 0, 0);
340
+ }, [ghost?.data]);
341
+ if (!ghost) return null;
342
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
343
+ "canvas",
344
+ {
345
+ ref,
346
+ width: ghost.width,
347
+ height: ghost.height,
348
+ "data-paint-proposal": proposal.id,
349
+ title: proposal.rationale ? `${proposal.title}: ${proposal.rationale}` : proposal.title,
350
+ "aria-label": `Suggested: ${proposal.title}`,
351
+ className: "absolute left-0 top-0 pointer-events-none",
352
+ style: { transform: `${transform} translate(${ghost.x}px, ${ghost.y}px)`, transformOrigin: "0 0", opacity: 0.7, outline: `${1.5 / zoom}px dashed #a78bfa`, outlineOffset: `${2 / zoom}px` }
353
+ }
354
+ );
355
+ };
304
356
 
305
357
  // src/paint-editor/PaintToolbar.tsx
306
358
  var import_react4 = require("react");
@@ -695,10 +747,25 @@ var EditorControl = ({ control: c, onSet }) => {
695
747
  }
696
748
  };
697
749
 
698
- // src/paint-editor/BrushLibraryBrowser.tsx
750
+ // src/brushes/BrushLibraryBrowser.tsx
699
751
  var import_react6 = require("react");
700
752
  var import_brushes2 = require("@pixerate/editor/brushes");
701
753
  var import_jsx_runtime5 = require("react/jsx-runtime");
754
+ var Thumbnail = ({ image, label, style }) => {
755
+ const ref = (0, import_react6.useRef)(null);
756
+ (0, import_react6.useEffect)(() => {
757
+ const canvas = ref.current;
758
+ const ctx = canvas?.getContext("2d");
759
+ if (!canvas || !ctx || !image || typeof image === "string" || typeof ctx.createImageData !== "function") return;
760
+ canvas.width = image.width;
761
+ canvas.height = image.height;
762
+ const img = ctx.createImageData(image.width, image.height);
763
+ img.data.set(image.data);
764
+ ctx.putImageData(img, 0, 0);
765
+ }, [image]);
766
+ if (typeof image === "string") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: image, alt: label, className: "rounded object-contain", style });
767
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("canvas", { ref, role: "img", "aria-label": label, className: "rounded", style, width: image?.width, height: image?.height });
768
+ };
702
769
  var BrushLibraryBrowser = ({ entries, activeId, onSelect, profile, thumbnail, thumbnailWidth = 112, thumbnailHeight = 32, className }) => {
703
770
  const [text, setText] = (0, import_react6.useState)("");
704
771
  const groups = (0, import_react6.useMemo)(() => (0, import_brushes2.brushLibraryGroups)(entries, { text, profile }), [entries, text, profile]);
@@ -718,7 +785,7 @@ var BrushLibraryBrowser = ({ entries, activeId, onSelect, profile, thumbnail, th
718
785
  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"}`,
719
786
  onClick: () => onSelect(e.brush.id),
720
787
  children: [
721
- thumbnail && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PixelCanvas, { pixels: thumbnail(e.brush.id), label: `${e.brush.name} thumbnail`, className: "rounded", style: { width: "100%", aspectRatio: `${thumbnailWidth} / ${thumbnailHeight}` } }),
788
+ thumbnail && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Thumbnail, { image: thumbnail(e.brush.id) ?? null, label: `${e.brush.name} thumbnail`, style: { width: "100%", aspectRatio: `${thumbnailWidth} / ${thumbnailHeight}` } }),
722
789
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "truncate text-[10px] text-slate-300", children: e.brush.name })
723
790
  ]
724
791
  },
@@ -3898,7 +3965,7 @@ var PAINT_CONTROLS = {
3898
3965
  lighting: '[data-testid="light-panel"]',
3899
3966
  symmetry: '[aria-label="Symmetry"]'
3900
3967
  };
3901
- var PaintEditor = ({ controller, fileName, height = 720, presence, className, playback, playbackId = "paint", onPlaybackReveal }) => {
3968
+ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
3902
3969
  const [tool, setTool] = (0, import_react29.useState)("brush");
3903
3970
  const [tab, setTab] = (0, import_react29.useState)("color");
3904
3971
  const tabRef = (0, import_react29.useRef)(tab);
@@ -3969,7 +4036,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
3969
4036
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-h-0 flex-1 gap-2", children: [
3970
4037
  /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
3971
4038
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col", children: [
3972
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, className: "flex-1 rounded-lg" }),
4039
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
3973
4040
  error && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
3974
4041
  ] }),
3975
4042
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
@@ -3999,6 +4066,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
3999
4066
  PaintGradientEditor,
4000
4067
  PaintLayersPanel,
4001
4068
  PaintPresenceLayer,
4069
+ PaintProposalGhosts,
4002
4070
  PaintSlider,
4003
4071
  PaintToolbar,
4004
4072
  PaperPanel,
@@ -4006,9 +4074,11 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
4006
4074
  StickerPicker,
4007
4075
  StrokePanel,
4008
4076
  WetPanel,
4077
+ usePaintChangeFeed,
4009
4078
  usePaintDirector,
4010
4079
  usePaintEditor,
4011
4080
  usePaintEditorState,
4012
4081
  usePaintEffectsProvider,
4013
- usePaintEffectsTools
4082
+ usePaintEffectsTools,
4083
+ usePaintProposals
4014
4084
  });
@@ -3,7 +3,7 @@ export * from './PaintCanvas.cjs';
3
3
  export * from './PaintToolbar.cjs';
4
4
  export * from './BrushPanel.cjs';
5
5
  export * from './BrushEditor.cjs';
6
- export * from './BrushLibraryBrowser.cjs';
6
+ export { BrushLibraryBrowser, type BrushLibraryBrowserProps } from '../brushes/BrushLibraryBrowser.cjs';
7
7
  export * from './PaperPanel.cjs';
8
8
  export * from './ColorPanel.cjs';
9
9
  export * from './PaintLayersPanel.cjs';
@@ -3,7 +3,7 @@ export * from './PaintCanvas.js';
3
3
  export * from './PaintToolbar.js';
4
4
  export * from './BrushPanel.js';
5
5
  export * from './BrushEditor.js';
6
- export * from './BrushLibraryBrowser.js';
6
+ export { BrushLibraryBrowser, type BrushLibraryBrowserProps } from '../brushes/BrushLibraryBrowser.js';
7
7
  export * from './PaperPanel.js';
8
8
  export * from './ColorPanel.js';
9
9
  export * from './PaintLayersPanel.js';