msdfgen-ts 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -4
- package/dist/atlas-worker.js +1380 -1117
- package/dist/msdfgen-ts.iife.js +3 -2
- package/dist/msdfgen-ts.js +2020 -1402
- package/dist/types/atlas-gen.d.ts +51 -25
- package/dist/types/font/tables/glyf.d.ts +3 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/msdf/shape-msdf.d.ts +51 -0
- package/dist/types/shape/normalize.d.ts +12 -1
- package/dist/types/shape/union.d.ts +58 -0
- package/dist/types/svg/svg.d.ts +78 -0
- package/package.json +38 -18
package/dist/msdfgen-ts.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
function
|
|
2
|
-
return
|
|
3
|
-
}
|
|
4
|
-
function
|
|
5
|
-
return
|
|
6
|
-
}
|
|
7
|
-
function
|
|
8
|
-
return (1 -
|
|
9
|
-
}
|
|
10
|
-
function
|
|
11
|
-
return +(
|
|
12
|
-
}
|
|
13
|
-
function
|
|
14
|
-
return 2 * +(
|
|
15
|
-
}
|
|
16
|
-
function $s
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
return
|
|
23
|
-
} else if (
|
|
24
|
-
return
|
|
1
|
+
function Ko(s, t, n, o) {
|
|
2
|
+
return s * n + t * o;
|
|
3
|
+
}
|
|
4
|
+
function K(s, t, n, o) {
|
|
5
|
+
return s * o - t * n;
|
|
6
|
+
}
|
|
7
|
+
function Po(s, t, n) {
|
|
8
|
+
return (1 - n) * s + n * t;
|
|
9
|
+
}
|
|
10
|
+
function ft(s) {
|
|
11
|
+
return +(s > 0) - +(s < 0);
|
|
12
|
+
}
|
|
13
|
+
function St(s) {
|
|
14
|
+
return 2 * +(s > 0) - 1;
|
|
15
|
+
}
|
|
16
|
+
function $o(s, t, n, o) {
|
|
17
|
+
if (t === 0 || Math.abs(n) > 1e12 * Math.abs(t))
|
|
18
|
+
return n === 0 ? o === 0 ? -1 : 0 : (s[0] = -o / n, 1);
|
|
19
|
+
const e = n * n - 4 * t * o;
|
|
20
|
+
if (e > 0) {
|
|
21
|
+
const i = Math.sqrt(e);
|
|
22
|
+
return s[0] = (-n + i) / (2 * t), s[1] = (-n - i) / (2 * t), 2;
|
|
23
|
+
} else if (e === 0)
|
|
24
|
+
return s[0] = -n / (2 * t), 1;
|
|
25
25
|
return 0;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
if (c <
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
return
|
|
27
|
+
function Zo(s, t, n, o) {
|
|
28
|
+
const e = t * t, i = 1 / 9 * (e - 3 * n), r = 1 / 54 * (t * (2 * e - 9 * n) + 27 * o), c = r * r, a = i * i * i, l = t * (1 / 3);
|
|
29
|
+
if (c < a) {
|
|
30
|
+
let h = r / Math.sqrt(a);
|
|
31
|
+
h < -1 && (h = -1), h > 1 && (h = 1), h = Math.acos(h);
|
|
32
|
+
const p = -2 * Math.sqrt(i);
|
|
33
|
+
return s[0] = p * Math.cos(1 / 3 * h) - l, s[1] = p * Math.cos(1 / 3 * (h + 2 * Math.PI)) - l, s[2] = p * Math.cos(1 / 3 * (h - 2 * Math.PI)) - l, 3;
|
|
34
34
|
} else {
|
|
35
|
-
const
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
42
|
-
if (Math.abs(
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
return $s
|
|
46
|
-
}
|
|
47
|
-
const
|
|
48
|
-
function
|
|
49
|
-
return ((
|
|
50
|
-
}
|
|
51
|
-
function
|
|
52
|
-
const c =
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
for (let
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
let f =
|
|
61
|
-
f >
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
}
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
function
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
74
|
-
const f = -
|
|
75
|
-
return f >=
|
|
76
|
-
}
|
|
77
|
-
const c =
|
|
35
|
+
const h = (r < 0 ? 1 : -1) * Math.pow(Math.abs(r) + Math.sqrt(c - a), 0.3333333333333333), p = h === 0 ? 0 : i / h;
|
|
36
|
+
return s[0] = h + p - l, h === p || Math.abs(h - p) < 1e-12 * Math.abs(h + p) ? (s[1] = -0.5 * (h + p) - l, 2) : 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function Jo(s, t, n, o, e) {
|
|
40
|
+
if (t !== 0) {
|
|
41
|
+
const i = n / t;
|
|
42
|
+
if (Math.abs(i) < 1e6)
|
|
43
|
+
return Zo(s, i, o / t, e / t);
|
|
44
|
+
}
|
|
45
|
+
return $o(s, n, o, e);
|
|
46
|
+
}
|
|
47
|
+
const te = 24;
|
|
48
|
+
function Qt(s, t, n, o) {
|
|
49
|
+
return ((o + s) * o + t) * o + n;
|
|
50
|
+
}
|
|
51
|
+
function ne(s, t, n, o, e, i, r) {
|
|
52
|
+
const c = i < 0;
|
|
53
|
+
let a = o - i * (e - o) / (r - i);
|
|
54
|
+
a > o && a < e || (a = 0.5 * (o + e));
|
|
55
|
+
for (let l = 0; l < te; l++) {
|
|
56
|
+
const h = Qt(s, t, n, a);
|
|
57
|
+
if (h === 0) return a;
|
|
58
|
+
h < 0 === c ? o = a : e = a;
|
|
59
|
+
const p = (3 * a + 2 * s) * a + t;
|
|
60
|
+
let f = a - h / p;
|
|
61
|
+
f > o && f < e || (f = 0.5 * (o + e));
|
|
62
|
+
const u = f - a;
|
|
63
|
+
if (a = f, (u < 0 ? -u : u) <= 1e-15 * (a < 0 ? -a : a)) break;
|
|
64
|
+
}
|
|
65
|
+
return a;
|
|
66
|
+
}
|
|
67
|
+
function fn(s, t, n, o, e, i, r, c, a) {
|
|
68
|
+
return i === 0 ? c[a++] = o : i < 0 != r < 0 && (c[a++] = ne(s, t, n, o, e, i, r)), a;
|
|
69
|
+
}
|
|
70
|
+
function se(s, t, n, o, e, i) {
|
|
71
|
+
let r = 0;
|
|
72
|
+
if (s === 0) {
|
|
73
|
+
if (t === 0) return 0;
|
|
74
|
+
const f = -n / t;
|
|
75
|
+
return f >= o && f <= e && (i[r++] = f), r;
|
|
76
|
+
}
|
|
77
|
+
const c = t * t - 4 * s * n;
|
|
78
78
|
if (c < 0) return 0;
|
|
79
|
-
const
|
|
80
|
-
let
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
else if (
|
|
84
|
-
const f =
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
function
|
|
90
|
-
if (
|
|
91
|
-
const c = 1 /
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
let
|
|
95
|
-
if (
|
|
96
|
-
|
|
79
|
+
const a = Math.sqrt(c), l = -0.5 * (t + (t < 0 ? -a : a));
|
|
80
|
+
let h, p;
|
|
81
|
+
if (l === 0)
|
|
82
|
+
h = 0, p = 0;
|
|
83
|
+
else if (h = l / s, p = n / l, h > p) {
|
|
84
|
+
const f = h;
|
|
85
|
+
h = p, p = f;
|
|
86
|
+
}
|
|
87
|
+
return h >= o && h <= e && (i[r++] = h), p !== h && p >= o && p <= e && (i[r++] = p), r;
|
|
88
|
+
}
|
|
89
|
+
function oe(s, t, n, o, e, i, r) {
|
|
90
|
+
if (s === 0) return se(t, n, o, e, i, r);
|
|
91
|
+
const c = 1 / s;
|
|
92
|
+
t *= c, n *= c, o *= c;
|
|
93
|
+
const a = Qt(t, n, o, e), l = Qt(t, n, o, i), h = t * t - 3 * n;
|
|
94
|
+
let p = 0;
|
|
95
|
+
if (h <= 0)
|
|
96
|
+
p = fn(t, n, o, e, i, a, l, r, 0);
|
|
97
97
|
else {
|
|
98
|
-
const f = Math.sqrt(
|
|
99
|
-
let
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
|
|
98
|
+
const f = Math.sqrt(h) / 3, u = -t / 3, y = u - f, x = u + f;
|
|
99
|
+
let g = e, M = a;
|
|
100
|
+
if (y > e && y < i) {
|
|
101
|
+
const b = Qt(t, n, o, y);
|
|
102
|
+
p = fn(t, n, o, g, y, M, b, r, p), g = y, M = b;
|
|
103
103
|
}
|
|
104
|
-
if (
|
|
105
|
-
const
|
|
106
|
-
|
|
104
|
+
if (x > e && x < i) {
|
|
105
|
+
const b = Qt(t, n, o, x);
|
|
106
|
+
p = fn(t, n, o, g, x, M, b, r, p), g = x, M = b;
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
p = fn(t, n, o, g, i, M, l, r, p);
|
|
109
109
|
}
|
|
110
|
-
return
|
|
110
|
+
return l === 0 && (r[p++] = i), p;
|
|
111
111
|
}
|
|
112
|
-
const
|
|
113
|
-
class
|
|
112
|
+
const nt = 0, ct = 1, Ct = 2, co = 4, ee = 4, B = [0, 0, 0];
|
|
113
|
+
class st {
|
|
114
114
|
/**
|
|
115
115
|
* @param type Segment type (LINEAR=0, QUADRATIC=1, CUBIC=2).
|
|
116
116
|
* @param p0x Start x.
|
|
@@ -122,15 +122,15 @@ class et {
|
|
|
122
122
|
* @param p3x CUBIC: end x. Others: 0.
|
|
123
123
|
* @param p3y CUBIC: end y. Others: 0.
|
|
124
124
|
*/
|
|
125
|
-
constructor(n,
|
|
126
|
-
this.type =
|
|
125
|
+
constructor(t, n, o, e, i, r, c, a, l) {
|
|
126
|
+
this.type = t, this.p0x = n, this.p0y = o, this.p1x = e, this.p1y = i, this.p2x = r, this.p2y = c, this.p3x = a, this.p3y = l, this.color = 7;
|
|
127
127
|
}
|
|
128
128
|
/** Endpoint x (the on-curve destination of this segment). */
|
|
129
129
|
endX() {
|
|
130
130
|
switch (this.type) {
|
|
131
|
-
case
|
|
131
|
+
case nt:
|
|
132
132
|
return this.p1x;
|
|
133
|
-
case
|
|
133
|
+
case ct:
|
|
134
134
|
return this.p2x;
|
|
135
135
|
default:
|
|
136
136
|
return this.p3x;
|
|
@@ -139,9 +139,9 @@ class et {
|
|
|
139
139
|
/** Endpoint y. */
|
|
140
140
|
endY() {
|
|
141
141
|
switch (this.type) {
|
|
142
|
-
case
|
|
142
|
+
case nt:
|
|
143
143
|
return this.p1y;
|
|
144
|
-
case
|
|
144
|
+
case ct:
|
|
145
145
|
return this.p2y;
|
|
146
146
|
default:
|
|
147
147
|
return this.p3y;
|
|
@@ -154,21 +154,21 @@ class et {
|
|
|
154
154
|
* @param param Parameter t.
|
|
155
155
|
* @param out Two-element array [x, y] to write into (reuse to avoid allocation).
|
|
156
156
|
*/
|
|
157
|
-
point(
|
|
158
|
-
const
|
|
157
|
+
point(t, n) {
|
|
158
|
+
const o = t;
|
|
159
159
|
switch (this.type) {
|
|
160
|
-
case
|
|
161
|
-
|
|
160
|
+
case nt: {
|
|
161
|
+
n[0] = this.p0x + o * (this.p1x - this.p0x), n[1] = this.p0y + o * (this.p1y - this.p0y);
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
case
|
|
165
|
-
const
|
|
166
|
-
|
|
164
|
+
case ct: {
|
|
165
|
+
const e = this.p0x + o * (this.p1x - this.p0x), i = this.p0y + o * (this.p1y - this.p0y), r = this.p1x + o * (this.p2x - this.p1x), c = this.p1y + o * (this.p2y - this.p1y);
|
|
166
|
+
n[0] = e + o * (r - e), n[1] = i + o * (c - i);
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
169
|
default: {
|
|
170
|
-
const
|
|
171
|
-
|
|
170
|
+
const e = this.p0x + o * (this.p1x - this.p0x), i = this.p0y + o * (this.p1y - this.p0y), r = this.p1x + o * (this.p2x - this.p1x), c = this.p1y + o * (this.p2y - this.p1y), a = this.p2x + o * (this.p3x - this.p2x), l = this.p2y + o * (this.p3y - this.p2y), h = e + o * (r - e), p = i + o * (c - i), f = r + o * (a - r), u = c + o * (l - c);
|
|
171
|
+
n[0] = h + o * (f - h), n[1] = p + o * (u - p);
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -180,21 +180,21 @@ class et {
|
|
|
180
180
|
* @param param Parameter t.
|
|
181
181
|
* @param out Two-element array [dx, dy] to write into.
|
|
182
182
|
*/
|
|
183
|
-
direction(
|
|
184
|
-
const
|
|
183
|
+
direction(t, n) {
|
|
184
|
+
const o = t;
|
|
185
185
|
switch (this.type) {
|
|
186
|
-
case
|
|
187
|
-
|
|
186
|
+
case nt: {
|
|
187
|
+
n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
|
-
case
|
|
191
|
-
const
|
|
192
|
-
|
|
190
|
+
case ct: {
|
|
191
|
+
const e = this.p1x - this.p0x + o * (this.p2x - this.p1x - (this.p1x - this.p0x)), i = this.p1y - this.p0y + o * (this.p2y - this.p1y - (this.p1y - this.p0y));
|
|
192
|
+
e !== 0 || i !== 0 ? (n[0] = e, n[1] = i) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
195
|
default: {
|
|
196
|
-
const
|
|
197
|
-
|
|
196
|
+
const e = this.p1x - this.p0x, i = this.p1y - this.p0y, r = this.p2x - this.p1x, c = this.p2y - this.p1y, a = this.p3x - this.p2x, l = this.p3y - this.p2y, h = e + o * (r - e) + o * (r + o * (a - r) - (e + o * (r - e))), p = i + o * (c - i) + o * (c + o * (l - c) - (i + o * (c - i)));
|
|
197
|
+
h !== 0 || p !== 0 ? (n[0] = h, n[1] = p) : o === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : o === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = h, n[1] = p);
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
}
|
|
@@ -207,82 +207,82 @@ class et {
|
|
|
207
207
|
* @returns Tuple [part0, part1, part2].
|
|
208
208
|
*/
|
|
209
209
|
splitInThirds() {
|
|
210
|
-
const
|
|
210
|
+
const t = [0, 0], n = [0, 0];
|
|
211
211
|
switch (this.type) {
|
|
212
|
-
case
|
|
213
|
-
this.point(1 / 3,
|
|
214
|
-
const
|
|
215
|
-
return
|
|
212
|
+
case nt: {
|
|
213
|
+
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
214
|
+
const o = new st(nt, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), e = new st(nt, t[0], t[1], n[0], n[1], 0, 0, 0, 0), i = new st(nt, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
|
|
215
|
+
return o.color = e.color = i.color = this.color, [o, e, i];
|
|
216
216
|
}
|
|
217
|
-
case
|
|
218
|
-
this.point(1 / 3,
|
|
219
|
-
const
|
|
220
|
-
|
|
217
|
+
case ct: {
|
|
218
|
+
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
219
|
+
const o = this.p0x + 1 / 3 * (this.p1x - this.p0x), e = this.p0y + 1 / 3 * (this.p1y - this.p0y), i = this.p0x + 5 / 9 * (this.p1x - this.p0x), r = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), a = this.p1y + 4 / 9 * (this.p2y - this.p1y), l = i + 0.5 * (c - i), h = r + 0.5 * (a - r), p = this.p1x + 2 / 3 * (this.p2x - this.p1x), f = this.p1y + 2 / 3 * (this.p2y - this.p1y), u = new st(
|
|
220
|
+
ct,
|
|
221
221
|
this.p0x,
|
|
222
222
|
this.p0y,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
n[0],
|
|
226
|
-
n[1],
|
|
227
|
-
0,
|
|
228
|
-
0
|
|
229
|
-
), _ = new et(
|
|
230
|
-
it,
|
|
231
|
-
n[0],
|
|
232
|
-
n[1],
|
|
233
|
-
h,
|
|
234
|
-
l,
|
|
223
|
+
o,
|
|
224
|
+
e,
|
|
235
225
|
t[0],
|
|
236
226
|
t[1],
|
|
237
227
|
0,
|
|
238
228
|
0
|
|
239
|
-
),
|
|
240
|
-
|
|
229
|
+
), y = new st(
|
|
230
|
+
ct,
|
|
241
231
|
t[0],
|
|
242
232
|
t[1],
|
|
243
|
-
|
|
233
|
+
l,
|
|
234
|
+
h,
|
|
235
|
+
n[0],
|
|
236
|
+
n[1],
|
|
237
|
+
0,
|
|
238
|
+
0
|
|
239
|
+
), x = new st(
|
|
240
|
+
ct,
|
|
241
|
+
n[0],
|
|
242
|
+
n[1],
|
|
243
|
+
p,
|
|
244
244
|
f,
|
|
245
245
|
this.p2x,
|
|
246
246
|
this.p2y,
|
|
247
247
|
0,
|
|
248
248
|
0
|
|
249
249
|
);
|
|
250
|
-
return
|
|
250
|
+
return u.color = y.color = x.color = this.color, [u, y, x];
|
|
251
251
|
}
|
|
252
252
|
default: {
|
|
253
|
-
this.point(1 / 3,
|
|
254
|
-
const
|
|
255
|
-
|
|
253
|
+
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
254
|
+
const o = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), e = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), i = this.p0x + 1 / 3 * (this.p1x - this.p0x), r = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), a = this.p1y + 1 / 3 * (this.p2y - this.p1y), l = this.p2x + 1 / 3 * (this.p3x - this.p2x), h = this.p2y + 1 / 3 * (this.p3y - this.p2y), p = i + 1 / 3 * (c - i), f = r + 1 / 3 * (a - r), u = c + 1 / 3 * (l - c), y = a + 1 / 3 * (h - a), x = p + 2 / 3 * (u - p), g = f + 2 / 3 * (y - f), M = this.p0x + 2 / 3 * (this.p1x - this.p0x), b = this.p0y + 2 / 3 * (this.p1y - this.p0y), A = this.p1x + 2 / 3 * (this.p2x - this.p1x), F = this.p1y + 2 / 3 * (this.p2y - this.p1y), k = this.p2x + 2 / 3 * (this.p3x - this.p2x), T = this.p2y + 2 / 3 * (this.p3y - this.p2y), q = M + 2 / 3 * (A - M), m = b + 2 / 3 * (F - b), d = A + 2 / 3 * (k - A), _ = F + 2 / 3 * (T - F), w = q + 1 / 3 * (d - q), E = m + 1 / 3 * (_ - m), I = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), C = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), S = new st(
|
|
255
|
+
Ct,
|
|
256
256
|
this.p0x,
|
|
257
257
|
this.p0y,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
o,
|
|
259
|
+
e,
|
|
260
|
+
p,
|
|
261
261
|
f,
|
|
262
|
-
n[0],
|
|
263
|
-
n[1]
|
|
264
|
-
), Q = new et(
|
|
265
|
-
Ot,
|
|
266
|
-
n[0],
|
|
267
|
-
n[1],
|
|
268
|
-
u,
|
|
269
|
-
x,
|
|
270
|
-
N,
|
|
271
|
-
R,
|
|
272
262
|
t[0],
|
|
273
263
|
t[1]
|
|
274
|
-
),
|
|
275
|
-
|
|
264
|
+
), O = new st(
|
|
265
|
+
Ct,
|
|
276
266
|
t[0],
|
|
277
267
|
t[1],
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
268
|
+
x,
|
|
269
|
+
g,
|
|
270
|
+
w,
|
|
271
|
+
E,
|
|
272
|
+
n[0],
|
|
273
|
+
n[1]
|
|
274
|
+
), L = new st(
|
|
275
|
+
Ct,
|
|
276
|
+
n[0],
|
|
277
|
+
n[1],
|
|
278
|
+
d,
|
|
279
|
+
_,
|
|
280
|
+
I,
|
|
281
|
+
C,
|
|
282
282
|
this.p3x,
|
|
283
283
|
this.p3y
|
|
284
284
|
);
|
|
285
|
-
return
|
|
285
|
+
return S.color = O.color = L.color = this.color, [S, O, L];
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
}
|
|
@@ -299,95 +299,95 @@ class et {
|
|
|
299
299
|
* @param oy Query point y (shape space).
|
|
300
300
|
* @param out Reusable result object (mutated).
|
|
301
301
|
*/
|
|
302
|
-
signedDistance(
|
|
302
|
+
signedDistance(t, n, o) {
|
|
303
303
|
switch (this.type) {
|
|
304
|
-
case
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
const
|
|
308
|
-
if (Math.abs(
|
|
309
|
-
|
|
304
|
+
case nt: {
|
|
305
|
+
const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = t - e, l = n - i, h = r - e, p = c - i, f = h * h + p * p, u = (a * h + l * p) / f, y = u > 0.5, x = (y ? r : e) - t, g = (y ? c : i) - n, M = Math.sqrt(x * x + g * g);
|
|
306
|
+
if (u > 0 && u < 1) {
|
|
307
|
+
const F = Math.sqrt(h * h + p * p), k = h / F, q = p / F * a - k * l;
|
|
308
|
+
if (Math.abs(q) < M) {
|
|
309
|
+
o.distance = q, o.dot = 0, o.param = u;
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
313
|
+
const b = a * p - l * h;
|
|
314
|
+
o.distance = St(b) * M;
|
|
315
|
+
const A = Math.sqrt(h * h + p * p);
|
|
316
|
+
o.dot = M === 0 || A === 0 ? 0 : Math.abs((h * x + p * g) / (A * M)), o.param = u;
|
|
317
317
|
return;
|
|
318
318
|
}
|
|
319
|
-
case
|
|
320
|
-
const
|
|
321
|
-
let
|
|
322
|
-
const
|
|
323
|
-
let
|
|
319
|
+
case ct: {
|
|
320
|
+
const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = e - t, p = i - n, f = r - e, u = c - i, y = a - r - f, x = l - c - u, g = y * y + x * x, M = 3 * (f * y + u * x), b = 2 * (f * f + u * u) + (h * y + p * x), A = h * f + p * u, F = oe(g, M, b, A, 0, 1, B);
|
|
321
|
+
let k = f, T = u;
|
|
322
|
+
const q = h * h + p * p;
|
|
323
|
+
let m = St(k * p - T * h), d = q, _ = -(h * k + p * T) / (k * k + T * T);
|
|
324
324
|
{
|
|
325
|
-
const
|
|
326
|
-
|
|
325
|
+
const E = a - t, I = l - n, C = E * E + I * I;
|
|
326
|
+
C < d && (k = a - r, T = l - c, m = St(k * I - T * E), d = C, _ = ((t - r) * k + (n - c) * T) / (k * k + T * T));
|
|
327
327
|
}
|
|
328
|
-
for (let
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
-
const
|
|
334
|
-
|
|
328
|
+
for (let E = 0; E < F; ++E) {
|
|
329
|
+
const I = B[E];
|
|
330
|
+
if (I > 0 && I < 1) {
|
|
331
|
+
const C = h + 2 * I * f + I * I * y, S = p + 2 * I * u + I * I * x, O = C * C + S * S;
|
|
332
|
+
if (O <= d) {
|
|
333
|
+
const L = f + I * y, W = u + I * x;
|
|
334
|
+
m = St(L * S - W * C), d = O, _ = I;
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
|
|
338
|
+
const w = m * Math.sqrt(d);
|
|
339
|
+
if (_ >= 0 && _ <= 1) {
|
|
340
|
+
o.distance = w, o.dot = 0, o.param = _;
|
|
341
341
|
return;
|
|
342
342
|
}
|
|
343
|
-
if (
|
|
344
|
-
const
|
|
345
|
-
|
|
343
|
+
if (o.distance = w, o.param = _, _ < 0.5) {
|
|
344
|
+
const E = Math.sqrt(f * f + u * u), I = Math.sqrt(q);
|
|
345
|
+
o.dot = I === 0 || E === 0 ? 0 : Math.abs((f * h + u * p) / (E * I));
|
|
346
346
|
} else {
|
|
347
|
-
const
|
|
348
|
-
|
|
347
|
+
const E = a - r, I = l - c, C = a - t, S = l - n, O = Math.sqrt(E * E + I * I), L = Math.sqrt(C * C + S * S);
|
|
348
|
+
o.dot = O === 0 || L === 0 ? 0 : Math.abs((E * C + I * S) / (O * L));
|
|
349
349
|
}
|
|
350
350
|
return;
|
|
351
351
|
}
|
|
352
352
|
default: {
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
let
|
|
353
|
+
const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, p = this.p3y, f = e - t, u = i - n, y = r - e, x = c - i, g = a - r - y, M = l - c - x, b = h - a - (a - r) - g, A = p - l - (l - c) - M;
|
|
354
|
+
let F = y, k = x;
|
|
355
|
+
F === 0 && k === 0 && (F = a - e, k = l - i);
|
|
356
|
+
const T = Math.sqrt(f * f + u * u);
|
|
357
|
+
let q = St(F * u - k * f) * T, m = -(f * F + u * k) / (F * F + k * k);
|
|
358
358
|
{
|
|
359
|
-
const
|
|
360
|
-
if (
|
|
361
|
-
let
|
|
362
|
-
|
|
359
|
+
const d = h - t, _ = p - n, w = Math.sqrt(d * d + _ * _);
|
|
360
|
+
if (w < Math.abs(q)) {
|
|
361
|
+
let E = h - a, I = p - l;
|
|
362
|
+
E === 0 && I === 0 && (E = h - r, I = p - c), F = E, k = I, q = St(F * _ - k * d) * w, m = ((F - d) * F + (k - _) * k) / (F * F + k * k);
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
|
-
for (let
|
|
366
|
-
let
|
|
367
|
-
if (
|
|
368
|
-
let
|
|
365
|
+
for (let d = 0; d <= co; ++d) {
|
|
366
|
+
let _ = 1 / co * d, w = f + 3 * _ * y + 3 * _ * _ * g + _ * _ * _ * b, E = u + 3 * _ * x + 3 * _ * _ * M + _ * _ * _ * A, I = 3 * y + 6 * _ * g + 3 * _ * _ * b, C = 3 * x + 6 * _ * M + 3 * _ * _ * A, S = 6 * g + 6 * _ * b, O = 6 * M + 6 * _ * A, L = _ - (w * I + E * C) / (I * I + C * C + (w * S + E * O));
|
|
367
|
+
if (L > 0 && L < 1) {
|
|
368
|
+
let W = ee;
|
|
369
369
|
do {
|
|
370
|
-
if (
|
|
371
|
-
|
|
372
|
-
} while (
|
|
373
|
-
const
|
|
374
|
-
|
|
370
|
+
if (_ = L, w = f + 3 * _ * y + 3 * _ * _ * g + _ * _ * _ * b, E = u + 3 * _ * x + 3 * _ * _ * M + _ * _ * _ * A, I = 3 * y + 6 * _ * g + 3 * _ * _ * b, C = 3 * x + 6 * _ * M + 3 * _ * _ * A, !--W) break;
|
|
371
|
+
S = 6 * g + 6 * _ * b, O = 6 * M + 6 * _ * A, L = _ - (w * I + E * C) / (I * I + C * C + (w * S + E * O));
|
|
372
|
+
} while (L > 0 && L < 1);
|
|
373
|
+
const X = Math.sqrt(w * w + E * E);
|
|
374
|
+
X < Math.abs(q) && (q = St(I * E - C * w) * X, m = _);
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
if (
|
|
378
|
-
|
|
377
|
+
if (m >= 0 && m <= 1) {
|
|
378
|
+
o.distance = q, o.dot = 0, o.param = m;
|
|
379
379
|
return;
|
|
380
380
|
}
|
|
381
|
-
if (
|
|
382
|
-
let
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
|
|
381
|
+
if (o.distance = q, o.param = m, m < 0.5) {
|
|
382
|
+
let d = y, _ = x;
|
|
383
|
+
d === 0 && _ === 0 && (d = a - e, _ = l - i);
|
|
384
|
+
const w = Math.sqrt(d * d + _ * _);
|
|
385
|
+
o.dot = T === 0 || w === 0 ? 0 : Math.abs((d * f + _ * u) / (w * T));
|
|
386
386
|
} else {
|
|
387
|
-
let
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
|
|
387
|
+
let d = h - a, _ = p - l;
|
|
388
|
+
d === 0 && _ === 0 && (d = h - r, _ = p - c);
|
|
389
|
+
const w = h - t, E = p - n, I = Math.sqrt(d * d + _ * _), C = Math.sqrt(w * w + E * E);
|
|
390
|
+
o.dot = I === 0 || C === 0 ? 0 : Math.abs((d * w + _ * E) / (I * C));
|
|
391
391
|
}
|
|
392
392
|
return;
|
|
393
393
|
}
|
|
@@ -404,58 +404,58 @@ class et {
|
|
|
404
404
|
* @param dyOut Output array (length >= 3) — crossing directions (±1).
|
|
405
405
|
* @returns Number of crossings written (0..3).
|
|
406
406
|
*/
|
|
407
|
-
scanlineIntersections(
|
|
407
|
+
scanlineIntersections(t, n, o) {
|
|
408
408
|
switch (this.type) {
|
|
409
|
-
case
|
|
410
|
-
const
|
|
411
|
-
if (
|
|
412
|
-
const
|
|
413
|
-
return
|
|
409
|
+
case nt: {
|
|
410
|
+
const e = this.p0y, i = this.p1y;
|
|
411
|
+
if (t >= e && t < i || t >= i && t < e) {
|
|
412
|
+
const r = (t - e) / (i - e);
|
|
413
|
+
return n[0] = Po(this.p0x, this.p1x, r), o[0] = ft(i - e), 1;
|
|
414
414
|
}
|
|
415
415
|
return 0;
|
|
416
416
|
}
|
|
417
|
-
case
|
|
418
|
-
const
|
|
419
|
-
let
|
|
420
|
-
|
|
417
|
+
case ct: {
|
|
418
|
+
const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y;
|
|
419
|
+
let h = 0, p = t > i ? 1 : -1;
|
|
420
|
+
n[h] = e, i === t && (i < c || i === c && i < l ? o[h++] = 1 : p = 1);
|
|
421
421
|
{
|
|
422
|
-
const f =
|
|
423
|
-
if (
|
|
424
|
-
const M =
|
|
425
|
-
|
|
422
|
+
const f = r - e, u = c - i, y = a - r - f, x = l - c - u, g = $o(B, x, 2 * u, i - t);
|
|
423
|
+
if (g >= 2 && B[0] > B[1]) {
|
|
424
|
+
const M = B[0];
|
|
425
|
+
B[0] = B[1], B[1] = M;
|
|
426
426
|
}
|
|
427
|
-
for (let M = 0; M <
|
|
428
|
-
const
|
|
429
|
-
|
|
427
|
+
for (let M = 0; M < g && h < 2; ++M) {
|
|
428
|
+
const b = B[M];
|
|
429
|
+
b >= 0 && b <= 1 && (n[h] = e + 2 * b * f + b * b * y, p * (u + b * x) >= 0 && (o[h++] = p, p = -p));
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
return
|
|
432
|
+
return l === t && (p > 0 && h > 0 && (--h, p = -1), (l < c || l === c && l < i) && h < 2 && (n[h] = a, p < 0 && (o[h++] = -1, p = 1))), p !== (t >= l ? 1 : -1) && (h > 0 ? --h : (Math.abs(l - t) < Math.abs(i - t) && (n[h] = a), o[h++] = p)), h;
|
|
433
433
|
}
|
|
434
434
|
default: {
|
|
435
|
-
const
|
|
436
|
-
let f = 0,
|
|
437
|
-
|
|
435
|
+
const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, p = this.p3y;
|
|
436
|
+
let f = 0, u = t > i ? 1 : -1;
|
|
437
|
+
n[f] = e, i === t && (i < c || i === c && (i < l || i === l && i < p) ? o[f++] = 1 : u = 1);
|
|
438
438
|
{
|
|
439
|
-
const
|
|
440
|
-
if (
|
|
441
|
-
if (
|
|
442
|
-
const
|
|
443
|
-
|
|
439
|
+
const y = h - 3 * a + 3 * r - e, x = p - 3 * l + 3 * c - i, g = 3 * a - 6 * r + 3 * e, M = 3 * l - 6 * c + 3 * i, b = 3 * r - 3 * e, A = 3 * c - 3 * i, F = Jo(B, x, M, A, i - t);
|
|
440
|
+
if (F >= 2) {
|
|
441
|
+
if (B[0] > B[1]) {
|
|
442
|
+
const k = B[0];
|
|
443
|
+
B[0] = B[1], B[1] = k;
|
|
444
444
|
}
|
|
445
|
-
if (
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
const
|
|
449
|
-
|
|
445
|
+
if (F >= 3 && B[1] > B[2]) {
|
|
446
|
+
const k = B[1];
|
|
447
|
+
if (B[1] = B[2], B[2] = k, B[0] > B[1]) {
|
|
448
|
+
const T = B[0];
|
|
449
|
+
B[0] = B[1], B[1] = T;
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
for (let
|
|
454
|
-
const
|
|
455
|
-
|
|
453
|
+
for (let k = 0; k < F && f < 3; ++k) {
|
|
454
|
+
const T = B[k];
|
|
455
|
+
T >= 0 && T <= 1 && (n[f] = ((y * T + g) * T + b) * T + e, u * ((3 * x * T + 2 * M) * T + A) >= 0 && (o[f++] = u, u = -u));
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
return
|
|
458
|
+
return p === t && (u > 0 && f > 0 && (--f, u = -1), (p < l || p === l && (p < c || p === c && p < i)) && f < 3 && (n[f] = h, u < 0 && (o[f++] = -1, u = 1))), u !== (t >= p ? 1 : -1) && (f > 0 ? --f : (Math.abs(p - t) < Math.abs(i - t) && (n[f] = h), o[f++] = u)), f;
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
}
|
|
@@ -467,39 +467,39 @@ class et {
|
|
|
467
467
|
* @returns A new CUBIC EdgeSegment with identical geometry.
|
|
468
468
|
*/
|
|
469
469
|
convertToCubic() {
|
|
470
|
-
const
|
|
471
|
-
|
|
470
|
+
const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), o = this.p1x + 1 / 3 * (this.p2x - this.p1x), e = this.p1y + 1 / 3 * (this.p2y - this.p1y), i = new st(
|
|
471
|
+
Ct,
|
|
472
472
|
this.p0x,
|
|
473
473
|
this.p0y,
|
|
474
|
-
n,
|
|
475
474
|
t,
|
|
476
|
-
|
|
477
|
-
|
|
475
|
+
n,
|
|
476
|
+
o,
|
|
477
|
+
e,
|
|
478
478
|
this.p2x,
|
|
479
479
|
this.p2y
|
|
480
480
|
);
|
|
481
|
-
return
|
|
481
|
+
return i.color = this.color, i;
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
|
-
class
|
|
484
|
+
class At {
|
|
485
485
|
/**
|
|
486
486
|
* @param buffer Source buffer (the full font file).
|
|
487
487
|
* @param byteOffset Starting position (default 0).
|
|
488
488
|
*/
|
|
489
|
-
constructor(
|
|
490
|
-
this._view = new DataView(
|
|
489
|
+
constructor(t, n = 0) {
|
|
490
|
+
this._view = new DataView(t), this._pos = n;
|
|
491
491
|
}
|
|
492
492
|
/** Current byte position. */
|
|
493
493
|
get pos() {
|
|
494
494
|
return this._pos;
|
|
495
495
|
}
|
|
496
496
|
/** Move to an absolute byte position. */
|
|
497
|
-
seek(
|
|
498
|
-
this._pos =
|
|
497
|
+
seek(t) {
|
|
498
|
+
this._pos = t;
|
|
499
499
|
}
|
|
500
500
|
/** Advance position by `n` bytes without reading. */
|
|
501
|
-
skip(
|
|
502
|
-
this._pos +=
|
|
501
|
+
skip(t) {
|
|
502
|
+
this._pos += t;
|
|
503
503
|
}
|
|
504
504
|
/** Read uint8 (1 byte). */
|
|
505
505
|
u8() {
|
|
@@ -507,23 +507,23 @@ class gt {
|
|
|
507
507
|
}
|
|
508
508
|
/** Read uint16 big-endian (2 bytes). */
|
|
509
509
|
u16() {
|
|
510
|
-
const
|
|
511
|
-
return this._pos += 2,
|
|
510
|
+
const t = this._view.getUint16(this._pos, !1);
|
|
511
|
+
return this._pos += 2, t;
|
|
512
512
|
}
|
|
513
513
|
/** Read int16 big-endian (2 bytes). */
|
|
514
514
|
i16() {
|
|
515
|
-
const
|
|
516
|
-
return this._pos += 2,
|
|
515
|
+
const t = this._view.getInt16(this._pos, !1);
|
|
516
|
+
return this._pos += 2, t;
|
|
517
517
|
}
|
|
518
518
|
/** Read uint32 big-endian (4 bytes). */
|
|
519
519
|
u32() {
|
|
520
|
-
const
|
|
521
|
-
return this._pos += 4,
|
|
520
|
+
const t = this._view.getUint32(this._pos, !1);
|
|
521
|
+
return this._pos += 4, t;
|
|
522
522
|
}
|
|
523
523
|
/** Read int32 big-endian (4 bytes). */
|
|
524
524
|
i32() {
|
|
525
|
-
const
|
|
526
|
-
return this._pos += 4,
|
|
525
|
+
const t = this._view.getInt32(this._pos, !1);
|
|
526
|
+
return this._pos += 4, t;
|
|
527
527
|
}
|
|
528
528
|
/**
|
|
529
529
|
* Read F2Dot14 (2 bytes): 2-bit signed integer + 14-bit fraction.
|
|
@@ -549,309 +549,309 @@ class gt {
|
|
|
549
549
|
}
|
|
550
550
|
// ── peek helpers (non-advancing reads at absolute positions) ──────────────
|
|
551
551
|
/** Read uint16 big-endian at an absolute byte offset without moving pos. */
|
|
552
|
-
peekU16(
|
|
553
|
-
return this._view.getUint16(
|
|
552
|
+
peekU16(t) {
|
|
553
|
+
return this._view.getUint16(t, !1);
|
|
554
554
|
}
|
|
555
555
|
/** Read uint32 big-endian at an absolute byte offset without moving pos. */
|
|
556
|
-
peekU32(
|
|
557
|
-
return this._view.getUint32(
|
|
556
|
+
peekU32(t) {
|
|
557
|
+
return this._view.getUint32(t, !1);
|
|
558
558
|
}
|
|
559
559
|
/** Read int16 big-endian at an absolute byte offset without moving pos. */
|
|
560
|
-
peekI16(
|
|
561
|
-
return this._view.getInt16(
|
|
560
|
+
peekI16(t) {
|
|
561
|
+
return this._view.getInt16(t, !1);
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
-
function
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
const
|
|
568
|
-
let
|
|
569
|
-
for (let
|
|
570
|
-
const c =
|
|
564
|
+
function ie(s, t) {
|
|
565
|
+
const n = new At(s, t);
|
|
566
|
+
n.skip(2);
|
|
567
|
+
const o = n.u16();
|
|
568
|
+
let e = null;
|
|
569
|
+
for (let r = 0; r < o; r++) {
|
|
570
|
+
const c = n.u16(), a = n.u16(), l = n.u32(), h = t + l, p = n.peekU16(h);
|
|
571
571
|
let f = -1;
|
|
572
|
-
c === 3 &&
|
|
573
|
-
}
|
|
574
|
-
if (!
|
|
575
|
-
const
|
|
576
|
-
return
|
|
577
|
-
}
|
|
578
|
-
function
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
const
|
|
582
|
-
for (let c = 0; c <
|
|
583
|
-
|
|
572
|
+
c === 3 && a === 10 && p === 12 ? f = 5 : c === 0 && a === 6 && p === 12 ? f = 4 : c === 0 && a === 4 && p === 12 ? f = 3 : c === 3 && a === 1 && p === 4 ? f = 2 : c === 0 && a <= 3 && p === 4 && (f = 1), f > ((e == null ? void 0 : e.priority) ?? -1) && (e = { priority: f, subtableAbsOffset: h });
|
|
573
|
+
}
|
|
574
|
+
if (!e) return () => 0;
|
|
575
|
+
const i = n.peekU16(e.subtableAbsOffset);
|
|
576
|
+
return i === 12 ? ce(s, e.subtableAbsOffset) : i === 4 ? re(s, e.subtableAbsOffset) : () => 0;
|
|
577
|
+
}
|
|
578
|
+
function ce(s, t) {
|
|
579
|
+
const n = new At(s, t);
|
|
580
|
+
n.skip(2), n.skip(2), n.skip(4), n.skip(4);
|
|
581
|
+
const o = n.u32(), e = new Uint32Array(o), i = new Uint32Array(o), r = new Uint32Array(o);
|
|
582
|
+
for (let c = 0; c < o; c++)
|
|
583
|
+
e[c] = n.u32(), i[c] = n.u32(), r[c] = n.u32();
|
|
584
584
|
return (c) => {
|
|
585
|
-
let
|
|
586
|
-
for (;
|
|
587
|
-
const
|
|
588
|
-
if (c <
|
|
589
|
-
else if (c > f)
|
|
590
|
-
else return (
|
|
585
|
+
let a = 0, l = o - 1;
|
|
586
|
+
for (; a <= l; ) {
|
|
587
|
+
const h = a + l >>> 1, p = e[h] ?? 0, f = i[h] ?? 0;
|
|
588
|
+
if (c < p) l = h - 1;
|
|
589
|
+
else if (c > f) a = h + 1;
|
|
590
|
+
else return (r[h] ?? 0) + (c - p);
|
|
591
591
|
}
|
|
592
592
|
return 0;
|
|
593
593
|
};
|
|
594
594
|
}
|
|
595
|
-
function
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
for (let
|
|
602
|
-
|
|
603
|
-
const
|
|
604
|
-
for (let
|
|
605
|
-
const c = new Int16Array(
|
|
606
|
-
for (let
|
|
607
|
-
const
|
|
608
|
-
for (let
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
return (
|
|
612
|
-
if (
|
|
613
|
-
let f = 0,
|
|
614
|
-
for (; f <=
|
|
615
|
-
const
|
|
616
|
-
if (
|
|
617
|
-
f =
|
|
618
|
-
else if (
|
|
619
|
-
|
|
595
|
+
function re(s, t) {
|
|
596
|
+
const n = new At(s, t);
|
|
597
|
+
n.skip(2), n.skip(2), n.skip(2);
|
|
598
|
+
const e = n.u16() >>> 1;
|
|
599
|
+
n.skip(6);
|
|
600
|
+
const i = new Uint16Array(e);
|
|
601
|
+
for (let p = 0; p < e; p++) i[p] = n.u16();
|
|
602
|
+
n.skip(2);
|
|
603
|
+
const r = new Uint16Array(e);
|
|
604
|
+
for (let p = 0; p < e; p++) r[p] = n.u16();
|
|
605
|
+
const c = new Int16Array(e);
|
|
606
|
+
for (let p = 0; p < e; p++) c[p] = n.i16();
|
|
607
|
+
const a = new Int32Array(e), l = new Uint16Array(e);
|
|
608
|
+
for (let p = 0; p < e; p++)
|
|
609
|
+
a[p] = n.pos, l[p] = n.u16();
|
|
610
|
+
const h = new DataView(s);
|
|
611
|
+
return (p) => {
|
|
612
|
+
if (p > 65535) return 0;
|
|
613
|
+
let f = 0, u = e - 1;
|
|
614
|
+
for (; f <= u; ) {
|
|
615
|
+
const y = f + u >>> 1, x = i[y] ?? 0;
|
|
616
|
+
if (p > x)
|
|
617
|
+
f = y + 1;
|
|
618
|
+
else if (p < (r[y] ?? 0))
|
|
619
|
+
u = y - 1;
|
|
620
620
|
else {
|
|
621
|
-
if ((
|
|
622
|
-
const M =
|
|
621
|
+
if ((i[y] ?? 0) === 65535) return 0;
|
|
622
|
+
const M = l[y] ?? 0, b = c[y] ?? 0, A = r[y] ?? 0;
|
|
623
623
|
if (M === 0)
|
|
624
|
-
return
|
|
625
|
-
const
|
|
626
|
-
return
|
|
624
|
+
return p + b & 65535;
|
|
625
|
+
const F = (a[y] ?? 0) + M + (p - A) * 2, k = h.getUint16(F, !1);
|
|
626
|
+
return k === 0 ? 0 : k + b & 65535;
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
629
|
return 0;
|
|
630
630
|
};
|
|
631
631
|
}
|
|
632
|
-
function
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
const
|
|
638
|
-
return { unitsPerEm:
|
|
639
|
-
}
|
|
640
|
-
function Mo(e, n) {
|
|
641
|
-
const t = new gt(e, n);
|
|
642
|
-
t.skip(4);
|
|
643
|
-
const s = t.i16(), i = t.i16(), o = t.i16();
|
|
644
|
-
t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(8), t.skip(2);
|
|
645
|
-
const p = t.u16();
|
|
646
|
-
return { ascender: s, descender: i, lineGap: o, numberOfHMetrics: p };
|
|
632
|
+
function ae(s, t) {
|
|
633
|
+
const n = new At(s, t);
|
|
634
|
+
n.skip(4), n.skip(4), n.skip(4), n.skip(4), n.skip(2);
|
|
635
|
+
const o = n.u16();
|
|
636
|
+
n.skip(16), n.skip(8), n.skip(2), n.skip(2), n.skip(2);
|
|
637
|
+
const e = n.i16();
|
|
638
|
+
return { unitsPerEm: o, indexToLocFormat: e };
|
|
647
639
|
}
|
|
648
|
-
function
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
640
|
+
function le(s, t) {
|
|
641
|
+
const n = new At(s, t);
|
|
642
|
+
n.skip(4);
|
|
643
|
+
const o = n.i16(), e = n.i16(), i = n.i16();
|
|
644
|
+
n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(8), n.skip(2);
|
|
645
|
+
const r = n.u16();
|
|
646
|
+
return { ascender: o, descender: e, lineGap: i, numberOfHMetrics: r };
|
|
647
|
+
}
|
|
648
|
+
function he(s, t, n, o) {
|
|
649
|
+
const e = new At(s, t), i = [];
|
|
650
|
+
let r = 0;
|
|
651
|
+
for (let c = 0; c < o; c++) {
|
|
652
|
+
const a = e.u16(), l = e.i16();
|
|
653
|
+
i[c] = { advanceWidth: a, lsb: l }, r = a;
|
|
654
654
|
}
|
|
655
|
-
for (let c =
|
|
656
|
-
const
|
|
657
|
-
|
|
655
|
+
for (let c = o; c < n; c++) {
|
|
656
|
+
const a = e.i16();
|
|
657
|
+
i[c] = { advanceWidth: r, lsb: a };
|
|
658
658
|
}
|
|
659
|
-
return
|
|
659
|
+
return i;
|
|
660
660
|
}
|
|
661
|
-
function
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
664
|
-
for (let c = 0; c <
|
|
661
|
+
function pe(s, t, n, o) {
|
|
662
|
+
const e = new At(s, t), i = n + 1, r = [];
|
|
663
|
+
if (o === 0)
|
|
664
|
+
for (let c = 0; c < i; c++) r[c] = e.u16() * 2;
|
|
665
665
|
else
|
|
666
|
-
for (let c = 0; c <
|
|
667
|
-
return
|
|
668
|
-
}
|
|
669
|
-
function
|
|
670
|
-
const
|
|
671
|
-
return
|
|
672
|
-
}
|
|
673
|
-
const
|
|
674
|
-
function
|
|
675
|
-
const
|
|
676
|
-
for (const c of
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
return { contours:
|
|
681
|
-
}
|
|
682
|
-
function
|
|
683
|
-
if (
|
|
684
|
-
const
|
|
685
|
-
return
|
|
686
|
-
}
|
|
687
|
-
function
|
|
688
|
-
if (
|
|
689
|
-
const
|
|
690
|
-
for (let
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
for (let
|
|
695
|
-
const f =
|
|
696
|
-
if (
|
|
697
|
-
let
|
|
698
|
-
for (;
|
|
666
|
+
for (let c = 0; c < i; c++) r[c] = e.u32();
|
|
667
|
+
return r;
|
|
668
|
+
}
|
|
669
|
+
function fe(s, t) {
|
|
670
|
+
const n = new At(s, t);
|
|
671
|
+
return n.skip(4), { numGlyphs: n.u16() };
|
|
672
|
+
}
|
|
673
|
+
const ue = 1, ye = 2, xe = 4, _e = 8, ro = 16, ao = 32, ge = 1, lo = 2, de = 8, Me = 32, me = 64, be = 128;
|
|
674
|
+
function we(s, t, n, o, e) {
|
|
675
|
+
const i = Oo(s, t, n, o, e), r = [];
|
|
676
|
+
for (const c of i) {
|
|
677
|
+
const a = Ie(c);
|
|
678
|
+
a.length > 0 && r.push(a);
|
|
679
|
+
}
|
|
680
|
+
return { contours: r, inverseYAxis: !1 };
|
|
681
|
+
}
|
|
682
|
+
function Oo(s, t, n, o, e) {
|
|
683
|
+
if (o === 0) return [];
|
|
684
|
+
const i = t + n, r = new At(s, i), c = r.i16();
|
|
685
|
+
return r.skip(8), c >= 0 ? Ae(r, c) : Ee(s, r, t, e);
|
|
686
|
+
}
|
|
687
|
+
function Ae(s, t) {
|
|
688
|
+
if (t === 0) return [];
|
|
689
|
+
const n = [];
|
|
690
|
+
for (let p = 0; p < t; p++) n[p] = s.u16();
|
|
691
|
+
const o = (n[t - 1] ?? 0) + 1, e = s.u16();
|
|
692
|
+
s.skip(e);
|
|
693
|
+
const i = new Uint8Array(o);
|
|
694
|
+
for (let p = 0; p < o; ) {
|
|
695
|
+
const f = s.u8();
|
|
696
|
+
if (i[p++] = f, f & _e) {
|
|
697
|
+
let u = s.u8();
|
|
698
|
+
for (; u-- > 0; ) i[p++] = f;
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
|
-
const
|
|
701
|
+
const r = new Float64Array(o);
|
|
702
702
|
let c = 0;
|
|
703
|
-
for (let
|
|
704
|
-
const f =
|
|
705
|
-
if (f &
|
|
706
|
-
const
|
|
707
|
-
c += f &
|
|
708
|
-
} else f &
|
|
709
|
-
p
|
|
710
|
-
}
|
|
711
|
-
const
|
|
703
|
+
for (let p = 0; p < o; p++) {
|
|
704
|
+
const f = i[p] ?? 0;
|
|
705
|
+
if (f & ye) {
|
|
706
|
+
const u = s.u8();
|
|
707
|
+
c += f & ro ? u : -u;
|
|
708
|
+
} else f & ro || (c += s.i16());
|
|
709
|
+
r[p] = c;
|
|
710
|
+
}
|
|
711
|
+
const a = new Float64Array(o);
|
|
712
712
|
c = 0;
|
|
713
|
-
for (let
|
|
714
|
-
const f =
|
|
715
|
-
if (f &
|
|
716
|
-
const
|
|
717
|
-
c += f &
|
|
718
|
-
} else f &
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
const
|
|
722
|
-
let
|
|
723
|
-
for (let
|
|
724
|
-
const f =
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
return
|
|
728
|
-
}
|
|
729
|
-
function
|
|
730
|
-
const
|
|
731
|
-
if (
|
|
732
|
-
const
|
|
733
|
-
for (let c = 0; c <
|
|
734
|
-
const
|
|
735
|
-
|
|
713
|
+
for (let p = 0; p < o; p++) {
|
|
714
|
+
const f = i[p] ?? 0;
|
|
715
|
+
if (f & xe) {
|
|
716
|
+
const u = s.u8();
|
|
717
|
+
c += f & ao ? u : -u;
|
|
718
|
+
} else f & ao || (c += s.i16());
|
|
719
|
+
a[p] = c;
|
|
720
|
+
}
|
|
721
|
+
const l = [];
|
|
722
|
+
let h = 0;
|
|
723
|
+
for (let p = 0; p < t; p++) {
|
|
724
|
+
const f = n[p] ?? 0, u = ke(i, r, a, h, f);
|
|
725
|
+
u.length > 0 && l.push(u), h = f + 1;
|
|
726
|
+
}
|
|
727
|
+
return l;
|
|
728
|
+
}
|
|
729
|
+
function ke(s, t, n, o, e) {
|
|
730
|
+
const i = e - o + 1;
|
|
731
|
+
if (i <= 0) return [];
|
|
732
|
+
const r = [];
|
|
733
|
+
for (let c = 0; c < i; c++) {
|
|
734
|
+
const a = s[o + c] ?? 0, l = t[o + c] ?? 0, h = n[o + c] ?? 0;
|
|
735
|
+
r.push({ x: l, y: h, onCurve: (a & ue) !== 0 });
|
|
736
736
|
}
|
|
737
|
-
return
|
|
737
|
+
return r;
|
|
738
738
|
}
|
|
739
|
-
function
|
|
740
|
-
const
|
|
741
|
-
if (
|
|
742
|
-
const
|
|
743
|
-
for (let c = 0; c <
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
x: Math.trunc((
|
|
747
|
-
y: Math.trunc((
|
|
739
|
+
function Ie(s) {
|
|
740
|
+
const t = s.length;
|
|
741
|
+
if (t <= 0) return [];
|
|
742
|
+
const n = [];
|
|
743
|
+
for (let c = 0; c < t; c++) {
|
|
744
|
+
const a = s[c], l = s[(c + 1) % t];
|
|
745
|
+
n.push(a), !a.onCurve && !l.onCurve && n.push({
|
|
746
|
+
x: Math.trunc((a.x + l.x) / 2),
|
|
747
|
+
y: Math.trunc((a.y + l.y) / 2),
|
|
748
748
|
onCurve: !0
|
|
749
749
|
});
|
|
750
750
|
}
|
|
751
|
-
const
|
|
752
|
-
let
|
|
753
|
-
if (!
|
|
754
|
-
for (let c = 1; c <
|
|
755
|
-
if (
|
|
756
|
-
|
|
751
|
+
const o = n.length;
|
|
752
|
+
let e = 0;
|
|
753
|
+
if (!n[0].onCurve) {
|
|
754
|
+
for (let c = 1; c < o; c++)
|
|
755
|
+
if (n[c].onCurve) {
|
|
756
|
+
e = c;
|
|
757
757
|
break;
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
|
-
const
|
|
761
|
-
let
|
|
762
|
-
for (;
|
|
763
|
-
const c =
|
|
764
|
-
if (
|
|
765
|
-
|
|
760
|
+
const i = [];
|
|
761
|
+
let r = 0;
|
|
762
|
+
for (; r < o; ) {
|
|
763
|
+
const c = n[(e + r) % o], a = n[(e + r + 1) % o];
|
|
764
|
+
if (a.onCurve)
|
|
765
|
+
i.push(new st(nt, c.x, c.y, a.x, a.y, 0, 0, 0, 0)), r += 1;
|
|
766
766
|
else {
|
|
767
|
-
const
|
|
768
|
-
|
|
767
|
+
const l = n[(e + r + 2) % o];
|
|
768
|
+
i.push(new st(ct, c.x, c.y, a.x, a.y, l.x, l.y, 0, 0)), r += 2;
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
|
-
return o;
|
|
772
|
-
}
|
|
773
|
-
function Lo(e, n, t, s) {
|
|
774
|
-
const i = [];
|
|
775
|
-
let o = 0;
|
|
776
|
-
do {
|
|
777
|
-
o = n.u16();
|
|
778
|
-
const p = n.u16();
|
|
779
|
-
let c, r;
|
|
780
|
-
o & vo ? (c = n.i16(), r = n.i16()) : (c = n.u8(), r = n.u8(), o & ks && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
|
|
781
|
-
let h = 0, l = 0;
|
|
782
|
-
o & ks && (h = c, l = r);
|
|
783
|
-
let a = 1, f = 0, y = 0, _ = 1;
|
|
784
|
-
o & Co ? a = _ = n.f2dot14() : o & Ro ? (a = n.f2dot14(), _ = n.f2dot14()) : o & To && (a = n.f2dot14(), f = n.f2dot14(), y = n.f2dot14(), _ = n.f2dot14());
|
|
785
|
-
const u = s(p), x = Go(u, a, f, y, _, h, l);
|
|
786
|
-
for (const M of x) i.push(M);
|
|
787
|
-
} while (o & Io);
|
|
788
771
|
return i;
|
|
789
772
|
}
|
|
790
|
-
function
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
(
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
773
|
+
function Ee(s, t, n, o) {
|
|
774
|
+
const e = [];
|
|
775
|
+
let i = 0;
|
|
776
|
+
do {
|
|
777
|
+
i = t.u16();
|
|
778
|
+
const r = t.u16();
|
|
779
|
+
let c, a;
|
|
780
|
+
i & ge ? (c = t.i16(), a = t.i16()) : (c = t.u8(), a = t.u8(), i & lo && (c > 127 && (c -= 256), a > 127 && (a -= 256)));
|
|
781
|
+
let l = 0, h = 0;
|
|
782
|
+
i & lo && (l = c, h = a);
|
|
783
|
+
let p = 1, f = 0, u = 0, y = 1;
|
|
784
|
+
i & de ? p = y = t.f2dot14() : i & me ? (p = t.f2dot14(), y = t.f2dot14()) : i & be && (p = t.f2dot14(), f = t.f2dot14(), u = t.f2dot14(), y = t.f2dot14());
|
|
785
|
+
const x = o(r), g = De(x, p, f, u, y, l, h);
|
|
786
|
+
for (const M of g) e.push(M);
|
|
787
|
+
} while (i & Me);
|
|
788
|
+
return e;
|
|
789
|
+
}
|
|
790
|
+
function ho(s) {
|
|
791
|
+
return s >= 0 ? Math.floor(s + 0.5) : Math.ceil(s - 0.5);
|
|
792
|
+
}
|
|
793
|
+
function De(s, t, n, o, e, i, r) {
|
|
794
|
+
if (t === 1 && n === 0 && o === 0 && e === 1 && i === 0 && r === 0) return s;
|
|
795
|
+
const a = t === 1 && n === 0 && o === 0 && e === 1;
|
|
796
|
+
return s.map(
|
|
797
|
+
(l) => l.map((h) => a ? { x: h.x + i, y: h.y + r, onCurve: h.onCurve } : {
|
|
798
|
+
x: ho(t * h.x + n * h.y + i),
|
|
799
|
+
y: ho(o * h.x + e * h.y + r),
|
|
800
|
+
onCurve: h.onCurve
|
|
801
801
|
})
|
|
802
802
|
);
|
|
803
803
|
}
|
|
804
|
-
function
|
|
805
|
-
const
|
|
806
|
-
if (
|
|
807
|
-
return
|
|
808
|
-
const
|
|
809
|
-
for (let
|
|
810
|
-
const c =
|
|
811
|
-
|
|
812
|
-
const
|
|
813
|
-
if (
|
|
814
|
-
|
|
804
|
+
function qe(s, t) {
|
|
805
|
+
const n = new At(s, t);
|
|
806
|
+
if (n.u16() !== 0)
|
|
807
|
+
return po;
|
|
808
|
+
const e = n.u16(), i = /* @__PURE__ */ new Map();
|
|
809
|
+
for (let r = 0; r < e; r++) {
|
|
810
|
+
const c = n.pos;
|
|
811
|
+
n.skip(2);
|
|
812
|
+
const a = n.u16(), l = n.u16(), h = l >> 8 & 255, p = !(l & 2), f = !!(l & 4);
|
|
813
|
+
if (h !== 0 || !p || f) {
|
|
814
|
+
n.seek(c + a);
|
|
815
815
|
continue;
|
|
816
816
|
}
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
for (let
|
|
820
|
-
const
|
|
821
|
-
|
|
817
|
+
const u = n.u16();
|
|
818
|
+
n.skip(6);
|
|
819
|
+
for (let y = 0; y < u; y++) {
|
|
820
|
+
const x = n.u16(), g = n.u16(), M = n.i16(), b = (x & 65535) << 16 | g & 65535;
|
|
821
|
+
i.set(b, M);
|
|
822
822
|
}
|
|
823
|
-
|
|
823
|
+
n.seek(c + a);
|
|
824
824
|
}
|
|
825
|
-
return
|
|
826
|
-
const
|
|
827
|
-
return
|
|
825
|
+
return i.size === 0 ? po : (r, c) => {
|
|
826
|
+
const a = (r & 65535) << 16 | c & 65535;
|
|
827
|
+
return i.get(a) ?? 0;
|
|
828
828
|
};
|
|
829
829
|
}
|
|
830
|
-
const
|
|
831
|
-
function
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
834
|
-
if (
|
|
835
|
-
const
|
|
836
|
-
|
|
830
|
+
const po = () => 0;
|
|
831
|
+
function Ce(s) {
|
|
832
|
+
const t = new At(s);
|
|
833
|
+
if (t.u32() === 1953784678) {
|
|
834
|
+
if (t.skip(4), t.u32() === 0) throw new Error("TTC contains no fonts");
|
|
835
|
+
const e = t.u32();
|
|
836
|
+
t.seek(e);
|
|
837
837
|
} else
|
|
838
|
-
|
|
839
|
-
return
|
|
838
|
+
t.seek(0);
|
|
839
|
+
return ve(s, t);
|
|
840
840
|
}
|
|
841
|
-
function
|
|
842
|
-
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
const
|
|
846
|
-
for (let
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
const
|
|
850
|
-
|
|
841
|
+
function ve(s, t) {
|
|
842
|
+
t.skip(4);
|
|
843
|
+
const n = t.u16();
|
|
844
|
+
t.skip(6);
|
|
845
|
+
const o = /* @__PURE__ */ new Map();
|
|
846
|
+
for (let e = 0; e < n; e++) {
|
|
847
|
+
const i = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
|
|
848
|
+
t.skip(4);
|
|
849
|
+
const r = t.u32(), c = t.u32();
|
|
850
|
+
o.set(i, { offset: r, length: c });
|
|
851
851
|
}
|
|
852
|
-
return
|
|
852
|
+
return o;
|
|
853
853
|
}
|
|
854
|
-
class
|
|
854
|
+
class Ti {
|
|
855
855
|
/**
|
|
856
856
|
* Parses a TrueType font from an ArrayBuffer.
|
|
857
857
|
*
|
|
@@ -861,20 +861,20 @@ class Di {
|
|
|
861
861
|
*
|
|
862
862
|
* @param buffer Raw font file bytes.
|
|
863
863
|
*/
|
|
864
|
-
constructor(
|
|
865
|
-
this._buffer =
|
|
866
|
-
const
|
|
867
|
-
if (!
|
|
868
|
-
if (!
|
|
869
|
-
if (!
|
|
870
|
-
if (!
|
|
871
|
-
if (!
|
|
864
|
+
constructor(t) {
|
|
865
|
+
this._buffer = t, this._tables = Ce(t);
|
|
866
|
+
const n = this._tables.get("head"), o = this._tables.get("maxp"), e = this._tables.get("hhea"), i = this._tables.get("hmtx"), r = this._tables.get("loca"), c = this._tables.get("cmap");
|
|
867
|
+
if (!n) throw new Error("Font missing required `head` table");
|
|
868
|
+
if (!o) throw new Error("Font missing required `maxp` table");
|
|
869
|
+
if (!e) throw new Error("Font missing required `hhea` table");
|
|
870
|
+
if (!i) throw new Error("Font missing required `hmtx` table");
|
|
871
|
+
if (!r) throw new Error("Font missing required `loca` table");
|
|
872
872
|
if (!c) throw new Error("Font missing required `cmap` table");
|
|
873
|
-
this._head =
|
|
874
|
-
const
|
|
875
|
-
this._hhea =
|
|
876
|
-
const
|
|
877
|
-
this._kern =
|
|
873
|
+
this._head = ae(t, n.offset);
|
|
874
|
+
const a = fe(t, o.offset);
|
|
875
|
+
this._hhea = le(t, e.offset), this._hmtx = he(t, i.offset, a.numGlyphs, this._hhea.numberOfHMetrics), this._loca = pe(t, r.offset, a.numGlyphs, this._head.indexToLocFormat), this._cmap = ie(t, c.offset);
|
|
876
|
+
const l = this._tables.get("kern");
|
|
877
|
+
this._kern = l ? qe(t, l.offset) : () => 0, this.metrics = {
|
|
878
878
|
unitsPerEm: this._head.unitsPerEm,
|
|
879
879
|
ascender: this._hhea.ascender,
|
|
880
880
|
descender: this._hhea.descender,
|
|
@@ -887,8 +887,8 @@ class Di {
|
|
|
887
887
|
*
|
|
888
888
|
* @param codepoint Unicode scalar value.
|
|
889
889
|
*/
|
|
890
|
-
glyphId(
|
|
891
|
-
return this._cmap(
|
|
890
|
+
glyphId(t) {
|
|
891
|
+
return this._cmap(t);
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
894
894
|
* Total glyph count (`maxp.numGlyphs`), including `.notdef` at index 0.
|
|
@@ -906,16 +906,16 @@ class Di {
|
|
|
906
906
|
*
|
|
907
907
|
* @param glyphId Glyph index.
|
|
908
908
|
*/
|
|
909
|
-
advance(
|
|
910
|
-
return (this._hmtx[
|
|
909
|
+
advance(t) {
|
|
910
|
+
return (this._hmtx[t] ?? this._hmtx[this._hmtx.length - 1] ?? { advanceWidth: 0 }).advanceWidth;
|
|
911
911
|
}
|
|
912
912
|
/**
|
|
913
913
|
* Left side bearing of a glyph in font units.
|
|
914
914
|
*
|
|
915
915
|
* @param glyphId Glyph index.
|
|
916
916
|
*/
|
|
917
|
-
lsb(
|
|
918
|
-
return (this._hmtx[
|
|
917
|
+
lsb(t) {
|
|
918
|
+
return (this._hmtx[t] ?? this._hmtx[this._hmtx.length - 1] ?? { lsb: 0 }).lsb;
|
|
919
919
|
}
|
|
920
920
|
/**
|
|
921
921
|
* Kerning adjustment between two glyphs in font units.
|
|
@@ -924,8 +924,8 @@ class Di {
|
|
|
924
924
|
* @param leftGlyphId Left glyph index.
|
|
925
925
|
* @param rightGlyphId Right glyph index.
|
|
926
926
|
*/
|
|
927
|
-
kerning(
|
|
928
|
-
return this._kern(
|
|
927
|
+
kerning(t, n) {
|
|
928
|
+
return this._kern(t, n);
|
|
929
929
|
}
|
|
930
930
|
/**
|
|
931
931
|
* Parses and returns the outline of a glyph as a Shape (raw font units, y-up).
|
|
@@ -939,15 +939,15 @@ class Di {
|
|
|
939
939
|
* @param glyphId Glyph index.
|
|
940
940
|
* @returns Shape with contours in font units, inverseYAxis=false.
|
|
941
941
|
*/
|
|
942
|
-
shape(
|
|
943
|
-
const
|
|
944
|
-
if (!
|
|
945
|
-
const
|
|
946
|
-
return
|
|
942
|
+
shape(t) {
|
|
943
|
+
const n = this._tables.get("glyf");
|
|
944
|
+
if (!n) return { contours: [], inverseYAxis: !1 };
|
|
945
|
+
const o = this._loca, e = o[t] ?? 0, r = (o[t + 1] ?? e) - e;
|
|
946
|
+
return we(
|
|
947
947
|
this._buffer,
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
948
|
+
n.offset,
|
|
949
|
+
e,
|
|
950
|
+
r,
|
|
951
951
|
(c) => this._glyphRaw(c)
|
|
952
952
|
);
|
|
953
953
|
}
|
|
@@ -957,586 +957,867 @@ class Di {
|
|
|
957
957
|
* merged outline (matching FreeType).
|
|
958
958
|
* @internal
|
|
959
959
|
*/
|
|
960
|
-
_glyphRaw(
|
|
961
|
-
const
|
|
962
|
-
if (!
|
|
963
|
-
const
|
|
964
|
-
return
|
|
960
|
+
_glyphRaw(t) {
|
|
961
|
+
const n = this._tables.get("glyf");
|
|
962
|
+
if (!n) return [];
|
|
963
|
+
const o = this._loca, e = o[t] ?? 0, r = (o[t + 1] ?? e) - e;
|
|
964
|
+
return Oo(
|
|
965
965
|
this._buffer,
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
966
|
+
n.offset,
|
|
967
|
+
e,
|
|
968
|
+
r,
|
|
969
969
|
(c) => this._glyphRaw(c)
|
|
970
970
|
);
|
|
971
971
|
}
|
|
972
972
|
}
|
|
973
|
-
function
|
|
974
|
-
const
|
|
975
|
-
for (const
|
|
976
|
-
for (let
|
|
977
|
-
const
|
|
978
|
-
if (
|
|
979
|
-
const
|
|
980
|
-
|
|
973
|
+
function dn(s, t) {
|
|
974
|
+
const n = 1 / t;
|
|
975
|
+
for (const o of s.contours)
|
|
976
|
+
for (let e = 0; e < o.length; e++) {
|
|
977
|
+
const i = o[e];
|
|
978
|
+
if (i.p0x *= n, i.p0y *= n, i.p1x *= n, i.p1y *= n, i.p2x *= n, i.p2y *= n, i.p3x *= n, i.p3y *= n, i.type === ct) {
|
|
979
|
+
const r = i.p1x - i.p0x, c = i.p1y - i.p0y, a = i.p2x - i.p1x, l = i.p2y - i.p1y;
|
|
980
|
+
K(r, c, a, l) === 0 && (o[e] = new st(nt, i.p0x, i.p0y, i.p2x, i.p2y, 0, 0, 0, 0));
|
|
981
|
+
} else if (i.type === Ct) {
|
|
982
|
+
const r = i.p2x - i.p1x, c = i.p2y - i.p1y, a = 1.5 * i.p1x - 0.5 * i.p0x, l = 1.5 * i.p1y - 0.5 * i.p0y;
|
|
983
|
+
K(i.p1x - i.p0x, i.p1y - i.p0y, r, c) === 0 && K(r, c, i.p3x - i.p2x, i.p3y - i.p2y) === 0 ? o[e] = new st(nt, i.p0x, i.p0y, i.p3x, i.p3y, 0, 0, 0, 0) : a === 1.5 * i.p2x - 0.5 * i.p3x && l === 1.5 * i.p2y - 0.5 * i.p3y && (o[e] = new st(ct, i.p0x, i.p0y, a, l, i.p3x, i.p3y, 0, 0));
|
|
981
984
|
}
|
|
982
985
|
}
|
|
983
986
|
}
|
|
984
|
-
const
|
|
985
|
-
function
|
|
986
|
-
switch (n
|
|
987
|
-
case
|
|
987
|
+
const fo = 1e-6, Te = 1.1111111111111112, Fe = new Float64Array(16);
|
|
988
|
+
function uo(s, t, n) {
|
|
989
|
+
switch (t[n] = s.p0x, t[n + 1] = s.p0y, t[n + 2] = s.p1x, t[n + 3] = s.p1y, s.type) {
|
|
990
|
+
case nt:
|
|
988
991
|
return 1;
|
|
989
|
-
case
|
|
990
|
-
return n
|
|
992
|
+
case ct:
|
|
993
|
+
return t[n + 4] = s.p2x, t[n + 5] = s.p2y, 2;
|
|
991
994
|
default:
|
|
992
|
-
return n
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
function
|
|
996
|
-
if (
|
|
997
|
-
const
|
|
998
|
-
(
|
|
999
|
-
}
|
|
1000
|
-
if (
|
|
1001
|
-
const
|
|
1002
|
-
(
|
|
1003
|
-
}
|
|
1004
|
-
return
|
|
1005
|
-
}
|
|
1006
|
-
function
|
|
1007
|
-
const
|
|
1008
|
-
let
|
|
1009
|
-
if (!(
|
|
1010
|
-
|
|
1011
|
-
const
|
|
1012
|
-
let c = 0,
|
|
1013
|
-
if (
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
if (
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
if (
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
if (
|
|
1026
|
-
const
|
|
1027
|
-
M =
|
|
1028
|
-
}
|
|
1029
|
-
c *=
|
|
1030
|
-
const
|
|
1031
|
-
if (
|
|
1032
|
-
const
|
|
1033
|
-
if (
|
|
1034
|
-
const
|
|
1035
|
-
if (
|
|
1036
|
-
const
|
|
1037
|
-
return
|
|
1038
|
-
}
|
|
1039
|
-
let
|
|
1040
|
-
if (
|
|
1041
|
-
const
|
|
1042
|
-
if (
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1045
|
-
const
|
|
1046
|
-
if (
|
|
1047
|
-
const
|
|
1048
|
-
return
|
|
1049
|
-
}
|
|
1050
|
-
const
|
|
1051
|
-
return
|
|
1052
|
-
}
|
|
1053
|
-
function
|
|
1054
|
-
let
|
|
1055
|
-
if (
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
if (
|
|
1060
|
-
if (
|
|
1061
|
-
const
|
|
1062
|
-
|
|
995
|
+
return t[n + 4] = s.p2x, t[n + 5] = s.p2y, t[n + 6] = s.p3x, t[n + 7] = s.p3y, 3;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
function yo(s, t, n) {
|
|
999
|
+
if (n === 3) {
|
|
1000
|
+
const o = s[t], e = s[t + 1], i = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5], l = s[t + 6], h = s[t + 7];
|
|
1001
|
+
(i === o && r === e || i === l && r === h) && (c === o && a === e || c === l && a === h) && (s[t + 2] = l, s[t + 3] = h, n = 1);
|
|
1002
|
+
}
|
|
1003
|
+
if (n === 2) {
|
|
1004
|
+
const o = s[t], e = s[t + 1], i = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5];
|
|
1005
|
+
(i === o && r === e || i === c && r === a) && (s[t + 2] = c, s[t + 3] = a, n = 1);
|
|
1006
|
+
}
|
|
1007
|
+
return n === 1 && s[t] === s[t + 2] && s[t + 1] === s[t + 3] && (n = 0), n;
|
|
1008
|
+
}
|
|
1009
|
+
function Se(s, t) {
|
|
1010
|
+
const n = Fe;
|
|
1011
|
+
let o = uo(s, n, 0), e = uo(t, n, 8);
|
|
1012
|
+
if (!(o >= 1 && o <= 3 && e >= 1 && e <= 3) || n[o * 2] !== n[8] || n[o * 2 + 1] !== n[9]) return 0;
|
|
1013
|
+
o = yo(n, 0, o), e = yo(n, 8, e);
|
|
1014
|
+
const i = n[o * 2], r = n[o * 2 + 1];
|
|
1015
|
+
let c = 0, a = 0, l = 0, h = 0, p = 0, f = 0, u = 0, y = 0, x = 0, g = 0, M = 0, b = 0;
|
|
1016
|
+
if (o >= 1 && (c = n[(o - 1) * 2] - i, a = n[(o - 1) * 2 + 1] - r), o >= 2) {
|
|
1017
|
+
const X = n[(o - 2) * 2] - n[(o - 1) * 2], H = n[(o - 2) * 2 + 1] - n[(o - 1) * 2 + 1];
|
|
1018
|
+
l = X - c, h = H - a;
|
|
1019
|
+
}
|
|
1020
|
+
if (o >= 3) {
|
|
1021
|
+
const X = n[(o - 3) * 2] - n[(o - 2) * 2], H = n[(o - 3) * 2 + 1] - n[(o - 2) * 2 + 1], J = n[(o - 2) * 2] - n[(o - 1) * 2], z = n[(o - 2) * 2 + 1] - n[(o - 1) * 2 + 1];
|
|
1022
|
+
p = X - J - l, f = H - z - h, l *= 3, h *= 3;
|
|
1023
|
+
}
|
|
1024
|
+
if (e >= 1 && (u = n[10] - i, y = n[11] - r), e >= 2) {
|
|
1025
|
+
const X = n[12] - n[10], H = n[13] - n[11];
|
|
1026
|
+
x = X - u, g = H - y;
|
|
1027
|
+
}
|
|
1028
|
+
if (e >= 3) {
|
|
1029
|
+
const X = n[14] - n[12], H = n[15] - n[13], J = n[12] - n[10], z = n[13] - n[11];
|
|
1030
|
+
M = X - J - x, b = H - z - g, x *= 3, g *= 3;
|
|
1031
|
+
}
|
|
1032
|
+
c *= o, a *= o, u *= e, y *= e;
|
|
1033
|
+
const A = c !== 0 || a !== 0;
|
|
1034
|
+
if (A && (u !== 0 || y !== 0)) {
|
|
1035
|
+
const X = Math.sqrt(c * c + a * a), H = Math.sqrt(u * u + y * y), J = X * K(c, a, x, g) + H * K(l, h, u, y);
|
|
1036
|
+
if (J) return ft(J);
|
|
1037
|
+
const z = X * X * K(c, a, M, b) + X * H * K(l, h, x, g) + H * H * K(p, f, u, y);
|
|
1038
|
+
if (z) return ft(z);
|
|
1039
|
+
const Et = X * K(l, h, M, b) + H * K(p, f, x, g);
|
|
1040
|
+
return ft(Et || K(p, f, M, b));
|
|
1041
|
+
}
|
|
1042
|
+
let k = 1, T = l, q = h, m = p, d = f, _ = u, w = y, E = x, I = g, C = M, S = b;
|
|
1043
|
+
if (A && (T = x, q = g, m = M, d = b, _ = c, w = a, E = l, I = h, C = p, S = f, k = -1), _ !== 0 || w !== 0) {
|
|
1044
|
+
const X = K(m, d, _, w);
|
|
1045
|
+
if (X) return k * ft(X);
|
|
1046
|
+
const H = K(T, q, E, I);
|
|
1047
|
+
if (H) return k * ft(H);
|
|
1048
|
+
const J = K(m, d, E, I);
|
|
1049
|
+
if (J) return k * ft(J);
|
|
1050
|
+
const z = K(T, q, C, S);
|
|
1051
|
+
return z ? k * ft(z) : k * ft(K(m, d, C, S));
|
|
1052
|
+
}
|
|
1053
|
+
const O = Math.sqrt(T * T + q * q), L = Math.sqrt(E * E + I * I), W = Math.sqrt(O) * K(T, q, C, S) + Math.sqrt(L) * K(m, d, E, I);
|
|
1054
|
+
return ft(W || K(m, d, C, S));
|
|
1055
|
+
}
|
|
1056
|
+
function xo(s, t, n, o, e) {
|
|
1057
|
+
let i = s[t];
|
|
1058
|
+
if (i.type === ct) {
|
|
1059
|
+
const r = i.convertToCubic();
|
|
1060
|
+
s[t] = r, i = r;
|
|
1061
|
+
}
|
|
1062
|
+
if (i.type === Ct)
|
|
1063
|
+
if (n === 0) {
|
|
1064
|
+
const r = Math.sqrt((i.p1x - i.p0x) ** 2 + (i.p1y - i.p0y) ** 2);
|
|
1065
|
+
i.p1x += r * o, i.p1y += r * e;
|
|
1063
1066
|
} else {
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1067
|
+
const r = Math.sqrt((i.p2x - i.p3x) ** 2 + (i.p2y - i.p3y) ** 2);
|
|
1068
|
+
i.p2x += r * o, i.p2y += r * e;
|
|
1066
1069
|
}
|
|
1067
1070
|
}
|
|
1068
|
-
const
|
|
1069
|
-
function
|
|
1070
|
-
for (let
|
|
1071
|
-
const
|
|
1072
|
-
let
|
|
1073
|
-
for (let
|
|
1074
|
-
const
|
|
1075
|
-
(
|
|
1071
|
+
const Bt = [0, 0], Vt = [0, 0];
|
|
1072
|
+
function Re(s) {
|
|
1073
|
+
for (let t = 0; t < s.contours.length; t++) {
|
|
1074
|
+
const n = s.contours[t];
|
|
1075
|
+
let o = 0;
|
|
1076
|
+
for (let e = 0; e < n.length; e++) {
|
|
1077
|
+
const i = n[e];
|
|
1078
|
+
(i.p0x !== i.endX() || i.p0y !== i.endY()) && (n[o++] = i);
|
|
1076
1079
|
}
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1079
|
-
for (const
|
|
1080
|
-
if (
|
|
1081
|
-
const [
|
|
1082
|
-
|
|
1083
|
-
} else if (
|
|
1084
|
-
const
|
|
1085
|
-
for (let
|
|
1086
|
-
const
|
|
1087
|
-
|
|
1088
|
-
const c = Math.sqrt(
|
|
1089
|
-
if (c === 0 ||
|
|
1090
|
-
const
|
|
1091
|
-
if (
|
|
1092
|
-
const
|
|
1093
|
-
let
|
|
1094
|
-
const M = Math.sqrt(
|
|
1080
|
+
n.length = o;
|
|
1081
|
+
}
|
|
1082
|
+
for (const t of s.contours)
|
|
1083
|
+
if (t.length === 1) {
|
|
1084
|
+
const [n, o, e] = t[0].splitInThirds();
|
|
1085
|
+
t.length = 0, t.push(n, o, e);
|
|
1086
|
+
} else if (t.length > 0) {
|
|
1087
|
+
const n = t.length;
|
|
1088
|
+
for (let o = 0; o < n; o++) {
|
|
1089
|
+
const e = (o + n - 1) % n, i = t[e], r = t[o];
|
|
1090
|
+
i.direction(1, Bt), r.direction(0, Vt);
|
|
1091
|
+
const c = Math.sqrt(Bt[0] ** 2 + Bt[1] ** 2), a = Math.sqrt(Vt[0] ** 2 + Vt[1] ** 2);
|
|
1092
|
+
if (c === 0 || a === 0) continue;
|
|
1093
|
+
const l = Bt[0] / c, h = Bt[1] / c, p = Vt[0] / a, f = Vt[1] / a;
|
|
1094
|
+
if (Ko(l, h, p, f) < fo - 1) {
|
|
1095
|
+
const u = fo - 1, y = Te * Math.sqrt(1 - u * u) / u;
|
|
1096
|
+
let x = p - l, g = f - h;
|
|
1097
|
+
const M = Math.sqrt(x * x + g * g);
|
|
1095
1098
|
if (M === 0) continue;
|
|
1096
|
-
|
|
1099
|
+
x = y * x / M, g = y * g / M, Se(i, r) < 0 && (x = -x, g = -g), xo(t, e, 1, -g, x), xo(t, o, 0, g, -x);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const _o = [0, 0, 0], go = [0, 0, 0], Mo = [0, 0];
|
|
1105
|
+
function No(s) {
|
|
1106
|
+
const t = 0.5 * (Math.sqrt(5) - 1), n = s.map(() => 0), o = [];
|
|
1107
|
+
for (let e = 0; e < s.length; e++) {
|
|
1108
|
+
const i = s[e];
|
|
1109
|
+
if (n[e] || i.length === 0) continue;
|
|
1110
|
+
const r = i[0].p0y;
|
|
1111
|
+
let c = r;
|
|
1112
|
+
for (let l = 0; l < i.length && r === c; l++) c = i[l].endY();
|
|
1113
|
+
for (let l = 0; l < i.length && r === c; l++)
|
|
1114
|
+
i[l].point(t, Mo), c = Mo[1];
|
|
1115
|
+
const a = Po(r, c, t);
|
|
1116
|
+
for (let l = 0; l < s.length; l++)
|
|
1117
|
+
for (const h of s[l]) {
|
|
1118
|
+
const p = h.scanlineIntersections(a, _o, go);
|
|
1119
|
+
for (let f = 0; f < p; f++) o.push({ x: _o[f], dy: go[f], c: l });
|
|
1120
|
+
}
|
|
1121
|
+
o.sort((l, h) => ft(l.x - h.x));
|
|
1122
|
+
for (let l = 1; l < o.length; l++)
|
|
1123
|
+
o[l].x === o[l - 1].x && (o[l].dy = o[l - 1].dy = 0);
|
|
1124
|
+
for (let l = 0; l < o.length; l++) {
|
|
1125
|
+
const h = o[l];
|
|
1126
|
+
h.dy && (n[h.c] += 2 * (l & 1 ^ (h.dy > 0 ? 1 : 0)) - 1);
|
|
1127
|
+
}
|
|
1128
|
+
o.length = 0;
|
|
1129
|
+
}
|
|
1130
|
+
for (let e = 0; e < s.length; e++) {
|
|
1131
|
+
if (n[e] >= 0) continue;
|
|
1132
|
+
const i = s[e].reverse();
|
|
1133
|
+
for (let r = 0; r < i.length; r++) {
|
|
1134
|
+
const c = i[r];
|
|
1135
|
+
i[r] = c.type === nt ? new st(nt, c.p1x, c.p1y, c.p0x, c.p0y, 0, 0, 0, 0) : c.type === ct ? new st(ct, c.p2x, c.p2y, c.p1x, c.p1y, c.p0x, c.p0y, 0, 0) : new st(Ct, c.p3x, c.p3y, c.p2x, c.p2y, c.p1x, c.p1y, c.p0x, c.p0y);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
const mo = 1e-5, ms = 1e-6, Le = 2e4, Pe = 1e5;
|
|
1140
|
+
function $e(s) {
|
|
1141
|
+
return [s.p0x, s.p0y, s.p1x, s.p1y, s.p2x, s.p2y, s.p3x, s.p3y].slice(0, 2 * s.type + 4);
|
|
1142
|
+
}
|
|
1143
|
+
function bo(s) {
|
|
1144
|
+
const t = s.length / 2 - 2;
|
|
1145
|
+
return new st(
|
|
1146
|
+
t,
|
|
1147
|
+
s[0],
|
|
1148
|
+
s[1],
|
|
1149
|
+
s[2],
|
|
1150
|
+
s[3],
|
|
1151
|
+
s[4] ?? 0,
|
|
1152
|
+
s[5] ?? 0,
|
|
1153
|
+
s[6] ?? 0,
|
|
1154
|
+
s[7] ?? 0
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
const rt = new Float64Array(8), at = new Float64Array(8), Rt = new Float64Array(8);
|
|
1158
|
+
function bs(s, t, n, o) {
|
|
1159
|
+
const e = s.length, i = e / 2 - 1;
|
|
1160
|
+
for (let r = 0; r <= i; r++) {
|
|
1161
|
+
for (let c = 0; c < e; c++) Rt[c] = s[c];
|
|
1162
|
+
for (let c = 0, a = e; c < i; c++, a -= 2) {
|
|
1163
|
+
const l = c < i - r ? t : n;
|
|
1164
|
+
for (let h = 0; h < a - 2; h++) Rt[h] = Rt[h] + l * (Rt[h + 2] - Rt[h]);
|
|
1165
|
+
}
|
|
1166
|
+
o[2 * r] = Rt[0], o[2 * r + 1] = Rt[1];
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function Oe(s, t, n) {
|
|
1170
|
+
return bs(s, t, n, rt), Array.from(rt.subarray(0, s.length));
|
|
1171
|
+
}
|
|
1172
|
+
let ws = 0, As = 0, qt = -1, Jt = -1, tn = 0, nn = 0, Mn = 0, mn = 0;
|
|
1173
|
+
function Ne(s, t) {
|
|
1174
|
+
qt = -1, Jt = -1;
|
|
1175
|
+
let n = 0;
|
|
1176
|
+
for (let h = 0; h < 2; h++) {
|
|
1177
|
+
const p = h ? s.length - 2 : 0;
|
|
1178
|
+
for (let f = 0; f < 2; f++) {
|
|
1179
|
+
const u = f ? t.length - 2 : 0;
|
|
1180
|
+
s[p] === t[u] && s[p + 1] === t[u + 1] && (n++, qt = h, Jt = f);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (n !== 1) {
|
|
1184
|
+
qt = -1;
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
const o = qt ? s.length - 2 : 0;
|
|
1188
|
+
tn = s[o], nn = s[o + 1];
|
|
1189
|
+
let e = 0, i = 0;
|
|
1190
|
+
for (let h = 2; h < s.length && e === 0 && i === 0; h += 2) {
|
|
1191
|
+
const p = qt ? s.length - 2 - h : h;
|
|
1192
|
+
e = s[p] - tn, i = s[p + 1] - nn;
|
|
1193
|
+
}
|
|
1194
|
+
let r = 0, c = 0;
|
|
1195
|
+
for (let h = 2; h < t.length && r === 0 && c === 0; h += 2) {
|
|
1196
|
+
const p = Jt ? t.length - 2 - h : h;
|
|
1197
|
+
r = t[p] - tn, c = t[p + 1] - nn;
|
|
1198
|
+
}
|
|
1199
|
+
const a = Math.hypot(e, i), l = Math.hypot(r, c);
|
|
1200
|
+
Mn = e / a - r / l, mn = i / a - c / l, Math.hypot(Mn, mn) > 1e-9 || (qt = -1);
|
|
1201
|
+
}
|
|
1202
|
+
function Ue(s, t) {
|
|
1203
|
+
const n = qt ? s - 2 : 0;
|
|
1204
|
+
for (let e = 0; e < s; e += 2)
|
|
1205
|
+
if (e !== n && (rt[e] - tn) * Mn + (rt[e + 1] - nn) * mn <= 0) return !1;
|
|
1206
|
+
const o = Jt ? t - 2 : 0;
|
|
1207
|
+
for (let e = 0; e < t; e += 2)
|
|
1208
|
+
if (e !== o && (at[e] - tn) * Mn + (at[e + 1] - nn) * mn >= 0) return !1;
|
|
1209
|
+
return !0;
|
|
1210
|
+
}
|
|
1211
|
+
function Kt(s, t, n, o, e, i, r) {
|
|
1212
|
+
if (--ws < 0 || --As < 0) return;
|
|
1213
|
+
const c = s.length, a = o.length;
|
|
1214
|
+
bs(s, t, n, rt), bs(o, e, i, at);
|
|
1215
|
+
let l = 1 / 0, h = 1 / 0, p = -1 / 0, f = -1 / 0;
|
|
1216
|
+
for (let A = 0; A < c; A += 2)
|
|
1217
|
+
l = Math.min(l, rt[A]), h = Math.min(h, rt[A + 1]), p = Math.max(p, rt[A]), f = Math.max(f, rt[A + 1]);
|
|
1218
|
+
let u = 1 / 0, y = 1 / 0, x = -1 / 0, g = -1 / 0;
|
|
1219
|
+
for (let A = 0; A < a; A += 2)
|
|
1220
|
+
u = Math.min(u, at[A]), y = Math.min(y, at[A + 1]), x = Math.max(x, at[A]), g = Math.max(g, at[A + 1]);
|
|
1221
|
+
if (l > x || u > p || h > g || y > f || qt >= 0 && (qt ? n === 1 : t === 0) && (Jt ? i === 1 : e === 0) && Ue(c, a))
|
|
1222
|
+
return;
|
|
1223
|
+
const M = Math.max(p - l, f - h), b = Math.max(x - u, g - y);
|
|
1224
|
+
if (c === 4 && a === 4 || M < mo && b < mo) {
|
|
1225
|
+
const A = rt[c - 2] - rt[0], F = rt[c - 1] - rt[1], k = at[a - 2] - at[0], T = at[a - 1] - at[1], q = K(A, F, k, T), m = K(at[0] - rt[0], at[1] - rt[1], k, T) / q, d = K(at[0] - rt[0], at[1] - rt[1], A, F) / q;
|
|
1226
|
+
m >= 0 && m <= 1 && d >= 0 && d <= 1 && r.push(t + m * (n - t), e + d * (i - e));
|
|
1227
|
+
} else M > b ? (Kt(s, t, (t + n) / 2, o, e, i, r), Kt(s, (t + n) / 2, n, o, e, i, r)) : (Kt(s, t, n, o, e, (e + i) / 2, r), Kt(s, t, n, o, (e + i) / 2, i, r));
|
|
1228
|
+
}
|
|
1229
|
+
function un(s, t, n) {
|
|
1230
|
+
const o = s[2] - s[0], e = s[3] - s[1];
|
|
1231
|
+
return ((t - s[0]) * o + (n - s[1]) * e) / (o * o + e * e);
|
|
1232
|
+
}
|
|
1233
|
+
function Ge(s, t, n) {
|
|
1234
|
+
if (s.length !== 4 || t.length !== 4) return !1;
|
|
1235
|
+
const o = s[2] - s[0], e = s[3] - s[1], i = 1e-9 * Math.hypot(o, e);
|
|
1236
|
+
return Math.abs(K(o, e, t[0] - s[0], t[1] - s[1])) > i || Math.abs(K(o, e, t[2] - s[0], t[3] - s[1])) > i ? !1 : (n.push(un(s, t[0], t[1]), 0, un(s, t[2], t[3]), 1), n.push(0, un(t, s[0], s[1]), 1, un(t, s[2], s[3])), !0);
|
|
1237
|
+
}
|
|
1238
|
+
function Ye(s) {
|
|
1239
|
+
const t = [];
|
|
1240
|
+
for (let n = s.length - 2; n >= 0; n -= 2) t.push(s[n], s[n + 1]);
|
|
1241
|
+
return t;
|
|
1242
|
+
}
|
|
1243
|
+
function Xe(s, t) {
|
|
1244
|
+
if (s.length !== t.length) return !1;
|
|
1245
|
+
for (let n = 0; n < s.length; n++) if (!(Math.abs(s[n] - t[n]) < ms)) return !1;
|
|
1246
|
+
return !0;
|
|
1247
|
+
}
|
|
1248
|
+
const jt = [0, 0], Lt = [0, 0], bn = [0, 0, 0], wn = [0, 0, 0];
|
|
1249
|
+
let Wt = new Int32Array(8);
|
|
1250
|
+
const We = 0, Uo = 1, He = 2;
|
|
1251
|
+
function wo(s, t, n, o) {
|
|
1252
|
+
let e = 0;
|
|
1253
|
+
for (let i = 0; i < s.length; i++) {
|
|
1254
|
+
if (o < t[4 * i + 1] - 1e-9 || o > t[4 * i + 3] + 1e-9) continue;
|
|
1255
|
+
const r = s[i].scanlineIntersections(o, bn, wn);
|
|
1256
|
+
for (let c = 0; c < r; c++) bn[c] <= n && (e += wn[c]);
|
|
1257
|
+
}
|
|
1258
|
+
return e !== 0;
|
|
1259
|
+
}
|
|
1260
|
+
function Ao(s, t, n, o, e, i, r) {
|
|
1261
|
+
Wt.fill(0, 0, n);
|
|
1262
|
+
for (let a = 0; a < s.length; a++) {
|
|
1263
|
+
if (r < e[4 * a + 1] - 1e-9 || r > e[4 * a + 3] + 1e-9) continue;
|
|
1264
|
+
const l = s[a].scanlineIntersections(r, bn, wn);
|
|
1265
|
+
for (let h = 0; h < l; h++) bn[h] <= i && (Wt[t[a]] += wn[h]);
|
|
1266
|
+
}
|
|
1267
|
+
let c = !1;
|
|
1268
|
+
for (let a = 1; a < n && !c; a++) c = Wt[a] !== 0;
|
|
1269
|
+
return Wt[0] !== 0 && (o === Uo ? c : !c);
|
|
1270
|
+
}
|
|
1271
|
+
function Be(s) {
|
|
1272
|
+
const t = Is([s.contours]);
|
|
1273
|
+
t && (s.contours = t);
|
|
1274
|
+
}
|
|
1275
|
+
function ko(s, t) {
|
|
1276
|
+
const n = Is([s.contours, ...t.length > 0 ? t : [[]]], Uo);
|
|
1277
|
+
n && (s.contours = n);
|
|
1278
|
+
}
|
|
1279
|
+
function Ve(s, t) {
|
|
1280
|
+
if (t.length === 0) return;
|
|
1281
|
+
const n = Is([s.contours, ...t], He);
|
|
1282
|
+
n && (s.contours = n);
|
|
1283
|
+
}
|
|
1284
|
+
function Is(s, t = We) {
|
|
1285
|
+
const n = s.flat(), o = n.flat(), e = o.map($e), i = e.length, r = s.length, c = r > 1;
|
|
1286
|
+
Wt.length < r && (Wt = new Int32Array(r));
|
|
1287
|
+
const a = new Float64Array(4 * i), l = new Int32Array(i), h = new Int32Array(i);
|
|
1288
|
+
let p = 0;
|
|
1289
|
+
for (let m = 0; m < r; m++)
|
|
1290
|
+
for (const d of s[m]) {
|
|
1291
|
+
for (let _ = 0; _ < d.length; _++)
|
|
1292
|
+
l[p + _] = p + (_ + 1) % d.length, h[p + _] = m;
|
|
1293
|
+
p += d.length;
|
|
1294
|
+
}
|
|
1295
|
+
for (let m = 0; m < i; m++) {
|
|
1296
|
+
const d = e[m];
|
|
1297
|
+
let _ = 1 / 0, w = 1 / 0, E = -1 / 0, I = -1 / 0;
|
|
1298
|
+
for (let C = 0; C < d.length; C += 2)
|
|
1299
|
+
_ = Math.min(_, d[C]), w = Math.min(w, d[C + 1]), E = Math.max(E, d[C]), I = Math.max(I, d[C + 1]);
|
|
1300
|
+
a[4 * m] = _, a[4 * m + 1] = w, a[4 * m + 2] = E, a[4 * m + 3] = I;
|
|
1301
|
+
}
|
|
1302
|
+
const f = Array.from({ length: i }, (m, d) => d).sort((m, d) => a[4 * m] - a[4 * d]), u = e.map(() => []), y = new Uint8Array(i);
|
|
1303
|
+
As = Pe;
|
|
1304
|
+
for (let m = 0; m < i; m++) {
|
|
1305
|
+
const d = f[m];
|
|
1306
|
+
for (let _ = m + 1; _ < i; _++) {
|
|
1307
|
+
const w = f[_];
|
|
1308
|
+
if (a[4 * w] > a[4 * d + 2]) break;
|
|
1309
|
+
if (a[4 * d + 1] > a[4 * w + 3] || a[4 * w + 1] > a[4 * d + 3]) continue;
|
|
1310
|
+
const E = Math.min(d, w), I = Math.max(d, w);
|
|
1311
|
+
l[E] !== I && l[I] !== E && (y[E] = y[I] = 1);
|
|
1312
|
+
const C = [];
|
|
1313
|
+
if (ws = Le, Ge(e[E], e[I], C) || (Ne(e[E], e[I]), Kt(e[E], 0, 1, e[I], 0, 1, C)), ws < 0 || As < 0) return null;
|
|
1314
|
+
for (let S = 0; S < C.length; S += 2)
|
|
1315
|
+
u[E].push(C[S]), u[I].push(C[S + 1]);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
const x = u.map((m) => {
|
|
1319
|
+
const d = [0];
|
|
1320
|
+
for (const _ of m.sort((w, E) => w - E))
|
|
1321
|
+
_ - d[d.length - 1] > 1e-7 && _ < 1 - 1e-7 && d.push(_);
|
|
1322
|
+
return d.push(1), d;
|
|
1323
|
+
});
|
|
1324
|
+
let g = !1;
|
|
1325
|
+
const M = [], b = [];
|
|
1326
|
+
let A = 0;
|
|
1327
|
+
for (const m of n) {
|
|
1328
|
+
const d = A + m.length;
|
|
1329
|
+
let _ = !0;
|
|
1330
|
+
for (let C = A; C < d; C++) (y[C] || x[C].length > 2) && (_ = !1);
|
|
1331
|
+
let w = !1, E = !1, I = !1;
|
|
1332
|
+
for (let C = A; C < d; C++) {
|
|
1333
|
+
const S = x[C];
|
|
1334
|
+
for (let O = 1; O < S.length; O++) {
|
|
1335
|
+
const L = Oe(e[C], S[O - 1], S[O]), W = bo(L);
|
|
1336
|
+
W.point(0.5, jt), W.direction(0.5, Lt);
|
|
1337
|
+
const X = Math.hypot(Lt[0], Lt[1]), H = Math.hypot(L[L.length - 2] - L[0], L[L.length - 1] - L[1]);
|
|
1338
|
+
if (!(X === 0 || H === 0)) {
|
|
1339
|
+
if (!_ || !w) {
|
|
1340
|
+
const J = Math.min(1e-6, H * H / 64) / X, z = jt[0] + Lt[1] * J, Et = jt[1] - Lt[0] * J, ht = jt[0] - Lt[1] * J, vt = jt[1] + Lt[0] * J;
|
|
1341
|
+
E = c ? Ao(o, h, r, t, a, z, Et) : wo(o, a, z, Et), I = c ? Ao(o, h, r, t, a, ht, vt) : wo(o, a, ht, vt), w = !0;
|
|
1342
|
+
}
|
|
1343
|
+
E === I ? h[C] === 0 && (g = !0) : (M.push(L), b.push(E), h[C] !== 0 && (g = !0));
|
|
1097
1344
|
}
|
|
1098
1345
|
}
|
|
1099
1346
|
}
|
|
1347
|
+
A = d;
|
|
1348
|
+
}
|
|
1349
|
+
const F = 2 * b.filter(Boolean).length >= b.length, k = [];
|
|
1350
|
+
for (let m = 0; m < M.length; m++) {
|
|
1351
|
+
let d = M[m];
|
|
1352
|
+
b[m] !== F && (d = Ye(d), g = !0);
|
|
1353
|
+
let _ = !1;
|
|
1354
|
+
for (let w = 0; w < k.length && !_; w++) _ = Xe(k[w], d);
|
|
1355
|
+
_ ? g = !0 : k.push(d);
|
|
1356
|
+
}
|
|
1357
|
+
if (!g) return null;
|
|
1358
|
+
const T = new Uint8Array(k.length), q = [];
|
|
1359
|
+
for (let m = 0; m < k.length; m++) {
|
|
1360
|
+
if (T[m]) continue;
|
|
1361
|
+
T[m] = 1;
|
|
1362
|
+
const d = [k[m]];
|
|
1363
|
+
for (; ; ) {
|
|
1364
|
+
const _ = d[d.length - 1], w = _[_.length - 2], E = _[_.length - 1];
|
|
1365
|
+
if (d.length > 1 && Math.hypot(w - d[0][0], E - d[0][1]) < ms) {
|
|
1366
|
+
d[0][0] = w, d[0][1] = E;
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
let I = -1, C = ms;
|
|
1370
|
+
for (let S = 0; S < k.length; S++) {
|
|
1371
|
+
if (T[S]) continue;
|
|
1372
|
+
const O = Math.hypot(k[S][0] - w, k[S][1] - E);
|
|
1373
|
+
O < C && (I = S, C = O);
|
|
1374
|
+
}
|
|
1375
|
+
if (I < 0) return null;
|
|
1376
|
+
T[I] = 1, k[I][0] = w, k[I][1] = E, d.push(k[I]);
|
|
1377
|
+
}
|
|
1378
|
+
q.push(d.map(bo));
|
|
1379
|
+
}
|
|
1380
|
+
return q;
|
|
1100
1381
|
}
|
|
1101
|
-
const
|
|
1102
|
-
function
|
|
1103
|
-
return Math.trunc(3 + 2.875 *
|
|
1382
|
+
const qn = 1, Cn = 2, je = 3, vn = 4, ze = 5, Qe = 6, Es = 7, pt = [0, 0], Pt = [0, 0];
|
|
1383
|
+
function Ke(s, t) {
|
|
1384
|
+
return Math.trunc(3 + 2.875 * s / (t - 1) - 1.4375 + 0.5) - 3;
|
|
1104
1385
|
}
|
|
1105
|
-
function
|
|
1106
|
-
return
|
|
1386
|
+
function Ze(s, t, n, o, e) {
|
|
1387
|
+
return s * n + t * o <= 0 || Math.abs(s * o - t * n) > e;
|
|
1107
1388
|
}
|
|
1108
|
-
function
|
|
1109
|
-
const
|
|
1110
|
-
return
|
|
1389
|
+
function Je(s) {
|
|
1390
|
+
const t = Number(s.v & 1n);
|
|
1391
|
+
return s.v >>= 1n, t;
|
|
1111
1392
|
}
|
|
1112
|
-
function
|
|
1113
|
-
const
|
|
1114
|
-
return
|
|
1393
|
+
function ti(s) {
|
|
1394
|
+
const t = Number(s.v % 3n);
|
|
1395
|
+
return s.v /= 3n, t;
|
|
1115
1396
|
}
|
|
1116
|
-
function
|
|
1117
|
-
return [
|
|
1397
|
+
function Io(s) {
|
|
1398
|
+
return [Qe, ze, je][ti(s)];
|
|
1118
1399
|
}
|
|
1119
|
-
function
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1400
|
+
function Zt(s, t) {
|
|
1401
|
+
const n = s.v << 1 + Je(t);
|
|
1402
|
+
s.v = (n | n >> 3) & Es;
|
|
1122
1403
|
}
|
|
1123
|
-
function
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1404
|
+
function ni(s, t, n) {
|
|
1405
|
+
const o = s.v & n;
|
|
1406
|
+
o === qn || o === Cn || o === vn ? s.v = o ^ Es : Zt(s, t);
|
|
1126
1407
|
}
|
|
1127
|
-
function
|
|
1128
|
-
const
|
|
1129
|
-
|
|
1130
|
-
const
|
|
1131
|
-
for (const c of
|
|
1408
|
+
function si(s, t, n = 0n) {
|
|
1409
|
+
const o = Math.sin(t), e = { v: Io({ v: n }) }, i = { v: n };
|
|
1410
|
+
i.v = n, e.v = Io(i);
|
|
1411
|
+
const r = [];
|
|
1412
|
+
for (const c of s.contours) {
|
|
1132
1413
|
if (c.length === 0) continue;
|
|
1133
|
-
|
|
1134
|
-
const
|
|
1135
|
-
let
|
|
1414
|
+
r.length = 0, c[c.length - 1].direction(1, pt);
|
|
1415
|
+
const l = Math.sqrt(pt[0] * pt[0] + pt[1] * pt[1]);
|
|
1416
|
+
let h = l > 0 ? pt[0] / l : 0, p = l > 0 ? pt[1] / l : 0;
|
|
1136
1417
|
for (let f = 0; f < c.length; f++) {
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
const M = Math.sqrt(
|
|
1142
|
-
|
|
1418
|
+
const u = c[f];
|
|
1419
|
+
u.direction(0, Pt);
|
|
1420
|
+
const y = Math.sqrt(Pt[0] * Pt[0] + Pt[1] * Pt[1]), x = y > 0 ? Pt[0] / y : 0, g = y > 0 ? Pt[1] / y : 0;
|
|
1421
|
+
Ze(h, p, x, g, o) && r.push(f), u.direction(1, pt);
|
|
1422
|
+
const M = Math.sqrt(pt[0] * pt[0] + pt[1] * pt[1]);
|
|
1423
|
+
h = M > 0 ? pt[0] / M : 0, p = M > 0 ? pt[1] / M : 0;
|
|
1143
1424
|
}
|
|
1144
|
-
if (
|
|
1145
|
-
|
|
1146
|
-
for (const f of c) f.color =
|
|
1147
|
-
} else if (
|
|
1148
|
-
const f = [0,
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
if (
|
|
1152
|
-
for (let
|
|
1153
|
-
const
|
|
1154
|
-
c[(
|
|
1425
|
+
if (r.length === 0) {
|
|
1426
|
+
Zt(e, i);
|
|
1427
|
+
for (const f of c) f.color = e.v;
|
|
1428
|
+
} else if (r.length === 1) {
|
|
1429
|
+
const f = [0, Es, 0];
|
|
1430
|
+
Zt(e, i), f[0] = e.v, Zt(e, i), f[2] = e.v;
|
|
1431
|
+
const u = r[0], y = c.length;
|
|
1432
|
+
if (y >= 3)
|
|
1433
|
+
for (let x = 0; x < y; x++) {
|
|
1434
|
+
const g = Ke(x, y);
|
|
1435
|
+
c[(u + x) % y].color = f[1 + g];
|
|
1155
1436
|
}
|
|
1156
|
-
else if (
|
|
1157
|
-
const
|
|
1158
|
-
if (
|
|
1437
|
+
else if (y >= 1) {
|
|
1438
|
+
const x = [null, null, null, null, null, null, null], g = c[0].splitInThirds();
|
|
1439
|
+
if (x[0 + 3 * u] = g[0], x[1 + 3 * u] = g[1], x[2 + 3 * u] = g[2], y >= 2) {
|
|
1159
1440
|
const M = c[1].splitInThirds();
|
|
1160
|
-
|
|
1441
|
+
x[3 - 3 * u] = M[0], x[4 - 3 * u] = M[1], x[5 - 3 * u] = M[2], x[0].color = x[1].color = f[0], x[2].color = x[3].color = f[1], x[4].color = x[5].color = f[2];
|
|
1161
1442
|
} else
|
|
1162
|
-
|
|
1443
|
+
x[0].color = f[0], x[1].color = f[1], x[2].color = f[2];
|
|
1163
1444
|
c.length = 0;
|
|
1164
|
-
for (const M of
|
|
1445
|
+
for (const M of x) M !== null && c.push(M);
|
|
1165
1446
|
}
|
|
1166
1447
|
} else {
|
|
1167
|
-
const f =
|
|
1168
|
-
let
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
const
|
|
1172
|
-
for (let M = 0; M <
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1448
|
+
const f = r.length;
|
|
1449
|
+
let u = 0;
|
|
1450
|
+
const y = r[0], x = c.length;
|
|
1451
|
+
Zt(e, i);
|
|
1452
|
+
const g = e.v;
|
|
1453
|
+
for (let M = 0; M < x; M++) {
|
|
1454
|
+
const b = (y + M) % x;
|
|
1455
|
+
u + 1 < f && r[u + 1] === b && (++u, ni(e, i, u === f - 1 ? g : 0)), c[b].color = e.v;
|
|
1175
1456
|
}
|
|
1176
1457
|
}
|
|
1177
1458
|
}
|
|
1178
1459
|
}
|
|
1179
|
-
const
|
|
1180
|
-
let
|
|
1181
|
-
const
|
|
1182
|
-
let
|
|
1183
|
-
function
|
|
1184
|
-
const
|
|
1185
|
-
if (
|
|
1186
|
-
let
|
|
1187
|
-
if (
|
|
1188
|
-
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
const c =
|
|
1194
|
-
|
|
1195
|
-
} else if (
|
|
1196
|
-
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
const c =
|
|
1202
|
-
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1460
|
+
const V = Number.MAX_VALUE, P = [0, 0], gt = [0, 0];
|
|
1461
|
+
let Eo = 0, Z = new Float64Array(0), ot = new Float64Array(0), G = new Float64Array(0), Y = new Float64Array(0), et = new Int32Array(0), it = new Float64Array(0), Gt = new Float64Array(0), Yt = new Float64Array(0), Xt = new Float64Array(0), $t = new Int32Array(0);
|
|
1462
|
+
const tt = [0, 0];
|
|
1463
|
+
let Do = 0, ns = new Float64Array(0), ss = new Float64Array(0), os = new Float64Array(0), es = new Float64Array(0), is = new Float64Array(0), cs = new Float64Array(0), rs = new Float64Array(0), as = new Float64Array(0), ls = new Float64Array(0), hs = new Float64Array(0), ps = new Float64Array(0), fs = new Float64Array(0), qo = 0, zt = new Int32Array(0);
|
|
1464
|
+
function oi(s) {
|
|
1465
|
+
const t = s.length;
|
|
1466
|
+
if (t === 0) return 0;
|
|
1467
|
+
let n = 0;
|
|
1468
|
+
if (t === 1) {
|
|
1469
|
+
s[0].point(0, tt);
|
|
1470
|
+
const o = tt[0], e = tt[1];
|
|
1471
|
+
s[0].point(1 / 3, tt);
|
|
1472
|
+
const i = tt[0], r = tt[1];
|
|
1473
|
+
s[0].point(2 / 3, tt);
|
|
1474
|
+
const c = tt[0], a = tt[1];
|
|
1475
|
+
n += o * r - e * i, n += i * a - r * c, n += c * e - a * o;
|
|
1476
|
+
} else if (t === 2) {
|
|
1477
|
+
s[0].point(0, tt);
|
|
1478
|
+
const o = tt[0], e = tt[1];
|
|
1479
|
+
s[0].point(0.5, tt);
|
|
1480
|
+
const i = tt[0], r = tt[1];
|
|
1481
|
+
s[1].point(0, tt);
|
|
1482
|
+
const c = tt[0], a = tt[1];
|
|
1483
|
+
s[1].point(0.5, tt);
|
|
1484
|
+
const l = tt[0], h = tt[1];
|
|
1485
|
+
n += o * r - e * i, n += i * a - r * c, n += c * h - a * l, n += l * e - h * o;
|
|
1205
1486
|
} else {
|
|
1206
|
-
const
|
|
1207
|
-
let
|
|
1208
|
-
for (let
|
|
1209
|
-
const c =
|
|
1210
|
-
|
|
1487
|
+
const o = s[t - 1];
|
|
1488
|
+
let e = o.p0x, i = o.p0y;
|
|
1489
|
+
for (let r = 0; r < t; r++) {
|
|
1490
|
+
const c = s[r].p0x, a = s[r].p0y;
|
|
1491
|
+
n += e * a - i * c, e = c, i = a;
|
|
1211
1492
|
}
|
|
1212
1493
|
}
|
|
1213
|
-
return
|
|
1214
|
-
}
|
|
1215
|
-
function
|
|
1216
|
-
const c =
|
|
1217
|
-
let
|
|
1218
|
-
if (
|
|
1219
|
-
c.direction(0,
|
|
1220
|
-
const
|
|
1221
|
-
if (
|
|
1222
|
-
const
|
|
1223
|
-
c.point(0,
|
|
1224
|
-
const f =
|
|
1225
|
-
if (f *
|
|
1226
|
-
const
|
|
1227
|
-
Math.abs(
|
|
1494
|
+
return n > 0 ? -1 : n < 0 ? 1 : 0;
|
|
1495
|
+
}
|
|
1496
|
+
function ei(s, t, n, o, e, i, r) {
|
|
1497
|
+
const c = r[s][t];
|
|
1498
|
+
let a = n;
|
|
1499
|
+
if (i < 0) {
|
|
1500
|
+
c.direction(0, P);
|
|
1501
|
+
const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
1502
|
+
if (l > 0) {
|
|
1503
|
+
const h = P[0] / l, p = P[1] / l;
|
|
1504
|
+
c.point(0, gt);
|
|
1505
|
+
const f = o - gt[0], u = e - gt[1];
|
|
1506
|
+
if (f * h + u * p < 0) {
|
|
1507
|
+
const x = f * p - u * h;
|
|
1508
|
+
Math.abs(x) <= Math.abs(a) && (a = x);
|
|
1228
1509
|
}
|
|
1229
1510
|
}
|
|
1230
1511
|
}
|
|
1231
|
-
if (
|
|
1232
|
-
c.direction(1,
|
|
1233
|
-
const
|
|
1234
|
-
if (
|
|
1235
|
-
const
|
|
1236
|
-
c.point(1,
|
|
1237
|
-
const f =
|
|
1238
|
-
if (f *
|
|
1239
|
-
const
|
|
1240
|
-
Math.abs(
|
|
1512
|
+
if (i > 1) {
|
|
1513
|
+
c.direction(1, P);
|
|
1514
|
+
const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
1515
|
+
if (l > 0) {
|
|
1516
|
+
const h = P[0] / l, p = P[1] / l;
|
|
1517
|
+
c.point(1, gt);
|
|
1518
|
+
const f = o - gt[0], u = e - gt[1];
|
|
1519
|
+
if (f * h + u * p > 0) {
|
|
1520
|
+
const x = f * p - u * h;
|
|
1521
|
+
Math.abs(x) <= Math.abs(a) && (a = x);
|
|
1241
1522
|
}
|
|
1242
1523
|
}
|
|
1243
1524
|
}
|
|
1244
|
-
return
|
|
1525
|
+
return a;
|
|
1245
1526
|
}
|
|
1246
|
-
function
|
|
1247
|
-
let
|
|
1248
|
-
if (
|
|
1249
|
-
const
|
|
1250
|
-
Math.abs(
|
|
1527
|
+
function xt(s, t, n, o, e, i, r, c, a) {
|
|
1528
|
+
let l = s < 0 ? t : n;
|
|
1529
|
+
if (e >= 0) {
|
|
1530
|
+
const h = ei(o, e, s, r, c, i, a);
|
|
1531
|
+
Math.abs(h) < Math.abs(l) && (l = h);
|
|
1251
1532
|
}
|
|
1252
|
-
return
|
|
1533
|
+
return l;
|
|
1253
1534
|
}
|
|
1254
|
-
function
|
|
1255
|
-
return Math.max(Math.min(
|
|
1535
|
+
function wt(s, t, n) {
|
|
1536
|
+
return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
|
|
1256
1537
|
}
|
|
1257
|
-
function
|
|
1258
|
-
if (c.length !==
|
|
1259
|
-
throw new Error(`generateMSDF: out.length ${c.length} !== ${
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1538
|
+
function ii(s, t, n, o, e, i, r, c) {
|
|
1539
|
+
if (c.length !== t * n * 3)
|
|
1540
|
+
throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
|
|
1541
|
+
const a = s.contours, l = a.length;
|
|
1542
|
+
if (l === 0) {
|
|
1262
1543
|
c.fill(0);
|
|
1263
1544
|
return;
|
|
1264
1545
|
}
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
for (let
|
|
1268
|
-
|
|
1269
|
-
let
|
|
1270
|
-
for (let
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
for (let
|
|
1274
|
-
const
|
|
1275
|
-
for (let M = 0; M <
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1278
|
-
let
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1546
|
+
const h = o / r;
|
|
1547
|
+
$t.length < l && ($t = new Int32Array(l));
|
|
1548
|
+
for (let u = 0; u < l; u++) $t[u] = oi(a[u]);
|
|
1549
|
+
qo < l + 1 && (zt = new Int32Array(l + 1), qo = l + 1);
|
|
1550
|
+
let p = 0;
|
|
1551
|
+
for (let u = 0; u < l; u++)
|
|
1552
|
+
zt[u] = p, p += a[u].length;
|
|
1553
|
+
zt[l] = p, Do < p && (ns = new Float64Array(p), ss = new Float64Array(p), os = new Float64Array(p), es = new Float64Array(p), is = new Float64Array(p), cs = new Float64Array(p), rs = new Float64Array(p), as = new Float64Array(p), ls = new Float64Array(p), hs = new Float64Array(p), ps = new Float64Array(p), fs = new Float64Array(p), Do = p);
|
|
1554
|
+
for (let u = 0; u < l; u++) {
|
|
1555
|
+
const y = a[u], x = y.length, g = zt[u];
|
|
1556
|
+
for (let M = 0; M < x; M++) {
|
|
1557
|
+
const b = y[M], A = y[(M + x - 1) % x], F = y[(M + 1) % x], k = g + M;
|
|
1558
|
+
b.point(0, gt), ns[k] = gt[0], ss[k] = gt[1], b.point(1, gt), os[k] = gt[0], es[k] = gt[1], b.direction(0, P);
|
|
1559
|
+
let T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
1560
|
+
const q = T > 0 ? P[0] / T : 0, m = T > 0 ? P[1] / T : 0;
|
|
1561
|
+
is[k] = q, cs[k] = m, b.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
1562
|
+
const d = T > 0 ? P[0] / T : 0, _ = T > 0 ? P[1] / T : 0;
|
|
1563
|
+
rs[k] = d, as[k] = _, A.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
1564
|
+
const w = T > 0 ? P[0] / T : 0, E = T > 0 ? P[1] / T : 0;
|
|
1565
|
+
F.direction(0, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
1566
|
+
const I = T > 0 ? P[0] / T : 0, C = T > 0 ? P[1] / T : 0, S = w + q, O = E + m, L = Math.sqrt(S * S + O * O);
|
|
1567
|
+
ls[k] = L > 0 ? S / L : 0, hs[k] = L > 0 ? O / L : 0;
|
|
1568
|
+
const W = d + I, X = _ + C, H = Math.sqrt(W * W + X * X);
|
|
1569
|
+
ps[k] = H > 0 ? -(W / H) : 0, fs[k] = H > 0 ? -(X / H) : 0;
|
|
1289
1570
|
}
|
|
1290
1571
|
}
|
|
1291
|
-
if (
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1572
|
+
if (Eo < l) {
|
|
1573
|
+
const u = l * 3;
|
|
1574
|
+
Z = new Float64Array(u), ot = new Float64Array(u), G = new Float64Array(u), Y = new Float64Array(u), et = new Int32Array(u), it = new Float64Array(u), Gt = new Float64Array(l), Yt = new Float64Array(l), Xt = new Float64Array(l), Eo = l;
|
|
1294
1575
|
}
|
|
1295
1576
|
const f = { distance: 0, dot: 0, param: 0 };
|
|
1296
|
-
for (let
|
|
1297
|
-
for (let
|
|
1298
|
-
const
|
|
1299
|
-
for (let
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
for (let
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
const
|
|
1306
|
-
if (
|
|
1307
|
-
const
|
|
1308
|
-
(
|
|
1577
|
+
for (let u = 0; u < n; u++)
|
|
1578
|
+
for (let y = 0; y < t; y++) {
|
|
1579
|
+
const x = (y + 0.5) / o - e, g = (u + 0.5) / o - i;
|
|
1580
|
+
for (let R = 0; R < l; R++) {
|
|
1581
|
+
const v = a[R], ut = v.length, D = R * 3, N = zt[R];
|
|
1582
|
+
Z[D] = Z[D + 1] = Z[D + 2] = -V, ot[D] = ot[D + 1] = ot[D + 2] = 0, G[D] = G[D + 1] = G[D + 2] = -V, Y[D] = Y[D + 1] = Y[D + 2] = V, et[D] = et[D + 1] = et[D + 2] = -1, it[D] = it[D + 1] = it[D + 2] = 0;
|
|
1583
|
+
for (let U = 0; U < ut; U++) {
|
|
1584
|
+
const j = v[U], Bn = j.color, Vn = (Bn & qn) !== 0, jn = (Bn & Cn) !== 0, zn = (Bn & vn) !== 0;
|
|
1585
|
+
j.signedDistance(x, g, f);
|
|
1586
|
+
const pn = f.distance, Ut = f.dot, Qn = f.param, Tt = Math.abs(pn);
|
|
1587
|
+
if (Vn) {
|
|
1588
|
+
const kt = Math.abs(Z[D]);
|
|
1589
|
+
(Tt < kt || Tt === kt && Ut < ot[D]) && (Z[D] = pn, ot[D] = Ut, et[D] = U, it[D] = Qn);
|
|
1309
1590
|
}
|
|
1310
|
-
if (
|
|
1311
|
-
const
|
|
1312
|
-
(
|
|
1591
|
+
if (jn) {
|
|
1592
|
+
const kt = Math.abs(Z[D + 1]);
|
|
1593
|
+
(Tt < kt || Tt === kt && Ut < ot[D + 1]) && (Z[D + 1] = pn, ot[D + 1] = Ut, et[D + 1] = U, it[D + 1] = Qn);
|
|
1313
1594
|
}
|
|
1314
|
-
if (
|
|
1315
|
-
const
|
|
1316
|
-
(
|
|
1595
|
+
if (zn) {
|
|
1596
|
+
const kt = Math.abs(Z[D + 2]);
|
|
1597
|
+
(Tt < kt || Tt === kt && Ut < ot[D + 2]) && (Z[D + 2] = pn, ot[D + 2] = Ut, et[D + 2] = U, it[D + 2] = Qn);
|
|
1317
1598
|
}
|
|
1318
|
-
const
|
|
1319
|
-
if (
|
|
1320
|
-
const
|
|
1321
|
-
Math.abs(
|
|
1599
|
+
const yt = N + U, Kn = x - ns[yt], Zn = g - ss[yt], Jn = x - os[yt], ts = g - es[yt], so = is[yt], oo = cs[yt], eo = rs[yt], io = as[yt], zo = Kn * ls[yt] + Zn * hs[yt], Qo = Jn * ps[yt] + ts * fs[yt];
|
|
1600
|
+
if (zo > 0 && -(Kn * so + Zn * oo) > 0) {
|
|
1601
|
+
const $ = Kn * oo - Zn * so;
|
|
1602
|
+
Math.abs($) < Tt && (Vn && ($ <= 0 && $ > G[D] ? G[D] = $ : $ > 0 && $ < Y[D] && (Y[D] = $)), jn && ($ <= 0 && $ > G[D + 1] ? G[D + 1] = $ : $ > 0 && $ < Y[D + 1] && (Y[D + 1] = $)), zn && ($ <= 0 && $ > G[D + 2] ? G[D + 2] = $ : $ > 0 && $ < Y[D + 2] && (Y[D + 2] = $)));
|
|
1322
1603
|
}
|
|
1323
|
-
if (
|
|
1324
|
-
const
|
|
1325
|
-
Math.abs(
|
|
1604
|
+
if (Qo > 0 && Jn * eo + ts * io > 0) {
|
|
1605
|
+
const $ = Jn * io - ts * eo;
|
|
1606
|
+
Math.abs($) < Tt && (Vn && ($ <= 0 && $ > G[D] ? G[D] = $ : $ > 0 && $ < Y[D] && (Y[D] = $)), jn && ($ <= 0 && $ > G[D + 1] ? G[D + 1] = $ : $ > 0 && $ < Y[D + 1] && (Y[D + 1] = $)), zn && ($ <= 0 && $ > G[D + 2] ? G[D + 2] = $ : $ > 0 && $ < Y[D + 2] && (Y[D + 2] = $)));
|
|
1326
1607
|
}
|
|
1327
1608
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
G[
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
u,
|
|
1609
|
+
Gt[R] = xt(
|
|
1610
|
+
Z[D],
|
|
1611
|
+
G[D],
|
|
1612
|
+
Y[D],
|
|
1613
|
+
R,
|
|
1614
|
+
et[D],
|
|
1615
|
+
it[D],
|
|
1336
1616
|
x,
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1617
|
+
g,
|
|
1618
|
+
a
|
|
1619
|
+
), Yt[R] = xt(
|
|
1620
|
+
Z[D + 1],
|
|
1621
|
+
G[D + 1],
|
|
1622
|
+
Y[D + 1],
|
|
1623
|
+
R,
|
|
1624
|
+
et[D + 1],
|
|
1625
|
+
it[D + 1],
|
|
1346
1626
|
x,
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1627
|
+
g,
|
|
1628
|
+
a
|
|
1629
|
+
), Xt[R] = xt(
|
|
1630
|
+
Z[D + 2],
|
|
1631
|
+
G[D + 2],
|
|
1632
|
+
Y[D + 2],
|
|
1633
|
+
R,
|
|
1634
|
+
et[D + 2],
|
|
1635
|
+
it[D + 2],
|
|
1356
1636
|
x,
|
|
1357
|
-
|
|
1637
|
+
g,
|
|
1638
|
+
a
|
|
1358
1639
|
);
|
|
1359
1640
|
}
|
|
1360
|
-
let M = -
|
|
1361
|
-
for (let
|
|
1362
|
-
const
|
|
1641
|
+
let M = -V, b = 0, A = -V, F = V, k = -1, T = -1, q = 0, m = -V, d = 0, _ = -V, w = V, E = -1, I = -1, C = 0, S = -V, O = 0, L = -V, W = V, X = -1, H = -1, J = 0, z = -V, Et = 0, ht = -V, vt = V, Dt = -1, qs = -1, Cs = 0, on = -V, vs = 0, Tn = -V, Fn = V, Ts = -1, Fs = -1, Ss = 0, en = -V, Rs = 0, Sn = -V, Rn = V, Ls = -1, Ps = -1, $s = 0, cn = -V, Os = 0, Ln = -V, Pn = V, Ns = -1, Us = -1, Gs = 0, rn = -V, Ys = 0, $n = -V, On = V, Xs = -1, Ws = -1, Hs = 0, an = -V, Bs = 0, Nn = -V, Un = V, Vs = -1, js = -1, zs = 0;
|
|
1642
|
+
for (let R = 0; R < l; R++) {
|
|
1643
|
+
const v = R * 3, ut = $t[R], D = wt(Gt[R], Yt[R], Xt[R]);
|
|
1363
1644
|
{
|
|
1364
|
-
const
|
|
1365
|
-
(
|
|
1645
|
+
const N = Z[v], U = ot[v], j = Math.abs(N);
|
|
1646
|
+
(j < Math.abs(M) || j === Math.abs(M) && U < b) && (M = N, b = U, k = R, T = et[v], q = it[v]), G[v] > A && (A = G[v]), Y[v] < F && (F = Y[v]);
|
|
1366
1647
|
}
|
|
1367
1648
|
{
|
|
1368
|
-
const
|
|
1369
|
-
(
|
|
1649
|
+
const N = Z[v + 1], U = ot[v + 1], j = Math.abs(N);
|
|
1650
|
+
(j < Math.abs(m) || j === Math.abs(m) && U < d) && (m = N, d = U, E = R, I = et[v + 1], C = it[v + 1]), G[v + 1] > _ && (_ = G[v + 1]), Y[v + 1] < w && (w = Y[v + 1]);
|
|
1370
1651
|
}
|
|
1371
1652
|
{
|
|
1372
|
-
const
|
|
1373
|
-
(
|
|
1653
|
+
const N = Z[v + 2], U = ot[v + 2], j = Math.abs(N);
|
|
1654
|
+
(j < Math.abs(S) || j === Math.abs(S) && U < O) && (S = N, O = U, X = R, H = et[v + 2], J = it[v + 2]), G[v + 2] > L && (L = G[v + 2]), Y[v + 2] < W && (W = Y[v + 2]);
|
|
1374
1655
|
}
|
|
1375
|
-
if (
|
|
1656
|
+
if (ut > 0 && D >= 0) {
|
|
1376
1657
|
{
|
|
1377
|
-
const
|
|
1378
|
-
(
|
|
1658
|
+
const N = Z[v], U = ot[v], j = Math.abs(N);
|
|
1659
|
+
(j < Math.abs(z) || j === Math.abs(z) && U < Et) && (z = N, Et = U, Dt = R, qs = et[v], Cs = it[v]), G[v] > ht && (ht = G[v]), Y[v] < vt && (vt = Y[v]);
|
|
1379
1660
|
}
|
|
1380
1661
|
{
|
|
1381
|
-
const
|
|
1382
|
-
(
|
|
1662
|
+
const N = Z[v + 1], U = ot[v + 1], j = Math.abs(N);
|
|
1663
|
+
(j < Math.abs(on) || j === Math.abs(on) && U < vs) && (on = N, vs = U, Ts = R, Fs = et[v + 1], Ss = it[v + 1]), G[v + 1] > Tn && (Tn = G[v + 1]), Y[v + 1] < Fn && (Fn = Y[v + 1]);
|
|
1383
1664
|
}
|
|
1384
1665
|
{
|
|
1385
|
-
const
|
|
1386
|
-
(
|
|
1666
|
+
const N = Z[v + 2], U = ot[v + 2], j = Math.abs(N);
|
|
1667
|
+
(j < Math.abs(en) || j === Math.abs(en) && U < Rs) && (en = N, Rs = U, Ls = R, Ps = et[v + 2], $s = it[v + 2]), G[v + 2] > Sn && (Sn = G[v + 2]), Y[v + 2] < Rn && (Rn = Y[v + 2]);
|
|
1387
1668
|
}
|
|
1388
1669
|
}
|
|
1389
|
-
if (
|
|
1670
|
+
if (ut < 0 && D <= 0) {
|
|
1390
1671
|
{
|
|
1391
|
-
const
|
|
1392
|
-
(
|
|
1672
|
+
const N = Z[v], U = ot[v], j = Math.abs(N);
|
|
1673
|
+
(j < Math.abs(cn) || j === Math.abs(cn) && U < Os) && (cn = N, Os = U, Ns = R, Us = et[v], Gs = it[v]), G[v] > Ln && (Ln = G[v]), Y[v] < Pn && (Pn = Y[v]);
|
|
1393
1674
|
}
|
|
1394
1675
|
{
|
|
1395
|
-
const
|
|
1396
|
-
(
|
|
1676
|
+
const N = Z[v + 1], U = ot[v + 1], j = Math.abs(N);
|
|
1677
|
+
(j < Math.abs(rn) || j === Math.abs(rn) && U < Ys) && (rn = N, Ys = U, Xs = R, Ws = et[v + 1], Hs = it[v + 1]), G[v + 1] > $n && ($n = G[v + 1]), Y[v + 1] < On && (On = Y[v + 1]);
|
|
1397
1678
|
}
|
|
1398
1679
|
{
|
|
1399
|
-
const
|
|
1400
|
-
(
|
|
1680
|
+
const N = Z[v + 2], U = ot[v + 2], j = Math.abs(N);
|
|
1681
|
+
(j < Math.abs(an) || j === Math.abs(an) && U < Bs) && (an = N, Bs = U, Vs = R, js = et[v + 2], zs = it[v + 2]), G[v + 2] > Nn && (Nn = G[v + 2]), Y[v + 2] < Un && (Un = Y[v + 2]);
|
|
1401
1682
|
}
|
|
1402
1683
|
}
|
|
1403
1684
|
}
|
|
1404
|
-
const
|
|
1685
|
+
const Gn = xt(
|
|
1405
1686
|
M,
|
|
1406
|
-
v,
|
|
1407
|
-
C,
|
|
1408
1687
|
A,
|
|
1409
|
-
D,
|
|
1410
|
-
I,
|
|
1411
|
-
u,
|
|
1412
|
-
x,
|
|
1413
|
-
r
|
|
1414
|
-
), xn = lt(
|
|
1415
1688
|
F,
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
R,
|
|
1689
|
+
k,
|
|
1690
|
+
T,
|
|
1419
1691
|
q,
|
|
1420
|
-
P,
|
|
1421
|
-
u,
|
|
1422
1692
|
x,
|
|
1423
|
-
|
|
1424
|
-
|
|
1693
|
+
g,
|
|
1694
|
+
a
|
|
1695
|
+
), Yn = xt(
|
|
1696
|
+
m,
|
|
1697
|
+
_,
|
|
1698
|
+
w,
|
|
1699
|
+
E,
|
|
1700
|
+
I,
|
|
1701
|
+
C,
|
|
1702
|
+
x,
|
|
1703
|
+
g,
|
|
1704
|
+
a
|
|
1705
|
+
), Xn = xt(
|
|
1706
|
+
S,
|
|
1707
|
+
L,
|
|
1708
|
+
W,
|
|
1425
1709
|
X,
|
|
1426
|
-
V,
|
|
1427
|
-
nt,
|
|
1428
1710
|
H,
|
|
1711
|
+
J,
|
|
1712
|
+
x,
|
|
1713
|
+
g,
|
|
1714
|
+
a
|
|
1715
|
+
), jo = wt(Gn, Yn, Xn), Qs = xt(
|
|
1429
1716
|
z,
|
|
1430
1717
|
ht,
|
|
1431
|
-
|
|
1718
|
+
vt,
|
|
1719
|
+
Dt,
|
|
1720
|
+
qs,
|
|
1721
|
+
Cs,
|
|
1432
1722
|
x,
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
sn,
|
|
1723
|
+
g,
|
|
1724
|
+
a
|
|
1725
|
+
), Ks = xt(
|
|
1437
1726
|
on,
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1727
|
+
Tn,
|
|
1728
|
+
Fn,
|
|
1729
|
+
Ts,
|
|
1730
|
+
Fs,
|
|
1731
|
+
Ss,
|
|
1442
1732
|
x,
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1733
|
+
g,
|
|
1734
|
+
a
|
|
1735
|
+
), Zs = xt(
|
|
1446
1736
|
en,
|
|
1737
|
+
Sn,
|
|
1738
|
+
Rn,
|
|
1739
|
+
Ls,
|
|
1740
|
+
Ps,
|
|
1741
|
+
$s,
|
|
1742
|
+
x,
|
|
1743
|
+
g,
|
|
1744
|
+
a
|
|
1745
|
+
), ln = wt(Qs, Ks, Zs), Js = xt(
|
|
1447
1746
|
cn,
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1747
|
+
Ln,
|
|
1748
|
+
Pn,
|
|
1749
|
+
Ns,
|
|
1750
|
+
Us,
|
|
1751
|
+
Gs,
|
|
1452
1752
|
x,
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1753
|
+
g,
|
|
1754
|
+
a
|
|
1755
|
+
), to = xt(
|
|
1456
1756
|
rn,
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
x,
|
|
1463
|
-
r
|
|
1464
|
-
), Ht = Mt(ds, bs, As), ws = lt(
|
|
1465
|
-
Yt,
|
|
1466
|
-
hn,
|
|
1467
|
-
pn,
|
|
1468
|
-
as,
|
|
1469
|
-
hs,
|
|
1470
|
-
ps,
|
|
1471
|
-
u,
|
|
1472
|
-
x,
|
|
1473
|
-
r
|
|
1474
|
-
), Ds = lt(
|
|
1475
|
-
Xt,
|
|
1476
|
-
ln,
|
|
1477
|
-
fn,
|
|
1478
|
-
fs,
|
|
1479
|
-
ys,
|
|
1480
|
-
us,
|
|
1481
|
-
u,
|
|
1757
|
+
$n,
|
|
1758
|
+
On,
|
|
1759
|
+
Xs,
|
|
1760
|
+
Ws,
|
|
1761
|
+
Hs,
|
|
1482
1762
|
x,
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1763
|
+
g,
|
|
1764
|
+
a
|
|
1765
|
+
), no = xt(
|
|
1766
|
+
an,
|
|
1767
|
+
Nn,
|
|
1768
|
+
Un,
|
|
1769
|
+
Vs,
|
|
1770
|
+
js,
|
|
1771
|
+
zs,
|
|
1492
1772
|
x,
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1773
|
+
g,
|
|
1774
|
+
a
|
|
1775
|
+
), hn = wt(Js, to, no);
|
|
1776
|
+
let Mt, mt, bt, Wn = 0;
|
|
1777
|
+
if (ln >= 0 && Math.abs(ln) <= Math.abs(hn)) {
|
|
1778
|
+
Mt = Qs, mt = Ks, bt = Zs, Wn = 1;
|
|
1779
|
+
for (let R = 0; R < l; R++)
|
|
1780
|
+
if ($t[R] > 0) {
|
|
1781
|
+
const v = Gt[R], ut = Yt[R], D = Xt[R], N = wt(v, ut, D);
|
|
1782
|
+
Math.abs(N) < Math.abs(hn) && N > wt(Mt, mt, bt) && (Mt = v, mt = ut, bt = D);
|
|
1502
1783
|
}
|
|
1503
|
-
} else if (
|
|
1504
|
-
|
|
1505
|
-
for (let
|
|
1506
|
-
if (
|
|
1507
|
-
const
|
|
1508
|
-
Math.abs(
|
|
1784
|
+
} else if (hn <= 0 && Math.abs(hn) < Math.abs(ln)) {
|
|
1785
|
+
Mt = Js, mt = to, bt = no, Wn = -1;
|
|
1786
|
+
for (let R = 0; R < l; R++)
|
|
1787
|
+
if ($t[R] < 0) {
|
|
1788
|
+
const v = Gt[R], ut = Yt[R], D = Xt[R], N = wt(v, ut, D);
|
|
1789
|
+
Math.abs(N) < Math.abs(ln) && N < wt(Mt, mt, bt) && (Mt = v, mt = ut, bt = D);
|
|
1509
1790
|
}
|
|
1510
1791
|
} else {
|
|
1511
|
-
const
|
|
1512
|
-
c[
|
|
1792
|
+
const R = (u * t + y) * 3;
|
|
1793
|
+
c[R + 0] = Gn * h + 0.5, c[R + 1] = Yn * h + 0.5, c[R + 2] = Xn * h + 0.5;
|
|
1513
1794
|
continue;
|
|
1514
1795
|
}
|
|
1515
|
-
for (let
|
|
1516
|
-
if (
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1796
|
+
for (let R = 0; R < l; R++)
|
|
1797
|
+
if ($t[R] !== Wn) {
|
|
1798
|
+
const v = Gt[R], ut = Yt[R], D = Xt[R], N = wt(v, ut, D), U = wt(Mt, mt, bt);
|
|
1799
|
+
N * U >= 0 && Math.abs(N) < Math.abs(U) && (Mt = v, mt = ut, bt = D);
|
|
1519
1800
|
}
|
|
1520
|
-
Mt
|
|
1521
|
-
const
|
|
1522
|
-
c[
|
|
1801
|
+
wt(Mt, mt, bt) === jo && (Mt = Gn, mt = Yn, bt = Xn);
|
|
1802
|
+
const Hn = (u * t + y) * 3;
|
|
1803
|
+
c[Hn + 0] = Mt * h + 0.5, c[Hn + 1] = mt * h + 0.5, c[Hn + 2] = bt * h + 0.5;
|
|
1523
1804
|
}
|
|
1524
1805
|
}
|
|
1525
|
-
const
|
|
1526
|
-
function
|
|
1527
|
-
switch (
|
|
1528
|
-
case
|
|
1529
|
-
return
|
|
1530
|
-
case
|
|
1531
|
-
return (
|
|
1532
|
-
case
|
|
1533
|
-
return
|
|
1534
|
-
case
|
|
1535
|
-
return
|
|
1806
|
+
const Go = 0, ci = 1, ri = 2, ai = 3;
|
|
1807
|
+
function li(s, t) {
|
|
1808
|
+
switch (t) {
|
|
1809
|
+
case Go:
|
|
1810
|
+
return s !== 0;
|
|
1811
|
+
case ci:
|
|
1812
|
+
return (s & 1) !== 0;
|
|
1813
|
+
case ri:
|
|
1814
|
+
return s > 0;
|
|
1815
|
+
case ai:
|
|
1816
|
+
return s < 0;
|
|
1536
1817
|
}
|
|
1537
1818
|
return !1;
|
|
1538
1819
|
}
|
|
1539
|
-
class
|
|
1820
|
+
class hi {
|
|
1540
1821
|
constructor() {
|
|
1541
1822
|
this._intersections = [], this._lastIndex = 0;
|
|
1542
1823
|
}
|
|
@@ -1546,12 +1827,12 @@ class ri {
|
|
|
1546
1827
|
*
|
|
1547
1828
|
* @param intersections Unsorted crossings (ownership transferred; mutated).
|
|
1548
1829
|
*/
|
|
1549
|
-
setIntersections(
|
|
1550
|
-
if (this._intersections =
|
|
1551
|
-
|
|
1552
|
-
let
|
|
1553
|
-
for (let
|
|
1554
|
-
|
|
1830
|
+
setIntersections(t) {
|
|
1831
|
+
if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
|
|
1832
|
+
t.sort((o, e) => ft(o.x - e.x));
|
|
1833
|
+
let n = 0;
|
|
1834
|
+
for (let o = 0; o < t.length; o++)
|
|
1835
|
+
n += t[o].direction, t[o].direction = n;
|
|
1555
1836
|
}
|
|
1556
1837
|
}
|
|
1557
1838
|
/**
|
|
@@ -1560,19 +1841,19 @@ class ri {
|
|
|
1560
1841
|
* @param x Query x-coordinate.
|
|
1561
1842
|
* @returns Index into the sorted crossings, or -1 when x precedes all.
|
|
1562
1843
|
*/
|
|
1563
|
-
_moveTo(
|
|
1564
|
-
const
|
|
1565
|
-
if (
|
|
1566
|
-
let
|
|
1567
|
-
if (
|
|
1844
|
+
_moveTo(t) {
|
|
1845
|
+
const n = this._intersections.length;
|
|
1846
|
+
if (n === 0) return -1;
|
|
1847
|
+
let o = this._lastIndex;
|
|
1848
|
+
if (t < this._intersections[o].x)
|
|
1568
1849
|
do {
|
|
1569
|
-
if (
|
|
1850
|
+
if (o === 0)
|
|
1570
1851
|
return this._lastIndex = 0, -1;
|
|
1571
|
-
--
|
|
1572
|
-
} while (
|
|
1852
|
+
--o;
|
|
1853
|
+
} while (t < this._intersections[o].x);
|
|
1573
1854
|
else
|
|
1574
|
-
for (;
|
|
1575
|
-
return this._lastIndex =
|
|
1855
|
+
for (; o < n - 1 && t >= this._intersections[o + 1].x; ) ++o;
|
|
1856
|
+
return this._lastIndex = o, o;
|
|
1576
1857
|
}
|
|
1577
1858
|
/**
|
|
1578
1859
|
* Returns the accumulated winding number at x.
|
|
@@ -1580,9 +1861,9 @@ class ri {
|
|
|
1580
1861
|
* @param x Query x-coordinate.
|
|
1581
1862
|
* @returns Signed winding number.
|
|
1582
1863
|
*/
|
|
1583
|
-
sumIntersections(
|
|
1584
|
-
const
|
|
1585
|
-
return
|
|
1864
|
+
sumIntersections(t) {
|
|
1865
|
+
const n = this._moveTo(t);
|
|
1866
|
+
return n >= 0 ? this._intersections[n].direction : 0;
|
|
1586
1867
|
}
|
|
1587
1868
|
/**
|
|
1588
1869
|
* Tests whether the point at x is filled under the given fill rule.
|
|
@@ -1591,324 +1872,664 @@ class ri {
|
|
|
1591
1872
|
* @param fillRule Fill rule to apply.
|
|
1592
1873
|
* @returns True when filled.
|
|
1593
1874
|
*/
|
|
1594
|
-
filled(
|
|
1595
|
-
return
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
const
|
|
1599
|
-
function
|
|
1600
|
-
const
|
|
1601
|
-
for (const
|
|
1602
|
-
for (const
|
|
1603
|
-
const
|
|
1604
|
-
for (let c = 0; c <
|
|
1605
|
-
|
|
1875
|
+
filled(t, n) {
|
|
1876
|
+
return li(this.sumIntersections(t), n);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
const Co = [0, 0, 0], vo = [0, 0, 0];
|
|
1880
|
+
function pi(s, t, n) {
|
|
1881
|
+
const o = [];
|
|
1882
|
+
for (const e of s.contours)
|
|
1883
|
+
for (const i of e) {
|
|
1884
|
+
const r = i.scanlineIntersections(t, Co, vo);
|
|
1885
|
+
for (let c = 0; c < r; c++)
|
|
1886
|
+
o.push({ x: Co[c], direction: vo[c] });
|
|
1606
1887
|
}
|
|
1607
|
-
|
|
1608
|
-
}
|
|
1609
|
-
const
|
|
1610
|
-
function
|
|
1611
|
-
if (
|
|
1612
|
-
const c = new
|
|
1613
|
-
for (let
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
for (let
|
|
1617
|
-
const f = (
|
|
1618
|
-
|
|
1888
|
+
n.setIntersections(o);
|
|
1889
|
+
}
|
|
1890
|
+
const Ht = 2, Yo = 1, us = 1.001, fi = 1.1111111111111112, An = 0.01;
|
|
1891
|
+
function ui(s, t, n, o, e, i, r) {
|
|
1892
|
+
if (n === 0 || o === 0) return;
|
|
1893
|
+
const c = new hi(), a = new Int8Array(n * o);
|
|
1894
|
+
for (let l = 0; l < o; l++) {
|
|
1895
|
+
const h = (l + 0.5) / e - r;
|
|
1896
|
+
pi(t, h, c);
|
|
1897
|
+
for (let p = 0; p < n; p++) {
|
|
1898
|
+
const f = (p + 0.5) / e - i, u = c.filled(f, Go), y = (l * n + p) * 3, x = s[y], g = s[y + 1], M = s[y + 2], b = lt(x, g, M), A = l * n + p;
|
|
1899
|
+
b === 0.5 ? a[A] = 0 : b > 0.5 !== u ? (s[y] = 1 - x, s[y + 1] = 1 - g, s[y + 2] = 1 - M, a[A] = -1) : a[A] = 1;
|
|
1619
1900
|
}
|
|
1620
1901
|
}
|
|
1621
|
-
for (let
|
|
1622
|
-
for (let
|
|
1623
|
-
const
|
|
1624
|
-
if (
|
|
1902
|
+
for (let l = 0; l < o; l++)
|
|
1903
|
+
for (let h = 0; h < n; h++) {
|
|
1904
|
+
const p = l * n + h;
|
|
1905
|
+
if (a[p] !== 0) continue;
|
|
1625
1906
|
let f = 0;
|
|
1626
|
-
if (
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1907
|
+
if (h > 0 && (f += a[p - 1]), h < n - 1 && (f += a[p + 1]), l > 0 && (f += a[p - n]), l < o - 1 && (f += a[p + n]), f < 0) {
|
|
1908
|
+
const u = (l * n + h) * 3;
|
|
1909
|
+
s[u] = 1 - s[u], s[u + 1] = 1 - s[u + 1], s[u + 2] = 1 - s[u + 2];
|
|
1629
1910
|
}
|
|
1630
1911
|
}
|
|
1631
1912
|
}
|
|
1632
|
-
const
|
|
1633
|
-
function
|
|
1634
|
-
const
|
|
1635
|
-
|
|
1913
|
+
const ys = [0, 0];
|
|
1914
|
+
function yi(s, t, n, o, e, i, r, c) {
|
|
1915
|
+
const a = new Uint8Array(n * o);
|
|
1916
|
+
xi(a, t, n, o, e, i, r), _i(a, s, n, o, e, c), mi(a, s, n, o, c, fi), bi(a, s, n, o);
|
|
1636
1917
|
}
|
|
1637
|
-
function
|
|
1638
|
-
for (const c of
|
|
1918
|
+
function xi(s, t, n, o, e, i, r) {
|
|
1919
|
+
for (const c of t.contours) {
|
|
1639
1920
|
if (c.length === 0) continue;
|
|
1640
|
-
let
|
|
1641
|
-
for (const
|
|
1642
|
-
const
|
|
1643
|
-
if (!(
|
|
1644
|
-
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1921
|
+
let a = c[c.length - 1];
|
|
1922
|
+
for (const l of c) {
|
|
1923
|
+
const h = a.color & l.color;
|
|
1924
|
+
if (!(h & h - 1)) {
|
|
1925
|
+
l.point(0, ys);
|
|
1926
|
+
const p = e * (ys[0] + i), f = e * (ys[1] + r), u = Math.floor(p - 0.5) | 0, y = Math.floor(f - 0.5) | 0, x = u + 1, g = y + 1;
|
|
1927
|
+
u < n && y < o && x >= 0 && g >= 0 && (u >= 0 && y >= 0 && (s[y * n + u] |= Ht), x < n && y >= 0 && (s[y * n + x] |= Ht), u >= 0 && g < o && (s[g * n + u] |= Ht), x < n && g < o && (s[g * n + x] |= Ht));
|
|
1647
1928
|
}
|
|
1648
|
-
|
|
1929
|
+
a = l;
|
|
1649
1930
|
}
|
|
1650
1931
|
}
|
|
1651
1932
|
}
|
|
1652
|
-
function
|
|
1653
|
-
let
|
|
1654
|
-
for (let
|
|
1655
|
-
const
|
|
1933
|
+
function yn(s, t, n) {
|
|
1934
|
+
let o = 0;
|
|
1935
|
+
for (let e = 0; e < 3; e++) {
|
|
1936
|
+
const i = s[t + e], r = s[n + e], c = i - r;
|
|
1656
1937
|
if (c === 0) continue;
|
|
1657
|
-
const
|
|
1658
|
-
if (
|
|
1659
|
-
const
|
|
1660
|
-
|
|
1938
|
+
const a = (i - 0.5) / c;
|
|
1939
|
+
if (a > 0 && a < 1) {
|
|
1940
|
+
const l = 1 - a, h = l * s[t] + a * s[n], p = l * s[t + 1] + a * s[n + 1], f = l * s[t + 2] + a * s[n + 2], u = e === 0 ? h : e === 1 ? p : f;
|
|
1941
|
+
lt(h, p, f) === u && (o |= e === 0 ? qn : e === 1 ? Cn : vn);
|
|
1661
1942
|
}
|
|
1662
1943
|
}
|
|
1663
|
-
return
|
|
1664
|
-
}
|
|
1665
|
-
function wt(e, n, t, s, i, o) {
|
|
1666
|
-
(o & Jt && t[s] !== i || o & tn && t[s + 1] !== i || o & nn && t[s + 2] !== i) && (e[n] |= mt);
|
|
1944
|
+
return o;
|
|
1667
1945
|
}
|
|
1668
|
-
function
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1946
|
+
function Ft(s, t, n, o, e, i) {
|
|
1947
|
+
(i & qn && n[o] !== e || i & Cn && n[o + 1] !== e || i & vn && n[o + 2] !== e) && (s[t] |= Ht);
|
|
1948
|
+
}
|
|
1949
|
+
function _i(s, t, n, o, e, i) {
|
|
1950
|
+
const r = us / i, c = us / i, a = us * Math.SQRT2 / i;
|
|
1951
|
+
for (let l = 0; l < o; l++)
|
|
1952
|
+
for (let h = 0; h < n - 1; h++) {
|
|
1953
|
+
const p = (l * n + h) * 3, f = p + 3, u = lt(t[p], t[p + 1], t[p + 2]), y = lt(t[f], t[f + 1], t[f + 2]);
|
|
1954
|
+
if (Math.abs(u - 0.5) + Math.abs(y - 0.5) < r) {
|
|
1955
|
+
const x = yn(t, p, f);
|
|
1956
|
+
Ft(s, l * n + h, t, p, u, x), Ft(s, l * n + h + 1, t, f, y, x);
|
|
1676
1957
|
}
|
|
1677
1958
|
}
|
|
1678
|
-
for (let
|
|
1679
|
-
for (let
|
|
1680
|
-
const
|
|
1681
|
-
if (Math.abs(
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1959
|
+
for (let l = 0; l < o - 1; l++)
|
|
1960
|
+
for (let h = 0; h < n; h++) {
|
|
1961
|
+
const p = (l * n + h) * 3, f = ((l + 1) * n + h) * 3, u = lt(t[p], t[p + 1], t[p + 2]), y = lt(t[f], t[f + 1], t[f + 2]);
|
|
1962
|
+
if (Math.abs(u - 0.5) + Math.abs(y - 0.5) < c) {
|
|
1963
|
+
const x = yn(t, p, f);
|
|
1964
|
+
Ft(s, l * n + h, t, p, u, x), Ft(s, (l + 1) * n + h, t, f, y, x);
|
|
1684
1965
|
}
|
|
1685
1966
|
}
|
|
1686
|
-
for (let
|
|
1687
|
-
for (let
|
|
1688
|
-
const
|
|
1689
|
-
if (Math.abs(
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1967
|
+
for (let l = 0; l < o - 1; l++)
|
|
1968
|
+
for (let h = 0; h < n - 1; h++) {
|
|
1969
|
+
const p = (l * n + h) * 3, f = (l * n + h + 1) * 3, u = ((l + 1) * n + h) * 3, y = ((l + 1) * n + h + 1) * 3, x = lt(t[p], t[p + 1], t[p + 2]), g = lt(t[f], t[f + 1], t[f + 2]), M = lt(t[u], t[u + 1], t[u + 2]), b = lt(t[y], t[y + 1], t[y + 2]);
|
|
1970
|
+
if (Math.abs(x - 0.5) + Math.abs(b - 0.5) < a) {
|
|
1971
|
+
const A = yn(t, p, y);
|
|
1972
|
+
Ft(s, l * n + h, t, p, x, A), Ft(s, (l + 1) * n + h + 1, t, y, b, A);
|
|
1692
1973
|
}
|
|
1693
|
-
if (Math.abs(
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1974
|
+
if (Math.abs(g - 0.5) + Math.abs(M - 0.5) < a) {
|
|
1975
|
+
const A = yn(t, f, u);
|
|
1976
|
+
Ft(s, l * n + h + 1, t, f, g, A), Ft(s, (l + 1) * n + h, t, u, M, A);
|
|
1696
1977
|
}
|
|
1697
1978
|
}
|
|
1698
1979
|
}
|
|
1699
|
-
function
|
|
1700
|
-
const
|
|
1701
|
-
return
|
|
1980
|
+
function gi(s, t, n) {
|
|
1981
|
+
const o = t < s ? t : s, e = s < t ? t : s, i = n < e ? n : e;
|
|
1982
|
+
return o < i ? i : o;
|
|
1702
1983
|
}
|
|
1703
|
-
function
|
|
1704
|
-
return
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1984
|
+
function di(s, t, n, o) {
|
|
1985
|
+
return lt(
|
|
1986
|
+
s[t] + o * (s[n] - s[t]),
|
|
1987
|
+
s[t + 1] + o * (s[n + 1] - s[t + 1]),
|
|
1988
|
+
s[t + 2] + o * (s[n + 2] - s[t + 2])
|
|
1708
1989
|
);
|
|
1709
1990
|
}
|
|
1710
|
-
function
|
|
1711
|
-
return
|
|
1712
|
-
Math.fround(
|
|
1713
|
-
Math.fround(
|
|
1714
|
-
Math.fround(
|
|
1991
|
+
function ks(s, t, n, o) {
|
|
1992
|
+
return gi(
|
|
1993
|
+
Math.fround(o * (o * n[0] + t[0]) + s[0]),
|
|
1994
|
+
Math.fround(o * (o * n[1] + t[1]) + s[1]),
|
|
1995
|
+
Math.fround(o * (o * n[2] + t[2]) + s[2])
|
|
1715
1996
|
);
|
|
1716
1997
|
}
|
|
1717
|
-
const
|
|
1718
|
-
function
|
|
1719
|
-
if (
|
|
1720
|
-
const
|
|
1721
|
-
return
|
|
1998
|
+
const Nt = [0, 0, 0], It = [0, 0, 0], xs = [0, 0, 0], _t = [0, 0, 0], To = 1, Xo = 2;
|
|
1999
|
+
function Ds(s, t, n, o, e, i, r, c) {
|
|
2000
|
+
if (o > 0.5 && e > 0.5 && i <= 0.5 || o < 0.5 && e < 0.5 && i >= 0.5 || !c && Mi(o, e, i) !== i) {
|
|
2001
|
+
const a = (n - s) * r, l = (t - n) * r;
|
|
2002
|
+
return i >= o - a && i <= o + a && i >= e - l && i <= e + l ? To : To | Xo;
|
|
1722
2003
|
}
|
|
1723
2004
|
return 0;
|
|
1724
2005
|
}
|
|
1725
|
-
function
|
|
1726
|
-
return (
|
|
2006
|
+
function Wo(s) {
|
|
2007
|
+
return (s & Xo) !== 0;
|
|
1727
2008
|
}
|
|
1728
|
-
function
|
|
1729
|
-
return Math.max(Math.min(
|
|
2009
|
+
function Mi(s, t, n) {
|
|
2010
|
+
return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
|
|
1730
2011
|
}
|
|
1731
|
-
function
|
|
1732
|
-
const
|
|
1733
|
-
if (Math.abs(
|
|
2012
|
+
function xn(s, t, n, o, e, i) {
|
|
2013
|
+
const r = lt(s[n], s[n + 1], s[n + 2]);
|
|
2014
|
+
if (Math.abs(o - 0.5) < Math.abs(r - 0.5)) return !1;
|
|
1734
2015
|
for (let c = 0; c < 3; c++) {
|
|
1735
|
-
const
|
|
1736
|
-
if (
|
|
1737
|
-
const
|
|
1738
|
-
if (
|
|
1739
|
-
const f =
|
|
1740
|
-
if (
|
|
2016
|
+
const a = s[t + c] - s[t + (c + 1) % 3], l = s[n + c] - s[n + (c + 1) % 3], h = a - l;
|
|
2017
|
+
if (h === 0) continue;
|
|
2018
|
+
const p = a / h;
|
|
2019
|
+
if (p > An && p < 1 - An) {
|
|
2020
|
+
const f = di(s, t, n, p), u = Ds(0, 1, p, o, r, f, e, i);
|
|
2021
|
+
if (Wo(u)) return !0;
|
|
1741
2022
|
}
|
|
1742
2023
|
}
|
|
1743
2024
|
return !1;
|
|
1744
2025
|
}
|
|
1745
|
-
function
|
|
1746
|
-
if (!(
|
|
1747
|
-
const
|
|
1748
|
-
|
|
1749
|
-
const
|
|
1750
|
-
|
|
1751
|
-
const f =
|
|
1752
|
-
return
|
|
1753
|
-
}
|
|
1754
|
-
function
|
|
1755
|
-
if (!(
|
|
1756
|
-
|
|
1757
|
-
const
|
|
1758
|
-
let
|
|
1759
|
-
return
|
|
1760
|
-
}
|
|
1761
|
-
function
|
|
1762
|
-
const
|
|
1763
|
-
Math.fround(
|
|
1764
|
-
),
|
|
1765
|
-
if (
|
|
2026
|
+
function Fo(s, t, n, o, e, i, r, c, a) {
|
|
2027
|
+
if (!(a > 0 && a < 1)) return 0;
|
|
2028
|
+
const l = a > r ? 0 : a, h = a > r ? a : 1;
|
|
2029
|
+
_t[0] = s[t], _t[1] = s[t + 1], _t[2] = s[t + 2];
|
|
2030
|
+
const p = a > r ? n : ks(_t, Nt, It, a);
|
|
2031
|
+
_t[0] = s[t], _t[1] = s[t + 1], _t[2] = s[t + 2];
|
|
2032
|
+
const f = a > r ? ks(_t, Nt, It, a) : o;
|
|
2033
|
+
return Ds(l, h, r, p, f, c, e, i);
|
|
2034
|
+
}
|
|
2035
|
+
function _n(s, t, n, o, e, i, r, c, a) {
|
|
2036
|
+
if (!(r > An && r < 1 - An)) return !1;
|
|
2037
|
+
_t[0] = s[t], _t[1] = s[t + 1], _t[2] = s[t + 2];
|
|
2038
|
+
const l = ks(_t, Nt, It, r);
|
|
2039
|
+
let h = Ds(0, 1, r, n, o, l, e, i);
|
|
2040
|
+
return h |= Fo(s, t, n, o, e, i, r, l, c), h |= Fo(s, t, n, o, e, i, r, l, a), Wo(h);
|
|
2041
|
+
}
|
|
2042
|
+
function _s(s, t, n, o, e, i, r, c, a, l, h, p, f) {
|
|
2043
|
+
const u = Math.fround(s[t + l] - s[t + h]), y = Math.fround(
|
|
2044
|
+
Math.fround(s[n + l] - s[n + h]) + Math.fround(s[o + l] - s[o + h])
|
|
2045
|
+
), x = Math.fround(s[e + l] - s[e + h]), g = Math.fround(Math.fround(x - y) + u), M = Math.fround(Math.fround(y - u) - u), b = u;
|
|
2046
|
+
if (g === 0 || Math.abs(M) > 1e12 * Math.abs(g)) {
|
|
1766
2047
|
if (M !== 0) {
|
|
1767
|
-
const
|
|
1768
|
-
if (
|
|
2048
|
+
const F = -b / M;
|
|
2049
|
+
if (_n(s, t, i, r, c, a, F, p, f)) return !0;
|
|
1769
2050
|
}
|
|
1770
2051
|
return !1;
|
|
1771
2052
|
}
|
|
1772
|
-
const
|
|
1773
|
-
if (
|
|
1774
|
-
const
|
|
1775
|
-
if (
|
|
1776
|
-
const
|
|
1777
|
-
if (
|
|
1778
|
-
} else if (
|
|
1779
|
-
const
|
|
1780
|
-
if (
|
|
2053
|
+
const A = M * M - 4 * g * b;
|
|
2054
|
+
if (A > 0) {
|
|
2055
|
+
const F = Math.sqrt(A), k = (-M + F) / (2 * g);
|
|
2056
|
+
if (_n(s, t, i, r, c, a, k, p, f)) return !0;
|
|
2057
|
+
const T = (-M - F) / (2 * g);
|
|
2058
|
+
if (_n(s, t, i, r, c, a, T, p, f)) return !0;
|
|
2059
|
+
} else if (A === 0) {
|
|
2060
|
+
const F = -M / (2 * g);
|
|
2061
|
+
if (_n(s, t, i, r, c, a, F, p, f)) return !0;
|
|
1781
2062
|
}
|
|
1782
2063
|
return !1;
|
|
1783
2064
|
}
|
|
1784
|
-
function
|
|
1785
|
-
const
|
|
1786
|
-
if (Math.abs(
|
|
2065
|
+
function gn(s, t, n, o, e, i, r, c) {
|
|
2066
|
+
const a = lt(s[e], s[e + 1], s[e + 2]);
|
|
2067
|
+
if (Math.abs(i - 0.5) < Math.abs(a - 0.5)) return !1;
|
|
1787
2068
|
for (let f = 0; f < 3; f++)
|
|
1788
|
-
|
|
1789
|
-
Math.fround(
|
|
1790
|
-
),
|
|
1791
|
-
const
|
|
1792
|
-
return !!(
|
|
1793
|
-
e,
|
|
1794
|
-
n,
|
|
1795
|
-
t,
|
|
2069
|
+
xs[f] = Math.fround(
|
|
2070
|
+
Math.fround(s[t + f] - s[n + f]) - s[o + f]
|
|
2071
|
+
), Nt[f] = Math.fround(-s[t + f] - xs[f]), It[f] = Math.fround(s[e + f] + xs[f]);
|
|
2072
|
+
const l = It[0] !== 0 ? -0.5 * Nt[0] / It[0] : -1, h = It[1] !== 0 ? -0.5 * Nt[1] / It[1] : -1, p = It[2] !== 0 ? -0.5 * Nt[2] / It[2] : -1;
|
|
2073
|
+
return !!(_s(
|
|
1796
2074
|
s,
|
|
1797
|
-
|
|
2075
|
+
t,
|
|
2076
|
+
n,
|
|
1798
2077
|
o,
|
|
2078
|
+
e,
|
|
2079
|
+
i,
|
|
2080
|
+
a,
|
|
1799
2081
|
r,
|
|
1800
|
-
p,
|
|
1801
2082
|
c,
|
|
1802
2083
|
0,
|
|
1803
2084
|
1,
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
) ||
|
|
1807
|
-
e,
|
|
1808
|
-
n,
|
|
1809
|
-
t,
|
|
2085
|
+
l,
|
|
2086
|
+
h
|
|
2087
|
+
) || _s(
|
|
1810
2088
|
s,
|
|
1811
|
-
|
|
2089
|
+
t,
|
|
2090
|
+
n,
|
|
1812
2091
|
o,
|
|
2092
|
+
e,
|
|
2093
|
+
i,
|
|
2094
|
+
a,
|
|
1813
2095
|
r,
|
|
1814
|
-
p,
|
|
1815
2096
|
c,
|
|
1816
2097
|
1,
|
|
1817
2098
|
2,
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
) ||
|
|
1821
|
-
e,
|
|
1822
|
-
n,
|
|
1823
|
-
t,
|
|
2099
|
+
h,
|
|
2100
|
+
p
|
|
2101
|
+
) || _s(
|
|
1824
2102
|
s,
|
|
1825
|
-
|
|
2103
|
+
t,
|
|
2104
|
+
n,
|
|
1826
2105
|
o,
|
|
2106
|
+
e,
|
|
2107
|
+
i,
|
|
2108
|
+
a,
|
|
1827
2109
|
r,
|
|
1828
|
-
p,
|
|
1829
2110
|
c,
|
|
1830
2111
|
2,
|
|
1831
2112
|
0,
|
|
1832
|
-
|
|
1833
|
-
|
|
2113
|
+
p,
|
|
2114
|
+
l
|
|
1834
2115
|
));
|
|
1835
2116
|
}
|
|
1836
|
-
function
|
|
1837
|
-
const
|
|
1838
|
-
for (let
|
|
1839
|
-
for (let
|
|
1840
|
-
const
|
|
1841
|
-
let
|
|
1842
|
-
if (
|
|
1843
|
-
const
|
|
1844
|
-
|
|
2117
|
+
function mi(s, t, n, o, e, i) {
|
|
2118
|
+
const r = i / e, c = i / e, a = i * Math.SQRT2 / e;
|
|
2119
|
+
for (let l = 0; l < o; l++)
|
|
2120
|
+
for (let h = 0; h < n; h++) {
|
|
2121
|
+
const p = l * n + h, f = p * 3, u = lt(t[f], t[f + 1], t[f + 2]), y = (s[p] & Ht) !== 0, x = h > 0, g = h < n - 1, M = l > 0, b = l < o - 1, A = x ? (p - 1) * 3 : -1, F = g ? (p + 1) * 3 : -1, k = M ? (p - n) * 3 : -1, T = b ? (p + n) * 3 : -1;
|
|
2122
|
+
let q = !1;
|
|
2123
|
+
if (x && xn(t, f, A, u, r, y) && (q = !0), !q && M && xn(t, f, k, u, c, y) && (q = !0), !q && g && xn(t, f, F, u, r, y) && (q = !0), !q && b && xn(t, f, T, u, c, y) && (q = !0), !q && x && M) {
|
|
2124
|
+
const m = (p - n - 1) * 3;
|
|
2125
|
+
gn(t, f, A, k, m, u, a, y) && (q = !0);
|
|
1845
2126
|
}
|
|
1846
|
-
if (!
|
|
1847
|
-
const
|
|
1848
|
-
|
|
2127
|
+
if (!q && g && M) {
|
|
2128
|
+
const m = (p - n + 1) * 3;
|
|
2129
|
+
gn(t, f, F, k, m, u, a, y) && (q = !0);
|
|
1849
2130
|
}
|
|
1850
|
-
if (!
|
|
1851
|
-
const
|
|
1852
|
-
|
|
2131
|
+
if (!q && x && b) {
|
|
2132
|
+
const m = (p + n - 1) * 3;
|
|
2133
|
+
gn(t, f, A, T, m, u, a, y) && (q = !0);
|
|
1853
2134
|
}
|
|
1854
|
-
if (!
|
|
1855
|
-
const
|
|
1856
|
-
|
|
2135
|
+
if (!q && g && b) {
|
|
2136
|
+
const m = (p + n + 1) * 3;
|
|
2137
|
+
gn(t, f, F, T, m, u, a, y) && (q = !0);
|
|
1857
2138
|
}
|
|
1858
|
-
|
|
2139
|
+
q && (s[p] |= Yo);
|
|
1859
2140
|
}
|
|
1860
2141
|
}
|
|
1861
|
-
function
|
|
1862
|
-
const
|
|
1863
|
-
for (let
|
|
1864
|
-
if (
|
|
1865
|
-
const
|
|
1866
|
-
|
|
2142
|
+
function bi(s, t, n, o) {
|
|
2143
|
+
const e = n * o;
|
|
2144
|
+
for (let i = 0; i < e; i++)
|
|
2145
|
+
if (s[i] & Yo) {
|
|
2146
|
+
const r = i * 3, c = lt(t[r], t[r + 1], t[r + 2]);
|
|
2147
|
+
t[r] = c, t[r + 1] = c, t[r + 2] = c;
|
|
1867
2148
|
}
|
|
1868
2149
|
}
|
|
1869
|
-
function
|
|
1870
|
-
return Math.max(Math.min(
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
2150
|
+
function lt(s, t, n) {
|
|
2151
|
+
return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
|
|
2152
|
+
}
|
|
2153
|
+
const wi = 3, Ai = 0n, So = 16;
|
|
2154
|
+
function ki(s, t, n, o = !0) {
|
|
2155
|
+
if (o && Be(s), s.contours.length === 0) return null;
|
|
2156
|
+
const e = kn(s), i = t, r = n, c = Math.max(1, Math.ceil((e.maxX - e.minX) * i)) + 2 * r, a = Math.max(1, Math.ceil((e.maxY - e.minY) * i)) + 2 * r, l = r / i - e.minX, h = r / i - e.minY;
|
|
2157
|
+
Re(s), si(s, wi, Ai);
|
|
2158
|
+
const p = new Float32Array(c * a * 3);
|
|
2159
|
+
return ii(s, c, a, i, l, h, r, p), ui(p, s, c, a, i, l, h), yi(p, s, c, a, i, l, h, r), {
|
|
2160
|
+
msdf: p,
|
|
2161
|
+
w: c,
|
|
2162
|
+
h: a,
|
|
2163
|
+
planeLeft: -l,
|
|
2164
|
+
planeBottom: -h,
|
|
2165
|
+
planeRight: c / i - l,
|
|
2166
|
+
planeTop: a / i - h
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
const gs = [0, 0];
|
|
2170
|
+
function kn(s) {
|
|
2171
|
+
let t = 1 / 0, n = 1 / 0, o = -1 / 0, e = -1 / 0;
|
|
2172
|
+
for (const i of s.contours)
|
|
2173
|
+
for (const r of i)
|
|
2174
|
+
for (let c = 0; c <= So; c++) {
|
|
2175
|
+
r.point(c / So, gs);
|
|
2176
|
+
const a = gs[0], l = gs[1];
|
|
2177
|
+
a < t && (t = a), l < n && (n = l), a > o && (o = a), l > e && (e = l);
|
|
2178
|
+
}
|
|
2179
|
+
return { minX: t, minY: n, maxX: o, maxY: e };
|
|
2180
|
+
}
|
|
2181
|
+
function Q(s, t) {
|
|
2182
|
+
var n;
|
|
2183
|
+
return (n = new RegExp(`\\s${t}\\s*=\\s*(["'])([\\s\\S]*?)\\1`).exec(s)) == null ? void 0 : n[2];
|
|
2184
|
+
}
|
|
2185
|
+
function In(s, t, n) {
|
|
2186
|
+
const o = new RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`, "g"), e = (c) => {
|
|
2187
|
+
var a, l;
|
|
2188
|
+
return (l = (a = [...c.matchAll(o)].pop()) == null ? void 0 : a[1]) == null ? void 0 : l.trim();
|
|
2189
|
+
}, i = Q(s, "class");
|
|
2190
|
+
let r = "";
|
|
2191
|
+
if (i && n) {
|
|
2192
|
+
const c = new Set(i.split(/\s+/));
|
|
2193
|
+
r = n.filter(([a]) => c.has(a)).map(([, a]) => a).join(";");
|
|
2194
|
+
}
|
|
2195
|
+
return e(Q(s, "style") ?? "") ?? e(r) ?? Q(s, t);
|
|
2196
|
+
}
|
|
2197
|
+
function En(s, t) {
|
|
2198
|
+
return s === void 0 ? t : parseFloat(s) / (s.trim().endsWith("%") ? 100 : 1);
|
|
2199
|
+
}
|
|
2200
|
+
function Ot(s, t) {
|
|
2201
|
+
return s === void 0 ? 0 : parseFloat(s) * (s.trim().endsWith("%") ? t / 100 : 1);
|
|
2202
|
+
}
|
|
2203
|
+
function Fi(s) {
|
|
2204
|
+
const { layers: t, width: n } = Ii(s);
|
|
2205
|
+
return { shape: { contours: t.flatMap((e) => e.shape.contours), inverseYAxis: !1 }, width: n };
|
|
2206
|
+
}
|
|
2207
|
+
function Ii(s) {
|
|
2208
|
+
var k, T;
|
|
2209
|
+
s = s.replace(/<!--[\s\S]*?-->/g, "");
|
|
2210
|
+
const t = ((k = /<svg\b[^>]*>/.exec(s)) == null ? void 0 : k[0]) ?? "", n = (Q(t, "viewBox") ?? `0 0 ${Q(t, "width")} ${Q(t, "height")}`).trim().split(/[\s,]+/).map(parseFloat), [o = 0, e = 0, i = NaN, r = NaN] = n;
|
|
2211
|
+
if (!(r > 0)) throw new Error("parseSvg: needs a viewBox or width/height");
|
|
2212
|
+
const c = [i, r], a = [r, 0, 0, -r, o, e + r], l = [1, 0, 0, -1, -o, e + r], h = i / r, p = [];
|
|
2213
|
+
i > 0 && Dn(`M${o} ${e}h${i}v${r}h${-i}z`, l, p), dn({ contours: p }, r);
|
|
2214
|
+
const f = /* @__PURE__ */ new Map(), u = /<(linear|radial)Gradient\b([^>]*?)(?:\/>|>([\s\S]*?)<\/\1Gradient>)/g;
|
|
2215
|
+
for (const [, q = "", m = "", d = ""] of s.matchAll(u))
|
|
2216
|
+
f.set(Q(m, "id") ?? "", [q, m, d]);
|
|
2217
|
+
const y = /* @__PURE__ */ new Map();
|
|
2218
|
+
for (const [, q = "", m = ""] of s.matchAll(
|
|
2219
|
+
/<clipPath\b([^>]*?)(?:\/>|>([\s\S]*?)<\/clipPath>)/g
|
|
2220
|
+
))
|
|
2221
|
+
y.set(Q(q, "id") ?? "", [q, m]);
|
|
2222
|
+
const x = /* @__PURE__ */ new Map();
|
|
2223
|
+
for (const [, q = "", m = ""] of s.matchAll(Ho)) {
|
|
2224
|
+
const d = Q(m, "id");
|
|
2225
|
+
d !== void 0 && x.set(d, [q, m]);
|
|
2226
|
+
}
|
|
2227
|
+
const g = [];
|
|
2228
|
+
for (const [, q = ""] of s.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/g))
|
|
2229
|
+
for (const [, m = "", d = ""] of q.matchAll(/([^{}]+)\{([^}]*)\}/g))
|
|
2230
|
+
for (const _ of m.split(",")) {
|
|
2231
|
+
const w = (T = /^\s*\.([\w-]+)\s*$/.exec(_)) == null ? void 0 : T[1];
|
|
2232
|
+
w && g.push([w, d]);
|
|
2233
|
+
}
|
|
2234
|
+
const M = [], b = [], A = [
|
|
2235
|
+
{
|
|
2236
|
+
m: [1, 0, 0, 1, 0, 0],
|
|
2237
|
+
fill: "black",
|
|
2238
|
+
rule: "nonzero",
|
|
2239
|
+
fillOpacity: 1,
|
|
2240
|
+
opacity: 1,
|
|
2241
|
+
clips: [],
|
|
2242
|
+
// every clip region on the way here, each in shape space
|
|
2243
|
+
group: -1
|
|
2244
|
+
// innermost container with opacity < 1, in `groups`
|
|
2245
|
+
}
|
|
2246
|
+
];
|
|
2247
|
+
let F = 0;
|
|
2248
|
+
for (const [, q, m = "", d = "", _] of s.matchAll(
|
|
2249
|
+
/<(\/?)([\w:-]+)([^>]*?)(\/?)>/g
|
|
2250
|
+
)) {
|
|
2251
|
+
if (F > 0 || /^(defs|clipPath|mask|symbol|pattern|marker|style)$/.test(m)) {
|
|
2252
|
+
q ? F-- : _ || F++;
|
|
2253
|
+
continue;
|
|
2254
|
+
}
|
|
2255
|
+
if (q) {
|
|
2256
|
+
A.pop();
|
|
2257
|
+
continue;
|
|
2258
|
+
}
|
|
2259
|
+
const w = A[A.length - 1], E = (ht) => In(d, ht, g), I = En(E("opacity"), 1), C = Bo(m, d, c), S = {
|
|
2260
|
+
m: dt(w.m, sn(Q(d, "transform") ?? "")),
|
|
2261
|
+
fill: E("fill") ?? w.fill,
|
|
2262
|
+
rule: E("fill-rule") ?? w.rule,
|
|
2263
|
+
fillOpacity: En(E("fill-opacity"), w.fillOpacity),
|
|
2264
|
+
opacity: w.opacity * I,
|
|
2265
|
+
clips: w.clips,
|
|
2266
|
+
group: w.group
|
|
2267
|
+
};
|
|
2268
|
+
C === void 0 && I < 1 && !_ && (S.group = b.push({ members: [], parent: w.group, translucent: !1 }) - 1);
|
|
2269
|
+
const O = y.get(Ro(E("clip-path")));
|
|
2270
|
+
if (O && Q(O[0], "clipPathUnits") !== "objectBoundingBox" && (S.clips = [...w.clips, Ei(O, x, g, dt(l, S.m), c)]), _ || A.push(S), C === void 0 || S.fill === "none") continue;
|
|
2271
|
+
const L = [];
|
|
2272
|
+
Dn(C, dt(l, S.m), L), S.rule === "evenodd" && No(L);
|
|
2273
|
+
const W = { contours: L, inverseYAxis: !1 };
|
|
2274
|
+
dn(W, r);
|
|
2275
|
+
const X = f.get(Ro(S.fill)), H = dt(Vo(S.m), a), J = X ? Di(X, f, g, H, C, c) : null;
|
|
2276
|
+
for (const ht of S.clips) ko(W, ht);
|
|
2277
|
+
const z = kn(W);
|
|
2278
|
+
if (!(z.maxX <= 0 || z.minX >= h || z.maxY <= 0 || z.minY >= 1 || ((z.minX < 0 || z.minY < 0 || z.maxX > h || z.maxY > 1) && p.length > 0 && ko(W, [p]), W.contours.length === 0))) {
|
|
2279
|
+
if (S.group >= 0) {
|
|
2280
|
+
const ht = b[S.group];
|
|
2281
|
+
ht.members.push(M.length);
|
|
2282
|
+
const vt = J ? J.stops.some((Dt) => Dt.opacity < 1) : !1;
|
|
2283
|
+
(I < 1 || S.fillOpacity < 1 || vt) && (ht.translucent = !0);
|
|
2284
|
+
for (let Dt = ht.parent; Dt >= 0; Dt = b[Dt].parent) b[Dt].translucent = !0;
|
|
2285
|
+
}
|
|
2286
|
+
M.push({
|
|
2287
|
+
shape: W,
|
|
2288
|
+
color: S.fill,
|
|
2289
|
+
opacity: S.opacity * S.fillOpacity,
|
|
2290
|
+
gradient: J
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
for (const q of b) {
|
|
2295
|
+
if (q.translucent || q.members.length < 2) continue;
|
|
2296
|
+
const m = q.members.map((d) => kn(M[d].shape));
|
|
2297
|
+
for (let d = 0; d < q.members.length - 1; d++) {
|
|
2298
|
+
const _ = m[d], w = [];
|
|
2299
|
+
for (let E = d + 1; E < q.members.length; E++) {
|
|
2300
|
+
const I = m[E];
|
|
2301
|
+
I.minX < _.maxX && _.minX < I.maxX && I.minY < _.maxY && _.minY < I.maxY && w.push(M[q.members[E]].shape.contours);
|
|
2302
|
+
}
|
|
2303
|
+
Ve(M[q.members[d]].shape, w);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
return { layers: M.filter((q) => q.shape.contours.length > 0), width: i / r };
|
|
2307
|
+
}
|
|
2308
|
+
const Ho = /<([\w:-]+)\b([^>]*?)\/?>/g;
|
|
2309
|
+
function Ro(s) {
|
|
2310
|
+
var t;
|
|
2311
|
+
return ((t = /url\(\s*['"]?#([^)'"\s]+)/.exec(s ?? "")) == null ? void 0 : t[1]) ?? "";
|
|
2312
|
+
}
|
|
2313
|
+
function Ei([s = "", t = ""], n, o, e, i) {
|
|
2314
|
+
var h;
|
|
2315
|
+
const [r = 0, c = 1] = i, a = [], l = dt(e, sn(Q(s, "transform") ?? ""));
|
|
2316
|
+
for (const [, p = "", f = ""] of t.matchAll(Ho)) {
|
|
2317
|
+
let u = [p, f], y = dt(l, sn(Q(f, "transform") ?? ""));
|
|
2318
|
+
if (p === "use") {
|
|
2319
|
+
const b = n.get(((h = Q(f, "(?:xlink:)?href")) == null ? void 0 : h.slice(1)) ?? "");
|
|
2320
|
+
if (!b) continue;
|
|
2321
|
+
y = dt(y, [1, 0, 0, 1, Ot(Q(f, "x"), r), Ot(Q(f, "y"), c)]), y = dt(y, sn(Q(b[1], "transform") ?? "")), u = b;
|
|
2322
|
+
}
|
|
2323
|
+
const x = Bo(u[0], u[1], i);
|
|
2324
|
+
if (x === void 0) continue;
|
|
2325
|
+
const g = [];
|
|
2326
|
+
Dn(x, y, g), [u[1], f, s].map((b) => In(b, "clip-rule", o)).find(Boolean) === "evenodd" && No(g), dn({ contours: g }, c), a.push(g);
|
|
2327
|
+
}
|
|
2328
|
+
return a;
|
|
2329
|
+
}
|
|
2330
|
+
function Bo(s, t, [n = 0, o = 0]) {
|
|
2331
|
+
const e = (f, u) => Ot(Q(t, f), u), [i, r, c, a] = [e("x", n), e("y", o), e("width", n), e("height", o)], [l, h, p] = [e("cx", n), e("cy", o), Math.hypot(n, o) / Math.SQRT2];
|
|
2332
|
+
switch (s) {
|
|
2333
|
+
case "path":
|
|
2334
|
+
return Q(t, "d") ?? "";
|
|
2335
|
+
case "polygon":
|
|
2336
|
+
case "polyline":
|
|
2337
|
+
return `M${Q(t, "points") ?? "0 0"}`;
|
|
2338
|
+
case "circle":
|
|
2339
|
+
case "ellipse": {
|
|
2340
|
+
const [f, u] = s === "circle" ? [e("r", p), e("r", p)] : [e("rx", n), e("ry", o)], y = `A${f} ${u} 0 1 0`;
|
|
2341
|
+
return `M${l - f} ${h}${y} ${l + f} ${h}${y} ${l - f} ${h}Z`;
|
|
2342
|
+
}
|
|
2343
|
+
case "rect": {
|
|
2344
|
+
const [f, u] = [Q(t, "rx"), Q(t, "ry")], y = Math.min(f === void 0 ? Ot(u, o) : Ot(f, n), c / 2), x = Math.min(u === void 0 ? Ot(f, n) : Ot(u, o), a / 2), g = `A${y} ${x} 0 0 1`;
|
|
2345
|
+
return `M${i + y} ${r}H${i + c - y}${g} ${i + c} ${r + x}V${r + a - x}${g} ${i + c - y} ${r + a}H${i + y}${g} ${i} ${r + a - x}V${r + x}${g} ${i + y} ${r}Z`;
|
|
2346
|
+
}
|
|
2347
|
+
default:
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
function Di(s, t, n, o, e, [i = 0, r = 0]) {
|
|
2352
|
+
var d;
|
|
2353
|
+
const c = [];
|
|
2354
|
+
for (let _ = s; _ && !c.includes(_); )
|
|
2355
|
+
c.push(_), _ = t.get(((d = Q(_[1] ?? "", "(?:xlink:)?href")) == null ? void 0 : d.slice(1)) ?? "");
|
|
2356
|
+
const a = (_) => c.map((w) => Q(w[1] ?? "", _)).find((w) => w !== void 0), l = a("gradientUnits") === "userSpaceOnUse", h = (_, w, E) => {
|
|
2357
|
+
const I = a(_) ?? w;
|
|
2358
|
+
return parseFloat(I) * (I.trim().endsWith("%") ? (l ? E : 1) / 100 : 1);
|
|
2359
|
+
};
|
|
2360
|
+
let p = sn(a("gradientTransform") ?? "");
|
|
2361
|
+
if (!l) {
|
|
2362
|
+
const _ = [];
|
|
2363
|
+
Dn(e, [1, 0, 0, 1, 0, 0], _);
|
|
2364
|
+
const w = kn({ contours: _ });
|
|
2365
|
+
p = dt([w.maxX - w.minX, 0, 0, w.maxY - w.minY, w.minX, w.minY], p);
|
|
2366
|
+
}
|
|
2367
|
+
const f = s[0] === "radial", [u, y] = [h("x1", "0%", i), h("y1", "0%", r)], [x, g] = [h("x2", "100%", i) - u, h("y2", "0%", r) - y], M = Math.hypot(i, r) / Math.SQRT2, [b, A, F] = [h("cx", "50%", i), h("cy", "50%", r), h("r", "50%", M)], k = x * x + g * g || 1, T = f ? [1 / F, 0, 0, 1 / F, -b / F, -A / F] : [x / k, 0, g / k, 0, -(u * x + y * g) / k, 0], m = [...(c.map((_) => _[2] ?? "").find((_) => /<stop\b/.test(_)) ?? "").matchAll(/<stop\b[^>]*>/g)].map(([_]) => ({
|
|
2368
|
+
offset: En(Q(_, "offset"), 0),
|
|
2369
|
+
color: In(_, "stop-color", n) ?? "black",
|
|
2370
|
+
opacity: En(In(_, "stop-opacity", n), 1)
|
|
2371
|
+
}));
|
|
2372
|
+
return { radial: f, matrix: dt(T, dt(Vo(p), o)), stops: m };
|
|
2373
|
+
}
|
|
2374
|
+
function dt(s, t) {
|
|
2375
|
+
const [n = 0, o = 0, e = 0, i = 0, r = 0, c = 0] = s, [a = 0, l = 0, h = 0, p = 0, f = 0, u = 0] = t;
|
|
2376
|
+
return [
|
|
2377
|
+
n * a + e * l,
|
|
2378
|
+
o * a + i * l,
|
|
2379
|
+
n * h + e * p,
|
|
2380
|
+
o * h + i * p,
|
|
2381
|
+
n * f + e * u + r,
|
|
2382
|
+
o * f + i * u + c
|
|
2383
|
+
];
|
|
2384
|
+
}
|
|
2385
|
+
function qi([s = 0, t = 0, n = 0, o = 0, e = 0, i = 0], r, c) {
|
|
2386
|
+
return [s * r + n * c + e, t * r + o * c + i];
|
|
2387
|
+
}
|
|
2388
|
+
function Vo([s = 0, t = 0, n = 0, o = 0, e = 0, i = 0]) {
|
|
2389
|
+
const r = s * o - t * n;
|
|
2390
|
+
return [o / r, -t / r, -n / r, s / r, (n * i - o * e) / r, (t * e - s * i) / r];
|
|
2391
|
+
}
|
|
2392
|
+
function sn(s) {
|
|
2393
|
+
let t = [1, 0, 0, 1, 0, 0];
|
|
2394
|
+
for (const [, n, o = ""] of s.matchAll(/(\w+)\s*\(([^)]*)\)/g)) {
|
|
2395
|
+
const [e = 0, i, r, c = 0, a = 0, l = 0] = o.trim().split(/[\s,]+/).map(parseFloat), h = e * Math.PI / 180, [p, f] = [Math.cos(h), Math.sin(h)], [u, y] = [i ?? 0, r ?? 0];
|
|
2396
|
+
t = dt(
|
|
2397
|
+
t,
|
|
2398
|
+
n === "matrix" ? [e, i ?? 0, r ?? 0, c, a, l] : n === "translate" ? [1, 0, 0, 1, e, i ?? 0] : n === "scale" ? [e, 0, 0, i ?? e, 0, 0] : n === "rotate" ? [p, f, -f, p, u - p * u + f * y, y - f * u - p * y] : n === "skewX" ? [1, 0, Math.tan(h), 1, 0, 0] : [1, Math.tan(h), 0, 1, 0, 0]
|
|
2399
|
+
// skewY
|
|
2400
|
+
);
|
|
2401
|
+
}
|
|
2402
|
+
return t;
|
|
2403
|
+
}
|
|
2404
|
+
const ds = /[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/y;
|
|
2405
|
+
function Dn(s, t, n) {
|
|
2406
|
+
let o = 0, e = 0, i = 0, r = 0, c = 0, a = 0, l = 0, h = "", p = "", f = [];
|
|
2407
|
+
const u = () => {
|
|
2408
|
+
for (; o < s.length && ` \r
|
|
2409
|
+
,`.includes(s[o]); ) o++;
|
|
2410
|
+
}, y = () => {
|
|
2411
|
+
u(), ds.lastIndex = o;
|
|
2412
|
+
const b = ds.exec(s);
|
|
2413
|
+
if (!b) throw new Error(`parseSvg: expected a number at ${o} in path "${s}"`);
|
|
2414
|
+
return o = ds.lastIndex, parseFloat(b[0]);
|
|
2415
|
+
}, x = () => (u(), s[o++] === "1" ? 1 : 0), g = (b, ...A) => {
|
|
2416
|
+
const F = [e, i, ...A], k = [];
|
|
2417
|
+
for (let C = 0; C < F.length; C += 2) k.push(...qi(t, F[C], F[C + 1]));
|
|
2418
|
+
const [T = 0, q = 0, m = 0, d = 0, _ = 0, w = 0, E = 0, I = 0] = k;
|
|
2419
|
+
f.push(new st(b, T, q, m, d, _, w, E, I)), e = A[A.length - 2], i = A[A.length - 1];
|
|
2420
|
+
}, M = () => {
|
|
2421
|
+
f.length > 0 && ((e !== r || i !== c) && g(nt, r, c), n.push(f), f = []), e = r, i = c;
|
|
2422
|
+
};
|
|
2423
|
+
for (u(); o < s.length; u()) {
|
|
2424
|
+
if (/[a-zA-Z]/.test(s[o])) h = s[o++];
|
|
2425
|
+
else if (!h) throw new Error(`parseSvg: expected a command at ${o} in path "${s}"`);
|
|
2426
|
+
const b = h.toUpperCase(), A = h === b ? 0 : e, F = h === b ? 0 : i, k = b === "S" && "CS".includes(p) || b === "T" && "QT".includes(p), T = k ? 2 * e - a : e, q = k ? 2 * i - l : i;
|
|
2427
|
+
switch (b) {
|
|
2428
|
+
case "M": {
|
|
2429
|
+
const m = A + y(), d = F + y();
|
|
2430
|
+
M(), e = r = m, i = c = d, h = h === "M" ? "L" : "l";
|
|
2431
|
+
break;
|
|
2432
|
+
}
|
|
2433
|
+
case "L":
|
|
2434
|
+
g(nt, A + y(), F + y());
|
|
2435
|
+
break;
|
|
2436
|
+
case "H":
|
|
2437
|
+
g(nt, A + y(), i);
|
|
2438
|
+
break;
|
|
2439
|
+
case "V":
|
|
2440
|
+
g(nt, e, F + y());
|
|
2441
|
+
break;
|
|
2442
|
+
case "C":
|
|
2443
|
+
case "S": {
|
|
2444
|
+
const m = b === "C" ? A + y() : T, d = b === "C" ? F + y() : q;
|
|
2445
|
+
a = A + y(), l = F + y(), g(Ct, m, d, a, l, A + y(), F + y());
|
|
2446
|
+
break;
|
|
2447
|
+
}
|
|
2448
|
+
case "Q":
|
|
2449
|
+
case "T":
|
|
2450
|
+
a = b === "Q" ? A + y() : T, l = b === "Q" ? F + y() : q, g(ct, a, l, A + y(), F + y());
|
|
2451
|
+
break;
|
|
2452
|
+
case "A": {
|
|
2453
|
+
const m = y(), d = y(), _ = y(), w = x(), E = x();
|
|
2454
|
+
Ci(g, e, i, m, d, _, w, E, A + y(), F + y());
|
|
2455
|
+
break;
|
|
2456
|
+
}
|
|
2457
|
+
case "Z":
|
|
2458
|
+
M(), h = "";
|
|
2459
|
+
break;
|
|
2460
|
+
default:
|
|
2461
|
+
throw new Error(`parseSvg: unknown path command "${h}"`);
|
|
2462
|
+
}
|
|
2463
|
+
p = b;
|
|
2464
|
+
}
|
|
2465
|
+
M();
|
|
2466
|
+
}
|
|
2467
|
+
function Ci(s, t, n, o, e, i, r, c, a, l) {
|
|
2468
|
+
if (t === a && n === l) return;
|
|
2469
|
+
if (o = Math.abs(o), e = Math.abs(e), o === 0 || e === 0) return s(nt, a, l);
|
|
2470
|
+
const h = Math.cos(i * Math.PI / 180), p = Math.sin(i * Math.PI / 180), f = (t - a) / 2, u = (n - l) / 2, y = h * f + p * u, x = -p * f + h * u, g = y * y / (o * o) + x * x / (e * e);
|
|
2471
|
+
g > 1 && (o *= Math.sqrt(g), e *= Math.sqrt(g));
|
|
2472
|
+
const M = o * o * x * x + e * e * y * y, b = (r === c ? -1 : 1) * Math.sqrt(Math.max(0, (o * o * e * e - M) / M)), A = b * o * x / e, F = -b * e * y / o, k = h * A - p * F + (t + a) / 2, T = p * A + h * F + (n + l) / 2, q = Math.atan2((x - F) / e, (y - A) / o);
|
|
2473
|
+
let m = Math.atan2((-x - F) / e, (-y - A) / o) - q;
|
|
2474
|
+
c && m < 0 ? m += 2 * Math.PI : !c && m > 0 && (m -= 2 * Math.PI);
|
|
2475
|
+
const d = Math.max(1, Math.ceil(Math.abs(m) / (Math.PI / 2) - 1e-9)), _ = m / d, w = 4 / 3 * Math.tan(_ / 4), E = (C, S) => k + o * C * h - e * S * p, I = (C, S) => T + o * C * p + e * S * h;
|
|
2476
|
+
for (let C = 0; C < d; C++) {
|
|
2477
|
+
const S = Math.cos(q + C * _), O = Math.sin(q + C * _), L = Math.cos(q + (C + 1) * _), W = Math.sin(q + (C + 1) * _), X = C === d - 1;
|
|
2478
|
+
s(
|
|
2479
|
+
Ct,
|
|
2480
|
+
E(S - w * O, O + w * S),
|
|
2481
|
+
I(S - w * O, O + w * S),
|
|
2482
|
+
E(L + w * W, W - w * L),
|
|
2483
|
+
I(L + w * W, W - w * L),
|
|
2484
|
+
X ? a : E(L, W),
|
|
2485
|
+
X ? l : I(L, W)
|
|
2486
|
+
);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
function vi(s) {
|
|
2490
|
+
let t = 0, n = 0;
|
|
2491
|
+
for (const c of s)
|
|
2492
|
+
t += c.w * c.h, n = Math.max(n, c.w);
|
|
2493
|
+
s.sort((c, a) => a.h - c.h);
|
|
2494
|
+
const e = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
|
|
2495
|
+
let i = 0, r = 0;
|
|
2496
|
+
for (const c of s)
|
|
2497
|
+
for (let a = e.length - 1; a >= 0; a--) {
|
|
2498
|
+
const l = e[a];
|
|
2499
|
+
if (!(c.w > l.w || c.h > l.h)) {
|
|
2500
|
+
if (c.x = l.x, c.y = l.y, r = Math.max(r, c.y + c.h), i = Math.max(i, c.x + c.w), c.w === l.w && c.h === l.h) {
|
|
2501
|
+
const h = e.pop();
|
|
2502
|
+
h && a < e.length && (e[a] = h);
|
|
2503
|
+
} else c.h === l.h ? (l.x += c.w, l.w -= c.w) : c.w === l.w ? (l.y += c.h, l.h -= c.h) : (e.push({
|
|
2504
|
+
x: l.x + c.w,
|
|
2505
|
+
y: l.y,
|
|
2506
|
+
w: l.w - c.w,
|
|
1890
2507
|
h: c.h
|
|
1891
|
-
}),
|
|
2508
|
+
}), l.y += c.h, l.h -= c.h);
|
|
1892
2509
|
break;
|
|
1893
2510
|
}
|
|
1894
2511
|
}
|
|
1895
2512
|
return {
|
|
1896
|
-
w:
|
|
2513
|
+
w: i,
|
|
1897
2514
|
// container width
|
|
1898
|
-
h:
|
|
2515
|
+
h: r,
|
|
1899
2516
|
// container height
|
|
1900
|
-
fill:
|
|
2517
|
+
fill: t / (i * r) || 0
|
|
1901
2518
|
// space utilization
|
|
1902
2519
|
};
|
|
1903
2520
|
}
|
|
1904
|
-
const
|
|
1905
|
-
function
|
|
1906
|
-
const
|
|
1907
|
-
return ~Math.trunc(255.5 - 255 *
|
|
2521
|
+
const Lo = 4;
|
|
2522
|
+
function Ms(s) {
|
|
2523
|
+
const t = s < 0 ? 0 : s > 1 ? 1 : s;
|
|
2524
|
+
return ~Math.trunc(255.5 - 255 * t) & 255;
|
|
1908
2525
|
}
|
|
1909
|
-
class
|
|
1910
|
-
|
|
1911
|
-
|
|
2526
|
+
class Si {
|
|
2527
|
+
/**
|
|
2528
|
+
* @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
|
|
2529
|
+
* @param opts Generation scale and distance range.
|
|
2530
|
+
*/
|
|
2531
|
+
constructor(t, n = {}) {
|
|
2532
|
+
this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._cacheByKey = /* @__PURE__ */ new Map(), this._font = t, this._pxPerEm = n.pixelsPerEm ?? 40, this._pxrange = n.pxrange ?? 4, this._floats = n.float ? new Float32Array(0) : null, this.pxrangeEm = this._pxrange / this._pxPerEm;
|
|
1912
2533
|
}
|
|
1913
2534
|
/** Packed atlas texture width in texels (chosen by potpack). */
|
|
1914
2535
|
get width() {
|
|
@@ -1922,97 +2543,97 @@ class Ei {
|
|
|
1922
2543
|
get texture() {
|
|
1923
2544
|
return this._pixels;
|
|
1924
2545
|
}
|
|
2546
|
+
/** {@link Atlas.texture} as raw float RGB, not clamped to [0, 1], for zoom that
|
|
2547
|
+
* outruns 8 bits; `null` without the `float` option. */
|
|
2548
|
+
get floatTexture() {
|
|
2549
|
+
return this._floats;
|
|
2550
|
+
}
|
|
1925
2551
|
/**
|
|
1926
2552
|
* Batched generate + pack. Generates MSDFs for any codepoints not
|
|
1927
2553
|
* already cached, then runs potpack **once** over the whole cache.
|
|
1928
2554
|
* Returns the `AtlasGlyph` for each requested codepoint, in order.
|
|
1929
2555
|
*/
|
|
1930
|
-
glyphs(
|
|
1931
|
-
const
|
|
1932
|
-
|
|
1933
|
-
for (const i of n) {
|
|
1934
|
-
const o = this._cache.get(i);
|
|
1935
|
-
if (o) {
|
|
1936
|
-
t.push(o.glyph);
|
|
1937
|
-
continue;
|
|
1938
|
-
}
|
|
1939
|
-
const p = this._generateForGlyphId(this._font.glyphId(i));
|
|
1940
|
-
this._cache.set(i, p), t.push(p.glyph), s++;
|
|
1941
|
-
}
|
|
1942
|
-
return s > 0 && this._repack(), t;
|
|
2556
|
+
glyphs(t) {
|
|
2557
|
+
const n = this._requireFont();
|
|
2558
|
+
return this.glyphsByIndex(Array.from(t, (o) => n.glyphId(o)));
|
|
1943
2559
|
}
|
|
1944
2560
|
/**
|
|
1945
2561
|
* Single-glyph convenience: generates + packs if missing. Repacks the
|
|
1946
2562
|
* whole atlas on every new insert — for more than one glyph, use
|
|
1947
2563
|
* {@link Atlas.glyphs} instead.
|
|
1948
2564
|
*/
|
|
1949
|
-
glyph(
|
|
1950
|
-
return this.glyphs([
|
|
2565
|
+
glyph(t) {
|
|
2566
|
+
return this.glyphs([t])[0];
|
|
1951
2567
|
}
|
|
1952
2568
|
/**
|
|
1953
2569
|
* Batched generate + pack, addressed by raw glyph index instead of
|
|
1954
2570
|
* Unicode codepoint — the {@link Atlas.glyphs} twin for glyphs with no
|
|
1955
2571
|
* reachable cmap entry. Icon fonts (e.g. Lucide) commonly have far more
|
|
1956
2572
|
* glyphs than mapped codepoints; this is how the rest of the set gets
|
|
1957
|
-
* generated. Shares one packed atlas texture with
|
|
1958
|
-
*
|
|
1959
|
-
* through either method. Cached separately from {@link Atlas.glyphs} (a
|
|
1960
|
-
* codepoint and a glyph index are different numbers in the same integer
|
|
1961
|
-
* space — sharing one cache would collide them).
|
|
2573
|
+
* generated. Shares one cache and one packed atlas texture with
|
|
2574
|
+
* {@link Atlas.glyphs}, which maps codepoints to glyph indices first.
|
|
1962
2575
|
*/
|
|
1963
|
-
glyphsByIndex(
|
|
1964
|
-
const
|
|
1965
|
-
let
|
|
1966
|
-
for (const
|
|
1967
|
-
const
|
|
1968
|
-
if (
|
|
1969
|
-
|
|
2576
|
+
glyphsByIndex(t) {
|
|
2577
|
+
const n = [];
|
|
2578
|
+
let o = 0;
|
|
2579
|
+
for (const e of t) {
|
|
2580
|
+
const i = this._cache.get(e);
|
|
2581
|
+
if (i) {
|
|
2582
|
+
n.push(i.glyph);
|
|
1970
2583
|
continue;
|
|
1971
2584
|
}
|
|
1972
|
-
const
|
|
1973
|
-
this.
|
|
2585
|
+
const r = this._generateForGlyphId(e);
|
|
2586
|
+
this._cache.set(e, r), n.push(r.glyph), o++;
|
|
1974
2587
|
}
|
|
1975
|
-
return
|
|
2588
|
+
return o > 0 && this._repack(), n;
|
|
1976
2589
|
}
|
|
1977
2590
|
/** Single-glyph convenience for {@link Atlas.glyphsByIndex} — see its
|
|
1978
2591
|
* doc. For more than one glyph, prefer {@link Atlas.glyphsByIndex}
|
|
1979
2592
|
* (one potpack for the whole batch instead of one per insert). */
|
|
1980
|
-
glyphByIndex(
|
|
1981
|
-
return this.glyphsByIndex([
|
|
2593
|
+
glyphByIndex(t) {
|
|
2594
|
+
return this.glyphsByIndex([t])[0];
|
|
1982
2595
|
}
|
|
1983
2596
|
/**
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
2597
|
+
* Batched generate + pack for arbitrary shapes (e.g. from `parseSvg`),
|
|
2598
|
+
* keyed by a caller-chosen string — the {@link Atlas.glyphs} twin for
|
|
2599
|
+
* non-font input. Shapes must be y-up, in the units `pixelsPerEm` scales
|
|
2600
|
+
* (`parseSvg` makes 1 unit = the viewBox height). A new shape is mutated
|
|
2601
|
+
* (overlaps merged, normalized + coloured); a cached key ignores the shape
|
|
2602
|
+
* passed. `advance` is 0. Shares the one packed texture with the glyph cache.
|
|
1987
2603
|
*/
|
|
1988
|
-
|
|
1989
|
-
const
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
const
|
|
2005
|
-
return
|
|
2604
|
+
shapes(t) {
|
|
2605
|
+
const n = [];
|
|
2606
|
+
let o = 0;
|
|
2607
|
+
for (const [e, i] of t) {
|
|
2608
|
+
let r = this._cacheByKey.get(e);
|
|
2609
|
+
r || (r = this._generate(i, 0), this._cacheByKey.set(e, r), o++), n.push(r.glyph);
|
|
2610
|
+
}
|
|
2611
|
+
return o > 0 && this._repack(), n;
|
|
2612
|
+
}
|
|
2613
|
+
/** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
|
|
2614
|
+
_requireFont() {
|
|
2615
|
+
if (!this._font) throw new Error("Atlas: no font — this atlas only supports shapes()");
|
|
2616
|
+
return this._font;
|
|
2617
|
+
}
|
|
2618
|
+
/** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
|
|
2619
|
+
_generateForGlyphId(t) {
|
|
2620
|
+
const n = this._requireFont(), o = n.metrics.unitsPerEm, e = n.shape(t);
|
|
2621
|
+
return dn(e, o), this._generate(e, n.advance(t) / o);
|
|
2622
|
+
}
|
|
2623
|
+
/** Generates one entry from an em-unit shape. Does not cache or pack. */
|
|
2624
|
+
_generate(t, n) {
|
|
2625
|
+
const o = ki(t, this._pxPerEm, this._pxrange);
|
|
2626
|
+
return { glyph: {
|
|
2006
2627
|
x: 0,
|
|
2007
2628
|
y: 0,
|
|
2008
|
-
w:
|
|
2009
|
-
h:
|
|
2010
|
-
advance:
|
|
2011
|
-
planeLeft:
|
|
2012
|
-
planeBottom:
|
|
2013
|
-
planeRight:
|
|
2014
|
-
planeTop:
|
|
2015
|
-
}, msdf:
|
|
2629
|
+
w: o ? o.w : 0,
|
|
2630
|
+
h: o ? o.h : 0,
|
|
2631
|
+
advance: n,
|
|
2632
|
+
planeLeft: o ? o.planeLeft : 0,
|
|
2633
|
+
planeBottom: o ? o.planeBottom : 0,
|
|
2634
|
+
planeRight: o ? o.planeRight : 0,
|
|
2635
|
+
planeTop: o ? o.planeTop : 0
|
|
2636
|
+
}, msdf: o ? o.msdf : null };
|
|
2016
2637
|
}
|
|
2017
2638
|
/**
|
|
2018
2639
|
* Lays out `text` left-to-right on a single line, applying kerning.
|
|
@@ -2021,19 +2642,19 @@ class Ei {
|
|
|
2021
2642
|
* is the pen position in em. `text` must not contain `\n` — use
|
|
2022
2643
|
* {@link Atlas.layoutMultiline} for multi-line input.
|
|
2023
2644
|
*/
|
|
2024
|
-
layout(
|
|
2025
|
-
const
|
|
2026
|
-
for (const
|
|
2027
|
-
this.glyphs(
|
|
2028
|
-
const
|
|
2029
|
-
let
|
|
2030
|
-
for (const
|
|
2031
|
-
const
|
|
2032
|
-
c >= 0 && (
|
|
2033
|
-
const
|
|
2034
|
-
|
|
2645
|
+
layout(t) {
|
|
2646
|
+
const n = [];
|
|
2647
|
+
for (const a of t) n.push(a.codePointAt(0));
|
|
2648
|
+
this.glyphs(n);
|
|
2649
|
+
const o = [], e = this._requireFont(), i = e.metrics.unitsPerEm;
|
|
2650
|
+
let r = 0, c = -1;
|
|
2651
|
+
for (const a of n) {
|
|
2652
|
+
const l = e.glyphId(a);
|
|
2653
|
+
c >= 0 && (r += e.kerning(c, l) / i);
|
|
2654
|
+
const h = this._cache.get(l).glyph;
|
|
2655
|
+
o.push({ glyph: h, penX: r, penY: 0 }), r += h.advance, c = l;
|
|
2035
2656
|
}
|
|
2036
|
-
return { glyphs:
|
|
2657
|
+
return { glyphs: o, widthEm: r };
|
|
2037
2658
|
}
|
|
2038
2659
|
/**
|
|
2039
2660
|
* Lays out `text` as one or more `\n`-separated lines, each run through
|
|
@@ -2050,65 +2671,62 @@ class Ei {
|
|
|
2050
2671
|
* not per-glyph ink bounds) — fine for camera framing, not for tight
|
|
2051
2672
|
* cropping.
|
|
2052
2673
|
*/
|
|
2053
|
-
layoutMultiline(
|
|
2054
|
-
const
|
|
2055
|
-
`),
|
|
2674
|
+
layoutMultiline(t) {
|
|
2675
|
+
const n = this._requireFont(), o = n.metrics.unitsPerEm, e = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / o, i = t.split(`
|
|
2676
|
+
`), r = [];
|
|
2056
2677
|
let c = 0;
|
|
2057
|
-
for (let
|
|
2058
|
-
const { glyphs:
|
|
2059
|
-
for (const f of
|
|
2060
|
-
|
|
2678
|
+
for (let a = 0; a < i.length; a++) {
|
|
2679
|
+
const { glyphs: l, widthEm: h } = this.layout(i[a]), p = -a * e;
|
|
2680
|
+
for (const f of l) r.push({ glyph: f.glyph, penX: f.penX, penY: p });
|
|
2681
|
+
h > c && (c = h);
|
|
2061
2682
|
}
|
|
2062
|
-
return { glyphs:
|
|
2683
|
+
return { glyphs: r, widthEm: c, heightEm: i.length * e };
|
|
2063
2684
|
}
|
|
2064
|
-
/** Repacks every cached
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
2685
|
+
/** Repacks every cached entry (glyph-index- and string-keyed caches — one
|
|
2686
|
+
* shared texture) with potpack, reallocates the texture, and re-blits each
|
|
2687
|
+
* MSDF at its assigned rect. Called by `glyphsByIndex()`/`shapes()` after
|
|
2688
|
+
* any batch of new inserts — once per batch.
|
|
2689
|
+
*
|
|
2690
|
+
* Each cell gets a 1-texel gutter of zeros on its right and bottom, so a
|
|
2691
|
+
* quad covering the whole cell can sample its full rect: linear filtering
|
|
2692
|
+
* at the edge blends with zeros (further outside the glyph), never with a
|
|
2693
|
+
* neighbouring glyph's texels. */
|
|
2068
2694
|
_repack() {
|
|
2069
|
-
const
|
|
2070
|
-
for (const
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
i.entry.glyph.x = i.x, i.entry.glyph.y = i.y, this._blit(i.entry.msdf, i.x, i.y, i.w, i.h);
|
|
2695
|
+
const t = [];
|
|
2696
|
+
for (const e of [this._cache, this._cacheByKey])
|
|
2697
|
+
for (const { glyph: i, msdf: r } of e.values())
|
|
2698
|
+
r && t.push({ w: i.w + 1, h: i.h + 1, x: 0, y: 0, glyph: i, msdf: r });
|
|
2699
|
+
const { w: n, h: o } = vi(t);
|
|
2700
|
+
this._width = n, this._height = o, this._pixels = new Uint8Array(n * o * Lo), this._floats && (this._floats = new Float32Array(n * o * 3));
|
|
2701
|
+
for (const e of t)
|
|
2702
|
+
e.glyph.x = e.x, e.glyph.y = e.y, this._blit(e.msdf, e.x, e.y, e.glyph.w, e.glyph.h);
|
|
2078
2703
|
}
|
|
2079
2704
|
/**
|
|
2080
2705
|
* Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
|
|
2081
2706
|
* atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
|
|
2082
2707
|
*/
|
|
2083
|
-
_blit(n,
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2708
|
+
_blit(t, n, o, e, i) {
|
|
2709
|
+
var a;
|
|
2710
|
+
const r = this._width, c = this._pixels;
|
|
2711
|
+
for (let l = 0; l < i; l++) {
|
|
2712
|
+
const h = o + (i - 1 - l);
|
|
2713
|
+
(a = this._floats) == null || a.set(t.subarray(l * e * 3, (l + 1) * e * 3), (h * r + n) * 3);
|
|
2714
|
+
for (let p = 0; p < e; p++) {
|
|
2715
|
+
const f = (l * e + p) * 3, u = (h * r + (n + p)) * Lo;
|
|
2716
|
+
c[u] = Ms(t[f]), c[u + 1] = Ms(t[f + 1]), c[u + 2] = Ms(t[f + 2]), c[u + 3] = 255;
|
|
2090
2717
|
}
|
|
2091
2718
|
}
|
|
2092
2719
|
}
|
|
2093
2720
|
}
|
|
2094
|
-
const zn = [0, 0];
|
|
2095
|
-
function wi(e) {
|
|
2096
|
-
let n = 1 / 0, t = 1 / 0, s = -1 / 0, i = -1 / 0;
|
|
2097
|
-
for (const o of e.contours)
|
|
2098
|
-
for (const p of o)
|
|
2099
|
-
for (let c = 0; c <= Qs; c++) {
|
|
2100
|
-
p.point(c / Qs, zn);
|
|
2101
|
-
const r = zn[0], h = zn[1];
|
|
2102
|
-
r < n && (n = r), h < t && (t = h), r > s && (s = r), h > i && (i = h);
|
|
2103
|
-
}
|
|
2104
|
-
return { minX: n, minY: t, maxX: s, maxY: i };
|
|
2105
|
-
}
|
|
2106
2721
|
export {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2722
|
+
Si as Atlas,
|
|
2723
|
+
Ct as CUBIC,
|
|
2724
|
+
st as EdgeSegment,
|
|
2725
|
+
Ti as Font,
|
|
2726
|
+
nt as LINEAR,
|
|
2727
|
+
ct as QUADRATIC,
|
|
2728
|
+
ki as generateShapeMSDF,
|
|
2729
|
+
Fi as parseSvg,
|
|
2730
|
+
Ii as parseSvgLayers,
|
|
2731
|
+
Ms as pixelFloatToByte
|
|
2114
2732
|
};
|