@magicpages/kalotyp-core 0.1.0 → 0.1.2

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,2204 @@
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 = te(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 = te(e);
182
+ y(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 = v(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
+ y(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 v(e, t, n) {
235
+ return e < t ? t : e > n ? n : e;
236
+ }
237
+ function te(e) {
238
+ return {
239
+ zoom: v(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 y(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 ne = 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 re(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 ie(e) {
285
+ return e.x + e.width;
286
+ }
287
+ function ae(e) {
288
+ return e.y + e.height;
289
+ }
290
+ function oe(e) {
291
+ return {
292
+ x: e.x + e.width / 2,
293
+ y: e.y + e.height / 2
294
+ };
295
+ }
296
+ function se(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 ce(e, t) {
300
+ return e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height;
301
+ }
302
+ function le(e, t, n, r) {
303
+ return b({
304
+ x: e.x + t,
305
+ y: e.y + n,
306
+ width: e.width,
307
+ height: e.height
308
+ }, r);
309
+ }
310
+ function b(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 x(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 ue = 50, de = class {
330
+ shadow;
331
+ undoStack = [];
332
+ redoStack = [];
333
+ constructor(e) {
334
+ this.shadow = S(e);
335
+ }
336
+ commit(e) {
337
+ fe(e, this.shadow) || (this.undoStack.push(this.shadow), this.undoStack.length > 50 && this.undoStack.shift(), this.shadow = S(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(S(e)), this.shadow = t, {
348
+ snapshot: t,
349
+ changed: pe(e, t)
350
+ }) : null;
351
+ }
352
+ redo(e) {
353
+ let t = this.redoStack.pop();
354
+ return t ? (this.undoStack.push(S(e)), this.undoStack.length > 50 && this.undoStack.shift(), this.shadow = t, {
355
+ snapshot: t,
356
+ changed: pe(e, t)
357
+ }) : null;
358
+ }
359
+ size() {
360
+ return {
361
+ undo: this.undoStack.length,
362
+ redo: this.redoStack.length
363
+ };
364
+ }
365
+ };
366
+ function fe(e, t) {
367
+ if (e.size !== t.size) return !1;
368
+ for (let [n, r] of e) if (!t.has(n) || C(r) !== C(t.get(n))) return !1;
369
+ return !0;
370
+ }
371
+ function pe(e, t) {
372
+ let n = /* @__PURE__ */ new Set();
373
+ for (let [r, i] of t) C(i) !== C(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 S(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 C(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 w = {
395
+ mimeChoice: "auto",
396
+ quality: .85,
397
+ stripMetadata: !0
398
+ }, me = [
399
+ "image/png",
400
+ "image/jpeg",
401
+ "image/webp",
402
+ "image/avif"
403
+ ];
404
+ function T(e) {
405
+ return Number.isFinite(e) ? e < 0 ? 0 : e > 1 ? 1 : e : w.quality;
406
+ }
407
+ function he(e, t) {
408
+ return e.mimeChoice === t ? e : {
409
+ ...e,
410
+ mimeChoice: t
411
+ };
412
+ }
413
+ function ge(e, t) {
414
+ let n = T(t);
415
+ return e.quality === n ? e : {
416
+ ...e,
417
+ quality: n
418
+ };
419
+ }
420
+ function _e(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 E = [255, 216], D = [255, 225], O = [
429
+ 69,
430
+ 120,
431
+ 105,
432
+ 102,
433
+ 0,
434
+ 0
516
435
  ];
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" }
436
+ async function ve(e) {
437
+ if (e.output.type && e.output.type !== "image/jpeg") return e.output;
438
+ let t = await ye(e.source);
439
+ if (!be(t, E)) return e.output;
440
+ let n = xe(t);
441
+ if (!n) return e.output;
442
+ let r = await ye(e.output);
443
+ if (!be(r, E)) 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 ye(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 be(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 xe(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] === D[0] && e[t + 1] === D[1] && Se(e, t + 4)) return e.slice(t, i);
472
+ t = i;
473
+ }
474
+ }
475
+ function Se(e, t) {
476
+ for (let n = 0; n < O.length; n++) if (e[t + n] !== O[n]) return !1;
477
+ return !0;
478
+ }
479
+ //#endregion
480
+ //#region src/pipeline/encode.ts
481
+ var Ce = "image/png", we = new Set([
482
+ "image/png",
483
+ "image/webp",
484
+ "image/avif"
485
+ ]);
486
+ async function Te(e, t) {
487
+ return e.mimeChoice === "auto" ? await a("image/webp") ? "image/webp" : !we.has(t.mimeType) && await a("image/jpeg") ? "image/jpeg" : Ce : await a(e.mimeChoice) ? e.mimeChoice : await a("image/webp") ? "image/webp" : Ce;
488
+ }
489
+ function Ee(e, t) {
490
+ let n = Oe(t);
491
+ if (!e) return `kalotyp-image.${n}`;
492
+ let r = ke(e);
493
+ if (!r) return `kalotyp-image.${n}`;
494
+ let i = je(r);
495
+ return i ? `${i}.${n}` : `kalotyp-image.${n}`;
496
+ }
497
+ async function De(t, r = {}) {
498
+ let i = r.output ?? w, a = await Te(i, t), o = T(i.quality), s = Ee(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 ve({
509
+ source: r.sourceBlob,
510
+ output: l
511
+ }) : l;
512
+ return new File([u], s, { type: a });
513
+ }
514
+ function Oe(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 ke(e) {
523
+ let t = Ae(e).split(/[/\\]/);
524
+ return t[t.length - 1];
525
+ }
526
+ function Ae(e) {
527
+ let t = e.indexOf("?");
528
+ return t === -1 ? e : e.slice(0, t);
529
+ }
530
+ function je(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 Me(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/smooth.ts
543
+ var Ne = 2;
544
+ function Pe(e) {
545
+ if (e.length <= 1) return [...e];
546
+ let t = e[0];
547
+ if (!t) return [];
548
+ let n = [t], r = t;
549
+ for (let t = 1; t < e.length - 1; t++) {
550
+ let i = e[t];
551
+ if (!i) continue;
552
+ let a = i.x - r.x, o = i.y - r.y;
553
+ a * a + o * o < 4 || (n.push(i), r = i);
554
+ }
555
+ let i = e[e.length - 1];
556
+ return i && i !== r && n.push(i), n;
557
+ }
558
+ function k(e, t) {
559
+ if (t.length === 0) return;
560
+ let n = t[0];
561
+ if (!n) return;
562
+ if (t.length === 1) {
563
+ e.moveTo(n.x, n.y), e.lineTo(n.x, n.y);
564
+ return;
565
+ }
566
+ e.moveTo(n.x, n.y);
567
+ for (let n = 1; n < t.length - 1; n++) {
568
+ let r = t[n], i = t[n + 1];
569
+ if (!r || !i) continue;
570
+ let a = (r.x + i.x) / 2, o = (r.y + i.y) / 2;
571
+ e.quadraticCurveTo(r.x, r.y, a, o);
572
+ }
573
+ let r = t[t.length - 1];
574
+ r && e.lineTo(r.x, r.y);
575
+ }
576
+ //#endregion
577
+ //#region src/plugins/annotate/state.ts
578
+ var Fe = "rgba(255, 235, 59, 0.35)", Ie = 18, Le = 6, Re = 32, ze = "#ff3b30", Be = 4;
579
+ function Ve() {
580
+ return {
581
+ color: ze,
582
+ strokeWidth: 4,
583
+ fillColor: null,
584
+ fontSize: 32
585
+ };
586
+ }
587
+ function He(e) {
588
+ return {
589
+ shapes: [],
590
+ selectedId: null,
591
+ activeTool: "select",
592
+ currentStyle: Ve(),
593
+ imageSize: e.imageSize,
594
+ nextShapeNumber: 1
595
+ };
596
+ }
597
+ function Ue(e) {
598
+ return {
599
+ id: `s_${e.nextShapeNumber.toString(36)}`,
600
+ nextShapeNumber: e.nextShapeNumber + 1
601
+ };
602
+ }
603
+ function We(e, t) {
604
+ return e.activeTool === t ? e : {
605
+ ...e,
606
+ activeTool: t,
607
+ selectedId: t === "select" ? e.selectedId : null
608
+ };
609
+ }
610
+ function Ge(e, t) {
611
+ return {
612
+ ...e,
613
+ currentStyle: {
614
+ ...e.currentStyle,
615
+ ...t
616
+ }
617
+ };
618
+ }
619
+ function Ke(e, t) {
620
+ return e.selectedId === t ? e : {
621
+ ...e,
622
+ selectedId: t
623
+ };
624
+ }
625
+ function qe(e, t) {
626
+ return {
627
+ ...e,
628
+ shapes: [...e.shapes, t],
629
+ selectedId: t.id
630
+ };
631
+ }
632
+ function Je(e, t) {
633
+ let n = !1, r = e.shapes.map((e) => e.id === t.id ? (n = !0, t) : e);
634
+ return n ? {
635
+ ...e,
636
+ shapes: r
637
+ } : e;
638
+ }
639
+ function Ye(e, t) {
640
+ let n = e.shapes.filter((e) => e.id !== t);
641
+ return n.length === e.shapes.length ? e : {
642
+ ...e,
643
+ shapes: n,
644
+ selectedId: e.selectedId === t ? null : e.selectedId
645
+ };
646
+ }
647
+ function Xe(e, t) {
648
+ if (t !== null) return e.shapes.find((e) => e.id === t);
649
+ }
650
+ function Ze(e) {
651
+ let { x: t, y: n, width: r, height: i } = e;
652
+ return r < 0 && (t += r, r = -r), i < 0 && (n += i, i = -i), {
653
+ x: t,
654
+ y: n,
655
+ width: r,
656
+ height: i
657
+ };
658
+ }
659
+ function Qe(e, t, n) {
660
+ switch (e.kind) {
661
+ case "text": return {
662
+ ...e,
663
+ x: e.x + t,
664
+ y: e.y + n
665
+ };
666
+ case "rect":
667
+ case "ellipse": return {
668
+ ...e,
669
+ x: e.x + t,
670
+ y: e.y + n
671
+ };
672
+ case "arrow": return {
673
+ ...e,
674
+ x1: e.x1 + t,
675
+ y1: e.y1 + n,
676
+ x2: e.x2 + t,
677
+ y2: e.y2 + n
678
+ };
679
+ case "freehand":
680
+ case "highlight": return {
681
+ ...e,
682
+ points: e.points.map((e) => ({
683
+ x: e.x + t,
684
+ y: e.y + n
685
+ }))
686
+ };
687
+ default: return A(e);
688
+ }
689
+ }
690
+ function A(e) {
691
+ throw Error(`Unhandled annotation shape kind: ${JSON.stringify(e)}`);
692
+ }
693
+ function $e(e, t, n) {
694
+ if (t === "horizontal") switch (e.kind) {
695
+ case "rect":
696
+ case "ellipse": return {
697
+ ...e,
698
+ x: n.width - e.x - e.width
699
+ };
700
+ case "text": return {
701
+ ...e,
702
+ x: n.width - e.x
703
+ };
704
+ case "arrow": return {
705
+ ...e,
706
+ x1: n.width - e.x1,
707
+ x2: n.width - e.x2
708
+ };
709
+ case "freehand":
710
+ case "highlight": return {
711
+ ...e,
712
+ points: e.points.map((e) => ({
713
+ x: n.width - e.x,
714
+ y: e.y
715
+ }))
716
+ };
717
+ default: return A(e);
718
+ }
719
+ switch (e.kind) {
720
+ case "rect":
721
+ case "ellipse": return {
722
+ ...e,
723
+ y: n.height - e.y - e.height
724
+ };
725
+ case "text": return {
726
+ ...e,
727
+ y: n.height - e.y
728
+ };
729
+ case "arrow": return {
730
+ ...e,
731
+ y1: n.height - e.y1,
732
+ y2: n.height - e.y2
733
+ };
734
+ case "freehand":
735
+ case "highlight": return {
736
+ ...e,
737
+ points: e.points.map((e) => ({
738
+ x: e.x,
739
+ y: n.height - e.y
740
+ }))
741
+ };
742
+ default: return A(e);
743
+ }
744
+ }
745
+ function et(e, t, n) {
746
+ if (t === 0) return e;
747
+ let r = (e, r) => t === 1 ? {
748
+ x: n.height - r,
749
+ y: e
750
+ } : t === 2 ? {
751
+ x: n.width - e,
752
+ y: n.height - r
753
+ } : {
754
+ x: r,
755
+ y: n.width - e
756
+ };
757
+ switch (e.kind) {
758
+ case "rect":
759
+ case "ellipse": {
760
+ 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);
761
+ return {
762
+ ...e,
763
+ x: n,
764
+ y: i,
765
+ width: a,
766
+ height: o
767
+ };
768
+ }
769
+ case "text": {
770
+ let t = r(e.x, e.y);
771
+ return {
772
+ ...e,
773
+ x: t.x,
774
+ y: t.y
775
+ };
776
+ }
777
+ case "arrow": {
778
+ let t = r(e.x1, e.y1), n = r(e.x2, e.y2);
779
+ return {
780
+ ...e,
781
+ x1: t.x,
782
+ y1: t.y,
783
+ x2: n.x,
784
+ y2: n.y
785
+ };
786
+ }
787
+ case "freehand":
788
+ case "highlight": return {
789
+ ...e,
790
+ points: e.points.map((e) => r(e.x, e.y))
791
+ };
792
+ default: return A(e);
793
+ }
794
+ }
795
+ function tt(e, t) {
796
+ return e.shapes.length === 0 ? e : {
797
+ ...e,
798
+ shapes: e.shapes.map(t)
799
+ };
800
+ }
801
+ var nt = [
802
+ "text",
803
+ "rect",
804
+ "ellipse",
805
+ "arrow"
782
806
  ];
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
- }
807
+ function rt(e) {
808
+ return e === "text" || e === "rect" || e === "ellipse" || e === "arrow";
809
+ }
810
+ function it(e, t) {
811
+ let { imageSize: n, style: r, id: i } = t, a = Math.min(n.width, n.height), o = n.width / 2, s = n.height / 2;
812
+ switch (e) {
813
+ case "rect":
814
+ case "ellipse": {
815
+ let t = Math.max(80, Math.round(a * .25)), n = Math.round(o - t / 2), c = Math.round(s - t / 2);
816
+ return e === "rect" ? {
817
+ id: i,
818
+ kind: "rect",
819
+ x: n,
820
+ y: c,
821
+ width: t,
822
+ height: t,
823
+ strokeColor: r.color,
824
+ strokeWidth: r.strokeWidth,
825
+ fillColor: r.fillColor
826
+ } : {
827
+ id: i,
828
+ kind: "ellipse",
829
+ x: n,
830
+ y: c,
831
+ width: t,
832
+ height: t,
833
+ strokeColor: r.color,
834
+ strokeWidth: r.strokeWidth,
835
+ fillColor: r.fillColor
836
+ };
837
+ }
838
+ case "arrow": {
839
+ let e = Math.max(100, Math.round(a * .3)), t = Math.round(o - e / 2), n = t + e, c = Math.round(s);
840
+ return {
841
+ id: i,
842
+ kind: "arrow",
843
+ x1: t,
844
+ y1: c,
845
+ x2: n,
846
+ y2: c,
847
+ color: r.color,
848
+ strokeWidth: r.strokeWidth
849
+ };
850
+ }
851
+ case "text": return {
852
+ id: i,
853
+ kind: "text",
854
+ x: Math.round(o),
855
+ y: Math.round(s - r.fontSize / 2),
856
+ text: "",
857
+ fontSize: r.fontSize,
858
+ color: r.color,
859
+ textAlign: "center"
860
+ };
861
+ }
862
+ }
863
+ //#endregion
864
+ //#region src/plugins/annotate/bake.ts
865
+ var at = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
866
+ async function ot(n, r) {
867
+ if (n.shapes.length === 0) return r;
868
+ let i = e(r.width, r.height), a = t(i);
869
+ a.imageSmoothingEnabled = !0, a.imageSmoothingQuality = "high", a.drawImage(r.bitmap, 0, 0, r.width, r.height);
870
+ for (let e of n.shapes) j(a, e);
871
+ return {
872
+ bitmap: i.canvas,
873
+ width: r.width,
874
+ height: r.height,
875
+ mimeType: r.mimeType
876
+ };
877
+ }
878
+ function j(e, t) {
879
+ switch (t.kind) {
880
+ case "text":
881
+ st(e, t);
882
+ return;
883
+ case "rect":
884
+ ct(e, t);
885
+ return;
886
+ case "ellipse":
887
+ lt(e, t);
888
+ return;
889
+ case "arrow":
890
+ ut(e, t);
891
+ return;
892
+ case "freehand":
893
+ dt(e, t);
894
+ return;
895
+ case "highlight":
896
+ ft(e, t);
897
+ return;
898
+ default: A(t);
899
+ }
900
+ }
901
+ function st(e, t) {
902
+ e.save(), e.fillStyle = t.color, e.font = `${t.fontSize}px ${at}`, e.textAlign = t.textAlign, e.textBaseline = "top";
903
+ let n = t.text.length === 0 ? [""] : t.text.split("\n"), r = t.fontSize * 1.2;
904
+ for (let i = 0; i < n.length; i++) {
905
+ let a = n[i];
906
+ a !== void 0 && e.fillText(a, t.x, t.y + i * r);
907
+ }
908
+ e.restore();
909
+ }
910
+ function ct(e, t) {
911
+ 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();
912
+ }
913
+ function lt(e, t) {
914
+ e.save();
915
+ let n = t.width / 2, r = t.height / 2, i = t.x + n, a = t.y + r;
916
+ 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();
917
+ }
918
+ function ut(e, t) {
919
+ let n = t.x2 - t.x1, r = t.y2 - t.y1, i = Math.sqrt(n * n + r * r);
920
+ if (i < .5) return;
921
+ e.save(), e.strokeStyle = t.color, e.fillStyle = t.color, e.lineWidth = t.strokeWidth, e.lineCap = "round", e.lineJoin = "round";
922
+ 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;
923
+ e.beginPath(), e.moveTo(t.x1, t.y1), e.lineTo(l, u), e.stroke();
924
+ let d = t.x2 - s * a, f = t.y2 - c * a, p = -c, m = s;
925
+ 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();
926
+ }
927
+ function dt(e, t) {
928
+ t.points.length !== 0 && (e.save(), e.strokeStyle = t.color, e.lineWidth = t.strokeWidth, e.lineCap = "round", e.lineJoin = "round", e.beginPath(), k(e, t.points), e.stroke(), e.restore());
929
+ }
930
+ function ft(e, t) {
931
+ 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(), k(e, t.points), e.stroke(), e.restore());
932
+ }
933
+ //#endregion
934
+ //#region src/plugins/annotate/geometry.ts
935
+ function M(e) {
936
+ switch (e.kind) {
937
+ case "text": {
938
+ let { width: t, height: n } = N(e.text, e.fontSize);
939
+ return {
940
+ x: P(e.x, t, e.textAlign),
941
+ y: e.y,
942
+ width: t,
943
+ height: n
944
+ };
945
+ }
946
+ case "rect":
947
+ case "ellipse": return {
948
+ x: e.x,
949
+ y: e.y,
950
+ width: e.width,
951
+ height: e.height
952
+ };
953
+ case "arrow": return {
954
+ x: Math.min(e.x1, e.x2),
955
+ y: Math.min(e.y1, e.y2),
956
+ width: Math.abs(e.x2 - e.x1),
957
+ height: Math.abs(e.y2 - e.y1)
958
+ };
959
+ case "freehand":
960
+ case "highlight": {
961
+ let t = e.points[0];
962
+ if (!t) return {
963
+ x: 0,
964
+ y: 0,
965
+ width: 0,
966
+ height: 0
967
+ };
968
+ let n = t.x, r = t.y, i = t.x, a = t.y;
969
+ 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);
970
+ return {
971
+ x: n,
972
+ y: r,
973
+ width: i - n,
974
+ height: a - r
975
+ };
976
+ }
977
+ default: return A(e);
978
+ }
979
+ }
980
+ var pt = [
981
+ "tl",
982
+ "tr",
983
+ "bl",
984
+ "br",
985
+ "t",
986
+ "r",
987
+ "b",
988
+ "l"
967
989
  ];
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"
990
+ function mt(e) {
991
+ 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;
992
+ return {
993
+ tl: {
994
+ x: t,
995
+ y: r
996
+ },
997
+ tr: {
998
+ x: n,
999
+ y: r
1000
+ },
1001
+ bl: {
1002
+ x: t,
1003
+ y: i
1004
+ },
1005
+ br: {
1006
+ x: n,
1007
+ y: i
1008
+ },
1009
+ t: {
1010
+ x: a,
1011
+ y: r
1012
+ },
1013
+ r: {
1014
+ x: n,
1015
+ y: o
1016
+ },
1017
+ b: {
1018
+ x: a,
1019
+ y: i
1020
+ },
1021
+ l: {
1022
+ x: t,
1023
+ y: o
1024
+ }
1025
+ };
1026
+ }
1027
+ function ht(e, t, n) {
1028
+ let r = e.x, i = e.y, a = e.x + e.width, o = e.y + e.height;
1029
+ 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), {
1030
+ x: r,
1031
+ y: i,
1032
+ width: a - r,
1033
+ height: o - i
1034
+ };
1035
+ }
1036
+ function N(e, t) {
1037
+ let n = e.length === 0 ? [""] : e.split("\n"), r = 0;
1038
+ for (let e of n) e.length > r && (r = e.length);
1039
+ return {
1040
+ width: Math.max(t * .6, r * t * .55),
1041
+ height: n.length * t * 1.2
1042
+ };
1043
+ }
1044
+ function P(e, t, n) {
1045
+ switch (n) {
1046
+ case "left": return e;
1047
+ case "center": return e - t / 2;
1048
+ case "right": return e - t;
1049
+ }
1050
+ }
1051
+ //#endregion
1052
+ //#region src/plugins/annotate/hit-test.ts
1053
+ var gt = 4;
1054
+ function _t(e, t) {
1055
+ for (let n = e.length - 1; n >= 0; n--) {
1056
+ let r = e[n];
1057
+ if (r && F(r, t)) return r;
1058
+ }
1059
+ }
1060
+ function F(e, t) {
1061
+ switch (e.kind) {
1062
+ case "text": return I(t, M(e));
1063
+ case "rect": {
1064
+ let n = I(t, R(e));
1065
+ if (e.fillColor !== null) return n;
1066
+ let r = L(R(e), e.strokeWidth / 2 + 4), i = L(R(e), -(e.strokeWidth / 2 + 4));
1067
+ return I(t, r) && !I(t, i);
1068
+ }
1069
+ case "ellipse": {
1070
+ let n = R(e), r = n.width / 2, i = n.height / 2, a = n.x + r, o = n.y + i;
1071
+ if (r <= 0 || i <= 0) return !1;
1072
+ 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);
1073
+ return e.fillColor === null ? l <= (1 + u) ** 2 && l >= (1 - u) ** 2 : l <= (1 + u) ** 2;
1074
+ }
1075
+ case "arrow": return z(t, {
1076
+ x: e.x1,
1077
+ y: e.y1
1078
+ }, {
1079
+ x: e.x2,
1080
+ y: e.y2
1081
+ }, e.strokeWidth / 2 + 4);
1082
+ case "freehand":
1083
+ case "highlight": {
1084
+ if (!I(t, L(M(e), e.strokeWidth / 2 + 4))) return !1;
1085
+ let n = e.strokeWidth / 2 + 4;
1086
+ for (let r = 1; r < e.points.length; r++) {
1087
+ let i = e.points[r - 1], a = e.points[r];
1088
+ if (i && a && z(t, i, a, n)) return !0;
1089
+ }
1090
+ if (e.points.length === 1) {
1091
+ let r = e.points[0];
1092
+ if (!r) return !1;
1093
+ let i = r.x - t.x, a = r.y - t.y;
1094
+ return i * i + a * a <= n * n;
1095
+ }
1096
+ return !1;
1097
+ }
1098
+ default: return A(e);
1099
+ }
1100
+ }
1101
+ function I(e, t) {
1102
+ return e.x >= t.x && e.y >= t.y && e.x <= t.x + t.width && e.y <= t.y + t.height;
1103
+ }
1104
+ function L(e, t) {
1105
+ return {
1106
+ x: e.x - t,
1107
+ y: e.y - t,
1108
+ width: e.width + t * 2,
1109
+ height: e.height + t * 2
1110
+ };
1111
+ }
1112
+ function R(e) {
1113
+ let { x: t, y: n, width: r, height: i } = e;
1114
+ return r < 0 && (t += r, r = -r), i < 0 && (n += i, i = -i), {
1115
+ x: t,
1116
+ y: n,
1117
+ width: r,
1118
+ height: i
1119
+ };
1120
+ }
1121
+ function z(e, t, n, r) {
1122
+ let i = n.x - t.x, a = n.y - t.y, o = i * i + a * a;
1123
+ if (o === 0) {
1124
+ let n = e.x - t.x, i = e.y - t.y;
1125
+ return n * n + i * i <= r * r;
1126
+ }
1127
+ let s = ((e.x - t.x) * i + (e.y - t.y) * a) / o;
1128
+ s < 0 ? s = 0 : s > 1 && (s = 1);
1129
+ let c = t.x + s * i, l = t.y + s * a, u = e.x - c, d = e.y - l;
1130
+ return u * u + d * d <= r * r;
1131
+ }
1132
+ //#endregion
1133
+ //#region src/plugins/crop/aspect-ratio.ts
1134
+ function B(e, t) {
1135
+ if (t <= 0 || e.width <= 0 || e.height <= 0) return {
1136
+ x: e.x,
1137
+ y: e.y,
1138
+ width: 0,
1139
+ height: 0
1140
+ };
1141
+ let n = e.width / e.height, r, i;
1142
+ return t >= n ? (r = e.width, i = r / t) : (i = e.height, r = i * t), {
1143
+ x: e.x + (e.width - r) / 2,
1144
+ y: e.y + (e.height - i) / 2,
1145
+ width: r,
1146
+ height: i
1147
+ };
1148
+ }
1149
+ function V(e, t, n, r) {
1150
+ if (t <= 0) return e;
1151
+ if (e.width <= 0 || e.height <= 0) return B(r, t);
1152
+ let i = e.width / e.height, a, o;
1153
+ i > t ? (o = e.height, a = o * t) : (a = e.width, o = a / t);
1154
+ let s = b(H(e, a, o, n), r), c = s.height === 0 ? 0 : s.width / s.height;
1155
+ return Math.abs(c - t) <= vt ? s : yt(s, t, n);
1156
+ }
1157
+ var vt = 1e-6;
1158
+ function H(e, t, n, r) {
1159
+ switch (r) {
1160
+ case "tl": return {
1161
+ x: e.x,
1162
+ y: e.y,
1163
+ width: t,
1164
+ height: n
1165
+ };
1166
+ case "tr": return {
1167
+ x: e.x + e.width - t,
1168
+ y: e.y,
1169
+ width: t,
1170
+ height: n
1171
+ };
1172
+ case "bl": return {
1173
+ x: e.x,
1174
+ y: e.y + e.height - n,
1175
+ width: t,
1176
+ height: n
1177
+ };
1178
+ case "br": return {
1179
+ x: e.x + e.width - t,
1180
+ y: e.y + e.height - n,
1181
+ width: t,
1182
+ height: n
1183
+ };
1184
+ case "center": return {
1185
+ x: e.x + (e.width - t) / 2,
1186
+ y: e.y + (e.height - n) / 2,
1187
+ width: t,
1188
+ height: n
1189
+ };
1190
+ }
1191
+ }
1192
+ function yt(e, t, n) {
1193
+ let r = B(e, t);
1194
+ return H(e, r.width, r.height, n);
1195
+ }
1196
+ //#endregion
1197
+ //#region src/plugins/crop/bake.ts
1198
+ function bt(t, n) {
1199
+ let r = x(n.rect), i = U(r.x, 0, t.width), a = U(r.y, 0, t.height), o = U(r.width, 1, t.width - i), s = U(r.height, 1, t.height - a), c = e(o, s);
1200
+ if (c.kind === "offscreen") {
1201
+ let e = c.canvas.getContext("2d");
1202
+ if (!e) throw Error("2D canvas context is not available");
1203
+ return e.drawImage(t.bitmap, i, a, o, s, 0, 0, o, s), {
1204
+ bitmap: c.canvas,
1205
+ width: o,
1206
+ height: s,
1207
+ mimeType: t.mimeType
1208
+ };
1209
+ }
1210
+ let l = c.canvas.getContext("2d");
1211
+ if (!l) throw Error("2D canvas context is not available");
1212
+ return l.drawImage(t.bitmap, i, a, o, s, 0, 0, o, s), {
1213
+ bitmap: c.canvas,
1214
+ width: o,
1215
+ height: s,
1216
+ mimeType: t.mimeType
1217
+ };
1218
+ }
1219
+ function U(e, t, n) {
1220
+ return Math.max(t, Math.min(n, e));
1221
+ }
1222
+ //#endregion
1223
+ //#region src/plugins/crop/preset-filter.ts
1224
+ function W(e, t) {
1225
+ let [n] = e;
1226
+ return n === void 0 || t === void 0 ? !0 : t === "landscape" ? n >= 1 : t === "portrait" ? n < 1 : !0;
1227
+ }
1228
+ function xt(e, t) {
1229
+ return e.filter((e) => W(e, t));
1230
+ }
1231
+ //#endregion
1232
+ //#region src/plugins/crop/resize.ts
1233
+ function St(e, t, n, r) {
1234
+ 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;
1235
+ (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);
1236
+ let p = Math.min(l, d), m = Math.min(u, f), h = Math.abs(d - l), g = Math.abs(f - u);
1237
+ 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));
1238
+ let _ = {
1239
+ x: p,
1240
+ y: m,
1241
+ width: h,
1242
+ height: g
1243
+ };
1244
+ return _ = b(_, r.bounds), r.aspectRatio !== void 0 && r.aspectRatio > 0 && (_ = V(_, r.aspectRatio, Ct(t), r.bounds)), _;
1245
+ }
1246
+ function Ct(e) {
1247
+ switch (e) {
1248
+ case "tl": return "br";
1249
+ case "tr": return "bl";
1250
+ case "bl": return "tr";
1251
+ case "br": return "tl";
1252
+ case "t": return "bl";
1253
+ case "b": return "tl";
1254
+ case "l": return "tr";
1255
+ case "r": return "tl";
1256
+ }
1257
+ }
1258
+ //#endregion
1259
+ //#region src/plugins/crop/state.ts
1260
+ function wt(e) {
1261
+ return {
1262
+ rect: {
1263
+ x: 0,
1264
+ y: 0,
1265
+ width: e.imageSize.width,
1266
+ height: e.imageSize.height
1267
+ },
1268
+ aspectRatio: void 0,
1269
+ activePresetIndex: Et(e.presets),
1270
+ presets: e.presets,
1271
+ imageSize: e.imageSize
1272
+ };
1273
+ }
1274
+ function Tt(e, t) {
1275
+ let n = e.presets[t];
1276
+ if (!n) return e;
1277
+ let [r] = n;
1278
+ if (r === void 0) return {
1279
+ ...e,
1280
+ aspectRatio: void 0,
1281
+ activePresetIndex: t
1282
+ };
1283
+ let i = B({
1284
+ x: 0,
1285
+ y: 0,
1286
+ width: e.imageSize.width,
1287
+ height: e.imageSize.height
1288
+ }, r);
1289
+ return {
1290
+ ...e,
1291
+ rect: i,
1292
+ aspectRatio: r,
1293
+ activePresetIndex: t
1294
+ };
1295
+ }
1296
+ function Et(e) {
1297
+ return e.findIndex(([e]) => e === void 0);
1298
+ }
1299
+ //#endregion
1300
+ //#region src/plugins/finetune/state.ts
1301
+ var Dt = -100, Ot = 100, kt = 1, G = {
1302
+ brightness: 0,
1303
+ contrast: 0,
1304
+ saturation: 0,
1305
+ exposure: 0,
1306
+ clarity: 0,
1307
+ gamma: 0
1308
+ }, At = [
1309
+ {
1310
+ key: "brightness",
1311
+ label: "Brightness"
1312
+ },
1313
+ {
1314
+ key: "contrast",
1315
+ label: "Contrast"
1316
+ },
1317
+ {
1318
+ key: "saturation",
1319
+ label: "Saturation"
1320
+ },
1321
+ {
1322
+ key: "exposure",
1323
+ label: "Exposure"
1324
+ },
1325
+ {
1326
+ key: "clarity",
1327
+ label: "Clarity"
1328
+ },
1329
+ {
1330
+ key: "gamma",
1331
+ label: "Gamma"
1332
+ }
1130
1333
  ];
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"
1334
+ function jt() {
1335
+ return G;
1336
+ }
1337
+ function Mt(e) {
1338
+ return e.brightness === 0 && e.contrast === 0 && e.saturation === 0 && e.exposure === 0 && e.clarity === 0 && e.gamma === 0;
1339
+ }
1340
+ function Nt(e, t, n) {
1341
+ let r = It(n);
1342
+ return e[t] === r ? e : {
1343
+ ...e,
1344
+ [t]: r
1345
+ };
1346
+ }
1347
+ function Pt(e, t) {
1348
+ return e[t] === 0 ? e : {
1349
+ ...e,
1350
+ [t]: 0
1351
+ };
1352
+ }
1353
+ function Ft() {
1354
+ return G;
1355
+ }
1356
+ function It(e) {
1357
+ return Number.isNaN(e) ? 0 : e <= -100 ? Dt : e >= 100 ? 100 : Math.round(e / 1) * 1;
1358
+ }
1359
+ //#endregion
1360
+ //#region src/plugins/filter/presets.ts
1361
+ var Lt = [
1362
+ {
1363
+ id: "none",
1364
+ label: "None",
1365
+ state: G
1366
+ },
1367
+ {
1368
+ id: "vivid",
1369
+ label: "Vivid",
1370
+ state: {
1371
+ brightness: 0,
1372
+ contrast: 10,
1373
+ saturation: 40,
1374
+ exposure: 0,
1375
+ clarity: 5,
1376
+ gamma: 0
1377
+ }
1378
+ },
1379
+ {
1380
+ id: "mono",
1381
+ label: "Mono",
1382
+ state: {
1383
+ brightness: 0,
1384
+ contrast: 15,
1385
+ saturation: -100,
1386
+ exposure: 0,
1387
+ clarity: 0,
1388
+ gamma: 0
1389
+ }
1390
+ },
1391
+ {
1392
+ id: "soft",
1393
+ label: "Soft",
1394
+ state: {
1395
+ brightness: 5,
1396
+ contrast: -10,
1397
+ saturation: 0,
1398
+ exposure: 0,
1399
+ clarity: -25,
1400
+ gamma: 0
1401
+ }
1402
+ },
1403
+ {
1404
+ id: "punch",
1405
+ label: "Punch",
1406
+ state: {
1407
+ brightness: 0,
1408
+ contrast: 30,
1409
+ saturation: 5,
1410
+ exposure: 0,
1411
+ clarity: 25,
1412
+ gamma: 0
1413
+ }
1414
+ },
1415
+ {
1416
+ id: "mute",
1417
+ label: "Mute",
1418
+ state: {
1419
+ brightness: 0,
1420
+ contrast: 5,
1421
+ saturation: -50,
1422
+ exposure: 0,
1423
+ clarity: -5,
1424
+ gamma: 0
1425
+ }
1426
+ },
1427
+ {
1428
+ id: "bright",
1429
+ label: "Bright",
1430
+ state: {
1431
+ brightness: 5,
1432
+ contrast: 5,
1433
+ saturation: 0,
1434
+ exposure: 15,
1435
+ clarity: 0,
1436
+ gamma: 0
1437
+ }
1438
+ }
1230
1439
  ];
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
1440
+ function Rt(e, t) {
1441
+ 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;
1442
+ }
1443
+ function zt(e) {
1444
+ for (let t of Lt) if (Rt(t.state, e)) return t;
1445
+ }
1446
+ //#endregion
1447
+ //#region src/plugins/finetune/math.ts
1448
+ function Bt(e) {
1449
+ let t = new Uint8ClampedArray(256), n = e.brightness / 200, r = 1 + e.contrast / 100, i = 1 + e.exposure / 200, a = Vt(e.gamma);
1450
+ for (let e = 0; e < 256; e++) {
1451
+ let o = e / 255;
1452
+ 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);
1453
+ }
1454
+ return t;
1455
+ }
1456
+ function Vt(e) {
1457
+ return e === 0 ? 1 : e > 0 ? 1 - e / 100 * .5 : 1 + 1 * (-e / 100);
1458
+ }
1459
+ function Ht(e, t, n, r) {
1460
+ let i = e.length;
1461
+ if (t.length !== i) throw Error("applyFinetuneLutAndSaturation: src/dst length mismatch");
1462
+ let a = 1 + r.saturation / 100;
1463
+ if (a === 1) {
1464
+ 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];
1465
+ return;
1466
+ }
1467
+ for (let r = 0; r < i; r += 4) {
1468
+ 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;
1469
+ 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];
1470
+ }
1471
+ }
1472
+ function Ut(e, t, n) {
1473
+ if (n === 0) return;
1474
+ let r = e.length;
1475
+ if (t.length !== r) throw Error("applyClarity: dst/blurred length mismatch");
1476
+ let i = n / 100;
1477
+ for (let n = 0; n < r; n += 4) {
1478
+ 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]);
1479
+ 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;
1480
+ }
1481
+ }
1482
+ function Wt(e, t, n, r, i) {
1483
+ if (e.length !== t.length || e.length !== n.length) throw Error("boxBlur3x3: buffer length mismatch");
1484
+ for (let n = 0; n < i; n++) for (let i = 0; i < r; i++) {
1485
+ 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;
1486
+ 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];
1487
+ }
1488
+ for (let e = 0; e < i; e++) {
1489
+ let a = e === 0 ? 0 : e - 1, o = e === i - 1 ? i - 1 : e + 1;
1490
+ for (let i = 0; i < r; i++) {
1491
+ let s = (e * r + i) * 4, c = (a * r + i) * 4, l = (o * r + i) * 4;
1492
+ 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];
1493
+ }
1494
+ }
1495
+ }
1496
+ function K(e, t, n) {
1497
+ if (t.width !== n.width || t.height !== n.height || t.data.length !== n.data.length) throw Error("applyFinetuneToImageData: baseline/dst dimensions mismatch");
1498
+ let r = Bt(e);
1499
+ if (Ht(t.data, n.data, r, e), e.clarity !== 0) {
1500
+ let r = new Uint8ClampedArray(t.data.length), i = new Uint8ClampedArray(t.data.length);
1501
+ Wt(t.data, r, i, t.width, t.height), Ut(n.data, i, e.clarity);
1502
+ }
1503
+ }
1504
+ //#endregion
1505
+ //#region src/plugins/finetune/bake.ts
1506
+ async function Gt(n, r) {
1507
+ if (Mt(n)) return r;
1508
+ let i = e(r.width, r.height), a = t(i);
1509
+ a.imageSmoothingEnabled = !0, a.imageSmoothingQuality = "high", a.drawImage(r.bitmap, 0, 0, r.width, r.height);
1510
+ let o = a.getImageData(0, 0, r.width, r.height);
1511
+ if (n.clarity === 0) K(n, o, o), a.putImageData(o, 0, 0);
1512
+ else {
1513
+ let e = new ImageData(new Uint8ClampedArray(o.data.length), o.width, o.height);
1514
+ K(n, o, e), a.putImageData(e, 0, 0);
1515
+ }
1516
+ return {
1517
+ bitmap: i.canvas,
1518
+ width: r.width,
1519
+ height: r.height,
1520
+ mimeType: r.mimeType
1521
+ };
1522
+ }
1523
+ //#endregion
1524
+ //#region src/plugins/flip/state.ts
1525
+ function Kt() {
1526
+ return {
1527
+ horizontal: !1,
1528
+ vertical: !1
1529
+ };
1530
+ }
1531
+ function qt(e, t) {
1532
+ return t === "horizontal" ? {
1533
+ ...e,
1534
+ horizontal: !e.horizontal
1535
+ } : {
1536
+ ...e,
1537
+ vertical: !e.vertical
1538
+ };
1539
+ }
1540
+ function Jt(e) {
1541
+ return !e.horizontal && !e.vertical;
1542
+ }
1543
+ //#endregion
1544
+ //#region src/plugins/flip/bake.ts
1545
+ async function Yt(n, r) {
1546
+ if (Jt(n)) return r;
1547
+ 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;
1548
+ return s.setTransform(c, 0, 0, l, u, d), s.drawImage(r.bitmap, 0, 0), {
1549
+ bitmap: o.canvas,
1550
+ width: i,
1551
+ height: a,
1552
+ mimeType: r.mimeType
1553
+ };
1554
+ }
1555
+ //#endregion
1556
+ //#region src/plugins/frame/state.ts
1557
+ var Xt = [
1558
+ "none",
1559
+ "solidSharp",
1560
+ "solidRound",
1561
+ "lineSingle",
1562
+ "hook",
1563
+ "polaroid"
1564
+ ], Zt = [
1565
+ {
1566
+ id: "none",
1567
+ label: "None",
1568
+ acceptsColor: !1,
1569
+ defaultColor: "#000000"
1570
+ },
1571
+ {
1572
+ id: "solidSharp",
1573
+ label: "Mat Sharp",
1574
+ acceptsColor: !0,
1575
+ defaultColor: "#000000"
1576
+ },
1577
+ {
1578
+ id: "solidRound",
1579
+ label: "Mat Round",
1580
+ acceptsColor: !0,
1581
+ defaultColor: "#000000"
1582
+ },
1583
+ {
1584
+ id: "lineSingle",
1585
+ label: "Line Single",
1586
+ acceptsColor: !0,
1587
+ defaultColor: "#000000"
1588
+ },
1589
+ {
1590
+ id: "hook",
1591
+ label: "Corner Hooks",
1592
+ acceptsColor: !0,
1593
+ defaultColor: "#000000"
1594
+ },
1595
+ {
1596
+ id: "polaroid",
1597
+ label: "Polaroid",
1598
+ acceptsColor: !0,
1599
+ defaultColor: "#ffffff"
1600
+ }
1601
+ ], Qt = {
1602
+ presetId: "none",
1603
+ color: "#000000"
1975
1604
  };
1976
- //# sourceMappingURL=index.js.map
1605
+ function $t() {
1606
+ return Qt;
1607
+ }
1608
+ function en(e) {
1609
+ return e.presetId === "none";
1610
+ }
1611
+ function tn(e, t) {
1612
+ if (e.presetId === t) return e;
1613
+ let n = q(e.presetId), r = q(t);
1614
+ return r ? {
1615
+ presetId: t,
1616
+ color: n !== void 0 && e.color === n.defaultColor ? r.defaultColor : e.color
1617
+ } : {
1618
+ ...e,
1619
+ presetId: t
1620
+ };
1621
+ }
1622
+ function nn(e, t) {
1623
+ return e.color === t ? e : {
1624
+ ...e,
1625
+ color: t
1626
+ };
1627
+ }
1628
+ function q(e) {
1629
+ return Zt.find((t) => t.id === e);
1630
+ }
1631
+ //#endregion
1632
+ //#region src/plugins/frame/bake.ts
1633
+ async function rn(e, t) {
1634
+ return en(e) ? t : e.presetId === "polaroid" ? dn(e.color, t) : e.presetId === "none" ? t : an(e.presetId, e.color, t);
1635
+ }
1636
+ function an(n, r, i) {
1637
+ let a = e(i.width, i.height), o = t(a);
1638
+ return o.drawImage(i.bitmap, 0, 0, i.width, i.height), on(o, n, r, i.width, i.height), {
1639
+ bitmap: a.canvas,
1640
+ width: i.width,
1641
+ height: i.height,
1642
+ mimeType: i.mimeType
1643
+ };
1644
+ }
1645
+ function on(e, t, n, r, i) {
1646
+ switch (t) {
1647
+ case "solidSharp":
1648
+ sn(e, n, r, i);
1649
+ return;
1650
+ case "solidRound":
1651
+ cn(e, n, r, i);
1652
+ return;
1653
+ case "lineSingle":
1654
+ ln(e, n, r, i);
1655
+ return;
1656
+ case "hook":
1657
+ un(e, n, r, i);
1658
+ return;
1659
+ }
1660
+ }
1661
+ function sn(e, t, n, r) {
1662
+ let i = fn(n, r);
1663
+ 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();
1664
+ }
1665
+ function cn(e, t, n, r) {
1666
+ let i = fn(n, r);
1667
+ sn(e, t, n, r), e.save(), e.globalCompositeOperation = "destination-out", e.fillStyle = "#000", J(e, 0, 0, i, "tl"), J(e, n, 0, i, "tr"), J(e, 0, r, i, "bl"), J(e, n, r, i, "br"), e.restore();
1668
+ }
1669
+ function J(e, t, n, r, i) {
1670
+ switch (e.beginPath(), e.moveTo(t, n), i) {
1671
+ case "tl":
1672
+ e.lineTo(t + r, n), e.arc(t + r, n + r, r, -Math.PI / 2, Math.PI, !0), e.lineTo(t, n);
1673
+ break;
1674
+ case "tr":
1675
+ e.lineTo(t, n + r), e.arc(t - r, n + r, r, 0, -Math.PI / 2, !0), e.lineTo(t, n);
1676
+ break;
1677
+ case "bl":
1678
+ e.lineTo(t + r, n), e.arc(t + r, n - r, r, Math.PI / 2, Math.PI, !1), e.lineTo(t, n);
1679
+ break;
1680
+ case "br":
1681
+ e.lineTo(t - r, n), e.arc(t - r, n - r, r, Math.PI / 2, 0, !0), e.lineTo(t, n);
1682
+ break;
1683
+ }
1684
+ e.closePath(), e.fill();
1685
+ }
1686
+ function ln(e, t, n, r) {
1687
+ let i = Math.round(Math.min(n, r) * .05), a = Math.max(2, Math.round(Math.min(n, r) * .01));
1688
+ e.save(), e.strokeStyle = t, e.lineWidth = a;
1689
+ let o = a / 2;
1690
+ e.strokeRect(i + o, i + o, n - 2 * i - a, r - 2 * i - a), e.restore();
1691
+ }
1692
+ function un(e, t, n, r) {
1693
+ 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);
1694
+ e.save(), e.strokeStyle = t, e.lineWidth = a, e.lineCap = "square";
1695
+ let s = a / 2, c = (t, n, r, a) => {
1696
+ e.beginPath(), e.moveTo(t + r * i, n), e.lineTo(t, n), e.lineTo(t, n + a * i), e.stroke();
1697
+ };
1698
+ 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();
1699
+ }
1700
+ function dn(n, r) {
1701
+ 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);
1702
+ return f.fillStyle = n, f.fillRect(0, 0, l, u), f.drawImage(r.bitmap, o, a, r.width, r.height), {
1703
+ bitmap: d.canvas,
1704
+ width: l,
1705
+ height: u,
1706
+ mimeType: r.mimeType
1707
+ };
1708
+ }
1709
+ function fn(e, t) {
1710
+ return Math.max(4, Math.round(Math.min(e, t) * .04));
1711
+ }
1712
+ function pn(e, t, n) {
1713
+ if (e !== "polaroid") return {
1714
+ width: t,
1715
+ height: n
1716
+ };
1717
+ let r = Math.min(t, n), i = Math.round(r * .05), a = Math.round(r * .18);
1718
+ return {
1719
+ width: t + 2 * i,
1720
+ height: n + i + a
1721
+ };
1722
+ }
1723
+ //#endregion
1724
+ //#region src/plugins/redact/bake.ts
1725
+ async function mn(n, r) {
1726
+ if (n.regions.length === 0) return r;
1727
+ let i = e(r.width, r.height), a = t(i);
1728
+ a.drawImage(r.bitmap, 0, 0, r.width, r.height);
1729
+ for (let e of n.regions) hn(a, i.canvas, e, r);
1730
+ return {
1731
+ bitmap: i.canvas,
1732
+ width: r.width,
1733
+ height: r.height,
1734
+ mimeType: r.mimeType
1735
+ };
1736
+ }
1737
+ function hn(e, t, n, r) {
1738
+ let i = Math.round(n.width), a = Math.round(n.height);
1739
+ if (i < 1 || a < 1) return;
1740
+ let o = Math.round(n.x), s = Math.round(n.y);
1741
+ switch (n.mode) {
1742
+ case "solid":
1743
+ gn(e, n, o, s, i, a);
1744
+ return;
1745
+ case "pixelate":
1746
+ _n(e, t, r, o, s, i, a);
1747
+ return;
1748
+ case "blur":
1749
+ vn(e, t, r, o, s, i, a);
1750
+ return;
1751
+ }
1752
+ }
1753
+ function gn(e, t, n, r, i, a) {
1754
+ e.save(), e.fillStyle = t.color, e.fillRect(n, r, i, a), e.restore();
1755
+ }
1756
+ function _n(e, t, n, r, i, a, o) {
1757
+ 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));
1758
+ e.save();
1759
+ let d = Y(l, u);
1760
+ if (!d) {
1761
+ e.restore();
1762
+ return;
1763
+ }
1764
+ 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();
1765
+ }
1766
+ function vn(e, t, n, r, i, a, o) {
1767
+ let s = 1 / 8, c = Math.max(1, Math.round(a * s)), l = Math.max(1, Math.round(o * s)), u = Y(c, l);
1768
+ if (!u) return;
1769
+ u.ctx.imageSmoothingEnabled = !0, u.ctx.imageSmoothingQuality = "high", u.ctx.drawImage(t, r, i, a, o, 0, 0, c, l);
1770
+ let d = Math.max(1, Math.round(c * .5)), f = Math.max(1, Math.round(l * .5)), p = Y(d, f);
1771
+ if (!p) {
1772
+ e.save(), e.imageSmoothingEnabled = !0, e.imageSmoothingQuality = "high", e.drawImage(u.canvas, 0, 0, c, l, r, i, a, o), e.restore();
1773
+ return;
1774
+ }
1775
+ 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();
1776
+ }
1777
+ function Y(e, t) {
1778
+ if (typeof OffscreenCanvas < "u") try {
1779
+ let n = new OffscreenCanvas(e, t), r = n.getContext("2d");
1780
+ if (r) return {
1781
+ canvas: n,
1782
+ ctx: r
1783
+ };
1784
+ } catch {}
1785
+ if (typeof document > "u") return null;
1786
+ let n = document.createElement("canvas");
1787
+ n.width = e, n.height = t;
1788
+ let r = n.getContext("2d");
1789
+ return r ? {
1790
+ canvas: n,
1791
+ ctx: r
1792
+ } : null;
1793
+ }
1794
+ //#endregion
1795
+ //#region src/plugins/redact/state.ts
1796
+ var yn = [
1797
+ "pixelate",
1798
+ "blur",
1799
+ "solid"
1800
+ ], bn = "#000000", xn = "pixelate";
1801
+ function Sn(e) {
1802
+ return {
1803
+ regions: [],
1804
+ nextRegionNumber: 1,
1805
+ selectedId: null,
1806
+ currentMode: xn,
1807
+ currentColor: bn,
1808
+ imageSize: e.imageSize
1809
+ };
1810
+ }
1811
+ function Cn(e) {
1812
+ return {
1813
+ id: `r_${e.nextRegionNumber.toString(36)}`,
1814
+ nextRegionNumber: e.nextRegionNumber + 1
1815
+ };
1816
+ }
1817
+ function wn(e, t) {
1818
+ return {
1819
+ ...e,
1820
+ regions: [...e.regions, t],
1821
+ selectedId: t.id
1822
+ };
1823
+ }
1824
+ function X(e, t) {
1825
+ let n = !1, r = e.regions.map((e) => e.id === t.id ? (n = !0, t) : e);
1826
+ return n ? {
1827
+ ...e,
1828
+ regions: r
1829
+ } : e;
1830
+ }
1831
+ function Tn(e, t) {
1832
+ let n = e.regions.filter((e) => e.id !== t);
1833
+ return n.length === e.regions.length ? e : {
1834
+ ...e,
1835
+ regions: n,
1836
+ selectedId: e.selectedId === t ? null : e.selectedId
1837
+ };
1838
+ }
1839
+ function En(e, t, n) {
1840
+ if (e.regions.length === 0) return e;
1841
+ let r = e.regions.map((e) => t === "horizontal" ? {
1842
+ ...e,
1843
+ x: n.width - e.x - e.width
1844
+ } : {
1845
+ ...e,
1846
+ y: n.height - e.y - e.height
1847
+ });
1848
+ return {
1849
+ ...e,
1850
+ regions: r,
1851
+ imageSize: n
1852
+ };
1853
+ }
1854
+ function Dn(e, t, n, r) {
1855
+ if (e.regions.length === 0) return {
1856
+ ...e,
1857
+ imageSize: r
1858
+ };
1859
+ if (t === 0 && n === 0 && e.imageSize === r) return e;
1860
+ let i = e.regions.map((e) => ({
1861
+ ...e,
1862
+ x: e.x + t,
1863
+ y: e.y + n
1864
+ }));
1865
+ return {
1866
+ ...e,
1867
+ regions: i,
1868
+ imageSize: r
1869
+ };
1870
+ }
1871
+ function On(e, t, n) {
1872
+ if (t === 0 || e.regions.length === 0) return {
1873
+ ...e,
1874
+ imageSize: n
1875
+ };
1876
+ let r = e.imageSize.width, i = e.imageSize.height, a = e.regions.map((e) => {
1877
+ let { x: n, y: a, width: o, height: s } = e;
1878
+ return t === 1 ? {
1879
+ ...e,
1880
+ x: i - a - s,
1881
+ y: n,
1882
+ width: s,
1883
+ height: o
1884
+ } : t === 2 ? {
1885
+ ...e,
1886
+ x: r - n - o,
1887
+ y: i - a - s
1888
+ } : {
1889
+ ...e,
1890
+ x: a,
1891
+ y: r - n - o,
1892
+ width: s,
1893
+ height: o
1894
+ };
1895
+ });
1896
+ return {
1897
+ ...e,
1898
+ regions: a,
1899
+ imageSize: n
1900
+ };
1901
+ }
1902
+ function kn(e, t) {
1903
+ return e.selectedId === t ? e : {
1904
+ ...e,
1905
+ selectedId: t
1906
+ };
1907
+ }
1908
+ function An(e, t) {
1909
+ return e.currentMode === t ? e : {
1910
+ ...e,
1911
+ currentMode: t
1912
+ };
1913
+ }
1914
+ function jn(e, t) {
1915
+ return e.currentColor === t ? e : {
1916
+ ...e,
1917
+ currentColor: t
1918
+ };
1919
+ }
1920
+ function Mn(e, t, n) {
1921
+ let r = e.regions.find((e) => e.id === t);
1922
+ return !r || r.mode === n ? e : X(e, {
1923
+ ...r,
1924
+ mode: n
1925
+ });
1926
+ }
1927
+ function Nn(e, t, n) {
1928
+ let r = e.regions.find((e) => e.id === t);
1929
+ return !r || r.color === n ? e : X(e, {
1930
+ ...r,
1931
+ color: n
1932
+ });
1933
+ }
1934
+ function Pn(e, t) {
1935
+ if (t !== null) return e.regions.find((e) => e.id === t);
1936
+ }
1937
+ function Fn(e) {
1938
+ return e.selectedId === null ? null : e.regions.find((t) => t.id === e.selectedId) ?? null;
1939
+ }
1940
+ function In(e) {
1941
+ let { x: t, y: n, width: r, height: i } = e;
1942
+ return r < 0 && (t += r, r = -r), i < 0 && (n += i, i = -i), {
1943
+ x: t,
1944
+ y: n,
1945
+ width: r,
1946
+ height: i
1947
+ };
1948
+ }
1949
+ function Ln(e) {
1950
+ 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;
1951
+ return {
1952
+ id: i,
1953
+ x: Math.round(s - o / 2),
1954
+ y: Math.round(c - o / 2),
1955
+ width: o,
1956
+ height: o,
1957
+ mode: n,
1958
+ color: r
1959
+ };
1960
+ }
1961
+ function Rn(e, t) {
1962
+ if (e.imageSize.width === t.width && e.imageSize.height === t.height) return e;
1963
+ let n = [];
1964
+ 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(zn(r, t));
1965
+ let r = e.selectedId !== null && !n.some((t) => t.id === e.selectedId);
1966
+ return {
1967
+ ...e,
1968
+ regions: n,
1969
+ imageSize: {
1970
+ width: t.width,
1971
+ height: t.height
1972
+ },
1973
+ selectedId: r ? null : e.selectedId
1974
+ };
1975
+ }
1976
+ function zn(e, t) {
1977
+ 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);
1978
+ return {
1979
+ ...e,
1980
+ x: n,
1981
+ y: r,
1982
+ width: Math.max(0, i - n),
1983
+ height: Math.max(0, a - r)
1984
+ };
1985
+ }
1986
+ function Bn(e) {
1987
+ return {
1988
+ x: e.x,
1989
+ y: e.y,
1990
+ width: e.width,
1991
+ height: e.height
1992
+ };
1993
+ }
1994
+ //#endregion
1995
+ //#region src/plugins/resize/state.ts
1996
+ var Z = 8e3, Vn = 1;
1997
+ function Hn() {
1998
+ return {
1999
+ scaleX: 1,
2000
+ scaleY: 1,
2001
+ lockAspect: !0
2002
+ };
2003
+ }
2004
+ function Un(e) {
2005
+ return Math.abs(e.scaleX - 1) < 1e-9 && Math.abs(e.scaleY - 1) < 1e-9;
2006
+ }
2007
+ function Q(e, t) {
2008
+ return {
2009
+ width: $(Math.round(t.width * e.scaleX)),
2010
+ height: $(Math.round(t.height * e.scaleY))
2011
+ };
2012
+ }
2013
+ function Wn(e, t, n) {
2014
+ if (n.width <= 0) return e;
2015
+ let r = $(Math.round(t)) / n.width, i = e.lockAspect ? r : e.scaleY;
2016
+ return {
2017
+ ...e,
2018
+ scaleX: r,
2019
+ scaleY: i
2020
+ };
2021
+ }
2022
+ function Gn(e, t, n) {
2023
+ if (n.height <= 0) return e;
2024
+ let r = $(Math.round(t)) / n.height, i = e.lockAspect ? r : e.scaleX;
2025
+ return {
2026
+ ...e,
2027
+ scaleX: i,
2028
+ scaleY: r
2029
+ };
2030
+ }
2031
+ function Kn(e, t) {
2032
+ let n = Yn(t / 100);
2033
+ return {
2034
+ ...e,
2035
+ scaleX: n,
2036
+ scaleY: n
2037
+ };
2038
+ }
2039
+ function qn(e, t) {
2040
+ if (e.lockAspect === t) return e;
2041
+ if (!t) return {
2042
+ ...e,
2043
+ lockAspect: !1
2044
+ };
2045
+ let n = (e.scaleX + e.scaleY) / 2;
2046
+ return {
2047
+ scaleX: n,
2048
+ scaleY: n,
2049
+ lockAspect: !0
2050
+ };
2051
+ }
2052
+ function Jn(e) {
2053
+ let t = Math.max(e.scaleX, e.scaleY);
2054
+ return Math.round(t * 1e3) / 10;
2055
+ }
2056
+ function $(e) {
2057
+ return Number.isFinite(e) ? Math.max(1, Math.min(Z, Math.trunc(e))) : 1;
2058
+ }
2059
+ function Yn(e) {
2060
+ return !Number.isFinite(e) || e <= 0 ? .01 : Math.max(.01, Math.min(e, Z));
2061
+ }
2062
+ //#endregion
2063
+ //#region src/plugins/resize/bake.ts
2064
+ async function Xn(e, t) {
2065
+ if (Un(e)) return t;
2066
+ let { width: n, height: r } = Q(e, t);
2067
+ if (n <= 0 || r <= 0) return t;
2068
+ let i = Zn(t.width, t.height, n, r), a = {
2069
+ bitmap: t.bitmap,
2070
+ width: t.width,
2071
+ height: t.height
2072
+ }, o = [];
2073
+ for (let e = 0; e < i; e++) {
2074
+ let e = Math.max(n, Math.floor(a.width / 2)), t = Math.max(r, Math.floor(a.height / 2)), i = Qn(a, e, t);
2075
+ o.push(i), a = {
2076
+ bitmap: i.canvas,
2077
+ width: e,
2078
+ height: t
2079
+ };
2080
+ }
2081
+ let s = Qn(a, n, r);
2082
+ return o.length = 0, {
2083
+ bitmap: s.canvas,
2084
+ width: n,
2085
+ height: r,
2086
+ mimeType: t.mimeType
2087
+ };
2088
+ }
2089
+ function Zn(e, t, n, r) {
2090
+ let i = e, a = t, o = 0;
2091
+ for (; (i / 2 > n || a / 2 > r) && o < 16;) i = Math.floor(i / 2), a = Math.floor(a / 2), o += 1;
2092
+ return o;
2093
+ }
2094
+ function Qn(n, r, i) {
2095
+ let a = e(r, i), o = t(a);
2096
+ return o.imageSmoothingEnabled = !0, o.imageSmoothingQuality = "high", o.drawImage(n.bitmap, 0, 0, n.width, n.height, 0, 0, r, i), a;
2097
+ }
2098
+ //#endregion
2099
+ //#region src/plugins/rotate/inscribe.ts
2100
+ function $n(e, t) {
2101
+ let n = e.width, r = e.height;
2102
+ if (n <= 0 || r <= 0) return {
2103
+ width: 0,
2104
+ height: 0
2105
+ };
2106
+ 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 > er ? n * n / o : Infinity, l = s > er ? n * r / s : Infinity, u = Math.min(c, l);
2107
+ return {
2108
+ width: u,
2109
+ height: u * r / n
2110
+ };
2111
+ }
2112
+ var er = 1e-9, tr = -45, nr = 45, rr = .1;
2113
+ function ir() {
2114
+ return {
2115
+ quarterTurns: 0,
2116
+ freeAngle: 0
2117
+ };
2118
+ }
2119
+ function ar(e) {
2120
+ return {
2121
+ ...e,
2122
+ quarterTurns: (e.quarterTurns + 1) % 4
2123
+ };
2124
+ }
2125
+ function or(e) {
2126
+ return {
2127
+ ...e,
2128
+ quarterTurns: (e.quarterTurns + 3) % 4
2129
+ };
2130
+ }
2131
+ function sr(e, t) {
2132
+ let n = ur(t, -45, 45), r = Math.round(n * 10) / 10;
2133
+ return {
2134
+ ...e,
2135
+ freeAngle: r
2136
+ };
2137
+ }
2138
+ function cr(e) {
2139
+ return e.quarterTurns === 0 && Math.abs(e.freeAngle) < 1e-6;
2140
+ }
2141
+ function lr(e) {
2142
+ return e.quarterTurns * 90 + e.freeAngle;
2143
+ }
2144
+ function ur(e, t, n) {
2145
+ return Math.max(t, Math.min(n, e));
2146
+ }
2147
+ //#endregion
2148
+ //#region src/plugins/rotate/bake.ts
2149
+ async function dr(n, r) {
2150
+ if (cr(n)) return r;
2151
+ let i = lr(n), a = i * Math.PI / 180, o = i - n.quarterTurns * 90, s = Math.abs(o) < 1e-6, c, l;
2152
+ if (s) n.quarterTurns === 1 || n.quarterTurns === 3 ? (c = r.height, l = r.width) : (c = r.width, l = r.height);
2153
+ else {
2154
+ let e = $n(r, a);
2155
+ c = Math.max(1, Math.round(e.width)), l = Math.max(1, Math.round(e.height));
2156
+ }
2157
+ let u = e(c, l), d = t(u);
2158
+ 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), {
2159
+ bitmap: u.canvas,
2160
+ width: c,
2161
+ height: l,
2162
+ mimeType: r.mimeType
2163
+ };
2164
+ }
2165
+ //#endregion
2166
+ //#region src/state/store.ts
2167
+ function fr(e) {
2168
+ let t = e, n = /* @__PURE__ */ new Set();
2169
+ function r(e) {
2170
+ for (let r of [...n]) try {
2171
+ r(t, e);
2172
+ } catch (e) {
2173
+ queueMicrotask(() => {
2174
+ throw e;
2175
+ });
2176
+ }
2177
+ }
2178
+ return {
2179
+ get() {
2180
+ return t;
2181
+ },
2182
+ set(e) {
2183
+ let n = t;
2184
+ t = {
2185
+ ...t,
2186
+ ...e
2187
+ }, r(n);
2188
+ },
2189
+ update(e) {
2190
+ let n = t;
2191
+ t = {
2192
+ ...t,
2193
+ ...e(t)
2194
+ }, r(n);
2195
+ },
2196
+ subscribe(e) {
2197
+ return n.add(e), () => n.delete(e);
2198
+ }
2199
+ };
2200
+ }
2201
+ //#endregion
2202
+ export { pt as ALL_SELECTION_HANDLES, G as DEFAULT_FINETUNE_STATE, Qt as DEFAULT_FRAME_STATE, w as DEFAULT_OUTPUT_STATE, ze as DEFAULT_PALETTE_COLOR, bn as DEFAULT_REDACT_COLOR, xn as DEFAULT_REDACT_MODE, Be as DEFAULT_STROKE_WIDTH, me as ENCODABLE_MIMES, ne as EventBus, Lt as FILTER_PRESETS, At as FINETUNE_ADJUSTMENTS, Ot as FINETUNE_MAX, Dt as FINETUNE_MIN, kt as FINETUNE_STEP, Zt as FRAME_PRESETS, Xt as FRAME_PRESET_IDS, Le as FREEHAND_DEFAULT_STROKE, nr as FREE_ANGLE_MAX, tr as FREE_ANGLE_MIN, rr as FREE_ANGLE_STEP, Fe as HIGHLIGHT_DEFAULT_COLOR, Ie as HIGHLIGHT_DEFAULT_STROKE, ue as HISTORY_MAX_ENTRIES, de as History, l as IDENTITY_VIEWPORT_TRANSFORM, nt as KEYBOARD_PLACEABLE_KINDS, g as MAX_ZOOM, Ne as MIN_SAMPLE_DISTANCE, _ as MIN_ZOOM, gt as PICK_TOLERANCE, yn as REDACT_MODES, Z as RESIZE_MAX_DIMENSION, Vn as RESIZE_MIN_DIMENSION, at as SYSTEM_FONT_STACK, Re as TEXT_DEFAULT_FONT_SIZE, ee as ViewportController, wn as addRegion, qe as addShape, P as alignToOrigin, V as applyAspectRatio, Ut as applyClarity, Ht as applyFinetuneLutAndSaturation, K as applyFinetuneToImageData, Tt as applyPresetByIndex, A as assertNever, ot as bakeAnnotate, n as bakeCanvasToBlob, bt as bakeCrop, Gt as bakeFinetune, Yt as bakeFlip, rn as bakeFrame, mn as bakeRedact, Xn as bakeResize, dr as bakeRotate, M as boundingBoxOf, Wt as boxBlur3x3, Bt as buildFinetuneLut, a as canEncodeMime, T as clampQuality, b as clampRectInside, u as computeViewport, ve as copyJpegExif, e as createBakeCanvas, Ln as createCenteredRedactRegion, it as createCenteredShape, fr as createStore, Pe as decimatePoints, Ve as defaultStylePalette, Tn as deleteRedactRegion, Ye as deleteShape, Ee as deriveOutputName, lr as effectiveAngleDeg, Jn as effectivePercent, De as encodeSourceImage, N as estimateTextSize, xt as filterPresets, zt as findActivePreset, q as findFramePreset, Pn as findRedactRegion, Xe as findShape, Rt as finetuneStatesEqual, B as fitRectToBoundsWithRatio, pn as frameOutputSize, t as getBakeContext2D, F as hitTest, He as initialAnnotateState, wt as initialCropState, jt as initialFinetuneState, Kt as initialFlipState, $t as initialFrameState, Sn as initialRedactState, Hn as initialResizeState, ir as initialRotateState, Mt as isFinetuneNoOp, Jt as isFlipNoOp, en as isFrameNoOp, rt as isKeyboardPlaceableKind, W as isPresetVisible, Un as isResizeNoOp, cr as isRotateNoOp, $n as largestInscribedRect, o as loadImage, Cn as mintRegionId, Ue as mintShapeId, En as mirrorRedactRegions, $e as mirrorShape, Ze as normaliseRectExtent, In as normaliseRedactExtent, on as paintInsideFrame, hn as paintRedactRegion, j as paintShape, _t as pickShape, p as pointDisplayToImage, f as pointImageToDisplay, se as pointInRect, ae as rectBottom, oe as rectCenter, h as rectDisplayToImage, ht as rectFromHandleDrag, re as rectFromPoints, m as rectImageToDisplay, ie as rectRight, ce as rectsEqual, Bn as regionBoundingBox, X as replaceRedactRegion, Je as replaceShape, Ft as resetAllFinetune, Pt as resetFinetune, St as resizeRectFromHandle, Te as resolveOutputMime, Q as resolveOutputSize, Rn as revalidateRedactAgainstBounds, ar as rotateClockwise, or as rotateCounterClockwise, On as rotateRedactRegions, et as rotateShape, x as roundRect, Me as runUtilityChain, kn as selectRedactRegion, Ke as selectShape, Fn as selectedRedactRegionOf, mt as selectionHandlePositions, We as setActiveTool, Nt as setFinetune, nn as setFrameColor, tn as setFramePreset, sr as setFreeAngle, Gn as setHeightPx, qn as setLockAspect, he as setOutputMime, ge as setOutputQuality, Kn as setPercent, jn as setRedactCurrentColor, An as setRedactCurrentMode, Nn as setRedactRegionColor, Mn as setRedactRegionMode, _e as setStripMetadata, Ge as setStyle, Wn as setWidthPx, qt as toggleFlip, k as tracePath, tt as transformShapes, le as translateClampedRect, Dn as translateRedactRegions, Qe as translateShape };
2203
+
2204
+ //# sourceMappingURL=index.js.map