@twinfinity/printing 5.0.3-ci.28538-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.
- package/README.md +208 -0
- package/dist/BuildInfo.d.ts +25 -0
- package/dist/BuildInfo.d.ts.map +1 -0
- package/dist/BuildInfo.js +15 -0
- package/dist/BuildInfo.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/analyzeTemplate.d.ts +29 -0
- package/dist/layout/analyzeTemplate.d.ts.map +1 -0
- package/dist/layout/analyzeTemplate.js +168 -0
- package/dist/layout/analyzeTemplate.js.map +1 -0
- package/dist/layout/clipUtils.d.ts +18 -0
- package/dist/layout/clipUtils.d.ts.map +1 -0
- package/dist/layout/clipUtils.js +165 -0
- package/dist/layout/clipUtils.js.map +1 -0
- package/dist/layout/colorConstants.d.ts +11 -0
- package/dist/layout/colorConstants.d.ts.map +1 -0
- package/dist/layout/colorConstants.js +14 -0
- package/dist/layout/colorConstants.js.map +1 -0
- package/dist/layout/elementKinds.d.ts +21 -0
- package/dist/layout/elementKinds.d.ts.map +1 -0
- package/dist/layout/elementKinds.js +17 -0
- package/dist/layout/elementKinds.js.map +1 -0
- package/dist/layout/exportDrawing.d.ts +143 -0
- package/dist/layout/exportDrawing.d.ts.map +1 -0
- package/dist/layout/exportDrawing.js +146 -0
- package/dist/layout/exportDrawing.js.map +1 -0
- package/dist/layout/filters.d.ts +33 -0
- package/dist/layout/filters.d.ts.map +1 -0
- package/dist/layout/filters.js +77 -0
- package/dist/layout/filters.js.map +1 -0
- package/dist/layout/geometryConstants.d.ts +8 -0
- package/dist/layout/geometryConstants.d.ts.map +1 -0
- package/dist/layout/geometryConstants.js +10 -0
- package/dist/layout/geometryConstants.js.map +1 -0
- package/dist/layout/index.d.ts +86 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +363 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/itemBuilders.d.ts +29 -0
- package/dist/layout/itemBuilders.d.ts.map +1 -0
- package/dist/layout/itemBuilders.js +135 -0
- package/dist/layout/itemBuilders.js.map +1 -0
- package/dist/layout/labelsRender.d.ts +29 -0
- package/dist/layout/labelsRender.d.ts.map +1 -0
- package/dist/layout/labelsRender.js +109 -0
- package/dist/layout/labelsRender.js.map +1 -0
- package/dist/layout/legendConstants.d.ts +12 -0
- package/dist/layout/legendConstants.d.ts.map +1 -0
- package/dist/layout/legendConstants.js +12 -0
- package/dist/layout/legendConstants.js.map +1 -0
- package/dist/layout/legendRender.d.ts +13 -0
- package/dist/layout/legendRender.d.ts.map +1 -0
- package/dist/layout/legendRender.js +424 -0
- package/dist/layout/legendRender.js.map +1 -0
- package/dist/layout/legendRows.d.ts +26 -0
- package/dist/layout/legendRows.d.ts.map +1 -0
- package/dist/layout/legendRows.js +45 -0
- package/dist/layout/legendRows.js.map +1 -0
- package/dist/layout/legendUtils.d.ts +21 -0
- package/dist/layout/legendUtils.d.ts.map +1 -0
- package/dist/layout/legendUtils.js +110 -0
- package/dist/layout/legendUtils.js.map +1 -0
- package/dist/layout/metadata.d.ts +43 -0
- package/dist/layout/metadata.d.ts.map +1 -0
- package/dist/layout/metadata.js +191 -0
- package/dist/layout/metadata.js.map +1 -0
- package/dist/layout/model.d.ts +15 -0
- package/dist/layout/model.d.ts.map +1 -0
- package/dist/layout/model.js +310 -0
- package/dist/layout/model.js.map +1 -0
- package/dist/layout/options.d.ts +17 -0
- package/dist/layout/options.d.ts.map +1 -0
- package/dist/layout/options.js +2 -0
- package/dist/layout/options.js.map +1 -0
- package/dist/layout/presets.d.ts +23 -0
- package/dist/layout/presets.d.ts.map +1 -0
- package/dist/layout/presets.js +41 -0
- package/dist/layout/presets.js.map +1 -0
- package/dist/layout/qrRender.d.ts +13 -0
- package/dist/layout/qrRender.d.ts.map +1 -0
- package/dist/layout/qrRender.js +97 -0
- package/dist/layout/qrRender.js.map +1 -0
- package/dist/layout/renderDrawing.d.ts +62 -0
- package/dist/layout/renderDrawing.d.ts.map +1 -0
- package/dist/layout/renderDrawing.js +555 -0
- package/dist/layout/renderDrawing.js.map +1 -0
- package/dist/layout/renderUtils.d.ts +36 -0
- package/dist/layout/renderUtils.d.ts.map +1 -0
- package/dist/layout/renderUtils.js +117 -0
- package/dist/layout/renderUtils.js.map +1 -0
- package/dist/layout/sectionValidation.d.ts +3 -0
- package/dist/layout/sectionValidation.d.ts.map +1 -0
- package/dist/layout/sectionValidation.js +2 -0
- package/dist/layout/sectionValidation.js.map +1 -0
- package/dist/layout/templateVariables.d.ts +137 -0
- package/dist/layout/templateVariables.d.ts.map +1 -0
- package/dist/layout/templateVariables.js +295 -0
- package/dist/layout/templateVariables.js.map +1 -0
- package/dist/layout/typeGuards.d.ts +5 -0
- package/dist/layout/typeGuards.d.ts.map +1 -0
- package/dist/layout/typeGuards.js +9 -0
- package/dist/layout/typeGuards.js.map +1 -0
- package/dist/layout/types.d.ts +816 -0
- package/dist/layout/types.d.ts.map +1 -0
- package/dist/layout/types.js +2 -0
- package/dist/layout/types.js.map +1 -0
- package/dist/layout/utils.d.ts +9 -0
- package/dist/layout/utils.d.ts.map +1 -0
- package/dist/layout/utils.js +84 -0
- package/dist/layout/utils.js.map +1 -0
- package/dist/layout/validation.d.ts +7 -0
- package/dist/layout/validation.d.ts.map +1 -0
- package/dist/layout/validation.js +352 -0
- package/dist/layout/validation.js.map +1 -0
- package/dist/layout/validationHelpers.d.ts +15 -0
- package/dist/layout/validationHelpers.d.ts.map +1 -0
- package/dist/layout/validationHelpers.js +43 -0
- package/dist/layout/validationHelpers.js.map +1 -0
- package/dist/layout/validationUtils.d.ts +5 -0
- package/dist/layout/validationUtils.d.ts.map +1 -0
- package/dist/layout/validationUtils.js +5 -0
- package/dist/layout/validationUtils.js.map +1 -0
- package/dist/layout/viewportPrep.d.ts +47 -0
- package/dist/layout/viewportPrep.d.ts.map +1 -0
- package/dist/layout/viewportPrep.js +275 -0
- package/dist/layout/viewportPrep.js.map +1 -0
- package/dist/layout/viewportRender.d.ts +42 -0
- package/dist/layout/viewportRender.d.ts.map +1 -0
- package/dist/layout/viewportRender.js +337 -0
- package/dist/layout/viewportRender.js.map +1 -0
- package/dist/layout/viewportUtils.d.ts +9 -0
- package/dist/layout/viewportUtils.d.ts.map +1 -0
- package/dist/layout/viewportUtils.js +40 -0
- package/dist/layout/viewportUtils.js.map +1 -0
- package/dist/layout/warnings.d.ts +2 -0
- package/dist/layout/warnings.d.ts.map +1 -0
- package/dist/layout/warnings.js +4 -0
- package/dist/layout/warnings.js.map +1 -0
- package/dist/printToPdf.d.ts +38 -0
- package/dist/printToPdf.d.ts.map +1 -0
- package/dist/printToPdf.js +79 -0
- package/dist/printToPdf.js.map +1 -0
- package/dist/printToSvg.d.ts +11 -0
- package/dist/printToSvg.d.ts.map +1 -0
- package/dist/printToSvg.js +168 -0
- package/dist/printToSvg.js.map +1 -0
- package/dist/sections.d.ts +118 -0
- package/dist/sections.d.ts.map +1 -0
- package/dist/sections.js +839 -0
- package/dist/sections.js.map +1 -0
- package/dist/templates/default-template.json +137 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
- package/src/BuildInfo.ts +41 -0
- package/src/index.ts +10 -0
- package/src/layout/analyzeTemplate.ts +218 -0
- package/src/layout/clipUtils.ts +193 -0
- package/src/layout/colorConstants.ts +16 -0
- package/src/layout/elementKinds.ts +35 -0
- package/src/layout/exportDrawing.ts +206 -0
- package/src/layout/filters.ts +80 -0
- package/src/layout/geometryConstants.ts +11 -0
- package/src/layout/index.ts +671 -0
- package/src/layout/itemBuilders.ts +159 -0
- package/src/layout/labelsRender.ts +170 -0
- package/src/layout/legendConstants.ts +11 -0
- package/src/layout/legendRender.ts +543 -0
- package/src/layout/legendRows.ts +62 -0
- package/src/layout/legendUtils.ts +144 -0
- package/src/layout/metadata.ts +210 -0
- package/src/layout/model.ts +372 -0
- package/src/layout/options.ts +17 -0
- package/src/layout/presets.ts +51 -0
- package/src/layout/qrRender.ts +126 -0
- package/src/layout/qrcode.d.ts +2 -0
- package/src/layout/renderDrawing.ts +710 -0
- package/src/layout/renderUtils.ts +138 -0
- package/src/layout/sectionValidation.ts +2 -0
- package/src/layout/templateVariables.ts +317 -0
- package/src/layout/typeGuards.ts +9 -0
- package/src/layout/types.ts +835 -0
- package/src/layout/utils.ts +85 -0
- package/src/layout/validation.ts +392 -0
- package/src/layout/validationHelpers.ts +59 -0
- package/src/layout/validationUtils.ts +6 -0
- package/src/layout/viewportPrep.ts +351 -0
- package/src/layout/viewportRender.ts +442 -0
- package/src/layout/viewportUtils.ts +50 -0
- package/src/layout/warnings.ts +3 -0
- package/src/printToPdf.ts +108 -0
- package/src/printToSvg.ts +188 -0
- package/src/sections.ts +1019 -0
- package/src/templates/default-template.json +137 -0
- package/src/types.ts +49 -0
- package/templates/default-a0-landscape.json +209 -0
- package/templates/default-a0-portrait.json +195 -0
- package/templates/default-a1-landscape.json +167 -0
- package/templates/default-a1-portrait.json +153 -0
- package/templates/default-a3-landscape.json +111 -0
- package/templates/default-a3-portrait.json +125 -0
- package/templates/default-a4-landscape.json +97 -0
- package/templates/default-a4-portrait.json +97 -0
- package/templates/template-schema.json +1395 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LEGEND_TEXT_WIDTH_FACTOR,
|
|
3
|
+
LEGEND_MIN_CONTENT_WIDTH_EM,
|
|
4
|
+
LEGEND_TEXT_Y_OFFSET_FACTOR,
|
|
5
|
+
PX_PER_MM
|
|
6
|
+
} from './legendConstants';
|
|
7
|
+
// v2 format: { digits?: number; prefix?: string; suffix?: string } or undefined
|
|
8
|
+
type LegendFormat = { digits?: number; prefix?: string; suffix?: string } | string | undefined;
|
|
9
|
+
import {
|
|
10
|
+
RGB_MAX,
|
|
11
|
+
RED_SHIFT,
|
|
12
|
+
GREEN_SHIFT,
|
|
13
|
+
HASH_COLOR_MODULO,
|
|
14
|
+
HASH_GREEN_SHIFT,
|
|
15
|
+
HASH_BLUE_SHIFT,
|
|
16
|
+
RGB_MIN
|
|
17
|
+
} from './colorConstants';
|
|
18
|
+
|
|
19
|
+
import { isRecord, getProp } from './typeGuards';
|
|
20
|
+
|
|
21
|
+
export function parseLegendColor(value: unknown, fallbackKey: string): [number, number, number, number] {
|
|
22
|
+
if (Array.isArray(value) && (value.length === 3 || value.length === 4)) {
|
|
23
|
+
const [r, g, b, a = RGB_MAX] = value.map((v) => Number(v) || 0);
|
|
24
|
+
return [clampColor(r), clampColor(g), clampColor(b), clampColor(a)];
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === 'string') {
|
|
27
|
+
const hex = value.trim();
|
|
28
|
+
const match = /^#?([a-fA-F0-9]{6})([a-fA-F0-9]{2})?$/.exec(hex);
|
|
29
|
+
if (match) {
|
|
30
|
+
const intVal = parseInt(match[1], 16);
|
|
31
|
+
const aHex = match[2];
|
|
32
|
+
return [
|
|
33
|
+
(intVal >> RED_SHIFT) & 0xff,
|
|
34
|
+
(intVal >> GREEN_SHIFT) & 0xff,
|
|
35
|
+
intVal & 0xff,
|
|
36
|
+
aHex ? parseInt(aHex, 16) : RGB_MAX
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const hash = Math.abs(hashCode(fallbackKey || ''));
|
|
41
|
+
return [
|
|
42
|
+
hash % HASH_COLOR_MODULO,
|
|
43
|
+
(hash >> HASH_GREEN_SHIFT) % HASH_COLOR_MODULO,
|
|
44
|
+
(hash >> HASH_BLUE_SHIFT) % HASH_COLOR_MODULO,
|
|
45
|
+
RGB_MAX
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function formatLegendValue(value: unknown, fmt?: LegendFormat): string {
|
|
50
|
+
if (fmt === undefined || fmt === null || fmt === 'string') {
|
|
51
|
+
return value === undefined || value === null ? '' : String(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof fmt === 'string') {
|
|
55
|
+
const fixedMatch = /^fixed\((\d+)(?:,\s*([^)]*))?\)$/i.exec(fmt);
|
|
56
|
+
if (fixedMatch) {
|
|
57
|
+
const digits = parseInt(fixedMatch[1], 10);
|
|
58
|
+
const suffix = fixedMatch[2] || '';
|
|
59
|
+
const num = Number(value);
|
|
60
|
+
if (Number.isFinite(num)) {
|
|
61
|
+
return `${num.toFixed(digits)}${suffix ? ` ${suffix.trim()}` : ''}`.trim();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return String(value ?? '');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isRecord(fmt)) {
|
|
68
|
+
const digits = getProp(fmt, 'digits');
|
|
69
|
+
const prefix = getProp(fmt, 'prefix');
|
|
70
|
+
const suffix = getProp(fmt, 'suffix');
|
|
71
|
+
const num = Number(value);
|
|
72
|
+
if (Number.isFinite(num) && typeof digits === 'number') {
|
|
73
|
+
const prefixStr = typeof prefix === 'string' ? prefix : '';
|
|
74
|
+
const suffixStr = typeof suffix === 'string' ? suffix : '';
|
|
75
|
+
return `${prefixStr}${num.toFixed(digits)}${suffixStr}`;
|
|
76
|
+
}
|
|
77
|
+
return String(value ?? '');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return String(value ?? '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function computeLegendColumnWidths(
|
|
84
|
+
columnLabels: { label: string; minWidthMm?: number; maxWidthMm?: number }[],
|
|
85
|
+
rows: { values: string[] }[],
|
|
86
|
+
fontSizeMm: number,
|
|
87
|
+
cellPaddingMm: number,
|
|
88
|
+
swatchWidthMm: number,
|
|
89
|
+
fontFamily: string
|
|
90
|
+
): { colWidthsMm: number[]; columnCount: number } {
|
|
91
|
+
const columnCount = Math.min(6, Math.max(2, columnLabels.length + 1));
|
|
92
|
+
const colWidthsMm: number[] = new Array(columnCount).fill(0);
|
|
93
|
+
colWidthsMm[0] = swatchWidthMm;
|
|
94
|
+
const measureTextWidthMm = createLegendTextMeasurer(fontFamily, fontSizeMm);
|
|
95
|
+
|
|
96
|
+
for (let c = 1; c < columnCount; c++) {
|
|
97
|
+
const colIdx = c - 1;
|
|
98
|
+
const col = columnLabels[colIdx];
|
|
99
|
+
const minWidth = col.minWidthMm ?? fontSizeMm * LEGEND_MIN_CONTENT_WIDTH_EM;
|
|
100
|
+
const maxWidth = col.maxWidthMm ?? Number.POSITIVE_INFINITY;
|
|
101
|
+
let maxWidthMeasured = measureTextWidthMm(col.label ?? '');
|
|
102
|
+
rows.forEach((row) => {
|
|
103
|
+
const text = row.values[colIdx] ?? '';
|
|
104
|
+
maxWidthMeasured = Math.max(maxWidthMeasured, measureTextWidthMm(text));
|
|
105
|
+
});
|
|
106
|
+
const contentWidth = Math.max(minWidth, Math.min(maxWidth, maxWidthMeasured + cellPaddingMm * 2));
|
|
107
|
+
colWidthsMm[c] = contentWidth;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { colWidthsMm, columnCount };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function computeLegendTextYOffset(fontSizeMm: number): number {
|
|
114
|
+
return fontSizeMm * LEGEND_TEXT_Y_OFFSET_FACTOR;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const createLegendTextMeasurer = (fontFamily: string, fontSizeMm: number): ((text: string) => number) => {
|
|
118
|
+
if (typeof document !== 'undefined') {
|
|
119
|
+
const canvas = document.createElement('canvas');
|
|
120
|
+
canvas.width = 1024;
|
|
121
|
+
canvas.height = 64;
|
|
122
|
+
const canvasCtx = canvas.getContext('2d');
|
|
123
|
+
if (canvasCtx) {
|
|
124
|
+
canvasCtx.font = `${fontSizeMm * PX_PER_MM}px ${fontFamily}`;
|
|
125
|
+
const measureTextWidthMm = (text: string): number => {
|
|
126
|
+
const metrics = canvasCtx.measureText(text);
|
|
127
|
+
return metrics.width / PX_PER_MM;
|
|
128
|
+
};
|
|
129
|
+
return measureTextWidthMm;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return (text: string): number => text.length * fontSizeMm * LEGEND_TEXT_WIDTH_FACTOR;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const clampColor = (value: number): number => Math.max(RGB_MIN, Math.min(RGB_MAX, Math.round(value)));
|
|
136
|
+
|
|
137
|
+
const hashCode = (str: string): number => {
|
|
138
|
+
let hash = 0;
|
|
139
|
+
for (let i = 0; i < str.length; i++) {
|
|
140
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
141
|
+
hash |= 0;
|
|
142
|
+
}
|
|
143
|
+
return hash;
|
|
144
|
+
};
|
|
@@ -0,0 +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);
|