@nebula-spatial/cad-loader 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +46 -0
  2. package/dist/core/cad-types.d.ts +26 -0
  3. package/dist/core/errors.d.ts +5 -0
  4. package/dist/core/index.d.ts +24 -0
  5. package/dist/core/index.js +2262 -0
  6. package/dist/core/parser/bin-group-reader.d.ts +9 -0
  7. package/dist/core/parser/bin-parser.d.ts +65 -0
  8. package/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  9. package/dist/core/parser/geometry-segments.d.ts +20 -0
  10. package/dist/core/parser/text-roundtrip.d.ts +4 -0
  11. package/dist/core/parser/types.d.ts +80 -0
  12. package/dist/core/runtime-text-decoder.d.ts +8 -0
  13. package/dist/core/types.d.ts +147 -0
  14. package/dist/core/utils/insert-bbox.d.ts +10 -0
  15. package/dist/core/utils/viewport-rect.d.ts +21 -0
  16. package/dist/index.d.ts +26 -0
  17. package/dist/index.js +4435 -0
  18. package/dist/loader/geo-loader.d.ts +56 -0
  19. package/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  20. package/dist/loader/internal/flow-control.d.ts +29 -0
  21. package/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  22. package/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  23. package/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  24. package/dist/loader/internal/geo-loader-pipeline.d.ts +81 -0
  25. package/dist/loader/internal/geo-loader-worker-adapter.d.ts +7 -0
  26. package/dist/loader/internal/geo-node-builder.d.ts +29 -0
  27. package/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  28. package/dist/loader/internal/geo-node.d.ts +284 -0
  29. package/dist/loader/internal/geo-prepare-worker-types.d.ts +87 -0
  30. package/dist/loader/internal/geo-prepare.d.ts +38 -0
  31. package/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  32. package/dist/loader/internal/insert-model-builder.d.ts +10 -0
  33. package/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  34. package/dist/loader/internal/line-canonical.d.ts +37 -0
  35. package/dist/loader/internal/line-quality.d.ts +9 -0
  36. package/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  37. package/dist/loader/internal/transport.d.ts +2 -0
  38. package/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  39. package/dist/scene/geo-cad-line-material.d.ts +18 -0
  40. package/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  41. package/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  42. package/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  43. package/dist/selection/cad-insert-selection.d.ts +35 -0
  44. package/dist/session/load-session.d.ts +90 -0
  45. package/dist/shared/abort.d.ts +3 -0
  46. package/dist/shared/cad-display-color.d.ts +55 -0
  47. package/dist/shared/cad-load-source.d.ts +8 -0
  48. package/dist/shared/color-buffer.d.ts +6 -0
  49. package/dist/shared/constants.d.ts +11 -0
  50. package/dist/shared/display-color-buffer.d.ts +27 -0
  51. package/dist/shared/errors.d.ts +2 -0
  52. package/dist/shared/text-font.d.ts +12 -0
  53. package/dist/shared/types.d.ts +57 -0
  54. package/dist/shared/utils/insert-bbox.d.ts +1 -0
  55. package/dist/shared/utils/timing.d.ts +2 -0
  56. package/dist/shared/utils/viewport-rect.d.ts +1 -0
  57. package/dist/shared/viewer-theme.d.ts +2 -0
  58. package/dist/workers/geo-prepare.worker.js +2166 -0
  59. package/package.json +61 -0
package/dist/index.js ADDED
@@ -0,0 +1,4435 @@
1
+ var Zn = Object.defineProperty;
2
+ var Lt = (t) => {
3
+ throw TypeError(t);
4
+ };
5
+ var Jn = (t, n, e) => n in t ? Zn(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
6
+ var m = (t, n, e) => Jn(t, typeof n != "symbol" ? n + "" : n, e), Ke = (t, n, e) => n.has(t) || Lt("Cannot " + e);
7
+ var p = (t, n, e) => (Ke(t, n, "read from private field"), e ? e.call(t) : n.get(t)), B = (t, n, e) => n.has(t) ? Lt("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(t) : n.set(t, e), k = (t, n, e, r) => (Ke(t, n, "write to private field"), r ? r.call(t, e) : n.set(t, e), e), R = (t, n, e) => (Ke(t, n, "access private method"), e);
8
+ import { CadPackError as A, normalizeGeometrySegments as er, normalizeViewportRect as yt, cloneViewportRect as _e, mergeViewportRects as Le, readGroup as tr, transformBBoxByInstance as nr, parseBinStreaming as mt, isStrictTextRoundtripEnabled as rr, assertStrictTextRoundtrip as ir, computeViewportRectFromPositions as Me, expandViewportRect as ar, viewportRectEquals as sr, viewportRectIntersects as or, viewportRectContains as lr, transformViewportRect as cr, parseBinPayload as ur, parseBinBounds as dr, readExternalAnnotationManifest as yn, readExternalBlockAnnotations as mn, readExternalVariantDependencyPlan as xn, readExternalVariantManifest as hr, readSceneAnnotationSidecar as fr } from "./core/index.js";
9
+ import { readBlockAnnotationSidecar as Ts } from "./core/index.js";
10
+ import { BufferAttribute as U, RawShaderMaterial as yr, Color as pn, Vector2 as gn, DoubleSide as st, BufferGeometry as xt, LineSegments as pt, InstancedInterleavedBuffer as Mt, InstancedBufferGeometry as bn, Float32BufferAttribute as Cn, InterleavedBufferAttribute as Te, Mesh as gt, Vector3 as Ye, Box3 as mr, Sphere as xr, Object3D as In, InstancedBufferAttribute as ce, Points as wn, Group as j, PointsMaterial as Dt, LineBasicMaterial as Ft, MeshBasicMaterial as Ot } from "three";
11
+ import { BatchedText as Gt, Text as pr } from "troika-three-text";
12
+ import gr from "rbush";
13
+ const bt = 16.7, Ct = 6, It = 128 * 1024 * 1024, wt = 64 * 1024 * 1024, vt = 2, Rt = 1, br = 3e5, Cr = 22e4, _t = 2;
14
+ function te(t, n = "CAD load aborted") {
15
+ if (t instanceof Error && t.name === "AbortError") return t;
16
+ const e = typeof t == "string" && t.length > 0 ? t : n, r = new Error(e, t === void 0 ? void 0 : { cause: t });
17
+ return r.name = "AbortError", r;
18
+ }
19
+ function zt(t, n) {
20
+ if (!t) return () => {
21
+ };
22
+ if (t.aborted)
23
+ return n.abort(t.reason), () => {
24
+ };
25
+ const e = () => n.abort(t.reason);
26
+ return t.addEventListener("abort", e, { once: !0 }), () => t.removeEventListener("abort", e);
27
+ }
28
+ function Ir(t, n, e = "CAD load aborted") {
29
+ return n.aborted ? Promise.reject(te(n.reason, e)) : new Promise((r, i) => {
30
+ const a = () => {
31
+ s(), i(te(n.reason, e));
32
+ }, s = () => n.removeEventListener("abort", a);
33
+ n.addEventListener("abort", a, { once: !0 }), t.then(
34
+ (o) => {
35
+ s(), r(o);
36
+ },
37
+ (o) => {
38
+ s(), i(o);
39
+ }
40
+ );
41
+ });
42
+ }
43
+ function Ne(t) {
44
+ return typeof t == "object" && t !== null;
45
+ }
46
+ function Ut(t) {
47
+ return Ne(t) && typeof t.arrayBuffer == "function";
48
+ }
49
+ function wr(t) {
50
+ return typeof URL == "function" && t instanceof URL;
51
+ }
52
+ function vr(t) {
53
+ return Ne(t) && typeof t.aborted == "boolean" && typeof t.addEventListener == "function" && typeof t.removeEventListener == "function";
54
+ }
55
+ function Bt(t, n) {
56
+ if (t instanceof ArrayBuffer)
57
+ return { source: { kind: "buffer", buffer: t } };
58
+ if (typeof t == "string" || wr(t)) {
59
+ const r = String(t);
60
+ if (r.trim().length === 0)
61
+ throw new A("E_SOURCE", "URL source must include a non-empty URL");
62
+ return { source: { kind: "url", url: r, signal: n } };
63
+ }
64
+ if (Ut(t) && !("kind" in t))
65
+ return { source: { kind: "packFile", file: t } };
66
+ if (!Ne(t))
67
+ throw new A("E_SOURCE", "CAD load source must be an ArrayBuffer, File, URL, or source object");
68
+ const e = t;
69
+ switch (e.kind) {
70
+ case "buffer":
71
+ if (!(e.buffer instanceof ArrayBuffer))
72
+ throw new A("E_SOURCE", "Buffer source must include an ArrayBuffer");
73
+ return { source: { kind: "buffer", buffer: e.buffer } };
74
+ case "packFile":
75
+ if (!Ut(e.file))
76
+ throw new A("E_SOURCE", "Pack file source must include a File-like object");
77
+ return { source: { kind: "packFile", file: e.file } };
78
+ case "url": {
79
+ if (typeof e.url != "string" || e.url.trim().length === 0)
80
+ throw new A("E_SOURCE", "URL source must include a non-empty URL");
81
+ const r = vr(e.signal) ? e.signal : void 0;
82
+ return {
83
+ source: { kind: "url", url: e.url, signal: n },
84
+ sourceSignal: r
85
+ };
86
+ }
87
+ default:
88
+ throw new A("E_SOURCE", `Unsupported CAD load source kind: ${String(e.kind)}`);
89
+ }
90
+ }
91
+ function Rr(t) {
92
+ if (!Ne(t) || typeof t.kind != "string")
93
+ throw new A("E_SOURCE", "Geo source must be an object");
94
+ Bt(t, new AbortController().signal);
95
+ }
96
+ function ot() {
97
+ return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
98
+ }
99
+ function Br(t) {
100
+ if (typeof queueMicrotask == "function") {
101
+ queueMicrotask(t);
102
+ return;
103
+ }
104
+ Promise.resolve().then(t);
105
+ }
106
+ class vn {
107
+ constructor(n) {
108
+ m(this, "highWatermarkBytes");
109
+ m(this, "lowWatermarkBytes");
110
+ m(this, "initialGeometryCredits");
111
+ m(this, "initialTextCredits");
112
+ m(this, "queuedBytes", 0);
113
+ m(this, "paused", !1);
114
+ m(this, "initialGranted", !1);
115
+ this.highWatermarkBytes = Math.max(0, n.highWatermarkBytes), this.lowWatermarkBytes = Math.max(0, Math.min(n.lowWatermarkBytes, this.highWatermarkBytes)), this.initialGeometryCredits = Math.max(0, n.initialGeometryCredits), this.initialTextCredits = Math.max(0, n.initialTextCredits);
116
+ }
117
+ takeInitialGrant() {
118
+ return this.initialGranted ? { geometryCredits: 0, textCredits: 0 } : (this.initialGranted = !0, {
119
+ geometryCredits: this.initialGeometryCredits,
120
+ textCredits: this.initialTextCredits
121
+ });
122
+ }
123
+ onQueued(n, e) {
124
+ this.queuedBytes += Math.max(0, e), this.queuedBytes > this.highWatermarkBytes && (this.paused = !0);
125
+ }
126
+ onConsumed(n, e) {
127
+ return this.queuedBytes = Math.max(0, this.queuedBytes - Math.max(0, e)), this.paused && this.shouldStayPaused() ? { geometryCredits: 0, textCredits: 0, paused: !0 } : this.paused ? (this.paused = !1, {
128
+ geometryCredits: n === "geometry" ? 1 : 0,
129
+ textCredits: n === "text" ? 1 : 0,
130
+ paused: !1
131
+ }) : {
132
+ geometryCredits: n === "geometry" ? 1 : 0,
133
+ textCredits: n === "text" ? 1 : 0,
134
+ paused: !1
135
+ };
136
+ }
137
+ getQueuedBytes() {
138
+ return this.queuedBytes;
139
+ }
140
+ shouldStayPaused() {
141
+ return this.lowWatermarkBytes === 0 ? this.queuedBytes > 0 : this.queuedBytes >= this.lowWatermarkBytes;
142
+ }
143
+ }
144
+ async function Rn(t) {
145
+ const n = Nt(), e = t.fetchImpl ?? fetch, r = new Map(
146
+ t.entries.map((l) => [l.id, l])
147
+ ), i = Array.from(new Set(t.requiredVariantIds)).sort((l, u) => l - u), a = /* @__PURE__ */ new Map(), s = Sr(t.concurrency);
148
+ let o = 0;
149
+ async function c() {
150
+ for (; o < i.length; ) {
151
+ const l = i[o++], u = r.get(l);
152
+ if (!u)
153
+ throw new Error(`External block ${l} is missing from manifest`);
154
+ const d = new URL(u.href, t.baseUrl).href, h = await e(d, { signal: t.signal });
155
+ if (!h.ok) {
156
+ const b = "status" in h ? h.status : void 0, g = "statusText" in h ? h.statusText : void 0, C = [b, g].filter((v) => v !== void 0 && v !== "").join(" ");
157
+ throw new Error(`External block ${l} fetch failed${C ? `: ${C}` : ""}`);
158
+ }
159
+ const f = await h.arrayBuffer();
160
+ if (f.byteLength !== u.raw_size)
161
+ throw new Error(
162
+ `External block ${l} raw_size mismatch: manifest=${u.raw_size}, response=${f.byteLength}`
163
+ );
164
+ a.set(l, f);
165
+ }
166
+ }
167
+ return await Promise.all(Array.from({ length: Math.min(s, i.length) }, c)), { buffers: a, fetchMs: Nt() - n };
168
+ }
169
+ function Sr(t) {
170
+ const n = Math.floor(t ?? 3);
171
+ return Number.isFinite(n) ? Math.max(1, Math.min(n, 8)) : 3;
172
+ }
173
+ function Nt() {
174
+ var t, n;
175
+ return ((n = (t = globalThis.performance) == null ? void 0 : t.now) == null ? void 0 : n.call(t)) ?? Date.now();
176
+ }
177
+ var Z;
178
+ class Er {
179
+ constructor() {
180
+ B(this, Z, /* @__PURE__ */ new Map());
181
+ }
182
+ get size() {
183
+ return p(this, Z).size;
184
+ }
185
+ append(n) {
186
+ let e = 0;
187
+ for (const r of n) {
188
+ if (r.count <= 0) continue;
189
+ const i = lt(r.layerIndex, r.lineweightPx);
190
+ let a = p(this, Z).get(i), s = r.pos, o = r.positionItemSize;
191
+ const c = r.linePositionKind ?? null;
192
+ a ? a.positionItemSize !== o && (Ht(a), o !== 3 && (s = Sn(s, r.count, o)), a.positionItemSize = 3, o = 3, a.linePositionKind = null) : (a = {
193
+ layerIndex: r.layerIndex,
194
+ ...r.lineweightPx === void 0 ? {} : { lineweightPx: r.lineweightPx },
195
+ posParts: [],
196
+ positionItemSize: o,
197
+ colParts: [],
198
+ colorRunParts: [],
199
+ linePositionKind: c,
200
+ count: 0,
201
+ bbox: null
202
+ }, p(this, Z).set(i, a));
203
+ const l = a.count > 0;
204
+ a.posParts.push(s), a.colParts.push(r.col);
205
+ const u = Mr(
206
+ r.colorRuns ?? Dr(r.col),
207
+ a.count
208
+ );
209
+ a.colorRunParts.push(u), a.linePositionKind !== c && (a.linePositionKind = null), a.positionItemSize === 2 && a.linePositionKind === null && Ht(a), a.count += r.count, a.bbox = l && a.bbox === null ? null : kr(a.bbox, r.bbox), e += r.count;
210
+ }
211
+ return e;
212
+ }
213
+ drain() {
214
+ const n = [];
215
+ for (const e of p(this, Z).values()) {
216
+ if (e.count <= 0) continue;
217
+ const r = e.posParts.length === 1 ? e.posParts[0] : Pr(e.posParts, e.count * e.positionItemSize), i = e.colParts.length === 1 ? e.colParts[0] : Lr(e.colParts, e.count * 3), a = En(e.colorRunParts.flat()), s = {
218
+ layerIndex: e.layerIndex,
219
+ pos: r,
220
+ positionItemSize: e.positionItemSize,
221
+ col: i,
222
+ count: e.count,
223
+ bbox: yt(e.bbox),
224
+ colorRuns: a
225
+ };
226
+ e.lineweightPx !== void 0 && (s.lineweightPx = e.lineweightPx), e.linePositionKind && (s.linePositionKind = e.linePositionKind), n.push(s);
227
+ }
228
+ return p(this, Z).clear(), n;
229
+ }
230
+ }
231
+ Z = new WeakMap();
232
+ function Xe() {
233
+ return new Er();
234
+ }
235
+ function Vr() {
236
+ return {
237
+ line: Xe(),
238
+ fill: Xe(),
239
+ dot: Xe()
240
+ };
241
+ }
242
+ function kr(t, n) {
243
+ const e = yt(n);
244
+ return t ? e ? {
245
+ minX: Math.min(t.minX, e.minX),
246
+ minY: Math.min(t.minY, e.minY),
247
+ maxX: Math.max(t.maxX, e.maxX),
248
+ maxY: Math.max(t.maxY, e.maxY)
249
+ } : null : e;
250
+ }
251
+ function de(t, n = {}) {
252
+ if (t.count <= 0) return [];
253
+ const e = er(t), r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), o = n.markLinePositionXy === !0 || n.splitLineweight === !0;
254
+ for (const g of e) {
255
+ if (g.vertexCount <= 0) continue;
256
+ const C = g.layerIndex, v = o ? g.lineweightPx : void 0, x = lt(C, v), I = i.get(x);
257
+ I === void 0 ? (i.set(x, g.vertexCount), a.set(x, C), s.set(x, v), r.push(x)) : i.set(x, I + g.vertexCount);
258
+ }
259
+ const c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), h = n.markLinePositionXy === !0 ? "xy-zero-z" : void 0, f = h ? 2 : 3;
260
+ for (const g of r) {
261
+ const C = a.get(g), v = s.get(g), x = i.get(g) ?? 0, I = {
262
+ layerIndex: C,
263
+ ...v === void 0 ? {} : { lineweightPx: v },
264
+ pos: new Float32Array(x * f),
265
+ positionItemSize: f,
266
+ col: new Uint8Array(x * 3),
267
+ count: x,
268
+ bbox: null,
269
+ colorRuns: []
270
+ };
271
+ h && (I.linePositionKind = h), c.set(g, I), l.set(g, 0), u.set(g, null);
272
+ }
273
+ for (const g of e) {
274
+ if (g.vertexCount <= 0) continue;
275
+ const C = g.layerIndex, v = o ? g.lineweightPx : void 0, x = lt(C, v), I = c.get(x), V = l.get(x), M = V, Q = g.color[0], q = g.color[1], W = g.color[2];
276
+ for (let N = 0; N < g.vertexCount; N += 1) {
277
+ const G = g.startVertex + N, $ = V + N, H = $ * f, ae = $ * 3, se = G * 2, F = t.pos[se], _ = t.pos[se + 1];
278
+ I.pos[H] = F, I.pos[H + 1] = _, f === 3 && (I.pos[H + 2] = 0), I.col[ae] = Q, I.col[ae + 1] = q, I.col[ae + 2] = W;
279
+ const D = u.get(x);
280
+ !Number.isFinite(F) || !Number.isFinite(_) ? d.add(x) : D ? (F < D.minX && (D.minX = F), _ < D.minY && (D.minY = _), F > D.maxX && (D.maxX = F), _ > D.maxY && (D.maxY = _)) : u.set(x, { minX: F, minY: _, maxX: F, maxY: _ });
281
+ }
282
+ I.colorRuns.push({
283
+ startVertex: M,
284
+ vertexCount: g.vertexCount,
285
+ color: [Q, q, W]
286
+ }), l.set(x, V + g.vertexCount);
287
+ }
288
+ const b = [];
289
+ for (const g of r) {
290
+ const C = c.get(g);
291
+ C && (C.bbox = d.has(g) ? null : yt(u.get(g) ?? null), C.colorRuns = En(C.colorRuns ?? []), b.push(C));
292
+ }
293
+ return b;
294
+ }
295
+ function lt(t, n) {
296
+ return n === void 0 ? `${t}:` : `${t}:${n}`;
297
+ }
298
+ function Ar(t, n) {
299
+ return t.append(n);
300
+ }
301
+ function Tr(t) {
302
+ return t.drain();
303
+ }
304
+ function Bn(t) {
305
+ return t.reduce((n, e) => n + e.pos.byteLength + e.col.byteLength, 0);
306
+ }
307
+ function Pr(t, n) {
308
+ const e = new Float32Array(n);
309
+ let r = 0;
310
+ for (const i of t)
311
+ e.set(i, r), r += i.length;
312
+ return e;
313
+ }
314
+ function Sn(t, n, e) {
315
+ if (e === 3) return t;
316
+ const r = new Float32Array(n * 3);
317
+ for (let i = 0; i < n; i += 1) {
318
+ const a = i * 2, s = i * 3;
319
+ r[s] = t[a] ?? 0, r[s + 1] = t[a + 1] ?? 0, r[s + 2] = 0;
320
+ }
321
+ return r;
322
+ }
323
+ function Ht(t) {
324
+ if (t.positionItemSize === 3) return;
325
+ const n = t.positionItemSize;
326
+ t.posParts = t.posParts.map((e) => Sn(e, e.length / n, n)), t.positionItemSize = 3, t.linePositionKind = null;
327
+ }
328
+ function Lr(t, n) {
329
+ const e = new Uint8Array(n);
330
+ let r = 0;
331
+ for (const i of t)
332
+ e.set(i, r), r += i.length;
333
+ return e;
334
+ }
335
+ function Mr(t, n) {
336
+ return t.map((e) => ({
337
+ startVertex: e.startVertex + n,
338
+ vertexCount: e.vertexCount,
339
+ color: [e.color[0], e.color[1], e.color[2]]
340
+ }));
341
+ }
342
+ function En(t) {
343
+ const n = [];
344
+ for (const e of t) {
345
+ const r = n[n.length - 1];
346
+ if (r && r.startVertex + r.vertexCount === e.startVertex && r.color[0] === e.color[0] && r.color[1] === e.color[1] && r.color[2] === e.color[2]) {
347
+ n[n.length - 1] = {
348
+ ...r,
349
+ vertexCount: r.vertexCount + e.vertexCount
350
+ };
351
+ continue;
352
+ }
353
+ n.push({
354
+ startVertex: e.startVertex,
355
+ vertexCount: e.vertexCount,
356
+ color: [e.color[0], e.color[1], e.color[2]]
357
+ });
358
+ }
359
+ return n;
360
+ }
361
+ function Dr(t) {
362
+ const n = Math.floor(t.length / 3), e = [];
363
+ let r = 0;
364
+ for (; r < n; ) {
365
+ const i = r * 3, a = t[i] ?? 0, s = t[i + 1] ?? 0, o = t[i + 2] ?? 0;
366
+ let c = r + 1;
367
+ for (; c < n; ) {
368
+ const l = c * 3;
369
+ if (t[l] !== a || t[l + 1] !== s || t[l + 2] !== o) break;
370
+ c += 1;
371
+ }
372
+ e.push({ startVertex: r, vertexCount: c - r, color: [a, s, o] }), r = c;
373
+ }
374
+ return e;
375
+ }
376
+ function Fr(t, n, e = "u8") {
377
+ if (n <= 0 && t.byteLength === 0)
378
+ return { pos: new Float32Array(0), count: 0, segments: [] };
379
+ const { buffer: r, startOffset: i, endOffset: a } = zr(t), s = new DataView(r), o = tr(r, s, i, n, a, e);
380
+ if (o.offset !== a)
381
+ throw new A(
382
+ "E_GROUP_RANGE",
383
+ `Insert runtime geometry chunk has trailing bytes: offset=${o.offset - i}, length=${t.byteLength}`
384
+ );
385
+ return o.chunk;
386
+ }
387
+ function Or(t) {
388
+ const n = (e) => {
389
+ const r = t[e], i = Fr(
390
+ r.raw,
391
+ r.count,
392
+ r.groupLayerEncoding
393
+ ), a = de(i, { splitLineweight: e === "line" }), s = /* @__PURE__ */ new Map();
394
+ for (const o of a)
395
+ s.set(Gr(o.layerIndex, o.lineweightPx), {
396
+ layerIndex: o.layerIndex,
397
+ ...o.lineweightPx === void 0 ? {} : { lineweightPx: o.lineweightPx },
398
+ pos: o.pos,
399
+ col: o.col,
400
+ count: o.count,
401
+ bbox: _e(o.bbox)
402
+ });
403
+ return s;
404
+ };
405
+ return {
406
+ line: n("line"),
407
+ fill: n("fill"),
408
+ dot: n("dot")
409
+ };
410
+ }
411
+ function Gr(t, n) {
412
+ return n === void 0 ? `${t}:` : `${t}:${n}`;
413
+ }
414
+ function _r(t, n) {
415
+ let e = n ? _e(n) : null;
416
+ for (const r of ["line", "fill", "dot"])
417
+ for (const i of t[r].values())
418
+ e = Le(e, i.bbox);
419
+ return e;
420
+ }
421
+ function zr(t) {
422
+ if (t.buffer instanceof ArrayBuffer)
423
+ return {
424
+ buffer: t.buffer,
425
+ startOffset: t.byteOffset,
426
+ endOffset: t.byteOffset + t.byteLength
427
+ };
428
+ const n = Uint8Array.from(t);
429
+ return {
430
+ buffer: n.buffer,
431
+ startOffset: n.byteOffset,
432
+ endOffset: n.byteOffset + n.byteLength
433
+ };
434
+ }
435
+ function Ur(t) {
436
+ const n = t.insertRuntime;
437
+ if (!n || n.instances.length === 0) return null;
438
+ const e = [], r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
439
+ for (const c of n.variants) {
440
+ const l = Or(c), u = Qe(l.line), d = Qe(l.fill), h = Qe(l.dot), f = u.length > 0 || d.length > 0 || h.length > 0;
441
+ r.set(c.id, f ? _r(l, null) : null), f && (i.add(c.id), e.push({
442
+ variantId: c.id,
443
+ line: u,
444
+ fill: d,
445
+ dot: h
446
+ }));
447
+ }
448
+ const a = n.instances.filter((c) => i.has(c.variantId));
449
+ if (a.length === 0) return null;
450
+ const s = Hr(a, r), o = Yr(e, s);
451
+ return {
452
+ variants: e,
453
+ instances: s,
454
+ bytes: o,
455
+ cost: s.count
456
+ };
457
+ }
458
+ function Qe(t) {
459
+ const n = [];
460
+ for (const e of t.values())
461
+ e.count <= 0 || n.push(Nr(e));
462
+ return n;
463
+ }
464
+ function Nr(t) {
465
+ return {
466
+ pos: t.pos,
467
+ col: t.col,
468
+ count: t.count,
469
+ layerIndex: t.layerIndex,
470
+ ...t.lineweightPx === void 0 ? {} : { lineweightPx: t.lineweightPx },
471
+ bbox: t.bbox
472
+ };
473
+ }
474
+ function Hr(t, n) {
475
+ const e = t.length, r = new Uint32Array(e * 3), i = new Float32Array(e * 6), a = new Float32Array(e * 4);
476
+ for (let s = 0; s < e; s += 1) {
477
+ const o = t[s], c = s * 3;
478
+ r[c] = o.instanceId, r[c + 1] = o.variantId, r[c + 2] = o.insLayerIdx;
479
+ const l = s * 6;
480
+ i[l] = o.matA, i[l + 1] = o.matB, i[l + 2] = o.matC, i[l + 3] = o.matD, i[l + 4] = o.tx, i[l + 5] = o.ty;
481
+ const u = nr(n.get(o.variantId) ?? null, o);
482
+ Kr(a, s * 4, u);
483
+ }
484
+ return { meta: r, mats: i, bboxes: a, count: e };
485
+ }
486
+ function Kr(t, n, e) {
487
+ if (!e) {
488
+ t[n] = Number.POSITIVE_INFINITY, t[n + 1] = Number.POSITIVE_INFINITY, t[n + 2] = Number.NEGATIVE_INFINITY, t[n + 3] = Number.NEGATIVE_INFINITY;
489
+ return;
490
+ }
491
+ t[n] = e.minX, t[n + 1] = e.minY, t[n + 2] = e.maxX, t[n + 3] = e.maxY;
492
+ }
493
+ function Yr(t, n) {
494
+ let e = n.meta.byteLength + n.mats.byteLength + n.bboxes.byteLength;
495
+ for (const r of t)
496
+ e += qe(r.line), e += qe(r.fill), e += qe(r.dot);
497
+ return e;
498
+ }
499
+ function qe(t) {
500
+ return t.reduce((n, e) => n + e.pos.byteLength + e.col.byteLength, 0);
501
+ }
502
+ const Kt = 262144, Xr = Number.MAX_SAFE_INTEGER, Yt = 524288, Qr = Number.MAX_SAFE_INTEGER, qr = 5e6, Wr = 64;
503
+ function $r(t) {
504
+ return t.lineCount + t.fillCount + t.dotCount;
505
+ }
506
+ function jr(t, n) {
507
+ return $r(t) >= qr ? {
508
+ initial: Yt,
509
+ steady: n ? Yt : Qr
510
+ } : {
511
+ initial: Kt,
512
+ steady: n ? Kt : Xr
513
+ };
514
+ }
515
+ function Zr(t) {
516
+ const n = !!(t.hiddenInstanceIds && t.hiddenInstanceIds.size > 0), e = t.keepTextsForHiddenInstances === !0, r = t.loadBlocks !== !1, i = t.suppressExpandedInsertGeometry === !0, a = t.maxExpandedInstanceVertices, s = typeof a == "number" && Number.isFinite(a) && a >= 0, o = !!(t.externalVariantBuffers && t.externalVariantBuffers.size > 0), c = t.requiredExternalVariantIds !== void 0, l = t.externalVariantDeltaOnly === !0;
517
+ if (!n && !e && r && !i && !s && !o && !c && !l)
518
+ return;
519
+ const u = {};
520
+ return n && (u.hiddenInstanceIds = t.hiddenInstanceIds), e && (u.keepTextsForHiddenInstances = !0), r || (u.loadBlocks = !1), i && (u.suppressExpandedInsertGeometry = !0), s && (u.maxExpandedInstanceVertices = a), o && (u.externalVariantBuffers = t.externalVariantBuffers), c && (u.requiredExternalVariantIds = t.requiredExternalVariantIds), l && (u.externalVariantDeltaOnly = !0), u;
521
+ }
522
+ async function Jr(t) {
523
+ if (!t.externalVariantFetchSource || !t.externalVariantGeometryFetchIds || t.externalVariantGeometryFetchIds.size === 0)
524
+ return t;
525
+ const n = Array.from(t.externalVariantGeometryFetchIds).filter((i) => {
526
+ var a;
527
+ return !((a = t.externalVariantBuffers) != null && a.has(i));
528
+ }).sort((i, a) => i - a);
529
+ if (n.length === 0)
530
+ return t;
531
+ const e = await Rn({
532
+ baseUrl: t.externalVariantFetchSource.baseUrl,
533
+ entries: t.externalVariantFetchSource.entries,
534
+ requiredVariantIds: n
535
+ }), r = new Map(t.externalVariantBuffers ?? []);
536
+ for (const [i, a] of e.buffers)
537
+ r.set(i, a);
538
+ return {
539
+ ...t,
540
+ externalVariantBuffers: r
541
+ };
542
+ }
543
+ function ei(t) {
544
+ return t.reduce((n, e) => n + e.t.length * 2 + 128, 0);
545
+ }
546
+ async function We(t, n, e, r) {
547
+ if (r()) return 0;
548
+ const i = Tr(n);
549
+ if (!i.length || r()) return 0;
550
+ const a = i.reduce((s, o) => s + o.count, 0);
551
+ return await e({
552
+ type: "geometry",
553
+ kind: t,
554
+ layers: i,
555
+ cost: a,
556
+ bytes: Bn(i)
557
+ }), a;
558
+ }
559
+ async function ti(t, n, e) {
560
+ return await We("line", t.line, n, e) + await We("fill", t.fill, n, e) + await We("dot", t.dot, n, e);
561
+ }
562
+ async function Xt(t, n, e) {
563
+ if (!t.length || e()) return 0;
564
+ const r = t.slice();
565
+ return t.length = 0, await n({
566
+ type: "text",
567
+ texts: r,
568
+ cost: r.length,
569
+ bytes: ei(r)
570
+ }), r.length;
571
+ }
572
+ function St() {
573
+ return {
574
+ start(t, n) {
575
+ let e = !1;
576
+ const r = () => e;
577
+ return {
578
+ completion: Promise.resolve().then(async () => {
579
+ if (await Promise.resolve(), r()) return;
580
+ const a = Vr(), s = [];
581
+ let o = 0, c = !1;
582
+ if (r()) return;
583
+ const l = await Jr(t);
584
+ if (r()) return;
585
+ const u = mt(l.buffer, Zr(l)), d = jr(
586
+ u.header,
587
+ t.externalVariantDeltaOnly === !0
588
+ );
589
+ if (r()) return;
590
+ await n({ type: "header", header: u.header });
591
+ const h = async () => {
592
+ const g = await ti(a, n, r);
593
+ return o = 0, g > 0 && (c = !0), g;
594
+ };
595
+ try {
596
+ for (const g of u.chunks) {
597
+ if (r()) return;
598
+ if (g.kind === "text") {
599
+ if (o > 0 && await h(), r()) return;
600
+ s.push(g.payload), s.length >= Wr && await Xt(s, n, r);
601
+ continue;
602
+ }
603
+ const C = de(g.payload, {
604
+ markLinePositionXy: g.kind === "line"
605
+ });
606
+ o += Ar(a[g.kind], C);
607
+ const v = c ? d.steady : d.initial;
608
+ o >= v && await h();
609
+ }
610
+ } catch (g) {
611
+ throw await h(), g;
612
+ }
613
+ await h(), await Xt(s, n, r), r() || await n({ type: "done" });
614
+ const f = ot(), b = Ur(u.header);
615
+ b && !r() && await n({
616
+ type: "insertModel",
617
+ variants: b.variants,
618
+ instances: b.instances,
619
+ bytes: b.bytes,
620
+ planMs: ot() - f
621
+ });
622
+ }),
623
+ cancel() {
624
+ e = !0;
625
+ },
626
+ dispose() {
627
+ }
628
+ };
629
+ }
630
+ };
631
+ }
632
+ function ni(t) {
633
+ return t.reduce((n, e) => n + e.t.length * 2 + 128, 0);
634
+ }
635
+ function ri(t) {
636
+ const n = {
637
+ type: "parse",
638
+ buffer: t.buffer
639
+ };
640
+ return t.hiddenInstanceIds && t.hiddenInstanceIds.size > 0 && (n.hiddenInstanceIds = Array.from(t.hiddenInstanceIds)), t.keepTextsForHiddenInstances === !0 && (n.keepTextsForHiddenInstances = !0), t.loadBlocks === !1 && (n.loadBlocks = !1), t.suppressExpandedInsertGeometry === !0 && (n.suppressExpandedInsertGeometry = !0), typeof t.maxExpandedInstanceVertices == "number" && Number.isFinite(t.maxExpandedInstanceVertices) && t.maxExpandedInstanceVertices >= 0 && (n.maxExpandedInstanceVertices = t.maxExpandedInstanceVertices), t.externalVariantFetchSource && (n.externalVariantFetchSource = t.externalVariantFetchSource), t.externalVariantBuffers && t.externalVariantBuffers.size > 0 && (n.externalVariantBuffers = Array.from(t.externalVariantBuffers, ([e, r]) => ({
641
+ variantId: e,
642
+ buffer: r
643
+ }))), t.requiredExternalVariantIds !== void 0 && (n.requiredExternalVariantIds = Array.from(t.requiredExternalVariantIds)), t.externalVariantGeometryFetchIds !== void 0 && (n.externalVariantGeometryFetchIds = Array.from(t.externalVariantGeometryFetchIds)), t.externalVariantDeltaOnly === !0 && (n.externalVariantDeltaOnly = !0), n;
644
+ }
645
+ function ii(t) {
646
+ const n = [t.buffer];
647
+ if (t.externalVariantBuffers && t.externalVariantBuffers.size > 0)
648
+ for (const e of t.externalVariantBuffers.values())
649
+ n.push(e);
650
+ return n;
651
+ }
652
+ function ai(t) {
653
+ const n = new Error(t.message);
654
+ return typeof t.code == "string" && (n.code = t.code), n;
655
+ }
656
+ function si(t) {
657
+ return t instanceof Error ? t : new Error(String(t));
658
+ }
659
+ function Et(t) {
660
+ return typeof t == "function" || typeof Worker == "function" && typeof globalThis.document < "u";
661
+ }
662
+ function Vt(t = {}) {
663
+ return {
664
+ start(n, e) {
665
+ var v;
666
+ const r = ((v = t.workerFactory) == null ? void 0 : v.call(t)) ?? (t.workerUrl ? new Worker(t.workerUrl, { type: "module" }) : new Worker(new URL(
667
+ /* @vite-ignore */
668
+ "" + new URL("workers/geo-prepare.worker.js", import.meta.url).href,
669
+ import.meta.url
670
+ ), { type: "module" }));
671
+ let i = !1, a = !1, s = Promise.resolve(), o, c, l, u;
672
+ const d = new Promise((x, I) => {
673
+ o = x, c = I;
674
+ }), h = new Promise((x, I) => {
675
+ l = x, u = I;
676
+ });
677
+ h.catch(() => {
678
+ });
679
+ const f = () => {
680
+ i || (i = !0, o());
681
+ }, b = () => {
682
+ a || (a = !0, l());
683
+ }, g = (x) => {
684
+ const I = si(x);
685
+ i || (i = !0, c(I)), a || (a = !0, u(I));
686
+ }, C = async (x) => {
687
+ if (!a) {
688
+ if (x.type === "error")
689
+ throw ai(x);
690
+ if (x.type === "complete") {
691
+ f(), b();
692
+ return;
693
+ }
694
+ if (x.type === "header") {
695
+ await e({ type: "header", header: x.header });
696
+ return;
697
+ }
698
+ if (x.type === "geometry") {
699
+ await e({
700
+ type: "geometry",
701
+ kind: x.kind,
702
+ layers: x.layers,
703
+ cost: x.cost,
704
+ bytes: Bn(x.layers)
705
+ });
706
+ return;
707
+ }
708
+ if (x.type === "insertModel") {
709
+ await e({
710
+ type: "insertModel",
711
+ variants: x.variants,
712
+ instances: x.instances,
713
+ bytes: x.bytes,
714
+ planMs: x.planMs
715
+ });
716
+ return;
717
+ }
718
+ if (x.type === "text") {
719
+ await e({
720
+ type: "text",
721
+ texts: x.texts,
722
+ cost: x.cost,
723
+ bytes: ni(x.texts)
724
+ });
725
+ return;
726
+ }
727
+ await e({ type: "done" }), f();
728
+ }
729
+ };
730
+ return r.addEventListener("message", (x) => {
731
+ s = s.then(() => C(x.data)), s.catch((I) => {
732
+ g(I);
733
+ });
734
+ }), r.addEventListener("error", (x) => {
735
+ g(new Error(x.message || "Geo prepare worker failed"));
736
+ }), r.addEventListener("messageerror", () => {
737
+ g(new Error("Geo prepare worker message decode failed"));
738
+ }), r.postMessage(ri(n), ii(n)), {
739
+ completion: d,
740
+ backgroundCompletion: h,
741
+ grant(x) {
742
+ a || r.postMessage({ type: "grant", ...x });
743
+ },
744
+ cancel() {
745
+ a || (b(), r.postMessage({ type: "cancel" }));
746
+ },
747
+ dispose() {
748
+ b(), r.terminate();
749
+ }
750
+ };
751
+ }
752
+ };
753
+ }
754
+ async function oi(t) {
755
+ if (!t.ok)
756
+ throw new A("E_PACK_HTTP", t.statusText || `Pack request failed with HTTP ${t.status}`);
757
+ return t.arrayBuffer();
758
+ }
759
+ async function Vn(t) {
760
+ var n;
761
+ switch (t.kind) {
762
+ case "buffer":
763
+ return t.buffer;
764
+ case "packFile":
765
+ return t.file.arrayBuffer();
766
+ case "url":
767
+ try {
768
+ return await oi(await fetch(t.url, { signal: t.signal }));
769
+ } catch (e) {
770
+ throw e instanceof A || e instanceof Error && e.name === "AbortError" ? e : (n = t.signal) != null && n.aborted ? te(t.signal.reason, "CAD pack request aborted") : new A("E_PACK_NETWORK", `Pack request failed: ${e.message}`);
771
+ }
772
+ default: {
773
+ const e = t;
774
+ throw new A("E_SOURCE", `Unsupported geo source: ${String(e)}`);
775
+ }
776
+ }
777
+ }
778
+ var he, re, fe, ie;
779
+ class li {
780
+ constructor(n) {
781
+ B(this, he, []);
782
+ B(this, re, []);
783
+ B(this, fe);
784
+ B(this, ie, !1);
785
+ k(this, fe, n);
786
+ }
787
+ [Symbol.asyncIterator]() {
788
+ return this;
789
+ }
790
+ next() {
791
+ const n = p(this, he).shift();
792
+ return n ? (p(this, fe).call(this, n), Promise.resolve({ done: !1, value: n.event })) : p(this, ie) ? Promise.resolve({ done: !0, value: void 0 }) : new Promise((e) => {
793
+ p(this, re).push({ resolve: e });
794
+ });
795
+ }
796
+ push(n) {
797
+ if (p(this, ie)) return;
798
+ const e = p(this, re).shift();
799
+ if (e) {
800
+ p(this, fe).call(this, n), e.resolve({ done: !1, value: n.event });
801
+ return;
802
+ }
803
+ p(this, he).push(n);
804
+ }
805
+ close() {
806
+ if (!p(this, ie))
807
+ for (k(this, ie, !0); p(this, re).length > 0; )
808
+ p(this, re).shift().resolve({ done: !0, value: void 0 });
809
+ }
810
+ clear() {
811
+ p(this, he).length = 0, this.close();
812
+ }
813
+ }
814
+ he = new WeakMap(), re = new WeakMap(), fe = new WeakMap(), ie = new WeakMap();
815
+ function Qt() {
816
+ let t, n;
817
+ return { promise: new Promise((r, i) => {
818
+ t = r, n = i;
819
+ }), resolve: t, reject: n };
820
+ }
821
+ function ci(t) {
822
+ return t instanceof Error ? t : new Error(String(t));
823
+ }
824
+ function $e(t) {
825
+ return t === void 0 ? void 0 : new Set(t);
826
+ }
827
+ function ui(t) {
828
+ return {
829
+ highWatermarkBytes: (t == null ? void 0 : t.highWatermarkBytes) ?? It,
830
+ lowWatermarkBytes: (t == null ? void 0 : t.lowWatermarkBytes) ?? wt,
831
+ initialGeometryCredits: (t == null ? void 0 : t.initialGeometryCredits) ?? vt,
832
+ initialTextCredits: (t == null ? void 0 : t.initialTextCredits) ?? Rt
833
+ };
834
+ }
835
+ function di(t) {
836
+ if (t.positionItemSize === 2) return t.pos;
837
+ const n = new Float32Array(t.count * 2);
838
+ for (let e = 0; e < t.count; e += 1)
839
+ n[e * 2] = t.pos[e * 3] ?? 0, n[e * 2 + 1] = t.pos[e * 3 + 1] ?? 0;
840
+ return n;
841
+ }
842
+ function hi(t) {
843
+ return (t.colorRuns ?? fi(t)).map((e) => ({
844
+ startVertex: e.startVertex,
845
+ vertexCount: e.vertexCount,
846
+ color: [e.color[0], e.color[1], e.color[2]],
847
+ layerIndex: t.layerIndex,
848
+ ...t.lineweightPx === void 0 ? {} : { lineweightPx: t.lineweightPx }
849
+ }));
850
+ }
851
+ function fi(t) {
852
+ return t.count <= 0 ? [] : [{
853
+ startVertex: 0,
854
+ vertexCount: t.count,
855
+ color: [t.col[0] ?? 0, t.col[1] ?? 0, t.col[2] ?? 0]
856
+ }];
857
+ }
858
+ function yi(t) {
859
+ const n = t.layerIndex <= 255 ? new Uint8Array(t.count).fill(t.layerIndex) : new Uint16Array(t.count).fill(t.layerIndex);
860
+ return {
861
+ pos: di(t),
862
+ col: t.col,
863
+ lay: n,
864
+ count: t.count,
865
+ segments: hi(t)
866
+ };
867
+ }
868
+ function mi(t) {
869
+ const n = [];
870
+ for (let e = 0; e < t.count; e += 1) {
871
+ const r = e * 3, i = e * 6;
872
+ n.push({
873
+ instanceId: t.meta[r] ?? 0,
874
+ variantId: t.meta[r + 1] ?? 0,
875
+ insLayerIdx: t.meta[r + 2] ?? 0,
876
+ matA: t.mats[i] ?? 0,
877
+ matB: t.mats[i + 1] ?? 0,
878
+ matC: t.mats[i + 2] ?? 0,
879
+ matD: t.mats[i + 3] ?? 0,
880
+ tx: t.mats[i + 4] ?? 0,
881
+ ty: t.mats[i + 5] ?? 0
882
+ });
883
+ }
884
+ return n;
885
+ }
886
+ function je(t) {
887
+ return {
888
+ pos: t.pos,
889
+ col: t.col,
890
+ count: t.count,
891
+ ...t.layerIndex === void 0 ? {} : { layerIndex: t.layerIndex },
892
+ ...t.lineweightPx === void 0 ? {} : { lineweightPx: t.lineweightPx },
893
+ ...t.bbox === void 0 ? {} : { bounds: t.bbox }
894
+ };
895
+ }
896
+ function xi(t) {
897
+ return {
898
+ variantId: t.variantId,
899
+ line: t.line.map(je),
900
+ fill: t.fill.map(je),
901
+ dot: t.dot.map(je)
902
+ };
903
+ }
904
+ var E, we, ve, Re, ye, J, L, me, ee, xe, Be, z, pe, Se, Ee, T, Ve, ke, w, kn, An, Tn, ue, ct, Pn, Ce, ut, De, Fe, Oe;
905
+ class pi {
906
+ constructor(n, e) {
907
+ B(this, w);
908
+ m(this, "events");
909
+ m(this, "ready");
910
+ B(this, E);
911
+ B(this, we);
912
+ B(this, ve);
913
+ B(this, Re, new AbortController());
914
+ B(this, ye, Qt());
915
+ B(this, J, Qt());
916
+ B(this, L);
917
+ B(this, me, []);
918
+ B(this, ee);
919
+ B(this, xe, /* @__PURE__ */ new Set());
920
+ B(this, Be, []);
921
+ B(this, z, null);
922
+ B(this, pe, null);
923
+ B(this, Se, 0);
924
+ B(this, Ee, !1);
925
+ B(this, T, !1);
926
+ B(this, Ve, !1);
927
+ B(this, ke, ot());
928
+ k(this, E, e);
929
+ const r = Bt(n, p(this, Re).signal);
930
+ k(this, we, r.source), k(this, ve, r.sourceSignal), k(this, ee, new vn(ui(e.flowControl))), k(this, L, new li((i) => R(this, w, Pn).call(this, i))), this.events = p(this, L), this.ready = p(this, ye).promise, this.ready.catch(() => {
931
+ }), p(this, J).promise.catch(() => {
932
+ }), R(this, w, ut).call(this, e.signal), R(this, w, ut).call(this, p(this, ve)), p(this, T) || R(this, w, kn).call(this);
933
+ }
934
+ abort(n) {
935
+ p(this, T) || R(this, w, De).call(this, te(n, "CAD load session aborted"));
936
+ }
937
+ dispose() {
938
+ var n;
939
+ if (!p(this, Ve)) {
940
+ if (k(this, Ve, !0), !p(this, T)) {
941
+ R(this, w, De).call(this, te("CAD load session disposed"));
942
+ return;
943
+ }
944
+ (n = p(this, z)) == null || n.dispose(), p(this, L).clear(), R(this, w, Oe).call(this);
945
+ }
946
+ }
947
+ }
948
+ E = new WeakMap(), we = new WeakMap(), ve = new WeakMap(), Re = new WeakMap(), ye = new WeakMap(), J = new WeakMap(), L = new WeakMap(), me = new WeakMap(), ee = new WeakMap(), xe = new WeakMap(), Be = new WeakMap(), z = new WeakMap(), pe = new WeakMap(), Se = new WeakMap(), Ee = new WeakMap(), T = new WeakMap(), Ve = new WeakMap(), ke = new WeakMap(), w = new WeakSet(), kn = async function() {
949
+ var n, e;
950
+ try {
951
+ const r = await Promise.race([
952
+ Vn(p(this, we)),
953
+ p(this, J).promise
954
+ ]);
955
+ if (p(this, T)) return;
956
+ k(this, Se, r.byteLength);
957
+ const a = R(this, w, An).call(this).start({
958
+ buffer: r,
959
+ hiddenInstanceIds: $e(p(this, E).hiddenInstanceIds),
960
+ keepTextsForHiddenInstances: p(this, E).keepTextsForHiddenInstances || void 0,
961
+ loadBlocks: p(this, E).loadBlocks,
962
+ suppressExpandedInsertGeometry: p(this, E).loadBlocks !== !1,
963
+ maxExpandedInstanceVertices: p(this, E).maxExpandedInstanceVertices,
964
+ externalVariantFetchSource: p(this, E).externalVariantFetchSource,
965
+ externalVariantBuffers: p(this, E).externalVariantBuffers,
966
+ requiredExternalVariantIds: $e(p(this, E).requiredExternalVariantIds),
967
+ externalVariantGeometryFetchIds: $e(p(this, E).externalVariantGeometryFetchIds)
968
+ }, (o) => R(this, w, Tn).call(this, o));
969
+ if (k(this, z, a), a.completion.catch(() => {
970
+ }), (n = a.backgroundCompletion) == null || n.catch(() => {
971
+ }), R(this, w, Ce).call(this, p(this, ee).takeInitialGrant()), await Promise.race([a.completion, p(this, J).promise]), a.backgroundCompletion && await Promise.race([a.backgroundCompletion, p(this, J).promise]), p(this, T)) return;
972
+ if (!p(this, Ee))
973
+ throw new Error("CAD loader adapter completed without a done event");
974
+ if (!p(this, pe))
975
+ throw new Error("CAD loader adapter completed without metadata");
976
+ const s = {
977
+ header: p(this, pe),
978
+ chunks: p(this, me),
979
+ rawBytes: p(this, Se)
980
+ };
981
+ k(this, T, !0), p(this, L).push({ event: { type: "ready", document: s } }), p(this, L).close(), p(this, ye).resolve(s), R(this, w, Oe).call(this);
982
+ } catch (r) {
983
+ p(this, T) || R(this, w, De).call(this, ci(r));
984
+ } finally {
985
+ (e = p(this, z)) == null || e.dispose(), R(this, w, Fe).call(this);
986
+ }
987
+ }, An = function() {
988
+ return p(this, E).preferWorker !== !1 && Et(p(this, E).workerFactory) ? Vt({
989
+ workerUrl: p(this, E).workerUrl,
990
+ workerFactory: p(this, E).workerFactory
991
+ }) : St();
992
+ }, Tn = async function(n) {
993
+ if (!p(this, T)) {
994
+ if (n.type === "header") {
995
+ k(this, pe, n.header), p(this, L).push({
996
+ event: { type: "meta", meta: n.header, header: n.header }
997
+ }), await R(this, w, ue).call(this);
998
+ return;
999
+ }
1000
+ if (n.type === "geometry") {
1001
+ const e = n.layers.map((r) => {
1002
+ const i = yi(r);
1003
+ return p(this, me).push({ kind: n.kind, payload: i }), {
1004
+ event: {
1005
+ type: "geometry",
1006
+ kind: n.kind,
1007
+ chunk: i,
1008
+ layerIndex: r.layerIndex,
1009
+ ...r.lineweightPx === void 0 ? {} : { lineweightPx: r.lineweightPx },
1010
+ bounds: r.bbox
1011
+ }
1012
+ };
1013
+ });
1014
+ await R(this, w, ct).call(this, e, "geometry", n.bytes), await R(this, w, ue).call(this);
1015
+ return;
1016
+ }
1017
+ if (n.type === "text") {
1018
+ const e = n.texts.map((r) => (p(this, me).push({ kind: "text", payload: r }), { event: { type: "text", chunk: r } }));
1019
+ await R(this, w, ct).call(this, e, "text", n.bytes), await R(this, w, ue).call(this);
1020
+ return;
1021
+ }
1022
+ if (n.type === "insertModel") {
1023
+ p(this, L).push({
1024
+ event: {
1025
+ type: "insert",
1026
+ instances: mi(n.instances),
1027
+ variants: n.variants.map(xi)
1028
+ }
1029
+ }), await R(this, w, ue).call(this);
1030
+ return;
1031
+ }
1032
+ k(this, Ee, !0), await R(this, w, ue).call(this);
1033
+ }
1034
+ }, ue = async function() {
1035
+ const n = Math.max(0, (p(this, E).frameBudgetMs ?? bt) - (p(this, E).frameReserveMs ?? Ct));
1036
+ typeof performance > "u" || typeof performance.now != "function" || performance.now() - p(this, ke) < n || (await new Promise((e) => {
1037
+ typeof globalThis.requestAnimationFrame == "function" ? globalThis.requestAnimationFrame(() => e()) : setTimeout(e, 0);
1038
+ }), k(this, ke, performance.now()));
1039
+ }, ct = function(n, e, r) {
1040
+ if (n.length === 0) {
1041
+ R(this, w, Ce).call(this, e === "geometry" ? { geometryCredits: 1, textCredits: 0 } : { geometryCredits: 0, textCredits: 1 });
1042
+ return;
1043
+ }
1044
+ const i = { kind: e, bytes: Math.max(0, r), creditReplaced: !1 };
1045
+ p(this, ee).onQueued(e, i.bytes);
1046
+ const a = p(this, ee).onConsumed(e, 0);
1047
+ if (i.creditReplaced = R(this, w, Ce).call(this, a), n.forEach((s, o) => {
1048
+ p(this, L).push({
1049
+ ...s,
1050
+ batch: i,
1051
+ accountsBatch: o === n.length - 1
1052
+ });
1053
+ }), !!a.paused)
1054
+ return new Promise((s) => {
1055
+ p(this, xe).add(s);
1056
+ });
1057
+ }, Pn = function(n) {
1058
+ if (!n.batch || !n.accountsBatch) return;
1059
+ const e = p(this, ee).onConsumed(n.batch.kind, n.batch.bytes);
1060
+ n.batch.creditReplaced || (n.batch.creditReplaced = R(this, w, Ce).call(this, e)), e.paused || R(this, w, Fe).call(this);
1061
+ }, Ce = function(n) {
1062
+ var e;
1063
+ return !((e = p(this, z)) != null && e.grant) || p(this, T) || n.geometryCredits <= 0 && n.textCredits <= 0 ? !1 : (p(this, z).grant({
1064
+ geometryCredits: n.geometryCredits,
1065
+ textCredits: n.textCredits
1066
+ }), !0);
1067
+ }, ut = function(n) {
1068
+ if (!n) return;
1069
+ if (n.aborted) {
1070
+ this.abort(n.reason);
1071
+ return;
1072
+ }
1073
+ const e = () => this.abort(n.reason);
1074
+ n.addEventListener("abort", e, { once: !0 }), p(this, Be).push(() => n.removeEventListener("abort", e));
1075
+ }, De = function(n) {
1076
+ var e, r, i;
1077
+ p(this, T) || (k(this, T, !0), p(this, Re).abort(n), (r = (e = p(this, z)) == null ? void 0 : e.cancel) == null || r.call(e), (i = p(this, z)) == null || i.dispose(), p(this, J).reject(n), p(this, ye).reject(n), p(this, L).push({ event: { type: "error", error: n } }), p(this, L).close(), R(this, w, Fe).call(this), R(this, w, Oe).call(this));
1078
+ }, Fe = function() {
1079
+ for (const n of p(this, xe)) n();
1080
+ p(this, xe).clear();
1081
+ }, Oe = function() {
1082
+ for (const n of p(this, Be).splice(0)) n();
1083
+ };
1084
+ function fs(t, n = {}) {
1085
+ return new pi(t, n);
1086
+ }
1087
+ class gi {
1088
+ constructor(n) {
1089
+ m(this, "queue", []);
1090
+ m(this, "budgetMs");
1091
+ m(this, "now");
1092
+ this.budgetMs = Math.max(0, n.frameBudgetMs - n.reserveMs), this.now = n.now ?? (() => performance.now());
1093
+ }
1094
+ enqueue(n) {
1095
+ this.queue.push(n);
1096
+ }
1097
+ hasPending() {
1098
+ return this.queue.length > 0;
1099
+ }
1100
+ size() {
1101
+ return this.queue.length;
1102
+ }
1103
+ async runFrame() {
1104
+ const n = this.now();
1105
+ let e = 0;
1106
+ for (; this.queue.length > 0; ) {
1107
+ const r = this.queue.shift();
1108
+ if (!r)
1109
+ break;
1110
+ if (await r(), e += 1, this.queue.length > 0 && this.now() - n >= this.budgetMs)
1111
+ return {
1112
+ executed: e,
1113
+ remaining: this.queue.length,
1114
+ exhausted: !0
1115
+ };
1116
+ }
1117
+ return {
1118
+ executed: e,
1119
+ remaining: this.queue.length,
1120
+ exhausted: !1
1121
+ };
1122
+ }
1123
+ }
1124
+ function bi(t) {
1125
+ return t.lineCount + t.fillCount + t.dotCount;
1126
+ }
1127
+ function Ci(t) {
1128
+ return t instanceof Error ? t : new Error(String(t));
1129
+ }
1130
+ class Ii {
1131
+ constructor(n) {
1132
+ m(this, "headerSeen", !1);
1133
+ m(this, "headerTexts", []);
1134
+ this.node = n;
1135
+ }
1136
+ initFromHeader(n) {
1137
+ this.node._initFromHeader(n), this.node.updateAutoQualityContext({
1138
+ visibleVertexCount: bi(n),
1139
+ zoom: 1
1140
+ }), this.headerSeen = !0, this.headerTexts = n.texts;
1141
+ }
1142
+ appendGeometry(n, e) {
1143
+ this.node._appendPreparedGeometryChunk(n, e);
1144
+ }
1145
+ appendText(n) {
1146
+ this.node._appendTextChunks(n);
1147
+ }
1148
+ installInsertModel(n) {
1149
+ this.node._installInsertModel(n);
1150
+ }
1151
+ appendInsertModel(n) {
1152
+ this.node._appendInsertModel(n);
1153
+ }
1154
+ async finalize(n) {
1155
+ try {
1156
+ if (!this.headerSeen)
1157
+ throw new Error("Geo loader pipeline completed without header");
1158
+ rr() && ir("Boundary-3:header->node", this.headerTexts, this.node._collectTextUserDataForDebug()), await this.node._finalizeIncrementally(n);
1159
+ } catch (e) {
1160
+ const r = Ci(e);
1161
+ throw this.fail(r), r;
1162
+ }
1163
+ }
1164
+ fail(n) {
1165
+ this.node._fail(n);
1166
+ }
1167
+ }
1168
+ function qt(t) {
1169
+ return t instanceof Error ? t : new Error(String(t));
1170
+ }
1171
+ function wi() {
1172
+ return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1173
+ }
1174
+ function vi(t) {
1175
+ return {
1176
+ frameBudgetMs: (t == null ? void 0 : t.frameBudgetMs) ?? bt,
1177
+ reserveMs: (t == null ? void 0 : t.reserveMs) ?? Ct,
1178
+ now: (t == null ? void 0 : t.now) ?? wi
1179
+ };
1180
+ }
1181
+ function Ri(t) {
1182
+ return {
1183
+ highWatermarkBytes: (t == null ? void 0 : t.highWatermarkBytes) ?? It,
1184
+ lowWatermarkBytes: (t == null ? void 0 : t.lowWatermarkBytes) ?? wt,
1185
+ initialGeometryCredits: (t == null ? void 0 : t.initialGeometryCredits) ?? vt,
1186
+ initialTextCredits: (t == null ? void 0 : t.initialTextCredits) ?? Rt
1187
+ };
1188
+ }
1189
+ function Bi() {
1190
+ return new Promise((t) => {
1191
+ if (typeof globalThis.requestAnimationFrame == "function") {
1192
+ globalThis.requestAnimationFrame(() => t());
1193
+ return;
1194
+ }
1195
+ setTimeout(t, 0);
1196
+ });
1197
+ }
1198
+ async function Ze(t) {
1199
+ await Bi(), await (t == null ? void 0 : t());
1200
+ }
1201
+ async function Ln(t) {
1202
+ var D, Tt;
1203
+ const { node: n } = t, e = new Ii(n), r = t.appendExternalVariantDelta === !0, i = new gi(vi(t.scheduler));
1204
+ let a = null, s = !0, o = null, c = !1, l = !1, u = !1, d = null, h = !1, f = null, b = null, g = null;
1205
+ const C = [], v = /* @__PURE__ */ new Set(), x = /* @__PURE__ */ new Set(), I = new Promise((y, S) => {
1206
+ f = S;
1207
+ });
1208
+ I.catch(() => {
1209
+ });
1210
+ const V = (y) => {
1211
+ var oe;
1212
+ const S = qt(y);
1213
+ if (!u) {
1214
+ u = !0, (oe = a == null ? void 0 : a.cancel) == null || oe.call(a);
1215
+ for (const K of v)
1216
+ G(K, S);
1217
+ r || e.fail(S), n.ready.catch(() => {
1218
+ }), f == null || f(S);
1219
+ }
1220
+ return S;
1221
+ }, M = (y) => (x.add(y), y.then(
1222
+ () => {
1223
+ x.delete(y);
1224
+ },
1225
+ () => {
1226
+ x.delete(y);
1227
+ }
1228
+ ), y.catch(() => {
1229
+ }), y), Q = (y) => ({
1230
+ geometryCredits: y.geometryCredits,
1231
+ textCredits: y.textCredits
1232
+ }), q = (y, S) => {
1233
+ u || !(a != null && a.grant) || S && y.geometryCredits <= 0 && y.textCredits <= 0 || a.grant(Q(y));
1234
+ }, W = (y) => {
1235
+ !o || y.flowQueued || (o.onQueued(y.kind, y.bytes), y.flowQueued = !0);
1236
+ }, N = () => {
1237
+ for (const y of v)
1238
+ W(y);
1239
+ }, G = (y, S) => {
1240
+ if (!y.settled) {
1241
+ if (y.settled = !0, v.delete(y), S) {
1242
+ y.reject(S);
1243
+ return;
1244
+ }
1245
+ y.resolve();
1246
+ }
1247
+ }, $ = () => (h = !0, d || (d = Promise.resolve().then(async () => {
1248
+ for (; !u; ) {
1249
+ for (h = !1; !u && i.hasPending(); ) {
1250
+ const y = await i.runFrame();
1251
+ !u && y.exhausted && await Ze(t.onYield);
1252
+ }
1253
+ if (!h && !i.hasPending())
1254
+ break;
1255
+ }
1256
+ }).catch((y) => {
1257
+ throw V(y);
1258
+ }).finally(() => {
1259
+ d = null, !u && h && i.hasPending() && $();
1260
+ }), d.catch(() => {
1261
+ }), d)), H = (y, S, oe) => {
1262
+ let K = null, Pt = null;
1263
+ const le = new Promise((Ae, He) => {
1264
+ K = Ae, Pt = He;
1265
+ }), Y = {
1266
+ kind: y,
1267
+ bytes: S,
1268
+ append: oe,
1269
+ flowQueued: !1,
1270
+ settled: !1,
1271
+ resolve: K,
1272
+ reject: Pt
1273
+ };
1274
+ return v.add(Y), x.add(le), le.then(
1275
+ () => {
1276
+ x.delete(le);
1277
+ },
1278
+ () => {
1279
+ x.delete(le);
1280
+ }
1281
+ ), le.catch(() => {
1282
+ }), W(Y), i.enqueue(() => {
1283
+ if (u) {
1284
+ G(Y, V(new Error("Geo loader pipeline failed before append task ran")));
1285
+ return;
1286
+ }
1287
+ try {
1288
+ Y.append(), o && Y.flowQueued && q(o.onConsumed(Y.kind, Y.bytes), !0), G(Y);
1289
+ } catch (Ae) {
1290
+ const He = qt(Ae);
1291
+ throw G(Y, He), V(Ae);
1292
+ }
1293
+ }), $(), le;
1294
+ }, ae = (y) => {
1295
+ if (y.type === "geometry") {
1296
+ e.appendGeometry(y.kind, y.layers);
1297
+ return;
1298
+ }
1299
+ if (y.type === "text") {
1300
+ e.appendText(y.texts);
1301
+ return;
1302
+ }
1303
+ if (y.type === "insertModel") {
1304
+ e.appendInsertModel({
1305
+ variants: y.variants,
1306
+ instances: y.instances,
1307
+ planMs: y.planMs
1308
+ });
1309
+ return;
1310
+ }
1311
+ }, se = (y) => H(y.type === "text" ? "text" : "geometry", y.bytes, () => {
1312
+ if (l) {
1313
+ ae(y);
1314
+ return;
1315
+ }
1316
+ C.push(y);
1317
+ }), F = (y, S) => {
1318
+ const oe = Promise.resolve().then(async () => {
1319
+ var K;
1320
+ await ((K = t.beforeTextAppend) == null ? void 0 : K.call(t, y)), await S();
1321
+ }).catch((K) => {
1322
+ throw V(K);
1323
+ });
1324
+ return M(oe);
1325
+ }, _ = (y) => {
1326
+ if (!u) {
1327
+ if (y.type === "header") {
1328
+ if (r) {
1329
+ g = y.header;
1330
+ return;
1331
+ }
1332
+ e.initFromHeader(y.header);
1333
+ return;
1334
+ }
1335
+ if (y.type === "geometry")
1336
+ return r ? se({
1337
+ type: "geometry",
1338
+ kind: y.kind,
1339
+ layers: y.layers,
1340
+ bytes: y.bytes
1341
+ }) : H("geometry", y.bytes, () => {
1342
+ e.appendGeometry(y.kind, y.layers);
1343
+ });
1344
+ if (y.type === "text")
1345
+ return r ? F(y.texts, () => se({
1346
+ type: "text",
1347
+ texts: y.texts,
1348
+ bytes: y.bytes
1349
+ })) : F(y.texts, () => H("text", y.bytes, () => {
1350
+ e.appendText(y.texts);
1351
+ }));
1352
+ if (y.type === "insertModel")
1353
+ return r ? se({
1354
+ type: "insertModel",
1355
+ variants: y.variants,
1356
+ instances: y.instances,
1357
+ bytes: y.bytes,
1358
+ planMs: y.planMs
1359
+ }) : H("geometry", y.bytes, () => {
1360
+ e.installInsertModel({
1361
+ variants: y.variants,
1362
+ instances: y.instances,
1363
+ planMs: y.planMs
1364
+ });
1365
+ });
1366
+ c = !0;
1367
+ }
1368
+ };
1369
+ try {
1370
+ if ((D = t.signal) != null && D.aborted)
1371
+ throw te(t.signal.reason);
1372
+ if (a = t.adapter.start(
1373
+ {
1374
+ buffer: t.buffer,
1375
+ hiddenInstanceIds: t.hiddenInstanceIds,
1376
+ keepTextsForHiddenInstances: t.keepTextsForHiddenInstances,
1377
+ loadBlocks: t.loadBlocks,
1378
+ suppressExpandedInsertGeometry: t.suppressExpandedInsertGeometry,
1379
+ maxExpandedInstanceVertices: t.maxExpandedInstanceVertices,
1380
+ externalVariantFetchSource: t.externalVariantFetchSource,
1381
+ externalVariantBuffers: t.externalVariantBuffers,
1382
+ requiredExternalVariantIds: t.requiredExternalVariantIds,
1383
+ externalVariantGeometryFetchIds: t.externalVariantGeometryFetchIds,
1384
+ externalVariantDeltaOnly: t.externalVariantDeltaOnly
1385
+ },
1386
+ _
1387
+ ), a.completion.catch(() => {
1388
+ }), t.signal) {
1389
+ const y = t.signal, S = () => {
1390
+ V(te(y.reason));
1391
+ };
1392
+ y.addEventListener("abort", S, { once: !0 }), b = () => y.removeEventListener("abort", S), y.aborted && S();
1393
+ }
1394
+ if (a.grant && (o = new vn(Ri(t.flowControl)), N(), q(o.takeInitialGrant(), !1)), await Promise.race([a.completion, I]), a.backgroundCompletion && await Promise.race([a.backgroundCompletion, I]), await $(), await Promise.all(Array.from(x)), !c)
1395
+ throw new Error("Geo loader pipeline completed without done event");
1396
+ if (await ((Tt = t.beforeFinalize) == null ? void 0 : Tt.call(t)), r) {
1397
+ if (!g)
1398
+ throw new Error("Geo loader pipeline completed without delta header");
1399
+ n.appendExternalVariantDeltaHeader(g);
1400
+ for (const y of C)
1401
+ H(y.type === "text" ? "text" : "geometry", y.bytes, () => {
1402
+ ae(y);
1403
+ });
1404
+ await $(), await Promise.all(Array.from(x)), await n._finalizeIncrementally(() => Ze(t.onYield));
1405
+ } else
1406
+ await e.finalize(() => Ze(t.onYield));
1407
+ if (l = !0, a.backgroundCompletion) {
1408
+ const y = a;
1409
+ s = !1, a.backgroundCompletion.then(async () => {
1410
+ await $(), await Promise.all(Array.from(x));
1411
+ }).catch(() => {
1412
+ }).finally(() => {
1413
+ y.dispose();
1414
+ });
1415
+ }
1416
+ } catch (y) {
1417
+ throw V(y);
1418
+ } finally {
1419
+ b == null || b(), s && (a == null || a.dispose());
1420
+ }
1421
+ }
1422
+ function Mn(t) {
1423
+ return t instanceof Error ? t : new Error(String(t));
1424
+ }
1425
+ function Si(t) {
1426
+ if (!t || t.size === 0)
1427
+ return t;
1428
+ const n = /* @__PURE__ */ new Map();
1429
+ for (const [e, r] of t)
1430
+ n.set(e, r.slice(0));
1431
+ return n;
1432
+ }
1433
+ function Ei() {
1434
+ return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1435
+ }
1436
+ function Dn(t = {}) {
1437
+ var s, o, c, l, u, d, h;
1438
+ const n = t.hiddenInstanceIds ? new Set(t.hiddenInstanceIds) : /* @__PURE__ */ new Set(), e = t.requiredExternalVariantIds !== void 0, r = e ? new Set(t.requiredExternalVariantIds) : /* @__PURE__ */ new Set(), i = t.externalVariantGeometryFetchIds !== void 0, a = i ? new Set(t.externalVariantGeometryFetchIds) : /* @__PURE__ */ new Set();
1439
+ return {
1440
+ scheduler: {
1441
+ frameBudgetMs: ((s = t.scheduler) == null ? void 0 : s.frameBudgetMs) ?? bt,
1442
+ reserveMs: ((o = t.scheduler) == null ? void 0 : o.reserveMs) ?? Ct,
1443
+ now: ((c = t.scheduler) == null ? void 0 : c.now) ?? Ei
1444
+ },
1445
+ flowControl: {
1446
+ highWatermarkBytes: ((l = t.flowControl) == null ? void 0 : l.highWatermarkBytes) ?? It,
1447
+ lowWatermarkBytes: ((u = t.flowControl) == null ? void 0 : u.lowWatermarkBytes) ?? wt,
1448
+ initialGeometryCredits: ((d = t.flowControl) == null ? void 0 : d.initialGeometryCredits) ?? vt,
1449
+ initialTextCredits: ((h = t.flowControl) == null ? void 0 : h.initialTextCredits) ?? Rt
1450
+ },
1451
+ beforeTextAppend: t.beforeTextAppend,
1452
+ beforeFinalize: t.beforeFinalize,
1453
+ signal: t.signal,
1454
+ hiddenInstanceIds: n.size > 0 ? n : void 0,
1455
+ preferWorker: t.preferWorker !== !1,
1456
+ workerUrl: t.workerUrl,
1457
+ workerFactory: t.workerFactory,
1458
+ keepTextsForHiddenInstances: t.keepTextsForHiddenInstances === !0,
1459
+ loadBlocks: t.loadBlocks !== !1,
1460
+ suppressExpandedInsertGeometry: t.loadBlocks !== !1,
1461
+ maxExpandedInstanceVertices: typeof t.maxExpandedInstanceVertices == "number" && Number.isFinite(t.maxExpandedInstanceVertices) && t.maxExpandedInstanceVertices >= 0 ? t.maxExpandedInstanceVertices : void 0,
1462
+ externalVariantFetchSource: t.externalVariantFetchSource,
1463
+ externalVariantBuffers: t.externalVariantBuffers,
1464
+ requiredExternalVariantIds: e ? r : void 0,
1465
+ externalVariantGeometryFetchIds: i ? a : void 0,
1466
+ externalVariantDeltaOnly: t.externalVariantDeltaOnly === !0
1467
+ };
1468
+ }
1469
+ async function Vi(t, n, e, r = {}) {
1470
+ const i = Dn(r), a = i.hiddenInstanceIds ?? /* @__PURE__ */ new Set(), s = i.preferWorker && Et(i.workerFactory) ? Vt({
1471
+ workerUrl: i.workerUrl,
1472
+ workerFactory: i.workerFactory
1473
+ }) : St();
1474
+ try {
1475
+ await Ln({
1476
+ node: t,
1477
+ buffer: n,
1478
+ adapter: s,
1479
+ scheduler: i.scheduler,
1480
+ flowControl: i.flowControl,
1481
+ beforeTextAppend: i.beforeTextAppend,
1482
+ beforeFinalize: i.beforeFinalize,
1483
+ signal: i.signal,
1484
+ onYield: e,
1485
+ hiddenInstanceIds: a.size > 0 ? a : void 0,
1486
+ keepTextsForHiddenInstances: i.keepTextsForHiddenInstances || void 0,
1487
+ loadBlocks: i.loadBlocks,
1488
+ suppressExpandedInsertGeometry: i.suppressExpandedInsertGeometry,
1489
+ maxExpandedInstanceVertices: i.maxExpandedInstanceVertices,
1490
+ externalVariantFetchSource: i.externalVariantFetchSource,
1491
+ externalVariantBuffers: i.externalVariantBuffers,
1492
+ requiredExternalVariantIds: i.requiredExternalVariantIds,
1493
+ externalVariantGeometryFetchIds: i.externalVariantGeometryFetchIds,
1494
+ externalVariantDeltaOnly: i.externalVariantDeltaOnly
1495
+ });
1496
+ } catch (o) {
1497
+ const c = Mn(o);
1498
+ throw t.ready.catch(() => {
1499
+ }), c;
1500
+ }
1501
+ }
1502
+ async function ki(t, n, e, r = {}) {
1503
+ const i = Dn({
1504
+ ...r,
1505
+ externalVariantDeltaOnly: !0
1506
+ }), a = i.hiddenInstanceIds ?? /* @__PURE__ */ new Set(), s = i.preferWorker && Et(i.workerFactory), o = s ? Vt({
1507
+ workerUrl: i.workerUrl,
1508
+ workerFactory: i.workerFactory
1509
+ }) : St(), c = s ? n.slice(0) : n, l = s ? Si(i.externalVariantBuffers) : i.externalVariantBuffers;
1510
+ try {
1511
+ await Ln({
1512
+ node: t,
1513
+ buffer: c,
1514
+ adapter: o,
1515
+ scheduler: i.scheduler,
1516
+ flowControl: i.flowControl,
1517
+ beforeTextAppend: i.beforeTextAppend,
1518
+ signal: i.signal,
1519
+ onYield: e,
1520
+ hiddenInstanceIds: a.size > 0 ? a : void 0,
1521
+ keepTextsForHiddenInstances: i.keepTextsForHiddenInstances || void 0,
1522
+ loadBlocks: i.loadBlocks,
1523
+ suppressExpandedInsertGeometry: i.suppressExpandedInsertGeometry,
1524
+ maxExpandedInstanceVertices: i.maxExpandedInstanceVertices,
1525
+ externalVariantFetchSource: i.externalVariantFetchSource,
1526
+ externalVariantBuffers: l,
1527
+ requiredExternalVariantIds: i.requiredExternalVariantIds,
1528
+ externalVariantGeometryFetchIds: i.externalVariantGeometryFetchIds,
1529
+ externalVariantDeltaOnly: !0,
1530
+ appendExternalVariantDelta: !0
1531
+ });
1532
+ } catch (u) {
1533
+ throw Mn(u);
1534
+ }
1535
+ }
1536
+ const Ai = "?", Ti = {
1537
+ "℄": "CL",
1538
+ "∅": "Ø",
1539
+ "⌀": "Ø"
1540
+ };
1541
+ function Pi(t) {
1542
+ return t >= 0 && t <= 8 || t >= 11 && t <= 31 || t >= 127 && t <= 159 || t >= 65024 && t <= 65039 || t >= 917760 && t <= 917999;
1543
+ }
1544
+ function Li(t) {
1545
+ return t >= 13312 && t <= 19903 || t >= 131072 && t <= 173791 || t >= 173824 && t <= 177983 || t >= 177984 && t <= 178207 || t >= 178208 && t <= 183983 || t >= 183984 && t <= 191471 || t >= 191472 && t <= 192095 || t >= 196608 && t <= 201551 || t >= 201552 && t <= 205743 || t >= 194560 && t <= 195103;
1546
+ }
1547
+ function Mi(t) {
1548
+ let n = !1, e = "";
1549
+ for (const r of t) {
1550
+ const i = r.codePointAt(0);
1551
+ if (i === void 0) continue;
1552
+ const a = Ti[r];
1553
+ if (a !== void 0) {
1554
+ e += a, n = !0;
1555
+ continue;
1556
+ }
1557
+ if (Pi(i)) {
1558
+ n = !0;
1559
+ continue;
1560
+ }
1561
+ if (Li(i)) {
1562
+ e += Ai, n = !0;
1563
+ continue;
1564
+ }
1565
+ e += r;
1566
+ }
1567
+ return { text: e, replacedUnsupported: n };
1568
+ }
1569
+ function Di(t) {
1570
+ return Mi(t);
1571
+ }
1572
+ function Wt(t) {
1573
+ if (!Number.isFinite(t)) return 0;
1574
+ const n = Math.round(t);
1575
+ return n < 0 ? 0 : n > 255 ? 255 : n;
1576
+ }
1577
+ function Fn(t) {
1578
+ return Number.isFinite(t) ? t >= 0 && t <= 1 ? Wt(t * 255) : Wt(t) : 0;
1579
+ }
1580
+ function On(t) {
1581
+ if (t instanceof Uint8Array)
1582
+ return t;
1583
+ const n = new Uint8Array(t.length);
1584
+ for (let e = 0; e < t.length; e += 1)
1585
+ n[e] = Fn(t[e] ?? 0);
1586
+ return n;
1587
+ }
1588
+ function Fi(t) {
1589
+ const n = new Float32Array(t.length);
1590
+ for (let e = 0; e < t.length; e += 1)
1591
+ n[e] = (t[e] ?? 0) / 255;
1592
+ return n;
1593
+ }
1594
+ function $t(t) {
1595
+ return new U(t, 3, !0);
1596
+ }
1597
+ function Oi(t) {
1598
+ const n = t.array;
1599
+ if (n instanceof Uint8Array)
1600
+ return n;
1601
+ if (n instanceof Float32Array)
1602
+ return On(n);
1603
+ const e = new Uint8Array(n.length);
1604
+ for (let r = 0; r < n.length; r += 1)
1605
+ e[r] = Fn(Number(n[r] ?? 0));
1606
+ return e;
1607
+ }
1608
+ function ze(t, n) {
1609
+ if (!Number.isInteger(t) || t < 0)
1610
+ return !1;
1611
+ let e = 0;
1612
+ for (const r of n)
1613
+ if (!Number.isInteger(r.startVertex) || !Number.isInteger(r.vertexCount) || r.vertexCount <= 0 || r.startVertex !== e || (e += r.vertexCount, e > t))
1614
+ return !1;
1615
+ return e === t;
1616
+ }
1617
+ function Gi(t, n) {
1618
+ if (!ze(t, n))
1619
+ throw new Error("Source color runs must be positive, contiguous, and cover the vertex count exactly.");
1620
+ }
1621
+ function Gn(t, n, e) {
1622
+ return (t & 255) << 16 | (n & 255) << 8 | e & 255;
1623
+ }
1624
+ function _i(t, n) {
1625
+ const e = new Uint8Array(t.length), r = Math.floor(t.length / 3), i = /* @__PURE__ */ new Map();
1626
+ let a = -1, s = [0, 0, 0], o = 0, c = 0, l = 0;
1627
+ for (let u = 0; u < r; u += 1) {
1628
+ const d = u * 3, h = t[d] ?? 0, f = t[d + 1] ?? 0, b = t[d + 2] ?? 0, g = Gn(h, f, b);
1629
+ let C;
1630
+ if (g === a)
1631
+ C = s, l += 1;
1632
+ else {
1633
+ o += 1;
1634
+ const v = i.get(g);
1635
+ if (v)
1636
+ C = v, c += 1;
1637
+ else {
1638
+ const x = n([h, f, b]);
1639
+ C = [x[0], x[1], x[2]], i.set(g, C);
1640
+ }
1641
+ a = g, s = C;
1642
+ }
1643
+ e[d] = C[0], e[d + 1] = C[1], e[d + 2] = C[2];
1644
+ }
1645
+ return {
1646
+ color: e,
1647
+ stats: {
1648
+ vertexCount: r,
1649
+ runCount: o,
1650
+ uniqueColorCount: i.size,
1651
+ cacheHitCount: c,
1652
+ repeatedRunVertexCount: l
1653
+ }
1654
+ };
1655
+ }
1656
+ function jt(t, n, e) {
1657
+ const r = new Uint8Array(t * 3), i = dt(r, t, n, e);
1658
+ return {
1659
+ color: r,
1660
+ stats: i
1661
+ };
1662
+ }
1663
+ function zi(t, n, e) {
1664
+ const r = new Float32Array(t * 3), i = Ui(r, t, n, e);
1665
+ return {
1666
+ color: r,
1667
+ stats: i
1668
+ };
1669
+ }
1670
+ function dt(t, n, e, r) {
1671
+ return _n(t, n, e, r, 1);
1672
+ }
1673
+ function Ui(t, n, e, r) {
1674
+ return _n(t, n, e, r, 1 / 255);
1675
+ }
1676
+ function _n(t, n, e, r, i) {
1677
+ Gi(n, e);
1678
+ const a = n * 3;
1679
+ if (t.length !== a)
1680
+ throw new Error("Display color target must cover the vertex count exactly.");
1681
+ const s = /* @__PURE__ */ new Map();
1682
+ let o = 0, c = 0;
1683
+ for (const l of e) {
1684
+ if (l.vertexCount <= 0) continue;
1685
+ const u = l.color[0] ?? 0, d = l.color[1] ?? 0, h = l.color[2] ?? 0, f = Gn(u, d, h);
1686
+ let b = s.get(f);
1687
+ if (b)
1688
+ o += 1;
1689
+ else {
1690
+ const C = r([u, d, h]);
1691
+ b = [C[0], C[1], C[2]], s.set(f, b);
1692
+ }
1693
+ c += Math.max(0, l.vertexCount - 1);
1694
+ const g = Math.min(n, l.startVertex + l.vertexCount);
1695
+ for (let C = l.startVertex; C < g; C += 1) {
1696
+ const v = C * 3;
1697
+ t[v] = b[0] * i, t[v + 1] = b[1] * i, t[v + 2] = b[2] * i;
1698
+ }
1699
+ }
1700
+ return {
1701
+ vertexCount: n,
1702
+ runCount: e.filter((l) => l.vertexCount > 0).length,
1703
+ uniqueColorCount: s.size,
1704
+ cacheHitCount: o,
1705
+ repeatedRunVertexCount: c
1706
+ };
1707
+ }
1708
+ const Ni = {
1709
+ dark: {
1710
+ background: [12, 12, 20],
1711
+ foreground: [242, 244, 248],
1712
+ defaultLine: [200, 200, 200],
1713
+ defaultText: [232, 235, 242],
1714
+ hover: [105, 160, 255],
1715
+ selected: [64, 255, 118],
1716
+ lockedOpacity: 0.42,
1717
+ xrefOpacity: 0.35,
1718
+ hatchOpacity: 0.5
1719
+ },
1720
+ light: {
1721
+ background: [247, 248, 251],
1722
+ foreground: [32, 41, 56],
1723
+ defaultLine: [48, 57, 74],
1724
+ defaultText: [24, 32, 44],
1725
+ hover: [42, 104, 218],
1726
+ selected: [31, 160, 82],
1727
+ lockedOpacity: 0.38,
1728
+ xrefOpacity: 0.32,
1729
+ hatchOpacity: 0.28
1730
+ }
1731
+ }, Hi = {
1732
+ 1: [255, 0, 0],
1733
+ 2: [255, 255, 0],
1734
+ 3: [0, 255, 0],
1735
+ 4: [0, 255, 255],
1736
+ 5: [0, 0, 255],
1737
+ 6: [255, 0, 255],
1738
+ 8: [128, 128, 128],
1739
+ 9: [192, 192, 192]
1740
+ }, Ki = 8;
1741
+ function zn(t) {
1742
+ return Ni[t];
1743
+ }
1744
+ function Zt(t, n) {
1745
+ const e = zn(n.theme), r = n.elementKind ?? "line", i = n.state ?? "normal", a = Ge(t, n, 0);
1746
+ let s = qi(a, e, r), o = a.kind === "aci" && Un(a.index) === 7;
1747
+ if (n.enhanceContrast) {
1748
+ const l = Yi(s, {
1749
+ theme: n.theme,
1750
+ elementKind: r
1751
+ });
1752
+ o || (o = !$i(s, l)), s = l;
1753
+ }
1754
+ let c = r === "hatch" ? e.hatchOpacity : 1;
1755
+ return i === "hidden" && (c = 0), i === "locked" && (c *= e.lockedOpacity), i === "xrefFaded" && (c *= e.xrefOpacity), i === "hover" && (s = e.hover, o = !0), i === "selected" && (s = e.selected, o = !0), {
1756
+ rgb: s,
1757
+ opacity: c,
1758
+ raw: t,
1759
+ resolvedRaw: a,
1760
+ adapted: o
1761
+ };
1762
+ }
1763
+ function Yi(t, n) {
1764
+ const e = zn(n.theme), r = n.elementKind === "text" ? 4.5 : n.elementKind === "hatch" ? 1.6 : 2.2;
1765
+ return Nn(t, e.background) >= r ? ge(t) : ji(t, e.background, r, n.theme);
1766
+ }
1767
+ function Ge(t, n, e = 0) {
1768
+ return e > Ki ? n.fallbackColor ?? { kind: "aci", index: 7 } : t.kind === "bylayer" ? Ge(n.layerColor ?? n.fallbackColor ?? { kind: "aci", index: 7 }, n, e + 1) : t.kind === "byblock" ? Ge(
1769
+ n.byBlockColor ?? n.parentByBlockColor ?? n.fallbackColor ?? { kind: "aci", index: 7 },
1770
+ {
1771
+ ...n,
1772
+ byBlockColor: n.parentByBlockColor ?? null
1773
+ },
1774
+ e + 1
1775
+ ) : t.kind === "none" ? Ge(n.fallbackColor ?? { kind: "aci", index: 7 }, n, e + 1) : t;
1776
+ }
1777
+ function Xi(t) {
1778
+ return kt(t);
1779
+ }
1780
+ function kt(t) {
1781
+ return Math.abs(t[0] - 200) <= 2 && Math.abs(t[1] - 200) <= 2 && Math.abs(t[2] - 200) <= 2;
1782
+ }
1783
+ function Qi(t, n = {}) {
1784
+ return n.treatLegacyForegroundAsAci7 && Xi(t) ? { kind: "aci", index: 7 } : { kind: "truecolor", rgb: ge(t) };
1785
+ }
1786
+ function qi(t, n, e) {
1787
+ return t.kind === "truecolor" ? ge(t.rgb) : t.kind === "aci" ? Wi(t.index, n) : (t.kind === "none", e === "text" ? n.defaultText : n.defaultLine);
1788
+ }
1789
+ function Wi(t, n) {
1790
+ const e = Un(t);
1791
+ return ge(e === 7 || e === 0 || e === 256 ? n.foreground : Hi[e] ?? n.defaultLine);
1792
+ }
1793
+ function Un(t) {
1794
+ return Number.isFinite(t) ? Math.abs(Math.trunc(t)) : 7;
1795
+ }
1796
+ function ge(t) {
1797
+ return [O(t[0]), O(t[1]), O(t[2])];
1798
+ }
1799
+ function $i(t, n) {
1800
+ return t[0] === n[0] && t[1] === n[1] && t[2] === n[2];
1801
+ }
1802
+ function O(t) {
1803
+ return Number.isFinite(t) ? Math.max(0, Math.min(255, Math.round(t))) : 0;
1804
+ }
1805
+ function Jt(t) {
1806
+ const [n, e, r] = t.map((i) => {
1807
+ const a = O(i) / 255;
1808
+ return a <= 0.03928 ? a / 12.92 : ((a + 0.055) / 1.055) ** 2.4;
1809
+ });
1810
+ return 0.2126 * (n ?? 0) + 0.7152 * (e ?? 0) + 0.0722 * (r ?? 0);
1811
+ }
1812
+ function Nn(t, n) {
1813
+ const e = Jt(t), r = Jt(n), i = Math.max(e, r), a = Math.min(e, r);
1814
+ return (i + 0.05) / (a + 0.05);
1815
+ }
1816
+ function ji(t, n, e, r) {
1817
+ const i = Zi(t);
1818
+ let a = 0, s = 1, o = ge(t);
1819
+ for (let c = 0; c < 16; c += 1) {
1820
+ const l = (a + s) / 2, u = r === "light" ? i.l * (1 - l) : i.l + (1 - i.l) * l, d = Ji(i.h, i.s, u);
1821
+ Nn(d, n) >= e ? (o = d, s = l) : a = l;
1822
+ }
1823
+ return o;
1824
+ }
1825
+ function Zi(t) {
1826
+ const n = O(t[0]) / 255, e = O(t[1]) / 255, r = O(t[2]) / 255, i = Math.max(n, e, r), a = Math.min(n, e, r), s = (i + a) / 2;
1827
+ if (i === a) return { h: 0, s: 0, l: s };
1828
+ const o = i - a, c = s > 0.5 ? o / (2 - i - a) : o / (i + a);
1829
+ let l = 0;
1830
+ return i === n ? l = (e - r) / o + (e < r ? 6 : 0) : i === e ? l = (r - n) / o + 2 : l = (n - e) / o + 4, l /= 6, { h: l, s: c, l: s };
1831
+ }
1832
+ function Ji(t, n, e) {
1833
+ if (n === 0) {
1834
+ const s = O(e * 255);
1835
+ return [s, s, s];
1836
+ }
1837
+ const r = (s, o, c) => {
1838
+ let l = c;
1839
+ return l < 0 && (l += 1), l > 1 && (l -= 1), l < 1 / 6 ? s + (o - s) * 6 * l : l < 1 / 2 ? o : l < 2 / 3 ? s + (o - s) * (2 / 3 - l) * 6 : s;
1840
+ }, i = e < 0.5 ? e * (1 + n) : e + n - e * n, a = 2 * e - i;
1841
+ return [
1842
+ O(r(a, i, t + 1 / 3) * 255),
1843
+ O(r(a, i, t) * 255),
1844
+ O(r(a, i, t - 1 / 3) * 255)
1845
+ ];
1846
+ }
1847
+ const ea = "dark", ta = `
1848
+ precision highp float;
1849
+
1850
+ uniform mat4 modelViewMatrix;
1851
+ uniform mat4 projectionMatrix;
1852
+ uniform vec2 uResolution;
1853
+ uniform float uLineWidthPx;
1854
+ uniform float uUseLayerColor;
1855
+ uniform vec3 uLayerColor;
1856
+
1857
+ attribute vec3 position;
1858
+
1859
+ #ifdef CAD_LINE_FAT
1860
+ attribute vec3 instanceStart;
1861
+ attribute vec3 instanceEnd;
1862
+ attribute vec3 instanceColorStart;
1863
+ attribute vec3 instanceColorEnd;
1864
+ #else
1865
+ attribute vec3 color;
1866
+ #endif
1867
+
1868
+ varying vec3 vColor;
1869
+
1870
+ vec2 safeNormalize2(vec2 value) {
1871
+ float lenSq = dot(value, value);
1872
+ vec2 normalized = value * inversesqrt(max(lenSq, 0.000000000001));
1873
+ return mix(vec2(1.0, 0.0), normalized, step(0.000000000001, lenSq));
1874
+ }
1875
+
1876
+ void main() {
1877
+ #ifdef CAD_LINE_FAT
1878
+ vec4 clipStart = projectionMatrix * modelViewMatrix * vec4(instanceStart, 1.0);
1879
+ vec4 clipEnd = projectionMatrix * modelViewMatrix * vec4(instanceEnd, 1.0);
1880
+ vec2 ndcStart = clipStart.xy / clipStart.w;
1881
+ vec2 ndcEnd = clipEnd.xy / clipEnd.w;
1882
+ vec2 dir = safeNormalize2(ndcEnd - ndcStart);
1883
+ vec2 normal = vec2(-dir.y, dir.x);
1884
+ float side = position.x;
1885
+ float endpoint = position.y;
1886
+ float cap = position.z;
1887
+ vec2 offsetPx = normal * side * uLineWidthPx * 0.5 + dir * cap * uLineWidthPx * 0.5;
1888
+ vec4 clip = mix(clipStart, clipEnd, endpoint);
1889
+ clip.xy += (offsetPx / uResolution) * 2.0 * clip.w;
1890
+ gl_Position = clip;
1891
+ vec3 sourceColor = mix(instanceColorStart, instanceColorEnd, endpoint);
1892
+ #else
1893
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1894
+ vec3 sourceColor = color;
1895
+ #endif
1896
+ vColor = mix(sourceColor, uLayerColor, uUseLayerColor);
1897
+ }
1898
+ `, na = `
1899
+ precision highp float;
1900
+
1901
+ uniform float uOpacity;
1902
+ varying vec3 vColor;
1903
+
1904
+ vec3 linearToOutputSrgb(vec3 value) {
1905
+ vec3 linear = max(value, vec3(0.0));
1906
+ vec3 lower = linear * 12.92;
1907
+ vec3 higher = 1.055 * pow(linear, vec3(1.0 / 2.4)) - 0.055;
1908
+ vec3 useHigher = step(vec3(0.0031308), linear);
1909
+ return clamp(mix(lower, higher, useHigher), 0.0, 1.0);
1910
+ }
1911
+
1912
+ void main() {
1913
+ gl_FragColor = vec4(linearToOutputSrgb(vColor), uOpacity);
1914
+ }
1915
+ `;
1916
+ class Hn extends yr {
1917
+ constructor(e) {
1918
+ var s, o;
1919
+ const r = new pn(16777215), i = new gn(1, 1), a = e.variant === "fat";
1920
+ super({
1921
+ glslVersion: null,
1922
+ defines: a ? { CAD_LINE_FAT: 1 } : {},
1923
+ ...a ? { side: st } : {},
1924
+ uniforms: {
1925
+ uResolution: { value: i },
1926
+ uLineWidthPx: { value: 1 },
1927
+ uUseLayerColor: { value: 0 },
1928
+ uLayerColor: { value: r },
1929
+ uOpacity: { value: 1 }
1930
+ },
1931
+ vertexShader: ta,
1932
+ fragmentShader: na,
1933
+ vertexColors: !0
1934
+ });
1935
+ m(this, "color");
1936
+ m(this, "resolution");
1937
+ this.color = r, this.resolution = i, this.linewidthPx = e.linewidthPx ?? 1, this.updateResolution(((s = e.resolution) == null ? void 0 : s.x) ?? 1, ((o = e.resolution) == null ? void 0 : o.y) ?? 1);
1938
+ }
1939
+ get vertexColors() {
1940
+ return this.uniforms.uUseLayerColor.value === 0;
1941
+ }
1942
+ set vertexColors(e) {
1943
+ var r;
1944
+ (r = this.uniforms) != null && r.uUseLayerColor && (this.uniforms.uUseLayerColor.value = e ? 0 : 1);
1945
+ }
1946
+ get opacity() {
1947
+ return this.uniforms.uOpacity.value;
1948
+ }
1949
+ set opacity(e) {
1950
+ var r;
1951
+ (r = this.uniforms) != null && r.uOpacity && (this.uniforms.uOpacity.value = e, this.transparent = e < 1);
1952
+ }
1953
+ get linewidthPx() {
1954
+ return this.uniforms.uLineWidthPx.value;
1955
+ }
1956
+ set linewidthPx(e) {
1957
+ this.uniforms.uLineWidthPx.value = Math.max(1, e);
1958
+ }
1959
+ updateResolution(e, r) {
1960
+ this.uniforms.uResolution.value.set(Math.max(1, e), Math.max(1, r));
1961
+ }
1962
+ }
1963
+ const ra = new Float32Array([
1964
+ -1,
1965
+ 1,
1966
+ 1,
1967
+ 1,
1968
+ 1,
1969
+ 1,
1970
+ -1,
1971
+ 1,
1972
+ 0,
1973
+ 1,
1974
+ 1,
1975
+ 0,
1976
+ -1,
1977
+ 0,
1978
+ 0,
1979
+ 1,
1980
+ 0,
1981
+ 0,
1982
+ -1,
1983
+ 0,
1984
+ -1,
1985
+ 1,
1986
+ 0,
1987
+ -1
1988
+ ]), ia = [
1989
+ 0,
1990
+ 2,
1991
+ 1,
1992
+ 2,
1993
+ 3,
1994
+ 1,
1995
+ 2,
1996
+ 4,
1997
+ 3,
1998
+ 4,
1999
+ 5,
2000
+ 3,
2001
+ 4,
2002
+ 6,
2003
+ 5,
2004
+ 6,
2005
+ 7,
2006
+ 5
2007
+ ];
2008
+ function aa(t) {
2009
+ const n = new Ye(t.minX, t.minY, 0), e = new Ye(t.maxX, t.maxY, 0), r = new mr(n, e), i = new Ye((t.minX + t.maxX) / 2, (t.minY + t.maxY) / 2, 0), a = Math.hypot(t.maxX - t.minX, t.maxY - t.minY) / 2;
2010
+ return { box: r, sphere: new xr(i, a) };
2011
+ }
2012
+ function Kn(t, n) {
2013
+ const e = aa(n);
2014
+ t.boundingBox = e.box, t.boundingSphere = e.sphere;
2015
+ }
2016
+ function sa(t) {
2017
+ const n = new xt();
2018
+ n.setAttribute("position", new U(t.position, t.positionItemSize)), n.setAttribute("color", new U(t.color, 3, !0)), Kn(n, t.bbox);
2019
+ const e = new Hn({ variant: "thin" }), r = new pt(n, e);
2020
+ return r.name = "cad-thin-line", r.renderOrder = 1, r.userData.kind = "line", r.userData.mode = "thin", r.userData.vertexCount = t.vertexCount, r.userData.bbox = t.bbox, r;
2021
+ }
2022
+ function oa(t) {
2023
+ const n = Math.floor(t.vertexCount / 2), e = t.positionItemSize * 2, r = new Mt(t.position, e, 1), i = new Mt(t.color, 6, 1), a = new bn();
2024
+ a.setIndex(ia), a.setAttribute("position", new Cn(ra.slice(), 3)), a.setAttribute("instanceStart", new Te(r, t.positionItemSize, 0)), a.setAttribute("instanceEnd", new Te(r, t.positionItemSize, t.positionItemSize)), a.setAttribute("instanceColorStart", new Te(i, 3, 0, !0)), a.setAttribute("instanceColorEnd", new Te(i, 3, 3, !0)), a.instanceCount = n, Kn(a, t.bbox);
2025
+ const s = new Hn({
2026
+ variant: "fat",
2027
+ linewidthPx: t.linewidthPx,
2028
+ resolution: t.resolution
2029
+ }), o = new gt(a, s);
2030
+ return o.name = "cad-fat-line", o.renderOrder = 1, o.userData.kind = "line", o.userData.mode = "fat", o.userData.vertexCount = t.vertexCount, o.userData.bbox = t.bbox, o;
2031
+ }
2032
+ function Je(t) {
2033
+ const n = t.getAttribute("color");
2034
+ n && (n.needsUpdate = !0);
2035
+ const e = t.getAttribute("instanceColorStart"), r = t.getAttribute("instanceColorEnd");
2036
+ e && (e.needsUpdate = !0), r && (r.needsUpdate = !0);
2037
+ }
2038
+ const la = 65536;
2039
+ class ca {
2040
+ constructor(n) {
2041
+ this.variants = n;
2042
+ }
2043
+ getVariant(n) {
2044
+ return this.variants.get(n);
2045
+ }
2046
+ variantIds() {
2047
+ return this.variants.keys();
2048
+ }
2049
+ appendVariants(n) {
2050
+ const e = [];
2051
+ for (const r of n) {
2052
+ const i = Xn(r);
2053
+ if (!i) continue;
2054
+ const a = this.variants.get(i.variantId);
2055
+ a && en(a), this.variants.set(i.variantId, i), e.push(i);
2056
+ }
2057
+ return e;
2058
+ }
2059
+ dispose() {
2060
+ for (const n of this.variants.values())
2061
+ en(n);
2062
+ this.variants.clear();
2063
+ }
2064
+ }
2065
+ function et(t, n) {
2066
+ const e = [];
2067
+ for (const r of n) {
2068
+ if (r.count <= 0) continue;
2069
+ const i = r.bbox !== void 0 ? ha(r.bbox) : Me(r.pos, r.count, 3), a = ua(t);
2070
+ for (let s = 0; s < r.count; ) {
2071
+ const o = da(s, r.count, a, Yn(t)), c = new xt(), l = r.pos.subarray(s * 3, o * 3), u = r.col.subarray(s * 3, o * 3), d = o - s;
2072
+ c.setAttribute("position", new U(l, 3)), c.setAttribute("color", new U(u, 3, !0)), e.push({
2073
+ geometry: c,
2074
+ vertexCount: d,
2075
+ layerIndex: r.layerIndex ?? 0,
2076
+ ...r.lineweightPx === void 0 ? {} : { lineweightPx: r.lineweightPx },
2077
+ bbox: i
2078
+ }), s = o;
2079
+ }
2080
+ }
2081
+ return e;
2082
+ }
2083
+ function Yn(t) {
2084
+ return t === "line" ? 2 : t === "fill" ? 3 : 1;
2085
+ }
2086
+ function ua(t) {
2087
+ const n = Yn(t);
2088
+ return Math.max(n, Math.floor(la / n) * n);
2089
+ }
2090
+ function da(t, n, e, r) {
2091
+ let i = Math.min(n, t + e);
2092
+ if (i < n) {
2093
+ const a = t + Math.floor((i - t) / r) * r;
2094
+ a > t && (i = a);
2095
+ }
2096
+ return i > t ? i : n;
2097
+ }
2098
+ function ha(t) {
2099
+ return t ? { minX: t.minX, minY: t.minY, maxX: t.maxX, maxY: t.maxY } : null;
2100
+ }
2101
+ function fa(t) {
2102
+ const n = /* @__PURE__ */ new Map();
2103
+ for (const e of t) {
2104
+ const r = Xn(e);
2105
+ r && n.set(r.variantId, r);
2106
+ }
2107
+ return new ca(n);
2108
+ }
2109
+ function Xn(t) {
2110
+ const n = /* @__PURE__ */ new Map(), e = et("line", t.line);
2111
+ e.length > 0 && n.set("line", e);
2112
+ const r = et("fill", t.fill);
2113
+ r.length > 0 && n.set("fill", r);
2114
+ const i = et("dot", t.dot);
2115
+ return i.length > 0 && n.set("dot", i), n.size > 0 ? { variantId: t.variantId, byKind: n } : null;
2116
+ }
2117
+ function en(t) {
2118
+ for (const n of t.byKind.values())
2119
+ for (const e of n)
2120
+ e.geometry.dispose();
2121
+ }
2122
+ class ya {
2123
+ constructor(n, e) {
2124
+ m(this, "mutableRecords");
2125
+ m(this, "indexByRecordKey", /* @__PURE__ */ new Map());
2126
+ this.tree = e, this.mutableRecords = [...n];
2127
+ for (let r = 0; r < this.mutableRecords.length; r += 1)
2128
+ this.indexByRecordKey.set(tt(this.mutableRecords[r]), r);
2129
+ }
2130
+ get records() {
2131
+ return this.mutableRecords;
2132
+ }
2133
+ appendRecords(n) {
2134
+ if (n.length === 0) return;
2135
+ const e = new Array(n.length), r = this.mutableRecords.length;
2136
+ for (let i = 0; i < n.length; i += 1) {
2137
+ const a = n[i];
2138
+ this.mutableRecords.push(a), this.indexByRecordKey.set(tt(a), r + i), e[i] = {
2139
+ minX: a.bbox.minX,
2140
+ minY: a.bbox.minY,
2141
+ maxX: a.bbox.maxX,
2142
+ maxY: a.bbox.maxY,
2143
+ index: r + i
2144
+ };
2145
+ }
2146
+ this.tree.load(e);
2147
+ }
2148
+ replaceRecord(n) {
2149
+ const e = this.indexByRecordKey.get(tt(n));
2150
+ if (e === void 0) return !1;
2151
+ const r = this.mutableRecords[e];
2152
+ return this.tree.remove(ht(r, e), (i, a) => i.index === a.index), this.mutableRecords[e] = n, this.tree.insert(ht(n, e)), !0;
2153
+ }
2154
+ queryInRect(n) {
2155
+ const e = this.tree.search({
2156
+ minX: n.minX,
2157
+ minY: n.minY,
2158
+ maxX: n.maxX,
2159
+ maxY: n.maxY
2160
+ }), r = new Array(e.length);
2161
+ for (let i = 0; i < e.length; i++)
2162
+ r[i] = this.records[e[i].index];
2163
+ return r;
2164
+ }
2165
+ size() {
2166
+ return this.mutableRecords.length;
2167
+ }
2168
+ variantHistogram() {
2169
+ const n = /* @__PURE__ */ new Map();
2170
+ for (const e of this.mutableRecords)
2171
+ n.set(e.variantId, (n.get(e.variantId) ?? 0) + 1);
2172
+ return n;
2173
+ }
2174
+ }
2175
+ function tt(t) {
2176
+ return t.recordKey ?? String(t.instanceId);
2177
+ }
2178
+ function ht(t, n) {
2179
+ return {
2180
+ minX: t.bbox.minX,
2181
+ minY: t.bbox.minY,
2182
+ maxX: t.bbox.maxX,
2183
+ maxY: t.bbox.maxY,
2184
+ index: n
2185
+ };
2186
+ }
2187
+ function ma(t) {
2188
+ const n = new gr();
2189
+ if (t.length > 0) {
2190
+ const e = new Array(t.length);
2191
+ for (let r = 0; r < t.length; r++)
2192
+ e[r] = ht(t[r], r);
2193
+ n.load(e);
2194
+ }
2195
+ return new ya(t, n);
2196
+ }
2197
+ class xa {
2198
+ constructor(n) {
2199
+ m(this, "slots", []);
2200
+ m(this, "group", new In());
2201
+ m(this, "marginRatio");
2202
+ m(this, "table");
2203
+ m(this, "materialFactory");
2204
+ m(this, "initialCapacity");
2205
+ m(this, "attachedParent", null);
2206
+ m(this, "lastQueryAll", !1);
2207
+ m(this, "lastQueryRect", null);
2208
+ m(this, "lastQueryHits", []);
2209
+ m(this, "lastFilteredQueryRect", null);
2210
+ m(this, "lastFilteredQueryAll", !1);
2211
+ m(this, "lastLayerVersion", -1);
2212
+ m(this, "lastUserHiddenCacheKey", "");
2213
+ m(this, "cacheValid", !1);
2214
+ m(this, "visibleVertexCount", 0);
2215
+ this.table = n.table, this.marginRatio = n.marginRatio, this.materialFactory = n.materialFactory, this.initialCapacity = Math.max(1, n.initialCapacity);
2216
+ for (const e of n.registry.variantIds()) {
2217
+ const r = n.registry.getVariant(e);
2218
+ r && this.appendVariant(r);
2219
+ }
2220
+ }
2221
+ appendVariant(n) {
2222
+ this.removeVariantSlots(n.variantId);
2223
+ for (const [e, r] of n.byKind)
2224
+ for (const i of r) {
2225
+ const a = this.initialCapacity, s = new bn(), o = i.geometry.getAttribute("position"), c = i.geometry.getAttribute("color");
2226
+ o && s.setAttribute("position", o), c && s.setAttribute("color", c), s.instanceCount = 0;
2227
+ const l = new ce(new Float32Array(a * 4), 4), u = new ce(new Float32Array(a * 4), 4), d = new ce(new Float32Array(a), 1);
2228
+ s.setAttribute("promotedInstMatRow0", l), s.setAttribute("promotedInstMatRow1", u), s.setAttribute("promotedInstVisible", d);
2229
+ const h = ga(e, s, this.materialFactory(e));
2230
+ h.visible = !1, h.frustumCulled = !1, h.userData.kind = e, h.userData.variantId = n.variantId, h.userData.insertPresenterMesh = !0, h.userData.vertexCount = 0, this.slots.push({
2231
+ variantId: n.variantId,
2232
+ kind: e,
2233
+ geometryLayerIndex: i.layerIndex,
2234
+ perVertexCount: i.vertexCount,
2235
+ localBBox: i.bbox,
2236
+ mesh: h,
2237
+ matRow0Attr: l,
2238
+ matRow1Attr: u,
2239
+ visibleAttr: d,
2240
+ capacity: a
2241
+ }), this.group.add(h);
2242
+ }
2243
+ this.invalidateFilteredQueryCache();
2244
+ }
2245
+ attach(n) {
2246
+ this.attachedParent !== n && (this.detach(), n.add(this.group), this.attachedParent = n);
2247
+ }
2248
+ detach() {
2249
+ this.attachedParent && (this.attachedParent.remove(this.group), this.attachedParent = null);
2250
+ }
2251
+ invalidateQueryCache() {
2252
+ this.lastQueryAll = !1, this.lastQueryRect = null, this.lastQueryHits = [], this.invalidateFilteredQueryCache();
2253
+ }
2254
+ refresh(n, e, r, i) {
2255
+ const a = n ? ar(n, this.marginRatio) : null, s = !a, o = i === void 0 ? `signature:${pa(r)}` : `revision:${i}`;
2256
+ if (this.cacheValid && this.lastLayerVersion === e.version && this.lastUserHiddenCacheKey === o && this.lastFilteredQueryAll === s && sr(this.lastFilteredQueryRect, a))
2257
+ return;
2258
+ const c = this.resolveQueryHits(a), l = /* @__PURE__ */ new Map();
2259
+ for (const d of c) {
2260
+ if (a && !or(a, d.bbox) || r.has(d.instanceId)) continue;
2261
+ let h = l.get(d.variantId);
2262
+ h || (h = [], l.set(d.variantId, h)), h.push(d);
2263
+ }
2264
+ let u = 0;
2265
+ for (const d of this.slots) {
2266
+ const h = l.get(d.variantId), f = h == null ? void 0 : h.filter((b) => this.slotVisibleForRecord(d, b, e));
2267
+ if (!f || f.length === 0) {
2268
+ tn(d.mesh, 0), d.mesh.userData.vertexCount = 0, d.mesh.visible = !1;
2269
+ continue;
2270
+ }
2271
+ this.ensureCapacity(d, f.length), this.writeMatRows(d, f), tn(d.mesh, f.length), d.mesh.userData.vertexCount = f.length * d.perVertexCount, d.mesh.visible = !0, u += f.length * d.perVertexCount;
2272
+ }
2273
+ this.visibleVertexCount = u, this.lastLayerVersion = e.version, this.lastUserHiddenCacheKey = o, this.lastFilteredQueryAll = s, this.lastFilteredQueryRect = a ? {
2274
+ minX: a.minX,
2275
+ minY: a.minY,
2276
+ maxX: a.maxX,
2277
+ maxY: a.maxY
2278
+ } : null, this.cacheValid = !0;
2279
+ }
2280
+ currentVisibleVertexCount() {
2281
+ return this.visibleVertexCount;
2282
+ }
2283
+ resolveQueryHits(n) {
2284
+ if (!n)
2285
+ return this.lastQueryAll || (this.lastQueryAll = !0, this.lastQueryRect = null, this.lastQueryHits = this.table.records), this.lastQueryHits;
2286
+ if (!this.lastQueryAll && this.lastQueryRect && lr(this.lastQueryRect, n))
2287
+ return this.lastQueryHits;
2288
+ const e = this.table.queryInRect(n);
2289
+ return this.lastQueryAll = !1, this.lastQueryRect = n, this.lastQueryHits = e, e;
2290
+ }
2291
+ removeVariantSlots(n) {
2292
+ let e = !1;
2293
+ for (let r = this.slots.length - 1; r >= 0; r -= 1) {
2294
+ const i = this.slots[r];
2295
+ i.variantId === n && (this.group.remove(i.mesh), i.mesh.geometry.dispose(), nn(i.mesh.material), this.slots.splice(r, 1), e = !0);
2296
+ }
2297
+ e && this.invalidateFilteredQueryCache();
2298
+ }
2299
+ invalidateFilteredQueryCache() {
2300
+ this.lastFilteredQueryRect = null, this.lastFilteredQueryAll = !1, this.lastLayerVersion = -1, this.lastUserHiddenCacheKey = "", this.cacheValid = !1;
2301
+ }
2302
+ dispose() {
2303
+ this.detach();
2304
+ for (const n of this.slots)
2305
+ this.group.remove(n.mesh), n.mesh.geometry.dispose(), nn(n.mesh.material);
2306
+ this.slots.length = 0, this.invalidateQueryCache(), this.visibleVertexCount = 0;
2307
+ }
2308
+ _debugSlots() {
2309
+ return this.slots;
2310
+ }
2311
+ ensureCapacity(n, e) {
2312
+ if (n.capacity >= e) return;
2313
+ const r = Math.max(e, n.capacity * 2);
2314
+ n.matRow0Attr = new ce(new Float32Array(r * 4), 4), n.matRow1Attr = new ce(new Float32Array(r * 4), 4), n.visibleAttr = new ce(new Float32Array(r), 1), n.mesh.geometry.setAttribute("promotedInstMatRow0", n.matRow0Attr), n.mesh.geometry.setAttribute("promotedInstMatRow1", n.matRow1Attr), n.mesh.geometry.setAttribute("promotedInstVisible", n.visibleAttr), n.capacity = r;
2315
+ }
2316
+ writeMatRows(n, e) {
2317
+ const r = n.matRow0Attr.array, i = n.matRow1Attr.array, a = n.visibleAttr.array;
2318
+ for (let o = 0; o < e.length; o += 1) {
2319
+ const c = e[o], l = o * 4;
2320
+ r[l] = c.matA, r[l + 1] = c.matC, r[l + 2] = c.tx, r[l + 3] = 0, i[l] = c.matB, i[l + 1] = c.matD, i[l + 2] = c.ty, i[l + 3] = 0, a[o] = 1;
2321
+ }
2322
+ const s = e.length * 4;
2323
+ n.matRow0Attr.clearUpdateRanges(), n.matRow1Attr.clearUpdateRanges(), n.visibleAttr.clearUpdateRanges(), n.matRow0Attr.addUpdateRange(0, s), n.matRow1Attr.addUpdateRange(0, s), n.visibleAttr.addUpdateRange(0, e.length), n.matRow0Attr.needsUpdate = !0, n.matRow1Attr.needsUpdate = !0, n.visibleAttr.needsUpdate = !0;
2324
+ }
2325
+ slotVisibleForRecord(n, e, r) {
2326
+ const i = n.geometryLayerIndex === 0 ? e.layerIdx : n.geometryLayerIndex;
2327
+ return r.isVisible(i);
2328
+ }
2329
+ }
2330
+ function pa(t) {
2331
+ return t.size === 0 ? "0:" : `${t.size}:${Array.from(t).sort((n, e) => n - e).join(",")}`;
2332
+ }
2333
+ function ga(t, n, e) {
2334
+ const r = t === "line" ? new pt(n, e) : t === "fill" ? new gt(n, e) : new wn(n, e);
2335
+ return r.count = 0, r;
2336
+ }
2337
+ function tn(t, n) {
2338
+ t.geometry.instanceCount = n, t.count = n;
2339
+ }
2340
+ function nn(t) {
2341
+ if (Array.isArray(t)) {
2342
+ for (const n of t) n.dispose();
2343
+ return;
2344
+ }
2345
+ t.dispose();
2346
+ }
2347
+ const Qn = 64, qn = 8;
2348
+ function ba() {
2349
+ return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2350
+ }
2351
+ async function Ca(t, n = {}) {
2352
+ const e = Math.max(1, Math.floor(n.opsPerPass ?? Qn) || 1), r = Math.max(0, n.frameBudgetMs ?? qn), i = n.now ?? ba, a = i();
2353
+ let s = a, o = 0, c = 0, l = 0, u = 0;
2354
+ for (let d = 0; d < t.length; d += 1) {
2355
+ const h = t[d];
2356
+ c += 1, h.run() && (l += 1, o += 1), n.onYield && d < t.length - 1 && (o >= e || i() - s >= r) && (await n.onYield(), u += 1, s = i(), o = 0);
2357
+ }
2358
+ return {
2359
+ visited: c,
2360
+ compacted: l,
2361
+ yielded: u,
2362
+ elapsedMs: i() - a
2363
+ };
2364
+ }
2365
+ function Ia(t, n) {
2366
+ return n.zoom, t === "full" && n.visibleVertexCount >= br ? "stress" : t === "stress" && n.visibleVertexCount <= Cr ? "full" : t;
2367
+ }
2368
+ function wa(t, n, e) {
2369
+ return t === "full" || t === "stress" ? t : Ia(n, e);
2370
+ }
2371
+ const va = 1e-6;
2372
+ function Ra(t, n) {
2373
+ let e = !0;
2374
+ for (let i = 0; i < n; i += 1) {
2375
+ const a = t[i * 3 + 2] ?? 0;
2376
+ if (Math.abs(a) > va) {
2377
+ e = !1;
2378
+ break;
2379
+ }
2380
+ }
2381
+ if (!e)
2382
+ return { kind: "xyz", xyz: t.slice(0, n * 3) };
2383
+ const r = new Float32Array(n * 2);
2384
+ for (let i = 0; i < n; i += 1)
2385
+ r[i * 2] = t[i * 3] ?? 0, r[i * 2 + 1] = t[i * 3 + 1] ?? 0;
2386
+ return { kind: "xy", xy: r };
2387
+ }
2388
+ function Ba(t, n, e = 3) {
2389
+ if (e === 2) {
2390
+ const i = n * 2;
2391
+ if (t.length === i)
2392
+ return { kind: "xy", xy: t };
2393
+ if (t.length > i)
2394
+ return { kind: "xy", xy: t.slice(0, i) };
2395
+ const a = new Float32Array(i);
2396
+ return a.set(t), { kind: "xy", xy: a };
2397
+ }
2398
+ const r = new Float32Array(n * 2);
2399
+ for (let i = 0; i < n; i += 1)
2400
+ r[i * 2] = t[i * 3] ?? 0, r[i * 2 + 1] = t[i * 3 + 1] ?? 0;
2401
+ return { kind: "xy", xy: r };
2402
+ }
2403
+ function Sa(t, n, e, r) {
2404
+ const i = r * 3;
2405
+ if (t.kind === "xyz") {
2406
+ e.set(t.xyz.subarray(0, n * 3), i);
2407
+ return;
2408
+ }
2409
+ for (let a = 0; a < n; a += 1) {
2410
+ const s = a * 2, o = i + a * 3;
2411
+ e[o] = t.xy[s] ?? 0, e[o + 1] = t.xy[s + 1] ?? 0, e[o + 2] = 0;
2412
+ }
2413
+ }
2414
+ function Ea(t, n, e, r, i) {
2415
+ if (i === 3) {
2416
+ Sa(t, n, e, r);
2417
+ return;
2418
+ }
2419
+ const a = r * 2;
2420
+ if (t.kind === "xy") {
2421
+ e.set(t.xy.subarray(0, n * 2), a);
2422
+ return;
2423
+ }
2424
+ for (let s = 0; s < n; s += 1) {
2425
+ const o = s * 3, c = a + s * 2;
2426
+ e[c] = t.xyz[o] ?? 0, e[c + 1] = t.xyz[o + 1] ?? 0;
2427
+ }
2428
+ }
2429
+ function Va(t, n, e) {
2430
+ const r = t.kind === "xy" ? e * 2 * Float32Array.BYTES_PER_ELEMENT : e * 3 * Float32Array.BYTES_PER_ELEMENT, i = Math.min(n.byteLength, e * 3);
2431
+ return {
2432
+ recordCount: 1,
2433
+ vertexCount: e,
2434
+ xyRecordCount: t.kind === "xy" ? 1 : 0,
2435
+ xyzRecordCount: t.kind === "xyz" ? 1 : 0,
2436
+ xyVertexCount: t.kind === "xy" ? e : 0,
2437
+ xyzVertexCount: t.kind === "xyz" ? e : 0,
2438
+ positionBytes: r,
2439
+ colorBytes: i,
2440
+ totalBytes: r + i
2441
+ };
2442
+ }
2443
+ function rn() {
2444
+ return {
2445
+ recordCount: 0,
2446
+ vertexCount: 0,
2447
+ xyRecordCount: 0,
2448
+ xyzRecordCount: 0,
2449
+ xyVertexCount: 0,
2450
+ xyzVertexCount: 0,
2451
+ positionBytes: 0,
2452
+ colorBytes: 0,
2453
+ totalBytes: 0
2454
+ };
2455
+ }
2456
+ function ka(t, n) {
2457
+ return {
2458
+ recordCount: t.recordCount + n.recordCount,
2459
+ vertexCount: t.vertexCount + n.vertexCount,
2460
+ xyRecordCount: t.xyRecordCount + n.xyRecordCount,
2461
+ xyzRecordCount: t.xyzRecordCount + n.xyzRecordCount,
2462
+ xyVertexCount: t.xyVertexCount + n.xyVertexCount,
2463
+ xyzVertexCount: t.xyzVertexCount + n.xyzVertexCount,
2464
+ positionBytes: t.positionBytes + n.positionBytes,
2465
+ colorBytes: t.colorBytes + n.colorBytes,
2466
+ totalBytes: t.totalBytes + n.totalBytes
2467
+ };
2468
+ }
2469
+ function Aa(t, n) {
2470
+ return {
2471
+ recordCount: X(t.recordCount, n.recordCount, "recordCount"),
2472
+ vertexCount: X(t.vertexCount, n.vertexCount, "vertexCount"),
2473
+ xyRecordCount: X(t.xyRecordCount, n.xyRecordCount, "xyRecordCount"),
2474
+ xyzRecordCount: X(t.xyzRecordCount, n.xyzRecordCount, "xyzRecordCount"),
2475
+ xyVertexCount: X(t.xyVertexCount, n.xyVertexCount, "xyVertexCount"),
2476
+ xyzVertexCount: X(t.xyzVertexCount, n.xyzVertexCount, "xyzVertexCount"),
2477
+ positionBytes: X(t.positionBytes, n.positionBytes, "positionBytes"),
2478
+ colorBytes: X(t.colorBytes, n.colorBytes, "colorBytes"),
2479
+ totalBytes: X(t.totalBytes, n.totalBytes, "totalBytes")
2480
+ };
2481
+ }
2482
+ function X(t, n, e) {
2483
+ const r = t - n;
2484
+ if (r < 0)
2485
+ throw new Error(`Line canonical memory stat ${String(e)} became negative: ${t} - ${n}`);
2486
+ return Object.is(r, -0) ? 0 : r;
2487
+ }
2488
+ const Ta = {
2489
+ visibleVertexCount: 0,
2490
+ zoom: 1
2491
+ }, Pa = /* @__PURE__ */ new Set(), La = Object.freeze({ kind: "structure" }), ys = Object.freeze({ kind: "visual" });
2492
+ function an(t) {
2493
+ return Number.isFinite(t.minX) && Number.isFinite(t.minY) && Number.isFinite(t.maxX) && Number.isFinite(t.maxY);
2494
+ }
2495
+ function Wn(t, n, e) {
2496
+ return `${t}:${n}:${e}`;
2497
+ }
2498
+ function Ma(t) {
2499
+ return t.recordKey ?? Wn(t.instanceId, t.variantId, 0);
2500
+ }
2501
+ const nt = "geo-node:promoted-instanced-v1", sn = "geo-node:text-batch-static-bounds-v1", Pe = "geo-node:text-batch-bounds-dirty-v1", on = 1.5, Da = 1, ln = "geo-node:world-sized-points-v1", $n = "geo-node:world-sized-points-uniforms", Fa = 16777216, Oa = 25, Ga = 28, _a = 29;
2502
+ function za() {
2503
+ return {
2504
+ activeThinCount: 0,
2505
+ activeFatCount: 0,
2506
+ cachedThinCount: 0,
2507
+ cachedFatCount: 0
2508
+ };
2509
+ }
2510
+ function be(t) {
2511
+ return [t[0], t[1], t[2], t[3]];
2512
+ }
2513
+ function Ua(t, n) {
2514
+ return [Math.min(t[0], n[0]), Math.min(t[1], n[1]), Math.max(t[2], n[2]), Math.max(t[3], n[3])];
2515
+ }
2516
+ function P(t) {
2517
+ return [t[0], t[1], t[2]];
2518
+ }
2519
+ function Na(t, n) {
2520
+ return t[0] === n[0] && t[1] === n[1] && t[2] === n[2];
2521
+ }
2522
+ function cn(t, n, e) {
2523
+ for (const r of n)
2524
+ r.vertexCount <= 0 || t.push({
2525
+ startVertex: r.startVertex + e,
2526
+ vertexCount: r.vertexCount,
2527
+ color: P(r.color)
2528
+ });
2529
+ }
2530
+ function ft(t) {
2531
+ const n = [];
2532
+ for (const e of t) {
2533
+ if (e.vertexCount <= 0) continue;
2534
+ const r = {
2535
+ startVertex: e.startVertex,
2536
+ vertexCount: e.vertexCount,
2537
+ color: P(e.color)
2538
+ }, i = n[n.length - 1];
2539
+ if (i && i.startVertex + i.vertexCount === r.startVertex && Na(i.color, r.color)) {
2540
+ n[n.length - 1] = {
2541
+ ...i,
2542
+ vertexCount: i.vertexCount + r.vertexCount
2543
+ };
2544
+ continue;
2545
+ }
2546
+ n.push(r);
2547
+ }
2548
+ return n;
2549
+ }
2550
+ function un(t, n) {
2551
+ if (!t || t.length === 0 || !ze(n, t))
2552
+ return;
2553
+ const e = ft(t);
2554
+ return e.length <= Math.ceil(n / 2) ? e : void 0;
2555
+ }
2556
+ function Ha(t, n) {
2557
+ if (!n || n.size === 0) return t;
2558
+ const e = /* @__PURE__ */ new Map();
2559
+ for (const [r, i] of t)
2560
+ e.set(r, [...i]);
2561
+ for (const [r, i] of n)
2562
+ e.set(r, Ka(e.get(r) ?? [], i));
2563
+ return e;
2564
+ }
2565
+ function Ka(t, n) {
2566
+ const e = /* @__PURE__ */ new Map();
2567
+ for (const r of t)
2568
+ e.set(r.variantId, {
2569
+ ...r,
2570
+ bboxes: [...r.bboxes],
2571
+ inserts: [...r.inserts]
2572
+ });
2573
+ for (const r of n) {
2574
+ const i = e.get(r.variantId);
2575
+ if (!i) {
2576
+ e.set(r.variantId, {
2577
+ ...r,
2578
+ bboxes: [...r.bboxes],
2579
+ inserts: [...r.inserts]
2580
+ });
2581
+ continue;
2582
+ }
2583
+ const a = new Map(i.inserts.map((o) => [o.instanceId, o]));
2584
+ for (const o of r.inserts)
2585
+ a.set(o.instanceId, o);
2586
+ const s = Array.from(a.values()).sort((o, c) => o.instanceId - c.instanceId);
2587
+ e.set(r.variantId, {
2588
+ ...i,
2589
+ blockName: r.blockName || i.blockName,
2590
+ instanceCount: s.length || Math.max(i.instanceCount, r.instanceCount),
2591
+ bboxes: s.map((o) => o.bbox).filter((o) => !!o),
2592
+ inserts: s
2593
+ });
2594
+ }
2595
+ return Array.from(e.values()).sort((r, i) => i.instanceCount - r.instanceCount);
2596
+ }
2597
+ function Ya(t) {
2598
+ return t.line.count > 0 || t.fill.count > 0 || t.dot.count > 0 || t.line.raw.byteLength > 0 || t.fill.raw.byteLength > 0 || t.dot.raw.byteLength > 0;
2599
+ }
2600
+ function dn(t, n) {
2601
+ if (n === 0) return t;
2602
+ const e = /* @__PURE__ */ new Map();
2603
+ for (const [r, i] of t)
2604
+ e.set(
2605
+ r,
2606
+ i.map((a) => a + n)
2607
+ );
2608
+ return e;
2609
+ }
2610
+ function Xa(t, n, e) {
2611
+ if (!n) return t;
2612
+ if (!t)
2613
+ return {
2614
+ ...n,
2615
+ textIndexesByInstanceId: dn(n.textIndexesByInstanceId, e),
2616
+ ownerInstanceIdByVariantOrdinal: n.ownerInstanceIdByVariantOrdinal ? new Map(n.ownerInstanceIdByVariantOrdinal) : void 0
2617
+ };
2618
+ const r = t.variants.slice();
2619
+ for (const a of n.variants)
2620
+ (!r[a.id] || Ya(a)) && (r[a.id] = a);
2621
+ const i = /* @__PURE__ */ new Map();
2622
+ for (const [a, s] of t.textIndexesByInstanceId)
2623
+ i.set(a, [...s]);
2624
+ for (const [a, s] of dn(n.textIndexesByInstanceId, e))
2625
+ i.set(a, [...i.get(a) ?? [], ...s]);
2626
+ return {
2627
+ layer0Index: t.layer0Index,
2628
+ variants: r,
2629
+ instances: [...t.instances, ...n.instances],
2630
+ textIndexesByInstanceId: i,
2631
+ ownerInstanceIdByVariantOrdinal: new Map([
2632
+ ...t.ownerInstanceIdByVariantOrdinal ?? /* @__PURE__ */ new Map(),
2633
+ ...n.ownerInstanceIdByVariantOrdinal ?? /* @__PURE__ */ new Map()
2634
+ ])
2635
+ };
2636
+ }
2637
+ function Qa(t) {
2638
+ return {
2639
+ index: t.index,
2640
+ name: t.name,
2641
+ color: P(t.color),
2642
+ lw_px: t.lw_px,
2643
+ visible: t.visible
2644
+ };
2645
+ }
2646
+ function qa(t) {
2647
+ const n = t >>> 0;
2648
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
2649
+ }
2650
+ function Wa(t) {
2651
+ return t[0] << 16 | t[1] << 8 | t[2];
2652
+ }
2653
+ function rt(t) {
2654
+ if (!Number.isFinite(t)) return 0;
2655
+ const n = Math.round(t);
2656
+ return n < 0 ? 0 : n > 255 ? 255 : n;
2657
+ }
2658
+ function $a(t) {
2659
+ switch (t) {
2660
+ case "fill":
2661
+ return 1;
2662
+ case "dot":
2663
+ return 2;
2664
+ case "text":
2665
+ return 3;
2666
+ case "hatch":
2667
+ return 4;
2668
+ case "overlay":
2669
+ return 5;
2670
+ case "line":
2671
+ default:
2672
+ return 0;
2673
+ }
2674
+ }
2675
+ function ja(t, n, e, r, i) {
2676
+ return (n !== null && kt(t) ? Fa : rt(t[0]) << 16 | rt(t[1]) << 8 | rt(t[2])) | $a(e) << Oa | (r === "light" ? 1 : 0) << Ga | (i ? 1 : 0) << _a;
2677
+ }
2678
+ function it(t) {
2679
+ return "color" in t && t.color instanceof pn;
2680
+ }
2681
+ function at(t) {
2682
+ const n = /* @__PURE__ */ new Set();
2683
+ t.traverse((e) => {
2684
+ var a;
2685
+ const r = e.geometry;
2686
+ r == null || r.dispose();
2687
+ const i = e.material;
2688
+ if (Array.isArray(i)) {
2689
+ for (const s of i)
2690
+ n.has(s) || (n.add(s), s.dispose());
2691
+ return;
2692
+ }
2693
+ i && !n.has(i) && (n.add(i), i.dispose()), e !== t && ((a = e.dispose) == null || a.call(e));
2694
+ });
2695
+ }
2696
+ function Za(t) {
2697
+ var i;
2698
+ const n = t.userData;
2699
+ if (n[nt] === !0)
2700
+ return;
2701
+ const e = t.onBeforeCompile;
2702
+ t.onBeforeCompile = (a, s) => {
2703
+ e == null || e(a, s), a.vertexShader.includes("attribute vec4 promotedInstMatRow0;") || (a.vertexShader = a.vertexShader.replace(
2704
+ "#include <common>",
2705
+ [
2706
+ "#include <common>",
2707
+ "attribute vec4 promotedInstMatRow0;",
2708
+ "attribute vec4 promotedInstMatRow1;",
2709
+ "attribute float promotedInstVisible;"
2710
+ ].join(`
2711
+ `)
2712
+ ).replace(
2713
+ "#include <begin_vertex>",
2714
+ [
2715
+ "vec3 transformed = vec3(position);",
2716
+ "transformed = vec3(",
2717
+ " promotedInstMatRow0.x * transformed.x + promotedInstMatRow0.y * transformed.y + promotedInstMatRow0.z,",
2718
+ " promotedInstMatRow1.x * transformed.x + promotedInstMatRow1.y * transformed.y + promotedInstMatRow1.z,",
2719
+ " transformed.z",
2720
+ ");"
2721
+ ].join(`
2722
+ `)
2723
+ ).replace(
2724
+ "#include <project_vertex>",
2725
+ [
2726
+ "#include <project_vertex>",
2727
+ "if (promotedInstVisible < 0.5) {",
2728
+ " gl_Position = vec4(2.0, 2.0, 2.0, 1.0);",
2729
+ "}"
2730
+ ].join(`
2731
+ `)
2732
+ ));
2733
+ };
2734
+ const r = (i = t.customProgramCacheKey) == null ? void 0 : i.bind(t);
2735
+ t.customProgramCacheKey = () => `${r ? r() : ""}|${nt}`, n[nt] = !0, t.needsUpdate = !0;
2736
+ }
2737
+ function Ja(t) {
2738
+ const n = t.userData[$n];
2739
+ return n && typeof n == "object" ? n : null;
2740
+ }
2741
+ function es(t, n) {
2742
+ var o;
2743
+ const e = t.userData, r = Ja(t);
2744
+ if (r)
2745
+ return r.uGeoPointWorldSize.value = n.pointWorldSize, r.uGeoPointViewportHeight.value = Math.max(1, Math.floor(n.viewportHeight) || 1), r.uGeoPointMinVisiblePixelSize.value = on, r;
2746
+ const i = {
2747
+ uGeoPointWorldSize: { value: n.pointWorldSize },
2748
+ uGeoPointViewportHeight: { value: Math.max(1, Math.floor(n.viewportHeight) || 1) },
2749
+ uGeoPointMinVisiblePixelSize: { value: on }
2750
+ };
2751
+ e[$n] = i;
2752
+ const a = t.onBeforeCompile;
2753
+ t.onBeforeCompile = (c, l) => {
2754
+ a == null || a(c, l), c.uniforms.uGeoPointWorldSize = i.uGeoPointWorldSize, c.uniforms.uGeoPointViewportHeight = i.uGeoPointViewportHeight, c.uniforms.uGeoPointMinVisiblePixelSize = i.uGeoPointMinVisiblePixelSize, c.vertexShader.includes("uGeoPointWorldSize") || (c.vertexShader = c.vertexShader.replace(
2755
+ "#include <common>",
2756
+ [
2757
+ "#include <common>",
2758
+ "uniform float uGeoPointWorldSize;",
2759
+ "uniform float uGeoPointViewportHeight;",
2760
+ "uniform float uGeoPointMinVisiblePixelSize;"
2761
+ ].join(`
2762
+ `)
2763
+ ).replace(
2764
+ "gl_PointSize = size;",
2765
+ [
2766
+ "float geoPointSize = abs(uGeoPointWorldSize * projectionMatrix[ 1 ][ 1 ] * 0.5 * uGeoPointViewportHeight);",
2767
+ "bool geoPointUsesPerspectiveDepth = isPerspectiveMatrix( projectionMatrix );",
2768
+ "if (geoPointUsesPerspectiveDepth) {",
2769
+ " geoPointSize /= max(1e-6, -mvPosition.z);",
2770
+ "}",
2771
+ "if (geoPointSize < uGeoPointMinVisiblePixelSize) {",
2772
+ " gl_Position = vec4(2.0, 2.0, 2.0, 1.0);",
2773
+ "}",
2774
+ "gl_PointSize = geoPointSize;"
2775
+ ].join(`
2776
+ `)
2777
+ ));
2778
+ };
2779
+ const s = (o = t.customProgramCacheKey) == null ? void 0 : o.bind(t);
2780
+ return t.customProgramCacheKey = () => `${s ? s() : ""}|${ln}`, e[ln] = !0, t.needsUpdate = !0, i;
2781
+ }
2782
+ const Ue = /* @__PURE__ */ new WeakMap();
2783
+ function hn(t, n) {
2784
+ n ? Ue.set(t, n) : Ue.delete(t);
2785
+ }
2786
+ class Ie extends j {
2787
+ constructor(e = {}) {
2788
+ super();
2789
+ m(this, "meta", {
2790
+ bounds: [0, 0, 0, 0],
2791
+ entityCount: 0,
2792
+ lineCount: 0,
2793
+ fillCount: 0,
2794
+ dotCount: 0,
2795
+ textCount: 0
2796
+ });
2797
+ m(this, "layerOrder", []);
2798
+ m(this, "layerStatesByIndex", /* @__PURE__ */ new Map());
2799
+ m(this, "bounds", [0, 0, 0, 0]);
2800
+ m(this, "originalLayerColorsByIndex", /* @__PURE__ */ new Map());
2801
+ m(this, "colorOverridesByIndex", /* @__PURE__ */ new Map());
2802
+ m(this, "displayThemeName", ea);
2803
+ m(this, "displayContrastEnhancement", !0);
2804
+ m(this, "displayHexMemo", /* @__PURE__ */ new Map());
2805
+ m(this, "layerStateRevision", 0);
2806
+ m(this, "metaRevision", 0);
2807
+ m(this, "renderDebugRevision", 0);
2808
+ m(this, "layersSnapshotCache", null);
2809
+ m(this, "metaSnapshotCache", null);
2810
+ m(this, "boundsSnapshotCache", null);
2811
+ m(this, "layerGroupsByIndex", /* @__PURE__ */ new Map());
2812
+ m(this, "textUserDataByAppendOrder", []);
2813
+ m(this, "textBatchByLayerIndex", /* @__PURE__ */ new Map());
2814
+ m(this, "textRenderablesByLayerIndex", /* @__PURE__ */ new Map());
2815
+ m(this, "textRenderablesByAppendOrder", []);
2816
+ m(this, "annotationOverlayGroupsByLayerIndex", /* @__PURE__ */ new Map());
2817
+ m(this, "annotationTextBatchByLayerIndex", /* @__PURE__ */ new Map());
2818
+ m(this, "annotationTextRenderablesByLayerIndex", /* @__PURE__ */ new Map());
2819
+ m(this, "annotationTextRecordsByOwnerKey", /* @__PURE__ */ new Map());
2820
+ m(this, "annotationTextRecordsByLayerIndex", /* @__PURE__ */ new Map());
2821
+ m(this, "pendingTextBatchSync", /* @__PURE__ */ new Set());
2822
+ m(this, "textBatchSyncScheduled", !1);
2823
+ m(this, "insertRuntime", null);
2824
+ m(this, "insertRuntimeInstancesById", /* @__PURE__ */ new Map());
2825
+ m(this, "blockGeometryRegistry", null);
2826
+ m(this, "insertPresenterVariantInputs", /* @__PURE__ */ new Map());
2827
+ m(this, "insertPresenterRecordsByKey", /* @__PURE__ */ new Map());
2828
+ m(this, "insertPresenterRecordKeysByInstanceId", /* @__PURE__ */ new Map());
2829
+ m(this, "insertInstanceTable", null);
2830
+ m(this, "viewportInstancePresenter", null);
2831
+ m(this, "insertPresenterExternallyManaged", !1);
2832
+ m(this, "renderQualityMode", "auto");
2833
+ m(this, "effectiveRenderQuality", "full");
2834
+ m(this, "interactionRenderQualityOverride", null);
2835
+ m(this, "lineModeSwitchingEnabled", !1);
2836
+ m(this, "autoQualityContext", { ...Ta });
2837
+ m(this, "lineChunkRecords", []);
2838
+ m(this, "lineCanonicalMemoryStats", rn());
2839
+ m(this, "nonLineChunkStats", []);
2840
+ m(this, "worldSizedPointUniforms", /* @__PURE__ */ new Set());
2841
+ m(this, "lineResolution", { width: 1, height: 1 });
2842
+ m(this, "internalChangeHook", null);
2843
+ m(this, "disposed", !1);
2844
+ m(this, "readySettled", !1);
2845
+ m(this, "layerBlockUsages", /* @__PURE__ */ new Map());
2846
+ m(this, "colorRefreshStats", {
2847
+ displayRefreshVertexTotal: 0,
2848
+ displayRefreshRunTotal: 0,
2849
+ displayRefreshUniqueColorTotal: 0,
2850
+ displayRefreshCacheHitTotal: 0,
2851
+ displayRefreshRepeatedRunVertexTotal: 0
2852
+ });
2853
+ m(this, "contentGeneration", 0);
2854
+ m(this, "annotationOverlayVisible", !0);
2855
+ m(this, "readyPromise");
2856
+ m(this, "resolveReady");
2857
+ m(this, "rejectReady");
2858
+ m(this, "resolveTextFont");
2859
+ this.name = "GeoNode", this.resolveTextFont = e.resolveTextFont ?? Di, this.startReadyCycle();
2860
+ }
2861
+ get ready() {
2862
+ return this.readyPromise;
2863
+ }
2864
+ setLayerVisible(e, r) {
2865
+ var o;
2866
+ const i = this.layerStatesByIndex.get(e), a = this.layerGroupsByIndex.get(e);
2867
+ if (!i) return;
2868
+ const s = i.visible !== r;
2869
+ s && (this.layerStateRevision += 1, (o = this.viewportInstancePresenter) == null || o.invalidateQueryCache()), i.visible = r, a && (a.visible = r), this.refreshAnnotationTextVisibilityForLayer(e), s && this.refreshDefaultInsertPresenterIfUnmanaged();
2870
+ }
2871
+ setAnnotationOverlayVisible(e) {
2872
+ if (this.annotationOverlayVisible !== e) {
2873
+ this.annotationOverlayVisible = e;
2874
+ for (const r of this.annotationOverlayGroupsByLayerIndex.values())
2875
+ this.applyAnnotationOverlayVisibility(r);
2876
+ this.notifyInternalChange();
2877
+ }
2878
+ }
2879
+ setDisplayTheme(e, r = {}) {
2880
+ const i = r.enhanceContrast ?? this.displayContrastEnhancement, a = this.displayThemeName === e && this.displayContrastEnhancement === i;
2881
+ this.displayThemeName = e, this.displayContrastEnhancement = i, !a && (this.displayHexMemo.clear(), this.refreshDisplayColors(), this.notifyInternalChange());
2882
+ }
2883
+ setLayerColor(e, r) {
2884
+ const i = this.layerStatesByIndex.get(e), a = this.layerGroupsByIndex.get(e), s = this.originalLayerColorsByIndex.get(e);
2885
+ if (!i || !a || !s) return;
2886
+ const o = r === null ? null : qa(r);
2887
+ o ? this.colorOverridesByIndex.set(e, P(o)) : this.colorOverridesByIndex.delete(e), this.displayHexMemo.clear(), i.color = P(o ?? s), this.layerStateRevision += 1, a.traverse((c) => {
2888
+ var h;
2889
+ const l = (h = c.userData) == null ? void 0 : h.kind;
2890
+ if (l === "text" || l === "text-batch") return;
2891
+ const u = c.material, d = Array.isArray(u) ? u : u ? [u] : [];
2892
+ for (const f of d)
2893
+ it(f) && (this.applyLayerColorState(f, o, this.displayElementKindForObject(c)), f.needsUpdate = !0);
2894
+ }), this.applyCachedLineChunkColors(e, o), this.applyLayerTextColors(e, o);
2895
+ }
2896
+ setRenderQuality(e) {
2897
+ this.renderQualityMode = e, this.applyEffectiveRenderQuality(this.resolveCurrentEffectiveRenderQuality());
2898
+ }
2899
+ setLineModeSwitchingEnabled(e) {
2900
+ this.lineModeSwitchingEnabled !== e && (this.lineModeSwitchingEnabled = e, this.applyEffectiveRenderQuality(this.resolveCurrentEffectiveRenderQuality(), { forceLineRebuild: !0 }));
2901
+ }
2902
+ updateAutoQualityContext(e) {
2903
+ this.autoQualityContext = { ...e }, this.lineModeSwitchingEnabled && (this.renderQualityMode !== "auto" && !this.interactionRenderQualityOverride || this.applyEffectiveRenderQuality(this.resolveCurrentEffectiveRenderQuality()));
2904
+ }
2905
+ setInteractionRenderQualityOverride(e) {
2906
+ this.interactionRenderQualityOverride !== e && (this.interactionRenderQualityOverride = e, this.applyEffectiveRenderQuality(this.resolveCurrentEffectiveRenderQuality()));
2907
+ }
2908
+ getMeta() {
2909
+ var r;
2910
+ if (((r = this.metaSnapshotCache) == null ? void 0 : r.revision) === this.metaRevision)
2911
+ return this.metaSnapshotCache.value;
2912
+ const e = Object.freeze({
2913
+ bounds: be(this.meta.bounds),
2914
+ entityCount: this.meta.entityCount,
2915
+ lineCount: this.meta.lineCount,
2916
+ fillCount: this.meta.fillCount,
2917
+ dotCount: this.meta.dotCount,
2918
+ textCount: this.meta.textCount
2919
+ });
2920
+ return this.metaSnapshotCache = { revision: this.metaRevision, value: e }, e;
2921
+ }
2922
+ getLayers() {
2923
+ var r;
2924
+ if (((r = this.layersSnapshotCache) == null ? void 0 : r.revision) === this.layerStateRevision)
2925
+ return this.layersSnapshotCache.value;
2926
+ const e = Object.freeze(
2927
+ this.layerOrder.map((i) => this.layerStatesByIndex.get(i)).filter((i) => i !== void 0).map((i) => Object.freeze(Qa(i)))
2928
+ );
2929
+ return this.layersSnapshotCache = { revision: this.layerStateRevision, value: e }, e;
2930
+ }
2931
+ getLayerVisibility() {
2932
+ const e = this.layerStateRevision, r = /* @__PURE__ */ new Map();
2933
+ for (const [i, a] of this.layerStatesByIndex)
2934
+ r.set(i, a.visible);
2935
+ return {
2936
+ version: e,
2937
+ isVisible: (i) => r.get(i) ?? !0
2938
+ };
2939
+ }
2940
+ refreshInsertPresenter(e, r, i, a = 0) {
2941
+ var s;
2942
+ this.insertPresenterExternallyManaged = !0, (s = this.viewportInstancePresenter) == null || s.refresh(e, r, i, a);
2943
+ }
2944
+ getInsertPresenterVisibleVertexCount() {
2945
+ var e;
2946
+ return ((e = this.viewportInstancePresenter) == null ? void 0 : e.currentVisibleVertexCount()) ?? 0;
2947
+ }
2948
+ invalidateInsertPresenterQueryCache() {
2949
+ var e;
2950
+ (e = this.viewportInstancePresenter) == null || e.invalidateQueryCache();
2951
+ }
2952
+ getLayerBlockUsages(e) {
2953
+ return this.layerBlockUsages.get(e) ?? [];
2954
+ }
2955
+ getBlockLayerStatsRevision() {
2956
+ return this.layerStateRevision * 1e6 + this.metaRevision;
2957
+ }
2958
+ getRenderDebugRevision() {
2959
+ return this.renderDebugRevision;
2960
+ }
2961
+ getBounds() {
2962
+ var r;
2963
+ if (((r = this.boundsSnapshotCache) == null ? void 0 : r.revision) === this.metaRevision)
2964
+ return this.boundsSnapshotCache.value;
2965
+ const e = Object.freeze(be(this.bounds));
2966
+ return this.boundsSnapshotCache = { revision: this.metaRevision, value: e }, e;
2967
+ }
2968
+ getGeometryChunkStats() {
2969
+ const e = this.lineChunkRecords.map((i) => ({
2970
+ layerIndex: i.layerIndex,
2971
+ vertexCount: i.vertexCount,
2972
+ bbox: _e(i.bbox)
2973
+ })), r = this.nonLineChunkStats.map((i) => ({
2974
+ layerIndex: i.layerIndex,
2975
+ vertexCount: i.vertexCount,
2976
+ bbox: _e(i.bbox)
2977
+ }));
2978
+ return [...e, ...r];
2979
+ }
2980
+ _collectTextUserDataForDebug() {
2981
+ return this.textUserDataByAppendOrder.map((e) => ({ ...e, c: P(e.c) }));
2982
+ }
2983
+ getTextEntries() {
2984
+ return this.textUserDataByAppendOrder;
2985
+ }
2986
+ getInsertInstanceBaseTransform(e, r) {
2987
+ const i = this.resolveInsertRuntimeInstance(e, r);
2988
+ if (!i) return null;
2989
+ const a = Math.hypot(i.matA, i.matB), s = Math.hypot(i.matC, i.matD), o = Math.atan2(i.matB, i.matA);
2990
+ return {
2991
+ tx: i.tx,
2992
+ ty: i.ty,
2993
+ rotation: o * 180 / Math.PI,
2994
+ scaleX: a,
2995
+ scaleY: s
2996
+ };
2997
+ }
2998
+ getInsertVariantGeometry(e) {
2999
+ var r;
3000
+ return ((r = this.blockGeometryRegistry) == null ? void 0 : r.getVariant(e)) ?? null;
3001
+ }
3002
+ getInsertInstanceMatrix(e, r) {
3003
+ const i = this.resolveInsertRuntimeInstance(e, r);
3004
+ return i ? {
3005
+ matA: i.matA,
3006
+ matB: i.matB,
3007
+ matC: i.matC,
3008
+ matD: i.matD,
3009
+ tx: i.tx,
3010
+ ty: i.ty
3011
+ } : null;
3012
+ }
3013
+ getInsertPreviewRecordsForInstance(e) {
3014
+ const r = this.insertPresenterRecordKeysByInstanceId.get(e);
3015
+ if (!r || r.size === 0) return [];
3016
+ const i = [];
3017
+ for (const a of r) {
3018
+ const s = this.insertPresenterRecordsByKey.get(a);
3019
+ s && i.push(s);
3020
+ }
3021
+ return i;
3022
+ }
3023
+ getEffectiveLayerColorHex(e) {
3024
+ const r = this.colorOverridesByIndex.get(e);
3025
+ return r ? this.resolveDisplayHexForRgb(r, null, "line") : null;
3026
+ }
3027
+ resolveInsertRuntimeInstance(e, r) {
3028
+ var i;
3029
+ return r === void 0 ? this.insertRuntimeInstancesById.get(e) ?? null : ((i = this.insertRuntime) == null ? void 0 : i.instances.find(
3030
+ (a) => a.instanceId === e && a.variantId === r
3031
+ )) ?? null;
3032
+ }
3033
+ updateTextEntry(e, r) {
3034
+ if (e < 0 || e >= this.textRenderablesByAppendOrder.length) return !1;
3035
+ const i = this.textRenderablesByAppendOrder[e], a = this.textUserDataByAppendOrder[e];
3036
+ if (!i || !a) return !1;
3037
+ let s = !1;
3038
+ return r.content !== void 0 && (i.text = r.content, a.t = r.content), r.x !== void 0 && (i.position.x = r.x, a.x = r.x, s = !0), r.y !== void 0 && (i.position.y = r.y, a.y = r.y, s = !0), r.rotation !== void 0 && (i.rotation.z = r.rotation * Math.PI / 180, a.r = r.rotation, s = !0), s && (this.commitTroikaTextTransform(i), this.markTextBatchBoundsDirty(this.textBatchByLayerIndex.get(a.li)), this.markTextBatchBoundsDirty(this.annotationTextBatchByLayerIndex.get(a.li))), i.sync(), this.notifyInternalChange(), !0;
3039
+ }
3040
+ updateInsertInstanceTransform(e, r) {
3041
+ var f;
3042
+ if (!this.insertInstanceTable) return !1;
3043
+ const i = this.insertPresenterRecordKeysByInstanceId.get(e);
3044
+ if (!i || i.size === 0) return !1;
3045
+ const a = r.rotation * Math.PI / 180, s = Math.cos(a), o = Math.sin(a), c = r.scaleX * s, l = r.scaleX * o, u = -r.scaleY * o, d = r.scaleY * s;
3046
+ let h = !0;
3047
+ for (const b of i) {
3048
+ const g = this.insertPresenterRecordsByKey.get(b);
3049
+ if (!g) continue;
3050
+ const C = {
3051
+ ...g,
3052
+ matA: c,
3053
+ matB: l,
3054
+ matC: u,
3055
+ matD: d,
3056
+ tx: r.tx,
3057
+ ty: r.ty,
3058
+ bbox: this.computeInsertPresenterWorldBBox(g.variantId, {
3059
+ matA: c,
3060
+ matB: l,
3061
+ matC: u,
3062
+ matD: d,
3063
+ tx: r.tx,
3064
+ ty: r.ty
3065
+ }) ?? g.bbox
3066
+ };
3067
+ this.insertPresenterRecordsByKey.set(b, C), this.insertInstanceTable.replaceRecord(C) || (h = !1);
3068
+ }
3069
+ return h ? (f = this.viewportInstancePresenter) == null || f.invalidateQueryCache() : this.rebuildViewportInsertPresenter([...this.insertPresenterRecordsByKey.values()]), this.refreshDefaultInsertPresenterIfUnmanaged(), this.notifyInternalChange(), !0;
3070
+ }
3071
+ getEffectiveRenderQuality() {
3072
+ return this.effectiveRenderQuality;
3073
+ }
3074
+ getLineRenderMode() {
3075
+ return this.lineModeSwitchingEnabled ? this.effectiveRenderQuality : "width";
3076
+ }
3077
+ getLineModeSwitchingEnabled() {
3078
+ return this.lineModeSwitchingEnabled;
3079
+ }
3080
+ getRenderQualityModeForDebug() {
3081
+ return this.renderQualityMode;
3082
+ }
3083
+ getLineMemoryStats() {
3084
+ const e = this.rebuildLineVariantStats();
3085
+ return Object.freeze({
3086
+ canonical: Object.freeze({ ...this.lineCanonicalMemoryStats }),
3087
+ variants: Object.freeze({ ...e })
3088
+ });
3089
+ }
3090
+ getColorPipelineStats() {
3091
+ let e = 0, r = 0, i = 0, a = 0;
3092
+ return this.traverse((s) => {
3093
+ const o = s.geometry;
3094
+ if (!o) return;
3095
+ const c = o.userData.cadDisplaySourceColor, l = o.userData.cadDisplayColorRuns;
3096
+ c instanceof Uint8Array ? (e += 1, r += c.byteLength) : l && l.length > 0 && (e += 1);
3097
+ const u = o.getAttribute("color");
3098
+ u instanceof U && ArrayBuffer.isView(u.array) && (i += u.array.byteLength, u.array instanceof Float32Array && (a += u.array.byteLength));
3099
+ }), Object.freeze({
3100
+ geometryCount: e,
3101
+ sourceRgbBytes: r,
3102
+ displayRgbBytes: i,
3103
+ displayRgbFloat32Bytes: a,
3104
+ ...this.colorRefreshStats
3105
+ });
3106
+ }
3107
+ getInsertRuntime() {
3108
+ return this.insertRuntime;
3109
+ }
3110
+ getTextRenderablesByAppendOrder() {
3111
+ return [...this.textRenderablesByAppendOrder];
3112
+ }
3113
+ getSupplementalTextRenderablesByInstanceId() {
3114
+ var i;
3115
+ const e = (i = this.insertRuntime) == null ? void 0 : i.ownerInstanceIdByVariantOrdinal;
3116
+ if (!e || this.annotationTextRecordsByOwnerKey.size === 0)
3117
+ return /* @__PURE__ */ new Map();
3118
+ const r = /* @__PURE__ */ new Map();
3119
+ for (const [a, s] of this.annotationTextRecordsByOwnerKey) {
3120
+ const o = e.get(a);
3121
+ if (o === void 0) continue;
3122
+ const c = r.get(o), l = s.map((u) => this.createInsertVisibilityHandleForAnnotationText(u));
3123
+ c ? c.push(...l) : r.set(o, [...l]);
3124
+ }
3125
+ return r;
3126
+ }
3127
+ rebuildInsertRuntimeInstanceIndex() {
3128
+ var e;
3129
+ this.insertRuntimeInstancesById.clear();
3130
+ for (const r of ((e = this.insertRuntime) == null ? void 0 : e.instances) ?? [])
3131
+ this.insertRuntimeInstancesById.has(r.instanceId) || this.insertRuntimeInstancesById.set(r.instanceId, r);
3132
+ }
3133
+ dispose() {
3134
+ if (this.disposed) return;
3135
+ this.disposed = !0;
3136
+ const e = Ue.get(this);
3137
+ Ue.delete(this), e == null || e(), this.resetContent(), this.rejectReadyOnce(new A("E_DISPOSED", "GeoNode disposed before completion"));
3138
+ }
3139
+ _initFromHeader(e) {
3140
+ if (!this.disposed) {
3141
+ this.readySettled && this.startReadyCycle(), this.resetContent(), this.bounds = be(e.bounds), this.meta = {
3142
+ bounds: be(e.bounds),
3143
+ entityCount: e.entityCount,
3144
+ lineCount: e.lineCount,
3145
+ fillCount: e.fillCount,
3146
+ dotCount: e.dotCount,
3147
+ textCount: e.textCount
3148
+ }, this.metaRevision += 1, this.layerStateRevision += 1, this.layerBlockUsages = e.layerBlockUsages ?? /* @__PURE__ */ new Map(), this.insertRuntime = e.insertRuntime ?? null, this.rebuildInsertRuntimeInstanceIndex();
3149
+ for (const r of e.layers) {
3150
+ const i = r.index, a = {
3151
+ ...r,
3152
+ visible: r.visible ?? !0,
3153
+ color: P(r.color)
3154
+ };
3155
+ this.layerOrder.push(i), this.layerStatesByIndex.set(i, a), this.originalLayerColorsByIndex.set(i, P(a.color));
3156
+ const s = this.ensureLayerGroup(i, a.name, a.visible);
3157
+ s.name = a.name, s.visible = a.visible;
3158
+ }
3159
+ this.notifyInternalChange();
3160
+ }
3161
+ }
3162
+ _appendChunk(e) {
3163
+ if (!this.disposed) {
3164
+ if (e.kind === "text") {
3165
+ this._appendTextChunks([e.payload]);
3166
+ return;
3167
+ }
3168
+ this._appendPreparedGeometryChunk(
3169
+ e.kind,
3170
+ de(e.payload, {
3171
+ markLinePositionXy: e.kind === "line"
3172
+ })
3173
+ );
3174
+ }
3175
+ }
3176
+ _appendPreparedGeometryChunk(e, r) {
3177
+ if (!(this.disposed || r.length === 0)) {
3178
+ for (const i of r) {
3179
+ if (i.count <= 0) continue;
3180
+ const a = this.getOrCreateKindGroup(i.layerIndex, e), s = e === "line" ? this.createRenderableLineChunk(
3181
+ a,
3182
+ i.layerIndex,
3183
+ i.pos,
3184
+ i.col,
3185
+ i.count,
3186
+ i.bbox,
3187
+ i.linePositionKind,
3188
+ i.colorRuns,
3189
+ i.positionItemSize,
3190
+ i.lineweightPx
3191
+ ) : this.createRenderableChunk(
3192
+ e,
3193
+ i.layerIndex,
3194
+ i.pos,
3195
+ i.col,
3196
+ i.count,
3197
+ i.bbox,
3198
+ i.colorRuns
3199
+ );
3200
+ a.add(s);
3201
+ }
3202
+ this.notifyInternalChange();
3203
+ }
3204
+ }
3205
+ _appendTextChunks(e) {
3206
+ if (!(this.disposed || e.length === 0)) {
3207
+ for (const r of e)
3208
+ this.appendTextChunk(r);
3209
+ this.notifyInternalChange();
3210
+ }
3211
+ }
3212
+ _installInsertModel(e) {
3213
+ this.disposed || (this.clearViewportInsertPresenter(), this.mergeInsertModelPayload(e), this.rebuildViewportInsertPresenterFromAccumulatedModel(), this.readySettled && this.refreshDefaultInsertPresenterIfUnmanaged(), this.notifyInternalChange());
3214
+ }
3215
+ _appendInsertModel(e) {
3216
+ if (this.disposed) return;
3217
+ const r = this.mergeInsertModelPayload(e);
3218
+ if (!this.blockGeometryRegistry || !this.insertInstanceTable || !this.viewportInstancePresenter || r.replacedRecord)
3219
+ this.rebuildViewportInsertPresenterFromAccumulatedModel();
3220
+ else {
3221
+ const i = this.blockGeometryRegistry.appendVariants(r.variantInputs);
3222
+ for (const a of i)
3223
+ this.viewportInstancePresenter.appendVariant(a);
3224
+ this.insertInstanceTable.appendRecords(r.records), (i.length > 0 || r.records.length > 0 || r.replacedVariant) && this.viewportInstancePresenter.invalidateQueryCache();
3225
+ }
3226
+ this.readySettled && this.refreshDefaultInsertPresenterIfUnmanaged(), this.notifyInternalChange();
3227
+ }
3228
+ mergeInsertModelPayload(e) {
3229
+ const r = [], i = this.createInsertInstanceRecords(e.instances);
3230
+ let a = !1, s = !1;
3231
+ for (const o of e.variants) {
3232
+ const c = this.createVariantGeometryInput(o);
3233
+ this.insertPresenterVariantInputs.has(o.variantId) && (a = !0), this.insertPresenterVariantInputs.set(o.variantId, c), r.push(c);
3234
+ }
3235
+ for (const o of i) {
3236
+ const c = Ma(o);
3237
+ this.insertPresenterRecordsByKey.has(c) && (s = !0), this.insertPresenterRecordsByKey.set(c, o);
3238
+ let l = this.insertPresenterRecordKeysByInstanceId.get(o.instanceId);
3239
+ l || (l = /* @__PURE__ */ new Set(), this.insertPresenterRecordKeysByInstanceId.set(o.instanceId, l)), l.add(c);
3240
+ }
3241
+ return { variantInputs: r, records: i, replacedVariant: a, replacedRecord: s };
3242
+ }
3243
+ createVariantGeometryInput(e) {
3244
+ return {
3245
+ variantId: e.variantId,
3246
+ line: e.line.map((r) => ({
3247
+ pos: r.pos,
3248
+ col: r.col,
3249
+ count: r.count,
3250
+ layerIndex: r.layerIndex,
3251
+ ...r.lineweightPx === void 0 ? {} : { lineweightPx: r.lineweightPx },
3252
+ bbox: r.bbox
3253
+ })),
3254
+ fill: e.fill.map((r) => ({
3255
+ pos: r.pos,
3256
+ col: r.col,
3257
+ count: r.count,
3258
+ layerIndex: r.layerIndex,
3259
+ bbox: r.bbox
3260
+ })),
3261
+ dot: e.dot.map((r) => ({
3262
+ pos: r.pos,
3263
+ col: r.col,
3264
+ count: r.count,
3265
+ layerIndex: r.layerIndex,
3266
+ bbox: r.bbox
3267
+ }))
3268
+ };
3269
+ }
3270
+ rebuildViewportInsertPresenterFromAccumulatedModel() {
3271
+ var e, r;
3272
+ (e = this.viewportInstancePresenter) == null || e.dispose(), this.viewportInstancePresenter = null, this.insertInstanceTable = null, (r = this.blockGeometryRegistry) == null || r.dispose(), this.blockGeometryRegistry = fa([...this.insertPresenterVariantInputs.values()]), this.rebuildViewportInsertPresenter([...this.insertPresenterRecordsByKey.values()]);
3273
+ }
3274
+ rebuildViewportInsertPresenter(e) {
3275
+ var r;
3276
+ this.blockGeometryRegistry && (this.insertInstanceTable = ma(e), (r = this.viewportInstancePresenter) == null || r.dispose(), this.viewportInstancePresenter = new xa({
3277
+ registry: this.blockGeometryRegistry,
3278
+ table: this.insertInstanceTable,
3279
+ materialFactory: (i) => this.createInsertPresenterMaterial(i),
3280
+ initialCapacity: 1024,
3281
+ marginRatio: 0.2
3282
+ }), this.viewportInstancePresenter.attach(this));
3283
+ }
3284
+ computeInsertPresenterWorldBBox(e, r) {
3285
+ var o;
3286
+ const i = (o = this.blockGeometryRegistry) == null ? void 0 : o.getVariant(e);
3287
+ if (!i) return null;
3288
+ let a = null;
3289
+ for (const c of i.byKind.values())
3290
+ for (const l of c)
3291
+ a = Le(a, l.bbox);
3292
+ if (!a) return null;
3293
+ const s = cr(a, r);
3294
+ return an(s) ? s : null;
3295
+ }
3296
+ _debugHasInsertPresenter() {
3297
+ return this.viewportInstancePresenter !== null;
3298
+ }
3299
+ _debugInsertInstanceTableSize() {
3300
+ var e;
3301
+ return ((e = this.insertInstanceTable) == null ? void 0 : e.size()) ?? 0;
3302
+ }
3303
+ appendAnnotationOverlay(e) {
3304
+ this.disposed || (this.appendAnnotationPreparedGeometryChunk(
3305
+ "line",
3306
+ de(e.line, {
3307
+ markLinePositionXy: !0
3308
+ })
3309
+ ), this.appendAnnotationPreparedGeometryChunk("fill", de(e.fill)), this.appendAnnotationPreparedGeometryChunk("dot", de(e.dot)), this.appendAnnotationTextChunks(e.texts), this.notifyInternalChange());
3310
+ }
3311
+ appendExternalVariantDelta(e) {
3312
+ if (!this.disposed) {
3313
+ this.appendExternalVariantDeltaHeader(e.header);
3314
+ for (const r of e.chunks)
3315
+ this._appendChunk(r);
3316
+ this.notifyInternalChange();
3317
+ }
3318
+ }
3319
+ appendExternalVariantDeltaHeader(e) {
3320
+ if (this.disposed) return;
3321
+ const r = this.meta.textCount, i = Ua(this.bounds, e.bounds);
3322
+ this.bounds = i, this.meta = {
3323
+ bounds: be(i),
3324
+ entityCount: this.meta.entityCount + e.entityCount,
3325
+ lineCount: this.meta.lineCount + e.lineCount,
3326
+ fillCount: this.meta.fillCount + e.fillCount,
3327
+ dotCount: this.meta.dotCount + e.dotCount,
3328
+ textCount: this.meta.textCount + e.textCount
3329
+ }, this.metaRevision += 1, this.layerBlockUsages = Ha(this.layerBlockUsages, e.layerBlockUsages), this.insertRuntime = Xa(this.insertRuntime, e.insertRuntime, r), this.rebuildInsertRuntimeInstanceIndex(), this.updateAutoQualityContext({
3330
+ visibleVertexCount: this.meta.lineCount + this.meta.fillCount + this.meta.dotCount,
3331
+ zoom: this.autoQualityContext.zoom
3332
+ }), this.notifyInternalChange();
3333
+ }
3334
+ _finalize() {
3335
+ if (this.disposed) {
3336
+ this.rejectReadyOnce(new A("E_DISPOSED", "GeoNode disposed before completion"));
3337
+ return;
3338
+ }
3339
+ this.compactGeometryByLayer(), this.refreshDefaultInsertPresenterIfUnmanaged(), this.resolveReadyOnce();
3340
+ }
3341
+ async _finalizeIncrementally(e, r = Qn, i = {}) {
3342
+ if (this.disposed) {
3343
+ this.rejectReadyOnce(new A("E_DISPOSED", "GeoNode disposed before completion"));
3344
+ return;
3345
+ }
3346
+ const a = this.contentGeneration;
3347
+ await this.compactGeometryByLayerIncrementally(r, e), !(this.disposed || a !== this.contentGeneration) && (this.refreshDefaultInsertPresenterIfUnmanaged(), this.resolveReadyOnce());
3348
+ }
3349
+ _fail(e) {
3350
+ if (this.disposed) {
3351
+ this.rejectReadyOnce(new A("E_DISPOSED", "GeoNode disposed before completion"));
3352
+ return;
3353
+ }
3354
+ this.rejectReadyOnce(e);
3355
+ }
3356
+ _setInternalChangeHook(e) {
3357
+ this.internalChangeHook = e;
3358
+ }
3359
+ _setViewportSize(e, r) {
3360
+ var i;
3361
+ this.lineResolution = {
3362
+ width: Math.max(1, Math.floor(e) || 1),
3363
+ height: Math.max(1, Math.floor(r) || 1)
3364
+ };
3365
+ for (const a of this.lineChunkRecords)
3366
+ (i = a.fatMaterial) == null || i.updateResolution(this.lineResolution.width, this.lineResolution.height);
3367
+ for (const a of this.worldSizedPointUniforms)
3368
+ a.uGeoPointViewportHeight.value = this.lineResolution.height;
3369
+ }
3370
+ createPointMaterial(e, r, i) {
3371
+ var u;
3372
+ const a = ((u = this.layerStatesByIndex.get(e)) == null ? void 0 : u.lw_px) ?? 1, s = this.resolvePointWorldSize(Math.max(a * 1.5, 3)), o = new Dt({
3373
+ vertexColors: !0,
3374
+ size: 1,
3375
+ sizeAttenuation: !1,
3376
+ depthTest: !1,
3377
+ depthWrite: !1
3378
+ }), c = es(o, {
3379
+ pointWorldSize: s,
3380
+ viewportHeight: this.lineResolution.height
3381
+ });
3382
+ this.worldSizedPointUniforms.add(c);
3383
+ const l = o.dispose.bind(o);
3384
+ return o.dispose = () => {
3385
+ this.worldSizedPointUniforms.delete(c), l();
3386
+ }, this.applyLayerColorState(o, r, i), o;
3387
+ }
3388
+ resolvePointWorldSize(e) {
3389
+ return !Number.isFinite(e) || e <= 0 ? 1 : e * Da;
3390
+ }
3391
+ appendTextChunk(e) {
3392
+ const r = this.getOrCreateTextBatch(e.li), i = this.createRenderableTextChunk(e);
3393
+ this.applyColorToTextRenderable(i, this.colorOverridesByIndex.get(e.li) ?? null), r.add(i), this.markTextBatchBoundsDirty(r);
3394
+ const a = this.textRenderablesByLayerIndex.get(e.li) ?? [];
3395
+ a.push(i), this.textRenderablesByLayerIndex.set(e.li, a), this.textRenderablesByAppendOrder.push(i);
3396
+ const s = Number(r.userData.textCount || 0);
3397
+ r.userData.textCount = s + 1, this.textUserDataByAppendOrder.push({ ...i.userData.text, c: P(i.userData.text.c) }), typeof globalThis.self < "u" && this.scheduleTextBatchSync(r);
3398
+ }
3399
+ appendAnnotationTextChunks(e) {
3400
+ if (!(this.disposed || e.length === 0))
3401
+ for (const r of e)
3402
+ this.appendAnnotationTextChunk(r);
3403
+ }
3404
+ appendAnnotationTextChunk(e) {
3405
+ const r = this.getOrCreateAnnotationTextBatch(e.li), i = this.createRenderableTextChunk(e);
3406
+ i.userData.annotationOverlay = !0, i.visible = this.annotationOverlayVisible, this.applyColorToTextRenderable(i, this.colorOverridesByIndex.get(e.li) ?? null), r.add(i), this.markTextBatchBoundsDirty(r);
3407
+ const a = this.annotationTextRenderablesByLayerIndex.get(e.li) ?? [];
3408
+ a.push(i), this.annotationTextRenderablesByLayerIndex.set(e.li, a);
3409
+ const s = Ie.getTextOwnerKey(e), o = {
3410
+ renderable: i,
3411
+ layerIndex: e.li,
3412
+ ownerKey: s,
3413
+ insertVisible: !0
3414
+ }, c = this.annotationTextRecordsByLayerIndex.get(e.li) ?? [];
3415
+ if (c.push(o), this.annotationTextRecordsByLayerIndex.set(e.li, c), s) {
3416
+ const u = this.annotationTextRecordsByOwnerKey.get(s) ?? [];
3417
+ u.push(o), this.annotationTextRecordsByOwnerKey.set(s, u);
3418
+ }
3419
+ this.applyAnnotationTextRenderableVisibility(o);
3420
+ const l = Number(r.userData.textCount || 0);
3421
+ r.userData.textCount = l + 1, this.textUserDataByAppendOrder.push({ ...i.userData.text, c: P(i.userData.text.c) }), typeof globalThis.self < "u" && this.scheduleTextBatchSync(r);
3422
+ }
3423
+ getOrCreateTextBatch(e) {
3424
+ const r = this.textBatchByLayerIndex.get(e);
3425
+ if (r) return r;
3426
+ const i = Gt, a = new i();
3427
+ return this.configureTextBatchForStaticBounds(a), a.name = "text-batch", a.renderOrder = 3, a.depthOffset = -0.1, a.userData.kind = "text-batch", a.userData.layerIndex = e, a.userData.textCount = 0, typeof globalThis.self < "u" && a.addEventListener("synccomplete", () => {
3428
+ this.markTextBatchBoundsClean(a), this.notifyInternalChange();
3429
+ }), this.getOrCreateKindGroup(e, "text").add(a), this.textBatchByLayerIndex.set(e, a), a;
3430
+ }
3431
+ getOrCreateAnnotationTextBatch(e) {
3432
+ const r = this.annotationTextBatchByLayerIndex.get(e);
3433
+ if (r) return r;
3434
+ const i = Gt, a = new i();
3435
+ return this.configureTextBatchForStaticBounds(a), a.name = "annotation-text-batch", a.renderOrder = 4, a.depthOffset = -0.2, a.visible = this.annotationOverlayVisible && this.isLayerVisible(e), a.userData.kind = "text-batch", a.userData.layerIndex = e, a.userData.textCount = 0, a.userData.annotationOverlay = !0, typeof globalThis.self < "u" && a.addEventListener("synccomplete", () => {
3436
+ this.markTextBatchBoundsClean(a), this.notifyInternalChange();
3437
+ }), this.getOrCreateAnnotationKindGroup(e, "text").add(a), this.annotationTextBatchByLayerIndex.set(e, a), a;
3438
+ }
3439
+ configureTextBatchForStaticBounds(e) {
3440
+ const r = e.userData;
3441
+ r[sn] !== !0 && (e.matrixAutoUpdate = !1, e.updateMatrix(), e.updateMatrixWorld = function(a) {
3442
+ var s;
3443
+ In.prototype.updateMatrixWorld.call(this, a), this.userData[Pe] === !0 && ((s = this.updateBounds) == null || s.call(this), this.userData[Pe] = !1);
3444
+ }, r[sn] = !0, this.markTextBatchBoundsClean(e));
3445
+ }
3446
+ markTextBatchBoundsDirty(e) {
3447
+ e && (e.userData[Pe] = !0);
3448
+ }
3449
+ markTextBatchBoundsClean(e) {
3450
+ e && (e.userData[Pe] = !1);
3451
+ }
3452
+ scheduleTextBatchSync(e) {
3453
+ this.pendingTextBatchSync.add(e), !this.textBatchSyncScheduled && (this.textBatchSyncScheduled = !0, Br(() => {
3454
+ if (this.textBatchSyncScheduled = !1, this.disposed) {
3455
+ this.pendingTextBatchSync.clear();
3456
+ return;
3457
+ }
3458
+ const r = Array.from(this.pendingTextBatchSync);
3459
+ this.pendingTextBatchSync.clear();
3460
+ for (const i of r)
3461
+ i.parent && i.sync();
3462
+ }));
3463
+ }
3464
+ createRenderableChunk(e, r, i, a, s, o, c) {
3465
+ const l = new xt();
3466
+ l.setAttribute("position", new Cn(i, 3)), this.registerGeometryDisplayColors(
3467
+ l,
3468
+ a,
3469
+ r,
3470
+ e === "fill" ? "fill" : e === "dot" ? "dot" : "line",
3471
+ c
3472
+ );
3473
+ const u = this.colorOverridesByIndex.get(r) ?? null;
3474
+ let d;
3475
+ if (e === "line") {
3476
+ const f = new Ft({ vertexColors: !0 });
3477
+ this.applyLayerColorState(f, u, e);
3478
+ const b = new pt(l, f);
3479
+ b.renderOrder = 1, d = b;
3480
+ } else if (e === "fill") {
3481
+ const f = new Ot({
3482
+ vertexColors: !0,
3483
+ side: st,
3484
+ depthWrite: !1
3485
+ });
3486
+ this.applyLayerColorState(f, u, e);
3487
+ const b = new gt(l, f);
3488
+ b.renderOrder = 0, d = b;
3489
+ } else {
3490
+ const f = this.createPointMaterial(r, u, e), b = new wn(l, f);
3491
+ b.renderOrder = 2, d = b;
3492
+ }
3493
+ d.name = `${e}-chunk`, d.userData.kind = e, d.userData.layerIndex = r, d.userData.vertexCount = s;
3494
+ const h = o === void 0 ? Me(i, Math.floor(i.length / 3), 3) : o;
3495
+ return d.userData.bbox = h, this.nonLineChunkStats.push({ layerIndex: r, vertexCount: s, bbox: h }), d;
3496
+ }
3497
+ createRenderableLineChunk(e, r, i, a, s, o, c, l, u = 3, d) {
3498
+ const h = this.makeLineChunkRecord(
3499
+ e,
3500
+ r,
3501
+ i,
3502
+ a,
3503
+ s,
3504
+ o,
3505
+ c,
3506
+ l,
3507
+ u,
3508
+ d
3509
+ );
3510
+ return this.registerLineChunkRecord(h), h.renderable;
3511
+ }
3512
+ makeLineChunkRecord(e, r, i, a, s, o, c, l, u = 3, d) {
3513
+ const h = this.resolveLineweightPx(r, d), f = s < 2 || s % 2 !== 0 || h <= 1, b = un(l, s), g = c === "xy-zero-z" || u === 2 ? Ba(i, s, u) : Ra(i, s), C = o === void 0 ? Me(i, s, u) : o, v = this.resolveInitialLineChunkVariant(r, s, f, d), x = this.buildLineRenderableViews(
3514
+ r,
3515
+ g,
3516
+ a,
3517
+ s,
3518
+ f,
3519
+ C,
3520
+ b,
3521
+ d
3522
+ ), I = v === "fat" && x.fatRenderable ? x.fatRenderable : x.thinRenderable, V = {
3523
+ layerIndex: r,
3524
+ ...d === void 0 ? {} : { lineweightPx: d },
3525
+ parent: e,
3526
+ position: g,
3527
+ canonicalMemoryStats: Va(g, a, s),
3528
+ col: a,
3529
+ colorRuns: b,
3530
+ vertexCount: s,
3531
+ bbox: C,
3532
+ forceThin: f,
3533
+ activeVariant: v,
3534
+ renderable: I,
3535
+ thinRenderable: x.thinRenderable,
3536
+ fatRenderable: x.fatRenderable,
3537
+ thinMaterial: x.thinMaterial,
3538
+ fatMaterial: x.fatMaterial
3539
+ };
3540
+ return this.installSharedLineColorTargetMarkers(V), this.applyInitialLineDisplayColors(V), V;
3541
+ }
3542
+ registerLineChunkRecord(e) {
3543
+ this.lineChunkRecords.push(e), this.addLineCanonicalStats(e);
3544
+ }
3545
+ addLineCanonicalStats(e) {
3546
+ this.lineCanonicalMemoryStats = ka(
3547
+ this.lineCanonicalMemoryStats,
3548
+ e.canonicalMemoryStats
3549
+ );
3550
+ }
3551
+ subtractLineCanonicalStats(e) {
3552
+ this.lineCanonicalMemoryStats = Aa(
3553
+ this.lineCanonicalMemoryStats,
3554
+ e.canonicalMemoryStats
3555
+ );
3556
+ }
3557
+ rebuildLineVariantStats() {
3558
+ const e = za();
3559
+ for (const r of this.lineChunkRecords)
3560
+ r.activeVariant === "thin" && (e.activeThinCount += 1), r.activeVariant === "fat" && (e.activeFatCount += 1), r.thinRenderable && r.thinRenderable !== r.renderable && (e.cachedThinCount += 1), r.fatRenderable && r.fatRenderable !== r.renderable && (e.cachedFatCount += 1);
3561
+ return e;
3562
+ }
3563
+ resolveLineChunkVariant(e) {
3564
+ const r = this.resolveLineweightPx(e.layerIndex, e.lineweightPx);
3565
+ return this.shouldUseThinLineVariant(r, e.vertexCount, e.forceThin) ? "thin" : "fat";
3566
+ }
3567
+ resolveInitialLineChunkVariant(e, r, i, a) {
3568
+ const s = this.resolveLineweightPx(e, a);
3569
+ return this.shouldUseThinLineVariant(s, r, i) ? "thin" : "fat";
3570
+ }
3571
+ resolveLineweightPx(e, r) {
3572
+ var i;
3573
+ return r ?? ((i = this.layerStatesByIndex.get(e)) == null ? void 0 : i.lw_px) ?? 1;
3574
+ }
3575
+ shouldUseThinLineVariant(e, r, i) {
3576
+ return i || r < 2 || r % 2 !== 0 ? !0 : this.lineModeSwitchingEnabled ? this.effectiveRenderQuality === "stress" && e < _t : e < _t;
3577
+ }
3578
+ buildLineRenderableViews(e, r, i, a, s, o, c, l) {
3579
+ const u = this.resolveLineweightPx(e, l), d = r.kind === "xy" ? r.xy : r.xyz, h = r.kind === "xy" ? 2 : 3, f = o ?? Me(d, a, h) ?? {
3580
+ minX: 0,
3581
+ minY: 0,
3582
+ maxX: 0,
3583
+ maxY: 0
3584
+ }, b = i.slice(), g = sa({
3585
+ position: d,
3586
+ positionItemSize: h,
3587
+ color: i,
3588
+ vertexCount: a,
3589
+ bbox: f
3590
+ });
3591
+ this.finalizeCadLineRenderable(g, e, a, f, i, b, c);
3592
+ let C = null;
3593
+ return !s && a >= 2 && a % 2 === 0 && (C = oa({
3594
+ position: d,
3595
+ positionItemSize: h,
3596
+ color: i,
3597
+ vertexCount: a,
3598
+ linewidthPx: u,
3599
+ resolution: new gn(this.lineResolution.width, this.lineResolution.height),
3600
+ bbox: f
3601
+ }), this.finalizeCadLineRenderable(C, e, a, f, i, b, c)), {
3602
+ thinRenderable: g,
3603
+ fatRenderable: C,
3604
+ thinMaterial: g.material,
3605
+ fatMaterial: (C == null ? void 0 : C.material) ?? null
3606
+ };
3607
+ }
3608
+ finalizeCadLineRenderable(e, r, i, a, s, o, c) {
3609
+ e.name = "line-chunk", e.renderOrder = 1, e.userData.kind = "line", e.userData.layerIndex = r, e.userData.vertexCount = i, e.userData.bbox = a;
3610
+ const l = e.geometry;
3611
+ l.userData.cadDisplayColorTarget = {
3612
+ array: s,
3613
+ markNeedsUpdate: () => Je(l)
3614
+ }, this.installGeometryDisplayColorMetadata(l, o, r, "line", c);
3615
+ const u = this.colorOverridesByIndex.get(r) ?? null;
3616
+ this.applyLayerColorState(e.material, u, "line"), e.material.needsUpdate = !0;
3617
+ }
3618
+ installSharedLineColorTargetMarkers(e) {
3619
+ const r = () => {
3620
+ Je(e.thinRenderable.geometry), e.fatRenderable && Je(e.fatRenderable.geometry);
3621
+ }, i = (a) => {
3622
+ if (!a) return;
3623
+ const s = a.geometry;
3624
+ s.userData.cadDisplayColorTarget = {
3625
+ array: e.col,
3626
+ markNeedsUpdate: r
3627
+ };
3628
+ };
3629
+ i(e.thinRenderable), i(e.fatRenderable);
3630
+ }
3631
+ applyInitialLineDisplayColors(e) {
3632
+ const r = e.renderable;
3633
+ this.applyDisplayColorsToGeometry(r.geometry);
3634
+ }
3635
+ createRenderableTextChunk(e) {
3636
+ const r = pr, i = this.resolveTextFont(e.t), a = new r();
3637
+ a.text = i.text, a.fontSize = e.h, a.position.set(e.x, e.y, 0), a.rotation.z = (e.r || 0) * Math.PI / 180, a.color = this.resolveDisplayHexForRgb(e.c, e.li, "text"), a.anchorX = Ie.resolveTextAnchorX(e.ha), a.anchorY = Ie.resolveTextAnchorY(e.va), i.fontUrl && (a.font = i.fontUrl), e.w && (a.maxWidth = e.w), e.lh && (a.lineHeight = e.lh);
3638
+ const s = e.wf || 1;
3639
+ return a.scale.x = (e.mx ? -1 : 1) * s, e.my && (a.scale.y = -1), this.commitTroikaTextTransform(a), a.name = "text-chunk", a.userData.kind = "text", a.userData.layerIndex = e.li, a.userData.text = { ...e, c: P(e.c) }, a.userData.renderedText = i.text, a.userData.fontKind = i.kind ?? "default", a.userData.replacedUnsupportedText = i.replacedUnsupported === !0, a;
3640
+ }
3641
+ commitTroikaTextTransform(e) {
3642
+ e.matrixAutoUpdate = !1, e.updateMatrix();
3643
+ }
3644
+ getOrCreateKindGroup(e, r) {
3645
+ const i = this.ensureLayerGroup(e), a = i.children.find((o) => o instanceof j && o.name === r);
3646
+ if (a) return a;
3647
+ const s = new j();
3648
+ return s.name = r, i.add(s), s;
3649
+ }
3650
+ appendAnnotationPreparedGeometryChunk(e, r) {
3651
+ if (!(this.disposed || r.length === 0))
3652
+ for (const i of r) {
3653
+ if (i.count <= 0) continue;
3654
+ const a = this.getOrCreateAnnotationKindGroup(i.layerIndex, e), s = e === "line" ? this.createRenderableLineChunk(
3655
+ a,
3656
+ i.layerIndex,
3657
+ i.pos,
3658
+ i.col,
3659
+ i.count,
3660
+ i.bbox,
3661
+ i.linePositionKind,
3662
+ i.colorRuns,
3663
+ i.positionItemSize,
3664
+ i.lineweightPx
3665
+ ) : this.createRenderableChunk(
3666
+ e,
3667
+ i.layerIndex,
3668
+ i.pos,
3669
+ i.col,
3670
+ i.count,
3671
+ i.bbox,
3672
+ i.colorRuns
3673
+ );
3674
+ s.userData.annotationOverlay = !0, s.visible = this.annotationOverlayVisible, a.add(s);
3675
+ }
3676
+ }
3677
+ getOrCreateAnnotationKindGroup(e, r) {
3678
+ const i = this.getOrCreateAnnotationOverlayGroup(e), a = r === "text" ? "annotation-text" : `annotation-${r}`, s = i.children.find(
3679
+ (c) => c instanceof j && c.name === a
3680
+ );
3681
+ if (s) return s;
3682
+ const o = new j();
3683
+ return o.name = a, o.visible = this.annotationOverlayVisible && this.isLayerVisible(e), o.userData.annotationOverlay = !0, o.userData.kind = r, i.add(o), o;
3684
+ }
3685
+ getOrCreateAnnotationOverlayGroup(e) {
3686
+ const r = this.annotationOverlayGroupsByLayerIndex.get(e);
3687
+ if (r) return r;
3688
+ const i = this.ensureLayerGroup(e), a = new j();
3689
+ return a.name = "annotation-overlay", a.visible = this.annotationOverlayVisible && this.isLayerVisible(e), a.userData.annotationOverlay = !0, a.userData.layerIndex = e, this.annotationOverlayGroupsByLayerIndex.set(e, a), i.add(a), a;
3690
+ }
3691
+ applyAnnotationOverlayVisibility(e) {
3692
+ e.traverse((r) => {
3693
+ const i = Number(r.userData.layerIndex ?? e.userData.layerIndex), a = Number.isInteger(i) ? this.isLayerVisible(i) : !0;
3694
+ r.visible = this.annotationOverlayVisible && a;
3695
+ });
3696
+ for (const r of this.annotationTextRecordsByLayerIndex.values())
3697
+ for (const i of r)
3698
+ this.applyAnnotationTextRenderableVisibility(i);
3699
+ }
3700
+ createInsertVisibilityHandleForAnnotationText(e) {
3701
+ const r = this;
3702
+ return {
3703
+ get visible() {
3704
+ return e.insertVisible;
3705
+ },
3706
+ set visible(i) {
3707
+ e.insertVisible = i, r.applyAnnotationTextRenderableVisibility(e);
3708
+ }
3709
+ };
3710
+ }
3711
+ applyAnnotationTextRenderableVisibility(e) {
3712
+ e.renderable.visible = this.annotationOverlayVisible && this.isLayerVisible(e.layerIndex) && e.insertVisible;
3713
+ }
3714
+ refreshAnnotationTextVisibilityForLayer(e) {
3715
+ for (const i of this.annotationTextRecordsByLayerIndex.get(e) ?? [])
3716
+ this.applyAnnotationTextRenderableVisibility(i);
3717
+ const r = this.annotationOverlayGroupsByLayerIndex.get(e);
3718
+ r && this.applyAnnotationOverlayVisibility(r);
3719
+ }
3720
+ isLayerVisible(e) {
3721
+ var r;
3722
+ return ((r = this.layerStatesByIndex.get(e)) == null ? void 0 : r.visible) ?? !0;
3723
+ }
3724
+ ensureLayerGroup(e, r, i = !0) {
3725
+ var o;
3726
+ const a = this.layerGroupsByIndex.get(e);
3727
+ if (a) return a;
3728
+ const s = new j();
3729
+ if (s.name = r ?? `Layer ${e}`, s.visible = ((o = this.layerStatesByIndex.get(e)) == null ? void 0 : o.visible) ?? i, s.userData.layerIndex = e, this.layerGroupsByIndex.set(e, s), this.add(s), !this.layerStatesByIndex.has(e)) {
3730
+ this.layerOrder.push(e);
3731
+ const c = [255, 255, 255];
3732
+ this.layerStatesByIndex.set(e, {
3733
+ index: e,
3734
+ name: s.name,
3735
+ color: P(c),
3736
+ lw_px: 1,
3737
+ visible: i
3738
+ }), this.originalLayerColorsByIndex.set(e, P(c)), this.layerStateRevision += 1;
3739
+ }
3740
+ return s;
3741
+ }
3742
+ compactGeometryByLayer() {
3743
+ this.compactLineChunksPerLayer(), this.compactNonLineChunksPerLayer("fill"), this.compactNonLineChunksPerLayer("dot"), this.rebuildNonLineChunkStats(), this.notifyInternalChange();
3744
+ }
3745
+ async compactGeometryByLayerIncrementally(e, r) {
3746
+ const i = [];
3747
+ for (const a of this.layerOrder)
3748
+ i.push(
3749
+ {
3750
+ label: `line:${a}`,
3751
+ run: () => this.compactLineChunksForSingleLayer(a)
3752
+ },
3753
+ {
3754
+ label: `fill:${a}`,
3755
+ run: () => this.compactNonLineChunksForSingleLayer(a, "fill")
3756
+ },
3757
+ {
3758
+ label: `dot:${a}`,
3759
+ run: () => this.compactNonLineChunksForSingleLayer(a, "dot")
3760
+ }
3761
+ );
3762
+ await Ca(i, {
3763
+ opsPerPass: e,
3764
+ frameBudgetMs: qn,
3765
+ onYield: r
3766
+ }), this.rebuildNonLineChunkStats(), this.notifyInternalChange();
3767
+ }
3768
+ compactLineChunksPerLayer() {
3769
+ for (const e of this.layerOrder)
3770
+ this.compactLineChunksForSingleLayer(e);
3771
+ }
3772
+ compactLineChunksForSingleLayer(e) {
3773
+ const r = this.buildLineCompactionGroups(e);
3774
+ if (r.length === 0)
3775
+ return !1;
3776
+ const i = /* @__PURE__ */ new Set(), a = [];
3777
+ for (const o of r) {
3778
+ let c = 0, l = null;
3779
+ for (const x of o.records)
3780
+ c += x.vertexCount, l = Le(l, x.bbox);
3781
+ const u = o.canonicalKind === "xy" ? 2 : 3, d = new Float32Array(c * u), h = new Uint8Array(c * 3), f = [];
3782
+ let b = !0, g = 0;
3783
+ for (const x of o.records)
3784
+ Ea(
3785
+ x.position,
3786
+ x.vertexCount,
3787
+ d,
3788
+ g,
3789
+ u
3790
+ ), h.set(x.col, g * 3), x.colorRuns && x.colorRuns.length > 0 ? cn(f, x.colorRuns, g) : b = !1, g += x.vertexCount;
3791
+ for (const x of o.records)
3792
+ i.add(x), this.subtractLineCanonicalStats(x), this.disposeLineChunkRecord(x);
3793
+ const C = b ? ft(f) : void 0, v = this.makeLineChunkRecord(
3794
+ o.parent,
3795
+ e,
3796
+ d,
3797
+ h,
3798
+ c,
3799
+ l,
3800
+ u === 2 ? "xy-zero-z" : void 0,
3801
+ C,
3802
+ u,
3803
+ o.lineweightPx
3804
+ );
3805
+ o.parent.add(v.renderable), this.addLineCanonicalStats(v), a.push(v);
3806
+ }
3807
+ const s = this.lineChunkRecords.filter((o) => !i.has(o));
3808
+ return this.lineChunkRecords.length = 0, this.lineChunkRecords.push(...s, ...a), !0;
3809
+ }
3810
+ buildLineCompactionGroups(e) {
3811
+ const r = /* @__PURE__ */ new Map();
3812
+ for (const i of this.lineChunkRecords) {
3813
+ if (i.layerIndex !== e) continue;
3814
+ const a = `${i.parent.id}:${i.position.kind}:${i.lineweightPx ?? ""}`;
3815
+ let s = r.get(a);
3816
+ s || (s = {
3817
+ layerIndex: e,
3818
+ ...i.lineweightPx === void 0 ? {} : { lineweightPx: i.lineweightPx },
3819
+ parent: i.parent,
3820
+ canonicalKind: i.position.kind,
3821
+ records: []
3822
+ }, r.set(a, s)), s.records.push(i);
3823
+ }
3824
+ return [...r.values()].filter((i) => i.records.length > 1);
3825
+ }
3826
+ compactNonLineChunksPerLayer(e) {
3827
+ for (const r of this.layerOrder)
3828
+ this.compactNonLineChunksForSingleLayer(r, e);
3829
+ }
3830
+ compactNonLineChunksForSingleLayer(e, r) {
3831
+ var v, x;
3832
+ const i = this.findKindGroup(e, r);
3833
+ if (!i || i.children.length <= 1)
3834
+ return !1;
3835
+ const a = [...i.children];
3836
+ if (a.length <= 1)
3837
+ return !1;
3838
+ let s = 0, o = null;
3839
+ const c = [], l = [], u = [];
3840
+ let d = !0;
3841
+ for (const I of a) {
3842
+ const M = I.geometry;
3843
+ if (!M) continue;
3844
+ const Q = M.getAttribute("position"), q = M.getAttribute("color");
3845
+ if (!(Q instanceof U) || !(q instanceof U) || !(Q.array instanceof Float32Array)) continue;
3846
+ const W = Number(((v = I.userData) == null ? void 0 : v.vertexCount) || 0);
3847
+ if (W <= 0) continue;
3848
+ const N = M.userData.cadDisplaySourceColor, G = M.userData.cadDisplayColorRuns;
3849
+ G && G.length > 0 ? cn(u, G, s) : d = !1, s += W, c.push(Q.array), l.push(N instanceof Uint8Array ? N : Oi(q)), o = Le(o, ((x = I.userData) == null ? void 0 : x.bbox) ?? null);
3850
+ }
3851
+ for (const I of a)
3852
+ i.remove(I), at(I);
3853
+ if (s <= 0)
3854
+ return !1;
3855
+ const h = new Float32Array(s * 3), f = new Uint8Array(s * 3);
3856
+ let b = 0;
3857
+ for (let I = 0; I < c.length; I += 1) {
3858
+ const V = Math.floor(c[I].length / 3), M = b * 3;
3859
+ h.set(c[I], M), f.set(l[I], M), b += V;
3860
+ }
3861
+ const g = d ? ft(u) : void 0, C = this.createRenderableChunk(
3862
+ r,
3863
+ e,
3864
+ h,
3865
+ f,
3866
+ s,
3867
+ o,
3868
+ g
3869
+ );
3870
+ return i.add(C), !0;
3871
+ }
3872
+ rebuildNonLineChunkStats() {
3873
+ var r, i;
3874
+ this.nonLineChunkStats.length = 0;
3875
+ const e = ["fill", "dot"];
3876
+ for (const a of e)
3877
+ for (const s of this.layerOrder) {
3878
+ const o = this.findKindGroup(s, a);
3879
+ if (o)
3880
+ for (const c of o.children) {
3881
+ const l = Number(((r = c.userData) == null ? void 0 : r.vertexCount) || 0), u = ((i = c.userData) == null ? void 0 : i.bbox) ?? null;
3882
+ this.nonLineChunkStats.push({ layerIndex: s, vertexCount: l, bbox: u });
3883
+ }
3884
+ }
3885
+ }
3886
+ findKindGroup(e, r) {
3887
+ const i = this.layerGroupsByIndex.get(e);
3888
+ return i ? i.children.find((s) => s instanceof j && s.name === r) ?? null : null;
3889
+ }
3890
+ disposeLineChunkRecord(e) {
3891
+ const r = [e.renderable, e.thinRenderable, e.fatRenderable], i = /* @__PURE__ */ new Set();
3892
+ for (const a of r)
3893
+ !a || i.has(a) || (i.add(a), a.parent && a.parent.remove(a), at(a));
3894
+ e.fatRenderable = null, e.fatMaterial = null;
3895
+ }
3896
+ applyLayerColorState(e, r, i = "line") {
3897
+ r ? (e.vertexColors = !1, e.color.setHex(this.resolveDisplayHexForRgb(r, null, i))) : (e.vertexColors = !0, e.color.setHex(16777215));
3898
+ const a = Zt(
3899
+ { kind: "none" },
3900
+ {
3901
+ theme: this.displayThemeName,
3902
+ elementKind: i,
3903
+ enhanceContrast: this.displayContrastEnhancement
3904
+ }
3905
+ ).opacity;
3906
+ e.opacity = a, e.transparent = a < 1;
3907
+ }
3908
+ refreshDisplayColors() {
3909
+ this.traverse((e) => {
3910
+ var u, d;
3911
+ const r = (u = e.userData) == null ? void 0 : u.kind;
3912
+ if (r === "text" || r === "text-batch") return;
3913
+ const i = e.geometry;
3914
+ i && this.applyDisplayColorsToGeometry(i);
3915
+ const a = e.material, s = Number.isInteger((d = e.userData) == null ? void 0 : d.layerIndex) ? Number(e.userData.layerIndex) : null, o = s === null ? null : this.colorOverridesByIndex.get(s) ?? null, c = this.displayElementKindForObject(e), l = Array.isArray(a) ? a : a ? [a] : [];
3916
+ for (const h of l)
3917
+ it(h) && (this.applyLayerColorState(h, o, c), h.needsUpdate = !0);
3918
+ });
3919
+ for (const e of this.layerOrder)
3920
+ this.applyLayerTextColors(e, this.colorOverridesByIndex.get(e) ?? null);
3921
+ }
3922
+ registerGeometryDisplayColors(e, r, i, a, s) {
3923
+ const o = this.installGeometryDisplayColorMetadata(
3924
+ e,
3925
+ r,
3926
+ i,
3927
+ a,
3928
+ s
3929
+ );
3930
+ this.applyDisplayColorsToGeometry(o);
3931
+ }
3932
+ installGeometryDisplayColorMetadata(e, r, i, a, s) {
3933
+ const o = e, c = Math.floor(r.length / 3), l = un(s, c);
3934
+ return l ? (delete o.userData.cadDisplaySourceColor, o.userData.cadDisplayColorRuns = l) : (o.userData.cadDisplaySourceColor = On(r).slice(), delete o.userData.cadDisplayColorRuns), o.userData.cadDisplayVertexCount = c, o.userData.cadDisplayLayerIndex = i, o.userData.cadDisplayElementKind = a, o;
3935
+ }
3936
+ applyDisplayColorsToGeometry(e) {
3937
+ const r = e, i = r.userData.cadDisplaySourceColor, a = r.userData.cadDisplayColorRuns, s = Number(r.userData.cadDisplayVertexCount ?? 0), o = Number(r.userData.cadDisplayLayerIndex ?? 0), c = r.userData.cadDisplayElementKind ?? "line", l = a && a.length > 0 && ze(s, a), u = r.userData.cadDisplayColorTarget;
3938
+ if (u) {
3939
+ if (l) {
3940
+ const f = s * 3;
3941
+ if (u.array.length !== f)
3942
+ throw new Error(
3943
+ `CAD display color target length mismatch: expected ${f}, received ${u.array.length}`
3944
+ );
3945
+ const b = dt(
3946
+ u.array,
3947
+ s,
3948
+ a,
3949
+ (g) => this.resolveDisplayRgbForLegacyRgb(g, o, c)
3950
+ );
3951
+ this.recordDisplayColorBuildStats(b), u.markNeedsUpdate();
3952
+ return;
3953
+ }
3954
+ if (i instanceof Uint8Array && i.length > 0) {
3955
+ if (u.array.length !== i.length)
3956
+ throw new Error(
3957
+ `CAD display color target length mismatch: expected ${i.length}, received ${u.array.length}`
3958
+ );
3959
+ const f = this.buildDisplayColorBytes(i, o, c);
3960
+ u.array.set(f), u.markNeedsUpdate();
3961
+ return;
3962
+ }
3963
+ return;
3964
+ }
3965
+ if (l && typeof r.setColors == "function") {
3966
+ const f = zi(
3967
+ s,
3968
+ a,
3969
+ (b) => this.resolveDisplayRgbForLegacyRgb(b, o, c)
3970
+ );
3971
+ this.recordDisplayColorBuildStats(f.stats), r.setColors(f.color), r.getAttribute("instanceColorStart") && (r.getAttribute("instanceColorStart").needsUpdate = !0), r.getAttribute("instanceColorEnd") && (r.getAttribute("instanceColorEnd").needsUpdate = !0);
3972
+ return;
3973
+ }
3974
+ if (l) {
3975
+ const f = r.getAttribute("color");
3976
+ if (f instanceof U && f.array instanceof Uint8Array && f.array.length === s * 3) {
3977
+ const g = dt(
3978
+ f.array,
3979
+ s,
3980
+ a,
3981
+ (C) => this.resolveDisplayRgbForLegacyRgb(C, o, c)
3982
+ );
3983
+ this.recordDisplayColorBuildStats(g), f.normalized = !0, f.needsUpdate = !0;
3984
+ return;
3985
+ }
3986
+ const b = jt(
3987
+ s,
3988
+ a,
3989
+ (g) => this.resolveDisplayRgbForLegacyRgb(g, o, c)
3990
+ );
3991
+ this.recordDisplayColorBuildStats(b.stats), r.setAttribute("color", $t(b.color));
3992
+ return;
3993
+ }
3994
+ if (!(i instanceof Uint8Array) || i.length === 0) return;
3995
+ const d = this.buildDisplayColorBytes(i, o, c);
3996
+ if (typeof r.setColors == "function") {
3997
+ r.setColors(Fi(d)), r.getAttribute("instanceColorStart") && (r.getAttribute("instanceColorStart").needsUpdate = !0), r.getAttribute("instanceColorEnd") && (r.getAttribute("instanceColorEnd").needsUpdate = !0);
3998
+ return;
3999
+ }
4000
+ const h = r.getAttribute("color");
4001
+ if (h instanceof U && h.array instanceof Uint8Array && h.array.length === d.length) {
4002
+ h.array.set(d), h.normalized = !0, h.needsUpdate = !0;
4003
+ return;
4004
+ }
4005
+ r.setAttribute("color", $t(d));
4006
+ }
4007
+ buildDisplayColorBytes(e, r, i, a, s) {
4008
+ const c = a && a.length > 0 && typeof s == "number" && ze(s, a) ? jt(
4009
+ s,
4010
+ a,
4011
+ (l) => this.resolveDisplayRgbForLegacyRgb(l, r, i)
4012
+ ) : _i(
4013
+ e,
4014
+ (l) => this.resolveDisplayRgbForLegacyRgb(l, r, i)
4015
+ );
4016
+ return this.recordDisplayColorBuildStats(c.stats), c.color;
4017
+ }
4018
+ recordDisplayColorBuildStats(e) {
4019
+ this.colorRefreshStats.displayRefreshVertexTotal += e.vertexCount, this.colorRefreshStats.displayRefreshRunTotal += e.runCount, this.colorRefreshStats.displayRefreshUniqueColorTotal += e.uniqueColorCount, this.colorRefreshStats.displayRefreshCacheHitTotal += e.cacheHitCount, this.colorRefreshStats.displayRefreshRepeatedRunVertexTotal += e.repeatedRunVertexCount;
4020
+ }
4021
+ resolveDisplayHexForRgb(e, r, i) {
4022
+ const a = ja(e, r, i, this.displayThemeName, this.displayContrastEnhancement), s = this.displayHexMemo.get(a);
4023
+ if (s !== void 0) return s;
4024
+ const o = Wa(this.resolveDisplayRgbForLegacyRgb(e, r, i));
4025
+ return this.displayHexMemo.set(a, o), o;
4026
+ }
4027
+ resolveDisplayRgbForLegacyRgb(e, r, i) {
4028
+ const a = r !== null && kt(e), s = Qi(e, { treatLegacyForegroundAsAci7: a });
4029
+ return Zt(s, {
4030
+ theme: this.displayThemeName,
4031
+ elementKind: i,
4032
+ enhanceContrast: this.displayContrastEnhancement
4033
+ }).rgb;
4034
+ }
4035
+ displayElementKindForObject(e) {
4036
+ var i;
4037
+ const r = (i = e.userData) == null ? void 0 : i.kind;
4038
+ return r === "text-batch" ? "text" : r === "fill" || r === "dot" || r === "text" || r === "hatch" || r === "overlay" ? r : "line";
4039
+ }
4040
+ createInsertInstanceRecords(e) {
4041
+ const r = [], { meta: i, mats: a, bboxes: s, count: o } = e, c = /* @__PURE__ */ new Map();
4042
+ for (let l = 0; l < o; l += 1) {
4043
+ const u = i[l * 3], d = i[l * 3 + 1], h = `${u}:${d}`, f = c.get(h) ?? 0;
4044
+ c.set(h, f + 1);
4045
+ const b = {
4046
+ minX: s[l * 4],
4047
+ minY: s[l * 4 + 1],
4048
+ maxX: s[l * 4 + 2],
4049
+ maxY: s[l * 4 + 3]
4050
+ };
4051
+ an(b) && r.push({
4052
+ recordKey: Wn(u, d, f),
4053
+ instanceId: u,
4054
+ variantId: d,
4055
+ layerIdx: i[l * 3 + 2],
4056
+ matA: a[l * 6],
4057
+ matB: a[l * 6 + 1],
4058
+ matC: a[l * 6 + 2],
4059
+ matD: a[l * 6 + 3],
4060
+ tx: a[l * 6 + 4],
4061
+ ty: a[l * 6 + 5],
4062
+ bbox: b
4063
+ });
4064
+ }
4065
+ return r;
4066
+ }
4067
+ createInsertPresenterMaterial(e) {
4068
+ let r;
4069
+ return e === "line" ? r = new Ft({ vertexColors: !0 }) : e === "fill" ? r = new Ot({
4070
+ vertexColors: !0,
4071
+ side: st,
4072
+ depthWrite: !1
4073
+ }) : r = new Dt({
4074
+ vertexColors: !0,
4075
+ size: 2,
4076
+ sizeAttenuation: !1
4077
+ }), Za(r), r;
4078
+ }
4079
+ clearViewportInsertPresenter() {
4080
+ var e, r;
4081
+ (e = this.viewportInstancePresenter) == null || e.dispose(), this.viewportInstancePresenter = null, this.insertInstanceTable = null, (r = this.blockGeometryRegistry) == null || r.dispose(), this.blockGeometryRegistry = null, this.insertPresenterVariantInputs.clear(), this.insertPresenterRecordsByKey.clear(), this.insertPresenterRecordKeysByInstanceId.clear();
4082
+ }
4083
+ refreshDefaultInsertPresenterIfUnmanaged() {
4084
+ var e;
4085
+ this.insertPresenterExternallyManaged || (e = this.viewportInstancePresenter) == null || e.refresh(
4086
+ null,
4087
+ this.getLayerVisibility(),
4088
+ Pa,
4089
+ 0
4090
+ );
4091
+ }
4092
+ resetContent() {
4093
+ this.contentGeneration += 1, this.insertPresenterExternallyManaged = !1, this.clearViewportInsertPresenter();
4094
+ for (const e of this.lineChunkRecords)
4095
+ this.disposeLineChunkRecord(e);
4096
+ at(this);
4097
+ for (const e of [...this.children])
4098
+ this.remove(e);
4099
+ this.layerOrder.length = 0, this.layerStatesByIndex.clear(), this.layerGroupsByIndex.clear(), this.layersSnapshotCache = null, this.metaSnapshotCache = null, this.boundsSnapshotCache = null, this.originalLayerColorsByIndex.clear(), this.colorOverridesByIndex.clear(), this.displayHexMemo.clear(), this.lineCanonicalMemoryStats = rn(), this.lineChunkRecords.length = 0, this.nonLineChunkStats.length = 0, this.worldSizedPointUniforms.clear(), this.textUserDataByAppendOrder.length = 0, this.textBatchByLayerIndex.clear(), this.textRenderablesByLayerIndex.clear(), this.textRenderablesByAppendOrder.length = 0, this.annotationOverlayGroupsByLayerIndex.clear(), this.annotationTextBatchByLayerIndex.clear(), this.annotationTextRenderablesByLayerIndex.clear(), this.annotationTextRecordsByOwnerKey.clear(), this.annotationTextRecordsByLayerIndex.clear(), this.pendingTextBatchSync.clear(), this.textBatchSyncScheduled = !1, this.insertRuntime = null, this.insertRuntimeInstancesById.clear(), this.colorRefreshStats = {
4100
+ displayRefreshVertexTotal: 0,
4101
+ displayRefreshRunTotal: 0,
4102
+ displayRefreshUniqueColorTotal: 0,
4103
+ displayRefreshCacheHitTotal: 0,
4104
+ displayRefreshRepeatedRunVertexTotal: 0
4105
+ };
4106
+ }
4107
+ rebuildLineChunks() {
4108
+ for (const e of this.lineChunkRecords) {
4109
+ const r = this.resolveLineChunkVariant(e);
4110
+ if (e.activeVariant === r && e.renderable) continue;
4111
+ const i = e.renderable, a = r === "fat" && e.fatRenderable ? e.fatRenderable : e.thinRenderable;
4112
+ a.visible = e.parent.visible, e.parent.add(a), i.parent && i.parent.remove(i), e.activeVariant = a === e.fatRenderable ? "fat" : "thin", e.renderable = a;
4113
+ }
4114
+ }
4115
+ applyCachedLineChunkColors(e, r) {
4116
+ for (const i of this.lineChunkRecords)
4117
+ i.layerIndex === e && (this.applyColorToRenderable(i.thinRenderable, r), this.applyColorToRenderable(i.fatRenderable, r));
4118
+ }
4119
+ applyColorToRenderable(e, r) {
4120
+ if (!e) return;
4121
+ const i = e.material, a = Array.isArray(i) ? i : i ? [i] : [];
4122
+ for (const s of a)
4123
+ it(s) && (this.applyLayerColorState(s, r, this.displayElementKindForObject(e)), s.needsUpdate = !0);
4124
+ }
4125
+ applyLayerTextColors(e, r) {
4126
+ const i = [
4127
+ ...this.textRenderablesByLayerIndex.get(e) ?? [],
4128
+ ...this.annotationTextRenderablesByLayerIndex.get(e) ?? []
4129
+ ];
4130
+ if (i.length === 0) return;
4131
+ for (const o of i)
4132
+ this.applyColorToTextRenderable(o, r);
4133
+ const a = this.textBatchByLayerIndex.get(e), s = this.annotationTextBatchByLayerIndex.get(e);
4134
+ a && this.invalidateTextBatchDisplayState(a), s && this.invalidateTextBatchDisplayState(s), !(typeof globalThis.self > "u") && (a && this.scheduleTextBatchSync(a), s && this.scheduleTextBatchSync(s));
4135
+ }
4136
+ invalidateTextBatchDisplayState(e) {
4137
+ var a;
4138
+ const r = e._dataTextures;
4139
+ if (r) {
4140
+ for (const s of Object.values(r))
4141
+ (a = s == null ? void 0 : s.dispose) == null || a.call(s);
4142
+ e._dataTextures = {};
4143
+ }
4144
+ const i = Array.isArray(e.material) ? e.material : e.material ? [e.material] : [];
4145
+ for (const s of i)
4146
+ s.needsUpdate = !0;
4147
+ }
4148
+ applyColorToTextRenderable(e, r) {
4149
+ const i = e.userData.text, a = r ?? (i == null ? void 0 : i.c) ?? [255, 255, 255];
4150
+ e.color = this.resolveDisplayHexForRgb(a, (i == null ? void 0 : i.li) ?? null, "text");
4151
+ }
4152
+ applyEffectiveRenderQuality(e, r = {}) {
4153
+ e === this.effectiveRenderQuality && !r.forceLineRebuild || (this.effectiveRenderQuality = e, this.rebuildLineChunks(), this.notifyInternalChange());
4154
+ }
4155
+ resolveCurrentEffectiveRenderQuality() {
4156
+ return this.interactionRenderQualityOverride ?? wa(this.renderQualityMode, this.effectiveRenderQuality, this.autoQualityContext);
4157
+ }
4158
+ notifyInternalChange(e = La) {
4159
+ var r;
4160
+ this.renderDebugRevision += 1, (r = this.internalChangeHook) == null || r.call(this, e);
4161
+ }
4162
+ static getTextOwnerKey(e) {
4163
+ return !Number.isInteger(e.iv) || !Number.isInteger(e.io) ? null : `${e.iv}:${e.io}`;
4164
+ }
4165
+ static resolveTextAnchorX(e) {
4166
+ return e === "center" || e === "right" ? e : "left";
4167
+ }
4168
+ static resolveTextAnchorY(e) {
4169
+ return e === "top" || e === "middle" || e === "bottom" ? e : "bottom-baseline";
4170
+ }
4171
+ startReadyCycle() {
4172
+ this.readySettled = !1, this.readyPromise = new Promise((e, r) => {
4173
+ this.resolveReady = e, this.rejectReady = r;
4174
+ });
4175
+ }
4176
+ resolveReadyOnce() {
4177
+ this.readySettled || (this.readySettled = !0, this.resolveReady());
4178
+ }
4179
+ rejectReadyOnce(e) {
4180
+ this.readySettled || (this.readySettled = !0, this.rejectReady(e));
4181
+ }
4182
+ }
4183
+ async function ms(t, n, e) {
4184
+ if (!e.externalVariantBuffers && !e.externalVariantFetchSource)
4185
+ throw new Error("External variant delta requires buffers or fetch source");
4186
+ await ki(t, n, void 0, {
4187
+ hiddenInstanceIds: At(e.hiddenInstanceIds),
4188
+ externalVariantFetchSource: e.externalVariantFetchSource,
4189
+ externalVariantBuffers: e.externalVariantBuffers,
4190
+ requiredExternalVariantIds: ne(e.requiredExternalVariantIds),
4191
+ externalVariantGeometryFetchIds: ne(e.externalVariantGeometryFetchIds),
4192
+ beforeTextAppend: e.beforeTextAppend,
4193
+ externalVariantDeltaOnly: !0
4194
+ });
4195
+ }
4196
+ function xs(t) {
4197
+ return ur(t);
4198
+ }
4199
+ function ps(t) {
4200
+ return mt(t).header;
4201
+ }
4202
+ function gs(t) {
4203
+ return dr(t);
4204
+ }
4205
+ function bs(t) {
4206
+ return hr(t);
4207
+ }
4208
+ function Cs(t, n) {
4209
+ return xn(t, n);
4210
+ }
4211
+ function Is(t) {
4212
+ return yn(t);
4213
+ }
4214
+ function ws(t, n) {
4215
+ return mn(t, n);
4216
+ }
4217
+ function vs(t, n) {
4218
+ if (!n.externalVariantBuffers && !n.externalVariantFetchSource)
4219
+ throw new Error("External variant delta requires buffers or fetch source");
4220
+ const e = mt(t, {
4221
+ hiddenInstanceIds: At(n.hiddenInstanceIds),
4222
+ externalVariantBuffers: n.externalVariantBuffers,
4223
+ requiredExternalVariantIds: ne(n.requiredExternalVariantIds),
4224
+ externalVariantDeltaOnly: !0
4225
+ });
4226
+ return {
4227
+ header: e.header,
4228
+ chunks: Array.from(e.chunks)
4229
+ };
4230
+ }
4231
+ function Rs(t) {
4232
+ Rr(t);
4233
+ }
4234
+ function ts(t) {
4235
+ return t instanceof Error ? t : typeof t == "string" ? new Error(t) : new Error(`Unknown geo load error: ${String(t)}`);
4236
+ }
4237
+ function At(t) {
4238
+ if (!(!t || t.length === 0))
4239
+ return new Set(t);
4240
+ }
4241
+ function ne(t) {
4242
+ if (t !== void 0)
4243
+ return new Set(t);
4244
+ }
4245
+ function ns(t) {
4246
+ if (t.kind !== "url") return null;
4247
+ try {
4248
+ const n = typeof document > "u" ? void 0 : document.baseURI;
4249
+ return new URL(t.url, n).href;
4250
+ } catch {
4251
+ return null;
4252
+ }
4253
+ }
4254
+ function fn(t) {
4255
+ return !!(t && (t.line.count > 0 || t.fill.count > 0 || t.dot.count > 0 || t.texts.length > 0));
4256
+ }
4257
+ async function rs(t, n, e) {
4258
+ if (!n) return null;
4259
+ const r = new URL(n.href, t).href, i = await fetch(r, { signal: e });
4260
+ if (!i.ok) {
4261
+ const o = [i.status, i.statusText].filter(Boolean).join(" ");
4262
+ throw new Error(`Scene annotation fetch failed${o ? `: ${o}` : ""}`);
4263
+ }
4264
+ const a = await i.arrayBuffer();
4265
+ if (a.byteLength !== n.raw_size)
4266
+ throw new Error(
4267
+ `Scene annotation raw_size mismatch: manifest=${n.raw_size}, response=${a.byteLength}`
4268
+ );
4269
+ const s = fr(a);
4270
+ if (s.line.count !== n.line_count || s.fill.count !== n.fill_count || s.dot.count !== n.dot_count || s.texts.length !== n.text_count)
4271
+ throw new Error(`Scene annotation count mismatch for ${r}`);
4272
+ return s;
4273
+ }
4274
+ async function is(t, n, e, r, i) {
4275
+ if (e.externalVariantFetchSource !== void 0 || e.externalVariantBuffers !== void 0 || e.requiredExternalVariantIds !== void 0 || e.externalVariantGeometryFetchIds !== void 0)
4276
+ return { annotations: [] };
4277
+ const a = ns(t);
4278
+ if (!a) return { annotations: [] };
4279
+ const s = xn(n, {
4280
+ hiddenInstanceIds: r,
4281
+ loadBlocks: e.loadBlocks
4282
+ }), o = s.requiredVariantIds.length > 0 ? Rn({
4283
+ baseUrl: a,
4284
+ entries: s.manifest,
4285
+ requiredVariantIds: s.requiredVariantIds,
4286
+ signal: i
4287
+ }) : Promise.resolve({ buffers: /* @__PURE__ */ new Map(), fetchMs: 0 }), c = e.loadAnnotations === !1 ? null : yn(n), [l, u] = await Promise.all([
4288
+ o,
4289
+ c != null && c.scene ? rs(a, c.scene, i) : Promise.resolve(null)
4290
+ ]), d = [];
4291
+ if (fn(u) && d.push(u), e.loadAnnotations !== !1 && e.loadBlocks !== !1) {
4292
+ const h = mn(n, {
4293
+ externalVariantBuffers: l.buffers,
4294
+ hiddenInstanceIds: r
4295
+ });
4296
+ fn(h) && d.push(h);
4297
+ }
4298
+ return {
4299
+ externalVariantBuffers: l.buffers,
4300
+ requiredExternalVariantIds: s.requiredVariantIds,
4301
+ externalVariantGeometryFetchIds: s.requiredVariantIds,
4302
+ annotations: d
4303
+ };
4304
+ }
4305
+ function Bs(t, n = {}) {
4306
+ const e = new AbortController(), r = Bt(t, e.signal), i = new Ie({ resolveTextFont: n.resolveTextFont }), a = [
4307
+ zt(n.signal, e),
4308
+ zt(r.sourceSignal, e)
4309
+ ];
4310
+ hn(i, () => {
4311
+ e.abort(te("GeoNode disposed during CAD load"));
4312
+ });
4313
+ const s = At(n.hiddenInstanceIds), o = ne(n.requiredExternalVariantIds), c = ne(n.externalVariantGeometryFetchIds);
4314
+ return (async () => {
4315
+ var l;
4316
+ try {
4317
+ const u = await Ir(
4318
+ Vn(r.source),
4319
+ e.signal,
4320
+ "CAD load aborted before decoding"
4321
+ ), d = await is(
4322
+ r.source,
4323
+ u,
4324
+ n,
4325
+ s,
4326
+ e.signal
4327
+ ), h = {
4328
+ signal: e.signal,
4329
+ hiddenInstanceIds: s,
4330
+ requiredExternalVariantIds: o ?? ne(d.requiredExternalVariantIds),
4331
+ externalVariantGeometryFetchIds: c ?? ne(d.externalVariantGeometryFetchIds),
4332
+ beforeTextAppend: n.beforeTextAppend,
4333
+ beforeFinalize: async () => {
4334
+ var f;
4335
+ for (const b of d.annotations)
4336
+ await ((f = n.beforeTextAppend) == null ? void 0 : f.call(n, b.texts)), i.appendAnnotationOverlay(b);
4337
+ }
4338
+ };
4339
+ n.loadBlocks === !1 && (h.loadBlocks = !1), typeof n.maxExpandedInstanceVertices == "number" && Number.isFinite(n.maxExpandedInstanceVertices) && n.maxExpandedInstanceVertices >= 0 && (h.maxExpandedInstanceVertices = n.maxExpandedInstanceVertices), n.preferWorker === !1 && (h.preferWorker = !1), n.workerUrl !== void 0 && (h.workerUrl = n.workerUrl), n.workerFactory && (h.workerFactory = n.workerFactory), n.externalVariantFetchSource && (h.externalVariantFetchSource = n.externalVariantFetchSource), n.externalVariantBuffers && n.externalVariantBuffers.size > 0 ? h.externalVariantBuffers = n.externalVariantBuffers : (l = d.externalVariantBuffers) != null && l.size && (h.externalVariantBuffers = d.externalVariantBuffers), await Vi(i, u, void 0, {
4340
+ ...h
4341
+ });
4342
+ } catch (u) {
4343
+ i._fail(ts(u));
4344
+ } finally {
4345
+ for (const u of a) u();
4346
+ hn(i, null);
4347
+ }
4348
+ })(), i;
4349
+ }
4350
+ const as = 40;
4351
+ function jn(t) {
4352
+ return !!(t && Number.isFinite(t.minX) && Number.isFinite(t.minY) && Number.isFinite(t.maxX) && Number.isFinite(t.maxY) && t.maxX >= t.minX && t.maxY >= t.minY);
4353
+ }
4354
+ function ss(t, n, e) {
4355
+ return n.x >= t.minX - e && n.x <= t.maxX + e && n.y >= t.minY - e && n.y <= t.maxY + e;
4356
+ }
4357
+ function os(t, n) {
4358
+ return n.minX >= t.minX && n.maxX <= t.maxX && n.minY >= t.minY && n.maxY <= t.maxY;
4359
+ }
4360
+ function Ss(t, n) {
4361
+ return t.layerIndex === n.layerIndex && t.variantId === n.variantId && t.instanceId === n.instanceId;
4362
+ }
4363
+ function Es(t, n, e = {}) {
4364
+ var s;
4365
+ if (!Number.isFinite(n.x) || !Number.isFinite(n.y)) return null;
4366
+ const r = Math.max(0, e.padding ?? as), i = t.getLayers();
4367
+ let a = null;
4368
+ for (let o = i.length - 1; o >= 0; o -= 1) {
4369
+ const c = i[o];
4370
+ if (!c || !c.visible) continue;
4371
+ const l = t.getLayerBlockUsages(c.index);
4372
+ for (let u = l.length - 1; u >= 0; u -= 1) {
4373
+ const d = l[u];
4374
+ for (let h = d.inserts.length - 1; h >= 0; h -= 1) {
4375
+ const f = d.inserts[h];
4376
+ if (!f.canHighlight || !jn(f.bbox) || ((s = e.isInstanceVisible) == null ? void 0 : s.call(e, f.instanceId)) === !1 || !ss(f.bbox, n, r)) continue;
4377
+ const b = {
4378
+ kind: "insert",
4379
+ layerIndex: c.index,
4380
+ variantId: d.variantId,
4381
+ instanceId: f.instanceId
4382
+ };
4383
+ if (a || (a = b), !e.viewport || os(e.viewport, f.bbox)) return b;
4384
+ }
4385
+ }
4386
+ }
4387
+ return a;
4388
+ }
4389
+ function Vs(t, n) {
4390
+ const e = t.getLayerBlockUsages(n.layerIndex).find((s) => s.variantId === n.variantId), r = e == null ? void 0 : e.inserts.find((s) => s.instanceId === n.instanceId);
4391
+ if (!e || !r || !jn(r.bbox)) return null;
4392
+ const i = t.getLayers().find((s) => s.index === n.layerIndex), a = t.getInsertInstanceBaseTransform(n.instanceId, n.variantId);
4393
+ return {
4394
+ id: { ...n },
4395
+ label: r.label,
4396
+ blockName: e.blockName || `block#${n.variantId}`,
4397
+ layerName: (i == null ? void 0 : i.name) ?? `layer#${n.layerIndex}`,
4398
+ layerIndex: n.layerIndex,
4399
+ tx: (a == null ? void 0 : a.tx) ?? r.tx,
4400
+ ty: (a == null ? void 0 : a.ty) ?? r.ty,
4401
+ rotation: (a == null ? void 0 : a.rotation) ?? null,
4402
+ scaleX: (a == null ? void 0 : a.scaleX) ?? null,
4403
+ scaleY: (a == null ? void 0 : a.scaleY) ?? null,
4404
+ bbox: Object.freeze({ ...r.bbox })
4405
+ };
4406
+ }
4407
+ export {
4408
+ La as GEO_NODE_STRUCTURE_CHANGE,
4409
+ ys as GEO_NODE_VISUAL_CHANGE,
4410
+ A as GeoLoaderError,
4411
+ Ie as GeoNode,
4412
+ ms as appendExternalVariantDeltaToGeoNode,
4413
+ Rs as assertValidSourceOrThrow,
4414
+ Ss as cadInsertSelectionEquals,
4415
+ fs as createLoadSession,
4416
+ ar as expandViewportRect,
4417
+ vs as loadExternalVariantDeltaFromBuffer,
4418
+ Bs as loadGeo,
4419
+ Le as mergeViewportRects,
4420
+ ts as normalizeGeoError,
4421
+ xs as parseBuffer,
4422
+ gs as parseBufferBounds,
4423
+ ps as parseBufferHeader,
4424
+ Es as pickCadInsertAtPoint,
4425
+ Ts as readBlockAnnotationSidecar,
4426
+ Is as readBufferExternalAnnotationManifest,
4427
+ ws as readBufferExternalBlockAnnotations,
4428
+ Cs as readBufferExternalVariantDependencyPlan,
4429
+ bs as readBufferExternalVariantManifest,
4430
+ fr as readSceneAnnotationSidecar,
4431
+ Vs as resolveCadInsertDetails,
4432
+ nr as transformBBoxByInstance,
4433
+ lr as viewportRectContains,
4434
+ or as viewportRectIntersects
4435
+ };