@flyfish-dev/cad-viewer 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -6
- package/README.zh-CN.md +15 -6
- package/dist/cad-viewer.es.js +388 -386
- package/dist/cad-viewer.es.js.map +1 -1
- package/dist/cad-viewer.umd.cjs +6 -6
- package/dist/cad-viewer.umd.cjs.map +1 -1
- package/dist/types/loaders/dwg/DwgWorkerClient.d.ts.map +1 -1
- package/dist/wasm/dwg-worker.js +24 -0
- package/dist/wasm/dwg-worker.js.map +1 -0
- package/package.json +7 -4
- package/dist/assets/DwgWorker-CuZJ5EUe.js +0 -349
- package/dist/assets/DwgWorker-CuZJ5EUe.js.map +0 -1
- package/dist/assets/index-C365l3i9.js +0 -4161
- package/dist/assets/index-C365l3i9.js.map +0 -1
package/dist/cad-viewer.es.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (e, t, r) =>
|
|
4
|
-
import { openDwfDocument as
|
|
1
|
+
var re = Object.defineProperty;
|
|
2
|
+
var ie = (e, t, r) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var d = (e, t, r) => ie(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { openDwfDocument as se, DwfViewer as ne } from "dwf-viewer";
|
|
5
5
|
async function U(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 oe(e) {
|
|
12
12
|
return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
|
|
13
13
|
}
|
|
14
14
|
function L(e) {
|
|
@@ -24,19 +24,19 @@ function B(e, t) {
|
|
|
24
24
|
if (r === "xps") return "xps";
|
|
25
25
|
if (r === "dwf") return "dwf";
|
|
26
26
|
if (t && t.byteLength >= 6) {
|
|
27
|
-
const i =
|
|
27
|
+
const i = Ct(t.slice(0, 6));
|
|
28
28
|
if (/^AC10/.test(i)) return "dwg";
|
|
29
29
|
if (t[0] === 80 && t[1] === 75) return "dwfx";
|
|
30
|
-
const s =
|
|
30
|
+
const s = Ct(t.slice(0, Math.min(t.byteLength, 2048))).toUpperCase();
|
|
31
31
|
if (s.includes("SECTION") && s.includes("ENTITIES")) return "dxf";
|
|
32
32
|
if (s.includes("DWF")) return "dwf";
|
|
33
33
|
}
|
|
34
34
|
return "unknown";
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function Ct(e) {
|
|
37
37
|
return Array.from(e, (t) => t >= 32 && t <= 126 ? String.fromCharCode(t) : " ").join("");
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class ae {
|
|
40
40
|
constructor(t = []) {
|
|
41
41
|
d(this, "loaders", []);
|
|
42
42
|
for (const r of t) this.register(r);
|
|
@@ -64,17 +64,18 @@ class oe {
|
|
|
64
64
|
return i.load({ ...t, buffer: s }, r);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
const ce = "wasm/dwg-worker.js";
|
|
68
|
+
class he {
|
|
68
69
|
constructor() {
|
|
69
70
|
d(this, "worker");
|
|
70
71
|
d(this, "sequence", 0);
|
|
71
72
|
d(this, "pending", /* @__PURE__ */ new Map());
|
|
72
73
|
}
|
|
73
74
|
load(t, r, i = {}) {
|
|
74
|
-
var
|
|
75
|
+
var h, l;
|
|
75
76
|
if (!dt()) 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 ?? ((
|
|
77
|
-
return (
|
|
77
|
+
const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((h = r.file) == null ? void 0 : h.name), c = fe(t, r, i);
|
|
78
|
+
return (l = i.onProgress) == null || l.call(i, { phase: "worker-start", format: "dwg", message: "Dispatching DWG parse to worker…", total: t.byteLength }), new Promise((f, u) => {
|
|
78
79
|
var g;
|
|
79
80
|
if ((g = i.signal) != null && g.aborted) {
|
|
80
81
|
u(j());
|
|
@@ -92,7 +93,7 @@ class ae {
|
|
|
92
93
|
requestId: n,
|
|
93
94
|
bytes: c,
|
|
94
95
|
fileName: a,
|
|
95
|
-
options:
|
|
96
|
+
options: Pt(i)
|
|
96
97
|
}, [c]);
|
|
97
98
|
} catch (S) {
|
|
98
99
|
this.pending.delete(n), $(p), u(S instanceof Error ? S : new Error(String(S)));
|
|
@@ -104,8 +105,8 @@ class ae {
|
|
|
104
105
|
if (!dt()) return Promise.reject(new Error("Web Worker is not available in this runtime."));
|
|
105
106
|
const r = this.ensureWorker(t), i = ++this.sequence, s = Math.max(0, Number(t.workerTimeoutMs ?? 0));
|
|
106
107
|
return (n = t.onProgress) == null || n.call(t, { phase: "worker-start", format: "dwg", message: "Starting DWG worker warmup…" }), new Promise((o, a) => {
|
|
107
|
-
var
|
|
108
|
-
if ((
|
|
108
|
+
var h;
|
|
109
|
+
if ((h = t.signal) != null && h.aborted) {
|
|
109
110
|
a(j());
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
@@ -121,9 +122,9 @@ class ae {
|
|
|
121
122
|
this.pending.delete(i), this.resetWorker(), a(j());
|
|
122
123
|
}, t.signal.addEventListener("abort", c.abortHandler, { once: !0 })), this.pending.set(i, c);
|
|
123
124
|
try {
|
|
124
|
-
r.postMessage({ type: "warmup", requestId: i, options:
|
|
125
|
-
} catch (
|
|
126
|
-
this.pending.delete(i), $(c), a(
|
|
125
|
+
r.postMessage({ type: "warmup", requestId: i, options: Pt(t) });
|
|
126
|
+
} catch (l) {
|
|
127
|
+
this.pending.delete(i), $(c), a(l instanceof Error ? l : new Error(String(l)));
|
|
127
128
|
}
|
|
128
129
|
});
|
|
129
130
|
}
|
|
@@ -131,7 +132,7 @@ class ae {
|
|
|
131
132
|
this.resetWorker();
|
|
132
133
|
}
|
|
133
134
|
ensureWorker(t) {
|
|
134
|
-
return this.worker || (this.worker =
|
|
135
|
+
return this.worker || (this.worker = le(t), this.worker.onmessage = (r) => this.handleMessage(r.data), this.worker.onerror = (r) => {
|
|
135
136
|
const i = r.message || "DWG worker failed.";
|
|
136
137
|
this.rejectAll(new Error(i)), this.resetWorker(!1);
|
|
137
138
|
}, this.worker.onmessageerror = () => {
|
|
@@ -171,27 +172,23 @@ class ae {
|
|
|
171
172
|
function dt() {
|
|
172
173
|
return typeof Worker < "u" && typeof URL < "u";
|
|
173
174
|
}
|
|
174
|
-
function
|
|
175
|
-
return e.workerFactory ? e.workerFactory() :
|
|
176
|
-
/* @vite-ignore */
|
|
177
|
-
"/assets/DwgWorker-CuZJ5EUe.js",
|
|
178
|
-
import.meta.url
|
|
179
|
-
), { type: "module", name: "lightweight-cad-dwg-loader" });
|
|
175
|
+
function le(e) {
|
|
176
|
+
return e.workerFactory ? e.workerFactory() : new Worker(ue(e.workerUrl), { type: "module", name: "lightweight-cad-dwg-loader" });
|
|
180
177
|
}
|
|
181
|
-
function
|
|
178
|
+
function Pt(e) {
|
|
182
179
|
return {
|
|
183
180
|
// Resolve the asset directory on the UI thread. Relative paths such as
|
|
184
181
|
// './wasm' must be relative to the document URL, not to the generated
|
|
185
182
|
// worker chunk URL. Otherwise the worker may request /assets/wasm/... and
|
|
186
183
|
// receive the app's HTML fallback instead of libredwg-web.wasm.
|
|
187
|
-
wasmPath:
|
|
184
|
+
wasmPath: de(e.wasmPath),
|
|
188
185
|
includePaperSpace: e.includePaperSpace,
|
|
189
186
|
maxInsertDepth: e.maxInsertDepth,
|
|
190
187
|
keepRaw: !!e.keepRaw
|
|
191
188
|
};
|
|
192
189
|
}
|
|
193
|
-
function
|
|
194
|
-
return !!t.file || r.transferInputBuffer === !0 ?
|
|
190
|
+
function fe(e, t, r) {
|
|
191
|
+
return !!t.file || r.transferInputBuffer === !0 ? oe(e) : e.slice().buffer;
|
|
195
192
|
}
|
|
196
193
|
function $(e) {
|
|
197
194
|
e.timer && clearTimeout(e.timer), e.signal && e.abortHandler && e.signal.removeEventListener("abort", e.abortHandler);
|
|
@@ -201,26 +198,31 @@ function j() {
|
|
|
201
198
|
const e = new Error("DWG loading was aborted.");
|
|
202
199
|
return e.name = "AbortError", e;
|
|
203
200
|
}
|
|
204
|
-
function
|
|
201
|
+
function de(e) {
|
|
205
202
|
const t = ((e == null ? void 0 : e.trim()) || "/wasm").replace(/\/+$/, "");
|
|
206
|
-
return t === "" ?
|
|
203
|
+
return t === "" ? kt() : Xt(t) ? t : t.startsWith("/") ? `${kt()}${t}` : new URL(t, vt()).href.replace(/\/+$/, "");
|
|
207
204
|
}
|
|
208
|
-
function
|
|
205
|
+
function ue(e) {
|
|
206
|
+
if (e instanceof URL) return e;
|
|
207
|
+
const t = (e == null ? void 0 : e.trim()) || ce;
|
|
208
|
+
return Xt(t) ? t : new URL(t, vt()).href;
|
|
209
|
+
}
|
|
210
|
+
function vt() {
|
|
209
211
|
return typeof document < "u" && document.baseURI ? document.baseURI : typeof location < "u" && location.href ? location.href : "http://localhost/";
|
|
210
212
|
}
|
|
211
|
-
function
|
|
212
|
-
return typeof location < "u" && location.origin ? location.origin : new URL(
|
|
213
|
+
function kt() {
|
|
214
|
+
return typeof location < "u" && location.origin ? location.origin : new URL(vt()).origin;
|
|
213
215
|
}
|
|
214
|
-
function
|
|
216
|
+
function Xt(e) {
|
|
215
217
|
return /^[a-z][a-z0-9+.-]*:/i.test(e);
|
|
216
218
|
}
|
|
217
|
-
class
|
|
219
|
+
class me {
|
|
218
220
|
constructor(t = {}) {
|
|
219
221
|
d(this, "id", "dwg");
|
|
220
222
|
d(this, "label", "DWG / LibreDWG WebAssembly");
|
|
221
223
|
d(this, "formats", ["dwg"]);
|
|
222
224
|
d(this, "defaults");
|
|
223
|
-
d(this, "workerClient", new
|
|
225
|
+
d(this, "workerClient", new he());
|
|
224
226
|
this.defaults = { useWorker: !0, ...t };
|
|
225
227
|
}
|
|
226
228
|
accepts(t, r) {
|
|
@@ -238,7 +240,7 @@ class de {
|
|
|
238
240
|
try {
|
|
239
241
|
return await this.workerClient.load(s, t, { ...i, fileName: n });
|
|
240
242
|
} catch (c) {
|
|
241
|
-
throw
|
|
243
|
+
throw pe(c) ? c : ge(c);
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
246
|
terminateWorker() {
|
|
@@ -249,14 +251,14 @@ class de {
|
|
|
249
251
|
return r.useWorker === !1 ? Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")) : this.workerClient.preload(r);
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
|
-
function
|
|
254
|
+
function pe(e) {
|
|
253
255
|
return e instanceof Error && e.name === "AbortError";
|
|
254
256
|
}
|
|
255
|
-
function
|
|
257
|
+
function ge(e) {
|
|
256
258
|
const t = e instanceof Error ? e.message : String(e);
|
|
257
259
|
return new Error(`${t} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`);
|
|
258
260
|
}
|
|
259
|
-
function
|
|
261
|
+
function Ut(e) {
|
|
260
262
|
return {
|
|
261
263
|
format: e.format,
|
|
262
264
|
sourceName: e.sourceName,
|
|
@@ -322,15 +324,15 @@ function R(e) {
|
|
|
322
324
|
return "unsupported";
|
|
323
325
|
}
|
|
324
326
|
}
|
|
325
|
-
function
|
|
327
|
+
function be(e, t, r = {}) {
|
|
326
328
|
const i = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), s = r.includeUnknownProperties === !1 ? { type: i, kind: R(i) } : { ...e, type: i, kind: R(i) };
|
|
327
329
|
r.keepRaw && (s.raw = e), s.handle = C(e.handle ?? e.id), s.layer = C(e.layer ?? e.layerName), s.lineType = C(e.lineType ?? e.linetype);
|
|
328
330
|
const n = r.numericColorMode ?? "auto", o = y(e.color), a = y(e.colorIndex ?? e.colorNumber ?? e.aci ?? e.aciColor ?? e.color_index);
|
|
329
331
|
s.colorIndex = a ?? (n !== "rgb" && o !== void 0 && Math.abs(o) <= 257 ? o : void 0);
|
|
330
|
-
const c = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb,
|
|
331
|
-
s.trueColor = c ?? (
|
|
332
|
-
const
|
|
333
|
-
|
|
332
|
+
const c = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb, h = o !== void 0 && o >= 0 && o <= 16777215 && (n === "rgb" || n === "auto" && Math.abs(o) > 257);
|
|
333
|
+
s.trueColor = c ?? (h ? o : void 0), (typeof e.color == "string" || typeof e.color == "number") && (s.color = e.color), s.colorNumber = y(e.colorNumber) ?? s.colorNumber, s.colorName = C(e.colorName ?? e.color_name) ?? s.colorName, s.fillColor = e.fillColor ?? e.fill_color, s.fillColorIndex = y(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? s.fillColorIndex, s.opacity = y(e.opacity ?? e.alpha) ?? s.opacity, s.lineweight = y(e.lineweight ?? e.lineWeight), s.isVisible = !(e.isVisible === !1 || e.visible === !1), s.startPoint = P(e.startPoint ?? e.start ?? e.p0 ?? e.from) ?? s.startPoint, s.endPoint = P(e.endPoint ?? e.end ?? e.p1 ?? e.to) ?? s.endPoint, s.center = P(e.center ?? e.centerPoint) ?? s.center, s.insertionPoint = P(e.insertionPoint ?? e.position ?? e.location ?? e.point ?? e.basePoint) ?? s.insertionPoint, s.radius = y(e.radius) ?? s.radius, s.startAngle = y(e.startAngle ?? e.start_angle) ?? s.startAngle, s.endAngle = y(e.endAngle ?? e.end_angle) ?? s.endAngle, s.majorAxisEndPoint = P(e.majorAxisEndPoint ?? e.majorAxis ?? e.major) ?? s.majorAxisEndPoint, s.axisRatio = y(e.axisRatio ?? e.ratio) ?? s.axisRatio, s.height = y(e.height ?? e.textHeight) ?? s.height, s.textHeight = y(e.textHeight ?? e.height) ?? s.textHeight, s.rotation = y(e.rotation ?? e.angle) ?? s.rotation, s.text = C(e.text ?? e.value ?? e.string ?? e.contents) ?? s.text, s.name = C(e.name ?? e.blockName) ?? s.name, s.blockName = C(e.blockName ?? e.name) ?? s.blockName;
|
|
334
|
+
const l = rt(e.vertices ?? e.points);
|
|
335
|
+
l.length > 0 && (s.vertices = l);
|
|
334
336
|
const f = rt(e.controlPoints ?? e.control_points);
|
|
335
337
|
f.length > 0 && (s.controlPoints = f);
|
|
336
338
|
const u = rt(e.fitPoints ?? e.fit_points);
|
|
@@ -375,13 +377,13 @@ function G(e) {
|
|
|
375
377
|
warnings: [...e.warnings]
|
|
376
378
|
};
|
|
377
379
|
}
|
|
378
|
-
function
|
|
380
|
+
function St(e, t) {
|
|
379
381
|
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
380
382
|
}
|
|
381
|
-
function
|
|
383
|
+
function ve(e, t) {
|
|
382
384
|
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
383
385
|
}
|
|
384
|
-
function
|
|
386
|
+
function ye(e) {
|
|
385
387
|
return e != null && e.length ? e.flatMap((t) => t.entities.map((r) => ({ ...r, pageIndex: t.index }))) : [];
|
|
386
388
|
}
|
|
387
389
|
function y(e) {
|
|
@@ -402,12 +404,12 @@ function O(e) {
|
|
|
402
404
|
function v(e, t) {
|
|
403
405
|
m(t) && (e.minX = Math.min(e.minX, t.x), e.minY = Math.min(e.minY, t.y), e.maxX = Math.max(e.maxX, t.x), e.maxY = Math.max(e.maxY, t.y));
|
|
404
406
|
}
|
|
405
|
-
function
|
|
407
|
+
function Vt(e, t, r) {
|
|
406
408
|
if (!m(t) || !Number.isFinite(r)) return;
|
|
407
409
|
const i = Math.abs(r);
|
|
408
410
|
v(e, { x: t.x - i, y: t.y - i }), v(e, { x: t.x + i, y: t.y + i });
|
|
409
411
|
}
|
|
410
|
-
function
|
|
412
|
+
function $t(e, t = 0.02, r = 1e-6) {
|
|
411
413
|
if (!O(e)) return { minX: -10, minY: -10, maxX: 10, maxY: 10 };
|
|
412
414
|
const i = Math.max((e.maxX - e.minX) * t, r), s = Math.max((e.maxY - e.minY) * t, r);
|
|
413
415
|
return { minX: e.minX - i, minY: e.minY - s, maxX: e.maxX + i, maxY: e.maxY + s };
|
|
@@ -415,7 +417,7 @@ function Vt(e, t = 0.02, r = 1e-6) {
|
|
|
415
417
|
function m(e) {
|
|
416
418
|
return !!e && typeof e == "object" && Number.isFinite(e.x) && Number.isFinite(e.y);
|
|
417
419
|
}
|
|
418
|
-
function
|
|
420
|
+
function x(e) {
|
|
419
421
|
return { x: e.x, y: e.y };
|
|
420
422
|
}
|
|
421
423
|
function I(e) {
|
|
@@ -426,42 +428,42 @@ function K(e, t, r, i, s = !0, n = 64) {
|
|
|
426
428
|
let o = r, a = i;
|
|
427
429
|
if (!Number.isFinite(o) || !Number.isFinite(a)) return [];
|
|
428
430
|
(Math.abs(o) > Math.PI * 2 + 1e-6 || Math.abs(a) > Math.PI * 2 + 1e-6) && (o = I(o), a = I(a)), s && a < o && (a += Math.PI * 2), !s && o < a && (o += Math.PI * 2);
|
|
429
|
-
const c = a - o,
|
|
430
|
-
for (let f = 0; f <=
|
|
431
|
-
const u = o + c * (f /
|
|
432
|
-
|
|
431
|
+
const c = a - o, h = Math.max(8, Math.min(256, Math.ceil(Math.abs(c) / (Math.PI * 2) * n))), l = [];
|
|
432
|
+
for (let f = 0; f <= h; f++) {
|
|
433
|
+
const u = o + c * (f / h);
|
|
434
|
+
l.push({ x: e.x + Math.cos(u) * t, y: e.y + Math.sin(u) * t });
|
|
433
435
|
}
|
|
434
|
-
return
|
|
436
|
+
return l;
|
|
435
437
|
}
|
|
436
438
|
function J(e, t, r = 1, i = 0, s = Math.PI * 2, n = 96) {
|
|
437
439
|
if (!m(e) || !m(t)) return [];
|
|
438
440
|
const o = Math.hypot(t.x, t.y);
|
|
439
441
|
if (!Number.isFinite(o) || o <= 0) return [];
|
|
440
442
|
const a = o * (Number.isFinite(r) && r > 0 ? r : 1), c = Math.atan2(t.y, t.x);
|
|
441
|
-
let
|
|
442
|
-
(Math.abs(
|
|
443
|
-
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(
|
|
443
|
+
let h = Number.isFinite(i) ? i : 0, l = Number.isFinite(s) ? s : Math.PI * 2;
|
|
444
|
+
(Math.abs(h) > Math.PI * 2 + 1e-6 || Math.abs(l) > Math.PI * 2 + 1e-6) && (h = I(h), l = I(l)), l < h && (l += Math.PI * 2);
|
|
445
|
+
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(l - h) / (Math.PI * 2) * n))), u = [], p = Math.cos(c), g = Math.sin(c);
|
|
444
446
|
for (let S = 0; S <= f; S++) {
|
|
445
|
-
const z =
|
|
447
|
+
const z = h + (l - h) * (S / f), _ = Math.cos(z) * o, H = Math.sin(z) * a;
|
|
446
448
|
u.push({ x: e.x + _ * p - H * g, y: e.y + _ * g + H * p });
|
|
447
449
|
}
|
|
448
450
|
return u;
|
|
449
451
|
}
|
|
450
|
-
function
|
|
451
|
-
if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [
|
|
452
|
+
function jt(e, t, r = 0, i = 16) {
|
|
453
|
+
if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [x(e), x(t)];
|
|
452
454
|
const s = Math.hypot(t.x - e.x, t.y - e.y);
|
|
453
|
-
if (s <= 1e-12) return [
|
|
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,
|
|
455
|
+
if (s <= 1e-12) return [x(e), x(t)];
|
|
456
|
+
const n = 4 * Math.atan(r), o = Math.abs(s / (2 * Math.sin(n / 2))), a = { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 }, c = (t.x - e.x) / s, h = (t.y - e.y) / s, l = r >= 0 ? 1 : -1, f = Math.sqrt(Math.max(o * o - (s / 2) ** 2, 0)), u = { x: a.x - l * h * f, y: a.y + l * c * f }, p = Math.atan2(e.y - u.y, e.x - u.x), g = Math.atan2(t.y - u.y, t.x - u.x);
|
|
455
457
|
return K(u, o, p, g, r >= 0, i);
|
|
456
458
|
}
|
|
457
|
-
function
|
|
459
|
+
function Gt(e) {
|
|
458
460
|
return e.replace(/\\P/g, `
|
|
459
461
|
`).replace(/\\~|\\ /g, " ").replace(/\\[A-Za-z][^;]*;/g, "").replace(/[{}]/g, "").replace(/\\[A-Za-z]/g, "").trim();
|
|
460
462
|
}
|
|
461
463
|
function A(e, t, r) {
|
|
462
464
|
return Math.min(r, Math.max(t, e));
|
|
463
465
|
}
|
|
464
|
-
class
|
|
466
|
+
class xe {
|
|
465
467
|
constructor(t = {}) {
|
|
466
468
|
d(this, "id", "dxf");
|
|
467
469
|
d(this, "label", "DXF / JavaScript parser");
|
|
@@ -474,24 +476,24 @@ class ve {
|
|
|
474
476
|
}
|
|
475
477
|
async load(t, r = {}) {
|
|
476
478
|
var f;
|
|
477
|
-
const i = { ...this.defaults, ...r }, s = performance.now(), n = await U(t), o =
|
|
479
|
+
const i = { ...this.defaults, ...r }, s = performance.now(), n = await U(t), o = Ee(n, i.dxfEncoding), a = [];
|
|
478
480
|
let c;
|
|
479
481
|
try {
|
|
480
|
-
c = await
|
|
482
|
+
c = await we(o);
|
|
481
483
|
} catch (u) {
|
|
482
|
-
a.push(`dxf-parser failed, using built-in fallback parser: ${u instanceof Error ? u.message : String(u)}`), c =
|
|
484
|
+
a.push(`dxf-parser failed, using built-in fallback parser: ${u instanceof Error ? u.message : String(u)}`), c = Fe(o);
|
|
483
485
|
}
|
|
484
|
-
const
|
|
485
|
-
return { document:
|
|
486
|
+
const h = Ce(c, t.fileName ?? ((f = t.file) == null ? void 0 : f.name), a), l = performance.now() - s;
|
|
487
|
+
return { document: h, raw: c, bytes: n.byteLength, elapsedMs: l, format: "dxf", warnings: h.warnings };
|
|
486
488
|
}
|
|
487
489
|
}
|
|
488
|
-
async function
|
|
490
|
+
async function we(e) {
|
|
489
491
|
const t = await import("dxf-parser"), r = t.default ?? t.DxfParser;
|
|
490
492
|
if (!r) throw new Error("dxf-parser did not expose a parser constructor.");
|
|
491
493
|
return new r().parseSync(e);
|
|
492
494
|
}
|
|
493
|
-
function
|
|
494
|
-
const i = e && typeof e == "object" ? e : {}, s =
|
|
495
|
+
function Ce(e, t, r = []) {
|
|
496
|
+
const i = e && typeof e == "object" ? e : {}, s = Pe(i), n = ke(i), a = (Array.isArray(i.entities) ? i.entities : []).filter((h) => !!h && typeof h == "object").map((h) => yt(h)), c = Ut({
|
|
495
497
|
format: "dxf",
|
|
496
498
|
sourceName: t,
|
|
497
499
|
header: i.header && typeof i.header == "object" ? i.header : {},
|
|
@@ -504,12 +506,12 @@ function we(e, t, r = []) {
|
|
|
504
506
|
});
|
|
505
507
|
return a.length === 0 && c.warnings.push("DXF file did not expose any ENTITIES."), c;
|
|
506
508
|
}
|
|
507
|
-
function
|
|
508
|
-
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r =
|
|
509
|
-
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 =
|
|
509
|
+
function yt(e) {
|
|
510
|
+
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r = be(e, t), i = y(e.colorIndex ?? e.colorNumber ?? e.aci), s = y(e.color);
|
|
511
|
+
if (r.colorIndex = i ?? (s !== void 0 && Math.abs(s) <= 257 ? s : void 0), r.trueColor = e.trueColor ?? e.true_color ?? e.colorRGB ?? e.trueColorValue ?? (s !== void 0 && Math.abs(s) > 257 ? s : void 0), r.layer = C(e.layer ?? e.layerName) ?? "0", r.isClosed = !!(e.shape ?? e.closed ?? e.isClosed) || (Number(e.flag ?? e.flags ?? 0) & 1) === 1, t === "LINE" && (r.startPoint = P(e.startPoint ?? { x: e.x1 ?? e.x, y: e.y1 ?? e.y, z: e.z1 ?? e.z }) ?? r.startPoint, r.endPoint = P(e.endPoint ?? { x: e.x2, y: e.y2, z: e.z2 }) ?? r.endPoint), (t === "TEXT" || t === "MTEXT" || t === "ATTRIB" || t === "ATTDEF") && (r.insertionPoint = P(e.startPoint ?? e.position ?? e.insertionPoint) ?? r.insertionPoint, r.text = Be(e.text ?? e.string ?? e.value) ?? r.text, r.textHeight = y(e.textHeight ?? e.height) ?? r.textHeight, r.rotation = Mt(e.rotation ?? e.angle)), (t === "ARC" || t === "ELLIPSE") && (r.startAngle = Et(e.startAngle ?? e.start_angle), r.endAngle = Et(e.endAngle ?? e.end_angle)), t === "INSERT") {
|
|
510
512
|
r.blockName = C(e.name ?? e.blockName) ?? r.blockName, r.insertionPoint = P(e.position ?? e.insertionPoint ?? e.point) ?? r.insertionPoint;
|
|
511
513
|
const n = y(e.xScale ?? e.scaleX ?? e.xscale), o = y(e.yScale ?? e.scaleY ?? e.yscale), a = y(e.zScale ?? e.scaleZ ?? e.zscale);
|
|
512
|
-
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation =
|
|
514
|
+
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation = Mt(e.rotation ?? e.angle);
|
|
513
515
|
}
|
|
514
516
|
if (t === "SPLINE") {
|
|
515
517
|
const n = Q(e.controlPoints ?? e.control_points ?? e.points);
|
|
@@ -517,13 +519,13 @@ function vt(e) {
|
|
|
517
519
|
const o = Q(e.fitPoints ?? e.fit_points);
|
|
518
520
|
o.length && (r.fitPoints = o);
|
|
519
521
|
}
|
|
520
|
-
return t === "HATCH" && (r.loops =
|
|
522
|
+
return t === "HATCH" && (r.loops = Me(e), r.fillColorIndex = r.colorIndex), (t === "SOLID" || t === "TRACE" || t === "3DFACE") && (r.vertices = Ne(e), r.fillColorIndex = r.colorIndex), r;
|
|
521
523
|
}
|
|
522
|
-
function
|
|
523
|
-
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 =
|
|
524
|
+
function Pe(e) {
|
|
525
|
+
const t = {}, r = e.tables, i = e.layers ?? (r == null ? void 0 : r.layer) ?? (r == null ? void 0 : r.LAYER) ?? (r == null ? void 0 : r.layers), s = Se(i);
|
|
524
526
|
for (const n of s) {
|
|
525
527
|
const o = n, a = C(o.name ?? o.layerName);
|
|
526
|
-
a &&
|
|
528
|
+
a && St(t, {
|
|
527
529
|
name: a,
|
|
528
530
|
color: o.color ?? o.colorNumber ?? o.colorIndex,
|
|
529
531
|
colorIndex: y(o.colorNumber ?? o.colorIndex ?? o.color),
|
|
@@ -534,25 +536,25 @@ function xe(e) {
|
|
|
534
536
|
raw: o
|
|
535
537
|
});
|
|
536
538
|
}
|
|
537
|
-
return t[0] ||
|
|
539
|
+
return t[0] || St(t, { name: "0", colorIndex: 7, isVisible: !0 }), t;
|
|
538
540
|
}
|
|
539
|
-
function
|
|
541
|
+
function ke(e) {
|
|
540
542
|
const t = {}, r = e.blocks;
|
|
541
543
|
if (!r || typeof r != "object") return t;
|
|
542
544
|
if (Array.isArray(r))
|
|
543
|
-
for (const i of r)
|
|
545
|
+
for (const i of r) Nt(t, i);
|
|
544
546
|
else
|
|
545
|
-
for (const [i, s] of Object.entries(r))
|
|
547
|
+
for (const [i, s] of Object.entries(r)) Nt(t, s, i);
|
|
546
548
|
return t;
|
|
547
549
|
}
|
|
548
|
-
function
|
|
550
|
+
function Nt(e, t, r) {
|
|
549
551
|
if (!t || typeof t != "object") return;
|
|
550
552
|
const i = t, s = C(i.name ?? i.blockName ?? r);
|
|
551
553
|
if (!s) return;
|
|
552
|
-
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) =>
|
|
553
|
-
|
|
554
|
+
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) => yt(a));
|
|
555
|
+
ve(e, { name: s, basePoint: P(i.basePoint ?? i.position) ?? { x: 0, y: 0 }, entities: o, raw: i });
|
|
554
556
|
}
|
|
555
|
-
function
|
|
557
|
+
function Se(e) {
|
|
556
558
|
if (!e) return [];
|
|
557
559
|
if (Array.isArray(e)) return e;
|
|
558
560
|
if (typeof e != "object") return [];
|
|
@@ -562,7 +564,7 @@ function Pe(e) {
|
|
|
562
564
|
function Q(e) {
|
|
563
565
|
return Array.isArray(e) ? e.map(P).filter((t) => !!t) : [];
|
|
564
566
|
}
|
|
565
|
-
function
|
|
567
|
+
function Ne(e) {
|
|
566
568
|
const t = Q(e.vertices ?? e.points);
|
|
567
569
|
if (t.length) return t;
|
|
568
570
|
const r = [];
|
|
@@ -572,7 +574,7 @@ function ke(e) {
|
|
|
572
574
|
}
|
|
573
575
|
return r;
|
|
574
576
|
}
|
|
575
|
-
function
|
|
577
|
+
function Me(e) {
|
|
576
578
|
const t = e.boundaryLoops ?? e.loops ?? e.paths;
|
|
577
579
|
if (Array.isArray(t))
|
|
578
580
|
return t.map((r) => {
|
|
@@ -580,27 +582,27 @@ function Se(e) {
|
|
|
580
582
|
return { vertices: Q(i.vertices ?? i.points), isClosed: !0 };
|
|
581
583
|
}).filter((r) => r.vertices && r.vertices.length > 0);
|
|
582
584
|
}
|
|
583
|
-
function
|
|
585
|
+
function Mt(e) {
|
|
584
586
|
const t = y(e);
|
|
585
587
|
if (t !== void 0)
|
|
586
588
|
return Math.abs(t) > Math.PI * 2 + 1e-6 ? I(t) : t;
|
|
587
589
|
}
|
|
588
|
-
function
|
|
590
|
+
function Et(e) {
|
|
589
591
|
const t = y(e);
|
|
590
592
|
if (t !== void 0)
|
|
591
593
|
return Math.abs(t) > Math.PI * 2 + 1e-6 ? I(t) : t;
|
|
592
594
|
}
|
|
593
|
-
function
|
|
595
|
+
function Ee(e, t) {
|
|
594
596
|
const r = ut(t);
|
|
595
597
|
if (r) return M(e, r);
|
|
596
|
-
const i =
|
|
598
|
+
const i = Ie(e);
|
|
597
599
|
if (i) return M(e, i);
|
|
598
|
-
const s = ut(
|
|
600
|
+
const s = ut(Te(e));
|
|
599
601
|
if (s) return M(e, s);
|
|
600
602
|
const n = M(e, "utf-8");
|
|
601
|
-
return n.includes("�") ?
|
|
603
|
+
return n.includes("�") ? Ae(e) : n;
|
|
602
604
|
}
|
|
603
|
-
const
|
|
605
|
+
const It = {
|
|
604
606
|
ANSI_874: "windows-874",
|
|
605
607
|
ANSI_932: "shift_jis",
|
|
606
608
|
ANSI_936: "gb18030",
|
|
@@ -645,12 +647,12 @@ const Et = {
|
|
|
645
647
|
UTF16BE: "utf-16be",
|
|
646
648
|
UTF_16BE: "utf-16be"
|
|
647
649
|
};
|
|
648
|
-
function
|
|
650
|
+
function Ie(e) {
|
|
649
651
|
if (e.length >= 3 && e[0] === 239 && e[1] === 187 && e[2] === 191) return "utf-8";
|
|
650
652
|
if (e.length >= 2 && e[0] === 255 && e[1] === 254) return "utf-16le";
|
|
651
653
|
if (e.length >= 2 && e[0] === 254 && e[1] === 255) return "utf-16be";
|
|
652
654
|
}
|
|
653
|
-
function
|
|
655
|
+
function Te(e) {
|
|
654
656
|
var i, s, n, o;
|
|
655
657
|
const r = M(e.subarray(0, Math.min(e.byteLength, 131072)), "iso-8859-1").replace(/\r\n/g, `
|
|
656
658
|
`).replace(/\r/g, `
|
|
@@ -659,15 +661,15 @@ function Ee(e) {
|
|
|
659
661
|
for (let a = 0; a < r.length - 3; a++)
|
|
660
662
|
if (!(((i = r[a]) == null ? void 0 : i.trim()) !== "9" || ((s = r[a + 1]) == null ? void 0 : s.trim().toUpperCase()) !== "$DWGCODEPAGE"))
|
|
661
663
|
for (let c = a + 2; c < Math.min(a + 10, r.length - 1); c += 2) {
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
664
|
+
const h = (n = r[c]) == null ? void 0 : n.trim(), l = (o = r[c + 1]) == null ? void 0 : o.trim();
|
|
665
|
+
if (h === "3" && l) return l;
|
|
664
666
|
}
|
|
665
667
|
}
|
|
666
668
|
function ut(e) {
|
|
667
669
|
const t = e == null ? void 0 : e.trim();
|
|
668
670
|
if (!t) return;
|
|
669
671
|
const r = t.replace(/[-\s]+/g, "_").toUpperCase();
|
|
670
|
-
if (
|
|
672
|
+
if (It[r]) return It[r];
|
|
671
673
|
const i = /^ANSI_(\d{3,4})$/.exec(r);
|
|
672
674
|
if (i) return ut(`cp${i[1]}`);
|
|
673
675
|
const s = /^CP(\d{3,4})$/.exec(r);
|
|
@@ -680,16 +682,16 @@ function M(e, t) {
|
|
|
680
682
|
return new TextDecoder("utf-8", { fatal: !1 }).decode(e);
|
|
681
683
|
}
|
|
682
684
|
}
|
|
683
|
-
function
|
|
685
|
+
function Ae(e) {
|
|
684
686
|
const t = ["windows-1252", "gb18030", "big5", "shift_jis", "euc-kr", "iso-8859-1"];
|
|
685
687
|
let r = "", i = Number.POSITIVE_INFINITY;
|
|
686
688
|
for (const s of t) {
|
|
687
|
-
const n = M(e, s), o =
|
|
689
|
+
const n = M(e, s), o = Le(n, s);
|
|
688
690
|
o < i && (i = o, r = n);
|
|
689
691
|
}
|
|
690
692
|
return r || M(e, "utf-8");
|
|
691
693
|
}
|
|
692
|
-
function
|
|
694
|
+
function Le(e, t) {
|
|
693
695
|
const r = it(e, /\uFFFD/g), i = it(e, /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g), s = it(e, /[\u3400-\u9FFF\uF900-\uFAFF]/g), n = e.includes("SECTION") && (e.includes("ENTITIES") || e.includes("HEADER"));
|
|
694
696
|
let o = r * 1e4 + i * 1e3;
|
|
695
697
|
return n && (o -= 500), t === "windows-1252" && (o -= 2), t === "gb18030" && s >= 2 && (o -= 50 + Math.min(s, 200) * 2), o;
|
|
@@ -698,7 +700,7 @@ function it(e, t) {
|
|
|
698
700
|
var r;
|
|
699
701
|
return ((r = e.match(t)) == null ? void 0 : r.length) ?? 0;
|
|
700
702
|
}
|
|
701
|
-
function
|
|
703
|
+
function Be(e) {
|
|
702
704
|
const t = C(e);
|
|
703
705
|
if (t !== void 0)
|
|
704
706
|
return t.replace(/\\U\+([0-9a-fA-F]{4,6})/g, (r, i) => {
|
|
@@ -707,14 +709,14 @@ function Ae(e) {
|
|
|
707
709
|
}).replace(/%%[cC]/g, "∅").replace(/%%[dD]/g, "°").replace(/%%[pP]/g, "±").replace(/\\P/g, `
|
|
708
710
|
`);
|
|
709
711
|
}
|
|
710
|
-
function
|
|
711
|
-
var
|
|
712
|
+
function Fe(e) {
|
|
713
|
+
var h, l;
|
|
712
714
|
const t = e.replace(/\r\n/g, `
|
|
713
715
|
`).replace(/\r/g, `
|
|
714
716
|
`).split(`
|
|
715
717
|
`), r = [];
|
|
716
718
|
for (let f = 0; f < t.length - 1; f += 2) {
|
|
717
|
-
const u = Number((
|
|
719
|
+
const u = Number((h = t[f]) == null ? void 0 : h.trim()), p = t[f + 1] ?? "";
|
|
718
720
|
Number.isFinite(u) && r.push({ code: u, value: p.trimEnd() });
|
|
719
721
|
}
|
|
720
722
|
const i = [], s = {};
|
|
@@ -722,7 +724,7 @@ function Le(e) {
|
|
|
722
724
|
for (let f = 0; f < r.length; f++) {
|
|
723
725
|
const u = r[f];
|
|
724
726
|
if (u.code === 0 && u.value === "SECTION") {
|
|
725
|
-
n = ((
|
|
727
|
+
n = ((l = r[f + 1]) == null ? void 0 : l.code) === 2 ? r[f + 1].value.toUpperCase() : "", f++;
|
|
726
728
|
continue;
|
|
727
729
|
}
|
|
728
730
|
if (u.code === 0 && u.value === "ENDSEC") {
|
|
@@ -737,7 +739,7 @@ function Le(e) {
|
|
|
737
739
|
if (!o.length) return;
|
|
738
740
|
const f = (p = o[0]) == null ? void 0 : p.value.toUpperCase();
|
|
739
741
|
if (f === "VERTEX" && a) {
|
|
740
|
-
const g =
|
|
742
|
+
const g = w(o, 10, 20, 30);
|
|
741
743
|
g && (a.vertices ?? (a.vertices = [])).push({ ...g, bulge: b(o, 42) }), o = [];
|
|
742
744
|
return;
|
|
743
745
|
}
|
|
@@ -749,11 +751,11 @@ function Le(e) {
|
|
|
749
751
|
o = [];
|
|
750
752
|
return;
|
|
751
753
|
}
|
|
752
|
-
const u =
|
|
754
|
+
const u = De(f, o);
|
|
753
755
|
f === "POLYLINE" ? a = u : i.push(u), o = [];
|
|
754
756
|
}
|
|
755
757
|
}
|
|
756
|
-
function
|
|
758
|
+
function De(e, t) {
|
|
757
759
|
const r = {
|
|
758
760
|
type: e,
|
|
759
761
|
handle: Y(t, 5),
|
|
@@ -765,43 +767,43 @@ function Be(e, t) {
|
|
|
765
767
|
};
|
|
766
768
|
switch (e) {
|
|
767
769
|
case "LINE":
|
|
768
|
-
Object.assign(r, { startPoint:
|
|
770
|
+
Object.assign(r, { startPoint: w(t, 10, 20, 30), endPoint: w(t, 11, 21, 31) });
|
|
769
771
|
break;
|
|
770
772
|
case "CIRCLE":
|
|
771
|
-
Object.assign(r, { center:
|
|
773
|
+
Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40) });
|
|
772
774
|
break;
|
|
773
775
|
case "ARC":
|
|
774
|
-
Object.assign(r, { center:
|
|
776
|
+
Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40), startAngle: Z(b(t, 50)), endAngle: Z(b(t, 51)) });
|
|
775
777
|
break;
|
|
776
778
|
case "POINT":
|
|
777
|
-
Object.assign(r, { point:
|
|
779
|
+
Object.assign(r, { point: w(t, 10, 20, 30) });
|
|
778
780
|
break;
|
|
779
781
|
case "TEXT":
|
|
780
782
|
case "MTEXT":
|
|
781
|
-
Object.assign(r, { insertionPoint:
|
|
783
|
+
Object.assign(r, { insertionPoint: w(t, 10, 20, 30), text: Oe(t), textHeight: b(t, 40), rotation: Z(b(t, 50)) });
|
|
782
784
|
break;
|
|
783
785
|
case "LWPOLYLINE":
|
|
784
|
-
Object.assign(r, { vertices:
|
|
786
|
+
Object.assign(r, { vertices: Re(t), flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
785
787
|
break;
|
|
786
788
|
case "POLYLINE":
|
|
787
789
|
Object.assign(r, { vertices: [], flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
788
790
|
break;
|
|
789
791
|
case "ELLIPSE":
|
|
790
|
-
Object.assign(r, { center:
|
|
792
|
+
Object.assign(r, { center: w(t, 10, 20, 30), majorAxisEndPoint: w(t, 11, 21, 31), axisRatio: b(t, 40), startAngle: b(t, 41), endAngle: b(t, 42) });
|
|
791
793
|
break;
|
|
792
794
|
case "SPLINE":
|
|
793
|
-
Object.assign(r, { controlPoints:
|
|
795
|
+
Object.assign(r, { controlPoints: We(t, 10, 20, 30), degree: b(t, 71), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
794
796
|
break;
|
|
795
797
|
case "INSERT":
|
|
796
|
-
Object.assign(r, { name: Y(t, 2), blockName: Y(t, 2), insertionPoint:
|
|
798
|
+
Object.assign(r, { name: Y(t, 2), blockName: Y(t, 2), insertionPoint: w(t, 10, 20, 30), rotation: Z(b(t, 50)), scale: { x: b(t, 41) ?? 1, y: b(t, 42) ?? b(t, 41) ?? 1, z: b(t, 43) ?? 1 } });
|
|
797
799
|
break;
|
|
798
800
|
case "SOLID":
|
|
799
801
|
case "TRACE":
|
|
800
802
|
case "3DFACE":
|
|
801
|
-
Object.assign(r, { vertices: [
|
|
803
|
+
Object.assign(r, { vertices: [w(t, 10, 20, 30), w(t, 11, 21, 31), w(t, 12, 22, 32), w(t, 13, 23, 33)].filter(Boolean) });
|
|
802
804
|
break;
|
|
803
805
|
}
|
|
804
|
-
return
|
|
806
|
+
return yt(r);
|
|
805
807
|
}
|
|
806
808
|
function b(e, t) {
|
|
807
809
|
var s;
|
|
@@ -813,21 +815,21 @@ function Y(e, t) {
|
|
|
813
815
|
const r = (i = e.find((s) => s.code === t)) == null ? void 0 : i.value;
|
|
814
816
|
return r && r.length > 0 ? r : void 0;
|
|
815
817
|
}
|
|
816
|
-
function
|
|
818
|
+
function w(e, t, r, i) {
|
|
817
819
|
const s = b(e, t), n = b(e, r), o = b(e, i);
|
|
818
820
|
if (!(s === void 0 || n === void 0))
|
|
819
821
|
return o === void 0 ? { x: s, y: n } : { x: s, y: n, z: o };
|
|
820
822
|
}
|
|
821
|
-
function
|
|
823
|
+
function We(e, t, r, i) {
|
|
822
824
|
const s = [];
|
|
823
825
|
for (let n = 0; n < e.length; n++) {
|
|
824
826
|
if (e[n].code !== t) continue;
|
|
825
|
-
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),
|
|
826
|
-
Number.isFinite(o) && Number.isFinite(
|
|
827
|
+
const o = Number(e[n].value), a = e.slice(n + 1).find((f) => f.code === r), c = e.slice(n + 1).find((f) => f.code === i), h = Number(a == null ? void 0 : a.value), l = Number(c == null ? void 0 : c.value);
|
|
828
|
+
Number.isFinite(o) && Number.isFinite(h) && s.push(Number.isFinite(l) ? { x: o, y: h, z: l } : { x: o, y: h });
|
|
827
829
|
}
|
|
828
830
|
return s;
|
|
829
831
|
}
|
|
830
|
-
function
|
|
832
|
+
function Re(e) {
|
|
831
833
|
const t = [];
|
|
832
834
|
for (let r = 0; r < e.length; r++) {
|
|
833
835
|
if (e[r].code !== 10) continue;
|
|
@@ -839,14 +841,14 @@ function De(e) {
|
|
|
839
841
|
}
|
|
840
842
|
return t;
|
|
841
843
|
}
|
|
842
|
-
function
|
|
844
|
+
function Oe(e) {
|
|
843
845
|
const t = e.filter((r) => r.code === 1 || r.code === 3).map((r) => r.value);
|
|
844
846
|
return t.length ? t.join("") : void 0;
|
|
845
847
|
}
|
|
846
848
|
function Z(e) {
|
|
847
849
|
return typeof e == "number" && Number.isFinite(e) ? I(e) : void 0;
|
|
848
850
|
}
|
|
849
|
-
class
|
|
851
|
+
class ze {
|
|
850
852
|
constructor(t = {}) {
|
|
851
853
|
d(this, "id", "dwf");
|
|
852
854
|
d(this, "label", "DWF/DWFx native viewer powered by dwf-viewer");
|
|
@@ -866,21 +868,21 @@ class Re {
|
|
|
866
868
|
}
|
|
867
869
|
async load(t, r = {}) {
|
|
868
870
|
var f, u, p, g;
|
|
869
|
-
const i = { ...this.defaults, ...r }, s = performance.now(), n = t.fileName ?? ((f = t.file) == null ? void 0 : f.name), o = await U(t), a =
|
|
871
|
+
const i = { ...this.defaults, ...r }, s = performance.now(), n = t.fileName ?? ((f = t.file) == null ? void 0 : f.name), o = await U(t), a = Lt(B(t, o), L(t));
|
|
870
872
|
(u = i.onProgress) == null || u.call(i, { phase: "parse", format: a, message: "Opening DWF/DWFx with dwf-viewer…", percent: 48 });
|
|
871
|
-
const c = await
|
|
873
|
+
const c = await se(o, { fileName: n });
|
|
872
874
|
(p = i.onProgress) == null || p.call(i, { phase: "normalize", format: a, message: "Reading DWF pages, sheets and model metadata…", percent: 76 });
|
|
873
|
-
const
|
|
874
|
-
return (g = i.onProgress) == null || g.call(i, { phase: "done", format:
|
|
875
|
+
const h = Tt(c, n, a, i.keepRaw === !0), l = performance.now() - s;
|
|
876
|
+
return (g = i.onProgress) == null || g.call(i, { phase: "done", format: h.format, message: "DWF/DWFx document ready.", percent: 100, elapsedMs: l }), { document: h, raw: i.keepRaw ? c : void 0, bytes: o.byteLength, elapsedMs: l, format: h.format, warnings: h.warnings };
|
|
875
877
|
}
|
|
876
878
|
async mount(t, r, i = {}) {
|
|
877
|
-
var z, _, H,
|
|
878
|
-
const s = { ...this.defaults, ...i }, n = performance.now(), o = t.fileName ?? ((z = t.file) == null ? void 0 : z.name), a = await U(t), c =
|
|
879
|
-
(_ = s.onProgress) == null || _.call(s, { phase: "native-render", format: c, message: "Mounting native DWF renderer…", percent: 28 }), this.unmount(), this.host = r, r.replaceChildren(), this.native = new
|
|
879
|
+
var z, _, H, xt, wt;
|
|
880
|
+
const s = { ...this.defaults, ...i }, n = performance.now(), o = t.fileName ?? ((z = t.file) == null ? void 0 : z.name), a = await U(t), c = Lt(B(t, a), L(t)), h = Ue(s), l = Bt(s), f = Ve(s, h, l), u = Zt(s, h, l);
|
|
881
|
+
(_ = s.onProgress) == null || _.call(s, { phase: "native-render", format: c, message: "Mounting native DWF renderer…", percent: 28 }), this.unmount(), this.host = r, r.replaceChildren(), this.native = new ne(r, f), (H = s.onProgress) == null || H.call(s, { phase: "parse", format: c, message: "Parsing DWF package and page streams…", percent: 58 }), await this.native.load(a, {
|
|
880
882
|
fileName: o,
|
|
881
883
|
...u
|
|
882
|
-
}), (
|
|
883
|
-
const p = this.native.getDocument(), g =
|
|
884
|
+
}), (xt = s.onProgress) == null || xt.call(s, { phase: "render", format: c, message: "Rendering DWF/DWFx with dwf-viewer…", percent: 88 }), this.lastStats = await this.native.render();
|
|
885
|
+
const p = this.native.getDocument(), g = Tt(p, o, c, s.keepRaw === !0);
|
|
884
886
|
g.metadata.loaderMode = "Native DWF", g.metadata.nativeRenderer = "dwf-viewer", g.metadata.nativeRenderStats = this.lastStats ? { ...this.lastStats, warnings: this.lastStats.warnings.length } : void 0;
|
|
885
887
|
const S = performance.now() - n;
|
|
886
888
|
return (wt = s.onProgress) == null || wt.call(s, { phase: "done", format: g.format, message: "DWF/DWFx rendered.", percent: 100, elapsedMs: S }), { document: g, raw: s.keepRaw ? p : void 0, bytes: a.byteLength, elapsedMs: S, format: g.format, warnings: g.warnings };
|
|
@@ -913,7 +915,7 @@ class Re {
|
|
|
913
915
|
if (r) {
|
|
914
916
|
if (typeof t.dwfBackground == "string") r.background = t.dwfBackground;
|
|
915
917
|
else {
|
|
916
|
-
const a =
|
|
918
|
+
const a = Bt(t);
|
|
917
919
|
a && (r.background = a);
|
|
918
920
|
}
|
|
919
921
|
typeof t.dwfPreferWebgl == "boolean" && ((i = r.setPreferWebgl) == null || i.call(r, t.dwfPreferWebgl)), typeof t.dwfPreferWasm == "boolean" && ((s = r.setPreferWasm) == null || s.call(r, t.dwfPreferWasm)), t.dwfLineWeightMode && ((n = r.setLineWeightMode) == null || n.call(r, t.dwfLineWeightMode)), q(r, "minStrokeCssPx", t.dwfMinStrokeCssPx), q(r, "maxOverviewStrokeCssPx", t.dwfMaxOverviewStrokeCssPx), q(r, "minTextCssPx", t.dwfMinTextCssPx), q(r, "minFilledAreaCssPx", t.dwfMinFilledAreaCssPx), (o = r.render) == null || o.call(r);
|
|
@@ -923,33 +925,33 @@ class Re {
|
|
|
923
925
|
return this.lastStats;
|
|
924
926
|
}
|
|
925
927
|
}
|
|
926
|
-
function
|
|
928
|
+
function Tt(e, t, r, i) {
|
|
927
929
|
var a, c;
|
|
928
|
-
const s =
|
|
929
|
-
for (const
|
|
930
|
+
const s = At((e == null ? void 0 : e.diagnostics) ?? []), n = ((e == null ? void 0 : e.pageData) ?? []).map((h, l) => _e(h, l));
|
|
931
|
+
for (const h of (e == null ? void 0 : e.pageData) ?? []) s.push(...At(h.diagnostics));
|
|
930
932
|
const o = {
|
|
931
933
|
parser: "dwf-viewer",
|
|
932
934
|
nativeRenderer: "dwf-viewer",
|
|
933
935
|
dwfKind: e == null ? void 0 : e.kind,
|
|
934
936
|
packageEntries: ((a = e == null ? void 0 : e.packageEntries) == null ? void 0 : a.length) ?? 0,
|
|
935
937
|
resources: ((c = e == null ? void 0 : e.resources) == null ? void 0 : c.length) ?? 0,
|
|
936
|
-
pageKinds:
|
|
937
|
-
pageNames: ((e == null ? void 0 : e.pages) ?? []).map((
|
|
938
|
+
pageKinds: Ge(((e == null ? void 0 : e.pageData) ?? []).map((h) => h.kind)),
|
|
939
|
+
pageNames: ((e == null ? void 0 : e.pages) ?? []).map((h) => h.name)
|
|
938
940
|
};
|
|
939
|
-
return
|
|
941
|
+
return Ut({
|
|
940
942
|
format: r,
|
|
941
943
|
sourceName: t,
|
|
942
944
|
layers: {},
|
|
943
945
|
blocks: {},
|
|
944
946
|
pages: n,
|
|
945
|
-
entities:
|
|
947
|
+
entities: ye(n),
|
|
946
948
|
metadata: o,
|
|
947
|
-
warnings:
|
|
949
|
+
warnings: Ze(s),
|
|
948
950
|
raw: i ? e : void 0
|
|
949
951
|
});
|
|
950
952
|
}
|
|
951
|
-
function
|
|
952
|
-
const r =
|
|
953
|
+
function _e(e, t) {
|
|
954
|
+
const r = He(e, t);
|
|
953
955
|
return {
|
|
954
956
|
index: t,
|
|
955
957
|
name: e.name || e.sourcePath || `${t + 1}`,
|
|
@@ -958,18 +960,18 @@ function Oe(e, t) {
|
|
|
958
960
|
entities: r
|
|
959
961
|
};
|
|
960
962
|
}
|
|
961
|
-
function
|
|
962
|
-
return e.kind === "w2d-text" ? e.primitives.flatMap((r, i) =>
|
|
963
|
+
function He(e, t) {
|
|
964
|
+
return e.kind === "w2d-text" ? e.primitives.flatMap((r, i) => Ye(r, t, i)) : e.kind === "image" ? [{ type: "DWF_IMAGE_PAGE", kind: "image", pageIndex: t, width: e.width, height: e.height, imageSource: e.sourcePath }] : e.kind === "w3d-model" ? e.model.meshes.map((r, i) => ({
|
|
963
965
|
id: r.id,
|
|
964
966
|
type: "W3D_MESH",
|
|
965
967
|
kind: "solid",
|
|
966
968
|
pageIndex: t,
|
|
967
|
-
color: r.color ?
|
|
969
|
+
color: r.color ? je(r.color) : void 0,
|
|
968
970
|
name: r.name || `mesh-${i + 1}`,
|
|
969
971
|
raw: { vertexCount: r.vertexCount, triangleCount: r.triangleCount, materialId: r.materialId }
|
|
970
972
|
})) : 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 } }];
|
|
971
973
|
}
|
|
972
|
-
function
|
|
974
|
+
function Ye(e, t, r) {
|
|
973
975
|
const i = {
|
|
974
976
|
id: `dwf-${t}-${r}`,
|
|
975
977
|
pageIndex: t,
|
|
@@ -983,7 +985,7 @@ function _e(e, t, r) {
|
|
|
983
985
|
...i,
|
|
984
986
|
type: e.type === "polygon" ? "DWF_POLYGON" : "DWF_POLYLINE",
|
|
985
987
|
kind: "polyline",
|
|
986
|
-
vertices:
|
|
988
|
+
vertices: Xe(e.points),
|
|
987
989
|
isClosed: e.type === "polygon"
|
|
988
990
|
}];
|
|
989
991
|
if (e.type === "path")
|
|
@@ -1014,36 +1016,36 @@ function _e(e, t, r) {
|
|
|
1014
1016
|
}
|
|
1015
1017
|
return [];
|
|
1016
1018
|
}
|
|
1017
|
-
function
|
|
1019
|
+
function Xe(e) {
|
|
1018
1020
|
const t = [];
|
|
1019
1021
|
for (let r = 0; r + 1 < e.length; r += 2) t.push({ x: e[r], y: e[r + 1], z: 0 });
|
|
1020
1022
|
return t;
|
|
1021
1023
|
}
|
|
1022
|
-
function
|
|
1024
|
+
function At(e) {
|
|
1023
1025
|
return e.filter((t) => t.level !== "info").map((t) => `${t.code}: ${t.message}${t.source ? ` (${t.source})` : ""}`);
|
|
1024
1026
|
}
|
|
1025
|
-
function
|
|
1027
|
+
function Lt(e, t) {
|
|
1026
1028
|
return t === "dwf" || t === "dwfx" || t === "xps" ? t : e === "dwf" || e === "dwfx" || e === "xps" ? e : "dwf";
|
|
1027
1029
|
}
|
|
1028
|
-
function
|
|
1030
|
+
function Ue(e) {
|
|
1029
1031
|
if (e.dwfWasmUrl) return e.dwfWasmUrl;
|
|
1030
1032
|
if (typeof document > "u") return;
|
|
1031
|
-
const t = e.wasmPath ? new URL(
|
|
1033
|
+
const t = e.wasmPath ? new URL($e(e.wasmPath), document.baseURI).href : new URL("wasm/", document.baseURI).href;
|
|
1032
1034
|
return new URL("dwfv-render.wasm", t).href;
|
|
1033
1035
|
}
|
|
1034
|
-
function
|
|
1036
|
+
function Bt(e) {
|
|
1035
1037
|
if (e.dwfBackground) return e.dwfBackground;
|
|
1036
1038
|
const t = e.canvasOptions;
|
|
1037
1039
|
return (t == null ? void 0 : t.background) ?? "#05070d";
|
|
1038
1040
|
}
|
|
1039
|
-
function
|
|
1041
|
+
function Ve(e, t, r) {
|
|
1040
1042
|
return {
|
|
1041
|
-
...
|
|
1043
|
+
...Zt(e, t, r),
|
|
1042
1044
|
maxDevicePixelRatio: e.dwfMaxDevicePixelRatio ?? 2,
|
|
1043
1045
|
maxCanvasPixels: e.dwfMaxCanvasPixels ?? 16777216
|
|
1044
1046
|
};
|
|
1045
1047
|
}
|
|
1046
|
-
function
|
|
1048
|
+
function Zt(e, t, r) {
|
|
1047
1049
|
return {
|
|
1048
1050
|
wasmUrl: t,
|
|
1049
1051
|
preferWebgl: e.dwfPreferWebgl ?? !0,
|
|
@@ -1061,36 +1063,36 @@ function Gt(e, t, r) {
|
|
|
1061
1063
|
function q(e, t, r) {
|
|
1062
1064
|
typeof r == "number" && Number.isFinite(r) && (e[t] = r);
|
|
1063
1065
|
}
|
|
1064
|
-
function
|
|
1066
|
+
function $e(e) {
|
|
1065
1067
|
return e.endsWith("/") ? e : `${e}/`;
|
|
1066
1068
|
}
|
|
1067
|
-
function
|
|
1069
|
+
function je(e) {
|
|
1068
1070
|
const [t, r, i] = e.map((s) => Math.max(0, Math.min(255, Math.round(s * 255))));
|
|
1069
1071
|
return `#${st(t)}${st(r)}${st(i)}`;
|
|
1070
1072
|
}
|
|
1071
1073
|
function st(e) {
|
|
1072
1074
|
return e.toString(16).padStart(2, "0");
|
|
1073
1075
|
}
|
|
1074
|
-
function
|
|
1076
|
+
function Ge(e) {
|
|
1075
1077
|
const t = {};
|
|
1076
1078
|
for (const r of e) t[r] = (t[r] ?? 0) + 1;
|
|
1077
1079
|
return t;
|
|
1078
1080
|
}
|
|
1079
|
-
function
|
|
1081
|
+
function Ze(e) {
|
|
1080
1082
|
return Array.from(new Set(e));
|
|
1081
1083
|
}
|
|
1082
|
-
function
|
|
1083
|
-
return new
|
|
1084
|
-
new
|
|
1085
|
-
new
|
|
1086
|
-
new
|
|
1084
|
+
function qe(e = {}) {
|
|
1085
|
+
return new ae([
|
|
1086
|
+
new me(e),
|
|
1087
|
+
new xe(e),
|
|
1088
|
+
new ze(e)
|
|
1087
1089
|
]);
|
|
1088
1090
|
}
|
|
1089
|
-
function
|
|
1091
|
+
function Ke(e) {
|
|
1090
1092
|
const t = e;
|
|
1091
1093
|
return t.nativeRenderer === !0 && typeof t.mount == "function";
|
|
1092
1094
|
}
|
|
1093
|
-
const
|
|
1095
|
+
const Je = {
|
|
1094
1096
|
1: "#ff0000",
|
|
1095
1097
|
2: "#ffff00",
|
|
1096
1098
|
3: "#00ff00",
|
|
@@ -1349,7 +1351,7 @@ const qe = {
|
|
|
1349
1351
|
function E(e, t = "#ffffff", r = t) {
|
|
1350
1352
|
if (typeof e != "number" || Number.isNaN(e)) return t;
|
|
1351
1353
|
const i = Math.abs(Math.trunc(e));
|
|
1352
|
-
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r :
|
|
1354
|
+
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r : Je[i] ?? t;
|
|
1353
1355
|
}
|
|
1354
1356
|
function V(e, t = "rgb") {
|
|
1355
1357
|
const r = Math.max(0, Math.trunc(e)) & 16777215, i = r >> 16 & 255, s = r >> 8 & 255, n = r & 255;
|
|
@@ -1358,7 +1360,7 @@ function V(e, t = "rgb") {
|
|
|
1358
1360
|
function F(e) {
|
|
1359
1361
|
if (typeof e == "string") {
|
|
1360
1362
|
const t = e.trim();
|
|
1361
|
-
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ?
|
|
1363
|
+
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ? Qe(t) ?? t : {
|
|
1362
1364
|
red: "#ff0000",
|
|
1363
1365
|
yellow: "#ffff00",
|
|
1364
1366
|
green: "#00ff00",
|
|
@@ -1377,7 +1379,7 @@ function F(e) {
|
|
|
1377
1379
|
return Number.isFinite(n) && n >= 0 && n < 1 ? `rgba(${r}, ${i}, ${s}, ${n})` : `rgb(${r}, ${i}, ${s})`;
|
|
1378
1380
|
}
|
|
1379
1381
|
}
|
|
1380
|
-
function
|
|
1382
|
+
function Qe(e) {
|
|
1381
1383
|
if (!e) return;
|
|
1382
1384
|
const t = e.trim();
|
|
1383
1385
|
if (/^#[0-9a-f]{8}$/i.test(t)) {
|
|
@@ -1395,11 +1397,11 @@ function D(e, t, r = {}) {
|
|
|
1395
1397
|
let n;
|
|
1396
1398
|
const o = F(e.trueColor) ?? F(e.color) ?? F(e.colorName);
|
|
1397
1399
|
if (o && (n = o), !n) {
|
|
1398
|
-
const a =
|
|
1400
|
+
const a = nr(e, ["trueColor", "true_color", "truecolor", "colorRGB", "colorRgb", "rgbColor", "rgb"]);
|
|
1399
1401
|
typeof a == "number" && a >= 0 && a <= 16777215 && (n = V(a, r.trueColorByteOrder ?? "rgb"));
|
|
1400
1402
|
}
|
|
1401
1403
|
if (!n) {
|
|
1402
|
-
const a =
|
|
1404
|
+
const a = Qt(e.colorIndex, e.colorNumber, e.aci);
|
|
1403
1405
|
typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (n = E(a, s, i));
|
|
1404
1406
|
}
|
|
1405
1407
|
if (!n && typeof e.color == "number") {
|
|
@@ -1407,10 +1409,10 @@ function D(e, t, r = {}) {
|
|
|
1407
1409
|
Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (n = E(a, s, i)) : n = V(a, r.trueColorByteOrder ?? "rgb");
|
|
1408
1410
|
}
|
|
1409
1411
|
if (!n) {
|
|
1410
|
-
const a =
|
|
1411
|
-
n =
|
|
1412
|
+
const a = sr(t, e.layer);
|
|
1413
|
+
n = er(a, r);
|
|
1412
1414
|
}
|
|
1413
|
-
return
|
|
1415
|
+
return qt(n ?? s, r);
|
|
1414
1416
|
}
|
|
1415
1417
|
function mt(e, t, r = {}) {
|
|
1416
1418
|
let i;
|
|
@@ -1419,62 +1421,62 @@ function mt(e, t, r = {}) {
|
|
|
1419
1421
|
const n = e.fillColor;
|
|
1420
1422
|
i = Math.abs(n) <= 257 ? E(n, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff") : V(n, r.trueColorByteOrder ?? "rgb");
|
|
1421
1423
|
}
|
|
1422
|
-
return !i && typeof e.fillColorIndex == "number" && (i = E(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ?
|
|
1424
|
+
return !i && typeof e.fillColorIndex == "number" && (i = E(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ? qt(i, r) : void 0;
|
|
1423
1425
|
}
|
|
1424
|
-
function
|
|
1426
|
+
function qt(e, t = {}) {
|
|
1425
1427
|
if (t.contrastMode !== "adaptive") return e;
|
|
1426
1428
|
const r = t.background ?? "#0b1020", i = t.foreground ?? "#ffffff";
|
|
1427
|
-
return
|
|
1429
|
+
return tr(e, r, i, t.minColorContrast ?? 2.4);
|
|
1428
1430
|
}
|
|
1429
|
-
function
|
|
1431
|
+
function tr(e, t, r, i = 2.4) {
|
|
1430
1432
|
const s = nt(r) ?? { r: 255, g: 255, b: 255, a: 1 }, n = nt(t) ?? { r: 11, g: 16, b: 32, a: 1 }, o = nt(e);
|
|
1431
1433
|
if (!o) return e;
|
|
1432
|
-
const a =
|
|
1434
|
+
const a = Ft(o, n);
|
|
1433
1435
|
if (ot(a, n) >= i) return e;
|
|
1434
|
-
const c = pt(n),
|
|
1435
|
-
for (const
|
|
1436
|
-
const f =
|
|
1437
|
-
if (ot(
|
|
1436
|
+
const c = pt(n), h = c < 0.5 ? { r: 255, g: 255, b: 255, a: o.a } : { r: 0, g: 0, b: 0, a: o.a };
|
|
1437
|
+
for (const l of [0.25, 0.4, 0.55, 0.7, 0.85, 1]) {
|
|
1438
|
+
const f = or(o, h, l);
|
|
1439
|
+
if (ot(Ft(f, n), n) >= i) return Dt(f);
|
|
1438
1440
|
}
|
|
1439
|
-
return ot(s, n) >= i ?
|
|
1441
|
+
return ot(s, n) >= i ? Dt(s) : c < 0.5 ? "#ffffff" : "#000000";
|
|
1440
1442
|
}
|
|
1441
|
-
function
|
|
1443
|
+
function Kt(e) {
|
|
1442
1444
|
return e ? e.isVisible !== !1 && e.isFrozen !== !0 : !0;
|
|
1443
1445
|
}
|
|
1444
|
-
function
|
|
1446
|
+
function er(e, t) {
|
|
1445
1447
|
if (!e) return;
|
|
1446
1448
|
const r = t.foreground ?? "#ffffff", i = F(e.trueColor);
|
|
1447
1449
|
if (i) return i;
|
|
1448
1450
|
if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return V(e.trueColor, t.trueColorByteOrder ?? "rgb");
|
|
1449
1451
|
const s = F(e.color);
|
|
1450
1452
|
if (s) return s;
|
|
1451
|
-
if (
|
|
1453
|
+
if (ir(e.colorIndex)) return E(e.colorIndex, r, r);
|
|
1452
1454
|
if (typeof e.color == "number") {
|
|
1453
1455
|
const n = Number(e.color);
|
|
1454
1456
|
return Math.abs(n) <= 257 ? E(n, r, r) : V(n, t.trueColorByteOrder ?? "rgb");
|
|
1455
1457
|
}
|
|
1456
1458
|
if (typeof e.colorIndex == "number") return E(e.colorIndex, r, r);
|
|
1457
1459
|
}
|
|
1458
|
-
function
|
|
1459
|
-
return
|
|
1460
|
+
function rr(e) {
|
|
1461
|
+
return Qt(e.colorIndex, e.colorNumber, e.aci) === 0 ? !0 : e.trueColor === void 0 && e.color === 0;
|
|
1460
1462
|
}
|
|
1461
|
-
function
|
|
1462
|
-
if (!
|
|
1463
|
+
function Jt(e, t, r, i = {}) {
|
|
1464
|
+
if (!rr(e)) return e;
|
|
1463
1465
|
const s = D(t, r, i);
|
|
1464
1466
|
return { ...e, color: s, trueColor: void 0, colorIndex: void 0, colorNumber: void 0 };
|
|
1465
1467
|
}
|
|
1466
|
-
function
|
|
1468
|
+
function ir(e) {
|
|
1467
1469
|
return typeof e == "number" && Number.isFinite(e) && Math.abs(Math.trunc(e)) >= 1 && Math.abs(Math.trunc(e)) <= 255;
|
|
1468
1470
|
}
|
|
1469
|
-
function
|
|
1471
|
+
function sr(e, t) {
|
|
1470
1472
|
if (!(!e || !t))
|
|
1471
1473
|
return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
1472
1474
|
}
|
|
1473
|
-
function
|
|
1475
|
+
function Qt(...e) {
|
|
1474
1476
|
for (const t of e)
|
|
1475
1477
|
if (typeof t == "number" && Number.isFinite(t)) return t;
|
|
1476
1478
|
}
|
|
1477
|
-
function
|
|
1479
|
+
function nr(e, t) {
|
|
1478
1480
|
const r = e;
|
|
1479
1481
|
for (const i of t) {
|
|
1480
1482
|
const s = r[i];
|
|
@@ -1511,7 +1513,7 @@ function nt(e) {
|
|
|
1511
1513
|
}
|
|
1512
1514
|
}
|
|
1513
1515
|
}
|
|
1514
|
-
function
|
|
1516
|
+
function Ft(e, t) {
|
|
1515
1517
|
const r = e.a + t.a * (1 - e.a);
|
|
1516
1518
|
return r <= 0 ? { r: 0, g: 0, b: 0, a: 0 } : {
|
|
1517
1519
|
r: (e.r * e.a + t.r * t.a * (1 - e.a)) / r,
|
|
@@ -1520,7 +1522,7 @@ function Bt(e, t) {
|
|
|
1520
1522
|
a: r
|
|
1521
1523
|
};
|
|
1522
1524
|
}
|
|
1523
|
-
function
|
|
1525
|
+
function or(e, t, r) {
|
|
1524
1526
|
const i = Math.max(0, Math.min(1, r));
|
|
1525
1527
|
return {
|
|
1526
1528
|
r: e.r + (t.r - e.r) * i,
|
|
@@ -1540,7 +1542,7 @@ function ot(e, t) {
|
|
|
1540
1542
|
const r = pt(e), i = pt(t), s = Math.max(r, i), n = Math.min(r, i);
|
|
1541
1543
|
return (s + 0.05) / (n + 0.05);
|
|
1542
1544
|
}
|
|
1543
|
-
function
|
|
1545
|
+
function Dt(e) {
|
|
1544
1546
|
const t = W(e.r), r = W(e.g), i = W(e.b);
|
|
1545
1547
|
return e.a < 0.999 ? `rgba(${t}, ${r}, ${i}, ${gt(e.a)})` : `rgb(${t}, ${r}, ${i})`;
|
|
1546
1548
|
}
|
|
@@ -1560,14 +1562,14 @@ function at(e, t) {
|
|
|
1560
1562
|
f: e.b * t.e + e.d * t.f + e.f
|
|
1561
1563
|
};
|
|
1562
1564
|
}
|
|
1563
|
-
function
|
|
1565
|
+
function Wt(e, t) {
|
|
1564
1566
|
return { a: 1, b: 0, c: 0, d: 1, e, f: t };
|
|
1565
1567
|
}
|
|
1566
|
-
function
|
|
1568
|
+
function ar(e) {
|
|
1567
1569
|
const t = Math.cos(e), r = Math.sin(e);
|
|
1568
1570
|
return { a: t, b: r, c: -r, d: t, e: 0, f: 0 };
|
|
1569
1571
|
}
|
|
1570
|
-
function
|
|
1572
|
+
function cr(e, t = e) {
|
|
1571
1573
|
return { a: e, b: 0, c: 0, d: t, e: 0, f: 0 };
|
|
1572
1574
|
}
|
|
1573
1575
|
function k(e, t) {
|
|
@@ -1577,14 +1579,14 @@ function k(e, t) {
|
|
|
1577
1579
|
z: "z" in e ? e.z : void 0
|
|
1578
1580
|
};
|
|
1579
1581
|
}
|
|
1580
|
-
function
|
|
1582
|
+
function Rt(e, t) {
|
|
1581
1583
|
if (e)
|
|
1582
1584
|
return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) => k(i, t)) }));
|
|
1583
1585
|
}
|
|
1584
1586
|
function tt(e, t = { x: 0, y: 0 }) {
|
|
1585
1587
|
const r = e.insertionPoint ?? { x: 0, y: 0 }, i = e.scale, s = Number(typeof i == "object" && i ? i.x ?? 1 : e.scaleX ?? 1), n = Number(typeof i == "object" && i ? i.y ?? s : e.scaleY ?? s), o = Number(e.rotation ?? 0);
|
|
1586
|
-
let a =
|
|
1587
|
-
return a = at(a,
|
|
1588
|
+
let a = Wt(r.x, r.y);
|
|
1589
|
+
return a = at(a, ar(Number.isFinite(o) ? o : 0)), a = at(a, cr(Number.isFinite(s) ? s : 1, Number.isFinite(n) ? n : 1)), a = at(a, Wt(-t.x, -t.y)), a;
|
|
1588
1590
|
}
|
|
1589
1591
|
function et(e, t) {
|
|
1590
1592
|
const r = { ...e, raw: e.raw ?? e };
|
|
@@ -1592,18 +1594,18 @@ function et(e, t) {
|
|
|
1592
1594
|
const s = k({ x: 0, y: 0 }, t), n = k(e.majorAxisEndPoint, t);
|
|
1593
1595
|
r.majorAxisEndPoint = { x: n.x - s.x, y: n.y - s.y, z: n.z };
|
|
1594
1596
|
}
|
|
1595
|
-
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 =
|
|
1597
|
+
e.vertices && (r.vertices = e.vertices.map((s) => ({ ...k(s, t), bulge: s.bulge, startWidth: s.startWidth, endWidth: s.endWidth }))), e.points && (r.points = e.points.map((s) => k(s, t))), e.controlPoints && (r.controlPoints = e.controlPoints.map((s) => k(s, t))), e.fitPoints && (r.fitPoints = e.fitPoints.map((s) => k(s, t))), e.commands && (r.commands = Rt(e.commands, t)), e.loops && (r.loops = e.loops.map((s) => {
|
|
1596
1598
|
var n;
|
|
1597
1599
|
return {
|
|
1598
1600
|
...s,
|
|
1599
1601
|
vertices: (n = s.vertices) == null ? void 0 : n.map((o) => k(o, t)),
|
|
1600
|
-
commands:
|
|
1602
|
+
commands: Rt(s.commands, t)
|
|
1601
1603
|
};
|
|
1602
1604
|
}));
|
|
1603
1605
|
const i = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c));
|
|
1604
1606
|
return typeof e.radius == "number" && Number.isFinite(i) && (r.radius = e.radius * i), r;
|
|
1605
1607
|
}
|
|
1606
|
-
const
|
|
1608
|
+
const hr = {
|
|
1607
1609
|
background: "#0b1020",
|
|
1608
1610
|
foreground: "#ffffff",
|
|
1609
1611
|
showUnsupportedMarkers: !1,
|
|
@@ -1626,7 +1628,7 @@ const ar = {
|
|
|
1626
1628
|
preserveDrawingBuffer: !1,
|
|
1627
1629
|
enableSpatialIndex: !0
|
|
1628
1630
|
};
|
|
1629
|
-
class
|
|
1631
|
+
class Ot {
|
|
1630
1632
|
constructor(t, r = {}) {
|
|
1631
1633
|
d(this, "canvas");
|
|
1632
1634
|
d(this, "ctx");
|
|
@@ -1645,7 +1647,7 @@ class Rt {
|
|
|
1645
1647
|
d(this, "onViewChange");
|
|
1646
1648
|
const i = t.getContext("2d");
|
|
1647
1649
|
if (!i) throw new Error("Canvas 2D context is not available.");
|
|
1648
|
-
this.canvas = t, this.ctx = i, this.opts = { ...
|
|
1650
|
+
this.canvas = t, this.ctx = i, this.opts = { ...hr, ...r }, this.canvas.classList.add("cad-viewer-canvas"), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
|
|
1649
1651
|
}
|
|
1650
1652
|
destroy() {
|
|
1651
1653
|
var t;
|
|
@@ -1710,7 +1712,7 @@ class Rt {
|
|
|
1710
1712
|
return { ...this.bounds };
|
|
1711
1713
|
}
|
|
1712
1714
|
getStats() {
|
|
1713
|
-
return
|
|
1715
|
+
return lr(this.stats);
|
|
1714
1716
|
}
|
|
1715
1717
|
getZoomRatio() {
|
|
1716
1718
|
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
@@ -1778,7 +1780,7 @@ class Rt {
|
|
|
1778
1780
|
const i = String(t.type ?? "UNKNOWN").toUpperCase();
|
|
1779
1781
|
this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
|
|
1780
1782
|
const s = this.lookupLayer(t.layer);
|
|
1781
|
-
if (t.isVisible === !1 || !
|
|
1783
|
+
if (t.isVisible === !1 || !Kt(s)) {
|
|
1782
1784
|
this.stats.skipped++;
|
|
1783
1785
|
return;
|
|
1784
1786
|
}
|
|
@@ -1847,7 +1849,7 @@ class Rt {
|
|
|
1847
1849
|
drawArc(t) {
|
|
1848
1850
|
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
1849
1851
|
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
1850
|
-
this.strokeWorldPolyline(t, K(
|
|
1852
|
+
this.strokeWorldPolyline(t, K(x(r), i, s, n, !0), !1);
|
|
1851
1853
|
}
|
|
1852
1854
|
drawPolyline(t) {
|
|
1853
1855
|
const r = t.vertices ?? t.points;
|
|
@@ -1856,8 +1858,8 @@ class Rt {
|
|
|
1856
1858
|
for (let o = 0; o < n; o++) {
|
|
1857
1859
|
const a = r[o], c = r[(o + 1) % r.length];
|
|
1858
1860
|
if (!m(a) || !m(c)) continue;
|
|
1859
|
-
const
|
|
1860
|
-
s.length > 0 &&
|
|
1861
|
+
const h = jt(a, c, Number(a.bulge ?? 0));
|
|
1862
|
+
s.length > 0 && h.shift(), s.push(...h);
|
|
1861
1863
|
}
|
|
1862
1864
|
this.strokeWorldPolyline(t, s, i);
|
|
1863
1865
|
}
|
|
@@ -1874,7 +1876,7 @@ class Rt {
|
|
|
1874
1876
|
this.beginStyledPath(t), this.ctx.moveTo(i.x - 3, i.y), this.ctx.lineTo(i.x + 3, i.y), this.ctx.moveTo(i.x, i.y - 3), this.ctx.lineTo(i.x, i.y + 3), this.finishStroke();
|
|
1875
1877
|
}
|
|
1876
1878
|
drawText(t) {
|
|
1877
|
-
const r = t.insertionPoint ?? t.startPoint ?? t.center, i =
|
|
1879
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = Gt(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
1878
1880
|
if (!m(r) || !i) return this.markSkipped(String(t.type));
|
|
1879
1881
|
this.drawTextAt(t, r, i, s, Number(t.rotation ?? 0));
|
|
1880
1882
|
}
|
|
@@ -1883,8 +1885,8 @@ class Rt {
|
|
|
1883
1885
|
if (i && r < this.opts.maxInsertDepth) {
|
|
1884
1886
|
const a = tt(t, i.basePoint ?? { x: 0, y: 0 });
|
|
1885
1887
|
for (const c of i.entities) {
|
|
1886
|
-
const
|
|
1887
|
-
this.drawEntityTracked(et(
|
|
1888
|
+
const h = Jt(c, t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast });
|
|
1889
|
+
this.drawEntityTracked(et(h, a), r + 1);
|
|
1888
1890
|
}
|
|
1889
1891
|
return;
|
|
1890
1892
|
}
|
|
@@ -1956,17 +1958,17 @@ class Rt {
|
|
|
1956
1958
|
drawImage(t) {
|
|
1957
1959
|
const r = t.insertionPoint;
|
|
1958
1960
|
if (!m(r)) return this.markSkipped(String(t.type));
|
|
1959
|
-
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),
|
|
1961
|
+
const i = Number(t.width ?? 32), s = Number(t.height ?? 32), n = this.worldToScreen(r), o = this.worldToScreen({ x: r.x + i, y: r.y - s }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y), f = t.imageDataUrl;
|
|
1960
1962
|
if (f) {
|
|
1961
1963
|
const u = this.getImage(f);
|
|
1962
1964
|
if (u.complete && u.naturalWidth > 0) {
|
|
1963
|
-
this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(u, a, c,
|
|
1965
|
+
this.ctx.save(), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.ctx.drawImage(u, a, c, h, l), this.ctx.restore(), this.stats.drawn++;
|
|
1964
1966
|
return;
|
|
1965
1967
|
}
|
|
1966
1968
|
u.onload = () => this.render();
|
|
1967
1969
|
}
|
|
1968
1970
|
if (!this.opts.showImagePlaceholders) return this.markSkipped(String(t.type));
|
|
1969
|
-
this.beginStyledPath(t), this.ctx.rect(a, c,
|
|
1971
|
+
this.beginStyledPath(t), this.ctx.rect(a, c, h, l), this.ctx.moveTo(a, c), this.ctx.lineTo(a + h, c + l), this.ctx.moveTo(a + h, c), this.ctx.lineTo(a, c + l), this.finishStroke();
|
|
1970
1972
|
}
|
|
1971
1973
|
getImage(t) {
|
|
1972
1974
|
let r = this.imageCache.get(t);
|
|
@@ -1983,7 +1985,7 @@ class Rt {
|
|
|
1983
1985
|
o.save(), o.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), o.translate(a.x, a.y), o.rotate(-n);
|
|
1984
1986
|
const c = Math.max(4, Math.min(256, Math.abs(s) * this.view.scale));
|
|
1985
1987
|
o.font = `${c}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, o.fillStyle = D(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), o.globalAlpha = A(Number(t.opacity ?? 1), 0, 1), o.textBaseline = "alphabetic";
|
|
1986
|
-
for (const [
|
|
1988
|
+
for (const [h, l] of i.split(/\r?\n/g).entries()) o.fillText(l, 0, h * c * 1.22);
|
|
1987
1989
|
o.restore(), this.stats.drawn++;
|
|
1988
1990
|
}
|
|
1989
1991
|
strokeWorldPolyline(t, r, i) {
|
|
@@ -2004,12 +2006,12 @@ class Rt {
|
|
|
2004
2006
|
entityAnchor(t) {
|
|
2005
2007
|
for (const r of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
2006
2008
|
const i = t[r];
|
|
2007
|
-
if (m(i)) return
|
|
2009
|
+
if (m(i)) return x(i);
|
|
2008
2010
|
}
|
|
2009
|
-
if (Array.isArray(t.vertices) && m(t.vertices[0])) return
|
|
2011
|
+
if (Array.isArray(t.vertices) && m(t.vertices[0])) return x(t.vertices[0]);
|
|
2010
2012
|
if (Array.isArray(t.commands) && t.commands.length) {
|
|
2011
2013
|
const r = t.commands.find((i) => i.points.length > 0);
|
|
2012
|
-
if (r) return
|
|
2014
|
+
if (r) return x(r.points[0]);
|
|
2013
2015
|
}
|
|
2014
2016
|
}
|
|
2015
2017
|
computeBounds(t) {
|
|
@@ -2019,7 +2021,7 @@ class Rt {
|
|
|
2019
2021
|
for (const s of t.pages)
|
|
2020
2022
|
v(r, { x: 0, y: 0 }), v(r, { x: s.width, y: s.height });
|
|
2021
2023
|
for (const s of t.entities) this.includeEntityBounds(r, s, 0);
|
|
2022
|
-
return
|
|
2024
|
+
return $t(r);
|
|
2023
2025
|
}
|
|
2024
2026
|
includeEntityBounds(t, r, i) {
|
|
2025
2027
|
const s = String(r.type ?? "").toUpperCase(), n = r.kind ?? R(s);
|
|
@@ -2034,7 +2036,7 @@ class Rt {
|
|
|
2034
2036
|
if (n === "line")
|
|
2035
2037
|
m(r.startPoint) && v(t, r.startPoint), m(r.endPoint) && v(t, r.endPoint);
|
|
2036
2038
|
else if (n === "circle" || n === "arc")
|
|
2037
|
-
m(r.center) && Number.isFinite(r.radius) &&
|
|
2039
|
+
m(r.center) && Number.isFinite(r.radius) && Vt(t, r.center, Number(r.radius));
|
|
2038
2040
|
else if (n === "polyline" || n === "solid" || n === "spline")
|
|
2039
2041
|
for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) && v(t, o);
|
|
2040
2042
|
else if (n === "ellipse")
|
|
@@ -2073,7 +2075,7 @@ class Rt {
|
|
|
2073
2075
|
});
|
|
2074
2076
|
}
|
|
2075
2077
|
}
|
|
2076
|
-
function
|
|
2078
|
+
function lr(e) {
|
|
2077
2079
|
return {
|
|
2078
2080
|
total: e.total,
|
|
2079
2081
|
drawn: e.drawn,
|
|
@@ -2089,7 +2091,7 @@ function cr(e) {
|
|
|
2089
2091
|
buildElapsedMs: e.buildElapsedMs
|
|
2090
2092
|
};
|
|
2091
2093
|
}
|
|
2092
|
-
const
|
|
2094
|
+
const fr = {
|
|
2093
2095
|
background: "#0b1020",
|
|
2094
2096
|
foreground: "#ffffff",
|
|
2095
2097
|
showUnsupportedMarkers: !1,
|
|
@@ -2112,7 +2114,7 @@ const lr = {
|
|
|
2112
2114
|
preserveDrawingBuffer: !1,
|
|
2113
2115
|
enableSpatialIndex: !0
|
|
2114
2116
|
};
|
|
2115
|
-
class
|
|
2117
|
+
class zt {
|
|
2116
2118
|
constructor(t, r = {}) {
|
|
2117
2119
|
d(this, "canvas");
|
|
2118
2120
|
d(this, "backend", "webgl");
|
|
@@ -2136,12 +2138,12 @@ class Ot {
|
|
|
2136
2138
|
d(this, "rafHandle", 0);
|
|
2137
2139
|
d(this, "onStats");
|
|
2138
2140
|
d(this, "onViewChange");
|
|
2139
|
-
const i =
|
|
2141
|
+
const i = dr(t, r);
|
|
2140
2142
|
if (!i) throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');
|
|
2141
|
-
this.canvas = t, this.gl = i, this.program =
|
|
2143
|
+
this.canvas = t, this.gl = i, this.program = ur(i), this.opts = { ...fr, ...r }, this.canvas.classList.add("cad-viewer-canvas", "cad-viewer-webgl-canvas"), this.createOverlayCanvas(), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
|
|
2142
2144
|
}
|
|
2143
2145
|
static isSupported() {
|
|
2144
|
-
return
|
|
2146
|
+
return te();
|
|
2145
2147
|
}
|
|
2146
2148
|
destroy() {
|
|
2147
2149
|
var t, r;
|
|
@@ -2151,15 +2153,15 @@ class Ot {
|
|
|
2151
2153
|
this.document = void 0, this.bounds = N(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.disposeScene(), this.render(), this.emitViewChange();
|
|
2152
2154
|
}
|
|
2153
2155
|
setDocument(t) {
|
|
2154
|
-
this.document = t, this.bounds =
|
|
2155
|
-
const r =
|
|
2156
|
-
this.scene =
|
|
2156
|
+
this.document = t, this.bounds = yr(t, this.opts), this.disposeScene();
|
|
2157
|
+
const r = pr(t, this.opts, this.bounds);
|
|
2158
|
+
this.scene = mr(this.gl, r), this.stats = Cr(this.scene, 0), this.fitToView();
|
|
2157
2159
|
}
|
|
2158
2160
|
getDocument() {
|
|
2159
2161
|
return this.document;
|
|
2160
2162
|
}
|
|
2161
2163
|
setOptions(t) {
|
|
2162
|
-
const r =
|
|
2164
|
+
const r = wr(this.opts, t);
|
|
2163
2165
|
if (this.opts = { ...this.opts, ...t }, r && this.document) {
|
|
2164
2166
|
this.setDocument(this.document);
|
|
2165
2167
|
return;
|
|
@@ -2213,7 +2215,7 @@ class Ot {
|
|
|
2213
2215
|
return { ...this.bounds };
|
|
2214
2216
|
}
|
|
2215
2217
|
getStats() {
|
|
2216
|
-
return
|
|
2218
|
+
return Pr(this.stats);
|
|
2217
2219
|
}
|
|
2218
2220
|
getZoomRatio() {
|
|
2219
2221
|
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
@@ -2237,7 +2239,7 @@ class Ot {
|
|
|
2237
2239
|
return this.cancelScheduledRender(), this.renderNow();
|
|
2238
2240
|
}
|
|
2239
2241
|
renderNow() {
|
|
2240
|
-
var
|
|
2242
|
+
var h;
|
|
2241
2243
|
const t = performance.now(), r = this.gl;
|
|
2242
2244
|
r.viewport(0, 0, this.canvas.width, this.canvas.height);
|
|
2243
2245
|
const i = bt(this.opts.background, [11, 16, 32, 255]);
|
|
@@ -2246,8 +2248,8 @@ class Ot {
|
|
|
2246
2248
|
const o = this.scene, a = this.visibleWorldBounds();
|
|
2247
2249
|
if (o) {
|
|
2248
2250
|
r.useProgram(this.program.program), r.uniform2f(this.program.uViewCenter, this.view.centerX - o.origin.x, this.view.centerY - o.origin.y), r.uniform1f(this.program.uScale, this.view.scale * this.dpr), r.uniform2f(this.program.uViewport, this.canvas.width, this.canvas.height), r.uniform1f(this.program.uPointSize, Math.max(2, Math.min(12, 4 * this.dpr)));
|
|
2249
|
-
const
|
|
2250
|
-
s +=
|
|
2251
|
+
const l = this.drawBatches(o.lineBatches, r.LINES, a);
|
|
2252
|
+
s += l.visible, n += l.culled;
|
|
2251
2253
|
const f = this.drawBatches(o.triangleBatches, r.TRIANGLES, a);
|
|
2252
2254
|
s += f.visible, n += f.culled;
|
|
2253
2255
|
const u = this.drawBatches(o.pointBatches, r.POINTS, a);
|
|
@@ -2255,13 +2257,13 @@ class Ot {
|
|
|
2255
2257
|
}
|
|
2256
2258
|
this.renderOverlay(a);
|
|
2257
2259
|
const c = performance.now() - t;
|
|
2258
|
-
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 }, (
|
|
2260
|
+
return this.stats = o ? { ...o.stats, renderElapsedMs: c, backend: "webgl", primitiveCount: o.primitiveCount, visiblePrimitiveCount: s, culledPrimitiveCount: n, gpuMemoryBytes: o.gpuMemoryBytes, buildElapsedMs: o.buildElapsedMs } : { total: 0, drawn: 0, skipped: 0, byType: {}, unsupported: {}, renderElapsedMs: c, backend: "webgl", primitiveCount: 0, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: 0, buildElapsedMs: 0 }, (h = this.onStats) == null || h.call(this, this.getStats()), this.getStats();
|
|
2259
2261
|
}
|
|
2260
2262
|
drawBatches(t, r, i) {
|
|
2261
2263
|
const s = this.gl;
|
|
2262
2264
|
let n = 0, o = 0;
|
|
2263
2265
|
for (const a of t) {
|
|
2264
|
-
if (!
|
|
2266
|
+
if (!lt(a.bounds, i)) {
|
|
2265
2267
|
o += a.primitiveCount;
|
|
2266
2268
|
continue;
|
|
2267
2269
|
}
|
|
@@ -2298,32 +2300,32 @@ class Ot {
|
|
|
2298
2300
|
let n = 0;
|
|
2299
2301
|
for (const o of r) {
|
|
2300
2302
|
if (n >= s) break;
|
|
2301
|
-
if (!
|
|
2303
|
+
if (!lt(o.bounds, i)) continue;
|
|
2302
2304
|
const a = Math.abs(o.height) * this.view.scale;
|
|
2303
2305
|
if (a < this.opts.textMinPixelHeight) continue;
|
|
2304
2306
|
const c = this.worldToScreen(o.point);
|
|
2305
2307
|
if (c.x < -512 || c.y < -512 || c.x > this.cssWidth + 512 || c.y > this.cssHeight + 512) continue;
|
|
2306
2308
|
t.save(), t.translate(c.x, c.y), t.rotate(-o.rotation);
|
|
2307
|
-
const
|
|
2308
|
-
t.font = `${
|
|
2309
|
-
for (const [
|
|
2309
|
+
const h = Math.max(4, Math.min(256, a));
|
|
2310
|
+
t.font = `${h}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`, t.fillStyle = o.color, t.globalAlpha = o.opacity, t.textBaseline = "alphabetic";
|
|
2311
|
+
for (const [l, f] of o.text.split(/\r?\n/g).entries()) t.fillText(f, 0, l * h * 1.22);
|
|
2310
2312
|
t.restore(), n++;
|
|
2311
2313
|
}
|
|
2312
2314
|
}
|
|
2313
2315
|
drawImagesOverlay(t, r, i) {
|
|
2314
2316
|
for (const s of r) {
|
|
2315
|
-
if (!
|
|
2316
|
-
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),
|
|
2317
|
-
if (!(
|
|
2317
|
+
if (!lt(s.bounds, i)) continue;
|
|
2318
|
+
const n = this.worldToScreen(s.point), o = this.worldToScreen({ x: s.point.x + s.width, y: s.point.y - s.height }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y);
|
|
2319
|
+
if (!(h < 1 || l < 1)) {
|
|
2318
2320
|
if (s.source) {
|
|
2319
2321
|
const f = this.getImage(s.source);
|
|
2320
2322
|
if (f.complete && f.naturalWidth > 0) {
|
|
2321
|
-
t.save(), t.globalAlpha = s.opacity, t.drawImage(f, a, c,
|
|
2323
|
+
t.save(), t.globalAlpha = s.opacity, t.drawImage(f, a, c, h, l), t.restore();
|
|
2322
2324
|
continue;
|
|
2323
2325
|
}
|
|
2324
2326
|
f.onload = () => this.scheduleRender();
|
|
2325
2327
|
}
|
|
2326
|
-
this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = s.color, t.globalAlpha = s.opacity, t.lineWidth = 1, t.strokeRect(a, c,
|
|
2328
|
+
this.opts.showImagePlaceholders && (t.save(), t.strokeStyle = s.color, t.globalAlpha = s.opacity, t.lineWidth = 1, t.strokeRect(a, c, h, l), t.beginPath(), t.moveTo(a, c), t.lineTo(a + h, c + l), t.moveTo(a + h, c), t.lineTo(a, c + l), t.stroke(), t.restore());
|
|
2327
2329
|
}
|
|
2328
2330
|
}
|
|
2329
2331
|
}
|
|
@@ -2397,12 +2399,12 @@ class Ot {
|
|
|
2397
2399
|
});
|
|
2398
2400
|
}
|
|
2399
2401
|
}
|
|
2400
|
-
function
|
|
2402
|
+
function te() {
|
|
2401
2403
|
if (typeof document > "u") return !1;
|
|
2402
2404
|
const e = document.createElement("canvas");
|
|
2403
2405
|
return !!(e.getContext("webgl2") ?? e.getContext("webgl") ?? e.getContext("experimental-webgl"));
|
|
2404
2406
|
}
|
|
2405
|
-
function
|
|
2407
|
+
function dr(e, t) {
|
|
2406
2408
|
const r = {
|
|
2407
2409
|
alpha: !1,
|
|
2408
2410
|
antialias: t.antialias ?? !0,
|
|
@@ -2413,7 +2415,7 @@ function hr(e, t) {
|
|
|
2413
2415
|
};
|
|
2414
2416
|
return e.getContext("webgl2", r) ?? e.getContext("webgl", r) ?? e.getContext("experimental-webgl", r) ?? void 0;
|
|
2415
2417
|
}
|
|
2416
|
-
function
|
|
2418
|
+
function ur(e) {
|
|
2417
2419
|
const t = `
|
|
2418
2420
|
attribute vec2 a_position;
|
|
2419
2421
|
attribute vec4 a_color;
|
|
@@ -2438,15 +2440,15 @@ function fr(e) {
|
|
|
2438
2440
|
void main() {
|
|
2439
2441
|
gl_FragColor = v_color;
|
|
2440
2442
|
}
|
|
2441
|
-
`, i =
|
|
2443
|
+
`, i = _t(e, e.VERTEX_SHADER, t), s = _t(e, e.FRAGMENT_SHADER, r), n = e.createProgram();
|
|
2442
2444
|
if (!n) throw new Error("Failed to create WebGL program.");
|
|
2443
2445
|
if (e.attachShader(n, i), e.attachShader(n, s), e.linkProgram(n), !e.getProgramParameter(n, e.LINK_STATUS)) {
|
|
2444
|
-
const
|
|
2445
|
-
throw e.deleteProgram(n), new Error(
|
|
2446
|
+
const l = e.getProgramInfoLog(n) ?? "Unknown WebGL program link error.";
|
|
2447
|
+
throw e.deleteProgram(n), new Error(l);
|
|
2446
2448
|
}
|
|
2447
2449
|
e.deleteShader(i), e.deleteShader(s);
|
|
2448
|
-
const o = e.getUniformLocation(n, "u_viewCenter"), a = e.getUniformLocation(n, "u_scale"), c = e.getUniformLocation(n, "u_viewport"),
|
|
2449
|
-
if (!o || !a || !c || !
|
|
2450
|
+
const o = e.getUniformLocation(n, "u_viewCenter"), a = e.getUniformLocation(n, "u_scale"), c = e.getUniformLocation(n, "u_viewport"), h = e.getUniformLocation(n, "u_pointSize");
|
|
2451
|
+
if (!o || !a || !c || !h) throw new Error("Failed to resolve WebGL shader uniforms.");
|
|
2450
2452
|
return {
|
|
2451
2453
|
program: n,
|
|
2452
2454
|
aPosition: e.getAttribLocation(n, "a_position"),
|
|
@@ -2454,10 +2456,10 @@ function fr(e) {
|
|
|
2454
2456
|
uViewCenter: o,
|
|
2455
2457
|
uScale: a,
|
|
2456
2458
|
uViewport: c,
|
|
2457
|
-
uPointSize:
|
|
2459
|
+
uPointSize: h
|
|
2458
2460
|
};
|
|
2459
2461
|
}
|
|
2460
|
-
function
|
|
2462
|
+
function _t(e, t, r) {
|
|
2461
2463
|
const i = e.createShader(t);
|
|
2462
2464
|
if (!i) throw new Error("Failed to create WebGL shader.");
|
|
2463
2465
|
if (e.shaderSource(i, r), e.compileShader(i), !e.getShaderParameter(i, e.COMPILE_STATUS)) {
|
|
@@ -2466,13 +2468,13 @@ function zt(e, t, r) {
|
|
|
2466
2468
|
}
|
|
2467
2469
|
return i;
|
|
2468
2470
|
}
|
|
2469
|
-
function
|
|
2471
|
+
function mr(e, t) {
|
|
2470
2472
|
let r = 0;
|
|
2471
2473
|
const i = (a) => a.map((c) => {
|
|
2472
|
-
const
|
|
2474
|
+
const h = Ht(e, c.positions), l = Ht(e, c.colors), f = c.positions.byteLength + c.colors.byteLength;
|
|
2473
2475
|
return r += f, {
|
|
2474
|
-
positionBuffer:
|
|
2475
|
-
colorBuffer:
|
|
2476
|
+
positionBuffer: h,
|
|
2477
|
+
colorBuffer: l,
|
|
2476
2478
|
vertexCount: c.positions.length / 2,
|
|
2477
2479
|
primitiveCount: c.primitiveCount,
|
|
2478
2480
|
bounds: c.bounds,
|
|
@@ -2492,18 +2494,18 @@ function dr(e, t) {
|
|
|
2492
2494
|
buildElapsedMs: t.buildElapsedMs
|
|
2493
2495
|
};
|
|
2494
2496
|
}
|
|
2495
|
-
function
|
|
2497
|
+
function Ht(e, t) {
|
|
2496
2498
|
const r = e.createBuffer();
|
|
2497
2499
|
if (!r) throw new Error("Failed to create WebGL buffer.");
|
|
2498
2500
|
return e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW), r;
|
|
2499
2501
|
}
|
|
2500
|
-
function
|
|
2501
|
-
const i = performance.now(), s = O(r) ? { x: (r.minX + r.maxX) / 2, y: (r.minY + r.maxY) / 2 } : { x: 0, y: 0 }, n = new
|
|
2502
|
+
function pr(e, t, r) {
|
|
2503
|
+
const i = performance.now(), s = O(r) ? { x: (r.minX + r.maxX) / 2, y: (r.minY + r.maxY) / 2 } : { x: 0, y: 0 }, n = new gr(e, t, r, s);
|
|
2502
2504
|
for (const a of e.entities) n.addEntityTracked(a, 0);
|
|
2503
2505
|
const o = n.finalize();
|
|
2504
2506
|
return o.buildElapsedMs = performance.now() - i, o;
|
|
2505
2507
|
}
|
|
2506
|
-
class
|
|
2508
|
+
class gr {
|
|
2507
2509
|
constructor(t, r, i, s) {
|
|
2508
2510
|
d(this, "lineBuckets", /* @__PURE__ */ new Map());
|
|
2509
2511
|
d(this, "triangleBuckets", /* @__PURE__ */ new Map());
|
|
@@ -2523,7 +2525,7 @@ class mr {
|
|
|
2523
2525
|
const i = String(t.type ?? "UNKNOWN").toUpperCase();
|
|
2524
2526
|
this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
|
|
2525
2527
|
const s = this.lookupLayer(t.layer);
|
|
2526
|
-
if (t.isVisible === !1 || !
|
|
2528
|
+
if (t.isVisible === !1 || !Kt(s)) {
|
|
2527
2529
|
this.stats.skipped++;
|
|
2528
2530
|
return;
|
|
2529
2531
|
}
|
|
@@ -2599,8 +2601,8 @@ class mr {
|
|
|
2599
2601
|
for (let o = 0; o < n; o++) {
|
|
2600
2602
|
const a = r[o], c = r[(o + 1) % r.length];
|
|
2601
2603
|
if (!m(a) || !m(c)) continue;
|
|
2602
|
-
const
|
|
2603
|
-
s.length > 0 &&
|
|
2604
|
+
const h = jt(a, c, Number(a.bulge ?? 0), Math.max(4, Math.min(24, this.opts.maxCurveSegments / 4)));
|
|
2605
|
+
s.length > 0 && h.shift(), s.push(...h);
|
|
2604
2606
|
}
|
|
2605
2607
|
if (s.length < 2) return this.markSkipped(String(t.type));
|
|
2606
2608
|
this.addPolyline(s, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
@@ -2611,9 +2613,9 @@ class mr {
|
|
|
2611
2613
|
this.addPolyline(r, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
2612
2614
|
}
|
|
2613
2615
|
addTextEntity(t) {
|
|
2614
|
-
const r = t.insertionPoint ?? t.startPoint ?? t.center, i =
|
|
2616
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = Gt(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
2615
2617
|
if (!m(r) || !i || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2616
|
-
const n =
|
|
2618
|
+
const n = x(r), o = Math.max(1, i.split(/\r?\n/g).reduce((c, h) => Math.max(c, h.length), 0)) * Math.abs(s) * 0.62, a = Math.max(1, i.split(/\r?\n/g).length) * Math.abs(s) * 1.22;
|
|
2617
2619
|
this.textItems.push({
|
|
2618
2620
|
point: n,
|
|
2619
2621
|
text: i,
|
|
@@ -2634,7 +2636,7 @@ class mr {
|
|
|
2634
2636
|
if (i && r < this.opts.maxInsertDepth) {
|
|
2635
2637
|
const n = tt(t, i.basePoint ?? { x: 0, y: 0 });
|
|
2636
2638
|
for (const o of i.entities) {
|
|
2637
|
-
const a =
|
|
2639
|
+
const a = Jt(o, t, this.document, this.colorOptions());
|
|
2638
2640
|
this.addEntityTracked(et(a, n), r + 1);
|
|
2639
2641
|
}
|
|
2640
2642
|
return;
|
|
@@ -2647,7 +2649,7 @@ class mr {
|
|
|
2647
2649
|
addSolidEntity(t) {
|
|
2648
2650
|
const r = t.vertices ?? t.points;
|
|
2649
2651
|
if (!Array.isArray(r) || r.length < 3) return this.markSkipped(String(t.type));
|
|
2650
|
-
const i = r.filter(m).map(
|
|
2652
|
+
const i = r.filter(m).map(x);
|
|
2651
2653
|
if (i.length < 3) return this.markSkipped(String(t.type));
|
|
2652
2654
|
const s = this.fillBytes(t) ?? this.strokeBytes(t);
|
|
2653
2655
|
this.addTriangleFan(i, s), this.addPolyline(i, !0, this.strokeBytes(t)), this.stats.drawn++;
|
|
@@ -2659,7 +2661,7 @@ class mr {
|
|
|
2659
2661
|
const i = this.strokeBytes(t), s = this.fillBytes(t);
|
|
2660
2662
|
let n = !1;
|
|
2661
2663
|
for (const a of r) {
|
|
2662
|
-
const c = (o = a.commands) != null && o.length ?
|
|
2664
|
+
const c = (o = a.commands) != null && o.length ? Yt(a.commands, this.opts.maxCurveSegments) : (a.vertices ?? []).filter(m).map(x);
|
|
2663
2665
|
c.length < 2 || (this.addPolyline(c, !0, i), s && c.length >= 3 && this.addTriangleFan(c, s), n = !0);
|
|
2664
2666
|
}
|
|
2665
2667
|
if (!n) return this.markSkipped("HATCH");
|
|
@@ -2669,12 +2671,12 @@ class mr {
|
|
|
2669
2671
|
var i;
|
|
2670
2672
|
const r = (i = t.fitPoints) != null && i.length ? t.fitPoints : t.controlPoints;
|
|
2671
2673
|
if (!r || r.length < 2) return this.markSkipped("SPLINE");
|
|
2672
|
-
this.addPolyline(r.filter(m).map(
|
|
2674
|
+
this.addPolyline(r.filter(m).map(x), !!t.isClosed, this.strokeBytes(t)), this.stats.drawn++;
|
|
2673
2675
|
}
|
|
2674
2676
|
addPathEntity(t) {
|
|
2675
2677
|
var s;
|
|
2676
2678
|
if (!((s = t.commands) != null && s.length)) return this.markSkipped(String(t.type));
|
|
2677
|
-
const r =
|
|
2679
|
+
const r = Yt(t.commands, this.opts.maxCurveSegments);
|
|
2678
2680
|
if (r.length < 2) return this.markSkipped(String(t.type));
|
|
2679
2681
|
this.addPolyline(r, !1, this.strokeBytes(t));
|
|
2680
2682
|
const i = this.fillBytes(t);
|
|
@@ -2685,15 +2687,15 @@ class mr {
|
|
|
2685
2687
|
if (!m(r)) return this.markSkipped(String(t.type));
|
|
2686
2688
|
const i = Number(t.width ?? 32), s = Number(t.height ?? 32);
|
|
2687
2689
|
if (!Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2688
|
-
const n =
|
|
2690
|
+
const n = x(r), o = ht([n, { x: n.x + i, y: n.y - s }]);
|
|
2689
2691
|
this.imageItems.push({ point: n, width: i, height: s, source: t.imageDataUrl ?? t.imageSource, color: D(t, this.document, this.colorOptions()), opacity: A(Number(t.opacity ?? 1), 0, 1), bounds: o }), this.stats.drawn++;
|
|
2690
2692
|
}
|
|
2691
2693
|
addUnsupportedMarker(t) {
|
|
2692
|
-
const r =
|
|
2694
|
+
const r = ee(t);
|
|
2693
2695
|
r && this.addPoint(r, this.strokeBytes(t));
|
|
2694
2696
|
}
|
|
2695
2697
|
addPolyline(t, r, i) {
|
|
2696
|
-
const s = t.filter(m).map(
|
|
2698
|
+
const s = t.filter(m).map(x);
|
|
2697
2699
|
if (!(s.length < 2)) {
|
|
2698
2700
|
for (let n = 0; n < s.length - 1; n++) this.addSegment(s[n], s[n + 1], i);
|
|
2699
2701
|
r && this.addSegment(s[s.length - 1], s[0], i);
|
|
@@ -2701,24 +2703,24 @@ class mr {
|
|
|
2701
2703
|
}
|
|
2702
2704
|
addSegment(t, r, i) {
|
|
2703
2705
|
if (!m(t) || !m(r) || Math.hypot(t.x - r.x, t.y - r.y) <= 1e-14) return;
|
|
2704
|
-
const s = this.batchFor(this.lineBuckets,
|
|
2706
|
+
const s = this.batchFor(this.lineBuckets, ht([t, r]));
|
|
2705
2707
|
T(s, t, i, this.origin), T(s, r, i, this.origin), s.primitiveCount++, this.primitiveCount++;
|
|
2706
2708
|
}
|
|
2707
2709
|
addPoint(t, r) {
|
|
2708
|
-
const i = this.batchFor(this.pointBuckets,
|
|
2710
|
+
const i = this.batchFor(this.pointBuckets, xr(t));
|
|
2709
2711
|
T(i, t, r, this.origin), i.primitiveCount++, this.primitiveCount++;
|
|
2710
2712
|
}
|
|
2711
2713
|
addTriangleFan(t, r) {
|
|
2712
|
-
const i = t.filter(m).map(
|
|
2714
|
+
const i = t.filter(m).map(x);
|
|
2713
2715
|
if (i.length < 3) return;
|
|
2714
|
-
const s =
|
|
2716
|
+
const s = ht(i), n = this.batchFor(this.triangleBuckets, s);
|
|
2715
2717
|
for (let o = 1; o < i.length - 1; o++)
|
|
2716
2718
|
T(n, i[0], r, this.origin), T(n, i[o], r, this.origin), T(n, i[o + 1], r, this.origin), n.primitiveCount++, this.primitiveCount++;
|
|
2717
2719
|
}
|
|
2718
2720
|
batchFor(t, r) {
|
|
2719
2721
|
const i = this.bucketKey(r);
|
|
2720
2722
|
let s = t.get(i);
|
|
2721
|
-
return s || (s =
|
|
2723
|
+
return s || (s = br(), t.set(i, s)), v(s.bounds, { x: r.minX, y: r.minY }), v(s.bounds, { x: r.maxX, y: r.maxY }), s;
|
|
2722
2724
|
}
|
|
2723
2725
|
bucketKey(t) {
|
|
2724
2726
|
if (!Number.isFinite(this.tileSize)) return "all";
|
|
@@ -2747,7 +2749,7 @@ class mr {
|
|
|
2747
2749
|
return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
2748
2750
|
}
|
|
2749
2751
|
}
|
|
2750
|
-
function
|
|
2752
|
+
function br() {
|
|
2751
2753
|
return { positions: [], colors: [], bounds: N(), primitiveCount: 0 };
|
|
2752
2754
|
}
|
|
2753
2755
|
function T(e, t, r, i) {
|
|
@@ -2762,20 +2764,20 @@ function ct(e, t) {
|
|
|
2762
2764
|
r.push({ positions: new Float32Array(i.positions), colors: new Uint8Array(i.colors), bounds: { ...i.bounds }, primitiveCount: i.primitiveCount });
|
|
2763
2765
|
continue;
|
|
2764
2766
|
}
|
|
2765
|
-
const n =
|
|
2767
|
+
const n = vr(i), o = Math.max(n, Math.floor(t / n) * n);
|
|
2766
2768
|
for (let a = 0; a < s; a += o) {
|
|
2767
|
-
const c = Math.min(s, a + o),
|
|
2768
|
-
for (let u = 0; u <
|
|
2769
|
-
r.push({ positions: new Float32Array(
|
|
2769
|
+
const c = Math.min(s, a + o), h = i.positions.slice(a * 2, c * 2), l = i.colors.slice(a * 4, c * 4), f = N();
|
|
2770
|
+
for (let u = 0; u < h.length; u += 2) v(f, { x: h[u], y: h[u + 1] });
|
|
2771
|
+
r.push({ positions: new Float32Array(h), colors: new Uint8Array(l), bounds: { ...i.bounds }, primitiveCount: Math.floor((c - a) / n) });
|
|
2770
2772
|
}
|
|
2771
2773
|
}
|
|
2772
2774
|
return r;
|
|
2773
2775
|
}
|
|
2774
|
-
function
|
|
2776
|
+
function vr(e) {
|
|
2775
2777
|
const t = e.positions.length / 2;
|
|
2776
2778
|
return t === e.primitiveCount ? 1 : t === e.primitiveCount * 3 ? 3 : 2;
|
|
2777
2779
|
}
|
|
2778
|
-
function
|
|
2780
|
+
function yr(e, t) {
|
|
2779
2781
|
var n;
|
|
2780
2782
|
const r = N();
|
|
2781
2783
|
if ((n = e.pages) != null && n.length)
|
|
@@ -2785,96 +2787,96 @@ function br(e, t) {
|
|
|
2785
2787
|
if (o)
|
|
2786
2788
|
return e.blocks[o] ?? e.blocks[o.toLowerCase()] ?? Object.values(e.blocks).find((a) => a.name.toLowerCase() === o.toLowerCase());
|
|
2787
2789
|
}, s = (o, a) => {
|
|
2788
|
-
const c = String(o.type ?? "").toUpperCase(),
|
|
2789
|
-
if (
|
|
2790
|
-
const
|
|
2791
|
-
if (
|
|
2792
|
-
const f = tt(o,
|
|
2793
|
-
for (const u of
|
|
2790
|
+
const c = String(o.type ?? "").toUpperCase(), h = o.kind ?? R(c);
|
|
2791
|
+
if (h === "insert") {
|
|
2792
|
+
const l = i(o.blockName ?? o.name);
|
|
2793
|
+
if (l && a < t.maxInsertDepth) {
|
|
2794
|
+
const f = tt(o, l.basePoint ?? { x: 0, y: 0 });
|
|
2795
|
+
for (const u of l.entities) s(et(u, f), a + 1);
|
|
2794
2796
|
return;
|
|
2795
2797
|
}
|
|
2796
2798
|
}
|
|
2797
|
-
if (
|
|
2799
|
+
if (h === "line")
|
|
2798
2800
|
m(o.startPoint) && v(r, o.startPoint), m(o.endPoint) && v(r, o.endPoint);
|
|
2799
|
-
else if (
|
|
2800
|
-
m(o.center) && Number.isFinite(o.radius) &&
|
|
2801
|
-
else if (
|
|
2802
|
-
for (const
|
|
2803
|
-
else if (
|
|
2804
|
-
m(o.center) && m(o.majorAxisEndPoint) && J(o.center, o.majorAxisEndPoint, Number(o.axisRatio ?? 1), Number(o.startAngle ?? 0), Number(o.endAngle ?? Math.PI * 2), t.maxCurveSegments).forEach((
|
|
2805
|
-
else if (
|
|
2806
|
-
for (const
|
|
2807
|
-
else if (
|
|
2808
|
-
for (const
|
|
2809
|
-
for (const f of
|
|
2810
|
-
for (const f of
|
|
2801
|
+
else if (h === "circle" || h === "arc")
|
|
2802
|
+
m(o.center) && Number.isFinite(o.radius) && Vt(r, o.center, Number(o.radius));
|
|
2803
|
+
else if (h === "polyline" || h === "solid" || h === "spline")
|
|
2804
|
+
for (const l of [...o.vertices ?? [], ...o.points ?? [], ...o.controlPoints ?? [], ...o.fitPoints ?? []]) m(l) && v(r, l);
|
|
2805
|
+
else if (h === "ellipse")
|
|
2806
|
+
m(o.center) && m(o.majorAxisEndPoint) && J(o.center, o.majorAxisEndPoint, Number(o.axisRatio ?? 1), Number(o.startAngle ?? 0), Number(o.endAngle ?? Math.PI * 2), t.maxCurveSegments).forEach((l) => v(r, l));
|
|
2807
|
+
else if (h === "path")
|
|
2808
|
+
for (const l of o.commands ?? []) for (const f of l.points) v(r, f);
|
|
2809
|
+
else if (h === "hatch")
|
|
2810
|
+
for (const l of o.loops ?? []) {
|
|
2811
|
+
for (const f of l.vertices ?? []) v(r, f);
|
|
2812
|
+
for (const f of l.commands ?? []) for (const u of f.points) v(r, u);
|
|
2811
2813
|
}
|
|
2812
2814
|
else {
|
|
2813
|
-
const
|
|
2814
|
-
|
|
2815
|
+
const l = ee(o);
|
|
2816
|
+
l && v(r, l);
|
|
2815
2817
|
}
|
|
2816
2818
|
};
|
|
2817
2819
|
for (const o of e.entities) s(o, 0);
|
|
2818
|
-
return
|
|
2820
|
+
return $t(r);
|
|
2819
2821
|
}
|
|
2820
|
-
function
|
|
2822
|
+
function Yt(e, t) {
|
|
2821
2823
|
const r = [];
|
|
2822
2824
|
let i, s;
|
|
2823
2825
|
const n = (o) => {
|
|
2824
|
-
(!r.length || Math.hypot(r[r.length - 1].x - o.x, r[r.length - 1].y - o.y) > 1e-12) && r.push(
|
|
2826
|
+
(!r.length || Math.hypot(r[r.length - 1].x - o.x, r[r.length - 1].y - o.y) > 1e-12) && r.push(x(o)), i = x(o);
|
|
2825
2827
|
};
|
|
2826
2828
|
for (const o of e)
|
|
2827
2829
|
if (o.cmd === "M")
|
|
2828
|
-
i =
|
|
2830
|
+
i = x(o.points[0]), s = i, n(i);
|
|
2829
2831
|
else if (o.cmd === "L")
|
|
2830
2832
|
n(o.points[0]);
|
|
2831
2833
|
else if (o.cmd === "Q" && i && o.points.length >= 2) {
|
|
2832
|
-
const a = i, [c,
|
|
2833
|
-
for (let f = 1; f <=
|
|
2834
|
-
const u = f /
|
|
2835
|
-
n({ x: p * p * a.x + 2 * p * u * c.x + u * u *
|
|
2834
|
+
const a = i, [c, h] = o.points, l = Math.max(4, Math.min(t, 24));
|
|
2835
|
+
for (let f = 1; f <= l; f++) {
|
|
2836
|
+
const u = f / l, p = 1 - u;
|
|
2837
|
+
n({ x: p * p * a.x + 2 * p * u * c.x + u * u * h.x, y: p * p * a.y + 2 * p * u * c.y + u * u * h.y });
|
|
2836
2838
|
}
|
|
2837
2839
|
} else if (o.cmd === "C" && i && o.points.length >= 3) {
|
|
2838
|
-
const a = i, [c,
|
|
2840
|
+
const a = i, [c, h, l] = o.points, f = Math.max(6, Math.min(t, 32));
|
|
2839
2841
|
for (let u = 1; u <= f; u++) {
|
|
2840
2842
|
const p = u / f, g = 1 - p;
|
|
2841
2843
|
n({
|
|
2842
|
-
x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p *
|
|
2843
|
-
y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p *
|
|
2844
|
+
x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p * h.x + p ** 3 * l.x,
|
|
2845
|
+
y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p * h.y + p ** 3 * l.y
|
|
2844
2846
|
});
|
|
2845
2847
|
}
|
|
2846
2848
|
} else o.cmd === "Z" && s && n(s);
|
|
2847
2849
|
return r;
|
|
2848
2850
|
}
|
|
2849
|
-
function
|
|
2851
|
+
function ee(e) {
|
|
2850
2852
|
for (const t of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
2851
2853
|
const r = e[t];
|
|
2852
|
-
if (m(r)) return
|
|
2854
|
+
if (m(r)) return x(r);
|
|
2853
2855
|
}
|
|
2854
|
-
if (Array.isArray(e.vertices) && m(e.vertices[0])) return
|
|
2856
|
+
if (Array.isArray(e.vertices) && m(e.vertices[0])) return x(e.vertices[0]);
|
|
2855
2857
|
if (Array.isArray(e.commands) && e.commands.length) {
|
|
2856
2858
|
const t = e.commands.find((r) => r.points.length > 0);
|
|
2857
|
-
if (t) return
|
|
2859
|
+
if (t) return x(t.points[0]);
|
|
2858
2860
|
}
|
|
2859
2861
|
}
|
|
2860
|
-
function
|
|
2862
|
+
function ht(e) {
|
|
2861
2863
|
const t = N();
|
|
2862
2864
|
for (const r of e) v(t, r);
|
|
2863
2865
|
return t;
|
|
2864
2866
|
}
|
|
2865
|
-
function
|
|
2867
|
+
function xr(e) {
|
|
2866
2868
|
return { minX: e.x, minY: e.y, maxX: e.x, maxY: e.y };
|
|
2867
2869
|
}
|
|
2868
|
-
function
|
|
2870
|
+
function lt(e, t) {
|
|
2869
2871
|
return e.minX <= t.maxX && e.maxX >= t.minX && e.minY <= t.maxY && e.maxY >= t.minY;
|
|
2870
2872
|
}
|
|
2871
|
-
function
|
|
2873
|
+
function wr(e, t) {
|
|
2872
2874
|
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;
|
|
2873
2875
|
}
|
|
2874
|
-
function
|
|
2876
|
+
function Cr(e, t) {
|
|
2875
2877
|
return { ...e.stats, renderElapsedMs: t, backend: "webgl", primitiveCount: e.primitiveCount, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: e.gpuMemoryBytes, buildElapsedMs: e.buildElapsedMs };
|
|
2876
2878
|
}
|
|
2877
|
-
function
|
|
2879
|
+
function Pr(e) {
|
|
2878
2880
|
return {
|
|
2879
2881
|
total: e.total,
|
|
2880
2882
|
drawn: e.drawn,
|
|
@@ -2900,8 +2902,8 @@ function bt(e, t, r = 1) {
|
|
|
2900
2902
|
else {
|
|
2901
2903
|
const o = i.match(/^rgba?\(([^)]+)\)$/i);
|
|
2902
2904
|
if (o) {
|
|
2903
|
-
const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((
|
|
2904
|
-
|
|
2905
|
+
const a = o[1].split(/[\s,\/]+/).filter(Boolean), c = a.slice(0, 3).some((l) => l.includes("%")), h = a.map((l) => Number(l.replace("%", "")));
|
|
2906
|
+
h.length >= 3 && h.slice(0, 3).every(Number.isFinite) && (s = [X(c ? h[0] * 2.55 : h[0]), X(c ? h[1] * 2.55 : h[1]), X(c ? h[2] * 2.55 : h[2]), X((Number.isFinite(h[3]) ? h[3] : 1) * 255)]);
|
|
2905
2907
|
}
|
|
2906
2908
|
}
|
|
2907
2909
|
const n = s ?? t;
|
|
@@ -2910,7 +2912,7 @@ function bt(e, t, r = 1) {
|
|
|
2910
2912
|
function X(e) {
|
|
2911
2913
|
return Math.max(0, Math.min(255, Math.round(e)));
|
|
2912
2914
|
}
|
|
2913
|
-
class
|
|
2915
|
+
class kr {
|
|
2914
2916
|
constructor(t = {}) {
|
|
2915
2917
|
d(this, "canvas");
|
|
2916
2918
|
d(this, "renderer");
|
|
@@ -2920,7 +2922,7 @@ class Cr {
|
|
|
2920
2922
|
d(this, "lastResult");
|
|
2921
2923
|
d(this, "activeNativeLoader");
|
|
2922
2924
|
var r;
|
|
2923
|
-
if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ??
|
|
2925
|
+
if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ?? qe(t), t.loaders) for (const i of t.loaders) this.registry.register(i);
|
|
2924
2926
|
if (this.canvas = t.canvas ?? document.createElement("canvas"), this.canvas.classList.add("cad-viewer-canvas"), t.container)
|
|
2925
2927
|
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);
|
|
2926
2928
|
else if (t.nativeHost)
|
|
@@ -2930,7 +2932,7 @@ class Cr {
|
|
|
2930
2932
|
const i = document.createElement("div");
|
|
2931
2933
|
i.classList.add("cad-viewer-native-host"), t.canvas.parentElement.appendChild(i), this.nativeHost = i;
|
|
2932
2934
|
}
|
|
2933
|
-
this.renderer =
|
|
2935
|
+
this.renderer = Nr(t.renderer ?? "auto", this.canvas, t.canvasOptions), this.renderer.onStats = (i) => {
|
|
2934
2936
|
var s, n;
|
|
2935
2937
|
return (n = (s = this.options).onRenderStats) == null ? void 0 : n.call(s, i);
|
|
2936
2938
|
}, this.renderer.onViewChange = (i) => {
|
|
@@ -3027,12 +3029,12 @@ class Cr {
|
|
|
3027
3029
|
const o = this.mergeLoadOptions(r);
|
|
3028
3030
|
ft(o.signal);
|
|
3029
3031
|
const a = await this.registry.detect(t), c = { ...t, buffer: a.bytes };
|
|
3030
|
-
if (
|
|
3032
|
+
if (Ke(a.loader))
|
|
3031
3033
|
return await this.applyNativeLoadResult(a.loader, c, o, i);
|
|
3032
|
-
const
|
|
3033
|
-
return this.applyLoadResult(
|
|
3034
|
+
const h = await a.loader.load(c, o);
|
|
3035
|
+
return this.applyLoadResult(h, i);
|
|
3034
3036
|
} catch (o) {
|
|
3035
|
-
const a =
|
|
3037
|
+
const a = Sr(o);
|
|
3036
3038
|
throw (n = (s = this.options).onError) == null || n.call(s, a), a;
|
|
3037
3039
|
}
|
|
3038
3040
|
}
|
|
@@ -3054,12 +3056,12 @@ class Cr {
|
|
|
3054
3056
|
try {
|
|
3055
3057
|
const c = await t.mount(r, this.nativeHost, i);
|
|
3056
3058
|
ft(i.signal);
|
|
3057
|
-
const
|
|
3059
|
+
const h = {
|
|
3058
3060
|
...c,
|
|
3059
3061
|
fileName: s,
|
|
3060
3062
|
summary: G(c.document)
|
|
3061
3063
|
};
|
|
3062
|
-
return this.lastResult =
|
|
3064
|
+
return this.lastResult = h, this.emitNativeRenderStats(c), (a = (o = this.options).onLoad) == null || a.call(o, h), h;
|
|
3063
3065
|
} catch (c) {
|
|
3064
3066
|
throw this.deactivateNativeRenderer(), c;
|
|
3065
3067
|
}
|
|
@@ -3073,9 +3075,9 @@ class Cr {
|
|
|
3073
3075
|
(r = this.activeNativeLoader) == null || r.unmount(), this.activeNativeLoader = void 0, this.nativeHost && (this.nativeHost.classList.remove("is-active"), this.nativeHost.replaceChildren()), this.canvas.style.display = "";
|
|
3074
3076
|
}
|
|
3075
3077
|
emitNativeRenderStats(t) {
|
|
3076
|
-
var o, a, c,
|
|
3078
|
+
var o, a, c, h;
|
|
3077
3079
|
const r = t.document.metadata, i = Number(((o = r.nativeRenderStats) == null ? void 0 : o.commands) ?? t.document.entities.length ?? 0), n = String(((a = r.nativeRenderStats) == null ? void 0 : a.backend) ?? "webgl").includes("webgl") ? "webgl" : "canvas2d";
|
|
3078
|
-
(
|
|
3080
|
+
(h = (c = this.options).onRenderStats) == null || h.call(c, {
|
|
3079
3081
|
total: i,
|
|
3080
3082
|
drawn: i,
|
|
3081
3083
|
skipped: 0,
|
|
@@ -3102,45 +3104,45 @@ class Cr {
|
|
|
3102
3104
|
};
|
|
3103
3105
|
}
|
|
3104
3106
|
}
|
|
3105
|
-
function
|
|
3106
|
-
return new
|
|
3107
|
+
function Ir(e = {}) {
|
|
3108
|
+
return new kr(e);
|
|
3107
3109
|
}
|
|
3108
|
-
function
|
|
3110
|
+
function Sr(e) {
|
|
3109
3111
|
return e instanceof Error ? e : new Error(String(e));
|
|
3110
3112
|
}
|
|
3111
3113
|
function ft(e) {
|
|
3112
3114
|
if (e != null && e.aborted)
|
|
3113
3115
|
throw new DOMException("Loading cancelled.", "AbortError");
|
|
3114
3116
|
}
|
|
3115
|
-
function
|
|
3116
|
-
if (e === "canvas2d") return new
|
|
3117
|
-
if (e === "webgl") return new
|
|
3118
|
-
if (
|
|
3117
|
+
function Nr(e, t, r = {}) {
|
|
3118
|
+
if (e === "canvas2d") return new Ot(t, r);
|
|
3119
|
+
if (e === "webgl") return new zt(t, r);
|
|
3120
|
+
if (te())
|
|
3119
3121
|
try {
|
|
3120
|
-
return new
|
|
3122
|
+
return new zt(t, r);
|
|
3121
3123
|
} catch {
|
|
3122
3124
|
}
|
|
3123
|
-
return new
|
|
3125
|
+
return new Ot(t, r);
|
|
3124
3126
|
}
|
|
3125
3127
|
export {
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3128
|
+
Ot as CadCanvasRenderer,
|
|
3129
|
+
ae as CadLoaderRegistry,
|
|
3130
|
+
kr as CadViewer,
|
|
3131
|
+
zt as CadWebGLRenderer,
|
|
3132
|
+
ze as DwfLoader,
|
|
3133
|
+
me as DwgLoader,
|
|
3134
|
+
he as DwgWorkerClient,
|
|
3135
|
+
xe as DxfLoader,
|
|
3134
3136
|
E as colorFromAci,
|
|
3135
3137
|
V as colorFromTrueColor,
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3138
|
+
Ut as createCadDocument,
|
|
3139
|
+
Ir as createCadViewer,
|
|
3140
|
+
qe as createDefaultLoaderRegistry,
|
|
3139
3141
|
B as detectCadFormat,
|
|
3140
3142
|
R as inferEntityKind,
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3143
|
+
Ke as isCadNativeRenderableLoader,
|
|
3144
|
+
te as isWebGLAvailable,
|
|
3145
|
+
be as normalizeCadEntity,
|
|
3144
3146
|
U as readInputBytes,
|
|
3145
3147
|
D as resolveCadColor,
|
|
3146
3148
|
G as summarizeCadDocument,
|