@ingcreators/annot-annotator 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,317 +1,953 @@
1
- import { Resvg as b } from "@resvg/resvg-js";
2
- import { DOMParser as w, XMLSerializer as B } from "@xmldom/xmldom";
3
- const S = "1", N = "data-annot-version";
4
- function T(e) {
5
- if (!e || e.trim().length === 0)
6
- return "";
7
- const t = new w();
8
- let r;
9
- try {
10
- r = t.parseFromString(e, "image/svg+xml");
11
- } catch {
12
- return "";
13
- }
14
- const n = r.documentElement;
15
- if (!n) return "";
16
- const o = new B();
17
- let i = "";
18
- for (let d = 0; d < n.childNodes.length; d++) {
19
- const f = n.childNodes.item(d);
20
- if (!f || f.nodeType !== 1) continue;
21
- const s = f, p = s.localName ?? s.tagName ?? "";
22
- if (p === "defs") {
23
- const c = A(s);
24
- c !== null && (i += o.serializeToString(c));
25
- continue;
26
- }
27
- if (!(p === "image" && !s.getAttribute("data-redact-style")) && s.getAttribute("id") !== "ui-overlay") {
28
- if (s.getAttribute("id") === "annotations") {
29
- for (let c = 0; c < s.childNodes.length; c++) {
30
- const u = s.childNodes.item(c);
31
- u && u.nodeType === 1 && (i += o.serializeToString(u));
32
- }
33
- continue;
34
- }
35
- i += o.serializeToString(s);
36
- }
37
- }
38
- return i;
39
- }
40
- function A(e) {
41
- const t = e.cloneNode(!0);
42
- for (let r = t.childNodes.length - 1; r >= 0; r--) {
43
- const n = t.childNodes.item(r);
44
- if (!n || n.nodeType !== 1) continue;
45
- const o = n;
46
- (o.localName ?? o.tagName ?? "") === "style" && o.hasAttribute("data-annot-fonts") && t.removeChild(n);
47
- }
48
- return t.childNodes.length === 0 ? null : t;
49
- }
50
- function H(e = {}) {
51
- const t = {
52
- loadSystemFonts: e.loadSystemFonts ?? !1,
53
- ...e.fontFiles ? { fontFiles: e.fontFiles } : {},
54
- ...e.fontDirs ? { fontDirs: e.fontDirs } : {},
55
- ...e.defaultFontFamily ? { defaultFontFamily: e.defaultFontFamily } : {}
56
- };
57
- return {
58
- toSvg(r) {
59
- return m(r);
60
- },
61
- toPng(r) {
62
- const n = m(r);
63
- return new b(n, {
64
- fitTo: { mode: "width", value: r.width },
65
- background: "rgba(0, 0, 0, 0)",
66
- font: t
67
- }).render().asPng();
68
- }
69
- };
70
- }
71
- function m(e) {
72
- const t = "http://www.w3.org/2000/svg", r = "http://www.w3.org/1999/xlink", n = T(e.annotationsSvg);
73
- return `<svg xmlns="${t}" xmlns:xlink="${r}" ${N}="${S}" width="${e.width}" height="${e.height}" viewBox="0 0 ${e.width} ${e.height}"><image href="${e.originalDataUrl}" width="${e.width}" height="${e.height}"/>` + n + "</svg>";
74
- }
75
- const K = {
76
- BBox: {
77
- type: "object",
78
- required: ["x", "y", "width", "height"],
79
- additionalProperties: !1,
80
- properties: {
81
- x: { type: "number" },
82
- y: { type: "number" },
83
- width: { type: "number", minimum: 0 },
84
- height: { type: "number", minimum: 0 }
85
- }
86
- },
87
- Point: {
88
- type: "object",
89
- required: ["x", "y"],
90
- additionalProperties: !1,
91
- properties: {
92
- x: { type: "number" },
93
- y: { type: "number" }
94
- }
95
- },
96
- Intent: {
97
- type: "string",
98
- enum: ["info", "warning", "error", "success", "neutral"]
99
- },
100
- AnnotationStyle: {
101
- type: "object",
102
- additionalProperties: !1,
103
- properties: {
104
- intent: { $ref: "#/$defs/Intent" },
105
- stroke: { type: "string" },
106
- strokeWidth: { type: "number", minimum: 0 },
107
- fill: { type: "string" },
108
- color: { type: "string" }
109
- }
110
- }
111
- }, F = {
112
- type: "object",
113
- required: ["type", "bbox"],
114
- additionalProperties: !1,
115
- properties: {
116
- type: { const: "rect" },
117
- bbox: { $ref: "#/$defs/BBox" },
118
- intent: { $ref: "#/$defs/Intent" },
119
- stroke: { type: "string" },
120
- strokeWidth: { type: "number", minimum: 0 },
121
- fill: { type: "string" },
122
- color: { type: "string" }
123
- }
124
- }, v = {
125
- type: "object",
126
- required: ["type", "center", "radius"],
127
- additionalProperties: !1,
128
- properties: {
129
- type: { const: "circle" },
130
- center: { $ref: "#/$defs/Point" },
131
- radius: { type: "number", minimum: 0 },
132
- intent: { $ref: "#/$defs/Intent" },
133
- stroke: { type: "string" },
134
- strokeWidth: { type: "number", minimum: 0 },
135
- fill: { type: "string" },
136
- color: { type: "string" }
137
- }
138
- }, O = {
139
- type: "object",
140
- required: ["type", "from", "to"],
141
- additionalProperties: !1,
142
- properties: {
143
- type: { const: "arrow" },
144
- from: { $ref: "#/$defs/Point" },
145
- to: { $ref: "#/$defs/Point" },
146
- intent: { $ref: "#/$defs/Intent" },
147
- stroke: { type: "string" },
148
- strokeWidth: { type: "number", minimum: 0 },
149
- color: { type: "string" }
150
- }
151
- }, W = {
152
- type: "object",
153
- required: ["type", "at", "content"],
154
- additionalProperties: !1,
155
- properties: {
156
- type: { const: "text" },
157
- at: { $ref: "#/$defs/Point" },
158
- content: { type: "string" },
159
- fontSize: { type: "number", minimum: 0 },
160
- anchor: { type: "string", enum: ["start", "middle", "end"] },
161
- intent: { $ref: "#/$defs/Intent" },
162
- color: { type: "string" }
163
- }
164
- }, P = {
165
- type: "object",
166
- required: ["type", "at", "targetBbox", "content"],
167
- additionalProperties: !1,
168
- properties: {
169
- type: { const: "callout" },
170
- at: { $ref: "#/$defs/Point" },
171
- targetBbox: { $ref: "#/$defs/BBox" },
172
- content: { type: "string" },
173
- intent: { $ref: "#/$defs/Intent" },
174
- stroke: { type: "string" },
175
- color: { type: "string" }
176
- }
177
- }, I = {
178
- type: "object",
179
- required: ["type", "svgFragment"],
180
- additionalProperties: !1,
181
- properties: {
182
- type: { const: "raw" },
183
- svgFragment: { type: "string" }
184
- }
185
- }, Y = {
186
- oneOf: [F, v, O, W, P, I]
187
- }, J = {
188
- type: "object",
189
- required: ["bbox"],
190
- additionalProperties: !1,
191
- properties: {
192
- bbox: { $ref: "#/$defs/BBox" },
193
- style: { type: "string", enum: ["solid", "mosaic", "blur"] },
194
- color: { type: "string" }
195
- }
196
- };
197
- function $(e, t = {}) {
198
- const r = t.stroke ?? "red", n = t.strokeWidth ?? 2, o = t.fill ?? "none";
199
- return `<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${l(o)}" stroke="${l(r)}" stroke-width="${n}"/>`;
200
- }
201
- function k(e, t, r = {}) {
202
- const n = r.color ?? "red", o = r.strokeWidth ?? 2, i = `annot-arrow-${_()}`;
203
- return `<defs><marker id="${i}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto" markerUnits="strokeWidth"><path d="M 0 0 L 10 5 L 0 10 z" fill="${l(n)}"/></marker></defs><line x1="${e.x}" y1="${e.y}" x2="${t.x}" y2="${t.y}" stroke="${l(n)}" stroke-width="${o}" marker-end="url(#${i})"/>`;
204
- }
205
- function x(e, t, r = {}) {
206
- const n = r.color ?? "red", o = r.fontSize ?? 14, i = r.anchor ?? "start";
207
- return `<text x="${e.x}" y="${e.y}" fill="${l(n)}" font-size="${o}" text-anchor="${i}">` + E(t) + "</text>";
208
- }
209
- let g = 0;
210
- function _() {
211
- return g = g + 1 | 0, g;
212
- }
213
- function l(e) {
214
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
215
- }
216
- function E(e) {
217
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
218
- }
219
- const R = {
220
- info: { stroke: "#3b82f6", fill: "rgba(59, 130, 246, 0.12)", text: "#1e40af" },
221
- warning: { stroke: "#f59e0b", fill: "rgba(245, 158, 11, 0.12)", text: "#92400e" },
222
- error: { stroke: "#ef4444", fill: "rgba(239, 68, 68, 0.12)", text: "#991b1b" },
223
- success: { stroke: "#10b981", fill: "rgba(16, 185, 129, 0.12)", text: "#065f46" },
224
- neutral: { stroke: "#6b7280", fill: "rgba(107, 114, 128, 0.12)", text: "#374151" }
225
- }, z = "error";
226
- function a(e) {
227
- const t = e.intent ?? z, r = R[t];
228
- return {
229
- stroke: e.stroke ?? r.stroke,
230
- fill: e.fill ?? "none",
231
- text: e.color ?? r.text
232
- };
233
- }
234
- function Q(e) {
235
- return e.map(j).join("");
236
- }
237
- function j(e) {
238
- switch (e.type) {
239
- case "rect":
240
- return q(e);
241
- case "circle":
242
- return C(e);
243
- case "arrow":
244
- return X(e);
245
- case "text":
246
- return D(e);
247
- case "callout":
248
- return L(e);
249
- case "raw":
250
- return M(e);
251
- }
252
- }
253
- function q(e) {
254
- const t = a(e);
255
- return $(e.bbox, {
256
- stroke: t.stroke,
257
- strokeWidth: e.strokeWidth ?? 2,
258
- fill: t.fill
259
- });
260
- }
261
- function C(e) {
262
- const t = a(e), r = e.strokeWidth ?? 2;
263
- return `<circle cx="${e.center.x}" cy="${e.center.y}" r="${e.radius}" fill="${y(t.fill)}" stroke="${y(t.stroke)}" stroke-width="${r}"/>`;
1
+ import { Resvg as e } from "@resvg/resvg-js";
2
+ import { createCanvas as t, loadImage as n } from "@napi-rs/canvas";
3
+ import { deflate as r } from "pako";
4
+ import { DOMParser as i, XMLSerializer as a } from "@xmldom/xmldom";
5
+ //#region ../core/src/editor/svg-format.ts
6
+ var o = "data-annot-version", s = "annot", c = "https://ingcreators.com/annot/ns/1.0/";
7
+ new TextEncoder().encode("http://ns.adobe.com/xap/1.0/\0"), new TextEncoder().encode("annot:OriginalImage\0");
8
+ var l = new TextEncoder().encode("XML:com.adobe.xmp");
9
+ function u(e, t, n, r) {
10
+ let i = r && Object.keys(r).length > 0 ? JSON.stringify(r) : "";
11
+ return `<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
12
+ <x:xmpmeta xmlns:x="adobe:ns:meta/">
13
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
14
+ <rdf:Description rdf:about=""
15
+ xmlns:${s}="${c}">
16
+ <${s}:annotations><![CDATA[${e}]]></${s}:annotations>
17
+ <${s}:width>${t}</${s}:width>
18
+ <${s}:height>${n}</${s}:height>
19
+ <${s}:version>1.0</${s}:version>${i ? `\n <${s}:tags>${i}</${s}:tags>` : ""}
20
+ </rdf:Description>
21
+ </rdf:RDF>
22
+ </x:xmpmeta>
23
+ <?xpacket end="w"?>`;
264
24
  }
265
- function X(e) {
266
- const t = a(e);
267
- return k(e.from, e.to, {
268
- color: t.stroke,
269
- strokeWidth: e.strokeWidth ?? 2
270
- });
271
- }
272
- function D(e) {
273
- const t = a(e);
274
- return x(e.at, e.content, {
275
- color: t.text,
276
- fontSize: e.fontSize ?? 14,
277
- anchor: e.anchor ?? "start"
278
- });
279
- }
280
- function L(e) {
281
- const t = a(e), r = e.targetBbox, n = U(r, e.at);
282
- return $(r, {
283
- stroke: t.stroke,
284
- strokeWidth: e.strokeWidth ?? 2,
285
- fill: t.fill
286
- }) + k(e.at, n, {
287
- color: t.stroke,
288
- strokeWidth: 2
289
- }) + x(e.at, e.content, {
290
- color: t.text,
291
- fontSize: 14,
292
- anchor: "start"
293
- });
294
- }
295
- function M(e) {
296
- return e.svgFragment;
297
- }
298
- function U(e, t) {
299
- const r = h(t.x, e.x, e.x + e.width), n = h(t.y, e.y, e.y + e.height);
300
- return { x: r, y: n };
301
- }
302
- function h(e, t, r) {
303
- return Math.min(Math.max(e, t), r);
25
+ function d(e) {
26
+ return new Uint8Array([
27
+ e >> 24 & 255,
28
+ e >> 16 & 255,
29
+ e >> 8 & 255,
30
+ e & 255
31
+ ]);
32
+ }
33
+ function f(e, t) {
34
+ return (e[t] << 24 | e[t + 1] << 16 | e[t + 2] << 8 | e[t + 3]) >>> 0;
35
+ }
36
+ function p(...e) {
37
+ let t = 0;
38
+ for (let n of e) t += n.length;
39
+ let n = new Uint8Array(t), r = 0;
40
+ for (let t of e) n.set(t, r), r += t.length;
41
+ return n;
42
+ }
43
+ function m(e, t, n) {
44
+ if (t + n.length > e.length) return !1;
45
+ for (let r = 0; r < n.length; r++) if (e[t + r] !== n[r]) return !1;
46
+ return !0;
47
+ }
48
+ function h(e) {
49
+ let t = e.split(",")[1] || "", n = atob(t), r = new Uint8Array(n.length);
50
+ for (let e = 0; e < n.length; e++) r[e] = n.charCodeAt(e);
51
+ return r;
52
+ }
53
+ var g = (() => {
54
+ let e = new Uint32Array(256);
55
+ for (let t = 0; t < 256; t++) {
56
+ let n = t;
57
+ for (let e = 0; e < 8; e++) n & 1 ? n = 3988292384 ^ n >>> 1 : n >>>= 1;
58
+ e[t] = n;
59
+ }
60
+ return e;
61
+ })();
62
+ function _(e) {
63
+ let t = 4294967295;
64
+ for (let n = 0; n < e.length; n++) t = g[(t ^ e[n]) & 255] ^ t >>> 8;
65
+ return (t ^ 4294967295) >>> 0;
66
+ }
67
+ function v(e, t) {
68
+ let n = p(e, t), r = _(n);
69
+ return p(d(t.length), n, d(r));
304
70
  }
305
71
  function y(e) {
306
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
307
- }
308
- export {
309
- Y as BBOX_ANNOTATION_SCHEMA,
310
- J as BBOX_REDACT_REGION_SCHEMA,
311
- K as SHARED_DEFS,
312
- k as arrowBetween,
313
- Q as bboxAnnotationsToSvg,
314
- H as createAnnotator,
315
- $ as rectForBoundingBox,
316
- x as textAt
72
+ let t = p(l, new Uint8Array([
73
+ 0,
74
+ 0,
75
+ 0,
76
+ 0,
77
+ 0
78
+ ]), e);
79
+ return v(new TextEncoder().encode("iTXt"), t);
80
+ }
81
+ function b(e) {
82
+ let t = [e.slice(0, 8)], n = 8;
83
+ for (; n + 12 <= e.length;) {
84
+ let r = f(e, n), i = e.slice(n + 4, n + 8), a = n + 8, o = a + r + 4;
85
+ if (o > e.length) break;
86
+ let s = String.fromCharCode(...i);
87
+ !(s === "iTXt" && m(e, a, l)) && s !== "svGo" && t.push(e.slice(n, o)), n = o;
88
+ }
89
+ return p(...t);
90
+ }
91
+ function x(e, t, n) {
92
+ let r = y(t), i = v(new TextEncoder().encode("svGo"), n), a = b(e), o = a.length - 12;
93
+ return p(a.slice(0, o), r, i, a.slice(o));
94
+ }
95
+ function S(e) {
96
+ let t = u(e.annotationsSvg, e.width, e.height, e.tags), n = new TextEncoder().encode(t), r = typeof e.originalImage == "string" ? h(e.originalImage) : e.originalImage;
97
+ return x(e.renderedPng, n, r);
98
+ }
99
+ //#endregion
100
+ //#region ../core/src/encode/options.ts
101
+ var C = {
102
+ light: 1280,
103
+ standard: 1920,
104
+ highQuality: 2560,
105
+ original: null
106
+ }, w = {
107
+ light: "Light (1280px)",
108
+ standard: "Standard (1920px)",
109
+ highQuality: "High Quality (2560px)",
110
+ original: "Original"
111
+ }, T = {
112
+ format: "smart",
113
+ smartFallback: "png",
114
+ smartColorThreshold: 15e3,
115
+ jpegPercent: 92,
116
+ saveSizePreset: "standard",
117
+ quantizer: "median-cut"
118
+ };
119
+ function E(e, t, n) {
120
+ let r = C[n];
121
+ if (r === null || e <= r) return {
122
+ width: e,
123
+ height: t,
124
+ scaled: !1
125
+ };
126
+ let i = r / e;
127
+ return {
128
+ width: r,
129
+ height: Math.max(1, Math.round(t * i)),
130
+ scaled: !0
131
+ };
132
+ }
133
+ //#endregion
134
+ //#region ../core/src/encode/png8.ts
135
+ var D = new Uint8Array([
136
+ 137,
137
+ 80,
138
+ 78,
139
+ 71,
140
+ 13,
141
+ 10,
142
+ 26,
143
+ 10
144
+ ]), O = (() => {
145
+ let e = new Uint32Array(256);
146
+ for (let t = 0; t < 256; t++) {
147
+ let n = t;
148
+ for (let e = 0; e < 8; e++) n = n & 1 ? 3988292384 ^ n >>> 1 : n >>> 1;
149
+ e[t] = n >>> 0;
150
+ }
151
+ return e;
152
+ })();
153
+ function k(e) {
154
+ let t = 4294967295;
155
+ for (let n = 0; n < e.length; n++) t = O[(t ^ e[n]) & 255] ^ t >>> 8;
156
+ return (t ^ 4294967295) >>> 0;
157
+ }
158
+ function A(e, t) {
159
+ let n = new Uint8Array(12 + t.length), r = new DataView(n.buffer);
160
+ r.setUint32(0, t.length, !1);
161
+ for (let t = 0; t < 4; t++) n[4 + t] = e.charCodeAt(t);
162
+ n.set(t, 8);
163
+ let i = n.subarray(4, 8 + t.length);
164
+ return r.setUint32(8 + t.length, k(i), !1), n;
165
+ }
166
+ function j(e, t, n, i, a = 9) {
167
+ if (n <= 0 || i <= 0) throw Error("encodePng8: invalid dimensions");
168
+ if (e.length % 4 != 0) throw Error("encodePng8: palette must be RGBA bytes (multiple of 4)");
169
+ let o = e.length >>> 2;
170
+ if (o < 1 || o > 256) throw Error(`encodePng8: palette must have 1–256 colors, got ${o}`);
171
+ if (t.length !== n * i) throw Error(`encodePng8: indices length ${t.length} != width*height ${n * i}`);
172
+ let s = new Uint8Array(13), c = new DataView(s.buffer);
173
+ c.setUint32(0, n, !1), c.setUint32(4, i, !1), s[8] = 8, s[9] = 3, s[10] = 0, s[11] = 0, s[12] = 0;
174
+ let l = new Uint8Array(o * 3), u = !1, d = -1;
175
+ for (let t = 0; t < o; t++) l[t * 3] = e[t * 4], l[t * 3 + 1] = e[t * 4 + 1], l[t * 3 + 2] = e[t * 4 + 2], e[t * 4 + 3] < 255 && (u = !0, d = t);
176
+ let f = null;
177
+ if (u) {
178
+ f = new Uint8Array(d + 1);
179
+ for (let t = 0; t <= d; t++) f[t] = e[t * 4 + 3];
180
+ }
181
+ let p = n + 1, m = new Uint8Array(p * i);
182
+ for (let e = 0; e < i; e++) {
183
+ let r = e * p;
184
+ m[r] = 0, m.set(t.subarray(e * n, e * n + n), r + 1);
185
+ }
186
+ let h = r(m, {
187
+ level: a,
188
+ memLevel: 9,
189
+ windowBits: 15
190
+ }), g = [
191
+ D,
192
+ A("IHDR", s),
193
+ A("PLTE", l)
194
+ ];
195
+ f && g.push(A("tRNS", f)), g.push(A("IDAT", h)), g.push(A("IEND", new Uint8Array()));
196
+ let _ = 0;
197
+ for (let e of g) _ += e.length;
198
+ let v = new Uint8Array(_), y = 0;
199
+ for (let e of g) v.set(e, y), y += e.length;
200
+ return v;
201
+ }
202
+ //#endregion
203
+ //#region ../core/src/encode/quantize-median-cut.ts
204
+ function M(e, t, n, r) {
205
+ if (!Number.isInteger(t) || t <= 0) throw Error(`quantizeMedianCut: invalid width ${t}`);
206
+ if (!Number.isInteger(n) || n <= 0) throw Error(`quantizeMedianCut: invalid height ${n}`);
207
+ let i = t * n * 4;
208
+ if (e.length !== i) throw Error(`quantizeMedianCut: rgba length ${e.length} != width*height*4 = ${i}`);
209
+ let a = Math.max(1, Math.min(256, Math.floor(r))), { opaqueSamples: o, hasTransparent: s, transparentCount: c } = P(e), l = F(o, s ? Math.max(1, a - 1) : a), u = l.length, d = u + +!!s, f = new Uint8Array(d * 4), p = 0;
210
+ s && (f[0] = 0, f[1] = 0, f[2] = 0, f[3] = 0, p = 1);
211
+ let m = p * 4;
212
+ for (let e = 0; e < u; e++) {
213
+ let t = l[e], n = (p + e) * 4;
214
+ f[n] = t.rMean, f[n + 1] = t.gMean, f[n + 2] = t.bMean, f[n + 3] = 255;
215
+ }
216
+ return {
217
+ palette: f,
218
+ indices: te(e, t, n, f, m, s, c > 0)
219
+ };
220
+ }
221
+ var N = 16;
222
+ function P(e) {
223
+ let t = /* @__PURE__ */ new Map(), n = 0, r = e.length;
224
+ for (let i = 0; i < r; i += 4) {
225
+ if (e[i + 3] < N) {
226
+ n++;
227
+ continue;
228
+ }
229
+ let r = e[i], a = e[i + 1], o = e[i + 2], s = r << 16 | a << 8 | o;
230
+ t.set(s, (t.get(s) ?? 0) + 1);
231
+ }
232
+ let i = Array(t.size), a = 0;
233
+ for (let [e, n] of t) i[a++] = {
234
+ r: e >>> 16 & 255,
235
+ g: e >>> 8 & 255,
236
+ b: e & 255,
237
+ count: n
238
+ };
239
+ return {
240
+ opaqueSamples: i,
241
+ hasTransparent: n > 0,
242
+ transparentCount: n
243
+ };
244
+ }
245
+ function F(e, t) {
246
+ if (e.length === 0) return [];
247
+ if (t <= 1) return [I(e, 0, e.length, 0)];
248
+ let n = [I(e, 0, e.length, 0)], r = 1;
249
+ for (; n.length < t;) {
250
+ let t = -1, i = -1, a = Infinity;
251
+ for (let e = 0; e < n.length; e++) {
252
+ let r = n[e];
253
+ r.end - r.start < 2 || (r.priority > i || r.priority === i && r.insertOrder < a) && (i = r.priority, a = r.insertOrder, t = e);
254
+ }
255
+ if (t < 0) break;
256
+ let o = n[t], s = o.rMax - o.rMin, c = o.gMax - o.gMin, l = o.bMax - o.bMin, u;
257
+ u = s >= c && s >= l ? 0 : c >= l ? 1 : 2, ee(e, o.start, o.end, u);
258
+ let d = o.population >>> 1, f = 0, p = o.start + 1;
259
+ for (let t = o.start; t < o.end; t++) if (f += e[t].count, f >= d) {
260
+ p = t + 1;
261
+ break;
262
+ }
263
+ p <= o.start && (p = o.start + 1), p >= o.end && (p = o.end - 1);
264
+ let m = I(e, o.start, p, r++), h = I(e, p, o.end, r++);
265
+ n[t] = m, n.push(h);
266
+ }
267
+ return n;
268
+ }
269
+ function I(e, t, n, r) {
270
+ let i = 255, a = 0, o = 255, s = 0, c = 255, l = 0, u = 0, d = 0, f = 0, p = 0;
271
+ for (let r = t; r < n; r++) {
272
+ let t = e[r];
273
+ t.r < i && (i = t.r), t.r > a && (a = t.r), t.g < o && (o = t.g), t.g > s && (s = t.g), t.b < c && (c = t.b), t.b > l && (l = t.b), u += t.count, d += t.r * t.count, f += t.g * t.count, p += t.b * t.count;
274
+ }
275
+ let m = Math.max(a - i, s - o, l - c), h = u > 0 ? u : 1;
276
+ return {
277
+ start: t,
278
+ end: n,
279
+ rMin: i,
280
+ rMax: a,
281
+ gMin: o,
282
+ gMax: s,
283
+ bMin: c,
284
+ bMax: l,
285
+ population: u,
286
+ rMean: Math.round(d / h),
287
+ gMean: Math.round(f / h),
288
+ bMean: Math.round(p / h),
289
+ priority: u * m,
290
+ insertOrder: r
291
+ };
292
+ }
293
+ function ee(e, t, n, r) {
294
+ let i = e.slice(t, n);
295
+ r === 0 ? i.sort((e, t) => e.r - t.r) : r === 1 ? i.sort((e, t) => e.g - t.g) : i.sort((e, t) => e.b - t.b);
296
+ for (let n = 0; n < i.length; n++) e[t + n] = i[n];
297
+ }
298
+ function te(e, t, n, r, i, a, o) {
299
+ let s = t * n, c = new Uint8Array(s), l = new Float32Array(t), u = new Float32Array(t), d = new Float32Array(t), f = new Float32Array(t), p = new Float32Array(t), m = new Float32Array(t), h = r.length - i >>> 2, g = new Int32Array(h), _ = new Int32Array(h), v = new Int32Array(h);
300
+ for (let e = 0; e < h; e++) {
301
+ let t = i + e * 4;
302
+ g[e] = r[t], _[e] = r[t + 1], v[e] = r[t + 2];
303
+ }
304
+ let y = +!!a, b = /* @__PURE__ */ new Map();
305
+ for (let r = 0; r < n; r++) {
306
+ f.fill(0), p.fill(0), m.fill(0);
307
+ for (let n = 0; n < t; n++) {
308
+ let i = r * t + n, o = i * 4, s = e[o + 3];
309
+ if (a && s < N) {
310
+ c[i] = 0;
311
+ continue;
312
+ }
313
+ let x = e[o] + l[n], S = e[o + 1] + u[n], C = e[o + 2] + d[n], w = x < 0 ? 0 : x > 255 ? 255 : x + .5 | 0, T = S < 0 ? 0 : S > 255 ? 255 : S + .5 | 0, E = C < 0 ? 0 : C > 255 ? 255 : C + .5 | 0, D = w << 16 | T << 8 | E, O = b.get(D);
314
+ if (O === void 0) {
315
+ let e = Infinity;
316
+ O = 0;
317
+ for (let t = 0; t < h; t++) {
318
+ let n = x - g[t], r = S - _[t], i = C - v[t], a = n * n + r * r + i * i;
319
+ a < e && (e = a, O = t);
320
+ }
321
+ b.set(D, O);
322
+ }
323
+ c[i] = y + O;
324
+ let k = x - g[O], A = S - _[O], j = C - v[O];
325
+ n + 1 < t && (l[n + 1] = (l[n + 1] ?? 0) + k * 7 / 16, u[n + 1] = (u[n + 1] ?? 0) + A * 7 / 16, d[n + 1] = (d[n + 1] ?? 0) + j * 7 / 16), n > 0 && (f[n - 1] = (f[n - 1] ?? 0) + k * 3 / 16, p[n - 1] = (p[n - 1] ?? 0) + A * 3 / 16, m[n - 1] = (m[n - 1] ?? 0) + j * 3 / 16), f[n] = (f[n] ?? 0) + k * 5 / 16, p[n] = (p[n] ?? 0) + A * 5 / 16, m[n] = (m[n] ?? 0) + j * 5 / 16, n + 1 < t && (f[n + 1] = (f[n + 1] ?? 0) + k * 1 / 16, p[n + 1] = (p[n + 1] ?? 0) + A * 1 / 16, m[n + 1] = (m[n + 1] ?? 0) + j * 1 / 16);
326
+ }
327
+ [l, f] = [f, l], [u, p] = [p, u], [d, m] = [m, d];
328
+ }
329
+ return c;
330
+ }
331
+ //#endregion
332
+ //#region src/encode/quantize.ts
333
+ function ne(e, t, n) {
334
+ let { palette: r, indices: i } = M(e, t, n, 256);
335
+ return j(r, i, t, n, 9);
336
+ }
337
+ function L(e, t) {
338
+ let n = new Uint32Array(e.buffer, e.byteOffset, e.byteLength >>> 2), r = n.length;
339
+ if (r === 0) return !1;
340
+ let i = Math.max(1, Math.floor(r / 5e4)), a = /* @__PURE__ */ new Set();
341
+ for (let e = 0; e < r; e += i) if (a.add(n[e]), a.size > t) return !0;
342
+ return !1;
343
+ }
344
+ //#endregion
345
+ //#region src/encode/encode.ts
346
+ var re = 1e7;
347
+ async function R(e, t, n, r = T) {
348
+ let i = E(t, n, r.saveSizePreset ?? "original"), a = i.scaled ? ae(e, t, n, i.width, i.height) : e, o = i.width, s = i.height;
349
+ return r.format === "png" ? {
350
+ bytes: z(a, o, s),
351
+ chosen: "png",
352
+ width: o,
353
+ height: s
354
+ } : r.format === "jpeg" ? {
355
+ bytes: B(a, o, s, r.jpegPercent / 100),
356
+ chosen: "jpeg",
357
+ width: o,
358
+ height: s
359
+ } : o * s > re ? {
360
+ bytes: z(a, o, s),
361
+ chosen: "png",
362
+ reason: "too-large-for-png8",
363
+ width: o,
364
+ height: s
365
+ } : L(a, r.smartColorThreshold) ? r.smartFallback === "jpeg" ? {
366
+ bytes: B(a, o, s, r.jpegPercent / 100),
367
+ chosen: "jpeg",
368
+ reason: "photo-fallback-jpeg",
369
+ width: o,
370
+ height: s
371
+ } : {
372
+ bytes: z(a, o, s),
373
+ chosen: "png",
374
+ reason: "photo-fallback-png",
375
+ width: o,
376
+ height: s
377
+ } : {
378
+ bytes: ne(a, o, s),
379
+ chosen: "png",
380
+ reason: "png-8",
381
+ width: o,
382
+ height: s
383
+ };
384
+ }
385
+ async function ie(e, r = T) {
386
+ let i = await n(Buffer.from(e)), a = t(i.width, i.height).getContext("2d");
387
+ a.drawImage(i, 0, 0);
388
+ let o = a.getImageData(0, 0, i.width, i.height).data;
389
+ return R(new Uint8Array(o.buffer, o.byteOffset, o.byteLength), i.width, i.height, r);
390
+ }
391
+ function z(e, n, r) {
392
+ let i = t(n, r), a = i.getContext("2d"), o = a.createImageData(n, r);
393
+ o.data.set(e), a.putImageData(o, 0, 0);
394
+ let s = i.toBuffer("image/png");
395
+ return new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
396
+ }
397
+ function B(e, n, r, i) {
398
+ let a = t(n, r), o = a.getContext("2d"), s = o.createImageData(n, r);
399
+ s.data.set(e), o.putImageData(s, 0, 0);
400
+ let c = a.toBuffer("image/jpeg", i);
401
+ return new Uint8Array(c.buffer, c.byteOffset, c.byteLength);
402
+ }
403
+ function ae(e, n, r, i, a) {
404
+ let o = t(n, r), s = o.getContext("2d"), c = s.createImageData(n, r);
405
+ c.data.set(e), s.putImageData(c, 0, 0);
406
+ let l = t(i, a).getContext("2d");
407
+ l.imageSmoothingEnabled = !0, l.imageSmoothingQuality = "high", l.drawImage(o, 0, 0, n, r, 0, 0, i, a);
408
+ let u = l.getImageData(0, 0, i, a).data;
409
+ return new Uint8Array(u.buffer, u.byteOffset, u.byteLength);
410
+ }
411
+ //#endregion
412
+ //#region src/sanitise-svg.ts
413
+ function oe(e) {
414
+ if (!e || e.trim().length === 0) return "";
415
+ let t = new i(), n;
416
+ try {
417
+ n = t.parseFromString(e, "image/svg+xml");
418
+ } catch {
419
+ return "";
420
+ }
421
+ let r = n.documentElement;
422
+ if (!r) return "";
423
+ let o = new a(), s = "";
424
+ for (let e = 0; e < r.childNodes.length; e++) {
425
+ let t = r.childNodes.item(e);
426
+ if (!t || t.nodeType !== 1) continue;
427
+ let n = t, i = n.localName ?? n.tagName ?? "";
428
+ if (i === "defs") {
429
+ let e = se(n);
430
+ e !== null && (s += o.serializeToString(e));
431
+ continue;
432
+ }
433
+ if (!(i === "image" && !n.getAttribute("data-redact-style")) && n.getAttribute("id") !== "ui-overlay") {
434
+ if (n.getAttribute("id") === "annotations") {
435
+ for (let e = 0; e < n.childNodes.length; e++) {
436
+ let t = n.childNodes.item(e);
437
+ t && t.nodeType === 1 && (s += o.serializeToString(t));
438
+ }
439
+ continue;
440
+ }
441
+ s += o.serializeToString(n);
442
+ }
443
+ }
444
+ return s;
445
+ }
446
+ function se(e) {
447
+ let t = e.cloneNode(!0);
448
+ for (let e = t.childNodes.length - 1; e >= 0; e--) {
449
+ let n = t.childNodes.item(e);
450
+ if (!n || n.nodeType !== 1) continue;
451
+ let r = n;
452
+ (r.localName ?? r.tagName ?? "") === "style" && r.hasAttribute("data-annot-fonts") && t.removeChild(n);
453
+ }
454
+ return t.childNodes.length === 0 ? null : t;
455
+ }
456
+ //#endregion
457
+ //#region src/annotator.ts
458
+ function V(t = {}) {
459
+ let n = {
460
+ loadSystemFonts: t.loadSystemFonts ?? !1,
461
+ ...t.fontFiles ? { fontFiles: t.fontFiles } : {},
462
+ ...t.fontDirs ? { fontDirs: t.fontDirs } : {},
463
+ ...t.defaultFontFamily ? { defaultFontFamily: t.defaultFontFamily } : {}
464
+ };
465
+ function r(t) {
466
+ let r = new e(H(t), {
467
+ fitTo: {
468
+ mode: "width",
469
+ value: t.width
470
+ },
471
+ background: "rgba(0, 0, 0, 0)",
472
+ font: n
473
+ }).render();
474
+ return {
475
+ pixels: r.pixels,
476
+ width: r.width,
477
+ height: r.height
478
+ };
479
+ }
480
+ return {
481
+ toSvg(e) {
482
+ return H(e);
483
+ },
484
+ toPng(t) {
485
+ return new e(H(t), {
486
+ fitTo: {
487
+ mode: "width",
488
+ value: t.width
489
+ },
490
+ background: "rgba(0, 0, 0, 0)",
491
+ font: n
492
+ }).render().asPng();
493
+ },
494
+ toEditablePng(t) {
495
+ return S({
496
+ renderedPng: new e(H(t), {
497
+ fitTo: {
498
+ mode: "width",
499
+ value: t.width
500
+ },
501
+ background: "rgba(0, 0, 0, 0)",
502
+ font: n
503
+ }).render().asPng(),
504
+ originalImage: t.originalDataUrl,
505
+ annotationsSvg: t.annotationsSvg,
506
+ width: t.width,
507
+ height: t.height,
508
+ tags: t.tags
509
+ });
510
+ },
511
+ async toEncoded(e, t) {
512
+ let { pixels: n, width: i, height: a } = r(e);
513
+ return R(n, i, a, t);
514
+ }
515
+ };
516
+ }
517
+ function H(e) {
518
+ let t = oe(e.annotationsSvg);
519
+ return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ${o}="1" width="${e.width}" height="${e.height}" viewBox="0 0 ${e.width} ${e.height}"><image href="${e.originalDataUrl}" width="${e.width}" height="${e.height}"/>` + t + "</svg>";
520
+ }
521
+ //#endregion
522
+ //#region src/dsl/schema.ts
523
+ var U = {
524
+ BBox: {
525
+ type: "object",
526
+ required: [
527
+ "x",
528
+ "y",
529
+ "width",
530
+ "height"
531
+ ],
532
+ additionalProperties: !1,
533
+ properties: {
534
+ x: { type: "number" },
535
+ y: { type: "number" },
536
+ width: {
537
+ type: "number",
538
+ minimum: 0
539
+ },
540
+ height: {
541
+ type: "number",
542
+ minimum: 0
543
+ }
544
+ }
545
+ },
546
+ Point: {
547
+ type: "object",
548
+ required: ["x", "y"],
549
+ additionalProperties: !1,
550
+ properties: {
551
+ x: { type: "number" },
552
+ y: { type: "number" }
553
+ }
554
+ },
555
+ Intent: {
556
+ type: "string",
557
+ enum: [
558
+ "info",
559
+ "warning",
560
+ "error",
561
+ "success",
562
+ "neutral"
563
+ ]
564
+ },
565
+ AnnotationStyle: {
566
+ type: "object",
567
+ additionalProperties: !1,
568
+ properties: {
569
+ intent: { $ref: "#/$defs/Intent" },
570
+ stroke: { type: "string" },
571
+ strokeWidth: {
572
+ type: "number",
573
+ minimum: 0
574
+ },
575
+ fill: { type: "string" },
576
+ color: { type: "string" }
577
+ }
578
+ }
579
+ }, W = { oneOf: [
580
+ {
581
+ type: "object",
582
+ required: ["type", "bbox"],
583
+ additionalProperties: !1,
584
+ properties: {
585
+ type: { const: "rect" },
586
+ bbox: { $ref: "#/$defs/BBox" },
587
+ intent: { $ref: "#/$defs/Intent" },
588
+ stroke: { type: "string" },
589
+ strokeWidth: {
590
+ type: "number",
591
+ minimum: 0
592
+ },
593
+ fill: { type: "string" },
594
+ color: { type: "string" }
595
+ }
596
+ },
597
+ {
598
+ type: "object",
599
+ required: [
600
+ "type",
601
+ "center",
602
+ "radius"
603
+ ],
604
+ additionalProperties: !1,
605
+ properties: {
606
+ type: { const: "circle" },
607
+ center: { $ref: "#/$defs/Point" },
608
+ radius: {
609
+ type: "number",
610
+ minimum: 0
611
+ },
612
+ intent: { $ref: "#/$defs/Intent" },
613
+ stroke: { type: "string" },
614
+ strokeWidth: {
615
+ type: "number",
616
+ minimum: 0
617
+ },
618
+ fill: { type: "string" },
619
+ color: { type: "string" }
620
+ }
621
+ },
622
+ {
623
+ type: "object",
624
+ required: [
625
+ "type",
626
+ "from",
627
+ "to"
628
+ ],
629
+ additionalProperties: !1,
630
+ properties: {
631
+ type: { const: "arrow" },
632
+ from: { $ref: "#/$defs/Point" },
633
+ to: { $ref: "#/$defs/Point" },
634
+ intent: { $ref: "#/$defs/Intent" },
635
+ stroke: { type: "string" },
636
+ strokeWidth: {
637
+ type: "number",
638
+ minimum: 0
639
+ },
640
+ color: { type: "string" }
641
+ }
642
+ },
643
+ {
644
+ type: "object",
645
+ required: [
646
+ "type",
647
+ "at",
648
+ "content"
649
+ ],
650
+ additionalProperties: !1,
651
+ properties: {
652
+ type: { const: "text" },
653
+ at: { $ref: "#/$defs/Point" },
654
+ content: { type: "string" },
655
+ fontSize: {
656
+ type: "number",
657
+ minimum: 0
658
+ },
659
+ anchor: {
660
+ type: "string",
661
+ enum: [
662
+ "start",
663
+ "middle",
664
+ "end"
665
+ ]
666
+ },
667
+ intent: { $ref: "#/$defs/Intent" },
668
+ color: { type: "string" }
669
+ }
670
+ },
671
+ {
672
+ type: "object",
673
+ required: [
674
+ "type",
675
+ "at",
676
+ "targetBbox",
677
+ "content"
678
+ ],
679
+ additionalProperties: !1,
680
+ properties: {
681
+ type: { const: "callout" },
682
+ at: { $ref: "#/$defs/Point" },
683
+ targetBbox: { $ref: "#/$defs/BBox" },
684
+ content: { type: "string" },
685
+ intent: { $ref: "#/$defs/Intent" },
686
+ stroke: { type: "string" },
687
+ color: { type: "string" }
688
+ }
689
+ },
690
+ {
691
+ type: "object",
692
+ required: [
693
+ "type",
694
+ "bbox",
695
+ "number"
696
+ ],
697
+ additionalProperties: !1,
698
+ properties: {
699
+ type: { const: "numberedBadge" },
700
+ bbox: { $ref: "#/$defs/BBox" },
701
+ number: { type: "number" },
702
+ placement: {
703
+ type: "string",
704
+ enum: [
705
+ "auto",
706
+ "topLeft",
707
+ "topRight",
708
+ "bottomLeft",
709
+ "bottomRight"
710
+ ]
711
+ },
712
+ badgeSize: {
713
+ type: "number",
714
+ minimum: 0
715
+ },
716
+ imageWidth: {
717
+ type: "number",
718
+ minimum: 0
719
+ },
720
+ imageHeight: {
721
+ type: "number",
722
+ minimum: 0
723
+ },
724
+ intent: { $ref: "#/$defs/Intent" },
725
+ stroke: { type: "string" },
726
+ strokeWidth: {
727
+ type: "number",
728
+ minimum: 0
729
+ },
730
+ fill: { type: "string" },
731
+ color: { type: "string" }
732
+ }
733
+ },
734
+ {
735
+ type: "object",
736
+ required: ["type", "svgFragment"],
737
+ additionalProperties: !1,
738
+ properties: {
739
+ type: { const: "raw" },
740
+ svgFragment: { type: "string" }
741
+ }
742
+ }
743
+ ] }, G = {
744
+ type: "object",
745
+ required: ["bbox"],
746
+ additionalProperties: !1,
747
+ properties: {
748
+ bbox: { $ref: "#/$defs/BBox" },
749
+ style: {
750
+ type: "string",
751
+ enum: [
752
+ "solid",
753
+ "mosaic",
754
+ "blur"
755
+ ]
756
+ },
757
+ color: { type: "string" }
758
+ }
317
759
  };
760
+ //#endregion
761
+ //#region src/dsl/svg-primitives.ts
762
+ function K(e, t = {}) {
763
+ let n = t.stroke ?? "red", r = t.strokeWidth ?? 2, i = t.fill ?? "none";
764
+ return `<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${X(i)}" stroke="${X(n)}" stroke-width="${r}"/>`;
765
+ }
766
+ function q(e, t, n = {}) {
767
+ let r = n.color ?? "red", i = n.strokeWidth ?? 2, a = `annot-arrow-${ce()}`;
768
+ return `<defs><marker id="${a}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto" markerUnits="strokeWidth"><path d="M 0 0 L 10 5 L 0 10 z" fill="${X(r)}"/></marker></defs><line x1="${e.x}" y1="${e.y}" x2="${t.x}" y2="${t.y}" stroke="${X(r)}" stroke-width="${i}" marker-end="url(#${a})"/>`;
769
+ }
770
+ function J(e, t, n = {}) {
771
+ let r = n.color ?? "red", i = n.fontSize ?? 14, a = n.anchor ?? "start";
772
+ return `<text x="${e.x}" y="${e.y}" fill="${X(r)}" font-size="${i}" text-anchor="${a}">` + le(t) + "</text>";
773
+ }
774
+ var Y = 0;
775
+ function ce() {
776
+ return Y = Y + 1 | 0, Y;
777
+ }
778
+ function X(e) {
779
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
780
+ }
781
+ function le(e) {
782
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
783
+ }
784
+ //#endregion
785
+ //#region src/dsl/to-svg.ts
786
+ var ue = {
787
+ info: {
788
+ stroke: "#3b82f6",
789
+ fill: "rgba(59, 130, 246, 0.12)",
790
+ text: "#1e40af"
791
+ },
792
+ warning: {
793
+ stroke: "#f59e0b",
794
+ fill: "rgba(245, 158, 11, 0.12)",
795
+ text: "#92400e"
796
+ },
797
+ error: {
798
+ stroke: "#ef4444",
799
+ fill: "rgba(239, 68, 68, 0.12)",
800
+ text: "#991b1b"
801
+ },
802
+ success: {
803
+ stroke: "#10b981",
804
+ fill: "rgba(16, 185, 129, 0.12)",
805
+ text: "#065f46"
806
+ },
807
+ neutral: {
808
+ stroke: "#6b7280",
809
+ fill: "rgba(107, 114, 128, 0.12)",
810
+ text: "#374151"
811
+ }
812
+ }, de = "error";
813
+ function Z(e) {
814
+ let t = ue[e.intent ?? de];
815
+ return {
816
+ stroke: e.stroke ?? t.stroke,
817
+ fill: e.fill ?? "none",
818
+ text: e.color ?? t.text
819
+ };
820
+ }
821
+ function fe(e) {
822
+ return e.map(pe).join("");
823
+ }
824
+ function pe(e) {
825
+ switch (e.type) {
826
+ case "rect": return me(e);
827
+ case "circle": return he(e);
828
+ case "arrow": return ge(e);
829
+ case "text": return _e(e);
830
+ case "callout": return ve(e);
831
+ case "numberedBadge": return xe(e);
832
+ case "raw": return ye(e);
833
+ }
834
+ }
835
+ function me(e) {
836
+ let t = Z(e);
837
+ return K(e.bbox, {
838
+ stroke: t.stroke,
839
+ strokeWidth: e.strokeWidth ?? 2,
840
+ fill: t.fill
841
+ });
842
+ }
843
+ function he(e) {
844
+ let t = Z(e), n = e.strokeWidth ?? 2;
845
+ return `<circle cx="${e.center.x}" cy="${e.center.y}" r="${e.radius}" fill="${$(t.fill)}" stroke="${$(t.stroke)}" stroke-width="${n}"/>`;
846
+ }
847
+ function ge(e) {
848
+ let t = Z(e);
849
+ return q(e.from, e.to, {
850
+ color: t.stroke,
851
+ strokeWidth: e.strokeWidth ?? 2
852
+ });
853
+ }
854
+ function _e(e) {
855
+ let t = Z(e);
856
+ return J(e.at, e.content, {
857
+ color: t.text,
858
+ fontSize: e.fontSize ?? 14,
859
+ anchor: e.anchor ?? "start"
860
+ });
861
+ }
862
+ function ve(e) {
863
+ let t = Z(e), n = e.targetBbox, r = we(n, e.at);
864
+ return K(n, {
865
+ stroke: t.stroke,
866
+ strokeWidth: e.strokeWidth ?? 2,
867
+ fill: t.fill
868
+ }) + q(e.at, r, {
869
+ color: t.stroke,
870
+ strokeWidth: 2
871
+ }) + J(e.at, e.content, {
872
+ color: t.text,
873
+ fontSize: 14,
874
+ anchor: "start"
875
+ });
876
+ }
877
+ function ye(e) {
878
+ return e.svgFragment;
879
+ }
880
+ var be = 40;
881
+ function xe(e) {
882
+ let t = Z(e), n = e.badgeSize ?? be, r = Se(e, n), i = K(e.bbox, {
883
+ stroke: t.stroke,
884
+ strokeWidth: e.strokeWidth ?? 3,
885
+ fill: e.fill ?? "none"
886
+ }), a = Ce(e.bbox, r), o = n / 2, s = `<circle cx="${a.x}" cy="${a.y}" r="${o}" fill="${t.stroke}" stroke="#ffffff" stroke-width="${Math.max(2, o * .12)}" />`, c = Math.round(o * 1.1), l = `<text x="${a.x}" y="${a.y}" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif" font-size="${c}" font-weight="700" fill="#ffffff" text-anchor="middle" dominant-baseline="central">${$(String(e.number))}</text>`;
887
+ return i + s + l;
888
+ }
889
+ function Se(e, t) {
890
+ if (e.placement && e.placement !== "auto") return e.placement;
891
+ if (e.imageWidth === void 0 || e.imageHeight === void 0) return "topRight";
892
+ let n = t / 2, r = [
893
+ {
894
+ kind: "topLeft",
895
+ x: e.bbox.x,
896
+ y: e.bbox.y
897
+ },
898
+ {
899
+ kind: "topRight",
900
+ x: e.bbox.x + e.bbox.width,
901
+ y: e.bbox.y
902
+ },
903
+ {
904
+ kind: "bottomLeft",
905
+ x: e.bbox.x,
906
+ y: e.bbox.y + e.bbox.height
907
+ },
908
+ {
909
+ kind: "bottomRight",
910
+ x: e.bbox.x + e.bbox.width,
911
+ y: e.bbox.y + e.bbox.height
912
+ }
913
+ ], i = r[0], a = -Infinity;
914
+ for (let t of r) {
915
+ let r = Math.min(t.x - n, t.y - n, e.imageWidth - t.x - n, e.imageHeight - t.y - n);
916
+ r > a && (a = r, i = t);
917
+ }
918
+ return i.kind;
919
+ }
920
+ function Ce(e, t) {
921
+ switch (t) {
922
+ case "topLeft": return {
923
+ x: e.x,
924
+ y: e.y
925
+ };
926
+ case "topRight": return {
927
+ x: e.x + e.width,
928
+ y: e.y
929
+ };
930
+ case "bottomLeft": return {
931
+ x: e.x,
932
+ y: e.y + e.height
933
+ };
934
+ case "bottomRight": return {
935
+ x: e.x + e.width,
936
+ y: e.y + e.height
937
+ };
938
+ }
939
+ }
940
+ function we(e, t) {
941
+ return {
942
+ x: Q(t.x, e.x, e.x + e.width),
943
+ y: Q(t.y, e.y, e.y + e.height)
944
+ };
945
+ }
946
+ function Q(e, t, n) {
947
+ return Math.min(Math.max(e, t), n);
948
+ }
949
+ function $(e) {
950
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
951
+ }
952
+ //#endregion
953
+ export { W as BBOX_ANNOTATION_SCHEMA, G as BBOX_REDACT_REGION_SCHEMA, T as DEFAULT_ENCODE_OPTIONS, w as SAVE_SIZE_LABEL, C as SAVE_SIZE_MAX_WIDTH, U as SHARED_DEFS, q as arrowBetween, fe as bboxAnnotationsToSvg, E as computeResizeTarget, V as createAnnotator, ie as decodeAndEncodeImage, R as encodeRgba, L as isPhotoHeavy, K as rectForBoundingBox, J as textAt };