@ifc-lite/export 6.0.0 → 7.0.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.
Files changed (202) hide show
  1. package/README.md +42 -20
  2. package/dist/anonymize-types.d.ts +2 -0
  3. package/dist/anonymize-types.d.ts.map +1 -1
  4. package/dist/declared-property-type.d.ts +2 -110
  5. package/dist/declared-property-type.d.ts.map +1 -1
  6. package/dist/declared-property-type.js +15 -0
  7. package/dist/declared-property-type.js.map +1 -1
  8. package/dist/energy-artifact.d.ts +6 -0
  9. package/dist/energy-artifact.d.ts.map +1 -0
  10. package/dist/energy-artifact.js +33 -0
  11. package/dist/energy-artifact.js.map +1 -0
  12. package/dist/generated/ifc4-required-slots.d.ts +4 -1
  13. package/dist/generated/ifc4-required-slots.d.ts.map +1 -1
  14. package/dist/generated/ifc4-required-slots.js +704 -0
  15. package/dist/generated/ifc4-required-slots.js.map +1 -1
  16. package/dist/geometry-diagnostics.d.ts +14 -0
  17. package/dist/geometry-diagnostics.d.ts.map +1 -0
  18. package/dist/geometry-diagnostics.js +29 -0
  19. package/dist/geometry-diagnostics.js.map +1 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +7 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/merged-exporter.d.ts +1 -4
  25. package/dist/merged-exporter.d.ts.map +1 -1
  26. package/dist/merged-exporter.js +39 -23
  27. package/dist/merged-exporter.js.map +1 -1
  28. package/dist/merged-header.d.ts +2 -1
  29. package/dist/merged-header.d.ts.map +1 -1
  30. package/dist/merged-header.js +8 -0
  31. package/dist/merged-header.js.map +1 -1
  32. package/dist/merged-inherited-units.d.ts +8 -0
  33. package/dist/merged-inherited-units.d.ts.map +1 -0
  34. package/dist/merged-inherited-units.js +117 -0
  35. package/dist/merged-inherited-units.js.map +1 -0
  36. package/dist/merged-inverse-claims.d.ts +5 -6
  37. package/dist/merged-inverse-claims.d.ts.map +1 -1
  38. package/dist/merged-inverse-claims.js +29 -10
  39. package/dist/merged-inverse-claims.js.map +1 -1
  40. package/dist/merged-profile-units.d.ts +9 -0
  41. package/dist/merged-profile-units.d.ts.map +1 -0
  42. package/dist/merged-profile-units.js +44 -0
  43. package/dist/merged-profile-units.js.map +1 -0
  44. package/dist/related-entities.d.ts.map +1 -1
  45. package/dist/related-entities.js +11 -9
  46. package/dist/related-entities.js.map +1 -1
  47. package/dist/rust-artifact.d.ts +4 -0
  48. package/dist/rust-artifact.d.ts.map +1 -0
  49. package/dist/rust-artifact.js +15 -0
  50. package/dist/rust-artifact.js.map +1 -0
  51. package/dist/schema-calendar-date-values.d.ts +1 -0
  52. package/dist/schema-calendar-date-values.d.ts.map +1 -1
  53. package/dist/schema-calendar-date-values.js +4 -4
  54. package/dist/schema-calendar-date-values.js.map +1 -1
  55. package/dist/schema-calendar-dates.d.ts +16 -1
  56. package/dist/schema-calendar-dates.d.ts.map +1 -1
  57. package/dist/schema-calendar-dates.js +118 -19
  58. package/dist/schema-calendar-dates.js.map +1 -1
  59. package/dist/schema-conversion-loss-description.d.ts.map +1 -1
  60. package/dist/schema-conversion-loss-description.js +3 -0
  61. package/dist/schema-conversion-loss-description.js.map +1 -1
  62. package/dist/schema-conversion-loss-report.d.ts.map +1 -1
  63. package/dist/schema-conversion-loss-report.js +25 -36
  64. package/dist/schema-conversion-loss-report.js.map +1 -1
  65. package/dist/schema-conversion-loss-varying.d.ts +11 -0
  66. package/dist/schema-conversion-loss-varying.d.ts.map +1 -0
  67. package/dist/schema-conversion-loss-varying.js +44 -0
  68. package/dist/schema-conversion-loss-varying.js.map +1 -0
  69. package/dist/schema-converter-attr-maps.d.ts +6 -5
  70. package/dist/schema-converter-attr-maps.d.ts.map +1 -1
  71. package/dist/schema-converter-attr-maps.js +8 -6
  72. package/dist/schema-converter-attr-maps.js.map +1 -1
  73. package/dist/schema-converter-durations.d.ts +0 -3
  74. package/dist/schema-converter-durations.d.ts.map +1 -1
  75. package/dist/schema-converter-durations.js +0 -18
  76. package/dist/schema-converter-durations.js.map +1 -1
  77. package/dist/schema-converter-enums.d.ts +6 -3
  78. package/dist/schema-converter-enums.d.ts.map +1 -1
  79. package/dist/schema-converter-enums.js +25 -9
  80. package/dist/schema-converter-enums.js.map +1 -1
  81. package/dist/schema-converter-ifc4-slots.d.ts +10 -5
  82. package/dist/schema-converter-ifc4-slots.d.ts.map +1 -1
  83. package/dist/schema-converter-ifc4-slots.js +17 -20
  84. package/dist/schema-converter-ifc4-slots.js.map +1 -1
  85. package/dist/schema-converter-ifc4x3-upgrade.d.ts +5 -4
  86. package/dist/schema-converter-ifc4x3-upgrade.d.ts.map +1 -1
  87. package/dist/schema-converter-ifc4x3-upgrade.js +15 -8
  88. package/dist/schema-converter-ifc4x3-upgrade.js.map +1 -1
  89. package/dist/schema-converter-material-referent.d.ts +3 -0
  90. package/dist/schema-converter-material-referent.d.ts.map +1 -1
  91. package/dist/schema-converter-material-referent.js +24 -6
  92. package/dist/schema-converter-material-referent.js.map +1 -1
  93. package/dist/schema-converter-space-boundary.d.ts +47 -0
  94. package/dist/schema-converter-space-boundary.d.ts.map +1 -0
  95. package/dist/schema-converter-space-boundary.js +108 -0
  96. package/dist/schema-converter-space-boundary.js.map +1 -0
  97. package/dist/schema-converter-step-finish.d.ts.map +1 -1
  98. package/dist/schema-converter-step-finish.js +3 -2
  99. package/dist/schema-converter-step-finish.js.map +1 -1
  100. package/dist/schema-converter-structural-diagnostics.d.ts +6 -0
  101. package/dist/schema-converter-structural-diagnostics.d.ts.map +1 -1
  102. package/dist/schema-converter-structural-diagnostics.js +19 -4
  103. package/dist/schema-converter-structural-diagnostics.js.map +1 -1
  104. package/dist/schema-converter-structural-source.d.ts +3 -0
  105. package/dist/schema-converter-structural-source.d.ts.map +1 -1
  106. package/dist/schema-converter-structural-source.js.map +1 -1
  107. package/dist/schema-converter-structural-varying.d.ts +10 -2
  108. package/dist/schema-converter-structural-varying.d.ts.map +1 -1
  109. package/dist/schema-converter-structural-varying.js +28 -11
  110. package/dist/schema-converter-structural-varying.js.map +1 -1
  111. package/dist/schema-converter-structural.d.ts +3 -0
  112. package/dist/schema-converter-structural.d.ts.map +1 -1
  113. package/dist/schema-converter-structural.js +13 -5
  114. package/dist/schema-converter-structural.js.map +1 -1
  115. package/dist/schema-converter-typed-properties.js +1 -2
  116. package/dist/schema-converter-typed-properties.js.map +1 -1
  117. package/dist/schema-converter-unrooted-upgrade.d.ts +23 -6
  118. package/dist/schema-converter-unrooted-upgrade.d.ts.map +1 -1
  119. package/dist/schema-converter-unrooted-upgrade.js +62 -12
  120. package/dist/schema-converter-unrooted-upgrade.js.map +1 -1
  121. package/dist/schema-converter-value-forms.d.ts +28 -5
  122. package/dist/schema-converter-value-forms.d.ts.map +1 -1
  123. package/dist/schema-converter-value-forms.js +32 -19
  124. package/dist/schema-converter-value-forms.js.map +1 -1
  125. package/dist/schema-converter.d.ts +3 -4
  126. package/dist/schema-converter.d.ts.map +1 -1
  127. package/dist/schema-converter.js +25 -24
  128. package/dist/schema-converter.js.map +1 -1
  129. package/dist/schema-project-time-unit.d.ts +8 -0
  130. package/dist/schema-project-time-unit.d.ts.map +1 -0
  131. package/dist/schema-project-time-unit.js +123 -0
  132. package/dist/schema-project-time-unit.js.map +1 -0
  133. package/dist/schema-structural-varying-constant.d.ts +16 -0
  134. package/dist/schema-structural-varying-constant.d.ts.map +1 -0
  135. package/dist/schema-structural-varying-constant.js +36 -0
  136. package/dist/schema-structural-varying-constant.js.map +1 -0
  137. package/dist/schema-structural-varying-effective.d.ts +1 -1
  138. package/dist/schema-structural-varying-effective.d.ts.map +1 -1
  139. package/dist/schema-structural-varying-effective.js +12 -22
  140. package/dist/schema-structural-varying-effective.js.map +1 -1
  141. package/dist/schema-untranslatable.d.ts.map +1 -1
  142. package/dist/schema-untranslatable.js +5 -2
  143. package/dist/schema-untranslatable.js.map +1 -1
  144. package/dist/schema-work-control-durations.d.ts +13 -0
  145. package/dist/schema-work-control-durations.d.ts.map +1 -0
  146. package/dist/schema-work-control-durations.js +74 -0
  147. package/dist/schema-work-control-durations.js.map +1 -0
  148. package/dist/step-export-types.d.ts +3 -0
  149. package/dist/step-export-types.d.ts.map +1 -1
  150. package/dist/step-export-types.js.map +1 -1
  151. package/dist/step-exporter.d.ts.map +1 -1
  152. package/dist/step-exporter.js +2 -0
  153. package/dist/step-exporter.js.map +1 -1
  154. package/dist/step-omission-predicates.d.ts.map +1 -1
  155. package/dist/step-omission-predicates.js +3 -1
  156. package/dist/step-omission-predicates.js.map +1 -1
  157. package/dist/step-outer-args.d.ts +1 -1
  158. package/dist/step-outer-args.d.ts.map +1 -1
  159. package/dist/step-outer-args.js +10 -3
  160. package/dist/step-outer-args.js.map +1 -1
  161. package/dist/step-overlay-entities.d.ts.map +1 -1
  162. package/dist/step-overlay-entities.js +9 -0
  163. package/dist/step-overlay-entities.js.map +1 -1
  164. package/dist/step-pass-builder.d.ts.map +1 -1
  165. package/dist/step-pass-builder.js +21 -5
  166. package/dist/step-pass-builder.js.map +1 -1
  167. package/dist/step-property-set-readers.d.ts +4 -4
  168. package/dist/step-property-set-readers.d.ts.map +1 -1
  169. package/dist/step-property-set-readers.js +13 -13
  170. package/dist/step-property-set-readers.js.map +1 -1
  171. package/dist/step-retype-type-link.d.ts +7 -0
  172. package/dist/step-retype-type-link.d.ts.map +1 -0
  173. package/dist/step-retype-type-link.js +95 -0
  174. package/dist/step-retype-type-link.js.map +1 -0
  175. package/dist/step-source-iteration.d.ts.map +1 -1
  176. package/dist/step-source-iteration.js +10 -0
  177. package/dist/step-source-iteration.js.map +1 -1
  178. package/dist/step-subset-relations.d.ts +131 -0
  179. package/dist/step-subset-relations.d.ts.map +1 -0
  180. package/dist/step-subset-relations.js +342 -0
  181. package/dist/step-subset-relations.js.map +1 -0
  182. package/dist/step-subset-spatial-ancestors.d.ts +26 -0
  183. package/dist/step-subset-spatial-ancestors.d.ts.map +1 -0
  184. package/dist/step-subset-spatial-ancestors.js +103 -0
  185. package/dist/step-subset-spatial-ancestors.js.map +1 -0
  186. package/dist/step-subset-storey.d.ts +21 -0
  187. package/dist/step-subset-storey.d.ts.map +1 -0
  188. package/dist/step-subset-storey.js +319 -0
  189. package/dist/step-subset-storey.js.map +1 -0
  190. package/dist/step-subset.d.ts +68 -0
  191. package/dist/step-subset.d.ts.map +1 -0
  192. package/dist/step-subset.js +388 -0
  193. package/dist/step-subset.js.map +1 -0
  194. package/dist/unit-normalize.d.ts +14 -13
  195. package/dist/unit-normalize.d.ts.map +1 -1
  196. package/dist/unit-normalize.js +103 -85
  197. package/dist/unit-normalize.js.map +1 -1
  198. package/dist/xlsx-limits.d.ts +12 -0
  199. package/dist/xlsx-limits.d.ts.map +1 -0
  200. package/dist/xlsx-limits.js +48 -0
  201. package/dist/xlsx-limits.js.map +1 -0
  202. package/package.json +7 -7
@@ -0,0 +1,388 @@
1
+ // This Source Code Form is subject to the terms of the Mozilla Public
2
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ /**
5
+ * Raw STEP subset extraction: pull a handful of products out of a large IFC
6
+ * into a small, VALID, standalone model. Records are copied byte-for-byte, so a
7
+ * suspect element keeps reproducing outside the file it came from.
8
+ *
9
+ * The output carries each selected product's full forward reference closure
10
+ * PLUS the shared context roots (IfcProject, unit assignment, geometric
11
+ * contexts, and the backward closure of the selection's spatial ancestors, see
12
+ * `step-subset-spatial-ancestors.ts`) and every spatial-structure relation, its
13
+ * related-objects SET rewritten down to the kept members (see
14
+ * `step-subset-relations.ts`), so the result parses and renders on its own.
15
+ *
16
+ * Consumers: `ifc-lite extract-entities` and the MCP `model_extract` tool.
17
+ */
18
+ import { stepStringLiteralEnd } from '@ifc-lite/encoding';
19
+ import { detectSchemaVersion, expandTypes, parseSourceHeader } from '@ifc-lite/parser';
20
+ import { getIfcRootTypes } from './subset-roots.js';
21
+ import { planSpatialRelations, refsOutsideStrings, splitTopLevelArgs, STRUCTURE_RELATION_ATTRS, SubsetSelectionError } from './step-subset-relations.js';
22
+ import { slotRef } from './schema-converter-structural-source.js';
23
+ import { skipStepTrivia } from './step-slot-grammar.js';
24
+ import { skipStepComment } from './step-comment-skip.js';
25
+ import { spatialAncestors } from './step-subset-spatial-ancestors.js';
26
+ import { resolveStoreyArgument, storeyMembers } from './step-subset-storey.js';
27
+ export { SubsetSelectionError } from './step-subset-relations.js';
28
+ /** The first attribute's text when it is a string literal, read without splitting the whole body. */
29
+ function firstStringSlot(body) {
30
+ const start = skipStepTrivia(body, 0);
31
+ if (start < 0 || body[start] !== "'")
32
+ return null;
33
+ const end = stepStringLiteralEnd(body, start);
34
+ if (end < 0)
35
+ return null;
36
+ const after = skipStepTrivia(body, end);
37
+ return after === body.length || body[after] === ',' ? body.slice(start + 1, end - 1) : null;
38
+ }
39
+ /** Index after the DATA section opener, ignoring header strings and comments, or -1. */
40
+ function findDataSection(text) {
41
+ for (let i = 0; i < text.length; i++) {
42
+ const ch = text[i];
43
+ if (ch === "'") {
44
+ const end = stepStringLiteralEnd(text, i);
45
+ if (end < 0)
46
+ return -1;
47
+ i = end - 1;
48
+ }
49
+ else if (ch === '/' && text[i + 1] === '*') {
50
+ i = skipStepComment(text, i) - 1;
51
+ }
52
+ else if (text.startsWith('DATA', i) && !/[A-Za-z0-9_]/.test(text[i - 1] ?? '')) {
53
+ const end = skipStepTrivia(text, i + 4);
54
+ if (text[end] === ';')
55
+ return end + 1;
56
+ }
57
+ }
58
+ return -1;
59
+ }
60
+ /** Voids, fills and projections: the relation pulls a feature in once its anchor (attribute 5) is kept. */
61
+ const ASSEMBLY_RELATIONS = new Set(['IFCRELAGGREGATES', 'IFCRELNESTS']);
62
+ const HOST_FEATURE_RELATIONS = new Set(['IFCRELVOIDSELEMENT', 'IFCRELFILLSELEMENT', 'IFCRELPROJECTSELEMENT']);
63
+ /**
64
+ * String-aware STEP DATA tokenizer. Splits the data section into instances at
65
+ * the `;` that terminates each `#id = TYPE(...)`, ignoring `;`/`#`/`(` inside
66
+ * STEP string literals (`'...'`, where `''` is an escaped quote). A regex split
67
+ * mis-fires on names containing `;` or `#` (common in Revit exports), so this
68
+ * scans character by character instead.
69
+ */
70
+ export function parseStep(text) {
71
+ const headerEnd = findDataSection(text);
72
+ if (headerEnd < 0)
73
+ throw new Error('Not a STEP file: no DATA; section');
74
+ // A record may follow the section opener on the same line.
75
+ const header = text.slice(0, headerEnd) + '\n';
76
+ const data = text;
77
+ const instances = new Map();
78
+ const rooted = getIfcRootTypes();
79
+ const guidToId = new Map();
80
+ let i = headerEnd;
81
+ const n = data.length;
82
+ while (i < n) {
83
+ // Seek the next `#`
84
+ while (i < n && data[i] !== '#') {
85
+ // Comments between records are trivia, never a terminator.
86
+ if (data[i] === '/' && data[i + 1] === '*') {
87
+ i = skipStepComment(data, i);
88
+ continue;
89
+ }
90
+ // Stop at ENDSEC to avoid scanning the footer.
91
+ if (data.startsWith('ENDSEC', i)) {
92
+ i = n;
93
+ break;
94
+ }
95
+ i++;
96
+ }
97
+ if (i >= n)
98
+ break;
99
+ const hashStart = i;
100
+ i++; // past '#'
101
+ let idStr = '';
102
+ while (i < n && data[i] >= '0' && data[i] <= '9')
103
+ idStr += data[i++];
104
+ if (idStr === '')
105
+ continue; // a `#` inside something odd; skip
106
+ // expect optional spaces then '='
107
+ let j = skipStepTrivia(data, i);
108
+ if (j < 0)
109
+ break;
110
+ if (data[j] !== '=')
111
+ continue; // `#42` as a REFERENCE, not a definition
112
+ j = skipStepTrivia(data, j + 1);
113
+ if (j < 0)
114
+ break; // an unclosed comment runs to the end
115
+ // read TYPE
116
+ let type = '';
117
+ while (j < n && /[A-Za-z0-9_]/.test(data[j]))
118
+ type += data[j++];
119
+ // now consume the balanced `( ... )` respecting strings, then the ';'
120
+ j = skipStepTrivia(data, j);
121
+ if (j < 0)
122
+ break;
123
+ if (data[j] !== '(')
124
+ continue; // not a record definition after all
125
+ const bodyStart = j + 1;
126
+ let depth = 0;
127
+ for (; j < n; j++) {
128
+ const ch = data[j];
129
+ if (ch === '/' && data[j + 1] === '*') {
130
+ // A comment's quotes and parentheses do not frame the record.
131
+ j = skipStepComment(data, j) - 1;
132
+ }
133
+ else if (ch === "'") {
134
+ // The shared literal-end rule (`''`, PAGE-directive operand, #7589).
135
+ const end = stepStringLiteralEnd(data, j);
136
+ j = end < 0 ? n : end - 1; // unterminated: runs to the end
137
+ if (end < 0)
138
+ break;
139
+ }
140
+ else if (ch === '(')
141
+ depth++;
142
+ else if (ch === ')') {
143
+ depth--;
144
+ if (depth === 0) {
145
+ j++;
146
+ break;
147
+ }
148
+ }
149
+ }
150
+ const bodyEnd = j - 1; // index of the matching ')'
151
+ const semi = skipStepTrivia(data, j);
152
+ if (semi < 0 || semi >= n || depth !== 0)
153
+ break;
154
+ if (data[semi] !== ';') {
155
+ // A malformed record must not consume the next well-formed one.
156
+ i = semi;
157
+ continue;
158
+ }
159
+ const id = parseInt(idStr, 10);
160
+ const body = data.slice(bodyStart, bodyEnd);
161
+ const full = data.slice(hashStart, semi + 1).trim();
162
+ const upperType = type.toUpperCase();
163
+ instances.set(id, { id, type: upperType, body, full, bodyStart: bodyStart - hashStart });
164
+ // Only IfcRoot records carry a GlobalId (their first attribute); a property
165
+ // or material whose first string happens to be 22 characters must not answer for one.
166
+ if (rooted.has(upperType)) {
167
+ const guid = firstStringSlot(body);
168
+ if (guid?.length === 22)
169
+ guidToId.set(guid, id);
170
+ }
171
+ i = semi + 1;
172
+ }
173
+ return { header, instances, guidToId };
174
+ }
175
+ /** Resolve one selector token to an expressId (`#42`, `42`, or a GlobalId).
176
+ * An `#id` / bare id is validated against the model too, so a typo'd or stale
177
+ * id fails loudly instead of silently selecting nothing. */
178
+ export function resolveToId(token, parsed) {
179
+ const t = token.trim();
180
+ const guidId = parsed.guidToId.get(t);
181
+ if (guidId !== undefined) {
182
+ const numericId = /^\d+$/.test(t) ? Number(t) : undefined;
183
+ if (numericId !== undefined && numericId !== guidId && parsed.instances.has(numericId)) {
184
+ throw new SubsetSelectionError('invalid', `Ambiguous product selector '${t}': GlobalId for #${guidId} also names express id #${numericId}; use an explicit #id.`);
185
+ }
186
+ return guidId;
187
+ }
188
+ if (t.startsWith('#') || /^\d+$/.test(t)) {
189
+ if (!/^#?\d+$/.test(t))
190
+ throw new SubsetSelectionError('invalid', `Invalid expressId: ${t}`);
191
+ const id = Number(t.replace(/^#/, ''));
192
+ if (!parsed.instances.has(id))
193
+ throw new SubsetSelectionError('not-found', `expressId not found in model: #${id}`);
194
+ return id;
195
+ }
196
+ throw new SubsetSelectionError('not-found', `GlobalId not found in model: ${t}`);
197
+ }
198
+ /**
199
+ * Forward reference closure: every instance transitively referenced by
200
+ * `seeds`.
201
+ *
202
+ * Uses `refsOutsideStrings`, not a raw `/#(\d+)/g` scan, because a record's
203
+ * Name/Description is free TEXT and Revit writes `#`-shaped substrings into
204
+ * it (`'Chair pairs with #71'`). A raw regex reads that as a reference to
205
+ * entity 71 and pulls it — and its own closure — into the extraction even
206
+ * though it was never selected. See #4148.
207
+ *
208
+ * An id NAMED but never DEFINED is not added, or a rewritten SET would emit
209
+ * it as a dangling `#id` (#4128).
210
+ */
211
+ export function forwardClosure(seeds, parsed, into) {
212
+ const stack = [...seeds];
213
+ while (stack.length) {
214
+ const id = stack.pop();
215
+ if (into.has(id))
216
+ continue;
217
+ const rec = parsed.instances.get(id);
218
+ if (!rec)
219
+ continue;
220
+ into.add(id);
221
+ for (const ref of refsOutsideStrings(rec.body)) {
222
+ if (!into.has(ref))
223
+ stack.push(ref);
224
+ }
225
+ }
226
+ }
227
+ /**
228
+ * Assemble the subset: the closure of `seedProducts` + context roots
229
+ * (project/units/contexts + the backward closure of spatial ancestors, not
230
+ * the whole skeleton) + spatial-structure relations, each rewritten down to
231
+ * its kept members (so no dangling references).
232
+ */
233
+ export function buildSubset(seedProducts, parsed) {
234
+ const keep = new Set();
235
+ forwardClosure(seedProducts, parsed, keep);
236
+ // Openings, fillers and physical assembly parts point back to the selected
237
+ // host through inverse relationships. Traverse them before adding spatial
238
+ // context, so selecting an assembly never pulls in the contents of a storey.
239
+ const inverse = new Map();
240
+ const narrowedAssemblies = new Set();
241
+ for (const inst of parsed.instances.values()) {
242
+ const assembly = ASSEMBLY_RELATIONS.has(inst.type);
243
+ if (!assembly && !HOST_FEATURE_RELATIONS.has(inst.type))
244
+ continue;
245
+ const args = splitTopLevelArgs(inst.body);
246
+ if (!args || args.length !== STRUCTURE_RELATION_ATTRS)
247
+ continue;
248
+ const anchor = slotRef(args[4]);
249
+ if (anchor === null)
250
+ continue;
251
+ if (assembly) {
252
+ if (parsed.instances.get(anchor)?.type !== 'IFCELEMENTASSEMBLY')
253
+ continue;
254
+ // A selected part narrows all decomposition records on this assembly.
255
+ if (refsOutsideStrings(args[5]).some((part) => seedProducts.has(part)))
256
+ narrowedAssemblies.add(anchor);
257
+ }
258
+ const relations = inverse.get(anchor);
259
+ if (relations)
260
+ relations.push(inst.id);
261
+ else
262
+ inverse.set(anchor, [inst.id]);
263
+ }
264
+ // Set iteration also visits new members. Each anchor and relation is handled
265
+ // once, even for deep or cyclic assembly graphs.
266
+ for (const id of keep) {
267
+ const relations = inverse.get(id);
268
+ if (!relations)
269
+ continue;
270
+ const expansion = narrowedAssemblies.has(id)
271
+ ? relations.filter((relation) => !ASSEMBLY_RELATIONS.has(parsed.instances.get(relation).type))
272
+ : relations;
273
+ forwardClosure(expansion, parsed, keep);
274
+ }
275
+ // Context roots: IfcProject (always — units/contexts hang off it even when
276
+ // nothing selected reaches it) plus every spatial ancestor of what is
277
+ // kept, closed forward. Backward closure, not a type list, so an unrelated
278
+ // storey/space is never dragged in and a product under an IfcSpace or IFC4X3
279
+ // facility class keeps its parent too (#4124). After the fixpoint, so a
280
+ // filler or projection it pulled in keeps its own storey; ancestors are
281
+ // spatial structures, never feature anchors, so the fixpoint needs none.
282
+ const rootSeeds = spatialAncestors(keep, parsed.instances);
283
+ for (const inst of parsed.instances.values()) {
284
+ if (inst.type === 'IFCPROJECT')
285
+ rootSeeds.push(inst.id);
286
+ }
287
+ forwardClosure(rootSeeds, parsed, keep);
288
+ // Spatial relationships that connect kept products into the tree, each
289
+ // relation's member SET filtered down to the kept ids rather than the whole
290
+ // relation being dropped. `step-subset-relations.ts` owns that rule and the
291
+ // no-dangling-reference invariant it preserves.
292
+ let spatial = planSpatialRelations(parsed.instances.values(), keep);
293
+ // A relation-private IfcOwnerHistory is reachable from nothing else, so the
294
+ // plan drops the relation and reports what blocked it. Close over a dropped
295
+ // relation's blocker group and replan (#4126), but only when EVERY id in the
296
+ // group is a defined IfcOwnerHistory: then the closure keeps all of them and
297
+ // that relation survives round two. A group holding anything else (a phantom
298
+ // id, or a product named in a Name or Description slot, both schema-invalid)
299
+ // leaves its relation dropped whatever is kept, so closing over it would only
300
+ // emit records nothing references and drag unselected products in (#4150).
301
+ // ONE replan, not a `while`: for a SCHEMA-VALID record an IfcOwnerHistory
302
+ // subtree names no product, container or relation, so it blocks nothing new;
303
+ // on invalid input a second round is discarded and the relation stays dropped
304
+ // (never a dangling id).
305
+ const owners = spatial.blockedOn
306
+ .filter((ids) => ids.every((id) => parsed.instances.get(id)?.type === 'IFCOWNERHISTORY'))
307
+ .flat();
308
+ if (owners.length > 0) {
309
+ forwardClosure(owners, parsed, keep);
310
+ spatial = planSpatialRelations(parsed.instances.values(), keep);
311
+ }
312
+ for (const id of spatial.add)
313
+ keep.add(id);
314
+ return { keep, rewritten: spatial.rewritten };
315
+ }
316
+ /** Serialize the subset back into a valid STEP file (sorted, header preserved). */
317
+ export function serializeSubset({ keep, rewritten }, parsed) {
318
+ const kept = [...keep].filter((id) => parsed.instances.has(id)).sort((a, b) => a - b);
319
+ const lines = kept.map((id) => rewritten.get(id) ?? parsed.instances.get(id).full);
320
+ return parsed.header + lines.join('\n') + '\nENDSEC;\nEND-ISO-10303-21;\n';
321
+ }
322
+ /**
323
+ * Resolve selectors to seed product ids. A product or storey token that names
324
+ * nothing throws; a type that matches nothing just adds nothing, so the caller
325
+ * decides how to word an empty selection.
326
+ *
327
+ * An explicit schema overrides FILE_SCHEMA. Without either, types expand across bundled schemas.
328
+ */
329
+ export function selectSubsetSeeds(parsed, selectors) {
330
+ let schemaVersion = selectors.schemaVersion;
331
+ if (schemaVersion === undefined) {
332
+ const headerBytes = new TextEncoder().encode(parsed.header);
333
+ const header = parseSourceHeader(headerBytes);
334
+ if (header?.schemaIdentifiers.length)
335
+ schemaVersion = detectSchemaVersion(headerBytes, header);
336
+ }
337
+ const seeds = new Set();
338
+ for (const token of selectors.products ?? []) {
339
+ if (token.trim())
340
+ seeds.add(resolveToId(token, parsed));
341
+ }
342
+ // Expanded STEP type name -> the requested types it came from, so one scan
343
+ // also tells which requested type matched nothing.
344
+ const requested = (selectors.types ?? []).map((t) => t.trim()).filter(Boolean);
345
+ const wantedTypes = new Map();
346
+ requested.forEach((type, i) => {
347
+ for (const name of expandTypes([type], schemaVersion)) {
348
+ const key = name.toUpperCase();
349
+ const from = wantedTypes.get(key);
350
+ if (from)
351
+ from.push(i);
352
+ else
353
+ wantedTypes.set(key, [i]);
354
+ }
355
+ });
356
+ const typeMatched = new Set();
357
+ if (wantedTypes.size > 0) {
358
+ for (const inst of parsed.instances.values()) {
359
+ const from = wantedTypes.get(inst.type);
360
+ if (!from)
361
+ continue;
362
+ seeds.add(inst.id);
363
+ for (const i of from)
364
+ typeMatched.add(i);
365
+ }
366
+ }
367
+ if (selectors.requireEachMatch) {
368
+ const missing = requested.filter((_, i) => !typeMatched.has(i));
369
+ if (missing.length > 0)
370
+ throw new SubsetSelectionError('invalid', `No product of type ${missing.join(', ')} (or a subtype).`);
371
+ }
372
+ for (const token of selectors.storeys ?? []) {
373
+ if (!token.trim())
374
+ continue;
375
+ const storeys = resolveStoreyArgument(token, parsed, selectors.splitStoreyLists === true);
376
+ for (const { storeyId, placementId } of storeys) {
377
+ // Keep the storey itself, even when it is empty.
378
+ seeds.add(storeyId);
379
+ const products = storeyMembers(storeyId, placementId, parsed, schemaVersion);
380
+ if (selectors.requireEachMatch && products.length === 0)
381
+ throw new SubsetSelectionError('invalid', `Storey ${token} has no elements.`);
382
+ for (const id of products)
383
+ seeds.add(id);
384
+ }
385
+ }
386
+ return seeds;
387
+ }
388
+ //# sourceMappingURL=step-subset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-subset.js","sourceRoot":"","sources":["../src/step-subset.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,oBAAoB,EAAgC,MAAM,4BAA4B,CAAC;AACvL,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAUlE,qGAAqG;AACrG,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACtC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,GAAG,GAAG,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9C,IAAI,GAAG,GA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 +1,6 @@
1
+ export declare const PROFILE_MEASURE_POWERS: ReadonlyMap<string, number>;
1
2
  /**
2
- * Per-entity plan: which STEP attribute indices carry a length / area / volume,
3
+ * Per-entity plan: which STEP attribute indices carry dimensional values,
3
4
  * and where a self-describing unit override lives. Indices are 0-based STEP order.
4
5
  */
5
6
  export interface EntityLengthPlan {
@@ -11,18 +12,22 @@ export interface EntityLengthPlan {
11
12
  areaIdx: number[];
12
13
  /** Scalar volume attributes → scale by the volume factor. */
13
14
  volumeIdx: number[];
15
+ /** Scalar profile measures and their STEP type names. */
16
+ profileMeasures: {
17
+ index: number;
18
+ measure: string;
19
+ }[];
14
20
  /**
15
21
  * Indices of unit-override attributes (`Unit` / `DefiningUnit` / `DefinedUnit`,
16
- * typed IfcNamedUnit or the IfcUnit SELECT). When ANY of them is a live
17
- * reference (not `$`), the entity's value(s) carry their own unit and must NOT
18
- * be rescaled to the global unit.
22
+ * typed IfcNamedUnit or the IfcUnit SELECT). An explicit unit protects its
23
+ * value or table column from rescaling.
19
24
  */
20
25
  unitGuardIdx: number[];
21
26
  /** True when there is neither a value to scale nor a unit override to consider. */
22
27
  empty: boolean;
23
28
  }
24
29
  /**
25
- * Derive (and cache) the length/area/volume attribute plan for an uppercase STEP
30
+ * Derive (and cache) the dimensional attribute plan for an uppercase STEP
26
31
  * type name from the generated schema registry. Excluded types (unit definitions,
27
32
  * georeferencing) and unknown/abstract types return the empty plan.
28
33
  */
@@ -37,22 +42,18 @@ export declare function getEntityLengthPlan(typeUpper: string, legacySchema?: 'I
37
42
  * with a mantissa dot (`1.5E-7`), so small/large magnitudes stay parseable.
38
43
  */
39
44
  export declare function toStepRealScaled(v: number): string;
40
- /**
41
- * Multiply every bare numeric literal in `text` by `factor`, leaving quoted
42
- * strings and `#`-references untouched. O(n) single pass — safe for the large
43
- * coordinate lists of tessellated geometry.
44
- */
45
+ /** Scale coordinate literals and leave references, strings and comments intact. */
45
46
  export declare function scaleNumberLiterals(text: string, factor: number): string;
46
- export declare function scaleTypedMeasures(text: string, lengthFactor: number, areaFactor: number, volumeFactor: number): string;
47
+ export declare function scaleTypedMeasures(text: string, lengthFactor: number, areaFactor: number, volumeFactor: number, profileFactors?: ReadonlyMap<string, number>, preserveTrivia?: boolean): string;
47
48
  /**
48
- * Rescale every length/area/volume-valued datum of one STEP entity line.
49
+ * Rescale the dimensional data of one STEP entity line.
49
50
  *
50
51
  * `typeUpper` is the entity's uppercase STEP type (used for the schema-derived
51
52
  * plan). The line is expected to be a single `#id=TYPE(...);` statement. Returns
52
53
  * the input unchanged when all factors are `1`, the type is excluded (unit
53
54
  * definition / georeferencing), or there is nothing to scale.
54
55
  */
55
- export declare function rescaleEntityLengths(line: string, typeUpper: string, lengthFactor: number, areaFactor: number, volumeFactor: number, legacySchema?: 'IFC2X3'): string;
56
+ export declare function rescaleEntityLengths(line: string, typeUpper: string, lengthFactor: number, areaFactor: number, volumeFactor: number, profileFactors?: ReadonlyMap<string, number>, legacySchema?: 'IFC2X3', normalizeCell?: (cell: string, column: number, scale: (value: string) => string) => string): string;
56
57
  /**
57
58
  * Factor that converts a value expressed in `modelScale` units into `primaryScale`
58
59
  * units (both are SI-per-unit for the same dimension). Returns `1` when the units
@@ -1 +1 @@
1
- {"version":3,"file":"unit-normalize.d.ts","sourceRoot":"","sources":["../src/unit-normalize.ts"],"names":[],"mappings":"AAqFA;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,yDAAyD;IACzD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,mFAAmF;IACnF,KAAK,EAAE,OAAO,CAAC;CAChB;AA0BD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,S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