@magicpages/kalotyp-core 0.1.1 → 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.
package/dist/index.js CHANGED
@@ -1,1976 +1,2478 @@
1
- class Dn {
2
- listeners = /* @__PURE__ */ new Map();
3
- on(n, e) {
4
- let i = this.listeners.get(n);
5
- return i || (i = /* @__PURE__ */ new Set(), this.listeners.set(n, i)), i.add(e), () => {
6
- i?.delete(e);
7
- };
8
- }
9
- off(n, e) {
10
- this.listeners.get(n)?.delete(e);
11
- }
12
- emit(n, e) {
13
- const i = this.listeners.get(n);
14
- if (i)
15
- for (const r of [...i])
16
- try {
17
- r(e);
18
- } catch (o) {
19
- queueMicrotask(() => {
20
- throw o;
21
- });
22
- }
23
- }
24
- clear() {
25
- this.listeners.clear();
26
- }
27
- }
28
- async function Ln(t) {
29
- if (typeof createImageBitmap == "function") {
30
- const n = await wt(t);
31
- if (n)
32
- try {
33
- const e = await createImageBitmap(n, { imageOrientation: "from-image" });
34
- return { element: e, width: e.width, height: e.height };
35
- } catch {
36
- }
37
- }
38
- return xt(t);
39
- }
40
- async function wt(t) {
41
- if (t instanceof Blob) return t;
42
- if (typeof fetch != "function") return null;
43
- try {
44
- const n = await fetch(t, { credentials: "omit" });
45
- return n.ok ? await n.blob() : null;
46
- } catch {
47
- return null;
48
- }
49
- }
50
- async function xt(t) {
51
- const n = typeof t == "string" ? t : URL.createObjectURL(t), e = typeof t != "string";
52
- try {
53
- const i = await new Promise((r, o) => {
54
- const a = new Image();
55
- a.crossOrigin = "anonymous", a.onload = () => r(a), a.onerror = () => o(new Error(`Failed to load image: ${n}`)), a.src = n;
56
- });
57
- return {
58
- element: i,
59
- width: i.naturalWidth,
60
- height: i.naturalHeight
61
- };
62
- } finally {
63
- e && URL.revokeObjectURL(n);
64
- }
65
- }
66
- const k = Object.freeze({
67
- zoom: 1,
68
- panX: 0,
69
- panY: 0
1
+ //#region src/canvas/bake-canvas.ts
2
+ function e(e, t) {
3
+ if (r()) return {
4
+ kind: "offscreen",
5
+ canvas: new OffscreenCanvas(e, t)
6
+ };
7
+ let n = document.createElement("canvas");
8
+ return n.width = e, n.height = t, {
9
+ kind: "html",
10
+ canvas: n
11
+ };
12
+ }
13
+ function t(e) {
14
+ if (e.kind === "offscreen") {
15
+ let t = e.canvas.getContext("2d");
16
+ if (!t) throw Error("2D canvas context is not available");
17
+ return t;
18
+ }
19
+ let t = e.canvas.getContext("2d");
20
+ if (!t) throw Error("2D canvas context is not available");
21
+ return t;
22
+ }
23
+ async function n(e, t, n) {
24
+ return e.kind === "offscreen" ? e.canvas.convertToBlob({
25
+ type: t,
26
+ quality: n
27
+ }) : new Promise((r, i) => {
28
+ e.canvas.toBlob((e) => {
29
+ e ? r(e) : i(/* @__PURE__ */ Error("toBlob produced null"));
30
+ }, t, n);
31
+ });
32
+ }
33
+ function r() {
34
+ return typeof OffscreenCanvas > "u" ? !1 : typeof OffscreenCanvas.prototype.convertToBlob == "function";
35
+ }
36
+ var i = /* @__PURE__ */ new Map();
37
+ function a(t) {
38
+ let r = i.get(t);
39
+ if (r) return r;
40
+ let a = (async () => {
41
+ try {
42
+ let r = await n(e(1, 1), t, .5);
43
+ return r.type === t && r.size > 0;
44
+ } catch {
45
+ return !1;
46
+ }
47
+ })();
48
+ return i.set(t, a), a;
49
+ }
50
+ //#endregion
51
+ //#region src/canvas/load-image.ts
52
+ async function o(e) {
53
+ if (typeof createImageBitmap == "function") {
54
+ let t = await s(e);
55
+ if (t) try {
56
+ let e = await createImageBitmap(t, { imageOrientation: "from-image" });
57
+ return {
58
+ element: e,
59
+ width: e.width,
60
+ height: e.height
61
+ };
62
+ } catch {}
63
+ }
64
+ return c(e);
65
+ }
66
+ async function s(e) {
67
+ if (e instanceof Blob) return e;
68
+ if (typeof fetch != "function") return null;
69
+ try {
70
+ let t = await fetch(e, { credentials: "omit" });
71
+ return t.ok ? await t.blob() : null;
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+ async function c(e) {
77
+ let t = typeof e == "string" ? e : URL.createObjectURL(e), n = typeof e != "string";
78
+ try {
79
+ let e = await new Promise((e, n) => {
80
+ let r = new Image();
81
+ r.crossOrigin = "anonymous", r.onload = () => e(r), r.onerror = () => n(/* @__PURE__ */ Error(`Failed to load image: ${t}`)), r.src = t;
82
+ });
83
+ return {
84
+ element: e,
85
+ width: e.naturalWidth,
86
+ height: e.naturalHeight
87
+ };
88
+ } finally {
89
+ n && URL.revokeObjectURL(t);
90
+ }
91
+ }
92
+ //#endregion
93
+ //#region src/canvas/viewport.ts
94
+ var l = Object.freeze({
95
+ zoom: 1,
96
+ panX: 0,
97
+ panY: 0
70
98
  });
71
- function pt(t, n, e = k) {
72
- const i = Math.max(0, t.width - t.padding * 2), r = Math.max(0, t.height - t.padding * 2);
73
- if (n.width <= 0 || n.height <= 0 || i <= 0 || r <= 0)
74
- return {
75
- displayRect: { x: t.padding, y: t.padding, width: 0, height: 0 },
76
- scale: 0
77
- };
78
- const o = Math.min(i / n.width, r / n.height), a = Math.max(0, e.zoom || 0), c = o * a, l = n.width * c, s = n.height * c, u = t.padding + (i - l) / 2, h = t.padding + (r - s) / 2, f = u + e.panX, d = h + e.panY, m = z(f, u, l, i, t.padding), p = z(d, h, s, r, t.padding);
79
- return {
80
- displayRect: { x: m, y: p, width: l, height: s },
81
- scale: c
82
- };
83
- }
84
- function z(t, n, e, i, r) {
85
- if (e <= i) return n;
86
- const o = r, a = r + i, c = o + 1 - e, l = a - 1;
87
- return t < c ? c : t > l ? l : t;
88
- }
89
- function Bn(t, n) {
90
- return {
91
- x: n.displayRect.x + t.x * n.scale,
92
- y: n.displayRect.y + t.y * n.scale
93
- };
94
- }
95
- function Wn(t, n) {
96
- return n.scale === 0 ? { x: 0, y: 0 } : {
97
- x: (t.x - n.displayRect.x) / n.scale,
98
- y: (t.y - n.displayRect.y) / n.scale
99
- };
100
- }
101
- function Yn(t, n) {
102
- return {
103
- x: n.displayRect.x + t.x * n.scale,
104
- y: n.displayRect.y + t.y * n.scale,
105
- width: t.width * n.scale,
106
- height: t.height * n.scale
107
- };
108
- }
109
- function Xn(t, n) {
110
- return n.scale === 0 ? { x: 0, y: 0, width: 0, height: 0 } : {
111
- x: (t.x - n.displayRect.x) / n.scale,
112
- y: (t.y - n.displayRect.y) / n.scale,
113
- width: t.width / n.scale,
114
- height: t.height / n.scale
115
- };
116
- }
117
- const ot = 8, at = 0.25;
118
- class Un {
119
- current;
120
- isPinching;
121
- listeners;
122
- constructor(n = k) {
123
- this.current = D(n), this.isPinching = !1, this.listeners = /* @__PURE__ */ new Set();
124
- }
125
- getTransform() {
126
- return this.current;
127
- }
128
- getSnapshot() {
129
- return { transform: this.current, pinching: this.isPinching };
130
- }
131
- setTransform(n) {
132
- const e = D(n);
133
- L(this.current, e) || (this.current = e, this.emit());
134
- }
135
- /**
136
- * Apply a multiplicative zoom delta anchored on a stage CSS-pixel point.
137
- * The point under `anchor` stays under `anchor` after the zoom.
138
- *
139
- * Pan is the displaced image-center's offset from the stage center, so the
140
- * dolly-zoom reduces to `pan_new = ratio · pan_old + (1 − ratio) · (anchor − stageCenter)`,
141
- * independent of the active plugin's image intrinsic.
142
- */
143
- zoomAt(n, e, i) {
144
- if (!Number.isFinite(n) || n <= 0) return this.current;
145
- const r = this.current.zoom, o = r * n, a = ct(o, at, ot);
146
- if (a === r) return this.current;
147
- const c = a / r, l = e.x - i.x, s = e.y - i.y, u = c * this.current.panX + (1 - c) * l, h = c * this.current.panY + (1 - c) * s;
148
- return this.current = { zoom: a, panX: u, panY: h }, this.emit(), this.current;
149
- }
150
- /**
151
- * Translate pan by `(dx, dy)` in stage CSS pixels at the current zoom.
152
- * Pan is stored raw; `computeViewport` clamps at emission time so the
153
- * gesture handler's math stays stable when the user pans past the clamp.
154
- */
155
- panBy(n, e) {
156
- n === 0 && e === 0 || (this.current = {
157
- zoom: this.current.zoom,
158
- panX: this.current.panX + n,
159
- panY: this.current.panY + e
160
- }, this.emit());
161
- }
162
- resetToFit() {
163
- L(this.current, k) || (this.current = k, this.emit());
164
- }
165
- /** Reset only the pan, preserving zoom. Used on plugin switch. */
166
- resetPan() {
167
- this.current.panX === 0 && this.current.panY === 0 || (this.current = { zoom: this.current.zoom, panX: 0, panY: 0 }, this.emit());
168
- }
169
- /** True while a multi-pointer gesture is active. Heavy plugins read this. */
170
- getPinching() {
171
- return this.isPinching;
172
- }
173
- setPinching(n) {
174
- this.isPinching !== n && (this.isPinching = n, this.emit());
175
- }
176
- computeViewport(n, e) {
177
- return pt(n, e, this.current);
178
- }
179
- /** Subscribe to transform / pinching changes. Handler runs synchronously after every change. */
180
- subscribe(n) {
181
- return this.listeners.add(n), () => {
182
- this.listeners.delete(n);
183
- };
184
- }
185
- clear() {
186
- this.listeners.clear();
187
- }
188
- emit() {
189
- const n = this.getSnapshot();
190
- for (const e of this.listeners) e(n);
191
- }
192
- }
193
- function ct(t, n, e) {
194
- return t < n ? n : t > e ? e : t;
195
- }
196
- function D(t) {
197
- const n = ct(Number.isFinite(t.zoom) ? t.zoom : 1, at, ot), e = Number.isFinite(t.panX) ? t.panX : 0, i = Number.isFinite(t.panY) ? t.panY : 0;
198
- return { zoom: n, panX: e, panY: i };
199
- }
200
- function L(t, n) {
201
- return t.zoom === n.zoom && t.panX === n.panX && t.panY === n.panY;
202
- }
203
- function g(t, n) {
204
- if (Mt())
205
- return { kind: "offscreen", canvas: new OffscreenCanvas(t, n) };
206
- const e = document.createElement("canvas");
207
- return e.width = t, e.height = n, { kind: "html", canvas: e };
208
- }
209
- function y(t) {
210
- if (t.kind === "offscreen") {
211
- const e = t.canvas.getContext("2d");
212
- if (!e) throw new Error("2D canvas context is not available");
213
- return e;
214
- }
215
- const n = t.canvas.getContext("2d");
216
- if (!n) throw new Error("2D canvas context is not available");
217
- return n;
218
- }
219
- async function st(t, n, e) {
220
- return t.kind === "offscreen" ? t.canvas.convertToBlob({ type: n, quality: e }) : new Promise((i, r) => {
221
- t.canvas.toBlob(
222
- (o) => {
223
- o ? i(o) : r(new Error("toBlob produced null"));
224
- },
225
- n,
226
- e
227
- );
228
- });
229
- }
230
- function Mt() {
231
- return typeof OffscreenCanvas > "u" ? !1 : typeof OffscreenCanvas.prototype.convertToBlob == "function";
232
- }
233
- const B = /* @__PURE__ */ new Map();
234
- function b(t) {
235
- const n = B.get(t);
236
- if (n) return n;
237
- const e = (async () => {
238
- try {
239
- const i = g(1, 1), r = await st(i, t, 0.5);
240
- return r.type === t && r.size > 0;
241
- } catch {
242
- return !1;
243
- }
244
- })();
245
- return B.set(t, e), e;
246
- }
247
- function Hn(t, n) {
248
- const e = Math.min(t.x, n.x), i = Math.min(t.y, n.y), r = Math.abs(t.x - n.x), o = Math.abs(t.y - n.y);
249
- return { x: e, y: i, width: r, height: o };
250
- }
251
- function qn(t) {
252
- return t.x + t.width;
253
- }
254
- function jn(t) {
255
- return t.y + t.height;
256
- }
257
- function $n(t) {
258
- return { x: t.x + t.width / 2, y: t.y + t.height / 2 };
259
- }
260
- function Qn(t, n) {
261
- return t.x >= n.x && t.x <= n.x + n.width && t.y >= n.y && t.y <= n.y + n.height;
262
- }
263
- function Kn(t, n) {
264
- return t.x === n.x && t.y === n.y && t.width === n.width && t.height === n.height;
265
- }
266
- function Vn(t, n, e, i) {
267
- const r = { x: t.x + n, y: t.y + e, width: t.width, height: t.height };
268
- return P(r, i);
269
- }
270
- function P(t, n) {
271
- let { x: e, y: i, width: r, height: o } = t;
272
- return r > n.width && (r = n.width), o > n.height && (o = n.height), e < n.x && (e = n.x), i < n.y && (i = n.y), e + r > n.x + n.width && (e = n.x + n.width - r), i + o > n.y + n.height && (i = n.y + n.height - o), { x: e, y: i, width: r, height: o };
273
- }
274
- function St(t) {
275
- return {
276
- x: Math.round(t.x),
277
- y: Math.round(t.y),
278
- width: Math.round(t.width),
279
- height: Math.round(t.height)
280
- };
281
- }
282
- function Gn(t) {
283
- let n = t;
284
- const e = /* @__PURE__ */ new Set();
285
- function i(r) {
286
- for (const o of [...e])
287
- try {
288
- o(n, r);
289
- } catch (a) {
290
- queueMicrotask(() => {
291
- throw a;
292
- });
293
- }
294
- }
295
- return {
296
- get() {
297
- return n;
298
- },
299
- set(r) {
300
- const o = n;
301
- n = { ...n, ...r }, i(o);
302
- },
303
- update(r) {
304
- const o = n;
305
- n = { ...n, ...r(n) }, i(o);
306
- },
307
- subscribe(r) {
308
- return e.add(r), () => e.delete(r);
309
- }
310
- };
311
- }
312
- const W = 50;
313
- class Jn {
314
- shadow;
315
- undoStack = [];
316
- redoStack = [];
317
- constructor(n) {
318
- this.shadow = E(n);
319
- }
320
- /**
321
- * Capture a commit. Previous shadow → undo stack; `current` → shadow.
322
- * Redo is cleared because a new commit branches the history. A commit
323
- * structurally equal to the shadow is a no-op so duplicates (clicking
324
- * the same preset twice) don't pollute the undo stack.
325
- */
326
- commit(n) {
327
- bt(n, this.shadow) || (this.undoStack.push(this.shadow), this.undoStack.length > W && this.undoStack.shift(), this.shadow = E(n), this.redoStack.length = 0);
328
- }
329
- canUndo() {
330
- return this.undoStack.length > 0;
331
- }
332
- canRedo() {
333
- return this.redoStack.length > 0;
334
- }
335
- /** Pop the most recent prior snapshot; `current` goes onto the redo stack. Returns null if undo is empty. */
336
- undo(n) {
337
- const e = this.undoStack.pop();
338
- return e ? (this.redoStack.push(E(n)), this.shadow = e, { snapshot: e, changed: Y(n, e) }) : null;
339
- }
340
- /** Pop the most recent redo entry; `current` goes onto the undo stack. Returns null if redo is empty. */
341
- redo(n) {
342
- const e = this.redoStack.pop();
343
- return e ? (this.undoStack.push(E(n)), this.undoStack.length > W && this.undoStack.shift(), this.shadow = e, { snapshot: e, changed: Y(n, e) }) : null;
344
- }
345
- /** Test/debug helpers; not part of the editor's runtime API. */
346
- size() {
347
- return { undo: this.undoStack.length, redo: this.redoStack.length };
348
- }
349
- }
350
- function bt(t, n) {
351
- if (t.size !== n.size) return !1;
352
- for (const [e, i] of t)
353
- if (!n.has(e) || C(i) !== C(n.get(e))) return !1;
354
- return !0;
355
- }
356
- function Y(t, n) {
357
- const e = /* @__PURE__ */ new Set();
358
- for (const [i, r] of n)
359
- C(r) !== C(t.get(i)) && e.add(i);
360
- for (const i of t.keys())
361
- n.has(i) || e.add(i);
362
- return e;
363
- }
364
- function E(t) {
365
- const n = /* @__PURE__ */ new Map();
366
- for (const [e, i] of t)
367
- n.set(e, structuredClone(i));
368
- return n;
369
- }
370
- function C(t) {
371
- return JSON.stringify(t, (n, e) => {
372
- if (e && typeof e == "object" && !Array.isArray(e)) {
373
- const i = {};
374
- for (const r of Object.keys(e).sort())
375
- i[r] = e[r];
376
- return i;
377
- }
378
- return e;
379
- });
380
- }
381
- function O(t, n) {
382
- if (n <= 0 || t.width <= 0 || t.height <= 0)
383
- return { x: t.x, y: t.y, width: 0, height: 0 };
384
- const e = t.width / t.height;
385
- let i, r;
386
- return n >= e ? (i = t.width, r = i / n) : (r = t.height, i = r * n), {
387
- x: t.x + (t.width - i) / 2,
388
- y: t.y + (t.height - r) / 2,
389
- width: i,
390
- height: r
391
- };
392
- }
393
- function Et(t, n, e, i) {
394
- if (n <= 0) return t;
395
- if (t.width <= 0 || t.height <= 0) return O(i, n);
396
- const r = t.width / t.height;
397
- let o, a;
398
- r > n ? (a = t.height, o = a * n) : (o = t.width, a = o / n);
399
- const c = lt(t, o, a, e), l = P(c, i), s = l.height === 0 ? 0 : l.width / l.height;
400
- return Math.abs(s - n) <= Rt ? l : It(l, n, e);
401
- }
402
- const Rt = 1e-6;
403
- function lt(t, n, e, i) {
404
- switch (i) {
405
- case "tl":
406
- return { x: t.x, y: t.y, width: n, height: e };
407
- case "tr":
408
- return { x: t.x + t.width - n, y: t.y, width: n, height: e };
409
- case "bl":
410
- return { x: t.x, y: t.y + t.height - e, width: n, height: e };
411
- case "br":
412
- return {
413
- x: t.x + t.width - n,
414
- y: t.y + t.height - e,
415
- width: n,
416
- height: e
417
- };
418
- case "center":
419
- return {
420
- x: t.x + (t.width - n) / 2,
421
- y: t.y + (t.height - e) / 2,
422
- width: n,
423
- height: e
424
- };
425
- }
426
- }
427
- function It(t, n, e) {
428
- const i = O(t, n);
429
- return lt(t, i.width, i.height, e);
430
- }
431
- function Zn(t, n, e, i) {
432
- const r = i.minSize ?? 1, o = t.x, a = t.y, c = t.x + t.width, l = t.y + t.height;
433
- let s = o, u = a, h = c, f = l;
434
- (n === "tl" || n === "l" || n === "bl") && (s = e.x), (n === "tr" || n === "r" || n === "br") && (h = e.x), (n === "tl" || n === "t" || n === "tr") && (u = e.y), (n === "bl" || n === "b" || n === "br") && (f = e.y), (n === "l" || n === "r") && (u = a, f = l), (n === "t" || n === "b") && (s = o, h = c);
435
- let d = Math.min(s, h), m = Math.min(u, f), p = Math.abs(h - s), A = Math.abs(f - u);
436
- p < r && (p = r, n === "tl" || n === "l" || n === "bl" ? d = c - r : (n === "tr" || n === "r" || n === "br") && (d = o)), A < r && (A = r, n === "tl" || n === "t" || n === "tr" ? m = l - r : (n === "bl" || n === "b" || n === "br") && (m = a));
437
- let M = { x: d, y: m, width: p, height: A };
438
- return M = P(M, i.bounds), i.aspectRatio !== void 0 && i.aspectRatio > 0 && (M = Et(M, i.aspectRatio, Tt(n), i.bounds)), M;
439
- }
440
- function Tt(t) {
441
- switch (t) {
442
- case "tl":
443
- return "br";
444
- case "tr":
445
- return "bl";
446
- case "bl":
447
- return "tr";
448
- case "br":
449
- return "tl";
450
- case "t":
451
- return "bl";
452
- case "b":
453
- return "tl";
454
- case "l":
455
- return "tr";
456
- case "r":
457
- return "tl";
458
- }
459
- }
460
- function kt(t, n) {
461
- const [e] = t;
462
- return e === void 0 || n === void 0 ? !0 : n === "landscape" ? e >= 1 : n === "portrait" ? e < 1 : !0;
463
- }
464
- function te(t, n) {
465
- return t.filter((e) => kt(e, n));
466
- }
467
- function ne(t) {
468
- return {
469
- rect: { x: 0, y: 0, width: t.imageSize.width, height: t.imageSize.height },
470
- aspectRatio: void 0,
471
- activePresetIndex: Ct(t.presets),
472
- presets: t.presets,
473
- imageSize: t.imageSize
474
- };
475
- }
476
- function ee(t, n) {
477
- const e = t.presets[n];
478
- if (!e) return t;
479
- const [i] = e;
480
- if (i === void 0)
481
- return { ...t, aspectRatio: void 0, activePresetIndex: n };
482
- const r = {
483
- x: 0,
484
- y: 0,
485
- width: t.imageSize.width,
486
- height: t.imageSize.height
487
- }, o = O(r, i);
488
- return { ...t, rect: o, aspectRatio: i, activePresetIndex: n };
489
- }
490
- function Ct(t) {
491
- return t.findIndex(([n]) => n === void 0);
492
- }
493
- function ie(t, n) {
494
- const e = St(n.rect), i = R(e.x, 0, t.width), r = R(e.y, 0, t.height), o = R(e.width, 1, t.width - i), a = R(e.height, 1, t.height - r), c = g(o, a);
495
- if (c.kind === "offscreen") {
496
- const s = c.canvas.getContext("2d");
497
- if (!s) throw new Error("2D canvas context is not available");
498
- return s.drawImage(t.bitmap, i, r, o, a, 0, 0, o, a), { bitmap: c.canvas, width: o, height: a, mimeType: t.mimeType };
499
- }
500
- const l = c.canvas.getContext("2d");
501
- if (!l) throw new Error("2D canvas context is not available");
502
- return l.drawImage(t.bitmap, i, r, o, a, 0, 0, o, a), { bitmap: c.canvas, width: o, height: a, mimeType: t.mimeType };
503
- }
504
- function R(t, n, e) {
505
- return Math.max(n, Math.min(e, t));
506
- }
507
- const ut = {
508
- mimeChoice: "auto",
509
- quality: 0.85,
510
- stripMetadata: !0
511
- }, re = [
512
- "image/png",
513
- "image/jpeg",
514
- "image/webp",
515
- "image/avif"
99
+ function u(e, t, n = l) {
100
+ let r = Math.max(0, e.width - e.padding * 2), i = Math.max(0, e.height - e.padding * 2);
101
+ if (t.width <= 0 || t.height <= 0 || r <= 0 || i <= 0) return {
102
+ displayRect: {
103
+ x: e.padding,
104
+ y: e.padding,
105
+ width: 0,
106
+ height: 0
107
+ },
108
+ scale: 0
109
+ };
110
+ let a = Math.min(r / t.width, i / t.height) * Math.max(0, n.zoom || 0), o = t.width * a, s = t.height * a, c = e.padding + (r - o) / 2, u = e.padding + (i - s) / 2, f = c + n.panX, p = u + n.panY;
111
+ return {
112
+ displayRect: {
113
+ x: d(f, c, o, r, e.padding),
114
+ y: d(p, u, s, i, e.padding),
115
+ width: o,
116
+ height: s
117
+ },
118
+ scale: a
119
+ };
120
+ }
121
+ function d(e, t, n, r, i) {
122
+ if (n <= r) return t;
123
+ let a = i, o = i + r, s = a + 1 - n, c = o - 1;
124
+ return e < s ? s : e > c ? c : e;
125
+ }
126
+ function f(e, t) {
127
+ return {
128
+ x: t.displayRect.x + e.x * t.scale,
129
+ y: t.displayRect.y + e.y * t.scale
130
+ };
131
+ }
132
+ function p(e, t) {
133
+ return t.scale === 0 ? {
134
+ x: 0,
135
+ y: 0
136
+ } : {
137
+ x: (e.x - t.displayRect.x) / t.scale,
138
+ y: (e.y - t.displayRect.y) / t.scale
139
+ };
140
+ }
141
+ function m(e, t) {
142
+ return {
143
+ x: t.displayRect.x + e.x * t.scale,
144
+ y: t.displayRect.y + e.y * t.scale,
145
+ width: e.width * t.scale,
146
+ height: e.height * t.scale
147
+ };
148
+ }
149
+ function h(e, t) {
150
+ return t.scale === 0 ? {
151
+ x: 0,
152
+ y: 0,
153
+ width: 0,
154
+ height: 0
155
+ } : {
156
+ x: (e.x - t.displayRect.x) / t.scale,
157
+ y: (e.y - t.displayRect.y) / t.scale,
158
+ width: e.width / t.scale,
159
+ height: e.height / t.scale
160
+ };
161
+ }
162
+ //#endregion
163
+ //#region src/canvas/viewport-controller.ts
164
+ var g = 8, _ = .25, ee = class {
165
+ current;
166
+ isPinching;
167
+ listeners;
168
+ constructor(e = l) {
169
+ this.current = ne(e), this.isPinching = !1, this.listeners = /* @__PURE__ */ new Set();
170
+ }
171
+ getTransform() {
172
+ return this.current;
173
+ }
174
+ getSnapshot() {
175
+ return {
176
+ transform: this.current,
177
+ pinching: this.isPinching
178
+ };
179
+ }
180
+ setTransform(e) {
181
+ let t = ne(e);
182
+ re(this.current, t) || (this.current = t, this.emit());
183
+ }
184
+ zoomAt(e, t, n) {
185
+ if (!Number.isFinite(e) || e <= 0) return this.current;
186
+ let r = this.current.zoom, i = te(r * e, _, 8);
187
+ if (i === r) return this.current;
188
+ let a = i / r, o = t.x - n.x, s = t.y - n.y, c = a * this.current.panX + (1 - a) * o, l = a * this.current.panY + (1 - a) * s;
189
+ return this.current = {
190
+ zoom: i,
191
+ panX: c,
192
+ panY: l
193
+ }, this.emit(), this.current;
194
+ }
195
+ panBy(e, t) {
196
+ e === 0 && t === 0 || (this.current = {
197
+ zoom: this.current.zoom,
198
+ panX: this.current.panX + e,
199
+ panY: this.current.panY + t
200
+ }, this.emit());
201
+ }
202
+ resetToFit() {
203
+ re(this.current, l) || (this.current = l, this.emit());
204
+ }
205
+ resetPan() {
206
+ this.current.panX === 0 && this.current.panY === 0 || (this.current = {
207
+ zoom: this.current.zoom,
208
+ panX: 0,
209
+ panY: 0
210
+ }, this.emit());
211
+ }
212
+ getPinching() {
213
+ return this.isPinching;
214
+ }
215
+ setPinching(e) {
216
+ this.isPinching !== e && (this.isPinching = e, this.emit());
217
+ }
218
+ computeViewport(e, t) {
219
+ return u(e, t, this.current);
220
+ }
221
+ subscribe(e) {
222
+ return this.listeners.add(e), () => {
223
+ this.listeners.delete(e);
224
+ };
225
+ }
226
+ clear() {
227
+ this.listeners.clear();
228
+ }
229
+ emit() {
230
+ let e = this.getSnapshot();
231
+ for (let t of this.listeners) t(e);
232
+ }
233
+ };
234
+ function te(e, t, n) {
235
+ return e < t ? t : e > n ? n : e;
236
+ }
237
+ function ne(e) {
238
+ return {
239
+ zoom: te(Number.isFinite(e.zoom) ? e.zoom : 1, _, 8),
240
+ panX: Number.isFinite(e.panX) ? e.panX : 0,
241
+ panY: Number.isFinite(e.panY) ? e.panY : 0
242
+ };
243
+ }
244
+ function re(e, t) {
245
+ return e.zoom === t.zoom && e.panX === t.panX && e.panY === t.panY;
246
+ }
247
+ //#endregion
248
+ //#region src/events/event-bus.ts
249
+ var ie = class {
250
+ listeners = /* @__PURE__ */ new Map();
251
+ on(e, t) {
252
+ let n = this.listeners.get(e);
253
+ return n || (n = /* @__PURE__ */ new Set(), this.listeners.set(e, n)), n.add(t), () => {
254
+ n?.delete(t);
255
+ };
256
+ }
257
+ off(e, t) {
258
+ this.listeners.get(e)?.delete(t);
259
+ }
260
+ emit(e, t) {
261
+ let n = this.listeners.get(e);
262
+ if (n) for (let e of [...n]) try {
263
+ e(t);
264
+ } catch (e) {
265
+ queueMicrotask(() => {
266
+ throw e;
267
+ });
268
+ }
269
+ }
270
+ clear() {
271
+ this.listeners.clear();
272
+ }
273
+ };
274
+ //#endregion
275
+ //#region src/geometry/rect.ts
276
+ function ae(e, t) {
277
+ return {
278
+ x: Math.min(e.x, t.x),
279
+ y: Math.min(e.y, t.y),
280
+ width: Math.abs(e.x - t.x),
281
+ height: Math.abs(e.y - t.y)
282
+ };
283
+ }
284
+ function oe(e) {
285
+ return e.x + e.width;
286
+ }
287
+ function se(e) {
288
+ return e.y + e.height;
289
+ }
290
+ function ce(e) {
291
+ return {
292
+ x: e.x + e.width / 2,
293
+ y: e.y + e.height / 2
294
+ };
295
+ }
296
+ function le(e, t) {
297
+ return e.x >= t.x && e.x <= t.x + t.width && e.y >= t.y && e.y <= t.y + t.height;
298
+ }
299
+ function ue(e, t) {
300
+ return e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height;
301
+ }
302
+ function de(e, t, n, r) {
303
+ return v({
304
+ x: e.x + t,
305
+ y: e.y + n,
306
+ width: e.width,
307
+ height: e.height
308
+ }, r);
309
+ }
310
+ function v(e, t) {
311
+ let { x: n, y: r, width: i, height: a } = e;
312
+ return i > t.width && (i = t.width), a > t.height && (a = t.height), n < t.x && (n = t.x), r < t.y && (r = t.y), n + i > t.x + t.width && (n = t.x + t.width - i), r + a > t.y + t.height && (r = t.y + t.height - a), {
313
+ x: n,
314
+ y: r,
315
+ width: i,
316
+ height: a
317
+ };
318
+ }
319
+ function y(e) {
320
+ return {
321
+ x: Math.round(e.x),
322
+ y: Math.round(e.y),
323
+ width: Math.round(e.width),
324
+ height: Math.round(e.height)
325
+ };
326
+ }
327
+ //#endregion
328
+ //#region src/history/history.ts
329
+ var fe = 50, pe = class {
330
+ shadow;
331
+ undoStack = [];
332
+ redoStack = [];
333
+ constructor(e) {
334
+ this.shadow = x(e);
335
+ }
336
+ commit(e) {
337
+ me(e, this.shadow) || (this.undoStack.push(this.shadow), this.undoStack.length > 50 && this.undoStack.shift(), this.shadow = x(e), this.redoStack.length = 0);
338
+ }
339
+ canUndo() {
340
+ return this.undoStack.length > 0;
341
+ }
342
+ canRedo() {
343
+ return this.redoStack.length > 0;
344
+ }
345
+ undo(e) {
346
+ let t = this.undoStack.pop();
347
+ return t ? (this.redoStack.push(x(e)), this.shadow = t, {
348
+ snapshot: t,
349
+ changed: b(e, t)
350
+ }) : null;
351
+ }
352
+ redo(e) {
353
+ let t = this.redoStack.pop();
354
+ return t ? (this.undoStack.push(x(e)), this.undoStack.length > 50 && this.undoStack.shift(), this.shadow = t, {
355
+ snapshot: t,
356
+ changed: b(e, t)
357
+ }) : null;
358
+ }
359
+ size() {
360
+ return {
361
+ undo: this.undoStack.length,
362
+ redo: this.redoStack.length
363
+ };
364
+ }
365
+ };
366
+ function me(e, t) {
367
+ if (e.size !== t.size) return !1;
368
+ for (let [n, r] of e) if (!t.has(n) || S(r) !== S(t.get(n))) return !1;
369
+ return !0;
370
+ }
371
+ function b(e, t) {
372
+ let n = /* @__PURE__ */ new Set();
373
+ for (let [r, i] of t) S(i) !== S(e.get(r)) && n.add(r);
374
+ for (let r of e.keys()) t.has(r) || n.add(r);
375
+ return n;
376
+ }
377
+ function x(e) {
378
+ let t = /* @__PURE__ */ new Map();
379
+ for (let [n, r] of e) t.set(n, structuredClone(r));
380
+ return t;
381
+ }
382
+ function S(e) {
383
+ return JSON.stringify(e, (e, t) => {
384
+ if (t && typeof t == "object" && !Array.isArray(t)) {
385
+ let e = {};
386
+ for (let n of Object.keys(t).sort()) e[n] = t[n];
387
+ return e;
388
+ }
389
+ return t;
390
+ });
391
+ }
392
+ //#endregion
393
+ //#region src/output/state.ts
394
+ var C = {
395
+ mimeChoice: "auto",
396
+ quality: .85,
397
+ stripMetadata: !0
398
+ }, he = [
399
+ "image/png",
400
+ "image/jpeg",
401
+ "image/webp",
402
+ "image/avif"
516
403
  ];
517
- function ht(t) {
518
- return Number.isFinite(t) ? t < 0 ? 0 : t > 1 ? 1 : t : ut.quality;
519
- }
520
- function oe(t, n) {
521
- return t.mimeChoice === n ? t : { ...t, mimeChoice: n };
522
- }
523
- function ae(t, n) {
524
- const e = ht(n);
525
- return t.quality === e ? t : { ...t, quality: e };
526
- }
527
- function ce(t, n) {
528
- return t.stripMetadata === n ? t : { ...t, stripMetadata: n };
529
- }
530
- const X = [255, 216], U = [255, 225], H = [69, 120, 105, 102, 0, 0];
531
- async function vt(t) {
532
- if (t.output.type && t.output.type !== "image/jpeg") return t.output;
533
- const n = await q(t.source);
534
- if (!j(n, X)) return t.output;
535
- const e = At(n);
536
- if (!e) return t.output;
537
- const i = await q(t.output);
538
- if (!j(i, X)) return t.output;
539
- const r = new Uint8Array(i.length + e.length);
540
- return r.set(i.subarray(0, 2), 0), r.set(e, 2), r.set(i.subarray(2), 2 + e.length), new Blob([r], { type: "image/jpeg" });
541
- }
542
- async function q(t) {
543
- return typeof t.arrayBuffer == "function" ? new Uint8Array(await t.arrayBuffer()) : new Promise((n, e) => {
544
- const i = new FileReader();
545
- i.onload = () => {
546
- const r = i.result;
547
- r instanceof ArrayBuffer ? n(new Uint8Array(r)) : e(new Error("FileReader returned a non-ArrayBuffer result"));
548
- }, i.onerror = () => e(i.error ?? new Error("FileReader failed")), i.readAsArrayBuffer(t);
549
- });
550
- }
551
- function j(t, n) {
552
- if (t.length < n.length) return !1;
553
- for (let e = 0; e < n.length; e++)
554
- if (t[e] !== n[e]) return !1;
555
- return !0;
556
- }
557
- function At(t) {
558
- let n = 2;
559
- for (; n + 4 <= t.length; ) {
560
- if (t[n] !== 255) return;
561
- const e = t[n + 1];
562
- if (e === void 0 || e === 218 || e === 217) return;
563
- const i = t[n + 2] !== void 0 && t[n + 3] !== void 0 ? t[n + 2] * 256 + t[n + 3] : 0;
564
- if (i < 2) return;
565
- const r = n + 2 + i;
566
- if (r > t.length) return;
567
- if (t[n] === U[0] && t[n + 1] === U[1] && Nt(t, n + 4))
568
- return t.slice(n, r);
569
- n = r;
570
- }
571
- }
572
- function Nt(t, n) {
573
- for (let e = 0; e < H.length; e++)
574
- if (t[n + e] !== H[e]) return !1;
575
- return !0;
576
- }
577
- const $ = "image/png", Ft = /* @__PURE__ */ new Set(["image/png", "image/webp", "image/avif"]);
578
- async function Pt(t, n) {
579
- return t.mimeChoice !== "auto" ? await b(t.mimeChoice) ? t.mimeChoice : await b("image/webp") ? "image/webp" : $ : await b("image/webp") ? "image/webp" : !Ft.has(n.mimeType) && await b("image/jpeg") ? "image/jpeg" : $;
580
- }
581
- function Ot(t, n) {
582
- const e = _t(n);
583
- if (!t) return `kalotyp-image.${e}`;
584
- const i = zt(t);
585
- if (!i) return `kalotyp-image.${e}`;
586
- const r = Lt(i);
587
- return r ? `${r}.${e}` : `kalotyp-image.${e}`;
588
- }
589
- async function se(t, n = {}) {
590
- const e = n.output ?? ut, i = await Pt(e, t), r = ht(e.quality), o = Ot(n.sourceName, i), a = g(t.width, t.height);
591
- if (a.kind === "offscreen") {
592
- const u = a.canvas.getContext("2d");
593
- if (!u) throw new Error("2D canvas context is not available");
594
- u.drawImage(t.bitmap, 0, 0);
595
- } else {
596
- const u = a.canvas.getContext("2d");
597
- if (!u) throw new Error("2D canvas context is not available");
598
- u.drawImage(t.bitmap, 0, 0);
599
- }
600
- const c = await st(a, i, r), s = n.output?.stripMetadata === !1 && i === "image/jpeg" && t.mimeType === "image/jpeg" && n.sourceBlob !== void 0 ? await vt({ source: n.sourceBlob, output: c }) : c;
601
- return new File([s], o, { type: i });
602
- }
603
- function _t(t) {
604
- if (t === "image/jpeg") return "jpg";
605
- if (t === "image/png") return "png";
606
- if (t === "image/webp") return "webp";
607
- if (t === "image/avif") return "avif";
608
- const n = t.split("/")[1];
609
- return n && n.length > 0 ? n : "bin";
610
- }
611
- function zt(t) {
612
- const e = Dt(t).split(/[/\\]/);
613
- return e[e.length - 1];
614
- }
615
- function Dt(t) {
616
- const n = t.indexOf("?");
617
- return n === -1 ? t : t.slice(0, n);
618
- }
619
- function Lt(t) {
620
- const n = t.lastIndexOf(".");
621
- return n <= 0 ? t : t.slice(0, n);
622
- }
623
- async function le(t, n) {
624
- let e = n;
625
- for (const i of t)
626
- e = await i.plugin.bake(i.state, e);
627
- return e;
628
- }
629
- function ue() {
630
- return { horizontal: !1, vertical: !1 };
631
- }
632
- function he(t, n) {
633
- return n === "horizontal" ? { ...t, horizontal: !t.horizontal } : { ...t, vertical: !t.vertical };
634
- }
635
- function Bt(t) {
636
- return !t.horizontal && !t.vertical;
637
- }
638
- async function fe(t, n) {
639
- if (Bt(t)) return n;
640
- const { width: e, height: i } = n, r = g(e, i), o = y(r), a = t.horizontal ? -1 : 1, c = t.vertical ? -1 : 1, l = t.horizontal ? e : 0, s = t.vertical ? i : 0;
641
- return o.setTransform(a, 0, 0, c, l, s), o.drawImage(n.bitmap, 0, 0), {
642
- bitmap: r.canvas,
643
- width: e,
644
- height: i,
645
- mimeType: n.mimeType
646
- };
647
- }
648
- const Wt = -45, Yt = 45, de = 0.1;
649
- function ge() {
650
- return { quarterTurns: 0, freeAngle: 0 };
651
- }
652
- function me(t) {
653
- return { ...t, quarterTurns: (t.quarterTurns + 1) % 4 };
654
- }
655
- function ye(t) {
656
- return { ...t, quarterTurns: (t.quarterTurns + 3) % 4 };
657
- }
658
- function we(t, n) {
659
- const e = Ht(n, Wt, Yt), i = Math.round(e * 10) / 10;
660
- return { ...t, freeAngle: i };
661
- }
662
- function Xt(t) {
663
- return t.quarterTurns === 0 && Math.abs(t.freeAngle) < 1e-6;
664
- }
665
- function Ut(t) {
666
- return t.quarterTurns * 90 + t.freeAngle;
667
- }
668
- function Ht(t, n, e) {
669
- return Math.max(n, Math.min(e, t));
670
- }
671
- function qt(t, n) {
672
- const e = t.width, i = t.height;
673
- if (e <= 0 || i <= 0) return { width: 0, height: 0 };
674
- const r = Math.abs(Math.cos(n)), o = Math.abs(Math.sin(n)), a = e * r + i * o, c = e * o + i * r, l = a > Q ? e * e / a : Number.POSITIVE_INFINITY, s = c > Q ? e * i / c : Number.POSITIVE_INFINITY, u = Math.min(l, s), h = u * i / e;
675
- return { width: u, height: h };
676
- }
677
- const Q = 1e-9;
678
- async function xe(t, n) {
679
- if (Xt(t)) return n;
680
- const e = Ut(t), i = e * Math.PI / 180, r = e - t.quarterTurns * 90, o = Math.abs(r) < 1e-6;
681
- let a, c;
682
- if (o)
683
- t.quarterTurns === 1 || t.quarterTurns === 3 ? (a = n.height, c = n.width) : (a = n.width, c = n.height);
684
- else {
685
- const u = qt(n, i);
686
- a = Math.max(1, Math.round(u.width)), c = Math.max(1, Math.round(u.height));
687
- }
688
- const l = g(a, c), s = y(l);
689
- return s.imageSmoothingEnabled = !0, s.imageSmoothingQuality = "high", s.translate(a / 2, c / 2), s.rotate(i), s.drawImage(n.bitmap, -n.width / 2, -n.height / 2), {
690
- bitmap: l.canvas,
691
- width: a,
692
- height: c,
693
- mimeType: n.mimeType
694
- };
695
- }
696
- const ft = 8e3, K = 1;
697
- function pe() {
698
- return { scaleX: 1, scaleY: 1, lockAspect: !0 };
699
- }
700
- function jt(t) {
701
- return Math.abs(t.scaleX - 1) < 1e-9 && Math.abs(t.scaleY - 1) < 1e-9;
702
- }
703
- function $t(t, n) {
704
- const e = v(Math.round(n.width * t.scaleX)), i = v(Math.round(n.height * t.scaleY));
705
- return { width: e, height: i };
706
- }
707
- function Me(t, n, e) {
708
- if (e.width <= 0) return t;
709
- const r = v(Math.round(n)) / e.width, o = t.lockAspect ? r : t.scaleY;
710
- return { ...t, scaleX: r, scaleY: o };
711
- }
712
- function Se(t, n, e) {
713
- if (e.height <= 0) return t;
714
- const r = v(Math.round(n)) / e.height, o = t.lockAspect ? r : t.scaleX;
715
- return { ...t, scaleX: o, scaleY: r };
716
- }
717
- function be(t, n) {
718
- const e = Qt(n / 100);
719
- return { ...t, scaleX: e, scaleY: e };
720
- }
721
- function Ee(t, n) {
722
- if (t.lockAspect === n) return t;
723
- if (!n) return { ...t, lockAspect: !1 };
724
- const e = (t.scaleX + t.scaleY) / 2;
725
- return { scaleX: e, scaleY: e, lockAspect: !0 };
726
- }
727
- function Re(t) {
728
- const n = Math.max(t.scaleX, t.scaleY);
729
- return Math.round(n * 1e3) / 10;
730
- }
731
- function v(t) {
732
- return Number.isFinite(t) ? Math.max(K, Math.min(ft, Math.trunc(t))) : K;
733
- }
734
- function Qt(t) {
735
- return !Number.isFinite(t) || t <= 0 ? 0.01 : Math.max(0.01, Math.min(t, ft));
736
- }
737
- async function Ie(t, n) {
738
- if (jt(t)) return n;
739
- const { width: e, height: i } = $t(t, n);
740
- if (e <= 0 || i <= 0) return n;
741
- const r = Kt(n.width, n.height, e, i);
742
- let o = {
743
- bitmap: n.bitmap,
744
- width: n.width,
745
- height: n.height
746
- };
747
- for (let c = 0; c < r; c++) {
748
- const l = Math.max(e, Math.floor(o.width / 2)), s = Math.max(i, Math.floor(o.height / 2));
749
- o = { bitmap: V(o, l, s).canvas, width: l, height: s };
750
- }
751
- return {
752
- bitmap: V(o, e, i).canvas,
753
- width: e,
754
- height: i,
755
- mimeType: n.mimeType
756
- };
757
- }
758
- function Kt(t, n, e, i) {
759
- let r = t, o = n, a = 0;
760
- for (; (r / 2 > e || o / 2 > i) && a < 16; )
761
- r = Math.floor(r / 2), o = Math.floor(o / 2), a += 1;
762
- return a;
763
- }
764
- function V(t, n, e) {
765
- const i = g(n, e), r = y(i);
766
- return r.imageSmoothingEnabled = !0, r.imageSmoothingQuality = "high", r.drawImage(t.bitmap, 0, 0, t.width, t.height, 0, 0, n, e), i;
767
- }
768
- const G = -100, J = 100, Z = 1, _ = {
769
- brightness: 0,
770
- contrast: 0,
771
- saturation: 0,
772
- exposure: 0,
773
- clarity: 0,
774
- gamma: 0
775
- }, Te = [
776
- { key: "brightness", label: "Brightness" },
777
- { key: "contrast", label: "Contrast" },
778
- { key: "saturation", label: "Saturation" },
779
- { key: "exposure", label: "Exposure" },
780
- { key: "clarity", label: "Clarity" },
781
- { key: "gamma", label: "Gamma" }
404
+ function w(e) {
405
+ return Number.isFinite(e) ? e < 0 ? 0 : e > 1 ? 1 : e : C.quality;
406
+ }
407
+ function ge(e, t) {
408
+ return e.mimeChoice === t ? e : {
409
+ ...e,
410
+ mimeChoice: t
411
+ };
412
+ }
413
+ function _e(e, t) {
414
+ let n = w(t);
415
+ return e.quality === n ? e : {
416
+ ...e,
417
+ quality: n
418
+ };
419
+ }
420
+ function ve(e, t) {
421
+ return e.stripMetadata === t ? e : {
422
+ ...e,
423
+ stripMetadata: t
424
+ };
425
+ }
426
+ //#endregion
427
+ //#region src/pipeline/exif.ts
428
+ var ye = [255, 216], T = [255, 225], be = [
429
+ 69,
430
+ 120,
431
+ 105,
432
+ 102,
433
+ 0,
434
+ 0
782
435
  ];
783
- function ke() {
784
- return _;
785
- }
786
- function Vt(t) {
787
- return t.brightness === 0 && t.contrast === 0 && t.saturation === 0 && t.exposure === 0 && t.clarity === 0 && t.gamma === 0;
788
- }
789
- function Ce(t, n, e) {
790
- const i = Gt(e);
791
- return t[n] === i ? t : { ...t, [n]: i };
792
- }
793
- function ve(t, n) {
794
- return t[n] === 0 ? t : { ...t, [n]: 0 };
795
- }
796
- function Ae() {
797
- return _;
798
- }
799
- function Gt(t) {
800
- return Number.isNaN(t) ? 0 : t <= G ? G : t >= J ? J : Math.round(t / Z) * Z;
801
- }
802
- function Jt(t) {
803
- const n = new Uint8ClampedArray(256), e = t.brightness / 200, i = 1 + t.contrast / 100, r = 1 + t.exposure / 200, o = Zt(t.gamma);
804
- for (let a = 0; a < 256; a++) {
805
- let c = a / 255;
806
- c = c * r, c = (c - 0.5) * i + 0.5, c = c + e, c < 0 ? c = 0 : c > 1 && (c = 1), c = c ** o, c < 0 ? c = 0 : c > 1 && (c = 1), n[a] = Math.round(c * 255);
807
- }
808
- return n;
809
- }
810
- function Zt(t) {
811
- return t === 0 ? 1 : t > 0 ? 1 - 0.5 * (t / 100) : 1 + 1 * (-t / 100);
812
- }
813
- function tn(t, n, e, i) {
814
- const r = t.length;
815
- if (n.length !== r)
816
- throw new Error("applyFinetuneLutAndSaturation: src/dst length mismatch");
817
- const o = 1 + i.saturation / 100;
818
- if (o === 1) {
819
- for (let a = 0; a < r; a += 4)
820
- n[a] = e[t[a]], n[a + 1] = e[t[a + 1]], n[a + 2] = e[t[a + 2]], n[a + 3] = t[a + 3];
821
- return;
822
- }
823
- for (let a = 0; a < r; a += 4) {
824
- const c = e[t[a]], l = e[t[a + 1]], s = e[t[a + 2]], u = 0.2126 * c + 0.7152 * l + 0.0722 * s;
825
- let h = u + (c - u) * o, f = u + (l - u) * o, d = u + (s - u) * o;
826
- h < 0 ? h = 0 : h > 255 && (h = 255), f < 0 ? f = 0 : f > 255 && (f = 255), d < 0 ? d = 0 : d > 255 && (d = 255), n[a] = h, n[a + 1] = f, n[a + 2] = d, n[a + 3] = t[a + 3];
827
- }
828
- }
829
- function nn(t, n, e) {
830
- if (e === 0) return;
831
- const i = t.length;
832
- if (n.length !== i)
833
- throw new Error("applyClarity: dst/blurred length mismatch");
834
- const r = e / 100;
835
- for (let o = 0; o < i; o += 4) {
836
- const a = t[o], c = t[o + 1], l = t[o + 2];
837
- let s = a + r * (a - n[o]), u = c + r * (c - n[o + 1]), h = l + r * (l - n[o + 2]);
838
- s < 0 ? s = 0 : s > 255 && (s = 255), u < 0 ? u = 0 : u > 255 && (u = 255), h < 0 ? h = 0 : h > 255 && (h = 255), t[o] = s, t[o + 1] = u, t[o + 2] = h;
839
- }
840
- }
841
- function en(t, n, e, i, r) {
842
- if (t.length !== n.length || t.length !== e.length)
843
- throw new Error("boxBlur3x3: buffer length mismatch");
844
- for (let o = 0; o < r; o++)
845
- for (let a = 0; a < i; a++) {
846
- const c = a === 0 ? 0 : a - 1, l = a === i - 1 ? i - 1 : a + 1, s = (o * i + a) * 4, u = (o * i + c) * 4, h = (o * i + l) * 4;
847
- n[s] = (t[u] + t[s] + t[h]) / 3, n[s + 1] = (t[u + 1] + t[s + 1] + t[h + 1]) / 3, n[s + 2] = (t[u + 2] + t[s + 2] + t[h + 2]) / 3, n[s + 3] = t[s + 3];
848
- }
849
- for (let o = 0; o < r; o++) {
850
- const a = o === 0 ? 0 : o - 1, c = o === r - 1 ? r - 1 : o + 1;
851
- for (let l = 0; l < i; l++) {
852
- const s = (o * i + l) * 4, u = (a * i + l) * 4, h = (c * i + l) * 4;
853
- e[s] = (n[u] + n[s] + n[h]) / 3, e[s + 1] = (n[u + 1] + n[s + 1] + n[h + 1]) / 3, e[s + 2] = (n[u + 2] + n[s + 2] + n[h + 2]) / 3, e[s + 3] = n[s + 3];
854
- }
855
- }
856
- }
857
- function tt(t, n, e) {
858
- if (n.width !== e.width || n.height !== e.height || n.data.length !== e.data.length)
859
- throw new Error("applyFinetuneToImageData: baseline/dst dimensions mismatch");
860
- const i = Jt(t);
861
- if (tn(n.data, e.data, i, t), t.clarity !== 0) {
862
- const r = new Uint8ClampedArray(n.data.length), o = new Uint8ClampedArray(n.data.length);
863
- en(n.data, r, o, n.width, n.height), nn(e.data, o, t.clarity);
864
- }
865
- }
866
- async function Ne(t, n) {
867
- if (Vt(t)) return n;
868
- const e = g(n.width, n.height), i = y(e);
869
- i.imageSmoothingEnabled = !0, i.imageSmoothingQuality = "high", i.drawImage(n.bitmap, 0, 0, n.width, n.height);
870
- const r = i.getImageData(0, 0, n.width, n.height);
871
- if (t.clarity === 0)
872
- tt(t, r, r), i.putImageData(r, 0, 0);
873
- else {
874
- const o = new ImageData(
875
- new Uint8ClampedArray(r.data.length),
876
- r.width,
877
- r.height
878
- );
879
- tt(t, r, o), i.putImageData(o, 0, 0);
880
- }
881
- return {
882
- bitmap: e.canvas,
883
- width: n.width,
884
- height: n.height,
885
- mimeType: n.mimeType
886
- };
887
- }
888
- const rn = [
889
- {
890
- id: "none",
891
- label: "None",
892
- state: _
893
- },
894
- {
895
- id: "vivid",
896
- label: "Vivid",
897
- state: {
898
- brightness: 0,
899
- contrast: 10,
900
- saturation: 40,
901
- exposure: 0,
902
- clarity: 5,
903
- gamma: 0
904
- }
905
- },
906
- {
907
- id: "mono",
908
- label: "Mono",
909
- // -100 saturation is bit-exact grayscale via Rec. 709 luminance.
910
- state: {
911
- brightness: 0,
912
- contrast: 15,
913
- saturation: -100,
914
- exposure: 0,
915
- clarity: 0,
916
- gamma: 0
917
- }
918
- },
919
- {
920
- id: "soft",
921
- label: "Soft",
922
- state: {
923
- brightness: 5,
924
- contrast: -10,
925
- saturation: 0,
926
- exposure: 0,
927
- clarity: -25,
928
- gamma: 0
929
- }
930
- },
931
- {
932
- id: "punch",
933
- label: "Punch",
934
- state: {
935
- brightness: 0,
936
- contrast: 30,
937
- saturation: 5,
938
- exposure: 0,
939
- clarity: 25,
940
- gamma: 0
941
- }
942
- },
943
- {
944
- id: "mute",
945
- label: "Mute",
946
- state: {
947
- brightness: 0,
948
- contrast: 5,
949
- saturation: -50,
950
- exposure: 0,
951
- clarity: -5,
952
- gamma: 0
953
- }
954
- },
955
- {
956
- id: "bright",
957
- label: "Bright",
958
- state: {
959
- brightness: 5,
960
- contrast: 5,
961
- saturation: 0,
962
- exposure: 15,
963
- clarity: 0,
964
- gamma: 0
965
- }
966
- }
436
+ async function xe(e) {
437
+ if (e.output.type && e.output.type !== "image/jpeg") return e.output;
438
+ let t = await Se(e.source);
439
+ if (!Ce(t, ye)) return e.output;
440
+ let n = we(t);
441
+ if (!n) return e.output;
442
+ let r = await Se(e.output);
443
+ if (!Ce(r, ye)) return e.output;
444
+ let i = new Uint8Array(r.length + n.length);
445
+ return i.set(r.subarray(0, 2), 0), i.set(n, 2), i.set(r.subarray(2), 2 + n.length), new Blob([i], { type: "image/jpeg" });
446
+ }
447
+ async function Se(e) {
448
+ return typeof e.arrayBuffer == "function" ? new Uint8Array(await e.arrayBuffer()) : new Promise((t, n) => {
449
+ let r = new FileReader();
450
+ r.onload = () => {
451
+ let e = r.result;
452
+ e instanceof ArrayBuffer ? t(new Uint8Array(e)) : n(/* @__PURE__ */ Error("FileReader returned a non-ArrayBuffer result"));
453
+ }, r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("FileReader failed")), r.readAsArrayBuffer(e);
454
+ });
455
+ }
456
+ function Ce(e, t) {
457
+ if (e.length < t.length) return !1;
458
+ for (let n = 0; n < t.length; n++) if (e[n] !== t[n]) return !1;
459
+ return !0;
460
+ }
461
+ function we(e) {
462
+ let t = 2;
463
+ for (; t + 4 <= e.length;) {
464
+ if (e[t] !== 255) return;
465
+ let n = e[t + 1];
466
+ if (n === void 0 || n === 218 || n === 217) return;
467
+ let r = e[t + 2] !== void 0 && e[t + 3] !== void 0 ? e[t + 2] * 256 + e[t + 3] : 0;
468
+ if (r < 2) return;
469
+ let i = t + 2 + r;
470
+ if (i > e.length) return;
471
+ if (e[t] === T[0] && e[t + 1] === T[1] && Te(e, t + 4)) return e.slice(t, i);
472
+ t = i;
473
+ }
474
+ }
475
+ function Te(e, t) {
476
+ for (let n = 0; n < be.length; n++) if (e[t + n] !== be[n]) return !1;
477
+ return !0;
478
+ }
479
+ //#endregion
480
+ //#region src/pipeline/encode.ts
481
+ var Ee = "image/png", De = new Set([
482
+ "image/png",
483
+ "image/webp",
484
+ "image/avif"
485
+ ]);
486
+ async function Oe(e, t) {
487
+ return e.mimeChoice === "auto" ? await a("image/webp") ? "image/webp" : !De.has(t.mimeType) && await a("image/jpeg") ? "image/jpeg" : Ee : await a(e.mimeChoice) ? e.mimeChoice : await a("image/webp") ? "image/webp" : Ee;
488
+ }
489
+ function ke(e, t) {
490
+ let n = je(t);
491
+ if (!e) return `kalotyp-image.${n}`;
492
+ let r = Me(e);
493
+ if (!r) return `kalotyp-image.${n}`;
494
+ let i = Pe(r);
495
+ return i ? `${i}.${n}` : `kalotyp-image.${n}`;
496
+ }
497
+ async function Ae(t, r = {}) {
498
+ let i = r.output ?? C, a = await Oe(i, t), o = w(i.quality), s = ke(r.sourceName, a), c = e(t.width, t.height);
499
+ if (c.kind === "offscreen") {
500
+ let e = c.canvas.getContext("2d");
501
+ if (!e) throw Error("2D canvas context is not available");
502
+ e.drawImage(t.bitmap, 0, 0);
503
+ } else {
504
+ let e = c.canvas.getContext("2d");
505
+ if (!e) throw Error("2D canvas context is not available");
506
+ e.drawImage(t.bitmap, 0, 0);
507
+ }
508
+ let l = await n(c, a, o), u = r.output?.stripMetadata === !1 && a === "image/jpeg" && t.mimeType === "image/jpeg" && r.sourceBlob !== void 0 ? await xe({
509
+ source: r.sourceBlob,
510
+ output: l
511
+ }) : l;
512
+ return new File([u], s, { type: a });
513
+ }
514
+ function je(e) {
515
+ if (e === "image/jpeg") return "jpg";
516
+ if (e === "image/png") return "png";
517
+ if (e === "image/webp") return "webp";
518
+ if (e === "image/avif") return "avif";
519
+ let t = e.split("/")[1];
520
+ return t && t.length > 0 ? t : "bin";
521
+ }
522
+ function Me(e) {
523
+ let t = Ne(e).split(/[/\\]/);
524
+ return t[t.length - 1];
525
+ }
526
+ function Ne(e) {
527
+ let t = e.indexOf("?");
528
+ return t === -1 ? e : e.slice(0, t);
529
+ }
530
+ function Pe(e) {
531
+ let t = e.lastIndexOf(".");
532
+ return t <= 0 ? e : e.slice(0, t);
533
+ }
534
+ //#endregion
535
+ //#region src/pipeline/run-chain.ts
536
+ async function Fe(e, t) {
537
+ let n = t;
538
+ for (let t of e) n = await t.plugin.bake(t.state, n);
539
+ return n;
540
+ }
541
+ //#endregion
542
+ //#region src/plugins/annotate/fonts.ts
543
+ var Ie = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif", Le = "\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\", \"Twemoji Mozilla\", \"Android Emoji\", sans-serif", E = [
544
+ {
545
+ key: "system",
546
+ label: "System",
547
+ stack: Ie,
548
+ bunnyName: null,
549
+ generic: "sans-serif"
550
+ },
551
+ {
552
+ key: "inter",
553
+ label: "Inter",
554
+ stack: "\"Inter\", sans-serif",
555
+ bunnyName: "inter",
556
+ generic: "sans-serif"
557
+ },
558
+ {
559
+ key: "roboto",
560
+ label: "Roboto",
561
+ stack: "\"Roboto\", sans-serif",
562
+ bunnyName: "roboto",
563
+ generic: "sans-serif"
564
+ },
565
+ {
566
+ key: "manrope",
567
+ label: "Manrope",
568
+ stack: "\"Manrope\", sans-serif",
569
+ bunnyName: "manrope",
570
+ generic: "sans-serif"
571
+ },
572
+ {
573
+ key: "poppins",
574
+ label: "Poppins",
575
+ stack: "\"Poppins\", sans-serif",
576
+ bunnyName: "poppins",
577
+ generic: "sans-serif"
578
+ },
579
+ {
580
+ key: "nunito",
581
+ label: "Nunito",
582
+ stack: "\"Nunito\", sans-serif",
583
+ bunnyName: "nunito",
584
+ generic: "sans-serif"
585
+ },
586
+ {
587
+ key: "fira-sans",
588
+ label: "Fira Sans",
589
+ stack: "\"Fira Sans\", sans-serif",
590
+ bunnyName: "fira-sans",
591
+ generic: "sans-serif"
592
+ },
593
+ {
594
+ key: "noto-sans",
595
+ label: "Noto Sans",
596
+ stack: "\"Noto Sans\", sans-serif",
597
+ bunnyName: "noto-sans",
598
+ generic: "sans-serif"
599
+ },
600
+ {
601
+ key: "tenor-sans",
602
+ label: "Tenor Sans",
603
+ stack: "\"Tenor Sans\", sans-serif",
604
+ bunnyName: "tenor-sans",
605
+ generic: "sans-serif"
606
+ },
607
+ {
608
+ key: "space-grotesk",
609
+ label: "Space Grotesk",
610
+ stack: "\"Space Grotesk\", sans-serif",
611
+ bunnyName: "space-grotesk",
612
+ generic: "sans-serif"
613
+ },
614
+ {
615
+ key: "chakra-petch",
616
+ label: "Chakra Petch",
617
+ stack: "\"Chakra Petch\", sans-serif",
618
+ bunnyName: "chakra-petch",
619
+ generic: "sans-serif"
620
+ },
621
+ {
622
+ key: "lora",
623
+ label: "Lora",
624
+ stack: "\"Lora\", serif",
625
+ bunnyName: "lora",
626
+ generic: "serif"
627
+ },
628
+ {
629
+ key: "merriweather",
630
+ label: "Merriweather",
631
+ stack: "\"Merriweather\", serif",
632
+ bunnyName: "merriweather",
633
+ generic: "serif"
634
+ },
635
+ {
636
+ key: "noto-serif",
637
+ label: "Noto Serif",
638
+ stack: "\"Noto Serif\", serif",
639
+ bunnyName: "noto-serif",
640
+ generic: "serif"
641
+ },
642
+ {
643
+ key: "ibm-plex-serif",
644
+ label: "IBM Plex Serif",
645
+ stack: "\"IBM Plex Serif\", serif",
646
+ bunnyName: "ibm-plex-serif",
647
+ generic: "serif"
648
+ },
649
+ {
650
+ key: "cardo",
651
+ label: "Cardo",
652
+ stack: "\"Cardo\", serif",
653
+ bunnyName: "cardo",
654
+ generic: "serif"
655
+ },
656
+ {
657
+ key: "old-standard-tt",
658
+ label: "Old Standard TT",
659
+ stack: "\"Old Standard TT\", serif",
660
+ bunnyName: "old-standard-tt",
661
+ generic: "serif"
662
+ },
663
+ {
664
+ key: "prata",
665
+ label: "Prata",
666
+ stack: "\"Prata\", serif",
667
+ bunnyName: "prata",
668
+ generic: "serif"
669
+ },
670
+ {
671
+ key: "rufina",
672
+ label: "Rufina",
673
+ stack: "\"Rufina\", serif",
674
+ bunnyName: "rufina",
675
+ generic: "serif"
676
+ },
677
+ {
678
+ key: "jetbrains-mono",
679
+ label: "JetBrains Mono",
680
+ stack: "\"JetBrains Mono\", monospace",
681
+ bunnyName: "jetbrains-mono",
682
+ generic: "monospace"
683
+ },
684
+ {
685
+ key: "fira-mono",
686
+ label: "Fira Mono",
687
+ stack: "\"Fira Mono\", monospace",
688
+ bunnyName: "fira-mono",
689
+ generic: "monospace"
690
+ },
691
+ {
692
+ key: "space-mono",
693
+ label: "Space Mono",
694
+ stack: "\"Space Mono\", monospace",
695
+ bunnyName: "space-mono",
696
+ generic: "monospace"
697
+ }
698
+ ], D = new Map(E.map((e) => [e.key, e]));
699
+ function O(e) {
700
+ return D.get(e)?.stack ?? "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
701
+ }
702
+ function Re(e) {
703
+ return D.get(e) ?? E[0];
704
+ }
705
+ function k(e, t = 1) {
706
+ return `${e.fontStyle === "italic" ? "italic " : ""}${e.fontWeight === "bold" ? "bold " : ""}${e.fontSize * t}px ${O(e.fontFamily)}`;
707
+ }
708
+ //#endregion
709
+ //#region src/plugins/annotate/smooth.ts
710
+ var ze = 2;
711
+ function Be(e) {
712
+ if (e.length <= 1) return [...e];
713
+ let t = e[0];
714
+ if (!t) return [];
715
+ let n = [t], r = t;
716
+ for (let t = 1; t < e.length - 1; t++) {
717
+ let i = e[t];
718
+ if (!i) continue;
719
+ let a = i.x - r.x, o = i.y - r.y;
720
+ a * a + o * o < 4 || (n.push(i), r = i);
721
+ }
722
+ let i = e[e.length - 1];
723
+ return i && i !== r && n.push(i), n;
724
+ }
725
+ function A(e, t) {
726
+ if (t.length === 0) return;
727
+ let n = t[0];
728
+ if (!n) return;
729
+ if (t.length === 1) {
730
+ e.moveTo(n.x, n.y), e.lineTo(n.x, n.y);
731
+ return;
732
+ }
733
+ e.moveTo(n.x, n.y);
734
+ for (let n = 1; n < t.length - 1; n++) {
735
+ let r = t[n], i = t[n + 1];
736
+ if (!r || !i) continue;
737
+ let a = (r.x + i.x) / 2, o = (r.y + i.y) / 2;
738
+ e.quadraticCurveTo(r.x, r.y, a, o);
739
+ }
740
+ let r = t[t.length - 1];
741
+ r && e.lineTo(r.x, r.y);
742
+ }
743
+ //#endregion
744
+ //#region src/plugins/annotate/state.ts
745
+ var Ve = "rgba(255, 235, 59, 0.35)", He = 18, Ue = 6, We = 32, Ge = "#ff3b30", Ke = 4, j = "system", qe = "😀", Je = 8;
746
+ function Ye(e) {
747
+ let t = Math.min(e.width, e.height);
748
+ return Math.max(64, Math.round(t * .2));
749
+ }
750
+ function M(e) {
751
+ return (e % 360 + 360) % 360;
752
+ }
753
+ function N() {
754
+ return {
755
+ color: Ge,
756
+ strokeWidth: 4,
757
+ fillColor: null,
758
+ fontSize: 32,
759
+ fontFamily: j,
760
+ fontWeight: "normal",
761
+ fontStyle: "normal",
762
+ textAlign: "left",
763
+ emoji: qe
764
+ };
765
+ }
766
+ function P(e) {
767
+ return typeof e.fontFamily == "string" && (e.fontWeight === "normal" || e.fontWeight === "bold") && (e.fontStyle === "normal" || e.fontStyle === "italic") ? e : {
768
+ ...e,
769
+ fontFamily: typeof e.fontFamily == "string" ? e.fontFamily : j,
770
+ fontWeight: e.fontWeight === "bold" ? "bold" : "normal",
771
+ fontStyle: e.fontStyle === "italic" ? "italic" : "normal"
772
+ };
773
+ }
774
+ function Xe(e) {
775
+ return {
776
+ shapes: [],
777
+ selectedId: null,
778
+ activeTool: "select",
779
+ currentStyle: N(),
780
+ imageSize: e.imageSize,
781
+ nextShapeNumber: 1
782
+ };
783
+ }
784
+ function Ze(e) {
785
+ return {
786
+ id: `s_${e.nextShapeNumber.toString(36)}`,
787
+ nextShapeNumber: e.nextShapeNumber + 1
788
+ };
789
+ }
790
+ function Qe(e, t) {
791
+ return e.activeTool === t ? e : {
792
+ ...e,
793
+ activeTool: t,
794
+ selectedId: t === "select" ? e.selectedId : null
795
+ };
796
+ }
797
+ function $e(e, t) {
798
+ return {
799
+ ...e,
800
+ currentStyle: {
801
+ ...e.currentStyle,
802
+ ...t
803
+ }
804
+ };
805
+ }
806
+ function et(e, t) {
807
+ return e.selectedId === t ? e : {
808
+ ...e,
809
+ selectedId: t
810
+ };
811
+ }
812
+ function tt(e, t) {
813
+ return {
814
+ ...e,
815
+ shapes: [...e.shapes, t],
816
+ selectedId: t.id
817
+ };
818
+ }
819
+ function nt(e, t) {
820
+ let n = !1, r = e.shapes.map((e) => e.id === t.id ? (n = !0, t) : e);
821
+ return n ? {
822
+ ...e,
823
+ shapes: r
824
+ } : e;
825
+ }
826
+ function rt(e, t) {
827
+ let n = e.shapes.filter((e) => e.id !== t);
828
+ return n.length === e.shapes.length ? e : {
829
+ ...e,
830
+ shapes: n,
831
+ selectedId: e.selectedId === t ? null : e.selectedId
832
+ };
833
+ }
834
+ function it(e, t) {
835
+ if (t !== null) return e.shapes.find((e) => e.id === t);
836
+ }
837
+ function at(e) {
838
+ let { x: t, y: n, width: r, height: i } = e;
839
+ return r < 0 && (t += r, r = -r), i < 0 && (n += i, i = -i), {
840
+ x: t,
841
+ y: n,
842
+ width: r,
843
+ height: i
844
+ };
845
+ }
846
+ function ot(e, t, n) {
847
+ switch (e.kind) {
848
+ case "text": return {
849
+ ...e,
850
+ x: e.x + t,
851
+ y: e.y + n
852
+ };
853
+ case "rect":
854
+ case "ellipse":
855
+ case "emoji": return {
856
+ ...e,
857
+ x: e.x + t,
858
+ y: e.y + n
859
+ };
860
+ case "arrow": return {
861
+ ...e,
862
+ x1: e.x1 + t,
863
+ y1: e.y1 + n,
864
+ x2: e.x2 + t,
865
+ y2: e.y2 + n
866
+ };
867
+ case "freehand":
868
+ case "highlight": return {
869
+ ...e,
870
+ points: e.points.map((e) => ({
871
+ x: e.x + t,
872
+ y: e.y + n
873
+ }))
874
+ };
875
+ default: return F(e);
876
+ }
877
+ }
878
+ function F(e) {
879
+ throw Error(`Unhandled annotation shape kind: ${JSON.stringify(e)}`);
880
+ }
881
+ function st(e, t, n) {
882
+ if (t === "horizontal") switch (e.kind) {
883
+ case "rect":
884
+ case "ellipse": return {
885
+ ...e,
886
+ x: n.width - e.x - e.width
887
+ };
888
+ case "emoji": return {
889
+ ...e,
890
+ x: n.width - e.x - e.size,
891
+ rotation: M(-e.rotation)
892
+ };
893
+ case "text": return {
894
+ ...e,
895
+ x: n.width - e.x
896
+ };
897
+ case "arrow": return {
898
+ ...e,
899
+ x1: n.width - e.x1,
900
+ x2: n.width - e.x2
901
+ };
902
+ case "freehand":
903
+ case "highlight": return {
904
+ ...e,
905
+ points: e.points.map((e) => ({
906
+ x: n.width - e.x,
907
+ y: e.y
908
+ }))
909
+ };
910
+ default: return F(e);
911
+ }
912
+ switch (e.kind) {
913
+ case "rect":
914
+ case "ellipse": return {
915
+ ...e,
916
+ y: n.height - e.y - e.height
917
+ };
918
+ case "emoji": return {
919
+ ...e,
920
+ y: n.height - e.y - e.size,
921
+ rotation: M(180 - e.rotation)
922
+ };
923
+ case "text": return {
924
+ ...e,
925
+ y: n.height - e.y
926
+ };
927
+ case "arrow": return {
928
+ ...e,
929
+ y1: n.height - e.y1,
930
+ y2: n.height - e.y2
931
+ };
932
+ case "freehand":
933
+ case "highlight": return {
934
+ ...e,
935
+ points: e.points.map((e) => ({
936
+ x: e.x,
937
+ y: n.height - e.y
938
+ }))
939
+ };
940
+ default: return F(e);
941
+ }
942
+ }
943
+ function ct(e, t, n) {
944
+ if (t === 0) return e;
945
+ let r = (e, r) => t === 1 ? {
946
+ x: n.height - r,
947
+ y: e
948
+ } : t === 2 ? {
949
+ x: n.width - e,
950
+ y: n.height - r
951
+ } : {
952
+ x: r,
953
+ y: n.width - e
954
+ };
955
+ switch (e.kind) {
956
+ case "rect":
957
+ case "ellipse": {
958
+ let t = [r(e.x, e.y), r(e.x + e.width, e.y + e.height)], n = Math.min(t[0].x, t[1].x), i = Math.min(t[0].y, t[1].y), a = Math.abs(t[1].x - t[0].x), o = Math.abs(t[1].y - t[0].y);
959
+ return {
960
+ ...e,
961
+ x: n,
962
+ y: i,
963
+ width: a,
964
+ height: o
965
+ };
966
+ }
967
+ case "emoji": {
968
+ let n = [r(e.x, e.y), r(e.x + e.size, e.y + e.size)], i = Math.min(n[0].x, n[1].x), a = Math.min(n[0].y, n[1].y);
969
+ return {
970
+ ...e,
971
+ x: i,
972
+ y: a,
973
+ rotation: M(e.rotation + t * 90)
974
+ };
975
+ }
976
+ case "text": {
977
+ let t = r(e.x, e.y);
978
+ return {
979
+ ...e,
980
+ x: t.x,
981
+ y: t.y
982
+ };
983
+ }
984
+ case "arrow": {
985
+ let t = r(e.x1, e.y1), n = r(e.x2, e.y2);
986
+ return {
987
+ ...e,
988
+ x1: t.x,
989
+ y1: t.y,
990
+ x2: n.x,
991
+ y2: n.y
992
+ };
993
+ }
994
+ case "freehand":
995
+ case "highlight": return {
996
+ ...e,
997
+ points: e.points.map((e) => r(e.x, e.y))
998
+ };
999
+ default: return F(e);
1000
+ }
1001
+ }
1002
+ function lt(e, t) {
1003
+ return e.shapes.length === 0 ? e : {
1004
+ ...e,
1005
+ shapes: e.shapes.map(t)
1006
+ };
1007
+ }
1008
+ var ut = [
1009
+ "text",
1010
+ "rect",
1011
+ "ellipse",
1012
+ "arrow",
1013
+ "emoji"
967
1014
  ];
968
- function on(t, n) {
969
- return t.brightness === n.brightness && t.contrast === n.contrast && t.saturation === n.saturation && t.exposure === n.exposure && t.clarity === n.clarity && t.gamma === n.gamma;
970
- }
971
- function Fe(t) {
972
- for (const n of rn)
973
- if (on(n.state, t)) return n;
974
- }
975
- const Pe = "rgba(255, 235, 59, 0.35)", Oe = 18, _e = 6, an = 32, cn = "#ff3b30", sn = 4;
976
- function ln() {
977
- return {
978
- color: cn,
979
- strokeWidth: sn,
980
- fillColor: null,
981
- fontSize: an
982
- };
983
- }
984
- function ze(t) {
985
- return {
986
- shapes: [],
987
- selectedId: null,
988
- activeTool: "select",
989
- currentStyle: ln(),
990
- imageSize: t.imageSize,
991
- nextShapeNumber: 1
992
- };
993
- }
994
- function De(t) {
995
- return {
996
- id: `s_${t.nextShapeNumber.toString(36)}`,
997
- nextShapeNumber: t.nextShapeNumber + 1
998
- };
999
- }
1000
- function Le(t, n) {
1001
- return t.activeTool === n ? t : { ...t, activeTool: n, selectedId: n === "select" ? t.selectedId : null };
1002
- }
1003
- function Be(t, n) {
1004
- return { ...t, currentStyle: { ...t.currentStyle, ...n } };
1005
- }
1006
- function We(t, n) {
1007
- return t.selectedId === n ? t : { ...t, selectedId: n };
1008
- }
1009
- function Ye(t, n) {
1010
- return { ...t, shapes: [...t.shapes, n], selectedId: n.id };
1011
- }
1012
- function Xe(t, n) {
1013
- let e = !1;
1014
- const i = t.shapes.map((r) => r.id !== n.id ? r : (e = !0, n));
1015
- return e ? { ...t, shapes: i } : t;
1016
- }
1017
- function Ue(t, n) {
1018
- const e = t.shapes.filter((i) => i.id !== n);
1019
- return e.length === t.shapes.length ? t : {
1020
- ...t,
1021
- shapes: e,
1022
- selectedId: t.selectedId === n ? null : t.selectedId
1023
- };
1024
- }
1025
- function He(t, n) {
1026
- if (n !== null)
1027
- return t.shapes.find((e) => e.id === n);
1028
- }
1029
- function qe(t) {
1030
- let { x: n, y: e, width: i, height: r } = t;
1031
- return i < 0 && (n += i, i = -i), r < 0 && (e += r, r = -r), { x: n, y: e, width: i, height: r };
1032
- }
1033
- function je(t, n, e) {
1034
- switch (t.kind) {
1035
- case "text":
1036
- return { ...t, x: t.x + n, y: t.y + e };
1037
- case "rect":
1038
- case "ellipse":
1039
- return { ...t, x: t.x + n, y: t.y + e };
1040
- case "arrow":
1041
- return {
1042
- ...t,
1043
- x1: t.x1 + n,
1044
- y1: t.y1 + e,
1045
- x2: t.x2 + n,
1046
- y2: t.y2 + e
1047
- };
1048
- case "freehand":
1049
- case "highlight":
1050
- return { ...t, points: t.points.map((i) => ({ x: i.x + n, y: i.y + e })) };
1051
- default:
1052
- return w(t);
1053
- }
1054
- }
1055
- function w(t) {
1056
- throw new Error(`Unhandled annotation shape kind: ${JSON.stringify(t)}`);
1057
- }
1058
- function $e(t, n, e) {
1059
- if (n === "horizontal")
1060
- switch (t.kind) {
1061
- case "rect":
1062
- case "ellipse":
1063
- return { ...t, x: e.width - t.x - t.width };
1064
- case "text":
1065
- return { ...t, x: e.width - t.x };
1066
- case "arrow":
1067
- return { ...t, x1: e.width - t.x1, x2: e.width - t.x2 };
1068
- case "freehand":
1069
- case "highlight":
1070
- return {
1071
- ...t,
1072
- points: t.points.map((i) => ({ x: e.width - i.x, y: i.y }))
1073
- };
1074
- default:
1075
- return w(t);
1076
- }
1077
- switch (t.kind) {
1078
- case "rect":
1079
- case "ellipse":
1080
- return { ...t, y: e.height - t.y - t.height };
1081
- case "text":
1082
- return { ...t, y: e.height - t.y };
1083
- case "arrow":
1084
- return { ...t, y1: e.height - t.y1, y2: e.height - t.y2 };
1085
- case "freehand":
1086
- case "highlight":
1087
- return {
1088
- ...t,
1089
- points: t.points.map((i) => ({ x: i.x, y: e.height - i.y }))
1090
- };
1091
- default:
1092
- return w(t);
1093
- }
1094
- }
1095
- function Qe(t, n, e) {
1096
- if (n === 0) return t;
1097
- const i = (r, o) => n === 1 ? { x: e.height - o, y: r } : n === 2 ? { x: e.width - r, y: e.height - o } : { x: o, y: e.width - r };
1098
- switch (t.kind) {
1099
- case "rect":
1100
- case "ellipse": {
1101
- const r = [
1102
- i(t.x, t.y),
1103
- i(t.x + t.width, t.y + t.height)
1104
- ], o = Math.min(r[0].x, r[1].x), a = Math.min(r[0].y, r[1].y), c = Math.abs(r[1].x - r[0].x), l = Math.abs(r[1].y - r[0].y);
1105
- return { ...t, x: o, y: a, width: c, height: l };
1106
- }
1107
- case "text": {
1108
- const r = i(t.x, t.y);
1109
- return { ...t, x: r.x, y: r.y };
1110
- }
1111
- case "arrow": {
1112
- const r = i(t.x1, t.y1), o = i(t.x2, t.y2);
1113
- return { ...t, x1: r.x, y1: r.y, x2: o.x, y2: o.y };
1114
- }
1115
- case "freehand":
1116
- case "highlight":
1117
- return { ...t, points: t.points.map((r) => i(r.x, r.y)) };
1118
- default:
1119
- return w(t);
1120
- }
1121
- }
1122
- function Ke(t, n) {
1123
- return t.shapes.length === 0 ? t : { ...t, shapes: t.shapes.map(n) };
1124
- }
1125
- const Ve = [
1126
- "text",
1127
- "rect",
1128
- "ellipse",
1129
- "arrow"
1015
+ function dt(e) {
1016
+ return e === "text" || e === "rect" || e === "ellipse" || e === "arrow" || e === "emoji";
1017
+ }
1018
+ function ft(e, t) {
1019
+ let { imageSize: n, style: r, id: i } = t, a = Math.min(n.width, n.height), o = n.width / 2, s = n.height / 2;
1020
+ switch (e) {
1021
+ case "rect":
1022
+ case "ellipse": {
1023
+ let t = Math.max(80, Math.round(a * .25)), n = Math.round(o - t / 2), c = Math.round(s - t / 2);
1024
+ return e === "rect" ? {
1025
+ id: i,
1026
+ kind: "rect",
1027
+ x: n,
1028
+ y: c,
1029
+ width: t,
1030
+ height: t,
1031
+ strokeColor: r.color,
1032
+ strokeWidth: r.strokeWidth,
1033
+ fillColor: r.fillColor
1034
+ } : {
1035
+ id: i,
1036
+ kind: "ellipse",
1037
+ x: n,
1038
+ y: c,
1039
+ width: t,
1040
+ height: t,
1041
+ strokeColor: r.color,
1042
+ strokeWidth: r.strokeWidth,
1043
+ fillColor: r.fillColor
1044
+ };
1045
+ }
1046
+ case "arrow": {
1047
+ let e = Math.max(100, Math.round(a * .3)), t = Math.round(o - e / 2), n = t + e, c = Math.round(s);
1048
+ return {
1049
+ id: i,
1050
+ kind: "arrow",
1051
+ x1: t,
1052
+ y1: c,
1053
+ x2: n,
1054
+ y2: c,
1055
+ color: r.color,
1056
+ strokeWidth: r.strokeWidth
1057
+ };
1058
+ }
1059
+ case "text": return {
1060
+ id: i,
1061
+ kind: "text",
1062
+ x: Math.round(o),
1063
+ y: Math.round(s - r.fontSize / 2),
1064
+ text: "",
1065
+ fontSize: r.fontSize,
1066
+ color: r.color,
1067
+ textAlign: r.textAlign,
1068
+ fontFamily: r.fontFamily,
1069
+ fontWeight: r.fontWeight,
1070
+ fontStyle: r.fontStyle
1071
+ };
1072
+ case "emoji": {
1073
+ let e = Ye(n);
1074
+ return {
1075
+ id: i,
1076
+ kind: "emoji",
1077
+ x: Math.round(o - e / 2),
1078
+ y: Math.round(s - e / 2),
1079
+ emoji: r.emoji,
1080
+ size: e,
1081
+ rotation: 0
1082
+ };
1083
+ }
1084
+ }
1085
+ }
1086
+ //#endregion
1087
+ //#region src/plugins/annotate/text-layout.ts
1088
+ var I = 1.2;
1089
+ function L(e) {
1090
+ return e.length === 0 ? [""] : e.split("\n");
1091
+ }
1092
+ function R(e, t) {
1093
+ let n = L(e.text), r = 0;
1094
+ for (let e of n) {
1095
+ let n = t(e);
1096
+ n > r && (r = n);
1097
+ }
1098
+ return r = Math.max(r, e.fontSize * .6), {
1099
+ lines: n,
1100
+ width: r,
1101
+ height: n.length * e.fontSize * I
1102
+ };
1103
+ }
1104
+ function z(e, t) {
1105
+ return e.length * t * .55;
1106
+ }
1107
+ function pt(e, t, n) {
1108
+ switch (n) {
1109
+ case "left": return 0;
1110
+ case "center": return (e - t) / 2;
1111
+ case "right": return e - t;
1112
+ }
1113
+ }
1114
+ //#endregion
1115
+ //#region src/plugins/annotate/bake.ts
1116
+ var mt = 400;
1117
+ async function ht(e) {
1118
+ if (typeof document > "u" || !("fonts" in document)) return;
1119
+ let t = /* @__PURE__ */ new Set();
1120
+ for (let n of e) n.kind === "text" && t.add(k(P(n)));
1121
+ if (t.size === 0) return;
1122
+ let n = new Promise((e) => setTimeout(e, mt)), r = Promise.all([...t].map((e) => document.fonts.load(e))).then(() => document.fonts.ready).then(() => void 0).catch(() => void 0);
1123
+ await Promise.race([r, n]);
1124
+ }
1125
+ async function gt(n, r, i) {
1126
+ if (n.shapes.length === 0) return r;
1127
+ await ht(n.shapes);
1128
+ let a = e(r.width, r.height), o = t(a);
1129
+ o.imageSmoothingEnabled = !0, o.imageSmoothingQuality = "high", o.drawImage(r.bitmap, 0, 0, r.width, r.height);
1130
+ for (let e of n.shapes) _t(o, e, i);
1131
+ return {
1132
+ bitmap: a.canvas,
1133
+ width: r.width,
1134
+ height: r.height,
1135
+ mimeType: r.mimeType
1136
+ };
1137
+ }
1138
+ function _t(e, t, n) {
1139
+ switch (t.kind) {
1140
+ case "text":
1141
+ yt(e, t);
1142
+ return;
1143
+ case "rect":
1144
+ bt(e, t);
1145
+ return;
1146
+ case "ellipse":
1147
+ xt(e, t);
1148
+ return;
1149
+ case "arrow":
1150
+ St(e, t);
1151
+ return;
1152
+ case "freehand":
1153
+ Ct(e, t);
1154
+ return;
1155
+ case "highlight":
1156
+ wt(e, t);
1157
+ return;
1158
+ case "emoji":
1159
+ vt(e, t, n?.resolveEmojiImage);
1160
+ return;
1161
+ default: F(t);
1162
+ }
1163
+ }
1164
+ function vt(e, t, n) {
1165
+ let r = n?.(t.emoji) ?? null;
1166
+ if (e.save(), t.rotation) {
1167
+ let n = t.x + t.size / 2, r = t.y + t.size / 2;
1168
+ e.translate(n, r), e.rotate(t.rotation * Math.PI / 180), e.translate(-n, -r);
1169
+ }
1170
+ r ? e.drawImage(r, t.x, t.y, t.size, t.size) : (e.textAlign = "left", e.textBaseline = "top", e.font = `${t.size}px ${Le}`, e.fillText(t.emoji, t.x, t.y)), e.restore();
1171
+ }
1172
+ function yt(e, t) {
1173
+ let n = P(t);
1174
+ e.save(), e.fillStyle = n.color, e.font = k(n), e.textAlign = "left", e.textBaseline = "top";
1175
+ let r = L(n.text), i = r.map((t) => e.measureText(t).width), a = i.reduce((e, t) => t > e ? t : e, 0), o = n.fontSize * I;
1176
+ for (let t = 0; t < r.length; t++) {
1177
+ let s = r[t];
1178
+ if (s === void 0) continue;
1179
+ let c = pt(a, i[t] ?? 0, n.textAlign);
1180
+ e.fillText(s, n.x + c, n.y + t * o);
1181
+ }
1182
+ e.restore();
1183
+ }
1184
+ function bt(e, t) {
1185
+ e.save(), t.fillColor !== null && (e.fillStyle = t.fillColor, e.fillRect(t.x, t.y, t.width, t.height)), t.strokeWidth > 0 && (e.strokeStyle = t.strokeColor, e.lineWidth = t.strokeWidth, e.lineJoin = "miter", e.strokeRect(t.x, t.y, t.width, t.height)), e.restore();
1186
+ }
1187
+ function xt(e, t) {
1188
+ e.save();
1189
+ let n = t.width / 2, r = t.height / 2, i = t.x + n, a = t.y + r;
1190
+ e.beginPath(), e.ellipse(i, a, Math.max(0, n), Math.max(0, r), 0, 0, Math.PI * 2), t.fillColor !== null && (e.fillStyle = t.fillColor, e.fill()), t.strokeWidth > 0 && (e.strokeStyle = t.strokeColor, e.lineWidth = t.strokeWidth, e.stroke()), e.restore();
1191
+ }
1192
+ function St(e, t) {
1193
+ let n = t.x2 - t.x1, r = t.y2 - t.y1, i = Math.sqrt(n * n + r * r);
1194
+ if (i < .5) return;
1195
+ e.save(), e.strokeStyle = t.color, e.fillStyle = t.color, e.lineWidth = t.strokeWidth, e.lineCap = "round", e.lineJoin = "round";
1196
+ let a = Math.min(Math.max(t.strokeWidth * 5, 28), i * .6), o = Math.max(t.strokeWidth * 4, 18), s = n / i, c = r / i, l = t.x2 - s * a * .6, u = t.y2 - c * a * .6;
1197
+ e.beginPath(), e.moveTo(t.x1, t.y1), e.lineTo(l, u), e.stroke();
1198
+ let d = t.x2 - s * a, f = t.y2 - c * a, p = -c, m = s;
1199
+ e.beginPath(), e.moveTo(t.x2, t.y2), e.lineTo(d + p * o / 2, f + m * o / 2), e.lineTo(d - p * o / 2, f - m * o / 2), e.closePath(), e.fill(), e.restore();
1200
+ }
1201
+ function Ct(e, t) {
1202
+ t.points.length !== 0 && (e.save(), e.strokeStyle = t.color, e.lineWidth = t.strokeWidth, e.lineCap = "round", e.lineJoin = "round", e.beginPath(), A(e, t.points), e.stroke(), e.restore());
1203
+ }
1204
+ function wt(e, t) {
1205
+ t.points.length !== 0 && (e.save(), e.globalCompositeOperation = "multiply", e.strokeStyle = t.color, e.lineWidth = t.strokeWidth, e.lineCap = "round", e.lineJoin = "round", e.beginPath(), A(e, t.points), e.stroke(), e.restore());
1206
+ }
1207
+ //#endregion
1208
+ //#region src/plugins/annotate/geometry.ts
1209
+ function B(e) {
1210
+ switch (e.kind) {
1211
+ case "text": {
1212
+ let t = P(e), { width: n, height: r } = R(t, (e) => z(e, t.fontSize));
1213
+ return {
1214
+ x: t.x,
1215
+ y: t.y,
1216
+ width: n,
1217
+ height: r
1218
+ };
1219
+ }
1220
+ case "rect":
1221
+ case "ellipse": return {
1222
+ x: e.x,
1223
+ y: e.y,
1224
+ width: e.width,
1225
+ height: e.height
1226
+ };
1227
+ case "emoji": return {
1228
+ x: e.x,
1229
+ y: e.y,
1230
+ width: e.size,
1231
+ height: e.size
1232
+ };
1233
+ case "arrow": return {
1234
+ x: Math.min(e.x1, e.x2),
1235
+ y: Math.min(e.y1, e.y2),
1236
+ width: Math.abs(e.x2 - e.x1),
1237
+ height: Math.abs(e.y2 - e.y1)
1238
+ };
1239
+ case "freehand":
1240
+ case "highlight": {
1241
+ let t = e.points[0];
1242
+ if (!t) return {
1243
+ x: 0,
1244
+ y: 0,
1245
+ width: 0,
1246
+ height: 0
1247
+ };
1248
+ let n = t.x, r = t.y, i = t.x, a = t.y;
1249
+ for (let t of e.points) t.x < n && (n = t.x), t.x > i && (i = t.x), t.y < r && (r = t.y), t.y > a && (a = t.y);
1250
+ return {
1251
+ x: n,
1252
+ y: r,
1253
+ width: i - n,
1254
+ height: a - r
1255
+ };
1256
+ }
1257
+ default: return F(e);
1258
+ }
1259
+ }
1260
+ var Tt = [
1261
+ "tl",
1262
+ "tr",
1263
+ "bl",
1264
+ "br",
1265
+ "t",
1266
+ "r",
1267
+ "b",
1268
+ "l"
1130
1269
  ];
1131
- function Ge(t) {
1132
- return t === "text" || t === "rect" || t === "ellipse" || t === "arrow";
1133
- }
1134
- function Je(t, n) {
1135
- const { imageSize: e, style: i, id: r } = n, o = Math.min(e.width, e.height), a = e.width / 2, c = e.height / 2;
1136
- switch (t) {
1137
- case "rect":
1138
- case "ellipse": {
1139
- const l = Math.max(80, Math.round(o * 0.25)), s = Math.round(a - l / 2), u = Math.round(c - l / 2);
1140
- return t === "rect" ? {
1141
- id: r,
1142
- kind: "rect",
1143
- x: s,
1144
- y: u,
1145
- width: l,
1146
- height: l,
1147
- strokeColor: i.color,
1148
- strokeWidth: i.strokeWidth,
1149
- fillColor: i.fillColor
1150
- } : {
1151
- id: r,
1152
- kind: "ellipse",
1153
- x: s,
1154
- y: u,
1155
- width: l,
1156
- height: l,
1157
- strokeColor: i.color,
1158
- strokeWidth: i.strokeWidth,
1159
- fillColor: i.fillColor
1160
- };
1161
- }
1162
- case "arrow": {
1163
- const l = Math.max(100, Math.round(o * 0.3)), s = Math.round(a - l / 2), u = s + l, h = Math.round(c);
1164
- return {
1165
- id: r,
1166
- kind: "arrow",
1167
- x1: s,
1168
- y1: h,
1169
- x2: u,
1170
- y2: h,
1171
- color: i.color,
1172
- strokeWidth: i.strokeWidth
1173
- };
1174
- }
1175
- case "text": {
1176
- const l = Math.round(a), s = Math.round(c - i.fontSize / 2);
1177
- return {
1178
- id: r,
1179
- kind: "text",
1180
- x: l,
1181
- y: s,
1182
- text: "",
1183
- fontSize: i.fontSize,
1184
- color: i.color,
1185
- textAlign: "center"
1186
- };
1187
- }
1188
- }
1189
- }
1190
- function nt(t) {
1191
- switch (t.kind) {
1192
- case "text": {
1193
- const { width: n, height: e } = un(t.text, t.fontSize);
1194
- return { x: hn(t.x, n, t.textAlign), y: t.y, width: n, height: e };
1195
- }
1196
- case "rect":
1197
- case "ellipse":
1198
- return { x: t.x, y: t.y, width: t.width, height: t.height };
1199
- case "arrow": {
1200
- const n = Math.min(t.x1, t.x2), e = Math.min(t.y1, t.y2);
1201
- return {
1202
- x: n,
1203
- y: e,
1204
- width: Math.abs(t.x2 - t.x1),
1205
- height: Math.abs(t.y2 - t.y1)
1206
- };
1207
- }
1208
- case "freehand":
1209
- case "highlight": {
1210
- const n = t.points[0];
1211
- if (!n) return { x: 0, y: 0, width: 0, height: 0 };
1212
- let e = n.x, i = n.y, r = n.x, o = n.y;
1213
- for (const a of t.points)
1214
- a.x < e && (e = a.x), a.x > r && (r = a.x), a.y < i && (i = a.y), a.y > o && (o = a.y);
1215
- return { x: e, y: i, width: r - e, height: o - i };
1216
- }
1217
- default:
1218
- return w(t);
1219
- }
1220
- }
1221
- const Ze = [
1222
- "tl",
1223
- "tr",
1224
- "bl",
1225
- "br",
1226
- "t",
1227
- "r",
1228
- "b",
1229
- "l"
1270
+ function Et(e) {
1271
+ let t = e.x, n = e.x + e.width, r = e.y, i = e.y + e.height, a = e.x + e.width / 2, o = e.y + e.height / 2;
1272
+ return {
1273
+ tl: {
1274
+ x: t,
1275
+ y: r
1276
+ },
1277
+ tr: {
1278
+ x: n,
1279
+ y: r
1280
+ },
1281
+ bl: {
1282
+ x: t,
1283
+ y: i
1284
+ },
1285
+ br: {
1286
+ x: n,
1287
+ y: i
1288
+ },
1289
+ t: {
1290
+ x: a,
1291
+ y: r
1292
+ },
1293
+ r: {
1294
+ x: n,
1295
+ y: o
1296
+ },
1297
+ b: {
1298
+ x: a,
1299
+ y: i
1300
+ },
1301
+ l: {
1302
+ x: t,
1303
+ y: o
1304
+ }
1305
+ };
1306
+ }
1307
+ function Dt(e, t, n) {
1308
+ let r = e.x, i = e.y, a = e.x + e.width, o = e.y + e.height;
1309
+ return (t === "tl" || t === "l" || t === "bl") && (r = n.x), (t === "tr" || t === "r" || t === "br") && (a = n.x), (t === "tl" || t === "t" || t === "tr") && (i = n.y), (t === "bl" || t === "b" || t === "br") && (o = n.y), {
1310
+ x: r,
1311
+ y: i,
1312
+ width: a - r,
1313
+ height: o - i
1314
+ };
1315
+ }
1316
+ //#endregion
1317
+ //#region src/plugins/annotate/hit-test.ts
1318
+ var Ot = 4;
1319
+ function kt(e, t) {
1320
+ for (let n = e.length - 1; n >= 0; n--) {
1321
+ let r = e[n];
1322
+ if (r && At(r, t)) return r;
1323
+ }
1324
+ }
1325
+ function At(e, t) {
1326
+ switch (e.kind) {
1327
+ case "text": return V(t, B(e));
1328
+ case "emoji": {
1329
+ let n = B(e);
1330
+ if (!e.rotation) return V(t, n);
1331
+ let r = n.x + n.width / 2, i = n.y + n.height / 2, a = -e.rotation * Math.PI / 180, o = t.x - r, s = t.y - i;
1332
+ return V({
1333
+ x: r + o * Math.cos(a) - s * Math.sin(a),
1334
+ y: i + o * Math.sin(a) + s * Math.cos(a)
1335
+ }, n);
1336
+ }
1337
+ case "rect": {
1338
+ let n = V(t, U(e));
1339
+ if (e.fillColor !== null) return n;
1340
+ let r = H(U(e), e.strokeWidth / 2 + 4), i = H(U(e), -(e.strokeWidth / 2 + 4));
1341
+ return V(t, r) && !V(t, i);
1342
+ }
1343
+ case "ellipse": {
1344
+ let n = U(e), r = n.width / 2, i = n.height / 2, a = n.x + r, o = n.y + i;
1345
+ if (r <= 0 || i <= 0) return !1;
1346
+ let s = (t.x - a) / r, c = (t.y - o) / i, l = s * s + c * c, u = (e.strokeWidth / 2 + 4) / Math.min(r, i);
1347
+ return e.fillColor === null ? l <= (1 + u) ** 2 && l >= (1 - u) ** 2 : l <= (1 + u) ** 2;
1348
+ }
1349
+ case "arrow": return jt(t, {
1350
+ x: e.x1,
1351
+ y: e.y1
1352
+ }, {
1353
+ x: e.x2,
1354
+ y: e.y2
1355
+ }, e.strokeWidth / 2 + 4);
1356
+ case "freehand":
1357
+ case "highlight": {
1358
+ if (!V(t, H(B(e), e.strokeWidth / 2 + 4))) return !1;
1359
+ let n = e.strokeWidth / 2 + 4;
1360
+ for (let r = 1; r < e.points.length; r++) {
1361
+ let i = e.points[r - 1], a = e.points[r];
1362
+ if (i && a && jt(t, i, a, n)) return !0;
1363
+ }
1364
+ if (e.points.length === 1) {
1365
+ let r = e.points[0];
1366
+ if (!r) return !1;
1367
+ let i = r.x - t.x, a = r.y - t.y;
1368
+ return i * i + a * a <= n * n;
1369
+ }
1370
+ return !1;
1371
+ }
1372
+ default: return F(e);
1373
+ }
1374
+ }
1375
+ function V(e, t) {
1376
+ return e.x >= t.x && e.y >= t.y && e.x <= t.x + t.width && e.y <= t.y + t.height;
1377
+ }
1378
+ function H(e, t) {
1379
+ return {
1380
+ x: e.x - t,
1381
+ y: e.y - t,
1382
+ width: e.width + t * 2,
1383
+ height: e.height + t * 2
1384
+ };
1385
+ }
1386
+ function U(e) {
1387
+ let { x: t, y: n, width: r, height: i } = e;
1388
+ return r < 0 && (t += r, r = -r), i < 0 && (n += i, i = -i), {
1389
+ x: t,
1390
+ y: n,
1391
+ width: r,
1392
+ height: i
1393
+ };
1394
+ }
1395
+ function jt(e, t, n, r) {
1396
+ let i = n.x - t.x, a = n.y - t.y, o = i * i + a * a;
1397
+ if (o === 0) {
1398
+ let n = e.x - t.x, i = e.y - t.y;
1399
+ return n * n + i * i <= r * r;
1400
+ }
1401
+ let s = ((e.x - t.x) * i + (e.y - t.y) * a) / o;
1402
+ s < 0 ? s = 0 : s > 1 && (s = 1);
1403
+ let c = t.x + s * i, l = t.y + s * a, u = e.x - c, d = e.y - l;
1404
+ return u * u + d * d <= r * r;
1405
+ }
1406
+ //#endregion
1407
+ //#region src/plugins/crop/aspect-ratio.ts
1408
+ function W(e, t) {
1409
+ if (t <= 0 || e.width <= 0 || e.height <= 0) return {
1410
+ x: e.x,
1411
+ y: e.y,
1412
+ width: 0,
1413
+ height: 0
1414
+ };
1415
+ let n = e.width / e.height, r, i;
1416
+ return t >= n ? (r = e.width, i = r / t) : (i = e.height, r = i * t), {
1417
+ x: e.x + (e.width - r) / 2,
1418
+ y: e.y + (e.height - i) / 2,
1419
+ width: r,
1420
+ height: i
1421
+ };
1422
+ }
1423
+ function Mt(e, t, n, r) {
1424
+ if (t <= 0) return e;
1425
+ if (e.width <= 0 || e.height <= 0) return W(r, t);
1426
+ let i = e.width / e.height, a, o;
1427
+ i > t ? (o = e.height, a = o * t) : (a = e.width, o = a / t);
1428
+ let s = v(Pt(e, a, o, n), r), c = s.height === 0 ? 0 : s.width / s.height;
1429
+ return Math.abs(c - t) <= Nt ? s : Ft(s, t, n);
1430
+ }
1431
+ var Nt = 1e-6;
1432
+ function Pt(e, t, n, r) {
1433
+ switch (r) {
1434
+ case "tl": return {
1435
+ x: e.x,
1436
+ y: e.y,
1437
+ width: t,
1438
+ height: n
1439
+ };
1440
+ case "tr": return {
1441
+ x: e.x + e.width - t,
1442
+ y: e.y,
1443
+ width: t,
1444
+ height: n
1445
+ };
1446
+ case "bl": return {
1447
+ x: e.x,
1448
+ y: e.y + e.height - n,
1449
+ width: t,
1450
+ height: n
1451
+ };
1452
+ case "br": return {
1453
+ x: e.x + e.width - t,
1454
+ y: e.y + e.height - n,
1455
+ width: t,
1456
+ height: n
1457
+ };
1458
+ case "center": return {
1459
+ x: e.x + (e.width - t) / 2,
1460
+ y: e.y + (e.height - n) / 2,
1461
+ width: t,
1462
+ height: n
1463
+ };
1464
+ }
1465
+ }
1466
+ function Ft(e, t, n) {
1467
+ let r = W(e, t);
1468
+ return Pt(e, r.width, r.height, n);
1469
+ }
1470
+ //#endregion
1471
+ //#region src/plugins/crop/bake.ts
1472
+ function It(t, n) {
1473
+ let r = y(n.rect), i = G(r.x, 0, t.width), a = G(r.y, 0, t.height), o = G(r.width, 1, t.width - i), s = G(r.height, 1, t.height - a), c = e(o, s);
1474
+ if (c.kind === "offscreen") {
1475
+ let e = c.canvas.getContext("2d");
1476
+ if (!e) throw Error("2D canvas context is not available");
1477
+ return e.drawImage(t.bitmap, i, a, o, s, 0, 0, o, s), {
1478
+ bitmap: c.canvas,
1479
+ width: o,
1480
+ height: s,
1481
+ mimeType: t.mimeType
1482
+ };
1483
+ }
1484
+ let l = c.canvas.getContext("2d");
1485
+ if (!l) throw Error("2D canvas context is not available");
1486
+ return l.drawImage(t.bitmap, i, a, o, s, 0, 0, o, s), {
1487
+ bitmap: c.canvas,
1488
+ width: o,
1489
+ height: s,
1490
+ mimeType: t.mimeType
1491
+ };
1492
+ }
1493
+ function G(e, t, n) {
1494
+ return Math.max(t, Math.min(n, e));
1495
+ }
1496
+ //#endregion
1497
+ //#region src/plugins/crop/preset-filter.ts
1498
+ function Lt(e, t) {
1499
+ let [n] = e;
1500
+ return n === void 0 || t === void 0 ? !0 : t === "landscape" ? n >= 1 : t === "portrait" ? n < 1 : !0;
1501
+ }
1502
+ function Rt(e, t) {
1503
+ return e.filter((e) => Lt(e, t));
1504
+ }
1505
+ //#endregion
1506
+ //#region src/plugins/crop/resize.ts
1507
+ function zt(e, t, n, r) {
1508
+ let i = r.minSize ?? 1, a = e.x, o = e.y, s = e.x + e.width, c = e.y + e.height, l = a, u = o, d = s, f = c;
1509
+ (t === "tl" || t === "l" || t === "bl") && (l = n.x), (t === "tr" || t === "r" || t === "br") && (d = n.x), (t === "tl" || t === "t" || t === "tr") && (u = n.y), (t === "bl" || t === "b" || t === "br") && (f = n.y), (t === "l" || t === "r") && (u = o, f = c), (t === "t" || t === "b") && (l = a, d = s);
1510
+ let p = Math.min(l, d), m = Math.min(u, f), h = Math.abs(d - l), g = Math.abs(f - u);
1511
+ h < i && (h = i, t === "tl" || t === "l" || t === "bl" ? p = s - i : (t === "tr" || t === "r" || t === "br") && (p = a)), g < i && (g = i, t === "tl" || t === "t" || t === "tr" ? m = c - i : (t === "bl" || t === "b" || t === "br") && (m = o));
1512
+ let _ = {
1513
+ x: p,
1514
+ y: m,
1515
+ width: h,
1516
+ height: g
1517
+ };
1518
+ return _ = v(_, r.bounds), r.aspectRatio !== void 0 && r.aspectRatio > 0 && (_ = Mt(_, r.aspectRatio, Bt(t), r.bounds)), _;
1519
+ }
1520
+ function Bt(e) {
1521
+ switch (e) {
1522
+ case "tl": return "br";
1523
+ case "tr": return "bl";
1524
+ case "bl": return "tr";
1525
+ case "br": return "tl";
1526
+ case "t": return "bl";
1527
+ case "b": return "tl";
1528
+ case "l": return "tr";
1529
+ case "r": return "tl";
1530
+ }
1531
+ }
1532
+ //#endregion
1533
+ //#region src/plugins/crop/state.ts
1534
+ function Vt(e) {
1535
+ return {
1536
+ rect: {
1537
+ x: 0,
1538
+ y: 0,
1539
+ width: e.imageSize.width,
1540
+ height: e.imageSize.height
1541
+ },
1542
+ aspectRatio: void 0,
1543
+ activePresetIndex: Ut(e.presets),
1544
+ presets: e.presets,
1545
+ imageSize: e.imageSize
1546
+ };
1547
+ }
1548
+ function Ht(e, t) {
1549
+ let n = e.presets[t];
1550
+ if (!n) return e;
1551
+ let [r] = n;
1552
+ if (r === void 0) return {
1553
+ ...e,
1554
+ aspectRatio: void 0,
1555
+ activePresetIndex: t
1556
+ };
1557
+ let i = W({
1558
+ x: 0,
1559
+ y: 0,
1560
+ width: e.imageSize.width,
1561
+ height: e.imageSize.height
1562
+ }, r);
1563
+ return {
1564
+ ...e,
1565
+ rect: i,
1566
+ aspectRatio: r,
1567
+ activePresetIndex: t
1568
+ };
1569
+ }
1570
+ function Ut(e) {
1571
+ return e.findIndex(([e]) => e === void 0);
1572
+ }
1573
+ //#endregion
1574
+ //#region src/plugins/finetune/state.ts
1575
+ var Wt = -100, Gt = 100, Kt = 1, K = {
1576
+ brightness: 0,
1577
+ contrast: 0,
1578
+ saturation: 0,
1579
+ exposure: 0,
1580
+ clarity: 0,
1581
+ gamma: 0
1582
+ }, qt = [
1583
+ {
1584
+ key: "brightness",
1585
+ label: "Brightness"
1586
+ },
1587
+ {
1588
+ key: "contrast",
1589
+ label: "Contrast"
1590
+ },
1591
+ {
1592
+ key: "saturation",
1593
+ label: "Saturation"
1594
+ },
1595
+ {
1596
+ key: "exposure",
1597
+ label: "Exposure"
1598
+ },
1599
+ {
1600
+ key: "clarity",
1601
+ label: "Clarity"
1602
+ },
1603
+ {
1604
+ key: "gamma",
1605
+ label: "Gamma"
1606
+ }
1230
1607
  ];
1231
- function ti(t) {
1232
- const n = t.x, e = t.x + t.width, i = t.y, r = t.y + t.height, o = t.x + t.width / 2, a = t.y + t.height / 2;
1233
- return {
1234
- tl: { x: n, y: i },
1235
- tr: { x: e, y: i },
1236
- bl: { x: n, y: r },
1237
- br: { x: e, y: r },
1238
- t: { x: o, y: i },
1239
- r: { x: e, y: a },
1240
- b: { x: o, y: r },
1241
- l: { x: n, y: a }
1242
- };
1243
- }
1244
- function ni(t, n, e) {
1245
- let i = t.x, r = t.y, o = t.x + t.width, a = t.y + t.height;
1246
- return (n === "tl" || n === "l" || n === "bl") && (i = e.x), (n === "tr" || n === "r" || n === "br") && (o = e.x), (n === "tl" || n === "t" || n === "tr") && (r = e.y), (n === "bl" || n === "b" || n === "br") && (a = e.y), { x: i, y: r, width: o - i, height: a - r };
1247
- }
1248
- function un(t, n) {
1249
- const e = t.length === 0 ? [""] : t.split(`
1250
- `);
1251
- let i = 0;
1252
- for (const a of e)
1253
- a.length > i && (i = a.length);
1254
- const r = Math.max(n * 0.6, i * n * 0.55), o = e.length * n * 1.2;
1255
- return { width: r, height: o };
1256
- }
1257
- function hn(t, n, e) {
1258
- switch (e) {
1259
- case "left":
1260
- return t;
1261
- case "center":
1262
- return t - n / 2;
1263
- case "right":
1264
- return t - n;
1265
- }
1266
- }
1267
- const x = 4;
1268
- function ei(t, n) {
1269
- for (let e = t.length - 1; e >= 0; e--) {
1270
- const i = t[e];
1271
- if (i && fn(i, n)) return i;
1272
- }
1273
- }
1274
- function fn(t, n) {
1275
- switch (t.kind) {
1276
- case "text":
1277
- return S(n, nt(t));
1278
- case "rect": {
1279
- const e = S(n, I(t));
1280
- if (t.fillColor !== null) return e;
1281
- const i = N(I(t), t.strokeWidth / 2 + x), r = N(I(t), -(t.strokeWidth / 2 + x));
1282
- return S(n, i) && !S(n, r);
1283
- }
1284
- case "ellipse": {
1285
- const e = I(t), i = e.width / 2, r = e.height / 2, o = e.x + i, a = e.y + r;
1286
- if (i <= 0 || r <= 0) return !1;
1287
- const c = (n.x - o) / i, l = (n.y - a) / r, s = c * c + l * l, u = (t.strokeWidth / 2 + x) / Math.min(i, r);
1288
- return t.fillColor !== null ? s <= (1 + u) ** 2 : s <= (1 + u) ** 2 && s >= (1 - u) ** 2;
1289
- }
1290
- case "arrow":
1291
- return et(
1292
- n,
1293
- { x: t.x1, y: t.y1 },
1294
- { x: t.x2, y: t.y2 },
1295
- t.strokeWidth / 2 + x
1296
- );
1297
- case "freehand":
1298
- case "highlight": {
1299
- const e = nt(t), i = N(e, t.strokeWidth / 2 + x);
1300
- if (!S(n, i)) return !1;
1301
- const r = t.strokeWidth / 2 + x;
1302
- for (let o = 1; o < t.points.length; o++) {
1303
- const a = t.points[o - 1], c = t.points[o];
1304
- if (a && c && et(n, a, c, r)) return !0;
1305
- }
1306
- if (t.points.length === 1) {
1307
- const o = t.points[0];
1308
- if (!o) return !1;
1309
- const a = o.x - n.x, c = o.y - n.y;
1310
- return a * a + c * c <= r * r;
1311
- }
1312
- return !1;
1313
- }
1314
- default:
1315
- return w(t);
1316
- }
1317
- }
1318
- function S(t, n) {
1319
- return t.x >= n.x && t.y >= n.y && t.x <= n.x + n.width && t.y <= n.y + n.height;
1320
- }
1321
- function N(t, n) {
1322
- return {
1323
- x: t.x - n,
1324
- y: t.y - n,
1325
- width: t.width + n * 2,
1326
- height: t.height + n * 2
1327
- };
1328
- }
1329
- function I(t) {
1330
- let { x: n, y: e, width: i, height: r } = t;
1331
- return i < 0 && (n += i, i = -i), r < 0 && (e += r, r = -r), { x: n, y: e, width: i, height: r };
1332
- }
1333
- function et(t, n, e, i) {
1334
- const r = e.x - n.x, o = e.y - n.y, a = r * r + o * o;
1335
- if (a === 0) {
1336
- const f = t.x - n.x, d = t.y - n.y;
1337
- return f * f + d * d <= i * i;
1338
- }
1339
- let c = ((t.x - n.x) * r + (t.y - n.y) * o) / a;
1340
- c < 0 ? c = 0 : c > 1 && (c = 1);
1341
- const l = n.x + c * r, s = n.y + c * o, u = t.x - l, h = t.y - s;
1342
- return u * u + h * h <= i * i;
1343
- }
1344
- const it = 2;
1345
- function ii(t) {
1346
- if (t.length <= 1) return [...t];
1347
- const n = t[0];
1348
- if (!n) return [];
1349
- const e = [n];
1350
- let i = n;
1351
- const r = it * it;
1352
- for (let a = 1; a < t.length - 1; a++) {
1353
- const c = t[a];
1354
- if (!c) continue;
1355
- const l = c.x - i.x, s = c.y - i.y;
1356
- l * l + s * s < r || (e.push(c), i = c);
1357
- }
1358
- const o = t[t.length - 1];
1359
- return o && o !== i && e.push(o), e;
1360
- }
1361
- function dt(t, n) {
1362
- if (n.length === 0) return;
1363
- const e = n[0];
1364
- if (!e) return;
1365
- if (n.length === 1) {
1366
- t.moveTo(e.x, e.y), t.lineTo(e.x, e.y);
1367
- return;
1368
- }
1369
- t.moveTo(e.x, e.y);
1370
- for (let r = 1; r < n.length - 1; r++) {
1371
- const o = n[r], a = n[r + 1];
1372
- if (!o || !a) continue;
1373
- const c = (o.x + a.x) / 2, l = (o.y + a.y) / 2;
1374
- t.quadraticCurveTo(o.x, o.y, c, l);
1375
- }
1376
- const i = n[n.length - 1];
1377
- i && t.lineTo(i.x, i.y);
1378
- }
1379
- const dn = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
1380
- async function ri(t, n) {
1381
- if (t.shapes.length === 0) return n;
1382
- const e = g(n.width, n.height), i = y(e);
1383
- i.imageSmoothingEnabled = !0, i.imageSmoothingQuality = "high", i.drawImage(n.bitmap, 0, 0, n.width, n.height);
1384
- for (const r of t.shapes)
1385
- gn(i, r);
1386
- return {
1387
- bitmap: e.canvas,
1388
- width: n.width,
1389
- height: n.height,
1390
- mimeType: n.mimeType
1391
- };
1392
- }
1393
- function gn(t, n) {
1394
- switch (n.kind) {
1395
- case "text":
1396
- mn(t, n);
1397
- return;
1398
- case "rect":
1399
- yn(t, n);
1400
- return;
1401
- case "ellipse":
1402
- wn(t, n);
1403
- return;
1404
- case "arrow":
1405
- xn(t, n);
1406
- return;
1407
- case "freehand":
1408
- pn(t, n);
1409
- return;
1410
- case "highlight":
1411
- Mn(t, n);
1412
- return;
1413
- default:
1414
- w(n);
1415
- }
1416
- }
1417
- function mn(t, n) {
1418
- t.save(), t.fillStyle = n.color, t.font = `${n.fontSize}px ${dn}`, t.textAlign = n.textAlign, t.textBaseline = "top";
1419
- const e = n.text.length === 0 ? [""] : n.text.split(`
1420
- `), i = n.fontSize * 1.2;
1421
- for (let r = 0; r < e.length; r++) {
1422
- const o = e[r];
1423
- o !== void 0 && t.fillText(o, n.x, n.y + r * i);
1424
- }
1425
- t.restore();
1426
- }
1427
- function yn(t, n) {
1428
- t.save(), n.fillColor !== null && (t.fillStyle = n.fillColor, t.fillRect(n.x, n.y, n.width, n.height)), n.strokeWidth > 0 && (t.strokeStyle = n.strokeColor, t.lineWidth = n.strokeWidth, t.lineJoin = "miter", t.strokeRect(n.x, n.y, n.width, n.height)), t.restore();
1429
- }
1430
- function wn(t, n) {
1431
- t.save();
1432
- const e = n.width / 2, i = n.height / 2, r = n.x + e, o = n.y + i;
1433
- t.beginPath(), t.ellipse(r, o, Math.max(0, e), Math.max(0, i), 0, 0, Math.PI * 2), n.fillColor !== null && (t.fillStyle = n.fillColor, t.fill()), n.strokeWidth > 0 && (t.strokeStyle = n.strokeColor, t.lineWidth = n.strokeWidth, t.stroke()), t.restore();
1434
- }
1435
- function xn(t, n) {
1436
- const e = n.x2 - n.x1, i = n.y2 - n.y1, r = Math.sqrt(e * e + i * i);
1437
- if (r < 0.5) return;
1438
- t.save(), t.strokeStyle = n.color, t.fillStyle = n.color, t.lineWidth = n.strokeWidth, t.lineCap = "round", t.lineJoin = "round";
1439
- const o = Math.min(Math.max(n.strokeWidth * 5, 28), r * 0.6), a = Math.max(n.strokeWidth * 4, 18), c = e / r, l = i / r, s = n.x2 - c * o * 0.6, u = n.y2 - l * o * 0.6;
1440
- t.beginPath(), t.moveTo(n.x1, n.y1), t.lineTo(s, u), t.stroke();
1441
- const h = n.x2 - c * o, f = n.y2 - l * o, d = -l, m = c;
1442
- t.beginPath(), t.moveTo(n.x2, n.y2), t.lineTo(h + d * a / 2, f + m * a / 2), t.lineTo(h - d * a / 2, f - m * a / 2), t.closePath(), t.fill(), t.restore();
1443
- }
1444
- function pn(t, n) {
1445
- n.points.length !== 0 && (t.save(), t.strokeStyle = n.color, t.lineWidth = n.strokeWidth, t.lineCap = "round", t.lineJoin = "round", t.beginPath(), dt(t, n.points), t.stroke(), t.restore());
1446
- }
1447
- function Mn(t, n) {
1448
- n.points.length !== 0 && (t.save(), t.globalCompositeOperation = "multiply", t.strokeStyle = n.color, t.lineWidth = n.strokeWidth, t.lineCap = "round", t.lineJoin = "round", t.beginPath(), dt(t, n.points), t.stroke(), t.restore());
1449
- }
1450
- const oi = ["pixelate", "blur", "solid"], Sn = "#000000", bn = "pixelate";
1451
- function ai(t) {
1452
- return {
1453
- regions: [],
1454
- nextRegionNumber: 1,
1455
- selectedId: null,
1456
- currentMode: bn,
1457
- currentColor: Sn,
1458
- imageSize: t.imageSize
1459
- };
1460
- }
1461
- function ci(t) {
1462
- return {
1463
- id: `r_${t.nextRegionNumber.toString(36)}`,
1464
- nextRegionNumber: t.nextRegionNumber + 1
1465
- };
1466
- }
1467
- function si(t, n) {
1468
- return {
1469
- ...t,
1470
- regions: [...t.regions, n],
1471
- selectedId: n.id
1472
- };
1473
- }
1474
- function gt(t, n) {
1475
- let e = !1;
1476
- const i = t.regions.map((r) => r.id !== n.id ? r : (e = !0, n));
1477
- return e ? { ...t, regions: i } : t;
1478
- }
1479
- function li(t, n) {
1480
- const e = t.regions.filter((i) => i.id !== n);
1481
- return e.length === t.regions.length ? t : {
1482
- ...t,
1483
- regions: e,
1484
- selectedId: t.selectedId === n ? null : t.selectedId
1485
- };
1486
- }
1487
- function ui(t, n, e) {
1488
- if (t.regions.length === 0) return t;
1489
- const i = t.regions.map((r) => n === "horizontal" ? { ...r, x: e.width - r.x - r.width } : { ...r, y: e.height - r.y - r.height });
1490
- return { ...t, regions: i, imageSize: e };
1491
- }
1492
- function hi(t, n, e, i) {
1493
- if (t.regions.length === 0) return { ...t, imageSize: i };
1494
- if (n === 0 && e === 0 && t.imageSize === i) return t;
1495
- const r = t.regions.map((o) => ({
1496
- ...o,
1497
- x: o.x + n,
1498
- y: o.y + e
1499
- }));
1500
- return { ...t, regions: r, imageSize: i };
1501
- }
1502
- function fi(t, n, e) {
1503
- if (n === 0) return { ...t, imageSize: e };
1504
- if (t.regions.length === 0) return { ...t, imageSize: e };
1505
- const i = t.imageSize.width, r = t.imageSize.height, o = t.regions.map((a) => {
1506
- const { x: c, y: l, width: s, height: u } = a;
1507
- return n === 1 ? { ...a, x: r - l - u, y: c, width: u, height: s } : n === 2 ? {
1508
- ...a,
1509
- x: i - c - s,
1510
- y: r - l - u
1511
- } : { ...a, x: l, y: i - c - s, width: u, height: s };
1512
- });
1513
- return { ...t, regions: o, imageSize: e };
1514
- }
1515
- function di(t, n) {
1516
- return t.selectedId === n ? t : { ...t, selectedId: n };
1517
- }
1518
- function gi(t, n) {
1519
- return t.currentMode === n ? t : { ...t, currentMode: n };
1520
- }
1521
- function mi(t, n) {
1522
- return t.currentColor === n ? t : { ...t, currentColor: n };
1523
- }
1524
- function yi(t, n, e) {
1525
- const i = t.regions.find((r) => r.id === n);
1526
- return !i || i.mode === e ? t : gt(t, { ...i, mode: e });
1527
- }
1528
- function wi(t, n, e) {
1529
- const i = t.regions.find((r) => r.id === n);
1530
- return !i || i.color === e ? t : gt(t, { ...i, color: e });
1531
- }
1532
- function xi(t, n) {
1533
- if (n !== null)
1534
- return t.regions.find((e) => e.id === n);
1535
- }
1536
- function pi(t) {
1537
- return t.selectedId === null ? null : t.regions.find((n) => n.id === t.selectedId) ?? null;
1538
- }
1539
- function Mi(t) {
1540
- let { x: n, y: e, width: i, height: r } = t;
1541
- return i < 0 && (n += i, i = -i), r < 0 && (e += r, r = -r), { x: n, y: e, width: i, height: r };
1542
- }
1543
- function Si(t) {
1544
- const { imageSize: n, mode: e, color: i, id: r } = t, o = Math.min(n.width, n.height), a = Math.max(80, Math.round(o * 0.25)), c = n.width / 2, l = n.height / 2, s = Math.round(c - a / 2), u = Math.round(l - a / 2);
1545
- return {
1546
- id: r,
1547
- x: s,
1548
- y: u,
1549
- width: a,
1550
- height: a,
1551
- mode: e,
1552
- color: i
1553
- };
1554
- }
1555
- function bi(t, n) {
1556
- if (t.imageSize.width === n.width && t.imageSize.height === n.height)
1557
- return t;
1558
- const e = [];
1559
- for (const r of t.regions)
1560
- r.x + r.width <= 0 || r.y + r.height <= 0 || r.x >= n.width || r.y >= n.height || e.push(En(r, n));
1561
- const i = t.selectedId !== null && !e.some((r) => r.id === t.selectedId);
1562
- return {
1563
- ...t,
1564
- regions: e,
1565
- imageSize: { width: n.width, height: n.height },
1566
- selectedId: i ? null : t.selectedId
1567
- };
1568
- }
1569
- function En(t, n) {
1570
- const e = Math.max(0, t.x), i = Math.max(0, t.y), r = Math.min(n.width, t.x + t.width), o = Math.min(n.height, t.y + t.height);
1571
- return {
1572
- ...t,
1573
- x: e,
1574
- y: i,
1575
- width: Math.max(0, r - e),
1576
- height: Math.max(0, o - i)
1577
- };
1578
- }
1579
- function Ei(t) {
1580
- return { x: t.x, y: t.y, width: t.width, height: t.height };
1581
- }
1582
- async function Ri(t, n) {
1583
- if (t.regions.length === 0) return n;
1584
- const e = g(n.width, n.height), i = y(e);
1585
- i.drawImage(n.bitmap, 0, 0, n.width, n.height);
1586
- for (const r of t.regions)
1587
- Rn(i, e.canvas, r, n);
1588
- return {
1589
- bitmap: e.canvas,
1590
- width: n.width,
1591
- height: n.height,
1592
- mimeType: n.mimeType
1593
- };
1594
- }
1595
- function Rn(t, n, e, i) {
1596
- const r = Math.round(e.width), o = Math.round(e.height);
1597
- if (r < 1 || o < 1) return;
1598
- const a = Math.round(e.x), c = Math.round(e.y);
1599
- switch (e.mode) {
1600
- case "solid":
1601
- In(t, e, a, c, r, o);
1602
- return;
1603
- case "pixelate":
1604
- Tn(t, n, i, a, c, r, o);
1605
- return;
1606
- case "blur":
1607
- kn(t, n, i, a, c, r, o);
1608
- return;
1609
- }
1610
- }
1611
- function In(t, n, e, i, r, o) {
1612
- t.save(), t.fillStyle = n.color, t.fillRect(e, i, r, o), t.restore();
1613
- }
1614
- function Tn(t, n, e, i, r, o, a) {
1615
- const c = Math.max(o, a), l = Math.max(4, Math.round(8 * Math.min(1, c / 240))), s = Math.max(1, Math.round(o / c * l)), u = Math.max(1, Math.round(a / c * l));
1616
- t.save();
1617
- const h = F(s, u);
1618
- if (!h) {
1619
- t.restore();
1620
- return;
1621
- }
1622
- h.ctx.imageSmoothingEnabled = !0, h.ctx.imageSmoothingQuality = "low", h.ctx.drawImage(n, i, r, o, a, 0, 0, s, u), t.imageSmoothingEnabled = !1, t.drawImage(h.canvas, 0, 0, s, u, i, r, o, a), t.restore();
1623
- }
1624
- function kn(t, n, e, i, r, o, a) {
1625
- const l = Math.max(1, Math.round(o * 0.125)), s = Math.max(1, Math.round(a * 0.125)), u = F(l, s);
1626
- if (!u) return;
1627
- u.ctx.imageSmoothingEnabled = !0, u.ctx.imageSmoothingQuality = "high", u.ctx.drawImage(n, i, r, o, a, 0, 0, l, s);
1628
- const h = Math.max(1, Math.round(l * 0.5)), f = Math.max(1, Math.round(s * 0.5)), d = F(h, f);
1629
- if (!d) {
1630
- t.save(), t.imageSmoothingEnabled = !0, t.imageSmoothingQuality = "high", t.drawImage(u.canvas, 0, 0, l, s, i, r, o, a), t.restore();
1631
- return;
1632
- }
1633
- d.ctx.imageSmoothingEnabled = !0, d.ctx.imageSmoothingQuality = "high", d.ctx.drawImage(u.canvas, 0, 0, l, s, 0, 0, h, f), t.save(), t.imageSmoothingEnabled = !0, t.imageSmoothingQuality = "high", t.drawImage(d.canvas, 0, 0, h, f, i, r, o, a), t.restore();
1634
- }
1635
- function F(t, n) {
1636
- if (typeof OffscreenCanvas < "u")
1637
- try {
1638
- const r = new OffscreenCanvas(t, n), o = r.getContext("2d");
1639
- if (o) return { canvas: r, ctx: o };
1640
- } catch {
1641
- }
1642
- if (typeof document > "u") return null;
1643
- const e = document.createElement("canvas");
1644
- e.width = t, e.height = n;
1645
- const i = e.getContext("2d");
1646
- return i ? { canvas: e, ctx: i } : null;
1647
- }
1648
- const Ii = [
1649
- "none",
1650
- "solidSharp",
1651
- "solidRound",
1652
- "lineSingle",
1653
- "hook",
1654
- "polaroid"
1655
- ], Cn = [
1656
- {
1657
- id: "none",
1658
- label: "None",
1659
- acceptsColor: !1,
1660
- defaultColor: "#000000"
1661
- },
1662
- {
1663
- id: "solidSharp",
1664
- label: "Mat Sharp",
1665
- acceptsColor: !0,
1666
- defaultColor: "#000000"
1667
- },
1668
- {
1669
- id: "solidRound",
1670
- label: "Mat Round",
1671
- acceptsColor: !0,
1672
- defaultColor: "#000000"
1673
- },
1674
- {
1675
- id: "lineSingle",
1676
- label: "Line Single",
1677
- acceptsColor: !0,
1678
- defaultColor: "#000000"
1679
- },
1680
- {
1681
- id: "hook",
1682
- label: "Corner Hooks",
1683
- acceptsColor: !0,
1684
- defaultColor: "#000000"
1685
- },
1686
- {
1687
- id: "polaroid",
1688
- label: "Polaroid",
1689
- acceptsColor: !0,
1690
- defaultColor: "#ffffff"
1691
- }
1692
- ], vn = {
1693
- presetId: "none",
1694
- color: "#000000"
1695
- };
1696
- function Ti() {
1697
- return vn;
1698
- }
1699
- function An(t) {
1700
- return t.presetId === "none";
1701
- }
1702
- function ki(t, n) {
1703
- if (t.presetId === n) return t;
1704
- const e = rt(t.presetId), i = rt(n);
1705
- if (!i) return { ...t, presetId: n };
1706
- const o = e !== void 0 && t.color === e.defaultColor ? i.defaultColor : t.color;
1707
- return { presetId: n, color: o };
1708
- }
1709
- function Ci(t, n) {
1710
- return t.color === n ? t : { ...t, color: n };
1711
- }
1712
- function rt(t) {
1713
- return Cn.find((n) => n.id === t);
1714
- }
1715
- async function vi(t, n) {
1716
- return An(t) ? n : t.presetId === "polaroid" ? zn(t.color, n) : t.presetId === "none" ? n : Nn(t.presetId, t.color, n);
1717
- }
1718
- function Nn(t, n, e) {
1719
- const i = g(e.width, e.height), r = y(i);
1720
- return r.drawImage(e.bitmap, 0, 0, e.width, e.height), Fn(r, t, n, e.width, e.height), {
1721
- bitmap: i.canvas,
1722
- width: e.width,
1723
- height: e.height,
1724
- mimeType: e.mimeType
1725
- };
1726
- }
1727
- function Fn(t, n, e, i, r) {
1728
- switch (n) {
1729
- case "solidSharp":
1730
- mt(t, e, i, r);
1731
- return;
1732
- case "solidRound":
1733
- Pn(t, e, i, r);
1734
- return;
1735
- case "lineSingle":
1736
- On(t, e, i, r);
1737
- return;
1738
- case "hook":
1739
- _n(t, e, i, r);
1740
- return;
1741
- }
1742
- }
1743
- function mt(t, n, e, i) {
1744
- const r = yt(e, i);
1745
- t.save(), t.fillStyle = n, t.fillRect(0, 0, e, r), t.fillRect(0, i - r, e, r), t.fillRect(0, r, r, i - 2 * r), t.fillRect(e - r, r, r, i - 2 * r), t.restore();
1746
- }
1747
- function Pn(t, n, e, i) {
1748
- const o = yt(e, i);
1749
- mt(t, n, e, i), t.save(), t.globalCompositeOperation = "destination-out", t.fillStyle = "#000", T(t, 0, 0, o, "tl"), T(t, e, 0, o, "tr"), T(t, 0, i, o, "bl"), T(t, e, i, o, "br"), t.restore();
1750
- }
1751
- function T(t, n, e, i, r) {
1752
- switch (t.beginPath(), t.moveTo(n, e), r) {
1753
- case "tl":
1754
- t.lineTo(n + i, e), t.arc(n + i, e + i, i, -Math.PI / 2, Math.PI, !0), t.lineTo(n, e);
1755
- break;
1756
- case "tr":
1757
- t.lineTo(n, e + i), t.arc(n - i, e + i, i, 0, -Math.PI / 2, !0), t.lineTo(n, e);
1758
- break;
1759
- case "bl":
1760
- t.lineTo(n + i, e), t.arc(n + i, e - i, i, Math.PI / 2, Math.PI, !1), t.lineTo(n, e);
1761
- break;
1762
- case "br":
1763
- t.lineTo(n - i, e), t.arc(n - i, e - i, i, Math.PI / 2, 0, !0), t.lineTo(n, e);
1764
- break;
1765
- }
1766
- t.closePath(), t.fill();
1767
- }
1768
- function On(t, n, e, i) {
1769
- const r = Math.round(Math.min(e, i) * 0.05), o = Math.max(2, Math.round(Math.min(e, i) * 0.01));
1770
- t.save(), t.strokeStyle = n, t.lineWidth = o;
1771
- const a = o / 2;
1772
- t.strokeRect(
1773
- r + a,
1774
- r + a,
1775
- e - 2 * r - o,
1776
- i - 2 * r - o
1777
- ), t.restore();
1778
- }
1779
- function _n(t, n, e, i) {
1780
- const r = Math.round(Math.min(e, i) * 0.08), o = Math.max(2, Math.round(Math.min(e, i) * 0.01)), a = Math.round(Math.min(e, i) * 0.05);
1781
- t.save(), t.strokeStyle = n, t.lineWidth = o, t.lineCap = "square";
1782
- const c = o / 2, l = (s, u, h, f) => {
1783
- t.beginPath(), t.moveTo(s + h * r, u), t.lineTo(s, u), t.lineTo(s, u + f * r), t.stroke();
1784
- };
1785
- l(a + c, a + c, 1, 1), l(e - a - c, a + c, -1, 1), l(a + c, i - a - c, 1, -1), l(e - a - c, i - a - c, -1, -1), t.restore();
1786
- }
1787
- function zn(t, n) {
1788
- const e = Math.min(n.width, n.height), i = Math.round(e * 0.05), r = i, o = i, a = Math.round(e * 0.18), c = n.width + r + o, l = n.height + i + a, s = g(c, l), u = y(s);
1789
- return u.fillStyle = t, u.fillRect(0, 0, c, l), u.drawImage(n.bitmap, r, i, n.width, n.height), {
1790
- bitmap: s.canvas,
1791
- width: c,
1792
- height: l,
1793
- mimeType: n.mimeType
1794
- };
1795
- }
1796
- function yt(t, n) {
1797
- return Math.max(4, Math.round(Math.min(t, n) * 0.04));
1798
- }
1799
- function Ai(t, n, e) {
1800
- if (t !== "polaroid")
1801
- return { width: n, height: e };
1802
- const i = Math.min(n, e), r = Math.round(i * 0.05), o = Math.round(i * 0.18);
1803
- return {
1804
- width: n + 2 * r,
1805
- height: e + r + o
1806
- };
1807
- }
1808
- export {
1809
- Ze as ALL_SELECTION_HANDLES,
1810
- _ as DEFAULT_FINETUNE_STATE,
1811
- vn as DEFAULT_FRAME_STATE,
1812
- ut as DEFAULT_OUTPUT_STATE,
1813
- cn as DEFAULT_PALETTE_COLOR,
1814
- Sn as DEFAULT_REDACT_COLOR,
1815
- bn as DEFAULT_REDACT_MODE,
1816
- sn as DEFAULT_STROKE_WIDTH,
1817
- re as ENCODABLE_MIMES,
1818
- Dn as EventBus,
1819
- rn as FILTER_PRESETS,
1820
- Te as FINETUNE_ADJUSTMENTS,
1821
- J as FINETUNE_MAX,
1822
- G as FINETUNE_MIN,
1823
- Z as FINETUNE_STEP,
1824
- Cn as FRAME_PRESETS,
1825
- Ii as FRAME_PRESET_IDS,
1826
- _e as FREEHAND_DEFAULT_STROKE,
1827
- Yt as FREE_ANGLE_MAX,
1828
- Wt as FREE_ANGLE_MIN,
1829
- de as FREE_ANGLE_STEP,
1830
- Pe as HIGHLIGHT_DEFAULT_COLOR,
1831
- Oe as HIGHLIGHT_DEFAULT_STROKE,
1832
- W as HISTORY_MAX_ENTRIES,
1833
- Jn as History,
1834
- k as IDENTITY_VIEWPORT_TRANSFORM,
1835
- Ve as KEYBOARD_PLACEABLE_KINDS,
1836
- ot as MAX_ZOOM,
1837
- it as MIN_SAMPLE_DISTANCE,
1838
- at as MIN_ZOOM,
1839
- x as PICK_TOLERANCE,
1840
- oi as REDACT_MODES,
1841
- ft as RESIZE_MAX_DIMENSION,
1842
- K as RESIZE_MIN_DIMENSION,
1843
- dn as SYSTEM_FONT_STACK,
1844
- an as TEXT_DEFAULT_FONT_SIZE,
1845
- Un as ViewportController,
1846
- si as addRegion,
1847
- Ye as addShape,
1848
- hn as alignToOrigin,
1849
- Et as applyAspectRatio,
1850
- nn as applyClarity,
1851
- tn as applyFinetuneLutAndSaturation,
1852
- tt as applyFinetuneToImageData,
1853
- ee as applyPresetByIndex,
1854
- w as assertNever,
1855
- ri as bakeAnnotate,
1856
- st as bakeCanvasToBlob,
1857
- ie as bakeCrop,
1858
- Ne as bakeFinetune,
1859
- fe as bakeFlip,
1860
- vi as bakeFrame,
1861
- Ri as bakeRedact,
1862
- Ie as bakeResize,
1863
- xe as bakeRotate,
1864
- nt as boundingBoxOf,
1865
- en as boxBlur3x3,
1866
- Jt as buildFinetuneLut,
1867
- b as canEncodeMime,
1868
- ht as clampQuality,
1869
- P as clampRectInside,
1870
- pt as computeViewport,
1871
- vt as copyJpegExif,
1872
- g as createBakeCanvas,
1873
- Si as createCenteredRedactRegion,
1874
- Je as createCenteredShape,
1875
- Gn as createStore,
1876
- ii as decimatePoints,
1877
- ln as defaultStylePalette,
1878
- li as deleteRedactRegion,
1879
- Ue as deleteShape,
1880
- Ot as deriveOutputName,
1881
- Ut as effectiveAngleDeg,
1882
- Re as effectivePercent,
1883
- se as encodeSourceImage,
1884
- un as estimateTextSize,
1885
- te as filterPresets,
1886
- Fe as findActivePreset,
1887
- rt as findFramePreset,
1888
- xi as findRedactRegion,
1889
- He as findShape,
1890
- on as finetuneStatesEqual,
1891
- O as fitRectToBoundsWithRatio,
1892
- Ai as frameOutputSize,
1893
- y as getBakeContext2D,
1894
- fn as hitTest,
1895
- ze as initialAnnotateState,
1896
- ne as initialCropState,
1897
- ke as initialFinetuneState,
1898
- ue as initialFlipState,
1899
- Ti as initialFrameState,
1900
- ai as initialRedactState,
1901
- pe as initialResizeState,
1902
- ge as initialRotateState,
1903
- Vt as isFinetuneNoOp,
1904
- Bt as isFlipNoOp,
1905
- An as isFrameNoOp,
1906
- Ge as isKeyboardPlaceableKind,
1907
- kt as isPresetVisible,
1908
- jt as isResizeNoOp,
1909
- Xt as isRotateNoOp,
1910
- qt as largestInscribedRect,
1911
- Ln as loadImage,
1912
- ci as mintRegionId,
1913
- De as mintShapeId,
1914
- ui as mirrorRedactRegions,
1915
- $e as mirrorShape,
1916
- qe as normaliseRectExtent,
1917
- Mi as normaliseRedactExtent,
1918
- Fn as paintInsideFrame,
1919
- Rn as paintRedactRegion,
1920
- gn as paintShape,
1921
- ei as pickShape,
1922
- Wn as pointDisplayToImage,
1923
- Bn as pointImageToDisplay,
1924
- Qn as pointInRect,
1925
- jn as rectBottom,
1926
- $n as rectCenter,
1927
- Xn as rectDisplayToImage,
1928
- ni as rectFromHandleDrag,
1929
- Hn as rectFromPoints,
1930
- Yn as rectImageToDisplay,
1931
- qn as rectRight,
1932
- Kn as rectsEqual,
1933
- Ei as regionBoundingBox,
1934
- gt as replaceRedactRegion,
1935
- Xe as replaceShape,
1936
- Ae as resetAllFinetune,
1937
- ve as resetFinetune,
1938
- Zn as resizeRectFromHandle,
1939
- Pt as resolveOutputMime,
1940
- $t as resolveOutputSize,
1941
- bi as revalidateRedactAgainstBounds,
1942
- me as rotateClockwise,
1943
- ye as rotateCounterClockwise,
1944
- fi as rotateRedactRegions,
1945
- Qe as rotateShape,
1946
- St as roundRect,
1947
- le as runUtilityChain,
1948
- di as selectRedactRegion,
1949
- We as selectShape,
1950
- pi as selectedRedactRegionOf,
1951
- ti as selectionHandlePositions,
1952
- Le as setActiveTool,
1953
- Ce as setFinetune,
1954
- Ci as setFrameColor,
1955
- ki as setFramePreset,
1956
- we as setFreeAngle,
1957
- Se as setHeightPx,
1958
- Ee as setLockAspect,
1959
- oe as setOutputMime,
1960
- ae as setOutputQuality,
1961
- be as setPercent,
1962
- mi as setRedactCurrentColor,
1963
- gi as setRedactCurrentMode,
1964
- wi as setRedactRegionColor,
1965
- yi as setRedactRegionMode,
1966
- ce as setStripMetadata,
1967
- Be as setStyle,
1968
- Me as setWidthPx,
1969
- he as toggleFlip,
1970
- dt as tracePath,
1971
- Ke as transformShapes,
1972
- Vn as translateClampedRect,
1973
- hi as translateRedactRegions,
1974
- je as translateShape
1608
+ function Jt() {
1609
+ return K;
1610
+ }
1611
+ function Yt(e) {
1612
+ return e.brightness === 0 && e.contrast === 0 && e.saturation === 0 && e.exposure === 0 && e.clarity === 0 && e.gamma === 0;
1613
+ }
1614
+ function Xt(e, t, n) {
1615
+ let r = $t(n);
1616
+ return e[t] === r ? e : {
1617
+ ...e,
1618
+ [t]: r
1619
+ };
1620
+ }
1621
+ function Zt(e, t) {
1622
+ return e[t] === 0 ? e : {
1623
+ ...e,
1624
+ [t]: 0
1625
+ };
1626
+ }
1627
+ function Qt() {
1628
+ return K;
1629
+ }
1630
+ function $t(e) {
1631
+ return Number.isNaN(e) ? 0 : e <= -100 ? Wt : e >= 100 ? 100 : Math.round(e / 1) * 1;
1632
+ }
1633
+ //#endregion
1634
+ //#region src/plugins/filter/presets.ts
1635
+ var en = [
1636
+ {
1637
+ id: "none",
1638
+ label: "None",
1639
+ state: K
1640
+ },
1641
+ {
1642
+ id: "vivid",
1643
+ label: "Vivid",
1644
+ state: {
1645
+ brightness: 0,
1646
+ contrast: 10,
1647
+ saturation: 40,
1648
+ exposure: 0,
1649
+ clarity: 5,
1650
+ gamma: 0
1651
+ }
1652
+ },
1653
+ {
1654
+ id: "mono",
1655
+ label: "Mono",
1656
+ state: {
1657
+ brightness: 0,
1658
+ contrast: 15,
1659
+ saturation: -100,
1660
+ exposure: 0,
1661
+ clarity: 0,
1662
+ gamma: 0
1663
+ }
1664
+ },
1665
+ {
1666
+ id: "soft",
1667
+ label: "Soft",
1668
+ state: {
1669
+ brightness: 5,
1670
+ contrast: -10,
1671
+ saturation: 0,
1672
+ exposure: 0,
1673
+ clarity: -25,
1674
+ gamma: 0
1675
+ }
1676
+ },
1677
+ {
1678
+ id: "punch",
1679
+ label: "Punch",
1680
+ state: {
1681
+ brightness: 0,
1682
+ contrast: 30,
1683
+ saturation: 5,
1684
+ exposure: 0,
1685
+ clarity: 25,
1686
+ gamma: 0
1687
+ }
1688
+ },
1689
+ {
1690
+ id: "mute",
1691
+ label: "Mute",
1692
+ state: {
1693
+ brightness: 0,
1694
+ contrast: 5,
1695
+ saturation: -50,
1696
+ exposure: 0,
1697
+ clarity: -5,
1698
+ gamma: 0
1699
+ }
1700
+ },
1701
+ {
1702
+ id: "bright",
1703
+ label: "Bright",
1704
+ state: {
1705
+ brightness: 5,
1706
+ contrast: 5,
1707
+ saturation: 0,
1708
+ exposure: 15,
1709
+ clarity: 0,
1710
+ gamma: 0
1711
+ }
1712
+ }
1713
+ ];
1714
+ function tn(e, t) {
1715
+ return e.brightness === t.brightness && e.contrast === t.contrast && e.saturation === t.saturation && e.exposure === t.exposure && e.clarity === t.clarity && e.gamma === t.gamma;
1716
+ }
1717
+ function nn(e) {
1718
+ for (let t of en) if (tn(t.state, e)) return t;
1719
+ }
1720
+ //#endregion
1721
+ //#region src/plugins/finetune/math.ts
1722
+ function rn(e) {
1723
+ let t = new Uint8ClampedArray(256), n = e.brightness / 200, r = 1 + e.contrast / 100, i = 1 + e.exposure / 200, a = an(e.gamma);
1724
+ for (let e = 0; e < 256; e++) {
1725
+ let o = e / 255;
1726
+ o *= i, o = (o - .5) * r + .5, o += n, o < 0 ? o = 0 : o > 1 && (o = 1), o **= a, o < 0 ? o = 0 : o > 1 && (o = 1), t[e] = Math.round(o * 255);
1727
+ }
1728
+ return t;
1729
+ }
1730
+ function an(e) {
1731
+ return e === 0 ? 1 : e > 0 ? 1 - e / 100 * .5 : 1 + 1 * (-e / 100);
1732
+ }
1733
+ function on(e, t, n, r) {
1734
+ let i = e.length;
1735
+ if (t.length !== i) throw Error("applyFinetuneLutAndSaturation: src/dst length mismatch");
1736
+ let a = 1 + r.saturation / 100;
1737
+ if (a === 1) {
1738
+ for (let r = 0; r < i; r += 4) t[r] = n[e[r]], t[r + 1] = n[e[r + 1]], t[r + 2] = n[e[r + 2]], t[r + 3] = e[r + 3];
1739
+ return;
1740
+ }
1741
+ for (let r = 0; r < i; r += 4) {
1742
+ let i = n[e[r]], o = n[e[r + 1]], s = n[e[r + 2]], c = .2126 * i + .7152 * o + .0722 * s, l = c + (i - c) * a, u = c + (o - c) * a, d = c + (s - c) * a;
1743
+ l < 0 ? l = 0 : l > 255 && (l = 255), u < 0 ? u = 0 : u > 255 && (u = 255), d < 0 ? d = 0 : d > 255 && (d = 255), t[r] = l, t[r + 1] = u, t[r + 2] = d, t[r + 3] = e[r + 3];
1744
+ }
1745
+ }
1746
+ function sn(e, t, n) {
1747
+ if (n === 0) return;
1748
+ let r = e.length;
1749
+ if (t.length !== r) throw Error("applyClarity: dst/blurred length mismatch");
1750
+ let i = n / 100;
1751
+ for (let n = 0; n < r; n += 4) {
1752
+ let r = e[n], a = e[n + 1], o = e[n + 2], s = r + i * (r - t[n]), c = a + i * (a - t[n + 1]), l = o + i * (o - t[n + 2]);
1753
+ s < 0 ? s = 0 : s > 255 && (s = 255), c < 0 ? c = 0 : c > 255 && (c = 255), l < 0 ? l = 0 : l > 255 && (l = 255), e[n] = s, e[n + 1] = c, e[n + 2] = l;
1754
+ }
1755
+ }
1756
+ function cn(e, t, n, r, i) {
1757
+ if (e.length !== t.length || e.length !== n.length) throw Error("boxBlur3x3: buffer length mismatch");
1758
+ for (let n = 0; n < i; n++) for (let i = 0; i < r; i++) {
1759
+ let a = i === 0 ? 0 : i - 1, o = i === r - 1 ? r - 1 : i + 1, s = (n * r + i) * 4, c = (n * r + a) * 4, l = (n * r + o) * 4;
1760
+ t[s] = (e[c] + e[s] + e[l]) / 3, t[s + 1] = (e[c + 1] + e[s + 1] + e[l + 1]) / 3, t[s + 2] = (e[c + 2] + e[s + 2] + e[l + 2]) / 3, t[s + 3] = e[s + 3];
1761
+ }
1762
+ for (let e = 0; e < i; e++) {
1763
+ let a = e === 0 ? 0 : e - 1, o = e === i - 1 ? i - 1 : e + 1;
1764
+ for (let i = 0; i < r; i++) {
1765
+ let s = (e * r + i) * 4, c = (a * r + i) * 4, l = (o * r + i) * 4;
1766
+ n[s] = (t[c] + t[s] + t[l]) / 3, n[s + 1] = (t[c + 1] + t[s + 1] + t[l + 1]) / 3, n[s + 2] = (t[c + 2] + t[s + 2] + t[l + 2]) / 3, n[s + 3] = t[s + 3];
1767
+ }
1768
+ }
1769
+ }
1770
+ function q(e, t, n) {
1771
+ if (t.width !== n.width || t.height !== n.height || t.data.length !== n.data.length) throw Error("applyFinetuneToImageData: baseline/dst dimensions mismatch");
1772
+ let r = rn(e);
1773
+ if (on(t.data, n.data, r, e), e.clarity !== 0) {
1774
+ let r = new Uint8ClampedArray(t.data.length), i = new Uint8ClampedArray(t.data.length);
1775
+ cn(t.data, r, i, t.width, t.height), sn(n.data, i, e.clarity);
1776
+ }
1777
+ }
1778
+ //#endregion
1779
+ //#region src/plugins/finetune/bake.ts
1780
+ async function ln(n, r) {
1781
+ if (Yt(n)) return r;
1782
+ let i = e(r.width, r.height), a = t(i);
1783
+ a.imageSmoothingEnabled = !0, a.imageSmoothingQuality = "high", a.drawImage(r.bitmap, 0, 0, r.width, r.height);
1784
+ let o = a.getImageData(0, 0, r.width, r.height);
1785
+ if (n.clarity === 0) q(n, o, o), a.putImageData(o, 0, 0);
1786
+ else {
1787
+ let e = new ImageData(new Uint8ClampedArray(o.data.length), o.width, o.height);
1788
+ q(n, o, e), a.putImageData(e, 0, 0);
1789
+ }
1790
+ return {
1791
+ bitmap: i.canvas,
1792
+ width: r.width,
1793
+ height: r.height,
1794
+ mimeType: r.mimeType
1795
+ };
1796
+ }
1797
+ //#endregion
1798
+ //#region src/plugins/flip/state.ts
1799
+ function un() {
1800
+ return {
1801
+ horizontal: !1,
1802
+ vertical: !1
1803
+ };
1804
+ }
1805
+ function dn(e, t) {
1806
+ return t === "horizontal" ? {
1807
+ ...e,
1808
+ horizontal: !e.horizontal
1809
+ } : {
1810
+ ...e,
1811
+ vertical: !e.vertical
1812
+ };
1813
+ }
1814
+ function fn(e) {
1815
+ return !e.horizontal && !e.vertical;
1816
+ }
1817
+ //#endregion
1818
+ //#region src/plugins/flip/bake.ts
1819
+ async function pn(n, r) {
1820
+ if (fn(n)) return r;
1821
+ let { width: i, height: a } = r, o = e(i, a), s = t(o), c = n.horizontal ? -1 : 1, l = n.vertical ? -1 : 1, u = n.horizontal ? i : 0, d = n.vertical ? a : 0;
1822
+ return s.setTransform(c, 0, 0, l, u, d), s.drawImage(r.bitmap, 0, 0), {
1823
+ bitmap: o.canvas,
1824
+ width: i,
1825
+ height: a,
1826
+ mimeType: r.mimeType
1827
+ };
1828
+ }
1829
+ //#endregion
1830
+ //#region src/plugins/frame/state.ts
1831
+ var mn = [
1832
+ "none",
1833
+ "solidSharp",
1834
+ "solidRound",
1835
+ "lineSingle",
1836
+ "hook",
1837
+ "polaroid"
1838
+ ], hn = [
1839
+ {
1840
+ id: "none",
1841
+ label: "None",
1842
+ acceptsColor: !1,
1843
+ defaultColor: "#000000"
1844
+ },
1845
+ {
1846
+ id: "solidSharp",
1847
+ label: "Mat Sharp",
1848
+ acceptsColor: !0,
1849
+ defaultColor: "#000000"
1850
+ },
1851
+ {
1852
+ id: "solidRound",
1853
+ label: "Mat Round",
1854
+ acceptsColor: !0,
1855
+ defaultColor: "#000000"
1856
+ },
1857
+ {
1858
+ id: "lineSingle",
1859
+ label: "Line Single",
1860
+ acceptsColor: !0,
1861
+ defaultColor: "#000000"
1862
+ },
1863
+ {
1864
+ id: "hook",
1865
+ label: "Corner Hooks",
1866
+ acceptsColor: !0,
1867
+ defaultColor: "#000000"
1868
+ },
1869
+ {
1870
+ id: "polaroid",
1871
+ label: "Polaroid",
1872
+ acceptsColor: !0,
1873
+ defaultColor: "#ffffff"
1874
+ }
1875
+ ], gn = {
1876
+ presetId: "none",
1877
+ color: "#000000"
1975
1878
  };
1976
- //# sourceMappingURL=index.js.map
1879
+ function _n() {
1880
+ return gn;
1881
+ }
1882
+ function vn(e) {
1883
+ return e.presetId === "none";
1884
+ }
1885
+ function yn(e, t) {
1886
+ if (e.presetId === t) return e;
1887
+ let n = J(e.presetId), r = J(t);
1888
+ return r ? {
1889
+ presetId: t,
1890
+ color: n !== void 0 && e.color === n.defaultColor ? r.defaultColor : e.color
1891
+ } : {
1892
+ ...e,
1893
+ presetId: t
1894
+ };
1895
+ }
1896
+ function bn(e, t) {
1897
+ return e.color === t ? e : {
1898
+ ...e,
1899
+ color: t
1900
+ };
1901
+ }
1902
+ function J(e) {
1903
+ return hn.find((t) => t.id === e);
1904
+ }
1905
+ //#endregion
1906
+ //#region src/plugins/frame/bake.ts
1907
+ async function xn(e, t) {
1908
+ return vn(e) ? t : e.presetId === "polaroid" ? On(e.color, t) : e.presetId === "none" ? t : Sn(e.presetId, e.color, t);
1909
+ }
1910
+ function Sn(n, r, i) {
1911
+ let a = e(i.width, i.height), o = t(a);
1912
+ return o.drawImage(i.bitmap, 0, 0, i.width, i.height), Cn(o, n, r, i.width, i.height), {
1913
+ bitmap: a.canvas,
1914
+ width: i.width,
1915
+ height: i.height,
1916
+ mimeType: i.mimeType
1917
+ };
1918
+ }
1919
+ function Cn(e, t, n, r, i) {
1920
+ switch (t) {
1921
+ case "solidSharp":
1922
+ wn(e, n, r, i);
1923
+ return;
1924
+ case "solidRound":
1925
+ Tn(e, n, r, i);
1926
+ return;
1927
+ case "lineSingle":
1928
+ En(e, n, r, i);
1929
+ return;
1930
+ case "hook":
1931
+ Dn(e, n, r, i);
1932
+ return;
1933
+ }
1934
+ }
1935
+ function wn(e, t, n, r) {
1936
+ let i = kn(n, r);
1937
+ e.save(), e.fillStyle = t, e.fillRect(0, 0, n, i), e.fillRect(0, r - i, n, i), e.fillRect(0, i, i, r - 2 * i), e.fillRect(n - i, i, i, r - 2 * i), e.restore();
1938
+ }
1939
+ function Tn(e, t, n, r) {
1940
+ let i = kn(n, r);
1941
+ wn(e, t, n, r), e.save(), e.globalCompositeOperation = "destination-out", e.fillStyle = "#000", Y(e, 0, 0, i, "tl"), Y(e, n, 0, i, "tr"), Y(e, 0, r, i, "bl"), Y(e, n, r, i, "br"), e.restore();
1942
+ }
1943
+ function Y(e, t, n, r, i) {
1944
+ switch (e.beginPath(), e.moveTo(t, n), i) {
1945
+ case "tl":
1946
+ e.lineTo(t + r, n), e.arc(t + r, n + r, r, -Math.PI / 2, Math.PI, !0), e.lineTo(t, n);
1947
+ break;
1948
+ case "tr":
1949
+ e.lineTo(t, n + r), e.arc(t - r, n + r, r, 0, -Math.PI / 2, !0), e.lineTo(t, n);
1950
+ break;
1951
+ case "bl":
1952
+ e.lineTo(t + r, n), e.arc(t + r, n - r, r, Math.PI / 2, Math.PI, !1), e.lineTo(t, n);
1953
+ break;
1954
+ case "br":
1955
+ e.lineTo(t - r, n), e.arc(t - r, n - r, r, Math.PI / 2, 0, !0), e.lineTo(t, n);
1956
+ break;
1957
+ }
1958
+ e.closePath(), e.fill();
1959
+ }
1960
+ function En(e, t, n, r) {
1961
+ let i = Math.round(Math.min(n, r) * .05), a = Math.max(2, Math.round(Math.min(n, r) * .01));
1962
+ e.save(), e.strokeStyle = t, e.lineWidth = a;
1963
+ let o = a / 2;
1964
+ e.strokeRect(i + o, i + o, n - 2 * i - a, r - 2 * i - a), e.restore();
1965
+ }
1966
+ function Dn(e, t, n, r) {
1967
+ let i = Math.round(Math.min(n, r) * .08), a = Math.max(2, Math.round(Math.min(n, r) * .01)), o = Math.round(Math.min(n, r) * .05);
1968
+ e.save(), e.strokeStyle = t, e.lineWidth = a, e.lineCap = "square";
1969
+ let s = a / 2, c = (t, n, r, a) => {
1970
+ e.beginPath(), e.moveTo(t + r * i, n), e.lineTo(t, n), e.lineTo(t, n + a * i), e.stroke();
1971
+ };
1972
+ c(o + s, o + s, 1, 1), c(n - o - s, o + s, -1, 1), c(o + s, r - o - s, 1, -1), c(n - o - s, r - o - s, -1, -1), e.restore();
1973
+ }
1974
+ function On(n, r) {
1975
+ let i = Math.min(r.width, r.height), a = Math.round(i * .05), o = a, s = a, c = Math.round(i * .18), l = r.width + o + s, u = r.height + a + c, d = e(l, u), f = t(d);
1976
+ return f.fillStyle = n, f.fillRect(0, 0, l, u), f.drawImage(r.bitmap, o, a, r.width, r.height), {
1977
+ bitmap: d.canvas,
1978
+ width: l,
1979
+ height: u,
1980
+ mimeType: r.mimeType
1981
+ };
1982
+ }
1983
+ function kn(e, t) {
1984
+ return Math.max(4, Math.round(Math.min(e, t) * .04));
1985
+ }
1986
+ function An(e, t, n) {
1987
+ if (e !== "polaroid") return {
1988
+ width: t,
1989
+ height: n
1990
+ };
1991
+ let r = Math.min(t, n), i = Math.round(r * .05), a = Math.round(r * .18);
1992
+ return {
1993
+ width: t + 2 * i,
1994
+ height: n + i + a
1995
+ };
1996
+ }
1997
+ //#endregion
1998
+ //#region src/plugins/redact/bake.ts
1999
+ async function jn(n, r) {
2000
+ if (n.regions.length === 0) return r;
2001
+ let i = e(r.width, r.height), a = t(i);
2002
+ a.drawImage(r.bitmap, 0, 0, r.width, r.height);
2003
+ for (let e of n.regions) Mn(a, i.canvas, e, r);
2004
+ return {
2005
+ bitmap: i.canvas,
2006
+ width: r.width,
2007
+ height: r.height,
2008
+ mimeType: r.mimeType
2009
+ };
2010
+ }
2011
+ function Mn(e, t, n, r) {
2012
+ let i = Math.round(n.width), a = Math.round(n.height);
2013
+ if (i < 1 || a < 1) return;
2014
+ let o = Math.round(n.x), s = Math.round(n.y);
2015
+ switch (n.mode) {
2016
+ case "solid":
2017
+ Nn(e, n, o, s, i, a);
2018
+ return;
2019
+ case "pixelate":
2020
+ Pn(e, t, r, o, s, i, a);
2021
+ return;
2022
+ case "blur":
2023
+ Fn(e, t, r, o, s, i, a);
2024
+ return;
2025
+ }
2026
+ }
2027
+ function Nn(e, t, n, r, i, a) {
2028
+ e.save(), e.fillStyle = t.color, e.fillRect(n, r, i, a), e.restore();
2029
+ }
2030
+ function Pn(e, t, n, r, i, a, o) {
2031
+ let s = Math.max(a, o), c = Math.max(4, Math.round(8 * Math.min(1, s / 240))), l = Math.max(1, Math.round(a / s * c)), u = Math.max(1, Math.round(o / s * c));
2032
+ e.save();
2033
+ let d = X(l, u);
2034
+ if (!d) {
2035
+ e.restore();
2036
+ return;
2037
+ }
2038
+ d.ctx.imageSmoothingEnabled = !0, d.ctx.imageSmoothingQuality = "low", d.ctx.drawImage(t, r, i, a, o, 0, 0, l, u), e.imageSmoothingEnabled = !1, e.drawImage(d.canvas, 0, 0, l, u, r, i, a, o), e.restore();
2039
+ }
2040
+ function Fn(e, t, n, r, i, a, o) {
2041
+ let s = 1 / 8, c = Math.max(1, Math.round(a * s)), l = Math.max(1, Math.round(o * s)), u = X(c, l);
2042
+ if (!u) return;
2043
+ u.ctx.imageSmoothingEnabled = !0, u.ctx.imageSmoothingQuality = "high", u.ctx.drawImage(t, r, i, a, o, 0, 0, c, l);
2044
+ let d = Math.max(1, Math.round(c * .5)), f = Math.max(1, Math.round(l * .5)), p = X(d, f);
2045
+ if (!p) {
2046
+ e.save(), e.imageSmoothingEnabled = !0, e.imageSmoothingQuality = "high", e.drawImage(u.canvas, 0, 0, c, l, r, i, a, o), e.restore();
2047
+ return;
2048
+ }
2049
+ p.ctx.imageSmoothingEnabled = !0, p.ctx.imageSmoothingQuality = "high", p.ctx.drawImage(u.canvas, 0, 0, c, l, 0, 0, d, f), e.save(), e.imageSmoothingEnabled = !0, e.imageSmoothingQuality = "high", e.drawImage(p.canvas, 0, 0, d, f, r, i, a, o), e.restore();
2050
+ }
2051
+ function X(e, t) {
2052
+ if (typeof OffscreenCanvas < "u") try {
2053
+ let n = new OffscreenCanvas(e, t), r = n.getContext("2d");
2054
+ if (r) return {
2055
+ canvas: n,
2056
+ ctx: r
2057
+ };
2058
+ } catch {}
2059
+ if (typeof document > "u") return null;
2060
+ let n = document.createElement("canvas");
2061
+ n.width = e, n.height = t;
2062
+ let r = n.getContext("2d");
2063
+ return r ? {
2064
+ canvas: n,
2065
+ ctx: r
2066
+ } : null;
2067
+ }
2068
+ //#endregion
2069
+ //#region src/plugins/redact/state.ts
2070
+ var In = [
2071
+ "pixelate",
2072
+ "blur",
2073
+ "solid"
2074
+ ], Ln = "#000000", Rn = "pixelate";
2075
+ function zn(e) {
2076
+ return {
2077
+ regions: [],
2078
+ nextRegionNumber: 1,
2079
+ selectedId: null,
2080
+ currentMode: Rn,
2081
+ currentColor: Ln,
2082
+ imageSize: e.imageSize
2083
+ };
2084
+ }
2085
+ function Bn(e) {
2086
+ return {
2087
+ id: `r_${e.nextRegionNumber.toString(36)}`,
2088
+ nextRegionNumber: e.nextRegionNumber + 1
2089
+ };
2090
+ }
2091
+ function Vn(e, t) {
2092
+ return {
2093
+ ...e,
2094
+ regions: [...e.regions, t],
2095
+ selectedId: t.id
2096
+ };
2097
+ }
2098
+ function Z(e, t) {
2099
+ let n = !1, r = e.regions.map((e) => e.id === t.id ? (n = !0, t) : e);
2100
+ return n ? {
2101
+ ...e,
2102
+ regions: r
2103
+ } : e;
2104
+ }
2105
+ function Hn(e, t) {
2106
+ let n = e.regions.filter((e) => e.id !== t);
2107
+ return n.length === e.regions.length ? e : {
2108
+ ...e,
2109
+ regions: n,
2110
+ selectedId: e.selectedId === t ? null : e.selectedId
2111
+ };
2112
+ }
2113
+ function Un(e, t, n) {
2114
+ if (e.regions.length === 0) return e;
2115
+ let r = e.regions.map((e) => t === "horizontal" ? {
2116
+ ...e,
2117
+ x: n.width - e.x - e.width
2118
+ } : {
2119
+ ...e,
2120
+ y: n.height - e.y - e.height
2121
+ });
2122
+ return {
2123
+ ...e,
2124
+ regions: r,
2125
+ imageSize: n
2126
+ };
2127
+ }
2128
+ function Wn(e, t, n, r) {
2129
+ if (e.regions.length === 0) return {
2130
+ ...e,
2131
+ imageSize: r
2132
+ };
2133
+ if (t === 0 && n === 0 && e.imageSize === r) return e;
2134
+ let i = e.regions.map((e) => ({
2135
+ ...e,
2136
+ x: e.x + t,
2137
+ y: e.y + n
2138
+ }));
2139
+ return {
2140
+ ...e,
2141
+ regions: i,
2142
+ imageSize: r
2143
+ };
2144
+ }
2145
+ function Gn(e, t, n) {
2146
+ if (t === 0 || e.regions.length === 0) return {
2147
+ ...e,
2148
+ imageSize: n
2149
+ };
2150
+ let r = e.imageSize.width, i = e.imageSize.height, a = e.regions.map((e) => {
2151
+ let { x: n, y: a, width: o, height: s } = e;
2152
+ return t === 1 ? {
2153
+ ...e,
2154
+ x: i - a - s,
2155
+ y: n,
2156
+ width: s,
2157
+ height: o
2158
+ } : t === 2 ? {
2159
+ ...e,
2160
+ x: r - n - o,
2161
+ y: i - a - s
2162
+ } : {
2163
+ ...e,
2164
+ x: a,
2165
+ y: r - n - o,
2166
+ width: s,
2167
+ height: o
2168
+ };
2169
+ });
2170
+ return {
2171
+ ...e,
2172
+ regions: a,
2173
+ imageSize: n
2174
+ };
2175
+ }
2176
+ function Kn(e, t) {
2177
+ return e.selectedId === t ? e : {
2178
+ ...e,
2179
+ selectedId: t
2180
+ };
2181
+ }
2182
+ function qn(e, t) {
2183
+ return e.currentMode === t ? e : {
2184
+ ...e,
2185
+ currentMode: t
2186
+ };
2187
+ }
2188
+ function Jn(e, t) {
2189
+ return e.currentColor === t ? e : {
2190
+ ...e,
2191
+ currentColor: t
2192
+ };
2193
+ }
2194
+ function Yn(e, t, n) {
2195
+ let r = e.regions.find((e) => e.id === t);
2196
+ return !r || r.mode === n ? e : Z(e, {
2197
+ ...r,
2198
+ mode: n
2199
+ });
2200
+ }
2201
+ function Xn(e, t, n) {
2202
+ let r = e.regions.find((e) => e.id === t);
2203
+ return !r || r.color === n ? e : Z(e, {
2204
+ ...r,
2205
+ color: n
2206
+ });
2207
+ }
2208
+ function Zn(e, t) {
2209
+ if (t !== null) return e.regions.find((e) => e.id === t);
2210
+ }
2211
+ function Qn(e) {
2212
+ return e.selectedId === null ? null : e.regions.find((t) => t.id === e.selectedId) ?? null;
2213
+ }
2214
+ function $n(e) {
2215
+ let { x: t, y: n, width: r, height: i } = e;
2216
+ return r < 0 && (t += r, r = -r), i < 0 && (n += i, i = -i), {
2217
+ x: t,
2218
+ y: n,
2219
+ width: r,
2220
+ height: i
2221
+ };
2222
+ }
2223
+ function er(e) {
2224
+ let { imageSize: t, mode: n, color: r, id: i } = e, a = Math.min(t.width, t.height), o = Math.max(80, Math.round(a * .25)), s = t.width / 2, c = t.height / 2;
2225
+ return {
2226
+ id: i,
2227
+ x: Math.round(s - o / 2),
2228
+ y: Math.round(c - o / 2),
2229
+ width: o,
2230
+ height: o,
2231
+ mode: n,
2232
+ color: r
2233
+ };
2234
+ }
2235
+ function tr(e, t) {
2236
+ if (e.imageSize.width === t.width && e.imageSize.height === t.height) return e;
2237
+ let n = [];
2238
+ for (let r of e.regions) r.x + r.width <= 0 || r.y + r.height <= 0 || r.x >= t.width || r.y >= t.height || n.push(nr(r, t));
2239
+ let r = e.selectedId !== null && !n.some((t) => t.id === e.selectedId);
2240
+ return {
2241
+ ...e,
2242
+ regions: n,
2243
+ imageSize: {
2244
+ width: t.width,
2245
+ height: t.height
2246
+ },
2247
+ selectedId: r ? null : e.selectedId
2248
+ };
2249
+ }
2250
+ function nr(e, t) {
2251
+ let n = Math.max(0, e.x), r = Math.max(0, e.y), i = Math.min(t.width, e.x + e.width), a = Math.min(t.height, e.y + e.height);
2252
+ return {
2253
+ ...e,
2254
+ x: n,
2255
+ y: r,
2256
+ width: Math.max(0, i - n),
2257
+ height: Math.max(0, a - r)
2258
+ };
2259
+ }
2260
+ function rr(e) {
2261
+ return {
2262
+ x: e.x,
2263
+ y: e.y,
2264
+ width: e.width,
2265
+ height: e.height
2266
+ };
2267
+ }
2268
+ //#endregion
2269
+ //#region src/plugins/resize/state.ts
2270
+ var Q = 8e3, ir = 1;
2271
+ function ar() {
2272
+ return {
2273
+ scaleX: 1,
2274
+ scaleY: 1,
2275
+ lockAspect: !0
2276
+ };
2277
+ }
2278
+ function or(e) {
2279
+ return Math.abs(e.scaleX - 1) < 1e-9 && Math.abs(e.scaleY - 1) < 1e-9;
2280
+ }
2281
+ function sr(e, t) {
2282
+ return {
2283
+ width: $(Math.round(t.width * e.scaleX)),
2284
+ height: $(Math.round(t.height * e.scaleY))
2285
+ };
2286
+ }
2287
+ function cr(e, t, n) {
2288
+ if (n.width <= 0) return e;
2289
+ let r = $(Math.round(t)) / n.width, i = e.lockAspect ? r : e.scaleY;
2290
+ return {
2291
+ ...e,
2292
+ scaleX: r,
2293
+ scaleY: i
2294
+ };
2295
+ }
2296
+ function lr(e, t, n) {
2297
+ if (n.height <= 0) return e;
2298
+ let r = $(Math.round(t)) / n.height, i = e.lockAspect ? r : e.scaleX;
2299
+ return {
2300
+ ...e,
2301
+ scaleX: i,
2302
+ scaleY: r
2303
+ };
2304
+ }
2305
+ function ur(e, t) {
2306
+ let n = pr(t / 100);
2307
+ return {
2308
+ ...e,
2309
+ scaleX: n,
2310
+ scaleY: n
2311
+ };
2312
+ }
2313
+ function dr(e, t) {
2314
+ if (e.lockAspect === t) return e;
2315
+ if (!t) return {
2316
+ ...e,
2317
+ lockAspect: !1
2318
+ };
2319
+ let n = (e.scaleX + e.scaleY) / 2;
2320
+ return {
2321
+ scaleX: n,
2322
+ scaleY: n,
2323
+ lockAspect: !0
2324
+ };
2325
+ }
2326
+ function fr(e) {
2327
+ let t = Math.max(e.scaleX, e.scaleY);
2328
+ return Math.round(t * 1e3) / 10;
2329
+ }
2330
+ function $(e) {
2331
+ return Number.isFinite(e) ? Math.max(1, Math.min(Q, Math.trunc(e))) : 1;
2332
+ }
2333
+ function pr(e) {
2334
+ return !Number.isFinite(e) || e <= 0 ? .01 : Math.max(.01, Math.min(e, Q));
2335
+ }
2336
+ //#endregion
2337
+ //#region src/plugins/resize/bake.ts
2338
+ async function mr(e, t) {
2339
+ if (or(e)) return t;
2340
+ let { width: n, height: r } = sr(e, t);
2341
+ if (n <= 0 || r <= 0) return t;
2342
+ let i = hr(t.width, t.height, n, r), a = {
2343
+ bitmap: t.bitmap,
2344
+ width: t.width,
2345
+ height: t.height
2346
+ }, o = [];
2347
+ for (let e = 0; e < i; e++) {
2348
+ let e = Math.max(n, Math.floor(a.width / 2)), t = Math.max(r, Math.floor(a.height / 2)), i = gr(a, e, t);
2349
+ o.push(i), a = {
2350
+ bitmap: i.canvas,
2351
+ width: e,
2352
+ height: t
2353
+ };
2354
+ }
2355
+ let s = gr(a, n, r);
2356
+ return o.length = 0, {
2357
+ bitmap: s.canvas,
2358
+ width: n,
2359
+ height: r,
2360
+ mimeType: t.mimeType
2361
+ };
2362
+ }
2363
+ function hr(e, t, n, r) {
2364
+ let i = e, a = t, o = 0;
2365
+ for (; (i / 2 > n || a / 2 > r) && o < 16;) i = Math.floor(i / 2), a = Math.floor(a / 2), o += 1;
2366
+ return o;
2367
+ }
2368
+ function gr(n, r, i) {
2369
+ let a = e(r, i), o = t(a);
2370
+ return o.imageSmoothingEnabled = !0, o.imageSmoothingQuality = "high", o.drawImage(n.bitmap, 0, 0, n.width, n.height, 0, 0, r, i), a;
2371
+ }
2372
+ //#endregion
2373
+ //#region src/plugins/rotate/inscribe.ts
2374
+ function _r(e, t) {
2375
+ let n = e.width, r = e.height;
2376
+ if (n <= 0 || r <= 0) return {
2377
+ width: 0,
2378
+ height: 0
2379
+ };
2380
+ let i = Math.abs(Math.cos(t)), a = Math.abs(Math.sin(t)), o = n * i + r * a, s = n * a + r * i, c = o > vr ? n * n / o : Infinity, l = s > vr ? n * r / s : Infinity, u = Math.min(c, l);
2381
+ return {
2382
+ width: u,
2383
+ height: u * r / n
2384
+ };
2385
+ }
2386
+ var vr = 1e-9, yr = -45, br = 45, xr = .1;
2387
+ function Sr() {
2388
+ return {
2389
+ quarterTurns: 0,
2390
+ freeAngle: 0
2391
+ };
2392
+ }
2393
+ function Cr(e) {
2394
+ return {
2395
+ ...e,
2396
+ quarterTurns: (e.quarterTurns + 1) % 4
2397
+ };
2398
+ }
2399
+ function wr(e) {
2400
+ return {
2401
+ ...e,
2402
+ quarterTurns: (e.quarterTurns + 3) % 4
2403
+ };
2404
+ }
2405
+ function Tr(e, t) {
2406
+ let n = Or(t, -45, 45), r = Math.round(n * 10) / 10;
2407
+ return {
2408
+ ...e,
2409
+ freeAngle: r
2410
+ };
2411
+ }
2412
+ function Er(e) {
2413
+ return e.quarterTurns === 0 && Math.abs(e.freeAngle) < 1e-6;
2414
+ }
2415
+ function Dr(e) {
2416
+ return e.quarterTurns * 90 + e.freeAngle;
2417
+ }
2418
+ function Or(e, t, n) {
2419
+ return Math.max(t, Math.min(n, e));
2420
+ }
2421
+ //#endregion
2422
+ //#region src/plugins/rotate/bake.ts
2423
+ async function kr(n, r) {
2424
+ if (Er(n)) return r;
2425
+ let i = Dr(n), a = i * Math.PI / 180, o = i - n.quarterTurns * 90, s = Math.abs(o) < 1e-6, c, l;
2426
+ if (s) n.quarterTurns === 1 || n.quarterTurns === 3 ? (c = r.height, l = r.width) : (c = r.width, l = r.height);
2427
+ else {
2428
+ let e = _r(r, a);
2429
+ c = Math.max(1, Math.round(e.width)), l = Math.max(1, Math.round(e.height));
2430
+ }
2431
+ let u = e(c, l), d = t(u);
2432
+ return d.imageSmoothingEnabled = !0, d.imageSmoothingQuality = "high", d.translate(c / 2, l / 2), d.rotate(a), d.drawImage(r.bitmap, -r.width / 2, -r.height / 2), {
2433
+ bitmap: u.canvas,
2434
+ width: c,
2435
+ height: l,
2436
+ mimeType: r.mimeType
2437
+ };
2438
+ }
2439
+ //#endregion
2440
+ //#region src/state/store.ts
2441
+ function Ar(e) {
2442
+ let t = e, n = /* @__PURE__ */ new Set();
2443
+ function r(e) {
2444
+ for (let r of [...n]) try {
2445
+ r(t, e);
2446
+ } catch (e) {
2447
+ queueMicrotask(() => {
2448
+ throw e;
2449
+ });
2450
+ }
2451
+ }
2452
+ return {
2453
+ get() {
2454
+ return t;
2455
+ },
2456
+ set(e) {
2457
+ let n = t;
2458
+ t = {
2459
+ ...t,
2460
+ ...e
2461
+ }, r(n);
2462
+ },
2463
+ update(e) {
2464
+ let n = t;
2465
+ t = {
2466
+ ...t,
2467
+ ...e(t)
2468
+ }, r(n);
2469
+ },
2470
+ subscribe(e) {
2471
+ return n.add(e), () => n.delete(e);
2472
+ }
2473
+ };
2474
+ }
2475
+ //#endregion
2476
+ export { Tt as ALL_SELECTION_HANDLES, qe as DEFAULT_EMOJI, K as DEFAULT_FINETUNE_STATE, j as DEFAULT_FONT_KEY, gn as DEFAULT_FRAME_STATE, C as DEFAULT_OUTPUT_STATE, Ge as DEFAULT_PALETTE_COLOR, Ln as DEFAULT_REDACT_COLOR, Rn as DEFAULT_REDACT_MODE, Ke as DEFAULT_STROKE_WIDTH, Le as EMOJI_FONT_STACK, Je as EMOJI_MIN_SIZE, he as ENCODABLE_MIMES, ie as EventBus, en as FILTER_PRESETS, qt as FINETUNE_ADJUSTMENTS, Gt as FINETUNE_MAX, Wt as FINETUNE_MIN, Kt as FINETUNE_STEP, hn as FRAME_PRESETS, mn as FRAME_PRESET_IDS, Ue as FREEHAND_DEFAULT_STROKE, br as FREE_ANGLE_MAX, yr as FREE_ANGLE_MIN, xr as FREE_ANGLE_STEP, Ve as HIGHLIGHT_DEFAULT_COLOR, He as HIGHLIGHT_DEFAULT_STROKE, fe as HISTORY_MAX_ENTRIES, pe as History, l as IDENTITY_VIEWPORT_TRANSFORM, ut as KEYBOARD_PLACEABLE_KINDS, g as MAX_ZOOM, ze as MIN_SAMPLE_DISTANCE, _ as MIN_ZOOM, Ot as PICK_TOLERANCE, In as REDACT_MODES, Q as RESIZE_MAX_DIMENSION, ir as RESIZE_MIN_DIMENSION, Ie as SYSTEM_FONT_STACK, We as TEXT_DEFAULT_FONT_SIZE, E as TEXT_FONTS, I as TEXT_LINE_HEIGHT, ee as ViewportController, Vn as addRegion, tt as addShape, Mt as applyAspectRatio, sn as applyClarity, on as applyFinetuneLutAndSaturation, q as applyFinetuneToImageData, Ht as applyPresetByIndex, F as assertNever, gt as bakeAnnotate, n as bakeCanvasToBlob, It as bakeCrop, ln as bakeFinetune, pn as bakeFlip, xn as bakeFrame, jn as bakeRedact, mr as bakeResize, kr as bakeRotate, B as boundingBoxOf, cn as boxBlur3x3, rn as buildFinetuneLut, a as canEncodeMime, w as clampQuality, v as clampRectInside, u as computeViewport, xe as copyJpegExif, e as createBakeCanvas, er as createCenteredRedactRegion, ft as createCenteredShape, Ar as createStore, k as cssFontString, Be as decimatePoints, Ye as defaultEmojiSize, N as defaultStylePalette, Hn as deleteRedactRegion, rt as deleteShape, ke as deriveOutputName, Dr as effectiveAngleDeg, fr as effectivePercent, Ae as encodeSourceImage, z as estimateLineWidth, Rt as filterPresets, nn as findActivePreset, J as findFramePreset, Zn as findRedactRegion, it as findShape, tn as finetuneStatesEqual, W as fitRectToBoundsWithRatio, Re as fontDefFor, O as fontStackFor, An as frameOutputSize, t as getBakeContext2D, At as hitTest, Xe as initialAnnotateState, Vt as initialCropState, Jt as initialFinetuneState, un as initialFlipState, _n as initialFrameState, zn as initialRedactState, ar as initialResizeState, Sr as initialRotateState, Yt as isFinetuneNoOp, fn as isFlipNoOp, vn as isFrameNoOp, dt as isKeyboardPlaceableKind, Lt as isPresetVisible, or as isResizeNoOp, Er as isRotateNoOp, _r as largestInscribedRect, R as layoutTextLines, pt as lineOffset, o as loadImage, Bn as mintRegionId, Ze as mintShapeId, Un as mirrorRedactRegions, st as mirrorShape, at as normaliseRectExtent, $n as normaliseRedactExtent, M as normalizeAngle, P as normalizeTextShape, Cn as paintInsideFrame, Mn as paintRedactRegion, _t as paintShape, kt as pickShape, p as pointDisplayToImage, f as pointImageToDisplay, le as pointInRect, se as rectBottom, ce as rectCenter, h as rectDisplayToImage, Dt as rectFromHandleDrag, ae as rectFromPoints, m as rectImageToDisplay, oe as rectRight, ue as rectsEqual, rr as regionBoundingBox, Z as replaceRedactRegion, nt as replaceShape, Qt as resetAllFinetune, Zt as resetFinetune, zt as resizeRectFromHandle, Oe as resolveOutputMime, sr as resolveOutputSize, tr as revalidateRedactAgainstBounds, Cr as rotateClockwise, wr as rotateCounterClockwise, Gn as rotateRedactRegions, ct as rotateShape, y as roundRect, Fe as runUtilityChain, Kn as selectRedactRegion, et as selectShape, Qn as selectedRedactRegionOf, Et as selectionHandlePositions, Qe as setActiveTool, Xt as setFinetune, bn as setFrameColor, yn as setFramePreset, Tr as setFreeAngle, lr as setHeightPx, dr as setLockAspect, ge as setOutputMime, _e as setOutputQuality, ur as setPercent, Jn as setRedactCurrentColor, qn as setRedactCurrentMode, Xn as setRedactRegionColor, Yn as setRedactRegionMode, ve as setStripMetadata, $e as setStyle, cr as setWidthPx, L as textLines, dn as toggleFlip, A as tracePath, lt as transformShapes, de as translateClampedRect, Wn as translateRedactRegions, ot as translateShape };
2477
+
2478
+ //# sourceMappingURL=index.js.map