@hussmartinez/image-sdk 0.6.0 → 0.7.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/NOTICE +35 -0
- package/README.md +30 -2
- package/dist/assets/image/job.worker.js +1 -0
- package/dist/assets/image/render.worker.js +2 -2
- package/dist/element.d.ts +309 -9
- package/dist/element.js +3 -2
- package/dist/element.js.map +1 -1
- package/dist/index.d.ts +347 -22
- package/dist/index.js +52 -23
- package/dist/index.js.map +1 -1
- package/dist/lazy/inline-job-worker-2EbG2Vzb.js +30 -0
- package/dist/lazy/inline-job-worker-2EbG2Vzb.js.map +1 -0
- package/dist/lazy/inline-worker-DdS6iQ9X.js +30 -0
- package/dist/lazy/{inline-worker-COOlwTsC.js.map → inline-worker-DdS6iQ9X.js.map} +1 -1
- package/dist/react.d.ts +358 -10
- package/dist/react.js +1 -1
- package/dist/shared/{core-VHeENp7j.js → core-A001a7oa.js} +557 -37
- package/dist/shared/core-A001a7oa.js.map +1 -0
- package/dist/shared/{editor-Bj9Xo5nf.js → editor-CV39S-zb.js} +3112 -2375
- package/dist/shared/editor-CV39S-zb.js.map +1 -0
- package/dist/styles.css +154 -0
- package/formats/hm-image-command/v4.schema.json +418 -0
- package/formats/hm-image-plan/v4.schema.json +1114 -0
- package/package.json +4 -2
- package/dist/lazy/inline-worker-COOlwTsC.js +0 -30
- package/dist/shared/core-VHeENp7j.js.map +0 -1
- package/dist/shared/editor-Bj9Xo5nf.js.map +0 -1
package/dist/element.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ declare interface AddStrokesCommand {
|
|
|
35
35
|
/**
|
|
36
36
|
* Registers `<hm-image-editor>`, or the tag you name, and returns its class
|
|
37
37
|
* (docs/adr/0007, sdk-core ADR 0040): the attributes `theme`, `locale` and
|
|
38
|
-
* `tools`; the properties `file`, `plan`, `filePolicy`, `assetsUrl`,
|
|
38
|
+
* `tools`; the properties `file`, `plan`, `filePolicy`, `animations`, `assetsUrl`,
|
|
39
39
|
* `messages`, `engine` and `processor`; the methods `open`, `insertImage`, `execute`,
|
|
40
40
|
* `export`, `undo` and `redo`; and the events `hm-image-editor-change`,
|
|
41
41
|
* `-event`, `-export` and `-error`. Calling it again returns the same class.
|
|
@@ -70,6 +70,19 @@ declare type ExifOrientation = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
|
70
70
|
*/
|
|
71
71
|
declare const FILTER_PRESETS: readonly ["vivid", "warm", "cool", "fade", "mono", "noir", "sepia"];
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* An animation (docs/adr/0011): the frames of the base's source, in the
|
|
75
|
+
* order they play. Everything else in the plan applies to every frame.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
declare interface ImageAnimation {
|
|
80
|
+
/** `null`: play once. 0: for ever. Otherwise that many repeats, to {@link MAX_FRAME_DELAY}. */
|
|
81
|
+
readonly loop: number | null;
|
|
82
|
+
/** 1 to {@link MAX_ANIMATION_FRAMES} frames. */
|
|
83
|
+
readonly frames: readonly ImageFrame[];
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
/**
|
|
74
87
|
* An arrow from one point of the scene to another (ADR 0009,
|
|
75
88
|
* docs/adr/0014). Its head's size follows its width, and its tip is exactly
|
|
@@ -133,7 +146,7 @@ declare interface ImageCallOptions {
|
|
|
133
146
|
*
|
|
134
147
|
* @public
|
|
135
148
|
*/
|
|
136
|
-
declare type ImageCommand = SetCropCommand | SetOrientationCommand | SetOutputCommand | SetMetadataCommand | SetDevelopCommand | SetFilterCommand | InsertLayersCommand | RemoveLayersCommand | MoveLayersCommand | UpdateLayersCommand | AddStrokesCommand | RemoveStrokesCommand | InsertRedactionsCommand | RemoveRedactionsCommand | MoveRedactionsCommand | UpdateRedactionsCommand | ImageInverseCommand;
|
|
149
|
+
declare type ImageCommand = SetCropCommand | SetOrientationCommand | SetOutputCommand | SetMetadataCommand | SetDevelopCommand | SetFilterCommand | InsertLayersCommand | RemoveLayersCommand | MoveLayersCommand | UpdateLayersCommand | AddStrokesCommand | RemoveStrokesCommand | InsertRedactionsCommand | RemoveRedactionsCommand | MoveRedactionsCommand | UpdateRedactionsCommand | InsertFramesCommand | RemoveFramesCommand | MoveFramesCommand | ReverseFramesCommand | UpdateFramesCommand | SetLoopCommand | ImageInverseCommand;
|
|
137
150
|
|
|
138
151
|
/**
|
|
139
152
|
* A rectangle in whole pixels of the oriented source: `x` and `y` from its
|
|
@@ -226,6 +239,8 @@ export declare interface ImageEditorElementProps {
|
|
|
226
239
|
/** The plan, applied as one undoable step when it changes. */
|
|
227
240
|
plan?: ImagePlan;
|
|
228
241
|
filePolicy?: ImageFilePolicyOverrides;
|
|
242
|
+
/** Whether an animated file opens as an animation: `true` when unset. */
|
|
243
|
+
animations?: boolean;
|
|
229
244
|
/** Where the application serves the package's `dist/assets/` directory. */
|
|
230
245
|
assetsUrl?: string | URL;
|
|
231
246
|
/** Text overrides, typed against the English catalogue. */
|
|
@@ -289,10 +304,12 @@ export declare const imageEditorMessages: {
|
|
|
289
304
|
readonly "editor.engineUnavailable": "Image processing stopped. Reload this page or reopen the editor, then choose the image again. Unsaved edits will be lost unless your application has saved them.";
|
|
290
305
|
readonly "editor.label": "Image editor";
|
|
291
306
|
readonly "editor.preview": "Edited image preview, {width, number} × {height, number}";
|
|
307
|
+
readonly "editor.openingPreview": "First frame of the image being opened, {width, number} × {height, number}";
|
|
292
308
|
readonly "editor.empty": "Open an image to start editing. It stays on this device.";
|
|
293
309
|
readonly "editor.choose": "Choose an image";
|
|
294
310
|
readonly "editor.dropHint": "or drop it here";
|
|
295
311
|
readonly "editor.opening": "Opening the image…";
|
|
312
|
+
readonly "editor.checkingFrames": "Checking frames: {done, number} of {total, number}";
|
|
296
313
|
readonly "editor.cancel": "Cancel";
|
|
297
314
|
readonly "editor.opened": "Image opened, {width, number} × {height, number}.";
|
|
298
315
|
readonly "editor.undid": "Undid {action}.";
|
|
@@ -318,6 +335,14 @@ export declare const imageEditorMessages: {
|
|
|
318
335
|
readonly "actions.image.moveRedactions": "redaction order";
|
|
319
336
|
readonly "actions.image.setRedactionOrder": "redaction order";
|
|
320
337
|
readonly "actions.image.updateRedactions": "redaction change";
|
|
338
|
+
readonly "actions.image.insertFrames": "frame";
|
|
339
|
+
readonly "actions.image.removeFrames": "frame";
|
|
340
|
+
readonly "actions.image.restoreFrames": "frame";
|
|
341
|
+
readonly "actions.image.moveFrames": "frame order";
|
|
342
|
+
readonly "actions.image.setFrameOrder": "frame order";
|
|
343
|
+
readonly "actions.image.reverseFrames": "frame order";
|
|
344
|
+
readonly "actions.image.updateFrames": "frame timing";
|
|
345
|
+
readonly "actions.image.setLoop": "repeat count";
|
|
321
346
|
readonly "toolbar.label": "Image tools";
|
|
322
347
|
readonly "toolbar.groups.file": "File";
|
|
323
348
|
readonly "toolbar.groups.history": "History";
|
|
@@ -326,6 +351,7 @@ export declare const imageEditorMessages: {
|
|
|
326
351
|
readonly "toolbar.groups.other": "More tools";
|
|
327
352
|
readonly "tools.open": "Open image";
|
|
328
353
|
readonly "tools.undo": "Undo";
|
|
354
|
+
readonly "tools.play": "Play";
|
|
329
355
|
readonly "tools.redo": "Redo";
|
|
330
356
|
readonly "tools.rotate-left": "Rotate left";
|
|
331
357
|
readonly "tools.rotate-right": "Rotate right";
|
|
@@ -479,8 +505,52 @@ export declare const imageEditorMessages: {
|
|
|
479
505
|
readonly "inspector.adjust": "Adjust";
|
|
480
506
|
readonly "inspector.filters": "Filters";
|
|
481
507
|
readonly "inspector.info": "Info";
|
|
508
|
+
readonly "timeline.label": "Animation";
|
|
509
|
+
readonly "timeline.play": "Play";
|
|
510
|
+
readonly "timeline.frame": "Frame";
|
|
511
|
+
readonly "timeline.position": "Frame {frame, number} of {count, number}";
|
|
512
|
+
readonly "timeline.where": "Frame {frame, number} of {count, number}, {seconds, number} s";
|
|
513
|
+
readonly "tools.frames": "Frames";
|
|
514
|
+
readonly "toolbar.groups.frames": "Frames";
|
|
515
|
+
readonly "frames.panel": "Frames";
|
|
516
|
+
readonly "frames.list": "Frames, in the order they play";
|
|
517
|
+
readonly "frames.row": "Frame {index, number}, {seconds} seconds";
|
|
518
|
+
readonly "frames.selected": "Selected frame";
|
|
519
|
+
readonly "frames.moveEarlier": "Move earlier";
|
|
520
|
+
readonly "frames.moveLater": "Move later";
|
|
521
|
+
readonly "frames.duplicate": "Duplicate";
|
|
522
|
+
readonly "frames.remove": "Delete";
|
|
523
|
+
readonly "frames.reverse": "Reverse order";
|
|
524
|
+
readonly "frames.delay": "Delay, in seconds";
|
|
525
|
+
readonly "frames.delayAll": "Use for every frame";
|
|
526
|
+
readonly "frames.loop": "Plays";
|
|
527
|
+
readonly "frames.loops.once": "Once";
|
|
528
|
+
readonly "frames.loops.repeat": "Repeats";
|
|
529
|
+
readonly "frames.loops.forever": "For ever";
|
|
530
|
+
readonly "frames.repeats": "Times it repeats after the first";
|
|
531
|
+
readonly "frames.done": "Done";
|
|
532
|
+
readonly "frames.movedEarlier": "Moved frame {from, number} earlier. It's frame {index, number} of {count, number}.";
|
|
533
|
+
readonly "frames.movedLater": "Moved frame {from, number} later. It's frame {index, number} of {count, number}.";
|
|
534
|
+
readonly "frames.duplicated": "Duplicated frame {index, number}. The copy is frame {copy, number}.";
|
|
535
|
+
readonly "frames.removed": {
|
|
536
|
+
readonly $plural: "count";
|
|
537
|
+
} & {
|
|
538
|
+
readonly one: "Deleted frame {index, number}. One frame is left.";
|
|
539
|
+
readonly other: "Deleted frame {index, number}. {count, number} frames are left.";
|
|
540
|
+
};
|
|
541
|
+
readonly "frames.reversed": "Reversed the order of the frames.";
|
|
542
|
+
readonly "frames.delayedAll": "Every frame now shows for {seconds} seconds.";
|
|
482
543
|
readonly "notices.label": "Notices";
|
|
483
544
|
readonly "notices.dismiss": "Dismiss";
|
|
545
|
+
readonly "notices.incomplete": {
|
|
546
|
+
readonly $plural: "frames";
|
|
547
|
+
} & {
|
|
548
|
+
readonly one: "This animation's file is damaged. Only its first frame could be opened, of {listed, number}.";
|
|
549
|
+
readonly other: "This animation's file is damaged. {frames, number} of its {listed, number} frames could be opened.";
|
|
550
|
+
};
|
|
551
|
+
readonly "notices.incompleteEnd": "This animation's file is damaged at its end. All {frames, number} of its frames were opened.";
|
|
552
|
+
readonly "notices.animationTooLarge": "This animation is too large to edit as an animation. Its first frame is open as a still image.";
|
|
553
|
+
readonly "notices.firstFrame": "This file is an animation. Its first frame is open as a still image.";
|
|
484
554
|
readonly "notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.";
|
|
485
555
|
readonly "info.panel": "Image info";
|
|
486
556
|
readonly "info.size": "Size";
|
|
@@ -532,6 +602,7 @@ export declare const imageEditorMessages: {
|
|
|
532
602
|
readonly "export.formats.png": "PNG";
|
|
533
603
|
readonly "export.formats.jpeg": "JPEG";
|
|
534
604
|
readonly "export.formats.webp": "WebP";
|
|
605
|
+
readonly "export.formats.gif": "GIF";
|
|
535
606
|
readonly "export.quality": "Quality";
|
|
536
607
|
readonly "export.qualityValue": "{quality, number}%";
|
|
537
608
|
readonly "export.size": "Size";
|
|
@@ -542,6 +613,7 @@ export declare const imageEditorMessages: {
|
|
|
542
613
|
readonly "export.fitHeight": "Largest height";
|
|
543
614
|
readonly "export.fields": "Details to include";
|
|
544
615
|
readonly "export.fieldsHint": "Only what you fill in is written to the file.";
|
|
616
|
+
readonly "export.fieldsNone": "A {format} file carries no details: these aren't written to it.";
|
|
545
617
|
readonly "export.field.title": "Title";
|
|
546
618
|
readonly "export.field.description": "Description";
|
|
547
619
|
readonly "export.field.artist": "Artist";
|
|
@@ -598,6 +670,7 @@ export declare const imageEditorMessages: {
|
|
|
598
670
|
readonly one: "This animation has {actual, number} frames, which is over the {maximum}-frame limit.";
|
|
599
671
|
readonly other: "This animation has {actual, number} frames, which is over the {maximum, number}-frame limit.";
|
|
600
672
|
};
|
|
673
|
+
readonly "errors.ANIMATION_TOO_LARGE": "This animation is too large to open with all its frames. Its first frame can still be opened.";
|
|
601
674
|
readonly "errors.SESSION_TOO_LARGE": "The open images would use {actual, fileSize} of memory, which is over the {maximum, fileSize} limit. Close an image, or clear the undo history, and try again.";
|
|
602
675
|
readonly "errors.TOO_MANY_LAYERS": {
|
|
603
676
|
readonly $plural: "maximum";
|
|
@@ -614,6 +687,7 @@ export declare const imageEditorMessages: {
|
|
|
614
687
|
readonly one: "This animation has {actual} frame.";
|
|
615
688
|
readonly other: "This animation has {actual, number} frames, and may be slow to edit and export.";
|
|
616
689
|
};
|
|
690
|
+
readonly "warnings.maxAnimationPixels": "This animation is large, and may be slow to play, edit and export.";
|
|
617
691
|
readonly "warnings.maxSessionSize": "The open images use {actual, fileSize} of memory. Clearing the undo history frees memory.";
|
|
618
692
|
readonly "warnings.maxLayers": {
|
|
619
693
|
readonly $plural: "actual";
|
|
@@ -768,6 +842,9 @@ declare class ImageError extends SdkError<ImageErrorCode> {
|
|
|
768
842
|
* - `IMAGE_DIMENSION_TOO_LARGE`: a width or height exceeds the
|
|
769
843
|
* `maxImageDimension` limit.
|
|
770
844
|
* - `TOO_MANY_FRAMES`: an animation exceeds the `maxFrames` limit.
|
|
845
|
+
* - `ANIMATION_TOO_LARGE`: a file asked for with all its frames has a screen
|
|
846
|
+
* over the `maxAnimationPixels` limit. The session doesn't raise it: it
|
|
847
|
+
* opens such a file as its first frame instead (docs/adr/0011).
|
|
771
848
|
* - `SESSION_TOO_LARGE`: the decoded images the session holds exceed the
|
|
772
849
|
* `maxSessionSize` limit.
|
|
773
850
|
* - `TOO_MANY_LAYERS`: the layer plan exceeds the `maxLayers` limit.
|
|
@@ -780,12 +857,14 @@ declare class ImageError extends SdkError<ImageErrorCode> {
|
|
|
780
857
|
*
|
|
781
858
|
* @public
|
|
782
859
|
*/
|
|
783
|
-
declare type ImageErrorCode = SdkCoreErrorCode | "INVALID_IMAGE" | "UNSUPPORTED_FORMAT" | "DECODE_FAILED" | "INVALID_COMMAND" | "INVALID_DOCUMENT" | "UNSUPPORTED_PLAN" | "IMAGE_TOO_LARGE" | "IMAGE_DIMENSION_TOO_LARGE" | "TOO_MANY_FRAMES" | "SESSION_TOO_LARGE" | "TOO_MANY_LAYERS" | "TOO_MANY_POINTS";
|
|
860
|
+
declare type ImageErrorCode = SdkCoreErrorCode | "INVALID_IMAGE" | "UNSUPPORTED_FORMAT" | "DECODE_FAILED" | "INVALID_COMMAND" | "INVALID_DOCUMENT" | "UNSUPPORTED_PLAN" | "IMAGE_TOO_LARGE" | "IMAGE_DIMENSION_TOO_LARGE" | "TOO_MANY_FRAMES" | "ANIMATION_TOO_LARGE" | "SESSION_TOO_LARGE" | "TOO_MANY_LAYERS" | "TOO_MANY_POINTS";
|
|
784
861
|
|
|
785
862
|
/**
|
|
786
863
|
* The file an export produces (ADR 0001). `quality`, from 0 to 1, applies to
|
|
787
864
|
* the lossy formats; it defaults to 0.92. WebP is encoded only where the
|
|
788
|
-
* browser can, and otherwise rejects with `UNSUPPORTED_FORMAT`.
|
|
865
|
+
* browser can, and otherwise rejects with `UNSUPPORTED_FORMAT`. A GIF is
|
|
866
|
+
* written by the SDK's own encoder, every frame of an animated plan and one
|
|
867
|
+
* frame of a still, and carries no metadata (docs/adr/0011).
|
|
789
868
|
*
|
|
790
869
|
* @public
|
|
791
870
|
*/
|
|
@@ -797,6 +876,8 @@ declare type ImageExportFormat = {
|
|
|
797
876
|
} | {
|
|
798
877
|
readonly type: "webp";
|
|
799
878
|
readonly quality?: number;
|
|
879
|
+
} | {
|
|
880
|
+
readonly type: "gif";
|
|
800
881
|
};
|
|
801
882
|
|
|
802
883
|
/**
|
|
@@ -809,6 +890,11 @@ declare type ImageExportFormat = {
|
|
|
809
890
|
declare interface ImageExportJob {
|
|
810
891
|
readonly plan: ImagePlan;
|
|
811
892
|
readonly format: ImageExportFormat;
|
|
893
|
+
/**
|
|
894
|
+
* Which frame of an animated plan to export, as an index into the plan's
|
|
895
|
+
* `animation.frames`: 0 when omitted. A still has only frame 0.
|
|
896
|
+
*/
|
|
897
|
+
readonly frame?: number;
|
|
812
898
|
}
|
|
813
899
|
|
|
814
900
|
/**
|
|
@@ -893,6 +979,30 @@ declare type ImageFilterPreset = (typeof FILTER_PRESETS)[number];
|
|
|
893
979
|
*/
|
|
894
980
|
declare type ImageFormat = "png" | "jpeg" | "webp" | "gif" | "avif" | "heif" | "bmp";
|
|
895
981
|
|
|
982
|
+
/**
|
|
983
|
+
* One frame of an animation (docs/adr/0011): which of the source's frames
|
|
984
|
+
* it shows, and for how long. It holds no pixels, so two frames may show
|
|
985
|
+
* the same one.
|
|
986
|
+
*
|
|
987
|
+
* @public
|
|
988
|
+
*/
|
|
989
|
+
declare interface ImageFrame {
|
|
990
|
+
/**
|
|
991
|
+
* Its identity: 1 to {@link MAX_KEY_LENGTH} code points, unique among the
|
|
992
|
+
* plan's layers, redactions and frames.
|
|
993
|
+
*/
|
|
994
|
+
readonly key: string;
|
|
995
|
+
/** A frame of the base's source, from 0. */
|
|
996
|
+
readonly frame: number;
|
|
997
|
+
/** How long it's shown, in hundredths of a second: 0 to {@link MAX_FRAME_DELAY}. */
|
|
998
|
+
readonly delay: number;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/** The fields of a frame an update may set. @public */
|
|
1002
|
+
declare interface ImageFrameProps {
|
|
1003
|
+
readonly delay?: number;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
896
1006
|
/**
|
|
897
1007
|
* Another image, drawn to fill its box (ADR 0009).
|
|
898
1008
|
*
|
|
@@ -928,7 +1038,7 @@ declare interface ImageInsertOptions {
|
|
|
928
1038
|
*
|
|
929
1039
|
* @public
|
|
930
1040
|
*/
|
|
931
|
-
declare type ImageInverseCommand = RestoreStrokesCommand | RestoreLayersCommand | SetLayerOrderCommand | RestoreRedactionsCommand | SetRedactionOrderCommand;
|
|
1041
|
+
declare type ImageInverseCommand = RestoreStrokesCommand | RestoreLayersCommand | SetLayerOrderCommand | RestoreRedactionsCommand | SetRedactionOrderCommand | RestoreFramesCommand | SetFrameOrderCommand;
|
|
932
1042
|
|
|
933
1043
|
/**
|
|
934
1044
|
* The metadata fields a user may keep on export (ADR 0005). Empty strings
|
|
@@ -1010,7 +1120,7 @@ declare type ImageLimitDefinitions = typeof imageLimitDefinitions;
|
|
|
1010
1120
|
|
|
1011
1121
|
/**
|
|
1012
1122
|
* The image SDK's limit definitions: sdk-core's core limits with image
|
|
1013
|
-
* defaults, plus
|
|
1123
|
+
* defaults, plus six for images (ADR 0004, docs/adr/0011).
|
|
1014
1124
|
*
|
|
1015
1125
|
* | Limit | Code | Default maximum | Default warning |
|
|
1016
1126
|
* |---|---|---|---|
|
|
@@ -1021,6 +1131,7 @@ declare type ImageLimitDefinitions = typeof imageLimitDefinitions;
|
|
|
1021
1131
|
* | `maxImagePixels` | `IMAGE_TOO_LARGE` | 50 megapixels | 24 megapixels |
|
|
1022
1132
|
* | `maxImageDimension` | `IMAGE_DIMENSION_TOO_LARGE` | 16,384 pixels | none |
|
|
1023
1133
|
* | `maxFrames` | `TOO_MANY_FRAMES` | 300 | 100 |
|
|
1134
|
+
* | `maxAnimationPixels` | `ANIMATION_TOO_LARGE` | 8 megapixels | 2 megapixels |
|
|
1024
1135
|
* | `maxSessionSize` | `SESSION_TOO_LARGE` | 1 GB | 500 MB |
|
|
1025
1136
|
* | `maxLayers` | `TOO_MANY_LAYERS` | 256 | none |
|
|
1026
1137
|
* | `maxDrawingPoints` | `TOO_MANY_POINTS` | 200,000 | 100,000 |
|
|
@@ -1029,6 +1140,13 @@ declare type ImageLimitDefinitions = typeof imageLimitDefinitions;
|
|
|
1029
1140
|
* per pixel. `maxImagePixels` is the same limit, with the same name, code
|
|
1030
1141
|
* and unit, as `pdf-sdk`'s. `maxImageDimension` is a side length, in pixels.
|
|
1031
1142
|
*
|
|
1143
|
+
* `maxAnimationPixels` is the size of an animation's screen: an
|
|
1144
|
+
* animation's working set is several screens, so it needs a lower ceiling
|
|
1145
|
+
* than a still's. With `maxFrames` and, across its frames,
|
|
1146
|
+
* `maxDecodedSize`, it's a limit on holding a file as an animation, not on
|
|
1147
|
+
* what opens: an animated file over any of them opens as its first frame,
|
|
1148
|
+
* a still (docs/adr/0011). As a still it's held to the others.
|
|
1149
|
+
*
|
|
1032
1150
|
* @public
|
|
1033
1151
|
*/
|
|
1034
1152
|
declare const imageLimitDefinitions: {
|
|
@@ -1055,6 +1173,12 @@ declare const imageLimitDefinitions: {
|
|
|
1055
1173
|
readonly default: 300;
|
|
1056
1174
|
readonly warning: 100;
|
|
1057
1175
|
};
|
|
1176
|
+
readonly maxAnimationPixels: {
|
|
1177
|
+
readonly code: "ANIMATION_TOO_LARGE";
|
|
1178
|
+
readonly unit: "pixels";
|
|
1179
|
+
readonly default: 8000000;
|
|
1180
|
+
readonly warning: 2000000;
|
|
1181
|
+
};
|
|
1058
1182
|
readonly maxSessionSize: {
|
|
1059
1183
|
readonly code: "SESSION_TOO_LARGE";
|
|
1060
1184
|
readonly unit: "bytes";
|
|
@@ -1156,8 +1280,8 @@ declare interface ImagePlan {
|
|
|
1156
1280
|
readonly layers: readonly ImageLayer[];
|
|
1157
1281
|
/** The redactions, applied over every layer (ADR 0010). */
|
|
1158
1282
|
readonly redactions: readonly ImageRedaction[];
|
|
1159
|
-
/** The animation
|
|
1160
|
-
readonly animation: null;
|
|
1283
|
+
/** The animation, or `null` for a still (docs/adr/0011). */
|
|
1284
|
+
readonly animation: ImageAnimation | null;
|
|
1161
1285
|
readonly output: ImageOutput;
|
|
1162
1286
|
/** The fields the user chose to keep on export. Never a location (ADR 0005). */
|
|
1163
1287
|
readonly metadata: ImageKeepableMetadata;
|
|
@@ -1304,6 +1428,27 @@ declare interface ImageRegisterOptions extends ImageProgressOptions {
|
|
|
1304
1428
|
* directly.
|
|
1305
1429
|
*/
|
|
1306
1430
|
readonly filePolicy?: ImageFilePolicy;
|
|
1431
|
+
/**
|
|
1432
|
+
* Which frames of an animated file the source holds (docs/adr/0011).
|
|
1433
|
+
*
|
|
1434
|
+
* - `"first"`, the default: its first frame, as a still.
|
|
1435
|
+
* - `"all"`: every frame. The engine decodes each once to check it, so
|
|
1436
|
+
* the call takes as long as that; `onProgress` follows it, and the
|
|
1437
|
+
* source's `frames` are those that decoded. A file with one frame is a
|
|
1438
|
+
* still either way. A file whose screen is over `filePolicy`'s
|
|
1439
|
+
* `maxAnimationPixels` rejects with `ANIMATION_TOO_LARGE`: register it
|
|
1440
|
+
* as `"first"` instead, as the session does.
|
|
1441
|
+
*/
|
|
1442
|
+
readonly frames?: "first" | "all";
|
|
1443
|
+
/**
|
|
1444
|
+
* For a source registered with all its frames: called once its first
|
|
1445
|
+
* frame can be drawn, before the rest are checked and before `register`
|
|
1446
|
+
* resolves (docs/adr/0011). From then until `register` settles, a renderer
|
|
1447
|
+
* of the same engine may draw a still plan of the source, its first frame;
|
|
1448
|
+
* nothing else may use it yet. Not called for a still, or by an engine
|
|
1449
|
+
* that can't show a source early.
|
|
1450
|
+
*/
|
|
1451
|
+
readonly onFirstFrame?: () => void;
|
|
1307
1452
|
}
|
|
1308
1453
|
|
|
1309
1454
|
/**
|
|
@@ -1400,10 +1545,14 @@ declare interface ImageSession {
|
|
|
1400
1545
|
* `maxProcessingTime` aborts the processor's signal with
|
|
1401
1546
|
* `PROCESSING_TIME_EXCEEDED`. Custom adapters must observe that signal;
|
|
1402
1547
|
* a session cannot preempt an arbitrary adapter that ignores it.
|
|
1548
|
+
*
|
|
1549
|
+
* An animation exports as one frame to these formats: `frame`, an index
|
|
1550
|
+
* into the plan's `animation.frames`, 0 when omitted (docs/adr/0011).
|
|
1403
1551
|
*/
|
|
1404
1552
|
export(format: ImageExportFormat, options?: {
|
|
1405
1553
|
readonly signal?: AbortSignal;
|
|
1406
1554
|
readonly onProgress?: (fraction: number) => void;
|
|
1555
|
+
readonly frame?: number;
|
|
1407
1556
|
}): Promise<ImageSessionExport>;
|
|
1408
1557
|
/** Releases every source the session holds. Later calls throw. */
|
|
1409
1558
|
destroy(): Promise<void>;
|
|
@@ -1458,6 +1607,26 @@ declare interface ImageSessionSnapshot {
|
|
|
1458
1607
|
readonly inserting: boolean;
|
|
1459
1608
|
/** Whether a file is being opened. The current document stays until it's ready. */
|
|
1460
1609
|
readonly opening: boolean;
|
|
1610
|
+
/**
|
|
1611
|
+
* How far the open of an animation has got: the frames checked, of those
|
|
1612
|
+
* the file lists (docs/adr/0011). `null` when nothing is being opened,
|
|
1613
|
+
* and for a still.
|
|
1614
|
+
*/
|
|
1615
|
+
readonly progress: {
|
|
1616
|
+
readonly done: number;
|
|
1617
|
+
readonly total: number;
|
|
1618
|
+
} | null;
|
|
1619
|
+
/**
|
|
1620
|
+
* The first frame of the animation being opened, once it can be drawn and
|
|
1621
|
+
* while the rest are checked (docs/adr/0011): a source id a renderer of
|
|
1622
|
+
* the session's engine may draw as a still, and its size. `null` when
|
|
1623
|
+
* nothing is opening, for a still, and before the first frame is ready.
|
|
1624
|
+
*/
|
|
1625
|
+
readonly openingFrame: {
|
|
1626
|
+
readonly source: string;
|
|
1627
|
+
readonly width: number;
|
|
1628
|
+
readonly height: number;
|
|
1629
|
+
} | null;
|
|
1461
1630
|
/** Whether an export is in progress. */
|
|
1462
1631
|
readonly exporting: boolean;
|
|
1463
1632
|
/** The limits the last open, edit or export came near: at or above their warnings. */
|
|
@@ -1480,6 +1649,12 @@ declare interface ImageSessionSource extends ImageSourceInfo {
|
|
|
1480
1649
|
readonly metadata: ImageMetadataPresence;
|
|
1481
1650
|
/** The fields the user may choose to keep, as the file had them. */
|
|
1482
1651
|
readonly keepable: ImageKeepableMetadata;
|
|
1652
|
+
/**
|
|
1653
|
+
* How many frames the file lists. More than `frames` when an animated
|
|
1654
|
+
* file is open as its first frame, or when its frames ended early
|
|
1655
|
+
* (docs/adr/0011).
|
|
1656
|
+
*/
|
|
1657
|
+
readonly fileFrames: number;
|
|
1483
1658
|
}
|
|
1484
1659
|
|
|
1485
1660
|
/**
|
|
@@ -1522,10 +1697,42 @@ declare interface ImageSourceInfo {
|
|
|
1522
1697
|
readonly format: ImageFormat;
|
|
1523
1698
|
readonly width: number;
|
|
1524
1699
|
readonly height: number;
|
|
1700
|
+
/**
|
|
1701
|
+
* How many frames the source holds: 1 for a still, and for an animated
|
|
1702
|
+
* file registered as its first frame. For a source registered with all
|
|
1703
|
+
* its frames, the frames that decoded (docs/adr/0011).
|
|
1704
|
+
*/
|
|
1525
1705
|
readonly frames: number;
|
|
1526
1706
|
readonly hasAlpha: boolean;
|
|
1527
|
-
/**
|
|
1707
|
+
/**
|
|
1708
|
+
* The bytes the source takes in the worker: width × height × 4 for a
|
|
1709
|
+
* still. An animated source counts what's held, not every frame: its
|
|
1710
|
+
* screens in memory and its frame cache's ceiling (docs/adr/0011).
|
|
1711
|
+
*/
|
|
1528
1712
|
readonly decodedBytes: number;
|
|
1713
|
+
/**
|
|
1714
|
+
* The timing the file gives its frames, for a source registered with all
|
|
1715
|
+
* its frames; `null` for a still.
|
|
1716
|
+
*/
|
|
1717
|
+
readonly timing: ImageSourceTiming | null;
|
|
1718
|
+
/**
|
|
1719
|
+
* Whether the file's frames ended early: before its end, or at a frame
|
|
1720
|
+
* that couldn't be decoded (docs/adr/0011). The frames before that are
|
|
1721
|
+
* the source's. Always `false` for a still.
|
|
1722
|
+
*/
|
|
1723
|
+
readonly incomplete: boolean;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* How an animated file plays (docs/adr/0011), as the file has it.
|
|
1728
|
+
*
|
|
1729
|
+
* @public
|
|
1730
|
+
*/
|
|
1731
|
+
declare interface ImageSourceTiming {
|
|
1732
|
+
/** `null`: play once. 0: for ever. Otherwise that many repeats. */
|
|
1733
|
+
readonly loop: number | null;
|
|
1734
|
+
/** Each frame's delay in hundredths of a second, 0 to 65,535: one for each of the source's frames. */
|
|
1735
|
+
readonly delays: readonly number[];
|
|
1529
1736
|
}
|
|
1530
1737
|
|
|
1531
1738
|
/**
|
|
@@ -1580,6 +1787,19 @@ declare interface ImageThumbnail {
|
|
|
1580
1787
|
close(): void;
|
|
1581
1788
|
}
|
|
1582
1789
|
|
|
1790
|
+
/**
|
|
1791
|
+
* Inserts frames into the animation, such as duplicates (docs/adr/0011).
|
|
1792
|
+
* Each shows a frame the base's source has.
|
|
1793
|
+
*
|
|
1794
|
+
* @public
|
|
1795
|
+
*/
|
|
1796
|
+
declare interface InsertFramesCommand {
|
|
1797
|
+
readonly type: "image.insertFrames";
|
|
1798
|
+
/** The index, from 0 to the number of frames. */
|
|
1799
|
+
readonly at: number;
|
|
1800
|
+
readonly frames: readonly ImageFrame[];
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1583
1803
|
/**
|
|
1584
1804
|
* Inserts layers at an index of the plan's layers, which are drawn bottom
|
|
1585
1805
|
* to top (ADR 0009). Each needs a key no layer or redaction of the plan has.
|
|
@@ -1629,6 +1849,17 @@ declare const LAYER_FONTS: readonly ["sans-serif", "serif", "monospace"];
|
|
|
1629
1849
|
*/
|
|
1630
1850
|
declare const LAYER_SHAPES: readonly ["rectangle", "ellipse"];
|
|
1631
1851
|
|
|
1852
|
+
/**
|
|
1853
|
+
* Moves frames to an index of the list without them, keeping their order.
|
|
1854
|
+
*
|
|
1855
|
+
* @public
|
|
1856
|
+
*/
|
|
1857
|
+
declare interface MoveFramesCommand {
|
|
1858
|
+
readonly type: "image.moveFrames";
|
|
1859
|
+
readonly keys: readonly string[];
|
|
1860
|
+
readonly to: number;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1632
1863
|
/**
|
|
1633
1864
|
* Moves layers to an index of the list without them, keeping the order they
|
|
1634
1865
|
* had: up or down the stack.
|
|
@@ -1653,6 +1884,16 @@ declare interface MoveRedactionsCommand {
|
|
|
1653
1884
|
readonly to: number;
|
|
1654
1885
|
}
|
|
1655
1886
|
|
|
1887
|
+
/**
|
|
1888
|
+
* Removes frames from the animation, which keeps at least one.
|
|
1889
|
+
*
|
|
1890
|
+
* @public
|
|
1891
|
+
*/
|
|
1892
|
+
declare interface RemoveFramesCommand {
|
|
1893
|
+
readonly type: "image.removeFrames";
|
|
1894
|
+
readonly keys: readonly string[];
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1656
1897
|
/**
|
|
1657
1898
|
* Removes layers, by key.
|
|
1658
1899
|
*
|
|
@@ -1685,6 +1926,21 @@ declare interface RemoveStrokesCommand {
|
|
|
1685
1926
|
readonly indexes: readonly number[];
|
|
1686
1927
|
}
|
|
1687
1928
|
|
|
1929
|
+
/**
|
|
1930
|
+
* Puts removed frames back, each at its index, by rising index. It's what
|
|
1931
|
+
* undoes {@link RemoveFramesCommand}: the reducer applies it, but it isn't
|
|
1932
|
+
* part of the portable command format (ADR 0009).
|
|
1933
|
+
*
|
|
1934
|
+
* @public
|
|
1935
|
+
*/
|
|
1936
|
+
declare interface RestoreFramesCommand {
|
|
1937
|
+
readonly type: "image.restoreFrames";
|
|
1938
|
+
readonly entries: readonly {
|
|
1939
|
+
readonly at: number;
|
|
1940
|
+
readonly frame: ImageFrame;
|
|
1941
|
+
}[];
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1688
1944
|
/**
|
|
1689
1945
|
* Puts removed layers back, each at its index, by rising index. It's what
|
|
1690
1946
|
* undoes {@link RemoveLayersCommand}: the reducer applies it, but it isn't
|
|
@@ -1731,6 +1987,15 @@ declare interface RestoreStrokesCommand {
|
|
|
1731
1987
|
}[];
|
|
1732
1988
|
}
|
|
1733
1989
|
|
|
1990
|
+
/**
|
|
1991
|
+
* Reverses the order the frames play in. It undoes itself.
|
|
1992
|
+
*
|
|
1993
|
+
* @public
|
|
1994
|
+
*/
|
|
1995
|
+
declare interface ReverseFramesCommand {
|
|
1996
|
+
readonly type: "image.reverseFrames";
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1734
1999
|
/**
|
|
1735
2000
|
* Sets or removes the base's crop, in whole pixels of the oriented source.
|
|
1736
2001
|
*
|
|
@@ -1762,6 +2027,18 @@ declare interface SetFilterCommand {
|
|
|
1762
2027
|
readonly filter: ImageFilter | null;
|
|
1763
2028
|
}
|
|
1764
2029
|
|
|
2030
|
+
/**
|
|
2031
|
+
* Sets the whole order of the frames: every key, once. It's what undoes
|
|
2032
|
+
* {@link MoveFramesCommand}: the reducer applies it, but it isn't part of
|
|
2033
|
+
* the portable command format (ADR 0009).
|
|
2034
|
+
*
|
|
2035
|
+
* @public
|
|
2036
|
+
*/
|
|
2037
|
+
declare interface SetFrameOrderCommand {
|
|
2038
|
+
readonly type: "image.setFrameOrder";
|
|
2039
|
+
readonly keys: readonly string[];
|
|
2040
|
+
}
|
|
2041
|
+
|
|
1765
2042
|
/**
|
|
1766
2043
|
* Sets the whole order of the layers: every key, once. It's what undoes
|
|
1767
2044
|
* {@link MoveLayersCommand}: the reducer applies it, but it isn't part of
|
|
@@ -1774,6 +2051,16 @@ declare interface SetLayerOrderCommand {
|
|
|
1774
2051
|
readonly keys: readonly string[];
|
|
1775
2052
|
}
|
|
1776
2053
|
|
|
2054
|
+
/**
|
|
2055
|
+
* Sets how many times the animation repeats: `null` for once, 0 for ever.
|
|
2056
|
+
*
|
|
2057
|
+
* @public
|
|
2058
|
+
*/
|
|
2059
|
+
declare interface SetLoopCommand {
|
|
2060
|
+
readonly type: "image.setLoop";
|
|
2061
|
+
readonly loop: number | null;
|
|
2062
|
+
}
|
|
2063
|
+
|
|
1777
2064
|
/**
|
|
1778
2065
|
* Sets one metadata field to keep on export. An empty value keeps nothing.
|
|
1779
2066
|
*
|
|
@@ -1817,6 +2104,19 @@ declare interface SetRedactionOrderCommand {
|
|
|
1817
2104
|
readonly keys: readonly string[];
|
|
1818
2105
|
}
|
|
1819
2106
|
|
|
2107
|
+
/**
|
|
2108
|
+
* Sets some frames' delays: one command for one frame or for all of them.
|
|
2109
|
+
*
|
|
2110
|
+
* @public
|
|
2111
|
+
*/
|
|
2112
|
+
declare interface UpdateFramesCommand {
|
|
2113
|
+
readonly type: "image.updateFrames";
|
|
2114
|
+
readonly updates: readonly {
|
|
2115
|
+
readonly key: string;
|
|
2116
|
+
readonly props: ImageFrameProps;
|
|
2117
|
+
}[];
|
|
2118
|
+
}
|
|
2119
|
+
|
|
1820
2120
|
/**
|
|
1821
2121
|
* Sets some fields of some layers: their boxes after a move, their opacity,
|
|
1822
2122
|
* a text layer's text. `props` may hold any field of the layer's kind except
|
package/dist/element.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-
|
|
1
|
+
import { qt as ImageError } from "./shared/core-A001a7oa.js";
|
|
2
|
+
import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-CV39S-zb.js";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { createEditorElement } from "@hussmartinez/sdk-core/element";
|
|
@@ -105,6 +105,7 @@ var defineImageEditorElement = /* @__PURE__ */ createEditorElement({
|
|
|
105
105
|
"file",
|
|
106
106
|
"plan",
|
|
107
107
|
"filePolicy",
|
|
108
|
+
"animations",
|
|
108
109
|
"assetsUrl",
|
|
109
110
|
"messages",
|
|
110
111
|
"engine",
|
package/dist/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","names":[],"sources":["../src/react/element/mount.tsx","../src/element.ts"],"sourcesContent":["import type { MessageOverrides } from \"@hussmartinez/sdk-core\";\nimport type { EditorElementContext, MountedEditor } from \"@hussmartinez/sdk-core/element\";\nimport { type ReactNode, type RefCallback, useEffect, useRef } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ImageError } from \"../../core/errors/image-error.js\";\nimport type { ImageFilePolicyOverrides } from \"../../core/errors/image-limits.js\";\nimport type { ImagePlan } from \"../../core/model/plan.js\";\nimport type { ImageEngine } from \"../../core/ports/image-engine.js\";\nimport type { ImageProcessor } from \"../../core/ports/image-processor.js\";\nimport { ImageEditor } from \"../editor/ImageEditor.js\";\nimport type { ImageEditorHandle } from \"../editor/types.js\";\nimport type { ImageEditorMessageCatalogue } from \"../editor-messages.js\";\nimport { ExportListenerContext, type ImageExportReport } from \"../export/export-listener.js\";\n\n/**\n * The `<hm-image-editor>` element's props: its attributes, `theme`, `locale`\n * and `tools`, and its properties (docs/adr/0007). They're writable, since a\n * host sets them on the element, such as `editor.file = file`.\n *\n * @public\n */\nexport interface ImageEditorElementProps {\n /** `light`, `dark` or `system`: ui's colour mode, on the element. Inherited when unset. */\n theme?: string;\n /** The locale for numbers and plurals. Defaults to `\"en\"`. */\n locale?: string;\n /** Which tools are present, by id, in order: the attribute is space-separated. */\n tools?: readonly string[];\n /** An image to open. Setting another opens it, replacing the current one. */\n file?: Blob;\n /** The plan, applied as one undoable step when it changes. */\n plan?: ImagePlan;\n filePolicy?: ImageFilePolicyOverrides;\n /** Where the application serves the package's `dist/assets/` directory. */\n assetsUrl?: string | URL;\n /** Text overrides, typed against the English catalogue. */\n messages?: MessageOverrides<ImageEditorMessageCatalogue>;\n engine?: ImageEngine;\n processor?: ImageProcessor;\n}\n\n/**\n * The `<hm-image-editor>` element's methods: the React editor's ref handle.\n * They wait for the editor's first render; `export()` returns the file.\n *\n * @public\n */\nexport type ImageEditorElementMethods = Pick<\n ImageEditorHandle,\n \"open\" | \"insertImage\" | \"execute\" | \"export\" | \"undo\" | \"redo\"\n>;\n\n/**\n * The element's events, fired as `hm-image-editor-<name>`. None carries a\n * file name or contents (sdk-core ADR 0012):\n *\n * - `change`: the plan, after each committed edit, open, undo or redo.\n * - `event`: the session's anonymous usage event.\n * - `export`: an {@link ImageExportReport} after the export dialog finishes.\n * - `error`: `{ code, details }` of a failure the editor shows.\n *\n * @public\n */\nexport type ImageEditorElementEvent = \"change\" | \"event\" | \"export\" | \"error\";\n\nconst MODES = new Set([\"light\", \"dark\", \"system\"]);\n\ninterface ElementEditorProps {\n readonly values: Partial<ImageEditorElementProps>;\n readonly setHandle: RefCallback<ImageEditorHandle>;\n readonly handle: { readonly current: ImageEditorHandle | null };\n readonly dispatch: EditorElementContext<ImageEditorElementEvent>[\"dispatch\"];\n readonly report: (report: ImageExportReport) => void;\n}\n\nfunction ElementEditor(props: ElementEditorProps): ReactNode {\n const { values, setHandle, handle, dispatch, report } = props;\n const { file, theme: _theme, ...editorProps } = values;\n\n // A file opens when it's set, and another replaces it.\n const opened = useRef<Blob | undefined>(undefined);\n useEffect(() => {\n if (!file || file === opened.current) return;\n opened.current = file;\n void handle.current?.open(file);\n }, [file, handle]);\n\n // A failure the editor shows is an `error` event, once per failure.\n useEffect(() => {\n const session = handle.current?.session;\n if (!session) return;\n let last = session.getSnapshot().error;\n return session.subscribe(() => {\n const error = session.getSnapshot().error;\n if (error && error !== last) {\n dispatch(\"error\", { code: error.code, details: error.details ?? {} });\n }\n last = error;\n });\n }, [handle, dispatch]);\n\n return (\n <ExportListenerContext.Provider value={report}>\n <ImageEditor\n ref={setHandle}\n {...editorProps}\n onChange={(plan) => dispatch(\"change\", plan)}\n onEvent={(event) => dispatch(\"event\", event)}\n />\n </ExportListenerContext.Provider>\n );\n}\n\n/**\n * Renders `<ImageEditor>` into the element's light DOM, for\n * `createEditorElement` (sdk-core ADR 0040). It renders without `flushSync`,\n * since the element may connect during a host's React commit; so `open()`\n * and `export()` wait for the first render, and `execute()`, `undo()` and\n * `redo()` act on the document there is.\n */\nexport function mountImageEditor(\n host: HTMLElement,\n initial: Partial<ImageEditorElementProps>,\n context: EditorElementContext<ImageEditorElementEvent>,\n): MountedEditor<Partial<ImageEditorElementProps>, ImageEditorElementMethods> {\n const root = createRoot(host);\n const handle: { current: ImageEditorHandle | null } = { current: null };\n let resolveReady: (editor: ImageEditorHandle) => void = () => {};\n const ready = new Promise<ImageEditorHandle>((resolve) => {\n resolveReady = resolve;\n });\n const setHandle: RefCallback<ImageEditorHandle> = (editor) => {\n handle.current = editor;\n if (editor) resolveReady(editor);\n };\n const dispatch = context.dispatch;\n const report = (exported: ImageExportReport) => dispatch(\"export\", exported);\n\n const render = (values: Partial<ImageEditorElementProps>) => {\n // The colour mode is ui's attribute on the element itself, so changing it\n // never re-renders the editor.\n const mode = values.theme;\n if (mode && MODES.has(mode)) host.setAttribute(\"data-hm-theme\", mode);\n else host.removeAttribute(\"data-hm-theme\");\n root.render(\n <ElementEditor\n values={values}\n setHandle={setHandle}\n handle={handle}\n dispatch={dispatch}\n report={report}\n />,\n );\n };\n render(initial);\n\n const now = (): ImageEditorHandle | null => handle.current;\n return {\n update: render,\n unmount: () => {\n root.unmount();\n host.removeAttribute(\"data-hm-theme\");\n },\n handle: {\n open: async (file) => (await ready).open(file),\n insertImage: async (file) => (await ready).insertImage(file),\n export: async (format) => (await ready).export(format),\n execute: (commands) => {\n const editor = now();\n if (!editor) {\n throw new ImageError(\"INVALID_COMMAND\", \"There's nothing to edit before a file is open.\");\n }\n editor.execute(commands);\n },\n undo: () => now()?.undo(),\n redo: () => now()?.redo(),\n },\n };\n}\n","/**\n * The `<hm-image-editor>` custom element of the image SDK.\n *\n * @remarks\n * Importing this entry registers nothing: applications call\n * `defineImageEditorElement()` themselves, and importing it on a server does\n * nothing (ADR 0004, ADR 0007). The element renders `<ImageEditor>` into its\n * light DOM, so React and React DOM, the package's optional peer\n * dependencies, are needed here. Hosts import `@hussmartinez/ui/styles.css`\n * once, then this package's `styles.css` (sdk-core ADR 0036).\n *\n * @packageDocumentation\n */\n\nimport { createEditorElement } from \"@hussmartinez/sdk-core/element\";\nimport {\n type ImageEditorElementEvent,\n type ImageEditorElementMethods,\n type ImageEditorElementProps,\n mountImageEditor,\n} from \"./react/element/mount.js\";\n\nexport type { ImageEditorMessageCatalogue } from \"./react/editor-messages.js\";\nexport { imageEditorMessages } from \"./react/editor-messages.js\";\nexport type { ImageExportReport } from \"./react/export/export-listener.js\";\nexport type { ImageEditorElementEvent, ImageEditorElementMethods, ImageEditorElementProps };\n\n/** A space-separated list, as the `tools` attribute holds. */\nconst words = (value: string): readonly string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Registers `<hm-image-editor>`, or the tag you name, and returns its class\n * (docs/adr/0007, sdk-core ADR 0040): the attributes `theme`, `locale` and\n * `tools`; the properties `file`, `plan`, `filePolicy`, `assetsUrl`,\n * `messages`, `engine` and `processor`; the methods `open`, `insertImage`, `execute`,\n * `export`, `undo` and `redo`; and the events `hm-image-editor-change`,\n * `-event`, `-export` and `-error`. Calling it again returns the same class.\n *\n * @example\n * ```ts\n * import { defineImageEditorElement } from \"@hussmartinez/image-sdk/element\";\n *\n * defineImageEditorElement();\n * const editor = document.querySelector(\"hm-image-editor\");\n * editor.file = file;\n * editor.addEventListener(\"hm-image-editor-change\", (event) => save(event.detail));\n * ```\n *\n * @public\n */\nexport const defineImageEditorElement = /* @__PURE__ */ createEditorElement<\n Partial<ImageEditorElementProps>,\n ImageEditorElementMethods,\n ImageEditorElementEvent\n>({\n kind: \"image\",\n attributes: {\n theme: \"theme\",\n locale: \"locale\",\n tools: { property: \"tools\", parse: words },\n },\n properties: [\"file\", \"plan\", \"filePolicy\", \"assetsUrl\", \"messages\", \"engine\", \"processor\"],\n methods: [\"open\", \"insertImage\", \"execute\", \"export\", \"undo\", \"redo\"],\n events: [\"change\", \"event\", \"export\", \"error\"],\n mount: mountImageEditor,\n});\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"element.js","names":[],"sources":["../src/react/element/mount.tsx","../src/element.ts"],"sourcesContent":["import type { MessageOverrides } from \"@hussmartinez/sdk-core\";\nimport type { EditorElementContext, MountedEditor } from \"@hussmartinez/sdk-core/element\";\nimport { type ReactNode, type RefCallback, useEffect, useRef } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ImageError } from \"../../core/errors/image-error.js\";\nimport type { ImageFilePolicyOverrides } from \"../../core/errors/image-limits.js\";\nimport type { ImagePlan } from \"../../core/model/plan.js\";\nimport type { ImageEngine } from \"../../core/ports/image-engine.js\";\nimport type { ImageProcessor } from \"../../core/ports/image-processor.js\";\nimport { ImageEditor } from \"../editor/ImageEditor.js\";\nimport type { ImageEditorHandle } from \"../editor/types.js\";\nimport type { ImageEditorMessageCatalogue } from \"../editor-messages.js\";\nimport { ExportListenerContext, type ImageExportReport } from \"../export/export-listener.js\";\n\n/**\n * The `<hm-image-editor>` element's props: its attributes, `theme`, `locale`\n * and `tools`, and its properties (docs/adr/0007). They're writable, since a\n * host sets them on the element, such as `editor.file = file`.\n *\n * @public\n */\nexport interface ImageEditorElementProps {\n /** `light`, `dark` or `system`: ui's colour mode, on the element. Inherited when unset. */\n theme?: string;\n /** The locale for numbers and plurals. Defaults to `\"en\"`. */\n locale?: string;\n /** Which tools are present, by id, in order: the attribute is space-separated. */\n tools?: readonly string[];\n /** An image to open. Setting another opens it, replacing the current one. */\n file?: Blob;\n /** The plan, applied as one undoable step when it changes. */\n plan?: ImagePlan;\n filePolicy?: ImageFilePolicyOverrides;\n /** Whether an animated file opens as an animation: `true` when unset. */\n animations?: boolean;\n /** Where the application serves the package's `dist/assets/` directory. */\n assetsUrl?: string | URL;\n /** Text overrides, typed against the English catalogue. */\n messages?: MessageOverrides<ImageEditorMessageCatalogue>;\n engine?: ImageEngine;\n processor?: ImageProcessor;\n}\n\n/**\n * The `<hm-image-editor>` element's methods: the React editor's ref handle.\n * They wait for the editor's first render; `export()` returns the file.\n *\n * @public\n */\nexport type ImageEditorElementMethods = Pick<\n ImageEditorHandle,\n \"open\" | \"insertImage\" | \"execute\" | \"export\" | \"undo\" | \"redo\"\n>;\n\n/**\n * The element's events, fired as `hm-image-editor-<name>`. None carries a\n * file name or contents (sdk-core ADR 0012):\n *\n * - `change`: the plan, after each committed edit, open, undo or redo.\n * - `event`: the session's anonymous usage event.\n * - `export`: an {@link ImageExportReport} after the export dialog finishes.\n * - `error`: `{ code, details }` of a failure the editor shows.\n *\n * @public\n */\nexport type ImageEditorElementEvent = \"change\" | \"event\" | \"export\" | \"error\";\n\nconst MODES = new Set([\"light\", \"dark\", \"system\"]);\n\ninterface ElementEditorProps {\n readonly values: Partial<ImageEditorElementProps>;\n readonly setHandle: RefCallback<ImageEditorHandle>;\n readonly handle: { readonly current: ImageEditorHandle | null };\n readonly dispatch: EditorElementContext<ImageEditorElementEvent>[\"dispatch\"];\n readonly report: (report: ImageExportReport) => void;\n}\n\nfunction ElementEditor(props: ElementEditorProps): ReactNode {\n const { values, setHandle, handle, dispatch, report } = props;\n const { file, theme: _theme, ...editorProps } = values;\n\n // A file opens when it's set, and another replaces it.\n const opened = useRef<Blob | undefined>(undefined);\n useEffect(() => {\n if (!file || file === opened.current) return;\n opened.current = file;\n void handle.current?.open(file);\n }, [file, handle]);\n\n // A failure the editor shows is an `error` event, once per failure.\n useEffect(() => {\n const session = handle.current?.session;\n if (!session) return;\n let last = session.getSnapshot().error;\n return session.subscribe(() => {\n const error = session.getSnapshot().error;\n if (error && error !== last) {\n dispatch(\"error\", { code: error.code, details: error.details ?? {} });\n }\n last = error;\n });\n }, [handle, dispatch]);\n\n return (\n <ExportListenerContext.Provider value={report}>\n <ImageEditor\n ref={setHandle}\n {...editorProps}\n onChange={(plan) => dispatch(\"change\", plan)}\n onEvent={(event) => dispatch(\"event\", event)}\n />\n </ExportListenerContext.Provider>\n );\n}\n\n/**\n * Renders `<ImageEditor>` into the element's light DOM, for\n * `createEditorElement` (sdk-core ADR 0040). It renders without `flushSync`,\n * since the element may connect during a host's React commit; so `open()`\n * and `export()` wait for the first render, and `execute()`, `undo()` and\n * `redo()` act on the document there is.\n */\nexport function mountImageEditor(\n host: HTMLElement,\n initial: Partial<ImageEditorElementProps>,\n context: EditorElementContext<ImageEditorElementEvent>,\n): MountedEditor<Partial<ImageEditorElementProps>, ImageEditorElementMethods> {\n const root = createRoot(host);\n const handle: { current: ImageEditorHandle | null } = { current: null };\n let resolveReady: (editor: ImageEditorHandle) => void = () => {};\n const ready = new Promise<ImageEditorHandle>((resolve) => {\n resolveReady = resolve;\n });\n const setHandle: RefCallback<ImageEditorHandle> = (editor) => {\n handle.current = editor;\n if (editor) resolveReady(editor);\n };\n const dispatch = context.dispatch;\n const report = (exported: ImageExportReport) => dispatch(\"export\", exported);\n\n const render = (values: Partial<ImageEditorElementProps>) => {\n // The colour mode is ui's attribute on the element itself, so changing it\n // never re-renders the editor.\n const mode = values.theme;\n if (mode && MODES.has(mode)) host.setAttribute(\"data-hm-theme\", mode);\n else host.removeAttribute(\"data-hm-theme\");\n root.render(\n <ElementEditor\n values={values}\n setHandle={setHandle}\n handle={handle}\n dispatch={dispatch}\n report={report}\n />,\n );\n };\n render(initial);\n\n const now = (): ImageEditorHandle | null => handle.current;\n return {\n update: render,\n unmount: () => {\n root.unmount();\n host.removeAttribute(\"data-hm-theme\");\n },\n handle: {\n open: async (file) => (await ready).open(file),\n insertImage: async (file) => (await ready).insertImage(file),\n export: async (format) => (await ready).export(format),\n execute: (commands) => {\n const editor = now();\n if (!editor) {\n throw new ImageError(\"INVALID_COMMAND\", \"There's nothing to edit before a file is open.\");\n }\n editor.execute(commands);\n },\n undo: () => now()?.undo(),\n redo: () => now()?.redo(),\n },\n };\n}\n","/**\n * The `<hm-image-editor>` custom element of the image SDK.\n *\n * @remarks\n * Importing this entry registers nothing: applications call\n * `defineImageEditorElement()` themselves, and importing it on a server does\n * nothing (ADR 0004, ADR 0007). The element renders `<ImageEditor>` into its\n * light DOM, so React and React DOM, the package's optional peer\n * dependencies, are needed here. Hosts import `@hussmartinez/ui/styles.css`\n * once, then this package's `styles.css` (sdk-core ADR 0036).\n *\n * @packageDocumentation\n */\n\nimport { createEditorElement } from \"@hussmartinez/sdk-core/element\";\nimport {\n type ImageEditorElementEvent,\n type ImageEditorElementMethods,\n type ImageEditorElementProps,\n mountImageEditor,\n} from \"./react/element/mount.js\";\n\nexport type { ImageEditorMessageCatalogue } from \"./react/editor-messages.js\";\nexport { imageEditorMessages } from \"./react/editor-messages.js\";\nexport type { ImageExportReport } from \"./react/export/export-listener.js\";\nexport type { ImageEditorElementEvent, ImageEditorElementMethods, ImageEditorElementProps };\n\n/** A space-separated list, as the `tools` attribute holds. */\nconst words = (value: string): readonly string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Registers `<hm-image-editor>`, or the tag you name, and returns its class\n * (docs/adr/0007, sdk-core ADR 0040): the attributes `theme`, `locale` and\n * `tools`; the properties `file`, `plan`, `filePolicy`, `animations`, `assetsUrl`,\n * `messages`, `engine` and `processor`; the methods `open`, `insertImage`, `execute`,\n * `export`, `undo` and `redo`; and the events `hm-image-editor-change`,\n * `-event`, `-export` and `-error`. Calling it again returns the same class.\n *\n * @example\n * ```ts\n * import { defineImageEditorElement } from \"@hussmartinez/image-sdk/element\";\n *\n * defineImageEditorElement();\n * const editor = document.querySelector(\"hm-image-editor\");\n * editor.file = file;\n * editor.addEventListener(\"hm-image-editor-change\", (event) => save(event.detail));\n * ```\n *\n * @public\n */\nexport const defineImageEditorElement = /* @__PURE__ */ createEditorElement<\n Partial<ImageEditorElementProps>,\n ImageEditorElementMethods,\n ImageEditorElementEvent\n>({\n kind: \"image\",\n attributes: {\n theme: \"theme\",\n locale: \"locale\",\n tools: { property: \"tools\", parse: words },\n },\n properties: [\n \"file\",\n \"plan\",\n \"filePolicy\",\n \"animations\",\n \"assetsUrl\",\n \"messages\",\n \"engine\",\n \"processor\",\n ],\n methods: [\"open\", \"insertImage\", \"execute\", \"export\", \"undo\", \"redo\"],\n events: [\"change\", \"event\", \"export\", \"error\"],\n mount: mountImageEditor,\n});\n"],"mappings":"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"}
|