@flyfish-dev/cad-viewer 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/NOTICE +11 -0
- package/README.md +411 -0
- package/README.zh-CN.md +411 -0
- package/dist/assets/DwgWorker-CuZJ5EUe.js +349 -0
- package/dist/assets/DwgWorker-CuZJ5EUe.js.map +1 -0
- package/dist/assets/index-C365l3i9.js +4161 -0
- package/dist/assets/index-C365l3i9.js.map +1 -0
- package/dist/cad-viewer.es.js +2992 -0
- package/dist/cad-viewer.es.js.map +1 -0
- package/dist/cad-viewer.umd.cjs +30 -0
- package/dist/cad-viewer.umd.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/style.css +1 -0
- package/dist/types/core/color.d.ts +21 -0
- package/dist/types/core/color.d.ts.map +1 -0
- package/dist/types/core/entity.d.ts +34 -0
- package/dist/types/core/entity.d.ts.map +1 -0
- package/dist/types/core/format.d.ts +8 -0
- package/dist/types/core/format.d.ts.map +1 -0
- package/dist/types/core/geometry.d.ts +17 -0
- package/dist/types/core/geometry.d.ts.map +1 -0
- package/dist/types/core/transform.d.ts +20 -0
- package/dist/types/core/transform.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +195 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/loaders/CadLoaderRegistry.d.ts +15 -0
- package/dist/types/loaders/CadLoaderRegistry.d.ts.map +1 -0
- package/dist/types/loaders/dwf/DwfLoader.d.ts +15 -0
- package/dist/types/loaders/dwf/DwfLoader.d.ts.map +1 -0
- package/dist/types/loaders/dwg/DwgLoader.d.ts +15 -0
- package/dist/types/loaders/dwg/DwgLoader.d.ts.map +1 -0
- package/dist/types/loaders/dwg/DwgParser.d.ts +24 -0
- package/dist/types/loaders/dwg/DwgParser.d.ts.map +1 -0
- package/dist/types/loaders/dwg/DwgWorker.d.ts +2 -0
- package/dist/types/loaders/dwg/DwgWorker.d.ts.map +1 -0
- package/dist/types/loaders/dwg/DwgWorkerClient.d.ts +18 -0
- package/dist/types/loaders/dwg/DwgWorkerClient.d.ts.map +1 -0
- package/dist/types/loaders/dwg/dwgVersion.d.ts +9 -0
- package/dist/types/loaders/dwg/dwgVersion.d.ts.map +1 -0
- package/dist/types/loaders/dwg/libredwgWasmModuleProxy.d.ts +14 -0
- package/dist/types/loaders/dwg/libredwgWasmModuleProxy.d.ts.map +1 -0
- package/dist/types/loaders/dxf/DxfLoader.d.ts +12 -0
- package/dist/types/loaders/dxf/DxfLoader.d.ts.map +1 -0
- package/dist/types/loaders/index.d.ts +8 -0
- package/dist/types/loaders/index.d.ts.map +1 -0
- package/dist/types/viewer/CadCanvasRenderer.d.ts +142 -0
- package/dist/types/viewer/CadCanvasRenderer.d.ts.map +1 -0
- package/dist/types/viewer/CadViewer.d.ts +55 -0
- package/dist/types/viewer/CadViewer.d.ts.map +1 -0
- package/dist/types/viewer/CadWebGLRenderer.d.ts +69 -0
- package/dist/types/viewer/CadWebGLRenderer.d.ts.map +1 -0
- package/dist/wasm/libredwg-web.js +15 -0
- package/dist/wasm/libredwg-web.wasm +0 -0
- package/package.json +103 -0
|
@@ -0,0 +1,2992 @@
|
|
|
1
|
+
var Jt = Object.defineProperty;
|
|
2
|
+
var te = (e, t, r) => t in e ? Jt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var u = (e, t, r) => te(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { unzipSync as ee } from "fflate";
|
|
5
|
+
async function et(e) {
|
|
6
|
+
if (e.buffer instanceof Uint8Array) return e.buffer;
|
|
7
|
+
if (e.buffer instanceof ArrayBuffer) return new Uint8Array(e.buffer);
|
|
8
|
+
if (e.file) return new Uint8Array(await e.file.arrayBuffer());
|
|
9
|
+
throw new Error("CadLoadInput requires a File, ArrayBuffer, or Uint8Array.");
|
|
10
|
+
}
|
|
11
|
+
function re(e) {
|
|
12
|
+
return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
|
|
13
|
+
}
|
|
14
|
+
function Y(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 rt(e, t) {
|
|
20
|
+
const r = Y(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";
|
|
26
|
+
if (t && t.byteLength >= 6) {
|
|
27
|
+
const i = vt(t.slice(0, 6));
|
|
28
|
+
if (/^AC10/.test(i)) return "dwg";
|
|
29
|
+
if (t[0] === 80 && t[1] === 75) return "dwfx";
|
|
30
|
+
const s = vt(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";
|
|
33
|
+
}
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
function vt(e) {
|
|
37
|
+
return Array.from(e, (t) => t >= 32 && t <= 126 ? String.fromCharCode(t) : " ").join("");
|
|
38
|
+
}
|
|
39
|
+
function wt(e) {
|
|
40
|
+
return new TextDecoder("utf-8").decode(e);
|
|
41
|
+
}
|
|
42
|
+
class ie {
|
|
43
|
+
constructor(t = []) {
|
|
44
|
+
u(this, "loaders", []);
|
|
45
|
+
for (const r of t) this.register(r);
|
|
46
|
+
}
|
|
47
|
+
register(t) {
|
|
48
|
+
const r = this.loaders.findIndex((i) => i.id === t.id);
|
|
49
|
+
return r >= 0 ? this.loaders.splice(r, 1, t) : this.loaders.push(t), this;
|
|
50
|
+
}
|
|
51
|
+
unregister(t) {
|
|
52
|
+
const r = this.loaders.findIndex((i) => i.id === t);
|
|
53
|
+
return r >= 0 && this.loaders.splice(r, 1), this;
|
|
54
|
+
}
|
|
55
|
+
list() {
|
|
56
|
+
return [...this.loaders];
|
|
57
|
+
}
|
|
58
|
+
async detect(t) {
|
|
59
|
+
const r = await et(t), i = rt(t, r), s = this.loaders.find((o) => o.formats.includes(i) && o.accepts(t, r));
|
|
60
|
+
if (s) return { loader: s, bytes: r, format: i };
|
|
61
|
+
const n = this.loaders.find((o) => o.accepts(t, r));
|
|
62
|
+
if (n) return { loader: n, bytes: r, format: i };
|
|
63
|
+
throw new Error(`No CAD loader registered for ${i === "unknown" ? "this file" : i.toUpperCase()}.`);
|
|
64
|
+
}
|
|
65
|
+
async load(t, r = {}) {
|
|
66
|
+
const { loader: i, bytes: s } = await this.detect(t);
|
|
67
|
+
return i.load({ ...t, buffer: s }, r);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class se {
|
|
71
|
+
constructor() {
|
|
72
|
+
u(this, "worker");
|
|
73
|
+
u(this, "sequence", 0);
|
|
74
|
+
u(this, "pending", /* @__PURE__ */ new Map());
|
|
75
|
+
}
|
|
76
|
+
load(t, r, i = {}) {
|
|
77
|
+
var l, h;
|
|
78
|
+
if (!ht()) throw new Error("Web Worker is not available in this runtime.");
|
|
79
|
+
const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((l = r.file) == null ? void 0 : l.name), c = oe(t, r, i);
|
|
80
|
+
return (h = i.onProgress) == null || h.call(i, { phase: "worker-start", format: "dwg", message: "Dispatching DWG parse to worker…", total: t.byteLength }), new Promise((f, d) => {
|
|
81
|
+
var g;
|
|
82
|
+
if ((g = i.signal) != null && g.aborted) {
|
|
83
|
+
d(U());
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const p = { resolve: f, reject: d, onProgress: i.onProgress, signal: i.signal };
|
|
87
|
+
o > 0 && (p.timer = setTimeout(() => {
|
|
88
|
+
this.pending.delete(n), this.resetWorker(), d(new Error(`DWG worker timed out after ${o} ms.`));
|
|
89
|
+
}, o)), i.signal && (p.abortHandler = () => {
|
|
90
|
+
this.pending.delete(n), this.resetWorker(), d(U());
|
|
91
|
+
}, i.signal.addEventListener("abort", p.abortHandler, { once: !0 })), this.pending.set(n, p);
|
|
92
|
+
try {
|
|
93
|
+
s.postMessage({
|
|
94
|
+
type: "load",
|
|
95
|
+
requestId: n,
|
|
96
|
+
bytes: c,
|
|
97
|
+
fileName: a,
|
|
98
|
+
options: Ct(i)
|
|
99
|
+
}, [c]);
|
|
100
|
+
} catch (S) {
|
|
101
|
+
this.pending.delete(n), _(p), d(S instanceof Error ? S : new Error(String(S)));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
preload(t = {}) {
|
|
106
|
+
var n;
|
|
107
|
+
if (!ht()) return Promise.reject(new Error("Web Worker is not available in this runtime."));
|
|
108
|
+
const r = this.ensureWorker(t), i = ++this.sequence, s = Math.max(0, Number(t.workerTimeoutMs ?? 0));
|
|
109
|
+
return (n = t.onProgress) == null || n.call(t, { phase: "worker-start", format: "dwg", message: "Starting DWG worker warmup…" }), new Promise((o, a) => {
|
|
110
|
+
var l;
|
|
111
|
+
if ((l = t.signal) != null && l.aborted) {
|
|
112
|
+
a(U());
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const c = {
|
|
116
|
+
resolve: () => o(),
|
|
117
|
+
reject: a,
|
|
118
|
+
onProgress: t.onProgress,
|
|
119
|
+
signal: t.signal
|
|
120
|
+
};
|
|
121
|
+
s > 0 && (c.timer = setTimeout(() => {
|
|
122
|
+
this.pending.delete(i), this.resetWorker(), a(new Error(`DWG worker warmup timed out after ${s} ms.`));
|
|
123
|
+
}, s)), t.signal && (c.abortHandler = () => {
|
|
124
|
+
this.pending.delete(i), this.resetWorker(), a(U());
|
|
125
|
+
}, t.signal.addEventListener("abort", c.abortHandler, { once: !0 })), this.pending.set(i, c);
|
|
126
|
+
try {
|
|
127
|
+
r.postMessage({ type: "warmup", requestId: i, options: Ct(t) });
|
|
128
|
+
} catch (h) {
|
|
129
|
+
this.pending.delete(i), _(c), a(h instanceof Error ? h : new Error(String(h)));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
terminate() {
|
|
134
|
+
this.resetWorker();
|
|
135
|
+
}
|
|
136
|
+
ensureWorker(t) {
|
|
137
|
+
return this.worker || (this.worker = ne(t), this.worker.onmessage = (r) => this.handleMessage(r.data), this.worker.onerror = (r) => {
|
|
138
|
+
const i = r.message || "DWG worker failed.";
|
|
139
|
+
this.rejectAll(new Error(i)), this.resetWorker(!1);
|
|
140
|
+
}, this.worker.onmessageerror = () => {
|
|
141
|
+
this.rejectAll(new Error("DWG worker returned a message that could not be cloned.")), this.resetWorker(!1);
|
|
142
|
+
}), this.worker;
|
|
143
|
+
}
|
|
144
|
+
handleMessage(t) {
|
|
145
|
+
var s, n;
|
|
146
|
+
if (t.type === "ready") return;
|
|
147
|
+
const r = this.pending.get(t.requestId);
|
|
148
|
+
if (!r) return;
|
|
149
|
+
if (t.type === "progress") {
|
|
150
|
+
(s = r.onProgress) == null || s.call(r, t.progress);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (this.pending.delete(t.requestId), _(r), t.type === "result") {
|
|
154
|
+
r.resolve(t.result);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (t.type === "warmup-result") {
|
|
158
|
+
(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);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const i = new Error(t.error.message);
|
|
162
|
+
i.name = t.error.name || "DwgWorkerError", t.error.stack && (i.stack = t.error.stack), r.reject(i);
|
|
163
|
+
}
|
|
164
|
+
rejectAll(t) {
|
|
165
|
+
for (const [, r] of this.pending)
|
|
166
|
+
_(r), r.reject(t);
|
|
167
|
+
this.pending.clear();
|
|
168
|
+
}
|
|
169
|
+
resetWorker(t = !0) {
|
|
170
|
+
var r;
|
|
171
|
+
t && this.rejectAll(new Error("DWG worker was terminated.")), (r = this.worker) == null || r.terminate(), this.worker = void 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function ht() {
|
|
175
|
+
return typeof Worker < "u" && typeof URL < "u";
|
|
176
|
+
}
|
|
177
|
+
function ne(e) {
|
|
178
|
+
return e.workerFactory ? e.workerFactory() : e.workerUrl ? new Worker(e.workerUrl, { type: "module", name: "lightweight-cad-dwg-loader" }) : new Worker(new URL(
|
|
179
|
+
/* @vite-ignore */
|
|
180
|
+
"/assets/DwgWorker-CuZJ5EUe.js",
|
|
181
|
+
import.meta.url
|
|
182
|
+
), { type: "module", name: "lightweight-cad-dwg-loader" });
|
|
183
|
+
}
|
|
184
|
+
function Ct(e) {
|
|
185
|
+
return {
|
|
186
|
+
// Resolve the asset directory on the UI thread. Relative paths such as
|
|
187
|
+
// './wasm' must be relative to the document URL, not to the generated
|
|
188
|
+
// worker chunk URL. Otherwise the worker may request /assets/wasm/... and
|
|
189
|
+
// receive the app's HTML fallback instead of libredwg-web.wasm.
|
|
190
|
+
wasmPath: ae(e.wasmPath),
|
|
191
|
+
includePaperSpace: e.includePaperSpace,
|
|
192
|
+
maxInsertDepth: e.maxInsertDepth,
|
|
193
|
+
keepRaw: !!e.keepRaw
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function oe(e, t, r) {
|
|
197
|
+
return !!t.file || r.transferInputBuffer === !0 ? re(e) : e.slice().buffer;
|
|
198
|
+
}
|
|
199
|
+
function _(e) {
|
|
200
|
+
e.timer && clearTimeout(e.timer), e.signal && e.abortHandler && e.signal.removeEventListener("abort", e.abortHandler);
|
|
201
|
+
}
|
|
202
|
+
function U() {
|
|
203
|
+
if (typeof DOMException < "u") return new DOMException("DWG loading was aborted.", "AbortError");
|
|
204
|
+
const e = new Error("DWG loading was aborted.");
|
|
205
|
+
return e.name = "AbortError", e;
|
|
206
|
+
}
|
|
207
|
+
function ae(e) {
|
|
208
|
+
const t = ((e == null ? void 0 : e.trim()) || "/wasm").replace(/\/+$/, "");
|
|
209
|
+
return t === "" ? Pt() : ce(t) ? t : t.startsWith("/") ? `${Pt()}${t}` : new URL(t, zt()).href.replace(/\/+$/, "");
|
|
210
|
+
}
|
|
211
|
+
function zt() {
|
|
212
|
+
return typeof document < "u" && document.baseURI ? document.baseURI : typeof location < "u" && location.href ? location.href : "http://localhost/";
|
|
213
|
+
}
|
|
214
|
+
function Pt() {
|
|
215
|
+
return typeof location < "u" && location.origin ? location.origin : new URL(zt()).origin;
|
|
216
|
+
}
|
|
217
|
+
function ce(e) {
|
|
218
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(e);
|
|
219
|
+
}
|
|
220
|
+
class le {
|
|
221
|
+
constructor(t = {}) {
|
|
222
|
+
u(this, "id", "dwg");
|
|
223
|
+
u(this, "label", "DWG / LibreDWG WebAssembly");
|
|
224
|
+
u(this, "formats", ["dwg"]);
|
|
225
|
+
u(this, "defaults");
|
|
226
|
+
u(this, "workerClient", new se());
|
|
227
|
+
this.defaults = { useWorker: !0, ...t };
|
|
228
|
+
}
|
|
229
|
+
accepts(t, r) {
|
|
230
|
+
return Y(t) === "dwg" ? !0 : rt(t, r) === "dwg";
|
|
231
|
+
}
|
|
232
|
+
async load(t, r = {}) {
|
|
233
|
+
var o, a;
|
|
234
|
+
const i = { ...this.defaults, ...r };
|
|
235
|
+
(o = i.onProgress) == null || o.call(i, { phase: "read", format: "dwg", message: "Reading DWG bytes…" });
|
|
236
|
+
const s = await et(t), n = t.fileName ?? ((a = t.file) == null ? void 0 : a.name);
|
|
237
|
+
if (i.useWorker === !1)
|
|
238
|
+
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.");
|
|
239
|
+
if (!ht())
|
|
240
|
+
throw new Error("DWG loading requires Web Worker support in this build. Provide a custom loader for this runtime.");
|
|
241
|
+
try {
|
|
242
|
+
return await this.workerClient.load(s, t, { ...i, fileName: n });
|
|
243
|
+
} catch (c) {
|
|
244
|
+
throw he(c) ? c : fe(c);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
terminateWorker() {
|
|
248
|
+
this.workerClient.terminate();
|
|
249
|
+
}
|
|
250
|
+
preload(t = {}) {
|
|
251
|
+
const r = { ...this.defaults, ...t };
|
|
252
|
+
return r.useWorker === !1 ? Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")) : this.workerClient.preload(r);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function he(e) {
|
|
256
|
+
return e instanceof Error && e.name === "AbortError";
|
|
257
|
+
}
|
|
258
|
+
function fe(e) {
|
|
259
|
+
const t = e instanceof Error ? e.message : String(e);
|
|
260
|
+
return new Error(`${t} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`);
|
|
261
|
+
}
|
|
262
|
+
function Xt(e) {
|
|
263
|
+
return {
|
|
264
|
+
format: e.format,
|
|
265
|
+
sourceName: e.sourceName,
|
|
266
|
+
units: e.units,
|
|
267
|
+
header: e.header ?? {},
|
|
268
|
+
layers: e.layers ?? {},
|
|
269
|
+
blocks: e.blocks ?? {},
|
|
270
|
+
entities: e.entities ?? [],
|
|
271
|
+
pages: e.pages,
|
|
272
|
+
metadata: e.metadata ?? {},
|
|
273
|
+
warnings: e.warnings ?? [],
|
|
274
|
+
raw: e.raw
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function O(e) {
|
|
278
|
+
switch (String(e ?? "").toUpperCase()) {
|
|
279
|
+
case "LINE":
|
|
280
|
+
return "line";
|
|
281
|
+
case "CIRCLE":
|
|
282
|
+
return "circle";
|
|
283
|
+
case "ARC":
|
|
284
|
+
return "arc";
|
|
285
|
+
case "LWPOLYLINE":
|
|
286
|
+
case "POLYLINE":
|
|
287
|
+
case "POLYLINE_2D":
|
|
288
|
+
case "POLYLINE2D":
|
|
289
|
+
case "POLYLINE_3D":
|
|
290
|
+
case "POLYLINE3D":
|
|
291
|
+
case "LEADER":
|
|
292
|
+
case "MULTILEADER":
|
|
293
|
+
return "polyline";
|
|
294
|
+
case "ELLIPSE":
|
|
295
|
+
return "ellipse";
|
|
296
|
+
case "TEXT":
|
|
297
|
+
case "MTEXT":
|
|
298
|
+
case "ATTRIB":
|
|
299
|
+
case "ATTDEF":
|
|
300
|
+
case "DIMENSION":
|
|
301
|
+
return "text";
|
|
302
|
+
case "POINT":
|
|
303
|
+
return "point";
|
|
304
|
+
case "INSERT":
|
|
305
|
+
return "insert";
|
|
306
|
+
case "SOLID":
|
|
307
|
+
case "TRACE":
|
|
308
|
+
case "3DFACE":
|
|
309
|
+
return "solid";
|
|
310
|
+
case "HATCH":
|
|
311
|
+
return "hatch";
|
|
312
|
+
case "SPLINE":
|
|
313
|
+
return "spline";
|
|
314
|
+
case "PATH":
|
|
315
|
+
case "XPS_PATH":
|
|
316
|
+
case "DWF_PATH":
|
|
317
|
+
return "path";
|
|
318
|
+
case "IMAGE":
|
|
319
|
+
case "RASTER_IMAGE":
|
|
320
|
+
case "DWF_IMAGE":
|
|
321
|
+
return "image";
|
|
322
|
+
case "VIEWPORT":
|
|
323
|
+
return "viewport";
|
|
324
|
+
default:
|
|
325
|
+
return "unsupported";
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function de(e, t, r = {}) {
|
|
329
|
+
const i = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), s = r.includeUnknownProperties === !1 ? { type: i, kind: O(i) } : { ...e, type: i, kind: O(i) };
|
|
330
|
+
r.keepRaw && (s.raw = e), s.handle = P(e.handle ?? e.id), s.layer = P(e.layer ?? e.layerName), s.lineType = P(e.lineType ?? e.linetype);
|
|
331
|
+
const n = r.numericColorMode ?? "auto", o = x(e.color), a = x(e.colorIndex ?? e.colorNumber ?? e.aci ?? e.aciColor ?? e.color_index);
|
|
332
|
+
s.colorIndex = a ?? (n !== "rgb" && o !== void 0 && Math.abs(o) <= 257 ? o : void 0);
|
|
333
|
+
const c = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb, l = o !== void 0 && o >= 0 && o <= 16777215 && (n === "rgb" || n === "auto" && Math.abs(o) > 257);
|
|
334
|
+
s.trueColor = c ?? (l ? o : void 0), (typeof e.color == "string" || typeof e.color == "number") && (s.color = e.color), s.colorNumber = x(e.colorNumber) ?? s.colorNumber, s.colorName = P(e.colorName ?? e.color_name) ?? s.colorName, s.fillColor = e.fillColor ?? e.fill_color, s.fillColorIndex = x(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? s.fillColorIndex, s.opacity = x(e.opacity ?? e.alpha) ?? s.opacity, s.lineweight = x(e.lineweight ?? e.lineWeight), s.isVisible = !(e.isVisible === !1 || e.visible === !1), s.startPoint = k(e.startPoint ?? e.start ?? e.p0 ?? e.from) ?? s.startPoint, s.endPoint = k(e.endPoint ?? e.end ?? e.p1 ?? e.to) ?? s.endPoint, s.center = k(e.center ?? e.centerPoint) ?? s.center, s.insertionPoint = k(e.insertionPoint ?? e.position ?? e.location ?? e.point ?? e.basePoint) ?? s.insertionPoint, s.radius = x(e.radius) ?? s.radius, s.startAngle = x(e.startAngle ?? e.start_angle) ?? s.startAngle, s.endAngle = x(e.endAngle ?? e.end_angle) ?? s.endAngle, s.majorAxisEndPoint = k(e.majorAxisEndPoint ?? e.majorAxis ?? e.major) ?? s.majorAxisEndPoint, s.axisRatio = x(e.axisRatio ?? e.ratio) ?? s.axisRatio, s.height = x(e.height ?? e.textHeight) ?? s.height, s.textHeight = x(e.textHeight ?? e.height) ?? s.textHeight, s.rotation = x(e.rotation ?? e.angle) ?? s.rotation, s.text = P(e.text ?? e.value ?? e.string ?? e.contents) ?? s.text, s.name = P(e.name ?? e.blockName) ?? s.name, s.blockName = P(e.blockName ?? e.name) ?? s.blockName;
|
|
335
|
+
const h = it(e.vertices ?? e.points);
|
|
336
|
+
h.length > 0 && (s.vertices = h);
|
|
337
|
+
const f = it(e.controlPoints ?? e.control_points);
|
|
338
|
+
f.length > 0 && (s.controlPoints = f);
|
|
339
|
+
const d = it(e.fitPoints ?? e.fit_points);
|
|
340
|
+
return d.length > 0 && (s.fitPoints = d), s;
|
|
341
|
+
}
|
|
342
|
+
function k(e) {
|
|
343
|
+
if (!e || typeof e != "object") return;
|
|
344
|
+
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);
|
|
345
|
+
if (!(!Number.isFinite(r) || !Number.isFinite(i)))
|
|
346
|
+
return Number.isFinite(n) ? { x: r, y: i, z: n } : { x: r, y: i };
|
|
347
|
+
}
|
|
348
|
+
function it(e) {
|
|
349
|
+
if (!Array.isArray(e)) return [];
|
|
350
|
+
const t = [];
|
|
351
|
+
for (const r of e) {
|
|
352
|
+
const i = k(r);
|
|
353
|
+
if (!i) continue;
|
|
354
|
+
const s = r, n = i, o = x(s.bulge);
|
|
355
|
+
o !== void 0 && (n.bulge = o);
|
|
356
|
+
const a = x(s.startWidth ?? s.start_width);
|
|
357
|
+
a !== void 0 && (n.startWidth = a);
|
|
358
|
+
const c = x(s.endWidth ?? s.end_width);
|
|
359
|
+
c !== void 0 && (n.endWidth = c), t.push(n);
|
|
360
|
+
}
|
|
361
|
+
return t;
|
|
362
|
+
}
|
|
363
|
+
function kt(e) {
|
|
364
|
+
var r;
|
|
365
|
+
const t = {};
|
|
366
|
+
for (const i of e.entities) {
|
|
367
|
+
const s = String(i.type ?? "UNKNOWN").toUpperCase();
|
|
368
|
+
t[s] = (t[s] ?? 0) + 1;
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
format: e.format,
|
|
372
|
+
sourceName: e.sourceName,
|
|
373
|
+
entityCount: e.entities.length,
|
|
374
|
+
layerCount: Object.keys(e.layers).length,
|
|
375
|
+
blockCount: Object.keys(e.blocks).length,
|
|
376
|
+
pageCount: ((r = e.pages) == null ? void 0 : r.length) ?? 0,
|
|
377
|
+
byType: t,
|
|
378
|
+
warnings: [...e.warnings]
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function St(e, t) {
|
|
382
|
+
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
383
|
+
}
|
|
384
|
+
function ue(e, t) {
|
|
385
|
+
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
386
|
+
}
|
|
387
|
+
function me(e) {
|
|
388
|
+
return e != null && e.length ? e.flatMap((t) => t.entities.map((r) => ({ ...r, pageIndex: t.index }))) : [];
|
|
389
|
+
}
|
|
390
|
+
function x(e) {
|
|
391
|
+
const t = Number(e);
|
|
392
|
+
return Number.isFinite(t) ? t : void 0;
|
|
393
|
+
}
|
|
394
|
+
function P(e) {
|
|
395
|
+
if (typeof e != "string" && typeof e != "number") return;
|
|
396
|
+
const t = String(e);
|
|
397
|
+
return t.length > 0 ? t : void 0;
|
|
398
|
+
}
|
|
399
|
+
function N() {
|
|
400
|
+
return { minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
|
|
401
|
+
}
|
|
402
|
+
function R(e) {
|
|
403
|
+
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;
|
|
404
|
+
}
|
|
405
|
+
function y(e, t) {
|
|
406
|
+
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));
|
|
407
|
+
}
|
|
408
|
+
function Yt(e, t, r) {
|
|
409
|
+
if (!m(t) || !Number.isFinite(r)) return;
|
|
410
|
+
const i = Math.abs(r);
|
|
411
|
+
y(e, { x: t.x - i, y: t.y - i }), y(e, { x: t.x + i, y: t.y + i });
|
|
412
|
+
}
|
|
413
|
+
function Ht(e, t = 0.02, r = 1e-6) {
|
|
414
|
+
if (!R(e)) return { minX: -10, minY: -10, maxX: 10, maxY: 10 };
|
|
415
|
+
const i = Math.max((e.maxX - e.minX) * t, r), s = Math.max((e.maxY - e.minY) * t, r);
|
|
416
|
+
return { minX: e.minX - i, minY: e.minY - s, maxX: e.maxX + i, maxY: e.maxY + s };
|
|
417
|
+
}
|
|
418
|
+
function m(e) {
|
|
419
|
+
return !!e && typeof e == "object" && Number.isFinite(e.x) && Number.isFinite(e.y);
|
|
420
|
+
}
|
|
421
|
+
function v(e) {
|
|
422
|
+
return { x: e.x, y: e.y };
|
|
423
|
+
}
|
|
424
|
+
function A(e) {
|
|
425
|
+
return e * Math.PI / 180;
|
|
426
|
+
}
|
|
427
|
+
function G(e, t, r, i, s = !0, n = 64) {
|
|
428
|
+
if (!m(e) || !Number.isFinite(t)) return [];
|
|
429
|
+
let o = r, a = i;
|
|
430
|
+
if (!Number.isFinite(o) || !Number.isFinite(a)) return [];
|
|
431
|
+
(Math.abs(o) > Math.PI * 2 + 1e-6 || Math.abs(a) > Math.PI * 2 + 1e-6) && (o = A(o), a = A(a)), s && a < o && (a += Math.PI * 2), !s && o < a && (o += Math.PI * 2);
|
|
432
|
+
const c = a - o, l = Math.max(8, Math.min(256, Math.ceil(Math.abs(c) / (Math.PI * 2) * n))), h = [];
|
|
433
|
+
for (let f = 0; f <= l; f++) {
|
|
434
|
+
const d = o + c * (f / l);
|
|
435
|
+
h.push({ x: e.x + Math.cos(d) * t, y: e.y + Math.sin(d) * t });
|
|
436
|
+
}
|
|
437
|
+
return h;
|
|
438
|
+
}
|
|
439
|
+
function Z(e, t, r = 1, i = 0, s = Math.PI * 2, n = 96) {
|
|
440
|
+
if (!m(e) || !m(t)) return [];
|
|
441
|
+
const o = Math.hypot(t.x, t.y);
|
|
442
|
+
if (!Number.isFinite(o) || o <= 0) return [];
|
|
443
|
+
const a = o * (Number.isFinite(r) && r > 0 ? r : 1), c = Math.atan2(t.y, t.x);
|
|
444
|
+
let l = Number.isFinite(i) ? i : 0, h = Number.isFinite(s) ? s : Math.PI * 2;
|
|
445
|
+
(Math.abs(l) > Math.PI * 2 + 1e-6 || Math.abs(h) > Math.PI * 2 + 1e-6) && (l = A(l), h = A(h)), h < l && (h += Math.PI * 2);
|
|
446
|
+
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(h - l) / (Math.PI * 2) * n))), d = [], p = Math.cos(c), g = Math.sin(c);
|
|
447
|
+
for (let S = 0; S <= f; S++) {
|
|
448
|
+
const M = l + (h - l) * (S / f), yt = Math.cos(M) * o, xt = Math.sin(M) * a;
|
|
449
|
+
d.push({ x: e.x + yt * p - xt * g, y: e.y + yt * g + xt * p });
|
|
450
|
+
}
|
|
451
|
+
return d;
|
|
452
|
+
}
|
|
453
|
+
function _t(e, t, r = 0, i = 16) {
|
|
454
|
+
if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [v(e), v(t)];
|
|
455
|
+
const s = Math.hypot(t.x - e.x, t.y - e.y);
|
|
456
|
+
if (s <= 1e-12) return [v(e), v(t)];
|
|
457
|
+
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, l = (t.y - e.y) / s, h = r >= 0 ? 1 : -1, f = Math.sqrt(Math.max(o * o - (s / 2) ** 2, 0)), d = { x: a.x - h * l * f, y: a.y + h * c * f }, p = Math.atan2(e.y - d.y, e.x - d.x), g = Math.atan2(t.y - d.y, t.x - d.x);
|
|
458
|
+
return G(d, o, p, g, r >= 0, i);
|
|
459
|
+
}
|
|
460
|
+
function Ut(e) {
|
|
461
|
+
return e.replace(/\\P/g, `
|
|
462
|
+
`).replace(/\\~|\\ /g, " ").replace(/\\[A-Za-z][^;]*;/g, "").replace(/[{}]/g, "").replace(/\\[A-Za-z]/g, "").trim();
|
|
463
|
+
}
|
|
464
|
+
function B(e, t, r) {
|
|
465
|
+
return Math.min(r, Math.max(t, e));
|
|
466
|
+
}
|
|
467
|
+
class pe {
|
|
468
|
+
constructor(t = {}) {
|
|
469
|
+
u(this, "id", "dxf");
|
|
470
|
+
u(this, "label", "DXF / JavaScript parser");
|
|
471
|
+
u(this, "formats", ["dxf"]);
|
|
472
|
+
u(this, "defaults");
|
|
473
|
+
this.defaults = t;
|
|
474
|
+
}
|
|
475
|
+
accepts(t, r) {
|
|
476
|
+
return Y(t) === "dxf" || rt(t, r) === "dxf";
|
|
477
|
+
}
|
|
478
|
+
async load(t, r = {}) {
|
|
479
|
+
var h;
|
|
480
|
+
({ ...this.defaults, ...r });
|
|
481
|
+
const i = performance.now(), s = await et(t), n = Pe(s), o = [];
|
|
482
|
+
let a;
|
|
483
|
+
try {
|
|
484
|
+
a = await ge(n);
|
|
485
|
+
} catch (f) {
|
|
486
|
+
o.push(`dxf-parser failed, using built-in fallback parser: ${f instanceof Error ? f.message : String(f)}`), a = ke(n);
|
|
487
|
+
}
|
|
488
|
+
const c = be(a, t.fileName ?? ((h = t.file) == null ? void 0 : h.name), o), l = performance.now() - i;
|
|
489
|
+
return { document: c, raw: a, bytes: s.byteLength, elapsedMs: l, format: "dxf", warnings: c.warnings };
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
async function ge(e) {
|
|
493
|
+
const t = await import("dxf-parser"), r = t.default ?? t.DxfParser;
|
|
494
|
+
if (!r) throw new Error("dxf-parser did not expose a parser constructor.");
|
|
495
|
+
return new r().parseSync(e);
|
|
496
|
+
}
|
|
497
|
+
function be(e, t, r = []) {
|
|
498
|
+
const i = e && typeof e == "object" ? e : {}, s = ye(i), n = xe(i), a = (Array.isArray(i.entities) ? i.entities : []).filter((l) => !!l && typeof l == "object").map((l) => gt(l)), c = Xt({
|
|
499
|
+
format: "dxf",
|
|
500
|
+
sourceName: t,
|
|
501
|
+
header: i.header && typeof i.header == "object" ? i.header : {},
|
|
502
|
+
layers: s,
|
|
503
|
+
blocks: n,
|
|
504
|
+
entities: a,
|
|
505
|
+
metadata: { parser: "dxf-parser + cad-viewer normalizer" },
|
|
506
|
+
warnings: r,
|
|
507
|
+
raw: e
|
|
508
|
+
});
|
|
509
|
+
return a.length === 0 && c.warnings.push("DXF file did not expose any ENTITIES."), c;
|
|
510
|
+
}
|
|
511
|
+
function gt(e) {
|
|
512
|
+
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r = de(e, t), i = x(e.colorIndex ?? e.colorNumber ?? e.aci), s = x(e.color);
|
|
513
|
+
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 = P(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 = k(e.startPoint ?? { x: e.x1 ?? e.x, y: e.y1 ?? e.y, z: e.z1 ?? e.z }) ?? r.startPoint, r.endPoint = k(e.endPoint ?? { x: e.x2, y: e.y2, z: e.z2 }) ?? r.endPoint), (t === "TEXT" || t === "MTEXT" || t === "ATTRIB" || t === "ATTDEF") && (r.insertionPoint = k(e.startPoint ?? e.position ?? e.insertionPoint) ?? r.insertionPoint, r.text = P(e.text ?? e.string ?? e.value) ?? r.text, r.textHeight = x(e.textHeight ?? e.height) ?? r.textHeight, r.rotation = Nt(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") {
|
|
514
|
+
r.blockName = P(e.name ?? e.blockName) ?? r.blockName, r.insertionPoint = k(e.position ?? e.insertionPoint ?? e.point) ?? r.insertionPoint;
|
|
515
|
+
const n = x(e.xScale ?? e.scaleX ?? e.xscale), o = x(e.yScale ?? e.scaleY ?? e.yscale), a = x(e.zScale ?? e.scaleZ ?? e.zscale);
|
|
516
|
+
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation = Nt(e.rotation ?? e.angle);
|
|
517
|
+
}
|
|
518
|
+
if (t === "SPLINE") {
|
|
519
|
+
const n = q(e.controlPoints ?? e.control_points ?? e.points);
|
|
520
|
+
n.length && (r.controlPoints = n);
|
|
521
|
+
const o = q(e.fitPoints ?? e.fit_points);
|
|
522
|
+
o.length && (r.fitPoints = o);
|
|
523
|
+
}
|
|
524
|
+
return t === "HATCH" && (r.loops = Ce(e), r.fillColorIndex = r.colorIndex), (t === "SOLID" || t === "TRACE" || t === "3DFACE") && (r.vertices = we(e), r.fillColorIndex = r.colorIndex), r;
|
|
525
|
+
}
|
|
526
|
+
function ye(e) {
|
|
527
|
+
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 = ve(i);
|
|
528
|
+
for (const n of s) {
|
|
529
|
+
const o = n, a = P(o.name ?? o.layerName);
|
|
530
|
+
a && St(t, {
|
|
531
|
+
name: a,
|
|
532
|
+
color: o.color ?? o.colorNumber ?? o.colorIndex,
|
|
533
|
+
colorIndex: x(o.colorNumber ?? o.colorIndex ?? o.color),
|
|
534
|
+
lineType: P(o.lineType ?? o.linetype),
|
|
535
|
+
isVisible: Number(o.colorNumber ?? o.colorIndex ?? o.color ?? 1) >= 0,
|
|
536
|
+
isFrozen: !!o.frozen,
|
|
537
|
+
isLocked: !!o.locked,
|
|
538
|
+
raw: o
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
return t[0] || St(t, { name: "0", colorIndex: 7, isVisible: !0 }), t;
|
|
542
|
+
}
|
|
543
|
+
function xe(e) {
|
|
544
|
+
const t = {}, r = e.blocks;
|
|
545
|
+
if (!r || typeof r != "object") return t;
|
|
546
|
+
if (Array.isArray(r))
|
|
547
|
+
for (const i of r) Mt(t, i);
|
|
548
|
+
else
|
|
549
|
+
for (const [i, s] of Object.entries(r)) Mt(t, s, i);
|
|
550
|
+
return t;
|
|
551
|
+
}
|
|
552
|
+
function Mt(e, t, r) {
|
|
553
|
+
if (!t || typeof t != "object") return;
|
|
554
|
+
const i = t, s = P(i.name ?? i.blockName ?? r);
|
|
555
|
+
if (!s) return;
|
|
556
|
+
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) => gt(a));
|
|
557
|
+
ue(e, { name: s, basePoint: k(i.basePoint ?? i.position) ?? { x: 0, y: 0 }, entities: o, raw: i });
|
|
558
|
+
}
|
|
559
|
+
function ve(e) {
|
|
560
|
+
if (!e) return [];
|
|
561
|
+
if (Array.isArray(e)) return e;
|
|
562
|
+
if (typeof e != "object") return [];
|
|
563
|
+
const t = e;
|
|
564
|
+
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");
|
|
565
|
+
}
|
|
566
|
+
function q(e) {
|
|
567
|
+
return Array.isArray(e) ? e.map(k).filter((t) => !!t) : [];
|
|
568
|
+
}
|
|
569
|
+
function we(e) {
|
|
570
|
+
const t = q(e.vertices ?? e.points);
|
|
571
|
+
if (t.length) return t;
|
|
572
|
+
const r = [];
|
|
573
|
+
for (let i = 0; i < 4; i++) {
|
|
574
|
+
const s = k({ x: e[`x${i}`] ?? e[`x${i + 1}`], y: e[`y${i}`] ?? e[`y${i + 1}`], z: e[`z${i}`] ?? e[`z${i + 1}`] });
|
|
575
|
+
s && r.push(s);
|
|
576
|
+
}
|
|
577
|
+
return r;
|
|
578
|
+
}
|
|
579
|
+
function Ce(e) {
|
|
580
|
+
const t = e.boundaryLoops ?? e.loops ?? e.paths;
|
|
581
|
+
if (Array.isArray(t))
|
|
582
|
+
return t.map((r) => {
|
|
583
|
+
const i = r;
|
|
584
|
+
return { vertices: q(i.vertices ?? i.points), isClosed: !0 };
|
|
585
|
+
}).filter((r) => r.vertices && r.vertices.length > 0);
|
|
586
|
+
}
|
|
587
|
+
function Nt(e) {
|
|
588
|
+
const t = x(e);
|
|
589
|
+
if (t !== void 0)
|
|
590
|
+
return Math.abs(t) > Math.PI * 2 + 1e-6 ? A(t) : t;
|
|
591
|
+
}
|
|
592
|
+
function Et(e) {
|
|
593
|
+
const t = x(e);
|
|
594
|
+
if (t !== void 0)
|
|
595
|
+
return Math.abs(t) > Math.PI * 2 + 1e-6 ? A(t) : t;
|
|
596
|
+
}
|
|
597
|
+
function Pe(e) {
|
|
598
|
+
const t = new TextDecoder("utf-8", { fatal: !1 }).decode(e);
|
|
599
|
+
return t.includes("SECTION") ? t : new TextDecoder("iso-8859-1", { fatal: !1 }).decode(e);
|
|
600
|
+
}
|
|
601
|
+
function ke(e) {
|
|
602
|
+
var l, h;
|
|
603
|
+
const t = e.replace(/\r\n/g, `
|
|
604
|
+
`).replace(/\r/g, `
|
|
605
|
+
`).split(`
|
|
606
|
+
`), r = [];
|
|
607
|
+
for (let f = 0; f < t.length - 1; f += 2) {
|
|
608
|
+
const d = Number((l = t[f]) == null ? void 0 : l.trim()), p = t[f + 1] ?? "";
|
|
609
|
+
Number.isFinite(d) && r.push({ code: d, value: p.trimEnd() });
|
|
610
|
+
}
|
|
611
|
+
const i = [], s = {};
|
|
612
|
+
let n = "", o = [], a;
|
|
613
|
+
for (let f = 0; f < r.length; f++) {
|
|
614
|
+
const d = r[f];
|
|
615
|
+
if (d.code === 0 && d.value === "SECTION") {
|
|
616
|
+
n = ((h = r[f + 1]) == null ? void 0 : h.code) === 2 ? r[f + 1].value.toUpperCase() : "", f++;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
if (d.code === 0 && d.value === "ENDSEC") {
|
|
620
|
+
c(), n = "";
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
n === "ENTITIES" && (d.code === 0 ? (c(), o = [d]) : o.push(d));
|
|
624
|
+
}
|
|
625
|
+
return c(), { header: {}, tables: {}, entities: i, blocks: s };
|
|
626
|
+
function c() {
|
|
627
|
+
var p;
|
|
628
|
+
if (!o.length) return;
|
|
629
|
+
const f = (p = o[0]) == null ? void 0 : p.value.toUpperCase();
|
|
630
|
+
if (f === "VERTEX" && a) {
|
|
631
|
+
const g = C(o, 10, 20, 30);
|
|
632
|
+
g && (a.vertices ?? (a.vertices = [])).push({ ...g, bulge: b(o, 42) }), o = [];
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (f === "SEQEND") {
|
|
636
|
+
a && i.push(a), a = void 0, o = [];
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (a && (i.push(a), a = void 0), !f || f === "EOF") {
|
|
640
|
+
o = [];
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const d = Se(f, o);
|
|
644
|
+
f === "POLYLINE" ? a = d : i.push(d), o = [];
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function Se(e, t) {
|
|
648
|
+
const r = {
|
|
649
|
+
type: e,
|
|
650
|
+
handle: z(t, 5),
|
|
651
|
+
layer: z(t, 8) ?? "0",
|
|
652
|
+
colorIndex: b(t, 62),
|
|
653
|
+
trueColor: b(t, 420),
|
|
654
|
+
lineType: z(t, 6),
|
|
655
|
+
lineweight: b(t, 370)
|
|
656
|
+
};
|
|
657
|
+
switch (e) {
|
|
658
|
+
case "LINE":
|
|
659
|
+
Object.assign(r, { startPoint: C(t, 10, 20, 30), endPoint: C(t, 11, 21, 31) });
|
|
660
|
+
break;
|
|
661
|
+
case "CIRCLE":
|
|
662
|
+
Object.assign(r, { center: C(t, 10, 20, 30), radius: b(t, 40) });
|
|
663
|
+
break;
|
|
664
|
+
case "ARC":
|
|
665
|
+
Object.assign(r, { center: C(t, 10, 20, 30), radius: b(t, 40), startAngle: V(b(t, 50)), endAngle: V(b(t, 51)) });
|
|
666
|
+
break;
|
|
667
|
+
case "POINT":
|
|
668
|
+
Object.assign(r, { point: C(t, 10, 20, 30) });
|
|
669
|
+
break;
|
|
670
|
+
case "TEXT":
|
|
671
|
+
case "MTEXT":
|
|
672
|
+
Object.assign(r, { insertionPoint: C(t, 10, 20, 30), text: Ee(t), textHeight: b(t, 40), rotation: V(b(t, 50)) });
|
|
673
|
+
break;
|
|
674
|
+
case "LWPOLYLINE":
|
|
675
|
+
Object.assign(r, { vertices: Ne(t), flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
676
|
+
break;
|
|
677
|
+
case "POLYLINE":
|
|
678
|
+
Object.assign(r, { vertices: [], flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
679
|
+
break;
|
|
680
|
+
case "ELLIPSE":
|
|
681
|
+
Object.assign(r, { center: C(t, 10, 20, 30), majorAxisEndPoint: C(t, 11, 21, 31), axisRatio: b(t, 40), startAngle: b(t, 41), endAngle: b(t, 42) });
|
|
682
|
+
break;
|
|
683
|
+
case "SPLINE":
|
|
684
|
+
Object.assign(r, { controlPoints: Me(t, 10, 20, 30), degree: b(t, 71), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
685
|
+
break;
|
|
686
|
+
case "INSERT":
|
|
687
|
+
Object.assign(r, { name: z(t, 2), blockName: z(t, 2), insertionPoint: C(t, 10, 20, 30), rotation: V(b(t, 50)), scale: { x: b(t, 41) ?? 1, y: b(t, 42) ?? b(t, 41) ?? 1, z: b(t, 43) ?? 1 } });
|
|
688
|
+
break;
|
|
689
|
+
case "SOLID":
|
|
690
|
+
case "TRACE":
|
|
691
|
+
case "3DFACE":
|
|
692
|
+
Object.assign(r, { vertices: [C(t, 10, 20, 30), C(t, 11, 21, 31), C(t, 12, 22, 32), C(t, 13, 23, 33)].filter(Boolean) });
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
return gt(r);
|
|
696
|
+
}
|
|
697
|
+
function b(e, t) {
|
|
698
|
+
var s;
|
|
699
|
+
const r = (s = e.find((n) => n.code === t)) == null ? void 0 : s.value, i = Number(r);
|
|
700
|
+
return Number.isFinite(i) ? i : void 0;
|
|
701
|
+
}
|
|
702
|
+
function z(e, t) {
|
|
703
|
+
var i;
|
|
704
|
+
const r = (i = e.find((s) => s.code === t)) == null ? void 0 : i.value;
|
|
705
|
+
return r && r.length > 0 ? r : void 0;
|
|
706
|
+
}
|
|
707
|
+
function C(e, t, r, i) {
|
|
708
|
+
const s = b(e, t), n = b(e, r), o = b(e, i);
|
|
709
|
+
if (!(s === void 0 || n === void 0))
|
|
710
|
+
return o === void 0 ? { x: s, y: n } : { x: s, y: n, z: o };
|
|
711
|
+
}
|
|
712
|
+
function Me(e, t, r, i) {
|
|
713
|
+
const s = [];
|
|
714
|
+
for (let n = 0; n < e.length; n++) {
|
|
715
|
+
if (e[n].code !== t) continue;
|
|
716
|
+
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), l = Number(a == null ? void 0 : a.value), h = Number(c == null ? void 0 : c.value);
|
|
717
|
+
Number.isFinite(o) && Number.isFinite(l) && s.push(Number.isFinite(h) ? { x: o, y: l, z: h } : { x: o, y: l });
|
|
718
|
+
}
|
|
719
|
+
return s;
|
|
720
|
+
}
|
|
721
|
+
function Ne(e) {
|
|
722
|
+
const t = [];
|
|
723
|
+
for (let r = 0; r < e.length; r++) {
|
|
724
|
+
if (e[r].code !== 10) continue;
|
|
725
|
+
const i = Number(e[r].value);
|
|
726
|
+
let s, n;
|
|
727
|
+
for (let o = r + 1; o < e.length && e[o].code !== 10; o++)
|
|
728
|
+
e[o].code === 20 && (s = Number(e[o].value)), e[o].code === 42 && (n = Number(e[o].value));
|
|
729
|
+
Number.isFinite(i) && Number.isFinite(s) && t.push({ x: i, y: s, bulge: Number.isFinite(n) ? n : void 0 });
|
|
730
|
+
}
|
|
731
|
+
return t;
|
|
732
|
+
}
|
|
733
|
+
function Ee(e) {
|
|
734
|
+
const t = e.filter((r) => r.code === 1 || r.code === 3).map((r) => r.value);
|
|
735
|
+
return t.length ? t.join("") : void 0;
|
|
736
|
+
}
|
|
737
|
+
function V(e) {
|
|
738
|
+
return typeof e == "number" && Number.isFinite(e) ? A(e) : void 0;
|
|
739
|
+
}
|
|
740
|
+
const Ie = {
|
|
741
|
+
1: "#ff0000",
|
|
742
|
+
2: "#ffff00",
|
|
743
|
+
3: "#00ff00",
|
|
744
|
+
4: "#00ffff",
|
|
745
|
+
5: "#0000ff",
|
|
746
|
+
6: "#ff00ff",
|
|
747
|
+
8: "#808080",
|
|
748
|
+
9: "#c0c0c0",
|
|
749
|
+
10: "#ff0000",
|
|
750
|
+
11: "#ff7f7f",
|
|
751
|
+
12: "#a50000",
|
|
752
|
+
13: "#a55252",
|
|
753
|
+
14: "#7f0000",
|
|
754
|
+
15: "#7f3f3f",
|
|
755
|
+
16: "#4c0000",
|
|
756
|
+
17: "#4c2626",
|
|
757
|
+
18: "#260000",
|
|
758
|
+
19: "#261313",
|
|
759
|
+
20: "#ff3f00",
|
|
760
|
+
21: "#ff9f7f",
|
|
761
|
+
22: "#a52900",
|
|
762
|
+
23: "#a56752",
|
|
763
|
+
24: "#7f1f00",
|
|
764
|
+
25: "#7f4f3f",
|
|
765
|
+
26: "#4c1300",
|
|
766
|
+
27: "#4c2f26",
|
|
767
|
+
28: "#260900",
|
|
768
|
+
29: "#261713",
|
|
769
|
+
30: "#ff7f00",
|
|
770
|
+
31: "#ffbf7f",
|
|
771
|
+
32: "#a55200",
|
|
772
|
+
33: "#a57c52",
|
|
773
|
+
34: "#7f3f00",
|
|
774
|
+
35: "#7f5f3f",
|
|
775
|
+
36: "#4c2600",
|
|
776
|
+
37: "#4c3926",
|
|
777
|
+
38: "#261300",
|
|
778
|
+
39: "#261c13",
|
|
779
|
+
40: "#ffbf00",
|
|
780
|
+
41: "#ffdf7f",
|
|
781
|
+
42: "#a57c00",
|
|
782
|
+
43: "#a59152",
|
|
783
|
+
44: "#7f5f00",
|
|
784
|
+
45: "#7f6f3f",
|
|
785
|
+
46: "#4c3900",
|
|
786
|
+
47: "#4c4226",
|
|
787
|
+
48: "#261c00",
|
|
788
|
+
49: "#262113",
|
|
789
|
+
50: "#ffff00",
|
|
790
|
+
51: "#ffff7f",
|
|
791
|
+
52: "#a5a500",
|
|
792
|
+
53: "#a5a552",
|
|
793
|
+
54: "#7f7f00",
|
|
794
|
+
55: "#7f7f3f",
|
|
795
|
+
56: "#4c4c00",
|
|
796
|
+
57: "#4c4c26",
|
|
797
|
+
58: "#262600",
|
|
798
|
+
59: "#262613",
|
|
799
|
+
60: "#bfff00",
|
|
800
|
+
61: "#dfff7f",
|
|
801
|
+
62: "#7ca500",
|
|
802
|
+
63: "#91a552",
|
|
803
|
+
64: "#5f7f00",
|
|
804
|
+
65: "#6f7f3f",
|
|
805
|
+
66: "#394c00",
|
|
806
|
+
67: "#424c26",
|
|
807
|
+
68: "#1c2600",
|
|
808
|
+
69: "#212613",
|
|
809
|
+
70: "#7fff00",
|
|
810
|
+
71: "#bfff7f",
|
|
811
|
+
72: "#52a500",
|
|
812
|
+
73: "#7ca552",
|
|
813
|
+
74: "#3f7f00",
|
|
814
|
+
75: "#5f7f3f",
|
|
815
|
+
76: "#264c00",
|
|
816
|
+
77: "#394c26",
|
|
817
|
+
78: "#132600",
|
|
818
|
+
79: "#1c2613",
|
|
819
|
+
80: "#3fff00",
|
|
820
|
+
81: "#9fff7f",
|
|
821
|
+
82: "#29a500",
|
|
822
|
+
83: "#67a552",
|
|
823
|
+
84: "#1f7f00",
|
|
824
|
+
85: "#4f7f3f",
|
|
825
|
+
86: "#134c00",
|
|
826
|
+
87: "#2f4c26",
|
|
827
|
+
88: "#092600",
|
|
828
|
+
89: "#172613",
|
|
829
|
+
90: "#00ff00",
|
|
830
|
+
91: "#7fff7f",
|
|
831
|
+
92: "#00a500",
|
|
832
|
+
93: "#52a552",
|
|
833
|
+
94: "#007f00",
|
|
834
|
+
95: "#3f7f3f",
|
|
835
|
+
96: "#004c00",
|
|
836
|
+
97: "#264c26",
|
|
837
|
+
98: "#002600",
|
|
838
|
+
99: "#132613",
|
|
839
|
+
100: "#00ff3f",
|
|
840
|
+
101: "#7fff9f",
|
|
841
|
+
102: "#00a529",
|
|
842
|
+
103: "#52a567",
|
|
843
|
+
104: "#007f1f",
|
|
844
|
+
105: "#3f7f4f",
|
|
845
|
+
106: "#004c13",
|
|
846
|
+
107: "#264c2f",
|
|
847
|
+
108: "#002609",
|
|
848
|
+
109: "#132617",
|
|
849
|
+
110: "#00ff7f",
|
|
850
|
+
111: "#7fffbf",
|
|
851
|
+
112: "#00a552",
|
|
852
|
+
113: "#52a57c",
|
|
853
|
+
114: "#007f3f",
|
|
854
|
+
115: "#3f7f5f",
|
|
855
|
+
116: "#004c26",
|
|
856
|
+
117: "#264c39",
|
|
857
|
+
118: "#002613",
|
|
858
|
+
119: "#13261c",
|
|
859
|
+
120: "#00ffbf",
|
|
860
|
+
121: "#7fffdf",
|
|
861
|
+
122: "#00a57c",
|
|
862
|
+
123: "#52a591",
|
|
863
|
+
124: "#007f5f",
|
|
864
|
+
125: "#3f7f6f",
|
|
865
|
+
126: "#004c39",
|
|
866
|
+
127: "#264c42",
|
|
867
|
+
128: "#00261c",
|
|
868
|
+
129: "#132621",
|
|
869
|
+
130: "#00ffff",
|
|
870
|
+
131: "#7fffff",
|
|
871
|
+
132: "#00a5a5",
|
|
872
|
+
133: "#52a5a5",
|
|
873
|
+
134: "#007f7f",
|
|
874
|
+
135: "#3f7f7f",
|
|
875
|
+
136: "#004c4c",
|
|
876
|
+
137: "#264c4c",
|
|
877
|
+
138: "#002626",
|
|
878
|
+
139: "#132626",
|
|
879
|
+
140: "#00bfff",
|
|
880
|
+
141: "#7fdfff",
|
|
881
|
+
142: "#007ca5",
|
|
882
|
+
143: "#5291a5",
|
|
883
|
+
144: "#005f7f",
|
|
884
|
+
145: "#3f6f7f",
|
|
885
|
+
146: "#00394c",
|
|
886
|
+
147: "#26424c",
|
|
887
|
+
148: "#001c26",
|
|
888
|
+
149: "#132126",
|
|
889
|
+
150: "#007fff",
|
|
890
|
+
151: "#7fbfff",
|
|
891
|
+
152: "#0052a5",
|
|
892
|
+
153: "#527ca5",
|
|
893
|
+
154: "#003f7f",
|
|
894
|
+
155: "#3f5f7f",
|
|
895
|
+
156: "#00264c",
|
|
896
|
+
157: "#26394c",
|
|
897
|
+
158: "#001326",
|
|
898
|
+
159: "#131c26",
|
|
899
|
+
160: "#003fff",
|
|
900
|
+
161: "#7f9fff",
|
|
901
|
+
162: "#0029a5",
|
|
902
|
+
163: "#5267a5",
|
|
903
|
+
164: "#001f7f",
|
|
904
|
+
165: "#3f4f7f",
|
|
905
|
+
166: "#00134c",
|
|
906
|
+
167: "#262f4c",
|
|
907
|
+
168: "#000926",
|
|
908
|
+
169: "#131726",
|
|
909
|
+
170: "#0000ff",
|
|
910
|
+
171: "#7f7fff",
|
|
911
|
+
172: "#0000a5",
|
|
912
|
+
173: "#5252a5",
|
|
913
|
+
174: "#00007f",
|
|
914
|
+
175: "#3f3f7f",
|
|
915
|
+
176: "#00004c",
|
|
916
|
+
177: "#26264c",
|
|
917
|
+
178: "#000026",
|
|
918
|
+
179: "#131326",
|
|
919
|
+
180: "#3f00ff",
|
|
920
|
+
181: "#9f7fff",
|
|
921
|
+
182: "#2900a5",
|
|
922
|
+
183: "#6752a5",
|
|
923
|
+
184: "#1f007f",
|
|
924
|
+
185: "#4f3f7f",
|
|
925
|
+
186: "#13004c",
|
|
926
|
+
187: "#2f264c",
|
|
927
|
+
188: "#090026",
|
|
928
|
+
189: "#171326",
|
|
929
|
+
190: "#7f00ff",
|
|
930
|
+
191: "#bf7fff",
|
|
931
|
+
192: "#5200a5",
|
|
932
|
+
193: "#7c52a5",
|
|
933
|
+
194: "#3f007f",
|
|
934
|
+
195: "#5f3f7f",
|
|
935
|
+
196: "#26004c",
|
|
936
|
+
197: "#39264c",
|
|
937
|
+
198: "#130026",
|
|
938
|
+
199: "#1c1326",
|
|
939
|
+
200: "#bf00ff",
|
|
940
|
+
201: "#df7fff",
|
|
941
|
+
202: "#7c00a5",
|
|
942
|
+
203: "#9152a5",
|
|
943
|
+
204: "#5f007f",
|
|
944
|
+
205: "#6f3f7f",
|
|
945
|
+
206: "#39004c",
|
|
946
|
+
207: "#42264c",
|
|
947
|
+
208: "#1c0026",
|
|
948
|
+
209: "#211326",
|
|
949
|
+
210: "#ff00ff",
|
|
950
|
+
211: "#ff7fff",
|
|
951
|
+
212: "#a500a5",
|
|
952
|
+
213: "#a552a5",
|
|
953
|
+
214: "#7f007f",
|
|
954
|
+
215: "#7f3f7f",
|
|
955
|
+
216: "#4c004c",
|
|
956
|
+
217: "#4c264c",
|
|
957
|
+
218: "#260026",
|
|
958
|
+
219: "#261326",
|
|
959
|
+
220: "#ff00bf",
|
|
960
|
+
221: "#ff7fdf",
|
|
961
|
+
222: "#a5007c",
|
|
962
|
+
223: "#a55291",
|
|
963
|
+
224: "#7f005f",
|
|
964
|
+
225: "#7f3f6f",
|
|
965
|
+
226: "#4c0039",
|
|
966
|
+
227: "#4c2642",
|
|
967
|
+
228: "#26001c",
|
|
968
|
+
229: "#261321",
|
|
969
|
+
230: "#ff007f",
|
|
970
|
+
231: "#ff7fbf",
|
|
971
|
+
232: "#a50052",
|
|
972
|
+
233: "#a5527c",
|
|
973
|
+
234: "#7f003f",
|
|
974
|
+
235: "#7f3f5f",
|
|
975
|
+
236: "#4c0026",
|
|
976
|
+
237: "#4c2639",
|
|
977
|
+
238: "#260013",
|
|
978
|
+
239: "#26131c",
|
|
979
|
+
240: "#ff003f",
|
|
980
|
+
241: "#ff7f9f",
|
|
981
|
+
242: "#a50029",
|
|
982
|
+
243: "#a55267",
|
|
983
|
+
244: "#7f001f",
|
|
984
|
+
245: "#7f3f4f",
|
|
985
|
+
246: "#4c0013",
|
|
986
|
+
247: "#4c262f",
|
|
987
|
+
248: "#260009",
|
|
988
|
+
249: "#261317",
|
|
989
|
+
250: "#333333",
|
|
990
|
+
251: "#505050",
|
|
991
|
+
252: "#696969",
|
|
992
|
+
253: "#828282",
|
|
993
|
+
254: "#bebebe",
|
|
994
|
+
255: "#ffffff"
|
|
995
|
+
};
|
|
996
|
+
function T(e, t = "#ffffff", r = t) {
|
|
997
|
+
if (typeof e != "number" || Number.isNaN(e)) return t;
|
|
998
|
+
const i = Math.abs(Math.trunc(e));
|
|
999
|
+
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r : Ie[i] ?? t;
|
|
1000
|
+
}
|
|
1001
|
+
function H(e, t = "rgb") {
|
|
1002
|
+
const r = Math.max(0, Math.trunc(e)) & 16777215, i = r >> 16 & 255, s = r >> 8 & 255, n = r & 255;
|
|
1003
|
+
return `rgb(${t === "rgb" ? i : n}, ${s}, ${t === "rgb" ? n : i})`;
|
|
1004
|
+
}
|
|
1005
|
+
function F(e) {
|
|
1006
|
+
if (typeof e == "string") {
|
|
1007
|
+
const t = e.trim();
|
|
1008
|
+
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ? K(t) ?? t : {
|
|
1009
|
+
red: "#ff0000",
|
|
1010
|
+
yellow: "#ffff00",
|
|
1011
|
+
green: "#00ff00",
|
|
1012
|
+
cyan: "#00ffff",
|
|
1013
|
+
blue: "#0000ff",
|
|
1014
|
+
magenta: "#ff00ff",
|
|
1015
|
+
white: "#ffffff",
|
|
1016
|
+
black: "#000000",
|
|
1017
|
+
grey: "#808080",
|
|
1018
|
+
gray: "#808080"
|
|
1019
|
+
}[t.toLowerCase()] : void 0;
|
|
1020
|
+
}
|
|
1021
|
+
if (e && typeof e == "object") {
|
|
1022
|
+
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);
|
|
1023
|
+
if ([r, i, s].every(Number.isFinite))
|
|
1024
|
+
return Number.isFinite(n) && n >= 0 && n < 1 ? `rgba(${r}, ${i}, ${s}, ${n})` : `rgb(${r}, ${i}, ${s})`;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function K(e) {
|
|
1028
|
+
if (!e) return;
|
|
1029
|
+
const t = e.trim();
|
|
1030
|
+
if (/^#[0-9a-f]{8}$/i.test(t)) {
|
|
1031
|
+
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);
|
|
1032
|
+
return r >= 0.999 ? `rgb(${i}, ${s}, ${n})` : `rgba(${i}, ${s}, ${n}, ${ut(r)})`;
|
|
1033
|
+
}
|
|
1034
|
+
if (/^#[0-9a-f]{6}$/i.test(t) || /^#[0-9a-f]{3}$/i.test(t)) return t;
|
|
1035
|
+
if (/^sc#/i.test(t)) {
|
|
1036
|
+
const r = t.slice(3).split(",").map((a) => Number(a.trim())), [i, s, n, o] = r.length === 4 ? r : [1, ...r];
|
|
1037
|
+
if ([i, s, n, o].every(Number.isFinite)) return `rgba(${Math.round(s * 255)}, ${Math.round(n * 255)}, ${Math.round(o * 255)}, ${ut(i)})`;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function D(e, t, r = {}) {
|
|
1041
|
+
const i = r.foreground ?? "#ffffff", s = i;
|
|
1042
|
+
let n;
|
|
1043
|
+
const o = F(e.trueColor) ?? F(e.color) ?? F(e.colorName);
|
|
1044
|
+
if (o && (n = o), !n) {
|
|
1045
|
+
const a = De(e, ["trueColor", "true_color", "truecolor", "colorRGB", "colorRgb", "rgbColor", "rgb"]);
|
|
1046
|
+
typeof a == "number" && a >= 0 && a <= 16777215 && (n = H(a, r.trueColorByteOrder ?? "rgb"));
|
|
1047
|
+
}
|
|
1048
|
+
if (!n) {
|
|
1049
|
+
const a = Gt(e.colorIndex, e.colorNumber, e.aci);
|
|
1050
|
+
typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (n = T(a, s, i));
|
|
1051
|
+
}
|
|
1052
|
+
if (!n && typeof e.color == "number") {
|
|
1053
|
+
const a = Number(e.color);
|
|
1054
|
+
Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (n = T(a, s, i)) : n = H(a, r.trueColorByteOrder ?? "rgb");
|
|
1055
|
+
}
|
|
1056
|
+
if (!n) {
|
|
1057
|
+
const a = Fe(t, e.layer);
|
|
1058
|
+
n = Ae(a, r);
|
|
1059
|
+
}
|
|
1060
|
+
return Vt(n ?? s, r);
|
|
1061
|
+
}
|
|
1062
|
+
function ft(e, t, r = {}) {
|
|
1063
|
+
let i;
|
|
1064
|
+
const s = F(e.fillColor);
|
|
1065
|
+
if (s && (i = s), !i && typeof e.fillColor == "number") {
|
|
1066
|
+
const n = e.fillColor;
|
|
1067
|
+
i = Math.abs(n) <= 257 ? T(n, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff") : H(n, r.trueColorByteOrder ?? "rgb");
|
|
1068
|
+
}
|
|
1069
|
+
return !i && typeof e.fillColorIndex == "number" && (i = T(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ? Vt(i, r) : void 0;
|
|
1070
|
+
}
|
|
1071
|
+
function Vt(e, t = {}) {
|
|
1072
|
+
if (t.contrastMode !== "adaptive") return e;
|
|
1073
|
+
const r = t.background ?? "#0b1020", i = t.foreground ?? "#ffffff";
|
|
1074
|
+
return Te(e, r, i, t.minColorContrast ?? 2.4);
|
|
1075
|
+
}
|
|
1076
|
+
function Te(e, t, r, i = 2.4) {
|
|
1077
|
+
const s = st(r) ?? { r: 255, g: 255, b: 255, a: 1 }, n = st(t) ?? { r: 11, g: 16, b: 32, a: 1 }, o = st(e);
|
|
1078
|
+
if (!o) return e;
|
|
1079
|
+
const a = It(o, n);
|
|
1080
|
+
if (nt(a, n) >= i) return e;
|
|
1081
|
+
const c = dt(n), l = c < 0.5 ? { r: 255, g: 255, b: 255, a: o.a } : { r: 0, g: 0, b: 0, a: o.a };
|
|
1082
|
+
for (const h of [0.25, 0.4, 0.55, 0.7, 0.85, 1]) {
|
|
1083
|
+
const f = We(o, l, h);
|
|
1084
|
+
if (nt(It(f, n), n) >= i) return Tt(f);
|
|
1085
|
+
}
|
|
1086
|
+
return nt(s, n) >= i ? Tt(s) : c < 0.5 ? "#ffffff" : "#000000";
|
|
1087
|
+
}
|
|
1088
|
+
function $t(e) {
|
|
1089
|
+
return e ? e.isVisible !== !1 && e.isFrozen !== !0 : !0;
|
|
1090
|
+
}
|
|
1091
|
+
function Ae(e, t) {
|
|
1092
|
+
if (!e) return;
|
|
1093
|
+
const r = t.foreground ?? "#ffffff", i = F(e.trueColor);
|
|
1094
|
+
if (i) return i;
|
|
1095
|
+
if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return H(e.trueColor, t.trueColorByteOrder ?? "rgb");
|
|
1096
|
+
const s = F(e.color);
|
|
1097
|
+
if (s) return s;
|
|
1098
|
+
if (Be(e.colorIndex)) return T(e.colorIndex, r, r);
|
|
1099
|
+
if (typeof e.color == "number") {
|
|
1100
|
+
const n = Number(e.color);
|
|
1101
|
+
return Math.abs(n) <= 257 ? T(n, r, r) : H(n, t.trueColorByteOrder ?? "rgb");
|
|
1102
|
+
}
|
|
1103
|
+
if (typeof e.colorIndex == "number") return T(e.colorIndex, r, r);
|
|
1104
|
+
}
|
|
1105
|
+
function Le(e) {
|
|
1106
|
+
return Gt(e.colorIndex, e.colorNumber, e.aci) === 0 ? !0 : e.trueColor === void 0 && e.color === 0;
|
|
1107
|
+
}
|
|
1108
|
+
function jt(e, t, r, i = {}) {
|
|
1109
|
+
if (!Le(e)) return e;
|
|
1110
|
+
const s = D(t, r, i);
|
|
1111
|
+
return { ...e, color: s, trueColor: void 0, colorIndex: void 0, colorNumber: void 0 };
|
|
1112
|
+
}
|
|
1113
|
+
function Be(e) {
|
|
1114
|
+
return typeof e == "number" && Number.isFinite(e) && Math.abs(Math.trunc(e)) >= 1 && Math.abs(Math.trunc(e)) <= 255;
|
|
1115
|
+
}
|
|
1116
|
+
function Fe(e, t) {
|
|
1117
|
+
if (!(!e || !t))
|
|
1118
|
+
return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
1119
|
+
}
|
|
1120
|
+
function Gt(...e) {
|
|
1121
|
+
for (const t of e)
|
|
1122
|
+
if (typeof t == "number" && Number.isFinite(t)) return t;
|
|
1123
|
+
}
|
|
1124
|
+
function De(e, t) {
|
|
1125
|
+
const r = e;
|
|
1126
|
+
for (const i of t) {
|
|
1127
|
+
const s = r[i];
|
|
1128
|
+
if (typeof s == "number" && Number.isFinite(s)) return s;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
function st(e) {
|
|
1132
|
+
const t = e.trim().toLowerCase();
|
|
1133
|
+
if (/^#[0-9a-f]{3}$/i.test(t))
|
|
1134
|
+
return {
|
|
1135
|
+
r: parseInt(t[1] + t[1], 16),
|
|
1136
|
+
g: parseInt(t[2] + t[2], 16),
|
|
1137
|
+
b: parseInt(t[3] + t[3], 16),
|
|
1138
|
+
a: 1
|
|
1139
|
+
};
|
|
1140
|
+
if (/^#[0-9a-f]{6}$/i.test(t))
|
|
1141
|
+
return {
|
|
1142
|
+
r: parseInt(t.slice(1, 3), 16),
|
|
1143
|
+
g: parseInt(t.slice(3, 5), 16),
|
|
1144
|
+
b: parseInt(t.slice(5, 7), 16),
|
|
1145
|
+
a: 1
|
|
1146
|
+
};
|
|
1147
|
+
const r = t.match(/^rgba?\(([^)]+)\)$/i);
|
|
1148
|
+
if (r) {
|
|
1149
|
+
const i = r[1].split(/[,\s/]+/).filter(Boolean).map((s) => Number(s.replace("%", "")));
|
|
1150
|
+
if (i.length >= 3 && i.slice(0, 3).every(Number.isFinite)) {
|
|
1151
|
+
const s = /%/.test(r[1]);
|
|
1152
|
+
return {
|
|
1153
|
+
r: W(s ? i[0] * 2.55 : i[0]),
|
|
1154
|
+
g: W(s ? i[1] * 2.55 : i[1]),
|
|
1155
|
+
b: W(s ? i[2] * 2.55 : i[2]),
|
|
1156
|
+
a: Number.isFinite(i[3]) ? Math.max(0, Math.min(1, i[3])) : 1
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
function It(e, t) {
|
|
1162
|
+
const r = e.a + t.a * (1 - e.a);
|
|
1163
|
+
return r <= 0 ? { r: 0, g: 0, b: 0, a: 0 } : {
|
|
1164
|
+
r: (e.r * e.a + t.r * t.a * (1 - e.a)) / r,
|
|
1165
|
+
g: (e.g * e.a + t.g * t.a * (1 - e.a)) / r,
|
|
1166
|
+
b: (e.b * e.a + t.b * t.a * (1 - e.a)) / r,
|
|
1167
|
+
a: r
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function We(e, t, r) {
|
|
1171
|
+
const i = Math.max(0, Math.min(1, r));
|
|
1172
|
+
return {
|
|
1173
|
+
r: e.r + (t.r - e.r) * i,
|
|
1174
|
+
g: e.g + (t.g - e.g) * i,
|
|
1175
|
+
b: e.b + (t.b - e.b) * i,
|
|
1176
|
+
a: e.a
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
function dt(e) {
|
|
1180
|
+
const t = [e.r, e.g, e.b].map((r) => {
|
|
1181
|
+
const i = r / 255;
|
|
1182
|
+
return i <= 0.03928 ? i / 12.92 : ((i + 0.055) / 1.055) ** 2.4;
|
|
1183
|
+
});
|
|
1184
|
+
return 0.2126 * t[0] + 0.7152 * t[1] + 0.0722 * t[2];
|
|
1185
|
+
}
|
|
1186
|
+
function nt(e, t) {
|
|
1187
|
+
const r = dt(e), i = dt(t), s = Math.max(r, i), n = Math.min(r, i);
|
|
1188
|
+
return (s + 0.05) / (n + 0.05);
|
|
1189
|
+
}
|
|
1190
|
+
function Tt(e) {
|
|
1191
|
+
const t = W(e.r), r = W(e.g), i = W(e.b);
|
|
1192
|
+
return e.a < 0.999 ? `rgba(${t}, ${r}, ${i}, ${ut(e.a)})` : `rgb(${t}, ${r}, ${i})`;
|
|
1193
|
+
}
|
|
1194
|
+
function W(e) {
|
|
1195
|
+
return Math.max(0, Math.min(255, Math.round(e)));
|
|
1196
|
+
}
|
|
1197
|
+
function ut(e) {
|
|
1198
|
+
return Math.round(e * 1e3) / 1e3;
|
|
1199
|
+
}
|
|
1200
|
+
const At = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
|
|
1201
|
+
function j(e, t) {
|
|
1202
|
+
return {
|
|
1203
|
+
a: e.a * t.a + e.c * t.b,
|
|
1204
|
+
b: e.b * t.a + e.d * t.b,
|
|
1205
|
+
c: e.a * t.c + e.c * t.d,
|
|
1206
|
+
d: e.b * t.c + e.d * t.d,
|
|
1207
|
+
e: e.a * t.e + e.c * t.f + e.e,
|
|
1208
|
+
f: e.b * t.e + e.d * t.f + e.f
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
function Lt(e, t) {
|
|
1212
|
+
return { a: 1, b: 0, c: 0, d: 1, e, f: t };
|
|
1213
|
+
}
|
|
1214
|
+
function Oe(e) {
|
|
1215
|
+
const t = Math.cos(e), r = Math.sin(e);
|
|
1216
|
+
return { a: t, b: r, c: -r, d: t, e: 0, f: 0 };
|
|
1217
|
+
}
|
|
1218
|
+
function Re(e, t = e) {
|
|
1219
|
+
return { a: e, b: 0, c: 0, d: t, e: 0, f: 0 };
|
|
1220
|
+
}
|
|
1221
|
+
function w(e, t) {
|
|
1222
|
+
return {
|
|
1223
|
+
x: e.x * t.a + e.y * t.c + t.e,
|
|
1224
|
+
y: e.x * t.b + e.y * t.d + t.f,
|
|
1225
|
+
z: "z" in e ? e.z : void 0
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
function Bt(e, t) {
|
|
1229
|
+
if (e)
|
|
1230
|
+
return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) => w(i, t)) }));
|
|
1231
|
+
}
|
|
1232
|
+
function Q(e, t = { x: 0, y: 0 }) {
|
|
1233
|
+
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);
|
|
1234
|
+
let a = Lt(r.x, r.y);
|
|
1235
|
+
return a = j(a, Oe(Number.isFinite(o) ? o : 0)), a = j(a, Re(Number.isFinite(s) ? s : 1, Number.isFinite(n) ? n : 1)), a = j(a, Lt(-t.x, -t.y)), a;
|
|
1236
|
+
}
|
|
1237
|
+
function J(e, t) {
|
|
1238
|
+
const r = { ...e, raw: e.raw ?? e };
|
|
1239
|
+
if (e.startPoint && (r.startPoint = w(e.startPoint, t)), e.endPoint && (r.endPoint = w(e.endPoint, t)), e.center && (r.center = w(e.center, t)), e.insertionPoint && (r.insertionPoint = w(e.insertionPoint, t)), e.majorAxisEndPoint) {
|
|
1240
|
+
const s = w({ x: 0, y: 0 }, t), n = w(e.majorAxisEndPoint, t);
|
|
1241
|
+
r.majorAxisEndPoint = { x: n.x - s.x, y: n.y - s.y, z: n.z };
|
|
1242
|
+
}
|
|
1243
|
+
e.vertices && (r.vertices = e.vertices.map((s) => ({ ...w(s, t), bulge: s.bulge, startWidth: s.startWidth, endWidth: s.endWidth }))), e.points && (r.points = e.points.map((s) => w(s, t))), e.controlPoints && (r.controlPoints = e.controlPoints.map((s) => w(s, t))), e.fitPoints && (r.fitPoints = e.fitPoints.map((s) => w(s, t))), e.commands && (r.commands = Bt(e.commands, t)), e.loops && (r.loops = e.loops.map((s) => {
|
|
1244
|
+
var n;
|
|
1245
|
+
return {
|
|
1246
|
+
...s,
|
|
1247
|
+
vertices: (n = s.vertices) == null ? void 0 : n.map((o) => w(o, t)),
|
|
1248
|
+
commands: Bt(s.commands, t)
|
|
1249
|
+
};
|
|
1250
|
+
}));
|
|
1251
|
+
const i = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c));
|
|
1252
|
+
return typeof e.radius == "number" && Number.isFinite(i) && (r.radius = e.radius * i), r;
|
|
1253
|
+
}
|
|
1254
|
+
function tt(e) {
|
|
1255
|
+
var c;
|
|
1256
|
+
if (!e) return;
|
|
1257
|
+
const t = ((c = e.match(/-?\d*\.?\d+(?:[eE][+-]?\d+)?/g)) == null ? void 0 : c.map(Number)) ?? [];
|
|
1258
|
+
if (t.length < 6) return;
|
|
1259
|
+
const [r, i, s, n, o, a] = t;
|
|
1260
|
+
return { a: r, b: i, c: s, d: n, e: o, f: a };
|
|
1261
|
+
}
|
|
1262
|
+
class mt extends Error {
|
|
1263
|
+
constructor(r) {
|
|
1264
|
+
super(r);
|
|
1265
|
+
u(this, "format", "dwf");
|
|
1266
|
+
this.name = "DwfUnsupportedError";
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
class ze {
|
|
1270
|
+
constructor(t = {}) {
|
|
1271
|
+
u(this, "id", "dwf");
|
|
1272
|
+
u(this, "label", "DWFx/XPS 2D package loader");
|
|
1273
|
+
u(this, "formats", ["dwf", "dwfx", "xps"]);
|
|
1274
|
+
u(this, "defaults");
|
|
1275
|
+
this.defaults = t;
|
|
1276
|
+
}
|
|
1277
|
+
accepts(t, r) {
|
|
1278
|
+
const i = Y(t);
|
|
1279
|
+
if (i === "dwf" || i === "dwfx" || i === "xps") return !0;
|
|
1280
|
+
const s = rt(t, r);
|
|
1281
|
+
return s === "dwf" || s === "dwfx" || s === "xps";
|
|
1282
|
+
}
|
|
1283
|
+
async load(t, r = {}) {
|
|
1284
|
+
var d;
|
|
1285
|
+
({ ...this.defaults, ...r });
|
|
1286
|
+
const i = performance.now(), s = await et(t), n = t.fileName ?? ((d = t.file) == null ? void 0 : d.name), o = Y(t), a = Xe(s), c = Ye(a, n);
|
|
1287
|
+
if (c.length === 0) {
|
|
1288
|
+
const p = Object.keys(a), g = p.some((M) => /\.(w2d|w3d|whip)$/i.test(M)), S = p.some((M) => /manifest|descriptor|eplot/i.test(M));
|
|
1289
|
+
throw g || o === "dwf" || S ? new mt("Classic DWF packages usually store geometry in WHIP/W2D/W3D streams. This browser build detects them but does not decode the full classic DWF graphics stream without a DWF Toolkit/WASM implementation. DWFx/XPS 2D pages are supported.") : new mt("No FixedPage/XPS content found in this DWF/DWFx package.");
|
|
1290
|
+
}
|
|
1291
|
+
const l = [];
|
|
1292
|
+
o === "dwf" && l.push("This .dwf package contained XPS/FixedPage-compatible content and was rendered through the DWFx loader path. Classic WHIP/W2D streams are not decoded.");
|
|
1293
|
+
const h = Xt({
|
|
1294
|
+
format: o === "dwf" ? "dwf" : o === "xps" ? "xps" : "dwfx",
|
|
1295
|
+
sourceName: n,
|
|
1296
|
+
layers: {},
|
|
1297
|
+
blocks: {},
|
|
1298
|
+
pages: c,
|
|
1299
|
+
entities: me(c),
|
|
1300
|
+
metadata: {
|
|
1301
|
+
parser: "cad-viewer DWFx/XPS loader",
|
|
1302
|
+
packageEntries: Object.keys(a).length
|
|
1303
|
+
},
|
|
1304
|
+
warnings: l,
|
|
1305
|
+
raw: { entries: Object.keys(a) }
|
|
1306
|
+
}), f = performance.now() - i;
|
|
1307
|
+
return { document: h, raw: h.raw, bytes: s.byteLength, elapsedMs: f, format: h.format, warnings: h.warnings };
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
function Xe(e) {
|
|
1311
|
+
if (!(e[0] === 80 && e[1] === 75))
|
|
1312
|
+
throw new mt("DWF/DWFx loader expects a ZIP/OPC package. Non-ZIP classic DWF streams require a dedicated WHIP decoder.");
|
|
1313
|
+
return ee(e);
|
|
1314
|
+
}
|
|
1315
|
+
function Ye(e, t) {
|
|
1316
|
+
const r = Object.entries(e).filter(([s, n]) => /\.fpage$/i.test(s) || wt(n.slice(0, Math.min(512, n.byteLength))).includes("<FixedPage")).sort(([s], [n]) => s.localeCompare(n)), i = [];
|
|
1317
|
+
for (const [s, n] of r) {
|
|
1318
|
+
const o = wt(n);
|
|
1319
|
+
if (!o.includes("<FixedPage")) continue;
|
|
1320
|
+
const a = He(o, i.length, s, e, t);
|
|
1321
|
+
a && i.push(a);
|
|
1322
|
+
}
|
|
1323
|
+
return i;
|
|
1324
|
+
}
|
|
1325
|
+
function He(e, t, r, i, s) {
|
|
1326
|
+
if (typeof DOMParser > "u")
|
|
1327
|
+
throw new Error("DWFx/XPS parsing requires DOMParser. Use it in a browser environment or provide a DOMParser polyfill.");
|
|
1328
|
+
const o = new DOMParser().parseFromString(e, "application/xml").documentElement;
|
|
1329
|
+
if (!o || !/FixedPage$/i.test(o.nodeName)) return;
|
|
1330
|
+
const a = I(o, "Width") ?? 1e3, c = I(o, "Height") ?? 1e3, l = [];
|
|
1331
|
+
return Zt(o, At, (h, f) => {
|
|
1332
|
+
const d = j(f, Ge(h) ?? At), p = qt(h.nodeName);
|
|
1333
|
+
if (p === "Path") {
|
|
1334
|
+
const g = _e(h, d, c, t);
|
|
1335
|
+
g && l.push(g);
|
|
1336
|
+
} else if (p === "Glyphs") {
|
|
1337
|
+
const g = Ue(h, d, c, t);
|
|
1338
|
+
g && l.push(g);
|
|
1339
|
+
} else if (p !== "Canvas") {
|
|
1340
|
+
if (p === "ImageBrush") {
|
|
1341
|
+
const g = Ve(h, d, c, t, r, i);
|
|
1342
|
+
g && l.push(g);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
return d;
|
|
1346
|
+
}), { index: t, name: s ? `${s} / ${r}` : r, width: a, height: c, entities: l };
|
|
1347
|
+
}
|
|
1348
|
+
function Zt(e, t, r) {
|
|
1349
|
+
const i = r(e, t);
|
|
1350
|
+
for (const s of Array.from(e.children)) Zt(s, i, r);
|
|
1351
|
+
}
|
|
1352
|
+
function _e(e, t, r, i) {
|
|
1353
|
+
const s = e.getAttribute("Data") ?? je(e);
|
|
1354
|
+
if (!s) return;
|
|
1355
|
+
const n = $e(s).map((l) => ({
|
|
1356
|
+
cmd: l.cmd,
|
|
1357
|
+
points: l.points.map((h) => bt(w(h, t), r))
|
|
1358
|
+
}));
|
|
1359
|
+
if (!n.length) return;
|
|
1360
|
+
const o = K(e.getAttribute("Stroke") ?? void 0), a = K(e.getAttribute("Fill") ?? void 0), c = I(e, "Opacity");
|
|
1361
|
+
return {
|
|
1362
|
+
type: "XPS_PATH",
|
|
1363
|
+
kind: "path",
|
|
1364
|
+
commands: n,
|
|
1365
|
+
color: o ?? a ?? "#ffffff",
|
|
1366
|
+
fillColor: a,
|
|
1367
|
+
lineweight: I(e, "StrokeThickness") ?? 1,
|
|
1368
|
+
opacity: c,
|
|
1369
|
+
pageIndex: i,
|
|
1370
|
+
raw: e.outerHTML
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
function Ue(e, t, r, i) {
|
|
1374
|
+
const s = e.getAttribute("UnicodeString") ?? e.getAttribute("Indices") ?? "";
|
|
1375
|
+
if (!s) return;
|
|
1376
|
+
const n = { x: I(e, "OriginX") ?? 0, y: I(e, "OriginY") ?? 0 };
|
|
1377
|
+
return {
|
|
1378
|
+
type: "DWF_TEXT",
|
|
1379
|
+
kind: "text",
|
|
1380
|
+
insertionPoint: bt(w(n, t), r),
|
|
1381
|
+
text: s,
|
|
1382
|
+
textHeight: I(e, "FontRenderingEmSize") ?? 12,
|
|
1383
|
+
color: K(e.getAttribute("Fill") ?? void 0) ?? "#ffffff",
|
|
1384
|
+
opacity: I(e, "Opacity"),
|
|
1385
|
+
pageIndex: i,
|
|
1386
|
+
raw: e.outerHTML
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
function Ve(e, t, r, i, s, n) {
|
|
1390
|
+
var S, M;
|
|
1391
|
+
const o = e.getAttribute("ImageSource");
|
|
1392
|
+
if (!o) return;
|
|
1393
|
+
const a = ((M = (S = e.getAttribute("Viewport")) == null ? void 0 : S.match(/-?\d*\.?\d+(?:[eE][+-]?\d+)?/g)) == null ? void 0 : M.map(Number)) ?? [], c = a[0] ?? 0, l = a[1] ?? 0, h = a[2] ?? 32, f = a[3] ?? 32, d = bt(w({ x: c, y: l }, t), r), p = Ze(s, o), g = n[p.replace(/^\//, "")] ?? n[p];
|
|
1394
|
+
return {
|
|
1395
|
+
type: "DWF_IMAGE",
|
|
1396
|
+
kind: "image",
|
|
1397
|
+
insertionPoint: d,
|
|
1398
|
+
width: h,
|
|
1399
|
+
height: f,
|
|
1400
|
+
imageSource: o,
|
|
1401
|
+
imageDataUrl: g ? qe(g, p) : void 0,
|
|
1402
|
+
pageIndex: i,
|
|
1403
|
+
raw: e.outerHTML
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
function $e(e) {
|
|
1407
|
+
const t = e.match(/[AaCcHhLlMmQqSsVvZz]|-?\d*\.?\d+(?:[eE][+-]?\d+)?/g) ?? [], r = [];
|
|
1408
|
+
let i = 0, s = "", n = { x: 0, y: 0 }, o = { x: 0, y: 0 };
|
|
1409
|
+
const a = (l) => /^[A-Za-z]$/.test(l), c = () => Number(t[i++]);
|
|
1410
|
+
for (; i < t.length && (a(t[i]) && (s = t[i++]), !!s); ) {
|
|
1411
|
+
const l = s === s.toLowerCase(), h = s.toUpperCase();
|
|
1412
|
+
if (h === "Z") {
|
|
1413
|
+
r.push({ cmd: "Z", points: [] }), n = { ...o }, s = "";
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
if (h === "M") {
|
|
1417
|
+
const f = c(), d = c();
|
|
1418
|
+
if (!Number.isFinite(f) || !Number.isFinite(d)) break;
|
|
1419
|
+
n = E(f, d, l, n), o = { ...n }, r.push({ cmd: "M", points: [n] }), s = l ? "l" : "L";
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
if (h === "L") {
|
|
1423
|
+
const f = c(), d = c();
|
|
1424
|
+
if (!Number.isFinite(f) || !Number.isFinite(d)) break;
|
|
1425
|
+
n = E(f, d, l, n), r.push({ cmd: "L", points: [n] });
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
if (h === "H") {
|
|
1429
|
+
const f = c();
|
|
1430
|
+
if (!Number.isFinite(f)) break;
|
|
1431
|
+
n = { x: l ? n.x + f : f, y: n.y }, r.push({ cmd: "L", points: [n] });
|
|
1432
|
+
continue;
|
|
1433
|
+
}
|
|
1434
|
+
if (h === "V") {
|
|
1435
|
+
const f = c();
|
|
1436
|
+
if (!Number.isFinite(f)) break;
|
|
1437
|
+
n = { x: n.x, y: l ? n.y + f : f }, r.push({ cmd: "L", points: [n] });
|
|
1438
|
+
continue;
|
|
1439
|
+
}
|
|
1440
|
+
if (h === "C") {
|
|
1441
|
+
const f = E(c(), c(), l, n), d = E(c(), c(), l, n), p = E(c(), c(), l, n);
|
|
1442
|
+
if (![f.x, f.y, d.x, d.y, p.x, p.y].every(Number.isFinite)) break;
|
|
1443
|
+
n = p, r.push({ cmd: "C", points: [f, d, p] });
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1446
|
+
if (h === "Q" || h === "S") {
|
|
1447
|
+
const f = E(c(), c(), l, n), d = E(c(), c(), l, n);
|
|
1448
|
+
if (![f.x, f.y, d.x, d.y].every(Number.isFinite)) break;
|
|
1449
|
+
n = d, r.push({ cmd: "Q", points: [f, d] });
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
if (h === "A") {
|
|
1453
|
+
c(), c(), c(), c(), c();
|
|
1454
|
+
const f = E(c(), c(), l, n);
|
|
1455
|
+
if (![f.x, f.y].every(Number.isFinite)) break;
|
|
1456
|
+
n = f, r.push({ cmd: "L", points: [f] });
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
break;
|
|
1460
|
+
}
|
|
1461
|
+
return r;
|
|
1462
|
+
}
|
|
1463
|
+
function E(e, t, r, i) {
|
|
1464
|
+
return r ? { x: i.x + e, y: i.y + t } : { x: e, y: t };
|
|
1465
|
+
}
|
|
1466
|
+
function bt(e, t) {
|
|
1467
|
+
return { x: e.x, y: t - e.y };
|
|
1468
|
+
}
|
|
1469
|
+
function je(e) {
|
|
1470
|
+
for (const t of Array.from(e.children))
|
|
1471
|
+
if (/PathGeometry$/i.test(t.nodeName)) {
|
|
1472
|
+
const r = t.getAttribute("Figures");
|
|
1473
|
+
if (r) return r;
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
function Ge(e) {
|
|
1477
|
+
return tt(e.getAttribute("RenderTransform")) ?? tt(e.getAttribute("Transform")) ?? $(e, "RenderTransform") ?? $(e, "Canvas.RenderTransform") ?? $(e, "Path.RenderTransform") ?? $(e, "Glyphs.RenderTransform");
|
|
1478
|
+
}
|
|
1479
|
+
function $(e, t) {
|
|
1480
|
+
for (const r of Array.from(e.children)) {
|
|
1481
|
+
if (qt(r.nodeName) !== t && r.nodeName !== t) continue;
|
|
1482
|
+
const i = r.textContent ? tt(r.textContent) : void 0;
|
|
1483
|
+
if (i) return i;
|
|
1484
|
+
for (const s of Array.from(r.children)) {
|
|
1485
|
+
const n = tt(s.getAttribute("Matrix") ?? s.textContent ?? void 0);
|
|
1486
|
+
if (n) return n;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
function I(e, t) {
|
|
1491
|
+
const r = e.getAttribute(t), i = r === null ? NaN : Number(r);
|
|
1492
|
+
return Number.isFinite(i) ? i : void 0;
|
|
1493
|
+
}
|
|
1494
|
+
function qt(e) {
|
|
1495
|
+
return e.includes(":") ? e.split(":").pop() ?? e : e;
|
|
1496
|
+
}
|
|
1497
|
+
function Ze(e, t) {
|
|
1498
|
+
if (t.startsWith("/")) return t.slice(1);
|
|
1499
|
+
const i = `${e.includes("/") ? e.slice(0, e.lastIndexOf("/") + 1) : ""}${t}`.split("/"), s = [];
|
|
1500
|
+
for (const n of i)
|
|
1501
|
+
!n || n === "." || (n === ".." ? s.pop() : s.push(n));
|
|
1502
|
+
return s.join("/");
|
|
1503
|
+
}
|
|
1504
|
+
function qe(e, t) {
|
|
1505
|
+
const r = /\.jpe?g$/i.test(t) ? "image/jpeg" : /\.webp$/i.test(t) ? "image/webp" : "image/png";
|
|
1506
|
+
let i = "";
|
|
1507
|
+
for (const s of e) i += String.fromCharCode(s);
|
|
1508
|
+
return `data:${r};base64,${btoa(i)}`;
|
|
1509
|
+
}
|
|
1510
|
+
function Ke(e = {}) {
|
|
1511
|
+
return new ie([
|
|
1512
|
+
new le(e),
|
|
1513
|
+
new pe(e),
|
|
1514
|
+
new ze(e)
|
|
1515
|
+
]);
|
|
1516
|
+
}
|
|
1517
|
+
const Qe = {
|
|
1518
|
+
background: "#0b1020",
|
|
1519
|
+
foreground: "#ffffff",
|
|
1520
|
+
showUnsupportedMarkers: !1,
|
|
1521
|
+
showImagePlaceholders: !0,
|
|
1522
|
+
showPageBounds: !0,
|
|
1523
|
+
minScale: 1e-9,
|
|
1524
|
+
maxScale: 1e9,
|
|
1525
|
+
wheelZoomFactor: 1.14,
|
|
1526
|
+
trueColorByteOrder: "rgb",
|
|
1527
|
+
maxInsertDepth: 16,
|
|
1528
|
+
contrastMode: "adaptive",
|
|
1529
|
+
minColorContrast: 2.4,
|
|
1530
|
+
maxCurveSegments: 96,
|
|
1531
|
+
spatialIndexCellCount: 72,
|
|
1532
|
+
maxVerticesPerBatch: 65536,
|
|
1533
|
+
textMinPixelHeight: 4,
|
|
1534
|
+
maxVisibleTextLabels: 2500,
|
|
1535
|
+
powerPreference: "high-performance",
|
|
1536
|
+
antialias: !0,
|
|
1537
|
+
preserveDrawingBuffer: !1,
|
|
1538
|
+
enableSpatialIndex: !0
|
|
1539
|
+
};
|
|
1540
|
+
class Ft {
|
|
1541
|
+
constructor(t, r = {}) {
|
|
1542
|
+
u(this, "canvas");
|
|
1543
|
+
u(this, "ctx");
|
|
1544
|
+
u(this, "opts");
|
|
1545
|
+
u(this, "document");
|
|
1546
|
+
u(this, "bounds", N());
|
|
1547
|
+
u(this, "view", { centerX: 0, centerY: 0, scale: 1 });
|
|
1548
|
+
u(this, "fitScale", 1);
|
|
1549
|
+
u(this, "dpr", 1);
|
|
1550
|
+
u(this, "isDragging", !1);
|
|
1551
|
+
u(this, "lastPointer");
|
|
1552
|
+
u(this, "resizeObserver");
|
|
1553
|
+
u(this, "imageCache", /* @__PURE__ */ new Map());
|
|
1554
|
+
u(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "canvas2d" });
|
|
1555
|
+
u(this, "onStats");
|
|
1556
|
+
u(this, "onViewChange");
|
|
1557
|
+
const i = t.getContext("2d");
|
|
1558
|
+
if (!i) throw new Error("Canvas 2D context is not available.");
|
|
1559
|
+
this.canvas = t, this.ctx = i, this.opts = { ...Qe, ...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();
|
|
1560
|
+
}
|
|
1561
|
+
destroy() {
|
|
1562
|
+
var t;
|
|
1563
|
+
(t = this.resizeObserver) == null || t.disconnect();
|
|
1564
|
+
}
|
|
1565
|
+
clear() {
|
|
1566
|
+
this.document = void 0, this.bounds = N(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
|
|
1567
|
+
}
|
|
1568
|
+
setDocument(t) {
|
|
1569
|
+
this.document = t, this.bounds = this.computeBounds(t), this.fitToView();
|
|
1570
|
+
}
|
|
1571
|
+
getDocument() {
|
|
1572
|
+
return this.document;
|
|
1573
|
+
}
|
|
1574
|
+
setOptions(t) {
|
|
1575
|
+
Object.assign(this.opts, t), this.render(), this.emitViewChange();
|
|
1576
|
+
}
|
|
1577
|
+
getOptions() {
|
|
1578
|
+
return { ...this.opts };
|
|
1579
|
+
}
|
|
1580
|
+
fitToView(t = 0.92) {
|
|
1581
|
+
if (!R(this.bounds)) {
|
|
1582
|
+
this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
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);
|
|
1586
|
+
this.fitScale = o, this.view = {
|
|
1587
|
+
centerX: (this.bounds.minX + this.bounds.maxX) / 2,
|
|
1588
|
+
centerY: (this.bounds.minY + this.bounds.maxY) / 2,
|
|
1589
|
+
scale: o
|
|
1590
|
+
}, this.render(), this.emitViewChange();
|
|
1591
|
+
}
|
|
1592
|
+
resize() {
|
|
1593
|
+
this.dpr = Math.max(1, window.devicePixelRatio || 1);
|
|
1594
|
+
const t = Math.max(1, Math.floor(this.cssWidth * this.dpr)), r = Math.max(1, Math.floor(this.cssHeight * this.dpr));
|
|
1595
|
+
(this.canvas.width !== t || this.canvas.height !== r) && (this.canvas.width = t, this.canvas.height = r), this.render(), this.emitViewChange();
|
|
1596
|
+
}
|
|
1597
|
+
zoom(t, r) {
|
|
1598
|
+
if (!Number.isFinite(t) || t <= 0) return;
|
|
1599
|
+
const i = r ?? { x: this.cssWidth / 2, y: this.cssHeight / 2 }, s = this.screenToWorld(i);
|
|
1600
|
+
this.view.scale = this.clampScale(this.view.scale * t);
|
|
1601
|
+
const n = this.screenToWorld(i);
|
|
1602
|
+
this.view.centerX += s.x - n.x, this.view.centerY += s.y - n.y, this.render(), this.emitViewChange();
|
|
1603
|
+
}
|
|
1604
|
+
zoomIn() {
|
|
1605
|
+
this.zoom(this.opts.wheelZoomFactor);
|
|
1606
|
+
}
|
|
1607
|
+
zoomOut() {
|
|
1608
|
+
this.zoom(1 / this.opts.wheelZoomFactor);
|
|
1609
|
+
}
|
|
1610
|
+
panByScreenDelta(t, r) {
|
|
1611
|
+
!Number.isFinite(t) || !Number.isFinite(r) || (this.view.centerX -= t / this.view.scale, this.view.centerY += r / this.view.scale, this.render(), this.emitViewChange());
|
|
1612
|
+
}
|
|
1613
|
+
setViewState(t) {
|
|
1614
|
+
if (![t.centerX, t.centerY, t.scale].every(Number.isFinite)) throw new Error("Invalid view state.");
|
|
1615
|
+
this.view = { ...t, scale: this.clampScale(t.scale) }, this.render(), this.emitViewChange();
|
|
1616
|
+
}
|
|
1617
|
+
getViewState() {
|
|
1618
|
+
return { ...this.view };
|
|
1619
|
+
}
|
|
1620
|
+
getBounds() {
|
|
1621
|
+
return { ...this.bounds };
|
|
1622
|
+
}
|
|
1623
|
+
getStats() {
|
|
1624
|
+
return Je(this.stats);
|
|
1625
|
+
}
|
|
1626
|
+
getZoomRatio() {
|
|
1627
|
+
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
1628
|
+
}
|
|
1629
|
+
getZoomPercent() {
|
|
1630
|
+
return this.getZoomRatio() * 100;
|
|
1631
|
+
}
|
|
1632
|
+
worldToScreen(t) {
|
|
1633
|
+
return {
|
|
1634
|
+
x: this.cssWidth / 2 + (t.x - this.view.centerX) * this.view.scale,
|
|
1635
|
+
y: this.cssHeight / 2 - (t.y - this.view.centerY) * this.view.scale
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
screenToWorld(t) {
|
|
1639
|
+
return {
|
|
1640
|
+
x: this.view.centerX + (t.x - this.cssWidth / 2) / this.view.scale,
|
|
1641
|
+
y: this.view.centerY - (t.y - this.cssHeight / 2) / this.view.scale
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
render() {
|
|
1645
|
+
var r, i;
|
|
1646
|
+
const t = performance.now();
|
|
1647
|
+
if (this.stats = { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "canvas2d" }, this.clearCanvas(), this.document) {
|
|
1648
|
+
this.opts.showPageBounds && ((r = this.document.pages) != null && r.length) && this.drawPageBounds(this.document);
|
|
1649
|
+
for (const s of this.document.entities) this.drawEntityTracked(s, 0);
|
|
1650
|
+
}
|
|
1651
|
+
return this.stats.renderElapsedMs = performance.now() - t, (i = this.onStats) == null || i.call(this, this.getStats()), this.getStats();
|
|
1652
|
+
}
|
|
1653
|
+
get cssWidth() {
|
|
1654
|
+
return this.canvas.clientWidth || 1;
|
|
1655
|
+
}
|
|
1656
|
+
get cssHeight() {
|
|
1657
|
+
return this.canvas.clientHeight || 1;
|
|
1658
|
+
}
|
|
1659
|
+
bindEvents() {
|
|
1660
|
+
this.canvas.addEventListener("wheel", (r) => {
|
|
1661
|
+
r.preventDefault();
|
|
1662
|
+
const i = r.deltaY < 0 ? this.opts.wheelZoomFactor : 1 / this.opts.wheelZoomFactor;
|
|
1663
|
+
this.zoom(i, { x: r.offsetX, y: r.offsetY });
|
|
1664
|
+
}, { passive: !1 }), this.canvas.addEventListener("pointerdown", (r) => {
|
|
1665
|
+
this.canvas.setPointerCapture(r.pointerId), this.isDragging = !0, this.lastPointer = { x: r.clientX, y: r.clientY }, this.canvas.classList.add("is-dragging");
|
|
1666
|
+
}), this.canvas.addEventListener("pointermove", (r) => {
|
|
1667
|
+
!this.isDragging || !this.lastPointer || (this.panByScreenDelta(r.clientX - this.lastPointer.x, r.clientY - this.lastPointer.y), this.lastPointer = { x: r.clientX, y: r.clientY });
|
|
1668
|
+
});
|
|
1669
|
+
const t = (r) => {
|
|
1670
|
+
r && this.canvas.hasPointerCapture(r.pointerId) && this.canvas.releasePointerCapture(r.pointerId), this.isDragging = !1, this.lastPointer = void 0, this.canvas.classList.remove("is-dragging");
|
|
1671
|
+
};
|
|
1672
|
+
this.canvas.addEventListener("pointerup", t), this.canvas.addEventListener("pointercancel", () => t());
|
|
1673
|
+
}
|
|
1674
|
+
clearCanvas() {
|
|
1675
|
+
const t = this.ctx;
|
|
1676
|
+
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();
|
|
1677
|
+
}
|
|
1678
|
+
drawPageBounds(t) {
|
|
1679
|
+
const r = this.ctx;
|
|
1680
|
+
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]);
|
|
1681
|
+
for (const i of t.pages ?? []) {
|
|
1682
|
+
const s = this.worldToScreen({ x: 0, y: 0 }), n = this.worldToScreen({ x: i.width, y: i.height });
|
|
1683
|
+
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));
|
|
1684
|
+
}
|
|
1685
|
+
r.restore();
|
|
1686
|
+
}
|
|
1687
|
+
drawEntityTracked(t, r) {
|
|
1688
|
+
this.stats.total++;
|
|
1689
|
+
const i = String(t.type ?? "UNKNOWN").toUpperCase();
|
|
1690
|
+
this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
|
|
1691
|
+
const s = this.lookupLayer(t.layer);
|
|
1692
|
+
if (t.isVisible === !1 || !$t(s)) {
|
|
1693
|
+
this.stats.skipped++;
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
this.drawEntity(t, i, r);
|
|
1697
|
+
}
|
|
1698
|
+
drawEntity(t, r, i) {
|
|
1699
|
+
switch (t.kind ?? O(r)) {
|
|
1700
|
+
case "line":
|
|
1701
|
+
return this.drawLine(t);
|
|
1702
|
+
case "circle":
|
|
1703
|
+
return this.drawCircle(t);
|
|
1704
|
+
case "arc":
|
|
1705
|
+
return this.drawArc(t);
|
|
1706
|
+
case "polyline":
|
|
1707
|
+
return this.drawPolyline(t);
|
|
1708
|
+
case "ellipse":
|
|
1709
|
+
return this.drawEllipse(t);
|
|
1710
|
+
case "text":
|
|
1711
|
+
return this.drawText(t);
|
|
1712
|
+
case "point":
|
|
1713
|
+
return this.drawPoint(t);
|
|
1714
|
+
case "insert":
|
|
1715
|
+
return this.drawInsert(t, i);
|
|
1716
|
+
case "solid":
|
|
1717
|
+
return this.drawSolid(t);
|
|
1718
|
+
case "hatch":
|
|
1719
|
+
return this.drawHatch(t);
|
|
1720
|
+
case "spline":
|
|
1721
|
+
return this.drawSpline(t);
|
|
1722
|
+
case "path":
|
|
1723
|
+
return this.drawPath(t);
|
|
1724
|
+
case "image":
|
|
1725
|
+
return this.drawImage(t);
|
|
1726
|
+
case "viewport":
|
|
1727
|
+
return this.markSkipped(r);
|
|
1728
|
+
default:
|
|
1729
|
+
this.stats.unsupported[r] = (this.stats.unsupported[r] ?? 0) + 1, this.stats.skipped++, this.opts.showUnsupportedMarkers && this.drawUnsupportedMarker(t);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
beginStyledPath(t, r = !1) {
|
|
1733
|
+
const i = this.ctx;
|
|
1734
|
+
i.save(), i.setTransform(this.dpr, 0, 0, this.dpr, 0, 0);
|
|
1735
|
+
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 = ft(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }) ?? s;
|
|
1736
|
+
i.strokeStyle = s, i.fillStyle = r ? n : s, i.globalAlpha = B(Number(t.opacity ?? 1), 0, 1), i.lineCap = "round", i.lineJoin = "round";
|
|
1737
|
+
const o = typeof t.lineweight == "number" && t.lineweight > 0 ? t.lineweight : 0;
|
|
1738
|
+
i.lineWidth = Math.max(1, Math.min(12, o > 0 ? o / 30 : 1)), i.beginPath();
|
|
1739
|
+
}
|
|
1740
|
+
finishStroke() {
|
|
1741
|
+
this.ctx.stroke(), this.ctx.restore(), this.stats.drawn++;
|
|
1742
|
+
}
|
|
1743
|
+
finishFillStroke(t = !1) {
|
|
1744
|
+
t && this.ctx.fill(), this.ctx.stroke(), this.ctx.restore(), this.stats.drawn++;
|
|
1745
|
+
}
|
|
1746
|
+
drawLine(t) {
|
|
1747
|
+
const r = t.startPoint, i = t.endPoint;
|
|
1748
|
+
if (!m(r) || !m(i)) return this.markSkipped("LINE");
|
|
1749
|
+
const s = this.worldToScreen(r), n = this.worldToScreen(i);
|
|
1750
|
+
this.beginStyledPath(t), this.ctx.moveTo(s.x, s.y), this.ctx.lineTo(n.x, n.y), this.finishStroke();
|
|
1751
|
+
}
|
|
1752
|
+
drawCircle(t) {
|
|
1753
|
+
const r = t.center, i = Number(t.radius);
|
|
1754
|
+
if (!m(r) || !Number.isFinite(i)) return this.markSkipped("CIRCLE");
|
|
1755
|
+
const s = this.worldToScreen(r);
|
|
1756
|
+
this.beginStyledPath(t), this.ctx.arc(s.x, s.y, Math.abs(i) * this.view.scale, 0, Math.PI * 2), this.finishStroke();
|
|
1757
|
+
}
|
|
1758
|
+
drawArc(t) {
|
|
1759
|
+
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
1760
|
+
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
1761
|
+
this.strokeWorldPolyline(t, G(v(r), i, s, n, !0), !1);
|
|
1762
|
+
}
|
|
1763
|
+
drawPolyline(t) {
|
|
1764
|
+
const r = t.vertices ?? t.points;
|
|
1765
|
+
if (!Array.isArray(r) || r.length < 2) return this.markSkipped(String(t.type));
|
|
1766
|
+
const i = !!t.isClosed || (Number(t.flag) & 1) === 1, s = [], n = i ? r.length : r.length - 1;
|
|
1767
|
+
for (let o = 0; o < n; o++) {
|
|
1768
|
+
const a = r[o], c = r[(o + 1) % r.length];
|
|
1769
|
+
if (!m(a) || !m(c)) continue;
|
|
1770
|
+
const l = _t(a, c, Number(a.bulge ?? 0));
|
|
1771
|
+
s.length > 0 && l.shift(), s.push(...l);
|
|
1772
|
+
}
|
|
1773
|
+
this.strokeWorldPolyline(t, s, i);
|
|
1774
|
+
}
|
|
1775
|
+
drawEllipse(t) {
|
|
1776
|
+
const r = t.center, i = t.majorAxisEndPoint, s = Number(t.axisRatio ?? 1);
|
|
1777
|
+
if (!m(r) || !m(i)) return this.markSkipped("ELLIPSE");
|
|
1778
|
+
const n = Z(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;
|
|
1779
|
+
this.strokeWorldPolyline(t, n, o);
|
|
1780
|
+
}
|
|
1781
|
+
drawPoint(t) {
|
|
1782
|
+
const r = t.point ?? t.location ?? t.center ?? t.insertionPoint;
|
|
1783
|
+
if (!m(r)) return this.markSkipped("POINT");
|
|
1784
|
+
const i = this.worldToScreen(r);
|
|
1785
|
+
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();
|
|
1786
|
+
}
|
|
1787
|
+
drawText(t) {
|
|
1788
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = Ut(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
1789
|
+
if (!m(r) || !i) return this.markSkipped(String(t.type));
|
|
1790
|
+
this.drawTextAt(t, r, i, s, Number(t.rotation ?? 0));
|
|
1791
|
+
}
|
|
1792
|
+
drawInsert(t, r) {
|
|
1793
|
+
const i = this.lookupBlock(t.blockName ?? t.name);
|
|
1794
|
+
if (i && r < this.opts.maxInsertDepth) {
|
|
1795
|
+
const a = Q(t, i.basePoint ?? { x: 0, y: 0 });
|
|
1796
|
+
for (const c of i.entities) {
|
|
1797
|
+
const l = 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 });
|
|
1798
|
+
this.drawEntityTracked(J(l, a), r + 1);
|
|
1799
|
+
}
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
const s = t.insertionPoint;
|
|
1803
|
+
if (!m(s)) return this.markSkipped("INSERT");
|
|
1804
|
+
const n = this.worldToScreen(s);
|
|
1805
|
+
this.beginStyledPath(t);
|
|
1806
|
+
const o = 5;
|
|
1807
|
+
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);
|
|
1808
|
+
}
|
|
1809
|
+
drawSolid(t) {
|
|
1810
|
+
const r = t.vertices ?? t.points;
|
|
1811
|
+
if (!Array.isArray(r) || r.length < 3) return this.markSkipped(String(t.type));
|
|
1812
|
+
this.beginStyledPath(t, !0);
|
|
1813
|
+
const i = this.worldToScreen(r[0]);
|
|
1814
|
+
this.ctx.moveTo(i.x, i.y);
|
|
1815
|
+
for (const s of r.slice(1)) {
|
|
1816
|
+
if (!m(s)) continue;
|
|
1817
|
+
const n = this.worldToScreen(s);
|
|
1818
|
+
this.ctx.lineTo(n.x, n.y);
|
|
1819
|
+
}
|
|
1820
|
+
this.ctx.closePath(), this.finishFillStroke(!0);
|
|
1821
|
+
}
|
|
1822
|
+
drawHatch(t) {
|
|
1823
|
+
var i, s;
|
|
1824
|
+
const r = t.loops;
|
|
1825
|
+
if (!Array.isArray(r) || r.length === 0) return this.markSkipped("HATCH");
|
|
1826
|
+
this.beginStyledPath(t, !0);
|
|
1827
|
+
for (const n of r)
|
|
1828
|
+
if ((i = n.commands) != null && i.length) this.addPathCommands(n.commands);
|
|
1829
|
+
else if ((s = n.vertices) != null && s.length) {
|
|
1830
|
+
const o = this.worldToScreen(n.vertices[0]);
|
|
1831
|
+
this.ctx.moveTo(o.x, o.y);
|
|
1832
|
+
for (const a of n.vertices.slice(1)) {
|
|
1833
|
+
const c = this.worldToScreen(a);
|
|
1834
|
+
this.ctx.lineTo(c.x, c.y);
|
|
1835
|
+
}
|
|
1836
|
+
this.ctx.closePath();
|
|
1837
|
+
}
|
|
1838
|
+
this.finishFillStroke(!!ft(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }));
|
|
1839
|
+
}
|
|
1840
|
+
drawSpline(t) {
|
|
1841
|
+
var i;
|
|
1842
|
+
const r = (i = t.fitPoints) != null && i.length ? t.fitPoints : t.controlPoints;
|
|
1843
|
+
if (!r || r.length < 2) return this.markSkipped("SPLINE");
|
|
1844
|
+
this.strokeWorldPolyline(t, r, !!t.isClosed);
|
|
1845
|
+
}
|
|
1846
|
+
drawPath(t) {
|
|
1847
|
+
var r;
|
|
1848
|
+
if (!((r = t.commands) != null && r.length)) return this.markSkipped(String(t.type));
|
|
1849
|
+
this.beginStyledPath(t, !!t.fillColor), this.addPathCommands(t.commands), this.finishFillStroke(!!t.fillColor);
|
|
1850
|
+
}
|
|
1851
|
+
addPathCommands(t) {
|
|
1852
|
+
for (const r of t)
|
|
1853
|
+
if (r.cmd === "M") {
|
|
1854
|
+
const i = this.worldToScreen(r.points[0]);
|
|
1855
|
+
this.ctx.moveTo(i.x, i.y);
|
|
1856
|
+
} else if (r.cmd === "L") {
|
|
1857
|
+
const i = this.worldToScreen(r.points[0]);
|
|
1858
|
+
this.ctx.lineTo(i.x, i.y);
|
|
1859
|
+
} else if (r.cmd === "C") {
|
|
1860
|
+
const [i, s, n] = r.points.map((o) => this.worldToScreen(o));
|
|
1861
|
+
this.ctx.bezierCurveTo(i.x, i.y, s.x, s.y, n.x, n.y);
|
|
1862
|
+
} else if (r.cmd === "Q") {
|
|
1863
|
+
const [i, s] = r.points.map((n) => this.worldToScreen(n));
|
|
1864
|
+
this.ctx.quadraticCurveTo(i.x, i.y, s.x, s.y);
|
|
1865
|
+
} else r.cmd === "Z" && this.ctx.closePath();
|
|
1866
|
+
}
|
|
1867
|
+
drawImage(t) {
|
|
1868
|
+
const r = t.insertionPoint;
|
|
1869
|
+
if (!m(r)) return this.markSkipped(String(t.type));
|
|
1870
|
+
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), l = Math.abs(o.x - n.x), h = Math.abs(o.y - n.y), f = t.imageDataUrl;
|
|
1871
|
+
if (f) {
|
|
1872
|
+
const d = this.getImage(f);
|
|
1873
|
+
if (d.complete && d.naturalWidth > 0) {
|
|
1874
|
+
this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(d, a, c, l, h), this.ctx.restore(), this.stats.drawn++;
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
d.onload = () => this.render();
|
|
1878
|
+
}
|
|
1879
|
+
if (!this.opts.showImagePlaceholders) return this.markSkipped(String(t.type));
|
|
1880
|
+
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();
|
|
1881
|
+
}
|
|
1882
|
+
getImage(t) {
|
|
1883
|
+
let r = this.imageCache.get(t);
|
|
1884
|
+
return r || (r = new Image(), r.src = t, this.imageCache.set(t, r)), r;
|
|
1885
|
+
}
|
|
1886
|
+
drawUnsupportedMarker(t) {
|
|
1887
|
+
const r = this.entityAnchor(t);
|
|
1888
|
+
if (!r) return;
|
|
1889
|
+
const i = this.worldToScreen(r);
|
|
1890
|
+
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();
|
|
1891
|
+
}
|
|
1892
|
+
drawTextAt(t, r, i, s, n) {
|
|
1893
|
+
const o = this.ctx, a = this.worldToScreen(r);
|
|
1894
|
+
o.save(), o.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), o.translate(a.x, a.y), o.rotate(-n);
|
|
1895
|
+
const c = Math.max(4, Math.min(256, Math.abs(s) * this.view.scale));
|
|
1896
|
+
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 = B(Number(t.opacity ?? 1), 0, 1), o.textBaseline = "alphabetic";
|
|
1897
|
+
for (const [l, h] of i.split(/\r?\n/g).entries()) o.fillText(h, 0, l * c * 1.22);
|
|
1898
|
+
o.restore(), this.stats.drawn++;
|
|
1899
|
+
}
|
|
1900
|
+
strokeWorldPolyline(t, r, i) {
|
|
1901
|
+
const s = r.filter(m);
|
|
1902
|
+
if (s.length < 2) return this.markSkipped(String(t.type));
|
|
1903
|
+
this.beginStyledPath(t);
|
|
1904
|
+
const n = this.worldToScreen(s[0]);
|
|
1905
|
+
this.ctx.moveTo(n.x, n.y);
|
|
1906
|
+
for (const o of s.slice(1)) {
|
|
1907
|
+
const a = this.worldToScreen(o);
|
|
1908
|
+
this.ctx.lineTo(a.x, a.y);
|
|
1909
|
+
}
|
|
1910
|
+
i && this.ctx.closePath(), this.finishStroke();
|
|
1911
|
+
}
|
|
1912
|
+
markSkipped(t) {
|
|
1913
|
+
this.stats.skipped++, this.stats.unsupported[t] = this.stats.unsupported[t] ?? 0;
|
|
1914
|
+
}
|
|
1915
|
+
entityAnchor(t) {
|
|
1916
|
+
for (const r of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
1917
|
+
const i = t[r];
|
|
1918
|
+
if (m(i)) return v(i);
|
|
1919
|
+
}
|
|
1920
|
+
if (Array.isArray(t.vertices) && m(t.vertices[0])) return v(t.vertices[0]);
|
|
1921
|
+
if (Array.isArray(t.commands) && t.commands.length) {
|
|
1922
|
+
const r = t.commands.find((i) => i.points.length > 0);
|
|
1923
|
+
if (r) return v(r.points[0]);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
computeBounds(t) {
|
|
1927
|
+
var i;
|
|
1928
|
+
const r = N();
|
|
1929
|
+
if ((i = t.pages) != null && i.length)
|
|
1930
|
+
for (const s of t.pages)
|
|
1931
|
+
y(r, { x: 0, y: 0 }), y(r, { x: s.width, y: s.height });
|
|
1932
|
+
for (const s of t.entities) this.includeEntityBounds(r, s, 0);
|
|
1933
|
+
return Ht(r);
|
|
1934
|
+
}
|
|
1935
|
+
includeEntityBounds(t, r, i) {
|
|
1936
|
+
const s = String(r.type ?? "").toUpperCase(), n = r.kind ?? O(s);
|
|
1937
|
+
if (n === "insert") {
|
|
1938
|
+
const o = this.lookupBlock(r.blockName ?? r.name);
|
|
1939
|
+
if (o && i < this.opts.maxInsertDepth) {
|
|
1940
|
+
const a = Q(r, o.basePoint ?? { x: 0, y: 0 });
|
|
1941
|
+
for (const c of o.entities) this.includeEntityBounds(t, J(c, a), i + 1);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
if (n === "line")
|
|
1946
|
+
m(r.startPoint) && y(t, r.startPoint), m(r.endPoint) && y(t, r.endPoint);
|
|
1947
|
+
else if (n === "circle" || n === "arc")
|
|
1948
|
+
m(r.center) && Number.isFinite(r.radius) && Yt(t, r.center, Number(r.radius));
|
|
1949
|
+
else if (n === "polyline" || n === "solid" || n === "spline")
|
|
1950
|
+
for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) && y(t, o);
|
|
1951
|
+
else if (n === "ellipse")
|
|
1952
|
+
m(r.center) && m(r.majorAxisEndPoint) && Z(r.center, r.majorAxisEndPoint, Number(r.axisRatio ?? 1), Number(r.startAngle ?? 0), Number(r.endAngle ?? Math.PI * 2)).forEach((o) => y(t, o));
|
|
1953
|
+
else if (n === "path")
|
|
1954
|
+
for (const o of r.commands ?? []) for (const a of o.points) y(t, a);
|
|
1955
|
+
else if (n === "hatch")
|
|
1956
|
+
for (const o of r.loops ?? []) {
|
|
1957
|
+
for (const a of o.vertices ?? []) y(t, a);
|
|
1958
|
+
for (const a of o.commands ?? []) for (const c of a.points) y(t, c);
|
|
1959
|
+
}
|
|
1960
|
+
else {
|
|
1961
|
+
const o = this.entityAnchor(r);
|
|
1962
|
+
o && y(t, o);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
lookupLayer(t) {
|
|
1966
|
+
if (!(!this.document || !t))
|
|
1967
|
+
return this.document.layers[t] ?? this.document.layers[t.toLowerCase()] ?? Object.values(this.document.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
1968
|
+
}
|
|
1969
|
+
lookupBlock(t) {
|
|
1970
|
+
if (!(!this.document || !t))
|
|
1971
|
+
return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
1972
|
+
}
|
|
1973
|
+
clampScale(t) {
|
|
1974
|
+
return Math.min(this.opts.maxScale, Math.max(this.opts.minScale, t));
|
|
1975
|
+
}
|
|
1976
|
+
emitViewChange() {
|
|
1977
|
+
var t;
|
|
1978
|
+
(t = this.onViewChange) == null || t.call(this, {
|
|
1979
|
+
view: this.getViewState(),
|
|
1980
|
+
fitScale: this.fitScale,
|
|
1981
|
+
zoomRatio: this.getZoomRatio(),
|
|
1982
|
+
zoomPercent: this.getZoomPercent(),
|
|
1983
|
+
bounds: this.getBounds()
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
function Je(e) {
|
|
1988
|
+
return {
|
|
1989
|
+
total: e.total,
|
|
1990
|
+
drawn: e.drawn,
|
|
1991
|
+
skipped: e.skipped,
|
|
1992
|
+
byType: { ...e.byType },
|
|
1993
|
+
unsupported: { ...e.unsupported },
|
|
1994
|
+
renderElapsedMs: e.renderElapsedMs,
|
|
1995
|
+
backend: e.backend,
|
|
1996
|
+
primitiveCount: e.primitiveCount,
|
|
1997
|
+
visiblePrimitiveCount: e.visiblePrimitiveCount,
|
|
1998
|
+
culledPrimitiveCount: e.culledPrimitiveCount,
|
|
1999
|
+
gpuMemoryBytes: e.gpuMemoryBytes,
|
|
2000
|
+
buildElapsedMs: e.buildElapsedMs
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
const tr = {
|
|
2004
|
+
background: "#0b1020",
|
|
2005
|
+
foreground: "#ffffff",
|
|
2006
|
+
showUnsupportedMarkers: !1,
|
|
2007
|
+
showImagePlaceholders: !0,
|
|
2008
|
+
showPageBounds: !0,
|
|
2009
|
+
minScale: 1e-9,
|
|
2010
|
+
maxScale: 1e9,
|
|
2011
|
+
wheelZoomFactor: 1.14,
|
|
2012
|
+
trueColorByteOrder: "rgb",
|
|
2013
|
+
maxInsertDepth: 16,
|
|
2014
|
+
contrastMode: "adaptive",
|
|
2015
|
+
minColorContrast: 2.4,
|
|
2016
|
+
maxCurveSegments: 96,
|
|
2017
|
+
spatialIndexCellCount: 72,
|
|
2018
|
+
maxVerticesPerBatch: 65536,
|
|
2019
|
+
textMinPixelHeight: 4,
|
|
2020
|
+
maxVisibleTextLabels: 2500,
|
|
2021
|
+
powerPreference: "high-performance",
|
|
2022
|
+
antialias: !0,
|
|
2023
|
+
preserveDrawingBuffer: !1,
|
|
2024
|
+
enableSpatialIndex: !0
|
|
2025
|
+
};
|
|
2026
|
+
class Dt {
|
|
2027
|
+
constructor(t, r = {}) {
|
|
2028
|
+
u(this, "canvas");
|
|
2029
|
+
u(this, "backend", "webgl");
|
|
2030
|
+
u(this, "gl");
|
|
2031
|
+
u(this, "program");
|
|
2032
|
+
u(this, "eventController", new AbortController());
|
|
2033
|
+
u(this, "imageCache", /* @__PURE__ */ new Map());
|
|
2034
|
+
u(this, "opts");
|
|
2035
|
+
u(this, "document");
|
|
2036
|
+
u(this, "bounds", N());
|
|
2037
|
+
u(this, "view", { centerX: 0, centerY: 0, scale: 1 });
|
|
2038
|
+
u(this, "fitScale", 1);
|
|
2039
|
+
u(this, "dpr", 1);
|
|
2040
|
+
u(this, "isDragging", !1);
|
|
2041
|
+
u(this, "lastPointer");
|
|
2042
|
+
u(this, "resizeObserver");
|
|
2043
|
+
u(this, "overlayCanvas");
|
|
2044
|
+
u(this, "overlayCtx");
|
|
2045
|
+
u(this, "scene");
|
|
2046
|
+
u(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 });
|
|
2047
|
+
u(this, "rafHandle", 0);
|
|
2048
|
+
u(this, "onStats");
|
|
2049
|
+
u(this, "onViewChange");
|
|
2050
|
+
const i = er(t, r);
|
|
2051
|
+
if (!i) throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');
|
|
2052
|
+
this.canvas = t, this.gl = i, this.program = rr(i), this.opts = { ...tr, ...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();
|
|
2053
|
+
}
|
|
2054
|
+
static isSupported() {
|
|
2055
|
+
return Kt();
|
|
2056
|
+
}
|
|
2057
|
+
destroy() {
|
|
2058
|
+
var t, r;
|
|
2059
|
+
this.eventController.abort(), (t = this.resizeObserver) == null || t.disconnect(), this.cancelScheduledRender(), this.disposeScene(), (r = this.overlayCanvas) == null || r.remove();
|
|
2060
|
+
}
|
|
2061
|
+
clear() {
|
|
2062
|
+
this.document = void 0, this.bounds = N(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.disposeScene(), this.render(), this.emitViewChange();
|
|
2063
|
+
}
|
|
2064
|
+
setDocument(t) {
|
|
2065
|
+
this.document = t, this.bounds = cr(t, this.opts), this.disposeScene();
|
|
2066
|
+
const r = sr(t, this.opts, this.bounds);
|
|
2067
|
+
this.scene = ir(this.gl, r), this.stats = fr(this.scene, 0), this.fitToView();
|
|
2068
|
+
}
|
|
2069
|
+
getDocument() {
|
|
2070
|
+
return this.document;
|
|
2071
|
+
}
|
|
2072
|
+
setOptions(t) {
|
|
2073
|
+
const r = hr(this.opts, t);
|
|
2074
|
+
if (this.opts = { ...this.opts, ...t }, r && this.document) {
|
|
2075
|
+
this.setDocument(this.document);
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
this.render(), this.emitViewChange();
|
|
2079
|
+
}
|
|
2080
|
+
getOptions() {
|
|
2081
|
+
return { ...this.opts };
|
|
2082
|
+
}
|
|
2083
|
+
fitToView(t = 0.92) {
|
|
2084
|
+
if (!R(this.bounds)) {
|
|
2085
|
+
this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
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);
|
|
2089
|
+
this.fitScale = o, this.view = {
|
|
2090
|
+
centerX: (this.bounds.minX + this.bounds.maxX) / 2,
|
|
2091
|
+
centerY: (this.bounds.minY + this.bounds.maxY) / 2,
|
|
2092
|
+
scale: o
|
|
2093
|
+
}, this.render(), this.emitViewChange();
|
|
2094
|
+
}
|
|
2095
|
+
resize() {
|
|
2096
|
+
this.dpr = Math.max(1, window.devicePixelRatio || 1);
|
|
2097
|
+
const t = Math.max(1, Math.floor(this.cssWidth * this.dpr)), r = Math.max(1, Math.floor(this.cssHeight * this.dpr));
|
|
2098
|
+
(this.canvas.width !== t || this.canvas.height !== r) && (this.canvas.width = t, this.canvas.height = r), this.resizeOverlay(t, r), this.render(), this.emitViewChange();
|
|
2099
|
+
}
|
|
2100
|
+
zoom(t, r) {
|
|
2101
|
+
if (!Number.isFinite(t) || t <= 0) return;
|
|
2102
|
+
const i = r ?? { x: this.cssWidth / 2, y: this.cssHeight / 2 }, s = this.screenToWorld(i);
|
|
2103
|
+
this.view.scale = this.clampScale(this.view.scale * t);
|
|
2104
|
+
const n = this.screenToWorld(i);
|
|
2105
|
+
this.view.centerX += s.x - n.x, this.view.centerY += s.y - n.y, this.scheduleRender(), this.emitViewChange();
|
|
2106
|
+
}
|
|
2107
|
+
zoomIn() {
|
|
2108
|
+
this.zoom(this.opts.wheelZoomFactor);
|
|
2109
|
+
}
|
|
2110
|
+
zoomOut() {
|
|
2111
|
+
this.zoom(1 / this.opts.wheelZoomFactor);
|
|
2112
|
+
}
|
|
2113
|
+
panByScreenDelta(t, r) {
|
|
2114
|
+
!Number.isFinite(t) || !Number.isFinite(r) || (this.view.centerX -= t / this.view.scale, this.view.centerY += r / this.view.scale, this.scheduleRender(), this.emitViewChange());
|
|
2115
|
+
}
|
|
2116
|
+
setViewState(t) {
|
|
2117
|
+
if (![t.centerX, t.centerY, t.scale].every(Number.isFinite)) throw new Error("Invalid view state.");
|
|
2118
|
+
this.view = { ...t, scale: this.clampScale(t.scale) }, this.render(), this.emitViewChange();
|
|
2119
|
+
}
|
|
2120
|
+
getViewState() {
|
|
2121
|
+
return { ...this.view };
|
|
2122
|
+
}
|
|
2123
|
+
getBounds() {
|
|
2124
|
+
return { ...this.bounds };
|
|
2125
|
+
}
|
|
2126
|
+
getStats() {
|
|
2127
|
+
return dr(this.stats);
|
|
2128
|
+
}
|
|
2129
|
+
getZoomRatio() {
|
|
2130
|
+
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
2131
|
+
}
|
|
2132
|
+
getZoomPercent() {
|
|
2133
|
+
return this.getZoomRatio() * 100;
|
|
2134
|
+
}
|
|
2135
|
+
worldToScreen(t) {
|
|
2136
|
+
return {
|
|
2137
|
+
x: this.cssWidth / 2 + (t.x - this.view.centerX) * this.view.scale,
|
|
2138
|
+
y: this.cssHeight / 2 - (t.y - this.view.centerY) * this.view.scale
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
screenToWorld(t) {
|
|
2142
|
+
return {
|
|
2143
|
+
x: this.view.centerX + (t.x - this.cssWidth / 2) / this.view.scale,
|
|
2144
|
+
y: this.view.centerY - (t.y - this.cssHeight / 2) / this.view.scale
|
|
2145
|
+
};
|
|
2146
|
+
}
|
|
2147
|
+
render() {
|
|
2148
|
+
return this.cancelScheduledRender(), this.renderNow();
|
|
2149
|
+
}
|
|
2150
|
+
renderNow() {
|
|
2151
|
+
var l;
|
|
2152
|
+
const t = performance.now(), r = this.gl;
|
|
2153
|
+
r.viewport(0, 0, this.canvas.width, this.canvas.height);
|
|
2154
|
+
const i = pt(this.opts.background, [11, 16, 32, 255]);
|
|
2155
|
+
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);
|
|
2156
|
+
let s = 0, n = 0;
|
|
2157
|
+
const o = this.scene, a = this.visibleWorldBounds();
|
|
2158
|
+
if (o) {
|
|
2159
|
+
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)));
|
|
2160
|
+
const h = this.drawBatches(o.lineBatches, r.LINES, a);
|
|
2161
|
+
s += h.visible, n += h.culled;
|
|
2162
|
+
const f = this.drawBatches(o.triangleBatches, r.TRIANGLES, a);
|
|
2163
|
+
s += f.visible, n += f.culled;
|
|
2164
|
+
const d = this.drawBatches(o.pointBatches, r.POINTS, a);
|
|
2165
|
+
s += d.visible, n += d.culled;
|
|
2166
|
+
}
|
|
2167
|
+
this.renderOverlay(a);
|
|
2168
|
+
const c = performance.now() - t;
|
|
2169
|
+
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 }, (l = this.onStats) == null || l.call(this, this.getStats()), this.getStats();
|
|
2170
|
+
}
|
|
2171
|
+
drawBatches(t, r, i) {
|
|
2172
|
+
const s = this.gl;
|
|
2173
|
+
let n = 0, o = 0;
|
|
2174
|
+
for (const a of t) {
|
|
2175
|
+
if (!ct(a.bounds, i)) {
|
|
2176
|
+
o += a.primitiveCount;
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
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;
|
|
2180
|
+
}
|
|
2181
|
+
return { visible: n, culled: o };
|
|
2182
|
+
}
|
|
2183
|
+
scheduleRender() {
|
|
2184
|
+
this.rafHandle || (this.rafHandle = window.requestAnimationFrame(() => {
|
|
2185
|
+
this.rafHandle = 0, this.renderNow();
|
|
2186
|
+
}));
|
|
2187
|
+
}
|
|
2188
|
+
cancelScheduledRender() {
|
|
2189
|
+
this.rafHandle && (window.cancelAnimationFrame(this.rafHandle), this.rafHandle = 0);
|
|
2190
|
+
}
|
|
2191
|
+
renderOverlay(t) {
|
|
2192
|
+
var s, n;
|
|
2193
|
+
const r = this.overlayCtx, i = this.overlayCanvas;
|
|
2194
|
+
!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());
|
|
2195
|
+
}
|
|
2196
|
+
drawPageBoundsOverlay(t) {
|
|
2197
|
+
var r, i;
|
|
2198
|
+
if ((i = (r = this.document) == null ? void 0 : r.pages) != null && i.length) {
|
|
2199
|
+
t.save(), t.strokeStyle = "rgba(148, 163, 184, 0.34)", t.lineWidth = 1, t.setLineDash([8, 6]);
|
|
2200
|
+
for (const s of this.document.pages) {
|
|
2201
|
+
const n = this.worldToScreen({ x: 0, y: 0 }), o = this.worldToScreen({ x: s.width, y: s.height });
|
|
2202
|
+
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));
|
|
2203
|
+
}
|
|
2204
|
+
t.restore();
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
drawTextOverlay(t, r, i) {
|
|
2208
|
+
const s = this.opts.maxVisibleTextLabels;
|
|
2209
|
+
let n = 0;
|
|
2210
|
+
for (const o of r) {
|
|
2211
|
+
if (n >= s) break;
|
|
2212
|
+
if (!ct(o.bounds, i)) continue;
|
|
2213
|
+
const a = Math.abs(o.height) * this.view.scale;
|
|
2214
|
+
if (a < this.opts.textMinPixelHeight) continue;
|
|
2215
|
+
const c = this.worldToScreen(o.point);
|
|
2216
|
+
if (c.x < -512 || c.y < -512 || c.x > this.cssWidth + 512 || c.y > this.cssHeight + 512) continue;
|
|
2217
|
+
t.save(), t.translate(c.x, c.y), t.rotate(-o.rotation);
|
|
2218
|
+
const l = Math.max(4, Math.min(256, a));
|
|
2219
|
+
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";
|
|
2220
|
+
for (const [h, f] of o.text.split(/\r?\n/g).entries()) t.fillText(f, 0, h * l * 1.22);
|
|
2221
|
+
t.restore(), n++;
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
drawImagesOverlay(t, r, i) {
|
|
2225
|
+
for (const s of r) {
|
|
2226
|
+
if (!ct(s.bounds, i)) continue;
|
|
2227
|
+
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), l = Math.abs(o.x - n.x), h = Math.abs(o.y - n.y);
|
|
2228
|
+
if (!(l < 1 || h < 1)) {
|
|
2229
|
+
if (s.source) {
|
|
2230
|
+
const f = this.getImage(s.source);
|
|
2231
|
+
if (f.complete && f.naturalWidth > 0) {
|
|
2232
|
+
t.save(), t.globalAlpha = s.opacity, t.drawImage(f, a, c, l, h), t.restore();
|
|
2233
|
+
continue;
|
|
2234
|
+
}
|
|
2235
|
+
f.onload = () => this.scheduleRender();
|
|
2236
|
+
}
|
|
2237
|
+
this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = s.color, t.globalAlpha = s.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());
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
getImage(t) {
|
|
2242
|
+
let r = this.imageCache.get(t);
|
|
2243
|
+
return r || (r = new Image(), r.src = t, this.imageCache.set(t, r)), r;
|
|
2244
|
+
}
|
|
2245
|
+
createOverlayCanvas() {
|
|
2246
|
+
const t = this.canvas.parentElement;
|
|
2247
|
+
if (!t || typeof document > "u") return;
|
|
2248
|
+
window.getComputedStyle(t).position === "static" && (t.style.position = "relative");
|
|
2249
|
+
const i = document.createElement("canvas");
|
|
2250
|
+
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";
|
|
2251
|
+
const s = i.getContext("2d");
|
|
2252
|
+
s && (t.appendChild(i), this.overlayCanvas = i, this.overlayCtx = s);
|
|
2253
|
+
}
|
|
2254
|
+
resizeOverlay(t, r) {
|
|
2255
|
+
this.overlayCanvas && (this.overlayCanvas.width !== t || this.overlayCanvas.height !== r) && (this.overlayCanvas.width = t, this.overlayCanvas.height = r);
|
|
2256
|
+
}
|
|
2257
|
+
bindEvents() {
|
|
2258
|
+
const t = this.eventController.signal;
|
|
2259
|
+
this.canvas.addEventListener("wheel", (i) => {
|
|
2260
|
+
i.preventDefault();
|
|
2261
|
+
const s = i.deltaY < 0 ? this.opts.wheelZoomFactor : 1 / this.opts.wheelZoomFactor;
|
|
2262
|
+
this.zoom(s, { x: i.offsetX, y: i.offsetY });
|
|
2263
|
+
}, { passive: !1, signal: t }), this.canvas.addEventListener("pointerdown", (i) => {
|
|
2264
|
+
this.canvas.setPointerCapture(i.pointerId), this.isDragging = !0, this.lastPointer = { x: i.clientX, y: i.clientY }, this.canvas.classList.add("is-dragging");
|
|
2265
|
+
}, { signal: t }), this.canvas.addEventListener("pointermove", (i) => {
|
|
2266
|
+
!this.isDragging || !this.lastPointer || (this.panByScreenDelta(i.clientX - this.lastPointer.x, i.clientY - this.lastPointer.y), this.lastPointer = { x: i.clientX, y: i.clientY });
|
|
2267
|
+
}, { signal: t });
|
|
2268
|
+
const r = (i) => {
|
|
2269
|
+
i && this.canvas.hasPointerCapture(i.pointerId) && this.canvas.releasePointerCapture(i.pointerId), this.isDragging = !1, this.lastPointer = void 0, this.canvas.classList.remove("is-dragging");
|
|
2270
|
+
};
|
|
2271
|
+
this.canvas.addEventListener("pointerup", r, { signal: t }), this.canvas.addEventListener("pointercancel", () => r(), { signal: t }), this.canvas.addEventListener("webglcontextlost", (i) => {
|
|
2272
|
+
i.preventDefault(), this.cancelScheduledRender();
|
|
2273
|
+
}, { signal: t });
|
|
2274
|
+
}
|
|
2275
|
+
visibleWorldBounds() {
|
|
2276
|
+
const t = this.cssWidth / Math.max(this.view.scale, 1e-12) / 2, r = this.cssHeight / Math.max(this.view.scale, 1e-12) / 2;
|
|
2277
|
+
return {
|
|
2278
|
+
minX: this.view.centerX - t,
|
|
2279
|
+
maxX: this.view.centerX + t,
|
|
2280
|
+
minY: this.view.centerY - r,
|
|
2281
|
+
maxY: this.view.centerY + r
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2284
|
+
get cssWidth() {
|
|
2285
|
+
return this.canvas.clientWidth || 1;
|
|
2286
|
+
}
|
|
2287
|
+
get cssHeight() {
|
|
2288
|
+
return this.canvas.clientHeight || 1;
|
|
2289
|
+
}
|
|
2290
|
+
clampScale(t) {
|
|
2291
|
+
return Math.min(this.opts.maxScale, Math.max(this.opts.minScale, t));
|
|
2292
|
+
}
|
|
2293
|
+
disposeScene() {
|
|
2294
|
+
if (!this.scene) return;
|
|
2295
|
+
const t = this.gl;
|
|
2296
|
+
for (const r of [...this.scene.lineBatches, ...this.scene.triangleBatches, ...this.scene.pointBatches])
|
|
2297
|
+
t.deleteBuffer(r.positionBuffer), t.deleteBuffer(r.colorBuffer);
|
|
2298
|
+
this.scene = void 0;
|
|
2299
|
+
}
|
|
2300
|
+
emitViewChange() {
|
|
2301
|
+
var t;
|
|
2302
|
+
(t = this.onViewChange) == null || t.call(this, {
|
|
2303
|
+
view: this.getViewState(),
|
|
2304
|
+
fitScale: this.fitScale,
|
|
2305
|
+
zoomRatio: this.getZoomRatio(),
|
|
2306
|
+
zoomPercent: this.getZoomPercent(),
|
|
2307
|
+
bounds: this.getBounds()
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
function Kt() {
|
|
2312
|
+
if (typeof document > "u") return !1;
|
|
2313
|
+
const e = document.createElement("canvas");
|
|
2314
|
+
return !!(e.getContext("webgl2") ?? e.getContext("webgl") ?? e.getContext("experimental-webgl"));
|
|
2315
|
+
}
|
|
2316
|
+
function er(e, t) {
|
|
2317
|
+
const r = {
|
|
2318
|
+
alpha: !1,
|
|
2319
|
+
antialias: t.antialias ?? !0,
|
|
2320
|
+
depth: !1,
|
|
2321
|
+
stencil: !1,
|
|
2322
|
+
preserveDrawingBuffer: t.preserveDrawingBuffer ?? !1,
|
|
2323
|
+
powerPreference: t.powerPreference ?? "high-performance"
|
|
2324
|
+
};
|
|
2325
|
+
return e.getContext("webgl2", r) ?? e.getContext("webgl", r) ?? e.getContext("experimental-webgl", r) ?? void 0;
|
|
2326
|
+
}
|
|
2327
|
+
function rr(e) {
|
|
2328
|
+
const t = `
|
|
2329
|
+
attribute vec2 a_position;
|
|
2330
|
+
attribute vec4 a_color;
|
|
2331
|
+
uniform vec2 u_viewCenter;
|
|
2332
|
+
uniform float u_scale;
|
|
2333
|
+
uniform vec2 u_viewport;
|
|
2334
|
+
uniform float u_pointSize;
|
|
2335
|
+
varying vec4 v_color;
|
|
2336
|
+
void main() {
|
|
2337
|
+
vec2 screen = vec2(
|
|
2338
|
+
u_viewport.x * 0.5 + (a_position.x - u_viewCenter.x) * u_scale,
|
|
2339
|
+
u_viewport.y * 0.5 - (a_position.y - u_viewCenter.y) * u_scale
|
|
2340
|
+
);
|
|
2341
|
+
vec2 clip = vec2(screen.x / u_viewport.x * 2.0 - 1.0, 1.0 - screen.y / u_viewport.y * 2.0);
|
|
2342
|
+
gl_Position = vec4(clip, 0.0, 1.0);
|
|
2343
|
+
gl_PointSize = u_pointSize;
|
|
2344
|
+
v_color = a_color;
|
|
2345
|
+
}
|
|
2346
|
+
`, r = `
|
|
2347
|
+
precision mediump float;
|
|
2348
|
+
varying vec4 v_color;
|
|
2349
|
+
void main() {
|
|
2350
|
+
gl_FragColor = v_color;
|
|
2351
|
+
}
|
|
2352
|
+
`, i = Wt(e, e.VERTEX_SHADER, t), s = Wt(e, e.FRAGMENT_SHADER, r), n = e.createProgram();
|
|
2353
|
+
if (!n) throw new Error("Failed to create WebGL program.");
|
|
2354
|
+
if (e.attachShader(n, i), e.attachShader(n, s), e.linkProgram(n), !e.getProgramParameter(n, e.LINK_STATUS)) {
|
|
2355
|
+
const h = e.getProgramInfoLog(n) ?? "Unknown WebGL program link error.";
|
|
2356
|
+
throw e.deleteProgram(n), new Error(h);
|
|
2357
|
+
}
|
|
2358
|
+
e.deleteShader(i), e.deleteShader(s);
|
|
2359
|
+
const o = e.getUniformLocation(n, "u_viewCenter"), a = e.getUniformLocation(n, "u_scale"), c = e.getUniformLocation(n, "u_viewport"), l = e.getUniformLocation(n, "u_pointSize");
|
|
2360
|
+
if (!o || !a || !c || !l) throw new Error("Failed to resolve WebGL shader uniforms.");
|
|
2361
|
+
return {
|
|
2362
|
+
program: n,
|
|
2363
|
+
aPosition: e.getAttribLocation(n, "a_position"),
|
|
2364
|
+
aColor: e.getAttribLocation(n, "a_color"),
|
|
2365
|
+
uViewCenter: o,
|
|
2366
|
+
uScale: a,
|
|
2367
|
+
uViewport: c,
|
|
2368
|
+
uPointSize: l
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2371
|
+
function Wt(e, t, r) {
|
|
2372
|
+
const i = e.createShader(t);
|
|
2373
|
+
if (!i) throw new Error("Failed to create WebGL shader.");
|
|
2374
|
+
if (e.shaderSource(i, r), e.compileShader(i), !e.getShaderParameter(i, e.COMPILE_STATUS)) {
|
|
2375
|
+
const s = e.getShaderInfoLog(i) ?? "Unknown WebGL shader compile error.";
|
|
2376
|
+
throw e.deleteShader(i), new Error(s);
|
|
2377
|
+
}
|
|
2378
|
+
return i;
|
|
2379
|
+
}
|
|
2380
|
+
function ir(e, t) {
|
|
2381
|
+
let r = 0;
|
|
2382
|
+
const i = (a) => a.map((c) => {
|
|
2383
|
+
const l = Ot(e, c.positions), h = Ot(e, c.colors), f = c.positions.byteLength + c.colors.byteLength;
|
|
2384
|
+
return r += f, {
|
|
2385
|
+
positionBuffer: l,
|
|
2386
|
+
colorBuffer: h,
|
|
2387
|
+
vertexCount: c.positions.length / 2,
|
|
2388
|
+
primitiveCount: c.primitiveCount,
|
|
2389
|
+
bounds: c.bounds,
|
|
2390
|
+
gpuBytes: f
|
|
2391
|
+
};
|
|
2392
|
+
}), s = i(t.lineBatches), n = i(t.triangleBatches), o = i(t.pointBatches);
|
|
2393
|
+
return {
|
|
2394
|
+
origin: t.origin,
|
|
2395
|
+
lineBatches: s,
|
|
2396
|
+
triangleBatches: n,
|
|
2397
|
+
pointBatches: o,
|
|
2398
|
+
textItems: t.textItems,
|
|
2399
|
+
imageItems: t.imageItems,
|
|
2400
|
+
stats: t.stats,
|
|
2401
|
+
primitiveCount: t.primitiveCount,
|
|
2402
|
+
gpuMemoryBytes: r,
|
|
2403
|
+
buildElapsedMs: t.buildElapsedMs
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
function Ot(e, t) {
|
|
2407
|
+
const r = e.createBuffer();
|
|
2408
|
+
if (!r) throw new Error("Failed to create WebGL buffer.");
|
|
2409
|
+
return e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW), r;
|
|
2410
|
+
}
|
|
2411
|
+
function sr(e, t, r) {
|
|
2412
|
+
const i = performance.now(), s = R(r) ? { x: (r.minX + r.maxX) / 2, y: (r.minY + r.maxY) / 2 } : { x: 0, y: 0 }, n = new nr(e, t, r, s);
|
|
2413
|
+
for (const a of e.entities) n.addEntityTracked(a, 0);
|
|
2414
|
+
const o = n.finalize();
|
|
2415
|
+
return o.buildElapsedMs = performance.now() - i, o;
|
|
2416
|
+
}
|
|
2417
|
+
class nr {
|
|
2418
|
+
constructor(t, r, i, s) {
|
|
2419
|
+
u(this, "lineBuckets", /* @__PURE__ */ new Map());
|
|
2420
|
+
u(this, "triangleBuckets", /* @__PURE__ */ new Map());
|
|
2421
|
+
u(this, "pointBuckets", /* @__PURE__ */ new Map());
|
|
2422
|
+
u(this, "textItems", []);
|
|
2423
|
+
u(this, "imageItems", []);
|
|
2424
|
+
u(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 });
|
|
2425
|
+
u(this, "tileSize");
|
|
2426
|
+
u(this, "maxVerticesPerBatch");
|
|
2427
|
+
u(this, "primitiveCount", 0);
|
|
2428
|
+
this.document = t, this.opts = r, this.bounds = i, this.origin = s;
|
|
2429
|
+
const n = R(i) ? Math.max(i.maxX - i.minX, i.maxY - i.minY, 1e-9) : 1;
|
|
2430
|
+
this.tileSize = r.enableSpatialIndex ? n / Math.max(8, r.spatialIndexCellCount) : Number.POSITIVE_INFINITY, this.maxVerticesPerBatch = Math.max(4096, Math.floor(r.maxVerticesPerBatch));
|
|
2431
|
+
}
|
|
2432
|
+
addEntityTracked(t, r) {
|
|
2433
|
+
this.stats.total++;
|
|
2434
|
+
const i = String(t.type ?? "UNKNOWN").toUpperCase();
|
|
2435
|
+
this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
|
|
2436
|
+
const s = this.lookupLayer(t.layer);
|
|
2437
|
+
if (t.isVisible === !1 || !$t(s)) {
|
|
2438
|
+
this.stats.skipped++;
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
this.addEntity(t, i, r);
|
|
2442
|
+
}
|
|
2443
|
+
finalize() {
|
|
2444
|
+
const t = ot(this.lineBuckets, this.maxVerticesPerBatch), r = ot(this.triangleBuckets, this.maxVerticesPerBatch), i = ot(this.pointBuckets, this.maxVerticesPerBatch);
|
|
2445
|
+
return this.stats.primitiveCount = this.primitiveCount, {
|
|
2446
|
+
origin: this.origin,
|
|
2447
|
+
lineBatches: t,
|
|
2448
|
+
triangleBatches: r,
|
|
2449
|
+
pointBatches: i,
|
|
2450
|
+
textItems: this.textItems,
|
|
2451
|
+
imageItems: this.imageItems,
|
|
2452
|
+
stats: this.stats,
|
|
2453
|
+
primitiveCount: this.primitiveCount,
|
|
2454
|
+
buildElapsedMs: 0
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
addEntity(t, r, i) {
|
|
2458
|
+
switch (t.kind ?? O(r)) {
|
|
2459
|
+
case "line":
|
|
2460
|
+
return this.addLineEntity(t);
|
|
2461
|
+
case "circle":
|
|
2462
|
+
return this.addCircleEntity(t);
|
|
2463
|
+
case "arc":
|
|
2464
|
+
return this.addArcEntity(t);
|
|
2465
|
+
case "polyline":
|
|
2466
|
+
return this.addPolylineEntity(t);
|
|
2467
|
+
case "ellipse":
|
|
2468
|
+
return this.addEllipseEntity(t);
|
|
2469
|
+
case "text":
|
|
2470
|
+
return this.addTextEntity(t);
|
|
2471
|
+
case "point":
|
|
2472
|
+
return this.addPointEntity(t);
|
|
2473
|
+
case "insert":
|
|
2474
|
+
return this.addInsertEntity(t, i);
|
|
2475
|
+
case "solid":
|
|
2476
|
+
return this.addSolidEntity(t);
|
|
2477
|
+
case "hatch":
|
|
2478
|
+
return this.addHatchEntity(t);
|
|
2479
|
+
case "spline":
|
|
2480
|
+
return this.addSplineEntity(t);
|
|
2481
|
+
case "path":
|
|
2482
|
+
return this.addPathEntity(t);
|
|
2483
|
+
case "image":
|
|
2484
|
+
return this.addImageEntity(t);
|
|
2485
|
+
case "viewport":
|
|
2486
|
+
return this.markSkipped(r);
|
|
2487
|
+
default:
|
|
2488
|
+
this.stats.unsupported[r] = (this.stats.unsupported[r] ?? 0) + 1, this.stats.skipped++, this.opts.showUnsupportedMarkers && this.addUnsupportedMarker(t);
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
addLineEntity(t) {
|
|
2492
|
+
if (!m(t.startPoint) || !m(t.endPoint)) return this.markSkipped("LINE");
|
|
2493
|
+
this.addSegment(t.startPoint, t.endPoint, this.strokeBytes(t)), this.stats.drawn++;
|
|
2494
|
+
}
|
|
2495
|
+
addCircleEntity(t) {
|
|
2496
|
+
const r = t.center, i = Number(t.radius);
|
|
2497
|
+
if (!m(r) || !Number.isFinite(i)) return this.markSkipped("CIRCLE");
|
|
2498
|
+
const s = Math.max(16, Math.min(this.opts.maxCurveSegments, Math.ceil(Math.sqrt(Math.abs(i)) * 12))), n = G(r, i, 0, Math.PI * 2, !0, s);
|
|
2499
|
+
this.addPolyline(n, !0, this.strokeBytes(t)), this.stats.drawn++;
|
|
2500
|
+
}
|
|
2501
|
+
addArcEntity(t) {
|
|
2502
|
+
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
2503
|
+
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
2504
|
+
this.addPolyline(G(r, i, s, n, !0, this.opts.maxCurveSegments), !1, this.strokeBytes(t)), this.stats.drawn++;
|
|
2505
|
+
}
|
|
2506
|
+
addPolylineEntity(t) {
|
|
2507
|
+
const r = t.vertices ?? t.points;
|
|
2508
|
+
if (!Array.isArray(r) || r.length < 2) return this.markSkipped(String(t.type));
|
|
2509
|
+
const i = !!t.isClosed || (Number(t.flag) & 1) === 1, s = [], n = i ? r.length : r.length - 1;
|
|
2510
|
+
for (let o = 0; o < n; o++) {
|
|
2511
|
+
const a = r[o], c = r[(o + 1) % r.length];
|
|
2512
|
+
if (!m(a) || !m(c)) continue;
|
|
2513
|
+
const l = _t(a, c, Number(a.bulge ?? 0), Math.max(4, Math.min(24, this.opts.maxCurveSegments / 4)));
|
|
2514
|
+
s.length > 0 && l.shift(), s.push(...l);
|
|
2515
|
+
}
|
|
2516
|
+
if (s.length < 2) return this.markSkipped(String(t.type));
|
|
2517
|
+
this.addPolyline(s, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
2518
|
+
}
|
|
2519
|
+
addEllipseEntity(t) {
|
|
2520
|
+
if (!m(t.center) || !m(t.majorAxisEndPoint)) return this.markSkipped("ELLIPSE");
|
|
2521
|
+
const r = Z(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;
|
|
2522
|
+
this.addPolyline(r, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
2523
|
+
}
|
|
2524
|
+
addTextEntity(t) {
|
|
2525
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = Ut(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
2526
|
+
if (!m(r) || !i || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2527
|
+
const n = v(r), o = Math.max(1, i.split(/\r?\n/g).reduce((c, l) => Math.max(c, l.length), 0)) * Math.abs(s) * 0.62, a = Math.max(1, i.split(/\r?\n/g).length) * Math.abs(s) * 1.22;
|
|
2528
|
+
this.textItems.push({
|
|
2529
|
+
point: n,
|
|
2530
|
+
text: i,
|
|
2531
|
+
height: s,
|
|
2532
|
+
rotation: Number(t.rotation ?? 0),
|
|
2533
|
+
color: D(t, this.document, this.colorOptions()),
|
|
2534
|
+
opacity: B(Number(t.opacity ?? 1), 0, 1),
|
|
2535
|
+
bounds: { minX: n.x - o * 0.1, minY: n.y - a, maxX: n.x + o, maxY: n.y + a }
|
|
2536
|
+
}), this.stats.drawn++;
|
|
2537
|
+
}
|
|
2538
|
+
addPointEntity(t) {
|
|
2539
|
+
const r = t.point ?? t.location ?? t.center ?? t.insertionPoint;
|
|
2540
|
+
if (!m(r)) return this.markSkipped("POINT");
|
|
2541
|
+
this.addPoint(r, this.strokeBytes(t)), this.stats.drawn++;
|
|
2542
|
+
}
|
|
2543
|
+
addInsertEntity(t, r) {
|
|
2544
|
+
const i = this.lookupBlock(t.blockName ?? t.name);
|
|
2545
|
+
if (i && r < this.opts.maxInsertDepth) {
|
|
2546
|
+
const n = Q(t, i.basePoint ?? { x: 0, y: 0 });
|
|
2547
|
+
for (const o of i.entities) {
|
|
2548
|
+
const a = jt(o, t, this.document, this.colorOptions());
|
|
2549
|
+
this.addEntityTracked(J(a, n), r + 1);
|
|
2550
|
+
}
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
const s = t.insertionPoint;
|
|
2554
|
+
if (!m(s)) return this.markSkipped("INSERT");
|
|
2555
|
+
if (this.addPoint(s, this.strokeBytes(t)), Array.isArray(t.attribs)) for (const n of t.attribs) this.addTextEntity(n);
|
|
2556
|
+
this.stats.drawn++;
|
|
2557
|
+
}
|
|
2558
|
+
addSolidEntity(t) {
|
|
2559
|
+
const r = t.vertices ?? t.points;
|
|
2560
|
+
if (!Array.isArray(r) || r.length < 3) return this.markSkipped(String(t.type));
|
|
2561
|
+
const i = r.filter(m).map(v);
|
|
2562
|
+
if (i.length < 3) return this.markSkipped(String(t.type));
|
|
2563
|
+
const s = this.fillBytes(t) ?? this.strokeBytes(t);
|
|
2564
|
+
this.addTriangleFan(i, s), this.addPolyline(i, !0, this.strokeBytes(t)), this.stats.drawn++;
|
|
2565
|
+
}
|
|
2566
|
+
addHatchEntity(t) {
|
|
2567
|
+
var o;
|
|
2568
|
+
const r = t.loops;
|
|
2569
|
+
if (!Array.isArray(r) || r.length === 0) return this.markSkipped("HATCH");
|
|
2570
|
+
const i = this.strokeBytes(t), s = this.fillBytes(t);
|
|
2571
|
+
let n = !1;
|
|
2572
|
+
for (const a of r) {
|
|
2573
|
+
const c = (o = a.commands) != null && o.length ? Rt(a.commands, this.opts.maxCurveSegments) : (a.vertices ?? []).filter(m).map(v);
|
|
2574
|
+
c.length < 2 || (this.addPolyline(c, !0, i), s && c.length >= 3 && this.addTriangleFan(c, s), n = !0);
|
|
2575
|
+
}
|
|
2576
|
+
if (!n) return this.markSkipped("HATCH");
|
|
2577
|
+
this.stats.drawn++;
|
|
2578
|
+
}
|
|
2579
|
+
addSplineEntity(t) {
|
|
2580
|
+
var i;
|
|
2581
|
+
const r = (i = t.fitPoints) != null && i.length ? t.fitPoints : t.controlPoints;
|
|
2582
|
+
if (!r || r.length < 2) return this.markSkipped("SPLINE");
|
|
2583
|
+
this.addPolyline(r.filter(m).map(v), !!t.isClosed, this.strokeBytes(t)), this.stats.drawn++;
|
|
2584
|
+
}
|
|
2585
|
+
addPathEntity(t) {
|
|
2586
|
+
var s;
|
|
2587
|
+
if (!((s = t.commands) != null && s.length)) return this.markSkipped(String(t.type));
|
|
2588
|
+
const r = Rt(t.commands, this.opts.maxCurveSegments);
|
|
2589
|
+
if (r.length < 2) return this.markSkipped(String(t.type));
|
|
2590
|
+
this.addPolyline(r, !1, this.strokeBytes(t));
|
|
2591
|
+
const i = this.fillBytes(t);
|
|
2592
|
+
i && r.length >= 3 && this.addTriangleFan(r, i), this.stats.drawn++;
|
|
2593
|
+
}
|
|
2594
|
+
addImageEntity(t) {
|
|
2595
|
+
const r = t.insertionPoint;
|
|
2596
|
+
if (!m(r)) return this.markSkipped(String(t.type));
|
|
2597
|
+
const i = Number(t.width ?? 32), s = Number(t.height ?? 32);
|
|
2598
|
+
if (!Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2599
|
+
const n = v(r), o = at([n, { x: n.x + i, y: n.y - s }]);
|
|
2600
|
+
this.imageItems.push({ point: n, width: i, height: s, source: t.imageDataUrl ?? t.imageSource, color: D(t, this.document, this.colorOptions()), opacity: B(Number(t.opacity ?? 1), 0, 1), bounds: o }), this.stats.drawn++;
|
|
2601
|
+
}
|
|
2602
|
+
addUnsupportedMarker(t) {
|
|
2603
|
+
const r = Qt(t);
|
|
2604
|
+
r && this.addPoint(r, this.strokeBytes(t));
|
|
2605
|
+
}
|
|
2606
|
+
addPolyline(t, r, i) {
|
|
2607
|
+
const s = t.filter(m).map(v);
|
|
2608
|
+
if (!(s.length < 2)) {
|
|
2609
|
+
for (let n = 0; n < s.length - 1; n++) this.addSegment(s[n], s[n + 1], i);
|
|
2610
|
+
r && this.addSegment(s[s.length - 1], s[0], i);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
addSegment(t, r, i) {
|
|
2614
|
+
if (!m(t) || !m(r) || Math.hypot(t.x - r.x, t.y - r.y) <= 1e-14) return;
|
|
2615
|
+
const s = this.batchFor(this.lineBuckets, at([t, r]));
|
|
2616
|
+
L(s, t, i, this.origin), L(s, r, i, this.origin), s.primitiveCount++, this.primitiveCount++;
|
|
2617
|
+
}
|
|
2618
|
+
addPoint(t, r) {
|
|
2619
|
+
const i = this.batchFor(this.pointBuckets, lr(t));
|
|
2620
|
+
L(i, t, r, this.origin), i.primitiveCount++, this.primitiveCount++;
|
|
2621
|
+
}
|
|
2622
|
+
addTriangleFan(t, r) {
|
|
2623
|
+
const i = t.filter(m).map(v);
|
|
2624
|
+
if (i.length < 3) return;
|
|
2625
|
+
const s = at(i), n = this.batchFor(this.triangleBuckets, s);
|
|
2626
|
+
for (let o = 1; o < i.length - 1; o++)
|
|
2627
|
+
L(n, i[0], r, this.origin), L(n, i[o], r, this.origin), L(n, i[o + 1], r, this.origin), n.primitiveCount++, this.primitiveCount++;
|
|
2628
|
+
}
|
|
2629
|
+
batchFor(t, r) {
|
|
2630
|
+
const i = this.bucketKey(r);
|
|
2631
|
+
let s = t.get(i);
|
|
2632
|
+
return s || (s = or(), t.set(i, s)), y(s.bounds, { x: r.minX, y: r.minY }), y(s.bounds, { x: r.maxX, y: r.maxY }), s;
|
|
2633
|
+
}
|
|
2634
|
+
bucketKey(t) {
|
|
2635
|
+
if (!Number.isFinite(this.tileSize)) return "all";
|
|
2636
|
+
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);
|
|
2637
|
+
return `${s}:${n}`;
|
|
2638
|
+
}
|
|
2639
|
+
strokeBytes(t) {
|
|
2640
|
+
return pt(D(t, this.document, this.colorOptions()), [255, 255, 255, 255], B(Number(t.opacity ?? 1), 0, 1));
|
|
2641
|
+
}
|
|
2642
|
+
fillBytes(t) {
|
|
2643
|
+
const r = ft(t, this.document, this.colorOptions());
|
|
2644
|
+
return r ? pt(r, [255, 255, 255, 255], B(Number(t.opacity ?? 1), 0, 1)) : void 0;
|
|
2645
|
+
}
|
|
2646
|
+
colorOptions() {
|
|
2647
|
+
return { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast };
|
|
2648
|
+
}
|
|
2649
|
+
markSkipped(t) {
|
|
2650
|
+
this.stats.skipped++, this.stats.unsupported[t] = this.stats.unsupported[t] ?? 0;
|
|
2651
|
+
}
|
|
2652
|
+
lookupLayer(t) {
|
|
2653
|
+
if (t)
|
|
2654
|
+
return this.document.layers[t] ?? this.document.layers[t.toLowerCase()] ?? Object.values(this.document.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
2655
|
+
}
|
|
2656
|
+
lookupBlock(t) {
|
|
2657
|
+
if (t)
|
|
2658
|
+
return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
function or() {
|
|
2662
|
+
return { positions: [], colors: [], bounds: N(), primitiveCount: 0 };
|
|
2663
|
+
}
|
|
2664
|
+
function L(e, t, r, i) {
|
|
2665
|
+
e.positions.push(t.x - i.x, t.y - i.y), e.colors.push(r[0], r[1], r[2], r[3]);
|
|
2666
|
+
}
|
|
2667
|
+
function ot(e, t) {
|
|
2668
|
+
const r = [];
|
|
2669
|
+
for (const i of e.values()) {
|
|
2670
|
+
const s = i.positions.length / 2;
|
|
2671
|
+
if (s <= 0 || !R(i.bounds)) continue;
|
|
2672
|
+
if (s <= t) {
|
|
2673
|
+
r.push({ positions: new Float32Array(i.positions), colors: new Uint8Array(i.colors), bounds: { ...i.bounds }, primitiveCount: i.primitiveCount });
|
|
2674
|
+
continue;
|
|
2675
|
+
}
|
|
2676
|
+
const n = ar(i), o = Math.max(n, Math.floor(t / n) * n);
|
|
2677
|
+
for (let a = 0; a < s; a += o) {
|
|
2678
|
+
const c = Math.min(s, a + o), l = i.positions.slice(a * 2, c * 2), h = i.colors.slice(a * 4, c * 4), f = N();
|
|
2679
|
+
for (let d = 0; d < l.length; d += 2) y(f, { x: l[d], y: l[d + 1] });
|
|
2680
|
+
r.push({ positions: new Float32Array(l), colors: new Uint8Array(h), bounds: { ...i.bounds }, primitiveCount: Math.floor((c - a) / n) });
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
return r;
|
|
2684
|
+
}
|
|
2685
|
+
function ar(e) {
|
|
2686
|
+
const t = e.positions.length / 2;
|
|
2687
|
+
return t === e.primitiveCount ? 1 : t === e.primitiveCount * 3 ? 3 : 2;
|
|
2688
|
+
}
|
|
2689
|
+
function cr(e, t) {
|
|
2690
|
+
var n;
|
|
2691
|
+
const r = N();
|
|
2692
|
+
if ((n = e.pages) != null && n.length)
|
|
2693
|
+
for (const o of e.pages)
|
|
2694
|
+
y(r, { x: 0, y: 0 }), y(r, { x: o.width, y: o.height });
|
|
2695
|
+
const i = (o) => {
|
|
2696
|
+
if (o)
|
|
2697
|
+
return e.blocks[o] ?? e.blocks[o.toLowerCase()] ?? Object.values(e.blocks).find((a) => a.name.toLowerCase() === o.toLowerCase());
|
|
2698
|
+
}, s = (o, a) => {
|
|
2699
|
+
const c = String(o.type ?? "").toUpperCase(), l = o.kind ?? O(c);
|
|
2700
|
+
if (l === "insert") {
|
|
2701
|
+
const h = i(o.blockName ?? o.name);
|
|
2702
|
+
if (h && a < t.maxInsertDepth) {
|
|
2703
|
+
const f = Q(o, h.basePoint ?? { x: 0, y: 0 });
|
|
2704
|
+
for (const d of h.entities) s(J(d, f), a + 1);
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
if (l === "line")
|
|
2709
|
+
m(o.startPoint) && y(r, o.startPoint), m(o.endPoint) && y(r, o.endPoint);
|
|
2710
|
+
else if (l === "circle" || l === "arc")
|
|
2711
|
+
m(o.center) && Number.isFinite(o.radius) && Yt(r, o.center, Number(o.radius));
|
|
2712
|
+
else if (l === "polyline" || l === "solid" || l === "spline")
|
|
2713
|
+
for (const h of [...o.vertices ?? [], ...o.points ?? [], ...o.controlPoints ?? [], ...o.fitPoints ?? []]) m(h) && y(r, h);
|
|
2714
|
+
else if (l === "ellipse")
|
|
2715
|
+
m(o.center) && m(o.majorAxisEndPoint) && Z(o.center, o.majorAxisEndPoint, Number(o.axisRatio ?? 1), Number(o.startAngle ?? 0), Number(o.endAngle ?? Math.PI * 2), t.maxCurveSegments).forEach((h) => y(r, h));
|
|
2716
|
+
else if (l === "path")
|
|
2717
|
+
for (const h of o.commands ?? []) for (const f of h.points) y(r, f);
|
|
2718
|
+
else if (l === "hatch")
|
|
2719
|
+
for (const h of o.loops ?? []) {
|
|
2720
|
+
for (const f of h.vertices ?? []) y(r, f);
|
|
2721
|
+
for (const f of h.commands ?? []) for (const d of f.points) y(r, d);
|
|
2722
|
+
}
|
|
2723
|
+
else {
|
|
2724
|
+
const h = Qt(o);
|
|
2725
|
+
h && y(r, h);
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
for (const o of e.entities) s(o, 0);
|
|
2729
|
+
return Ht(r);
|
|
2730
|
+
}
|
|
2731
|
+
function Rt(e, t) {
|
|
2732
|
+
const r = [];
|
|
2733
|
+
let i, s;
|
|
2734
|
+
const n = (o) => {
|
|
2735
|
+
(!r.length || Math.hypot(r[r.length - 1].x - o.x, r[r.length - 1].y - o.y) > 1e-12) && r.push(v(o)), i = v(o);
|
|
2736
|
+
};
|
|
2737
|
+
for (const o of e)
|
|
2738
|
+
if (o.cmd === "M")
|
|
2739
|
+
i = v(o.points[0]), s = i, n(i);
|
|
2740
|
+
else if (o.cmd === "L")
|
|
2741
|
+
n(o.points[0]);
|
|
2742
|
+
else if (o.cmd === "Q" && i && o.points.length >= 2) {
|
|
2743
|
+
const a = i, [c, l] = o.points, h = Math.max(4, Math.min(t, 24));
|
|
2744
|
+
for (let f = 1; f <= h; f++) {
|
|
2745
|
+
const d = f / h, p = 1 - d;
|
|
2746
|
+
n({ x: p * p * a.x + 2 * p * d * c.x + d * d * l.x, y: p * p * a.y + 2 * p * d * c.y + d * d * l.y });
|
|
2747
|
+
}
|
|
2748
|
+
} else if (o.cmd === "C" && i && o.points.length >= 3) {
|
|
2749
|
+
const a = i, [c, l, h] = o.points, f = Math.max(6, Math.min(t, 32));
|
|
2750
|
+
for (let d = 1; d <= f; d++) {
|
|
2751
|
+
const p = d / f, g = 1 - p;
|
|
2752
|
+
n({
|
|
2753
|
+
x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p * l.x + p ** 3 * h.x,
|
|
2754
|
+
y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p * l.y + p ** 3 * h.y
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
} else o.cmd === "Z" && s && n(s);
|
|
2758
|
+
return r;
|
|
2759
|
+
}
|
|
2760
|
+
function Qt(e) {
|
|
2761
|
+
for (const t of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
2762
|
+
const r = e[t];
|
|
2763
|
+
if (m(r)) return v(r);
|
|
2764
|
+
}
|
|
2765
|
+
if (Array.isArray(e.vertices) && m(e.vertices[0])) return v(e.vertices[0]);
|
|
2766
|
+
if (Array.isArray(e.commands) && e.commands.length) {
|
|
2767
|
+
const t = e.commands.find((r) => r.points.length > 0);
|
|
2768
|
+
if (t) return v(t.points[0]);
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
function at(e) {
|
|
2772
|
+
const t = N();
|
|
2773
|
+
for (const r of e) y(t, r);
|
|
2774
|
+
return t;
|
|
2775
|
+
}
|
|
2776
|
+
function lr(e) {
|
|
2777
|
+
return { minX: e.x, minY: e.y, maxX: e.x, maxY: e.y };
|
|
2778
|
+
}
|
|
2779
|
+
function ct(e, t) {
|
|
2780
|
+
return e.minX <= t.maxX && e.maxX >= t.minX && e.minY <= t.maxY && e.maxY >= t.minY;
|
|
2781
|
+
}
|
|
2782
|
+
function hr(e, t) {
|
|
2783
|
+
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;
|
|
2784
|
+
}
|
|
2785
|
+
function fr(e, t) {
|
|
2786
|
+
return { ...e.stats, renderElapsedMs: t, backend: "webgl", primitiveCount: e.primitiveCount, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: e.gpuMemoryBytes, buildElapsedMs: e.buildElapsedMs };
|
|
2787
|
+
}
|
|
2788
|
+
function dr(e) {
|
|
2789
|
+
return {
|
|
2790
|
+
total: e.total,
|
|
2791
|
+
drawn: e.drawn,
|
|
2792
|
+
skipped: e.skipped,
|
|
2793
|
+
byType: { ...e.byType },
|
|
2794
|
+
unsupported: { ...e.unsupported },
|
|
2795
|
+
renderElapsedMs: e.renderElapsedMs,
|
|
2796
|
+
backend: e.backend,
|
|
2797
|
+
primitiveCount: e.primitiveCount,
|
|
2798
|
+
visiblePrimitiveCount: e.visiblePrimitiveCount,
|
|
2799
|
+
culledPrimitiveCount: e.culledPrimitiveCount,
|
|
2800
|
+
gpuMemoryBytes: e.gpuMemoryBytes,
|
|
2801
|
+
buildElapsedMs: e.buildElapsedMs
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
function pt(e, t, r = 1) {
|
|
2805
|
+
const i = e.trim().toLowerCase();
|
|
2806
|
+
let s;
|
|
2807
|
+
if (/^#[0-9a-f]{3}$/i.test(i))
|
|
2808
|
+
s = [parseInt(i[1] + i[1], 16), parseInt(i[2] + i[2], 16), parseInt(i[3] + i[3], 16), 255];
|
|
2809
|
+
else if (/^#[0-9a-f]{6}$/i.test(i))
|
|
2810
|
+
s = [parseInt(i.slice(1, 3), 16), parseInt(i.slice(3, 5), 16), parseInt(i.slice(5, 7), 16), 255];
|
|
2811
|
+
else {
|
|
2812
|
+
const o = i.match(/^rgba?\(([^)]+)\)$/i);
|
|
2813
|
+
if (o) {
|
|
2814
|
+
const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((h) => h.includes("%")), l = a.map((h) => Number(h.replace("%", "")));
|
|
2815
|
+
l.length >= 3 && l.slice(0, 3).every(Number.isFinite) && (s = [X(c ? l[0] * 2.55 : l[0]), X(c ? l[1] * 2.55 : l[1]), X(c ? l[2] * 2.55 : l[2]), X((Number.isFinite(l[3]) ? l[3] : 1) * 255)]);
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
const n = s ?? t;
|
|
2819
|
+
return [n[0], n[1], n[2], X(n[3] * r)];
|
|
2820
|
+
}
|
|
2821
|
+
function X(e) {
|
|
2822
|
+
return Math.max(0, Math.min(255, Math.round(e)));
|
|
2823
|
+
}
|
|
2824
|
+
class ur {
|
|
2825
|
+
constructor(t = {}) {
|
|
2826
|
+
u(this, "canvas");
|
|
2827
|
+
u(this, "renderer");
|
|
2828
|
+
u(this, "registry");
|
|
2829
|
+
u(this, "options");
|
|
2830
|
+
u(this, "lastResult");
|
|
2831
|
+
if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ?? Ke(t), t.loaders) for (const r of t.loaders) this.registry.register(r);
|
|
2832
|
+
this.canvas = t.canvas ?? document.createElement("canvas"), this.canvas.classList.add("cad-viewer-canvas"), !t.canvas && t.container && (this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", t.container.appendChild(this.canvas)), this.renderer = mr(t.renderer ?? "auto", this.canvas, t.canvasOptions), this.renderer.onStats = (r) => {
|
|
2833
|
+
var i, s;
|
|
2834
|
+
return (s = (i = this.options).onRenderStats) == null ? void 0 : s.call(i, r);
|
|
2835
|
+
}, this.renderer.onViewChange = (r) => {
|
|
2836
|
+
var i, s;
|
|
2837
|
+
return (s = (i = this.options).onViewChange) == null ? void 0 : s.call(i, r);
|
|
2838
|
+
};
|
|
2839
|
+
}
|
|
2840
|
+
registerLoader(t) {
|
|
2841
|
+
return this.registry.register(t), this;
|
|
2842
|
+
}
|
|
2843
|
+
async loadFile(t, r = {}) {
|
|
2844
|
+
var i, s, n, o;
|
|
2845
|
+
(s = (i = this.options).onLoadStart) == null || s.call(i, t);
|
|
2846
|
+
try {
|
|
2847
|
+
const a = await this.registry.load({ file: t, fileName: t.name }, this.mergeLoadOptions(r));
|
|
2848
|
+
return this.applyLoadResult(a, t.name);
|
|
2849
|
+
} catch (a) {
|
|
2850
|
+
const c = lt(a);
|
|
2851
|
+
throw (o = (n = this.options).onError) == null || o.call(n, c), c;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
async loadBuffer(t, r, i = {}) {
|
|
2855
|
+
var s, n, o, a;
|
|
2856
|
+
(n = (s = this.options).onLoadStart) == null || n.call(s, t);
|
|
2857
|
+
try {
|
|
2858
|
+
const c = await this.registry.load({ buffer: t, fileName: r }, this.mergeLoadOptions(i));
|
|
2859
|
+
return this.applyLoadResult(c, r);
|
|
2860
|
+
} catch (c) {
|
|
2861
|
+
const l = lt(c);
|
|
2862
|
+
throw (a = (o = this.options).onError) == null || a.call(o, l), l;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
async load(t, r = {}) {
|
|
2866
|
+
var i, s, n, o, a;
|
|
2867
|
+
(s = (i = this.options).onLoadStart) == null || s.call(i, t);
|
|
2868
|
+
try {
|
|
2869
|
+
const c = await this.registry.load(t, this.mergeLoadOptions(r));
|
|
2870
|
+
return this.applyLoadResult(c, t.fileName ?? ((n = t.file) == null ? void 0 : n.name));
|
|
2871
|
+
} catch (c) {
|
|
2872
|
+
const l = lt(c);
|
|
2873
|
+
throw (a = (o = this.options).onError) == null || a.call(o, l), l;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
setDocument(t, r) {
|
|
2877
|
+
var s, n;
|
|
2878
|
+
const i = {
|
|
2879
|
+
document: t,
|
|
2880
|
+
raw: t.raw,
|
|
2881
|
+
bytes: 0,
|
|
2882
|
+
elapsedMs: 0,
|
|
2883
|
+
format: t.format,
|
|
2884
|
+
warnings: t.warnings,
|
|
2885
|
+
summary: kt(t),
|
|
2886
|
+
fileName: r
|
|
2887
|
+
};
|
|
2888
|
+
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;
|
|
2889
|
+
}
|
|
2890
|
+
fit() {
|
|
2891
|
+
this.renderer.fitToView();
|
|
2892
|
+
}
|
|
2893
|
+
zoomIn() {
|
|
2894
|
+
this.renderer.zoomIn();
|
|
2895
|
+
}
|
|
2896
|
+
zoomOut() {
|
|
2897
|
+
this.renderer.zoomOut();
|
|
2898
|
+
}
|
|
2899
|
+
resize() {
|
|
2900
|
+
this.renderer.resize();
|
|
2901
|
+
}
|
|
2902
|
+
setCanvasOptions(t) {
|
|
2903
|
+
this.renderer.setOptions(t);
|
|
2904
|
+
}
|
|
2905
|
+
async preloadDwg(t = {}) {
|
|
2906
|
+
const r = this.registry.list().find((i) => i.id === "dwg");
|
|
2907
|
+
if (!(r != null && r.preload)) throw new Error("The registered DWG loader does not support preload().");
|
|
2908
|
+
return r.preload(this.mergeLoadOptions(t));
|
|
2909
|
+
}
|
|
2910
|
+
clear() {
|
|
2911
|
+
this.lastResult = void 0, this.renderer.clear();
|
|
2912
|
+
}
|
|
2913
|
+
destroy() {
|
|
2914
|
+
var t, r;
|
|
2915
|
+
for (const i of this.registry.list()) {
|
|
2916
|
+
const s = i;
|
|
2917
|
+
(t = s.terminateWorker) == null || t.call(s), (r = s.destroy) == null || r.call(s);
|
|
2918
|
+
}
|
|
2919
|
+
this.renderer.destroy();
|
|
2920
|
+
}
|
|
2921
|
+
getLoadResult() {
|
|
2922
|
+
return this.lastResult;
|
|
2923
|
+
}
|
|
2924
|
+
getDocument() {
|
|
2925
|
+
return this.renderer.getDocument();
|
|
2926
|
+
}
|
|
2927
|
+
getZoomPercent() {
|
|
2928
|
+
return this.renderer.getZoomPercent();
|
|
2929
|
+
}
|
|
2930
|
+
applyLoadResult(t, r) {
|
|
2931
|
+
var s, n, o, a;
|
|
2932
|
+
(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();
|
|
2933
|
+
const i = {
|
|
2934
|
+
...t,
|
|
2935
|
+
fileName: r,
|
|
2936
|
+
summary: kt(t.document)
|
|
2937
|
+
};
|
|
2938
|
+
return this.lastResult = i, (a = (o = this.options).onLoad) == null || a.call(o, i), i;
|
|
2939
|
+
}
|
|
2940
|
+
mergeLoadOptions(t) {
|
|
2941
|
+
const r = this.options.onProgress, i = t.onProgress;
|
|
2942
|
+
return {
|
|
2943
|
+
...this.options,
|
|
2944
|
+
...t,
|
|
2945
|
+
onProgress: (s) => {
|
|
2946
|
+
var n, o;
|
|
2947
|
+
(o = (n = this.options).onLoadProgress) == null || o.call(n, s), r == null || r(s), i && i !== r && i(s);
|
|
2948
|
+
}
|
|
2949
|
+
};
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
function br(e = {}) {
|
|
2953
|
+
return new ur(e);
|
|
2954
|
+
}
|
|
2955
|
+
function lt(e) {
|
|
2956
|
+
return e instanceof Error ? e : new Error(String(e));
|
|
2957
|
+
}
|
|
2958
|
+
function mr(e, t, r = {}) {
|
|
2959
|
+
if (e === "canvas2d") return new Ft(t, r);
|
|
2960
|
+
if (e === "webgl") return new Dt(t, r);
|
|
2961
|
+
if (Kt())
|
|
2962
|
+
try {
|
|
2963
|
+
return new Dt(t, r);
|
|
2964
|
+
} catch {
|
|
2965
|
+
}
|
|
2966
|
+
return new Ft(t, r);
|
|
2967
|
+
}
|
|
2968
|
+
export {
|
|
2969
|
+
Ft as CadCanvasRenderer,
|
|
2970
|
+
ie as CadLoaderRegistry,
|
|
2971
|
+
ur as CadViewer,
|
|
2972
|
+
Dt as CadWebGLRenderer,
|
|
2973
|
+
ze as DwfLoader,
|
|
2974
|
+
mt as DwfUnsupportedError,
|
|
2975
|
+
le as DwgLoader,
|
|
2976
|
+
se as DwgWorkerClient,
|
|
2977
|
+
pe as DxfLoader,
|
|
2978
|
+
T as colorFromAci,
|
|
2979
|
+
H as colorFromTrueColor,
|
|
2980
|
+
Xt as createCadDocument,
|
|
2981
|
+
br as createCadViewer,
|
|
2982
|
+
Ke as createDefaultLoaderRegistry,
|
|
2983
|
+
rt as detectCadFormat,
|
|
2984
|
+
O as inferEntityKind,
|
|
2985
|
+
Kt as isWebGLAvailable,
|
|
2986
|
+
de as normalizeCadEntity,
|
|
2987
|
+
et as readInputBytes,
|
|
2988
|
+
D as resolveCadColor,
|
|
2989
|
+
kt as summarizeCadDocument,
|
|
2990
|
+
ht as supportsDwgWorker
|
|
2991
|
+
};
|
|
2992
|
+
//# sourceMappingURL=cad-viewer.es.js.map
|