@ifc-lite/parser 5.1.0 → 6.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.
Files changed (199) hide show
  1. package/dist/classification-resolver.d.ts.map +1 -1
  2. package/dist/classification-resolver.js +35 -10
  3. package/dist/classification-resolver.js.map +1 -1
  4. package/dist/columnar-entity-preparation.d.ts +25 -0
  5. package/dist/columnar-entity-preparation.d.ts.map +1 -0
  6. package/dist/columnar-entity-preparation.js +282 -0
  7. package/dist/columnar-entity-preparation.js.map +1 -0
  8. package/dist/columnar-parser-indexes.d.ts +17 -1
  9. package/dist/columnar-parser-indexes.d.ts.map +1 -1
  10. package/dist/columnar-parser-indexes.js +31 -21
  11. package/dist/columnar-parser-indexes.js.map +1 -1
  12. package/dist/columnar-parser-root-attributes.d.ts +66 -0
  13. package/dist/columnar-parser-root-attributes.d.ts.map +1 -0
  14. package/dist/columnar-parser-root-attributes.js +245 -0
  15. package/dist/columnar-parser-root-attributes.js.map +1 -0
  16. package/dist/columnar-parser.d.ts +26 -63
  17. package/dist/columnar-parser.d.ts.map +1 -1
  18. package/dist/columnar-parser.js +384 -751
  19. package/dist/columnar-parser.js.map +1 -1
  20. package/dist/compact-entity-index-columns.d.ts +17 -0
  21. package/dist/compact-entity-index-columns.d.ts.map +1 -0
  22. package/dist/compact-entity-index-columns.js +15 -0
  23. package/dist/compact-entity-index-columns.js.map +1 -0
  24. package/dist/compact-entity-index-transport.d.ts +2 -12
  25. package/dist/compact-entity-index-transport.d.ts.map +1 -1
  26. package/dist/compact-entity-index-transport.js +1 -11
  27. package/dist/compact-entity-index-transport.js.map +1 -1
  28. package/dist/compact-entity-index.d.ts +6 -0
  29. package/dist/compact-entity-index.d.ts.map +1 -1
  30. package/dist/compact-entity-index.js +12 -20
  31. package/dist/compact-entity-index.js.map +1 -1
  32. package/dist/cost-extractor.d.ts +10 -0
  33. package/dist/cost-extractor.d.ts.map +1 -0
  34. package/dist/cost-extractor.js +369 -0
  35. package/dist/cost-extractor.js.map +1 -0
  36. package/dist/cost-schedule-2x3.d.ts +31 -0
  37. package/dist/cost-schedule-2x3.d.ts.map +1 -0
  38. package/dist/cost-schedule-2x3.js +75 -0
  39. package/dist/cost-schedule-2x3.js.map +1 -0
  40. package/dist/cost-types.d.ts +105 -0
  41. package/dist/cost-types.d.ts.map +1 -0
  42. package/dist/cost-types.js +5 -0
  43. package/dist/cost-types.js.map +1 -0
  44. package/dist/data-store-transport.d.ts +3 -2
  45. package/dist/data-store-transport.d.ts.map +1 -1
  46. package/dist/data-store-transport.js +10 -34
  47. package/dist/data-store-transport.js.map +1 -1
  48. package/dist/drop-census.d.ts +136 -0
  49. package/dist/drop-census.d.ts.map +1 -0
  50. package/dist/drop-census.js +53 -0
  51. package/dist/drop-census.js.map +1 -0
  52. package/dist/entity-refs-from-index.d.ts +10 -0
  53. package/dist/entity-refs-from-index.d.ts.map +1 -1
  54. package/dist/entity-refs-from-index.js +52 -36
  55. package/dist/entity-refs-from-index.js.map +1 -1
  56. package/dist/entity-scanner.d.ts +5 -0
  57. package/dist/entity-scanner.d.ts.map +1 -1
  58. package/dist/entity-scanner.js +30 -12
  59. package/dist/entity-scanner.js.map +1 -1
  60. package/dist/entity-type-byte-interner.d.ts +12 -0
  61. package/dist/entity-type-byte-interner.d.ts.map +1 -0
  62. package/dist/entity-type-byte-interner.js +66 -0
  63. package/dist/entity-type-byte-interner.js.map +1 -0
  64. package/dist/generated/ifc2x3/schema-registry.d.ts +50 -0
  65. package/dist/generated/ifc2x3/schema-registry.d.ts.map +1 -0
  66. package/dist/generated/ifc2x3/schema-registry.js +50052 -0
  67. package/dist/generated/ifc2x3/schema-registry.js.map +1 -0
  68. package/dist/generated/ifc4x3/schema-registry.d.ts +50 -0
  69. package/dist/generated/ifc4x3/schema-registry.d.ts.map +1 -0
  70. package/dist/generated/ifc4x3/schema-registry.js +71299 -0
  71. package/dist/generated/ifc4x3/schema-registry.js.map +1 -0
  72. package/dist/generated/schema-registry-by-version.d.ts +61 -0
  73. package/dist/generated/schema-registry-by-version.d.ts.map +1 -0
  74. package/dist/generated/schema-registry-by-version.js +86 -0
  75. package/dist/generated/schema-registry-by-version.js.map +1 -0
  76. package/dist/group-assignment-factor.d.ts +13 -0
  77. package/dist/group-assignment-factor.d.ts.map +1 -0
  78. package/dist/group-assignment-factor.js +30 -0
  79. package/dist/group-assignment-factor.js.map +1 -0
  80. package/dist/ifczip.d.ts +6 -0
  81. package/dist/ifczip.d.ts.map +1 -1
  82. package/dist/ifczip.js +20 -11
  83. package/dist/ifczip.js.map +1 -1
  84. package/dist/index.d.ts +10 -6
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +17 -7
  87. package/dist/index.js.map +1 -1
  88. package/dist/on-demand-extractors.d.ts +1 -0
  89. package/dist/on-demand-extractors.d.ts.map +1 -1
  90. package/dist/on-demand-extractors.js +2 -1
  91. package/dist/on-demand-extractors.js.map +1 -1
  92. package/dist/parser.worker.d.ts +6 -3
  93. package/dist/parser.worker.d.ts.map +1 -1
  94. package/dist/parser.worker.js +24 -12
  95. package/dist/parser.worker.js.map +1 -1
  96. package/dist/prepass-source-fingerprint.d.ts +3 -0
  97. package/dist/prepass-source-fingerprint.d.ts.map +1 -0
  98. package/dist/prepass-source-fingerprint.js +13 -0
  99. package/dist/prepass-source-fingerprint.js.map +1 -0
  100. package/dist/property-value-parser.d.ts +10 -0
  101. package/dist/property-value-parser.d.ts.map +1 -1
  102. package/dist/property-value-parser.js +40 -1
  103. package/dist/property-value-parser.js.map +1 -1
  104. package/dist/scan-entities-balanced.d.ts.map +1 -1
  105. package/dist/scan-entities-balanced.js +8 -6
  106. package/dist/scan-entities-balanced.js.map +1 -1
  107. package/dist/scan-worker-lexing.d.ts +14 -0
  108. package/dist/scan-worker-lexing.d.ts.map +1 -0
  109. package/dist/scan-worker-lexing.js +101 -0
  110. package/dist/scan-worker-lexing.js.map +1 -0
  111. package/dist/scan-worker-source.d.ts +1 -1
  112. package/dist/scan-worker-source.d.ts.map +1 -1
  113. package/dist/scan-worker-source.js +61 -59
  114. package/dist/scan-worker-source.js.map +1 -1
  115. package/dist/schedule-extractor.d.ts +2 -80
  116. package/dist/schedule-extractor.d.ts.map +1 -1
  117. package/dist/schedule-extractor.js +100 -225
  118. package/dist/schedule-extractor.js.map +1 -1
  119. package/dist/schedule-serializer-builders.d.ts +28 -0
  120. package/dist/schedule-serializer-builders.d.ts.map +1 -0
  121. package/dist/schedule-serializer-builders.js +163 -0
  122. package/dist/schedule-serializer-builders.js.map +1 -0
  123. package/dist/schedule-serializer.d.ts +6 -0
  124. package/dist/schedule-serializer.d.ts.map +1 -1
  125. package/dist/schedule-serializer.js +26 -165
  126. package/dist/schedule-serializer.js.map +1 -1
  127. package/dist/schedule-types.d.ts +211 -0
  128. package/dist/schedule-types.d.ts.map +1 -0
  129. package/dist/schedule-types.js +221 -0
  130. package/dist/schedule-types.js.map +1 -0
  131. package/dist/select-entity-columns.d.ts +7 -0
  132. package/dist/select-entity-columns.d.ts.map +1 -0
  133. package/dist/select-entity-columns.js +43 -0
  134. package/dist/select-entity-columns.js.map +1 -0
  135. package/dist/spatial-hierarchy-ambiguity.d.ts +39 -0
  136. package/dist/spatial-hierarchy-ambiguity.d.ts.map +1 -0
  137. package/dist/spatial-hierarchy-ambiguity.js +25 -0
  138. package/dist/spatial-hierarchy-ambiguity.js.map +1 -0
  139. package/dist/spatial-hierarchy-attributes.d.ts +54 -0
  140. package/dist/spatial-hierarchy-attributes.d.ts.map +1 -0
  141. package/dist/spatial-hierarchy-attributes.js +145 -0
  142. package/dist/spatial-hierarchy-attributes.js.map +1 -0
  143. package/dist/spatial-hierarchy-builder.d.ts +6 -38
  144. package/dist/spatial-hierarchy-builder.d.ts.map +1 -1
  145. package/dist/spatial-hierarchy-builder.js +48 -166
  146. package/dist/spatial-hierarchy-builder.js.map +1 -1
  147. package/dist/spatial-hierarchy-canonical-parent.d.ts +86 -0
  148. package/dist/spatial-hierarchy-canonical-parent.d.ts.map +1 -0
  149. package/dist/spatial-hierarchy-canonical-parent.js +212 -0
  150. package/dist/spatial-hierarchy-canonical-parent.js.map +1 -0
  151. package/dist/step-lexing.d.ts +1 -1
  152. package/dist/step-lexing.d.ts.map +1 -1
  153. package/dist/step-lexing.js +1 -56
  154. package/dist/step-lexing.js.map +1 -1
  155. package/dist/step-record-boundary.d.ts +28 -0
  156. package/dist/step-record-boundary.d.ts.map +1 -0
  157. package/dist/step-record-boundary.js +108 -0
  158. package/dist/step-record-boundary.js.map +1 -0
  159. package/dist/step-record-boundary.vectors.d.ts +58 -0
  160. package/dist/step-record-boundary.vectors.d.ts.map +1 -0
  161. package/dist/step-record-boundary.vectors.js +80 -0
  162. package/dist/step-record-boundary.vectors.js.map +1 -0
  163. package/dist/structural-extractor.d.ts +9 -0
  164. package/dist/structural-extractor.d.ts.map +1 -0
  165. package/dist/structural-extractor.js +310 -0
  166. package/dist/structural-extractor.js.map +1 -0
  167. package/dist/structural-load-extractor.d.ts +147 -0
  168. package/dist/structural-load-extractor.d.ts.map +1 -0
  169. package/dist/structural-load-extractor.js +178 -0
  170. package/dist/structural-load-extractor.js.map +1 -0
  171. package/dist/structural-step-values.d.ts +51 -0
  172. package/dist/structural-step-values.d.ts.map +1 -0
  173. package/dist/structural-step-values.js +109 -0
  174. package/dist/structural-step-values.js.map +1 -0
  175. package/dist/structural-types.d.ts +145 -0
  176. package/dist/structural-types.d.ts.map +1 -0
  177. package/dist/structural-types.js +5 -0
  178. package/dist/structural-types.js.map +1 -0
  179. package/dist/tokenizer.d.ts +11 -5
  180. package/dist/tokenizer.d.ts.map +1 -1
  181. package/dist/tokenizer.js +75 -21
  182. package/dist/tokenizer.js.map +1 -1
  183. package/dist/wasm-init-retry.d.ts +6 -42
  184. package/dist/wasm-init-retry.d.ts.map +1 -1
  185. package/dist/wasm-init-retry.js +6 -99
  186. package/dist/wasm-init-retry.js.map +1 -1
  187. package/dist/wasm-panic-forward.d.ts +7 -63
  188. package/dist/wasm-panic-forward.d.ts.map +1 -1
  189. package/dist/wasm-panic-forward.js +7 -100
  190. package/dist/wasm-panic-forward.js.map +1 -1
  191. package/dist/worker-index-publication.d.ts +43 -0
  192. package/dist/worker-index-publication.d.ts.map +1 -0
  193. package/dist/worker-index-publication.js +129 -0
  194. package/dist/worker-index-publication.js.map +1 -0
  195. package/dist/worker-parser.d.ts +5 -2
  196. package/dist/worker-parser.d.ts.map +1 -1
  197. package/dist/worker-parser.js +22 -10
  198. package/dist/worker-parser.js.map +1 -1
  199. package/package.json +5 -4
@@ -4,562 +4,424 @@
4
4
  import { SpatialHierarchyBuilder } from './spatial-hierarchy-builder.js';
5
5
  import { EntityExtractor } from './entity-extractor.js';
6
6
  import { extractLengthUnitScale } from './unit-extractor.js';
7
- import { getAttributeNames, getAttributeNamesAcrossSchemas, getInheritanceChain } from './ifc-schema.js';
8
7
  import { parsePropertyValueWithComplex } from './on-demand-extractors.js';
9
8
  import { readQuantitySet } from './quantity-collect.js';
10
- import { buildCompactEntityIndexAsync } from './compact-entity-index.js';
9
+ import { prepareColumnarEntities } from './columnar-entity-preparation.js';
11
10
  import { yieldToEventLoop } from './yield-to-event-loop.js';
12
11
  import { StringTable, EntityTableBuilder, PropertyTableBuilder, QuantityTableBuilder, RelationshipGraphBuilder, RelationshipType, } from '@ifc-lite/data';
13
12
  import { BufferEntitySource } from './entity-source.js';
14
13
  import { batchExtractGlobalIdAndName } from './columnar-parser-attributes.js';
15
- import { GEOMETRY_TYPES, REL_TYPE_MAP, SPATIAL_TYPES, HIERARCHY_REL_TYPES, PROPERTY_REL_TYPES, ASSOCIATION_REL_TYPES, SKIP_DISPLAY_ATTRS, PROPERTY_ENTITY_TYPES, PROPERTY_CONTAINER_TYPES, isIfcTypeLikeEntity, } from './columnar-parser-indexes.js';
14
+ import { REL_TYPE_MAP, SECONDARY_REL_TYPE_MAP, } from './columnar-parser-indexes.js';
16
15
  import { extractRelFast, extractPropertyRelFast } from './columnar-parser-relationships.js';
17
16
  import { detectSchemaVersion, parseSourceHeader } from './source-header.js';
18
17
  import { contiguousSourceBytes } from './source-bytes.js';
18
+ import { getEntityRefFromStore, extractRootAttributesFromEntity, pickLongName } from './columnar-parser-root-attributes.js';
19
+ // Re-exported: part of the package's public on-demand-extraction surface
20
+ // (see packages/parser/src/index.ts).
21
+ export { extractEntityAttributesOnDemand, extractAllEntityAttributes, getRawNamedAttributes, extractRootAttributesFromEntity, } from './columnar-parser-root-attributes.js';
19
22
  /** Appends `ref` to `map.get(objId)`, skipping a repeat — these maps win over the deduped graph (#3760/#3782). */
20
23
  function addOnDemandRef(map, objId, ref) {
21
24
  const list = map.get(objId) ?? map.set(objId, []).get(objId);
22
25
  if (!list.includes(ref))
23
26
  list.push(ref);
24
27
  }
25
- export class ColumnarParser {
26
- /**
27
- * Parse IFC file into columnar data store
28
- *
29
- * Uses fast semicolon-based scanning with on-demand property extraction.
30
- * Properties are parsed lazily when accessed, not upfront.
31
- * This provides instant UI responsiveness even for very large files.
32
- */
33
- async parseLite(buffer, entityRefs, options = {}) {
34
- const startTime = performance.now();
35
- const uint8Buffer = new Uint8Array(buffer);
36
- const totalEntities = entityRefs.length;
37
- // Phase timing for performance telemetry
38
- let phaseStart = startTime;
39
- const emitDiagnostic = (message) => {
40
- options.onDiagnostic?.(message);
41
- };
42
- const logPhase = (name) => {
43
- const now = performance.now();
44
- const elapsed = Math.round(now - phaseStart);
45
- console.log(`[parseLite] ${name}: ${elapsed}ms`);
46
- emitDiagnostic(`${name}: ${elapsed}ms`);
47
- phaseStart = now;
48
- };
49
- options.onProgress?.({ phase: 'building', percent: 0 });
50
- // Capture verbatim HEADER fields so a round-trip export can reproduce
51
- // the source FILE_DESCRIPTION items + exact FILE_SCHEMA token instead
52
- // of regenerating a fresh ifc-lite header. Cheap: the scan stops at the
53
- // header's ENDSEC, so the DATA section is never touched.
54
- const sourceHeader = parseSourceHeader(uint8Buffer);
55
- // Schema version comes from that header's FILE_SCHEMA declaration, not
56
- // from a substring scan of the raw bytes — exporter product names in
57
- // FILE_NAME free text carry schema tokens too (issue #3278).
58
- const schemaVersion = detectSchemaVersion(uint8Buffer, sourceHeader);
59
- // Initialize builders (entity table capacity set after categorization below)
60
- const strings = new StringTable();
61
- const propertyTableBuilder = new PropertyTableBuilder(strings);
62
- const quantityTableBuilder = new QuantityTableBuilder(strings);
63
- const relationshipGraphBuilder = new RelationshipGraphBuilder();
64
- logPhase('init builders');
65
- // Single pass: build byType index AND categorize entities simultaneously.
66
- // Uses a type-name cache to avoid calling .toUpperCase() on 4.4M refs
67
- // (only ~776 unique type names in IFC4).
68
- const byType = new Map();
69
- const deferPropertyAtomIndex = options.deferPropertyAtomIndex === true;
70
- const typeUpperCache = new Map();
71
- const getTypeUpper = (type) => {
72
- let upper = typeUpperCache.get(type);
73
- if (upper === undefined) {
74
- upper = type.toUpperCase();
75
- typeUpperCache.set(type, upper);
76
- }
77
- return upper;
78
- };
79
- // Non-product helper entities that on-demand extraction / StepExporter
80
- // need addressable in `byId`. These are not IfcProduct subtypes so the
81
- // schema-driven IFCPRODUCT subtype check below cannot capture them.
82
- // Without them, findPreferredGeometricRepresentationContextId() and
83
- // findLengthUnitReference() fail because the entities are missing from
84
- // the compact entity index.
85
- const RELEVANT_NON_PRODUCT_HELPERS = new Set([
86
- 'IFCGEOMETRICREPRESENTATIONCONTEXT', 'IFCGEOMETRICREPRESENTATIONSUBCONTEXT',
87
- 'IFCUNITASSIGNMENT', 'IFCSIUNIT', 'IFCCONVERSIONBASEDUNIT',
88
- 'IFCDERIVEDUNIT', 'IFCDERIVEDUNITELEMENT', 'IFCMEASUREWITHUNIT',
89
- 'IFCDIMENSIONALEXPONENTS',
90
- 'IFCMAPCONVERSION', 'IFCPROJECTEDCRS',
91
- 'IFCMATERIALLAYER', 'IFCMATERIALLAYERSET', 'IFCMATERIALLAYERSETUSAGE',
92
- 'IFCMATERIALCONSTITUENTSET', 'IFCMATERIALCONSTITUENT',
93
- 'IFCMATERIALPROFILESET', 'IFCMATERIALPROFILE', 'IFCMATERIAL',
94
- 'IFCCLASSIFICATION', 'IFCCLASSIFICATIONREFERENCE',
95
- 'IFCDOCUMENTINFORMATION', 'IFCDOCUMENTREFERENCE',
96
- ]);
97
- // Schema-driven inclusion: every IfcProduct subtype belongs in the
98
- // EntityTable. The previous hardcoded enumeration of IFC4 building-
99
- // element leaves (IFCWALL, IFCSLAB, …) and IFC4x3 infrastructure
100
- // leaves (IFCREFERENT, IFCSIGNAL, IFCALIGNMENT, IFCPAVEMENT, …) drifted
101
- // with every schema bump — new entities silently became CAT_SKIP and
102
- // disappeared from the hierarchy panel. The generated schema registry
103
- // already knows the full inheritance chain, so use it.
104
- const RELEVANT_PRODUCT_ROOTS = new Set(['IFCPRODUCT']);
105
- // IfcGroup family (IfcZone, IfcSystem, IfcDistributionSystem,
106
- // IfcBuildingSystem, IfcDistributionCircuit, …). These are NOT
107
- // IfcProduct subtypes, so without an explicit branch they fall through
108
- // to CAT_SKIP and never enter the EntityTable — leaving their Name
109
- // unresolvable (`getName` → '') and making them invisible to
110
- // `getByType`. The Relationships card then shows "Group #<id>" and the
111
- // lens/lists can't surface them. Route them into their own bucket so we
112
- // can extract Name/LongName/ObjectType for the group label (#1075).
113
- const GROUP_ROOTS = new Set(['IFCGROUP']);
114
- // Category constants for the lookup cache
115
- const CAT_SKIP = 0, CAT_SPATIAL = 1, CAT_GEOMETRY = 2, CAT_HIERARCHY_REL = 3, CAT_PROPERTY_REL = 4, CAT_PROPERTY_ENTITY = 5, CAT_ASSOCIATION_REL = 6, CAT_TYPE_OBJECT = 7, CAT_RELEVANT = 8, CAT_GROUP = 9;
116
- /** Returns true if `upper` (already uppercased) is a subtype of any type in `set`. */
117
- function isSubtypeOfAny(upper, set) {
118
- const chain = getInheritanceChain(upper);
119
- return chain.some(ancestor => set.has(ancestor.toUpperCase()));
120
- }
121
- // Cache: type name → category (avoids 4.4M .toUpperCase() calls)
122
- const typeCategoryCache = new Map();
123
- function getCategory(type) {
124
- let cat = typeCategoryCache.get(type);
125
- if (cat !== undefined)
126
- return cat;
127
- const upper = getTypeUpper(type);
128
- if (SPATIAL_TYPES.has(upper) || isSubtypeOfAny(upper, SPATIAL_TYPES))
129
- cat = CAT_SPATIAL;
130
- else if (GEOMETRY_TYPES.has(upper) || isSubtypeOfAny(upper, GEOMETRY_TYPES))
131
- cat = CAT_GEOMETRY;
132
- else if (HIERARCHY_REL_TYPES.has(upper))
133
- cat = CAT_HIERARCHY_REL;
134
- else if (PROPERTY_REL_TYPES.has(upper))
135
- cat = CAT_PROPERTY_REL;
136
- else if (PROPERTY_ENTITY_TYPES.has(upper))
137
- cat = CAT_PROPERTY_ENTITY;
138
- else if (ASSOCIATION_REL_TYPES.has(upper))
139
- cat = CAT_ASSOCIATION_REL;
140
- else if (isIfcTypeLikeEntity(upper))
141
- cat = CAT_TYPE_OBJECT;
142
- else if (isSubtypeOfAny(upper, GROUP_ROOTS))
143
- cat = CAT_GROUP;
144
- else if (RELEVANT_NON_PRODUCT_HELPERS.has(upper)
145
- || isSubtypeOfAny(upper, RELEVANT_PRODUCT_ROOTS)
146
- || upper.startsWith('IFCREL'))
147
- cat = CAT_RELEVANT;
148
- else
149
- cat = CAT_SKIP;
150
- typeCategoryCache.set(type, cat);
151
- return cat;
152
- }
153
- // Time-based yielding: yield to the main thread every ~80ms so geometry
154
- // streaming callbacks can fire. This limits main-thread blocking to short
155
- // bursts that don't starve geometry, while adding minimal overhead (~15 yields
156
- // × ~1ms each ≈ 15ms total over the full parse).
157
- const YIELD_INTERVAL_MS = Math.max(16, options.yieldIntervalMs ?? 80);
158
- let lastYieldTime = performance.now();
159
- const yieldIfNeeded = async () => {
160
- const now = performance.now();
161
- if (now - lastYieldTime >= YIELD_INTERVAL_MS) {
162
- await yieldToEventLoop();
163
- lastYieldTime = performance.now();
164
- }
165
- };
166
- emitDiagnostic(`parseLite start: totalEntities=${totalEntities} yieldInterval=${YIELD_INTERVAL_MS}ms`);
167
- const spatialRefs = [];
168
- const geometryRefs = [];
169
- const relationshipRefs = [];
170
- const propertyRelRefs = [];
171
- const propertyContainerRefs = [];
172
- const propertyAtomRefs = [];
173
- const associationRelRefs = [];
174
- const typeObjectRefs = [];
175
- const otherRelevantRefs = [];
176
- const groupRefs = [];
177
- for (let i = 0; i < entityRefs.length; i++) {
178
- if ((i & 0x3FF) === 0)
179
- await yieldIfNeeded();
180
- const ref = entityRefs[i];
181
- // Categorize (cached — .toUpperCase() called once per unique type)
182
- const cat = getCategory(ref.type);
183
- const typeUpper = cat === CAT_PROPERTY_ENTITY ? getTypeUpper(ref.type) : '';
184
- // ALL entities must be indexed in byType for on-demand extraction
185
- // (e.g. IfcGeometricRepresentationContext, IfcSiUnit, IfcMaterialLayer).
186
- // Only property atoms are optionally deferred for huge-file lazy loading.
187
- const includeInPrimaryIndex = !deferPropertyAtomIndex || cat !== CAT_PROPERTY_ENTITY || PROPERTY_CONTAINER_TYPES.has(typeUpper);
188
- if (includeInPrimaryIndex) {
189
- // STEP convention is uppercase entity type names and every
190
- // downstream consumer (schedule-extractor, property readers,
191
- // test helpers) keys on uppercase. The tokenizer preserves
192
- // original case though, so if a STEP writer ever emits
193
- // mixed-case or lowercase types the index would miss on
194
- // canonical lookups. Normalise once here — `getTypeUpper`
195
- // is already cached by type name so the cost is ~0.
196
- const typeKey = getTypeUpper(ref.type);
197
- let typeList = byType.get(typeKey);
198
- if (!typeList) {
199
- typeList = [];
200
- byType.set(typeKey, typeList);
201
- }
202
- typeList.push(ref.expressId);
203
- }
204
- if (cat === CAT_SPATIAL)
205
- spatialRefs.push(ref);
206
- else if (cat === CAT_GEOMETRY)
207
- geometryRefs.push(ref);
208
- else if (cat === CAT_HIERARCHY_REL)
209
- relationshipRefs.push(ref);
210
- else if (cat === CAT_PROPERTY_REL)
211
- propertyRelRefs.push(ref);
212
- else if (cat === CAT_PROPERTY_ENTITY) {
213
- if (PROPERTY_CONTAINER_TYPES.has(typeUpper))
214
- propertyContainerRefs.push(ref);
215
- else
216
- propertyAtomRefs.push(ref);
217
- }
218
- else if (cat === CAT_ASSOCIATION_REL)
219
- associationRelRefs.push(ref);
220
- else if (cat === CAT_TYPE_OBJECT)
221
- typeObjectRefs.push(ref);
222
- else if (cat === CAT_GROUP)
223
- groupRefs.push(ref);
224
- else if (cat === CAT_RELEVANT)
225
- otherRelevantRefs.push(ref);
226
- }
227
- logPhase(`categorize ${totalEntities} → spatial:${spatialRefs.length} geom:${geometryRefs.length} rel:${relationshipRefs.length} propRel:${propertyRelRefs.length} propContainers:${propertyContainerRefs.length} propAtoms:${propertyAtomRefs.length} assocRel:${associationRelRefs.length} type:${typeObjectRefs.length} group:${groupRefs.length} other:${otherRelevantRefs.length}`);
228
- // ALL entity refs must be indexed in byId so that on-demand extraction
229
- // can look up any entity by expressId (e.g. IfcUnitAssignment,
230
- // IfcGeometricRepresentationContext, IfcSiUnit, IfcLocalPlacement, etc.).
231
- // Only property atoms are optionally deferred for huge-file lazy loading.
232
- const indexedRefs = deferPropertyAtomIndex
233
- ? entityRefs.filter(ref => {
234
- const cat = getCategory(ref.type);
235
- return cat !== CAT_PROPERTY_ENTITY || PROPERTY_CONTAINER_TYPES.has(getTypeUpper(ref.type));
236
- })
237
- : entityRefs;
238
- emitDiagnostic(`index input: indexedRefs=${indexedRefs.length} deferredPropertyAtoms=${deferPropertyAtomIndex ? propertyAtomRefs.length : 0}`);
239
- // Keep every indexed entity available for on-demand reference resolution.
240
- const compactByIdIndex = await buildCompactEntityIndexAsync(indexedRefs);
241
- logPhase('compact entity index');
242
- // Create entity table builder with EXACT capacity (not totalEntities which
243
- // includes millions of geometry-representation entities we don't store).
244
- // For a 14M entity file, this reduces allocation from ~546MB to ~20MB.
245
- const relevantCount = spatialRefs.length + geometryRefs.length + typeObjectRefs.length
246
- + relationshipRefs.length + groupRefs.length + otherRelevantRefs.length;
247
- const entityTableBuilder = new EntityTableBuilder(relevantCount, strings);
248
- const entityIndex = {
249
- byId: compactByIdIndex,
250
- byType,
251
- };
252
- // === TARGETED PARSING using batch byte-level extraction ===
253
- // Uses 2 TextDecoder.decode() calls total for ALL entity GlobalIds/Names
254
- // (instead of per-entity calls), and pure byte scanning for relationships.
255
- options.onProgress?.({ phase: 'parsing entities', percent: 10 });
256
- const extractor = new EntityExtractor(uint8Buffer);
257
- // Spatial entities: small count, use extractEntity for full accuracy
258
- const parsedEntityData = new Map();
259
- for (const ref of spatialRefs) {
260
- const entity = extractor.extractEntity(ref);
261
- if (entity) {
262
- const attrs = entity.attributes || [];
263
- parsedEntityData.set(ref.expressId, {
264
- globalId: typeof attrs[0] === 'string' ? attrs[0] : '',
265
- name: typeof attrs[2] === 'string' ? attrs[2] : '',
266
- });
267
- }
28
+ /** Internal implementation shared by public refs and parser-worker columns. */
29
+ export async function parseColumnarInput(buffer, input, options = {}) {
30
+ const startTime = performance.now();
31
+ const uint8Buffer = new Uint8Array(buffer);
32
+ const totalEntities = Array.isArray(input) ? input.length : input.expressIds.length;
33
+ // Phase timing for performance telemetry
34
+ let phaseStart = startTime;
35
+ const emitDiagnostic = (message) => {
36
+ options.onDiagnostic?.(message);
37
+ };
38
+ const logPhase = (name) => {
39
+ const now = performance.now();
40
+ const elapsed = Math.round(now - phaseStart);
41
+ console.log(`[parseLite] ${name}: ${elapsed}ms`);
42
+ emitDiagnostic(`${name}: ${elapsed}ms`);
43
+ phaseStart = now;
44
+ };
45
+ options.onProgress?.({ phase: 'building', percent: 0 });
46
+ // Capture verbatim HEADER fields so a round-trip export can reproduce
47
+ // the source FILE_DESCRIPTION items + exact FILE_SCHEMA token instead
48
+ // of regenerating a fresh ifc-lite header. Cheap: the scan stops at the
49
+ // header's ENDSEC, so the DATA section is never touched.
50
+ const sourceHeader = parseSourceHeader(uint8Buffer);
51
+ // Schema version comes from that header's FILE_SCHEMA declaration, not
52
+ // from a substring scan of the raw bytes — exporter product names in
53
+ // FILE_NAME free text carry schema tokens too (issue #3278).
54
+ const schemaVersion = detectSchemaVersion(uint8Buffer, sourceHeader);
55
+ // Initialize builders (entity table capacity set after categorization below)
56
+ const strings = new StringTable();
57
+ const propertyTableBuilder = new PropertyTableBuilder(strings);
58
+ const quantityTableBuilder = new QuantityTableBuilder(strings);
59
+ const relationshipGraphBuilder = new RelationshipGraphBuilder();
60
+ logPhase('init builders');
61
+ // Time-based yielding: yield to the main thread every ~80ms so geometry
62
+ // streaming callbacks can fire. This limits main-thread blocking to short
63
+ // bursts that don't starve geometry, while adding minimal overhead (~15 yields
64
+ // × ~1ms each ≈ 15ms total over the full parse).
65
+ const YIELD_INTERVAL_MS = Math.max(16, options.yieldIntervalMs ?? 80);
66
+ let lastYieldTime = performance.now();
67
+ const yieldIfNeeded = async () => {
68
+ const now = performance.now();
69
+ if (now - lastYieldTime >= YIELD_INTERVAL_MS) {
70
+ await yieldToEventLoop();
71
+ lastYieldTime = performance.now();
268
72
  }
269
- logPhase('spatial entities');
270
- await yieldIfNeeded();
271
- // Group family (IfcZone / IfcSystem / IfcDistributionSystem / …): small
272
- // count, full extract so we can resolve Name + LongName + ObjectType for
273
- // the group label. Name is often empty on these the human label lives
274
- // in LongName (IfcZone/IfcDistributionSystem) so fall back to it, and
275
- // keep ObjectType (e.g. a system designation) for richer display. (#1075)
276
- const groupExtra = new Map();
277
- for (const ref of groupRefs) {
278
- const entity = extractor.extractEntity(ref);
279
- if (!entity)
280
- continue;
281
- const root = extractRootAttributesFromEntity(entity);
282
- const longName = pickLongName(entity);
73
+ };
74
+ emitDiagnostic(`parseLite start: totalEntities=${totalEntities} yieldInterval=${YIELD_INTERVAL_MS}ms`);
75
+ const prepared = await prepareColumnarEntities(input, options.deferPropertyAtomIndex === true, yieldIfNeeded);
76
+ const { byType, getTypeUpper, spatialRefs, geometryRefs, relationshipRefs, propertyRelRefs, propertyContainerRefs, associationRelRefs, typeObjectRefs, otherRelevantRefs, groupRefs } = prepared;
77
+ logPhase(`categorize ${totalEntities} spatial:${spatialRefs.length} geom:${geometryRefs.length} rel:${relationshipRefs.length} propRel:${propertyRelRefs.length} propContainers:${propertyContainerRefs.length} propAtoms:${prepared.propertyAtomCount} assocRel:${associationRelRefs.length} type:${typeObjectRefs.length} group:${groupRefs.length} other:${otherRelevantRefs.length}`);
78
+ emitDiagnostic(`index input: indexedRefs=${prepared.indexedCount} deferredPropertyAtoms=${options.deferPropertyAtomIndex ? prepared.propertyAtomCount : 0}`);
79
+ const compactByIdIndex = await prepared.buildPrimaryIndex();
80
+ logPhase('compact entity index');
81
+ // Create entity table builder with EXACT capacity (not totalEntities which
82
+ // includes millions of geometry-representation entities we don't store).
83
+ // For a 14M entity file, this reduces allocation from ~546MB to ~20MB.
84
+ const relevantCount = spatialRefs.length + geometryRefs.length + typeObjectRefs.length
85
+ + relationshipRefs.length + groupRefs.length + otherRelevantRefs.length;
86
+ const entityTableBuilder = new EntityTableBuilder(relevantCount, strings);
87
+ const entityIndex = {
88
+ byId: compactByIdIndex,
89
+ byType,
90
+ };
91
+ // === TARGETED PARSING using batch byte-level extraction ===
92
+ // Uses 2 TextDecoder.decode() calls total for ALL entity GlobalIds/Names
93
+ // (instead of per-entity calls), and pure byte scanning for relationships.
94
+ options.onProgress?.({ phase: 'parsing entities', percent: 10 });
95
+ const extractor = new EntityExtractor(uint8Buffer);
96
+ // Spatial entities: small count, use extractEntity for full accuracy
97
+ const parsedEntityData = new Map();
98
+ for (const ref of spatialRefs) {
99
+ const entity = extractor.extractEntity(ref);
100
+ if (entity) {
101
+ const attrs = entity.attributes || [];
283
102
  parsedEntityData.set(ref.expressId, {
284
- globalId: root.globalId,
285
- name: root.name || longName,
103
+ globalId: typeof attrs[0] === 'string' ? attrs[0] : '',
104
+ name: typeof attrs[2] === 'string' ? attrs[2] : '',
286
105
  });
287
- groupExtra.set(ref.expressId, { description: root.description, objectType: root.objectType });
288
106
  }
289
- logPhase('group entities');
290
- await yieldIfNeeded();
291
- // Geometry + type object entities: batch extract GlobalId+Name with 2 TextDecoder calls
292
- options.onProgress?.({ phase: 'parsing geometry names', percent: 12 });
293
- const geomData = await batchExtractGlobalIdAndName(uint8Buffer, geometryRefs, yieldIfNeeded);
294
- for (const [id, data] of geomData)
295
- parsedEntityData.set(id, data);
296
- await yieldIfNeeded();
297
- const typeData = await batchExtractGlobalIdAndName(uint8Buffer, typeObjectRefs, yieldIfNeeded);
298
- for (const [id, data] of typeData)
299
- parsedEntityData.set(id, data);
300
- logPhase('batch geom GlobalId+Name');
301
- await yieldIfNeeded();
302
- // Other relevant products (IfcSpatialZone, IfcVirtualElement, IfcGrid,
303
- // IfcAnnotation, ): batch GlobalId+Name so they show their Name in the
304
- // hierarchy / lists instead of nothing. Previously these were added to
305
- // the EntityTable with an empty name (parsedEntityData never covered
306
- // this bucket), so e.g. IfcSpatialZone listed without a label. (#1075)
307
- const otherData = await batchExtractGlobalIdAndName(uint8Buffer, otherRelevantRefs, yieldIfNeeded);
308
- for (const [id, data] of otherData)
309
- parsedEntityData.set(id, data);
310
- logPhase('batch other-relevant GlobalId+Name');
311
- await yieldIfNeeded();
312
- // Relationships: byte-level scanning (numbers only, no TextDecoder)
313
- options.onProgress?.({ phase: 'parsing relationships', percent: 20 });
314
- for (let i = 0; i < relationshipRefs.length; i++) {
315
- if ((i & 0x3FF) === 0)
316
- await yieldIfNeeded();
317
- const ref = relationshipRefs[i];
318
- const typeUpper = getTypeUpper(ref.type);
319
- const rel = extractRelFast(uint8Buffer, ref.byteOffset, ref.byteLength, typeUpper);
320
- if (rel) {
321
- const relType = REL_TYPE_MAP[typeUpper];
322
- if (relType) {
323
- for (const targetId of rel.relatedObjects) {
324
- relationshipGraphBuilder.addEdge(rel.relatingObject, targetId, relType, ref.expressId);
325
- }
107
+ }
108
+ logPhase('spatial entities');
109
+ await yieldIfNeeded();
110
+ // Group family (IfcZone / IfcSystem / IfcDistributionSystem / …): small
111
+ // count, full extract so we can resolve Name + LongName + ObjectType for
112
+ // the group label. Name is often empty on these — the human label lives
113
+ // in LongName (IfcZone/IfcDistributionSystem) — so fall back to it, and
114
+ // keep ObjectType (e.g. a system designation) for richer display. (#1075)
115
+ const groupExtra = new Map();
116
+ for (const ref of groupRefs) {
117
+ const entity = extractor.extractEntity(ref);
118
+ if (!entity)
119
+ continue;
120
+ const root = extractRootAttributesFromEntity(entity);
121
+ const longName = pickLongName(entity);
122
+ parsedEntityData.set(ref.expressId, {
123
+ globalId: root.globalId,
124
+ name: root.name || longName,
125
+ });
126
+ groupExtra.set(ref.expressId, { description: root.description, objectType: root.objectType });
127
+ }
128
+ logPhase('group entities');
129
+ await yieldIfNeeded();
130
+ // Geometry + type object entities: batch extract GlobalId+Name with 2 TextDecoder calls
131
+ options.onProgress?.({ phase: 'parsing geometry names', percent: 12 });
132
+ const geomData = await batchExtractGlobalIdAndName(uint8Buffer, geometryRefs, yieldIfNeeded);
133
+ for (const [id, data] of geomData)
134
+ parsedEntityData.set(id, data);
135
+ await yieldIfNeeded();
136
+ const typeData = await batchExtractGlobalIdAndName(uint8Buffer, typeObjectRefs, yieldIfNeeded);
137
+ for (const [id, data] of typeData)
138
+ parsedEntityData.set(id, data);
139
+ logPhase('batch geom GlobalId+Name');
140
+ await yieldIfNeeded();
141
+ // Other relevant products (IfcSpatialZone, IfcVirtualElement, IfcGrid,
142
+ // IfcAnnotation, …): batch GlobalId+Name so they show their Name in the
143
+ // hierarchy / lists instead of nothing. Previously these were added to
144
+ // the EntityTable with an empty name (parsedEntityData never covered
145
+ // this bucket), so e.g. IfcSpatialZone listed without a label. (#1075)
146
+ const otherData = await batchExtractGlobalIdAndName(uint8Buffer, otherRelevantRefs, yieldIfNeeded);
147
+ for (const [id, data] of otherData)
148
+ parsedEntityData.set(id, data);
149
+ logPhase('batch other-relevant GlobalId+Name');
150
+ await yieldIfNeeded();
151
+ // Relationships: byte-level scanning (numbers only, no TextDecoder)
152
+ options.onProgress?.({ phase: 'parsing relationships', percent: 20 });
153
+ for (let i = 0; i < relationshipRefs.length; i++) {
154
+ if ((i & 0x3FF) === 0)
155
+ await yieldIfNeeded();
156
+ const ref = relationshipRefs[i];
157
+ const typeUpper = getTypeUpper(ref.type);
158
+ const rel = extractRelFast(uint8Buffer, ref.byteOffset, ref.byteLength, typeUpper);
159
+ if (rel) {
160
+ const relType = REL_TYPE_MAP[typeUpper];
161
+ if (relType) {
162
+ for (const targetId of rel.relatedObjects) {
163
+ relationshipGraphBuilder.addEdge(rel.relatingObject, targetId, relType, ref.expressId);
326
164
  }
327
165
  }
328
- }
329
- logPhase('byte-level relationships');
330
- // === BUILD ENTITY TABLE from categorized arrays ===
331
- // Instead of iterating ALL 4.4M entityRefs, iterate only categorized arrays
332
- // (~100K-200K total). This eliminates a 200-300ms loop over 4.4M items.
333
- options.onProgress?.({ phase: 'building entities', percent: 30 });
334
- // Helper to add entities with pre-parsed data
335
- const addEntityBatch = (refs, hasGeometry, isType) => {
336
- for (const ref of refs) {
337
- const entityData = parsedEntityData.get(ref.expressId);
338
- entityTableBuilder.add(ref.expressId, ref.type, entityData?.globalId || '', entityData?.name || '', '', // description
339
- '', // objectType
340
- hasGeometry, isType);
166
+ // A second, distinct edge for STEP classes REL_TYPE_MAP folds
167
+ // into a broader bucket (IfcRelNests -> also Nests,
168
+ // IfcRelAssignsToGroupByFactor -> also AssignsToGroupByFactor)
169
+ // so a caller can ask for exactly that class without losing
170
+ // any existing consumer of the broader one (#4205).
171
+ const secondaryRelType = SECONDARY_REL_TYPE_MAP[typeUpper];
172
+ if (secondaryRelType) {
173
+ for (const targetId of rel.relatedObjects) {
174
+ relationshipGraphBuilder.addEdge(rel.relatingObject, targetId, secondaryRelType, ref.expressId);
175
+ }
341
176
  }
342
- };
343
- addEntityBatch(spatialRefs, false, false);
344
- addEntityBatch(geometryRefs, true, false);
345
- addEntityBatch(typeObjectRefs, false, true);
346
- addEntityBatch(relationshipRefs, false, false);
347
- addEntityBatch(otherRelevantRefs, false, false);
348
- // Groups carry Description + ObjectType (the system designation), which
349
- // the shared addEntityBatch drops as ''. Add them with the extra fields
350
- // so the Properties title / lists / lens can surface them. (#1075)
351
- for (const ref of groupRefs) {
352
- const entityData = parsedEntityData.get(ref.expressId);
353
- const extra = groupExtra.get(ref.expressId);
354
- entityTableBuilder.add(ref.expressId, ref.type, entityData?.globalId || '', entityData?.name || '', extra?.description || '', extra?.objectType || '', false, false);
355
177
  }
356
- logPhase('add entity batches');
357
- const entityTable = entityTableBuilder.build();
358
- logPhase('entity table build()');
359
- // Empty property/quantity tables - use on-demand extraction instead
360
- const propertyTable = propertyTableBuilder.build();
361
- const quantityTable = quantityTableBuilder.build();
362
- // Build intermediate relationship graph (spatial/hierarchy edges only).
363
- // Property/association edges are added later; final graph is rebuilt at the end.
364
- const hierarchyRelGraph = relationshipGraphBuilder.build();
365
- logPhase('hierarchy rel graph build()');
366
- await yieldIfNeeded();
367
- // === EXTRACT LENGTH UNIT SCALE ===
368
- options.onProgress?.({ phase: 'extracting units', percent: 85 });
369
- const lengthUnitScale = extractLengthUnitScale(uint8Buffer, entityIndex);
370
- // === BUILD SPATIAL HIERARCHY ===
371
- options.onProgress?.({ phase: 'building hierarchy', percent: 90 });
372
- let spatialHierarchy;
373
- try {
374
- const hierarchyBuilder = new SpatialHierarchyBuilder();
375
- spatialHierarchy = hierarchyBuilder.build(entityTable, hierarchyRelGraph, strings, uint8Buffer, entityIndex, lengthUnitScale);
376
- logPhase('spatial hierarchy');
377
- }
378
- catch (error) {
379
- console.warn('[ColumnarParser] Failed to build spatial hierarchy:', error);
380
- }
381
- // === EMIT SPATIAL HIERARCHY EARLY ===
382
- // The hierarchy panel can render immediately while property/association
383
- // parsing continues. This lets the panel appear at the same time as
384
- // geometry streaming completes.
385
- // ONE accessor, shared by the store field and the entity source.
386
- //
387
- // These used to be built separately -- `BufferEntitySource` got the raw
388
- // `uint8Buffer` and wrapped it in its own accessor, while `source` got
389
- // another. That is invisible while both are resident views over the
390
- // same bytes, and fatal once the source can switch to compressed
391
- // storage in place (#2183): `getEntity` would keep reading its private
392
- // resident accessor, so the original buffer would never be released and
393
- // the store would serve entities from one representation and properties
394
- // from the other. Measured: with two accessors the buffer survives GC
395
- // after the swap; with one it is collected.
396
- const source = contiguousSourceBytes(uint8Buffer);
397
- const entitySource = new BufferEntitySource(source, entityIndex);
398
- const earlyStore = {
399
- fileSize: buffer.byteLength,
400
- schemaVersion,
401
- sourceHeader,
402
- entityCount: totalEntities,
403
- parseTime: performance.now() - startTime,
404
- source,
405
- entityIndex,
406
- strings,
407
- entities: entityTable,
408
- properties: propertyTable,
409
- quantities: quantityTable,
410
- relationships: hierarchyRelGraph,
411
- spatialHierarchy,
412
- lengthUnitScale,
413
- getEntity(expressId) { return entitySource.getEntity(expressId); },
414
- getEntitiesByType(typeName) { return entitySource.getEntitiesByType(typeName); },
415
- getProperties(expressId) { return this.properties.getForEntity(expressId); },
416
- getQuantities(expressId) { return this.quantities.getForEntity(expressId); },
417
- };
418
- options.onSpatialReady?.(earlyStore);
419
- await yieldIfNeeded(); // Let geometry process after hierarchy emission
420
- // === DEFERRED: Parse property and association relationships ===
421
- // These are NOT needed for the spatial hierarchy panel.
422
- options.onProgress?.({ phase: 'parsing property refs', percent: 92 });
423
- const onDemandPropertyMap = new Map();
424
- const onDemandQuantityMap = new Map();
425
- // Pre-build Sets of property set / quantity set IDs from already-categorized refs.
426
- // This replaces 252K binary searches on the 14M compact entity index with O(1) Set lookups.
427
- const propertySetIds = new Set();
428
- const quantitySetIds = new Set();
429
- for (const ref of propertyContainerRefs) {
430
- const tu = getTypeUpper(ref.type);
431
- if (tu === 'IFCPROPERTYSET')
432
- propertySetIds.add(ref.expressId);
433
- else if (tu === 'IFCELEMENTQUANTITY')
434
- quantitySetIds.add(ref.expressId);
178
+ }
179
+ logPhase('byte-level relationships');
180
+ // === BUILD ENTITY TABLE from categorized arrays ===
181
+ // Instead of iterating ALL 4.4M entityRefs, iterate only categorized arrays
182
+ // (~100K-200K total). This eliminates a 200-300ms loop over 4.4M items.
183
+ options.onProgress?.({ phase: 'building entities', percent: 30 });
184
+ // Helper to add entities with pre-parsed data
185
+ const addEntityBatch = (refs, hasGeometry, isType) => {
186
+ for (const ref of refs) {
187
+ const entityData = parsedEntityData.get(ref.expressId);
188
+ entityTableBuilder.add(ref.expressId, ref.type, entityData?.globalId || '', entityData?.name || '', '', // description
189
+ '', // objectType
190
+ hasGeometry, isType);
435
191
  }
436
- // Property rels: byte-level scanning + addEdge (now fast with SoA builder).
437
- let totalPropRelObjects = 0;
438
- for (let pi = 0; pi < propertyRelRefs.length; pi++) {
439
- if ((pi & 0x3FF) === 0)
440
- await yieldIfNeeded();
441
- const ref = propertyRelRefs[pi];
442
- const result = extractPropertyRelFast(uint8Buffer, ref.byteOffset, ref.byteLength);
443
- if (result) {
444
- const { relatedObjects, relatingDefs } = result;
445
- totalPropRelObjects += relatedObjects.length;
446
- // RelatingPropertyDefinition is IfcPropertySetDefinitionSelect, whose
447
- // second alternative (IfcPropertySetDefinitionSet) is a SET of pset/
448
- // qset definitions `relatingDefs` has more than one entry for that
449
- // case. Every entry in the group applies to every related object.
450
- for (const relatingDef of relatingDefs) {
192
+ };
193
+ addEntityBatch(spatialRefs, false, false);
194
+ addEntityBatch(geometryRefs, true, false);
195
+ addEntityBatch(typeObjectRefs, false, true);
196
+ addEntityBatch(relationshipRefs, false, false);
197
+ addEntityBatch(otherRelevantRefs, false, false);
198
+ // Groups carry Description + ObjectType (the system designation), which
199
+ // the shared addEntityBatch drops as ''. Add them with the extra fields
200
+ // so the Properties title / lists / lens can surface them. (#1075)
201
+ for (const ref of groupRefs) {
202
+ const entityData = parsedEntityData.get(ref.expressId);
203
+ const extra = groupExtra.get(ref.expressId);
204
+ entityTableBuilder.add(ref.expressId, ref.type, entityData?.globalId || '', entityData?.name || '', extra?.description || '', extra?.objectType || '', false, false);
205
+ }
206
+ logPhase('add entity batches');
207
+ const entityTable = entityTableBuilder.build();
208
+ logPhase('entity table build()');
209
+ // Empty property/quantity tables - use on-demand extraction instead
210
+ const propertyTable = propertyTableBuilder.build();
211
+ const quantityTable = quantityTableBuilder.build();
212
+ // Build intermediate relationship graph (spatial/hierarchy edges only).
213
+ // Property/association edges are added later; final graph is rebuilt at the end.
214
+ const hierarchyRelGraph = relationshipGraphBuilder.build();
215
+ logPhase('hierarchy rel graph build()');
216
+ await yieldIfNeeded();
217
+ // === EXTRACT LENGTH UNIT SCALE ===
218
+ options.onProgress?.({ phase: 'extracting units', percent: 85 });
219
+ const lengthUnitScale = extractLengthUnitScale(uint8Buffer, entityIndex);
220
+ // === BUILD SPATIAL HIERARCHY ===
221
+ options.onProgress?.({ phase: 'building hierarchy', percent: 90 });
222
+ let spatialHierarchy;
223
+ try {
224
+ const hierarchyBuilder = new SpatialHierarchyBuilder();
225
+ spatialHierarchy = hierarchyBuilder.build(entityTable, hierarchyRelGraph, strings, uint8Buffer, entityIndex, lengthUnitScale);
226
+ logPhase('spatial hierarchy');
227
+ }
228
+ catch (error) {
229
+ console.warn('[ColumnarParser] Failed to build spatial hierarchy:', error);
230
+ }
231
+ // === EMIT SPATIAL HIERARCHY EARLY ===
232
+ // The hierarchy panel can render immediately while property/association
233
+ // parsing continues. This lets the panel appear at the same time as
234
+ // geometry streaming completes.
235
+ // ONE accessor, shared by the store field and the entity source.
236
+ //
237
+ // These used to be built separately -- `BufferEntitySource` got the raw
238
+ // `uint8Buffer` and wrapped it in its own accessor, while `source` got
239
+ // another. That is invisible while both are resident views over the
240
+ // same bytes, and fatal once the source can switch to compressed
241
+ // storage in place (#2183): `getEntity` would keep reading its private
242
+ // resident accessor, so the original buffer would never be released and
243
+ // the store would serve entities from one representation and properties
244
+ // from the other. Measured: with two accessors the buffer survives GC
245
+ // after the swap; with one it is collected.
246
+ const source = contiguousSourceBytes(uint8Buffer);
247
+ const entitySource = new BufferEntitySource(source, entityIndex);
248
+ const earlyStore = {
249
+ fileSize: buffer.byteLength,
250
+ schemaVersion,
251
+ sourceHeader,
252
+ entityCount: totalEntities,
253
+ parseTime: performance.now() - startTime,
254
+ source,
255
+ entityIndex,
256
+ dropCensus: prepared.dropCensus,
257
+ strings,
258
+ entities: entityTable,
259
+ properties: propertyTable,
260
+ quantities: quantityTable,
261
+ relationships: hierarchyRelGraph,
262
+ spatialHierarchy,
263
+ lengthUnitScale,
264
+ getEntity(expressId) { return entitySource.getEntity(expressId); },
265
+ getEntitiesByType(typeName) { return entitySource.getEntitiesByType(typeName); },
266
+ getProperties(expressId) { return this.properties.getForEntity(expressId); },
267
+ getQuantities(expressId) { return this.quantities.getForEntity(expressId); },
268
+ };
269
+ options.onSpatialReady?.(earlyStore);
270
+ await yieldIfNeeded(); // Let geometry process after hierarchy emission
271
+ // === DEFERRED: Parse property and association relationships ===
272
+ // These are NOT needed for the spatial hierarchy panel.
273
+ options.onProgress?.({ phase: 'parsing property refs', percent: 92 });
274
+ const onDemandPropertyMap = new Map();
275
+ const onDemandQuantityMap = new Map();
276
+ // Pre-build Sets of property set / quantity set IDs from already-categorized refs.
277
+ // This replaces 252K binary searches on the 14M compact entity index with O(1) Set lookups.
278
+ const propertySetIds = new Set();
279
+ const quantitySetIds = new Set();
280
+ for (const ref of propertyContainerRefs) {
281
+ const tu = getTypeUpper(ref.type);
282
+ if (tu === 'IFCPROPERTYSET')
283
+ propertySetIds.add(ref.expressId);
284
+ else if (tu === 'IFCELEMENTQUANTITY')
285
+ quantitySetIds.add(ref.expressId);
286
+ }
287
+ // Property rels: byte-level scanning + addEdge (now fast with SoA builder).
288
+ let totalPropRelObjects = 0;
289
+ for (let pi = 0; pi < propertyRelRefs.length; pi++) {
290
+ if ((pi & 0x3FF) === 0)
291
+ await yieldIfNeeded();
292
+ const ref = propertyRelRefs[pi];
293
+ const result = extractPropertyRelFast(uint8Buffer, ref.byteOffset, ref.byteLength);
294
+ if (result) {
295
+ const { relatedObjects, relatingDefs } = result;
296
+ totalPropRelObjects += relatedObjects.length;
297
+ // RelatingPropertyDefinition is IfcPropertySetDefinitionSelect, whose
298
+ // second alternative (IfcPropertySetDefinitionSet) is a SET of pset/
299
+ // qset definitions — `relatingDefs` has more than one entry for that
300
+ // case. Every entry in the group applies to every related object.
301
+ for (const relatingDef of relatingDefs) {
302
+ for (const objId of relatedObjects) {
303
+ relationshipGraphBuilder.addEdge(relatingDef, objId, RelationshipType.DefinesByProperties, ref.expressId);
304
+ }
305
+ // Build on-demand property/quantity maps using pre-built Sets (O(1) vs binary search)
306
+ const isPropSet = propertySetIds.has(relatingDef);
307
+ const isQtySet = !isPropSet && quantitySetIds.has(relatingDef);
308
+ if (isPropSet || isQtySet) {
309
+ const targetMap = isPropSet ? onDemandPropertyMap : onDemandQuantityMap;
451
310
  for (const objId of relatedObjects) {
452
- relationshipGraphBuilder.addEdge(relatingDef, objId, RelationshipType.DefinesByProperties, ref.expressId);
453
- }
454
- // Build on-demand property/quantity maps using pre-built Sets (O(1) vs binary search)
455
- const isPropSet = propertySetIds.has(relatingDef);
456
- const isQtySet = !isPropSet && quantitySetIds.has(relatingDef);
457
- if (isPropSet || isQtySet) {
458
- const targetMap = isPropSet ? onDemandPropertyMap : onDemandQuantityMap;
459
- for (const objId of relatedObjects) {
460
- addOnDemandRef(targetMap, objId, relatingDef);
461
- }
311
+ addOnDemandRef(targetMap, objId, relatingDef);
462
312
  }
463
313
  }
464
314
  }
465
315
  }
466
- await yieldIfNeeded();
467
- // Association rels: byte-level scanning, no addEdge (same reasoning as property rels)
468
- options.onProgress?.({ phase: 'parsing associations', percent: 95 });
469
- const onDemandClassificationMap = new Map();
470
- const onDemandMaterialMap = new Map();
471
- const onDemandDocumentMap = new Map();
472
- // Determinism rule for elements with MULTIPLE IfcRelAssociatesMaterial:
473
- // the map keeps EVERY association (list-valued), ordered by rel express
474
- // id, so list[0] the "primary" is the RelatingMaterial of the
475
- // LOWEST rel express id regardless of file order. The cache rebuild
476
- // (viewer spatialHierarchy rebuildOnDemandMaps) applies the same rule
477
- // via edge relationshipIds, so fresh-parse and cache-load agree.
478
- const materialRelIds = new Map();
479
- for (let i = 0; i < associationRelRefs.length; i++) {
480
- if ((i & 0x3FF) === 0)
481
- await yieldIfNeeded();
482
- const ref = associationRelRefs[i];
483
- const result = extractPropertyRelFast(uint8Buffer, ref.byteOffset, ref.byteLength);
484
- if (result) {
485
- // IfcRelAssociates{Material,Classification,Document}'s Relating*
486
- // selects are always single refs (unlike RelatingPropertyDefinition
487
- // above, none of IfcMaterialSelect/IfcClassificationSelect/
488
- // IfcDocumentSelect admit a SET alternative) — take the one entry.
489
- const { relatedObjects, relatingDefs } = result;
490
- const relatingRef = relatingDefs[0];
491
- const typeUpper = getTypeUpper(ref.type);
492
- if (typeUpper === 'IFCRELASSOCIATESCLASSIFICATION') {
493
- for (const objId of relatedObjects) {
494
- addOnDemandRef(onDemandClassificationMap, objId, relatingRef);
495
- relationshipGraphBuilder.addEdge(relatingRef, objId, RelationshipType.AssociatesClassification, ref.expressId);
496
- }
316
+ }
317
+ await yieldIfNeeded();
318
+ // Association rels: byte-level scanning, no addEdge (same reasoning as property rels)
319
+ options.onProgress?.({ phase: 'parsing associations', percent: 95 });
320
+ const onDemandClassificationMap = new Map();
321
+ const onDemandMaterialMap = new Map();
322
+ const onDemandDocumentMap = new Map();
323
+ // Determinism rule for elements with MULTIPLE IfcRelAssociatesMaterial:
324
+ // the map keeps EVERY association (list-valued), ordered by rel express
325
+ // id, so list[0] the "primary" is the RelatingMaterial of the
326
+ // LOWEST rel express id regardless of file order. The cache rebuild
327
+ // (viewer spatialHierarchy rebuildOnDemandMaps) applies the same rule
328
+ // via edge relationshipIds, so fresh-parse and cache-load agree.
329
+ const materialRelIds = new Map();
330
+ for (let i = 0; i < associationRelRefs.length; i++) {
331
+ if ((i & 0x3FF) === 0)
332
+ await yieldIfNeeded();
333
+ const ref = associationRelRefs[i];
334
+ const result = extractPropertyRelFast(uint8Buffer, ref.byteOffset, ref.byteLength);
335
+ if (result) {
336
+ // IfcRelAssociates{Material,Classification,Document}'s Relating*
337
+ // selects are always single refs (unlike RelatingPropertyDefinition
338
+ // above, none of IfcMaterialSelect/IfcClassificationSelect/
339
+ // IfcDocumentSelect admit a SET alternative) — take the one entry.
340
+ const { relatedObjects, relatingDefs } = result;
341
+ const relatingRef = relatingDefs[0];
342
+ const typeUpper = getTypeUpper(ref.type);
343
+ if (typeUpper === 'IFCRELASSOCIATESCLASSIFICATION') {
344
+ for (const objId of relatedObjects) {
345
+ addOnDemandRef(onDemandClassificationMap, objId, relatingRef);
346
+ relationshipGraphBuilder.addEdge(relatingRef, objId, RelationshipType.AssociatesClassification, ref.expressId);
497
347
  }
498
- else if (typeUpper === 'IFCRELASSOCIATESMATERIAL') {
499
- for (const objId of relatedObjects) {
500
- let list = onDemandMaterialMap.get(objId);
501
- let relIds = materialRelIds.get(objId);
502
- if (!list || !relIds) {
503
- list = [];
504
- onDemandMaterialMap.set(objId, list);
505
- relIds = [];
506
- materialRelIds.set(objId, relIds);
507
- }
508
- // Deliberately NOT deduped (#3782 review): buildMaterialUsageIndex
509
- // already dedupes downstream (seenPerMaterial), per material-fraction-and-associations.test.ts.
510
- let at = relIds.length;
511
- while (at > 0 && relIds[at - 1] > ref.expressId)
512
- at--;
513
- relIds.splice(at, 0, ref.expressId);
514
- list.splice(at, 0, relatingRef);
515
- relationshipGraphBuilder.addEdge(relatingRef, objId, RelationshipType.AssociatesMaterial, ref.expressId);
348
+ }
349
+ else if (typeUpper === 'IFCRELASSOCIATESMATERIAL') {
350
+ for (const objId of relatedObjects) {
351
+ let list = onDemandMaterialMap.get(objId);
352
+ let relIds = materialRelIds.get(objId);
353
+ if (!list || !relIds) {
354
+ list = [];
355
+ onDemandMaterialMap.set(objId, list);
356
+ relIds = [];
357
+ materialRelIds.set(objId, relIds);
516
358
  }
359
+ // Deliberately NOT deduped (#3782 review): buildMaterialUsageIndex
360
+ // already dedupes downstream (seenPerMaterial), per material-fraction-and-associations.test.ts.
361
+ let at = relIds.length;
362
+ while (at > 0 && relIds[at - 1] > ref.expressId)
363
+ at--;
364
+ relIds.splice(at, 0, ref.expressId);
365
+ list.splice(at, 0, relatingRef);
366
+ relationshipGraphBuilder.addEdge(relatingRef, objId, RelationshipType.AssociatesMaterial, ref.expressId);
517
367
  }
518
- else if (typeUpper === 'IFCRELASSOCIATESDOCUMENT') {
519
- for (const objId of relatedObjects) {
520
- addOnDemandRef(onDemandDocumentMap, objId, relatingRef);
521
- relationshipGraphBuilder.addEdge(relatingRef, objId, RelationshipType.AssociatesDocument, ref.expressId);
522
- }
368
+ }
369
+ else if (typeUpper === 'IFCRELASSOCIATESDOCUMENT') {
370
+ for (const objId of relatedObjects) {
371
+ addOnDemandRef(onDemandDocumentMap, objId, relatingRef);
372
+ relationshipGraphBuilder.addEdge(relatingRef, objId, RelationshipType.AssociatesDocument, ref.expressId);
523
373
  }
524
374
  }
525
375
  }
526
- logPhase('property+association rels');
527
- // Rebuild relationship graph with ALL edges (hierarchy + property + association)
528
- const fullRelationshipGraph = relationshipGraphBuilder.build();
529
- logPhase('relationship graph build()');
530
- let deferredEntityIndex;
531
- if (deferPropertyAtomIndex && propertyAtomRefs.length > 0) {
532
- options.onProgress?.({ phase: 'indexing property atoms', percent: 98 });
533
- deferredEntityIndex = await buildCompactEntityIndexAsync(propertyAtomRefs, undefined, 1024, 2);
534
- logPhase('deferred property atom index');
535
- }
536
- const parseTime = performance.now() - startTime;
537
- options.onProgress?.({ phase: 'complete', percent: 100 });
538
- const finalStore = {
539
- ...earlyStore,
540
- parseTime,
541
- relationships: fullRelationshipGraph,
542
- deferredEntityIndex,
543
- onDemandPropertyMap,
544
- onDemandQuantityMap,
545
- onDemandClassificationMap,
546
- onDemandMaterialMap,
547
- onDemandDocumentMap,
548
- lengthUnitScale,
549
- getEntity(expressId) { return entitySource.getEntity(expressId); },
550
- getEntitiesByType(typeName) { return entitySource.getEntitiesByType(typeName); },
551
- getProperties(expressId) {
552
- if (onDemandPropertyMap.size > 0)
553
- return extractPropertiesOnDemand(this, expressId);
554
- return this.properties.getForEntity(expressId);
555
- },
556
- getQuantities(expressId) {
557
- if (onDemandQuantityMap.size > 0)
558
- return extractQuantitiesOnDemand(this, expressId);
559
- return this.quantities.getForEntity(expressId);
560
- },
561
- };
562
- return finalStore;
376
+ }
377
+ logPhase('property+association rels');
378
+ // Rebuild relationship graph with ALL edges (hierarchy + property + association)
379
+ const fullRelationshipGraph = relationshipGraphBuilder.build();
380
+ logPhase('relationship graph build()');
381
+ let deferredEntityIndex;
382
+ if (options.deferPropertyAtomIndex && prepared.propertyAtomCount > 0) {
383
+ options.onProgress?.({ phase: 'indexing property atoms', percent: 98 });
384
+ deferredEntityIndex = await prepared.buildDeferredIndex();
385
+ logPhase('deferred property atom index');
386
+ }
387
+ const parseTime = performance.now() - startTime;
388
+ options.onProgress?.({ phase: 'complete', percent: 100 });
389
+ const finalStore = {
390
+ ...earlyStore,
391
+ parseTime,
392
+ relationships: fullRelationshipGraph,
393
+ deferredEntityIndex,
394
+ onDemandPropertyMap,
395
+ onDemandQuantityMap,
396
+ onDemandClassificationMap,
397
+ onDemandMaterialMap,
398
+ onDemandDocumentMap,
399
+ lengthUnitScale,
400
+ getEntity(expressId) { return entitySource.getEntity(expressId); },
401
+ getEntitiesByType(typeName) { return entitySource.getEntitiesByType(typeName); },
402
+ getProperties(expressId) {
403
+ if (onDemandPropertyMap.size > 0)
404
+ return extractPropertiesOnDemand(this, expressId);
405
+ return this.properties.getForEntity(expressId);
406
+ },
407
+ getQuantities(expressId) {
408
+ if (onDemandQuantityMap.size > 0)
409
+ return extractQuantitiesOnDemand(this, expressId);
410
+ return this.quantities.getForEntity(expressId);
411
+ },
412
+ };
413
+ return finalStore;
414
+ }
415
+ export class ColumnarParser {
416
+ /**
417
+ * Parse IFC file into columnar data store
418
+ *
419
+ * Uses fast semicolon-based scanning with on-demand property extraction.
420
+ * Properties are parsed lazily when accessed, not upfront.
421
+ * This provides instant UI responsiveness even for very large files.
422
+ */
423
+ async parseLite(buffer, entityRefs, options = {}) {
424
+ return parseColumnarInput(buffer, entityRefs, options);
563
425
  }
564
426
  /**
565
427
  * Extract properties for a single entity ON-DEMAND
@@ -665,236 +527,7 @@ export function extractQuantitiesOnDemand(store, entityId) {
665
527
  const parser = new ColumnarParser();
666
528
  return parser.extractQuantitiesOnDemand(store, entityId);
667
529
  }
668
- function getEntityRefFromStore(store, expressId) {
669
- return store.entityIndex.byId.get(expressId) ?? store.deferredEntityIndex?.get(expressId);
670
- }
671
- /**
672
- * Extract entity attributes on-demand from source buffer.
673
- * Returns globalId, name, description, objectType, tag mapped by schema name
674
- * (see {@link extractRootAttributesFromEntity}), so the result stays correct
675
- * for entity types whose attribute order differs from the IfcElement layout.
676
- * This is used for entities that weren't fully parsed during initial load.
677
- */
678
- export function extractEntityAttributesOnDemand(store, entityId) {
679
- const ref = store.entityIndex.byId.get(entityId);
680
- if (!ref) {
681
- return { globalId: '', name: '', description: '', objectType: '', tag: '' };
682
- }
683
- const extractor = new EntityExtractor(store.source);
684
- const entity = extractor.extractEntity(ref);
685
- if (!entity) {
686
- return { globalId: '', name: '', description: '', objectType: '', tag: '' };
687
- }
688
- return extractRootAttributesFromEntity(entity);
689
- }
690
- /**
691
- * Extract ALL named entity attributes on-demand from source buffer.
692
- * Uses the IFC schema to map attribute indices to names.
693
- * Returns only string/enum attributes, skipping references and structural attributes.
694
- */
695
- export function extractAllEntityAttributes(store, entityId) {
696
- const ref = store.entityIndex.byId.get(entityId);
697
- if (!ref)
698
- return [];
699
- const extractor = new EntityExtractor(store.source);
700
- const entity = extractor.extractEntity(ref);
701
- if (!entity)
702
- return [];
703
- const attrs = entity.attributes || [];
704
- // Use properly-cased type name from entity table (IfcTypeEnumToString)
705
- // instead of ref.type which is UPPERCASE from STEP (e.g., IFCWALLSTANDARDCASE)
706
- // and breaks multi-word type normalization in getAttributeNames.
707
- // For resource-level entities (IfcTask, IfcTaskTime, IfcMaterial,
708
- // IfcClassification, ...) the entity table returns 'Unknown';
709
- // fall back to ref.type so the schema-driven attribute-name
710
- // resolution still works for those types.
711
- const tableName = store.entities.getTypeName(entityId);
712
- const typeName = tableName && tableName !== 'Unknown' ? tableName : ref.type;
713
- // Named across the bundled schema union (2X3 + 4 + 4X3), not through the
714
- // IFC4 codegen pin alone. The pin answers an EMPTY list — not a wrong one —
715
- // for every class it does not carry, and 251 real classes are outside it:
716
- // the IFC2X3 ones IFC4 dropped and the whole IFC4X3 infrastructure
717
- // vocabulary (`IfcCourse`, `IfcPavement`, `IfcKerb`, `IfcSignal`, `IfcRoad`,
718
- // …). An empty list means this function returns NO attributes for such an
719
- // entity, so every caller that looks one up by name silently finds nothing
720
- // and cannot tell that apart from an unset slot. The model-diff adapters
721
- // read `PredefinedType` this way, which made a cleared `PredefinedType` —
722
- // the single most common edit in a real infrastructure revision — compare
723
- // equal to itself on exactly the classes IFC4X3 exists for. Same pinned-
724
- // registry family as #2001/#2003/#2021.
725
- //
726
- // Provably additive: `getAttributeNamesAcrossSchemas` returns the pinned
727
- // result unchanged whenever the pin has one, so no IFC2X3 or IFC4 entity's
728
- // attribute list — or the hash anyone derives from it — moves.
729
- const attrNames = getAttributeNamesAcrossSchemas(typeName);
730
- const result = [];
731
- const len = Math.min(attrs.length, attrNames.length);
732
- for (let i = 0; i < len; i++) {
733
- const attrName = attrNames[i];
734
- if (SKIP_DISPLAY_ATTRS.has(attrName))
735
- continue;
736
- const raw = attrs[i];
737
- // STEP `$` (unset) and `*` (derived) deserialize as null /
738
- // undefined and must be skipped. Strings are emitted with
739
- // `.ENUM.` markers stripped. Empty strings are preserved so
740
- // IDS optional-attribute checks can distinguish "slot truly
741
- // absent" from "slot explicitly empty". Numbers and booleans
742
- // pass through unchanged so e.g. `CountValue = 0` reads as
743
- // present.
744
- if (typeof raw === 'string') {
745
- // STEP logical-unknown markers (`.U.`, `.X.`) read as
746
- // "no value" per IDS spec — they fail any attribute
747
- // check, including a bare existence check, so don't
748
- // surface them as if the slot were populated.
749
- if (raw === '.U.' || raw === '.X.')
750
- continue;
751
- // Bare boolean tokens (`.T.` / `.F.`) on a schema-typed
752
- // IfcBoolean attribute slot — resolve to JS boolean so
753
- // IDS checks comparing against `true` / `false` literals
754
- // pass without case-sensitive string contortions.
755
- if (raw === '.T.') {
756
- result.push({ name: attrName, value: true });
757
- continue;
758
- }
759
- if (raw === '.F.') {
760
- result.push({ name: attrName, value: false });
761
- continue;
762
- }
763
- const display = raw.startsWith('.') && raw.endsWith('.')
764
- ? raw.slice(1, -1)
765
- : raw;
766
- result.push({ name: attrName, value: display });
767
- }
768
- else if (typeof raw === 'number' || typeof raw === 'boolean') {
769
- result.push({ name: attrName, value: raw });
770
- }
771
- else if (Array.isArray(raw) && raw.length === 2) {
772
- // Typed STEP values like IFCREAL(0.0), IFCBOOLEAN(.T.) —
773
- // return the underlying primitive so attribute existence
774
- // and value checks can compare it directly.
775
- const inner = raw[1];
776
- const tag = String(raw[0]).toUpperCase();
777
- if (tag.includes('BOOLEAN')) {
778
- result.push({ name: attrName, value: inner === '.T.' || inner === true });
779
- }
780
- else if (tag.includes('LOGICAL')) {
781
- if (inner === '.U.' || inner === '.X.') {
782
- // UNKNOWN logical → don't surface (treated as absent)
783
- continue;
784
- }
785
- result.push({ name: attrName, value: inner === '.T.' || inner === true });
786
- }
787
- else if (typeof inner === 'number' || typeof inner === 'boolean') {
788
- result.push({ name: attrName, value: inner });
789
- }
790
- else if (typeof inner === 'string' && inner) {
791
- const display = inner.startsWith('.') && inner.endsWith('.')
792
- ? inner.slice(1, -1)
793
- : inner;
794
- result.push({ name: attrName, value: display });
795
- }
796
- }
797
- }
798
- return result;
799
- }
800
- /**
801
- * Returns named raw attribute pairs for an entity, filtered to display-relevant attributes.
802
- * Skips structural/reference attributes using the IFC schema. Used by query layer for coercion.
803
- */
804
- export function getRawNamedAttributes(entity) {
805
- const attrs = entity.attributes || [];
806
- const attrNames = getAttributeNames(entity.type);
807
- const result = [];
808
- const len = Math.min(attrs.length, attrNames.length);
809
- for (let i = 0; i < len; i++) {
810
- const attrName = attrNames[i];
811
- if (SKIP_DISPLAY_ATTRS.has(attrName))
812
- continue;
813
- result.push({ name: attrName, raw: attrs[i] });
814
- }
815
- return result;
816
- }
817
- // getAttributeNames() walks the schema registry (an O(types) scan for the
818
- // UPPERCASE STEP names entities carry), so memoise the per-type index lookup.
819
- // There are only a few hundred distinct types but potentially millions of
820
- // entities, keeping the on-demand path cheap even when called per entity.
821
- const rootAttrIndexCache = new Map();
822
- function getRootAttrIndices(type) {
823
- let idx = rootAttrIndexCache.get(type);
824
- if (!idx) {
825
- const names = getAttributeNames(type);
826
- idx = {
827
- known: names.length > 0,
828
- globalId: names.indexOf('GlobalId'),
829
- name: names.indexOf('Name'),
830
- description: names.indexOf('Description'),
831
- objectType: names.indexOf('ObjectType'),
832
- tag: names.indexOf('Tag'),
833
- longName: names.indexOf('LongName'),
834
- };
835
- rootAttrIndexCache.set(type, idx);
836
- }
837
- return idx;
838
- }
839
- /**
840
- * Resolve the common IfcRoot-family display attributes (GlobalId, Name,
841
- * Description, ObjectType, Tag) from an entity's raw attribute array.
842
- *
843
- * These are mapped by schema-derived attribute *name*, not fixed index. The
844
- * fixed indices `[0],[2],[3],[4],[7]` only hold for the IfcElement layout: for
845
- * a spatial element `attrs[7]` is LongName (not Tag), and for a resource entity
846
- * like IfcMaterial `attrs[0]` is Name (not GlobalId). Name-mapping keeps all of
847
- * these correct for every entity type, returning '' for attributes the type
848
- * does not declare.
849
- *
850
- * For types the schema registry does not recognise (e.g. an IFC4x3 infra leaf
851
- * outside the codegen pin, or a vendor extension) we fall back to the canonical
852
- * IfcRoot/IfcElement positions so we never regress vs. the old fixed-index path.
853
- */
854
- export function extractRootAttributesFromEntity(entity) {
855
- const attrs = entity.attributes || [];
856
- const enumIdx = entity.enumAttrIndices;
857
- const idx = getRootAttrIndices(entity.type);
858
- const pick = (schemaIndex, fallbackIndex) => {
859
- const i = idx.known ? schemaIndex : fallbackIndex;
860
- const raw = i >= 0 ? attrs[i] : undefined;
861
- if (typeof raw !== 'string')
862
- return '';
863
- // Unknown-type fallback only: a fixed index can land on a STEP bare-enum
864
- // token — e.g. a PredefinedType at attr 7 for a non-IfcElement layout —
865
- // which must not leak into a Tag/Description cell. Reject by token KIND
866
- // via the extractor's side channel (#1799), not by dotted-string shape:
867
- // a quoted string that merely looks like an enum ('.USERDEFINED.')
868
- // survives, exactly matching the Rust server path (string_at accepts
869
- // AttributeValue::String and rejects ::Enum, #1779). Skipped for known
870
- // types, whose schema indices point at genuine string slots.
871
- if (!idx.known && enumIdx !== undefined && enumIdx.includes(i))
872
- return '';
873
- return raw;
874
- };
875
- return {
876
- globalId: pick(idx.globalId, 0),
877
- name: pick(idx.name, 2),
878
- description: pick(idx.description, 3),
879
- objectType: pick(idx.objectType, 4),
880
- tag: pick(idx.tag, 7),
881
- };
882
- }
883
- /**
884
- * Resolve an entity's LongName (IfcZone, IfcSystem subtypes, IfcSpatialZone,
885
- * IfcBuildingSystem, …) by schema attribute name. Groups frequently leave Name
886
- * empty and carry their human label in LongName, so consumers fall back to this
887
- * for the display label. Returns '' when the type does not declare LongName.
888
- * (#1075)
889
- */
890
- export function pickLongName(entity) {
891
- const idx = getRootAttrIndices(entity.type);
892
- if (!idx.known || idx.longName < 0)
893
- return '';
894
- const raw = (entity.attributes || [])[idx.longName];
895
- return typeof raw === 'string' ? raw : '';
896
- }
897
530
  // Re-export on-demand extraction functions from focused module
898
- export { extractClassificationsOnDemand, extractClassificationSystemsOnDemand, extractMaterialsOnDemand, extractAllMaterialsOnDemand, extractMaterialPropertiesOnDemand, extractMaterialPropertiesForMaterialId, resolveMaterialDefId, resolveAllMaterialDefIds, collectMaterialLeaves, buildMaterialUsageIndex, getMaterialDisplay, extractTypePropertiesOnDemand, extractTypeEntityOwnProperties, extractTypeQuantitiesOnDemand, extractDocumentsOnDemand, extractRelationshipsOnDemand, extractGroupMembersOnDemand, extractGeoreferencingOnDemand, parsePropertyValue, extractPsetsFromIds, extractQsetsFromIds, } from './on-demand-extractors.js';
531
+ export { extractClassificationsOnDemand, extractClassificationSystemsOnDemand, extractMaterialsOnDemand, extractAllMaterialsOnDemand, extractMaterialPropertiesOnDemand, extractMaterialPropertiesForMaterialId, resolveMaterialDefId, resolveAllMaterialDefIds, collectMaterialLeaves, buildMaterialUsageIndex, getMaterialDisplay, extractTypePropertiesOnDemand, extractTypeEntityOwnProperties, extractTypeQuantitiesOnDemand, extractDocumentsOnDemand, extractRelationshipsOnDemand, extractGroupMembersOnDemand, extractGroupAssignmentFactorOnDemand, extractGeoreferencingOnDemand, parsePropertyValue, extractPsetsFromIds, extractQsetsFromIds, } from './on-demand-extractors.js';
899
532
  export { mergeInheritedPropertySets, mergeInheritedQuantitySets } from './property-set-merge.js';
900
533
  //# sourceMappingURL=columnar-parser.js.map