@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,166 @@
|
|
|
1
|
+
import { masterTextStyleCategoryForRole } from "../../../core/dist/placeholders.js";
|
|
2
|
+
import "../../../core/dist/capability.js";
|
|
3
|
+
// ../capabilities/dist/shared/style-inheritance.js
|
|
4
|
+
function replaceWhenDeclared(inherited, localValue, isDeclaredLocally) {
|
|
5
|
+
return isDeclaredLocally && localValue !== void 0 ? localValue : inherited;
|
|
6
|
+
}
|
|
7
|
+
function levelRule() {
|
|
8
|
+
return {
|
|
9
|
+
freeContainer: "inherit",
|
|
10
|
+
placeholderLayer: "levelStyle",
|
|
11
|
+
apply: replaceWhenDeclared
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function bodyRule(freeContainer) {
|
|
15
|
+
return {
|
|
16
|
+
freeContainer,
|
|
17
|
+
placeholderLayer: "bodyPr",
|
|
18
|
+
apply: replaceWhenDeclared
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function spPrRule() {
|
|
22
|
+
return {
|
|
23
|
+
freeContainer: "localOnly",
|
|
24
|
+
placeholderLayer: "spPr",
|
|
25
|
+
apply: replaceWhenDeclared
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const sharedStyleRules = Object.freeze({
|
|
29
|
+
fontFamily: levelRule(),
|
|
30
|
+
fontSize: levelRule(),
|
|
31
|
+
fontWeight: levelRule(),
|
|
32
|
+
fontStyle: levelRule(),
|
|
33
|
+
color: levelRule(),
|
|
34
|
+
letterSpacing: levelRule(),
|
|
35
|
+
textTransform: levelRule(),
|
|
36
|
+
textDecoration: levelRule(),
|
|
37
|
+
textShadow: {
|
|
38
|
+
freeContainer: "inherit",
|
|
39
|
+
placeholderLayer: "levelStyle",
|
|
40
|
+
apply(inherited, localValue, isDeclaredLocally) {
|
|
41
|
+
if (!isDeclaredLocally || localValue === void 0) return inherited;
|
|
42
|
+
return localValue === "none" ? void 0 : localValue;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
lang: levelRule(),
|
|
46
|
+
lineHeight: levelRule(),
|
|
47
|
+
align: levelRule(),
|
|
48
|
+
spacingAfter: levelRule(),
|
|
49
|
+
verticalAlign: bodyRule("inherit"),
|
|
50
|
+
textWrap: bodyRule("inherit"),
|
|
51
|
+
padding: bodyRule("localOnly"),
|
|
52
|
+
paddingTop: bodyRule("localOnly"),
|
|
53
|
+
paddingRight: bodyRule("localOnly"),
|
|
54
|
+
paddingBottom: bodyRule("localOnly"),
|
|
55
|
+
paddingLeft: bodyRule("localOnly"),
|
|
56
|
+
backgroundColor: spPrRule(),
|
|
57
|
+
backgroundImage: spPrRule(),
|
|
58
|
+
borderColor: spPrRule(),
|
|
59
|
+
borderWidth: spPrRule(),
|
|
60
|
+
borderStyle: spPrRule(),
|
|
61
|
+
borderRadius: spPrRule(),
|
|
62
|
+
opacity: spPrRule(),
|
|
63
|
+
boxShadow: spPrRule(),
|
|
64
|
+
softEdge: spPrRule(),
|
|
65
|
+
rotate: spPrRule()
|
|
66
|
+
});
|
|
67
|
+
/** True iff `key` is an own defined declaration on `record`, honoring explicit `undefined` removal. */
|
|
68
|
+
function hasLocalDeclaration(record, key) {
|
|
69
|
+
return record !== void 0 && Object.hasOwn(record, key) && record[key] !== void 0;
|
|
70
|
+
}
|
|
71
|
+
/** Collects the subset of `keys` explicitly declared with defined values on `record`. */
|
|
72
|
+
function localDeclaredKeySet(record, keys) {
|
|
73
|
+
const result = /* @__PURE__ */ new Set();
|
|
74
|
+
if (record === void 0) return result;
|
|
75
|
+
for (const key of keys) if (hasLocalDeclaration(record, key)) result.add(key);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
function levelStyleEntry(styles, levelIndex0) {
|
|
79
|
+
if (styles === void 0) return void 0;
|
|
80
|
+
return styles[Math.min(9, Math.max(1, levelIndex0 + 1))];
|
|
81
|
+
}
|
|
82
|
+
function applyLayer(accumulator, source, layerFilter) {
|
|
83
|
+
if (source === void 0) return;
|
|
84
|
+
for (const [key, rawRule] of Object.entries(sharedStyleRules)) {
|
|
85
|
+
const rule = rawRule;
|
|
86
|
+
if (layerFilter !== "all" && rule.placeholderLayer !== layerFilter) continue;
|
|
87
|
+
if (!hasLocalDeclaration(source, key)) continue;
|
|
88
|
+
const next = rule.apply(accumulator[key], source[key], true);
|
|
89
|
+
if (next === void 0) delete accumulator[key];
|
|
90
|
+
else accumulator[key] = next;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Evaluates Path B placeholder container defaults (`bodyPr` + level-0 base text properties):
|
|
95
|
+
* Master Theme -> Master txStyles -> Master Ph -> Layout Ph -> Slide local style.
|
|
96
|
+
* Note: Deck.style and Slide.style are intentionally excluded.
|
|
97
|
+
*/
|
|
98
|
+
function resolvePlaceholderBaseTextStyle(placeholder, slideLocalStyle) {
|
|
99
|
+
const result = {};
|
|
100
|
+
const role = placeholder.layoutPlaceholder?.type ?? placeholder.nativeRef.type;
|
|
101
|
+
const category = masterTextStyleCategoryForRole(role);
|
|
102
|
+
const masterTxLevel1 = levelStyleEntry(placeholder.masterTextStyles?.[category], 0);
|
|
103
|
+
const masterPhStyle = placeholder.masterPlaceholder?.style;
|
|
104
|
+
const masterPhLevel1 = levelStyleEntry(placeholder.masterPlaceholder?.listStyles, 0);
|
|
105
|
+
const layoutPhStyle = placeholder.layoutPlaceholder?.style;
|
|
106
|
+
const layoutPhLevel1 = levelStyleEntry(placeholder.layoutPlaceholder?.listStyles, 0);
|
|
107
|
+
applyLayer(result, masterTxLevel1, "levelStyle");
|
|
108
|
+
applyLayer(result, masterPhStyle, "all");
|
|
109
|
+
applyLayer(result, masterPhLevel1, "levelStyle");
|
|
110
|
+
applyLayer(result, layoutPhStyle, "all");
|
|
111
|
+
applyLayer(result, layoutPhLevel1, "levelStyle");
|
|
112
|
+
applyLayer(result, slideLocalStyle, "all");
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Evaluates level-specific paragraph/run defaults for a bound placeholder at `levelIndex0` (0..8),
|
|
117
|
+
* cascading Master txStyles -> Master Ph -> Layout Ph -> Slide local style -> P/Span local style.
|
|
118
|
+
*/
|
|
119
|
+
function resolvePlaceholderLevelTextStyle(placeholder, levelIndex0, slideLocalStyle) {
|
|
120
|
+
const result = {};
|
|
121
|
+
const role = placeholder.layoutPlaceholder?.type ?? placeholder.nativeRef.type;
|
|
122
|
+
const category = masterTextStyleCategoryForRole(role);
|
|
123
|
+
const masterTxLevel = levelStyleEntry(placeholder.masterTextStyles?.[category], levelIndex0);
|
|
124
|
+
const masterPhLevel = levelStyleEntry(placeholder.masterPlaceholder?.listStyles, levelIndex0);
|
|
125
|
+
const layoutPhLevel = levelStyleEntry(placeholder.layoutPlaceholder?.listStyles, levelIndex0);
|
|
126
|
+
applyLayer(result, masterTxLevel, "levelStyle");
|
|
127
|
+
applyLayer(result, placeholder.masterPlaceholder?.style, "levelStyle");
|
|
128
|
+
applyLayer(result, masterPhLevel, "levelStyle");
|
|
129
|
+
applyLayer(result, placeholder.layoutPlaceholder?.style, "levelStyle");
|
|
130
|
+
applyLayer(result, layoutPhLevel, "levelStyle");
|
|
131
|
+
applyLayer(result, slideLocalStyle, "levelStyle");
|
|
132
|
+
const resolvedList = layoutPhLevel?.list ?? masterPhLevel?.list ?? masterTxLevel?.list;
|
|
133
|
+
if (resolvedList !== void 0) result["list"] = resolvedList;
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Evaluates visual (`spPr`) style overrides on a bound placeholder along Path B
|
|
138
|
+
* without absorbing Deck.style or Slide.style.
|
|
139
|
+
*/
|
|
140
|
+
function resolvePlaceholderVisualStyle(placeholder, slideLocalStyle) {
|
|
141
|
+
const result = {};
|
|
142
|
+
applyLayer(result, placeholder.masterPlaceholder?.style, "spPr");
|
|
143
|
+
applyLayer(result, placeholder.layoutPlaceholder?.style, "spPr");
|
|
144
|
+
applyLayer(result, slideLocalStyle, "spPr");
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
/** Resolves effective box coordinates for a bound placeholder plus slide-local geometry tracking. */
|
|
148
|
+
function resolvePlaceholderGeometry(placeholder, props) {
|
|
149
|
+
const style = typeof props["style"] === "object" && props["style"] !== null && !Array.isArray(props["style"]) ? props["style"] : void 0;
|
|
150
|
+
const localWidth = style !== void 0 && hasLocalDeclaration(style, "width") ? style["width"] : hasLocalDeclaration(props, "width") ? props["width"] : void 0;
|
|
151
|
+
const localHeight = style !== void 0 && hasLocalDeclaration(style, "height") ? style["height"] : hasLocalDeclaration(props, "height") ? props["height"] : void 0;
|
|
152
|
+
const hasLocalX = hasLocalDeclaration(props, "x");
|
|
153
|
+
const hasLocalY = hasLocalDeclaration(props, "y");
|
|
154
|
+
const hasLocalWidth = localWidth !== void 0;
|
|
155
|
+
const hasLocalHeight = localHeight !== void 0;
|
|
156
|
+
const layoutPh = placeholder.layoutPlaceholder;
|
|
157
|
+
const masterPh = placeholder.masterPlaceholder;
|
|
158
|
+
return {
|
|
159
|
+
x: hasLocalX ? props["x"] : layoutPh?.x ?? masterPh?.x,
|
|
160
|
+
y: hasLocalY ? props["y"] : layoutPh?.y ?? masterPh?.y,
|
|
161
|
+
width: hasLocalWidth ? localWidth : layoutPh?.width ?? masterPh?.width,
|
|
162
|
+
height: hasLocalHeight ? localHeight : layoutPh?.height ?? masterPh?.height,
|
|
163
|
+
hasLocalBoxOverride: hasLocalX || hasLocalY || hasLocalWidth || hasLocalHeight
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export { hasLocalDeclaration, localDeclaredKeySet, resolvePlaceholderBaseTextStyle, resolvePlaceholderGeometry, resolvePlaceholderLevelTextStyle, resolvePlaceholderVisualStyle, sharedStyleRules };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// ../capabilities/dist/shared/style-parse.js
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function layoutStyleValue(input, name) {
|
|
6
|
+
const value = input.props["style"];
|
|
7
|
+
if (!isRecord(value)) return void 0;
|
|
8
|
+
const raw = value[name];
|
|
9
|
+
return typeof raw === "number" || raw === "auto" || typeof raw === "string" && raw.endsWith("%") ? raw : void 0;
|
|
10
|
+
}
|
|
11
|
+
export { layoutStyleValue };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import { authorIdSchema } from "../../../core/dist/author-ids.js";
|
|
3
|
+
import { layoutStyleSchema } from "../../../core/dist/layout-schemas.js";
|
|
4
|
+
import { textStyleSchema, validateTextStyle, visualStyleSchema } from "../../../core/dist/theme.js";
|
|
5
|
+
import { linkTargetSchema } from "../../../core/dist/author-schemas.js";
|
|
6
|
+
import { nativePlaceholderRefSchema, textListSchema } from "../../../core/dist/placeholders.js";
|
|
7
|
+
import "../../../core/dist/capability.js";
|
|
8
|
+
import { pxToEmu, xmlEscape } from "../../../emit/dist/ooxml.js";
|
|
9
|
+
import "../../../emit/dist/index.js";
|
|
10
|
+
import { motionPropsSchema } from "../motion/motion-schemas.js";
|
|
11
|
+
import { optionalNameSchema } from "./identity.js";
|
|
12
|
+
import { morphKeySchema } from "./morph-api.js";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
// ../capabilities/dist/shared/text-schemas.js
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
const coreTextStyleShape = textStyleSchema.unwrap().shape;
|
|
19
|
+
const runStyleObjectSchema = z.strictObject({
|
|
20
|
+
fontFamily: coreTextStyleShape.fontFamily,
|
|
21
|
+
fontSize: coreTextStyleShape.fontSize,
|
|
22
|
+
fontWeight: coreTextStyleShape.fontWeight,
|
|
23
|
+
fontStyle: coreTextStyleShape.fontStyle,
|
|
24
|
+
color: coreTextStyleShape.color,
|
|
25
|
+
letterSpacing: coreTextStyleShape.letterSpacing,
|
|
26
|
+
textTransform: coreTextStyleShape.textTransform,
|
|
27
|
+
textDecoration: coreTextStyleShape.textDecoration,
|
|
28
|
+
textShadow: coreTextStyleShape.textShadow,
|
|
29
|
+
lang: coreTextStyleShape.lang
|
|
30
|
+
});
|
|
31
|
+
/** Run-level style schema shared by `Span` and `SlideNumber`. */
|
|
32
|
+
const runStyleSchema = runStyleObjectSchema.readonly();
|
|
33
|
+
const paragraphStyleObjectSchema = runStyleObjectSchema.extend({
|
|
34
|
+
lineHeight: coreTextStyleShape.lineHeight,
|
|
35
|
+
align: coreTextStyleShape.align,
|
|
36
|
+
spacingAfter: coreTextStyleShape.spacingAfter,
|
|
37
|
+
list: textListSchema.optional()
|
|
38
|
+
});
|
|
39
|
+
/** Paragraph-level style schema shared by `P` across Text, Shape, Table Cell, and Notes. */
|
|
40
|
+
const paragraphStyleSchema = paragraphStyleObjectSchema.readonly();
|
|
41
|
+
const runStyleKeys = new Set(Object.keys(runStyleObjectSchema.shape));
|
|
42
|
+
const paragraphStyleKeys = new Set(Object.keys(paragraphStyleObjectSchema.shape));
|
|
43
|
+
/** Coordinate bounds for text box `x` and `y` in logical pixels. */
|
|
44
|
+
const textCoordinateSchema = z.number().finite().min(-1e6).max(1e6);
|
|
45
|
+
/** Positive pixel dimension bounds convertible to DrawingML EMU. */
|
|
46
|
+
const textPositiveSizeSchema = z.number().finite().positive().refine((value) => {
|
|
47
|
+
const extent = pxToEmu(value);
|
|
48
|
+
return extent >= 1 && extent <= 2147483647;
|
|
49
|
+
}, "Converted value exceeds shape dimension range");
|
|
50
|
+
const nonNegativeInsetSchema = z.number().finite().nonnegative().refine((value) => {
|
|
51
|
+
const converted = pxToEmu(value);
|
|
52
|
+
return Number.isSafeInteger(converted);
|
|
53
|
+
}, "Inset must be within DrawingML EMU range");
|
|
54
|
+
const textPaddingValueSchema = z.union([
|
|
55
|
+
nonNegativeInsetSchema,
|
|
56
|
+
z.tuple([nonNegativeInsetSchema, nonNegativeInsetSchema]),
|
|
57
|
+
z.tuple([
|
|
58
|
+
nonNegativeInsetSchema,
|
|
59
|
+
nonNegativeInsetSchema,
|
|
60
|
+
nonNegativeInsetSchema,
|
|
61
|
+
nonNegativeInsetSchema
|
|
62
|
+
])
|
|
63
|
+
]);
|
|
64
|
+
const textInsetsStyleSchema = z.object({
|
|
65
|
+
padding: textPaddingValueSchema.optional(),
|
|
66
|
+
paddingTop: nonNegativeInsetSchema.optional(),
|
|
67
|
+
paddingRight: nonNegativeInsetSchema.optional(),
|
|
68
|
+
paddingBottom: nonNegativeInsetSchema.optional(),
|
|
69
|
+
paddingLeft: nonNegativeInsetSchema.optional()
|
|
70
|
+
}).readonly();
|
|
71
|
+
const textBoxStyleSchema = z.strictObject({
|
|
72
|
+
...layoutStyleSchema.unwrap().shape,
|
|
73
|
+
...coreTextStyleShape,
|
|
74
|
+
...visualStyleSchema.unwrap().shape
|
|
75
|
+
}).readonly();
|
|
76
|
+
const motionPropsShape = motionPropsSchema.unwrap().shape;
|
|
77
|
+
const textAuthorPropsObjectSchema = z.strictObject({
|
|
78
|
+
id: authorIdSchema.optional(),
|
|
79
|
+
name: optionalNameSchema.optional(),
|
|
80
|
+
placeholder: z.string().optional(),
|
|
81
|
+
nativePlaceholder: nativePlaceholderRefSchema.optional(),
|
|
82
|
+
morphKey: morphKeySchema.optional(),
|
|
83
|
+
link: linkTargetSchema.optional(),
|
|
84
|
+
x: textCoordinateSchema.optional(),
|
|
85
|
+
y: textCoordinateSchema.optional(),
|
|
86
|
+
width: textPositiveSizeSchema.optional(),
|
|
87
|
+
height: z.union([textPositiveSizeSchema, z.literal("auto")]).optional(),
|
|
88
|
+
style: textBoxStyleSchema.optional(),
|
|
89
|
+
enter: motionPropsShape.enter,
|
|
90
|
+
emphasis: motionPropsShape.emphasis,
|
|
91
|
+
motion: motionPropsShape.motion
|
|
92
|
+
});
|
|
93
|
+
const textAuthorPropsSchema = textAuthorPropsObjectSchema.readonly();
|
|
94
|
+
const textBoxAllowedParamKeys = /* @__PURE__ */ new Set([...Object.keys(textAuthorPropsObjectSchema.shape), "children"]);
|
|
95
|
+
const paragraphAuthorPropsSchema = z.strictObject({
|
|
96
|
+
id: authorIdSchema.optional(),
|
|
97
|
+
style: paragraphStyleSchema.optional()
|
|
98
|
+
}).readonly();
|
|
99
|
+
const spanAuthorPropsSchema = z.strictObject({
|
|
100
|
+
id: authorIdSchema.optional(),
|
|
101
|
+
style: runStyleSchema.optional()
|
|
102
|
+
}).readonly();
|
|
103
|
+
const slideNumberAuthorPropsSchema = spanAuthorPropsSchema;
|
|
104
|
+
/** Parses and validates a paragraph list declaration, preserving DrawingML error codes. */
|
|
105
|
+
function parseTextList(value) {
|
|
106
|
+
if (!isRecord(value) || value["type"] !== "bullet" && value["type"] !== "number") throw new CapabilityError("invalid-list", "list.type must be bullet or number");
|
|
107
|
+
const parsed = textListSchema.safeParse(value);
|
|
108
|
+
if (!parsed.success) {
|
|
109
|
+
const issue = parsed.error.issues[0];
|
|
110
|
+
if (issue?.code === "unrecognized_keys") throw new CapabilityError("unknown-style-property", `list contains unimplemented style ${issue.keys[0]}`);
|
|
111
|
+
const field = issue?.path[0];
|
|
112
|
+
if (field === "level") throw new CapabilityError("invalid-list", "list.level must be an integer between 0 and 8");
|
|
113
|
+
if (field === "character") throw new CapabilityError("invalid-list", "Bullet must be a single Unicode character");
|
|
114
|
+
if (field === "style") throw new CapabilityError("invalid-list", "Numbering style currently only supports arabicPeriod");
|
|
115
|
+
if (field === "startAt") throw new CapabilityError("invalid-list", "Numbering start value must be an integer between 1 and 32767");
|
|
116
|
+
throw new CapabilityError("invalid-list", issue?.message ?? "Invalid list");
|
|
117
|
+
}
|
|
118
|
+
if (parsed.data.type === "bullet") {
|
|
119
|
+
const character = parsed.data.character ?? "•";
|
|
120
|
+
try {
|
|
121
|
+
xmlEscape(character);
|
|
122
|
+
} catch {
|
|
123
|
+
throw new CapabilityError("invalid-xml-character", "Bullet contains characters not allowed in XML 1.0");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return parsed.data;
|
|
127
|
+
}
|
|
128
|
+
function checkedStyleObject(value, allowedKeys, label) {
|
|
129
|
+
if (value === void 0) return {};
|
|
130
|
+
if (!isRecord(value)) throw new CapabilityError("invalid-style", `${label} must be an object`);
|
|
131
|
+
const unknown = Object.keys(value).find((key) => !allowedKeys.has(key));
|
|
132
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-style-property", `${label} contains unimplemented style ${unknown}`);
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
/** Validates run-level style declarations using shared core text schemas. */
|
|
136
|
+
function parseRunStyle(value, label = "Span.style") {
|
|
137
|
+
const props = checkedStyleObject(value, runStyleKeys, label);
|
|
138
|
+
return validateTextStyle(props);
|
|
139
|
+
}
|
|
140
|
+
/** Validates paragraph-level style declarations including `list`. */
|
|
141
|
+
function parseParagraphStyle(value, label = "P.style") {
|
|
142
|
+
const { list, ...textProps } = checkedStyleObject(value, paragraphStyleKeys, label);
|
|
143
|
+
validateTextStyle(textProps);
|
|
144
|
+
const parsedList = list === void 0 ? void 0 : parseTextList(list);
|
|
145
|
+
return {
|
|
146
|
+
...textProps,
|
|
147
|
+
...parsedList === void 0 ? {} : { list: parsedList }
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** Validates text box padding/inset declarations via Zod and converts edges to pixel numbers. */
|
|
151
|
+
function parseTextInsets(value) {
|
|
152
|
+
const style = isRecord(value) ? value : {};
|
|
153
|
+
const candidate = {
|
|
154
|
+
...style["padding"] === void 0 ? {} : { padding: style["padding"] },
|
|
155
|
+
...style["paddingTop"] === void 0 ? {} : { paddingTop: style["paddingTop"] },
|
|
156
|
+
...style["paddingRight"] === void 0 ? {} : { paddingRight: style["paddingRight"] },
|
|
157
|
+
...style["paddingBottom"] === void 0 ? {} : { paddingBottom: style["paddingBottom"] },
|
|
158
|
+
...style["paddingLeft"] === void 0 ? {} : { paddingLeft: style["paddingLeft"] }
|
|
159
|
+
};
|
|
160
|
+
const parsed = textInsetsStyleSchema.safeParse(candidate);
|
|
161
|
+
if (!parsed.success) {
|
|
162
|
+
const issue = parsed.error.issues[0];
|
|
163
|
+
if (issue?.path[0] === "padding") {
|
|
164
|
+
const rawPadding = candidate.padding;
|
|
165
|
+
const isTupleOrNumber = typeof rawPadding === "number" || Array.isArray(rawPadding) && (rawPadding.length === 2 || rawPadding.length === 4);
|
|
166
|
+
throw new CapabilityError("invalid-text-insets", isTupleOrNumber ? "padding inset must be a finite non-negative pixel number" : "padding must be a number, a 2-tuple, or a 4-tuple");
|
|
167
|
+
}
|
|
168
|
+
const edge = String(issue?.path[0] ?? "padding").replace("padding", "");
|
|
169
|
+
const label = edge === "" ? "padding" : edge.toLowerCase();
|
|
170
|
+
throw new CapabilityError("invalid-text-insets", `${label} inset must be a finite non-negative pixel number`);
|
|
171
|
+
}
|
|
172
|
+
const raw = parsed.data.padding;
|
|
173
|
+
let edges = {
|
|
174
|
+
top: 0,
|
|
175
|
+
right: 0,
|
|
176
|
+
bottom: 0,
|
|
177
|
+
left: 0
|
|
178
|
+
};
|
|
179
|
+
if (typeof raw === "number") edges = {
|
|
180
|
+
top: raw,
|
|
181
|
+
right: raw,
|
|
182
|
+
bottom: raw,
|
|
183
|
+
left: raw
|
|
184
|
+
};
|
|
185
|
+
else if (Array.isArray(raw)) edges = raw.length === 2 ? {
|
|
186
|
+
top: raw[0],
|
|
187
|
+
right: raw[1],
|
|
188
|
+
bottom: raw[0],
|
|
189
|
+
left: raw[1]
|
|
190
|
+
} : {
|
|
191
|
+
top: raw[0],
|
|
192
|
+
right: raw[1],
|
|
193
|
+
bottom: raw[2],
|
|
194
|
+
left: raw[3]
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
top: parsed.data.paddingTop ?? edges.top,
|
|
198
|
+
right: parsed.data.paddingRight ?? edges.right,
|
|
199
|
+
bottom: parsed.data.paddingBottom ?? edges.bottom,
|
|
200
|
+
left: parsed.data.paddingLeft ?? edges.left
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Validates a text box coordinate (`x` or `y`) with Zod schema bounds. */
|
|
204
|
+
function parseTextCoordinate(value, label, path) {
|
|
205
|
+
const parsed = textCoordinateSchema.safeParse(value);
|
|
206
|
+
if (!parsed.success) throw new CapabilityError("invalid-text-box", `${label} must be a finite pixel number between -1000000 and 1000000`, path);
|
|
207
|
+
return parsed.data;
|
|
208
|
+
}
|
|
209
|
+
/** Validates a text box extent (`width` or `height`) with Zod schema bounds. */
|
|
210
|
+
function parseTextExtent(value, label, path) {
|
|
211
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) throw new CapabilityError("invalid-text-box", `${label} must be a finite positive pixel number`, path);
|
|
212
|
+
const parsed = textPositiveSizeSchema.safeParse(value);
|
|
213
|
+
if (!parsed.success) throw new CapabilityError("invalid-text-box", `${label} converted value exceeds shape dimension range`, path);
|
|
214
|
+
return parsed.data;
|
|
215
|
+
}
|
|
216
|
+
export { paragraphAuthorPropsSchema, paragraphStyleKeys, paragraphStyleSchema, parseParagraphStyle, parseRunStyle, parseTextCoordinate, parseTextExtent, parseTextInsets, parseTextList, runStyleKeys, runStyleSchema, slideNumberAuthorPropsSchema, spanAuthorPropsSchema, textAuthorPropsSchema, textBoxAllowedParamKeys, textBoxStyleSchema, textCoordinateSchema, textInsetsStyleSchema, textListSchema, textPaddingValueSchema, textPositiveSizeSchema };
|