@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/write.js ADDED
@@ -0,0 +1,546 @@
1
+ import { a as e, i as t, n, r, s as i, t as a } from "./open-D1NQyRTk.js";
2
+ import { a as o, c as s, l as c, n as l, o as u, r as d, s as f, t as p, u as m } from "./units-B32iYdmV.js";
3
+ //#region src/write.ts
4
+ var h = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$", g = /^[0-3][0-9A-Za-z_$]{21}$/, _ = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;
5
+ function v(e) {
6
+ (typeof e != "string" || !_.test(e)) && t("range", "expected a UUID such as 3f2504e0-4f89-11d3-9a0c-0305e82c3301");
7
+ let n = BigInt(`0x${e.replace(/-/g, "")}`), r = "";
8
+ for (let e = 0; e < 22; e++, n >>= 6n) r = h[Number(n & 63n)] + r;
9
+ return r;
10
+ }
11
+ function y(e) {
12
+ (typeof e != "string" || !g.test(e)) && t("range", "expected a 22-character IFC GUID whose first character is 0 to 3");
13
+ let n = 0n;
14
+ for (let t of e) n = n * 64n + BigInt(h.indexOf(t));
15
+ let r = n.toString(16).padStart(32, "0");
16
+ return `${r.slice(0, 8)}-${r.slice(8, 12)}-${r.slice(12, 16)}-${r.slice(16, 20)}-${r.slice(20)}`;
17
+ }
18
+ function b() {
19
+ let e = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
20
+ return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, v([...e].map((e) => e.toString(16).padStart(2, "0")).join(""));
21
+ }
22
+ function x(r, o = {}) {
23
+ n(r), a(o.signal);
24
+ let s = w(e("saving the model", () => r.api.SaveModel(r.id)));
25
+ a(o.signal);
26
+ let c = i(s);
27
+ return c && t("unsupported", `web-ifc wrote malformed STEP (${c}); report the edit that caused it`), s;
28
+ }
29
+ var S = (e) => e !== void 0 && e >= 48 && e <= 57, C = (e) => e !== void 0 && (e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 95 || S(e));
30
+ function w(e) {
31
+ let t = [];
32
+ for (let n = 0, r = e.length; n < r;) {
33
+ let i = e[n];
34
+ if (i === 39 || i === 34) for (n++; n < r && (e[n] !== i || e[++n] === i); n++);
35
+ else if (i === 47 && e[n + 1] === 42) {
36
+ let t = e.indexOf(42, n + 2);
37
+ for (; t >= 0 && e[t + 1] !== 47;) t = e.indexOf(42, t + 1);
38
+ n = t < 0 ? r : t + 2;
39
+ } else if (i === 35 || C(i) && !S(i)) for (n++; C(e[n]); n++);
40
+ else if (S(i)) {
41
+ let r = !1;
42
+ for (; S(e[n]) || e[n] === 46; n++) r ||= e[n] === 46;
43
+ if ((e[n] === 69 || e[n] === 101) && !r && t.push(n), e[n] === 69 || e[n] === 101) for (n++; S(e[n]) || e[n] === 43 || e[n] === 45; n++);
44
+ } else n++;
45
+ }
46
+ if (!t.length) return e;
47
+ let n = new Uint8Array(e.length + t.length), r = 0, i = 0;
48
+ for (let a of t) n.set(e.subarray(r, a), i), i += a - r, n[i++] = 46, r = a;
49
+ return n.set(e.subarray(r), i), n;
50
+ }
51
+ var T = {
52
+ m: ["LENGTHUNIT", "METRE"],
53
+ m2: ["AREAUNIT", "SQUARE_METRE"],
54
+ m3: ["VOLUMEUNIT", "CUBIC_METRE"],
55
+ g: ["MASSUNIT", "GRAM"],
56
+ s: ["TIMEUNIT", "SECOND"],
57
+ rad: ["PLANEANGLEUNIT", "RADIAN"],
58
+ sr: ["SOLIDANGLEUNIT", "STERADIAN"],
59
+ K: ["THERMODYNAMICTEMPERATUREUNIT", "KELVIN"],
60
+ degC: ["THERMODYNAMICTEMPERATUREUNIT", "DEGREE_CELSIUS"],
61
+ A: ["ELECTRICCURRENTUNIT", "AMPERE"],
62
+ mol: ["AMOUNTOFSUBSTANCEUNIT", "MOLE"],
63
+ cd: ["LUMINOUSINTENSITYUNIT", "CANDELA"],
64
+ N: ["FORCEUNIT", "NEWTON"],
65
+ Pa: ["PRESSUREUNIT", "PASCAL"],
66
+ J: ["ENERGYUNIT", "JOULE"],
67
+ W: ["POWERUNIT", "WATT"],
68
+ Hz: ["FREQUENCYUNIT", "HERTZ"],
69
+ V: ["ELECTRICVOLTAGEUNIT", "VOLT"],
70
+ C: ["ELECTRICCHARGEUNIT", "COULOMB"],
71
+ F: ["ELECTRICCAPACITANCEUNIT", "FARAD"],
72
+ ohm: ["ELECTRICRESISTANCEUNIT", "OHM"],
73
+ S: ["ELECTRICCONDUCTANCEUNIT", "SIEMENS"],
74
+ Wb: ["MAGNETICFLUXUNIT", "WEBER"],
75
+ T: ["MAGNETICFLUXDENSITYUNIT", "TESLA"],
76
+ H: ["INDUCTANCEUNIT", "HENRY"],
77
+ lm: ["LUMINOUSFLUXUNIT", "LUMEN"],
78
+ lx: ["ILLUMINANCEUNIT", "LUX"],
79
+ Bq: ["RADIOACTIVITYUNIT", "BECQUEREL"],
80
+ Gy: ["ABSORBEDDOSEUNIT", "GRAY"],
81
+ Sv: ["DOSEEQUIVALENTUNIT", "SIEVERT"]
82
+ }, E = {
83
+ E: "EXA",
84
+ P: "PETA",
85
+ T: "TERA",
86
+ G: "GIGA",
87
+ M: "MEGA",
88
+ k: "KILO",
89
+ h: "HECTO",
90
+ da: "DECA",
91
+ d: "DECI",
92
+ c: "CENTI",
93
+ m: "MILLI",
94
+ u: "MICRO",
95
+ µ: "MICRO",
96
+ n: "NANO",
97
+ p: "PICO",
98
+ f: "FEMTO",
99
+ a: "ATTO"
100
+ };
101
+ function ee(e) {
102
+ let n = T[e];
103
+ if (n) return [
104
+ n[0],
105
+ null,
106
+ n[1]
107
+ ];
108
+ for (let t of [2, 1]) {
109
+ let n = E[e.slice(0, t)], r = T[e.slice(t)];
110
+ if (n && r && e.slice(t) !== "degC") return [
111
+ r[0],
112
+ n,
113
+ r[1]
114
+ ];
115
+ }
116
+ return t("range", `unknown unit ${JSON.stringify(e)}; use an SI symbol with an optional prefix, such as mm, m2, kg or kPa`);
117
+ }
118
+ var D = {
119
+ length: [
120
+ "IFCQUANTITYLENGTH",
121
+ "LengthValue",
122
+ "IFCLENGTHMEASURE"
123
+ ],
124
+ area: [
125
+ "IFCQUANTITYAREA",
126
+ "AreaValue",
127
+ "IFCAREAMEASURE"
128
+ ],
129
+ volume: [
130
+ "IFCQUANTITYVOLUME",
131
+ "VolumeValue",
132
+ "IFCVOLUMEMEASURE"
133
+ ],
134
+ count: [
135
+ "IFCQUANTITYCOUNT",
136
+ "CountValue",
137
+ "IFCCOUNTMEASURE"
138
+ ],
139
+ weight: [
140
+ "IFCQUANTITYWEIGHT",
141
+ "WeightValue",
142
+ "IFCMASSMEASURE"
143
+ ],
144
+ time: [
145
+ "IFCQUANTITYTIME",
146
+ "TimeValue",
147
+ "IFCTIMEMEASURE"
148
+ ],
149
+ number: [
150
+ "IFCQUANTITYNUMBER",
151
+ "NumberValue",
152
+ "IFCNUMERICMEASURE"
153
+ ]
154
+ }, te = [
155
+ "IFCRELDEFINESBYPROPERTIES",
156
+ "IFCRELDEFINESBYTEMPLATE",
157
+ "IFCTYPEOBJECT",
158
+ "IFCPROPERTYSET",
159
+ "IFCELEMENTQUANTITY",
160
+ "IFCCOMPLEXPROPERTY",
161
+ "IFCPHYSICALCOMPLEXQUANTITY",
162
+ "IFCEXTENDEDMATERIALPROPERTIES",
163
+ "IFCEXTENDEDPROPERTIES",
164
+ "IFCPROPERTYDEPENDENCYRELATIONSHIP",
165
+ "IFCPROPERTYCONSTRAINTRELATIONSHIP",
166
+ "IFCRESOURCECONSTRAINTRELATIONSHIP",
167
+ "IFCRESOURCEAPPROVALRELATIONSHIP"
168
+ ], ne = [
169
+ "HasProperties",
170
+ "Quantities",
171
+ "HasQuantities"
172
+ ], re = {
173
+ Name: "IFCLABEL",
174
+ Description: "IFCTEXT",
175
+ ObjectType: "IFCLABEL",
176
+ Tag: "IFCIDENTIFIER",
177
+ LongName: "IFCLABEL",
178
+ ElementType: "IFCLABEL",
179
+ ApplicableOccurrence: "IFCIDENTIFIER"
180
+ }, ie = /^[A-Z][A-Z0-9_]*$/, O = {
181
+ property: ["IFCPROPERTYSET", "HasProperties"],
182
+ quantity: ["IFCELEMENTQUANTITY", "Quantities"]
183
+ }, ae = (e, t) => !t || t.scale === 1 && t.shift === 0 ? e : Number(((e - t.shift) / t.scale).toPrecision(15));
184
+ function k(i, a = {}) {
185
+ n(i);
186
+ let { api: h, id: g } = i, _ = Math.floor((a.now === void 0 ? Date.now() : a.now instanceof Date ? a.now.getTime() : NaN) / 1e3);
187
+ Number.isSafeInteger(_) || t("range", "now must be a valid Date");
188
+ let v = i.schema.toUpperCase() === "IFC2X3", y = /* @__PURE__ */ new Map(), x = r(i), S = (n) => {
189
+ let r = y.get(n);
190
+ return r === void 0 && (r = e("reading a line", () => h.GetLine(g, n)), r || t("range", `line #${n} does not exist`), y.set(n, r)), r;
191
+ }, C, w = (e) => Array.isArray(e) ? e.map(w).find(Boolean) : e && e.type === 5 && typeof e.value == "number" && e.constructor !== Object ? e.constructor : void 0, T = (n) => {
192
+ if (!C) {
193
+ let n = (e) => {
194
+ for (let t of Object.keys(e ?? {})) C ||= w(e[t]);
195
+ };
196
+ for (let e of y.values()) n(e);
197
+ let r = C ? void 0 : e("listing lines", () => h.GetAllLines(g));
198
+ for (let e = 0; !C && r && e < r.size(); e++) n(S(r.get(e)));
199
+ C || t("unsupported", "the model holds no references to copy; it has nothing to edit");
200
+ }
201
+ return new C(n);
202
+ }, E = /* @__PURE__ */ new Map(), k = (t) => {
203
+ let n = E.get(t.type);
204
+ return n === void 0 && E.set(t.type, n = e("reading a type name", () => h.GetNameFromTypeCode(t.type)).toUpperCase()), n;
205
+ }, A = (e, t = !1) => {
206
+ let n;
207
+ try {
208
+ n = h.GetLineIDsWithType(g, h.GetTypeCodeFromName(e), t);
209
+ } catch {
210
+ return [];
211
+ }
212
+ let r = [];
213
+ for (let e = 0; e < n.size(); e++) x.has(n.get(e)) || r.push(n.get(e));
214
+ return r;
215
+ }, oe = (e) => {
216
+ let n;
217
+ try {
218
+ n = h.CreateIfcEntity(g, h.GetTypeCodeFromName(e));
219
+ } catch {}
220
+ return n || t("unsupported", `${i.schema} has no ${e}; it needs a newer schema`), n;
221
+ }, N = (e, n) => {
222
+ let r;
223
+ try {
224
+ r = h.CreateIfcType(g, h.GetTypeCodeFromName(e), n);
225
+ } catch {}
226
+ return r || t("range", `${i.schema} has no defined type ${e}; use one of its types, such as IfcLabel or IfcLengthMeasure`), r;
227
+ }, P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), se = (e) => {
228
+ let t = [];
229
+ for (let n of Object.keys(e)) n !== "OwnerHistory" && t.push(...c(e[n]));
230
+ let n = k(e) === "IFCRELDEFINESBYPROPERTIES" ? c(e.RelatedObjects) : [];
231
+ for (let e of t) P.set(e, (P.get(e) ?? 0) + 1);
232
+ for (let t of n) I.set(t, [...I.get(t) ?? [], e.expressID]);
233
+ F.set(e.expressID, {
234
+ refs: t,
235
+ objects: n
236
+ });
237
+ }, ce = (e) => {
238
+ let t = F.get(e);
239
+ if (t) {
240
+ for (let e of t.refs) P.set(e, P.get(e) - 1);
241
+ for (let n of t.objects) I.set(n, I.get(n).filter((t) => t !== e));
242
+ F.delete(e);
243
+ }
244
+ };
245
+ for (let e of te) for (let t of A(e, !0)) F.has(t) || se(S(t));
246
+ let L = new Set(A("IFCTYPEOBJECT", !0)), le = new Set(A("IFCOBJECTDEFINITION", !0)), ue = [], de = [], R = /* @__PURE__ */ new Set(), z = (t, n = F.has(t.expressID)) => ((t.expressID === void 0 || t.expressID < 0) && (t.expressID = e("reading the largest expressID", () => h.GetMaxExpressID(g)) + 1, ue.push(t.expressID), R.add(t.expressID)), ce(t.expressID), e("writing a line", () => h.WriteLine(g, t)), y.set(t.expressID, t), n && se(t), t.expressID), B = (t) => {
247
+ let n = S(t);
248
+ ce(t), e("deleting a line", () => h.DeleteLine(g, t)), y.delete(t), x.add(t), de.push(t);
249
+ for (let e of ne) for (let t of c(n[e])) P.get(t) || B(t);
250
+ }, V = (e, n, r = []) => {
251
+ let a = oe(e);
252
+ for (let e of Object.keys(a)) a[e] === void 0 && !r.includes(e) && (a[e] = null);
253
+ for (let [r, o] of Object.entries(n)) r in a || t("unsupported", `${i.schema} ${e} has no ${r}`), a[r] = o;
254
+ return a;
255
+ }, H = A("IFCOWNERHISTORY").sort((e, t) => e - t)[0], fe = v || H !== void 0 || !!a.user || !!a.application, U, W, G, K = (e, t) => N(e, e === "IFCLOGICAL" && t === null ? "U" : t), q = (e) => N("IFCLABEL", e), pe = (e) => z(V("IFCORGANIZATION", { Name: q(e) })), me = () => {
256
+ if (U !== void 0) return U;
257
+ let e = H === void 0 ? void 0 : s(S(H).OwningUser);
258
+ if (!a.user && e !== void 0) return U = e;
259
+ let n = a.user ?? { organization: "Unknown" };
260
+ (typeof n.organization != "string" || !n.organization) && t("range", "user.organization must be a non-empty string");
261
+ let r = z(V("IFCPERSON", {
262
+ FamilyName: n.familyName === void 0 ? null : q(n.familyName),
263
+ GivenName: n.givenName === void 0 ? n.familyName === void 0 ? q("Unknown") : null : q(n.givenName)
264
+ }));
265
+ return U = z(V("IFCPERSONANDORGANIZATION", {
266
+ ThePerson: T(r),
267
+ TheOrganization: T(pe(n.organization))
268
+ }));
269
+ }, he = () => {
270
+ if (W !== void 0) return W;
271
+ let e = H === void 0 ? void 0 : s(S(H).OwningApplication);
272
+ if (!a.application && e !== void 0) return W = e;
273
+ let n = a.application ?? {
274
+ name: "Margo Engine",
275
+ version: "1.0.0",
276
+ identifier: "margoengine",
277
+ developer: "Margo Engine"
278
+ };
279
+ for (let e of [
280
+ "name",
281
+ "version",
282
+ "identifier",
283
+ "developer"
284
+ ]) (typeof n[e] != "string" || !n[e]) && t("range", `application.${e} must be a non-empty string`);
285
+ return W = z(V("IFCAPPLICATION", {
286
+ ApplicationDeveloper: T(pe(n.developer)),
287
+ Version: q(n.version),
288
+ ApplicationFullName: q(n.name),
289
+ ApplicationIdentifier: N("IFCIDENTIFIER", n.identifier)
290
+ }));
291
+ }, ge = (e, t) => V("IFCOWNERHISTORY", {
292
+ OwningUser: t?.OwningUser ?? T(me()),
293
+ OwningApplication: t?.OwningApplication ?? T(he()),
294
+ State: t?.State ?? null,
295
+ ChangeAction: {
296
+ type: 3,
297
+ value: e
298
+ },
299
+ LastModifiedDate: N("IFCTIMESTAMP", _),
300
+ LastModifyingUser: T(me()),
301
+ LastModifyingApplication: T(he()),
302
+ CreationDate: t?.CreationDate ?? N("IFCTIMESTAMP", _)
303
+ }), _e = () => fe ? (G === void 0 && (G = z(ge("ADDED"))), T(G)) : null, ve = /* @__PURE__ */ new Map(), J = (e) => {
304
+ if (!("GlobalId" in e) || R.has(e.expressID) || !fe) return;
305
+ let t = s(e.OwnerHistory) ?? null;
306
+ if (t !== null && R.has(t)) return;
307
+ let n = ve.get(t);
308
+ n === void 0 && ve.set(t, n = z(ge("MODIFIED", t === null ? void 0 : S(t)))), e.OwnerHistory = T(n);
309
+ }, Y = (e, t) => V(e, {
310
+ GlobalId: N("IFCGLOBALLYUNIQUEID", b()),
311
+ OwnerHistory: _e(),
312
+ ...t
313
+ }), ye, be = (e) => {
314
+ if (e) return ye ??= l((e) => e === void 0 ? void 0 : S(e), k, (e) => A(e).sort((e, t) => e - t)), ye.byType[e];
315
+ }, xe = /* @__PURE__ */ new Map(), Se = (e, n) => {
316
+ let [r, i, a] = ee(e), o = u(n);
317
+ o !== r && t("range", `unit ${e} is a ${r}, but ${n} takes ${o ?? "no unit"}`);
318
+ let s = `${r} ${i} ${a}`, c = xe.get(s);
319
+ return c === void 0 && (c = A("IFCSIUNIT").find((e) => {
320
+ let t = S(e);
321
+ return t.UnitType?.value === r && (t.Prefix?.value ?? null) === i && t.Name?.value === a;
322
+ }), c ??= z(V("IFCSIUNIT", {
323
+ UnitType: {
324
+ type: 3,
325
+ value: r
326
+ },
327
+ Prefix: i ? {
328
+ type: 3,
329
+ value: i
330
+ } : null,
331
+ Name: {
332
+ type: 3,
333
+ value: a
334
+ }
335
+ }, ["Dimensions"])), xe.set(s, c)), [c, {
336
+ ...d(i, a),
337
+ symbol: e,
338
+ name: s
339
+ }];
340
+ }, Ce = (e) => e === void 0 ? void 0 : o(S(e), (e) => e === void 0 ? void 0 : S(e), k), we = (e, n, r) => {
341
+ let i = typeof e != "object" || !e;
342
+ !i && (typeof e.type != "string" || !e.type) && t("range", `${r}: a typed value needs a type such as IfcLabel`);
343
+ let a = i ? e : e.raw === void 0 ? e.value : e.raw;
344
+ a === void 0 && t("range", `${r}: a typed value needs value or raw`);
345
+ let o = a === null ? "null" : typeof a;
346
+ [
347
+ "string",
348
+ "number",
349
+ "boolean",
350
+ "null"
351
+ ].includes(o) || t("range", `${r}: expected a string, number or boolean`);
352
+ let s = i ? void 0 : e.type.toUpperCase();
353
+ s === void 0 && n.type && j(n.type, a) && (s = n.type), s ??= typeof a == "string" ? [...a].length > 255 ? "IFCTEXT" : "IFCLABEL" : typeof a == "boolean" ? "IFCBOOLEAN" : "IFCREAL", j(s, a) || t("range", `${r}: ${JSON.stringify(a)} is not a valid ${s}`);
354
+ let c, l;
355
+ !i && e.unit !== void 0 ? [c, l] = Se(e.unit, s) : l = s === n.type && n.unit !== void 0 ? Ce(c = n.unit) : be(u(s));
356
+ let d = a;
357
+ return typeof a == "number" && (i || e.raw === void 0) && (d = ae(a, l)), M(s, d, r), {
358
+ wrapper: K(s, d),
359
+ type: s,
360
+ unit: c
361
+ };
362
+ }, X = (e) => ((!Number.isSafeInteger(e) || !le.has(e)) && t("range", `#${e} is not an object or type object; pass an expressID from readIFCData`), L.has(e)), Te = (e) => {
363
+ if (L.has(e)) return c(S(e).HasPropertySets).map((e) => ({ set: e }));
364
+ let t = [];
365
+ for (let n of I.get(e) ?? []) for (let e of c(S(n).RelatingPropertyDefinition)) t.push({
366
+ set: e,
367
+ rel: n
368
+ });
369
+ return t;
370
+ }, Z = (e, t, n) => Te(e).find(({ set: e }) => {
371
+ let r = S(e);
372
+ return m(r.Name) === t && (n ? k(r) === O[n][0] : k(r) in {
373
+ IFCPROPERTYSET: 1,
374
+ IFCELEMENTQUANTITY: 1
375
+ });
376
+ }), Q = (e, t, n) => Array.isArray(e) ? e.flatMap((e) => s(e) === t ? n === null ? [] : [T(n)] : [e]) : s(e) === t ? n === null ? null : T(n) : e, Ee = (e, t) => {
377
+ let { set: n, rel: r } = t;
378
+ if (r !== void 0) {
379
+ let t = S(r);
380
+ c(t.RelatedObjects).length > 1 && (J(t), t.RelatedObjects = Q(t.RelatedObjects, e, null), z(t), r = z(Y("IFCRELDEFINESBYPROPERTIES", {
381
+ Name: t.Name,
382
+ Description: t.Description,
383
+ RelatedObjects: [T(e)],
384
+ RelatingPropertyDefinition: t.RelatingPropertyDefinition
385
+ }), !0));
386
+ }
387
+ if ((P.get(n) ?? 0) > 1) {
388
+ let t = S(n), i = oe(k(t));
389
+ for (let e of Object.keys(i)) i[e] = e === "expressID" || e === "type" ? i[e] : t[e] ?? null;
390
+ i.GlobalId = N("IFCGLOBALLYUNIQUEID", b()), i.OwnerHistory = _e();
391
+ let a = z(i, !0), o = S(r === void 0 ? e : r), s = r === void 0 ? "HasPropertySets" : "RelatingPropertyDefinition";
392
+ J(o), o[s] = Q(o[s], n, a), z(o), n = a;
393
+ }
394
+ return n;
395
+ }, De = (e, t, n, r) => {
396
+ let i = z(Y(O[t][0], {
397
+ Name: q(n),
398
+ [O[t][1]]: r.map(T)
399
+ }), !0);
400
+ if (L.has(e)) {
401
+ let t = S(e);
402
+ J(t), t.HasPropertySets = [...t.HasPropertySets ?? [], T(i)], z(t);
403
+ } else z(Y("IFCRELDEFINESBYPROPERTIES", {
404
+ RelatedObjects: [T(e)],
405
+ RelatingPropertyDefinition: T(i)
406
+ }), !0);
407
+ return i;
408
+ }, Oe = (e, t) => {
409
+ if (t.rel === void 0) {
410
+ let n = S(e);
411
+ J(n);
412
+ let r = Q(n.HasPropertySets, t.set, null);
413
+ n.HasPropertySets = r.length ? r : null, z(n);
414
+ } else {
415
+ let n = S(t.rel), r = c(n.RelatedObjects).length > 1, i = c(n.RelatingPropertyDefinition).filter((e) => e !== t.set);
416
+ r ? (J(n), n.RelatedObjects = Q(n.RelatedObjects, e, null), z(n), i.length && z(Y("IFCRELDEFINESBYPROPERTIES", {
417
+ Name: n.Name,
418
+ Description: n.Description,
419
+ RelatedObjects: [T(e)],
420
+ RelatingPropertyDefinition: Q(n.RelatingPropertyDefinition, t.set, null)
421
+ }), !0)) : i.length ? (J(n), n.RelatingPropertyDefinition = Q(n.RelatingPropertyDefinition, t.set, null), z(n)) : B(t.rel);
422
+ }
423
+ P.get(t.set) || B(t.set);
424
+ }, ke = (e, n, r, i, a) => {
425
+ X(e), (typeof r != "string" || !r) && t("range", "the set name must be a non-empty string"), (typeof i != "string" || !i) && t("range", "the property name must be a non-empty string");
426
+ let o = Z(e, r, n), s = o ? S(o.set) : void 0, l = s && c(s[O[n][1]]).find((e) => m(S(e).Name) === i), u = a(l === void 0 ? void 0 : S(l));
427
+ if (!o) return De(e, n, r, [z(u)]), u.expressID;
428
+ let d = S(Ee(e, o));
429
+ if (l !== void 0 && P.get(l) === 1) {
430
+ let e = S(l);
431
+ u.expressID = l, z(u);
432
+ for (let t of ne) for (let n of c(e[t])) P.get(n) || B(n);
433
+ return J(d), z(d), l;
434
+ }
435
+ let f = z(u);
436
+ J(d);
437
+ let p = O[n][1];
438
+ return d[p] = l === void 0 ? [...d[p], T(f)] : Q(d[p], l, f), z(d), l !== void 0 && !P.get(l) && B(l), f;
439
+ }, Ae = (e, t, n, r) => {
440
+ X(e);
441
+ let i = Z(e, n, t);
442
+ if (!i) return !1;
443
+ let a = O[t][1], o = c(S(i.set)[a]).find((e) => m(S(e).Name) === r);
444
+ if (o === void 0) return !1;
445
+ if (c(S(i.set)[a]).length === 1) return Oe(e, i), !0;
446
+ let s = S(Ee(e, i));
447
+ return J(s), s[a] = Q(s[a], o, null), z(s), P.get(o) || B(o), !0;
448
+ }, je = (e, n, r) => {
449
+ let i = `property ${e}`, a = r ? k(r) : void 0, o = Array.isArray(n), c = a === "IFCPROPERTYENUMERATEDVALUE" && (o ? n : [n]).every((e) => typeof e == "string" || typeof e == "object" && !!e && typeof e.value == "string"), l = c ? "IFCPROPERTYENUMERATEDVALUE" : o ? "IFCPROPERTYLISTVALUE" : "IFCPROPERTYSINGLEVALUE", u = V(l, {});
450
+ if (r) for (let e of Object.keys(u)) e !== "expressID" && e !== "type" && e in r && (u[e] = r[e] ?? null);
451
+ u.Name = N("IFCIDENTIFIER", e);
452
+ let d = a === "IFCPROPERTYSINGLEVALUE" ? r.NominalValue : (r?.ListValues ?? r?.EnumerationValues)?.[0], p = {
453
+ type: typeof d?.name == "string" ? d.name.toUpperCase() : void 0,
454
+ unit: s(r?.Unit)
455
+ }, m = (o ? n : [n]).map((e) => we(e, p, i));
456
+ if (m.length || t("range", `${i}: a list needs at least one value`), m.some((e) => e.type !== m[0].type) && t("range", `${i}: every value of a list must have one type`), c) {
457
+ let e = s(r.EnumerationReference);
458
+ if (e !== void 0) {
459
+ let n = (S(e).EnumerationValues ?? []).map((e) => f(e));
460
+ for (let e of m) n.includes(f(e.wrapper)) || t("range", `${i}: ${JSON.stringify(f(e.wrapper))} is not one of ${n.join(", ")}`);
461
+ }
462
+ u.EnumerationValues = m.map((e) => e.wrapper);
463
+ } else o ? u.ListValues = m.map((e) => e.wrapper) : u.NominalValue = m[0].wrapper;
464
+ return "Unit" in u && l !== "IFCPROPERTYENUMERATEDVALUE" && (u.Unit = m[0].unit === void 0 ? null : T(m[0].unit)), u;
465
+ }, Me = (e, n, r) => {
466
+ let a = `quantity ${e}`, o = typeof n == "number" ? { value: n } : n;
467
+ (!o || typeof o != "object") && t("range", `${a}: expected a number or { kind, value }`);
468
+ let c = r ? Object.entries(D).find(([, e]) => e[0] === k(r))?.[0] : void 0, l = o.kind ?? c;
469
+ if (!l || !D[l]) return t("range", `${a}: a new quantity needs kind (length, area, volume, count, weight, time or number)`);
470
+ let [u, d, f] = D[l], m = V(u, {});
471
+ if (r && l === c) for (let e of Object.keys(m)) e !== "expressID" && e !== "type" && e in r && (m[e] = r[e] ?? null);
472
+ m.Name = q(e);
473
+ let h = o.raw ?? o.value;
474
+ (typeof h != "number" || !Number.isFinite(h)) && t("range", `${a}: expected a finite number`);
475
+ let g;
476
+ if (o.unit !== void 0) {
477
+ let [e, t] = Se(o.unit, f);
478
+ m.Unit = T(e), g = t;
479
+ } else g = r && l === c && s(r.Unit) !== void 0 ? Ce(s(r.Unit)) : be(p[u]);
480
+ let _ = o.raw === void 0 ? ae(o.value, g) : o.raw;
481
+ return _ < 0 && t("range", `${a}: quantities must not be negative`), m[d] = N(f, _), o.formula !== void 0 && ("Formula" in m || t("unsupported", `${i.schema} quantities have no Formula`), m.Formula = N("IFCLABEL", o.formula)), m;
482
+ }, $ = {
483
+ created: ue,
484
+ deleted: de,
485
+ setProperty: (e, t, n, r) => ke(e, "property", t, n, (e) => je(n, r, e)),
486
+ setPropertySet(e, n, r, i = {}) {
487
+ (!r || typeof r != "object") && t("range", "values must be an object of property names to values");
488
+ for (let [t, i] of Object.entries(r)) i === null ? $.removeProperty(e, n, t) : $.setProperty(e, n, t, i);
489
+ if (i.replace) {
490
+ let t = Z(e, n, "property");
491
+ if (t) for (let i of c(S(t.set).HasProperties)) {
492
+ let t = m(S(i).Name);
493
+ t !== void 0 && !(t in r) && $.removeProperty(e, n, t);
494
+ }
495
+ }
496
+ },
497
+ removeProperty: (e, t, n) => Ae(e, "property", t, n),
498
+ removePropertySet(e, t) {
499
+ X(e);
500
+ let n = Z(e, t);
501
+ return n ? (Oe(e, n), !0) : !1;
502
+ },
503
+ setQuantity: (e, t, n, r) => ke(e, "quantity", t, n, (e) => Me(n, r, e)),
504
+ removeQuantity: (e, t, n) => Ae(e, "quantity", t, n),
505
+ rename: (e, t) => $.setAttribute(e, "Name", t),
506
+ setAttribute(e, n, r) {
507
+ (!Number.isSafeInteger(e) || e <= 0) && t("range", "expected an expressID");
508
+ let i = S(e);
509
+ (typeof n != "string" || !(n in i) || [
510
+ "expressID",
511
+ "type",
512
+ "GlobalId",
513
+ "OwnerHistory"
514
+ ].includes(n)) && t("range", `#${e} has no attribute ${JSON.stringify(n)} that can be set`);
515
+ let a = i[n];
516
+ if ((c(a).length || a && a.type === 5 || Array.isArray(a) && a.length) && t("range", `${n} holds references or a list; setAttribute sets single values`), r === null) (!(n in re) || !("GlobalId" in i)) && t("range", `${n} cannot be cleared; only optional IfcRoot text attributes can`), i[n] = null;
517
+ else if (typeof r == "object") {
518
+ typeof r.type != "string" && t("range", "a typed attribute value needs a type");
519
+ let e = r.type.toUpperCase();
520
+ M(e, r.raw, n), i[n] = K(e, r.raw);
521
+ } else if (a && a.type === 3 && !a.name) (typeof r != "string" || !ie.test(r)) && t("range", `${n} is an enumeration; pass a value such as NOTDEFINED`), i[n] = {
522
+ type: 3,
523
+ value: r
524
+ };
525
+ else if (!a && (n === "PredefinedType" || n === "CompositionType")) (typeof r != "string" || !ie.test(r)) && t("range", `${n} is an enumeration; pass a value such as NOTDEFINED`), i[n] = {
526
+ type: 3,
527
+ value: r
528
+ };
529
+ else {
530
+ let e = typeof a?.name == "string" ? a.name.toUpperCase() : re[n];
531
+ e || t("range", `${n} is unset and its type is not known here; pass { type, raw }`), M(e, r, n), i[n] = K(e, r);
532
+ }
533
+ J(i), z(i);
534
+ }
535
+ };
536
+ return $;
537
+ }
538
+ var A = /INTEGER|TIMESTAMP|NUMBER$/;
539
+ function j(e, t) {
540
+ return e === "IFCBOOLEAN" ? typeof t == "boolean" : e === "IFCLOGICAL" ? typeof t == "boolean" || t === null : t === null ? !1 : /^IFC(LABEL|TEXT|IDENTIFIER|DESCRIPTIVEMEASURE|DATE|DATETIME|TIME|DURATION|URIREFERENCE|GLOBALLYUNIQUEID|PRESENTABLETEXT|BOXALIGNMENT|FONTSTYLE|FONTVARIANT|FONTWEIGHT|TEXTALIGNMENT|TEXTDECORATION|TEXTFONTNAME|TEXTTRANSFORMATION|WELLKNOWNTEXTLITERAL|LANGUAGEID)$/.test(e) ? typeof t == "string" : typeof t == "number";
541
+ }
542
+ function M(e, n, r) {
543
+ j(e, n) || t("range", `${r}: ${JSON.stringify(n)} is not a valid ${e}`), typeof n == "number" && (Number.isFinite(n) || t("range", `${r}: numbers must be finite`), A.test(e) && !Number.isInteger(n) && t("range", `${r}: ${e} needs an integer`), e.startsWith("IFCPOSITIVE") && !(n > 0) && t("range", `${r}: ${e} needs a value above 0`), e.startsWith("IFCNONNEGATIVE") && n < 0 && t("range", `${r}: ${e} needs a value of 0 or more`), e === "IFCNORMALISEDRATIOMEASURE" && (n < 0 || n > 1) && t("range", `${r}: ${e} needs a value from 0 to 1`)), typeof n == "string" && (e === "IFCLABEL" || e === "IFCIDENTIFIER") && [...n].length > 255 && t("range", `${r}: ${e} holds at most 255 characters; use IfcText`);
544
+ }
545
+ //#endregion
546
+ export { k as editIFC, v as ifcGuidFromUUID, b as newIFCGuid, x as saveIFC, y as uuidFromIFCGuid };
package/package.json CHANGED
@@ -1,6 +1,102 @@
1
- {
2
- "name": "@margoengine/ifc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@margoengine/ifc",
3
+ "version": "0.1.0",
4
+ "description": "IFC geometry and BIM identifiers for Margo Engine, using an initialized web-ifc runtime.",
5
+ "keywords": [
6
+ "margoengine",
7
+ "webgpu",
8
+ "3d",
9
+ "ifc",
10
+ "bim"
11
+ ],
12
+ "homepage": "https://margoengine.com",
13
+ "bugs": {
14
+ "url": "https://github.com/scottcampbelldata/margoengine/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/scottcampbelldata/margoengine.git",
19
+ "directory": "packages/ifc"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "author": "Scott Campbell",
23
+ "type": "module",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "node ../../scripts/build-optional.js ifc",
29
+ "test": "npm run build && node --test tests/*.test.js",
30
+ "test:gpu": "cd ../.. && node packages/ifc/tests/scene-gpu-check.mjs",
31
+ "prepack": "npm run build"
32
+ },
33
+ "sideEffects": false,
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js"
38
+ },
39
+ "./bcf": {
40
+ "types": "./dist/bcf.d.ts",
41
+ "import": "./dist/bcf.js"
42
+ },
43
+ "./data": {
44
+ "types": "./dist/data.d.ts",
45
+ "import": "./dist/data.js"
46
+ },
47
+ "./ids": {
48
+ "types": "./dist/ids.d.ts",
49
+ "import": "./dist/ids.js"
50
+ },
51
+ "./query": {
52
+ "types": "./dist/query.d.ts",
53
+ "import": "./dist/query.js"
54
+ },
55
+ "./scene": {
56
+ "types": "./dist/scene.d.ts",
57
+ "import": "./dist/scene.js"
58
+ },
59
+ "./section": {
60
+ "types": "./dist/section.d.ts",
61
+ "import": "./dist/section.js"
62
+ },
63
+ "./worker": {
64
+ "types": "./dist/worker.d.ts",
65
+ "import": "./dist/worker.js"
66
+ },
67
+ "./write": {
68
+ "types": "./dist/write.d.ts",
69
+ "import": "./dist/write.js"
70
+ }
71
+ },
72
+ "files": [
73
+ "dist",
74
+ "NOTICE.md",
75
+ "NOTICE"
76
+ ],
77
+ "peerDependencies": {
78
+ "@margoengine/core": "^0.1.0",
79
+ "@margoengine/loaders": "^0.1.0",
80
+ "@margoengine/materials": "^0.1.0",
81
+ "web-ifc": "^0.0.78",
82
+ "@margoengine/geometry": "^0.1.0",
83
+ "@margoengine/lines": "^0.1.0"
84
+ },
85
+ "peerDependenciesMeta": {
86
+ "web-ifc": {
87
+ "optional": true
88
+ },
89
+ "@margoengine/materials": {
90
+ "optional": true
91
+ },
92
+ "@margoengine/core": {
93
+ "optional": true
94
+ },
95
+ "@margoengine/geometry": {
96
+ "optional": true
97
+ },
98
+ "@margoengine/lines": {
99
+ "optional": true
100
+ }
101
+ }
102
+ }