@hussmartinez/image-sdk 0.9.0 → 0.10.1
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 +1 -1
- package/dist/assets/image/job.worker.js +1 -1
- package/dist/assets/image/render.worker.js +2 -2
- package/dist/element.js +2 -2
- package/dist/index.d.ts +10 -1
- package/dist/index.js +1 -1
- package/dist/lazy/{inline-job-worker-BFybekkp.js → inline-job-worker-ok4juPo9.js} +2 -2
- package/dist/lazy/{inline-job-worker-BFybekkp.js.map → inline-job-worker-ok4juPo9.js.map} +1 -1
- package/dist/lazy/inline-worker-uUmNP8s2.js +30 -0
- package/dist/lazy/{inline-worker-CMzixw3b.js.map → inline-worker-uUmNP8s2.js.map} +1 -1
- package/dist/react.d.ts +10 -1
- package/dist/react.js +1 -1
- package/dist/shared/{core-CCE45OTe.js → core-CX0DXHI4.js} +145 -127
- package/dist/shared/core-CX0DXHI4.js.map +1 -0
- package/dist/shared/{editor-CJEZNOqH.js → editor-BWKiEOe7.js} +76 -45
- package/dist/shared/editor-BWKiEOe7.js.map +1 -0
- package/package.json +1 -1
- package/dist/lazy/inline-worker-CMzixw3b.js +0 -30
- package/dist/shared/core-CCE45OTe.js.map +0 -1
- package/dist/shared/editor-CJEZNOqH.js.map +0 -1
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
import { A as dragHandle, At as createImageRenderer, B as outputSize, C as drawingBounds, Ct as MAX_SCENE_COORDINATE, D as aspectRatio, E as ASPECT_PRESETS, F as wholeCrop, Ft as createImageProcessor, I as compositionSize, It as createImageEngine, J as FORBIDDEN_IN_TEXT, Jt as isImageError, Kt as asImageError, L as compositionToSource, Lt as engineInternals, M as handleInSource, N as moveCrop, Nt as fittedView, O as compositionDeltaToSource, P as nudgeCropOnScreen, Pt as placement, R as cropRect, Rt as ANIMATION_LIMITS, T as simplifyStroke, Tt as MAX_STROKE_WIDTH, _ as layerToScene, _t as MAX_FRAME_DELAY, a as compositionRectToScene, at as MAX_METADATA_LENGTH, b as createImageKey, bt as MAX_LAYER_TEXT_LENGTH, ct as DEVELOP_ADJUSTMENTS, d as sceneRectToComposition, dt as LAYER_ALIGNMENTS, f as applyMatrix, ft as LAYER_FONTS, g as layerToOutput, i as newLayerBox, j as fitAspect, k as cropInComposition, kt as createPlan, lt as FILTER_PRESETS, m as invertMatrix, n as createImageSession, o as fitRedactionRegion, q as createImageReducer, r as keepsFields, st as longerThan, t as imageMessages, x as arrowBounds, y as sceneToOutput } from "./core-
|
|
1
|
+
import { A as dragHandle, At as createImageRenderer, B as outputSize, C as drawingBounds, Ct as MAX_SCENE_COORDINATE, D as aspectRatio, E as ASPECT_PRESETS, F as wholeCrop, Ft as createImageProcessor, I as compositionSize, It as createImageEngine, J as FORBIDDEN_IN_TEXT, Jt as isImageError, Kt as asImageError, L as compositionToSource, Lt as engineInternals, M as handleInSource, N as moveCrop, Nt as fittedView, O as compositionDeltaToSource, P as nudgeCropOnScreen, Pt as placement, R as cropRect, Rt as ANIMATION_LIMITS, T as simplifyStroke, Tt as MAX_STROKE_WIDTH, _ as layerToScene, _t as MAX_FRAME_DELAY, a as compositionRectToScene, at as MAX_METADATA_LENGTH, b as createImageKey, bt as MAX_LAYER_TEXT_LENGTH, ct as DEVELOP_ADJUSTMENTS, d as sceneRectToComposition, dt as LAYER_ALIGNMENTS, f as applyMatrix, ft as LAYER_FONTS, g as layerToOutput, i as newLayerBox, j as fitAspect, k as cropInComposition, kt as createPlan, lt as FILTER_PRESETS, m as invertMatrix, n as createImageSession, o as fitRedactionRegion, q as createImageReducer, r as keepsFields, st as longerThan, t as imageMessages, x as arrowBounds, y as sceneToOutput } from "./core-CX0DXHI4.js";
|
|
2
2
|
import { applyCommands, createMessages, createShortcutRegistry, createStore, createToolRegistry, defineMessages, defineTool, plural } from "@hussmartinez/sdk-core";
|
|
3
3
|
import { AddIcon, AnnouncerProvider, ArrowIcon, Button, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, IconButton, LayersIcon, MoveDownIcon, MoveUpIcon, NumberField, OpenIcon, PageGridIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, Slider, Spinner, TextArea, TextField, TextIcon, ToggleButton, Toolbar, ToolbarGroup, Tooltip, UiMessagesProvider, UndoIcon, VisibleIcon, ZoomInIcon, ZoomOutIcon, useAnnounce, usePlatform } from "@hussmartinez/ui/react";
|
|
4
|
-
import { createContext, forwardRef, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { createContext, forwardRef, useContext, useEffect, useId, useImperativeHandle, useInsertionEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { uiMessages } from "@hussmartinez/ui";
|
|
7
7
|
// src/features/editor-state.ts
|
|
8
|
-
var PAUSED = Object.freeze({
|
|
8
|
+
var PAUSED = /* @__PURE__ */ Object.freeze({
|
|
9
9
|
frame: 0,
|
|
10
10
|
playing: false
|
|
11
11
|
});
|
|
12
|
-
var NO_TOOL = Object.freeze({
|
|
12
|
+
var NO_TOOL = /* @__PURE__ */ Object.freeze({
|
|
13
13
|
tool: null,
|
|
14
14
|
crop: null,
|
|
15
15
|
redact: null,
|
|
16
16
|
layers: null,
|
|
17
17
|
draw: null
|
|
18
18
|
});
|
|
19
|
-
var IDLE =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
var IDLE = /* @__PURE__ */ idle();
|
|
20
|
+
function idle() {
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
...NO_TOOL,
|
|
23
|
+
error: null,
|
|
24
|
+
preview: null,
|
|
25
|
+
dialog: null,
|
|
26
|
+
playback: PAUSED
|
|
27
|
+
});
|
|
28
|
+
}
|
|
26
29
|
function createEditorStore() {
|
|
27
30
|
return createStore(IDLE);
|
|
28
31
|
}
|
|
29
32
|
// src/features/tool-types.ts
|
|
30
33
|
var hasDocument = ({ snapshot }) => snapshot.plan !== null;
|
|
34
|
+
function withReason(tool, unavailable) {
|
|
35
|
+
return {
|
|
36
|
+
...tool,
|
|
37
|
+
unavailable
|
|
38
|
+
};
|
|
39
|
+
}
|
|
31
40
|
// src/features/crop/crop-tools.ts
|
|
32
41
|
function startCrop({ session, editor }) {
|
|
33
42
|
const { plan, source } = session.getSnapshot();
|
|
@@ -220,25 +229,22 @@ var drawTool = /* @__PURE__ */ defineTool({
|
|
|
220
229
|
shortcuts: ["D"]
|
|
221
230
|
});
|
|
222
231
|
// src/features/export/export-tool.ts
|
|
223
|
-
var exportTool = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
playback
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}),
|
|
240
|
-
unavailable: ({ snapshot, editor }) => snapshot.plan !== null && editor.tool === "crop" ? "tools.exportWhileCropping" : void 0
|
|
241
|
-
};
|
|
232
|
+
var exportTool = /* @__PURE__ */ withReason(/* @__PURE__ */ defineTool({
|
|
233
|
+
id: "image.export",
|
|
234
|
+
label: "tools.export",
|
|
235
|
+
icon: "export",
|
|
236
|
+
group: "export",
|
|
237
|
+
isEnabled: ({ snapshot, editor }) => snapshot.plan !== null && editor.tool !== "crop",
|
|
238
|
+
run: ({ editor }) => editor.set((state) => state.tool === "crop" ? state : {
|
|
239
|
+
...state,
|
|
240
|
+
...NO_TOOL,
|
|
241
|
+
dialog: "export",
|
|
242
|
+
playback: {
|
|
243
|
+
...state.playback,
|
|
244
|
+
playing: false
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
}), ({ snapshot, editor }) => snapshot.plan !== null && editor.tool === "crop" ? "tools.exportWhileCropping" : void 0);
|
|
242
248
|
// src/features/frames/frames-tool.ts
|
|
243
249
|
var animated = ({ snapshot }) => snapshot.plan?.animation != null;
|
|
244
250
|
var framesTool = /* @__PURE__ */ defineTool({
|
|
@@ -1048,7 +1054,10 @@ function useRedactActions() {
|
|
|
1048
1054
|
// src/react/layers/use-layers.ts
|
|
1049
1055
|
var DUPLICATE_OFFSET = 8;
|
|
1050
1056
|
var LABEL_LENGTH = 40;
|
|
1051
|
-
var EVERY_FORBIDDEN =
|
|
1057
|
+
var EVERY_FORBIDDEN = /* @__PURE__ */ everyMatch(FORBIDDEN_IN_TEXT);
|
|
1058
|
+
function everyMatch(pattern) {
|
|
1059
|
+
return new RegExp(pattern.source, `${pattern.flags}g`);
|
|
1060
|
+
}
|
|
1052
1061
|
function layerLabel(layer, messages) {
|
|
1053
1062
|
if (layer.name !== "") return layer.name;
|
|
1054
1063
|
if (layer.kind === "text") {
|
|
@@ -2908,7 +2917,7 @@ function ImageStage(props) {
|
|
|
2908
2917
|
});
|
|
2909
2918
|
}
|
|
2910
2919
|
// src/react/export/export-listener.ts
|
|
2911
|
-
var ExportListenerContext = createContext(null);
|
|
2920
|
+
var ExportListenerContext = /* @__PURE__ */ createContext(null);
|
|
2912
2921
|
// src/react/export/ExportDialog.tsx
|
|
2913
2922
|
var FORMATS = [
|
|
2914
2923
|
"png",
|
|
@@ -2967,7 +2976,8 @@ var formatOf = (draft) => draft.format === "jpeg" || draft.format === "webp" ? {
|
|
|
2967
2976
|
} : { type: draft.format };
|
|
2968
2977
|
function ImageExportDialog(props) {
|
|
2969
2978
|
const { onExport, fileName = "image" } = props;
|
|
2970
|
-
const
|
|
2979
|
+
const { engine, emit } = useImageInternals();
|
|
2980
|
+
const lifecycle = engineInternals(engine);
|
|
2971
2981
|
const session = useImageSession();
|
|
2972
2982
|
const { plan, source } = useImageDocument();
|
|
2973
2983
|
const [editor, editorStore] = useImageEditorState();
|
|
@@ -3087,6 +3097,11 @@ function ImageExportDialog(props) {
|
|
|
3087
3097
|
link.href = objectUrl.current;
|
|
3088
3098
|
link.download = `${fileName}.${EXTENSIONS[phase.format]}`;
|
|
3089
3099
|
link.click();
|
|
3100
|
+
emit({
|
|
3101
|
+
type: "download",
|
|
3102
|
+
outcome: "done",
|
|
3103
|
+
commands: []
|
|
3104
|
+
});
|
|
3090
3105
|
};
|
|
3091
3106
|
const composition = compositionSize(plan, source);
|
|
3092
3107
|
const size = outputSize(current.output, composition);
|
|
@@ -3610,15 +3625,18 @@ var imageEditorText = /* @__PURE__ */ defineMessages({
|
|
|
3610
3625
|
"export.close": "Done"
|
|
3611
3626
|
});
|
|
3612
3627
|
// src/react/editor-messages.ts
|
|
3613
|
-
var imageEditorMessages = /* @__PURE__ */
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3628
|
+
var imageEditorMessages = /* @__PURE__ */ editorCatalogue();
|
|
3629
|
+
function editorCatalogue() {
|
|
3630
|
+
return defineMessages({
|
|
3631
|
+
...imageMessages,
|
|
3632
|
+
...uiMessages,
|
|
3633
|
+
...imageEditorText
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3618
3636
|
// src/react/view-store.ts
|
|
3619
|
-
var FITTED = Object.freeze({
|
|
3637
|
+
var FITTED = /* @__PURE__ */ Object.freeze({
|
|
3620
3638
|
zoom: 1,
|
|
3621
|
-
pan: Object.freeze({
|
|
3639
|
+
pan: /* @__PURE__ */ Object.freeze({
|
|
3622
3640
|
x: 0,
|
|
3623
3641
|
y: 0
|
|
3624
3642
|
})
|
|
@@ -3657,6 +3675,15 @@ function ImageProvider(props) {
|
|
|
3657
3675
|
const [editor] = useState(createEditorStore);
|
|
3658
3676
|
const [opener] = useState(() => createOpener(owned.session));
|
|
3659
3677
|
const [inserter] = useState(() => createInserter(owned.session, editor));
|
|
3678
|
+
const onEvent = useRef(props.onEvent);
|
|
3679
|
+
useInsertionEffect(() => {
|
|
3680
|
+
onEvent.current = props.onEvent;
|
|
3681
|
+
}, [props.onEvent]);
|
|
3682
|
+
const [emit] = useState(() => (event) => {
|
|
3683
|
+
try {
|
|
3684
|
+
onEvent.current?.(event);
|
|
3685
|
+
} catch {}
|
|
3686
|
+
});
|
|
3660
3687
|
useEffect(() => {
|
|
3661
3688
|
if (owned.pending !== void 0) clearTimeout(owned.pending);
|
|
3662
3689
|
return () => {
|
|
@@ -3674,14 +3701,16 @@ function ImageProvider(props) {
|
|
|
3674
3701
|
view,
|
|
3675
3702
|
editor,
|
|
3676
3703
|
opener,
|
|
3677
|
-
inserter
|
|
3704
|
+
inserter,
|
|
3705
|
+
emit
|
|
3678
3706
|
}), [
|
|
3679
3707
|
owned,
|
|
3680
3708
|
messages,
|
|
3681
3709
|
view,
|
|
3682
3710
|
editor,
|
|
3683
3711
|
opener,
|
|
3684
|
-
inserter
|
|
3712
|
+
inserter,
|
|
3713
|
+
emit
|
|
3685
3714
|
]);
|
|
3686
3715
|
return /* @__PURE__ */ jsx(ImageContext.Provider, {
|
|
3687
3716
|
value,
|
|
@@ -5150,11 +5179,13 @@ function ImageEditorBody(props) {
|
|
|
5150
5179
|
] })
|
|
5151
5180
|
});
|
|
5152
5181
|
}
|
|
5153
|
-
var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
5182
|
+
var ImageEditor = /* @__PURE__ */ forwardRef(function ImageEditor(props, ref) {
|
|
5154
5183
|
const { initialFile, plan, onChange, tools, toolbar, icons, className, classNames, unstyled, onEvent, onExport, features, theme, ...provider } = props;
|
|
5155
5184
|
const events = useRef(void 0);
|
|
5156
5185
|
const latestOnEvent = useRef(onEvent);
|
|
5157
|
-
|
|
5186
|
+
useInsertionEffect(() => {
|
|
5187
|
+
latestOnEvent.current = onEvent;
|
|
5188
|
+
}, [onEvent]);
|
|
5158
5189
|
const [onSessionEvent] = useMemo(() => [(event) => {
|
|
5159
5190
|
events.current?.(event);
|
|
5160
5191
|
latestOnEvent.current?.(event);
|
|
@@ -5183,4 +5214,4 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
|
5183
5214
|
});
|
|
5184
5215
|
export { imageTools as S, useImageDocument as _, ImageFilterPanel as a, useImageSession as b, ImageLayersPanel as c, imageEditorMessages as d, ImageExportDialog as f, ImageCropPanel as g, ImageDrawPanel as h, ImageInfoPanel as i, ImageFramesPanel as l, ImageStage as m, imageIcons as n, ImageAdjustPanel as o, ExportListenerContext as p, ImageToolbar as r, ImageRedactPanel as s, ImageEditor as t, ImageEditorProvider as u, useImageEditorState as v, useImageView as x, useImageMessages as y };
|
|
5185
5216
|
|
|
5186
|
-
//# sourceMappingURL=editor-
|
|
5217
|
+
//# sourceMappingURL=editor-BWKiEOe7.js.map
|