@hussmartinez/image-sdk 0.8.0 → 0.10.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 +1 -1
- package/dist/assets/image/job.worker.js +1 -1
- package/dist/assets/image/render.worker.js +1 -1
- 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-BSYw65Yh.js → inline-job-worker-CIW_4y1q.js} +2 -2
- package/dist/lazy/{inline-job-worker-BSYw65Yh.js.map → inline-job-worker-CIW_4y1q.js.map} +1 -1
- package/dist/lazy/{inline-worker-CNWqkatu.js → inline-worker-B7Zgl5CJ.js} +2 -2
- package/dist/lazy/{inline-worker-CNWqkatu.js.map → inline-worker-B7Zgl5CJ.js.map} +1 -1
- package/dist/react.d.ts +10 -1
- package/dist/react.js +1 -1
- package/dist/shared/{core-Dl1fQBA9.js → core-VTHSqv-f.js} +4 -4
- package/dist/shared/{core-Dl1fQBA9.js.map → core-VTHSqv-f.js.map} +1 -1
- package/dist/shared/{editor-B5NuHohd.js → editor-CXmyuWHq.js} +97 -19
- package/dist/shared/editor-CXmyuWHq.js.map +1 -0
- package/package.json +1 -1
- package/dist/shared/editor-B5NuHohd.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
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-VTHSqv-f.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
|
|
@@ -982,11 +982,7 @@ function useRedactActions() {
|
|
|
982
982
|
}]
|
|
983
983
|
}]);
|
|
984
984
|
},
|
|
985
|
-
commit(
|
|
986
|
-
if (soon) {
|
|
987
|
-
gesture.commitSoon();
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
985
|
+
commit() {
|
|
990
986
|
const drew = gesture.active() && count();
|
|
991
987
|
gesture.commit();
|
|
992
988
|
if (drew !== false && count() > drew) announce(messages.t("redact.added", { count: count() }));
|
|
@@ -1157,9 +1153,8 @@ function useLayerActions() {
|
|
|
1157
1153
|
}]
|
|
1158
1154
|
}]);
|
|
1159
1155
|
},
|
|
1160
|
-
commit(
|
|
1161
|
-
|
|
1162
|
-
else gesture.commit();
|
|
1156
|
+
commit() {
|
|
1157
|
+
gesture.commit();
|
|
1163
1158
|
},
|
|
1164
1159
|
cancel() {
|
|
1165
1160
|
gesture.cancel();
|
|
@@ -1925,6 +1920,45 @@ function DrawOverlay(props) {
|
|
|
1925
1920
|
onPointerCancel: onPointerEnd
|
|
1926
1921
|
});
|
|
1927
1922
|
}
|
|
1923
|
+
// src/react/key-run.ts
|
|
1924
|
+
function createKeyRun() {
|
|
1925
|
+
const held = /* @__PURE__ */ new Set();
|
|
1926
|
+
let running = false;
|
|
1927
|
+
let cancelled = false;
|
|
1928
|
+
return {
|
|
1929
|
+
press(key) {
|
|
1930
|
+
held.add(key);
|
|
1931
|
+
if (cancelled) return false;
|
|
1932
|
+
running = true;
|
|
1933
|
+
return true;
|
|
1934
|
+
},
|
|
1935
|
+
release(key) {
|
|
1936
|
+
if (!held.delete(key) || held.size > 0) return false;
|
|
1937
|
+
const ended = running && !cancelled;
|
|
1938
|
+
running = false;
|
|
1939
|
+
cancelled = false;
|
|
1940
|
+
return ended;
|
|
1941
|
+
},
|
|
1942
|
+
cancel() {
|
|
1943
|
+
if (!running) return false;
|
|
1944
|
+
running = false;
|
|
1945
|
+
cancelled = held.size > 0;
|
|
1946
|
+
return true;
|
|
1947
|
+
},
|
|
1948
|
+
handOff() {
|
|
1949
|
+
const ended = running && !cancelled;
|
|
1950
|
+
running = false;
|
|
1951
|
+
return ended;
|
|
1952
|
+
},
|
|
1953
|
+
leave() {
|
|
1954
|
+
held.clear();
|
|
1955
|
+
const ended = running && !cancelled;
|
|
1956
|
+
running = false;
|
|
1957
|
+
cancelled = false;
|
|
1958
|
+
return ended;
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1928
1962
|
// src/react/layers/frame-geometry.ts
|
|
1929
1963
|
var isBoxedLayer = (layer) => layer.kind === "text" || layer.kind === "shape" || layer.kind === "image";
|
|
1930
1964
|
var LAYER_HANDLES = [
|
|
@@ -2043,6 +2077,7 @@ function LayersOverlay(props) {
|
|
|
2043
2077
|
const describedBy = useId();
|
|
2044
2078
|
const drag = useRef(void 0);
|
|
2045
2079
|
const focusNext = useRef(null);
|
|
2080
|
+
const keys = useRef(createKeyRun());
|
|
2046
2081
|
const frameOf = (key) => overlay.current?.querySelector(`[data-hm-layer="${CSS.escape(key)}"]`);
|
|
2047
2082
|
useEffect(() => {
|
|
2048
2083
|
const key = focusNext.current;
|
|
@@ -2100,6 +2135,7 @@ function LayersOverlay(props) {
|
|
|
2100
2135
|
};
|
|
2101
2136
|
const onFramePointerDown = (layer, part) => (event) => {
|
|
2102
2137
|
if (event.button !== 0) return;
|
|
2138
|
+
if (keys.current.handOff()) actions.commit();
|
|
2103
2139
|
event.preventDefault();
|
|
2104
2140
|
event.stopPropagation();
|
|
2105
2141
|
actions.select(layer.key);
|
|
@@ -2141,7 +2177,8 @@ function LayersOverlay(props) {
|
|
|
2141
2177
|
if (drag.current) {
|
|
2142
2178
|
drag.current = void 0;
|
|
2143
2179
|
actions.cancel();
|
|
2144
|
-
} else actions.
|
|
2180
|
+
} else if (keys.current.cancel()) actions.cancel();
|
|
2181
|
+
else actions.done();
|
|
2145
2182
|
return;
|
|
2146
2183
|
}
|
|
2147
2184
|
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
@@ -2157,10 +2194,17 @@ function LayersOverlay(props) {
|
|
|
2157
2194
|
if (!arrow) return;
|
|
2158
2195
|
event.preventDefault();
|
|
2159
2196
|
event.stopPropagation();
|
|
2197
|
+
if (drag.current) return;
|
|
2198
|
+
if (!keys.current.press(event.key)) return;
|
|
2160
2199
|
const fields = nudgeOf(layer, arrow[0], arrow[1], event.shiftKey);
|
|
2161
2200
|
if (!fields) return;
|
|
2162
2201
|
actions.moving(layer.key, fields);
|
|
2163
|
-
|
|
2202
|
+
};
|
|
2203
|
+
const onKeyUp = (event) => {
|
|
2204
|
+
if (ARROWS$1[event.key] && keys.current.release(event.key)) actions.commit();
|
|
2205
|
+
};
|
|
2206
|
+
const onBlur = () => {
|
|
2207
|
+
if (keys.current.leave()) actions.commit();
|
|
2164
2208
|
};
|
|
2165
2209
|
const count = plan.layers.length;
|
|
2166
2210
|
const shown = plan.layers.filter((layer) => layer.visible || layer.key === selected);
|
|
@@ -2190,6 +2234,8 @@ function LayersOverlay(props) {
|
|
|
2190
2234
|
tabIndex: layer.key === tabStop ? 0 : -1,
|
|
2191
2235
|
onFocus: () => actions.select(layer.key),
|
|
2192
2236
|
onKeyDown: onKeyDown(layer),
|
|
2237
|
+
onKeyUp,
|
|
2238
|
+
onBlur,
|
|
2193
2239
|
onPointerDown: onFramePointerDown(layer, "move"),
|
|
2194
2240
|
...pointer
|
|
2195
2241
|
};
|
|
@@ -2325,6 +2371,7 @@ function RedactOverlay(props) {
|
|
|
2325
2371
|
const describedBy = useId();
|
|
2326
2372
|
const drag = useRef(void 0);
|
|
2327
2373
|
const focusNext = useRef(null);
|
|
2374
|
+
const keys = useRef(createKeyRun());
|
|
2328
2375
|
const selected = state.redact?.selected ?? null;
|
|
2329
2376
|
const exists = plan.redactions.some((redaction) => redaction.key === selected);
|
|
2330
2377
|
const previous = useRef(null);
|
|
@@ -2362,6 +2409,7 @@ function RedactOverlay(props) {
|
|
|
2362
2409
|
};
|
|
2363
2410
|
const onFramePointerDown = (redaction, handle) => (event) => {
|
|
2364
2411
|
if (event.button !== 0) return;
|
|
2412
|
+
if (keys.current.handOff()) actions.commit();
|
|
2365
2413
|
event.preventDefault();
|
|
2366
2414
|
event.stopPropagation();
|
|
2367
2415
|
actions.select(redaction.key);
|
|
@@ -2379,6 +2427,7 @@ function RedactOverlay(props) {
|
|
|
2379
2427
|
};
|
|
2380
2428
|
const onBackgroundPointerDown = (event) => {
|
|
2381
2429
|
if (event.button !== 0) return;
|
|
2430
|
+
if (keys.current.handOff()) actions.commit();
|
|
2382
2431
|
event.preventDefault();
|
|
2383
2432
|
capture(event);
|
|
2384
2433
|
const at = onComposition(event);
|
|
@@ -2452,7 +2501,8 @@ function RedactOverlay(props) {
|
|
|
2452
2501
|
if (drag.current) {
|
|
2453
2502
|
drag.current = void 0;
|
|
2454
2503
|
actions.cancel();
|
|
2455
|
-
} else actions.
|
|
2504
|
+
} else if (keys.current.cancel()) actions.cancel();
|
|
2505
|
+
else actions.done();
|
|
2456
2506
|
return;
|
|
2457
2507
|
}
|
|
2458
2508
|
if (event.key === "Delete" || event.key === "Backspace") {
|
|
@@ -2470,10 +2520,17 @@ function RedactOverlay(props) {
|
|
|
2470
2520
|
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
2471
2521
|
event.preventDefault();
|
|
2472
2522
|
event.stopPropagation();
|
|
2523
|
+
if (drag.current) return;
|
|
2524
|
+
if (!keys.current.press(event.key)) return;
|
|
2473
2525
|
const [dx, dy] = arrow;
|
|
2474
2526
|
const moved = event.shiftKey ? dragged(shown(redaction), dx !== 0 ? "e" : "s", dx, dy) : dragged(shown(redaction), "move", dx, dy);
|
|
2475
2527
|
actions.moving(redaction.key, toScene(moved));
|
|
2476
|
-
|
|
2528
|
+
};
|
|
2529
|
+
const onKeyUp = (event) => {
|
|
2530
|
+
if (ARROWS[event.key] && keys.current.release(event.key)) actions.commit();
|
|
2531
|
+
};
|
|
2532
|
+
const onBlur = () => {
|
|
2533
|
+
if (keys.current.leave()) actions.commit();
|
|
2477
2534
|
};
|
|
2478
2535
|
const count = plan.redactions.length;
|
|
2479
2536
|
const tabStop = exists ? selected : plan.redactions[0]?.key;
|
|
@@ -2504,6 +2561,8 @@ function RedactOverlay(props) {
|
|
|
2504
2561
|
},
|
|
2505
2562
|
onFocus: () => actions.select(redaction.key),
|
|
2506
2563
|
onKeyDown: onKeyDown(redaction),
|
|
2564
|
+
onKeyUp,
|
|
2565
|
+
onBlur,
|
|
2507
2566
|
onPointerDown: onFramePointerDown(redaction, "move"),
|
|
2508
2567
|
...pointer,
|
|
2509
2568
|
children: [/* @__PURE__ */ jsx("span", {
|
|
@@ -2908,7 +2967,8 @@ var formatOf = (draft) => draft.format === "jpeg" || draft.format === "webp" ? {
|
|
|
2908
2967
|
} : { type: draft.format };
|
|
2909
2968
|
function ImageExportDialog(props) {
|
|
2910
2969
|
const { onExport, fileName = "image" } = props;
|
|
2911
|
-
const
|
|
2970
|
+
const { engine, emit } = useImageInternals();
|
|
2971
|
+
const lifecycle = engineInternals(engine);
|
|
2912
2972
|
const session = useImageSession();
|
|
2913
2973
|
const { plan, source } = useImageDocument();
|
|
2914
2974
|
const [editor, editorStore] = useImageEditorState();
|
|
@@ -3028,6 +3088,11 @@ function ImageExportDialog(props) {
|
|
|
3028
3088
|
link.href = objectUrl.current;
|
|
3029
3089
|
link.download = `${fileName}.${EXTENSIONS[phase.format]}`;
|
|
3030
3090
|
link.click();
|
|
3091
|
+
emit({
|
|
3092
|
+
type: "download",
|
|
3093
|
+
outcome: "done",
|
|
3094
|
+
commands: []
|
|
3095
|
+
});
|
|
3031
3096
|
};
|
|
3032
3097
|
const composition = compositionSize(plan, source);
|
|
3033
3098
|
const size = outputSize(current.output, composition);
|
|
@@ -3598,6 +3663,15 @@ function ImageProvider(props) {
|
|
|
3598
3663
|
const [editor] = useState(createEditorStore);
|
|
3599
3664
|
const [opener] = useState(() => createOpener(owned.session));
|
|
3600
3665
|
const [inserter] = useState(() => createInserter(owned.session, editor));
|
|
3666
|
+
const onEvent = useRef(props.onEvent);
|
|
3667
|
+
useInsertionEffect(() => {
|
|
3668
|
+
onEvent.current = props.onEvent;
|
|
3669
|
+
}, [props.onEvent]);
|
|
3670
|
+
const [emit] = useState(() => (event) => {
|
|
3671
|
+
try {
|
|
3672
|
+
onEvent.current?.(event);
|
|
3673
|
+
} catch {}
|
|
3674
|
+
});
|
|
3601
3675
|
useEffect(() => {
|
|
3602
3676
|
if (owned.pending !== void 0) clearTimeout(owned.pending);
|
|
3603
3677
|
return () => {
|
|
@@ -3615,14 +3689,16 @@ function ImageProvider(props) {
|
|
|
3615
3689
|
view,
|
|
3616
3690
|
editor,
|
|
3617
3691
|
opener,
|
|
3618
|
-
inserter
|
|
3692
|
+
inserter,
|
|
3693
|
+
emit
|
|
3619
3694
|
}), [
|
|
3620
3695
|
owned,
|
|
3621
3696
|
messages,
|
|
3622
3697
|
view,
|
|
3623
3698
|
editor,
|
|
3624
3699
|
opener,
|
|
3625
|
-
inserter
|
|
3700
|
+
inserter,
|
|
3701
|
+
emit
|
|
3626
3702
|
]);
|
|
3627
3703
|
return /* @__PURE__ */ jsx(ImageContext.Provider, {
|
|
3628
3704
|
value,
|
|
@@ -5095,7 +5171,9 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
|
5095
5171
|
const { initialFile, plan, onChange, tools, toolbar, icons, className, classNames, unstyled, onEvent, onExport, features, theme, ...provider } = props;
|
|
5096
5172
|
const events = useRef(void 0);
|
|
5097
5173
|
const latestOnEvent = useRef(onEvent);
|
|
5098
|
-
|
|
5174
|
+
useInsertionEffect(() => {
|
|
5175
|
+
latestOnEvent.current = onEvent;
|
|
5176
|
+
}, [onEvent]);
|
|
5099
5177
|
const [onSessionEvent] = useMemo(() => [(event) => {
|
|
5100
5178
|
events.current?.(event);
|
|
5101
5179
|
latestOnEvent.current?.(event);
|
|
@@ -5124,4 +5202,4 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
|
5124
5202
|
});
|
|
5125
5203
|
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 };
|
|
5126
5204
|
|
|
5127
|
-
//# sourceMappingURL=editor-
|
|
5205
|
+
//# sourceMappingURL=editor-CXmyuWHq.js.map
|