@flyfish-dev/cad-viewer 0.6.0 → 0.6.2
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/NOTICE +1 -1
- package/README.md +20 -6
- package/README.zh-CN.md +24 -6
- package/dist/cad-viewer.es.js +403 -392
- package/dist/cad-viewer.es.js.map +1 -1
- package/dist/cad-viewer.umd.cjs +4 -4
- package/dist/cad-viewer.umd.cjs.map +1 -1
- package/dist/types/core/types.d.ts +11 -0
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/loaders/dwf/DwfLoader.d.ts.map +1 -1
- package/package.json +5 -4
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 Kt = Object.defineProperty;
|
|
2
|
+
var Jt = (e, t, r) => t in e ? Kt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var d = (e, t, r) => Jt(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { openDwfDocument as Qt, DwfViewer as te } from "dwf-viewer";
|
|
5
5
|
async function _(e) {
|
|
6
6
|
if (e.buffer instanceof Uint8Array) return e.buffer;
|
|
7
7
|
if (e.buffer instanceof ArrayBuffer) return new Uint8Array(e.buffer);
|
|
8
8
|
if (e.file) return new Uint8Array(await e.file.arrayBuffer());
|
|
9
9
|
throw new Error("CadLoadInput requires a File, ArrayBuffer, or Uint8Array.");
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function ee(e) {
|
|
12
12
|
return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : e.slice().buffer;
|
|
13
13
|
}
|
|
14
14
|
function L(e) {
|
|
@@ -16,7 +16,7 @@ function L(e) {
|
|
|
16
16
|
const t = e.fileName ?? ((i = e.file) == null ? void 0 : i.name) ?? "", r = t.lastIndexOf(".");
|
|
17
17
|
return r >= 0 ? t.slice(r + 1).toLowerCase() : "";
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function A(e, t) {
|
|
20
20
|
const r = L(e);
|
|
21
21
|
if (r === "dwg") return "dwg";
|
|
22
22
|
if (r === "dxf") return "dxf";
|
|
@@ -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 = vt(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 = vt(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 vt(e) {
|
|
37
37
|
return Array.from(e, (t) => t >= 32 && t <= 126 ? String.fromCharCode(t) : " ").join("");
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class re {
|
|
40
40
|
constructor(t = []) {
|
|
41
41
|
d(this, "loaders", []);
|
|
42
42
|
for (const r of t) this.register(r);
|
|
@@ -53,7 +53,7 @@ class Jt {
|
|
|
53
53
|
return [...this.loaders];
|
|
54
54
|
}
|
|
55
55
|
async detect(t) {
|
|
56
|
-
const r = await _(t), i =
|
|
56
|
+
const r = await _(t), i = A(t, r), s = this.loaders.find((o) => o.formats.includes(i) && o.accepts(t, r));
|
|
57
57
|
if (s) return { loader: s, bytes: r, format: i };
|
|
58
58
|
const n = this.loaders.find((o) => o.accepts(t, r));
|
|
59
59
|
if (n) return { loader: n, bytes: r, format: i };
|
|
@@ -64,7 +64,7 @@ class Jt {
|
|
|
64
64
|
return i.load({ ...t, buffer: s }, r);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
class
|
|
67
|
+
class ie {
|
|
68
68
|
constructor() {
|
|
69
69
|
d(this, "worker");
|
|
70
70
|
d(this, "sequence", 0);
|
|
@@ -72,11 +72,11 @@ class Qt {
|
|
|
72
72
|
}
|
|
73
73
|
load(t, r, i = {}) {
|
|
74
74
|
var h, l;
|
|
75
|
-
if (!
|
|
76
|
-
const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((h = r.file) == null ? void 0 : h.name), c =
|
|
75
|
+
if (!lt()) throw new Error("Web Worker is not available in this runtime.");
|
|
76
|
+
const s = this.ensureWorker(i), n = ++this.sequence, o = Math.max(0, Number(i.workerTimeoutMs ?? 0)), a = i.fileName ?? r.fileName ?? ((h = r.file) == null ? void 0 : h.name), c = ne(t, r, i);
|
|
77
77
|
return (l = i.onProgress) == null || l.call(i, { phase: "worker-start", format: "dwg", message: "Dispatching DWG parse to worker…", total: t.byteLength }), new Promise((f, u) => {
|
|
78
|
-
var
|
|
79
|
-
if ((
|
|
78
|
+
var g;
|
|
79
|
+
if ((g = i.signal) != null && g.aborted) {
|
|
80
80
|
u($());
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
@@ -92,7 +92,7 @@ class Qt {
|
|
|
92
92
|
requestId: n,
|
|
93
93
|
bytes: c,
|
|
94
94
|
fileName: a,
|
|
95
|
-
options:
|
|
95
|
+
options: yt(i)
|
|
96
96
|
}, [c]);
|
|
97
97
|
} catch (S) {
|
|
98
98
|
this.pending.delete(n), V(p), u(S instanceof Error ? S : new Error(String(S)));
|
|
@@ -101,7 +101,7 @@ class Qt {
|
|
|
101
101
|
}
|
|
102
102
|
preload(t = {}) {
|
|
103
103
|
var n;
|
|
104
|
-
if (!
|
|
104
|
+
if (!lt()) return Promise.reject(new Error("Web Worker is not available in this runtime."));
|
|
105
105
|
const r = this.ensureWorker(t), i = ++this.sequence, s = Math.max(0, Number(t.workerTimeoutMs ?? 0));
|
|
106
106
|
return (n = t.onProgress) == null || n.call(t, { phase: "worker-start", format: "dwg", message: "Starting DWG worker warmup…" }), new Promise((o, a) => {
|
|
107
107
|
var h;
|
|
@@ -121,7 +121,7 @@ class Qt {
|
|
|
121
121
|
this.pending.delete(i), this.resetWorker(), a($());
|
|
122
122
|
}, t.signal.addEventListener("abort", c.abortHandler, { once: !0 })), this.pending.set(i, c);
|
|
123
123
|
try {
|
|
124
|
-
r.postMessage({ type: "warmup", requestId: i, options:
|
|
124
|
+
r.postMessage({ type: "warmup", requestId: i, options: yt(t) });
|
|
125
125
|
} catch (l) {
|
|
126
126
|
this.pending.delete(i), V(c), a(l instanceof Error ? l : new Error(String(l)));
|
|
127
127
|
}
|
|
@@ -131,7 +131,7 @@ class Qt {
|
|
|
131
131
|
this.resetWorker();
|
|
132
132
|
}
|
|
133
133
|
ensureWorker(t) {
|
|
134
|
-
return this.worker || (this.worker =
|
|
134
|
+
return this.worker || (this.worker = se(t), this.worker.onmessage = (r) => this.handleMessage(r.data), this.worker.onerror = (r) => {
|
|
135
135
|
const i = r.message || "DWG worker failed.";
|
|
136
136
|
this.rejectAll(new Error(i)), this.resetWorker(!1);
|
|
137
137
|
}, this.worker.onmessageerror = () => {
|
|
@@ -168,30 +168,30 @@ class Qt {
|
|
|
168
168
|
t && this.rejectAll(new Error("DWG worker was terminated.")), (r = this.worker) == null || r.terminate(), this.worker = void 0;
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function lt() {
|
|
172
172
|
return typeof Worker < "u" && typeof URL < "u";
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function se(e) {
|
|
175
175
|
return e.workerFactory ? e.workerFactory() : e.workerUrl ? new Worker(e.workerUrl, { type: "module", name: "lightweight-cad-dwg-loader" }) : new Worker(new URL(
|
|
176
176
|
/* @vite-ignore */
|
|
177
177
|
"/assets/DwgWorker-CuZJ5EUe.js",
|
|
178
178
|
import.meta.url
|
|
179
179
|
), { type: "module", name: "lightweight-cad-dwg-loader" });
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function yt(e) {
|
|
182
182
|
return {
|
|
183
183
|
// Resolve the asset directory on the UI thread. Relative paths such as
|
|
184
184
|
// './wasm' must be relative to the document URL, not to the generated
|
|
185
185
|
// worker chunk URL. Otherwise the worker may request /assets/wasm/... and
|
|
186
186
|
// receive the app's HTML fallback instead of libredwg-web.wasm.
|
|
187
|
-
wasmPath:
|
|
187
|
+
wasmPath: oe(e.wasmPath),
|
|
188
188
|
includePaperSpace: e.includePaperSpace,
|
|
189
189
|
maxInsertDepth: e.maxInsertDepth,
|
|
190
190
|
keepRaw: !!e.keepRaw
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
return !!t.file || r.transferInputBuffer === !0 ?
|
|
193
|
+
function ne(e, t, r) {
|
|
194
|
+
return !!t.file || r.transferInputBuffer === !0 ? ee(e) : e.slice().buffer;
|
|
195
195
|
}
|
|
196
196
|
function V(e) {
|
|
197
197
|
e.timer && clearTimeout(e.timer), e.signal && e.abortHandler && e.signal.removeEventListener("abort", e.abortHandler);
|
|
@@ -201,30 +201,30 @@ function $() {
|
|
|
201
201
|
const e = new Error("DWG loading was aborted.");
|
|
202
202
|
return e.name = "AbortError", e;
|
|
203
203
|
}
|
|
204
|
-
function
|
|
204
|
+
function oe(e) {
|
|
205
205
|
const t = ((e == null ? void 0 : e.trim()) || "/wasm").replace(/\/+$/, "");
|
|
206
|
-
return t === "" ?
|
|
206
|
+
return t === "" ? xt() : ae(t) ? t : t.startsWith("/") ? `${xt()}${t}` : new URL(t, Ot()).href.replace(/\/+$/, "");
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function Ot() {
|
|
209
209
|
return typeof document < "u" && document.baseURI ? document.baseURI : typeof location < "u" && location.href ? location.href : "http://localhost/";
|
|
210
210
|
}
|
|
211
|
-
function
|
|
212
|
-
return typeof location < "u" && location.origin ? location.origin : new URL(
|
|
211
|
+
function xt() {
|
|
212
|
+
return typeof location < "u" && location.origin ? location.origin : new URL(Ot()).origin;
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function ae(e) {
|
|
215
215
|
return /^[a-z][a-z0-9+.-]*:/i.test(e);
|
|
216
216
|
}
|
|
217
|
-
class
|
|
217
|
+
class ce {
|
|
218
218
|
constructor(t = {}) {
|
|
219
219
|
d(this, "id", "dwg");
|
|
220
220
|
d(this, "label", "DWG / LibreDWG WebAssembly");
|
|
221
221
|
d(this, "formats", ["dwg"]);
|
|
222
222
|
d(this, "defaults");
|
|
223
|
-
d(this, "workerClient", new
|
|
223
|
+
d(this, "workerClient", new ie());
|
|
224
224
|
this.defaults = { useWorker: !0, ...t };
|
|
225
225
|
}
|
|
226
226
|
accepts(t, r) {
|
|
227
|
-
return L(t) === "dwg" ? !0 :
|
|
227
|
+
return L(t) === "dwg" ? !0 : A(t, r) === "dwg";
|
|
228
228
|
}
|
|
229
229
|
async load(t, r = {}) {
|
|
230
230
|
var o, a;
|
|
@@ -233,12 +233,12 @@ class se {
|
|
|
233
233
|
const s = await _(t), n = t.fileName ?? ((a = t.file) == null ? void 0 : a.name);
|
|
234
234
|
if (i.useWorker === !1)
|
|
235
235
|
throw new Error("DWG main-thread parsing is intentionally not bundled by the default viewer. Keep useWorker enabled, or register a custom DWG loader for non-browser runtimes.");
|
|
236
|
-
if (!
|
|
236
|
+
if (!lt())
|
|
237
237
|
throw new Error("DWG loading requires Web Worker support in this build. Provide a custom loader for this runtime.");
|
|
238
238
|
try {
|
|
239
239
|
return await this.workerClient.load(s, t, { ...i, fileName: n });
|
|
240
240
|
} catch (c) {
|
|
241
|
-
throw
|
|
241
|
+
throw he(c) ? c : le(c);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
terminateWorker() {
|
|
@@ -249,14 +249,14 @@ class se {
|
|
|
249
249
|
return r.useWorker === !1 ? Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")) : this.workerClient.preload(r);
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
function
|
|
252
|
+
function he(e) {
|
|
253
253
|
return e instanceof Error && e.name === "AbortError";
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function le(e) {
|
|
256
256
|
const t = e instanceof Error ? e.message : String(e);
|
|
257
257
|
return new Error(`${t} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`);
|
|
258
258
|
}
|
|
259
|
-
function
|
|
259
|
+
function zt(e) {
|
|
260
260
|
return {
|
|
261
261
|
format: e.format,
|
|
262
262
|
sourceName: e.sourceName,
|
|
@@ -322,31 +322,31 @@ function R(e) {
|
|
|
322
322
|
return "unsupported";
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function fe(e, t, r = {}) {
|
|
326
326
|
const i = t ?? String(e.type ?? e.entityType ?? e.objectName ?? "UNKNOWN").toUpperCase(), s = r.includeUnknownProperties === !1 ? { type: i, kind: R(i) } : { ...e, type: i, kind: R(i) };
|
|
327
327
|
r.keepRaw && (s.raw = e), s.handle = C(e.handle ?? e.id), s.layer = C(e.layer ?? e.layerName), s.lineType = C(e.lineType ?? e.linetype);
|
|
328
328
|
const n = r.numericColorMode ?? "auto", o = y(e.color), a = y(e.colorIndex ?? e.colorNumber ?? e.aci ?? e.aciColor ?? e.color_index);
|
|
329
329
|
s.colorIndex = a ?? (n !== "rgb" && o !== void 0 && Math.abs(o) <= 257 ? o : void 0);
|
|
330
330
|
const c = e.trueColor ?? e.true_color ?? e.truecolor ?? e.colorRGB ?? e.colorRgb ?? e.rgbColor ?? e.rgb, h = o !== void 0 && o >= 0 && o <= 16777215 && (n === "rgb" || n === "auto" && Math.abs(o) > 257);
|
|
331
|
-
s.trueColor = c ?? (h ? o : void 0), (typeof e.color == "string" || typeof e.color == "number") && (s.color = e.color), s.colorNumber = y(e.colorNumber) ?? s.colorNumber, s.colorName = C(e.colorName ?? e.color_name) ?? s.colorName, s.fillColor = e.fillColor ?? e.fill_color, s.fillColorIndex = y(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? s.fillColorIndex, s.opacity = y(e.opacity ?? e.alpha) ?? s.opacity, s.lineweight = y(e.lineweight ?? e.lineWeight), s.isVisible = !(e.isVisible === !1 || e.visible === !1), s.startPoint =
|
|
332
|
-
const l =
|
|
331
|
+
s.trueColor = c ?? (h ? o : void 0), (typeof e.color == "string" || typeof e.color == "number") && (s.color = e.color), s.colorNumber = y(e.colorNumber) ?? s.colorNumber, s.colorName = C(e.colorName ?? e.color_name) ?? s.colorName, s.fillColor = e.fillColor ?? e.fill_color, s.fillColorIndex = y(e.fillColorIndex ?? e.fill_color_index ?? e.fillColorNumber) ?? s.fillColorIndex, s.opacity = y(e.opacity ?? e.alpha) ?? s.opacity, s.lineweight = y(e.lineweight ?? e.lineWeight), s.isVisible = !(e.isVisible === !1 || e.visible === !1), s.startPoint = P(e.startPoint ?? e.start ?? e.p0 ?? e.from) ?? s.startPoint, s.endPoint = P(e.endPoint ?? e.end ?? e.p1 ?? e.to) ?? s.endPoint, s.center = P(e.center ?? e.centerPoint) ?? s.center, s.insertionPoint = P(e.insertionPoint ?? e.position ?? e.location ?? e.point ?? e.basePoint) ?? s.insertionPoint, s.radius = y(e.radius) ?? s.radius, s.startAngle = y(e.startAngle ?? e.start_angle) ?? s.startAngle, s.endAngle = y(e.endAngle ?? e.end_angle) ?? s.endAngle, s.majorAxisEndPoint = P(e.majorAxisEndPoint ?? e.majorAxis ?? e.major) ?? s.majorAxisEndPoint, s.axisRatio = y(e.axisRatio ?? e.ratio) ?? s.axisRatio, s.height = y(e.height ?? e.textHeight) ?? s.height, s.textHeight = y(e.textHeight ?? e.height) ?? s.textHeight, s.rotation = y(e.rotation ?? e.angle) ?? s.rotation, s.text = C(e.text ?? e.value ?? e.string ?? e.contents) ?? s.text, s.name = C(e.name ?? e.blockName) ?? s.name, s.blockName = C(e.blockName ?? e.name) ?? s.blockName;
|
|
332
|
+
const l = et(e.vertices ?? e.points);
|
|
333
333
|
l.length > 0 && (s.vertices = l);
|
|
334
|
-
const f =
|
|
334
|
+
const f = et(e.controlPoints ?? e.control_points);
|
|
335
335
|
f.length > 0 && (s.controlPoints = f);
|
|
336
|
-
const u =
|
|
336
|
+
const u = et(e.fitPoints ?? e.fit_points);
|
|
337
337
|
return u.length > 0 && (s.fitPoints = u), s;
|
|
338
338
|
}
|
|
339
|
-
function
|
|
339
|
+
function P(e) {
|
|
340
340
|
if (!e || typeof e != "object") return;
|
|
341
341
|
const t = e, r = Number(t.x ?? t.X ?? t[0]), i = Number(t.y ?? t.Y ?? t[1]), s = t.z ?? t.Z ?? t[2], n = s === void 0 ? void 0 : Number(s);
|
|
342
342
|
if (!(!Number.isFinite(r) || !Number.isFinite(i)))
|
|
343
343
|
return Number.isFinite(n) ? { x: r, y: i, z: n } : { x: r, y: i };
|
|
344
344
|
}
|
|
345
|
-
function
|
|
345
|
+
function et(e) {
|
|
346
346
|
if (!Array.isArray(e)) return [];
|
|
347
347
|
const t = [];
|
|
348
348
|
for (const r of e) {
|
|
349
|
-
const i =
|
|
349
|
+
const i = P(r);
|
|
350
350
|
if (!i) continue;
|
|
351
351
|
const s = r, n = i, o = y(s.bulge);
|
|
352
352
|
o !== void 0 && (n.bulge = o);
|
|
@@ -375,13 +375,13 @@ function j(e) {
|
|
|
375
375
|
warnings: [...e.warnings]
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function wt(e, t) {
|
|
379
379
|
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
380
380
|
}
|
|
381
|
-
function
|
|
381
|
+
function de(e, t) {
|
|
382
382
|
t.name && (e[t.name] = t, e[t.name.toLowerCase()] = t);
|
|
383
383
|
}
|
|
384
|
-
function
|
|
384
|
+
function ue(e) {
|
|
385
385
|
return e != null && e.length ? e.flatMap((t) => t.entities.map((r) => ({ ...r, pageIndex: t.index }))) : [];
|
|
386
386
|
}
|
|
387
387
|
function y(e) {
|
|
@@ -399,15 +399,15 @@ function M() {
|
|
|
399
399
|
function D(e) {
|
|
400
400
|
return Number.isFinite(e.minX) && Number.isFinite(e.minY) && Number.isFinite(e.maxX) && Number.isFinite(e.maxY) && e.maxX >= e.minX && e.maxY >= e.minY;
|
|
401
401
|
}
|
|
402
|
-
function
|
|
402
|
+
function v(e, t) {
|
|
403
403
|
m(t) && (e.minX = Math.min(e.minX, t.x), e.minY = Math.min(e.minY, t.y), e.maxX = Math.max(e.maxX, t.x), e.maxY = Math.max(e.maxY, t.y));
|
|
404
404
|
}
|
|
405
|
-
function
|
|
405
|
+
function Yt(e, t, r) {
|
|
406
406
|
if (!m(t) || !Number.isFinite(r)) return;
|
|
407
407
|
const i = Math.abs(r);
|
|
408
|
-
|
|
408
|
+
v(e, { x: t.x - i, y: t.y - i }), v(e, { x: t.x + i, y: t.y + i });
|
|
409
409
|
}
|
|
410
|
-
function
|
|
410
|
+
function Ht(e, t = 0.02, r = 1e-6) {
|
|
411
411
|
if (!D(e)) return { minX: -10, minY: -10, maxX: 10, maxY: 10 };
|
|
412
412
|
const i = Math.max((e.maxX - e.minX) * t, r), s = Math.max((e.maxY - e.minY) * t, r);
|
|
413
413
|
return { minX: e.minX - i, minY: e.minY - s, maxX: e.maxX + i, maxY: e.maxY + s };
|
|
@@ -421,7 +421,7 @@ function x(e) {
|
|
|
421
421
|
function E(e) {
|
|
422
422
|
return e * Math.PI / 180;
|
|
423
423
|
}
|
|
424
|
-
function
|
|
424
|
+
function q(e, t, r, i, s = !0, n = 64) {
|
|
425
425
|
if (!m(e) || !Number.isFinite(t)) return [];
|
|
426
426
|
let o = r, a = i;
|
|
427
427
|
if (!Number.isFinite(o) || !Number.isFinite(a)) return [];
|
|
@@ -433,35 +433,35 @@ function Z(e, t, r, i, s = !0, n = 64) {
|
|
|
433
433
|
}
|
|
434
434
|
return l;
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function K(e, t, r = 1, i = 0, s = Math.PI * 2, n = 96) {
|
|
437
437
|
if (!m(e) || !m(t)) return [];
|
|
438
438
|
const o = Math.hypot(t.x, t.y);
|
|
439
439
|
if (!Number.isFinite(o) || o <= 0) return [];
|
|
440
440
|
const a = o * (Number.isFinite(r) && r > 0 ? r : 1), c = Math.atan2(t.y, t.x);
|
|
441
441
|
let h = Number.isFinite(i) ? i : 0, l = Number.isFinite(s) ? s : Math.PI * 2;
|
|
442
442
|
(Math.abs(h) > Math.PI * 2 + 1e-6 || Math.abs(l) > Math.PI * 2 + 1e-6) && (h = E(h), l = E(l)), l < h && (l += Math.PI * 2);
|
|
443
|
-
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(l - h) / (Math.PI * 2) * n))), u = [], p = Math.cos(c),
|
|
443
|
+
const f = Math.max(12, Math.min(256, Math.ceil(Math.abs(l - h) / (Math.PI * 2) * n))), u = [], p = Math.cos(c), g = Math.sin(c);
|
|
444
444
|
for (let S = 0; S <= f; S++) {
|
|
445
445
|
const O = h + (l - h) * (S / f), z = Math.cos(O) * o, Y = Math.sin(O) * a;
|
|
446
|
-
u.push({ x: e.x + z * p - Y *
|
|
446
|
+
u.push({ x: e.x + z * p - Y * g, y: e.y + z * g + Y * p });
|
|
447
447
|
}
|
|
448
448
|
return u;
|
|
449
449
|
}
|
|
450
|
-
function
|
|
450
|
+
function Xt(e, t, r = 0, i = 16) {
|
|
451
451
|
if (!Number.isFinite(r) || Math.abs(r) < 1e-12) return [x(e), x(t)];
|
|
452
452
|
const s = Math.hypot(t.x - e.x, t.y - e.y);
|
|
453
453
|
if (s <= 1e-12) return [x(e), x(t)];
|
|
454
|
-
const n = 4 * Math.atan(r), o = Math.abs(s / (2 * Math.sin(n / 2))), a = { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 }, c = (t.x - e.x) / s, h = (t.y - e.y) / s, l = r >= 0 ? 1 : -1, f = Math.sqrt(Math.max(o * o - (s / 2) ** 2, 0)), u = { x: a.x - l * h * f, y: a.y + l * c * f }, p = Math.atan2(e.y - u.y, e.x - u.x),
|
|
455
|
-
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, h = (t.y - e.y) / s, l = r >= 0 ? 1 : -1, f = Math.sqrt(Math.max(o * o - (s / 2) ** 2, 0)), u = { x: a.x - l * h * f, y: a.y + l * c * f }, p = Math.atan2(e.y - u.y, e.x - u.x), g = Math.atan2(t.y - u.y, t.x - u.x);
|
|
455
|
+
return q(u, o, p, g, r >= 0, i);
|
|
456
456
|
}
|
|
457
|
-
function
|
|
457
|
+
function _t(e) {
|
|
458
458
|
return e.replace(/\\P/g, `
|
|
459
459
|
`).replace(/\\~|\\ /g, " ").replace(/\\[A-Za-z][^;]*;/g, "").replace(/[{}]/g, "").replace(/\\[A-Za-z]/g, "").trim();
|
|
460
460
|
}
|
|
461
461
|
function T(e, t, r) {
|
|
462
462
|
return Math.min(r, Math.max(t, e));
|
|
463
463
|
}
|
|
464
|
-
class
|
|
464
|
+
class me {
|
|
465
465
|
constructor(t = {}) {
|
|
466
466
|
d(this, "id", "dxf");
|
|
467
467
|
d(this, "label", "DXF / JavaScript parser");
|
|
@@ -470,29 +470,29 @@ class le {
|
|
|
470
470
|
this.defaults = t;
|
|
471
471
|
}
|
|
472
472
|
accepts(t, r) {
|
|
473
|
-
return L(t) === "dxf" ||
|
|
473
|
+
return L(t) === "dxf" || A(t, r) === "dxf";
|
|
474
474
|
}
|
|
475
475
|
async load(t, r = {}) {
|
|
476
476
|
var l;
|
|
477
477
|
({ ...this.defaults, ...r });
|
|
478
|
-
const i = performance.now(), s = await _(t), n =
|
|
478
|
+
const i = performance.now(), s = await _(t), n = Ce(s), o = [];
|
|
479
479
|
let a;
|
|
480
480
|
try {
|
|
481
|
-
a = await
|
|
481
|
+
a = await pe(n);
|
|
482
482
|
} catch (f) {
|
|
483
|
-
o.push(`dxf-parser failed, using built-in fallback parser: ${f instanceof Error ? f.message : String(f)}`), a =
|
|
483
|
+
o.push(`dxf-parser failed, using built-in fallback parser: ${f instanceof Error ? f.message : String(f)}`), a = Pe(n);
|
|
484
484
|
}
|
|
485
|
-
const c =
|
|
485
|
+
const c = ge(a, t.fileName ?? ((l = t.file) == null ? void 0 : l.name), o), h = performance.now() - i;
|
|
486
486
|
return { document: c, raw: a, bytes: s.byteLength, elapsedMs: h, format: "dxf", warnings: c.warnings };
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
-
async function
|
|
489
|
+
async function pe(e) {
|
|
490
490
|
const t = await import("dxf-parser"), r = t.default ?? t.DxfParser;
|
|
491
491
|
if (!r) throw new Error("dxf-parser did not expose a parser constructor.");
|
|
492
492
|
return new r().parseSync(e);
|
|
493
493
|
}
|
|
494
|
-
function
|
|
495
|
-
const i = e && typeof e == "object" ? e : {}, s =
|
|
494
|
+
function ge(e, t, r = []) {
|
|
495
|
+
const i = e && typeof e == "object" ? e : {}, s = be(i), n = ve(i), a = (Array.isArray(i.entities) ? i.entities : []).filter((h) => !!h && typeof h == "object").map((h) => pt(h)), c = zt({
|
|
496
496
|
format: "dxf",
|
|
497
497
|
sourceName: t,
|
|
498
498
|
header: i.header && typeof i.header == "object" ? i.header : {},
|
|
@@ -505,26 +505,26 @@ function de(e, t, r = []) {
|
|
|
505
505
|
});
|
|
506
506
|
return a.length === 0 && c.warnings.push("DXF file did not expose any ENTITIES."), c;
|
|
507
507
|
}
|
|
508
|
-
function
|
|
509
|
-
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r =
|
|
510
|
-
if (r.colorIndex = i ?? (s !== void 0 && Math.abs(s) <= 257 ? s : void 0), r.trueColor = e.trueColor ?? e.true_color ?? e.colorRGB ?? e.trueColorValue ?? (s !== void 0 && Math.abs(s) > 257 ? s : void 0), r.layer = C(e.layer ?? e.layerName) ?? "0", r.isClosed = !!(e.shape ?? e.closed ?? e.isClosed) || (Number(e.flag ?? e.flags ?? 0) & 1) === 1, t === "LINE" && (r.startPoint =
|
|
511
|
-
r.blockName = C(e.name ?? e.blockName) ?? r.blockName, r.insertionPoint =
|
|
508
|
+
function pt(e) {
|
|
509
|
+
const t = String(e.type ?? e.entityType ?? "UNKNOWN").toUpperCase(), r = fe(e, t), i = y(e.colorIndex ?? e.colorNumber ?? e.aci), s = y(e.color);
|
|
510
|
+
if (r.colorIndex = i ?? (s !== void 0 && Math.abs(s) <= 257 ? s : void 0), r.trueColor = e.trueColor ?? e.true_color ?? e.colorRGB ?? e.trueColorValue ?? (s !== void 0 && Math.abs(s) > 257 ? s : void 0), r.layer = C(e.layer ?? e.layerName) ?? "0", r.isClosed = !!(e.shape ?? e.closed ?? e.isClosed) || (Number(e.flag ?? e.flags ?? 0) & 1) === 1, t === "LINE" && (r.startPoint = P(e.startPoint ?? { x: e.x1 ?? e.x, y: e.y1 ?? e.y, z: e.z1 ?? e.z }) ?? r.startPoint, r.endPoint = P(e.endPoint ?? { x: e.x2, y: e.y2, z: e.z2 }) ?? r.endPoint), (t === "TEXT" || t === "MTEXT" || t === "ATTRIB" || t === "ATTDEF") && (r.insertionPoint = P(e.startPoint ?? e.position ?? e.insertionPoint) ?? r.insertionPoint, r.text = C(e.text ?? e.string ?? e.value) ?? r.text, r.textHeight = y(e.textHeight ?? e.height) ?? r.textHeight, r.rotation = Pt(e.rotation ?? e.angle)), (t === "ARC" || t === "ELLIPSE") && (r.startAngle = kt(e.startAngle ?? e.start_angle), r.endAngle = kt(e.endAngle ?? e.end_angle)), t === "INSERT") {
|
|
511
|
+
r.blockName = C(e.name ?? e.blockName) ?? r.blockName, r.insertionPoint = P(e.position ?? e.insertionPoint ?? e.point) ?? r.insertionPoint;
|
|
512
512
|
const n = y(e.xScale ?? e.scaleX ?? e.xscale), o = y(e.yScale ?? e.scaleY ?? e.yscale), a = y(e.zScale ?? e.scaleZ ?? e.zscale);
|
|
513
|
-
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation =
|
|
513
|
+
(n !== void 0 || o !== void 0 || a !== void 0) && (r.scale = { x: n ?? 1, y: o ?? n ?? 1, z: a ?? 1 }), r.rotation = Pt(e.rotation ?? e.angle);
|
|
514
514
|
}
|
|
515
515
|
if (t === "SPLINE") {
|
|
516
|
-
const n =
|
|
516
|
+
const n = J(e.controlPoints ?? e.control_points ?? e.points);
|
|
517
517
|
n.length && (r.controlPoints = n);
|
|
518
|
-
const o =
|
|
518
|
+
const o = J(e.fitPoints ?? e.fit_points);
|
|
519
519
|
o.length && (r.fitPoints = o);
|
|
520
520
|
}
|
|
521
|
-
return t === "HATCH" && (r.loops =
|
|
521
|
+
return t === "HATCH" && (r.loops = we(e), r.fillColorIndex = r.colorIndex), (t === "SOLID" || t === "TRACE" || t === "3DFACE") && (r.vertices = xe(e), r.fillColorIndex = r.colorIndex), r;
|
|
522
522
|
}
|
|
523
|
-
function
|
|
524
|
-
const t = {}, r = e.tables, i = e.layers ?? (r == null ? void 0 : r.layer) ?? (r == null ? void 0 : r.LAYER) ?? (r == null ? void 0 : r.layers), s =
|
|
523
|
+
function be(e) {
|
|
524
|
+
const t = {}, r = e.tables, i = e.layers ?? (r == null ? void 0 : r.layer) ?? (r == null ? void 0 : r.LAYER) ?? (r == null ? void 0 : r.layers), s = ye(i);
|
|
525
525
|
for (const n of s) {
|
|
526
526
|
const o = n, a = C(o.name ?? o.layerName);
|
|
527
|
-
a &&
|
|
527
|
+
a && wt(t, {
|
|
528
528
|
name: a,
|
|
529
529
|
color: o.color ?? o.colorNumber ?? o.colorIndex,
|
|
530
530
|
colorIndex: y(o.colorNumber ?? o.colorIndex ?? o.color),
|
|
@@ -535,67 +535,67 @@ function ue(e) {
|
|
|
535
535
|
raw: o
|
|
536
536
|
});
|
|
537
537
|
}
|
|
538
|
-
return t[0] ||
|
|
538
|
+
return t[0] || wt(t, { name: "0", colorIndex: 7, isVisible: !0 }), t;
|
|
539
539
|
}
|
|
540
|
-
function
|
|
540
|
+
function ve(e) {
|
|
541
541
|
const t = {}, r = e.blocks;
|
|
542
542
|
if (!r || typeof r != "object") return t;
|
|
543
543
|
if (Array.isArray(r))
|
|
544
|
-
for (const i of r)
|
|
544
|
+
for (const i of r) Ct(t, i);
|
|
545
545
|
else
|
|
546
|
-
for (const [i, s] of Object.entries(r))
|
|
546
|
+
for (const [i, s] of Object.entries(r)) Ct(t, s, i);
|
|
547
547
|
return t;
|
|
548
548
|
}
|
|
549
|
-
function
|
|
549
|
+
function Ct(e, t, r) {
|
|
550
550
|
if (!t || typeof t != "object") return;
|
|
551
551
|
const i = t, s = C(i.name ?? i.blockName ?? r);
|
|
552
552
|
if (!s) return;
|
|
553
|
-
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) =>
|
|
554
|
-
|
|
553
|
+
const o = (Array.isArray(i.entities) ? i.entities : []).filter((a) => !!a && typeof a == "object").map((a) => pt(a));
|
|
554
|
+
de(e, { name: s, basePoint: P(i.basePoint ?? i.position) ?? { x: 0, y: 0 }, entities: o, raw: i });
|
|
555
555
|
}
|
|
556
|
-
function
|
|
556
|
+
function ye(e) {
|
|
557
557
|
if (!e) return [];
|
|
558
558
|
if (Array.isArray(e)) return e;
|
|
559
559
|
if (typeof e != "object") return [];
|
|
560
560
|
const t = e;
|
|
561
561
|
return Array.isArray(t.entries) ? t.entries : Array.isArray(t.records) ? t.records : Array.isArray(t.layers) ? t.layers : Object.values(t).filter((r) => r && typeof r == "object");
|
|
562
562
|
}
|
|
563
|
-
function
|
|
564
|
-
return Array.isArray(e) ? e.map(
|
|
563
|
+
function J(e) {
|
|
564
|
+
return Array.isArray(e) ? e.map(P).filter((t) => !!t) : [];
|
|
565
565
|
}
|
|
566
|
-
function
|
|
567
|
-
const t =
|
|
566
|
+
function xe(e) {
|
|
567
|
+
const t = J(e.vertices ?? e.points);
|
|
568
568
|
if (t.length) return t;
|
|
569
569
|
const r = [];
|
|
570
570
|
for (let i = 0; i < 4; i++) {
|
|
571
|
-
const s =
|
|
571
|
+
const s = P({ x: e[`x${i}`] ?? e[`x${i + 1}`], y: e[`y${i}`] ?? e[`y${i + 1}`], z: e[`z${i}`] ?? e[`z${i + 1}`] });
|
|
572
572
|
s && r.push(s);
|
|
573
573
|
}
|
|
574
574
|
return r;
|
|
575
575
|
}
|
|
576
|
-
function
|
|
576
|
+
function we(e) {
|
|
577
577
|
const t = e.boundaryLoops ?? e.loops ?? e.paths;
|
|
578
578
|
if (Array.isArray(t))
|
|
579
579
|
return t.map((r) => {
|
|
580
580
|
const i = r;
|
|
581
|
-
return { vertices:
|
|
581
|
+
return { vertices: J(i.vertices ?? i.points), isClosed: !0 };
|
|
582
582
|
}).filter((r) => r.vertices && r.vertices.length > 0);
|
|
583
583
|
}
|
|
584
|
-
function
|
|
584
|
+
function Pt(e) {
|
|
585
585
|
const t = y(e);
|
|
586
586
|
if (t !== void 0)
|
|
587
587
|
return Math.abs(t) > Math.PI * 2 + 1e-6 ? E(t) : t;
|
|
588
588
|
}
|
|
589
|
-
function
|
|
589
|
+
function kt(e) {
|
|
590
590
|
const t = y(e);
|
|
591
591
|
if (t !== void 0)
|
|
592
592
|
return Math.abs(t) > Math.PI * 2 + 1e-6 ? E(t) : t;
|
|
593
593
|
}
|
|
594
|
-
function
|
|
594
|
+
function Ce(e) {
|
|
595
595
|
const t = new TextDecoder("utf-8", { fatal: !1 }).decode(e);
|
|
596
596
|
return t.includes("SECTION") ? t : new TextDecoder("iso-8859-1", { fatal: !1 }).decode(e);
|
|
597
597
|
}
|
|
598
|
-
function
|
|
598
|
+
function Pe(e) {
|
|
599
599
|
var h, l;
|
|
600
600
|
const t = e.replace(/\r\n/g, `
|
|
601
601
|
`).replace(/\r/g, `
|
|
@@ -625,8 +625,8 @@ function ye(e) {
|
|
|
625
625
|
if (!o.length) return;
|
|
626
626
|
const f = (p = o[0]) == null ? void 0 : p.value.toUpperCase();
|
|
627
627
|
if (f === "VERTEX" && a) {
|
|
628
|
-
const
|
|
629
|
-
|
|
628
|
+
const g = w(o, 10, 20, 30);
|
|
629
|
+
g && (a.vertices ?? (a.vertices = [])).push({ ...g, bulge: b(o, 42) }), o = [];
|
|
630
630
|
return;
|
|
631
631
|
}
|
|
632
632
|
if (f === "SEQEND") {
|
|
@@ -637,51 +637,51 @@ function ye(e) {
|
|
|
637
637
|
o = [];
|
|
638
638
|
return;
|
|
639
639
|
}
|
|
640
|
-
const u =
|
|
640
|
+
const u = ke(f, o);
|
|
641
641
|
f === "POLYLINE" ? a = u : i.push(u), o = [];
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
|
-
function
|
|
644
|
+
function ke(e, t) {
|
|
645
645
|
const r = {
|
|
646
646
|
type: e,
|
|
647
647
|
handle: H(t, 5),
|
|
648
648
|
layer: H(t, 8) ?? "0",
|
|
649
|
-
colorIndex:
|
|
650
|
-
trueColor:
|
|
649
|
+
colorIndex: b(t, 62),
|
|
650
|
+
trueColor: b(t, 420),
|
|
651
651
|
lineType: H(t, 6),
|
|
652
|
-
lineweight:
|
|
652
|
+
lineweight: b(t, 370)
|
|
653
653
|
};
|
|
654
654
|
switch (e) {
|
|
655
655
|
case "LINE":
|
|
656
656
|
Object.assign(r, { startPoint: w(t, 10, 20, 30), endPoint: w(t, 11, 21, 31) });
|
|
657
657
|
break;
|
|
658
658
|
case "CIRCLE":
|
|
659
|
-
Object.assign(r, { center: w(t, 10, 20, 30), radius:
|
|
659
|
+
Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40) });
|
|
660
660
|
break;
|
|
661
661
|
case "ARC":
|
|
662
|
-
Object.assign(r, { center: w(t, 10, 20, 30), radius:
|
|
662
|
+
Object.assign(r, { center: w(t, 10, 20, 30), radius: b(t, 40), startAngle: G(b(t, 50)), endAngle: G(b(t, 51)) });
|
|
663
663
|
break;
|
|
664
664
|
case "POINT":
|
|
665
665
|
Object.assign(r, { point: w(t, 10, 20, 30) });
|
|
666
666
|
break;
|
|
667
667
|
case "TEXT":
|
|
668
668
|
case "MTEXT":
|
|
669
|
-
Object.assign(r, { insertionPoint: w(t, 10, 20, 30), text:
|
|
669
|
+
Object.assign(r, { insertionPoint: w(t, 10, 20, 30), text: Ne(t), textHeight: b(t, 40), rotation: G(b(t, 50)) });
|
|
670
670
|
break;
|
|
671
671
|
case "LWPOLYLINE":
|
|
672
|
-
Object.assign(r, { vertices:
|
|
672
|
+
Object.assign(r, { vertices: Me(t), flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
673
673
|
break;
|
|
674
674
|
case "POLYLINE":
|
|
675
|
-
Object.assign(r, { vertices: [], flag:
|
|
675
|
+
Object.assign(r, { vertices: [], flag: b(t, 70), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
676
676
|
break;
|
|
677
677
|
case "ELLIPSE":
|
|
678
|
-
Object.assign(r, { center: w(t, 10, 20, 30), majorAxisEndPoint: w(t, 11, 21, 31), axisRatio:
|
|
678
|
+
Object.assign(r, { center: w(t, 10, 20, 30), majorAxisEndPoint: w(t, 11, 21, 31), axisRatio: b(t, 40), startAngle: b(t, 41), endAngle: b(t, 42) });
|
|
679
679
|
break;
|
|
680
680
|
case "SPLINE":
|
|
681
|
-
Object.assign(r, { controlPoints:
|
|
681
|
+
Object.assign(r, { controlPoints: Se(t, 10, 20, 30), degree: b(t, 71), isClosed: (Number(b(t, 70) ?? 0) & 1) === 1 });
|
|
682
682
|
break;
|
|
683
683
|
case "INSERT":
|
|
684
|
-
Object.assign(r, { name: H(t, 2), blockName: H(t, 2), insertionPoint: w(t, 10, 20, 30), rotation: G(
|
|
684
|
+
Object.assign(r, { name: H(t, 2), blockName: H(t, 2), insertionPoint: w(t, 10, 20, 30), rotation: G(b(t, 50)), scale: { x: b(t, 41) ?? 1, y: b(t, 42) ?? b(t, 41) ?? 1, z: b(t, 43) ?? 1 } });
|
|
685
685
|
break;
|
|
686
686
|
case "SOLID":
|
|
687
687
|
case "TRACE":
|
|
@@ -689,9 +689,9 @@ function xe(e, t) {
|
|
|
689
689
|
Object.assign(r, { vertices: [w(t, 10, 20, 30), w(t, 11, 21, 31), w(t, 12, 22, 32), w(t, 13, 23, 33)].filter(Boolean) });
|
|
690
690
|
break;
|
|
691
691
|
}
|
|
692
|
-
return
|
|
692
|
+
return pt(r);
|
|
693
693
|
}
|
|
694
|
-
function
|
|
694
|
+
function b(e, t) {
|
|
695
695
|
var s;
|
|
696
696
|
const r = (s = e.find((n) => n.code === t)) == null ? void 0 : s.value, i = Number(r);
|
|
697
697
|
return Number.isFinite(i) ? i : void 0;
|
|
@@ -702,11 +702,11 @@ function H(e, t) {
|
|
|
702
702
|
return r && r.length > 0 ? r : void 0;
|
|
703
703
|
}
|
|
704
704
|
function w(e, t, r, i) {
|
|
705
|
-
const s =
|
|
705
|
+
const s = b(e, t), n = b(e, r), o = b(e, i);
|
|
706
706
|
if (!(s === void 0 || n === void 0))
|
|
707
707
|
return o === void 0 ? { x: s, y: n } : { x: s, y: n, z: o };
|
|
708
708
|
}
|
|
709
|
-
function
|
|
709
|
+
function Se(e, t, r, i) {
|
|
710
710
|
const s = [];
|
|
711
711
|
for (let n = 0; n < e.length; n++) {
|
|
712
712
|
if (e[n].code !== t) continue;
|
|
@@ -715,7 +715,7 @@ function we(e, t, r, i) {
|
|
|
715
715
|
}
|
|
716
716
|
return s;
|
|
717
717
|
}
|
|
718
|
-
function
|
|
718
|
+
function Me(e) {
|
|
719
719
|
const t = [];
|
|
720
720
|
for (let r = 0; r < e.length; r++) {
|
|
721
721
|
if (e[r].code !== 10) continue;
|
|
@@ -727,14 +727,14 @@ function Ce(e) {
|
|
|
727
727
|
}
|
|
728
728
|
return t;
|
|
729
729
|
}
|
|
730
|
-
function
|
|
730
|
+
function Ne(e) {
|
|
731
731
|
const t = e.filter((r) => r.code === 1 || r.code === 3).map((r) => r.value);
|
|
732
732
|
return t.length ? t.join("") : void 0;
|
|
733
733
|
}
|
|
734
734
|
function G(e) {
|
|
735
735
|
return typeof e == "number" && Number.isFinite(e) ? E(e) : void 0;
|
|
736
736
|
}
|
|
737
|
-
class
|
|
737
|
+
class Ee {
|
|
738
738
|
constructor(t = {}) {
|
|
739
739
|
d(this, "id", "dwf");
|
|
740
740
|
d(this, "label", "DWF/DWFx native viewer powered by dwf-viewer");
|
|
@@ -749,43 +749,29 @@ class Pe {
|
|
|
749
749
|
accepts(t, r) {
|
|
750
750
|
const i = L(t);
|
|
751
751
|
if (i === "dwf" || i === "dwfx" || i === "xps") return !0;
|
|
752
|
-
const s =
|
|
752
|
+
const s = A(t, r);
|
|
753
753
|
return s === "dwf" || s === "dwfx" || s === "xps";
|
|
754
754
|
}
|
|
755
755
|
async load(t, r = {}) {
|
|
756
|
-
var f, u, p,
|
|
757
|
-
const i = { ...this.defaults, ...r }, s = performance.now(), n = t.fileName ?? ((f = t.file) == null ? void 0 : f.name), o = await _(t), a =
|
|
756
|
+
var f, u, p, g;
|
|
757
|
+
const i = { ...this.defaults, ...r }, s = performance.now(), n = t.fileName ?? ((f = t.file) == null ? void 0 : f.name), o = await _(t), a = Nt(A(t, o), L(t));
|
|
758
758
|
(u = i.onProgress) == null || u.call(i, { phase: "parse", format: a, message: "Opening DWF/DWFx with dwf-viewer…", percent: 48 });
|
|
759
|
-
const c = await
|
|
759
|
+
const c = await Qt(o, { fileName: n });
|
|
760
760
|
(p = i.onProgress) == null || p.call(i, { phase: "normalize", format: a, message: "Reading DWF pages, sheets and model metadata…", percent: 76 });
|
|
761
|
-
const h =
|
|
762
|
-
return (
|
|
761
|
+
const h = St(c, n, a, i.keepRaw === !0), l = performance.now() - s;
|
|
762
|
+
return (g = i.onProgress) == null || g.call(i, { phase: "done", format: h.format, message: "DWF/DWFx document ready.", percent: 100, elapsedMs: l }), { document: h, raw: i.keepRaw ? c : void 0, bytes: o.byteLength, elapsedMs: l, format: h.format, warnings: h.warnings };
|
|
763
763
|
}
|
|
764
764
|
async mount(t, r, i = {}) {
|
|
765
|
-
var
|
|
766
|
-
const s = { ...this.defaults, ...i }, n = performance.now(), o = t.fileName ?? ((
|
|
767
|
-
(
|
|
768
|
-
wasmUrl: h,
|
|
769
|
-
preferWebgl: s.dwfPreferWebgl ?? !0,
|
|
770
|
-
preferWasm: s.dwfPreferWasm ?? !0,
|
|
771
|
-
background: l,
|
|
772
|
-
maxDevicePixelRatio: s.dwfMaxDevicePixelRatio ?? 2,
|
|
773
|
-
maxCanvasPixels: s.dwfMaxCanvasPixels ?? 16777216,
|
|
774
|
-
maxGpuCacheBytes: s.dwfMaxGpuCacheBytes ?? 160 * 1024 * 1024,
|
|
775
|
-
maxCachedScenes: s.dwfMaxCachedScenes ?? 2
|
|
776
|
-
}), (O = s.onProgress) == null || O.call(s, { phase: "parse", format: c, message: "Parsing DWF package and page streams…", percent: 58 }), await this.native.load(a, {
|
|
765
|
+
var O, z, Y, gt, bt;
|
|
766
|
+
const s = { ...this.defaults, ...i }, n = performance.now(), o = t.fileName ?? ((O = t.file) == null ? void 0 : O.name), a = await _(t), c = Nt(A(t, a), L(t)), h = Be(s), l = Et(s), f = Fe(s, h, l), u = Ut(s, h, l);
|
|
767
|
+
(z = s.onProgress) == null || z.call(s, { phase: "native-render", format: c, message: "Mounting native DWF renderer…", percent: 28 }), this.unmount(), this.host = r, r.replaceChildren(), this.native = new te(r, f), (Y = s.onProgress) == null || Y.call(s, { phase: "parse", format: c, message: "Parsing DWF package and page streams…", percent: 58 }), await this.native.load(a, {
|
|
777
768
|
fileName: o,
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}), (z = s.onProgress) == null || z.call(s, { phase: "render", format: c, message: "Rendering DWF/DWFx with dwf-viewer…", percent: 88 }), this.lastStats = await this.native.render();
|
|
785
|
-
const f = this.native.getDocument(), u = Ct(f, o, c, s.keepRaw === !0);
|
|
786
|
-
u.metadata.loaderMode = "Native DWF", u.metadata.nativeRenderer = "dwf-viewer", u.metadata.nativeRenderStats = this.lastStats ? { ...this.lastStats, warnings: this.lastStats.warnings.length } : void 0;
|
|
787
|
-
const p = performance.now() - n;
|
|
788
|
-
return (Y = s.onProgress) == null || Y.call(s, { phase: "done", format: u.format, message: "DWF/DWFx rendered.", percent: 100, elapsedMs: p }), { document: u, raw: s.keepRaw ? f : void 0, bytes: a.byteLength, elapsedMs: p, format: u.format, warnings: u.warnings };
|
|
769
|
+
...u
|
|
770
|
+
}), (gt = s.onProgress) == null || gt.call(s, { phase: "render", format: c, message: "Rendering DWF/DWFx with dwf-viewer…", percent: 88 }), this.lastStats = await this.native.render();
|
|
771
|
+
const p = this.native.getDocument(), g = St(p, o, c, s.keepRaw === !0);
|
|
772
|
+
g.metadata.loaderMode = "Native DWF", g.metadata.nativeRenderer = "dwf-viewer", g.metadata.nativeRenderStats = this.lastStats ? { ...this.lastStats, warnings: this.lastStats.warnings.length } : void 0;
|
|
773
|
+
const S = performance.now() - n;
|
|
774
|
+
return (bt = s.onProgress) == null || bt.call(s, { phase: "done", format: g.format, message: "DWF/DWFx rendered.", percent: 100, elapsedMs: S }), { document: g, raw: s.keepRaw ? p : void 0, bytes: a.byteLength, elapsedMs: S, format: g.format, warnings: g.warnings };
|
|
789
775
|
}
|
|
790
776
|
unmount() {
|
|
791
777
|
var t;
|
|
@@ -810,48 +796,48 @@ class Pe {
|
|
|
810
796
|
(t = this.native) == null || t.render();
|
|
811
797
|
}
|
|
812
798
|
setNativeOptions(t) {
|
|
813
|
-
var i, s, n;
|
|
799
|
+
var i, s, n, o;
|
|
814
800
|
const r = this.native;
|
|
815
801
|
if (r) {
|
|
816
802
|
if (typeof t.dwfBackground == "string") r.background = t.dwfBackground;
|
|
817
803
|
else {
|
|
818
|
-
const
|
|
819
|
-
|
|
804
|
+
const a = Et(t);
|
|
805
|
+
a && (r.background = a);
|
|
820
806
|
}
|
|
821
|
-
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)), (n = r.
|
|
807
|
+
typeof t.dwfPreferWebgl == "boolean" && ((i = r.setPreferWebgl) == null || i.call(r, t.dwfPreferWebgl)), typeof t.dwfPreferWasm == "boolean" && ((s = r.setPreferWasm) == null || s.call(r, t.dwfPreferWasm)), t.dwfLineWeightMode && ((n = r.setLineWeightMode) == null || n.call(r, t.dwfLineWeightMode)), Z(r, "minStrokeCssPx", t.dwfMinStrokeCssPx), Z(r, "maxOverviewStrokeCssPx", t.dwfMaxOverviewStrokeCssPx), Z(r, "minTextCssPx", t.dwfMinTextCssPx), Z(r, "minFilledAreaCssPx", t.dwfMinFilledAreaCssPx), (o = r.render) == null || o.call(r);
|
|
822
808
|
}
|
|
823
809
|
}
|
|
824
810
|
getLastNativeStats() {
|
|
825
811
|
return this.lastStats;
|
|
826
812
|
}
|
|
827
813
|
}
|
|
828
|
-
function
|
|
814
|
+
function St(e, t, r, i) {
|
|
829
815
|
var a, c;
|
|
830
|
-
const s =
|
|
831
|
-
for (const h of (e == null ? void 0 : e.pageData) ?? []) s.push(...
|
|
816
|
+
const s = Mt((e == null ? void 0 : e.diagnostics) ?? []), n = ((e == null ? void 0 : e.pageData) ?? []).map((h, l) => Ie(h, l));
|
|
817
|
+
for (const h of (e == null ? void 0 : e.pageData) ?? []) s.push(...Mt(h.diagnostics));
|
|
832
818
|
const o = {
|
|
833
819
|
parser: "dwf-viewer",
|
|
834
820
|
nativeRenderer: "dwf-viewer",
|
|
835
821
|
dwfKind: e == null ? void 0 : e.kind,
|
|
836
822
|
packageEntries: ((a = e == null ? void 0 : e.packageEntries) == null ? void 0 : a.length) ?? 0,
|
|
837
823
|
resources: ((c = e == null ? void 0 : e.resources) == null ? void 0 : c.length) ?? 0,
|
|
838
|
-
pageKinds:
|
|
824
|
+
pageKinds: De(((e == null ? void 0 : e.pageData) ?? []).map((h) => h.kind)),
|
|
839
825
|
pageNames: ((e == null ? void 0 : e.pages) ?? []).map((h) => h.name)
|
|
840
826
|
};
|
|
841
|
-
return
|
|
827
|
+
return zt({
|
|
842
828
|
format: r,
|
|
843
829
|
sourceName: t,
|
|
844
830
|
layers: {},
|
|
845
831
|
blocks: {},
|
|
846
832
|
pages: n,
|
|
847
|
-
entities:
|
|
833
|
+
entities: ue(n),
|
|
848
834
|
metadata: o,
|
|
849
|
-
warnings:
|
|
835
|
+
warnings: Oe(s),
|
|
850
836
|
raw: i ? e : void 0
|
|
851
837
|
});
|
|
852
838
|
}
|
|
853
|
-
function
|
|
854
|
-
const r =
|
|
839
|
+
function Ie(e, t) {
|
|
840
|
+
const r = Te(e, t);
|
|
855
841
|
return {
|
|
856
842
|
index: t,
|
|
857
843
|
name: e.name || e.sourcePath || `${t + 1}`,
|
|
@@ -860,18 +846,18 @@ function Se(e, t) {
|
|
|
860
846
|
entities: r
|
|
861
847
|
};
|
|
862
848
|
}
|
|
863
|
-
function
|
|
864
|
-
return e.kind === "w2d-text" ? e.primitives.flatMap((r, i) =>
|
|
849
|
+
function Te(e, t) {
|
|
850
|
+
return e.kind === "w2d-text" ? e.primitives.flatMap((r, i) => Le(r, t, i)) : e.kind === "image" ? [{ type: "DWF_IMAGE_PAGE", kind: "image", pageIndex: t, width: e.width, height: e.height, imageSource: e.sourcePath }] : e.kind === "w3d-model" ? e.model.meshes.map((r, i) => ({
|
|
865
851
|
id: r.id,
|
|
866
852
|
type: "W3D_MESH",
|
|
867
853
|
kind: "solid",
|
|
868
854
|
pageIndex: t,
|
|
869
|
-
color: r.color ?
|
|
855
|
+
color: r.color ? Re(r.color) : void 0,
|
|
870
856
|
name: r.name || `mesh-${i + 1}`,
|
|
871
857
|
raw: { vertexCount: r.vertexCount, triangleCount: r.triangleCount, materialId: r.materialId }
|
|
872
858
|
})) : e.kind === "xps-fixed-page" ? [{ type: "XPS_FIXED_PAGE", kind: "viewport", pageIndex: t, width: e.width, height: e.height, raw: { sourcePath: e.sourcePath } }] : [{ type: "DWF_PAGE", kind: "viewport", pageIndex: t, width: e.width, height: e.height, raw: { sourcePath: e.sourcePath } }];
|
|
873
859
|
}
|
|
874
|
-
function
|
|
860
|
+
function Le(e, t, r) {
|
|
875
861
|
const i = {
|
|
876
862
|
id: `dwf-${t}-${r}`,
|
|
877
863
|
pageIndex: t,
|
|
@@ -885,7 +871,7 @@ function Ne(e, t, r) {
|
|
|
885
871
|
...i,
|
|
886
872
|
type: e.type === "polygon" ? "DWF_POLYGON" : "DWF_POLYLINE",
|
|
887
873
|
kind: "polyline",
|
|
888
|
-
vertices:
|
|
874
|
+
vertices: Ae(e.points),
|
|
889
875
|
isClosed: e.type === "polygon"
|
|
890
876
|
}];
|
|
891
877
|
if (e.type === "path")
|
|
@@ -916,58 +902,83 @@ function Ne(e, t, r) {
|
|
|
916
902
|
}
|
|
917
903
|
return [];
|
|
918
904
|
}
|
|
919
|
-
function
|
|
905
|
+
function Ae(e) {
|
|
920
906
|
const t = [];
|
|
921
907
|
for (let r = 0; r + 1 < e.length; r += 2) t.push({ x: e[r], y: e[r + 1], z: 0 });
|
|
922
908
|
return t;
|
|
923
909
|
}
|
|
924
|
-
function
|
|
910
|
+
function Mt(e) {
|
|
925
911
|
return e.filter((t) => t.level !== "info").map((t) => `${t.code}: ${t.message}${t.source ? ` (${t.source})` : ""}`);
|
|
926
912
|
}
|
|
927
|
-
function
|
|
913
|
+
function Nt(e, t) {
|
|
928
914
|
return t === "dwf" || t === "dwfx" || t === "xps" ? t : e === "dwf" || e === "dwfx" || e === "xps" ? e : "dwf";
|
|
929
915
|
}
|
|
930
|
-
function
|
|
916
|
+
function Be(e) {
|
|
931
917
|
if (e.dwfWasmUrl) return e.dwfWasmUrl;
|
|
932
918
|
if (typeof document > "u") return;
|
|
933
|
-
const t = e.wasmPath ? new URL(
|
|
919
|
+
const t = e.wasmPath ? new URL(We(e.wasmPath), document.baseURI).href : new URL("wasm/", document.baseURI).href;
|
|
934
920
|
return new URL("dwfv-render.wasm", t).href;
|
|
935
921
|
}
|
|
936
|
-
function
|
|
922
|
+
function Et(e) {
|
|
937
923
|
if (e.dwfBackground) return e.dwfBackground;
|
|
938
924
|
const t = e.canvasOptions;
|
|
939
925
|
return (t == null ? void 0 : t.background) ?? "#05070d";
|
|
940
926
|
}
|
|
941
|
-
function
|
|
927
|
+
function Fe(e, t, r) {
|
|
928
|
+
return {
|
|
929
|
+
...Ut(e, t, r),
|
|
930
|
+
maxDevicePixelRatio: e.dwfMaxDevicePixelRatio ?? 2,
|
|
931
|
+
maxCanvasPixels: e.dwfMaxCanvasPixels ?? 16777216
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
function Ut(e, t, r) {
|
|
935
|
+
return {
|
|
936
|
+
wasmUrl: t,
|
|
937
|
+
preferWebgl: e.dwfPreferWebgl ?? !0,
|
|
938
|
+
preferWasm: e.dwfPreferWasm ?? !0,
|
|
939
|
+
background: r,
|
|
940
|
+
maxGpuCacheBytes: e.dwfMaxGpuCacheBytes ?? 160 * 1024 * 1024,
|
|
941
|
+
maxCachedScenes: e.dwfMaxCachedScenes ?? 2,
|
|
942
|
+
lineWeightMode: e.dwfLineWeightMode ?? "adaptive",
|
|
943
|
+
minStrokeCssPx: e.dwfMinStrokeCssPx,
|
|
944
|
+
maxOverviewStrokeCssPx: e.dwfMaxOverviewStrokeCssPx,
|
|
945
|
+
minTextCssPx: e.dwfMinTextCssPx,
|
|
946
|
+
minFilledAreaCssPx: e.dwfMinFilledAreaCssPx
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function Z(e, t, r) {
|
|
950
|
+
typeof r == "number" && Number.isFinite(r) && (e[t] = r);
|
|
951
|
+
}
|
|
952
|
+
function We(e) {
|
|
942
953
|
return e.endsWith("/") ? e : `${e}/`;
|
|
943
954
|
}
|
|
944
|
-
function
|
|
955
|
+
function Re(e) {
|
|
945
956
|
const [t, r, i] = e.map((s) => Math.max(0, Math.min(255, Math.round(s * 255))));
|
|
946
|
-
return `#${
|
|
957
|
+
return `#${rt(t)}${rt(r)}${rt(i)}`;
|
|
947
958
|
}
|
|
948
|
-
function
|
|
959
|
+
function rt(e) {
|
|
949
960
|
return e.toString(16).padStart(2, "0");
|
|
950
961
|
}
|
|
951
|
-
function
|
|
962
|
+
function De(e) {
|
|
952
963
|
const t = {};
|
|
953
964
|
for (const r of e) t[r] = (t[r] ?? 0) + 1;
|
|
954
965
|
return t;
|
|
955
966
|
}
|
|
956
|
-
function
|
|
967
|
+
function Oe(e) {
|
|
957
968
|
return Array.from(new Set(e));
|
|
958
969
|
}
|
|
959
|
-
function
|
|
960
|
-
return new
|
|
961
|
-
new
|
|
962
|
-
new
|
|
963
|
-
new
|
|
970
|
+
function ze(e = {}) {
|
|
971
|
+
return new re([
|
|
972
|
+
new ce(e),
|
|
973
|
+
new me(e),
|
|
974
|
+
new Ee(e)
|
|
964
975
|
]);
|
|
965
976
|
}
|
|
966
|
-
function
|
|
977
|
+
function Ye(e) {
|
|
967
978
|
const t = e;
|
|
968
979
|
return t.nativeRenderer === !0 && typeof t.mount == "function";
|
|
969
980
|
}
|
|
970
|
-
const
|
|
981
|
+
const He = {
|
|
971
982
|
1: "#ff0000",
|
|
972
983
|
2: "#ffff00",
|
|
973
984
|
3: "#00ff00",
|
|
@@ -1226,16 +1237,16 @@ const Re = {
|
|
|
1226
1237
|
function N(e, t = "#ffffff", r = t) {
|
|
1227
1238
|
if (typeof e != "number" || Number.isNaN(e)) return t;
|
|
1228
1239
|
const i = Math.abs(Math.trunc(e));
|
|
1229
|
-
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r :
|
|
1240
|
+
return i === 0 || i === 256 || i === 257 ? t : i === 7 ? r : He[i] ?? t;
|
|
1230
1241
|
}
|
|
1231
1242
|
function U(e, t = "rgb") {
|
|
1232
1243
|
const r = Math.max(0, Math.trunc(e)) & 16777215, i = r >> 16 & 255, s = r >> 8 & 255, n = r & 255;
|
|
1233
1244
|
return `rgb(${t === "rgb" ? i : n}, ${s}, ${t === "rgb" ? n : i})`;
|
|
1234
1245
|
}
|
|
1235
|
-
function
|
|
1246
|
+
function B(e) {
|
|
1236
1247
|
if (typeof e == "string") {
|
|
1237
1248
|
const t = e.trim();
|
|
1238
|
-
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ?
|
|
1249
|
+
return t ? /^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t) ? Xe(t) ?? t : {
|
|
1239
1250
|
red: "#ff0000",
|
|
1240
1251
|
yellow: "#ffff00",
|
|
1241
1252
|
green: "#00ff00",
|
|
@@ -1254,29 +1265,29 @@ function A(e) {
|
|
|
1254
1265
|
return Number.isFinite(n) && n >= 0 && n < 1 ? `rgba(${r}, ${i}, ${s}, ${n})` : `rgb(${r}, ${i}, ${s})`;
|
|
1255
1266
|
}
|
|
1256
1267
|
}
|
|
1257
|
-
function
|
|
1268
|
+
function Xe(e) {
|
|
1258
1269
|
if (!e) return;
|
|
1259
1270
|
const t = e.trim();
|
|
1260
1271
|
if (/^#[0-9a-f]{8}$/i.test(t)) {
|
|
1261
1272
|
const r = parseInt(t.slice(1, 3), 16) / 255, i = parseInt(t.slice(3, 5), 16), s = parseInt(t.slice(5, 7), 16), n = parseInt(t.slice(7, 9), 16);
|
|
1262
|
-
return r >= 0.999 ? `rgb(${i}, ${s}, ${n})` : `rgba(${i}, ${s}, ${n}, ${
|
|
1273
|
+
return r >= 0.999 ? `rgb(${i}, ${s}, ${n})` : `rgba(${i}, ${s}, ${n}, ${ut(r)})`;
|
|
1263
1274
|
}
|
|
1264
1275
|
if (/^#[0-9a-f]{6}$/i.test(t) || /^#[0-9a-f]{3}$/i.test(t)) return t;
|
|
1265
1276
|
if (/^sc#/i.test(t)) {
|
|
1266
1277
|
const r = t.slice(3).split(",").map((a) => Number(a.trim())), [i, s, n, o] = r.length === 4 ? r : [1, ...r];
|
|
1267
|
-
if ([i, s, n, o].every(Number.isFinite)) return `rgba(${Math.round(s * 255)}, ${Math.round(n * 255)}, ${Math.round(o * 255)}, ${
|
|
1278
|
+
if ([i, s, n, o].every(Number.isFinite)) return `rgba(${Math.round(s * 255)}, ${Math.round(n * 255)}, ${Math.round(o * 255)}, ${ut(i)})`;
|
|
1268
1279
|
}
|
|
1269
1280
|
}
|
|
1270
1281
|
function F(e, t, r = {}) {
|
|
1271
1282
|
const i = r.foreground ?? "#ffffff", s = i;
|
|
1272
1283
|
let n;
|
|
1273
|
-
const o =
|
|
1284
|
+
const o = B(e.trueColor) ?? B(e.color) ?? B(e.colorName);
|
|
1274
1285
|
if (o && (n = o), !n) {
|
|
1275
|
-
const a =
|
|
1286
|
+
const a = Ge(e, ["trueColor", "true_color", "truecolor", "colorRGB", "colorRgb", "rgbColor", "rgb"]);
|
|
1276
1287
|
typeof a == "number" && a >= 0 && a <= 16777215 && (n = U(a, r.trueColorByteOrder ?? "rgb"));
|
|
1277
1288
|
}
|
|
1278
1289
|
if (!n) {
|
|
1279
|
-
const a =
|
|
1290
|
+
const a = Gt(e.colorIndex, e.colorNumber, e.aci);
|
|
1280
1291
|
typeof a == "number" && Math.abs(a) <= 257 && a !== 256 && a !== 0 && a !== 257 && (n = N(a, s, i));
|
|
1281
1292
|
}
|
|
1282
1293
|
if (!n && typeof e.color == "number") {
|
|
@@ -1284,81 +1295,81 @@ function F(e, t, r = {}) {
|
|
|
1284
1295
|
Math.abs(a) <= 257 ? a !== 0 && a !== 256 && a !== 257 && (n = N(a, s, i)) : n = U(a, r.trueColorByteOrder ?? "rgb");
|
|
1285
1296
|
}
|
|
1286
1297
|
if (!n) {
|
|
1287
|
-
const a =
|
|
1288
|
-
n =
|
|
1298
|
+
const a = je(t, e.layer);
|
|
1299
|
+
n = Ue(a, r);
|
|
1289
1300
|
}
|
|
1290
|
-
return
|
|
1301
|
+
return Vt(n ?? s, r);
|
|
1291
1302
|
}
|
|
1292
|
-
function
|
|
1303
|
+
function ft(e, t, r = {}) {
|
|
1293
1304
|
let i;
|
|
1294
|
-
const s =
|
|
1305
|
+
const s = B(e.fillColor);
|
|
1295
1306
|
if (s && (i = s), !i && typeof e.fillColor == "number") {
|
|
1296
1307
|
const n = e.fillColor;
|
|
1297
1308
|
i = Math.abs(n) <= 257 ? N(n, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff") : U(n, r.trueColorByteOrder ?? "rgb");
|
|
1298
1309
|
}
|
|
1299
|
-
return !i && typeof e.fillColorIndex == "number" && (i = N(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ?
|
|
1310
|
+
return !i && typeof e.fillColorIndex == "number" && (i = N(e.fillColorIndex, r.foreground ?? "#ffffff", r.foreground ?? "#ffffff")), i ? Vt(i, r) : void 0;
|
|
1300
1311
|
}
|
|
1301
|
-
function
|
|
1312
|
+
function Vt(e, t = {}) {
|
|
1302
1313
|
if (t.contrastMode !== "adaptive") return e;
|
|
1303
1314
|
const r = t.background ?? "#0b1020", i = t.foreground ?? "#ffffff";
|
|
1304
|
-
return
|
|
1315
|
+
return _e(e, r, i, t.minColorContrast ?? 2.4);
|
|
1305
1316
|
}
|
|
1306
|
-
function
|
|
1307
|
-
const s =
|
|
1317
|
+
function _e(e, t, r, i = 2.4) {
|
|
1318
|
+
const s = it(r) ?? { r: 255, g: 255, b: 255, a: 1 }, n = it(t) ?? { r: 11, g: 16, b: 32, a: 1 }, o = it(e);
|
|
1308
1319
|
if (!o) return e;
|
|
1309
|
-
const a =
|
|
1310
|
-
if (
|
|
1311
|
-
const c =
|
|
1320
|
+
const a = It(o, n);
|
|
1321
|
+
if (st(a, n) >= i) return e;
|
|
1322
|
+
const c = dt(n), h = c < 0.5 ? { r: 255, g: 255, b: 255, a: o.a } : { r: 0, g: 0, b: 0, a: o.a };
|
|
1312
1323
|
for (const l of [0.25, 0.4, 0.55, 0.7, 0.85, 1]) {
|
|
1313
|
-
const f =
|
|
1314
|
-
if (
|
|
1324
|
+
const f = Ze(o, h, l);
|
|
1325
|
+
if (st(It(f, n), n) >= i) return Tt(f);
|
|
1315
1326
|
}
|
|
1316
|
-
return
|
|
1327
|
+
return st(s, n) >= i ? Tt(s) : c < 0.5 ? "#ffffff" : "#000000";
|
|
1317
1328
|
}
|
|
1318
|
-
function
|
|
1329
|
+
function $t(e) {
|
|
1319
1330
|
return e ? e.isVisible !== !1 && e.isFrozen !== !0 : !0;
|
|
1320
1331
|
}
|
|
1321
|
-
function
|
|
1332
|
+
function Ue(e, t) {
|
|
1322
1333
|
if (!e) return;
|
|
1323
|
-
const r = t.foreground ?? "#ffffff", i =
|
|
1334
|
+
const r = t.foreground ?? "#ffffff", i = B(e.trueColor);
|
|
1324
1335
|
if (i) return i;
|
|
1325
1336
|
if (typeof e.trueColor == "number" && e.trueColor >= 0 && e.trueColor <= 16777215) return U(e.trueColor, t.trueColorByteOrder ?? "rgb");
|
|
1326
|
-
const s =
|
|
1337
|
+
const s = B(e.color);
|
|
1327
1338
|
if (s) return s;
|
|
1328
|
-
if (
|
|
1339
|
+
if ($e(e.colorIndex)) return N(e.colorIndex, r, r);
|
|
1329
1340
|
if (typeof e.color == "number") {
|
|
1330
1341
|
const n = Number(e.color);
|
|
1331
1342
|
return Math.abs(n) <= 257 ? N(n, r, r) : U(n, t.trueColorByteOrder ?? "rgb");
|
|
1332
1343
|
}
|
|
1333
1344
|
if (typeof e.colorIndex == "number") return N(e.colorIndex, r, r);
|
|
1334
1345
|
}
|
|
1335
|
-
function
|
|
1336
|
-
return
|
|
1346
|
+
function Ve(e) {
|
|
1347
|
+
return Gt(e.colorIndex, e.colorNumber, e.aci) === 0 ? !0 : e.trueColor === void 0 && e.color === 0;
|
|
1337
1348
|
}
|
|
1338
|
-
function
|
|
1339
|
-
if (!
|
|
1349
|
+
function jt(e, t, r, i = {}) {
|
|
1350
|
+
if (!Ve(e)) return e;
|
|
1340
1351
|
const s = F(t, r, i);
|
|
1341
1352
|
return { ...e, color: s, trueColor: void 0, colorIndex: void 0, colorNumber: void 0 };
|
|
1342
1353
|
}
|
|
1343
|
-
function
|
|
1354
|
+
function $e(e) {
|
|
1344
1355
|
return typeof e == "number" && Number.isFinite(e) && Math.abs(Math.trunc(e)) >= 1 && Math.abs(Math.trunc(e)) <= 255;
|
|
1345
1356
|
}
|
|
1346
|
-
function
|
|
1357
|
+
function je(e, t) {
|
|
1347
1358
|
if (!(!e || !t))
|
|
1348
1359
|
return e.layers[t] ?? e.layers[t.toLowerCase()] ?? Object.values(e.layers).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
1349
1360
|
}
|
|
1350
|
-
function
|
|
1361
|
+
function Gt(...e) {
|
|
1351
1362
|
for (const t of e)
|
|
1352
1363
|
if (typeof t == "number" && Number.isFinite(t)) return t;
|
|
1353
1364
|
}
|
|
1354
|
-
function
|
|
1365
|
+
function Ge(e, t) {
|
|
1355
1366
|
const r = e;
|
|
1356
1367
|
for (const i of t) {
|
|
1357
1368
|
const s = r[i];
|
|
1358
1369
|
if (typeof s == "number" && Number.isFinite(s)) return s;
|
|
1359
1370
|
}
|
|
1360
1371
|
}
|
|
1361
|
-
function
|
|
1372
|
+
function it(e) {
|
|
1362
1373
|
const t = e.trim().toLowerCase();
|
|
1363
1374
|
if (/^#[0-9a-f]{3}$/i.test(t))
|
|
1364
1375
|
return {
|
|
@@ -1388,7 +1399,7 @@ function rt(e) {
|
|
|
1388
1399
|
}
|
|
1389
1400
|
}
|
|
1390
1401
|
}
|
|
1391
|
-
function
|
|
1402
|
+
function It(e, t) {
|
|
1392
1403
|
const r = e.a + t.a * (1 - e.a);
|
|
1393
1404
|
return r <= 0 ? { r: 0, g: 0, b: 0, a: 0 } : {
|
|
1394
1405
|
r: (e.r * e.a + t.r * t.a * (1 - e.a)) / r,
|
|
@@ -1397,7 +1408,7 @@ function Mt(e, t) {
|
|
|
1397
1408
|
a: r
|
|
1398
1409
|
};
|
|
1399
1410
|
}
|
|
1400
|
-
function
|
|
1411
|
+
function Ze(e, t, r) {
|
|
1401
1412
|
const i = Math.max(0, Math.min(1, r));
|
|
1402
1413
|
return {
|
|
1403
1414
|
r: e.r + (t.r - e.r) * i,
|
|
@@ -1406,28 +1417,28 @@ function Ue(e, t, r) {
|
|
|
1406
1417
|
a: e.a
|
|
1407
1418
|
};
|
|
1408
1419
|
}
|
|
1409
|
-
function
|
|
1420
|
+
function dt(e) {
|
|
1410
1421
|
const t = [e.r, e.g, e.b].map((r) => {
|
|
1411
1422
|
const i = r / 255;
|
|
1412
1423
|
return i <= 0.03928 ? i / 12.92 : ((i + 0.055) / 1.055) ** 2.4;
|
|
1413
1424
|
});
|
|
1414
1425
|
return 0.2126 * t[0] + 0.7152 * t[1] + 0.0722 * t[2];
|
|
1415
1426
|
}
|
|
1416
|
-
function
|
|
1417
|
-
const r =
|
|
1427
|
+
function st(e, t) {
|
|
1428
|
+
const r = dt(e), i = dt(t), s = Math.max(r, i), n = Math.min(r, i);
|
|
1418
1429
|
return (s + 0.05) / (n + 0.05);
|
|
1419
1430
|
}
|
|
1420
|
-
function
|
|
1431
|
+
function Tt(e) {
|
|
1421
1432
|
const t = W(e.r), r = W(e.g), i = W(e.b);
|
|
1422
|
-
return e.a < 0.999 ? `rgba(${t}, ${r}, ${i}, ${
|
|
1433
|
+
return e.a < 0.999 ? `rgba(${t}, ${r}, ${i}, ${ut(e.a)})` : `rgb(${t}, ${r}, ${i})`;
|
|
1423
1434
|
}
|
|
1424
1435
|
function W(e) {
|
|
1425
1436
|
return Math.max(0, Math.min(255, Math.round(e)));
|
|
1426
1437
|
}
|
|
1427
|
-
function
|
|
1438
|
+
function ut(e) {
|
|
1428
1439
|
return Math.round(e * 1e3) / 1e3;
|
|
1429
1440
|
}
|
|
1430
|
-
function
|
|
1441
|
+
function nt(e, t) {
|
|
1431
1442
|
return {
|
|
1432
1443
|
a: e.a * t.a + e.c * t.b,
|
|
1433
1444
|
b: e.b * t.a + e.d * t.b,
|
|
@@ -1437,50 +1448,50 @@ function st(e, t) {
|
|
|
1437
1448
|
f: e.b * t.e + e.d * t.f + e.f
|
|
1438
1449
|
};
|
|
1439
1450
|
}
|
|
1440
|
-
function
|
|
1451
|
+
function Lt(e, t) {
|
|
1441
1452
|
return { a: 1, b: 0, c: 0, d: 1, e, f: t };
|
|
1442
1453
|
}
|
|
1443
|
-
function
|
|
1454
|
+
function qe(e) {
|
|
1444
1455
|
const t = Math.cos(e), r = Math.sin(e);
|
|
1445
1456
|
return { a: t, b: r, c: -r, d: t, e: 0, f: 0 };
|
|
1446
1457
|
}
|
|
1447
|
-
function
|
|
1458
|
+
function Ke(e, t = e) {
|
|
1448
1459
|
return { a: e, b: 0, c: 0, d: t, e: 0, f: 0 };
|
|
1449
1460
|
}
|
|
1450
|
-
function
|
|
1461
|
+
function k(e, t) {
|
|
1451
1462
|
return {
|
|
1452
1463
|
x: e.x * t.a + e.y * t.c + t.e,
|
|
1453
1464
|
y: e.x * t.b + e.y * t.d + t.f,
|
|
1454
1465
|
z: "z" in e ? e.z : void 0
|
|
1455
1466
|
};
|
|
1456
1467
|
}
|
|
1457
|
-
function
|
|
1468
|
+
function At(e, t) {
|
|
1458
1469
|
if (e)
|
|
1459
|
-
return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) =>
|
|
1470
|
+
return e.map((r) => ({ cmd: r.cmd, points: r.points.map((i) => k(i, t)) }));
|
|
1460
1471
|
}
|
|
1461
|
-
function
|
|
1472
|
+
function Q(e, t = { x: 0, y: 0 }) {
|
|
1462
1473
|
const r = e.insertionPoint ?? { x: 0, y: 0 }, i = e.scale, s = Number(typeof i == "object" && i ? i.x ?? 1 : e.scaleX ?? 1), n = Number(typeof i == "object" && i ? i.y ?? s : e.scaleY ?? s), o = Number(e.rotation ?? 0);
|
|
1463
|
-
let a =
|
|
1464
|
-
return a =
|
|
1474
|
+
let a = Lt(r.x, r.y);
|
|
1475
|
+
return a = nt(a, qe(Number.isFinite(o) ? o : 0)), a = nt(a, Ke(Number.isFinite(s) ? s : 1, Number.isFinite(n) ? n : 1)), a = nt(a, Lt(-t.x, -t.y)), a;
|
|
1465
1476
|
}
|
|
1466
|
-
function
|
|
1477
|
+
function tt(e, t) {
|
|
1467
1478
|
const r = { ...e, raw: e.raw ?? e };
|
|
1468
|
-
if (e.startPoint && (r.startPoint =
|
|
1469
|
-
const s =
|
|
1479
|
+
if (e.startPoint && (r.startPoint = k(e.startPoint, t)), e.endPoint && (r.endPoint = k(e.endPoint, t)), e.center && (r.center = k(e.center, t)), e.insertionPoint && (r.insertionPoint = k(e.insertionPoint, t)), e.majorAxisEndPoint) {
|
|
1480
|
+
const s = k({ x: 0, y: 0 }, t), n = k(e.majorAxisEndPoint, t);
|
|
1470
1481
|
r.majorAxisEndPoint = { x: n.x - s.x, y: n.y - s.y, z: n.z };
|
|
1471
1482
|
}
|
|
1472
|
-
e.vertices && (r.vertices = e.vertices.map((s) => ({ ...
|
|
1483
|
+
e.vertices && (r.vertices = e.vertices.map((s) => ({ ...k(s, t), bulge: s.bulge, startWidth: s.startWidth, endWidth: s.endWidth }))), e.points && (r.points = e.points.map((s) => k(s, t))), e.controlPoints && (r.controlPoints = e.controlPoints.map((s) => k(s, t))), e.fitPoints && (r.fitPoints = e.fitPoints.map((s) => k(s, t))), e.commands && (r.commands = At(e.commands, t)), e.loops && (r.loops = e.loops.map((s) => {
|
|
1473
1484
|
var n;
|
|
1474
1485
|
return {
|
|
1475
1486
|
...s,
|
|
1476
|
-
vertices: (n = s.vertices) == null ? void 0 : n.map((o) =>
|
|
1477
|
-
commands:
|
|
1487
|
+
vertices: (n = s.vertices) == null ? void 0 : n.map((o) => k(o, t)),
|
|
1488
|
+
commands: At(s.commands, t)
|
|
1478
1489
|
};
|
|
1479
1490
|
}));
|
|
1480
1491
|
const i = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c));
|
|
1481
1492
|
return typeof e.radius == "number" && Number.isFinite(i) && (r.radius = e.radius * i), r;
|
|
1482
1493
|
}
|
|
1483
|
-
const
|
|
1494
|
+
const Je = {
|
|
1484
1495
|
background: "#0b1020",
|
|
1485
1496
|
foreground: "#ffffff",
|
|
1486
1497
|
showUnsupportedMarkers: !1,
|
|
@@ -1503,7 +1514,7 @@ const je = {
|
|
|
1503
1514
|
preserveDrawingBuffer: !1,
|
|
1504
1515
|
enableSpatialIndex: !0
|
|
1505
1516
|
};
|
|
1506
|
-
class
|
|
1517
|
+
class Bt {
|
|
1507
1518
|
constructor(t, r = {}) {
|
|
1508
1519
|
d(this, "canvas");
|
|
1509
1520
|
d(this, "ctx");
|
|
@@ -1522,7 +1533,7 @@ class Tt {
|
|
|
1522
1533
|
d(this, "onViewChange");
|
|
1523
1534
|
const i = t.getContext("2d");
|
|
1524
1535
|
if (!i) throw new Error("Canvas 2D context is not available.");
|
|
1525
|
-
this.canvas = t, this.ctx = i, this.opts = { ...
|
|
1536
|
+
this.canvas = t, this.ctx = i, this.opts = { ...Je, ...r }, this.canvas.classList.add("cad-viewer-canvas"), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
|
|
1526
1537
|
}
|
|
1527
1538
|
destroy() {
|
|
1528
1539
|
var t;
|
|
@@ -1587,7 +1598,7 @@ class Tt {
|
|
|
1587
1598
|
return { ...this.bounds };
|
|
1588
1599
|
}
|
|
1589
1600
|
getStats() {
|
|
1590
|
-
return
|
|
1601
|
+
return Qe(this.stats);
|
|
1591
1602
|
}
|
|
1592
1603
|
getZoomRatio() {
|
|
1593
1604
|
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
@@ -1655,7 +1666,7 @@ class Tt {
|
|
|
1655
1666
|
const i = String(t.type ?? "UNKNOWN").toUpperCase();
|
|
1656
1667
|
this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
|
|
1657
1668
|
const s = this.lookupLayer(t.layer);
|
|
1658
|
-
if (t.isVisible === !1 ||
|
|
1669
|
+
if (t.isVisible === !1 || !$t(s)) {
|
|
1659
1670
|
this.stats.skipped++;
|
|
1660
1671
|
return;
|
|
1661
1672
|
}
|
|
@@ -1698,7 +1709,7 @@ class Tt {
|
|
|
1698
1709
|
beginStyledPath(t, r = !1) {
|
|
1699
1710
|
const i = this.ctx;
|
|
1700
1711
|
i.save(), i.setTransform(this.dpr, 0, 0, this.dpr, 0, 0);
|
|
1701
|
-
const s = F(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), n =
|
|
1712
|
+
const s = F(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }), n = ft(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }) ?? s;
|
|
1702
1713
|
i.strokeStyle = s, i.fillStyle = r ? n : s, i.globalAlpha = T(Number(t.opacity ?? 1), 0, 1), i.lineCap = "round", i.lineJoin = "round";
|
|
1703
1714
|
const o = typeof t.lineweight == "number" && t.lineweight > 0 ? t.lineweight : 0;
|
|
1704
1715
|
i.lineWidth = Math.max(1, Math.min(12, o > 0 ? o / 30 : 1)), i.beginPath();
|
|
@@ -1724,7 +1735,7 @@ class Tt {
|
|
|
1724
1735
|
drawArc(t) {
|
|
1725
1736
|
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
1726
1737
|
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
1727
|
-
this.strokeWorldPolyline(t,
|
|
1738
|
+
this.strokeWorldPolyline(t, q(x(r), i, s, n, !0), !1);
|
|
1728
1739
|
}
|
|
1729
1740
|
drawPolyline(t) {
|
|
1730
1741
|
const r = t.vertices ?? t.points;
|
|
@@ -1733,7 +1744,7 @@ class Tt {
|
|
|
1733
1744
|
for (let o = 0; o < n; o++) {
|
|
1734
1745
|
const a = r[o], c = r[(o + 1) % r.length];
|
|
1735
1746
|
if (!m(a) || !m(c)) continue;
|
|
1736
|
-
const h =
|
|
1747
|
+
const h = Xt(a, c, Number(a.bulge ?? 0));
|
|
1737
1748
|
s.length > 0 && h.shift(), s.push(...h);
|
|
1738
1749
|
}
|
|
1739
1750
|
this.strokeWorldPolyline(t, s, i);
|
|
@@ -1741,7 +1752,7 @@ class Tt {
|
|
|
1741
1752
|
drawEllipse(t) {
|
|
1742
1753
|
const r = t.center, i = t.majorAxisEndPoint, s = Number(t.axisRatio ?? 1);
|
|
1743
1754
|
if (!m(r) || !m(i)) return this.markSkipped("ELLIPSE");
|
|
1744
|
-
const n =
|
|
1755
|
+
const n = K(r, i, s, Number(t.startAngle ?? 0), Number(t.endAngle ?? Math.PI * 2)), o = Math.abs(Number(t.endAngle ?? Math.PI * 2) - Number(t.startAngle ?? 0)) >= Math.PI * 2 - 1e-6;
|
|
1745
1756
|
this.strokeWorldPolyline(t, n, o);
|
|
1746
1757
|
}
|
|
1747
1758
|
drawPoint(t) {
|
|
@@ -1751,17 +1762,17 @@ class Tt {
|
|
|
1751
1762
|
this.beginStyledPath(t), this.ctx.moveTo(i.x - 3, i.y), this.ctx.lineTo(i.x + 3, i.y), this.ctx.moveTo(i.x, i.y - 3), this.ctx.lineTo(i.x, i.y + 3), this.finishStroke();
|
|
1752
1763
|
}
|
|
1753
1764
|
drawText(t) {
|
|
1754
|
-
const r = t.insertionPoint ?? t.startPoint ?? t.center, i =
|
|
1765
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = _t(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
1755
1766
|
if (!m(r) || !i) return this.markSkipped(String(t.type));
|
|
1756
1767
|
this.drawTextAt(t, r, i, s, Number(t.rotation ?? 0));
|
|
1757
1768
|
}
|
|
1758
1769
|
drawInsert(t, r) {
|
|
1759
1770
|
const i = this.lookupBlock(t.blockName ?? t.name);
|
|
1760
1771
|
if (i && r < this.opts.maxInsertDepth) {
|
|
1761
|
-
const a =
|
|
1772
|
+
const a = Q(t, i.basePoint ?? { x: 0, y: 0 });
|
|
1762
1773
|
for (const c of i.entities) {
|
|
1763
|
-
const h =
|
|
1764
|
-
this.drawEntityTracked(
|
|
1774
|
+
const h = jt(c, t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast });
|
|
1775
|
+
this.drawEntityTracked(tt(h, a), r + 1);
|
|
1765
1776
|
}
|
|
1766
1777
|
return;
|
|
1767
1778
|
}
|
|
@@ -1801,7 +1812,7 @@ class Tt {
|
|
|
1801
1812
|
}
|
|
1802
1813
|
this.ctx.closePath();
|
|
1803
1814
|
}
|
|
1804
|
-
this.finishFillStroke(!!
|
|
1815
|
+
this.finishFillStroke(!!ft(t, this.document, { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast }));
|
|
1805
1816
|
}
|
|
1806
1817
|
drawSpline(t) {
|
|
1807
1818
|
var i;
|
|
@@ -1894,38 +1905,38 @@ class Tt {
|
|
|
1894
1905
|
const r = M();
|
|
1895
1906
|
if ((i = t.pages) != null && i.length)
|
|
1896
1907
|
for (const s of t.pages)
|
|
1897
|
-
|
|
1908
|
+
v(r, { x: 0, y: 0 }), v(r, { x: s.width, y: s.height });
|
|
1898
1909
|
for (const s of t.entities) this.includeEntityBounds(r, s, 0);
|
|
1899
|
-
return
|
|
1910
|
+
return Ht(r);
|
|
1900
1911
|
}
|
|
1901
1912
|
includeEntityBounds(t, r, i) {
|
|
1902
1913
|
const s = String(r.type ?? "").toUpperCase(), n = r.kind ?? R(s);
|
|
1903
1914
|
if (n === "insert") {
|
|
1904
1915
|
const o = this.lookupBlock(r.blockName ?? r.name);
|
|
1905
1916
|
if (o && i < this.opts.maxInsertDepth) {
|
|
1906
|
-
const a =
|
|
1907
|
-
for (const c of o.entities) this.includeEntityBounds(t,
|
|
1917
|
+
const a = Q(r, o.basePoint ?? { x: 0, y: 0 });
|
|
1918
|
+
for (const c of o.entities) this.includeEntityBounds(t, tt(c, a), i + 1);
|
|
1908
1919
|
return;
|
|
1909
1920
|
}
|
|
1910
1921
|
}
|
|
1911
1922
|
if (n === "line")
|
|
1912
|
-
m(r.startPoint) &&
|
|
1923
|
+
m(r.startPoint) && v(t, r.startPoint), m(r.endPoint) && v(t, r.endPoint);
|
|
1913
1924
|
else if (n === "circle" || n === "arc")
|
|
1914
|
-
m(r.center) && Number.isFinite(r.radius) &&
|
|
1925
|
+
m(r.center) && Number.isFinite(r.radius) && Yt(t, r.center, Number(r.radius));
|
|
1915
1926
|
else if (n === "polyline" || n === "solid" || n === "spline")
|
|
1916
|
-
for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) &&
|
|
1927
|
+
for (const o of [...r.vertices ?? [], ...r.points ?? [], ...r.controlPoints ?? [], ...r.fitPoints ?? []]) m(o) && v(t, o);
|
|
1917
1928
|
else if (n === "ellipse")
|
|
1918
|
-
m(r.center) && m(r.majorAxisEndPoint) &&
|
|
1929
|
+
m(r.center) && m(r.majorAxisEndPoint) && K(r.center, r.majorAxisEndPoint, Number(r.axisRatio ?? 1), Number(r.startAngle ?? 0), Number(r.endAngle ?? Math.PI * 2)).forEach((o) => v(t, o));
|
|
1919
1930
|
else if (n === "path")
|
|
1920
|
-
for (const o of r.commands ?? []) for (const a of o.points)
|
|
1931
|
+
for (const o of r.commands ?? []) for (const a of o.points) v(t, a);
|
|
1921
1932
|
else if (n === "hatch")
|
|
1922
1933
|
for (const o of r.loops ?? []) {
|
|
1923
|
-
for (const a of o.vertices ?? [])
|
|
1924
|
-
for (const a of o.commands ?? []) for (const c of a.points)
|
|
1934
|
+
for (const a of o.vertices ?? []) v(t, a);
|
|
1935
|
+
for (const a of o.commands ?? []) for (const c of a.points) v(t, c);
|
|
1925
1936
|
}
|
|
1926
1937
|
else {
|
|
1927
1938
|
const o = this.entityAnchor(r);
|
|
1928
|
-
o &&
|
|
1939
|
+
o && v(t, o);
|
|
1929
1940
|
}
|
|
1930
1941
|
}
|
|
1931
1942
|
lookupLayer(t) {
|
|
@@ -1950,7 +1961,7 @@ class Tt {
|
|
|
1950
1961
|
});
|
|
1951
1962
|
}
|
|
1952
1963
|
}
|
|
1953
|
-
function
|
|
1964
|
+
function Qe(e) {
|
|
1954
1965
|
return {
|
|
1955
1966
|
total: e.total,
|
|
1956
1967
|
drawn: e.drawn,
|
|
@@ -1966,7 +1977,7 @@ function Ge(e) {
|
|
|
1966
1977
|
buildElapsedMs: e.buildElapsedMs
|
|
1967
1978
|
};
|
|
1968
1979
|
}
|
|
1969
|
-
const
|
|
1980
|
+
const tr = {
|
|
1970
1981
|
background: "#0b1020",
|
|
1971
1982
|
foreground: "#ffffff",
|
|
1972
1983
|
showUnsupportedMarkers: !1,
|
|
@@ -1989,7 +2000,7 @@ const Ze = {
|
|
|
1989
2000
|
preserveDrawingBuffer: !1,
|
|
1990
2001
|
enableSpatialIndex: !0
|
|
1991
2002
|
};
|
|
1992
|
-
class
|
|
2003
|
+
class Ft {
|
|
1993
2004
|
constructor(t, r = {}) {
|
|
1994
2005
|
d(this, "canvas");
|
|
1995
2006
|
d(this, "backend", "webgl");
|
|
@@ -2013,12 +2024,12 @@ class Lt {
|
|
|
2013
2024
|
d(this, "rafHandle", 0);
|
|
2014
2025
|
d(this, "onStats");
|
|
2015
2026
|
d(this, "onViewChange");
|
|
2016
|
-
const i =
|
|
2027
|
+
const i = er(t, r);
|
|
2017
2028
|
if (!i) throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');
|
|
2018
|
-
this.canvas = t, this.gl = i, this.program =
|
|
2029
|
+
this.canvas = t, this.gl = i, this.program = rr(i), this.opts = { ...tr, ...r }, this.canvas.classList.add("cad-viewer-canvas", "cad-viewer-webgl-canvas"), this.createOverlayCanvas(), this.bindEvents(), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(t)), this.resize();
|
|
2019
2030
|
}
|
|
2020
2031
|
static isSupported() {
|
|
2021
|
-
return
|
|
2032
|
+
return Zt();
|
|
2022
2033
|
}
|
|
2023
2034
|
destroy() {
|
|
2024
2035
|
var t, r;
|
|
@@ -2028,15 +2039,15 @@ class Lt {
|
|
|
2028
2039
|
this.document = void 0, this.bounds = M(), this.view = { centerX: 0, centerY: 0, scale: 1 }, this.fitScale = 1, this.disposeScene(), this.render(), this.emitViewChange();
|
|
2029
2040
|
}
|
|
2030
2041
|
setDocument(t) {
|
|
2031
|
-
this.document = t, this.bounds =
|
|
2032
|
-
const r =
|
|
2033
|
-
this.scene =
|
|
2042
|
+
this.document = t, this.bounds = cr(t, this.opts), this.disposeScene();
|
|
2043
|
+
const r = sr(t, this.opts, this.bounds);
|
|
2044
|
+
this.scene = ir(this.gl, r), this.stats = fr(this.scene, 0), this.fitToView();
|
|
2034
2045
|
}
|
|
2035
2046
|
getDocument() {
|
|
2036
2047
|
return this.document;
|
|
2037
2048
|
}
|
|
2038
2049
|
setOptions(t) {
|
|
2039
|
-
const r =
|
|
2050
|
+
const r = lr(this.opts, t);
|
|
2040
2051
|
if (this.opts = { ...this.opts, ...t }, r && this.document) {
|
|
2041
2052
|
this.setDocument(this.document);
|
|
2042
2053
|
return;
|
|
@@ -2090,7 +2101,7 @@ class Lt {
|
|
|
2090
2101
|
return { ...this.bounds };
|
|
2091
2102
|
}
|
|
2092
2103
|
getStats() {
|
|
2093
|
-
return
|
|
2104
|
+
return dr(this.stats);
|
|
2094
2105
|
}
|
|
2095
2106
|
getZoomRatio() {
|
|
2096
2107
|
return Math.abs(this.fitScale) < 1e-12 ? 1 : this.view.scale / this.fitScale;
|
|
@@ -2117,7 +2128,7 @@ class Lt {
|
|
|
2117
2128
|
var h;
|
|
2118
2129
|
const t = performance.now(), r = this.gl;
|
|
2119
2130
|
r.viewport(0, 0, this.canvas.width, this.canvas.height);
|
|
2120
|
-
const i =
|
|
2131
|
+
const i = mt(this.opts.background, [11, 16, 32, 255]);
|
|
2121
2132
|
r.clearColor(i[0] / 255, i[1] / 255, i[2] / 255, i[3] / 255), r.clear(r.COLOR_BUFFER_BIT), r.disable(r.DEPTH_TEST), r.enable(r.BLEND), r.blendFunc(r.SRC_ALPHA, r.ONE_MINUS_SRC_ALPHA);
|
|
2122
2133
|
let s = 0, n = 0;
|
|
2123
2134
|
const o = this.scene, a = this.visibleWorldBounds();
|
|
@@ -2138,7 +2149,7 @@ class Lt {
|
|
|
2138
2149
|
const s = this.gl;
|
|
2139
2150
|
let n = 0, o = 0;
|
|
2140
2151
|
for (const a of t) {
|
|
2141
|
-
if (!
|
|
2152
|
+
if (!ct(a.bounds, i)) {
|
|
2142
2153
|
o += a.primitiveCount;
|
|
2143
2154
|
continue;
|
|
2144
2155
|
}
|
|
@@ -2175,7 +2186,7 @@ class Lt {
|
|
|
2175
2186
|
let n = 0;
|
|
2176
2187
|
for (const o of r) {
|
|
2177
2188
|
if (n >= s) break;
|
|
2178
|
-
if (!
|
|
2189
|
+
if (!ct(o.bounds, i)) continue;
|
|
2179
2190
|
const a = Math.abs(o.height) * this.view.scale;
|
|
2180
2191
|
if (a < this.opts.textMinPixelHeight) continue;
|
|
2181
2192
|
const c = this.worldToScreen(o.point);
|
|
@@ -2189,7 +2200,7 @@ class Lt {
|
|
|
2189
2200
|
}
|
|
2190
2201
|
drawImagesOverlay(t, r, i) {
|
|
2191
2202
|
for (const s of r) {
|
|
2192
|
-
if (!
|
|
2203
|
+
if (!ct(s.bounds, i)) continue;
|
|
2193
2204
|
const n = this.worldToScreen(s.point), o = this.worldToScreen({ x: s.point.x + s.width, y: s.point.y - s.height }), a = Math.min(n.x, o.x), c = Math.min(n.y, o.y), h = Math.abs(o.x - n.x), l = Math.abs(o.y - n.y);
|
|
2194
2205
|
if (!(h < 1 || l < 1)) {
|
|
2195
2206
|
if (s.source) {
|
|
@@ -2274,12 +2285,12 @@ class Lt {
|
|
|
2274
2285
|
});
|
|
2275
2286
|
}
|
|
2276
2287
|
}
|
|
2277
|
-
function
|
|
2288
|
+
function Zt() {
|
|
2278
2289
|
if (typeof document > "u") return !1;
|
|
2279
2290
|
const e = document.createElement("canvas");
|
|
2280
2291
|
return !!(e.getContext("webgl2") ?? e.getContext("webgl") ?? e.getContext("experimental-webgl"));
|
|
2281
2292
|
}
|
|
2282
|
-
function
|
|
2293
|
+
function er(e, t) {
|
|
2283
2294
|
const r = {
|
|
2284
2295
|
alpha: !1,
|
|
2285
2296
|
antialias: t.antialias ?? !0,
|
|
@@ -2290,7 +2301,7 @@ function qe(e, t) {
|
|
|
2290
2301
|
};
|
|
2291
2302
|
return e.getContext("webgl2", r) ?? e.getContext("webgl", r) ?? e.getContext("experimental-webgl", r) ?? void 0;
|
|
2292
2303
|
}
|
|
2293
|
-
function
|
|
2304
|
+
function rr(e) {
|
|
2294
2305
|
const t = `
|
|
2295
2306
|
attribute vec2 a_position;
|
|
2296
2307
|
attribute vec4 a_color;
|
|
@@ -2315,7 +2326,7 @@ function Ke(e) {
|
|
|
2315
2326
|
void main() {
|
|
2316
2327
|
gl_FragColor = v_color;
|
|
2317
2328
|
}
|
|
2318
|
-
`, i =
|
|
2329
|
+
`, i = Wt(e, e.VERTEX_SHADER, t), s = Wt(e, e.FRAGMENT_SHADER, r), n = e.createProgram();
|
|
2319
2330
|
if (!n) throw new Error("Failed to create WebGL program.");
|
|
2320
2331
|
if (e.attachShader(n, i), e.attachShader(n, s), e.linkProgram(n), !e.getProgramParameter(n, e.LINK_STATUS)) {
|
|
2321
2332
|
const l = e.getProgramInfoLog(n) ?? "Unknown WebGL program link error.";
|
|
@@ -2334,7 +2345,7 @@ function Ke(e) {
|
|
|
2334
2345
|
uPointSize: h
|
|
2335
2346
|
};
|
|
2336
2347
|
}
|
|
2337
|
-
function
|
|
2348
|
+
function Wt(e, t, r) {
|
|
2338
2349
|
const i = e.createShader(t);
|
|
2339
2350
|
if (!i) throw new Error("Failed to create WebGL shader.");
|
|
2340
2351
|
if (e.shaderSource(i, r), e.compileShader(i), !e.getShaderParameter(i, e.COMPILE_STATUS)) {
|
|
@@ -2343,10 +2354,10 @@ function Bt(e, t, r) {
|
|
|
2343
2354
|
}
|
|
2344
2355
|
return i;
|
|
2345
2356
|
}
|
|
2346
|
-
function
|
|
2357
|
+
function ir(e, t) {
|
|
2347
2358
|
let r = 0;
|
|
2348
2359
|
const i = (a) => a.map((c) => {
|
|
2349
|
-
const h =
|
|
2360
|
+
const h = Rt(e, c.positions), l = Rt(e, c.colors), f = c.positions.byteLength + c.colors.byteLength;
|
|
2350
2361
|
return r += f, {
|
|
2351
2362
|
positionBuffer: h,
|
|
2352
2363
|
colorBuffer: l,
|
|
@@ -2369,18 +2380,18 @@ function Je(e, t) {
|
|
|
2369
2380
|
buildElapsedMs: t.buildElapsedMs
|
|
2370
2381
|
};
|
|
2371
2382
|
}
|
|
2372
|
-
function
|
|
2383
|
+
function Rt(e, t) {
|
|
2373
2384
|
const r = e.createBuffer();
|
|
2374
2385
|
if (!r) throw new Error("Failed to create WebGL buffer.");
|
|
2375
2386
|
return e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW), r;
|
|
2376
2387
|
}
|
|
2377
|
-
function
|
|
2378
|
-
const i = performance.now(), s = D(r) ? { x: (r.minX + r.maxX) / 2, y: (r.minY + r.maxY) / 2 } : { x: 0, y: 0 }, n = new
|
|
2388
|
+
function sr(e, t, r) {
|
|
2389
|
+
const i = performance.now(), s = D(r) ? { x: (r.minX + r.maxX) / 2, y: (r.minY + r.maxY) / 2 } : { x: 0, y: 0 }, n = new nr(e, t, r, s);
|
|
2379
2390
|
for (const a of e.entities) n.addEntityTracked(a, 0);
|
|
2380
2391
|
const o = n.finalize();
|
|
2381
2392
|
return o.buildElapsedMs = performance.now() - i, o;
|
|
2382
2393
|
}
|
|
2383
|
-
class
|
|
2394
|
+
class nr {
|
|
2384
2395
|
constructor(t, r, i, s) {
|
|
2385
2396
|
d(this, "lineBuckets", /* @__PURE__ */ new Map());
|
|
2386
2397
|
d(this, "triangleBuckets", /* @__PURE__ */ new Map());
|
|
@@ -2400,14 +2411,14 @@ class tr {
|
|
|
2400
2411
|
const i = String(t.type ?? "UNKNOWN").toUpperCase();
|
|
2401
2412
|
this.stats.byType[i] = (this.stats.byType[i] ?? 0) + 1;
|
|
2402
2413
|
const s = this.lookupLayer(t.layer);
|
|
2403
|
-
if (t.isVisible === !1 ||
|
|
2414
|
+
if (t.isVisible === !1 || !$t(s)) {
|
|
2404
2415
|
this.stats.skipped++;
|
|
2405
2416
|
return;
|
|
2406
2417
|
}
|
|
2407
2418
|
this.addEntity(t, i, r);
|
|
2408
2419
|
}
|
|
2409
2420
|
finalize() {
|
|
2410
|
-
const t =
|
|
2421
|
+
const t = ot(this.lineBuckets, this.maxVerticesPerBatch), r = ot(this.triangleBuckets, this.maxVerticesPerBatch), i = ot(this.pointBuckets, this.maxVerticesPerBatch);
|
|
2411
2422
|
return this.stats.primitiveCount = this.primitiveCount, {
|
|
2412
2423
|
origin: this.origin,
|
|
2413
2424
|
lineBatches: t,
|
|
@@ -2461,13 +2472,13 @@ class tr {
|
|
|
2461
2472
|
addCircleEntity(t) {
|
|
2462
2473
|
const r = t.center, i = Number(t.radius);
|
|
2463
2474
|
if (!m(r) || !Number.isFinite(i)) return this.markSkipped("CIRCLE");
|
|
2464
|
-
const s = Math.max(16, Math.min(this.opts.maxCurveSegments, Math.ceil(Math.sqrt(Math.abs(i)) * 12))), n =
|
|
2475
|
+
const s = Math.max(16, Math.min(this.opts.maxCurveSegments, Math.ceil(Math.sqrt(Math.abs(i)) * 12))), n = q(r, i, 0, Math.PI * 2, !0, s);
|
|
2465
2476
|
this.addPolyline(n, !0, this.strokeBytes(t)), this.stats.drawn++;
|
|
2466
2477
|
}
|
|
2467
2478
|
addArcEntity(t) {
|
|
2468
2479
|
const r = t.center, i = Number(t.radius), s = Number(t.startAngle), n = Number(t.endAngle);
|
|
2469
2480
|
if (!m(r) || !Number.isFinite(i) || !Number.isFinite(s) || !Number.isFinite(n)) return this.markSkipped("ARC");
|
|
2470
|
-
this.addPolyline(
|
|
2481
|
+
this.addPolyline(q(r, i, s, n, !0, this.opts.maxCurveSegments), !1, this.strokeBytes(t)), this.stats.drawn++;
|
|
2471
2482
|
}
|
|
2472
2483
|
addPolylineEntity(t) {
|
|
2473
2484
|
const r = t.vertices ?? t.points;
|
|
@@ -2476,7 +2487,7 @@ class tr {
|
|
|
2476
2487
|
for (let o = 0; o < n; o++) {
|
|
2477
2488
|
const a = r[o], c = r[(o + 1) % r.length];
|
|
2478
2489
|
if (!m(a) || !m(c)) continue;
|
|
2479
|
-
const h =
|
|
2490
|
+
const h = Xt(a, c, Number(a.bulge ?? 0), Math.max(4, Math.min(24, this.opts.maxCurveSegments / 4)));
|
|
2480
2491
|
s.length > 0 && h.shift(), s.push(...h);
|
|
2481
2492
|
}
|
|
2482
2493
|
if (s.length < 2) return this.markSkipped(String(t.type));
|
|
@@ -2484,11 +2495,11 @@ class tr {
|
|
|
2484
2495
|
}
|
|
2485
2496
|
addEllipseEntity(t) {
|
|
2486
2497
|
if (!m(t.center) || !m(t.majorAxisEndPoint)) return this.markSkipped("ELLIPSE");
|
|
2487
|
-
const r =
|
|
2498
|
+
const r = K(t.center, t.majorAxisEndPoint, Number(t.axisRatio ?? 1), Number(t.startAngle ?? 0), Number(t.endAngle ?? Math.PI * 2), this.opts.maxCurveSegments), i = Math.abs(Number(t.endAngle ?? Math.PI * 2) - Number(t.startAngle ?? 0)) >= Math.PI * 2 - 1e-6;
|
|
2488
2499
|
this.addPolyline(r, i, this.strokeBytes(t)), this.stats.drawn++;
|
|
2489
2500
|
}
|
|
2490
2501
|
addTextEntity(t) {
|
|
2491
|
-
const r = t.insertionPoint ?? t.startPoint ?? t.center, i =
|
|
2502
|
+
const r = t.insertionPoint ?? t.startPoint ?? t.center, i = _t(String(t.text ?? t.value ?? "")), s = Number(t.textHeight ?? t.height ?? 1);
|
|
2492
2503
|
if (!m(r) || !i || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2493
2504
|
const n = x(r), o = Math.max(1, i.split(/\r?\n/g).reduce((c, h) => Math.max(c, h.length), 0)) * Math.abs(s) * 0.62, a = Math.max(1, i.split(/\r?\n/g).length) * Math.abs(s) * 1.22;
|
|
2494
2505
|
this.textItems.push({
|
|
@@ -2509,10 +2520,10 @@ class tr {
|
|
|
2509
2520
|
addInsertEntity(t, r) {
|
|
2510
2521
|
const i = this.lookupBlock(t.blockName ?? t.name);
|
|
2511
2522
|
if (i && r < this.opts.maxInsertDepth) {
|
|
2512
|
-
const n =
|
|
2523
|
+
const n = Q(t, i.basePoint ?? { x: 0, y: 0 });
|
|
2513
2524
|
for (const o of i.entities) {
|
|
2514
|
-
const a =
|
|
2515
|
-
this.addEntityTracked(
|
|
2525
|
+
const a = jt(o, t, this.document, this.colorOptions());
|
|
2526
|
+
this.addEntityTracked(tt(a, n), r + 1);
|
|
2516
2527
|
}
|
|
2517
2528
|
return;
|
|
2518
2529
|
}
|
|
@@ -2536,7 +2547,7 @@ class tr {
|
|
|
2536
2547
|
const i = this.strokeBytes(t), s = this.fillBytes(t);
|
|
2537
2548
|
let n = !1;
|
|
2538
2549
|
for (const a of r) {
|
|
2539
|
-
const c = (o = a.commands) != null && o.length ?
|
|
2550
|
+
const c = (o = a.commands) != null && o.length ? Dt(a.commands, this.opts.maxCurveSegments) : (a.vertices ?? []).filter(m).map(x);
|
|
2540
2551
|
c.length < 2 || (this.addPolyline(c, !0, i), s && c.length >= 3 && this.addTriangleFan(c, s), n = !0);
|
|
2541
2552
|
}
|
|
2542
2553
|
if (!n) return this.markSkipped("HATCH");
|
|
@@ -2551,7 +2562,7 @@ class tr {
|
|
|
2551
2562
|
addPathEntity(t) {
|
|
2552
2563
|
var s;
|
|
2553
2564
|
if (!((s = t.commands) != null && s.length)) return this.markSkipped(String(t.type));
|
|
2554
|
-
const r =
|
|
2565
|
+
const r = Dt(t.commands, this.opts.maxCurveSegments);
|
|
2555
2566
|
if (r.length < 2) return this.markSkipped(String(t.type));
|
|
2556
2567
|
this.addPolyline(r, !1, this.strokeBytes(t));
|
|
2557
2568
|
const i = this.fillBytes(t);
|
|
@@ -2562,11 +2573,11 @@ class tr {
|
|
|
2562
2573
|
if (!m(r)) return this.markSkipped(String(t.type));
|
|
2563
2574
|
const i = Number(t.width ?? 32), s = Number(t.height ?? 32);
|
|
2564
2575
|
if (!Number.isFinite(i) || !Number.isFinite(s)) return this.markSkipped(String(t.type));
|
|
2565
|
-
const n = x(r), o =
|
|
2576
|
+
const n = x(r), o = at([n, { x: n.x + i, y: n.y - s }]);
|
|
2566
2577
|
this.imageItems.push({ point: n, width: i, height: s, source: t.imageDataUrl ?? t.imageSource, color: F(t, this.document, this.colorOptions()), opacity: T(Number(t.opacity ?? 1), 0, 1), bounds: o }), this.stats.drawn++;
|
|
2567
2578
|
}
|
|
2568
2579
|
addUnsupportedMarker(t) {
|
|
2569
|
-
const r =
|
|
2580
|
+
const r = qt(t);
|
|
2570
2581
|
r && this.addPoint(r, this.strokeBytes(t));
|
|
2571
2582
|
}
|
|
2572
2583
|
addPolyline(t, r, i) {
|
|
@@ -2578,24 +2589,24 @@ class tr {
|
|
|
2578
2589
|
}
|
|
2579
2590
|
addSegment(t, r, i) {
|
|
2580
2591
|
if (!m(t) || !m(r) || Math.hypot(t.x - r.x, t.y - r.y) <= 1e-14) return;
|
|
2581
|
-
const s = this.batchFor(this.lineBuckets,
|
|
2592
|
+
const s = this.batchFor(this.lineBuckets, at([t, r]));
|
|
2582
2593
|
I(s, t, i, this.origin), I(s, r, i, this.origin), s.primitiveCount++, this.primitiveCount++;
|
|
2583
2594
|
}
|
|
2584
2595
|
addPoint(t, r) {
|
|
2585
|
-
const i = this.batchFor(this.pointBuckets,
|
|
2596
|
+
const i = this.batchFor(this.pointBuckets, hr(t));
|
|
2586
2597
|
I(i, t, r, this.origin), i.primitiveCount++, this.primitiveCount++;
|
|
2587
2598
|
}
|
|
2588
2599
|
addTriangleFan(t, r) {
|
|
2589
2600
|
const i = t.filter(m).map(x);
|
|
2590
2601
|
if (i.length < 3) return;
|
|
2591
|
-
const s =
|
|
2602
|
+
const s = at(i), n = this.batchFor(this.triangleBuckets, s);
|
|
2592
2603
|
for (let o = 1; o < i.length - 1; o++)
|
|
2593
2604
|
I(n, i[0], r, this.origin), I(n, i[o], r, this.origin), I(n, i[o + 1], r, this.origin), n.primitiveCount++, this.primitiveCount++;
|
|
2594
2605
|
}
|
|
2595
2606
|
batchFor(t, r) {
|
|
2596
2607
|
const i = this.bucketKey(r);
|
|
2597
2608
|
let s = t.get(i);
|
|
2598
|
-
return s || (s =
|
|
2609
|
+
return s || (s = or(), t.set(i, s)), v(s.bounds, { x: r.minX, y: r.minY }), v(s.bounds, { x: r.maxX, y: r.maxY }), s;
|
|
2599
2610
|
}
|
|
2600
2611
|
bucketKey(t) {
|
|
2601
2612
|
if (!Number.isFinite(this.tileSize)) return "all";
|
|
@@ -2603,11 +2614,11 @@ class tr {
|
|
|
2603
2614
|
return `${s}:${n}`;
|
|
2604
2615
|
}
|
|
2605
2616
|
strokeBytes(t) {
|
|
2606
|
-
return
|
|
2617
|
+
return mt(F(t, this.document, this.colorOptions()), [255, 255, 255, 255], T(Number(t.opacity ?? 1), 0, 1));
|
|
2607
2618
|
}
|
|
2608
2619
|
fillBytes(t) {
|
|
2609
|
-
const r =
|
|
2610
|
-
return r ?
|
|
2620
|
+
const r = ft(t, this.document, this.colorOptions());
|
|
2621
|
+
return r ? mt(r, [255, 255, 255, 255], T(Number(t.opacity ?? 1), 0, 1)) : void 0;
|
|
2611
2622
|
}
|
|
2612
2623
|
colorOptions() {
|
|
2613
2624
|
return { foreground: this.opts.foreground, background: this.opts.background, trueColorByteOrder: this.opts.trueColorByteOrder, contrastMode: this.opts.contrastMode, minColorContrast: this.opts.minColorContrast };
|
|
@@ -2624,13 +2635,13 @@ class tr {
|
|
|
2624
2635
|
return this.document.blocks[t] ?? this.document.blocks[t.toLowerCase()] ?? Object.values(this.document.blocks).find((r) => r.name.toLowerCase() === t.toLowerCase());
|
|
2625
2636
|
}
|
|
2626
2637
|
}
|
|
2627
|
-
function
|
|
2638
|
+
function or() {
|
|
2628
2639
|
return { positions: [], colors: [], bounds: M(), primitiveCount: 0 };
|
|
2629
2640
|
}
|
|
2630
2641
|
function I(e, t, r, i) {
|
|
2631
2642
|
e.positions.push(t.x - i.x, t.y - i.y), e.colors.push(r[0], r[1], r[2], r[3]);
|
|
2632
2643
|
}
|
|
2633
|
-
function
|
|
2644
|
+
function ot(e, t) {
|
|
2634
2645
|
const r = [];
|
|
2635
2646
|
for (const i of e.values()) {
|
|
2636
2647
|
const s = i.positions.length / 2;
|
|
@@ -2639,25 +2650,25 @@ function nt(e, t) {
|
|
|
2639
2650
|
r.push({ positions: new Float32Array(i.positions), colors: new Uint8Array(i.colors), bounds: { ...i.bounds }, primitiveCount: i.primitiveCount });
|
|
2640
2651
|
continue;
|
|
2641
2652
|
}
|
|
2642
|
-
const n =
|
|
2653
|
+
const n = ar(i), o = Math.max(n, Math.floor(t / n) * n);
|
|
2643
2654
|
for (let a = 0; a < s; a += o) {
|
|
2644
2655
|
const c = Math.min(s, a + o), h = i.positions.slice(a * 2, c * 2), l = i.colors.slice(a * 4, c * 4), f = M();
|
|
2645
|
-
for (let u = 0; u < h.length; u += 2)
|
|
2656
|
+
for (let u = 0; u < h.length; u += 2) v(f, { x: h[u], y: h[u + 1] });
|
|
2646
2657
|
r.push({ positions: new Float32Array(h), colors: new Uint8Array(l), bounds: { ...i.bounds }, primitiveCount: Math.floor((c - a) / n) });
|
|
2647
2658
|
}
|
|
2648
2659
|
}
|
|
2649
2660
|
return r;
|
|
2650
2661
|
}
|
|
2651
|
-
function
|
|
2662
|
+
function ar(e) {
|
|
2652
2663
|
const t = e.positions.length / 2;
|
|
2653
2664
|
return t === e.primitiveCount ? 1 : t === e.primitiveCount * 3 ? 3 : 2;
|
|
2654
2665
|
}
|
|
2655
|
-
function
|
|
2666
|
+
function cr(e, t) {
|
|
2656
2667
|
var n;
|
|
2657
2668
|
const r = M();
|
|
2658
2669
|
if ((n = e.pages) != null && n.length)
|
|
2659
2670
|
for (const o of e.pages)
|
|
2660
|
-
|
|
2671
|
+
v(r, { x: 0, y: 0 }), v(r, { x: o.width, y: o.height });
|
|
2661
2672
|
const i = (o) => {
|
|
2662
2673
|
if (o)
|
|
2663
2674
|
return e.blocks[o] ?? e.blocks[o.toLowerCase()] ?? Object.values(e.blocks).find((a) => a.name.toLowerCase() === o.toLowerCase());
|
|
@@ -2666,35 +2677,35 @@ function ir(e, t) {
|
|
|
2666
2677
|
if (h === "insert") {
|
|
2667
2678
|
const l = i(o.blockName ?? o.name);
|
|
2668
2679
|
if (l && a < t.maxInsertDepth) {
|
|
2669
|
-
const f =
|
|
2670
|
-
for (const u of l.entities) s(
|
|
2680
|
+
const f = Q(o, l.basePoint ?? { x: 0, y: 0 });
|
|
2681
|
+
for (const u of l.entities) s(tt(u, f), a + 1);
|
|
2671
2682
|
return;
|
|
2672
2683
|
}
|
|
2673
2684
|
}
|
|
2674
2685
|
if (h === "line")
|
|
2675
|
-
m(o.startPoint) &&
|
|
2686
|
+
m(o.startPoint) && v(r, o.startPoint), m(o.endPoint) && v(r, o.endPoint);
|
|
2676
2687
|
else if (h === "circle" || h === "arc")
|
|
2677
|
-
m(o.center) && Number.isFinite(o.radius) &&
|
|
2688
|
+
m(o.center) && Number.isFinite(o.radius) && Yt(r, o.center, Number(o.radius));
|
|
2678
2689
|
else if (h === "polyline" || h === "solid" || h === "spline")
|
|
2679
|
-
for (const l of [...o.vertices ?? [], ...o.points ?? [], ...o.controlPoints ?? [], ...o.fitPoints ?? []]) m(l) &&
|
|
2690
|
+
for (const l of [...o.vertices ?? [], ...o.points ?? [], ...o.controlPoints ?? [], ...o.fitPoints ?? []]) m(l) && v(r, l);
|
|
2680
2691
|
else if (h === "ellipse")
|
|
2681
|
-
m(o.center) && m(o.majorAxisEndPoint) &&
|
|
2692
|
+
m(o.center) && m(o.majorAxisEndPoint) && K(o.center, o.majorAxisEndPoint, Number(o.axisRatio ?? 1), Number(o.startAngle ?? 0), Number(o.endAngle ?? Math.PI * 2), t.maxCurveSegments).forEach((l) => v(r, l));
|
|
2682
2693
|
else if (h === "path")
|
|
2683
|
-
for (const l of o.commands ?? []) for (const f of l.points)
|
|
2694
|
+
for (const l of o.commands ?? []) for (const f of l.points) v(r, f);
|
|
2684
2695
|
else if (h === "hatch")
|
|
2685
2696
|
for (const l of o.loops ?? []) {
|
|
2686
|
-
for (const f of l.vertices ?? [])
|
|
2687
|
-
for (const f of l.commands ?? []) for (const u of f.points)
|
|
2697
|
+
for (const f of l.vertices ?? []) v(r, f);
|
|
2698
|
+
for (const f of l.commands ?? []) for (const u of f.points) v(r, u);
|
|
2688
2699
|
}
|
|
2689
2700
|
else {
|
|
2690
|
-
const l =
|
|
2691
|
-
l &&
|
|
2701
|
+
const l = qt(o);
|
|
2702
|
+
l && v(r, l);
|
|
2692
2703
|
}
|
|
2693
2704
|
};
|
|
2694
2705
|
for (const o of e.entities) s(o, 0);
|
|
2695
|
-
return
|
|
2706
|
+
return Ht(r);
|
|
2696
2707
|
}
|
|
2697
|
-
function
|
|
2708
|
+
function Dt(e, t) {
|
|
2698
2709
|
const r = [];
|
|
2699
2710
|
let i, s;
|
|
2700
2711
|
const n = (o) => {
|
|
@@ -2714,16 +2725,16 @@ function Ft(e, t) {
|
|
|
2714
2725
|
} else if (o.cmd === "C" && i && o.points.length >= 3) {
|
|
2715
2726
|
const a = i, [c, h, l] = o.points, f = Math.max(6, Math.min(t, 32));
|
|
2716
2727
|
for (let u = 1; u <= f; u++) {
|
|
2717
|
-
const p = u / f,
|
|
2728
|
+
const p = u / f, g = 1 - p;
|
|
2718
2729
|
n({
|
|
2719
|
-
x:
|
|
2720
|
-
y:
|
|
2730
|
+
x: g ** 3 * a.x + 3 * g * g * p * c.x + 3 * g * p * p * h.x + p ** 3 * l.x,
|
|
2731
|
+
y: g ** 3 * a.y + 3 * g * g * p * c.y + 3 * g * p * p * h.y + p ** 3 * l.y
|
|
2721
2732
|
});
|
|
2722
2733
|
}
|
|
2723
2734
|
} else o.cmd === "Z" && s && n(s);
|
|
2724
2735
|
return r;
|
|
2725
2736
|
}
|
|
2726
|
-
function
|
|
2737
|
+
function qt(e) {
|
|
2727
2738
|
for (const t of ["startPoint", "insertionPoint", "center", "point", "location"]) {
|
|
2728
2739
|
const r = e[t];
|
|
2729
2740
|
if (m(r)) return x(r);
|
|
@@ -2734,24 +2745,24 @@ function $t(e) {
|
|
|
2734
2745
|
if (t) return x(t.points[0]);
|
|
2735
2746
|
}
|
|
2736
2747
|
}
|
|
2737
|
-
function
|
|
2748
|
+
function at(e) {
|
|
2738
2749
|
const t = M();
|
|
2739
|
-
for (const r of e)
|
|
2750
|
+
for (const r of e) v(t, r);
|
|
2740
2751
|
return t;
|
|
2741
2752
|
}
|
|
2742
|
-
function
|
|
2753
|
+
function hr(e) {
|
|
2743
2754
|
return { minX: e.x, minY: e.y, maxX: e.x, maxY: e.y };
|
|
2744
2755
|
}
|
|
2745
|
-
function
|
|
2756
|
+
function ct(e, t) {
|
|
2746
2757
|
return e.minX <= t.maxX && e.maxX >= t.minX && e.minY <= t.maxY && e.maxY >= t.minY;
|
|
2747
2758
|
}
|
|
2748
|
-
function
|
|
2759
|
+
function lr(e, t) {
|
|
2749
2760
|
return t.trueColorByteOrder !== void 0 && t.trueColorByteOrder !== e.trueColorByteOrder || t.contrastMode !== void 0 && t.contrastMode !== e.contrastMode || t.minColorContrast !== void 0 && t.minColorContrast !== e.minColorContrast || t.foreground !== void 0 && t.foreground !== e.foreground || t.background !== void 0 && t.background !== e.background || t.maxInsertDepth !== void 0 && t.maxInsertDepth !== e.maxInsertDepth || t.maxCurveSegments !== void 0 && t.maxCurveSegments !== e.maxCurveSegments || t.spatialIndexCellCount !== void 0 && t.spatialIndexCellCount !== e.spatialIndexCellCount || t.maxVerticesPerBatch !== void 0 && t.maxVerticesPerBatch !== e.maxVerticesPerBatch || t.enableSpatialIndex !== void 0 && t.enableSpatialIndex !== e.enableSpatialIndex;
|
|
2750
2761
|
}
|
|
2751
|
-
function
|
|
2762
|
+
function fr(e, t) {
|
|
2752
2763
|
return { ...e.stats, renderElapsedMs: t, backend: "webgl", primitiveCount: e.primitiveCount, visiblePrimitiveCount: 0, culledPrimitiveCount: 0, gpuMemoryBytes: e.gpuMemoryBytes, buildElapsedMs: e.buildElapsedMs };
|
|
2753
2764
|
}
|
|
2754
|
-
function
|
|
2765
|
+
function dr(e) {
|
|
2755
2766
|
return {
|
|
2756
2767
|
total: e.total,
|
|
2757
2768
|
drawn: e.drawn,
|
|
@@ -2767,7 +2778,7 @@ function ar(e) {
|
|
|
2767
2778
|
buildElapsedMs: e.buildElapsedMs
|
|
2768
2779
|
};
|
|
2769
2780
|
}
|
|
2770
|
-
function
|
|
2781
|
+
function mt(e, t, r = 1) {
|
|
2771
2782
|
const i = e.trim().toLowerCase();
|
|
2772
2783
|
let s;
|
|
2773
2784
|
if (/^#[0-9a-f]{3}$/i.test(i))
|
|
@@ -2787,7 +2798,7 @@ function ut(e, t, r = 1) {
|
|
|
2787
2798
|
function X(e) {
|
|
2788
2799
|
return Math.max(0, Math.min(255, Math.round(e)));
|
|
2789
2800
|
}
|
|
2790
|
-
class
|
|
2801
|
+
class ur {
|
|
2791
2802
|
constructor(t = {}) {
|
|
2792
2803
|
d(this, "canvas");
|
|
2793
2804
|
d(this, "renderer");
|
|
@@ -2797,7 +2808,7 @@ class cr {
|
|
|
2797
2808
|
d(this, "lastResult");
|
|
2798
2809
|
d(this, "activeNativeLoader");
|
|
2799
2810
|
var r;
|
|
2800
|
-
if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ??
|
|
2811
|
+
if (this.options = { autoFit: !0, ...t }, this.registry = t.registry ?? ze(t), t.loaders) for (const i of t.loaders) this.registry.register(i);
|
|
2801
2812
|
if (this.canvas = t.canvas ?? document.createElement("canvas"), this.canvas.classList.add("cad-viewer-canvas"), t.container)
|
|
2802
2813
|
t.container.classList.add("cad-viewer-container"), t.canvas || (this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", t.container.appendChild(this.canvas)), this.nativeHost = t.nativeHost ?? document.createElement("div"), this.nativeHost.classList.add("cad-viewer-native-host"), t.nativeHost || t.container.appendChild(this.nativeHost);
|
|
2803
2814
|
else if (t.nativeHost)
|
|
@@ -2807,7 +2818,7 @@ class cr {
|
|
|
2807
2818
|
const i = document.createElement("div");
|
|
2808
2819
|
i.classList.add("cad-viewer-native-host"), t.canvas.parentElement.appendChild(i), this.nativeHost = i;
|
|
2809
2820
|
}
|
|
2810
|
-
this.renderer =
|
|
2821
|
+
this.renderer = pr(t.renderer ?? "auto", this.canvas, t.canvasOptions), this.renderer.onStats = (i) => {
|
|
2811
2822
|
var s, n;
|
|
2812
2823
|
return (n = (s = this.options).onRenderStats) == null ? void 0 : n.call(s, i);
|
|
2813
2824
|
}, this.renderer.onViewChange = (i) => {
|
|
@@ -2902,14 +2913,14 @@ class cr {
|
|
|
2902
2913
|
var s, n;
|
|
2903
2914
|
try {
|
|
2904
2915
|
const o = this.mergeLoadOptions(r);
|
|
2905
|
-
|
|
2916
|
+
ht(o.signal);
|
|
2906
2917
|
const a = await this.registry.detect(t), c = { ...t, buffer: a.bytes };
|
|
2907
|
-
if (
|
|
2918
|
+
if (Ye(a.loader))
|
|
2908
2919
|
return await this.applyNativeLoadResult(a.loader, c, o, i);
|
|
2909
2920
|
const h = await a.loader.load(c, o);
|
|
2910
2921
|
return this.applyLoadResult(h, i);
|
|
2911
2922
|
} catch (o) {
|
|
2912
|
-
const a =
|
|
2923
|
+
const a = mr(o);
|
|
2913
2924
|
throw (n = (s = this.options).onError) == null || n.call(s, a), a;
|
|
2914
2925
|
}
|
|
2915
2926
|
}
|
|
@@ -2927,10 +2938,10 @@ class cr {
|
|
|
2927
2938
|
var n, o, a;
|
|
2928
2939
|
if (!this.nativeHost)
|
|
2929
2940
|
throw new Error("Native DWF rendering requires CadViewerOptions.container, nativeHost, or a canvas parent element.");
|
|
2930
|
-
|
|
2941
|
+
ht(i.signal), this.renderer.clear(), (n = this.activeNativeLoader) == null || n.unmount(), this.activeNativeLoader = t, this.canvas.style.display = "none", this.nativeHost.classList.add("is-active");
|
|
2931
2942
|
try {
|
|
2932
2943
|
const c = await t.mount(r, this.nativeHost, i);
|
|
2933
|
-
|
|
2944
|
+
ht(i.signal);
|
|
2934
2945
|
const h = {
|
|
2935
2946
|
...c,
|
|
2936
2947
|
fileName: s,
|
|
@@ -2979,48 +2990,48 @@ class cr {
|
|
|
2979
2990
|
};
|
|
2980
2991
|
}
|
|
2981
2992
|
}
|
|
2982
|
-
function
|
|
2983
|
-
return new
|
|
2993
|
+
function vr(e = {}) {
|
|
2994
|
+
return new ur(e);
|
|
2984
2995
|
}
|
|
2985
|
-
function
|
|
2996
|
+
function mr(e) {
|
|
2986
2997
|
return e instanceof Error ? e : new Error(String(e));
|
|
2987
2998
|
}
|
|
2988
|
-
function
|
|
2999
|
+
function ht(e) {
|
|
2989
3000
|
if (e != null && e.aborted)
|
|
2990
3001
|
throw new DOMException("Loading cancelled.", "AbortError");
|
|
2991
3002
|
}
|
|
2992
|
-
function
|
|
2993
|
-
if (e === "canvas2d") return new
|
|
2994
|
-
if (e === "webgl") return new
|
|
2995
|
-
if (
|
|
3003
|
+
function pr(e, t, r = {}) {
|
|
3004
|
+
if (e === "canvas2d") return new Bt(t, r);
|
|
3005
|
+
if (e === "webgl") return new Ft(t, r);
|
|
3006
|
+
if (Zt())
|
|
2996
3007
|
try {
|
|
2997
|
-
return new
|
|
3008
|
+
return new Ft(t, r);
|
|
2998
3009
|
} catch {
|
|
2999
3010
|
}
|
|
3000
|
-
return new
|
|
3011
|
+
return new Bt(t, r);
|
|
3001
3012
|
}
|
|
3002
3013
|
export {
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3014
|
+
Bt as CadCanvasRenderer,
|
|
3015
|
+
re as CadLoaderRegistry,
|
|
3016
|
+
ur as CadViewer,
|
|
3017
|
+
Ft as CadWebGLRenderer,
|
|
3018
|
+
Ee as DwfLoader,
|
|
3019
|
+
ce as DwgLoader,
|
|
3020
|
+
ie as DwgWorkerClient,
|
|
3021
|
+
me as DxfLoader,
|
|
3011
3022
|
N as colorFromAci,
|
|
3012
3023
|
U as colorFromTrueColor,
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3024
|
+
zt as createCadDocument,
|
|
3025
|
+
vr as createCadViewer,
|
|
3026
|
+
ze as createDefaultLoaderRegistry,
|
|
3027
|
+
A as detectCadFormat,
|
|
3017
3028
|
R as inferEntityKind,
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3029
|
+
Ye as isCadNativeRenderableLoader,
|
|
3030
|
+
Zt as isWebGLAvailable,
|
|
3031
|
+
fe as normalizeCadEntity,
|
|
3021
3032
|
_ as readInputBytes,
|
|
3022
3033
|
F as resolveCadColor,
|
|
3023
3034
|
j as summarizeCadDocument,
|
|
3024
|
-
|
|
3035
|
+
lt as supportsDwgWorker
|
|
3025
3036
|
};
|
|
3026
3037
|
//# sourceMappingURL=cad-viewer.es.js.map
|