@pixerate/editor-react 0.119.0 → 0.121.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/{chunk-H2EO7O3J.js → chunk-CQXZVIV7.js} +221 -14
- package/dist/image-editor/LayersPanel.d.cts +2 -1
- package/dist/image-editor/LayersPanel.d.ts +2 -1
- package/dist/image-editor/SelectionOptionsBar.d.cts +8 -4
- package/dist/image-editor/SelectionOptionsBar.d.ts +8 -4
- package/dist/image-editor/index.cjs +216 -14
- package/dist/image-editor/index.js +1 -1
- package/dist/index.cjs +216 -14
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -223,6 +223,7 @@ import {
|
|
|
223
223
|
measureCanvasViewport,
|
|
224
224
|
watchCanvasViewport,
|
|
225
225
|
startMarchingAnts,
|
|
226
|
+
handleSelectionShortcut,
|
|
226
227
|
ShapeDrawGesture,
|
|
227
228
|
TypeToolGesture,
|
|
228
229
|
DEFAULT_SHAPE_TOOL_OPTIONS,
|
|
@@ -593,6 +594,26 @@ var ImageEditorCanvas = ({
|
|
|
593
594
|
if (g.error) report("paint", g.error);
|
|
594
595
|
}
|
|
595
596
|
};
|
|
597
|
+
useEffect2(() => {
|
|
598
|
+
if (mode !== "select" || typeof window === "undefined") return;
|
|
599
|
+
const onKey = (e) => {
|
|
600
|
+
const target = e.target;
|
|
601
|
+
if (target?.closest?.('input, textarea, select, [contenteditable="true"]')) return;
|
|
602
|
+
if (window.getSelection?.()?.toString()) return;
|
|
603
|
+
const gesture = selectionGestureRef.current;
|
|
604
|
+
if (handleSelectionShortcut(controller, e, (message) => report("select", message))) {
|
|
605
|
+
e.preventDefault();
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
if (gesture?.key(e.key)) {
|
|
609
|
+
e.preventDefault();
|
|
610
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
611
|
+
void renderCanvas();
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
window.addEventListener("keydown", onKey);
|
|
615
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
616
|
+
});
|
|
596
617
|
useEffect2(() => {
|
|
597
618
|
if (mode !== "paint" || typeof window === "undefined") return;
|
|
598
619
|
const onKey = (e) => {
|
|
@@ -608,7 +629,11 @@ var ImageEditorCanvas = ({
|
|
|
608
629
|
if (mode === "select") {
|
|
609
630
|
const gesture = selectionGestureRef.current;
|
|
610
631
|
const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
611
|
-
void gesture.begin(imgPt, e).then(() =>
|
|
632
|
+
void gesture.begin(imgPt, e).then(() => {
|
|
633
|
+
report("select", gesture.error);
|
|
634
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
635
|
+
void renderCanvas();
|
|
636
|
+
});
|
|
612
637
|
return;
|
|
613
638
|
}
|
|
614
639
|
if (mode === "crop") {
|
|
@@ -690,7 +715,7 @@ var ImageEditorCanvas = ({
|
|
|
690
715
|
const canvasPt = getCanvasEventPoint(e);
|
|
691
716
|
if (mode === "select") {
|
|
692
717
|
const gesture = selectionGestureRef.current;
|
|
693
|
-
if (gesture.active && gesture.move(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
|
|
718
|
+
if (gesture.active && gesture.move(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e)) {
|
|
694
719
|
selectionDraftRef.current = gesture.draftPath;
|
|
695
720
|
renderCanvas();
|
|
696
721
|
}
|
|
@@ -833,7 +858,7 @@ var ImageEditorCanvas = ({
|
|
|
833
858
|
const gesture = selectionGestureRef.current;
|
|
834
859
|
if (gesture.active) {
|
|
835
860
|
gesture.end(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
|
|
836
|
-
selectionDraftRef.current =
|
|
861
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
837
862
|
renderCanvas();
|
|
838
863
|
}
|
|
839
864
|
return;
|
|
@@ -1361,7 +1386,7 @@ var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram, classN
|
|
|
1361
1386
|
type: "button",
|
|
1362
1387
|
className: "px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1363
1388
|
onClick: () => {
|
|
1364
|
-
setSelectedId(controller.addAdjustmentLayer(newKind));
|
|
1389
|
+
setSelectedId(controller.addAdjustmentLayer({ kind: newKind, useSelection: true }));
|
|
1365
1390
|
setChannel("master");
|
|
1366
1391
|
setRange(-1);
|
|
1367
1392
|
},
|
|
@@ -1623,6 +1648,8 @@ import {
|
|
|
1623
1648
|
downloadPsd,
|
|
1624
1649
|
dropPlacement,
|
|
1625
1650
|
dropZone,
|
|
1651
|
+
maskThumbnailClick,
|
|
1652
|
+
layerThumbnailClick,
|
|
1626
1653
|
openPsdFile,
|
|
1627
1654
|
layerBadge,
|
|
1628
1655
|
layerHasThumbnail,
|
|
@@ -1929,7 +1956,14 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
1929
1956
|
pixels: thumb(layer),
|
|
1930
1957
|
size: thumbnailSize,
|
|
1931
1958
|
label: `${row.label} pixels`,
|
|
1932
|
-
|
|
1959
|
+
testId: "layer-thumbnail",
|
|
1960
|
+
selected: row.active && state.activeTarget === "pixels" && Boolean(layer.mask),
|
|
1961
|
+
onClick: (e) => {
|
|
1962
|
+
if (e.ctrlKey || e.metaKey) {
|
|
1963
|
+
e.stopPropagation();
|
|
1964
|
+
attempt(() => layerThumbnailClick(controller, layer, e));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1933
1967
|
}
|
|
1934
1968
|
),
|
|
1935
1969
|
layer.type !== "pixel" && /* @__PURE__ */ jsx8(
|
|
@@ -1974,8 +2008,7 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
1974
2008
|
selected: row.active && state.activeTarget === "mask",
|
|
1975
2009
|
onClick: (e) => {
|
|
1976
2010
|
e.stopPropagation();
|
|
1977
|
-
|
|
1978
|
-
else attempt(() => controller.setActiveLayer(layer.id, "mask"));
|
|
2011
|
+
attempt(() => maskThumbnailClick(controller, layer, e));
|
|
1979
2012
|
}
|
|
1980
2013
|
}
|
|
1981
2014
|
),
|
|
@@ -2281,7 +2314,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
2281
2314
|
/* @__PURE__ */ jsx11("span", { className: "flex-1 font-semibold uppercase tracking-wider text-[11px] text-foreground", children: "Filters" }),
|
|
2282
2315
|
/* @__PURE__ */ jsx11("button", { type: "button", className: imageOutlineButtonClass, "aria-pressed": browse === "filter", onClick: () => setBrowse(browse === "filter" ? null : "filter"), children: "Add filter\u2026" })
|
|
2283
2316
|
] }),
|
|
2284
|
-
browse === "filter" && layer && /* @__PURE__ */ jsx11(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id))) }),
|
|
2317
|
+
browse === "filter" && layer && /* @__PURE__ */ jsx11(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id, { useSelection: true }))) }),
|
|
2285
2318
|
filters.length > 0 && layer && /* @__PURE__ */ jsx11("ol", { className: "space-y-1", "data-effect-part": "filters", "aria-label": "Filters", children: filters.map((f) => {
|
|
2286
2319
|
const label = f.kind === "effect" ? f.name ?? f.effect : f.kind;
|
|
2287
2320
|
const all = layer.smartFilters.filters;
|
|
@@ -2605,6 +2638,8 @@ var ColorProfilePanel = ({ controller, className }) => {
|
|
|
2605
2638
|
// src/image-editor/SelectionOptionsBar.tsx
|
|
2606
2639
|
import { useState as useState11 } from "react";
|
|
2607
2640
|
import {
|
|
2641
|
+
COLOR_RANGE_PRESETS,
|
|
2642
|
+
COLOR_RANGE_PRESET_LABELS,
|
|
2608
2643
|
SELECTION_MODES,
|
|
2609
2644
|
SELECTION_MODE_LABELS,
|
|
2610
2645
|
SELECTION_TOOLS,
|
|
@@ -2612,12 +2647,18 @@ import {
|
|
|
2612
2647
|
} from "@pixerate/editor/image-editor";
|
|
2613
2648
|
import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2614
2649
|
var MODIFY_OPS = [
|
|
2615
|
-
{ op: "
|
|
2616
|
-
{ op: "
|
|
2650
|
+
{ op: "expand", label: "Expand" },
|
|
2651
|
+
{ op: "contract", label: "Contract" },
|
|
2617
2652
|
{ op: "feather", label: "Feather" },
|
|
2618
2653
|
{ op: "border", label: "Border" },
|
|
2619
2654
|
{ op: "smooth", label: "Smooth" }
|
|
2620
2655
|
];
|
|
2656
|
+
var DISPLAYS = [
|
|
2657
|
+
{ id: "ants", label: "Ants" },
|
|
2658
|
+
{ id: "quickMask", label: "Quick Mask" },
|
|
2659
|
+
{ id: "none", label: "Hidden" }
|
|
2660
|
+
];
|
|
2661
|
+
var numberInput = "w-14 bg-background border border-border rounded px-1 py-0.5 text-foreground";
|
|
2621
2662
|
var btn = (on) => `px-2 py-1 rounded-md border text-[11px] transition-colors ${on ? "bg-primary border-primary text-primary-foreground" : "bg-background border-border text-foreground hover:bg-accent hover:text-accent-foreground"}`;
|
|
2622
2663
|
var SelectionOptionsBar = ({
|
|
2623
2664
|
controller,
|
|
@@ -2625,12 +2666,50 @@ var SelectionOptionsBar = ({
|
|
|
2625
2666
|
onOptionsChange,
|
|
2626
2667
|
selection,
|
|
2627
2668
|
quickMask,
|
|
2669
|
+
selectionDisplay,
|
|
2628
2670
|
className = ""
|
|
2629
2671
|
}) => {
|
|
2630
2672
|
const [radius, setRadius] = useState11(2);
|
|
2631
2673
|
const set = (patch) => onOptionsChange({ ...options, ...patch });
|
|
2632
2674
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
2633
|
-
const
|
|
2675
|
+
const display = selectionDisplay ?? (quickMask === void 0 ? controller.getSelectionDisplay() : quickMask ? "quickMask" : "ants");
|
|
2676
|
+
const [preset, setPreset] = useState11("reds");
|
|
2677
|
+
const [rangeStatus, setRangeStatus] = useState11(null);
|
|
2678
|
+
const [colorStatus, setColorStatus] = useState11(null);
|
|
2679
|
+
const [strokeWidth, setStrokeWidth] = useState11(4);
|
|
2680
|
+
const [strokeLocation, setStrokeLocation] = useState11("outside");
|
|
2681
|
+
const edit = (fn) => {
|
|
2682
|
+
setColorStatus(null);
|
|
2683
|
+
try {
|
|
2684
|
+
fn();
|
|
2685
|
+
} catch (err) {
|
|
2686
|
+
setColorStatus(err instanceof Error ? err.message : String(err));
|
|
2687
|
+
}
|
|
2688
|
+
};
|
|
2689
|
+
const runColor = async (op) => {
|
|
2690
|
+
setColorStatus(null);
|
|
2691
|
+
const opts = { tolerance: options.tolerance, sampleMerged: options.sampleMerged, sample: options.sample };
|
|
2692
|
+
try {
|
|
2693
|
+
await (op === "grow" ? controller.growSelection(opts) : controller.selectSimilar(opts));
|
|
2694
|
+
} catch (err) {
|
|
2695
|
+
setColorStatus(err instanceof Error ? err.message : String(err));
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
const applyPreset = async () => {
|
|
2699
|
+
setRangeStatus(null);
|
|
2700
|
+
try {
|
|
2701
|
+
await controller.selectColorRangePreset(preset, {
|
|
2702
|
+
mode: options.mode,
|
|
2703
|
+
feather: options.feather ?? 0,
|
|
2704
|
+
invert: options.rangeInvert ?? false,
|
|
2705
|
+
falloff: options.fuzziness ?? 20,
|
|
2706
|
+
sampleMerged: options.sampleMerged,
|
|
2707
|
+
sample: options.sample
|
|
2708
|
+
});
|
|
2709
|
+
} catch (err) {
|
|
2710
|
+
setRangeStatus(err instanceof Error ? err.message : String(err));
|
|
2711
|
+
}
|
|
2712
|
+
};
|
|
2634
2713
|
const [subject, setSubject] = useState11("");
|
|
2635
2714
|
const [segmenting, setSegmenting] = useState11(false);
|
|
2636
2715
|
const [subjectStatus, setSubjectStatus] = useState11(null);
|
|
@@ -2663,6 +2742,21 @@ var SelectionOptionsBar = ({
|
|
|
2663
2742
|
/* @__PURE__ */ jsx15(ImageCheckbox, { label: "Contiguous", checked: options.contiguous, onChange: (on) => set({ contiguous: on }) }),
|
|
2664
2743
|
"Contiguous"
|
|
2665
2744
|
] }),
|
|
2745
|
+
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
2746
|
+
"Distance",
|
|
2747
|
+
/* @__PURE__ */ jsx15(
|
|
2748
|
+
ImageSelect,
|
|
2749
|
+
{
|
|
2750
|
+
label: "Colour distance",
|
|
2751
|
+
value: options.distance,
|
|
2752
|
+
options: [
|
|
2753
|
+
{ value: "rgb", label: "RGB" },
|
|
2754
|
+
{ value: "perceptual", label: "Perceptual" }
|
|
2755
|
+
],
|
|
2756
|
+
onChange: (v) => set({ distance: v })
|
|
2757
|
+
}
|
|
2758
|
+
)
|
|
2759
|
+
] }),
|
|
2666
2760
|
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
2667
2761
|
/* @__PURE__ */ jsx15(ImageCheckbox, { label: "Sample adjusted image", checked: options.sampleMerged, onChange: (on) => set({ sampleMerged: on }) }),
|
|
2668
2762
|
"Sample adjusted image"
|
|
@@ -2683,6 +2777,67 @@ var SelectionOptionsBar = ({
|
|
|
2683
2777
|
)
|
|
2684
2778
|
] })
|
|
2685
2779
|
] }),
|
|
2780
|
+
options.tool === "polygon" && /* @__PURE__ */ jsx15("p", { className: "text-muted-foreground", children: "Click to add corners (Shift for 45\xB0), drag for a free-hand stretch; double-click, Enter or a click on the first corner closes it, Backspace removes a corner, Escape cancels." }),
|
|
2781
|
+
options.tool === "range" && /* @__PURE__ */ jsxs13("div", { "data-testid": "color-range-options", className: "flex flex-col gap-2", children: [
|
|
2782
|
+
/* @__PURE__ */ jsx15("p", { className: "text-muted-foreground", children: "Click a colour to select it; Shift-click adds a colour, Alt-click removes one." }),
|
|
2783
|
+
/* @__PURE__ */ jsxs13("label", { className: "flex flex-col gap-1", children: [
|
|
2784
|
+
/* @__PURE__ */ jsxs13("span", { className: "flex justify-between text-muted-foreground", children: [
|
|
2785
|
+
/* @__PURE__ */ jsx15("span", { children: "Fuzziness" }),
|
|
2786
|
+
/* @__PURE__ */ jsx15("span", { className: "font-mono", children: options.fuzziness ?? 40 })
|
|
2787
|
+
] }),
|
|
2788
|
+
/* @__PURE__ */ jsx15(ImageRange, { label: "Fuzziness", min: 0, max: 200, step: 1, value: options.fuzziness ?? 40, onChange: (v) => set({ fuzziness: v }) })
|
|
2789
|
+
] }),
|
|
2790
|
+
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
2791
|
+
"Localized radius",
|
|
2792
|
+
/* @__PURE__ */ jsx15(
|
|
2793
|
+
"input",
|
|
2794
|
+
{
|
|
2795
|
+
type: "number",
|
|
2796
|
+
min: 0,
|
|
2797
|
+
step: 1,
|
|
2798
|
+
"aria-label": "Localized radius",
|
|
2799
|
+
value: options.localized ?? 0,
|
|
2800
|
+
onChange: (e) => set({ localized: Math.max(0, Number(e.target.value) || 0) }),
|
|
2801
|
+
className: numberInput
|
|
2802
|
+
}
|
|
2803
|
+
),
|
|
2804
|
+
"px"
|
|
2805
|
+
] }),
|
|
2806
|
+
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
2807
|
+
/* @__PURE__ */ jsx15(ImageCheckbox, { label: "Invert", checked: options.rangeInvert ?? false, onChange: (on) => set({ rangeInvert: on }) }),
|
|
2808
|
+
"Invert"
|
|
2809
|
+
] }),
|
|
2810
|
+
/* @__PURE__ */ jsxs13("div", { className: "flex items-center gap-1", children: [
|
|
2811
|
+
/* @__PURE__ */ jsx15(
|
|
2812
|
+
ImageSelect,
|
|
2813
|
+
{
|
|
2814
|
+
label: "Color Range preset",
|
|
2815
|
+
value: preset,
|
|
2816
|
+
options: COLOR_RANGE_PRESETS.map((p) => ({ value: p, label: COLOR_RANGE_PRESET_LABELS[p] })),
|
|
2817
|
+
onChange: (v) => setPreset(v)
|
|
2818
|
+
}
|
|
2819
|
+
),
|
|
2820
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => void applyPreset(), children: "Select" })
|
|
2821
|
+
] }),
|
|
2822
|
+
rangeStatus && /* @__PURE__ */ jsx15("p", { role: "status", className: "text-muted-foreground", children: rangeStatus })
|
|
2823
|
+
] }),
|
|
2824
|
+
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
2825
|
+
"Feather",
|
|
2826
|
+
/* @__PURE__ */ jsx15(
|
|
2827
|
+
"input",
|
|
2828
|
+
{
|
|
2829
|
+
type: "number",
|
|
2830
|
+
min: 0,
|
|
2831
|
+
max: 1e3,
|
|
2832
|
+
step: 0.5,
|
|
2833
|
+
"aria-label": "Feather",
|
|
2834
|
+
value: options.feather ?? 0,
|
|
2835
|
+
onChange: (e) => set({ feather: Math.max(0, Number(e.target.value) || 0) }),
|
|
2836
|
+
className: numberInput
|
|
2837
|
+
}
|
|
2838
|
+
),
|
|
2839
|
+
"px"
|
|
2840
|
+
] }),
|
|
2686
2841
|
controller.segmentationProvider && /* @__PURE__ */ jsxs13(
|
|
2687
2842
|
"form",
|
|
2688
2843
|
{
|
|
@@ -2720,7 +2875,13 @@ var SelectionOptionsBar = ({
|
|
|
2720
2875
|
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => controller.selectAll(), children: "Select All" }),
|
|
2721
2876
|
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => controller.deselect(), children: "Deselect" }),
|
|
2722
2877
|
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => controller.invertSelection(), children: "Inverse" }),
|
|
2723
|
-
/* @__PURE__ */ jsx15("button", { type: "button",
|
|
2878
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !controller.canReselect(), onClick: () => controller.reselect(), children: "Reselect" }),
|
|
2879
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, title: "Add connected pixels of a selected colour (wand tolerance)", onClick: () => void runColor("grow"), children: "Grow" }),
|
|
2880
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, title: "Add every pixel of a selected colour (wand tolerance)", onClick: () => void runColor("similar"), children: "Similar" })
|
|
2881
|
+
] }),
|
|
2882
|
+
/* @__PURE__ */ jsxs13("div", { role: "group", "aria-label": "Show selection", className: "flex flex-wrap items-center gap-1", children: [
|
|
2883
|
+
/* @__PURE__ */ jsx15("span", { className: "text-muted-foreground", children: "Show" }),
|
|
2884
|
+
DISPLAYS.map((d) => /* @__PURE__ */ jsx15("button", { type: "button", "aria-pressed": display === d.id, className: btn(display === d.id), onClick: () => controller.setSelectionDisplay(d.id), children: d.label }, d.id))
|
|
2724
2885
|
] }),
|
|
2725
2886
|
/* @__PURE__ */ jsxs13("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
2726
2887
|
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
@@ -2735,12 +2896,57 @@ var SelectionOptionsBar = ({
|
|
|
2735
2896
|
"aria-label": "Modify radius",
|
|
2736
2897
|
value: radius,
|
|
2737
2898
|
onChange: (e) => setRadius(Math.max(0, Number(e.target.value) || 0)),
|
|
2738
|
-
className:
|
|
2899
|
+
className: numberInput
|
|
2739
2900
|
}
|
|
2740
2901
|
)
|
|
2741
2902
|
] }),
|
|
2742
2903
|
MODIFY_OPS.map(({ op, label }) => /* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => controller.modifySelection(op, radius), children: label }, op))
|
|
2743
2904
|
] }),
|
|
2905
|
+
/* @__PURE__ */ jsxs13("div", { role: "group", "aria-label": "Edit selection", className: "flex flex-wrap items-center gap-1", children: [
|
|
2906
|
+
/* @__PURE__ */ jsxs13("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
2907
|
+
"Stroke",
|
|
2908
|
+
/* @__PURE__ */ jsx15(
|
|
2909
|
+
"input",
|
|
2910
|
+
{
|
|
2911
|
+
type: "number",
|
|
2912
|
+
min: 1,
|
|
2913
|
+
max: 250,
|
|
2914
|
+
step: 1,
|
|
2915
|
+
"aria-label": "Stroke width",
|
|
2916
|
+
value: strokeWidth,
|
|
2917
|
+
onChange: (e) => setStrokeWidth(Math.min(250, Math.max(1, Number(e.target.value) || 1))),
|
|
2918
|
+
className: numberInput
|
|
2919
|
+
}
|
|
2920
|
+
),
|
|
2921
|
+
"px"
|
|
2922
|
+
] }),
|
|
2923
|
+
/* @__PURE__ */ jsx15(
|
|
2924
|
+
ImageSelect,
|
|
2925
|
+
{
|
|
2926
|
+
label: "Stroke location",
|
|
2927
|
+
value: strokeLocation,
|
|
2928
|
+
options: [
|
|
2929
|
+
{ value: "outside", label: "Outside" },
|
|
2930
|
+
{ value: "center", label: "Center" },
|
|
2931
|
+
{ value: "inside", label: "Inside" }
|
|
2932
|
+
],
|
|
2933
|
+
onChange: (v) => setStrokeLocation(v)
|
|
2934
|
+
}
|
|
2935
|
+
),
|
|
2936
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.strokeSelection({ width: strokeWidth, location: strokeLocation })), children: "Stroke" }),
|
|
2937
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.cropToSelection()), children: "Crop to Selection" }),
|
|
2938
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.contentAwareFill({ output: "new-layer" })), children: "Content-Aware Fill" })
|
|
2939
|
+
] }),
|
|
2940
|
+
/* @__PURE__ */ jsxs13("div", { role: "group", "aria-label": "Clipboard", className: "flex flex-wrap gap-1", children: [
|
|
2941
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.copyPixels()), children: "Copy" }),
|
|
2942
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.copyPixels({ merged: true })), children: "Copy Merged" }),
|
|
2943
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.cutPixels()), children: "Cut" }),
|
|
2944
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.pastePixels("new-layer")), children: "Paste" }),
|
|
2945
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.pastePixels("in-place")), children: "Paste in Place" }),
|
|
2946
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.pastePixels("into")), children: "Paste Into" }),
|
|
2947
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.pastePixels("outside")), children: "Paste Outside" })
|
|
2948
|
+
] }),
|
|
2949
|
+
colorStatus && /* @__PURE__ */ jsx15("p", { role: "status", className: "text-muted-foreground", children: colorStatus }),
|
|
2744
2950
|
/* @__PURE__ */ jsx15("p", { "data-testid": "selection-status", className: "text-muted-foreground", children: describeSelection(sel) })
|
|
2745
2951
|
] });
|
|
2746
2952
|
};
|
|
@@ -4080,7 +4286,8 @@ var ImageEditor = ({
|
|
|
4080
4286
|
options: selectionOptions,
|
|
4081
4287
|
onOptionsChange: setSelectionOptions,
|
|
4082
4288
|
selection: state.selection ?? null,
|
|
4083
|
-
quickMask: Boolean(state.quickMask)
|
|
4289
|
+
quickMask: Boolean(state.quickMask),
|
|
4290
|
+
selectionDisplay: state.selectionDisplay
|
|
4084
4291
|
}
|
|
4085
4292
|
),
|
|
4086
4293
|
selectionError && /* @__PURE__ */ jsx20("p", { role: "alert", className: "text-destructive", children: selectionError }),
|
|
@@ -14,7 +14,8 @@ export interface LayersPanelProps {
|
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* The layer stack, top first: visibility, thumbnails, names (double-click to rename), locks,
|
|
17
|
-
* mask thumbnails (click to paint the mask, Shift-click to disable it
|
|
17
|
+
* mask thumbnails (click to paint the mask, Shift-click to disable it, Ctrl/⌘-click to load it
|
|
18
|
+
* as the selection; Ctrl/⌘-click a layer thumbnail to select its pixels), drag to reorder or drop
|
|
18
19
|
* into a group, opacity / fill / blend / clipping for the active layer, and the layer menu
|
|
19
20
|
* (right-click a row, or the ⋯ button), an fx badge on rows with effects (click to switch them
|
|
20
21
|
* on or off) and the active layer's effects. Every action is one undo step on the controller.
|
|
@@ -14,7 +14,8 @@ export interface LayersPanelProps {
|
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* The layer stack, top first: visibility, thumbnails, names (double-click to rename), locks,
|
|
17
|
-
* mask thumbnails (click to paint the mask, Shift-click to disable it
|
|
17
|
+
* mask thumbnails (click to paint the mask, Shift-click to disable it, Ctrl/⌘-click to load it
|
|
18
|
+
* as the selection; Ctrl/⌘-click a layer thumbnail to select its pixels), drag to reorder or drop
|
|
18
19
|
* into a group, opacity / fill / blend / clipping for the active layer, and the layer menu
|
|
19
20
|
* (right-click a row, or the ⋯ button), an fx badge on rows with effects (click to switch them
|
|
20
21
|
* on or off) and the active layer's effects. Every action is one undo step on the controller.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ImageEditorController, SelectionMask, SelectionToolOptions } from '@pixerate/editor/image-editor';
|
|
2
|
+
import type { ImageEditorController, SelectionDisplay, SelectionMask, SelectionToolOptions } from '@pixerate/editor/image-editor';
|
|
3
3
|
export interface SelectionOptionsBarProps {
|
|
4
4
|
controller: ImageEditorController;
|
|
5
5
|
options: SelectionToolOptions;
|
|
@@ -8,12 +8,16 @@ export interface SelectionOptionsBarProps {
|
|
|
8
8
|
selection?: SelectionMask | null;
|
|
9
9
|
/** The current Quick Mask view flag (`state.quickMask`). */
|
|
10
10
|
quickMask?: boolean;
|
|
11
|
+
/** How the canvas shows the selection (`state.selectionDisplay`); wins over `quickMask`. */
|
|
12
|
+
selectionDisplay?: SelectionDisplay;
|
|
11
13
|
className?: string;
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
|
-
* Options bar of the selection tools: tool, mode (new / add / subtract / intersect),
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* Options bar of the selection tools: tool, mode (new / add / subtract / intersect), feather,
|
|
17
|
+
* magic wand tolerance, contiguous and colour distance, Color Range (click to sample, Shift-click
|
|
18
|
+
* to add, Alt-click to remove; fuzziness, localized, invert, presets), anti-alias, sample merged,
|
|
19
|
+
* Select › All / Deselect / Inverse, Modify (grow, shrink, feather, border, smooth) and how the
|
|
20
|
+
* selection shows (marching ants, Quick Mask or hidden). With a segmentation
|
|
17
21
|
* provider on the controller it adds Select › Subject (a description and a button).
|
|
18
22
|
*/
|
|
19
23
|
export declare const SelectionOptionsBar: React.FC<SelectionOptionsBarProps>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ImageEditorController, SelectionMask, SelectionToolOptions } from '@pixerate/editor/image-editor';
|
|
2
|
+
import type { ImageEditorController, SelectionDisplay, SelectionMask, SelectionToolOptions } from '@pixerate/editor/image-editor';
|
|
3
3
|
export interface SelectionOptionsBarProps {
|
|
4
4
|
controller: ImageEditorController;
|
|
5
5
|
options: SelectionToolOptions;
|
|
@@ -8,12 +8,16 @@ export interface SelectionOptionsBarProps {
|
|
|
8
8
|
selection?: SelectionMask | null;
|
|
9
9
|
/** The current Quick Mask view flag (`state.quickMask`). */
|
|
10
10
|
quickMask?: boolean;
|
|
11
|
+
/** How the canvas shows the selection (`state.selectionDisplay`); wins over `quickMask`. */
|
|
12
|
+
selectionDisplay?: SelectionDisplay;
|
|
11
13
|
className?: string;
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
|
-
* Options bar of the selection tools: tool, mode (new / add / subtract / intersect),
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* Options bar of the selection tools: tool, mode (new / add / subtract / intersect), feather,
|
|
17
|
+
* magic wand tolerance, contiguous and colour distance, Color Range (click to sample, Shift-click
|
|
18
|
+
* to add, Alt-click to remove; fuzziness, localized, invert, presets), anti-alias, sample merged,
|
|
19
|
+
* Select › All / Deselect / Inverse, Modify (grow, shrink, feather, border, smooth) and how the
|
|
20
|
+
* selection shows (marching ants, Quick Mask or hidden). With a segmentation
|
|
17
21
|
* provider on the controller it adds Select › Subject (a description and a button).
|
|
18
22
|
*/
|
|
19
23
|
export declare const SelectionOptionsBar: React.FC<SelectionOptionsBarProps>;
|
|
@@ -696,6 +696,26 @@ var ImageEditorCanvas = ({
|
|
|
696
696
|
if (g.error) report("paint", g.error);
|
|
697
697
|
}
|
|
698
698
|
};
|
|
699
|
+
(0, import_react5.useEffect)(() => {
|
|
700
|
+
if (mode !== "select" || typeof window === "undefined") return;
|
|
701
|
+
const onKey = (e) => {
|
|
702
|
+
const target = e.target;
|
|
703
|
+
if (target?.closest?.('input, textarea, select, [contenteditable="true"]')) return;
|
|
704
|
+
if (window.getSelection?.()?.toString()) return;
|
|
705
|
+
const gesture = selectionGestureRef.current;
|
|
706
|
+
if ((0, import_image_editor2.handleSelectionShortcut)(controller, e, (message) => report("select", message))) {
|
|
707
|
+
e.preventDefault();
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (gesture?.key(e.key)) {
|
|
711
|
+
e.preventDefault();
|
|
712
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
713
|
+
void renderCanvas();
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
window.addEventListener("keydown", onKey);
|
|
717
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
718
|
+
});
|
|
699
719
|
(0, import_react5.useEffect)(() => {
|
|
700
720
|
if (mode !== "paint" || typeof window === "undefined") return;
|
|
701
721
|
const onKey = (e) => {
|
|
@@ -711,7 +731,11 @@ var ImageEditorCanvas = ({
|
|
|
711
731
|
if (mode === "select") {
|
|
712
732
|
const gesture = selectionGestureRef.current;
|
|
713
733
|
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
714
|
-
void gesture.begin(imgPt, e).then(() =>
|
|
734
|
+
void gesture.begin(imgPt, e).then(() => {
|
|
735
|
+
report("select", gesture.error);
|
|
736
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
737
|
+
void renderCanvas();
|
|
738
|
+
});
|
|
715
739
|
return;
|
|
716
740
|
}
|
|
717
741
|
if (mode === "crop") {
|
|
@@ -793,7 +817,7 @@ var ImageEditorCanvas = ({
|
|
|
793
817
|
const canvasPt = getCanvasEventPoint(e);
|
|
794
818
|
if (mode === "select") {
|
|
795
819
|
const gesture = selectionGestureRef.current;
|
|
796
|
-
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
|
|
820
|
+
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e)) {
|
|
797
821
|
selectionDraftRef.current = gesture.draftPath;
|
|
798
822
|
renderCanvas();
|
|
799
823
|
}
|
|
@@ -936,7 +960,7 @@ var ImageEditorCanvas = ({
|
|
|
936
960
|
const gesture = selectionGestureRef.current;
|
|
937
961
|
if (gesture.active) {
|
|
938
962
|
gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
|
|
939
|
-
selectionDraftRef.current =
|
|
963
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
940
964
|
renderCanvas();
|
|
941
965
|
}
|
|
942
966
|
return;
|
|
@@ -1445,7 +1469,7 @@ var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram, classN
|
|
|
1445
1469
|
type: "button",
|
|
1446
1470
|
className: "px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1447
1471
|
onClick: () => {
|
|
1448
|
-
setSelectedId(controller.addAdjustmentLayer(newKind));
|
|
1472
|
+
setSelectedId(controller.addAdjustmentLayer({ kind: newKind, useSelection: true }));
|
|
1449
1473
|
setChannel("master");
|
|
1450
1474
|
setRange(-1);
|
|
1451
1475
|
},
|
|
@@ -1998,7 +2022,14 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
1998
2022
|
pixels: thumb(layer),
|
|
1999
2023
|
size: thumbnailSize,
|
|
2000
2024
|
label: `${row.label} pixels`,
|
|
2001
|
-
|
|
2025
|
+
testId: "layer-thumbnail",
|
|
2026
|
+
selected: row.active && state.activeTarget === "pixels" && Boolean(layer.mask),
|
|
2027
|
+
onClick: (e) => {
|
|
2028
|
+
if (e.ctrlKey || e.metaKey) {
|
|
2029
|
+
e.stopPropagation();
|
|
2030
|
+
attempt(() => (0, import_image_editor8.layerThumbnailClick)(controller, layer, e));
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2002
2033
|
}
|
|
2003
2034
|
),
|
|
2004
2035
|
layer.type !== "pixel" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
@@ -2043,8 +2074,7 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
2043
2074
|
selected: row.active && state.activeTarget === "mask",
|
|
2044
2075
|
onClick: (e) => {
|
|
2045
2076
|
e.stopPropagation();
|
|
2046
|
-
|
|
2047
|
-
else attempt(() => controller.setActiveLayer(layer.id, "mask"));
|
|
2077
|
+
attempt(() => (0, import_image_editor8.maskThumbnailClick)(controller, layer, e));
|
|
2048
2078
|
}
|
|
2049
2079
|
}
|
|
2050
2080
|
),
|
|
@@ -4116,7 +4146,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
4116
4146
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "flex-1 font-semibold uppercase tracking-wider text-[11px] text-foreground", children: "Filters" }),
|
|
4117
4147
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: imageOutlineButtonClass, "aria-pressed": browse === "filter", onClick: () => setBrowse(browse === "filter" ? null : "filter"), children: "Add filter\u2026" })
|
|
4118
4148
|
] }),
|
|
4119
|
-
browse === "filter" && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id))) }),
|
|
4149
|
+
browse === "filter" && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id, { useSelection: true }))) }),
|
|
4120
4150
|
filters.length > 0 && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("ol", { className: "space-y-1", "data-effect-part": "filters", "aria-label": "Filters", children: filters.map((f) => {
|
|
4121
4151
|
const label = f.kind === "effect" ? f.name ?? f.effect : f.kind;
|
|
4122
4152
|
const all = layer.smartFilters.filters;
|
|
@@ -4551,12 +4581,18 @@ var import_react25 = require("react");
|
|
|
4551
4581
|
var import_image_editor14 = require("@pixerate/editor/image-editor");
|
|
4552
4582
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
4553
4583
|
var MODIFY_OPS = [
|
|
4554
|
-
{ op: "
|
|
4555
|
-
{ op: "
|
|
4584
|
+
{ op: "expand", label: "Expand" },
|
|
4585
|
+
{ op: "contract", label: "Contract" },
|
|
4556
4586
|
{ op: "feather", label: "Feather" },
|
|
4557
4587
|
{ op: "border", label: "Border" },
|
|
4558
4588
|
{ op: "smooth", label: "Smooth" }
|
|
4559
4589
|
];
|
|
4590
|
+
var DISPLAYS = [
|
|
4591
|
+
{ id: "ants", label: "Ants" },
|
|
4592
|
+
{ id: "quickMask", label: "Quick Mask" },
|
|
4593
|
+
{ id: "none", label: "Hidden" }
|
|
4594
|
+
];
|
|
4595
|
+
var numberInput = "w-14 bg-background border border-border rounded px-1 py-0.5 text-foreground";
|
|
4560
4596
|
var btn = (on) => `px-2 py-1 rounded-md border text-[11px] transition-colors ${on ? "bg-primary border-primary text-primary-foreground" : "bg-background border-border text-foreground hover:bg-accent hover:text-accent-foreground"}`;
|
|
4561
4597
|
var SelectionOptionsBar = ({
|
|
4562
4598
|
controller,
|
|
@@ -4564,12 +4600,50 @@ var SelectionOptionsBar = ({
|
|
|
4564
4600
|
onOptionsChange,
|
|
4565
4601
|
selection,
|
|
4566
4602
|
quickMask,
|
|
4603
|
+
selectionDisplay,
|
|
4567
4604
|
className = ""
|
|
4568
4605
|
}) => {
|
|
4569
4606
|
const [radius, setRadius] = (0, import_react25.useState)(2);
|
|
4570
4607
|
const set = (patch) => onOptionsChange({ ...options, ...patch });
|
|
4571
4608
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
4572
|
-
const
|
|
4609
|
+
const display = selectionDisplay ?? (quickMask === void 0 ? controller.getSelectionDisplay() : quickMask ? "quickMask" : "ants");
|
|
4610
|
+
const [preset, setPreset] = (0, import_react25.useState)("reds");
|
|
4611
|
+
const [rangeStatus, setRangeStatus] = (0, import_react25.useState)(null);
|
|
4612
|
+
const [colorStatus, setColorStatus] = (0, import_react25.useState)(null);
|
|
4613
|
+
const [strokeWidth, setStrokeWidth] = (0, import_react25.useState)(4);
|
|
4614
|
+
const [strokeLocation, setStrokeLocation] = (0, import_react25.useState)("outside");
|
|
4615
|
+
const edit = (fn) => {
|
|
4616
|
+
setColorStatus(null);
|
|
4617
|
+
try {
|
|
4618
|
+
fn();
|
|
4619
|
+
} catch (err) {
|
|
4620
|
+
setColorStatus(err instanceof Error ? err.message : String(err));
|
|
4621
|
+
}
|
|
4622
|
+
};
|
|
4623
|
+
const runColor = async (op) => {
|
|
4624
|
+
setColorStatus(null);
|
|
4625
|
+
const opts = { tolerance: options.tolerance, sampleMerged: options.sampleMerged, sample: options.sample };
|
|
4626
|
+
try {
|
|
4627
|
+
await (op === "grow" ? controller.growSelection(opts) : controller.selectSimilar(opts));
|
|
4628
|
+
} catch (err) {
|
|
4629
|
+
setColorStatus(err instanceof Error ? err.message : String(err));
|
|
4630
|
+
}
|
|
4631
|
+
};
|
|
4632
|
+
const applyPreset = async () => {
|
|
4633
|
+
setRangeStatus(null);
|
|
4634
|
+
try {
|
|
4635
|
+
await controller.selectColorRangePreset(preset, {
|
|
4636
|
+
mode: options.mode,
|
|
4637
|
+
feather: options.feather ?? 0,
|
|
4638
|
+
invert: options.rangeInvert ?? false,
|
|
4639
|
+
falloff: options.fuzziness ?? 20,
|
|
4640
|
+
sampleMerged: options.sampleMerged,
|
|
4641
|
+
sample: options.sample
|
|
4642
|
+
});
|
|
4643
|
+
} catch (err) {
|
|
4644
|
+
setRangeStatus(err instanceof Error ? err.message : String(err));
|
|
4645
|
+
}
|
|
4646
|
+
};
|
|
4573
4647
|
const [subject, setSubject] = (0, import_react25.useState)("");
|
|
4574
4648
|
const [segmenting, setSegmenting] = (0, import_react25.useState)(false);
|
|
4575
4649
|
const [subjectStatus, setSubjectStatus] = (0, import_react25.useState)(null);
|
|
@@ -4602,6 +4676,21 @@ var SelectionOptionsBar = ({
|
|
|
4602
4676
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageCheckbox, { label: "Contiguous", checked: options.contiguous, onChange: (on) => set({ contiguous: on }) }),
|
|
4603
4677
|
"Contiguous"
|
|
4604
4678
|
] }),
|
|
4679
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
4680
|
+
"Distance",
|
|
4681
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4682
|
+
ImageSelect,
|
|
4683
|
+
{
|
|
4684
|
+
label: "Colour distance",
|
|
4685
|
+
value: options.distance,
|
|
4686
|
+
options: [
|
|
4687
|
+
{ value: "rgb", label: "RGB" },
|
|
4688
|
+
{ value: "perceptual", label: "Perceptual" }
|
|
4689
|
+
],
|
|
4690
|
+
onChange: (v) => set({ distance: v })
|
|
4691
|
+
}
|
|
4692
|
+
)
|
|
4693
|
+
] }),
|
|
4605
4694
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
4606
4695
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageCheckbox, { label: "Sample adjusted image", checked: options.sampleMerged, onChange: (on) => set({ sampleMerged: on }) }),
|
|
4607
4696
|
"Sample adjusted image"
|
|
@@ -4622,6 +4711,67 @@ var SelectionOptionsBar = ({
|
|
|
4622
4711
|
)
|
|
4623
4712
|
] })
|
|
4624
4713
|
] }),
|
|
4714
|
+
options.tool === "polygon" && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "text-muted-foreground", children: "Click to add corners (Shift for 45\xB0), drag for a free-hand stretch; double-click, Enter or a click on the first corner closes it, Backspace removes a corner, Escape cancels." }),
|
|
4715
|
+
options.tool === "range" && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { "data-testid": "color-range-options", className: "flex flex-col gap-2", children: [
|
|
4716
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "text-muted-foreground", children: "Click a colour to select it; Shift-click adds a colour, Alt-click removes one." }),
|
|
4717
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex flex-col gap-1", children: [
|
|
4718
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("span", { className: "flex justify-between text-muted-foreground", children: [
|
|
4719
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { children: "Fuzziness" }),
|
|
4720
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "font-mono", children: options.fuzziness ?? 40 })
|
|
4721
|
+
] }),
|
|
4722
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageRange, { label: "Fuzziness", min: 0, max: 200, step: 1, value: options.fuzziness ?? 40, onChange: (v) => set({ fuzziness: v }) })
|
|
4723
|
+
] }),
|
|
4724
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
4725
|
+
"Localized radius",
|
|
4726
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4727
|
+
"input",
|
|
4728
|
+
{
|
|
4729
|
+
type: "number",
|
|
4730
|
+
min: 0,
|
|
4731
|
+
step: 1,
|
|
4732
|
+
"aria-label": "Localized radius",
|
|
4733
|
+
value: options.localized ?? 0,
|
|
4734
|
+
onChange: (e) => set({ localized: Math.max(0, Number(e.target.value) || 0) }),
|
|
4735
|
+
className: numberInput
|
|
4736
|
+
}
|
|
4737
|
+
),
|
|
4738
|
+
"px"
|
|
4739
|
+
] }),
|
|
4740
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
4741
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageCheckbox, { label: "Invert", checked: options.rangeInvert ?? false, onChange: (on) => set({ rangeInvert: on }) }),
|
|
4742
|
+
"Invert"
|
|
4743
|
+
] }),
|
|
4744
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
4745
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4746
|
+
ImageSelect,
|
|
4747
|
+
{
|
|
4748
|
+
label: "Color Range preset",
|
|
4749
|
+
value: preset,
|
|
4750
|
+
options: import_image_editor14.COLOR_RANGE_PRESETS.map((p) => ({ value: p, label: import_image_editor14.COLOR_RANGE_PRESET_LABELS[p] })),
|
|
4751
|
+
onChange: (v) => setPreset(v)
|
|
4752
|
+
}
|
|
4753
|
+
),
|
|
4754
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => void applyPreset(), children: "Select" })
|
|
4755
|
+
] }),
|
|
4756
|
+
rangeStatus && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { role: "status", className: "text-muted-foreground", children: rangeStatus })
|
|
4757
|
+
] }),
|
|
4758
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
4759
|
+
"Feather",
|
|
4760
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4761
|
+
"input",
|
|
4762
|
+
{
|
|
4763
|
+
type: "number",
|
|
4764
|
+
min: 0,
|
|
4765
|
+
max: 1e3,
|
|
4766
|
+
step: 0.5,
|
|
4767
|
+
"aria-label": "Feather",
|
|
4768
|
+
value: options.feather ?? 0,
|
|
4769
|
+
onChange: (e) => set({ feather: Math.max(0, Number(e.target.value) || 0) }),
|
|
4770
|
+
className: numberInput
|
|
4771
|
+
}
|
|
4772
|
+
),
|
|
4773
|
+
"px"
|
|
4774
|
+
] }),
|
|
4625
4775
|
controller.segmentationProvider && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4626
4776
|
"form",
|
|
4627
4777
|
{
|
|
@@ -4659,7 +4809,13 @@ var SelectionOptionsBar = ({
|
|
|
4659
4809
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => controller.selectAll(), children: "Select All" }),
|
|
4660
4810
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => controller.deselect(), children: "Deselect" }),
|
|
4661
4811
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => controller.invertSelection(), children: "Inverse" }),
|
|
4662
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button",
|
|
4812
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !controller.canReselect(), onClick: () => controller.reselect(), children: "Reselect" }),
|
|
4813
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, title: "Add connected pixels of a selected colour (wand tolerance)", onClick: () => void runColor("grow"), children: "Grow" }),
|
|
4814
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, title: "Add every pixel of a selected colour (wand tolerance)", onClick: () => void runColor("similar"), children: "Similar" })
|
|
4815
|
+
] }),
|
|
4816
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { role: "group", "aria-label": "Show selection", className: "flex flex-wrap items-center gap-1", children: [
|
|
4817
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "text-muted-foreground", children: "Show" }),
|
|
4818
|
+
DISPLAYS.map((d) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", "aria-pressed": display === d.id, className: btn(display === d.id), onClick: () => controller.setSelectionDisplay(d.id), children: d.label }, d.id))
|
|
4663
4819
|
] }),
|
|
4664
4820
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
4665
4821
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
@@ -4674,12 +4830,57 @@ var SelectionOptionsBar = ({
|
|
|
4674
4830
|
"aria-label": "Modify radius",
|
|
4675
4831
|
value: radius,
|
|
4676
4832
|
onChange: (e) => setRadius(Math.max(0, Number(e.target.value) || 0)),
|
|
4677
|
-
className:
|
|
4833
|
+
className: numberInput
|
|
4678
4834
|
}
|
|
4679
4835
|
)
|
|
4680
4836
|
] }),
|
|
4681
4837
|
MODIFY_OPS.map(({ op, label }) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => controller.modifySelection(op, radius), children: label }, op))
|
|
4682
4838
|
] }),
|
|
4839
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { role: "group", "aria-label": "Edit selection", className: "flex flex-wrap items-center gap-1", children: [
|
|
4840
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
4841
|
+
"Stroke",
|
|
4842
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4843
|
+
"input",
|
|
4844
|
+
{
|
|
4845
|
+
type: "number",
|
|
4846
|
+
min: 1,
|
|
4847
|
+
max: 250,
|
|
4848
|
+
step: 1,
|
|
4849
|
+
"aria-label": "Stroke width",
|
|
4850
|
+
value: strokeWidth,
|
|
4851
|
+
onChange: (e) => setStrokeWidth(Math.min(250, Math.max(1, Number(e.target.value) || 1))),
|
|
4852
|
+
className: numberInput
|
|
4853
|
+
}
|
|
4854
|
+
),
|
|
4855
|
+
"px"
|
|
4856
|
+
] }),
|
|
4857
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4858
|
+
ImageSelect,
|
|
4859
|
+
{
|
|
4860
|
+
label: "Stroke location",
|
|
4861
|
+
value: strokeLocation,
|
|
4862
|
+
options: [
|
|
4863
|
+
{ value: "outside", label: "Outside" },
|
|
4864
|
+
{ value: "center", label: "Center" },
|
|
4865
|
+
{ value: "inside", label: "Inside" }
|
|
4866
|
+
],
|
|
4867
|
+
onChange: (v) => setStrokeLocation(v)
|
|
4868
|
+
}
|
|
4869
|
+
),
|
|
4870
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.strokeSelection({ width: strokeWidth, location: strokeLocation })), children: "Stroke" }),
|
|
4871
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.cropToSelection()), children: "Crop to Selection" }),
|
|
4872
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.contentAwareFill({ output: "new-layer" })), children: "Content-Aware Fill" })
|
|
4873
|
+
] }),
|
|
4874
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { role: "group", "aria-label": "Clipboard", className: "flex flex-wrap gap-1", children: [
|
|
4875
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.copyPixels()), children: "Copy" }),
|
|
4876
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.copyPixels({ merged: true })), children: "Copy Merged" }),
|
|
4877
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.cutPixels()), children: "Cut" }),
|
|
4878
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.pastePixels("new-layer")), children: "Paste" }),
|
|
4879
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.pastePixels("in-place")), children: "Paste in Place" }),
|
|
4880
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.pastePixels("into")), children: "Paste Into" }),
|
|
4881
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.pastePixels("outside")), children: "Paste Outside" })
|
|
4882
|
+
] }),
|
|
4883
|
+
colorStatus && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { role: "status", className: "text-muted-foreground", children: colorStatus }),
|
|
4683
4884
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { "data-testid": "selection-status", className: "text-muted-foreground", children: (0, import_image_editor14.describeSelection)(sel) })
|
|
4684
4885
|
] });
|
|
4685
4886
|
};
|
|
@@ -6014,7 +6215,8 @@ var ImageEditor = ({
|
|
|
6014
6215
|
options: selectionOptions,
|
|
6015
6216
|
onOptionsChange: setSelectionOptions,
|
|
6016
6217
|
selection: state.selection ?? null,
|
|
6017
|
-
quickMask: Boolean(state.quickMask)
|
|
6218
|
+
quickMask: Boolean(state.quickMask),
|
|
6219
|
+
selectionDisplay: state.selectionDisplay
|
|
6018
6220
|
}
|
|
6019
6221
|
),
|
|
6020
6222
|
selectionError && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("p", { role: "alert", className: "text-destructive", children: selectionError }),
|
package/dist/index.cjs
CHANGED
|
@@ -4410,6 +4410,26 @@ var ImageEditorCanvas = ({
|
|
|
4410
4410
|
if (g.error) report("paint", g.error);
|
|
4411
4411
|
}
|
|
4412
4412
|
};
|
|
4413
|
+
(0, import_react41.useEffect)(() => {
|
|
4414
|
+
if (mode !== "select" || typeof window === "undefined") return;
|
|
4415
|
+
const onKey = (e) => {
|
|
4416
|
+
const target = e.target;
|
|
4417
|
+
if (target?.closest?.('input, textarea, select, [contenteditable="true"]')) return;
|
|
4418
|
+
if (window.getSelection?.()?.toString()) return;
|
|
4419
|
+
const gesture = selectionGestureRef.current;
|
|
4420
|
+
if ((0, import_image_editor2.handleSelectionShortcut)(controller, e, (message2) => report("select", message2))) {
|
|
4421
|
+
e.preventDefault();
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
if (gesture?.key(e.key)) {
|
|
4425
|
+
e.preventDefault();
|
|
4426
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
4427
|
+
void renderCanvas();
|
|
4428
|
+
}
|
|
4429
|
+
};
|
|
4430
|
+
window.addEventListener("keydown", onKey);
|
|
4431
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
4432
|
+
});
|
|
4413
4433
|
(0, import_react41.useEffect)(() => {
|
|
4414
4434
|
if (mode !== "paint" || typeof window === "undefined") return;
|
|
4415
4435
|
const onKey = (e) => {
|
|
@@ -4425,7 +4445,11 @@ var ImageEditorCanvas = ({
|
|
|
4425
4445
|
if (mode === "select") {
|
|
4426
4446
|
const gesture = selectionGestureRef.current;
|
|
4427
4447
|
const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
|
|
4428
|
-
void gesture.begin(imgPt, e).then(() =>
|
|
4448
|
+
void gesture.begin(imgPt, e).then(() => {
|
|
4449
|
+
report("select", gesture.error);
|
|
4450
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
4451
|
+
void renderCanvas();
|
|
4452
|
+
});
|
|
4429
4453
|
return;
|
|
4430
4454
|
}
|
|
4431
4455
|
if (mode === "crop") {
|
|
@@ -4507,7 +4531,7 @@ var ImageEditorCanvas = ({
|
|
|
4507
4531
|
const canvasPt = getCanvasEventPoint(e);
|
|
4508
4532
|
if (mode === "select") {
|
|
4509
4533
|
const gesture = selectionGestureRef.current;
|
|
4510
|
-
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
|
|
4534
|
+
if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e)) {
|
|
4511
4535
|
selectionDraftRef.current = gesture.draftPath;
|
|
4512
4536
|
renderCanvas();
|
|
4513
4537
|
}
|
|
@@ -4650,7 +4674,7 @@ var ImageEditorCanvas = ({
|
|
|
4650
4674
|
const gesture = selectionGestureRef.current;
|
|
4651
4675
|
if (gesture.active) {
|
|
4652
4676
|
gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
|
|
4653
|
-
selectionDraftRef.current =
|
|
4677
|
+
selectionDraftRef.current = gesture.draftPath;
|
|
4654
4678
|
renderCanvas();
|
|
4655
4679
|
}
|
|
4656
4680
|
return;
|
|
@@ -5159,7 +5183,7 @@ var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram, classN
|
|
|
5159
5183
|
type: "button",
|
|
5160
5184
|
className: "px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90",
|
|
5161
5185
|
onClick: () => {
|
|
5162
|
-
setSelectedId(controller.addAdjustmentLayer(newKind));
|
|
5186
|
+
setSelectedId(controller.addAdjustmentLayer({ kind: newKind, useSelection: true }));
|
|
5163
5187
|
setChannel("master");
|
|
5164
5188
|
setRange(-1);
|
|
5165
5189
|
},
|
|
@@ -5712,7 +5736,14 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
5712
5736
|
pixels: thumb(layer),
|
|
5713
5737
|
size: thumbnailSize,
|
|
5714
5738
|
label: `${row.label} pixels`,
|
|
5715
|
-
|
|
5739
|
+
testId: "layer-thumbnail",
|
|
5740
|
+
selected: row.active && state.activeTarget === "pixels" && Boolean(layer.mask),
|
|
5741
|
+
onClick: (e) => {
|
|
5742
|
+
if (e.ctrlKey || e.metaKey) {
|
|
5743
|
+
e.stopPropagation();
|
|
5744
|
+
attempt(() => (0, import_image_editor8.layerThumbnailClick)(controller, layer, e));
|
|
5745
|
+
}
|
|
5746
|
+
}
|
|
5716
5747
|
}
|
|
5717
5748
|
),
|
|
5718
5749
|
layer.type !== "pixel" && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
@@ -5757,8 +5788,7 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
5757
5788
|
selected: row.active && state.activeTarget === "mask",
|
|
5758
5789
|
onClick: (e) => {
|
|
5759
5790
|
e.stopPropagation();
|
|
5760
|
-
|
|
5761
|
-
else attempt(() => controller.setActiveLayer(layer.id, "mask"));
|
|
5791
|
+
attempt(() => (0, import_image_editor8.maskThumbnailClick)(controller, layer, e));
|
|
5762
5792
|
}
|
|
5763
5793
|
}
|
|
5764
5794
|
),
|
|
@@ -7830,7 +7860,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
7830
7860
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "flex-1 font-semibold uppercase tracking-wider text-[11px] text-foreground", children: "Filters" }),
|
|
7831
7861
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("button", { type: "button", className: imageOutlineButtonClass, "aria-pressed": browse === "filter", onClick: () => setBrowse(browse === "filter" ? null : "filter"), children: "Add filter\u2026" })
|
|
7832
7862
|
] }),
|
|
7833
|
-
browse === "filter" && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id))) }),
|
|
7863
|
+
browse === "filter" && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id, { useSelection: true }))) }),
|
|
7834
7864
|
filters.length > 0 && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("ol", { className: "space-y-1", "data-effect-part": "filters", "aria-label": "Filters", children: filters.map((f) => {
|
|
7835
7865
|
const label = f.kind === "effect" ? f.name ?? f.effect : f.kind;
|
|
7836
7866
|
const all = layer.smartFilters.filters;
|
|
@@ -8265,12 +8295,18 @@ var import_react61 = require("react");
|
|
|
8265
8295
|
var import_image_editor14 = require("@pixerate/editor/image-editor");
|
|
8266
8296
|
var import_jsx_runtime41 = require("react/jsx-runtime");
|
|
8267
8297
|
var MODIFY_OPS = [
|
|
8268
|
-
{ op: "
|
|
8269
|
-
{ op: "
|
|
8298
|
+
{ op: "expand", label: "Expand" },
|
|
8299
|
+
{ op: "contract", label: "Contract" },
|
|
8270
8300
|
{ op: "feather", label: "Feather" },
|
|
8271
8301
|
{ op: "border", label: "Border" },
|
|
8272
8302
|
{ op: "smooth", label: "Smooth" }
|
|
8273
8303
|
];
|
|
8304
|
+
var DISPLAYS = [
|
|
8305
|
+
{ id: "ants", label: "Ants" },
|
|
8306
|
+
{ id: "quickMask", label: "Quick Mask" },
|
|
8307
|
+
{ id: "none", label: "Hidden" }
|
|
8308
|
+
];
|
|
8309
|
+
var numberInput = "w-14 bg-background border border-border rounded px-1 py-0.5 text-foreground";
|
|
8274
8310
|
var btn = (on) => `px-2 py-1 rounded-md border text-[11px] transition-colors ${on ? "bg-primary border-primary text-primary-foreground" : "bg-background border-border text-foreground hover:bg-accent hover:text-accent-foreground"}`;
|
|
8275
8311
|
var SelectionOptionsBar = ({
|
|
8276
8312
|
controller,
|
|
@@ -8278,12 +8314,50 @@ var SelectionOptionsBar = ({
|
|
|
8278
8314
|
onOptionsChange,
|
|
8279
8315
|
selection,
|
|
8280
8316
|
quickMask,
|
|
8317
|
+
selectionDisplay,
|
|
8281
8318
|
className = ""
|
|
8282
8319
|
}) => {
|
|
8283
8320
|
const [radius, setRadius] = (0, import_react61.useState)(2);
|
|
8284
8321
|
const set = (patch) => onOptionsChange({ ...options, ...patch });
|
|
8285
8322
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
8286
|
-
const
|
|
8323
|
+
const display = selectionDisplay ?? (quickMask === void 0 ? controller.getSelectionDisplay() : quickMask ? "quickMask" : "ants");
|
|
8324
|
+
const [preset, setPreset] = (0, import_react61.useState)("reds");
|
|
8325
|
+
const [rangeStatus, setRangeStatus] = (0, import_react61.useState)(null);
|
|
8326
|
+
const [colorStatus, setColorStatus] = (0, import_react61.useState)(null);
|
|
8327
|
+
const [strokeWidth, setStrokeWidth] = (0, import_react61.useState)(4);
|
|
8328
|
+
const [strokeLocation, setStrokeLocation] = (0, import_react61.useState)("outside");
|
|
8329
|
+
const edit = (fn) => {
|
|
8330
|
+
setColorStatus(null);
|
|
8331
|
+
try {
|
|
8332
|
+
fn();
|
|
8333
|
+
} catch (err) {
|
|
8334
|
+
setColorStatus(err instanceof Error ? err.message : String(err));
|
|
8335
|
+
}
|
|
8336
|
+
};
|
|
8337
|
+
const runColor = async (op) => {
|
|
8338
|
+
setColorStatus(null);
|
|
8339
|
+
const opts = { tolerance: options.tolerance, sampleMerged: options.sampleMerged, sample: options.sample };
|
|
8340
|
+
try {
|
|
8341
|
+
await (op === "grow" ? controller.growSelection(opts) : controller.selectSimilar(opts));
|
|
8342
|
+
} catch (err) {
|
|
8343
|
+
setColorStatus(err instanceof Error ? err.message : String(err));
|
|
8344
|
+
}
|
|
8345
|
+
};
|
|
8346
|
+
const applyPreset = async () => {
|
|
8347
|
+
setRangeStatus(null);
|
|
8348
|
+
try {
|
|
8349
|
+
await controller.selectColorRangePreset(preset, {
|
|
8350
|
+
mode: options.mode,
|
|
8351
|
+
feather: options.feather ?? 0,
|
|
8352
|
+
invert: options.rangeInvert ?? false,
|
|
8353
|
+
falloff: options.fuzziness ?? 20,
|
|
8354
|
+
sampleMerged: options.sampleMerged,
|
|
8355
|
+
sample: options.sample
|
|
8356
|
+
});
|
|
8357
|
+
} catch (err) {
|
|
8358
|
+
setRangeStatus(err instanceof Error ? err.message : String(err));
|
|
8359
|
+
}
|
|
8360
|
+
};
|
|
8287
8361
|
const [subject, setSubject] = (0, import_react61.useState)("");
|
|
8288
8362
|
const [segmenting, setSegmenting] = (0, import_react61.useState)(false);
|
|
8289
8363
|
const [subjectStatus, setSubjectStatus] = (0, import_react61.useState)(null);
|
|
@@ -8316,6 +8390,21 @@ var SelectionOptionsBar = ({
|
|
|
8316
8390
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ImageCheckbox, { label: "Contiguous", checked: options.contiguous, onChange: (on) => set({ contiguous: on }) }),
|
|
8317
8391
|
"Contiguous"
|
|
8318
8392
|
] }),
|
|
8393
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
8394
|
+
"Distance",
|
|
8395
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
8396
|
+
ImageSelect,
|
|
8397
|
+
{
|
|
8398
|
+
label: "Colour distance",
|
|
8399
|
+
value: options.distance,
|
|
8400
|
+
options: [
|
|
8401
|
+
{ value: "rgb", label: "RGB" },
|
|
8402
|
+
{ value: "perceptual", label: "Perceptual" }
|
|
8403
|
+
],
|
|
8404
|
+
onChange: (v) => set({ distance: v })
|
|
8405
|
+
}
|
|
8406
|
+
)
|
|
8407
|
+
] }),
|
|
8319
8408
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
8320
8409
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ImageCheckbox, { label: "Sample adjusted image", checked: options.sampleMerged, onChange: (on) => set({ sampleMerged: on }) }),
|
|
8321
8410
|
"Sample adjusted image"
|
|
@@ -8336,6 +8425,67 @@ var SelectionOptionsBar = ({
|
|
|
8336
8425
|
)
|
|
8337
8426
|
] })
|
|
8338
8427
|
] }),
|
|
8428
|
+
options.tool === "polygon" && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { className: "text-muted-foreground", children: "Click to add corners (Shift for 45\xB0), drag for a free-hand stretch; double-click, Enter or a click on the first corner closes it, Backspace removes a corner, Escape cancels." }),
|
|
8429
|
+
options.tool === "range" && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { "data-testid": "color-range-options", className: "flex flex-col gap-2", children: [
|
|
8430
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { className: "text-muted-foreground", children: "Click a colour to select it; Shift-click adds a colour, Alt-click removes one." }),
|
|
8431
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex flex-col gap-1", children: [
|
|
8432
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("span", { className: "flex justify-between text-muted-foreground", children: [
|
|
8433
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { children: "Fuzziness" }),
|
|
8434
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "font-mono", children: options.fuzziness ?? 40 })
|
|
8435
|
+
] }),
|
|
8436
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ImageRange, { label: "Fuzziness", min: 0, max: 200, step: 1, value: options.fuzziness ?? 40, onChange: (v) => set({ fuzziness: v }) })
|
|
8437
|
+
] }),
|
|
8438
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
8439
|
+
"Localized radius",
|
|
8440
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
8441
|
+
"input",
|
|
8442
|
+
{
|
|
8443
|
+
type: "number",
|
|
8444
|
+
min: 0,
|
|
8445
|
+
step: 1,
|
|
8446
|
+
"aria-label": "Localized radius",
|
|
8447
|
+
value: options.localized ?? 0,
|
|
8448
|
+
onChange: (e) => set({ localized: Math.max(0, Number(e.target.value) || 0) }),
|
|
8449
|
+
className: numberInput
|
|
8450
|
+
}
|
|
8451
|
+
),
|
|
8452
|
+
"px"
|
|
8453
|
+
] }),
|
|
8454
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-2 text-foreground", children: [
|
|
8455
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ImageCheckbox, { label: "Invert", checked: options.rangeInvert ?? false, onChange: (on) => set({ rangeInvert: on }) }),
|
|
8456
|
+
"Invert"
|
|
8457
|
+
] }),
|
|
8458
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
8459
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
8460
|
+
ImageSelect,
|
|
8461
|
+
{
|
|
8462
|
+
label: "Color Range preset",
|
|
8463
|
+
value: preset,
|
|
8464
|
+
options: import_image_editor14.COLOR_RANGE_PRESETS.map((p) => ({ value: p, label: import_image_editor14.COLOR_RANGE_PRESET_LABELS[p] })),
|
|
8465
|
+
onChange: (v) => setPreset(v)
|
|
8466
|
+
}
|
|
8467
|
+
),
|
|
8468
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => void applyPreset(), children: "Select" })
|
|
8469
|
+
] }),
|
|
8470
|
+
rangeStatus && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { role: "status", className: "text-muted-foreground", children: rangeStatus })
|
|
8471
|
+
] }),
|
|
8472
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
8473
|
+
"Feather",
|
|
8474
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
8475
|
+
"input",
|
|
8476
|
+
{
|
|
8477
|
+
type: "number",
|
|
8478
|
+
min: 0,
|
|
8479
|
+
max: 1e3,
|
|
8480
|
+
step: 0.5,
|
|
8481
|
+
"aria-label": "Feather",
|
|
8482
|
+
value: options.feather ?? 0,
|
|
8483
|
+
onChange: (e) => set({ feather: Math.max(0, Number(e.target.value) || 0) }),
|
|
8484
|
+
className: numberInput
|
|
8485
|
+
}
|
|
8486
|
+
),
|
|
8487
|
+
"px"
|
|
8488
|
+
] }),
|
|
8339
8489
|
controller.segmentationProvider && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
|
|
8340
8490
|
"form",
|
|
8341
8491
|
{
|
|
@@ -8373,7 +8523,13 @@ var SelectionOptionsBar = ({
|
|
|
8373
8523
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => controller.selectAll(), children: "Select All" }),
|
|
8374
8524
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => controller.deselect(), children: "Deselect" }),
|
|
8375
8525
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => controller.invertSelection(), children: "Inverse" }),
|
|
8376
|
-
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button",
|
|
8526
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !controller.canReselect(), onClick: () => controller.reselect(), children: "Reselect" }),
|
|
8527
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, title: "Add connected pixels of a selected colour (wand tolerance)", onClick: () => void runColor("grow"), children: "Grow" }),
|
|
8528
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, title: "Add every pixel of a selected colour (wand tolerance)", onClick: () => void runColor("similar"), children: "Similar" })
|
|
8529
|
+
] }),
|
|
8530
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { role: "group", "aria-label": "Show selection", className: "flex flex-wrap items-center gap-1", children: [
|
|
8531
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "text-muted-foreground", children: "Show" }),
|
|
8532
|
+
DISPLAYS.map((d) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", "aria-pressed": display === d.id, className: btn(display === d.id), onClick: () => controller.setSelectionDisplay(d.id), children: d.label }, d.id))
|
|
8377
8533
|
] }),
|
|
8378
8534
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
8379
8535
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
@@ -8388,12 +8544,57 @@ var SelectionOptionsBar = ({
|
|
|
8388
8544
|
"aria-label": "Modify radius",
|
|
8389
8545
|
value: radius,
|
|
8390
8546
|
onChange: (e) => setRadius(Math.max(0, Number(e.target.value) || 0)),
|
|
8391
|
-
className:
|
|
8547
|
+
className: numberInput
|
|
8392
8548
|
}
|
|
8393
8549
|
)
|
|
8394
8550
|
] }),
|
|
8395
8551
|
MODIFY_OPS.map(({ op, label }) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => controller.modifySelection(op, radius), children: label }, op))
|
|
8396
8552
|
] }),
|
|
8553
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { role: "group", "aria-label": "Edit selection", className: "flex flex-wrap items-center gap-1", children: [
|
|
8554
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("label", { className: "flex items-center gap-1 text-muted-foreground", children: [
|
|
8555
|
+
"Stroke",
|
|
8556
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
8557
|
+
"input",
|
|
8558
|
+
{
|
|
8559
|
+
type: "number",
|
|
8560
|
+
min: 1,
|
|
8561
|
+
max: 250,
|
|
8562
|
+
step: 1,
|
|
8563
|
+
"aria-label": "Stroke width",
|
|
8564
|
+
value: strokeWidth,
|
|
8565
|
+
onChange: (e) => setStrokeWidth(Math.min(250, Math.max(1, Number(e.target.value) || 1))),
|
|
8566
|
+
className: numberInput
|
|
8567
|
+
}
|
|
8568
|
+
),
|
|
8569
|
+
"px"
|
|
8570
|
+
] }),
|
|
8571
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
8572
|
+
ImageSelect,
|
|
8573
|
+
{
|
|
8574
|
+
label: "Stroke location",
|
|
8575
|
+
value: strokeLocation,
|
|
8576
|
+
options: [
|
|
8577
|
+
{ value: "outside", label: "Outside" },
|
|
8578
|
+
{ value: "center", label: "Center" },
|
|
8579
|
+
{ value: "inside", label: "Inside" }
|
|
8580
|
+
],
|
|
8581
|
+
onChange: (v) => setStrokeLocation(v)
|
|
8582
|
+
}
|
|
8583
|
+
),
|
|
8584
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.strokeSelection({ width: strokeWidth, location: strokeLocation })), children: "Stroke" }),
|
|
8585
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.cropToSelection()), children: "Crop to Selection" }),
|
|
8586
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.contentAwareFill({ output: "new-layer" })), children: "Content-Aware Fill" })
|
|
8587
|
+
] }),
|
|
8588
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { role: "group", "aria-label": "Clipboard", className: "flex flex-wrap gap-1", children: [
|
|
8589
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.copyPixels()), children: "Copy" }),
|
|
8590
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.copyPixels({ merged: true })), children: "Copy Merged" }),
|
|
8591
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.cutPixels()), children: "Cut" }),
|
|
8592
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.pastePixels("new-layer")), children: "Paste" }),
|
|
8593
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), onClick: () => edit(() => controller.pastePixels("in-place")), children: "Paste in Place" }),
|
|
8594
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.pastePixels("into")), children: "Paste Into" }),
|
|
8595
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: btn(false), disabled: !sel, onClick: () => edit(() => controller.pastePixels("outside")), children: "Paste Outside" })
|
|
8596
|
+
] }),
|
|
8597
|
+
colorStatus && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { role: "status", className: "text-muted-foreground", children: colorStatus }),
|
|
8397
8598
|
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { "data-testid": "selection-status", className: "text-muted-foreground", children: (0, import_image_editor14.describeSelection)(sel) })
|
|
8398
8599
|
] });
|
|
8399
8600
|
};
|
|
@@ -9728,7 +9929,8 @@ var ImageEditor = ({
|
|
|
9728
9929
|
options: selectionOptions,
|
|
9729
9930
|
onOptionsChange: setSelectionOptions,
|
|
9730
9931
|
selection: state.selection ?? null,
|
|
9731
|
-
quickMask: Boolean(state.quickMask)
|
|
9932
|
+
quickMask: Boolean(state.quickMask),
|
|
9933
|
+
selectionDisplay: state.selectionDisplay
|
|
9732
9934
|
}
|
|
9733
9935
|
),
|
|
9734
9936
|
selectionError && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("p", { role: "alert", className: "text-destructive", children: selectionError }),
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.121.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.
|
|
257
|
+
"@pixerate/editor": ">=0.185.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.
|
|
308
|
+
"@pixerate/editor": "0.185.0"
|
|
309
309
|
},
|
|
310
310
|
"scripts": {
|
|
311
311
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|