@officedk/pptxdk 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { BuildError } from "./diagnostics.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// ../core/dist/layout-schemas.js
|
|
4
|
+
const percentPattern = /^(-?(?:\d+(?:\.\d*)?|\.\d+))%$/u;
|
|
5
|
+
const nonNegativePercentPattern = /^(\d+(?:\.\d*)?|\.\d+)%$/u;
|
|
6
|
+
const percentLengthSchema = z.string().regex(percentPattern, "must be a pixel number, percentage, or auto");
|
|
7
|
+
const nonNegativePercentLengthSchema = z.string().regex(nonNegativePercentPattern, "must be a non-negative pixel number, percentage, or auto");
|
|
8
|
+
const rawLayoutLengthSchema = z.union([
|
|
9
|
+
z.number().finite(),
|
|
10
|
+
percentLengthSchema,
|
|
11
|
+
z.literal("auto")
|
|
12
|
+
]);
|
|
13
|
+
/** Fixed canvas length; numeric values are interpreted in pixels, percentages are evaluated against the parent layout region. */
|
|
14
|
+
const layoutLengthSchema = rawLayoutLengthSchema;
|
|
15
|
+
const rawNonNegativeLayoutLengthSchema = z.union([
|
|
16
|
+
z.number().finite().nonnegative(),
|
|
17
|
+
nonNegativePercentLengthSchema,
|
|
18
|
+
z.literal("auto")
|
|
19
|
+
]);
|
|
20
|
+
const rawLayoutSpacingSchema = z.union([
|
|
21
|
+
z.number().finite(),
|
|
22
|
+
z.tuple([z.number().finite(), z.number().finite()]).readonly(),
|
|
23
|
+
z.tuple([
|
|
24
|
+
z.number().finite(),
|
|
25
|
+
z.number().finite(),
|
|
26
|
+
z.number().finite(),
|
|
27
|
+
z.number().finite()
|
|
28
|
+
]).readonly()
|
|
29
|
+
]);
|
|
30
|
+
const layoutSpacingSchema = rawLayoutSpacingSchema;
|
|
31
|
+
const rawNonNegativeLayoutSpacingSchema = z.union([
|
|
32
|
+
z.number().finite().nonnegative(),
|
|
33
|
+
z.tuple([z.number().finite().nonnegative(), z.number().finite().nonnegative()]).readonly(),
|
|
34
|
+
z.tuple([
|
|
35
|
+
z.number().finite().nonnegative(),
|
|
36
|
+
z.number().finite().nonnegative(),
|
|
37
|
+
z.number().finite().nonnegative(),
|
|
38
|
+
z.number().finite().nonnegative()
|
|
39
|
+
]).readonly()
|
|
40
|
+
]);
|
|
41
|
+
const nonNegativeLayoutSpacingSchema = rawNonNegativeLayoutSpacingSchema;
|
|
42
|
+
const paddingStyleObjectSchema = z.strictObject({
|
|
43
|
+
padding: rawNonNegativeLayoutSpacingSchema.optional(),
|
|
44
|
+
paddingTop: z.number().finite().nonnegative().optional(),
|
|
45
|
+
paddingRight: z.number().finite().nonnegative().optional(),
|
|
46
|
+
paddingBottom: z.number().finite().nonnegative().optional(),
|
|
47
|
+
paddingLeft: z.number().finite().nonnegative().optional()
|
|
48
|
+
});
|
|
49
|
+
const paddingStyleShape = paddingStyleObjectSchema.shape;
|
|
50
|
+
const paddingStyleSchema = paddingStyleObjectSchema.readonly();
|
|
51
|
+
const layoutDisplaySchema = z.enum([
|
|
52
|
+
"block",
|
|
53
|
+
"flex",
|
|
54
|
+
"grid",
|
|
55
|
+
"none"
|
|
56
|
+
]);
|
|
57
|
+
const layoutPositionSchema = z.enum([
|
|
58
|
+
"static",
|
|
59
|
+
"relative",
|
|
60
|
+
"absolute"
|
|
61
|
+
]);
|
|
62
|
+
const flexDirectionSchema = z.enum([
|
|
63
|
+
"row",
|
|
64
|
+
"column",
|
|
65
|
+
"row-reverse",
|
|
66
|
+
"column-reverse"
|
|
67
|
+
]);
|
|
68
|
+
const flexWrapSchema = z.enum(["nowrap", "wrap"]);
|
|
69
|
+
const justifyContentSchema = z.enum([
|
|
70
|
+
"start",
|
|
71
|
+
"end",
|
|
72
|
+
"center",
|
|
73
|
+
"flex-start",
|
|
74
|
+
"flex-end",
|
|
75
|
+
"space-between",
|
|
76
|
+
"space-around",
|
|
77
|
+
"space-evenly"
|
|
78
|
+
]);
|
|
79
|
+
const alignItemsSchema = z.enum([
|
|
80
|
+
"start",
|
|
81
|
+
"end",
|
|
82
|
+
"center",
|
|
83
|
+
"stretch",
|
|
84
|
+
"flex-start",
|
|
85
|
+
"flex-end",
|
|
86
|
+
"baseline"
|
|
87
|
+
]);
|
|
88
|
+
const alignSelfSchema = z.enum([
|
|
89
|
+
"auto",
|
|
90
|
+
"start",
|
|
91
|
+
"end",
|
|
92
|
+
"center",
|
|
93
|
+
"stretch",
|
|
94
|
+
"flex-start",
|
|
95
|
+
"flex-end",
|
|
96
|
+
"baseline"
|
|
97
|
+
]);
|
|
98
|
+
const alignContentSchema = z.enum([
|
|
99
|
+
"start",
|
|
100
|
+
"end",
|
|
101
|
+
"center",
|
|
102
|
+
"flex-start",
|
|
103
|
+
"flex-end",
|
|
104
|
+
"space-between",
|
|
105
|
+
"space-around",
|
|
106
|
+
"space-evenly",
|
|
107
|
+
"stretch"
|
|
108
|
+
]);
|
|
109
|
+
const justifyItemsSchema = z.enum([
|
|
110
|
+
"start",
|
|
111
|
+
"end",
|
|
112
|
+
"center",
|
|
113
|
+
"stretch",
|
|
114
|
+
"flex-start",
|
|
115
|
+
"flex-end"
|
|
116
|
+
]);
|
|
117
|
+
const justifySelfSchema = z.enum([
|
|
118
|
+
"auto",
|
|
119
|
+
"start",
|
|
120
|
+
"end",
|
|
121
|
+
"center",
|
|
122
|
+
"stretch",
|
|
123
|
+
"flex-start",
|
|
124
|
+
"flex-end"
|
|
125
|
+
]);
|
|
126
|
+
/** Fixed canvas CSS layout subset; numeric lengths are interpreted in pixels. */
|
|
127
|
+
const layoutStyleObjectSchema = z.strictObject({
|
|
128
|
+
display: layoutDisplaySchema.optional(),
|
|
129
|
+
position: layoutPositionSchema.optional(),
|
|
130
|
+
inset: rawLayoutLengthSchema.optional(),
|
|
131
|
+
left: rawLayoutLengthSchema.optional(),
|
|
132
|
+
top: rawLayoutLengthSchema.optional(),
|
|
133
|
+
right: rawLayoutLengthSchema.optional(),
|
|
134
|
+
bottom: rawLayoutLengthSchema.optional(),
|
|
135
|
+
width: rawNonNegativeLayoutLengthSchema.optional(),
|
|
136
|
+
height: rawNonNegativeLayoutLengthSchema.optional(),
|
|
137
|
+
minWidth: rawNonNegativeLayoutLengthSchema.optional(),
|
|
138
|
+
minHeight: rawNonNegativeLayoutLengthSchema.optional(),
|
|
139
|
+
maxWidth: rawNonNegativeLayoutLengthSchema.optional(),
|
|
140
|
+
maxHeight: rawNonNegativeLayoutLengthSchema.optional(),
|
|
141
|
+
margin: rawLayoutSpacingSchema.optional(),
|
|
142
|
+
marginTop: z.number().finite().optional(),
|
|
143
|
+
marginRight: z.number().finite().optional(),
|
|
144
|
+
marginBottom: z.number().finite().optional(),
|
|
145
|
+
marginLeft: z.number().finite().optional(),
|
|
146
|
+
padding: rawNonNegativeLayoutSpacingSchema.optional(),
|
|
147
|
+
paddingTop: z.number().finite().nonnegative().optional(),
|
|
148
|
+
paddingRight: z.number().finite().nonnegative().optional(),
|
|
149
|
+
paddingBottom: z.number().finite().nonnegative().optional(),
|
|
150
|
+
paddingLeft: z.number().finite().nonnegative().optional(),
|
|
151
|
+
gap: z.number().finite().nonnegative().optional(),
|
|
152
|
+
rowGap: z.number().finite().nonnegative().optional(),
|
|
153
|
+
columnGap: z.number().finite().nonnegative().optional(),
|
|
154
|
+
flexDirection: flexDirectionSchema.optional(),
|
|
155
|
+
flexWrap: flexWrapSchema.optional(),
|
|
156
|
+
justifyContent: justifyContentSchema.optional(),
|
|
157
|
+
alignItems: alignItemsSchema.optional(),
|
|
158
|
+
alignSelf: alignSelfSchema.optional(),
|
|
159
|
+
alignContent: alignContentSchema.optional(),
|
|
160
|
+
flex: z.number().finite().nonnegative().optional(),
|
|
161
|
+
flexGrow: z.number().finite().nonnegative().optional(),
|
|
162
|
+
flexShrink: z.number().finite().nonnegative().optional(),
|
|
163
|
+
flexBasis: rawNonNegativeLayoutLengthSchema.optional(),
|
|
164
|
+
aspectRatio: z.number().finite().positive().optional(),
|
|
165
|
+
gridTemplateColumns: z.string().optional(),
|
|
166
|
+
gridTemplateRows: z.string().optional(),
|
|
167
|
+
/** Track sizes for implicit Grid rows, cycling in order like CSS `grid-auto-rows`; defaults to `auto`. */
|
|
168
|
+
gridAutoRows: z.string().optional(),
|
|
169
|
+
gridColumn: z.union([z.number(), z.string()]).optional(),
|
|
170
|
+
gridRow: z.union([z.number(), z.string()]).optional(),
|
|
171
|
+
justifyItems: justifyItemsSchema.optional(),
|
|
172
|
+
justifySelf: justifySelfSchema.optional(),
|
|
173
|
+
zIndex: z.number().finite().optional()
|
|
174
|
+
});
|
|
175
|
+
const layoutStyleShape = layoutStyleObjectSchema.shape;
|
|
176
|
+
const layoutStyleSchema = layoutStyleObjectSchema.readonly();
|
|
177
|
+
const slideLayoutStyleObjectSchema = layoutStyleObjectSchema.omit({ zIndex: true });
|
|
178
|
+
const slideLayoutStyleShape = slideLayoutStyleObjectSchema.shape;
|
|
179
|
+
slideLayoutStyleObjectSchema.readonly();
|
|
180
|
+
const layoutSchemaKeys = new Set(Object.keys(layoutStyleObjectSchema.shape));
|
|
181
|
+
/**
|
|
182
|
+
* Validates pure value shapes of layout properties present in `style`, preserving existing
|
|
183
|
+
* BuildError diagnostic codes (`unsupported-layout-value` for enum mismatches, `invalid-layout-style`
|
|
184
|
+
* for invalid lengths, spacing, numbers, or grid track/placement types).
|
|
185
|
+
*/
|
|
186
|
+
function validateLayoutStyleValues(style, path) {
|
|
187
|
+
const layoutEntries = {};
|
|
188
|
+
for (const [key, value] of Object.entries(style)) if (layoutSchemaKeys.has(key) && value !== void 0) layoutEntries[key] = value;
|
|
189
|
+
const parsed = layoutStyleSchema.safeParse(layoutEntries);
|
|
190
|
+
if (parsed.success) return;
|
|
191
|
+
const issue = parsed.error.issues[0];
|
|
192
|
+
const key = typeof issue?.path[0] === "string" ? issue.path[0] : void 0;
|
|
193
|
+
const message = key === void 0 ? issue?.message ?? "Invalid layout style" : `${key}: ${issue?.message ?? "invalid value"}`;
|
|
194
|
+
throw new BuildError([{
|
|
195
|
+
code: "invalid-style",
|
|
196
|
+
path,
|
|
197
|
+
message,
|
|
198
|
+
...key === void 0 ? {} : { field: `style.${key}` }
|
|
199
|
+
}]);
|
|
200
|
+
}
|
|
201
|
+
export { alignContentSchema, alignItemsSchema, alignSelfSchema, flexDirectionSchema, flexWrapSchema, justifyContentSchema, justifyItemsSchema, justifySelfSchema, layoutDisplaySchema, layoutLengthSchema, layoutPositionSchema, layoutSpacingSchema, layoutStyleSchema, layoutStyleShape, nonNegativeLayoutSpacingSchema, paddingStyleSchema, paddingStyleShape, slideLayoutStyleShape, validateLayoutStyleValues };
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { blockFlexLayoutProperties, createBlockFlexLayoutSolver, isStyleRecord, paddingStyleKeys, validateBlockFlexContainerContext, validateBlockFlexContainerProperties, validateBlockFlexLayoutContextBounds } from "./block-flex-layout.js";
|
|
2
|
+
import { BuildError, CapabilityError, capabilityErrorToDiagnostic, toBuildDiagnostic } from "./diagnostics.js";
|
|
3
|
+
import { gridLayoutMode } from "./grid-layout.js";
|
|
4
|
+
import { expandedSpacing } from "./layout-protocol.js";
|
|
5
|
+
import { validateLayoutStyleValues } from "./layout-schemas.js";
|
|
6
|
+
import { textStyleKeys } from "./theme.js";
|
|
7
|
+
// ../core/dist/layout.js
|
|
8
|
+
function roundLayoutMetric(value) {
|
|
9
|
+
const rounded = Math.round(value * 100) / 100;
|
|
10
|
+
return Object.is(rounded, -0) ? 0 : rounded;
|
|
11
|
+
}
|
|
12
|
+
function roundRect(box) {
|
|
13
|
+
return {
|
|
14
|
+
x: roundLayoutMetric(box.x),
|
|
15
|
+
y: roundLayoutMetric(box.y),
|
|
16
|
+
width: roundLayoutMetric(box.width),
|
|
17
|
+
height: roundLayoutMetric(box.height)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const customContainerModes = [gridLayoutMode];
|
|
21
|
+
const layoutProperties = [...blockFlexLayoutProperties, ...customContainerModes.flatMap((mode) => [...mode.containerStyleKeys, ...mode.itemStyleKeys])];
|
|
22
|
+
const layoutPropertySet = new Set(layoutProperties);
|
|
23
|
+
layoutProperties.filter((key) => !paddingStyleKeys.includes(key));
|
|
24
|
+
function diagnostic(path, code, message, details) {
|
|
25
|
+
return toBuildDiagnostic(path, code, message, details);
|
|
26
|
+
}
|
|
27
|
+
function fail(path, code, message, details) {
|
|
28
|
+
throw new BuildError([diagnostic(path, code, message, details)]);
|
|
29
|
+
}
|
|
30
|
+
function element(child) {
|
|
31
|
+
return "props" in child;
|
|
32
|
+
}
|
|
33
|
+
function identity(element) {
|
|
34
|
+
const id = element.props["id"];
|
|
35
|
+
return typeof id === "string" && id.trim() !== "" ? id : void 0;
|
|
36
|
+
}
|
|
37
|
+
function label(element, index) {
|
|
38
|
+
return `${element.type}[${identity(element) ?? String(index + 1)}]`;
|
|
39
|
+
}
|
|
40
|
+
function readStyle(value, path, isContainer, allowsPadding = isContainer, allowedPresentation = /* @__PURE__ */ new Set()) {
|
|
41
|
+
if (value === void 0) return {};
|
|
42
|
+
if (!isStyleRecord(value)) fail(path, "invalid-style", "style must be an object", { field: "style" });
|
|
43
|
+
const unknown = Object.keys(value).find((key) => !layoutPropertySet.has(key) && !allowedPresentation.has(key));
|
|
44
|
+
if (unknown !== void 0) fail(path, "unknown-style", `style contains unsupported property ${unknown}`, {
|
|
45
|
+
prop: unknown,
|
|
46
|
+
field: `style.${unknown}`,
|
|
47
|
+
scope: "style"
|
|
48
|
+
});
|
|
49
|
+
const resolvedDisplay = validateBlockFlexContainerContext(value, path, isContainer, customContainerModes);
|
|
50
|
+
validateBlockFlexContainerProperties(value, resolvedDisplay, path, customContainerModes);
|
|
51
|
+
for (const mode of customContainerModes) mode.validateContainerStyle(value, resolvedDisplay, path);
|
|
52
|
+
validateLayoutStyleValues(value, path);
|
|
53
|
+
for (const mode of customContainerModes) mode.validateStyleValues(value, path);
|
|
54
|
+
validateBlockFlexLayoutContextBounds(value, allowsPadding, path);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
function hasOppositeOffsets(style, startKey, endKey) {
|
|
58
|
+
if (style.position !== "absolute") return false;
|
|
59
|
+
const start = style[startKey] ?? style.inset;
|
|
60
|
+
const end = style[endKey] ?? style.inset;
|
|
61
|
+
return start !== void 0 && start !== "auto" && end !== void 0 && end !== "auto";
|
|
62
|
+
}
|
|
63
|
+
function computeFixedAxes(style) {
|
|
64
|
+
return {
|
|
65
|
+
width: style.width !== void 0 && style.width !== "auto" || hasOppositeOffsets(style, "left", "right"),
|
|
66
|
+
height: style.height !== void 0 && style.height !== "auto" || hasOppositeOffsets(style, "top", "bottom")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function computeExplicitPixelSize(style) {
|
|
70
|
+
const width = typeof style.width === "number" && Number.isFinite(style.width) ? style.width : void 0;
|
|
71
|
+
const height = typeof style.height === "number" && Number.isFinite(style.height) ? style.height : void 0;
|
|
72
|
+
return {
|
|
73
|
+
...width === void 0 ? {} : { width },
|
|
74
|
+
...height === void 0 ? {} : { height }
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function computeLayoutSizedAxes(contract, parentStyle) {
|
|
78
|
+
const style = contract.layoutStyle;
|
|
79
|
+
const fixed = contract.fixedAxes ?? computeFixedAxes(style);
|
|
80
|
+
let width = fixed.width;
|
|
81
|
+
let height = fixed.height;
|
|
82
|
+
if (style.position !== "absolute") {
|
|
83
|
+
if (parentStyle.display === "flex") {
|
|
84
|
+
const direction = parentStyle.flexDirection ?? "row";
|
|
85
|
+
const isRow = direction === "row" || direction === "row-reverse";
|
|
86
|
+
const isMainFlexSized = style.flex !== void 0 || style.flexGrow !== void 0 && style.flexGrow > 0 || style.flexBasis !== void 0 && style.flexBasis !== "auto";
|
|
87
|
+
const isCrossStretched = (style.alignSelf === void 0 || style.alignSelf === "auto" ? parentStyle.alignItems ?? "stretch" : style.alignSelf) === "stretch";
|
|
88
|
+
if (isRow) {
|
|
89
|
+
width ||= isMainFlexSized;
|
|
90
|
+
height ||= isCrossStretched;
|
|
91
|
+
} else {
|
|
92
|
+
height ||= isMainFlexSized;
|
|
93
|
+
width ||= isCrossStretched;
|
|
94
|
+
}
|
|
95
|
+
} else if (parentStyle.display === "grid") {
|
|
96
|
+
const effectiveJustify = style.justifySelf === void 0 || style.justifySelf === "auto" ? parentStyle.justifyItems ?? "stretch" : style.justifySelf;
|
|
97
|
+
const effectiveAlign = style.alignSelf === void 0 || style.alignSelf === "auto" ? parentStyle.alignItems ?? "stretch" : style.alignSelf;
|
|
98
|
+
if (effectiveJustify === "stretch") width = true;
|
|
99
|
+
if (effectiveAlign === "stretch" && style.aspectRatio === void 0) height = true;
|
|
100
|
+
} else if (!contract.preservesIntrinsicSize) width = true;
|
|
101
|
+
}
|
|
102
|
+
if (style.aspectRatio !== void 0) {
|
|
103
|
+
if (width && !height) height = true;
|
|
104
|
+
else if (height && !width) width = true;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
width,
|
|
108
|
+
height
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parses and validates host props into a CapabilityLayoutContract for object capabilities.
|
|
113
|
+
*/
|
|
114
|
+
function parseCapabilityLayoutContract(options) {
|
|
115
|
+
const { nativeKind, props, allowedStyleKeys, allowPadding = false, isContainer = false, excludedFromLayout = false } = options;
|
|
116
|
+
const path = options.path ?? "style";
|
|
117
|
+
const rawStyle = props["style"];
|
|
118
|
+
if (rawStyle !== void 0) {
|
|
119
|
+
if (!isStyleRecord(rawStyle)) throw new CapabilityError("invalid-style", "style must be an object", options.path, { field: "style" });
|
|
120
|
+
if (!allowPadding) {
|
|
121
|
+
const paddingKey = paddingStyleKeys.find((key) => rawStyle[key] !== void 0);
|
|
122
|
+
if (paddingKey !== void 0) throw new CapabilityError("invalid-layout-context", "padding is only applicable to layout containers", options.path, { field: `style.${paddingKey}` });
|
|
123
|
+
}
|
|
124
|
+
const unknown = Object.keys(rawStyle).find((key) => rawStyle[key] !== void 0 && !allowedStyleKeys.has(key));
|
|
125
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-style", `style contains unsupported property ${unknown}`, options.path, {
|
|
126
|
+
prop: unknown,
|
|
127
|
+
field: `style.${unknown}`,
|
|
128
|
+
scope: "style"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const layoutStyle = readStyle(rawStyle, path, isContainer, allowPadding, allowedStyleKeys);
|
|
132
|
+
let padding;
|
|
133
|
+
if (allowPadding && rawStyle !== void 0) {
|
|
134
|
+
if (paddingStyleKeys.some((key) => rawStyle[key] !== void 0)) {
|
|
135
|
+
const edges = expandedSpacing(layoutStyle, "padding");
|
|
136
|
+
padding = {
|
|
137
|
+
top: edges.top,
|
|
138
|
+
right: edges.right,
|
|
139
|
+
bottom: edges.bottom,
|
|
140
|
+
left: edges.left
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const explicitPixelSize = computeExplicitPixelSize(layoutStyle);
|
|
145
|
+
const fixedAxes = computeFixedAxes(layoutStyle);
|
|
146
|
+
const positioned = layoutStyle.position === "relative" || layoutStyle.position === "absolute";
|
|
147
|
+
const isIntrinsicWidthObject = nativeKind === "pic" || nativeKind === "grpSp" && !positioned && (layoutStyle.width === void 0 || layoutStyle.width === "auto");
|
|
148
|
+
return {
|
|
149
|
+
nativeKind,
|
|
150
|
+
layoutStyle,
|
|
151
|
+
explicitPixelSize,
|
|
152
|
+
fixedAxes,
|
|
153
|
+
positioned,
|
|
154
|
+
...padding === void 0 ? {} : { padding },
|
|
155
|
+
...isIntrinsicWidthObject ? { preservesIntrinsicSize: true } : {},
|
|
156
|
+
...excludedFromLayout ? { excludedFromLayout: true } : {}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const nativeElementKinds = /* @__PURE__ */ new Set([
|
|
160
|
+
"sp",
|
|
161
|
+
"pic",
|
|
162
|
+
"grpSp",
|
|
163
|
+
"graphicFrame",
|
|
164
|
+
"cxnSp"
|
|
165
|
+
]);
|
|
166
|
+
function validateBoundObjectCapability(bound) {
|
|
167
|
+
if (typeof bound !== "object" || bound === null) throw new CapabilityError("invalid-capability-binding", "Object capability bind() must return a bound capability object");
|
|
168
|
+
const candidate = bound;
|
|
169
|
+
if (typeof candidate.contract !== "object" || candidate.contract === null || candidate.contract.nativeKind === void 0 || !nativeElementKinds.has(candidate.contract.nativeKind) || typeof candidate.contract.layoutStyle !== "object" || candidate.contract.layoutStyle === null || Array.isArray(candidate.contract.layoutStyle) || typeof candidate.resolve !== "function") throw new CapabilityError("invalid-capability-binding", "Object capability bind() must return a valid contract and resolve handler");
|
|
170
|
+
return bound;
|
|
171
|
+
}
|
|
172
|
+
function objectModule(module) {
|
|
173
|
+
return module !== void 0 && "bind" in module;
|
|
174
|
+
}
|
|
175
|
+
/** Coordinates layout tree construction, capability binding, solver collaboration, and box commitment. */
|
|
176
|
+
var LayoutPass = class {
|
|
177
|
+
#modules;
|
|
178
|
+
#slideNumber;
|
|
179
|
+
#options;
|
|
180
|
+
#boxes = /* @__PURE__ */ new WeakMap();
|
|
181
|
+
#sizedAxes = /* @__PURE__ */ new WeakMap();
|
|
182
|
+
#gridTracks = /* @__PURE__ */ new WeakMap();
|
|
183
|
+
#gridAreas = /* @__PURE__ */ new WeakMap();
|
|
184
|
+
#themes = /* @__PURE__ */ new WeakMap();
|
|
185
|
+
#hidden = /* @__PURE__ */ new WeakSet();
|
|
186
|
+
#boundObjects = /* @__PURE__ */ new WeakMap();
|
|
187
|
+
#nodeMeta = /* @__PURE__ */ new WeakMap();
|
|
188
|
+
#solver;
|
|
189
|
+
#placeholderFor = () => void 0;
|
|
190
|
+
constructor(modules, dimensions, slideNumber = 1, options = {}) {
|
|
191
|
+
this.#modules = modules;
|
|
192
|
+
this.#slideNumber = slideNumber;
|
|
193
|
+
this.#options = options;
|
|
194
|
+
this.#solver = createBlockFlexLayoutSolver({
|
|
195
|
+
dimensions,
|
|
196
|
+
customContainers: customContainerModes.map((mode) => mode.createSolver())
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
run(children, parentPath, theme, slideStyle, placeholderFor) {
|
|
200
|
+
this.#placeholderFor = placeholderFor ?? (() => void 0);
|
|
201
|
+
const rootStyle = readStyle(slideStyle, parentPath, true, true, /* @__PURE__ */ new Set([...textStyleKeys, "background"]));
|
|
202
|
+
const root = this.#solver.createRoot({
|
|
203
|
+
path: parentPath,
|
|
204
|
+
style: rootStyle
|
|
205
|
+
});
|
|
206
|
+
this.#appendChildren(children, parentPath, root, theme);
|
|
207
|
+
this.#solver.solve((node, box, meta) => {
|
|
208
|
+
const elementMeta = this.#nodeMeta.get(node);
|
|
209
|
+
if (elementMeta === void 0) return;
|
|
210
|
+
this.#boxes.set(elementMeta.element, box);
|
|
211
|
+
if (meta?.gridTracks !== void 0) this.#gridTracks.set(elementMeta.element, {
|
|
212
|
+
columnWidths: meta.gridTracks.columnWidths.map(roundLayoutMetric),
|
|
213
|
+
rowHeights: meta.gridTracks.rowHeights.map(roundLayoutMetric)
|
|
214
|
+
});
|
|
215
|
+
if (meta?.gridArea !== void 0) this.#gridAreas.set(elementMeta.element, roundRect(meta.gridArea));
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
boxes: this.#boxes,
|
|
219
|
+
sizedAxes: this.#sizedAxes,
|
|
220
|
+
gridTracks: this.#gridTracks,
|
|
221
|
+
gridAreas: this.#gridAreas,
|
|
222
|
+
themes: this.#themes,
|
|
223
|
+
hidden: this.#hidden,
|
|
224
|
+
bound: this.#boundObjects
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
#bindCapability(child, childPath, themeContext, module, placeholder) {
|
|
228
|
+
let bound = this.#boundObjects.get(child);
|
|
229
|
+
if (bound === void 0) try {
|
|
230
|
+
bound = validateBoundObjectCapability(module.bind(child, {
|
|
231
|
+
path: childPath,
|
|
232
|
+
theme: themeContext,
|
|
233
|
+
options: this.#options,
|
|
234
|
+
slideNumber: this.#slideNumber,
|
|
235
|
+
...placeholder === void 0 ? {} : { placeholder }
|
|
236
|
+
}));
|
|
237
|
+
this.#boundObjects.set(child, bound);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (error instanceof BuildError) throw error;
|
|
240
|
+
if (error instanceof CapabilityError) throw new BuildError([capabilityErrorToDiagnostic(error, childPath, true)]);
|
|
241
|
+
return fail(childPath, "capability-failure", error instanceof Error ? error.message : String(error));
|
|
242
|
+
}
|
|
243
|
+
return bound;
|
|
244
|
+
}
|
|
245
|
+
#appendChildren(children, parentPath, parent, themeContext) {
|
|
246
|
+
children.forEach((child, index) => {
|
|
247
|
+
if (!element(child)) return;
|
|
248
|
+
const childPath = `${parentPath}/${label(child, index)}`;
|
|
249
|
+
if (parent.style.display === "none") {
|
|
250
|
+
this.#markHidden(child);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const module = this.#modules.get(child.type);
|
|
254
|
+
if (module !== void 0 && "compileDeclaration" in module) {
|
|
255
|
+
this.#themes.set(child, themeContext);
|
|
256
|
+
if (module.children === "owned") return;
|
|
257
|
+
this.#appendChildren(child.children, childPath, parent, themeContext);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (objectModule(module)) {
|
|
261
|
+
const placeholder = this.#placeholderFor(child);
|
|
262
|
+
const elementTheme = placeholder === void 0 ? themeContext : placeholder.masterTheme;
|
|
263
|
+
const bound = this.#bindCapability(child, childPath, elementTheme, module, placeholder);
|
|
264
|
+
const contract = bound.contract;
|
|
265
|
+
if (contract.layoutStyle.display === "none") {
|
|
266
|
+
this.#markHidden(child);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (placeholder !== void 0) {
|
|
270
|
+
this.#themes.set(child, elementTheme);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (contract.excludedFromLayout === true) {
|
|
274
|
+
this.#themes.set(child, themeContext);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
for (const mode of customContainerModes) mode.validateItemStyle(contract.layoutStyle, parent.style, childPath);
|
|
278
|
+
if (bound.container !== void 0) {
|
|
279
|
+
const built = this.#buildContainer(child, childPath, parent, themeContext, contract, bound.container);
|
|
280
|
+
this.#solver.appendChild(parent, built);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
this.#themes.set(child, themeContext);
|
|
284
|
+
const built = this.#buildLeafObject(child, childPath, parent, themeContext, bound, contract);
|
|
285
|
+
this.#solver.appendChild(parent, built);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
#buildContainer(input, path, parent, themeContext, contract, container) {
|
|
290
|
+
const style = contract.layoutStyle;
|
|
291
|
+
const theme = container.theme ?? themeContext;
|
|
292
|
+
this.#themes.set(input, theme);
|
|
293
|
+
this.#sizedAxes.set(input, computeLayoutSizedAxes(contract, parent.style));
|
|
294
|
+
const node = this.#solver.createNode({
|
|
295
|
+
path,
|
|
296
|
+
style,
|
|
297
|
+
isContainer: true,
|
|
298
|
+
propagatesBaseline: container.propagatesBaseline !== false,
|
|
299
|
+
...contract.preservesIntrinsicSize ? { preservesIntrinsicSize: true } : {},
|
|
300
|
+
...contract.padding === void 0 ? {} : { padding: contract.padding }
|
|
301
|
+
}, parent);
|
|
302
|
+
this.#nodeMeta.set(node, { element: input });
|
|
303
|
+
this.#appendChildren(container.children, path, node, theme);
|
|
304
|
+
return node;
|
|
305
|
+
}
|
|
306
|
+
#buildLeafObject(input, path, parent, themeContext, bound, contract) {
|
|
307
|
+
this.#sizedAxes.set(input, computeLayoutSizedAxes(contract, parent.style));
|
|
308
|
+
const node = this.#solver.createNode({
|
|
309
|
+
path,
|
|
310
|
+
style: contract.layoutStyle,
|
|
311
|
+
isContainer: false,
|
|
312
|
+
propagatesBaseline: false,
|
|
313
|
+
...contract.preservesIntrinsicSize ? { preservesIntrinsicSize: true } : {},
|
|
314
|
+
...contract.contentMinimumsEnforced ? { contentMinimumsEnforced: true } : {},
|
|
315
|
+
...contract.padding === void 0 ? {} : { padding: contract.padding },
|
|
316
|
+
...bound.measureLayout === void 0 ? {} : { measure: (request) => this.#measure(path, themeContext, bound, request) }
|
|
317
|
+
}, parent);
|
|
318
|
+
this.#nodeMeta.set(node, { element: input });
|
|
319
|
+
return node;
|
|
320
|
+
}
|
|
321
|
+
#markHidden(child) {
|
|
322
|
+
this.#hidden.add(child);
|
|
323
|
+
for (const descendant of child.children) if (element(descendant)) this.#markHidden(descendant);
|
|
324
|
+
}
|
|
325
|
+
#measure(path, theme, bound, request) {
|
|
326
|
+
if (bound.measureLayout === void 0) return;
|
|
327
|
+
try {
|
|
328
|
+
return bound.measureLayout({
|
|
329
|
+
...request,
|
|
330
|
+
theme,
|
|
331
|
+
slideNumber: this.#slideNumber
|
|
332
|
+
});
|
|
333
|
+
} catch (error) {
|
|
334
|
+
if (error instanceof BuildError) throw error;
|
|
335
|
+
if (error instanceof CapabilityError) throw new BuildError([capabilityErrorToDiagnostic(error, path, true)]);
|
|
336
|
+
return fail(path, "capability-failure", error instanceof Error ? error.message : String(error));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
export { LayoutPass, paddingStyleKeys, parseCapabilityLayoutContract, validateBoundObjectCapability };
|