@flyfish-dev/cad-viewer 0.5.3 → 0.6.1
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 +215 -641
- package/NOTICE +3 -5
- package/README.md +42 -20
- package/README.zh-CN.md +41 -19
- package/dist/cad-viewer.es.js +850 -805
- package/dist/cad-viewer.es.js.map +1 -1
- package/dist/cad-viewer.umd.cjs +4 -4
- package/dist/cad-viewer.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/core/types.d.ts +39 -1
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loaders/dwf/DwfLoader.d.ts +16 -7
- package/dist/types/loaders/dwf/DwfLoader.d.ts.map +1 -1
- package/dist/types/loaders/index.d.ts +1 -1
- package/dist/types/loaders/index.d.ts.map +1 -1
- package/dist/types/viewer/CadViewer.d.ts +11 -2
- package/dist/types/viewer/CadViewer.d.ts.map +1 -1
- package/dist/wasm/dwfv-render.wasm +0 -0
- package/package.json +12 -7
package/dist/cad-viewer.es.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
async function
|
|
1
|
+
var Kt = Object.defineProperty;
|
|
2
|
+
var Jt = (e, t, r) => t in e ? Kt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var d = (e, t, r) => Jt(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { openDwfDocument as Qt, DwfViewer as te } from "dwf-viewer";
|
|
5
|
+
async function _(e) {
|
|
6
6
|
if (e.buffer instanceof Uint8Array) return e.buffer;
|
|
7
7
|
if (e.buffer instanceof ArrayBuffer) return new Uint8Array(e.buffer);
|
|
8
8
|
if (e.file) return new Uint8Array(await e.file.arrayBuffer());
|
|
9
9
|
throw new Error("CadLoadInput requires a File, ArrayBuffer, or Uint8Array.");
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function ee(e) {
|
|
12
12
|
return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function L(e) {
|
|
15
15
|
var i;
|
|
16
16
|
const t = e.fileName ?? ((i = e.file) == null ? void 0 : i.name) ?? "", r = t.lastIndexOf(".");
|
|
17
17
|
return r >= 0 ? t.slice(r + 1).toLowerCase() : "";
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const r =
|
|
19
|
+
function A(e, t) {
|
|
20
|
+
const r = L(e);
|
|
21
21
|
if (r === "dwg") return "dwg";
|
|
22
22
|
if (r === "dxf") return "dxf";
|
|
23
23
|
if (r === "dwfx") return "dwfx";
|
|
@@ -36,12 +36,9 @@ function rt(e, t) {
|
|
|
36
36
|
function vt(e) {
|
|
37
37
|
return Array.from(e, (t) => t >= 32 && t <= 126 ? String.fromCharCode(t) : " ").join("");
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
return new TextDecoder("utf-8").decode(e);
|
|
41
|
-
}
|
|
42
|
-
class ie {
|
|
39
|
+
class re {
|
|
43
40
|
constructor(t = []) {
|
|
44
|
-
|
|
41
|
+
d(this, "loaders", []);
|
|
45
42
|
for (const r of t) this.register(r);
|
|
46
43
|
}
|
|
47
44
|
register(t) {
|
|
@@ -56,7 +53,7 @@ class ie {
|
|
|
56
53
|
return [...this.loaders];
|
|
57
54
|
}
|
|
58
55
|
async detect(t) {
|
|
59
|
-
const r = await
|
|
56
|
+
const r = await _(t), i = A(t, r), s = this.loaders.find((o) => o.formats.includes(i) && o.accepts(t, r));
|
|
60
57
|
if (s) return { loader: s, bytes: r, format: i };
|
|
61
58
|
const n = this.loaders.find((o) => o.accepts(t, r));
|
|
62
59
|
if (n) return { loader: n, bytes: r, format: i };
|
|
@@ -67,27 +64,27 @@ class ie {
|
|
|
67
64
|
return i.load({ ...t, buffer: s }, r);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
class
|
|
67
|
+
class ie {
|
|
71
68
|
constructor() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
d(this, "worker");
|
|
70
|
+
d(this, "sequence", 0);
|
|
71
|
+
d(this, "pending", /* @__PURE__ */ new Map());
|
|
75
72
|
}
|
|
76
73
|
load(t, r, i = {}) {
|
|
77
|
-
var
|
|
78
|
-
if (!
|
|
79
|
-
const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((
|
|
80
|
-
return (
|
|
74
|
+
var h, l;
|
|
75
|
+
if (!lt()) throw new Error("Web Worker is not available in this runtime.");
|
|
76
|
+
const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((h = r.file) == null ? void 0 : h.name), c = ne(t, r, i);
|
|
77
|
+
return (l = i.onProgress) == null || l.call(i, { phase: "worker-start", format: "dwg", message: "Dispatching DWG parse to worker…", total: t.byteLength }), new Promise((f, u) => {
|
|
81
78
|
var g;
|
|
82
79
|
if ((g = i.signal) != null && g.aborted) {
|
|
83
|
-
|
|
80
|
+
u($());
|
|
84
81
|
return;
|
|
85
82
|
}
|
|
86
|
-
const p = { resolve: f, reject:
|
|
83
|
+
const p = { resolve: f, reject: u, onProgress: i.onProgress, signal: i.signal };
|
|
87
84
|
o > 0 && (p.timer = setTimeout(() => {
|
|
88
|
-
this.pending.delete(n), this.resetWorker(),
|
|
85
|
+
this.pending.delete(n), this.resetWorker(), u(new Error(`DWG worker timed out after ${o} ms.`));
|
|
89
86
|
}, o)), i.signal && (p.abortHandler = () => {
|
|
90
|
-
this.pending.delete(n), this.resetWorker(),
|
|
87
|
+
this.pending.delete(n), this.resetWorker(), u($());
|
|
91
88
|
}, i.signal.addEventListener("abort", p.abortHandler, { once: !0 })), this.pending.set(n, p);
|
|
92
89
|
try {
|
|
93
90
|
s.postMessage({
|
|
@@ -95,21 +92,21 @@ class se {
|
|
|
95
92
|
requestId: n,
|
|
96
93
|
bytes: c,
|
|
97
94
|
fileName: a,
|
|
98
|
-
options:
|
|
95
|
+
options: yt(i)
|
|
99
96
|
}, [c]);
|
|
100
97
|
} catch (S) {
|
|
101
|
-
this.pending.delete(n),
|
|
98
|
+
this.pending.delete(n), V(p), u(S instanceof Error ? S : new Error(String(S)));
|
|
102
99
|
}
|
|
103
100
|
});
|
|
104
101
|
}
|
|
105
102
|
preload(t = {}) {
|
|
106
103
|
var n;
|
|
107
|
-
if (!
|
|
104
|
+
if (!lt()) return Promise.reject(new Error("Web Worker is not available in this runtime."));
|
|
108
105
|
const r = this.ensureWorker(t), i = ++this.sequence, s = Math.max(0, Number(t.workerTimeoutMs ?? 0));
|
|
109
106
|
return (n = t.onProgress) == null || n.call(t, { phase: "worker-start", format: "dwg", message: "Starting DWG worker warmup…" }), new Promise((o, a) => {
|
|
110
|
-
var
|
|
111
|
-
if ((
|
|
112
|
-
a(
|
|
107
|
+
var h;
|
|
108
|
+
if ((h = t.signal) != null && h.aborted) {
|
|
109
|
+
a($());
|
|
113
110
|
return;
|
|
114
111
|
}
|
|
115
112
|
const c = {
|
|
@@ -121,12 +118,12 @@ class se {
|
|
|
121
118
|
s > 0 && (c.timer = setTimeout(() => {
|
|
122
119
|
this.pending.delete(i), this.resetWorker(), a(new Error(`DWG worker warmup timed out after ${s} ms.`));
|
|
123
120
|
}, s)), t.signal && (c.abortHandler = () => {
|
|
124
|
-
this.pending.delete(i), this.resetWorker(), a(
|
|
121
|
+
this.pending.delete(i), this.resetWorker(), a($());
|
|
125
122
|
}, t.signal.addEventListener("abort", c.abortHandler, { once: !0 })), this.pending.set(i, c);
|
|
126
123
|
try {
|
|
127
|
-
r.postMessage({ type: "warmup", requestId: i, options:
|
|
128
|
-
} catch (
|
|
129
|
-
this.pending.delete(i),
|
|
124
|
+
r.postMessage({ type: "warmup", requestId: i, options: yt(t) });
|
|
125
|
+
} catch (l) {
|
|
126
|
+
this.pending.delete(i), V(c), a(l instanceof Error ? l : new Error(String(l)));
|
|
130
127
|
}
|
|
131
128
|
});
|
|
132
129
|
}
|
|
@@ -134,7 +131,7 @@ class se {
|
|
|
134
131
|
this.resetWorker();
|
|
135
132
|
}
|
|
136
133
|
ensureWorker(t) {
|
|
137
|
-
return this.worker || (this.worker =
|
|
134
|
+
return this.worker || (this.worker = se(t), this.worker.onmessage = (r) => this.handleMessage(r.data), this.worker.onerror = (r) => {
|
|
138
135
|
const i = r.message || "DWG worker failed.";
|
|
139
136
|
this.rejectAll(new Error(i)), this.resetWorker(!1);
|
|
140
137
|
}, this.worker.onmessageerror = () => {
|
|
@@ -150,7 +147,7 @@ class se {
|
|
|
150
147
|
(s = r.onProgress) == null || s.call(r, t.progress);
|
|
151
148
|
return;
|
|
152
149
|
}
|
|
153
|
-
if (this.pending.delete(t.requestId),
|
|
150
|
+
if (this.pending.delete(t.requestId), V(r), t.type === "result") {
|
|
154
151
|
r.resolve(t.result);
|
|
155
152
|
return;
|
|
156
153
|
}
|
|
@@ -163,7 +160,7 @@ class se {
|
|
|
163
160
|
}
|
|
164
161
|
rejectAll(t) {
|
|
165
162
|
for (const [, r] of this.pending)
|
|
166
|
-
|
|
163
|
+
V(r), r.reject(t);
|
|
167
164
|
this.pending.clear();
|
|
168
165
|
}
|
|
169
166
|
resetWorker(t = !0) {
|
|
@@ -171,77 +168,77 @@ class se {
|
|
|
171
168
|
t && this.rejectAll(new Error("DWG worker was terminated.")), (r = this.worker) == null || r.terminate(), this.worker = void 0;
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
|
-
function
|
|
171
|
+
function lt() {
|
|
175
172
|
return typeof Worker < "u" && typeof URL < "u";
|
|
176
173
|
}
|
|
177
|
-
function
|
|
174
|
+
function se(e) {
|
|
178
175
|
return e.workerFactory ? e.workerFactory() : e.workerUrl ? new Worker(e.workerUrl, { type: "module", name: "lightweight-cad-dwg-loader" }) : new Worker(new URL(
|
|
179
176
|
/* @vite-ignore */
|
|
180
177
|
"/assets/DwgWorker-CuZJ5EUe.js",
|
|
181
178
|
import.meta.url
|
|
182
179
|
), { type: "module", name: "lightweight-cad-dwg-loader" });
|
|
183
180
|
}
|
|
184
|
-
function
|
|
181
|
+
function yt(e) {
|
|
185
182
|
return {
|
|
186
183
|
// Resolve the asset directory on the UI thread. Relative paths such as
|
|
187
184
|
// './wasm' must be relative to the document URL, not to the generated
|
|
188
185
|
// worker chunk URL. Otherwise the worker may request /assets/wasm/... and
|
|
189
186
|
// receive the app's HTML fallback instead of libredwg-web.wasm.
|
|
190
|
-
wasmPath:
|
|
187
|
+
wasmPath: oe(e.wasmPath),
|
|
191
188
|
includePaperSpace: e.includePaperSpace,
|
|
192
189
|
maxInsertDepth: e.maxInsertDepth,
|
|
193
190
|
keepRaw: !!e.keepRaw
|
|
194
191
|
};
|
|
195
192
|
}
|
|
196
|
-
function
|
|
197
|
-
return !!t.file || r.transferInputBuffer === !0 ?
|
|
193
|
+
function ne(e, t, r) {
|
|
194
|
+
return !!t.file || r.transferInputBuffer === !0 ? ee(e) : e.slice().buffer;
|
|
198
195
|
}
|
|
199
|
-
function
|
|
196
|
+
function V(e) {
|
|
200
197
|
e.timer && clearTimeout(e.timer), e.signal && e.abortHandler && e.signal.removeEventListener("abort", e.abortHandler);
|
|
201
198
|
}
|
|
202
|
-
function
|
|
199
|
+
function $() {
|
|
203
200
|
if (typeof DOMException < "u") return new DOMException("DWG loading was aborted.", "AbortError");
|
|
204
201
|
const e = new Error("DWG loading was aborted.");
|
|
205
202
|
return e.name = "AbortError", e;
|
|
206
203
|
}
|
|
207
|
-
function
|
|
204
|
+
function oe(e) {
|
|
208
205
|
const t = ((e == null ? void 0 : e.trim()) || "/wasm").replace(/\/+$/, "");
|
|
209
|
-
return t === "" ?
|
|
206
|
+
return t === "" ? xt() : ae(t) ? t : t.startsWith("/") ? `${xt()}${t}` : new URL(t, Ot()).href.replace(/\/+$/, "");
|
|
210
207
|
}
|
|
211
|
-
function
|
|
208
|
+
function Ot() {
|
|
212
209
|
return typeof document < "u" && document.baseURI ? document.baseURI : typeof location < "u" && location.href ? location.href : "http://localhost/";
|
|
213
210
|
}
|
|
214
|
-
function
|
|
215
|
-
return typeof location < "u" && location.origin ? location.origin : new URL(
|
|
211
|
+
function xt() {
|
|
212
|
+
return typeof location < "u" && location.origin ? location.origin : new URL(Ot()).origin;
|
|
216
213
|
}
|
|
217
|
-
function
|
|
214
|
+
function ae(e) {
|
|
218
215
|
return /^[a-z][a-z0-9+.-]*:/i.test(e);
|
|
219
216
|
}
|
|
220
|
-
class
|
|
217
|
+
class ce {
|
|
221
218
|
constructor(t = {}) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
d(this, "id", "dwg");
|
|
220
|
+
d(this, "label", "DWG / LibreDWG WebAssembly");
|
|
221
|
+
d(this, "formats", ["dwg"]);
|
|
222
|
+
d(this, "defaults");
|
|
223
|
+
d(this, "workerClient", new ie());
|
|
227
224
|
this.defaults = { useWorker: !0, ...t };
|
|
228
225
|
}
|
|
229
226
|
accepts(t, r) {
|
|
230
|
-
return
|
|
227
|
+
return L(t) === "dwg" ? !0 : A(t, r) === "dwg";
|
|
231
228
|
}
|
|
232
229
|
async load(t, r = {}) {
|
|
233
230
|
var o, a;
|
|
234
231
|
const i = { ...this.defaults, ...r };
|
|
235
232
|
(o = i.onProgress) == null || o.call(i, { phase: "read", format: "dwg", message: "Reading DWG bytes…" });
|
|
236
|
-
const s = await
|
|
233
|
+
const s = await _(t), n = t.fileName ?? ((a = t.file) == null ? void 0 : a.name);
|
|
237
234
|
if (i.useWorker === !1)
|
|
238
235
|
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 (!
|
|
236
|
+
if (!lt())
|
|
240
237
|
throw new Error("DWG loading requires Web Worker support in this build. Provide a custom loader for this runtime.");
|
|
241
238
|
try {
|
|
242
239
|
return await this.workerClient.load(s, t, { ...i, fileName: n });
|
|
243
240
|
} catch (c) {
|
|
244
|
-
throw he(c) ? c :
|
|
241
|
+
throw he(c) ? c : le(c);
|
|
245
242
|
}
|
|
246
243
|
}
|
|
247
244
|
terminateWorker() {
|
|
@@ -255,11 +252,11 @@ class le {
|
|
|
255
252
|
function he(e) {
|
|
256
253
|
return e instanceof Error && e.name === "AbortError";
|
|
257
254
|
}
|
|
258
|
-
function
|
|
255
|
+
function le(e) {
|
|
259
256
|
const t = e instanceof Error ? e.message : String(e);
|
|
260
257
|
return new Error(`${t} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`);
|
|
261
258
|
}
|
|
262
|
-
function
|
|
259
|
+
function zt(e) {
|
|
263
260
|
return {
|
|
264
261
|
format: e.format,
|
|
265
262
|
sourceName: e.sourceName,
|
|
@@ -274,7 +271,7 @@ function Xt(e) {
|
|
|
274
271
|
raw: e.raw
|
|
275
272
|
};
|
|
276
273
|
}
|
|
277
|
-
function
|
|
274
|
+
function R(e) {
|
|
278
275
|
switch (String(e ?? "").toUpperCase()) {
|
|
279
276
|
case "LINE":
|
|
280
277
|
return "line";
|
|
@@ -325,42 +322,42 @@ function O(e) {
|
|
|
325
322
|
return "unsupported";
|
|
326
323
|
}
|
|
327
324
|
}
|
|
328
|
-
function
|
|
329
|
-
const i = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), s = r.includeUnknownProperties === !1 ? { type: i, kind:
|
|
330
|
-
r.keepRaw && (s.raw = e), s.handle =
|
|
331
|
-
const n = r.numericColorMode ?? "auto", o =
|
|
325
|
+
function fe(e, t, r = {}) {
|
|
326
|
+
const i = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), s = r.includeUnknownProperties === !1 ? { type: i, kind: R(i) } : { ...e, type: i, kind: R(i) };
|
|
327
|
+
r.keepRaw && (s.raw = e), s.handle = C(e.handle ?? e.id), s.layer = C(e.layer ?? e.layerName), s.lineType = C(e.lineType ?? e.linetype);
|
|
328
|
+
const n = r.numericColorMode ?? "auto", o = y(e.color), a = y(e.colorIndex ?? e.colorNumber ?? e.aci ?? e.aciColor ?? e.color_index);
|
|
332
329
|
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,
|
|
334
|
-
s.trueColor = c ?? (
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
const f =
|
|
330
|
+
const c = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb, h = o !== void 0 && o >= 0 && o <= 16777215 && (n === "rgb" || n === "auto" && Math.abs(o) > 257);
|
|
331
|
+
s.trueColor = c ?? (h ? o : void 0), (typeof e.color == "string" || typeof e.color == "number") && (s.color = e.color), s.colorNumber = y(e.colorNumber) ?? s.colorNumber, s.colorName = C(e.colorName ?? e.color_name) ?? s.colorName, s.fillColor = e.fillColor ?? e.fill_color, s.fillColorIndex = y(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? s.fillColorIndex, s.opacity = y(e.opacity ?? e.alpha) ?? s.opacity, s.lineweight = y(e.lineweight ?? e.lineWeight), s.isVisible = !(e.isVisible === !1 || e.visible === !1), s.startPoint = P(e.startPoint ?? e.start ?? e.p0 ?? e.from) ?? s.startPoint, s.endPoint = P(e.endPoint ?? e.end ?? e.p1 ?? e.to) ?? s.endPoint, s.center = P(e.center ?? e.centerPoint) ?? s.center, s.insertionPoint = P(e.insertionPoint ?? e.position ?? e.location ?? e.point ?? e.basePoint) ?? s.insertionPoint, s.radius = y(e.radius) ?? s.radius, s.startAngle = y(e.startAngle ?? e.start_angle) ?? s.startAngle, s.endAngle = y(e.endAngle ?? e.end_angle) ?? s.endAngle, s.majorAxisEndPoint = P(e.majorAxisEndPoint ?? e.majorAxis ?? e.major) ?? s.majorAxisEndPoint, s.axisRatio = y(e.axisRatio ?? e.ratio) ?? s.axisRatio, s.height = y(e.height ?? e.textHeight) ?? s.height, s.textHeight = y(e.textHeight ?? e.height) ?? s.textHeight, s.rotation = y(e.rotation ?? e.angle) ?? s.rotation, s.text = C(e.text ?? e.value ?? e.string ?? e.contents) ?? s.text, s.name = C(e.name ?? e.blockName) ?? s.name, s.blockName = C(e.blockName ?? e.name) ?? s.blockName;
|
|
332
|
+
const l = et(e.vertices ?? e.points);
|
|
333
|
+
l.length > 0 && (s.vertices = l);
|
|
334
|
+
const f = et(e.controlPoints ?? e.control_points);
|
|
338
335
|
f.length > 0 && (s.controlPoints = f);
|
|
339
|
-
const
|
|
340
|
-
return
|
|
336
|
+
const u = et(e.fitPoints ?? e.fit_points);
|
|
337
|
+
return u.length > 0 && (s.fitPoints = u), s;
|
|
341
338
|
}
|
|
342
|
-
function
|
|
339
|
+
function P(e) {
|
|
343
340
|
if (!e || typeof e != "object") return;
|
|
344
341
|
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
342
|
if (!(!Number.isFinite(r) || !Number.isFinite(i)))
|
|
346
343
|
return Number.isFinite(n) ? { x: r, y: i, z: n } : { x: r, y: i };
|
|
347
344
|
}
|
|
348
|
-
function
|
|
345
|
+
function et(e) {
|
|
349
346
|
if (!Array.isArray(e)) return [];
|
|
350
347
|
const t = [];
|
|
351
348
|
for (const r of e) {
|
|
352
|
-
const i =
|
|
349
|
+
const i = P(r);
|
|
353
350
|
if (!i) continue;
|
|
354
|
-
const s = r, n = i, o =
|
|
351
|
+
const s = r, n = i, o = y(s.bulge);
|
|
355
352
|
o !== void 0 && (n.bulge = o);
|
|
356
|
-
const a =
|
|
353
|
+
const a = y(s.startWidth ?? s.start_width);
|
|
357
354
|
a !== void 0 && (n.startWidth = a);
|
|
358
|
-
const c =
|
|
355
|
+
const c = y(s.endWidth ?? s.end_width);
|
|
359
356
|
c !== void 0 && (n.endWidth = c), t.push(n);
|
|
360
357
|
}
|
|
361
358
|
return t;
|
|
362
359
|
}
|
|
363
|
-
function
|
|
360
|
+
function j(e) {
|
|
364
361
|
var r;
|
|
365
362
|
const t = {};
|
|
366
363
|
for (const i of e.entities) {
|
|
@@ -378,124 +375,124 @@ function kt(e) {
|
|
|
378
375
|
warnings: [...e.warnings]
|
|
379
376
|
};
|
|
380
377
|
}
|
|
381
|
-
function
|
|
378
|
+
function wt(e, t) {
|
|
382
379
|
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
383
380
|
}
|
|
384
|
-
function
|
|
381
|
+
function de(e, t) {
|
|
385
382
|
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
386
383
|
}
|
|
387
|
-
function
|
|
384
|
+
function ue(e) {
|
|
388
385
|
return e != null && e.length ? e.flatMap((t) => t.entities.map((r) => ({ ...r, pageIndex: t.index }))) : [];
|
|
389
386
|
}
|
|
390
|
-
function
|
|
387
|
+
function y(e) {
|
|
391
388
|
const t = Number(e);
|
|
392
389
|
return Number.isFinite(t) ? t : void 0;
|
|
393
390
|
}
|
|
394
|
-
function
|
|
391
|
+
function C(e) {
|
|
395
392
|
if (typeof e != "string" && typeof e != "number") return;
|
|
396
393
|
const t = String(e);
|
|
397
394
|
return t.length > 0 ? t : void 0;
|
|
398
395
|
}
|
|
399
|
-
function
|
|
396
|
+
function M() {
|
|
400
397
|
return { minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
|
|
401
398
|
}
|
|
402
|
-
function
|
|
399
|
+
function D(e) {
|
|
403
400
|
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
401
|
}
|
|
405
|
-
function
|
|
402
|
+
function v(e, t) {
|
|
406
403
|
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
404
|
}
|
|
408
405
|
function Yt(e, t, r) {
|
|
409
406
|
if (!m(t) || !Number.isFinite(r)) return;
|
|
410
407
|
const i = Math.abs(r);
|
|
411
|
-
|
|
408
|
+
v(e, { x: t.x - i, y: t.y - i }), v(e, { x: t.x + i, y: t.y + i });
|
|
412
409
|
}
|
|
413
410
|
function Ht(e, t = 0.02, r = 1e-6) {
|
|
414
|
-
if (!
|
|
411
|
+
if (!D(e)) return { minX: -10, minY: -10, maxX: 10, maxY: 10 };
|
|
415
412
|
const i = Math.max((e.maxX - e.minX) * t, r), s = Math.max((e.maxY - e.minY) * t, r);
|
|
416
413
|
return { minX: e.minX - i, minY: e.minY - s, maxX: e.maxX + i, maxY: e.maxY + s };
|
|
417
414
|
}
|
|
418
415
|
function m(e) {
|
|
419
416
|
return !!e && typeof e == "object" && Number.isFinite(e.x) && Number.isFinite(e.y);
|
|
420
417
|
}
|
|
421
|
-
function
|
|
418
|
+
function x(e) {
|
|
422
419
|
return { x: e.x, y: e.y };
|
|
423
420
|
}
|
|
424
|
-
function
|
|
421
|
+
function E(e) {
|
|
425
422
|
return e * Math.PI / 180;
|
|
426
423
|
}
|
|
427
|
-
function
|
|
424
|
+
function q(e, t, r, i, s = !0, n = 64) {
|
|
428
425
|
if (!m(e) || !Number.isFinite(t)) return [];
|
|
429
426
|
let o = r, a = i;
|
|
430
427
|
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 =
|
|
432
|
-
const c = a - o,
|
|
433
|
-
for (let f = 0; f <=
|
|
434
|
-
const
|
|
435
|
-
|
|
428
|
+
(Math.abs(o) > Math.PI * 2 + 1e-6 || Math.abs(a) > Math.PI * 2 + 1e-6) && (o = E(o), a = E(a)), s && a < o && (a += Math.PI * 2), !s && o < a && (o += Math.PI * 2);
|
|
429
|
+
const c = a - o, h = Math.max(8, Math.min(256, Math.ceil(Math.abs(c) / (Math.PI * 2) * n))), l = [];
|
|
430
|
+
for (let f = 0; f <= h; f++) {
|
|
431
|
+
const u = o + c * (f / h);
|
|
432
|
+
l.push({ x: e.x + Math.cos(u) * t, y: e.y + Math.sin(u) * t });
|
|
436
433
|
}
|
|
437
|
-
return
|
|
434
|
+
return l;
|
|
438
435
|
}
|
|
439
|
-
function
|
|
436
|
+
function K(e, t, r = 1, i = 0, s = Math.PI * 2, n = 96) {
|
|
440
437
|
if (!m(e) || !m(t)) return [];
|
|
441
438
|
const o = Math.hypot(t.x, t.y);
|
|
442
439
|
if (!Number.isFinite(o) || o <= 0) return [];
|
|
443
440
|
const a = o * (Number.isFinite(r) && r > 0 ? r : 1), c = Math.atan2(t.y, t.x);
|
|
444
|
-
let
|
|
445
|
-
(Math.abs(
|
|
446
|
-
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(
|
|
441
|
+
let h = Number.isFinite(i) ? i : 0, l = Number.isFinite(s) ? s : Math.PI * 2;
|
|
442
|
+
(Math.abs(h) > Math.PI * 2 + 1e-6 || Math.abs(l) > Math.PI * 2 + 1e-6) && (h = E(h), l = E(l)), l < h && (l += Math.PI * 2);
|
|
443
|
+
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(l - h) / (Math.PI * 2) * n))), u = [], p = Math.cos(c), g = Math.sin(c);
|
|
447
444
|
for (let S = 0; S <= f; S++) {
|
|
448
|
-
const
|
|
449
|
-
|
|
445
|
+
const O = h + (l - h) * (S / f), z = Math.cos(O) * o, Y = Math.sin(O) * a;
|
|
446
|
+
u.push({ x: e.x + z * p - Y * g, y: e.y + z * g + Y * p });
|
|
450
447
|
}
|
|
451
|
-
return
|
|
448
|
+
return u;
|
|
452
449
|
}
|
|
453
|
-
function
|
|
454
|
-
if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [
|
|
450
|
+
function Xt(e, t, r = 0, i = 16) {
|
|
451
|
+
if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [x(e), x(t)];
|
|
455
452
|
const s = Math.hypot(t.x - e.x, t.y - e.y);
|
|
456
|
-
if (s <= 1e-12) return [
|
|
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,
|
|
458
|
-
return
|
|
453
|
+
if (s <= 1e-12) return [x(e), x(t)];
|
|
454
|
+
const n = 4 * Math.atan(r), o = Math.abs(s / (2 * Math.sin(n / 2))), a = { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 }, c = (t.x - e.x) / s, h = (t.y - e.y) / s, l = r >= 0 ? 1 : -1, f = Math.sqrt(Math.max(o * o - (s / 2) ** 2, 0)), u = { x: a.x - l * h * f, y: a.y + l * c * f }, p = Math.atan2(e.y - u.y, e.x - u.x), g = Math.atan2(t.y - u.y, t.x - u.x);
|
|
455
|
+
return q(u, o, p, g, r >= 0, i);
|
|
459
456
|
}
|
|
460
|
-
function
|
|
457
|
+
function _t(e) {
|
|
461
458
|
return e.replace(/\\P/g, `
|
|
462
459
|
`).replace(/\\~|\\ /g, " ").replace(/\\[A-Za-z][^;]*;/g, "").replace(/[{}]/g, "").replace(/\\[A-Za-z]/g, "").trim();
|
|
463
460
|
}
|
|
464
|
-
function
|
|
461
|
+
function T(e, t, r) {
|
|
465
462
|
return Math.min(r, Math.max(t, e));
|
|
466
463
|
}
|
|
467
|
-
class
|
|
464
|
+
class me {
|
|
468
465
|
constructor(t = {}) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
466
|
+
d(this, "id", "dxf");
|
|
467
|
+
d(this, "label", "DXF / JavaScript parser");
|
|
468
|
+
d(this, "formats", ["dxf"]);
|
|
469
|
+
d(this, "defaults");
|
|
473
470
|
this.defaults = t;
|
|
474
471
|
}
|
|
475
472
|
accepts(t, r) {
|
|
476
|
-
return
|
|
473
|
+
return L(t) === "dxf" || A(t, r) === "dxf";
|
|
477
474
|
}
|
|
478
475
|
async load(t, r = {}) {
|
|
479
|
-
var
|
|
476
|
+
var l;
|
|
480
477
|
({ ...this.defaults, ...r });
|
|
481
|
-
const i = performance.now(), s = await
|
|
478
|
+
const i = performance.now(), s = await _(t), n = Ce(s), o = [];
|
|
482
479
|
let a;
|
|
483
480
|
try {
|
|
484
|
-
a = await
|
|
481
|
+
a = await pe(n);
|
|
485
482
|
} catch (f) {
|
|
486
|
-
o.push(`dxf-parser failed, using built-in fallback parser: ${f instanceof Error ? f.message : String(f)}`), a =
|
|
483
|
+
o.push(`dxf-parser failed, using built-in fallback parser: ${f instanceof Error ? f.message : String(f)}`), a = Pe(n);
|
|
487
484
|
}
|
|
488
|
-
const c =
|
|
489
|
-
return { document: c, raw: a, bytes: s.byteLength, elapsedMs:
|
|
485
|
+
const c = ge(a, t.fileName ?? ((l = t.file) == null ? void 0 : l.name), o), h = performance.now() - i;
|
|
486
|
+
return { document: c, raw: a, bytes: s.byteLength, elapsedMs: h, format: "dxf", warnings: c.warnings };
|
|
490
487
|
}
|
|
491
488
|
}
|
|
492
|
-
async function
|
|
489
|
+
async function pe(e) {
|
|
493
490
|
const t = await import("dxf-parser"), r = t.default ?? t.DxfParser;
|
|
494
491
|
if (!r) throw new Error("dxf-parser did not expose a parser constructor.");
|
|
495
492
|
return new r().parseSync(e);
|
|
496
493
|
}
|
|
497
|
-
function
|
|
498
|
-
const i = e && typeof e == "object" ? e : {}, s =
|
|
494
|
+
function ge(e, t, r = []) {
|
|
495
|
+
const i = e && typeof e == "object" ? e : {}, s = be(i), n = ve(i), a = (Array.isArray(i.entities) ? i.entities : []).filter((h) => !!h && typeof h == "object").map((h) => pt(h)), c = zt({
|
|
499
496
|
format: "dxf",
|
|
500
497
|
sourceName: t,
|
|
501
498
|
header: i.header && typeof i.header == "object" ? i.header : {},
|
|
@@ -508,119 +505,119 @@ function be(e, t, r = []) {
|
|
|
508
505
|
});
|
|
509
506
|
return a.length === 0 && c.warnings.push("DXF file did not expose any ENTITIES."), c;
|
|
510
507
|
}
|
|
511
|
-
function
|
|
512
|
-
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r =
|
|
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 =
|
|
514
|
-
r.blockName =
|
|
515
|
-
const n =
|
|
516
|
-
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation =
|
|
508
|
+
function pt(e) {
|
|
509
|
+
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r = fe(e, t), i = y(e.colorIndex ?? e.colorNumber ?? e.aci), s = y(e.color);
|
|
510
|
+
if (r.colorIndex = i ?? (s !== void 0 && Math.abs(s) <= 257 ? s : void 0), r.trueColor = e.trueColor ?? e.true_color ?? e.colorRGB ?? e.trueColorValue ?? (s !== void 0 && Math.abs(s) > 257 ? s : void 0), r.layer = C(e.layer ?? e.layerName) ?? "0", r.isClosed = !!(e.shape ?? e.closed ?? e.isClosed) || (Number(e.flag ?? e.flags ?? 0) & 1) === 1, t === "LINE" && (r.startPoint = P(e.startPoint ?? { x: e.x1 ?? e.x, y: e.y1 ?? e.y, z: e.z1 ?? e.z }) ?? r.startPoint, r.endPoint = P(e.endPoint ?? { x: e.x2, y: e.y2, z: e.z2 }) ?? r.endPoint), (t === "TEXT" || t === "MTEXT" || t === "ATTRIB" || t === "ATTDEF") && (r.insertionPoint = P(e.startPoint ?? e.position ?? e.insertionPoint) ?? r.insertionPoint, r.text = C(e.text ?? e.string ?? e.value) ?? r.text, r.textHeight = y(e.textHeight ?? e.height) ?? r.textHeight, r.rotation = Pt(e.rotation ?? e.angle)), (t === "ARC" || t === "ELLIPSE") && (r.startAngle = kt(e.startAngle ?? e.start_angle), r.endAngle = kt(e.endAngle ?? e.end_angle)), t === "INSERT") {
|
|
511
|
+
r.blockName = C(e.name ?? e.blockName) ?? r.blockName, r.insertionPoint = P(e.position ?? e.insertionPoint ?? e.point) ?? r.insertionPoint;
|
|
512
|
+
const n = y(e.xScale ?? e.scaleX ?? e.xscale), o = y(e.yScale ?? e.scaleY ?? e.yscale), a = y(e.zScale ?? e.scaleZ ?? e.zscale);
|
|
513
|
+
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation = Pt(e.rotation ?? e.angle);
|
|
517
514
|
}
|
|
518
515
|
if (t === "SPLINE") {
|
|
519
|
-
const n =
|
|
516
|
+
const n = J(e.controlPoints ?? e.control_points ?? e.points);
|
|
520
517
|
n.length && (r.controlPoints = n);
|
|
521
|
-
const o =
|
|
518
|
+
const o = J(e.fitPoints ?? e.fit_points);
|
|
522
519
|
o.length && (r.fitPoints = o);
|
|
523
520
|
}
|
|
524
|
-
return t === "HATCH" && (r.loops =
|
|
521
|
+
return t === "HATCH" && (r.loops = we(e), r.fillColorIndex = r.colorIndex), (t === "SOLID" || t === "TRACE" || t === "3DFACE") && (r.vertices = xe(e), r.fillColorIndex = r.colorIndex), r;
|
|
525
522
|
}
|
|
526
|
-
function
|
|
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 =
|
|
523
|
+
function be(e) {
|
|
524
|
+
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 = ye(i);
|
|
528
525
|
for (const n of s) {
|
|
529
|
-
const o = n, a =
|
|
530
|
-
a &&
|
|
526
|
+
const o = n, a = C(o.name ?? o.layerName);
|
|
527
|
+
a && wt(t, {
|
|
531
528
|
name: a,
|
|
532
529
|
color: o.color ?? o.colorNumber ?? o.colorIndex,
|
|
533
|
-
colorIndex:
|
|
534
|
-
lineType:
|
|
530
|
+
colorIndex: y(o.colorNumber ?? o.colorIndex ?? o.color),
|
|
531
|
+
lineType: C(o.lineType ?? o.linetype),
|
|
535
532
|
isVisible: Number(o.colorNumber ?? o.colorIndex ?? o.color ?? 1) >= 0,
|
|
536
533
|
isFrozen: !!o.frozen,
|
|
537
534
|
isLocked: !!o.locked,
|
|
538
535
|
raw: o
|
|
539
536
|
});
|
|
540
537
|
}
|
|
541
|
-
return t[0] ||
|
|
538
|
+
return t[0] || wt(t, { name: "0", colorIndex: 7, isVisible: !0 }), t;
|
|
542
539
|
}
|
|
543
|
-
function
|
|
540
|
+
function ve(e) {
|
|
544
541
|
const t = {}, r = e.blocks;
|
|
545
542
|
if (!r || typeof r != "object") return t;
|
|
546
543
|
if (Array.isArray(r))
|
|
547
|
-
for (const i of r)
|
|
544
|
+
for (const i of r) Ct(t, i);
|
|
548
545
|
else
|
|
549
|
-
for (const [i, s] of Object.entries(r))
|
|
546
|
+
for (const [i, s] of Object.entries(r)) Ct(t, s, i);
|
|
550
547
|
return t;
|
|
551
548
|
}
|
|
552
|
-
function
|
|
549
|
+
function Ct(e, t, r) {
|
|
553
550
|
if (!t || typeof t != "object") return;
|
|
554
|
-
const i = t, s =
|
|
551
|
+
const i = t, s = C(i.name ?? i.blockName ?? r);
|
|
555
552
|
if (!s) return;
|
|
556
|
-
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) =>
|
|
557
|
-
|
|
553
|
+
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) => pt(a));
|
|
554
|
+
de(e, { name: s, basePoint: P(i.basePoint ?? i.position) ?? { x: 0, y: 0 }, entities: o, raw: i });
|
|
558
555
|
}
|
|
559
|
-
function
|
|
556
|
+
function ye(e) {
|
|
560
557
|
if (!e) return [];
|
|
561
558
|
if (Array.isArray(e)) return e;
|
|
562
559
|
if (typeof e != "object") return [];
|
|
563
560
|
const t = e;
|
|
564
561
|
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
562
|
}
|
|
566
|
-
function
|
|
567
|
-
return Array.isArray(e) ? e.map(
|
|
563
|
+
function J(e) {
|
|
564
|
+
return Array.isArray(e) ? e.map(P).filter((t) => !!t) : [];
|
|
568
565
|
}
|
|
569
|
-
function
|
|
570
|
-
const t =
|
|
566
|
+
function xe(e) {
|
|
567
|
+
const t = J(e.vertices ?? e.points);
|
|
571
568
|
if (t.length) return t;
|
|
572
569
|
const r = [];
|
|
573
570
|
for (let i = 0; i < 4; i++) {
|
|
574
|
-
const s =
|
|
571
|
+
const s = P({ x: e[`x${i}`] ?? e[`x${i + 1}`], y: e[`y${i}`] ?? e[`y${i + 1}`], z: e[`z${i}`] ?? e[`z${i + 1}`] });
|
|
575
572
|
s && r.push(s);
|
|
576
573
|
}
|
|
577
574
|
return r;
|
|
578
575
|
}
|
|
579
|
-
function
|
|
576
|
+
function we(e) {
|
|
580
577
|
const t = e.boundaryLoops ?? e.loops ?? e.paths;
|
|
581
578
|
if (Array.isArray(t))
|
|
582
579
|
return t.map((r) => {
|
|
583
580
|
const i = r;
|
|
584
|
-
return { vertices:
|
|
581
|
+
return { vertices: J(i.vertices ?? i.points), isClosed: !0 };
|
|
585
582
|
}).filter((r) => r.vertices && r.vertices.length > 0);
|
|
586
583
|
}
|
|
587
|
-
function
|
|
588
|
-
const t =
|
|
584
|
+
function Pt(e) {
|
|
585
|
+
const t = y(e);
|
|
589
586
|
if (t !== void 0)
|
|
590
|
-
return Math.abs(t) > Math.PI * 2 + 1e-6 ?
|
|
587
|
+
return Math.abs(t) > Math.PI * 2 + 1e-6 ? E(t) : t;
|
|
591
588
|
}
|
|
592
|
-
function
|
|
593
|
-
const t =
|
|
589
|
+
function kt(e) {
|
|
590
|
+
const t = y(e);
|
|
594
591
|
if (t !== void 0)
|
|
595
|
-
return Math.abs(t) > Math.PI * 2 + 1e-6 ?
|
|
592
|
+
return Math.abs(t) > Math.PI * 2 + 1e-6 ? E(t) : t;
|
|
596
593
|
}
|
|
597
|
-
function
|
|
594
|
+
function Ce(e) {
|
|
598
595
|
const t = new TextDecoder("utf-8", { fatal: !1 }).decode(e);
|
|
599
596
|
return t.includes("SECTION") ? t : new TextDecoder("iso-8859-1", { fatal: !1 }).decode(e);
|
|
600
597
|
}
|
|
601
|
-
function
|
|
602
|
-
var
|
|
598
|
+
function Pe(e) {
|
|
599
|
+
var h, l;
|
|
603
600
|
const t = e.replace(/\r\n/g, `
|
|
604
601
|
`).replace(/\r/g, `
|
|
605
602
|
`).split(`
|
|
606
603
|
`), r = [];
|
|
607
604
|
for (let f = 0; f < t.length - 1; f += 2) {
|
|
608
|
-
const
|
|
609
|
-
Number.isFinite(
|
|
605
|
+
const u = Number((h = t[f]) == null ? void 0 : h.trim()), p = t[f + 1] ?? "";
|
|
606
|
+
Number.isFinite(u) && r.push({ code: u, value: p.trimEnd() });
|
|
610
607
|
}
|
|
611
608
|
const i = [], s = {};
|
|
612
609
|
let n = "", o = [], a;
|
|
613
610
|
for (let f = 0; f < r.length; f++) {
|
|
614
|
-
const
|
|
615
|
-
if (
|
|
616
|
-
n = ((
|
|
611
|
+
const u = r[f];
|
|
612
|
+
if (u.code === 0 && u.value === "SECTION") {
|
|
613
|
+
n = ((l = r[f + 1]) == null ? void 0 : l.code) === 2 ? r[f + 1].value.toUpperCase() : "", f++;
|
|
617
614
|
continue;
|
|
618
615
|
}
|
|
619
|
-
if (
|
|
616
|
+
if (u.code === 0 && u.value === "ENDSEC") {
|
|
620
617
|
c(), n = "";
|
|
621
618
|
continue;
|
|
622
619
|
}
|
|
623
|
-
n === "ENTITIES" && (
|
|
620
|
+
n === "ENTITIES" && (u.code === 0 ? (c(), o = [u]) : o.push(u));
|
|
624
621
|
}
|
|
625
622
|
return c(), { header: {}, tables: {}, entities: i, blocks: s };
|
|
626
623
|
function c() {
|
|
@@ -628,7 +625,7 @@ function ke(e) {
|
|
|
628
625
|
if (!o.length) return;
|
|
629
626
|
const f = (p = o[0]) == null ? void 0 : p.value.toUpperCase();
|
|
630
627
|
if (f === "VERTEX" && a) {
|
|
631
|
-
const g =
|
|
628
|
+
const g = w(o, 10, 20, 30);
|
|
632
629
|
g && (a.vertices ?? (a.vertices = [])).push({ ...g, bulge: b(o, 42) }), o = [];
|
|
633
630
|
return;
|
|
634
631
|
}
|
|
@@ -640,85 +637,85 @@ function ke(e) {
|
|
|
640
637
|
o = [];
|
|
641
638
|
return;
|
|
642
639
|
}
|
|
643
|
-
const
|
|
644
|
-
f === "POLYLINE" ? a =
|
|
640
|
+
const u = ke(f, o);
|
|
641
|
+
f === "POLYLINE" ? a = u : i.push(u), o = [];
|
|
645
642
|
}
|
|
646
643
|
}
|
|
647
|
-
function
|
|
644
|
+
function ke(e, t) {
|
|
648
645
|
const r = {
|
|
649
646
|
type: e,
|
|
650
|
-
handle:
|
|
651
|
-
layer:
|
|
647
|
+
handle: H(t, 5),
|
|
648
|
+
layer: H(t, 8) ?? "0",
|
|
652
649
|
colorIndex: b(t, 62),
|
|
653
650
|
trueColor: b(t, 420),
|
|
654
|
-
lineType:
|
|
651
|
+
lineType: H(t, 6),
|
|
655
652
|
lineweight: b(t, 370)
|
|
656
653
|
};
|
|
657
654
|
switch (e) {
|
|
658
655
|
case "LINE":
|
|
659
|
-
Object.assign(r, { startPoint:
|
|
656
|
+
Object.assign(r, { startPoint: w(t, 10, 20, 30), endPoint: w(t, 11, 21, 31) });
|
|
660
657
|
break;
|
|
661
658
|
case "CIRCLE":
|
|
662
|
-
Object.assign(r, { center:
|
|
659
|
+
Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40) });
|
|
663
660
|
break;
|
|
664
661
|
case "ARC":
|
|
665
|
-
Object.assign(r, { center:
|
|
662
|
+
Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40), startAngle: G(b(t, 50)), endAngle: G(b(t, 51)) });
|
|
666
663
|
break;
|
|
667
664
|
case "POINT":
|
|
668
|
-
Object.assign(r, { point:
|
|
665
|
+
Object.assign(r, { point: w(t, 10, 20, 30) });
|
|
669
666
|
break;
|
|
670
667
|
case "TEXT":
|
|
671
668
|
case "MTEXT":
|
|
672
|
-
Object.assign(r, { insertionPoint:
|
|
669
|
+
Object.assign(r, { insertionPoint: w(t, 10, 20, 30), text: Ne(t), textHeight: b(t, 40), rotation: G(b(t, 50)) });
|
|
673
670
|
break;
|
|
674
671
|
case "LWPOLYLINE":
|
|
675
|
-
Object.assign(r, { vertices:
|
|
672
|
+
Object.assign(r, { vertices: Me(t), flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
676
673
|
break;
|
|
677
674
|
case "POLYLINE":
|
|
678
675
|
Object.assign(r, { vertices: [], flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
679
676
|
break;
|
|
680
677
|
case "ELLIPSE":
|
|
681
|
-
Object.assign(r, { center:
|
|
678
|
+
Object.assign(r, { center: w(t, 10, 20, 30), majorAxisEndPoint: w(t, 11, 21, 31), axisRatio: b(t, 40), startAngle: b(t, 41), endAngle: b(t, 42) });
|
|
682
679
|
break;
|
|
683
680
|
case "SPLINE":
|
|
684
|
-
Object.assign(r, { controlPoints:
|
|
681
|
+
Object.assign(r, { controlPoints: Se(t, 10, 20, 30), degree: b(t, 71), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
685
682
|
break;
|
|
686
683
|
case "INSERT":
|
|
687
|
-
Object.assign(r, { name:
|
|
684
|
+
Object.assign(r, { name: H(t, 2), blockName: H(t, 2), insertionPoint: w(t, 10, 20, 30), rotation: G(b(t, 50)), scale: { x: b(t, 41) ?? 1, y: b(t, 42) ?? b(t, 41) ?? 1, z: b(t, 43) ?? 1 } });
|
|
688
685
|
break;
|
|
689
686
|
case "SOLID":
|
|
690
687
|
case "TRACE":
|
|
691
688
|
case "3DFACE":
|
|
692
|
-
Object.assign(r, { vertices: [
|
|
689
|
+
Object.assign(r, { vertices: [w(t, 10, 20, 30), w(t, 11, 21, 31), w(t, 12, 22, 32), w(t, 13, 23, 33)].filter(Boolean) });
|
|
693
690
|
break;
|
|
694
691
|
}
|
|
695
|
-
return
|
|
692
|
+
return pt(r);
|
|
696
693
|
}
|
|
697
694
|
function b(e, t) {
|
|
698
695
|
var s;
|
|
699
696
|
const r = (s = e.find((n) => n.code === t)) == null ? void 0 : s.value, i = Number(r);
|
|
700
697
|
return Number.isFinite(i) ? i : void 0;
|
|
701
698
|
}
|
|
702
|
-
function
|
|
699
|
+
function H(e, t) {
|
|
703
700
|
var i;
|
|
704
701
|
const r = (i = e.find((s) => s.code === t)) == null ? void 0 : i.value;
|
|
705
702
|
return r && r.length > 0 ? r : void 0;
|
|
706
703
|
}
|
|
707
|
-
function
|
|
704
|
+
function w(e, t, r, i) {
|
|
708
705
|
const s = b(e, t), n = b(e, r), o = b(e, i);
|
|
709
706
|
if (!(s === void 0 || n === void 0))
|
|
710
707
|
return o === void 0 ? { x: s, y: n } : { x: s, y: n, z: o };
|
|
711
708
|
}
|
|
712
|
-
function
|
|
709
|
+
function Se(e, t, r, i) {
|
|
713
710
|
const s = [];
|
|
714
711
|
for (let n = 0; n < e.length; n++) {
|
|
715
712
|
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),
|
|
717
|
-
Number.isFinite(o) && Number.isFinite(
|
|
713
|
+
const o = Number(e[n].value), a = e.slice(n + 1).find((f) => f.code === r), c = e.slice(n + 1).find((f) => f.code === i), h = Number(a == null ? void 0 : a.value), l = Number(c == null ? void 0 : c.value);
|
|
714
|
+
Number.isFinite(o) && Number.isFinite(h) && s.push(Number.isFinite(l) ? { x: o, y: h, z: l } : { x: o, y: h });
|
|
718
715
|
}
|
|
719
716
|
return s;
|
|
720
717
|
}
|
|
721
|
-
function
|
|
718
|
+
function Me(e) {
|
|
722
719
|
const t = [];
|
|
723
720
|
for (let r = 0; r < e.length; r++) {
|
|
724
721
|
if (e[r].code !== 10) continue;
|
|
@@ -730,14 +727,258 @@ function Ne(e) {
|
|
|
730
727
|
}
|
|
731
728
|
return t;
|
|
732
729
|
}
|
|
733
|
-
function
|
|
730
|
+
function Ne(e) {
|
|
734
731
|
const t = e.filter((r) => r.code === 1 || r.code === 3).map((r) => r.value);
|
|
735
732
|
return t.length ? t.join("") : void 0;
|
|
736
733
|
}
|
|
737
|
-
function
|
|
738
|
-
return typeof e == "number" && Number.isFinite(e) ?
|
|
734
|
+
function G(e) {
|
|
735
|
+
return typeof e == "number" && Number.isFinite(e) ? E(e) : void 0;
|
|
736
|
+
}
|
|
737
|
+
class Ee {
|
|
738
|
+
constructor(t = {}) {
|
|
739
|
+
d(this, "id", "dwf");
|
|
740
|
+
d(this, "label", "DWF/DWFx native viewer powered by dwf-viewer");
|
|
741
|
+
d(this, "formats", ["dwf", "dwfx", "xps"]);
|
|
742
|
+
d(this, "nativeRenderer", !0);
|
|
743
|
+
d(this, "defaults");
|
|
744
|
+
d(this, "native");
|
|
745
|
+
d(this, "host");
|
|
746
|
+
d(this, "lastStats");
|
|
747
|
+
this.defaults = t;
|
|
748
|
+
}
|
|
749
|
+
accepts(t, r) {
|
|
750
|
+
const i = L(t);
|
|
751
|
+
if (i === "dwf" || i === "dwfx" || i === "xps") return !0;
|
|
752
|
+
const s = A(t, r);
|
|
753
|
+
return s === "dwf" || s === "dwfx" || s === "xps";
|
|
754
|
+
}
|
|
755
|
+
async load(t, r = {}) {
|
|
756
|
+
var f, u, p, g;
|
|
757
|
+
const i = { ...this.defaults, ...r }, s = performance.now(), n = t.fileName ?? ((f = t.file) == null ? void 0 : f.name), o = await _(t), a = Nt(A(t, o), L(t));
|
|
758
|
+
(u = i.onProgress) == null || u.call(i, { phase: "parse", format: a, message: "Opening DWF/DWFx with dwf-viewer…", percent: 48 });
|
|
759
|
+
const c = await Qt(o, { fileName: n });
|
|
760
|
+
(p = i.onProgress) == null || p.call(i, { phase: "normalize", format: a, message: "Reading DWF pages, sheets and model metadata…", percent: 76 });
|
|
761
|
+
const h = St(c, n, a, i.keepRaw === !0), l = performance.now() - s;
|
|
762
|
+
return (g = i.onProgress) == null || g.call(i, { phase: "done", format: h.format, message: "DWF/DWFx document ready.", percent: 100, elapsedMs: l }), { document: h, raw: i.keepRaw ? c : void 0, bytes: o.byteLength, elapsedMs: l, format: h.format, warnings: h.warnings };
|
|
763
|
+
}
|
|
764
|
+
async mount(t, r, i = {}) {
|
|
765
|
+
var O, z, Y, gt, bt;
|
|
766
|
+
const s = { ...this.defaults, ...i }, n = performance.now(), o = t.fileName ?? ((O = t.file) == null ? void 0 : O.name), a = await _(t), c = Nt(A(t, a), L(t)), h = Be(s), l = Et(s), f = Fe(s, h, l), u = Ut(s, h, l);
|
|
767
|
+
(z = s.onProgress) == null || z.call(s, { phase: "native-render", format: c, message: "Mounting native DWF renderer…", percent: 28 }), this.unmount(), this.host = r, r.replaceChildren(), this.native = new te(r, f), (Y = s.onProgress) == null || Y.call(s, { phase: "parse", format: c, message: "Parsing DWF package and page streams…", percent: 58 }), await this.native.load(a, {
|
|
768
|
+
fileName: o,
|
|
769
|
+
...u
|
|
770
|
+
}), (gt = s.onProgress) == null || gt.call(s, { phase: "render", format: c, message: "Rendering DWF/DWFx with dwf-viewer…", percent: 88 }), this.lastStats = await this.native.render();
|
|
771
|
+
const p = this.native.getDocument(), g = St(p, o, c, s.keepRaw === !0);
|
|
772
|
+
g.metadata.loaderMode = "Native DWF", g.metadata.nativeRenderer = "dwf-viewer", g.metadata.nativeRenderStats = this.lastStats ? { ...this.lastStats, warnings: this.lastStats.warnings.length } : void 0;
|
|
773
|
+
const S = performance.now() - n;
|
|
774
|
+
return (bt = s.onProgress) == null || bt.call(s, { phase: "done", format: g.format, message: "DWF/DWFx rendered.", percent: 100, elapsedMs: S }), { document: g, raw: s.keepRaw ? p : void 0, bytes: a.byteLength, elapsedMs: S, format: g.format, warnings: g.warnings };
|
|
775
|
+
}
|
|
776
|
+
unmount() {
|
|
777
|
+
var t;
|
|
778
|
+
(t = this.native) == null || t.dispose(), this.native = void 0, this.lastStats = void 0, this.host && this.host.replaceChildren();
|
|
779
|
+
}
|
|
780
|
+
fit() {
|
|
781
|
+
var t;
|
|
782
|
+
(t = this.native) == null || t.fit();
|
|
783
|
+
}
|
|
784
|
+
zoomIn() {
|
|
785
|
+
var r;
|
|
786
|
+
const t = (r = this.native) == null ? void 0 : r.zoomInButton;
|
|
787
|
+
t == null || t.click();
|
|
788
|
+
}
|
|
789
|
+
zoomOut() {
|
|
790
|
+
var r;
|
|
791
|
+
const t = (r = this.native) == null ? void 0 : r.zoomOutButton;
|
|
792
|
+
t == null || t.click();
|
|
793
|
+
}
|
|
794
|
+
resize() {
|
|
795
|
+
var t;
|
|
796
|
+
(t = this.native) == null || t.render();
|
|
797
|
+
}
|
|
798
|
+
setNativeOptions(t) {
|
|
799
|
+
var i, s, n, o;
|
|
800
|
+
const r = this.native;
|
|
801
|
+
if (r) {
|
|
802
|
+
if (typeof t.dwfBackground == "string") r.background = t.dwfBackground;
|
|
803
|
+
else {
|
|
804
|
+
const a = Et(t);
|
|
805
|
+
a && (r.background = a);
|
|
806
|
+
}
|
|
807
|
+
typeof t.dwfPreferWebgl == "boolean" && ((i = r.setPreferWebgl) == null || i.call(r, t.dwfPreferWebgl)), typeof t.dwfPreferWasm == "boolean" && ((s = r.setPreferWasm) == null || s.call(r, t.dwfPreferWasm)), t.dwfLineWeightMode && ((n = r.setLineWeightMode) == null || n.call(r, t.dwfLineWeightMode)), Z(r, "minStrokeCssPx", t.dwfMinStrokeCssPx), Z(r, "maxOverviewStrokeCssPx", t.dwfMaxOverviewStrokeCssPx), Z(r, "minTextCssPx", t.dwfMinTextCssPx), Z(r, "minFilledAreaCssPx", t.dwfMinFilledAreaCssPx), (o = r.render) == null || o.call(r);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
getLastNativeStats() {
|
|
811
|
+
return this.lastStats;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function St(e, t, r, i) {
|
|
815
|
+
var a, c;
|
|
816
|
+
const s = Mt((e == null ? void 0 : e.diagnostics) ?? []), n = ((e == null ? void 0 : e.pageData) ?? []).map((h, l) => Ie(h, l));
|
|
817
|
+
for (const h of (e == null ? void 0 : e.pageData) ?? []) s.push(...Mt(h.diagnostics));
|
|
818
|
+
const o = {
|
|
819
|
+
parser: "dwf-viewer",
|
|
820
|
+
nativeRenderer: "dwf-viewer",
|
|
821
|
+
dwfKind: e == null ? void 0 : e.kind,
|
|
822
|
+
packageEntries: ((a = e == null ? void 0 : e.packageEntries) == null ? void 0 : a.length) ?? 0,
|
|
823
|
+
resources: ((c = e == null ? void 0 : e.resources) == null ? void 0 : c.length) ?? 0,
|
|
824
|
+
pageKinds: De(((e == null ? void 0 : e.pageData) ?? []).map((h) => h.kind)),
|
|
825
|
+
pageNames: ((e == null ? void 0 : e.pages) ?? []).map((h) => h.name)
|
|
826
|
+
};
|
|
827
|
+
return zt({
|
|
828
|
+
format: r,
|
|
829
|
+
sourceName: t,
|
|
830
|
+
layers: {},
|
|
831
|
+
blocks: {},
|
|
832
|
+
pages: n,
|
|
833
|
+
entities: ue(n),
|
|
834
|
+
metadata: o,
|
|
835
|
+
warnings: Oe(s),
|
|
836
|
+
raw: i ? e : void 0
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
function Ie(e, t) {
|
|
840
|
+
const r = Te(e, t);
|
|
841
|
+
return {
|
|
842
|
+
index: t,
|
|
843
|
+
name: e.name || e.sourcePath || `${t + 1}`,
|
|
844
|
+
width: e.width || 1e3,
|
|
845
|
+
height: e.height || 1e3,
|
|
846
|
+
entities: r
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function Te(e, t) {
|
|
850
|
+
return e.kind === "w2d-text" ? e.primitives.flatMap((r, i) => Le(r, t, i)) : e.kind === "image" ? [{ type: "DWF_IMAGE_PAGE", kind: "image", pageIndex: t, width: e.width, height: e.height, imageSource: e.sourcePath }] : e.kind === "w3d-model" ? e.model.meshes.map((r, i) => ({
|
|
851
|
+
id: r.id,
|
|
852
|
+
type: "W3D_MESH",
|
|
853
|
+
kind: "solid",
|
|
854
|
+
pageIndex: t,
|
|
855
|
+
color: r.color ? Re(r.color) : void 0,
|
|
856
|
+
name: r.name || `mesh-${i + 1}`,
|
|
857
|
+
raw: { vertexCount: r.vertexCount, triangleCount: r.triangleCount, materialId: r.materialId }
|
|
858
|
+
})) : e.kind === "xps-fixed-page" ? [{ type: "XPS_FIXED_PAGE", kind: "viewport", pageIndex: t, width: e.width, height: e.height, raw: { sourcePath: e.sourcePath } }] : [{ type: "DWF_PAGE", kind: "viewport", pageIndex: t, width: e.width, height: e.height, raw: { sourcePath: e.sourcePath } }];
|
|
859
|
+
}
|
|
860
|
+
function Le(e, t, r) {
|
|
861
|
+
const i = {
|
|
862
|
+
id: `dwf-${t}-${r}`,
|
|
863
|
+
pageIndex: t,
|
|
864
|
+
color: e.stroke,
|
|
865
|
+
fillColor: e.fill,
|
|
866
|
+
lineweight: e.lineWidth,
|
|
867
|
+
raw: { matrix: e.matrix }
|
|
868
|
+
};
|
|
869
|
+
if (e.type === "polyline" || e.type === "polygon")
|
|
870
|
+
return [{
|
|
871
|
+
...i,
|
|
872
|
+
type: e.type === "polygon" ? "DWF_POLYGON" : "DWF_POLYLINE",
|
|
873
|
+
kind: "polyline",
|
|
874
|
+
vertices: Ae(e.points),
|
|
875
|
+
isClosed: e.type === "polygon"
|
|
876
|
+
}];
|
|
877
|
+
if (e.type === "path")
|
|
878
|
+
return [{ ...i, type: "DWF_PATH", kind: "path", commands: e.commands }];
|
|
879
|
+
if (e.type === "text")
|
|
880
|
+
return [{
|
|
881
|
+
...i,
|
|
882
|
+
type: "DWF_TEXT",
|
|
883
|
+
kind: "text",
|
|
884
|
+
insertionPoint: { x: e.x, y: e.y, z: 0 },
|
|
885
|
+
text: e.text,
|
|
886
|
+
textHeight: e.size
|
|
887
|
+
}];
|
|
888
|
+
if (e.type === "rect") {
|
|
889
|
+
const s = e.x, n = e.y, o = e.width, a = e.height;
|
|
890
|
+
return [{
|
|
891
|
+
...i,
|
|
892
|
+
type: "DWF_RECT",
|
|
893
|
+
kind: "polyline",
|
|
894
|
+
isClosed: !0,
|
|
895
|
+
vertices: [
|
|
896
|
+
{ x: s, y: n, z: 0 },
|
|
897
|
+
{ x: s + o, y: n, z: 0 },
|
|
898
|
+
{ x: s + o, y: n + a, z: 0 },
|
|
899
|
+
{ x: s, y: n + a, z: 0 }
|
|
900
|
+
]
|
|
901
|
+
}];
|
|
902
|
+
}
|
|
903
|
+
return [];
|
|
904
|
+
}
|
|
905
|
+
function Ae(e) {
|
|
906
|
+
const t = [];
|
|
907
|
+
for (let r = 0; r + 1 < e.length; r += 2) t.push({ x: e[r], y: e[r + 1], z: 0 });
|
|
908
|
+
return t;
|
|
909
|
+
}
|
|
910
|
+
function Mt(e) {
|
|
911
|
+
return e.filter((t) => t.level !== "info").map((t) => `${t.code}: ${t.message}${t.source ? ` (${t.source})` : ""}`);
|
|
912
|
+
}
|
|
913
|
+
function Nt(e, t) {
|
|
914
|
+
return t === "dwf" || t === "dwfx" || t === "xps" ? t : e === "dwf" || e === "dwfx" || e === "xps" ? e : "dwf";
|
|
915
|
+
}
|
|
916
|
+
function Be(e) {
|
|
917
|
+
if (e.dwfWasmUrl) return e.dwfWasmUrl;
|
|
918
|
+
if (typeof document > "u") return;
|
|
919
|
+
const t = e.wasmPath ? new URL(We(e.wasmPath), document.baseURI).href : new URL("wasm/", document.baseURI).href;
|
|
920
|
+
return new URL("dwfv-render.wasm", t).href;
|
|
921
|
+
}
|
|
922
|
+
function Et(e) {
|
|
923
|
+
if (e.dwfBackground) return e.dwfBackground;
|
|
924
|
+
const t = e.canvasOptions;
|
|
925
|
+
return (t == null ? void 0 : t.background) ?? "#05070d";
|
|
926
|
+
}
|
|
927
|
+
function Fe(e, t, r) {
|
|
928
|
+
return {
|
|
929
|
+
...Ut(e, t, r),
|
|
930
|
+
maxDevicePixelRatio: e.dwfMaxDevicePixelRatio ?? 2,
|
|
931
|
+
maxCanvasPixels: e.dwfMaxCanvasPixels ?? 16777216
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
function Ut(e, t, r) {
|
|
935
|
+
return {
|
|
936
|
+
wasmUrl: t,
|
|
937
|
+
preferWebgl: e.dwfPreferWebgl ?? !0,
|
|
938
|
+
preferWasm: e.dwfPreferWasm ?? !0,
|
|
939
|
+
background: r,
|
|
940
|
+
maxGpuCacheBytes: e.dwfMaxGpuCacheBytes ?? 160 * 1024 * 1024,
|
|
941
|
+
maxCachedScenes: e.dwfMaxCachedScenes ?? 2,
|
|
942
|
+
lineWeightMode: e.dwfLineWeightMode ?? "adaptive",
|
|
943
|
+
minStrokeCssPx: e.dwfMinStrokeCssPx,
|
|
944
|
+
maxOverviewStrokeCssPx: e.dwfMaxOverviewStrokeCssPx,
|
|
945
|
+
minTextCssPx: e.dwfMinTextCssPx,
|
|
946
|
+
minFilledAreaCssPx: e.dwfMinFilledAreaCssPx
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function Z(e, t, r) {
|
|
950
|
+
typeof r == "number" && Number.isFinite(r) && (e[t] = r);
|
|
951
|
+
}
|
|
952
|
+
function We(e) {
|
|
953
|
+
return e.endsWith("/") ? e : `${e}/`;
|
|
954
|
+
}
|
|
955
|
+
function Re(e) {
|
|
956
|
+
const [t, r, i] = e.map((s) => Math.max(0, Math.min(255, Math.round(s * 255))));
|
|
957
|
+
return `#${rt(t)}${rt(r)}${rt(i)}`;
|
|
958
|
+
}
|
|
959
|
+
function rt(e) {
|
|
960
|
+
return e.toString(16).padStart(2, "0");
|
|
961
|
+
}
|
|
962
|
+
function De(e) {
|
|
963
|
+
const t = {};
|
|
964
|
+
for (const r of e) t[r] = (t[r] ?? 0) + 1;
|
|
965
|
+
return t;
|
|
966
|
+
}
|
|
967
|
+
function Oe(e) {
|
|
968
|
+
return Array.from(new Set(e));
|
|
969
|
+
}
|
|
970
|
+
function ze(e = {}) {
|
|
971
|
+
return new re([
|
|
972
|
+
new ce(e),
|
|
973
|
+
new me(e),
|
|
974
|
+
new Ee(e)
|
|
975
|
+
]);
|
|
976
|
+
}
|
|
977
|
+
function Ye(e) {
|
|
978
|
+
const t = e;
|
|
979
|
+
return t.nativeRenderer === !0 && typeof t.mount == "function";
|
|
739
980
|
}
|
|
740
|
-
const
|
|
981
|
+
const He = {
|
|
741
982
|
1: "#ff0000",
|
|
742
983
|
2: "#ffff00",
|
|
743
984
|
3: "#00ff00",
|
|
@@ -993,19 +1234,19 @@ const Ie = {
|
|
|
993
1234
|
254: "#bebebe",
|
|
994
1235
|
255: "#ffffff"
|
|
995
1236
|
};
|
|
996
|
-
function
|
|
1237
|
+
function N(e, t = "#ffffff", r = t) {
|
|
997
1238
|
if (typeof e != "number" || Number.isNaN(e)) return t;
|
|
998
1239
|
const i = Math.abs(Math.trunc(e));
|
|
999
|
-
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r :
|
|
1240
|
+
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r : He[i] ?? t;
|
|
1000
1241
|
}
|
|
1001
|
-
function
|
|
1242
|
+
function U(e, t = "rgb") {
|
|
1002
1243
|
const r = Math.max(0, Math.trunc(e)) & 16777215, i = r >> 16 & 255, s = r >> 8 & 255, n = r & 255;
|
|
1003
1244
|
return `rgb(${t === "rgb" ? i : n}, ${s}, ${t === "rgb" ? n : i})`;
|
|
1004
1245
|
}
|
|
1005
|
-
function
|
|
1246
|
+
function B(e) {
|
|
1006
1247
|
if (typeof e == "string") {
|
|
1007
1248
|
const t = e.trim();
|
|
1008
|
-
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ?
|
|
1249
|
+
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ? Xe(t) ?? t : {
|
|
1009
1250
|
red: "#ff0000",
|
|
1010
1251
|
yellow: "#ffff00",
|
|
1011
1252
|
green: "#00ff00",
|
|
@@ -1024,7 +1265,7 @@ function F(e) {
|
|
|
1024
1265
|
return Number.isFinite(n) && n >= 0 && n < 1 ? `rgba(${r}, ${i}, ${s}, ${n})` : `rgb(${r}, ${i}, ${s})`;
|
|
1025
1266
|
}
|
|
1026
1267
|
}
|
|
1027
|
-
function
|
|
1268
|
+
function Xe(e) {
|
|
1028
1269
|
if (!e) return;
|
|
1029
1270
|
const t = e.trim();
|
|
1030
1271
|
if (/^#[0-9a-f]{8}$/i.test(t)) {
|
|
@@ -1037,83 +1278,83 @@ function K(e) {
|
|
|
1037
1278
|
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
1279
|
}
|
|
1039
1280
|
}
|
|
1040
|
-
function
|
|
1281
|
+
function F(e, t, r = {}) {
|
|
1041
1282
|
const i = r.foreground ?? "#ffffff", s = i;
|
|
1042
1283
|
let n;
|
|
1043
|
-
const o =
|
|
1284
|
+
const o = B(e.trueColor) ?? B(e.color) ?? B(e.colorName);
|
|
1044
1285
|
if (o && (n = o), !n) {
|
|
1045
|
-
const a =
|
|
1046
|
-
typeof a == "number" && a >= 0 && a <= 16777215 && (n =
|
|
1286
|
+
const a = Ge(e, ["trueColor", "true_color", "truecolor", "colorRGB", "colorRgb", "rgbColor", "rgb"]);
|
|
1287
|
+
typeof a == "number" && a >= 0 && a <= 16777215 && (n = U(a, r.trueColorByteOrder ?? "rgb"));
|
|
1047
1288
|
}
|
|
1048
1289
|
if (!n) {
|
|
1049
1290
|
const a = Gt(e.colorIndex, e.colorNumber, e.aci);
|
|
1050
|
-
typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (n =
|
|
1291
|
+
typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (n = N(a, s, i));
|
|
1051
1292
|
}
|
|
1052
1293
|
if (!n && typeof e.color == "number") {
|
|
1053
1294
|
const a = Number(e.color);
|
|
1054
|
-
Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (n =
|
|
1295
|
+
Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (n = N(a, s, i)) : n = U(a, r.trueColorByteOrder ?? "rgb");
|
|
1055
1296
|
}
|
|
1056
1297
|
if (!n) {
|
|
1057
|
-
const a =
|
|
1058
|
-
n =
|
|
1298
|
+
const a = je(t, e.layer);
|
|
1299
|
+
n = Ue(a, r);
|
|
1059
1300
|
}
|
|
1060
1301
|
return Vt(n ?? s, r);
|
|
1061
1302
|
}
|
|
1062
1303
|
function ft(e, t, r = {}) {
|
|
1063
1304
|
let i;
|
|
1064
|
-
const s =
|
|
1305
|
+
const s = B(e.fillColor);
|
|
1065
1306
|
if (s && (i = s), !i && typeof e.fillColor == "number") {
|
|
1066
1307
|
const n = e.fillColor;
|
|
1067
|
-
i = Math.abs(n) <= 257 ?
|
|
1308
|
+
i = Math.abs(n) <= 257 ? N(n, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff") : U(n, r.trueColorByteOrder ?? "rgb");
|
|
1068
1309
|
}
|
|
1069
|
-
return !i && typeof e.fillColorIndex == "number" && (i =
|
|
1310
|
+
return !i && typeof e.fillColorIndex == "number" && (i = N(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ? Vt(i, r) : void 0;
|
|
1070
1311
|
}
|
|
1071
1312
|
function Vt(e, t = {}) {
|
|
1072
1313
|
if (t.contrastMode !== "adaptive") return e;
|
|
1073
1314
|
const r = t.background ?? "#0b1020", i = t.foreground ?? "#ffffff";
|
|
1074
|
-
return
|
|
1315
|
+
return _e(e, r, i, t.minColorContrast ?? 2.4);
|
|
1075
1316
|
}
|
|
1076
|
-
function
|
|
1077
|
-
const s =
|
|
1317
|
+
function _e(e, t, r, i = 2.4) {
|
|
1318
|
+
const s = it(r) ?? { r: 255, g: 255, b: 255, a: 1 }, n = it(t) ?? { r: 11, g: 16, b: 32, a: 1 }, o = it(e);
|
|
1078
1319
|
if (!o) return e;
|
|
1079
1320
|
const a = It(o, n);
|
|
1080
|
-
if (
|
|
1081
|
-
const c = dt(n),
|
|
1082
|
-
for (const
|
|
1083
|
-
const f =
|
|
1084
|
-
if (
|
|
1321
|
+
if (st(a, n) >= i) return e;
|
|
1322
|
+
const c = dt(n), h = c < 0.5 ? { r: 255, g: 255, b: 255, a: o.a } : { r: 0, g: 0, b: 0, a: o.a };
|
|
1323
|
+
for (const l of [0.25, 0.4, 0.55, 0.7, 0.85, 1]) {
|
|
1324
|
+
const f = Ze(o, h, l);
|
|
1325
|
+
if (st(It(f, n), n) >= i) return Tt(f);
|
|
1085
1326
|
}
|
|
1086
|
-
return
|
|
1327
|
+
return st(s, n) >= i ? Tt(s) : c < 0.5 ? "#ffffff" : "#000000";
|
|
1087
1328
|
}
|
|
1088
1329
|
function $t(e) {
|
|
1089
1330
|
return e ? e.isVisible !== !1 && e.isFrozen !== !0 : !0;
|
|
1090
1331
|
}
|
|
1091
|
-
function
|
|
1332
|
+
function Ue(e, t) {
|
|
1092
1333
|
if (!e) return;
|
|
1093
|
-
const r = t.foreground ?? "#ffffff", i =
|
|
1334
|
+
const r = t.foreground ?? "#ffffff", i = B(e.trueColor);
|
|
1094
1335
|
if (i) return i;
|
|
1095
|
-
if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return
|
|
1096
|
-
const s =
|
|
1336
|
+
if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return U(e.trueColor, t.trueColorByteOrder ?? "rgb");
|
|
1337
|
+
const s = B(e.color);
|
|
1097
1338
|
if (s) return s;
|
|
1098
|
-
if (
|
|
1339
|
+
if ($e(e.colorIndex)) return N(e.colorIndex, r, r);
|
|
1099
1340
|
if (typeof e.color == "number") {
|
|
1100
1341
|
const n = Number(e.color);
|
|
1101
|
-
return Math.abs(n) <= 257 ?
|
|
1342
|
+
return Math.abs(n) <= 257 ? N(n, r, r) : U(n, t.trueColorByteOrder ?? "rgb");
|
|
1102
1343
|
}
|
|
1103
|
-
if (typeof e.colorIndex == "number") return
|
|
1344
|
+
if (typeof e.colorIndex == "number") return N(e.colorIndex, r, r);
|
|
1104
1345
|
}
|
|
1105
|
-
function
|
|
1346
|
+
function Ve(e) {
|
|
1106
1347
|
return Gt(e.colorIndex, e.colorNumber, e.aci) === 0 ? !0 : e.trueColor === void 0 && e.color === 0;
|
|
1107
1348
|
}
|
|
1108
1349
|
function jt(e, t, r, i = {}) {
|
|
1109
|
-
if (!
|
|
1110
|
-
const s =
|
|
1350
|
+
if (!Ve(e)) return e;
|
|
1351
|
+
const s = F(t, r, i);
|
|
1111
1352
|
return { ...e, color: s, trueColor: void 0, colorIndex: void 0, colorNumber: void 0 };
|
|
1112
1353
|
}
|
|
1113
|
-
function
|
|
1354
|
+
function $e(e) {
|
|
1114
1355
|
return typeof e == "number" && Number.isFinite(e) && Math.abs(Math.trunc(e)) >= 1 && Math.abs(Math.trunc(e)) <= 255;
|
|
1115
1356
|
}
|
|
1116
|
-
function
|
|
1357
|
+
function je(e, t) {
|
|
1117
1358
|
if (!(!e || !t))
|
|
1118
1359
|
return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
1119
1360
|
}
|
|
@@ -1121,14 +1362,14 @@ function Gt(...e) {
|
|
|
1121
1362
|
for (const t of e)
|
|
1122
1363
|
if (typeof t == "number" && Number.isFinite(t)) return t;
|
|
1123
1364
|
}
|
|
1124
|
-
function
|
|
1365
|
+
function Ge(e, t) {
|
|
1125
1366
|
const r = e;
|
|
1126
1367
|
for (const i of t) {
|
|
1127
1368
|
const s = r[i];
|
|
1128
1369
|
if (typeof s == "number" && Number.isFinite(s)) return s;
|
|
1129
1370
|
}
|
|
1130
1371
|
}
|
|
1131
|
-
function
|
|
1372
|
+
function it(e) {
|
|
1132
1373
|
const t = e.trim().toLowerCase();
|
|
1133
1374
|
if (/^#[0-9a-f]{3}$/i.test(t))
|
|
1134
1375
|
return {
|
|
@@ -1167,7 +1408,7 @@ function It(e, t) {
|
|
|
1167
1408
|
a: r
|
|
1168
1409
|
};
|
|
1169
1410
|
}
|
|
1170
|
-
function
|
|
1411
|
+
function Ze(e, t, r) {
|
|
1171
1412
|
const i = Math.max(0, Math.min(1, r));
|
|
1172
1413
|
return {
|
|
1173
1414
|
r: e.r + (t.r - e.r) * i,
|
|
@@ -1183,7 +1424,7 @@ function dt(e) {
|
|
|
1183
1424
|
});
|
|
1184
1425
|
return 0.2126 * t[0] + 0.7152 * t[1] + 0.0722 * t[2];
|
|
1185
1426
|
}
|
|
1186
|
-
function
|
|
1427
|
+
function st(e, t) {
|
|
1187
1428
|
const r = dt(e), i = dt(t), s = Math.max(r, i), n = Math.min(r, i);
|
|
1188
1429
|
return (s + 0.05) / (n + 0.05);
|
|
1189
1430
|
}
|
|
@@ -1197,8 +1438,7 @@ function W(e) {
|
|
|
1197
1438
|
function ut(e) {
|
|
1198
1439
|
return Math.round(e * 1e3) / 1e3;
|
|
1199
1440
|
}
|
|
1200
|
-
|
|
1201
|
-
function j(e, t) {
|
|
1441
|
+
function nt(e, t) {
|
|
1202
1442
|
return {
|
|
1203
1443
|
a: e.a * t.a + e.c * t.b,
|
|
1204
1444
|
b: e.b * t.a + e.d * t.b,
|
|
@@ -1211,310 +1451,47 @@ function j(e, t) {
|
|
|
1211
1451
|
function Lt(e, t) {
|
|
1212
1452
|
return { a: 1, b: 0, c: 0, d: 1, e, f: t };
|
|
1213
1453
|
}
|
|
1214
|
-
function
|
|
1454
|
+
function qe(e) {
|
|
1215
1455
|
const t = Math.cos(e), r = Math.sin(e);
|
|
1216
1456
|
return { a: t, b: r, c: -r, d: t, e: 0, f: 0 };
|
|
1217
1457
|
}
|
|
1218
|
-
function
|
|
1458
|
+
function Ke(e, t = e) {
|
|
1219
1459
|
return { a: e, b: 0, c: 0, d: t, e: 0, f: 0 };
|
|
1220
1460
|
}
|
|
1221
|
-
function
|
|
1461
|
+
function k(e, t) {
|
|
1222
1462
|
return {
|
|
1223
1463
|
x: e.x * t.a + e.y * t.c + t.e,
|
|
1224
1464
|
y: e.x * t.b + e.y * t.d + t.f,
|
|
1225
1465
|
z: "z" in e ? e.z : void 0
|
|
1226
1466
|
};
|
|
1227
1467
|
}
|
|
1228
|
-
function
|
|
1468
|
+
function At(e, t) {
|
|
1229
1469
|
if (e)
|
|
1230
|
-
return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) =>
|
|
1470
|
+
return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) => k(i, t)) }));
|
|
1231
1471
|
}
|
|
1232
1472
|
function Q(e, t = { x: 0, y: 0 }) {
|
|
1233
1473
|
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
1474
|
let a = Lt(r.x, r.y);
|
|
1235
|
-
return a =
|
|
1475
|
+
return a = nt(a, qe(Number.isFinite(o) ? o : 0)), a = nt(a, Ke(Number.isFinite(s) ? s : 1, Number.isFinite(n) ? n : 1)), a = nt(a, Lt(-t.x, -t.y)), a;
|
|
1236
1476
|
}
|
|
1237
|
-
function
|
|
1477
|
+
function tt(e, t) {
|
|
1238
1478
|
const r = { ...e, raw: e.raw ?? e };
|
|
1239
|
-
if (e.startPoint && (r.startPoint =
|
|
1240
|
-
const s =
|
|
1479
|
+
if (e.startPoint && (r.startPoint = k(e.startPoint, t)), e.endPoint && (r.endPoint = k(e.endPoint, t)), e.center && (r.center = k(e.center, t)), e.insertionPoint && (r.insertionPoint = k(e.insertionPoint, t)), e.majorAxisEndPoint) {
|
|
1480
|
+
const s = k({ x: 0, y: 0 }, t), n = k(e.majorAxisEndPoint, t);
|
|
1241
1481
|
r.majorAxisEndPoint = { x: n.x - s.x, y: n.y - s.y, z: n.z };
|
|
1242
1482
|
}
|
|
1243
|
-
e.vertices && (r.vertices = e.vertices.map((s) => ({ ...
|
|
1483
|
+
e.vertices && (r.vertices = e.vertices.map((s) => ({ ...k(s, t), bulge: s.bulge, startWidth: s.startWidth, endWidth: s.endWidth }))), e.points && (r.points = e.points.map((s) => k(s, t))), e.controlPoints && (r.controlPoints = e.controlPoints.map((s) => k(s, t))), e.fitPoints && (r.fitPoints = e.fitPoints.map((s) => k(s, t))), e.commands && (r.commands = At(e.commands, t)), e.loops && (r.loops = e.loops.map((s) => {
|
|
1244
1484
|
var n;
|
|
1245
1485
|
return {
|
|
1246
1486
|
...s,
|
|
1247
|
-
vertices: (n = s.vertices) == null ? void 0 : n.map((o) =>
|
|
1248
|
-
commands:
|
|
1487
|
+
vertices: (n = s.vertices) == null ? void 0 : n.map((o) => k(o, t)),
|
|
1488
|
+
commands: At(s.commands, t)
|
|
1249
1489
|
};
|
|
1250
1490
|
}));
|
|
1251
1491
|
const i = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c));
|
|
1252
1492
|
return typeof e.radius == "number" && Number.isFinite(i) && (r.radius = e.radius * i), r;
|
|
1253
1493
|
}
|
|
1254
|
-
|
|
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 = {
|
|
1494
|
+
const Je = {
|
|
1518
1495
|
background: "#0b1020",
|
|
1519
1496
|
foreground: "#ffffff",
|
|
1520
1497
|
showUnsupportedMarkers: !1,
|
|
@@ -1537,33 +1514,33 @@ const Qe = {
|
|
|
1537
1514
|
preserveDrawingBuffer: !1,
|
|
1538
1515
|
enableSpatialIndex: !0
|
|
1539
1516
|
};
|
|
1540
|
-
class
|
|
1517
|
+
class Bt {
|
|
1541
1518
|
constructor(t, r = {}) {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1519
|
+
d(this, "canvas");
|
|
1520
|
+
d(this, "ctx");
|
|
1521
|
+
d(this, "opts");
|
|
1522
|
+
d(this, "document");
|
|
1523
|
+
d(this, "bounds", M());
|
|
1524
|
+
d(this, "view", { centerX: 0, centerY: 0, scale: 1 });
|
|
1525
|
+
d(this, "fitScale", 1);
|
|
1526
|
+
d(this, "dpr", 1);
|
|
1527
|
+
d(this, "isDragging", !1);
|
|
1528
|
+
d(this, "lastPointer");
|
|
1529
|
+
d(this, "resizeObserver");
|
|
1530
|
+
d(this, "imageCache", /* @__PURE__ */ new Map());
|
|
1531
|
+
d(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "canvas2d" });
|
|
1532
|
+
d(this, "onStats");
|
|
1533
|
+
d(this, "onViewChange");
|
|
1557
1534
|
const i = t.getContext("2d");
|
|
1558
1535
|
if (!i) throw new Error("Canvas 2D context is not available.");
|
|
1559
|
-
this.canvas = t, this.ctx = i, this.opts = { ...
|
|
1536
|
+
this.canvas = t, this.ctx = i, this.opts = { ...Je, ...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
1537
|
}
|
|
1561
1538
|
destroy() {
|
|
1562
1539
|
var t;
|
|
1563
1540
|
(t = this.resizeObserver) == null || t.disconnect();
|
|
1564
1541
|
}
|
|
1565
1542
|
clear() {
|
|
1566
|
-
this.document = void 0, this.bounds =
|
|
1543
|
+
this.document = void 0, this.bounds = M(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
|
|
1567
1544
|
}
|
|
1568
1545
|
setDocument(t) {
|
|
1569
1546
|
this.document = t, this.bounds = this.computeBounds(t), this.fitToView();
|
|
@@ -1578,7 +1555,7 @@ class Ft {
|
|
|
1578
1555
|
return { ...this.opts };
|
|
1579
1556
|
}
|
|
1580
1557
|
fitToView(t = 0.92) {
|
|
1581
|
-
if (!
|
|
1558
|
+
if (!D(this.bounds)) {
|
|
1582
1559
|
this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
|
|
1583
1560
|
return;
|
|
1584
1561
|
}
|
|
@@ -1621,7 +1598,7 @@ class Ft {
|
|
|
1621
1598
|
return { ...this.bounds };
|
|
1622
1599
|
}
|
|
1623
1600
|
getStats() {
|
|
1624
|
-
return
|
|
1601
|
+
return Qe(this.stats);
|
|
1625
1602
|
}
|
|
1626
1603
|
getZoomRatio() {
|
|
1627
1604
|
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
@@ -1696,7 +1673,7 @@ class Ft {
|
|
|
1696
1673
|
this.drawEntity(t, i, r);
|
|
1697
1674
|
}
|
|
1698
1675
|
drawEntity(t, r, i) {
|
|
1699
|
-
switch (t.kind ??
|
|
1676
|
+
switch (t.kind ?? R(r)) {
|
|
1700
1677
|
case "line":
|
|
1701
1678
|
return this.drawLine(t);
|
|
1702
1679
|
case "circle":
|
|
@@ -1732,8 +1709,8 @@ class Ft {
|
|
|
1732
1709
|
beginStyledPath(t, r = !1) {
|
|
1733
1710
|
const i = this.ctx;
|
|
1734
1711
|
i.save(), i.setTransform(this.dpr, 0, 0, this.dpr, 0, 0);
|
|
1735
|
-
const s =
|
|
1736
|
-
i.strokeStyle = s, i.fillStyle = r ? n : s, i.globalAlpha =
|
|
1712
|
+
const s = F(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;
|
|
1713
|
+
i.strokeStyle = s, i.fillStyle = r ? n : s, i.globalAlpha = T(Number(t.opacity ?? 1), 0, 1), i.lineCap = "round", i.lineJoin = "round";
|
|
1737
1714
|
const o = typeof t.lineweight == "number" && t.lineweight > 0 ? t.lineweight : 0;
|
|
1738
1715
|
i.lineWidth = Math.max(1, Math.min(12, o > 0 ? o / 30 : 1)), i.beginPath();
|
|
1739
1716
|
}
|
|
@@ -1758,7 +1735,7 @@ class Ft {
|
|
|
1758
1735
|
drawArc(t) {
|
|
1759
1736
|
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
1760
1737
|
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
1761
|
-
this.strokeWorldPolyline(t,
|
|
1738
|
+
this.strokeWorldPolyline(t, q(x(r), i, s, n, !0), !1);
|
|
1762
1739
|
}
|
|
1763
1740
|
drawPolyline(t) {
|
|
1764
1741
|
const r = t.vertices ?? t.points;
|
|
@@ -1767,15 +1744,15 @@ class Ft {
|
|
|
1767
1744
|
for (let o = 0; o < n; o++) {
|
|
1768
1745
|
const a = r[o], c = r[(o + 1) % r.length];
|
|
1769
1746
|
if (!m(a) || !m(c)) continue;
|
|
1770
|
-
const
|
|
1771
|
-
s.length > 0 &&
|
|
1747
|
+
const h = Xt(a, c, Number(a.bulge ?? 0));
|
|
1748
|
+
s.length > 0 && h.shift(), s.push(...h);
|
|
1772
1749
|
}
|
|
1773
1750
|
this.strokeWorldPolyline(t, s, i);
|
|
1774
1751
|
}
|
|
1775
1752
|
drawEllipse(t) {
|
|
1776
1753
|
const r = t.center, i = t.majorAxisEndPoint, s = Number(t.axisRatio ?? 1);
|
|
1777
1754
|
if (!m(r) || !m(i)) return this.markSkipped("ELLIPSE");
|
|
1778
|
-
const n =
|
|
1755
|
+
const n = K(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
1756
|
this.strokeWorldPolyline(t, n, o);
|
|
1780
1757
|
}
|
|
1781
1758
|
drawPoint(t) {
|
|
@@ -1785,7 +1762,7 @@ class Ft {
|
|
|
1785
1762
|
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
1763
|
}
|
|
1787
1764
|
drawText(t) {
|
|
1788
|
-
const r = t.insertionPoint ?? t.startPoint ?? t.center, i =
|
|
1765
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = _t(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
1789
1766
|
if (!m(r) || !i) return this.markSkipped(String(t.type));
|
|
1790
1767
|
this.drawTextAt(t, r, i, s, Number(t.rotation ?? 0));
|
|
1791
1768
|
}
|
|
@@ -1794,8 +1771,8 @@ class Ft {
|
|
|
1794
1771
|
if (i && r < this.opts.maxInsertDepth) {
|
|
1795
1772
|
const a = Q(t, i.basePoint ?? { x: 0, y: 0 });
|
|
1796
1773
|
for (const c of i.entities) {
|
|
1797
|
-
const
|
|
1798
|
-
this.drawEntityTracked(
|
|
1774
|
+
const h = jt(c, t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast });
|
|
1775
|
+
this.drawEntityTracked(tt(h, a), r + 1);
|
|
1799
1776
|
}
|
|
1800
1777
|
return;
|
|
1801
1778
|
}
|
|
@@ -1867,17 +1844,17 @@ class Ft {
|
|
|
1867
1844
|
drawImage(t) {
|
|
1868
1845
|
const r = t.insertionPoint;
|
|
1869
1846
|
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),
|
|
1847
|
+
const i = Number(t.width ?? 32), s = Number(t.height ?? 32), n = this.worldToScreen(r), o = this.worldToScreen({ x: r.x + i, y: r.y - s }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y), f = t.imageDataUrl;
|
|
1871
1848
|
if (f) {
|
|
1872
|
-
const
|
|
1873
|
-
if (
|
|
1874
|
-
this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(
|
|
1849
|
+
const u = this.getImage(f);
|
|
1850
|
+
if (u.complete && u.naturalWidth > 0) {
|
|
1851
|
+
this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(u, a, c, h, l), this.ctx.restore(), this.stats.drawn++;
|
|
1875
1852
|
return;
|
|
1876
1853
|
}
|
|
1877
|
-
|
|
1854
|
+
u.onload = () => this.render();
|
|
1878
1855
|
}
|
|
1879
1856
|
if (!this.opts.showImagePlaceholders) return this.markSkipped(String(t.type));
|
|
1880
|
-
this.beginStyledPath(t), this.ctx.rect(a, c,
|
|
1857
|
+
this.beginStyledPath(t), this.ctx.rect(a, c, h, l), this.ctx.moveTo(a, c), this.ctx.lineTo(a + h, c + l), this.ctx.moveTo(a + h, c), this.ctx.lineTo(a, c + l), this.finishStroke();
|
|
1881
1858
|
}
|
|
1882
1859
|
getImage(t) {
|
|
1883
1860
|
let r = this.imageCache.get(t);
|
|
@@ -1893,8 +1870,8 @@ class Ft {
|
|
|
1893
1870
|
const o = this.ctx, a = this.worldToScreen(r);
|
|
1894
1871
|
o.save(), o.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), o.translate(a.x, a.y), o.rotate(-n);
|
|
1895
1872
|
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 =
|
|
1897
|
-
for (const [
|
|
1873
|
+
o.font = `${c}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, o.fillStyle = F(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 = T(Number(t.opacity ?? 1), 0, 1), o.textBaseline = "alphabetic";
|
|
1874
|
+
for (const [h, l] of i.split(/\r?\n/g).entries()) o.fillText(l, 0, h * c * 1.22);
|
|
1898
1875
|
o.restore(), this.stats.drawn++;
|
|
1899
1876
|
}
|
|
1900
1877
|
strokeWorldPolyline(t, r, i) {
|
|
@@ -1915,51 +1892,51 @@ class Ft {
|
|
|
1915
1892
|
entityAnchor(t) {
|
|
1916
1893
|
for (const r of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
1917
1894
|
const i = t[r];
|
|
1918
|
-
if (m(i)) return
|
|
1895
|
+
if (m(i)) return x(i);
|
|
1919
1896
|
}
|
|
1920
|
-
if (Array.isArray(t.vertices) && m(t.vertices[0])) return
|
|
1897
|
+
if (Array.isArray(t.vertices) && m(t.vertices[0])) return x(t.vertices[0]);
|
|
1921
1898
|
if (Array.isArray(t.commands) && t.commands.length) {
|
|
1922
1899
|
const r = t.commands.find((i) => i.points.length > 0);
|
|
1923
|
-
if (r) return
|
|
1900
|
+
if (r) return x(r.points[0]);
|
|
1924
1901
|
}
|
|
1925
1902
|
}
|
|
1926
1903
|
computeBounds(t) {
|
|
1927
1904
|
var i;
|
|
1928
|
-
const r =
|
|
1905
|
+
const r = M();
|
|
1929
1906
|
if ((i = t.pages) != null && i.length)
|
|
1930
1907
|
for (const s of t.pages)
|
|
1931
|
-
|
|
1908
|
+
v(r, { x: 0, y: 0 }), v(r, { x: s.width, y: s.height });
|
|
1932
1909
|
for (const s of t.entities) this.includeEntityBounds(r, s, 0);
|
|
1933
1910
|
return Ht(r);
|
|
1934
1911
|
}
|
|
1935
1912
|
includeEntityBounds(t, r, i) {
|
|
1936
|
-
const s = String(r.type ?? "").toUpperCase(), n = r.kind ??
|
|
1913
|
+
const s = String(r.type ?? "").toUpperCase(), n = r.kind ?? R(s);
|
|
1937
1914
|
if (n === "insert") {
|
|
1938
1915
|
const o = this.lookupBlock(r.blockName ?? r.name);
|
|
1939
1916
|
if (o && i < this.opts.maxInsertDepth) {
|
|
1940
1917
|
const a = Q(r, o.basePoint ?? { x: 0, y: 0 });
|
|
1941
|
-
for (const c of o.entities) this.includeEntityBounds(t,
|
|
1918
|
+
for (const c of o.entities) this.includeEntityBounds(t, tt(c, a), i + 1);
|
|
1942
1919
|
return;
|
|
1943
1920
|
}
|
|
1944
1921
|
}
|
|
1945
1922
|
if (n === "line")
|
|
1946
|
-
m(r.startPoint) &&
|
|
1923
|
+
m(r.startPoint) && v(t, r.startPoint), m(r.endPoint) && v(t, r.endPoint);
|
|
1947
1924
|
else if (n === "circle" || n === "arc")
|
|
1948
1925
|
m(r.center) && Number.isFinite(r.radius) && Yt(t, r.center, Number(r.radius));
|
|
1949
1926
|
else if (n === "polyline" || n === "solid" || n === "spline")
|
|
1950
|
-
for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) &&
|
|
1927
|
+
for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) && v(t, o);
|
|
1951
1928
|
else if (n === "ellipse")
|
|
1952
|
-
m(r.center) && m(r.majorAxisEndPoint) &&
|
|
1929
|
+
m(r.center) && m(r.majorAxisEndPoint) && K(r.center, r.majorAxisEndPoint, Number(r.axisRatio ?? 1), Number(r.startAngle ?? 0), Number(r.endAngle ?? Math.PI * 2)).forEach((o) => v(t, o));
|
|
1953
1930
|
else if (n === "path")
|
|
1954
|
-
for (const o of r.commands ?? []) for (const a of o.points)
|
|
1931
|
+
for (const o of r.commands ?? []) for (const a of o.points) v(t, a);
|
|
1955
1932
|
else if (n === "hatch")
|
|
1956
1933
|
for (const o of r.loops ?? []) {
|
|
1957
|
-
for (const a of o.vertices ?? [])
|
|
1958
|
-
for (const a of o.commands ?? []) for (const c of a.points)
|
|
1934
|
+
for (const a of o.vertices ?? []) v(t, a);
|
|
1935
|
+
for (const a of o.commands ?? []) for (const c of a.points) v(t, c);
|
|
1959
1936
|
}
|
|
1960
1937
|
else {
|
|
1961
1938
|
const o = this.entityAnchor(r);
|
|
1962
|
-
o &&
|
|
1939
|
+
o && v(t, o);
|
|
1963
1940
|
}
|
|
1964
1941
|
}
|
|
1965
1942
|
lookupLayer(t) {
|
|
@@ -1984,7 +1961,7 @@ class Ft {
|
|
|
1984
1961
|
});
|
|
1985
1962
|
}
|
|
1986
1963
|
}
|
|
1987
|
-
function
|
|
1964
|
+
function Qe(e) {
|
|
1988
1965
|
return {
|
|
1989
1966
|
total: e.total,
|
|
1990
1967
|
drawn: e.drawn,
|
|
@@ -2023,43 +2000,43 @@ const tr = {
|
|
|
2023
2000
|
preserveDrawingBuffer: !1,
|
|
2024
2001
|
enableSpatialIndex: !0
|
|
2025
2002
|
};
|
|
2026
|
-
class
|
|
2003
|
+
class Ft {
|
|
2027
2004
|
constructor(t, r = {}) {
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2005
|
+
d(this, "canvas");
|
|
2006
|
+
d(this, "backend", "webgl");
|
|
2007
|
+
d(this, "gl");
|
|
2008
|
+
d(this, "program");
|
|
2009
|
+
d(this, "eventController", new AbortController());
|
|
2010
|
+
d(this, "imageCache", /* @__PURE__ */ new Map());
|
|
2011
|
+
d(this, "opts");
|
|
2012
|
+
d(this, "document");
|
|
2013
|
+
d(this, "bounds", M());
|
|
2014
|
+
d(this, "view", { centerX: 0, centerY: 0, scale: 1 });
|
|
2015
|
+
d(this, "fitScale", 1);
|
|
2016
|
+
d(this, "dpr", 1);
|
|
2017
|
+
d(this, "isDragging", !1);
|
|
2018
|
+
d(this, "lastPointer");
|
|
2019
|
+
d(this, "resizeObserver");
|
|
2020
|
+
d(this, "overlayCanvas");
|
|
2021
|
+
d(this, "overlayCtx");
|
|
2022
|
+
d(this, "scene");
|
|
2023
|
+
d(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: 0, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 });
|
|
2024
|
+
d(this, "rafHandle", 0);
|
|
2025
|
+
d(this, "onStats");
|
|
2026
|
+
d(this, "onViewChange");
|
|
2050
2027
|
const i = er(t, r);
|
|
2051
2028
|
if (!i) throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');
|
|
2052
2029
|
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
2030
|
}
|
|
2054
2031
|
static isSupported() {
|
|
2055
|
-
return
|
|
2032
|
+
return Zt();
|
|
2056
2033
|
}
|
|
2057
2034
|
destroy() {
|
|
2058
2035
|
var t, r;
|
|
2059
2036
|
this.eventController.abort(), (t = this.resizeObserver) == null || t.disconnect(), this.cancelScheduledRender(), this.disposeScene(), (r = this.overlayCanvas) == null || r.remove();
|
|
2060
2037
|
}
|
|
2061
2038
|
clear() {
|
|
2062
|
-
this.document = void 0, this.bounds =
|
|
2039
|
+
this.document = void 0, this.bounds = M(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.disposeScene(), this.render(), this.emitViewChange();
|
|
2063
2040
|
}
|
|
2064
2041
|
setDocument(t) {
|
|
2065
2042
|
this.document = t, this.bounds = cr(t, this.opts), this.disposeScene();
|
|
@@ -2070,7 +2047,7 @@ class Dt {
|
|
|
2070
2047
|
return this.document;
|
|
2071
2048
|
}
|
|
2072
2049
|
setOptions(t) {
|
|
2073
|
-
const r =
|
|
2050
|
+
const r = lr(this.opts, t);
|
|
2074
2051
|
if (this.opts = { ...this.opts, ...t }, r && this.document) {
|
|
2075
2052
|
this.setDocument(this.document);
|
|
2076
2053
|
return;
|
|
@@ -2081,7 +2058,7 @@ class Dt {
|
|
|
2081
2058
|
return { ...this.opts };
|
|
2082
2059
|
}
|
|
2083
2060
|
fitToView(t = 0.92) {
|
|
2084
|
-
if (!
|
|
2061
|
+
if (!D(this.bounds)) {
|
|
2085
2062
|
this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.render(), this.emitViewChange();
|
|
2086
2063
|
return;
|
|
2087
2064
|
}
|
|
@@ -2148,25 +2125,25 @@ class Dt {
|
|
|
2148
2125
|
return this.cancelScheduledRender(), this.renderNow();
|
|
2149
2126
|
}
|
|
2150
2127
|
renderNow() {
|
|
2151
|
-
var
|
|
2128
|
+
var h;
|
|
2152
2129
|
const t = performance.now(), r = this.gl;
|
|
2153
2130
|
r.viewport(0, 0, this.canvas.width, this.canvas.height);
|
|
2154
|
-
const i =
|
|
2131
|
+
const i = mt(this.opts.background, [11, 16, 32, 255]);
|
|
2155
2132
|
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
2133
|
let s = 0, n = 0;
|
|
2157
2134
|
const o = this.scene, a = this.visibleWorldBounds();
|
|
2158
2135
|
if (o) {
|
|
2159
2136
|
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
|
|
2161
|
-
s +=
|
|
2137
|
+
const l = this.drawBatches(o.lineBatches, r.LINES, a);
|
|
2138
|
+
s += l.visible, n += l.culled;
|
|
2162
2139
|
const f = this.drawBatches(o.triangleBatches, r.TRIANGLES, a);
|
|
2163
2140
|
s += f.visible, n += f.culled;
|
|
2164
|
-
const
|
|
2165
|
-
s +=
|
|
2141
|
+
const u = this.drawBatches(o.pointBatches, r.POINTS, a);
|
|
2142
|
+
s += u.visible, n += u.culled;
|
|
2166
2143
|
}
|
|
2167
2144
|
this.renderOverlay(a);
|
|
2168
2145
|
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 }, (
|
|
2146
|
+
return this.stats = o ? { ...o.stats, renderElapsedMs: c, backend: "webgl", primitiveCount: o.primitiveCount, visiblePrimitiveCount: s, culledPrimitiveCount: n, gpuMemoryBytes: o.gpuMemoryBytes, buildElapsedMs: o.buildElapsedMs } : { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: c, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 }, (h = this.onStats) == null || h.call(this, this.getStats()), this.getStats();
|
|
2170
2147
|
}
|
|
2171
2148
|
drawBatches(t, r, i) {
|
|
2172
2149
|
const s = this.gl;
|
|
@@ -2215,26 +2192,26 @@ class Dt {
|
|
|
2215
2192
|
const c = this.worldToScreen(o.point);
|
|
2216
2193
|
if (c.x < -512 || c.y < -512 || c.x > this.cssWidth + 512 || c.y > this.cssHeight + 512) continue;
|
|
2217
2194
|
t.save(), t.translate(c.x, c.y), t.rotate(-o.rotation);
|
|
2218
|
-
const
|
|
2219
|
-
t.font = `${
|
|
2220
|
-
for (const [
|
|
2195
|
+
const h = Math.max(4, Math.min(256, a));
|
|
2196
|
+
t.font = `${h}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, t.fillStyle = o.color, t.globalAlpha = o.opacity, t.textBaseline = "alphabetic";
|
|
2197
|
+
for (const [l, f] of o.text.split(/\r?\n/g).entries()) t.fillText(f, 0, l * h * 1.22);
|
|
2221
2198
|
t.restore(), n++;
|
|
2222
2199
|
}
|
|
2223
2200
|
}
|
|
2224
2201
|
drawImagesOverlay(t, r, i) {
|
|
2225
2202
|
for (const s of r) {
|
|
2226
2203
|
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),
|
|
2228
|
-
if (!(
|
|
2204
|
+
const n = this.worldToScreen(s.point), o = this.worldToScreen({ x: s.point.x + s.width, y: s.point.y - s.height }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y);
|
|
2205
|
+
if (!(h < 1 || l < 1)) {
|
|
2229
2206
|
if (s.source) {
|
|
2230
2207
|
const f = this.getImage(s.source);
|
|
2231
2208
|
if (f.complete && f.naturalWidth > 0) {
|
|
2232
|
-
t.save(), t.globalAlpha = s.opacity, t.drawImage(f, a, c,
|
|
2209
|
+
t.save(), t.globalAlpha = s.opacity, t.drawImage(f, a, c, h, l), t.restore();
|
|
2233
2210
|
continue;
|
|
2234
2211
|
}
|
|
2235
2212
|
f.onload = () => this.scheduleRender();
|
|
2236
2213
|
}
|
|
2237
|
-
this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = s.color, t.globalAlpha = s.opacity, t.lineWidth = 1, t.strokeRect(a, c,
|
|
2214
|
+
this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = s.color, t.globalAlpha = s.opacity, t.lineWidth = 1, t.strokeRect(a, c, h, l), t.beginPath(), t.moveTo(a, c), t.lineTo(a + h, c + l), t.moveTo(a + h, c), t.lineTo(a, c + l), t.stroke(), t.restore());
|
|
2238
2215
|
}
|
|
2239
2216
|
}
|
|
2240
2217
|
}
|
|
@@ -2308,7 +2285,7 @@ class Dt {
|
|
|
2308
2285
|
});
|
|
2309
2286
|
}
|
|
2310
2287
|
}
|
|
2311
|
-
function
|
|
2288
|
+
function Zt() {
|
|
2312
2289
|
if (typeof document > "u") return !1;
|
|
2313
2290
|
const e = document.createElement("canvas");
|
|
2314
2291
|
return !!(e.getContext("webgl2") ?? e.getContext("webgl") ?? e.getContext("experimental-webgl"));
|
|
@@ -2352,12 +2329,12 @@ function rr(e) {
|
|
|
2352
2329
|
`, i = Wt(e, e.VERTEX_SHADER, t), s = Wt(e, e.FRAGMENT_SHADER, r), n = e.createProgram();
|
|
2353
2330
|
if (!n) throw new Error("Failed to create WebGL program.");
|
|
2354
2331
|
if (e.attachShader(n, i), e.attachShader(n, s), e.linkProgram(n), !e.getProgramParameter(n, e.LINK_STATUS)) {
|
|
2355
|
-
const
|
|
2356
|
-
throw e.deleteProgram(n), new Error(
|
|
2332
|
+
const l = e.getProgramInfoLog(n) ?? "Unknown WebGL program link error.";
|
|
2333
|
+
throw e.deleteProgram(n), new Error(l);
|
|
2357
2334
|
}
|
|
2358
2335
|
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"),
|
|
2360
|
-
if (!o || !a || !c || !
|
|
2336
|
+
const o = e.getUniformLocation(n, "u_viewCenter"), a = e.getUniformLocation(n, "u_scale"), c = e.getUniformLocation(n, "u_viewport"), h = e.getUniformLocation(n, "u_pointSize");
|
|
2337
|
+
if (!o || !a || !c || !h) throw new Error("Failed to resolve WebGL shader uniforms.");
|
|
2361
2338
|
return {
|
|
2362
2339
|
program: n,
|
|
2363
2340
|
aPosition: e.getAttribLocation(n, "a_position"),
|
|
@@ -2365,7 +2342,7 @@ function rr(e) {
|
|
|
2365
2342
|
uViewCenter: o,
|
|
2366
2343
|
uScale: a,
|
|
2367
2344
|
uViewport: c,
|
|
2368
|
-
uPointSize:
|
|
2345
|
+
uPointSize: h
|
|
2369
2346
|
};
|
|
2370
2347
|
}
|
|
2371
2348
|
function Wt(e, t, r) {
|
|
@@ -2380,10 +2357,10 @@ function Wt(e, t, r) {
|
|
|
2380
2357
|
function ir(e, t) {
|
|
2381
2358
|
let r = 0;
|
|
2382
2359
|
const i = (a) => a.map((c) => {
|
|
2383
|
-
const
|
|
2360
|
+
const h = Rt(e, c.positions), l = Rt(e, c.colors), f = c.positions.byteLength + c.colors.byteLength;
|
|
2384
2361
|
return r += f, {
|
|
2385
|
-
positionBuffer:
|
|
2386
|
-
colorBuffer:
|
|
2362
|
+
positionBuffer: h,
|
|
2363
|
+
colorBuffer: l,
|
|
2387
2364
|
vertexCount: c.positions.length / 2,
|
|
2388
2365
|
primitiveCount: c.primitiveCount,
|
|
2389
2366
|
bounds: c.bounds,
|
|
@@ -2403,30 +2380,30 @@ function ir(e, t) {
|
|
|
2403
2380
|
buildElapsedMs: t.buildElapsedMs
|
|
2404
2381
|
};
|
|
2405
2382
|
}
|
|
2406
|
-
function
|
|
2383
|
+
function Rt(e, t) {
|
|
2407
2384
|
const r = e.createBuffer();
|
|
2408
2385
|
if (!r) throw new Error("Failed to create WebGL buffer.");
|
|
2409
2386
|
return e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW), r;
|
|
2410
2387
|
}
|
|
2411
2388
|
function sr(e, t, r) {
|
|
2412
|
-
const i = performance.now(), s =
|
|
2389
|
+
const i = performance.now(), s = D(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
2390
|
for (const a of e.entities) n.addEntityTracked(a, 0);
|
|
2414
2391
|
const o = n.finalize();
|
|
2415
2392
|
return o.buildElapsedMs = performance.now() - i, o;
|
|
2416
2393
|
}
|
|
2417
2394
|
class nr {
|
|
2418
2395
|
constructor(t, r, i, s) {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2396
|
+
d(this, "lineBuckets", /* @__PURE__ */ new Map());
|
|
2397
|
+
d(this, "triangleBuckets", /* @__PURE__ */ new Map());
|
|
2398
|
+
d(this, "pointBuckets", /* @__PURE__ */ new Map());
|
|
2399
|
+
d(this, "textItems", []);
|
|
2400
|
+
d(this, "imageItems", []);
|
|
2401
|
+
d(this, "stats", { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 });
|
|
2402
|
+
d(this, "tileSize");
|
|
2403
|
+
d(this, "maxVerticesPerBatch");
|
|
2404
|
+
d(this, "primitiveCount", 0);
|
|
2428
2405
|
this.document = t, this.opts = r, this.bounds = i, this.origin = s;
|
|
2429
|
-
const n =
|
|
2406
|
+
const n = D(i) ? Math.max(i.maxX - i.minX, i.maxY - i.minY, 1e-9) : 1;
|
|
2430
2407
|
this.tileSize = r.enableSpatialIndex ? n / Math.max(8, r.spatialIndexCellCount) : Number.POSITIVE_INFINITY, this.maxVerticesPerBatch = Math.max(4096, Math.floor(r.maxVerticesPerBatch));
|
|
2431
2408
|
}
|
|
2432
2409
|
addEntityTracked(t, r) {
|
|
@@ -2455,7 +2432,7 @@ class nr {
|
|
|
2455
2432
|
};
|
|
2456
2433
|
}
|
|
2457
2434
|
addEntity(t, r, i) {
|
|
2458
|
-
switch (t.kind ??
|
|
2435
|
+
switch (t.kind ?? R(r)) {
|
|
2459
2436
|
case "line":
|
|
2460
2437
|
return this.addLineEntity(t);
|
|
2461
2438
|
case "circle":
|
|
@@ -2495,13 +2472,13 @@ class nr {
|
|
|
2495
2472
|
addCircleEntity(t) {
|
|
2496
2473
|
const r = t.center, i = Number(t.radius);
|
|
2497
2474
|
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 =
|
|
2475
|
+
const s = Math.max(16, Math.min(this.opts.maxCurveSegments, Math.ceil(Math.sqrt(Math.abs(i)) * 12))), n = q(r, i, 0, Math.PI * 2, !0, s);
|
|
2499
2476
|
this.addPolyline(n, !0, this.strokeBytes(t)), this.stats.drawn++;
|
|
2500
2477
|
}
|
|
2501
2478
|
addArcEntity(t) {
|
|
2502
2479
|
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
2503
2480
|
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
2504
|
-
this.addPolyline(
|
|
2481
|
+
this.addPolyline(q(r, i, s, n, !0, this.opts.maxCurveSegments), !1, this.strokeBytes(t)), this.stats.drawn++;
|
|
2505
2482
|
}
|
|
2506
2483
|
addPolylineEntity(t) {
|
|
2507
2484
|
const r = t.vertices ?? t.points;
|
|
@@ -2510,28 +2487,28 @@ class nr {
|
|
|
2510
2487
|
for (let o = 0; o < n; o++) {
|
|
2511
2488
|
const a = r[o], c = r[(o + 1) % r.length];
|
|
2512
2489
|
if (!m(a) || !m(c)) continue;
|
|
2513
|
-
const
|
|
2514
|
-
s.length > 0 &&
|
|
2490
|
+
const h = Xt(a, c, Number(a.bulge ?? 0), Math.max(4, Math.min(24, this.opts.maxCurveSegments / 4)));
|
|
2491
|
+
s.length > 0 && h.shift(), s.push(...h);
|
|
2515
2492
|
}
|
|
2516
2493
|
if (s.length < 2) return this.markSkipped(String(t.type));
|
|
2517
2494
|
this.addPolyline(s, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
2518
2495
|
}
|
|
2519
2496
|
addEllipseEntity(t) {
|
|
2520
2497
|
if (!m(t.center) || !m(t.majorAxisEndPoint)) return this.markSkipped("ELLIPSE");
|
|
2521
|
-
const r =
|
|
2498
|
+
const r = K(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
2499
|
this.addPolyline(r, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
2523
2500
|
}
|
|
2524
2501
|
addTextEntity(t) {
|
|
2525
|
-
const r = t.insertionPoint ?? t.startPoint ?? t.center, i =
|
|
2502
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = _t(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
2526
2503
|
if (!m(r) || !i || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2527
|
-
const n =
|
|
2504
|
+
const n = x(r), o = Math.max(1, i.split(/\r?\n/g).reduce((c, h) => Math.max(c, h.length), 0)) * Math.abs(s) * 0.62, a = Math.max(1, i.split(/\r?\n/g).length) * Math.abs(s) * 1.22;
|
|
2528
2505
|
this.textItems.push({
|
|
2529
2506
|
point: n,
|
|
2530
2507
|
text: i,
|
|
2531
2508
|
height: s,
|
|
2532
2509
|
rotation: Number(t.rotation ?? 0),
|
|
2533
|
-
color:
|
|
2534
|
-
opacity:
|
|
2510
|
+
color: F(t, this.document, this.colorOptions()),
|
|
2511
|
+
opacity: T(Number(t.opacity ?? 1), 0, 1),
|
|
2535
2512
|
bounds: { minX: n.x - o * 0.1, minY: n.y - a, maxX: n.x + o, maxY: n.y + a }
|
|
2536
2513
|
}), this.stats.drawn++;
|
|
2537
2514
|
}
|
|
@@ -2546,7 +2523,7 @@ class nr {
|
|
|
2546
2523
|
const n = Q(t, i.basePoint ?? { x: 0, y: 0 });
|
|
2547
2524
|
for (const o of i.entities) {
|
|
2548
2525
|
const a = jt(o, t, this.document, this.colorOptions());
|
|
2549
|
-
this.addEntityTracked(
|
|
2526
|
+
this.addEntityTracked(tt(a, n), r + 1);
|
|
2550
2527
|
}
|
|
2551
2528
|
return;
|
|
2552
2529
|
}
|
|
@@ -2558,7 +2535,7 @@ class nr {
|
|
|
2558
2535
|
addSolidEntity(t) {
|
|
2559
2536
|
const r = t.vertices ?? t.points;
|
|
2560
2537
|
if (!Array.isArray(r) || r.length < 3) return this.markSkipped(String(t.type));
|
|
2561
|
-
const i = r.filter(m).map(
|
|
2538
|
+
const i = r.filter(m).map(x);
|
|
2562
2539
|
if (i.length < 3) return this.markSkipped(String(t.type));
|
|
2563
2540
|
const s = this.fillBytes(t) ?? this.strokeBytes(t);
|
|
2564
2541
|
this.addTriangleFan(i, s), this.addPolyline(i, !0, this.strokeBytes(t)), this.stats.drawn++;
|
|
@@ -2570,7 +2547,7 @@ class nr {
|
|
|
2570
2547
|
const i = this.strokeBytes(t), s = this.fillBytes(t);
|
|
2571
2548
|
let n = !1;
|
|
2572
2549
|
for (const a of r) {
|
|
2573
|
-
const c = (o = a.commands) != null && o.length ?
|
|
2550
|
+
const c = (o = a.commands) != null && o.length ? Dt(a.commands, this.opts.maxCurveSegments) : (a.vertices ?? []).filter(m).map(x);
|
|
2574
2551
|
c.length < 2 || (this.addPolyline(c, !0, i), s && c.length >= 3 && this.addTriangleFan(c, s), n = !0);
|
|
2575
2552
|
}
|
|
2576
2553
|
if (!n) return this.markSkipped("HATCH");
|
|
@@ -2580,12 +2557,12 @@ class nr {
|
|
|
2580
2557
|
var i;
|
|
2581
2558
|
const r = (i = t.fitPoints) != null && i.length ? t.fitPoints : t.controlPoints;
|
|
2582
2559
|
if (!r || r.length < 2) return this.markSkipped("SPLINE");
|
|
2583
|
-
this.addPolyline(r.filter(m).map(
|
|
2560
|
+
this.addPolyline(r.filter(m).map(x), !!t.isClosed, this.strokeBytes(t)), this.stats.drawn++;
|
|
2584
2561
|
}
|
|
2585
2562
|
addPathEntity(t) {
|
|
2586
2563
|
var s;
|
|
2587
2564
|
if (!((s = t.commands) != null && s.length)) return this.markSkipped(String(t.type));
|
|
2588
|
-
const r =
|
|
2565
|
+
const r = Dt(t.commands, this.opts.maxCurveSegments);
|
|
2589
2566
|
if (r.length < 2) return this.markSkipped(String(t.type));
|
|
2590
2567
|
this.addPolyline(r, !1, this.strokeBytes(t));
|
|
2591
2568
|
const i = this.fillBytes(t);
|
|
@@ -2596,15 +2573,15 @@ class nr {
|
|
|
2596
2573
|
if (!m(r)) return this.markSkipped(String(t.type));
|
|
2597
2574
|
const i = Number(t.width ?? 32), s = Number(t.height ?? 32);
|
|
2598
2575
|
if (!Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2599
|
-
const n =
|
|
2600
|
-
this.imageItems.push({ point: n, width: i, height: s, source: t.imageDataUrl ?? t.imageSource, color:
|
|
2576
|
+
const n = x(r), o = at([n, { x: n.x + i, y: n.y - s }]);
|
|
2577
|
+
this.imageItems.push({ point: n, width: i, height: s, source: t.imageDataUrl ?? t.imageSource, color: F(t, this.document, this.colorOptions()), opacity: T(Number(t.opacity ?? 1), 0, 1), bounds: o }), this.stats.drawn++;
|
|
2601
2578
|
}
|
|
2602
2579
|
addUnsupportedMarker(t) {
|
|
2603
|
-
const r =
|
|
2580
|
+
const r = qt(t);
|
|
2604
2581
|
r && this.addPoint(r, this.strokeBytes(t));
|
|
2605
2582
|
}
|
|
2606
2583
|
addPolyline(t, r, i) {
|
|
2607
|
-
const s = t.filter(m).map(
|
|
2584
|
+
const s = t.filter(m).map(x);
|
|
2608
2585
|
if (!(s.length < 2)) {
|
|
2609
2586
|
for (let n = 0; n < s.length - 1; n++) this.addSegment(s[n], s[n + 1], i);
|
|
2610
2587
|
r && this.addSegment(s[s.length - 1], s[0], i);
|
|
@@ -2613,23 +2590,23 @@ class nr {
|
|
|
2613
2590
|
addSegment(t, r, i) {
|
|
2614
2591
|
if (!m(t) || !m(r) || Math.hypot(t.x - r.x, t.y - r.y) <= 1e-14) return;
|
|
2615
2592
|
const s = this.batchFor(this.lineBuckets, at([t, r]));
|
|
2616
|
-
|
|
2593
|
+
I(s, t, i, this.origin), I(s, r, i, this.origin), s.primitiveCount++, this.primitiveCount++;
|
|
2617
2594
|
}
|
|
2618
2595
|
addPoint(t, r) {
|
|
2619
|
-
const i = this.batchFor(this.pointBuckets,
|
|
2620
|
-
|
|
2596
|
+
const i = this.batchFor(this.pointBuckets, hr(t));
|
|
2597
|
+
I(i, t, r, this.origin), i.primitiveCount++, this.primitiveCount++;
|
|
2621
2598
|
}
|
|
2622
2599
|
addTriangleFan(t, r) {
|
|
2623
|
-
const i = t.filter(m).map(
|
|
2600
|
+
const i = t.filter(m).map(x);
|
|
2624
2601
|
if (i.length < 3) return;
|
|
2625
2602
|
const s = at(i), n = this.batchFor(this.triangleBuckets, s);
|
|
2626
2603
|
for (let o = 1; o < i.length - 1; o++)
|
|
2627
|
-
|
|
2604
|
+
I(n, i[0], r, this.origin), I(n, i[o], r, this.origin), I(n, i[o + 1], r, this.origin), n.primitiveCount++, this.primitiveCount++;
|
|
2628
2605
|
}
|
|
2629
2606
|
batchFor(t, r) {
|
|
2630
2607
|
const i = this.bucketKey(r);
|
|
2631
2608
|
let s = t.get(i);
|
|
2632
|
-
return s || (s = or(), t.set(i, s)),
|
|
2609
|
+
return s || (s = or(), t.set(i, s)), v(s.bounds, { x: r.minX, y: r.minY }), v(s.bounds, { x: r.maxX, y: r.maxY }), s;
|
|
2633
2610
|
}
|
|
2634
2611
|
bucketKey(t) {
|
|
2635
2612
|
if (!Number.isFinite(this.tileSize)) return "all";
|
|
@@ -2637,11 +2614,11 @@ class nr {
|
|
|
2637
2614
|
return `${s}:${n}`;
|
|
2638
2615
|
}
|
|
2639
2616
|
strokeBytes(t) {
|
|
2640
|
-
return
|
|
2617
|
+
return mt(F(t, this.document, this.colorOptions()), [255, 255, 255, 255], T(Number(t.opacity ?? 1), 0, 1));
|
|
2641
2618
|
}
|
|
2642
2619
|
fillBytes(t) {
|
|
2643
2620
|
const r = ft(t, this.document, this.colorOptions());
|
|
2644
|
-
return r ?
|
|
2621
|
+
return r ? mt(r, [255, 255, 255, 255], T(Number(t.opacity ?? 1), 0, 1)) : void 0;
|
|
2645
2622
|
}
|
|
2646
2623
|
colorOptions() {
|
|
2647
2624
|
return { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast };
|
|
@@ -2659,25 +2636,25 @@ class nr {
|
|
|
2659
2636
|
}
|
|
2660
2637
|
}
|
|
2661
2638
|
function or() {
|
|
2662
|
-
return { positions: [], colors: [], bounds:
|
|
2639
|
+
return { positions: [], colors: [], bounds: M(), primitiveCount: 0 };
|
|
2663
2640
|
}
|
|
2664
|
-
function
|
|
2641
|
+
function I(e, t, r, i) {
|
|
2665
2642
|
e.positions.push(t.x - i.x, t.y - i.y), e.colors.push(r[0], r[1], r[2], r[3]);
|
|
2666
2643
|
}
|
|
2667
2644
|
function ot(e, t) {
|
|
2668
2645
|
const r = [];
|
|
2669
2646
|
for (const i of e.values()) {
|
|
2670
2647
|
const s = i.positions.length / 2;
|
|
2671
|
-
if (s <= 0 || !
|
|
2648
|
+
if (s <= 0 || !D(i.bounds)) continue;
|
|
2672
2649
|
if (s <= t) {
|
|
2673
2650
|
r.push({ positions: new Float32Array(i.positions), colors: new Uint8Array(i.colors), bounds: { ...i.bounds }, primitiveCount: i.primitiveCount });
|
|
2674
2651
|
continue;
|
|
2675
2652
|
}
|
|
2676
2653
|
const n = ar(i), o = Math.max(n, Math.floor(t / n) * n);
|
|
2677
2654
|
for (let a = 0; a < s; a += o) {
|
|
2678
|
-
const c = Math.min(s, a + o),
|
|
2679
|
-
for (let
|
|
2680
|
-
r.push({ positions: new Float32Array(
|
|
2655
|
+
const c = Math.min(s, a + o), h = i.positions.slice(a * 2, c * 2), l = i.colors.slice(a * 4, c * 4), f = M();
|
|
2656
|
+
for (let u = 0; u < h.length; u += 2) v(f, { x: h[u], y: h[u + 1] });
|
|
2657
|
+
r.push({ positions: new Float32Array(h), colors: new Uint8Array(l), bounds: { ...i.bounds }, primitiveCount: Math.floor((c - a) / n) });
|
|
2681
2658
|
}
|
|
2682
2659
|
}
|
|
2683
2660
|
return r;
|
|
@@ -2688,98 +2665,98 @@ function ar(e) {
|
|
|
2688
2665
|
}
|
|
2689
2666
|
function cr(e, t) {
|
|
2690
2667
|
var n;
|
|
2691
|
-
const r =
|
|
2668
|
+
const r = M();
|
|
2692
2669
|
if ((n = e.pages) != null && n.length)
|
|
2693
2670
|
for (const o of e.pages)
|
|
2694
|
-
|
|
2671
|
+
v(r, { x: 0, y: 0 }), v(r, { x: o.width, y: o.height });
|
|
2695
2672
|
const i = (o) => {
|
|
2696
2673
|
if (o)
|
|
2697
2674
|
return e.blocks[o] ?? e.blocks[o.toLowerCase()] ?? Object.values(e.blocks).find((a) => a.name.toLowerCase() === o.toLowerCase());
|
|
2698
2675
|
}, s = (o, a) => {
|
|
2699
|
-
const c = String(o.type ?? "").toUpperCase(),
|
|
2700
|
-
if (
|
|
2701
|
-
const
|
|
2702
|
-
if (
|
|
2703
|
-
const f = Q(o,
|
|
2704
|
-
for (const
|
|
2676
|
+
const c = String(o.type ?? "").toUpperCase(), h = o.kind ?? R(c);
|
|
2677
|
+
if (h === "insert") {
|
|
2678
|
+
const l = i(o.blockName ?? o.name);
|
|
2679
|
+
if (l && a < t.maxInsertDepth) {
|
|
2680
|
+
const f = Q(o, l.basePoint ?? { x: 0, y: 0 });
|
|
2681
|
+
for (const u of l.entities) s(tt(u, f), a + 1);
|
|
2705
2682
|
return;
|
|
2706
2683
|
}
|
|
2707
2684
|
}
|
|
2708
|
-
if (
|
|
2709
|
-
m(o.startPoint) &&
|
|
2710
|
-
else if (
|
|
2685
|
+
if (h === "line")
|
|
2686
|
+
m(o.startPoint) && v(r, o.startPoint), m(o.endPoint) && v(r, o.endPoint);
|
|
2687
|
+
else if (h === "circle" || h === "arc")
|
|
2711
2688
|
m(o.center) && Number.isFinite(o.radius) && Yt(r, o.center, Number(o.radius));
|
|
2712
|
-
else if (
|
|
2713
|
-
for (const
|
|
2714
|
-
else if (
|
|
2715
|
-
m(o.center) && m(o.majorAxisEndPoint) &&
|
|
2716
|
-
else if (
|
|
2717
|
-
for (const
|
|
2718
|
-
else if (
|
|
2719
|
-
for (const
|
|
2720
|
-
for (const f of
|
|
2721
|
-
for (const f of
|
|
2689
|
+
else if (h === "polyline" || h === "solid" || h === "spline")
|
|
2690
|
+
for (const l of [...o.vertices ?? [], ...o.points ?? [], ...o.controlPoints ?? [], ...o.fitPoints ?? []]) m(l) && v(r, l);
|
|
2691
|
+
else if (h === "ellipse")
|
|
2692
|
+
m(o.center) && m(o.majorAxisEndPoint) && K(o.center, o.majorAxisEndPoint, Number(o.axisRatio ?? 1), Number(o.startAngle ?? 0), Number(o.endAngle ?? Math.PI * 2), t.maxCurveSegments).forEach((l) => v(r, l));
|
|
2693
|
+
else if (h === "path")
|
|
2694
|
+
for (const l of o.commands ?? []) for (const f of l.points) v(r, f);
|
|
2695
|
+
else if (h === "hatch")
|
|
2696
|
+
for (const l of o.loops ?? []) {
|
|
2697
|
+
for (const f of l.vertices ?? []) v(r, f);
|
|
2698
|
+
for (const f of l.commands ?? []) for (const u of f.points) v(r, u);
|
|
2722
2699
|
}
|
|
2723
2700
|
else {
|
|
2724
|
-
const
|
|
2725
|
-
|
|
2701
|
+
const l = qt(o);
|
|
2702
|
+
l && v(r, l);
|
|
2726
2703
|
}
|
|
2727
2704
|
};
|
|
2728
2705
|
for (const o of e.entities) s(o, 0);
|
|
2729
2706
|
return Ht(r);
|
|
2730
2707
|
}
|
|
2731
|
-
function
|
|
2708
|
+
function Dt(e, t) {
|
|
2732
2709
|
const r = [];
|
|
2733
2710
|
let i, s;
|
|
2734
2711
|
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(
|
|
2712
|
+
(!r.length || Math.hypot(r[r.length - 1].x - o.x, r[r.length - 1].y - o.y) > 1e-12) && r.push(x(o)), i = x(o);
|
|
2736
2713
|
};
|
|
2737
2714
|
for (const o of e)
|
|
2738
2715
|
if (o.cmd === "M")
|
|
2739
|
-
i =
|
|
2716
|
+
i = x(o.points[0]), s = i, n(i);
|
|
2740
2717
|
else if (o.cmd === "L")
|
|
2741
2718
|
n(o.points[0]);
|
|
2742
2719
|
else if (o.cmd === "Q" && i && o.points.length >= 2) {
|
|
2743
|
-
const a = i, [c,
|
|
2744
|
-
for (let f = 1; f <=
|
|
2745
|
-
const
|
|
2746
|
-
n({ x: p * p * a.x + 2 * p *
|
|
2720
|
+
const a = i, [c, h] = o.points, l = Math.max(4, Math.min(t, 24));
|
|
2721
|
+
for (let f = 1; f <= l; f++) {
|
|
2722
|
+
const u = f / l, p = 1 - u;
|
|
2723
|
+
n({ x: p * p * a.x + 2 * p * u * c.x + u * u * h.x, y: p * p * a.y + 2 * p * u * c.y + u * u * h.y });
|
|
2747
2724
|
}
|
|
2748
2725
|
} else if (o.cmd === "C" && i && o.points.length >= 3) {
|
|
2749
|
-
const a = i, [c,
|
|
2750
|
-
for (let
|
|
2751
|
-
const p =
|
|
2726
|
+
const a = i, [c, h, l] = o.points, f = Math.max(6, Math.min(t, 32));
|
|
2727
|
+
for (let u = 1; u <= f; u++) {
|
|
2728
|
+
const p = u / f, g = 1 - p;
|
|
2752
2729
|
n({
|
|
2753
|
-
x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p *
|
|
2754
|
-
y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p *
|
|
2730
|
+
x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p * h.x + p ** 3 * l.x,
|
|
2731
|
+
y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p * h.y + p ** 3 * l.y
|
|
2755
2732
|
});
|
|
2756
2733
|
}
|
|
2757
2734
|
} else o.cmd === "Z" && s && n(s);
|
|
2758
2735
|
return r;
|
|
2759
2736
|
}
|
|
2760
|
-
function
|
|
2737
|
+
function qt(e) {
|
|
2761
2738
|
for (const t of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
2762
2739
|
const r = e[t];
|
|
2763
|
-
if (m(r)) return
|
|
2740
|
+
if (m(r)) return x(r);
|
|
2764
2741
|
}
|
|
2765
|
-
if (Array.isArray(e.vertices) && m(e.vertices[0])) return
|
|
2742
|
+
if (Array.isArray(e.vertices) && m(e.vertices[0])) return x(e.vertices[0]);
|
|
2766
2743
|
if (Array.isArray(e.commands) && e.commands.length) {
|
|
2767
2744
|
const t = e.commands.find((r) => r.points.length > 0);
|
|
2768
|
-
if (t) return
|
|
2745
|
+
if (t) return x(t.points[0]);
|
|
2769
2746
|
}
|
|
2770
2747
|
}
|
|
2771
2748
|
function at(e) {
|
|
2772
|
-
const t =
|
|
2773
|
-
for (const r of e)
|
|
2749
|
+
const t = M();
|
|
2750
|
+
for (const r of e) v(t, r);
|
|
2774
2751
|
return t;
|
|
2775
2752
|
}
|
|
2776
|
-
function
|
|
2753
|
+
function hr(e) {
|
|
2777
2754
|
return { minX: e.x, minY: e.y, maxX: e.x, maxY: e.y };
|
|
2778
2755
|
}
|
|
2779
2756
|
function ct(e, t) {
|
|
2780
2757
|
return e.minX <= t.maxX && e.maxX >= t.minX && e.minY <= t.maxY && e.maxY >= t.minY;
|
|
2781
2758
|
}
|
|
2782
|
-
function
|
|
2759
|
+
function lr(e, t) {
|
|
2783
2760
|
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
2761
|
}
|
|
2785
2762
|
function fr(e, t) {
|
|
@@ -2801,7 +2778,7 @@ function dr(e) {
|
|
|
2801
2778
|
buildElapsedMs: e.buildElapsedMs
|
|
2802
2779
|
};
|
|
2803
2780
|
}
|
|
2804
|
-
function
|
|
2781
|
+
function mt(e, t, r = 1) {
|
|
2805
2782
|
const i = e.trim().toLowerCase();
|
|
2806
2783
|
let s;
|
|
2807
2784
|
if (/^#[0-9a-f]{3}$/i.test(i))
|
|
@@ -2811,8 +2788,8 @@ function pt(e, t, r = 1) {
|
|
|
2811
2788
|
else {
|
|
2812
2789
|
const o = i.match(/^rgba?\(([^)]+)\)$/i);
|
|
2813
2790
|
if (o) {
|
|
2814
|
-
const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((
|
|
2815
|
-
|
|
2791
|
+
const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((l) => l.includes("%")), h = a.map((l) => Number(l.replace("%", "")));
|
|
2792
|
+
h.length >= 3 && h.slice(0, 3).every(Number.isFinite) && (s = [X(c ? h[0] * 2.55 : h[0]), X(c ? h[1] * 2.55 : h[1]), X(c ? h[2] * 2.55 : h[2]), X((Number.isFinite(h[3]) ? h[3] : 1) * 255)]);
|
|
2816
2793
|
}
|
|
2817
2794
|
}
|
|
2818
2795
|
const n = s ?? t;
|
|
@@ -2823,58 +2800,50 @@ function X(e) {
|
|
|
2823
2800
|
}
|
|
2824
2801
|
class ur {
|
|
2825
2802
|
constructor(t = {}) {
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2803
|
+
d(this, "canvas");
|
|
2804
|
+
d(this, "renderer");
|
|
2805
|
+
d(this, "registry");
|
|
2806
|
+
d(this, "nativeHost");
|
|
2807
|
+
d(this, "options");
|
|
2808
|
+
d(this, "lastResult");
|
|
2809
|
+
d(this, "activeNativeLoader");
|
|
2810
|
+
var r;
|
|
2811
|
+
if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ?? ze(t), t.loaders) for (const i of t.loaders) this.registry.register(i);
|
|
2812
|
+
if (this.canvas = t.canvas ?? document.createElement("canvas"), this.canvas.classList.add("cad-viewer-canvas"), t.container)
|
|
2813
|
+
t.container.classList.add("cad-viewer-container"), t.canvas || (this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", t.container.appendChild(this.canvas)), this.nativeHost = t.nativeHost ?? document.createElement("div"), this.nativeHost.classList.add("cad-viewer-native-host"), t.nativeHost || t.container.appendChild(this.nativeHost);
|
|
2814
|
+
else if (t.nativeHost)
|
|
2815
|
+
this.nativeHost = t.nativeHost, this.nativeHost.classList.add("cad-viewer-native-host");
|
|
2816
|
+
else if ((r = t.canvas) != null && r.parentElement) {
|
|
2817
|
+
t.canvas.parentElement.classList.add("cad-viewer-container");
|
|
2818
|
+
const i = document.createElement("div");
|
|
2819
|
+
i.classList.add("cad-viewer-native-host"), t.canvas.parentElement.appendChild(i), this.nativeHost = i;
|
|
2820
|
+
}
|
|
2821
|
+
this.renderer = pr(t.renderer ?? "auto", this.canvas, t.canvasOptions), this.renderer.onStats = (i) => {
|
|
2822
|
+
var s, n;
|
|
2823
|
+
return (n = (s = this.options).onRenderStats) == null ? void 0 : n.call(s, i);
|
|
2824
|
+
}, this.renderer.onViewChange = (i) => {
|
|
2825
|
+
var s, n;
|
|
2826
|
+
return (n = (s = this.options).onViewChange) == null ? void 0 : n.call(s, i);
|
|
2838
2827
|
};
|
|
2839
2828
|
}
|
|
2840
2829
|
registerLoader(t) {
|
|
2841
2830
|
return this.registry.register(t), this;
|
|
2842
2831
|
}
|
|
2843
2832
|
async loadFile(t, r = {}) {
|
|
2844
|
-
var i, s
|
|
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
|
-
}
|
|
2833
|
+
var i, s;
|
|
2834
|
+
return (s = (i = this.options).onLoadStart) == null || s.call(i, t), this.loadThroughRegistry({ file: t, fileName: t.name }, r, t.name);
|
|
2853
2835
|
}
|
|
2854
2836
|
async loadBuffer(t, r, i = {}) {
|
|
2855
|
-
var s, n
|
|
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
|
-
}
|
|
2837
|
+
var s, n;
|
|
2838
|
+
return (n = (s = this.options).onLoadStart) == null || n.call(s, t), this.loadThroughRegistry({ buffer: t, fileName: r }, i, r);
|
|
2864
2839
|
}
|
|
2865
2840
|
async load(t, r = {}) {
|
|
2866
|
-
var i, s, n
|
|
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
|
-
}
|
|
2841
|
+
var i, s, n;
|
|
2842
|
+
return (s = (i = this.options).onLoadStart) == null || s.call(i, t), this.loadThroughRegistry(t, r, t.fileName ?? ((n = t.file) == null ? void 0 : n.name));
|
|
2875
2843
|
}
|
|
2876
2844
|
setDocument(t, r) {
|
|
2877
2845
|
var s, n;
|
|
2846
|
+
this.deactivateNativeRenderer();
|
|
2878
2847
|
const i = {
|
|
2879
2848
|
document: t,
|
|
2880
2849
|
raw: t.raw,
|
|
@@ -2882,25 +2851,33 @@ class ur {
|
|
|
2882
2851
|
elapsedMs: 0,
|
|
2883
2852
|
format: t.format,
|
|
2884
2853
|
warnings: t.warnings,
|
|
2885
|
-
summary:
|
|
2854
|
+
summary: j(t),
|
|
2886
2855
|
fileName: r
|
|
2887
2856
|
};
|
|
2888
2857
|
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
2858
|
}
|
|
2890
2859
|
fit() {
|
|
2891
|
-
|
|
2860
|
+
var t, r;
|
|
2861
|
+
this.activeNativeLoader ? (r = (t = this.activeNativeLoader).fit) == null || r.call(t) : this.renderer.fitToView();
|
|
2892
2862
|
}
|
|
2893
2863
|
zoomIn() {
|
|
2894
|
-
|
|
2864
|
+
var t, r;
|
|
2865
|
+
this.activeNativeLoader ? (r = (t = this.activeNativeLoader).zoomIn) == null || r.call(t) : this.renderer.zoomIn();
|
|
2895
2866
|
}
|
|
2896
2867
|
zoomOut() {
|
|
2897
|
-
|
|
2868
|
+
var t, r;
|
|
2869
|
+
this.activeNativeLoader ? (r = (t = this.activeNativeLoader).zoomOut) == null || r.call(t) : this.renderer.zoomOut();
|
|
2898
2870
|
}
|
|
2899
2871
|
resize() {
|
|
2900
|
-
|
|
2872
|
+
var t, r;
|
|
2873
|
+
this.activeNativeLoader ? (r = (t = this.activeNativeLoader).resize) == null || r.call(t) : this.renderer.resize();
|
|
2901
2874
|
}
|
|
2902
2875
|
setCanvasOptions(t) {
|
|
2903
|
-
|
|
2876
|
+
var r, i;
|
|
2877
|
+
this.options.canvasOptions = { ...this.options.canvasOptions ?? {}, ...t }, this.renderer.setOptions(t), this.activeNativeLoader && ((i = (r = this.activeNativeLoader).setNativeOptions) == null || i.call(r, {
|
|
2878
|
+
...this.mergeLoadOptions({}),
|
|
2879
|
+
dwfBackground: t.background ?? this.options.dwfBackground
|
|
2880
|
+
}));
|
|
2904
2881
|
}
|
|
2905
2882
|
async preloadDwg(t = {}) {
|
|
2906
2883
|
const r = this.registry.list().find((i) => i.id === "dwg");
|
|
@@ -2908,13 +2885,14 @@ class ur {
|
|
|
2908
2885
|
return r.preload(this.mergeLoadOptions(t));
|
|
2909
2886
|
}
|
|
2910
2887
|
clear() {
|
|
2911
|
-
this.lastResult = void 0, this.renderer.clear();
|
|
2888
|
+
this.lastResult = void 0, this.deactivateNativeRenderer(), this.renderer.clear();
|
|
2912
2889
|
}
|
|
2913
2890
|
destroy() {
|
|
2914
|
-
var t, r;
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2891
|
+
var t, r, i;
|
|
2892
|
+
this.deactivateNativeRenderer();
|
|
2893
|
+
for (const s of this.registry.list()) {
|
|
2894
|
+
const n = s;
|
|
2895
|
+
(t = n.terminateWorker) == null || t.call(n), (r = n.unmount) == null || r.call(n), (i = n.destroy) == null || i.call(n);
|
|
2918
2896
|
}
|
|
2919
2897
|
this.renderer.destroy();
|
|
2920
2898
|
}
|
|
@@ -2922,21 +2900,84 @@ class ur {
|
|
|
2922
2900
|
return this.lastResult;
|
|
2923
2901
|
}
|
|
2924
2902
|
getDocument() {
|
|
2925
|
-
|
|
2903
|
+
var t;
|
|
2904
|
+
return this.activeNativeLoader ? (t = this.lastResult) == null ? void 0 : t.document : this.renderer.getDocument();
|
|
2926
2905
|
}
|
|
2927
2906
|
getZoomPercent() {
|
|
2928
|
-
return this.renderer.getZoomPercent();
|
|
2907
|
+
return this.activeNativeLoader ? 100 : this.renderer.getZoomPercent();
|
|
2908
|
+
}
|
|
2909
|
+
isNativeRendererActive() {
|
|
2910
|
+
return !!this.activeNativeLoader;
|
|
2911
|
+
}
|
|
2912
|
+
async loadThroughRegistry(t, r, i) {
|
|
2913
|
+
var s, n;
|
|
2914
|
+
try {
|
|
2915
|
+
const o = this.mergeLoadOptions(r);
|
|
2916
|
+
ht(o.signal);
|
|
2917
|
+
const a = await this.registry.detect(t), c = { ...t, buffer: a.bytes };
|
|
2918
|
+
if (Ye(a.loader))
|
|
2919
|
+
return await this.applyNativeLoadResult(a.loader, c, o, i);
|
|
2920
|
+
const h = await a.loader.load(c, o);
|
|
2921
|
+
return this.applyLoadResult(h, i);
|
|
2922
|
+
} catch (o) {
|
|
2923
|
+
const a = mr(o);
|
|
2924
|
+
throw (n = (s = this.options).onError) == null || n.call(s, a), a;
|
|
2925
|
+
}
|
|
2929
2926
|
}
|
|
2930
2927
|
applyLoadResult(t, r) {
|
|
2931
2928
|
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();
|
|
2929
|
+
this.deactivateNativeRenderer(), (n = (s = this.options).onLoadProgress) == null || n.call(s, { phase: "render", format: t.format, message: "Rendering normalized CAD scene…", percent: 96 }), this.renderer.setDocument(t.document), this.options.autoFit || this.renderer.render();
|
|
2933
2930
|
const i = {
|
|
2934
2931
|
...t,
|
|
2935
2932
|
fileName: r,
|
|
2936
|
-
summary:
|
|
2933
|
+
summary: j(t.document)
|
|
2937
2934
|
};
|
|
2938
2935
|
return this.lastResult = i, (a = (o = this.options).onLoad) == null || a.call(o, i), i;
|
|
2939
2936
|
}
|
|
2937
|
+
async applyNativeLoadResult(t, r, i, s) {
|
|
2938
|
+
var n, o, a;
|
|
2939
|
+
if (!this.nativeHost)
|
|
2940
|
+
throw new Error("Native DWF rendering requires CadViewerOptions.container, nativeHost, or a canvas parent element.");
|
|
2941
|
+
ht(i.signal), this.renderer.clear(), (n = this.activeNativeLoader) == null || n.unmount(), this.activeNativeLoader = t, this.canvas.style.display = "none", this.nativeHost.classList.add("is-active");
|
|
2942
|
+
try {
|
|
2943
|
+
const c = await t.mount(r, this.nativeHost, i);
|
|
2944
|
+
ht(i.signal);
|
|
2945
|
+
const h = {
|
|
2946
|
+
...c,
|
|
2947
|
+
fileName: s,
|
|
2948
|
+
summary: j(c.document)
|
|
2949
|
+
};
|
|
2950
|
+
return this.lastResult = h, this.emitNativeRenderStats(c), (a = (o = this.options).onLoad) == null || a.call(o, h), h;
|
|
2951
|
+
} catch (c) {
|
|
2952
|
+
throw this.deactivateNativeRenderer(), c;
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
deactivateNativeRenderer() {
|
|
2956
|
+
var t, r;
|
|
2957
|
+
if (!this.activeNativeLoader && !((t = this.nativeHost) != null && t.classList.contains("is-active"))) {
|
|
2958
|
+
this.canvas.style.display = "";
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
(r = this.activeNativeLoader) == null || r.unmount(), this.activeNativeLoader = void 0, this.nativeHost && (this.nativeHost.classList.remove("is-active"), this.nativeHost.replaceChildren()), this.canvas.style.display = "";
|
|
2962
|
+
}
|
|
2963
|
+
emitNativeRenderStats(t) {
|
|
2964
|
+
var o, a, c, h;
|
|
2965
|
+
const r = t.document.metadata, i = Number(((o = r.nativeRenderStats) == null ? void 0 : o.commands) ?? t.document.entities.length ?? 0), n = String(((a = r.nativeRenderStats) == null ? void 0 : a.backend) ?? "webgl").includes("webgl") ? "webgl" : "canvas2d";
|
|
2966
|
+
(h = (c = this.options).onRenderStats) == null || h.call(c, {
|
|
2967
|
+
total: i,
|
|
2968
|
+
drawn: i,
|
|
2969
|
+
skipped: 0,
|
|
2970
|
+
byType: j(t.document).byType,
|
|
2971
|
+
unsupported: {},
|
|
2972
|
+
renderElapsedMs: t.elapsedMs,
|
|
2973
|
+
backend: n,
|
|
2974
|
+
primitiveCount: i,
|
|
2975
|
+
visiblePrimitiveCount: i,
|
|
2976
|
+
culledPrimitiveCount: 0,
|
|
2977
|
+
gpuMemoryBytes: void 0,
|
|
2978
|
+
buildElapsedMs: t.elapsedMs
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2940
2981
|
mergeLoadOptions(t) {
|
|
2941
2982
|
const r = this.options.onProgress, i = t.onProgress;
|
|
2942
2983
|
return {
|
|
@@ -2949,44 +2990,48 @@ class ur {
|
|
|
2949
2990
|
};
|
|
2950
2991
|
}
|
|
2951
2992
|
}
|
|
2952
|
-
function
|
|
2993
|
+
function vr(e = {}) {
|
|
2953
2994
|
return new ur(e);
|
|
2954
2995
|
}
|
|
2955
|
-
function
|
|
2996
|
+
function mr(e) {
|
|
2956
2997
|
return e instanceof Error ? e : new Error(String(e));
|
|
2957
2998
|
}
|
|
2958
|
-
function
|
|
2959
|
-
if (e
|
|
2960
|
-
|
|
2961
|
-
|
|
2999
|
+
function ht(e) {
|
|
3000
|
+
if (e != null && e.aborted)
|
|
3001
|
+
throw new DOMException("Loading cancelled.", "AbortError");
|
|
3002
|
+
}
|
|
3003
|
+
function pr(e, t, r = {}) {
|
|
3004
|
+
if (e === "canvas2d") return new Bt(t, r);
|
|
3005
|
+
if (e === "webgl") return new Ft(t, r);
|
|
3006
|
+
if (Zt())
|
|
2962
3007
|
try {
|
|
2963
|
-
return new
|
|
3008
|
+
return new Ft(t, r);
|
|
2964
3009
|
} catch {
|
|
2965
3010
|
}
|
|
2966
|
-
return new
|
|
3011
|
+
return new Bt(t, r);
|
|
2967
3012
|
}
|
|
2968
3013
|
export {
|
|
2969
|
-
|
|
2970
|
-
|
|
3014
|
+
Bt as CadCanvasRenderer,
|
|
3015
|
+
re as CadLoaderRegistry,
|
|
2971
3016
|
ur as CadViewer,
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3017
|
+
Ft as CadWebGLRenderer,
|
|
3018
|
+
Ee as DwfLoader,
|
|
3019
|
+
ce as DwgLoader,
|
|
3020
|
+
ie as DwgWorkerClient,
|
|
3021
|
+
me as DxfLoader,
|
|
3022
|
+
N as colorFromAci,
|
|
3023
|
+
U as colorFromTrueColor,
|
|
3024
|
+
zt as createCadDocument,
|
|
3025
|
+
vr as createCadViewer,
|
|
3026
|
+
ze as createDefaultLoaderRegistry,
|
|
3027
|
+
A as detectCadFormat,
|
|
3028
|
+
R as inferEntityKind,
|
|
3029
|
+
Ye as isCadNativeRenderableLoader,
|
|
3030
|
+
Zt as isWebGLAvailable,
|
|
3031
|
+
fe as normalizeCadEntity,
|
|
3032
|
+
_ as readInputBytes,
|
|
3033
|
+
F as resolveCadColor,
|
|
3034
|
+
j as summarizeCadDocument,
|
|
3035
|
+
lt as supportsDwgWorker
|
|
2991
3036
|
};
|
|
2992
3037
|
//# sourceMappingURL=cad-viewer.es.js.map
|