ooxml.js 1.3.0 → 2.0.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/README.md +7 -4
- package/dist/index.cjs +1336 -128
- package/dist/index.d.cts +280 -131
- package/dist/index.d.ts +280 -131
- package/dist/index.js +1308 -116
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,14 +27,14 @@ const XmlPiSchema = z.object({
|
|
|
27
27
|
target: z.string(),
|
|
28
28
|
content: z.string()
|
|
29
29
|
});
|
|
30
|
-
function isRecord$
|
|
30
|
+
function isRecord$2(value) {
|
|
31
31
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
32
|
}
|
|
33
33
|
function isAttribute(value) {
|
|
34
|
-
return isRecord$
|
|
34
|
+
return isRecord$2(value) && typeof value.name === "string" && typeof value.value === "string";
|
|
35
35
|
}
|
|
36
36
|
function isXmlNode(value) {
|
|
37
|
-
if (!isRecord$
|
|
37
|
+
if (!isRecord$2(value)) return false;
|
|
38
38
|
const t = value.type;
|
|
39
39
|
if (t === "text" || t === "cdata" || t === "comment") return typeof value.value === "string";
|
|
40
40
|
if (t === "declaration") return Array.isArray(value.attributes) && value.attributes.every(isAttribute);
|
|
@@ -129,7 +129,7 @@ const PARSER = new XMLParser({
|
|
|
129
129
|
function parseXml(xml) {
|
|
130
130
|
return parseNodes(PARSER.parse(xml));
|
|
131
131
|
}
|
|
132
|
-
function isRecord(value) {
|
|
132
|
+
function isRecord$1(value) {
|
|
133
133
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
134
134
|
}
|
|
135
135
|
function isUnknownArray$1(value) {
|
|
@@ -144,7 +144,7 @@ function parseNodes(raw) {
|
|
|
144
144
|
return raw.map(parseNode);
|
|
145
145
|
}
|
|
146
146
|
function parseNode(raw) {
|
|
147
|
-
if (!isRecord(raw)) throw new Error("fast-xml-parser node was not an object");
|
|
147
|
+
if (!isRecord$1(raw)) throw new Error("fast-xml-parser node was not an object");
|
|
148
148
|
let tagKey;
|
|
149
149
|
for (const key of Object.keys(raw)) if (key !== ":@") {
|
|
150
150
|
if (tagKey !== void 0) throw new Error("XML node had multiple tag keys");
|
|
@@ -182,7 +182,7 @@ function parseNode(raw) {
|
|
|
182
182
|
}
|
|
183
183
|
function parseAttributes(raw) {
|
|
184
184
|
if (raw === void 0) return [];
|
|
185
|
-
if (!isRecord(raw)) throw new Error("XML attributes were not an object");
|
|
185
|
+
if (!isRecord$1(raw)) throw new Error("XML attributes were not an object");
|
|
186
186
|
const attrs = [];
|
|
187
187
|
for (const key of Object.keys(raw)) {
|
|
188
188
|
if (!key.startsWith("@_")) throw new Error(`unexpected attribute key without @_ prefix: ${key}`);
|
|
@@ -196,7 +196,7 @@ function parseAttributes(raw) {
|
|
|
196
196
|
function scalarText(raw) {
|
|
197
197
|
if (!isUnknownArray$1(raw) || raw.length === 0) throw new Error("expected a scalar-text wrapper array");
|
|
198
198
|
const first = raw[0];
|
|
199
|
-
if (!isRecord(first)) throw new Error("scalar-text wrapper was not an object");
|
|
199
|
+
if (!isRecord$1(first)) throw new Error("scalar-text wrapper was not an object");
|
|
200
200
|
return asString(first["#text"]);
|
|
201
201
|
}
|
|
202
202
|
//#endregion
|
|
@@ -533,27 +533,659 @@ function encodeCompactPackage(cpkg) {
|
|
|
533
533
|
return z.encode(compactPackageCodec, cpkg);
|
|
534
534
|
}
|
|
535
535
|
//#endregion
|
|
536
|
-
//#region src/typed/
|
|
537
|
-
const
|
|
536
|
+
//#region src/typed/shared/geometry.ts
|
|
537
|
+
const BoxSchema = z.object({
|
|
538
|
+
xPt: z.number(),
|
|
539
|
+
yPt: z.number(),
|
|
540
|
+
widthPt: z.number().nonnegative(),
|
|
541
|
+
heightPt: z.number().nonnegative()
|
|
542
|
+
});
|
|
543
|
+
const PageSizeSchema = z.object({
|
|
544
|
+
widthPt: z.number().positive(),
|
|
545
|
+
heightPt: z.number().positive()
|
|
546
|
+
});
|
|
547
|
+
const MarginsSchema = z.object({
|
|
548
|
+
topPt: z.number().nonnegative(),
|
|
549
|
+
rightPt: z.number().nonnegative(),
|
|
550
|
+
bottomPt: z.number().nonnegative(),
|
|
551
|
+
leftPt: z.number().nonnegative()
|
|
552
|
+
});
|
|
553
|
+
const PAGE_SIZE_LETTER = {
|
|
554
|
+
widthPt: 612,
|
|
555
|
+
heightPt: 792
|
|
556
|
+
};
|
|
557
|
+
const PAGE_SIZE_A4 = {
|
|
558
|
+
widthPt: 595.28,
|
|
559
|
+
heightPt: 841.89
|
|
560
|
+
};
|
|
561
|
+
const SLIDE_SIZE_WIDESCREEN = {
|
|
562
|
+
widthPt: 960,
|
|
563
|
+
heightPt: 540
|
|
564
|
+
};
|
|
565
|
+
const SLIDE_SIZE_STANDARD = {
|
|
566
|
+
widthPt: 720,
|
|
567
|
+
heightPt: 540
|
|
568
|
+
};
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/typed/shared/color.ts
|
|
571
|
+
const ColorSchema = z.object({
|
|
572
|
+
r: z.number().min(0).max(1),
|
|
573
|
+
g: z.number().min(0).max(1),
|
|
574
|
+
b: z.number().min(0).max(1)
|
|
575
|
+
});
|
|
576
|
+
const COLOR_BLACK = {
|
|
577
|
+
r: 0,
|
|
578
|
+
g: 0,
|
|
579
|
+
b: 0
|
|
580
|
+
};
|
|
581
|
+
const HEX_COLOR_PATTERN = /^#?([0-9a-fA-F]{6})$/;
|
|
582
|
+
const HEX_BYTE_MAX = 255;
|
|
583
|
+
function rgbHexToColor(hex) {
|
|
584
|
+
const match = HEX_COLOR_PATTERN.exec(hex);
|
|
585
|
+
if (match === null) throw new Error(`not a 6-digit hex colour: ${hex}`);
|
|
586
|
+
const digits = match[1];
|
|
587
|
+
if (digits === void 0) throw new Error(`not a 6-digit hex colour: ${hex}`);
|
|
588
|
+
const r = Number.parseInt(digits.slice(0, 2), 16);
|
|
589
|
+
const g = Number.parseInt(digits.slice(2, 4), 16);
|
|
590
|
+
const b = Number.parseInt(digits.slice(4, 6), 16);
|
|
591
|
+
return {
|
|
592
|
+
r: r / HEX_BYTE_MAX,
|
|
593
|
+
g: g / HEX_BYTE_MAX,
|
|
594
|
+
b: b / HEX_BYTE_MAX
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function toHexByte(component) {
|
|
598
|
+
return Math.round(component * HEX_BYTE_MAX).toString(16).padStart(2, "0");
|
|
599
|
+
}
|
|
600
|
+
function colorToRgbHex(color) {
|
|
601
|
+
return `${toHexByte(color.r)}${toHexByte(color.g)}${toHexByte(color.b)}`;
|
|
602
|
+
}
|
|
603
|
+
const OOXML_PERCENT_SCALE = 1e5;
|
|
604
|
+
function clamp01(x) {
|
|
605
|
+
return Math.max(0, Math.min(1, x));
|
|
606
|
+
}
|
|
607
|
+
function srgbToLinear(c) {
|
|
608
|
+
return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
609
|
+
}
|
|
610
|
+
function linearToSrgb(c) {
|
|
611
|
+
return c <= .0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - .055;
|
|
612
|
+
}
|
|
613
|
+
function applyShadeOrTint(color, kind, value) {
|
|
614
|
+
const pct = value / OOXML_PERCENT_SCALE;
|
|
615
|
+
const transform = kind === "shade" ? (linear) => linear * pct : (linear) => 1 - (1 - linear) * pct;
|
|
616
|
+
return {
|
|
617
|
+
r: clamp01(linearToSrgb(transform(srgbToLinear(color.r)))),
|
|
618
|
+
g: clamp01(linearToSrgb(transform(srgbToLinear(color.g)))),
|
|
619
|
+
b: clamp01(linearToSrgb(transform(srgbToLinear(color.b))))
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function rgbToHsl(color) {
|
|
623
|
+
const { r, g, b } = color;
|
|
624
|
+
const max = Math.max(r, g, b);
|
|
625
|
+
const min = Math.min(r, g, b);
|
|
626
|
+
const l = (max + min) / 2;
|
|
627
|
+
if (max === min) return {
|
|
628
|
+
h: 0,
|
|
629
|
+
s: 0,
|
|
630
|
+
l
|
|
631
|
+
};
|
|
632
|
+
const d = max - min;
|
|
633
|
+
const s = l > .5 ? d / (2 - max - min) : d / (max + min);
|
|
634
|
+
let h;
|
|
635
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
636
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
637
|
+
else h = (r - g) / d + 4;
|
|
638
|
+
return {
|
|
639
|
+
h: h * 60,
|
|
640
|
+
s,
|
|
641
|
+
l
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function hueToRgbComponent(p, q, hue) {
|
|
645
|
+
let t = hue;
|
|
646
|
+
if (t < 0) t += 1;
|
|
647
|
+
if (t > 1) t -= 1;
|
|
648
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
649
|
+
if (t < 1 / 2) return q;
|
|
650
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
651
|
+
return p;
|
|
652
|
+
}
|
|
653
|
+
function hslToRgb(hsl) {
|
|
654
|
+
const { h, s, l } = hsl;
|
|
655
|
+
if (s === 0) return {
|
|
656
|
+
r: l,
|
|
657
|
+
g: l,
|
|
658
|
+
b: l
|
|
659
|
+
};
|
|
660
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
661
|
+
const p = 2 * l - q;
|
|
662
|
+
const hk = h / 360;
|
|
663
|
+
return {
|
|
664
|
+
r: clamp01(hueToRgbComponent(p, q, hk + 1 / 3)),
|
|
665
|
+
g: clamp01(hueToRgbComponent(p, q, hk)),
|
|
666
|
+
b: clamp01(hueToRgbComponent(p, q, hk - 1 / 3))
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function applyLumModOrOff(color, kind, value) {
|
|
670
|
+
const hsl = rgbToHsl(color);
|
|
671
|
+
const pct = value / OOXML_PERCENT_SCALE;
|
|
672
|
+
const l = clamp01(kind === "lumMod" ? hsl.l * pct : hsl.l + pct);
|
|
673
|
+
return hslToRgb({
|
|
674
|
+
...hsl,
|
|
675
|
+
l
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
function applyColorTransforms(base, transforms) {
|
|
679
|
+
let color = base;
|
|
680
|
+
for (const t of transforms) if (t.kind === "shade" || t.kind === "tint") color = applyShadeOrTint(color, t.kind, t.value);
|
|
681
|
+
for (const t of transforms) if (t.kind === "lumMod" || t.kind === "lumOff") color = applyLumModOrOff(color, t.kind, t.value);
|
|
682
|
+
return color;
|
|
683
|
+
}
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/typed/shared/style.ts
|
|
686
|
+
const AlignmentSchema = z.enum([
|
|
687
|
+
"left",
|
|
688
|
+
"center",
|
|
689
|
+
"right",
|
|
690
|
+
"justify"
|
|
691
|
+
]);
|
|
692
|
+
//#endregion
|
|
693
|
+
//#region src/typed/shared/metadata.ts
|
|
694
|
+
const DocumentMetadataSchema = z.object({
|
|
695
|
+
title: z.string().optional(),
|
|
696
|
+
author: z.string().optional(),
|
|
697
|
+
subject: z.string().optional(),
|
|
698
|
+
keywords: z.array(z.string()).optional(),
|
|
699
|
+
creator: z.string().optional(),
|
|
700
|
+
createdIso: z.string().optional(),
|
|
701
|
+
modifiedIso: z.string().optional()
|
|
702
|
+
});
|
|
703
|
+
const CORE_PROPERTIES_PATH = "docProps/core.xml";
|
|
704
|
+
const APP_PROPERTIES_PATH = "docProps/app.xml";
|
|
705
|
+
function firstElementText(root, tag) {
|
|
706
|
+
if (root === void 0) return;
|
|
707
|
+
const element = childrenWithTag(root, tag)[0];
|
|
708
|
+
if (element === void 0) return;
|
|
709
|
+
const text = textContent(element);
|
|
710
|
+
return text.length > 0 ? text : void 0;
|
|
711
|
+
}
|
|
712
|
+
function readKeywords(core) {
|
|
713
|
+
const raw = firstElementText(core, "cp:keywords");
|
|
714
|
+
if (raw === void 0) return;
|
|
715
|
+
const parts = raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
716
|
+
return parts.length > 0 ? parts : void 0;
|
|
717
|
+
}
|
|
718
|
+
function readCoreProperties(pkg) {
|
|
719
|
+
const core = rootElement(pkg.parts[CORE_PROPERTIES_PATH]);
|
|
720
|
+
const app = rootElement(pkg.parts[APP_PROPERTIES_PATH]);
|
|
721
|
+
return {
|
|
722
|
+
title: firstElementText(core, "dc:title"),
|
|
723
|
+
author: firstElementText(core, "dc:creator"),
|
|
724
|
+
subject: firstElementText(core, "dc:subject"),
|
|
725
|
+
keywords: readKeywords(core),
|
|
726
|
+
creator: firstElementText(app, "Application"),
|
|
727
|
+
createdIso: firstElementText(core, "dcterms:created"),
|
|
728
|
+
modifiedIso: firstElementText(core, "dcterms:modified")
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/typed/shared/content.ts
|
|
733
|
+
const ContentRunSchema = z.object({
|
|
538
734
|
text: z.string(),
|
|
539
735
|
bold: z.boolean().optional(),
|
|
540
|
-
italic: z.boolean().optional()
|
|
736
|
+
italic: z.boolean().optional(),
|
|
737
|
+
underline: z.boolean().optional(),
|
|
738
|
+
strike: z.boolean().optional(),
|
|
739
|
+
fontFamily: z.string().optional(),
|
|
740
|
+
sizePt: z.number().positive().optional(),
|
|
741
|
+
color: ColorSchema.optional(),
|
|
742
|
+
hyperlink: z.string().optional()
|
|
541
743
|
});
|
|
542
|
-
const
|
|
744
|
+
const ContentListMembershipSchema = z.object({
|
|
543
745
|
numId: z.string(),
|
|
544
|
-
level: z.number()
|
|
746
|
+
level: z.number().int().nonnegative()
|
|
545
747
|
});
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
|
|
748
|
+
const ContentParagraphSchema = z.object({
|
|
749
|
+
kind: z.literal("paragraph"),
|
|
750
|
+
runs: z.array(ContentRunSchema),
|
|
751
|
+
styleId: z.string().optional(),
|
|
752
|
+
alignment: AlignmentSchema.optional(),
|
|
753
|
+
list: ContentListMembershipSchema.optional(),
|
|
754
|
+
spacingBeforePt: z.number().optional(),
|
|
755
|
+
spacingAfterPt: z.number().optional(),
|
|
756
|
+
lineSpacing: z.number().positive().optional(),
|
|
757
|
+
indentLeftPt: z.number().optional(),
|
|
758
|
+
indentFirstLinePt: z.number().optional()
|
|
549
759
|
});
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
760
|
+
const ContentImageBlockSchema = z.object({
|
|
761
|
+
kind: z.literal("image"),
|
|
762
|
+
format: z.enum(["png", "jpeg"]),
|
|
763
|
+
base64: z.string(),
|
|
764
|
+
widthPt: z.number().positive(),
|
|
765
|
+
heightPt: z.number().positive(),
|
|
766
|
+
altText: z.string().optional()
|
|
767
|
+
});
|
|
768
|
+
const ContentPageBreakSchema = z.object({ kind: z.literal("pageBreak") });
|
|
769
|
+
function isRecord(value) {
|
|
770
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
771
|
+
}
|
|
772
|
+
function isContentRun(value) {
|
|
773
|
+
return isRecord(value) && typeof value.text === "string";
|
|
774
|
+
}
|
|
775
|
+
function isContentTableCell(value) {
|
|
776
|
+
return isRecord(value) && Array.isArray(value.blocks) && value.blocks.every(isContentBlock);
|
|
777
|
+
}
|
|
778
|
+
function isContentTableRow(value) {
|
|
779
|
+
return isRecord(value) && Array.isArray(value.cells) && value.cells.every(isContentTableCell) && (value.heightPt === void 0 || typeof value.heightPt === "number");
|
|
780
|
+
}
|
|
781
|
+
function isContentBlock(value) {
|
|
782
|
+
if (!isRecord(value)) return false;
|
|
783
|
+
const kind = value.kind;
|
|
784
|
+
if (kind === "paragraph") return Array.isArray(value.runs) && value.runs.every(isContentRun);
|
|
785
|
+
if (kind === "image") return (value.format === "png" || value.format === "jpeg") && typeof value.base64 === "string" && typeof value.widthPt === "number" && typeof value.heightPt === "number";
|
|
786
|
+
if (kind === "pageBreak") return true;
|
|
787
|
+
if (kind === "table") return Array.isArray(value.rows) && value.rows.every(isContentTableRow) && Array.isArray(value.columnWidthsPt) && value.columnWidthsPt.every((w) => typeof w === "number");
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
const ContentBlockSchema = z.custom(isContentBlock);
|
|
791
|
+
const ContentTableCellSchema = z.object({
|
|
792
|
+
blocks: z.array(ContentBlockSchema),
|
|
793
|
+
colSpan: z.number().int().positive().optional(),
|
|
794
|
+
rowSpan: z.number().int().positive().optional(),
|
|
795
|
+
background: ColorSchema.optional()
|
|
796
|
+
});
|
|
797
|
+
const ContentTableRowSchema = z.object({
|
|
798
|
+
cells: z.array(ContentTableCellSchema),
|
|
799
|
+
heightPt: z.number().positive().optional()
|
|
800
|
+
});
|
|
801
|
+
const ContentTableSchema = z.object({
|
|
802
|
+
kind: z.literal("table"),
|
|
803
|
+
rows: z.array(ContentTableRowSchema),
|
|
804
|
+
columnWidthsPt: z.array(z.number().positive())
|
|
556
805
|
});
|
|
806
|
+
const ContentSectionSchema = z.object({
|
|
807
|
+
pageSize: PageSizeSchema,
|
|
808
|
+
margins: MarginsSchema,
|
|
809
|
+
blocks: z.array(ContentBlockSchema)
|
|
810
|
+
});
|
|
811
|
+
const ContentShapeSchema = z.object({
|
|
812
|
+
name: z.string().optional(),
|
|
813
|
+
frame: BoxSchema,
|
|
814
|
+
rotationDeg: z.number().optional(),
|
|
815
|
+
insetLeftPt: z.number().nonnegative(),
|
|
816
|
+
insetTopPt: z.number().nonnegative(),
|
|
817
|
+
insetRightPt: z.number().nonnegative(),
|
|
818
|
+
insetBottomPt: z.number().nonnegative(),
|
|
819
|
+
fontScale: z.number().positive().optional(),
|
|
820
|
+
lineSpacingReduction: z.number().nonnegative().optional(),
|
|
821
|
+
blocks: z.array(ContentBlockSchema)
|
|
822
|
+
});
|
|
823
|
+
const ContentSlideSchema = z.object({
|
|
824
|
+
size: PageSizeSchema,
|
|
825
|
+
shapes: z.array(ContentShapeSchema),
|
|
826
|
+
notes: z.string()
|
|
827
|
+
});
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/image/sniff.ts
|
|
830
|
+
const PNG_SIGNATURE = [
|
|
831
|
+
137,
|
|
832
|
+
80,
|
|
833
|
+
78,
|
|
834
|
+
71,
|
|
835
|
+
13,
|
|
836
|
+
10,
|
|
837
|
+
26,
|
|
838
|
+
10
|
|
839
|
+
];
|
|
840
|
+
const JPEG_SIGNATURE = [
|
|
841
|
+
255,
|
|
842
|
+
216,
|
|
843
|
+
255
|
|
844
|
+
];
|
|
845
|
+
function startsWith(bytes, signature) {
|
|
846
|
+
if (bytes.length < signature.length) return false;
|
|
847
|
+
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
function sniffImageFormat(bytes) {
|
|
851
|
+
if (startsWith(bytes, PNG_SIGNATURE)) return "png";
|
|
852
|
+
if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
|
|
853
|
+
}
|
|
854
|
+
const EMU_PER_POINT = 914400 / 72;
|
|
855
|
+
function emuToPt(emu) {
|
|
856
|
+
return emu / EMU_PER_POINT;
|
|
857
|
+
}
|
|
858
|
+
function twipsToPt(twips) {
|
|
859
|
+
return twips / 20;
|
|
860
|
+
}
|
|
861
|
+
function halfPointsToPt(halfPoints) {
|
|
862
|
+
return halfPoints / 2;
|
|
863
|
+
}
|
|
864
|
+
function drawingMlFontSizeToPt(hundredths) {
|
|
865
|
+
return hundredths / 100;
|
|
866
|
+
}
|
|
867
|
+
function lineUnitsToMultiplier(lineUnits) {
|
|
868
|
+
return lineUnits / 240;
|
|
869
|
+
}
|
|
870
|
+
//#endregion
|
|
871
|
+
//#region src/typed/shared/drawingml.ts
|
|
872
|
+
const ROTATION_UNITS_PER_DEGREE = 6e4;
|
|
873
|
+
function readXfrm(xfrm) {
|
|
874
|
+
if (xfrm === void 0) return;
|
|
875
|
+
const off = childrenWithTag(xfrm, "a:off")[0];
|
|
876
|
+
const ext = childrenWithTag(xfrm, "a:ext")[0];
|
|
877
|
+
if (off === void 0 || ext === void 0) return;
|
|
878
|
+
const x = attr(off, "x");
|
|
879
|
+
const y = attr(off, "y");
|
|
880
|
+
const cx = attr(ext, "cx");
|
|
881
|
+
const cy = attr(ext, "cy");
|
|
882
|
+
if (x === void 0 || y === void 0 || cx === void 0 || cy === void 0) return;
|
|
883
|
+
const rot = attr(xfrm, "rot");
|
|
884
|
+
return {
|
|
885
|
+
xPt: emuToPt(Number(x)),
|
|
886
|
+
yPt: emuToPt(Number(y)),
|
|
887
|
+
widthPt: emuToPt(Number(cx)),
|
|
888
|
+
heightPt: emuToPt(Number(cy)),
|
|
889
|
+
rotationDeg: rot === void 0 ? 0 : Number(rot) / ROTATION_UNITS_PER_DEGREE,
|
|
890
|
+
flipH: attr(xfrm, "flipH") === "1",
|
|
891
|
+
flipV: attr(xfrm, "flipV") === "1"
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
const CLR_SCHEME_SLOTS = [
|
|
895
|
+
"dk1",
|
|
896
|
+
"lt1",
|
|
897
|
+
"dk2",
|
|
898
|
+
"lt2",
|
|
899
|
+
"accent1",
|
|
900
|
+
"accent2",
|
|
901
|
+
"accent3",
|
|
902
|
+
"accent4",
|
|
903
|
+
"accent5",
|
|
904
|
+
"accent6",
|
|
905
|
+
"hlink",
|
|
906
|
+
"folHlink"
|
|
907
|
+
];
|
|
908
|
+
function readThemeSlotColor(colorEl) {
|
|
909
|
+
if (colorEl.tag === "a:srgbClr") {
|
|
910
|
+
const val = attr(colorEl, "val");
|
|
911
|
+
return val === void 0 ? void 0 : rgbHexToColor(val);
|
|
912
|
+
}
|
|
913
|
+
if (colorEl.tag === "a:sysClr") {
|
|
914
|
+
const lastClr = attr(colorEl, "lastClr");
|
|
915
|
+
if (lastClr !== void 0) return rgbHexToColor(lastClr);
|
|
916
|
+
return attr(colorEl, "val") === "window" ? {
|
|
917
|
+
r: 1,
|
|
918
|
+
g: 1,
|
|
919
|
+
b: 1
|
|
920
|
+
} : {
|
|
921
|
+
r: 0,
|
|
922
|
+
g: 0,
|
|
923
|
+
b: 0
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
function readClrScheme(clrSchemeEl) {
|
|
928
|
+
const map = /* @__PURE__ */ new Map();
|
|
929
|
+
for (const slot of CLR_SCHEME_SLOTS) {
|
|
930
|
+
const wrapper = childrenWithTag(clrSchemeEl, `a:${slot}`)[0];
|
|
931
|
+
if (wrapper === void 0) continue;
|
|
932
|
+
const colorEl = wrapper.children.find((c) => c.type === "element");
|
|
933
|
+
if (colorEl === void 0) continue;
|
|
934
|
+
const color = readThemeSlotColor(colorEl);
|
|
935
|
+
if (color !== void 0) map.set(slot, color);
|
|
936
|
+
}
|
|
937
|
+
return map;
|
|
938
|
+
}
|
|
939
|
+
function readSchemeFont(fontSchemeEl, tag) {
|
|
940
|
+
if (fontSchemeEl === void 0) return;
|
|
941
|
+
const fontEl = childrenWithTag(fontSchemeEl, tag)[0];
|
|
942
|
+
const latin = fontEl === void 0 ? void 0 : childrenWithTag(fontEl, "a:latin")[0];
|
|
943
|
+
return latin === void 0 ? void 0 : attr(latin, "typeface");
|
|
944
|
+
}
|
|
945
|
+
const DEFAULT_THEME_FONT = "Calibri";
|
|
946
|
+
const EMPTY_THEME = {
|
|
947
|
+
colorScheme: /* @__PURE__ */ new Map(),
|
|
948
|
+
majorFont: DEFAULT_THEME_FONT,
|
|
949
|
+
minorFont: DEFAULT_THEME_FONT
|
|
950
|
+
};
|
|
951
|
+
function readTheme(themeRoot) {
|
|
952
|
+
const clrSchemeEl = elementsWithTag([themeRoot], "a:clrScheme")[0];
|
|
953
|
+
const colorScheme = clrSchemeEl === void 0 ? /* @__PURE__ */ new Map() : readClrScheme(clrSchemeEl);
|
|
954
|
+
const fontSchemeEl = elementsWithTag([themeRoot], "a:fontScheme")[0];
|
|
955
|
+
return {
|
|
956
|
+
colorScheme,
|
|
957
|
+
majorFont: readSchemeFont(fontSchemeEl, "a:majorFont") ?? DEFAULT_THEME_FONT,
|
|
958
|
+
minorFont: readSchemeFont(fontSchemeEl, "a:minorFont") ?? DEFAULT_THEME_FONT
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
function resolveThemeFontReference(typeface, theme) {
|
|
962
|
+
if (typeface === "+mj-lt") return theme.majorFont;
|
|
963
|
+
if (typeface === "+mn-lt") return theme.minorFont;
|
|
964
|
+
return typeface;
|
|
965
|
+
}
|
|
966
|
+
function readColorMap(clrMapEl) {
|
|
967
|
+
const map = /* @__PURE__ */ new Map();
|
|
968
|
+
if (clrMapEl === void 0) return map;
|
|
969
|
+
for (const a of clrMapEl.attributes) map.set(a.name, a.value);
|
|
970
|
+
return map;
|
|
971
|
+
}
|
|
972
|
+
function resolveSchemeColorSlot(schemeVal, colorMap) {
|
|
973
|
+
return colorMap.get(schemeVal) ?? schemeVal;
|
|
974
|
+
}
|
|
975
|
+
const COLOR_TRANSFORM_TAGS = /* @__PURE__ */ new Map([
|
|
976
|
+
["a:shade", "shade"],
|
|
977
|
+
["a:tint", "tint"],
|
|
978
|
+
["a:lumMod", "lumMod"],
|
|
979
|
+
["a:lumOff", "lumOff"]
|
|
980
|
+
]);
|
|
981
|
+
function readColorTransforms(container) {
|
|
982
|
+
const transforms = [];
|
|
983
|
+
for (const child of container.children) {
|
|
984
|
+
if (child.type !== "element") continue;
|
|
985
|
+
const kind = COLOR_TRANSFORM_TAGS.get(child.tag);
|
|
986
|
+
if (kind === void 0) continue;
|
|
987
|
+
const val = attr(child, "val");
|
|
988
|
+
if (val === void 0) continue;
|
|
989
|
+
transforms.push({
|
|
990
|
+
kind,
|
|
991
|
+
value: Number(val)
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
return transforms;
|
|
995
|
+
}
|
|
996
|
+
function readSchemeColor(schemeClrEl, colorMap, theme) {
|
|
997
|
+
const val = attr(schemeClrEl, "val");
|
|
998
|
+
if (val === void 0) return;
|
|
999
|
+
const base = theme.colorScheme.get(resolveSchemeColorSlot(val, colorMap));
|
|
1000
|
+
return base === void 0 ? void 0 : applyColorTransforms(base, readColorTransforms(schemeClrEl));
|
|
1001
|
+
}
|
|
1002
|
+
function readSrgbColor(srgbClrEl) {
|
|
1003
|
+
const val = attr(srgbClrEl, "val");
|
|
1004
|
+
return val === void 0 ? void 0 : applyColorTransforms(rgbHexToColor(val), readColorTransforms(srgbClrEl));
|
|
1005
|
+
}
|
|
1006
|
+
function readSolidFillColor(solidFillEl, colorMap, theme) {
|
|
1007
|
+
if (solidFillEl === void 0) return;
|
|
1008
|
+
const schemeClr = childrenWithTag(solidFillEl, "a:schemeClr")[0];
|
|
1009
|
+
if (schemeClr !== void 0) return readSchemeColor(schemeClr, colorMap, theme);
|
|
1010
|
+
const srgbClr = childrenWithTag(solidFillEl, "a:srgbClr")[0];
|
|
1011
|
+
return srgbClr === void 0 ? void 0 : readSrgbColor(srgbClr);
|
|
1012
|
+
}
|
|
1013
|
+
function readGroupXfrm(xfrm) {
|
|
1014
|
+
const base = readXfrm(xfrm);
|
|
1015
|
+
if (base === void 0 || xfrm === void 0) return;
|
|
1016
|
+
const chOff = childrenWithTag(xfrm, "a:chOff")[0];
|
|
1017
|
+
const chExt = childrenWithTag(xfrm, "a:chExt")[0];
|
|
1018
|
+
if (chOff === void 0 || chExt === void 0) return;
|
|
1019
|
+
const cx = attr(chOff, "x");
|
|
1020
|
+
const cy = attr(chOff, "y");
|
|
1021
|
+
const ccx = attr(chExt, "cx");
|
|
1022
|
+
const ccy = attr(chExt, "cy");
|
|
1023
|
+
if (cx === void 0 || cy === void 0 || ccx === void 0 || ccy === void 0) return;
|
|
1024
|
+
return {
|
|
1025
|
+
offXPt: base.xPt,
|
|
1026
|
+
offYPt: base.yPt,
|
|
1027
|
+
extWidthPt: base.widthPt,
|
|
1028
|
+
extHeightPt: base.heightPt,
|
|
1029
|
+
childOffXPt: emuToPt(Number(cx)),
|
|
1030
|
+
childOffYPt: emuToPt(Number(cy)),
|
|
1031
|
+
childExtWidthPt: emuToPt(Number(ccx)),
|
|
1032
|
+
childExtHeightPt: emuToPt(Number(ccy))
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
function applyGroupTransform(group, childFrame) {
|
|
1036
|
+
const scaleX = group.childExtWidthPt === 0 ? 1 : group.extWidthPt / group.childExtWidthPt;
|
|
1037
|
+
const scaleY = group.childExtHeightPt === 0 ? 1 : group.extHeightPt / group.childExtHeightPt;
|
|
1038
|
+
return {
|
|
1039
|
+
xPt: group.offXPt + (childFrame.xPt - group.childOffXPt) * scaleX,
|
|
1040
|
+
yPt: group.offYPt + (childFrame.yPt - group.childOffYPt) * scaleY,
|
|
1041
|
+
widthPt: childFrame.widthPt * scaleX,
|
|
1042
|
+
heightPt: childFrame.heightPt * scaleY
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/typed/docx/styles.ts
|
|
1047
|
+
function mergeParagraphLayer(base, layer) {
|
|
1048
|
+
return {
|
|
1049
|
+
alignment: layer.alignment ?? base.alignment,
|
|
1050
|
+
spacingBeforePt: layer.spacingBeforePt ?? base.spacingBeforePt,
|
|
1051
|
+
spacingAfterPt: layer.spacingAfterPt ?? base.spacingAfterPt,
|
|
1052
|
+
lineSpacing: layer.lineSpacing ?? base.lineSpacing,
|
|
1053
|
+
indentLeftPt: layer.indentLeftPt ?? base.indentLeftPt,
|
|
1054
|
+
indentFirstLinePt: layer.indentFirstLinePt ?? base.indentFirstLinePt
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function mergeRunLayer(base, layer) {
|
|
1058
|
+
return {
|
|
1059
|
+
bold: layer.bold ?? base.bold,
|
|
1060
|
+
italic: layer.italic ?? base.italic,
|
|
1061
|
+
underline: layer.underline ?? base.underline,
|
|
1062
|
+
strike: layer.strike ?? base.strike,
|
|
1063
|
+
fontFamily: layer.fontFamily ?? base.fontFamily,
|
|
1064
|
+
sizePt: layer.sizePt ?? base.sizePt,
|
|
1065
|
+
color: layer.color ?? base.color
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
function readToggle$1(el) {
|
|
1069
|
+
if (el === void 0) return;
|
|
1070
|
+
const val = attr(el, "w:val");
|
|
1071
|
+
return val === void 0 || val !== "0" && val !== "false" && val !== "off";
|
|
1072
|
+
}
|
|
1073
|
+
function readUnderline(u) {
|
|
1074
|
+
if (u === void 0) return;
|
|
1075
|
+
const val = attr(u, "w:val");
|
|
1076
|
+
return val !== void 0 && val !== "none";
|
|
1077
|
+
}
|
|
1078
|
+
function readRunColor(colorEl) {
|
|
1079
|
+
if (colorEl === void 0) return;
|
|
1080
|
+
const val = attr(colorEl, "w:val");
|
|
1081
|
+
return val === void 0 || val === "auto" ? void 0 : rgbHexToColor(val);
|
|
1082
|
+
}
|
|
1083
|
+
function readRunFontFamily(rFonts, theme) {
|
|
1084
|
+
if (rFonts === void 0) return;
|
|
1085
|
+
const ascii = attr(rFonts, "w:ascii");
|
|
1086
|
+
if (ascii !== void 0) return ascii;
|
|
1087
|
+
const asciiTheme = attr(rFonts, "w:asciiTheme");
|
|
1088
|
+
if (asciiTheme === "majorHAnsi" || asciiTheme === "majorAscii") return theme.majorFont;
|
|
1089
|
+
if (asciiTheme === "minorHAnsi" || asciiTheme === "minorAscii") return theme.minorFont;
|
|
1090
|
+
}
|
|
1091
|
+
function readRunPropertiesLayer(rPr, theme) {
|
|
1092
|
+
if (rPr === void 0) return {};
|
|
1093
|
+
const sz = childrenWithTag(rPr, "w:sz")[0];
|
|
1094
|
+
const szVal = sz === void 0 ? void 0 : attr(sz, "w:val");
|
|
1095
|
+
return {
|
|
1096
|
+
bold: readToggle$1(childrenWithTag(rPr, "w:b")[0]),
|
|
1097
|
+
italic: readToggle$1(childrenWithTag(rPr, "w:i")[0]),
|
|
1098
|
+
underline: readUnderline(childrenWithTag(rPr, "w:u")[0]),
|
|
1099
|
+
strike: readToggle$1(childrenWithTag(rPr, "w:strike")[0]),
|
|
1100
|
+
fontFamily: readRunFontFamily(childrenWithTag(rPr, "w:rFonts")[0], theme),
|
|
1101
|
+
sizePt: szVal === void 0 ? void 0 : halfPointsToPt(Number(szVal)),
|
|
1102
|
+
color: readRunColor(childrenWithTag(rPr, "w:color")[0])
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
function readAlignment$1(jc) {
|
|
1106
|
+
const val = jc === void 0 ? void 0 : attr(jc, "w:val");
|
|
1107
|
+
if (val === "left" || val === "start") return "left";
|
|
1108
|
+
if (val === "center") return "center";
|
|
1109
|
+
if (val === "right" || val === "end") return "right";
|
|
1110
|
+
if (val === "both" || val === "distribute") return "justify";
|
|
1111
|
+
}
|
|
1112
|
+
function readParagraphPropertiesLayer(pPr) {
|
|
1113
|
+
if (pPr === void 0) return {};
|
|
1114
|
+
const spacing = childrenWithTag(pPr, "w:spacing")[0];
|
|
1115
|
+
const before = spacing === void 0 ? void 0 : attr(spacing, "w:before");
|
|
1116
|
+
const after = spacing === void 0 ? void 0 : attr(spacing, "w:after");
|
|
1117
|
+
const line = spacing === void 0 ? void 0 : attr(spacing, "w:line");
|
|
1118
|
+
const lineRule = spacing === void 0 ? void 0 : attr(spacing, "w:lineRule");
|
|
1119
|
+
const ind = childrenWithTag(pPr, "w:ind")[0];
|
|
1120
|
+
const left = ind === void 0 ? void 0 : attr(ind, "w:left") ?? attr(ind, "w:start");
|
|
1121
|
+
const firstLine = ind === void 0 ? void 0 : attr(ind, "w:firstLine");
|
|
1122
|
+
const hanging = ind === void 0 ? void 0 : attr(ind, "w:hanging");
|
|
1123
|
+
return {
|
|
1124
|
+
alignment: readAlignment$1(childrenWithTag(pPr, "w:jc")[0]),
|
|
1125
|
+
spacingBeforePt: before === void 0 ? void 0 : twipsToPt(Number(before)),
|
|
1126
|
+
spacingAfterPt: after === void 0 ? void 0 : twipsToPt(Number(after)),
|
|
1127
|
+
lineSpacing: line === void 0 || lineRule === "exact" || lineRule === "atLeast" ? void 0 : lineUnitsToMultiplier(Number(line)),
|
|
1128
|
+
indentLeftPt: left === void 0 ? void 0 : twipsToPt(Number(left)),
|
|
1129
|
+
indentFirstLinePt: firstLine !== void 0 ? twipsToPt(Number(firstLine)) : hanging !== void 0 ? -twipsToPt(Number(hanging)) : void 0
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function findStyle(stylesRoot, styleId, type) {
|
|
1133
|
+
return elementsWithTag([stylesRoot], "w:style").find((s) => attr(s, "w:type") === type && attr(s, "w:styleId") === styleId);
|
|
1134
|
+
}
|
|
1135
|
+
function findDefaultStyle(stylesRoot, type) {
|
|
1136
|
+
return elementsWithTag([stylesRoot], "w:style").find((s) => attr(s, "w:type") === type && attr(s, "w:default") === "1");
|
|
1137
|
+
}
|
|
1138
|
+
function resolveBasedOnChain(stylesRoot, styleId, type) {
|
|
1139
|
+
const chain = [];
|
|
1140
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1141
|
+
let currentId = styleId;
|
|
1142
|
+
while (currentId !== void 0 && !visited.has(currentId)) {
|
|
1143
|
+
visited.add(currentId);
|
|
1144
|
+
const style = findStyle(stylesRoot, currentId, type);
|
|
1145
|
+
if (style === void 0) break;
|
|
1146
|
+
chain.unshift(style);
|
|
1147
|
+
const basedOn = childrenWithTag(style, "w:basedOn")[0];
|
|
1148
|
+
currentId = basedOn === void 0 ? void 0 : attr(basedOn, "w:val");
|
|
1149
|
+
}
|
|
1150
|
+
return chain;
|
|
1151
|
+
}
|
|
1152
|
+
function docDefaultsElement(stylesRoot, wrapperTag, innerTag) {
|
|
1153
|
+
const docDefaults = stylesRoot === void 0 ? void 0 : childrenWithTag(stylesRoot, "w:docDefaults")[0];
|
|
1154
|
+
const wrapper = docDefaults === void 0 ? void 0 : childrenWithTag(docDefaults, wrapperTag)[0];
|
|
1155
|
+
return wrapper === void 0 ? void 0 : childrenWithTag(wrapper, innerTag)[0];
|
|
1156
|
+
}
|
|
1157
|
+
function resolveParagraphProperties(paragraph, context) {
|
|
1158
|
+
const pPr = childrenWithTag(paragraph, "w:pPr")[0];
|
|
1159
|
+
const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:pStyle")[0];
|
|
1160
|
+
const styleId = pStyleEl === void 0 ? void 0 : attr(pStyleEl, "w:val");
|
|
1161
|
+
let resolved = readParagraphPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:pPrDefault", "w:pPr"));
|
|
1162
|
+
if (context.stylesRoot !== void 0) {
|
|
1163
|
+
const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
|
|
1164
|
+
if (defaultStyle !== void 0) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer(childrenWithTag(defaultStyle, "w:pPr")[0]));
|
|
1165
|
+
if (styleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, styleId, "paragraph")) resolved = mergeParagraphLayer(resolved, readParagraphPropertiesLayer(childrenWithTag(style, "w:pPr")[0]));
|
|
1166
|
+
}
|
|
1167
|
+
return mergeParagraphLayer(resolved, readParagraphPropertiesLayer(pPr));
|
|
1168
|
+
}
|
|
1169
|
+
function resolveRunProperties(run, paragraph, context) {
|
|
1170
|
+
const pPr = childrenWithTag(paragraph, "w:pPr")[0];
|
|
1171
|
+
const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:pStyle")[0];
|
|
1172
|
+
const pStyleId = pStyleEl === void 0 ? void 0 : attr(pStyleEl, "w:val");
|
|
1173
|
+
let resolved = readRunPropertiesLayer(docDefaultsElement(context.stylesRoot, "w:rPrDefault", "w:rPr"), context.theme);
|
|
1174
|
+
if (context.stylesRoot !== void 0) {
|
|
1175
|
+
const defaultStyle = findDefaultStyle(context.stylesRoot, "paragraph");
|
|
1176
|
+
if (defaultStyle !== void 0) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag(defaultStyle, "w:rPr")[0], context.theme));
|
|
1177
|
+
if (pStyleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, pStyleId, "paragraph")) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag(style, "w:rPr")[0], context.theme));
|
|
1178
|
+
}
|
|
1179
|
+
const paragraphMarkRPr = pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:rPr")[0];
|
|
1180
|
+
resolved = mergeRunLayer(resolved, readRunPropertiesLayer(paragraphMarkRPr, context.theme));
|
|
1181
|
+
const rPr = childrenWithTag(run, "w:rPr")[0];
|
|
1182
|
+
const rStyleEl = rPr === void 0 ? void 0 : childrenWithTag(rPr, "w:rStyle")[0];
|
|
1183
|
+
const rStyleId = rStyleEl === void 0 ? void 0 : attr(rStyleEl, "w:val");
|
|
1184
|
+
if (context.stylesRoot !== void 0 && rStyleId !== void 0) for (const style of resolveBasedOnChain(context.stylesRoot, rStyleId, "character")) resolved = mergeRunLayer(resolved, readRunPropertiesLayer(childrenWithTag(style, "w:rPr")[0], context.theme));
|
|
1185
|
+
return mergeRunLayer(resolved, readRunPropertiesLayer(rPr, context.theme));
|
|
1186
|
+
}
|
|
1187
|
+
//#endregion
|
|
1188
|
+
//#region src/typed/docx/read.ts
|
|
557
1189
|
const CommentSchema = z.object({
|
|
558
1190
|
author: z.string().optional(),
|
|
559
1191
|
text: z.string()
|
|
@@ -563,62 +1195,256 @@ const FootnoteSchema = z.object({
|
|
|
563
1195
|
text: z.string()
|
|
564
1196
|
});
|
|
565
1197
|
const DocxDocumentSchema = z.object({
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
hyperlinks: z.array(HyperlinkSchema),
|
|
1198
|
+
metadata: DocumentMetadataSchema,
|
|
1199
|
+
sections: z.array(ContentSectionSchema),
|
|
569
1200
|
comments: z.array(CommentSchema),
|
|
570
1201
|
footnotes: z.array(FootnoteSchema),
|
|
571
1202
|
headers: z.array(z.string()),
|
|
572
1203
|
footers: z.array(z.string())
|
|
573
1204
|
});
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
1205
|
+
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
1206
|
+
const STYLES_PART_PATH = "word/styles.xml";
|
|
1207
|
+
const THEME_REL_SUFFIX$1 = "/theme";
|
|
1208
|
+
const DEFAULT_MARGIN_PT = 72;
|
|
1209
|
+
const DEFAULT_MARGINS = {
|
|
1210
|
+
topPt: DEFAULT_MARGIN_PT,
|
|
1211
|
+
rightPt: DEFAULT_MARGIN_PT,
|
|
1212
|
+
bottomPt: DEFAULT_MARGIN_PT,
|
|
1213
|
+
leftPt: DEFAULT_MARGIN_PT
|
|
1214
|
+
};
|
|
1215
|
+
function readPageSize(sectPr) {
|
|
1216
|
+
const pgSz = childrenWithTag(sectPr, "w:pgSz")[0];
|
|
1217
|
+
const w = pgSz === void 0 ? void 0 : attr(pgSz, "w:w");
|
|
1218
|
+
const h = pgSz === void 0 ? void 0 : attr(pgSz, "w:h");
|
|
1219
|
+
return w === void 0 || h === void 0 ? PAGE_SIZE_LETTER : {
|
|
1220
|
+
widthPt: twipsToPt(Number(w)),
|
|
1221
|
+
heightPt: twipsToPt(Number(h))
|
|
1222
|
+
};
|
|
577
1223
|
}
|
|
578
|
-
function
|
|
579
|
-
const
|
|
580
|
-
if (
|
|
581
|
-
|
|
582
|
-
|
|
1224
|
+
function readMargins(sectPr) {
|
|
1225
|
+
const pgMar = childrenWithTag(sectPr, "w:pgMar")[0];
|
|
1226
|
+
if (pgMar === void 0) return DEFAULT_MARGINS;
|
|
1227
|
+
const top = attr(pgMar, "w:top");
|
|
1228
|
+
const right = attr(pgMar, "w:right");
|
|
1229
|
+
const bottom = attr(pgMar, "w:bottom");
|
|
1230
|
+
const left = attr(pgMar, "w:left");
|
|
1231
|
+
return {
|
|
1232
|
+
topPt: top === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(top)),
|
|
1233
|
+
rightPt: right === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(right)),
|
|
1234
|
+
bottomPt: bottom === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(bottom)),
|
|
1235
|
+
leftPt: left === void 0 ? DEFAULT_MARGIN_PT : twipsToPt(Number(left))
|
|
1236
|
+
};
|
|
583
1237
|
}
|
|
584
|
-
function readListMembership(
|
|
585
|
-
const
|
|
586
|
-
if (pPr === void 0) return;
|
|
587
|
-
const numPr = childrenWithTag(pPr, "w:numPr")[0];
|
|
1238
|
+
function readListMembership(pPr) {
|
|
1239
|
+
const numPr = pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:numPr")[0];
|
|
588
1240
|
if (numPr === void 0) return;
|
|
589
1241
|
const numIdEl = childrenWithTag(numPr, "w:numId")[0];
|
|
590
|
-
const numId = numIdEl
|
|
1242
|
+
const numId = numIdEl === void 0 ? void 0 : attr(numIdEl, "w:val");
|
|
591
1243
|
if (numId === void 0) return;
|
|
592
1244
|
const ilvlEl = childrenWithTag(numPr, "w:ilvl")[0];
|
|
593
|
-
const ilvlVal = ilvlEl
|
|
1245
|
+
const ilvlVal = ilvlEl === void 0 ? void 0 : attr(ilvlEl, "w:val");
|
|
594
1246
|
return {
|
|
595
1247
|
numId,
|
|
596
|
-
level: ilvlVal
|
|
1248
|
+
level: ilvlVal === void 0 ? 0 : Number(ilvlVal)
|
|
597
1249
|
};
|
|
598
1250
|
}
|
|
599
|
-
function
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
1251
|
+
function readToggle(el) {
|
|
1252
|
+
if (el === void 0) return false;
|
|
1253
|
+
const val = attr(el, "w:val");
|
|
1254
|
+
return val === void 0 || val !== "0" && val !== "false" && val !== "off";
|
|
1255
|
+
}
|
|
1256
|
+
function hasPageBreakBefore(paragraph) {
|
|
1257
|
+
const pPr = childrenWithTag(paragraph, "w:pPr")[0];
|
|
1258
|
+
return readToggle(pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:pageBreakBefore")[0]);
|
|
1259
|
+
}
|
|
1260
|
+
function readRunText(run) {
|
|
1261
|
+
let text = "";
|
|
1262
|
+
for (const child of run.children) {
|
|
1263
|
+
if (child.type !== "element") continue;
|
|
1264
|
+
if (child.tag === "w:t") text += textContent(child);
|
|
1265
|
+
else if (child.tag === "w:tab") text += " ";
|
|
1266
|
+
else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
|
|
1267
|
+
}
|
|
1268
|
+
return text;
|
|
604
1269
|
}
|
|
605
|
-
function
|
|
606
|
-
|
|
1270
|
+
function readRun$1(run, paragraph, context) {
|
|
1271
|
+
const props = resolveRunProperties(run, paragraph, context);
|
|
1272
|
+
return {
|
|
1273
|
+
text: readRunText(run),
|
|
1274
|
+
bold: props.bold,
|
|
1275
|
+
italic: props.italic,
|
|
1276
|
+
underline: props.underline,
|
|
1277
|
+
strike: props.strike,
|
|
1278
|
+
fontFamily: props.fontFamily,
|
|
1279
|
+
sizePt: props.sizePt,
|
|
1280
|
+
color: props.color
|
|
1281
|
+
};
|
|
607
1282
|
}
|
|
608
|
-
function
|
|
609
|
-
|
|
1283
|
+
function readParagraphRuns(paragraph, context, rels) {
|
|
1284
|
+
const runs = [];
|
|
1285
|
+
let fieldState = "none";
|
|
1286
|
+
function walk(nodes, hyperlinkTarget) {
|
|
1287
|
+
for (const node of nodes) {
|
|
1288
|
+
if (node.type !== "element") continue;
|
|
1289
|
+
if (node.tag === "w:r") {
|
|
1290
|
+
const fldChar = childrenWithTag(node, "w:fldChar")[0];
|
|
1291
|
+
if (fldChar !== void 0) {
|
|
1292
|
+
const type = attr(fldChar, "w:fldCharType");
|
|
1293
|
+
if (type === "begin") fieldState = "code";
|
|
1294
|
+
else if (type === "separate") fieldState = "result";
|
|
1295
|
+
else if (type === "end") fieldState = "none";
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
if (fieldState === "code") continue;
|
|
1299
|
+
const run = readRun$1(node, paragraph, context);
|
|
1300
|
+
runs.push(hyperlinkTarget === void 0 ? run : {
|
|
1301
|
+
...run,
|
|
1302
|
+
hyperlink: hyperlinkTarget
|
|
1303
|
+
});
|
|
1304
|
+
} else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
|
|
1305
|
+
else if (node.tag === "w:hyperlink") {
|
|
1306
|
+
const rId = attr(node, "r:id");
|
|
1307
|
+
const target = rId === void 0 ? void 0 : rels.get(rId)?.target;
|
|
1308
|
+
walk(node.children, target ?? hyperlinkTarget);
|
|
1309
|
+
} else if (node.tag === "w:ins") walk(node.children, hyperlinkTarget);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
walk(paragraph.children, void 0);
|
|
1313
|
+
return runs;
|
|
1314
|
+
}
|
|
1315
|
+
function readParagraph$1(paragraph, context, rels) {
|
|
1316
|
+
const pPr = childrenWithTag(paragraph, "w:pPr")[0];
|
|
1317
|
+
const pStyleEl = pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:pStyle")[0];
|
|
1318
|
+
const props = resolveParagraphProperties(paragraph, context);
|
|
1319
|
+
return {
|
|
1320
|
+
kind: "paragraph",
|
|
1321
|
+
runs: readParagraphRuns(paragraph, context, rels),
|
|
1322
|
+
styleId: pStyleEl === void 0 ? void 0 : attr(pStyleEl, "w:val"),
|
|
1323
|
+
alignment: props.alignment,
|
|
1324
|
+
list: readListMembership(pPr),
|
|
1325
|
+
spacingBeforePt: props.spacingBeforePt,
|
|
1326
|
+
spacingAfterPt: props.spacingAfterPt,
|
|
1327
|
+
lineSpacing: props.lineSpacing,
|
|
1328
|
+
indentLeftPt: props.indentLeftPt,
|
|
1329
|
+
indentFirstLinePt: props.indentFirstLinePt
|
|
1330
|
+
};
|
|
610
1331
|
}
|
|
611
|
-
function
|
|
612
|
-
|
|
1332
|
+
function readCellShading(tcPr) {
|
|
1333
|
+
const shd = tcPr === void 0 ? void 0 : childrenWithTag(tcPr, "w:shd")[0];
|
|
1334
|
+
const fill = shd === void 0 ? void 0 : attr(shd, "w:fill");
|
|
1335
|
+
return fill === void 0 || fill === "auto" || fill === "none" ? void 0 : rgbHexToColor(fill);
|
|
1336
|
+
}
|
|
1337
|
+
function readRawCell(tc, context, rels) {
|
|
1338
|
+
const tcPr = childrenWithTag(tc, "w:tcPr")[0];
|
|
1339
|
+
const gridSpanEl = tcPr === void 0 ? void 0 : childrenWithTag(tcPr, "w:gridSpan")[0];
|
|
1340
|
+
const gridSpanVal = gridSpanEl === void 0 ? void 0 : attr(gridSpanEl, "w:val");
|
|
1341
|
+
const vMerge = tcPr === void 0 ? void 0 : childrenWithTag(tcPr, "w:vMerge")[0];
|
|
1342
|
+
const vMergeVal = vMerge === void 0 ? void 0 : attr(vMerge, "w:val") ?? "continue";
|
|
1343
|
+
return {
|
|
1344
|
+
gridSpan: gridSpanVal === void 0 ? 1 : Number(gridSpanVal),
|
|
1345
|
+
isVMergeContinuation: vMergeVal === "continue",
|
|
1346
|
+
background: readCellShading(tcPr),
|
|
1347
|
+
blocks: readBodyBlocks(tc.children, context, rels)
|
|
1348
|
+
};
|
|
613
1349
|
}
|
|
614
|
-
function
|
|
615
|
-
const
|
|
616
|
-
const
|
|
1350
|
+
function readTable$1(tbl, context, rels) {
|
|
1351
|
+
const tblGrid = childrenWithTag(tbl, "w:tblGrid")[0];
|
|
1352
|
+
const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag(tblGrid, "w:gridCol").map((col) => twipsToPt(Number(attr(col, "w:w") ?? "0")));
|
|
1353
|
+
const rawRows = childrenWithTag(tbl, "w:tr").map((tr) => childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels)));
|
|
1354
|
+
const rowColumnIndices = rawRows.map((row) => {
|
|
1355
|
+
const indices = [];
|
|
1356
|
+
let col = 0;
|
|
1357
|
+
for (const cell of row) {
|
|
1358
|
+
indices.push(col);
|
|
1359
|
+
col += cell.gridSpan;
|
|
1360
|
+
}
|
|
1361
|
+
return indices;
|
|
1362
|
+
});
|
|
617
1363
|
return {
|
|
618
|
-
|
|
619
|
-
|
|
1364
|
+
kind: "table",
|
|
1365
|
+
columnWidthsPt,
|
|
1366
|
+
rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
|
|
1367
|
+
if (cell.isVMergeContinuation) return { blocks: [] };
|
|
1368
|
+
const colIndex = rowColumnIndices[rowIndex][cellIndex];
|
|
1369
|
+
let rowSpan = 1;
|
|
1370
|
+
for (let r = rowIndex + 1; r < rawRows.length; r++) {
|
|
1371
|
+
const matchIndex = rowColumnIndices[r].indexOf(colIndex);
|
|
1372
|
+
if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
|
|
1373
|
+
rowSpan++;
|
|
1374
|
+
}
|
|
1375
|
+
return {
|
|
1376
|
+
blocks: cell.blocks,
|
|
1377
|
+
colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
|
|
1378
|
+
rowSpan: rowSpan > 1 ? rowSpan : void 0,
|
|
1379
|
+
background: cell.background
|
|
1380
|
+
};
|
|
1381
|
+
}) }))
|
|
620
1382
|
};
|
|
621
1383
|
}
|
|
1384
|
+
function readBodyBlocks(nodes, context, rels) {
|
|
1385
|
+
const blocks = [];
|
|
1386
|
+
for (const node of nodes) {
|
|
1387
|
+
if (node.type !== "element") continue;
|
|
1388
|
+
if (node.tag === "w:p") {
|
|
1389
|
+
if (hasPageBreakBefore(node)) blocks.push({ kind: "pageBreak" });
|
|
1390
|
+
blocks.push(readParagraph$1(node, context, rels));
|
|
1391
|
+
} else if (node.tag === "w:tbl") blocks.push(readTable$1(node, context, rels));
|
|
1392
|
+
else if (node.tag === "w:sdt") {
|
|
1393
|
+
const sdtContent = childrenWithTag(node, "w:sdtContent")[0];
|
|
1394
|
+
if (sdtContent !== void 0) blocks.push(...readBodyBlocks(sdtContent.children, context, rels));
|
|
1395
|
+
} else if (node.tag === "w:ins") blocks.push(...readBodyBlocks(node.children, context, rels));
|
|
1396
|
+
else if (node.tag === "mc:AlternateContent") {
|
|
1397
|
+
const target = childrenWithTag(node, "mc:Fallback")[0] ?? childrenWithTag(node, "mc:Choice")[0];
|
|
1398
|
+
if (target !== void 0) blocks.push(...readBodyBlocks(target.children, context, rels));
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
return blocks;
|
|
1402
|
+
}
|
|
1403
|
+
function readSections(body, context, rels) {
|
|
1404
|
+
const sections = [];
|
|
1405
|
+
let currentBlocks = [];
|
|
1406
|
+
for (const node of body.children) {
|
|
1407
|
+
if (node.type !== "element") continue;
|
|
1408
|
+
if (node.tag === "w:sectPr") {
|
|
1409
|
+
sections.push({
|
|
1410
|
+
pageSize: readPageSize(node),
|
|
1411
|
+
margins: readMargins(node),
|
|
1412
|
+
blocks: currentBlocks
|
|
1413
|
+
});
|
|
1414
|
+
currentBlocks = [];
|
|
1415
|
+
continue;
|
|
1416
|
+
}
|
|
1417
|
+
if (node.tag === "w:p") {
|
|
1418
|
+
const pPr = childrenWithTag(node, "w:pPr")[0];
|
|
1419
|
+
const sectPr = pPr === void 0 ? void 0 : childrenWithTag(pPr, "w:sectPr")[0];
|
|
1420
|
+
if (hasPageBreakBefore(node)) currentBlocks.push({ kind: "pageBreak" });
|
|
1421
|
+
currentBlocks.push(readParagraph$1(node, context, rels));
|
|
1422
|
+
if (sectPr !== void 0) {
|
|
1423
|
+
sections.push({
|
|
1424
|
+
pageSize: readPageSize(sectPr),
|
|
1425
|
+
margins: readMargins(sectPr),
|
|
1426
|
+
blocks: currentBlocks
|
|
1427
|
+
});
|
|
1428
|
+
currentBlocks = [];
|
|
1429
|
+
}
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
currentBlocks.push(...readBodyBlocks([node], context, rels));
|
|
1433
|
+
}
|
|
1434
|
+
if (currentBlocks.length > 0 || sections.length === 0) sections.push({
|
|
1435
|
+
pageSize: PAGE_SIZE_LETTER,
|
|
1436
|
+
margins: DEFAULT_MARGINS,
|
|
1437
|
+
blocks: currentBlocks
|
|
1438
|
+
});
|
|
1439
|
+
return sections;
|
|
1440
|
+
}
|
|
1441
|
+
function readDocumentTheme(pkg, docRels) {
|
|
1442
|
+
for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX$1)) {
|
|
1443
|
+
const themeRoot = rootElement(pkg.parts[rel.target]);
|
|
1444
|
+
if (themeRoot !== void 0) return readTheme(themeRoot);
|
|
1445
|
+
}
|
|
1446
|
+
return EMPTY_THEME;
|
|
1447
|
+
}
|
|
622
1448
|
function readComment(comment) {
|
|
623
1449
|
const author = attr(comment, "w:author");
|
|
624
1450
|
const result = { text: elementsWithTag(comment.children, "w:t").map(textContent).join("") };
|
|
@@ -658,14 +1484,18 @@ function readHeaderFooterText(pkg, prefix) {
|
|
|
658
1484
|
return out;
|
|
659
1485
|
}
|
|
660
1486
|
function readDocx(pkg) {
|
|
661
|
-
const
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
1487
|
+
const documentRoot = rootElement(pkg.parts[DOCUMENT_PART_PATH]);
|
|
1488
|
+
if (documentRoot === void 0) throw new Error(`readDocx: package has no ${DOCUMENT_PART_PATH} part`);
|
|
1489
|
+
const body = childrenWithTag(documentRoot, "w:body")[0];
|
|
1490
|
+
if (body === void 0) throw new Error(`readDocx: ${DOCUMENT_PART_PATH} has no w:body element`);
|
|
1491
|
+
const docRels = resolveRelationships(pkg, DOCUMENT_PART_PATH);
|
|
1492
|
+
const context = {
|
|
1493
|
+
stylesRoot: rootElement(pkg.parts[STYLES_PART_PATH]),
|
|
1494
|
+
theme: readDocumentTheme(pkg, docRels)
|
|
1495
|
+
};
|
|
1496
|
+
return {
|
|
1497
|
+
metadata: readCoreProperties(pkg),
|
|
1498
|
+
sections: readSections(body, context, docRels),
|
|
669
1499
|
comments: readComments(pkg),
|
|
670
1500
|
footnotes: readFootnotes(pkg),
|
|
671
1501
|
headers: readHeaderFooterText(pkg, "word/header"),
|
|
@@ -673,72 +1503,434 @@ function readDocx(pkg) {
|
|
|
673
1503
|
};
|
|
674
1504
|
}
|
|
675
1505
|
//#endregion
|
|
676
|
-
//#region src/typed/pptx.ts
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
1506
|
+
//#region src/typed/pptx/inherit.ts
|
|
1507
|
+
const SLIDE_LAYOUT_REL_SUFFIX = "/slideLayout";
|
|
1508
|
+
const SLIDE_MASTER_REL_SUFFIX = "/slideMaster";
|
|
1509
|
+
const THEME_REL_SUFFIX = "/theme";
|
|
1510
|
+
function findRelTarget(pkg, partPath, typeSuffix) {
|
|
1511
|
+
for (const rel of resolveRelationships(pkg, partPath).values()) if (rel.type.endsWith(typeSuffix)) return rel.target;
|
|
1512
|
+
}
|
|
1513
|
+
function resolveSlideInheritance(pkg, slidePath) {
|
|
1514
|
+
const layoutPath = findRelTarget(pkg, slidePath, SLIDE_LAYOUT_REL_SUFFIX);
|
|
1515
|
+
const layoutRoot = layoutPath === void 0 ? void 0 : rootElement(pkg.parts[layoutPath]);
|
|
1516
|
+
const masterPath = layoutPath === void 0 ? void 0 : findRelTarget(pkg, layoutPath, SLIDE_MASTER_REL_SUFFIX);
|
|
1517
|
+
const masterRoot = masterPath === void 0 ? void 0 : rootElement(pkg.parts[masterPath]);
|
|
1518
|
+
const themePath = masterPath === void 0 ? void 0 : findRelTarget(pkg, masterPath, THEME_REL_SUFFIX);
|
|
1519
|
+
const themeRoot = themePath === void 0 ? void 0 : rootElement(pkg.parts[themePath]);
|
|
1520
|
+
return {
|
|
1521
|
+
layoutRoot,
|
|
1522
|
+
masterRoot,
|
|
1523
|
+
theme: themeRoot === void 0 ? EMPTY_THEME : readTheme(themeRoot),
|
|
1524
|
+
colorMap: readColorMap(masterRoot === void 0 ? void 0 : childrenWithTag(masterRoot, "p:clrMap")[0])
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
const TYPE_NORMALIZATION = /* @__PURE__ */ new Map([["ctrTitle", "title"], ["subTitle", "body"]]);
|
|
1528
|
+
function normalizePlaceholderType(type) {
|
|
1529
|
+
return type === void 0 ? void 0 : TYPE_NORMALIZATION.get(type) ?? type;
|
|
1530
|
+
}
|
|
1531
|
+
function readPlaceholderKey(shape) {
|
|
1532
|
+
const ph = elementsWithTag([shape], "p:ph")[0];
|
|
1533
|
+
return ph === void 0 ? void 0 : {
|
|
1534
|
+
type: attr(ph, "type"),
|
|
1535
|
+
idx: attr(ph, "idx")
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
function shapesOf(root) {
|
|
1539
|
+
return root === void 0 ? [] : elementsWithTag([root], "p:sp");
|
|
1540
|
+
}
|
|
1541
|
+
function findMatchingPlaceholder(root, key) {
|
|
1542
|
+
const shapes = shapesOf(root);
|
|
1543
|
+
if (key.idx !== void 0) {
|
|
1544
|
+
const byIdx = shapes.find((shape) => readPlaceholderKey(shape)?.idx === key.idx);
|
|
1545
|
+
if (byIdx !== void 0) return byIdx;
|
|
1546
|
+
}
|
|
1547
|
+
const normalizedTarget = normalizePlaceholderType(key.type);
|
|
1548
|
+
if (normalizedTarget === void 0) return;
|
|
1549
|
+
return shapes.find((shape) => normalizePlaceholderType(readPlaceholderKey(shape)?.type) === normalizedTarget);
|
|
1550
|
+
}
|
|
1551
|
+
function shapeXfrm(shape) {
|
|
1552
|
+
if (shape === void 0) return;
|
|
1553
|
+
const spPr = childrenWithTag(shape, "p:spPr")[0];
|
|
1554
|
+
return spPr === void 0 ? void 0 : readXfrm(childrenWithTag(spPr, "a:xfrm")[0]);
|
|
1555
|
+
}
|
|
1556
|
+
function resolvePlaceholderXfrm(key, context) {
|
|
1557
|
+
return shapeXfrm(findMatchingPlaceholder(context.layoutRoot, key)) ?? shapeXfrm(findMatchingPlaceholder(context.masterRoot, key));
|
|
1558
|
+
}
|
|
1559
|
+
function readRunPropertiesFromElement(rPr, context) {
|
|
1560
|
+
const sz = attr(rPr, "sz");
|
|
1561
|
+
const latin = childrenWithTag(rPr, "a:latin")[0];
|
|
1562
|
+
const typeface = latin === void 0 ? void 0 : attr(latin, "typeface");
|
|
1563
|
+
const solidFill = childrenWithTag(rPr, "a:solidFill")[0];
|
|
1564
|
+
const bold = attr(rPr, "b");
|
|
1565
|
+
const italic = attr(rPr, "i");
|
|
1566
|
+
return {
|
|
1567
|
+
fontFamily: typeface === void 0 ? void 0 : resolveThemeFontReference(typeface, context.theme),
|
|
1568
|
+
sizePt: sz === void 0 ? void 0 : drawingMlFontSizeToPt(Number(sz)),
|
|
1569
|
+
bold: bold === void 0 ? void 0 : bold === "1",
|
|
1570
|
+
italic: italic === void 0 ? void 0 : italic === "1",
|
|
1571
|
+
color: readSolidFillColor(solidFill, context.colorMap, context.theme)
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
function txStyleTagFor(placeholderType) {
|
|
1575
|
+
const normalized = normalizePlaceholderType(placeholderType);
|
|
1576
|
+
if (normalized === "title") return "p:titleStyle";
|
|
1577
|
+
if (normalized === "body") return "p:bodyStyle";
|
|
1578
|
+
return "p:otherStyle";
|
|
1579
|
+
}
|
|
1580
|
+
function levelTag(level) {
|
|
1581
|
+
return `a:lvl${Math.min(Math.max(level, 0), 8) + 1}pPr`;
|
|
1582
|
+
}
|
|
1583
|
+
function resolveDefaultRunProperties(placeholderType, level, context) {
|
|
1584
|
+
if (context.masterRoot === void 0) return {};
|
|
1585
|
+
const txStyles = childrenWithTag(context.masterRoot, "p:txStyles")[0];
|
|
1586
|
+
const styleEl = txStyles === void 0 ? void 0 : childrenWithTag(txStyles, txStyleTagFor(placeholderType))[0];
|
|
1587
|
+
const lvlPPr = styleEl === void 0 ? void 0 : childrenWithTag(styleEl, levelTag(level))[0];
|
|
1588
|
+
const defRPr = lvlPPr === void 0 ? void 0 : childrenWithTag(lvlPPr, "a:defRPr")[0];
|
|
1589
|
+
return defRPr === void 0 ? {} : readRunPropertiesFromElement(defRPr, context);
|
|
1590
|
+
}
|
|
1591
|
+
//#endregion
|
|
1592
|
+
//#region src/typed/pptx/read.ts
|
|
1593
|
+
const PptxDocumentSchema = z.object({
|
|
1594
|
+
metadata: DocumentMetadataSchema,
|
|
1595
|
+
slides: z.array(ContentSlideSchema)
|
|
687
1596
|
});
|
|
688
|
-
const
|
|
689
|
-
const
|
|
690
|
-
function
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
|
|
1597
|
+
const PRESENTATION_PATH = "ppt/presentation.xml";
|
|
1598
|
+
const TABLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
|
|
1599
|
+
function readSlideSize(presentationRoot) {
|
|
1600
|
+
const sldSz = presentationRoot === void 0 ? void 0 : childrenWithTag(presentationRoot, "p:sldSz")[0];
|
|
1601
|
+
const cx = sldSz === void 0 ? void 0 : attr(sldSz, "cx");
|
|
1602
|
+
const cy = sldSz === void 0 ? void 0 : attr(sldSz, "cy");
|
|
1603
|
+
return cx === void 0 || cy === void 0 ? SLIDE_SIZE_WIDESCREEN : {
|
|
1604
|
+
widthPt: emuToPt(Number(cx)),
|
|
1605
|
+
heightPt: emuToPt(Number(cy))
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
function readSlidePathsInOrder(pkg, presentationRoot) {
|
|
1609
|
+
if (presentationRoot === void 0) return [];
|
|
1610
|
+
const sldIdLst = childrenWithTag(presentationRoot, "p:sldIdLst")[0];
|
|
1611
|
+
if (sldIdLst === void 0) return [];
|
|
1612
|
+
const presentationRels = resolveRelationships(pkg, PRESENTATION_PATH);
|
|
1613
|
+
const paths = [];
|
|
1614
|
+
for (const sldId of childrenWithTag(sldIdLst, "p:sldId")) {
|
|
1615
|
+
const rId = attr(sldId, "r:id");
|
|
1616
|
+
const rel = rId === void 0 ? void 0 : presentationRels.get(rId);
|
|
1617
|
+
if (rel !== void 0) paths.push(rel.target);
|
|
1618
|
+
}
|
|
1619
|
+
return paths;
|
|
1620
|
+
}
|
|
1621
|
+
function shapeName(shape) {
|
|
1622
|
+
const cNvPr = elementsWithTag([shape], "p:cNvPr")[0];
|
|
1623
|
+
return cNvPr === void 0 ? void 0 : attr(cNvPr, "name");
|
|
1624
|
+
}
|
|
1625
|
+
function mergeRunProperties(base, override) {
|
|
1626
|
+
return {
|
|
1627
|
+
fontFamily: override.fontFamily ?? base.fontFamily,
|
|
1628
|
+
sizePt: override.sizePt ?? base.sizePt,
|
|
1629
|
+
bold: override.bold ?? base.bold,
|
|
1630
|
+
italic: override.italic ?? base.italic,
|
|
1631
|
+
color: override.color ?? base.color
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
function isUnderlined(rPr) {
|
|
1635
|
+
if (rPr === void 0) return;
|
|
1636
|
+
const u = attr(rPr, "u");
|
|
1637
|
+
return u === void 0 ? void 0 : u !== "none";
|
|
1638
|
+
}
|
|
1639
|
+
function isStrikethrough(rPr) {
|
|
1640
|
+
if (rPr === void 0) return;
|
|
1641
|
+
const strike = attr(rPr, "strike");
|
|
1642
|
+
return strike === void 0 ? void 0 : strike !== "noStrike";
|
|
1643
|
+
}
|
|
1644
|
+
function readHyperlink(rPr, slideRels) {
|
|
1645
|
+
if (rPr === void 0) return;
|
|
1646
|
+
const hlink = childrenWithTag(rPr, "a:hlinkClick")[0];
|
|
1647
|
+
const rId = hlink === void 0 ? void 0 : attr(hlink, "r:id");
|
|
1648
|
+
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
1649
|
+
return rel?.targetMode === "External" ? rel.target : void 0;
|
|
1650
|
+
}
|
|
1651
|
+
function readRun(runEl, cascadeBase, context, slideRels) {
|
|
1652
|
+
const rPr = childrenWithTag(runEl, "a:rPr")[0];
|
|
1653
|
+
const merged = mergeRunProperties(cascadeBase, rPr === void 0 ? {} : readRunPropertiesFromElement(rPr, context));
|
|
1654
|
+
const tEl = childrenWithTag(runEl, "a:t")[0];
|
|
1655
|
+
return {
|
|
1656
|
+
text: tEl === void 0 ? "" : textContent(tEl),
|
|
1657
|
+
bold: merged.bold,
|
|
1658
|
+
italic: merged.italic,
|
|
1659
|
+
underline: isUnderlined(rPr),
|
|
1660
|
+
strike: isStrikethrough(rPr),
|
|
1661
|
+
fontFamily: merged.fontFamily,
|
|
1662
|
+
sizePt: merged.sizePt,
|
|
1663
|
+
color: merged.color,
|
|
1664
|
+
hyperlink: readHyperlink(rPr, slideRels)
|
|
1665
|
+
};
|
|
694
1666
|
}
|
|
695
|
-
function
|
|
696
|
-
|
|
1667
|
+
function readAlignment(algn) {
|
|
1668
|
+
if (algn === "l") return "left";
|
|
1669
|
+
if (algn === "ctr") return "center";
|
|
1670
|
+
if (algn === "r") return "right";
|
|
1671
|
+
if (algn === "just" || algn === "justLow") return "justify";
|
|
1672
|
+
}
|
|
1673
|
+
function readAbsoluteSpacingPt(spc) {
|
|
1674
|
+
if (spc === void 0) return;
|
|
1675
|
+
const pts = childrenWithTag(spc, "a:spcPts")[0];
|
|
1676
|
+
const val = pts === void 0 ? void 0 : attr(pts, "val");
|
|
1677
|
+
return val === void 0 ? void 0 : drawingMlFontSizeToPt(Number(val));
|
|
1678
|
+
}
|
|
1679
|
+
function readLineSpacingMultiplier(pPr) {
|
|
1680
|
+
const lnSpc = pPr === void 0 ? void 0 : childrenWithTag(pPr, "a:lnSpc")[0];
|
|
1681
|
+
const pct = lnSpc === void 0 ? void 0 : childrenWithTag(lnSpc, "a:spcPct")[0];
|
|
1682
|
+
const val = pct === void 0 ? void 0 : attr(pct, "val");
|
|
1683
|
+
return val === void 0 ? void 0 : Number(val) / 1e5;
|
|
1684
|
+
}
|
|
1685
|
+
function readParagraph(pEl, placeholderType, context, slideRels) {
|
|
1686
|
+
const pPr = childrenWithTag(pEl, "a:pPr")[0];
|
|
1687
|
+
const masterDefaults = resolveDefaultRunProperties(placeholderType, pPr === void 0 ? 0 : Number(attr(pPr, "lvl") ?? "0"), context);
|
|
1688
|
+
const pPrDefRPr = pPr === void 0 ? void 0 : childrenWithTag(pPr, "a:defRPr")[0];
|
|
1689
|
+
const paragraphDefaults = pPrDefRPr === void 0 ? masterDefaults : mergeRunProperties(masterDefaults, readRunPropertiesFromElement(pPrDefRPr, context));
|
|
1690
|
+
const runs = [];
|
|
1691
|
+
for (const child of pEl.children) {
|
|
1692
|
+
if (child.type !== "element") continue;
|
|
1693
|
+
if (child.tag === "a:r" || child.tag === "a:fld") runs.push(readRun(child, paragraphDefaults, context, slideRels));
|
|
1694
|
+
else if (child.tag === "a:br") runs.push({ text: "\n" });
|
|
1695
|
+
}
|
|
1696
|
+
const marL = pPr === void 0 ? void 0 : attr(pPr, "marL");
|
|
1697
|
+
const indent = pPr === void 0 ? void 0 : attr(pPr, "indent");
|
|
1698
|
+
return {
|
|
1699
|
+
kind: "paragraph",
|
|
1700
|
+
runs,
|
|
1701
|
+
alignment: pPr === void 0 ? void 0 : readAlignment(attr(pPr, "algn")),
|
|
1702
|
+
spacingBeforePt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : childrenWithTag(pPr, "a:spcBef")[0]),
|
|
1703
|
+
spacingAfterPt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : childrenWithTag(pPr, "a:spcAft")[0]),
|
|
1704
|
+
lineSpacing: readLineSpacingMultiplier(pPr),
|
|
1705
|
+
indentLeftPt: marL === void 0 ? void 0 : emuToPt(Number(marL)),
|
|
1706
|
+
indentFirstLinePt: indent === void 0 ? void 0 : emuToPt(Number(indent))
|
|
1707
|
+
};
|
|
697
1708
|
}
|
|
698
|
-
function
|
|
699
|
-
return
|
|
1709
|
+
function textBodyParagraphs(txBody, placeholderType, context, slideRels) {
|
|
1710
|
+
return txBody === void 0 ? [] : childrenWithTag(txBody, "a:p").map((p) => readParagraph(p, placeholderType, context, slideRels));
|
|
1711
|
+
}
|
|
1712
|
+
const DEFAULT_INSET_LEFT_RIGHT_EMU = 91440;
|
|
1713
|
+
const DEFAULT_INSET_TOP_BOTTOM_EMU = 45720;
|
|
1714
|
+
const NO_TEXT_BODY_EXTRAS = {
|
|
1715
|
+
insetLeftPt: 0,
|
|
1716
|
+
insetTopPt: 0,
|
|
1717
|
+
insetRightPt: 0,
|
|
1718
|
+
insetBottomPt: 0,
|
|
1719
|
+
fontScale: void 0,
|
|
1720
|
+
lineSpacingReduction: void 0
|
|
1721
|
+
};
|
|
1722
|
+
function readShapeTextExtras(txBody) {
|
|
1723
|
+
if (txBody === void 0) return NO_TEXT_BODY_EXTRAS;
|
|
1724
|
+
const bodyPr = childrenWithTag(txBody, "a:bodyPr")[0];
|
|
1725
|
+
const lIns = bodyPr === void 0 ? void 0 : attr(bodyPr, "lIns");
|
|
1726
|
+
const tIns = bodyPr === void 0 ? void 0 : attr(bodyPr, "tIns");
|
|
1727
|
+
const rIns = bodyPr === void 0 ? void 0 : attr(bodyPr, "rIns");
|
|
1728
|
+
const bIns = bodyPr === void 0 ? void 0 : attr(bodyPr, "bIns");
|
|
1729
|
+
const normAutofit = bodyPr === void 0 ? void 0 : childrenWithTag(bodyPr, "a:normAutofit")[0];
|
|
1730
|
+
const fontScale = normAutofit === void 0 ? void 0 : attr(normAutofit, "fontScale");
|
|
1731
|
+
const lnSpcReduction = normAutofit === void 0 ? void 0 : attr(normAutofit, "lnSpcReduction");
|
|
1732
|
+
return {
|
|
1733
|
+
insetLeftPt: emuToPt(lIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(lIns)),
|
|
1734
|
+
insetTopPt: emuToPt(tIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(tIns)),
|
|
1735
|
+
insetRightPt: emuToPt(rIns === void 0 ? DEFAULT_INSET_LEFT_RIGHT_EMU : Number(rIns)),
|
|
1736
|
+
insetBottomPt: emuToPt(bIns === void 0 ? DEFAULT_INSET_TOP_BOTTOM_EMU : Number(bIns)),
|
|
1737
|
+
fontScale: fontScale === void 0 ? void 0 : Number(fontScale) / 1e5,
|
|
1738
|
+
lineSpacingReduction: lnSpcReduction === void 0 ? void 0 : Number(lnSpcReduction) / 1e5
|
|
1739
|
+
};
|
|
700
1740
|
}
|
|
701
|
-
function
|
|
702
|
-
|
|
1741
|
+
function resolveShapeFrame(shape, context, parentTransform) {
|
|
1742
|
+
const key = readPlaceholderKey(shape);
|
|
1743
|
+
const spPr = childrenWithTag(shape, "p:spPr")[0];
|
|
1744
|
+
const xfrm = (spPr === void 0 ? void 0 : readXfrm(childrenWithTag(spPr, "a:xfrm")[0])) ?? (key === void 0 ? void 0 : resolvePlaceholderXfrm(key, context));
|
|
1745
|
+
if (xfrm === void 0) return;
|
|
1746
|
+
const localFrame = {
|
|
1747
|
+
xPt: xfrm.xPt,
|
|
1748
|
+
yPt: xfrm.yPt,
|
|
1749
|
+
widthPt: xfrm.widthPt,
|
|
1750
|
+
heightPt: xfrm.heightPt
|
|
1751
|
+
};
|
|
1752
|
+
return {
|
|
1753
|
+
frame: parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame),
|
|
1754
|
+
rotationDeg: xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg
|
|
1755
|
+
};
|
|
703
1756
|
}
|
|
704
|
-
function
|
|
705
|
-
|
|
1757
|
+
function readSpShape(sp, context, slideRels, parentTransform) {
|
|
1758
|
+
const resolved = resolveShapeFrame(sp, context, parentTransform);
|
|
1759
|
+
if (resolved === void 0) return;
|
|
1760
|
+
const key = readPlaceholderKey(sp);
|
|
1761
|
+
const txBody = childrenWithTag(sp, "p:txBody")[0];
|
|
1762
|
+
const blocks = textBodyParagraphs(txBody, key?.type, context, slideRels);
|
|
1763
|
+
const extras = readShapeTextExtras(txBody);
|
|
1764
|
+
return {
|
|
1765
|
+
name: shapeName(sp),
|
|
1766
|
+
frame: resolved.frame,
|
|
1767
|
+
rotationDeg: resolved.rotationDeg,
|
|
1768
|
+
...extras,
|
|
1769
|
+
blocks
|
|
1770
|
+
};
|
|
706
1771
|
}
|
|
1772
|
+
function readPicShape(pic, context, slideRels, pkg, parentTransform) {
|
|
1773
|
+
const resolved = resolveShapeFrame(pic, context, parentTransform);
|
|
1774
|
+
if (resolved === void 0) return;
|
|
1775
|
+
const blipFill = childrenWithTag(pic, "p:blipFill")[0];
|
|
1776
|
+
const blip = blipFill === void 0 ? void 0 : childrenWithTag(blipFill, "a:blip")[0];
|
|
1777
|
+
const rId = blip === void 0 ? void 0 : attr(blip, "r:embed");
|
|
1778
|
+
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
1779
|
+
const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
|
|
1780
|
+
const blocks = [];
|
|
1781
|
+
if (mediaPart?.kind === "binary") {
|
|
1782
|
+
const format = sniffImageFormat(base64ToBytes(mediaPart.base64));
|
|
1783
|
+
if (format !== void 0) {
|
|
1784
|
+
const image = {
|
|
1785
|
+
kind: "image",
|
|
1786
|
+
format,
|
|
1787
|
+
base64: mediaPart.base64,
|
|
1788
|
+
widthPt: resolved.frame.widthPt,
|
|
1789
|
+
heightPt: resolved.frame.heightPt
|
|
1790
|
+
};
|
|
1791
|
+
blocks.push(image);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
return {
|
|
1795
|
+
name: shapeName(pic),
|
|
1796
|
+
frame: resolved.frame,
|
|
1797
|
+
rotationDeg: resolved.rotationDeg,
|
|
1798
|
+
...NO_TEXT_BODY_EXTRAS,
|
|
1799
|
+
blocks
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
function readTableCell(tc, context, slideRels) {
|
|
1803
|
+
const hMerge = attr(tc, "hMerge");
|
|
1804
|
+
const vMerge = attr(tc, "vMerge");
|
|
1805
|
+
if (hMerge === "1" || vMerge === "1") return { blocks: [] };
|
|
1806
|
+
const tcPr = childrenWithTag(tc, "a:tcPr")[0];
|
|
1807
|
+
const background = readSolidFillColor(tcPr === void 0 ? void 0 : childrenWithTag(tcPr, "a:solidFill")[0], context.colorMap, context.theme);
|
|
1808
|
+
const txBody = childrenWithTag(tc, "a:txBody")[0];
|
|
1809
|
+
const gridSpan = attr(tc, "gridSpan");
|
|
1810
|
+
const rowSpan = attr(tc, "rowSpan");
|
|
1811
|
+
return {
|
|
1812
|
+
blocks: textBodyParagraphs(txBody, void 0, context, slideRels),
|
|
1813
|
+
colSpan: gridSpan === void 0 ? void 0 : Number(gridSpan),
|
|
1814
|
+
rowSpan: rowSpan === void 0 ? void 0 : Number(rowSpan),
|
|
1815
|
+
background
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
function readTable(tbl, context, slideRels) {
|
|
1819
|
+
const tblGrid = childrenWithTag(tbl, "a:tblGrid")[0];
|
|
1820
|
+
const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag(tblGrid, "a:gridCol").map((col) => emuToPt(Number(attr(col, "w") ?? "0")));
|
|
1821
|
+
return {
|
|
1822
|
+
kind: "table",
|
|
1823
|
+
rows: childrenWithTag(tbl, "a:tr").map((tr) => {
|
|
1824
|
+
const h = attr(tr, "h");
|
|
1825
|
+
return {
|
|
1826
|
+
cells: childrenWithTag(tr, "a:tc").map((tc) => readTableCell(tc, context, slideRels)),
|
|
1827
|
+
heightPt: h === void 0 ? void 0 : emuToPt(Number(h))
|
|
1828
|
+
};
|
|
1829
|
+
}),
|
|
1830
|
+
columnWidthsPt
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
function readGraphicFrameShape(gf, context, slideRels, parentTransform) {
|
|
1834
|
+
const xfrm = readXfrm(childrenWithTag(gf, "p:xfrm")[0]);
|
|
1835
|
+
if (xfrm === void 0) return;
|
|
1836
|
+
const localFrame = {
|
|
1837
|
+
xPt: xfrm.xPt,
|
|
1838
|
+
yPt: xfrm.yPt,
|
|
1839
|
+
widthPt: xfrm.widthPt,
|
|
1840
|
+
heightPt: xfrm.heightPt
|
|
1841
|
+
};
|
|
1842
|
+
const frame = parentTransform === void 0 ? localFrame : applyGroupTransform(parentTransform, localFrame);
|
|
1843
|
+
const rotationDeg = xfrm.rotationDeg === 0 ? void 0 : xfrm.rotationDeg;
|
|
1844
|
+
const graphic = childrenWithTag(gf, "a:graphic")[0];
|
|
1845
|
+
const graphicData = graphic === void 0 ? void 0 : childrenWithTag(graphic, "a:graphicData")[0];
|
|
1846
|
+
const tbl = (graphicData === void 0 ? void 0 : attr(graphicData, "uri")) === TABLE_GRAPHIC_URI && graphicData !== void 0 ? childrenWithTag(graphicData, "a:tbl")[0] : void 0;
|
|
1847
|
+
const blocks = tbl === void 0 ? [] : [readTable(tbl, context, slideRels)];
|
|
1848
|
+
return {
|
|
1849
|
+
name: shapeName(gf),
|
|
1850
|
+
frame,
|
|
1851
|
+
rotationDeg,
|
|
1852
|
+
...NO_TEXT_BODY_EXTRAS,
|
|
1853
|
+
blocks
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
function walkShapeTreeChildren(children, parentTransform, context, slideRels, pkg, out) {
|
|
1857
|
+
for (const node of children) {
|
|
1858
|
+
if (node.type !== "element") continue;
|
|
1859
|
+
if (node.tag === "p:sp") {
|
|
1860
|
+
const shape = readSpShape(node, context, slideRels, parentTransform);
|
|
1861
|
+
if (shape !== void 0) out.push(shape);
|
|
1862
|
+
} else if (node.tag === "p:pic") {
|
|
1863
|
+
const shape = readPicShape(node, context, slideRels, pkg, parentTransform);
|
|
1864
|
+
if (shape !== void 0) out.push(shape);
|
|
1865
|
+
} else if (node.tag === "p:graphicFrame") {
|
|
1866
|
+
const shape = readGraphicFrameShape(node, context, slideRels, parentTransform);
|
|
1867
|
+
if (shape !== void 0) out.push(shape);
|
|
1868
|
+
} else if (node.tag === "p:grpSp") {
|
|
1869
|
+
const grpSpPr = childrenWithTag(node, "p:grpSpPr")[0];
|
|
1870
|
+
const composed = composeGroupTransform(readGroupXfrm(grpSpPr === void 0 ? void 0 : childrenWithTag(grpSpPr, "a:xfrm")[0]), parentTransform);
|
|
1871
|
+
walkShapeTreeChildren(node.children, composed, context, slideRels, pkg, out);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
function composeGroupTransform(own, parent) {
|
|
1876
|
+
if (own === void 0) return;
|
|
1877
|
+
if (parent === void 0) return own;
|
|
1878
|
+
const absolute = applyGroupTransform(parent, {
|
|
1879
|
+
xPt: own.offXPt,
|
|
1880
|
+
yPt: own.offYPt,
|
|
1881
|
+
widthPt: own.extWidthPt,
|
|
1882
|
+
heightPt: own.extHeightPt
|
|
1883
|
+
});
|
|
1884
|
+
return {
|
|
1885
|
+
...own,
|
|
1886
|
+
offXPt: absolute.xPt,
|
|
1887
|
+
offYPt: absolute.yPt,
|
|
1888
|
+
extWidthPt: absolute.widthPt,
|
|
1889
|
+
extHeightPt: absolute.heightPt
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1892
|
+
const NOTES_SLIDE_REL_SUFFIX = "/notesSlide";
|
|
707
1893
|
function readNotes(pkg, slidePath) {
|
|
708
|
-
const rels = resolveRelationships(pkg, slidePath);
|
|
709
1894
|
let notesPath;
|
|
710
|
-
for (const rel of
|
|
1895
|
+
for (const rel of resolveRelationships(pkg, slidePath).values()) if (rel.type.endsWith(NOTES_SLIDE_REL_SUFFIX)) {
|
|
711
1896
|
notesPath = rel.target;
|
|
712
1897
|
break;
|
|
713
1898
|
}
|
|
714
1899
|
if (notesPath === void 0) return "";
|
|
715
|
-
const
|
|
716
|
-
if (
|
|
717
|
-
|
|
1900
|
+
const notesRoot = rootElement(pkg.parts[notesPath]);
|
|
1901
|
+
if (notesRoot === void 0) return "";
|
|
1902
|
+
const bodyShape = elementsWithTag([notesRoot], "p:sp").find((shape) => {
|
|
1903
|
+
const key = readPlaceholderKey(shape);
|
|
1904
|
+
return key !== void 0 && (key.type === void 0 || key.type === "body");
|
|
1905
|
+
});
|
|
1906
|
+
if (bodyShape !== void 0) {
|
|
1907
|
+
const txBody = childrenWithTag(bodyShape, "p:txBody")[0];
|
|
1908
|
+
if (txBody !== void 0) return elementsWithTag(txBody.children, "a:t").map(textContent).join("");
|
|
1909
|
+
}
|
|
1910
|
+
return elementsWithTag([notesRoot], "a:t").map(textContent).join("");
|
|
1911
|
+
}
|
|
1912
|
+
function readSlide(pkg, slidePath, size) {
|
|
1913
|
+
const slideRoot = rootElement(pkg.parts[slidePath]);
|
|
1914
|
+
const context = resolveSlideInheritance(pkg, slidePath);
|
|
1915
|
+
const slideRels = resolveRelationships(pkg, slidePath);
|
|
1916
|
+
const cSld = slideRoot === void 0 ? void 0 : childrenWithTag(slideRoot, "p:cSld")[0];
|
|
1917
|
+
const spTree = cSld === void 0 ? void 0 : childrenWithTag(cSld, "p:spTree")[0];
|
|
1918
|
+
const shapes = [];
|
|
1919
|
+
if (spTree !== void 0) walkShapeTreeChildren(spTree.children, void 0, context, slideRels, pkg, shapes);
|
|
1920
|
+
return {
|
|
1921
|
+
size,
|
|
1922
|
+
shapes,
|
|
1923
|
+
notes: readNotes(pkg, slidePath)
|
|
1924
|
+
};
|
|
718
1925
|
}
|
|
719
1926
|
function readPptx(pkg) {
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const index = Number(captured);
|
|
728
|
-
const text = elementsWithTag(part.nodes, "a:t").map(textContent).join("");
|
|
729
|
-
const shapes = elementsWithTag(part.nodes, "p:sp").map(readShape);
|
|
730
|
-
const tables = elementsWithTag(part.nodes, "a:tbl").map(readTable);
|
|
731
|
-
const notes = readNotes(pkg, path);
|
|
732
|
-
found.push({
|
|
733
|
-
index,
|
|
734
|
-
text,
|
|
735
|
-
shapes,
|
|
736
|
-
tables,
|
|
737
|
-
notes
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
found.sort((a, b) => a.index - b.index);
|
|
741
|
-
return { slides: found };
|
|
1927
|
+
const presentationRoot = rootElement(pkg.parts[PRESENTATION_PATH]);
|
|
1928
|
+
const size = readSlideSize(presentationRoot);
|
|
1929
|
+
const slides = readSlidePathsInOrder(pkg, presentationRoot).map((slidePath) => readSlide(pkg, slidePath, size));
|
|
1930
|
+
return {
|
|
1931
|
+
metadata: readCoreProperties(pkg),
|
|
1932
|
+
slides
|
|
1933
|
+
};
|
|
742
1934
|
}
|
|
743
1935
|
//#endregion
|
|
744
1936
|
//#region src/typed/xlsx.ts
|
|
@@ -883,4 +2075,4 @@ function readXlsx(pkg) {
|
|
|
883
2075
|
};
|
|
884
2076
|
}
|
|
885
2077
|
//#endregion
|
|
886
|
-
export { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema,
|
|
2078
|
+
export { AlignmentSchema, AttributeSchema, BinaryPartSchema, BoxSchema, COLOR_BLACK, ColorSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentImageBlockSchema, ContentListMembershipSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DefinedNameSchema, DocumentMetadataSchema, DocxDocumentSchema, FootnoteSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PageSizeSchema, PartSchema, PptxDocumentSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XlsxCellSchema, XlsxSheetSchema, XlsxWorkbookSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, applyColorTransforms, attr, base64ToBytes, buildXml, bytesToBase64, childrenWithTag, colorToRgbHex, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, elementsWithTag, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, resolveRelationships, rgbHexToColor, rootElement, serializePackage, sniffImageFormat, textContent, toCompact, unzipPackage, walk, xmlCodec, zipPackage };
|