@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,1153 @@
|
|
|
1
|
+
import { assertValidLang, schemeColorNameSchema } from "../../core/dist/theme.js";
|
|
2
|
+
import { allocatePlaceholderAuthorKeys, layoutPlaceholderSpecSchema, masterPlaceholderSpecSchema, masterTextStylesSchema, placeholderOrientSchema, placeholderRoleSchema, placeholderSzSchema } from "../../core/dist/placeholders.js";
|
|
3
|
+
import { slideLayoutTypeSchema } from "../../core/dist/masters.js";
|
|
4
|
+
import "../../core/dist/index.js";
|
|
5
|
+
import { createSlideLayoutNode, createSlideMasterNode } from "../../core/dist/document.js";
|
|
6
|
+
import { readAlternateContent } from "./alternate-content.js";
|
|
7
|
+
import { A_NS, P_NS, R_NS, XML_NS, emuToPx } from "./namespaces.js";
|
|
8
|
+
import { resolvePartPath } from "./opc.js";
|
|
9
|
+
import { inspectUnsupportedGraphicFrame, peekShapeTreeObjectIdentity } from "./resources.js";
|
|
10
|
+
import { isNonDefaultColorMap, readColorMapElement, readColorMapOverride, readThemeOverridePart, readThemePart } from "./themes.js";
|
|
11
|
+
import { readPlaceholderSpPrVisuals } from "./visual.js";
|
|
12
|
+
import { hexRgb6Schema, ooxmlBoolSchema, ooxmlIntSchema, ooxmlNonNegativeIntSchema, ooxmlPositiveIntSchema } from "./xml-fragments.js";
|
|
13
|
+
import { XmlElementCursor, parseXmlPart } from "./xml-reader.js";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
// ../import/dist/masters.js
|
|
16
|
+
const minimumMasterLayoutId = 2147483648;
|
|
17
|
+
const maximumMasterLayoutId = 4294967295;
|
|
18
|
+
const slideMasterAttrsSchema = z.object({ preserve: ooxmlBoolSchema.optional() });
|
|
19
|
+
const slideLayoutAttrsSchema = z.object({
|
|
20
|
+
type: slideLayoutTypeSchema.optional(),
|
|
21
|
+
preserve: ooxmlBoolSchema.optional(),
|
|
22
|
+
matchingName: z.string().optional(),
|
|
23
|
+
userDrawn: ooxmlBoolSchema.optional(),
|
|
24
|
+
showMasterSp: ooxmlBoolSchema.optional(),
|
|
25
|
+
showMasterPhAnim: ooxmlBoolSchema.optional()
|
|
26
|
+
});
|
|
27
|
+
const headerFooterAttrsSchema = z.object({
|
|
28
|
+
sldNum: ooxmlBoolSchema.optional(),
|
|
29
|
+
hdr: ooxmlBoolSchema.optional(),
|
|
30
|
+
ftr: ooxmlBoolSchema.optional(),
|
|
31
|
+
dt: ooxmlBoolSchema.optional()
|
|
32
|
+
});
|
|
33
|
+
function readHeaderFooterElement(parentCursor, partPath, diagnostics) {
|
|
34
|
+
const hf = parentCursor.child(P_NS, "hf");
|
|
35
|
+
if (hf === void 0) return void 0;
|
|
36
|
+
const raw = hf.attrsObject([
|
|
37
|
+
"sldNum",
|
|
38
|
+
"hdr",
|
|
39
|
+
"ftr",
|
|
40
|
+
"dt"
|
|
41
|
+
]);
|
|
42
|
+
const parsed = headerFooterAttrsSchema.safeParse(raw);
|
|
43
|
+
if (!parsed.success) {
|
|
44
|
+
diagnostics.push({
|
|
45
|
+
code: "invalid-xml-value",
|
|
46
|
+
category: "corrupt-input",
|
|
47
|
+
disposition: "omitted",
|
|
48
|
+
location: {
|
|
49
|
+
part: partPath,
|
|
50
|
+
xpath: hf.xpath
|
|
51
|
+
},
|
|
52
|
+
attributeOrElement: "p:hf",
|
|
53
|
+
rawValue: JSON.stringify(raw)
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const result = {
|
|
58
|
+
...parsed.data.dt === void 0 ? {} : { dateTime: parsed.data.dt },
|
|
59
|
+
...parsed.data.ftr === void 0 ? {} : { footer: parsed.data.ftr },
|
|
60
|
+
...parsed.data.hdr === void 0 ? {} : { header: parsed.data.hdr },
|
|
61
|
+
...parsed.data.sldNum === void 0 ? {} : { slideNumber: parsed.data.sldNum }
|
|
62
|
+
};
|
|
63
|
+
return Object.keys(result).length === 0 ? {} : result;
|
|
64
|
+
}
|
|
65
|
+
const defaultColorMap = {
|
|
66
|
+
bg1: "lt1",
|
|
67
|
+
tx1: "dk1",
|
|
68
|
+
bg2: "lt2",
|
|
69
|
+
tx2: "dk2",
|
|
70
|
+
accent1: "accent1",
|
|
71
|
+
accent2: "accent2",
|
|
72
|
+
accent3: "accent3",
|
|
73
|
+
accent4: "accent4",
|
|
74
|
+
accent5: "accent5",
|
|
75
|
+
accent6: "accent6",
|
|
76
|
+
hlink: "hlink",
|
|
77
|
+
folHlink: "folHlink"
|
|
78
|
+
};
|
|
79
|
+
function readColorModifierVal(colorCursor, localName) {
|
|
80
|
+
const mod = colorCursor.child(A_NS, localName);
|
|
81
|
+
if (mod === void 0) return void 0;
|
|
82
|
+
const parsed = ooxmlNonNegativeIntSchema.safeParse(mod.attr("val"));
|
|
83
|
+
return parsed.success ? Math.min(1, parsed.data / 1e5) : void 0;
|
|
84
|
+
}
|
|
85
|
+
function readStyleColor(containerCursor, _clrMap) {
|
|
86
|
+
const srgb = containerCursor.child(A_NS, "srgbClr");
|
|
87
|
+
const scheme = srgb === void 0 ? containerCursor.child(A_NS, "schemeClr") : void 0;
|
|
88
|
+
const colorCursor = srgb ?? scheme;
|
|
89
|
+
if (colorCursor === void 0) return void 0;
|
|
90
|
+
let baseColor;
|
|
91
|
+
if (srgb !== void 0) {
|
|
92
|
+
const parsed = hexRgb6Schema.safeParse(srgb.attr("val"));
|
|
93
|
+
if (!parsed.success) return void 0;
|
|
94
|
+
baseColor = `#${parsed.data.toUpperCase()}`;
|
|
95
|
+
} else if (scheme !== void 0) {
|
|
96
|
+
const parsedScheme = schemeColorNameSchema.safeParse(scheme.attr("val"));
|
|
97
|
+
const slot = parsedScheme.success ? parsedScheme.data : void 0;
|
|
98
|
+
if (slot === void 0) return void 0;
|
|
99
|
+
const rawLumMod = readColorModifierVal(colorCursor, "lumMod");
|
|
100
|
+
const rawLumOff = readColorModifierVal(colorCursor, "lumOff");
|
|
101
|
+
const tint = readColorModifierVal(colorCursor, "tint");
|
|
102
|
+
const lumMod = rawLumMod ?? (rawLumOff === void 0 && tint !== void 0 ? tint : void 0);
|
|
103
|
+
const lumOff = rawLumOff ?? (rawLumMod === void 0 && tint !== void 0 ? 1 - tint : void 0);
|
|
104
|
+
baseColor = lumMod !== void 0 ? {
|
|
105
|
+
slot,
|
|
106
|
+
lumMod,
|
|
107
|
+
...lumOff === void 0 ? {} : { lumOff }
|
|
108
|
+
} : slot;
|
|
109
|
+
}
|
|
110
|
+
if (baseColor === void 0) return void 0;
|
|
111
|
+
const alpha = readColorModifierVal(colorCursor, "alpha");
|
|
112
|
+
return alpha !== void 0 ? {
|
|
113
|
+
color: baseColor,
|
|
114
|
+
alpha
|
|
115
|
+
} : baseColor;
|
|
116
|
+
}
|
|
117
|
+
function readDefRPr(rPr, clrMap) {
|
|
118
|
+
const raw = rPr.attrsObject([
|
|
119
|
+
"lang",
|
|
120
|
+
"sz",
|
|
121
|
+
"b",
|
|
122
|
+
"i",
|
|
123
|
+
"u",
|
|
124
|
+
"strike",
|
|
125
|
+
"cap",
|
|
126
|
+
"spc",
|
|
127
|
+
"kern",
|
|
128
|
+
"dirty",
|
|
129
|
+
"smtClean",
|
|
130
|
+
"baseline"
|
|
131
|
+
]);
|
|
132
|
+
let lang;
|
|
133
|
+
if (raw["lang"] !== void 0) try {
|
|
134
|
+
lang = assertValidLang(raw["lang"]);
|
|
135
|
+
} catch {
|
|
136
|
+
lang = void 0;
|
|
137
|
+
}
|
|
138
|
+
const szParsed = ooxmlPositiveIntSchema.safeParse(raw["sz"]);
|
|
139
|
+
const fontSize = szParsed.success ? `${szParsed.data / 100}pt` : void 0;
|
|
140
|
+
const bParsed = ooxmlBoolSchema.safeParse(raw["b"]);
|
|
141
|
+
const fontWeight = bParsed.success ? bParsed.data ? "bold" : "normal" : void 0;
|
|
142
|
+
const iParsed = ooxmlBoolSchema.safeParse(raw["i"]);
|
|
143
|
+
const fontStyle = iParsed.success ? iParsed.data ? "italic" : "normal" : void 0;
|
|
144
|
+
const textDecoration = raw["u"] === "sng" ? "underline" : raw["strike"] === "sngStrike" ? "line-through" : raw["u"] === "none" && raw["strike"] === "noStrike" ? "none" : void 0;
|
|
145
|
+
const textTransform = raw["cap"] === "all" ? "uppercase" : raw["cap"] === "none" ? "none" : void 0;
|
|
146
|
+
const spcParsed = ooxmlIntSchema.safeParse(raw["spc"]);
|
|
147
|
+
const letterSpacing = spcParsed.success ? spcParsed.data / 75 : void 0;
|
|
148
|
+
const solidFill = rPr.child(A_NS, "solidFill");
|
|
149
|
+
const color = solidFill === void 0 ? void 0 : readStyleColor(solidFill, clrMap);
|
|
150
|
+
rPr.ignoreEmptyChild(A_NS, "noFill");
|
|
151
|
+
const latin = rPr.child(A_NS, "latin");
|
|
152
|
+
const ea = rPr.child(A_NS, "ea");
|
|
153
|
+
const cs = rPr.child(A_NS, "cs");
|
|
154
|
+
const fontCursor = latin ?? ea ?? cs;
|
|
155
|
+
let fontFamily;
|
|
156
|
+
if (fontCursor !== void 0) {
|
|
157
|
+
const typeface = fontCursor.attr("typeface");
|
|
158
|
+
fontCursor.consumeAttr("pitchFamily");
|
|
159
|
+
fontCursor.consumeAttr("charset");
|
|
160
|
+
fontCursor.consumeAttr("panose");
|
|
161
|
+
if (typeface !== void 0 && typeface.trim() !== "") {
|
|
162
|
+
if (typeface === "+mj-lt" || typeface === "+mj-ea" || typeface === "+mj-cs") fontFamily = "major";
|
|
163
|
+
else if (typeface === "+mn-lt" || typeface === "+mn-ea" || typeface === "+mn-cs") fontFamily = "minor";
|
|
164
|
+
else fontFamily = typeface;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const extra of [ea, cs]) if (extra !== void 0 && extra !== fontCursor) {
|
|
168
|
+
extra.consumeAttr("typeface");
|
|
169
|
+
extra.consumeAttr("pitchFamily");
|
|
170
|
+
extra.consumeAttr("charset");
|
|
171
|
+
extra.consumeAttr("panose");
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
...fontFamily === void 0 ? {} : { fontFamily },
|
|
175
|
+
...fontSize === void 0 ? {} : { fontSize },
|
|
176
|
+
...fontWeight === void 0 ? {} : { fontWeight },
|
|
177
|
+
...fontStyle === void 0 ? {} : { fontStyle },
|
|
178
|
+
...color === void 0 ? {} : { color },
|
|
179
|
+
...letterSpacing === void 0 ? {} : { letterSpacing },
|
|
180
|
+
...textTransform === void 0 ? {} : { textTransform },
|
|
181
|
+
...textDecoration === void 0 ? {} : { textDecoration },
|
|
182
|
+
...lang === void 0 ? {} : { lang }
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function readLevelParagraphProperties(pPr, levelIndex0, clrMap) {
|
|
186
|
+
const rawAttrs = pPr.attrsObject([
|
|
187
|
+
"marL",
|
|
188
|
+
"indent",
|
|
189
|
+
"algn",
|
|
190
|
+
"defTabSz",
|
|
191
|
+
"rtl",
|
|
192
|
+
"eaLnBrk",
|
|
193
|
+
"latinLnBrk",
|
|
194
|
+
"hangingPunct",
|
|
195
|
+
"fontAlgn"
|
|
196
|
+
]);
|
|
197
|
+
const marLParsed = ooxmlNonNegativeIntSchema.safeParse(rawAttrs["marL"]);
|
|
198
|
+
const marginLeft = marLParsed.success ? emuToPx(marLParsed.data) : void 0;
|
|
199
|
+
const indentParsed = ooxmlIntSchema.safeParse(rawAttrs["indent"]);
|
|
200
|
+
const indent = indentParsed.success ? emuToPx(indentParsed.data) : void 0;
|
|
201
|
+
const align = rawAttrs["algn"] === void 0 ? void 0 : {
|
|
202
|
+
l: "left",
|
|
203
|
+
ctr: "center",
|
|
204
|
+
r: "right",
|
|
205
|
+
just: "justify"
|
|
206
|
+
}[rawAttrs["algn"]];
|
|
207
|
+
const spcBef = pPr.child(A_NS, "spcBef");
|
|
208
|
+
const spcBefPts = spcBef?.child(A_NS, "spcPts");
|
|
209
|
+
(spcBef?.child(A_NS, "spcPct"))?.consumeAttr("val");
|
|
210
|
+
const spcBefVal = ooxmlNonNegativeIntSchema.safeParse(spcBefPts?.attr("val"));
|
|
211
|
+
const spacingBefore = spcBefVal.success ? spcBefVal.data / 75 : void 0;
|
|
212
|
+
const spcAft = pPr.child(A_NS, "spcAft");
|
|
213
|
+
const spcAftPts = spcAft?.child(A_NS, "spcPts");
|
|
214
|
+
(spcAft?.child(A_NS, "spcPct"))?.consumeAttr("val");
|
|
215
|
+
const spcAftVal = ooxmlNonNegativeIntSchema.safeParse(spcAftPts?.attr("val"));
|
|
216
|
+
const spacingAfter = spcAftVal.success ? spcAftVal.data / 75 : void 0;
|
|
217
|
+
const lnSpc = pPr.child(A_NS, "lnSpc");
|
|
218
|
+
const lnSpcPts = lnSpc?.child(A_NS, "spcPts");
|
|
219
|
+
(lnSpc?.child(A_NS, "spcPct"))?.consumeAttr("val");
|
|
220
|
+
const lnSpcVal = ooxmlPositiveIntSchema.safeParse(lnSpcPts?.attr("val"));
|
|
221
|
+
const lineHeight = lnSpcVal.success ? `${lnSpcVal.data / 100}pt` : void 0;
|
|
222
|
+
pPr.ignoreEmptyChild(A_NS, "buNone");
|
|
223
|
+
const buFont = pPr.child(A_NS, "buFont");
|
|
224
|
+
if (buFont !== void 0) {
|
|
225
|
+
buFont.consumeAttr("typeface");
|
|
226
|
+
buFont.consumeAttr("pitchFamily");
|
|
227
|
+
buFont.consumeAttr("charset");
|
|
228
|
+
buFont.consumeAttr("panose");
|
|
229
|
+
}
|
|
230
|
+
const buChar = pPr.child(A_NS, "buChar");
|
|
231
|
+
const buAutoNum = pPr.child(A_NS, "buAutoNum");
|
|
232
|
+
let list;
|
|
233
|
+
if (buChar !== void 0) {
|
|
234
|
+
const ch = buChar.attr("char");
|
|
235
|
+
if (ch !== void 0 && ch.length > 0) list = {
|
|
236
|
+
type: "bullet",
|
|
237
|
+
character: ch,
|
|
238
|
+
...levelIndex0 > 0 ? { level: levelIndex0 } : {}
|
|
239
|
+
};
|
|
240
|
+
} else if (buAutoNum !== void 0) {
|
|
241
|
+
buAutoNum.consumeAttr("type");
|
|
242
|
+
const startParsed = ooxmlPositiveIntSchema.safeParse(buAutoNum.attr("startAt"));
|
|
243
|
+
list = {
|
|
244
|
+
type: "number",
|
|
245
|
+
style: "arabicPeriod",
|
|
246
|
+
...startParsed.success ? { startAt: startParsed.data } : {},
|
|
247
|
+
...levelIndex0 > 0 ? { level: levelIndex0 } : {}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const defRPr = pPr.child(A_NS, "defRPr");
|
|
251
|
+
return {
|
|
252
|
+
...defRPr === void 0 ? {} : readDefRPr(defRPr, clrMap),
|
|
253
|
+
...list === void 0 ? {} : { list },
|
|
254
|
+
...marginLeft === void 0 ? {} : { marginLeft },
|
|
255
|
+
...indent === void 0 ? {} : { indent },
|
|
256
|
+
...spacingBefore === void 0 ? {} : { spacingBefore },
|
|
257
|
+
...align === void 0 ? {} : { align },
|
|
258
|
+
...lineHeight === void 0 ? {} : { lineHeight },
|
|
259
|
+
...spacingAfter === void 0 ? {} : { spacingAfter }
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function readPlaceholderListStyles(container, clrMap) {
|
|
263
|
+
if (container === void 0) return void 0;
|
|
264
|
+
const levels = {};
|
|
265
|
+
let count = 0;
|
|
266
|
+
for (const levelNum of [
|
|
267
|
+
1,
|
|
268
|
+
2,
|
|
269
|
+
3,
|
|
270
|
+
4,
|
|
271
|
+
5,
|
|
272
|
+
6,
|
|
273
|
+
7,
|
|
274
|
+
8,
|
|
275
|
+
9
|
|
276
|
+
]) {
|
|
277
|
+
const pPr = container.child(A_NS, `lvl${levelNum}pPr`);
|
|
278
|
+
if (pPr === void 0) continue;
|
|
279
|
+
levels[levelNum] = readLevelParagraphProperties(pPr, levelNum - 1, clrMap);
|
|
280
|
+
count += 1;
|
|
281
|
+
}
|
|
282
|
+
return count === 0 ? void 0 : levels;
|
|
283
|
+
}
|
|
284
|
+
function readMasterTextStyles(txStyles, clrMap) {
|
|
285
|
+
if (txStyles === void 0) return void 0;
|
|
286
|
+
const titleStyleCursor = txStyles.child(P_NS, "titleStyle");
|
|
287
|
+
const bodyStyleCursor = txStyles.child(P_NS, "bodyStyle");
|
|
288
|
+
const otherStyleCursor = txStyles.child(P_NS, "otherStyle");
|
|
289
|
+
const titleStyle = readPlaceholderListStyles(titleStyleCursor, clrMap);
|
|
290
|
+
const bodyStyle = readPlaceholderListStyles(bodyStyleCursor, clrMap);
|
|
291
|
+
const otherStyle = readPlaceholderListStyles(otherStyleCursor, clrMap);
|
|
292
|
+
const candidate = {
|
|
293
|
+
...titleStyle === void 0 ? {} : { titleStyle },
|
|
294
|
+
...bodyStyle === void 0 ? {} : { bodyStyle },
|
|
295
|
+
...otherStyle === void 0 ? {} : { otherStyle }
|
|
296
|
+
};
|
|
297
|
+
if (Object.keys(candidate).length === 0) return void 0;
|
|
298
|
+
const parsed = masterTextStylesSchema.safeParse(candidate);
|
|
299
|
+
return parsed.success ? parsed.data : void 0;
|
|
300
|
+
}
|
|
301
|
+
function directPlaceholderChild(el) {
|
|
302
|
+
for (let child = el.firstChild; child !== null; child = child.nextSibling) {
|
|
303
|
+
if (child.nodeType !== 1) continue;
|
|
304
|
+
const childEl = child;
|
|
305
|
+
if ((childEl.namespaceURI ?? "") === "http://schemas.openxmlformats.org/presentationml/2006/main" && (childEl.localName ?? childEl.tagName) === "nvSpPr") for (let nv = childEl.firstChild; nv !== null; nv = nv.nextSibling) {
|
|
306
|
+
if (nv.nodeType !== 1) continue;
|
|
307
|
+
const nvEl = nv;
|
|
308
|
+
if ((nvEl.namespaceURI ?? "") === "http://schemas.openxmlformats.org/presentationml/2006/main" && (nvEl.localName ?? nvEl.tagName) === "nvPr") for (let ph = nvEl.firstChild; ph !== null; ph = ph.nextSibling) {
|
|
309
|
+
if (ph.nodeType !== 1) continue;
|
|
310
|
+
const phEl = ph;
|
|
311
|
+
if ((phEl.namespaceURI ?? "") === "http://schemas.openxmlformats.org/presentationml/2006/main" && (phEl.localName ?? phEl.tagName) === "ph") return true;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
function readPlaceholderSpList(spTree, clrMap, isMaster, pkg, partPath, diagnostics, readPlaceholderVisuals) {
|
|
318
|
+
const placeholderKeyBySpid = /* @__PURE__ */ new Map();
|
|
319
|
+
if (spTree === void 0) return { placeholderKeyBySpid };
|
|
320
|
+
const rawSpecs = [];
|
|
321
|
+
const rawSpids = [];
|
|
322
|
+
for (const sp of spTree.matchingChildren((el) => (el.namespaceURI ?? "") === "http://schemas.openxmlformats.org/presentationml/2006/main" && (el.localName ?? el.tagName) === "sp" && directPlaceholderChild(el))) {
|
|
323
|
+
const nvSpPr = sp.child(P_NS, "nvSpPr");
|
|
324
|
+
const cNvPr = nvSpPr?.child(P_NS, "cNvPr");
|
|
325
|
+
const rawId = cNvPr?.attr("id");
|
|
326
|
+
const parsedSpid = ooxmlNonNegativeIntSchema.safeParse(rawId);
|
|
327
|
+
const spid = parsedSpid.success && parsedSpid.data > 0 ? parsedSpid.data : void 0;
|
|
328
|
+
const rawName = cNvPr?.attr("name");
|
|
329
|
+
const name = rawName !== void 0 && rawName.trim() !== "" ? rawName : void 0;
|
|
330
|
+
const cNvSpPr = nvSpPr?.child(P_NS, "cNvSpPr");
|
|
331
|
+
if (cNvSpPr !== void 0) {
|
|
332
|
+
cNvSpPr.consumeAttr("txBox");
|
|
333
|
+
cNvSpPr.child(A_NS, "spLocks")?.consumeAttr("noGrp");
|
|
334
|
+
}
|
|
335
|
+
const ph = (nvSpPr?.child(P_NS, "nvPr"))?.child(P_NS, "ph");
|
|
336
|
+
if (ph === void 0) continue;
|
|
337
|
+
const rawType = ph.attr("type");
|
|
338
|
+
const explicitType = rawType !== void 0;
|
|
339
|
+
const typeRes = placeholderRoleSchema.safeParse(rawType ?? "obj");
|
|
340
|
+
const phType = typeRes.success ? typeRes.data : "obj";
|
|
341
|
+
const idxParsed = ooxmlNonNegativeIntSchema.safeParse(ph.attr("idx"));
|
|
342
|
+
const idx = idxParsed.success ? idxParsed.data : void 0;
|
|
343
|
+
const szParsed = placeholderSzSchema.safeParse(ph.attr("sz"));
|
|
344
|
+
const orientParsed = placeholderOrientSchema.safeParse(ph.attr("orient"));
|
|
345
|
+
const customPromptParsed = ooxmlBoolSchema.safeParse(ph.attr("hasCustomPrompt"));
|
|
346
|
+
let x;
|
|
347
|
+
let y;
|
|
348
|
+
let width;
|
|
349
|
+
let height;
|
|
350
|
+
let geometry;
|
|
351
|
+
let flipH;
|
|
352
|
+
let flipV;
|
|
353
|
+
const styleProps = {};
|
|
354
|
+
const spPr = sp.child(P_NS, "spPr");
|
|
355
|
+
if (spPr !== void 0) {
|
|
356
|
+
const phLocation = {
|
|
357
|
+
part: partPath,
|
|
358
|
+
xpath: spPr.xpath,
|
|
359
|
+
...spid === void 0 ? {} : { objectId: spid },
|
|
360
|
+
...name === void 0 ? {} : { objectName: name }
|
|
361
|
+
};
|
|
362
|
+
const importedSpPr = (readPlaceholderVisuals ?? readPlaceholderSpPrVisuals)({
|
|
363
|
+
spPr,
|
|
364
|
+
pkg,
|
|
365
|
+
location: phLocation,
|
|
366
|
+
diagnostics
|
|
367
|
+
});
|
|
368
|
+
x = importedSpPr.x;
|
|
369
|
+
y = importedSpPr.y;
|
|
370
|
+
width = importedSpPr.width;
|
|
371
|
+
height = importedSpPr.height;
|
|
372
|
+
geometry = importedSpPr.geometry;
|
|
373
|
+
flipH = importedSpPr.flipH;
|
|
374
|
+
flipV = importedSpPr.flipV;
|
|
375
|
+
if (importedSpPr.style !== void 0) Object.assign(styleProps, importedSpPr.style);
|
|
376
|
+
}
|
|
377
|
+
let listStyles;
|
|
378
|
+
let promptText;
|
|
379
|
+
const txBody = sp.child(P_NS, "txBody");
|
|
380
|
+
if (txBody !== void 0) {
|
|
381
|
+
const bodyPr = txBody.child(A_NS, "bodyPr");
|
|
382
|
+
if (bodyPr !== void 0) {
|
|
383
|
+
const b = bodyPr.attrsObject([
|
|
384
|
+
"wrap",
|
|
385
|
+
"rtlCol",
|
|
386
|
+
"lIns",
|
|
387
|
+
"tIns",
|
|
388
|
+
"rIns",
|
|
389
|
+
"bIns",
|
|
390
|
+
"anchor",
|
|
391
|
+
"anchorCtr",
|
|
392
|
+
"numCol",
|
|
393
|
+
"spcCol"
|
|
394
|
+
]);
|
|
395
|
+
if (b["wrap"] === "none") styleProps["textWrap"] = "nowrap";
|
|
396
|
+
else if (b["wrap"] === "square") styleProps["textWrap"] = "normal";
|
|
397
|
+
if (b["anchor"] === "t") styleProps["verticalAlign"] = "top";
|
|
398
|
+
else if (b["anchor"] === "ctr") styleProps["verticalAlign"] = "middle";
|
|
399
|
+
else if (b["anchor"] === "b") styleProps["verticalAlign"] = "bottom";
|
|
400
|
+
const lIns = ooxmlNonNegativeIntSchema.safeParse(b["lIns"]);
|
|
401
|
+
const tIns = ooxmlNonNegativeIntSchema.safeParse(b["tIns"]);
|
|
402
|
+
const rIns = ooxmlNonNegativeIntSchema.safeParse(b["rIns"]);
|
|
403
|
+
const bIns = ooxmlNonNegativeIntSchema.safeParse(b["bIns"]);
|
|
404
|
+
if (lIns.success && lIns.data !== 0) styleProps["paddingLeft"] = emuToPx(lIns.data);
|
|
405
|
+
if (tIns.success && tIns.data !== 0) styleProps["paddingTop"] = emuToPx(tIns.data);
|
|
406
|
+
if (rIns.success && rIns.data !== 0) styleProps["paddingRight"] = emuToPx(rIns.data);
|
|
407
|
+
if (bIns.success && bIns.data !== 0) styleProps["paddingBottom"] = emuToPx(bIns.data);
|
|
408
|
+
bodyPr.ignoreEmptyChild(A_NS, "noAutofit");
|
|
409
|
+
bodyPr.ignoreEmptyChild(A_NS, "spAutoFit");
|
|
410
|
+
const normAutofit = bodyPr.child(A_NS, "normAutofit");
|
|
411
|
+
normAutofit?.consumeAttr("fontScale");
|
|
412
|
+
normAutofit?.consumeAttr("lnSpcReduction");
|
|
413
|
+
}
|
|
414
|
+
listStyles = readPlaceholderListStyles(txBody.child(A_NS, "lstStyle"), clrMap);
|
|
415
|
+
const promptParagraphs = [];
|
|
416
|
+
let promptLvl1Fallback;
|
|
417
|
+
for (const p of txBody.children(A_NS, "p")) {
|
|
418
|
+
const pPr = p.child(A_NS, "pPr");
|
|
419
|
+
const pStyle = pPr === void 0 ? void 0 : readLevelParagraphProperties(pPr, 0, clrMap);
|
|
420
|
+
const runTexts = [];
|
|
421
|
+
for (const r of p.children(A_NS, "r")) {
|
|
422
|
+
const rPr = r.child(A_NS, "rPr");
|
|
423
|
+
const rStyle = rPr === void 0 ? void 0 : readDefRPr(rPr, clrMap);
|
|
424
|
+
if (promptLvl1Fallback === void 0 && (pStyle !== void 0 || rStyle !== void 0)) promptLvl1Fallback = {
|
|
425
|
+
...pStyle,
|
|
426
|
+
...rStyle
|
|
427
|
+
};
|
|
428
|
+
const t = r.child(A_NS, "t");
|
|
429
|
+
if (t !== void 0) {
|
|
430
|
+
t.consumeAttr("space", XML_NS);
|
|
431
|
+
runTexts.push(t.textContent);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const fld = p.child(A_NS, "fld");
|
|
435
|
+
if (fld !== void 0) {
|
|
436
|
+
fld.consumeAttr("id");
|
|
437
|
+
fld.consumeAttr("type");
|
|
438
|
+
const rPr = fld.child(A_NS, "rPr");
|
|
439
|
+
if (rPr !== void 0) readDefRPr(rPr, clrMap);
|
|
440
|
+
fld.ignoreEmptyChild(A_NS, "pPr");
|
|
441
|
+
const t = fld.child(A_NS, "t");
|
|
442
|
+
if (t !== void 0) {
|
|
443
|
+
t.consumeAttr("space", XML_NS);
|
|
444
|
+
runTexts.push(t.textContent);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
const endPara = p.child(A_NS, "endParaRPr");
|
|
448
|
+
if (endPara !== void 0) readDefRPr(endPara, clrMap);
|
|
449
|
+
if (runTexts.length > 0) promptParagraphs.push(runTexts.join(""));
|
|
450
|
+
}
|
|
451
|
+
if (promptParagraphs.length > 0) promptText = promptParagraphs.join("\n");
|
|
452
|
+
if (listStyles === void 0 && promptLvl1Fallback !== void 0 && Object.keys(promptLvl1Fallback).length > 0) listStyles = { 1: promptLvl1Fallback };
|
|
453
|
+
}
|
|
454
|
+
const style = Object.keys(styleProps).length === 0 ? void 0 : styleProps;
|
|
455
|
+
const candidate = {
|
|
456
|
+
type: phType,
|
|
457
|
+
...explicitType ? {} : { explicitType: false },
|
|
458
|
+
...idx === void 0 ? {} : { idx },
|
|
459
|
+
...szParsed.success ? { sz: szParsed.data } : {},
|
|
460
|
+
...orientParsed.success ? { orient: orientParsed.data } : {},
|
|
461
|
+
...customPromptParsed.success && customPromptParsed.data ? { hasCustomPrompt: true } : {},
|
|
462
|
+
...name === void 0 ? {} : { name },
|
|
463
|
+
...x === void 0 ? {} : { x },
|
|
464
|
+
...y === void 0 ? {} : { y },
|
|
465
|
+
...width === void 0 ? {} : { width },
|
|
466
|
+
...height === void 0 ? {} : { height },
|
|
467
|
+
...geometry === void 0 ? {} : { geometry },
|
|
468
|
+
...flipH ? { flipH: true } : {},
|
|
469
|
+
...flipV ? { flipV: true } : {},
|
|
470
|
+
...style === void 0 ? {} : { style },
|
|
471
|
+
...listStyles === void 0 ? {} : { listStyles },
|
|
472
|
+
...promptText === void 0 ? {} : { promptText }
|
|
473
|
+
};
|
|
474
|
+
const validated = (isMaster ? masterPlaceholderSpecSchema : layoutPlaceholderSpecSchema).safeParse(candidate);
|
|
475
|
+
rawSpecs.push(validated.success ? validated.data : candidate);
|
|
476
|
+
rawSpids.push(spid);
|
|
477
|
+
}
|
|
478
|
+
if (rawSpecs.length === 0) return { placeholderKeyBySpid };
|
|
479
|
+
const keys = allocatePlaceholderAuthorKeys(rawSpecs);
|
|
480
|
+
const map = {};
|
|
481
|
+
for (let i = 0; i < rawSpecs.length; i += 1) {
|
|
482
|
+
const key = keys[i];
|
|
483
|
+
map[key] = rawSpecs[i];
|
|
484
|
+
const spid = rawSpids[i];
|
|
485
|
+
if (spid !== void 0) placeholderKeyBySpid.set(spid, key);
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
placeholders: Object.freeze(map),
|
|
489
|
+
placeholderKeyBySpid
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
/** Allocates a deterministic unique author id within `used`, disambiguating collisions with `-2`, `-3`, ... */
|
|
493
|
+
function allocateScopedAuthorId(requested, used, fallbackBase) {
|
|
494
|
+
const base = requested !== void 0 && requested.trim().length > 0 ? requested.trim() : fallbackBase;
|
|
495
|
+
if (!used.has(base)) {
|
|
496
|
+
used.add(base);
|
|
497
|
+
return base;
|
|
498
|
+
}
|
|
499
|
+
let suffix = 2;
|
|
500
|
+
while (used.has(`${base}-${suffix}`)) suffix += 1;
|
|
501
|
+
const unique = `${base}-${suffix}`;
|
|
502
|
+
used.add(unique);
|
|
503
|
+
return unique;
|
|
504
|
+
}
|
|
505
|
+
/** Consumes standard identity `<p:nvGrpSpPr>` and `<p:grpSpPr>` transform boilerplate on an `spTree`. */
|
|
506
|
+
function consumeIdentityShapeTreeBoilerplate(spTree) {
|
|
507
|
+
const nvGrpSpPr = spTree.child(P_NS, "nvGrpSpPr");
|
|
508
|
+
if (nvGrpSpPr !== void 0) {
|
|
509
|
+
const cNvPr = nvGrpSpPr.child(P_NS, "cNvPr");
|
|
510
|
+
if (cNvPr !== void 0) {
|
|
511
|
+
cNvPr.consumeAttr("id");
|
|
512
|
+
cNvPr.consumeAttr("name");
|
|
513
|
+
}
|
|
514
|
+
nvGrpSpPr.ignoreEmptyChild(P_NS, "cNvGrpSpPr");
|
|
515
|
+
nvGrpSpPr.ignoreEmptyChild(P_NS, "nvPr");
|
|
516
|
+
}
|
|
517
|
+
const grpSpPr = spTree.child(P_NS, "grpSpPr");
|
|
518
|
+
if (grpSpPr !== void 0) {
|
|
519
|
+
const xfrm = grpSpPr.child(A_NS, "xfrm");
|
|
520
|
+
if (xfrm !== void 0) {
|
|
521
|
+
const off = xfrm.child(A_NS, "off");
|
|
522
|
+
if (off !== void 0 && off.attr("x") === "0" && off.attr("y") === "0") {}
|
|
523
|
+
const ext = xfrm.child(A_NS, "ext");
|
|
524
|
+
if (ext !== void 0 && ext.attr("cx") === "0" && ext.attr("cy") === "0") {}
|
|
525
|
+
const chOff = xfrm.child(A_NS, "chOff");
|
|
526
|
+
if (chOff !== void 0 && chOff.attr("x") === "0" && chOff.attr("y") === "0") {}
|
|
527
|
+
const chExt = xfrm.child(A_NS, "chExt");
|
|
528
|
+
if (chExt !== void 0 && chExt.attr("cx") === "0" && chExt.attr("cy") === "0") {}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/** Records `unconsumed-xml` diagnostics for all unconsumed attributes/elements under a root cursor. */
|
|
533
|
+
function appendUnconsumedDiagnostics(cursor, slideIndex, diagnostics) {
|
|
534
|
+
for (const item of cursor.collectUnconsumed()) diagnostics.push({
|
|
535
|
+
code: "unconsumed-xml",
|
|
536
|
+
category: "unsupported",
|
|
537
|
+
disposition: "omitted",
|
|
538
|
+
kind: item.kind,
|
|
539
|
+
location: {
|
|
540
|
+
...item.location,
|
|
541
|
+
...slideIndex === void 0 ? {} : { slideIndex }
|
|
542
|
+
},
|
|
543
|
+
namespaceUri: item.namespaceUri,
|
|
544
|
+
localName: item.localName
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
function validateMasterLayoutNumericId(rawId, part, xpath, diagnostics) {
|
|
548
|
+
if (rawId === void 0) return;
|
|
549
|
+
const parsed = ooxmlNonNegativeIntSchema.safeParse(rawId);
|
|
550
|
+
if (!parsed.success || parsed.data < minimumMasterLayoutId || parsed.data > maximumMasterLayoutId) diagnostics.push({
|
|
551
|
+
code: "invalid-xml-value",
|
|
552
|
+
category: "corrupt-input",
|
|
553
|
+
disposition: "recovered",
|
|
554
|
+
location: {
|
|
555
|
+
part,
|
|
556
|
+
xpath: `${xpath}/@id`
|
|
557
|
+
},
|
|
558
|
+
attributeOrElement: "@id",
|
|
559
|
+
rawValue: rawId
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
const p14Namespace = "http://schemas.microsoft.com/office/powerpoint/2010/main";
|
|
563
|
+
const creationIdExtensionUri = "{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}";
|
|
564
|
+
/** Consumes benign PowerPoint `<p:cSld>/<p:extLst>` creationId metadata without altering author models. */
|
|
565
|
+
function consumeCommonSlideCreationId(cSld) {
|
|
566
|
+
const extLst = cSld.child(P_NS, "extLst");
|
|
567
|
+
if (extLst === void 0) return;
|
|
568
|
+
for (const ext of extLst.children(P_NS, "ext")) {
|
|
569
|
+
if (ext.attr("uri") !== creationIdExtensionUri) continue;
|
|
570
|
+
const creationId = ext.child(p14Namespace, "creationId");
|
|
571
|
+
if (creationId !== void 0) creationId.consumeAttr("val");
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function stripSlideIndexFromDiagnostics(entries) {
|
|
575
|
+
if (entries === void 0 || entries.length === 0) return [];
|
|
576
|
+
return entries.map((entry) => {
|
|
577
|
+
const { slideIndex: _ignored, ...locationRest } = entry.location;
|
|
578
|
+
return {
|
|
579
|
+
...entry,
|
|
580
|
+
location: locationRest
|
|
581
|
+
};
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
const supportedShapeTreeNamespaces = /* @__PURE__ */ new Set([
|
|
585
|
+
P_NS,
|
|
586
|
+
A_NS,
|
|
587
|
+
R_NS
|
|
588
|
+
]);
|
|
589
|
+
function readSingleShapeTreeItem(itemCursor, pkg, partPath, slideIndex, relIndex, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, containerNode, layoutPlaceholders, clrMap, registerImportedObject, omittedSpids, masterPlaceholders) {
|
|
590
|
+
const identity = peekShapeTreeObjectIdentity(itemCursor.element);
|
|
591
|
+
const match = shapeTreeHandlers.find((handler) => itemCursor.namespaceUri === "http://schemas.openxmlformats.org/presentationml/2006/main" && handler.localName === itemCursor.localName && (handler.matches === void 0 || handler.matches(itemCursor)));
|
|
592
|
+
if (match === void 0) {
|
|
593
|
+
if (omittedSpids !== void 0 && identity.objectId !== void 0) omittedSpids.set(identity.objectId, {
|
|
594
|
+
...identity.objectName === void 0 ? {} : { objectName: identity.objectName },
|
|
595
|
+
reason: "unsupported"
|
|
596
|
+
});
|
|
597
|
+
const frameInfo = itemCursor.namespaceUri === "http://schemas.openxmlformats.org/presentationml/2006/main" && itemCursor.localName === "graphicFrame" ? inspectUnsupportedGraphicFrame(itemCursor, partPath, relIndex.byId, relIndex.entries) : void 0;
|
|
598
|
+
diagnostics.push({
|
|
599
|
+
code: "unsupported-mechanism",
|
|
600
|
+
category: "unsupported",
|
|
601
|
+
disposition: "omitted",
|
|
602
|
+
location: {
|
|
603
|
+
part: partPath,
|
|
604
|
+
xpath: itemCursor.xpath,
|
|
605
|
+
...slideIndex === void 0 ? {} : { slideIndex },
|
|
606
|
+
...identity
|
|
607
|
+
},
|
|
608
|
+
namespaceUri: itemCursor.namespaceUri,
|
|
609
|
+
localName: itemCursor.localName,
|
|
610
|
+
...frameInfo?.mechanismHint === void 0 ? {} : { mechanismHint: frameInfo.mechanismHint },
|
|
611
|
+
...frameInfo === void 0 || frameInfo.cascaded.length === 0 ? {} : { cascaded: frameInfo.cascaded }
|
|
612
|
+
});
|
|
613
|
+
itemCursor.suppressUnconsumed();
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const outcome = match.read({
|
|
617
|
+
cursor: itemCursor,
|
|
618
|
+
part: partPath,
|
|
619
|
+
slideIndex: slideIndex ?? 0,
|
|
620
|
+
package: pkg,
|
|
621
|
+
...containerNode === void 0 ? {} : { containerNode },
|
|
622
|
+
relationships: relIndex.byId,
|
|
623
|
+
registerDeferredSlideLink,
|
|
624
|
+
...registerImportedObject === void 0 ? {} : { registerImportedObject },
|
|
625
|
+
...layoutPlaceholders === void 0 ? {} : { layoutPlaceholders },
|
|
626
|
+
...masterPlaceholders === void 0 ? {} : { masterPlaceholders },
|
|
627
|
+
...clrMap === void 0 ? {} : { clrMap }
|
|
628
|
+
});
|
|
629
|
+
if (outcome.diagnostics !== void 0) diagnostics.push(...slideIndex === void 0 ? stripSlideIndexFromDiagnostics(outcome.diagnostics) : outcome.diagnostics);
|
|
630
|
+
if (outcome.node === void 0) {
|
|
631
|
+
if (omittedSpids !== void 0 && identity.objectId !== void 0) omittedSpids.set(identity.objectId, {
|
|
632
|
+
...identity.objectName === void 0 ? {} : { objectName: identity.objectName },
|
|
633
|
+
reason: "corrupt"
|
|
634
|
+
});
|
|
635
|
+
itemCursor.suppressUnconsumed();
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (registerImportedObject !== void 0 && identity.objectId !== void 0) registerImportedObject(identity.objectId, outcome.node);
|
|
639
|
+
return outcome.node;
|
|
640
|
+
}
|
|
641
|
+
/** Shared `<p:spTree>` child reader for slides, slide layouts, and slide masters. */
|
|
642
|
+
function readShapeTreeItems(args) {
|
|
643
|
+
const { spTree, pkg, partPath, slideIndex, relIndex, shapeTreeHandlers, registerDeferredSlideLink, appendNode, diagnostics, containerNode, layoutPlaceholders, masterPlaceholders, clrMap, registerImportedObject, omittedSpids } = args;
|
|
644
|
+
consumeIdentityShapeTreeBoilerplate(spTree);
|
|
645
|
+
for (const itemCursor of spTree.remainingElementChildren()) {
|
|
646
|
+
if (itemCursor.namespaceUri === MC_NS_IMPORT_PLACEHOLDER && itemCursor.localName === "AlternateContent") {
|
|
647
|
+
const selection = readAlternateContent(itemCursor, (ns) => supportedShapeTreeNamespaces.has(ns));
|
|
648
|
+
if (selection.branch === "choice") for (const childCursor of selection.children) {
|
|
649
|
+
const node = readSingleShapeTreeItem(childCursor, pkg, partPath, slideIndex, relIndex, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, containerNode, layoutPlaceholders, clrMap, registerImportedObject, omittedSpids, masterPlaceholders);
|
|
650
|
+
if (node !== void 0) appendNode(node);
|
|
651
|
+
}
|
|
652
|
+
else if (selection.branch === "fallback") {
|
|
653
|
+
let adoptedFallback = false;
|
|
654
|
+
for (const childCursor of selection.children) {
|
|
655
|
+
const identity = peekShapeTreeObjectIdentity(childCursor.element);
|
|
656
|
+
const node = readSingleShapeTreeItem(childCursor, pkg, partPath, slideIndex, relIndex, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, containerNode, layoutPlaceholders, clrMap, registerImportedObject, omittedSpids, masterPlaceholders);
|
|
657
|
+
if (node !== void 0) {
|
|
658
|
+
adoptedFallback = true;
|
|
659
|
+
appendNode(node);
|
|
660
|
+
diagnostics.push({
|
|
661
|
+
code: "compatibility-fallback",
|
|
662
|
+
category: "unsupported",
|
|
663
|
+
disposition: "fallback",
|
|
664
|
+
location: {
|
|
665
|
+
part: partPath,
|
|
666
|
+
xpath: itemCursor.xpath,
|
|
667
|
+
...slideIndex === void 0 ? {} : { slideIndex },
|
|
668
|
+
...identity
|
|
669
|
+
},
|
|
670
|
+
preferredMechanism: selection.preferredMechanism,
|
|
671
|
+
selectedFallback: node.kind,
|
|
672
|
+
loss: {
|
|
673
|
+
lost: "native-mechanism",
|
|
674
|
+
retainedAs: node.kind
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (!adoptedFallback) itemCursor.suppressUnconsumed();
|
|
680
|
+
} else {
|
|
681
|
+
diagnostics.push({
|
|
682
|
+
code: "unsupported-mechanism",
|
|
683
|
+
category: "unsupported",
|
|
684
|
+
disposition: "omitted",
|
|
685
|
+
location: {
|
|
686
|
+
part: partPath,
|
|
687
|
+
xpath: itemCursor.xpath,
|
|
688
|
+
...slideIndex === void 0 ? {} : { slideIndex }
|
|
689
|
+
},
|
|
690
|
+
namespaceUri: itemCursor.namespaceUri,
|
|
691
|
+
localName: itemCursor.localName,
|
|
692
|
+
mechanismHint: selection.preferredMechanism
|
|
693
|
+
});
|
|
694
|
+
itemCursor.suppressUnconsumed();
|
|
695
|
+
}
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
const node = readSingleShapeTreeItem(itemCursor, pkg, partPath, slideIndex, relIndex, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, containerNode, layoutPlaceholders, clrMap, registerImportedObject, omittedSpids, masterPlaceholders);
|
|
699
|
+
if (node !== void 0) appendNode(node);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
const MC_NS_IMPORT_PLACEHOLDER = "http://schemas.openxmlformats.org/markup-compatibility/2006";
|
|
703
|
+
function readSlideLayoutPart(pkg, layoutPartPath, ownerMasterPartPath, layoutOrder, usedLayoutIds, masterClrMap, masterLevelSlideHandlers, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, readPlaceholderVisuals) {
|
|
704
|
+
const xmlText = pkg.readTextPart(layoutPartPath);
|
|
705
|
+
if (xmlText === void 0) return void 0;
|
|
706
|
+
let layoutEl;
|
|
707
|
+
try {
|
|
708
|
+
layoutEl = parseXmlPart(layoutPartPath, xmlText);
|
|
709
|
+
} catch {
|
|
710
|
+
diagnostics.push({
|
|
711
|
+
code: "corrupt-part",
|
|
712
|
+
category: "corrupt-input",
|
|
713
|
+
disposition: "omitted",
|
|
714
|
+
location: { part: layoutPartPath }
|
|
715
|
+
});
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if ((layoutEl.namespaceURI ?? "") !== "http://schemas.openxmlformats.org/presentationml/2006/main" || (layoutEl.localName ?? layoutEl.tagName) !== "sldLayout") {
|
|
719
|
+
diagnostics.push({
|
|
720
|
+
code: "corrupt-part",
|
|
721
|
+
category: "corrupt-input",
|
|
722
|
+
disposition: "omitted",
|
|
723
|
+
location: { part: layoutPartPath }
|
|
724
|
+
});
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
const layoutCursor = XmlElementCursor.createRoot(layoutEl, layoutPartPath, "/p:sldLayout");
|
|
728
|
+
const rawAttrs = layoutCursor.attrsObject([
|
|
729
|
+
"type",
|
|
730
|
+
"preserve",
|
|
731
|
+
"matchingName",
|
|
732
|
+
"userDrawn",
|
|
733
|
+
"showMasterSp",
|
|
734
|
+
"showMasterPhAnim"
|
|
735
|
+
]);
|
|
736
|
+
const parsedAttrs = slideLayoutAttrsSchema.safeParse(rawAttrs);
|
|
737
|
+
let layoutType;
|
|
738
|
+
let preserve;
|
|
739
|
+
let matchingName;
|
|
740
|
+
let userDrawn;
|
|
741
|
+
let showMasterShapes;
|
|
742
|
+
let showMasterPlaceholderAnimations;
|
|
743
|
+
if (parsedAttrs.success) {
|
|
744
|
+
layoutType = parsedAttrs.data.type;
|
|
745
|
+
preserve = parsedAttrs.data.preserve;
|
|
746
|
+
matchingName = parsedAttrs.data.matchingName;
|
|
747
|
+
userDrawn = parsedAttrs.data.userDrawn;
|
|
748
|
+
showMasterShapes = parsedAttrs.data.showMasterSp;
|
|
749
|
+
showMasterPlaceholderAnimations = parsedAttrs.data.showMasterPhAnim;
|
|
750
|
+
} else {
|
|
751
|
+
for (const issue of parsedAttrs.error.issues) {
|
|
752
|
+
const key = String(issue.path[0] ?? "sldLayout");
|
|
753
|
+
diagnostics.push({
|
|
754
|
+
code: "invalid-xml-value",
|
|
755
|
+
category: "corrupt-input",
|
|
756
|
+
disposition: "recovered",
|
|
757
|
+
location: {
|
|
758
|
+
part: layoutPartPath,
|
|
759
|
+
xpath: `${layoutCursor.xpath}/@${key}`
|
|
760
|
+
},
|
|
761
|
+
attributeOrElement: `@${key}`,
|
|
762
|
+
rawValue: rawAttrs[key] ?? ""
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
const typeRes = slideLayoutTypeSchema.safeParse(rawAttrs["type"]);
|
|
766
|
+
if (typeRes.success) layoutType = typeRes.data;
|
|
767
|
+
const preserveRes = ooxmlBoolSchema.safeParse(rawAttrs["preserve"]);
|
|
768
|
+
if (preserveRes.success) preserve = preserveRes.data;
|
|
769
|
+
if (rawAttrs["matchingName"] !== void 0) matchingName = rawAttrs["matchingName"];
|
|
770
|
+
const userDrawnRes = ooxmlBoolSchema.safeParse(rawAttrs["userDrawn"]);
|
|
771
|
+
if (userDrawnRes.success) userDrawn = userDrawnRes.data;
|
|
772
|
+
const showSpRes = ooxmlBoolSchema.safeParse(rawAttrs["showMasterSp"]);
|
|
773
|
+
if (showSpRes.success) showMasterShapes = showSpRes.data;
|
|
774
|
+
const showPhAnimRes = ooxmlBoolSchema.safeParse(rawAttrs["showMasterPhAnim"]);
|
|
775
|
+
if (showPhAnimRes.success) showMasterPlaceholderAnimations = showPhAnimRes.data;
|
|
776
|
+
}
|
|
777
|
+
const cSld = layoutCursor.child(P_NS, "cSld");
|
|
778
|
+
let layoutName;
|
|
779
|
+
if (cSld === void 0) {
|
|
780
|
+
diagnostics.push({
|
|
781
|
+
code: "corrupt-part",
|
|
782
|
+
category: "corrupt-input",
|
|
783
|
+
disposition: "omitted",
|
|
784
|
+
location: {
|
|
785
|
+
part: layoutPartPath,
|
|
786
|
+
xpath: layoutCursor.xpath
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
layoutName = cSld.attr("name");
|
|
792
|
+
consumeCommonSlideCreationId(cSld);
|
|
793
|
+
const spTree = cSld.child(P_NS, "spTree");
|
|
794
|
+
let placeholders;
|
|
795
|
+
let layoutPlaceholderKeyBySpid;
|
|
796
|
+
if (spTree !== void 0) {
|
|
797
|
+
consumeIdentityShapeTreeBoilerplate(spTree);
|
|
798
|
+
const placeholderRead = readPlaceholderSpList(spTree, masterClrMap, false, pkg, layoutPartPath, diagnostics, readPlaceholderVisuals);
|
|
799
|
+
placeholders = placeholderRead.placeholders;
|
|
800
|
+
layoutPlaceholderKeyBySpid = placeholderRead.placeholderKeyBySpid;
|
|
801
|
+
}
|
|
802
|
+
const clrMapOvr = layoutCursor.child(P_NS, "clrMapOvr");
|
|
803
|
+
let colorMapOverride;
|
|
804
|
+
if (clrMapOvr !== void 0) {
|
|
805
|
+
const parsedOvr = readColorMapOverride(clrMapOvr, layoutPartPath, void 0, diagnostics);
|
|
806
|
+
if (parsedOvr !== void 0 && parsedOvr !== "master") colorMapOverride = parsedOvr;
|
|
807
|
+
}
|
|
808
|
+
const layoutHeaderFooter = readHeaderFooterElement(layoutCursor, layoutPartPath, diagnostics);
|
|
809
|
+
const layoutRels = pkg.readRelationships(layoutPartPath);
|
|
810
|
+
diagnostics.push(...layoutRels.diagnostics);
|
|
811
|
+
const backMasterRel = layoutRels.entries.find((entry) => entry.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" && entry.TargetMode !== "External");
|
|
812
|
+
if (backMasterRel !== void 0) {
|
|
813
|
+
if (resolvePartPath(layoutPartPath, backMasterRel.Target) !== ownerMasterPartPath) diagnostics.push({
|
|
814
|
+
code: "broken-relationship",
|
|
815
|
+
category: "corrupt-input",
|
|
816
|
+
disposition: "omitted",
|
|
817
|
+
location: {
|
|
818
|
+
part: layoutPartPath,
|
|
819
|
+
xpath: backMasterRel.xpath
|
|
820
|
+
},
|
|
821
|
+
relationshipId: backMasterRel.Id
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
let themeOverride;
|
|
825
|
+
const themeOverrideRel = layoutRels.entries.find((entry) => entry.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/themeOverride" && entry.TargetMode !== "External");
|
|
826
|
+
if (themeOverrideRel !== void 0) {
|
|
827
|
+
const overridePart = resolvePartPath(layoutPartPath, themeOverrideRel.Target);
|
|
828
|
+
if (overridePart === void 0 || !pkg.hasPart(overridePart)) diagnostics.push({
|
|
829
|
+
code: "missing-target-part",
|
|
830
|
+
category: "corrupt-input",
|
|
831
|
+
disposition: "omitted",
|
|
832
|
+
location: {
|
|
833
|
+
part: layoutPartPath,
|
|
834
|
+
xpath: themeOverrideRel.xpath
|
|
835
|
+
},
|
|
836
|
+
relationshipId: themeOverrideRel.Id,
|
|
837
|
+
targetPart: overridePart ?? themeOverrideRel.Target
|
|
838
|
+
});
|
|
839
|
+
else themeOverride = readThemeOverridePart(pkg, overridePart, void 0, diagnostics);
|
|
840
|
+
}
|
|
841
|
+
const props = {
|
|
842
|
+
id: allocateScopedAuthorId(layoutName, usedLayoutIds, `layout-${layoutOrder}`),
|
|
843
|
+
...layoutName === void 0 ? {} : { name: layoutName },
|
|
844
|
+
...layoutType === void 0 ? {} : { type: layoutType },
|
|
845
|
+
...preserve === void 0 ? {} : { preserve },
|
|
846
|
+
...matchingName === void 0 ? {} : { matchingName },
|
|
847
|
+
...userDrawn === void 0 ? {} : { userDrawn },
|
|
848
|
+
...showMasterShapes === void 0 ? {} : { showMasterShapes },
|
|
849
|
+
...showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations },
|
|
850
|
+
...placeholders === void 0 ? {} : { placeholders },
|
|
851
|
+
...colorMapOverride === void 0 ? {} : { colorMapOverride },
|
|
852
|
+
...themeOverride === void 0 ? {} : { themeOverride },
|
|
853
|
+
...layoutHeaderFooter === void 0 ? {} : { headerFooter: layoutHeaderFooter }
|
|
854
|
+
};
|
|
855
|
+
const layoutNode = createSlideLayoutNode(props);
|
|
856
|
+
if (spTree !== void 0 && shapeTreeHandlers.length > 0) readShapeTreeItems({
|
|
857
|
+
spTree,
|
|
858
|
+
pkg,
|
|
859
|
+
partPath: layoutPartPath,
|
|
860
|
+
slideIndex: void 0,
|
|
861
|
+
relIndex: {
|
|
862
|
+
entries: layoutRels.entries,
|
|
863
|
+
byId: new Map(layoutRels.entries.map((entry) => [entry.Id, entry])),
|
|
864
|
+
diagnostics: []
|
|
865
|
+
},
|
|
866
|
+
shapeTreeHandlers,
|
|
867
|
+
registerDeferredSlideLink,
|
|
868
|
+
appendNode: (node) => layoutNode.append(node),
|
|
869
|
+
diagnostics,
|
|
870
|
+
containerNode: layoutNode,
|
|
871
|
+
clrMap: masterClrMap
|
|
872
|
+
});
|
|
873
|
+
for (const slideHandler of masterLevelSlideHandlers) {
|
|
874
|
+
if (slideHandler.matches !== void 0 && !slideHandler.matches(layoutCursor)) continue;
|
|
875
|
+
const outcome = slideHandler.read({
|
|
876
|
+
slideCursor: layoutCursor,
|
|
877
|
+
slideNode: layoutNode,
|
|
878
|
+
part: layoutPartPath,
|
|
879
|
+
...slideHandler.slot === "transition" ? {} : { slideIndex: 0 },
|
|
880
|
+
package: pkg,
|
|
881
|
+
...layoutPlaceholderKeyBySpid === void 0 ? {} : { placeholderKeyBySpid: layoutPlaceholderKeyBySpid }
|
|
882
|
+
});
|
|
883
|
+
diagnostics.push(...stripSlideIndexFromDiagnostics(outcome.diagnostics));
|
|
884
|
+
}
|
|
885
|
+
appendUnconsumedDiagnostics(layoutCursor, void 0, diagnostics);
|
|
886
|
+
return layoutNode;
|
|
887
|
+
}
|
|
888
|
+
function readSlideMasterPart(pkg, masterPartPath, masterOrder, usedDeckIds, themesByPartPath, layoutNodeByPartPath, clrMapByLayoutPartPath, masterLevelSlideHandlers, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, readPlaceholderVisuals) {
|
|
889
|
+
const xmlText = pkg.readTextPart(masterPartPath);
|
|
890
|
+
if (xmlText === void 0) return void 0;
|
|
891
|
+
let masterEl;
|
|
892
|
+
try {
|
|
893
|
+
masterEl = parseXmlPart(masterPartPath, xmlText);
|
|
894
|
+
} catch {
|
|
895
|
+
diagnostics.push({
|
|
896
|
+
code: "corrupt-part",
|
|
897
|
+
category: "corrupt-input",
|
|
898
|
+
disposition: "omitted",
|
|
899
|
+
location: { part: masterPartPath }
|
|
900
|
+
});
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
if ((masterEl.namespaceURI ?? "") !== "http://schemas.openxmlformats.org/presentationml/2006/main" || (masterEl.localName ?? masterEl.tagName) !== "sldMaster") {
|
|
904
|
+
diagnostics.push({
|
|
905
|
+
code: "corrupt-part",
|
|
906
|
+
category: "corrupt-input",
|
|
907
|
+
disposition: "omitted",
|
|
908
|
+
location: { part: masterPartPath }
|
|
909
|
+
});
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
const masterCursor = XmlElementCursor.createRoot(masterEl, masterPartPath, "/p:sldMaster");
|
|
913
|
+
const rawAttrs = masterCursor.attrsObject(["preserve"]);
|
|
914
|
+
const parsedAttrs = slideMasterAttrsSchema.safeParse(rawAttrs);
|
|
915
|
+
let preserve;
|
|
916
|
+
if (!parsedAttrs.success) diagnostics.push({
|
|
917
|
+
code: "invalid-xml-value",
|
|
918
|
+
category: "corrupt-input",
|
|
919
|
+
disposition: "recovered",
|
|
920
|
+
location: {
|
|
921
|
+
part: masterPartPath,
|
|
922
|
+
xpath: `${masterCursor.xpath}/@preserve`
|
|
923
|
+
},
|
|
924
|
+
attributeOrElement: "@preserve",
|
|
925
|
+
rawValue: rawAttrs["preserve"] ?? ""
|
|
926
|
+
});
|
|
927
|
+
else preserve = parsedAttrs.data.preserve;
|
|
928
|
+
const cSld = masterCursor.child(P_NS, "cSld");
|
|
929
|
+
if (cSld === void 0) {
|
|
930
|
+
diagnostics.push({
|
|
931
|
+
code: "corrupt-part",
|
|
932
|
+
category: "corrupt-input",
|
|
933
|
+
disposition: "omitted",
|
|
934
|
+
location: {
|
|
935
|
+
part: masterPartPath,
|
|
936
|
+
xpath: masterCursor.xpath
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const masterName = cSld.attr("name");
|
|
942
|
+
consumeCommonSlideCreationId(cSld);
|
|
943
|
+
const clrMap = masterCursor.child(P_NS, "clrMap");
|
|
944
|
+
let colorMap;
|
|
945
|
+
let masterClrMap = defaultColorMap;
|
|
946
|
+
if (clrMap !== void 0) {
|
|
947
|
+
const parsedMap = readColorMapElement(clrMap, masterPartPath, void 0, diagnostics);
|
|
948
|
+
masterClrMap = parsedMap;
|
|
949
|
+
if (isNonDefaultColorMap(parsedMap)) colorMap = parsedMap;
|
|
950
|
+
}
|
|
951
|
+
const spTree = cSld.child(P_NS, "spTree");
|
|
952
|
+
let masterPlaceholders;
|
|
953
|
+
let masterPlaceholderKeyBySpid;
|
|
954
|
+
if (spTree !== void 0) {
|
|
955
|
+
consumeIdentityShapeTreeBoilerplate(spTree);
|
|
956
|
+
const placeholderRead = readPlaceholderSpList(spTree, masterClrMap, true, pkg, masterPartPath, diagnostics, readPlaceholderVisuals);
|
|
957
|
+
masterPlaceholders = placeholderRead.placeholders;
|
|
958
|
+
masterPlaceholderKeyBySpid = placeholderRead.placeholderKeyBySpid;
|
|
959
|
+
}
|
|
960
|
+
const txStylesCursor = masterCursor.child(P_NS, "txStyles");
|
|
961
|
+
let textStyles;
|
|
962
|
+
if (txStylesCursor !== void 0) {
|
|
963
|
+
txStylesCursor.ignoreEmptyChild(P_NS, "titleStyle");
|
|
964
|
+
txStylesCursor.ignoreEmptyChild(P_NS, "bodyStyle");
|
|
965
|
+
txStylesCursor.ignoreEmptyChild(P_NS, "otherStyle");
|
|
966
|
+
textStyles = readMasterTextStyles(txStylesCursor, masterClrMap);
|
|
967
|
+
}
|
|
968
|
+
const masterHeaderFooter = readHeaderFooterElement(masterCursor, masterPartPath, diagnostics);
|
|
969
|
+
const masterRels = pkg.readRelationships(masterPartPath);
|
|
970
|
+
diagnostics.push(...masterRels.diagnostics);
|
|
971
|
+
const masterRelById = /* @__PURE__ */ new Map();
|
|
972
|
+
for (const rel of masterRels.entries) masterRelById.set(rel.Id, rel);
|
|
973
|
+
let masterTheme;
|
|
974
|
+
const themeRel = masterRels.entries.find((entry) => entry.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" && entry.TargetMode !== "External");
|
|
975
|
+
if (themeRel !== void 0) {
|
|
976
|
+
const themePartPath = resolvePartPath(masterPartPath, themeRel.Target);
|
|
977
|
+
if (themePartPath === void 0 || !pkg.hasPart(themePartPath)) diagnostics.push({
|
|
978
|
+
code: "missing-target-part",
|
|
979
|
+
category: "corrupt-input",
|
|
980
|
+
disposition: "omitted",
|
|
981
|
+
location: {
|
|
982
|
+
part: masterPartPath,
|
|
983
|
+
xpath: themeRel.xpath
|
|
984
|
+
},
|
|
985
|
+
relationshipId: themeRel.Id,
|
|
986
|
+
targetPart: themePartPath ?? themeRel.Target
|
|
987
|
+
});
|
|
988
|
+
else masterTheme = readThemePart(pkg, themePartPath, themesByPartPath, diagnostics);
|
|
989
|
+
}
|
|
990
|
+
const masterProps = {
|
|
991
|
+
id: allocateScopedAuthorId(masterName, usedDeckIds, `master-${masterOrder}`),
|
|
992
|
+
...masterName === void 0 ? {} : { name: masterName },
|
|
993
|
+
...preserve === void 0 ? {} : { preserve },
|
|
994
|
+
...masterPlaceholders === void 0 ? {} : { placeholders: masterPlaceholders },
|
|
995
|
+
...textStyles === void 0 ? {} : { textStyles },
|
|
996
|
+
...masterTheme === void 0 ? {} : { theme: masterTheme },
|
|
997
|
+
...colorMap === void 0 ? {} : { colorMap },
|
|
998
|
+
...masterHeaderFooter === void 0 ? {} : { headerFooter: masterHeaderFooter }
|
|
999
|
+
};
|
|
1000
|
+
const masterNode = createSlideMasterNode(masterProps);
|
|
1001
|
+
if (spTree !== void 0 && shapeTreeHandlers.length > 0) readShapeTreeItems({
|
|
1002
|
+
spTree,
|
|
1003
|
+
pkg,
|
|
1004
|
+
partPath: masterPartPath,
|
|
1005
|
+
slideIndex: void 0,
|
|
1006
|
+
relIndex: {
|
|
1007
|
+
entries: masterRels.entries,
|
|
1008
|
+
byId: masterRelById,
|
|
1009
|
+
diagnostics: []
|
|
1010
|
+
},
|
|
1011
|
+
shapeTreeHandlers,
|
|
1012
|
+
registerDeferredSlideLink,
|
|
1013
|
+
appendNode: (node) => masterNode.append(node),
|
|
1014
|
+
diagnostics,
|
|
1015
|
+
containerNode: masterNode,
|
|
1016
|
+
clrMap: masterClrMap
|
|
1017
|
+
});
|
|
1018
|
+
for (const slideHandler of masterLevelSlideHandlers) {
|
|
1019
|
+
if (slideHandler.matches !== void 0 && !slideHandler.matches(masterCursor)) continue;
|
|
1020
|
+
const outcome = slideHandler.read({
|
|
1021
|
+
slideCursor: masterCursor,
|
|
1022
|
+
slideNode: masterNode,
|
|
1023
|
+
part: masterPartPath,
|
|
1024
|
+
...slideHandler.slot === "transition" ? {} : { slideIndex: 0 },
|
|
1025
|
+
package: pkg,
|
|
1026
|
+
...masterPlaceholderKeyBySpid === void 0 ? {} : { placeholderKeyBySpid: masterPlaceholderKeyBySpid }
|
|
1027
|
+
});
|
|
1028
|
+
diagnostics.push(...stripSlideIndexFromDiagnostics(outcome.diagnostics));
|
|
1029
|
+
}
|
|
1030
|
+
const usedLayoutIds = /* @__PURE__ */ new Set();
|
|
1031
|
+
const sldLayoutIdLst = masterCursor.child(P_NS, "sldLayoutIdLst");
|
|
1032
|
+
if (sldLayoutIdLst !== void 0) {
|
|
1033
|
+
const layoutIdEntries = sldLayoutIdLst.children(P_NS, "sldLayoutId");
|
|
1034
|
+
for (let index = 0; index < layoutIdEntries.length; index += 1) {
|
|
1035
|
+
const layoutIdCursor = layoutIdEntries[index];
|
|
1036
|
+
validateMasterLayoutNumericId(layoutIdCursor.attr("id"), masterPartPath, layoutIdCursor.xpath, diagnostics);
|
|
1037
|
+
const rId = layoutIdCursor.attr("id", R_NS);
|
|
1038
|
+
if (rId === void 0) {
|
|
1039
|
+
diagnostics.push({
|
|
1040
|
+
code: "broken-relationship",
|
|
1041
|
+
category: "corrupt-input",
|
|
1042
|
+
disposition: "omitted",
|
|
1043
|
+
location: {
|
|
1044
|
+
part: masterPartPath,
|
|
1045
|
+
xpath: layoutIdCursor.xpath
|
|
1046
|
+
},
|
|
1047
|
+
relationshipId: ""
|
|
1048
|
+
});
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
const rel = masterRelById.get(rId);
|
|
1052
|
+
if (rel === void 0 || rel.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" || rel.TargetMode === "External") {
|
|
1053
|
+
diagnostics.push({
|
|
1054
|
+
code: "broken-relationship",
|
|
1055
|
+
category: "corrupt-input",
|
|
1056
|
+
disposition: "omitted",
|
|
1057
|
+
location: {
|
|
1058
|
+
part: masterPartPath,
|
|
1059
|
+
xpath: layoutIdCursor.xpath
|
|
1060
|
+
},
|
|
1061
|
+
relationshipId: rId
|
|
1062
|
+
});
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
const layoutPart = resolvePartPath(masterPartPath, rel.Target);
|
|
1066
|
+
if (layoutPart === void 0 || !pkg.hasPart(layoutPart)) {
|
|
1067
|
+
diagnostics.push({
|
|
1068
|
+
code: "missing-target-part",
|
|
1069
|
+
category: "corrupt-input",
|
|
1070
|
+
disposition: "omitted",
|
|
1071
|
+
location: {
|
|
1072
|
+
part: masterPartPath,
|
|
1073
|
+
xpath: layoutIdCursor.xpath
|
|
1074
|
+
},
|
|
1075
|
+
relationshipId: rId,
|
|
1076
|
+
targetPart: layoutPart ?? rel.Target
|
|
1077
|
+
});
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
const layoutNode = readSlideLayoutPart(pkg, layoutPart, masterPartPath, index + 1, usedLayoutIds, masterClrMap, masterLevelSlideHandlers, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, readPlaceholderVisuals);
|
|
1081
|
+
if (layoutNode !== void 0) {
|
|
1082
|
+
masterNode.append(layoutNode);
|
|
1083
|
+
layoutNodeByPartPath.set(layoutPart, layoutNode);
|
|
1084
|
+
clrMapByLayoutPartPath.set(layoutPart, masterClrMap);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
appendUnconsumedDiagnostics(masterCursor, void 0, diagnostics);
|
|
1089
|
+
return masterNode;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Traverses `<p:sldMasterIdLst>` and `<p:sldLayoutIdLst>` relationships to reconstruct explicit
|
|
1093
|
+
* `SlideMaster` and `SlideLayout` ownership (including idle layouts) onto `deckNode`.
|
|
1094
|
+
*/
|
|
1095
|
+
function importMastersAndLayouts(presCursor, pkg, presRelById, deckNode, usedDeckIds, diagnostics, slideHandlers = [], shapeTreeHandlers = [], registerDeferredSlideLink = () => {}, clrMapByLayoutPartPath = /* @__PURE__ */ new Map(), readPlaceholderVisuals) {
|
|
1096
|
+
const masterLevelSlideHandlers = slideHandlers.filter((handler) => handler.slot === "background" || handler.slot === "header-footer" || handler.slot === "transition" || handler.slot === "timing");
|
|
1097
|
+
const layoutNodeByPartPath = /* @__PURE__ */ new Map();
|
|
1098
|
+
const themesByPartPath = /* @__PURE__ */ new Map();
|
|
1099
|
+
const masterIdLst = presCursor.child(P_NS, "sldMasterIdLst");
|
|
1100
|
+
if (masterIdLst === void 0) return layoutNodeByPartPath;
|
|
1101
|
+
const masterIdEntries = masterIdLst.children(P_NS, "sldMasterId");
|
|
1102
|
+
for (let index = 0; index < masterIdEntries.length; index += 1) {
|
|
1103
|
+
const masterIdCursor = masterIdEntries[index];
|
|
1104
|
+
validateMasterLayoutNumericId(masterIdCursor.attr("id"), pkg.presentationPath, masterIdCursor.xpath, diagnostics);
|
|
1105
|
+
const rId = masterIdCursor.attr("id", R_NS);
|
|
1106
|
+
if (rId === void 0) {
|
|
1107
|
+
diagnostics.push({
|
|
1108
|
+
code: "broken-relationship",
|
|
1109
|
+
category: "corrupt-input",
|
|
1110
|
+
disposition: "omitted",
|
|
1111
|
+
location: {
|
|
1112
|
+
part: pkg.presentationPath,
|
|
1113
|
+
xpath: masterIdCursor.xpath
|
|
1114
|
+
},
|
|
1115
|
+
relationshipId: ""
|
|
1116
|
+
});
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
const rel = presRelById.get(rId);
|
|
1120
|
+
if (rel === void 0 || rel.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" || rel.TargetMode === "External") {
|
|
1121
|
+
diagnostics.push({
|
|
1122
|
+
code: "broken-relationship",
|
|
1123
|
+
category: "corrupt-input",
|
|
1124
|
+
disposition: "omitted",
|
|
1125
|
+
location: {
|
|
1126
|
+
part: pkg.presentationPath,
|
|
1127
|
+
xpath: masterIdCursor.xpath
|
|
1128
|
+
},
|
|
1129
|
+
relationshipId: rId
|
|
1130
|
+
});
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
const masterPart = resolvePartPath(pkg.presentationPath, rel.Target);
|
|
1134
|
+
if (masterPart === void 0 || !pkg.hasPart(masterPart)) {
|
|
1135
|
+
diagnostics.push({
|
|
1136
|
+
code: "missing-target-part",
|
|
1137
|
+
category: "corrupt-input",
|
|
1138
|
+
disposition: "omitted",
|
|
1139
|
+
location: {
|
|
1140
|
+
part: pkg.presentationPath,
|
|
1141
|
+
xpath: masterIdCursor.xpath
|
|
1142
|
+
},
|
|
1143
|
+
relationshipId: rId,
|
|
1144
|
+
targetPart: masterPart ?? rel.Target
|
|
1145
|
+
});
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
const masterNode = readSlideMasterPart(pkg, masterPart, index + 1, usedDeckIds, themesByPartPath, layoutNodeByPartPath, clrMapByLayoutPartPath, masterLevelSlideHandlers, shapeTreeHandlers, registerDeferredSlideLink, diagnostics, readPlaceholderVisuals);
|
|
1149
|
+
if (masterNode !== void 0) deckNode.append(masterNode);
|
|
1150
|
+
}
|
|
1151
|
+
return layoutNodeByPartPath;
|
|
1152
|
+
}
|
|
1153
|
+
export { allocateScopedAuthorId, appendUnconsumedDiagnostics, consumeCommonSlideCreationId, consumeIdentityShapeTreeBoilerplate, importMastersAndLayouts, readShapeTreeItems };
|