@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.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/build.d.ts +94 -0
- package/dist/build.js +148 -0
- package/dist/capabilities/dist/all.js +32 -0
- package/dist/capabilities/dist/box/box-codegen.js +51 -0
- package/dist/capabilities/dist/box/box-declaration.js +31 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +138 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +77 -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 +2272 -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 +1078 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1124 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -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 +190 -0
- package/dist/capabilities/dist/chart/preview/layout.js +519 -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 +48 -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 +148 -0
- package/dist/capabilities/dist/font/font-embedding.js +289 -0
- package/dist/capabilities/dist/font/font-family.js +10 -0
- package/dist/capabilities/dist/font/font-import.js +302 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +25 -0
- package/dist/capabilities/dist/group/group-codegen.js +51 -0
- package/dist/capabilities/dist/group/group-declaration.js +42 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +319 -0
- package/dist/capabilities/dist/group/group-xml.js +7 -0
- package/dist/capabilities/dist/group/group.js +211 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +94 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +221 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +778 -0
- package/dist/capabilities/dist/image/image-schemas.js +149 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +472 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +527 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1033 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
- package/dist/capabilities/dist/motion/motion-query.js +420 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
- package/dist/capabilities/dist/motion/motion.js +1372 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +20 -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 +35 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +191 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +579 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +337 -0
- package/dist/capabilities/dist/shared/geometry.js +1423 -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 +113 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
- package/dist/capabilities/dist/shared/style-parse.js +11 -0
- package/dist/capabilities/dist/shared/text-schemas.js +216 -0
- package/dist/capabilities/dist/shared/text-service.js +1883 -0
- package/dist/capabilities/dist/shared/visual.js +918 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
- package/dist/capabilities/dist/table/table-codegen.js +81 -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 +539 -0
- package/dist/capabilities/dist/table/table-schemas.js +279 -0
- package/dist/capabilities/dist/table/table-xml.js +37 -0
- package/dist/capabilities/dist/table/table.js +662 -0
- package/dist/capabilities/dist/text/text-codegen.js +129 -0
- package/dist/capabilities/dist/text/text-declaration.js +19 -0
- package/dist/capabilities/dist/text/text-elements.js +38 -0
- package/dist/capabilities/dist/text/text-import.js +1077 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +335 -0
- package/dist/capabilities/dist/transition/transition-api.js +139 -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-D_xeNVIw.d.ts +29496 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +78 -0
- package/dist/codegen/dist/codegen.js +611 -0
- package/dist/codegen/dist/identifiers.js +193 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +49 -0
- package/dist/core/dist/author-ids.js +48 -0
- package/dist/core/dist/author-schemas.js +313 -0
- package/dist/core/dist/block-flex-layout.js +749 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +13 -0
- package/dist/core/dist/declaration.js +15 -0
- package/dist/core/dist/diagnostics.js +21 -0
- package/dist/core/dist/document-internals.js +13 -0
- package/dist/core/dist/document.js +408 -0
- package/dist/core/dist/geometry-schemas.js +249 -0
- package/dist/core/dist/grid-layout.js +445 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +45 -0
- package/dist/core/dist/layout-protocol.js +66 -0
- package/dist/core/dist/layout-schemas.js +208 -0
- package/dist/core/dist/layout.js +299 -0
- package/dist/core/dist/masters.js +169 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +213 -0
- package/dist/core/dist/query.js +155 -0
- package/dist/core/dist/resolution.js +11 -0
- package/dist/core/dist/resolve.js +1827 -0
- package/dist/core/dist/stage-options.js +67 -0
- package/dist/core/dist/theme.js +931 -0
- package/dist/document-BHPUODPP.d.ts +27759 -0
- package/dist/emit/dist/emit.js +936 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +606 -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 +153 -0
- package/dist/import/dist/fonts.js +250 -0
- package/dist/import/dist/import.js +504 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1153 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +60 -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 +671 -0
- package/dist/import/dist/visual.js +761 -0
- package/dist/import/dist/xml-fragments.js +36 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-B5m3hqjC.d.ts +7 -0
- package/dist/index-CCy-Yo8G.d.ts +1208 -0
- package/dist/index-DpxcZ4Gs.d.ts +725 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +70 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +194 -0
- package/dist/pptxdk/src/cli-commands.js +913 -0
- package/dist/pptxdk/src/compose.js +44 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +240 -0
- package/dist/preview/dist/options.js +53 -0
- package/dist/preview-Cfw0QdMM.d.ts +86 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +27 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +65 -0
- package/dist/react/dist/elements.js +59 -0
- package/dist/react/dist/index.js +68 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +27 -0
- package/dist/transition-Cips9wma.d.ts +82 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +14 -0
- package/package.json +78 -3
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
import { BuildError } from "./diagnostics.js";
|
|
2
|
+
import { expandedSpacing, parseLayoutNumber } from "./layout-protocol.js";
|
|
3
|
+
import Yoga, { Align, Direction, Display, Edge, FlexDirection, Gutter, Justify, MeasureMode, PositionType, Wrap } from "yoga-layout";
|
|
4
|
+
// ../core/dist/block-flex-layout.js
|
|
5
|
+
const paddingStyleKeys = [
|
|
6
|
+
"padding",
|
|
7
|
+
"paddingTop",
|
|
8
|
+
"paddingRight",
|
|
9
|
+
"paddingBottom",
|
|
10
|
+
"paddingLeft"
|
|
11
|
+
];
|
|
12
|
+
const blockFlexContainerProperties = [
|
|
13
|
+
"flexDirection",
|
|
14
|
+
"flexWrap",
|
|
15
|
+
"justifyContent",
|
|
16
|
+
"alignItems",
|
|
17
|
+
"alignContent",
|
|
18
|
+
"gap",
|
|
19
|
+
"rowGap",
|
|
20
|
+
"columnGap"
|
|
21
|
+
];
|
|
22
|
+
const blockFlexLayoutProperties = [
|
|
23
|
+
"display",
|
|
24
|
+
"position",
|
|
25
|
+
"inset",
|
|
26
|
+
"left",
|
|
27
|
+
"top",
|
|
28
|
+
"right",
|
|
29
|
+
"bottom",
|
|
30
|
+
"width",
|
|
31
|
+
"height",
|
|
32
|
+
"minWidth",
|
|
33
|
+
"minHeight",
|
|
34
|
+
"maxWidth",
|
|
35
|
+
"maxHeight",
|
|
36
|
+
"margin",
|
|
37
|
+
"marginTop",
|
|
38
|
+
"marginRight",
|
|
39
|
+
"marginBottom",
|
|
40
|
+
"marginLeft",
|
|
41
|
+
"padding",
|
|
42
|
+
"paddingTop",
|
|
43
|
+
"paddingRight",
|
|
44
|
+
"paddingBottom",
|
|
45
|
+
"paddingLeft",
|
|
46
|
+
"gap",
|
|
47
|
+
"rowGap",
|
|
48
|
+
"columnGap",
|
|
49
|
+
"flexDirection",
|
|
50
|
+
"flexWrap",
|
|
51
|
+
"justifyContent",
|
|
52
|
+
"alignItems",
|
|
53
|
+
"alignSelf",
|
|
54
|
+
"alignContent",
|
|
55
|
+
"flex",
|
|
56
|
+
"flexGrow",
|
|
57
|
+
"flexShrink",
|
|
58
|
+
"flexBasis",
|
|
59
|
+
"aspectRatio",
|
|
60
|
+
"zIndex"
|
|
61
|
+
];
|
|
62
|
+
function fail(path, code, message) {
|
|
63
|
+
throw new BuildError([{
|
|
64
|
+
severity: "error",
|
|
65
|
+
path,
|
|
66
|
+
code,
|
|
67
|
+
message
|
|
68
|
+
}]);
|
|
69
|
+
}
|
|
70
|
+
function isStyleRecord(value) {
|
|
71
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
72
|
+
}
|
|
73
|
+
function parseLayoutLength(value, name, path, nonNegative = true) {
|
|
74
|
+
if (value === void 0 || value === "auto") return void 0;
|
|
75
|
+
if (typeof value === "string") {
|
|
76
|
+
const percent = /^(-?(?:\d+(?:\.\d*)?|\.\d+))%$/u.exec(value);
|
|
77
|
+
if (percent === null) fail(path, "invalid-layout-style", `${name} must be a pixel number, percentage, or auto`);
|
|
78
|
+
const amount = Number(percent[1]);
|
|
79
|
+
if (!Number.isFinite(amount) || nonNegative && amount < 0) fail(path, "invalid-layout-style", `${name} cannot be less than 0`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const amount = parseLayoutNumber(value, name, path);
|
|
83
|
+
if (nonNegative && amount < 0) fail(path, "invalid-layout-style", `${name} cannot be less than 0`);
|
|
84
|
+
return amount;
|
|
85
|
+
}
|
|
86
|
+
function styleLength(value) {
|
|
87
|
+
return typeof value === "number" ? value : void 0;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Validates container-level Block/Flex display and container-only property eligibility.
|
|
91
|
+
*/
|
|
92
|
+
function validateBlockFlexContainerContext(value, path, isContainer, customContainers = []) {
|
|
93
|
+
const customContainerKeys = customContainers.flatMap((mode) => mode.containerStyleKeys);
|
|
94
|
+
if (!isContainer && (value["display"] !== void 0 && value["display"] !== "none" && value["display"] !== "block" || Object.keys(value).some((key) => blockFlexContainerProperties.includes(key) || customContainerKeys.includes(key)))) fail(path, "invalid-layout-context", "Container-only styles cannot be used on objects without layout children");
|
|
95
|
+
const display = value["display"];
|
|
96
|
+
const customDisplays = customContainers.map((mode) => mode.display);
|
|
97
|
+
if (display !== void 0 && display !== "block" && display !== "flex" && display !== "none" && !customDisplays.includes(display)) {
|
|
98
|
+
const supported = [
|
|
99
|
+
"block",
|
|
100
|
+
"flex",
|
|
101
|
+
...customDisplays,
|
|
102
|
+
"none"
|
|
103
|
+
];
|
|
104
|
+
fail(path, "unsupported-layout-value", `display only supports ${supported.length <= 2 ? supported.join(" or ") : `${supported.slice(0, -1).join(", ")}, or ${supported.at(-1)}`}`);
|
|
105
|
+
}
|
|
106
|
+
return display ?? "block";
|
|
107
|
+
}
|
|
108
|
+
function validateBlockFlexContainerProperties(value, resolvedDisplay, path, customContainers = []) {
|
|
109
|
+
const activeCustomMode = customContainers.find((mode) => mode.display === resolvedDisplay);
|
|
110
|
+
for (const key of blockFlexContainerProperties) if (value[key] !== void 0 && resolvedDisplay !== "flex" && !(activeCustomMode?.sharedContainerProperties.includes(key) ?? false)) {
|
|
111
|
+
const supported = ["flex", ...customContainers.filter((mode) => mode.sharedContainerProperties.includes(key)).map((mode) => mode.display)];
|
|
112
|
+
fail(path, "invalid-layout-context", `${key} is only applicable to display: ${supported.length === 1 ? `"${supported[0]}"` : `"${supported[0]}" or ${supported.slice(1).join(", ")}`} containers`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function validateBlockFlexLayoutContextBounds(value, allowsPadding, path) {
|
|
116
|
+
if ((value["position"] ?? "static") === "static" && [
|
|
117
|
+
"inset",
|
|
118
|
+
"left",
|
|
119
|
+
"top",
|
|
120
|
+
"right",
|
|
121
|
+
"bottom"
|
|
122
|
+
].some((key) => value[key] !== void 0)) fail(path, "invalid-layout-context", "Position offsets are only applicable to relative or absolute elements");
|
|
123
|
+
if (!allowsPadding && paddingStyleKeys.some((key) => value[key] !== void 0)) fail(path, "invalid-layout-context", "padding is only applicable to layout containers");
|
|
124
|
+
const minWidth = value["minWidth"];
|
|
125
|
+
const maxWidth = value["maxWidth"];
|
|
126
|
+
if (typeof minWidth === "number" && typeof maxWidth === "number" && minWidth > maxWidth) fail(path, "invalid-layout-style", "minWidth cannot be greater than maxWidth");
|
|
127
|
+
const minHeight = value["minHeight"];
|
|
128
|
+
const maxHeight = value["maxHeight"];
|
|
129
|
+
if (typeof minHeight === "number" && typeof maxHeight === "number" && minHeight > maxHeight) fail(path, "invalid-layout-style", "minHeight cannot be greater than maxHeight");
|
|
130
|
+
}
|
|
131
|
+
function yogaJustify(value) {
|
|
132
|
+
switch (value) {
|
|
133
|
+
case "start":
|
|
134
|
+
case "flex-start": return Justify.FlexStart;
|
|
135
|
+
case "end":
|
|
136
|
+
case "flex-end": return Justify.FlexEnd;
|
|
137
|
+
case "center": return Justify.Center;
|
|
138
|
+
case "space-between": return Justify.SpaceBetween;
|
|
139
|
+
case "space-around": return Justify.SpaceAround;
|
|
140
|
+
case "space-evenly": return Justify.SpaceEvenly;
|
|
141
|
+
default: throw new Error(`Unsupported justifyContent: ${String(value)}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function yogaAlign(value) {
|
|
145
|
+
switch (value) {
|
|
146
|
+
case "auto": return Align.Auto;
|
|
147
|
+
case "start":
|
|
148
|
+
case "flex-start": return Align.FlexStart;
|
|
149
|
+
case "end":
|
|
150
|
+
case "flex-end": return Align.FlexEnd;
|
|
151
|
+
case "center": return Align.Center;
|
|
152
|
+
case "stretch": return Align.Stretch;
|
|
153
|
+
case "baseline": return Align.Baseline;
|
|
154
|
+
default: throw new Error(`Unsupported alignItems: ${String(value)}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function yogaAlignContent(value) {
|
|
158
|
+
switch (value) {
|
|
159
|
+
case "start":
|
|
160
|
+
case "flex-start": return Align.FlexStart;
|
|
161
|
+
case "end":
|
|
162
|
+
case "flex-end": return Align.FlexEnd;
|
|
163
|
+
case "center": return Align.Center;
|
|
164
|
+
case "space-between": return Align.SpaceBetween;
|
|
165
|
+
case "space-around": return Align.SpaceAround;
|
|
166
|
+
case "space-evenly": return Align.SpaceEvenly;
|
|
167
|
+
case "stretch": return Align.Stretch;
|
|
168
|
+
default: throw new Error(`Unsupported alignContent: ${String(value)}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function rowDirection(style) {
|
|
172
|
+
const direction = style.flexDirection ?? "row";
|
|
173
|
+
return direction === "row" || direction === "row-reverse";
|
|
174
|
+
}
|
|
175
|
+
function reverseDirection(style) {
|
|
176
|
+
return (style.flexDirection ?? "row").endsWith("-reverse");
|
|
177
|
+
}
|
|
178
|
+
function setLength(yoga, property, value) {
|
|
179
|
+
const [pointSetter, percentSetter] = {
|
|
180
|
+
width: ["setWidth", "setWidthPercent"],
|
|
181
|
+
height: ["setHeight", "setHeightPercent"],
|
|
182
|
+
minWidth: ["setMinWidth", "setMinWidthPercent"],
|
|
183
|
+
minHeight: ["setMinHeight", "setMinHeightPercent"],
|
|
184
|
+
maxWidth: ["setMaxWidth", "setMaxWidthPercent"],
|
|
185
|
+
maxHeight: ["setMaxHeight", "setMaxHeightPercent"],
|
|
186
|
+
flexBasis: ["setFlexBasis", "setFlexBasisPercent"]
|
|
187
|
+
}[property];
|
|
188
|
+
const percent = typeof value === "string" ? /^(\d+(?:\.\d*)?|\.\d+)%$/u.exec(value) : null;
|
|
189
|
+
if (percent !== null) {
|
|
190
|
+
yoga[percentSetter](Number(percent[1]));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (typeof value === "number") {
|
|
194
|
+
yoga[pointSetter](value);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (value === "auto") {
|
|
198
|
+
const setter = yoga[{
|
|
199
|
+
width: "setWidthAuto",
|
|
200
|
+
height: "setHeightAuto",
|
|
201
|
+
minWidth: "setMinWidth",
|
|
202
|
+
minHeight: "setMinHeight",
|
|
203
|
+
maxWidth: "setMaxWidth",
|
|
204
|
+
maxHeight: "setMaxHeight",
|
|
205
|
+
flexBasis: "setFlexBasisAuto"
|
|
206
|
+
}[property]];
|
|
207
|
+
if (setter !== void 0) setter.call(yoga);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function setPosition(yoga, edge, value) {
|
|
211
|
+
if (value === void 0 || value === "auto") return;
|
|
212
|
+
yoga.setPosition(edge, value);
|
|
213
|
+
}
|
|
214
|
+
function applyBlockFlexStyle(yoga, style, parent, isRoot, isContainer, isCustomContainer) {
|
|
215
|
+
const display = style.display ?? "block";
|
|
216
|
+
yoga.setDisplay(display === "none" ? Display.None : Display.Flex);
|
|
217
|
+
const positioned = style.position === "absolute" || style.position === "relative" || isRoot;
|
|
218
|
+
yoga.setPositionType(style.position === "absolute" ? PositionType.Absolute : positioned ? PositionType.Relative : PositionType.Static);
|
|
219
|
+
if (!positioned && isCustomContainer) yoga.setAlwaysFormsContainingBlock(true);
|
|
220
|
+
for (const [edge, value] of [
|
|
221
|
+
[Edge.Left, style.left ?? style.inset],
|
|
222
|
+
[Edge.Top, style.top ?? style.inset],
|
|
223
|
+
[Edge.Right, style.right ?? style.inset],
|
|
224
|
+
[Edge.Bottom, style.bottom ?? style.inset]
|
|
225
|
+
]) setPosition(yoga, edge, value);
|
|
226
|
+
if (style.aspectRatio !== void 0) yoga.setAspectRatio(style.aspectRatio);
|
|
227
|
+
const flex = style.display === "flex";
|
|
228
|
+
yoga.setFlexDirection(flex ? {
|
|
229
|
+
row: FlexDirection.Row,
|
|
230
|
+
column: FlexDirection.Column,
|
|
231
|
+
"row-reverse": FlexDirection.RowReverse,
|
|
232
|
+
"column-reverse": FlexDirection.ColumnReverse
|
|
233
|
+
}[style.flexDirection ?? "row"] : FlexDirection.Column);
|
|
234
|
+
if (flex && style.flexWrap === "wrap") yoga.setFlexWrap(Wrap.Wrap);
|
|
235
|
+
if (flex && style.justifyContent !== void 0) {
|
|
236
|
+
const align = style.justifyContent;
|
|
237
|
+
const isReversed = reverseDirection(style);
|
|
238
|
+
const physicalAlign = align === "start" ? isReversed ? "flex-end" : "flex-start" : align === "end" ? isReversed ? "flex-start" : "flex-end" : align;
|
|
239
|
+
yoga.setJustifyContent(yogaJustify(physicalAlign));
|
|
240
|
+
}
|
|
241
|
+
if (flex && style.alignItems !== void 0) yoga.setAlignItems(yogaAlign(style.alignItems));
|
|
242
|
+
if (flex && style.alignContent !== void 0) yoga.setAlignContent(yogaAlignContent(style.alignContent));
|
|
243
|
+
else if (flex && style.flexWrap === "wrap") yoga.setAlignContent(Align.Stretch);
|
|
244
|
+
if ((flex || isCustomContainer) && style.gap !== void 0) yoga.setGap(Gutter.All, style.gap);
|
|
245
|
+
if ((flex || isCustomContainer) && style.rowGap !== void 0) yoga.setGap(Gutter.Row, style.rowGap);
|
|
246
|
+
if ((flex || isCustomContainer) && style.columnGap !== void 0) yoga.setGap(Gutter.Column, style.columnGap);
|
|
247
|
+
for (const key of [
|
|
248
|
+
"width",
|
|
249
|
+
"height",
|
|
250
|
+
"minWidth",
|
|
251
|
+
"minHeight",
|
|
252
|
+
"maxWidth",
|
|
253
|
+
"maxHeight"
|
|
254
|
+
]) setLength(yoga, key, style[key]);
|
|
255
|
+
const padding = expandedSpacing(style, "padding");
|
|
256
|
+
yoga.setPadding(Edge.Top, padding.top);
|
|
257
|
+
yoga.setPadding(Edge.Right, padding.right);
|
|
258
|
+
yoga.setPadding(Edge.Bottom, padding.bottom);
|
|
259
|
+
yoga.setPadding(Edge.Left, padding.left);
|
|
260
|
+
if (!isRoot) {
|
|
261
|
+
const margin = expandedSpacing(style, "margin");
|
|
262
|
+
yoga.setMargin(Edge.Top, margin.top);
|
|
263
|
+
yoga.setMargin(Edge.Right, margin.right);
|
|
264
|
+
yoga.setMargin(Edge.Bottom, margin.bottom);
|
|
265
|
+
yoga.setMargin(Edge.Left, margin.left);
|
|
266
|
+
if (parent.display === "flex") {
|
|
267
|
+
yoga.setFlexShrink(style.flexShrink ?? 1);
|
|
268
|
+
if (style.flex !== void 0) {
|
|
269
|
+
yoga.setFlexGrow(style.flex);
|
|
270
|
+
yoga.setFlexShrink(style.flexShrink ?? 1);
|
|
271
|
+
yoga.setFlexBasis(0);
|
|
272
|
+
}
|
|
273
|
+
if (style.flexGrow !== void 0) yoga.setFlexGrow(style.flexGrow);
|
|
274
|
+
if (style.flexBasis !== void 0) setLength(yoga, "flexBasis", style.flexBasis);
|
|
275
|
+
if (style.alignSelf !== void 0) yoga.setAlignSelf(yogaAlign(style.alignSelf));
|
|
276
|
+
} else yoga.setFlexShrink(0);
|
|
277
|
+
}
|
|
278
|
+
if (isContainer && style.display !== "flex") yoga.setAlignItems(Align.Stretch);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Creates the Block & Flex layout solver backed by Yoga, handling CSS-subset block/flex defaults,
|
|
282
|
+
* automatic minimum sizes, text baseline alignment & propagation, containing-block escaping,
|
|
283
|
+
* loose canvas geometry, and delegated custom container collaboration.
|
|
284
|
+
*/
|
|
285
|
+
function createBlockFlexLayoutSolver(options) {
|
|
286
|
+
const { dimensions, customContainers = [] } = options;
|
|
287
|
+
const config = Yoga.Config.create();
|
|
288
|
+
config.setPointScaleFactor(0);
|
|
289
|
+
const internalNodes = /* @__PURE__ */ new WeakMap();
|
|
290
|
+
let rootNode;
|
|
291
|
+
const findCustomHandler = (display) => customContainers.find((handler) => handler.handlesDisplay(display));
|
|
292
|
+
const asInternal = (node) => {
|
|
293
|
+
const internal = internalNodes.get(node);
|
|
294
|
+
if (internal === void 0) throw new Error(`Unknown layout solver node: ${node.path}`);
|
|
295
|
+
return internal;
|
|
296
|
+
};
|
|
297
|
+
const containingBlock = (parent) => {
|
|
298
|
+
let current = parent;
|
|
299
|
+
while (current !== void 0) {
|
|
300
|
+
if (current.isRoot) return current;
|
|
301
|
+
if (current.style.position === "relative" || current.style.position === "absolute") return current;
|
|
302
|
+
current = current.parent;
|
|
303
|
+
}
|
|
304
|
+
return fail(parent.path, "layout-unavailable", "Positioned object is not within slide canvas");
|
|
305
|
+
};
|
|
306
|
+
const minContent = (node, axis) => {
|
|
307
|
+
if (!node.isContainer) {
|
|
308
|
+
const padding = expandedSpacing(node.style, "padding");
|
|
309
|
+
const computedWidth = node.yoga.getComputedWidth();
|
|
310
|
+
const rawWidth = node.style.width ?? node.contractWidth;
|
|
311
|
+
const measuredWidth = typeof rawWidth === "string" && rawWidth.endsWith("%") ? void 0 : Math.max(0, computedWidth - padding.left - padding.right);
|
|
312
|
+
const measured = node.measure?.(measuredWidth === void 0 ? {} : { availableWidth: measuredWidth });
|
|
313
|
+
const result = axis === "width" ? measured?.minContentWidth : measured?.minContentHeight;
|
|
314
|
+
if (result === void 0) return void 0;
|
|
315
|
+
return result + (axis === "width" ? padding.left + padding.right : padding.top + padding.bottom);
|
|
316
|
+
}
|
|
317
|
+
const horizontal = axis === "width";
|
|
318
|
+
if (node.customHandler !== void 0) return node.customHandler.measureMinContent(node.view, axis, port);
|
|
319
|
+
const flexRow = node.style.display === "flex" && rowDirection(node.style) && node.style.flexWrap !== "wrap";
|
|
320
|
+
const flexColumn = node.style.display === "flex" && !rowDirection(node.style);
|
|
321
|
+
let content;
|
|
322
|
+
if (horizontal && flexRow) {
|
|
323
|
+
content = node.children.reduce((total, child) => total + minContentContribution(child, axis), 0);
|
|
324
|
+
content += (node.style.columnGap ?? node.style.gap ?? 0) * Math.max(0, node.children.length - 1);
|
|
325
|
+
} else if (!horizontal && (flexColumn || node.style.display !== "flex")) {
|
|
326
|
+
content = node.children.reduce((total, child) => total + minContentContribution(child, axis), 0);
|
|
327
|
+
if (node.style.display === "flex") content += (node.style.rowGap ?? node.style.gap ?? 0) * Math.max(0, node.children.length - 1);
|
|
328
|
+
} else content = Math.max(0, ...node.children.map((child) => minContentContribution(child, axis)));
|
|
329
|
+
if (!horizontal && flexRow) content = baselineContentHeight(node) ?? content;
|
|
330
|
+
if (horizontal) {
|
|
331
|
+
const padding = expandedSpacing(node.style, "padding");
|
|
332
|
+
content += padding.left + padding.right;
|
|
333
|
+
const declared = styleLength(node.style.width);
|
|
334
|
+
const maximum = styleLength(node.style.maxWidth);
|
|
335
|
+
if (declared !== void 0) content = Math.min(content, declared);
|
|
336
|
+
if (maximum !== void 0) content = Math.min(content, maximum);
|
|
337
|
+
} else {
|
|
338
|
+
const padding = expandedSpacing(node.style, "padding");
|
|
339
|
+
content += padding.top + padding.bottom;
|
|
340
|
+
const declared = styleLength(node.style.height);
|
|
341
|
+
const maximum = styleLength(node.style.maxHeight);
|
|
342
|
+
if (declared !== void 0) content = Math.min(content, declared);
|
|
343
|
+
if (maximum !== void 0) content = Math.min(content, maximum);
|
|
344
|
+
}
|
|
345
|
+
return content;
|
|
346
|
+
};
|
|
347
|
+
const minContentContribution = (node, axis) => {
|
|
348
|
+
const content = minContent(node, axis) ?? 0;
|
|
349
|
+
let size = parseLayoutLength(node.style[axis] ?? (axis === "width" ? node.contractWidth : node.contractHeight), axis, node.path) ?? content;
|
|
350
|
+
const minimum = axis === "width" ? styleLength(node.style.minWidth) : styleLength(node.style.minHeight);
|
|
351
|
+
const maximum = axis === "width" ? styleLength(node.style.maxWidth) : styleLength(node.style.maxHeight);
|
|
352
|
+
if (minimum !== void 0) size = Math.max(size, minimum);
|
|
353
|
+
if (maximum !== void 0) size = Math.min(size, maximum);
|
|
354
|
+
const margin = expandedSpacing(node.style, "margin");
|
|
355
|
+
return size + (axis === "width" ? margin.left + margin.right : margin.top + margin.bottom);
|
|
356
|
+
};
|
|
357
|
+
const automaticMinimum = (node, axis) => {
|
|
358
|
+
const content = minContent(node, axis);
|
|
359
|
+
if (content === void 0) return void 0;
|
|
360
|
+
const maximum = axis === "width" ? styleLength(node.style.maxWidth) : styleLength(node.style.maxHeight);
|
|
361
|
+
const declared = parseLayoutLength(node.style[axis] ?? (axis === "width" ? node.contractWidth : node.contractHeight), axis, node.path);
|
|
362
|
+
return Math.min(content, ...declared === void 0 ? [] : [declared], ...maximum === void 0 ? [] : [maximum]);
|
|
363
|
+
};
|
|
364
|
+
const applyAutomaticMinimums = (root) => {
|
|
365
|
+
let changed = false;
|
|
366
|
+
if (root.style.display === "flex") {
|
|
367
|
+
const horizontal = rowDirection(root.style);
|
|
368
|
+
for (const child of root.children) {
|
|
369
|
+
const explicitMinimum = horizontal ? child.style.minWidth : child.style.minHeight;
|
|
370
|
+
if (child.style.position === "absolute" || explicitMinimum !== void 0 && explicitMinimum !== "auto") continue;
|
|
371
|
+
const minimum = automaticMinimum(child, horizontal ? "width" : "height");
|
|
372
|
+
if (minimum === void 0 || minimum <= 0) continue;
|
|
373
|
+
if (horizontal) child.yoga.setMinWidth(minimum);
|
|
374
|
+
else child.yoga.setMinHeight(minimum);
|
|
375
|
+
changed = true;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
for (const child of root.children) if (applyAutomaticMinimums(child)) changed = true;
|
|
379
|
+
return changed;
|
|
380
|
+
};
|
|
381
|
+
const resolvedChildAlignment = (node, child) => {
|
|
382
|
+
const childAlignment = child.yoga.getAlignSelf();
|
|
383
|
+
const alignment = childAlignment === Align.Auto ? node.yoga.getAlignItems() : childAlignment;
|
|
384
|
+
const direction = node.yoga.getFlexDirection();
|
|
385
|
+
if (alignment === Align.Baseline && (direction === FlexDirection.Column || direction === FlexDirection.ColumnReverse)) return Align.FlexStart;
|
|
386
|
+
return alignment;
|
|
387
|
+
};
|
|
388
|
+
const baselineParticipants = (node) => {
|
|
389
|
+
return node.children.filter((child) => resolvedChildAlignment(node, child) === Align.Baseline);
|
|
390
|
+
};
|
|
391
|
+
const hasVerticalOffset = (node) => {
|
|
392
|
+
return node.style.top !== void 0 || node.style.marginTop !== void 0 || node.style.bottom !== void 0 || node.style.marginBottom !== void 0;
|
|
393
|
+
};
|
|
394
|
+
const resolveBaselineLeaf = (node) => {
|
|
395
|
+
if (!node.isContainer || !node.propagatesBaseline) {
|
|
396
|
+
if (node.measure === void 0) fail(node.path, "unsupported-baseline-context", "Baseline alignment requires a text-bearing capability with baseline support");
|
|
397
|
+
return node;
|
|
398
|
+
}
|
|
399
|
+
if (node.children.length !== 1) fail(node.path, "unsupported-baseline-context", "Text baseline currently only propagates along single-child Box chains");
|
|
400
|
+
const child = node.children[0];
|
|
401
|
+
const simpleRow = node.style.display === "flex" && node.style.flexWrap !== "wrap" && rowDirection(node.style) && !reverseDirection(node.style);
|
|
402
|
+
const childAlign = child.style.alignSelf;
|
|
403
|
+
const parentAlign = node.style.alignItems;
|
|
404
|
+
const alignedAtStart = childAlign === "start" || childAlign === "flex-start" || (childAlign === void 0 || childAlign === "auto") && (parentAlign === "start" || parentAlign === "flex-start");
|
|
405
|
+
const childHeight = child.contractHeight ?? child.style.height;
|
|
406
|
+
if (!simpleRow || !alignedAtStart && !((childAlign === void 0 || childAlign === "auto" || childAlign === "stretch") && (parentAlign === void 0 || parentAlign === "stretch") && typeof childHeight === "number")) fail(node.path, "unsupported-baseline-context", "Text baseline requires a nowrap row Box with the only child fixed at the top of the cross axis");
|
|
407
|
+
return resolveBaselineLeaf(child);
|
|
408
|
+
};
|
|
409
|
+
const installBaselineMarker = (node) => {
|
|
410
|
+
if (node.baselineContent !== void 0) return;
|
|
411
|
+
const measureFunction = node.measureFunction;
|
|
412
|
+
if (measureFunction === void 0 || node.measure === void 0) fail(node.path, "unsupported-baseline-context", "Baseline alignment requires a text-bearing capability with baseline support");
|
|
413
|
+
const availableWidth = parseLayoutLength(node.contractWidth ?? node.style.width, "width", node.path);
|
|
414
|
+
const padding = expandedSpacing(node.style, "padding");
|
|
415
|
+
const measurement = node.measure(availableWidth === void 0 ? {} : { availableWidth: Math.max(0, availableWidth - padding.left - padding.right) });
|
|
416
|
+
if (measurement?.baseline === void 0) fail(node.path, "unsupported-baseline-context", "Baseline alignment requires a text-bearing capability with baseline support");
|
|
417
|
+
if (measurement.baseline === "unavailable" || hasVerticalOffset(node)) fail(node.path, "baseline-measurement-unavailable", "Baseline alignment requires a single text run, top anchor, and explicit font resource");
|
|
418
|
+
const content = Yoga.Node.create(config);
|
|
419
|
+
content.setFlexShrink(1);
|
|
420
|
+
content.setMeasureFunc(measureFunction);
|
|
421
|
+
const marker = Yoga.Node.create(config);
|
|
422
|
+
marker.setWidth(0);
|
|
423
|
+
marker.setHeight(0);
|
|
424
|
+
marker.setPositionType(PositionType.Relative);
|
|
425
|
+
marker.setPosition(Edge.Top, measurement.baseline);
|
|
426
|
+
marker.setIsReferenceBaseline(true);
|
|
427
|
+
node.yoga.unsetMeasureFunc();
|
|
428
|
+
node.yoga.setFlexDirection(FlexDirection.Row);
|
|
429
|
+
node.yoga.setAlignItems(Align.FlexStart);
|
|
430
|
+
node.yoga.insertChild(content, 0);
|
|
431
|
+
node.yoga.insertChild(marker, 1);
|
|
432
|
+
node.baseline = measurement.baseline + padding.top;
|
|
433
|
+
node.baselineContent = content;
|
|
434
|
+
};
|
|
435
|
+
const prepareTextBaselines = (node) => {
|
|
436
|
+
const flexRow = node.style.display === "flex" && rowDirection(node.style);
|
|
437
|
+
const participants = baselineParticipants(node);
|
|
438
|
+
if (flexRow && participants.length > 0) {
|
|
439
|
+
if (node.style.flexWrap === "wrap") fail(node.path, "unsupported-baseline-context", "Text baseline currently requires a nowrap row flex container");
|
|
440
|
+
for (const participant of participants) installBaselineMarker(resolveBaselineLeaf(participant));
|
|
441
|
+
}
|
|
442
|
+
for (const child of node.children) prepareTextBaselines(child);
|
|
443
|
+
for (const child of node.escaped) prepareTextBaselines(child);
|
|
444
|
+
};
|
|
445
|
+
const markBaselineMeasurementsDirty = (node) => {
|
|
446
|
+
let changed = false;
|
|
447
|
+
if (node.baselineContent !== void 0) {
|
|
448
|
+
node.baselineContent.markDirty();
|
|
449
|
+
changed = true;
|
|
450
|
+
}
|
|
451
|
+
for (const child of node.children) if (markBaselineMeasurementsDirty(child)) changed = true;
|
|
452
|
+
return changed;
|
|
453
|
+
};
|
|
454
|
+
const baselineOffsetWithin = (node) => {
|
|
455
|
+
if (node.baseline !== void 0) return node.baseline;
|
|
456
|
+
if (node.children.length === 0) return node.yoga.getComputedHeight();
|
|
457
|
+
const participants = new Set(baselineParticipants(node));
|
|
458
|
+
const baselineChild = node.children.find((child) => child.yoga.isReferenceBaseline() || participants.has(child));
|
|
459
|
+
const child = baselineChild ?? node.children[0];
|
|
460
|
+
if (child === void 0) fail(node.path, "unsupported-baseline-context", "Layout subtree has no propagatable text baseline");
|
|
461
|
+
if (node.style.flexWrap === "wrap" && baselineChild !== void 0 && baselineChild !== node.children[0]) fail(node.path, "unsupported-baseline-context", "Cannot reliably determine text baseline row in wrapping Box");
|
|
462
|
+
return child.yoga.getComputedTop() + baselineOffsetWithin(child);
|
|
463
|
+
};
|
|
464
|
+
const baselineContentHeight = (node) => {
|
|
465
|
+
const participants = baselineParticipants(node);
|
|
466
|
+
if (participants.length === 0) return void 0;
|
|
467
|
+
let ascent = 0;
|
|
468
|
+
let descent = 0;
|
|
469
|
+
for (const child of participants) {
|
|
470
|
+
const margin = expandedSpacing(child.style, "margin");
|
|
471
|
+
const contribution = minContentContribution(child, "height");
|
|
472
|
+
const height = Math.max(0, contribution - margin.top - margin.bottom);
|
|
473
|
+
const baseline = baselineOffsetWithin(child);
|
|
474
|
+
ascent = Math.max(ascent, margin.top + baseline);
|
|
475
|
+
descent = Math.max(descent, margin.bottom + height - baseline);
|
|
476
|
+
}
|
|
477
|
+
const nonParticipantsHeight = Math.max(0, ...node.children.filter((child) => !participants.includes(child)).map((child) => minContentContribution(child, "height")));
|
|
478
|
+
return Math.max(ascent + descent, nonParticipantsHeight);
|
|
479
|
+
};
|
|
480
|
+
const port = {
|
|
481
|
+
getComputedSize(node) {
|
|
482
|
+
const internal = asInternal(node);
|
|
483
|
+
return {
|
|
484
|
+
width: internal.yoga.getComputedWidth(),
|
|
485
|
+
height: internal.yoga.getComputedHeight()
|
|
486
|
+
};
|
|
487
|
+
},
|
|
488
|
+
getAllocatedHeight(node) {
|
|
489
|
+
return asInternal(node).allocatedHeight;
|
|
490
|
+
},
|
|
491
|
+
setAllocatedHeight(node, height) {
|
|
492
|
+
asInternal(node).allocatedHeight = height;
|
|
493
|
+
},
|
|
494
|
+
setContainerSize(node, size) {
|
|
495
|
+
const internal = asInternal(node);
|
|
496
|
+
if (size.width !== void 0) internal.yoga.setWidth(size.width);
|
|
497
|
+
if (size.height !== void 0) internal.yoga.setHeight(size.height);
|
|
498
|
+
},
|
|
499
|
+
measureNaturalSize(node, availableWidth) {
|
|
500
|
+
const internal = asInternal(node);
|
|
501
|
+
internal.yoga.calculateLayout(availableWidth, void 0, Direction.LTR);
|
|
502
|
+
return {
|
|
503
|
+
width: internal.yoga.getComputedWidth(),
|
|
504
|
+
height: internal.yoga.getComputedHeight()
|
|
505
|
+
};
|
|
506
|
+
},
|
|
507
|
+
measureMinContentContribution(node, axis) {
|
|
508
|
+
return minContentContribution(asInternal(node), axis);
|
|
509
|
+
},
|
|
510
|
+
setChildConstraints(node, constraints) {
|
|
511
|
+
const internal = asInternal(node);
|
|
512
|
+
if (constraints.width !== void 0) internal.yoga.setWidth(constraints.width);
|
|
513
|
+
if (constraints.height === "auto") internal.yoga.setHeightAuto();
|
|
514
|
+
else if (constraints.height !== void 0) internal.yoga.setHeight(constraints.height);
|
|
515
|
+
if (constraints.minWidth !== void 0) internal.yoga.setMinWidth(constraints.minWidth);
|
|
516
|
+
if (constraints.maxWidth !== void 0) internal.yoga.setMaxWidth(constraints.maxWidth);
|
|
517
|
+
if (constraints.minHeight !== void 0) internal.yoga.setMinHeight(constraints.minHeight);
|
|
518
|
+
if (constraints.maxHeight !== void 0) internal.yoga.setMaxHeight(constraints.maxHeight);
|
|
519
|
+
},
|
|
520
|
+
placeChild(node, position) {
|
|
521
|
+
const internal = asInternal(node);
|
|
522
|
+
internal.yoga.setPositionType(PositionType.Absolute);
|
|
523
|
+
internal.yoga.setPosition(Edge.Left, position.x);
|
|
524
|
+
internal.yoga.setPosition(Edge.Top, position.y);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
const resolveCustomContainers = (node) => {
|
|
528
|
+
node.customHandler?.placeContainer(node.view, port);
|
|
529
|
+
for (const child of node.children) resolveCustomContainers(child);
|
|
530
|
+
};
|
|
531
|
+
const placeEscaped = (node, containingBox, onCommit) => {
|
|
532
|
+
const container = Yoga.Node.create(config);
|
|
533
|
+
container.setWidth(containingBox.width);
|
|
534
|
+
container.setHeight(containingBox.height);
|
|
535
|
+
container.setPositionType(PositionType.Relative);
|
|
536
|
+
container.insertChild(node.yoga, 0);
|
|
537
|
+
try {
|
|
538
|
+
markBaselineMeasurementsDirty(node);
|
|
539
|
+
for (let pass = 0; pass < 3; pass += 1) {
|
|
540
|
+
container.calculateLayout(containingBox.width, containingBox.height, Direction.LTR);
|
|
541
|
+
resolveCustomContainers(node);
|
|
542
|
+
}
|
|
543
|
+
if (applyAutomaticMinimums(node)) {
|
|
544
|
+
container.calculateLayout(containingBox.width, containingBox.height, Direction.LTR);
|
|
545
|
+
resolveCustomContainers(node);
|
|
546
|
+
container.calculateLayout(containingBox.width, containingBox.height, Direction.LTR);
|
|
547
|
+
}
|
|
548
|
+
container.calculateLayout(containingBox.width, containingBox.height, Direction.LTR);
|
|
549
|
+
commit(node, {
|
|
550
|
+
x: containingBox.x,
|
|
551
|
+
y: containingBox.y
|
|
552
|
+
}, onCommit);
|
|
553
|
+
} finally {
|
|
554
|
+
container.removeChild(node.yoga);
|
|
555
|
+
container.free();
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
const commit = (node, origin, onCommit) => {
|
|
559
|
+
const box = {
|
|
560
|
+
x: origin.x + node.yoga.getComputedLeft(),
|
|
561
|
+
y: origin.y + node.yoga.getComputedTop(),
|
|
562
|
+
width: node.yoga.getComputedWidth(),
|
|
563
|
+
height: node.yoga.getComputedHeight()
|
|
564
|
+
};
|
|
565
|
+
onCommit(node.view, box);
|
|
566
|
+
for (const child of node.children) commit(child, {
|
|
567
|
+
x: box.x,
|
|
568
|
+
y: box.y
|
|
569
|
+
}, onCommit);
|
|
570
|
+
for (const child of node.escaped) placeEscaped(child, box, onCommit);
|
|
571
|
+
};
|
|
572
|
+
const freeEscaped = (node) => {
|
|
573
|
+
for (const child of node.escaped) {
|
|
574
|
+
child.yoga.freeRecursive();
|
|
575
|
+
freeEscaped(child);
|
|
576
|
+
}
|
|
577
|
+
for (const child of node.children) freeEscaped(child);
|
|
578
|
+
};
|
|
579
|
+
return {
|
|
580
|
+
createRoot(spec) {
|
|
581
|
+
const yoga = Yoga.Node.create(config);
|
|
582
|
+
const customHandler = findCustomHandler(spec.style.display);
|
|
583
|
+
yoga.setWidth(dimensions.width);
|
|
584
|
+
yoga.setHeight(dimensions.height);
|
|
585
|
+
yoga.setPositionType(PositionType.Relative);
|
|
586
|
+
applyBlockFlexStyle(yoga, spec.style, { display: "block" }, true, true, customHandler !== void 0);
|
|
587
|
+
const view = {
|
|
588
|
+
path: spec.path,
|
|
589
|
+
style: spec.style,
|
|
590
|
+
isRoot: true,
|
|
591
|
+
isContainer: true,
|
|
592
|
+
children: []
|
|
593
|
+
};
|
|
594
|
+
const root = {
|
|
595
|
+
view,
|
|
596
|
+
yoga,
|
|
597
|
+
path: spec.path,
|
|
598
|
+
style: spec.style,
|
|
599
|
+
isRoot: true,
|
|
600
|
+
isContainer: true,
|
|
601
|
+
propagatesBaseline: true,
|
|
602
|
+
customHandler,
|
|
603
|
+
children: [],
|
|
604
|
+
escaped: []
|
|
605
|
+
};
|
|
606
|
+
internalNodes.set(view, root);
|
|
607
|
+
rootNode = root;
|
|
608
|
+
return view;
|
|
609
|
+
},
|
|
610
|
+
createNode(spec, parent) {
|
|
611
|
+
const parentInternal = asInternal(parent);
|
|
612
|
+
const yoga = Yoga.Node.create(config);
|
|
613
|
+
const customHandler = spec.isContainer ? findCustomHandler(spec.style.display) : void 0;
|
|
614
|
+
applyBlockFlexStyle(yoga, spec.style, parentInternal.style, false, spec.isContainer, customHandler !== void 0);
|
|
615
|
+
if (!spec.isContainer && spec.padding !== void 0) {
|
|
616
|
+
yoga.setPadding(Edge.Top, spec.padding.top);
|
|
617
|
+
yoga.setPadding(Edge.Right, spec.padding.right);
|
|
618
|
+
yoga.setPadding(Edge.Bottom, spec.padding.bottom);
|
|
619
|
+
yoga.setPadding(Edge.Left, spec.padding.left);
|
|
620
|
+
}
|
|
621
|
+
const width = spec.contractWidth ?? spec.style.width;
|
|
622
|
+
const height = spec.contractHeight ?? spec.style.height;
|
|
623
|
+
if (width !== void 0) setLength(yoga, "width", width);
|
|
624
|
+
if (height !== void 0) setLength(yoga, "height", height);
|
|
625
|
+
if (spec.style.position === "absolute") {
|
|
626
|
+
if (spec.style.left === void 0 && spec.style.inset === void 0 && spec.style.right === void 0 && spec.contractX !== void 0) yoga.setPosition(Edge.Left, spec.contractX);
|
|
627
|
+
if (spec.style.top === void 0 && spec.style.inset === void 0 && spec.style.bottom === void 0 && spec.contractY !== void 0) yoga.setPosition(Edge.Top, spec.contractY);
|
|
628
|
+
}
|
|
629
|
+
const childViews = [];
|
|
630
|
+
const view = {
|
|
631
|
+
path: spec.path,
|
|
632
|
+
style: spec.style,
|
|
633
|
+
isRoot: false,
|
|
634
|
+
isContainer: spec.isContainer,
|
|
635
|
+
...spec.contractWidth === void 0 ? {} : { contractWidth: spec.contractWidth },
|
|
636
|
+
...spec.contractHeight === void 0 ? {} : { contractHeight: spec.contractHeight },
|
|
637
|
+
...spec.padding === void 0 ? {} : { padding: spec.padding },
|
|
638
|
+
children: childViews
|
|
639
|
+
};
|
|
640
|
+
const node = {
|
|
641
|
+
view,
|
|
642
|
+
yoga,
|
|
643
|
+
path: spec.path,
|
|
644
|
+
style: spec.style,
|
|
645
|
+
isRoot: false,
|
|
646
|
+
isContainer: spec.isContainer,
|
|
647
|
+
propagatesBaseline: spec.propagatesBaseline ?? false,
|
|
648
|
+
...spec.contractWidth === void 0 ? {} : { contractWidth: spec.contractWidth },
|
|
649
|
+
...spec.contractHeight === void 0 ? {} : { contractHeight: spec.contractHeight },
|
|
650
|
+
...spec.contractX === void 0 ? {} : { contractX: spec.contractX },
|
|
651
|
+
...spec.contractY === void 0 ? {} : { contractY: spec.contractY },
|
|
652
|
+
...spec.measure === void 0 ? {} : { measure: spec.measure },
|
|
653
|
+
...customHandler === void 0 ? {} : { customHandler },
|
|
654
|
+
parent: parentInternal,
|
|
655
|
+
children: [],
|
|
656
|
+
escaped: []
|
|
657
|
+
};
|
|
658
|
+
internalNodes.set(view, node);
|
|
659
|
+
if (spec.measure !== void 0) {
|
|
660
|
+
const measure = spec.measure;
|
|
661
|
+
const measureFunction = (availWidth, widthMode) => {
|
|
662
|
+
const measured = measure(widthMode === MeasureMode.Undefined ? {} : {
|
|
663
|
+
availableWidth: availWidth,
|
|
664
|
+
widthMode: widthMode === MeasureMode.Exactly ? "exactly" : "at-most"
|
|
665
|
+
});
|
|
666
|
+
return {
|
|
667
|
+
width: widthMode === MeasureMode.Exactly ? availWidth : measured?.width ?? 0,
|
|
668
|
+
height: measured?.height ?? 0
|
|
669
|
+
};
|
|
670
|
+
};
|
|
671
|
+
node.measureFunction = measureFunction;
|
|
672
|
+
yoga.setMeasureFunc(measureFunction);
|
|
673
|
+
}
|
|
674
|
+
return view;
|
|
675
|
+
},
|
|
676
|
+
appendChild(parent, child) {
|
|
677
|
+
const parentInternal = asInternal(parent);
|
|
678
|
+
const childInternal = asInternal(child);
|
|
679
|
+
childInternal.parent = parentInternal;
|
|
680
|
+
if (childInternal.style.position === "absolute") {
|
|
681
|
+
const cb = containingBlock(parentInternal);
|
|
682
|
+
if (cb !== parentInternal) {
|
|
683
|
+
cb.escaped.push(childInternal);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (parentInternal.customHandler !== void 0 && childInternal.style.position !== "absolute") childInternal.yoga.setPositionType(PositionType.Absolute);
|
|
688
|
+
parentInternal.yoga.insertChild(childInternal.yoga, parentInternal.children.length);
|
|
689
|
+
parentInternal.children.push(childInternal);
|
|
690
|
+
parentInternal.view.children.push(child);
|
|
691
|
+
},
|
|
692
|
+
requiresLooseLayout(style) {
|
|
693
|
+
return style.position === "absolute" || style.position === "relative" || style.aspectRatio !== void 0 || style.width !== void 0 || style.height !== void 0 || style.minWidth !== void 0 || style.minHeight !== void 0 || style.maxWidth !== void 0 || style.maxHeight !== void 0;
|
|
694
|
+
},
|
|
695
|
+
positionLooseGeometry(node) {
|
|
696
|
+
const internal = asInternal(node);
|
|
697
|
+
if (internal.isRoot) return;
|
|
698
|
+
const x = internal.contractX ?? 0;
|
|
699
|
+
const y = internal.contractY ?? 0;
|
|
700
|
+
if (internal.style.position === "absolute") {
|
|
701
|
+
if (internal.style.left === void 0 && internal.style.inset === void 0 && internal.style.right === void 0) internal.yoga.setPosition(Edge.Left, x);
|
|
702
|
+
if (internal.style.top === void 0 && internal.style.inset === void 0 && internal.style.bottom === void 0) internal.yoga.setPosition(Edge.Top, y);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const offset = (start, end, basis) => {
|
|
706
|
+
if (typeof start === "number") return start;
|
|
707
|
+
if (typeof start === "string" && start.endsWith("%")) return Number(start.slice(0, -1)) * basis / 100;
|
|
708
|
+
if (typeof end === "number") return -end;
|
|
709
|
+
if (typeof end === "string" && end.endsWith("%")) return -(Number(end.slice(0, -1)) * basis) / 100;
|
|
710
|
+
return 0;
|
|
711
|
+
};
|
|
712
|
+
const left = offset(internal.style.left ?? internal.style.inset, internal.style.right ?? internal.style.inset, dimensions.width);
|
|
713
|
+
const top = offset(internal.style.top ?? internal.style.inset, internal.style.bottom ?? internal.style.inset, dimensions.height);
|
|
714
|
+
internal.yoga.setPositionType(PositionType.Absolute);
|
|
715
|
+
internal.yoga.setPositionAuto(Edge.Right);
|
|
716
|
+
internal.yoga.setPositionAuto(Edge.Bottom);
|
|
717
|
+
internal.yoga.setPosition(Edge.Left, x + left);
|
|
718
|
+
internal.yoga.setPosition(Edge.Top, y + top);
|
|
719
|
+
internal.yoga.setAlwaysFormsContainingBlock(true);
|
|
720
|
+
},
|
|
721
|
+
solve(onCommit) {
|
|
722
|
+
if (rootNode === void 0) throw new Error("Layout solver root has not been initialized");
|
|
723
|
+
const root = rootNode;
|
|
724
|
+
try {
|
|
725
|
+
prepareTextBaselines(root);
|
|
726
|
+
root.yoga.calculateLayout(dimensions.width, dimensions.height, Direction.LTR);
|
|
727
|
+
for (let pass = 0; pass < 3; pass += 1) {
|
|
728
|
+
resolveCustomContainers(root);
|
|
729
|
+
root.yoga.calculateLayout(dimensions.width, dimensions.height, Direction.LTR);
|
|
730
|
+
}
|
|
731
|
+
if (markBaselineMeasurementsDirty(root)) root.yoga.calculateLayout(dimensions.width, dimensions.height, Direction.LTR);
|
|
732
|
+
if (applyAutomaticMinimums(root)) {
|
|
733
|
+
root.yoga.calculateLayout(dimensions.width, dimensions.height, Direction.LTR);
|
|
734
|
+
resolveCustomContainers(root);
|
|
735
|
+
root.yoga.calculateLayout(dimensions.width, dimensions.height, Direction.LTR);
|
|
736
|
+
}
|
|
737
|
+
commit(root, {
|
|
738
|
+
x: 0,
|
|
739
|
+
y: 0
|
|
740
|
+
}, onCommit);
|
|
741
|
+
} finally {
|
|
742
|
+
root.yoga.freeRecursive();
|
|
743
|
+
freeEscaped(root);
|
|
744
|
+
config.free();
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
export { blockFlexLayoutProperties, createBlockFlexLayoutSolver, isStyleRecord, paddingStyleKeys, parseLayoutLength, styleLength, validateBlockFlexContainerContext, validateBlockFlexContainerProperties, validateBlockFlexLayoutContextBounds };
|