@flyfish-dev/cad-viewer 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,113 +1,113 @@
1
- var re = Object.defineProperty;
2
- var ie = (e, t, r) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var d = (e, t, r) => ie(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { openDwfDocument as se, DwfViewer as ne } from "dwf-viewer";
5
- async function U(e) {
1
+ var Te = Object.defineProperty;
2
+ var Le = (e, t, n) => t in e ? Te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var d = (e, t, n) => Le(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { openDwfDocument as Ae, DwfViewer as Be } from "dwf-viewer";
5
+ async function K(e) {
6
6
  if (e.buffer instanceof Uint8Array) return e.buffer;
7
7
  if (e.buffer instanceof ArrayBuffer) return new Uint8Array(e.buffer);
8
8
  if (e.file) return new Uint8Array(await e.file.arrayBuffer());
9
9
  throw new Error("CadLoadInput requires a File, ArrayBuffer, or Uint8Array.");
10
10
  }
11
- function oe(e) {
11
+ function Fe(e) {
12
12
  return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
13
13
  }
14
- function L(e) {
15
- var i;
16
- const t = e.fileName ?? ((i = e.file) == null ? void 0 : i.name) ?? "", r = t.lastIndexOf(".");
17
- return r >= 0 ? t.slice(r + 1).toLowerCase() : "";
18
- }
19
- function B(e, t) {
20
- const r = L(e);
21
- if (r === "dwg") return "dwg";
22
- if (r === "dxf") return "dxf";
23
- if (r === "dwfx") return "dwfx";
24
- if (r === "xps") return "xps";
25
- if (r === "dwf") return "dwf";
14
+ function z(e) {
15
+ var r;
16
+ const t = e.fileName ?? ((r = e.file) == null ? void 0 : r.name) ?? "", n = t.lastIndexOf(".");
17
+ return n >= 0 ? t.slice(n + 1).toLowerCase() : "";
18
+ }
19
+ function Y(e, t) {
20
+ const n = z(e);
21
+ if (n === "dwg") return "dwg";
22
+ if (n === "dxf") return "dxf";
23
+ if (n === "dwfx") return "dwfx";
24
+ if (n === "xps") return "xps";
25
+ if (n === "dwf") return "dwf";
26
26
  if (t && t.byteLength >= 6) {
27
- const i = Ct(t.slice(0, 6));
28
- if (/^AC10/.test(i)) return "dwg";
27
+ const r = Wt(t.slice(0, 6));
28
+ if (/^AC10/.test(r)) return "dwg";
29
29
  if (t[0] === 80 && t[1] === 75) return "dwfx";
30
- const s = Ct(t.slice(0, Math.min(t.byteLength, 2048))).toUpperCase();
31
- if (s.includes("SECTION") && s.includes("ENTITIES")) return "dxf";
32
- if (s.includes("DWF")) return "dwf";
30
+ const i = Wt(t.slice(0, Math.min(t.byteLength, 2048))).toUpperCase();
31
+ if (i.includes("SECTION") && i.includes("ENTITIES")) return "dxf";
32
+ if (i.includes("DWF")) return "dwf";
33
33
  }
34
34
  return "unknown";
35
35
  }
36
- function Ct(e) {
36
+ function Wt(e) {
37
37
  return Array.from(e, (t) => t >= 32 && t <= 126 ? String.fromCharCode(t) : " ").join("");
38
38
  }
39
- class ae {
39
+ class De {
40
40
  constructor(t = []) {
41
41
  d(this, "loaders", []);
42
- for (const r of t) this.register(r);
42
+ for (const n of t) this.register(n);
43
43
  }
44
44
  register(t) {
45
- const r = this.loaders.findIndex((i) => i.id === t.id);
46
- return r >= 0 ? this.loaders.splice(r, 1, t) : this.loaders.push(t), this;
45
+ const n = this.loaders.findIndex((r) => r.id === t.id);
46
+ return n >= 0 ? this.loaders.splice(n, 1, t) : this.loaders.push(t), this;
47
47
  }
48
48
  unregister(t) {
49
- const r = this.loaders.findIndex((i) => i.id === t);
50
- return r >= 0 && this.loaders.splice(r, 1), this;
49
+ const n = this.loaders.findIndex((r) => r.id === t);
50
+ return n >= 0 && this.loaders.splice(n, 1), this;
51
51
  }
52
52
  list() {
53
53
  return [...this.loaders];
54
54
  }
55
55
  async detect(t) {
56
- const r = await U(t), i = B(t, r), s = this.loaders.find((o) => o.formats.includes(i) && o.accepts(t, r));
57
- if (s) return { loader: s, bytes: r, format: i };
58
- const n = this.loaders.find((o) => o.accepts(t, r));
59
- if (n) return { loader: n, bytes: r, format: i };
60
- throw new Error(`No CAD loader registered for ${i === "unknown" ? "this file" : i.toUpperCase()}.`);
56
+ const n = await K(t), r = Y(t, n), i = this.loaders.find((o) => o.formats.includes(r) && o.accepts(t, n));
57
+ if (i) return { loader: i, bytes: n, format: r };
58
+ const s = this.loaders.find((o) => o.accepts(t, n));
59
+ if (s) return { loader: s, bytes: n, format: r };
60
+ throw new Error(`No CAD loader registered for ${r === "unknown" ? "this file" : r.toUpperCase()}.`);
61
61
  }
62
- async load(t, r = {}) {
63
- const { loader: i, bytes: s } = await this.detect(t);
64
- return i.load({ ...t, buffer: s }, r);
62
+ async load(t, n = {}) {
63
+ const { loader: r, bytes: i } = await this.detect(t);
64
+ return r.load({ ...t, buffer: i }, n);
65
65
  }
66
66
  }
67
- const ce = "wasm/dwg-worker.js";
68
- class he {
67
+ const Re = "wasm/dwg-worker.js";
68
+ class Oe {
69
69
  constructor() {
70
70
  d(this, "worker");
71
71
  d(this, "sequence", 0);
72
72
  d(this, "pending", /* @__PURE__ */ new Map());
73
73
  }
74
- load(t, r, i = {}) {
75
- var h, l;
76
- if (!dt()) throw new Error("Web Worker is not available in this runtime.");
77
- const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((h = r.file) == null ? void 0 : h.name), c = fe(t, r, i);
78
- return (l = i.onProgress) == null || l.call(i, { phase: "worker-start", format: "dwg", message: "Dispatching DWG parse to worker…", total: t.byteLength }), new Promise((f, u) => {
79
- var g;
80
- if ((g = i.signal) != null && g.aborted) {
81
- u(j());
74
+ load(t, n, r = {}) {
75
+ var l, h;
76
+ if (!xt()) throw new Error("Web Worker is not available in this runtime.");
77
+ const i = this.ensureWorker(r), s = ++this.sequence, o = Math.max(0, Number(r.workerTimeoutMs ?? 0)), a = r.fileName ?? n.fileName ?? ((l = n.file) == null ? void 0 : l.name), c = _e(t, n, r);
78
+ return (h = r.onProgress) == null || h.call(r, { phase: "worker-start", format: "dwg", message: "Dispatching DWG parse to worker…", total: t.byteLength }), new Promise((u, f) => {
79
+ var p;
80
+ if ((p = r.signal) != null && p.aborted) {
81
+ f(rt());
82
82
  return;
83
83
  }
84
- const p = { resolve: f, reject: u, onProgress: i.onProgress, signal: i.signal };
85
- o > 0 && (p.timer = setTimeout(() => {
86
- this.pending.delete(n), this.resetWorker(), u(new Error(`DWG worker timed out after ${o} ms.`));
87
- }, o)), i.signal && (p.abortHandler = () => {
88
- this.pending.delete(n), this.resetWorker(), u(j());
89
- }, i.signal.addEventListener("abort", p.abortHandler, { once: !0 })), this.pending.set(n, p);
84
+ const m = { resolve: u, reject: f, onProgress: r.onProgress, signal: r.signal };
85
+ o > 0 && (m.timer = setTimeout(() => {
86
+ this.pending.delete(s), this.resetWorker(), f(new Error(`DWG worker timed out after ${o} ms.`));
87
+ }, o)), r.signal && (m.abortHandler = () => {
88
+ this.pending.delete(s), this.resetWorker(), f(rt());
89
+ }, r.signal.addEventListener("abort", m.abortHandler, { once: !0 })), this.pending.set(s, m);
90
90
  try {
91
- s.postMessage({
91
+ i.postMessage({
92
92
  type: "load",
93
- requestId: n,
93
+ requestId: s,
94
94
  bytes: c,
95
95
  fileName: a,
96
- options: Pt(i)
96
+ options: _t(r)
97
97
  }, [c]);
98
- } catch (S) {
99
- this.pending.delete(n), $(p), u(S instanceof Error ? S : new Error(String(S)));
98
+ } catch (C) {
99
+ this.pending.delete(s), nt(m), f(C instanceof Error ? C : new Error(String(C)));
100
100
  }
101
101
  });
102
102
  }
103
103
  preload(t = {}) {
104
- var n;
105
- if (!dt()) return Promise.reject(new Error("Web Worker is not available in this runtime."));
106
- const r = this.ensureWorker(t), i = ++this.sequence, s = Math.max(0, Number(t.workerTimeoutMs ?? 0));
107
- return (n = t.onProgress) == null || n.call(t, { phase: "worker-start", format: "dwg", message: "Starting DWG worker warmup…" }), new Promise((o, a) => {
108
- var h;
109
- if ((h = t.signal) != null && h.aborted) {
110
- a(j());
104
+ var s;
105
+ if (!xt()) return Promise.reject(new Error("Web Worker is not available in this runtime."));
106
+ const n = this.ensureWorker(t), r = ++this.sequence, i = Math.max(0, Number(t.workerTimeoutMs ?? 0));
107
+ return (s = t.onProgress) == null || s.call(t, { phase: "worker-start", format: "dwg", message: "Starting DWG worker warmup…" }), new Promise((o, a) => {
108
+ var l;
109
+ if ((l = t.signal) != null && l.aborted) {
110
+ a(rt());
111
111
  return;
112
112
  }
113
113
  const c = {
@@ -116,15 +116,15 @@ class he {
116
116
  onProgress: t.onProgress,
117
117
  signal: t.signal
118
118
  };
119
- s > 0 && (c.timer = setTimeout(() => {
120
- this.pending.delete(i), this.resetWorker(), a(new Error(`DWG worker warmup timed out after ${s} ms.`));
121
- }, s)), t.signal && (c.abortHandler = () => {
122
- this.pending.delete(i), this.resetWorker(), a(j());
123
- }, t.signal.addEventListener("abort", c.abortHandler, { once: !0 })), this.pending.set(i, c);
119
+ i > 0 && (c.timer = setTimeout(() => {
120
+ this.pending.delete(r), this.resetWorker(), a(new Error(`DWG worker warmup timed out after ${i} ms.`));
121
+ }, i)), t.signal && (c.abortHandler = () => {
122
+ this.pending.delete(r), this.resetWorker(), a(rt());
123
+ }, t.signal.addEventListener("abort", c.abortHandler, { once: !0 })), this.pending.set(r, c);
124
124
  try {
125
- r.postMessage({ type: "warmup", requestId: i, options: Pt(t) });
126
- } catch (l) {
127
- this.pending.delete(i), $(c), a(l instanceof Error ? l : new Error(String(l)));
125
+ n.postMessage({ type: "warmup", requestId: r, options: _t(t) });
126
+ } catch (h) {
127
+ this.pending.delete(r), nt(c), a(h instanceof Error ? h : new Error(String(h)));
128
128
  }
129
129
  });
130
130
  }
@@ -132,148 +132,150 @@ class he {
132
132
  this.resetWorker();
133
133
  }
134
134
  ensureWorker(t) {
135
- return this.worker || (this.worker = le(t), this.worker.onmessage = (r) => this.handleMessage(r.data), this.worker.onerror = (r) => {
136
- const i = r.message || "DWG worker failed.";
137
- this.rejectAll(new Error(i)), this.resetWorker(!1);
135
+ return this.worker || (this.worker = We(t), this.worker.onmessage = (n) => this.handleMessage(n.data), this.worker.onerror = (n) => {
136
+ const r = n.message || "DWG worker failed.";
137
+ this.rejectAll(new Error(r)), this.resetWorker(!1);
138
138
  }, this.worker.onmessageerror = () => {
139
139
  this.rejectAll(new Error("DWG worker returned a message that could not be cloned.")), this.resetWorker(!1);
140
140
  }), this.worker;
141
141
  }
142
142
  handleMessage(t) {
143
- var s, n;
143
+ var i, s;
144
144
  if (t.type === "ready") return;
145
- const r = this.pending.get(t.requestId);
146
- if (!r) return;
145
+ const n = this.pending.get(t.requestId);
146
+ if (!n) return;
147
147
  if (t.type === "progress") {
148
- (s = r.onProgress) == null || s.call(r, t.progress);
148
+ (i = n.onProgress) == null || i.call(n, t.progress);
149
149
  return;
150
150
  }
151
- if (this.pending.delete(t.requestId), $(r), t.type === "result") {
152
- r.resolve(t.result);
151
+ if (this.pending.delete(t.requestId), nt(n), t.type === "result") {
152
+ n.resolve(t.result);
153
153
  return;
154
154
  }
155
155
  if (t.type === "warmup-result") {
156
- (n = r.onProgress) == null || n.call(r, { phase: "worker-ready", format: "dwg", message: "DWG worker warmup complete.", percent: 100, elapsedMs: t.elapsedMs }), r.resolve(void 0);
156
+ (s = n.onProgress) == null || s.call(n, { phase: "worker-ready", format: "dwg", message: "DWG worker warmup complete.", percent: 100, elapsedMs: t.elapsedMs }), n.resolve(void 0);
157
157
  return;
158
158
  }
159
- const i = new Error(t.error.message);
160
- i.name = t.error.name || "DwgWorkerError", t.error.stack && (i.stack = t.error.stack), r.reject(i);
159
+ const r = new Error(t.error.message);
160
+ r.name = t.error.name || "DwgWorkerError", t.error.stack && (r.stack = t.error.stack), n.reject(r);
161
161
  }
162
162
  rejectAll(t) {
163
- for (const [, r] of this.pending)
164
- $(r), r.reject(t);
163
+ for (const [, n] of this.pending)
164
+ nt(n), n.reject(t);
165
165
  this.pending.clear();
166
166
  }
167
167
  resetWorker(t = !0) {
168
- var r;
169
- t && this.rejectAll(new Error("DWG worker was terminated.")), (r = this.worker) == null || r.terminate(), this.worker = void 0;
168
+ var n;
169
+ t && this.rejectAll(new Error("DWG worker was terminated.")), (n = this.worker) == null || n.terminate(), this.worker = void 0;
170
170
  }
171
171
  }
172
- function dt() {
172
+ function xt() {
173
173
  return typeof Worker < "u" && typeof URL < "u";
174
174
  }
175
- function le(e) {
176
- return e.workerFactory ? e.workerFactory() : new Worker(ue(e.workerUrl), { type: "module", name: "lightweight-cad-dwg-loader" });
175
+ function We(e) {
176
+ return e.workerFactory ? e.workerFactory() : new Worker(Ye(e.workerUrl), { type: "module", name: "lightweight-cad-dwg-loader" });
177
177
  }
178
- function Pt(e) {
178
+ function _t(e) {
179
179
  return {
180
180
  // Resolve the asset directory on the UI thread. Relative paths such as
181
181
  // './wasm' must be relative to the document URL, not to the generated
182
182
  // worker chunk URL. Otherwise the worker may request /assets/wasm/... and
183
183
  // receive the app's HTML fallback instead of libredwg-web.wasm.
184
- wasmPath: de(e.wasmPath),
184
+ wasmPath: ze(e.wasmPath),
185
185
  includePaperSpace: e.includePaperSpace,
186
186
  maxInsertDepth: e.maxInsertDepth,
187
187
  keepRaw: !!e.keepRaw
188
188
  };
189
189
  }
190
- function fe(e, t, r) {
191
- return !!t.file || r.transferInputBuffer === !0 ? oe(e) : e.slice().buffer;
190
+ function _e(e, t, n) {
191
+ return !!t.file || n.transferInputBuffer === !0 ? Fe(e) : e.slice().buffer;
192
192
  }
193
- function $(e) {
193
+ function nt(e) {
194
194
  e.timer && clearTimeout(e.timer), e.signal && e.abortHandler && e.signal.removeEventListener("abort", e.abortHandler);
195
195
  }
196
- function j() {
196
+ function rt() {
197
197
  if (typeof DOMException < "u") return new DOMException("DWG loading was aborted.", "AbortError");
198
198
  const e = new Error("DWG loading was aborted.");
199
199
  return e.name = "AbortError", e;
200
200
  }
201
- function de(e) {
201
+ function ze(e) {
202
202
  const t = ((e == null ? void 0 : e.trim()) || "/wasm").replace(/\/+$/, "");
203
- return t === "" ? kt() : Xt(t) ? t : t.startsWith("/") ? `${kt()}${t}` : new URL(t, vt()).href.replace(/\/+$/, "");
203
+ return t === "" ? zt() : oe(t) ? t : t.startsWith("/") ? `${zt()}${t}` : new URL(t, Et()).href.replace(/\/+$/, "");
204
204
  }
205
- function ue(e) {
205
+ function Ye(e) {
206
206
  if (e instanceof URL) return e;
207
- const t = (e == null ? void 0 : e.trim()) || ce;
208
- return Xt(t) ? t : new URL(t, vt()).href;
207
+ const t = (e == null ? void 0 : e.trim()) || Re;
208
+ return oe(t) ? t : new URL(t, Et()).href;
209
209
  }
210
- function vt() {
210
+ function Et() {
211
211
  return typeof document < "u" && document.baseURI ? document.baseURI : typeof location < "u" && location.href ? location.href : "http://localhost/";
212
212
  }
213
- function kt() {
214
- return typeof location < "u" && location.origin ? location.origin : new URL(vt()).origin;
213
+ function zt() {
214
+ return typeof location < "u" && location.origin ? location.origin : new URL(Et()).origin;
215
215
  }
216
- function Xt(e) {
216
+ function oe(e) {
217
217
  return /^[a-z][a-z0-9+.-]*:/i.test(e);
218
218
  }
219
- class me {
219
+ class Xe {
220
220
  constructor(t = {}) {
221
221
  d(this, "id", "dwg");
222
222
  d(this, "label", "DWG / LibreDWG WebAssembly");
223
223
  d(this, "formats", ["dwg"]);
224
224
  d(this, "defaults");
225
- d(this, "workerClient", new he());
225
+ d(this, "workerClient", new Oe());
226
226
  this.defaults = { useWorker: !0, ...t };
227
227
  }
228
- accepts(t, r) {
229
- return L(t) === "dwg" ? !0 : B(t, r) === "dwg";
228
+ accepts(t, n) {
229
+ return z(t) === "dwg" ? !0 : Y(t, n) === "dwg";
230
230
  }
231
- async load(t, r = {}) {
231
+ async load(t, n = {}) {
232
232
  var o, a;
233
- const i = { ...this.defaults, ...r };
234
- (o = i.onProgress) == null || o.call(i, { phase: "read", format: "dwg", message: "Reading DWG bytes…" });
235
- const s = await U(t), n = t.fileName ?? ((a = t.file) == null ? void 0 : a.name);
236
- if (i.useWorker === !1)
233
+ const r = { ...this.defaults, ...n };
234
+ (o = r.onProgress) == null || o.call(r, { phase: "read", format: "dwg", message: "Reading DWG bytes…" });
235
+ const i = await K(t), s = t.fileName ?? ((a = t.file) == null ? void 0 : a.name);
236
+ if (r.useWorker === !1)
237
237
  throw new Error("DWG main-thread parsing is intentionally not bundled by the default viewer. Keep useWorker enabled, or register a custom DWG loader for non-browser runtimes.");
238
- if (!dt())
238
+ if (!xt())
239
239
  throw new Error("DWG loading requires Web Worker support in this build. Provide a custom loader for this runtime.");
240
240
  try {
241
- return await this.workerClient.load(s, t, { ...i, fileName: n });
241
+ return await this.workerClient.load(i, t, { ...r, fileName: s });
242
242
  } catch (c) {
243
- throw pe(c) ? c : ge(c);
243
+ throw Ve(c) ? c : He(c);
244
244
  }
245
245
  }
246
246
  terminateWorker() {
247
247
  this.workerClient.terminate();
248
248
  }
249
249
  preload(t = {}) {
250
- const r = { ...this.defaults, ...t };
251
- return r.useWorker === !1 ? Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")) : this.workerClient.preload(r);
250
+ const n = { ...this.defaults, ...t };
251
+ return n.useWorker === !1 ? Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")) : this.workerClient.preload(n);
252
252
  }
253
253
  }
254
- function pe(e) {
254
+ function Ve(e) {
255
255
  return e instanceof Error && e.name === "AbortError";
256
256
  }
257
- function ge(e) {
257
+ function He(e) {
258
258
  const t = e instanceof Error ? e.message : String(e);
259
259
  return new Error(`${t} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`);
260
260
  }
261
- function Ut(e) {
261
+ function It(e) {
262
262
  return {
263
263
  format: e.format,
264
264
  sourceName: e.sourceName,
265
265
  units: e.units,
266
266
  header: e.header ?? {},
267
267
  layers: e.layers ?? {},
268
+ lineTypes: e.lineTypes ?? {},
268
269
  blocks: e.blocks ?? {},
269
270
  entities: e.entities ?? [],
270
271
  pages: e.pages,
272
+ savedView: e.savedView,
271
273
  metadata: e.metadata ?? {},
272
274
  warnings: e.warnings ?? [],
273
275
  raw: e.raw
274
276
  };
275
277
  }
276
- function R(e) {
278
+ function J(e) {
277
279
  switch (String(e ?? "").toUpperCase()) {
278
280
  case "LINE":
279
281
  return "line";
@@ -324,47 +326,51 @@ function R(e) {
324
326
  return "unsupported";
325
327
  }
326
328
  }
327
- function be(e, t, r = {}) {
328
- const i = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), s = r.includeUnknownProperties === !1 ? { type: i, kind: R(i) } : { ...e, type: i, kind: R(i) };
329
- r.keepRaw && (s.raw = e), s.handle = C(e.handle ?? e.id), s.layer = C(e.layer ?? e.layerName), s.lineType = C(e.lineType ?? e.linetype);
330
- const n = r.numericColorMode ?? "auto", o = y(e.color), a = y(e.colorIndex ?? e.colorNumber ?? e.aci ?? e.aciColor ?? e.color_index);
331
- s.colorIndex = a ?? (n !== "rgb" && o !== void 0 && Math.abs(o) <= 257 ? o : void 0);
332
- const c = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb, h = o !== void 0 && o >= 0 && o <= 16777215 && (n === "rgb" || n === "auto" && Math.abs(o) > 257);
333
- s.trueColor = c ?? (h ? o : void 0), (typeof e.color == "string" || typeof e.color == "number") && (s.color = e.color), s.colorNumber = y(e.colorNumber) ?? s.colorNumber, s.colorName = C(e.colorName ?? e.color_name) ?? s.colorName, s.fillColor = e.fillColor ?? e.fill_color, s.fillColorIndex = y(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? s.fillColorIndex, s.opacity = y(e.opacity ?? e.alpha) ?? s.opacity, s.lineweight = y(e.lineweight ?? e.lineWeight), s.isVisible = !(e.isVisible === !1 || e.visible === !1), s.startPoint = P(e.startPoint ?? e.start ?? e.p0 ?? e.from) ?? s.startPoint, s.endPoint = P(e.endPoint ?? e.end ?? e.p1 ?? e.to) ?? s.endPoint, s.center = P(e.center ?? e.centerPoint) ?? s.center, s.insertionPoint = P(e.insertionPoint ?? e.position ?? e.location ?? e.point ?? e.basePoint) ?? s.insertionPoint, s.radius = y(e.radius) ?? s.radius, s.startAngle = y(e.startAngle ?? e.start_angle) ?? s.startAngle, s.endAngle = y(e.endAngle ?? e.end_angle) ?? s.endAngle, s.majorAxisEndPoint = P(e.majorAxisEndPoint ?? e.majorAxis ?? e.major) ?? s.majorAxisEndPoint, s.axisRatio = y(e.axisRatio ?? e.ratio) ?? s.axisRatio, s.height = y(e.height ?? e.textHeight) ?? s.height, s.textHeight = y(e.textHeight ?? e.height) ?? s.textHeight, s.rotation = y(e.rotation ?? e.angle) ?? s.rotation, s.text = C(e.text ?? e.value ?? e.string ?? e.contents) ?? s.text, s.name = C(e.name ?? e.blockName) ?? s.name, s.blockName = C(e.blockName ?? e.name) ?? s.blockName;
334
- const l = rt(e.vertices ?? e.points);
335
- l.length > 0 && (s.vertices = l);
336
- const f = rt(e.controlPoints ?? e.control_points);
337
- f.length > 0 && (s.controlPoints = f);
338
- const u = rt(e.fitPoints ?? e.fit_points);
339
- return u.length > 0 && (s.fitPoints = u), s;
340
- }
341
- function P(e) {
329
+ function Tt(e, t, n = {}) {
330
+ const r = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), i = n.includeUnknownProperties === !1 ? { type: r, kind: J(r) } : { ...e, type: r, kind: J(r) };
331
+ n.keepRaw && (i.raw = e), i.handle = w(e.handle ?? e.id), i.layer = w(e.layer ?? e.layerName), i.lineType = w(e.lineType ?? e.linetype), i.lineTypeScale = b(e.lineTypeScale ?? e.linetypeScale ?? e.ltscale) ?? i.lineTypeScale, i.flag = b(e.flag ?? e.flags) ?? i.flag;
332
+ const s = e.isClosed === !0 || e.closed === !0 || e.shape === !0, o = /^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D|SPLINE)$/.test(r), a = r === "LWPOLYLINE";
333
+ (s || o && (Number(i.flag ?? 0) & 1) === 1 || a && (Number(i.flag ?? 0) & 512) === 512) && (i.isClosed = !0);
334
+ const c = n.numericColorMode ?? "auto", l = b(e.color), h = b(e.colorIndex ?? e.colorNumber ?? e.aci ?? e.aciColor ?? e.color_index);
335
+ i.colorIndex = h ?? (c !== "rgb" && l !== void 0 && Math.abs(l) <= 257 ? l : void 0);
336
+ const u = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb, f = l !== void 0 && l >= 0 && l <= 16777215 && (c === "rgb" || c === "auto" && Math.abs(l) > 257);
337
+ i.trueColor = u ?? (f ? l : void 0), (typeof e.color == "string" || typeof e.color == "number") && (i.color = e.color), i.colorNumber = b(e.colorNumber) ?? i.colorNumber, i.colorName = w(e.colorName ?? e.color_name) ?? i.colorName, i.fillColor = e.fillColor ?? e.fill_color, i.fillColorIndex = b(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? i.fillColorIndex, i.opacity = b(e.opacity ?? e.alpha) ?? i.opacity, i.lineweight = b(e.lineweight ?? e.lineWeight), i.isVisible = !(e.isVisible === !1 || e.visible === !1), i.startPoint = k(e.startPoint ?? e.start ?? e.p0 ?? e.from) ?? i.startPoint, i.endPoint = k(e.endPoint ?? e.end ?? e.p1 ?? e.to) ?? i.endPoint, i.center = k(e.center ?? e.centerPoint) ?? i.center, i.insertionPoint = k(e.insertionPoint ?? e.position ?? e.location ?? e.point ?? e.basePoint) ?? i.insertionPoint, i.radius = b(e.radius) ?? i.radius, i.startAngle = b(e.startAngle ?? e.start_angle) ?? i.startAngle, i.endAngle = b(e.endAngle ?? e.end_angle) ?? i.endAngle, i.majorAxisEndPoint = k(e.majorAxisEndPoint ?? e.majorAxis ?? e.major) ?? i.majorAxisEndPoint, i.axisRatio = b(e.axisRatio ?? e.ratio) ?? i.axisRatio, i.height = b(e.height ?? e.textHeight) ?? i.height, i.textHeight = b(e.textHeight ?? e.height) ?? i.textHeight, i.rotation = b(e.rotation ?? e.angle) ?? i.rotation, i.text = w(e.text ?? e.value ?? e.string ?? e.contents) ?? i.text, i.name = w(e.name ?? e.blockName) ?? i.name, i.blockName = w(e.blockName ?? e.name) ?? i.blockName;
338
+ const m = ft(e.vertices ?? e.points);
339
+ m.length > 0 && (i.vertices = m);
340
+ const p = ft(e.controlPoints ?? e.control_points);
341
+ p.length > 0 && (i.controlPoints = p);
342
+ const C = ft(e.fitPoints ?? e.fit_points);
343
+ C.length > 0 && (i.fitPoints = C);
344
+ const y = e.attribs ?? e.attributes;
345
+ return Array.isArray(y) && (i.attribs = y.filter((v) => !!v && typeof v == "object").map((v) => Tt(v, void 0, n))), i;
346
+ }
347
+ function k(e) {
342
348
  if (!e || typeof e != "object") return;
343
- const t = e, r = Number(t.x ?? t.X ?? t[0]), i = Number(t.y ?? t.Y ?? t[1]), s = t.z ?? t.Z ?? t[2], n = s === void 0 ? void 0 : Number(s);
344
- if (!(!Number.isFinite(r) || !Number.isFinite(i)))
345
- return Number.isFinite(n) ? { x: r, y: i, z: n } : { x: r, y: i };
349
+ const t = e, n = Number(t.x ?? t.X ?? t[0]), r = Number(t.y ?? t.Y ?? t[1]), i = t.z ?? t.Z ?? t[2], s = i === void 0 ? void 0 : Number(i);
350
+ if (!(!Number.isFinite(n) || !Number.isFinite(r)))
351
+ return Number.isFinite(s) ? { x: n, y: r, z: s } : { x: n, y: r };
346
352
  }
347
- function rt(e) {
353
+ function ft(e) {
348
354
  if (!Array.isArray(e)) return [];
349
355
  const t = [];
350
- for (const r of e) {
351
- const i = P(r);
352
- if (!i) continue;
353
- const s = r, n = i, o = y(s.bulge);
354
- o !== void 0 && (n.bulge = o);
355
- const a = y(s.startWidth ?? s.start_width);
356
- a !== void 0 && (n.startWidth = a);
357
- const c = y(s.endWidth ?? s.end_width);
358
- c !== void 0 && (n.endWidth = c), t.push(n);
356
+ for (const n of e) {
357
+ const r = k(n);
358
+ if (!r) continue;
359
+ const i = n, s = r, o = b(i.bulge);
360
+ o !== void 0 && (s.bulge = o);
361
+ const a = b(i.startWidth ?? i.start_width);
362
+ a !== void 0 && (s.startWidth = a);
363
+ const c = b(i.endWidth ?? i.end_width);
364
+ c !== void 0 && (s.endWidth = c), t.push(s);
359
365
  }
360
366
  return t;
361
367
  }
362
- function G(e) {
363
- var r;
368
+ function it(e) {
369
+ var n;
364
370
  const t = {};
365
- for (const i of e.entities) {
366
- const s = String(i.type ?? "UNKNOWN").toUpperCase();
367
- t[s] = (t[s] ?? 0) + 1;
371
+ for (const r of e.entities) {
372
+ const i = String(r.type ?? "UNKNOWN").toUpperCase();
373
+ t[i] = (t[i] ?? 0) + 1;
368
374
  }
369
375
  return {
370
376
  format: e.format,
@@ -372,98 +378,109 @@ function G(e) {
372
378
  entityCount: e.entities.length,
373
379
  layerCount: Object.keys(e.layers).length,
374
380
  blockCount: Object.keys(e.blocks).length,
375
- pageCount: ((r = e.pages) == null ? void 0 : r.length) ?? 0,
381
+ pageCount: ((n = e.pages) == null ? void 0 : n.length) ?? 0,
376
382
  byType: t,
377
383
  warnings: [...e.warnings]
378
384
  };
379
385
  }
380
- function St(e, t) {
386
+ function ae(e) {
387
+ if (e.isClosed === !0) return !0;
388
+ const t = String(e.type ?? "").toUpperCase(), n = Number(e.flag ?? 0);
389
+ return t === "LWPOLYLINE" ? (n & 512) === 512 : /^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D)$/.test(t) ? (n & 1) === 1 : !1;
390
+ }
391
+ function wt(e, t) {
381
392
  t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
382
393
  }
383
- function ve(e, t) {
394
+ function ce(e, t) {
384
395
  t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
385
396
  }
386
- function ye(e) {
387
- return e != null && e.length ? e.flatMap((t) => t.entities.map((r) => ({ ...r, pageIndex: t.index }))) : [];
397
+ function Ue(e, t) {
398
+ t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t, t.handle && (e[t.handle] = t, e[t.handle.toLowerCase()] = t));
388
399
  }
389
- function y(e) {
400
+ function $e(e) {
401
+ return e != null && e.length ? e.flatMap((t) => t.entities.map((n) => ({ ...n, pageIndex: t.index }))) : [];
402
+ }
403
+ function b(e) {
390
404
  const t = Number(e);
391
405
  return Number.isFinite(t) ? t : void 0;
392
406
  }
393
- function C(e) {
407
+ function w(e) {
394
408
  if (typeof e != "string" && typeof e != "number") return;
395
409
  const t = String(e);
396
410
  return t.length > 0 ? t : void 0;
397
411
  }
398
- function N() {
412
+ function L() {
399
413
  return { minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
400
414
  }
401
- function O(e) {
415
+ function I(e) {
402
416
  return Number.isFinite(e.minX) && Number.isFinite(e.minY) && Number.isFinite(e.maxX) && Number.isFinite(e.maxY) && e.maxX >= e.minX && e.maxY >= e.minY;
403
417
  }
404
- function v(e, t) {
405
- m(t) && (e.minX = Math.min(e.minX, t.x), e.minY = Math.min(e.minY, t.y), e.maxX = Math.max(e.maxX, t.x), e.maxY = Math.max(e.maxY, t.y));
418
+ function S(e, t) {
419
+ g(t) && (e.minX = Math.min(e.minX, t.x), e.minY = Math.min(e.minY, t.y), e.maxX = Math.max(e.maxX, t.x), e.maxY = Math.max(e.maxY, t.y));
420
+ }
421
+ function je(e, t, n) {
422
+ if (!g(t) || !Number.isFinite(n)) return;
423
+ const r = Math.abs(n);
424
+ S(e, { x: t.x - r, y: t.y - r }), S(e, { x: t.x + r, y: t.y + r });
406
425
  }
407
- function Vt(e, t, r) {
408
- if (!m(t) || !Number.isFinite(r)) return;
409
- const i = Math.abs(r);
410
- v(e, { x: t.x - i, y: t.y - i }), v(e, { x: t.x + i, y: t.y + i });
426
+ function le(e, t) {
427
+ I(t) && (S(e, { x: t.minX, y: t.minY }), S(e, { x: t.maxX, y: t.maxY }));
411
428
  }
412
- function $t(e, t = 0.02, r = 1e-6) {
413
- if (!O(e)) return { minX: -10, minY: -10, maxX: 10, maxY: 10 };
414
- const i = Math.max((e.maxX - e.minX) * t, r), s = Math.max((e.maxY - e.minY) * t, r);
415
- return { minX: e.minX - i, minY: e.minY - s, maxX: e.maxX + i, maxY: e.maxY + s };
429
+ function he(e, t = 0.02, n = 1e-6) {
430
+ if (!I(e)) return { minX: -10, minY: -10, maxX: 10, maxY: 10 };
431
+ const r = Math.max((e.maxX - e.minX) * t, n), i = Math.max((e.maxY - e.minY) * t, n);
432
+ return { minX: e.minX - r, minY: e.minY - i, maxX: e.maxX + r, maxY: e.maxY + i };
416
433
  }
417
- function m(e) {
434
+ function g(e) {
418
435
  return !!e && typeof e == "object" && Number.isFinite(e.x) && Number.isFinite(e.y);
419
436
  }
420
- function x(e) {
437
+ function P(e) {
421
438
  return { x: e.x, y: e.y };
422
439
  }
423
- function I(e) {
440
+ function W(e) {
424
441
  return e * Math.PI / 180;
425
442
  }
426
- function K(e, t, r, i, s = !0, n = 64) {
427
- if (!m(e) || !Number.isFinite(t)) return [];
428
- let o = r, a = i;
443
+ function Q(e, t, n, r, i = !0, s = 64) {
444
+ if (!g(e) || !Number.isFinite(t)) return [];
445
+ let o = n, a = r;
429
446
  if (!Number.isFinite(o) || !Number.isFinite(a)) return [];
430
- (Math.abs(o) > Math.PI * 2 + 1e-6 || Math.abs(a) > Math.PI * 2 + 1e-6) && (o = I(o), a = I(a)), s && a < o && (a += Math.PI * 2), !s && o < a && (o += Math.PI * 2);
431
- const c = a - o, h = Math.max(8, Math.min(256, Math.ceil(Math.abs(c) / (Math.PI * 2) * n))), l = [];
432
- for (let f = 0; f <= h; f++) {
433
- const u = o + c * (f / h);
434
- l.push({ x: e.x + Math.cos(u) * t, y: e.y + Math.sin(u) * t });
447
+ (Math.abs(o) > Math.PI * 2 + 1e-6 || Math.abs(a) > Math.PI * 2 + 1e-6) && (o = W(o), a = W(a)), i && a < o && (a += Math.PI * 2), !i && o < a && (o += Math.PI * 2);
448
+ const c = a - o, l = Math.max(8, Math.min(256, Math.ceil(Math.abs(c) / (Math.PI * 2) * s))), h = [];
449
+ for (let u = 0; u <= l; u++) {
450
+ const f = o + c * (u / l);
451
+ h.push({ x: e.x + Math.cos(f) * t, y: e.y + Math.sin(f) * t });
435
452
  }
436
- return l;
453
+ return h;
437
454
  }
438
- function J(e, t, r = 1, i = 0, s = Math.PI * 2, n = 96) {
439
- if (!m(e) || !m(t)) return [];
455
+ function Lt(e, t, n = 1, r = 0, i = Math.PI * 2, s = 96) {
456
+ if (!g(e) || !g(t)) return [];
440
457
  const o = Math.hypot(t.x, t.y);
441
458
  if (!Number.isFinite(o) || o <= 0) return [];
442
- const a = o * (Number.isFinite(r) && r > 0 ? r : 1), c = Math.atan2(t.y, t.x);
443
- let h = Number.isFinite(i) ? i : 0, l = Number.isFinite(s) ? s : Math.PI * 2;
444
- (Math.abs(h) > Math.PI * 2 + 1e-6 || Math.abs(l) > Math.PI * 2 + 1e-6) && (h = I(h), l = I(l)), l < h && (l += Math.PI * 2);
445
- const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(l - h) / (Math.PI * 2) * n))), u = [], p = Math.cos(c), g = Math.sin(c);
446
- for (let S = 0; S <= f; S++) {
447
- const z = h + (l - h) * (S / f), _ = Math.cos(z) * o, H = Math.sin(z) * a;
448
- u.push({ x: e.x + _ * p - H * g, y: e.y + _ * g + H * p });
449
- }
450
- return u;
451
- }
452
- function jt(e, t, r = 0, i = 16) {
453
- if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [x(e), x(t)];
454
- const s = Math.hypot(t.x - e.x, t.y - e.y);
455
- if (s <= 1e-12) return [x(e), x(t)];
456
- const n = 4 * Math.atan(r), o = Math.abs(s / (2 * Math.sin(n / 2))), a = { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 }, c = (t.x - e.x) / s, h = (t.y - e.y) / s, l = r >= 0 ? 1 : -1, f = Math.sqrt(Math.max(o * o - (s / 2) ** 2, 0)), u = { x: a.x - l * h * f, y: a.y + l * c * f }, p = Math.atan2(e.y - u.y, e.x - u.x), g = Math.atan2(t.y - u.y, t.x - u.x);
457
- return K(u, o, p, g, r >= 0, i);
459
+ const a = o * (Number.isFinite(n) && n > 0 ? n : 1), c = Math.atan2(t.y, t.x);
460
+ let l = Number.isFinite(r) ? r : 0, h = Number.isFinite(i) ? i : Math.PI * 2;
461
+ (Math.abs(l) > Math.PI * 2 + 1e-6 || Math.abs(h) > Math.PI * 2 + 1e-6) && (l = W(l), h = W(h)), h < l && (h += Math.PI * 2);
462
+ const u = Math.max(12, Math.min(256, Math.ceil(Math.abs(h - l) / (Math.PI * 2) * s))), f = [], m = Math.cos(c), p = Math.sin(c);
463
+ for (let C = 0; C <= u; C++) {
464
+ const y = l + (h - l) * (C / u), v = Math.cos(y) * o, N = Math.sin(y) * a;
465
+ f.push({ x: e.x + v * m - N * p, y: e.y + v * p + N * m });
466
+ }
467
+ return f;
468
+ }
469
+ function fe(e, t, n = 0, r = 16) {
470
+ if (!Number.isFinite(n) || Math.abs(n) < 1e-12) return [P(e), P(t)];
471
+ const i = Math.hypot(t.x - e.x, t.y - e.y);
472
+ if (i <= 1e-12) return [P(e), P(t)];
473
+ const s = 4 * Math.atan(n), o = Math.abs(i / (2 * Math.sin(s / 2))), a = { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 }, c = (t.x - e.x) / i, l = (t.y - e.y) / i, h = n >= 0 ? 1 : -1, u = Math.sqrt(Math.max(o * o - (i / 2) ** 2, 0)), f = { x: a.x - h * l * u, y: a.y + h * c * u }, m = Math.atan2(e.y - f.y, e.x - f.x), p = Math.atan2(t.y - f.y, t.x - f.x);
474
+ return Q(f, o, m, p, n >= 0, r);
458
475
  }
459
- function Gt(e) {
476
+ function ue(e) {
460
477
  return e.replace(/\\P/g, `
461
478
  `).replace(/\\~|\\ /g, " ").replace(/\\[A-Za-z][^;]*;/g, "").replace(/[{}]/g, "").replace(/\\[A-Za-z]/g, "").trim();
462
479
  }
463
- function A(e, t, r) {
464
- return Math.min(r, Math.max(t, e));
480
+ function _(e, t, n) {
481
+ return Math.min(n, Math.max(t, e));
465
482
  }
466
- class xe {
483
+ class Ge {
467
484
  constructor(t = {}) {
468
485
  d(this, "id", "dxf");
469
486
  d(this, "label", "DXF / JavaScript parser");
@@ -471,138 +488,138 @@ class xe {
471
488
  d(this, "defaults");
472
489
  this.defaults = t;
473
490
  }
474
- accepts(t, r) {
475
- return L(t) === "dxf" || B(t, r) === "dxf";
491
+ accepts(t, n) {
492
+ return z(t) === "dxf" || Y(t, n) === "dxf";
476
493
  }
477
- async load(t, r = {}) {
478
- var f;
479
- const i = { ...this.defaults, ...r }, s = performance.now(), n = await U(t), o = Ee(n, i.dxfEncoding), a = [];
494
+ async load(t, n = {}) {
495
+ var u;
496
+ const r = { ...this.defaults, ...n }, i = performance.now(), s = await K(t), o = nn(s, r.dxfEncoding), a = [];
480
497
  let c;
481
498
  try {
482
- c = await we(o);
483
- } catch (u) {
484
- a.push(`dxf-parser failed, using built-in fallback parser: ${u instanceof Error ? u.message : String(u)}`), c = Fe(o);
499
+ c = await Ze(o);
500
+ } catch (f) {
501
+ a.push(`dxf-parser failed, using built-in fallback parser: ${f instanceof Error ? f.message : String(f)}`), c = ln(o);
485
502
  }
486
- const h = Ce(c, t.fileName ?? ((f = t.file) == null ? void 0 : f.name), a), l = performance.now() - s;
487
- return { document: h, raw: c, bytes: n.byteLength, elapsedMs: l, format: "dxf", warnings: h.warnings };
503
+ const l = qe(c, t.fileName ?? ((u = t.file) == null ? void 0 : u.name), a), h = performance.now() - i;
504
+ return { document: l, raw: c, bytes: s.byteLength, elapsedMs: h, format: "dxf", warnings: l.warnings };
488
505
  }
489
506
  }
490
- async function we(e) {
491
- const t = await import("dxf-parser"), r = t.default ?? t.DxfParser;
492
- if (!r) throw new Error("dxf-parser did not expose a parser constructor.");
493
- return new r().parseSync(e);
507
+ async function Ze(e) {
508
+ const t = await import("dxf-parser"), n = t.default ?? t.DxfParser;
509
+ if (!n) throw new Error("dxf-parser did not expose a parser constructor.");
510
+ return new n().parseSync(e);
494
511
  }
495
- function Ce(e, t, r = []) {
496
- const i = e && typeof e == "object" ? e : {}, s = Pe(i), n = ke(i), a = (Array.isArray(i.entities) ? i.entities : []).filter((h) => !!h && typeof h == "object").map((h) => yt(h)), c = Ut({
512
+ function qe(e, t, n = []) {
513
+ const r = e && typeof e == "object" ? e : {}, i = Ke(r), s = Je(r), a = (Array.isArray(r.entities) ? r.entities : []).filter((l) => !!l && typeof l == "object").map((l) => At(l)), c = It({
497
514
  format: "dxf",
498
515
  sourceName: t,
499
- header: i.header && typeof i.header == "object" ? i.header : {},
500
- layers: s,
501
- blocks: n,
516
+ header: r.header && typeof r.header == "object" ? r.header : {},
517
+ layers: i,
518
+ blocks: s,
502
519
  entities: a,
503
520
  metadata: { parser: "dxf-parser + cad-viewer normalizer" },
504
- warnings: r,
521
+ warnings: n,
505
522
  raw: e
506
523
  });
507
524
  return a.length === 0 && c.warnings.push("DXF file did not expose any ENTITIES."), c;
508
525
  }
509
- function yt(e) {
510
- const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r = be(e, t), i = y(e.colorIndex ?? e.colorNumber ?? e.aci), s = y(e.color);
511
- if (r.colorIndex = i ?? (s !== void 0 && Math.abs(s) <= 257 ? s : void 0), r.trueColor = e.trueColor ?? e.true_color ?? e.colorRGB ?? e.trueColorValue ?? (s !== void 0 && Math.abs(s) > 257 ? s : void 0), r.layer = C(e.layer ?? e.layerName) ?? "0", r.isClosed = !!(e.shape ?? e.closed ?? e.isClosed) || (Number(e.flag ?? e.flags ?? 0) & 1) === 1, t === "LINE" && (r.startPoint = P(e.startPoint ?? { x: e.x1 ?? e.x, y: e.y1 ?? e.y, z: e.z1 ?? e.z }) ?? r.startPoint, r.endPoint = P(e.endPoint ?? { x: e.x2, y: e.y2, z: e.z2 }) ?? r.endPoint), (t === "TEXT" || t === "MTEXT" || t === "ATTRIB" || t === "ATTDEF") && (r.insertionPoint = P(e.startPoint ?? e.position ?? e.insertionPoint) ?? r.insertionPoint, r.text = Be(e.text ?? e.string ?? e.value) ?? r.text, r.textHeight = y(e.textHeight ?? e.height) ?? r.textHeight, r.rotation = Mt(e.rotation ?? e.angle)), (t === "ARC" || t === "ELLIPSE") && (r.startAngle = Et(e.startAngle ?? e.start_angle), r.endAngle = Et(e.endAngle ?? e.end_angle)), t === "INSERT") {
512
- r.blockName = C(e.name ?? e.blockName) ?? r.blockName, r.insertionPoint = P(e.position ?? e.insertionPoint ?? e.point) ?? r.insertionPoint;
513
- const n = y(e.xScale ?? e.scaleX ?? e.xscale), o = y(e.yScale ?? e.scaleY ?? e.yscale), a = y(e.zScale ?? e.scaleZ ?? e.zscale);
514
- (n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation = Mt(e.rotation ?? e.angle);
526
+ function At(e) {
527
+ const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), n = Tt(e, t), r = b(e.colorIndex ?? e.colorNumber ?? e.aci), i = b(e.color);
528
+ if (n.colorIndex = r ?? (i !== void 0 && Math.abs(i) <= 257 ? i : void 0), n.trueColor = e.trueColor ?? e.true_color ?? e.colorRGB ?? e.trueColorValue ?? (i !== void 0 && Math.abs(i) > 257 ? i : void 0), n.layer = w(e.layer ?? e.layerName) ?? "0", n.isClosed = !!(e.shape ?? e.closed ?? e.isClosed) || (Number(e.flag ?? e.flags ?? 0) & 1) === 1, t === "LINE" && (n.startPoint = k(e.startPoint ?? { x: e.x1 ?? e.x, y: e.y1 ?? e.y, z: e.z1 ?? e.z }) ?? n.startPoint, n.endPoint = k(e.endPoint ?? { x: e.x2, y: e.y2, z: e.z2 }) ?? n.endPoint), (t === "TEXT" || t === "MTEXT" || t === "ATTRIB" || t === "ATTDEF") && (n.insertionPoint = k(e.startPoint ?? e.position ?? e.insertionPoint) ?? n.insertionPoint, n.text = cn(e.text ?? e.string ?? e.value) ?? n.text, n.textHeight = b(e.textHeight ?? e.height) ?? n.textHeight, n.rotation = Xt(e.rotation ?? e.angle)), (t === "ARC" || t === "ELLIPSE") && (n.startAngle = Vt(e.startAngle ?? e.start_angle), n.endAngle = Vt(e.endAngle ?? e.end_angle)), t === "INSERT") {
529
+ n.blockName = w(e.name ?? e.blockName) ?? n.blockName, n.insertionPoint = k(e.position ?? e.insertionPoint ?? e.point) ?? n.insertionPoint;
530
+ const s = b(e.xScale ?? e.scaleX ?? e.xscale), o = b(e.yScale ?? e.scaleY ?? e.yscale), a = b(e.zScale ?? e.scaleZ ?? e.zscale);
531
+ (s !== void 0 || o !== void 0 || a !== void 0) && (n.scale = { x: s ?? 1, y: o ?? s ?? 1, z: a ?? 1 }), n.rotation = Xt(e.rotation ?? e.angle);
515
532
  }
516
533
  if (t === "SPLINE") {
517
- const n = Q(e.controlPoints ?? e.control_points ?? e.points);
518
- n.length && (r.controlPoints = n);
519
- const o = Q(e.fitPoints ?? e.fit_points);
520
- o.length && (r.fitPoints = o);
521
- }
522
- return t === "HATCH" && (r.loops = Me(e), r.fillColorIndex = r.colorIndex), (t === "SOLID" || t === "TRACE" || t === "3DFACE") && (r.vertices = Ne(e), r.fillColorIndex = r.colorIndex), r;
523
- }
524
- function Pe(e) {
525
- const t = {}, r = e.tables, i = e.layers ?? (r == null ? void 0 : r.layer) ?? (r == null ? void 0 : r.LAYER) ?? (r == null ? void 0 : r.layers), s = Se(i);
526
- for (const n of s) {
527
- const o = n, a = C(o.name ?? o.layerName);
528
- a && St(t, {
534
+ const s = lt(e.controlPoints ?? e.control_points ?? e.points);
535
+ s.length && (n.controlPoints = s);
536
+ const o = lt(e.fitPoints ?? e.fit_points);
537
+ o.length && (n.fitPoints = o);
538
+ }
539
+ return t === "HATCH" && (n.loops = en(e), n.fillColorIndex = n.colorIndex), (t === "SOLID" || t === "TRACE" || t === "3DFACE") && (n.vertices = tn(e), n.fillColorIndex = n.colorIndex), n;
540
+ }
541
+ function Ke(e) {
542
+ const t = {}, n = e.tables, r = e.layers ?? (n == null ? void 0 : n.layer) ?? (n == null ? void 0 : n.LAYER) ?? (n == null ? void 0 : n.layers), i = Qe(r);
543
+ for (const s of i) {
544
+ const o = s, a = w(o.name ?? o.layerName);
545
+ a && wt(t, {
529
546
  name: a,
530
547
  color: o.color ?? o.colorNumber ?? o.colorIndex,
531
- colorIndex: y(o.colorNumber ?? o.colorIndex ?? o.color),
532
- lineType: C(o.lineType ?? o.linetype),
548
+ colorIndex: b(o.colorNumber ?? o.colorIndex ?? o.color),
549
+ lineType: w(o.lineType ?? o.linetype),
533
550
  isVisible: Number(o.colorNumber ?? o.colorIndex ?? o.color ?? 1) >= 0,
534
551
  isFrozen: !!o.frozen,
535
552
  isLocked: !!o.locked,
536
553
  raw: o
537
554
  });
538
555
  }
539
- return t[0] || St(t, { name: "0", colorIndex: 7, isVisible: !0 }), t;
556
+ return t[0] || wt(t, { name: "0", colorIndex: 7, isVisible: !0 }), t;
540
557
  }
541
- function ke(e) {
542
- const t = {}, r = e.blocks;
543
- if (!r || typeof r != "object") return t;
544
- if (Array.isArray(r))
545
- for (const i of r) Nt(t, i);
558
+ function Je(e) {
559
+ const t = {}, n = e.blocks;
560
+ if (!n || typeof n != "object") return t;
561
+ if (Array.isArray(n))
562
+ for (const r of n) Yt(t, r);
546
563
  else
547
- for (const [i, s] of Object.entries(r)) Nt(t, s, i);
564
+ for (const [r, i] of Object.entries(n)) Yt(t, i, r);
548
565
  return t;
549
566
  }
550
- function Nt(e, t, r) {
567
+ function Yt(e, t, n) {
551
568
  if (!t || typeof t != "object") return;
552
- const i = t, s = C(i.name ?? i.blockName ?? r);
553
- if (!s) return;
554
- const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) => yt(a));
555
- ve(e, { name: s, basePoint: P(i.basePoint ?? i.position) ?? { x: 0, y: 0 }, entities: o, raw: i });
569
+ const r = t, i = w(r.name ?? r.blockName ?? n);
570
+ if (!i) return;
571
+ const o = (Array.isArray(r.entities) ? r.entities : []).filter((a) => !!a && typeof a == "object").map((a) => At(a));
572
+ ce(e, { name: i, basePoint: k(r.basePoint ?? r.position) ?? { x: 0, y: 0 }, entities: o, raw: r });
556
573
  }
557
- function Se(e) {
574
+ function Qe(e) {
558
575
  if (!e) return [];
559
576
  if (Array.isArray(e)) return e;
560
577
  if (typeof e != "object") return [];
561
578
  const t = e;
562
- return Array.isArray(t.entries) ? t.entries : Array.isArray(t.records) ? t.records : Array.isArray(t.layers) ? t.layers : Object.values(t).filter((r) => r && typeof r == "object");
579
+ return Array.isArray(t.entries) ? t.entries : Array.isArray(t.records) ? t.records : Array.isArray(t.layers) ? t.layers : Object.values(t).filter((n) => n && typeof n == "object");
563
580
  }
564
- function Q(e) {
565
- return Array.isArray(e) ? e.map(P).filter((t) => !!t) : [];
581
+ function lt(e) {
582
+ return Array.isArray(e) ? e.map(k).filter((t) => !!t) : [];
566
583
  }
567
- function Ne(e) {
568
- const t = Q(e.vertices ?? e.points);
584
+ function tn(e) {
585
+ const t = lt(e.vertices ?? e.points);
569
586
  if (t.length) return t;
570
- const r = [];
571
- for (let i = 0; i < 4; i++) {
572
- const s = P({ x: e[`x${i}`] ?? e[`x${i + 1}`], y: e[`y${i}`] ?? e[`y${i + 1}`], z: e[`z${i}`] ?? e[`z${i + 1}`] });
573
- s && r.push(s);
587
+ const n = [];
588
+ for (let r = 0; r < 4; r++) {
589
+ const i = k({ x: e[`x${r}`] ?? e[`x${r + 1}`], y: e[`y${r}`] ?? e[`y${r + 1}`], z: e[`z${r}`] ?? e[`z${r + 1}`] });
590
+ i && n.push(i);
574
591
  }
575
- return r;
592
+ return n;
576
593
  }
577
- function Me(e) {
594
+ function en(e) {
578
595
  const t = e.boundaryLoops ?? e.loops ?? e.paths;
579
596
  if (Array.isArray(t))
580
- return t.map((r) => {
581
- const i = r;
582
- return { vertices: Q(i.vertices ?? i.points), isClosed: !0 };
583
- }).filter((r) => r.vertices && r.vertices.length > 0);
597
+ return t.map((n) => {
598
+ const r = n;
599
+ return { vertices: lt(r.vertices ?? r.points), isClosed: !0 };
600
+ }).filter((n) => n.vertices && n.vertices.length > 0);
584
601
  }
585
- function Mt(e) {
586
- const t = y(e);
602
+ function Xt(e) {
603
+ const t = b(e);
587
604
  if (t !== void 0)
588
- return Math.abs(t) > Math.PI * 2 + 1e-6 ? I(t) : t;
605
+ return Math.abs(t) > Math.PI * 2 + 1e-6 ? W(t) : t;
589
606
  }
590
- function Et(e) {
591
- const t = y(e);
607
+ function Vt(e) {
608
+ const t = b(e);
592
609
  if (t !== void 0)
593
- return Math.abs(t) > Math.PI * 2 + 1e-6 ? I(t) : t;
594
- }
595
- function Ee(e, t) {
596
- const r = ut(t);
597
- if (r) return M(e, r);
598
- const i = Ie(e);
599
- if (i) return M(e, i);
600
- const s = ut(Te(e));
601
- if (s) return M(e, s);
602
- const n = M(e, "utf-8");
603
- return n.includes("�") ? Ae(e) : n;
604
- }
605
- const It = {
610
+ return Math.abs(t) > Math.PI * 2 + 1e-6 ? W(t) : t;
611
+ }
612
+ function nn(e, t) {
613
+ const n = Ct(t);
614
+ if (n) return R(e, n);
615
+ const r = rn(e);
616
+ if (r) return R(e, r);
617
+ const i = Ct(sn(e));
618
+ if (i) return R(e, i);
619
+ const s = R(e, "utf-8");
620
+ return s.includes("�") ? on(e) : s;
621
+ }
622
+ const Ht = {
606
623
  ANSI_874: "windows-874",
607
624
  ANSI_932: "shift_jis",
608
625
  ANSI_936: "gb18030",
@@ -647,208 +664,208 @@ const It = {
647
664
  UTF16BE: "utf-16be",
648
665
  UTF_16BE: "utf-16be"
649
666
  };
650
- function Ie(e) {
667
+ function rn(e) {
651
668
  if (e.length >= 3 && e[0] === 239 && e[1] === 187 && e[2] === 191) return "utf-8";
652
669
  if (e.length >= 2 && e[0] === 255 && e[1] === 254) return "utf-16le";
653
670
  if (e.length >= 2 && e[0] === 254 && e[1] === 255) return "utf-16be";
654
671
  }
655
- function Te(e) {
656
- var i, s, n, o;
657
- const r = M(e.subarray(0, Math.min(e.byteLength, 131072)), "iso-8859-1").replace(/\r\n/g, `
672
+ function sn(e) {
673
+ var r, i, s, o;
674
+ const n = R(e.subarray(0, Math.min(e.byteLength, 131072)), "iso-8859-1").replace(/\r\n/g, `
658
675
  `).replace(/\r/g, `
659
676
  `).split(`
660
677
  `);
661
- for (let a = 0; a < r.length - 3; a++)
662
- if (!(((i = r[a]) == null ? void 0 : i.trim()) !== "9" || ((s = r[a + 1]) == null ? void 0 : s.trim().toUpperCase()) !== "$DWGCODEPAGE"))
663
- for (let c = a + 2; c < Math.min(a + 10, r.length - 1); c += 2) {
664
- const h = (n = r[c]) == null ? void 0 : n.trim(), l = (o = r[c + 1]) == null ? void 0 : o.trim();
665
- if (h === "3" && l) return l;
678
+ for (let a = 0; a < n.length - 3; a++)
679
+ if (!(((r = n[a]) == null ? void 0 : r.trim()) !== "9" || ((i = n[a + 1]) == null ? void 0 : i.trim().toUpperCase()) !== "$DWGCODEPAGE"))
680
+ for (let c = a + 2; c < Math.min(a + 10, n.length - 1); c += 2) {
681
+ const l = (s = n[c]) == null ? void 0 : s.trim(), h = (o = n[c + 1]) == null ? void 0 : o.trim();
682
+ if (l === "3" && h) return h;
666
683
  }
667
684
  }
668
- function ut(e) {
685
+ function Ct(e) {
669
686
  const t = e == null ? void 0 : e.trim();
670
687
  if (!t) return;
671
- const r = t.replace(/[-\s]+/g, "_").toUpperCase();
672
- if (It[r]) return It[r];
673
- const i = /^ANSI_(\d{3,4})$/.exec(r);
674
- if (i) return ut(`cp${i[1]}`);
675
- const s = /^CP(\d{3,4})$/.exec(r);
676
- return s ? s[1] === "936" ? "gb18030" : s[1] === "950" ? "big5" : s[1] === "932" ? "shift_jis" : s[1] === "949" ? "euc-kr" : `windows-${s[1]}` : t;
677
- }
678
- function M(e, t) {
688
+ const n = t.replace(/[-\s]+/g, "_").toUpperCase();
689
+ if (Ht[n]) return Ht[n];
690
+ const r = /^ANSI_(\d{3,4})$/.exec(n);
691
+ if (r) return Ct(`cp${r[1]}`);
692
+ const i = /^CP(\d{3,4})$/.exec(n);
693
+ return i ? i[1] === "936" ? "gb18030" : i[1] === "950" ? "big5" : i[1] === "932" ? "shift_jis" : i[1] === "949" ? "euc-kr" : `windows-${i[1]}` : t;
694
+ }
695
+ function R(e, t) {
679
696
  try {
680
697
  return new TextDecoder(t, { fatal: !1 }).decode(e);
681
698
  } catch {
682
699
  return new TextDecoder("utf-8", { fatal: !1 }).decode(e);
683
700
  }
684
701
  }
685
- function Ae(e) {
702
+ function on(e) {
686
703
  const t = ["windows-1252", "gb18030", "big5", "shift_jis", "euc-kr", "iso-8859-1"];
687
- let r = "", i = Number.POSITIVE_INFINITY;
688
- for (const s of t) {
689
- const n = M(e, s), o = Le(n, s);
690
- o < i && (i = o, r = n);
704
+ let n = "", r = Number.POSITIVE_INFINITY;
705
+ for (const i of t) {
706
+ const s = R(e, i), o = an(s, i);
707
+ o < r && (r = o, n = s);
691
708
  }
692
- return r || M(e, "utf-8");
709
+ return n || R(e, "utf-8");
693
710
  }
694
- function Le(e, t) {
695
- const r = it(e, /\uFFFD/g), i = it(e, /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g), s = it(e, /[\u3400-\u9FFF\uF900-\uFAFF]/g), n = e.includes("SECTION") && (e.includes("ENTITIES") || e.includes("HEADER"));
696
- let o = r * 1e4 + i * 1e3;
697
- return n && (o -= 500), t === "windows-1252" && (o -= 2), t === "gb18030" && s >= 2 && (o -= 50 + Math.min(s, 200) * 2), o;
711
+ function an(e, t) {
712
+ const n = ut(e, /\uFFFD/g), r = ut(e, /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g), i = ut(e, /[\u3400-\u9FFF\uF900-\uFAFF]/g), s = e.includes("SECTION") && (e.includes("ENTITIES") || e.includes("HEADER"));
713
+ let o = n * 1e4 + r * 1e3;
714
+ return s && (o -= 500), t === "windows-1252" && (o -= 2), t === "gb18030" && i >= 2 && (o -= 50 + Math.min(i, 200) * 2), o;
698
715
  }
699
- function it(e, t) {
700
- var r;
701
- return ((r = e.match(t)) == null ? void 0 : r.length) ?? 0;
716
+ function ut(e, t) {
717
+ var n;
718
+ return ((n = e.match(t)) == null ? void 0 : n.length) ?? 0;
702
719
  }
703
- function Be(e) {
704
- const t = C(e);
720
+ function cn(e) {
721
+ const t = w(e);
705
722
  if (t !== void 0)
706
- return t.replace(/\\U\+([0-9a-fA-F]{4,6})/g, (r, i) => {
707
- const s = Number.parseInt(i, 16);
708
- return Number.isFinite(s) && s >= 0 && s <= 1114111 ? String.fromCodePoint(s) : r;
723
+ return t.replace(/\\U\+([0-9a-fA-F]{4,6})/g, (n, r) => {
724
+ const i = Number.parseInt(r, 16);
725
+ return Number.isFinite(i) && i >= 0 && i <= 1114111 ? String.fromCodePoint(i) : n;
709
726
  }).replace(/%%[cC]/g, "∅").replace(/%%[dD]/g, "°").replace(/%%[pP]/g, "±").replace(/\\P/g, `
710
727
  `);
711
728
  }
712
- function Fe(e) {
713
- var h, l;
729
+ function ln(e) {
730
+ var l, h;
714
731
  const t = e.replace(/\r\n/g, `
715
732
  `).replace(/\r/g, `
716
733
  `).split(`
717
- `), r = [];
718
- for (let f = 0; f < t.length - 1; f += 2) {
719
- const u = Number((h = t[f]) == null ? void 0 : h.trim()), p = t[f + 1] ?? "";
720
- Number.isFinite(u) && r.push({ code: u, value: p.trimEnd() });
721
- }
722
- const i = [], s = {};
723
- let n = "", o = [], a;
724
- for (let f = 0; f < r.length; f++) {
725
- const u = r[f];
726
- if (u.code === 0 && u.value === "SECTION") {
727
- n = ((l = r[f + 1]) == null ? void 0 : l.code) === 2 ? r[f + 1].value.toUpperCase() : "", f++;
734
+ `), n = [];
735
+ for (let u = 0; u < t.length - 1; u += 2) {
736
+ const f = Number((l = t[u]) == null ? void 0 : l.trim()), m = t[u + 1] ?? "";
737
+ Number.isFinite(f) && n.push({ code: f, value: m.trimEnd() });
738
+ }
739
+ const r = [], i = {};
740
+ let s = "", o = [], a;
741
+ for (let u = 0; u < n.length; u++) {
742
+ const f = n[u];
743
+ if (f.code === 0 && f.value === "SECTION") {
744
+ s = ((h = n[u + 1]) == null ? void 0 : h.code) === 2 ? n[u + 1].value.toUpperCase() : "", u++;
728
745
  continue;
729
746
  }
730
- if (u.code === 0 && u.value === "ENDSEC") {
731
- c(), n = "";
747
+ if (f.code === 0 && f.value === "ENDSEC") {
748
+ c(), s = "";
732
749
  continue;
733
750
  }
734
- n === "ENTITIES" && (u.code === 0 ? (c(), o = [u]) : o.push(u));
751
+ s === "ENTITIES" && (f.code === 0 ? (c(), o = [f]) : o.push(f));
735
752
  }
736
- return c(), { header: {}, tables: {}, entities: i, blocks: s };
753
+ return c(), { header: {}, tables: {}, entities: r, blocks: i };
737
754
  function c() {
738
- var p;
755
+ var m;
739
756
  if (!o.length) return;
740
- const f = (p = o[0]) == null ? void 0 : p.value.toUpperCase();
741
- if (f === "VERTEX" && a) {
742
- const g = w(o, 10, 20, 30);
743
- g && (a.vertices ?? (a.vertices = [])).push({ ...g, bulge: b(o, 42) }), o = [];
757
+ const u = (m = o[0]) == null ? void 0 : m.value.toUpperCase();
758
+ if (u === "VERTEX" && a) {
759
+ const p = M(o, 10, 20, 30);
760
+ p && (a.vertices ?? (a.vertices = [])).push({ ...p, bulge: x(o, 42) }), o = [];
744
761
  return;
745
762
  }
746
- if (f === "SEQEND") {
747
- a && i.push(a), a = void 0, o = [];
763
+ if (u === "SEQEND") {
764
+ a && r.push(a), a = void 0, o = [];
748
765
  return;
749
766
  }
750
- if (a && (i.push(a), a = void 0), !f || f === "EOF") {
767
+ if (a && (r.push(a), a = void 0), !u || u === "EOF") {
751
768
  o = [];
752
769
  return;
753
770
  }
754
- const u = De(f, o);
755
- f === "POLYLINE" ? a = u : i.push(u), o = [];
771
+ const f = hn(u, o);
772
+ u === "POLYLINE" ? a = f : r.push(f), o = [];
756
773
  }
757
774
  }
758
- function De(e, t) {
759
- const r = {
775
+ function hn(e, t) {
776
+ const n = {
760
777
  type: e,
761
- handle: Y(t, 5),
762
- layer: Y(t, 8) ?? "0",
763
- colorIndex: b(t, 62),
764
- trueColor: b(t, 420),
765
- lineType: Y(t, 6),
766
- lineweight: b(t, 370)
778
+ handle: G(t, 5),
779
+ layer: G(t, 8) ?? "0",
780
+ colorIndex: x(t, 62),
781
+ trueColor: x(t, 420),
782
+ lineType: G(t, 6),
783
+ lineweight: x(t, 370)
767
784
  };
768
785
  switch (e) {
769
786
  case "LINE":
770
- Object.assign(r, { startPoint: w(t, 10, 20, 30), endPoint: w(t, 11, 21, 31) });
787
+ Object.assign(n, { startPoint: M(t, 10, 20, 30), endPoint: M(t, 11, 21, 31) });
771
788
  break;
772
789
  case "CIRCLE":
773
- Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40) });
790
+ Object.assign(n, { center: M(t, 10, 20, 30), radius: x(t, 40) });
774
791
  break;
775
792
  case "ARC":
776
- Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40), startAngle: Z(b(t, 50)), endAngle: Z(b(t, 51)) });
793
+ Object.assign(n, { center: M(t, 10, 20, 30), radius: x(t, 40), startAngle: st(x(t, 50)), endAngle: st(x(t, 51)) });
777
794
  break;
778
795
  case "POINT":
779
- Object.assign(r, { point: w(t, 10, 20, 30) });
796
+ Object.assign(n, { point: M(t, 10, 20, 30) });
780
797
  break;
781
798
  case "TEXT":
782
799
  case "MTEXT":
783
- Object.assign(r, { insertionPoint: w(t, 10, 20, 30), text: Oe(t), textHeight: b(t, 40), rotation: Z(b(t, 50)) });
800
+ Object.assign(n, { insertionPoint: M(t, 10, 20, 30), text: dn(t), textHeight: x(t, 40), rotation: st(x(t, 50)) });
784
801
  break;
785
802
  case "LWPOLYLINE":
786
- Object.assign(r, { vertices: Re(t), flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
803
+ Object.assign(n, { vertices: un(t), flag: x(t, 70), isClosed: (Number(x(t, 70) ?? 0) & 1) === 1 });
787
804
  break;
788
805
  case "POLYLINE":
789
- Object.assign(r, { vertices: [], flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
806
+ Object.assign(n, { vertices: [], flag: x(t, 70), isClosed: (Number(x(t, 70) ?? 0) & 1) === 1 });
790
807
  break;
791
808
  case "ELLIPSE":
792
- Object.assign(r, { center: w(t, 10, 20, 30), majorAxisEndPoint: w(t, 11, 21, 31), axisRatio: b(t, 40), startAngle: b(t, 41), endAngle: b(t, 42) });
809
+ Object.assign(n, { center: M(t, 10, 20, 30), majorAxisEndPoint: M(t, 11, 21, 31), axisRatio: x(t, 40), startAngle: x(t, 41), endAngle: x(t, 42) });
793
810
  break;
794
811
  case "SPLINE":
795
- Object.assign(r, { controlPoints: We(t, 10, 20, 30), degree: b(t, 71), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
812
+ Object.assign(n, { controlPoints: fn(t, 10, 20, 30), degree: x(t, 71), isClosed: (Number(x(t, 70) ?? 0) & 1) === 1 });
796
813
  break;
797
814
  case "INSERT":
798
- Object.assign(r, { name: Y(t, 2), blockName: Y(t, 2), insertionPoint: w(t, 10, 20, 30), rotation: Z(b(t, 50)), scale: { x: b(t, 41) ?? 1, y: b(t, 42) ?? b(t, 41) ?? 1, z: b(t, 43) ?? 1 } });
815
+ Object.assign(n, { name: G(t, 2), blockName: G(t, 2), insertionPoint: M(t, 10, 20, 30), rotation: st(x(t, 50)), scale: { x: x(t, 41) ?? 1, y: x(t, 42) ?? x(t, 41) ?? 1, z: x(t, 43) ?? 1 } });
799
816
  break;
800
817
  case "SOLID":
801
818
  case "TRACE":
802
819
  case "3DFACE":
803
- Object.assign(r, { vertices: [w(t, 10, 20, 30), w(t, 11, 21, 31), w(t, 12, 22, 32), w(t, 13, 23, 33)].filter(Boolean) });
820
+ Object.assign(n, { vertices: [M(t, 10, 20, 30), M(t, 11, 21, 31), M(t, 12, 22, 32), M(t, 13, 23, 33)].filter(Boolean) });
804
821
  break;
805
822
  }
806
- return yt(r);
823
+ return At(n);
807
824
  }
808
- function b(e, t) {
809
- var s;
810
- const r = (s = e.find((n) => n.code === t)) == null ? void 0 : s.value, i = Number(r);
811
- return Number.isFinite(i) ? i : void 0;
812
- }
813
- function Y(e, t) {
825
+ function x(e, t) {
814
826
  var i;
815
- const r = (i = e.find((s) => s.code === t)) == null ? void 0 : i.value;
816
- return r && r.length > 0 ? r : void 0;
827
+ const n = (i = e.find((s) => s.code === t)) == null ? void 0 : i.value, r = Number(n);
828
+ return Number.isFinite(r) ? r : void 0;
817
829
  }
818
- function w(e, t, r, i) {
819
- const s = b(e, t), n = b(e, r), o = b(e, i);
820
- if (!(s === void 0 || n === void 0))
821
- return o === void 0 ? { x: s, y: n } : { x: s, y: n, z: o };
830
+ function G(e, t) {
831
+ var r;
832
+ const n = (r = e.find((i) => i.code === t)) == null ? void 0 : r.value;
833
+ return n && n.length > 0 ? n : void 0;
822
834
  }
823
- function We(e, t, r, i) {
824
- const s = [];
825
- for (let n = 0; n < e.length; n++) {
826
- if (e[n].code !== t) continue;
827
- const o = Number(e[n].value), a = e.slice(n + 1).find((f) => f.code === r), c = e.slice(n + 1).find((f) => f.code === i), h = Number(a == null ? void 0 : a.value), l = Number(c == null ? void 0 : c.value);
828
- Number.isFinite(o) && Number.isFinite(h) && s.push(Number.isFinite(l) ? { x: o, y: h, z: l } : { x: o, y: h });
835
+ function M(e, t, n, r) {
836
+ const i = x(e, t), s = x(e, n), o = x(e, r);
837
+ if (!(i === void 0 || s === void 0))
838
+ return o === void 0 ? { x: i, y: s } : { x: i, y: s, z: o };
839
+ }
840
+ function fn(e, t, n, r) {
841
+ const i = [];
842
+ for (let s = 0; s < e.length; s++) {
843
+ if (e[s].code !== t) continue;
844
+ const o = Number(e[s].value), a = e.slice(s + 1).find((u) => u.code === n), c = e.slice(s + 1).find((u) => u.code === r), l = Number(a == null ? void 0 : a.value), h = Number(c == null ? void 0 : c.value);
845
+ Number.isFinite(o) && Number.isFinite(l) && i.push(Number.isFinite(h) ? { x: o, y: l, z: h } : { x: o, y: l });
829
846
  }
830
- return s;
847
+ return i;
831
848
  }
832
- function Re(e) {
849
+ function un(e) {
833
850
  const t = [];
834
- for (let r = 0; r < e.length; r++) {
835
- if (e[r].code !== 10) continue;
836
- const i = Number(e[r].value);
837
- let s, n;
838
- for (let o = r + 1; o < e.length && e[o].code !== 10; o++)
839
- e[o].code === 20 && (s = Number(e[o].value)), e[o].code === 42 && (n = Number(e[o].value));
840
- Number.isFinite(i) && Number.isFinite(s) && t.push({ x: i, y: s, bulge: Number.isFinite(n) ? n : void 0 });
851
+ for (let n = 0; n < e.length; n++) {
852
+ if (e[n].code !== 10) continue;
853
+ const r = Number(e[n].value);
854
+ let i, s;
855
+ for (let o = n + 1; o < e.length && e[o].code !== 10; o++)
856
+ e[o].code === 20 && (i = Number(e[o].value)), e[o].code === 42 && (s = Number(e[o].value));
857
+ Number.isFinite(r) && Number.isFinite(i) && t.push({ x: r, y: i, bulge: Number.isFinite(s) ? s : void 0 });
841
858
  }
842
859
  return t;
843
860
  }
844
- function Oe(e) {
845
- const t = e.filter((r) => r.code === 1 || r.code === 3).map((r) => r.value);
861
+ function dn(e) {
862
+ const t = e.filter((n) => n.code === 1 || n.code === 3).map((n) => n.value);
846
863
  return t.length ? t.join("") : void 0;
847
864
  }
848
- function Z(e) {
849
- return typeof e == "number" && Number.isFinite(e) ? I(e) : void 0;
865
+ function st(e) {
866
+ return typeof e == "number" && Number.isFinite(e) ? W(e) : void 0;
850
867
  }
851
- class ze {
868
+ class mn {
852
869
  constructor(t = {}) {
853
870
  d(this, "id", "dwf");
854
871
  d(this, "label", "DWF/DWFx native viewer powered by dwf-viewer");
@@ -860,32 +877,32 @@ class ze {
860
877
  d(this, "lastStats");
861
878
  this.defaults = t;
862
879
  }
863
- accepts(t, r) {
864
- const i = L(t);
865
- if (i === "dwf" || i === "dwfx" || i === "xps") return !0;
866
- const s = B(t, r);
867
- return s === "dwf" || s === "dwfx" || s === "xps";
868
- }
869
- async load(t, r = {}) {
870
- var f, u, p, g;
871
- const i = { ...this.defaults, ...r }, s = performance.now(), n = t.fileName ?? ((f = t.file) == null ? void 0 : f.name), o = await U(t), a = Lt(B(t, o), L(t));
872
- (u = i.onProgress) == null || u.call(i, { phase: "parse", format: a, message: "Opening DWF/DWFx with dwf-viewer…", percent: 48 });
873
- const c = await se(o, { fileName: n });
874
- (p = i.onProgress) == null || p.call(i, { phase: "normalize", format: a, message: "Reading DWF pages, sheets and model metadata…", percent: 76 });
875
- const h = Tt(c, n, a, i.keepRaw === !0), l = performance.now() - s;
876
- return (g = i.onProgress) == null || g.call(i, { phase: "done", format: h.format, message: "DWF/DWFx document ready.", percent: 100, elapsedMs: l }), { document: h, raw: i.keepRaw ? c : void 0, bytes: o.byteLength, elapsedMs: l, format: h.format, warnings: h.warnings };
877
- }
878
- async mount(t, r, i = {}) {
879
- var z, _, H, xt, wt;
880
- const s = { ...this.defaults, ...i }, n = performance.now(), o = t.fileName ?? ((z = t.file) == null ? void 0 : z.name), a = await U(t), c = Lt(B(t, a), L(t)), h = Ue(s), l = Bt(s), f = Ve(s, h, l), u = Zt(s, h, l);
881
- (_ = s.onProgress) == null || _.call(s, { phase: "native-render", format: c, message: "Mounting native DWF renderer…", percent: 28 }), this.unmount(), this.host = r, r.replaceChildren(), this.native = new ne(r, f), (H = s.onProgress) == null || H.call(s, { phase: "parse", format: c, message: "Parsing DWF package and page streams…", percent: 58 }), await this.native.load(a, {
880
+ accepts(t, n) {
881
+ const r = z(t);
882
+ if (r === "dwf" || r === "dwfx" || r === "xps") return !0;
883
+ const i = Y(t, n);
884
+ return i === "dwf" || i === "dwfx" || i === "xps";
885
+ }
886
+ async load(t, n = {}) {
887
+ var u, f, m, p;
888
+ const r = { ...this.defaults, ...n }, i = performance.now(), s = t.fileName ?? ((u = t.file) == null ? void 0 : u.name), o = await K(t), a = jt(Y(t, o), z(t));
889
+ (f = r.onProgress) == null || f.call(r, { phase: "parse", format: a, message: "Opening DWF/DWFx with dwf-viewer…", percent: 48 });
890
+ const c = await Ae(o, { fileName: s });
891
+ (m = r.onProgress) == null || m.call(r, { phase: "normalize", format: a, message: "Reading DWF pages, sheets and model metadata…", percent: 76 });
892
+ const l = Ut(c, s, a, r.keepRaw === !0), h = performance.now() - i;
893
+ return (p = r.onProgress) == null || p.call(r, { phase: "done", format: l.format, message: "DWF/DWFx document ready.", percent: 100, elapsedMs: h }), { document: l, raw: r.keepRaw ? c : void 0, bytes: o.byteLength, elapsedMs: h, format: l.format, warnings: l.warnings };
894
+ }
895
+ async mount(t, n, r = {}) {
896
+ var y, v, N, A, T;
897
+ const i = { ...this.defaults, ...r }, s = performance.now(), o = t.fileName ?? ((y = t.file) == null ? void 0 : y.name), a = await K(t), c = jt(Y(t, a), z(t)), l = vn(i), h = Gt(i), u = xn(i, l, h), f = de(i, l, h);
898
+ (v = i.onProgress) == null || v.call(i, { phase: "native-render", format: c, message: "Mounting native DWF renderer…", percent: 28 }), this.unmount(), this.host = n, n.replaceChildren(), this.native = new Be(n, u), (N = i.onProgress) == null || N.call(i, { phase: "parse", format: c, message: "Parsing DWF package and page streams…", percent: 58 }), await this.native.load(a, {
882
899
  fileName: o,
883
- ...u
884
- }), (xt = s.onProgress) == null || xt.call(s, { phase: "render", format: c, message: "Rendering DWF/DWFx with dwf-viewer…", percent: 88 }), this.lastStats = await this.native.render();
885
- const p = this.native.getDocument(), g = Tt(p, o, c, s.keepRaw === !0);
886
- g.metadata.loaderMode = "Native DWF", g.metadata.nativeRenderer = "dwf-viewer", g.metadata.nativeRenderStats = this.lastStats ? { ...this.lastStats, warnings: this.lastStats.warnings.length } : void 0;
887
- const S = performance.now() - n;
888
- return (wt = s.onProgress) == null || wt.call(s, { phase: "done", format: g.format, message: "DWF/DWFx rendered.", percent: 100, elapsedMs: S }), { document: g, raw: s.keepRaw ? p : void 0, bytes: a.byteLength, elapsedMs: S, format: g.format, warnings: g.warnings };
900
+ ...f
901
+ }), (A = i.onProgress) == null || A.call(i, { phase: "render", format: c, message: "Rendering DWF/DWFx with dwf-viewer…", percent: 88 }), this.lastStats = await this.native.render();
902
+ const m = this.native.getDocument(), p = Ut(m, o, c, i.keepRaw === !0);
903
+ p.metadata.loaderMode = "Native DWF", p.metadata.nativeRenderer = "dwf-viewer", p.metadata.nativeRenderStats = this.lastStats ? { ...this.lastStats, warnings: this.lastStats.warnings.length } : void 0;
904
+ const C = performance.now() - s;
905
+ return (T = i.onProgress) == null || T.call(i, { phase: "done", format: p.format, message: "DWF/DWFx rendered.", percent: 100, elapsedMs: C }), { document: p, raw: i.keepRaw ? m : void 0, bytes: a.byteLength, elapsedMs: C, format: p.format, warnings: p.warnings };
889
906
  }
890
907
  unmount() {
891
908
  var t;
@@ -896,13 +913,13 @@ class ze {
896
913
  (t = this.native) == null || t.fit();
897
914
  }
898
915
  zoomIn() {
899
- var r;
900
- const t = (r = this.native) == null ? void 0 : r.zoomInButton;
916
+ var n;
917
+ const t = (n = this.native) == null ? void 0 : n.zoomInButton;
901
918
  t == null || t.click();
902
919
  }
903
920
  zoomOut() {
904
- var r;
905
- const t = (r = this.native) == null ? void 0 : r.zoomOutButton;
921
+ var n;
922
+ const t = (n = this.native) == null ? void 0 : n.zoomOutButton;
906
923
  t == null || t.click();
907
924
  }
908
925
  resize() {
@@ -910,70 +927,70 @@ class ze {
910
927
  (t = this.native) == null || t.render();
911
928
  }
912
929
  setNativeOptions(t) {
913
- var i, s, n, o;
914
- const r = this.native;
915
- if (r) {
916
- if (typeof t.dwfBackground == "string") r.background = t.dwfBackground;
930
+ var r, i, s, o;
931
+ const n = this.native;
932
+ if (n) {
933
+ if (typeof t.dwfBackground == "string") n.background = t.dwfBackground;
917
934
  else {
918
- const a = Bt(t);
919
- a && (r.background = a);
935
+ const a = Gt(t);
936
+ a && (n.background = a);
920
937
  }
921
- typeof t.dwfPreferWebgl == "boolean" && ((i = r.setPreferWebgl) == null || i.call(r, t.dwfPreferWebgl)), typeof t.dwfPreferWasm == "boolean" && ((s = r.setPreferWasm) == null || s.call(r, t.dwfPreferWasm)), t.dwfLineWeightMode && ((n = r.setLineWeightMode) == null || n.call(r, t.dwfLineWeightMode)), q(r, "minStrokeCssPx", t.dwfMinStrokeCssPx), q(r, "maxOverviewStrokeCssPx", t.dwfMaxOverviewStrokeCssPx), q(r, "minTextCssPx", t.dwfMinTextCssPx), q(r, "minFilledAreaCssPx", t.dwfMinFilledAreaCssPx), (o = r.render) == null || o.call(r);
938
+ typeof t.dwfPreferWebgl == "boolean" && ((r = n.setPreferWebgl) == null || r.call(n, t.dwfPreferWebgl)), typeof t.dwfPreferWasm == "boolean" && ((i = n.setPreferWasm) == null || i.call(n, t.dwfPreferWasm)), t.dwfLineWeightMode && ((s = n.setLineWeightMode) == null || s.call(n, t.dwfLineWeightMode)), ot(n, "minStrokeCssPx", t.dwfMinStrokeCssPx), ot(n, "maxOverviewStrokeCssPx", t.dwfMaxOverviewStrokeCssPx), ot(n, "minTextCssPx", t.dwfMinTextCssPx), ot(n, "minFilledAreaCssPx", t.dwfMinFilledAreaCssPx), (o = n.render) == null || o.call(n);
922
939
  }
923
940
  }
924
941
  getLastNativeStats() {
925
942
  return this.lastStats;
926
943
  }
927
944
  }
928
- function Tt(e, t, r, i) {
945
+ function Ut(e, t, n, r) {
929
946
  var a, c;
930
- const s = At((e == null ? void 0 : e.diagnostics) ?? []), n = ((e == null ? void 0 : e.pageData) ?? []).map((h, l) => _e(h, l));
931
- for (const h of (e == null ? void 0 : e.pageData) ?? []) s.push(...At(h.diagnostics));
947
+ const i = $t((e == null ? void 0 : e.diagnostics) ?? []), s = ((e == null ? void 0 : e.pageData) ?? []).map((l, h) => pn(l, h));
948
+ for (const l of (e == null ? void 0 : e.pageData) ?? []) i.push(...$t(l.diagnostics));
932
949
  const o = {
933
950
  parser: "dwf-viewer",
934
951
  nativeRenderer: "dwf-viewer",
935
952
  dwfKind: e == null ? void 0 : e.kind,
936
953
  packageEntries: ((a = e == null ? void 0 : e.packageEntries) == null ? void 0 : a.length) ?? 0,
937
954
  resources: ((c = e == null ? void 0 : e.resources) == null ? void 0 : c.length) ?? 0,
938
- pageKinds: Ge(((e == null ? void 0 : e.pageData) ?? []).map((h) => h.kind)),
939
- pageNames: ((e == null ? void 0 : e.pages) ?? []).map((h) => h.name)
955
+ pageKinds: Pn(((e == null ? void 0 : e.pageData) ?? []).map((l) => l.kind)),
956
+ pageNames: ((e == null ? void 0 : e.pages) ?? []).map((l) => l.name)
940
957
  };
941
- return Ut({
942
- format: r,
958
+ return It({
959
+ format: n,
943
960
  sourceName: t,
944
961
  layers: {},
945
962
  blocks: {},
946
- pages: n,
947
- entities: ye(n),
963
+ pages: s,
964
+ entities: $e(s),
948
965
  metadata: o,
949
- warnings: Ze(s),
950
- raw: i ? e : void 0
966
+ warnings: kn(i),
967
+ raw: r ? e : void 0
951
968
  });
952
969
  }
953
- function _e(e, t) {
954
- const r = He(e, t);
970
+ function pn(e, t) {
971
+ const n = gn(e, t);
955
972
  return {
956
973
  index: t,
957
974
  name: e.name || e.sourcePath || `${t + 1}`,
958
975
  width: e.width || 1e3,
959
976
  height: e.height || 1e3,
960
- entities: r
977
+ entities: n
961
978
  };
962
979
  }
963
- function He(e, t) {
964
- return e.kind === "w2d-text" ? e.primitives.flatMap((r, i) => Ye(r, t, i)) : e.kind === "image" ? [{ type: "DWF_IMAGE_PAGE", kind: "image", pageIndex: t, width: e.width, height: e.height, imageSource: e.sourcePath }] : e.kind === "w3d-model" ? e.model.meshes.map((r, i) => ({
965
- id: r.id,
980
+ function gn(e, t) {
981
+ return e.kind === "w2d-text" ? e.primitives.flatMap((n, r) => bn(n, t, r)) : e.kind === "image" ? [{ type: "DWF_IMAGE_PAGE", kind: "image", pageIndex: t, width: e.width, height: e.height, imageSource: e.sourcePath }] : e.kind === "w3d-model" ? e.model.meshes.map((n, r) => ({
982
+ id: n.id,
966
983
  type: "W3D_MESH",
967
984
  kind: "solid",
968
985
  pageIndex: t,
969
- color: r.color ? je(r.color) : void 0,
970
- name: r.name || `mesh-${i + 1}`,
971
- raw: { vertexCount: r.vertexCount, triangleCount: r.triangleCount, materialId: r.materialId }
986
+ color: n.color ? Cn(n.color) : void 0,
987
+ name: n.name || `mesh-${r + 1}`,
988
+ raw: { vertexCount: n.vertexCount, triangleCount: n.triangleCount, materialId: n.materialId }
972
989
  })) : e.kind === "xps-fixed-page" ? [{ type: "XPS_FIXED_PAGE", kind: "viewport", pageIndex: t, width: e.width, height: e.height, raw: { sourcePath: e.sourcePath } }] : [{ type: "DWF_PAGE", kind: "viewport", pageIndex: t, width: e.width, height: e.height, raw: { sourcePath: e.sourcePath } }];
973
990
  }
974
- function Ye(e, t, r) {
975
- const i = {
976
- id: `dwf-${t}-${r}`,
991
+ function bn(e, t, n) {
992
+ const r = {
993
+ id: `dwf-${t}-${n}`,
977
994
  pageIndex: t,
978
995
  color: e.stroke,
979
996
  fillColor: e.fill,
@@ -982,17 +999,17 @@ function Ye(e, t, r) {
982
999
  };
983
1000
  if (e.type === "polyline" || e.type === "polygon")
984
1001
  return [{
985
- ...i,
1002
+ ...r,
986
1003
  type: e.type === "polygon" ? "DWF_POLYGON" : "DWF_POLYLINE",
987
1004
  kind: "polyline",
988
- vertices: Xe(e.points),
1005
+ vertices: yn(e.points),
989
1006
  isClosed: e.type === "polygon"
990
1007
  }];
991
1008
  if (e.type === "path")
992
- return [{ ...i, type: "DWF_PATH", kind: "path", commands: e.commands }];
1009
+ return [{ ...r, type: "DWF_PATH", kind: "path", commands: e.commands }];
993
1010
  if (e.type === "text")
994
1011
  return [{
995
- ...i,
1012
+ ...r,
996
1013
  type: "DWF_TEXT",
997
1014
  kind: "text",
998
1015
  insertionPoint: { x: e.x, y: e.y, z: 0 },
@@ -1000,57 +1017,57 @@ function Ye(e, t, r) {
1000
1017
  textHeight: e.size
1001
1018
  }];
1002
1019
  if (e.type === "rect") {
1003
- const s = e.x, n = e.y, o = e.width, a = e.height;
1020
+ const i = e.x, s = e.y, o = e.width, a = e.height;
1004
1021
  return [{
1005
- ...i,
1022
+ ...r,
1006
1023
  type: "DWF_RECT",
1007
1024
  kind: "polyline",
1008
1025
  isClosed: !0,
1009
1026
  vertices: [
1010
- { x: s, y: n, z: 0 },
1011
- { x: s + o, y: n, z: 0 },
1012
- { x: s + o, y: n + a, z: 0 },
1013
- { x: s, y: n + a, z: 0 }
1027
+ { x: i, y: s, z: 0 },
1028
+ { x: i + o, y: s, z: 0 },
1029
+ { x: i + o, y: s + a, z: 0 },
1030
+ { x: i, y: s + a, z: 0 }
1014
1031
  ]
1015
1032
  }];
1016
1033
  }
1017
1034
  return [];
1018
1035
  }
1019
- function Xe(e) {
1036
+ function yn(e) {
1020
1037
  const t = [];
1021
- for (let r = 0; r + 1 < e.length; r += 2) t.push({ x: e[r], y: e[r + 1], z: 0 });
1038
+ for (let n = 0; n + 1 < e.length; n += 2) t.push({ x: e[n], y: e[n + 1], z: 0 });
1022
1039
  return t;
1023
1040
  }
1024
- function At(e) {
1041
+ function $t(e) {
1025
1042
  return e.filter((t) => t.level !== "info").map((t) => `${t.code}: ${t.message}${t.source ? ` (${t.source})` : ""}`);
1026
1043
  }
1027
- function Lt(e, t) {
1044
+ function jt(e, t) {
1028
1045
  return t === "dwf" || t === "dwfx" || t === "xps" ? t : e === "dwf" || e === "dwfx" || e === "xps" ? e : "dwf";
1029
1046
  }
1030
- function Ue(e) {
1047
+ function vn(e) {
1031
1048
  if (e.dwfWasmUrl) return e.dwfWasmUrl;
1032
1049
  if (typeof document > "u") return;
1033
- const t = e.wasmPath ? new URL($e(e.wasmPath), document.baseURI).href : new URL("wasm/", document.baseURI).href;
1050
+ const t = e.wasmPath ? new URL(wn(e.wasmPath), document.baseURI).href : new URL("wasm/", document.baseURI).href;
1034
1051
  return new URL("dwfv-render.wasm", t).href;
1035
1052
  }
1036
- function Bt(e) {
1053
+ function Gt(e) {
1037
1054
  if (e.dwfBackground) return e.dwfBackground;
1038
1055
  const t = e.canvasOptions;
1039
1056
  return (t == null ? void 0 : t.background) ?? "#05070d";
1040
1057
  }
1041
- function Ve(e, t, r) {
1058
+ function xn(e, t, n) {
1042
1059
  return {
1043
- ...Zt(e, t, r),
1060
+ ...de(e, t, n),
1044
1061
  maxDevicePixelRatio: e.dwfMaxDevicePixelRatio ?? 2,
1045
1062
  maxCanvasPixels: e.dwfMaxCanvasPixels ?? 16777216
1046
1063
  };
1047
1064
  }
1048
- function Zt(e, t, r) {
1065
+ function de(e, t, n) {
1049
1066
  return {
1050
1067
  wasmUrl: t,
1051
1068
  preferWebgl: e.dwfPreferWebgl ?? !0,
1052
1069
  preferWasm: e.dwfPreferWasm ?? !0,
1053
- background: r,
1070
+ background: n,
1054
1071
  maxGpuCacheBytes: e.dwfMaxGpuCacheBytes ?? 160 * 1024 * 1024,
1055
1072
  maxCachedScenes: e.dwfMaxCachedScenes ?? 2,
1056
1073
  lineWeightMode: e.dwfLineWeightMode ?? "adaptive",
@@ -1060,39 +1077,39 @@ function Zt(e, t, r) {
1060
1077
  minFilledAreaCssPx: e.dwfMinFilledAreaCssPx
1061
1078
  };
1062
1079
  }
1063
- function q(e, t, r) {
1064
- typeof r == "number" && Number.isFinite(r) && (e[t] = r);
1080
+ function ot(e, t, n) {
1081
+ typeof n == "number" && Number.isFinite(n) && (e[t] = n);
1065
1082
  }
1066
- function $e(e) {
1083
+ function wn(e) {
1067
1084
  return e.endsWith("/") ? e : `${e}/`;
1068
1085
  }
1069
- function je(e) {
1070
- const [t, r, i] = e.map((s) => Math.max(0, Math.min(255, Math.round(s * 255))));
1071
- return `#${st(t)}${st(r)}${st(i)}`;
1086
+ function Cn(e) {
1087
+ const [t, n, r] = e.map((i) => Math.max(0, Math.min(255, Math.round(i * 255))));
1088
+ return `#${dt(t)}${dt(n)}${dt(r)}`;
1072
1089
  }
1073
- function st(e) {
1090
+ function dt(e) {
1074
1091
  return e.toString(16).padStart(2, "0");
1075
1092
  }
1076
- function Ge(e) {
1093
+ function Pn(e) {
1077
1094
  const t = {};
1078
- for (const r of e) t[r] = (t[r] ?? 0) + 1;
1095
+ for (const n of e) t[n] = (t[n] ?? 0) + 1;
1079
1096
  return t;
1080
1097
  }
1081
- function Ze(e) {
1098
+ function kn(e) {
1082
1099
  return Array.from(new Set(e));
1083
1100
  }
1084
- function qe(e = {}) {
1085
- return new ae([
1086
- new me(e),
1087
- new xe(e),
1088
- new ze(e)
1101
+ function Sn(e = {}) {
1102
+ return new De([
1103
+ new Xe(e),
1104
+ new Ge(e),
1105
+ new mn(e)
1089
1106
  ]);
1090
1107
  }
1091
- function Ke(e) {
1108
+ function Nn(e) {
1092
1109
  const t = e;
1093
1110
  return t.nativeRenderer === !0 && typeof t.mount == "function";
1094
1111
  }
1095
- const Je = {
1112
+ const Mn = {
1096
1113
  1: "#ff0000",
1097
1114
  2: "#ffff00",
1098
1115
  3: "#00ff00",
@@ -1348,19 +1365,19 @@ const Je = {
1348
1365
  254: "#bebebe",
1349
1366
  255: "#ffffff"
1350
1367
  };
1351
- function E(e, t = "#ffffff", r = t) {
1368
+ function O(e, t = "#ffffff", n = t) {
1352
1369
  if (typeof e != "number" || Number.isNaN(e)) return t;
1353
- const i = Math.abs(Math.trunc(e));
1354
- return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r : Je[i] ?? t;
1370
+ const r = Math.abs(Math.trunc(e));
1371
+ return r === 0 || r === 256 || r === 257 ? t : r === 7 ? n : Mn[r] ?? t;
1355
1372
  }
1356
- function V(e, t = "rgb") {
1357
- const r = Math.max(0, Math.trunc(e)) & 16777215, i = r >> 16 & 255, s = r >> 8 & 255, n = r & 255;
1358
- return `rgb(${t === "rgb" ? i : n}, ${s}, ${t === "rgb" ? n : i})`;
1373
+ function tt(e, t = "rgb") {
1374
+ const n = Math.max(0, Math.trunc(e)) & 16777215, r = n >> 16 & 255, i = n >> 8 & 255, s = n & 255;
1375
+ return `rgb(${t === "rgb" ? r : s}, ${i}, ${t === "rgb" ? s : r})`;
1359
1376
  }
1360
- function F(e) {
1377
+ function X(e) {
1361
1378
  if (typeof e == "string") {
1362
1379
  const t = e.trim();
1363
- return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ? Qe(t) ?? t : {
1380
+ return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ? En(t) ?? t : {
1364
1381
  red: "#ff0000",
1365
1382
  yellow: "#ffff00",
1366
1383
  green: "#00ff00",
@@ -1374,116 +1391,116 @@ function F(e) {
1374
1391
  }[t.toLowerCase()] : void 0;
1375
1392
  }
1376
1393
  if (e && typeof e == "object") {
1377
- const t = e, r = Number(t.r ?? t.red), i = Number(t.g ?? t.green), s = Number(t.b ?? t.blue), n = Number(t.a ?? t.alpha ?? 1);
1378
- if ([r, i, s].every(Number.isFinite))
1379
- return Number.isFinite(n) && n >= 0 && n < 1 ? `rgba(${r}, ${i}, ${s}, ${n})` : `rgb(${r}, ${i}, ${s})`;
1394
+ const t = e, n = Number(t.r ?? t.red), r = Number(t.g ?? t.green), i = Number(t.b ?? t.blue), s = Number(t.a ?? t.alpha ?? 1);
1395
+ if ([n, r, i].every(Number.isFinite))
1396
+ return Number.isFinite(s) && s >= 0 && s < 1 ? `rgba(${n}, ${r}, ${i}, ${s})` : `rgb(${n}, ${r}, ${i})`;
1380
1397
  }
1381
1398
  }
1382
- function Qe(e) {
1399
+ function En(e) {
1383
1400
  if (!e) return;
1384
1401
  const t = e.trim();
1385
1402
  if (/^#[0-9a-f]{8}$/i.test(t)) {
1386
- const r = parseInt(t.slice(1, 3), 16) / 255, i = parseInt(t.slice(3, 5), 16), s = parseInt(t.slice(5, 7), 16), n = parseInt(t.slice(7, 9), 16);
1387
- return r >= 0.999 ? `rgb(${i}, ${s}, ${n})` : `rgba(${i}, ${s}, ${n}, ${gt(r)})`;
1403
+ const n = parseInt(t.slice(1, 3), 16) / 255, r = parseInt(t.slice(3, 5), 16), i = parseInt(t.slice(5, 7), 16), s = parseInt(t.slice(7, 9), 16);
1404
+ return n >= 0.999 ? `rgb(${r}, ${i}, ${s})` : `rgba(${r}, ${i}, ${s}, ${St(n)})`;
1388
1405
  }
1389
1406
  if (/^#[0-9a-f]{6}$/i.test(t) || /^#[0-9a-f]{3}$/i.test(t)) return t;
1390
1407
  if (/^sc#/i.test(t)) {
1391
- const r = t.slice(3).split(",").map((a) => Number(a.trim())), [i, s, n, o] = r.length === 4 ? r : [1, ...r];
1392
- if ([i, s, n, o].every(Number.isFinite)) return `rgba(${Math.round(s * 255)}, ${Math.round(n * 255)}, ${Math.round(o * 255)}, ${gt(i)})`;
1408
+ const n = t.slice(3).split(",").map((a) => Number(a.trim())), [r, i, s, o] = n.length === 4 ? n : [1, ...n];
1409
+ if ([r, i, s, o].every(Number.isFinite)) return `rgba(${Math.round(i * 255)}, ${Math.round(s * 255)}, ${Math.round(o * 255)}, ${St(r)})`;
1393
1410
  }
1394
1411
  }
1395
- function D(e, t, r = {}) {
1396
- const i = r.foreground ?? "#ffffff", s = i;
1397
- let n;
1398
- const o = F(e.trueColor) ?? F(e.color) ?? F(e.colorName);
1399
- if (o && (n = o), !n) {
1400
- const a = nr(e, ["trueColor", "true_color", "truecolor", "colorRGB", "colorRgb", "rgbColor", "rgb"]);
1401
- typeof a == "number" && a >= 0 && a <= 16777215 && (n = V(a, r.trueColorByteOrder ?? "rgb"));
1412
+ function V(e, t, n = {}) {
1413
+ const r = n.foreground ?? "#ffffff", i = r;
1414
+ let s;
1415
+ const o = X(e.trueColor) ?? X(e.color) ?? X(e.colorName);
1416
+ if (o && (s = o), !s) {
1417
+ const a = Fn(e, ["trueColor", "true_color", "truecolor", "colorRGB", "colorRgb", "rgbColor", "rgb"]);
1418
+ typeof a == "number" && a >= 0 && a <= 16777215 && (s = tt(a, n.trueColorByteOrder ?? "rgb"));
1402
1419
  }
1403
- if (!n) {
1404
- const a = Qt(e.colorIndex, e.colorNumber, e.aci);
1405
- typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (n = E(a, s, i));
1420
+ if (!s) {
1421
+ const a = be(e.colorIndex, e.colorNumber, e.aci);
1422
+ typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (s = O(a, i, r));
1406
1423
  }
1407
- if (!n && typeof e.color == "number") {
1424
+ if (!s && typeof e.color == "number") {
1408
1425
  const a = Number(e.color);
1409
- Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (n = E(a, s, i)) : n = V(a, r.trueColorByteOrder ?? "rgb");
1426
+ Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (s = O(a, i, r)) : s = tt(a, n.trueColorByteOrder ?? "rgb");
1410
1427
  }
1411
- if (!n) {
1412
- const a = sr(t, e.layer);
1413
- n = er(a, r);
1428
+ if (!s) {
1429
+ const a = Bn(t, e.layer);
1430
+ s = Tn(a, n);
1414
1431
  }
1415
- return qt(n ?? s, r);
1432
+ return me(s ?? i, n);
1416
1433
  }
1417
- function mt(e, t, r = {}) {
1418
- let i;
1419
- const s = F(e.fillColor);
1420
- if (s && (i = s), !i && typeof e.fillColor == "number") {
1421
- const n = e.fillColor;
1422
- i = Math.abs(n) <= 257 ? E(n, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff") : V(n, r.trueColorByteOrder ?? "rgb");
1434
+ function Pt(e, t, n = {}) {
1435
+ let r;
1436
+ const i = X(e.fillColor);
1437
+ if (i && (r = i), !r && typeof e.fillColor == "number") {
1438
+ const s = e.fillColor;
1439
+ r = Math.abs(s) <= 257 ? O(s, n.foreground ?? "#ffffff", n.foreground ?? "#ffffff") : tt(s, n.trueColorByteOrder ?? "rgb");
1423
1440
  }
1424
- return !i && typeof e.fillColorIndex == "number" && (i = E(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ? qt(i, r) : void 0;
1441
+ return !r && typeof e.fillColorIndex == "number" && (r = O(e.fillColorIndex, n.foreground ?? "#ffffff", n.foreground ?? "#ffffff")), r ? me(r, n) : void 0;
1425
1442
  }
1426
- function qt(e, t = {}) {
1443
+ function me(e, t = {}) {
1427
1444
  if (t.contrastMode !== "adaptive") return e;
1428
- const r = t.background ?? "#0b1020", i = t.foreground ?? "#ffffff";
1429
- return tr(e, r, i, t.minColorContrast ?? 2.4);
1445
+ const n = t.background ?? "#0b1020", r = t.foreground ?? "#ffffff";
1446
+ return In(e, n, r, t.minColorContrast ?? 2.4);
1430
1447
  }
1431
- function tr(e, t, r, i = 2.4) {
1432
- const s = nt(r) ?? { r: 255, g: 255, b: 255, a: 1 }, n = nt(t) ?? { r: 11, g: 16, b: 32, a: 1 }, o = nt(e);
1448
+ function In(e, t, n, r = 2.4) {
1449
+ const i = mt(n) ?? { r: 255, g: 255, b: 255, a: 1 }, s = mt(t) ?? { r: 11, g: 16, b: 32, a: 1 }, o = mt(e);
1433
1450
  if (!o) return e;
1434
- const a = Ft(o, n);
1435
- if (ot(a, n) >= i) return e;
1436
- const c = pt(n), h = c < 0.5 ? { r: 255, g: 255, b: 255, a: o.a } : { r: 0, g: 0, b: 0, a: o.a };
1437
- for (const l of [0.25, 0.4, 0.55, 0.7, 0.85, 1]) {
1438
- const f = or(o, h, l);
1439
- if (ot(Ft(f, n), n) >= i) return Dt(f);
1451
+ const a = Zt(o, s);
1452
+ if (pt(a, s) >= r) return e;
1453
+ const c = kt(s), l = c < 0.5 ? { r: 255, g: 255, b: 255, a: o.a } : { r: 0, g: 0, b: 0, a: o.a };
1454
+ for (const h of [0.25, 0.4, 0.55, 0.7, 0.85, 1]) {
1455
+ const u = Dn(o, l, h);
1456
+ if (pt(Zt(u, s), s) >= r) return qt(u);
1440
1457
  }
1441
- return ot(s, n) >= i ? Dt(s) : c < 0.5 ? "#ffffff" : "#000000";
1458
+ return pt(i, s) >= r ? qt(i) : c < 0.5 ? "#ffffff" : "#000000";
1442
1459
  }
1443
- function Kt(e) {
1460
+ function pe(e) {
1444
1461
  return e ? e.isVisible !== !1 && e.isFrozen !== !0 : !0;
1445
1462
  }
1446
- function er(e, t) {
1463
+ function Tn(e, t) {
1447
1464
  if (!e) return;
1448
- const r = t.foreground ?? "#ffffff", i = F(e.trueColor);
1465
+ const n = t.foreground ?? "#ffffff", r = X(e.trueColor);
1466
+ if (r) return r;
1467
+ if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return tt(e.trueColor, t.trueColorByteOrder ?? "rgb");
1468
+ const i = X(e.color);
1449
1469
  if (i) return i;
1450
- if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return V(e.trueColor, t.trueColorByteOrder ?? "rgb");
1451
- const s = F(e.color);
1452
- if (s) return s;
1453
- if (ir(e.colorIndex)) return E(e.colorIndex, r, r);
1470
+ if (An(e.colorIndex)) return O(e.colorIndex, n, n);
1454
1471
  if (typeof e.color == "number") {
1455
- const n = Number(e.color);
1456
- return Math.abs(n) <= 257 ? E(n, r, r) : V(n, t.trueColorByteOrder ?? "rgb");
1472
+ const s = Number(e.color);
1473
+ return Math.abs(s) <= 257 ? O(s, n, n) : tt(s, t.trueColorByteOrder ?? "rgb");
1457
1474
  }
1458
- if (typeof e.colorIndex == "number") return E(e.colorIndex, r, r);
1475
+ if (typeof e.colorIndex == "number") return O(e.colorIndex, n, n);
1459
1476
  }
1460
- function rr(e) {
1461
- return Qt(e.colorIndex, e.colorNumber, e.aci) === 0 ? !0 : e.trueColor === void 0 && e.color === 0;
1477
+ function Ln(e) {
1478
+ return be(e.colorIndex, e.colorNumber, e.aci) === 0 ? !0 : e.trueColor === void 0 && e.color === 0;
1462
1479
  }
1463
- function Jt(e, t, r, i = {}) {
1464
- if (!rr(e)) return e;
1465
- const s = D(t, r, i);
1466
- return { ...e, color: s, trueColor: void 0, colorIndex: void 0, colorNumber: void 0 };
1480
+ function ge(e, t, n, r = {}) {
1481
+ if (!Ln(e)) return e;
1482
+ const i = V(t, n, r);
1483
+ return { ...e, color: i, trueColor: void 0, colorIndex: void 0, colorNumber: void 0 };
1467
1484
  }
1468
- function ir(e) {
1485
+ function An(e) {
1469
1486
  return typeof e == "number" && Number.isFinite(e) && Math.abs(Math.trunc(e)) >= 1 && Math.abs(Math.trunc(e)) <= 255;
1470
1487
  }
1471
- function sr(e, t) {
1488
+ function Bn(e, t) {
1472
1489
  if (!(!e || !t))
1473
- return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
1490
+ return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((n) => n.name.toLowerCase() === t.toLowerCase());
1474
1491
  }
1475
- function Qt(...e) {
1492
+ function be(...e) {
1476
1493
  for (const t of e)
1477
1494
  if (typeof t == "number" && Number.isFinite(t)) return t;
1478
1495
  }
1479
- function nr(e, t) {
1480
- const r = e;
1481
- for (const i of t) {
1482
- const s = r[i];
1483
- if (typeof s == "number" && Number.isFinite(s)) return s;
1496
+ function Fn(e, t) {
1497
+ const n = e;
1498
+ for (const r of t) {
1499
+ const i = n[r];
1500
+ if (typeof i == "number" && Number.isFinite(i)) return i;
1484
1501
  }
1485
1502
  }
1486
- function nt(e) {
1503
+ function mt(e) {
1487
1504
  const t = e.trim().toLowerCase();
1488
1505
  if (/^#[0-9a-f]{3}$/i.test(t))
1489
1506
  return {
@@ -1499,60 +1516,61 @@ function nt(e) {
1499
1516
  b: parseInt(t.slice(5, 7), 16),
1500
1517
  a: 1
1501
1518
  };
1502
- const r = t.match(/^rgba?\(([^)]+)\)$/i);
1503
- if (r) {
1504
- const i = r[1].split(/[,\s/]+/).filter(Boolean).map((s) => Number(s.replace("%", "")));
1505
- if (i.length >= 3 && i.slice(0, 3).every(Number.isFinite)) {
1506
- const s = /%/.test(r[1]);
1519
+ const n = t.match(/^rgba?\(([^)]+)\)$/i);
1520
+ if (n) {
1521
+ const r = n[1].split(/[,\s/]+/).filter(Boolean).map((i) => Number(i.replace("%", "")));
1522
+ if (r.length >= 3 && r.slice(0, 3).every(Number.isFinite)) {
1523
+ const i = /%/.test(n[1]);
1507
1524
  return {
1508
- r: W(s ? i[0] * 2.55 : i[0]),
1509
- g: W(s ? i[1] * 2.55 : i[1]),
1510
- b: W(s ? i[2] * 2.55 : i[2]),
1511
- a: Number.isFinite(i[3]) ? Math.max(0, Math.min(1, i[3])) : 1
1525
+ r: H(i ? r[0] * 2.55 : r[0]),
1526
+ g: H(i ? r[1] * 2.55 : r[1]),
1527
+ b: H(i ? r[2] * 2.55 : r[2]),
1528
+ a: Number.isFinite(r[3]) ? Math.max(0, Math.min(1, r[3])) : 1
1512
1529
  };
1513
1530
  }
1514
1531
  }
1515
1532
  }
1516
- function Ft(e, t) {
1517
- const r = e.a + t.a * (1 - e.a);
1518
- return r <= 0 ? { r: 0, g: 0, b: 0, a: 0 } : {
1519
- r: (e.r * e.a + t.r * t.a * (1 - e.a)) / r,
1520
- g: (e.g * e.a + t.g * t.a * (1 - e.a)) / r,
1521
- b: (e.b * e.a + t.b * t.a * (1 - e.a)) / r,
1522
- a: r
1533
+ function Zt(e, t) {
1534
+ const n = e.a + t.a * (1 - e.a);
1535
+ return n <= 0 ? { r: 0, g: 0, b: 0, a: 0 } : {
1536
+ r: (e.r * e.a + t.r * t.a * (1 - e.a)) / n,
1537
+ g: (e.g * e.a + t.g * t.a * (1 - e.a)) / n,
1538
+ b: (e.b * e.a + t.b * t.a * (1 - e.a)) / n,
1539
+ a: n
1523
1540
  };
1524
1541
  }
1525
- function or(e, t, r) {
1526
- const i = Math.max(0, Math.min(1, r));
1542
+ function Dn(e, t, n) {
1543
+ const r = Math.max(0, Math.min(1, n));
1527
1544
  return {
1528
- r: e.r + (t.r - e.r) * i,
1529
- g: e.g + (t.g - e.g) * i,
1530
- b: e.b + (t.b - e.b) * i,
1545
+ r: e.r + (t.r - e.r) * r,
1546
+ g: e.g + (t.g - e.g) * r,
1547
+ b: e.b + (t.b - e.b) * r,
1531
1548
  a: e.a
1532
1549
  };
1533
1550
  }
1534
- function pt(e) {
1535
- const t = [e.r, e.g, e.b].map((r) => {
1536
- const i = r / 255;
1537
- return i <= 0.03928 ? i / 12.92 : ((i + 0.055) / 1.055) ** 2.4;
1551
+ function kt(e) {
1552
+ const t = [e.r, e.g, e.b].map((n) => {
1553
+ const r = n / 255;
1554
+ return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
1538
1555
  });
1539
1556
  return 0.2126 * t[0] + 0.7152 * t[1] + 0.0722 * t[2];
1540
1557
  }
1541
- function ot(e, t) {
1542
- const r = pt(e), i = pt(t), s = Math.max(r, i), n = Math.min(r, i);
1543
- return (s + 0.05) / (n + 0.05);
1558
+ function pt(e, t) {
1559
+ const n = kt(e), r = kt(t), i = Math.max(n, r), s = Math.min(n, r);
1560
+ return (i + 0.05) / (s + 0.05);
1544
1561
  }
1545
- function Dt(e) {
1546
- const t = W(e.r), r = W(e.g), i = W(e.b);
1547
- return e.a < 0.999 ? `rgba(${t}, ${r}, ${i}, ${gt(e.a)})` : `rgb(${t}, ${r}, ${i})`;
1562
+ function qt(e) {
1563
+ const t = H(e.r), n = H(e.g), r = H(e.b);
1564
+ return e.a < 0.999 ? `rgba(${t}, ${n}, ${r}, ${St(e.a)})` : `rgb(${t}, ${n}, ${r})`;
1548
1565
  }
1549
- function W(e) {
1566
+ function H(e) {
1550
1567
  return Math.max(0, Math.min(255, Math.round(e)));
1551
1568
  }
1552
- function gt(e) {
1569
+ function St(e) {
1553
1570
  return Math.round(e * 1e3) / 1e3;
1554
1571
  }
1555
- function at(e, t) {
1572
+ const Rn = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
1573
+ function ct(e, t) {
1556
1574
  return {
1557
1575
  a: e.a * t.a + e.c * t.b,
1558
1576
  b: e.b * t.a + e.d * t.b,
@@ -1562,50 +1580,308 @@ function at(e, t) {
1562
1580
  f: e.b * t.e + e.d * t.f + e.f
1563
1581
  };
1564
1582
  }
1565
- function Wt(e, t) {
1583
+ function Kt(e, t) {
1566
1584
  return { a: 1, b: 0, c: 0, d: 1, e, f: t };
1567
1585
  }
1568
- function ar(e) {
1569
- const t = Math.cos(e), r = Math.sin(e);
1570
- return { a: t, b: r, c: -r, d: t, e: 0, f: 0 };
1586
+ function ye(e) {
1587
+ const t = Math.cos(e), n = Math.sin(e);
1588
+ return { a: t, b: n, c: -n, d: t, e: 0, f: 0 };
1571
1589
  }
1572
- function cr(e, t = e) {
1590
+ function On(e, t = e) {
1573
1591
  return { a: e, b: 0, c: 0, d: t, e: 0, f: 0 };
1574
1592
  }
1575
- function k(e, t) {
1593
+ function E(e, t) {
1576
1594
  return {
1577
1595
  x: e.x * t.a + e.y * t.c + t.e,
1578
1596
  y: e.x * t.b + e.y * t.d + t.f,
1579
1597
  z: "z" in e ? e.z : void 0
1580
1598
  };
1581
1599
  }
1582
- function Rt(e, t) {
1600
+ function Jt(e, t) {
1583
1601
  if (e)
1584
- return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) => k(i, t)) }));
1602
+ return e.map((n) => ({ cmd: n.cmd, points: n.points.map((r) => E(r, t)) }));
1585
1603
  }
1586
- function tt(e, t = { x: 0, y: 0 }) {
1587
- const r = e.insertionPoint ?? { x: 0, y: 0 }, i = e.scale, s = Number(typeof i == "object" && i ? i.x ?? 1 : e.scaleX ?? 1), n = Number(typeof i == "object" && i ? i.y ?? s : e.scaleY ?? s), o = Number(e.rotation ?? 0);
1588
- let a = Wt(r.x, r.y);
1589
- return a = at(a, ar(Number.isFinite(o) ? o : 0)), a = at(a, cr(Number.isFinite(s) ? s : 1, Number.isFinite(n) ? n : 1)), a = at(a, Wt(-t.x, -t.y)), a;
1604
+ function Bt(e, t = { x: 0, y: 0 }) {
1605
+ const n = e.insertionPoint ?? { x: 0, y: 0 }, r = e.scale, i = Number(typeof r == "object" && r ? r.x ?? 1 : e.scaleX ?? 1), s = Number(typeof r == "object" && r ? r.y ?? i : e.scaleY ?? i), o = Number(e.rotation ?? 0);
1606
+ let a = Kt(n.x, n.y);
1607
+ return a = ct(a, ye(Number.isFinite(o) ? o : 0)), a = ct(a, On(Number.isFinite(i) ? i : 1, Number.isFinite(s) ? s : 1)), a = ct(a, Kt(-t.x, -t.y)), a;
1590
1608
  }
1591
- function et(e, t) {
1592
- const r = { ...e, raw: e.raw ?? e };
1593
- if (e.startPoint && (r.startPoint = k(e.startPoint, t)), e.endPoint && (r.endPoint = k(e.endPoint, t)), e.center && (r.center = k(e.center, t)), e.insertionPoint && (r.insertionPoint = k(e.insertionPoint, t)), e.majorAxisEndPoint) {
1594
- const s = k({ x: 0, y: 0 }, t), n = k(e.majorAxisEndPoint, t);
1595
- r.majorAxisEndPoint = { x: n.x - s.x, y: n.y - s.y, z: n.z };
1609
+ function $(e, t) {
1610
+ const n = { ...e };
1611
+ if (e.startPoint && (n.startPoint = E(e.startPoint, t)), e.endPoint && (n.endPoint = E(e.endPoint, t)), e.center && (n.center = E(e.center, t)), e.insertionPoint && (n.insertionPoint = E(e.insertionPoint, t)), e.majorAxisEndPoint) {
1612
+ const o = E({ x: 0, y: 0 }, t), a = E(e.majorAxisEndPoint, t);
1613
+ n.majorAxisEndPoint = { x: a.x - o.x, y: a.y - o.y, z: a.z };
1596
1614
  }
1597
- e.vertices && (r.vertices = e.vertices.map((s) => ({ ...k(s, t), bulge: s.bulge, startWidth: s.startWidth, endWidth: s.endWidth }))), e.points && (r.points = e.points.map((s) => k(s, t))), e.controlPoints && (r.controlPoints = e.controlPoints.map((s) => k(s, t))), e.fitPoints && (r.fitPoints = e.fitPoints.map((s) => k(s, t))), e.commands && (r.commands = Rt(e.commands, t)), e.loops && (r.loops = e.loops.map((s) => {
1598
- var n;
1615
+ e.vertices && (n.vertices = e.vertices.map((o) => ({ ...E(o, t), bulge: o.bulge, startWidth: o.startWidth, endWidth: o.endWidth }))), e.points && (n.points = e.points.map((o) => E(o, t))), e.controlPoints && (n.controlPoints = e.controlPoints.map((o) => E(o, t))), e.fitPoints && (n.fitPoints = e.fitPoints.map((o) => E(o, t))), e.attribs && (n.attribs = e.attribs.map((o) => $(o, t))), e.commands && (n.commands = Jt(e.commands, t)), e.loops && (n.loops = e.loops.map((o) => {
1616
+ var a;
1599
1617
  return {
1600
- ...s,
1601
- vertices: (n = s.vertices) == null ? void 0 : n.map((o) => k(o, t)),
1602
- commands: Rt(s.commands, t)
1618
+ ...o,
1619
+ vertices: (a = o.vertices) == null ? void 0 : a.map((c) => E(c, t)),
1620
+ commands: Jt(o.commands, t)
1603
1621
  };
1604
1622
  }));
1605
- const i = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c));
1606
- return typeof e.radius == "number" && Number.isFinite(i) && (r.radius = e.radius * i), r;
1623
+ const r = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c));
1624
+ typeof e.radius == "number" && Number.isFinite(r) && (n.radius = e.radius * r);
1625
+ const i = Math.atan2(t.b, t.a), s = e.kind === "ellipse" || String(e.type ?? "").toUpperCase() === "ELLIPSE";
1626
+ return Number.isFinite(i) && Math.abs(i) > 1e-14 && ((typeof e.rotation == "number" || e.kind === "text" || e.kind === "insert") && (n.rotation = Number(e.rotation ?? 0) + i), !s && typeof e.startAngle == "number" && (n.startAngle = e.startAngle + i), !s && typeof e.endAngle == "number" && (n.endAngle = e.endAngle + i)), t.a * t.d - t.b * t.c < 0 && n.vertices && (n.vertices = n.vertices.map((o) => ({ ...o, bulge: typeof o.bulge == "number" ? -o.bulge : void 0 }))), n;
1627
+ }
1628
+ const Wn = 16, _n = 96, zn = 0.01;
1629
+ function ve(e, t = {}) {
1630
+ const n = L();
1631
+ for (const i of e.pages ?? [])
1632
+ S(n, { x: 0, y: 0 }), S(n, { x: i.width, y: i.height });
1633
+ const r = we(e, t);
1634
+ for (const i of e.entities) le(n, Ce(i, r));
1635
+ return he(n);
1636
+ }
1637
+ function xe(e, t, n = "auto", r = {}) {
1638
+ if (n === "extents") return t;
1639
+ const i = Yn(e);
1640
+ if (!i) return t;
1641
+ if (n === "saved-view") return i;
1642
+ const s = L(), o = we(e, r);
1643
+ let a = 0;
1644
+ for (const c of e.entities) {
1645
+ const l = Hn(Ce(c, o), i);
1646
+ l && (a++, le(s, l));
1647
+ }
1648
+ return a === 0 || !Un(s, i) ? i : he(s);
1649
+ }
1650
+ function Yn(e) {
1651
+ const t = e.savedView;
1652
+ if (!t || t.source !== "vport" || t.sceneTransformApplied !== !0 || !g(t.center)) return;
1653
+ const n = Number(t.viewHeight), r = Number(t.aspectRatio);
1654
+ if (!Number.isFinite(n) || n <= 1e-9 || !Number.isFinite(r) || r <= 1e-9) return;
1655
+ const i = n * r;
1656
+ return {
1657
+ minX: t.center.x - i / 2,
1658
+ minY: t.center.y - n / 2,
1659
+ maxX: t.center.x + i / 2,
1660
+ maxY: t.center.y + n / 2
1661
+ };
1662
+ }
1663
+ function we(e, t) {
1664
+ return {
1665
+ document: e,
1666
+ maxInsertDepth: Math.max(0, Math.floor(t.maxInsertDepth ?? Wn)),
1667
+ maxCurveSegments: Math.max(12, Math.floor(t.maxCurveSegments ?? _n))
1668
+ };
1669
+ }
1670
+ function Ce(e, t, n = 0) {
1671
+ const r = L();
1672
+ return Pe(r, e, t, n), r;
1673
+ }
1674
+ function Pe(e, t, n, r) {
1675
+ const i = String(t.type ?? "").toUpperCase(), s = t.kind ?? J(i);
1676
+ if (s === "insert") {
1677
+ const o = Vn(n.document, t.blockName ?? t.name);
1678
+ if (o && r < n.maxInsertDepth) {
1679
+ const a = Bt(t, o.basePoint ?? { x: 0, y: 0 });
1680
+ for (const c of o.entities) Pe(e, $(c, a), n, r + 1);
1681
+ return;
1682
+ }
1683
+ }
1684
+ if (s === "line")
1685
+ g(t.startPoint) && S(e, t.startPoint), g(t.endPoint) && S(e, t.endPoint);
1686
+ else if (s === "circle" || s === "arc")
1687
+ g(t.center) && Number.isFinite(t.radius) && je(e, t.center, Number(t.radius));
1688
+ else if (s === "polyline" || s === "solid" || s === "spline")
1689
+ for (const o of [...t.vertices ?? [], ...t.points ?? [], ...t.controlPoints ?? [], ...t.fitPoints ?? []])
1690
+ g(o) && S(e, o);
1691
+ else if (s === "ellipse") {
1692
+ if (g(t.center) && g(t.majorAxisEndPoint))
1693
+ for (const o of Lt(
1694
+ t.center,
1695
+ t.majorAxisEndPoint,
1696
+ Number(t.axisRatio ?? 1),
1697
+ Number(t.startAngle ?? 0),
1698
+ Number(t.endAngle ?? Math.PI * 2),
1699
+ n.maxCurveSegments
1700
+ )) S(e, o);
1701
+ } else if (s === "path")
1702
+ for (const o of t.commands ?? []) for (const a of o.points) S(e, a);
1703
+ else if (s === "hatch")
1704
+ for (const o of t.loops ?? []) {
1705
+ for (const a of o.vertices ?? []) S(e, a);
1706
+ for (const a of o.commands ?? []) for (const c of a.points) S(e, c);
1707
+ }
1708
+ else {
1709
+ const o = Xn(t);
1710
+ o && S(e, o);
1711
+ }
1712
+ }
1713
+ function Xn(e) {
1714
+ for (const t of ["startPoint", "insertionPoint", "center", "point", "location"]) {
1715
+ const n = e[t];
1716
+ if (g(n)) return n;
1717
+ }
1718
+ if (Array.isArray(e.vertices) && g(e.vertices[0])) return e.vertices[0];
1719
+ if (Array.isArray(e.commands)) {
1720
+ const t = e.commands.find((n) => n.points.length > 0);
1721
+ if (t) return t.points[0];
1722
+ }
1723
+ }
1724
+ function Vn(e, t) {
1725
+ if (t)
1726
+ return e.blocks[t] ?? e.blocks[t.toLowerCase()] ?? Object.values(e.blocks).find((n) => n.name.toLowerCase() === t.toLowerCase());
1727
+ }
1728
+ function Hn(e, t) {
1729
+ if (!I(e) || !I(t)) return;
1730
+ const n = {
1731
+ minX: Math.max(e.minX, t.minX),
1732
+ minY: Math.max(e.minY, t.minY),
1733
+ maxX: Math.min(e.maxX, t.maxX),
1734
+ maxY: Math.min(e.maxY, t.maxY)
1735
+ };
1736
+ return I(n) ? n : void 0;
1737
+ }
1738
+ function Un(e, t) {
1739
+ if (!I(e) || !I(t)) return !1;
1740
+ const n = Math.hypot(e.maxX - e.minX, e.maxY - e.minY), r = Math.hypot(t.maxX - t.minX, t.maxY - t.minY);
1741
+ return r > 1e-9 && n / r >= zn;
1742
+ }
1743
+ const Qt = 1e5, ke = /* @__PURE__ */ new Set(["", "bylayer", "15"]), Ft = /* @__PURE__ */ new Set(["byblock", "14"]), $n = /* @__PURE__ */ new Set(["continuous", "16"]), U = (e) => String(e ?? "").trim().toLowerCase();
1744
+ function jn(e) {
1745
+ return Ft.has(U(e));
1746
+ }
1747
+ function Se(e, t, n) {
1748
+ if (!jn(e.lineType)) return e;
1749
+ const r = Ne(t, n);
1750
+ return {
1751
+ ...e,
1752
+ lineType: r || "Continuous",
1753
+ lineTypeScale: q(e.lineTypeScale, 1) * q(t.lineTypeScale, 1)
1754
+ };
1755
+ }
1756
+ function Ne(e, t) {
1757
+ var i;
1758
+ let n = String(e.lineType ?? "").trim();
1759
+ const r = U(n);
1760
+ return ke.has(r) ? n = ((i = Kn(t, e.layer)) == null ? void 0 : i.lineType) ?? "Continuous" : Ft.has(r) && (n = "Continuous"), n || "Continuous";
1761
+ }
1762
+ function Nt(e, t) {
1763
+ var u, f;
1764
+ if (!t) return;
1765
+ const n = Ne(e, t), r = U(n);
1766
+ if ($n.has(r) || ke.has(r) || Ft.has(r)) return;
1767
+ const i = qn(t, n);
1768
+ if (!(i != null && i.pattern.length)) return;
1769
+ const s = q(e.lineTypeScale, q((u = t.header) == null ? void 0 : u.CELTSCALE, 1)), o = q((f = t.header) == null ? void 0 : f.LTSCALE, 1) * s, a = Gn(i, o), c = a.reduce((m, p) => m + p.length, 0);
1770
+ if (!Number.isFinite(c) || c <= 1e-9) return;
1771
+ const l = a.some((m) => !m.draw && m.length > 1e-12), h = a.some((m) => m.marker);
1772
+ if (!(!l && !h))
1773
+ return { name: i.name, segments: Zn(a, l), runs: a, period: c };
1774
+ }
1775
+ function Mr(e, t, n) {
1776
+ return Dt(e, t, n).segments;
1777
+ }
1778
+ function Dt(e, t, n, r = Qt) {
1779
+ const i = e.filter((y) => Number.isFinite(y.x) && Number.isFinite(y.y));
1780
+ if (i.length < 2 || n.runs.length === 0) return { segments: [], dots: [] };
1781
+ const s = [];
1782
+ for (let y = 0; y < i.length - 1; y++) s.push([i[y], i[y + 1]]);
1783
+ t && s.push([i[i.length - 1], i[0]]);
1784
+ const o = Number.isFinite(r) ? Math.max(1, Math.floor(r)) : Qt, a = s.reduce((y, [v, N]) => y + Math.hypot(N.x - v.x, N.y - v.y), 0), l = (n.period > 1e-12 ? a / n.period : Number.POSITIVE_INFINITY) * Math.max(1, n.runs.length);
1785
+ if (!Number.isFinite(l) || l > o)
1786
+ return { segments: s, dots: [] };
1787
+ const h = { segments: [], dots: [] };
1788
+ let u = 0, f = n.runs[0].length, m = !0;
1789
+ const p = (y) => {
1790
+ const v = h.dots[h.dots.length - 1];
1791
+ v && Math.hypot(v.x - y.x, v.y - y.y) <= 1e-10 || h.dots.push(y);
1792
+ }, C = () => {
1793
+ u = (u + 1) % n.runs.length, f = n.runs[u].length, m = !0;
1794
+ };
1795
+ for (const [y, v] of s) {
1796
+ const N = v.x - y.x, A = v.y - y.y, T = Math.hypot(N, A);
1797
+ if (T <= 1e-14) continue;
1798
+ let B = 0;
1799
+ for (; B < T - 1e-12; ) {
1800
+ let Rt = 0;
1801
+ for (; f <= 1e-12 && Rt < n.runs.length; ) {
1802
+ const F = n.runs[u];
1803
+ if (m && F.marker) {
1804
+ const j = B / T;
1805
+ p({ x: y.x + N * j, y: y.y + A * j });
1806
+ }
1807
+ C(), Rt++;
1808
+ }
1809
+ if (f <= 1e-12) break;
1810
+ const Ot = n.runs[u];
1811
+ if (m) {
1812
+ if (Ot.marker) {
1813
+ const F = B / T;
1814
+ p({ x: y.x + N * F, y: y.y + A * F });
1815
+ }
1816
+ m = !1;
1817
+ }
1818
+ const et = Math.min(f, T - B);
1819
+ if (Ot.draw && et > 1e-12) {
1820
+ const F = B / T, j = (B + et) / T;
1821
+ h.segments.push([
1822
+ { x: y.x + N * F, y: y.y + A * F },
1823
+ { x: y.x + N * j, y: y.y + A * j }
1824
+ ]);
1825
+ }
1826
+ B += et, f -= et, f <= 1e-12 && C();
1827
+ }
1828
+ }
1829
+ return h;
1830
+ }
1831
+ function Gn(e, t) {
1832
+ const n = [];
1833
+ for (const r of e.pattern) {
1834
+ const i = Number(r.length), s = Number(r.elementTypeFlag ?? 0) !== 0;
1835
+ Number.isFinite(i) && n.push({ draw: i >= 0, length: Math.abs(i) * t, marker: i >= 0 && (i === 0 || s) });
1836
+ }
1837
+ return n;
1838
+ }
1839
+ function Zn(e, t) {
1840
+ if (!t) return [];
1841
+ const n = [];
1842
+ for (const i of e) {
1843
+ if (i.length <= 1e-12) continue;
1844
+ const s = n[n.length - 1];
1845
+ (s == null ? void 0 : s.draw) === i.draw ? s.length += i.length : n.push({ draw: i.draw, length: i.length });
1846
+ }
1847
+ const r = [];
1848
+ for (const i of n) {
1849
+ const s = r.length % 2 === 0;
1850
+ i.draw !== s && r.push(1e-9), r.push(i.length);
1851
+ }
1852
+ return r.length % 2 === 1 && r.push(1e-9), r;
1853
+ }
1854
+ function qn(e, t) {
1855
+ const n = U(t), r = e.lineTypes ?? {};
1856
+ return r[t] ?? r[n] ?? Object.values(r).find((i) => U(i.name) === n || U(i.handle) === n);
1857
+ }
1858
+ function Kn(e, t) {
1859
+ if (!(!e || !t))
1860
+ return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((n) => n.name.toLowerCase() === t.toLowerCase());
1607
1861
  }
1608
- const hr = {
1862
+ function q(e, t) {
1863
+ const n = Number(e);
1864
+ return Number.isFinite(n) && n > 0 ? n : t;
1865
+ }
1866
+ const Jn = (e) => Math.abs(e.a - 1) < 1e-12 && Math.abs(e.b) < 1e-12 && Math.abs(e.c) < 1e-12 && Math.abs(e.d - 1) < 1e-12 && Math.abs(e.e) < 1e-9 && Math.abs(e.f) < 1e-9;
1867
+ function Me(e) {
1868
+ var n, r, i;
1869
+ if (e.metadata.sceneTransformApplied === !0 || ((n = e.savedView) == null ? void 0 : n.sceneTransformApplied) === !1) return e;
1870
+ const t = ((r = e.savedView) == null ? void 0 : r.sceneTransform) ?? Rn;
1871
+ return Jn(t) ? e : {
1872
+ ...e,
1873
+ entities: e.entities.map((s) => $(s, t)),
1874
+ pages: (i = e.pages) == null ? void 0 : i.map((s) => ({
1875
+ ...s,
1876
+ entities: s.entities.map((o) => $(o, t))
1877
+ })),
1878
+ metadata: {
1879
+ ...e.metadata,
1880
+ sceneTransformApplied: !0
1881
+ }
1882
+ };
1883
+ }
1884
+ const Qn = {
1609
1885
  background: "#0b1020",
1610
1886
  foreground: "#ffffff",
1611
1887
  showUnsupportedMarkers: !1,
@@ -1616,6 +1892,7 @@ const hr = {
1616
1892
  wheelZoomFactor: 1.14,
1617
1893
  trueColorByteOrder: "rgb",
1618
1894
  maxInsertDepth: 16,
1895
+ fitMode: "auto",
1619
1896
  contrastMode: "adaptive",
1620
1897
  minColorContrast: 2.4,
1621
1898
  maxCurveSegments: 96,
@@ -1628,13 +1905,14 @@ const hr = {
1628
1905
  preserveDrawingBuffer: !1,
1629
1906
  enableSpatialIndex: !0
1630
1907
  };
1631
- class Ot {
1632
- constructor(t, r = {}) {
1908
+ class te {
1909
+ constructor(t, n = {}) {
1633
1910
  d(this, "canvas");
1634
1911
  d(this, "ctx");
1635
1912
  d(this, "opts");
1913
+ d(this, "sourceDocument");
1636
1914
  d(this, "document");
1637
- d(this, "bounds", N());
1915
+ d(this, "bounds", L());
1638
1916
  d(this, "view", { centerX: 0, centerY: 0, scale: 1 });
1639
1917
  d(this, "fitScale", 1);
1640
1918
  d(this, "dpr", 1);
@@ -1645,52 +1923,61 @@ class Ot {
1645
1923
  d(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "canvas2d" });
1646
1924
  d(this, "onStats");
1647
1925
  d(this, "onViewChange");
1648
- const i = t.getContext("2d");
1649
- if (!i) throw new Error("Canvas 2D context is not available.");
1650
- this.canvas = t, this.ctx = i, this.opts = { ...hr, ...r }, this.canvas.classList.add("cad-viewer-canvas"), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
1926
+ const r = t.getContext("2d");
1927
+ if (!r) throw new Error("Canvas 2D context is not available.");
1928
+ this.canvas = t, this.ctx = r, this.opts = { ...Qn, ...n }, this.canvas.classList.add("cad-viewer-canvas"), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
1651
1929
  }
1652
1930
  destroy() {
1653
1931
  var t;
1654
1932
  (t = this.resizeObserver) == null || t.disconnect();
1655
1933
  }
1656
1934
  clear() {
1657
- this.document = void 0, this.bounds = N(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
1935
+ this.sourceDocument = void 0, this.document = void 0, this.bounds = L(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
1658
1936
  }
1659
1937
  setDocument(t) {
1660
- this.document = t, this.bounds = this.computeBounds(t), this.fitToView();
1938
+ this.sourceDocument = t, this.document = Me(t), this.bounds = ve(this.document, this.boundsOptions()), this.fitToView();
1661
1939
  }
1662
1940
  getDocument() {
1663
1941
  return this.document;
1664
1942
  }
1943
+ getSourceDocument() {
1944
+ return this.sourceDocument;
1945
+ }
1665
1946
  setOptions(t) {
1666
- Object.assign(this.opts, t), this.render(), this.emitViewChange();
1947
+ const n = t.fitMode !== void 0 && t.fitMode !== this.opts.fitMode;
1948
+ if (Object.assign(this.opts, t), n && this.document) {
1949
+ this.fitToView();
1950
+ return;
1951
+ }
1952
+ this.render(), this.emitViewChange();
1667
1953
  }
1668
1954
  getOptions() {
1669
1955
  return { ...this.opts };
1670
1956
  }
1671
- fitToView(t = 0.92) {
1672
- if (!O(this.bounds)) {
1957
+ fitToView(t = 0.92, n = this.opts.fitMode) {
1958
+ const r = this.document ? xe(this.document, this.bounds, n, this.boundsOptions()) : this.bounds;
1959
+ if (!I(r)) {
1673
1960
  this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
1674
1961
  return;
1675
1962
  }
1676
- const r = Math.max(1, this.cssWidth), i = Math.max(1, this.cssHeight), s = Math.max(this.bounds.maxX - this.bounds.minX, 1e-9), n = Math.max(this.bounds.maxY - this.bounds.minY, 1e-9), o = this.clampScale(Math.min(r / s, i / n) * t);
1677
- this.fitScale = o, this.view = {
1678
- centerX: (this.bounds.minX + this.bounds.maxX) / 2,
1679
- centerY: (this.bounds.minY + this.bounds.maxY) / 2,
1680
- scale: o
1963
+ const i = Math.max(1, this.cssWidth), s = Math.max(1, this.cssHeight), o = Math.max(r.maxX - r.minX, 1e-9), a = Math.max(r.maxY - r.minY, 1e-9), c = this.clampScale(Math.min(i / o, s / a) * t);
1964
+ this.fitScale = c, this.view = {
1965
+ centerX: (r.minX + r.maxX) / 2,
1966
+ centerY: (r.minY + r.maxY) / 2,
1967
+ scale: c
1681
1968
  }, this.render(), this.emitViewChange();
1682
1969
  }
1683
1970
  resize() {
1684
1971
  this.dpr = Math.max(1, window.devicePixelRatio || 1);
1685
- const t = Math.max(1, Math.floor(this.cssWidth * this.dpr)), r = Math.max(1, Math.floor(this.cssHeight * this.dpr));
1686
- (this.canvas.width !== t || this.canvas.height !== r) && (this.canvas.width = t, this.canvas.height = r), this.render(), this.emitViewChange();
1972
+ const t = Math.max(1, Math.floor(this.cssWidth * this.dpr)), n = Math.max(1, Math.floor(this.cssHeight * this.dpr));
1973
+ (this.canvas.width !== t || this.canvas.height !== n) && (this.canvas.width = t, this.canvas.height = n), this.render(), this.emitViewChange();
1687
1974
  }
1688
- zoom(t, r) {
1975
+ zoom(t, n) {
1689
1976
  if (!Number.isFinite(t) || t <= 0) return;
1690
- const i = r ?? { x: this.cssWidth / 2, y: this.cssHeight / 2 }, s = this.screenToWorld(i);
1977
+ const r = n ?? { x: this.cssWidth / 2, y: this.cssHeight / 2 }, i = this.screenToWorld(r);
1691
1978
  this.view.scale = this.clampScale(this.view.scale * t);
1692
- const n = this.screenToWorld(i);
1693
- this.view.centerX += s.x - n.x, this.view.centerY += s.y - n.y, this.render(), this.emitViewChange();
1979
+ const s = this.screenToWorld(r);
1980
+ this.view.centerX += i.x - s.x, this.view.centerY += i.y - s.y, this.render(), this.emitViewChange();
1694
1981
  }
1695
1982
  zoomIn() {
1696
1983
  this.zoom(this.opts.wheelZoomFactor);
@@ -1698,8 +1985,8 @@ class Ot {
1698
1985
  zoomOut() {
1699
1986
  this.zoom(1 / this.opts.wheelZoomFactor);
1700
1987
  }
1701
- panByScreenDelta(t, r) {
1702
- !Number.isFinite(t) || !Number.isFinite(r) || (this.view.centerX -= t / this.view.scale, this.view.centerY += r / this.view.scale, this.render(), this.emitViewChange());
1988
+ panByScreenDelta(t, n) {
1989
+ !Number.isFinite(t) || !Number.isFinite(n) || (this.view.centerX -= t / this.view.scale, this.view.centerY += n / this.view.scale, this.render(), this.emitViewChange());
1703
1990
  }
1704
1991
  setViewState(t) {
1705
1992
  if (![t.centerX, t.centerY, t.scale].every(Number.isFinite)) throw new Error("Invalid view state.");
@@ -1712,7 +1999,7 @@ class Ot {
1712
1999
  return { ...this.bounds };
1713
2000
  }
1714
2001
  getStats() {
1715
- return lr(this.stats);
2002
+ return tr(this.stats);
1716
2003
  }
1717
2004
  getZoomRatio() {
1718
2005
  return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
@@ -1733,13 +2020,13 @@ class Ot {
1733
2020
  };
1734
2021
  }
1735
2022
  render() {
1736
- var r, i;
2023
+ var n, r;
1737
2024
  const t = performance.now();
1738
2025
  if (this.stats = { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "canvas2d" }, this.clearCanvas(), this.document) {
1739
- this.opts.showPageBounds && ((r = this.document.pages) != null && r.length) && this.drawPageBounds(this.document);
1740
- for (const s of this.document.entities) this.drawEntityTracked(s, 0);
2026
+ this.opts.showPageBounds && ((n = this.document.pages) != null && n.length) && this.drawPageBounds(this.document);
2027
+ for (const i of this.document.entities) this.drawEntityTracked(i, 0);
1741
2028
  }
1742
- return this.stats.renderElapsedMs = performance.now() - t, (i = this.onStats) == null || i.call(this, this.getStats()), this.getStats();
2029
+ return this.stats.renderElapsedMs = performance.now() - t, (r = this.onStats) == null || r.call(this, this.getStats()), this.getStats();
1743
2030
  }
1744
2031
  get cssWidth() {
1745
2032
  return this.canvas.clientWidth || 1;
@@ -1748,17 +2035,17 @@ class Ot {
1748
2035
  return this.canvas.clientHeight || 1;
1749
2036
  }
1750
2037
  bindEvents() {
1751
- this.canvas.addEventListener("wheel", (r) => {
1752
- r.preventDefault();
1753
- const i = r.deltaY < 0 ? this.opts.wheelZoomFactor : 1 / this.opts.wheelZoomFactor;
1754
- this.zoom(i, { x: r.offsetX, y: r.offsetY });
1755
- }, { passive: !1 }), this.canvas.addEventListener("pointerdown", (r) => {
1756
- this.canvas.setPointerCapture(r.pointerId), this.isDragging = !0, this.lastPointer = { x: r.clientX, y: r.clientY }, this.canvas.classList.add("is-dragging");
1757
- }), this.canvas.addEventListener("pointermove", (r) => {
1758
- !this.isDragging || !this.lastPointer || (this.panByScreenDelta(r.clientX - this.lastPointer.x, r.clientY - this.lastPointer.y), this.lastPointer = { x: r.clientX, y: r.clientY });
2038
+ this.canvas.addEventListener("wheel", (n) => {
2039
+ n.preventDefault();
2040
+ const r = n.deltaY < 0 ? this.opts.wheelZoomFactor : 1 / this.opts.wheelZoomFactor;
2041
+ this.zoom(r, { x: n.offsetX, y: n.offsetY });
2042
+ }, { passive: !1 }), this.canvas.addEventListener("pointerdown", (n) => {
2043
+ this.canvas.setPointerCapture(n.pointerId), this.isDragging = !0, this.lastPointer = { x: n.clientX, y: n.clientY }, this.canvas.classList.add("is-dragging");
2044
+ }), this.canvas.addEventListener("pointermove", (n) => {
2045
+ !this.isDragging || !this.lastPointer || (this.panByScreenDelta(n.clientX - this.lastPointer.x, n.clientY - this.lastPointer.y), this.lastPointer = { x: n.clientX, y: n.clientY });
1759
2046
  });
1760
- const t = (r) => {
1761
- r && this.canvas.hasPointerCapture(r.pointerId) && this.canvas.releasePointerCapture(r.pointerId), this.isDragging = !1, this.lastPointer = void 0, this.canvas.classList.remove("is-dragging");
2047
+ const t = (n) => {
2048
+ n && this.canvas.hasPointerCapture(n.pointerId) && this.canvas.releasePointerCapture(n.pointerId), this.isDragging = !1, this.lastPointer = void 0, this.canvas.classList.remove("is-dragging");
1762
2049
  };
1763
2050
  this.canvas.addEventListener("pointerup", t), this.canvas.addEventListener("pointercancel", () => t());
1764
2051
  }
@@ -1767,27 +2054,27 @@ class Ot {
1767
2054
  t.save(), t.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), t.clearRect(0, 0, this.cssWidth, this.cssHeight), t.fillStyle = this.opts.background, t.fillRect(0, 0, this.cssWidth, this.cssHeight), t.restore();
1768
2055
  }
1769
2056
  drawPageBounds(t) {
1770
- const r = this.ctx;
1771
- r.save(), r.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), r.strokeStyle = "rgba(148, 163, 184, 0.35)", r.lineWidth = 1, r.setLineDash([8, 6]);
1772
- for (const i of t.pages ?? []) {
1773
- const s = this.worldToScreen({ x: 0, y: 0 }), n = this.worldToScreen({ x: i.width, y: i.height });
1774
- r.strokeRect(Math.min(s.x, n.x), Math.min(s.y, n.y), Math.abs(n.x - s.x), Math.abs(n.y - s.y));
2057
+ const n = this.ctx;
2058
+ n.save(), n.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), n.strokeStyle = "rgba(148, 163, 184, 0.35)", n.lineWidth = 1, n.setLineDash([8, 6]);
2059
+ for (const r of t.pages ?? []) {
2060
+ const i = this.worldToScreen({ x: 0, y: 0 }), s = this.worldToScreen({ x: r.width, y: r.height });
2061
+ n.strokeRect(Math.min(i.x, s.x), Math.min(i.y, s.y), Math.abs(s.x - i.x), Math.abs(s.y - i.y));
1775
2062
  }
1776
- r.restore();
2063
+ n.restore();
1777
2064
  }
1778
- drawEntityTracked(t, r) {
2065
+ drawEntityTracked(t, n) {
1779
2066
  this.stats.total++;
1780
- const i = String(t.type ?? "UNKNOWN").toUpperCase();
1781
- this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
1782
- const s = this.lookupLayer(t.layer);
1783
- if (t.isVisible === !1 || !Kt(s)) {
2067
+ const r = String(t.type ?? "UNKNOWN").toUpperCase();
2068
+ this.stats.byType[r] = (this.stats.byType[r] ?? 0) + 1;
2069
+ const i = this.lookupLayer(t.layer);
2070
+ if (t.isVisible === !1 || !pe(i)) {
1784
2071
  this.stats.skipped++;
1785
2072
  return;
1786
2073
  }
1787
- this.drawEntity(t, i, r);
2074
+ this.drawEntity(t, r, n);
1788
2075
  }
1789
- drawEntity(t, r, i) {
1790
- switch (t.kind ?? R(r)) {
2076
+ drawEntity(t, n, r) {
2077
+ switch (t.kind ?? J(n)) {
1791
2078
  case "line":
1792
2079
  return this.drawLine(t);
1793
2080
  case "circle":
@@ -1803,7 +2090,7 @@ class Ot {
1803
2090
  case "point":
1804
2091
  return this.drawPoint(t);
1805
2092
  case "insert":
1806
- return this.drawInsert(t, i);
2093
+ return this.drawInsert(t, r);
1807
2094
  case "solid":
1808
2095
  return this.drawSolid(t);
1809
2096
  case "hatch":
@@ -1815,18 +2102,20 @@ class Ot {
1815
2102
  case "image":
1816
2103
  return this.drawImage(t);
1817
2104
  case "viewport":
1818
- return this.markSkipped(r);
2105
+ return this.markSkipped(n);
1819
2106
  default:
1820
- this.stats.unsupported[r] = (this.stats.unsupported[r] ?? 0) + 1, this.stats.skipped++, this.opts.showUnsupportedMarkers && this.drawUnsupportedMarker(t);
2107
+ this.stats.unsupported[n] = (this.stats.unsupported[n] ?? 0) + 1, this.stats.skipped++, this.opts.showUnsupportedMarkers && this.drawUnsupportedMarker(t);
1821
2108
  }
1822
2109
  }
1823
- beginStyledPath(t, r = !1) {
2110
+ beginStyledPath(t, n = !1, r = !0) {
1824
2111
  const i = this.ctx;
1825
2112
  i.save(), i.setTransform(this.dpr, 0, 0, this.dpr, 0, 0);
1826
- const s = D(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), n = mt(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }) ?? s;
1827
- i.strokeStyle = s, i.fillStyle = r ? n : s, i.globalAlpha = A(Number(t.opacity ?? 1), 0, 1), i.lineCap = "round", i.lineJoin = "round";
1828
- const o = typeof t.lineweight == "number" && t.lineweight > 0 ? t.lineweight : 0;
1829
- i.lineWidth = Math.max(1, Math.min(12, o > 0 ? o / 30 : 1)), i.beginPath();
2113
+ const s = V(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), o = Pt(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }) ?? s;
2114
+ i.strokeStyle = s, i.fillStyle = n ? o : s, i.globalAlpha = _(Number(t.opacity ?? 1), 0, 1), i.lineCap = "round", i.lineJoin = "round";
2115
+ const a = typeof t.lineweight == "number" && t.lineweight > 0 ? t.lineweight : 0;
2116
+ i.lineWidth = Math.max(1, Math.min(12, a > 0 ? a / 30 : 1));
2117
+ const c = r ? Nt(t, this.document) : void 0;
2118
+ i.setLineDash(c ? c.segments.map((l) => Math.max(0.05, l * this.view.scale)) : []), i.beginPath();
1830
2119
  }
1831
2120
  finishStroke() {
1832
2121
  this.ctx.stroke(), this.ctx.restore(), this.stats.drawn++;
@@ -1835,235 +2124,217 @@ class Ot {
1835
2124
  t && this.ctx.fill(), this.ctx.stroke(), this.ctx.restore(), this.stats.drawn++;
1836
2125
  }
1837
2126
  drawLine(t) {
1838
- const r = t.startPoint, i = t.endPoint;
1839
- if (!m(r) || !m(i)) return this.markSkipped("LINE");
1840
- const s = this.worldToScreen(r), n = this.worldToScreen(i);
1841
- this.beginStyledPath(t), this.ctx.moveTo(s.x, s.y), this.ctx.lineTo(n.x, n.y), this.finishStroke();
2127
+ const n = t.startPoint, r = t.endPoint;
2128
+ if (!g(n) || !g(r)) return this.markSkipped("LINE");
2129
+ this.strokeWorldPolyline(t, [n, r], !1);
1842
2130
  }
1843
2131
  drawCircle(t) {
1844
- const r = t.center, i = Number(t.radius);
1845
- if (!m(r) || !Number.isFinite(i)) return this.markSkipped("CIRCLE");
1846
- const s = this.worldToScreen(r);
1847
- this.beginStyledPath(t), this.ctx.arc(s.x, s.y, Math.abs(i) * this.view.scale, 0, Math.PI * 2), this.finishStroke();
2132
+ const n = t.center, r = Number(t.radius);
2133
+ if (!g(n) || !Number.isFinite(r)) return this.markSkipped("CIRCLE");
2134
+ this.strokeWorldPolyline(t, Q(P(n), r, 0, Math.PI * 2, !0), !0);
1848
2135
  }
1849
2136
  drawArc(t) {
1850
- const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
1851
- if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
1852
- this.strokeWorldPolyline(t, K(x(r), i, s, n, !0), !1);
2137
+ const n = t.center, r = Number(t.radius), i = Number(t.startAngle), s = Number(t.endAngle);
2138
+ if (!g(n) || !Number.isFinite(r) || !Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped("ARC");
2139
+ this.strokeWorldPolyline(t, Q(P(n), r, i, s, !0), !1);
1853
2140
  }
1854
2141
  drawPolyline(t) {
1855
- const r = t.vertices ?? t.points;
1856
- if (!Array.isArray(r) || r.length < 2) return this.markSkipped(String(t.type));
1857
- const i = !!t.isClosed || (Number(t.flag) & 1) === 1, s = [], n = i ? r.length : r.length - 1;
1858
- for (let o = 0; o < n; o++) {
1859
- const a = r[o], c = r[(o + 1) % r.length];
1860
- if (!m(a) || !m(c)) continue;
1861
- const h = jt(a, c, Number(a.bulge ?? 0));
1862
- s.length > 0 && h.shift(), s.push(...h);
2142
+ const n = t.vertices ?? t.points;
2143
+ if (!Array.isArray(n) || n.length < 2) return this.markSkipped(String(t.type));
2144
+ const r = ae(t), i = [], s = r ? n.length : n.length - 1;
2145
+ for (let o = 0; o < s; o++) {
2146
+ const a = n[o], c = n[(o + 1) % n.length];
2147
+ if (!g(a) || !g(c)) continue;
2148
+ const l = fe(a, c, Number(a.bulge ?? 0));
2149
+ i.length > 0 && l.shift(), i.push(...l);
1863
2150
  }
1864
- this.strokeWorldPolyline(t, s, i);
2151
+ this.strokeWorldPolyline(t, i, r);
1865
2152
  }
1866
2153
  drawEllipse(t) {
1867
- const r = t.center, i = t.majorAxisEndPoint, s = Number(t.axisRatio ?? 1);
1868
- if (!m(r) || !m(i)) return this.markSkipped("ELLIPSE");
1869
- const n = J(r, i, s, Number(t.startAngle ?? 0), Number(t.endAngle ?? Math.PI * 2)), o = Math.abs(Number(t.endAngle ?? Math.PI * 2) - Number(t.startAngle ?? 0)) >= Math.PI * 2 - 1e-6;
1870
- this.strokeWorldPolyline(t, n, o);
2154
+ const n = t.center, r = t.majorAxisEndPoint, i = Number(t.axisRatio ?? 1);
2155
+ if (!g(n) || !g(r)) return this.markSkipped("ELLIPSE");
2156
+ const s = Lt(n, r, i, Number(t.startAngle ?? 0), Number(t.endAngle ?? Math.PI * 2)), o = Math.abs(Number(t.endAngle ?? Math.PI * 2) - Number(t.startAngle ?? 0)) >= Math.PI * 2 - 1e-6;
2157
+ this.strokeWorldPolyline(t, s, o);
1871
2158
  }
1872
2159
  drawPoint(t) {
1873
- const r = t.point ?? t.location ?? t.center ?? t.insertionPoint;
1874
- if (!m(r)) return this.markSkipped("POINT");
1875
- const i = this.worldToScreen(r);
1876
- this.beginStyledPath(t), this.ctx.moveTo(i.x - 3, i.y), this.ctx.lineTo(i.x + 3, i.y), this.ctx.moveTo(i.x, i.y - 3), this.ctx.lineTo(i.x, i.y + 3), this.finishStroke();
2160
+ const n = t.point ?? t.location ?? t.center ?? t.insertionPoint;
2161
+ if (!g(n)) return this.markSkipped("POINT");
2162
+ const r = this.worldToScreen(n);
2163
+ this.beginStyledPath(t), this.ctx.moveTo(r.x - 3, r.y), this.ctx.lineTo(r.x + 3, r.y), this.ctx.moveTo(r.x, r.y - 3), this.ctx.lineTo(r.x, r.y + 3), this.finishStroke();
1877
2164
  }
1878
2165
  drawText(t) {
1879
- const r = t.insertionPoint ?? t.startPoint ?? t.center, i = Gt(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
1880
- if (!m(r) || !i) return this.markSkipped(String(t.type));
1881
- this.drawTextAt(t, r, i, s, Number(t.rotation ?? 0));
1882
- }
1883
- drawInsert(t, r) {
1884
- const i = this.lookupBlock(t.blockName ?? t.name);
1885
- if (i && r < this.opts.maxInsertDepth) {
1886
- const a = tt(t, i.basePoint ?? { x: 0, y: 0 });
1887
- for (const c of i.entities) {
1888
- const h = Jt(c, t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast });
1889
- this.drawEntityTracked(et(h, a), r + 1);
2166
+ const n = t.insertionPoint ?? t.startPoint ?? t.center, r = ue(String(t.text ?? t.value ?? "")), i = Number(t.textHeight ?? t.height ?? 1);
2167
+ if (!g(n) || !r) return this.markSkipped(String(t.type));
2168
+ this.drawTextAt(t, n, r, i, Number(t.rotation ?? 0));
2169
+ }
2170
+ drawInsert(t, n) {
2171
+ const r = this.lookupBlock(t.blockName ?? t.name);
2172
+ if (r && n < this.opts.maxInsertDepth) {
2173
+ const a = Bt(t, r.basePoint ?? { x: 0, y: 0 });
2174
+ for (const c of r.entities) {
2175
+ const l = ge(c, t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), h = Se(l, t, this.document);
2176
+ this.drawEntityTracked($(h, a), n + 1);
1890
2177
  }
1891
2178
  return;
1892
2179
  }
1893
- const s = t.insertionPoint;
1894
- if (!m(s)) return this.markSkipped("INSERT");
1895
- const n = this.worldToScreen(s);
2180
+ const i = t.insertionPoint;
2181
+ if (!g(i)) return this.markSkipped("INSERT");
2182
+ const s = this.worldToScreen(i);
1896
2183
  this.beginStyledPath(t);
1897
2184
  const o = 5;
1898
- if (this.ctx.rect(n.x - o, n.y - o, o * 2, o * 2), this.finishStroke(), Array.isArray(t.attribs)) for (const a of t.attribs) this.drawText(a);
2185
+ if (this.ctx.rect(s.x - o, s.y - o, o * 2, o * 2), this.finishStroke(), Array.isArray(t.attribs)) for (const a of t.attribs) this.drawText(a);
1899
2186
  }
1900
2187
  drawSolid(t) {
1901
- const r = t.vertices ?? t.points;
1902
- if (!Array.isArray(r) || r.length < 3) return this.markSkipped(String(t.type));
2188
+ const n = t.vertices ?? t.points;
2189
+ if (!Array.isArray(n) || n.length < 3) return this.markSkipped(String(t.type));
1903
2190
  this.beginStyledPath(t, !0);
1904
- const i = this.worldToScreen(r[0]);
1905
- this.ctx.moveTo(i.x, i.y);
1906
- for (const s of r.slice(1)) {
1907
- if (!m(s)) continue;
1908
- const n = this.worldToScreen(s);
1909
- this.ctx.lineTo(n.x, n.y);
2191
+ const r = this.worldToScreen(n[0]);
2192
+ this.ctx.moveTo(r.x, r.y);
2193
+ for (const i of n.slice(1)) {
2194
+ if (!g(i)) continue;
2195
+ const s = this.worldToScreen(i);
2196
+ this.ctx.lineTo(s.x, s.y);
1910
2197
  }
1911
2198
  this.ctx.closePath(), this.finishFillStroke(!0);
1912
2199
  }
1913
2200
  drawHatch(t) {
1914
- var i, s;
1915
- const r = t.loops;
1916
- if (!Array.isArray(r) || r.length === 0) return this.markSkipped("HATCH");
2201
+ var r, i;
2202
+ const n = t.loops;
2203
+ if (!Array.isArray(n) || n.length === 0) return this.markSkipped("HATCH");
1917
2204
  this.beginStyledPath(t, !0);
1918
- for (const n of r)
1919
- if ((i = n.commands) != null && i.length) this.addPathCommands(n.commands);
1920
- else if ((s = n.vertices) != null && s.length) {
1921
- const o = this.worldToScreen(n.vertices[0]);
2205
+ for (const s of n)
2206
+ if ((r = s.commands) != null && r.length) this.addPathCommands(s.commands);
2207
+ else if ((i = s.vertices) != null && i.length) {
2208
+ const o = this.worldToScreen(s.vertices[0]);
1922
2209
  this.ctx.moveTo(o.x, o.y);
1923
- for (const a of n.vertices.slice(1)) {
2210
+ for (const a of s.vertices.slice(1)) {
1924
2211
  const c = this.worldToScreen(a);
1925
2212
  this.ctx.lineTo(c.x, c.y);
1926
2213
  }
1927
2214
  this.ctx.closePath();
1928
2215
  }
1929
- this.finishFillStroke(!!mt(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }));
2216
+ this.finishFillStroke(!!Pt(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }));
1930
2217
  }
1931
2218
  drawSpline(t) {
1932
- var i;
1933
- const r = (i = t.fitPoints) != null && i.length ? t.fitPoints : t.controlPoints;
1934
- if (!r || r.length < 2) return this.markSkipped("SPLINE");
1935
- this.strokeWorldPolyline(t, r, !!t.isClosed);
2219
+ var r;
2220
+ const n = (r = t.fitPoints) != null && r.length ? t.fitPoints : t.controlPoints;
2221
+ if (!n || n.length < 2) return this.markSkipped("SPLINE");
2222
+ this.strokeWorldPolyline(t, n, !!t.isClosed);
1936
2223
  }
1937
2224
  drawPath(t) {
1938
- var r;
1939
- if (!((r = t.commands) != null && r.length)) return this.markSkipped(String(t.type));
2225
+ var n;
2226
+ if (!((n = t.commands) != null && n.length)) return this.markSkipped(String(t.type));
1940
2227
  this.beginStyledPath(t, !!t.fillColor), this.addPathCommands(t.commands), this.finishFillStroke(!!t.fillColor);
1941
2228
  }
1942
2229
  addPathCommands(t) {
1943
- for (const r of t)
1944
- if (r.cmd === "M") {
1945
- const i = this.worldToScreen(r.points[0]);
1946
- this.ctx.moveTo(i.x, i.y);
1947
- } else if (r.cmd === "L") {
1948
- const i = this.worldToScreen(r.points[0]);
1949
- this.ctx.lineTo(i.x, i.y);
1950
- } else if (r.cmd === "C") {
1951
- const [i, s, n] = r.points.map((o) => this.worldToScreen(o));
1952
- this.ctx.bezierCurveTo(i.x, i.y, s.x, s.y, n.x, n.y);
1953
- } else if (r.cmd === "Q") {
1954
- const [i, s] = r.points.map((n) => this.worldToScreen(n));
1955
- this.ctx.quadraticCurveTo(i.x, i.y, s.x, s.y);
1956
- } else r.cmd === "Z" && this.ctx.closePath();
2230
+ for (const n of t)
2231
+ if (n.cmd === "M") {
2232
+ const r = this.worldToScreen(n.points[0]);
2233
+ this.ctx.moveTo(r.x, r.y);
2234
+ } else if (n.cmd === "L") {
2235
+ const r = this.worldToScreen(n.points[0]);
2236
+ this.ctx.lineTo(r.x, r.y);
2237
+ } else if (n.cmd === "C") {
2238
+ const [r, i, s] = n.points.map((o) => this.worldToScreen(o));
2239
+ this.ctx.bezierCurveTo(r.x, r.y, i.x, i.y, s.x, s.y);
2240
+ } else if (n.cmd === "Q") {
2241
+ const [r, i] = n.points.map((s) => this.worldToScreen(s));
2242
+ this.ctx.quadraticCurveTo(r.x, r.y, i.x, i.y);
2243
+ } else n.cmd === "Z" && this.ctx.closePath();
1957
2244
  }
1958
2245
  drawImage(t) {
1959
- const r = t.insertionPoint;
1960
- if (!m(r)) return this.markSkipped(String(t.type));
1961
- const i = Number(t.width ?? 32), s = Number(t.height ?? 32), n = this.worldToScreen(r), o = this.worldToScreen({ x: r.x + i, y: r.y - s }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y), f = t.imageDataUrl;
1962
- if (f) {
1963
- const u = this.getImage(f);
1964
- if (u.complete && u.naturalWidth > 0) {
1965
- this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(u, a, c, h, l), this.ctx.restore(), this.stats.drawn++;
2246
+ const n = t.insertionPoint;
2247
+ if (!g(n)) return this.markSkipped(String(t.type));
2248
+ const r = Number(t.width ?? 32), i = Number(t.height ?? 32), s = this.worldToScreen(n), o = this.worldToScreen({ x: n.x + r, y: n.y - i }), a = Math.min(s.x, o.x), c = Math.min(s.y, o.y), l = Math.abs(o.x - s.x), h = Math.abs(o.y - s.y), u = t.imageDataUrl;
2249
+ if (u) {
2250
+ const f = this.getImage(u);
2251
+ if (f.complete && f.naturalWidth > 0) {
2252
+ this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(f, a, c, l, h), this.ctx.restore(), this.stats.drawn++;
1966
2253
  return;
1967
2254
  }
1968
- u.onload = () => this.render();
2255
+ f.onload = () => this.render();
1969
2256
  }
1970
2257
  if (!this.opts.showImagePlaceholders) return this.markSkipped(String(t.type));
1971
- this.beginStyledPath(t), this.ctx.rect(a, c, h, l), this.ctx.moveTo(a, c), this.ctx.lineTo(a + h, c + l), this.ctx.moveTo(a + h, c), this.ctx.lineTo(a, c + l), this.finishStroke();
2258
+ this.beginStyledPath(t), this.ctx.rect(a, c, l, h), this.ctx.moveTo(a, c), this.ctx.lineTo(a + l, c + h), this.ctx.moveTo(a + l, c), this.ctx.lineTo(a, c + h), this.finishStroke();
1972
2259
  }
1973
2260
  getImage(t) {
1974
- let r = this.imageCache.get(t);
1975
- return r || (r = new Image(), r.src = t, this.imageCache.set(t, r)), r;
2261
+ let n = this.imageCache.get(t);
2262
+ return n || (n = new Image(), n.src = t, this.imageCache.set(t, n)), n;
1976
2263
  }
1977
2264
  drawUnsupportedMarker(t) {
1978
- const r = this.entityAnchor(t);
1979
- if (!r) return;
1980
- const i = this.worldToScreen(r);
1981
- this.beginStyledPath(t), this.ctx.moveTo(i.x - 4, i.y - 4), this.ctx.lineTo(i.x + 4, i.y + 4), this.ctx.moveTo(i.x + 4, i.y - 4), this.ctx.lineTo(i.x - 4, i.y + 4), this.finishStroke();
1982
- }
1983
- drawTextAt(t, r, i, s, n) {
1984
- const o = this.ctx, a = this.worldToScreen(r);
1985
- o.save(), o.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), o.translate(a.x, a.y), o.rotate(-n);
1986
- const c = Math.max(4, Math.min(256, Math.abs(s) * this.view.scale));
1987
- o.font = `${c}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, o.fillStyle = D(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), o.globalAlpha = A(Number(t.opacity ?? 1), 0, 1), o.textBaseline = "alphabetic";
1988
- for (const [h, l] of i.split(/\r?\n/g).entries()) o.fillText(l, 0, h * c * 1.22);
2265
+ const n = this.entityAnchor(t);
2266
+ if (!n) return;
2267
+ const r = this.worldToScreen(n);
2268
+ this.beginStyledPath(t), this.ctx.moveTo(r.x - 4, r.y - 4), this.ctx.lineTo(r.x + 4, r.y + 4), this.ctx.moveTo(r.x + 4, r.y - 4), this.ctx.lineTo(r.x - 4, r.y + 4), this.finishStroke();
2269
+ }
2270
+ drawTextAt(t, n, r, i, s) {
2271
+ const o = this.ctx, a = this.worldToScreen(n);
2272
+ o.save(), o.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), o.translate(a.x, a.y), o.rotate(-s);
2273
+ const c = Math.max(4, Math.min(256, Math.abs(i) * this.view.scale));
2274
+ o.font = `${c}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, o.fillStyle = V(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), o.globalAlpha = _(Number(t.opacity ?? 1), 0, 1), o.textBaseline = "alphabetic";
2275
+ for (const [l, h] of r.split(/\r?\n/g).entries()) o.fillText(h, 0, l * c * 1.22);
1989
2276
  o.restore(), this.stats.drawn++;
1990
2277
  }
1991
- strokeWorldPolyline(t, r, i) {
1992
- const s = r.filter(m);
1993
- if (s.length < 2) return this.markSkipped(String(t.type));
2278
+ strokeWorldPolyline(t, n, r) {
2279
+ const i = n.filter(g);
2280
+ if (i.length < 2) return this.markSkipped(String(t.type));
2281
+ const s = Nt(t, this.document);
2282
+ if (s) {
2283
+ const a = Dt(i, r, s);
2284
+ this.beginStyledPath(t, !1, !1);
2285
+ for (const [c, l] of a.segments) {
2286
+ const h = this.worldToScreen(c), u = this.worldToScreen(l);
2287
+ this.ctx.moveTo(h.x, h.y), this.ctx.lineTo(u.x, u.y);
2288
+ }
2289
+ if (this.ctx.stroke(), a.dots.length > 0) {
2290
+ this.ctx.setLineDash([]), this.ctx.beginPath();
2291
+ const c = Math.max(0.5, this.ctx.lineWidth / 2);
2292
+ for (const l of a.dots) {
2293
+ const h = this.worldToScreen(l);
2294
+ this.ctx.moveTo(h.x + c, h.y), this.ctx.arc(h.x, h.y, c, 0, Math.PI * 2);
2295
+ }
2296
+ this.ctx.fillStyle = this.ctx.strokeStyle, this.ctx.fill();
2297
+ }
2298
+ this.ctx.restore(), this.stats.drawn++;
2299
+ return;
2300
+ }
1994
2301
  this.beginStyledPath(t);
1995
- const n = this.worldToScreen(s[0]);
1996
- this.ctx.moveTo(n.x, n.y);
1997
- for (const o of s.slice(1)) {
1998
- const a = this.worldToScreen(o);
1999
- this.ctx.lineTo(a.x, a.y);
2302
+ const o = this.worldToScreen(i[0]);
2303
+ this.ctx.moveTo(o.x, o.y);
2304
+ for (const a of i.slice(1)) {
2305
+ const c = this.worldToScreen(a);
2306
+ this.ctx.lineTo(c.x, c.y);
2000
2307
  }
2001
- i && this.ctx.closePath(), this.finishStroke();
2308
+ r && this.ctx.closePath(), this.finishStroke();
2002
2309
  }
2003
2310
  markSkipped(t) {
2004
2311
  this.stats.skipped++, this.stats.unsupported[t] = this.stats.unsupported[t] ?? 0;
2005
2312
  }
2006
2313
  entityAnchor(t) {
2007
- for (const r of ["startPoint", "insertionPoint", "center", "point", "location"]) {
2008
- const i = t[r];
2009
- if (m(i)) return x(i);
2314
+ for (const n of ["startPoint", "insertionPoint", "center", "point", "location"]) {
2315
+ const r = t[n];
2316
+ if (g(r)) return P(r);
2010
2317
  }
2011
- if (Array.isArray(t.vertices) && m(t.vertices[0])) return x(t.vertices[0]);
2318
+ if (Array.isArray(t.vertices) && g(t.vertices[0])) return P(t.vertices[0]);
2012
2319
  if (Array.isArray(t.commands) && t.commands.length) {
2013
- const r = t.commands.find((i) => i.points.length > 0);
2014
- if (r) return x(r.points[0]);
2015
- }
2016
- }
2017
- computeBounds(t) {
2018
- var i;
2019
- const r = N();
2020
- if ((i = t.pages) != null && i.length)
2021
- for (const s of t.pages)
2022
- v(r, { x: 0, y: 0 }), v(r, { x: s.width, y: s.height });
2023
- for (const s of t.entities) this.includeEntityBounds(r, s, 0);
2024
- return $t(r);
2025
- }
2026
- includeEntityBounds(t, r, i) {
2027
- const s = String(r.type ?? "").toUpperCase(), n = r.kind ?? R(s);
2028
- if (n === "insert") {
2029
- const o = this.lookupBlock(r.blockName ?? r.name);
2030
- if (o && i < this.opts.maxInsertDepth) {
2031
- const a = tt(r, o.basePoint ?? { x: 0, y: 0 });
2032
- for (const c of o.entities) this.includeEntityBounds(t, et(c, a), i + 1);
2033
- return;
2034
- }
2035
- }
2036
- if (n === "line")
2037
- m(r.startPoint) && v(t, r.startPoint), m(r.endPoint) && v(t, r.endPoint);
2038
- else if (n === "circle" || n === "arc")
2039
- m(r.center) && Number.isFinite(r.radius) && Vt(t, r.center, Number(r.radius));
2040
- else if (n === "polyline" || n === "solid" || n === "spline")
2041
- for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) && v(t, o);
2042
- else if (n === "ellipse")
2043
- m(r.center) && m(r.majorAxisEndPoint) && J(r.center, r.majorAxisEndPoint, Number(r.axisRatio ?? 1), Number(r.startAngle ?? 0), Number(r.endAngle ?? Math.PI * 2)).forEach((o) => v(t, o));
2044
- else if (n === "path")
2045
- for (const o of r.commands ?? []) for (const a of o.points) v(t, a);
2046
- else if (n === "hatch")
2047
- for (const o of r.loops ?? []) {
2048
- for (const a of o.vertices ?? []) v(t, a);
2049
- for (const a of o.commands ?? []) for (const c of a.points) v(t, c);
2050
- }
2051
- else {
2052
- const o = this.entityAnchor(r);
2053
- o && v(t, o);
2320
+ const n = t.commands.find((r) => r.points.length > 0);
2321
+ if (n) return P(n.points[0]);
2054
2322
  }
2055
2323
  }
2056
2324
  lookupLayer(t) {
2057
2325
  if (!(!this.document || !t))
2058
- return this.document.layers[t] ?? this.document.layers[t.toLowerCase()] ?? Object.values(this.document.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
2326
+ return this.document.layers[t] ?? this.document.layers[t.toLowerCase()] ?? Object.values(this.document.layers).find((n) => n.name.toLowerCase() === t.toLowerCase());
2059
2327
  }
2060
2328
  lookupBlock(t) {
2061
2329
  if (!(!this.document || !t))
2062
- return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((r) => r.name.toLowerCase() === t.toLowerCase());
2330
+ return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((n) => n.name.toLowerCase() === t.toLowerCase());
2063
2331
  }
2064
2332
  clampScale(t) {
2065
2333
  return Math.min(this.opts.maxScale, Math.max(this.opts.minScale, t));
2066
2334
  }
2335
+ boundsOptions() {
2336
+ return { maxInsertDepth: this.opts.maxInsertDepth, maxCurveSegments: this.opts.maxCurveSegments };
2337
+ }
2067
2338
  emitViewChange() {
2068
2339
  var t;
2069
2340
  (t = this.onViewChange) == null || t.call(this, {
@@ -2075,7 +2346,7 @@ class Ot {
2075
2346
  });
2076
2347
  }
2077
2348
  }
2078
- function lr(e) {
2349
+ function tr(e) {
2079
2350
  return {
2080
2351
  total: e.total,
2081
2352
  drawn: e.drawn,
@@ -2091,7 +2362,7 @@ function lr(e) {
2091
2362
  buildElapsedMs: e.buildElapsedMs
2092
2363
  };
2093
2364
  }
2094
- const fr = {
2365
+ const er = {
2095
2366
  background: "#0b1020",
2096
2367
  foreground: "#ffffff",
2097
2368
  showUnsupportedMarkers: !1,
@@ -2102,6 +2373,7 @@ const fr = {
2102
2373
  wheelZoomFactor: 1.14,
2103
2374
  trueColorByteOrder: "rgb",
2104
2375
  maxInsertDepth: 16,
2376
+ fitMode: "auto",
2105
2377
  contrastMode: "adaptive",
2106
2378
  minColorContrast: 2.4,
2107
2379
  maxCurveSegments: 96,
@@ -2114,8 +2386,8 @@ const fr = {
2114
2386
  preserveDrawingBuffer: !1,
2115
2387
  enableSpatialIndex: !0
2116
2388
  };
2117
- class zt {
2118
- constructor(t, r = {}) {
2389
+ class ee {
2390
+ constructor(t, n = {}) {
2119
2391
  d(this, "canvas");
2120
2392
  d(this, "backend", "webgl");
2121
2393
  d(this, "gl");
@@ -2123,8 +2395,9 @@ class zt {
2123
2395
  d(this, "eventController", new AbortController());
2124
2396
  d(this, "imageCache", /* @__PURE__ */ new Map());
2125
2397
  d(this, "opts");
2398
+ d(this, "sourceDocument");
2126
2399
  d(this, "document");
2127
- d(this, "bounds", N());
2400
+ d(this, "bounds", L());
2128
2401
  d(this, "view", { centerX: 0, centerY: 0, scale: 1 });
2129
2402
  d(this, "fitScale", 1);
2130
2403
  d(this, "dpr", 1);
@@ -2138,32 +2411,39 @@ class zt {
2138
2411
  d(this, "rafHandle", 0);
2139
2412
  d(this, "onStats");
2140
2413
  d(this, "onViewChange");
2141
- const i = dr(t, r);
2142
- if (!i) throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');
2143
- this.canvas = t, this.gl = i, this.program = ur(i), this.opts = { ...fr, ...r }, this.canvas.classList.add("cad-viewer-canvas", "cad-viewer-webgl-canvas"), this.createOverlayCanvas(), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
2414
+ const r = nr(t, n);
2415
+ if (!r) throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');
2416
+ this.canvas = t, this.gl = r, this.program = rr(r), this.opts = { ...er, ...n }, this.canvas.classList.add("cad-viewer-canvas", "cad-viewer-webgl-canvas"), this.createOverlayCanvas(), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
2144
2417
  }
2145
2418
  static isSupported() {
2146
- return te();
2419
+ return Ee();
2147
2420
  }
2148
2421
  destroy() {
2149
- var t, r;
2150
- this.eventController.abort(), (t = this.resizeObserver) == null || t.disconnect(), this.cancelScheduledRender(), this.disposeScene(), (r = this.overlayCanvas) == null || r.remove();
2422
+ var t, n;
2423
+ this.eventController.abort(), (t = this.resizeObserver) == null || t.disconnect(), this.cancelScheduledRender(), this.disposeScene(), (n = this.overlayCanvas) == null || n.remove();
2151
2424
  }
2152
2425
  clear() {
2153
- this.document = void 0, this.bounds = N(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.disposeScene(), this.render(), this.emitViewChange();
2426
+ this.sourceDocument = void 0, this.document = void 0, this.bounds = L(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.disposeScene(), this.render(), this.emitViewChange();
2154
2427
  }
2155
2428
  setDocument(t) {
2156
- this.document = t, this.bounds = yr(t, this.opts), this.disposeScene();
2157
- const r = pr(t, this.opts, this.bounds);
2158
- this.scene = mr(this.gl, r), this.stats = Cr(this.scene, 0), this.fitToView();
2429
+ this.sourceDocument = t, this.document = Me(t), this.bounds = ve(this.document, this.boundsOptions()), this.disposeScene();
2430
+ const n = sr(this.document, this.opts, this.bounds);
2431
+ this.scene = ir(this.gl, n), this.stats = fr(this.scene, 0), this.fitToView();
2159
2432
  }
2160
2433
  getDocument() {
2161
2434
  return this.document;
2162
2435
  }
2436
+ getSourceDocument() {
2437
+ return this.sourceDocument;
2438
+ }
2163
2439
  setOptions(t) {
2164
- const r = wr(this.opts, t);
2165
- if (this.opts = { ...this.opts, ...t }, r && this.document) {
2166
- this.setDocument(this.document);
2440
+ const n = hr(this.opts, t), r = t.fitMode !== void 0 && t.fitMode !== this.opts.fitMode;
2441
+ if (this.opts = { ...this.opts, ...t }, n && (this.sourceDocument ?? this.document)) {
2442
+ this.setDocument(this.sourceDocument ?? this.document);
2443
+ return;
2444
+ }
2445
+ if (r && this.document) {
2446
+ this.fitToView();
2167
2447
  return;
2168
2448
  }
2169
2449
  this.render(), this.emitViewChange();
@@ -2171,29 +2451,30 @@ class zt {
2171
2451
  getOptions() {
2172
2452
  return { ...this.opts };
2173
2453
  }
2174
- fitToView(t = 0.92) {
2175
- if (!O(this.bounds)) {
2454
+ fitToView(t = 0.92, n = this.opts.fitMode) {
2455
+ const r = this.document ? xe(this.document, this.bounds, n, this.boundsOptions()) : this.bounds;
2456
+ if (!I(r)) {
2176
2457
  this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
2177
2458
  return;
2178
2459
  }
2179
- const r = Math.max(1, this.cssWidth), i = Math.max(1, this.cssHeight), s = Math.max(this.bounds.maxX - this.bounds.minX, 1e-9), n = Math.max(this.bounds.maxY - this.bounds.minY, 1e-9), o = this.clampScale(Math.min(r / s, i / n) * t);
2180
- this.fitScale = o, this.view = {
2181
- centerX: (this.bounds.minX + this.bounds.maxX) / 2,
2182
- centerY: (this.bounds.minY + this.bounds.maxY) / 2,
2183
- scale: o
2460
+ const i = Math.max(1, this.cssWidth), s = Math.max(1, this.cssHeight), o = Math.max(r.maxX - r.minX, 1e-9), a = Math.max(r.maxY - r.minY, 1e-9), c = this.clampScale(Math.min(i / o, s / a) * t);
2461
+ this.fitScale = c, this.view = {
2462
+ centerX: (r.minX + r.maxX) / 2,
2463
+ centerY: (r.minY + r.maxY) / 2,
2464
+ scale: c
2184
2465
  }, this.render(), this.emitViewChange();
2185
2466
  }
2186
2467
  resize() {
2187
2468
  this.dpr = Math.max(1, window.devicePixelRatio || 1);
2188
- const t = Math.max(1, Math.floor(this.cssWidth * this.dpr)), r = Math.max(1, Math.floor(this.cssHeight * this.dpr));
2189
- (this.canvas.width !== t || this.canvas.height !== r) && (this.canvas.width = t, this.canvas.height = r), this.resizeOverlay(t, r), this.render(), this.emitViewChange();
2469
+ const t = Math.max(1, Math.floor(this.cssWidth * this.dpr)), n = Math.max(1, Math.floor(this.cssHeight * this.dpr));
2470
+ (this.canvas.width !== t || this.canvas.height !== n) && (this.canvas.width = t, this.canvas.height = n), this.resizeOverlay(t, n), this.render(), this.emitViewChange();
2190
2471
  }
2191
- zoom(t, r) {
2472
+ zoom(t, n) {
2192
2473
  if (!Number.isFinite(t) || t <= 0) return;
2193
- const i = r ?? { x: this.cssWidth / 2, y: this.cssHeight / 2 }, s = this.screenToWorld(i);
2474
+ const r = n ?? { x: this.cssWidth / 2, y: this.cssHeight / 2 }, i = this.screenToWorld(r);
2194
2475
  this.view.scale = this.clampScale(this.view.scale * t);
2195
- const n = this.screenToWorld(i);
2196
- this.view.centerX += s.x - n.x, this.view.centerY += s.y - n.y, this.scheduleRender(), this.emitViewChange();
2476
+ const s = this.screenToWorld(r);
2477
+ this.view.centerX += i.x - s.x, this.view.centerY += i.y - s.y, this.scheduleRender(), this.emitViewChange();
2197
2478
  }
2198
2479
  zoomIn() {
2199
2480
  this.zoom(this.opts.wheelZoomFactor);
@@ -2201,8 +2482,8 @@ class zt {
2201
2482
  zoomOut() {
2202
2483
  this.zoom(1 / this.opts.wheelZoomFactor);
2203
2484
  }
2204
- panByScreenDelta(t, r) {
2205
- !Number.isFinite(t) || !Number.isFinite(r) || (this.view.centerX -= t / this.view.scale, this.view.centerY += r / this.view.scale, this.scheduleRender(), this.emitViewChange());
2485
+ panByScreenDelta(t, n) {
2486
+ !Number.isFinite(t) || !Number.isFinite(n) || (this.view.centerX -= t / this.view.scale, this.view.centerY += n / this.view.scale, this.scheduleRender(), this.emitViewChange());
2206
2487
  }
2207
2488
  setViewState(t) {
2208
2489
  if (![t.centerX, t.centerY, t.scale].every(Number.isFinite)) throw new Error("Invalid view state.");
@@ -2215,7 +2496,7 @@ class zt {
2215
2496
  return { ...this.bounds };
2216
2497
  }
2217
2498
  getStats() {
2218
- return Pr(this.stats);
2499
+ return ur(this.stats);
2219
2500
  }
2220
2501
  getZoomRatio() {
2221
2502
  return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
@@ -2239,37 +2520,39 @@ class zt {
2239
2520
  return this.cancelScheduledRender(), this.renderNow();
2240
2521
  }
2241
2522
  renderNow() {
2242
- var h;
2243
- const t = performance.now(), r = this.gl;
2244
- r.viewport(0, 0, this.canvas.width, this.canvas.height);
2245
- const i = bt(this.opts.background, [11, 16, 32, 255]);
2246
- r.clearColor(i[0] / 255, i[1] / 255, i[2] / 255, i[3] / 255), r.clear(r.COLOR_BUFFER_BIT), r.disable(r.DEPTH_TEST), r.enable(r.BLEND), r.blendFunc(r.SRC_ALPHA, r.ONE_MINUS_SRC_ALPHA);
2247
- let s = 0, n = 0;
2523
+ var l;
2524
+ const t = performance.now(), n = this.gl;
2525
+ n.viewport(0, 0, this.canvas.width, this.canvas.height);
2526
+ const r = Mt(this.opts.background, [11, 16, 32, 255]);
2527
+ n.clearColor(r[0] / 255, r[1] / 255, r[2] / 255, r[3] / 255), n.clear(n.COLOR_BUFFER_BIT), n.disable(n.DEPTH_TEST), n.enable(n.BLEND), n.blendFunc(n.SRC_ALPHA, n.ONE_MINUS_SRC_ALPHA);
2528
+ let i = 0, s = 0;
2248
2529
  const o = this.scene, a = this.visibleWorldBounds();
2249
2530
  if (o) {
2250
- r.useProgram(this.program.program), r.uniform2f(this.program.uViewCenter, this.view.centerX - o.origin.x, this.view.centerY - o.origin.y), r.uniform1f(this.program.uScale, this.view.scale * this.dpr), r.uniform2f(this.program.uViewport, this.canvas.width, this.canvas.height), r.uniform1f(this.program.uPointSize, Math.max(2, Math.min(12, 4 * this.dpr)));
2251
- const l = this.drawBatches(o.lineBatches, r.LINES, a);
2252
- s += l.visible, n += l.culled;
2253
- const f = this.drawBatches(o.triangleBatches, r.TRIANGLES, a);
2254
- s += f.visible, n += f.culled;
2255
- const u = this.drawBatches(o.pointBatches, r.POINTS, a);
2256
- s += u.visible, n += u.culled;
2531
+ n.useProgram(this.program.program), n.uniform2f(this.program.uViewCenter, this.view.centerX - o.origin.x, this.view.centerY - o.origin.y), n.uniform1f(this.program.uScale, this.view.scale * this.dpr), n.uniform2f(this.program.uViewport, this.canvas.width, this.canvas.height), n.uniform1f(this.program.uPointSize, Math.max(1, this.dpr));
2532
+ const h = this.drawBatches(o.lineBatches, n.LINES, a);
2533
+ i += h.visible, s += h.culled;
2534
+ const u = this.drawBatches(o.triangleBatches, n.TRIANGLES, a);
2535
+ i += u.visible, s += u.culled;
2536
+ const f = this.drawBatches(o.lineTypePointBatches, n.POINTS, a);
2537
+ i += f.visible, s += f.culled, n.uniform1f(this.program.uPointSize, Math.max(2, Math.min(12, 4 * this.dpr)));
2538
+ const m = this.drawBatches(o.pointBatches, n.POINTS, a);
2539
+ i += m.visible, s += m.culled;
2257
2540
  }
2258
2541
  this.renderOverlay(a);
2259
2542
  const c = performance.now() - t;
2260
- return this.stats = o ? { ...o.stats, renderElapsedMs: c, backend: "webgl", primitiveCount: o.primitiveCount, visiblePrimitiveCount: s, culledPrimitiveCount: n, gpuMemoryBytes: o.gpuMemoryBytes, buildElapsedMs: o.buildElapsedMs } : { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: c, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 }, (h = this.onStats) == null || h.call(this, this.getStats()), this.getStats();
2543
+ return this.stats = o ? { ...o.stats, renderElapsedMs: c, backend: "webgl", primitiveCount: o.primitiveCount, visiblePrimitiveCount: i, culledPrimitiveCount: s, gpuMemoryBytes: o.gpuMemoryBytes, buildElapsedMs: o.buildElapsedMs } : { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: c, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 }, (l = this.onStats) == null || l.call(this, this.getStats()), this.getStats();
2261
2544
  }
2262
- drawBatches(t, r, i) {
2263
- const s = this.gl;
2264
- let n = 0, o = 0;
2545
+ drawBatches(t, n, r) {
2546
+ const i = this.gl;
2547
+ let s = 0, o = 0;
2265
2548
  for (const a of t) {
2266
- if (!lt(a.bounds, i)) {
2549
+ if (!bt(a.bounds, r)) {
2267
2550
  o += a.primitiveCount;
2268
2551
  continue;
2269
2552
  }
2270
- s.bindBuffer(s.ARRAY_BUFFER, a.positionBuffer), s.enableVertexAttribArray(this.program.aPosition), s.vertexAttribPointer(this.program.aPosition, 2, s.FLOAT, !1, 0, 0), s.bindBuffer(s.ARRAY_BUFFER, a.colorBuffer), s.enableVertexAttribArray(this.program.aColor), s.vertexAttribPointer(this.program.aColor, 4, s.UNSIGNED_BYTE, !0, 0, 0), s.drawArrays(r, 0, a.vertexCount), n += a.primitiveCount;
2553
+ i.bindBuffer(i.ARRAY_BUFFER, a.positionBuffer), i.enableVertexAttribArray(this.program.aPosition), i.vertexAttribPointer(this.program.aPosition, 2, i.FLOAT, !1, 0, 0), i.bindBuffer(i.ARRAY_BUFFER, a.colorBuffer), i.enableVertexAttribArray(this.program.aColor), i.vertexAttribPointer(this.program.aColor, 4, i.UNSIGNED_BYTE, !0, 0, 0), i.drawArrays(n, 0, a.vertexCount), s += a.primitiveCount;
2271
2554
  }
2272
- return { visible: n, culled: o };
2555
+ return { visible: s, culled: o };
2273
2556
  }
2274
2557
  scheduleRender() {
2275
2558
  this.rafHandle || (this.rafHandle = window.requestAnimationFrame(() => {
@@ -2280,96 +2563,96 @@ class zt {
2280
2563
  this.rafHandle && (window.cancelAnimationFrame(this.rafHandle), this.rafHandle = 0);
2281
2564
  }
2282
2565
  renderOverlay(t) {
2283
- var s, n;
2284
- const r = this.overlayCtx, i = this.overlayCanvas;
2285
- !r || !i || (r.save(), r.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), r.clearRect(0, 0, this.cssWidth, this.cssHeight), this.opts.showPageBounds && ((n = (s = this.document) == null ? void 0 : s.pages) != null && n.length) && this.drawPageBoundsOverlay(r), this.scene && (this.drawImagesOverlay(r, this.scene.imageItems, t), this.drawTextOverlay(r, this.scene.textItems, t)), r.restore());
2566
+ var i, s;
2567
+ const n = this.overlayCtx, r = this.overlayCanvas;
2568
+ !n || !r || (n.save(), n.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), n.clearRect(0, 0, this.cssWidth, this.cssHeight), this.opts.showPageBounds && ((s = (i = this.document) == null ? void 0 : i.pages) != null && s.length) && this.drawPageBoundsOverlay(n), this.scene && (this.drawImagesOverlay(n, this.scene.imageItems, t), this.drawTextOverlay(n, this.scene.textItems, t)), n.restore());
2286
2569
  }
2287
2570
  drawPageBoundsOverlay(t) {
2288
- var r, i;
2289
- if ((i = (r = this.document) == null ? void 0 : r.pages) != null && i.length) {
2571
+ var n, r;
2572
+ if ((r = (n = this.document) == null ? void 0 : n.pages) != null && r.length) {
2290
2573
  t.save(), t.strokeStyle = "rgba(148, 163, 184, 0.34)", t.lineWidth = 1, t.setLineDash([8, 6]);
2291
- for (const s of this.document.pages) {
2292
- const n = this.worldToScreen({ x: 0, y: 0 }), o = this.worldToScreen({ x: s.width, y: s.height });
2293
- t.strokeRect(Math.min(n.x, o.x), Math.min(n.y, o.y), Math.abs(o.x - n.x), Math.abs(o.y - n.y));
2574
+ for (const i of this.document.pages) {
2575
+ const s = this.worldToScreen({ x: 0, y: 0 }), o = this.worldToScreen({ x: i.width, y: i.height });
2576
+ t.strokeRect(Math.min(s.x, o.x), Math.min(s.y, o.y), Math.abs(o.x - s.x), Math.abs(o.y - s.y));
2294
2577
  }
2295
2578
  t.restore();
2296
2579
  }
2297
2580
  }
2298
- drawTextOverlay(t, r, i) {
2299
- const s = this.opts.maxVisibleTextLabels;
2300
- let n = 0;
2301
- for (const o of r) {
2302
- if (n >= s) break;
2303
- if (!lt(o.bounds, i)) continue;
2581
+ drawTextOverlay(t, n, r) {
2582
+ const i = this.opts.maxVisibleTextLabels;
2583
+ let s = 0;
2584
+ for (const o of n) {
2585
+ if (s >= i) break;
2586
+ if (!bt(o.bounds, r)) continue;
2304
2587
  const a = Math.abs(o.height) * this.view.scale;
2305
2588
  if (a < this.opts.textMinPixelHeight) continue;
2306
2589
  const c = this.worldToScreen(o.point);
2307
2590
  if (c.x < -512 || c.y < -512 || c.x > this.cssWidth + 512 || c.y > this.cssHeight + 512) continue;
2308
2591
  t.save(), t.translate(c.x, c.y), t.rotate(-o.rotation);
2309
- const h = Math.max(4, Math.min(256, a));
2310
- t.font = `${h}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, t.fillStyle = o.color, t.globalAlpha = o.opacity, t.textBaseline = "alphabetic";
2311
- for (const [l, f] of o.text.split(/\r?\n/g).entries()) t.fillText(f, 0, l * h * 1.22);
2312
- t.restore(), n++;
2592
+ const l = Math.max(4, Math.min(256, a));
2593
+ t.font = `${l}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, t.fillStyle = o.color, t.globalAlpha = o.opacity, t.textBaseline = "alphabetic";
2594
+ for (const [h, u] of o.text.split(/\r?\n/g).entries()) t.fillText(u, 0, h * l * 1.22);
2595
+ t.restore(), s++;
2313
2596
  }
2314
2597
  }
2315
- drawImagesOverlay(t, r, i) {
2316
- for (const s of r) {
2317
- if (!lt(s.bounds, i)) continue;
2318
- const n = this.worldToScreen(s.point), o = this.worldToScreen({ x: s.point.x + s.width, y: s.point.y - s.height }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y);
2319
- if (!(h < 1 || l < 1)) {
2320
- if (s.source) {
2321
- const f = this.getImage(s.source);
2322
- if (f.complete && f.naturalWidth > 0) {
2323
- t.save(), t.globalAlpha = s.opacity, t.drawImage(f, a, c, h, l), t.restore();
2598
+ drawImagesOverlay(t, n, r) {
2599
+ for (const i of n) {
2600
+ if (!bt(i.bounds, r)) continue;
2601
+ const s = this.worldToScreen(i.point), o = this.worldToScreen({ x: i.point.x + i.width, y: i.point.y - i.height }), a = Math.min(s.x, o.x), c = Math.min(s.y, o.y), l = Math.abs(o.x - s.x), h = Math.abs(o.y - s.y);
2602
+ if (!(l < 1 || h < 1)) {
2603
+ if (i.source) {
2604
+ const u = this.getImage(i.source);
2605
+ if (u.complete && u.naturalWidth > 0) {
2606
+ t.save(), t.globalAlpha = i.opacity, t.drawImage(u, a, c, l, h), t.restore();
2324
2607
  continue;
2325
2608
  }
2326
- f.onload = () => this.scheduleRender();
2609
+ u.onload = () => this.scheduleRender();
2327
2610
  }
2328
- this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = s.color, t.globalAlpha = s.opacity, t.lineWidth = 1, t.strokeRect(a, c, h, l), t.beginPath(), t.moveTo(a, c), t.lineTo(a + h, c + l), t.moveTo(a + h, c), t.lineTo(a, c + l), t.stroke(), t.restore());
2611
+ this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = i.color, t.globalAlpha = i.opacity, t.lineWidth = 1, t.strokeRect(a, c, l, h), t.beginPath(), t.moveTo(a, c), t.lineTo(a + l, c + h), t.moveTo(a + l, c), t.lineTo(a, c + h), t.stroke(), t.restore());
2329
2612
  }
2330
2613
  }
2331
2614
  }
2332
2615
  getImage(t) {
2333
- let r = this.imageCache.get(t);
2334
- return r || (r = new Image(), r.src = t, this.imageCache.set(t, r)), r;
2616
+ let n = this.imageCache.get(t);
2617
+ return n || (n = new Image(), n.src = t, this.imageCache.set(t, n)), n;
2335
2618
  }
2336
2619
  createOverlayCanvas() {
2337
2620
  const t = this.canvas.parentElement;
2338
2621
  if (!t || typeof document > "u") return;
2339
2622
  window.getComputedStyle(t).position === "static" && (t.style.position = "relative");
2340
- const i = document.createElement("canvas");
2341
- i.className = "cad-viewer-text-overlay", i.setAttribute("aria-hidden", "true"), i.style.position = "absolute", i.style.inset = "0", i.style.width = "100%", i.style.height = "100%", i.style.pointerEvents = "none", i.style.zIndex = "1";
2342
- const s = i.getContext("2d");
2343
- s && (t.appendChild(i), this.overlayCanvas = i, this.overlayCtx = s);
2623
+ const r = document.createElement("canvas");
2624
+ r.className = "cad-viewer-text-overlay", r.setAttribute("aria-hidden", "true"), r.style.position = "absolute", r.style.inset = "0", r.style.width = "100%", r.style.height = "100%", r.style.pointerEvents = "none", r.style.zIndex = "1";
2625
+ const i = r.getContext("2d");
2626
+ i && (t.appendChild(r), this.overlayCanvas = r, this.overlayCtx = i);
2344
2627
  }
2345
- resizeOverlay(t, r) {
2346
- this.overlayCanvas && (this.overlayCanvas.width !== t || this.overlayCanvas.height !== r) && (this.overlayCanvas.width = t, this.overlayCanvas.height = r);
2628
+ resizeOverlay(t, n) {
2629
+ this.overlayCanvas && (this.overlayCanvas.width !== t || this.overlayCanvas.height !== n) && (this.overlayCanvas.width = t, this.overlayCanvas.height = n);
2347
2630
  }
2348
2631
  bindEvents() {
2349
2632
  const t = this.eventController.signal;
2350
- this.canvas.addEventListener("wheel", (i) => {
2351
- i.preventDefault();
2352
- const s = i.deltaY < 0 ? this.opts.wheelZoomFactor : 1 / this.opts.wheelZoomFactor;
2353
- this.zoom(s, { x: i.offsetX, y: i.offsetY });
2354
- }, { passive: !1, signal: t }), this.canvas.addEventListener("pointerdown", (i) => {
2355
- this.canvas.setPointerCapture(i.pointerId), this.isDragging = !0, this.lastPointer = { x: i.clientX, y: i.clientY }, this.canvas.classList.add("is-dragging");
2356
- }, { signal: t }), this.canvas.addEventListener("pointermove", (i) => {
2357
- !this.isDragging || !this.lastPointer || (this.panByScreenDelta(i.clientX - this.lastPointer.x, i.clientY - this.lastPointer.y), this.lastPointer = { x: i.clientX, y: i.clientY });
2633
+ this.canvas.addEventListener("wheel", (r) => {
2634
+ r.preventDefault();
2635
+ const i = r.deltaY < 0 ? this.opts.wheelZoomFactor : 1 / this.opts.wheelZoomFactor;
2636
+ this.zoom(i, { x: r.offsetX, y: r.offsetY });
2637
+ }, { passive: !1, signal: t }), this.canvas.addEventListener("pointerdown", (r) => {
2638
+ this.canvas.setPointerCapture(r.pointerId), this.isDragging = !0, this.lastPointer = { x: r.clientX, y: r.clientY }, this.canvas.classList.add("is-dragging");
2639
+ }, { signal: t }), this.canvas.addEventListener("pointermove", (r) => {
2640
+ !this.isDragging || !this.lastPointer || (this.panByScreenDelta(r.clientX - this.lastPointer.x, r.clientY - this.lastPointer.y), this.lastPointer = { x: r.clientX, y: r.clientY });
2358
2641
  }, { signal: t });
2359
- const r = (i) => {
2360
- i && this.canvas.hasPointerCapture(i.pointerId) && this.canvas.releasePointerCapture(i.pointerId), this.isDragging = !1, this.lastPointer = void 0, this.canvas.classList.remove("is-dragging");
2642
+ const n = (r) => {
2643
+ r && this.canvas.hasPointerCapture(r.pointerId) && this.canvas.releasePointerCapture(r.pointerId), this.isDragging = !1, this.lastPointer = void 0, this.canvas.classList.remove("is-dragging");
2361
2644
  };
2362
- this.canvas.addEventListener("pointerup", r, { signal: t }), this.canvas.addEventListener("pointercancel", () => r(), { signal: t }), this.canvas.addEventListener("webglcontextlost", (i) => {
2363
- i.preventDefault(), this.cancelScheduledRender();
2645
+ this.canvas.addEventListener("pointerup", n, { signal: t }), this.canvas.addEventListener("pointercancel", () => n(), { signal: t }), this.canvas.addEventListener("webglcontextlost", (r) => {
2646
+ r.preventDefault(), this.cancelScheduledRender();
2364
2647
  }, { signal: t });
2365
2648
  }
2366
2649
  visibleWorldBounds() {
2367
- const t = this.cssWidth / Math.max(this.view.scale, 1e-12) / 2, r = this.cssHeight / Math.max(this.view.scale, 1e-12) / 2;
2650
+ const t = this.cssWidth / Math.max(this.view.scale, 1e-12) / 2, n = this.cssHeight / Math.max(this.view.scale, 1e-12) / 2;
2368
2651
  return {
2369
2652
  minX: this.view.centerX - t,
2370
2653
  maxX: this.view.centerX + t,
2371
- minY: this.view.centerY - r,
2372
- maxY: this.view.centerY + r
2654
+ minY: this.view.centerY - n,
2655
+ maxY: this.view.centerY + n
2373
2656
  };
2374
2657
  }
2375
2658
  get cssWidth() {
@@ -2381,11 +2664,14 @@ class zt {
2381
2664
  clampScale(t) {
2382
2665
  return Math.min(this.opts.maxScale, Math.max(this.opts.minScale, t));
2383
2666
  }
2667
+ boundsOptions() {
2668
+ return { maxInsertDepth: this.opts.maxInsertDepth, maxCurveSegments: this.opts.maxCurveSegments };
2669
+ }
2384
2670
  disposeScene() {
2385
2671
  if (!this.scene) return;
2386
2672
  const t = this.gl;
2387
- for (const r of [...this.scene.lineBatches, ...this.scene.triangleBatches, ...this.scene.pointBatches])
2388
- t.deleteBuffer(r.positionBuffer), t.deleteBuffer(r.colorBuffer);
2673
+ for (const n of [...this.scene.lineBatches, ...this.scene.triangleBatches, ...this.scene.lineTypePointBatches, ...this.scene.pointBatches])
2674
+ t.deleteBuffer(n.positionBuffer), t.deleteBuffer(n.colorBuffer);
2389
2675
  this.scene = void 0;
2390
2676
  }
2391
2677
  emitViewChange() {
@@ -2399,13 +2685,13 @@ class zt {
2399
2685
  });
2400
2686
  }
2401
2687
  }
2402
- function te() {
2688
+ function Ee() {
2403
2689
  if (typeof document > "u") return !1;
2404
2690
  const e = document.createElement("canvas");
2405
2691
  return !!(e.getContext("webgl2") ?? e.getContext("webgl") ?? e.getContext("experimental-webgl"));
2406
2692
  }
2407
- function dr(e, t) {
2408
- const r = {
2693
+ function nr(e, t) {
2694
+ const n = {
2409
2695
  alpha: !1,
2410
2696
  antialias: t.antialias ?? !0,
2411
2697
  depth: !1,
@@ -2413,9 +2699,9 @@ function dr(e, t) {
2413
2699
  preserveDrawingBuffer: t.preserveDrawingBuffer ?? !1,
2414
2700
  powerPreference: t.powerPreference ?? "high-performance"
2415
2701
  };
2416
- return e.getContext("webgl2", r) ?? e.getContext("webgl", r) ?? e.getContext("experimental-webgl", r) ?? void 0;
2702
+ return e.getContext("webgl2", n) ?? e.getContext("webgl", n) ?? e.getContext("experimental-webgl", n) ?? void 0;
2417
2703
  }
2418
- function ur(e) {
2704
+ function rr(e) {
2419
2705
  const t = `
2420
2706
  attribute vec2 a_position;
2421
2707
  attribute vec4 a_color;
@@ -2434,81 +2720,83 @@ function ur(e) {
2434
2720
  gl_PointSize = u_pointSize;
2435
2721
  v_color = a_color;
2436
2722
  }
2437
- `, r = `
2723
+ `, n = `
2438
2724
  precision mediump float;
2439
2725
  varying vec4 v_color;
2440
2726
  void main() {
2441
2727
  gl_FragColor = v_color;
2442
2728
  }
2443
- `, i = _t(e, e.VERTEX_SHADER, t), s = _t(e, e.FRAGMENT_SHADER, r), n = e.createProgram();
2444
- if (!n) throw new Error("Failed to create WebGL program.");
2445
- if (e.attachShader(n, i), e.attachShader(n, s), e.linkProgram(n), !e.getProgramParameter(n, e.LINK_STATUS)) {
2446
- const l = e.getProgramInfoLog(n) ?? "Unknown WebGL program link error.";
2447
- throw e.deleteProgram(n), new Error(l);
2448
- }
2449
- e.deleteShader(i), e.deleteShader(s);
2450
- const o = e.getUniformLocation(n, "u_viewCenter"), a = e.getUniformLocation(n, "u_scale"), c = e.getUniformLocation(n, "u_viewport"), h = e.getUniformLocation(n, "u_pointSize");
2451
- if (!o || !a || !c || !h) throw new Error("Failed to resolve WebGL shader uniforms.");
2729
+ `, r = ne(e, e.VERTEX_SHADER, t), i = ne(e, e.FRAGMENT_SHADER, n), s = e.createProgram();
2730
+ if (!s) throw new Error("Failed to create WebGL program.");
2731
+ if (e.attachShader(s, r), e.attachShader(s, i), e.linkProgram(s), !e.getProgramParameter(s, e.LINK_STATUS)) {
2732
+ const h = e.getProgramInfoLog(s) ?? "Unknown WebGL program link error.";
2733
+ throw e.deleteProgram(s), new Error(h);
2734
+ }
2735
+ e.deleteShader(r), e.deleteShader(i);
2736
+ const o = e.getUniformLocation(s, "u_viewCenter"), a = e.getUniformLocation(s, "u_scale"), c = e.getUniformLocation(s, "u_viewport"), l = e.getUniformLocation(s, "u_pointSize");
2737
+ if (!o || !a || !c || !l) throw new Error("Failed to resolve WebGL shader uniforms.");
2452
2738
  return {
2453
- program: n,
2454
- aPosition: e.getAttribLocation(n, "a_position"),
2455
- aColor: e.getAttribLocation(n, "a_color"),
2739
+ program: s,
2740
+ aPosition: e.getAttribLocation(s, "a_position"),
2741
+ aColor: e.getAttribLocation(s, "a_color"),
2456
2742
  uViewCenter: o,
2457
2743
  uScale: a,
2458
2744
  uViewport: c,
2459
- uPointSize: h
2745
+ uPointSize: l
2460
2746
  };
2461
2747
  }
2462
- function _t(e, t, r) {
2463
- const i = e.createShader(t);
2464
- if (!i) throw new Error("Failed to create WebGL shader.");
2465
- if (e.shaderSource(i, r), e.compileShader(i), !e.getShaderParameter(i, e.COMPILE_STATUS)) {
2466
- const s = e.getShaderInfoLog(i) ?? "Unknown WebGL shader compile error.";
2467
- throw e.deleteShader(i), new Error(s);
2748
+ function ne(e, t, n) {
2749
+ const r = e.createShader(t);
2750
+ if (!r) throw new Error("Failed to create WebGL shader.");
2751
+ if (e.shaderSource(r, n), e.compileShader(r), !e.getShaderParameter(r, e.COMPILE_STATUS)) {
2752
+ const i = e.getShaderInfoLog(r) ?? "Unknown WebGL shader compile error.";
2753
+ throw e.deleteShader(r), new Error(i);
2468
2754
  }
2469
- return i;
2755
+ return r;
2470
2756
  }
2471
- function mr(e, t) {
2472
- let r = 0;
2473
- const i = (a) => a.map((c) => {
2474
- const h = Ht(e, c.positions), l = Ht(e, c.colors), f = c.positions.byteLength + c.colors.byteLength;
2475
- return r += f, {
2757
+ function ir(e, t) {
2758
+ let n = 0;
2759
+ const r = (c) => c.map((l) => {
2760
+ const h = re(e, l.positions), u = re(e, l.colors), f = l.positions.byteLength + l.colors.byteLength;
2761
+ return n += f, {
2476
2762
  positionBuffer: h,
2477
- colorBuffer: l,
2478
- vertexCount: c.positions.length / 2,
2479
- primitiveCount: c.primitiveCount,
2480
- bounds: c.bounds,
2763
+ colorBuffer: u,
2764
+ vertexCount: l.positions.length / 2,
2765
+ primitiveCount: l.primitiveCount,
2766
+ bounds: l.bounds,
2481
2767
  gpuBytes: f
2482
2768
  };
2483
- }), s = i(t.lineBatches), n = i(t.triangleBatches), o = i(t.pointBatches);
2769
+ }), i = r(t.lineBatches), s = r(t.triangleBatches), o = r(t.lineTypePointBatches), a = r(t.pointBatches);
2484
2770
  return {
2485
2771
  origin: t.origin,
2486
- lineBatches: s,
2487
- triangleBatches: n,
2488
- pointBatches: o,
2772
+ lineBatches: i,
2773
+ triangleBatches: s,
2774
+ lineTypePointBatches: o,
2775
+ pointBatches: a,
2489
2776
  textItems: t.textItems,
2490
2777
  imageItems: t.imageItems,
2491
2778
  stats: t.stats,
2492
2779
  primitiveCount: t.primitiveCount,
2493
- gpuMemoryBytes: r,
2780
+ gpuMemoryBytes: n,
2494
2781
  buildElapsedMs: t.buildElapsedMs
2495
2782
  };
2496
2783
  }
2497
- function Ht(e, t) {
2498
- const r = e.createBuffer();
2499
- if (!r) throw new Error("Failed to create WebGL buffer.");
2500
- return e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW), r;
2784
+ function re(e, t) {
2785
+ const n = e.createBuffer();
2786
+ if (!n) throw new Error("Failed to create WebGL buffer.");
2787
+ return e.bindBuffer(e.ARRAY_BUFFER, n), e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW), n;
2501
2788
  }
2502
- function pr(e, t, r) {
2503
- const i = performance.now(), s = O(r) ? { x: (r.minX + r.maxX) / 2, y: (r.minY + r.maxY) / 2 } : { x: 0, y: 0 }, n = new gr(e, t, r, s);
2504
- for (const a of e.entities) n.addEntityTracked(a, 0);
2505
- const o = n.finalize();
2506
- return o.buildElapsedMs = performance.now() - i, o;
2789
+ function sr(e, t, n) {
2790
+ const r = performance.now(), i = I(n) ? { x: (n.minX + n.maxX) / 2, y: (n.minY + n.maxY) / 2 } : { x: 0, y: 0 }, s = new or(e, t, n, i);
2791
+ for (const a of e.entities) s.addEntityTracked(a, 0);
2792
+ const o = s.finalize();
2793
+ return o.buildElapsedMs = performance.now() - r, o;
2507
2794
  }
2508
- class gr {
2509
- constructor(t, r, i, s) {
2795
+ class or {
2796
+ constructor(t, n, r, i) {
2510
2797
  d(this, "lineBuckets", /* @__PURE__ */ new Map());
2511
2798
  d(this, "triangleBuckets", /* @__PURE__ */ new Map());
2799
+ d(this, "lineTypePointBuckets", /* @__PURE__ */ new Map());
2512
2800
  d(this, "pointBuckets", /* @__PURE__ */ new Map());
2513
2801
  d(this, "textItems", []);
2514
2802
  d(this, "imageItems", []);
@@ -2516,27 +2804,28 @@ class gr {
2516
2804
  d(this, "tileSize");
2517
2805
  d(this, "maxVerticesPerBatch");
2518
2806
  d(this, "primitiveCount", 0);
2519
- this.document = t, this.opts = r, this.bounds = i, this.origin = s;
2520
- const n = O(i) ? Math.max(i.maxX - i.minX, i.maxY - i.minY, 1e-9) : 1;
2521
- this.tileSize = r.enableSpatialIndex ? n / Math.max(8, r.spatialIndexCellCount) : Number.POSITIVE_INFINITY, this.maxVerticesPerBatch = Math.max(4096, Math.floor(r.maxVerticesPerBatch));
2807
+ this.document = t, this.opts = n, this.bounds = r, this.origin = i;
2808
+ const s = I(r) ? Math.max(r.maxX - r.minX, r.maxY - r.minY, 1e-9) : 1;
2809
+ this.tileSize = n.enableSpatialIndex ? s / Math.max(8, n.spatialIndexCellCount) : Number.POSITIVE_INFINITY, this.maxVerticesPerBatch = Math.max(4096, Math.floor(n.maxVerticesPerBatch));
2522
2810
  }
2523
- addEntityTracked(t, r) {
2811
+ addEntityTracked(t, n) {
2524
2812
  this.stats.total++;
2525
- const i = String(t.type ?? "UNKNOWN").toUpperCase();
2526
- this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
2527
- const s = this.lookupLayer(t.layer);
2528
- if (t.isVisible === !1 || !Kt(s)) {
2813
+ const r = String(t.type ?? "UNKNOWN").toUpperCase();
2814
+ this.stats.byType[r] = (this.stats.byType[r] ?? 0) + 1;
2815
+ const i = this.lookupLayer(t.layer);
2816
+ if (t.isVisible === !1 || !pe(i)) {
2529
2817
  this.stats.skipped++;
2530
2818
  return;
2531
2819
  }
2532
- this.addEntity(t, i, r);
2820
+ this.addEntity(t, r, n);
2533
2821
  }
2534
2822
  finalize() {
2535
- const t = ct(this.lineBuckets, this.maxVerticesPerBatch), r = ct(this.triangleBuckets, this.maxVerticesPerBatch), i = ct(this.pointBuckets, this.maxVerticesPerBatch);
2823
+ const t = at(this.lineBuckets, this.maxVerticesPerBatch), n = at(this.triangleBuckets, this.maxVerticesPerBatch), r = at(this.lineTypePointBuckets, this.maxVerticesPerBatch), i = at(this.pointBuckets, this.maxVerticesPerBatch);
2536
2824
  return this.stats.primitiveCount = this.primitiveCount, {
2537
2825
  origin: this.origin,
2538
2826
  lineBatches: t,
2539
- triangleBatches: r,
2827
+ triangleBatches: n,
2828
+ lineTypePointBatches: r,
2540
2829
  pointBatches: i,
2541
2830
  textItems: this.textItems,
2542
2831
  imageItems: this.imageItems,
@@ -2545,8 +2834,8 @@ class gr {
2545
2834
  buildElapsedMs: 0
2546
2835
  };
2547
2836
  }
2548
- addEntity(t, r, i) {
2549
- switch (t.kind ?? R(r)) {
2837
+ addEntity(t, n, r) {
2838
+ switch (t.kind ?? J(n)) {
2550
2839
  case "line":
2551
2840
  return this.addLineEntity(t);
2552
2841
  case "circle":
@@ -2562,7 +2851,7 @@ class gr {
2562
2851
  case "point":
2563
2852
  return this.addPointEntity(t);
2564
2853
  case "insert":
2565
- return this.addInsertEntity(t, i);
2854
+ return this.addInsertEntity(t, r);
2566
2855
  case "solid":
2567
2856
  return this.addSolidEntity(t);
2568
2857
  case "hatch":
@@ -2574,165 +2863,175 @@ class gr {
2574
2863
  case "image":
2575
2864
  return this.addImageEntity(t);
2576
2865
  case "viewport":
2577
- return this.markSkipped(r);
2866
+ return this.markSkipped(n);
2578
2867
  default:
2579
- this.stats.unsupported[r] = (this.stats.unsupported[r] ?? 0) + 1, this.stats.skipped++, this.opts.showUnsupportedMarkers && this.addUnsupportedMarker(t);
2868
+ this.stats.unsupported[n] = (this.stats.unsupported[n] ?? 0) + 1, this.stats.skipped++, this.opts.showUnsupportedMarkers && this.addUnsupportedMarker(t);
2580
2869
  }
2581
2870
  }
2582
2871
  addLineEntity(t) {
2583
- if (!m(t.startPoint) || !m(t.endPoint)) return this.markSkipped("LINE");
2584
- this.addSegment(t.startPoint, t.endPoint, this.strokeBytes(t)), this.stats.drawn++;
2872
+ if (!g(t.startPoint) || !g(t.endPoint)) return this.markSkipped("LINE");
2873
+ this.addPolyline([t.startPoint, t.endPoint], !1, this.strokeBytes(t), t), this.stats.drawn++;
2585
2874
  }
2586
2875
  addCircleEntity(t) {
2587
- const r = t.center, i = Number(t.radius);
2588
- if (!m(r) || !Number.isFinite(i)) return this.markSkipped("CIRCLE");
2589
- const s = Math.max(16, Math.min(this.opts.maxCurveSegments, Math.ceil(Math.sqrt(Math.abs(i)) * 12))), n = K(r, i, 0, Math.PI * 2, !0, s);
2590
- this.addPolyline(n, !0, this.strokeBytes(t)), this.stats.drawn++;
2876
+ const n = t.center, r = Number(t.radius);
2877
+ if (!g(n) || !Number.isFinite(r)) return this.markSkipped("CIRCLE");
2878
+ const i = Math.max(16, Math.min(this.opts.maxCurveSegments, Math.ceil(Math.sqrt(Math.abs(r)) * 12))), s = Q(n, r, 0, Math.PI * 2, !0, i);
2879
+ this.addPolyline(s, !0, this.strokeBytes(t), t), this.stats.drawn++;
2591
2880
  }
2592
2881
  addArcEntity(t) {
2593
- const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
2594
- if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
2595
- this.addPolyline(K(r, i, s, n, !0, this.opts.maxCurveSegments), !1, this.strokeBytes(t)), this.stats.drawn++;
2882
+ const n = t.center, r = Number(t.radius), i = Number(t.startAngle), s = Number(t.endAngle);
2883
+ if (!g(n) || !Number.isFinite(r) || !Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped("ARC");
2884
+ this.addPolyline(Q(n, r, i, s, !0, this.opts.maxCurveSegments), !1, this.strokeBytes(t), t), this.stats.drawn++;
2596
2885
  }
2597
2886
  addPolylineEntity(t) {
2598
- const r = t.vertices ?? t.points;
2599
- if (!Array.isArray(r) || r.length < 2) return this.markSkipped(String(t.type));
2600
- const i = !!t.isClosed || (Number(t.flag) & 1) === 1, s = [], n = i ? r.length : r.length - 1;
2601
- for (let o = 0; o < n; o++) {
2602
- const a = r[o], c = r[(o + 1) % r.length];
2603
- if (!m(a) || !m(c)) continue;
2604
- const h = jt(a, c, Number(a.bulge ?? 0), Math.max(4, Math.min(24, this.opts.maxCurveSegments / 4)));
2605
- s.length > 0 && h.shift(), s.push(...h);
2887
+ const n = t.vertices ?? t.points;
2888
+ if (!Array.isArray(n) || n.length < 2) return this.markSkipped(String(t.type));
2889
+ const r = ae(t), i = [], s = r ? n.length : n.length - 1;
2890
+ for (let o = 0; o < s; o++) {
2891
+ const a = n[o], c = n[(o + 1) % n.length];
2892
+ if (!g(a) || !g(c)) continue;
2893
+ const l = fe(a, c, Number(a.bulge ?? 0), Math.max(4, Math.min(24, this.opts.maxCurveSegments / 4)));
2894
+ i.length > 0 && l.shift(), i.push(...l);
2606
2895
  }
2607
- if (s.length < 2) return this.markSkipped(String(t.type));
2608
- this.addPolyline(s, i, this.strokeBytes(t)), this.stats.drawn++;
2896
+ if (i.length < 2) return this.markSkipped(String(t.type));
2897
+ this.addPolyline(i, r, this.strokeBytes(t), t), this.stats.drawn++;
2609
2898
  }
2610
2899
  addEllipseEntity(t) {
2611
- if (!m(t.center) || !m(t.majorAxisEndPoint)) return this.markSkipped("ELLIPSE");
2612
- const r = J(t.center, t.majorAxisEndPoint, Number(t.axisRatio ?? 1), Number(t.startAngle ?? 0), Number(t.endAngle ?? Math.PI * 2), this.opts.maxCurveSegments), i = Math.abs(Number(t.endAngle ?? Math.PI * 2) - Number(t.startAngle ?? 0)) >= Math.PI * 2 - 1e-6;
2613
- this.addPolyline(r, i, this.strokeBytes(t)), this.stats.drawn++;
2900
+ if (!g(t.center) || !g(t.majorAxisEndPoint)) return this.markSkipped("ELLIPSE");
2901
+ const n = Lt(t.center, t.majorAxisEndPoint, Number(t.axisRatio ?? 1), Number(t.startAngle ?? 0), Number(t.endAngle ?? Math.PI * 2), this.opts.maxCurveSegments), r = Math.abs(Number(t.endAngle ?? Math.PI * 2) - Number(t.startAngle ?? 0)) >= Math.PI * 2 - 1e-6;
2902
+ this.addPolyline(n, r, this.strokeBytes(t), t), this.stats.drawn++;
2614
2903
  }
2615
2904
  addTextEntity(t) {
2616
- const r = t.insertionPoint ?? t.startPoint ?? t.center, i = Gt(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
2617
- if (!m(r) || !i || !Number.isFinite(s)) return this.markSkipped(String(t.type));
2618
- const n = x(r), o = Math.max(1, i.split(/\r?\n/g).reduce((c, h) => Math.max(c, h.length), 0)) * Math.abs(s) * 0.62, a = Math.max(1, i.split(/\r?\n/g).length) * Math.abs(s) * 1.22;
2905
+ const n = t.insertionPoint ?? t.startPoint ?? t.center, r = ue(String(t.text ?? t.value ?? "")), i = Number(t.textHeight ?? t.height ?? 1);
2906
+ if (!g(n) || !r || !Number.isFinite(i)) return this.markSkipped(String(t.type));
2907
+ const s = P(n), o = Math.max(1, r.split(/\r?\n/g).reduce((c, l) => Math.max(c, l.length), 0)) * Math.abs(i) * 0.62, a = Math.max(1, r.split(/\r?\n/g).length) * Math.abs(i) * 1.22;
2619
2908
  this.textItems.push({
2620
- point: n,
2621
- text: i,
2622
- height: s,
2909
+ point: s,
2910
+ text: r,
2911
+ height: i,
2623
2912
  rotation: Number(t.rotation ?? 0),
2624
- color: D(t, this.document, this.colorOptions()),
2625
- opacity: A(Number(t.opacity ?? 1), 0, 1),
2626
- bounds: { minX: n.x - o * 0.1, minY: n.y - a, maxX: n.x + o, maxY: n.y + a }
2913
+ color: V(t, this.document, this.colorOptions()),
2914
+ opacity: _(Number(t.opacity ?? 1), 0, 1),
2915
+ bounds: { minX: s.x - o * 0.1, minY: s.y - a, maxX: s.x + o, maxY: s.y + a }
2627
2916
  }), this.stats.drawn++;
2628
2917
  }
2629
2918
  addPointEntity(t) {
2630
- const r = t.point ?? t.location ?? t.center ?? t.insertionPoint;
2631
- if (!m(r)) return this.markSkipped("POINT");
2632
- this.addPoint(r, this.strokeBytes(t)), this.stats.drawn++;
2633
- }
2634
- addInsertEntity(t, r) {
2635
- const i = this.lookupBlock(t.blockName ?? t.name);
2636
- if (i && r < this.opts.maxInsertDepth) {
2637
- const n = tt(t, i.basePoint ?? { x: 0, y: 0 });
2638
- for (const o of i.entities) {
2639
- const a = Jt(o, t, this.document, this.colorOptions());
2640
- this.addEntityTracked(et(a, n), r + 1);
2919
+ const n = t.point ?? t.location ?? t.center ?? t.insertionPoint;
2920
+ if (!g(n)) return this.markSkipped("POINT");
2921
+ this.addPoint(n, this.strokeBytes(t)), this.stats.drawn++;
2922
+ }
2923
+ addInsertEntity(t, n) {
2924
+ const r = this.lookupBlock(t.blockName ?? t.name);
2925
+ if (r && n < this.opts.maxInsertDepth) {
2926
+ const s = Bt(t, r.basePoint ?? { x: 0, y: 0 });
2927
+ for (const o of r.entities) {
2928
+ const a = ge(o, t, this.document, this.colorOptions()), c = Se(a, t, this.document);
2929
+ this.addEntityTracked($(c, s), n + 1);
2641
2930
  }
2642
2931
  return;
2643
2932
  }
2644
- const s = t.insertionPoint;
2645
- if (!m(s)) return this.markSkipped("INSERT");
2646
- if (this.addPoint(s, this.strokeBytes(t)), Array.isArray(t.attribs)) for (const n of t.attribs) this.addTextEntity(n);
2933
+ const i = t.insertionPoint;
2934
+ if (!g(i)) return this.markSkipped("INSERT");
2935
+ if (this.addPoint(i, this.strokeBytes(t)), Array.isArray(t.attribs)) for (const s of t.attribs) this.addTextEntity(s);
2647
2936
  this.stats.drawn++;
2648
2937
  }
2649
2938
  addSolidEntity(t) {
2650
- const r = t.vertices ?? t.points;
2651
- if (!Array.isArray(r) || r.length < 3) return this.markSkipped(String(t.type));
2652
- const i = r.filter(m).map(x);
2653
- if (i.length < 3) return this.markSkipped(String(t.type));
2654
- const s = this.fillBytes(t) ?? this.strokeBytes(t);
2655
- this.addTriangleFan(i, s), this.addPolyline(i, !0, this.strokeBytes(t)), this.stats.drawn++;
2939
+ const n = t.vertices ?? t.points;
2940
+ if (!Array.isArray(n) || n.length < 3) return this.markSkipped(String(t.type));
2941
+ const r = n.filter(g).map(P);
2942
+ if (r.length < 3) return this.markSkipped(String(t.type));
2943
+ const i = this.fillBytes(t) ?? this.strokeBytes(t);
2944
+ this.addTriangleFan(r, i), this.addPolyline(r, !0, this.strokeBytes(t), t), this.stats.drawn++;
2656
2945
  }
2657
2946
  addHatchEntity(t) {
2658
2947
  var o;
2659
- const r = t.loops;
2660
- if (!Array.isArray(r) || r.length === 0) return this.markSkipped("HATCH");
2661
- const i = this.strokeBytes(t), s = this.fillBytes(t);
2662
- let n = !1;
2663
- for (const a of r) {
2664
- const c = (o = a.commands) != null && o.length ? Yt(a.commands, this.opts.maxCurveSegments) : (a.vertices ?? []).filter(m).map(x);
2665
- c.length < 2 || (this.addPolyline(c, !0, i), s && c.length >= 3 && this.addTriangleFan(c, s), n = !0);
2948
+ const n = t.loops;
2949
+ if (!Array.isArray(n) || n.length === 0) return this.markSkipped("HATCH");
2950
+ const r = this.strokeBytes(t), i = this.fillBytes(t);
2951
+ let s = !1;
2952
+ for (const a of n) {
2953
+ const c = (o = a.commands) != null && o.length ? ie(a.commands, this.opts.maxCurveSegments) : (a.vertices ?? []).filter(g).map(P);
2954
+ c.length < 2 || (this.addPolyline(c, !0, r, t), i && c.length >= 3 && this.addTriangleFan(c, i), s = !0);
2666
2955
  }
2667
- if (!n) return this.markSkipped("HATCH");
2956
+ if (!s) return this.markSkipped("HATCH");
2668
2957
  this.stats.drawn++;
2669
2958
  }
2670
2959
  addSplineEntity(t) {
2671
- var i;
2672
- const r = (i = t.fitPoints) != null && i.length ? t.fitPoints : t.controlPoints;
2673
- if (!r || r.length < 2) return this.markSkipped("SPLINE");
2674
- this.addPolyline(r.filter(m).map(x), !!t.isClosed, this.strokeBytes(t)), this.stats.drawn++;
2960
+ var r;
2961
+ const n = (r = t.fitPoints) != null && r.length ? t.fitPoints : t.controlPoints;
2962
+ if (!n || n.length < 2) return this.markSkipped("SPLINE");
2963
+ this.addPolyline(n.filter(g).map(P), !!t.isClosed, this.strokeBytes(t), t), this.stats.drawn++;
2675
2964
  }
2676
2965
  addPathEntity(t) {
2677
- var s;
2678
- if (!((s = t.commands) != null && s.length)) return this.markSkipped(String(t.type));
2679
- const r = Yt(t.commands, this.opts.maxCurveSegments);
2680
- if (r.length < 2) return this.markSkipped(String(t.type));
2681
- this.addPolyline(r, !1, this.strokeBytes(t));
2682
- const i = this.fillBytes(t);
2683
- i && r.length >= 3 && this.addTriangleFan(r, i), this.stats.drawn++;
2966
+ var i;
2967
+ if (!((i = t.commands) != null && i.length)) return this.markSkipped(String(t.type));
2968
+ const n = ie(t.commands, this.opts.maxCurveSegments);
2969
+ if (n.length < 2) return this.markSkipped(String(t.type));
2970
+ this.addPolyline(n, !1, this.strokeBytes(t), t);
2971
+ const r = this.fillBytes(t);
2972
+ r && n.length >= 3 && this.addTriangleFan(n, r), this.stats.drawn++;
2684
2973
  }
2685
2974
  addImageEntity(t) {
2686
- const r = t.insertionPoint;
2687
- if (!m(r)) return this.markSkipped(String(t.type));
2688
- const i = Number(t.width ?? 32), s = Number(t.height ?? 32);
2689
- if (!Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped(String(t.type));
2690
- const n = x(r), o = ht([n, { x: n.x + i, y: n.y - s }]);
2691
- this.imageItems.push({ point: n, width: i, height: s, source: t.imageDataUrl ?? t.imageSource, color: D(t, this.document, this.colorOptions()), opacity: A(Number(t.opacity ?? 1), 0, 1), bounds: o }), this.stats.drawn++;
2975
+ const n = t.insertionPoint;
2976
+ if (!g(n)) return this.markSkipped(String(t.type));
2977
+ const r = Number(t.width ?? 32), i = Number(t.height ?? 32);
2978
+ if (!Number.isFinite(r) || !Number.isFinite(i)) return this.markSkipped(String(t.type));
2979
+ const s = P(n), o = gt([s, { x: s.x + r, y: s.y - i }]);
2980
+ this.imageItems.push({ point: s, width: r, height: i, source: t.imageDataUrl ?? t.imageSource, color: V(t, this.document, this.colorOptions()), opacity: _(Number(t.opacity ?? 1), 0, 1), bounds: o }), this.stats.drawn++;
2692
2981
  }
2693
2982
  addUnsupportedMarker(t) {
2694
- const r = ee(t);
2695
- r && this.addPoint(r, this.strokeBytes(t));
2696
- }
2697
- addPolyline(t, r, i) {
2698
- const s = t.filter(m).map(x);
2699
- if (!(s.length < 2)) {
2700
- for (let n = 0; n < s.length - 1; n++) this.addSegment(s[n], s[n + 1], i);
2701
- r && this.addSegment(s[s.length - 1], s[0], i);
2702
- }
2703
- }
2704
- addSegment(t, r, i) {
2705
- if (!m(t) || !m(r) || Math.hypot(t.x - r.x, t.y - r.y) <= 1e-14) return;
2706
- const s = this.batchFor(this.lineBuckets, ht([t, r]));
2707
- T(s, t, i, this.origin), T(s, r, i, this.origin), s.primitiveCount++, this.primitiveCount++;
2708
- }
2709
- addPoint(t, r) {
2710
- const i = this.batchFor(this.pointBuckets, xr(t));
2711
- T(i, t, r, this.origin), i.primitiveCount++, this.primitiveCount++;
2983
+ const n = lr(t);
2984
+ n && this.addPoint(n, this.strokeBytes(t));
2712
2985
  }
2713
- addTriangleFan(t, r) {
2714
- const i = t.filter(m).map(x);
2715
- if (i.length < 3) return;
2716
- const s = ht(i), n = this.batchFor(this.triangleBuckets, s);
2717
- for (let o = 1; o < i.length - 1; o++)
2718
- T(n, i[0], r, this.origin), T(n, i[o], r, this.origin), T(n, i[o + 1], r, this.origin), n.primitiveCount++, this.primitiveCount++;
2719
- }
2720
- batchFor(t, r) {
2721
- const i = this.bucketKey(r);
2722
- let s = t.get(i);
2723
- return s || (s = br(), t.set(i, s)), v(s.bounds, { x: r.minX, y: r.minY }), v(s.bounds, { x: r.maxX, y: r.maxY }), s;
2986
+ addPolyline(t, n, r, i) {
2987
+ const s = t.filter(g).map(P);
2988
+ if (s.length < 2) return;
2989
+ const o = i ? Nt(i, this.document) : void 0;
2990
+ if (o) {
2991
+ const a = Dt(s, n, o);
2992
+ for (const [c, l] of a.segments) this.addSegment(c, l, r);
2993
+ for (const c of a.dots) this.addLineTypePoint(c, r);
2994
+ return;
2995
+ }
2996
+ for (let a = 0; a < s.length - 1; a++) this.addSegment(s[a], s[a + 1], r);
2997
+ n && this.addSegment(s[s.length - 1], s[0], r);
2998
+ }
2999
+ addSegment(t, n, r) {
3000
+ if (!g(t) || !g(n) || Math.hypot(t.x - n.x, t.y - n.y) <= 1e-14) return;
3001
+ const i = this.batchFor(this.lineBuckets, gt([t, n]));
3002
+ D(i, t, r, this.origin), D(i, n, r, this.origin), i.primitiveCount++, this.primitiveCount++;
3003
+ }
3004
+ addPoint(t, n) {
3005
+ const r = this.batchFor(this.pointBuckets, se(t));
3006
+ D(r, t, n, this.origin), r.primitiveCount++, this.primitiveCount++;
3007
+ }
3008
+ addLineTypePoint(t, n) {
3009
+ const r = this.batchFor(this.lineTypePointBuckets, se(t));
3010
+ D(r, t, n, this.origin), r.primitiveCount++, this.primitiveCount++;
3011
+ }
3012
+ addTriangleFan(t, n) {
3013
+ const r = t.filter(g).map(P);
3014
+ if (r.length < 3) return;
3015
+ const i = gt(r), s = this.batchFor(this.triangleBuckets, i);
3016
+ for (let o = 1; o < r.length - 1; o++)
3017
+ D(s, r[0], n, this.origin), D(s, r[o], n, this.origin), D(s, r[o + 1], n, this.origin), s.primitiveCount++, this.primitiveCount++;
3018
+ }
3019
+ batchFor(t, n) {
3020
+ const r = this.bucketKey(n);
3021
+ let i = t.get(r);
3022
+ return i || (i = ar(), t.set(r, i)), S(i.bounds, { x: n.minX, y: n.minY }), S(i.bounds, { x: n.maxX, y: n.maxY }), i;
2724
3023
  }
2725
3024
  bucketKey(t) {
2726
3025
  if (!Number.isFinite(this.tileSize)) return "all";
2727
- const r = (t.minX + t.maxX) / 2, i = (t.minY + t.maxY) / 2, s = Math.floor((r - this.bounds.minX) / this.tileSize), n = Math.floor((i - this.bounds.minY) / this.tileSize);
2728
- return `${s}:${n}`;
3026
+ const n = (t.minX + t.maxX) / 2, r = (t.minY + t.maxY) / 2, i = Math.floor((n - this.bounds.minX) / this.tileSize), s = Math.floor((r - this.bounds.minY) / this.tileSize);
3027
+ return `${i}:${s}`;
2729
3028
  }
2730
3029
  strokeBytes(t) {
2731
- return bt(D(t, this.document, this.colorOptions()), [255, 255, 255, 255], A(Number(t.opacity ?? 1), 0, 1));
3030
+ return Mt(V(t, this.document, this.colorOptions()), [255, 255, 255, 255], _(Number(t.opacity ?? 1), 0, 1));
2732
3031
  }
2733
3032
  fillBytes(t) {
2734
- const r = mt(t, this.document, this.colorOptions());
2735
- return r ? bt(r, [255, 255, 255, 255], A(Number(t.opacity ?? 1), 0, 1)) : void 0;
3033
+ const n = Pt(t, this.document, this.colorOptions());
3034
+ return n ? Mt(n, [255, 255, 255, 255], _(Number(t.opacity ?? 1), 0, 1)) : void 0;
2736
3035
  }
2737
3036
  colorOptions() {
2738
3037
  return { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast };
@@ -2742,141 +3041,99 @@ class gr {
2742
3041
  }
2743
3042
  lookupLayer(t) {
2744
3043
  if (t)
2745
- return this.document.layers[t] ?? this.document.layers[t.toLowerCase()] ?? Object.values(this.document.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
3044
+ return this.document.layers[t] ?? this.document.layers[t.toLowerCase()] ?? Object.values(this.document.layers).find((n) => n.name.toLowerCase() === t.toLowerCase());
2746
3045
  }
2747
3046
  lookupBlock(t) {
2748
3047
  if (t)
2749
- return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((r) => r.name.toLowerCase() === t.toLowerCase());
3048
+ return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((n) => n.name.toLowerCase() === t.toLowerCase());
2750
3049
  }
2751
3050
  }
2752
- function br() {
2753
- return { positions: [], colors: [], bounds: N(), primitiveCount: 0 };
3051
+ function ar() {
3052
+ return { positions: [], colors: [], bounds: L(), primitiveCount: 0 };
2754
3053
  }
2755
- function T(e, t, r, i) {
2756
- e.positions.push(t.x - i.x, t.y - i.y), e.colors.push(r[0], r[1], r[2], r[3]);
3054
+ function D(e, t, n, r) {
3055
+ e.positions.push(t.x - r.x, t.y - r.y), e.colors.push(n[0], n[1], n[2], n[3]);
2757
3056
  }
2758
- function ct(e, t) {
2759
- const r = [];
2760
- for (const i of e.values()) {
2761
- const s = i.positions.length / 2;
2762
- if (s <= 0 || !O(i.bounds)) continue;
2763
- if (s <= t) {
2764
- r.push({ positions: new Float32Array(i.positions), colors: new Uint8Array(i.colors), bounds: { ...i.bounds }, primitiveCount: i.primitiveCount });
3057
+ function at(e, t) {
3058
+ const n = [];
3059
+ for (const r of e.values()) {
3060
+ const i = r.positions.length / 2;
3061
+ if (i <= 0 || !I(r.bounds)) continue;
3062
+ if (i <= t) {
3063
+ n.push({ positions: new Float32Array(r.positions), colors: new Uint8Array(r.colors), bounds: { ...r.bounds }, primitiveCount: r.primitiveCount });
2765
3064
  continue;
2766
3065
  }
2767
- const n = vr(i), o = Math.max(n, Math.floor(t / n) * n);
2768
- for (let a = 0; a < s; a += o) {
2769
- const c = Math.min(s, a + o), h = i.positions.slice(a * 2, c * 2), l = i.colors.slice(a * 4, c * 4), f = N();
2770
- for (let u = 0; u < h.length; u += 2) v(f, { x: h[u], y: h[u + 1] });
2771
- r.push({ positions: new Float32Array(h), colors: new Uint8Array(l), bounds: { ...i.bounds }, primitiveCount: Math.floor((c - a) / n) });
3066
+ const s = cr(r), o = Math.max(s, Math.floor(t / s) * s);
3067
+ for (let a = 0; a < i; a += o) {
3068
+ const c = Math.min(i, a + o), l = r.positions.slice(a * 2, c * 2), h = r.colors.slice(a * 4, c * 4), u = L();
3069
+ for (let f = 0; f < l.length; f += 2) S(u, { x: l[f], y: l[f + 1] });
3070
+ n.push({ positions: new Float32Array(l), colors: new Uint8Array(h), bounds: { ...r.bounds }, primitiveCount: Math.floor((c - a) / s) });
2772
3071
  }
2773
3072
  }
2774
- return r;
3073
+ return n;
2775
3074
  }
2776
- function vr(e) {
3075
+ function cr(e) {
2777
3076
  const t = e.positions.length / 2;
2778
3077
  return t === e.primitiveCount ? 1 : t === e.primitiveCount * 3 ? 3 : 2;
2779
3078
  }
2780
- function yr(e, t) {
2781
- var n;
2782
- const r = N();
2783
- if ((n = e.pages) != null && n.length)
2784
- for (const o of e.pages)
2785
- v(r, { x: 0, y: 0 }), v(r, { x: o.width, y: o.height });
2786
- const i = (o) => {
2787
- if (o)
2788
- return e.blocks[o] ?? e.blocks[o.toLowerCase()] ?? Object.values(e.blocks).find((a) => a.name.toLowerCase() === o.toLowerCase());
2789
- }, s = (o, a) => {
2790
- const c = String(o.type ?? "").toUpperCase(), h = o.kind ?? R(c);
2791
- if (h === "insert") {
2792
- const l = i(o.blockName ?? o.name);
2793
- if (l && a < t.maxInsertDepth) {
2794
- const f = tt(o, l.basePoint ?? { x: 0, y: 0 });
2795
- for (const u of l.entities) s(et(u, f), a + 1);
2796
- return;
2797
- }
2798
- }
2799
- if (h === "line")
2800
- m(o.startPoint) && v(r, o.startPoint), m(o.endPoint) && v(r, o.endPoint);
2801
- else if (h === "circle" || h === "arc")
2802
- m(o.center) && Number.isFinite(o.radius) && Vt(r, o.center, Number(o.radius));
2803
- else if (h === "polyline" || h === "solid" || h === "spline")
2804
- for (const l of [...o.vertices ?? [], ...o.points ?? [], ...o.controlPoints ?? [], ...o.fitPoints ?? []]) m(l) && v(r, l);
2805
- else if (h === "ellipse")
2806
- m(o.center) && m(o.majorAxisEndPoint) && J(o.center, o.majorAxisEndPoint, Number(o.axisRatio ?? 1), Number(o.startAngle ?? 0), Number(o.endAngle ?? Math.PI * 2), t.maxCurveSegments).forEach((l) => v(r, l));
2807
- else if (h === "path")
2808
- for (const l of o.commands ?? []) for (const f of l.points) v(r, f);
2809
- else if (h === "hatch")
2810
- for (const l of o.loops ?? []) {
2811
- for (const f of l.vertices ?? []) v(r, f);
2812
- for (const f of l.commands ?? []) for (const u of f.points) v(r, u);
2813
- }
2814
- else {
2815
- const l = ee(o);
2816
- l && v(r, l);
2817
- }
2818
- };
2819
- for (const o of e.entities) s(o, 0);
2820
- return $t(r);
2821
- }
2822
- function Yt(e, t) {
2823
- const r = [];
2824
- let i, s;
2825
- const n = (o) => {
2826
- (!r.length || Math.hypot(r[r.length - 1].x - o.x, r[r.length - 1].y - o.y) > 1e-12) && r.push(x(o)), i = x(o);
3079
+ function ie(e, t) {
3080
+ const n = [];
3081
+ let r, i;
3082
+ const s = (o) => {
3083
+ (!n.length || Math.hypot(n[n.length - 1].x - o.x, n[n.length - 1].y - o.y) > 1e-12) && n.push(P(o)), r = P(o);
2827
3084
  };
2828
3085
  for (const o of e)
2829
3086
  if (o.cmd === "M")
2830
- i = x(o.points[0]), s = i, n(i);
3087
+ r = P(o.points[0]), i = r, s(r);
2831
3088
  else if (o.cmd === "L")
2832
- n(o.points[0]);
2833
- else if (o.cmd === "Q" && i && o.points.length >= 2) {
2834
- const a = i, [c, h] = o.points, l = Math.max(4, Math.min(t, 24));
2835
- for (let f = 1; f <= l; f++) {
2836
- const u = f / l, p = 1 - u;
2837
- n({ x: p * p * a.x + 2 * p * u * c.x + u * u * h.x, y: p * p * a.y + 2 * p * u * c.y + u * u * h.y });
3089
+ s(o.points[0]);
3090
+ else if (o.cmd === "Q" && r && o.points.length >= 2) {
3091
+ const a = r, [c, l] = o.points, h = Math.max(4, Math.min(t, 24));
3092
+ for (let u = 1; u <= h; u++) {
3093
+ const f = u / h, m = 1 - f;
3094
+ s({ x: m * m * a.x + 2 * m * f * c.x + f * f * l.x, y: m * m * a.y + 2 * m * f * c.y + f * f * l.y });
2838
3095
  }
2839
- } else if (o.cmd === "C" && i && o.points.length >= 3) {
2840
- const a = i, [c, h, l] = o.points, f = Math.max(6, Math.min(t, 32));
2841
- for (let u = 1; u <= f; u++) {
2842
- const p = u / f, g = 1 - p;
2843
- n({
2844
- x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p * h.x + p ** 3 * l.x,
2845
- y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p * h.y + p ** 3 * l.y
3096
+ } else if (o.cmd === "C" && r && o.points.length >= 3) {
3097
+ const a = r, [c, l, h] = o.points, u = Math.max(6, Math.min(t, 32));
3098
+ for (let f = 1; f <= u; f++) {
3099
+ const m = f / u, p = 1 - m;
3100
+ s({
3101
+ x: p ** 3 * a.x + 3 * p * p * m * c.x + 3 * p * m * m * l.x + m ** 3 * h.x,
3102
+ y: p ** 3 * a.y + 3 * p * p * m * c.y + 3 * p * m * m * l.y + m ** 3 * h.y
2846
3103
  });
2847
3104
  }
2848
- } else o.cmd === "Z" && s && n(s);
2849
- return r;
3105
+ } else o.cmd === "Z" && i && s(i);
3106
+ return n;
2850
3107
  }
2851
- function ee(e) {
3108
+ function lr(e) {
2852
3109
  for (const t of ["startPoint", "insertionPoint", "center", "point", "location"]) {
2853
- const r = e[t];
2854
- if (m(r)) return x(r);
3110
+ const n = e[t];
3111
+ if (g(n)) return P(n);
2855
3112
  }
2856
- if (Array.isArray(e.vertices) && m(e.vertices[0])) return x(e.vertices[0]);
3113
+ if (Array.isArray(e.vertices) && g(e.vertices[0])) return P(e.vertices[0]);
2857
3114
  if (Array.isArray(e.commands) && e.commands.length) {
2858
- const t = e.commands.find((r) => r.points.length > 0);
2859
- if (t) return x(t.points[0]);
3115
+ const t = e.commands.find((n) => n.points.length > 0);
3116
+ if (t) return P(t.points[0]);
2860
3117
  }
2861
3118
  }
2862
- function ht(e) {
2863
- const t = N();
2864
- for (const r of e) v(t, r);
3119
+ function gt(e) {
3120
+ const t = L();
3121
+ for (const n of e) S(t, n);
2865
3122
  return t;
2866
3123
  }
2867
- function xr(e) {
3124
+ function se(e) {
2868
3125
  return { minX: e.x, minY: e.y, maxX: e.x, maxY: e.y };
2869
3126
  }
2870
- function lt(e, t) {
3127
+ function bt(e, t) {
2871
3128
  return e.minX <= t.maxX && e.maxX >= t.minX && e.minY <= t.maxY && e.maxY >= t.minY;
2872
3129
  }
2873
- function wr(e, t) {
3130
+ function hr(e, t) {
2874
3131
  return t.trueColorByteOrder !== void 0 && t.trueColorByteOrder !== e.trueColorByteOrder || t.contrastMode !== void 0 && t.contrastMode !== e.contrastMode || t.minColorContrast !== void 0 && t.minColorContrast !== e.minColorContrast || t.foreground !== void 0 && t.foreground !== e.foreground || t.background !== void 0 && t.background !== e.background || t.maxInsertDepth !== void 0 && t.maxInsertDepth !== e.maxInsertDepth || t.maxCurveSegments !== void 0 && t.maxCurveSegments !== e.maxCurveSegments || t.spatialIndexCellCount !== void 0 && t.spatialIndexCellCount !== e.spatialIndexCellCount || t.maxVerticesPerBatch !== void 0 && t.maxVerticesPerBatch !== e.maxVerticesPerBatch || t.enableSpatialIndex !== void 0 && t.enableSpatialIndex !== e.enableSpatialIndex;
2875
3132
  }
2876
- function Cr(e, t) {
3133
+ function fr(e, t) {
2877
3134
  return { ...e.stats, renderElapsedMs: t, backend: "webgl", primitiveCount: e.primitiveCount, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: e.gpuMemoryBytes, buildElapsedMs: e.buildElapsedMs };
2878
3135
  }
2879
- function Pr(e) {
3136
+ function ur(e) {
2880
3137
  return {
2881
3138
  total: e.total,
2882
3139
  drawn: e.drawn,
@@ -2892,27 +3149,27 @@ function Pr(e) {
2892
3149
  buildElapsedMs: e.buildElapsedMs
2893
3150
  };
2894
3151
  }
2895
- function bt(e, t, r = 1) {
2896
- const i = e.trim().toLowerCase();
2897
- let s;
2898
- if (/^#[0-9a-f]{3}$/i.test(i))
2899
- s = [parseInt(i[1] + i[1], 16), parseInt(i[2] + i[2], 16), parseInt(i[3] + i[3], 16), 255];
2900
- else if (/^#[0-9a-f]{6}$/i.test(i))
2901
- s = [parseInt(i.slice(1, 3), 16), parseInt(i.slice(3, 5), 16), parseInt(i.slice(5, 7), 16), 255];
3152
+ function Mt(e, t, n = 1) {
3153
+ const r = e.trim().toLowerCase();
3154
+ let i;
3155
+ if (/^#[0-9a-f]{3}$/i.test(r))
3156
+ i = [parseInt(r[1] + r[1], 16), parseInt(r[2] + r[2], 16), parseInt(r[3] + r[3], 16), 255];
3157
+ else if (/^#[0-9a-f]{6}$/i.test(r))
3158
+ i = [parseInt(r.slice(1, 3), 16), parseInt(r.slice(3, 5), 16), parseInt(r.slice(5, 7), 16), 255];
2902
3159
  else {
2903
- const o = i.match(/^rgba?\(([^)]+)\)$/i);
3160
+ const o = r.match(/^rgba?\(([^)]+)\)$/i);
2904
3161
  if (o) {
2905
- const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((l) => l.includes("%")), h = a.map((l) => Number(l.replace("%", "")));
2906
- h.length >= 3 && h.slice(0, 3).every(Number.isFinite) && (s = [X(c ? h[0] * 2.55 : h[0]), X(c ? h[1] * 2.55 : h[1]), X(c ? h[2] * 2.55 : h[2]), X((Number.isFinite(h[3]) ? h[3] : 1) * 255)]);
3162
+ const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((h) => h.includes("%")), l = a.map((h) => Number(h.replace("%", "")));
3163
+ l.length >= 3 && l.slice(0, 3).every(Number.isFinite) && (i = [Z(c ? l[0] * 2.55 : l[0]), Z(c ? l[1] * 2.55 : l[1]), Z(c ? l[2] * 2.55 : l[2]), Z((Number.isFinite(l[3]) ? l[3] : 1) * 255)]);
2907
3164
  }
2908
3165
  }
2909
- const n = s ?? t;
2910
- return [n[0], n[1], n[2], X(n[3] * r)];
3166
+ const s = i ?? t;
3167
+ return [s[0], s[1], s[2], Z(s[3] * n)];
2911
3168
  }
2912
- function X(e) {
3169
+ function Z(e) {
2913
3170
  return Math.max(0, Math.min(255, Math.round(e)));
2914
3171
  }
2915
- class kr {
3172
+ class dr {
2916
3173
  constructor(t = {}) {
2917
3174
  d(this, "canvas");
2918
3175
  d(this, "renderer");
@@ -2921,92 +3178,92 @@ class kr {
2921
3178
  d(this, "options");
2922
3179
  d(this, "lastResult");
2923
3180
  d(this, "activeNativeLoader");
2924
- var r;
2925
- if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ?? qe(t), t.loaders) for (const i of t.loaders) this.registry.register(i);
3181
+ var n;
3182
+ if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ?? Sn(t), t.loaders) for (const r of t.loaders) this.registry.register(r);
2926
3183
  if (this.canvas = t.canvas ?? document.createElement("canvas"), this.canvas.classList.add("cad-viewer-canvas"), t.container)
2927
3184
  t.container.classList.add("cad-viewer-container"), t.canvas || (this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", t.container.appendChild(this.canvas)), this.nativeHost = t.nativeHost ?? document.createElement("div"), this.nativeHost.classList.add("cad-viewer-native-host"), t.nativeHost || t.container.appendChild(this.nativeHost);
2928
3185
  else if (t.nativeHost)
2929
3186
  this.nativeHost = t.nativeHost, this.nativeHost.classList.add("cad-viewer-native-host");
2930
- else if ((r = t.canvas) != null && r.parentElement) {
3187
+ else if ((n = t.canvas) != null && n.parentElement) {
2931
3188
  t.canvas.parentElement.classList.add("cad-viewer-container");
2932
- const i = document.createElement("div");
2933
- i.classList.add("cad-viewer-native-host"), t.canvas.parentElement.appendChild(i), this.nativeHost = i;
3189
+ const r = document.createElement("div");
3190
+ r.classList.add("cad-viewer-native-host"), t.canvas.parentElement.appendChild(r), this.nativeHost = r;
2934
3191
  }
2935
- this.renderer = Nr(t.renderer ?? "auto", this.canvas, t.canvasOptions), this.renderer.onStats = (i) => {
2936
- var s, n;
2937
- return (n = (s = this.options).onRenderStats) == null ? void 0 : n.call(s, i);
2938
- }, this.renderer.onViewChange = (i) => {
2939
- var s, n;
2940
- return (n = (s = this.options).onViewChange) == null ? void 0 : n.call(s, i);
3192
+ this.renderer = pr(t.renderer ?? "auto", this.canvas, t.canvasOptions), this.renderer.onStats = (r) => {
3193
+ var i, s;
3194
+ return (s = (i = this.options).onRenderStats) == null ? void 0 : s.call(i, r);
3195
+ }, this.renderer.onViewChange = (r) => {
3196
+ var i, s;
3197
+ return (s = (i = this.options).onViewChange) == null ? void 0 : s.call(i, r);
2941
3198
  };
2942
3199
  }
2943
3200
  registerLoader(t) {
2944
3201
  return this.registry.register(t), this;
2945
3202
  }
2946
- async loadFile(t, r = {}) {
2947
- var i, s;
2948
- return (s = (i = this.options).onLoadStart) == null || s.call(i, t), this.loadThroughRegistry({ file: t, fileName: t.name }, r, t.name);
3203
+ async loadFile(t, n = {}) {
3204
+ var r, i;
3205
+ return (i = (r = this.options).onLoadStart) == null || i.call(r, t), this.loadThroughRegistry({ file: t, fileName: t.name }, n, t.name);
2949
3206
  }
2950
- async loadBuffer(t, r, i = {}) {
2951
- var s, n;
2952
- return (n = (s = this.options).onLoadStart) == null || n.call(s, t), this.loadThroughRegistry({ buffer: t, fileName: r }, i, r);
3207
+ async loadBuffer(t, n, r = {}) {
3208
+ var i, s;
3209
+ return (s = (i = this.options).onLoadStart) == null || s.call(i, t), this.loadThroughRegistry({ buffer: t, fileName: n }, r, n);
2953
3210
  }
2954
- async load(t, r = {}) {
2955
- var i, s, n;
2956
- return (s = (i = this.options).onLoadStart) == null || s.call(i, t), this.loadThroughRegistry(t, r, t.fileName ?? ((n = t.file) == null ? void 0 : n.name));
3211
+ async load(t, n = {}) {
3212
+ var r, i, s;
3213
+ return (i = (r = this.options).onLoadStart) == null || i.call(r, t), this.loadThroughRegistry(t, n, t.fileName ?? ((s = t.file) == null ? void 0 : s.name));
2957
3214
  }
2958
- setDocument(t, r) {
2959
- var s, n;
3215
+ setDocument(t, n) {
3216
+ var i, s;
2960
3217
  this.deactivateNativeRenderer();
2961
- const i = {
3218
+ const r = {
2962
3219
  document: t,
2963
3220
  raw: t.raw,
2964
3221
  bytes: 0,
2965
3222
  elapsedMs: 0,
2966
3223
  format: t.format,
2967
3224
  warnings: t.warnings,
2968
- summary: G(t),
2969
- fileName: r
3225
+ summary: it(t),
3226
+ fileName: n
2970
3227
  };
2971
- return this.renderer.setDocument(t), this.options.autoFit || this.renderer.render(), this.lastResult = i, (n = (s = this.options).onLoad) == null || n.call(s, i), i;
3228
+ return this.renderer.setDocument(t), this.options.autoFit || this.renderer.render(), this.lastResult = r, (s = (i = this.options).onLoad) == null || s.call(i, r), r;
2972
3229
  }
2973
- fit() {
2974
- var t, r;
2975
- this.activeNativeLoader ? (r = (t = this.activeNativeLoader).fit) == null || r.call(t) : this.renderer.fitToView();
3230
+ fit(t) {
3231
+ var n, r;
3232
+ this.activeNativeLoader ? (r = (n = this.activeNativeLoader).fit) == null || r.call(n) : this.renderer.fitToView(0.92, t);
2976
3233
  }
2977
3234
  zoomIn() {
2978
- var t, r;
2979
- this.activeNativeLoader ? (r = (t = this.activeNativeLoader).zoomIn) == null || r.call(t) : this.renderer.zoomIn();
3235
+ var t, n;
3236
+ this.activeNativeLoader ? (n = (t = this.activeNativeLoader).zoomIn) == null || n.call(t) : this.renderer.zoomIn();
2980
3237
  }
2981
3238
  zoomOut() {
2982
- var t, r;
2983
- this.activeNativeLoader ? (r = (t = this.activeNativeLoader).zoomOut) == null || r.call(t) : this.renderer.zoomOut();
3239
+ var t, n;
3240
+ this.activeNativeLoader ? (n = (t = this.activeNativeLoader).zoomOut) == null || n.call(t) : this.renderer.zoomOut();
2984
3241
  }
2985
3242
  resize() {
2986
- var t, r;
2987
- this.activeNativeLoader ? (r = (t = this.activeNativeLoader).resize) == null || r.call(t) : this.renderer.resize();
3243
+ var t, n;
3244
+ this.activeNativeLoader ? (n = (t = this.activeNativeLoader).resize) == null || n.call(t) : this.renderer.resize();
2988
3245
  }
2989
3246
  setCanvasOptions(t) {
2990
- var r, i;
2991
- this.options.canvasOptions = { ...this.options.canvasOptions ?? {}, ...t }, this.renderer.setOptions(t), this.activeNativeLoader && ((i = (r = this.activeNativeLoader).setNativeOptions) == null || i.call(r, {
3247
+ var n, r;
3248
+ this.options.canvasOptions = { ...this.options.canvasOptions ?? {}, ...t }, this.renderer.setOptions(t), this.activeNativeLoader && ((r = (n = this.activeNativeLoader).setNativeOptions) == null || r.call(n, {
2992
3249
  ...this.mergeLoadOptions({}),
2993
3250
  dwfBackground: t.background ?? this.options.dwfBackground
2994
3251
  }));
2995
3252
  }
2996
3253
  async preloadDwg(t = {}) {
2997
- const r = this.registry.list().find((i) => i.id === "dwg");
2998
- if (!(r != null && r.preload)) throw new Error("The registered DWG loader does not support preload().");
2999
- return r.preload(this.mergeLoadOptions(t));
3254
+ const n = this.registry.list().find((r) => r.id === "dwg");
3255
+ if (!(n != null && n.preload)) throw new Error("The registered DWG loader does not support preload().");
3256
+ return n.preload(this.mergeLoadOptions(t));
3000
3257
  }
3001
3258
  clear() {
3002
3259
  this.lastResult = void 0, this.deactivateNativeRenderer(), this.renderer.clear();
3003
3260
  }
3004
3261
  destroy() {
3005
- var t, r, i;
3262
+ var t, n, r;
3006
3263
  this.deactivateNativeRenderer();
3007
- for (const s of this.registry.list()) {
3008
- const n = s;
3009
- (t = n.terminateWorker) == null || t.call(n), (r = n.unmount) == null || r.call(n), (i = n.destroy) == null || i.call(n);
3264
+ for (const i of this.registry.list()) {
3265
+ const s = i;
3266
+ (t = s.terminateWorker) == null || t.call(s), (n = s.unmount) == null || n.call(s), (r = s.destroy) == null || r.call(s);
3010
3267
  }
3011
3268
  this.renderer.destroy();
3012
3269
  }
@@ -3017,135 +3274,324 @@ class kr {
3017
3274
  var t;
3018
3275
  return this.activeNativeLoader ? (t = this.lastResult) == null ? void 0 : t.document : this.renderer.getDocument();
3019
3276
  }
3277
+ getSourceDocument() {
3278
+ var t;
3279
+ return this.activeNativeLoader ? (t = this.lastResult) == null ? void 0 : t.document : this.renderer.getSourceDocument();
3280
+ }
3020
3281
  getZoomPercent() {
3021
3282
  return this.activeNativeLoader ? 100 : this.renderer.getZoomPercent();
3022
3283
  }
3023
3284
  isNativeRendererActive() {
3024
3285
  return !!this.activeNativeLoader;
3025
3286
  }
3026
- async loadThroughRegistry(t, r, i) {
3027
- var s, n;
3287
+ async loadThroughRegistry(t, n, r) {
3288
+ var i, s;
3028
3289
  try {
3029
- const o = this.mergeLoadOptions(r);
3030
- ft(o.signal);
3290
+ const o = this.mergeLoadOptions(n);
3291
+ yt(o.signal);
3031
3292
  const a = await this.registry.detect(t), c = { ...t, buffer: a.bytes };
3032
- if (Ke(a.loader))
3033
- return await this.applyNativeLoadResult(a.loader, c, o, i);
3034
- const h = await a.loader.load(c, o);
3035
- return this.applyLoadResult(h, i);
3293
+ if (Nn(a.loader))
3294
+ return await this.applyNativeLoadResult(a.loader, c, o, r);
3295
+ const l = await a.loader.load(c, o);
3296
+ return this.applyLoadResult(l, r);
3036
3297
  } catch (o) {
3037
- const a = Sr(o);
3038
- throw (n = (s = this.options).onError) == null || n.call(s, a), a;
3298
+ const a = mr(o);
3299
+ throw (s = (i = this.options).onError) == null || s.call(i, a), a;
3039
3300
  }
3040
3301
  }
3041
- applyLoadResult(t, r) {
3042
- var s, n, o, a;
3043
- this.deactivateNativeRenderer(), (n = (s = this.options).onLoadProgress) == null || n.call(s, { phase: "render", format: t.format, message: "Rendering normalized CAD scene…", percent: 96 }), this.renderer.setDocument(t.document), this.options.autoFit || this.renderer.render();
3044
- const i = {
3302
+ applyLoadResult(t, n) {
3303
+ var i, s, o, a;
3304
+ this.deactivateNativeRenderer(), (s = (i = this.options).onLoadProgress) == null || s.call(i, { phase: "render", format: t.format, message: "Rendering normalized CAD scene…", percent: 96 }), this.renderer.setDocument(t.document), this.options.autoFit || this.renderer.render();
3305
+ const r = {
3045
3306
  ...t,
3046
- fileName: r,
3047
- summary: G(t.document)
3307
+ fileName: n,
3308
+ summary: it(t.document)
3048
3309
  };
3049
- return this.lastResult = i, (a = (o = this.options).onLoad) == null || a.call(o, i), i;
3310
+ return this.lastResult = r, (a = (o = this.options).onLoad) == null || a.call(o, r), r;
3050
3311
  }
3051
- async applyNativeLoadResult(t, r, i, s) {
3052
- var n, o, a;
3312
+ async applyNativeLoadResult(t, n, r, i) {
3313
+ var s, o, a;
3053
3314
  if (!this.nativeHost)
3054
3315
  throw new Error("Native DWF rendering requires CadViewerOptions.container, nativeHost, or a canvas parent element.");
3055
- ft(i.signal), this.renderer.clear(), (n = this.activeNativeLoader) == null || n.unmount(), this.activeNativeLoader = t, this.canvas.style.display = "none", this.nativeHost.classList.add("is-active");
3316
+ yt(r.signal), this.renderer.clear(), (s = this.activeNativeLoader) == null || s.unmount(), this.activeNativeLoader = t, this.canvas.style.display = "none", this.nativeHost.classList.add("is-active");
3056
3317
  try {
3057
- const c = await t.mount(r, this.nativeHost, i);
3058
- ft(i.signal);
3059
- const h = {
3318
+ const c = await t.mount(n, this.nativeHost, r);
3319
+ yt(r.signal);
3320
+ const l = {
3060
3321
  ...c,
3061
- fileName: s,
3062
- summary: G(c.document)
3322
+ fileName: i,
3323
+ summary: it(c.document)
3063
3324
  };
3064
- return this.lastResult = h, this.emitNativeRenderStats(c), (a = (o = this.options).onLoad) == null || a.call(o, h), h;
3325
+ return this.lastResult = l, this.emitNativeRenderStats(c), (a = (o = this.options).onLoad) == null || a.call(o, l), l;
3065
3326
  } catch (c) {
3066
3327
  throw this.deactivateNativeRenderer(), c;
3067
3328
  }
3068
3329
  }
3069
3330
  deactivateNativeRenderer() {
3070
- var t, r;
3331
+ var t, n;
3071
3332
  if (!this.activeNativeLoader && !((t = this.nativeHost) != null && t.classList.contains("is-active"))) {
3072
3333
  this.canvas.style.display = "";
3073
3334
  return;
3074
3335
  }
3075
- (r = this.activeNativeLoader) == null || r.unmount(), this.activeNativeLoader = void 0, this.nativeHost && (this.nativeHost.classList.remove("is-active"), this.nativeHost.replaceChildren()), this.canvas.style.display = "";
3336
+ (n = this.activeNativeLoader) == null || n.unmount(), this.activeNativeLoader = void 0, this.nativeHost && (this.nativeHost.classList.remove("is-active"), this.nativeHost.replaceChildren()), this.canvas.style.display = "";
3076
3337
  }
3077
3338
  emitNativeRenderStats(t) {
3078
- var o, a, c, h;
3079
- const r = t.document.metadata, i = Number(((o = r.nativeRenderStats) == null ? void 0 : o.commands) ?? t.document.entities.length ?? 0), n = String(((a = r.nativeRenderStats) == null ? void 0 : a.backend) ?? "webgl").includes("webgl") ? "webgl" : "canvas2d";
3080
- (h = (c = this.options).onRenderStats) == null || h.call(c, {
3081
- total: i,
3082
- drawn: i,
3339
+ var o, a, c, l;
3340
+ const n = t.document.metadata, r = Number(((o = n.nativeRenderStats) == null ? void 0 : o.commands) ?? t.document.entities.length ?? 0), s = String(((a = n.nativeRenderStats) == null ? void 0 : a.backend) ?? "webgl").includes("webgl") ? "webgl" : "canvas2d";
3341
+ (l = (c = this.options).onRenderStats) == null || l.call(c, {
3342
+ total: r,
3343
+ drawn: r,
3083
3344
  skipped: 0,
3084
- byType: G(t.document).byType,
3345
+ byType: it(t.document).byType,
3085
3346
  unsupported: {},
3086
3347
  renderElapsedMs: t.elapsedMs,
3087
- backend: n,
3088
- primitiveCount: i,
3089
- visiblePrimitiveCount: i,
3348
+ backend: s,
3349
+ primitiveCount: r,
3350
+ visiblePrimitiveCount: r,
3090
3351
  culledPrimitiveCount: 0,
3091
3352
  gpuMemoryBytes: void 0,
3092
3353
  buildElapsedMs: t.elapsedMs
3093
3354
  });
3094
3355
  }
3095
3356
  mergeLoadOptions(t) {
3096
- const r = this.options.onProgress, i = t.onProgress;
3357
+ const n = this.options.onProgress, r = t.onProgress;
3097
3358
  return {
3098
3359
  ...this.options,
3099
3360
  ...t,
3100
- onProgress: (s) => {
3101
- var n, o;
3102
- (o = (n = this.options).onLoadProgress) == null || o.call(n, s), r == null || r(s), i && i !== r && i(s);
3361
+ onProgress: (i) => {
3362
+ var s, o;
3363
+ (o = (s = this.options).onLoadProgress) == null || o.call(s, i), n == null || n(i), r && r !== n && r(i);
3103
3364
  }
3104
3365
  };
3105
3366
  }
3106
3367
  }
3107
- function Ir(e = {}) {
3108
- return new kr(e);
3368
+ function Er(e = {}) {
3369
+ return new dr(e);
3109
3370
  }
3110
- function Sr(e) {
3371
+ function mr(e) {
3111
3372
  return e instanceof Error ? e : new Error(String(e));
3112
3373
  }
3113
- function ft(e) {
3374
+ function yt(e) {
3114
3375
  if (e != null && e.aborted)
3115
3376
  throw new DOMException("Loading cancelled.", "AbortError");
3116
3377
  }
3117
- function Nr(e, t, r = {}) {
3118
- if (e === "canvas2d") return new Ot(t, r);
3119
- if (e === "webgl") return new zt(t, r);
3120
- if (te())
3378
+ function pr(e, t, n = {}) {
3379
+ if (e === "canvas2d") return new te(t, n);
3380
+ if (e === "webgl") return new ee(t, n);
3381
+ if (Ee())
3121
3382
  try {
3122
- return new zt(t, r);
3383
+ return new ee(t, n);
3123
3384
  } catch {
3124
3385
  }
3125
- return new Ot(t, r);
3386
+ return new te(t, n);
3387
+ }
3388
+ function Ir(e, t, n, r = {}) {
3389
+ const i = e && typeof e == "object" ? e : {}, s = yr(i, r), o = vr(i, r), a = kr(i, r), c = br(i.header, n), l = xr(i, c), h = l.view, u = Array.isArray(i.entities) ? i.entities : [], f = { keepRaw: !!r.keepRaw, includeUnknownProperties: !!r.keepRaw }, m = u.filter((y) => !!y && typeof y == "object").map((y) => Ie(y, f)), p = It({
3390
+ format: "dwg",
3391
+ sourceName: t,
3392
+ header: c,
3393
+ layers: s,
3394
+ lineTypes: o,
3395
+ blocks: a,
3396
+ entities: m,
3397
+ savedView: h,
3398
+ metadata: {
3399
+ parser: "@mlightcad/libredwg-web",
3400
+ parserMode: "wasm",
3401
+ version: n,
3402
+ savedView: h
3403
+ },
3404
+ warnings: l.warning ? [l.warning] : [],
3405
+ raw: r.keepRaw ? e : void 0
3406
+ });
3407
+ return m.length === 0 && p.warnings.push("DWG parsed successfully but no model-space entities were exposed by the converter. Check layout/paper-space content or unsupported proxy objects."), [...new Set(Object.values(o))].some((y) => y.pattern.some((v) => Number(v.elementTypeFlag ?? 0) !== 0)) && p.warnings.push("Complex SHX linetype glyphs are preserved in the normalized LTYPE definition and rendered as a dash/dot approximation; embedded shape glyph fidelity is not available yet."), p;
3408
+ }
3409
+ function Ie(e, t) {
3410
+ const n = Tt(e, void 0, { ...t, numericColorMode: "rgb" }), r = b(e.color);
3411
+ r !== void 0 && r >= 0 && r <= 16777215 && (n.color = r, n.trueColor = r), n.colorIndex = b(e.colorIndex ?? e.colorNumber ?? e.aci) ?? n.colorIndex, n.colorName = w(e.colorName ?? e.color_name) ?? n.colorName;
3412
+ const i = b(e.flag ?? e.flags);
3413
+ i !== void 0 && (n.flag = i);
3414
+ const s = String(e.type ?? e.entityType ?? "").toUpperCase(), o = /^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D)$/.test(s);
3415
+ return (e.isClosed === !0 || e.closed === !0 || o && (Number(i ?? 0) & 1) === 1 || s === "LWPOLYLINE" && (Number(i ?? 0) & 512) === 512) && (n.isClosed = !0), n;
3416
+ }
3417
+ function gr(e) {
3418
+ return typeof e == "number" && Number.isFinite(e) && Math.abs(Math.trunc(e)) >= 1 && Math.abs(Math.trunc(e)) <= 255;
3419
+ }
3420
+ function br(e, t) {
3421
+ const n = e && typeof e == "object" ? { ...e } : {};
3422
+ return t && (n.dwgVersion = t), n;
3423
+ }
3424
+ function yr(e, t) {
3425
+ const n = {}, r = [], i = e.tables;
3426
+ for (const s of ["LAYER", "layer", "layers"]) {
3427
+ const o = e[s] ?? (i == null ? void 0 : i[s]);
3428
+ o && r.push(o);
3429
+ }
3430
+ for (const s of r)
3431
+ for (const o of ht(s)) {
3432
+ const a = o, c = w(a.name ?? a.layerName ?? a.entryName);
3433
+ if (!c) continue;
3434
+ const l = b(a.colorIndex ?? a.colorNumber), h = b(a.trueColor ?? a.true_color ?? a.truecolor ?? a.colorRGB ?? a.colorRgb ?? a.rgbColor ?? a.rgb), u = b(a.color), f = gr(l), m = h ?? (!f && u !== void 0 && u >= 0 && u <= 16777215 ? u : void 0), p = {
3435
+ name: c,
3436
+ color: f ? void 0 : a.color ?? a.colorName,
3437
+ colorIndex: l ?? (u !== void 0 && Math.abs(u) <= 257 ? u : void 0),
3438
+ trueColor: m,
3439
+ lineType: w(a.lineType ?? a.linetype),
3440
+ lineweight: b(a.lineweight ?? a.lineWeight),
3441
+ isVisible: !(a.isVisible === !1 || a.off === !0 || Number(l ?? a.color ?? 1) < 0),
3442
+ isFrozen: !!(a.isFrozen ?? a.frozen),
3443
+ isLocked: !!(a.isLocked ?? a.locked),
3444
+ raw: t.keepRaw ? a : void 0
3445
+ };
3446
+ wt(n, p);
3447
+ }
3448
+ return n;
3449
+ }
3450
+ function vr(e, t) {
3451
+ const n = {}, r = e.tables, i = [e.LTYPE, e.ltype, e.lineTypes, r == null ? void 0 : r.LTYPE, r == null ? void 0 : r.ltype, r == null ? void 0 : r.lineTypes];
3452
+ for (const s of i)
3453
+ for (const o of ht(s)) {
3454
+ const a = o, c = w(a.name ?? a.lineTypeName ?? a.entryName);
3455
+ if (!c) continue;
3456
+ const h = (Array.isArray(a.pattern) ? a.pattern : Array.isArray(a.dashes) ? a.dashes : []).flatMap((u) => {
3457
+ if (typeof u == "number") return [{ length: u }];
3458
+ if (!u || typeof u != "object") return [];
3459
+ const f = u, m = b(f.elementLength ?? f.length ?? f.dashLength);
3460
+ if (m === void 0) return [];
3461
+ const p = b(f.elementTypeFlag), C = b(f.shapeNumber), y = p !== void 0 && C !== void 0;
3462
+ return [{
3463
+ length: m,
3464
+ elementTypeFlag: y ? C : b(f.typeFlag ?? f.elementTypeFlag),
3465
+ shapeNumber: y ? p : b(f.shapeCode ?? f.shapeNumber),
3466
+ scale: b(f.scale),
3467
+ rotation: b(f.rotation),
3468
+ offsetX: b(f.offsetX),
3469
+ offsetY: b(f.offsetY),
3470
+ text: w(f.text)
3471
+ }];
3472
+ });
3473
+ Ue(n, {
3474
+ name: c,
3475
+ handle: w(a.handle ?? a.id),
3476
+ description: w(a.description),
3477
+ totalPatternLength: b(a.totalPatternLength ?? a.patternLength),
3478
+ pattern: h,
3479
+ raw: t.keepRaw ? a : void 0
3480
+ });
3481
+ }
3482
+ return n;
3483
+ }
3484
+ function xr(e, t) {
3485
+ const n = e.tables, i = ht(e.VPORT ?? e.vports ?? (n == null ? void 0 : n.VPORT) ?? (n == null ? void 0 : n.vports)).filter((v) => !!v && typeof v == "object").find((v) => String(v.name ?? "").trim().toLowerCase() === "*active"), s = i ? "vport" : "header-ucs", o = i ?? t, a = k(o.ucsOrigin ?? o.UCSORG ?? t.UCSORG), c = k(o.ucsXAxis ?? o.UCSXDIR ?? t.UCSXDIR), l = k(o.ucsYAxis ?? o.UCSYDIR ?? t.UCSYDIR), h = b(o.viewTwistAngle ?? o.twistAngle ?? o.VIEWTWIST) ?? 0, u = k(o.viewDirectionFromTarget ?? o.viewDirection ?? o.direction ?? o.VIEWDIR), f = !Pr(a, c, l);
3486
+ if (!(!!i || !!u || f || Math.abs(h) > 1e-12)) return {};
3487
+ const p = Cr(u), C = p ? wr(a, c, l, h) : { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }, y = {
3488
+ source: s,
3489
+ name: w(o.name),
3490
+ handle: w(o.handle),
3491
+ center: k(o.center ?? o.VIEWCTR),
3492
+ target: k(o.viewTarget ?? o.target ?? o.TARGET),
3493
+ direction: u,
3494
+ viewHeight: b(o.viewHeight ?? o.height ?? o.VIEWSIZE),
3495
+ aspectRatio: b(o.aspectRatio),
3496
+ twistAngle: h,
3497
+ ucsOrigin: a,
3498
+ ucsXAxis: c,
3499
+ ucsYAxis: l,
3500
+ sceneTransformApplied: p,
3501
+ sceneTransform: C
3502
+ };
3503
+ return p ? { view: y } : {
3504
+ view: y,
3505
+ warning: "The saved CAD view has a missing, non-finite, or tilted VIEWDIR. File Viewer kept world coordinates instead of applying an unsafe 2D UCS/PLAN rotation."
3506
+ };
3507
+ }
3508
+ function wr(e, t, n, r) {
3509
+ const i = vt(t) ?? { x: 1, y: 0 }, s = vt(n) ?? { x: -i.y, y: i.x }, o = i.x * s.x + i.y * s.y, a = vt({
3510
+ x: s.x - i.x * o,
3511
+ y: s.y - i.y * o
3512
+ }) ?? { x: -i.y, y: i.x }, c = {
3513
+ a: i.x,
3514
+ b: a.x,
3515
+ c: i.y,
3516
+ d: a.y,
3517
+ e: e ? -(e.x * i.x + e.y * i.y) : 0,
3518
+ f: e ? -(e.x * a.x + e.y * a.y) : 0
3519
+ };
3520
+ return ct(ye(Number.isFinite(r) ? r : 0), c);
3521
+ }
3522
+ function vt(e) {
3523
+ if (!e || Math.abs(Number(e.z ?? 0)) > 1e-6) return;
3524
+ const t = Math.hypot(e.x, e.y);
3525
+ if (!(!Number.isFinite(t) || t < 1e-12))
3526
+ return { x: e.x / t, y: e.y / t };
3527
+ }
3528
+ function Cr(e) {
3529
+ if (!e || !Number.isFinite(e.x) || !Number.isFinite(e.y) || !Number.isFinite(e.z)) return !1;
3530
+ const t = Math.hypot(e.x, e.y, Number(e.z));
3531
+ return !Number.isFinite(t) || t < 1e-12 ? !1 : Math.hypot(e.x, e.y) / t <= 1e-4 && Math.abs(Number(e.z)) / t >= 1 - 1e-8;
3532
+ }
3533
+ function Pr(e, t, n) {
3534
+ const r = (a, c) => Number.isFinite(a) && Math.abs(Number(a) - c) <= 1e-10, i = !e || r(e.x, 0) && r(e.y, 0) && r(e.z ?? 0, 0), s = !t || r(t.x, 1) && r(t.y, 0) && r(t.z ?? 0, 0), o = !n || r(n.x, 0) && r(n.y, 1) && r(n.z ?? 0, 0);
3535
+ return i && s && o;
3536
+ }
3537
+ function kr(e, t) {
3538
+ const n = {}, r = [e.blocks, e.blockHeaders, e.block_records, e.blockRecords], i = e.tables;
3539
+ r.push(i == null ? void 0 : i.BLOCK, i == null ? void 0 : i.BLOCK_RECORD, i == null ? void 0 : i.blocks);
3540
+ const s = { keepRaw: !!t.keepRaw, includeUnknownProperties: !!t.keepRaw };
3541
+ for (const o of r)
3542
+ for (const a of ht(o)) {
3543
+ const c = a, l = w(c.name ?? c.blockName ?? c.name2);
3544
+ if (!l) continue;
3545
+ const u = (Array.isArray(c.entities) ? c.entities : Array.isArray(c.ownedObjects) ? c.ownedObjects : []).filter((f) => !!f && typeof f == "object").map((f) => Ie(f, s));
3546
+ ce(n, {
3547
+ name: l,
3548
+ basePoint: k(c.basePoint ?? c.origin) ?? { x: 0, y: 0 },
3549
+ entities: u,
3550
+ raw: t.keepRaw ? c : void 0
3551
+ });
3552
+ }
3553
+ return n;
3554
+ }
3555
+ function ht(e) {
3556
+ if (!e) return [];
3557
+ if (Array.isArray(e)) return e;
3558
+ if (typeof e != "object") return [];
3559
+ const t = e, n = Object.values(t).filter((i) => i && typeof i == "object"), r = ["entries", "records", "items", "values", "layers", "blocks"].flatMap((i) => Array.isArray(t[i]) ? t[i] : []);
3560
+ return r.length > 0 ? r : n;
3126
3561
  }
3127
3562
  export {
3128
- Ot as CadCanvasRenderer,
3129
- ae as CadLoaderRegistry,
3130
- kr as CadViewer,
3131
- zt as CadWebGLRenderer,
3132
- ze as DwfLoader,
3133
- me as DwgLoader,
3134
- he as DwgWorkerClient,
3135
- xe as DxfLoader,
3136
- E as colorFromAci,
3137
- V as colorFromTrueColor,
3138
- Ut as createCadDocument,
3139
- Ir as createCadViewer,
3140
- qe as createDefaultLoaderRegistry,
3141
- B as detectCadFormat,
3142
- R as inferEntityKind,
3143
- Ke as isCadNativeRenderableLoader,
3144
- te as isWebGLAvailable,
3145
- be as normalizeCadEntity,
3146
- U as readInputBytes,
3147
- D as resolveCadColor,
3148
- G as summarizeCadDocument,
3149
- dt as supportsDwgWorker
3563
+ te as CadCanvasRenderer,
3564
+ De as CadLoaderRegistry,
3565
+ dr as CadViewer,
3566
+ ee as CadWebGLRenderer,
3567
+ mn as DwfLoader,
3568
+ Xe as DwgLoader,
3569
+ Oe as DwgWorkerClient,
3570
+ Ge as DxfLoader,
3571
+ Se as applyByBlockLineTypeInheritance,
3572
+ O as colorFromAci,
3573
+ tt as colorFromTrueColor,
3574
+ ve as computeCadDocumentBounds,
3575
+ It as createCadDocument,
3576
+ Me as createCadSceneDocument,
3577
+ Er as createCadViewer,
3578
+ Dt as createDashedCadPrimitives,
3579
+ Mr as createDashedCadSegments,
3580
+ Sn as createDefaultLoaderRegistry,
3581
+ Y as detectCadFormat,
3582
+ J as inferEntityKind,
3583
+ Nn as isCadNativeRenderableLoader,
3584
+ ae as isCadPolylineClosed,
3585
+ Ee as isWebGLAvailable,
3586
+ Tt as normalizeCadEntity,
3587
+ Ir as normalizeDwgDatabase,
3588
+ K as readInputBytes,
3589
+ V as resolveCadColor,
3590
+ xe as resolveCadFitBounds,
3591
+ Nt as resolveCadLinePattern,
3592
+ Ne as resolveCadLineTypeReference,
3593
+ Yn as resolveCadSavedViewBounds,
3594
+ it as summarizeCadDocument,
3595
+ xt as supportsDwgWorker
3150
3596
  };
3151
3597
  //# sourceMappingURL=cad-viewer.es.js.map