@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.
package/dist/ids.js ADDED
@@ -0,0 +1,759 @@
1
+ import { a as e, n as t, r as n, t as r } from "./open-D1NQyRTk.js";
2
+ import { n as i, u as a } from "./bcf-wKfMzfyy.js";
3
+ import { l as o } from "./data-CuTaQPFm.js";
4
+ import { i as s, o as c } from "./units-B32iYdmV.js";
5
+ import { t as l } from "./tolerance-CAOnp3Mo.js";
6
+ import { LoaderError as u } from "@margoengine/loaders/common";
7
+ //#region src/ids.ts
8
+ var d = "http://standards.buildingsmart.org/IDS", f = "http://www.w3.org/2001/XMLSchema", p = (e, t) => {
9
+ throw new u("IDS", e, t);
10
+ }, m = (e, t, n = d) => e.children.filter((e) => e.localName === t && e.namespaceURI === n), h = (e, t) => m(e, t)[0], g = (e) => e ? e.textContent : void 0;
11
+ function _(e, t) {
12
+ if (!e) return;
13
+ let n = h(e, "simpleValue");
14
+ if (n) return { simpleValue: n.textContent };
15
+ let r = m(e, "restriction", f)[0];
16
+ if (!r) return p("syntax", `${t} needs a simpleValue or an xs:restriction; add one`);
17
+ let i = { base: r.getAttribute("base") ?? "xs:string" };
18
+ for (let e of r.children) {
19
+ if (e.namespaceURI !== f) continue;
20
+ let n = e.getAttribute("value");
21
+ if (n === null) {
22
+ if (e.localName === "annotation") continue;
23
+ return p("syntax", `${t}: xs:${e.localName} needs a value attribute; add one`);
24
+ }
25
+ let r = e.localName;
26
+ if (r === "enumeration" || r === "pattern") (i[r] ??= []).push(n);
27
+ else if (r === "minInclusive" || r === "maxInclusive" || r === "minExclusive" || r === "maxExclusive") i[r] = n;
28
+ else if (r === "length" || r === "minLength" || r === "maxLength") {
29
+ let e = Number(n);
30
+ if (!Number.isInteger(e) || e < 0) return p("syntax", `${t}: xs:${r} must be a non-negative integer; fix the value`);
31
+ i[r] = e;
32
+ } else if (r !== "annotation" && r !== "totalDigits" && r !== "fractionDigits" && r !== "whiteSpace") return p("syntax", `${t}: xs:${r} is not an IDS restriction; use enumeration, pattern, bounds or lengths`);
33
+ }
34
+ return { restriction: i };
35
+ }
36
+ function v(e, t) {
37
+ return e === void 0 && p("syntax", `${t} is missing; add it as ids.xsd requires`), e;
38
+ }
39
+ function y(e) {
40
+ let t = {
41
+ facet: "entity",
42
+ name: v(_(h(e, "name"), "entity name"), "entity name")
43
+ }, n = _(h(e, "predefinedType"), "entity predefinedType");
44
+ return n && (t.predefinedType = n), t;
45
+ }
46
+ var b = [
47
+ "IFCRELAGGREGATES",
48
+ "IFCRELASSIGNSTOGROUP",
49
+ "IFCRELCONTAINEDINSPATIALSTRUCTURE",
50
+ "IFCRELNESTS",
51
+ "IFCRELVOIDSELEMENT IFCRELFILLSELEMENT"
52
+ ];
53
+ function x(e) {
54
+ let t = (e, t, n) => (n != null && (e[t] = n), e);
55
+ switch (e.localName) {
56
+ case "entity": return y(e);
57
+ case "attribute": return t({
58
+ facet: "attribute",
59
+ name: v(_(h(e, "name"), "attribute name"), "attribute name")
60
+ }, "value", _(h(e, "value"), "attribute value"));
61
+ case "classification": {
62
+ let n = { facet: "classification" };
63
+ return t(n, "value", _(h(e, "value"), "classification value")), t(n, "system", _(h(e, "system"), "classification system")), t(n, "uri", e.getAttribute("uri"));
64
+ }
65
+ case "property": {
66
+ let n = {
67
+ facet: "property",
68
+ propertySet: v(_(h(e, "propertySet"), "property propertySet"), "property propertySet"),
69
+ baseName: v(_(h(e, "baseName"), "property baseName"), "property baseName")
70
+ };
71
+ return t(n, "value", _(h(e, "value"), "property value")), t(n, "dataType", e.getAttribute("dataType")), t(n, "uri", e.getAttribute("uri"));
72
+ }
73
+ case "material": {
74
+ let n = { facet: "material" };
75
+ return t(n, "value", _(h(e, "value"), "material value")), t(n, "uri", e.getAttribute("uri"));
76
+ }
77
+ case "partOf": {
78
+ let t = {
79
+ facet: "partOf",
80
+ entity: y(v(h(e, "entity"), "partOf entity"))
81
+ }, n = e.getAttribute("relation");
82
+ return n !== null && (b.includes(n) || p("syntax", `partOf relation ${n} is not an IDS 1.0 relation; use one of ${b.join(", ")}`), t.relation = n), t;
83
+ }
84
+ }
85
+ }
86
+ var S = (e, t) => {
87
+ if (e === null) return t;
88
+ if (e === "unbounded") return e;
89
+ let n = Number(e);
90
+ return (!Number.isInteger(n) || n < 0) && p("syntax", `occurrence ${e} must be a non-negative integer or unbounded; fix it`), n;
91
+ };
92
+ function ee(e, t = {}) {
93
+ typeof e != "string" && !(e instanceof Uint8Array) && p("range", "expected IDS text or bytes; read the .ids file first");
94
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = a(n.replace(/^/, ""), {
95
+ maxElements: t.maxElements ?? 1e6,
96
+ fail: (e) => p("syntax", `malformed IDS XML: ${e}; fix the file`)
97
+ }).documentElement;
98
+ (r.localName !== "ids" || r.namespaceURI !== d) && p("syntax", `expected an <ids> root in ${d}; this is not an IDS 1.0 file`);
99
+ let i = v(h(r, "info"), "info"), o = { title: v(g(h(i, "title")), "info title") };
100
+ for (let e of [
101
+ "copyright",
102
+ "version",
103
+ "description",
104
+ "author",
105
+ "date",
106
+ "purpose",
107
+ "milestone"
108
+ ]) {
109
+ let t = g(h(i, e));
110
+ t !== void 0 && (o[e] = t);
111
+ }
112
+ let s = [];
113
+ for (let e of m(v(h(r, "specifications"), "specifications"), "specification")) {
114
+ let t = v(h(e, "applicability"), "specification applicability"), n = {
115
+ name: v(e.getAttribute("name") ?? void 0, "specification name"),
116
+ ifcVersion: v(e.getAttribute("ifcVersion") ?? void 0, "specification ifcVersion").trim().split(/\s+/),
117
+ minOccurs: S(t.getAttribute("minOccurs"), 1),
118
+ maxOccurs: S(t.getAttribute("maxOccurs"), 1),
119
+ applicability: [],
120
+ requirements: []
121
+ };
122
+ n.minOccurs === "unbounded" && p("syntax", "minOccurs cannot be unbounded; use 0 or 1");
123
+ for (let t of [
124
+ "identifier",
125
+ "description",
126
+ "instructions"
127
+ ]) {
128
+ let r = e.getAttribute(t);
129
+ r !== null && (n[t] = r);
130
+ }
131
+ for (let e of t.children) {
132
+ let t = x(e);
133
+ t && n.applicability.push(t);
134
+ }
135
+ let r = h(e, "requirements");
136
+ if (r) {
137
+ let e = r.getAttribute("description");
138
+ e !== null && (n.requirementsDescription = e);
139
+ for (let e of r.children) {
140
+ let t = x(e);
141
+ if (!t) continue;
142
+ let r = t;
143
+ r.cardinality = e.getAttribute("cardinality") ?? "required", [
144
+ "required",
145
+ "optional",
146
+ "prohibited"
147
+ ].includes(r.cardinality) || p("syntax", `cardinality ${r.cardinality} must be required, optional or prohibited`);
148
+ let i = e.getAttribute("instructions");
149
+ i !== null && (r.instructions = i), n.requirements.push(r);
150
+ }
151
+ }
152
+ s.push(n);
153
+ }
154
+ return s.length || p("syntax", "an IDS needs at least one specification; add one"), {
155
+ info: o,
156
+ specifications: s
157
+ };
158
+ }
159
+ var C = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), w = (e, t) => t === void 0 ? "" : ` ${e}="${C(String(t))}"`;
160
+ function T(e, t, n) {
161
+ if (!t) return "";
162
+ if ("simpleValue" in t) return `${n}<ids:${e}><ids:simpleValue>${C(t.simpleValue)}</ids:simpleValue></ids:${e}>\n`;
163
+ let r = t.restriction, i = `${n} `, a = "";
164
+ for (let e of r.enumeration ?? []) a += `${i}<xs:enumeration value="${C(e)}"/>\n`;
165
+ for (let e of r.pattern ?? []) a += `${i}<xs:pattern value="${C(e)}"/>\n`;
166
+ for (let e of [
167
+ "minExclusive",
168
+ "minInclusive",
169
+ "maxExclusive",
170
+ "maxInclusive",
171
+ "length",
172
+ "minLength",
173
+ "maxLength"
174
+ ]) r[e] !== void 0 && (a += `${i}<xs:${e} value="${C(String(r[e]))}"/>\n`);
175
+ return `${n}<ids:${e}>\n${n} <xs:restriction base="${C(r.base)}">\n${a}${n} </xs:restriction>\n${n}</ids:${e}>\n`;
176
+ }
177
+ function E(e, t, n) {
178
+ let r = n ? e : void 0, i = (t) => `${t}${r && e.facet !== "entity" ? w("cardinality", r.cardinality) : ""}${r ? w("instructions", r.instructions) : ""}`, a = `${t} `;
179
+ switch (e.facet) {
180
+ case "entity": return `${t}<ids:entity${r ? w("instructions", r.instructions) : ""}>\n${T("name", e.name, a)}${T("predefinedType", e.predefinedType, a)}${t}</ids:entity>\n`;
181
+ case "partOf": return `${t}<ids:partOf${i(w("relation", e.relation))}>\n${E(e.entity, a, !1)}${t}</ids:partOf>\n`;
182
+ case "classification": return `${t}<ids:classification${i(w("uri", e.uri))}>\n${T("value", e.value, a)}${T("system", e.system, a)}${t}</ids:classification>\n`;
183
+ case "attribute": return `${t}<ids:attribute${i("")}>\n${T("name", e.name, a)}${T("value", e.value, a)}${t}</ids:attribute>\n`;
184
+ case "property": return `${t}<ids:property${i(w("dataType", e.dataType) + w("uri", e.uri))}>\n${T("propertySet", e.propertySet, a)}${T("baseName", e.baseName, a)}${T("value", e.value, a)}${t}</ids:property>\n`;
185
+ case "material": return `${t}<ids:material${i(w("uri", e.uri))}>\n${T("value", e.value, a)}${t}</ids:material>\n`;
186
+ }
187
+ }
188
+ var D = [
189
+ "entity",
190
+ "partOf",
191
+ "classification",
192
+ "attribute",
193
+ "property",
194
+ "material"
195
+ ], O = (e) => [...e].sort((e, t) => D.indexOf(e.facet) - D.indexOf(t.facet));
196
+ function k(e) {
197
+ (!e || !e.info || !Array.isArray(e.specifications)) && p("range", "expected an IDSDocument with info and specifications"), e.specifications.length || p("range", "an IDS needs at least one specification; add one");
198
+ let t = `<?xml version="1.0" encoding="UTF-8"?>
199
+ <ids:ids xmlns:ids="${d}" xmlns:xs="${f}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="${d} http://standards.buildingsmart.org/IDS/1.0/ids.xsd">\n <ids:info>\n`;
200
+ for (let n of [
201
+ "title",
202
+ "copyright",
203
+ "version",
204
+ "description",
205
+ "author",
206
+ "date",
207
+ "purpose",
208
+ "milestone"
209
+ ]) e.info[n] !== void 0 && (t += ` <ids:${n}>${C(e.info[n])}</ids:${n}>\n`);
210
+ t += " </ids:info>\n <ids:specifications>\n";
211
+ for (let n of e.specifications) {
212
+ t += ` <ids:specification${w("name", n.name)}${w("ifcVersion", n.ifcVersion.join(" "))}${w("identifier", n.identifier)}${w("description", n.description)}${w("instructions", n.instructions)}>\n`, t += ` <ids:applicability${w("minOccurs", n.minOccurs)}${w("maxOccurs", n.maxOccurs)}>\n`;
213
+ for (let e of O(n.applicability)) t += E(e, " ", !1);
214
+ if (t += " </ids:applicability>\n", n.requirements.length || n.requirementsDescription !== void 0) {
215
+ t += ` <ids:requirements${w("description", n.requirementsDescription)}>\n`;
216
+ for (let e of O(n.requirements)) t += E(e, " ", !0);
217
+ t += " </ids:requirements>\n";
218
+ }
219
+ t += " </ids:specification>\n";
220
+ }
221
+ return `${t} </ids:specifications>\n</ids:ids>\n`;
222
+ }
223
+ var A = (e) => e && e.type === 5 && typeof e.value == "number" ? e.value : void 0, j = (e) => Array.isArray(e) ? e.map(A).filter((e) => e !== void 0) : A(e) === void 0 ? [] : [A(e)], M = (e) => e && typeof e.value == "string" && e.type !== 5 ? e.value : void 0, N = /^([-+]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?|NaN|\+INF|-INF)$/, P = /^[+-]?(\d+)$/, F = (e) => {
224
+ if (N.test(e) && /[0-9]|NaN|INF/.test(e)) return e === "NaN" ? NaN : e === "+INF" ? Infinity : e === "-INF" ? -Infinity : Number(e);
225
+ };
226
+ function te(e, t) {
227
+ if (typeof e == "string") return {
228
+ kind: "string",
229
+ value: e
230
+ };
231
+ if (typeof e == "boolean") return {
232
+ kind: "boolean",
233
+ value: e
234
+ };
235
+ if (typeof e == "number") return {
236
+ kind: t && I.has(t) ? "integer" : "real",
237
+ value: e
238
+ };
239
+ }
240
+ var I = /* @__PURE__ */ new Set([
241
+ "IFCCARDINALPOINTREFERENCE",
242
+ "IFCCOUNTMEASURE",
243
+ "IFCDAYINMONTHNUMBER",
244
+ "IFCDAYINWEEKNUMBER",
245
+ "IFCDAYLIGHTSAVINGHOUR",
246
+ "IFCDIMENSIONCOUNT",
247
+ "IFCHOURINDAY",
248
+ "IFCINTEGER",
249
+ "IFCINTEGERCOUNTRATEMEASURE",
250
+ "IFCMINUTEINHOUR",
251
+ "IFCMONTHINYEARNUMBER",
252
+ "IFCPOSITIVEINTEGER",
253
+ "IFCTIMESTAMP",
254
+ "IFCYEARNUMBER"
255
+ ]);
256
+ function L(e, t) {
257
+ if (t.kind === "string") return t.value === e;
258
+ if (t.kind === "boolean") return e === "true" || e === "1" ? t.value : e === "false" || e === "0" ? !t.value : !1;
259
+ if (t.kind === "integer") return P.test(e) && Number(e) === t.value;
260
+ let n = F(e);
261
+ return n !== void 0 && l(t.value, n);
262
+ }
263
+ var R = /* @__PURE__ */ new Map();
264
+ function ne(e) {
265
+ let t = R.get(e);
266
+ if (t !== void 0) return t;
267
+ let n = e.replace(/\\i/g, "[_:A-Za-z\\u00C0-\\u02FF\\u0370-\\u1FFF]").replace(/\\c/g, "[-._:A-Za-z0-9\\u00B7\\u00C0-\\u02FF\\u0300-\\u1FFF]").replace(/\\I/g, "[^_:A-Za-z\\u00C0-\\u02FF\\u0370-\\u1FFF]").replace(/\\C/g, "[^-._:A-Za-z0-9\\u00B7\\u00C0-\\u02FF\\u0300-\\u1FFF]");
268
+ try {
269
+ t = RegExp(`^(?:${n})$`, "u");
270
+ } catch {
271
+ t = null;
272
+ }
273
+ return R.set(e, t), t;
274
+ }
275
+ function z(e, t) {
276
+ if ("simpleValue" in e) return L(e.simpleValue, t);
277
+ let n = e.restriction;
278
+ if (n.enumeration && !n.enumeration.some((e) => L(e, t)) || n.pattern && (t.kind !== "string" || !n.pattern.some((e) => ne(e)?.test(t.value)))) return !1;
279
+ let r = [
280
+ n.minInclusive,
281
+ n.maxInclusive,
282
+ n.minExclusive,
283
+ n.maxExclusive
284
+ ];
285
+ if (r.some((e) => e !== void 0)) {
286
+ if (t.kind !== "real" && t.kind !== "integer") return !1;
287
+ let e = t.value, [n, i, a, o] = r.map((e) => e === void 0 ? void 0 : F(e));
288
+ if (r.some((e, t) => e !== void 0 && [
289
+ n,
290
+ i,
291
+ a,
292
+ o
293
+ ][t] === void 0) || n !== void 0 && !(e >= n) || i !== void 0 && !(e <= i) || a !== void 0 && !(e > a) || o !== void 0 && !(e < o)) return !1;
294
+ }
295
+ if (n.length !== void 0 || n.minLength !== void 0 || n.maxLength !== void 0) {
296
+ if (t.kind !== "string") return !1;
297
+ let e = [...t.value].length;
298
+ if (n.length !== void 0 && e !== n.length || n.minLength !== void 0 && e < n.minLength || n.maxLength !== void 0 && e > n.maxLength) return !1;
299
+ }
300
+ return !0;
301
+ }
302
+ var B = (e, t) => t !== void 0 && z(e, {
303
+ kind: "string",
304
+ value: t
305
+ }), V = (e) => "simpleValue" in e ? e.simpleValue : [
306
+ e.restriction.enumeration && `one of ${e.restriction.enumeration.join(", ")}`,
307
+ e.restriction.pattern && `matching ${e.restriction.pattern.join(" or ")}`,
308
+ e.restriction.minInclusive !== void 0 && `>= ${e.restriction.minInclusive}`,
309
+ e.restriction.minExclusive !== void 0 && `> ${e.restriction.minExclusive}`,
310
+ e.restriction.maxInclusive !== void 0 && `<= ${e.restriction.maxInclusive}`,
311
+ e.restriction.maxExclusive !== void 0 && `< ${e.restriction.maxExclusive}`,
312
+ e.restriction.length !== void 0 && `${e.restriction.length} characters`,
313
+ e.restriction.minLength !== void 0 && `at least ${e.restriction.minLength} characters`,
314
+ e.restriction.maxLength !== void 0 && `at most ${e.restriction.maxLength} characters`
315
+ ].filter(Boolean).join(", "), H = /* @__PURE__ */ new Set([
316
+ "IFCFURNISHINGELEMENT",
317
+ "IFCDISTRIBUTIONCONTROLELEMENT",
318
+ "IFCENERGYCONVERSIONDEVICE",
319
+ "IFCFLOWCONTROLLER",
320
+ "IFCFLOWFITTING",
321
+ "IFCFLOWMOVINGDEVICE",
322
+ "IFCFLOWSEGMENT",
323
+ "IFCFLOWSTORAGEDEVICE",
324
+ "IFCFLOWTERMINAL",
325
+ "IFCFLOWTREATMENTDEVICE",
326
+ "IFCEQUIPMENTELEMENT"
327
+ ]), re = class {
328
+ constructor(e, t) {
329
+ this.model = e, this.data = t, this.lines = /* @__PURE__ */ new Map(), this.codes = /* @__PURE__ */ new Map(), this.typeOfId = /* @__PURE__ */ new Map(), this.ifc2x3 = e.schema.toUpperCase().startsWith("IFC2X3");
330
+ }
331
+ line(t) {
332
+ let n = this.lines.get(t);
333
+ return n === void 0 && (n = e("reading a line", () => this.model.api.GetLine(this.model.id, t)) ?? null, this.lines.set(t, n)), n;
334
+ }
335
+ nameOfCode(t) {
336
+ let n = this.codes.get(t);
337
+ return n === void 0 && this.codes.set(t, n = e("reading a type name", () => this.model.api.GetNameFromTypeCode(t))), n;
338
+ }
339
+ type(t) {
340
+ let n = this.typeOfId.get(t);
341
+ if (n === void 0) {
342
+ let r = this.data.elements.get(t);
343
+ n = (r ? r.type : this.nameOfCode(e("reading a line type", () => this.model.api.GetLineType(this.model.id, t)))).toUpperCase(), this.typeOfId.set(t, n);
344
+ }
345
+ return n;
346
+ }
347
+ ids(e) {
348
+ let t = [], r = n(this.model);
349
+ for (let n = 0; n < e.size(); n++) r.has(e.get(n)) || t.push(e.get(n));
350
+ return t;
351
+ }
352
+ allIds() {
353
+ return this.all ??= this.ids(e("listing lines", () => this.model.api.GetAllLines(this.model.id))).sort((e, t) => e - t);
354
+ }
355
+ ofClass(t) {
356
+ let n = this.model.api, r = n.GetTypeCodeFromName(t);
357
+ return r ? this.ids(e(`listing ${t}`, () => n.GetLineIDsWithType(this.model.id, r, !1))) : [];
358
+ }
359
+ classes() {
360
+ let t = /* @__PURE__ */ new Set();
361
+ for (let n of e("listing classes", () => this.model.api.GetAllTypesOfModel(this.model.id))) t.add(String(n.typeName).toUpperCase());
362
+ return [...t];
363
+ }
364
+ materialPropertySets(e) {
365
+ return this.data.materialProperties?.get(e) ?? [];
366
+ }
367
+ resourceClassifications(e) {
368
+ if (!this.externalClasses) {
369
+ this.externalClasses = /* @__PURE__ */ new Map();
370
+ for (let e of this.ofClass("IFCEXTERNALREFERENCERELATIONSHIP")) {
371
+ let t = this.line(e), n = A(t?.RelatingReference);
372
+ if (n === void 0) continue;
373
+ let r = this.type(n);
374
+ if (r === "IFCCLASSIFICATIONREFERENCE" || r === "IFCCLASSIFICATION") for (let e of j(t.RelatedResourceObjects)) (this.externalClasses.get(e) ?? this.externalClasses.set(e, []).get(e)).push(n);
375
+ }
376
+ }
377
+ return this.externalClasses.get(e) ?? [];
378
+ }
379
+ hasMaterialLink(e) {
380
+ if (!this.materialLinks) {
381
+ this.materialLinks = /* @__PURE__ */ new Set();
382
+ for (let e of this.ofClass("IFCRELASSOCIATESMATERIAL")) for (let t of j(this.line(e)?.RelatedObjects)) this.materialLinks.add(t);
383
+ }
384
+ return this.materialLinks.has(e);
385
+ }
386
+ }, U = { ok: !0 }, W = (e) => ({
387
+ ok: !1,
388
+ reason: e
389
+ });
390
+ function ie(e, t) {
391
+ let n = e.type(t);
392
+ if (!e.ifc2x3 || !H.has(n)) return [n];
393
+ let r = e.data.elements.get(t)?.typeId, i = r === void 0 ? void 0 : e.type(r);
394
+ return i?.endsWith("TYPE") ? [n, i.slice(0, -4)] : [n];
395
+ }
396
+ function G(e, t) {
397
+ let n = (e, t) => {
398
+ let n = M(e?.PredefinedType);
399
+ if (n === void 0 || n === "NOTDEFINED") return [];
400
+ if (n !== "USERDEFINED") return [n];
401
+ let r = t ? M(e.ElementType) ?? M(e.ProcessType) ?? M(e.ResourceType) : M(e.ObjectType);
402
+ return r === void 0 ? [n] : [r, n];
403
+ }, r = e.data.elements.get(t)?.typeId, i = r === void 0 ? [] : n(e.line(r), !0);
404
+ return i.length ? i : n(e.line(t), e.type(t).endsWith("TYPE"));
405
+ }
406
+ function K(e, t, n) {
407
+ let r = ie(e, n);
408
+ if (!r.some((e) => B(t.name, e))) return W(`is ${r[r.length - 1]}, expected ${V(t.name)}`);
409
+ if (t.predefinedType) {
410
+ let r = G(e, n);
411
+ if (!r.some((e) => B(t.predefinedType, e))) return W(`predefined type is ${r[0] ?? "not set"}, expected ${V(t.predefinedType)}`);
412
+ }
413
+ return U;
414
+ }
415
+ function q(e, t) {
416
+ let n = "simpleValue" in t.name ? [t.name.simpleValue] : t.name.restriction.enumeration && Object.keys(t.name.restriction).length === 2 ? t.name.restriction.enumeration : e.classes().filter((e) => B(t.name, e)), r = /* @__PURE__ */ new Set();
417
+ for (let t of n) if (t === t.toUpperCase()) {
418
+ for (let n of e.ofClass(t)) r.add(n);
419
+ if (e.ifc2x3) for (let n of e.ofClass(`${t}TYPE`)) for (let t of e.data.elements.values()) t.typeId === n && H.has(t.type.toUpperCase()) && r.add(t.id);
420
+ }
421
+ return [...r];
422
+ }
423
+ var J = /* @__PURE__ */ new Set(["expressID", "type"]);
424
+ function ae(e, t) {
425
+ if (t == null) return "empty";
426
+ if (Array.isArray(t)) return t.length ? "object" : "empty";
427
+ if (typeof t != "object") return typeof t == "string" ? t === "" ? "empty" : {
428
+ kind: "string",
429
+ value: t
430
+ } : "object";
431
+ if (t.type === 5) return "object";
432
+ let n = typeof t.name == "string" ? t.name.toUpperCase() : void 0;
433
+ if (t.type === 3 && (n === "IFCBOOLEAN" || n === "IFCLOGICAL")) return t.value === !0 || t.value === "T" ? {
434
+ kind: "boolean",
435
+ value: !0
436
+ } : t.value === !1 || t.value === "F" ? {
437
+ kind: "boolean",
438
+ value: !1
439
+ } : "empty";
440
+ if (t.type === 4 || t.type === 10) {
441
+ let r = Number(t._representationValue ?? t.value);
442
+ if (t.type === 10) return {
443
+ kind: "integer",
444
+ value: r
445
+ };
446
+ let i = c(n), a = i ? e.data.units.byType[i] ?? s(i) : void 0;
447
+ return {
448
+ kind: n && I.has(n) ? "integer" : "real",
449
+ value: a ? r * a.scale + a.shift : r
450
+ };
451
+ }
452
+ return typeof t.value == "string" ? t.value === "" ? "empty" : {
453
+ kind: "string",
454
+ value: t.value
455
+ } : "object";
456
+ }
457
+ function oe(e, t, n) {
458
+ let r = e.line(n);
459
+ if (!r) return W("cannot be read");
460
+ let i = Object.keys(r).filter((e) => !J.has(e) && B(t.name, e));
461
+ if (!i.length) return W(`has no attribute ${V(t.name)}`);
462
+ let a = [];
463
+ for (let n of i) {
464
+ let i = ae(e, r[n]);
465
+ if (i === "empty") a.push(`${n} is empty`);
466
+ else {
467
+ if (!t.value) return U;
468
+ if (i === "object") a.push(`${n} is not a single value`);
469
+ else {
470
+ if (z(t.value, i)) return U;
471
+ a.push(`${n} is ${String(i.value)}, expected ${V(t.value)}`);
472
+ }
473
+ }
474
+ }
475
+ return W(a.join("; "));
476
+ }
477
+ function Y(e, t) {
478
+ let n = (t) => {
479
+ let n = { codes: [] }, r = /* @__PURE__ */ new Set();
480
+ for (let i = t; i !== void 0 && !r.has(i);) {
481
+ r.add(i);
482
+ let t = e.line(i);
483
+ if (e.type(i) === "IFCCLASSIFICATION") {
484
+ n.system = M(t.Name);
485
+ break;
486
+ }
487
+ let a = M(t.Identification) ?? M(t.ItemReference);
488
+ a !== void 0 && n.codes.push(a), i = A(t.ReferencedSource);
489
+ }
490
+ return n;
491
+ }, r = e.data.elements.get(t);
492
+ if (!r) return e.resourceClassifications(t).map(n);
493
+ let i = r.classifications.map((e) => ({
494
+ system: e.system,
495
+ codes: [e.code, ...e.parents ?? []].filter((e) => e !== void 0)
496
+ })), a = r.typeId === void 0 ? void 0 : e.data.elements.get(r.typeId), o = new Set(i.map((e) => e.system)), s = (a?.classifications ?? []).filter((e) => !o.has(e.system)).map((e) => ({
497
+ system: e.system,
498
+ codes: [e.code, ...e.parents ?? []].filter((e) => e !== void 0)
499
+ }));
500
+ return [...i, ...s];
501
+ }
502
+ function se(e, t, n) {
503
+ let r = Y(e, n);
504
+ return r.length ? r.some((e) => (!t.system || B(t.system, e.system)) && (!t.value || e.codes.some((e) => B(t.value, e)))) ? U : W(`is classified ${r.map((e) => `${e.system ?? "?"} ${e.codes[0] ?? ""}`.trim()).join(", ")}, expected ${[t.system && V(t.system), t.value && V(t.value)].filter(Boolean).join(" ")}`) : W("has no classification");
505
+ }
506
+ var ce = {
507
+ IFCQUANTITYLENGTH: "IFCLENGTHMEASURE",
508
+ IFCQUANTITYAREA: "IFCAREAMEASURE",
509
+ IFCQUANTITYVOLUME: "IFCVOLUMEMEASURE",
510
+ IFCQUANTITYCOUNT: "IFCCOUNTMEASURE",
511
+ IFCQUANTITYWEIGHT: "IFCMASSMEASURE",
512
+ IFCQUANTITYTIME: "IFCTIMEMEASURE",
513
+ IFCQUANTITYNUMBER: "IFCNUMERICMEASURE"
514
+ };
515
+ function X(e, t) {
516
+ let n = e.data.elements.get(t);
517
+ if (!n) return e.materialPropertySets(t);
518
+ let r = n.typeId === void 0 ? void 0 : e.data.elements.get(n.typeId), i = /* @__PURE__ */ new Map();
519
+ for (let e of [...r?.psets ?? [], ...n.psets]) {
520
+ let t = i.get(e.name);
521
+ i.set(e.name, t ? {
522
+ ...e,
523
+ properties: {
524
+ ...t.properties,
525
+ ...e.properties
526
+ }
527
+ } : e);
528
+ }
529
+ return [...i.values()];
530
+ }
531
+ var le = [
532
+ "minInclusive",
533
+ "maxInclusive",
534
+ "minExclusive",
535
+ "maxExclusive"
536
+ ], Z = (e) => "restriction" in e && le.some((t) => e.restriction[t] !== void 0), ue = (e) => e === null || e === "" || Array.isArray(e) && !e.length;
537
+ function de(e, t, n) {
538
+ if (t.kind === "complex" || t.kind === "reference") return W(`${n} is a ${t.kind} property, which IDS does not check`);
539
+ let r = t.kind === "table" ? [{
540
+ values: t.defining ?? [],
541
+ dataType: t.definingDataType
542
+ }, {
543
+ values: Array.isArray(t.value) ? t.value : [],
544
+ dataType: t.dataType
545
+ }] : t.kind === "bounded" ? [{
546
+ values: [
547
+ t.lower ?? null,
548
+ t.upper ?? null,
549
+ t.value
550
+ ],
551
+ dataType: t.dataType
552
+ }] : [{
553
+ values: Array.isArray(t.value) ? t.value : [t.value],
554
+ dataType: t.kind === "quantity" ? ce[t.dataType ?? ""] : t.dataType
555
+ }];
556
+ for (let e of r) e.values = e.values.filter((e) => !ue(e));
557
+ let i = r.filter((e) => e.values.length);
558
+ if (!i.length) return W(`${n} is empty`);
559
+ let a = e.dataType ? i.filter((t) => t.dataType === e.dataType) : i;
560
+ if (!a.length) return W(`${n} is ${i.map((e) => e.dataType ?? "untyped").join(" and ")}, expected ${e.dataType}`);
561
+ if (!e.value) return U;
562
+ let o = e.value, s = a.flatMap((e) => e.values).map(String).join(", ");
563
+ if (t.kind === "bounded" && Z(o)) {
564
+ let e = t.lower ?? void 0, r = t.upper ?? void 0;
565
+ return e === void 0 || r === void 0 ? W(`${n} is open-ended, expected ${V(o)}`) : z(o, {
566
+ kind: "real",
567
+ value: e
568
+ }) && z(o, {
569
+ kind: "real",
570
+ value: r
571
+ }) ? U : W(`${n} is ${e} to ${r}, expected ${V(o)}`);
572
+ }
573
+ let c = a.flatMap((e) => e.values.map((t) => te(t, e.dataType)).filter((e) => e !== void 0));
574
+ return (Z(o) && t.kind !== "single" && t.kind !== "quantity" ? c.length > 0 && c.every((e) => z(o, e)) : c.some((e) => z(o, e))) ? U : W(`${n} is ${s}, expected ${V(o)}`);
575
+ }
576
+ function fe(e, t, n) {
577
+ let r = X(e, n).filter((e) => B(t.propertySet, e.name));
578
+ if (!r.length) return W(`has no property set ${V(t.propertySet)}`);
579
+ for (let e of r) {
580
+ let n = Object.values(e.properties).filter((e) => B(t.baseName, e.name));
581
+ if (!n.length) return W(`${e.name} has no property ${V(t.baseName)}`);
582
+ for (let r of n) {
583
+ let n = de(t, r, `${e.name}.${r.name}`);
584
+ if (!n.ok) return n;
585
+ }
586
+ }
587
+ return U;
588
+ }
589
+ function Q(e, t) {
590
+ let n = e.data.elements.get(t);
591
+ if (!n) return;
592
+ let r = n.materials.length || e.hasMaterialLink(t) ? n : n.typeId === void 0 ? void 0 : e.data.elements.get(n.typeId);
593
+ if (!r || !r.materials.length && !e.hasMaterialLink(r.id)) return;
594
+ let i = [];
595
+ for (let e of r.materials) for (let t of [
596
+ e.name,
597
+ e.category,
598
+ e.part,
599
+ e.set
600
+ ]) t && i.push(t);
601
+ return i;
602
+ }
603
+ function pe(e, t, n) {
604
+ let r = Q(e, n);
605
+ return r ? t.value ? r.some((e) => B(t.value, e)) ? U : W(`has materials ${r.join(", ") || "(unnamed)"}, expected ${V(t.value)}`) : U : W("has no material");
606
+ }
607
+ function me(e, t, n) {
608
+ let r = [], i = /* @__PURE__ */ new Set([t]), a = [t];
609
+ for (; a.length;) {
610
+ let t = e.data.elements.get(a.shift());
611
+ if (!t) continue;
612
+ let o = [];
613
+ (!n || n === "IFCRELAGGREGATES") && o.push(t.aggregate), (!n || n === "IFCRELNESTS") && o.push(t.nest), (!n || n === "IFCRELCONTAINEDINSPATIALSTRUCTURE") && o.push(t.container), (!n || n === "IFCRELASSIGNSTOGROUP") && o.push(...t.groups ?? []), (!n || n === "IFCRELVOIDSELEMENT IFCRELFILLSELEMENT") && o.push(t.fills, t.voids);
614
+ for (let e of o) e !== void 0 && !i.has(e) && (i.add(e), r.push(e), a.push(e));
615
+ }
616
+ return r;
617
+ }
618
+ function he(e, t, n) {
619
+ return me(e, n, t.relation).some((n) => K(e, t.entity, n).ok) ? U : W(`is not part of ${V(t.entity.name)}${t.relation ? ` by ${t.relation}` : ""}`);
620
+ }
621
+ function $(e, t, n) {
622
+ switch (t.facet) {
623
+ case "entity": return K(e, t, n);
624
+ case "attribute": return oe(e, t, n);
625
+ case "classification": return se(e, t, n);
626
+ case "property": return fe(e, t, n);
627
+ case "material": return pe(e, t, n);
628
+ case "partOf": return he(e, t, n);
629
+ }
630
+ }
631
+ function ge(e, t, n) {
632
+ switch (t.facet) {
633
+ case "attribute": {
634
+ let r = e.line(n);
635
+ return !!r && Object.keys(r).some((e) => !J.has(e) && B(t.name, e) && r[e] !== null && r[e] !== void 0);
636
+ }
637
+ case "property": return X(e, n).some((e) => B(t.propertySet, e.name) && Object.values(e.properties).some((e) => B(t.baseName, e.name)));
638
+ case "classification": return Y(e, n).length > 0;
639
+ case "material": return Q(e, n) !== void 0;
640
+ default: return !0;
641
+ }
642
+ }
643
+ function _e(e) {
644
+ if (e.maxOccurs === 0 && e.requirements.length) return "a prohibited specification cannot have requirements";
645
+ if (!e.applicability.length) return "the applicability needs at least one facet";
646
+ }
647
+ var ve = (e) => {
648
+ let t = e.toUpperCase();
649
+ return t.startsWith("IFC2X3") ? "IFC2X3" : t.startsWith("IFC4X3") ? "IFC4X3_ADD2" : "IFC4";
650
+ };
651
+ function ye(e, n, i = {}) {
652
+ t(e), r(i.signal), (!n || !Array.isArray(n.specifications)) && p("range", "expected an IDSDocument; read the file with parseIDS");
653
+ let a = i.data ?? o(e, { signal: i.signal }), s = new re(e, a), c = ve(e.schema), l = [];
654
+ for (let e of n.specifications) {
655
+ r(i.signal);
656
+ let t = {
657
+ specification: e,
658
+ status: "pass",
659
+ applicable: [],
660
+ passed: [],
661
+ failures: [],
662
+ warnings: []
663
+ };
664
+ l.push(t), e.ifcVersion.some((e) => e.toUpperCase() === c) || t.warnings.push(`the model is ${c}; the specification is written for ${e.ifcVersion.join(", ")}`);
665
+ let n = _e(e);
666
+ if (n) {
667
+ t.status = "fail", t.reason = `invalid IDS: ${n}`;
668
+ continue;
669
+ }
670
+ let o = e.applicability.find((e) => e.facet === "entity"), u = o ? q(s, o) : s.allIds();
671
+ for (let n of u.sort((e, t) => e - t)) e.applicability.every((e) => $(s, e, n).ok) && t.applicable.push(n);
672
+ if (e.maxOccurs === 0) t.applicable.length && (t.status = "fail", t.reason = `${t.applicable.length} entities match a prohibited specification`);
673
+ else if (e.minOccurs >= 1 && !t.applicable.length) t.status = "fail", t.reason = "no entity matches the applicability of a required specification";
674
+ else {
675
+ for (let n of t.applicable) {
676
+ let r = !0;
677
+ e.requirements.forEach((e, i) => {
678
+ let o;
679
+ if (o = e.cardinality === "prohibited" ? $(s, e, n).ok ? W(`must not match ${e.facet} ${be(e)}`) : U : e.cardinality === "optional" && !ge(s, e, n) ? U : $(s, e, n), !o.ok) {
680
+ r = !1;
681
+ let e = a.elements.get(n), c = {
682
+ id: n,
683
+ type: e?.type ?? s.type(n),
684
+ requirement: i,
685
+ reason: o.reason
686
+ };
687
+ e?.globalId && (c.globalId = e.globalId), e?.name && (c.name = e.name), t.failures.push(c);
688
+ }
689
+ }), r && t.passed.push(n);
690
+ }
691
+ t.failures.length && (t.status = "fail");
692
+ }
693
+ }
694
+ return {
695
+ pass: l.every((e) => e.status !== "fail"),
696
+ schema: c,
697
+ title: n.info.title,
698
+ specifications: l
699
+ };
700
+ }
701
+ function be(e) {
702
+ switch (e.facet) {
703
+ case "entity": return V(e.name);
704
+ case "attribute": return `${V(e.name)}${e.value ? ` = ${V(e.value)}` : ""}`;
705
+ case "classification": return [e.system && V(e.system), e.value && V(e.value)].filter(Boolean).join(" ");
706
+ case "property": return `${V(e.propertySet)}.${V(e.baseName)}${e.value ? ` = ${V(e.value)}` : ""}`;
707
+ case "material": return e.value ? V(e.value) : "any material";
708
+ case "partOf": return V(e.entity.name);
709
+ }
710
+ }
711
+ function xe(e, t) {
712
+ (!e || !Array.isArray(e.specifications)) && p("range", "expected an IDSReport from checkIDS"), (typeof t?.author != "string" || !t.author) && p("range", "bcfTopicsFromIDS needs an author; pass { author }");
713
+ let n = t.date ?? (/* @__PURE__ */ new Date()).toISOString(), r = [];
714
+ for (let a of e.specifications) {
715
+ if (a.status !== "fail") continue;
716
+ let e = a.specification, o = [...new Set(a.failures.map((e) => e.id))], s = [
717
+ e.description,
718
+ e.instructions,
719
+ a.reason ?? `${o.length} of ${a.applicable.length} applicable entities fail its requirements`
720
+ ].filter((e) => !!e), c = {
721
+ guid: i(),
722
+ selection: a.failures.filter((e) => e.globalId).map((e) => ({ ifcGuid: e.globalId })),
723
+ defaultVisibility: !0,
724
+ exceptions: [],
725
+ spacesVisible: !1,
726
+ spaceBoundariesVisible: !1,
727
+ openingsVisible: !1,
728
+ coloring: [],
729
+ lines: [],
730
+ clippingPlanes: [],
731
+ bitmaps: []
732
+ };
733
+ t.camera && (c.camera = t.camera), c.selection = c.selection.filter((e, t, n) => n.findIndex((t) => t.ifcGuid === e.ifcGuid) === t), r.push({
734
+ guid: i(),
735
+ type: t.type ?? "Issue",
736
+ status: t.status ?? "Open",
737
+ title: `IDS: ${e.name}`,
738
+ labels: t.labels ?? ["IDS"],
739
+ referenceLinks: [],
740
+ creationDate: n,
741
+ creationAuthor: t.author,
742
+ description: s.join("\n"),
743
+ files: [],
744
+ documentReferences: [],
745
+ relatedTopics: [],
746
+ comments: a.failures.map((e) => ({
747
+ guid: i(),
748
+ date: n,
749
+ author: t.author,
750
+ comment: `${e.name ?? e.type} (${e.globalId ?? `#${e.id}`}): ${e.reason}`,
751
+ viewpoint: c.guid
752
+ })),
753
+ viewpoints: [c]
754
+ });
755
+ }
756
+ return r;
757
+ }
758
+ //#endregion
759
+ export { xe as bcfTopicsFromIDS, ye as checkIDS, ee as parseIDS, k as writeIDS };