@margoengine/ifc 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,871 @@
1
+ import { n as e, r as t } from "./data-CuTaQPFm.js";
2
+ import { t as n } from "./schema-B_VBQpdF.js";
3
+ import { LoaderError as r, crc32 as i, readZipDirectory as a, readZipEntry as o } from "@margoengine/loaders/common";
4
+ //#region ../shared/xml-document.js
5
+ var s = "http://www.w3.org/XML/1998/namespace", c = "http://www.w3.org/2000/xmlns/", l = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u{10000}-\\u{EFFFF}", u = `[${l}][${l}\\-.0-9\\u00B7\\u0300-\\u036F\\u203F\\u2040]*`, d = RegExp(`^${u}(?::${u})?$`, "u"), f = /[^\s/>=]+/y, p = /[ \t\r\n]*/y, m = /[^\t\n\r -퟿-�\u{10000}-\u{10FFFF}]/u, h = {
6
+ lt: "<",
7
+ gt: ">",
8
+ amp: "&",
9
+ quot: "\"",
10
+ apos: "'"
11
+ }, g = class {
12
+ constructor(e, t, n, r, i, a, o) {
13
+ this.nodeType = 1, this.tagName = e, this.prefix = t, this.localName = n, this.namespaceURI = r, this.attributes = i, this.parentElement = a, this.childNodes = [], this.children = [], this.start = o, this.contentStart = -1, this.end = -1;
14
+ }
15
+ get textContent() {
16
+ let e = "", t = [this];
17
+ for (; t.length;) {
18
+ let n = t.pop();
19
+ if (n.nodeType === 3 || n.nodeType === 4) e += n.data;
20
+ else if (n.nodeType === 1) for (let e = n.childNodes.length - 1; e >= 0; e--) t.push(n.childNodes[e]);
21
+ }
22
+ return e;
23
+ }
24
+ getAttribute(e) {
25
+ for (let t of this.attributes) if (t.name === e) return t.value;
26
+ return null;
27
+ }
28
+ getAttributeNS(e, t) {
29
+ let n = e || null;
30
+ for (let e of this.attributes) if (e.namespaceURI === n && e.localName === t) return e.value;
31
+ return null;
32
+ }
33
+ hasAttribute(e) {
34
+ return this.getAttribute(e) !== null;
35
+ }
36
+ }, _ = class {
37
+ constructor(e) {
38
+ this.documentElement = e;
39
+ }
40
+ *#e() {
41
+ let e = [this.documentElement];
42
+ for (; e.length;) {
43
+ let t = e.pop();
44
+ yield t;
45
+ for (let n = t.children.length - 1; n >= 0; n--) e.push(t.children[n]);
46
+ }
47
+ }
48
+ getElementById(e) {
49
+ for (let t of this.#e()) if (t.getAttributeNS(null, "id") === e) return t;
50
+ return null;
51
+ }
52
+ getElementsByTagNameNS(e, t) {
53
+ let n = e || null;
54
+ return [...this.#e()].filter((r) => (e === "*" || r.namespaceURI === n) && (t === "*" || r.localName === t));
55
+ }
56
+ };
57
+ function v(e, t = {}) {
58
+ let n = t.maxDepth ?? 512, r = t.maxElements ?? Infinity, i = (n, r) => {
59
+ let i = `${n} (line ${e.slice(0, r).split("\n").length})`;
60
+ throw t.fail && t.fail(i), TypeError(`Malformed XML: ${i}; supply a well-formed XML 1.0 document`);
61
+ };
62
+ typeof e != "string" && i("input is not a string", 0);
63
+ let a = m.exec(e);
64
+ a && i(`character U+${a[0].codePointAt(0).toString(16).toUpperCase()} is not allowed in XML`, a.index);
65
+ let o = (e, t) => e.indexOf("&") < 0 ? e : e.replace(/&([^;&]*)(;?)/g, (e, n, r) => {
66
+ if (r || i("unterminated entity or character reference", t), n[0] === "#") {
67
+ let r = /^#x[0-9A-Fa-f]+$/.test(n) ? Number.parseInt(n.slice(2), 16) : /^#[0-9]+$/.test(n) ? Number.parseInt(n.slice(1), 10) : NaN, a = r <= 1114111 ? String.fromCodePoint(r) : "";
68
+ return (!a || m.test(a) || r >= 55296 && r <= 57343) && i(`invalid character reference ${e}`, t), a;
69
+ }
70
+ return Object.hasOwn(h, n) || i(`undefined entity ${e}; only the five XML entities exist`, t), h[n];
71
+ }), l = (t) => (p.lastIndex = t, p.exec(e), p.lastIndex), u = (t) => {
72
+ f.lastIndex = t;
73
+ let n = f.exec(e)?.[0] ?? "";
74
+ return d.test(n) || i(`invalid element or attribute name "${n.slice(0, 40)}"`, t), n;
75
+ }, v = [Object.assign(Object.create(null), {
76
+ xml: s,
77
+ "": null
78
+ })], y = [], b = +(e.charCodeAt(0) === 65279), x = null, S = !1, C = 0, w = () => y[y.length - 1], T = (e, t, n = 3) => {
79
+ if (!y.length) {
80
+ (n === 4 || /[^ \t\r\n]/.test(e)) && i("text outside the root element", t);
81
+ return;
82
+ }
83
+ n === 3 && e.includes("]]>") && i("\"]]>\" in text", t);
84
+ let r = n === 3 ? o(e.replace(/\r\n?/g, "\n"), t) : e.replace(/\r\n?/g, "\n");
85
+ w().childNodes.push({
86
+ nodeType: n,
87
+ data: r,
88
+ textContent: r
89
+ });
90
+ };
91
+ for (; b < e.length;) {
92
+ let t = e.indexOf("<", b);
93
+ if (t < 0) {
94
+ T(e.slice(b), b);
95
+ break;
96
+ }
97
+ if (t > b && T(e.slice(b, t), b), e.startsWith("<!--", t)) {
98
+ let n = e.indexOf("-->", t + 4);
99
+ n < 0 && i("unterminated comment", t);
100
+ let r = e.slice(t + 4, n);
101
+ (r.includes("--") || r.endsWith("-")) && i("\"--\" inside a comment", t), y.length && w().childNodes.push({
102
+ nodeType: 8,
103
+ data: r,
104
+ textContent: r
105
+ }), b = n + 3;
106
+ } else if (e.startsWith("<![CDATA[", t)) {
107
+ let n = e.indexOf("]]>", t + 9);
108
+ n < 0 && i("unterminated CDATA section", t), T(e.slice(t + 9, n), t, 4), b = n + 3;
109
+ } else if (e.startsWith("<!DOCTYPE", t)) {
110
+ (S || x) && i("a document type declaration must come once, before the root element", t), S = !0;
111
+ let n = t + 9, r = "";
112
+ for (; n < e.length; n++) {
113
+ let a = e[n];
114
+ if (r) r = a === r ? "" : r;
115
+ else if (a === "\"" || a === "'") r = a;
116
+ else if (a === "[") i("DTD internal subsets (entity declarations) are not supported", t);
117
+ else if (a === ">") break;
118
+ }
119
+ n >= e.length && i("unterminated document type declaration", t), b = n + 1;
120
+ } else if (e[t + 1] === "?") {
121
+ let n = e.indexOf("?>", t + 2);
122
+ n < 0 && i("unterminated processing instruction", t);
123
+ let r = e.slice(t + 2, n), a = /^[^ \t\r\n]*/.exec(r)[0];
124
+ if ((!d.test(a) || a.includes(":")) && i("invalid processing instruction target", t), a.toLowerCase() === "xml") (a !== "xml" || t !== +(e.charCodeAt(0) === 65279)) && i("the XML declaration must start the document", t);
125
+ else if (y.length) {
126
+ let e = r.slice(a.length).replace(/^[ \t\r\n]+/, "");
127
+ w().childNodes.push({
128
+ nodeType: 7,
129
+ target: a,
130
+ data: e,
131
+ textContent: e
132
+ });
133
+ }
134
+ b = n + 2;
135
+ } else if (e[t + 1] === "/") {
136
+ let n = u(t + 2), r = l(t + 2 + n.length);
137
+ e[r] !== ">" && i(`malformed end tag </${n}>`, t);
138
+ let a = y.pop();
139
+ (!a || a.tagName !== n) && i(`end tag </${n}> does not match <${a ? a.tagName : "nothing"}>`, t), v.pop(), a.end = r + 1, b = r + 1;
140
+ } else {
141
+ x && !y.length && i("more than one root element", t);
142
+ let a = u(t + 1), d = [], f = t + 1 + a.length, p = !1;
143
+ for (;;) {
144
+ let n = l(f);
145
+ if (e.startsWith("/>", n)) {
146
+ p = !0, f = n + 2;
147
+ break;
148
+ }
149
+ if (e[n] === ">") {
150
+ f = n + 1;
151
+ break;
152
+ }
153
+ n >= e.length && i(`unterminated start tag <${a}>`, t), n === f && i(`attributes of <${a}> need white space between them`, n);
154
+ let r = u(n), s = l(n + r.length);
155
+ e[s] !== "=" && i(`attribute ${r} has no value`, n), s = l(s + 1);
156
+ let c = e[s];
157
+ c !== "\"" && c !== "'" && i(`attribute ${r} value is not quoted`, s);
158
+ let m = e.indexOf(c, s + 1);
159
+ m < 0 && i(`unterminated value of attribute ${r}`, s);
160
+ let h = e.slice(s + 1, m);
161
+ h.includes("<") && i(`"<" in the value of attribute ${r}`, s), d.some((e) => e.name === r) && i(`duplicate attribute ${r}`, n), d.push({
162
+ name: r,
163
+ value: o(h.replace(/\r\n|[\r\n\t]/g, " "), s)
164
+ }), f = m + 1;
165
+ }
166
+ let m = Object.create(v[v.length - 1]);
167
+ for (let { name: e, value: n } of d) if (e === "xmlns") (n === s || n === c) && i("the reserved XML namespaces cannot be the default", t), m[""] = n || null;
168
+ else if (e.startsWith("xmlns:")) {
169
+ let r = e.slice(6);
170
+ (r === "xmlns" || r === "xml" != (n === s) || n === c || !n) && i(`invalid namespace declaration ${e}`, t), m[r] = n;
171
+ }
172
+ let h = (e, n) => {
173
+ let r = e.indexOf(":");
174
+ if (r < 0) return [
175
+ null,
176
+ e,
177
+ n ? m[""] : null
178
+ ];
179
+ let a = e.slice(0, r), o = m[a];
180
+ return o || i(`namespace prefix ${a} is not declared`, t), [
181
+ a,
182
+ e.slice(r + 1),
183
+ o
184
+ ];
185
+ }, _ = d.map(({ name: e, value: t }) => {
186
+ let [n, r, i] = e === "xmlns" ? [
187
+ null,
188
+ "xmlns",
189
+ c
190
+ ] : e.startsWith("xmlns:") ? [
191
+ "xmlns",
192
+ e.slice(6),
193
+ c
194
+ ] : h(e, !1);
195
+ return {
196
+ name: e,
197
+ prefix: n,
198
+ localName: r,
199
+ namespaceURI: i,
200
+ value: t
201
+ };
202
+ });
203
+ for (let e = 0; e < _.length; e++) for (let n = 0; n < e; n++) _[e].namespaceURI === _[n].namespaceURI && _[e].localName === _[n].localName && i(`attributes ${_[n].name} and ${_[e].name} are the same name`, t);
204
+ let [S, T, E] = h(a, !0);
205
+ ++C > r && i(`more than ${r} elements`, t), y.length >= n && i(`elements nest deeper than ${n}`, t);
206
+ let D = new g(a, S, T, E, _, w() ?? null, t);
207
+ D.contentStart = f, y.length ? (w().childNodes.push(D), w().children.push(D)) : x = D, p ? D.end = f : (y.push(D), v.push(m)), b = f;
208
+ }
209
+ }
210
+ return y.length && i(`document ends inside <${w().tagName}>`, e.length), x || i("no root element", e.length), new _(x);
211
+ }
212
+ //#endregion
213
+ //#region ../shared/xml-escape.js
214
+ var y = (e) => String(e).replace(/[&<>"'\0-\x08\x0B\x0C\x0E-\x1F￾￿]|\p{Cs}/gu, (e) => ({
215
+ "&": "&amp;",
216
+ "<": "&lt;",
217
+ ">": "&gt;",
218
+ "\"": "&quot;",
219
+ "'": "&apos;"
220
+ })[e] ?? "�"), b = "BCF", x = (e, t) => {
221
+ throw new r(b, e, t);
222
+ }, S = (e) => {
223
+ e?.aborted && x("aborted", "aborted; pass a signal that is not aborted to read or write BCF");
224
+ }, C = (e, t) => e ? e.children.filter((e) => e.localName === t) : [], w = (e, t) => C(e, t)[0], T = (e, t) => w(e, t)?.textContent.trim() || void 0, E = (e, t) => e?.getAttribute(t) ?? void 0, D = (e, t) => e === void 0 ? t : e === "true" || e === "1", O = (e, t, n) => {
225
+ let r = Number(T(e, t));
226
+ return Number.isFinite(r) ? r : x("syntax", `${n} needs a finite ${t}; export the BCF again`);
227
+ }, k = (e, t) => e ? [
228
+ O(e, "X", t),
229
+ O(e, "Y", t),
230
+ O(e, "Z", t)
231
+ ] : x("syntax", `${t} is missing; export the BCF again`), A = (e) => {
232
+ let t = {}, n = E(e, "IfcGuid"), r = T(e, "OriginatingSystem"), i = T(e, "AuthoringToolId");
233
+ return n && (t.ifcGuid = n), r && (t.originatingSystem = r), i && (t.authoringToolId = i), t;
234
+ }, j = (e) => C(e, "Component").map(A), M = (e, t) => v(typeof e == "string" ? e : new TextDecoder().decode(e), { fail: (e) => x("syntax", `${t} is not well-formed XML (${e}); export the BCF again`) }).documentElement;
235
+ function N(e) {
236
+ let t = M(e, "The viewpoint");
237
+ t.localName !== "VisualizationInfo" && x("syntax", `a viewpoint starts with VisualizationInfo, not ${t.localName}`);
238
+ let n = w(t, "Components"), r = w(n, "Visibility"), i = w(r, "ViewSetupHints") ?? w(n, "ViewSetupHints"), a = {
239
+ guid: (E(t, "Guid") ?? "").toLowerCase(),
240
+ selection: j(w(n, "Selection")),
241
+ defaultVisibility: D(E(r, "DefaultVisibility"), !1),
242
+ exceptions: j(w(r, "Exceptions")),
243
+ spacesVisible: D(E(i, "SpacesVisible"), !1),
244
+ spaceBoundariesVisible: D(E(i, "SpaceBoundariesVisible"), !1),
245
+ openingsVisible: D(E(i, "OpeningsVisible"), !1),
246
+ coloring: C(w(n, "Coloring"), "Color").map((e) => ({
247
+ color: E(e, "Color") ?? x("syntax", "a Color needs its Color attribute; export the BCF again"),
248
+ components: j(w(e, "Components") ?? e)
249
+ })),
250
+ lines: C(w(t, "Lines"), "Line").map((e) => ({
251
+ start: k(w(e, "StartPoint"), "Line"),
252
+ end: k(w(e, "EndPoint"), "Line")
253
+ })),
254
+ clippingPlanes: C(w(t, "ClippingPlanes"), "ClippingPlane").map((e) => ({
255
+ location: k(w(e, "Location"), "ClippingPlane"),
256
+ direction: k(w(e, "Direction"), "ClippingPlane")
257
+ })),
258
+ bitmaps: [...C(w(t, "Bitmaps"), "Bitmap"), ...C(t, "Bitmap")].map((e) => ({
259
+ format: (T(e, "Format") ?? T(e, "Bitmap") ?? "").toLowerCase() === "jpg" ? "jpg" : "png",
260
+ reference: T(e, "Reference") ?? "",
261
+ location: k(w(e, "Location"), "Bitmap"),
262
+ normal: k(w(e, "Normal"), "Bitmap"),
263
+ up: k(w(e, "Up"), "Bitmap"),
264
+ height: O(e, "Height", "Bitmap")
265
+ }))
266
+ }, o = C(n, "Component");
267
+ if (o.length && !r) {
268
+ a.defaultVisibility = !0;
269
+ for (let e of o) {
270
+ let t = A(e);
271
+ D(E(e, "Selected"), !1) && a.selection.push(t), D(E(e, "Visible"), !0) || a.exceptions.push(t);
272
+ let n = E(e, "Color");
273
+ n && a.coloring.push({
274
+ color: n,
275
+ components: [t]
276
+ });
277
+ }
278
+ }
279
+ for (let e of ["Perspective", "Orthogonal"]) {
280
+ let n = w(t, `${e}Camera`);
281
+ if (!n || a.camera) continue;
282
+ let r = `${e}Camera`, i = T(n, "AspectRatio");
283
+ a.camera = {
284
+ type: e === "Perspective" ? "perspective" : "orthogonal",
285
+ position: k(w(n, "CameraViewPoint"), r),
286
+ direction: k(w(n, "CameraDirection"), r),
287
+ up: k(w(n, "CameraUpVector"), r),
288
+ aspectRatio: i === void 0 ? 1 : O(n, "AspectRatio", r)
289
+ }, e === "Perspective" ? a.camera.fieldOfView = O(n, "FieldOfView", r) : a.camera.viewToWorldScale = O(n, "ViewToWorldScale", r);
290
+ }
291
+ return a;
292
+ }
293
+ var P = (e, t = "", n = {}) => {
294
+ let r = Object.entries(n).filter(([, e]) => e !== void 0).map(([e, t]) => ` ${e}="${y(String(t))}"`).join("");
295
+ return t ? `<${e}${r}>${t}</${e}>` : `<${e}${r}/>`;
296
+ }, F = (e, t) => t === void 0 || t === "" ? "" : P(e, y(t)), I = (e, t) => ((t.length !== 3 || !t.every(Number.isFinite)) && x("range", `${e} needs three finite numbers`), P(e, P("X", String(t[0])) + P("Y", String(t[1])) + P("Z", String(t[2])))), L = (e) => P("Component", F("OriginatingSystem", e.originatingSystem) + F("AuthoringToolId", e.authoringToolId), { IfcGuid: e.ifcGuid }), R = (e) => e.map(L).join(""), z = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n", ee = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, B = (e, t) => {
297
+ ee.test(e) || x("range", `${t} GUID ${JSON.stringify(e)} must be a lower-case UUID; use newBCFGuid()`);
298
+ };
299
+ function V(e, t = {}) {
300
+ let n = (t.version ?? "3.0") === "3.0";
301
+ B(e.guid, "The viewpoint");
302
+ let r = e.camera;
303
+ n && !r && x("range", "a BCF 3.0 viewpoint needs a camera; set viewpoint.camera or write version 2.1");
304
+ let i = P("ViewSetupHints", "", {
305
+ SpacesVisible: e.spacesVisible,
306
+ SpaceBoundariesVisible: e.spaceBoundariesVisible,
307
+ OpeningsVisible: e.openingsVisible
308
+ }), a = P("Visibility", (n ? i : "") + (e.exceptions.length ? P("Exceptions", R(e.exceptions)) : ""), { DefaultVisibility: e.defaultVisibility }), o = e.coloring.filter((e) => e.components.length);
309
+ for (let e of o) /^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$/.test(e.color) || x("range", `colour ${JSON.stringify(e.color)} must be RRGGBB or AARRGGBB hex`);
310
+ let s = (n ? "" : i) + (e.selection.length ? P("Selection", R(e.selection)) : "") + a + (o.length ? P("Coloring", o.map((e) => P("Color", n ? P("Components", R(e.components)) : R(e.components), { Color: e.color.toUpperCase() })).join("")) : ""), c = "";
311
+ if (r) {
312
+ let e = r.type === "perspective", t = e ? r.fieldOfView : r.viewToWorldScale;
313
+ (e ? !(t > 0 && t < 180) : !(t > 0 && Number.isFinite(t))) && x("range", e ? "fieldOfView must be degrees in (0, 180)" : "viewToWorldScale must be a finite size above 0"), r.aspectRatio > 0 && Number.isFinite(r.aspectRatio) || x("range", "aspectRatio must be a finite width / height above 0"), c = P(e ? "PerspectiveCamera" : "OrthogonalCamera", I("CameraViewPoint", r.position) + I("CameraDirection", r.direction) + I("CameraUpVector", r.up) + P(e ? "FieldOfView" : "ViewToWorldScale", String(t)) + (n ? P("AspectRatio", String(r.aspectRatio)) : ""));
314
+ }
315
+ let l = (e) => P(n ? "Format" : "Bitmap", e.format) + P("Reference", y(e.reference)) + I("Location", e.location) + I("Normal", e.normal) + I("Up", e.up) + P("Height", String(e.height));
316
+ return z + P("VisualizationInfo", P("Components", s) + c + (e.lines.length ? P("Lines", e.lines.map((e) => P("Line", I("StartPoint", e.start) + I("EndPoint", e.end))).join("")) : "") + (e.clippingPlanes.length ? P("ClippingPlanes", e.clippingPlanes.map((e) => P("ClippingPlane", I("Location", e.location) + I("Direction", e.direction))).join("")) : "") + (n ? e.bitmaps.length ? P("Bitmaps", e.bitmaps.map((e) => P("Bitmap", l(e))).join("")) : "" : e.bitmaps.map((e) => P("Bitmap", l(e))).join("")), { Guid: e.guid });
317
+ }
318
+ var H = (e) => {
319
+ typeof e != "string" && x("syntax", "base64 data must be a string");
320
+ let t;
321
+ try {
322
+ t = atob(e);
323
+ } catch {
324
+ return x("syntax", "snapshot or bitmap data is not valid base64; encode the image bytes as base64");
325
+ }
326
+ return Uint8Array.from(t, (e) => e.charCodeAt(0));
327
+ }, U = (e) => {
328
+ let t = "";
329
+ for (let n = 0; n < e.length; n += 32768) t += String.fromCharCode(...e.subarray(n, n + 32768));
330
+ return btoa(t);
331
+ }, W = (e, t) => {
332
+ let n = [
333
+ Number(e?.x),
334
+ Number(e?.y),
335
+ Number(e?.z)
336
+ ];
337
+ return n.every(Number.isFinite) ? n : x("syntax", `${t} needs finite x, y and z`);
338
+ }, G = (e) => (Array.isArray(e) ? e : []).map((e) => {
339
+ let t = {};
340
+ return e?.ifc_guid && (t.ifcGuid = String(e.ifc_guid)), e?.originating_system && (t.originatingSystem = String(e.originating_system)), e?.authoring_tool_id && (t.authoringToolId = String(e.authoring_tool_id)), t;
341
+ }), K = (e) => String(e).toLowerCase() === "jpg" ? "jpg" : "png";
342
+ function te(e) {
343
+ (!e || typeof e != "object") && x("syntax", "a BCF-API viewpoint is a JSON object");
344
+ let t = e.components ?? {}, n = t.visibility ?? {}, r = n.view_setup_hints ?? {}, i = {
345
+ guid: String(e.guid ?? "").toLowerCase(),
346
+ selection: G(t.selection),
347
+ defaultVisibility: n.default_visibility === !0,
348
+ exceptions: G(n.exceptions),
349
+ spacesVisible: r.spaces_visible === !0,
350
+ spaceBoundariesVisible: r.space_boundaries_visible === !0,
351
+ openingsVisible: r.openings_visible === !0,
352
+ coloring: (Array.isArray(t.coloring) ? t.coloring : []).map((e) => ({
353
+ color: String(e?.color ?? ""),
354
+ components: G(e?.components)
355
+ })),
356
+ lines: (e.lines ?? []).map((e) => ({
357
+ start: W(e?.start_point, "line"),
358
+ end: W(e?.end_point, "line")
359
+ })),
360
+ clippingPlanes: (e.clipping_planes ?? []).map((e) => ({
361
+ location: W(e?.location, "clipping plane"),
362
+ direction: W(e?.direction, "clipping plane")
363
+ })),
364
+ bitmaps: (e.bitmaps ?? []).map((e, t) => ({
365
+ format: K(e?.bitmap_type),
366
+ reference: String(e?.reference ?? `bitmap${t}.${K(e?.bitmap_type)}`),
367
+ location: W(e?.location, "bitmap"),
368
+ normal: W(e?.normal, "bitmap"),
369
+ up: W(e?.up, "bitmap"),
370
+ height: Number(e?.height),
371
+ ...e?.bitmap_data ? { data: H(e.bitmap_data) } : {}
372
+ }))
373
+ };
374
+ Number.isInteger(e.index) && (i.index = e.index);
375
+ let a = e.perspective_camera, o = e.orthogonal_camera, s = a ?? o;
376
+ return s && (i.camera = {
377
+ type: a ? "perspective" : "orthogonal",
378
+ position: W(s.camera_view_point, "camera_view_point"),
379
+ direction: W(s.camera_direction, "camera_direction"),
380
+ up: W(s.camera_up_vector, "camera_up_vector"),
381
+ aspectRatio: Number.isFinite(s.aspect_ratio) ? s.aspect_ratio : 1
382
+ }, a ? i.camera.fieldOfView = Number(a.field_of_view) : i.camera.viewToWorldScale = Number(o.view_to_world_scale)), e.snapshot?.snapshot_data && (i.snapshot = {
383
+ format: K(e.snapshot.snapshot_type),
384
+ data: H(e.snapshot.snapshot_data)
385
+ }), i;
386
+ }
387
+ function ne(e) {
388
+ let t = (e) => ({
389
+ x: e[0],
390
+ y: e[1],
391
+ z: e[2]
392
+ }), n = (e) => e.map((e) => ({
393
+ ifc_guid: e.ifcGuid ?? null,
394
+ ...e.originatingSystem ? { originating_system: e.originatingSystem } : {},
395
+ ...e.authoringToolId ? { authoring_tool_id: e.authoringToolId } : {}
396
+ })), r = { guid: e.guid };
397
+ e.index !== void 0 && (r.index = e.index);
398
+ let i = e.camera;
399
+ if (i) {
400
+ let e = {
401
+ camera_view_point: t(i.position),
402
+ camera_direction: t(i.direction),
403
+ camera_up_vector: t(i.up),
404
+ aspect_ratio: i.aspectRatio
405
+ };
406
+ i.type === "perspective" ? r.perspective_camera = {
407
+ ...e,
408
+ field_of_view: i.fieldOfView
409
+ } : r.orthogonal_camera = {
410
+ ...e,
411
+ view_to_world_scale: i.viewToWorldScale
412
+ };
413
+ }
414
+ return r.lines = e.lines.map((e) => ({
415
+ start_point: t(e.start),
416
+ end_point: t(e.end)
417
+ })), r.clipping_planes = e.clippingPlanes.map((e) => ({
418
+ location: t(e.location),
419
+ direction: t(e.direction)
420
+ })), r.bitmaps = e.bitmaps.map((e) => ({
421
+ bitmap_type: e.format,
422
+ ...e.data ? { bitmap_data: U(e.data) } : {},
423
+ location: t(e.location),
424
+ normal: t(e.normal),
425
+ up: t(e.up),
426
+ height: e.height
427
+ })), e.snapshot && (r.snapshot = {
428
+ snapshot_type: e.snapshot.format,
429
+ snapshot_data: U(e.snapshot.data)
430
+ }), r.components = {
431
+ selection: n(e.selection),
432
+ coloring: e.coloring.map((e) => ({
433
+ color: e.color,
434
+ components: n(e.components)
435
+ })),
436
+ visibility: {
437
+ default_visibility: e.defaultVisibility,
438
+ exceptions: n(e.exceptions),
439
+ view_setup_hints: {
440
+ spaces_visible: e.spacesVisible,
441
+ space_boundaries_visible: e.spaceBoundariesVisible,
442
+ openings_visible: e.openingsVisible
443
+ }
444
+ }
445
+ }, r;
446
+ }
447
+ function q() {
448
+ let e = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
449
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
450
+ let t = [...e].map((e) => e.toString(16).padStart(2, "0")).join("");
451
+ return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
452
+ }
453
+ var J = [
454
+ [
455
+ "topicTypes",
456
+ "TopicTypes",
457
+ "TopicType"
458
+ ],
459
+ [
460
+ "topicStatuses",
461
+ "TopicStatuses",
462
+ "TopicStatus"
463
+ ],
464
+ [
465
+ "priorities",
466
+ "Priorities",
467
+ "Priority"
468
+ ],
469
+ [
470
+ "topicLabels",
471
+ "TopicLabels",
472
+ "TopicLabel"
473
+ ],
474
+ [
475
+ "users",
476
+ "Users",
477
+ "User"
478
+ ],
479
+ [
480
+ "snippetTypes",
481
+ "SnippetTypes",
482
+ "SnippetType"
483
+ ],
484
+ [
485
+ "stages",
486
+ "Stages",
487
+ "Stage"
488
+ ]
489
+ ], Y = (e) => e.map((e) => e.textContent.trim()).filter(Boolean);
490
+ function re(e) {
491
+ let t = w(e, "Topic") ?? x("syntax", "markup.bcf has no Topic; export the BCF again"), n = (e) => T(t, e) ?? x("syntax", `the topic has no ${e}; export the BCF again`), r = {
492
+ guid: (E(t, "Guid") ?? "").toLowerCase(),
493
+ type: E(t, "TopicType") ?? "",
494
+ status: E(t, "TopicStatus") ?? "",
495
+ title: n("Title"),
496
+ labels: Y([...C(w(t, "Labels"), "Label"), ...C(t, "Labels").filter((e) => !e.children.length)]),
497
+ referenceLinks: Y([...C(w(t, "ReferenceLinks"), "ReferenceLink"), ...C(t, "ReferenceLink")]),
498
+ creationDate: n("CreationDate"),
499
+ creationAuthor: n("CreationAuthor"),
500
+ files: C(w(w(e, "Header"), "Files"), "File").concat(C(w(e, "Header"), "File")).map((e) => {
501
+ let t = { isExternal: D(E(e, "IsExternal") ?? E(e, "isExternal"), !0) };
502
+ for (let [n, r] of [
503
+ ["filename", "Filename"],
504
+ ["date", "Date"],
505
+ ["reference", "Reference"]
506
+ ]) {
507
+ let i = T(e, r);
508
+ i && (t[n] = i);
509
+ }
510
+ let n = E(e, "IfcProject"), r = E(e, "IfcSpatialStructureElement");
511
+ return n && (t.ifcProject = n), r && (t.ifcSpatialStructureElement = r), t;
512
+ }),
513
+ documentReferences: [...C(w(t, "DocumentReferences"), "DocumentReference"), ...C(t, "DocumentReference")].map((e) => {
514
+ let t = {}, n = E(e, "Guid"), r = T(e, "DocumentGuid"), i = T(e, "Url") ?? T(e, "ReferencedDocument"), a = T(e, "Description");
515
+ return n && (t.guid = n.toLowerCase()), r && (t.documentGuid = r.toLowerCase()), i && (t.url = i), a && (t.description = a), t;
516
+ }),
517
+ relatedTopics: [...C(w(t, "RelatedTopics"), "RelatedTopic"), ...C(t, "RelatedTopic")].map((e) => (E(e, "Guid") ?? "").toLowerCase()).filter(Boolean),
518
+ comments: [...C(w(t, "Comments"), "Comment"), ...C(e, "Comment")].map((e) => {
519
+ let t = {
520
+ guid: (E(e, "Guid") ?? "").toLowerCase(),
521
+ date: T(e, "Date") ?? x("syntax", "a comment has no Date; export the BCF again"),
522
+ author: T(e, "Author") ?? x("syntax", "a comment has no Author; export the BCF again")
523
+ }, n = T(e, "Comment"), r = E(w(e, "Viewpoint"), "Guid"), i = T(e, "ModifiedDate"), a = T(e, "ModifiedAuthor");
524
+ return n && (t.comment = n), r && (t.viewpoint = r.toLowerCase()), i && (t.modifiedDate = i), a && (t.modifiedAuthor = a), t;
525
+ }),
526
+ refs: [...C(w(t, "Viewpoints"), "ViewPoint"), ...C(e, "Viewpoints")].map((e) => {
527
+ let t = Number(T(e, "Index"));
528
+ return {
529
+ guid: (E(e, "Guid") ?? "").toLowerCase(),
530
+ file: T(e, "Viewpoint"),
531
+ snapshot: T(e, "Snapshot"),
532
+ ...Number.isInteger(t) && T(e, "Index") !== void 0 ? { index: t } : {}
533
+ };
534
+ })
535
+ };
536
+ for (let e of [
537
+ "Priority",
538
+ "ModifiedDate",
539
+ "ModifiedAuthor",
540
+ "DueDate",
541
+ "AssignedTo",
542
+ "Stage",
543
+ "Description"
544
+ ]) {
545
+ let n = T(t, e);
546
+ n && (r[e[0].toLowerCase() + e.slice(1)] = n);
547
+ }
548
+ let i = Number(T(t, "Index"));
549
+ T(t, "Index") !== void 0 && Number.isInteger(i) && (r.index = i);
550
+ let a = E(t, "ServerAssignedId");
551
+ a && (r.serverAssignedId = a);
552
+ let o = w(t, "BimSnippet");
553
+ return o && (r.bimSnippet = {
554
+ type: E(o, "SnippetType") ?? "",
555
+ reference: T(o, "Reference") ?? "",
556
+ referenceSchema: T(o, "ReferenceSchema") ?? "",
557
+ isExternal: D(E(o, "IsExternal") ?? E(o, "isExternal"), !1)
558
+ }), r;
559
+ }
560
+ async function ie(e, t = {}) {
561
+ S(t.signal);
562
+ let n = a(e, t), r = new Map(n.map((e) => [e.name, e])), i = async (n) => {
563
+ let i = r.get(n);
564
+ return i ? o(e, i, t) : void 0;
565
+ }, s = async (e) => {
566
+ let t = await i(e);
567
+ return t ? M(t, e) : void 0;
568
+ }, c = {
569
+ version: E(await s("bcf.version"), "VersionId") ?? "1.0",
570
+ documents: [],
571
+ topics: []
572
+ }, l = w(await s("project.bcfp"), "Project");
573
+ l && (c.project = {
574
+ id: E(l, "ProjectId") ?? "",
575
+ ...T(l, "Name") ? { name: T(l, "Name") } : {}
576
+ });
577
+ let u = await s("extensions.xml");
578
+ if (u?.localName === "Extensions") {
579
+ c.extensions = {};
580
+ for (let [e, t, n] of J) c.extensions[e] = Y(C(w(u, t), n));
581
+ }
582
+ for (let e of C(w(await s("documents.xml"), "Documents"), "Document")) {
583
+ let t = (E(e, "Guid") ?? "").toLowerCase(), n = await i(`Documents/${t}`), r = T(e, "Description");
584
+ c.documents.push({
585
+ guid: t,
586
+ filename: T(e, "Filename") ?? t,
587
+ ...r ? { description: r } : {},
588
+ ...n ? { data: n } : {}
589
+ });
590
+ }
591
+ for (let a of n) {
592
+ let n = /^([^/]+)\/markup\.bcf$/i.exec(a.name);
593
+ if (!n) continue;
594
+ S(t.signal);
595
+ let s = n[1], { refs: l, ...u } = re(M(await o(e, a, t), a.name));
596
+ !l.length && r.has(`${s}/viewpoint.bcfv`) && l.push({
597
+ guid: "",
598
+ file: "viewpoint.bcfv",
599
+ ...r.has(`${s}/snapshot.png`) ? { snapshot: "snapshot.png" } : {}
600
+ });
601
+ let d = [];
602
+ for (let e of l) {
603
+ let t = e.file ? await i(`${s}/${e.file}`) : void 0;
604
+ if (!t) continue;
605
+ let n = N(t);
606
+ e.guid && (n.guid = e.guid), e.index !== void 0 && (n.index = e.index);
607
+ let r = e.snapshot ? await i(`${s}/${e.snapshot}`) : void 0;
608
+ r && (n.snapshot = {
609
+ format: /\.jpe?g$/i.test(e.snapshot) ? "jpg" : "png",
610
+ data: r
611
+ });
612
+ for (let e of n.bitmaps) {
613
+ let t = await i(`${s}/${e.reference}`);
614
+ t && (e.data = t);
615
+ }
616
+ d.push(n);
617
+ }
618
+ if (d.sort((e, t) => (e.index ?? Infinity) - (t.index ?? Infinity)), u.bimSnippet && !u.bimSnippet.isExternal) {
619
+ let e = await i(`${s}/${u.bimSnippet.reference}`);
620
+ e && (u.bimSnippet.data = e);
621
+ }
622
+ c.topics.push({
623
+ ...u,
624
+ guid: u.guid || s.toLowerCase(),
625
+ viewpoints: d
626
+ });
627
+ }
628
+ return c;
629
+ }
630
+ function ae(e) {
631
+ let t = new TextEncoder(), n = /* @__PURE__ */ new Set();
632
+ for (let [t] of e) for (let e = t.indexOf("/"); e > 0; e = t.indexOf("/", e + 1)) n.add(t.slice(0, e + 1));
633
+ let r = [...[...n].map((e) => [e, /* @__PURE__ */ new Uint8Array()]), ...e].map(([e, n]) => [t.encode(e), n]), a = 22;
634
+ for (let [e, t] of r) a += 76 + 2 * e.length + t.length;
635
+ let o = new Uint8Array(a), s = new DataView(o.buffer), c = 0, l = [], u = (e, t, n, r, i) => {
636
+ s.setUint32(c, e, !0);
637
+ let a = c + 4;
638
+ i !== void 0 && (s.setUint16(a, 20, !0), a += 2), s.setUint16(a, t[t.length - 1] === 47 ? 20 : 10, !0), s.setUint16(a + 2, 2048, !0), s.setUint16(a + 4, 0, !0), s.setUint32(a + 6, 2162688, !0), s.setUint32(a + 10, r, !0), s.setUint32(a + 14, n.length, !0), s.setUint32(a + 18, n.length, !0), s.setUint16(a + 22, t.length, !0), a += 26, i !== void 0 && (s.setUint32(a + 6, t[t.length - 1] === 47 ? 16 : 0, !0), s.setUint32(a + 10, i, !0), a += 14), o.set(t, a), c = a + t.length;
639
+ };
640
+ for (let [e, t] of r) l.push(c), u(67324752, e, t, i(t)), o.set(t, c), c += t.length;
641
+ let d = c;
642
+ return r.forEach(([e, t], n) => u(33639248, e, t, i(t), l[n])), s.setUint32(c, 101010256, !0), s.setUint16(c + 8, r.length, !0), s.setUint16(c + 10, r.length, !0), s.setUint32(c + 12, c - d, !0), s.setUint32(c + 16, d, !0), o;
643
+ }
644
+ function oe(e, t = {}) {
645
+ let n = t.version ?? "3.0", r = n === "3.0", i = new TextEncoder(), a = [], o = (e, t) => a.push([e, typeof t == "string" ? i.encode(t) : t]);
646
+ if (o("bcf.version", z + P("Version", r ? "" : P("DetailedVersion", n), { VersionId: n })), e.project) {
647
+ let t = P("Project", F("Name", e.project.name), { ProjectId: e.project.id });
648
+ o("project.bcfp", z + (r ? P("ProjectInfo", t) : P("ProjectExtension", t + P("ExtensionSchema", ""))));
649
+ }
650
+ if (r && (e.extensions && o("extensions.xml", z + P("Extensions", J.map(([t, n, r]) => {
651
+ let i = e.extensions[t] ?? [];
652
+ return i.length ? P(n, i.map((e) => P(r, y(e))).join("")) : "";
653
+ }).join(""))), e.documents?.length)) {
654
+ o("documents.xml", z + P("DocumentInfo", P("Documents", e.documents.map((e) => (B(e.guid, "A document"), P("Document", F("Filename", e.filename) + F("Description", e.description), { Guid: e.guid }))).join(""))));
655
+ for (let t of e.documents) t.data && o(`Documents/${t.guid}`, t.data);
656
+ }
657
+ for (let n of e.topics) {
658
+ B(n.guid, "The topic"), n.title || x("range", "every topic needs a title");
659
+ let e = n.guid, i = n.viewpoints.map((n) => {
660
+ let r = `${n.guid}.bcfv`;
661
+ o(`${e}/${r}`, V(n, t));
662
+ let i = n.snapshot ? `${n.guid}.${n.snapshot.format === "jpg" ? "jpg" : "png"}` : void 0;
663
+ n.snapshot && o(`${e}/${i}`, n.snapshot.data);
664
+ for (let t of n.bitmaps) t.data && o(`${e}/${t.reference}`, t.data);
665
+ return P("Viewpoint", y(r)) + (i ? P("Snapshot", i) : "") + F("Index", n.index);
666
+ }), a = (e) => (B(e.guid, "A comment"), P("Comment", F("Date", e.date) + F("Author", e.author) + (r ? F("Comment", e.comment) : P("Comment", y(e.comment ?? ""))) + (e.viewpoint ? P("Viewpoint", "", { Guid: e.viewpoint }) : "") + F("ModifiedDate", e.modifiedDate) + F("ModifiedAuthor", e.modifiedAuthor), { Guid: e.guid })), s = (e) => P("File", F("Filename", e.filename) + F("Date", e.date) + F("Reference", e.reference), {
667
+ IfcProject: e.ifcProject,
668
+ IfcSpatialStructureElement: e.ifcSpatialStructureElement,
669
+ IsExternal: e.isExternal
670
+ }), c = n.files.length ? P("Header", r ? P("Files", n.files.map(s).join("")) : n.files.map(s).join("")) : "", l = (e, t) => t.length ? r ? P(e, t.join("")) : t.join("") : "", u = n.documentReferences.map((e) => r ? P("DocumentReference", (e.documentGuid ? F("DocumentGuid", e.documentGuid) : F("Url", e.url)) + F("Description", e.description), { Guid: e.guid ?? q() }) : P("DocumentReference", F("ReferencedDocument", e.url ?? e.documentGuid) + F("Description", e.description), {
671
+ Guid: e.guid,
672
+ isExternal: e.url !== void 0 && /^[a-z][a-z0-9+.-]*:/i.test(e.url)
673
+ })), d = n.bimSnippet;
674
+ d?.data && !d.isExternal && o(`${e}/${d.reference}`, d.data);
675
+ let f = P("Topic", l("ReferenceLinks", n.referenceLinks.map((e) => P("ReferenceLink", y(e)))) + P("Title", y(n.title)) + F("Priority", n.priority) + F("Index", n.index) + (r ? n.labels.length ? P("Labels", n.labels.map((e) => P("Label", y(e))).join("")) : "" : n.labels.map((e) => P("Labels", y(e))).join("")) + F("CreationDate", n.creationDate) + F("CreationAuthor", n.creationAuthor) + F("ModifiedDate", n.modifiedDate) + F("ModifiedAuthor", n.modifiedAuthor) + F("DueDate", n.dueDate) + F("AssignedTo", n.assignedTo) + F("Stage", n.stage) + F("Description", n.description) + (d ? P("BimSnippet", F("Reference", d.reference) + F("ReferenceSchema", d.referenceSchema), {
676
+ SnippetType: d.type,
677
+ [r ? "IsExternal" : "isExternal"]: d.isExternal
678
+ }) : "") + l("DocumentReferences", u) + l("RelatedTopics", n.relatedTopics.map((e) => P("RelatedTopic", "", { Guid: e }))) + (r ? l("Comments", n.comments.map(a)) + l("Viewpoints", n.viewpoints.map((e, t) => P("ViewPoint", i[t], { Guid: e.guid }))) : ""), {
679
+ Guid: n.guid,
680
+ ...r && n.serverAssignedId ? { ServerAssignedId: n.serverAssignedId } : {},
681
+ TopicType: n.type,
682
+ TopicStatus: n.status
683
+ });
684
+ o(`${e}/markup.bcf`, z + P("Markup", c + f + (r ? "" : n.comments.map(a).join("") + n.viewpoints.map((e, t) => P("Viewpoints", i[t], { Guid: e.guid })).join(""))));
685
+ }
686
+ return ae(a);
687
+ }
688
+ var X = ([e, t, n]) => Q([
689
+ e,
690
+ n,
691
+ -t
692
+ ]), Z = ([e, t, n]) => Q([
693
+ e,
694
+ -n,
695
+ t
696
+ ]);
697
+ function Q(e) {
698
+ let t = Math.hypot(...e);
699
+ return t > 0 && Number.isFinite(t) ? [
700
+ e[0] / t,
701
+ e[1] / t,
702
+ e[2] / t
703
+ ] : x("range", "a direction must be a finite vector longer than 0");
704
+ }
705
+ function se(e) {
706
+ let t = /* @__PURE__ */ new Map();
707
+ for (let r of e.elements.values()) {
708
+ let i = r.aggregate ?? r.nest, a = i === void 0 ? void 0 : e.elements.get(i)?.type;
709
+ a === void 0 || n(e, a, "IfcSpatialStructureElement") || n(e, a, "IfcSpatialElement") || (t.get(i) ?? t.set(i, []).get(i)).push(r.id);
710
+ }
711
+ return t;
712
+ }
713
+ var $ = (e) => [...e.elements.values()].filter((t) => n(e, t.type, "IfcProduct")).sort((e, t) => e.id - t.id);
714
+ function ce(e, r, i = {}) {
715
+ let a = i.origin ?? [
716
+ 0,
717
+ 0,
718
+ 0
719
+ ], o = i.targetDistance ?? 10, s = se(r), c = [], l = /* @__PURE__ */ new Map();
720
+ for (let e of r.elements.values()) e.tag && l.set(e.tag, e.id);
721
+ let u = (e) => {
722
+ let t = /* @__PURE__ */ new Set();
723
+ for (let n of e) {
724
+ let e = n.ifcGuid && r.byGlobalId.get(n.ifcGuid) || (n.authoringToolId ? l.get(n.authoringToolId) : void 0);
725
+ if (e === void 0) c.push(n);
726
+ else for (let n = [e]; n.length;) {
727
+ let e = n.pop();
728
+ t.has(e) || (t.add(e), n.push(...s.get(e) ?? []));
729
+ }
730
+ }
731
+ return t;
732
+ }, d = u(e.exceptions), f = [], p = [];
733
+ for (let t of $(r)) {
734
+ let i = e.defaultVisibility;
735
+ n(r, t.type, "IfcSpace") ? i = e.spacesVisible : n(r, t.type, "IfcOpeningElement") && (i = e.openingsVisible), d.has(t.id) && (i = !i), (i ? f : p).push(t.id);
736
+ }
737
+ let m = /* @__PURE__ */ new Map();
738
+ for (let t of e.coloring) {
739
+ let e = t.color;
740
+ /^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$/.test(e) || x("range", `colour ${JSON.stringify(e)} must be RRGGBB or AARRGGBB hex`);
741
+ let n = (t) => parseInt(e.slice(t, t + 2), 16) / 255, r = e.length === 8, i = [
742
+ n(r ? 2 : 0),
743
+ n(r ? 4 : 2),
744
+ n(r ? 6 : 4),
745
+ r ? n(0) : 1
746
+ ];
747
+ for (let e of u(t.components)) m.set(e, i);
748
+ }
749
+ let h = {
750
+ visible: f,
751
+ hidden: p,
752
+ selected: [...u(e.selection)].sort((e, t) => e - t),
753
+ colors: m,
754
+ clippingPlanes: e.clippingPlanes.map(({ location: e, direction: n }) => {
755
+ let r = X(n).map((e) => -e), i = t(e, a);
756
+ return [
757
+ r[0],
758
+ r[1],
759
+ r[2],
760
+ -(r[0] * i[0] + r[1] * i[1] + r[2] * i[2])
761
+ ];
762
+ }),
763
+ lines: e.lines.map((e) => ({
764
+ start: t(e.start, a),
765
+ end: t(e.end, a)
766
+ })),
767
+ unresolved: c
768
+ }, g = e.camera;
769
+ if (g) {
770
+ let e = t(g.position, a), n = X(g.direction);
771
+ h.camera = {
772
+ type: g.type,
773
+ position: e,
774
+ target: [
775
+ e[0] + n[0] * o,
776
+ e[1] + n[1] * o,
777
+ e[2] + n[2] * o
778
+ ],
779
+ direction: n,
780
+ up: X(g.up),
781
+ aspect: g.aspectRatio,
782
+ ...g.type === "perspective" ? { fov: g.fieldOfView } : { height: g.viewToWorldScale }
783
+ };
784
+ }
785
+ return h;
786
+ }
787
+ function le(t, r, i = {}) {
788
+ let a = i.origin ?? [
789
+ 0,
790
+ 0,
791
+ 0
792
+ ], o = (e) => {
793
+ let t = r.elements.get(e)?.globalId;
794
+ return t ? { ifcGuid: t } : x("range", `element ${e} has no GlobalId in this model; pass expressIDs of its elements`);
795
+ }, s = new Set(t.hidden ?? []), c = $(r), l = (e) => n(r, e.type, "IfcSpace"), u = (e) => n(r, e.type, "IfcOpeningElement"), d = c.some((e) => l(e) && !s.has(e.id)), f = c.some((e) => u(e) && !s.has(e.id)), p = c.filter((e) => !(l(e) && !d || u(e) && !f)), m = p.filter((e) => !s.has(e.id)), h = p.filter((e) => s.has(e.id)), g = h.length < m.length, _ = /* @__PURE__ */ new Map();
796
+ for (let [e, n] of t.colors ?? []) {
797
+ (n.length < 3 || !n.every((e) => e >= 0 && e <= 1)) && x("range", `the colour of element ${e} needs 3 or 4 numbers from 0 to 1`);
798
+ let t = (e) => Math.round(e * 255).toString(16).padStart(2, "0").toUpperCase(), r = (n[3] !== void 0 && n[3] < 1 ? t(n[3]) : "") + t(n[0]) + t(n[1]) + t(n[2]);
799
+ (_.get(r) ?? _.set(r, []).get(r)).push(e);
800
+ }
801
+ let v = {
802
+ guid: t.guid ?? q(),
803
+ selection: [...t.selected ?? []].map(o),
804
+ defaultVisibility: g,
805
+ exceptions: (g ? h : m).map((e) => o(e.id)),
806
+ spacesVisible: d && g,
807
+ spaceBoundariesVisible: !1,
808
+ openingsVisible: f && g,
809
+ coloring: [..._].map(([e, t]) => ({
810
+ color: e,
811
+ components: t.map(o)
812
+ })),
813
+ lines: (t.lines ?? []).map((t) => ({
814
+ start: e(t.start, a),
815
+ end: e(t.end, a)
816
+ })),
817
+ clippingPlanes: (t.clippingPlanes ?? []).map((t) => {
818
+ let [n, r, i, o] = t, s = n * n + r * r + i * i;
819
+ (t.length !== 4 || !t.every(Number.isFinite) || !(s > 0)) && x("range", "a clipping plane is four finite numbers [a, b, c, d] with a nonzero normal");
820
+ let c = [
821
+ -o * n / s,
822
+ -o * r / s,
823
+ -o * i / s
824
+ ];
825
+ return {
826
+ location: e(c, a),
827
+ direction: Z([
828
+ -n,
829
+ -r,
830
+ -i
831
+ ])
832
+ };
833
+ }),
834
+ bitmaps: []
835
+ };
836
+ t.snapshot && (v.snapshot = t.snapshot);
837
+ let y = t.camera;
838
+ if (y) {
839
+ let t = y.direction ?? (y.target ? y.target.map((e, t) => e - y.position[t]) : x("range", "the camera needs a target or a direction")), n = y.type ?? "perspective", r = Q(t), i = [...y.up ?? [
840
+ 0,
841
+ 1,
842
+ 0
843
+ ]];
844
+ for (let e of [i, [
845
+ 0,
846
+ 0,
847
+ -1
848
+ ]]) {
849
+ let t = e[0] * r[0] + e[1] * r[1] + e[2] * r[2], n = [
850
+ e[0] - t * r[0],
851
+ e[1] - t * r[1],
852
+ e[2] - t * r[2]
853
+ ];
854
+ if (Math.hypot(...n) > 1e-6) {
855
+ i = n;
856
+ break;
857
+ }
858
+ }
859
+ v.camera = {
860
+ type: n,
861
+ position: e(y.position, a),
862
+ direction: Z(r),
863
+ up: Z(i),
864
+ aspectRatio: y.aspect ?? 1,
865
+ ...n === "perspective" ? { fieldOfView: y.fov ?? 60 } : { viewToWorldScale: y.height ?? x("range", "an orthogonal camera needs its height") }
866
+ };
867
+ }
868
+ return v;
869
+ }
870
+ //#endregion
871
+ export { ce as a, oe as c, ie as i, V as l, q as n, te as o, N as r, ne as s, le as t, v as u };