@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 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { IfcAPI } from 'web-ifc';
3
+ import { type LoadedGeometry, type ParseLimits } from '@margoengine/loaders/common';
4
+ import { type IFCModel, type IFCOpenOptions } from './open.js';
5
+ export { openIFC, type IFCModel, type IFCOpenOptions } from './open.js';
6
+ /** Options of readIFCGeometry: vertex and triangle limits, an AbortSignal and the origin to rebase onto. */
7
+ export interface IFCGeometryOptions extends ParseLimits {
8
+ signal?: AbortSignal;
9
+ /**
10
+ * World point subtracted from every vertex in float64 before it is stored as float32, so georeferenced models with
11
+ * coordinates in the hundreds of kilometres keep millimetre precision. `'auto'` takes the first placement's
12
+ * translation rounded to whole metres. Default: none (model coordinates). Engine axes: Y up, meters.
13
+ */
14
+ origin?: 'auto' | readonly [number, number, number];
15
+ }
16
+ /** Options of parseIFC: openIFC's options plus readIFCGeometry's. */
17
+ export interface IFCOptions extends IFCOpenOptions, IFCGeometryOptions {
18
+ }
19
+ /** One IFC product: its express ID, type, optional GlobalId and name. */
20
+ export interface IFCProduct {
21
+ expressID: number;
22
+ type: string;
23
+ globalId?: string;
24
+ name?: string;
25
+ }
26
+ /** The geometry parseIFC returns, with the IFC schema name and the list of products. */
27
+ export interface IFCResult extends LoadedGeometry {
28
+ kind: 'mesh';
29
+ schema: string;
30
+ products: IFCProduct[];
31
+ /** The point subtracted from every vertex (engine axes, meters); [0, 0, 0] unless `origin` was set. */
32
+ origin: [number, number, number];
33
+ }
34
+ /** Reads geometry in meters using an initialized, caller-owned web-ifc API. The opened model is always closed. */
35
+ export declare function parseIFC(api: IfcAPI, data: Uint8Array, options?: IFCOptions): IFCResult;
36
+ /**
37
+ * Reads every product's triangles from an open model into one LoadedGeometry: world-space meters (engine axes,
38
+ * Y up), one named, coloured group per placed geometry with the element's expressID in `objectId`, reflected
39
+ * winding corrected and normals computed. The model stays open.
40
+ */
41
+ export declare function readIFCGeometry(model: IFCModel, options?: IFCGeometryOptions): IFCResult;
42
+ /** Checks a column-major affine placement and returns its determinant. */
43
+ export declare function checkPlacement(m: ArrayLike<number>): number;
44
+ /** Checks a web-ifc surface colour and returns it as RGBA in 0..1. */
45
+ export declare function checkColor({ x, y, z, w, }: {
46
+ x: number;
47
+ y: number;
48
+ z: number;
49
+ w: number;
50
+ }): [number, number, number, number];
package/dist/index.js ADDED
@@ -0,0 +1,116 @@
1
+ import { a as e, i as t, n, o as r, t as i } from "./open-D1NQyRTk.js";
2
+ import { computeVertexNormals as a } from "@margoengine/loaders/common";
3
+ //#region src/index.ts
4
+ function o(e, t, n = {}) {
5
+ s(n);
6
+ let i = r(e, t, n);
7
+ try {
8
+ return c(i, n);
9
+ } finally {
10
+ i.close();
11
+ }
12
+ }
13
+ function s(e) {
14
+ for (let n of [
15
+ e.maxVertices ?? 0,
16
+ e.maxTriangles ?? 0,
17
+ e.maxBytes ?? 0
18
+ ]) (!Number.isSafeInteger(n) || n < 0) && t("range", "limits must be non-negative integers");
19
+ let n = e.origin;
20
+ n !== void 0 && n !== "auto" && !(Array.isArray(n) && n.length === 3 && n.every(Number.isFinite)) && t("range", "origin must be 'auto' or three finite numbers");
21
+ }
22
+ function c(r, o = {}) {
23
+ n(r), s(o);
24
+ let { api: c, id: d } = r, f = o.maxVertices ?? 8e6, p = o.maxTriangles ?? 16e6;
25
+ i(o.signal);
26
+ let m = [], h = [], g = [], _ = [], v = Array.isArray(o.origin) ? [
27
+ o.origin[0],
28
+ o.origin[1],
29
+ o.origin[2]
30
+ ] : o.origin === "auto" ? void 0 : [
31
+ 0,
32
+ 0,
33
+ 0
34
+ ], y;
35
+ e("reading meshes", () => c.StreamAllMeshes(d, (e) => {
36
+ if (!y) try {
37
+ i(o.signal);
38
+ let n = c.GetLine(d, e.expressID), r = c.GetNameFromTypeCode(c.GetLineType(d, e.expressID)), a = {
39
+ expressID: e.expressID,
40
+ type: r
41
+ };
42
+ typeof n?.GlobalId?.value == "string" && (a.globalId = n.GlobalId.value), typeof n?.Name?.value == "string" && (a.name = n.Name.value), _.push(a);
43
+ for (let n = 0; n < e.geometries.size(); n++) {
44
+ let i = e.geometries.get(n), o = c.GetGeometry(d, i.geometryExpressID);
45
+ try {
46
+ let n = c.GetVertexArray(o.GetVertexData(), o.GetVertexDataSize()), s = c.GetIndexArray(o.GetIndexData(), o.GetIndexDataSize());
47
+ (n.length % 6 || s.length % 3) && t("range", "invalid geometry layout; export the file again");
48
+ let d = n.length / 6, _ = m.length / 3, y = h.length, b = i.flatTransformation;
49
+ (_ + d > f || y / 3 + s.length / 3 > p) && t("limit", "geometry exceeds vertex or triangle limit; raise maxVertices or maxTriangles");
50
+ let x = l(b);
51
+ v ??= [
52
+ Math.round(b[12]),
53
+ Math.round(b[13]),
54
+ Math.round(b[14])
55
+ ];
56
+ for (let e = 0; e < d; e++) {
57
+ let r = n[e * 6], i = n[e * 6 + 1], a = n[e * 6 + 2];
58
+ for (let e = 0; e < 3; e++) {
59
+ let n = Math.fround(b[e] * r + b[4 + e] * i + b[8 + e] * a + b[12 + e] - v[e]);
60
+ Number.isFinite(n) || t("range", "non-finite vertex; export the file again"), m.push(n);
61
+ }
62
+ }
63
+ for (let e = 0; e < s.length; e += 3) {
64
+ let n = s[e], r = s[e + 1], i = s[e + 2];
65
+ (n >= d || r >= d || i >= d) && t("range", "index outside geometry; export the file again"), h.push(_ + n, _ + (x < 0 ? i : r), _ + (x < 0 ? r : i));
66
+ }
67
+ let S = u(i.color);
68
+ s.length && g.push({
69
+ start: y,
70
+ count: s.length,
71
+ objectId: String(e.expressID),
72
+ name: a.name ?? `${r} #${e.expressID}`,
73
+ color: S
74
+ });
75
+ } finally {
76
+ o.delete();
77
+ }
78
+ }
79
+ } catch (e) {
80
+ y = e;
81
+ }
82
+ }, !0)), y && e("reading a mesh", () => {
83
+ throw y;
84
+ }), i(o.signal), h.length || t("unsupported", "model contains no renderable triangles; check it has body representations");
85
+ let b = new Float32Array(m), x = new Uint32Array(h);
86
+ return {
87
+ kind: "mesh",
88
+ positions: b,
89
+ indices: x,
90
+ normals: a(b, x),
91
+ groups: g,
92
+ products: _,
93
+ schema: r.schema,
94
+ origin: v ?? [
95
+ 0,
96
+ 0,
97
+ 0
98
+ ]
99
+ };
100
+ }
101
+ function l(e) {
102
+ (e.length !== 16 || !Array.prototype.every.call(e, Number.isFinite) || e[3] !== 0 || e[7] !== 0 || e[11] !== 0 || e[15] !== 1) && t("range", "invalid affine placement; export the file again");
103
+ let n = e[0] * (e[5] * e[10] - e[6] * e[9]) - e[4] * (e[1] * e[10] - e[2] * e[9]) + e[8] * (e[1] * e[6] - e[2] * e[5]);
104
+ return (!Number.isFinite(n) || n === 0) && t("range", "singular placement; export the file again"), n;
105
+ }
106
+ function u({ x: e, y: n, z: r, w: i }) {
107
+ let a = [
108
+ e,
109
+ n,
110
+ r,
111
+ i
112
+ ];
113
+ return a.some((e) => !Number.isFinite(e) || e < 0 || e > 1) && t("range", "invalid surface color; export the file again"), a;
114
+ }
115
+ //#endregion
116
+ export { u as checkColor, l as checkPlacement, r as openIFC, o as parseIFC, c as readIFCGeometry };
@@ -0,0 +1,75 @@
1
+ import { type IFCModel } from './open.js';
2
+ /** One representation's triangles in its own coordinates (meters, engine axes): web-ifc's geometryExpressID. */
3
+ export interface IFCMeshGeometry {
4
+ positions: Float32Array;
5
+ normals: Float32Array;
6
+ indices: Uint32Array;
7
+ }
8
+ /** One placed geometry of an element. */
9
+ export interface IFCPlacement {
10
+ /** The element's expressID. */
11
+ element: number;
12
+ /** Key into `geometries`. */
13
+ geometry: number;
14
+ /** Column-major placement, translation already rebased by `origin` in float64. */
15
+ matrix: Float64Array;
16
+ /** Surface colour, sRGB and alpha, 0..1. */
17
+ color: [number, number, number, number];
18
+ }
19
+ /** What readIFCMeshes returns: structured-cloneable, so a worker can read it. */
20
+ export interface IFCMeshes {
21
+ schema: string;
22
+ /** The point subtracted from every placement (engine axes, meters). */
23
+ origin: [number, number, number];
24
+ geometries: Map<number, IFCMeshGeometry>;
25
+ placements: IFCPlacement[];
26
+ }
27
+ /** Options of readIFCMeshes and streamIFCMeshes. */
28
+ export interface IFCMeshOptions {
29
+ signal?: AbortSignal;
30
+ /** As readIFCGeometry's `origin`. Default none. */
31
+ origin?: 'auto' | readonly [number, number, number];
32
+ /** Only these elements (expressIDs, for example one storey's from readIFCData). Default every IfcProduct. */
33
+ elements?: Iterable<number>;
34
+ /** Read IfcSpace volumes too. Default false. IfcOpeningElement voids are never read. */
35
+ spaces?: boolean;
36
+ /**
37
+ * `'envelope'` reads walls, slabs, roofs and curtain walls first, then the other building elements, then the rest
38
+ * (furniture, services, proxies), each in file order, so the first chunks already show the building's shell;
39
+ * `'file'` reads in file (expressID) order. Default `'envelope'`.
40
+ */
41
+ order?: 'envelope' | 'file';
42
+ }
43
+ /** Options of streamIFCMeshes. */
44
+ export interface IFCStreamOptions extends IFCMeshOptions {
45
+ /** Elements read per chunk, 1 to 1,000,000. Default 256. */
46
+ chunk?: number;
47
+ }
48
+ /**
49
+ * One chunk of streamIFCMeshes: the placements of the elements read since the last chunk and the geometries first
50
+ * used by them (a geometry a later chunk places again is not sent again). `loaded` of `total` elements are read.
51
+ */
52
+ export interface IFCMeshChunk extends IFCMeshes {
53
+ loaded: number;
54
+ total: number;
55
+ }
56
+ /**
57
+ * The chunks of a mesh read, one per `chunk` elements. Chunks with no placements are left out, except the last,
58
+ * whose `loaded` equals `total`. @internal
59
+ */
60
+ export declare function meshChunks(model: IFCModel, options?: IFCStreamOptions): Generator<IFCMeshChunk>;
61
+ /**
62
+ * Reads every product's placed geometries from an open model, each distinct geometry once: the input of
63
+ * createIFCScene. The model stays open. The result equals streamIFCMeshes' chunks joined.
64
+ */
65
+ export declare function readIFCMeshes(model: IFCModel, options?: IFCMeshOptions): IFCMeshes;
66
+ /**
67
+ * Reads an open model's meshes `chunk` elements at a time (default 256), yielding to the event loop between chunks so
68
+ * the page keeps drawing: create the scene from the first chunk and `add` each later one, and the building appears
69
+ * while the rest is read. Each chunk carries `loaded` and `total` for a progress bar. Aborting the signal rejects the
70
+ * next step with LoaderError code `aborted`; the model stays open (it is the caller's). Every chunk structured-clones,
71
+ * so streamIFCInWorker (`/worker`) yields the same chunks from a worker.
72
+ */
73
+ export declare function streamIFCMeshes(model: IFCModel, options?: IFCStreamOptions): AsyncGenerator<IFCMeshChunk, void, undefined>;
74
+ /** @internal One web-ifc geometry as positions, normals and indices; undefined when it has no triangles. */
75
+ export declare function readGeometry(model: IFCModel, geometryId: number): IFCMeshGeometry | undefined;
@@ -0,0 +1,181 @@
1
+ import { LoaderError as e } from "@margoengine/loaders/common";
2
+ //#region src/step.ts
3
+ var t = 64, n = (e) => e === 32 || e === 9 || e === 10 || e === 13, r = (e) => e >= 48 && e <= 57, i = (e) => e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 95, a = (e) => i(e) || r(e) || e === 45, o = 0, s = 1, c = 2, l = 3, u = 4, d = 5, f = 6, p = 7, m = 8;
4
+ function h(e) {
5
+ let h = e.length, g = 0, _ = o, v = 0, y = () => {
6
+ for (;;) {
7
+ for (; g < h && n(e[g]);) g++;
8
+ if (e[g] === 47 && e[g + 1] === 42) {
9
+ let t = e.indexOf(42, g + 2);
10
+ for (; t >= 0 && e[t + 1] !== 47;) t = e.indexOf(42, t + 1);
11
+ if (t < 0) return !1;
12
+ g = t + 2;
13
+ } else break;
14
+ }
15
+ if (v = g, g >= h) return _ = o, !0;
16
+ let t = e[g];
17
+ if (t === 40) _ = u, g++;
18
+ else if (t === 41) _ = d, g++;
19
+ else if (t === 44) _ = f, g++;
20
+ else if (t === 59) _ = p, g++;
21
+ else if (t === 61) _ = m, g++;
22
+ else if (t === 36 || t === 42) _ = l, g++;
23
+ else if (t === 35) {
24
+ if (!r(e[++g])) return !1;
25
+ for (; r(e[g]);) g++;
26
+ _ = c;
27
+ } else if (t === 39) {
28
+ for (g++;; g++) {
29
+ if (g >= h) return !1;
30
+ if (e[g] === 39) {
31
+ if (e[g + 1] !== 39) break;
32
+ g++;
33
+ }
34
+ }
35
+ g++, _ = l;
36
+ } else if (t === 34) {
37
+ for (g++; g < h && e[g] !== 34; g++) if (!r(e[g]) && !((e[g] | 32) >= 97 && (e[g] | 32) <= 102)) return !1;
38
+ if (g++ >= h) return !1;
39
+ _ = l;
40
+ } else if (t === 46) {
41
+ if (!i(e[++g])) return !1;
42
+ for (; i(e[g]) || r(e[g]);) g++;
43
+ if (e[g++] !== 46) return !1;
44
+ _ = l;
45
+ } else if (r(t) || t === 43 || t === 45) {
46
+ if (r(t) || g++, !r(e[g])) return !1;
47
+ for (; r(e[g]);) g++;
48
+ if (e[g] === 46) for (; r(e[++g]););
49
+ if (e[g] === 69 || e[g] === 101) {
50
+ if ((e[g + 1] === 43 || e[g + 1] === 45) && g++, !r(e[++g])) return !1;
51
+ for (; r(e[g]);) g++;
52
+ }
53
+ _ = l;
54
+ } else if (i(t) || t === 33) {
55
+ for (g++; a(e[g]); g++);
56
+ _ = s;
57
+ } else return !1;
58
+ let y = e[g];
59
+ return !(_ !== u && _ !== d && _ !== f && _ !== p && _ !== m && g < h && !n(y) && y !== 40 && y !== 41 && y !== 44 && y !== 59 && y !== 61 && y !== 47);
60
+ }, b = () => _, x = (e) => `${e} at byte ${v}`, S = (e) => {
61
+ let n = [e ? 2 : 1], r = !0, i = !0;
62
+ for (; n.length;) {
63
+ if (!y()) return x("invalid token");
64
+ if (n[n.length - 1] === 2) {
65
+ if (b() === d) {
66
+ n.pop(), r = !1, i = !1;
67
+ continue;
68
+ }
69
+ if (b() !== s || !y() || b() !== u) return x("expected a record in a complex entity");
70
+ if (n.push(1) > t) return x("lists nest too deeply");
71
+ r = !0, i = !0;
72
+ } else if (r) {
73
+ if (b() === d && i) {
74
+ n.pop(), r = !1, i = !1;
75
+ continue;
76
+ }
77
+ if (b() === l || b() === c) r = !1;
78
+ else if (b() === u) {
79
+ if (n.push(1) > t) return x("lists nest too deeply");
80
+ i = !0;
81
+ continue;
82
+ } else if (b() === s) {
83
+ if (!y() || b() !== u) return x("expected ( after a typed parameter");
84
+ if (n.push(1) > t) return x("lists nest too deeply");
85
+ i = !0;
86
+ continue;
87
+ } else return x("expected a parameter");
88
+ i = !1;
89
+ } else if (b() === f) r = !0;
90
+ else if (b() === d) n.pop(), r = !1, i = !1;
91
+ else return x("expected , or ) between parameters");
92
+ }
93
+ return null;
94
+ };
95
+ for (;;) {
96
+ if (!y()) return x("invalid token");
97
+ if (b() === o) return null;
98
+ let e = null;
99
+ if (b() === c) {
100
+ if (!y() || b() !== m) return x("expected = after an instance name");
101
+ if (!y()) return x("invalid token");
102
+ if (b() === u) e = S(!0);
103
+ else if (b() === s) {
104
+ if (!y() || b() !== u) return x("expected ( after an entity name");
105
+ e = S(!1);
106
+ } else return x("expected an entity after =");
107
+ } else if (b() === s) {
108
+ if (!y()) return x("invalid token");
109
+ if (b() === u) e = S(!1);
110
+ else if (b() === p) continue;
111
+ else return x("expected ( or ; after a keyword");
112
+ } else return x("expected a statement");
113
+ if (e) return e;
114
+ if (!y() || b() !== p) return x("expected ; after a statement");
115
+ }
116
+ }
117
+ //#endregion
118
+ //#region src/open.ts
119
+ var g = (t, n) => {
120
+ throw new e("IFC", t, n);
121
+ }, _ = (e) => {
122
+ e?.aborted && g("aborted", "aborted; pass a signal that is not aborted to read the model");
123
+ };
124
+ function v(t, n) {
125
+ try {
126
+ return n();
127
+ } catch (n) {
128
+ if (n instanceof e) throw n;
129
+ let r = n instanceof WebAssembly.RuntimeError ? "Wasm trap" : n?.name || "Error";
130
+ throw Object.assign(new e("IFC", "unsupported", `web-ifc failed while ${t} (${r}: ${n?.message})`), { cause: n });
131
+ }
132
+ }
133
+ var y = /* @__PURE__ */ new WeakMap();
134
+ function b(e) {
135
+ let t = y.get(e.api);
136
+ t || y.set(e.api, t = /* @__PURE__ */ new Map());
137
+ let n = t.get(e.id);
138
+ return n || t.set(e.id, n = /* @__PURE__ */ new Set()), n;
139
+ }
140
+ function x(e) {
141
+ (!e || typeof e.id != "number" || !e.api) && g("range", "expected an IFCModel; call openIFC first"), e.closed && g("range", "the IFC model is closed; open it again with openIFC");
142
+ }
143
+ function S(e, t, n = {}) {
144
+ let r = n.maxBytes ?? 268435456;
145
+ (!Number.isSafeInteger(r) || r < 0) && g("range", "limits must be non-negative integers"), _(n.signal), (!e || typeof e.OpenModel != "function") && g("range", "expected an initialized web-ifc IfcAPI; call Init() first"), t instanceof Uint8Array || g("range", "expected Uint8Array; pass the file bytes"), t.byteLength > r && g("limit", "input exceeds maxBytes; raise maxBytes or pass a smaller file"), /^\s*ISO-10303-21;/i.test(new TextDecoder().decode(t.subarray(0, 128))) || g("header", "expected a STEP IFC file starting with ISO-10303-21;");
146
+ let i = h(t);
147
+ i && g("syntax", `malformed STEP: ${i}; export the file again`);
148
+ let a = v("opening the model", () => e.OpenModel(t, {
149
+ ALLOW_INCOMPATIBLE_SCHEMA_ALIASES: !1,
150
+ ...n.settings
151
+ }));
152
+ (a < 0 || !v("opening the model", () => e.IsModelOpen(a))) && g("unsupported", "web-ifc could not open the model; check the schema is IFC2X3, IFC4 or IFC4X3");
153
+ let o;
154
+ try {
155
+ o = v("reading the schema", () => e.GetModelSchema(a));
156
+ } catch (t) {
157
+ try {
158
+ e.CloseModel(a);
159
+ } catch {}
160
+ throw t;
161
+ }
162
+ let s = !1, c = () => {
163
+ if (!s) {
164
+ s = !0, y.get(e)?.delete(a);
165
+ try {
166
+ e.CloseModel(a);
167
+ } catch {}
168
+ }
169
+ }, l = {
170
+ api: e,
171
+ id: a,
172
+ schema: o,
173
+ get closed() {
174
+ return s;
175
+ },
176
+ close: c
177
+ };
178
+ return typeof Symbol.dispose == "symbol" && Object.defineProperty(l, Symbol.dispose, { value: c }), l;
179
+ }
180
+ //#endregion
181
+ export { v as a, g as i, x as n, S as o, b as r, h as s, _ as t };
package/dist/open.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { IfcAPI, LoaderSettings } from 'web-ifc';
3
+ /** Options of openIFC: an input size limit, an AbortSignal and native web-ifc settings. */
4
+ export interface IFCOpenOptions {
5
+ /** Inputs larger than this reject with `LoaderError` code `limit`. Default 256 MiB. */
6
+ maxBytes?: number;
7
+ signal?: AbortSignal;
8
+ /** Native web-ifc settings. Model coordinates are kept unless COORDINATE_TO_ORIGIN is set. */
9
+ settings?: LoaderSettings;
10
+ }
11
+ /** An open web-ifc model. `close()` (or `using`) releases it; readers reject on a closed model. */
12
+ export interface IFCModel {
13
+ readonly api: IfcAPI;
14
+ /** web-ifc's model ID. */
15
+ readonly id: number;
16
+ /** Schema name from the file header, such as `IFC2X3`, `IFC4` or `IFC4X3_ADD2`. */
17
+ readonly schema: string;
18
+ readonly closed: boolean;
19
+ close(): void;
20
+ [Symbol.dispose](): void;
21
+ }
22
+ export type IFCErrorCode = 'range' | 'limit' | 'header' | 'syntax' | 'unsupported' | 'aborted';
23
+ export declare const fail: (code: IFCErrorCode, message: string) => never;
24
+ export declare const checkAbort: (signal?: AbortSignal) => void;
25
+ /** Runs a web-ifc call; its own failures (a JS TypeError from its API layer, a Wasm trap) become named errors. */
26
+ export declare function native<T>(what: string, call: () => T): T;
27
+ /**
28
+ * expressIDs of the lines deleted from an open model through this package. web-ifc 0.0.78 keeps a deleted line in
29
+ * GetLineIDsWithType (GetAllLines and SaveModel drop it), so readers leave these out.
30
+ */
31
+ export declare function deletedLines(model: IFCModel): Set<number>;
32
+ /** Throws unless `model` is an open handle from openIFC. */
33
+ export declare function checkModel(model: IFCModel): void;
34
+ /**
35
+ * Checks and opens IFC bytes with an initialized, caller-owned web-ifc API. The bytes must be well-formed
36
+ * ISO 10303-21 first (web-ifc 0.0.78 loops forever on some malformed parameter lists), so a syntax error is
37
+ * `LoaderError` code `syntax`. Close the handle when done: `using model = openIFC(api, bytes)`.
38
+ */
39
+ export declare function openIFC(api: IfcAPI, data: Uint8Array, options?: IFCOpenOptions): IFCModel;
@@ -0,0 +1,2 @@
1
+ export declare const IFC4_PREDEFINED_ENUMS = "DoorPanelProperties:PanelOperation=DoorPanelOperationEnum,PanelPosition=DoorPanelPositionEnum PermeableCoveringProperties:OperationType=PermeableCoveringOperationEnum,PanelPosition=WindowPanelPositionEnum WindowPanelProperties:OperationType=WindowPanelOperationEnum,PanelPosition=WindowPanelPositionEnum";
2
+ export declare const IFC4X3_PREDEFINED_ENUMS = "DoorPanelProperties:PanelOperation=DoorPanelOperationEnum,PanelPosition=DoorPanelPositionEnum PermeableCoveringProperties:OperationType=PermeableCoveringOperationEnum,PanelPosition=WindowPanelPositionEnum WindowPanelProperties:OperationType=WindowPanelOperationEnum,PanelPosition=WindowPanelPositionEnum";
@@ -0,0 +1,62 @@
1
+ import { type IFCData, type IFCElement, type IFCValue } from './data.js';
2
+ export { nearlyEqual } from './tolerance.js';
3
+ export { isSubtypeOf, subtypesOf, supertypesOf, type IFCSchemaSource } from './schema.js';
4
+ /** A condition on one property or quantity (type properties included). Values compare in SI. */
5
+ export interface IFCPropertyCondition {
6
+ /** Property set or quantity set name; any set when omitted. */
7
+ set?: string | RegExp;
8
+ name: string | RegExp;
9
+ /** Default `exists` without a value, `=` with one. */
10
+ op?: '=' | '!=' | '<' | '<=' | '>' | '>=' | 'contains' | 'matches' | 'exists' | 'missing';
11
+ value?: IFCValue | RegExp;
12
+ }
13
+ /** What findElements matches; every given field must hold. Names and classes compare without case. */
14
+ export interface IFCQuery {
15
+ /**
16
+ * IFC class names, such as `IfcWall` or `IFCWALL`. Subtypes match too, by the model's schema (`IfcWall` finds
17
+ * `IfcWallStandardCase`, `IfcBuildingElement` finds every wall, slab and door), unless `subtypes` is false. IFC2X3
18
+ * models follow the inheritance readIFCData recorded from the runtime (`IFCData.inheritance`).
19
+ */
20
+ type?: string | readonly string[];
21
+ /** Match subtypes of `type` (default true); false matches the exact classes only, as an IDS entity facet does. */
22
+ subtypes?: boolean;
23
+ /** Effective predefined type (see effectivePredefinedType). */
24
+ predefinedType?: string | readonly string[];
25
+ /** The assigned IfcTypeObject, by expressID or name. */
26
+ typeObject?: number | string;
27
+ /** The element's storey, by expressID or name. */
28
+ storey?: number | string | readonly (number | string)[];
29
+ /** Any ancestor up the containment and aggregation chain (a building, a space, an assembly), by expressID. */
30
+ within?: number;
31
+ name?: string | RegExp;
32
+ globalId?: string | readonly string[];
33
+ /** A material, layer, profile or constituent name or category. */
34
+ material?: string | RegExp;
35
+ classification?: {
36
+ system?: string | RegExp;
37
+ code?: string | RegExp;
38
+ };
39
+ where?: readonly IFCPropertyCondition[];
40
+ /** Leave out type objects (default true): they are definitions, not placed elements. */
41
+ occurrencesOnly?: boolean;
42
+ filter?: (element: IFCElement, data: IFCData) => boolean;
43
+ }
44
+ /** A grouping key of groupElements, or a property whose value is the key. */
45
+ export type IFCGroupBy = 'type' | 'predefinedType' | 'typeObject' | 'storey' | 'material' | 'classification' | {
46
+ set: string;
47
+ name: string;
48
+ };
49
+ /** The predefined type as IDS 1.0 resolves it: the type object's first, then the element's own; USERDEFINED takes the custom name (a type's ElementType, ProcessType or ResourceType, an occurrence's ObjectType). */
50
+ export declare function effectivePredefinedType(data: IFCData, id: number): string | undefined;
51
+ /** The chain of wholes above an element: container, aggregate, nest, the opening it fills, the element it voids. */
52
+ export declare function ancestorsOf(data: IFCData, id: number): number[];
53
+ /** Every element below a spatial element or assembly (contained, aggregated, nested), in expressID order. */
54
+ export declare function descendantsOf(data: IFCData, id: number): number[];
55
+ /** The IDs of the elements that match every field of `query`, in expressID order. */
56
+ export declare function findElements(data: IFCData, query?: IFCQuery): number[];
57
+ /**
58
+ * Groups elements by a key, as a classifier tree does: class, predefined type, type object, storey, material,
59
+ * classification code or a property's value. An element with several materials or classifications is in each of
60
+ * their groups; one without the key is under `''`. `ids` limits the grouping (default: every occurrence).
61
+ */
62
+ export declare function groupElements(data: IFCData, by: IFCGroupBy, ids?: Iterable<number>): Map<string, number[]>;
package/dist/query.js ADDED
@@ -0,0 +1,92 @@
1
+ import { a as e, s as t, t as n } from "./data-CuTaQPFm.js";
2
+ import { n as r, r as i, t as a } from "./schema-B_VBQpdF.js";
3
+ import { t as o } from "./tolerance-CAOnp3Mo.js";
4
+ //#region src/query.ts
5
+ var s = (e) => e === void 0 ? void 0 : Array.isArray(e) ? e : [e], c = (e, t) => e !== void 0 && e.toUpperCase() === t.toUpperCase(), l = (e, t) => t === void 0 ? !1 : typeof e == "string" ? t === e : (e.lastIndex = 0, e.test(t)), u = (e) => e.type.toUpperCase().endsWith("TYPE") || e.type.toUpperCase().endsWith("STYLE");
6
+ function d(e, t) {
7
+ let n = e.elements.get(t);
8
+ if (!n) return;
9
+ let r = (e, t) => e.predefinedType === "USERDEFINED" ? t ?? "USERDEFINED" : e.predefinedType === "NOTDEFINED" ? void 0 : e.predefinedType, i = n.typeId === void 0 ? void 0 : e.elements.get(n.typeId);
10
+ return (i && r(i, i.elementType)) ?? r(n, u(n) ? n.elementType : n.objectType);
11
+ }
12
+ function f(e, t) {
13
+ let n = [], r = /* @__PURE__ */ new Set([t]);
14
+ for (let i = e.elements.get(t); i;) {
15
+ let t = i.container ?? i.aggregate ?? i.nest ?? i.fills ?? i.voids;
16
+ if (t === void 0 || r.has(t)) break;
17
+ r.add(t), n.push(t), i = e.elements.get(t);
18
+ }
19
+ return n;
20
+ }
21
+ function p(e, t) {
22
+ let n = /* @__PURE__ */ new Map();
23
+ for (let t of e.elements.values()) {
24
+ let e = t.container ?? t.aggregate ?? t.nest;
25
+ e !== void 0 && (n.get(e) ?? n.set(e, []).get(e)).push(t.id);
26
+ }
27
+ let r = [], i = [t], a = /* @__PURE__ */ new Set([t]);
28
+ for (; i.length;) for (let e of n.get(i.pop()) ?? []) a.has(e) || (a.add(e), r.push(e), i.push(e));
29
+ return r.sort((e, t) => e - t);
30
+ }
31
+ function m(e, t) {
32
+ let n = t.op ?? (t.value === void 0 ? "exists" : "="), r = (e) => e === null || e === "" || Array.isArray(e) && !e.length;
33
+ if (n === "missing") return !e || r(e.value);
34
+ if (!e || r(e.value)) return !1;
35
+ if (n === "exists") return !0;
36
+ let i = [], a = (e) => Array.isArray(e) ? e.forEach(a) : i.push(e);
37
+ a(e.value);
38
+ let s = t.value, c = (e) => s instanceof RegExp ? typeof e == "string" && l(s, e) : n === "contains" ? typeof e == "string" && typeof s == "string" && e.toLowerCase().includes(s.toLowerCase()) : n === "matches" ? typeof e == "string" && typeof s == "string" && new RegExp(s).test(e) : typeof e == "number" && typeof s == "number" ? n === "=" ? o(e, s) : n === "!=" ? !o(e, s) : n === "<" ? e < s && !o(e, s) : n === "<=" ? e <= s || o(e, s) : n === ">" ? e > s && !o(e, s) : e >= s || o(e, s) : n === "=" ? e === s : n === "!=" && e !== s;
39
+ return n === "!=" ? i.every(c) : i.some(c);
40
+ }
41
+ function h(r, i = {}) {
42
+ let o = s(i.type), p = s(i.predefinedType), h = s(i.storey), g = s(i.globalId), _ = typeof i.typeObject == "string" ? [...r.elements.values()].filter((e) => e.name === i.typeObject && u(e)).map((e) => e.id) : i.typeObject === void 0 ? void 0 : [i.typeObject], v = h && new Set(h.flatMap((e) => typeof e == "number" ? [e] : [...r.elements.values()].filter((t) => c(t.type, "IfcBuildingStorey") && t.name === e).map((e) => e.id))), y = [];
43
+ for (let s of r.elements.values()) if (!((i.occurrencesOnly ?? !0) && u(s)) && (!o || o.some((e) => i.subtypes ?? !0 ? a(r, s.type, e) : c(s.type, e))) && (!p || p.some((e) => c(d(r, s.id), e))) && (!_ || s.typeId !== void 0 && _.includes(s.typeId)) && (!v || s.storey !== void 0 && v.has(s.storey)) && (i.within === void 0 || f(r, s.id).includes(i.within)) && (i.name === void 0 || l(i.name, s.name)) && (!g || s.globalId !== void 0 && g.includes(s.globalId))) {
44
+ if (i.material !== void 0) {
45
+ let t = i.material;
46
+ if (!e(r, s.id).some((e) => l(t, e.name) || l(t, e.category) || l(t, e.part))) continue;
47
+ }
48
+ if (i.classification) {
49
+ let { system: e, code: t } = i.classification;
50
+ if (!n(r, s.id).some((n) => (e === void 0 || l(e, n.system)) && (t === void 0 || l(t, n.code)))) continue;
51
+ }
52
+ if (i.where?.length) {
53
+ let e = t(r, s.id);
54
+ if (!i.where.every((t) => {
55
+ let n = Object.entries(e).filter(([e]) => t.set === void 0 || l(t.set, e)).flatMap(([, e]) => Object.values(e).filter((e) => l(t.name, e.name)));
56
+ return (t.op ?? "") === "missing" ? n.every((e) => m(e, t)) : n.some((e) => m(e, t));
57
+ })) continue;
58
+ }
59
+ (!i.filter || i.filter(s, r)) && y.push(s.id);
60
+ }
61
+ return y;
62
+ }
63
+ function g(r, i, a = h(r)) {
64
+ let o = /* @__PURE__ */ new Map(), s = (e, t) => {
65
+ let n = o.get(e) ?? o.set(e, []).get(e);
66
+ n[n.length - 1] !== t && n.push(t);
67
+ }, c = (e) => e === void 0 ? "" : r.elements.get(e)?.name ?? `#${e}`;
68
+ for (let o of a) {
69
+ let a = r.elements.get(o);
70
+ if (a) {
71
+ if (i === "type") s(a.type, o);
72
+ else if (i === "predefinedType") s(d(r, o) ?? "", o);
73
+ else if (i === "typeObject") s(c(a.typeId), o);
74
+ else if (i === "storey") s(c(a.storey), o);
75
+ else if (i === "material") {
76
+ let t = e(r, o);
77
+ t.length || s("", o);
78
+ for (let e of t) s(e.name, o);
79
+ } else if (i === "classification") {
80
+ let e = n(r, o);
81
+ e.length || s("", o);
82
+ for (let t of e) s(t.code ?? t.name ?? "", o);
83
+ } else {
84
+ let e = t(r, o)[i.set]?.[i.name]?.value;
85
+ s(e == null ? "" : String(e), o);
86
+ }
87
+ }
88
+ }
89
+ return o;
90
+ }
91
+ //#endregion
92
+ export { f as ancestorsOf, p as descendantsOf, d as effectivePredefinedType, h as findElements, g as groupElements, a as isSubtypeOf, o as nearlyEqual, r as subtypesOf, i as supertypesOf };
package/dist/raw.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /** A decoded IFC value: text, number, boolean (null for LOGICAL UNKNOWN), or a list of them. */
2
+ export type RawValue = string | number | boolean | null | RawValue[];
3
+ export type Raw = any;
4
+ export declare const refOf: (v: Raw) => number | undefined;
5
+ export declare const refsOf: (v: Raw) => number[];
6
+ export declare const text: (v: Raw) => string | undefined;
7
+ export declare const decode: (v: Raw) => RawValue | undefined;