@officedk/pptxdk 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,1224 @@
|
|
|
1
|
+
import { schemeColorNameSchema } from "../../../core/dist/theme.js";
|
|
2
|
+
import { placeholderStyleSchema } from "../../../core/dist/placeholders.js";
|
|
3
|
+
import "../../../core/dist/capability.js";
|
|
4
|
+
import { A_NS, EMU_PER_PX, P_NS, XML_NS, emuToPx } from "../../../import/dist/namespaces.js";
|
|
5
|
+
import { extentEmuFragmentSchema, hexRgb6Schema, normalizeBulletCharacter, offsetEmuFragmentSchema, ooxmlAutoNumStartAtSchema, ooxmlBoolSchema, ooxmlIntSchema, ooxmlLineSpacingPercentSchema, ooxmlLineSpacingPointsSchema, ooxmlListLevelSchema, ooxmlNonNegativeIntSchema, ooxmlParagraphSpacingPointsSchema, ooxmlWritableExtentEmuSchema, readOoxmlBoxInsets, readOoxmlRunAttrStyles, transformAttributesFragmentSchema } from "../../../import/dist/xml-fragments.js";
|
|
6
|
+
import { readRunFontSlots } from "../../../import/dist/fonts.js";
|
|
7
|
+
import "../../../import/dist/index.js";
|
|
8
|
+
import { readNonVisualCommonProperties } from "../shape/shape-import.js";
|
|
9
|
+
import { attachDeferredSlideLink, consumeNonPlaceholderNvPr, hasPlaceholderElement } from "../shared/identity.js";
|
|
10
|
+
import { directElementChild, directPlaceholderElement, emitPlaceholderUnbindDiagnostic, isPlaceholderSpElement, materializeUnboundVisualStyle, readNvPrPlaceholder, resolvePlaceholderImportClaim, resolveUnboundPlaceholderBox, stripPlaceholderClearSentinels } from "../shared/placeholder-import.js";
|
|
11
|
+
import { resolvePlaceholderBaseTextStyle, resolvePlaceholderLevelTextStyle } from "../shared/style-inheritance.js";
|
|
12
|
+
import { paragraphStyleKeys, paragraphStyleSchema, textBoxStyleSchema } from "../shared/text-schemas.js";
|
|
13
|
+
import { readSpPrAppearance, readSpPrVisuals } from "../shared/visual.js";
|
|
14
|
+
import { createParagraphNode, createSlideNumberNode, createSpanNode, createSubNode, createSupNode, createTextNode } from "./text-declaration.js";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
// ../capabilities/dist/text/text-import.js
|
|
17
|
+
const NonVisualSpPrFlagsSchema = z.object({ txBox: ooxmlBoolSchema.optional() });
|
|
18
|
+
const BodyPrFragmentSchema = z.object({
|
|
19
|
+
wrap: z.enum(["square", "none"]).optional(),
|
|
20
|
+
rtlCol: ooxmlBoolSchema.optional(),
|
|
21
|
+
anchor: z.enum([
|
|
22
|
+
"t",
|
|
23
|
+
"ctr",
|
|
24
|
+
"b"
|
|
25
|
+
]).optional(),
|
|
26
|
+
anchorCtr: ooxmlBoolSchema.optional(),
|
|
27
|
+
spcFirstLastPara: ooxmlBoolSchema.optional(),
|
|
28
|
+
numCol: z.string().optional(),
|
|
29
|
+
spcCol: z.string().optional()
|
|
30
|
+
});
|
|
31
|
+
const ParagraphAlignSchema = z.enum([
|
|
32
|
+
"l",
|
|
33
|
+
"ctr",
|
|
34
|
+
"r",
|
|
35
|
+
"just"
|
|
36
|
+
]);
|
|
37
|
+
const SpacingPointsXmlSchema = z.object({ val: ooxmlParagraphSpacingPointsSchema });
|
|
38
|
+
const LineSpacingPointsXmlSchema = z.object({ val: ooxmlLineSpacingPointsSchema });
|
|
39
|
+
const SpacingPercentXmlSchema = z.object({ val: ooxmlLineSpacingPercentSchema });
|
|
40
|
+
const TextFieldXmlSchema = z.object({
|
|
41
|
+
id: z.string().min(1),
|
|
42
|
+
type: z.string().min(1)
|
|
43
|
+
});
|
|
44
|
+
const OuterShadowXmlSchema = z.object({
|
|
45
|
+
blurRad: ooxmlWritableExtentEmuSchema.optional(),
|
|
46
|
+
dist: ooxmlWritableExtentEmuSchema.optional(),
|
|
47
|
+
dir: ooxmlIntSchema.optional(),
|
|
48
|
+
algn: z.string().optional(),
|
|
49
|
+
rotWithShape: ooxmlBoolSchema.optional()
|
|
50
|
+
});
|
|
51
|
+
const PercentModifierSchema = z.object({ val: ooxmlNonNegativeIntSchema });
|
|
52
|
+
const SrgbColorSchema = z.object({ val: hexRgb6Schema });
|
|
53
|
+
const SchemeColorSchema = z.object({ val: schemeColorNameSchema });
|
|
54
|
+
const anchorToVerticalAlign = {
|
|
55
|
+
t: "top",
|
|
56
|
+
ctr: "middle",
|
|
57
|
+
b: "bottom"
|
|
58
|
+
};
|
|
59
|
+
const algnToTextAlign = {
|
|
60
|
+
l: "left",
|
|
61
|
+
ctr: "center",
|
|
62
|
+
r: "right",
|
|
63
|
+
just: "justify"
|
|
64
|
+
};
|
|
65
|
+
const textCompatiblePlaceholderRoles = /* @__PURE__ */ new Set([
|
|
66
|
+
"title",
|
|
67
|
+
"ctrTitle",
|
|
68
|
+
"subTitle",
|
|
69
|
+
"body",
|
|
70
|
+
"hdr",
|
|
71
|
+
"obj"
|
|
72
|
+
]);
|
|
73
|
+
const footerPlaceholderRoles = /* @__PURE__ */ new Set([
|
|
74
|
+
"dt",
|
|
75
|
+
"ftr",
|
|
76
|
+
"sldNum"
|
|
77
|
+
]);
|
|
78
|
+
/** Side-effect-free predicate distinguishing `<p:sp>` text boxes (`txBox="1"`) from shapes and placeholders. */
|
|
79
|
+
function isTextBoxSpElement(cursor) {
|
|
80
|
+
if (hasPlaceholderElement(cursor)) return false;
|
|
81
|
+
const nvSpPr = directElementChild(cursor.element, P_NS, "nvSpPr");
|
|
82
|
+
if (nvSpPr === void 0) return false;
|
|
83
|
+
const cNvSpPr = directElementChild(nvSpPr, P_NS, "cNvSpPr");
|
|
84
|
+
if (cNvSpPr === void 0) return false;
|
|
85
|
+
const txBox = cNvSpPr.getAttribute("txBox");
|
|
86
|
+
return txBox === "1" || txBox === "true";
|
|
87
|
+
}
|
|
88
|
+
/** Side-effect-free predicate matching non-footer populated `<p:sp>` placeholder elements. */
|
|
89
|
+
function isTextPlaceholderSpElement(cursor) {
|
|
90
|
+
const ph = directPlaceholderElement(cursor, "nvSpPr");
|
|
91
|
+
if (ph === void 0) return false;
|
|
92
|
+
if (directElementChild(cursor.element, "http://schemas.openxmlformats.org/presentationml/2006/main", "txBody") === void 0) return false;
|
|
93
|
+
const rawType = ph.getAttribute("type");
|
|
94
|
+
const role = rawType === null || rawType === "" ? "obj" : rawType;
|
|
95
|
+
return !footerPlaceholderRoles.has(role);
|
|
96
|
+
}
|
|
97
|
+
function readColorModifier(colorCursor, localName) {
|
|
98
|
+
const mod = colorCursor.child(A_NS, localName);
|
|
99
|
+
if (mod === void 0) return void 0;
|
|
100
|
+
const parsed = PercentModifierSchema.safeParse(mod.attrsObject(["val"]));
|
|
101
|
+
return parsed.success ? parsed.data.val / 1e5 : void 0;
|
|
102
|
+
}
|
|
103
|
+
function readColorElement(containerCursor, part, slideIndex, diagnostics) {
|
|
104
|
+
const srgb = containerCursor.child(A_NS, "srgbClr");
|
|
105
|
+
const scheme = srgb === void 0 ? containerCursor.child(A_NS, "schemeClr") : void 0;
|
|
106
|
+
const colorCursor = srgb ?? scheme;
|
|
107
|
+
if (colorCursor === void 0) return void 0;
|
|
108
|
+
let baseString;
|
|
109
|
+
let schemeSlot;
|
|
110
|
+
if (srgb !== void 0) {
|
|
111
|
+
const raw = srgb.attrsObject(["val"]);
|
|
112
|
+
const parsed = SrgbColorSchema.safeParse(raw);
|
|
113
|
+
if (!parsed.success) {
|
|
114
|
+
diagnostics.push({
|
|
115
|
+
code: "invalid-xml-value",
|
|
116
|
+
category: "corrupt-input",
|
|
117
|
+
disposition: "omitted",
|
|
118
|
+
location: {
|
|
119
|
+
part,
|
|
120
|
+
xpath: srgb.xpath,
|
|
121
|
+
slideIndex
|
|
122
|
+
},
|
|
123
|
+
attributeOrElement: "a:srgbClr/@val",
|
|
124
|
+
rawValue: raw["val"] ?? ""
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
baseString = `#${parsed.data.val.toUpperCase()}`;
|
|
129
|
+
} else if (scheme !== void 0) {
|
|
130
|
+
const raw = scheme.attrsObject(["val"]);
|
|
131
|
+
const parsed = SchemeColorSchema.safeParse(raw);
|
|
132
|
+
if (!parsed.success) {
|
|
133
|
+
diagnostics.push({
|
|
134
|
+
code: "invalid-xml-value",
|
|
135
|
+
category: "corrupt-input",
|
|
136
|
+
disposition: "omitted",
|
|
137
|
+
location: {
|
|
138
|
+
part,
|
|
139
|
+
xpath: scheme.xpath,
|
|
140
|
+
slideIndex
|
|
141
|
+
},
|
|
142
|
+
attributeOrElement: "a:schemeClr/@val",
|
|
143
|
+
rawValue: raw["val"] ?? ""
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
schemeSlot = parsed.data.val;
|
|
148
|
+
}
|
|
149
|
+
const lumMod = readColorModifier(colorCursor, "lumMod");
|
|
150
|
+
const lumOff = readColorModifier(colorCursor, "lumOff");
|
|
151
|
+
const alpha = readColorModifier(colorCursor, "alpha");
|
|
152
|
+
const baseColor = schemeSlot !== void 0 && lumMod !== void 0 ? {
|
|
153
|
+
slot: schemeSlot,
|
|
154
|
+
lumMod: Math.min(1, lumMod),
|
|
155
|
+
...lumOff === void 0 ? {} : { lumOff: Math.min(1, lumOff) }
|
|
156
|
+
} : schemeSlot ?? baseString;
|
|
157
|
+
if (baseColor === void 0) return void 0;
|
|
158
|
+
if (alpha !== void 0) return {
|
|
159
|
+
color: baseColor,
|
|
160
|
+
alpha: Math.min(1, alpha)
|
|
161
|
+
};
|
|
162
|
+
return baseColor;
|
|
163
|
+
}
|
|
164
|
+
function readOuterShadow(rPrCursor, part, slideIndex, diagnostics, allowShadowNone = false) {
|
|
165
|
+
const effectLst = rPrCursor.child(A_NS, "effectLst");
|
|
166
|
+
if (effectLst === void 0) return void 0;
|
|
167
|
+
const outerShdw = effectLst.child(A_NS, "outerShdw");
|
|
168
|
+
if (outerShdw === void 0) return allowShadowNone && effectLst.element.children.length === 0 ? "none" : void 0;
|
|
169
|
+
const raw = outerShdw.attrsObject([
|
|
170
|
+
"blurRad",
|
|
171
|
+
"dist",
|
|
172
|
+
"dir",
|
|
173
|
+
"algn",
|
|
174
|
+
"rotWithShape"
|
|
175
|
+
]);
|
|
176
|
+
const parsed = OuterShadowXmlSchema.safeParse(raw);
|
|
177
|
+
if (!parsed.success) {
|
|
178
|
+
diagnostics.push({
|
|
179
|
+
code: "invalid-xml-value",
|
|
180
|
+
category: "corrupt-input",
|
|
181
|
+
disposition: "omitted",
|
|
182
|
+
location: {
|
|
183
|
+
part,
|
|
184
|
+
xpath: outerShdw.xpath,
|
|
185
|
+
slideIndex
|
|
186
|
+
},
|
|
187
|
+
attributeOrElement: "a:outerShdw",
|
|
188
|
+
rawValue: JSON.stringify(raw)
|
|
189
|
+
});
|
|
190
|
+
outerShdw.suppressUnconsumed();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const color = readColorElement(outerShdw, part, slideIndex, diagnostics);
|
|
194
|
+
const blur = parsed.data.blurRad === void 0 ? void 0 : emuToPx(parsed.data.blurRad);
|
|
195
|
+
const distance = parsed.data.dist === void 0 ? void 0 : emuToPx(parsed.data.dist);
|
|
196
|
+
const angle = parsed.data.dir === void 0 ? void 0 : parsed.data.dir / 6e4;
|
|
197
|
+
return {
|
|
198
|
+
...color === void 0 ? {} : { color },
|
|
199
|
+
...blur === void 0 ? {} : { blur },
|
|
200
|
+
...distance === void 0 ? {} : { distance },
|
|
201
|
+
...angle === void 0 ? {} : { angle }
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function readRunProperties(rPrCursor, part, slideIndex, diagnostics, allowShadowNone = false) {
|
|
205
|
+
const attrStyles = readOoxmlRunAttrStyles({
|
|
206
|
+
rPrCursor,
|
|
207
|
+
location: {
|
|
208
|
+
part,
|
|
209
|
+
slideIndex
|
|
210
|
+
},
|
|
211
|
+
diagnostics,
|
|
212
|
+
allowBaseline: true,
|
|
213
|
+
allowNoneTextDecoration: true,
|
|
214
|
+
diagnoseUnsupportedEnums: true
|
|
215
|
+
});
|
|
216
|
+
let color;
|
|
217
|
+
const solidFill = rPrCursor.child(A_NS, "solidFill");
|
|
218
|
+
if (solidFill !== void 0) color = readColorElement(solidFill, part, slideIndex, diagnostics);
|
|
219
|
+
const textShadow = readOuterShadow(rPrCursor, part, slideIndex, diagnostics, allowShadowNone);
|
|
220
|
+
const { fontFamily, eastAsianFontFamily } = readRunFontSlots(rPrCursor);
|
|
221
|
+
return {
|
|
222
|
+
style: {
|
|
223
|
+
...fontFamily === void 0 ? {} : { fontFamily },
|
|
224
|
+
...eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily },
|
|
225
|
+
...attrStyles.fontSize === void 0 ? {} : { fontSize: attrStyles.fontSize },
|
|
226
|
+
...attrStyles.fontWeight === void 0 ? {} : { fontWeight: attrStyles.fontWeight },
|
|
227
|
+
...attrStyles.fontStyle === void 0 ? {} : { fontStyle: attrStyles.fontStyle },
|
|
228
|
+
...color === void 0 ? {} : { color },
|
|
229
|
+
...attrStyles.letterSpacing === void 0 ? {} : { letterSpacing: attrStyles.letterSpacing },
|
|
230
|
+
...attrStyles.textTransform === void 0 ? {} : { textTransform: attrStyles.textTransform },
|
|
231
|
+
...attrStyles.textDecoration === void 0 ? {} : { textDecoration: attrStyles.textDecoration },
|
|
232
|
+
...textShadow === void 0 ? {} : { textShadow },
|
|
233
|
+
...attrStyles.lang === void 0 ? {} : { lang: attrStyles.lang },
|
|
234
|
+
...attrStyles.baselineShift === void 0 ? {} : { baselineShift: attrStyles.baselineShift }
|
|
235
|
+
},
|
|
236
|
+
...attrStyles.sizePt === void 0 ? {} : { sizePt: attrStyles.sizePt },
|
|
237
|
+
...attrStyles.inlineKind === void 0 ? {} : { inlineKind: attrStyles.inlineKind }
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Import handler for `<a:fld type="slidenum">` inline text fields (`text-field-slidenum`).
|
|
242
|
+
*/
|
|
243
|
+
const textFieldSlideNumImportHandler = {
|
|
244
|
+
target: "text-inline",
|
|
245
|
+
localName: "fld",
|
|
246
|
+
matches(cursor) {
|
|
247
|
+
return cursor.element.getAttribute("type") === "slidenum";
|
|
248
|
+
},
|
|
249
|
+
read(context) {
|
|
250
|
+
const { cursor, part, slideIndex } = context;
|
|
251
|
+
const diagnostics = [];
|
|
252
|
+
const rawField = cursor.attrsObject(["id", "type"]);
|
|
253
|
+
const parsedField = TextFieldXmlSchema.safeParse(rawField);
|
|
254
|
+
const rPrCursor = cursor.child(A_NS, "rPr");
|
|
255
|
+
cursor.ignoreEmptyChild(A_NS, "pPr");
|
|
256
|
+
const tCursor = cursor.child(A_NS, "t");
|
|
257
|
+
if (tCursor !== void 0) tCursor.consumeAttr("space", XML_NS);
|
|
258
|
+
const fallbackText = tCursor?.textContent ?? "";
|
|
259
|
+
if (!parsedField.success) {
|
|
260
|
+
diagnostics.push({
|
|
261
|
+
code: "invalid-xml-value",
|
|
262
|
+
category: "corrupt-input",
|
|
263
|
+
disposition: "omitted",
|
|
264
|
+
location: {
|
|
265
|
+
part,
|
|
266
|
+
xpath: cursor.xpath,
|
|
267
|
+
slideIndex
|
|
268
|
+
},
|
|
269
|
+
attributeOrElement: "a:fld",
|
|
270
|
+
rawValue: JSON.stringify(rawField)
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
kind: "unsupported",
|
|
274
|
+
fieldType: rawField["type"] ?? "",
|
|
275
|
+
...rPrCursor === void 0 ? {} : { rPrCursor },
|
|
276
|
+
fallbackText,
|
|
277
|
+
diagnostics
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (parsedField.data.type !== "slidenum") {
|
|
281
|
+
diagnostics.push({
|
|
282
|
+
code: "unsupported-mechanism",
|
|
283
|
+
category: "unsupported",
|
|
284
|
+
disposition: "omitted",
|
|
285
|
+
location: {
|
|
286
|
+
part,
|
|
287
|
+
xpath: cursor.xpath,
|
|
288
|
+
slideIndex
|
|
289
|
+
},
|
|
290
|
+
namespaceUri: cursor.namespaceUri,
|
|
291
|
+
localName: cursor.localName,
|
|
292
|
+
mechanismHint: `text-field:${parsedField.data.type}`
|
|
293
|
+
});
|
|
294
|
+
return {
|
|
295
|
+
kind: "unsupported",
|
|
296
|
+
fieldType: parsedField.data.type,
|
|
297
|
+
...rPrCursor === void 0 ? {} : { rPrCursor },
|
|
298
|
+
fallbackText,
|
|
299
|
+
diagnostics
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
kind: "slide-number",
|
|
304
|
+
fieldType: "slidenum",
|
|
305
|
+
...rPrCursor === void 0 ? {} : { rPrCursor },
|
|
306
|
+
fallbackText,
|
|
307
|
+
diagnostics
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
function readParagraph(pCursor, part, slideIndex, diagnostics, allowShadowNone = false) {
|
|
312
|
+
const pPr = pCursor.child(A_NS, "pPr");
|
|
313
|
+
let align;
|
|
314
|
+
let lvl;
|
|
315
|
+
let buNone = false;
|
|
316
|
+
let list;
|
|
317
|
+
let lnSpcNode;
|
|
318
|
+
let spcAftNode;
|
|
319
|
+
let defParaSizePt;
|
|
320
|
+
if (pPr !== void 0) {
|
|
321
|
+
const rawPPr = pPr.attrsObject([
|
|
322
|
+
"algn",
|
|
323
|
+
"rtl",
|
|
324
|
+
"lvl",
|
|
325
|
+
"marL",
|
|
326
|
+
"indent",
|
|
327
|
+
"fontAlgn",
|
|
328
|
+
"eaLnBrk",
|
|
329
|
+
"latinLnBrk",
|
|
330
|
+
"hangingPunct",
|
|
331
|
+
"defTabSz"
|
|
332
|
+
]);
|
|
333
|
+
if (rawPPr["algn"] !== void 0) {
|
|
334
|
+
const parsedAlgn = ParagraphAlignSchema.safeParse(rawPPr["algn"]);
|
|
335
|
+
if (parsedAlgn.success) align = algnToTextAlign[parsedAlgn.data];
|
|
336
|
+
else diagnostics.push({
|
|
337
|
+
code: "invalid-xml-value",
|
|
338
|
+
category: "corrupt-input",
|
|
339
|
+
disposition: "recovered",
|
|
340
|
+
location: {
|
|
341
|
+
part,
|
|
342
|
+
xpath: `${pPr.xpath}/@algn`,
|
|
343
|
+
slideIndex
|
|
344
|
+
},
|
|
345
|
+
attributeOrElement: "@algn",
|
|
346
|
+
rawValue: rawPPr["algn"]
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (rawPPr["rtl"] !== void 0 && !ooxmlBoolSchema.safeParse(rawPPr["rtl"]).success) diagnostics.push({
|
|
350
|
+
code: "invalid-xml-value",
|
|
351
|
+
category: "corrupt-input",
|
|
352
|
+
disposition: "recovered",
|
|
353
|
+
location: {
|
|
354
|
+
part,
|
|
355
|
+
xpath: `${pPr.xpath}/@rtl`,
|
|
356
|
+
slideIndex
|
|
357
|
+
},
|
|
358
|
+
attributeOrElement: "@rtl",
|
|
359
|
+
rawValue: rawPPr["rtl"]
|
|
360
|
+
});
|
|
361
|
+
if (rawPPr["lvl"] !== void 0) {
|
|
362
|
+
const parsedLvl = ooxmlListLevelSchema.safeParse(rawPPr["lvl"]);
|
|
363
|
+
if (parsedLvl.success) lvl = parsedLvl.data;
|
|
364
|
+
else diagnostics.push({
|
|
365
|
+
code: "invalid-xml-value",
|
|
366
|
+
category: "corrupt-input",
|
|
367
|
+
disposition: "recovered",
|
|
368
|
+
location: {
|
|
369
|
+
part,
|
|
370
|
+
xpath: `${pPr.xpath}/@lvl`,
|
|
371
|
+
slideIndex
|
|
372
|
+
},
|
|
373
|
+
attributeOrElement: "@lvl",
|
|
374
|
+
rawValue: rawPPr["lvl"]
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
const spcBefNode = pPr.child(A_NS, "spcBef");
|
|
378
|
+
if (spcBefNode !== void 0) {
|
|
379
|
+
spcBefNode.child(A_NS, "spcPts")?.consumeAttr("val");
|
|
380
|
+
spcBefNode.child(A_NS, "spcPct")?.consumeAttr("val");
|
|
381
|
+
}
|
|
382
|
+
lnSpcNode = pPr.child(A_NS, "lnSpc");
|
|
383
|
+
spcAftNode = pPr.child(A_NS, "spcAft");
|
|
384
|
+
if (pPr.child("http://schemas.openxmlformats.org/drawingml/2006/main", "buNone") !== void 0) buNone = true;
|
|
385
|
+
pPr.child(A_NS, "buFont")?.attrsObject([
|
|
386
|
+
"typeface",
|
|
387
|
+
"pitchFamily",
|
|
388
|
+
"charset",
|
|
389
|
+
"panose"
|
|
390
|
+
]);
|
|
391
|
+
const buChar = pPr.child(A_NS, "buChar");
|
|
392
|
+
const buAutoNum = pPr.child(A_NS, "buAutoNum");
|
|
393
|
+
if (buChar !== void 0) {
|
|
394
|
+
const rawBu = buChar.attrsObject(["char"]);
|
|
395
|
+
const normalized = normalizeBulletCharacter(rawBu["char"]);
|
|
396
|
+
if (normalized.recovered) diagnostics.push({
|
|
397
|
+
code: "invalid-xml-value",
|
|
398
|
+
category: "corrupt-input",
|
|
399
|
+
disposition: "recovered",
|
|
400
|
+
location: {
|
|
401
|
+
part,
|
|
402
|
+
xpath: buChar.xpath,
|
|
403
|
+
slideIndex
|
|
404
|
+
},
|
|
405
|
+
attributeOrElement: "a:buChar/@char",
|
|
406
|
+
rawValue: rawBu["char"] ?? ""
|
|
407
|
+
});
|
|
408
|
+
list = {
|
|
409
|
+
type: "bullet",
|
|
410
|
+
character: normalized.character,
|
|
411
|
+
...lvl === void 0 ? {} : { level: lvl }
|
|
412
|
+
};
|
|
413
|
+
} else if (buAutoNum !== void 0) {
|
|
414
|
+
const rawNum = buAutoNum.attrsObject(["type", "startAt"]);
|
|
415
|
+
const rawType = rawNum["type"];
|
|
416
|
+
if (rawType === void 0 || rawType.length === 0) diagnostics.push({
|
|
417
|
+
code: "invalid-xml-value",
|
|
418
|
+
category: "corrupt-input",
|
|
419
|
+
disposition: "omitted",
|
|
420
|
+
location: {
|
|
421
|
+
part,
|
|
422
|
+
xpath: buAutoNum.xpath,
|
|
423
|
+
slideIndex
|
|
424
|
+
},
|
|
425
|
+
attributeOrElement: "a:buAutoNum",
|
|
426
|
+
rawValue: JSON.stringify(rawNum)
|
|
427
|
+
});
|
|
428
|
+
else {
|
|
429
|
+
if (rawType !== "arabicPeriod") diagnostics.push({
|
|
430
|
+
code: "invalid-xml-value",
|
|
431
|
+
category: "corrupt-input",
|
|
432
|
+
disposition: "recovered",
|
|
433
|
+
location: {
|
|
434
|
+
part,
|
|
435
|
+
xpath: `${buAutoNum.xpath}/@type`,
|
|
436
|
+
slideIndex
|
|
437
|
+
},
|
|
438
|
+
attributeOrElement: "a:buAutoNum/@type",
|
|
439
|
+
rawValue: rawType
|
|
440
|
+
});
|
|
441
|
+
let startAt;
|
|
442
|
+
if (rawNum["startAt"] !== void 0) {
|
|
443
|
+
const parsedStart = ooxmlAutoNumStartAtSchema.safeParse(rawNum["startAt"]);
|
|
444
|
+
if (parsedStart.success) startAt = parsedStart.data;
|
|
445
|
+
else diagnostics.push({
|
|
446
|
+
code: "invalid-xml-value",
|
|
447
|
+
category: "corrupt-input",
|
|
448
|
+
disposition: "omitted",
|
|
449
|
+
location: {
|
|
450
|
+
part,
|
|
451
|
+
xpath: `${buAutoNum.xpath}/@startAt`,
|
|
452
|
+
slideIndex
|
|
453
|
+
},
|
|
454
|
+
attributeOrElement: "a:buAutoNum/@startAt",
|
|
455
|
+
rawValue: rawNum["startAt"]
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
list = {
|
|
459
|
+
type: "number",
|
|
460
|
+
style: "arabicPeriod",
|
|
461
|
+
...startAt === void 0 ? {} : { startAt },
|
|
462
|
+
...lvl === void 0 ? {} : { level: lvl }
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
const defRPr = pPr.child(A_NS, "defRPr");
|
|
467
|
+
if (defRPr !== void 0) defParaSizePt = readRunProperties(defRPr, part, slideIndex, diagnostics, allowShadowNone).sizePt;
|
|
468
|
+
}
|
|
469
|
+
const runs = [];
|
|
470
|
+
let endParaSizePt;
|
|
471
|
+
for (const child of pCursor.remainingElementChildren()) {
|
|
472
|
+
if (child.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && child.localName === "r") {
|
|
473
|
+
const rPr = child.child(A_NS, "rPr");
|
|
474
|
+
const parsedRPr = rPr === void 0 ? { style: {} } : readRunProperties(rPr, part, slideIndex, diagnostics, allowShadowNone);
|
|
475
|
+
const t = child.child(A_NS, "t");
|
|
476
|
+
if (t !== void 0) {
|
|
477
|
+
t.consumeAttr("space", XML_NS);
|
|
478
|
+
runs.push({
|
|
479
|
+
kind: parsedRPr.inlineKind ?? "text",
|
|
480
|
+
text: t.textContent,
|
|
481
|
+
style: parsedRPr.style,
|
|
482
|
+
...parsedRPr.sizePt === void 0 ? {} : { sizePt: parsedRPr.sizePt }
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
if (child.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && child.localName === "br") {
|
|
488
|
+
const rPr = child.child(A_NS, "rPr");
|
|
489
|
+
const parsedRPr = rPr === void 0 ? { style: {} } : readRunProperties(rPr, part, slideIndex, diagnostics, allowShadowNone);
|
|
490
|
+
runs.push({
|
|
491
|
+
kind: parsedRPr.inlineKind ?? "text",
|
|
492
|
+
text: "\n",
|
|
493
|
+
style: parsedRPr.style,
|
|
494
|
+
...parsedRPr.sizePt === void 0 ? {} : { sizePt: parsedRPr.sizePt }
|
|
495
|
+
});
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (child.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && child.localName === "fld") {
|
|
499
|
+
const outcome = textFieldSlideNumImportHandler.read({
|
|
500
|
+
cursor: child,
|
|
501
|
+
part,
|
|
502
|
+
slideIndex
|
|
503
|
+
});
|
|
504
|
+
diagnostics.push(...outcome.diagnostics);
|
|
505
|
+
if (outcome.kind === "slide-number") {
|
|
506
|
+
const parsedRPr = outcome.rPrCursor === void 0 ? { style: {} } : readRunProperties(outcome.rPrCursor, part, slideIndex, diagnostics, allowShadowNone);
|
|
507
|
+
const fieldStyle = parsedRPr.inlineKind === void 0 ? parsedRPr.style : {
|
|
508
|
+
...parsedRPr.style,
|
|
509
|
+
baselineShift: parsedRPr.inlineKind === "sup" ? "30%" : "-25%"
|
|
510
|
+
};
|
|
511
|
+
runs.push({
|
|
512
|
+
kind: "slide-number",
|
|
513
|
+
style: fieldStyle,
|
|
514
|
+
...parsedRPr.sizePt === void 0 ? {} : { sizePt: parsedRPr.sizePt }
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (child.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && child.localName === "endParaRPr") {
|
|
520
|
+
endParaSizePt = readRunProperties(child, part, slideIndex, diagnostics, allowShadowNone).sizePt;
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
diagnostics.push({
|
|
524
|
+
code: "unconsumed-xml",
|
|
525
|
+
category: "unsupported",
|
|
526
|
+
disposition: "omitted",
|
|
527
|
+
kind: "element",
|
|
528
|
+
location: {
|
|
529
|
+
part,
|
|
530
|
+
xpath: child.xpath,
|
|
531
|
+
slideIndex
|
|
532
|
+
},
|
|
533
|
+
namespaceUri: child.namespaceUri,
|
|
534
|
+
localName: child.localName
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
const baseFontPt = runs.find((run) => run.sizePt !== void 0)?.sizePt ?? endParaSizePt ?? defParaSizePt ?? 18;
|
|
538
|
+
let lineHeight;
|
|
539
|
+
if (lnSpcNode !== void 0) {
|
|
540
|
+
const spcPts = lnSpcNode.child(A_NS, "spcPts");
|
|
541
|
+
const spcPct = spcPts === void 0 ? lnSpcNode.child(A_NS, "spcPct") : void 0;
|
|
542
|
+
if (spcPts !== void 0) {
|
|
543
|
+
const raw = spcPts.attrsObject(["val"]);
|
|
544
|
+
const parsed = LineSpacingPointsXmlSchema.safeParse(raw);
|
|
545
|
+
if (!parsed.success) diagnostics.push({
|
|
546
|
+
code: "invalid-xml-value",
|
|
547
|
+
category: "corrupt-input",
|
|
548
|
+
disposition: "omitted",
|
|
549
|
+
location: {
|
|
550
|
+
part,
|
|
551
|
+
xpath: spcPts.xpath,
|
|
552
|
+
slideIndex
|
|
553
|
+
},
|
|
554
|
+
attributeOrElement: "a:spcPts/@val",
|
|
555
|
+
rawValue: raw["val"] ?? ""
|
|
556
|
+
});
|
|
557
|
+
else lineHeight = `${parsed.data.val / 100}pt`;
|
|
558
|
+
} else if (spcPct !== void 0) {
|
|
559
|
+
const raw = spcPct.attrsObject(["val"]);
|
|
560
|
+
const parsed = SpacingPercentXmlSchema.safeParse(raw);
|
|
561
|
+
if (!parsed.success) diagnostics.push({
|
|
562
|
+
code: "invalid-xml-value",
|
|
563
|
+
category: "corrupt-input",
|
|
564
|
+
disposition: "omitted",
|
|
565
|
+
location: {
|
|
566
|
+
part,
|
|
567
|
+
xpath: spcPct.xpath,
|
|
568
|
+
slideIndex
|
|
569
|
+
},
|
|
570
|
+
attributeOrElement: "a:spcPct/@val",
|
|
571
|
+
rawValue: raw["val"] ?? ""
|
|
572
|
+
});
|
|
573
|
+
else lineHeight = `${parsed.data.val / 1e3}%`;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
let spacingAfter;
|
|
577
|
+
if (spcAftNode !== void 0) {
|
|
578
|
+
const spcPts = spcAftNode.child(A_NS, "spcPts");
|
|
579
|
+
const spcPct = spcPts === void 0 ? spcAftNode.child(A_NS, "spcPct") : void 0;
|
|
580
|
+
if (spcPts !== void 0) {
|
|
581
|
+
const raw = spcPts.attrsObject(["val"]);
|
|
582
|
+
const parsed = SpacingPointsXmlSchema.safeParse(raw);
|
|
583
|
+
if (!parsed.success) diagnostics.push({
|
|
584
|
+
code: "invalid-xml-value",
|
|
585
|
+
category: "corrupt-input",
|
|
586
|
+
disposition: "omitted",
|
|
587
|
+
location: {
|
|
588
|
+
part,
|
|
589
|
+
xpath: spcPts.xpath,
|
|
590
|
+
slideIndex
|
|
591
|
+
},
|
|
592
|
+
attributeOrElement: "a:spcPts/@val",
|
|
593
|
+
rawValue: raw["val"] ?? ""
|
|
594
|
+
});
|
|
595
|
+
else spacingAfter = parsed.data.val / 75;
|
|
596
|
+
} else if (spcPct !== void 0) {
|
|
597
|
+
const raw = spcPct.attrsObject(["val"]);
|
|
598
|
+
const parsed = ooxmlNonNegativeIntSchema.safeParse(raw["val"]);
|
|
599
|
+
const computed = parsed.success ? baseFontPt * parsed.data / 1e5 * (4 / 3) : void 0;
|
|
600
|
+
if (computed === void 0 || !Number.isFinite(computed) || Math.round(computed * 75) > 158400) diagnostics.push({
|
|
601
|
+
code: "invalid-xml-value",
|
|
602
|
+
category: "corrupt-input",
|
|
603
|
+
disposition: "omitted",
|
|
604
|
+
location: {
|
|
605
|
+
part,
|
|
606
|
+
xpath: spcPct.xpath,
|
|
607
|
+
slideIndex
|
|
608
|
+
},
|
|
609
|
+
attributeOrElement: "a:spcPct/@val",
|
|
610
|
+
rawValue: raw["val"] ?? ""
|
|
611
|
+
});
|
|
612
|
+
else spacingAfter = computed;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
runs,
|
|
617
|
+
style: {
|
|
618
|
+
...align === void 0 ? {} : { align },
|
|
619
|
+
...lineHeight === void 0 ? {} : { lineHeight },
|
|
620
|
+
...spacingAfter === void 0 ? {} : { spacingAfter },
|
|
621
|
+
...list === void 0 ? {} : { list }
|
|
622
|
+
},
|
|
623
|
+
...lvl === void 0 ? {} : { level0: lvl },
|
|
624
|
+
...buNone ? { buNone: true } : {}
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Shared rich-text body reader for text boxes, shapes, table cells, and speaker notes.
|
|
629
|
+
*/
|
|
630
|
+
function readRichTextBody(txBody, part, slideIndex, diagnostics, _clrMap, options) {
|
|
631
|
+
let paddingTop;
|
|
632
|
+
let paddingRight;
|
|
633
|
+
let paddingBottom;
|
|
634
|
+
let paddingLeft;
|
|
635
|
+
let verticalAlign;
|
|
636
|
+
let textWrap;
|
|
637
|
+
const bodyPr = txBody.child(A_NS, "bodyPr");
|
|
638
|
+
if (bodyPr !== void 0) {
|
|
639
|
+
const rawBodyPr = bodyPr.attrsObject([
|
|
640
|
+
"wrap",
|
|
641
|
+
"rtlCol",
|
|
642
|
+
"lIns",
|
|
643
|
+
"tIns",
|
|
644
|
+
"rIns",
|
|
645
|
+
"bIns",
|
|
646
|
+
"anchor",
|
|
647
|
+
"anchorCtr",
|
|
648
|
+
"spcFirstLastPara",
|
|
649
|
+
"numCol",
|
|
650
|
+
"spcCol"
|
|
651
|
+
]);
|
|
652
|
+
const parsedBodyPr = BodyPrFragmentSchema.safeParse(rawBodyPr);
|
|
653
|
+
if (!parsedBodyPr.success) diagnostics.push({
|
|
654
|
+
code: "invalid-xml-value",
|
|
655
|
+
category: "corrupt-input",
|
|
656
|
+
disposition: "recovered",
|
|
657
|
+
location: {
|
|
658
|
+
part,
|
|
659
|
+
xpath: bodyPr.xpath,
|
|
660
|
+
slideIndex
|
|
661
|
+
},
|
|
662
|
+
attributeOrElement: "a:bodyPr",
|
|
663
|
+
rawValue: JSON.stringify(rawBodyPr)
|
|
664
|
+
});
|
|
665
|
+
else {
|
|
666
|
+
const b = parsedBodyPr.data;
|
|
667
|
+
if (b.wrap === "none") textWrap = "nowrap";
|
|
668
|
+
else if (b.wrap === "square") textWrap = "normal";
|
|
669
|
+
if (b.anchor !== void 0) verticalAlign = anchorToVerticalAlign[b.anchor];
|
|
670
|
+
}
|
|
671
|
+
const insets = readOoxmlBoxInsets({
|
|
672
|
+
rawAttrs: rawBodyPr,
|
|
673
|
+
attrNames: {
|
|
674
|
+
left: "lIns",
|
|
675
|
+
top: "tIns",
|
|
676
|
+
right: "rIns",
|
|
677
|
+
bottom: "bIns"
|
|
678
|
+
},
|
|
679
|
+
elementXpath: bodyPr.xpath,
|
|
680
|
+
location: {
|
|
681
|
+
part,
|
|
682
|
+
slideIndex
|
|
683
|
+
},
|
|
684
|
+
diagnostics
|
|
685
|
+
});
|
|
686
|
+
paddingLeft = insets.paddingLeft;
|
|
687
|
+
paddingTop = insets.paddingTop;
|
|
688
|
+
paddingRight = insets.paddingRight;
|
|
689
|
+
paddingBottom = insets.paddingBottom;
|
|
690
|
+
bodyPr.ignoreEmptyChild(A_NS, "noAutofit");
|
|
691
|
+
bodyPr.ignoreEmptyChild(A_NS, "spAutoFit");
|
|
692
|
+
bodyPr.child(A_NS, "normAutofit")?.attrsObject(["fontScale", "lnSpcReduction"]);
|
|
693
|
+
}
|
|
694
|
+
txBody.ignoreEmptyChild(A_NS, "lstStyle");
|
|
695
|
+
const importedParagraphs = txBody.children(A_NS, "p").map((pCursor) => readParagraph(pCursor, part, slideIndex, diagnostics, options?.allowShadowNone === true));
|
|
696
|
+
return {
|
|
697
|
+
boxStyle: {
|
|
698
|
+
...paddingTop === void 0 ? {} : { paddingTop },
|
|
699
|
+
...paddingRight === void 0 ? {} : { paddingRight },
|
|
700
|
+
...paddingBottom === void 0 ? {} : { paddingBottom },
|
|
701
|
+
...paddingLeft === void 0 ? {} : { paddingLeft },
|
|
702
|
+
...verticalAlign === void 0 ? {} : { verticalAlign },
|
|
703
|
+
...textWrap === void 0 ? {} : { textWrap }
|
|
704
|
+
},
|
|
705
|
+
importedParagraphs
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
/** Populates a `RichTextContainer` (`TextNode`, `ShapeNode`, `CellNode`, `NotesNode`) from imported paragraphs. */
|
|
709
|
+
function populateRichTextNode(target, importedParagraphs) {
|
|
710
|
+
const paragraphNodes = importedParagraphs.map((para) => {
|
|
711
|
+
const pNode = createParagraphNode(Object.keys(para.style).length === 0 ? {} : { style: para.style });
|
|
712
|
+
if (para.runs.length === 1 && para.runs[0].kind === "text" && Object.keys(para.runs[0].style).length === 0) pNode.content(para.runs[0].text);
|
|
713
|
+
else if (para.runs.length > 0) pNode.content(...para.runs.map((run) => {
|
|
714
|
+
if (run.kind === "slide-number") return createSlideNumberNode(Object.keys(run.style).length === 0 ? {} : { style: run.style });
|
|
715
|
+
const runProps = Object.keys(run.style).length === 0 ? {} : { style: run.style };
|
|
716
|
+
if (run.kind === "sup") return createSupNode(runProps).content(run.text);
|
|
717
|
+
if (run.kind === "sub") return createSubNode(runProps).content(run.text);
|
|
718
|
+
return Object.keys(run.style).length === 0 ? run.text : createSpanNode({ style: run.style }).content(run.text);
|
|
719
|
+
}));
|
|
720
|
+
return pNode;
|
|
721
|
+
});
|
|
722
|
+
target.content(...paragraphNodes);
|
|
723
|
+
}
|
|
724
|
+
function textBoxVisualStyle(appearanceStyle, borderArrows, geometry, boxSize, rotate, location, diagnostics) {
|
|
725
|
+
const { border: rawBorder, ...restVisualStyle } = appearanceStyle;
|
|
726
|
+
const border = rawBorder;
|
|
727
|
+
const hasHeadArrow = borderArrows?.startArrow !== void 0;
|
|
728
|
+
const hasTailArrow = borderArrows?.endArrow !== void 0;
|
|
729
|
+
if (hasHeadArrow || hasTailArrow) diagnostics.push({
|
|
730
|
+
code: "unsupported-mechanism",
|
|
731
|
+
category: "unsupported",
|
|
732
|
+
disposition: "omitted",
|
|
733
|
+
location,
|
|
734
|
+
namespaceUri: A_NS,
|
|
735
|
+
localName: hasHeadArrow ? "headEnd" : "tailEnd",
|
|
736
|
+
mechanismHint: "textbox-line-arrow"
|
|
737
|
+
});
|
|
738
|
+
let borderRadius;
|
|
739
|
+
if (geometry === "roundRect") {
|
|
740
|
+
if (boxSize !== void 0) borderRadius = 16667 / 1e5 * Math.min(boxSize.width, boxSize.height);
|
|
741
|
+
} else if (typeof geometry === "object" && geometry.type === "preset") {
|
|
742
|
+
if (geometry.name === "roundRect") {
|
|
743
|
+
if (boxSize !== void 0) {
|
|
744
|
+
const adj = geometry.adjust?.["adj"] ?? 16667;
|
|
745
|
+
if (adj > 0) borderRadius = adj / 1e5 * Math.min(boxSize.width, boxSize.height);
|
|
746
|
+
}
|
|
747
|
+
} else if (geometry.name !== "rect") diagnostics.push({
|
|
748
|
+
code: "unsupported-mechanism",
|
|
749
|
+
category: "unsupported",
|
|
750
|
+
disposition: "omitted",
|
|
751
|
+
location,
|
|
752
|
+
namespaceUri: A_NS,
|
|
753
|
+
localName: "prstGeom",
|
|
754
|
+
mechanismHint: `textbox-preset:${geometry.name}`
|
|
755
|
+
});
|
|
756
|
+
} else if (typeof geometry === "object" && geometry.type === "custom") diagnostics.push({
|
|
757
|
+
code: "unsupported-mechanism",
|
|
758
|
+
category: "unsupported",
|
|
759
|
+
disposition: "omitted",
|
|
760
|
+
location,
|
|
761
|
+
namespaceUri: A_NS,
|
|
762
|
+
localName: "custGeom",
|
|
763
|
+
mechanismHint: "textbox-custGeom"
|
|
764
|
+
});
|
|
765
|
+
return {
|
|
766
|
+
...restVisualStyle,
|
|
767
|
+
...border === void 0 ? {} : { border },
|
|
768
|
+
...borderRadius === void 0 ? {} : { borderRadius },
|
|
769
|
+
...rotate === void 0 ? {} : { rotate }
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
function flattenImportedTextBody(imported, visualStyle) {
|
|
773
|
+
const importedParagraphs = imported?.importedParagraphs ?? [];
|
|
774
|
+
const singleParagraph = importedParagraphs.length === 1 ? importedParagraphs[0] : void 0;
|
|
775
|
+
const singleTextRun = singleParagraph !== void 0 && singleParagraph.style.list === void 0 && singleParagraph.runs.length === 1 && singleParagraph.runs[0].kind === "text" && singleParagraph.runs[0].style.baselineShift === void 0 ? singleParagraph.runs[0] : void 0;
|
|
776
|
+
const singleEmptyParagraph = singleParagraph !== void 0 && singleParagraph.style.list === void 0 && singleParagraph.runs.length === 0;
|
|
777
|
+
const flatParagraphStyle = singleTextRun === void 0 && !singleEmptyParagraph || singleParagraph === void 0 ? void 0 : (() => {
|
|
778
|
+
const { list: _list, ...rest } = singleParagraph.style;
|
|
779
|
+
return rest;
|
|
780
|
+
})();
|
|
781
|
+
const { baselineShift: _baselineShift, ...hoistableRunStyle } = singleTextRun === void 0 ? {} : singleTextRun.style;
|
|
782
|
+
const boxStyle = {
|
|
783
|
+
...imported?.boxStyle,
|
|
784
|
+
...visualStyle,
|
|
785
|
+
...flatParagraphStyle,
|
|
786
|
+
...hoistableRunStyle
|
|
787
|
+
};
|
|
788
|
+
if (singleTextRun !== void 0) return {
|
|
789
|
+
boxStyle,
|
|
790
|
+
singleText: singleTextRun.text
|
|
791
|
+
};
|
|
792
|
+
if (!singleEmptyParagraph && importedParagraphs.length > 0) return {
|
|
793
|
+
boxStyle,
|
|
794
|
+
paragraphsToPopulate: importedParagraphs
|
|
795
|
+
};
|
|
796
|
+
return { boxStyle };
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Reads a Transitional `<p:sp>` text box (`<p:cNvSpPr txBox="1"/>` without `<p:ph>`) into an editable `TextNode`.
|
|
800
|
+
*/
|
|
801
|
+
function readTextBoxSp(context) {
|
|
802
|
+
const { cursor, part, slideIndex, package: pkg } = context;
|
|
803
|
+
const diagnostics = [];
|
|
804
|
+
const nvSpPr = cursor.child(P_NS, "nvSpPr");
|
|
805
|
+
if (nvSpPr === void 0) {
|
|
806
|
+
diagnostics.push({
|
|
807
|
+
code: "corrupt-part",
|
|
808
|
+
category: "corrupt-input",
|
|
809
|
+
disposition: "omitted",
|
|
810
|
+
location: {
|
|
811
|
+
part,
|
|
812
|
+
xpath: cursor.xpath,
|
|
813
|
+
slideIndex
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
return { diagnostics };
|
|
817
|
+
}
|
|
818
|
+
const cNvPr = nvSpPr.child(P_NS, "cNvPr");
|
|
819
|
+
const { objectId, objectName, link, deferredSlideLink } = readNonVisualCommonProperties(cNvPr, context, diagnostics);
|
|
820
|
+
cNvPr?.ignoreEmptyChild(A_NS, "extLst");
|
|
821
|
+
const cNvSpPr = nvSpPr.child(P_NS, "cNvSpPr");
|
|
822
|
+
if (cNvSpPr !== void 0) {
|
|
823
|
+
const rawFlags = cNvSpPr.attrsObject(["txBox"]);
|
|
824
|
+
NonVisualSpPrFlagsSchema.safeParse(rawFlags);
|
|
825
|
+
cNvSpPr.child(A_NS, "spLocks")?.attrsObject([
|
|
826
|
+
"noGrp",
|
|
827
|
+
"noRot",
|
|
828
|
+
"noChangeAspect",
|
|
829
|
+
"noMove",
|
|
830
|
+
"noResize",
|
|
831
|
+
"noSelect"
|
|
832
|
+
]);
|
|
833
|
+
}
|
|
834
|
+
consumeNonPlaceholderNvPr(nvSpPr);
|
|
835
|
+
const location = {
|
|
836
|
+
part,
|
|
837
|
+
slideIndex,
|
|
838
|
+
...objectId === void 0 ? {} : { objectId },
|
|
839
|
+
...objectName === void 0 ? {} : { objectName }
|
|
840
|
+
};
|
|
841
|
+
const spPr = cursor.child(P_NS, "spPr");
|
|
842
|
+
const txBody = cursor.child(P_NS, "txBody");
|
|
843
|
+
if (spPr === void 0 || txBody === void 0) {
|
|
844
|
+
diagnostics.push({
|
|
845
|
+
code: "corrupt-part",
|
|
846
|
+
category: "corrupt-input",
|
|
847
|
+
disposition: "omitted",
|
|
848
|
+
location: {
|
|
849
|
+
...location,
|
|
850
|
+
xpath: cursor.xpath
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
return { diagnostics };
|
|
854
|
+
}
|
|
855
|
+
const visuals = readSpPrVisuals(spPr, pkg, location, diagnostics);
|
|
856
|
+
if (visuals === void 0) return { diagnostics };
|
|
857
|
+
const { background: rawBg, border: rawBorder, ...restFreeVisuals } = textBoxVisualStyle(visuals.style, visuals.borderArrows, visuals.geometry, {
|
|
858
|
+
width: visuals.transform.width,
|
|
859
|
+
height: visuals.transform.height
|
|
860
|
+
}, visuals.transform.rotate, location, diagnostics);
|
|
861
|
+
const visualStyle = {
|
|
862
|
+
...restFreeVisuals,
|
|
863
|
+
...rawBg === void 0 || rawBg === "none" ? {} : { background: rawBg },
|
|
864
|
+
...rawBorder === void 0 || rawBorder === "none" ? {} : { border: rawBorder }
|
|
865
|
+
};
|
|
866
|
+
const { boxStyle, singleText, paragraphsToPopulate } = flattenImportedTextBody(readRichTextBody(txBody, part, slideIndex, diagnostics), visualStyle);
|
|
867
|
+
const props = {
|
|
868
|
+
...objectName === void 0 ? {} : { name: objectName },
|
|
869
|
+
...link === void 0 ? {} : { link },
|
|
870
|
+
style: {
|
|
871
|
+
position: "absolute",
|
|
872
|
+
left: visuals.transform.x,
|
|
873
|
+
top: visuals.transform.y,
|
|
874
|
+
width: visuals.transform.width,
|
|
875
|
+
height: visuals.transform.height,
|
|
876
|
+
...boxStyle
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
const node = createTextNode(props);
|
|
880
|
+
if (singleText !== void 0) node.content(singleText);
|
|
881
|
+
else if (paragraphsToPopulate !== void 0) populateRichTextNode(node, paragraphsToPopulate);
|
|
882
|
+
attachDeferredSlideLink(node, deferredSlideLink, context);
|
|
883
|
+
return {
|
|
884
|
+
node,
|
|
885
|
+
diagnostics
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Reads a Transitional `<p:sp>` bound placeholder (`<p:nvPr><p:ph .../></p:nvPr>`)
|
|
890
|
+
* into a layout-bound `TextNode` preserving differential transforms and styles.
|
|
891
|
+
*/
|
|
892
|
+
function readTextPlaceholderSp(context) {
|
|
893
|
+
const { cursor, part, slideIndex, package: pkg } = context;
|
|
894
|
+
const diagnostics = [];
|
|
895
|
+
const nvSpPr = cursor.child(P_NS, "nvSpPr");
|
|
896
|
+
if (nvSpPr === void 0) {
|
|
897
|
+
diagnostics.push({
|
|
898
|
+
code: "corrupt-part",
|
|
899
|
+
category: "corrupt-input",
|
|
900
|
+
disposition: "omitted",
|
|
901
|
+
location: {
|
|
902
|
+
part,
|
|
903
|
+
xpath: cursor.xpath,
|
|
904
|
+
slideIndex
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
return { diagnostics };
|
|
908
|
+
}
|
|
909
|
+
const cNvPr = nvSpPr.child(P_NS, "cNvPr");
|
|
910
|
+
const { objectId, objectName, link, deferredSlideLink } = readNonVisualCommonProperties(cNvPr, context, diagnostics);
|
|
911
|
+
cNvPr?.ignoreEmptyChild(A_NS, "extLst");
|
|
912
|
+
const cNvSpPr = nvSpPr.child(P_NS, "cNvSpPr");
|
|
913
|
+
if (cNvSpPr !== void 0) {
|
|
914
|
+
cNvSpPr.consumeAttr("txBox");
|
|
915
|
+
cNvSpPr.child(A_NS, "spLocks")?.attrsObject([
|
|
916
|
+
"noGrp",
|
|
917
|
+
"noRot",
|
|
918
|
+
"noChangeAspect",
|
|
919
|
+
"noMove",
|
|
920
|
+
"noResize",
|
|
921
|
+
"noSelect"
|
|
922
|
+
]);
|
|
923
|
+
}
|
|
924
|
+
const location = {
|
|
925
|
+
part,
|
|
926
|
+
slideIndex,
|
|
927
|
+
...objectId === void 0 ? {} : { objectId },
|
|
928
|
+
...objectName === void 0 ? {} : { objectName }
|
|
929
|
+
};
|
|
930
|
+
const nvPr = nvSpPr.child(P_NS, "nvPr");
|
|
931
|
+
const phResult = readNvPrPlaceholder(nvPr, {
|
|
932
|
+
...location,
|
|
933
|
+
xpath: cursor.xpath
|
|
934
|
+
}, diagnostics);
|
|
935
|
+
if (phResult.kind === "none") {
|
|
936
|
+
diagnostics.push({
|
|
937
|
+
code: "corrupt-part",
|
|
938
|
+
category: "corrupt-input",
|
|
939
|
+
disposition: "omitted",
|
|
940
|
+
location: {
|
|
941
|
+
...location,
|
|
942
|
+
xpath: cursor.xpath
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
return { diagnostics };
|
|
946
|
+
}
|
|
947
|
+
if (phResult.kind === "error") return { diagnostics };
|
|
948
|
+
const nativeRef = phResult.nativeRef;
|
|
949
|
+
const spPr = cursor.child(P_NS, "spPr");
|
|
950
|
+
if (spPr === void 0) {
|
|
951
|
+
diagnostics.push({
|
|
952
|
+
code: "corrupt-part",
|
|
953
|
+
category: "corrupt-input",
|
|
954
|
+
disposition: "omitted",
|
|
955
|
+
location: {
|
|
956
|
+
...location,
|
|
957
|
+
xpath: cursor.xpath
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
return { diagnostics };
|
|
961
|
+
}
|
|
962
|
+
let localBox;
|
|
963
|
+
let rotate;
|
|
964
|
+
let flipH;
|
|
965
|
+
let flipV;
|
|
966
|
+
let fallbackUnits = {
|
|
967
|
+
w: 0,
|
|
968
|
+
h: 0
|
|
969
|
+
};
|
|
970
|
+
const xfrm = spPr.child(A_NS, "xfrm");
|
|
971
|
+
if (xfrm !== void 0) {
|
|
972
|
+
const hasExplicitFlipH = xfrm.element.hasAttribute("flipH");
|
|
973
|
+
const hasExplicitFlipV = xfrm.element.hasAttribute("flipV");
|
|
974
|
+
const rawXfrm = xfrm.attrsObject([
|
|
975
|
+
"rot",
|
|
976
|
+
"flipH",
|
|
977
|
+
"flipV"
|
|
978
|
+
]);
|
|
979
|
+
const parsedXfrm = transformAttributesFragmentSchema.safeParse(rawXfrm);
|
|
980
|
+
if (parsedXfrm.success) {
|
|
981
|
+
if (parsedXfrm.data.rot !== void 0 && parsedXfrm.data.rot !== 0) rotate = parsedXfrm.data.rot / 6e4;
|
|
982
|
+
if (hasExplicitFlipH && parsedXfrm.data.flipH !== void 0) flipH = parsedXfrm.data.flipH;
|
|
983
|
+
if (hasExplicitFlipV && parsedXfrm.data.flipV !== void 0) flipV = parsedXfrm.data.flipV;
|
|
984
|
+
}
|
|
985
|
+
const off = xfrm.child(A_NS, "off");
|
|
986
|
+
const ext = xfrm.child(A_NS, "ext");
|
|
987
|
+
if (off !== void 0 && ext !== void 0) {
|
|
988
|
+
const parsedOff = offsetEmuFragmentSchema.safeParse(off.attrsObject(["x", "y"]));
|
|
989
|
+
const parsedExt = extentEmuFragmentSchema.safeParse(ext.attrsObject(["cx", "cy"]));
|
|
990
|
+
if (!parsedOff.success || !parsedExt.success) diagnostics.push({
|
|
991
|
+
code: "invalid-xml-value",
|
|
992
|
+
category: "corrupt-input",
|
|
993
|
+
disposition: "recovered",
|
|
994
|
+
location: {
|
|
995
|
+
...location,
|
|
996
|
+
xpath: xfrm.xpath
|
|
997
|
+
},
|
|
998
|
+
attributeOrElement: "a:xfrm"
|
|
999
|
+
});
|
|
1000
|
+
else {
|
|
1001
|
+
fallbackUnits = {
|
|
1002
|
+
w: parsedExt.data.cx,
|
|
1003
|
+
h: parsedExt.data.cy
|
|
1004
|
+
};
|
|
1005
|
+
localBox = {
|
|
1006
|
+
x: emuToPx(parsedOff.data.x),
|
|
1007
|
+
y: emuToPx(parsedOff.data.y),
|
|
1008
|
+
width: emuToPx(parsedExt.data.cx),
|
|
1009
|
+
height: emuToPx(parsedExt.data.cy)
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
const claim = resolvePlaceholderImportClaim({
|
|
1015
|
+
context,
|
|
1016
|
+
nativeRef,
|
|
1017
|
+
compatibleRoles: textCompatiblePlaceholderRoles,
|
|
1018
|
+
allowMasterDirectFallback: true
|
|
1019
|
+
});
|
|
1020
|
+
const layoutPlaceholder = claim.layoutPlaceholder;
|
|
1021
|
+
const masterPlaceholder = claim.masterPlaceholder;
|
|
1022
|
+
const layoutPhWidth = typeof layoutPlaceholder?.style?.width === "number" ? layoutPlaceholder.style.width : void 0;
|
|
1023
|
+
const layoutPhHeight = typeof layoutPlaceholder?.style?.height === "number" ? layoutPlaceholder.style.height : void 0;
|
|
1024
|
+
const masterPhWidth = typeof masterPlaceholder?.style?.width === "number" ? masterPlaceholder.style.width : void 0;
|
|
1025
|
+
const masterPhHeight = typeof masterPlaceholder?.style?.height === "number" ? masterPlaceholder.style.height : void 0;
|
|
1026
|
+
const inheritedWidth = layoutPhWidth ?? masterPhWidth;
|
|
1027
|
+
const inheritedHeight = layoutPhHeight ?? masterPhHeight;
|
|
1028
|
+
const inheritedPlaceholderBox = inheritedWidth !== void 0 && inheritedHeight !== void 0 ? {
|
|
1029
|
+
width: inheritedWidth,
|
|
1030
|
+
height: inheritedHeight
|
|
1031
|
+
} : void 0;
|
|
1032
|
+
const effectiveFallbackUnits = localBox === void 0 && inheritedPlaceholderBox !== void 0 ? {
|
|
1033
|
+
w: Math.round(inheritedPlaceholderBox.width * EMU_PER_PX),
|
|
1034
|
+
h: Math.round(inheritedPlaceholderBox.height * EMU_PER_PX)
|
|
1035
|
+
} : fallbackUnits;
|
|
1036
|
+
const appearance = readSpPrAppearance(spPr, pkg, effectiveFallbackUnits, location, diagnostics, { preservePlaceholderClears: true });
|
|
1037
|
+
const visualStyle = textBoxVisualStyle(appearance.style, appearance.borderArrows, appearance.geometry, localBox ?? inheritedPlaceholderBox, rotate, location, diagnostics);
|
|
1038
|
+
const txBody = cursor.child(P_NS, "txBody");
|
|
1039
|
+
const imported = txBody === void 0 ? void 0 : readRichTextBody(txBody, part, slideIndex, diagnostics, void 0, { allowShadowNone: true });
|
|
1040
|
+
if (!claim.bound) {
|
|
1041
|
+
const resolvedBox = resolveUnboundPlaceholderBox({
|
|
1042
|
+
inheritanceContext: claim.inheritanceContext,
|
|
1043
|
+
...localBox === void 0 ? {} : { localBox },
|
|
1044
|
+
requireHeight: false
|
|
1045
|
+
});
|
|
1046
|
+
if (resolvedBox === void 0) {
|
|
1047
|
+
diagnostics.push({
|
|
1048
|
+
code: "unsupported-mechanism",
|
|
1049
|
+
category: "unsupported",
|
|
1050
|
+
disposition: "omitted",
|
|
1051
|
+
location: {
|
|
1052
|
+
...location,
|
|
1053
|
+
xpath: cursor.xpath
|
|
1054
|
+
},
|
|
1055
|
+
namespaceUri: P_NS,
|
|
1056
|
+
localName: "ph",
|
|
1057
|
+
mechanismHint: "orphan-placeholder-without-box"
|
|
1058
|
+
});
|
|
1059
|
+
return { diagnostics };
|
|
1060
|
+
}
|
|
1061
|
+
const freeVisualStyle = materializeUnboundVisualStyle({
|
|
1062
|
+
inheritanceContext: claim.inheritanceContext,
|
|
1063
|
+
localVisualStyle: {
|
|
1064
|
+
...visualStyle,
|
|
1065
|
+
...flipH === void 0 ? {} : { flipH },
|
|
1066
|
+
...flipV === void 0 ? {} : { flipV }
|
|
1067
|
+
},
|
|
1068
|
+
...appearance.geometry === void 0 ? {} : { localGeometry: appearance.geometry },
|
|
1069
|
+
boxSize: {
|
|
1070
|
+
width: resolvedBox.width,
|
|
1071
|
+
height: resolvedBox.height ?? 100
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
const baseTextStyle = stripPlaceholderClearSentinels({ ...resolvePlaceholderBaseTextStyle(claim.inheritanceContext, imported?.boxStyle) });
|
|
1075
|
+
const pickParagraphStyle = (source) => {
|
|
1076
|
+
const picked = {};
|
|
1077
|
+
for (const [k, v] of Object.entries(source)) if (v !== void 0 && paragraphStyleKeys.has(k)) picked[k] = v;
|
|
1078
|
+
const cleaned = stripPlaceholderClearSentinels(picked);
|
|
1079
|
+
const parsed = paragraphStyleSchema.safeParse(cleaned);
|
|
1080
|
+
return parsed.success ? parsed.data : {};
|
|
1081
|
+
};
|
|
1082
|
+
const importedParagraphs = imported?.importedParagraphs ?? [];
|
|
1083
|
+
const p0 = importedParagraphs.length === 1 ? importedParagraphs[0] : void 0;
|
|
1084
|
+
const p0LevelRaw = p0 === void 0 ? void 0 : resolvePlaceholderLevelTextStyle(claim.inheritanceContext, p0.level0 ?? 0, p0.style);
|
|
1085
|
+
const p0Level = p0LevelRaw !== void 0 && p0?.buNone ? {
|
|
1086
|
+
...p0LevelRaw,
|
|
1087
|
+
list: void 0
|
|
1088
|
+
} : p0LevelRaw;
|
|
1089
|
+
let freeSingleText;
|
|
1090
|
+
let freeParagraphs;
|
|
1091
|
+
let extraFlatStyle = {};
|
|
1092
|
+
const singlePlainRun = p0 !== void 0 && p0.runs.length === 1 && p0.runs[0].kind === "text" && p0.runs[0].style.baselineShift === void 0 ? p0.runs[0] : void 0;
|
|
1093
|
+
if (p0 !== void 0 && singlePlainRun !== void 0 && p0Level?.list === void 0) {
|
|
1094
|
+
const { baselineShift: _b, ...runRest } = singlePlainRun.style;
|
|
1095
|
+
extraFlatStyle = {
|
|
1096
|
+
...pickParagraphStyle(p0Level ?? {}),
|
|
1097
|
+
...runRest
|
|
1098
|
+
};
|
|
1099
|
+
freeSingleText = singlePlainRun.text;
|
|
1100
|
+
} else if (p0 !== void 0 && p0.runs.length === 0 && p0Level?.list === void 0) extraFlatStyle = pickParagraphStyle(p0Level ?? {});
|
|
1101
|
+
else if (importedParagraphs.length > 0) freeParagraphs = importedParagraphs.map((para) => {
|
|
1102
|
+
const rawLvl = resolvePlaceholderLevelTextStyle(claim.inheritanceContext, para.level0 ?? 0, para.style);
|
|
1103
|
+
const lvl = para.buNone ? {
|
|
1104
|
+
...rawLvl,
|
|
1105
|
+
list: void 0
|
|
1106
|
+
} : rawLvl;
|
|
1107
|
+
return {
|
|
1108
|
+
runs: para.runs,
|
|
1109
|
+
style: pickParagraphStyle(lvl)
|
|
1110
|
+
};
|
|
1111
|
+
});
|
|
1112
|
+
const combinedFreeStyle = stripPlaceholderClearSentinels({
|
|
1113
|
+
...baseTextStyle,
|
|
1114
|
+
...extraFlatStyle,
|
|
1115
|
+
...freeVisualStyle,
|
|
1116
|
+
position: "absolute",
|
|
1117
|
+
left: resolvedBox.x,
|
|
1118
|
+
top: resolvedBox.y,
|
|
1119
|
+
width: resolvedBox.width,
|
|
1120
|
+
...resolvedBox.height === void 0 ? {} : { height: resolvedBox.height }
|
|
1121
|
+
});
|
|
1122
|
+
const parsedFreeStyle = textBoxStyleSchema.safeParse(combinedFreeStyle);
|
|
1123
|
+
let validatedFreeStyle;
|
|
1124
|
+
if (parsedFreeStyle.success) validatedFreeStyle = parsedFreeStyle.data;
|
|
1125
|
+
else {
|
|
1126
|
+
diagnostics.push({
|
|
1127
|
+
code: "invalid-xml-value",
|
|
1128
|
+
category: "corrupt-input",
|
|
1129
|
+
disposition: "recovered",
|
|
1130
|
+
location: {
|
|
1131
|
+
...location,
|
|
1132
|
+
xpath: cursor.xpath
|
|
1133
|
+
},
|
|
1134
|
+
attributeOrElement: "p:sp",
|
|
1135
|
+
rawValue: parsedFreeStyle.error.issues[0]?.message ?? "invalid style"
|
|
1136
|
+
});
|
|
1137
|
+
validatedFreeStyle = {
|
|
1138
|
+
position: "absolute",
|
|
1139
|
+
left: resolvedBox.x,
|
|
1140
|
+
top: resolvedBox.y,
|
|
1141
|
+
width: resolvedBox.width,
|
|
1142
|
+
...resolvedBox.height === void 0 ? {} : { height: resolvedBox.height }
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
const freeNode = createTextNode({
|
|
1146
|
+
...objectName === void 0 ? {} : { name: objectName },
|
|
1147
|
+
...link === void 0 ? {} : { link },
|
|
1148
|
+
style: validatedFreeStyle
|
|
1149
|
+
});
|
|
1150
|
+
if (freeSingleText !== void 0) freeNode.content(freeSingleText);
|
|
1151
|
+
else if (freeParagraphs !== void 0) populateRichTextNode(freeNode, freeParagraphs);
|
|
1152
|
+
attachDeferredSlideLink(freeNode, deferredSlideLink, context);
|
|
1153
|
+
emitPlaceholderUnbindDiagnostic({
|
|
1154
|
+
diagnostics,
|
|
1155
|
+
location: {
|
|
1156
|
+
...location,
|
|
1157
|
+
xpath: cursor.xpath
|
|
1158
|
+
},
|
|
1159
|
+
retainedAs: "text"
|
|
1160
|
+
});
|
|
1161
|
+
return {
|
|
1162
|
+
node: freeNode,
|
|
1163
|
+
diagnostics
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
const matchedKey = claim.key;
|
|
1167
|
+
const { boxStyle, singleText, paragraphsToPopulate } = flattenImportedTextBody(imported, visualStyle);
|
|
1168
|
+
const combinedStyle = {
|
|
1169
|
+
...localBox === void 0 ? {} : {
|
|
1170
|
+
position: "absolute",
|
|
1171
|
+
left: localBox.x,
|
|
1172
|
+
top: localBox.y,
|
|
1173
|
+
width: localBox.width,
|
|
1174
|
+
height: localBox.height
|
|
1175
|
+
},
|
|
1176
|
+
...flipH === void 0 ? {} : { flipH },
|
|
1177
|
+
...flipV === void 0 ? {} : { flipV },
|
|
1178
|
+
...boxStyle
|
|
1179
|
+
};
|
|
1180
|
+
let validatedStyle;
|
|
1181
|
+
if (Object.keys(combinedStyle).length > 0) {
|
|
1182
|
+
const parsedStyle = placeholderStyleSchema.safeParse(combinedStyle);
|
|
1183
|
+
if (parsedStyle.success) validatedStyle = parsedStyle.data;
|
|
1184
|
+
else diagnostics.push({
|
|
1185
|
+
code: "invalid-xml-value",
|
|
1186
|
+
category: "corrupt-input",
|
|
1187
|
+
disposition: "recovered",
|
|
1188
|
+
location: {
|
|
1189
|
+
...location,
|
|
1190
|
+
xpath: cursor.xpath
|
|
1191
|
+
},
|
|
1192
|
+
attributeOrElement: "p:sp",
|
|
1193
|
+
rawValue: parsedStyle.error.issues[0]?.message ?? "invalid style"
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
const props = {
|
|
1197
|
+
...objectName === void 0 ? {} : { name: objectName },
|
|
1198
|
+
...link === void 0 ? {} : { link },
|
|
1199
|
+
...matchedKey === void 0 ? {} : { placeholder: matchedKey },
|
|
1200
|
+
nativePlaceholder: nativeRef,
|
|
1201
|
+
...validatedStyle === void 0 ? {} : { style: validatedStyle }
|
|
1202
|
+
};
|
|
1203
|
+
const node = createTextNode(props);
|
|
1204
|
+
if (singleText !== void 0) node.content(singleText);
|
|
1205
|
+
else if (paragraphsToPopulate !== void 0) populateRichTextNode(node, paragraphsToPopulate);
|
|
1206
|
+
attachDeferredSlideLink(node, deferredSlideLink, context);
|
|
1207
|
+
return {
|
|
1208
|
+
node,
|
|
1209
|
+
diagnostics
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
const textBoxImportHandler = {
|
|
1213
|
+
target: "shape-tree",
|
|
1214
|
+
localName: "sp",
|
|
1215
|
+
matches: (cursor) => isTextBoxSpElement(cursor) && !isPlaceholderSpElement(cursor),
|
|
1216
|
+
read: readTextBoxSp
|
|
1217
|
+
};
|
|
1218
|
+
const textPlaceholderImportHandler = {
|
|
1219
|
+
target: "shape-tree",
|
|
1220
|
+
localName: "sp",
|
|
1221
|
+
matches: isTextPlaceholderSpElement,
|
|
1222
|
+
read: readTextPlaceholderSp
|
|
1223
|
+
};
|
|
1224
|
+
export { isPlaceholderSpElement, isTextPlaceholderSpElement, populateRichTextNode, readRichTextBody, readTextBoxSp, readTextPlaceholderSp, textBoxImportHandler, textFieldSlideNumImportHandler, textPlaceholderImportHandler };
|