@nebula-spatial/cad-loader 0.2.3 → 0.2.4

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.
@@ -1,123 +1,123 @@
1
- var Xe = Object.defineProperty;
2
- var jt = (t) => {
1
+ var rn = Object.defineProperty;
2
+ var te = (t) => {
3
3
  throw TypeError(t);
4
4
  };
5
- var Ye = (t, e, n) => e in t ? Xe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
6
- var Z = (t, e, n) => Ye(t, typeof e != "symbol" ? e + "" : e, n), ze = (t, e, n) => e.has(t) || jt("Cannot " + n);
7
- var et = (t, e, n) => (ze(t, e, "read from private field"), n ? n.call(t) : e.get(t)), Wt = (t, e, n) => e.has(t) ? jt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n);
8
- class l extends Error {
5
+ var on = (t, e, n) => e in t ? rn(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
6
+ var Q = (t, e, n) => on(t, typeof e != "symbol" ? e + "" : e, n), sn = (t, e, n) => e.has(t) || te("Cannot " + n);
7
+ var rt = (t, e, n) => (sn(t, e, "read from private field"), n ? n.call(t) : e.get(t)), ee = (t, e, n) => e.has(t) ? te("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n);
8
+ class f extends Error {
9
9
  constructor(n, r) {
10
10
  super(r);
11
- Z(this, "code");
11
+ Q(this, "code");
12
12
  this.name = "GeoLoaderError", this.code = n;
13
13
  }
14
14
  }
15
- const Ut = 4096;
16
- function _e(t) {
15
+ const Bt = 4096;
16
+ function Ie(t) {
17
17
  return t >= 6 ? "u16_lw" : t >= 5 ? "u8_lw" : t >= 4 ? "u16" : "u8";
18
18
  }
19
- function xe(t) {
19
+ function Re(t) {
20
20
  return t === "u16_lw" ? 13 : t === "u8_lw" ? 12 : t === "u16" ? 9 : 8;
21
21
  }
22
- function Ee(t, e, n) {
22
+ function Ve(t, e, n) {
23
23
  return n === "u16" || n === "u16_lw" ? t.getUint16(e + 7, !0) : t.getUint8(e + 7);
24
24
  }
25
- function He(t) {
25
+ function an(t) {
26
26
  return t === "u16" || t === "u16_lw" ? 2 : 1;
27
27
  }
28
- function we(t, e, n) {
28
+ function Ge(t, e, n) {
29
29
  if (!(n !== "u8_lw" && n !== "u16_lw"))
30
- return t.getFloat32(e + 7 + He(n), !0);
30
+ return t.getFloat32(e + 7 + an(n), !0);
31
31
  }
32
- function pe(t, e, n, r, s = t.byteLength, o = "u8") {
32
+ function Ne(t, e, n, r, s = t.byteLength, o = "u8") {
33
33
  if (n > s || s > t.byteLength)
34
- throw new l("E_GROUP_RANGE", "Group byte range exceeds payload length");
34
+ throw new f("E_GROUP_RANGE", "Group byte range exceeds payload length");
35
35
  let i = n;
36
- const a = r * 2, c = a * 4;
37
- if (i + c > s)
38
- throw new l("E_GROUP_RANGE", "Group position bytes exceed payload length");
39
- let u;
36
+ const a = r * 2, u = a * 4;
37
+ if (i + u > s)
38
+ throw new f("E_GROUP_RANGE", "Group position bytes exceed payload length");
39
+ let c;
40
40
  if (a > 0) {
41
- const w = new Uint8Array(t, i, c), y = new Uint8Array(c), f = a;
42
- for (let x = 0; x < a; x++)
43
- y[x * 4] = w[x], y[x * 4 + 1] = w[f + x], y[x * 4 + 2] = w[f * 2 + x], y[x * 4 + 3] = w[f * 3 + x];
44
- u = new Float32Array(y.buffer);
41
+ const p = new Uint8Array(t, i, u), h = new Uint8Array(u), y = a;
42
+ for (let w = 0; w < a; w++)
43
+ h[w * 4] = p[w], h[w * 4 + 1] = p[y + w], h[w * 4 + 2] = p[y * 2 + w], h[w * 4 + 3] = p[y * 3 + w];
44
+ c = new Float32Array(h.buffer);
45
45
  } else
46
- u = new Float32Array(0);
47
- if (i += c, i + 4 > s)
48
- throw new l("E_GROUP_RANGE", "Missing seg_count field for group");
46
+ c = new Float32Array(0);
47
+ if (i += u, i + 4 > s)
48
+ throw new f("E_GROUP_RANGE", "Missing seg_count field for group");
49
49
  const m = e.getUint32(i, !0);
50
50
  i += 4;
51
51
  const g = [];
52
- let d = 0;
53
- const h = xe(o);
54
- for (let w = 0; w < m; w++) {
55
- if (i + h > s)
56
- throw new l("E_GROUP_RANGE", "Segment record exceeds payload length");
57
- const y = e.getUint32(i, !0), f = e.getUint8(i + 4), x = e.getUint8(i + 5), p = e.getUint8(i + 6), E = Ee(e, i, o), b = we(e, i, o);
58
- if (d + y > r)
59
- throw new l("E_SEGMENT_SUM", "Segment vertex_count sum exceeds group count");
52
+ let l = 0;
53
+ const d = Re(o);
54
+ for (let p = 0; p < m; p++) {
55
+ if (i + d > s)
56
+ throw new f("E_GROUP_RANGE", "Segment record exceeds payload length");
57
+ const h = e.getUint32(i, !0), y = e.getUint8(i + 4), w = e.getUint8(i + 5), _ = e.getUint8(i + 6), E = Ve(e, i, o), A = Ge(e, i, o);
58
+ if (l + h > r)
59
+ throw new f("E_SEGMENT_SUM", "Segment vertex_count sum exceeds group count");
60
60
  g.push({
61
- startVertex: d,
62
- vertexCount: y,
63
- color: [f, x, p],
61
+ startVertex: l,
62
+ vertexCount: h,
63
+ color: [y, w, _],
64
64
  layerIndex: E,
65
- ...b === void 0 ? {} : { lineweightPx: b }
66
- }), i += h;
67
- const P = d * 2;
68
- if (y > 1) {
69
- let N = u[P], C = u[P + 1];
70
- for (let G = 1; G < y; G++) {
71
- const U = P + G * 2;
72
- N += u[U], C += u[U + 1], u[U] = N, u[U + 1] = C;
65
+ ...A === void 0 ? {} : { lineweightPx: A }
66
+ }), i += d;
67
+ const U = l * 2;
68
+ if (h > 1) {
69
+ let N = c[U], C = c[U + 1];
70
+ for (let V = 1; V < h; V++) {
71
+ const G = U + V * 2;
72
+ N += c[G], C += c[G + 1], c[G] = N, c[G + 1] = C;
73
73
  }
74
74
  }
75
- d += y;
75
+ l += h;
76
76
  }
77
- if (d !== r)
78
- throw new l("E_SEGMENT_SUM", `Segment vertex_count sum ${d} does not match group count ${r}`);
77
+ if (l !== r)
78
+ throw new f("E_SEGMENT_SUM", `Segment vertex_count sum ${l} does not match group count ${r}`);
79
79
  return {
80
- chunk: { pos: u, count: r, segments: g },
80
+ chunk: { pos: c, count: r, segments: g },
81
81
  offset: i
82
82
  };
83
83
  }
84
- function Ke(t, e, n, r, s = "u8") {
84
+ function un(t, e, n, r, s = "u8") {
85
85
  const o = r * 2, i = o * 4;
86
86
  if (n + i > t.byteLength)
87
- throw new l("E_GROUP_RANGE", "Group position bytes exceed payload length");
87
+ throw new f("E_GROUP_RANGE", "Group position bytes exceed payload length");
88
88
  const a = new Uint8Array(t, n, i);
89
- let c = n + i;
90
- if (c + 4 > t.byteLength)
91
- throw new l("E_GROUP_RANGE", "Missing seg_count field for group");
92
- const u = e.getUint32(c, !0);
93
- c += 4;
89
+ let u = n + i;
90
+ if (u + 4 > t.byteLength)
91
+ throw new f("E_GROUP_RANGE", "Missing seg_count field for group");
92
+ const c = e.getUint32(u, !0);
93
+ u += 4;
94
94
  const m = [];
95
95
  let g = 0;
96
- const d = xe(s);
97
- for (let h = 0; h < u; h++) {
98
- if (c + d > t.byteLength)
99
- throw new l("E_GROUP_RANGE", "Segment record exceeds payload length");
100
- const w = e.getUint32(c, !0), y = e.getUint8(c + 4), f = e.getUint8(c + 5), x = e.getUint8(c + 6), p = Ee(e, c, s), E = we(e, c, s);
101
- if (c += d, g + w > r)
102
- throw new l("E_SEGMENT_SUM", "Segment vertex_count sum exceeds group count");
96
+ const l = Re(s);
97
+ for (let d = 0; d < c; d++) {
98
+ if (u + l > t.byteLength)
99
+ throw new f("E_GROUP_RANGE", "Segment record exceeds payload length");
100
+ const p = e.getUint32(u, !0), h = e.getUint8(u + 4), y = e.getUint8(u + 5), w = e.getUint8(u + 6), _ = Ve(e, u, s), E = Ge(e, u, s);
101
+ if (u += l, g + p > r)
102
+ throw new f("E_SEGMENT_SUM", "Segment vertex_count sum exceeds group count");
103
103
  m.push({
104
104
  startVertex: g,
105
- vertexCount: w,
106
- color: [y, f, x],
107
- layerIndex: p,
105
+ vertexCount: p,
106
+ color: [h, y, w],
107
+ layerIndex: _,
108
108
  ...E === void 0 ? {} : { lineweightPx: E }
109
- }), g += w;
109
+ }), g += p;
110
110
  }
111
111
  if (g !== r)
112
- throw new l("E_SEGMENT_SUM", `Segment vertex_count sum ${g} does not match group count ${r}`);
112
+ throw new f("E_SEGMENT_SUM", `Segment vertex_count sum ${g} does not match group count ${r}`);
113
113
  return {
114
114
  shuffled: a,
115
115
  plane: o,
116
116
  segments: m,
117
- offset: c
117
+ offset: u
118
118
  };
119
119
  }
120
- function je(t, e, n, r) {
120
+ function ln(t, e, n, r) {
121
121
  if (r === 0)
122
122
  return new Float32Array(0);
123
123
  const s = new Uint8Array(r * 4);
@@ -125,8 +125,8 @@ function je(t, e, n, r) {
125
125
  s[o * 4] = t[n + o], s[o * 4 + 1] = t[e + n + o], s[o * 4 + 2] = t[e * 2 + n + o], s[o * 4 + 3] = t[e * 3 + n + o];
126
126
  return new Float32Array(s.buffer);
127
127
  }
128
- function We(t, e, n, r, s) {
129
- const o = je(
128
+ function cn(t, e, n, r, s) {
129
+ const o = ln(
130
130
  t.shuffled,
131
131
  t.plane,
132
132
  (e.startVertex + n) * 2,
@@ -135,12 +135,12 @@ function We(t, e, n, r, s) {
135
135
  let i = (s == null ? void 0 : s[0]) ?? 0, a = (s == null ? void 0 : s[1]) ?? 0;
136
136
  if (r > 0) {
137
137
  n === 0 ? (i = o[0], a = o[1]) : (i += o[0], a += o[1], o[0] = i, o[1] = a);
138
- for (let u = 1; u < r; u++) {
139
- const m = u * 2;
138
+ for (let c = 1; c < r; c++) {
139
+ const m = c * 2;
140
140
  i += o[m], a += o[m + 1], o[m] = i, o[m + 1] = a;
141
141
  }
142
142
  }
143
- const c = r > 0 ? [{
143
+ const u = r > 0 ? [{
144
144
  startVertex: 0,
145
145
  vertexCount: r,
146
146
  color: [e.color[0], e.color[1], e.color[2]],
@@ -148,30 +148,30 @@ function We(t, e, n, r, s) {
148
148
  ...e.lineweightPx === void 0 ? {} : { lineweightPx: e.lineweightPx }
149
149
  }] : [];
150
150
  return {
151
- chunk: { pos: o, count: r, segments: c },
151
+ chunk: { pos: o, count: r, segments: u },
152
152
  lastPoint: r > 0 ? [i, a] : s
153
153
  };
154
154
  }
155
- function* qe(t, e, n, r, s = "u8") {
156
- const o = Ke(t, e, n, r, s);
155
+ function* fn(t, e, n, r, s = "u8") {
156
+ const o = un(t, e, n, r, s);
157
157
  if (r === 0)
158
158
  return yield { pos: new Float32Array(0), count: 0, segments: [] }, o.offset;
159
159
  for (const i of o.segments) {
160
160
  let a = null;
161
- for (let c = 0; c < i.vertexCount; c += Ut) {
162
- const u = Math.min(Ut, i.vertexCount - c), m = We(o, i, c, u, a);
161
+ for (let u = 0; u < i.vertexCount; u += Bt) {
162
+ const c = Math.min(Bt, i.vertexCount - u), m = cn(o, i, u, c, a);
163
163
  a = m.lastPoint, yield m.chunk;
164
164
  }
165
165
  }
166
166
  return o.offset;
167
167
  }
168
- function be() {
168
+ function Ue() {
169
169
  const t = globalThis.TextDecoder;
170
170
  if (!t)
171
- throw new l("E_HEADER_JSON", "TextDecoder is required to parse CAD pack metadata");
171
+ throw new f("E_HEADER_JSON", "TextDecoder is required to parse CAD pack metadata");
172
172
  return new t();
173
173
  }
174
- function ot(t) {
174
+ function it(t) {
175
175
  return t ? {
176
176
  minX: t.minX,
177
177
  minY: t.minY,
@@ -179,47 +179,47 @@ function ot(t) {
179
179
  maxY: t.maxY
180
180
  } : null;
181
181
  }
182
- function Ct(t) {
182
+ function $t(t) {
183
183
  return !!t && Number.isFinite(t.minX) && Number.isFinite(t.minY) && Number.isFinite(t.maxX) && Number.isFinite(t.maxY);
184
184
  }
185
- function mt(t) {
186
- return Ct(t) ? ot(t) : null;
185
+ function ht(t) {
186
+ return $t(t) ? it(t) : null;
187
187
  }
188
- function Ae(t, e) {
189
- const n = Ct(t) ? t : null, r = Ct(e) ? e : null;
188
+ function Ce(t, e) {
189
+ const n = $t(t) ? t : null, r = $t(e) ? e : null;
190
190
  return n ? r ? {
191
191
  minX: Math.min(n.minX, r.minX),
192
192
  minY: Math.min(n.minY, r.minY),
193
193
  maxX: Math.max(n.maxX, r.maxX),
194
194
  maxY: Math.max(n.maxY, r.maxY)
195
- } : ot(n) : ot(r);
195
+ } : it(n) : it(r);
196
196
  }
197
- function Je(t, e, n, r = 0, s = 1) {
197
+ function dn(t, e, n, r = 0, s = 1) {
198
198
  if (e <= 0 || n <= 0) return null;
199
- let o = Number.POSITIVE_INFINITY, i = Number.POSITIVE_INFINITY, a = Number.NEGATIVE_INFINITY, c = Number.NEGATIVE_INFINITY, u = !1;
199
+ let o = Number.POSITIVE_INFINITY, i = Number.POSITIVE_INFINITY, a = Number.NEGATIVE_INFINITY, u = Number.NEGATIVE_INFINITY, c = !1;
200
200
  for (let m = 0; m < e; m += 1) {
201
- const g = m * n, d = t[g + r], h = t[g + s];
202
- !Number.isFinite(d) || !Number.isFinite(h) || (d < o && (o = d), h < i && (i = h), d > a && (a = d), h > c && (c = h), u = !0);
201
+ const g = m * n, l = t[g + r], d = t[g + s];
202
+ !Number.isFinite(l) || !Number.isFinite(d) || (l < o && (o = l), d < i && (i = d), l > a && (a = l), d > u && (u = d), c = !0);
203
203
  }
204
- return u ? { minX: o, minY: i, maxX: a, maxY: c } : null;
204
+ return c ? { minX: o, minY: i, maxX: a, maxY: u } : null;
205
205
  }
206
- function Ie(t, e) {
207
- const n = t.minX, r = t.minY, s = t.maxX, o = t.maxY, { matA: i, matB: a, matC: c, matD: u, tx: m, ty: g } = e;
208
- let d = i * n + c * r + m, h = a * n + u * r + g, w = d, y = h, f = d, x = h;
209
- return d = i * n + c * o + m, h = a * n + u * o + g, d < w && (w = d), h < y && (y = h), d > f && (f = d), h > x && (x = h), d = i * s + c * r + m, h = a * s + u * r + g, d < w && (w = d), h < y && (y = h), d > f && (f = d), h > x && (x = h), d = i * s + c * o + m, h = a * s + u * o + g, d < w && (w = d), h < y && (y = h), d > f && (f = d), h > x && (x = h), { minX: w, minY: y, maxX: f, maxY: x };
206
+ function Se(t, e) {
207
+ const n = t.minX, r = t.minY, s = t.maxX, o = t.maxY, { matA: i, matB: a, matC: u, matD: c, tx: m, ty: g } = e;
208
+ let l = i * n + u * r + m, d = a * n + c * r + g, p = l, h = d, y = l, w = d;
209
+ return l = i * n + u * o + m, d = a * n + c * o + g, l < p && (p = l), d < h && (h = d), l > y && (y = l), d > w && (w = d), l = i * s + u * r + m, d = a * s + c * r + g, l < p && (p = l), d < h && (h = d), l > y && (y = l), d > w && (w = d), l = i * s + u * o + m, d = a * s + c * o + g, l < p && (p = l), d < h && (h = d), l > y && (y = l), d > w && (w = d), { minX: p, minY: h, maxX: y, maxY: w };
210
210
  }
211
- function Ze(t) {
211
+ function mn(t) {
212
212
  return Math.hypot(t.maxX - t.minX, t.maxY - t.minY);
213
213
  }
214
- function Qe(t, e) {
214
+ function gn(t, e) {
215
215
  const n = (t.minX + t.maxX) / 2, r = (t.minY + t.maxY) / 2, s = (e.minX + e.maxX) / 2, o = (e.minY + e.maxY) / 2;
216
216
  return Math.hypot(n - s, r - o);
217
217
  }
218
- const tn = {};
219
- function qt(t) {
218
+ const yn = {};
219
+ function ne(t) {
220
220
  return typeof t == "object" && t !== null;
221
221
  }
222
- function ut(t, e) {
222
+ function dt(t, e) {
223
223
  return Object.prototype.hasOwnProperty.call(t, e);
224
224
  }
225
225
  function K(t) {
@@ -234,10 +234,10 @@ function K(t) {
234
234
  }
235
235
  return e;
236
236
  }
237
- function Jt(t, e, n, r) {
238
- return new l("E_TEXT_ROUNDTRIP", `Text roundtrip mismatch at stage=${t} index=${e} path=${n}: ${r}`);
237
+ function re(t, e, n, r) {
238
+ return new f("E_TEXT_ROUNDTRIP", `Text roundtrip mismatch at stage=${t} index=${e} path=${n}: ${r}`);
239
239
  }
240
- function St(t, e, n) {
240
+ function vt(t, e, n) {
241
241
  if (Object.is(t, e)) return null;
242
242
  if (Array.isArray(t)) {
243
243
  if (!Array.isArray(e))
@@ -245,23 +245,23 @@ function St(t, e, n) {
245
245
  if (t.length !== e.length)
246
246
  return { path: K([...n, "length"]), reason: `array length ${t.length} !== ${e.length}` };
247
247
  for (let r = 0; r < t.length; r += 1) {
248
- const s = St(t[r], e[r], [...n, r]);
248
+ const s = vt(t[r], e[r], [...n, r]);
249
249
  if (s) return s;
250
250
  }
251
251
  return null;
252
252
  }
253
- if (qt(t)) {
254
- if (!qt(e) || Array.isArray(e))
253
+ if (ne(t)) {
254
+ if (!ne(e) || Array.isArray(e))
255
255
  return { path: K(n), reason: `expected object but found ${Array.isArray(e) ? "array" : typeof e}` };
256
256
  const r = Object.keys(t), s = Object.keys(e);
257
257
  if (r.length !== s.length) {
258
- const o = r.find((a) => !ut(e, a));
258
+ const o = r.find((a) => !dt(e, a));
259
259
  if (o !== void 0)
260
260
  return {
261
261
  path: K([...n, o]),
262
262
  reason: "missing key on actual"
263
263
  };
264
- const i = s.find((a) => !ut(t, a));
264
+ const i = s.find((a) => !dt(t, a));
265
265
  if (i !== void 0)
266
266
  return {
267
267
  path: K([...n, i]),
@@ -269,109 +269,109 @@ function St(t, e, n) {
269
269
  };
270
270
  }
271
271
  for (const o of r) {
272
- if (!ut(e, o))
272
+ if (!dt(e, o))
273
273
  return { path: K([...n, o]), reason: "missing key on actual" };
274
- const i = St(t[o], e[o], [...n, o]);
274
+ const i = vt(t[o], e[o], [...n, o]);
275
275
  if (i) return i;
276
276
  }
277
277
  for (const o of s)
278
- if (!ut(t, o))
278
+ if (!dt(t, o))
279
279
  return { path: K([...n, o]), reason: "extra key on actual" };
280
280
  return null;
281
281
  }
282
282
  return { path: K(n), reason: `expected ${String(t)} but found ${String(e)}` };
283
283
  }
284
- function en(t, e) {
285
- return St(t, e, []);
284
+ function hn(t, e) {
285
+ return vt(t, e, []);
286
286
  }
287
- function Zt(t) {
287
+ function oe(t) {
288
288
  if (t === !0 || t === "1" || t === "true") return !0;
289
289
  if (t === !1 || t === "0" || t === "false") return !1;
290
290
  }
291
- function nn() {
291
+ function _n() {
292
292
  var s, o;
293
- const t = globalThis.process, e = Zt(
293
+ const t = globalThis.process, e = oe(
294
294
  ((s = t == null ? void 0 : t.env) == null ? void 0 : s.DXF_STRICT_TEXT_ROUNDTRIP) ?? ((o = t == null ? void 0 : t.env) == null ? void 0 : o.VITE_DXF_STRICT_TEXT_ROUNDTRIP)
295
295
  );
296
296
  if (e !== void 0) return e;
297
- const n = tn, r = Zt(n == null ? void 0 : n.VITE_DXF_STRICT_TEXT_ROUNDTRIP);
297
+ const n = yn, r = oe(n == null ? void 0 : n.VITE_DXF_STRICT_TEXT_ROUNDTRIP);
298
298
  return r !== void 0 ? r : !1;
299
299
  }
300
- function rn(t, e, n) {
300
+ function xn(t, e, n) {
301
301
  if (e.length !== n.length)
302
- throw Jt(t, Math.min(e.length, n.length), "$length", `text count ${e.length} !== ${n.length}`);
302
+ throw re(t, Math.min(e.length, n.length), "$length", `text count ${e.length} !== ${n.length}`);
303
303
  for (let r = 0; r < e.length; r += 1) {
304
- const s = en(e[r], n[r]);
304
+ const s = hn(e[r], n[r]);
305
305
  if (s)
306
- throw Jt(t, r, s.path, s.reason);
306
+ throw re(t, r, s.path, s.reason);
307
307
  }
308
308
  }
309
- be();
310
- function Qt(t, e) {
309
+ Ue();
310
+ function se(t, e) {
311
311
  if (t > BigInt(Number.MAX_SAFE_INTEGER))
312
- throw new l("E_GROUP_RANGE", `${e} exceeds safe integer range`);
312
+ throw new f("E_GROUP_RANGE", `${e} exceeds safe integer range`);
313
313
  return Number(t);
314
314
  }
315
- function te(t, e, n, r) {
315
+ function ie(t, e, n, r) {
316
316
  if (!Number.isInteger(t) || !Number.isInteger(e) || t < 0 || e < 0 || t + e > n)
317
- throw new l("E_GROUP_RANGE", `${r} exceeds payload length`);
317
+ throw new f("E_GROUP_RANGE", `${r} exceeds payload length`);
318
318
  }
319
- function on(t) {
319
+ function En(t) {
320
320
  if (t.byteLength < 4) return !1;
321
321
  const e = new Uint8Array(t, 0, 4);
322
322
  return e[0] === 68 && e[1] === 88 && e[2] === 66 && e[3] === 83;
323
323
  }
324
- function sn(t) {
324
+ function wn(t) {
325
325
  if (t.byteLength < 20)
326
- throw new l("E_HEADER", "DXBS payload too small: missing container header");
327
- if (!on(t))
328
- throw new l("E_HEADER", "DXBS payload missing magic");
329
- const e = new DataView(t), n = e.getUint16(4, !0), r = e.getUint16(6, !0), s = e.getUint16(8, !0), o = e.getUint16(10, !0), i = e.getUint16(12, !0), a = e.getUint16(14, !0), c = e.getUint32(16, !0);
326
+ throw new f("E_HEADER", "DXBS payload too small: missing container header");
327
+ if (!En(t))
328
+ throw new f("E_HEADER", "DXBS payload missing magic");
329
+ const e = new DataView(t), n = e.getUint16(4, !0), r = e.getUint16(6, !0), s = e.getUint16(8, !0), o = e.getUint16(10, !0), i = e.getUint16(12, !0), a = e.getUint16(14, !0), u = e.getUint32(16, !0);
330
330
  if (n !== 3 || r < 3 || r > 6)
331
- throw new l("E_GROUP_RANGE", `Unsupported DXBS version: ${n}.${r}`);
331
+ throw new f("E_GROUP_RANGE", `Unsupported DXBS version: ${n}.${r}`);
332
332
  if (s !== 0)
333
- throw new l("E_GROUP_RANGE", `Unsupported DXBS sidecar kind: ${s}`);
333
+ throw new f("E_GROUP_RANGE", `Unsupported DXBS sidecar kind: ${s}`);
334
334
  if (a !== 0)
335
- throw new l("E_GROUP_RANGE", `Invalid DXBS reserved field: ${a}`);
335
+ throw new f("E_GROUP_RANGE", `Invalid DXBS reserved field: ${a}`);
336
336
  if (o < 24)
337
- throw new l("E_GROUP_RANGE", `Invalid DXBS directory entry size: ${o}`);
338
- if (c !== o * i)
339
- throw new l("E_GROUP_RANGE", "DXBS directory byte size mismatch");
340
- const u = 20;
341
- te(u, c, t.byteLength, "DXBS section directory");
337
+ throw new f("E_GROUP_RANGE", `Invalid DXBS directory entry size: ${o}`);
338
+ if (u !== o * i)
339
+ throw new f("E_GROUP_RANGE", "DXBS directory byte size mismatch");
340
+ const c = 20;
341
+ ie(c, u, t.byteLength, "DXBS section directory");
342
342
  const m = /* @__PURE__ */ new Map();
343
343
  for (let g = 0; g < i; g += 1) {
344
- const d = u + g * o, h = e.getUint16(d, !0), w = e.getUint16(d + 2, !0), y = e.getUint32(d + 4, !0), f = Qt(e.getBigUint64(d + 8, !0), "DXBS section offset"), x = Qt(e.getBigUint64(d + 16, !0), "DXBS section length");
345
- if (w !== 0)
346
- throw new l("E_GROUP_RANGE", `Unsupported DXBS section flags for type ${h}: ${w}`);
347
- if (y !== 0)
348
- throw new l("E_GROUP_RANGE", `Invalid DXBS section reserved field for type ${h}: ${y}`);
349
- te(f, x, t.byteLength, `DXBS section ${h}`), m.set(h, { type: h, flags: w, offset: f, length: x });
344
+ const l = c + g * o, d = e.getUint16(l, !0), p = e.getUint16(l + 2, !0), h = e.getUint32(l + 4, !0), y = se(e.getBigUint64(l + 8, !0), "DXBS section offset"), w = se(e.getBigUint64(l + 16, !0), "DXBS section length");
345
+ if (p !== 0)
346
+ throw new f("E_GROUP_RANGE", `Unsupported DXBS section flags for type ${d}: ${p}`);
347
+ if (h !== 0)
348
+ throw new f("E_GROUP_RANGE", `Invalid DXBS section reserved field for type ${d}: ${h}`);
349
+ ie(y, w, t.byteLength, `DXBS section ${d}`), m.set(d, { type: d, flags: p, offset: y, length: w });
350
350
  }
351
351
  return { versionMajor: n, versionMinor: r, sections: m };
352
352
  }
353
- function an(t, e, n) {
353
+ function pn(t, e, n) {
354
354
  const r = t.sections.get(e);
355
355
  if (!r)
356
- throw new l("E_GROUP_RANGE", `Missing DXBS section ${n}`);
356
+ throw new f("E_GROUP_RANGE", `Missing DXBS section ${n}`);
357
357
  return r;
358
358
  }
359
- function cn() {
359
+ function bn() {
360
360
  return {
361
361
  pos: new Float32Array(0),
362
362
  count: 0,
363
363
  segments: []
364
364
  };
365
365
  }
366
- function Pt(t) {
366
+ function Ot(t) {
367
367
  if (t.segments && t.segments.length > 0)
368
- return ln(t.segments, t.count), t.segments;
368
+ return In(t.segments, t.count), t.segments;
369
369
  if (t.count <= 0) return [];
370
370
  if (!t.col || !t.lay)
371
- throw new l("E_GROUP_RANGE", "Geometry chunk is missing segment or expanded color/layer metadata");
372
- return un(t.col, t.lay, t.count);
371
+ throw new f("E_GROUP_RANGE", "Geometry chunk is missing segment or expanded color/layer metadata");
372
+ return An(t.col, t.lay, t.count);
373
373
  }
374
- function ee(t) {
374
+ function ae(t) {
375
375
  const e = [];
376
376
  for (const n of t) {
377
377
  const r = e[e.length - 1];
@@ -385,66 +385,67 @@ function ee(t) {
385
385
  e.push({
386
386
  startVertex: n.startVertex,
387
387
  vertexCount: n.vertexCount,
388
- color: fn(n),
388
+ color: Rn(n),
389
389
  layerIndex: n.layerIndex,
390
390
  ...n.lineweightPx === void 0 ? {} : { lineweightPx: n.lineweightPx }
391
391
  });
392
392
  }
393
393
  return e;
394
394
  }
395
- function un(t, e, n) {
395
+ function An(t, e, n) {
396
396
  if (t.length < n * 3 || e.length < n)
397
- throw new l("E_GROUP_RANGE", "Expanded color/layer metadata is shorter than geometry count");
397
+ throw new f("E_GROUP_RANGE", "Expanded color/layer metadata is shorter than geometry count");
398
398
  const r = [];
399
399
  let s = 0;
400
400
  for (; s < n; ) {
401
- const o = s * 3, i = t[o] ?? 0, a = t[o + 1] ?? 0, c = t[o + 2] ?? 0, u = e[s] ?? 0;
401
+ const o = s * 3, i = t[o] ?? 0, a = t[o + 1] ?? 0, u = t[o + 2] ?? 0, c = e[s] ?? 0;
402
402
  let m = s + 1;
403
403
  for (; m < n; ) {
404
404
  const g = m * 3;
405
- if (e[m] !== u || t[g] !== i || t[g + 1] !== a || t[g + 2] !== c)
405
+ if (e[m] !== c || t[g] !== i || t[g + 1] !== a || t[g + 2] !== u)
406
406
  break;
407
407
  m += 1;
408
408
  }
409
409
  r.push({
410
410
  startVertex: s,
411
411
  vertexCount: m - s,
412
- color: [i, a, c],
413
- layerIndex: u
412
+ color: [i, a, u],
413
+ layerIndex: c
414
414
  }), s = m;
415
415
  }
416
416
  return r;
417
417
  }
418
- function ln(t, e) {
418
+ function In(t, e) {
419
419
  let n = 0;
420
420
  for (const r of t) {
421
421
  if (r.vertexCount < 0 || r.startVertex !== n)
422
- throw new l("E_SEGMENT_SUM", "Geometry segments must be contiguous and non-negative");
422
+ throw new f("E_SEGMENT_SUM", "Geometry segments must be contiguous and non-negative");
423
423
  n += r.vertexCount;
424
424
  }
425
425
  if (n !== e)
426
- throw new l("E_SEGMENT_SUM", `Geometry segment vertex sum ${n} does not match count ${e}`);
426
+ throw new f("E_SEGMENT_SUM", `Geometry segment vertex sum ${n} does not match count ${e}`);
427
427
  }
428
- function fn(t) {
428
+ function Rn(t) {
429
429
  return [t.color[0], t.color[1], t.color[2]];
430
430
  }
431
- const dn = 8e6, Ot = be(), mn = ["left", "center", "right"], hn = ["top", "middle", "bottom", "alphabetic"];
432
- function ne(t, e, n) {
431
+ const Vn = 8e6, Lt = Ue(), Gn = ["left", "center", "right"], Nn = ["top", "middle", "bottom", "alphabetic"];
432
+ function ue(t, e, n) {
433
433
  for (const r of t)
434
434
  n(r);
435
435
  for (const r of e)
436
436
  n(r);
437
437
  }
438
- function rt(t) {
438
+ const Te = /* @__PURE__ */ new WeakSet();
439
+ function st(t) {
439
440
  return typeof t == "object" && t !== null;
440
441
  }
441
- function gn(t) {
442
+ function Un(t) {
442
443
  return Array.isArray(t) ? "array" : t === null ? "null" : typeof t;
443
444
  }
444
- function yn(t) {
445
- return !(!rt(t) || Array.isArray(t) || typeof t.t != "string" || typeof t.x != "number" || typeof t.y != "number" || typeof t.h != "number" || typeof t.r != "number" || !Array.isArray(t.c) || t.c.length !== 3 || !t.c.every((e) => typeof e == "number") || typeof t.li != "number" || t.ha !== "left" && t.ha !== "center" && t.ha !== "right" || t.va !== "top" && t.va !== "middle" && t.va !== "bottom" && t.va !== "alphabetic" || typeof t.lh != "number" || t.w !== void 0 && typeof t.w != "number" || t.wf !== void 0 && typeof t.wf != "number" || t.iv !== void 0 && typeof t.iv != "number" || t.io !== void 0 && typeof t.io != "number" || t.mx !== void 0 && t.mx !== !0 || t.my !== void 0 && t.my !== !0);
445
+ function Cn(t) {
446
+ return !(!st(t) || Array.isArray(t) || typeof t.t != "string" || typeof t.x != "number" || typeof t.y != "number" || typeof t.h != "number" || typeof t.r != "number" || !Array.isArray(t.c) || t.c.length !== 3 || !t.c.every((e) => typeof e == "number") || typeof t.li != "number" || t.ha !== "left" && t.ha !== "center" && t.ha !== "right" || t.va !== "top" && t.va !== "middle" && t.va !== "bottom" && t.va !== "alphabetic" || typeof t.lh != "number" || t.w !== void 0 && typeof t.w != "number" || t.wf !== void 0 && typeof t.wf != "number" || t.iv !== void 0 && typeof t.iv != "number" || t.io !== void 0 && typeof t.io != "number" || t.mx !== void 0 && t.mx !== !0 || t.my !== void 0 && t.my !== !0);
446
447
  }
447
- function _n(t) {
448
+ function Sn(t) {
448
449
  return t.map((e, n) => ({
449
450
  index: n,
450
451
  name: e.name,
@@ -453,26 +454,26 @@ function _n(t) {
453
454
  visible: e.visible ?? !0
454
455
  }));
455
456
  }
456
- function Re(t) {
457
- const e = t.texts, n = Array.isArray(e) ? e : [], r = n.filter(yn), s = nn();
457
+ function Pe(t) {
458
+ const e = t.texts, n = Array.isArray(e) ? e : [], r = n.filter(Cn), s = _n();
458
459
  if (s && e !== void 0 && !Array.isArray(e))
459
- throw new l(
460
+ throw new f(
460
461
  "E_TEXT_ROUNDTRIP",
461
- `Text roundtrip mismatch at stage=Boundary-2:header->stream index=0 path=$: expected array but found ${gn(e)}`
462
+ `Text roundtrip mismatch at stage=Boundary-2:header->stream index=0 path=$: expected array but found ${Un(e)}`
462
463
  );
463
- return s && rn("Boundary-2:header->stream", n, r), {
464
+ return s && xn("Boundary-2:header->stream", n, r), {
464
465
  bounds: [...t.bounds],
465
466
  entityCount: Number(t.entity_count || 0),
466
467
  lineCount: Number(t.line_count || 0),
467
468
  fillCount: Number(t.fill_count || 0),
468
469
  dotCount: Number(t.dot_count || 0),
469
470
  textCount: r.length,
470
- layers: _n(t.layers ?? []),
471
+ layers: Sn(t.layers ?? []),
471
472
  texts: r
472
473
  };
473
474
  }
474
- function xn(t) {
475
- const e = t == null ? void 0 : t.maxExpandedInstanceVertices, n = typeof e == "number" && Number.isFinite(e) && e >= 0 ? Math.floor(e) : dn;
475
+ function Tn(t) {
476
+ const e = t == null ? void 0 : t.maxExpandedInstanceVertices, n = typeof e == "number" && Number.isFinite(e) && e >= 0 ? Math.floor(e) : Vn;
476
477
  return {
477
478
  hiddenInstanceIds: t != null && t.hiddenInstanceIds ? new Set(t.hiddenInstanceIds) : /* @__PURE__ */ new Set(),
478
479
  keepTextsForHiddenInstances: (t == null ? void 0 : t.keepTextsForHiddenInstances) === !0,
@@ -483,27 +484,28 @@ function xn(t) {
483
484
  externalVariantBuffers: t == null ? void 0 : t.externalVariantBuffers,
484
485
  requiredExternalVariantIds: t == null ? void 0 : t.requiredExternalVariantIds,
485
486
  externalVariantDeltaOnly: (t == null ? void 0 : t.externalVariantDeltaOnly) === !0,
486
- deferExternalVariantGeometry: (t == null ? void 0 : t.deferExternalVariantGeometry) === !0
487
+ deferExternalVariantGeometry: (t == null ? void 0 : t.deferExternalVariantGeometry) === !0,
488
+ cacheDocument: (t == null ? void 0 : t.cacheDocument) === !0
487
489
  };
488
490
  }
489
- function En(t) {
491
+ function Pn(t) {
490
492
  return t.loadBlocks && !t.suppressExpandedInsertGeometry;
491
493
  }
492
- function Ve(t, e) {
493
- return En(e) && !e.hiddenInstanceIds.has(t);
494
+ function Be(t, e) {
495
+ return Pn(e) && !e.hiddenInstanceIds.has(t);
494
496
  }
495
- function wn(t, e, n) {
497
+ function Bn(t, e, n) {
496
498
  if (n <= 0)
497
499
  return;
498
500
  const r = t.expandedInstanceVertices + n;
499
501
  if (r > t.maxExpandedInstanceVertices)
500
- throw new l(
502
+ throw new f(
501
503
  "E_EXPANSION_BUDGET",
502
504
  `CPU-expanded ${e} instance vertices exceed budget: ${r}/${t.maxExpandedInstanceVertices}. Disable block loading or raise maxExpandedInstanceVertices.`
503
505
  );
504
506
  t.expandedInstanceVertices = r;
505
507
  }
506
- function pn(t, e, n) {
508
+ function $n(t, e, n) {
507
509
  return n.loadBlocks ? n.hiddenInstanceIds.size === 0 || n.keepTextsForHiddenInstances ? t : t.filter((r) => {
508
510
  if (!Number.isInteger(r.iv) || !Number.isInteger(r.io))
509
511
  return !0;
@@ -511,7 +513,7 @@ function pn(t, e, n) {
511
513
  return s === void 0 || !n.hiddenInstanceIds.has(s);
512
514
  }) : t.filter((r) => !Number.isInteger(r.iv) || !Number.isInteger(r.io));
513
515
  }
514
- function bn(t, e) {
516
+ function vn(t, e) {
515
517
  const n = /* @__PURE__ */ new Map();
516
518
  return t.forEach((r, s) => {
517
519
  if (!Number.isInteger(r.iv) || !Number.isInteger(r.io))
@@ -523,43 +525,43 @@ function bn(t, e) {
523
525
  i ? i.push(s) : n.set(o, [s]);
524
526
  }), n;
525
527
  }
526
- function An(t, e, n, r, s, o, i) {
527
- const a = e.map((c, u) => ({
528
- id: c.id,
529
- blockName: Ne(c, u),
530
- line: n[u].line,
531
- fill: n[u].fill,
532
- dot: n[u].dot,
533
- texts: r.get(c.id) ?? []
528
+ function On(t, e, n, r, s, o, i) {
529
+ const a = e.map((u, c) => ({
530
+ id: u.id,
531
+ blockName: $e(u, c),
532
+ line: n[c].line,
533
+ fill: n[c].fill,
534
+ dot: n[c].dot,
535
+ texts: r.get(u.id) ?? []
534
536
  }));
535
537
  return {
536
538
  layer0Index: t,
537
539
  variants: a,
538
540
  instances: s,
539
- textIndexesByInstanceId: bn(o, i),
541
+ textIndexesByInstanceId: vn(o, i),
540
542
  ownerInstanceIdByVariantOrdinal: i
541
543
  };
542
544
  }
543
- function In(t) {
545
+ function Mn(t) {
544
546
  if (t.byteLength < 4)
545
- throw new l("E_HEADER", "Payload too small: missing header length");
547
+ throw new f("E_HEADER", "Payload too small: missing header length");
546
548
  const e = new DataView(t), n = e.getUint32(0, !0), r = 4, s = r + n;
547
549
  if (s > t.byteLength)
548
- throw new l("E_HEADER", "Header length exceeds payload length");
550
+ throw new f("E_HEADER", "Header length exceeds payload length");
549
551
  let o;
550
552
  try {
551
- o = JSON.parse(Ot.decode(new Uint8Array(t, r, n)));
553
+ o = JSON.parse(Lt.decode(new Uint8Array(t, r, n)));
552
554
  } catch (i) {
553
- throw new l("E_HEADER_JSON", `Invalid JSON header: ${i.message}`);
555
+ throw new f("E_HEADER_JSON", `Invalid JSON header: ${i.message}`);
554
556
  }
555
557
  return {
556
558
  meta: o,
557
- header: Re(o),
559
+ header: Pe(o),
558
560
  dataOffset: s,
559
561
  view: e
560
562
  };
561
563
  }
562
- function Ne(t, e) {
564
+ function $e(t, e) {
563
565
  var o, i, a;
564
566
  const n = (o = t.name) == null ? void 0 : o.trim();
565
567
  if (n)
@@ -570,145 +572,145 @@ function Ne(t, e) {
570
572
  const s = (a = t.blockName) == null ? void 0 : a.trim();
571
573
  return s || `block_${e}`;
572
574
  }
573
- function Rn(t) {
575
+ function kn(t) {
574
576
  const e = Number(t.version ?? 1), n = String(t.encoding ?? "").toLowerCase();
575
577
  if (e === 2) {
576
578
  const r = n ? ` ${n}` : "";
577
- throw new l(
579
+ throw new f(
578
580
  "E_UNSUPPORTED_PACK_VERSION",
579
581
  `当前文件是 V2${r} pack,前端不再兼容解析;请升级到最新版本后再打开。`
580
582
  );
581
583
  }
582
584
  }
583
- function Vn(t) {
584
- const e = In(t);
585
- return Rn(e.meta), e;
585
+ function Dn(t) {
586
+ const e = Mn(t);
587
+ return kn(e.meta), e;
586
588
  }
587
- function Nn(t) {
589
+ function ve(t) {
588
590
  if (t.byteLength < 4)
589
591
  return !1;
590
592
  const e = new Uint8Array(t, 0, 4);
591
593
  return e[0] === 68 && e[1] === 88 && e[2] === 66 && e[3] === 51;
592
594
  }
593
- function re(t, e) {
595
+ function le(t, e) {
594
596
  if (t > BigInt(Number.MAX_SAFE_INTEGER))
595
- throw new l("E_GROUP_RANGE", `${e} exceeds safe integer range`);
597
+ throw new f("E_GROUP_RANGE", `${e} exceeds safe integer range`);
596
598
  return Number(t);
597
599
  }
598
- function st(t, e, n, r) {
600
+ function at(t, e, n, r) {
599
601
  if (!Number.isInteger(t) || !Number.isInteger(e) || t < 0 || e < 0 || t + e > n)
600
- throw new l("E_GROUP_RANGE", `${r} exceeds payload length`);
602
+ throw new f("E_GROUP_RANGE", `${r} exceeds payload length`);
601
603
  }
602
- function Gn(t) {
604
+ function Ln(t) {
603
605
  if (t.byteLength < 20)
604
- throw new l("E_HEADER", "V3 payload too small: missing container header");
606
+ throw new f("E_HEADER", "V3 payload too small: missing container header");
605
607
  const e = new DataView(t), n = e.getUint16(4, !0), r = e.getUint16(6, !0), s = e.getUint32(8, !0), o = e.getUint16(12, !0), i = e.getUint16(14, !0), a = e.getUint32(16, !0);
606
608
  if (n !== 3 || r > 6)
607
- throw new l("E_GROUP_RANGE", `Unsupported V3 version: ${n}.${r}`);
609
+ throw new f("E_GROUP_RANGE", `Unsupported V3 version: ${n}.${r}`);
608
610
  if (s !== 0)
609
- throw new l("E_GROUP_RANGE", `Unsupported V3 file flags: ${s}`);
611
+ throw new f("E_GROUP_RANGE", `Unsupported V3 file flags: ${s}`);
610
612
  if (o < 24)
611
- throw new l("E_GROUP_RANGE", `Invalid V3 directory entry size: ${o}`);
613
+ throw new f("E_GROUP_RANGE", `Invalid V3 directory entry size: ${o}`);
612
614
  if (a !== o * i)
613
- throw new l("E_GROUP_RANGE", "V3 directory byte size mismatch");
614
- const c = 20;
615
- st(c, a, t.byteLength, "V3 section directory");
616
- const u = /* @__PURE__ */ new Map();
615
+ throw new f("E_GROUP_RANGE", "V3 directory byte size mismatch");
616
+ const u = 20;
617
+ at(u, a, t.byteLength, "V3 section directory");
618
+ const c = /* @__PURE__ */ new Map();
617
619
  for (let m = 0; m < i; m += 1) {
618
- const g = c + m * o, d = e.getUint16(g, !0), h = e.getUint16(g + 2, !0), w = e.getUint32(g + 4, !0), y = re(e.getBigUint64(g + 8, !0), "V3 section offset"), f = re(e.getBigUint64(g + 16, !0), "V3 section length");
619
- if (h !== 0)
620
- throw new l("E_GROUP_RANGE", `Unsupported V3 section flags for type ${d}: ${h}`);
621
- if (w !== 0)
622
- throw new l("E_GROUP_RANGE", `Invalid V3 section reserved field for type ${d}: ${w}`);
623
- st(y, f, t.byteLength, `V3 section ${d}`), u.set(d, { type: d, flags: h, offset: y, length: f });
620
+ const g = u + m * o, l = e.getUint16(g, !0), d = e.getUint16(g + 2, !0), p = e.getUint32(g + 4, !0), h = le(e.getBigUint64(g + 8, !0), "V3 section offset"), y = le(e.getBigUint64(g + 16, !0), "V3 section length");
621
+ if (d !== 0)
622
+ throw new f("E_GROUP_RANGE", `Unsupported V3 section flags for type ${l}: ${d}`);
623
+ if (p !== 0)
624
+ throw new f("E_GROUP_RANGE", `Invalid V3 section reserved field for type ${l}: ${p}`);
625
+ at(h, y, t.byteLength, `V3 section ${l}`), c.set(l, { type: l, flags: d, offset: h, length: y });
624
626
  }
625
- return { versionMinor: r, sections: u };
627
+ return { versionMinor: r, sections: c };
626
628
  }
627
- function Q(t, e, n) {
629
+ function tt(t, e, n) {
628
630
  const r = t.get(e);
629
631
  if (!r)
630
- throw new l("E_GROUP_RANGE", `Missing V3 section ${n}`);
632
+ throw new f("E_GROUP_RANGE", `Missing V3 section ${n}`);
631
633
  return r;
632
634
  }
633
- function _t(t, e) {
635
+ function pt(t, e) {
634
636
  return t.get(e) ?? { type: e, flags: 0, offset: 0, length: 0 };
635
637
  }
636
- function Un(t, e, n) {
638
+ function Fn(t, e, n) {
637
639
  try {
638
- return JSON.parse(Ot.decode(new Uint8Array(t, e.offset, e.length)));
640
+ return JSON.parse(Lt.decode(new Uint8Array(t, e.offset, e.length)));
639
641
  } catch (r) {
640
- throw new l("E_HEADER_JSON", `Invalid V3 ${n} JSON: ${r.message}`);
642
+ throw new f("E_HEADER_JSON", `Invalid V3 ${n} JSON: ${r.message}`);
641
643
  }
642
644
  }
643
- function Cn(t) {
645
+ function Xn(t) {
644
646
  const e = String(t.encoding ?? "").toLowerCase();
645
647
  return e === "nested_instanced_external" || e === "nested_instanced_external_annotations";
646
648
  }
647
- function Sn(t) {
649
+ function Yn(t) {
648
650
  return String(t.encoding ?? "").toLowerCase() === "nested_instanced_external_annotations";
649
651
  }
650
- function Pn(t, e, n) {
652
+ function zn(t, e, n) {
651
653
  const r = t.features, s = r && typeof r == "object" && !Array.isArray(r) ? { ...r } : {};
652
654
  return e && (s.has_external_variant_geometry = !0), n && (s.has_external_annotations = !0), Object.keys(s).length ? s : void 0;
653
655
  }
654
- function L(t, e) {
656
+ function Y(t, e) {
655
657
  if (!Number.isInteger(t) || Number(t) < 0)
656
- throw new l("E_HEADER", `${e} must be a non-negative integer`);
658
+ throw new f("E_HEADER", `${e} must be a non-negative integer`);
657
659
  return Number(t);
658
660
  }
659
- function Ge(t, e) {
661
+ function Oe(t, e) {
660
662
  if (typeof t != "string" || !t.trim())
661
- throw new l("E_HEADER", `${e} must be a non-empty string`);
663
+ throw new f("E_HEADER", `${e} must be a non-empty string`);
662
664
  return t;
663
665
  }
664
- function oe(t, e) {
666
+ function ce(t, e) {
665
667
  if (t == null)
666
668
  return null;
667
669
  if (!Array.isArray(t) || t.length !== 4 || t.some((n) => typeof n != "number" || !Number.isFinite(n)))
668
- throw new l("E_HEADER", `${e} must be null or [minX, minY, maxX, maxY]`);
670
+ throw new f("E_HEADER", `${e} must be null or [minX, minY, maxX, maxY]`);
669
671
  return [t[0], t[1], t[2], t[3]];
670
672
  }
671
- function Tt(t, e) {
672
- if (!rt(t) || Array.isArray(t))
673
- throw new l("E_HEADER", `${e} must be an object`);
673
+ function Mt(t, e) {
674
+ if (!st(t) || Array.isArray(t))
675
+ throw new f("E_HEADER", `${e} must be an object`);
674
676
  return {
675
- line_count: L(t.line_count, `${e}.line_count`),
676
- fill_count: L(t.fill_count, `${e}.fill_count`),
677
- dot_count: L(t.dot_count, `${e}.dot_count`),
678
- bbox: oe(t.bbox, `${e}.bbox`),
679
- own_bbox: oe(t.own_bbox, `${e}.own_bbox`)
677
+ line_count: Y(t.line_count, `${e}.line_count`),
678
+ fill_count: Y(t.fill_count, `${e}.fill_count`),
679
+ dot_count: Y(t.dot_count, `${e}.dot_count`),
680
+ bbox: ce(t.bbox, `${e}.bbox`),
681
+ own_bbox: ce(t.own_bbox, `${e}.own_bbox`)
680
682
  };
681
683
  }
682
- function Tn(t) {
684
+ function Hn(t) {
683
685
  return t ? { minX: t[0], minY: t[1], maxX: t[2], maxY: t[3] } : null;
684
686
  }
685
- function Bn(t, e) {
687
+ function Kn(t, e) {
686
688
  const n = t.external_variants;
687
689
  if (!Array.isArray(n))
688
- throw new l("E_HEADER", "V3 external SCENE_META.external_variants must be an array");
690
+ throw new f("E_HEADER", "V3 external SCENE_META.external_variants must be an array");
689
691
  if (n.length !== e)
690
- throw new l(
692
+ throw new f(
691
693
  "E_GROUP_RANGE",
692
694
  `V3 external variant manifest count mismatch: manifest=${n.length}, table=${e}`
693
695
  );
694
696
  return n.map((r, s) => {
695
- if (!rt(r) || Array.isArray(r))
696
- throw new l("E_HEADER", `V3 external_variants[${s}] must be an object`);
697
- const o = L(r.id, `V3 external_variants[${s}].id`);
697
+ if (!st(r) || Array.isArray(r))
698
+ throw new f("E_HEADER", `V3 external_variants[${s}] must be an object`);
699
+ const o = Y(r.id, `V3 external_variants[${s}].id`);
698
700
  if (o !== s)
699
- throw new l("E_GROUP_RANGE", `V3 external_variants[${s}].id must equal ${s}, found ${o}`);
700
- const i = Ge(r.href, `V3 external_variants[${s}].href`), a = L(r.raw_size, `V3 external_variants[${s}].raw_size`);
701
+ throw new f("E_GROUP_RANGE", `V3 external_variants[${s}].id must equal ${s}, found ${o}`);
702
+ const i = Oe(r.href, `V3 external_variants[${s}].href`), a = Y(r.raw_size, `V3 external_variants[${s}].raw_size`);
701
703
  if ("normal" in r || "annotation" in r) {
702
- const c = Tt(r.annotation, `V3 external_variants[${s}].annotation`);
704
+ const u = Mt(r.annotation, `V3 external_variants[${s}].annotation`);
703
705
  return {
704
706
  id: o,
705
707
  href: i,
706
708
  raw_size: a,
707
- normal: Tt(r.normal, `V3 external_variants[${s}].normal`),
709
+ normal: Mt(r.normal, `V3 external_variants[${s}].normal`),
708
710
  annotation: {
709
- ...c,
710
- text_count: L(
711
- rt(r.annotation) && !Array.isArray(r.annotation) ? r.annotation.text_count : void 0,
711
+ ...u,
712
+ text_count: Y(
713
+ st(r.annotation) && !Array.isArray(r.annotation) ? r.annotation.text_count : void 0,
712
714
  `V3 external_variants[${s}].annotation.text_count`
713
715
  )
714
716
  }
@@ -718,42 +720,42 @@ function Bn(t, e) {
718
720
  id: o,
719
721
  href: i,
720
722
  raw_size: a,
721
- line_count: L(r.line_count, `V3 external_variants[${s}].line_count`),
722
- fill_count: L(r.fill_count, `V3 external_variants[${s}].fill_count`),
723
- dot_count: L(r.dot_count, `V3 external_variants[${s}].dot_count`)
723
+ line_count: Y(r.line_count, `V3 external_variants[${s}].line_count`),
724
+ fill_count: Y(r.fill_count, `V3 external_variants[${s}].fill_count`),
725
+ dot_count: Y(r.dot_count, `V3 external_variants[${s}].dot_count`)
724
726
  };
725
727
  });
726
728
  }
727
- function $n(t) {
729
+ function jn(t) {
728
730
  const e = t.external_annotations;
729
731
  if (e == null) return null;
730
- if (!rt(e) || Array.isArray(e))
731
- throw new l("E_HEADER", "V3 external_annotations must be an object");
732
+ if (!st(e) || Array.isArray(e))
733
+ throw new f("E_HEADER", "V3 external_annotations must be an object");
732
734
  const n = e.scene;
733
735
  if (n == null) return {};
734
- if (!rt(n) || Array.isArray(n))
735
- throw new l("E_HEADER", "V3 external_annotations.scene must be an object");
736
- const r = Tt(n, "V3 external_annotations.scene");
736
+ if (!st(n) || Array.isArray(n))
737
+ throw new f("E_HEADER", "V3 external_annotations.scene must be an object");
738
+ const r = Mt(n, "V3 external_annotations.scene");
737
739
  return {
738
740
  scene: {
739
- href: Ge(n.href, "V3 external_annotations.scene.href"),
740
- raw_size: L(n.raw_size, "V3 external_annotations.scene.raw_size"),
741
+ href: Oe(n.href, "V3 external_annotations.scene.href"),
742
+ raw_size: Y(n.raw_size, "V3 external_annotations.scene.raw_size"),
741
743
  ...r,
742
- text_count: L(n.text_count, "V3 external_annotations.scene.text_count")
744
+ text_count: Y(n.text_count, "V3 external_annotations.scene.text_count")
743
745
  }
744
746
  };
745
747
  }
746
- function ht(t, e, n, r) {
747
- return st(e, n, t.byteLength, r), Ot.decode(t.subarray(e, e + n));
748
+ function _t(t, e, n, r) {
749
+ return at(e, n, t.byteLength, r), Lt.decode(t.subarray(e, e + n));
748
750
  }
749
- function On(t, e, n) {
751
+ function Wn(t, e, n) {
750
752
  if (e.length % 20 !== 0)
751
- throw new l("E_GROUP_RANGE", "V3 LAYER_TABLE length must be a multiple of 20");
753
+ throw new f("E_GROUP_RANGE", "V3 LAYER_TABLE length must be a multiple of 20");
752
754
  const r = new DataView(t), s = [];
753
755
  for (let o = e.offset; o < e.offset + e.length; o += 20) {
754
756
  const i = r.getUint32(o, !0), a = r.getUint32(o + 4, !0);
755
757
  s.push({
756
- name: ht(n, i, a, "V3 layer name"),
758
+ name: _t(n, i, a, "V3 layer name"),
757
759
  color: [r.getUint8(o + 8), r.getUint8(o + 9), r.getUint8(o + 10)],
758
760
  visible: r.getUint8(o + 11) !== 0,
759
761
  lw_px: r.getFloat32(o + 12, !0)
@@ -761,19 +763,19 @@ function On(t, e, n) {
761
763
  }
762
764
  return s;
763
765
  }
764
- function ft(t, e, n, r, s, o) {
766
+ function gt(t, e, n, r, s, o) {
765
767
  if (n + 4 > r)
766
- throw new l("E_GROUP_RANGE", `Missing ${s} vertex_count`);
767
- const i = e.getUint32(n, !0), a = n + 4, c = pe(t, e, a, i, r, o);
768
- if (c.offset > r)
769
- throw new l("E_GROUP_RANGE", `${s} exceeds section bounds`);
768
+ throw new f("E_GROUP_RANGE", `Missing ${s} vertex_count`);
769
+ const i = e.getUint32(n, !0), a = n + 4, u = Ne(t, e, a, i, r, o);
770
+ if (u.offset > r)
771
+ throw new f("E_GROUP_RANGE", `${s} exceeds section bounds`);
770
772
  return {
771
- chunk: c.chunk,
772
- offset: c.offset
773
+ chunk: u.chunk,
774
+ offset: u.offset
773
775
  };
774
776
  }
775
- function Ue(t, e, n, r, s, o) {
776
- const i = ft(t, e, n, r, s, o), a = n + 4;
777
+ function Me(t, e, n, r, s, o) {
778
+ const i = gt(t, e, n, r, s, o), a = n + 4;
777
779
  return {
778
780
  chunk: i.chunk,
779
781
  snapshot: {
@@ -784,33 +786,33 @@ function Ue(t, e, n, r, s, o) {
784
786
  offset: i.offset
785
787
  };
786
788
  }
787
- function dt(t = "u8") {
789
+ function yt(t = "u8") {
788
790
  return {
789
791
  chunk: { pos: new Float32Array(0), col: new Uint8Array(0), lay: new Uint8Array(0), count: 0 },
790
792
  snapshot: { count: 0, raw: new Uint8Array(0), groupLayerEncoding: t }
791
793
  };
792
794
  }
793
- function Mn(t = "u8") {
795
+ function ke(t = "u8") {
794
796
  return {
795
- line: dt(t),
796
- fill: dt(t),
797
- dot: dt(t)
797
+ line: yt(t),
798
+ fill: yt(t),
799
+ dot: yt(t)
798
800
  };
799
801
  }
800
- function vn(t, e, n) {
802
+ function De(t, e, n) {
801
803
  var r;
802
804
  return !!(e && n && t.deferExternalVariantGeometry && !((r = t.externalVariantBuffers) != null && r.has(e.id)));
803
805
  }
804
- function xt(t, e, n, r, s, o, i) {
806
+ function bt(t, e, n, r, s, o, i) {
805
807
  if (s === 0)
806
- return dt(i);
807
- st(r, s, n.length, o);
808
- const a = n.offset + r, c = a + s, u = Ue(t, e, a, c, o, i);
809
- if (u.offset !== c)
810
- throw new l("E_GROUP_RANGE", `${o} has trailing bytes`);
811
- return { chunk: u.chunk, snapshot: u.snapshot };
812
- }
813
- function Ce(t, e, n) {
808
+ return yt(i);
809
+ at(r, s, n.length, o);
810
+ const a = n.offset + r, u = a + s, c = Me(t, e, a, u, o, i);
811
+ if (c.offset !== u)
812
+ throw new f("E_GROUP_RANGE", `${o} has trailing bytes`);
813
+ return { chunk: c.chunk, snapshot: c.snapshot };
814
+ }
815
+ function Ft(t, e, n) {
814
816
  if ([
815
817
  t.getUint32(e + 8, !0),
816
818
  t.getUint32(e + 12, !0),
@@ -819,205 +821,232 @@ function Ce(t, e, n) {
819
821
  t.getUint32(e + 24, !0),
820
822
  t.getUint32(e + 28, !0)
821
823
  ].some((s) => s !== 0))
822
- throw new l("E_GROUP_RANGE", `V3 external variant ${n} must use zero inline geometry offsets`);
824
+ throw new f("E_GROUP_RANGE", `V3 external variant ${n} must use zero inline geometry offsets`);
823
825
  }
824
- function nt(t, e, n, r, s, o) {
825
- const i = Ue(t, e, n, t.byteLength, s, o);
826
+ function ot(t, e, n, r, s, o) {
827
+ const i = Me(t, e, n, t.byteLength, s, o);
826
828
  if (i.chunk.count !== r)
827
- throw new l(
829
+ throw new f(
828
830
  "E_GROUP_RANGE",
829
831
  `${s} vertex_count mismatch: manifest=${r}, sidecar=${i.chunk.count}`
830
832
  );
831
833
  return i;
832
834
  }
833
- function Mt(t) {
835
+ function xt(t) {
834
836
  return "normal" in t ? t.normal : t;
835
837
  }
836
- function Dn(t, e, n) {
837
- const r = Mt(t), s = new DataView(e);
838
+ function qn(t, e, n) {
839
+ const r = xt(t), s = new DataView(e);
838
840
  let o = 0;
839
- const i = nt(e, s, o, r.line_count, `V3 external variant ${t.id} line blob`, n);
841
+ const i = ot(e, s, o, r.line_count, `V3 external variant ${t.id} line blob`, n);
840
842
  o = i.offset;
841
- const a = nt(e, s, o, r.fill_count, `V3 external variant ${t.id} fill blob`, n);
843
+ const a = ot(e, s, o, r.fill_count, `V3 external variant ${t.id} fill blob`, n);
842
844
  o = a.offset;
843
- const c = nt(e, s, o, r.dot_count, `V3 external variant ${t.id} dot blob`, n);
844
- if (o = c.offset, o !== e.byteLength)
845
- throw new l("E_GROUP_RANGE", `V3 external variant ${t.id} sidecar has trailing bytes`);
845
+ const u = ot(e, s, o, r.dot_count, `V3 external variant ${t.id} dot blob`, n);
846
+ if (o = u.offset, o !== e.byteLength)
847
+ throw new f("E_GROUP_RANGE", `V3 external variant ${t.id} sidecar has trailing bytes`);
846
848
  return {
847
849
  line: { chunk: i.chunk, snapshot: i.snapshot },
848
850
  fill: { chunk: a.chunk, snapshot: a.snapshot },
849
- dot: { chunk: c.chunk, snapshot: c.snapshot }
851
+ dot: { chunk: u.chunk, snapshot: u.snapshot }
850
852
  };
851
853
  }
852
- function kn(t, e) {
853
- const n = sn(e), r = an(n, 257, "BLOCK_NORMAL_GEOMETRY"), s = new DataView(e);
854
+ function Jn(t, e) {
855
+ const n = wn(e), r = pn(n, 257, "BLOCK_NORMAL_GEOMETRY"), s = new DataView(e);
854
856
  let o = r.offset;
855
- const i = r.offset + r.length, a = _e(n.versionMinor), c = nt(e, s, o, t.normal.line_count, `V3.3 external variant ${t.id} normal line blob`, a);
856
- o = c.offset;
857
- const u = nt(e, s, o, t.normal.fill_count, `V3.3 external variant ${t.id} normal fill blob`, a);
857
+ const i = r.offset + r.length, a = Ie(n.versionMinor), u = ot(e, s, o, t.normal.line_count, `V3.3 external variant ${t.id} normal line blob`, a);
858
858
  o = u.offset;
859
- const m = nt(e, s, o, t.normal.dot_count, `V3.3 external variant ${t.id} normal dot blob`, a);
859
+ const c = ot(e, s, o, t.normal.fill_count, `V3.3 external variant ${t.id} normal fill blob`, a);
860
+ o = c.offset;
861
+ const m = ot(e, s, o, t.normal.dot_count, `V3.3 external variant ${t.id} normal dot blob`, a);
860
862
  if (o = m.offset, o !== i)
861
- throw new l("E_GROUP_RANGE", `V3.3 external variant ${t.id} normal geometry section has trailing bytes`);
863
+ throw new f("E_GROUP_RANGE", `V3.3 external variant ${t.id} normal geometry section has trailing bytes`);
862
864
  return {
863
- line: { chunk: c.chunk, snapshot: c.snapshot },
864
- fill: { chunk: u.chunk, snapshot: u.snapshot },
865
+ line: { chunk: u.chunk, snapshot: u.snapshot },
866
+ fill: { chunk: c.chunk, snapshot: c.snapshot },
865
867
  dot: { chunk: m.chunk, snapshot: m.snapshot }
866
868
  };
867
869
  }
868
- function Ln(t, e, n = "u8") {
870
+ function Zn(t, e, n = "u8") {
869
871
  if (e.byteLength !== t.raw_size)
870
- throw new l(
872
+ throw new f(
871
873
  "E_GROUP_RANGE",
872
874
  `V3 external variant ${t.id} raw_size mismatch: manifest=${t.raw_size}, sidecar=${e.byteLength}`
873
875
  );
874
- return "normal" in t ? kn(t, e) : Dn(t, e, n);
876
+ return "normal" in t ? Jn(t, e) : qn(t, e, n);
875
877
  }
876
- function Fn(t, e, n) {
878
+ function Le(t, e, n) {
877
879
  const r = e == null ? void 0 : e.get(t.id);
878
880
  if (!r)
879
- throw new l("E_GROUP_RANGE", `Missing V3 external sidecar buffer for variant ${t.id}`);
880
- return Ln(t, r, n);
881
+ throw new f("E_GROUP_RANGE", `Missing V3 external sidecar buffer for variant ${t.id}`);
882
+ return Zn(t, r, n);
881
883
  }
882
- function Et(t, e, n, r, s) {
884
+ function At(t, e, n, r, s) {
883
885
  if (r === 0)
884
886
  return 0;
885
- if (st(n, r, e.length, s), r < 4)
886
- throw new l("E_GROUP_RANGE", `Missing ${s} vertex_count`);
887
+ if (at(n, r, e.length, s), r < 4)
888
+ throw new f("E_GROUP_RANGE", `Missing ${s} vertex_count`);
887
889
  return t.getUint32(e.offset + n, !0);
888
890
  }
889
- function Xn(t, e, n, r) {
891
+ function Qn(t, e, n, r) {
890
892
  const s = n.offset + n.length;
891
893
  let o = n.offset;
892
- const i = ft(t, e, o, s, "V3 BASE_GEOMETRY line", r);
894
+ const i = gt(t, e, o, s, "V3 BASE_GEOMETRY line", r);
893
895
  o = i.offset;
894
- const a = ft(t, e, o, s, "V3 BASE_GEOMETRY fill", r);
896
+ const a = gt(t, e, o, s, "V3 BASE_GEOMETRY fill", r);
895
897
  o = a.offset;
896
- const c = ft(t, e, o, s, "V3 BASE_GEOMETRY dot", r);
897
- if (o = c.offset, o !== s)
898
- throw new l("E_GROUP_RANGE", "V3 BASE_GEOMETRY has trailing bytes");
898
+ const u = gt(t, e, o, s, "V3 BASE_GEOMETRY dot", r);
899
+ if (o = u.offset, o !== s)
900
+ throw new f("E_GROUP_RANGE", "V3 BASE_GEOMETRY has trailing bytes");
899
901
  return {
900
902
  line: i.chunk,
901
903
  fill: a.chunk,
902
- dot: c.chunk
904
+ dot: u.chunk
903
905
  };
904
906
  }
905
- function wt(t) {
906
- return Je(t.pos, t.count, 2);
907
+ function It(t) {
908
+ return dn(t.pos, t.count, 2);
907
909
  }
908
- function Yn(t, e, n) {
909
- return Bt(Bt(wt(t), wt(e)), wt(n));
910
+ function Fe(t, e, n) {
911
+ return kt(kt(It(t), It(e)), It(n));
910
912
  }
911
- function Se(t) {
912
- return "normal" in t ? Tn(t.normal.bbox ?? t.normal.own_bbox ?? null) : null;
913
+ function Xt(t) {
914
+ return "normal" in t ? Hn(t.normal.bbox ?? t.normal.own_bbox ?? null) : null;
913
915
  }
914
- function zn(t, e, n, r, s, o, i, a) {
916
+ function tr(t, e, n, r, s, o, i, a) {
915
917
  if (n.length % 60 !== 0)
916
- throw new l("E_GROUP_RANGE", "V3 VARIANT_TABLE length must be a multiple of 60");
917
- const c = [], u = /* @__PURE__ */ new Map(), m = [], g = n.length / 60;
918
- for (let d = 0; d < g; d += 1) {
919
- const h = n.offset + d * 60, w = e.getUint32(h, !0), y = e.getUint32(h + 4, !0), f = (o == null ? void 0 : o[d]) ?? null, x = !f || !a.requiredExternalVariantIds || a.requiredExternalVariantIds.has(d), p = vn(a, f, x), E = f ? (Ce(e, h, d), !x || p ? Mn(i) : Fn(f, a.externalVariantBuffers, i)) : {
920
- line: xt(
918
+ throw new f("E_GROUP_RANGE", "V3 VARIANT_TABLE length must be a multiple of 60");
919
+ const u = [], c = /* @__PURE__ */ new Map(), m = [], g = n.length / 60;
920
+ for (let l = 0; l < g; l += 1) {
921
+ const d = n.offset + l * 60, p = e.getUint32(d, !0), h = e.getUint32(d + 4, !0), y = (o == null ? void 0 : o[l]) ?? null, w = !y || !a.requiredExternalVariantIds || a.requiredExternalVariantIds.has(l), _ = De(a, y, w), E = y ? (Ft(e, d, l), !w || _ ? ke(i) : Le(y, a.externalVariantBuffers, i)) : {
922
+ line: bt(
921
923
  t,
922
924
  e,
923
925
  r,
924
- e.getUint32(h + 8, !0),
925
- e.getUint32(h + 12, !0),
926
- `V3 variant ${d} line blob`,
926
+ e.getUint32(d + 8, !0),
927
+ e.getUint32(d + 12, !0),
928
+ `V3 variant ${l} line blob`,
927
929
  i
928
930
  ),
929
- fill: xt(
931
+ fill: bt(
930
932
  t,
931
933
  e,
932
934
  r,
933
- e.getUint32(h + 16, !0),
934
- e.getUint32(h + 20, !0),
935
- `V3 variant ${d} fill blob`,
935
+ e.getUint32(d + 16, !0),
936
+ e.getUint32(d + 20, !0),
937
+ `V3 variant ${l} fill blob`,
936
938
  i
937
939
  ),
938
- dot: xt(
940
+ dot: bt(
939
941
  t,
940
942
  e,
941
943
  r,
942
- e.getUint32(h + 24, !0),
943
- e.getUint32(h + 28, !0),
944
- `V3 variant ${d} dot blob`,
944
+ e.getUint32(d + 24, !0),
945
+ e.getUint32(d + 28, !0),
946
+ `V3 variant ${l} dot blob`,
945
947
  i
946
948
  )
947
- }, b = f ? Mt(f) : null, P = (b == null ? void 0 : b.line_count) ?? E.line.chunk.count, N = (b == null ? void 0 : b.fill_count) ?? E.fill.chunk.count, C = (b == null ? void 0 : b.dot_count) ?? E.dot.chunk.count, G = f && (!x || p) ? Se(f) : Yn(E.line.chunk, E.fill.chunk, E.dot.chunk), U = {
948
- id: d,
949
- name: ht(s, w, y, `V3 variant ${d} name`),
950
- line_count: p ? P : E.line.chunk.count,
951
- fill_count: p ? N : E.fill.chunk.count,
952
- dot_count: p ? C : E.dot.chunk.count,
953
- sourceLineCount: P,
949
+ }, A = y ? xt(y) : null, U = (A == null ? void 0 : A.line_count) ?? E.line.chunk.count, N = (A == null ? void 0 : A.fill_count) ?? E.fill.chunk.count, C = (A == null ? void 0 : A.dot_count) ?? E.dot.chunk.count, V = y && (!w || _) ? Xt(y) : Fe(E.line.chunk, E.fill.chunk, E.dot.chunk), G = {
950
+ id: l,
951
+ name: _t(s, p, h, `V3 variant ${l} name`),
952
+ line_count: _ ? U : E.line.chunk.count,
953
+ fill_count: _ ? N : E.fill.chunk.count,
954
+ dot_count: _ ? C : E.dot.chunk.count,
955
+ sourceLineCount: U,
954
956
  sourceFillCount: N,
955
957
  sourceDotCount: C,
956
- nestedStart: e.getUint32(h + 32, !0),
957
- nestedCount: e.getUint32(h + 36, !0),
958
- textStart: e.getUint32(h + 40, !0),
959
- textCount: e.getUint32(h + 44, !0),
960
- precisionOriginX: e.getFloat32(h + 48, !0),
961
- precisionOriginY: e.getFloat32(h + 52, !0),
958
+ nestedStart: e.getUint32(d + 32, !0),
959
+ nestedCount: e.getUint32(d + 36, !0),
960
+ textStart: e.getUint32(d + 40, !0),
961
+ textCount: e.getUint32(d + 44, !0),
962
+ precisionOriginX: e.getFloat32(d + 48, !0),
963
+ precisionOriginY: e.getFloat32(d + 52, !0),
962
964
  lineSnapshot: E.line.snapshot,
963
965
  fillSnapshot: E.fill.snapshot,
964
966
  dotSnapshot: E.dot.snapshot,
965
- bbox: G
967
+ bbox: V
966
968
  };
967
- c.push(U), u.set(d, { line: E.line.chunk, fill: E.fill.chunk, dot: E.dot.chunk }), m.push({ line: E.line.snapshot, fill: E.fill.snapshot, dot: E.dot.snapshot });
969
+ u.push(G), c.set(l, { line: E.line.chunk, fill: E.fill.chunk, dot: E.dot.chunk }), m.push({ line: E.line.snapshot, fill: E.fill.snapshot, dot: E.dot.snapshot });
968
970
  }
969
- return { variantsById: c, variants: u, snapshots: m };
971
+ return { variantsById: u, variants: c, snapshots: m };
970
972
  }
971
- function Hn(t, e, n, r, s) {
973
+ function fe(t, e, n, r, s) {
972
974
  if (e.length % 60 !== 0)
973
- throw new l("E_GROUP_RANGE", "V3 VARIANT_TABLE length must be a multiple of 60");
975
+ throw new f("E_GROUP_RANGE", "V3 VARIANT_TABLE length must be a multiple of 60");
974
976
  const o = [], i = e.length / 60;
975
977
  for (let a = 0; a < i; a += 1) {
976
- const c = e.offset + a * 60, u = t.getUint32(c, !0), m = t.getUint32(c + 4, !0), g = (s == null ? void 0 : s[a]) ?? null;
977
- g && Ce(t, c, a);
978
- const d = g ? Mt(g) : null, h = t.getFloat32(c + 48, !0), w = t.getFloat32(c + 52, !0);
978
+ const u = e.offset + a * 60, c = t.getUint32(u, !0), m = t.getUint32(u + 4, !0), g = (s == null ? void 0 : s[a]) ?? null;
979
+ g && Ft(t, u, a);
980
+ const l = g ? xt(g) : null, d = t.getFloat32(u + 48, !0), p = t.getFloat32(u + 52, !0);
979
981
  o.push({
980
982
  id: a,
981
- name: ht(r, u, m, `V3 variant ${a} name`),
982
- line_count: g ? d.line_count : Et(
983
+ name: _t(r, c, m, `V3 variant ${a} name`),
984
+ line_count: g ? l.line_count : At(
983
985
  t,
984
986
  n,
985
- t.getUint32(c + 8, !0),
986
- t.getUint32(c + 12, !0),
987
+ t.getUint32(u + 8, !0),
988
+ t.getUint32(u + 12, !0),
987
989
  `V3 variant ${a} line blob`
988
990
  ),
989
- fill_count: g ? d.fill_count : Et(
991
+ fill_count: g ? l.fill_count : At(
990
992
  t,
991
993
  n,
992
- t.getUint32(c + 16, !0),
993
- t.getUint32(c + 20, !0),
994
+ t.getUint32(u + 16, !0),
995
+ t.getUint32(u + 20, !0),
994
996
  `V3 variant ${a} fill blob`
995
997
  ),
996
- dot_count: g ? d.dot_count : Et(
998
+ dot_count: g ? l.dot_count : At(
997
999
  t,
998
1000
  n,
999
- t.getUint32(c + 24, !0),
1000
- t.getUint32(c + 28, !0),
1001
+ t.getUint32(u + 24, !0),
1002
+ t.getUint32(u + 28, !0),
1001
1003
  `V3 variant ${a} dot blob`
1002
1004
  ),
1003
- nestedStart: t.getUint32(c + 32, !0),
1004
- nestedCount: t.getUint32(c + 36, !0),
1005
- textStart: t.getUint32(c + 40, !0),
1006
- textCount: t.getUint32(c + 44, !0),
1007
- precisionOriginX: h,
1008
- precisionOriginY: w,
1009
- bbox: g ? Se(g) : null
1005
+ nestedStart: t.getUint32(u + 32, !0),
1006
+ nestedCount: t.getUint32(u + 36, !0),
1007
+ textStart: t.getUint32(u + 40, !0),
1008
+ textCount: t.getUint32(u + 44, !0),
1009
+ precisionOriginX: d,
1010
+ precisionOriginY: p,
1011
+ bbox: g ? Xt(g) : null
1010
1012
  });
1011
1013
  }
1012
1014
  return o;
1013
1015
  }
1014
- function lt(t, e, n) {
1016
+ function er(t, e, n) {
1017
+ var a;
1018
+ const r = new DataView(t), s = [], o = /* @__PURE__ */ new Map(), i = [];
1019
+ for (const u of e.variantHeaders) {
1020
+ const c = ((a = e.externalVariants) == null ? void 0 : a[u.id]) ?? null, m = !c || !n.requiredExternalVariantIds || n.requiredExternalVariantIds.has(u.id), g = De(n, c, m), l = c ? (() => {
1021
+ const E = e.sections.get(5).offset + u.id * 60;
1022
+ return Ft(r, E, u.id), !m || g ? ke(e.groupLayerEncoding) : Le(c, n.externalVariantBuffers, e.groupLayerEncoding);
1023
+ })() : e.internalVariants.get(u.id);
1024
+ if (!l)
1025
+ throw new f("E_GROUP_RANGE", `Missing cached V3 variant geometry for variant ${u.id}`);
1026
+ const d = c ? xt(c) : null, p = (d == null ? void 0 : d.line_count) ?? l.line.chunk.count, h = (d == null ? void 0 : d.fill_count) ?? l.fill.chunk.count, y = (d == null ? void 0 : d.dot_count) ?? l.dot.chunk.count, w = c && (!m || g) ? Xt(c) : Fe(l.line.chunk, l.fill.chunk, l.dot.chunk), _ = {
1027
+ ...u,
1028
+ line_count: g ? p : l.line.chunk.count,
1029
+ fill_count: g ? h : l.fill.chunk.count,
1030
+ dot_count: g ? y : l.dot.chunk.count,
1031
+ sourceLineCount: p,
1032
+ sourceFillCount: h,
1033
+ sourceDotCount: y,
1034
+ lineSnapshot: l.line.snapshot,
1035
+ fillSnapshot: l.fill.snapshot,
1036
+ dotSnapshot: l.dot.snapshot,
1037
+ bbox: w
1038
+ };
1039
+ s.push(_), o.set(u.id, { line: l.line.chunk, fill: l.fill.chunk, dot: l.dot.chunk }), i.push({ line: l.line.snapshot, fill: l.fill.snapshot, dot: l.dot.snapshot });
1040
+ }
1041
+ return { variantsById: s, variants: o, snapshots: i };
1042
+ }
1043
+ function mt(t, e, n) {
1015
1044
  if (e.length % 32 !== 0)
1016
- throw new l("E_GROUP_RANGE", `${n} length must be a multiple of 32`);
1045
+ throw new f("E_GROUP_RANGE", `${n} length must be a multiple of 32`);
1017
1046
  const r = new DataView(t), s = [];
1018
1047
  for (let o = e.offset; o < e.offset + e.length; o += 32) {
1019
1048
  const i = r.getUint16(o + 30, !0);
1020
- rr(i), s.push({
1049
+ dr(i), s.push({
1021
1050
  variantId: r.getUint32(o, !0),
1022
1051
  matA: r.getFloat32(o + 4, !0),
1023
1052
  matB: r.getFloat32(o + 8, !0),
@@ -1031,39 +1060,39 @@ function lt(t, e, n) {
1031
1060
  }
1032
1061
  return s;
1033
1062
  }
1034
- function Kn(t, e, n) {
1035
- const r = t.getUint32(e, !0), s = t.getUint32(e + 4, !0), o = t.getUint8(e + 42), i = t.getUint8(e + 43), a = t.getFloat32(e + 24, !0), c = t.getFloat32(e + 28, !0);
1063
+ function nr(t, e, n) {
1064
+ const r = t.getUint32(e, !0), s = t.getUint32(e + 4, !0), o = t.getUint8(e + 42), i = t.getUint8(e + 43), a = t.getFloat32(e + 24, !0), u = t.getFloat32(e + 28, !0);
1036
1065
  return {
1037
- t: ht(n, r, s, "V3 text value"),
1066
+ t: _t(n, r, s, "V3 text value"),
1038
1067
  x: t.getFloat32(e + 8, !0),
1039
1068
  y: t.getFloat32(e + 12, !0),
1040
1069
  h: t.getFloat32(e + 16, !0),
1041
1070
  r: t.getFloat32(e + 20, !0),
1042
1071
  c: [t.getUint8(e + 36), t.getUint8(e + 37), t.getUint8(e + 38)],
1043
1072
  li: t.getUint16(e + 40, !0),
1044
- ha: mn[o & 3] ?? "left",
1045
- va: hn[o >> 2 & 3] ?? "alphabetic",
1073
+ ha: Gn[o & 3] ?? "left",
1074
+ va: Nn[o >> 2 & 3] ?? "alphabetic",
1046
1075
  lh: t.getFloat32(e + 32, !0),
1047
1076
  ...a ? { w: a } : {},
1048
- ...c !== 1 ? { wf: c } : {},
1077
+ ...u !== 1 ? { wf: u } : {},
1049
1078
  ...i & 1 ? { mx: !0 } : {},
1050
1079
  ...i & 2 ? { my: !0 } : {}
1051
1080
  };
1052
1081
  }
1053
- function pt(t, e, n, r) {
1082
+ function Rt(t, e, n, r) {
1054
1083
  if (e.length % 44 !== 0)
1055
- throw new l("E_GROUP_RANGE", `${r} length must be a multiple of 44`);
1084
+ throw new f("E_GROUP_RANGE", `${r} length must be a multiple of 44`);
1056
1085
  const s = [], o = new DataView(t);
1057
1086
  for (let i = e.offset; i < e.offset + e.length; i += 44)
1058
- s.push(Kn(o, i, n));
1087
+ s.push(nr(o, i, n));
1059
1088
  return s;
1060
1089
  }
1061
- function jn(t, e) {
1090
+ function rr(t, e) {
1062
1091
  if (t.length % 44 !== 0)
1063
- throw new l("E_GROUP_RANGE", `${e} length must be a multiple of 44`);
1092
+ throw new f("E_GROUP_RANGE", `${e} length must be a multiple of 44`);
1064
1093
  return t.length / 44;
1065
1094
  }
1066
- function Wn(t, e, n, r) {
1095
+ function or(t, e, n, r) {
1067
1096
  return {
1068
1097
  instanceId: n,
1069
1098
  variantId: e.variantId,
@@ -1076,15 +1105,15 @@ function Wn(t, e, n, r) {
1076
1105
  insLayerIdx: r
1077
1106
  };
1078
1107
  }
1079
- function qn(t, e, n, r) {
1080
- var y;
1081
- const s = ((y = r[e.insLayerIdx]) == null ? void 0 : y.visible) === !1, o = e.matA * t.x + e.matC * t.y + e.tx, i = e.matB * t.x + e.matD * t.y + e.ty, a = Math.hypot(e.matA, e.matB), c = Math.hypot(e.matC, e.matD), u = c > 1e-12 ? c : a > 1e-12 ? a : 1, m = a > 1e-12 && u > 1e-12 ? a / u : 1, g = Jn(t, e), { mx: d, my: h, ...w } = t;
1108
+ function sr(t, e, n, r) {
1109
+ var h;
1110
+ const s = ((h = r[e.insLayerIdx]) == null ? void 0 : h.visible) === !1, o = e.matA * t.x + e.matC * t.y + e.tx, i = e.matB * t.x + e.matD * t.y + e.ty, a = Math.hypot(e.matA, e.matB), u = Math.hypot(e.matC, e.matD), c = u > 1e-12 ? u : a > 1e-12 ? a : 1, m = a > 1e-12 && c > 1e-12 ? a / c : 1, g = ir(t, e), { mx: l, my: d, ...p } = t;
1082
1111
  return {
1083
- ...w,
1112
+ ...p,
1084
1113
  x: o,
1085
1114
  y: i,
1086
- h: t.h * u,
1087
- w: t.w === void 0 ? void 0 : t.w * u,
1115
+ h: t.h * c,
1116
+ w: t.w === void 0 ? void 0 : t.w * c,
1088
1117
  wf: (t.wf ?? 1) * m,
1089
1118
  r: g.r,
1090
1119
  ...g.mx ? { mx: !0 } : {},
@@ -1092,294 +1121,336 @@ function qn(t, e, n, r) {
1092
1121
  li: s || t.li === n ? e.insLayerIdx : t.li
1093
1122
  };
1094
1123
  }
1095
- function Jn(t, e) {
1096
- const n = t.r * Math.PI / 180, r = Math.cos(n), s = Math.sin(n), o = t.mx ? -1 : 1, i = t.my ? -1 : 1, a = o * (e.matA * r + e.matC * s), c = o * (e.matB * r + e.matD * s), u = i * (e.matC * r - e.matA * s), m = i * (e.matD * r - e.matB * s), g = a * m - c * u, d = Math.atan2(c, a) * 180 / Math.PI;
1097
- return g < 0 ? { r: Math.atan2(-c, -a) * 180 / Math.PI, mx: !0 } : { r: d };
1124
+ function ir(t, e) {
1125
+ const n = t.r * Math.PI / 180, r = Math.cos(n), s = Math.sin(n), o = t.mx ? -1 : 1, i = t.my ? -1 : 1, a = o * (e.matA * r + e.matC * s), u = o * (e.matB * r + e.matD * s), c = i * (e.matC * r - e.matA * s), m = i * (e.matD * r - e.matB * s), g = a * m - u * c, l = Math.atan2(u, a) * 180 / Math.PI;
1126
+ return g < 0 ? { r: Math.atan2(-u, -a) * 180 / Math.PI, mx: !0 } : { r: l };
1098
1127
  }
1099
- function Zn(t, e) {
1128
+ function ar(t, e) {
1100
1129
  return t === e ? e : t;
1101
1130
  }
1102
- function Qn(t, e, n) {
1131
+ function ur(t, e, n) {
1103
1132
  return t === n ? e : t;
1104
1133
  }
1105
- function tr(t, e) {
1106
- const n = new DataView(t), { versionMinor: r, sections: s } = Gn(t), o = _e(r), i = Q(s, 1, "SCENE_META"), a = Q(s, 2, "LAYER_TABLE"), c = Q(s, 3, "STRING_TABLE"), u = Q(s, 4, "BASE_GEOMETRY"), m = Q(s, 5, "VARIANT_TABLE"), g = Q(s, 6, "VARIANT_GEOMETRY"), d = Q(s, 7, "SCENE_INSTANCE_TABLE"), h = _t(s, 8), w = _t(s, 9), y = _t(s, 10), f = Un(t, i, "SCENE_META"), x = Cn(f) ? Bn(f, m.length / 60) : null, p = Sn(f), E = p ? $n(f) : null, b = Pn(f, x, p), P = p ? "nested_instanced_external_annotations" : x ? "nested_instanced_external" : "nested_instanced", N = new Uint8Array(t, c.offset, c.length), C = On(t, a, N), G = Number(f.layer0_index ?? 0), U = Re({
1107
- bounds: f.bounds ?? [0, 0, 0, 0],
1108
- entity_count: Number(f.entity_count ?? 0),
1109
- line_count: Number(f.base_line_count ?? 0),
1110
- fill_count: Number(f.base_fill_count ?? 0),
1111
- dot_count: Number(f.base_dot_count ?? 0),
1112
- layers: C,
1134
+ function lr(t, e, n) {
1135
+ const r = new DataView(t), s = n ? void 0 : Ln(t), o = (n == null ? void 0 : n.versionMinor) ?? s.versionMinor, i = (n == null ? void 0 : n.sections) ?? s.sections, a = (n == null ? void 0 : n.groupLayerEncoding) ?? Ie(o), u = n ? n.sections.get(1) : tt(i, 1, "SCENE_META"), c = n ? n.sections.get(2) : tt(i, 2, "LAYER_TABLE"), m = n ? n.sections.get(3) : tt(i, 3, "STRING_TABLE"), g = n ? n.sections.get(4) : tt(i, 4, "BASE_GEOMETRY"), l = n ? n.sections.get(5) : tt(i, 5, "VARIANT_TABLE"), d = n ? n.sections.get(6) : tt(i, 6, "VARIANT_GEOMETRY"), p = n ? n.sections.get(7) : tt(i, 7, "SCENE_INSTANCE_TABLE"), h = (n == null ? void 0 : n.sections.get(8)) ?? pt(i, 8), y = (n == null ? void 0 : n.sections.get(9)) ?? pt(i, 9), w = (n == null ? void 0 : n.sections.get(10)) ?? pt(i, 10), _ = (n == null ? void 0 : n.sceneMeta) ?? Fn(t, u, "SCENE_META"), E = (n == null ? void 0 : n.externalVariants) ?? (Xn(_) ? Kn(_, l.length / 60) : null), A = Yn(_), U = (n == null ? void 0 : n.externalAnnotations) ?? (A ? jn(_) : null), N = (n == null ? void 0 : n.geoMetaFeatures) ?? zn(_, E, A), C = (n == null ? void 0 : n.geoMetaEncoding) ?? (A ? "nested_instanced_external_annotations" : E ? "nested_instanced_external" : "nested_instanced"), V = (n == null ? void 0 : n.stringTable) ?? new Uint8Array(t, m.offset, m.length), G = n != null && n.layers ? [...n.layers] : Wn(t, c, V), $ = (n == null ? void 0 : n.layer0Index) ?? Number(_.layer0_index ?? 0), M = (n == null ? void 0 : n.headerForValidation) ?? Pe({
1136
+ bounds: _.bounds ?? [0, 0, 0, 0],
1137
+ entity_count: Number(_.entity_count ?? 0),
1138
+ line_count: Number(_.base_line_count ?? 0),
1139
+ fill_count: Number(_.base_fill_count ?? 0),
1140
+ dot_count: Number(_.base_dot_count ?? 0),
1141
+ layers: G,
1113
1142
  texts: []
1114
1143
  });
1115
- nr(G, U.layers);
1116
- const R = Xn(t, n, u, o);
1144
+ fr($, M.layers);
1145
+ const I = (n == null ? void 0 : n.baseGeometry) ?? Qn(t, r, g, a);
1117
1146
  if (!e.loadBlocks) {
1118
- const _ = Hn(n, m, g, N, x), A = lt(t, d, "V3 SCENE_INSTANCE_TABLE"), O = lt(t, h, "V3 NESTED_INSTANCE_TABLE"), S = pt(t, w, N, "V3 SCENE_TEXT_TABLE"), T = jn(y, "V3 VARIANT_TEXT_TABLE");
1119
- if (Number(f.variant_count ?? _.length) !== _.length)
1120
- throw new l("E_GROUP_RANGE", "V3 variant count mismatch");
1121
- if (Number(f.scene_instance_count ?? A.length) !== A.length)
1122
- throw new l("E_GROUP_RANGE", "V3 scene instance count mismatch");
1123
- if (Number(f.nested_instance_count ?? O.length) !== O.length)
1124
- throw new l("E_GROUP_RANGE", "V3 nested instance count mismatch");
1125
- if (Number(f.scene_text_count ?? S.length) !== S.length)
1126
- throw new l("E_GROUP_RANGE", "V3 scene text count mismatch");
1127
- if (Number(f.variant_text_count ?? T) !== T)
1128
- throw new l("E_GROUP_RANGE", "V3 variant text count mismatch");
1129
- for (const I of _) {
1130
- if (I.nestedStart + I.nestedCount > O.length)
1131
- throw new l("E_GROUP_RANGE", `V3 variant ${I.id} nested range exceeds table`);
1132
- if (I.textStart + I.textCount > T)
1133
- throw new l("E_GROUP_RANGE", `V3 variant ${I.id} text range exceeds table`);
1147
+ const x = (n == null ? void 0 : n.variantHeaders) ?? fe(r, l, d, V, E), b = (n == null ? void 0 : n.sceneInstances) ?? mt(t, p, "V3 SCENE_INSTANCE_TABLE"), B = (n == null ? void 0 : n.nestedInstances) ?? mt(t, h, "V3 NESTED_INSTANCE_TABLE"), S = (n == null ? void 0 : n.sceneTexts) ?? Rt(t, y, V, "V3 SCENE_TEXT_TABLE"), O = (n == null ? void 0 : n.variantTextCount) ?? rr(w, "V3 VARIANT_TEXT_TABLE");
1148
+ if (Number(_.variant_count ?? x.length) !== x.length)
1149
+ throw new f("E_GROUP_RANGE", "V3 variant count mismatch");
1150
+ if (Number(_.scene_instance_count ?? b.length) !== b.length)
1151
+ throw new f("E_GROUP_RANGE", "V3 scene instance count mismatch");
1152
+ if (Number(_.nested_instance_count ?? B.length) !== B.length)
1153
+ throw new f("E_GROUP_RANGE", "V3 nested instance count mismatch");
1154
+ if (Number(_.scene_text_count ?? S.length) !== S.length)
1155
+ throw new f("E_GROUP_RANGE", "V3 scene text count mismatch");
1156
+ if (Number(_.variant_text_count ?? O) !== O)
1157
+ throw new f("E_GROUP_RANGE", "V3 variant text count mismatch");
1158
+ for (const R of x) {
1159
+ if (R.nestedStart + R.nestedCount > B.length)
1160
+ throw new f("E_GROUP_RANGE", `V3 variant ${R.id} nested range exceeds table`);
1161
+ if (R.textStart + R.textCount > O)
1162
+ throw new f("E_GROUP_RANGE", `V3 variant ${R.id} text range exceeds table`);
1134
1163
  }
1135
- return ne(A, O, (I) => {
1136
- if (!_[I.variantId])
1137
- throw new l("E_GROUP_RANGE", `Unknown V3 variantId ${I.variantId}`);
1138
- ce(I.insLayerIdx, C.length);
1164
+ return ue(b, B, (R) => {
1165
+ if (!x[R.variantId])
1166
+ throw new f("E_GROUP_RANGE", `Unknown V3 variantId ${R.variantId}`);
1167
+ ye(R.insLayerIdx, G.length);
1139
1168
  }), {
1140
1169
  meta: {
1141
- bounds: f.bounds ?? [0, 0, 0, 0],
1142
- entity_count: Number(f.entity_count ?? 0),
1143
- line_count: R.line.count,
1144
- fill_count: R.fill.count,
1145
- dot_count: R.dot.count,
1170
+ bounds: _.bounds ?? [0, 0, 0, 0],
1171
+ entity_count: Number(_.entity_count ?? 0),
1172
+ line_count: I.line.count,
1173
+ fill_count: I.fill.count,
1174
+ dot_count: I.dot.count,
1146
1175
  version: 3,
1147
- version_minor: r,
1148
- encoding: P,
1149
- ...b ? { features: b } : {},
1150
- ...x ? { external_variants: [...x] } : {},
1151
- ...E ? { external_annotations: E } : {},
1152
- layer0_index: G,
1153
- block_variants: _.map((I) => ({
1154
- id: I.id,
1155
- name: I.name,
1156
- line_count: I.line_count,
1157
- fill_count: I.fill_count,
1158
- dot_count: I.dot_count
1176
+ version_minor: o,
1177
+ encoding: C,
1178
+ ...N ? { features: N } : {},
1179
+ ...E ? { external_variants: [...E] } : {},
1180
+ ...U ? { external_annotations: U } : {},
1181
+ layer0_index: $,
1182
+ block_variants: x.map((R) => ({
1183
+ id: R.id,
1184
+ name: R.name,
1185
+ line_count: R.line_count,
1186
+ fill_count: R.fill_count,
1187
+ dot_count: R.dot_count
1159
1188
  })),
1160
- instance_count: A.length,
1161
- layers: C,
1189
+ instance_count: b.length,
1190
+ layers: G,
1162
1191
  texts: S
1163
1192
  },
1164
1193
  header: {
1165
- ...U,
1166
- lineCount: R.line.count,
1167
- fillCount: R.fill.count,
1168
- dotCount: R.dot.count,
1194
+ ...M,
1195
+ lineCount: I.line.count,
1196
+ fillCount: I.fill.count,
1197
+ dotCount: I.dot.count,
1169
1198
  textCount: S.length,
1170
1199
  texts: S
1171
1200
  },
1172
1201
  decoded: {
1173
- baseLine: R.line,
1174
- baseFill: R.fill,
1175
- baseDot: R.dot,
1202
+ baseLine: I.line,
1203
+ baseFill: I.fill,
1204
+ baseDot: I.dot,
1176
1205
  variants: /* @__PURE__ */ new Map(),
1177
1206
  instances: [],
1178
1207
  instanceIdByVariantOrdinal: /* @__PURE__ */ new Map()
1179
1208
  }
1180
1209
  };
1181
1210
  }
1182
- const { variantsById: V, variants: F, snapshots: X } = zn(
1211
+ const T = n ? er(t, n, e) : tr(
1183
1212
  t,
1184
- n,
1185
- m,
1186
- g,
1187
- N,
1188
- x,
1189
- o,
1213
+ r,
1214
+ l,
1215
+ d,
1216
+ V,
1217
+ E,
1218
+ a,
1190
1219
  e
1191
- ), H = lt(t, d, "V3 SCENE_INSTANCE_TABLE"), $ = lt(t, h, "V3 NESTED_INSTANCE_TABLE"), M = pt(t, w, N, "V3 SCENE_TEXT_TABLE"), B = pt(t, y, N, "V3 VARIANT_TEXT_TABLE");
1192
- if (Number(f.variant_count ?? V.length) !== V.length)
1193
- throw new l("E_GROUP_RANGE", "V3 variant count mismatch");
1194
- if (Number(f.scene_instance_count ?? H.length) !== H.length)
1195
- throw new l("E_GROUP_RANGE", "V3 scene instance count mismatch");
1196
- if (Number(f.nested_instance_count ?? $.length) !== $.length)
1197
- throw new l("E_GROUP_RANGE", "V3 nested instance count mismatch");
1198
- if (Number(f.scene_text_count ?? M.length) !== M.length)
1199
- throw new l("E_GROUP_RANGE", "V3 scene text count mismatch");
1200
- if (Number(f.variant_text_count ?? B.length) !== B.length)
1201
- throw new l("E_GROUP_RANGE", "V3 variant text count mismatch");
1202
- for (const _ of V) {
1203
- if (_.nestedStart + _.nestedCount > $.length)
1204
- throw new l("E_GROUP_RANGE", `V3 variant ${_.id} nested range exceeds table`);
1205
- if (_.textStart + _.textCount > B.length)
1206
- throw new l("E_GROUP_RANGE", `V3 variant ${_.id} text range exceeds table`);
1220
+ ), { variantsById: P, variants: k, snapshots: D } = T, v = (n == null ? void 0 : n.sceneInstances) ?? mt(t, p, "V3 SCENE_INSTANCE_TABLE"), et = (n == null ? void 0 : n.nestedInstances) ?? mt(t, h, "V3 NESTED_INSTANCE_TABLE"), ut = (n == null ? void 0 : n.sceneTexts) ?? Rt(t, y, V, "V3 SCENE_TEXT_TABLE"), W = (n == null ? void 0 : n.variantTexts) ?? Rt(t, w, V, "V3 VARIANT_TEXT_TABLE");
1221
+ if (Number(_.variant_count ?? P.length) !== P.length)
1222
+ throw new f("E_GROUP_RANGE", "V3 variant count mismatch");
1223
+ if (Number(_.scene_instance_count ?? v.length) !== v.length)
1224
+ throw new f("E_GROUP_RANGE", "V3 scene instance count mismatch");
1225
+ if (Number(_.nested_instance_count ?? et.length) !== et.length)
1226
+ throw new f("E_GROUP_RANGE", "V3 nested instance count mismatch");
1227
+ if (Number(_.scene_text_count ?? ut.length) !== ut.length)
1228
+ throw new f("E_GROUP_RANGE", "V3 scene text count mismatch");
1229
+ if (Number(_.variant_text_count ?? W.length) !== W.length)
1230
+ throw new f("E_GROUP_RANGE", "V3 variant text count mismatch");
1231
+ for (const x of P) {
1232
+ if (x.nestedStart + x.nestedCount > et.length)
1233
+ throw new f("E_GROUP_RANGE", `V3 variant ${x.id} nested range exceeds table`);
1234
+ if (x.textStart + x.textCount > W.length)
1235
+ throw new f("E_GROUP_RANGE", `V3 variant ${x.id} text range exceeds table`);
1207
1236
  }
1208
- ne(H, $, (_) => {
1209
- if (!V[_.variantId])
1210
- throw new l("E_GROUP_RANGE", `Unknown V3 variantId ${_.variantId}`);
1211
- ce(_.insLayerIdx, C.length);
1237
+ ue(v, et, (x) => {
1238
+ if (!P[x.variantId])
1239
+ throw new f("E_GROUP_RANGE", `Unknown V3 variantId ${x.variantId}`);
1240
+ ye(x.insLayerIdx, G.length);
1212
1241
  });
1213
- const vt = /* @__PURE__ */ new Map();
1214
- for (const _ of V)
1215
- vt.set(
1216
- _.id,
1217
- B.slice(_.textStart, _.textStart + _.textCount)
1218
- );
1219
- const it = [], v = e.externalVariantDeltaOnly, Dt = v ? [] : [...M], gt = /* @__PURE__ */ new Map(), at = /* @__PURE__ */ new Map(), kt = /* @__PURE__ */ new Map(), Oe = (_, A) => {
1220
- gt.set(_, Bt(gt.get(_) ?? null, A));
1221
- }, Lt = (_, A, O, S, T, W) => {
1222
- var Kt;
1223
- if (T > 64)
1224
- throw new l("E_GROUP_RANGE", "V3 nested instance depth exceeds limit");
1225
- if (W.has(_))
1226
- throw new l("E_GROUP_RANGE", `V3 nested variant cycle detected at ${_}`);
1227
- const I = V[_];
1228
- if (!I)
1229
- throw new l("E_GROUP_RANGE", `Unknown V3 variantId ${_}`);
1230
- W.add(_);
1231
- const q = !e.requiredExternalVariantIds || e.requiredExternalVariantIds.has(_), Y = v ? ((Kt = e.requiredExternalVariantIds) == null ? void 0 : Kt.has(_)) === !0 : q;
1232
- let D = !1;
1233
- const Ht = !!(I.line_count || I.fill_count || I.dot_count), De = I.textCount > 0;
1234
- if (Y && (Ht || De) && (it.push({
1235
- instanceId: A.instanceId,
1236
- variantId: _,
1237
- matA: A.matA,
1238
- matB: A.matB,
1239
- matC: A.matC,
1240
- matD: A.matD,
1241
- tx: A.tx,
1242
- ty: A.ty,
1243
- insLayerIdx: A.insLayerIdx
1244
- }), Ht && Oe(A.instanceId, I.bbox ? Pe(I.bbox, A) : null), D = !0), Y) {
1245
- I.textCount > 0 && (D = !0);
1246
- for (let J = 0; J < I.textCount; J += 1) {
1247
- const tt = qn(B[I.textStart + J], A, G, U.layers);
1248
- Dt.push({
1249
- ...tt,
1250
- iv: O,
1242
+ const Yt = (n == null ? void 0 : n.variantTextsByVariantId) ?? (() => {
1243
+ const x = /* @__PURE__ */ new Map();
1244
+ for (const b of P)
1245
+ x.set(
1246
+ b.id,
1247
+ W.slice(b.textStart, b.textStart + b.textCount)
1248
+ );
1249
+ return x;
1250
+ })(), lt = [], L = e.externalVariantDeltaOnly, zt = L ? [] : [...ut], Et = /* @__PURE__ */ new Map(), ct = /* @__PURE__ */ new Map(), Ht = /* @__PURE__ */ new Map(), We = (x, b) => {
1251
+ Et.set(x, kt(Et.get(x) ?? null, b));
1252
+ }, Kt = (x, b, B, S, O, q) => {
1253
+ var Qt;
1254
+ if (O > 64)
1255
+ throw new f("E_GROUP_RANGE", "V3 nested instance depth exceeds limit");
1256
+ if (q.has(x))
1257
+ throw new f("E_GROUP_RANGE", `V3 nested variant cycle detected at ${x}`);
1258
+ const R = P[x];
1259
+ if (!R)
1260
+ throw new f("E_GROUP_RANGE", `Unknown V3 variantId ${x}`);
1261
+ q.add(x);
1262
+ const J = !e.requiredExternalVariantIds || e.requiredExternalVariantIds.has(x), z = L ? ((Qt = e.requiredExternalVariantIds) == null ? void 0 : Qt.has(x)) === !0 : J;
1263
+ let F = !1;
1264
+ const Zt = !!(R.line_count || R.fill_count || R.dot_count), Qe = R.textCount > 0;
1265
+ if (z && (Zt || Qe) && (lt.push({
1266
+ instanceId: b.instanceId,
1267
+ variantId: x,
1268
+ matA: b.matA,
1269
+ matB: b.matB,
1270
+ matC: b.matC,
1271
+ matD: b.matD,
1272
+ tx: b.tx,
1273
+ ty: b.ty,
1274
+ insLayerIdx: b.insLayerIdx
1275
+ }), Zt && We(b.instanceId, R.bbox ? Xe(R.bbox, b) : null), F = !0), z) {
1276
+ R.textCount > 0 && (F = !0);
1277
+ for (let Z = 0; Z < R.textCount; Z += 1) {
1278
+ const nt = sr(W[R.textStart + Z], b, $, M.layers);
1279
+ zt.push({
1280
+ ...nt,
1281
+ iv: B,
1251
1282
  io: S
1252
1283
  });
1253
1284
  }
1254
1285
  }
1255
- for (let J = 0; J < I.nestedCount; J += 1) {
1256
- const tt = $[I.nestedStart + J], ke = Qn(tt.insLayerIdx, A.insLayerIdx, G), Le = er(tt, I, V[tt.variantId]), Fe = Wn(A, Le, A.instanceId, ke);
1257
- D = Lt(tt.variantId, Fe, O, S, T + 1, W) || D;
1286
+ for (let Z = 0; Z < R.nestedCount; Z += 1) {
1287
+ const nt = et[R.nestedStart + Z], tn = ur(nt.insLayerIdx, b.insLayerIdx, $), en = cr(nt, R, P[nt.variantId]), nn = or(b, en, b.instanceId, tn);
1288
+ F = Kt(nt.variantId, nn, B, S, O + 1, q) || F;
1258
1289
  }
1259
- return W.delete(_), D;
1260
- }, yt = /* @__PURE__ */ new Map();
1261
- H.forEach((_, A) => {
1262
- if (!V[_.variantId])
1263
- throw new l("E_GROUP_RANGE", `Unknown V3 scene variantId ${_.variantId}`);
1264
- const S = kt.get(_.variantId) ?? 0;
1265
- kt.set(_.variantId, S + 1), at.set(`${_.variantId}:${S}`, A);
1266
- const T = Zn(_.insLayerIdx, G), W = {
1267
- instanceId: A,
1268
- variantId: _.variantId,
1269
- matA: _.matA,
1270
- matB: _.matB,
1271
- matC: _.matC,
1272
- matD: _.matD,
1273
- tx: _.tx,
1274
- ty: _.ty,
1275
- insLayerIdx: T
1276
- }, I = Lt(_.variantId, W, _.variantId, S, 0, /* @__PURE__ */ new Set());
1277
- if (v && !I)
1290
+ return q.delete(x), F;
1291
+ }, wt = /* @__PURE__ */ new Map();
1292
+ v.forEach((x, b) => {
1293
+ if (!P[x.variantId])
1294
+ throw new f("E_GROUP_RANGE", `Unknown V3 scene variantId ${x.variantId}`);
1295
+ const S = Ht.get(x.variantId) ?? 0;
1296
+ Ht.set(x.variantId, S + 1), ct.set(`${x.variantId}:${S}`, b);
1297
+ const O = ar(x.insLayerIdx, $), q = {
1298
+ instanceId: b,
1299
+ variantId: x.variantId,
1300
+ matA: x.matA,
1301
+ matB: x.matB,
1302
+ matC: x.matC,
1303
+ matD: x.matD,
1304
+ tx: x.tx,
1305
+ ty: x.ty,
1306
+ insLayerIdx: O
1307
+ }, R = Kt(x.variantId, q, x.variantId, S, 0, /* @__PURE__ */ new Set());
1308
+ if (L && !R)
1278
1309
  return;
1279
- let q = yt.get(T);
1280
- q || (q = /* @__PURE__ */ new Map(), yt.set(T, q));
1281
- let Y = q.get(_.variantId);
1282
- Y || (Y = { count: 0, bboxes: [], inserts: [] }, q.set(_.variantId, Y)), Y.count += 1;
1283
- const D = gt.get(A) ?? null;
1284
- D && Y.bboxes.push(D), Y.inserts.push({
1285
- instanceId: A,
1286
- variantId: _.variantId,
1287
- label: `#${A + 1} (${_.tx.toFixed(1)}, ${_.ty.toFixed(1)})`,
1288
- tx: _.tx,
1289
- ty: _.ty,
1290
- canHighlight: D !== null,
1291
- ...D ? { bbox: D } : {}
1310
+ let J = wt.get(O);
1311
+ J || (J = /* @__PURE__ */ new Map(), wt.set(O, J));
1312
+ let z = J.get(x.variantId);
1313
+ z || (z = { count: 0, bboxes: [], inserts: [] }, J.set(x.variantId, z)), z.count += 1;
1314
+ const F = Et.get(b) ?? null;
1315
+ F && z.bboxes.push(F), z.inserts.push({
1316
+ instanceId: b,
1317
+ variantId: x.variantId,
1318
+ label: `#${b + 1} (${x.tx.toFixed(1)}, ${x.ty.toFixed(1)})`,
1319
+ tx: x.tx,
1320
+ ty: x.ty,
1321
+ canHighlight: F !== null,
1322
+ ...F ? { bbox: F } : {}
1292
1323
  });
1293
1324
  });
1294
- const Ft = /* @__PURE__ */ new Map();
1295
- for (const [_, A] of yt) {
1296
- const O = [];
1297
- for (const [S, T] of A)
1298
- O.push({
1325
+ const jt = /* @__PURE__ */ new Map();
1326
+ for (const [x, b] of wt) {
1327
+ const B = [];
1328
+ for (const [S, O] of b)
1329
+ B.push({
1299
1330
  variantId: S,
1300
- blockName: Ne(V[S], S),
1301
- instanceCount: T.count,
1302
- bboxes: T.bboxes,
1303
- inserts: T.inserts
1331
+ blockName: $e(P[S], S),
1332
+ instanceCount: O.count,
1333
+ bboxes: O.bboxes,
1334
+ inserts: O.inserts
1304
1335
  });
1305
- O.sort((S, T) => T.instanceCount - S.instanceCount), Ft.set(_, O);
1336
+ B.sort((S, O) => O.instanceCount - S.instanceCount), jt.set(x, B);
1306
1337
  }
1307
- let Xt = v ? 0 : R.line.count, Yt = v ? 0 : R.fill.count, zt = v ? 0 : R.dot.count;
1308
- for (const _ of it) {
1309
- const A = V[_.variantId];
1310
- e.deferExternalVariantGeometry && A.lineSnapshot.count === 0 && A.fillSnapshot.count === 0 && A.dotSnapshot.count === 0 || !Ve(_.instanceId, e) || (Xt += A.line_count, Yt += A.fill_count, zt += A.dot_count);
1338
+ let Wt = L ? 0 : I.line.count, qt = L ? 0 : I.fill.count, Jt = L ? 0 : I.dot.count;
1339
+ for (const x of lt) {
1340
+ const b = P[x.variantId];
1341
+ e.deferExternalVariantGeometry && b.lineSnapshot.count === 0 && b.fillSnapshot.count === 0 && b.dotSnapshot.count === 0 || !Be(x.instanceId, e) || (Wt += b.line_count, qt += b.fill_count, Jt += b.dot_count);
1311
1342
  }
1312
- const ct = pn(Dt, at, e), Me = {
1313
- bounds: f.bounds ?? [0, 0, 0, 0],
1314
- entity_count: v ? 0 : Number(f.entity_count ?? 0),
1315
- line_count: R.line.count,
1316
- fill_count: R.fill.count,
1317
- dot_count: R.dot.count,
1343
+ const ft = $n(zt, ct, e), qe = {
1344
+ bounds: _.bounds ?? [0, 0, 0, 0],
1345
+ entity_count: L ? 0 : Number(_.entity_count ?? 0),
1346
+ line_count: I.line.count,
1347
+ fill_count: I.fill.count,
1348
+ dot_count: I.dot.count,
1318
1349
  version: 3,
1319
- version_minor: r,
1320
- encoding: P,
1321
- ...b ? { features: b } : {},
1322
- ...x ? { external_variants: [...x] } : {},
1323
- ...E ? { external_annotations: E } : {},
1324
- layer0_index: G,
1325
- block_variants: V.map((_) => ({
1326
- id: _.id,
1327
- name: _.name,
1328
- line_count: _.sourceLineCount,
1329
- fill_count: _.sourceFillCount,
1330
- dot_count: _.sourceDotCount
1350
+ version_minor: o,
1351
+ encoding: C,
1352
+ ...N ? { features: N } : {},
1353
+ ...E ? { external_variants: [...E] } : {},
1354
+ ...U ? { external_annotations: U } : {},
1355
+ layer0_index: $,
1356
+ block_variants: P.map((x) => ({
1357
+ id: x.id,
1358
+ name: x.name,
1359
+ line_count: x.sourceLineCount,
1360
+ fill_count: x.sourceFillCount,
1361
+ dot_count: x.sourceDotCount
1331
1362
  })),
1332
- instance_count: H.length,
1333
- layers: C,
1334
- texts: ct
1335
- }, ve = {
1336
- ...U,
1337
- entityCount: v ? 0 : U.entityCount,
1338
- lineCount: Xt,
1339
- fillCount: Yt,
1340
- dotCount: zt,
1341
- textCount: ct.length,
1342
- texts: ct,
1363
+ instance_count: v.length,
1364
+ layers: G,
1365
+ texts: ft
1366
+ }, Je = {
1367
+ ...M,
1368
+ entityCount: L ? 0 : M.entityCount,
1369
+ lineCount: Wt,
1370
+ fillCount: qt,
1371
+ dotCount: Jt,
1372
+ textCount: ft.length,
1373
+ texts: ft,
1343
1374
  ...e.loadBlocks ? {
1344
- layerBlockUsages: Ft,
1345
- insertRuntime: An(
1346
- G,
1347
- V,
1348
- X,
1349
- vt,
1350
- it,
1351
- ct,
1352
- at
1375
+ layerBlockUsages: jt,
1376
+ insertRuntime: On(
1377
+ $,
1378
+ P,
1379
+ D,
1380
+ Yt,
1381
+ lt,
1382
+ ft,
1383
+ ct
1353
1384
  )
1354
1385
  } : {}
1355
- };
1386
+ }, Ze = n ?? (e.cacheDocument ? (() => {
1387
+ const x = /* @__PURE__ */ new Map();
1388
+ for (const [b, B] of k)
1389
+ E != null && E[b] || x.set(b, {
1390
+ line: { chunk: B.line, snapshot: D[b].line },
1391
+ fill: { chunk: B.fill, snapshot: D[b].fill },
1392
+ dot: { chunk: B.dot, snapshot: D[b].dot }
1393
+ });
1394
+ return {
1395
+ kind: "dxb3-v3",
1396
+ buffer: t,
1397
+ versionMinor: o,
1398
+ sections: i,
1399
+ groupLayerEncoding: a,
1400
+ sceneMeta: _,
1401
+ externalVariants: E,
1402
+ externalAnnotations: U,
1403
+ geoMetaFeatures: N,
1404
+ geoMetaEncoding: C,
1405
+ stringTable: V,
1406
+ layers: G,
1407
+ layer0Index: $,
1408
+ headerForValidation: M,
1409
+ baseGeometry: I,
1410
+ variantHeaders: fe(
1411
+ r,
1412
+ l,
1413
+ d,
1414
+ V,
1415
+ E
1416
+ ),
1417
+ internalVariants: x,
1418
+ sceneInstances: v,
1419
+ nestedInstances: et,
1420
+ sceneTexts: ut,
1421
+ variantTexts: W,
1422
+ variantTextCount: W.length,
1423
+ variantTextsByVariantId: Yt
1424
+ };
1425
+ })() : void 0);
1356
1426
  return {
1357
- meta: Me,
1358
- header: ve,
1427
+ meta: qe,
1428
+ header: Je,
1429
+ documentCache: Ze,
1359
1430
  decoded: {
1360
- baseLine: v ? At() : R.line,
1361
- baseFill: v ? At() : R.fill,
1362
- baseDot: v ? At() : R.dot,
1363
- variants: F,
1364
- instances: it,
1365
- instanceIdByVariantOrdinal: at
1431
+ baseLine: L ? Gt() : I.line,
1432
+ baseFill: L ? Gt() : I.fill,
1433
+ baseDot: L ? Gt() : I.dot,
1434
+ variants: k,
1435
+ instances: lt,
1436
+ instanceIdByVariantOrdinal: ct
1366
1437
  }
1367
1438
  };
1368
1439
  }
1369
- function Bt(t, e) {
1370
- return Ae(t, e);
1440
+ function kt(t, e) {
1441
+ return Ce(t, e);
1371
1442
  }
1372
- function Pe(t, e) {
1373
- return Ie(t, e);
1443
+ function Xe(t, e) {
1444
+ return Se(t, e);
1374
1445
  }
1375
- function se(t) {
1376
- return Ze(t);
1446
+ function de(t) {
1447
+ return mn(t);
1377
1448
  }
1378
- function ie(t, e) {
1379
- return Qe(t, e);
1449
+ function me(t, e) {
1450
+ return gn(t, e);
1380
1451
  }
1381
- function ae(t, e) {
1382
- return Pe(t, {
1452
+ function ge(t, e) {
1453
+ return Xe(t, {
1383
1454
  variantId: e.variantId,
1384
1455
  matA: e.matA,
1385
1456
  matB: e.matB,
@@ -1390,7 +1461,7 @@ function ae(t, e) {
1390
1461
  insLayerIdx: e.insLayerIdx
1391
1462
  });
1392
1463
  }
1393
- function er(t, e, n) {
1464
+ function cr(t, e, n) {
1394
1465
  if (!(n != null && n.bbox) || !e.bbox)
1395
1466
  return t;
1396
1467
  const r = e.precisionOriginX, s = e.precisionOriginY;
@@ -1400,27 +1471,27 @@ function er(t, e, n) {
1400
1471
  ...t,
1401
1472
  tx: t.tx - r,
1402
1473
  ty: t.ty - s
1403
- }, i = ae(n.bbox, t), a = ae(n.bbox, o), c = Math.max(se(e.bbox), se(n.bbox), 1), u = Math.hypot(r, s), m = Math.hypot(t.tx, t.ty), g = Math.hypot(o.tx, o.ty);
1404
- if (u <= c * 16 || m <= c * 16)
1474
+ }, i = ge(n.bbox, t), a = ge(n.bbox, o), u = Math.max(de(e.bbox), de(n.bbox), 1), c = Math.hypot(r, s), m = Math.hypot(t.tx, t.ty), g = Math.hypot(o.tx, o.ty);
1475
+ if (c <= u * 16 || m <= u * 16)
1405
1476
  return t;
1406
- const d = ie(e.bbox, i), h = ie(e.bbox, a);
1407
- return d > c * 16 && h * 4 < d && g * 4 < m ? o : t;
1477
+ const l = me(e.bbox, i), d = me(e.bbox, a);
1478
+ return l > u * 16 && d * 4 < l && g * 4 < m ? o : t;
1408
1479
  }
1409
- function ce(t, e) {
1480
+ function ye(t, e) {
1410
1481
  if (t >= e)
1411
- throw new l("E_GROUP_RANGE", `Instance layer index ${t} exceeds layer count ${e}`);
1482
+ throw new f("E_GROUP_RANGE", `Instance layer index ${t} exceeds layer count ${e}`);
1412
1483
  }
1413
- function nr(t, e) {
1484
+ function fr(t, e) {
1414
1485
  if (!Number.isInteger(t) || t < 0 || t >= e.length)
1415
- throw new l("E_GROUP_RANGE", `layer0_index out of range: ${t}`);
1486
+ throw new f("E_GROUP_RANGE", `layer0_index out of range: ${t}`);
1416
1487
  if (e[t].name !== "0")
1417
- throw new l("E_GROUP_RANGE", `layer0_index must reference layer "0": ${t}`);
1488
+ throw new f("E_GROUP_RANGE", `layer0_index must reference layer "0": ${t}`);
1418
1489
  }
1419
- function rr(t) {
1490
+ function dr(t) {
1420
1491
  if (t !== 0)
1421
- throw new l("E_GROUP_RANGE", `Instance flags must be zero for Stage 1, found ${t}`);
1492
+ throw new f("E_GROUP_RANGE", `Instance flags must be zero for Stage 1, found ${t}`);
1422
1493
  }
1423
- function* or(t, e, n, r, s) {
1494
+ function* mr(t, e, n, r, s) {
1424
1495
  let o = n;
1425
1496
  const i = [
1426
1497
  { kind: "line", count: r.lineCount },
@@ -1428,91 +1499,91 @@ function* or(t, e, n, r, s) {
1428
1499
  { kind: "dot", count: r.dotCount }
1429
1500
  ];
1430
1501
  for (const a of i) {
1431
- const c = qe(t, e, o, a.count);
1502
+ const u = fn(t, e, o, a.count);
1432
1503
  for (; ; ) {
1433
- const u = c.next();
1434
- if (u.done) {
1435
- o = u.value;
1504
+ const c = u.next();
1505
+ if (c.done) {
1506
+ o = c.value;
1436
1507
  break;
1437
1508
  }
1438
- yield { kind: a.kind, payload: u.value };
1509
+ yield { kind: a.kind, payload: c.value };
1439
1510
  }
1440
1511
  }
1441
1512
  if (o !== t.byteLength)
1442
- throw new l("E_GROUP_RANGE", `Trailing bytes detected: offset=${o}, size=${t.byteLength}`);
1513
+ throw new f("E_GROUP_RANGE", `Trailing bytes detected: offset=${o}, size=${t.byteLength}`);
1443
1514
  for (const a of r.texts)
1444
1515
  yield { kind: "text", payload: a };
1445
1516
  }
1446
- function* sr(t, e, n, r) {
1447
- yield* or(t, e, n, r);
1517
+ function* gr(t, e, n, r) {
1518
+ yield* mr(t, e, n, r);
1448
1519
  }
1449
- function* bt(t, e, n, r, s, o, i, a) {
1450
- if (wn(a, t, Math.max(0, e - n.count)), e === 0) {
1451
- yield { kind: t, payload: cn() };
1520
+ function* Vt(t, e, n, r, s, o, i, a) {
1521
+ if (Bn(a, t, Math.max(0, e - n.count)), e === 0) {
1522
+ yield { kind: t, payload: bn() };
1452
1523
  return;
1453
1524
  }
1454
- const c = Ut;
1455
- let u = new Float32Array(c * 2), m = [], g = 0, d = 0;
1456
- const h = function* () {
1525
+ const u = Bt;
1526
+ let c = new Float32Array(u * 2), m = [], g = 0, l = 0;
1527
+ const d = function* () {
1457
1528
  if (g <= 0)
1458
1529
  return;
1459
- const f = g === c ? { pos: u, count: g, segments: ee(m) } : { pos: u.slice(0, g * 2), count: g, segments: ee(m) };
1460
- yield { kind: t, payload: f }, d += g, g = 0, u = new Float32Array(c * 2), m = [];
1461
- }, w = (f, x, p, E) => {
1462
- if (f <= 0)
1530
+ const y = g === u ? { pos: c, count: g, segments: ae(m) } : { pos: c.slice(0, g * 2), count: g, segments: ae(m) };
1531
+ yield { kind: t, payload: y }, l += g, g = 0, c = new Float32Array(u * 2), m = [];
1532
+ }, p = (y, w, _, E) => {
1533
+ if (y <= 0)
1463
1534
  return;
1464
- const b = m[m.length - 1];
1465
- if (b && b.startVertex + b.vertexCount === g && b.layerIndex === p && b.color[0] === x[0] && b.color[1] === x[1] && b.color[2] === x[2] && b.lineweightPx === E) {
1535
+ const A = m[m.length - 1];
1536
+ if (A && A.startVertex + A.vertexCount === g && A.layerIndex === _ && A.color[0] === w[0] && A.color[1] === w[1] && A.color[2] === w[2] && A.lineweightPx === E) {
1466
1537
  m[m.length - 1] = {
1467
- ...b,
1468
- vertexCount: b.vertexCount + f
1538
+ ...A,
1539
+ vertexCount: A.vertexCount + y
1469
1540
  };
1470
1541
  return;
1471
1542
  }
1472
1543
  m.push({
1473
1544
  startVertex: g,
1474
- vertexCount: f,
1475
- color: [x[0], x[1], x[2]],
1476
- layerIndex: p,
1545
+ vertexCount: y,
1546
+ color: [w[0], w[1], w[2]],
1547
+ layerIndex: _,
1477
1548
  ...E === void 0 ? {} : { lineweightPx: E }
1478
1549
  });
1479
1550
  };
1480
1551
  yield* function* () {
1481
- for (const f of Pt(n)) {
1482
- let x = f.startVertex;
1483
- const p = f.startVertex + f.vertexCount;
1484
- for (; x < p; ) {
1485
- const E = Math.min(c - g, p - x), b = x * 2, P = g * 2;
1486
- u.set(n.pos.subarray(b, b + E * 2), P), w(E, f.color, f.layerIndex, f.lineweightPx), x += E, g += E, g === c && (yield* h());
1552
+ for (const y of Ot(n)) {
1553
+ let w = y.startVertex;
1554
+ const _ = y.startVertex + y.vertexCount;
1555
+ for (; w < _; ) {
1556
+ const E = Math.min(u - g, _ - w), A = w * 2, U = g * 2;
1557
+ c.set(n.pos.subarray(A, A + E * 2), U), p(E, y.color, y.layerIndex, y.lineweightPx), w += E, g += E, g === u && (yield* d());
1487
1558
  }
1488
1559
  }
1489
1560
  }();
1490
- for (const f of s) {
1491
- if (!Ve(f.instanceId, a))
1561
+ for (const y of s) {
1562
+ if (!Be(y.instanceId, a))
1492
1563
  continue;
1493
- const x = r.get(f.variantId);
1494
- if (!x)
1495
- throw new l("E_GROUP_RANGE", `Unknown variantId ${f.variantId}`);
1496
- const p = x[t], E = i[f.insLayerIdx].visible === !1;
1497
- for (const b of Pt(p)) {
1498
- const P = E || b.layerIndex === o ? f.insLayerIdx : b.layerIndex;
1499
- let N = b.startVertex;
1500
- const C = b.startVertex + b.vertexCount;
1564
+ const w = r.get(y.variantId);
1565
+ if (!w)
1566
+ throw new f("E_GROUP_RANGE", `Unknown variantId ${y.variantId}`);
1567
+ const _ = w[t], E = i[y.insLayerIdx].visible === !1;
1568
+ for (const A of Ot(_)) {
1569
+ const U = E || A.layerIndex === o ? y.insLayerIdx : A.layerIndex;
1570
+ let N = A.startVertex;
1571
+ const C = A.startVertex + A.vertexCount;
1501
1572
  for (; N < C; ) {
1502
- const G = Math.min(c - g, C - N);
1503
- for (let U = 0; U < G; U += 1) {
1504
- const R = (N + U) * 2, V = (g + U) * 2, F = p.pos[R], X = p.pos[R + 1];
1505
- u[V] = f.matA * F + f.matC * X + f.tx, u[V + 1] = f.matB * F + f.matD * X + f.ty;
1573
+ const V = Math.min(u - g, C - N);
1574
+ for (let G = 0; G < V; G += 1) {
1575
+ const $ = (N + G) * 2, M = (g + G) * 2, I = _.pos[$], T = _.pos[$ + 1];
1576
+ c[M] = y.matA * I + y.matC * T + y.tx, c[M + 1] = y.matB * I + y.matD * T + y.ty;
1506
1577
  }
1507
- w(G, b.color, P, b.lineweightPx), N += G, g += G, g === c && (yield* h());
1578
+ p(V, A.color, U, A.lineweightPx), N += V, g += V, g === u && (yield* d());
1508
1579
  }
1509
1580
  }
1510
1581
  }
1511
- if (yield* h(), d !== e)
1512
- throw new l("E_GROUP_RANGE", `Expanded ${t} count mismatch: header=${e}, emitted=${d}`);
1582
+ if (yield* d(), l !== e)
1583
+ throw new f("E_GROUP_RANGE", `Expanded ${t} count mismatch: header=${e}, emitted=${l}`);
1513
1584
  }
1514
- function* ir(t, e, n, r) {
1515
- yield* bt(
1585
+ function* yr(t, e, n, r) {
1586
+ yield* Vt(
1516
1587
  "line",
1517
1588
  e.lineCount,
1518
1589
  t.baseLine,
@@ -1521,7 +1592,7 @@ function* ir(t, e, n, r) {
1521
1592
  n.layer0_index,
1522
1593
  e.layers,
1523
1594
  r
1524
- ), yield* bt(
1595
+ ), yield* Vt(
1525
1596
  "fill",
1526
1597
  e.fillCount,
1527
1598
  t.baseFill,
@@ -1530,7 +1601,7 @@ function* ir(t, e, n, r) {
1530
1601
  n.layer0_index,
1531
1602
  e.layers,
1532
1603
  r
1533
- ), yield* bt(
1604
+ ), yield* Vt(
1534
1605
  "dot",
1535
1606
  e.dotCount,
1536
1607
  t.baseDot,
@@ -1543,28 +1614,32 @@ function* ir(t, e, n, r) {
1543
1614
  for (const s of e.texts)
1544
1615
  yield { kind: "text", payload: s };
1545
1616
  }
1546
- function ar(t, e) {
1547
- const n = xn(e), r = tr(t, n);
1548
- return {
1549
- header: r.header,
1550
- chunks: ir(
1551
- r.decoded,
1552
- r.header,
1553
- { layer0_index: r.meta.layer0_index ?? 0 },
1554
- n
1617
+ function Ye(t, e, n) {
1618
+ const r = Tn(e), s = lr(t, r, n);
1619
+ return s.documentCache && Te.add(s.documentCache), {
1620
+ header: s.header,
1621
+ ...s.documentCache ? { documentCache: s.documentCache } : {},
1622
+ chunks: yr(
1623
+ s.decoded,
1624
+ s.header,
1625
+ { layer0_index: s.meta.layer0_index ?? 0 },
1626
+ r
1555
1627
  )
1556
1628
  };
1557
1629
  }
1558
- function cr(t, e) {
1559
- if (Nn(t))
1560
- return ar(t, e);
1561
- const n = Vn(t);
1630
+ function ze(t, e) {
1631
+ if (ve(t))
1632
+ return Ye(t, e);
1633
+ const n = Dn(t);
1562
1634
  return {
1563
1635
  header: n.header,
1564
- chunks: sr(t, n.view, n.dataOffset, n.header)
1636
+ chunks: gr(t, n.view, n.dataOffset, n.header)
1565
1637
  };
1566
1638
  }
1567
- function At() {
1639
+ function hr(t, e, n) {
1640
+ return e.kind !== "dxb3-v3" || e.buffer !== t || !Te.has(e) || !ve(t) ? ze(t, n) : Ye(t, n, e);
1641
+ }
1642
+ function Gt() {
1568
1643
  return {
1569
1644
  pos: new Float32Array(0),
1570
1645
  col: new Uint8Array(0),
@@ -1572,110 +1647,103 @@ function At() {
1572
1647
  count: 0
1573
1648
  };
1574
1649
  }
1575
- function ur(t, e) {
1576
- return t ? mt(Ie(t, e)) : null;
1577
- }
1578
- async function lr(t) {
1579
- const e = ue(), n = t.fetchImpl ?? fetch, r = new Map(
1580
- t.entries.map((u) => [u.id, u])
1581
- ), s = Array.from(new Set(t.requiredVariantIds)).sort((u, m) => u - m), o = /* @__PURE__ */ new Map(), i = fr(t.concurrency);
1582
- let a = 0;
1583
- async function c() {
1584
- var u;
1585
- for (; a < s.length; ) {
1586
- const m = s[a++], g = r.get(m);
1587
- if (!g)
1588
- throw new Error(`External block ${m} is missing from manifest`);
1589
- const d = new URL(g.href, t.baseUrl).href, h = await n(d, { signal: t.signal });
1590
- if (!h.ok) {
1591
- const y = "status" in h ? h.status : void 0, f = "statusText" in h ? h.statusText : void 0, x = [y, f].filter((p) => p !== void 0 && p !== "").join(" ");
1592
- throw new Error(`External block ${m} fetch failed${x ? `: ${x}` : ""}`);
1593
- }
1594
- const w = await h.arrayBuffer();
1595
- if (w.byteLength !== g.raw_size)
1596
- throw new Error(
1597
- `External block ${m} raw_size mismatch: manifest=${g.raw_size}, response=${w.byteLength}`
1598
- );
1599
- o.set(m, w), await ((u = t.onBuffer) == null ? void 0 : u.call(t, m, w));
1650
+ function _r(t, e) {
1651
+ return t ? ht(Se(t, e)) : null;
1652
+ }
1653
+ async function xr(t) {
1654
+ const e = he(), n = t.fetchImpl ?? fetch, r = new Map(
1655
+ t.entries.map((a) => [a.id, a])
1656
+ ), s = Array.from(new Set(t.requiredVariantIds)).sort((a, u) => a - u), o = /* @__PURE__ */ new Map();
1657
+ async function i(a) {
1658
+ var l;
1659
+ const u = r.get(a);
1660
+ if (!u)
1661
+ throw new Error(`External block ${a} is missing from manifest`);
1662
+ const c = new URL(u.href, t.baseUrl).href, m = await n(c, { signal: t.signal });
1663
+ if (!m.ok) {
1664
+ const d = "status" in m ? m.status : void 0, p = "statusText" in m ? m.statusText : void 0, h = [d, p].filter((y) => y !== void 0 && y !== "").join(" ");
1665
+ throw new Error(`External block ${a} fetch failed${h ? `: ${h}` : ""}`);
1600
1666
  }
1667
+ const g = await m.arrayBuffer();
1668
+ if (g.byteLength !== u.raw_size)
1669
+ throw new Error(
1670
+ `External block ${a} raw_size mismatch: manifest=${u.raw_size}, response=${g.byteLength}`
1671
+ );
1672
+ o.set(a, g), await ((l = t.onBuffer) == null ? void 0 : l.call(t, a, g));
1601
1673
  }
1602
- return await Promise.all(Array.from({ length: Math.min(i, s.length) }, c)), { buffers: o, fetchMs: ue() - e };
1674
+ return await Promise.all(s.map(i)), { buffers: o, fetchMs: he() - e };
1603
1675
  }
1604
- function fr(t) {
1605
- const e = Math.floor(t ?? 3);
1606
- return Number.isFinite(e) ? Math.max(1, Math.min(e, 8)) : 3;
1607
- }
1608
- function ue() {
1676
+ function he() {
1609
1677
  var t, e;
1610
1678
  return ((e = (t = globalThis.performance) == null ? void 0 : t.now) == null ? void 0 : e.call(t)) ?? Date.now();
1611
1679
  }
1612
1680
  var j;
1613
- class dr {
1681
+ class Er {
1614
1682
  constructor() {
1615
- Wt(this, j, /* @__PURE__ */ new Map());
1683
+ ee(this, j, /* @__PURE__ */ new Map());
1616
1684
  }
1617
1685
  get size() {
1618
- return et(this, j).size;
1686
+ return rt(this, j).size;
1619
1687
  }
1620
1688
  append(e) {
1621
1689
  let n = 0;
1622
1690
  for (const r of e) {
1623
1691
  if (r.count <= 0) continue;
1624
- const s = $t(r.layerIndex, r.lineweightPx);
1625
- let o = et(this, j).get(s), i = r.pos, a = r.positionItemSize;
1626
- const c = r.linePositionKind ?? null;
1627
- o ? o.positionItemSize !== a && (le(o), a !== 3 && (i = Be(i, r.count, a)), o.positionItemSize = 3, a = 3, o.linePositionKind = null) : (o = {
1692
+ const s = Dt(r.layerIndex, r.lineweightPx);
1693
+ let o = rt(this, j).get(s), i = r.pos, a = r.positionItemSize;
1694
+ const u = r.linePositionKind ?? null;
1695
+ o ? o.positionItemSize !== a && (_e(o), a !== 3 && (i = Ke(i, r.count, a)), o.positionItemSize = 3, a = 3, o.linePositionKind = null) : (o = {
1628
1696
  layerIndex: r.layerIndex,
1629
1697
  ...r.lineweightPx === void 0 ? {} : { lineweightPx: r.lineweightPx },
1630
1698
  posParts: [],
1631
1699
  positionItemSize: a,
1632
1700
  colParts: [],
1633
1701
  colorRunParts: [],
1634
- linePositionKind: c,
1702
+ linePositionKind: u,
1635
1703
  count: 0,
1636
1704
  bbox: null
1637
- }, et(this, j).set(s, o));
1638
- const u = o.count > 0;
1705
+ }, rt(this, j).set(s, o));
1706
+ const c = o.count > 0;
1639
1707
  o.posParts.push(i), o.colParts.push(r.col);
1640
- const m = wr(
1641
- r.colorRuns ?? pr(r.col),
1708
+ const m = Gr(
1709
+ r.colorRuns ?? Nr(r.col),
1642
1710
  o.count
1643
1711
  );
1644
- o.colorRunParts.push(m), o.linePositionKind !== c && (o.linePositionKind = null), o.positionItemSize === 2 && o.linePositionKind === null && le(o), o.count += r.count, o.bbox = u && o.bbox === null ? null : hr(o.bbox, r.bbox), n += r.count;
1712
+ o.colorRunParts.push(m), o.linePositionKind !== u && (o.linePositionKind = null), o.positionItemSize === 2 && o.linePositionKind === null && _e(o), o.count += r.count, o.bbox = c && o.bbox === null ? null : pr(o.bbox, r.bbox), n += r.count;
1645
1713
  }
1646
1714
  return n;
1647
1715
  }
1648
1716
  drain() {
1649
1717
  const e = [];
1650
- for (const n of et(this, j).values()) {
1718
+ for (const n of rt(this, j).values()) {
1651
1719
  if (n.count <= 0) continue;
1652
- const r = n.posParts.length === 1 ? n.posParts[0] : xr(n.posParts, n.count * n.positionItemSize), s = n.colParts.length === 1 ? n.colParts[0] : Er(n.colParts, n.count * 3), o = $e(n.colorRunParts.flat()), i = {
1720
+ const r = n.posParts.length === 1 ? n.posParts[0] : Rr(n.posParts, n.count * n.positionItemSize), s = n.colParts.length === 1 ? n.colParts[0] : Vr(n.colParts, n.count * 3), o = je(n.colorRunParts.flat()), i = {
1653
1721
  layerIndex: n.layerIndex,
1654
1722
  pos: r,
1655
1723
  positionItemSize: n.positionItemSize,
1656
1724
  col: s,
1657
1725
  count: n.count,
1658
- bbox: mt(n.bbox),
1726
+ bbox: ht(n.bbox),
1659
1727
  colorRuns: o
1660
1728
  };
1661
1729
  n.lineweightPx !== void 0 && (i.lineweightPx = n.lineweightPx), n.linePositionKind && (i.linePositionKind = n.linePositionKind), e.push(i);
1662
1730
  }
1663
- return et(this, j).clear(), e;
1731
+ return rt(this, j).clear(), e;
1664
1732
  }
1665
1733
  }
1666
1734
  j = new WeakMap();
1667
- function It() {
1668
- return new dr();
1735
+ function Nt() {
1736
+ return new Er();
1669
1737
  }
1670
- function mr() {
1738
+ function wr() {
1671
1739
  return {
1672
- line: It(),
1673
- fill: It(),
1674
- dot: It()
1740
+ line: Nt(),
1741
+ fill: Nt(),
1742
+ dot: Nt()
1675
1743
  };
1676
1744
  }
1677
- function hr(t, e) {
1678
- const n = mt(e);
1745
+ function pr(t, e) {
1746
+ const n = ht(e);
1679
1747
  return t ? n ? {
1680
1748
  minX: Math.min(t.minX, n.minX),
1681
1749
  minY: Math.min(t.minY, n.minY),
@@ -1683,73 +1751,73 @@ function hr(t, e) {
1683
1751
  maxY: Math.max(t.maxY, n.maxY)
1684
1752
  } : null : n;
1685
1753
  }
1686
- function Te(t, e = {}) {
1754
+ function He(t, e = {}) {
1687
1755
  if (t.count <= 0) return [];
1688
- const n = Pt(t), r = [], s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = e.markLinePositionXy === !0 || e.splitLineweight === !0;
1689
- for (const y of n) {
1690
- if (y.vertexCount <= 0) continue;
1691
- const f = y.layerIndex, x = a ? y.lineweightPx : void 0, p = $t(f, x), E = s.get(p);
1692
- E === void 0 ? (s.set(p, y.vertexCount), o.set(p, f), i.set(p, x), r.push(p)) : s.set(p, E + y.vertexCount);
1756
+ const n = Ot(t), r = [], s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = e.markLinePositionXy === !0 || e.splitLineweight === !0;
1757
+ for (const h of n) {
1758
+ if (h.vertexCount <= 0) continue;
1759
+ const y = h.layerIndex, w = a ? h.lineweightPx : void 0, _ = Dt(y, w), E = s.get(_);
1760
+ E === void 0 ? (s.set(_, h.vertexCount), o.set(_, y), i.set(_, w), r.push(_)) : s.set(_, E + h.vertexCount);
1693
1761
  }
1694
- const c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), d = e.markLinePositionXy === !0 ? "xy-zero-z" : void 0, h = d ? 2 : 3;
1695
- for (const y of r) {
1696
- const f = o.get(y), x = i.get(y), p = s.get(y) ?? 0, E = {
1697
- layerIndex: f,
1698
- ...x === void 0 ? {} : { lineweightPx: x },
1699
- pos: new Float32Array(p * h),
1700
- positionItemSize: h,
1701
- col: new Uint8Array(p * 3),
1702
- count: p,
1762
+ const u = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), l = e.markLinePositionXy === !0 ? "xy-zero-z" : void 0, d = l ? 2 : 3;
1763
+ for (const h of r) {
1764
+ const y = o.get(h), w = i.get(h), _ = s.get(h) ?? 0, E = {
1765
+ layerIndex: y,
1766
+ ...w === void 0 ? {} : { lineweightPx: w },
1767
+ pos: new Float32Array(_ * d),
1768
+ positionItemSize: d,
1769
+ col: new Uint8Array(_ * 3),
1770
+ count: _,
1703
1771
  bbox: null,
1704
1772
  colorRuns: []
1705
1773
  };
1706
- d && (E.linePositionKind = d), c.set(y, E), u.set(y, 0), m.set(y, null);
1774
+ l && (E.linePositionKind = l), u.set(h, E), c.set(h, 0), m.set(h, null);
1707
1775
  }
1708
- for (const y of n) {
1709
- if (y.vertexCount <= 0) continue;
1710
- const f = y.layerIndex, x = a ? y.lineweightPx : void 0, p = $t(f, x), E = c.get(p), b = u.get(p), P = b, N = y.color[0], C = y.color[1], G = y.color[2];
1711
- for (let U = 0; U < y.vertexCount; U += 1) {
1712
- const R = y.startVertex + U, V = b + U, F = V * h, X = V * 3, H = R * 2, $ = t.pos[H], M = t.pos[H + 1];
1713
- E.pos[F] = $, E.pos[F + 1] = M, h === 3 && (E.pos[F + 2] = 0), E.col[X] = N, E.col[X + 1] = C, E.col[X + 2] = G;
1714
- const B = m.get(p);
1715
- !Number.isFinite($) || !Number.isFinite(M) ? g.add(p) : B ? ($ < B.minX && (B.minX = $), M < B.minY && (B.minY = M), $ > B.maxX && (B.maxX = $), M > B.maxY && (B.maxY = M)) : m.set(p, { minX: $, minY: M, maxX: $, maxY: M });
1776
+ for (const h of n) {
1777
+ if (h.vertexCount <= 0) continue;
1778
+ const y = h.layerIndex, w = a ? h.lineweightPx : void 0, _ = Dt(y, w), E = u.get(_), A = c.get(_), U = A, N = h.color[0], C = h.color[1], V = h.color[2];
1779
+ for (let G = 0; G < h.vertexCount; G += 1) {
1780
+ const $ = h.startVertex + G, M = A + G, I = M * d, T = M * 3, P = $ * 2, k = t.pos[P], D = t.pos[P + 1];
1781
+ E.pos[I] = k, E.pos[I + 1] = D, d === 3 && (E.pos[I + 2] = 0), E.col[T] = N, E.col[T + 1] = C, E.col[T + 2] = V;
1782
+ const v = m.get(_);
1783
+ !Number.isFinite(k) || !Number.isFinite(D) ? g.add(_) : v ? (k < v.minX && (v.minX = k), D < v.minY && (v.minY = D), k > v.maxX && (v.maxX = k), D > v.maxY && (v.maxY = D)) : m.set(_, { minX: k, minY: D, maxX: k, maxY: D });
1716
1784
  }
1717
1785
  E.colorRuns.push({
1718
- startVertex: P,
1719
- vertexCount: y.vertexCount,
1720
- color: [N, C, G]
1721
- }), u.set(p, b + y.vertexCount);
1786
+ startVertex: U,
1787
+ vertexCount: h.vertexCount,
1788
+ color: [N, C, V]
1789
+ }), c.set(_, A + h.vertexCount);
1722
1790
  }
1723
- const w = [];
1724
- for (const y of r) {
1725
- const f = c.get(y);
1726
- f && (f.bbox = g.has(y) ? null : mt(m.get(y) ?? null), f.colorRuns = $e(f.colorRuns ?? []), w.push(f));
1791
+ const p = [];
1792
+ for (const h of r) {
1793
+ const y = u.get(h);
1794
+ y && (y.bbox = g.has(h) ? null : ht(m.get(h) ?? null), y.colorRuns = je(y.colorRuns ?? []), p.push(y));
1727
1795
  }
1728
- return w;
1796
+ return p;
1729
1797
  }
1730
- function $t(t, e) {
1798
+ function Dt(t, e) {
1731
1799
  return e === void 0 ? `${t}:` : `${t}:${e}`;
1732
1800
  }
1733
- function gr(t, e) {
1801
+ function br(t, e) {
1734
1802
  return t.append(e);
1735
1803
  }
1736
- function yr(t) {
1804
+ function Ar(t) {
1737
1805
  return t.drain();
1738
1806
  }
1739
- function _r(t) {
1807
+ function Ir(t) {
1740
1808
  const e = [], n = /* @__PURE__ */ new Set();
1741
1809
  for (const r of t)
1742
- fe(e, n, r.pos.buffer), fe(e, n, r.col.buffer);
1810
+ xe(e, n, r.pos.buffer), xe(e, n, r.col.buffer);
1743
1811
  return e;
1744
1812
  }
1745
- function xr(t, e) {
1813
+ function Rr(t, e) {
1746
1814
  const n = new Float32Array(e);
1747
1815
  let r = 0;
1748
1816
  for (const s of t)
1749
1817
  n.set(s, r), r += s.length;
1750
1818
  return n;
1751
1819
  }
1752
- function Be(t, e, n) {
1820
+ function Ke(t, e, n) {
1753
1821
  if (n === 3) return t;
1754
1822
  const r = new Float32Array(e * 3);
1755
1823
  for (let s = 0; s < e; s += 1) {
@@ -1758,26 +1826,26 @@ function Be(t, e, n) {
1758
1826
  }
1759
1827
  return r;
1760
1828
  }
1761
- function le(t) {
1829
+ function _e(t) {
1762
1830
  if (t.positionItemSize === 3) return;
1763
1831
  const e = t.positionItemSize;
1764
- t.posParts = t.posParts.map((n) => Be(n, n.length / e, e)), t.positionItemSize = 3, t.linePositionKind = null;
1832
+ t.posParts = t.posParts.map((n) => Ke(n, n.length / e, e)), t.positionItemSize = 3, t.linePositionKind = null;
1765
1833
  }
1766
- function Er(t, e) {
1834
+ function Vr(t, e) {
1767
1835
  const n = new Uint8Array(e);
1768
1836
  let r = 0;
1769
1837
  for (const s of t)
1770
1838
  n.set(s, r), r += s.length;
1771
1839
  return n;
1772
1840
  }
1773
- function wr(t, e) {
1841
+ function Gr(t, e) {
1774
1842
  return t.map((n) => ({
1775
1843
  startVertex: n.startVertex + e,
1776
1844
  vertexCount: n.vertexCount,
1777
1845
  color: [n.color[0], n.color[1], n.color[2]]
1778
1846
  }));
1779
1847
  }
1780
- function $e(t) {
1848
+ function je(t) {
1781
1849
  const e = [];
1782
1850
  for (const n of t) {
1783
1851
  const r = e[e.length - 1];
@@ -1796,50 +1864,50 @@ function $e(t) {
1796
1864
  }
1797
1865
  return e;
1798
1866
  }
1799
- function pr(t) {
1867
+ function Nr(t) {
1800
1868
  const e = Math.floor(t.length / 3), n = [];
1801
1869
  let r = 0;
1802
1870
  for (; r < e; ) {
1803
1871
  const s = r * 3, o = t[s] ?? 0, i = t[s + 1] ?? 0, a = t[s + 2] ?? 0;
1804
- let c = r + 1;
1805
- for (; c < e; ) {
1806
- const u = c * 3;
1807
- if (t[u] !== o || t[u + 1] !== i || t[u + 2] !== a) break;
1808
- c += 1;
1872
+ let u = r + 1;
1873
+ for (; u < e; ) {
1874
+ const c = u * 3;
1875
+ if (t[c] !== o || t[c + 1] !== i || t[c + 2] !== a) break;
1876
+ u += 1;
1809
1877
  }
1810
- n.push({ startVertex: r, vertexCount: c - r, color: [o, i, a] }), r = c;
1878
+ n.push({ startVertex: r, vertexCount: u - r, color: [o, i, a] }), r = u;
1811
1879
  }
1812
1880
  return n;
1813
1881
  }
1814
- function fe(t, e, n) {
1882
+ function xe(t, e, n) {
1815
1883
  n instanceof ArrayBuffer && (e.has(n) || (e.add(n), t.push(n)));
1816
1884
  }
1817
- function br(t, e, n = "u8") {
1885
+ function Ur(t, e, n = "u8") {
1818
1886
  if (e <= 0 && t.byteLength === 0)
1819
1887
  return { pos: new Float32Array(0), count: 0, segments: [] };
1820
- const { buffer: r, startOffset: s, endOffset: o } = Vr(t), i = new DataView(r), a = pe(r, i, s, e, o, n);
1888
+ const { buffer: r, startOffset: s, endOffset: o } = Pr(t), i = new DataView(r), a = Ne(r, i, s, e, o, n);
1821
1889
  if (a.offset !== o)
1822
- throw new l(
1890
+ throw new f(
1823
1891
  "E_GROUP_RANGE",
1824
1892
  `Insert runtime geometry chunk has trailing bytes: offset=${a.offset - s}, length=${t.byteLength}`
1825
1893
  );
1826
1894
  return a.chunk;
1827
1895
  }
1828
- function Ar(t) {
1896
+ function Cr(t) {
1829
1897
  const e = (n) => {
1830
- const r = t[n], s = br(
1898
+ const r = t[n], s = Ur(
1831
1899
  r.raw,
1832
1900
  r.count,
1833
1901
  r.groupLayerEncoding
1834
- ), o = Te(s, { splitLineweight: n === "line" }), i = /* @__PURE__ */ new Map();
1902
+ ), o = He(s, { splitLineweight: n === "line" }), i = /* @__PURE__ */ new Map();
1835
1903
  for (const a of o)
1836
- i.set(Ir(a.layerIndex, a.lineweightPx), {
1904
+ i.set(Sr(a.layerIndex, a.lineweightPx), {
1837
1905
  layerIndex: a.layerIndex,
1838
1906
  ...a.lineweightPx === void 0 ? {} : { lineweightPx: a.lineweightPx },
1839
1907
  pos: a.pos,
1840
1908
  col: a.col,
1841
1909
  count: a.count,
1842
- bbox: ot(a.bbox)
1910
+ bbox: it(a.bbox)
1843
1911
  });
1844
1912
  return i;
1845
1913
  };
@@ -1849,17 +1917,17 @@ function Ar(t) {
1849
1917
  dot: e("dot")
1850
1918
  };
1851
1919
  }
1852
- function Ir(t, e) {
1920
+ function Sr(t, e) {
1853
1921
  return e === void 0 ? `${t}:` : `${t}:${e}`;
1854
1922
  }
1855
- function Rr(t, e) {
1856
- let n = e ? ot(e) : null;
1923
+ function Tr(t, e) {
1924
+ let n = e ? it(e) : null;
1857
1925
  for (const r of ["line", "fill", "dot"])
1858
1926
  for (const s of t[r].values())
1859
- n = Ae(n, s.bbox);
1927
+ n = Ce(n, s.bbox);
1860
1928
  return n;
1861
1929
  }
1862
- function Vr(t) {
1930
+ function Pr(t) {
1863
1931
  if (t.buffer instanceof ArrayBuffer)
1864
1932
  return {
1865
1933
  buffer: t.buffer,
@@ -1873,22 +1941,22 @@ function Vr(t) {
1873
1941
  endOffset: e.byteOffset + e.byteLength
1874
1942
  };
1875
1943
  }
1876
- function Nr(t) {
1944
+ function Br(t) {
1877
1945
  const e = t.insertRuntime;
1878
1946
  if (!e || e.instances.length === 0) return null;
1879
1947
  const n = [], r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
1880
- for (const c of e.variants) {
1881
- const u = Ar(c), m = Rt(u.line), g = Rt(u.fill), d = Rt(u.dot), h = m.length > 0 || g.length > 0 || d.length > 0;
1882
- r.set(c.id, h ? Rr(u, null) : null), h && (s.add(c.id), n.push({
1883
- variantId: c.id,
1948
+ for (const u of e.variants) {
1949
+ const c = Cr(u), m = Ut(c.line), g = Ut(c.fill), l = Ut(c.dot), d = m.length > 0 || g.length > 0 || l.length > 0;
1950
+ r.set(u.id, d ? Tr(c, null) : null), d && (s.add(u.id), n.push({
1951
+ variantId: u.id,
1884
1952
  line: m,
1885
1953
  fill: g,
1886
- dot: d
1954
+ dot: l
1887
1955
  }));
1888
1956
  }
1889
- const o = e.instances.filter((c) => s.has(c.variantId));
1957
+ const o = e.instances.filter((u) => s.has(u.variantId));
1890
1958
  if (o.length === 0) return null;
1891
- const i = Cr(o, r), a = Pr(n, i);
1959
+ const i = Or(o, r), a = kr(n, i);
1892
1960
  return {
1893
1961
  variants: n,
1894
1962
  instances: i,
@@ -1896,22 +1964,22 @@ function Nr(t) {
1896
1964
  cost: i.count
1897
1965
  };
1898
1966
  }
1899
- function Gr(t) {
1967
+ function $r(t) {
1900
1968
  const e = [], n = /* @__PURE__ */ new Set(), r = (s) => {
1901
1969
  n.has(s) || (n.add(s), e.push(s));
1902
1970
  };
1903
1971
  r(t.instances.meta.buffer), r(t.instances.mats.buffer), r(t.instances.bboxes.buffer);
1904
1972
  for (const s of t.variants)
1905
- Nt(s.line, r), Nt(s.fill, r), Nt(s.dot, r);
1973
+ St(s.line, r), St(s.fill, r), St(s.dot, r);
1906
1974
  return e;
1907
1975
  }
1908
- function Rt(t) {
1976
+ function Ut(t) {
1909
1977
  const e = [];
1910
1978
  for (const n of t.values())
1911
- n.count <= 0 || e.push(Ur(n));
1979
+ n.count <= 0 || e.push(vr(n));
1912
1980
  return e;
1913
1981
  }
1914
- function Ur(t) {
1982
+ function vr(t) {
1915
1983
  return {
1916
1984
  pos: t.pos,
1917
1985
  col: t.col,
@@ -1921,48 +1989,48 @@ function Ur(t) {
1921
1989
  bbox: t.bbox
1922
1990
  };
1923
1991
  }
1924
- function Cr(t, e) {
1992
+ function Or(t, e) {
1925
1993
  const n = t.length, r = new Uint32Array(n * 3), s = new Float32Array(n * 6), o = new Float32Array(n * 4);
1926
1994
  for (let i = 0; i < n; i += 1) {
1927
- const a = t[i], c = i * 3;
1928
- r[c] = a.instanceId, r[c + 1] = a.variantId, r[c + 2] = a.insLayerIdx;
1929
- const u = i * 6;
1930
- s[u] = a.matA, s[u + 1] = a.matB, s[u + 2] = a.matC, s[u + 3] = a.matD, s[u + 4] = a.tx, s[u + 5] = a.ty;
1931
- const m = ur(e.get(a.variantId) ?? null, a);
1932
- Sr(o, i * 4, m);
1995
+ const a = t[i], u = i * 3;
1996
+ r[u] = a.instanceId, r[u + 1] = a.variantId, r[u + 2] = a.insLayerIdx;
1997
+ const c = i * 6;
1998
+ s[c] = a.matA, s[c + 1] = a.matB, s[c + 2] = a.matC, s[c + 3] = a.matD, s[c + 4] = a.tx, s[c + 5] = a.ty;
1999
+ const m = _r(e.get(a.variantId) ?? null, a);
2000
+ Mr(o, i * 4, m);
1933
2001
  }
1934
2002
  return { meta: r, mats: s, bboxes: o, count: n };
1935
2003
  }
1936
- function Sr(t, e, n) {
2004
+ function Mr(t, e, n) {
1937
2005
  if (!n) {
1938
2006
  t[e] = Number.POSITIVE_INFINITY, t[e + 1] = Number.POSITIVE_INFINITY, t[e + 2] = Number.NEGATIVE_INFINITY, t[e + 3] = Number.NEGATIVE_INFINITY;
1939
2007
  return;
1940
2008
  }
1941
2009
  t[e] = n.minX, t[e + 1] = n.minY, t[e + 2] = n.maxX, t[e + 3] = n.maxY;
1942
2010
  }
1943
- function Pr(t, e) {
2011
+ function kr(t, e) {
1944
2012
  let n = e.meta.byteLength + e.mats.byteLength + e.bboxes.byteLength;
1945
2013
  for (const r of t)
1946
- n += Vt(r.line), n += Vt(r.fill), n += Vt(r.dot);
2014
+ n += Ct(r.line), n += Ct(r.fill), n += Ct(r.dot);
1947
2015
  return n;
1948
2016
  }
1949
- function Vt(t) {
2017
+ function Ct(t) {
1950
2018
  return t.reduce((e, n) => e + n.pos.byteLength + n.col.byteLength, 0);
1951
2019
  }
1952
- function Nt(t, e) {
2020
+ function St(t, e) {
1953
2021
  for (const n of t)
1954
2022
  e(n.pos.buffer), e(n.col.buffer);
1955
2023
  }
1956
- function de() {
2024
+ function Ee() {
1957
2025
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1958
2026
  }
1959
- class Tr {
2027
+ class Dr {
1960
2028
  constructor() {
1961
- Z(this, "geometryCredits", 0);
1962
- Z(this, "textCredits", 0);
1963
- Z(this, "cancelled", !1);
1964
- Z(this, "geometryWaiters", []);
1965
- Z(this, "textWaiters", []);
2029
+ Q(this, "geometryCredits", 0);
2030
+ Q(this, "textCredits", 0);
2031
+ Q(this, "cancelled", !1);
2032
+ Q(this, "geometryWaiters", []);
2033
+ Q(this, "textWaiters", []);
1966
2034
  }
1967
2035
  grant(e) {
1968
2036
  this.cancelled || (this.geometryCredits += Math.max(0, e.geometryCredits), this.textCredits += Math.max(0, e.textCredits), this.flushWaiters());
@@ -2006,23 +2074,23 @@ class Tr {
2006
2074
  return e === "geometry" ? this.geometryWaiters : this.textWaiters;
2007
2075
  }
2008
2076
  }
2009
- const me = 262144, Br = Number.MAX_SAFE_INTEGER, he = 524288, $r = Number.MAX_SAFE_INTEGER, Or = 5e6, Mr = 64, z = self;
2010
- let k = null, ge = null;
2011
- async function Gt(t, e, n) {
2012
- const r = yr(e);
2077
+ const we = 262144, Lr = Number.MAX_SAFE_INTEGER, pe = 524288, Fr = Number.MAX_SAFE_INTEGER, Xr = 5e6, Yr = 64, H = self;
2078
+ let X = null, be = null, Tt = null;
2079
+ async function Pt(t, e, n) {
2080
+ const r = Ar(e);
2013
2081
  if (!r.length || !await n.take("geometry")) return 0;
2014
- const o = r.reduce((a, c) => a + c.count, 0), i = {
2082
+ const o = r.reduce((a, u) => a + u.count, 0), i = {
2015
2083
  type: "geometry",
2016
2084
  kind: t,
2017
2085
  layers: r,
2018
2086
  cost: o
2019
2087
  };
2020
- return z.postMessage(i, _r(r)), o;
2088
+ return H.postMessage(i, Ir(r)), o;
2021
2089
  }
2022
- async function vr(t, e) {
2023
- return await Gt("line", t.line, e) + await Gt("fill", t.fill, e) + await Gt("dot", t.dot, e);
2090
+ async function zr(t, e) {
2091
+ return await Pt("line", t.line, e) + await Pt("fill", t.fill, e) + await Pt("dot", t.dot, e);
2024
2092
  }
2025
- async function ye(t, e) {
2093
+ async function Ae(t, e) {
2026
2094
  if (!t.length || !await e.take("text")) return 0;
2027
2095
  const r = t.slice();
2028
2096
  t.length = 0;
@@ -2031,139 +2099,142 @@ async function ye(t, e) {
2031
2099
  texts: r,
2032
2100
  cost: r.length
2033
2101
  };
2034
- return z.postMessage(s), r.length;
2102
+ return H.postMessage(s), r.length;
2035
2103
  }
2036
- function Dr(t) {
2104
+ function Hr(t) {
2037
2105
  return t.lineCount + t.fillCount + t.dotCount;
2038
2106
  }
2039
- function kr(t, e) {
2040
- return Dr(t) >= Or ? {
2041
- initial: he,
2042
- steady: e ? he : $r
2107
+ function Kr(t, e) {
2108
+ return Hr(t) >= Xr ? {
2109
+ initial: pe,
2110
+ steady: e ? pe : Fr
2043
2111
  } : {
2044
- initial: me,
2045
- steady: e ? me : Br
2112
+ initial: we,
2113
+ steady: e ? we : Lr
2046
2114
  };
2047
2115
  }
2048
- function Lr(t) {
2116
+ function jr(t) {
2049
2117
  return t instanceof Error ? t : new Error(String(t));
2050
2118
  }
2051
- function Fr(t) {
2119
+ function Wr(t) {
2052
2120
  if (!(!t || t.length === 0))
2053
2121
  return new Map(t.map((e) => [e.variantId, e.buffer]));
2054
2122
  }
2055
- function Xr(t) {
2123
+ function qr(t) {
2056
2124
  if (t !== void 0)
2057
2125
  return new Set(t);
2058
2126
  }
2059
- async function Yr(t, e, n) {
2060
- const r = Fr(e);
2127
+ async function Jr(t, e, n) {
2128
+ const r = Wr(e);
2061
2129
  if (!t || !n || n.length === 0)
2062
2130
  return r;
2063
- const s = Array.from(new Set(n)).filter((a) => !(r != null && r.has(a))).sort((a, c) => a - c);
2131
+ const s = Array.from(new Set(n)).filter((a) => !(r != null && r.has(a))).sort((a, u) => a - u);
2064
2132
  if (s.length === 0)
2065
2133
  return r;
2066
- const o = await lr({
2134
+ const o = await xr({
2067
2135
  baseUrl: t.baseUrl,
2068
2136
  entries: t.entries,
2069
2137
  requiredVariantIds: s
2070
2138
  }), i = new Map(r ?? []);
2071
- for (const [a, c] of o.buffers)
2072
- i.set(a, c);
2139
+ for (const [a, u] of o.buffers)
2140
+ i.set(a, u);
2073
2141
  return i;
2074
2142
  }
2075
- async function zr(t, e, n, r, s = !0, o, i, a, c, u, m, g, d) {
2076
- const h = mr(), w = [];
2077
- let y = 0, f = !1;
2078
- const x = c === !0, p = typeof i == "number" && Number.isFinite(i) && i >= 0, E = await Yr(
2143
+ async function Zr(t, e, n, r, s = !0, o, i, a, u, c, m, g, l, d, p = !1) {
2144
+ const h = wr(), y = [];
2145
+ let w = 0, _ = !1;
2146
+ const E = u === !0, A = typeof i == "number" && Number.isFinite(i) && i >= 0, U = await Jr(
2079
2147
  a,
2080
- u,
2148
+ c,
2081
2149
  g
2082
- ), b = Xr(m), P = n && n.length > 0 || r === !0 || s === !1 || o === !0 || p || x || E || b !== void 0 || d === !0 ? {
2150
+ ), N = qr(m), C = n && n.length > 0 || r === !0 || s === !1 || o === !0 || A || E || U || N !== void 0 || l === !0 || d === !0 ? {
2083
2151
  ...n && n.length > 0 ? { hiddenInstanceIds: new Set(n) } : {},
2084
2152
  ...r === !0 ? { keepTextsForHiddenInstances: !0 } : {},
2085
2153
  ...s === !1 ? { loadBlocks: !1 } : {},
2086
2154
  ...o === !0 ? { suppressExpandedInsertGeometry: !0 } : {},
2087
- ...p ? { maxExpandedInstanceVertices: i } : {},
2088
- ...x ? { deferExternalVariantGeometry: !0 } : {},
2089
- ...E ? { externalVariantBuffers: E } : {},
2090
- ...b !== void 0 ? { requiredExternalVariantIds: b } : {},
2091
- ...d === !0 ? { externalVariantDeltaOnly: !0 } : {}
2092
- } : void 0, N = cr(t, P), C = kr(N.header, d === !0);
2093
- z.postMessage({
2155
+ ...A ? { maxExpandedInstanceVertices: i } : {},
2156
+ ...E ? { deferExternalVariantGeometry: !0 } : {},
2157
+ ...U ? { externalVariantBuffers: U } : {},
2158
+ ...N !== void 0 ? { requiredExternalVariantIds: N } : {},
2159
+ ...l === !0 ? { externalVariantDeltaOnly: !0 } : {},
2160
+ ...d === !0 ? { cacheDocument: !0 } : {}
2161
+ } : void 0, V = p && Tt ? hr(t, Tt, C) : ze(t, C);
2162
+ p || (Tt = V.documentCache ?? null);
2163
+ const G = Kr(V.header, l === !0);
2164
+ H.postMessage({
2094
2165
  type: "header",
2095
- header: N.header
2166
+ header: V.header
2096
2167
  });
2097
- const G = async () => {
2098
- const V = await vr(h, e);
2099
- return y = 0, V > 0 && (f = !0), V;
2168
+ const $ = async () => {
2169
+ const T = await zr(h, e);
2170
+ return w = 0, T > 0 && (_ = !0), T;
2100
2171
  };
2101
- for (const V of N.chunks) {
2102
- if (V.kind === "text") {
2103
- w.push(V.payload), w.length >= Mr && await ye(w, e);
2172
+ for (const T of V.chunks) {
2173
+ if (T.kind === "text") {
2174
+ y.push(T.payload), y.length >= Yr && await Ae(y, e);
2104
2175
  continue;
2105
2176
  }
2106
- const F = Te(V.payload, {
2107
- markLinePositionXy: V.kind === "line"
2177
+ const P = He(T.payload, {
2178
+ markLinePositionXy: T.kind === "line"
2108
2179
  });
2109
- y += gr(h[V.kind], F);
2110
- const X = f ? C.steady : C.initial;
2111
- y >= X && await G();
2180
+ w += br(h[T.kind], P);
2181
+ const k = _ ? G.steady : G.initial;
2182
+ w >= k && await $();
2112
2183
  }
2113
- await G(), await ye(w, e), z.postMessage({ type: "done" });
2114
- const U = de(), R = Nr(N.header);
2115
- R && z.postMessage(
2184
+ await $(), await Ae(y, e), H.postMessage({ type: "done" });
2185
+ const M = Ee(), I = Br(V.header);
2186
+ I && H.postMessage(
2116
2187
  {
2117
2188
  type: "insertModel",
2118
- variants: R.variants,
2119
- instances: R.instances,
2120
- cost: R.cost,
2121
- bytes: R.bytes,
2122
- planMs: de() - U
2189
+ variants: I.variants,
2190
+ instances: I.instances,
2191
+ cost: I.cost,
2192
+ bytes: I.bytes,
2193
+ planMs: Ee() - M
2123
2194
  },
2124
- Gr(R)
2125
- ), z.postMessage({ type: "complete" });
2195
+ $r(I)
2196
+ ), H.postMessage({ type: "complete" });
2126
2197
  }
2127
2198
  self.addEventListener("message", (t) => {
2128
2199
  const e = t.data;
2129
2200
  if (!e) return;
2130
2201
  if (e.type === "grant") {
2131
- k == null || k.grant({
2202
+ X == null || X.grant({
2132
2203
  geometryCredits: e.geometryCredits,
2133
2204
  textCredits: e.textCredits
2134
2205
  });
2135
2206
  return;
2136
2207
  }
2137
2208
  if (e.type === "cancel") {
2138
- k == null || k.cancel();
2209
+ X == null || X.cancel();
2139
2210
  return;
2140
2211
  }
2141
2212
  if (e.type !== "parse") return;
2142
- const n = new Tr();
2143
- k = n;
2213
+ const n = new Dr();
2214
+ X = n;
2144
2215
  const r = e.useRetainedMainBuffer === !0;
2145
2216
  if (r && e.buffer !== void 0) {
2146
2217
  const o = new Error("Geo prepare worker parse request cannot include both a retained and transferred main buffer");
2147
- o.code = "E_MAIN_BUFFER_PROTOCOL", z.postMessage({
2218
+ o.code = "E_MAIN_BUFFER_PROTOCOL", H.postMessage({
2148
2219
  type: "error",
2149
2220
  message: o.message,
2150
2221
  code: "E_MAIN_BUFFER_PROTOCOL"
2151
- }), k = null;
2222
+ }), X = null;
2152
2223
  return;
2153
2224
  }
2154
- const s = r ? ge : e.buffer;
2225
+ const s = r ? be : e.buffer;
2155
2226
  if (!s) {
2156
2227
  const o = new Error(
2157
2228
  r ? "Geo prepare worker has no retained main buffer for this delta parse" : "Geo prepare worker parse request is missing its main buffer"
2158
2229
  );
2159
- o.code = "E_MAIN_BUFFER_MISSING", z.postMessage({
2230
+ o.code = "E_MAIN_BUFFER_MISSING", H.postMessage({
2160
2231
  type: "error",
2161
2232
  message: o.message,
2162
2233
  code: "E_MAIN_BUFFER_MISSING"
2163
- }), k = null;
2234
+ }), X = null;
2164
2235
  return;
2165
2236
  }
2166
- r || (ge = s), zr(
2237
+ r || (be = s), Zr(
2167
2238
  s,
2168
2239
  n,
2169
2240
  e.hiddenInstanceIds,
@@ -2176,15 +2247,17 @@ self.addEventListener("message", (t) => {
2176
2247
  e.externalVariantBuffers,
2177
2248
  e.requiredExternalVariantIds,
2178
2249
  e.externalVariantGeometryFetchIds,
2179
- e.externalVariantDeltaOnly
2250
+ e.externalVariantDeltaOnly,
2251
+ e.cacheDocument,
2252
+ r
2180
2253
  ).catch((o) => {
2181
- const i = Lr(o), a = i.code;
2182
- z.postMessage({
2254
+ const i = jr(o), a = i.code;
2255
+ H.postMessage({
2183
2256
  type: "error",
2184
2257
  message: i.message,
2185
2258
  code: typeof a == "string" ? a : void 0
2186
2259
  });
2187
2260
  }).finally(() => {
2188
- k === n && (k = null);
2261
+ X === n && (X = null);
2189
2262
  });
2190
2263
  });