@ingcreators/annot-annotator 0.3.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/CHANGELOG.md +80 -0
- package/README.md +1 -1
- package/dist/annotator.d.ts +44 -8
- package/dist/dsl/types.d.ts +43 -1
- package/dist/encode/encode.d.ts +4 -4
- package/dist/encode/quantize.d.ts +4 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.js +940 -517
- package/package.json +6 -7
package/dist/index.js
CHANGED
|
@@ -1,530 +1,953 @@
|
|
|
1
|
-
import { Resvg as
|
|
2
|
-
import {
|
|
3
|
-
import { deflate as
|
|
4
|
-
import { DOMParser as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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"?>`;
|
|
24
|
+
}
|
|
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;
|
|
42
61
|
})();
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return (t ^ 4294967295) >>> 0;
|
|
48
|
-
}
|
|
49
|
-
function h(e, t) {
|
|
50
|
-
const r = new Uint8Array(12 + t.length), n = new DataView(r.buffer);
|
|
51
|
-
n.setUint32(0, t.length, !1);
|
|
52
|
-
for (let i = 0; i < 4; i++) r[4 + i] = e.charCodeAt(i);
|
|
53
|
-
r.set(t, 8);
|
|
54
|
-
const o = r.subarray(4, 8 + t.length);
|
|
55
|
-
return n.setUint32(8 + t.length, H(o), !1), r;
|
|
56
|
-
}
|
|
57
|
-
function Z(e, t, r, n, o = 9) {
|
|
58
|
-
if (r <= 0 || n <= 0) throw new Error("encodePng8: invalid dimensions");
|
|
59
|
-
if (e.length % 4 !== 0)
|
|
60
|
-
throw new Error("encodePng8: palette must be RGBA bytes (multiple of 4)");
|
|
61
|
-
const i = e.length >>> 2;
|
|
62
|
-
if (i < 1 || i > 256)
|
|
63
|
-
throw new Error(`encodePng8: palette must have 1–256 colors, got ${i}`);
|
|
64
|
-
if (t.length !== r * n)
|
|
65
|
-
throw new Error(
|
|
66
|
-
`encodePng8: indices length ${t.length} != width*height ${r * n}`
|
|
67
|
-
);
|
|
68
|
-
const s = new Uint8Array(13), a = new DataView(s.buffer);
|
|
69
|
-
a.setUint32(0, r, !1), a.setUint32(4, n, !1), s[8] = 8, s[9] = 3, s[10] = 0, s[11] = 0, s[12] = 0;
|
|
70
|
-
const c = new Uint8Array(i * 3);
|
|
71
|
-
let u = !1, f = -1;
|
|
72
|
-
for (let l = 0; l < i; l++)
|
|
73
|
-
c[l * 3] = e[l * 4], c[l * 3 + 1] = e[l * 4 + 1], c[l * 3 + 2] = e[l * 4 + 2], e[l * 4 + 3] < 255 && (u = !0, f = l);
|
|
74
|
-
let g = null;
|
|
75
|
-
if (u) {
|
|
76
|
-
g = new Uint8Array(f + 1);
|
|
77
|
-
for (let l = 0; l <= f; l++) g[l] = e[l * 4 + 3];
|
|
78
|
-
}
|
|
79
|
-
const A = r + 1, x = new Uint8Array(A * n);
|
|
80
|
-
for (let l = 0; l < n; l++) {
|
|
81
|
-
const T = l * A;
|
|
82
|
-
x[T] = 0, x.set(t.subarray(l * r, l * r + r), T + 1);
|
|
83
|
-
}
|
|
84
|
-
const U = L(x, { level: o, memLevel: 9, windowBits: 15 }), d = [G, h("IHDR", s), h("PLTE", c)];
|
|
85
|
-
g && d.push(h("tRNS", g)), d.push(h("IDAT", U)), d.push(h("IEND", new Uint8Array(0)));
|
|
86
|
-
let I = 0;
|
|
87
|
-
for (const l of d) I += l.length;
|
|
88
|
-
const S = new Uint8Array(I);
|
|
89
|
-
let v = 0;
|
|
90
|
-
for (const l of d)
|
|
91
|
-
S.set(l, v), v += l.length;
|
|
92
|
-
return S;
|
|
93
|
-
}
|
|
94
|
-
let w = null;
|
|
95
|
-
async function N() {
|
|
96
|
-
return w || (w = (async () => {
|
|
97
|
-
try {
|
|
98
|
-
const e = await import("@ingcreators/annot-imagequant");
|
|
99
|
-
return await e.default(), { quantize_image: e.quantize_image };
|
|
100
|
-
} catch {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
})(), w);
|
|
104
|
-
}
|
|
105
|
-
async function J(e, t, r) {
|
|
106
|
-
const n = await N();
|
|
107
|
-
if (!n) return null;
|
|
108
|
-
const o = n.quantize_image(e, t, r, 256);
|
|
109
|
-
if (!(o?.palette instanceof Uint8Array) || !(o?.indices instanceof Uint8Array))
|
|
110
|
-
throw new Error("quantize_image returned an unexpected shape");
|
|
111
|
-
return Z(o.palette, o.indices, t, r, 9);
|
|
112
|
-
}
|
|
113
|
-
function K(e, t) {
|
|
114
|
-
const r = new Uint32Array(e.buffer, e.byteOffset, e.byteLength >>> 2), n = r.length;
|
|
115
|
-
if (n === 0) return !1;
|
|
116
|
-
const i = Math.max(1, Math.floor(n / 5e4)), s = /* @__PURE__ */ new Set();
|
|
117
|
-
for (let a = 0; a < n; a += i)
|
|
118
|
-
if (s.add(r[a]), s.size > t) return !0;
|
|
119
|
-
return !1;
|
|
120
|
-
}
|
|
121
|
-
async function ve() {
|
|
122
|
-
return await N() !== null;
|
|
123
|
-
}
|
|
124
|
-
const Y = 1e7;
|
|
125
|
-
async function O(e, t, r, n = C) {
|
|
126
|
-
const o = n.saveSizePreset ?? "original", i = V(t, r, o), s = i.scaled ? ee(e, t, r, i.width, i.height) : e, a = i.width, c = i.height;
|
|
127
|
-
if (n.format === "png")
|
|
128
|
-
return { bytes: b(s, a, c), chosen: "png", width: a, height: c };
|
|
129
|
-
if (n.format === "jpeg")
|
|
130
|
-
return {
|
|
131
|
-
bytes: B(s, a, c, n.jpegPercent / 100),
|
|
132
|
-
chosen: "jpeg",
|
|
133
|
-
width: a,
|
|
134
|
-
height: c
|
|
135
|
-
};
|
|
136
|
-
if (a * c > Y)
|
|
137
|
-
return {
|
|
138
|
-
bytes: b(s, a, c),
|
|
139
|
-
chosen: "png",
|
|
140
|
-
reason: "too-large-for-png8",
|
|
141
|
-
width: a,
|
|
142
|
-
height: c
|
|
143
|
-
};
|
|
144
|
-
if (K(s, n.smartColorThreshold))
|
|
145
|
-
return n.smartFallback === "jpeg" ? {
|
|
146
|
-
bytes: B(s, a, c, n.jpegPercent / 100),
|
|
147
|
-
chosen: "jpeg",
|
|
148
|
-
reason: "photo-fallback-jpeg",
|
|
149
|
-
width: a,
|
|
150
|
-
height: c
|
|
151
|
-
} : {
|
|
152
|
-
bytes: b(s, a, c),
|
|
153
|
-
chosen: "png",
|
|
154
|
-
reason: "photo-fallback-png",
|
|
155
|
-
width: a,
|
|
156
|
-
height: c
|
|
157
|
-
};
|
|
158
|
-
const f = await J(s, a, c);
|
|
159
|
-
return f ? { bytes: f, chosen: "png", reason: "png-8", width: a, height: c } : {
|
|
160
|
-
bytes: b(s, a, c),
|
|
161
|
-
chosen: "png",
|
|
162
|
-
reason: "imagequant-missing",
|
|
163
|
-
width: a,
|
|
164
|
-
height: c
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
async function Te(e, t = C) {
|
|
168
|
-
const r = await R(Buffer.from(e)), o = m(r.width, r.height).getContext("2d");
|
|
169
|
-
o.drawImage(r, 0, 0);
|
|
170
|
-
const i = o.getImageData(0, 0, r.width, r.height).data, s = new Uint8Array(i.buffer, i.byteOffset, i.byteLength);
|
|
171
|
-
return O(s, r.width, r.height, t);
|
|
172
|
-
}
|
|
173
|
-
function b(e, t, r) {
|
|
174
|
-
const n = m(t, r), o = n.getContext("2d"), i = o.createImageData(t, r);
|
|
175
|
-
i.data.set(e), o.putImageData(i, 0, 0);
|
|
176
|
-
const s = n.toBuffer("image/png");
|
|
177
|
-
return new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
|
|
178
|
-
}
|
|
179
|
-
function B(e, t, r, n) {
|
|
180
|
-
const o = m(t, r), i = o.getContext("2d"), s = i.createImageData(t, r);
|
|
181
|
-
s.data.set(e), i.putImageData(s, 0, 0);
|
|
182
|
-
const a = o.toBuffer("image/jpeg", n);
|
|
183
|
-
return new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
184
|
-
}
|
|
185
|
-
function ee(e, t, r, n, o) {
|
|
186
|
-
const i = m(t, r), s = i.getContext("2d"), a = s.createImageData(t, r);
|
|
187
|
-
a.data.set(e), s.putImageData(a, 0, 0);
|
|
188
|
-
const u = m(n, o).getContext("2d");
|
|
189
|
-
u.imageSmoothingEnabled = !0, u.imageSmoothingQuality = "high", u.drawImage(i, 0, 0, t, r, 0, 0, n, o);
|
|
190
|
-
const g = u.getImageData(0, 0, n, o).data;
|
|
191
|
-
return new Uint8Array(g.buffer, g.byteOffset, g.byteLength);
|
|
192
|
-
}
|
|
193
|
-
function te(e) {
|
|
194
|
-
if (!e || e.trim().length === 0)
|
|
195
|
-
return "";
|
|
196
|
-
const t = new j();
|
|
197
|
-
let r;
|
|
198
|
-
try {
|
|
199
|
-
r = t.parseFromString(e, "image/svg+xml");
|
|
200
|
-
} catch {
|
|
201
|
-
return "";
|
|
202
|
-
}
|
|
203
|
-
const n = r.documentElement;
|
|
204
|
-
if (!n) return "";
|
|
205
|
-
const o = new q();
|
|
206
|
-
let i = "";
|
|
207
|
-
for (let s = 0; s < n.childNodes.length; s++) {
|
|
208
|
-
const a = n.childNodes.item(s);
|
|
209
|
-
if (!a || a.nodeType !== 1) continue;
|
|
210
|
-
const c = a, u = c.localName ?? c.tagName ?? "";
|
|
211
|
-
if (u === "defs") {
|
|
212
|
-
const f = re(c);
|
|
213
|
-
f !== null && (i += o.serializeToString(f));
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (!(u === "image" && !c.getAttribute("data-redact-style")) && c.getAttribute("id") !== "ui-overlay") {
|
|
217
|
-
if (c.getAttribute("id") === "annotations") {
|
|
218
|
-
for (let f = 0; f < c.childNodes.length; f++) {
|
|
219
|
-
const g = c.childNodes.item(f);
|
|
220
|
-
g && g.nodeType === 1 && (i += o.serializeToString(g));
|
|
221
|
-
}
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
i += o.serializeToString(c);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return i;
|
|
228
|
-
}
|
|
229
|
-
function re(e) {
|
|
230
|
-
const t = e.cloneNode(!0);
|
|
231
|
-
for (let r = t.childNodes.length - 1; r >= 0; r--) {
|
|
232
|
-
const n = t.childNodes.item(r);
|
|
233
|
-
if (!n || n.nodeType !== 1) continue;
|
|
234
|
-
const o = n;
|
|
235
|
-
(o.localName ?? o.tagName ?? "") === "style" && o.hasAttribute("data-annot-fonts") && t.removeChild(n);
|
|
236
|
-
}
|
|
237
|
-
return t.childNodes.length === 0 ? null : t;
|
|
238
|
-
}
|
|
239
|
-
function Pe(e = {}) {
|
|
240
|
-
const t = {
|
|
241
|
-
loadSystemFonts: e.loadSystemFonts ?? !1,
|
|
242
|
-
...e.fontFiles ? { fontFiles: e.fontFiles } : {},
|
|
243
|
-
...e.fontDirs ? { fontDirs: e.fontDirs } : {},
|
|
244
|
-
...e.defaultFontFamily ? { defaultFontFamily: e.defaultFontFamily } : {}
|
|
245
|
-
};
|
|
246
|
-
function r(n) {
|
|
247
|
-
const o = $(n), s = new P(o, {
|
|
248
|
-
fitTo: { mode: "width", value: n.width },
|
|
249
|
-
background: "rgba(0, 0, 0, 0)",
|
|
250
|
-
font: t
|
|
251
|
-
}).render();
|
|
252
|
-
return {
|
|
253
|
-
pixels: s.pixels,
|
|
254
|
-
width: s.width,
|
|
255
|
-
height: s.height
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
toSvg(n) {
|
|
260
|
-
return $(n);
|
|
261
|
-
},
|
|
262
|
-
toPng(n) {
|
|
263
|
-
const o = $(n);
|
|
264
|
-
return new P(o, {
|
|
265
|
-
fitTo: { mode: "width", value: n.width },
|
|
266
|
-
background: "rgba(0, 0, 0, 0)",
|
|
267
|
-
font: t
|
|
268
|
-
}).render().asPng();
|
|
269
|
-
},
|
|
270
|
-
async toEncoded(n, o) {
|
|
271
|
-
const { pixels: i, width: s, height: a } = r(n);
|
|
272
|
-
return O(i, s, a, o);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function $(e) {
|
|
277
|
-
const t = "http://www.w3.org/2000/svg", r = "http://www.w3.org/1999/xlink", n = te(e.annotationsSvg);
|
|
278
|
-
return `<svg xmlns="${t}" xmlns:xlink="${r}" ${M}="${W}" 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>";
|
|
279
|
-
}
|
|
280
|
-
const Be = {
|
|
281
|
-
BBox: {
|
|
282
|
-
type: "object",
|
|
283
|
-
required: ["x", "y", "width", "height"],
|
|
284
|
-
additionalProperties: !1,
|
|
285
|
-
properties: {
|
|
286
|
-
x: { type: "number" },
|
|
287
|
-
y: { type: "number" },
|
|
288
|
-
width: { type: "number", minimum: 0 },
|
|
289
|
-
height: { type: "number", minimum: 0 }
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
Point: {
|
|
293
|
-
type: "object",
|
|
294
|
-
required: ["x", "y"],
|
|
295
|
-
additionalProperties: !1,
|
|
296
|
-
properties: {
|
|
297
|
-
x: { type: "number" },
|
|
298
|
-
y: { type: "number" }
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
Intent: {
|
|
302
|
-
type: "string",
|
|
303
|
-
enum: ["info", "warning", "error", "success", "neutral"]
|
|
304
|
-
},
|
|
305
|
-
AnnotationStyle: {
|
|
306
|
-
type: "object",
|
|
307
|
-
additionalProperties: !1,
|
|
308
|
-
properties: {
|
|
309
|
-
intent: { $ref: "#/$defs/Intent" },
|
|
310
|
-
stroke: { type: "string" },
|
|
311
|
-
strokeWidth: { type: "number", minimum: 0 },
|
|
312
|
-
fill: { type: "string" },
|
|
313
|
-
color: { type: "string" }
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}, ne = {
|
|
317
|
-
type: "object",
|
|
318
|
-
required: ["type", "bbox"],
|
|
319
|
-
additionalProperties: !1,
|
|
320
|
-
properties: {
|
|
321
|
-
type: { const: "rect" },
|
|
322
|
-
bbox: { $ref: "#/$defs/BBox" },
|
|
323
|
-
intent: { $ref: "#/$defs/Intent" },
|
|
324
|
-
stroke: { type: "string" },
|
|
325
|
-
strokeWidth: { type: "number", minimum: 0 },
|
|
326
|
-
fill: { type: "string" },
|
|
327
|
-
color: { type: "string" }
|
|
328
|
-
}
|
|
329
|
-
}, oe = {
|
|
330
|
-
type: "object",
|
|
331
|
-
required: ["type", "center", "radius"],
|
|
332
|
-
additionalProperties: !1,
|
|
333
|
-
properties: {
|
|
334
|
-
type: { const: "circle" },
|
|
335
|
-
center: { $ref: "#/$defs/Point" },
|
|
336
|
-
radius: { type: "number", minimum: 0 },
|
|
337
|
-
intent: { $ref: "#/$defs/Intent" },
|
|
338
|
-
stroke: { type: "string" },
|
|
339
|
-
strokeWidth: { type: "number", minimum: 0 },
|
|
340
|
-
fill: { type: "string" },
|
|
341
|
-
color: { type: "string" }
|
|
342
|
-
}
|
|
343
|
-
}, ie = {
|
|
344
|
-
type: "object",
|
|
345
|
-
required: ["type", "from", "to"],
|
|
346
|
-
additionalProperties: !1,
|
|
347
|
-
properties: {
|
|
348
|
-
type: { const: "arrow" },
|
|
349
|
-
from: { $ref: "#/$defs/Point" },
|
|
350
|
-
to: { $ref: "#/$defs/Point" },
|
|
351
|
-
intent: { $ref: "#/$defs/Intent" },
|
|
352
|
-
stroke: { type: "string" },
|
|
353
|
-
strokeWidth: { type: "number", minimum: 0 },
|
|
354
|
-
color: { type: "string" }
|
|
355
|
-
}
|
|
356
|
-
}, se = {
|
|
357
|
-
type: "object",
|
|
358
|
-
required: ["type", "at", "content"],
|
|
359
|
-
additionalProperties: !1,
|
|
360
|
-
properties: {
|
|
361
|
-
type: { const: "text" },
|
|
362
|
-
at: { $ref: "#/$defs/Point" },
|
|
363
|
-
content: { type: "string" },
|
|
364
|
-
fontSize: { type: "number", minimum: 0 },
|
|
365
|
-
anchor: { type: "string", enum: ["start", "middle", "end"] },
|
|
366
|
-
intent: { $ref: "#/$defs/Intent" },
|
|
367
|
-
color: { type: "string" }
|
|
368
|
-
}
|
|
369
|
-
}, ae = {
|
|
370
|
-
type: "object",
|
|
371
|
-
required: ["type", "at", "targetBbox", "content"],
|
|
372
|
-
additionalProperties: !1,
|
|
373
|
-
properties: {
|
|
374
|
-
type: { const: "callout" },
|
|
375
|
-
at: { $ref: "#/$defs/Point" },
|
|
376
|
-
targetBbox: { $ref: "#/$defs/BBox" },
|
|
377
|
-
content: { type: "string" },
|
|
378
|
-
intent: { $ref: "#/$defs/Intent" },
|
|
379
|
-
stroke: { type: "string" },
|
|
380
|
-
color: { type: "string" }
|
|
381
|
-
}
|
|
382
|
-
}, ce = {
|
|
383
|
-
type: "object",
|
|
384
|
-
required: ["type", "svgFragment"],
|
|
385
|
-
additionalProperties: !1,
|
|
386
|
-
properties: {
|
|
387
|
-
type: { const: "raw" },
|
|
388
|
-
svgFragment: { type: "string" }
|
|
389
|
-
}
|
|
390
|
-
}, Ee = {
|
|
391
|
-
oneOf: [ne, oe, ie, se, ae, ce]
|
|
392
|
-
}, _e = {
|
|
393
|
-
type: "object",
|
|
394
|
-
required: ["bbox"],
|
|
395
|
-
additionalProperties: !1,
|
|
396
|
-
properties: {
|
|
397
|
-
bbox: { $ref: "#/$defs/BBox" },
|
|
398
|
-
style: { type: "string", enum: ["solid", "mosaic", "blur"] },
|
|
399
|
-
color: { type: "string" }
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
function F(e, t = {}) {
|
|
403
|
-
const r = t.stroke ?? "red", n = t.strokeWidth ?? 2, o = t.fill ?? "none";
|
|
404
|
-
return `<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${p(o)}" stroke="${p(r)}" stroke-width="${n}"/>`;
|
|
405
|
-
}
|
|
406
|
-
function z(e, t, r = {}) {
|
|
407
|
-
const n = r.color ?? "red", o = r.strokeWidth ?? 2, i = `annot-arrow-${le()}`;
|
|
408
|
-
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="${p(n)}"/></marker></defs><line x1="${e.x}" y1="${e.y}" x2="${t.x}" y2="${t.y}" stroke="${p(n)}" stroke-width="${o}" marker-end="url(#${i})"/>`;
|
|
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;
|
|
409
66
|
}
|
|
410
|
-
function
|
|
411
|
-
|
|
412
|
-
|
|
67
|
+
function v(e, t) {
|
|
68
|
+
let n = p(e, t), r = _(n);
|
|
69
|
+
return p(d(t.length), n, d(r));
|
|
413
70
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
71
|
+
function y(e) {
|
|
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
|
+
};
|
|
417
516
|
}
|
|
418
|
-
function
|
|
419
|
-
|
|
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
|
+
}
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
780
|
+
}
|
|
781
|
+
function le(e) {
|
|
782
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
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
|
+
};
|
|
420
820
|
}
|
|
421
821
|
function fe(e) {
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
const ge = {
|
|
425
|
-
info: { stroke: "#3b82f6", fill: "rgba(59, 130, 246, 0.12)", text: "#1e40af" },
|
|
426
|
-
warning: { stroke: "#f59e0b", fill: "rgba(245, 158, 11, 0.12)", text: "#92400e" },
|
|
427
|
-
error: { stroke: "#ef4444", fill: "rgba(239, 68, 68, 0.12)", text: "#991b1b" },
|
|
428
|
-
success: { stroke: "#10b981", fill: "rgba(16, 185, 129, 0.12)", text: "#065f46" },
|
|
429
|
-
neutral: { stroke: "#6b7280", fill: "rgba(107, 114, 128, 0.12)", text: "#374151" }
|
|
430
|
-
}, ue = "error";
|
|
431
|
-
function y(e) {
|
|
432
|
-
const t = e.intent ?? ue, r = ge[t];
|
|
433
|
-
return {
|
|
434
|
-
stroke: e.stroke ?? r.stroke,
|
|
435
|
-
fill: e.fill ?? "none",
|
|
436
|
-
text: e.color ?? r.text
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
function Ce(e) {
|
|
440
|
-
return e.map(de).join("");
|
|
441
|
-
}
|
|
442
|
-
function de(e) {
|
|
443
|
-
switch (e.type) {
|
|
444
|
-
case "rect":
|
|
445
|
-
return he(e);
|
|
446
|
-
case "circle":
|
|
447
|
-
return me(e);
|
|
448
|
-
case "arrow":
|
|
449
|
-
return pe(e);
|
|
450
|
-
case "text":
|
|
451
|
-
return ye(e);
|
|
452
|
-
case "callout":
|
|
453
|
-
return we(e);
|
|
454
|
-
case "raw":
|
|
455
|
-
return be(e);
|
|
456
|
-
}
|
|
822
|
+
return e.map(pe).join("");
|
|
457
823
|
}
|
|
458
|
-
function
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
+
}
|
|
465
834
|
}
|
|
466
835
|
function me(e) {
|
|
467
|
-
|
|
468
|
-
|
|
836
|
+
let t = Z(e);
|
|
837
|
+
return K(e.bbox, {
|
|
838
|
+
stroke: t.stroke,
|
|
839
|
+
strokeWidth: e.strokeWidth ?? 2,
|
|
840
|
+
fill: t.fill
|
|
841
|
+
});
|
|
469
842
|
}
|
|
470
|
-
function
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
+
});
|
|
476
876
|
}
|
|
477
877
|
function ye(e) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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);
|
|
509
948
|
}
|
|
510
|
-
function
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
_e as BBOX_REDACT_REGION_SCHEMA,
|
|
516
|
-
C as DEFAULT_ENCODE_OPTIONS,
|
|
517
|
-
Se as SAVE_SIZE_LABEL,
|
|
518
|
-
X as SAVE_SIZE_MAX_WIDTH,
|
|
519
|
-
Be as SHARED_DEFS,
|
|
520
|
-
z as arrowBetween,
|
|
521
|
-
Ce as bboxAnnotationsToSvg,
|
|
522
|
-
V as computeResizeTarget,
|
|
523
|
-
Pe as createAnnotator,
|
|
524
|
-
Te as decodeAndEncodeImage,
|
|
525
|
-
O as encodeRgba,
|
|
526
|
-
ve as isImagequantAvailable,
|
|
527
|
-
K as isPhotoHeavy,
|
|
528
|
-
F as rectForBoundingBox,
|
|
529
|
-
D as textAt
|
|
530
|
-
};
|
|
949
|
+
function $(e) {
|
|
950
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
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 };
|