@twinfinity/printing 6.0.1-ci.28952-beta → 6.0.2-beta

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 (82) hide show
  1. package/README.md +3 -3
  2. package/dist/BuildInfo.js +3 -3
  3. package/dist/BuildInfo.js.map +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/layout/analyzeTemplate.js.map +1 -1
  6. package/dist/layout/clipUtils.js.map +1 -1
  7. package/dist/layout/colorConstants.js.map +1 -1
  8. package/dist/layout/elementKinds.js.map +1 -1
  9. package/dist/layout/exportDrawing.js.map +1 -1
  10. package/dist/layout/filters.js.map +1 -1
  11. package/dist/layout/geometryConstants.js.map +1 -1
  12. package/dist/layout/index.js.map +1 -1
  13. package/dist/layout/itemBuilders.js.map +1 -1
  14. package/dist/layout/labelsRender.js.map +1 -1
  15. package/dist/layout/legendConstants.js.map +1 -1
  16. package/dist/layout/legendRender.js.map +1 -1
  17. package/dist/layout/legendRows.js.map +1 -1
  18. package/dist/layout/legendUtils.js.map +1 -1
  19. package/dist/layout/metadata.js.map +1 -1
  20. package/dist/layout/model.js.map +1 -1
  21. package/dist/layout/options.js.map +1 -1
  22. package/dist/layout/presets.js.map +1 -1
  23. package/dist/layout/qrRender.js.map +1 -1
  24. package/dist/layout/renderDrawing.js.map +1 -1
  25. package/dist/layout/renderUtils.js.map +1 -1
  26. package/dist/layout/sectionValidation.js.map +1 -1
  27. package/dist/layout/templateVariables.js.map +1 -1
  28. package/dist/layout/typeGuards.js.map +1 -1
  29. package/dist/layout/types.js.map +1 -1
  30. package/dist/layout/utils.js.map +1 -1
  31. package/dist/layout/validation.js.map +1 -1
  32. package/dist/layout/validationHelpers.js.map +1 -1
  33. package/dist/layout/validationUtils.js.map +1 -1
  34. package/dist/layout/viewportPrep.js.map +1 -1
  35. package/dist/layout/viewportRender.js.map +1 -1
  36. package/dist/layout/viewportUtils.js.map +1 -1
  37. package/dist/layout/warnings.js.map +1 -1
  38. package/dist/printToPdf.js.map +1 -1
  39. package/dist/printToSvg.js.map +1 -1
  40. package/dist/sections.js.map +1 -1
  41. package/dist/types.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/BuildInfo.ts +41 -41
  44. package/src/index.ts +10 -10
  45. package/src/layout/analyzeTemplate.ts +218 -218
  46. package/src/layout/clipUtils.ts +193 -193
  47. package/src/layout/colorConstants.ts +16 -16
  48. package/src/layout/elementKinds.ts +35 -35
  49. package/src/layout/exportDrawing.ts +206 -206
  50. package/src/layout/filters.ts +80 -80
  51. package/src/layout/geometryConstants.ts +11 -11
  52. package/src/layout/index.ts +671 -671
  53. package/src/layout/itemBuilders.ts +159 -159
  54. package/src/layout/labelsRender.ts +170 -170
  55. package/src/layout/legendConstants.ts +11 -11
  56. package/src/layout/legendRender.ts +543 -543
  57. package/src/layout/legendRows.ts +62 -62
  58. package/src/layout/legendUtils.ts +144 -144
  59. package/src/layout/metadata.ts +210 -210
  60. package/src/layout/model.ts +372 -372
  61. package/src/layout/options.ts +17 -17
  62. package/src/layout/presets.ts +51 -51
  63. package/src/layout/qrRender.ts +126 -126
  64. package/src/layout/qrcode.d.ts +2 -2
  65. package/src/layout/renderDrawing.ts +710 -710
  66. package/src/layout/renderUtils.ts +138 -138
  67. package/src/layout/sectionValidation.ts +2 -2
  68. package/src/layout/templateVariables.ts +317 -317
  69. package/src/layout/typeGuards.ts +9 -9
  70. package/src/layout/types.ts +835 -835
  71. package/src/layout/utils.ts +85 -85
  72. package/src/layout/validation.ts +392 -392
  73. package/src/layout/validationHelpers.ts +59 -59
  74. package/src/layout/validationUtils.ts +6 -6
  75. package/src/layout/viewportPrep.ts +351 -351
  76. package/src/layout/viewportRender.ts +442 -442
  77. package/src/layout/viewportUtils.ts +50 -50
  78. package/src/layout/warnings.ts +3 -3
  79. package/src/printToPdf.ts +108 -108
  80. package/src/printToSvg.ts +188 -188
  81. package/src/sections.ts +1019 -1019
  82. package/src/types.ts +49 -49
@@ -1,210 +1,210 @@
1
- import { getPathValue as getValueByPath } from './renderUtils';
2
- import type { LayoutTemplate, ResolvedIncludeFilter, WhereCondition } from './types';
3
-
4
- export interface ModelMetadataEntry {
5
- productId?: string;
6
- ifcClass?: string;
7
- ifcClassId?: string;
8
- properties?: unknown;
9
- [key: string]: unknown;
10
- }
11
-
12
- export type ModelMetadata = Record<string, ModelMetadataEntry>;
13
-
14
- import { isRecord, getProp } from './typeGuards';
15
- import { normalizeClass } from './filters';
16
-
17
- /** Resolve the IFC class name from a BIM product object's `.class` property. */
18
- export const resolveIfcClassName = (product: unknown): string | null => {
19
- const classObj = getProp(product, 'class');
20
- if (!classObj) return null;
21
- return normalizeClass(getProp(classObj, 'name') ?? getProp(classObj, 'type') ?? getProp(classObj, 'id'));
22
- };
23
-
24
- /** Resolve the predefined IFC class ID (e.g. "USERDEFINED") from `.class.id`. */
25
- export const resolveIfcClassId = (product: unknown): string | null => {
26
- const classObj = getProp(product, 'class');
27
- if (!classObj) return null;
28
- const id = getProp(classObj, 'id');
29
- return typeof id === 'string' ? id : null;
30
- };
31
-
32
- export const normalizePropertySets = (
33
- product: unknown
34
- ): Record<string, Record<string, { value: unknown; unit?: string; type?: string }>> => {
35
- const properties = getProp(product, 'properties');
36
- // BIM products may have properties at various paths:
37
- // - product.properties.data (Twinfinity standard)
38
- // - product.properties.propertySets (BIM API)
39
- // - product.propertySets (direct)
40
- // - product.properties (fallback)
41
- // New T8 API: product.propertySets → Record<string, T8PropertySet>
42
- // where T8PropertySet.properties → Record<string, T8Property { value, type, unit }>
43
- // Legacy: product.properties.data / product.properties.sets → Record<string, Record<string, unknown>>
44
- const raw =
45
- getProp(product, 'propertySets') ??
46
- getProp(properties, 'data') ??
47
- getProp(properties, 'sets') ??
48
- properties ??
49
- {};
50
- const propertySets: Record<string, Record<string, { value: unknown; unit?: string; type?: string }>> = {};
51
- if (!isRecord(raw)) return propertySets;
52
- Object.entries(raw).forEach(([setName, setValue]) => {
53
- if (!isRecord(setValue)) return;
54
- // T8PropertySet has a .properties sub-record with T8Property entries
55
- const innerProps = getProp(setValue, 'properties');
56
- const source = isRecord(innerProps) ? innerProps : setValue;
57
- const props: Record<string, { value: unknown; unit?: string; type?: string }> = {};
58
- Object.entries(source).forEach(([propName, propVal]) => {
59
- if (isRecord(propVal) && 'value' in propVal) {
60
- props[propName] = propVal as { value: unknown; unit?: string; type?: string };
61
- } else {
62
- props[propName] = { value: propVal };
63
- }
64
- });
65
- propertySets[setName] = props;
66
- });
67
- return propertySets;
68
- };
69
-
70
- export const buildMetadataMap = (entries: unknown[]): ModelMetadata => {
71
- const out: ModelMetadata = {};
72
- if (!Array.isArray(entries)) return out;
73
- entries.forEach((entry) => {
74
- const product = getProp(entry, 'product') ?? entry;
75
- const gid = getProp(product, 'gid') ?? getProp(product, 'id') ?? null;
76
- if (!gid) return;
77
- const propertySets = normalizePropertySets(product);
78
- const ifcClass = resolveIfcClassName(product) ?? undefined;
79
- const ifcClassId = resolveIfcClassId(product) ?? undefined;
80
- out[String(gid)] = {
81
- productId: String(gid),
82
- ifcClass,
83
- ifcClassId,
84
- properties: propertySets,
85
- propertySets
86
- };
87
- });
88
- return out;
89
- };
90
-
91
- export const resolveMeta = (meta: unknown, metadataById?: ModelMetadata): unknown => {
92
- const productId = getProp(meta, 'productId') ?? getProp(meta, 'gid') ?? getProp(meta, 'id');
93
- const base = productId && metadataById ? metadataById[String(productId)] : undefined;
94
- if (!base) {
95
- return meta;
96
- }
97
- const baseProps = getProp(base, 'properties');
98
- const metaProps = getProp(meta, 'properties');
99
- const mergedProps =
100
- baseProps || metaProps
101
- ? { ...(isRecord(baseProps) ? baseProps : {}), ...(isRecord(metaProps) ? metaProps : {}) }
102
- : undefined;
103
- return mergedProps
104
- ? { ...base, ...(isRecord(meta) ? meta : {}), productId, properties: mergedProps }
105
- : { ...base, ...(isRecord(meta) ? meta : {}), productId };
106
- };
107
-
108
- /**
109
- * Resolve includeClasses config to an array of filters.
110
- *
111
- * Supports:
112
- * - String arrays: ["space", "walls"]
113
- * - Filter objects: [{ class: "space", where: { "BIP.spacetype": "ROOM" } }]
114
- * - Preset references: { preset: "defaultBuilding" }
115
- * - Mixed arrays: ["walls", { class: "space", where: {...} }]
116
- *
117
- * @returns Array of filters (strings or class+where objects), or null if no filters
118
- */
119
- export const resolveIncludeClasses = (
120
- includeClasses: unknown,
121
- currentIncludePresets: Record<string, string[]>
122
- ): ResolvedIncludeFilter[] | null => {
123
- if (!includeClasses) return null;
124
-
125
- // Handle array of filters (strings or objects)
126
- if (Array.isArray(includeClasses)) {
127
- const result: ResolvedIncludeFilter[] = [];
128
- for (const item of includeClasses) {
129
- if (typeof item === 'string' && item.length > 0) {
130
- result.push(item);
131
- } else if (isRecord(item)) {
132
- const cls = getProp(item, 'class');
133
- const where = getProp(item, 'where');
134
- // Must have either class or where (or both)
135
- if (cls !== undefined || (where && isRecord(where))) {
136
- result.push({ class: cls as string | string[] | undefined, where: where as WhereCondition });
137
- }
138
- }
139
- }
140
- return result.length > 0 ? result : null;
141
- }
142
-
143
- // Handle preset reference or filter object
144
- if (isRecord(includeClasses)) {
145
- const preset = getProp(includeClasses, 'preset');
146
- const cls = getProp(includeClasses, 'class');
147
- const where = getProp(includeClasses, 'where');
148
-
149
- // Preset reference: { preset: "name" }
150
- if (typeof preset === 'string') {
151
- const presetName = preset;
152
- const base = currentIncludePresets[presetName] ?? [];
153
- const addProp = getProp(includeClasses, 'add');
154
- const removeProp = getProp(includeClasses, 'remove');
155
- const add = Array.isArray(addProp) ? addProp : [];
156
- const remove = Array.isArray(removeProp) ? removeProp : [];
157
- const set = new Set<string>();
158
- base.forEach((c: string) => set.add(c));
159
- add.forEach((c: unknown) => typeof c === 'string' && set.add(c));
160
- remove.forEach((c: unknown) => typeof c === 'string' && set.delete(c));
161
- const strings = Array.from(set).filter((c) => typeof c === 'string' && c.length > 0);
162
- return strings.length > 0 ? strings : null;
163
- }
164
-
165
- // Filter object: { class: "space", where: {...} }
166
- if (cls !== undefined || (where && isRecord(where))) {
167
- return [{ class: cls as string | string[] | undefined, where: where as WhereCondition }];
168
- }
169
- }
170
-
171
- return null;
172
- };
173
-
174
- /**
175
- * Resolve allowed class names from template/viewport includeClasses config.
176
- *
177
- * Extracts only string filters (class names), ignoring filter objects with where conditions.
178
- * Used for backward compatibility and simple class-based filtering.
179
- *
180
- * @returns Set of normalized class names, or null if no filters
181
- */
182
- export const resolveAllowedClasses = (layoutTemplate: LayoutTemplate, viewportId = 'main'): Set<string> | null => {
183
- if (!layoutTemplate) return null;
184
- const presets = layoutTemplate.presets?.includeClasses ?? {};
185
- const templateClasses = resolveIncludeClasses(getProp(layoutTemplate, 'includeClasses'), presets);
186
- const elements = layoutTemplate.elements;
187
- const viewportEl = Array.isArray(elements)
188
- ? elements.find((el) => isRecord(el) && getProp(el, 'kind') === 'viewport' && getProp(el, 'id') === viewportId)
189
- : undefined;
190
- const viewportClasses = resolveIncludeClasses(getProp(viewportEl, 'includeClasses'), presets);
191
- const resolved = viewportClasses ?? templateClasses;
192
- if (!resolved || !resolved.length) {
193
- return null;
194
- }
195
- // Extract only string filters (class names)
196
- const classNames = new Set<string>();
197
- for (const filter of resolved) {
198
- if (typeof filter === 'string') {
199
- classNames.add(filter);
200
- } else if (isRecord(filter) && filter.class) {
201
- const classes = Array.isArray(filter.class) ? filter.class : [filter.class];
202
- for (const c of classes) {
203
- if (typeof c === 'string') classNames.add(c);
204
- }
205
- }
206
- }
207
- return classNames.size > 0 ? classNames : null;
208
- };
209
-
210
- export const getPathValue = (obj: unknown, path: string): unknown => getValueByPath(obj, path);
1
+ import { getPathValue as getValueByPath } from './renderUtils';
2
+ import type { LayoutTemplate, ResolvedIncludeFilter, WhereCondition } from './types';
3
+
4
+ export interface ModelMetadataEntry {
5
+ productId?: string;
6
+ ifcClass?: string;
7
+ ifcClassId?: string;
8
+ properties?: unknown;
9
+ [key: string]: unknown;
10
+ }
11
+
12
+ export type ModelMetadata = Record<string, ModelMetadataEntry>;
13
+
14
+ import { isRecord, getProp } from './typeGuards';
15
+ import { normalizeClass } from './filters';
16
+
17
+ /** Resolve the IFC class name from a BIM product object's `.class` property. */
18
+ export const resolveIfcClassName = (product: unknown): string | null => {
19
+ const classObj = getProp(product, 'class');
20
+ if (!classObj) return null;
21
+ return normalizeClass(getProp(classObj, 'name') ?? getProp(classObj, 'type') ?? getProp(classObj, 'id'));
22
+ };
23
+
24
+ /** Resolve the predefined IFC class ID (e.g. "USERDEFINED") from `.class.id`. */
25
+ export const resolveIfcClassId = (product: unknown): string | null => {
26
+ const classObj = getProp(product, 'class');
27
+ if (!classObj) return null;
28
+ const id = getProp(classObj, 'id');
29
+ return typeof id === 'string' ? id : null;
30
+ };
31
+
32
+ export const normalizePropertySets = (
33
+ product: unknown
34
+ ): Record<string, Record<string, { value: unknown; unit?: string; type?: string }>> => {
35
+ const properties = getProp(product, 'properties');
36
+ // BIM products may have properties at various paths:
37
+ // - product.properties.data (Twinfinity standard)
38
+ // - product.properties.propertySets (BIM API)
39
+ // - product.propertySets (direct)
40
+ // - product.properties (fallback)
41
+ // New T8 API: product.propertySets → Record<string, T8PropertySet>
42
+ // where T8PropertySet.properties → Record<string, T8Property { value, type, unit }>
43
+ // Legacy: product.properties.data / product.properties.sets → Record<string, Record<string, unknown>>
44
+ const raw =
45
+ getProp(product, 'propertySets') ??
46
+ getProp(properties, 'data') ??
47
+ getProp(properties, 'sets') ??
48
+ properties ??
49
+ {};
50
+ const propertySets: Record<string, Record<string, { value: unknown; unit?: string; type?: string }>> = {};
51
+ if (!isRecord(raw)) return propertySets;
52
+ Object.entries(raw).forEach(([setName, setValue]) => {
53
+ if (!isRecord(setValue)) return;
54
+ // T8PropertySet has a .properties sub-record with T8Property entries
55
+ const innerProps = getProp(setValue, 'properties');
56
+ const source = isRecord(innerProps) ? innerProps : setValue;
57
+ const props: Record<string, { value: unknown; unit?: string; type?: string }> = {};
58
+ Object.entries(source).forEach(([propName, propVal]) => {
59
+ if (isRecord(propVal) && 'value' in propVal) {
60
+ props[propName] = propVal as { value: unknown; unit?: string; type?: string };
61
+ } else {
62
+ props[propName] = { value: propVal };
63
+ }
64
+ });
65
+ propertySets[setName] = props;
66
+ });
67
+ return propertySets;
68
+ };
69
+
70
+ export const buildMetadataMap = (entries: unknown[]): ModelMetadata => {
71
+ const out: ModelMetadata = {};
72
+ if (!Array.isArray(entries)) return out;
73
+ entries.forEach((entry) => {
74
+ const product = getProp(entry, 'product') ?? entry;
75
+ const gid = getProp(product, 'gid') ?? getProp(product, 'id') ?? null;
76
+ if (!gid) return;
77
+ const propertySets = normalizePropertySets(product);
78
+ const ifcClass = resolveIfcClassName(product) ?? undefined;
79
+ const ifcClassId = resolveIfcClassId(product) ?? undefined;
80
+ out[String(gid)] = {
81
+ productId: String(gid),
82
+ ifcClass,
83
+ ifcClassId,
84
+ properties: propertySets,
85
+ propertySets
86
+ };
87
+ });
88
+ return out;
89
+ };
90
+
91
+ export const resolveMeta = (meta: unknown, metadataById?: ModelMetadata): unknown => {
92
+ const productId = getProp(meta, 'productId') ?? getProp(meta, 'gid') ?? getProp(meta, 'id');
93
+ const base = productId && metadataById ? metadataById[String(productId)] : undefined;
94
+ if (!base) {
95
+ return meta;
96
+ }
97
+ const baseProps = getProp(base, 'properties');
98
+ const metaProps = getProp(meta, 'properties');
99
+ const mergedProps =
100
+ baseProps || metaProps
101
+ ? { ...(isRecord(baseProps) ? baseProps : {}), ...(isRecord(metaProps) ? metaProps : {}) }
102
+ : undefined;
103
+ return mergedProps
104
+ ? { ...base, ...(isRecord(meta) ? meta : {}), productId, properties: mergedProps }
105
+ : { ...base, ...(isRecord(meta) ? meta : {}), productId };
106
+ };
107
+
108
+ /**
109
+ * Resolve includeClasses config to an array of filters.
110
+ *
111
+ * Supports:
112
+ * - String arrays: ["space", "walls"]
113
+ * - Filter objects: [{ class: "space", where: { "BIP.spacetype": "ROOM" } }]
114
+ * - Preset references: { preset: "defaultBuilding" }
115
+ * - Mixed arrays: ["walls", { class: "space", where: {...} }]
116
+ *
117
+ * @returns Array of filters (strings or class+where objects), or null if no filters
118
+ */
119
+ export const resolveIncludeClasses = (
120
+ includeClasses: unknown,
121
+ currentIncludePresets: Record<string, string[]>
122
+ ): ResolvedIncludeFilter[] | null => {
123
+ if (!includeClasses) return null;
124
+
125
+ // Handle array of filters (strings or objects)
126
+ if (Array.isArray(includeClasses)) {
127
+ const result: ResolvedIncludeFilter[] = [];
128
+ for (const item of includeClasses) {
129
+ if (typeof item === 'string' && item.length > 0) {
130
+ result.push(item);
131
+ } else if (isRecord(item)) {
132
+ const cls = getProp(item, 'class');
133
+ const where = getProp(item, 'where');
134
+ // Must have either class or where (or both)
135
+ if (cls !== undefined || (where && isRecord(where))) {
136
+ result.push({ class: cls as string | string[] | undefined, where: where as WhereCondition });
137
+ }
138
+ }
139
+ }
140
+ return result.length > 0 ? result : null;
141
+ }
142
+
143
+ // Handle preset reference or filter object
144
+ if (isRecord(includeClasses)) {
145
+ const preset = getProp(includeClasses, 'preset');
146
+ const cls = getProp(includeClasses, 'class');
147
+ const where = getProp(includeClasses, 'where');
148
+
149
+ // Preset reference: { preset: "name" }
150
+ if (typeof preset === 'string') {
151
+ const presetName = preset;
152
+ const base = currentIncludePresets[presetName] ?? [];
153
+ const addProp = getProp(includeClasses, 'add');
154
+ const removeProp = getProp(includeClasses, 'remove');
155
+ const add = Array.isArray(addProp) ? addProp : [];
156
+ const remove = Array.isArray(removeProp) ? removeProp : [];
157
+ const set = new Set<string>();
158
+ base.forEach((c: string) => set.add(c));
159
+ add.forEach((c: unknown) => typeof c === 'string' && set.add(c));
160
+ remove.forEach((c: unknown) => typeof c === 'string' && set.delete(c));
161
+ const strings = Array.from(set).filter((c) => typeof c === 'string' && c.length > 0);
162
+ return strings.length > 0 ? strings : null;
163
+ }
164
+
165
+ // Filter object: { class: "space", where: {...} }
166
+ if (cls !== undefined || (where && isRecord(where))) {
167
+ return [{ class: cls as string | string[] | undefined, where: where as WhereCondition }];
168
+ }
169
+ }
170
+
171
+ return null;
172
+ };
173
+
174
+ /**
175
+ * Resolve allowed class names from template/viewport includeClasses config.
176
+ *
177
+ * Extracts only string filters (class names), ignoring filter objects with where conditions.
178
+ * Used for backward compatibility and simple class-based filtering.
179
+ *
180
+ * @returns Set of normalized class names, or null if no filters
181
+ */
182
+ export const resolveAllowedClasses = (layoutTemplate: LayoutTemplate, viewportId = 'main'): Set<string> | null => {
183
+ if (!layoutTemplate) return null;
184
+ const presets = layoutTemplate.presets?.includeClasses ?? {};
185
+ const templateClasses = resolveIncludeClasses(getProp(layoutTemplate, 'includeClasses'), presets);
186
+ const elements = layoutTemplate.elements;
187
+ const viewportEl = Array.isArray(elements)
188
+ ? elements.find((el) => isRecord(el) && getProp(el, 'kind') === 'viewport' && getProp(el, 'id') === viewportId)
189
+ : undefined;
190
+ const viewportClasses = resolveIncludeClasses(getProp(viewportEl, 'includeClasses'), presets);
191
+ const resolved = viewportClasses ?? templateClasses;
192
+ if (!resolved || !resolved.length) {
193
+ return null;
194
+ }
195
+ // Extract only string filters (class names)
196
+ const classNames = new Set<string>();
197
+ for (const filter of resolved) {
198
+ if (typeof filter === 'string') {
199
+ classNames.add(filter);
200
+ } else if (isRecord(filter) && filter.class) {
201
+ const classes = Array.isArray(filter.class) ? filter.class : [filter.class];
202
+ for (const c of classes) {
203
+ if (typeof c === 'string') classNames.add(c);
204
+ }
205
+ }
206
+ }
207
+ return classNames.size > 0 ? classNames : null;
208
+ };
209
+
210
+ export const getPathValue = (obj: unknown, path: string): unknown => getValueByPath(obj, path);