@officedk/pptxdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/build.d.ts +94 -0
- package/dist/build.js +148 -0
- package/dist/capabilities/dist/all.js +32 -0
- package/dist/capabilities/dist/box/box-codegen.js +51 -0
- package/dist/capabilities/dist/box/box-declaration.js +31 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +138 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +77 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2272 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1078 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1124 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +190 -0
- package/dist/capabilities/dist/chart/preview/layout.js +519 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +48 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +148 -0
- package/dist/capabilities/dist/font/font-embedding.js +289 -0
- package/dist/capabilities/dist/font/font-family.js +10 -0
- package/dist/capabilities/dist/font/font-import.js +302 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +25 -0
- package/dist/capabilities/dist/group/group-codegen.js +51 -0
- package/dist/capabilities/dist/group/group-declaration.js +42 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +319 -0
- package/dist/capabilities/dist/group/group-xml.js +7 -0
- package/dist/capabilities/dist/group/group.js +211 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +94 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +221 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +778 -0
- package/dist/capabilities/dist/image/image-schemas.js +149 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +472 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +527 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1033 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
- package/dist/capabilities/dist/motion/motion-query.js +420 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
- package/dist/capabilities/dist/motion/motion.js +1372 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +20 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +35 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +191 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +579 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +337 -0
- package/dist/capabilities/dist/shared/geometry.js +1423 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +113 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
- package/dist/capabilities/dist/shared/style-parse.js +11 -0
- package/dist/capabilities/dist/shared/text-schemas.js +216 -0
- package/dist/capabilities/dist/shared/text-service.js +1883 -0
- package/dist/capabilities/dist/shared/visual.js +918 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
- package/dist/capabilities/dist/table/table-codegen.js +81 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +539 -0
- package/dist/capabilities/dist/table/table-schemas.js +279 -0
- package/dist/capabilities/dist/table/table-xml.js +37 -0
- package/dist/capabilities/dist/table/table.js +662 -0
- package/dist/capabilities/dist/text/text-codegen.js +129 -0
- package/dist/capabilities/dist/text/text-declaration.js +19 -0
- package/dist/capabilities/dist/text/text-elements.js +38 -0
- package/dist/capabilities/dist/text/text-import.js +1077 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +335 -0
- package/dist/capabilities/dist/transition/transition-api.js +139 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-D_xeNVIw.d.ts +29496 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +78 -0
- package/dist/codegen/dist/codegen.js +611 -0
- package/dist/codegen/dist/identifiers.js +193 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +49 -0
- package/dist/core/dist/author-ids.js +48 -0
- package/dist/core/dist/author-schemas.js +313 -0
- package/dist/core/dist/block-flex-layout.js +749 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +13 -0
- package/dist/core/dist/declaration.js +15 -0
- package/dist/core/dist/diagnostics.js +21 -0
- package/dist/core/dist/document-internals.js +13 -0
- package/dist/core/dist/document.js +408 -0
- package/dist/core/dist/geometry-schemas.js +249 -0
- package/dist/core/dist/grid-layout.js +445 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +45 -0
- package/dist/core/dist/layout-protocol.js +66 -0
- package/dist/core/dist/layout-schemas.js +208 -0
- package/dist/core/dist/layout.js +299 -0
- package/dist/core/dist/masters.js +169 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +213 -0
- package/dist/core/dist/query.js +155 -0
- package/dist/core/dist/resolution.js +11 -0
- package/dist/core/dist/resolve.js +1827 -0
- package/dist/core/dist/stage-options.js +67 -0
- package/dist/core/dist/theme.js +931 -0
- package/dist/document-BHPUODPP.d.ts +27759 -0
- package/dist/emit/dist/emit.js +936 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +606 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +153 -0
- package/dist/import/dist/fonts.js +250 -0
- package/dist/import/dist/import.js +504 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1153 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +60 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +671 -0
- package/dist/import/dist/visual.js +761 -0
- package/dist/import/dist/xml-fragments.js +36 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-B5m3hqjC.d.ts +7 -0
- package/dist/index-CCy-Yo8G.d.ts +1208 -0
- package/dist/index-DpxcZ4Gs.d.ts +725 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +70 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +194 -0
- package/dist/pptxdk/src/cli-commands.js +913 -0
- package/dist/pptxdk/src/compose.js +44 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +240 -0
- package/dist/preview/dist/options.js +53 -0
- package/dist/preview-Cfw0QdMM.d.ts +86 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +27 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +65 -0
- package/dist/react/dist/elements.js +59 -0
- package/dist/react/dist/index.js +68 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +27 -0
- package/dist/transition-Cips9wma.d.ts +82 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +14 -0
- package/package.json +78 -3
|
@@ -0,0 +1,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,153 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ../import/dist/diagnostics.js
|
|
3
|
+
/** Source package location attached to import diagnostics and fatal errors. */
|
|
4
|
+
const importLocationSchema = z.object({
|
|
5
|
+
part: z.string().min(1),
|
|
6
|
+
xpath: z.string().min(1).optional(),
|
|
7
|
+
slideIndex: z.number().int().nonnegative().optional(),
|
|
8
|
+
objectId: z.number().int().optional(),
|
|
9
|
+
objectName: z.string().optional()
|
|
10
|
+
});
|
|
11
|
+
/** Native editing capability lost when a fallback representation is selected. */
|
|
12
|
+
const editabilityLossSchema = 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
|
+
/** Dependent item omitted because an ancestor or target part could not be imported. */
|
|
22
|
+
const cascadedOmissionSchema = z.object({
|
|
23
|
+
location: importLocationSchema,
|
|
24
|
+
role: z.string().min(1)
|
|
25
|
+
});
|
|
26
|
+
/** Fatal package/entry failure reason carried by `ImportError`. */
|
|
27
|
+
const fatalImportIssueSchema = z.discriminatedUnion("code", [
|
|
28
|
+
z.object({
|
|
29
|
+
code: z.literal("corrupt-archive"),
|
|
30
|
+
category: z.literal("corrupt-input"),
|
|
31
|
+
disposition: z.literal("aborted")
|
|
32
|
+
}),
|
|
33
|
+
z.object({
|
|
34
|
+
code: z.literal("missing-entry"),
|
|
35
|
+
category: z.literal("corrupt-input"),
|
|
36
|
+
disposition: z.literal("aborted"),
|
|
37
|
+
location: importLocationSchema,
|
|
38
|
+
expectedRelationshipType: z.string().optional()
|
|
39
|
+
}),
|
|
40
|
+
z.object({
|
|
41
|
+
code: z.literal("malformed-xml"),
|
|
42
|
+
category: z.literal("corrupt-input"),
|
|
43
|
+
disposition: z.literal("aborted"),
|
|
44
|
+
location: importLocationSchema,
|
|
45
|
+
detail: z.string().optional()
|
|
46
|
+
}),
|
|
47
|
+
z.object({
|
|
48
|
+
code: z.literal("broken-entry-relationship"),
|
|
49
|
+
category: z.literal("corrupt-input"),
|
|
50
|
+
disposition: z.literal("aborted"),
|
|
51
|
+
location: importLocationSchema,
|
|
52
|
+
relationshipId: z.string().optional(),
|
|
53
|
+
target: z.string().optional()
|
|
54
|
+
}),
|
|
55
|
+
z.object({
|
|
56
|
+
code: z.literal("invalid-presentation-root"),
|
|
57
|
+
category: z.literal("corrupt-input"),
|
|
58
|
+
disposition: z.literal("aborted"),
|
|
59
|
+
location: importLocationSchema,
|
|
60
|
+
namespaceUri: z.string().optional(),
|
|
61
|
+
localName: z.string().optional()
|
|
62
|
+
}),
|
|
63
|
+
z.object({
|
|
64
|
+
code: z.literal("unsupported-format-baseline"),
|
|
65
|
+
category: z.literal("unsupported"),
|
|
66
|
+
disposition: z.literal("aborted"),
|
|
67
|
+
baseline: z.enum(["ISO/IEC 29500 Strict", "unknown"]),
|
|
68
|
+
detectedNamespace: z.string().min(1),
|
|
69
|
+
location: importLocationSchema
|
|
70
|
+
})
|
|
71
|
+
]);
|
|
72
|
+
/** Recoverable or isolatable diagnostic event emitted in `ImportReport.diagnostics`. */
|
|
73
|
+
const importDiagnosticSchema = z.discriminatedUnion("code", [
|
|
74
|
+
z.object({
|
|
75
|
+
code: z.literal("corrupt-part"),
|
|
76
|
+
category: z.literal("corrupt-input"),
|
|
77
|
+
disposition: z.literal("omitted"),
|
|
78
|
+
location: importLocationSchema,
|
|
79
|
+
cascaded: z.array(cascadedOmissionSchema).readonly().optional()
|
|
80
|
+
}),
|
|
81
|
+
z.object({
|
|
82
|
+
code: z.literal("missing-target-part"),
|
|
83
|
+
category: z.literal("corrupt-input"),
|
|
84
|
+
disposition: z.literal("omitted"),
|
|
85
|
+
location: importLocationSchema,
|
|
86
|
+
relationshipId: z.string(),
|
|
87
|
+
targetPart: z.string(),
|
|
88
|
+
cascaded: z.array(cascadedOmissionSchema).readonly().optional()
|
|
89
|
+
}),
|
|
90
|
+
z.object({
|
|
91
|
+
code: z.literal("broken-relationship"),
|
|
92
|
+
category: z.literal("corrupt-input"),
|
|
93
|
+
disposition: z.literal("omitted"),
|
|
94
|
+
location: importLocationSchema,
|
|
95
|
+
relationshipId: z.string(),
|
|
96
|
+
cascaded: z.array(cascadedOmissionSchema).readonly().optional()
|
|
97
|
+
}),
|
|
98
|
+
z.object({
|
|
99
|
+
code: z.literal("invalid-xml-value"),
|
|
100
|
+
category: z.literal("corrupt-input"),
|
|
101
|
+
disposition: z.enum(["omitted", "recovered"]),
|
|
102
|
+
location: importLocationSchema,
|
|
103
|
+
attributeOrElement: z.string(),
|
|
104
|
+
rawValue: z.string().optional()
|
|
105
|
+
}),
|
|
106
|
+
z.object({
|
|
107
|
+
code: z.literal("unsupported-mechanism"),
|
|
108
|
+
category: z.literal("unsupported"),
|
|
109
|
+
disposition: z.literal("omitted"),
|
|
110
|
+
location: importLocationSchema,
|
|
111
|
+
namespaceUri: z.string(),
|
|
112
|
+
localName: z.string(),
|
|
113
|
+
mechanismHint: z.string().optional(),
|
|
114
|
+
loss: editabilityLossSchema.optional(),
|
|
115
|
+
cascaded: z.array(cascadedOmissionSchema).readonly().optional()
|
|
116
|
+
}),
|
|
117
|
+
z.object({
|
|
118
|
+
code: z.literal("compatibility-fallback"),
|
|
119
|
+
category: z.literal("unsupported"),
|
|
120
|
+
disposition: z.literal("fallback"),
|
|
121
|
+
location: importLocationSchema,
|
|
122
|
+
preferredMechanism: z.string(),
|
|
123
|
+
selectedFallback: z.string(),
|
|
124
|
+
loss: editabilityLossSchema
|
|
125
|
+
}),
|
|
126
|
+
z.object({
|
|
127
|
+
code: z.literal("unconsumed-xml"),
|
|
128
|
+
category: z.literal("unsupported"),
|
|
129
|
+
disposition: z.literal("omitted"),
|
|
130
|
+
kind: z.enum(["attribute", "element"]),
|
|
131
|
+
location: importLocationSchema,
|
|
132
|
+
namespaceUri: z.string(),
|
|
133
|
+
localName: z.string()
|
|
134
|
+
})
|
|
135
|
+
]);
|
|
136
|
+
/** Structured summary and per-item diagnostics produced by `createImporter`. */
|
|
137
|
+
const importReportSchema = z.object({
|
|
138
|
+
evidence: z.literal("import"),
|
|
139
|
+
sourceFormat: z.literal("ECMA-376 5th edition Transitional"),
|
|
140
|
+
slideCount: z.number().int().nonnegative(),
|
|
141
|
+
diagnostics: z.array(importDiagnosticSchema).readonly()
|
|
142
|
+
});
|
|
143
|
+
const importOptionsSchema = z.object({ signal: z.custom((value) => typeof value === "object" && value !== null && "aborted" in value && typeof value.aborted === "boolean").optional() }).strict();
|
|
144
|
+
/** Error thrown when PPTX entry points cannot be opened or use an unsupported baseline. */
|
|
145
|
+
var ImportError = class extends Error {
|
|
146
|
+
issue;
|
|
147
|
+
constructor(issue, message) {
|
|
148
|
+
super(message ?? issue.code);
|
|
149
|
+
this.name = "ImportError";
|
|
150
|
+
this.issue = Object.freeze(fatalImportIssueSchema.parse(issue));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
export { ImportError, cascadedOmissionSchema, editabilityLossSchema, fatalImportIssueSchema, importDiagnosticSchema, importLocationSchema, importOptionsSchema, importReportSchema };
|
|
@@ -0,0 +1,250 @@
|
|
|
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 embeddedFontTypefaceXmlSchema = z.object({
|
|
18
|
+
typeface: z.string().min(1),
|
|
19
|
+
pitchFamily: ooxmlIntSchema.optional(),
|
|
20
|
+
charset: ooxmlIntSchema.optional(),
|
|
21
|
+
panose: z.string().optional()
|
|
22
|
+
});
|
|
23
|
+
const embeddedFontSlotRefXmlSchema = z.object({ id: z.string().min(1) });
|
|
24
|
+
const themeTypefaceXmlSchema = z.object({ typeface: z.string().min(1) });
|
|
25
|
+
function isTrueTypeSfntHeader(bytes) {
|
|
26
|
+
if (bytes.byteLength < 12) return false;
|
|
27
|
+
const sig = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3]);
|
|
28
|
+
return sig === "\0\0\0" || sig === "true";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Unpacks an uncompressed EOT (`.fntdata`) container or raw SFNT buffer into a detached
|
|
32
|
+
* TrueType `Uint8Array`, isolating compressed/obfuscated or corrupt payloads cleanly.
|
|
33
|
+
*/
|
|
34
|
+
function unpackEotFontData(bytes) {
|
|
35
|
+
if (isTrueTypeSfntHeader(bytes)) return {
|
|
36
|
+
status: "ok",
|
|
37
|
+
ttfBytes: new Uint8Array(bytes)
|
|
38
|
+
};
|
|
39
|
+
if (bytes.byteLength < 82) return {
|
|
40
|
+
status: "corrupt",
|
|
41
|
+
reason: "EOT header shorter than 82 bytes"
|
|
42
|
+
};
|
|
43
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
44
|
+
const eotSize = view.getUint32(0, true);
|
|
45
|
+
const fontDataSize = view.getUint32(4, true);
|
|
46
|
+
const version = view.getUint32(8, true);
|
|
47
|
+
const flags = view.getUint32(12, true);
|
|
48
|
+
const italic = bytes[27] !== 0;
|
|
49
|
+
const weight = view.getUint32(28, true);
|
|
50
|
+
const magic = view.getUint16(34, true);
|
|
51
|
+
if (magic !== 20556) return {
|
|
52
|
+
status: "corrupt",
|
|
53
|
+
reason: `Invalid EOT magic number 0x${magic.toString(16)}`
|
|
54
|
+
};
|
|
55
|
+
if (version !== 65536 && version !== 131073 && version !== 131074) return {
|
|
56
|
+
status: "corrupt",
|
|
57
|
+
reason: `Unsupported EOT version 0x${version.toString(16)}`
|
|
58
|
+
};
|
|
59
|
+
if ((flags & 4) !== 0) return {
|
|
60
|
+
status: "unsupported",
|
|
61
|
+
reason: "compressed-eot"
|
|
62
|
+
};
|
|
63
|
+
if ((flags & 268435456) !== 0) return {
|
|
64
|
+
status: "unsupported",
|
|
65
|
+
reason: "obfuscated-eot"
|
|
66
|
+
};
|
|
67
|
+
if ((flags & 1) !== 0) return {
|
|
68
|
+
status: "unsupported",
|
|
69
|
+
reason: "eudc-eot"
|
|
70
|
+
};
|
|
71
|
+
if (fontDataSize === 0 || eotSize > bytes.byteLength || fontDataSize > eotSize - 82) return {
|
|
72
|
+
status: "corrupt",
|
|
73
|
+
reason: "EOT font payload bounds exceed container length"
|
|
74
|
+
};
|
|
75
|
+
const payloadStart = eotSize - fontDataSize;
|
|
76
|
+
const ttfBytes = bytes.slice(payloadStart, eotSize);
|
|
77
|
+
if (!isTrueTypeSfntHeader(ttfBytes)) return {
|
|
78
|
+
status: "corrupt",
|
|
79
|
+
reason: "Unpacked EOT payload is not a static TrueType SFNT file"
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
status: "ok",
|
|
83
|
+
ttfBytes,
|
|
84
|
+
...weight > 0 ? { eotWeight: weight } : {},
|
|
85
|
+
eotItalic: italic
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reads presentation-level `<p:embeddedFontLst>` declarations and resolves each font slot
|
|
90
|
+
* relationship into detached `.fntdata` bytes while isolating missing or broken targets.
|
|
91
|
+
*/
|
|
92
|
+
function readEmbeddedFontList(presentationCursor, presentationRels, pkg, diagnostics) {
|
|
93
|
+
const rawPresAttrs = presentationCursor.attrsObject(["embedTrueTypeFonts", "saveSubsetFonts"]);
|
|
94
|
+
if (!presentationFontAttrSchema.safeParse(rawPresAttrs).success) diagnostics.push({
|
|
95
|
+
code: "invalid-xml-value",
|
|
96
|
+
category: "corrupt-input",
|
|
97
|
+
disposition: "recovered",
|
|
98
|
+
location: {
|
|
99
|
+
part: pkg.presentationPath,
|
|
100
|
+
xpath: presentationCursor.xpath
|
|
101
|
+
},
|
|
102
|
+
attributeOrElement: "p:presentation",
|
|
103
|
+
rawValue: JSON.stringify(rawPresAttrs)
|
|
104
|
+
});
|
|
105
|
+
const embeddedFontLst = presentationCursor.child(P_NS, "embeddedFontLst");
|
|
106
|
+
if (embeddedFontLst === void 0) return [];
|
|
107
|
+
const relById = /* @__PURE__ */ new Map();
|
|
108
|
+
for (const rel of presentationRels) relById.set(rel.Id, rel);
|
|
109
|
+
const records = [];
|
|
110
|
+
for (const entryCursor of embeddedFontLst.children(P_NS, "embeddedFont")) {
|
|
111
|
+
const fontEl = entryCursor.child(P_NS, "font");
|
|
112
|
+
if (fontEl === void 0) {
|
|
113
|
+
diagnostics.push({
|
|
114
|
+
code: "corrupt-part",
|
|
115
|
+
category: "corrupt-input",
|
|
116
|
+
disposition: "omitted",
|
|
117
|
+
location: {
|
|
118
|
+
part: pkg.presentationPath,
|
|
119
|
+
xpath: entryCursor.xpath
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const rawFont = fontEl.attrsObject([
|
|
125
|
+
"typeface",
|
|
126
|
+
"pitchFamily",
|
|
127
|
+
"charset",
|
|
128
|
+
"panose"
|
|
129
|
+
]);
|
|
130
|
+
const parsedFont = embeddedFontTypefaceXmlSchema.safeParse(rawFont);
|
|
131
|
+
if (!parsedFont.success) {
|
|
132
|
+
diagnostics.push({
|
|
133
|
+
code: "invalid-xml-value",
|
|
134
|
+
category: "corrupt-input",
|
|
135
|
+
disposition: "omitted",
|
|
136
|
+
location: {
|
|
137
|
+
part: pkg.presentationPath,
|
|
138
|
+
xpath: fontEl.xpath
|
|
139
|
+
},
|
|
140
|
+
attributeOrElement: "p:font",
|
|
141
|
+
rawValue: JSON.stringify(rawFont)
|
|
142
|
+
});
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const slots = [];
|
|
146
|
+
for (const slotName of fontSlotNames) {
|
|
147
|
+
const slotCursor = entryCursor.child(P_NS, slotName);
|
|
148
|
+
if (slotCursor === void 0) continue;
|
|
149
|
+
const rId = slotCursor.attr("id", R_NS);
|
|
150
|
+
const parsedRef = embeddedFontSlotRefXmlSchema.safeParse({ id: rId });
|
|
151
|
+
if (!parsedRef.success) {
|
|
152
|
+
diagnostics.push({
|
|
153
|
+
code: "invalid-xml-value",
|
|
154
|
+
category: "corrupt-input",
|
|
155
|
+
disposition: "omitted",
|
|
156
|
+
location: {
|
|
157
|
+
part: pkg.presentationPath,
|
|
158
|
+
xpath: slotCursor.xpath
|
|
159
|
+
},
|
|
160
|
+
attributeOrElement: `p:${slotName}/@r:id`,
|
|
161
|
+
rawValue: rId ?? ""
|
|
162
|
+
});
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const rel = relById.get(parsedRef.data.id);
|
|
166
|
+
if (rel === void 0 || rel.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font" || rel.TargetMode === "External") {
|
|
167
|
+
diagnostics.push({
|
|
168
|
+
code: "broken-relationship",
|
|
169
|
+
category: "corrupt-input",
|
|
170
|
+
disposition: "omitted",
|
|
171
|
+
location: {
|
|
172
|
+
part: pkg.presentationPath,
|
|
173
|
+
xpath: slotCursor.xpath
|
|
174
|
+
},
|
|
175
|
+
relationshipId: parsedRef.data.id
|
|
176
|
+
});
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const targetPart = resolvePartPath(pkg.presentationPath, rel.Target);
|
|
180
|
+
const bytes = targetPart === void 0 ? void 0 : pkg.readDetachedBytes(targetPart);
|
|
181
|
+
if (targetPart === void 0 || bytes === void 0) {
|
|
182
|
+
diagnostics.push({
|
|
183
|
+
code: "missing-target-part",
|
|
184
|
+
category: "corrupt-input",
|
|
185
|
+
disposition: "omitted",
|
|
186
|
+
location: {
|
|
187
|
+
part: pkg.presentationPath,
|
|
188
|
+
xpath: slotCursor.xpath
|
|
189
|
+
},
|
|
190
|
+
relationshipId: parsedRef.data.id,
|
|
191
|
+
targetPart: targetPart ?? rel.Target
|
|
192
|
+
});
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
slots.push({
|
|
196
|
+
slot: slotName,
|
|
197
|
+
relationshipId: parsedRef.data.id,
|
|
198
|
+
partPath: targetPart,
|
|
199
|
+
bytes,
|
|
200
|
+
xpath: slotCursor.xpath
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
records.push({
|
|
204
|
+
typeface: parsedFont.data.typeface,
|
|
205
|
+
...parsedFont.data.pitchFamily === void 0 ? {} : { pitchFamily: parsedFont.data.pitchFamily },
|
|
206
|
+
...parsedFont.data.charset === void 0 ? {} : { charset: parsedFont.data.charset },
|
|
207
|
+
slots,
|
|
208
|
+
xpath: entryCursor.xpath
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return records;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Reads the primary theme `<a:fontScheme>` (`majorFont`/`minorFont` Latin typeface) following
|
|
215
|
+
* presentation -> slideMaster -> theme relationships so `+mj-lt` / `+mn-lt` tokens can link
|
|
216
|
+
* to embedded font resources.
|
|
217
|
+
*/
|
|
218
|
+
function readPresentationThemeFontScheme(pkg) {
|
|
219
|
+
const masterRel = pkg.presentationRels.find((rel) => rel.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" && rel.TargetMode !== "External");
|
|
220
|
+
if (masterRel === void 0) return void 0;
|
|
221
|
+
const masterPath = resolvePartPath(pkg.presentationPath, masterRel.Target);
|
|
222
|
+
if (masterPath === void 0) return void 0;
|
|
223
|
+
const themeRel = pkg.readRelationships(masterPath).entries.find((rel) => rel.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" && rel.TargetMode !== "External");
|
|
224
|
+
if (themeRel === void 0) return void 0;
|
|
225
|
+
const themePath = resolvePartPath(masterPath, themeRel.Target);
|
|
226
|
+
if (themePath === void 0) return void 0;
|
|
227
|
+
const themeXmlText = pkg.readTextPart(themePath);
|
|
228
|
+
if (themeXmlText === void 0) return void 0;
|
|
229
|
+
let themeEl;
|
|
230
|
+
try {
|
|
231
|
+
themeEl = parseXmlPart(themePath, themeXmlText);
|
|
232
|
+
} catch {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if ((themeEl.namespaceURI ?? "") !== "http://schemas.openxmlformats.org/drawingml/2006/main" || (themeEl.localName ?? themeEl.tagName) !== "theme") return;
|
|
236
|
+
const themeCursor = XmlElementCursor.createRoot(themeEl, themePath);
|
|
237
|
+
const themeName = themeCursor.attr("name");
|
|
238
|
+
const fontScheme = themeCursor.child(A_NS, "themeElements")?.child(A_NS, "fontScheme");
|
|
239
|
+
if (fontScheme === void 0) return void 0;
|
|
240
|
+
const majorLatin = fontScheme.child(A_NS, "majorFont")?.child(A_NS, "latin")?.attrsObject(["typeface"]);
|
|
241
|
+
const minorLatin = fontScheme.child(A_NS, "minorFont")?.child(A_NS, "latin")?.attrsObject(["typeface"]);
|
|
242
|
+
const parsedMajor = themeTypefaceXmlSchema.safeParse(majorLatin);
|
|
243
|
+
const parsedMinor = themeTypefaceXmlSchema.safeParse(minorLatin);
|
|
244
|
+
return {
|
|
245
|
+
...themeName !== void 0 && themeName.trim() !== "" ? { themeName } : {},
|
|
246
|
+
...parsedMajor.success ? { majorTypeface: parsedMajor.data.typeface } : {},
|
|
247
|
+
...parsedMinor.success ? { minorTypeface: parsedMinor.data.typeface } : {}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
export { readEmbeddedFontList, readPresentationThemeFontScheme, unpackEotFontData };
|