@hussmartinez/image-sdk 0.1.0 → 0.3.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/README.md +98 -9
- package/dist/assets/image/render.worker.js +1 -1
- package/dist/element.d.ts +32 -2
- package/dist/element.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/lazy/{inline-worker-BVCwAPZU.js → inline-worker-l_ynDNuS.js} +2 -2
- package/dist/lazy/{inline-worker-BVCwAPZU.js.map → inline-worker-l_ynDNuS.js.map} +1 -1
- package/dist/react.d.ts +85 -2
- package/dist/react.js +1 -1
- package/dist/shared/{core-cKo2m54U.js → core-BWNmXDlB.js} +271 -79
- package/dist/shared/core-BWNmXDlB.js.map +1 -0
- package/dist/shared/{editor-Dv5EU2YJ.js → editor-CJXEK6MY.js} +262 -75
- package/dist/shared/editor-CJXEK6MY.js.map +1 -0
- package/dist/styles.css +126 -19
- package/package.json +8 -7
- package/dist/shared/core-cKo2m54U.js.map +0 -1
- package/dist/shared/editor-Dv5EU2YJ.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as createImageReducer, F as DEVELOP_ADJUSTMENTS, G as placement, I as FILTER_PRESETS, K as createImageProcessor, M as MAX_METADATA_LENGTH, P as longerThan, V as createImageRenderer, _ as outputSize, a as compositionDeltaToSource, c as fitAspect, d as nudgeCropOnScreen, f as wholeCrop, i as aspectRatio, l as handleInSource, n as createImageSession, o as cropInComposition, p as compositionSize, q as createImageEngine, r as ASPECT_PRESETS, s as dragHandle, t as imageMessages,
|
|
1
|
+
import { D as createImageReducer, F as DEVELOP_ADJUSTMENTS, G as placement, I as FILTER_PRESETS, J as engineInternals, K as createImageProcessor, M as MAX_METADATA_LENGTH, P as longerThan, V as createImageRenderer, _ as outputSize, a as compositionDeltaToSource, c as fitAspect, d as nudgeCropOnScreen, f as wholeCrop, i as aspectRatio, l as handleInSource, n as createImageSession, nt as isImageError, o as cropInComposition, p as compositionSize, q as createImageEngine, r as ASPECT_PRESETS, s as dragHandle, t as imageMessages, u as moveCrop } from "./core-BWNmXDlB.js";
|
|
2
2
|
import { applyCommands, createMessages, createShortcutRegistry, createStore, createToolRegistry, defineTool } from "@hussmartinez/sdk-core";
|
|
3
|
-
import { AnnouncerProvider, Button, CropIcon, Dialog, DownloadIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, IconButton, NumberField, OpenIcon, ProgressBar, RedoIcon, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, Slider, Spinner, TextField, Toolbar, ToolbarGroup, UiMessagesProvider, UndoIcon, ZoomInIcon, ZoomOutIcon, useAnnounce, usePlatform } from "@hussmartinez/ui/react";
|
|
3
|
+
import { AnnouncerProvider, Button, CloseIcon, CropIcon, Dialog, DownloadIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, IconButton, NumberField, OpenIcon, ProgressBar, RedoIcon, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, Slider, Spinner, TextField, Toolbar, ToolbarGroup, UiMessagesProvider, UndoIcon, ZoomInIcon, ZoomOutIcon, useAnnounce, usePlatform } from "@hussmartinez/ui/react";
|
|
4
4
|
import { createContext, forwardRef, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
// src/features/tool-types.ts
|
|
@@ -406,6 +406,39 @@ function ImageCropPanel(props) {
|
|
|
406
406
|
]
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
|
+
// src/react/EngineBoundary.tsx
|
|
410
|
+
var usable = () => false;
|
|
411
|
+
var unchanged = () => () => {};
|
|
412
|
+
function EngineBoundary({ children }) {
|
|
413
|
+
const { engine, messages } = useImageInternals();
|
|
414
|
+
const lifecycle = engineInternals(engine);
|
|
415
|
+
const surface = useRef(null);
|
|
416
|
+
const notice = useRef(null);
|
|
417
|
+
const ownedFocus = useRef(null);
|
|
418
|
+
const subscribe = useMemo(() => lifecycle ? (changed) => lifecycle.subscribe(() => {
|
|
419
|
+
const active = document.activeElement;
|
|
420
|
+
ownedFocus.current = active && surface.current?.contains(active) ? active : null;
|
|
421
|
+
changed();
|
|
422
|
+
}) : unchanged, [lifecycle]);
|
|
423
|
+
const terminal = useSyncExternalStore(subscribe, lifecycle?.getSnapshot ?? usable, usable);
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
if (!terminal || !ownedFocus.current) return;
|
|
426
|
+
const active = document.activeElement;
|
|
427
|
+
if (active === document.body || active === ownedFocus.current) notice.current?.focus();
|
|
428
|
+
ownedFocus.current = null;
|
|
429
|
+
}, [terminal]);
|
|
430
|
+
return /* @__PURE__ */ jsx("div", {
|
|
431
|
+
ref: surface,
|
|
432
|
+
className: "hm-image-engine-boundary",
|
|
433
|
+
children: terminal ? /* @__PURE__ */ jsx("p", {
|
|
434
|
+
ref: notice,
|
|
435
|
+
role: "alert",
|
|
436
|
+
tabIndex: -1,
|
|
437
|
+
className: "hm-image-engine-unavailable",
|
|
438
|
+
children: messages.t("editor.engineUnavailable")
|
|
439
|
+
}) : children
|
|
440
|
+
});
|
|
441
|
+
}
|
|
409
442
|
// src/react/export/export-listener.ts
|
|
410
443
|
var ExportListenerContext = createContext(null);
|
|
411
444
|
// src/react/export/ExportDialog.tsx
|
|
@@ -419,13 +452,13 @@ var EXTENSIONS = {
|
|
|
419
452
|
jpeg: "jpg",
|
|
420
453
|
webp: "webp"
|
|
421
454
|
};
|
|
422
|
-
var FIELDS = [
|
|
455
|
+
var FIELDS$1 = [
|
|
423
456
|
"title",
|
|
424
457
|
"description",
|
|
425
458
|
"artist",
|
|
426
459
|
"copyright"
|
|
427
460
|
];
|
|
428
|
-
var KINDS = [
|
|
461
|
+
var KINDS$1 = [
|
|
429
462
|
"location",
|
|
430
463
|
"camera",
|
|
431
464
|
"timestamps",
|
|
@@ -450,7 +483,7 @@ function changes(plan, draft) {
|
|
|
450
483
|
type: "image.setOutput",
|
|
451
484
|
output: draft.output
|
|
452
485
|
});
|
|
453
|
-
for (const field of FIELDS) if (plan.metadata[field] !== draft.metadata[field]) commands.push({
|
|
486
|
+
for (const field of FIELDS$1) if (plan.metadata[field] !== draft.metadata[field]) commands.push({
|
|
454
487
|
type: "image.setMetadata",
|
|
455
488
|
field,
|
|
456
489
|
value: draft.metadata[field]
|
|
@@ -463,6 +496,7 @@ var formatOf = (draft) => draft.format === "png" ? { type: "png" } : {
|
|
|
463
496
|
};
|
|
464
497
|
function ImageExportDialog(props) {
|
|
465
498
|
const { onExport, fileName = "image" } = props;
|
|
499
|
+
const lifecycle = engineInternals(useImageInternals().engine);
|
|
466
500
|
const session = useImageSession();
|
|
467
501
|
const { plan, source } = useImageDocument();
|
|
468
502
|
const [editor, editorStore] = useImageEditorState();
|
|
@@ -536,7 +570,7 @@ function ImageExportDialog(props) {
|
|
|
536
570
|
progress
|
|
537
571
|
} : now)
|
|
538
572
|
});
|
|
539
|
-
if (controller.current !== running) return;
|
|
573
|
+
if (controller.current !== running || lifecycle?.getSnapshot()) return;
|
|
540
574
|
controller.current = null;
|
|
541
575
|
announce(messages.t("export.done", {
|
|
542
576
|
format: formatName(current.format),
|
|
@@ -561,7 +595,7 @@ function ImageExportDialog(props) {
|
|
|
561
595
|
format: current.format
|
|
562
596
|
});
|
|
563
597
|
} catch (reason) {
|
|
564
|
-
if (controller.current !== running) return;
|
|
598
|
+
if (controller.current !== running || lifecycle?.getSnapshot()) return;
|
|
565
599
|
controller.current = null;
|
|
566
600
|
setPhase({ kind: "choose" });
|
|
567
601
|
if (isImageError(reason) && reason.code === "ABORTED") {
|
|
@@ -573,7 +607,7 @@ function ImageExportDialog(props) {
|
|
|
573
607
|
};
|
|
574
608
|
const stop = () => controller.current?.abort();
|
|
575
609
|
const download = () => {
|
|
576
|
-
if (phase.kind !== "done") return;
|
|
610
|
+
if (phase.kind !== "done" || lifecycle?.getSnapshot()) return;
|
|
577
611
|
revoke();
|
|
578
612
|
objectUrl.current = URL.createObjectURL(phase.result.blob);
|
|
579
613
|
const link = document.createElement("a");
|
|
@@ -583,8 +617,8 @@ function ImageExportDialog(props) {
|
|
|
583
617
|
};
|
|
584
618
|
const composition = compositionSize(plan, source);
|
|
585
619
|
const size = outputSize(current.output, composition);
|
|
586
|
-
const removed = KINDS.filter((kind) => source.metadata[kind]);
|
|
587
|
-
const kept = FIELDS.filter((field) => current.metadata[field] !== "");
|
|
620
|
+
const removed = KINDS$1.filter((kind) => source.metadata[kind]);
|
|
621
|
+
const kept = FIELDS$1.filter((field) => current.metadata[field] !== "");
|
|
588
622
|
const exporting = phase.kind === "exporting";
|
|
589
623
|
const footer = phase.kind === "done" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
590
624
|
variant: "secondary",
|
|
@@ -643,13 +677,22 @@ function ImageExportDialog(props) {
|
|
|
643
677
|
current.format === "png" ? null : /* @__PURE__ */ jsx(Field, {
|
|
644
678
|
label: messages.t("export.quality"),
|
|
645
679
|
className: "hm-image-slider-field",
|
|
646
|
-
children: /* @__PURE__ */
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
680
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
681
|
+
className: "hm-image-adjust-row",
|
|
682
|
+
children: [/* @__PURE__ */ jsx(Slider, {
|
|
683
|
+
...control,
|
|
684
|
+
min: 1,
|
|
685
|
+
max: 100,
|
|
686
|
+
step: 1,
|
|
687
|
+
largeStep: 10,
|
|
688
|
+
value: current.quality,
|
|
689
|
+
formatValue: (quality) => messages.t("export.qualityValue", { quality }),
|
|
690
|
+
onValueChange: (quality) => update({ quality: Math.round(quality) })
|
|
691
|
+
}), /* @__PURE__ */ jsx("output", {
|
|
692
|
+
className: "hm-image-adjust-value",
|
|
693
|
+
"aria-hidden": "true",
|
|
694
|
+
children: messages.t("export.qualityValue", { quality: current.quality })
|
|
695
|
+
})]
|
|
653
696
|
})
|
|
654
697
|
}),
|
|
655
698
|
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
@@ -714,7 +757,7 @@ function ImageExportDialog(props) {
|
|
|
714
757
|
}),
|
|
715
758
|
/* @__PURE__ */ jsx("div", {
|
|
716
759
|
className: "hm-image-export-fields",
|
|
717
|
-
children: FIELDS.map((field) => /* @__PURE__ */ jsx(Field, {
|
|
760
|
+
children: FIELDS$1.map((field) => /* @__PURE__ */ jsx(Field, {
|
|
718
761
|
label: messages.t(`export.field.${field}`),
|
|
719
762
|
children: /* @__PURE__ */ jsx(TextField, {
|
|
720
763
|
autoComplete: "off",
|
|
@@ -798,6 +841,9 @@ function own(props) {
|
|
|
798
841
|
};
|
|
799
842
|
}
|
|
800
843
|
function ImageEditorProvider(props) {
|
|
844
|
+
return /* @__PURE__ */ jsx(ImageProvider, { ...props });
|
|
845
|
+
}
|
|
846
|
+
function ImageProvider(props) {
|
|
801
847
|
const { messages: overrides, locale = "en", children } = props;
|
|
802
848
|
const [owned] = useState(() => own(props));
|
|
803
849
|
const [view] = useState(createViewStore);
|
|
@@ -831,7 +877,7 @@ function ImageEditorProvider(props) {
|
|
|
831
877
|
value,
|
|
832
878
|
children: /* @__PURE__ */ jsx(UiMessagesProvider, {
|
|
833
879
|
messages,
|
|
834
|
-
children
|
|
880
|
+
children: props.boundary === false ? children : /* @__PURE__ */ jsx(EngineBoundary, { children })
|
|
835
881
|
})
|
|
836
882
|
});
|
|
837
883
|
}
|
|
@@ -925,7 +971,19 @@ function ImageAdjustPanel(props) {
|
|
|
925
971
|
return /* @__PURE__ */ jsxs("section", {
|
|
926
972
|
className: ["hm-image-adjust-panel", props.className].filter(Boolean).join(" "),
|
|
927
973
|
"aria-label": messages.t("develop.panel"),
|
|
928
|
-
children: [
|
|
974
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
975
|
+
className: "hm-image-adjust-actions",
|
|
976
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
977
|
+
variant: "secondary",
|
|
978
|
+
disabled: changed.length === 0,
|
|
979
|
+
onClick: () => {
|
|
980
|
+
reset(Object.fromEntries(changed.map((name) => [name, 0])));
|
|
981
|
+
first.current?.focus();
|
|
982
|
+
announce(messages.t("develop.wasReset"));
|
|
983
|
+
},
|
|
984
|
+
children: messages.t("develop.resetAll")
|
|
985
|
+
})
|
|
986
|
+
}), DEVELOP_ADJUSTMENTS.map((name, index) => {
|
|
929
987
|
const label = messages.t(`develop.${name}`);
|
|
930
988
|
return /* @__PURE__ */ jsx(Field, {
|
|
931
989
|
label,
|
|
@@ -964,15 +1022,6 @@ function ImageAdjustPanel(props) {
|
|
|
964
1022
|
]
|
|
965
1023
|
})
|
|
966
1024
|
}, name);
|
|
967
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
968
|
-
variant: "secondary",
|
|
969
|
-
disabled: changed.length === 0,
|
|
970
|
-
onClick: () => {
|
|
971
|
-
reset(Object.fromEntries(changed.map((name) => [name, 0])));
|
|
972
|
-
first.current?.focus();
|
|
973
|
-
announce(messages.t("develop.wasReset"));
|
|
974
|
-
},
|
|
975
|
-
children: messages.t("develop.resetAll")
|
|
976
1025
|
})]
|
|
977
1026
|
});
|
|
978
1027
|
}
|
|
@@ -1029,27 +1078,83 @@ function ImageFilterPanel(props) {
|
|
|
1029
1078
|
}) : null]
|
|
1030
1079
|
});
|
|
1031
1080
|
}
|
|
1081
|
+
// src/react/panels/InfoPanel.tsx
|
|
1082
|
+
var KINDS = [
|
|
1083
|
+
"location",
|
|
1084
|
+
"camera",
|
|
1085
|
+
"timestamps",
|
|
1086
|
+
"thumbnail",
|
|
1087
|
+
"colourProfile",
|
|
1088
|
+
"other"
|
|
1089
|
+
];
|
|
1090
|
+
var FIELDS = [
|
|
1091
|
+
"title",
|
|
1092
|
+
"description",
|
|
1093
|
+
"artist",
|
|
1094
|
+
"copyright"
|
|
1095
|
+
];
|
|
1096
|
+
function ImageInfoPanel(props) {
|
|
1097
|
+
const { plan, source } = useImageDocument();
|
|
1098
|
+
const messages = useImageMessages();
|
|
1099
|
+
if (!plan || !source) return null;
|
|
1100
|
+
const carried = KINDS.filter((kind) => source.metadata[kind]);
|
|
1101
|
+
const kept = FIELDS.filter((field) => plan.metadata[field] !== "");
|
|
1102
|
+
return /* @__PURE__ */ jsx("section", {
|
|
1103
|
+
className: ["hm-image-info-panel", props.className].filter(Boolean).join(" "),
|
|
1104
|
+
"aria-label": messages.t("info.panel"),
|
|
1105
|
+
children: /* @__PURE__ */ jsxs("dl", {
|
|
1106
|
+
className: "hm-image-info-list",
|
|
1107
|
+
children: [
|
|
1108
|
+
/* @__PURE__ */ jsx("dt", { children: messages.t("info.size") }),
|
|
1109
|
+
/* @__PURE__ */ jsx("dd", { children: messages.t("info.sizeValue", {
|
|
1110
|
+
width: source.width,
|
|
1111
|
+
height: source.height
|
|
1112
|
+
}) }),
|
|
1113
|
+
/* @__PURE__ */ jsx("dt", { children: messages.t("info.format") }),
|
|
1114
|
+
/* @__PURE__ */ jsx("dd", { children: messages.t(`info.formats.${source.format}`) }),
|
|
1115
|
+
source.frames > 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", { children: messages.t("info.frames") }), /* @__PURE__ */ jsx("dd", { children: source.frames })] }) : null,
|
|
1116
|
+
/* @__PURE__ */ jsx("dt", { children: messages.t("info.fileSize") }),
|
|
1117
|
+
/* @__PURE__ */ jsx("dd", { children: messages.t("info.fileSizeValue", { size: source.fileSize }) }),
|
|
1118
|
+
/* @__PURE__ */ jsx("dt", { children: messages.t("info.metadata") }),
|
|
1119
|
+
/* @__PURE__ */ jsx("dd", { children: carried.length > 0 ? /* @__PURE__ */ jsx("ul", { children: carried.map((kind) => /* @__PURE__ */ jsx("li", { children: messages.t(`export.kind.${kind}`) }, kind)) }) : messages.t("info.metadataNone") }),
|
|
1120
|
+
/* @__PURE__ */ jsx("dt", { children: messages.t("info.kept") }),
|
|
1121
|
+
/* @__PURE__ */ jsx("dd", { children: kept.length > 0 ? /* @__PURE__ */ jsx("ul", { children: kept.map((field) => /* @__PURE__ */ jsx("li", { children: messages.t(`export.field.${field}`) }, field)) }) : messages.t("info.keptNone") })
|
|
1122
|
+
]
|
|
1123
|
+
})
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1032
1126
|
// src/react/panels/Inspector.tsx
|
|
1033
|
-
|
|
1127
|
+
var PANELS = [
|
|
1128
|
+
"adjust",
|
|
1129
|
+
"filters",
|
|
1130
|
+
"info"
|
|
1131
|
+
];
|
|
1132
|
+
function ImageInspector(props) {
|
|
1034
1133
|
const { plan } = useImageDocument();
|
|
1035
1134
|
const [editor] = useImageEditorState();
|
|
1036
1135
|
const messages = useImageMessages();
|
|
1037
|
-
const [
|
|
1136
|
+
const [chosen, setPanel] = useState("adjust");
|
|
1038
1137
|
if (editor.tool === "crop") return /* @__PURE__ */ jsx(ImageCropPanel, {});
|
|
1039
1138
|
if (!plan) return null;
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
label: messages.t("inspector.
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1139
|
+
const panels = PANELS.filter((name) => props.features?.[name] !== false);
|
|
1140
|
+
const first = panels[0];
|
|
1141
|
+
if (first === void 0) return null;
|
|
1142
|
+
const panel = panels.includes(chosen) ? chosen : first;
|
|
1143
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1144
|
+
panels.length > 1 ? /* @__PURE__ */ jsx(SegmentedControl, {
|
|
1145
|
+
label: messages.t("inspector.label"),
|
|
1146
|
+
value: panel,
|
|
1147
|
+
size: "small",
|
|
1148
|
+
options: panels.map((name) => ({
|
|
1149
|
+
value: name,
|
|
1150
|
+
label: messages.t(`inspector.${name}`)
|
|
1151
|
+
})),
|
|
1152
|
+
onValueChange: (value) => setPanel(value)
|
|
1153
|
+
}) : null,
|
|
1154
|
+
panel === "adjust" ? /* @__PURE__ */ jsx(ImageAdjustPanel, {}) : null,
|
|
1155
|
+
panel === "filters" ? /* @__PURE__ */ jsx(ImageFilterPanel, {}) : null,
|
|
1156
|
+
panel === "info" ? /* @__PURE__ */ jsx(ImageInfoPanel, {}) : null
|
|
1157
|
+
] });
|
|
1053
1158
|
}
|
|
1054
1159
|
// src/react/crop/CropFrame.tsx
|
|
1055
1160
|
var HANDLES = [
|
|
@@ -1179,6 +1284,52 @@ function CropFrame(props) {
|
|
|
1179
1284
|
}, handle))]
|
|
1180
1285
|
});
|
|
1181
1286
|
}
|
|
1287
|
+
// src/react/stage/StageNotices.tsx
|
|
1288
|
+
function warningValues(limit, source) {
|
|
1289
|
+
if (limit === "maxFileSize") return { actual: source.fileSize };
|
|
1290
|
+
if (limit === "maxFrames") return { actual: source.frames };
|
|
1291
|
+
return {};
|
|
1292
|
+
}
|
|
1293
|
+
function StageNotices() {
|
|
1294
|
+
const { source, warnings, status } = useImageDocument();
|
|
1295
|
+
const messages = useImageMessages();
|
|
1296
|
+
const id = useId();
|
|
1297
|
+
const [dismissed, setDismissed] = useState(() => /* @__PURE__ */ new Set());
|
|
1298
|
+
if (!source || status !== "ready") return null;
|
|
1299
|
+
const t = messages.t;
|
|
1300
|
+
const notices = [];
|
|
1301
|
+
for (const limit of warnings) {
|
|
1302
|
+
if (limit === "maxSessionSize" || limit === "maxLayers") continue;
|
|
1303
|
+
notices.push({
|
|
1304
|
+
key: `${source.id}:${limit}`,
|
|
1305
|
+
text: t(`warnings.${limit}`, warningValues(limit, source))
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
if (source.metadata.colourProfile) notices.push({
|
|
1309
|
+
key: `${source.id}:colourProfile`,
|
|
1310
|
+
text: messages.t("notices.colourProfile")
|
|
1311
|
+
});
|
|
1312
|
+
const shown = notices.filter((notice) => !dismissed.has(notice.key));
|
|
1313
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1314
|
+
className: "hm-image-stage-notices",
|
|
1315
|
+
role: "status",
|
|
1316
|
+
"aria-label": messages.t("notices.label"),
|
|
1317
|
+
children: shown.length > 0 ? /* @__PURE__ */ jsx("ul", { children: shown.map((notice, index) => /* @__PURE__ */ jsxs("li", {
|
|
1318
|
+
className: "hm-image-stage-notice",
|
|
1319
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1320
|
+
id: `${id}-${index}`,
|
|
1321
|
+
children: notice.text
|
|
1322
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
1323
|
+
label: messages.t("notices.dismiss"),
|
|
1324
|
+
"aria-describedby": `${id}-${index}`,
|
|
1325
|
+
icon: /* @__PURE__ */ jsx(CloseIcon, {}),
|
|
1326
|
+
size: "small",
|
|
1327
|
+
variant: "quiet",
|
|
1328
|
+
onClick: () => setDismissed((before) => new Set(before).add(notice.key))
|
|
1329
|
+
})]
|
|
1330
|
+
}, notice.key)) }) : null
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1182
1333
|
// src/react/stage/ImageStage.tsx
|
|
1183
1334
|
var CROP_INSET = 24;
|
|
1184
1335
|
function useStageSize(element) {
|
|
@@ -1251,12 +1402,15 @@ function ImageStage(props) {
|
|
|
1251
1402
|
frame.append(canvas);
|
|
1252
1403
|
canvasRef.current = canvas;
|
|
1253
1404
|
const renderer = createImageRenderer(engine);
|
|
1254
|
-
const
|
|
1255
|
-
attached.catch(() => {});
|
|
1256
|
-
rendererRef.current = {
|
|
1405
|
+
const current = {
|
|
1257
1406
|
renderer,
|
|
1258
|
-
attached
|
|
1407
|
+
attached: renderer.attach(canvas),
|
|
1408
|
+
failed: false
|
|
1259
1409
|
};
|
|
1410
|
+
current.attached.catch(() => {
|
|
1411
|
+
current.failed = true;
|
|
1412
|
+
});
|
|
1413
|
+
rendererRef.current = current;
|
|
1260
1414
|
return () => {
|
|
1261
1415
|
rendererRef.current = void 0;
|
|
1262
1416
|
canvasRef.current = null;
|
|
@@ -1285,8 +1439,15 @@ function ImageStage(props) {
|
|
|
1285
1439
|
useEffect(() => {
|
|
1286
1440
|
const current = rendererRef.current;
|
|
1287
1441
|
if (!current || !plan || !size || size.width < 1 || size.height < 1) return;
|
|
1288
|
-
const { renderer
|
|
1289
|
-
|
|
1442
|
+
const { renderer } = current;
|
|
1443
|
+
if (current.failed && canvasRef.current) {
|
|
1444
|
+
current.failed = false;
|
|
1445
|
+
current.attached = renderer.attach(canvasRef.current);
|
|
1446
|
+
current.attached.catch(() => {
|
|
1447
|
+
current.failed = true;
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
current.attached.then(() => renderer.render(plan, {
|
|
1290
1451
|
width: size.width,
|
|
1291
1452
|
height: size.height,
|
|
1292
1453
|
pixelRatio: size.pixelRatio,
|
|
@@ -1301,6 +1462,12 @@ function ImageStage(props) {
|
|
|
1301
1462
|
inset
|
|
1302
1463
|
]);
|
|
1303
1464
|
const className = ["hm-image-stage", props.className].filter(Boolean).join(" ");
|
|
1465
|
+
const empty = status === "empty" && !snapshot.opening;
|
|
1466
|
+
const error = snapshot.error ? /* @__PURE__ */ jsx("p", {
|
|
1467
|
+
className: "hm-image-stage-error",
|
|
1468
|
+
role: "alert",
|
|
1469
|
+
children: messages.error(snapshot.error)
|
|
1470
|
+
}) : null;
|
|
1304
1471
|
return /* @__PURE__ */ jsxs("div", {
|
|
1305
1472
|
className,
|
|
1306
1473
|
"data-status": status,
|
|
@@ -1324,7 +1491,7 @@ function ImageStage(props) {
|
|
|
1324
1491
|
}
|
|
1325
1492
|
})
|
|
1326
1493
|
}) : null,
|
|
1327
|
-
|
|
1494
|
+
empty ? /* @__PURE__ */ jsxs(FileDropZone, {
|
|
1328
1495
|
className: "hm-image-stage-drop",
|
|
1329
1496
|
accept: "image/*",
|
|
1330
1497
|
onFiles: (files) => {
|
|
@@ -1333,10 +1500,10 @@ function ImageStage(props) {
|
|
|
1333
1500
|
},
|
|
1334
1501
|
buttonLabel: messages.t("editor.choose"),
|
|
1335
1502
|
hint: messages.t("editor.dropHint"),
|
|
1336
|
-
children: /* @__PURE__ */ jsx("p", {
|
|
1503
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1337
1504
|
className: "hm-image-stage-empty",
|
|
1338
1505
|
children: messages.t("editor.empty")
|
|
1339
|
-
})
|
|
1506
|
+
}), error]
|
|
1340
1507
|
}) : null,
|
|
1341
1508
|
snapshot.opening ? /* @__PURE__ */ jsxs("div", {
|
|
1342
1509
|
className: "hm-image-stage-opening",
|
|
@@ -1346,11 +1513,10 @@ function ImageStage(props) {
|
|
|
1346
1513
|
children: messages.t("editor.cancel")
|
|
1347
1514
|
})]
|
|
1348
1515
|
}) : null,
|
|
1349
|
-
|
|
1350
|
-
className: "hm-image-stage-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
}) : null
|
|
1516
|
+
empty ? null : /* @__PURE__ */ jsxs("div", {
|
|
1517
|
+
className: "hm-image-stage-foot",
|
|
1518
|
+
children: [/* @__PURE__ */ jsx(StageNotices, {}), error]
|
|
1519
|
+
})
|
|
1354
1520
|
]
|
|
1355
1521
|
});
|
|
1356
1522
|
}
|
|
@@ -1406,17 +1572,26 @@ var imageIcons = {
|
|
|
1406
1572
|
var join = (...names) => names.filter(Boolean).join(" ");
|
|
1407
1573
|
function ImageEditorBody(props) {
|
|
1408
1574
|
const { initialFile, onChange, classNames = {}, unstyled = false, handle, events } = props;
|
|
1409
|
-
const { session, messages, view, editor, opener } = useImageInternals();
|
|
1575
|
+
const { engine, session, messages, view, editor, opener } = useImageInternals();
|
|
1410
1576
|
const snapshot = useImageDocument();
|
|
1411
1577
|
const announce = useAnnounce();
|
|
1412
1578
|
const root = useRef(null);
|
|
1413
1579
|
const input = useRef(null);
|
|
1414
1580
|
const latestOnChange = useRef(onChange);
|
|
1415
1581
|
latestOnChange.current = onChange;
|
|
1416
|
-
const
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1582
|
+
const exportOn = props.features?.export !== false;
|
|
1583
|
+
const registry = useMemo(() => {
|
|
1584
|
+
const wanted = (id) => (!props.tools || props.tools.includes(id)) && (exportOn || id !== "image.export");
|
|
1585
|
+
const tools = props.tools ?? imageTools.map((tool) => tool.id);
|
|
1586
|
+
return createToolRegistry(imageTools, {
|
|
1587
|
+
tools: tools.filter(wanted),
|
|
1588
|
+
toolbar: (props.toolbar ?? DEFAULT_TOOLBAR).map((group) => group.filter(wanted)).filter((group) => group.length > 0)
|
|
1589
|
+
});
|
|
1590
|
+
}, [
|
|
1591
|
+
props.tools,
|
|
1592
|
+
props.toolbar,
|
|
1593
|
+
exportOn
|
|
1594
|
+
]);
|
|
1420
1595
|
const platform = usePlatform();
|
|
1421
1596
|
const shortcuts = useMemo(() => createShortcutRegistry({
|
|
1422
1597
|
platform,
|
|
@@ -1438,7 +1613,10 @@ function ImageEditorBody(props) {
|
|
|
1438
1613
|
}), [props.icons]);
|
|
1439
1614
|
useImperativeHandle(handle, () => ({
|
|
1440
1615
|
session,
|
|
1441
|
-
open: (file) =>
|
|
1616
|
+
open: async (file) => {
|
|
1617
|
+
engineInternals(engine)?.check();
|
|
1618
|
+
await opener.open(file);
|
|
1619
|
+
},
|
|
1442
1620
|
execute: (commands) => session.execute(commands),
|
|
1443
1621
|
export: (format) => session.export(format),
|
|
1444
1622
|
undo: () => {
|
|
@@ -1447,7 +1625,11 @@ function ImageEditorBody(props) {
|
|
|
1447
1625
|
redo: () => {
|
|
1448
1626
|
session.redo();
|
|
1449
1627
|
}
|
|
1450
|
-
}), [
|
|
1628
|
+
}), [
|
|
1629
|
+
engine,
|
|
1630
|
+
session,
|
|
1631
|
+
opener
|
|
1632
|
+
]);
|
|
1451
1633
|
const initial = useRef(initialFile);
|
|
1452
1634
|
useEffect(() => {
|
|
1453
1635
|
if (initial.current) opener.open(initial.current);
|
|
@@ -1534,6 +1716,7 @@ function ImageEditorBody(props) {
|
|
|
1534
1716
|
(returnTo.current?.isConnected ? returnTo.current : root.current?.querySelector("[data-tool=\"image.crop\"]"))?.focus();
|
|
1535
1717
|
}, [tool]);
|
|
1536
1718
|
const onKeyDown = (event) => {
|
|
1719
|
+
if (engineInternals(engine)?.getSnapshot()) return;
|
|
1537
1720
|
const id = shortcuts.match(event.nativeEvent, { root: event.currentTarget });
|
|
1538
1721
|
const tool = id ? registry.get(id) : void 0;
|
|
1539
1722
|
if (!tool) return;
|
|
@@ -1545,12 +1728,13 @@ function ImageEditorBody(props) {
|
|
|
1545
1728
|
event.preventDefault();
|
|
1546
1729
|
tool.run(context);
|
|
1547
1730
|
};
|
|
1548
|
-
return /* @__PURE__ */
|
|
1731
|
+
return /* @__PURE__ */ jsx("section", {
|
|
1549
1732
|
ref: root,
|
|
1550
1733
|
className: join("hm-image-editor", !unstyled && "hm-image-editor--styled", props.className, classNames.root),
|
|
1551
1734
|
onKeyDown,
|
|
1552
1735
|
"aria-label": messages.t("editor.label"),
|
|
1553
|
-
|
|
1736
|
+
...props.theme ? { "data-hm-theme": props.theme } : {},
|
|
1737
|
+
children: /* @__PURE__ */ jsxs(EngineBoundary, { children: [
|
|
1554
1738
|
/* @__PURE__ */ jsx("input", {
|
|
1555
1739
|
ref: input,
|
|
1556
1740
|
type: "file",
|
|
@@ -1576,16 +1760,16 @@ function ImageEditorBody(props) {
|
|
|
1576
1760
|
/* @__PURE__ */ jsx(ImageStage, { className: join("hm-image-editor-stage", classNames.stage) }),
|
|
1577
1761
|
/* @__PURE__ */ jsx("div", {
|
|
1578
1762
|
className: join("hm-image-editor-inspector", classNames.inspector),
|
|
1579
|
-
children: /* @__PURE__ */ jsx(ImageInspector, {})
|
|
1763
|
+
children: /* @__PURE__ */ jsx(ImageInspector, { ...props.features ? { features: props.features } : {} })
|
|
1580
1764
|
})
|
|
1581
1765
|
]
|
|
1582
1766
|
}),
|
|
1583
|
-
/* @__PURE__ */ jsx(ImageExportDialog, { ...props.onExport ? { onExport: props.onExport } : {} })
|
|
1584
|
-
]
|
|
1767
|
+
exportOn ? /* @__PURE__ */ jsx(ImageExportDialog, { ...props.onExport ? { onExport: props.onExport } : {} }) : null
|
|
1768
|
+
] })
|
|
1585
1769
|
});
|
|
1586
1770
|
}
|
|
1587
1771
|
var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
1588
|
-
const { initialFile, plan, onChange, tools, toolbar, icons, className, classNames, unstyled, onEvent, onExport, ...provider } = props;
|
|
1772
|
+
const { initialFile, plan, onChange, tools, toolbar, icons, className, classNames, unstyled, onEvent, onExport, features, theme, ...provider } = props;
|
|
1589
1773
|
const events = useRef(void 0);
|
|
1590
1774
|
const latestOnEvent = useRef(onEvent);
|
|
1591
1775
|
latestOnEvent.current = onEvent;
|
|
@@ -1593,9 +1777,10 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
|
1593
1777
|
events.current?.(event);
|
|
1594
1778
|
latestOnEvent.current?.(event);
|
|
1595
1779
|
}], []);
|
|
1596
|
-
return /* @__PURE__ */ jsx(
|
|
1780
|
+
return /* @__PURE__ */ jsx(ImageProvider, {
|
|
1597
1781
|
...provider,
|
|
1598
1782
|
onEvent: onSessionEvent,
|
|
1783
|
+
boundary: false,
|
|
1599
1784
|
children: /* @__PURE__ */ jsx(AnnouncerProvider, { children: /* @__PURE__ */ jsx(ImageEditorBody, {
|
|
1600
1785
|
handle: ref,
|
|
1601
1786
|
events,
|
|
@@ -1608,10 +1793,12 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
|
1608
1793
|
...className ? { className } : {},
|
|
1609
1794
|
...classNames ? { classNames } : {},
|
|
1610
1795
|
...unstyled === void 0 ? {} : { unstyled },
|
|
1611
|
-
...onExport ? { onExport } : {}
|
|
1796
|
+
...onExport ? { onExport } : {},
|
|
1797
|
+
...features ? { features } : {},
|
|
1798
|
+
...theme ? { theme } : {}
|
|
1612
1799
|
}) })
|
|
1613
1800
|
});
|
|
1614
1801
|
});
|
|
1615
|
-
export {
|
|
1802
|
+
export { imageTools as _, ImageInfoPanel as a, ImageEditorProvider as c, ImageCropPanel as d, useImageDocument as f, useImageView as g, useImageSession as h, ImageStage as i, ImageExportDialog as l, useImageMessages as m, imageIcons as n, ImageFilterPanel as o, useImageEditorState as p, ImageToolbar as r, ImageAdjustPanel as s, ImageEditor as t, ExportListenerContext as u };
|
|
1616
1803
|
|
|
1617
|
-
//# sourceMappingURL=editor-
|
|
1804
|
+
//# sourceMappingURL=editor-CJXEK6MY.js.map
|