@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.
Files changed (209) hide show
  1. package/README.md +208 -0
  2. package/dist/BuildInfo.d.ts +25 -0
  3. package/dist/BuildInfo.d.ts.map +1 -0
  4. package/dist/BuildInfo.js +15 -0
  5. package/dist/BuildInfo.js.map +1 -0
  6. package/dist/index.d.ts +7 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +9 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/layout/analyzeTemplate.d.ts +29 -0
  11. package/dist/layout/analyzeTemplate.d.ts.map +1 -0
  12. package/dist/layout/analyzeTemplate.js +168 -0
  13. package/dist/layout/analyzeTemplate.js.map +1 -0
  14. package/dist/layout/clipUtils.d.ts +18 -0
  15. package/dist/layout/clipUtils.d.ts.map +1 -0
  16. package/dist/layout/clipUtils.js +165 -0
  17. package/dist/layout/clipUtils.js.map +1 -0
  18. package/dist/layout/colorConstants.d.ts +11 -0
  19. package/dist/layout/colorConstants.d.ts.map +1 -0
  20. package/dist/layout/colorConstants.js +14 -0
  21. package/dist/layout/colorConstants.js.map +1 -0
  22. package/dist/layout/elementKinds.d.ts +21 -0
  23. package/dist/layout/elementKinds.d.ts.map +1 -0
  24. package/dist/layout/elementKinds.js +17 -0
  25. package/dist/layout/elementKinds.js.map +1 -0
  26. package/dist/layout/exportDrawing.d.ts +143 -0
  27. package/dist/layout/exportDrawing.d.ts.map +1 -0
  28. package/dist/layout/exportDrawing.js +146 -0
  29. package/dist/layout/exportDrawing.js.map +1 -0
  30. package/dist/layout/filters.d.ts +33 -0
  31. package/dist/layout/filters.d.ts.map +1 -0
  32. package/dist/layout/filters.js +77 -0
  33. package/dist/layout/filters.js.map +1 -0
  34. package/dist/layout/geometryConstants.d.ts +8 -0
  35. package/dist/layout/geometryConstants.d.ts.map +1 -0
  36. package/dist/layout/geometryConstants.js +10 -0
  37. package/dist/layout/geometryConstants.js.map +1 -0
  38. package/dist/layout/index.d.ts +86 -0
  39. package/dist/layout/index.d.ts.map +1 -0
  40. package/dist/layout/index.js +363 -0
  41. package/dist/layout/index.js.map +1 -0
  42. package/dist/layout/itemBuilders.d.ts +29 -0
  43. package/dist/layout/itemBuilders.d.ts.map +1 -0
  44. package/dist/layout/itemBuilders.js +135 -0
  45. package/dist/layout/itemBuilders.js.map +1 -0
  46. package/dist/layout/labelsRender.d.ts +29 -0
  47. package/dist/layout/labelsRender.d.ts.map +1 -0
  48. package/dist/layout/labelsRender.js +109 -0
  49. package/dist/layout/labelsRender.js.map +1 -0
  50. package/dist/layout/legendConstants.d.ts +12 -0
  51. package/dist/layout/legendConstants.d.ts.map +1 -0
  52. package/dist/layout/legendConstants.js +12 -0
  53. package/dist/layout/legendConstants.js.map +1 -0
  54. package/dist/layout/legendRender.d.ts +13 -0
  55. package/dist/layout/legendRender.d.ts.map +1 -0
  56. package/dist/layout/legendRender.js +424 -0
  57. package/dist/layout/legendRender.js.map +1 -0
  58. package/dist/layout/legendRows.d.ts +26 -0
  59. package/dist/layout/legendRows.d.ts.map +1 -0
  60. package/dist/layout/legendRows.js +45 -0
  61. package/dist/layout/legendRows.js.map +1 -0
  62. package/dist/layout/legendUtils.d.ts +21 -0
  63. package/dist/layout/legendUtils.d.ts.map +1 -0
  64. package/dist/layout/legendUtils.js +110 -0
  65. package/dist/layout/legendUtils.js.map +1 -0
  66. package/dist/layout/metadata.d.ts +43 -0
  67. package/dist/layout/metadata.d.ts.map +1 -0
  68. package/dist/layout/metadata.js +191 -0
  69. package/dist/layout/metadata.js.map +1 -0
  70. package/dist/layout/model.d.ts +15 -0
  71. package/dist/layout/model.d.ts.map +1 -0
  72. package/dist/layout/model.js +310 -0
  73. package/dist/layout/model.js.map +1 -0
  74. package/dist/layout/options.d.ts +17 -0
  75. package/dist/layout/options.d.ts.map +1 -0
  76. package/dist/layout/options.js +2 -0
  77. package/dist/layout/options.js.map +1 -0
  78. package/dist/layout/presets.d.ts +23 -0
  79. package/dist/layout/presets.d.ts.map +1 -0
  80. package/dist/layout/presets.js +41 -0
  81. package/dist/layout/presets.js.map +1 -0
  82. package/dist/layout/qrRender.d.ts +13 -0
  83. package/dist/layout/qrRender.d.ts.map +1 -0
  84. package/dist/layout/qrRender.js +97 -0
  85. package/dist/layout/qrRender.js.map +1 -0
  86. package/dist/layout/renderDrawing.d.ts +62 -0
  87. package/dist/layout/renderDrawing.d.ts.map +1 -0
  88. package/dist/layout/renderDrawing.js +555 -0
  89. package/dist/layout/renderDrawing.js.map +1 -0
  90. package/dist/layout/renderUtils.d.ts +36 -0
  91. package/dist/layout/renderUtils.d.ts.map +1 -0
  92. package/dist/layout/renderUtils.js +117 -0
  93. package/dist/layout/renderUtils.js.map +1 -0
  94. package/dist/layout/sectionValidation.d.ts +3 -0
  95. package/dist/layout/sectionValidation.d.ts.map +1 -0
  96. package/dist/layout/sectionValidation.js +2 -0
  97. package/dist/layout/sectionValidation.js.map +1 -0
  98. package/dist/layout/templateVariables.d.ts +137 -0
  99. package/dist/layout/templateVariables.d.ts.map +1 -0
  100. package/dist/layout/templateVariables.js +295 -0
  101. package/dist/layout/templateVariables.js.map +1 -0
  102. package/dist/layout/typeGuards.d.ts +5 -0
  103. package/dist/layout/typeGuards.d.ts.map +1 -0
  104. package/dist/layout/typeGuards.js +9 -0
  105. package/dist/layout/typeGuards.js.map +1 -0
  106. package/dist/layout/types.d.ts +816 -0
  107. package/dist/layout/types.d.ts.map +1 -0
  108. package/dist/layout/types.js +2 -0
  109. package/dist/layout/types.js.map +1 -0
  110. package/dist/layout/utils.d.ts +9 -0
  111. package/dist/layout/utils.d.ts.map +1 -0
  112. package/dist/layout/utils.js +84 -0
  113. package/dist/layout/utils.js.map +1 -0
  114. package/dist/layout/validation.d.ts +7 -0
  115. package/dist/layout/validation.d.ts.map +1 -0
  116. package/dist/layout/validation.js +352 -0
  117. package/dist/layout/validation.js.map +1 -0
  118. package/dist/layout/validationHelpers.d.ts +15 -0
  119. package/dist/layout/validationHelpers.d.ts.map +1 -0
  120. package/dist/layout/validationHelpers.js +43 -0
  121. package/dist/layout/validationHelpers.js.map +1 -0
  122. package/dist/layout/validationUtils.d.ts +5 -0
  123. package/dist/layout/validationUtils.d.ts.map +1 -0
  124. package/dist/layout/validationUtils.js +5 -0
  125. package/dist/layout/validationUtils.js.map +1 -0
  126. package/dist/layout/viewportPrep.d.ts +47 -0
  127. package/dist/layout/viewportPrep.d.ts.map +1 -0
  128. package/dist/layout/viewportPrep.js +275 -0
  129. package/dist/layout/viewportPrep.js.map +1 -0
  130. package/dist/layout/viewportRender.d.ts +42 -0
  131. package/dist/layout/viewportRender.d.ts.map +1 -0
  132. package/dist/layout/viewportRender.js +337 -0
  133. package/dist/layout/viewportRender.js.map +1 -0
  134. package/dist/layout/viewportUtils.d.ts +9 -0
  135. package/dist/layout/viewportUtils.d.ts.map +1 -0
  136. package/dist/layout/viewportUtils.js +40 -0
  137. package/dist/layout/viewportUtils.js.map +1 -0
  138. package/dist/layout/warnings.d.ts +2 -0
  139. package/dist/layout/warnings.d.ts.map +1 -0
  140. package/dist/layout/warnings.js +4 -0
  141. package/dist/layout/warnings.js.map +1 -0
  142. package/dist/printToPdf.d.ts +38 -0
  143. package/dist/printToPdf.d.ts.map +1 -0
  144. package/dist/printToPdf.js +79 -0
  145. package/dist/printToPdf.js.map +1 -0
  146. package/dist/printToSvg.d.ts +11 -0
  147. package/dist/printToSvg.d.ts.map +1 -0
  148. package/dist/printToSvg.js +168 -0
  149. package/dist/printToSvg.js.map +1 -0
  150. package/dist/sections.d.ts +118 -0
  151. package/dist/sections.d.ts.map +1 -0
  152. package/dist/sections.js +839 -0
  153. package/dist/sections.js.map +1 -0
  154. package/dist/templates/default-template.json +137 -0
  155. package/dist/types.d.ts +54 -0
  156. package/dist/types.d.ts.map +1 -0
  157. package/dist/types.js +11 -0
  158. package/dist/types.js.map +1 -0
  159. package/package.json +47 -0
  160. package/src/BuildInfo.ts +41 -0
  161. package/src/index.ts +10 -0
  162. package/src/layout/analyzeTemplate.ts +218 -0
  163. package/src/layout/clipUtils.ts +193 -0
  164. package/src/layout/colorConstants.ts +16 -0
  165. package/src/layout/elementKinds.ts +35 -0
  166. package/src/layout/exportDrawing.ts +206 -0
  167. package/src/layout/filters.ts +80 -0
  168. package/src/layout/geometryConstants.ts +11 -0
  169. package/src/layout/index.ts +671 -0
  170. package/src/layout/itemBuilders.ts +159 -0
  171. package/src/layout/labelsRender.ts +170 -0
  172. package/src/layout/legendConstants.ts +11 -0
  173. package/src/layout/legendRender.ts +543 -0
  174. package/src/layout/legendRows.ts +62 -0
  175. package/src/layout/legendUtils.ts +144 -0
  176. package/src/layout/metadata.ts +210 -0
  177. package/src/layout/model.ts +372 -0
  178. package/src/layout/options.ts +17 -0
  179. package/src/layout/presets.ts +51 -0
  180. package/src/layout/qrRender.ts +126 -0
  181. package/src/layout/qrcode.d.ts +2 -0
  182. package/src/layout/renderDrawing.ts +710 -0
  183. package/src/layout/renderUtils.ts +138 -0
  184. package/src/layout/sectionValidation.ts +2 -0
  185. package/src/layout/templateVariables.ts +317 -0
  186. package/src/layout/typeGuards.ts +9 -0
  187. package/src/layout/types.ts +835 -0
  188. package/src/layout/utils.ts +85 -0
  189. package/src/layout/validation.ts +392 -0
  190. package/src/layout/validationHelpers.ts +59 -0
  191. package/src/layout/validationUtils.ts +6 -0
  192. package/src/layout/viewportPrep.ts +351 -0
  193. package/src/layout/viewportRender.ts +442 -0
  194. package/src/layout/viewportUtils.ts +50 -0
  195. package/src/layout/warnings.ts +3 -0
  196. package/src/printToPdf.ts +108 -0
  197. package/src/printToSvg.ts +188 -0
  198. package/src/sections.ts +1019 -0
  199. package/src/templates/default-template.json +137 -0
  200. package/src/types.ts +49 -0
  201. package/templates/default-a0-landscape.json +209 -0
  202. package/templates/default-a0-portrait.json +195 -0
  203. package/templates/default-a1-landscape.json +167 -0
  204. package/templates/default-a1-portrait.json +153 -0
  205. package/templates/default-a3-landscape.json +111 -0
  206. package/templates/default-a3-portrait.json +125 -0
  207. package/templates/default-a4-landscape.json +97 -0
  208. package/templates/default-a4-portrait.json +97 -0
  209. package/templates/template-schema.json +1395 -0
@@ -0,0 +1,77 @@
1
+ import { resolveProperty } from './renderUtils';
2
+ import { isRecord, getProp } from './typeGuards';
3
+ const normalizeClass = (cls) => (typeof cls === 'string' ? cls.trim().toLowerCase() : null);
4
+ /** Compare two class strings, treating the 'Ifc' prefix as optional.
5
+ * e.g. "IfcSpace" matches "Space", "space", and "IfcSpace". */
6
+ const classEquals = (a, b) => {
7
+ if (a === null || b === null)
8
+ return false;
9
+ if (a === b)
10
+ return true;
11
+ // Try with/without Ifc prefix in both directions
12
+ const stripIfc = (s) => (s.startsWith('ifc') ? s.slice(3) : s);
13
+ return stripIfc(a) === stripIfc(b);
14
+ };
15
+ const normalizeValue = (v) => (typeof v === 'string' ? v.toLowerCase().trim() : v);
16
+ /**
17
+ * Check whether an item's ifcClass matches the given class filter.
18
+ *
19
+ * Uses normalizeClass() for string comparison — works for extracted items
20
+ * where we have a normalized ifcClass string (not a live product).
21
+ *
22
+ * For live products, the caller should use product.class.is() directly.
23
+ */
24
+ const matchesClass = (itemClass, classFilter) => {
25
+ if (classFilter === undefined)
26
+ return true;
27
+ const classes = Array.isArray(classFilter) ? classFilter : [classFilter];
28
+ const normalized = normalizeClass(itemClass);
29
+ if (normalized === null)
30
+ return false;
31
+ return classes.some((c) => classEquals(normalizeClass(c), normalized));
32
+ };
33
+ /**
34
+ * Check whether an item matches a `where` condition.
35
+ *
36
+ * Each key in `where` is a short property path (e.g. "BIP.spacetype").
37
+ * Each value is either a scalar (equality check) or an array (any-of check).
38
+ * Multiple keys = AND. String comparison is case-insensitive.
39
+ */
40
+ const matchesWhere = (item, where) => {
41
+ if (!where)
42
+ return true;
43
+ for (const [path, expected] of Object.entries(where)) {
44
+ const value = resolveProperty(item, path);
45
+ if (Array.isArray(expected)) {
46
+ const target = normalizeValue(value);
47
+ if (!expected.some((v) => normalizeValue(v) === target))
48
+ return false;
49
+ }
50
+ else {
51
+ if (normalizeValue(value) !== normalizeValue(expected))
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ };
57
+ /**
58
+ * V2 filter: match items by class + where conditions.
59
+ *
60
+ * @param item - An object with ifcClass and propertySets
61
+ * @param classFilter - IFC class name(s) to match, or undefined for any
62
+ * @param where - Property conditions (short paths), or undefined for no conditions
63
+ */
64
+ export const matchesV2Filter = (item, classFilter, where) => {
65
+ if (classFilter !== undefined && isRecord(item)) {
66
+ const itemClass = getProp(item, 'ifcClass');
67
+ const itemClassId = getProp(item, 'ifcClassId');
68
+ if (!matchesClass(itemClass, classFilter) && !matchesClass(itemClassId, classFilter)) {
69
+ return false;
70
+ }
71
+ }
72
+ if (!matchesWhere(item, where))
73
+ return false;
74
+ return true;
75
+ };
76
+ export { normalizeClass, classEquals, normalizeValue, matchesClass, matchesWhere };
77
+ //# sourceMappingURL=filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.js","sourceRoot":"/","sources":["layout/filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIjD,MAAM,cAAc,GAAG,CAAC,GAAY,EAAiB,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEpH;gEACgE;AAChE,MAAM,WAAW,GAAG,CAAC,CAAgB,EAAE,CAAgB,EAAW,EAAE;IAChE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC3C,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,iDAAiD;IACjD,MAAM,QAAQ,GAAG,CA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EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;gBAAE,OAAO,KAAK,CAAC;QAC1E,CAAC;aAAM,CAAC;YACJ,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,cAAc,CAAC,QAAQ,CAAC;gBAAE,OAAO,KAAK,CAAC;QACzE,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC3B,IAAa,EACb,WAA0C,EAC1C,KAAiC,EAC1B,EAAE;IACT,IAAI,WAAW,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC;YACnF,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { resolveProperty } from './renderUtils';\r\n\r\nimport { isRecord, getProp } from './typeGuards';\r\n\r\nimport type { WhereCondition } from './types';\r\n\r\nconst normalizeClass = (cls: unknown): string | null => (typeof cls === 'string' ? cls.trim().toLowerCase() : null);\r\n\r\n/** Compare two class strings, treating the 'Ifc' prefix as optional.\r\n * e.g. \"IfcSpace\" matches \"Space\", \"space\", and \"IfcSpace\". */\r\nconst classEquals = (a: string | null, b: string | null): boolean => {\r\n if (a === null || b === null) return false;\r\n if (a === b) return true;\r\n // Try with/without Ifc prefix in both directions\r\n const stripIfc = (s: string): string => (s.startsWith('ifc') ? s.slice(3) : s);\r\n return stripIfc(a) === stripIfc(b);\r\n};\r\nconst normalizeValue = (v: unknown): unknown => (typeof v === 'string' ? v.toLowerCase().trim() : v);\r\n\r\n/**\r\n * Check whether an item's ifcClass matches the given class filter.\r\n *\r\n * Uses normalizeClass() for string comparison — works for extracted items\r\n * where we have a normalized ifcClass string (not a live product).\r\n *\r\n * For live products, the caller should use product.class.is() directly.\r\n */\r\nconst matchesClass = (itemClass: unknown, classFilter: string | string[] | undefined): boolean => {\r\n if (classFilter === undefined) return true;\r\n const classes = Array.isArray(classFilter) ? classFilter : [classFilter];\r\n const normalized = normalizeClass(itemClass);\r\n if (normalized === null) return false;\r\n return classes.some((c) => classEquals(normalizeClass(c), normalized));\r\n};\r\n\r\n/**\r\n * Check whether an item matches a `where` condition.\r\n *\r\n * Each key in `where` is a short property path (e.g. \"BIP.spacetype\").\r\n * Each value is either a scalar (equality check) or an array (any-of check).\r\n * Multiple keys = AND. String comparison is case-insensitive.\r\n */\r\nconst matchesWhere = (item: unknown, where: WhereCondition | undefined): boolean => {\r\n if (!where) return true;\r\n for (const [path, expected] of Object.entries(where)) {\r\n const value = resolveProperty(item, path);\r\n if (Array.isArray(expected)) {\r\n const target = normalizeValue(value);\r\n if (!expected.some((v) => normalizeValue(v) === target)) return false;\r\n } else {\r\n if (normalizeValue(value) !== normalizeValue(expected)) return false;\r\n }\r\n }\r\n return true;\r\n};\r\n\r\n/**\r\n * V2 filter: match items by class + where conditions.\r\n *\r\n * @param item - An object with ifcClass and propertySets\r\n * @param classFilter - IFC class name(s) to match, or undefined for any\r\n * @param where - Property conditions (short paths), or undefined for no conditions\r\n */\r\nexport const matchesV2Filter = (\r\n item: unknown,\r\n classFilter: string | string[] | undefined,\r\n where: WhereCondition | undefined\r\n): boolean => {\r\n if (classFilter !== undefined && isRecord(item)) {\r\n const itemClass = getProp(item, 'ifcClass');\r\n const itemClassId = getProp(item, 'ifcClassId');\r\n if (!matchesClass(itemClass, classFilter) && !matchesClass(itemClassId, classFilter)) {\r\n return false;\r\n }\r\n }\r\n if (!matchesWhere(item, where)) return false;\r\n return true;\r\n};\r\n\r\nexport { normalizeClass, classEquals, normalizeValue, matchesClass, matchesWhere };\r\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Geometric computation constants
3
+ */
4
+ export declare const EPSILON_INTERSECTION = 1e-9;
5
+ export declare const EPSILON_DIVISION_SAFETY = 1e-9;
6
+ export declare const EPSILON_MIN_DIMENSION = 0.000001;
7
+ export declare const CENTER_FRACTION = 0.5;
8
+ //# sourceMappingURL=geometryConstants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometryConstants.d.ts","sourceRoot":"/","sources":["layout/geometryConstants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,qBAAqB,WAAO,CAAC;AAG1C,eAAO,MAAM,eAAe,MAAM,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Geometric computation constants
3
+ */
4
+ // Epsilon values for floating-point comparisons
5
+ export const EPSILON_INTERSECTION = 1e-9; // Used for detecting parallel lines
6
+ export const EPSILON_DIVISION_SAFETY = 1e-9; // Used to prevent division by zero
7
+ export const EPSILON_MIN_DIMENSION = 1e-6; // Minimum valid dimension for model bounds
8
+ // Geometric multipliers
9
+ export const CENTER_FRACTION = 0.5; // For calculating center/midpoint (x * 0.5)
10
+ //# sourceMappingURL=geometryConstants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometryConstants.js","sourceRoot":"/","sources":["layout/geometryConstants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,gDAAgD;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,CAAC,oCAAoC;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,CAAC,mCAAmC;AAChF,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,CAAC,2CAA2C;AAEtF,wBAAwB;AACxB,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC,CAAC,4CAA4C","sourcesContent":["/**\r\n * Geometric computation constants\r\n */\r\n\r\n// Epsilon values for floating-point comparisons\r\nexport const EPSILON_INTERSECTION = 1e-9; // Used for detecting parallel lines\r\nexport const EPSILON_DIVISION_SAFETY = 1e-9; // Used to prevent division by zero\r\nexport const EPSILON_MIN_DIMENSION = 1e-6; // Minimum valid dimension for model bounds\r\n\r\n// Geometric multipliers\r\nexport const CENTER_FRACTION = 0.5; // For calculating center/midpoint (x * 0.5)\r\n"]}
@@ -0,0 +1,86 @@
1
+ import type { SectionRenderState } from '@twinfinity/geometry';
2
+ import { pointInPolygon, filterItemsInPolygons, filterEntriesByClip, offsetPolygons, projectPolygonsToLocal } from './clipUtils';
3
+ import { RenderLayoutOptions } from './options';
4
+ import { LayoutTemplate, ModelContext, LayoutData, ValidationIssue, ComputedViewportScale } from './types';
5
+ export type LayoutDataValidationResult = {
6
+ ok: true;
7
+ } | {
8
+ ok: false;
9
+ errors: string[];
10
+ };
11
+ export type PreflightResult = {
12
+ ok: true;
13
+ } | {
14
+ ok: false;
15
+ templateErrors?: ValidationIssue[];
16
+ dataErrors?: string[];
17
+ sectionErrors?: string[];
18
+ };
19
+ /**
20
+ * Validate template, layout data, and section state in a single call.
21
+ * Combines `validateLayoutTemplate`, `validateLayoutData`, and `validateSectionState`.
22
+ */
23
+ export declare const preflight: (template: LayoutTemplate, data: unknown, expectedViewportIds: string[], sectionState?: SectionRenderState) => PreflightResult;
24
+ /**
25
+ * Validate layout data before rendering to catch missing propertySets or items arrays.
26
+ */
27
+ export declare const validateLayoutData: (data: unknown, expectedViewportIds: string[]) => LayoutDataValidationResult;
28
+ export type { PageSpec, TextStyle, StyleMap, AssetSpec, LayoutElement, BaseElement, ViewportElement, TextElement, ImageElement, LineElement, RectElement, CircleElement, PolylineElement, PolygonElement, PointMm, ScaleBarElement, QrElement, LabelsElement, LegendElement, GroupElement, LayoutTemplate, LegendAnchor, LegendColumn, SvgModelView, ModelContext, LayoutData, LayoutDataViewports, ViewportItemsMap, PagePresetKey, PageOrientation, ValidationOptions, ValidationIssue, ValidationResult, ComputedViewportScale, NormalizedProductItem, SectionStateValidationResult, LabelStyle, WhereCondition, ClipConfig, HighlightConfig, ViewportLineStyle, ViewportLineStyles, SectionResult, FillRule, RenderDrawingInput, RenderDrawingResult, IncludeClassesFilter, ResolvedIncludeFilter, TemplateVariableDef, TemplateVariableInfo } from './types';
29
+ export type { RenderLayoutOptions } from './options';
30
+ export { pointInPolygon, filterItemsInPolygons, filterEntriesByClip, offsetPolygons, projectPolygonsToLocal };
31
+ /** Normalize IFC class names to lowercase for consistent matching. */
32
+ export { normalizeClass } from './filters';
33
+ /** Test whether an item matches a class + where filter (used by clip, highlight, labels, legend). */
34
+ export { matchesV2Filter } from './filters';
35
+ /** Metadata utilities: build lookup maps, resolve IFC class includes, and merge metadata sources. */
36
+ export { buildMetadataMap, normalizePropertySets, resolveIfcClassName, resolveIfcClassId, resolveIncludeClasses, resolveAllowedClasses, resolveMeta } from './metadata';
37
+ /** Validate a layout template JSON structure. Returns `{ ok, errors }` or `{ ok, template }`. */
38
+ export { validateLayoutTemplate as validateLayoutTemplateExternal } from './validation';
39
+ /** Layout utility functions: scale denominators, label sizing, color parsing, and line style application. */
40
+ export { uniquePositiveDenoms, computeLabelFontSize, colorFromString, applyLineStyleToPaths } from './utils';
41
+ /** Property resolution: traverse nested objects with dot-path strings like `"BIP.spacename"`. */
42
+ export { getPathValue, resolveProperty, resolvePath, matchesPropertyFilter } from './renderUtils';
43
+ /** Build legend table rows from product items with property formatting. */
44
+ export { buildLegendRows, type LegendRow, type LegendRowOptions } from './legendRows';
45
+ /** Product normalization, viewport item builders, and section-state-to-SVG-model conversion. */
46
+ export type { ProductLike, BuildViewportItemsOptions } from './itemBuilders';
47
+ export { normalizeProductEntry, buildViewportItems, sectionStateToModelView } from './itemBuilders';
48
+ /**
49
+ * High-level facade: renders a complete drawing from a template + section geometry.
50
+ * Internalizes all data wiring (items, colors, labels, metadata) that `renderLayout` requires manually.
51
+ */
52
+ export { renderDrawing, resolveFillColor, BUILTIN_LINE_DEFAULTS, BUILTIN_HIDDEN_DEFAULTS, BUILTIN_LABEL_DEFAULTS, CATEGORY_BUILTIN_OVERRIDES, setRenderLayoutBinding } from './renderDrawing';
53
+ export type { ResolvedLineStyles } from './renderDrawing';
54
+ export { EXAMPLE_BUILDING_CLASSES } from './presets';
55
+ export { analyzeTemplate } from './analyzeTemplate';
56
+ export type { TemplateRequirements } from './analyzeTemplate';
57
+ /** Drawing export utilities: convert SVG markup to PDF or SVG files. */
58
+ export { exportToPdf, exportToSvg } from './exportDrawing';
59
+ export type { ExportPdfOptions, ExportSvgOptions } from './exportDrawing';
60
+ /** Template variable utilities: extract, validate, and resolve template parameters. */
61
+ export { getTemplateVariables, getTemplateDefaults, resolveTemplateValues, applyTemplateVariables } from './templateVariables';
62
+ /** Result of {@link renderLayout}: the final SVG markup, per-viewport scale info, and any warnings. */
63
+ export interface RenderLayoutResult {
64
+ /** Complete SVG markup string ready for embedding or PDF conversion. */
65
+ svg: string;
66
+ /** Per-viewport computed scale information (denominator, mm-per-model-unit, fit status). */
67
+ viewportScales: Record<string, ComputedViewportScale>;
68
+ /** Non-fatal issues encountered during rendering (missing assets, unresolved styles, etc.). */
69
+ warnings: string[];
70
+ }
71
+ /** Built-in default layout template (A3 landscape with a single viewport). */
72
+ export declare const DEFAULT_LAYOUT_TEMPLATE: LayoutTemplate;
73
+ /**
74
+ * Render a layout template to SVG.
75
+ *
76
+ * This is the low-level rendering function. For most use cases, prefer {@link renderDrawing}
77
+ * which handles all data wiring automatically.
78
+ *
79
+ * @param template - Validated layout template (page, elements, styles, presets).
80
+ * @param data - Layout data with viewport items, template variables, and legend rows.
81
+ * @param models - Per-viewport SVG model views (geometry + transforms).
82
+ * @param options - Optional rendering settings (remote assets, scale overrides, metadata).
83
+ * @returns SVG markup string, computed viewport scales, and any warnings.
84
+ */
85
+ export declare function renderLayout(template: LayoutTemplate, data: LayoutData, models: ModelContext, options?: RenderLayoutOptions): Promise<RenderLayoutResult>;
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EACH,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACzB,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAoBhD,OAAO,EAgBH,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,qBAAqB,EACxB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,0BAA0B,GAChC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IACI,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAER,MAAM,MAAM,eAAe,GACrB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IACI,EAAE,EAAE,KAAK,CAAC;IACV,cAAc,CAAC,EAAE,eAAe,EAAE,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,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,sBAAsB,EACzB,MAAM,qBAAqB,CAAC;AAE7B,uGAAuG;AACvG,MAAM,WAAW,kBAAkB;IAC/B,wEAAwE;IACxE,GAAG,EAAE,MAAM,CAAC;IACZ,4FAA4F;IAC5F,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IACtD,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,8EAA8E;AAC9E,eAAO,MAAM,uBAAuB,EAA0B,cAAc,CAAC;AAS7E;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAC9B,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC9B,OAAO,CAAC,kBAAkB,CAAC,CA4W7B"}
@@ -0,0 +1,363 @@
1
+ import defaultTemplateJson from '../templates/default-template.json';
2
+ import { pointInPolygon, filterItemsInPolygons, filterEntriesByClip, offsetPolygons, projectPolygonsToLocal } from './clipUtils';
3
+ import { uniquePositiveDenoms } from './utils';
4
+ import { validateLayoutTemplate as validateLayoutTemplateExternal } from './validation';
5
+ import { renderViewportElement } from './viewportRender';
6
+ import { prepareViewports } from './viewportPrep';
7
+ import { renderLabels } from './labelsRender';
8
+ import { renderQrElements } from './qrRender';
9
+ import { applyLegendFilter, buildLegendGroup } from './legendRender';
10
+ import { resolvePresets } from './presets';
11
+ import { pushWarning } from './warnings';
12
+ import { escapeAttr, escapeText, interpolate, getPathValue } from './renderUtils';
13
+ import { validateSectionState } from './sectionValidation';
14
+ import { ELEMENT_KIND_VIEWPORT, ELEMENT_KIND_TEXT, ELEMENT_KIND_IMAGE, ELEMENT_KIND_LINE, ELEMENT_KIND_RECT, ELEMENT_KIND_CIRCLE, ELEMENT_KIND_POLYLINE, ELEMENT_KIND_POLYGON, ELEMENT_KIND_SCALE_BAR, ELEMENT_KIND_QR, ELEMENT_KIND_LABELS, ELEMENT_KIND_LEGEND, ELEMENT_KIND_GROUP } from './elementKinds';
15
+ import { isRecord, getProp } from './typeGuards';
16
+ /**
17
+ * Validate template, layout data, and section state in a single call.
18
+ * Combines `validateLayoutTemplate`, `validateLayoutData`, and `validateSectionState`.
19
+ */
20
+ export const preflight = (template, data, expectedViewportIds, sectionState) => {
21
+ const templateValidation = validateLayoutTemplate(template);
22
+ const dataValidation = validateLayoutData(data, expectedViewportIds);
23
+ const sectionValidation = sectionState ? validateSectionState(sectionState) : { ok: true };
24
+ const ok = templateValidation.ok && dataValidation.ok && sectionValidation.ok;
25
+ if (ok)
26
+ return { ok: true };
27
+ return {
28
+ ok: false,
29
+ templateErrors: templateValidation.ok ? undefined : templateValidation.errors,
30
+ dataErrors: dataValidation.ok ? undefined : dataValidation.errors,
31
+ sectionErrors: sectionValidation.ok ? undefined : sectionValidation.errors
32
+ };
33
+ };
34
+ /**
35
+ * Validate layout data before rendering to catch missing propertySets or items arrays.
36
+ */
37
+ export const validateLayoutData = (data, expectedViewportIds) => {
38
+ const errors = [];
39
+ if (!isRecord(data)) {
40
+ return { ok: false, errors: ['layout data must be an object'] };
41
+ }
42
+ expectedViewportIds.forEach((vpId) => {
43
+ const viewports = getProp(data, 'viewports');
44
+ const viewport = isRecord(viewports) ? getProp(viewports, vpId) : undefined;
45
+ const items = getProp(viewport, 'items');
46
+ if (!Array.isArray(items)) {
47
+ errors.push(`viewports.${vpId}.items is required and must be an array.`);
48
+ return;
49
+ }
50
+ items.forEach((it, idx) => {
51
+ if (!isRecord(it)) {
52
+ errors.push(`viewports.${vpId}.items[${idx}] must be an object.`);
53
+ return;
54
+ }
55
+ const sets = getProp(it, 'propertySets');
56
+ if (!isRecord(sets)) {
57
+ errors.push(`viewports.${vpId}.items[${idx}] is missing propertySets.<Set>.<Prop>.value.`);
58
+ return;
59
+ }
60
+ Object.entries(sets).forEach(([setName, props]) => {
61
+ if (!isRecord(props)) {
62
+ errors.push(`viewports.${vpId}.items[${idx}].propertySets.${setName} must be an object.`);
63
+ return;
64
+ }
65
+ Object.entries(props).forEach(([propName, payload]) => {
66
+ if (!isRecord(payload) || !('value' in payload)) {
67
+ errors.push(`viewports.${vpId}.items[${idx}].propertySets.${setName}.${propName} must include a value (propertySets.<Set>.<Prop>.value).`);
68
+ }
69
+ });
70
+ });
71
+ });
72
+ });
73
+ return errors.length ? { ok: false, errors } : { ok: true };
74
+ };
75
+ const validateLayoutTemplate = validateLayoutTemplateExternal;
76
+ export { pointInPolygon, filterItemsInPolygons, filterEntriesByClip, offsetPolygons, projectPolygonsToLocal };
77
+ /** Normalize IFC class names to lowercase for consistent matching. */
78
+ export { normalizeClass } from './filters';
79
+ /** Test whether an item matches a class + where filter (used by clip, highlight, labels, legend). */
80
+ export { matchesV2Filter } from './filters';
81
+ /** Metadata utilities: build lookup maps, resolve IFC class includes, and merge metadata sources. */
82
+ export { buildMetadataMap, normalizePropertySets, resolveIfcClassName, resolveIfcClassId, resolveIncludeClasses, resolveAllowedClasses, resolveMeta } from './metadata';
83
+ /** Validate a layout template JSON structure. Returns `{ ok, errors }` or `{ ok, template }`. */
84
+ export { validateLayoutTemplate as validateLayoutTemplateExternal } from './validation';
85
+ /** Layout utility functions: scale denominators, label sizing, color parsing, and line style application. */
86
+ export { uniquePositiveDenoms, computeLabelFontSize, colorFromString, applyLineStyleToPaths } from './utils';
87
+ /** Property resolution: traverse nested objects with dot-path strings like `"BIP.spacename"`. */
88
+ export { getPathValue, resolveProperty, resolvePath, matchesPropertyFilter } from './renderUtils';
89
+ const SVG_NS = 'http://www.w3.org/2000/svg';
90
+ /** Build legend table rows from product items with property formatting. */
91
+ export { buildLegendRows } from './legendRows';
92
+ export { normalizeProductEntry, buildViewportItems, sectionStateToModelView } from './itemBuilders';
93
+ /**
94
+ * High-level facade: renders a complete drawing from a template + section geometry.
95
+ * Internalizes all data wiring (items, colors, labels, metadata) that `renderLayout` requires manually.
96
+ */
97
+ export { renderDrawing, resolveFillColor, BUILTIN_LINE_DEFAULTS, BUILTIN_HIDDEN_DEFAULTS, BUILTIN_LABEL_DEFAULTS, CATEGORY_BUILTIN_OVERRIDES, setRenderLayoutBinding } from './renderDrawing';
98
+ export { EXAMPLE_BUILDING_CLASSES } from './presets';
99
+ export { analyzeTemplate } from './analyzeTemplate';
100
+ /** Drawing export utilities: convert SVG markup to PDF or SVG files. */
101
+ export { exportToPdf, exportToSvg } from './exportDrawing';
102
+ /** Template variable utilities: extract, validate, and resolve template parameters. */
103
+ export { getTemplateVariables, getTemplateDefaults, resolveTemplateValues, applyTemplateVariables } from './templateVariables';
104
+ /** Built-in default layout template (A3 landscape with a single viewport). */
105
+ export const DEFAULT_LAYOUT_TEMPLATE = defaultTemplateJson;
106
+ const dashArray = (dashed) => (dashed ? ' stroke-dasharray="4 2"' : '');
107
+ const formatNumber = (value) => {
108
+ if (!Number.isFinite(value))
109
+ return 0;
110
+ return Number.parseFloat(value.toFixed(3));
111
+ };
112
+ /**
113
+ * Render a layout template to SVG.
114
+ *
115
+ * This is the low-level rendering function. For most use cases, prefer {@link renderDrawing}
116
+ * which handles all data wiring automatically.
117
+ *
118
+ * @param template - Validated layout template (page, elements, styles, presets).
119
+ * @param data - Layout data with viewport items, template variables, and legend rows.
120
+ * @param models - Per-viewport SVG model views (geometry + transforms).
121
+ * @param options - Optional rendering settings (remote assets, scale overrides, metadata).
122
+ * @returns SVG markup string, computed viewport scales, and any warnings.
123
+ */
124
+ export async function renderLayout(template, data, models, options) {
125
+ const presets = resolvePresets(template?.presets);
126
+ const validation = validateLayoutTemplate(template, {
127
+ allowRemoteAssets: options?.allowRemoteAssets,
128
+ allowDataUrls: options?.allowDataUrls,
129
+ maxViewports: options?.maxViewports
130
+ });
131
+ if (!validation.ok) {
132
+ throw new Error(`Template validation failed: ${validation.errors.map((e) => `${e.path}: ${e.message}`).join('; ')}`);
133
+ }
134
+ const preferredScales = uniquePositiveDenoms(options?.scaleDenominators);
135
+ const page = template.page;
136
+ const warnings = [];
137
+ // Flatten all elements to collect viewports, qrs, labels, legends regardless of grouping
138
+ const allElements = [];
139
+ const collectElements = (elements) => {
140
+ elements.forEach((el) => {
141
+ allElements.push(el);
142
+ if (el.kind === ELEMENT_KIND_GROUP) {
143
+ collectElements(el.children);
144
+ }
145
+ });
146
+ };
147
+ collectElements(template.elements);
148
+ const viewports = allElements.filter((el) => el.kind === ELEMENT_KIND_VIEWPORT);
149
+ const dataValidation = validateLayoutData(data, viewports.map((v) => v.id));
150
+ if (!dataValidation.ok) {
151
+ throw new Error(`Layout data validation failed: ${dataValidation.errors.join('; ')}`);
152
+ }
153
+ const { viewportScales, viewportClipPolygonsLocal, viewportClipPolygonsWorld, viewportClipBounds, viewportClipLabels, viewportClipStyles,
154
+ // viewportClipWhere intentionally omitted — not needed for rendering
155
+ viewportHighlight, filteredModelsByViewport } = prepareViewports(viewports, models, data, preferredScales, presets, {
156
+ metadataById: options?.metadataById,
157
+ warnings
158
+ });
159
+ const viewportData = {};
160
+ Object.entries(viewportScales).forEach(([id, scale]) => {
161
+ viewportData[id] = {
162
+ scaleDenom: scale.denom,
163
+ scaleText: `1:${scale.denom}`,
164
+ mmPerModelUnit: scale.mmPerModelUnit,
165
+ fits: scale.fits
166
+ };
167
+ });
168
+ const dataWithViewport = { ...data, viewport: viewportData };
169
+ const sorted = [...template.elements].sort((a, b) => (a.zIndex ?? 0) - (b.zIndex ?? 0));
170
+ const parts = [];
171
+ parts.push(`<svg xmlns="${SVG_NS}" width="${page.widthMm}mm" height="${page.heightMm}mm" viewBox="0 0 ${page.widthMm} ${page.heightMm}">`);
172
+ if (page.backgroundColor) {
173
+ parts.push(`<rect x="0" y="0" width="${page.widthMm}" height="${page.heightMm}" fill="${escapeAttr(page.backgroundColor)}"/>`);
174
+ }
175
+ const assetMap = new Map();
176
+ (template.assets ?? []).forEach((asset) => assetMap.set(asset.id, asset));
177
+ const qrElements = allElements.filter((el) => el.kind === ELEMENT_KIND_QR);
178
+ const labelElements = allElements.filter((el) => el.kind === ELEMENT_KIND_LABELS);
179
+ const viewportRenderInfo = {};
180
+ // Pre-process legends to collect color maps (needed before viewport rendering)
181
+ const legendColorMaps = new Map(); // viewport ID -> color map
182
+ const legendElements = allElements.filter((el) => el.kind === ELEMENT_KIND_LEGEND);
183
+ legendElements.forEach((legend) => {
184
+ if (legend.assignColors?.enabled && legend.groupBy) {
185
+ const legendItems = getPathValue(data, `viewports.${legend.viewport}.items`);
186
+ const rawLegendItems = Array.isArray(legendItems) ? legendItems : [];
187
+ const legendDataFiltered = applyLegendFilter(rawLegendItems, legend, viewports, viewportClipPolygonsLocal, viewportRenderInfo);
188
+ if (legendDataFiltered && legendDataFiltered.length) {
189
+ const vpEl = viewports.find((v) => v.id === legend.viewport);
190
+ const fillOpacity = vpEl?.fills?.length ? (vpEl.fills[0].fillOpacity ?? 0.35) : undefined;
191
+ const result = buildLegendGroup(legend, template.styles, page, page.marginMm, legendDataFiltered, fillOpacity);
192
+ if (result?.colorMap) {
193
+ legendColorMaps.set(legend.viewport, result.colorMap);
194
+ console.log(`[LEGEND PRE-PROCESS] Stored color map for viewport "${legend.viewport}": ${result.colorMap.size} colors`);
195
+ }
196
+ }
197
+ }
198
+ });
199
+ sorted.forEach((el) => {
200
+ if (el.kind === ELEMENT_KIND_RECT) {
201
+ const r = el;
202
+ parts.push(`<rect x="${r.xMm}" y="${r.yMm}" width="${r.widthMm}" height="${r.heightMm}"` +
203
+ (r.stroke ? ` stroke="${escapeAttr(r.stroke)}"` : '') +
204
+ (r.strokeWidthMm ? ` stroke-width="${r.strokeWidthMm}"` : '') +
205
+ (r.fill ? ` fill="${escapeAttr(r.fill)}"` : ' fill="none"') +
206
+ dashArray(r.dashed) +
207
+ ` />`);
208
+ }
209
+ else if (el.kind === ELEMENT_KIND_LINE) {
210
+ const l = el;
211
+ parts.push(`<line x1="${l.x1Mm}" y1="${l.y1Mm}" x2="${l.x2Mm}" y2="${l.y2Mm}"` +
212
+ (l.stroke ? ` stroke="${escapeAttr(l.stroke)}"` : '') +
213
+ (l.strokeWidthMm ? ` stroke-width="${l.strokeWidthMm}"` : '') +
214
+ dashArray(l.dashed) +
215
+ ` />`);
216
+ }
217
+ else if (el.kind === ELEMENT_KIND_CIRCLE) {
218
+ const c = el;
219
+ parts.push(`<circle cx="${c.cxMm}" cy="${c.cyMm}" r="${c.rMm}"` +
220
+ (c.stroke ? ` stroke="${escapeAttr(c.stroke)}"` : '') +
221
+ (c.strokeWidthMm ? ` stroke-width="${c.strokeWidthMm}"` : '') +
222
+ (c.fill ? ` fill="${escapeAttr(c.fill)}"` : ' fill="none"') +
223
+ dashArray(c.dashed) +
224
+ ` />`);
225
+ }
226
+ else if (el.kind === ELEMENT_KIND_POLYLINE) {
227
+ const pl = el;
228
+ const pointsStr = pl.points.map((p) => `${formatNumber(p.xMm)},${formatNumber(p.yMm)}`).join(' ');
229
+ parts.push(`<polyline points="${pointsStr}" stroke="${escapeAttr(pl.stroke)}" stroke-width="${pl.strokeWidthMm}" fill="none"${dashArray(pl.dashed)} />`);
230
+ }
231
+ else if (el.kind === ELEMENT_KIND_POLYGON) {
232
+ const pg = el;
233
+ const pointsStr = pg.points.map((p) => `${formatNumber(p.xMm)},${formatNumber(p.yMm)}`).join(' ');
234
+ parts.push(`<polygon points="${pointsStr}"` +
235
+ (pg.stroke ? ` stroke="${escapeAttr(pg.stroke)}"` : '') +
236
+ (pg.strokeWidthMm ? ` stroke-width="${pg.strokeWidthMm}"` : '') +
237
+ (pg.fill ? ` fill="${escapeAttr(pg.fill)}"` : ' fill="none"') +
238
+ dashArray(pg.dashed) +
239
+ ` />`);
240
+ }
241
+ else if (el.kind === ELEMENT_KIND_TEXT) {
242
+ const tEl = el;
243
+ const styleName = tEl.textStyle;
244
+ const style = styleName ? template.styles?.[styleName] : undefined;
245
+ if (!style) {
246
+ pushWarning(warnings, `Missing text style '${styleName ?? '(none)'}' for element '${tEl.id}'.`);
247
+ return;
248
+ }
249
+ const text = interpolate(tEl.text, dataWithViewport, warnings);
250
+ const anchor = tEl.align === 'center' ? 'middle' : tEl.align === 'right' ? 'end' : 'start';
251
+ parts.push(`<text x="${tEl.xMm}" y="${tEl.yMm}" font-family="${escapeAttr(style.fontFamily)}" font-size="${style.fontSizeMm}"` +
252
+ (style.fontWeight ? ` font-weight="${escapeAttr(style.fontWeight)}"` : '') +
253
+ (style.color ? ` fill="${escapeAttr(style.color)}"` : '') +
254
+ (style.letterSpacingMm !== undefined ? ` letter-spacing="${style.letterSpacingMm}"` : '') +
255
+ (style.lineHeightMm !== undefined ? ` line-height="${style.lineHeightMm}"` : '') +
256
+ ` text-anchor="${anchor}">${escapeText(text)}</text>`);
257
+ }
258
+ else if (el.kind === ELEMENT_KIND_IMAGE) {
259
+ const img = el;
260
+ const asset = assetMap.get(img.assetId);
261
+ if (!asset) {
262
+ pushWarning(warnings, `Missing asset '${img.assetId}' for image '${img.id}'.`);
263
+ return;
264
+ }
265
+ if (asset.src) {
266
+ parts.push(`<image href="${escapeAttr(asset.src)}" x="${img.xMm}" y="${img.yMm}" width="${img.widthMm}" height="${img.heightMm}"` +
267
+ (img.fit === 'cover'
268
+ ? ' preserveAspectRatio="xMidYMid slice"'
269
+ : img.fit === 'stretch'
270
+ ? ' preserveAspectRatio="none"'
271
+ : ' preserveAspectRatio="xMidYMid meet"') +
272
+ ` />`);
273
+ }
274
+ else if (asset.content) {
275
+ parts.push(`<g transform="translate(${img.xMm} ${img.yMm}) scale(${img.widthMm} ${img.heightMm})">${asset.content}</g>`);
276
+ }
277
+ }
278
+ else if (el.kind === ELEMENT_KIND_SCALE_BAR) {
279
+ const sb = el;
280
+ // Scale bar declares which viewport it binds to via `viewport`
281
+ const boundViewport = sb.viewport ?? viewports[0]?.id ?? null;
282
+ if (!boundViewport) {
283
+ pushWarning(warnings, `Scale bar '${sb.id}' is not bound to a viewport.`);
284
+ return;
285
+ }
286
+ const scaleInfo = viewportScales[boundViewport];
287
+ if (!scaleInfo) {
288
+ pushWarning(warnings, `Viewport '${boundViewport}' missing scale info for scale bar '${sb.id}'.`);
289
+ return;
290
+ }
291
+ const lengthMm = sb.maxLengthMm;
292
+ const segments = sb.segments ?? 10;
293
+ const segmentMm = lengthMm / segments;
294
+ const metersPerMm = 1 / scaleInfo.mmPerModelUnit;
295
+ const segmentMeters = segmentMm * metersPerMm;
296
+ const labelsEvery = Math.max(1, sb.labelEvery ?? 1);
297
+ const unitSuffix = sb.unit ? ` ${sb.unit}` : ' m';
298
+ const barParts = [];
299
+ const sbStroke = sb.stroke ?? '#000';
300
+ const sbStrokeWidth = sb.strokeWidthMm ?? 0.5;
301
+ for (let i = 0; i <= segments; i++) {
302
+ const x = sb.xMm + segmentMm * i;
303
+ const isLabel = i % labelsEvery === 0;
304
+ const height = isLabel ? 4 : 3;
305
+ barParts.push(`<line x1="${x}" y1="${sb.yMm}" x2="${x}" y2="${sb.yMm - height}" stroke="${escapeAttr(sbStroke)}" stroke-width="${sbStrokeWidth}" />`);
306
+ if (isLabel && sb.textStyle) {
307
+ const style = template.styles?.[sb.textStyle];
308
+ if (style) {
309
+ const labelValue = (segmentMeters * i).toFixed(2).replace(/\.?0+$/, '');
310
+ barParts.push(`<text x="${x}" y="${sb.yMm + style.fontSizeMm + 1}" font-family="${escapeAttr(style.fontFamily)}" font-size="${style.fontSizeMm}" text-anchor="middle">${escapeText(labelValue + unitSuffix)}</text>`);
311
+ }
312
+ }
313
+ }
314
+ barParts.push(`<line x1="${sb.xMm}" y1="${sb.yMm}" x2="${sb.xMm + lengthMm}" y2="${sb.yMm}" stroke="${escapeAttr(sbStroke)}" stroke-width="${sbStrokeWidth}" />`);
315
+ parts.push(barParts.join(''));
316
+ }
317
+ else if (el.kind === ELEMENT_KIND_VIEWPORT) {
318
+ const vp = el;
319
+ const model = filteredModelsByViewport[vp.id] ?? models[vp.id] ?? null;
320
+ if (!model) {
321
+ pushWarning(warnings, `Viewport '${vp.id}' missing model.`);
322
+ }
323
+ const vpParts = renderViewportElement(vp, model, dataWithViewport, preferredScales, presets.scales, assetMap, viewportScales, viewportClipPolygonsLocal, viewportClipBounds, viewportClipLabels, viewportClipStyles, viewportHighlight, viewportRenderInfo, warnings, legendColorMaps);
324
+ parts.push(...vpParts);
325
+ }
326
+ else if (el.kind === ELEMENT_KIND_LEGEND) {
327
+ const legend = el;
328
+ const legendItems = getPathValue(data, `viewports.${legend.viewport}.items`);
329
+ const rawLegendItems = Array.isArray(legendItems) ? legendItems : [];
330
+ const legendDataFiltered = applyLegendFilter(rawLegendItems, legend, viewports, viewportClipPolygonsLocal, viewportRenderInfo);
331
+ if (!legendDataFiltered || !legendDataFiltered.length) {
332
+ if (!rawLegendItems.length) {
333
+ pushWarning(warnings, `Legend '${legend.id}' has no items from viewport '${legend.viewport}'.`);
334
+ }
335
+ else {
336
+ pushWarning(warnings, `Legend '${legend.id}' filter matched 0 of ${rawLegendItems.length} items (class=${JSON.stringify(legend.class)}, where=${JSON.stringify(legend.where)}).`);
337
+ }
338
+ }
339
+ const vpEl = viewports.find((v) => v.id === legend.viewport);
340
+ // Derive swatch opacity from viewport fill rules (first matching rule's opacity)
341
+ const fillOpacity = vpEl?.fills?.length ? (vpEl.fills[0].fillOpacity ?? 0.35) : undefined;
342
+ const legendResult = buildLegendGroup(legend, template.styles, page, page.marginMm, legendDataFiltered || [], fillOpacity);
343
+ if (legendResult) {
344
+ parts.push(legendResult.svg);
345
+ }
346
+ }
347
+ });
348
+ if (labelElements.length) {
349
+ const labelParts = renderLabels(labelElements, data, viewportRenderInfo, viewportClipLabels, viewportClipPolygonsLocal, viewportClipPolygonsWorld, template.styles ?? {}, dataWithViewport, warnings);
350
+ parts.push(...labelParts);
351
+ }
352
+ if (qrElements.length) {
353
+ const qrParts = await renderQrElements(qrElements, viewports, viewportScales, models, { qrContext: options?.qrContext }, dataWithViewport, warnings);
354
+ parts.push(...qrParts);
355
+ }
356
+ parts.push('</svg>');
357
+ return { svg: parts.join(''), viewportScales, warnings };
358
+ }
359
+ // Register renderLayout with renderDrawing to break the circular dependency.
360
+ // This runs at module evaluation time — safe because renderLayout is defined above.
361
+ import { setRenderLayoutBinding as _setBinding } from './renderDrawing';
362
+ _setBinding(renderLayout);
363
+ //# sourceMappingURL=index.js.map