@hussmartinez/image-sdk 0.9.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.
@@ -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-CCE45OTe.js";
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
@@ -2967,7 +2967,8 @@ var formatOf = (draft) => draft.format === "jpeg" || draft.format === "webp" ? {
2967
2967
  } : { type: draft.format };
2968
2968
  function ImageExportDialog(props) {
2969
2969
  const { onExport, fileName = "image" } = props;
2970
- const lifecycle = engineInternals(useImageInternals().engine);
2970
+ const { engine, emit } = useImageInternals();
2971
+ const lifecycle = engineInternals(engine);
2971
2972
  const session = useImageSession();
2972
2973
  const { plan, source } = useImageDocument();
2973
2974
  const [editor, editorStore] = useImageEditorState();
@@ -3087,6 +3088,11 @@ function ImageExportDialog(props) {
3087
3088
  link.href = objectUrl.current;
3088
3089
  link.download = `${fileName}.${EXTENSIONS[phase.format]}`;
3089
3090
  link.click();
3091
+ emit({
3092
+ type: "download",
3093
+ outcome: "done",
3094
+ commands: []
3095
+ });
3090
3096
  };
3091
3097
  const composition = compositionSize(plan, source);
3092
3098
  const size = outputSize(current.output, composition);
@@ -3657,6 +3663,15 @@ function ImageProvider(props) {
3657
3663
  const [editor] = useState(createEditorStore);
3658
3664
  const [opener] = useState(() => createOpener(owned.session));
3659
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
+ });
3660
3675
  useEffect(() => {
3661
3676
  if (owned.pending !== void 0) clearTimeout(owned.pending);
3662
3677
  return () => {
@@ -3674,14 +3689,16 @@ function ImageProvider(props) {
3674
3689
  view,
3675
3690
  editor,
3676
3691
  opener,
3677
- inserter
3692
+ inserter,
3693
+ emit
3678
3694
  }), [
3679
3695
  owned,
3680
3696
  messages,
3681
3697
  view,
3682
3698
  editor,
3683
3699
  opener,
3684
- inserter
3700
+ inserter,
3701
+ emit
3685
3702
  ]);
3686
3703
  return /* @__PURE__ */ jsx(ImageContext.Provider, {
3687
3704
  value,
@@ -5154,7 +5171,9 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
5154
5171
  const { initialFile, plan, onChange, tools, toolbar, icons, className, classNames, unstyled, onEvent, onExport, features, theme, ...provider } = props;
5155
5172
  const events = useRef(void 0);
5156
5173
  const latestOnEvent = useRef(onEvent);
5157
- latestOnEvent.current = onEvent;
5174
+ useInsertionEffect(() => {
5175
+ latestOnEvent.current = onEvent;
5176
+ }, [onEvent]);
5158
5177
  const [onSessionEvent] = useMemo(() => [(event) => {
5159
5178
  events.current?.(event);
5160
5179
  latestOnEvent.current?.(event);
@@ -5183,4 +5202,4 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
5183
5202
  });
5184
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 };
5185
5204
 
5186
- //# sourceMappingURL=editor-CJEZNOqH.js.map
5205
+ //# sourceMappingURL=editor-CXmyuWHq.js.map