@hussmartinez/image-sdk 0.0.0-stage → 0.2.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.
@@ -0,0 +1,1444 @@
1
+ import { SdkError, applyCommands, coreLimits, createErrorHelpers, createHistory, createStore, createWorkerClient, defineLimits, defineMessages, isSdkError, plural, resolveAssetsBase, sdkCoreMessages } from "@hussmartinez/sdk-core";
2
+ import { uiMessages } from "@hussmartinez/ui";
3
+ // src/core/errors/image-error.ts
4
+ var ImageError = class extends SdkError {
5
+ name = "ImageError";
6
+ };
7
+ function isImageError(value, code) {
8
+ return isSdkError(value, code) && value.name === "ImageError";
9
+ }
10
+ // src/core/errors/error-helpers.ts
11
+ var { adapt: asImageError, abortError, throwIfAborted } = createErrorHelpers(ImageError, {
12
+ fallbackCode: "UNKNOWN",
13
+ fallbackMessage: "Image processing failed."
14
+ });
15
+ // src/core/errors/image-limits.ts
16
+ var imageLimitDefinitions = {
17
+ ...coreLimits,
18
+ maxDecodedSize: {
19
+ ...coreLimits.maxDecodedSize,
20
+ default: 1e9,
21
+ warning: 4e8
22
+ },
23
+ maxImagePixels: {
24
+ code: "IMAGE_TOO_LARGE",
25
+ unit: "pixels",
26
+ default: 5e7,
27
+ warning: 24e6
28
+ },
29
+ maxImageDimension: {
30
+ code: "IMAGE_DIMENSION_TOO_LARGE",
31
+ unit: "pixels",
32
+ default: 16384
33
+ },
34
+ maxFrames: {
35
+ code: "TOO_MANY_FRAMES",
36
+ unit: "count",
37
+ default: 300,
38
+ warning: 100
39
+ },
40
+ maxSessionSize: {
41
+ code: "SESSION_TOO_LARGE",
42
+ unit: "bytes",
43
+ default: 1e9,
44
+ warning: 5e8
45
+ },
46
+ maxLayers: {
47
+ code: "TOO_MANY_LAYERS",
48
+ unit: "count",
49
+ default: 256
50
+ }
51
+ };
52
+ var imageLimits = /* @__PURE__ */ defineLimits(imageLimitDefinitions, { errorClass: ImageError });
53
+ var PER_FILE_LIMITS = [
54
+ "maxFileSize",
55
+ "maxImageDimension",
56
+ "maxImagePixels",
57
+ "maxFrames",
58
+ "maxDecodedSize"
59
+ ];
60
+ function checkFileLimits(policy, fileSize, probe) {
61
+ const { width, height } = probe.oriented;
62
+ const actual = {
63
+ maxFileSize: fileSize,
64
+ maxImageDimension: Math.max(width, height),
65
+ maxImagePixels: width * height,
66
+ maxFrames: probe.frames,
67
+ maxDecodedSize: probe.decodedPixelBound * 4
68
+ };
69
+ return PER_FILE_LIMITS.filter((limit) => policy.check(limit, actual[limit]) === "warning");
70
+ }
71
+ var OUTPUT_LIMITS = ["maxImageDimension", "maxImagePixels"];
72
+ function checkOutputLimits(policy, size) {
73
+ policy.check("maxImageDimension", Math.max(size.width, size.height));
74
+ policy.check("maxImagePixels", size.width * size.height);
75
+ }
76
+ // src/adapters/image-engine.ts
77
+ var ENGINE_INTERNALS = Symbol("hm-image-engine");
78
+ function engineInternals(engine) {
79
+ return engine[ENGINE_INTERNALS];
80
+ }
81
+ function createImageEngine(options = {}) {
82
+ const base = options.assetsUrl === void 0 ? void 0 : resolveAssetsBase(options.assetsUrl);
83
+ const selfHosted = base === void 0 ? void 0 : `${base}image/render.worker.js`;
84
+ return createEngine({
85
+ loadWorker: selfHosted ? async () => () => new Worker(selfHosted, {
86
+ type: "module",
87
+ name: "hm-image-render"
88
+ }) : async () => (await import("../lazy/inline-worker-Cvw0Gpxf.js")).createInlineWorker,
89
+ version: "0.2.0",
90
+ ...selfHosted ? { asset: selfHosted } : {}
91
+ });
92
+ }
93
+ function createEngine(environment) {
94
+ let startWorker;
95
+ let destroyed = false;
96
+ const ids = /* @__PURE__ */ new Set();
97
+ const client = createWorkerClient({
98
+ createWorker: () => {
99
+ if (!startWorker) throw new ImageError("WORKER_START_FAILED", "The render worker hasn't loaded.");
100
+ return startWorker();
101
+ },
102
+ errorClasses: { ImageError },
103
+ idleTimeout: 0,
104
+ cancelTimeout: 3e4,
105
+ onCrash: () => ids.clear(),
106
+ packageVersion: environment.version,
107
+ workerAsset: environment.asset ?? "inline"
108
+ });
109
+ async function ready() {
110
+ if (destroyed) throw new Error("The image engine has been destroyed.");
111
+ startWorker ??= await environment.loadWorker();
112
+ }
113
+ async function run(signal, work) {
114
+ throwIfAborted(signal);
115
+ try {
116
+ await ready();
117
+ return await work();
118
+ } catch (error) {
119
+ if (error instanceof TypeError) throw error;
120
+ if (signal?.aborted) throw abortError(signal);
121
+ throw asImageError(error);
122
+ }
123
+ }
124
+ const callOptions = (options) => options?.signal ? { signal: options.signal } : {};
125
+ return {
126
+ [ENGINE_INTERNALS]: {
127
+ client: async () => {
128
+ await ready();
129
+ return client;
130
+ },
131
+ has: (id) => ids.has(id)
132
+ },
133
+ probe(file, options) {
134
+ return run(options?.signal, () => client.call("probe", { file }, callOptions(options)));
135
+ },
136
+ async register(id, file, probe, options) {
137
+ if (destroyed) throw new Error("The image engine has been destroyed.");
138
+ if (ids.has(id)) throw new TypeError(`The source id "${id}" is already in use.`);
139
+ ids.add(id);
140
+ try {
141
+ const size = await run(options?.signal, () => client.call("register", {
142
+ id,
143
+ file,
144
+ probe,
145
+ limits: Object.fromEntries(PER_FILE_LIMITS.map((limit) => [limit, (options?.filePolicy ?? imageLimits.resolve()).limits[limit].maximum]))
146
+ }, callOptions(options)));
147
+ options?.onProgress?.(1);
148
+ return {
149
+ id,
150
+ format: probe.format,
151
+ width: size.width,
152
+ height: size.height,
153
+ frames: 1,
154
+ hasAlpha: probe.hasAlpha,
155
+ decodedBytes: size.width * size.height * 4
156
+ };
157
+ } catch (error) {
158
+ ids.delete(id);
159
+ if (options?.signal?.aborted && !destroyed) client.call("release", { id }).catch(() => void 0);
160
+ throw error;
161
+ }
162
+ },
163
+ async thumbnail(id, maxSize, options) {
164
+ if (!ids.has(id)) throw new TypeError(`There's no source with the id "${id}".`);
165
+ if (!(maxSize >= 1)) throw new RangeError("maxSize must be at least 1.");
166
+ return run(options?.signal, () => client.call("thumbnail", {
167
+ id,
168
+ maxSize
169
+ }, callOptions(options)));
170
+ },
171
+ async release(id) {
172
+ if (!ids.delete(id) || destroyed) return;
173
+ await run(void 0, () => client.call("release", { id }));
174
+ },
175
+ async destroy() {
176
+ if (destroyed) return;
177
+ destroyed = true;
178
+ ids.clear();
179
+ client.destroy();
180
+ }
181
+ };
182
+ }
183
+ // src/adapters/image-processor.ts
184
+ var FORMATS = /* @__PURE__ */ new Set([
185
+ "png",
186
+ "jpeg",
187
+ "webp"
188
+ ]);
189
+ function createImageProcessor(engine) {
190
+ const internals = engineInternals(engine);
191
+ if (!internals) throw new TypeError("createImageProcessor needs an engine from createImageEngine.");
192
+ let destroyed = false;
193
+ return {
194
+ async export(job, options) {
195
+ if (destroyed) throw new Error("The image processor has been destroyed.");
196
+ const { plan, format } = job;
197
+ if (!FORMATS.has(format.type)) throw new TypeError(`"${String(format.type)}" isn't an export format.`);
198
+ if (format.type !== "png" && format.quality !== void 0) {
199
+ if (!(format.quality >= 0 && format.quality <= 1)) throw new RangeError("quality must be from 0 to 1.");
200
+ }
201
+ if (!internals.has(plan.base.source)) throw new TypeError(`There's no source with the id "${plan.base.source}".`);
202
+ const signal = options?.signal;
203
+ throwIfAborted(signal);
204
+ const policy = options?.filePolicy ?? imageLimits.resolve();
205
+ try {
206
+ const blob = await (await internals.client()).call("export", {
207
+ plan,
208
+ format,
209
+ limits: Object.fromEntries(OUTPUT_LIMITS.map((limit) => [limit, policy.limits[limit].maximum]))
210
+ }, signal ? { signal } : {});
211
+ options?.onProgress?.(1);
212
+ return blob;
213
+ } catch (error) {
214
+ if (error instanceof TypeError) throw error;
215
+ if (signal?.aborted) throw abortError(signal);
216
+ throw asImageError(error);
217
+ }
218
+ },
219
+ async destroy() {
220
+ destroyed = true;
221
+ }
222
+ };
223
+ }
224
+ // src/core/ports/image-renderer.ts
225
+ var MAX_PIXEL_RATIO = 4;
226
+ function backingSize(view) {
227
+ const ratio = Math.min(view.pixelRatio, 4);
228
+ return {
229
+ width: Math.max(1, Math.round(view.width * ratio)),
230
+ height: Math.max(1, Math.round(view.height * ratio))
231
+ };
232
+ }
233
+ function fittedView(width, height, pixelRatio = 1) {
234
+ return {
235
+ width,
236
+ height,
237
+ pixelRatio,
238
+ zoom: 1,
239
+ pan: {
240
+ x: 0,
241
+ y: 0
242
+ }
243
+ };
244
+ }
245
+ function placement(composition, view) {
246
+ const inset = view.inset ?? 0;
247
+ const fit = Math.min((view.width - 2 * inset) / composition.width, (view.height - 2 * inset) / composition.height);
248
+ const scale = Math.max(0, fit) * view.zoom;
249
+ const width = composition.width * scale;
250
+ const height = composition.height * scale;
251
+ return {
252
+ x: (view.width - width) / 2 + view.pan.x,
253
+ y: (view.height - height) / 2 + view.pan.y,
254
+ width,
255
+ height,
256
+ scale
257
+ };
258
+ }
259
+ // src/adapters/image-renderer.ts
260
+ var RENDERER_INTERNALS = Symbol("hm-image-renderer");
261
+ var nextCanvasId = 0;
262
+ function checkView(view) {
263
+ const positive = (n) => Number.isFinite(n) && n > 0;
264
+ if (!positive(view.width) || !positive(view.height) || !positive(view.pixelRatio) || !positive(view.zoom) || !Number.isFinite(view.pan.x) || !Number.isFinite(view.pan.y) || view.inset !== void 0 && !(view.inset >= 0 && 2 * view.inset < Math.min(view.width, view.height))) throw new RangeError("A view needs a positive size, pixel ratio and zoom, a finite pan, and an inset under half its size.");
265
+ }
266
+ function createImageRenderer(engine) {
267
+ const internals = engineInternals(engine);
268
+ if (!internals) throw new TypeError("createImageRenderer needs an engine from createImageEngine.");
269
+ nextCanvasId += 1;
270
+ const id = `preview-${nextCanvasId}`;
271
+ let attached = false;
272
+ let destroyed = false;
273
+ let drawn = 0;
274
+ let pending;
275
+ let inFlight;
276
+ const pump = () => {
277
+ if (inFlight || !pending) return;
278
+ const request = pending;
279
+ pending = void 0;
280
+ const controller = new AbortController();
281
+ const onAbort = () => controller.abort(request.signal?.reason);
282
+ request.signal?.addEventListener("abort", onAbort, { once: true });
283
+ inFlight = { controller };
284
+ internals.client().then((client) => client.call("render", {
285
+ id,
286
+ plan: request.plan,
287
+ view: request.view,
288
+ limits: request.limits
289
+ }, { signal: controller.signal })).then(() => {
290
+ drawn += 1;
291
+ request.resolve("drawn");
292
+ }, (error) => {
293
+ if (request.signal?.aborted) request.reject(abortError(request.signal));
294
+ else if (controller.signal.aborted) request.resolve("superseded");
295
+ else request.reject(error instanceof TypeError ? error : asImageError(error));
296
+ }).finally(() => {
297
+ request.signal?.removeEventListener("abort", onAbort);
298
+ inFlight = void 0;
299
+ pump();
300
+ });
301
+ };
302
+ return {
303
+ [RENDERER_INTERNALS]: {
304
+ snapshot: async () => (await internals.client()).call("snapshot", { id }),
305
+ drawn: () => drawn
306
+ },
307
+ async attach(canvas) {
308
+ if (destroyed) throw new Error("The image renderer has been destroyed.");
309
+ if (attached) throw new TypeError("The renderer already has a canvas.");
310
+ if (typeof canvas.transferControlToOffscreen !== "function") throw new ImageError("UNSUPPORTED_ENVIRONMENT", "This browser can't draw the preview in a worker.", { details: { feature: "transferControlToOffscreen" } });
311
+ const offscreen = canvas.transferControlToOffscreen();
312
+ try {
313
+ await (await internals.client()).call("attachCanvas", {
314
+ id,
315
+ canvas: offscreen
316
+ }, { transfer: true });
317
+ attached = true;
318
+ } catch (error) {
319
+ throw asImageError(error);
320
+ }
321
+ },
322
+ render(plan, view, options) {
323
+ if (destroyed) return Promise.reject(/* @__PURE__ */ new Error("The image renderer has been destroyed."));
324
+ if (!attached) return Promise.reject(/* @__PURE__ */ new TypeError("Attach a canvas before rendering."));
325
+ if (!internals.has(plan.base.source)) return Promise.reject(/* @__PURE__ */ new TypeError(`There's no source with the id "${plan.base.source}".`));
326
+ const policy = options?.filePolicy ?? imageLimits.resolve();
327
+ try {
328
+ checkView(view);
329
+ checkOutputLimits(policy, backingSize(view));
330
+ throwIfAborted(options?.signal);
331
+ } catch (error) {
332
+ return Promise.reject(error);
333
+ }
334
+ const limits = Object.fromEntries(OUTPUT_LIMITS.map((limit) => [limit, policy.limits[limit].maximum]));
335
+ return new Promise((resolve, reject) => {
336
+ pending?.resolve("superseded");
337
+ pending = {
338
+ plan,
339
+ view,
340
+ resolve,
341
+ reject,
342
+ signal: options?.signal,
343
+ limits
344
+ };
345
+ inFlight?.controller.abort(new DOMException("A later render replaced this one.", "AbortError"));
346
+ pump();
347
+ });
348
+ },
349
+ async destroy() {
350
+ if (destroyed) return;
351
+ destroyed = true;
352
+ pending?.resolve("superseded");
353
+ pending = void 0;
354
+ inFlight?.controller.abort(new DOMException("The renderer was destroyed.", "AbortError"));
355
+ if (attached) try {
356
+ await (await internals.client()).call("detachCanvas", { id });
357
+ } catch {}
358
+ }
359
+ };
360
+ }
361
+ // src/core/model/plan.ts
362
+ var DEVELOP_ADJUSTMENTS = [
363
+ "temperature",
364
+ "tint",
365
+ "exposure",
366
+ "highlights",
367
+ "shadows",
368
+ "contrast",
369
+ "saturation",
370
+ "vibrance"
371
+ ];
372
+ var NEUTRAL_DEVELOP = Object.freeze({
373
+ temperature: 0,
374
+ tint: 0,
375
+ exposure: 0,
376
+ highlights: 0,
377
+ shadows: 0,
378
+ contrast: 0,
379
+ saturation: 0,
380
+ vibrance: 0
381
+ });
382
+ var FILTER_PRESETS = [
383
+ "vivid",
384
+ "warm",
385
+ "cool",
386
+ "fade",
387
+ "mono",
388
+ "noir",
389
+ "sepia"
390
+ ];
391
+ var UPRIGHT = Object.freeze({
392
+ rotate: 0,
393
+ flipX: false,
394
+ flipY: false
395
+ });
396
+ var FULL_SIZE = Object.freeze({
397
+ kind: "scale",
398
+ scale: 1
399
+ });
400
+ function createPlan(source) {
401
+ return {
402
+ base: {
403
+ source,
404
+ crop: null,
405
+ orientation: UPRIGHT,
406
+ develop: NEUTRAL_DEVELOP,
407
+ filter: null
408
+ },
409
+ output: FULL_SIZE,
410
+ metadata: {
411
+ title: "",
412
+ description: "",
413
+ artist: "",
414
+ copyright: ""
415
+ }
416
+ };
417
+ }
418
+ function isValidCrop(crop, source) {
419
+ const { x, y, width, height } = crop;
420
+ return [
421
+ x,
422
+ y,
423
+ width,
424
+ height
425
+ ].every(Number.isSafeInteger) && x >= 0 && y >= 0 && width >= 1 && height >= 1 && x + width <= source.width && y + height <= source.height;
426
+ }
427
+ // src/core/model/source.ts
428
+ var NO_METADATA = Object.freeze({
429
+ location: false,
430
+ camera: false,
431
+ timestamps: false,
432
+ thumbnail: false,
433
+ colourProfile: false,
434
+ other: false
435
+ });
436
+ var EMPTY_KEEPABLE_METADATA = Object.freeze({
437
+ title: "",
438
+ description: "",
439
+ artist: "",
440
+ copyright: ""
441
+ });
442
+ var MAX_METADATA_LENGTH = 2e3;
443
+ function longerThan(text, max) {
444
+ if (text.length <= max) return false;
445
+ let count = 0;
446
+ for (const _ of text) {
447
+ count += 1;
448
+ if (count > max) return true;
449
+ }
450
+ return false;
451
+ }
452
+ // src/core/operations/commands.ts
453
+ var Invalid = class extends Error {
454
+ reason;
455
+ constructor(reason, message) {
456
+ super(message);
457
+ this.reason = reason;
458
+ }
459
+ };
460
+ function invalid(reason, message) {
461
+ throw new Invalid(reason, message);
462
+ }
463
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
464
+ function onlyFields(value, fields, what) {
465
+ for (const name of Object.keys(value)) if (!fields.includes(name)) invalid("malformed-command", `${what} has no field "${name}"`);
466
+ }
467
+ function allFields(value, fields, what) {
468
+ onlyFields(value, fields, what);
469
+ for (const name of fields) if (!Object.hasOwn(value, name)) invalid("malformed-command", `${what} needs "${name}"`);
470
+ }
471
+ var isWhole = (value, min, max = Number.MAX_SAFE_INTEGER) => Number.isSafeInteger(value) && value >= min && value <= max;
472
+ function checkCrop(value) {
473
+ if (!isRecord(value)) invalid("malformed-command", "a crop is an object");
474
+ allFields(value, [
475
+ "x",
476
+ "y",
477
+ "width",
478
+ "height"
479
+ ], "a crop");
480
+ const { x, y, width, height } = value;
481
+ if (!isWhole(x, 0) || !isWhole(y, 0) || !isWhole(width, 1) || !isWhole(height, 1)) invalid("malformed-command", "a crop is whole pixels from 0, at least 1 × 1");
482
+ return {
483
+ x,
484
+ y,
485
+ width,
486
+ height
487
+ };
488
+ }
489
+ function checkCropInSource(crop, source) {
490
+ if (!isValidCrop(crop, source)) invalid("crop-outside-source", "a crop must fit inside its source");
491
+ }
492
+ function checkOrientation(value) {
493
+ if (!isRecord(value)) invalid("malformed-command", "an orientation is an object");
494
+ allFields(value, [
495
+ "rotate",
496
+ "flipX",
497
+ "flipY"
498
+ ], "an orientation");
499
+ const { rotate, flipX, flipY } = value;
500
+ if (typeof flipX !== "boolean" || typeof flipY !== "boolean") invalid("malformed-command", "an orientation's flips are booleans");
501
+ if (![
502
+ 0,
503
+ 90,
504
+ 180,
505
+ 270
506
+ ].includes(rotate)) invalid("invalid-orientation", "a rotation is 0, 90, 180 or 270 degrees");
507
+ return {
508
+ rotate,
509
+ flipX,
510
+ flipY
511
+ };
512
+ }
513
+ function checkOutput(value) {
514
+ if (!isRecord(value)) invalid("malformed-command", "an output is an object");
515
+ if (value.kind === "scale") {
516
+ allFields(value, ["kind", "scale"], "a scale output");
517
+ if (typeof value.scale !== "number") invalid("malformed-command", "a scale is a number");
518
+ if (!(Number.isFinite(value.scale) && value.scale > 0 && value.scale <= 1)) invalid("invalid-output", "an output scale is more than 0 and at most 1");
519
+ return {
520
+ kind: "scale",
521
+ scale: value.scale
522
+ };
523
+ }
524
+ if (value.kind === "fit") {
525
+ allFields(value, [
526
+ "kind",
527
+ "width",
528
+ "height"
529
+ ], "a box output");
530
+ const { width, height } = value;
531
+ if (!Number.isInteger(width) || !Number.isInteger(height)) invalid("malformed-command", "a box's width and height are whole numbers");
532
+ if (!isWhole(width, 1) || !isWhole(height, 1)) invalid("invalid-output", "an output box is at least 1 × 1 pixel");
533
+ return {
534
+ kind: "fit",
535
+ width,
536
+ height
537
+ };
538
+ }
539
+ return invalid("malformed-command", "an output is either a scale or a box to fit");
540
+ }
541
+ var METADATA_FIELDS = [
542
+ "title",
543
+ "description",
544
+ "artist",
545
+ "copyright"
546
+ ];
547
+ function checkMetadataValue(field, value) {
548
+ if (typeof value !== "string") invalid("malformed-command", `metadata.${field} is text`);
549
+ if (longerThan(value, 2e3)) invalid("metadata-too-long", `metadata.${field} has more than ${MAX_METADATA_LENGTH} code points`);
550
+ return value;
551
+ }
552
+ function checkMetadata(value) {
553
+ if (!isRecord(value)) invalid("malformed-command", "metadata is an object");
554
+ allFields(value, METADATA_FIELDS, "metadata");
555
+ return Object.fromEntries(METADATA_FIELDS.map((field) => [field, checkMetadataValue(field, value[field])]));
556
+ }
557
+ var ADJUSTMENTS = DEVELOP_ADJUSTMENTS;
558
+ var PRESETS = FILTER_PRESETS;
559
+ function checkDevelop(value, all = false) {
560
+ if (!isRecord(value)) invalid("malformed-command", "develop values are an object");
561
+ const values = {};
562
+ for (const [name, level] of Object.entries(value)) {
563
+ if (!ADJUSTMENTS.includes(name)) invalid("unknown-adjustment", `"${name}" isn't a develop adjustment`);
564
+ if (typeof level !== "number") invalid("malformed-command", `${name} is a number`);
565
+ if (!isWhole(level, -100, 100)) invalid("invalid-level", `${name} is a whole number from -100 to 100`);
566
+ values[name] = level;
567
+ }
568
+ if (all) allFields(value, ADJUSTMENTS, "develop");
569
+ return Object.fromEntries(DEVELOP_ADJUSTMENTS.filter((name) => name in values).map((name) => [name, values[name]]));
570
+ }
571
+ function checkFilter(value) {
572
+ if (value === null) return null;
573
+ if (!isRecord(value)) invalid("malformed-command", "a filter is an object or null");
574
+ allFields(value, ["preset", "strength"], "a filter");
575
+ if (typeof value.preset !== "string") invalid("malformed-command", "a filter's preset is text");
576
+ if (!PRESETS.includes(value.preset)) invalid("unknown-preset", `a filter's preset is one of ${FILTER_PRESETS.join(", ")}`);
577
+ if (typeof value.strength !== "number") invalid("malformed-command", "a filter's strength is a number");
578
+ if (!isWhole(value.strength, 0, 100)) invalid("invalid-strength", "a filter's strength is a whole number from 0 to 100");
579
+ return {
580
+ preset: value.preset,
581
+ strength: value.strength
582
+ };
583
+ }
584
+ var COMMAND_FIELDS = {
585
+ "image.setCrop": ["type", "crop"],
586
+ "image.setOrientation": ["type", "orientation"],
587
+ "image.setOutput": ["type", "output"],
588
+ "image.setMetadata": [
589
+ "type",
590
+ "field",
591
+ "value"
592
+ ],
593
+ "image.setDevelop": ["type", "values"],
594
+ "image.setFilter": ["type", "filter"]
595
+ };
596
+ function apply(plan, input, sourceSize) {
597
+ if (!isRecord(input)) invalid("malformed-command", "a command is an object");
598
+ const { type } = input;
599
+ if (typeof type !== "string") invalid("malformed-command", "a command's type is text");
600
+ if (!Object.hasOwn(COMMAND_FIELDS, type)) invalid("unknown-command", `"${type}" isn't a command`);
601
+ const command = input;
602
+ allFields(command, COMMAND_FIELDS[command.type], `${command.type}`);
603
+ switch (command.type) {
604
+ case "image.setCrop": {
605
+ const crop = command.crop === null ? null : checkCrop(command.crop);
606
+ if (crop !== null) {
607
+ const size = sourceSize(plan.base.source);
608
+ if (size === void 0) invalid("unknown-source", `unknown source "${plan.base.source}"`);
609
+ checkCropInSource(crop, size);
610
+ }
611
+ return {
612
+ state: {
613
+ ...plan,
614
+ base: {
615
+ ...plan.base,
616
+ crop
617
+ }
618
+ },
619
+ inverse: {
620
+ type: "image.setCrop",
621
+ crop: plan.base.crop
622
+ }
623
+ };
624
+ }
625
+ case "image.setOrientation": {
626
+ const orientation = checkOrientation(command.orientation);
627
+ return {
628
+ state: {
629
+ ...plan,
630
+ base: {
631
+ ...plan.base,
632
+ orientation
633
+ }
634
+ },
635
+ inverse: {
636
+ type: "image.setOrientation",
637
+ orientation: plan.base.orientation
638
+ }
639
+ };
640
+ }
641
+ case "image.setOutput": {
642
+ const output = checkOutput(command.output);
643
+ return {
644
+ state: {
645
+ ...plan,
646
+ output
647
+ },
648
+ inverse: {
649
+ type: "image.setOutput",
650
+ output: plan.output
651
+ }
652
+ };
653
+ }
654
+ case "image.setMetadata": {
655
+ const { field } = command;
656
+ if (typeof field !== "string") invalid("malformed-command", "a metadata field is text");
657
+ if (!METADATA_FIELDS.includes(field)) invalid("unknown-metadata-field", "only title, description, artist and copyright are kept");
658
+ const value = checkMetadataValue(field, command.value);
659
+ return {
660
+ state: {
661
+ ...plan,
662
+ metadata: {
663
+ ...plan.metadata,
664
+ [field]: value
665
+ }
666
+ },
667
+ inverse: {
668
+ type: "image.setMetadata",
669
+ field,
670
+ value: plan.metadata[field]
671
+ }
672
+ };
673
+ }
674
+ case "image.setDevelop": {
675
+ const values = checkDevelop(command.values);
676
+ const previous = {};
677
+ for (const name of Object.keys(values)) previous[name] = plan.base.develop[name];
678
+ return {
679
+ state: {
680
+ ...plan,
681
+ base: {
682
+ ...plan.base,
683
+ develop: {
684
+ ...plan.base.develop,
685
+ ...values
686
+ }
687
+ }
688
+ },
689
+ inverse: {
690
+ type: "image.setDevelop",
691
+ values: previous
692
+ }
693
+ };
694
+ }
695
+ case "image.setFilter": {
696
+ const filter = checkFilter(command.filter);
697
+ return {
698
+ state: {
699
+ ...plan,
700
+ base: {
701
+ ...plan.base,
702
+ filter
703
+ }
704
+ },
705
+ inverse: {
706
+ type: "image.setFilter",
707
+ filter: plan.base.filter
708
+ }
709
+ };
710
+ }
711
+ }
712
+ }
713
+ function createImageReducer(sourceSize) {
714
+ return (plan, command) => {
715
+ try {
716
+ return apply(plan, command, sourceSize);
717
+ } catch (error) {
718
+ if (!(error instanceof Invalid)) throw error;
719
+ throw new ImageError("INVALID_COMMAND", `Invalid command: ${error.message}.`, { details: { reason: error.reason } });
720
+ }
721
+ };
722
+ }
723
+ // src/core/model/geometry.ts
724
+ function orientedSize(stored, orientation) {
725
+ return orientation >= 5 ? {
726
+ width: stored.height,
727
+ height: stored.width
728
+ } : stored;
729
+ }
730
+ function cropRect(crop, source) {
731
+ return crop ?? {
732
+ x: 0,
733
+ y: 0,
734
+ width: source.width,
735
+ height: source.height
736
+ };
737
+ }
738
+ function compositionSize(plan, source) {
739
+ const { width, height } = cropRect(plan.base.crop, source);
740
+ return plan.base.orientation.rotate % 180 !== 0 ? {
741
+ width: height,
742
+ height: width
743
+ } : {
744
+ width,
745
+ height
746
+ };
747
+ }
748
+ function outputSize(output, composition) {
749
+ const factor = output.kind === "scale" ? output.scale : Math.min(1, output.width / composition.width, output.height / composition.height);
750
+ return {
751
+ width: Math.max(1, Math.round(composition.width * factor)),
752
+ height: Math.max(1, Math.round(composition.height * factor))
753
+ };
754
+ }
755
+ function sourceToComposition(point, crop, orientation) {
756
+ const x = point.x - crop.x;
757
+ const y = point.y - crop.y;
758
+ const { width, height } = crop;
759
+ let turned;
760
+ switch (orientation.rotate) {
761
+ case 90:
762
+ turned = {
763
+ x: height - y,
764
+ y: x
765
+ };
766
+ break;
767
+ case 180:
768
+ turned = {
769
+ x: width - x,
770
+ y: height - y
771
+ };
772
+ break;
773
+ case 270:
774
+ turned = {
775
+ x: y,
776
+ y: width - x
777
+ };
778
+ break;
779
+ default: turned = {
780
+ x,
781
+ y
782
+ };
783
+ }
784
+ const size = orientation.rotate % 180 === 0 ? {
785
+ width,
786
+ height
787
+ } : {
788
+ width: height,
789
+ height: width
790
+ };
791
+ return {
792
+ x: orientation.flipX ? size.width - turned.x : turned.x,
793
+ y: orientation.flipY ? size.height - turned.y : turned.y
794
+ };
795
+ }
796
+ function compositionToSource(point, crop, orientation) {
797
+ const { width, height } = crop;
798
+ const size = orientation.rotate % 180 === 0 ? {
799
+ width,
800
+ height
801
+ } : {
802
+ width: height,
803
+ height: width
804
+ };
805
+ const x = orientation.flipX ? size.width - point.x : point.x;
806
+ const y = orientation.flipY ? size.height - point.y : point.y;
807
+ let source;
808
+ switch (orientation.rotate) {
809
+ case 90:
810
+ source = {
811
+ x: y,
812
+ y: height - x
813
+ };
814
+ break;
815
+ case 180:
816
+ source = {
817
+ x: width - x,
818
+ y: height - y
819
+ };
820
+ break;
821
+ case 270:
822
+ source = {
823
+ x: width - y,
824
+ y: x
825
+ };
826
+ break;
827
+ default: source = {
828
+ x,
829
+ y
830
+ };
831
+ }
832
+ return {
833
+ x: source.x + crop.x,
834
+ y: source.y + crop.y
835
+ };
836
+ }
837
+ // src/core/model/crop.ts
838
+ var ASPECT_PRESETS = [
839
+ "free",
840
+ "original",
841
+ [1, 1],
842
+ [4, 3],
843
+ [3, 2],
844
+ [16, 9],
845
+ [3, 4],
846
+ [2, 3],
847
+ [9, 16]
848
+ ];
849
+ function aspectRatio(aspect, source) {
850
+ if (aspect === "free") return void 0;
851
+ if (aspect === "original") return source.width / source.height;
852
+ return aspect[0] / aspect[1];
853
+ }
854
+ var wholeCrop = (source) => ({
855
+ x: 0,
856
+ y: 0,
857
+ width: source.width,
858
+ height: source.height
859
+ });
860
+ function fitAspect(within, ratio) {
861
+ if (ratio === void 0) return within;
862
+ let width = within.width;
863
+ let height = Math.round(width / ratio);
864
+ if (height > within.height) {
865
+ height = within.height;
866
+ width = Math.round(height * ratio);
867
+ }
868
+ width = Math.max(1, Math.min(within.width, width));
869
+ height = Math.max(1, Math.min(within.height, height));
870
+ return {
871
+ x: within.x + Math.floor((within.width - width) / 2),
872
+ y: within.y + Math.floor((within.height - height) / 2),
873
+ width,
874
+ height
875
+ };
876
+ }
877
+ function moveCrop(crop, dx, dy, source) {
878
+ return {
879
+ ...crop,
880
+ x: Math.min(source.width - crop.width, Math.max(0, crop.x + Math.round(dx))),
881
+ y: Math.min(source.height - crop.height, Math.max(0, crop.y + Math.round(dy)))
882
+ };
883
+ }
884
+ function dragHandle(crop, handle, dx, dy, source, ratio) {
885
+ let left = crop.x;
886
+ let top = crop.y;
887
+ let right = crop.x + crop.width;
888
+ let bottom = crop.y + crop.height;
889
+ if (handle.includes("w")) left = Math.min(right - 1, Math.max(0, left + dx));
890
+ if (handle.includes("e")) right = Math.max(left + 1, Math.min(source.width, right + dx));
891
+ if (handle.includes("n")) top = Math.min(bottom - 1, Math.max(0, top + dy));
892
+ if (handle.includes("s")) bottom = Math.max(top + 1, Math.min(source.height, bottom + dy));
893
+ left = Math.round(left);
894
+ right = Math.round(right);
895
+ top = Math.round(top);
896
+ bottom = Math.round(bottom);
897
+ if (ratio === void 0) return {
898
+ x: left,
899
+ y: top,
900
+ width: right - left,
901
+ height: bottom - top
902
+ };
903
+ const horizontal = handle.includes("e") || handle.includes("w");
904
+ const vertical = handle.includes("n") || handle.includes("s");
905
+ let width = right - left;
906
+ let height = bottom - top;
907
+ if (horizontal && !vertical) height = width / ratio;
908
+ else if (vertical && !horizontal) width = height * ratio;
909
+ else if (width / height > ratio) width = height * ratio;
910
+ else height = width / ratio;
911
+ const roomRight = handle.includes("w") ? right : source.width - left;
912
+ const roomDown = handle.includes("n") ? bottom : source.height - top;
913
+ const scale = Math.min(1, roomRight / width, roomDown / height);
914
+ width = Math.max(1, Math.round(width * scale));
915
+ height = Math.max(1, Math.round(height * scale));
916
+ const x = handle.includes("w") ? right - width : left;
917
+ let y = handle.includes("n") ? bottom - height : top;
918
+ let cx = x;
919
+ if (vertical && !horizontal) cx = Math.round(crop.x + (crop.width - width) / 2);
920
+ if (horizontal && !vertical) y = Math.round(crop.y + (crop.height - height) / 2);
921
+ return {
922
+ x: Math.min(source.width - width, Math.max(0, cx)),
923
+ y: Math.min(source.height - height, Math.max(0, y)),
924
+ width,
925
+ height
926
+ };
927
+ }
928
+ function cropInComposition(crop, orientation, source) {
929
+ const whole = wholeCrop(source);
930
+ const a = sourceToComposition({
931
+ x: crop.x,
932
+ y: crop.y
933
+ }, whole, orientation);
934
+ const b = sourceToComposition({
935
+ x: crop.x + crop.width,
936
+ y: crop.y + crop.height
937
+ }, whole, orientation);
938
+ return {
939
+ x: Math.min(a.x, b.x),
940
+ y: Math.min(a.y, b.y),
941
+ width: Math.abs(b.x - a.x),
942
+ height: Math.abs(b.y - a.y)
943
+ };
944
+ }
945
+ function compositionDeltaToSource(dx, dy, orientation, source) {
946
+ const whole = wholeCrop(source);
947
+ const origin = compositionToSource({
948
+ x: 0,
949
+ y: 0
950
+ }, whole, orientation);
951
+ const moved = compositionToSource({
952
+ x: dx,
953
+ y: dy
954
+ }, whole, orientation);
955
+ return {
956
+ dx: moved.x - origin.x,
957
+ dy: moved.y - origin.y
958
+ };
959
+ }
960
+ function handleInSource(handle, orientation) {
961
+ const vector = {
962
+ x: 0,
963
+ y: 0
964
+ };
965
+ if (handle.includes("e")) vector.x = 1;
966
+ if (handle.includes("w")) vector.x = -1;
967
+ if (handle.includes("s")) vector.y = 1;
968
+ if (handle.includes("n")) vector.y = -1;
969
+ const unit = compositionDeltaToSource(vector.x, vector.y, orientation, {
970
+ width: 2,
971
+ height: 2
972
+ });
973
+ return `${unit.dy > 0 ? "s" : unit.dy < 0 ? "n" : ""}${unit.dx > 0 ? "e" : unit.dx < 0 ? "w" : ""}`;
974
+ }
975
+ function nudgeCropOnScreen(crop, key, step, resize, orientation, source, ratio) {
976
+ const dx = key === "ArrowLeft" ? -step : key === "ArrowRight" ? step : 0;
977
+ const moved = compositionDeltaToSource(dx, key === "ArrowUp" ? -step : key === "ArrowDown" ? step : 0, orientation, source);
978
+ if (!resize) return moveCrop(crop, moved.dx, moved.dy, source);
979
+ return dragHandle(crop, handleInSource(dx === 0 ? "s" : "e", orientation), moved.dx, moved.dy, source, ratio);
980
+ }
981
+ // src/core/session/session.ts
982
+ var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
983
+ function commandsBetween(from, to) {
984
+ const commands = [];
985
+ if (!same(from.base.crop, to.base.crop)) commands.push({
986
+ type: "image.setCrop",
987
+ crop: to.base.crop
988
+ });
989
+ if (!same(from.base.orientation, to.base.orientation)) commands.push({
990
+ type: "image.setOrientation",
991
+ orientation: to.base.orientation
992
+ });
993
+ const develop = Object.fromEntries(Object.entries(to.base.develop).filter(([name, value]) => from.base.develop[name] !== value));
994
+ if (Object.keys(develop).length > 0) commands.push({
995
+ type: "image.setDevelop",
996
+ values: develop
997
+ });
998
+ if (!same(from.base.filter, to.base.filter)) commands.push({
999
+ type: "image.setFilter",
1000
+ filter: to.base.filter
1001
+ });
1002
+ if (!same(from.output, to.output)) commands.push({
1003
+ type: "image.setOutput",
1004
+ output: to.output
1005
+ });
1006
+ for (const field of Object.keys(to.metadata)) if (from.metadata[field] !== to.metadata[field]) commands.push({
1007
+ type: "image.setMetadata",
1008
+ field,
1009
+ value: to.metadata[field]
1010
+ });
1011
+ return commands;
1012
+ }
1013
+ var PRESENCE = [
1014
+ "location",
1015
+ "camera",
1016
+ "timestamps",
1017
+ "thumbnail",
1018
+ "colourProfile",
1019
+ "other"
1020
+ ];
1021
+ function checkSource(policy, file, probe) {
1022
+ const near = checkFileLimits(policy, file.size, probe);
1023
+ const bytes = probe.oriented.width * probe.oriented.height * 4;
1024
+ if (policy.check("maxSessionSize", bytes) === "warning") near.push("maxSessionSize");
1025
+ return near;
1026
+ }
1027
+ function createImageSession(options) {
1028
+ const { engine, processor } = options;
1029
+ const policy = imageLimits.resolve(options.filePolicy);
1030
+ const history = createHistory();
1031
+ let source = null;
1032
+ const reducer = createImageReducer((id) => source !== null && source.id === id ? source : void 0);
1033
+ let plan = null;
1034
+ let opens = 0;
1035
+ let opening = 0;
1036
+ let exporting = 0;
1037
+ let generation = 0;
1038
+ let warnings = [];
1039
+ let error = null;
1040
+ let nextId = 0;
1041
+ let destroyed = false;
1042
+ const snapshot = () => ({
1043
+ status: plan !== null ? "ready" : opening > 0 ? "opening" : "empty",
1044
+ plan,
1045
+ source,
1046
+ canUndo: history.canUndo,
1047
+ canRedo: history.canRedo,
1048
+ opening: opening > 0,
1049
+ exporting: exporting > 0,
1050
+ warnings,
1051
+ error
1052
+ });
1053
+ const store = createStore(snapshot());
1054
+ const publish = () => store.set(snapshot());
1055
+ const emit = (event) => {
1056
+ try {
1057
+ options.onEvent?.(event);
1058
+ } catch {}
1059
+ };
1060
+ const assertAlive = () => {
1061
+ if (destroyed) throw new Error("The image session has been destroyed.");
1062
+ };
1063
+ const fail = (reason) => {
1064
+ error = isImageError(reason) ? reason : asImageError(reason);
1065
+ return error;
1066
+ };
1067
+ const superseded = () => new ImageError("ABORTED", "A later open replaced this one.", { details: { reason: "superseded" } });
1068
+ const attempt = (from, commands) => {
1069
+ const { state, inverses } = applyCommands(reducer, from, commands);
1070
+ if (source) checkOutputLimits(policy, outputSize(state.output, compositionSize(state, source)));
1071
+ return {
1072
+ state,
1073
+ step: {
1074
+ commands: [...commands],
1075
+ inverses: [...inverses]
1076
+ }
1077
+ };
1078
+ };
1079
+ const replay = (direction) => {
1080
+ assertAlive();
1081
+ const step = direction === "undo" ? history.undo() : history.redo();
1082
+ if (!step || plan === null) return false;
1083
+ const commands = direction === "undo" ? step.inverses : step.commands;
1084
+ try {
1085
+ plan = applyCommands(reducer, plan, commands).state;
1086
+ } catch (reason) {
1087
+ history.restore(direction);
1088
+ publish();
1089
+ emit({
1090
+ type: direction,
1091
+ outcome: "failed",
1092
+ commands: commands.map((c) => c.type)
1093
+ });
1094
+ throw fail(reason);
1095
+ }
1096
+ error = null;
1097
+ publish();
1098
+ emit({
1099
+ type: direction,
1100
+ outcome: "done",
1101
+ commands: commands.map((c) => c.type)
1102
+ });
1103
+ return true;
1104
+ };
1105
+ const executeCommands = (input) => {
1106
+ assertAlive();
1107
+ const commands = Array.isArray(input) ? input : [input];
1108
+ try {
1109
+ if (plan === null) throw new ImageError("INVALID_COMMAND", "There's nothing to edit before a file is open.");
1110
+ const result = attempt(plan, commands);
1111
+ plan = result.state;
1112
+ history.push(result.step);
1113
+ error = null;
1114
+ emit({
1115
+ type: "execute",
1116
+ outcome: "done",
1117
+ commands: commands.map((c) => c.type)
1118
+ });
1119
+ } catch (reason) {
1120
+ emit({
1121
+ type: "execute",
1122
+ outcome: "failed",
1123
+ commands: commands.map((c) => c.type)
1124
+ });
1125
+ throw fail(reason);
1126
+ } finally {
1127
+ publish();
1128
+ }
1129
+ };
1130
+ return {
1131
+ getSnapshot: () => store.getSnapshot(),
1132
+ subscribe: (listener) => store.subscribe(listener),
1133
+ async open(file, openOptions = {}) {
1134
+ assertAlive();
1135
+ const { signal } = openOptions;
1136
+ opens += 1;
1137
+ const ticket = opens;
1138
+ nextId += 1;
1139
+ const id = `source-${nextId}`;
1140
+ let registered = false;
1141
+ opening += 1;
1142
+ publish();
1143
+ try {
1144
+ throwIfAborted(signal);
1145
+ policy.check("maxFileSize", file.size);
1146
+ const probe = await engine.probe(file, signal ? { signal } : {});
1147
+ const near = checkSource(policy, file, probe);
1148
+ if (ticket !== opens) throw superseded();
1149
+ const info = await engine.register(id, file, probe, {
1150
+ filePolicy: policy,
1151
+ ...signal ? { signal } : {}
1152
+ });
1153
+ registered = true;
1154
+ throwIfAborted(signal);
1155
+ assertAlive();
1156
+ if (ticket !== opens) throw superseded();
1157
+ const previous = source;
1158
+ source = {
1159
+ ...info,
1160
+ fileSize: file.size,
1161
+ metadata: probe.metadata,
1162
+ keepable: probe.keepable
1163
+ };
1164
+ plan = createPlan(id);
1165
+ history.clear();
1166
+ generation += 1;
1167
+ warnings = near;
1168
+ error = null;
1169
+ if (previous) engine.release(previous.id).catch(() => {});
1170
+ emit({
1171
+ type: "open",
1172
+ outcome: "done",
1173
+ commands: []
1174
+ });
1175
+ return source;
1176
+ } catch (reason) {
1177
+ if (registered && source?.id !== id) await engine.release(id).catch(() => {});
1178
+ const failure = isImageError(reason) ? reason : asImageError(reason);
1179
+ const cancelled = failure.code === "ABORTED";
1180
+ if (!cancelled) fail(failure);
1181
+ emit({
1182
+ type: "open",
1183
+ outcome: cancelled ? "cancelled" : "failed",
1184
+ commands: []
1185
+ });
1186
+ throw failure;
1187
+ } finally {
1188
+ opening -= 1;
1189
+ publish();
1190
+ }
1191
+ },
1192
+ execute: (input) => executeCommands(input),
1193
+ applyPlan(next) {
1194
+ assertAlive();
1195
+ if (plan === null || next.base.source !== plan.base.source) {
1196
+ const failure = new ImageError("INVALID_COMMAND", "The plan isn't for the open image.");
1197
+ error = failure;
1198
+ publish();
1199
+ throw failure;
1200
+ }
1201
+ const commands = commandsBetween(plan, next);
1202
+ if (commands.length > 0) executeCommands(commands);
1203
+ },
1204
+ group(fn) {
1205
+ assertAlive();
1206
+ return history.group(fn);
1207
+ },
1208
+ undo: () => replay("undo"),
1209
+ redo: () => replay("redo"),
1210
+ async export(format, exportOptions = {}) {
1211
+ assertAlive();
1212
+ const { signal, onProgress } = exportOptions;
1213
+ if (plan === null || source === null) throw new ImageError("INVALID_COMMAND", "There's nothing to export before a file is open.");
1214
+ const started = generation;
1215
+ const exported = plan;
1216
+ const from = source;
1217
+ exporting += 1;
1218
+ publish();
1219
+ try {
1220
+ const size = outputSize(exported.output, compositionSize(exported, from));
1221
+ const blob = await processor.export({
1222
+ plan: exported,
1223
+ format
1224
+ }, {
1225
+ filePolicy: policy,
1226
+ ...signal ? { signal } : {},
1227
+ ...onProgress ? { onProgress } : {}
1228
+ });
1229
+ if (started !== generation || destroyed) throw new ImageError("ABORTED", "Another file was opened during the export.", { details: { reason: "superseded" } });
1230
+ error = null;
1231
+ emit({
1232
+ type: "export",
1233
+ outcome: "done",
1234
+ commands: []
1235
+ });
1236
+ return {
1237
+ blob,
1238
+ width: size.width,
1239
+ height: size.height,
1240
+ removed: PRESENCE.filter((kind) => from.metadata[kind]),
1241
+ kept: Object.keys(exported.metadata).filter((field) => exported.metadata[field] !== "")
1242
+ };
1243
+ } catch (reason) {
1244
+ const failure = isImageError(reason) ? reason : asImageError(reason);
1245
+ const cancelled = failure.code === "ABORTED";
1246
+ if (!cancelled) fail(failure);
1247
+ emit({
1248
+ type: "export",
1249
+ outcome: cancelled ? "cancelled" : "failed",
1250
+ commands: []
1251
+ });
1252
+ throw failure;
1253
+ } finally {
1254
+ exporting -= 1;
1255
+ if (!destroyed) publish();
1256
+ }
1257
+ },
1258
+ async destroy() {
1259
+ if (destroyed) return;
1260
+ destroyed = true;
1261
+ const held = source;
1262
+ source = null;
1263
+ plan = null;
1264
+ history.clear();
1265
+ publish();
1266
+ if (held) await engine.release(held.id).catch(() => {});
1267
+ }
1268
+ };
1269
+ }
1270
+ // src/messages/en.ts
1271
+ var imageMessages = /* @__PURE__ */ defineMessages({
1272
+ ...sdkCoreMessages,
1273
+ ...uiMessages,
1274
+ "errors.INVALID_IMAGE": "This file isn't a valid image, or it's too damaged to open.",
1275
+ "errors.UNSUPPORTED_FORMAT": "This image format isn't supported. Try converting the file to PNG or JPEG, then open it again.",
1276
+ "errors.DECODE_FAILED": "This browser can't open this kind of image. Try another browser, or convert the file to PNG or JPEG.",
1277
+ "errors.INVALID_COMMAND": "This edit couldn't be made. Please try again.",
1278
+ "errors.INVALID_DOCUMENT": "This project is damaged, or it isn't an image project.",
1279
+ "errors.IMAGE_TOO_LARGE": "This image has more pixels than the editor can handle. Try a smaller version of it.",
1280
+ "errors.IMAGE_DIMENSION_TOO_LARGE": "This image is {actual, number} pixels across, which is over the {maximum, number}-pixel limit.",
1281
+ "errors.TOO_MANY_FRAMES": /* @__PURE__ */ plural("maximum", {
1282
+ one: "This animation has {actual, number} frames, which is over the {maximum}-frame limit.",
1283
+ other: "This animation has {actual, number} frames, which is over the {maximum, number}-frame limit."
1284
+ }),
1285
+ "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.",
1286
+ "errors.TOO_MANY_LAYERS": /* @__PURE__ */ plural("maximum", {
1287
+ one: "An image can have {maximum} layer. Merge or delete layers, and try again.",
1288
+ other: "An image can have up to {maximum, number} layers. Merge or delete layers, and try again."
1289
+ }),
1290
+ "warnings.maxImagePixels": "This image is large, and may be slow to edit on some devices.",
1291
+ "warnings.maxImageDimension": "This image is very wide or tall, and may be slow to edit.",
1292
+ "warnings.maxFrames": /* @__PURE__ */ plural("actual", {
1293
+ one: "This animation has {actual} frame.",
1294
+ other: "This animation has {actual, number} frames, and may be slow to edit and export."
1295
+ }),
1296
+ "warnings.maxSessionSize": "The open images use {actual, fileSize} of memory. Clearing the undo history frees memory.",
1297
+ "warnings.maxLayers": /* @__PURE__ */ plural("actual", {
1298
+ one: "This image has {actual} layer.",
1299
+ other: "This image has {actual, number} layers, and may be slow to edit and export."
1300
+ }),
1301
+ "editor.label": "Image editor",
1302
+ "editor.preview": "Edited image preview, {width, number} × {height, number}",
1303
+ "editor.empty": "Open an image to start editing. It stays on this device.",
1304
+ "editor.choose": "Choose an image",
1305
+ "editor.dropHint": "or drop it here",
1306
+ "editor.opening": "Opening the image…",
1307
+ "editor.cancel": "Cancel",
1308
+ "editor.opened": "Image opened, {width, number} × {height, number}.",
1309
+ "editor.undid": "Undid {action}.",
1310
+ "editor.redid": "Redid {action}.",
1311
+ "actions.image.setCrop": "crop",
1312
+ "actions.image.setOrientation": "rotate or flip",
1313
+ "actions.image.setOutput": "size",
1314
+ "actions.image.setMetadata": "metadata",
1315
+ "actions.image.setDevelop": "adjustment",
1316
+ "actions.image.setFilter": "filter",
1317
+ "toolbar.label": "Image tools",
1318
+ "toolbar.groups.file": "File",
1319
+ "toolbar.groups.history": "History",
1320
+ "toolbar.groups.orientation": "Rotate",
1321
+ "toolbar.groups.zoom": "Zoom",
1322
+ "toolbar.groups.other": "More tools",
1323
+ "tools.open": "Open image",
1324
+ "tools.undo": "Undo",
1325
+ "tools.redo": "Redo",
1326
+ "tools.rotate-left": "Rotate left",
1327
+ "tools.rotate-right": "Rotate right",
1328
+ "tools.zoom-in": "Zoom in",
1329
+ "tools.zoom-out": "Zoom out",
1330
+ "tools.zoom-fit": "Fit to the stage",
1331
+ "tools.crop": "Crop",
1332
+ "tools.flip-horizontal": "Flip horizontally",
1333
+ "tools.flip-vertical": "Flip vertically",
1334
+ "toolbar.groups.crop": "Crop",
1335
+ "crop.frame": "Crop area",
1336
+ "crop.frameDescription": "{width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; with Alt, they resize it; Enter applies and Escape cancels.",
1337
+ "crop.size": "{width, number} × {height, number}, from {x, number}, {y, number}",
1338
+ "crop.panel": "Crop",
1339
+ "crop.x": "Left",
1340
+ "crop.y": "Top",
1341
+ "crop.width": "Width",
1342
+ "crop.height": "Height",
1343
+ "crop.aspect": "Aspect ratio",
1344
+ "crop.aspects.free": "Free",
1345
+ "crop.aspects.original": "Original",
1346
+ "crop.aspects.ratio": "{width}:{height}",
1347
+ "crop.apply": "Apply crop",
1348
+ "crop.cancel": "Cancel",
1349
+ "crop.reset": "Whole image",
1350
+ "crop.applied": "Cropped to {width, number} × {height, number}.",
1351
+ "inspector.label": "Panels",
1352
+ "inspector.adjust": "Adjust",
1353
+ "inspector.filters": "Filters",
1354
+ "inspector.info": "Info",
1355
+ "notices.label": "Notices",
1356
+ "notices.dismiss": "Dismiss",
1357
+ "notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.",
1358
+ "info.panel": "Image info",
1359
+ "info.size": "Size",
1360
+ "info.sizeValue": "{width, number} × {height, number} pixels",
1361
+ "info.format": "Format",
1362
+ "info.formats.png": "PNG",
1363
+ "info.formats.jpeg": "JPEG",
1364
+ "info.formats.webp": "WebP",
1365
+ "info.formats.gif": "GIF",
1366
+ "info.formats.avif": "AVIF",
1367
+ "info.formats.heif": "HEIF",
1368
+ "info.formats.bmp": "BMP",
1369
+ "info.frames": "Frames",
1370
+ "info.fileSize": "File size",
1371
+ "info.fileSizeValue": "{size, fileSize}",
1372
+ "info.metadata": "Metadata in the file",
1373
+ "info.metadataNone": "None",
1374
+ "info.kept": "Kept on export",
1375
+ "info.keptNone": "Nothing",
1376
+ "develop.panel": "Adjust",
1377
+ "develop.temperature": "Temperature",
1378
+ "develop.tint": "Tint",
1379
+ "develop.exposure": "Exposure",
1380
+ "develop.highlights": "Highlights",
1381
+ "develop.shadows": "Shadows",
1382
+ "develop.contrast": "Contrast",
1383
+ "develop.saturation": "Saturation",
1384
+ "develop.vibrance": "Vibrance",
1385
+ "develop.reset": "Reset {name}",
1386
+ "develop.resetAll": "Reset all",
1387
+ "develop.wasReset": "All adjustments reset.",
1388
+ "filters.panel": "Filters",
1389
+ "filters.label": "Filter",
1390
+ "filters.none": "None",
1391
+ "filters.vivid": "Vivid",
1392
+ "filters.warm": "Warm",
1393
+ "filters.cool": "Cool",
1394
+ "filters.fade": "Fade",
1395
+ "filters.mono": "Mono",
1396
+ "filters.noir": "Noir",
1397
+ "filters.sepia": "Sepia",
1398
+ "filters.strength": "Strength",
1399
+ "toolbar.groups.export": "Export",
1400
+ "tools.export": "Export",
1401
+ "export.title": "Export image",
1402
+ "export.description": "The file is made on this device, and nothing is uploaded.",
1403
+ "export.format": "Format",
1404
+ "export.formats.png": "PNG",
1405
+ "export.formats.jpeg": "JPEG",
1406
+ "export.formats.webp": "WebP",
1407
+ "export.quality": "Quality",
1408
+ "export.qualityValue": "{quality, number}%",
1409
+ "export.size": "Size",
1410
+ "export.sizes.scale": "Scale",
1411
+ "export.sizes.fit": "Fit in a box",
1412
+ "export.scale": "Scale, in percent",
1413
+ "export.fitWidth": "Largest width",
1414
+ "export.fitHeight": "Largest height",
1415
+ "export.fields": "Details to include",
1416
+ "export.fieldsHint": "Only what you fill in is written to the file.",
1417
+ "export.field.title": "Title",
1418
+ "export.field.description": "Description",
1419
+ "export.field.artist": "Artist",
1420
+ "export.field.copyright": "Copyright",
1421
+ "export.summary": "Summary",
1422
+ "export.output": "{width, number} × {height, number} pixels, {format}",
1423
+ "export.removed": "Removed from the file",
1424
+ "export.removedNone": "The image had no other details to remove.",
1425
+ "export.kind.location": "Location",
1426
+ "export.kind.camera": "Camera details",
1427
+ "export.kind.timestamps": "Dates and times",
1428
+ "export.kind.thumbnail": "Embedded thumbnail",
1429
+ "export.kind.colourProfile": "Colour profile: colours outside sRGB are clipped",
1430
+ "export.kind.other": "Other metadata",
1431
+ "export.kept": "Kept in the file",
1432
+ "export.confirm": "Export",
1433
+ "export.cancel": "Cancel",
1434
+ "export.progress": "Exporting the image",
1435
+ "export.stop": "Stop exporting",
1436
+ "export.cancelled": "Export stopped.",
1437
+ "export.done": "Exported a {format} of {size, fileSize}.",
1438
+ "export.ready": "{width, number} × {height, number} pixels, {format}, {size, fileSize}",
1439
+ "export.download": "Download",
1440
+ "export.close": "Done"
1441
+ });
1442
+ export { imageLimits as $, onlyFields as A, createPlan as B, checkFilter as C, createImageReducer as D, checkOutput as E, DEVELOP_ADJUSTMENTS as F, placement as G, MAX_PIXEL_RATIO as H, FILTER_PRESETS as I, OUTPUT_LIMITS as J, createImageProcessor as K, FULL_SIZE as L, MAX_METADATA_LENGTH as M, NO_METADATA as N, invalid as O, longerThan as P, imageLimitDefinitions as Q, NEUTRAL_DEVELOP as R, checkDevelop as S, checkOrientation as T, backingSize as U, createImageRenderer as V, fittedView as W, checkFileLimits as X, PER_FILE_LIMITS as Y, checkOutputLimits as Z, outputSize as _, compositionDeltaToSource as a, checkCrop as b, fitAspect as c, nudgeCropOnScreen as d, ImageError as et, wholeCrop as f, orientedSize as g, cropRect as h, aspectRatio as i, EMPTY_KEEPABLE_METADATA as j, isRecord as k, handleInSource as l, compositionToSource as m, createImageSession as n, cropInComposition as o, compositionSize as p, createImageEngine as q, ASPECT_PRESETS as r, dragHandle as s, imageMessages as t, isImageError as tt, moveCrop as u, sourceToComposition as v, checkMetadata as w, checkCropInSource as x, Invalid as y, UPRIGHT as z };
1443
+
1444
+ //# sourceMappingURL=core-CAX3GOaj.js.map