@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,12 @@
|
|
|
1
|
+
// ../emit/dist/shape-tree.js
|
|
2
|
+
const emptyShapeTree = "<p:nvGrpSpPr><p:cNvPr id=\"1\" name=\"\"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"0\" cy=\"0\"/><a:chOff x=\"0\" y=\"0\"/><a:chExt cx=\"0\" cy=\"0\"/></a:xfrm></p:grpSpPr>";
|
|
3
|
+
/**
|
|
4
|
+
* Internal PresentationML shape tree wrapper shared by slides, masters, and layouts.
|
|
5
|
+
*
|
|
6
|
+
* Capability writers contribute complete native object XML; this module owns only the surrounding
|
|
7
|
+
* shape-tree envelope and its required non-visual group properties.
|
|
8
|
+
*/
|
|
9
|
+
function shapeTreeXml(shapeXml = "") {
|
|
10
|
+
return `<p:spTree>${emptyShapeTree}${shapeXml}</p:spTree>`;
|
|
11
|
+
}
|
|
12
|
+
export { shapeTreeXml };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MC_NS } from "./namespaces.js";
|
|
2
|
+
// ../import/dist/alternate-content.js
|
|
3
|
+
/**
|
|
4
|
+
* Evaluates `<mc:AlternateContent>` according to ECMA-376 Part 3 Markup Compatibility:
|
|
5
|
+
* selects the first `<mc:Choice>` whose `Requires` prefixes all resolve to supported namespaces,
|
|
6
|
+
* or falls back to `<mc:Fallback>` while suppressing spurious unconsumed-xml on rejected branches.
|
|
7
|
+
*/
|
|
8
|
+
function readAlternateContent(mcCursor, isNamespaceSupported) {
|
|
9
|
+
const choices = mcCursor.children(MC_NS, "Choice");
|
|
10
|
+
const fallback = mcCursor.child(MC_NS, "Fallback");
|
|
11
|
+
let preferredMechanism = "unknown";
|
|
12
|
+
for (const choice of choices) {
|
|
13
|
+
const rawRequires = choice.attr("Requires") ?? "";
|
|
14
|
+
const prefixes = rawRequires.trim().split(/\s+/u).filter(Boolean);
|
|
15
|
+
const resolvedNamespaces = [];
|
|
16
|
+
let allSupported = prefixes.length > 0;
|
|
17
|
+
for (const prefix of prefixes) {
|
|
18
|
+
const nsUri = choice.element.lookupNamespaceURI(prefix);
|
|
19
|
+
if (nsUri === null || nsUri === "") {
|
|
20
|
+
allSupported = false;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
resolvedNamespaces.push(nsUri);
|
|
24
|
+
if (!isNamespaceSupported(nsUri)) allSupported = false;
|
|
25
|
+
}
|
|
26
|
+
if (preferredMechanism === "unknown") preferredMechanism = resolvedNamespaces[0] ?? (rawRequires.trim() || "mc:Choice");
|
|
27
|
+
if (allSupported) {
|
|
28
|
+
for (const other of choices) if (other !== choice) {
|
|
29
|
+
other.consumeAttr("Requires");
|
|
30
|
+
other.suppressUnconsumed();
|
|
31
|
+
}
|
|
32
|
+
fallback?.suppressUnconsumed();
|
|
33
|
+
return {
|
|
34
|
+
branch: "choice",
|
|
35
|
+
cursor: choice,
|
|
36
|
+
children: choice.remainingElementChildren(),
|
|
37
|
+
requires: prefixes,
|
|
38
|
+
resolvedNamespaces
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
choice.suppressUnconsumed();
|
|
42
|
+
}
|
|
43
|
+
if (fallback !== void 0) return {
|
|
44
|
+
branch: "fallback",
|
|
45
|
+
cursor: fallback,
|
|
46
|
+
children: fallback.remainingElementChildren(),
|
|
47
|
+
preferredMechanism
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
branch: "unsupported",
|
|
51
|
+
preferredMechanism
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export { readAlternateContent };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ../import/dist/diagnostics.js
|
|
3
|
+
const rawImportLocationSchema = z.object({
|
|
4
|
+
part: z.string().min(1),
|
|
5
|
+
xpath: z.string().min(1).optional(),
|
|
6
|
+
slideIndex: z.number().int().nonnegative().optional(),
|
|
7
|
+
objectId: z.number().int().optional(),
|
|
8
|
+
objectName: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
/** Source package location attached to import diagnostics and fatal errors. */
|
|
11
|
+
const importLocationSchema = rawImportLocationSchema;
|
|
12
|
+
const rawEditabilityLossSchema = z.object({
|
|
13
|
+
lost: z.enum([
|
|
14
|
+
"native-mechanism",
|
|
15
|
+
"master-layout-inheritance",
|
|
16
|
+
"preferred-compatibility-branch",
|
|
17
|
+
"custom-print-layout"
|
|
18
|
+
]),
|
|
19
|
+
retainedAs: z.string().min(1)
|
|
20
|
+
});
|
|
21
|
+
/** Native editing capability lost when a fallback representation is selected. */
|
|
22
|
+
const editabilityLossSchema = rawEditabilityLossSchema;
|
|
23
|
+
const rawCascadedOmissionSchema = z.object({
|
|
24
|
+
location: rawImportLocationSchema,
|
|
25
|
+
role: z.string().min(1)
|
|
26
|
+
});
|
|
27
|
+
/** Dependent item omitted because an ancestor or target part could not be imported. */
|
|
28
|
+
const cascadedOmissionSchema = rawCascadedOmissionSchema;
|
|
29
|
+
/** Fatal package/entry failure reason carried by `ImportError`. */
|
|
30
|
+
const fatalImportIssueSchema = z.discriminatedUnion("code", [
|
|
31
|
+
z.object({
|
|
32
|
+
code: z.literal("corrupt-archive"),
|
|
33
|
+
category: z.literal("corrupt-input"),
|
|
34
|
+
disposition: z.literal("aborted")
|
|
35
|
+
}),
|
|
36
|
+
z.object({
|
|
37
|
+
code: z.literal("missing-entry"),
|
|
38
|
+
category: z.literal("corrupt-input"),
|
|
39
|
+
disposition: z.literal("aborted"),
|
|
40
|
+
location: rawImportLocationSchema,
|
|
41
|
+
expectedRelationshipType: z.string().optional()
|
|
42
|
+
}),
|
|
43
|
+
z.object({
|
|
44
|
+
code: z.literal("malformed-xml"),
|
|
45
|
+
category: z.literal("corrupt-input"),
|
|
46
|
+
disposition: z.literal("aborted"),
|
|
47
|
+
location: rawImportLocationSchema,
|
|
48
|
+
detail: z.string().optional()
|
|
49
|
+
}),
|
|
50
|
+
z.object({
|
|
51
|
+
code: z.literal("broken-entry-relationship"),
|
|
52
|
+
category: z.literal("corrupt-input"),
|
|
53
|
+
disposition: z.literal("aborted"),
|
|
54
|
+
location: rawImportLocationSchema,
|
|
55
|
+
relationshipId: z.string().optional(),
|
|
56
|
+
target: z.string().optional()
|
|
57
|
+
}),
|
|
58
|
+
z.object({
|
|
59
|
+
code: z.literal("invalid-presentation-root"),
|
|
60
|
+
category: z.literal("corrupt-input"),
|
|
61
|
+
disposition: z.literal("aborted"),
|
|
62
|
+
location: rawImportLocationSchema,
|
|
63
|
+
namespaceUri: z.string().optional(),
|
|
64
|
+
localName: z.string().optional()
|
|
65
|
+
}),
|
|
66
|
+
z.object({
|
|
67
|
+
code: z.literal("unsupported-format-baseline"),
|
|
68
|
+
category: z.literal("unsupported"),
|
|
69
|
+
disposition: z.literal("aborted"),
|
|
70
|
+
baseline: z.enum(["ISO/IEC 29500 Strict", "unknown"]),
|
|
71
|
+
detectedNamespace: z.string().min(1),
|
|
72
|
+
location: rawImportLocationSchema
|
|
73
|
+
})
|
|
74
|
+
]);
|
|
75
|
+
const rawImportDiagnosticSchema = z.discriminatedUnion("code", [
|
|
76
|
+
z.object({
|
|
77
|
+
code: z.literal("corrupt-part"),
|
|
78
|
+
category: z.literal("corrupt-input"),
|
|
79
|
+
disposition: z.literal("omitted"),
|
|
80
|
+
location: rawImportLocationSchema,
|
|
81
|
+
cascaded: z.array(rawCascadedOmissionSchema).readonly().optional()
|
|
82
|
+
}),
|
|
83
|
+
z.object({
|
|
84
|
+
code: z.literal("missing-target-part"),
|
|
85
|
+
category: z.literal("corrupt-input"),
|
|
86
|
+
disposition: z.literal("omitted"),
|
|
87
|
+
location: rawImportLocationSchema,
|
|
88
|
+
relationshipId: z.string(),
|
|
89
|
+
targetPart: z.string(),
|
|
90
|
+
cascaded: z.array(rawCascadedOmissionSchema).readonly().optional()
|
|
91
|
+
}),
|
|
92
|
+
z.object({
|
|
93
|
+
code: z.literal("broken-relationship"),
|
|
94
|
+
category: z.literal("corrupt-input"),
|
|
95
|
+
disposition: z.literal("omitted"),
|
|
96
|
+
location: rawImportLocationSchema,
|
|
97
|
+
relationshipId: z.string(),
|
|
98
|
+
cascaded: z.array(rawCascadedOmissionSchema).readonly().optional()
|
|
99
|
+
}),
|
|
100
|
+
z.object({
|
|
101
|
+
code: z.literal("invalid-xml-value"),
|
|
102
|
+
category: z.literal("corrupt-input"),
|
|
103
|
+
disposition: z.enum(["omitted", "recovered"]),
|
|
104
|
+
location: rawImportLocationSchema,
|
|
105
|
+
attributeOrElement: z.string(),
|
|
106
|
+
rawValue: z.string().optional()
|
|
107
|
+
}),
|
|
108
|
+
z.object({
|
|
109
|
+
code: z.literal("unsupported-mechanism"),
|
|
110
|
+
category: z.literal("unsupported"),
|
|
111
|
+
disposition: z.literal("omitted"),
|
|
112
|
+
location: rawImportLocationSchema,
|
|
113
|
+
namespaceUri: z.string(),
|
|
114
|
+
localName: z.string(),
|
|
115
|
+
mechanismHint: z.string().optional(),
|
|
116
|
+
loss: rawEditabilityLossSchema.optional(),
|
|
117
|
+
cascaded: z.array(rawCascadedOmissionSchema).readonly().optional()
|
|
118
|
+
}),
|
|
119
|
+
z.object({
|
|
120
|
+
code: z.literal("compatibility-fallback"),
|
|
121
|
+
category: z.literal("unsupported"),
|
|
122
|
+
disposition: z.literal("fallback"),
|
|
123
|
+
location: rawImportLocationSchema,
|
|
124
|
+
preferredMechanism: z.string(),
|
|
125
|
+
selectedFallback: z.string(),
|
|
126
|
+
loss: rawEditabilityLossSchema
|
|
127
|
+
}),
|
|
128
|
+
z.object({
|
|
129
|
+
code: z.literal("unconsumed-xml"),
|
|
130
|
+
category: z.literal("unsupported"),
|
|
131
|
+
disposition: z.literal("omitted"),
|
|
132
|
+
kind: z.enum(["attribute", "element"]),
|
|
133
|
+
location: rawImportLocationSchema,
|
|
134
|
+
namespaceUri: z.string(),
|
|
135
|
+
localName: z.string()
|
|
136
|
+
})
|
|
137
|
+
]);
|
|
138
|
+
/** Recoverable or isolatable diagnostic event emitted in `ImportReport.diagnostics`. */
|
|
139
|
+
const importDiagnosticSchema = rawImportDiagnosticSchema;
|
|
140
|
+
/** Structured summary and per-item diagnostics produced by `createImporter`. */
|
|
141
|
+
const importReportSchema = z.object({
|
|
142
|
+
evidence: z.literal("import"),
|
|
143
|
+
sourceFormat: z.literal("ECMA-376 5th edition Transitional"),
|
|
144
|
+
slideCount: z.number().int().nonnegative(),
|
|
145
|
+
diagnostics: z.array(rawImportDiagnosticSchema).readonly()
|
|
146
|
+
});
|
|
147
|
+
const importOptionsSchema = z.object({ signal: z.custom((value) => typeof value === "object" && value !== null && "aborted" in value && typeof value.aborted === "boolean").optional() }).strict();
|
|
148
|
+
/** Error thrown when PPTX entry points cannot be opened or use an unsupported baseline. */
|
|
149
|
+
var ImportError = class extends Error {
|
|
150
|
+
issue;
|
|
151
|
+
constructor(issue, message) {
|
|
152
|
+
super(message ?? issue.code);
|
|
153
|
+
this.name = "ImportError";
|
|
154
|
+
this.issue = Object.freeze(fatalImportIssueSchema.parse(issue));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
export { ImportError, cascadedOmissionSchema, editabilityLossSchema, fatalImportIssueSchema, importDiagnosticSchema, importLocationSchema, importOptionsSchema, importReportSchema };
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { A_NS, P_NS, R_NS } from "./namespaces.js";
|
|
2
|
+
import { resolvePartPath } from "./opc.js";
|
|
3
|
+
import { ooxmlBoolSchema, ooxmlIntSchema } from "./xml-fragments.js";
|
|
4
|
+
import { XmlElementCursor, parseXmlPart } from "./xml-reader.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// ../import/dist/fonts.js
|
|
7
|
+
const fontSlotNames = [
|
|
8
|
+
"regular",
|
|
9
|
+
"bold",
|
|
10
|
+
"italic",
|
|
11
|
+
"boldItalic"
|
|
12
|
+
];
|
|
13
|
+
const presentationFontAttrSchema = z.object({
|
|
14
|
+
embedTrueTypeFonts: ooxmlBoolSchema.optional(),
|
|
15
|
+
saveSubsetFonts: ooxmlBoolSchema.optional()
|
|
16
|
+
});
|
|
17
|
+
const reservedThemeFontPattern = /^(?:major|minor|\+(?:mj|mn)-)/iu;
|
|
18
|
+
function isAllowedThemeFontTypeface(value) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
return trimmed !== "" && !reservedThemeFontPattern.test(trimmed);
|
|
21
|
+
}
|
|
22
|
+
const embeddedFontTypefaceXmlSchema = z.object({
|
|
23
|
+
typeface: z.string().min(1).refine(isAllowedThemeFontTypeface),
|
|
24
|
+
pitchFamily: ooxmlIntSchema.optional(),
|
|
25
|
+
charset: ooxmlIntSchema.optional(),
|
|
26
|
+
panose: z.string().optional()
|
|
27
|
+
});
|
|
28
|
+
const embeddedFontSlotRefXmlSchema = z.object({ id: z.string().min(1) });
|
|
29
|
+
const themeTypefaceXmlSchema = z.object({ typeface: z.string().min(1).refine(isAllowedThemeFontTypeface) });
|
|
30
|
+
function isTrueTypeSfntHeader(bytes) {
|
|
31
|
+
if (bytes.byteLength < 12) return false;
|
|
32
|
+
const sig = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3]);
|
|
33
|
+
return sig === "\0\0\0" || sig === "true";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unpacks an uncompressed EOT (`.fntdata`) container or raw SFNT buffer into a detached
|
|
37
|
+
* TrueType `Uint8Array`, isolating compressed/obfuscated or corrupt payloads cleanly.
|
|
38
|
+
*/
|
|
39
|
+
function unpackEotFontData(bytes) {
|
|
40
|
+
if (isTrueTypeSfntHeader(bytes)) return {
|
|
41
|
+
status: "ok",
|
|
42
|
+
ttfBytes: new Uint8Array(bytes)
|
|
43
|
+
};
|
|
44
|
+
if (bytes.byteLength < 82) return {
|
|
45
|
+
status: "corrupt",
|
|
46
|
+
reason: "EOT header shorter than 82 bytes"
|
|
47
|
+
};
|
|
48
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
49
|
+
const eotSize = view.getUint32(0, true);
|
|
50
|
+
const fontDataSize = view.getUint32(4, true);
|
|
51
|
+
const version = view.getUint32(8, true);
|
|
52
|
+
const flags = view.getUint32(12, true);
|
|
53
|
+
const italic = bytes[27] !== 0;
|
|
54
|
+
const weight = view.getUint32(28, true);
|
|
55
|
+
const magic = view.getUint16(34, true);
|
|
56
|
+
if (magic !== 20556) return {
|
|
57
|
+
status: "corrupt",
|
|
58
|
+
reason: `Invalid EOT magic number 0x${magic.toString(16)}`
|
|
59
|
+
};
|
|
60
|
+
if (version !== 65536 && version !== 131073 && version !== 131074) return {
|
|
61
|
+
status: "corrupt",
|
|
62
|
+
reason: `Unsupported EOT version 0x${version.toString(16)}`
|
|
63
|
+
};
|
|
64
|
+
if ((flags & 4) !== 0) return {
|
|
65
|
+
status: "unsupported",
|
|
66
|
+
reason: "compressed-eot"
|
|
67
|
+
};
|
|
68
|
+
if ((flags & 268435456) !== 0) return {
|
|
69
|
+
status: "unsupported",
|
|
70
|
+
reason: "obfuscated-eot"
|
|
71
|
+
};
|
|
72
|
+
if ((flags & 1) !== 0) return {
|
|
73
|
+
status: "unsupported",
|
|
74
|
+
reason: "eudc-eot"
|
|
75
|
+
};
|
|
76
|
+
if (fontDataSize === 0 || eotSize > bytes.byteLength || fontDataSize > eotSize - 82) return {
|
|
77
|
+
status: "corrupt",
|
|
78
|
+
reason: "EOT font payload bounds exceed container length"
|
|
79
|
+
};
|
|
80
|
+
const payloadStart = eotSize - fontDataSize;
|
|
81
|
+
const ttfBytes = bytes.slice(payloadStart, eotSize);
|
|
82
|
+
if (!isTrueTypeSfntHeader(ttfBytes)) return {
|
|
83
|
+
status: "corrupt",
|
|
84
|
+
reason: "Unpacked EOT payload is not a static TrueType SFNT file"
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
status: "ok",
|
|
88
|
+
ttfBytes,
|
|
89
|
+
...weight > 0 ? { eotWeight: weight } : {},
|
|
90
|
+
eotItalic: italic
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reads presentation-level `<p:embeddedFontLst>` declarations and resolves each font slot
|
|
95
|
+
* relationship into detached `.fntdata` bytes while isolating missing or broken targets.
|
|
96
|
+
*/
|
|
97
|
+
function readEmbeddedFontList(presentationCursor, presentationRels, pkg, diagnostics) {
|
|
98
|
+
const rawPresAttrs = presentationCursor.attrsObject(["embedTrueTypeFonts", "saveSubsetFonts"]);
|
|
99
|
+
if (!presentationFontAttrSchema.safeParse(rawPresAttrs).success) diagnostics.push({
|
|
100
|
+
code: "invalid-xml-value",
|
|
101
|
+
category: "corrupt-input",
|
|
102
|
+
disposition: "recovered",
|
|
103
|
+
location: {
|
|
104
|
+
part: pkg.presentationPath,
|
|
105
|
+
xpath: presentationCursor.xpath
|
|
106
|
+
},
|
|
107
|
+
attributeOrElement: "p:presentation",
|
|
108
|
+
rawValue: JSON.stringify(rawPresAttrs)
|
|
109
|
+
});
|
|
110
|
+
const embeddedFontLst = presentationCursor.child(P_NS, "embeddedFontLst");
|
|
111
|
+
if (embeddedFontLst === void 0) return [];
|
|
112
|
+
const relById = /* @__PURE__ */ new Map();
|
|
113
|
+
for (const rel of presentationRels) relById.set(rel.Id, rel);
|
|
114
|
+
const records = [];
|
|
115
|
+
for (const entryCursor of embeddedFontLst.children(P_NS, "embeddedFont")) {
|
|
116
|
+
const fontEl = entryCursor.child(P_NS, "font");
|
|
117
|
+
if (fontEl === void 0) {
|
|
118
|
+
diagnostics.push({
|
|
119
|
+
code: "corrupt-part",
|
|
120
|
+
category: "corrupt-input",
|
|
121
|
+
disposition: "omitted",
|
|
122
|
+
location: {
|
|
123
|
+
part: pkg.presentationPath,
|
|
124
|
+
xpath: entryCursor.xpath
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const rawFont = fontEl.attrsObject([
|
|
130
|
+
"typeface",
|
|
131
|
+
"pitchFamily",
|
|
132
|
+
"charset",
|
|
133
|
+
"panose"
|
|
134
|
+
]);
|
|
135
|
+
const parsedFont = embeddedFontTypefaceXmlSchema.safeParse(rawFont);
|
|
136
|
+
if (!parsedFont.success) {
|
|
137
|
+
diagnostics.push({
|
|
138
|
+
code: "invalid-xml-value",
|
|
139
|
+
category: "corrupt-input",
|
|
140
|
+
disposition: "omitted",
|
|
141
|
+
location: {
|
|
142
|
+
part: pkg.presentationPath,
|
|
143
|
+
xpath: fontEl.xpath
|
|
144
|
+
},
|
|
145
|
+
attributeOrElement: "p:font",
|
|
146
|
+
rawValue: JSON.stringify(rawFont)
|
|
147
|
+
});
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const slots = [];
|
|
151
|
+
for (const slotName of fontSlotNames) {
|
|
152
|
+
const slotCursor = entryCursor.child(P_NS, slotName);
|
|
153
|
+
if (slotCursor === void 0) continue;
|
|
154
|
+
const rId = slotCursor.attr("id", R_NS);
|
|
155
|
+
const parsedRef = embeddedFontSlotRefXmlSchema.safeParse({ id: rId });
|
|
156
|
+
if (!parsedRef.success) {
|
|
157
|
+
diagnostics.push({
|
|
158
|
+
code: "invalid-xml-value",
|
|
159
|
+
category: "corrupt-input",
|
|
160
|
+
disposition: "omitted",
|
|
161
|
+
location: {
|
|
162
|
+
part: pkg.presentationPath,
|
|
163
|
+
xpath: slotCursor.xpath
|
|
164
|
+
},
|
|
165
|
+
attributeOrElement: `p:${slotName}/@r:id`,
|
|
166
|
+
rawValue: rId ?? ""
|
|
167
|
+
});
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const rel = relById.get(parsedRef.data.id);
|
|
171
|
+
if (rel === void 0 || rel.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font" || rel.TargetMode === "External") {
|
|
172
|
+
diagnostics.push({
|
|
173
|
+
code: "broken-relationship",
|
|
174
|
+
category: "corrupt-input",
|
|
175
|
+
disposition: "omitted",
|
|
176
|
+
location: {
|
|
177
|
+
part: pkg.presentationPath,
|
|
178
|
+
xpath: slotCursor.xpath
|
|
179
|
+
},
|
|
180
|
+
relationshipId: parsedRef.data.id
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const targetPart = resolvePartPath(pkg.presentationPath, rel.Target);
|
|
185
|
+
const bytes = targetPart === void 0 ? void 0 : pkg.readDetachedBytes(targetPart);
|
|
186
|
+
if (targetPart === void 0 || bytes === void 0) {
|
|
187
|
+
diagnostics.push({
|
|
188
|
+
code: "missing-target-part",
|
|
189
|
+
category: "corrupt-input",
|
|
190
|
+
disposition: "omitted",
|
|
191
|
+
location: {
|
|
192
|
+
part: pkg.presentationPath,
|
|
193
|
+
xpath: slotCursor.xpath
|
|
194
|
+
},
|
|
195
|
+
relationshipId: parsedRef.data.id,
|
|
196
|
+
targetPart: targetPart ?? rel.Target
|
|
197
|
+
});
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
slots.push({
|
|
201
|
+
slot: slotName,
|
|
202
|
+
relationshipId: parsedRef.data.id,
|
|
203
|
+
partPath: targetPart,
|
|
204
|
+
bytes,
|
|
205
|
+
xpath: slotCursor.xpath
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
records.push({
|
|
209
|
+
typeface: parsedFont.data.typeface,
|
|
210
|
+
...parsedFont.data.pitchFamily === void 0 ? {} : { pitchFamily: parsedFont.data.pitchFamily },
|
|
211
|
+
...parsedFont.data.charset === void 0 ? {} : { charset: parsedFont.data.charset },
|
|
212
|
+
slots,
|
|
213
|
+
xpath: entryCursor.xpath
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return records;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Reads the primary theme `<a:fontScheme>` (`majorFont`/`minorFont` Latin typeface) following
|
|
220
|
+
* presentation -> slideMaster -> theme relationships so `+mj-lt` / `+mn-lt` tokens can link
|
|
221
|
+
* to embedded font resources.
|
|
222
|
+
*/
|
|
223
|
+
function readPresentationThemeFontScheme(pkg, diagnostics) {
|
|
224
|
+
const masterRel = pkg.presentationRels.find((rel) => rel.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" && rel.TargetMode !== "External");
|
|
225
|
+
if (masterRel === void 0) return void 0;
|
|
226
|
+
const masterPath = resolvePartPath(pkg.presentationPath, masterRel.Target);
|
|
227
|
+
if (masterPath === void 0) return void 0;
|
|
228
|
+
const themeRel = pkg.readRelationships(masterPath).entries.find((rel) => rel.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" && rel.TargetMode !== "External");
|
|
229
|
+
if (themeRel === void 0) return void 0;
|
|
230
|
+
const themePath = resolvePartPath(masterPath, themeRel.Target);
|
|
231
|
+
if (themePath === void 0) return void 0;
|
|
232
|
+
const themeXmlText = pkg.readTextPart(themePath);
|
|
233
|
+
if (themeXmlText === void 0) return void 0;
|
|
234
|
+
let themeEl;
|
|
235
|
+
try {
|
|
236
|
+
themeEl = parseXmlPart(themePath, themeXmlText);
|
|
237
|
+
} catch {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if ((themeEl.namespaceURI ?? "") !== "http://schemas.openxmlformats.org/drawingml/2006/main" || (themeEl.localName ?? themeEl.tagName) !== "theme") return;
|
|
241
|
+
const themeCursor = XmlElementCursor.createRoot(themeEl, themePath, "/a:theme");
|
|
242
|
+
const themeName = themeCursor.attr("name");
|
|
243
|
+
const fontScheme = themeCursor.child(A_NS, "themeElements")?.child(A_NS, "fontScheme");
|
|
244
|
+
if (fontScheme === void 0) return void 0;
|
|
245
|
+
const readFontSlotTypeface = (slotCursor, elementTag) => {
|
|
246
|
+
const attrs = slotCursor?.attrsObject(["typeface"]);
|
|
247
|
+
const parsed = themeTypefaceXmlSchema.safeParse(attrs);
|
|
248
|
+
if (parsed.success) return parsed.data.typeface;
|
|
249
|
+
const rawTypeface = attrs?.["typeface"];
|
|
250
|
+
if (diagnostics !== void 0 && slotCursor !== void 0 && rawTypeface !== void 0 && rawTypeface.trim() !== "" && reservedThemeFontPattern.test(rawTypeface.trim())) {
|
|
251
|
+
const xpath = `${slotCursor.xpath}/@typeface`;
|
|
252
|
+
if (!diagnostics.some((existing) => existing.code === "invalid-xml-value" && existing.location.part === themePath && existing.attributeOrElement === `${elementTag}/@typeface` && existing.rawValue === rawTypeface && (existing.location.xpath === void 0 || existing.location.xpath === xpath))) diagnostics.push({
|
|
253
|
+
code: "invalid-xml-value",
|
|
254
|
+
category: "corrupt-input",
|
|
255
|
+
disposition: "omitted",
|
|
256
|
+
location: {
|
|
257
|
+
part: themePath,
|
|
258
|
+
xpath
|
|
259
|
+
},
|
|
260
|
+
attributeOrElement: `${elementTag}/@typeface`,
|
|
261
|
+
rawValue: rawTypeface
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const majorFont = fontScheme.child(A_NS, "majorFont");
|
|
266
|
+
const minorFont = fontScheme.child(A_NS, "minorFont");
|
|
267
|
+
const majorTypeface = readFontSlotTypeface(majorFont?.child(A_NS, "latin"), "a:latin");
|
|
268
|
+
const minorTypeface = readFontSlotTypeface(minorFont?.child(A_NS, "latin"), "a:latin");
|
|
269
|
+
const majorEastAsianTypeface = readFontSlotTypeface(majorFont?.child(A_NS, "ea"), "a:ea");
|
|
270
|
+
const minorEastAsianTypeface = readFontSlotTypeface(minorFont?.child(A_NS, "ea"), "a:ea");
|
|
271
|
+
return {
|
|
272
|
+
...themeName !== void 0 && themeName.trim() !== "" ? { themeName } : {},
|
|
273
|
+
...majorTypeface === void 0 ? {} : { majorTypeface },
|
|
274
|
+
...minorTypeface === void 0 ? {} : { minorTypeface },
|
|
275
|
+
...majorEastAsianTypeface === void 0 ? {} : { majorEastAsianTypeface },
|
|
276
|
+
...minorEastAsianTypeface === void 0 ? {} : { minorEastAsianTypeface }
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function normalizeRunFontSlotTypeface(typeface) {
|
|
280
|
+
if (typeface === "+mj-lt" || typeface === "+mj-ea" || typeface === "+mj-cs") return "major";
|
|
281
|
+
if (typeface === "+mn-lt" || typeface === "+mn-ea" || typeface === "+mn-cs") return "minor";
|
|
282
|
+
return typeface;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Reads `<a:latin>`, `<a:ea>`, and `<a:cs>` font slots under `<a:rPr>` or `<a:defRPr>`,
|
|
286
|
+
* preserving orthogonal `eastAsianFontFamily` when `<a:ea>` differs from `<a:latin>` or appears alone.
|
|
287
|
+
*/
|
|
288
|
+
function readRunFontSlots(rPrCursor) {
|
|
289
|
+
const readSlot = (cursor) => {
|
|
290
|
+
if (cursor === void 0) return void 0;
|
|
291
|
+
const typeface = cursor.attrsObject([
|
|
292
|
+
"typeface",
|
|
293
|
+
"pitchFamily",
|
|
294
|
+
"charset",
|
|
295
|
+
"panose"
|
|
296
|
+
])["typeface"];
|
|
297
|
+
return typeface !== void 0 && typeface.trim() !== "" ? normalizeRunFontSlotTypeface(typeface) : void 0;
|
|
298
|
+
};
|
|
299
|
+
const latinToken = readSlot(rPrCursor.child(A_NS, "latin"));
|
|
300
|
+
const eaToken = readSlot(rPrCursor.child(A_NS, "ea"));
|
|
301
|
+
const csToken = readSlot(rPrCursor.child(A_NS, "cs"));
|
|
302
|
+
const fontFamily = latinToken ?? (eaToken === void 0 ? csToken : void 0);
|
|
303
|
+
const eastAsianFontFamily = eaToken !== void 0 && eaToken !== fontFamily ? eaToken : void 0;
|
|
304
|
+
return {
|
|
305
|
+
...fontFamily === void 0 ? {} : { fontFamily },
|
|
306
|
+
...eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily }
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
export { readEmbeddedFontList, readPresentationThemeFontScheme, readRunFontSlots, unpackEotFontData };
|