@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,277 @@
|
|
|
1
|
+
import { assertValidLang } from "../../core/dist/theme.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { EMU_PER_PX, emuToPx } from "./namespaces.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// ../import/dist/xml-fragments.js
|
|
6
|
+
const integerStringPattern = /^-?\d+$/u;
|
|
7
|
+
const hexRgbPattern = /^[0-9a-fA-F]{6}$/u;
|
|
8
|
+
/** Parses an OOXML signed integer attribute string into a safe integer. */
|
|
9
|
+
const ooxmlIntSchema = z.string().regex(integerStringPattern).transform((value) => Number(value)).refine((value) => Number.isSafeInteger(value));
|
|
10
|
+
/** Parses an OOXML non-negative integer attribute string into a safe integer. */
|
|
11
|
+
const ooxmlNonNegativeIntSchema = ooxmlIntSchema.refine((value) => value >= 0);
|
|
12
|
+
/** Parses an OOXML positive integer attribute string into a safe integer. */
|
|
13
|
+
const ooxmlPositiveIntSchema = ooxmlIntSchema.refine((value) => value > 0);
|
|
14
|
+
/** DrawingML `<a:rPr sz="...">` valid integer centipoint domain (`1pt .. 4000pt`). */
|
|
15
|
+
const ooxmlFontSizeCentipointsSchema = ooxmlIntSchema.refine((value) => value >= 100 && value <= 4e5);
|
|
16
|
+
/** DrawingML `<a:rPr spc="...">` valid integer centipoint domain (`-4000pt .. 4000pt`). */
|
|
17
|
+
const ooxmlLetterSpacingCentipointsSchema = ooxmlIntSchema.refine((value) => value >= -4e5 && value <= 4e5);
|
|
18
|
+
/** DrawingML `<a:rPr baseline="...">` valid 32-bit signed thousandths of a percent (`ST_Percentage`). */
|
|
19
|
+
const ooxmlBaselineShiftThousandthsSchema = ooxmlIntSchema.refine((value) => value >= -2147483648 && value <= 2147483647);
|
|
20
|
+
/** DrawingML `<a:lnSpc><a:spcPts val="...">` valid centipoint domain (`>0 .. 1584pt`). */
|
|
21
|
+
const ooxmlLineSpacingPointsSchema = ooxmlIntSchema.refine((value) => value >= 1 && value <= 158400);
|
|
22
|
+
/** DrawingML `<a:lnSpc><a:spcPct val="...">` valid thousandth-percent domain (`>0% .. 13200%`). */
|
|
23
|
+
const ooxmlLineSpacingPercentSchema = ooxmlIntSchema.refine((value) => value >= 1 && value <= 132e5);
|
|
24
|
+
/** DrawingML `<a:spcBef|spcAft><a:spcPts val="...">` valid non-negative centipoint domain (`0 .. 1584pt`). */
|
|
25
|
+
const ooxmlParagraphSpacingPointsSchema = ooxmlIntSchema.refine((value) => value >= 0 && value <= 158400);
|
|
26
|
+
/** DrawingML `<a:buAutoNum startAt="...">` valid integer domain (`1 .. 32767`). */
|
|
27
|
+
const ooxmlAutoNumStartAtSchema = ooxmlIntSchema.refine((value) => value >= 1 && value <= 32767);
|
|
28
|
+
/** DrawingML `<a:pPr lvl="...">` valid paragraph level (`0 .. 8`). */
|
|
29
|
+
const ooxmlListLevelSchema = ooxmlIntSchema.refine((value) => value >= 0 && value <= 8);
|
|
30
|
+
/** DrawingML `ST_PositiveFixedAngle` domain (`0 <= value < 21_600_000`, 60,000ths of a degree). */
|
|
31
|
+
const ooxmlPositiveFixedAngleSchema = ooxmlIntSchema.refine((value) => value >= 0 && value < 216e5);
|
|
32
|
+
function pushInvalidXmlAttrDiagnostic(diagnostics, location, elementXpath, attrName, rawValue) {
|
|
33
|
+
diagnostics.push({
|
|
34
|
+
code: "invalid-xml-value",
|
|
35
|
+
category: "corrupt-input",
|
|
36
|
+
disposition: "omitted",
|
|
37
|
+
location: {
|
|
38
|
+
...location,
|
|
39
|
+
xpath: `${elementXpath}/@${attrName}`
|
|
40
|
+
},
|
|
41
|
+
attributeOrElement: `@${attrName}`,
|
|
42
|
+
rawValue
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parses `<a:rPr>`, `<a:defRPr>`, or `<a:endParaRPr>` scalar attributes independently so an
|
|
47
|
+
* out-of-range or malformed attribute strips only itself (recording `invalid-xml-value`) while
|
|
48
|
+
* preserving valid sibling attributes.
|
|
49
|
+
*/
|
|
50
|
+
function readOoxmlRunAttrStyles(args) {
|
|
51
|
+
const { rPrCursor, location, diagnostics } = args;
|
|
52
|
+
const raw = rPrCursor.attrsObject([
|
|
53
|
+
"lang",
|
|
54
|
+
"sz",
|
|
55
|
+
"b",
|
|
56
|
+
"i",
|
|
57
|
+
"u",
|
|
58
|
+
"strike",
|
|
59
|
+
"cap",
|
|
60
|
+
"spc",
|
|
61
|
+
"kern",
|
|
62
|
+
"dirty",
|
|
63
|
+
"smtClean",
|
|
64
|
+
"baseline"
|
|
65
|
+
]);
|
|
66
|
+
let lang;
|
|
67
|
+
if (raw["lang"] !== void 0) try {
|
|
68
|
+
lang = assertValidLang(raw["lang"]);
|
|
69
|
+
} catch {
|
|
70
|
+
pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "lang", raw["lang"]);
|
|
71
|
+
}
|
|
72
|
+
let fontSize;
|
|
73
|
+
let sizePt;
|
|
74
|
+
if (raw["sz"] !== void 0) {
|
|
75
|
+
const parsed = ooxmlFontSizeCentipointsSchema.safeParse(raw["sz"]);
|
|
76
|
+
if (parsed.success) {
|
|
77
|
+
sizePt = parsed.data / 100;
|
|
78
|
+
fontSize = `${sizePt}pt`;
|
|
79
|
+
} else pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "sz", raw["sz"]);
|
|
80
|
+
}
|
|
81
|
+
let fontWeight;
|
|
82
|
+
if (raw["b"] !== void 0) {
|
|
83
|
+
const parsed = ooxmlBoolSchema.safeParse(raw["b"]);
|
|
84
|
+
if (parsed.success) fontWeight = parsed.data ? "bold" : "normal";
|
|
85
|
+
else pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "b", raw["b"]);
|
|
86
|
+
}
|
|
87
|
+
let fontStyle;
|
|
88
|
+
if (raw["i"] !== void 0) {
|
|
89
|
+
const parsed = ooxmlBoolSchema.safeParse(raw["i"]);
|
|
90
|
+
if (parsed.success) fontStyle = parsed.data ? "italic" : "normal";
|
|
91
|
+
else pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "i", raw["i"]);
|
|
92
|
+
}
|
|
93
|
+
const rawU = raw["u"];
|
|
94
|
+
if (rawU !== void 0 && rawU !== "none" && rawU !== "sng" && args.diagnoseUnsupportedEnums === true) pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "u", rawU);
|
|
95
|
+
const rawStrike = raw["strike"];
|
|
96
|
+
if (rawStrike !== void 0 && rawStrike !== "noStrike" && rawStrike !== "sngStrike" && args.diagnoseUnsupportedEnums === true) pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "strike", rawStrike);
|
|
97
|
+
const textDecoration = rawU === "sng" ? "underline" : rawStrike === "sngStrike" ? "line-through" : args.allowNoneTextDecoration === true && rawU === "none" && rawStrike === "noStrike" ? "none" : void 0;
|
|
98
|
+
const rawCap = raw["cap"];
|
|
99
|
+
if (rawCap !== void 0 && rawCap !== "none" && rawCap !== "all" && args.diagnoseUnsupportedEnums === true) pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "cap", rawCap);
|
|
100
|
+
const textTransform = rawCap === "all" ? "uppercase" : rawCap === "none" ? "none" : void 0;
|
|
101
|
+
let letterSpacing;
|
|
102
|
+
if (raw["spc"] !== void 0) {
|
|
103
|
+
const parsed = ooxmlLetterSpacingCentipointsSchema.safeParse(raw["spc"]);
|
|
104
|
+
if (parsed.success) letterSpacing = parsed.data === 0 ? 0 : parsed.data / 75;
|
|
105
|
+
else pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "spc", raw["spc"]);
|
|
106
|
+
}
|
|
107
|
+
let baselineShift;
|
|
108
|
+
let inlineKind;
|
|
109
|
+
if (args.allowBaseline === true && raw["baseline"] !== void 0) {
|
|
110
|
+
const parsed = ooxmlBaselineShiftThousandthsSchema.safeParse(raw["baseline"]);
|
|
111
|
+
if (!parsed.success) pushInvalidXmlAttrDiagnostic(diagnostics, location, rPrCursor.xpath, "baseline", raw["baseline"]);
|
|
112
|
+
else if (parsed.data === 3e4) inlineKind = "sup";
|
|
113
|
+
else if (parsed.data === -25e3) inlineKind = "sub";
|
|
114
|
+
else if (parsed.data !== 0) baselineShift = `${parsed.data / 1e3}%`;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
...fontSize === void 0 ? {} : { fontSize },
|
|
118
|
+
...sizePt === void 0 ? {} : { sizePt },
|
|
119
|
+
...fontWeight === void 0 ? {} : { fontWeight },
|
|
120
|
+
...fontStyle === void 0 ? {} : { fontStyle },
|
|
121
|
+
...textDecoration === void 0 ? {} : { textDecoration },
|
|
122
|
+
...textTransform === void 0 ? {} : { textTransform },
|
|
123
|
+
...letterSpacing === void 0 ? {} : { letterSpacing },
|
|
124
|
+
...lang === void 0 ? {} : { lang },
|
|
125
|
+
...baselineShift === void 0 ? {} : { baselineShift },
|
|
126
|
+
...inlineKind === void 0 ? {} : { inlineKind }
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** Parses OOXML xsd:boolean attribute values ("1" | "0" | "true" | "false"). */
|
|
130
|
+
const ooxmlBoolSchema = z.enum([
|
|
131
|
+
"1",
|
|
132
|
+
"0",
|
|
133
|
+
"true",
|
|
134
|
+
"false"
|
|
135
|
+
]).transform((value) => value === "1" || value === "true");
|
|
136
|
+
/** Six-digit hex RGB value stored in `<a:srgbClr val="RRGGBB"/>`. */
|
|
137
|
+
const hexRgb6Schema = z.string().regex(hexRgbPattern);
|
|
138
|
+
/** Maximum logical pixel coordinate allowed by downstream builders (`[-1_000_000, 1_000_000]`). */
|
|
139
|
+
const MAXIMUM_COORDINATE_PX = 1e6;
|
|
140
|
+
/** Maximum positive signed 32-bit DrawingML EMU value (`ST_PositiveCoordinate32`). */
|
|
141
|
+
const MAXIMUM_WRITABLE_EMU = 2147483647;
|
|
142
|
+
/** Minimum signed 32-bit DrawingML EMU value. */
|
|
143
|
+
const MINIMUM_WRITABLE_INT32_EMU = -2147483648;
|
|
144
|
+
/** Maximum DrawingML stroke line width in EMU (`ST_LineWidth`). */
|
|
145
|
+
const MAXIMUM_LINE_WIDTH_EMU = 20116800;
|
|
146
|
+
function isWritablePixelCoordinateEmu(emu) {
|
|
147
|
+
const px = emuToPx(emu);
|
|
148
|
+
const roundtrip = Math.round(px * EMU_PER_PX);
|
|
149
|
+
return Number.isFinite(px) && Math.abs(px) <= 1e6 && Number.isSafeInteger(roundtrip);
|
|
150
|
+
}
|
|
151
|
+
function isWritableNonNegativeEmu(emu, maxEmu = MAXIMUM_WRITABLE_EMU) {
|
|
152
|
+
const roundtrip = Math.round(emuToPx(emu) * EMU_PER_PX);
|
|
153
|
+
return emu >= 0 && emu <= maxEmu && Number.isSafeInteger(roundtrip) && roundtrip >= 0 && roundtrip <= maxEmu;
|
|
154
|
+
}
|
|
155
|
+
function isWritablePositiveEmu(emu, maxEmu = MAXIMUM_WRITABLE_EMU) {
|
|
156
|
+
const roundtrip = Math.round(emuToPx(emu) * EMU_PER_PX);
|
|
157
|
+
return emu >= 1 && emu <= maxEmu && Number.isSafeInteger(roundtrip) && roundtrip >= 1 && roundtrip <= maxEmu;
|
|
158
|
+
}
|
|
159
|
+
/** DrawingML non-negative writable EMU extent (`0 .. 2_147_483_647`). */
|
|
160
|
+
const ooxmlWritableExtentEmuSchema = ooxmlNonNegativeIntSchema.refine((value) => isWritableNonNegativeEmu(value));
|
|
161
|
+
/** DrawingML positive writable EMU extent (`1 .. 2_147_483_647`). */
|
|
162
|
+
const ooxmlWritablePositiveExtentEmuSchema = ooxmlPositiveIntSchema.refine((value) => isWritablePositiveEmu(value));
|
|
163
|
+
/** DrawingML signed 32-bit EMU coordinate within `[-1_000_000, 1_000_000]` px after conversion. */
|
|
164
|
+
const ooxmlWritableInt32CoordEmuSchema = ooxmlIntSchema.refine((value) => value >= -2147483648 && value <= 2147483647 && isWritablePixelCoordinateEmu(value));
|
|
165
|
+
/** DrawingML `<a:ln w="...">` valid line width domain (`0 .. 20_116_800` EMU). */
|
|
166
|
+
const ooxmlLineWidthEmuSchema = ooxmlNonNegativeIntSchema.refine((value) => isWritableNonNegativeEmu(value, MAXIMUM_LINE_WIDTH_EMU));
|
|
167
|
+
/** DrawingML `<a:ln w="...">` strictly positive line width domain (`1 .. 20_116_800` EMU). */
|
|
168
|
+
const ooxmlPositiveLineWidthEmuSchema = ooxmlPositiveIntSchema.refine((value) => isWritablePositiveEmu(value, MAXIMUM_LINE_WIDTH_EMU));
|
|
169
|
+
/** `<a:off x="..." y="..."/>` fragment schema bounded to `[-1_000_000, 1_000_000]` px. */
|
|
170
|
+
const offsetEmuFragmentSchema = z.object({
|
|
171
|
+
x: ooxmlIntSchema.refine(isWritablePixelCoordinateEmu),
|
|
172
|
+
y: ooxmlIntSchema.refine(isWritablePixelCoordinateEmu)
|
|
173
|
+
});
|
|
174
|
+
/** `<a:ext cx="..." cy="..."/>` fragment schema bounded to `1 .. 2_147_483_647` EMU. */
|
|
175
|
+
const extentEmuFragmentSchema = z.object({
|
|
176
|
+
cx: ooxmlWritablePositiveExtentEmuSchema,
|
|
177
|
+
cy: ooxmlWritablePositiveExtentEmuSchema
|
|
178
|
+
});
|
|
179
|
+
/** `<a:ext cx="..." cy="..."/>` fragment schema allowing zero on one axis for 1D connectors, bounded to `0 .. 2_147_483_647` EMU. */
|
|
180
|
+
const nonNegativeExtentEmuFragmentSchema = z.object({
|
|
181
|
+
cx: ooxmlWritableExtentEmuSchema,
|
|
182
|
+
cy: ooxmlWritableExtentEmuSchema
|
|
183
|
+
});
|
|
184
|
+
/**
|
|
185
|
+
* Parses box inset/margin attributes (`lIns/tIns/rIns/bIns` or `marL/marT/marR/marB`) independently
|
|
186
|
+
* within DrawingML `0 .. 2_147_483_647` EMU bounds and enforces opposing-pair sums `<= 2_147_483_647` EMU.
|
|
187
|
+
*/
|
|
188
|
+
function readOoxmlBoxInsets(args) {
|
|
189
|
+
const { rawAttrs, attrNames, elementXpath, location, diagnostics } = args;
|
|
190
|
+
const parseEdge = (attrName) => {
|
|
191
|
+
const raw = rawAttrs[attrName];
|
|
192
|
+
if (raw === void 0) return void 0;
|
|
193
|
+
const parsed = ooxmlWritableExtentEmuSchema.safeParse(raw);
|
|
194
|
+
if (!parsed.success) {
|
|
195
|
+
pushInvalidXmlAttrDiagnostic(diagnostics, location, elementXpath, attrName, raw);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
return parsed.data;
|
|
199
|
+
};
|
|
200
|
+
let leftEmu = parseEdge(attrNames.left);
|
|
201
|
+
let rightEmu = parseEdge(attrNames.right);
|
|
202
|
+
let topEmu = parseEdge(attrNames.top);
|
|
203
|
+
let bottomEmu = parseEdge(attrNames.bottom);
|
|
204
|
+
if (leftEmu !== void 0 && rightEmu !== void 0 && leftEmu + rightEmu > 2147483647) {
|
|
205
|
+
diagnostics.push({
|
|
206
|
+
code: "invalid-xml-value",
|
|
207
|
+
category: "corrupt-input",
|
|
208
|
+
disposition: "recovered",
|
|
209
|
+
location: {
|
|
210
|
+
...location,
|
|
211
|
+
xpath: elementXpath
|
|
212
|
+
},
|
|
213
|
+
attributeOrElement: `${attrNames.left}+${attrNames.right}`,
|
|
214
|
+
rawValue: `${leftEmu}+${rightEmu}`
|
|
215
|
+
});
|
|
216
|
+
leftEmu = void 0;
|
|
217
|
+
rightEmu = void 0;
|
|
218
|
+
}
|
|
219
|
+
if (topEmu !== void 0 && bottomEmu !== void 0 && topEmu + bottomEmu > 2147483647) {
|
|
220
|
+
diagnostics.push({
|
|
221
|
+
code: "invalid-xml-value",
|
|
222
|
+
category: "corrupt-input",
|
|
223
|
+
disposition: "recovered",
|
|
224
|
+
location: {
|
|
225
|
+
...location,
|
|
226
|
+
xpath: elementXpath
|
|
227
|
+
},
|
|
228
|
+
attributeOrElement: `${attrNames.top}+${attrNames.bottom}`,
|
|
229
|
+
rawValue: `${topEmu}+${bottomEmu}`
|
|
230
|
+
});
|
|
231
|
+
topEmu = void 0;
|
|
232
|
+
bottomEmu = void 0;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
...topEmu !== void 0 && topEmu !== 0 ? { paddingTop: emuToPx(topEmu) } : {},
|
|
236
|
+
...rightEmu !== void 0 && rightEmu !== 0 ? { paddingRight: emuToPx(rightEmu) } : {},
|
|
237
|
+
...bottomEmu !== void 0 && bottomEmu !== 0 ? { paddingBottom: emuToPx(bottomEmu) } : {},
|
|
238
|
+
...leftEmu !== void 0 && leftEmu !== 0 ? { paddingLeft: emuToPx(leftEmu) } : {}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** `<a:xfrm rot="..." flipH="..." flipV="..."/>` attribute fragment schema. */
|
|
242
|
+
const transformAttributesFragmentSchema = z.object({
|
|
243
|
+
rot: ooxmlIntSchema.optional(),
|
|
244
|
+
flipH: ooxmlBoolSchema.optional(),
|
|
245
|
+
flipV: ooxmlBoolSchema.optional()
|
|
246
|
+
});
|
|
247
|
+
function isValidXml10CodePoint(codePoint) {
|
|
248
|
+
return codePoint === 9 || codePoint === 10 || codePoint === 13 || codePoint >= 32 && codePoint <= 55295 || codePoint >= 57344 && codePoint <= 65533 || codePoint >= 65536 && codePoint <= 1114111;
|
|
249
|
+
}
|
|
250
|
+
function isBulletSkipCodePoint(codePoint) {
|
|
251
|
+
return codePoint <= 32 || codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Normalizes `<a:buChar char="..."/>` to a single valid XML 1.0 Unicode code point,
|
|
255
|
+
* falling back to `"•"` when empty or malformed.
|
|
256
|
+
*/
|
|
257
|
+
function normalizeBulletCharacter(raw) {
|
|
258
|
+
if (raw !== void 0 && raw.length > 0) {
|
|
259
|
+
const first = raw.codePointAt(0);
|
|
260
|
+
if (first !== void 0 && String.fromCodePoint(first) === raw && isValidXml10CodePoint(first)) return {
|
|
261
|
+
character: raw,
|
|
262
|
+
recovered: false
|
|
263
|
+
};
|
|
264
|
+
for (const unit of raw) {
|
|
265
|
+
const cp = unit.codePointAt(0);
|
|
266
|
+
if (cp !== void 0 && isValidXml10CodePoint(cp) && !isBulletSkipCodePoint(cp)) return {
|
|
267
|
+
character: String.fromCodePoint(cp),
|
|
268
|
+
recovered: true
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
character: "•",
|
|
274
|
+
recovered: true
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
export { MAXIMUM_COORDINATE_PX, MAXIMUM_LINE_WIDTH_EMU, MAXIMUM_WRITABLE_EMU, MINIMUM_WRITABLE_INT32_EMU, extentEmuFragmentSchema, hexRgb6Schema, nonNegativeExtentEmuFragmentSchema, normalizeBulletCharacter, offsetEmuFragmentSchema, ooxmlAutoNumStartAtSchema, ooxmlBaselineShiftThousandthsSchema, ooxmlBoolSchema, ooxmlFontSizeCentipointsSchema, ooxmlIntSchema, ooxmlLetterSpacingCentipointsSchema, ooxmlLineSpacingPercentSchema, ooxmlLineSpacingPointsSchema, ooxmlLineWidthEmuSchema, ooxmlListLevelSchema, ooxmlNonNegativeIntSchema, ooxmlParagraphSpacingPointsSchema, ooxmlPositiveFixedAngleSchema, ooxmlPositiveIntSchema, ooxmlPositiveLineWidthEmuSchema, ooxmlWritableExtentEmuSchema, ooxmlWritableInt32CoordEmuSchema, ooxmlWritablePositiveExtentEmuSchema, readOoxmlBoxInsets, readOoxmlRunAttrStyles, transformAttributesFragmentSchema };
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { canonicalQName } from "./namespaces.js";
|
|
2
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
3
|
+
// ../import/dist/xml-reader.js
|
|
4
|
+
var _a;
|
|
5
|
+
/** Error raised when an XML part fails well-formedness or lacks a root element. */
|
|
6
|
+
var MalformedXmlPartError = class extends Error {
|
|
7
|
+
partPath;
|
|
8
|
+
detail;
|
|
9
|
+
constructor(partPath, detail) {
|
|
10
|
+
super(`Malformed XML in ${partPath}: ${detail}`);
|
|
11
|
+
this.name = "MalformedXmlPartError";
|
|
12
|
+
this.partPath = partPath;
|
|
13
|
+
this.detail = detail;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Parses an XML part with `@xmldom/xmldom` without emitting console noise. */
|
|
17
|
+
function parseXmlPart(partPath, xmlText) {
|
|
18
|
+
let parseFailure;
|
|
19
|
+
const parser = new DOMParser({ onError(level, message) {
|
|
20
|
+
if (level === "error" || level === "fatalError") parseFailure ??= message;
|
|
21
|
+
} });
|
|
22
|
+
let doc;
|
|
23
|
+
try {
|
|
24
|
+
doc = parser.parseFromString(xmlText, "application/xml");
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new MalformedXmlPartError(partPath, error instanceof Error ? error.message : String(error));
|
|
27
|
+
}
|
|
28
|
+
if (parseFailure !== void 0 || doc.documentElement === null) throw new MalformedXmlPartError(partPath, parseFailure ?? "Missing root element");
|
|
29
|
+
return doc.documentElement;
|
|
30
|
+
}
|
|
31
|
+
function attrKey(namespaceUri, localName) {
|
|
32
|
+
return `${namespaceUri}\u0000${localName}`;
|
|
33
|
+
}
|
|
34
|
+
function isIgnorableDeclarationAttr(namespaceUri, name, prefix, localName) {
|
|
35
|
+
if (namespaceUri === "http://www.w3.org/2000/xmlns/" || name === "xmlns" || prefix === "xmlns") return true;
|
|
36
|
+
return namespaceUri === "http://schemas.openxmlformats.org/markup-compatibility/2006" && localName === "Ignorable";
|
|
37
|
+
}
|
|
38
|
+
function isXmlElement(node) {
|
|
39
|
+
return node.nodeType === 1;
|
|
40
|
+
}
|
|
41
|
+
function elementChildrenOf(element) {
|
|
42
|
+
const result = [];
|
|
43
|
+
for (let child = element.firstChild; child !== null; child = child.nextSibling) if (isXmlElement(child)) result.push(child);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function childXpathFor(parentXpath, siblings, target) {
|
|
47
|
+
const ns = target.namespaceURI ?? "";
|
|
48
|
+
const local = target.localName ?? target.tagName;
|
|
49
|
+
const qname = canonicalQName(ns, local);
|
|
50
|
+
let total = 0;
|
|
51
|
+
let position = 0;
|
|
52
|
+
for (const sibling of siblings) {
|
|
53
|
+
const siblingNs = sibling.namespaceURI ?? "";
|
|
54
|
+
const siblingLocal = sibling.localName ?? sibling.tagName;
|
|
55
|
+
if (siblingNs === ns && siblingLocal === local) {
|
|
56
|
+
total += 1;
|
|
57
|
+
if (sibling === target) position = total;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return total > 1 ? `${parentXpath}/${qname}[${position}]` : `${parentXpath}/${qname}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Namespace-aware XML cursor that tracks consumed attributes and child elements so
|
|
64
|
+
* unconsumed OOXML constructs are surfaced with exact package part and XPath locations.
|
|
65
|
+
*/
|
|
66
|
+
var XmlElementCursor = class {
|
|
67
|
+
element;
|
|
68
|
+
part;
|
|
69
|
+
xpath;
|
|
70
|
+
namespaceUri;
|
|
71
|
+
localName;
|
|
72
|
+
#registry;
|
|
73
|
+
#consumedAttrs = /* @__PURE__ */ new Set();
|
|
74
|
+
#consumedChildren = /* @__PURE__ */ new Set();
|
|
75
|
+
#suppressUnconsumed = false;
|
|
76
|
+
#cachedChildren;
|
|
77
|
+
constructor(element, part, xpath, registry) {
|
|
78
|
+
this.element = element;
|
|
79
|
+
this.part = part;
|
|
80
|
+
this.xpath = xpath;
|
|
81
|
+
this.namespaceUri = element.namespaceURI ?? "";
|
|
82
|
+
this.localName = element.localName ?? element.tagName;
|
|
83
|
+
this.#registry = registry;
|
|
84
|
+
this.#registry.byElement.set(element, this);
|
|
85
|
+
this.#registry.ordered.push(this);
|
|
86
|
+
}
|
|
87
|
+
static createRoot(element, part, rootXpath) {
|
|
88
|
+
const registry = {
|
|
89
|
+
byElement: /* @__PURE__ */ new Map(),
|
|
90
|
+
ordered: []
|
|
91
|
+
};
|
|
92
|
+
const ns = element.namespaceURI ?? "";
|
|
93
|
+
const local = element.localName ?? element.tagName;
|
|
94
|
+
return new _a(element, part, rootXpath ?? `/${canonicalQName(ns, local)}`, registry);
|
|
95
|
+
}
|
|
96
|
+
get textContent() {
|
|
97
|
+
return this.element.textContent ?? "";
|
|
98
|
+
}
|
|
99
|
+
#elementChildren() {
|
|
100
|
+
this.#cachedChildren ??= elementChildrenOf(this.element);
|
|
101
|
+
return this.#cachedChildren;
|
|
102
|
+
}
|
|
103
|
+
#cursorFor(child) {
|
|
104
|
+
const existing = this.#registry.byElement.get(child);
|
|
105
|
+
if (existing !== void 0) return existing;
|
|
106
|
+
const xpath = childXpathFor(this.xpath, this.#elementChildren(), child);
|
|
107
|
+
return new _a(child, this.part, xpath, this.#registry);
|
|
108
|
+
}
|
|
109
|
+
/** Reads an attribute by `(namespaceUri, localName)` and marks it consumed if present. */
|
|
110
|
+
attr(localName, namespaceUri = "") {
|
|
111
|
+
const attributes = this.element.attributes;
|
|
112
|
+
for (let i = 0; i < attributes.length; i += 1) {
|
|
113
|
+
const attribute = attributes.item(i);
|
|
114
|
+
if (attribute === null) continue;
|
|
115
|
+
const attrNs = attribute.namespaceURI ?? "";
|
|
116
|
+
const attrLocal = attribute.localName ?? attribute.name;
|
|
117
|
+
if (attrNs === namespaceUri && attrLocal === localName) {
|
|
118
|
+
this.#consumedAttrs.add(attrKey(attrNs, attrLocal));
|
|
119
|
+
return attribute.value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Reads a set of allowed attributes into a plain record for Zod fragment parsing. */
|
|
124
|
+
attrsObject(allowed, namespaceUri = "") {
|
|
125
|
+
const result = {};
|
|
126
|
+
for (const localName of allowed) {
|
|
127
|
+
const value = this.attr(localName, namespaceUri);
|
|
128
|
+
if (value !== void 0) result[localName] = value;
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
/** Marks an attribute consumed even if its value is not retained. */
|
|
133
|
+
consumeAttr(localName, namespaceUri = "") {
|
|
134
|
+
return this.attr(localName, namespaceUri) !== void 0;
|
|
135
|
+
}
|
|
136
|
+
/** Returns the first matching child cursor and marks that child element consumed. */
|
|
137
|
+
child(namespaceUri, localName) {
|
|
138
|
+
for (const child of this.#elementChildren()) {
|
|
139
|
+
const childNs = child.namespaceURI ?? "";
|
|
140
|
+
const childLocal = child.localName ?? child.tagName;
|
|
141
|
+
if (childNs === namespaceUri && childLocal === localName) {
|
|
142
|
+
this.#consumedChildren.add(child);
|
|
143
|
+
return this.#cursorFor(child);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Returns all matching child cursors in document order and marks them consumed. */
|
|
148
|
+
children(namespaceUri, localName) {
|
|
149
|
+
const matches = [];
|
|
150
|
+
for (const child of this.#elementChildren()) {
|
|
151
|
+
const childNs = child.namespaceURI ?? "";
|
|
152
|
+
const childLocal = child.localName ?? child.tagName;
|
|
153
|
+
if (childNs === namespaceUri && childLocal === localName) {
|
|
154
|
+
this.#consumedChildren.add(child);
|
|
155
|
+
matches.push(this.#cursorFor(child));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return matches;
|
|
159
|
+
}
|
|
160
|
+
/** Returns matching direct element children without marking non-matching siblings consumed. */
|
|
161
|
+
matchingChildren(predicate) {
|
|
162
|
+
const matches = [];
|
|
163
|
+
for (const child of this.#elementChildren()) if (predicate(child)) {
|
|
164
|
+
this.#consumedChildren.add(child);
|
|
165
|
+
matches.push(this.#cursorFor(child));
|
|
166
|
+
}
|
|
167
|
+
return matches;
|
|
168
|
+
}
|
|
169
|
+
/** Returns all direct element children as cursors and marks them consumed by the caller. */
|
|
170
|
+
allElementChildren() {
|
|
171
|
+
return this.#elementChildren().map((child) => {
|
|
172
|
+
this.#consumedChildren.add(child);
|
|
173
|
+
return this.#cursorFor(child);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** Returns direct element children not yet consumed in document order and marks them consumed. */
|
|
177
|
+
remainingElementChildren() {
|
|
178
|
+
const remaining = [];
|
|
179
|
+
for (const child of this.#elementChildren()) {
|
|
180
|
+
if (this.#consumedChildren.has(child)) continue;
|
|
181
|
+
this.#consumedChildren.add(child);
|
|
182
|
+
remaining.push(this.#cursorFor(child));
|
|
183
|
+
}
|
|
184
|
+
return remaining;
|
|
185
|
+
}
|
|
186
|
+
/** Marks a specific child cursor consumed (useful after inspecting an element child). */
|
|
187
|
+
markChildConsumed(child) {
|
|
188
|
+
this.#consumedChildren.add(child.element);
|
|
189
|
+
}
|
|
190
|
+
/** Marks all direct element children consumed without descending into them. */
|
|
191
|
+
consumeChildrenWithoutVisiting() {
|
|
192
|
+
for (const child of this.#elementChildren()) this.#consumedChildren.add(child);
|
|
193
|
+
}
|
|
194
|
+
/** Suppresses unconsumed-xml diagnostics for this cursor and its remaining children (used when the subtree is already reported as omitted). */
|
|
195
|
+
suppressUnconsumed() {
|
|
196
|
+
this.#suppressUnconsumed = true;
|
|
197
|
+
this.consumeChildrenWithoutVisiting();
|
|
198
|
+
}
|
|
199
|
+
/** Marks an empty schema-boilerplate child element consumed only when it has no attributes or element children. */
|
|
200
|
+
ignoreEmptyChild(namespaceUri, localName) {
|
|
201
|
+
for (const child of this.#elementChildren()) {
|
|
202
|
+
const childNs = child.namespaceURI ?? "";
|
|
203
|
+
const childLocal = child.localName ?? child.tagName;
|
|
204
|
+
if (childNs !== namespaceUri || childLocal !== localName) continue;
|
|
205
|
+
if (hasNonIgnorableAttributes(child) || elementChildrenOf(child).length > 0) {
|
|
206
|
+
this.#consumedChildren.add(child);
|
|
207
|
+
this.#cursorFor(child);
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
this.#consumedChildren.add(child);
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
/** Collects unconsumed attributes and direct unconsumed child elements across all visited cursors. */
|
|
216
|
+
collectUnconsumed() {
|
|
217
|
+
const items = [];
|
|
218
|
+
for (const cursor of this.#registry.ordered) {
|
|
219
|
+
if (cursor.#suppressUnconsumed) continue;
|
|
220
|
+
const attributes = cursor.element.attributes;
|
|
221
|
+
for (let i = 0; i < attributes.length; i += 1) {
|
|
222
|
+
const attribute = attributes.item(i);
|
|
223
|
+
if (attribute === null) continue;
|
|
224
|
+
const attrNs = attribute.namespaceURI ?? "";
|
|
225
|
+
const attrLocal = attribute.localName ?? attribute.name;
|
|
226
|
+
if (isIgnorableDeclarationAttr(attrNs, attribute.name, attribute.prefix, attrLocal)) continue;
|
|
227
|
+
if (!cursor.#consumedAttrs.has(attrKey(attrNs, attrLocal))) items.push({
|
|
228
|
+
kind: "attribute",
|
|
229
|
+
location: {
|
|
230
|
+
part: cursor.part,
|
|
231
|
+
xpath: `${cursor.xpath}/@${canonicalQName(attrNs, attrLocal)}`
|
|
232
|
+
},
|
|
233
|
+
namespaceUri: attrNs,
|
|
234
|
+
localName: attrLocal
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const siblings = cursor.#elementChildren();
|
|
238
|
+
for (const child of siblings) if (!cursor.#consumedChildren.has(child)) {
|
|
239
|
+
const childNs = child.namespaceURI ?? "";
|
|
240
|
+
const childLocal = child.localName ?? child.tagName;
|
|
241
|
+
items.push({
|
|
242
|
+
kind: "element",
|
|
243
|
+
location: {
|
|
244
|
+
part: cursor.part,
|
|
245
|
+
xpath: childXpathFor(cursor.xpath, siblings, child)
|
|
246
|
+
},
|
|
247
|
+
namespaceUri: childNs,
|
|
248
|
+
localName: childLocal
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return items;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
_a = XmlElementCursor;
|
|
256
|
+
function hasNonIgnorableAttributes(element) {
|
|
257
|
+
const attributes = element.attributes;
|
|
258
|
+
for (let i = 0; i < attributes.length; i += 1) {
|
|
259
|
+
const attribute = attributes.item(i);
|
|
260
|
+
if (attribute === null) continue;
|
|
261
|
+
const attrNs = attribute.namespaceURI ?? "";
|
|
262
|
+
const attrLocal = attribute.localName ?? attribute.name;
|
|
263
|
+
if (!isIgnorableDeclarationAttr(attrNs, attribute.name, attribute.prefix, attrLocal)) return true;
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
export { MalformedXmlPartError, XmlElementCursor, parseXmlPart };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { $ as RegisteredCapabilityModule, U as EmitResult, a as CommonNode, et as Resolution, kt as EmitOptions } from "./capability-BbKW9w4O.js";
|
|
2
|
+
import "./index-cK2KtukZ.js";
|
|
3
|
+
import "./build-zrZuX4fK.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* Emits a PPTX archive and BuildReport from an existing Resolution without re-resolving the document.
|
|
7
|
+
*/
|
|
8
|
+
declare function emit(resolution: Resolution, options?: EmitOptions): EmitResult;
|
|
9
|
+
type CodegenTarget = "vanilla" | "react";
|
|
10
|
+
/** Supported author source generation syntax targets. */
|
|
11
|
+
declare const codegenTargetSchema: z.ZodType<CodegenTarget>;
|
|
12
|
+
type CodegenEntryName<T extends CodegenTarget = CodegenTarget> = T extends "vanilla" ? "deck.ts" : T extends "react" ? "deck.tsx" : "deck.ts" | "deck.tsx";
|
|
13
|
+
type CodegenOptions<T extends CodegenTarget = CodegenTarget> = {
|
|
14
|
+
readonly target: T;
|
|
15
|
+
};
|
|
16
|
+
/** Options controlling `codegen` target syntax output. */
|
|
17
|
+
declare const codegenOptionsSchema: z.ZodType<CodegenOptions>;
|
|
18
|
+
type CodegenFileContent = string | Uint8Array;
|
|
19
|
+
type CodegenResult<T extends CodegenTarget = CodegenTarget> = {
|
|
20
|
+
readonly target: T;
|
|
21
|
+
readonly entry: CodegenEntryName<T>;
|
|
22
|
+
readonly files: Readonly<Record<string, CodegenFileContent>>;
|
|
23
|
+
};
|
|
24
|
+
type CodegenDiagnosticCode = "invalid-document" | "invalid-options" | "unsupported-declaration" | "unsupported-slide-property" | "unexpressible-value";
|
|
25
|
+
declare const codegenDiagnosticCodeSchema: z.ZodType<CodegenDiagnosticCode>;
|
|
26
|
+
type CodegenDiagnostic = {
|
|
27
|
+
readonly code: "invalid-document";
|
|
28
|
+
readonly path: string;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
readonly field?: string | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
readonly code: "invalid-options";
|
|
33
|
+
readonly path: string;
|
|
34
|
+
readonly message: string;
|
|
35
|
+
readonly field?: string | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
readonly code: "unsupported-declaration";
|
|
38
|
+
readonly path: string;
|
|
39
|
+
readonly message: string;
|
|
40
|
+
readonly field?: string | undefined;
|
|
41
|
+
readonly declaration: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly code: "unsupported-slide-property";
|
|
44
|
+
readonly path: string;
|
|
45
|
+
readonly message: string;
|
|
46
|
+
readonly field: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly code: "unexpressible-value";
|
|
49
|
+
readonly path: string;
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly field?: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
declare const codegenDiagnosticSchema: z.ZodType<CodegenDiagnostic>;
|
|
54
|
+
/** Structured error thrown when an editable document cannot be expressed in generated source. */
|
|
55
|
+
declare class CodegenError extends Error {
|
|
56
|
+
readonly diagnostics: readonly CodegenDiagnostic[];
|
|
57
|
+
constructor(diagnostics: readonly CodegenDiagnostic[]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a synchronous source code generator wired with the provided capability modules.
|
|
61
|
+
*/
|
|
62
|
+
declare function createCodegen(capabilities: readonly RegisteredCapabilityModule[]): <T extends CodegenTarget>(document: CommonNode, options: CodegenOptions<T>) => CodegenResult<T>;
|
|
63
|
+
export { CodegenError as a, CodegenResult as c, codegenDiagnosticSchema as d, codegenOptionsSchema as f, CodegenEntryName as i, CodegenTarget as l, emit as m, CodegenDiagnostic as n, CodegenFileContent as o, codegenTargetSchema as p, CodegenDiagnosticCode as r, CodegenOptions as s, createCodegen as t, codegenDiagnosticCodeSchema as u };
|