@pixerate/editor-react 0.117.0 → 0.119.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.
@@ -222,6 +222,7 @@ import {
222
222
  getViewportProjection,
223
223
  measureCanvasViewport,
224
224
  watchCanvasViewport,
225
+ startMarchingAnts,
225
226
  ShapeDrawGesture,
226
227
  TypeToolGesture,
227
228
  DEFAULT_SHAPE_TOOL_OPTIONS,
@@ -375,6 +376,7 @@ var ImageEditorCanvas = ({
375
376
  const isDrawingRef = useRef2(false);
376
377
  const currentPathRef = useRef2([]);
377
378
  const dragStartPointRef = useRef2(null);
379
+ const antsOffsetRef = useRef2(0);
378
380
  const renderCanvas = useCallback2(
379
381
  async (draftAnnotation, draftCrop) => {
380
382
  const canvas = canvasRef.current;
@@ -382,6 +384,7 @@ var ImageEditorCanvas = ({
382
384
  if (!canvas || !container) return;
383
385
  const viewport = measureCanvasViewport(container);
384
386
  viewRef.current = { width: viewport.width, height: viewport.height };
387
+ transformTool.setView(getViewportProjection(controller.getState(), viewport.width, viewport.height, mode === "crop").scale);
385
388
  await controller.render(canvas, {
386
389
  viewportWidth: viewport.width,
387
390
  viewportHeight: viewport.height,
@@ -390,6 +393,7 @@ var ImageEditorCanvas = ({
390
393
  fit,
391
394
  showCropOverlay: mode === "crop",
392
395
  showSelectionOverlay: true,
396
+ antsOffset: antsOffsetRef.current,
393
397
  interactive: true,
394
398
  draftAnnotation: draftAnnotation !== void 0 ? draftAnnotation : draftAnnotationRef.current,
395
399
  draftCrop: draftCrop !== void 0 ? draftCrop : draftCropRef.current,
@@ -401,6 +405,14 @@ var ImageEditorCanvas = ({
401
405
  },
402
406
  [controller, mode, fit, transformTool]
403
407
  );
408
+ const marching = !!state.selection?.bounds && !state.quickMask;
409
+ useEffect2(() => {
410
+ if (!marching) return;
411
+ return startMarchingAnts((offset) => {
412
+ antsOffsetRef.current = offset;
413
+ void renderCanvas();
414
+ });
415
+ }, [marching, renderCanvas]);
404
416
  useEffect2(() => {
405
417
  let drafting = false;
406
418
  return agentPresence.subscribe(
@@ -2619,6 +2631,23 @@ var SelectionOptionsBar = ({
2619
2631
  const set = (patch) => onOptionsChange({ ...options, ...patch });
2620
2632
  const sel = selection === void 0 ? controller.getSelection() : selection;
2621
2633
  const qm = quickMask ?? Boolean(controller.getState().quickMask);
2634
+ const [subject, setSubject] = useState11("");
2635
+ const [segmenting, setSegmenting] = useState11(false);
2636
+ const [subjectStatus, setSubjectStatus] = useState11(null);
2637
+ const selectSubject = async () => {
2638
+ const target = subject.trim();
2639
+ if (!target || segmenting) return;
2640
+ setSegmenting(true);
2641
+ setSubjectStatus(null);
2642
+ try {
2643
+ const { segments } = await controller.selectSubject(target, { mode: options.mode });
2644
+ setSubjectStatus(segments.length ? null : `Nothing matching \u201C${target}\u201D was found.`);
2645
+ } catch (err) {
2646
+ setSubjectStatus(err instanceof Error ? err.message : String(err));
2647
+ } finally {
2648
+ setSegmenting(false);
2649
+ }
2650
+ };
2622
2651
  return /* @__PURE__ */ jsxs13("div", { "data-testid": "selection-options-bar", className: `flex flex-col gap-3 text-xs ${className}`, children: [
2623
2652
  /* @__PURE__ */ jsx15("div", { role: "group", "aria-label": "Selection tool", className: "flex flex-wrap gap-1", children: SELECTION_TOOLS.map((t) => /* @__PURE__ */ jsx15("button", { type: "button", "aria-pressed": options.tool === t.id, className: btn(options.tool === t.id), onClick: () => set({ tool: t.id }), children: t.label }, t.id)) }),
2624
2653
  /* @__PURE__ */ jsx15("div", { role: "group", "aria-label": "Selection mode", className: "flex flex-wrap gap-1", children: SELECTION_MODES.map((m) => /* @__PURE__ */ jsx15("button", { type: "button", "aria-pressed": options.mode === m, className: btn(options.mode === m), onClick: () => set({ mode: m }), children: SELECTION_MODE_LABELS[m] }, m)) }),
@@ -2654,6 +2683,35 @@ var SelectionOptionsBar = ({
2654
2683
  )
2655
2684
  ] })
2656
2685
  ] }),
2686
+ controller.segmentationProvider && /* @__PURE__ */ jsxs13(
2687
+ "form",
2688
+ {
2689
+ "data-testid": "select-subject",
2690
+ className: "flex flex-col gap-1",
2691
+ onSubmit: (e) => {
2692
+ e.preventDefault();
2693
+ void selectSubject();
2694
+ },
2695
+ children: [
2696
+ /* @__PURE__ */ jsxs13("div", { className: "flex gap-1", children: [
2697
+ /* @__PURE__ */ jsx15(
2698
+ "input",
2699
+ {
2700
+ type: "text",
2701
+ "aria-label": "Subject to select",
2702
+ placeholder: "Subject, e.g. the dog",
2703
+ value: subject,
2704
+ disabled: segmenting,
2705
+ onChange: (e) => setSubject(e.currentTarget.value),
2706
+ className: "min-w-0 flex-1 bg-background border border-border rounded px-2 py-1 text-foreground"
2707
+ }
2708
+ ),
2709
+ /* @__PURE__ */ jsx15("button", { type: "submit", className: btn(false), disabled: segmenting || !subject.trim(), "aria-busy": segmenting, children: segmenting ? "Selecting\u2026" : "Select Subject" })
2710
+ ] }),
2711
+ subjectStatus && /* @__PURE__ */ jsx15("p", { role: "status", className: "text-muted-foreground", children: subjectStatus })
2712
+ ]
2713
+ }
2714
+ ),
2657
2715
  /* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-2 text-foreground", children: [
2658
2716
  /* @__PURE__ */ jsx15(ImageCheckbox, { label: "Anti-alias", checked: options.antiAlias, onChange: (on) => set({ antiAlias: on }) }),
2659
2717
  "Anti-alias"
@@ -13,6 +13,7 @@ export interface SelectionOptionsBarProps {
13
13
  /**
14
14
  * Options bar of the selection tools: tool, mode (new / add / subtract / intersect), magic wand
15
15
  * tolerance and contiguous, anti-alias, sample merged, Select › All / Deselect / Inverse,
16
- * Modify (grow, shrink, feather, border, smooth) and the Quick Mask toggle.
16
+ * Modify (grow, shrink, feather, border, smooth) and the Quick Mask toggle. With a segmentation
17
+ * provider on the controller it adds Select › Subject (a description and a button).
17
18
  */
18
19
  export declare const SelectionOptionsBar: React.FC<SelectionOptionsBarProps>;
@@ -13,6 +13,7 @@ export interface SelectionOptionsBarProps {
13
13
  /**
14
14
  * Options bar of the selection tools: tool, mode (new / add / subtract / intersect), magic wand
15
15
  * tolerance and contiguous, anti-alias, sample merged, Select › All / Deselect / Inverse,
16
- * Modify (grow, shrink, feather, border, smooth) and the Quick Mask toggle.
16
+ * Modify (grow, shrink, feather, border, smooth) and the Quick Mask toggle. With a segmentation
17
+ * provider on the controller it adds Select › Subject (a description and a button).
17
18
  */
18
19
  export declare const SelectionOptionsBar: React.FC<SelectionOptionsBarProps>;
@@ -479,6 +479,7 @@ var ImageEditorCanvas = ({
479
479
  const isDrawingRef = (0, import_react5.useRef)(false);
480
480
  const currentPathRef = (0, import_react5.useRef)([]);
481
481
  const dragStartPointRef = (0, import_react5.useRef)(null);
482
+ const antsOffsetRef = (0, import_react5.useRef)(0);
482
483
  const renderCanvas = (0, import_react5.useCallback)(
483
484
  async (draftAnnotation, draftCrop) => {
484
485
  const canvas = canvasRef.current;
@@ -486,6 +487,7 @@ var ImageEditorCanvas = ({
486
487
  if (!canvas || !container) return;
487
488
  const viewport = (0, import_image_editor2.measureCanvasViewport)(container);
488
489
  viewRef.current = { width: viewport.width, height: viewport.height };
490
+ transformTool.setView((0, import_image_editor2.getViewportProjection)(controller.getState(), viewport.width, viewport.height, mode === "crop").scale);
489
491
  await controller.render(canvas, {
490
492
  viewportWidth: viewport.width,
491
493
  viewportHeight: viewport.height,
@@ -494,6 +496,7 @@ var ImageEditorCanvas = ({
494
496
  fit,
495
497
  showCropOverlay: mode === "crop",
496
498
  showSelectionOverlay: true,
499
+ antsOffset: antsOffsetRef.current,
497
500
  interactive: true,
498
501
  draftAnnotation: draftAnnotation !== void 0 ? draftAnnotation : draftAnnotationRef.current,
499
502
  draftCrop: draftCrop !== void 0 ? draftCrop : draftCropRef.current,
@@ -505,6 +508,14 @@ var ImageEditorCanvas = ({
505
508
  },
506
509
  [controller, mode, fit, transformTool]
507
510
  );
511
+ const marching = !!state.selection?.bounds && !state.quickMask;
512
+ (0, import_react5.useEffect)(() => {
513
+ if (!marching) return;
514
+ return (0, import_image_editor2.startMarchingAnts)((offset) => {
515
+ antsOffsetRef.current = offset;
516
+ void renderCanvas();
517
+ });
518
+ }, [marching, renderCanvas]);
508
519
  (0, import_react5.useEffect)(() => {
509
520
  let drafting = false;
510
521
  return agentPresence.subscribe(
@@ -4559,6 +4570,23 @@ var SelectionOptionsBar = ({
4559
4570
  const set = (patch) => onOptionsChange({ ...options, ...patch });
4560
4571
  const sel = selection === void 0 ? controller.getSelection() : selection;
4561
4572
  const qm = quickMask ?? Boolean(controller.getState().quickMask);
4573
+ const [subject, setSubject] = (0, import_react25.useState)("");
4574
+ const [segmenting, setSegmenting] = (0, import_react25.useState)(false);
4575
+ const [subjectStatus, setSubjectStatus] = (0, import_react25.useState)(null);
4576
+ const selectSubject = async () => {
4577
+ const target = subject.trim();
4578
+ if (!target || segmenting) return;
4579
+ setSegmenting(true);
4580
+ setSubjectStatus(null);
4581
+ try {
4582
+ const { segments } = await controller.selectSubject(target, { mode: options.mode });
4583
+ setSubjectStatus(segments.length ? null : `Nothing matching \u201C${target}\u201D was found.`);
4584
+ } catch (err) {
4585
+ setSubjectStatus(err instanceof Error ? err.message : String(err));
4586
+ } finally {
4587
+ setSegmenting(false);
4588
+ }
4589
+ };
4562
4590
  return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { "data-testid": "selection-options-bar", className: `flex flex-col gap-3 text-xs ${className}`, children: [
4563
4591
  /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { role: "group", "aria-label": "Selection tool", className: "flex flex-wrap gap-1", children: import_image_editor14.SELECTION_TOOLS.map((t) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", "aria-pressed": options.tool === t.id, className: btn(options.tool === t.id), onClick: () => set({ tool: t.id }), children: t.label }, t.id)) }),
4564
4592
  /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { role: "group", "aria-label": "Selection mode", className: "flex flex-wrap gap-1", children: import_image_editor14.SELECTION_MODES.map((m) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", "aria-pressed": options.mode === m, className: btn(options.mode === m), onClick: () => set({ mode: m }), children: import_image_editor14.SELECTION_MODE_LABELS[m] }, m)) }),
@@ -4594,6 +4622,35 @@ var SelectionOptionsBar = ({
4594
4622
  )
4595
4623
  ] })
4596
4624
  ] }),
4625
+ controller.segmentationProvider && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
4626
+ "form",
4627
+ {
4628
+ "data-testid": "select-subject",
4629
+ className: "flex flex-col gap-1",
4630
+ onSubmit: (e) => {
4631
+ e.preventDefault();
4632
+ void selectSubject();
4633
+ },
4634
+ children: [
4635
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex gap-1", children: [
4636
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
4637
+ "input",
4638
+ {
4639
+ type: "text",
4640
+ "aria-label": "Subject to select",
4641
+ placeholder: "Subject, e.g. the dog",
4642
+ value: subject,
4643
+ disabled: segmenting,
4644
+ onChange: (e) => setSubject(e.currentTarget.value),
4645
+ className: "min-w-0 flex-1 bg-background border border-border rounded px-2 py-1 text-foreground"
4646
+ }
4647
+ ),
4648
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "submit", className: btn(false), disabled: segmenting || !subject.trim(), "aria-busy": segmenting, children: segmenting ? "Selecting\u2026" : "Select Subject" })
4649
+ ] }),
4650
+ subjectStatus && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { role: "status", className: "text-muted-foreground", children: subjectStatus })
4651
+ ]
4652
+ }
4653
+ ),
4597
4654
  /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
4598
4655
  /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageCheckbox, { label: "Anti-alias", checked: options.antiAlias, onChange: (on) => set({ antiAlias: on }) }),
4599
4656
  "Anti-alias"
@@ -26,7 +26,7 @@ import {
26
26
  useImageEditorControls,
27
27
  useImageEffectsTools,
28
28
  useImageHistogram
29
- } from "../chunk-K7GU7BS7.js";
29
+ } from "../chunk-H2EO7O3J.js";
30
30
  import "../chunk-AJCWF6SN.js";
31
31
  import "../chunk-6BWTJ3EE.js";
32
32
  import "../chunk-5RPB4WGT.js";
package/dist/index.cjs CHANGED
@@ -4193,6 +4193,7 @@ var ImageEditorCanvas = ({
4193
4193
  const isDrawingRef = (0, import_react41.useRef)(false);
4194
4194
  const currentPathRef = (0, import_react41.useRef)([]);
4195
4195
  const dragStartPointRef = (0, import_react41.useRef)(null);
4196
+ const antsOffsetRef = (0, import_react41.useRef)(0);
4196
4197
  const renderCanvas = (0, import_react41.useCallback)(
4197
4198
  async (draftAnnotation, draftCrop) => {
4198
4199
  const canvas = canvasRef.current;
@@ -4200,6 +4201,7 @@ var ImageEditorCanvas = ({
4200
4201
  if (!canvas || !container) return;
4201
4202
  const viewport = (0, import_image_editor2.measureCanvasViewport)(container);
4202
4203
  viewRef.current = { width: viewport.width, height: viewport.height };
4204
+ transformTool.setView((0, import_image_editor2.getViewportProjection)(controller.getState(), viewport.width, viewport.height, mode === "crop").scale);
4203
4205
  await controller.render(canvas, {
4204
4206
  viewportWidth: viewport.width,
4205
4207
  viewportHeight: viewport.height,
@@ -4208,6 +4210,7 @@ var ImageEditorCanvas = ({
4208
4210
  fit,
4209
4211
  showCropOverlay: mode === "crop",
4210
4212
  showSelectionOverlay: true,
4213
+ antsOffset: antsOffsetRef.current,
4211
4214
  interactive: true,
4212
4215
  draftAnnotation: draftAnnotation !== void 0 ? draftAnnotation : draftAnnotationRef.current,
4213
4216
  draftCrop: draftCrop !== void 0 ? draftCrop : draftCropRef.current,
@@ -4219,6 +4222,14 @@ var ImageEditorCanvas = ({
4219
4222
  },
4220
4223
  [controller, mode, fit, transformTool]
4221
4224
  );
4225
+ const marching = !!state.selection?.bounds && !state.quickMask;
4226
+ (0, import_react41.useEffect)(() => {
4227
+ if (!marching) return;
4228
+ return (0, import_image_editor2.startMarchingAnts)((offset) => {
4229
+ antsOffsetRef.current = offset;
4230
+ void renderCanvas();
4231
+ });
4232
+ }, [marching, renderCanvas]);
4222
4233
  (0, import_react41.useEffect)(() => {
4223
4234
  let drafting = false;
4224
4235
  return agentPresence.subscribe(
@@ -8273,6 +8284,23 @@ var SelectionOptionsBar = ({
8273
8284
  const set = (patch) => onOptionsChange({ ...options, ...patch });
8274
8285
  const sel = selection === void 0 ? controller.getSelection() : selection;
8275
8286
  const qm = quickMask ?? Boolean(controller.getState().quickMask);
8287
+ const [subject, setSubject] = (0, import_react61.useState)("");
8288
+ const [segmenting, setSegmenting] = (0, import_react61.useState)(false);
8289
+ const [subjectStatus, setSubjectStatus] = (0, import_react61.useState)(null);
8290
+ const selectSubject = async () => {
8291
+ const target = subject.trim();
8292
+ if (!target || segmenting) return;
8293
+ setSegmenting(true);
8294
+ setSubjectStatus(null);
8295
+ try {
8296
+ const { segments } = await controller.selectSubject(target, { mode: options.mode });
8297
+ setSubjectStatus(segments.length ? null : `Nothing matching \u201C${target}\u201D was found.`);
8298
+ } catch (err) {
8299
+ setSubjectStatus(err instanceof Error ? err.message : String(err));
8300
+ } finally {
8301
+ setSegmenting(false);
8302
+ }
8303
+ };
8276
8304
  return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { "data-testid": "selection-options-bar", className: `flex flex-col gap-3 text-xs ${className}`, children: [
8277
8305
  /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { role: "group", "aria-label": "Selection tool", className: "flex flex-wrap gap-1", children: import_image_editor14.SELECTION_TOOLS.map((t) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", "aria-pressed": options.tool === t.id, className: btn(options.tool === t.id), onClick: () => set({ tool: t.id }), children: t.label }, t.id)) }),
8278
8306
  /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { role: "group", "aria-label": "Selection mode", className: "flex flex-wrap gap-1", children: import_image_editor14.SELECTION_MODES.map((m) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", "aria-pressed": options.mode === m, className: btn(options.mode === m), onClick: () => set({ mode: m }), children: import_image_editor14.SELECTION_MODE_LABELS[m] }, m)) }),
@@ -8308,6 +8336,35 @@ var SelectionOptionsBar = ({
8308
8336
  )
8309
8337
  ] })
8310
8338
  ] }),
8339
+ controller.segmentationProvider && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
8340
+ "form",
8341
+ {
8342
+ "data-testid": "select-subject",
8343
+ className: "flex flex-col gap-1",
8344
+ onSubmit: (e) => {
8345
+ e.preventDefault();
8346
+ void selectSubject();
8347
+ },
8348
+ children: [
8349
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex gap-1", children: [
8350
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8351
+ "input",
8352
+ {
8353
+ type: "text",
8354
+ "aria-label": "Subject to select",
8355
+ placeholder: "Subject, e.g. the dog",
8356
+ value: subject,
8357
+ disabled: segmenting,
8358
+ onChange: (e) => setSubject(e.currentTarget.value),
8359
+ className: "min-w-0 flex-1 bg-background border border-border rounded px-2 py-1 text-foreground"
8360
+ }
8361
+ ),
8362
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "submit", className: btn(false), disabled: segmenting || !subject.trim(), "aria-busy": segmenting, children: segmenting ? "Selecting\u2026" : "Select Subject" })
8363
+ ] }),
8364
+ subjectStatus && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { role: "status", className: "text-muted-foreground", children: subjectStatus })
8365
+ ]
8366
+ }
8367
+ ),
8311
8368
  /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
8312
8369
  /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ImageCheckbox, { label: "Anti-alias", checked: options.antiAlias, onChange: (on) => set({ antiAlias: on }) }),
8313
8370
  "Anti-alias"
package/dist/index.js CHANGED
@@ -50,7 +50,7 @@ import {
50
50
  useImageEditorControls,
51
51
  useImageEffectsTools,
52
52
  useImageHistogram
53
- } from "./chunk-K7GU7BS7.js";
53
+ } from "./chunk-H2EO7O3J.js";
54
54
  import "./chunk-AJCWF6SN.js";
55
55
  import "./chunk-6BWTJ3EE.js";
56
56
  import "./chunk-5RPB4WGT.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.117.0",
3
+ "version": "0.119.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -254,7 +254,7 @@
254
254
  "dependencies": {},
255
255
  "peerDependencies": {
256
256
  "@dagrejs/dagre": "^1.1.8",
257
- "@pixerate/editor": ">=0.178.0 <1.0.0-0",
257
+ "@pixerate/editor": ">=0.180.0 <1.0.0-0",
258
258
  "@tiptap/core": "^2.27.3",
259
259
  "@tiptap/extension-bubble-menu": "^2.27.3",
260
260
  "@tiptap/extension-placeholder": "^2.27.3",
@@ -305,7 +305,7 @@
305
305
  "tsup": "^9.0.0",
306
306
  "typescript": "^5.7.3",
307
307
  "vitest": "^5.0.5",
308
- "@pixerate/editor": "0.178.0"
308
+ "@pixerate/editor": "0.180.0"
309
309
  },
310
310
  "scripts": {
311
311
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",