@ingcreators/annot-annotator 0.3.0 → 0.6.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 +375 -0
- package/README.md +1 -1
- package/dist/annotator.d.ts +44 -8
- package/dist/diff-aggregate.d.ts +6 -0
- package/dist/diff.d.ts +30 -0
- package/dist/dsl/schema.d.ts +68 -0
- package/dist/dsl/types.d.ts +83 -1
- package/dist/encode/encode.d.ts +4 -4
- package/dist/encode/quantize.d.ts +4 -10
- package/dist/flatten-editable-png.d.ts +37 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +1193 -522
- package/dist/redact-burn.d.ts +63 -0
- package/package.json +10 -6
package/dist/index.js
CHANGED
|
@@ -1,530 +1,1201 @@
|
|
|
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
|
-
|
|
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 = /* @__PURE__ */ 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));
|
|
70
|
+
}
|
|
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"
|
|
21
118
|
};
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 = /* @__PURE__ */ 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;
|
|
42
152
|
})();
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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);
|
|
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 = /* @__PURE__ */ 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", /* @__PURE__ */ 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;
|
|
192
201
|
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region ../core/src/encode/quantize-median-cut.ts
|
|
204
|
+
function ee(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 } = te(e), l = ne(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: ie(e, t, n, f, m, s, c > 0)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
var M = 16;
|
|
193
222
|
function te(e) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
};
|
|
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] < M) {
|
|
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
|
+
};
|
|
275
244
|
}
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
245
|
+
function ne(e, t) {
|
|
246
|
+
if (e.length === 0) return [];
|
|
247
|
+
if (t <= 1) return [N(e, 0, e.length, 0)];
|
|
248
|
+
let n = [N(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, re(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 = N(e, o.start, p, r++), h = N(e, p, o.end, r++);
|
|
265
|
+
n[t] = m, n.push(h);
|
|
266
|
+
}
|
|
267
|
+
return n;
|
|
268
|
+
}
|
|
269
|
+
function N(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 re(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 ie(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 < M) {
|
|
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 ae(e, t, n) {
|
|
334
|
+
let { palette: r, indices: i } = ee(e, t, n, 256);
|
|
335
|
+
return j(r, i, t, n, 9);
|
|
336
|
+
}
|
|
337
|
+
function P(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 oe = 1e7;
|
|
347
|
+
async function F(e, t, n, r = T) {
|
|
348
|
+
let i = E(t, n, r.saveSizePreset ?? "original"), a = i.scaled ? ce(e, t, n, i.width, i.height) : e, o = i.width, s = i.height;
|
|
349
|
+
return r.format === "png" ? {
|
|
350
|
+
bytes: I(a, o, s),
|
|
351
|
+
chosen: "png",
|
|
352
|
+
width: o,
|
|
353
|
+
height: s
|
|
354
|
+
} : r.format === "jpeg" ? {
|
|
355
|
+
bytes: L(a, o, s, r.jpegPercent / 100),
|
|
356
|
+
chosen: "jpeg",
|
|
357
|
+
width: o,
|
|
358
|
+
height: s
|
|
359
|
+
} : o * s > oe ? {
|
|
360
|
+
bytes: I(a, o, s),
|
|
361
|
+
chosen: "png",
|
|
362
|
+
reason: "too-large-for-png8",
|
|
363
|
+
width: o,
|
|
364
|
+
height: s
|
|
365
|
+
} : P(a, r.smartColorThreshold) ? r.smartFallback === "jpeg" ? {
|
|
366
|
+
bytes: L(a, o, s, r.jpegPercent / 100),
|
|
367
|
+
chosen: "jpeg",
|
|
368
|
+
reason: "photo-fallback-jpeg",
|
|
369
|
+
width: o,
|
|
370
|
+
height: s
|
|
371
|
+
} : {
|
|
372
|
+
bytes: I(a, o, s),
|
|
373
|
+
chosen: "png",
|
|
374
|
+
reason: "photo-fallback-png",
|
|
375
|
+
width: o,
|
|
376
|
+
height: s
|
|
377
|
+
} : {
|
|
378
|
+
bytes: ae(a, o, s),
|
|
379
|
+
chosen: "png",
|
|
380
|
+
reason: "png-8",
|
|
381
|
+
width: o,
|
|
382
|
+
height: s
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
async function se(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 F(new Uint8Array(o.buffer, o.byteOffset, o.byteLength), i.width, i.height, r);
|
|
390
|
+
}
|
|
391
|
+
function I(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 L(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 ce(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 le(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 = ue(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 ue(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 de(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(R(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 R(e);
|
|
483
|
+
},
|
|
484
|
+
toPng(t) {
|
|
485
|
+
return new e(R(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(R(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 F(n, i, a, t);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function R(e) {
|
|
518
|
+
let t = le(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/redact-burn.ts
|
|
523
|
+
var fe = "solid", pe = "#000000", z = 16, me = 12;
|
|
524
|
+
async function B(e, r) {
|
|
525
|
+
if (r.length === 0) return e;
|
|
526
|
+
let i = await n(Buffer.from(e)), a = t(i.width, i.height), o = a.getContext("2d");
|
|
527
|
+
o.drawImage(i, 0, 0);
|
|
528
|
+
for (let e of r) if (!(e.bbox.width <= 0 || e.bbox.height <= 0)) switch (e.style ?? fe) {
|
|
529
|
+
case "solid":
|
|
530
|
+
he(o, e.bbox, e.color ?? pe);
|
|
531
|
+
break;
|
|
532
|
+
case "mosaic":
|
|
533
|
+
ge(o, i, e.bbox);
|
|
534
|
+
break;
|
|
535
|
+
case "blur":
|
|
536
|
+
_e(o, i, e.bbox);
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
let s = a.toBuffer("image/png");
|
|
540
|
+
return new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
|
|
541
|
+
}
|
|
542
|
+
function he(e, t, n) {
|
|
543
|
+
e.save(), e.fillStyle = n, e.fillRect(t.x, t.y, t.width, t.height), e.restore();
|
|
544
|
+
}
|
|
545
|
+
function ge(e, n, r) {
|
|
546
|
+
let i = Math.max(1, Math.round(r.width / z)), a = Math.max(1, Math.round(r.height / z)), o = t(i, a), s = o.getContext("2d");
|
|
547
|
+
s.imageSmoothingEnabled = !1, s.drawImage(n, r.x, r.y, r.width, r.height, 0, 0, i, a), e.save(), e.imageSmoothingEnabled = !1, e.drawImage(o, 0, 0, i, a, r.x, r.y, r.width, r.height), e.restore();
|
|
548
|
+
}
|
|
549
|
+
function _e(e, t, n) {
|
|
550
|
+
e.save(), e.beginPath(), e.rect(n.x, n.y, n.width, n.height), e.clip(), e.filter = `blur(${me}px)`, e.drawImage(t, 0, 0), e.restore();
|
|
551
|
+
}
|
|
552
|
+
var ve = B;
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region ../../node_modules/.pnpm/pixelmatch@7.2.0/node_modules/pixelmatch/index.js
|
|
555
|
+
function ye(e, t, n, r, i, a = {}) {
|
|
556
|
+
let { threshold: o = .1, alpha: s = .1, aaColor: c = [
|
|
557
|
+
255,
|
|
558
|
+
255,
|
|
559
|
+
0
|
|
560
|
+
], diffColor: l = [
|
|
561
|
+
255,
|
|
562
|
+
0,
|
|
563
|
+
0
|
|
564
|
+
], checkerboard: u = !0, includeAA: d, diffColorAlt: f, diffMask: p } = a;
|
|
565
|
+
if (!V(e) || !V(t) || n && !V(n)) throw Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");
|
|
566
|
+
if (e.length !== t.length || n && n.length !== e.length) throw Error(`Image sizes do not match. Image 1 size: ${e.length}, image 2 size: ${t.length}`);
|
|
567
|
+
if (e.length !== r * i * 4) throw Error(`Image data size does not match width/height. Expecting ${r * i * 4}. Got ${e.length}`);
|
|
568
|
+
let m = r * i, h = new Uint32Array(e.buffer, e.byteOffset, m), g = new Uint32Array(t.buffer, t.byteOffset, m), _ = !0;
|
|
569
|
+
for (let e = 0; e < m; e++) if (h[e] !== g[e]) {
|
|
570
|
+
_ = !1;
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
if (_) {
|
|
574
|
+
if (n && !p) for (let t = 0, r = 0; t < m; t++, r += 4) G(e, r, s, n);
|
|
575
|
+
return 0;
|
|
576
|
+
}
|
|
577
|
+
let v = 35215 * o * o, [y, b, x] = c, [S, C, w] = l, [T, E, D] = f || l, O = 0;
|
|
578
|
+
for (let a = 0, o = 0; a < m; a++, o += 4) {
|
|
579
|
+
let c = h[a] === g[a] ? 0 : be(e, t, o, o, u);
|
|
580
|
+
if (Math.abs(c) > v) {
|
|
581
|
+
let s = a % r, l = a / r | 0;
|
|
582
|
+
!d && (H(e, s, l, r, i, h, g, u) || H(t, s, l, r, i, g, h, u)) ? n && !p && W(n, o, y, b, x) : (n && (c < 0 ? W(n, o, T, E, D) : W(n, o, S, C, w)), O++);
|
|
583
|
+
} else n && !p && G(e, o, s, n);
|
|
584
|
+
}
|
|
585
|
+
return O;
|
|
586
|
+
}
|
|
587
|
+
function V(e) {
|
|
588
|
+
return ArrayBuffer.isView(e) && e.BYTES_PER_ELEMENT === 1;
|
|
589
|
+
}
|
|
590
|
+
function H(e, t, n, r, i, a, o, s) {
|
|
591
|
+
let c = Math.max(t - 1, 0), l = Math.max(n - 1, 0), u = Math.min(t + 1, r - 1), d = Math.min(n + 1, i - 1), f = (n * r + t) * 4, p = e[f], m = e[f + 1], h = e[f + 2], g = e[f + 3], _ = +(t === c || t === u || n === l || n === d), v = 0, y = 0, b = 0, x = 0, S = 0, C = 0;
|
|
592
|
+
for (let i = c; i <= u; i++) for (let a = l; a <= d; a++) {
|
|
593
|
+
if (i === t && a === n) continue;
|
|
594
|
+
let o = xe(e, f, (a * r + i) * 4, p, m, h, g, s);
|
|
595
|
+
if (o === 0) {
|
|
596
|
+
if (_++, _ > 2) return !1;
|
|
597
|
+
} else o < v ? (v = o, b = i, x = a) : o > y && (y = o, S = i, C = a);
|
|
598
|
+
}
|
|
599
|
+
return v === 0 || y === 0 ? !1 : U(a, b, x, r, i) && U(o, b, x, r, i) || U(a, S, C, r, i) && U(o, S, C, r, i);
|
|
600
|
+
}
|
|
601
|
+
function U(e, t, n, r, i) {
|
|
602
|
+
let a = Math.max(t - 1, 0), o = Math.max(n - 1, 0), s = Math.min(t + 1, r - 1), c = Math.min(n + 1, i - 1), l = e[n * r + t], u = +(t === a || t === s || n === o || n === c);
|
|
603
|
+
for (let i = a; i <= s; i++) for (let a = o; a <= c; a++) if (!(i === t && a === n) && (u += +(l === e[a * r + i]), u > 2)) return !0;
|
|
604
|
+
return !1;
|
|
605
|
+
}
|
|
606
|
+
function be(e, t, n, r, i) {
|
|
607
|
+
let a = e[n], o = e[n + 1], s = e[n + 2], c = e[n + 3], l = t[r], u = t[r + 1], d = t[r + 2], f = t[r + 3], p = a - l, m = o - u, h = s - d, g = c - f;
|
|
608
|
+
if (c < 255 || f < 255) {
|
|
609
|
+
let e = 255, t = 255, r = 255;
|
|
610
|
+
i && (e = 48 + n % 2 * 159, t = 48 + 159 * ((n / 1.618033988749895 | 0) % 2), r = 48 + 159 * ((n / 2.618033988749895 | 0) % 2)), p = (a * c - l * f - e * g) / 255, m = (o * c - u * f - t * g) / 255, h = (s * c - d * f - r * g) / 255;
|
|
611
|
+
}
|
|
612
|
+
let _ = p * .29889531 + m * .58662247 + h * .11448223, v = p * .59597799 - m * .2741761 - h * .32180189, y = p * .21147017 - m * .52261711 + h * .31114694, b = .5053 * _ * _ + .299 * v * v + .1957 * y * y;
|
|
613
|
+
return _ > 0 ? -b : b;
|
|
614
|
+
}
|
|
615
|
+
function xe(e, t, n, r, i, a, o, s) {
|
|
616
|
+
let c = e[n], l = e[n + 1], u = e[n + 2], d = e[n + 3], f = r - c, p = i - l, m = a - u, h = o - d;
|
|
617
|
+
if (!f && !p && !m && !h) return 0;
|
|
618
|
+
if (o < 255 || d < 255) {
|
|
619
|
+
let e = 255, n = 255, g = 255;
|
|
620
|
+
s && (e = 48 + t % 2 * 159, n = 48 + 159 * ((t / 1.618033988749895 | 0) % 2), g = 48 + 159 * ((t / 2.618033988749895 | 0) % 2)), f = (r * o - c * d - e * h) / 255, p = (i * o - l * d - n * h) / 255, m = (a * o - u * d - g * h) / 255;
|
|
621
|
+
}
|
|
622
|
+
return f * .29889531 + p * .58662247 + m * .11448223;
|
|
623
|
+
}
|
|
624
|
+
function W(e, t, n, r, i) {
|
|
625
|
+
e[t] = n, e[t + 1] = r, e[t + 2] = i, e[t + 3] = 255;
|
|
626
|
+
}
|
|
627
|
+
function G(e, t, n, r) {
|
|
628
|
+
let i = 255 + (e[t] * .29889531 + e[t + 1] * .58662247 + e[t + 2] * .11448223 - 255) * n * e[t + 3] / 255;
|
|
629
|
+
W(r, t, i, i, i);
|
|
630
|
+
}
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/diff-aggregate.ts
|
|
633
|
+
var Se = 4;
|
|
634
|
+
function K(e, t, n) {
|
|
635
|
+
let r = new Uint8Array(t * n), i = [];
|
|
636
|
+
for (let a = 0; a < n; a++) for (let o = 0; o < t; o++) {
|
|
637
|
+
let s = a * t + o;
|
|
638
|
+
if (r[s] || !Ce(e, s)) continue;
|
|
639
|
+
let c = we(e, r, o, a, t, n);
|
|
640
|
+
c.count >= Se && i.push({
|
|
641
|
+
x: c.minX,
|
|
642
|
+
y: c.minY,
|
|
643
|
+
width: c.maxX - c.minX + 1,
|
|
644
|
+
height: c.maxY - c.minY + 1
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
return i;
|
|
648
|
+
}
|
|
649
|
+
function Ce(e, t) {
|
|
650
|
+
return e[t * 4 + 3] > 0;
|
|
651
|
+
}
|
|
652
|
+
function we(e, t, n, r, i, a) {
|
|
653
|
+
let o = {
|
|
654
|
+
count: 0,
|
|
655
|
+
minX: n,
|
|
656
|
+
minY: r,
|
|
657
|
+
maxX: n,
|
|
658
|
+
maxY: r
|
|
659
|
+
}, s = [n, r];
|
|
660
|
+
for (; s.length > 0;) {
|
|
661
|
+
let n = s.pop(), r = s.pop();
|
|
662
|
+
if (r < 0 || r >= i || n < 0 || n >= a) continue;
|
|
663
|
+
let c = n * i + r;
|
|
664
|
+
t[c] || Ce(e, c) && (t[c] = 1, o.count += 1, r < o.minX && (o.minX = r), n < o.minY && (o.minY = n), r > o.maxX && (o.maxX = r), n > o.maxY && (o.maxY = n), s.push(r + 1, n), s.push(r - 1, n), s.push(r, n + 1), s.push(r, n - 1));
|
|
665
|
+
}
|
|
666
|
+
return o;
|
|
667
|
+
}
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/diff.ts
|
|
670
|
+
var Te = class extends Error {
|
|
671
|
+
constructor(e, t) {
|
|
672
|
+
super(`Cannot compare screenshots of different dimensions: before is ${e.width}×${e.height}, after is ${t.width}×${t.height}.`), this.name = "DimensionMismatchError";
|
|
673
|
+
}
|
|
401
674
|
};
|
|
402
|
-
function
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
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
|
-
}
|
|
457
|
-
}
|
|
458
|
-
function he(e) {
|
|
459
|
-
const t = y(e);
|
|
460
|
-
return F(e.bbox, {
|
|
461
|
-
stroke: t.stroke,
|
|
462
|
-
strokeWidth: e.strokeWidth ?? 2,
|
|
463
|
-
fill: t.fill
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
function me(e) {
|
|
467
|
-
const t = y(e), r = e.strokeWidth ?? 2;
|
|
468
|
-
return `<circle cx="${e.center.x}" cy="${e.center.y}" r="${e.radius}" fill="${_(t.fill)}" stroke="${_(t.stroke)}" stroke-width="${r}"/>`;
|
|
469
|
-
}
|
|
470
|
-
function pe(e) {
|
|
471
|
-
const t = y(e);
|
|
472
|
-
return z(e.from, e.to, {
|
|
473
|
-
color: t.stroke,
|
|
474
|
-
strokeWidth: e.strokeWidth ?? 2
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
function ye(e) {
|
|
478
|
-
const t = y(e);
|
|
479
|
-
return D(e.at, e.content, {
|
|
480
|
-
color: t.text,
|
|
481
|
-
fontSize: e.fontSize ?? 14,
|
|
482
|
-
anchor: e.anchor ?? "start"
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
function we(e) {
|
|
486
|
-
const t = y(e), r = e.targetBbox, n = xe(r, e.at);
|
|
487
|
-
return F(r, {
|
|
488
|
-
stroke: t.stroke,
|
|
489
|
-
strokeWidth: e.strokeWidth ?? 2,
|
|
490
|
-
fill: t.fill
|
|
491
|
-
}) + z(e.at, n, {
|
|
492
|
-
color: t.stroke,
|
|
493
|
-
strokeWidth: 2
|
|
494
|
-
}) + D(e.at, e.content, {
|
|
495
|
-
color: t.text,
|
|
496
|
-
fontSize: 14,
|
|
497
|
-
anchor: "start"
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
function be(e) {
|
|
501
|
-
return e.svgFragment;
|
|
502
|
-
}
|
|
503
|
-
function xe(e, t) {
|
|
504
|
-
const r = E(t.x, e.x, e.x + e.width), n = E(t.y, e.y, e.y + e.height);
|
|
505
|
-
return { x: r, y: n };
|
|
506
|
-
}
|
|
507
|
-
function E(e, t, r) {
|
|
508
|
-
return Math.min(Math.max(e, t), r);
|
|
675
|
+
async function Ee(e, t, r = {}) {
|
|
676
|
+
let [i, a] = await Promise.all([n(Buffer.from(e)), n(Buffer.from(t))]);
|
|
677
|
+
if (i.width !== a.width || i.height !== a.height) throw new Te({
|
|
678
|
+
width: i.width,
|
|
679
|
+
height: i.height
|
|
680
|
+
}, {
|
|
681
|
+
width: a.width,
|
|
682
|
+
height: a.height
|
|
683
|
+
});
|
|
684
|
+
let { width: o, height: s } = i, c = De(i, o, s), l = De(a, o, s), u = new Uint8Array(o * s * 4);
|
|
685
|
+
return {
|
|
686
|
+
mismatchedPixels: ye(c, l, u, o, s, {
|
|
687
|
+
threshold: r.threshold ?? .1,
|
|
688
|
+
includeAA: !1,
|
|
689
|
+
diffMask: !0
|
|
690
|
+
}),
|
|
691
|
+
regions: K(u, o, s),
|
|
692
|
+
width: o,
|
|
693
|
+
height: s
|
|
694
|
+
};
|
|
509
695
|
}
|
|
510
|
-
function
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
696
|
+
function De(e, n, r) {
|
|
697
|
+
let i = t(n, r).getContext("2d");
|
|
698
|
+
i.drawImage(e, 0, 0);
|
|
699
|
+
let a = i.getImageData(0, 0, n, r).data;
|
|
700
|
+
return new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
701
|
+
}
|
|
702
|
+
//#endregion
|
|
703
|
+
//#region src/flatten-editable-png.ts
|
|
704
|
+
function Oe(e) {
|
|
705
|
+
return b(e);
|
|
706
|
+
}
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/dsl/schema.ts
|
|
709
|
+
var ke = {
|
|
710
|
+
BBox: {
|
|
711
|
+
type: "object",
|
|
712
|
+
required: [
|
|
713
|
+
"x",
|
|
714
|
+
"y",
|
|
715
|
+
"width",
|
|
716
|
+
"height"
|
|
717
|
+
],
|
|
718
|
+
additionalProperties: !1,
|
|
719
|
+
properties: {
|
|
720
|
+
x: { type: "number" },
|
|
721
|
+
y: { type: "number" },
|
|
722
|
+
width: {
|
|
723
|
+
type: "number",
|
|
724
|
+
minimum: 0
|
|
725
|
+
},
|
|
726
|
+
height: {
|
|
727
|
+
type: "number",
|
|
728
|
+
minimum: 0
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
Point: {
|
|
733
|
+
type: "object",
|
|
734
|
+
required: ["x", "y"],
|
|
735
|
+
additionalProperties: !1,
|
|
736
|
+
properties: {
|
|
737
|
+
x: { type: "number" },
|
|
738
|
+
y: { type: "number" }
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
Intent: {
|
|
742
|
+
type: "string",
|
|
743
|
+
enum: [
|
|
744
|
+
"info",
|
|
745
|
+
"warning",
|
|
746
|
+
"error",
|
|
747
|
+
"success",
|
|
748
|
+
"neutral"
|
|
749
|
+
]
|
|
750
|
+
},
|
|
751
|
+
AnnotationStyle: {
|
|
752
|
+
type: "object",
|
|
753
|
+
additionalProperties: !1,
|
|
754
|
+
properties: {
|
|
755
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
756
|
+
stroke: { type: "string" },
|
|
757
|
+
strokeWidth: {
|
|
758
|
+
type: "number",
|
|
759
|
+
minimum: 0
|
|
760
|
+
},
|
|
761
|
+
fill: { type: "string" },
|
|
762
|
+
color: { type: "string" }
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}, Ae = { oneOf: [
|
|
766
|
+
{
|
|
767
|
+
type: "object",
|
|
768
|
+
required: ["type", "bbox"],
|
|
769
|
+
additionalProperties: !1,
|
|
770
|
+
properties: {
|
|
771
|
+
type: { const: "rect" },
|
|
772
|
+
bbox: { $ref: "#/$defs/BBox" },
|
|
773
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
774
|
+
stroke: { type: "string" },
|
|
775
|
+
strokeWidth: {
|
|
776
|
+
type: "number",
|
|
777
|
+
minimum: 0
|
|
778
|
+
},
|
|
779
|
+
fill: { type: "string" },
|
|
780
|
+
color: { type: "string" }
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
type: "object",
|
|
785
|
+
required: [
|
|
786
|
+
"type",
|
|
787
|
+
"center",
|
|
788
|
+
"radius"
|
|
789
|
+
],
|
|
790
|
+
additionalProperties: !1,
|
|
791
|
+
properties: {
|
|
792
|
+
type: { const: "circle" },
|
|
793
|
+
center: { $ref: "#/$defs/Point" },
|
|
794
|
+
radius: {
|
|
795
|
+
type: "number",
|
|
796
|
+
minimum: 0
|
|
797
|
+
},
|
|
798
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
799
|
+
stroke: { type: "string" },
|
|
800
|
+
strokeWidth: {
|
|
801
|
+
type: "number",
|
|
802
|
+
minimum: 0
|
|
803
|
+
},
|
|
804
|
+
fill: { type: "string" },
|
|
805
|
+
color: { type: "string" }
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
type: "object",
|
|
810
|
+
required: [
|
|
811
|
+
"type",
|
|
812
|
+
"from",
|
|
813
|
+
"to"
|
|
814
|
+
],
|
|
815
|
+
additionalProperties: !1,
|
|
816
|
+
properties: {
|
|
817
|
+
type: { const: "arrow" },
|
|
818
|
+
from: { $ref: "#/$defs/Point" },
|
|
819
|
+
to: { $ref: "#/$defs/Point" },
|
|
820
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
821
|
+
stroke: { type: "string" },
|
|
822
|
+
strokeWidth: {
|
|
823
|
+
type: "number",
|
|
824
|
+
minimum: 0
|
|
825
|
+
},
|
|
826
|
+
color: { type: "string" }
|
|
827
|
+
}
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
type: "object",
|
|
831
|
+
required: [
|
|
832
|
+
"type",
|
|
833
|
+
"at",
|
|
834
|
+
"content"
|
|
835
|
+
],
|
|
836
|
+
additionalProperties: !1,
|
|
837
|
+
properties: {
|
|
838
|
+
type: { const: "text" },
|
|
839
|
+
at: { $ref: "#/$defs/Point" },
|
|
840
|
+
content: { type: "string" },
|
|
841
|
+
fontSize: {
|
|
842
|
+
type: "number",
|
|
843
|
+
minimum: 0
|
|
844
|
+
},
|
|
845
|
+
anchor: {
|
|
846
|
+
type: "string",
|
|
847
|
+
enum: [
|
|
848
|
+
"start",
|
|
849
|
+
"middle",
|
|
850
|
+
"end"
|
|
851
|
+
]
|
|
852
|
+
},
|
|
853
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
854
|
+
color: { type: "string" }
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
type: "object",
|
|
859
|
+
required: [
|
|
860
|
+
"type",
|
|
861
|
+
"at",
|
|
862
|
+
"targetBbox",
|
|
863
|
+
"content"
|
|
864
|
+
],
|
|
865
|
+
additionalProperties: !1,
|
|
866
|
+
properties: {
|
|
867
|
+
type: { const: "callout" },
|
|
868
|
+
at: { $ref: "#/$defs/Point" },
|
|
869
|
+
targetBbox: { $ref: "#/$defs/BBox" },
|
|
870
|
+
content: { type: "string" },
|
|
871
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
872
|
+
stroke: { type: "string" },
|
|
873
|
+
color: { type: "string" }
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
type: "object",
|
|
878
|
+
required: [
|
|
879
|
+
"type",
|
|
880
|
+
"bbox",
|
|
881
|
+
"number"
|
|
882
|
+
],
|
|
883
|
+
additionalProperties: !1,
|
|
884
|
+
properties: {
|
|
885
|
+
type: { const: "numberedBadge" },
|
|
886
|
+
bbox: { $ref: "#/$defs/BBox" },
|
|
887
|
+
number: { type: "number" },
|
|
888
|
+
placement: {
|
|
889
|
+
type: "string",
|
|
890
|
+
enum: [
|
|
891
|
+
"auto",
|
|
892
|
+
"topLeft",
|
|
893
|
+
"topRight",
|
|
894
|
+
"bottomLeft",
|
|
895
|
+
"bottomRight"
|
|
896
|
+
]
|
|
897
|
+
},
|
|
898
|
+
badgeSize: {
|
|
899
|
+
type: "number",
|
|
900
|
+
minimum: 0
|
|
901
|
+
},
|
|
902
|
+
imageWidth: {
|
|
903
|
+
type: "number",
|
|
904
|
+
minimum: 0
|
|
905
|
+
},
|
|
906
|
+
imageHeight: {
|
|
907
|
+
type: "number",
|
|
908
|
+
minimum: 0
|
|
909
|
+
},
|
|
910
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
911
|
+
stroke: { type: "string" },
|
|
912
|
+
strokeWidth: {
|
|
913
|
+
type: "number",
|
|
914
|
+
minimum: 0
|
|
915
|
+
},
|
|
916
|
+
fill: { type: "string" },
|
|
917
|
+
color: { type: "string" }
|
|
918
|
+
}
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
type: "object",
|
|
922
|
+
required: ["type", "path"],
|
|
923
|
+
additionalProperties: !1,
|
|
924
|
+
properties: {
|
|
925
|
+
type: { const: "freehand" },
|
|
926
|
+
path: {
|
|
927
|
+
type: "string",
|
|
928
|
+
minLength: 1
|
|
929
|
+
},
|
|
930
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
931
|
+
stroke: { type: "string" },
|
|
932
|
+
strokeWidth: {
|
|
933
|
+
type: "number",
|
|
934
|
+
minimum: 0
|
|
935
|
+
},
|
|
936
|
+
fill: { type: "string" },
|
|
937
|
+
color: { type: "string" }
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
type: "object",
|
|
942
|
+
required: [
|
|
943
|
+
"type",
|
|
944
|
+
"cutout",
|
|
945
|
+
"imageWidth",
|
|
946
|
+
"imageHeight"
|
|
947
|
+
],
|
|
948
|
+
additionalProperties: !1,
|
|
949
|
+
properties: {
|
|
950
|
+
type: { const: "focusMask" },
|
|
951
|
+
cutout: { $ref: "#/$defs/BBox" },
|
|
952
|
+
imageWidth: {
|
|
953
|
+
type: "number",
|
|
954
|
+
minimum: 0
|
|
955
|
+
},
|
|
956
|
+
imageHeight: {
|
|
957
|
+
type: "number",
|
|
958
|
+
minimum: 0
|
|
959
|
+
},
|
|
960
|
+
dimColor: { type: "string" },
|
|
961
|
+
intent: { $ref: "#/$defs/Intent" },
|
|
962
|
+
stroke: { type: "string" },
|
|
963
|
+
strokeWidth: {
|
|
964
|
+
type: "number",
|
|
965
|
+
minimum: 0
|
|
966
|
+
},
|
|
967
|
+
fill: { type: "string" },
|
|
968
|
+
color: { type: "string" }
|
|
969
|
+
}
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
type: "object",
|
|
973
|
+
required: ["type", "svgFragment"],
|
|
974
|
+
additionalProperties: !1,
|
|
975
|
+
properties: {
|
|
976
|
+
type: { const: "raw" },
|
|
977
|
+
svgFragment: { type: "string" }
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
] }, je = {
|
|
981
|
+
type: "object",
|
|
982
|
+
required: ["bbox"],
|
|
983
|
+
additionalProperties: !1,
|
|
984
|
+
properties: {
|
|
985
|
+
bbox: { $ref: "#/$defs/BBox" },
|
|
986
|
+
style: {
|
|
987
|
+
type: "string",
|
|
988
|
+
enum: [
|
|
989
|
+
"solid",
|
|
990
|
+
"mosaic",
|
|
991
|
+
"blur"
|
|
992
|
+
]
|
|
993
|
+
},
|
|
994
|
+
color: { type: "string" }
|
|
995
|
+
}
|
|
530
996
|
};
|
|
997
|
+
//#endregion
|
|
998
|
+
//#region src/dsl/svg-primitives.ts
|
|
999
|
+
function q(e, t = {}) {
|
|
1000
|
+
let n = t.stroke ?? "red", r = t.strokeWidth ?? 2, i = t.fill ?? "none";
|
|
1001
|
+
return `<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${Z(i)}" stroke="${Z(n)}" stroke-width="${r}"/>`;
|
|
1002
|
+
}
|
|
1003
|
+
function J(e, t, n = {}) {
|
|
1004
|
+
let r = n.color ?? "red", i = n.strokeWidth ?? 2, a = `annot-arrow-${Me()}`;
|
|
1005
|
+
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="${Z(r)}"/></marker></defs><line x1="${e.x}" y1="${e.y}" x2="${t.x}" y2="${t.y}" stroke="${Z(r)}" stroke-width="${i}" marker-end="url(#${a})"/>`;
|
|
1006
|
+
}
|
|
1007
|
+
function Y(e, t, n = {}) {
|
|
1008
|
+
let r = n.color ?? "red", i = n.fontSize ?? 14, a = n.anchor ?? "start";
|
|
1009
|
+
return `<text x="${e.x}" y="${e.y}" fill="${Z(r)}" font-size="${i}" text-anchor="${a}">` + Ne(t) + "</text>";
|
|
1010
|
+
}
|
|
1011
|
+
var X = 0;
|
|
1012
|
+
function Me() {
|
|
1013
|
+
return X = X + 1 | 0, X;
|
|
1014
|
+
}
|
|
1015
|
+
function Z(e) {
|
|
1016
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1017
|
+
}
|
|
1018
|
+
function Ne(e) {
|
|
1019
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1020
|
+
}
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region src/dsl/to-svg.ts
|
|
1023
|
+
var Pe = {
|
|
1024
|
+
info: {
|
|
1025
|
+
stroke: "#3b82f6",
|
|
1026
|
+
fill: "rgba(59, 130, 246, 0.12)",
|
|
1027
|
+
text: "#1e40af"
|
|
1028
|
+
},
|
|
1029
|
+
warning: {
|
|
1030
|
+
stroke: "#f59e0b",
|
|
1031
|
+
fill: "rgba(245, 158, 11, 0.12)",
|
|
1032
|
+
text: "#92400e"
|
|
1033
|
+
},
|
|
1034
|
+
error: {
|
|
1035
|
+
stroke: "#ef4444",
|
|
1036
|
+
fill: "rgba(239, 68, 68, 0.12)",
|
|
1037
|
+
text: "#991b1b"
|
|
1038
|
+
},
|
|
1039
|
+
success: {
|
|
1040
|
+
stroke: "#10b981",
|
|
1041
|
+
fill: "rgba(16, 185, 129, 0.12)",
|
|
1042
|
+
text: "#065f46"
|
|
1043
|
+
},
|
|
1044
|
+
neutral: {
|
|
1045
|
+
stroke: "#6b7280",
|
|
1046
|
+
fill: "rgba(107, 114, 128, 0.12)",
|
|
1047
|
+
text: "#374151"
|
|
1048
|
+
}
|
|
1049
|
+
}, Fe = "error";
|
|
1050
|
+
function Q(e) {
|
|
1051
|
+
let t = Pe[e.intent ?? Fe];
|
|
1052
|
+
return {
|
|
1053
|
+
stroke: e.stroke ?? t.stroke,
|
|
1054
|
+
fill: e.fill ?? "none",
|
|
1055
|
+
text: e.color ?? t.text
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function Ie(e) {
|
|
1059
|
+
return e.map(Le).join("");
|
|
1060
|
+
}
|
|
1061
|
+
function Le(e) {
|
|
1062
|
+
switch (e.type) {
|
|
1063
|
+
case "rect": return Re(e);
|
|
1064
|
+
case "circle": return ze(e);
|
|
1065
|
+
case "arrow": return Be(e);
|
|
1066
|
+
case "text": return Ve(e);
|
|
1067
|
+
case "callout": return He(e);
|
|
1068
|
+
case "numberedBadge": return Je(e);
|
|
1069
|
+
case "freehand": return We(e);
|
|
1070
|
+
case "focusMask": return Ke(e);
|
|
1071
|
+
case "raw": return Ue(e);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
function Re(e) {
|
|
1075
|
+
let t = Q(e);
|
|
1076
|
+
return q(e.bbox, {
|
|
1077
|
+
stroke: t.stroke,
|
|
1078
|
+
strokeWidth: e.strokeWidth ?? 2,
|
|
1079
|
+
fill: t.fill
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
function ze(e) {
|
|
1083
|
+
let t = Q(e), n = e.strokeWidth ?? 2;
|
|
1084
|
+
return `<circle cx="${e.center.x}" cy="${e.center.y}" r="${e.radius}" fill="${$(t.fill)}" stroke="${$(t.stroke)}" stroke-width="${n}"/>`;
|
|
1085
|
+
}
|
|
1086
|
+
function Be(e) {
|
|
1087
|
+
let t = Q(e);
|
|
1088
|
+
return J(e.from, e.to, {
|
|
1089
|
+
color: t.stroke,
|
|
1090
|
+
strokeWidth: e.strokeWidth ?? 2
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
function Ve(e) {
|
|
1094
|
+
let t = Q(e);
|
|
1095
|
+
return Y(e.at, e.content, {
|
|
1096
|
+
color: t.text,
|
|
1097
|
+
fontSize: e.fontSize ?? 14,
|
|
1098
|
+
anchor: e.anchor ?? "start"
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
function He(e) {
|
|
1102
|
+
let t = Q(e), n = e.targetBbox, r = Ze(n, e.at);
|
|
1103
|
+
return q(n, {
|
|
1104
|
+
stroke: t.stroke,
|
|
1105
|
+
strokeWidth: e.strokeWidth ?? 2,
|
|
1106
|
+
fill: t.fill
|
|
1107
|
+
}) + J(e.at, r, {
|
|
1108
|
+
color: t.stroke,
|
|
1109
|
+
strokeWidth: 2
|
|
1110
|
+
}) + Y(e.at, e.content, {
|
|
1111
|
+
color: t.text,
|
|
1112
|
+
fontSize: 14,
|
|
1113
|
+
anchor: "start"
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
function Ue(e) {
|
|
1117
|
+
return e.svgFragment;
|
|
1118
|
+
}
|
|
1119
|
+
function We(e) {
|
|
1120
|
+
let t = Q(e), n = e.fill ?? "none", r = e.strokeWidth ?? 2;
|
|
1121
|
+
return `<path d="${$(e.path)}" fill="${$(n)}" stroke="${$(t.stroke)}" stroke-width="${r}" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
1122
|
+
}
|
|
1123
|
+
var Ge = "rgba(0,0,0,0.5)";
|
|
1124
|
+
function Ke(e) {
|
|
1125
|
+
let { cutout: t, imageWidth: n, imageHeight: r } = e, i = e.dimColor ?? Ge;
|
|
1126
|
+
return `<path d="${$(`M0,0 H${n} V${r} H0 Z M${t.x},${t.y} H${t.x + t.width} V${t.y + t.height} H${t.x} Z`)}" fill="${$(i)}" fill-rule="evenodd" stroke="none"/>`;
|
|
1127
|
+
}
|
|
1128
|
+
var qe = 40;
|
|
1129
|
+
function Je(e) {
|
|
1130
|
+
let t = Q(e), n = e.badgeSize ?? qe, r = Ye(e, n), i = q(e.bbox, {
|
|
1131
|
+
stroke: t.stroke,
|
|
1132
|
+
strokeWidth: e.strokeWidth ?? 3,
|
|
1133
|
+
fill: e.fill ?? "none"
|
|
1134
|
+
}), a = Xe(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>`;
|
|
1135
|
+
return i + s + l;
|
|
1136
|
+
}
|
|
1137
|
+
function Ye(e, t) {
|
|
1138
|
+
if (e.placement && e.placement !== "auto") return e.placement;
|
|
1139
|
+
if (e.imageWidth === void 0 || e.imageHeight === void 0) return "topRight";
|
|
1140
|
+
let n = t / 2, r = [
|
|
1141
|
+
{
|
|
1142
|
+
kind: "topLeft",
|
|
1143
|
+
x: e.bbox.x,
|
|
1144
|
+
y: e.bbox.y
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
kind: "topRight",
|
|
1148
|
+
x: e.bbox.x + e.bbox.width,
|
|
1149
|
+
y: e.bbox.y
|
|
1150
|
+
},
|
|
1151
|
+
{
|
|
1152
|
+
kind: "bottomLeft",
|
|
1153
|
+
x: e.bbox.x,
|
|
1154
|
+
y: e.bbox.y + e.bbox.height
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
kind: "bottomRight",
|
|
1158
|
+
x: e.bbox.x + e.bbox.width,
|
|
1159
|
+
y: e.bbox.y + e.bbox.height
|
|
1160
|
+
}
|
|
1161
|
+
], i = r[0], a = -Infinity;
|
|
1162
|
+
for (let t of r) {
|
|
1163
|
+
let r = Math.min(t.x - n, t.y - n, e.imageWidth - t.x - n, e.imageHeight - t.y - n);
|
|
1164
|
+
r > a && (a = r, i = t);
|
|
1165
|
+
}
|
|
1166
|
+
return i.kind;
|
|
1167
|
+
}
|
|
1168
|
+
function Xe(e, t) {
|
|
1169
|
+
switch (t) {
|
|
1170
|
+
case "topLeft": return {
|
|
1171
|
+
x: e.x,
|
|
1172
|
+
y: e.y
|
|
1173
|
+
};
|
|
1174
|
+
case "topRight": return {
|
|
1175
|
+
x: e.x + e.width,
|
|
1176
|
+
y: e.y
|
|
1177
|
+
};
|
|
1178
|
+
case "bottomLeft": return {
|
|
1179
|
+
x: e.x,
|
|
1180
|
+
y: e.y + e.height
|
|
1181
|
+
};
|
|
1182
|
+
case "bottomRight": return {
|
|
1183
|
+
x: e.x + e.width,
|
|
1184
|
+
y: e.y + e.height
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function Ze(e, t) {
|
|
1189
|
+
return {
|
|
1190
|
+
x: Qe(t.x, e.x, e.x + e.width),
|
|
1191
|
+
y: Qe(t.y, e.y, e.y + e.height)
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
function Qe(e, t, n) {
|
|
1195
|
+
return Math.min(Math.max(e, t), n);
|
|
1196
|
+
}
|
|
1197
|
+
function $(e) {
|
|
1198
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1199
|
+
}
|
|
1200
|
+
//#endregion
|
|
1201
|
+
export { Ae as BBOX_ANNOTATION_SCHEMA, je as BBOX_REDACT_REGION_SCHEMA, T as DEFAULT_ENCODE_OPTIONS, Te as DimensionMismatchError, w as SAVE_SIZE_LABEL, C as SAVE_SIZE_MAX_WIDTH, ke as SHARED_DEFS, K as aggregateDiffRegions, J as arrowBetween, Ie as bboxAnnotationsToSvg, B as burnRedactions, ve as burnRegions, E as computeResizeTarget, de as createAnnotator, se as decodeAndEncodeImage, Ee as diffScreenshots, F as encodeRgba, Oe as flattenEditablePng, P as isPhotoHeavy, q as rectForBoundingBox, Y as textAt };
|