@officedk/pptxdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/build.d.ts +94 -0
  4. package/dist/build.js +148 -0
  5. package/dist/capabilities/dist/all.js +32 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +51 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +31 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +138 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +77 -0
  11. package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
  12. package/dist/capabilities/dist/chart/chart-elements.js +12 -0
  13. package/dist/capabilities/dist/chart/chart-import.js +2272 -0
  14. package/dist/capabilities/dist/chart/chart-labels.js +86 -0
  15. package/dist/capabilities/dist/chart/chart-model.js +9 -0
  16. package/dist/capabilities/dist/chart/chart-schemas.js +1078 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1124 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -0
  20. package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
  21. package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
  22. package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
  23. package/dist/capabilities/dist/chart/preview/index.js +190 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +519 -0
  25. package/dist/capabilities/dist/chart/preview/legend.js +273 -0
  26. package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
  27. package/dist/capabilities/dist/chart/preview/markers.js +100 -0
  28. package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
  29. package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
  30. package/dist/capabilities/dist/chart/preview/scales.js +365 -0
  31. package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
  32. package/dist/capabilities/dist/chart/preview/style.js +48 -0
  33. package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
  34. package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
  35. package/dist/capabilities/dist/chart/preview/types.js +5 -0
  36. package/dist/capabilities/dist/document.js +148 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +289 -0
  38. package/dist/capabilities/dist/font/font-family.js +10 -0
  39. package/dist/capabilities/dist/font/font-import.js +302 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +25 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +51 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +42 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +319 -0
  46. package/dist/capabilities/dist/group/group-xml.js +7 -0
  47. package/dist/capabilities/dist/group/group.js +211 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +94 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +221 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +778 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +149 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +472 -0
  57. package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
  58. package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
  59. package/dist/capabilities/dist/masters/masters.js +250 -0
  60. package/dist/capabilities/dist/motion/motion-api.js +527 -0
  61. package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
  62. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  63. package/dist/capabilities/dist/motion/motion-import.js +1033 -0
  64. package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
  65. package/dist/capabilities/dist/motion/motion-query.js +420 -0
  66. package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
  67. package/dist/capabilities/dist/motion/motion.js +1372 -0
  68. package/dist/capabilities/dist/notes/notes-codegen.js +20 -0
  69. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  70. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  71. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  72. package/dist/capabilities/dist/notes/notes-schemas.js +35 -0
  73. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  74. package/dist/capabilities/dist/notes/notes.js +191 -0
  75. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
  76. package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
  77. package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
  78. package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
  79. package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
  80. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  81. package/dist/capabilities/dist/shape/shape-import.js +579 -0
  82. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  83. package/dist/capabilities/dist/shape/shape.js +337 -0
  84. package/dist/capabilities/dist/shared/geometry.js +1423 -0
  85. package/dist/capabilities/dist/shared/identity.js +205 -0
  86. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  87. package/dist/capabilities/dist/shared/placeholder-import.js +113 -0
  88. package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
  89. package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
  90. package/dist/capabilities/dist/shared/style-parse.js +11 -0
  91. package/dist/capabilities/dist/shared/text-schemas.js +216 -0
  92. package/dist/capabilities/dist/shared/text-service.js +1883 -0
  93. package/dist/capabilities/dist/shared/visual.js +918 -0
  94. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  95. package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
  96. package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
  97. package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
  98. package/dist/capabilities/dist/table/table-codegen.js +81 -0
  99. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  100. package/dist/capabilities/dist/table/table-elements.js +27 -0
  101. package/dist/capabilities/dist/table/table-import.js +539 -0
  102. package/dist/capabilities/dist/table/table-schemas.js +279 -0
  103. package/dist/capabilities/dist/table/table-xml.js +37 -0
  104. package/dist/capabilities/dist/table/table.js +662 -0
  105. package/dist/capabilities/dist/text/text-codegen.js +129 -0
  106. package/dist/capabilities/dist/text/text-declaration.js +19 -0
  107. package/dist/capabilities/dist/text/text-elements.js +38 -0
  108. package/dist/capabilities/dist/text/text-import.js +1077 -0
  109. package/dist/capabilities/dist/text/text-xml.js +9 -0
  110. package/dist/capabilities/dist/text/text.js +335 -0
  111. package/dist/capabilities/dist/transition/transition-api.js +139 -0
  112. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  113. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  114. package/dist/capabilities/dist/transition/transition.js +260 -0
  115. package/dist/capability-D_xeNVIw.d.ts +29496 -0
  116. package/dist/cli.js +20 -0
  117. package/dist/codegen/dist/assets.js +78 -0
  118. package/dist/codegen/dist/codegen.js +611 -0
  119. package/dist/codegen/dist/identifiers.js +193 -0
  120. package/dist/codegen/dist/index.js +3 -0
  121. package/dist/codegen/dist/printer.js +143 -0
  122. package/dist/codegen/dist/types.js +49 -0
  123. package/dist/core/dist/author-ids.js +48 -0
  124. package/dist/core/dist/author-schemas.js +313 -0
  125. package/dist/core/dist/block-flex-layout.js +749 -0
  126. package/dist/core/dist/build.js +4 -0
  127. package/dist/core/dist/capability.js +13 -0
  128. package/dist/core/dist/declaration.js +15 -0
  129. package/dist/core/dist/diagnostics.js +21 -0
  130. package/dist/core/dist/document-internals.js +13 -0
  131. package/dist/core/dist/document.js +408 -0
  132. package/dist/core/dist/geometry-schemas.js +249 -0
  133. package/dist/core/dist/grid-layout.js +445 -0
  134. package/dist/core/dist/host.js +40 -0
  135. package/dist/core/dist/index.js +15 -0
  136. package/dist/core/dist/input-values.js +45 -0
  137. package/dist/core/dist/layout-protocol.js +66 -0
  138. package/dist/core/dist/layout-schemas.js +208 -0
  139. package/dist/core/dist/layout.js +299 -0
  140. package/dist/core/dist/masters.js +169 -0
  141. package/dist/core/dist/morph.js +30 -0
  142. package/dist/core/dist/placeholders.js +213 -0
  143. package/dist/core/dist/query.js +155 -0
  144. package/dist/core/dist/resolution.js +11 -0
  145. package/dist/core/dist/resolve.js +1827 -0
  146. package/dist/core/dist/stage-options.js +67 -0
  147. package/dist/core/dist/theme.js +931 -0
  148. package/dist/document-BHPUODPP.d.ts +27759 -0
  149. package/dist/emit/dist/emit.js +936 -0
  150. package/dist/emit/dist/index.js +5 -0
  151. package/dist/emit/dist/ooxml.js +606 -0
  152. package/dist/emit/dist/shape-tree.js +12 -0
  153. package/dist/import/dist/alternate-content.js +54 -0
  154. package/dist/import/dist/diagnostics.js +153 -0
  155. package/dist/import/dist/fonts.js +250 -0
  156. package/dist/import/dist/import.js +504 -0
  157. package/dist/import/dist/index.js +16 -0
  158. package/dist/import/dist/masters.js +1153 -0
  159. package/dist/import/dist/mechanism.js +10 -0
  160. package/dist/import/dist/namespaces.js +60 -0
  161. package/dist/import/dist/notes-masters.js +300 -0
  162. package/dist/import/dist/opc.js +233 -0
  163. package/dist/import/dist/resources.js +166 -0
  164. package/dist/import/dist/sections.js +139 -0
  165. package/dist/import/dist/themes.js +671 -0
  166. package/dist/import/dist/visual.js +761 -0
  167. package/dist/import/dist/xml-fragments.js +36 -0
  168. package/dist/import/dist/xml-reader.js +267 -0
  169. package/dist/index-B5m3hqjC.d.ts +7 -0
  170. package/dist/index-CCy-Yo8G.d.ts +1208 -0
  171. package/dist/index-DpxcZ4Gs.d.ts +725 -0
  172. package/dist/index.d.ts +7 -0
  173. package/dist/index.js +70 -0
  174. package/dist/node.d.ts +53 -0
  175. package/dist/node.js +194 -0
  176. package/dist/pptxdk/src/cli-commands.js +913 -0
  177. package/dist/pptxdk/src/compose.js +44 -0
  178. package/dist/pptxdk/src/slide.js +9 -0
  179. package/dist/preview/dist/index.js +240 -0
  180. package/dist/preview/dist/options.js +53 -0
  181. package/dist/preview-Cfw0QdMM.d.ts +86 -0
  182. package/dist/preview.d.ts +3 -0
  183. package/dist/preview.js +27 -0
  184. package/dist/react/dist/append.js +66 -0
  185. package/dist/react/dist/document-adapter.js +65 -0
  186. package/dist/react/dist/elements.js +59 -0
  187. package/dist/react/dist/index.js +68 -0
  188. package/dist/react/dist/reconciler.js +290 -0
  189. package/dist/react.d.ts +145 -0
  190. package/dist/react.js +27 -0
  191. package/dist/transition-Cips9wma.d.ts +82 -0
  192. package/dist/vanilla.d.ts +4 -0
  193. package/dist/vanilla.js +14 -0
  194. package/package.json +78 -3
@@ -0,0 +1,249 @@
1
+ import { z } from "zod";
2
+ // ../core/dist/geometry-schemas.js
3
+ /** Complete DrawingML preset geometry list from ECMA-376 ST_ShapeType (187 shapes). */
4
+ const presetGeometryTuple = [
5
+ "line",
6
+ "lineInv",
7
+ "triangle",
8
+ "rtTriangle",
9
+ "rect",
10
+ "diamond",
11
+ "parallelogram",
12
+ "trapezoid",
13
+ "nonIsoscelesTrapezoid",
14
+ "pentagon",
15
+ "hexagon",
16
+ "heptagon",
17
+ "octagon",
18
+ "decagon",
19
+ "dodecagon",
20
+ "star4",
21
+ "star5",
22
+ "star6",
23
+ "star7",
24
+ "star8",
25
+ "star10",
26
+ "star12",
27
+ "star16",
28
+ "star24",
29
+ "star32",
30
+ "roundRect",
31
+ "round1Rect",
32
+ "round2SameRect",
33
+ "round2DiagRect",
34
+ "snipRoundRect",
35
+ "snip1Rect",
36
+ "snip2SameRect",
37
+ "snip2DiagRect",
38
+ "plaque",
39
+ "ellipse",
40
+ "teardrop",
41
+ "homePlate",
42
+ "chevron",
43
+ "pieWedge",
44
+ "pie",
45
+ "blockArc",
46
+ "donut",
47
+ "noSmoking",
48
+ "rightArrow",
49
+ "leftArrow",
50
+ "upArrow",
51
+ "downArrow",
52
+ "stripedRightArrow",
53
+ "notchedRightArrow",
54
+ "bentUpArrow",
55
+ "leftRightArrow",
56
+ "upDownArrow",
57
+ "leftUpArrow",
58
+ "leftRightUpArrow",
59
+ "quadArrow",
60
+ "leftArrowCallout",
61
+ "rightArrowCallout",
62
+ "upArrowCallout",
63
+ "downArrowCallout",
64
+ "leftRightArrowCallout",
65
+ "upDownArrowCallout",
66
+ "quadArrowCallout",
67
+ "bentArrow",
68
+ "uturnArrow",
69
+ "circularArrow",
70
+ "leftCircularArrow",
71
+ "leftRightCircularArrow",
72
+ "curvedRightArrow",
73
+ "curvedLeftArrow",
74
+ "curvedUpArrow",
75
+ "curvedDownArrow",
76
+ "swooshArrow",
77
+ "cube",
78
+ "can",
79
+ "lightningBolt",
80
+ "heart",
81
+ "sun",
82
+ "moon",
83
+ "smileyFace",
84
+ "irregularSeal1",
85
+ "irregularSeal2",
86
+ "foldedCorner",
87
+ "bevel",
88
+ "frame",
89
+ "halfFrame",
90
+ "corner",
91
+ "diagStripe",
92
+ "chord",
93
+ "arc",
94
+ "leftBracket",
95
+ "rightBracket",
96
+ "leftBrace",
97
+ "rightBrace",
98
+ "bracketPair",
99
+ "bracePair",
100
+ "straightConnector1",
101
+ "bentConnector2",
102
+ "bentConnector3",
103
+ "bentConnector4",
104
+ "bentConnector5",
105
+ "curvedConnector2",
106
+ "curvedConnector3",
107
+ "curvedConnector4",
108
+ "curvedConnector5",
109
+ "callout1",
110
+ "callout2",
111
+ "callout3",
112
+ "accentCallout1",
113
+ "accentCallout2",
114
+ "accentCallout3",
115
+ "borderCallout1",
116
+ "borderCallout2",
117
+ "borderCallout3",
118
+ "accentBorderCallout1",
119
+ "accentBorderCallout2",
120
+ "accentBorderCallout3",
121
+ "wedgeRectCallout",
122
+ "wedgeRoundRectCallout",
123
+ "wedgeEllipseCallout",
124
+ "cloudCallout",
125
+ "cloud",
126
+ "ribbon",
127
+ "ribbon2",
128
+ "ellipseRibbon",
129
+ "ellipseRibbon2",
130
+ "leftRightRibbon",
131
+ "verticalScroll",
132
+ "horizontalScroll",
133
+ "wave",
134
+ "doubleWave",
135
+ "plus",
136
+ "flowChartProcess",
137
+ "flowChartDecision",
138
+ "flowChartInputOutput",
139
+ "flowChartPredefinedProcess",
140
+ "flowChartInternalStorage",
141
+ "flowChartDocument",
142
+ "flowChartMultidocument",
143
+ "flowChartTerminator",
144
+ "flowChartPreparation",
145
+ "flowChartManualInput",
146
+ "flowChartManualOperation",
147
+ "flowChartConnector",
148
+ "flowChartPunchedCard",
149
+ "flowChartPunchedTape",
150
+ "flowChartSummingJunction",
151
+ "flowChartOr",
152
+ "flowChartCollate",
153
+ "flowChartSort",
154
+ "flowChartExtract",
155
+ "flowChartMerge",
156
+ "flowChartOfflineStorage",
157
+ "flowChartOnlineStorage",
158
+ "flowChartMagneticTape",
159
+ "flowChartMagneticDisk",
160
+ "flowChartMagneticDrum",
161
+ "flowChartDisplay",
162
+ "flowChartDelay",
163
+ "flowChartAlternateProcess",
164
+ "flowChartOffpageConnector",
165
+ "actionButtonBlank",
166
+ "actionButtonHome",
167
+ "actionButtonHelp",
168
+ "actionButtonInformation",
169
+ "actionButtonForwardNext",
170
+ "actionButtonBackPrevious",
171
+ "actionButtonEnd",
172
+ "actionButtonBeginning",
173
+ "actionButtonReturn",
174
+ "actionButtonDocument",
175
+ "actionButtonSound",
176
+ "actionButtonMovie",
177
+ "gear6",
178
+ "gear9",
179
+ "funnel",
180
+ "mathPlus",
181
+ "mathMinus",
182
+ "mathMultiply",
183
+ "mathDivide",
184
+ "mathEqual",
185
+ "mathNotEqual",
186
+ "cornerTabs",
187
+ "squareTabs",
188
+ "plaqueTabs",
189
+ "chartX",
190
+ "chartStar",
191
+ "chartPlus"
192
+ ];
193
+ const presetGeometryNameSchema = z.enum(presetGeometryTuple);
194
+ const geometryAdjustKeySchema = z.string().regex(/^adj(?:[1-9]\d*)?$/u, "Geometry adjust key must match adj or adjN");
195
+ const geometryAdjustSchema = z.record(geometryAdjustKeySchema, z.number().refine(Number.isSafeInteger, "Geometry adjust must be an integer DrawingML parameter")).readonly();
196
+ const presetGeometrySchema = z.strictObject({
197
+ type: z.literal("preset"),
198
+ name: presetGeometryNameSchema,
199
+ /** Raw DrawingML adjust values indexed by guide name (adj, adj1, adj2, etc.). */
200
+ adjust: geometryAdjustSchema.optional()
201
+ }).readonly();
202
+ const finiteCoordSchema = z.number().finite();
203
+ const pathCommandSchema = z.discriminatedUnion("op", [
204
+ z.strictObject({
205
+ op: z.literal("M"),
206
+ x: finiteCoordSchema,
207
+ y: finiteCoordSchema
208
+ }).readonly(),
209
+ z.strictObject({
210
+ op: z.literal("L"),
211
+ x: finiteCoordSchema,
212
+ y: finiteCoordSchema
213
+ }).readonly(),
214
+ z.strictObject({
215
+ op: z.literal("C"),
216
+ x1: finiteCoordSchema,
217
+ y1: finiteCoordSchema,
218
+ x2: finiteCoordSchema,
219
+ y2: finiteCoordSchema,
220
+ x: finiteCoordSchema,
221
+ y: finiteCoordSchema
222
+ }).readonly(),
223
+ z.strictObject({
224
+ op: z.literal("Q"),
225
+ x1: finiteCoordSchema,
226
+ y1: finiteCoordSchema,
227
+ x: finiteCoordSchema,
228
+ y: finiteCoordSchema
229
+ }).readonly(),
230
+ z.strictObject({ op: z.literal("Z") }).readonly()
231
+ ]);
232
+ const geometryPathSchema = z.strictObject({
233
+ commands: z.array(pathCommandSchema).min(1).readonly(),
234
+ fill: z.boolean().optional(),
235
+ stroke: z.boolean().optional()
236
+ }).readonly();
237
+ /** Custom geometry uses local coordinates and scales to the bounding box allocated by layout. */
238
+ const customGeometrySchema = z.strictObject({
239
+ type: z.literal("custom"),
240
+ width: z.number().finite().positive(),
241
+ height: z.number().finite().positive(),
242
+ paths: z.array(geometryPathSchema).min(1).readonly()
243
+ }).readonly();
244
+ const geometrySchema = z.union([
245
+ presetGeometryNameSchema,
246
+ presetGeometrySchema,
247
+ customGeometrySchema
248
+ ]);
249
+ export { customGeometrySchema, geometryAdjustKeySchema, geometryAdjustSchema, geometryPathSchema, geometrySchema, pathCommandSchema, presetGeometryNameSchema, presetGeometrySchema, presetGeometryTuple };
@@ -0,0 +1,445 @@
1
+ import { BuildError } from "./diagnostics.js";
2
+ import { expandedSpacing, resolvePercent } from "./layout-protocol.js";
3
+ // ../core/dist/grid-layout.js
4
+ const gridContainerProperties = [
5
+ "gridTemplateColumns",
6
+ "gridTemplateRows",
7
+ "gridAutoRows",
8
+ "justifyItems"
9
+ ];
10
+ const gridItemProperties = [
11
+ "gridColumn",
12
+ "gridRow",
13
+ "justifySelf"
14
+ ];
15
+ function fail(path, code, message) {
16
+ throw new BuildError([{
17
+ severity: "error",
18
+ path,
19
+ code,
20
+ message
21
+ }]);
22
+ }
23
+ function gridTokens(input, path) {
24
+ const tokens = [];
25
+ let depth = 0;
26
+ let current = "";
27
+ for (const character of input.trim()) {
28
+ if (character === "(") depth += 1;
29
+ if (character === ")") depth -= 1;
30
+ if (depth < 0) fail(path, "invalid-grid-tracks", "Mismatched parentheses in grid tracks");
31
+ if (/\s/u.test(character) && depth === 0) {
32
+ if (current !== "") tokens.push(current);
33
+ current = "";
34
+ } else current += character;
35
+ }
36
+ if (depth !== 0) fail(path, "invalid-grid-tracks", "Mismatched parentheses in grid tracks");
37
+ if (current !== "") tokens.push(current);
38
+ return tokens;
39
+ }
40
+ function parseGridPixels(token, path) {
41
+ const match = /^(\d+(?:\.\d+)?)(?:px)?$/u.exec(token);
42
+ if (match === null) fail(path, "invalid-grid-tracks", `Unsupported grid track ${token}`);
43
+ return Number(match[1]);
44
+ }
45
+ function parseGridBasicTrack(token, path) {
46
+ if (token === "auto") return {
47
+ kind: "auto",
48
+ min: 0
49
+ };
50
+ const fraction = /^(\d+(?:\.\d+)?)fr$/u.exec(token);
51
+ if (fraction !== null) {
52
+ const value = Number(fraction[1]);
53
+ if (value <= 0) fail(path, "invalid-grid-tracks", "fr track fraction must be greater than 0");
54
+ return {
55
+ kind: "fr",
56
+ value,
57
+ min: 0
58
+ };
59
+ }
60
+ return {
61
+ kind: "px",
62
+ value: parseGridPixels(token, path)
63
+ };
64
+ }
65
+ function gridTracks(input, path, defaultFr) {
66
+ if (input === void 0 || input.trim() === "") return defaultFr ? [{
67
+ kind: "fr",
68
+ value: 1,
69
+ min: 0
70
+ }] : [];
71
+ const parseOne = (token) => {
72
+ const repeat = /^repeat\(\s*(\d+)\s*,\s*(.+)\)$/u.exec(token);
73
+ if (repeat !== null) {
74
+ const count = Number(repeat[1]);
75
+ if (!Number.isInteger(count) || count < 1 || count > 128) fail(path, "invalid-grid-tracks", "repeat count must be an integer between 1 and 128");
76
+ const repeated = gridTokens(repeat[2], path).flatMap(parseOne);
77
+ if (repeated.length * count > 128) fail(path, "invalid-grid-tracks", "Expanded grid tracks cannot exceed 128 tracks");
78
+ return Array.from({ length: count }, () => repeated).flat();
79
+ }
80
+ const minmax = /^minmax\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)$/u.exec(token);
81
+ if (minmax !== null) {
82
+ const lower = minmax[1].trim();
83
+ const minValue = lower === "auto" ? 0 : parseGridPixels(lower, path);
84
+ const maximum = parseGridBasicTrack(minmax[2].trim(), path);
85
+ if (maximum.kind === "fr") return [{
86
+ ...maximum,
87
+ min: Math.max(minValue, maximum.min),
88
+ contentMinimum: lower === "auto"
89
+ }];
90
+ if (maximum.kind === "auto") return [{
91
+ kind: "auto",
92
+ min: minValue
93
+ }];
94
+ return [{
95
+ kind: "px",
96
+ value: Math.max(minValue, maximum.value)
97
+ }];
98
+ }
99
+ return [parseGridBasicTrack(token, path)];
100
+ };
101
+ const tracks = gridTokens(input, path).flatMap(parseOne);
102
+ if (tracks.length === 0 || tracks.length > 128) fail(path, "invalid-grid-tracks", "Grid tracks must contain between 1 and 128 tracks");
103
+ return tracks;
104
+ }
105
+ function gridAutoRowTracks(input, path) {
106
+ if (input === void 0) return [{
107
+ kind: "auto",
108
+ min: 0
109
+ }];
110
+ const tracks = gridTracks(input, path, false);
111
+ if (tracks.length === 0) fail(path, "invalid-grid-tracks", "gridAutoRows must contain at least 1 track");
112
+ return tracks;
113
+ }
114
+ function rowTrackGrowsWithContent(track) {
115
+ return track.kind === "auto" || track.kind === "fr" && track.contentMinimum === true;
116
+ }
117
+ function distributeFrTracks(sizes, tracks, availableSize, gap) {
118
+ const trackAt = (index) => tracks[index] ?? {
119
+ kind: "auto",
120
+ min: 0
121
+ };
122
+ const flexible = new Set(sizes.flatMap((_, index) => trackAt(index).kind === "fr" ? [index] : []));
123
+ if (flexible.size === 0) return;
124
+ const gapSize = gap * Math.max(0, sizes.length - 1);
125
+ const fixedSize = sizes.reduce((sum, size, index) => sum + (trackAt(index).kind === "fr" ? 0 : size), 0);
126
+ while (flexible.size > 0) {
127
+ const factorTotal = [...flexible].reduce((sum, index) => {
128
+ const track = trackAt(index);
129
+ return sum + (track.kind === "fr" ? track.value : 0);
130
+ }, 0);
131
+ const frozenSize = sizes.reduce((sum, size, index) => sum + (flexible.has(index) ? 0 : trackAt(index).kind === "fr" ? size : 0), 0);
132
+ const freeSize = Math.max(0, availableSize - fixedSize - gapSize - frozenSize);
133
+ const undersized = [...flexible].filter((index) => {
134
+ const track = trackAt(index);
135
+ return track.kind === "fr" && freeSize * (track.value / factorTotal) < (sizes[index] ?? track.min);
136
+ });
137
+ if (undersized.length > 0) {
138
+ for (const index of undersized) flexible.delete(index);
139
+ continue;
140
+ }
141
+ for (const index of flexible) {
142
+ const track = trackAt(index);
143
+ if (track.kind === "fr") sizes[index] = freeSize * (track.value / factorTotal);
144
+ }
145
+ return;
146
+ }
147
+ }
148
+ function gridPlacement(value, path) {
149
+ if (value === void 0) return { span: 1 };
150
+ const positiveIndex = (raw) => {
151
+ const result = Number(raw);
152
+ if (!Number.isInteger(result) || result < 1) fail(path, "invalid-grid-placement", "Grid line numbers must be positive integers");
153
+ return result - 1;
154
+ };
155
+ if (typeof value === "number") {
156
+ if (!Number.isInteger(value) || value < 1) fail(path, "invalid-grid-placement", "Grid line numbers must be positive integers");
157
+ return {
158
+ start: value - 1,
159
+ span: 1
160
+ };
161
+ }
162
+ const text = value.trim();
163
+ let match = /^span\s+(\d+)$/u.exec(text);
164
+ if (match !== null) {
165
+ const span = Number(match[1]);
166
+ if (span < 1) fail(path, "invalid-grid-placement", "Grid span must be a positive integer");
167
+ return { span };
168
+ }
169
+ match = /^(\d+)\s*\/\s*span\s+(\d+)$/u.exec(text);
170
+ if (match !== null) {
171
+ const span = Number(match[2]);
172
+ if (span < 1) fail(path, "invalid-grid-placement", "Grid span must be a positive integer");
173
+ return {
174
+ start: positiveIndex(match[1]),
175
+ span
176
+ };
177
+ }
178
+ match = /^(\d+)\s*\/\s*(\d+)$/u.exec(text);
179
+ if (match !== null) {
180
+ const start = positiveIndex(match[1]);
181
+ const end = positiveIndex(match[2]);
182
+ if (end <= start) fail(path, "invalid-grid-placement", "Grid end line number must be greater than start line number");
183
+ return {
184
+ start,
185
+ span: end - start
186
+ };
187
+ }
188
+ if (/^\d+$/u.test(text)) return {
189
+ start: positiveIndex(text),
190
+ span: 1
191
+ };
192
+ return fail(path, "invalid-grid-placement", `Unsupported grid placement ${value}`);
193
+ }
194
+ function gridAlignment(value) {
195
+ if (value === "center") return "center";
196
+ if (value === "end" || value === "flex-end") return "end";
197
+ if (value === "stretch") return "stretch";
198
+ return "start";
199
+ }
200
+ function validateGridContainerStyle(value, resolvedDisplay, path) {
201
+ if (resolvedDisplay === "grid" && value["alignItems"] === "baseline") fail(path, "unsupported-grid-alignment", "Grid containers do not support baseline alignment");
202
+ for (const key of gridContainerProperties) if (value[key] !== void 0 && resolvedDisplay !== "grid") fail(path, "invalid-layout-context", `${key} is only applicable to display: "grid" containers`);
203
+ }
204
+ function validateGridStyleValues() {}
205
+ function validateGridItemStyle(style, parentStyle, path) {
206
+ if (parentStyle.display === "grid" && style.position === "absolute" && (style.alignSelf !== void 0 || style.justifySelf !== void 0 || style.gridColumn !== void 0 || style.gridRow !== void 0)) fail(path, "unsupported-grid-positioning", "Absolutely positioned grid items currently do not support grid placement or self alignment");
207
+ if (parentStyle.display === "grid" && style.position !== "absolute" && style.alignSelf === "baseline") fail(path, "unsupported-grid-alignment", "Grid items do not support baseline alignment");
208
+ }
209
+ function computeGridPlacements(node, explicitColumns) {
210
+ const columns = [...explicitColumns];
211
+ const children = node.children.filter((child) => child.style.position !== "absolute");
212
+ const occupied = /* @__PURE__ */ new Set();
213
+ const placements = [];
214
+ let cursorRow = 0;
215
+ let cursorColumn = 0;
216
+ const ensureColumns = (count) => {
217
+ if (count > 128) fail(node.path, "invalid-grid-placement", "Implicit grid columns cannot exceed 128 columns");
218
+ while (columns.length < count) columns.push({
219
+ kind: "auto",
220
+ min: 0
221
+ });
222
+ };
223
+ for (const child of children) {
224
+ const column = gridPlacement(child.style.gridColumn, child.path);
225
+ const row = gridPlacement(child.style.gridRow, child.path);
226
+ const columnSpan = column.span;
227
+ if (column.start !== void 0) ensureColumns(column.start + columnSpan);
228
+ else if (columnSpan > columns.length) ensureColumns(columnSpan);
229
+ let currentRow = row.start ?? cursorRow;
230
+ let currentColumn = column.start ?? cursorColumn;
231
+ if (row.start === void 0 && column.start !== void 0 && column.start < cursorColumn) currentRow += 1;
232
+ const fits = (rowIndex, columnIndex) => {
233
+ if (row.start === void 0 && column.start === void 0) {
234
+ if (columnIndex + columnSpan > columns.length) return false;
235
+ } else ensureColumns(columnIndex + columnSpan);
236
+ for (let rowOffset = 0; rowOffset < row.span; rowOffset += 1) for (let columnOffset = 0; columnOffset < columnSpan; columnOffset += 1) if (occupied.has(`${rowIndex + rowOffset}:${columnIndex + columnOffset}`)) return false;
237
+ return true;
238
+ };
239
+ if (!(row.start !== void 0 && column.start !== void 0)) while (!fits(currentRow, currentColumn)) if (column.start !== void 0) currentRow += 1;
240
+ else {
241
+ currentColumn += 1;
242
+ if (currentColumn + columnSpan > columns.length) {
243
+ currentColumn = 0;
244
+ currentRow += 1;
245
+ }
246
+ }
247
+ if (currentRow + row.span > 128) fail(child.path, "invalid-grid-placement", "Implicit grid rows cannot exceed 128 rows");
248
+ for (let rowOffset = 0; rowOffset < row.span; rowOffset += 1) for (let columnOffset = 0; columnOffset < columnSpan; columnOffset += 1) occupied.add(`${currentRow + rowOffset}:${currentColumn + columnOffset}`);
249
+ placements.push({
250
+ node: child,
251
+ row: currentRow,
252
+ column: currentColumn,
253
+ rowSpan: row.span,
254
+ columnSpan
255
+ });
256
+ if (row.start === void 0) {
257
+ cursorRow = currentRow;
258
+ cursorColumn = currentColumn + columnSpan;
259
+ }
260
+ }
261
+ return {
262
+ placements,
263
+ columns
264
+ };
265
+ }
266
+ function buildGridModel(node, innerWidth, innerHeight, port) {
267
+ const columnTracks = gridTracks(node.style.gridTemplateColumns, node.path, true);
268
+ const rowTracks = gridTracks(node.style.gridTemplateRows, node.path, false);
269
+ const autoRowTracks = gridAutoRowTracks(node.style.gridAutoRows, node.path);
270
+ const { placements, columns } = computeGridPlacements(node, columnTracks);
271
+ const columnGap = node.style.columnGap ?? node.style.gap ?? 0;
272
+ const rowGap = node.style.rowGap ?? node.style.gap ?? 0;
273
+ const rowCount = Math.max(rowTracks.length, ...placements.map((placement) => placement.row + placement.rowSpan), 0);
274
+ const rowTrackAt = (index) => rowTracks[index] ?? autoRowTracks[(index - rowTracks.length) % autoRowTracks.length];
275
+ const minContentWidth = (item) => port.measureMinContentContribution(item, "width");
276
+ const columnWidths = columns.map((track) => track.kind === "px" ? track.value : track.min);
277
+ for (const placement of placements) {
278
+ if (placement.columnSpan !== 1) continue;
279
+ const track = columns[placement.column];
280
+ if (track === void 0 || track.kind === "px" || track.kind === "fr" && track.contentMinimum !== true) continue;
281
+ columnWidths[placement.column] = Math.max(columnWidths[placement.column] ?? 0, Math.max(track.min, minContentWidth(placement.node)));
282
+ }
283
+ const columnSpanWidth = (start, span) => columnWidths.slice(start, start + span).reduce((sum, width) => sum + width, 0) + columnGap * Math.max(0, span - 1);
284
+ for (const placement of placements) {
285
+ if (placement.columnSpan === 1) continue;
286
+ const missing = minContentWidth(placement.node) - columnSpanWidth(placement.column, placement.columnSpan);
287
+ if (missing <= 0) continue;
288
+ const growable = Array.from({ length: placement.columnSpan }, (_, index) => placement.column + index).filter((index) => columns[index]?.kind === "auto" || columns[index]?.kind === "fr" && columns[index]?.contentMinimum === true);
289
+ if (growable.length === 0) continue;
290
+ for (const index of growable) columnWidths[index] = (columnWidths[index] ?? 0) + missing / growable.length;
291
+ }
292
+ if (innerWidth !== void 0) distributeFrTracks(columnWidths, columns, innerWidth, columnGap);
293
+ const spanWidth = (start, span) => columnWidths.slice(start, start + span).reduce((sum, width) => sum + width, 0) + columnGap * Math.max(0, span - 1);
294
+ const rowHeights = Array.from({ length: rowCount }, (_, index) => {
295
+ const track = rowTrackAt(index);
296
+ return track.kind === "px" ? track.value : track.min;
297
+ });
298
+ for (const placement of placements) {
299
+ if (placement.rowSpan !== 1) continue;
300
+ const track = rowTrackAt(placement.row);
301
+ if (!rowTrackGrowsWithContent(track)) continue;
302
+ const margin = expandedSpacing(placement.node.style, "margin");
303
+ const size = port.measureNaturalSize(placement.node, spanWidth(placement.column, placement.columnSpan));
304
+ rowHeights[placement.row] = Math.max(rowHeights[placement.row] ?? 0, track.min, size.height + margin.top + margin.bottom);
305
+ }
306
+ const spanHeight = (start, span) => rowHeights.slice(start, start + span).reduce((sum, height) => sum + height, 0) + rowGap * Math.max(0, span - 1);
307
+ for (const placement of placements) {
308
+ if (placement.rowSpan === 1) continue;
309
+ const natural = port.measureNaturalSize(placement.node, spanWidth(placement.column, placement.columnSpan));
310
+ const margin = expandedSpacing(placement.node.style, "margin");
311
+ const missing = natural.height + margin.top + margin.bottom - spanHeight(placement.row, placement.rowSpan);
312
+ if (missing <= 0) continue;
313
+ const growable = Array.from({ length: placement.rowSpan }, (_, index) => placement.row + index).filter((index) => rowTrackGrowsWithContent(rowTrackAt(index)));
314
+ if (growable.length === 0) continue;
315
+ for (const index of growable) rowHeights[index] = (rowHeights[index] ?? 0) + missing / growable.length;
316
+ }
317
+ if (innerHeight !== void 0) distributeFrTracks(rowHeights, Array.from({ length: rowCount }, (_, index) => rowTrackAt(index)), innerHeight, rowGap);
318
+ const spanHeightFinal = (start, span) => rowHeights.slice(start, start + span).reduce((sum, height) => sum + height, 0) + rowGap * Math.max(0, span - 1);
319
+ return {
320
+ placements,
321
+ widths: columnWidths,
322
+ heights: rowHeights,
323
+ columnGap,
324
+ rowGap,
325
+ spanWidth,
326
+ spanHeight: spanHeightFinal,
327
+ width: spanWidth(0, columnWidths.length),
328
+ height: rowCount === 0 ? 0 : spanHeightFinal(0, rowCount)
329
+ };
330
+ }
331
+ /**
332
+ * Creates the Grid container solver collaborating strictly through `LayoutSolverPort`.
333
+ */
334
+ function createGridContainerSolver(warnOnce) {
335
+ return {
336
+ handlesDisplay(display) {
337
+ return display === "grid";
338
+ },
339
+ measureMinContent(node, axis, port) {
340
+ const model = buildGridModel(node, void 0, void 0, port);
341
+ const padding = expandedSpacing(node.style, "padding");
342
+ return (axis === "width" ? model.width : model.height) + (axis === "width" ? padding.left + padding.right : padding.top + padding.bottom);
343
+ },
344
+ placeContainer(node, port) {
345
+ if (node.style.display !== "grid") return;
346
+ const padding = expandedSpacing(node.style, "padding");
347
+ const computed = port.getComputedSize(node);
348
+ const outerWidth = computed.width;
349
+ const outerHeight = computed.height || port.getAllocatedHeight(node) || 0;
350
+ const hasWidth = node.isRoot || node.style.width !== void 0 && node.style.width !== "auto";
351
+ const hasResolvedHeight = node.isRoot || node.style.height !== void 0 && node.style.height !== "auto" || outerHeight > 0;
352
+ const innerWidth = outerWidth > 0 ? Math.max(0, outerWidth - padding.left - padding.right) : void 0;
353
+ const innerHeight = hasResolvedHeight ? Math.max(0, outerHeight - padding.top - padding.bottom) : void 0;
354
+ const model = buildGridModel(node, innerWidth, innerHeight, port);
355
+ if (innerWidth !== void 0 && model.width > innerWidth + .01) warnOnce(node.path, "grid-overflow", `Grid columns minimum size total ${model.width}px exceeds available width ${innerWidth}px; build retains track dimensions`);
356
+ if (innerHeight !== void 0 && model.height > innerHeight + .01) warnOnce(node.path, "grid-overflow", `Grid rows minimum size total ${model.height}px exceeds available height ${innerHeight}px; build retains track dimensions`);
357
+ port.setContainerSize(node, {
358
+ ...!hasWidth && outerWidth <= 0 ? { width: model.width + padding.left + padding.right } : {},
359
+ ...!hasResolvedHeight ? { height: model.height + padding.top + padding.bottom } : {}
360
+ });
361
+ for (const placement of model.placements) {
362
+ const child = placement.node;
363
+ const childStyle = child.style;
364
+ const cellWidth = model.spanWidth(placement.column, placement.columnSpan);
365
+ const cellHeight = model.spanHeight(placement.row, placement.rowSpan);
366
+ const cellX = padding.left + model.spanWidth(0, placement.column) + (placement.column > 0 ? model.columnGap : 0);
367
+ const cellY = padding.top + model.spanHeight(0, placement.row) + (placement.row > 0 ? model.rowGap : 0);
368
+ const margin = expandedSpacing(childStyle, "margin");
369
+ const availableWidth = Math.max(0, cellWidth - margin.left - margin.right);
370
+ const availableHeight = Math.max(0, cellHeight - margin.top - margin.bottom);
371
+ const justify = gridAlignment(childStyle.justifySelf === void 0 || childStyle.justifySelf === "auto" ? node.style.justifyItems ?? "stretch" : childStyle.justifySelf);
372
+ const alignValue = childStyle.alignSelf === void 0 || childStyle.alignSelf === "auto" ? node.style.alignItems ?? "stretch" : childStyle.alignSelf;
373
+ if (alignValue === "baseline") fail(child.path, "unsupported-grid-alignment", "Text baseline alignment in grid does not yet have a reliable row baseline");
374
+ const align = gridAlignment(alignValue);
375
+ const declaredWidth = childStyle.width ?? child.contractWidth;
376
+ const declaredHeight = childStyle.height ?? child.contractHeight;
377
+ const widthPercent = resolvePercent(declaredWidth, cellWidth);
378
+ const heightPercent = resolvePercent(declaredHeight, cellHeight);
379
+ const widthSpecified = declaredWidth !== void 0 && declaredWidth !== "auto";
380
+ let heightSpecified = declaredHeight !== void 0 && declaredHeight !== "auto";
381
+ const minWidth = resolvePercent(childStyle.minWidth, cellWidth);
382
+ const maxWidth = resolvePercent(childStyle.maxWidth, cellWidth);
383
+ const minHeight = resolvePercent(childStyle.minHeight, cellHeight);
384
+ const maxHeight = resolvePercent(childStyle.maxHeight, cellHeight);
385
+ let initialHeightConstraint;
386
+ if (heightPercent !== void 0 && availableHeight > 0) initialHeightConstraint = heightPercent;
387
+ else if (heightPercent !== void 0) {
388
+ initialHeightConstraint = "auto";
389
+ heightSpecified = false;
390
+ }
391
+ port.setChildConstraints(child, {
392
+ ...widthPercent === void 0 ? {} : { width: widthPercent },
393
+ ...initialHeightConstraint === void 0 ? {} : { height: initialHeightConstraint },
394
+ ...minWidth === void 0 ? {} : { minWidth },
395
+ ...maxWidth === void 0 ? {} : { maxWidth },
396
+ ...minHeight === void 0 ? {} : { minHeight },
397
+ ...maxHeight === void 0 ? {} : { maxHeight }
398
+ });
399
+ const intrinsic = port.measureNaturalSize(child, typeof declaredWidth === "string" && declaredWidth.endsWith("%") ? cellWidth : void 0);
400
+ let width = widthSpecified ? intrinsic.width : justify === "stretch" ? availableWidth : intrinsic.width;
401
+ if (childStyle.aspectRatio !== void 0 && heightSpecified && !widthSpecified) width = intrinsic.height * childStyle.aspectRatio;
402
+ if (!widthSpecified || widthPercent !== void 0) port.setChildConstraints(child, { width: Math.max(0, width) });
403
+ const naturalAtWidth = port.measureNaturalSize(child, width);
404
+ let height = heightSpecified ? naturalAtWidth.height : align === "stretch" && childStyle.aspectRatio === void 0 ? availableHeight : naturalAtWidth.height;
405
+ if (!heightSpecified && childStyle.aspectRatio === void 0) port.setChildConstraints(child, { height: Math.max(0, height) });
406
+ const finalSize = port.measureNaturalSize(child, width);
407
+ const usedWidth = finalSize.width || width;
408
+ const usedHeight = finalSize.height || height;
409
+ if (child.isContainer && !heightSpecified) port.setAllocatedHeight(child, height);
410
+ if (usedWidth > availableWidth + .01 || usedHeight > availableHeight + .01) warnOnce(child.path, "grid-item-overflow", "Grid item overflows its track area; build retains declared dimensions");
411
+ const xAlign = justify === "center" ? Math.max(0, (availableWidth - usedWidth) / 2) : justify === "end" ? Math.max(0, availableWidth - usedWidth) : 0;
412
+ const yAlign = align === "center" ? Math.max(0, (availableHeight - usedHeight) / 2) : align === "end" ? Math.max(0, availableHeight - usedHeight) : 0;
413
+ const relative = (start, end, basis) => {
414
+ const resolve = (value) => typeof value === "number" ? value : resolvePercent(value, basis);
415
+ return resolve(start) ?? -(resolve(end) ?? 0);
416
+ };
417
+ const dx = childStyle.position === "relative" ? relative(childStyle.left ?? childStyle.inset, childStyle.right ?? childStyle.inset, cellWidth) : 0;
418
+ const dy = childStyle.position === "relative" ? relative(childStyle.top ?? childStyle.inset, childStyle.bottom ?? childStyle.inset, cellHeight) : 0;
419
+ port.placeChild(child, {
420
+ x: cellX + xAlign + dx,
421
+ y: cellY + yAlign + dy
422
+ });
423
+ }
424
+ }
425
+ };
426
+ }
427
+ /**
428
+ * Ownership descriptor for Grid layout mode, registered with the core layout coordinator.
429
+ */
430
+ const gridLayoutMode = {
431
+ display: "grid",
432
+ containerStyleKeys: gridContainerProperties,
433
+ itemStyleKeys: gridItemProperties,
434
+ sharedContainerProperties: [
435
+ "alignItems",
436
+ "gap",
437
+ "rowGap",
438
+ "columnGap"
439
+ ],
440
+ validateContainerStyle: validateGridContainerStyle,
441
+ validateStyleValues: validateGridStyleValues,
442
+ validateItemStyle: validateGridItemStyle,
443
+ createSolver: createGridContainerSolver
444
+ };
445
+ export { createGridContainerSolver, gridLayoutMode };