pptx-glimpse 3.1.1 → 3.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/dist/cli.cjs CHANGED
@@ -6600,1739 +6600,1754 @@ function parseEnumValue(value, allowed) {
6600
6600
  function parseEnumValueWithDefault(value, allowed, fallback) {
6601
6601
  return parseEnumValue(value, allowed) ?? fallback;
6602
6602
  }
6603
- var KNOWN_TXBODY_CHILDREN = /* @__PURE__ */ new Set(["bodyPr", "lstStyle", "p"]);
6604
- var KNOWN_PARAGRAPH_CHILDREN = /* @__PURE__ */ new Set([
6605
- "pPr",
6603
+ var RECTANGLE_ALIGNMENT_TOKENS = /* @__PURE__ */ new Set([
6604
+ "tl",
6605
+ "t",
6606
+ "tr",
6607
+ "l",
6608
+ "ctr",
6606
6609
  "r",
6607
- "fld",
6608
- "br",
6609
- "endParaRPr"
6610
+ "bl",
6611
+ "b",
6612
+ "br"
6610
6613
  ]);
6611
- var KNOWN_RUN_CHILDREN = /* @__PURE__ */ new Set(["rPr", "t"]);
6612
- var KNOWN_RUN_PROPERTY_CHILDREN = /* @__PURE__ */ new Set([
6613
- "latin",
6614
- "ea",
6615
- "cs",
6616
- "solidFill"
6614
+ var COLOR_TRANSFORM_KINDS = /* @__PURE__ */ new Set([
6615
+ "lumMod",
6616
+ "lumOff",
6617
+ "tint",
6618
+ "shade",
6619
+ "alpha"
6617
6620
  ]);
6618
- var ALIGN_MAP = {
6619
- l: "left",
6620
- ctr: "center",
6621
- r: "right",
6622
- just: "justify"
6623
- };
6624
- var ANCHOR_MAP = {
6625
- t: "top",
6626
- ctr: "middle",
6627
- b: "bottom"
6621
+ var RAW_FILL_LOCAL_NAMES = ["grpFill"];
6622
+ var PRESET_COLOR_HEX = {
6623
+ black: "000000",
6624
+ white: "FFFFFF",
6625
+ red: "FF0000",
6626
+ green: "008000",
6627
+ blue: "0000FF",
6628
+ yellow: "FFFF00",
6629
+ cyan: "00FFFF",
6630
+ magenta: "FF00FF"
6628
6631
  };
6629
- var WRAP_VALUES = /* @__PURE__ */ new Set(["square", "none"]);
6630
- var VERTICAL_VALUES = /* @__PURE__ */ new Set([
6631
- "horz",
6632
- "vert",
6633
- "vert270",
6634
- "eaVert",
6635
- "wordArtVert",
6636
- "mongolianVert"
6637
- ]);
6638
- var VALID_AUTO_NUM_SCHEMES = /* @__PURE__ */ new Set([
6639
- "arabicPeriod",
6640
- "arabicParenR",
6641
- "romanUcPeriod",
6642
- "romanLcPeriod",
6643
- "alphaUcPeriod",
6644
- "alphaLcPeriod",
6645
- "alphaLcParenR",
6646
- "alphaUcParenR",
6647
- "arabicPlain"
6648
- ]);
6649
- function parseTextBody(txBody, partPath, nextId, ownerNodeId, ownerOrderingSlot, orderedTxBody) {
6650
- if (!txBody) return void 0;
6651
- const properties = parseBodyProperties(getChild(txBody, "bodyPr"));
6652
- const listStyle = parseTextStyle(getChild(txBody, "lstStyle"));
6653
- const orderedParagraphs = orderedTxBody?.filter((child) => orderedLocalName(child) === "p").map((child) => {
6654
- const key = orderedKey(child);
6655
- const value = key !== void 0 ? child[key] : void 0;
6656
- return Array.isArray(value) ? value : void 0;
6657
- });
6658
- const paragraphs = [];
6659
- let logicalParagraphIndex = 0;
6660
- getChildArray(txBody, "p").forEach((p, paragraphIndex) => {
6661
- const orderedChildren = orderedParagraphs?.[paragraphIndex];
6662
- if (orderedChildren !== void 0 && hasMultipleBulletPPr(p, orderedChildren)) {
6663
- const split = splitInterleavedParagraph(
6664
- p,
6665
- orderedChildren,
6666
- partPath,
6667
- nextId,
6668
- ownerNodeId,
6669
- ownerOrderingSlot,
6670
- logicalParagraphIndex
6632
+ function parseColorElement(parent) {
6633
+ if (!parent) return void 0;
6634
+ const srgb = getChild(parent, "srgbClr");
6635
+ if (srgb) {
6636
+ const hex = getAttr(srgb, "val");
6637
+ if (hex !== void 0) {
6638
+ return withTransforms({ kind: "srgb", hex: hex.toUpperCase() }, srgb);
6639
+ }
6640
+ }
6641
+ const scheme = getChild(parent, "schemeClr");
6642
+ if (scheme) {
6643
+ const name = getAttr(scheme, "val");
6644
+ if (name !== void 0) {
6645
+ return withTransforms({ kind: "scheme", scheme: name }, scheme);
6646
+ }
6647
+ }
6648
+ const sys = getChild(parent, "sysClr");
6649
+ if (sys) {
6650
+ const val = getAttr(sys, "val");
6651
+ if (val !== void 0) {
6652
+ const lastClr = getAttr(sys, "lastClr");
6653
+ return withTransforms(
6654
+ {
6655
+ kind: "system",
6656
+ value: val,
6657
+ ...lastClr !== void 0 ? { lastColor: lastClr.toUpperCase() } : {}
6658
+ },
6659
+ sys
6671
6660
  );
6672
- paragraphs.push(...split);
6673
- logicalParagraphIndex += split.length;
6674
- return;
6675
6661
  }
6676
- paragraphs.push(
6677
- parseParagraph(
6678
- p,
6679
- partPath,
6680
- nextId,
6681
- ownerNodeId,
6682
- ownerOrderingSlot,
6683
- logicalParagraphIndex,
6684
- orderedChildren
6685
- )
6686
- );
6687
- logicalParagraphIndex++;
6688
- });
6689
- const rawSidecars = collectUnknownSidecars(txBody, KNOWN_TXBODY_CHILDREN, nextId);
6662
+ }
6663
+ return void 0;
6664
+ }
6665
+ function parseEffectList(effectList) {
6666
+ if (effectList === void 0) return void 0;
6667
+ const outerShadow = parseOuterShadow(getChild(effectList, "outerShdw"));
6668
+ const innerShadow = parseInnerShadow(getChild(effectList, "innerShdw"));
6669
+ const glow = parseGlow(getChild(effectList, "glow"));
6670
+ const softEdge = parseSoftEdge(getChild(effectList, "softEdge"));
6671
+ const parsed = {
6672
+ ...outerShadow !== void 0 ? { outerShadow } : {},
6673
+ ...innerShadow !== void 0 ? { innerShadow } : {},
6674
+ ...glow !== void 0 ? { glow } : {},
6675
+ ...softEdge !== void 0 ? { softEdge } : {}
6676
+ };
6677
+ return Object.keys(parsed).length > 0 ? parsed : void 0;
6678
+ }
6679
+ function parseBlipEffects(blip) {
6680
+ if (blip === void 0) return void 0;
6681
+ const grayscale = getChild(blip, "grayscl") !== void 0;
6682
+ const biLevel = parseBiLevel(getChild(blip, "biLevel"));
6683
+ const blur = parseBlurEffect(getChild(blip, "blur"));
6684
+ const lum = parseLumEffect(getChild(blip, "lum"));
6685
+ const duotone = parseDuotoneEffect(getChild(blip, "duotone"));
6686
+ const clrChange = parseColorChangeEffect(getChild(blip, "clrChange"));
6687
+ const parsed = {
6688
+ grayscale,
6689
+ ...biLevel !== void 0 ? { biLevel } : {},
6690
+ ...blur !== void 0 ? { blur } : {},
6691
+ ...lum !== void 0 ? { lum } : {},
6692
+ ...duotone !== void 0 ? { duotone } : {},
6693
+ ...clrChange !== void 0 ? { clrChange } : {}
6694
+ };
6695
+ return grayscale || biLevel !== void 0 || blur !== void 0 || lum !== void 0 || duotone !== void 0 || clrChange !== void 0 ? parsed : void 0;
6696
+ }
6697
+ function parseOuterShadow(node) {
6698
+ if (node === void 0) return void 0;
6699
+ const color = parseColorElement(node);
6700
+ if (color === void 0) return void 0;
6690
6701
  return {
6691
- paragraphs,
6692
- ...properties !== void 0 ? { properties } : {},
6693
- ...listStyle !== void 0 ? { listStyle } : {},
6694
- handle: { partPath },
6695
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
6702
+ blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
6703
+ distance: asEmu2(numericAttr2(node, "dist") ?? 0),
6704
+ direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
6705
+ color,
6706
+ alignment: parseRectangleAlignment(getAttr(node, "algn"), "b"),
6707
+ rotateWithShape: getAttr(node, "rotWithShape") !== "0"
6696
6708
  };
6697
6709
  }
6698
- function parseTextStyle(node) {
6710
+ function parseInnerShadow(node) {
6699
6711
  if (node === void 0) return void 0;
6700
- const defaultParagraph = parseParagraphProperties(getChild(node, "defPPr"));
6701
- const levels = Array.from(
6702
- { length: 9 },
6703
- (_, index) => parseParagraphProperties(getChild(node, `lvl${index + 1}pPr`))
6704
- );
6705
- if (defaultParagraph === void 0 && levels.every((level) => level === void 0)) {
6706
- return void 0;
6707
- }
6708
- return { ...defaultParagraph !== void 0 ? { defaultParagraph } : {}, levels };
6712
+ const color = parseColorElement(node);
6713
+ if (color === void 0) return void 0;
6714
+ return {
6715
+ blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
6716
+ distance: asEmu2(numericAttr2(node, "dist") ?? 0),
6717
+ direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
6718
+ color
6719
+ };
6709
6720
  }
6710
- function hasMultipleBulletPPr(p, orderedChildren) {
6711
- const pPrList = getChildArray(p, "pPr");
6712
- let bulletPPrCount = 0;
6713
- let pPrCounter = 0;
6714
- for (const child of orderedChildren) {
6715
- if (orderedLocalName(child) !== "pPr") continue;
6716
- const pPr = pPrList[pPrCounter];
6717
- if (pPr !== void 0 && (getChild(pPr, "buChar") !== void 0 || getChild(pPr, "buAutoNum") !== void 0)) {
6718
- bulletPPrCount++;
6719
- if (bulletPPrCount >= 2) return true;
6720
- }
6721
- pPrCounter++;
6722
- }
6723
- return false;
6721
+ function parseGlow(node) {
6722
+ if (node === void 0) return void 0;
6723
+ const color = parseColorElement(node);
6724
+ if (color === void 0) return void 0;
6725
+ return {
6726
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0),
6727
+ color
6728
+ };
6724
6729
  }
6725
- function splitInterleavedParagraph(p, orderedChildren, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex) {
6726
- const pPrList = getChildArray(p, "pPr");
6727
- const rList = getChildArray(p, "r");
6728
- const fldList = getChildArray(p, "fld");
6729
- const brList = getChildArray(p, "br");
6730
- const groups = [];
6731
- let currentGroup;
6732
- let pPrCounter = 0;
6733
- let runCounter = 0;
6734
- let fieldCounter = 0;
6735
- let breakCounter = 0;
6736
- for (const child of orderedChildren) {
6737
- const tag = orderedLocalName(child);
6738
- if (tag === "pPr") {
6739
- const pPr = pPrList[pPrCounter];
6740
- const hasBullet = pPr !== void 0 && (getChild(pPr, "buChar") !== void 0 || getChild(pPr, "buAutoNum") !== void 0);
6741
- if (hasBullet || currentGroup === void 0) {
6742
- if (currentGroup !== void 0) groups.push(currentGroup);
6743
- currentGroup = {
6744
- pPrIndex: pPrCounter,
6745
- rNodes: [],
6746
- fldNodes: [],
6747
- brNodes: [],
6748
- orderedChildren: [child]
6749
- };
6750
- } else {
6751
- currentGroup.orderedChildren.push(child);
6752
- }
6753
- pPrCounter++;
6754
- } else if (tag === "r") {
6755
- currentGroup ??= {
6756
- pPrIndex: -1,
6757
- rNodes: [],
6758
- fldNodes: [],
6759
- brNodes: [],
6760
- orderedChildren: []
6761
- };
6762
- currentGroup.orderedChildren.push(child);
6763
- if (rList[runCounter] !== void 0) currentGroup.rNodes.push(rList[runCounter]);
6764
- runCounter++;
6765
- } else if (tag === "fld") {
6766
- currentGroup ??= {
6767
- pPrIndex: -1,
6768
- rNodes: [],
6769
- fldNodes: [],
6770
- brNodes: [],
6771
- orderedChildren: []
6772
- };
6773
- currentGroup.orderedChildren.push(child);
6774
- if (fldList[fieldCounter] !== void 0) currentGroup.fldNodes.push(fldList[fieldCounter]);
6775
- fieldCounter++;
6776
- } else if (tag === "br") {
6777
- currentGroup ??= {
6778
- pPrIndex: -1,
6779
- rNodes: [],
6780
- fldNodes: [],
6781
- brNodes: [],
6782
- orderedChildren: []
6783
- };
6784
- currentGroup.orderedChildren.push(child);
6785
- if (brList[breakCounter] !== void 0) currentGroup.brNodes.push(brList[breakCounter]);
6786
- breakCounter++;
6787
- }
6788
- }
6789
- if (currentGroup !== void 0) groups.push(currentGroup);
6790
- return groups.map((group, groupIndex) => {
6791
- const synthetic = {};
6792
- if (group.pPrIndex >= 0) synthetic.pPr = pPrList[group.pPrIndex];
6793
- synthetic.r = group.rNodes;
6794
- synthetic.fld = group.fldNodes;
6795
- synthetic.br = group.brNodes;
6796
- if (groupIndex === groups.length - 1 && getChild(p, "endParaRPr") !== void 0) {
6797
- synthetic.endParaRPr = getChild(p, "endParaRPr");
6798
- }
6799
- const paragraph = parseParagraph(
6800
- synthetic,
6801
- partPath,
6802
- nextId,
6803
- ownerNodeId,
6804
- ownerOrderingSlot,
6805
- paragraphIndex + groupIndex,
6806
- group.orderedChildren
6807
- );
6808
- if (groupIndex < groups.length - 1 && paragraph.runs.length > 0) {
6809
- const lastRun = paragraph.runs[paragraph.runs.length - 1];
6810
- if (lastRun.text.endsWith("\n")) {
6811
- const trimmed = lastRun.text.slice(0, -1);
6812
- const precedingRuns = paragraph.runs.slice(0, -1);
6813
- return {
6814
- ...paragraph,
6815
- runs: trimmed === "" ? precedingRuns : [...precedingRuns, { ...lastRun, text: trimmed }]
6816
- };
6817
- }
6818
- }
6819
- return paragraph;
6820
- });
6821
- }
6822
- function parseBodyProperties(bodyPr) {
6823
- if (!bodyPr) return void 0;
6824
- const marginLeft = numericAttr2(bodyPr, "lIns");
6825
- const marginRight = numericAttr2(bodyPr, "rIns");
6826
- const marginTop = numericAttr2(bodyPr, "tIns");
6827
- const marginBottom = numericAttr2(bodyPr, "bIns");
6828
- const anchorToken = getAttr(bodyPr, "anchor");
6829
- const anchor = anchorToken !== void 0 ? ANCHOR_MAP[anchorToken] : void 0;
6830
- const wrap = parseWrap(getAttr(bodyPr, "wrap"));
6831
- const vert = parseVerticalType(getAttr(bodyPr, "vert"));
6832
- const numCol = numericAttr2(bodyPr, "numCol");
6833
- const normAutofit = getChild(bodyPr, "normAutofit");
6834
- const hasSpAutofit = getChild(bodyPr, "spAutoFit") !== void 0;
6835
- const hasNoAutofit = getChild(bodyPr, "noAutofit") !== void 0;
6836
- const fontScale = numericAttr2(normAutofit, "fontScale");
6837
- const lnSpcReduction = numericAttr2(normAutofit, "lnSpcReduction");
6838
- const properties = {
6839
- ...marginLeft !== void 0 ? { marginLeft: emu(marginLeft) } : {},
6840
- ...marginRight !== void 0 ? { marginRight: emu(marginRight) } : {},
6841
- ...marginTop !== void 0 ? { marginTop: emu(marginTop) } : {},
6842
- ...marginBottom !== void 0 ? { marginBottom: emu(marginBottom) } : {},
6843
- ...anchor !== void 0 ? { anchor } : {},
6844
- ...wrap !== void 0 ? { wrap } : {},
6845
- ...normAutofit !== void 0 ? {
6846
- autoFit: "normAutofit",
6847
- fontScale: fontScale !== void 0 ? fontScale / 1e5 : 1,
6848
- lnSpcReduction: lnSpcReduction !== void 0 ? lnSpcReduction / 1e5 : 0
6849
- } : hasSpAutofit ? { autoFit: "spAutofit", fontScale: 1, lnSpcReduction: 0 } : hasNoAutofit ? { autoFit: "noAutofit", fontScale: 1, lnSpcReduction: 0 } : {},
6850
- ...numCol !== void 0 ? { numCol: Math.max(1, numCol) } : {},
6851
- ...vert !== void 0 ? { vert } : {}
6730
+ function parseSoftEdge(node) {
6731
+ if (node === void 0) return void 0;
6732
+ return {
6733
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0)
6852
6734
  };
6853
- return Object.keys(properties).length > 0 ? properties : void 0;
6854
6735
  }
6855
- function parseWrap(value) {
6856
- return parseEnumValue(value, WRAP_VALUES);
6736
+ function parseBiLevel(node) {
6737
+ if (node === void 0) return void 0;
6738
+ return {
6739
+ threshold: (numericAttr2(node, "thresh") ?? 5e4) / 1e5
6740
+ };
6857
6741
  }
6858
- function parseVerticalType(value) {
6859
- return parseEnumValue(value, VERTICAL_VALUES);
6742
+ function parseBlurEffect(node) {
6743
+ if (node === void 0) return void 0;
6744
+ return {
6745
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0),
6746
+ grow: getAttr(node, "grow") !== "0"
6747
+ };
6860
6748
  }
6861
- function parseParagraph(p, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, orderedChildren) {
6862
- const properties = parseParagraphProperties(getChild(p, "pPr"));
6863
- const runs = parseRunsInOrder(
6864
- p,
6865
- partPath,
6866
- nextId,
6867
- ownerNodeId,
6868
- ownerOrderingSlot,
6869
- paragraphIndex,
6870
- orderedChildren
6871
- );
6872
- const rawSidecars = collectUnknownSidecars(p, KNOWN_PARAGRAPH_CHILDREN, nextId);
6749
+ function parseLumEffect(node) {
6750
+ if (node === void 0) return void 0;
6873
6751
  return {
6874
- runs,
6875
- ...properties !== void 0 ? { properties } : {},
6876
- handle: {
6877
- partPath,
6878
- nodeId: textNodeId("paragraph", ownerNodeId, ownerOrderingSlot, paragraphIndex),
6879
- orderingSlot: paragraphIndex
6880
- },
6881
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
6752
+ brightness: (numericAttr2(node, "bright") ?? 0) / 1e5,
6753
+ contrast: (numericAttr2(node, "contrast") ?? 0) / 1e5
6882
6754
  };
6883
6755
  }
6884
- function parseRunsInOrder(p, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, orderedChildren) {
6885
- const rList = getChildArray(p, "r");
6886
- const fldList = getChildArray(p, "fld");
6887
- const brList = getChildArray(p, "br");
6888
- if (orderedChildren === void 0) {
6889
- return [
6890
- ...rList.map(
6891
- (r, runIndex) => parseRun(r, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex)
6892
- ),
6893
- ...fldList.map(
6894
- (fld, index) => parseRun(
6895
- fld,
6896
- partPath,
6897
- nextId,
6898
- ownerNodeId,
6899
- ownerOrderingSlot,
6900
- paragraphIndex,
6901
- rList.length + index
6902
- )
6903
- ),
6904
- ...brList.map(
6905
- (br, index) => parseBreakRun(
6906
- br,
6907
- partPath,
6908
- nextId,
6909
- ownerNodeId,
6910
- ownerOrderingSlot,
6911
- paragraphIndex,
6912
- rList.length + fldList.length + index
6913
- )
6914
- )
6915
- ];
6916
- }
6917
- const counters = {};
6918
- const runs = [];
6919
- for (const child of orderedChildren) {
6920
- const tag = orderedLocalName(child);
6921
- if (tag !== "r" && tag !== "fld" && tag !== "br") continue;
6922
- const index = counters[tag] ?? 0;
6923
- counters[tag] = index + 1;
6924
- const runIndex = runs.length;
6925
- if (tag === "r" && rList[index] !== void 0) {
6926
- runs.push(
6927
- parseRun(
6928
- rList[index],
6929
- partPath,
6930
- nextId,
6931
- ownerNodeId,
6932
- ownerOrderingSlot,
6933
- paragraphIndex,
6934
- runIndex
6935
- )
6936
- );
6937
- } else if (tag === "fld" && fldList[index] !== void 0) {
6938
- runs.push(
6939
- parseRun(
6940
- fldList[index],
6941
- partPath,
6942
- nextId,
6943
- ownerNodeId,
6944
- ownerOrderingSlot,
6945
- paragraphIndex,
6946
- runIndex
6947
- )
6948
- );
6949
- } else if (tag === "br" && brList[index] !== void 0) {
6950
- runs.push(
6951
- parseBreakRun(
6952
- brList[index],
6953
- partPath,
6954
- nextId,
6955
- ownerNodeId,
6956
- ownerOrderingSlot,
6957
- paragraphIndex,
6958
- runIndex
6959
- )
6960
- );
6756
+ function parseDuotoneEffect(node) {
6757
+ if (node === void 0) return void 0;
6758
+ const colors = collectColorChildren(node);
6759
+ if (colors.length < 2) return void 0;
6760
+ return { color1: colors[0], color2: colors[1] };
6761
+ }
6762
+ function parseColorChangeEffect(node) {
6763
+ if (node === void 0) return void 0;
6764
+ const from = firstColorChild(getChild(node, "clrFrom"));
6765
+ const to = firstColorChild(getChild(node, "clrTo"));
6766
+ return from !== void 0 && to !== void 0 ? { from, to } : void 0;
6767
+ }
6768
+ function collectColorChildren(parent) {
6769
+ const colors = [];
6770
+ for (const [key, value] of Object.entries(parent)) {
6771
+ if (key.startsWith("@_")) continue;
6772
+ const nodes = Array.isArray(value) ? value : [value];
6773
+ for (const node of nodes) {
6774
+ if (!isXmlNode(node)) continue;
6775
+ const color = parseColorChild(key, node);
6776
+ if (color !== void 0) colors.push(color);
6961
6777
  }
6962
6778
  }
6963
- return runs;
6779
+ return colors;
6964
6780
  }
6965
- function parseParagraphProperties(pPr) {
6966
- if (!pPr) return void 0;
6967
- const alignToken = getAttr(pPr, "algn");
6968
- const align = alignToken !== void 0 ? ALIGN_MAP[alignToken] : void 0;
6969
- const level = numericAttr2(pPr, "lvl");
6970
- const lineSpacing = parseSpacing(getChild(pPr, "lnSpc"));
6971
- const spaceBefore = parseSpacing(getChild(pPr, "spcBef"));
6972
- const spaceAfter = parseSpacing(getChild(pPr, "spcAft"));
6973
- const marginLeft = numericAttr2(pPr, "marL");
6974
- const indent = numericAttr2(pPr, "indent");
6975
- const bullet = parseBullet(pPr);
6976
- const bulletFont = getAttr(getChild(pPr, "buFont"), "typeface");
6977
- const bulletColor = parseColorElement(getChild(pPr, "buClr"));
6978
- const bulletSizePct = numericAttr2(getChild(pPr, "buSzPct"), "val");
6979
- const tabStops = parseTabStops(pPr);
6980
- const defaultRunProperties = parseRunProperties(getChild(pPr, "defRPr"));
6981
- const properties = {
6982
- ...align !== void 0 ? { align } : {},
6983
- ...level !== void 0 ? { level } : {},
6984
- ...lineSpacing !== void 0 ? { lineSpacing } : {},
6985
- ...spaceBefore !== void 0 ? { spaceBefore } : {},
6986
- ...spaceAfter !== void 0 ? { spaceAfter } : {},
6987
- ...marginLeft !== void 0 ? { marginLeft: emu(marginLeft) } : {},
6988
- ...indent !== void 0 ? { indent: emu(indent) } : {},
6989
- ...bullet !== void 0 ? { bullet } : {},
6990
- ...bulletFont !== void 0 ? { bulletFont } : {},
6991
- ...bulletColor !== void 0 ? { bulletColor } : {},
6992
- ...bulletSizePct !== void 0 ? { bulletSizePct } : {},
6993
- ...tabStops.length > 0 ? { tabStops } : {},
6994
- ...defaultRunProperties !== void 0 ? { defaultRunProperties } : {}
6995
- };
6996
- return Object.keys(properties).length > 0 ? properties : void 0;
6781
+ function firstColorChild(parent) {
6782
+ return parent !== void 0 ? collectColorChildren(parent)[0] : void 0;
6997
6783
  }
6998
- function parseTabStops(pPr) {
6999
- return getChildArray(getChild(pPr, "tabLst"), "tab").map((tab) => ({
7000
- position: emu(numericAttr2(tab, "pos") ?? 0),
7001
- alignment: unsafeOoxmlBoundaryAssertion(getAttr(tab, "algn")) ?? "l"
7002
- }));
6784
+ function parseColorChild(key, node) {
6785
+ const name = localName(key);
6786
+ return name === "prstClr" ? parsePresetColor(node) : parseColorElement({ [name]: node });
7003
6787
  }
7004
- function parseSpacing(node) {
7005
- const points = numericAttr2(getChild(node, "spcPts"), "val");
7006
- if (points !== void 0) return { type: "pts", value: asHundredthPt2(points) };
7007
- const percent = numericAttr2(getChild(node, "spcPct"), "val");
7008
- if (percent !== void 0) return { type: "pct", value: percent };
6788
+ function isXmlNode(value) {
6789
+ return typeof value === "object" && value !== null;
6790
+ }
6791
+ function parsePresetColor(node) {
6792
+ const value = getAttr(node, "val");
6793
+ const hex = value !== void 0 ? PRESET_COLOR_HEX[value] : void 0;
6794
+ return hex !== void 0 ? withTransforms({ kind: "srgb", hex }, node) : void 0;
6795
+ }
6796
+ function parseFill(parent, nextId) {
6797
+ if (!parent) return void 0;
6798
+ const solid = getChild(parent, "solidFill");
6799
+ if (solid) {
6800
+ const color = parseColorElement(solid);
6801
+ if (color) return { kind: "solid", color };
6802
+ return { kind: "raw", raw: makeSidecar("a:solidFill", solid, nextId) };
6803
+ }
6804
+ if (hasChild(parent, "noFill")) return { kind: "none" };
6805
+ const grad = getChild(parent, "gradFill");
6806
+ if (grad) {
6807
+ const fill = parseGradientFill(grad);
6808
+ return fill ?? { kind: "raw", raw: makeSidecar("a:gradFill", grad, nextId) };
6809
+ }
6810
+ const blip = getChild(parent, "blipFill");
6811
+ if (blip) {
6812
+ return parseBlipFill(blip) ?? { kind: "raw", raw: makeSidecar("a:blipFill", blip, nextId) };
6813
+ }
6814
+ const pattern = getChild(parent, "pattFill");
6815
+ if (pattern) {
6816
+ const fill = parsePatternFill(pattern);
6817
+ return fill ?? { kind: "raw", raw: makeSidecar("a:pattFill", pattern, nextId) };
6818
+ }
6819
+ for (const name of RAW_FILL_LOCAL_NAMES) {
6820
+ if (hasChild(parent, name)) {
6821
+ return { kind: "raw", raw: makeSidecar(`a:${name}`, getChild(parent, name) ?? {}, nextId) };
6822
+ }
6823
+ }
7009
6824
  return void 0;
7010
6825
  }
7011
- function parseBullet(pPr) {
7012
- if (pPr === void 0) return void 0;
7013
- if (getChild(pPr, "buNone") !== void 0) return { type: "none" };
7014
- const buChar = getChild(pPr, "buChar");
7015
- if (buChar !== void 0) {
7016
- return { type: "char", char: decodeXmlCharRef(getAttr(buChar, "char") ?? "\u2022") };
6826
+ function parseGradientFill(grad) {
6827
+ const stops = [];
6828
+ for (const gs of getChildArray(getChild(grad, "gsLst"), "gs")) {
6829
+ const color = parseColorElement(gs);
6830
+ if (color === void 0) continue;
6831
+ stops.push({
6832
+ position: (numericAttr2(gs, "pos") ?? 0) / 1e5,
6833
+ color
6834
+ });
7017
6835
  }
7018
- const buAutoNum = getChild(pPr, "buAutoNum");
7019
- if (buAutoNum !== void 0) {
7020
- const scheme = getAttr(buAutoNum, "type") ?? "arabicPeriod";
6836
+ if (stops.length === 0) return void 0;
6837
+ const path = getChild(grad, "path");
6838
+ if (path !== void 0) {
6839
+ const fillToRect = getChild(path, "fillToRect");
6840
+ const l = numericAttr2(fillToRect, "l") ?? 0;
6841
+ const t = numericAttr2(fillToRect, "t") ?? 0;
6842
+ const r = numericAttr2(fillToRect, "r") ?? 0;
6843
+ const b = numericAttr2(fillToRect, "b") ?? 0;
7021
6844
  return {
7022
- type: "autoNum",
7023
- scheme: parseEnumValueWithDefault(scheme, VALID_AUTO_NUM_SCHEMES, "arabicPeriod"),
7024
- startAt: numericAttr2(buAutoNum, "startAt") ?? 1
6845
+ kind: "gradient",
6846
+ gradientType: "radial",
6847
+ stops,
6848
+ centerX: (l + (1e5 - r)) / 2 / 1e5,
6849
+ centerY: (t + (1e5 - b)) / 2 / 1e5
7025
6850
  };
7026
6851
  }
7027
- return void 0;
7028
- }
7029
- function decodeXmlCharRef(value) {
7030
- return value.replace(
7031
- /&#x([0-9a-fA-F]+);|&#([0-9]+);/g,
7032
- (_match, hex, decimal) => String.fromCodePoint(parseInt(hex ?? decimal ?? "0", hex !== void 0 ? 16 : 10))
7033
- );
7034
- }
7035
- function parseRun(r, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7036
- const properties = parseRunProperties(getChild(r, "rPr"));
7037
- const rawSidecars = collectRunSidecars(r, nextId);
7038
6852
  return {
7039
- kind: "textRun",
7040
- text: decodeXmlCharRef(getChildText(r, "t") ?? ""),
7041
- ...properties !== void 0 ? { properties } : {},
7042
- handle: {
7043
- partPath,
7044
- nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7045
- orderingSlot: runIndex
7046
- },
7047
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
6853
+ kind: "gradient",
6854
+ gradientType: "linear",
6855
+ stops,
6856
+ angle: asOoxmlAngle(numericAttr2(getChild(grad, "lin"), "ang") ?? 0)
7048
6857
  };
7049
6858
  }
7050
- function parseBreakRun(br, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7051
- const properties = parseRunProperties(getChild(br, "rPr"));
6859
+ function parseBlipFill(blipFill) {
6860
+ const blip = getChild(blipFill, "blip");
6861
+ const embed = getNamespacedAttr(blip, "embed");
6862
+ if (embed === void 0) return void 0;
6863
+ const tile = parseImageFillTile(getChild(blipFill, "tile"));
7052
6864
  return {
7053
- kind: "textRun",
7054
- text: "\n",
7055
- ...properties !== void 0 ? { properties } : {},
7056
- handle: {
7057
- partPath,
7058
- nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7059
- orderingSlot: runIndex
7060
- }
6865
+ kind: "image",
6866
+ blipRelationshipId: asRelationshipId(embed),
6867
+ ...tile !== void 0 ? { tile } : {}
7061
6868
  };
7062
6869
  }
7063
- function parseRunProperties(rPr) {
7064
- if (!rPr) return void 0;
7065
- const bold = getAttr(rPr, "b");
7066
- const italic = getAttr(rPr, "i");
7067
- const underline = getAttr(rPr, "u");
7068
- const strike = getAttr(rPr, "strike");
7069
- const baseline = numericAttr2(rPr, "baseline");
7070
- const size = numericAttr2(rPr, "sz");
7071
- const typeface = getAttr(getChild(rPr, "latin"), "typeface");
7072
- const typefaceEa = getAttr(getChild(rPr, "ea"), "typeface");
7073
- const typefaceCs = getAttr(getChild(rPr, "cs"), "typeface");
7074
- const hasHyperlink = getChild(rPr, "hlinkClick") !== void 0;
7075
- const color = parseColorElement(getChild(rPr, "solidFill"));
7076
- const properties = {
7077
- ...bold !== void 0 ? { bold: isTrue(bold) } : {},
7078
- ...italic !== void 0 ? { italic: isTrue(italic) } : {},
7079
- ...underline !== void 0 ? { underline: underline !== "none" } : hasHyperlink ? { underline: true } : {},
7080
- ...strike !== void 0 ? { strikethrough: strike !== "noStrike" } : {},
7081
- ...baseline !== void 0 ? { baseline: baseline / 1e3 } : {},
7082
- // `a:rPr@sz` is in 1/100 pt unit. Convert to pt and save.
7083
- ...size !== void 0 ? { fontSize: asPt(size / 100) } : {},
7084
- ...typeface !== void 0 ? { typeface } : {},
7085
- ...typefaceEa !== void 0 ? { typefaceEa } : {},
7086
- ...typefaceCs !== void 0 ? { typefaceCs } : {},
7087
- ...color !== void 0 ? { color } : hasHyperlink ? { color: { kind: "scheme", scheme: "hlink" } } : {}
6870
+ function parseImageFillTile(tile) {
6871
+ if (tile === void 0) return void 0;
6872
+ const flip = getAttr(tile, "flip") ?? "none";
6873
+ return {
6874
+ tx: asEmu2(numericAttr2(tile, "tx") ?? 0),
6875
+ ty: asEmu2(numericAttr2(tile, "ty") ?? 0),
6876
+ sx: (numericAttr2(tile, "sx") ?? 1e5) / 1e5,
6877
+ sy: (numericAttr2(tile, "sy") ?? 1e5) / 1e5,
6878
+ flip: flip === "x" || flip === "y" || flip === "xy" ? flip : "none",
6879
+ align: parseRectangleAlignment(getAttr(tile, "algn"), "tl")
7088
6880
  };
7089
- return Object.keys(properties).length > 0 ? properties : void 0;
7090
6881
  }
7091
- function collectRunSidecars(r, nextId) {
7092
- const runLevel = collectUnknownSidecars(r, KNOWN_RUN_CHILDREN, nextId);
7093
- const propLevel = collectUnknownSidecars(getChild(r, "rPr"), KNOWN_RUN_PROPERTY_CHILDREN, nextId);
7094
- return [...runLevel, ...propLevel];
6882
+ function parseRectangleAlignment(value, fallback) {
6883
+ return parseEnumValueWithDefault(value, RECTANGLE_ALIGNMENT_TOKENS, fallback);
7095
6884
  }
7096
- function emu(value) {
7097
- return asEmu2(value);
6885
+ function parsePatternFill(pattern) {
6886
+ const foregroundColor = parseColorElement(getChild(pattern, "fgClr"));
6887
+ const backgroundColor = parseColorElement(getChild(pattern, "bgClr"));
6888
+ if (foregroundColor === void 0 || backgroundColor === void 0) return void 0;
6889
+ return {
6890
+ kind: "pattern",
6891
+ preset: getAttr(pattern, "prst") ?? "ltDnDiag",
6892
+ foregroundColor,
6893
+ backgroundColor
6894
+ };
7098
6895
  }
7099
- function textNodeId(kind, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7100
- const owner = ownerNodeId !== void 0 ? `shape:${ownerNodeId}` : `shapeSlot:${ownerOrderingSlot}`;
7101
- const suffix = kind === "paragraph" ? `p:${paragraphIndex}` : `p:${paragraphIndex}:r:${runIndex}`;
7102
- return asSourceNodeId(`text:${owner}:${suffix}`);
6896
+ function parseOutline(spPr, nextId) {
6897
+ const ln = getChild(spPr, "ln");
6898
+ return parseLine(ln, nextId);
7103
6899
  }
7104
- function orderedKey(node) {
7105
- return Object.keys(node).find((key) => key !== ":@");
6900
+ function parseLine(ln, nextId) {
6901
+ if (!ln) return void 0;
6902
+ const width = numericAttr2(ln, "w");
6903
+ const fill = parseFill(ln, nextId);
6904
+ const dashStyle = parseDashStyle(getChild(ln, "prstDash"));
6905
+ const customDash = parseCustomDash(ln);
6906
+ const lineCap = parseLineCap(getAttr(ln, "cap"));
6907
+ const lineJoin = parseLineJoin(ln);
6908
+ const headEnd = parseArrowEndpoint(getChild(ln, "headEnd"));
6909
+ const tailEnd = parseArrowEndpoint(getChild(ln, "tailEnd"));
6910
+ return {
6911
+ ...width !== void 0 ? { width: asEmu2(width) } : {},
6912
+ ...fill !== void 0 ? { fill } : {},
6913
+ ...dashStyle !== void 0 ? { dashStyle } : {},
6914
+ ...customDash !== void 0 ? { customDash } : {},
6915
+ ...lineCap !== void 0 ? { lineCap } : {},
6916
+ ...lineJoin !== void 0 ? { lineJoin } : {},
6917
+ ...headEnd !== void 0 ? { headEnd } : {},
6918
+ ...tailEnd !== void 0 ? { tailEnd } : {}
6919
+ };
7106
6920
  }
7107
- function orderedLocalName(node) {
7108
- const key = orderedKey(node);
7109
- return key !== void 0 ? localName(key) : void 0;
6921
+ function parseTransform(spPr) {
6922
+ const xfrm = getChild(spPr, "xfrm");
6923
+ if (!xfrm) return void 0;
6924
+ const off = getChild(xfrm, "off");
6925
+ const ext = getChild(xfrm, "ext");
6926
+ const offsetX = numericAttr2(off, "x");
6927
+ const offsetY = numericAttr2(off, "y");
6928
+ const width = numericAttr2(ext, "cx");
6929
+ const height = numericAttr2(ext, "cy");
6930
+ if (offsetX === void 0 || offsetY === void 0 || width === void 0 || height === void 0) {
6931
+ return void 0;
6932
+ }
6933
+ const rotation = numericAttr2(xfrm, "rot");
6934
+ const flipH = getAttr(xfrm, "flipH");
6935
+ const flipV = getAttr(xfrm, "flipV");
6936
+ return {
6937
+ offsetX: asEmu2(offsetX),
6938
+ offsetY: asEmu2(offsetY),
6939
+ width: asEmu2(width),
6940
+ height: asEmu2(height),
6941
+ ...rotation !== void 0 ? { rotation: asOoxmlAngle(rotation) } : {},
6942
+ ...isTrue(flipH) ? { flipHorizontal: true } : {},
6943
+ ...isTrue(flipV) ? { flipVertical: true } : {}
6944
+ };
7110
6945
  }
7111
- var KNOWN_SHAPE_CHILDREN = /* @__PURE__ */ new Set(["nvSpPr", "spPr", "style", "txBody"]);
7112
- var KNOWN_CONNECTOR_CHILDREN = /* @__PURE__ */ new Set(["nvCxnSpPr", "spPr", "style"]);
7113
- var KNOWN_GROUP_CHILDREN = /* @__PURE__ */ new Set(["nvGrpSpPr", "grpSpPr"]);
7114
- var KNOWN_PICTURE_CHILDREN = /* @__PURE__ */ new Set(["nvPicPr", "blipFill", "spPr"]);
7115
- var KNOWN_BLIP_FILL_CHILDREN = /* @__PURE__ */ new Set([
7116
- "blip",
7117
- "srcRect",
7118
- "stretch",
7119
- "tile"
7120
- ]);
7121
- var KNOWN_BLIP_CHILDREN = /* @__PURE__ */ new Set([
7122
- "grayscl",
7123
- "biLevel",
7124
- "blur",
7125
- "lum",
7126
- "duotone",
7127
- "clrChange"
7128
- ]);
7129
- var KNOWN_EFFECT_CHILDREN = /* @__PURE__ */ new Set([
7130
- "outerShdw",
7131
- "innerShdw",
7132
- "glow",
7133
- "softEdge"
7134
- ]);
7135
- var KNOWN_GRAPHIC_FRAME_CHILDREN = /* @__PURE__ */ new Set([
7136
- "nvGraphicFramePr",
7137
- "xfrm",
7138
- "graphic"
7139
- ]);
7140
- var KNOWN_GRAPHIC_CHILDREN = /* @__PURE__ */ new Set(["graphicData"]);
7141
- var KNOWN_GRAPHIC_DATA_CHILDREN = /* @__PURE__ */ new Set(["tbl"]);
7142
- var KNOWN_TABLE_CHILDREN = /* @__PURE__ */ new Set(["tblPr", "tblGrid", "tr"]);
7143
- var KNOWN_TABLE_CELL_CHILDREN = /* @__PURE__ */ new Set(["txBody", "tcPr"]);
7144
- var KNOWN_TABLE_CELL_PROPERTIES_CHILDREN = /* @__PURE__ */ new Set([
7145
- "lnL",
7146
- "lnR",
7147
- "lnT",
7148
- "lnB",
7149
- "solidFill",
7150
- "noFill",
7151
- "gradFill",
7152
- "blipFill",
7153
- "pattFill",
7154
- "grpFill"
7155
- ]);
7156
- var KNOWN_SP_PR_CHILDREN = /* @__PURE__ */ new Set([
7157
- "xfrm",
7158
- "prstGeom",
7159
- "solidFill",
7160
- "noFill",
7161
- "gradFill",
7162
- "blipFill",
7163
- "pattFill",
7164
- "grpFill",
7165
- "ln",
7166
- "effectLst"
7167
- ]);
7168
- var SHAPE_TREE_NODE_TAGS = /* @__PURE__ */ new Set([
7169
- "sp",
7170
- "pic",
7171
- "cxnSp",
7172
- "grpSp",
7173
- "graphicFrame"
7174
- ]);
7175
- var CHART_GRAPHIC_DATA_URIS = /* @__PURE__ */ new Set([
7176
- "http://schemas.openxmlformats.org/drawingml/2006/chart",
7177
- "http://purl.oclc.org/ooxml/drawingml/chart"
7178
- ]);
7179
- var SMARTART_DIAGRAM_URIS = /* @__PURE__ */ new Set([
7180
- "http://schemas.openxmlformats.org/drawingml/2006/diagram",
7181
- "http://purl.oclc.org/ooxml/drawingml/diagram"
7182
- ]);
7183
- function parseShapeTree(spTree, partPath, nextId, orderedChildren) {
7184
- if (!spTree) return [];
7185
- if (orderedChildren !== void 0) {
7186
- return parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren);
7187
- }
7188
- const nodes = [];
7189
- let orderingSlot = 0;
7190
- for (const key of Object.keys(spTree)) {
6946
+ function withTransforms(base, colorNode) {
6947
+ const transforms = [];
6948
+ for (const key of Object.keys(colorNode)) {
7191
6949
  if (key.startsWith("@_")) continue;
7192
- if (key === "#text") continue;
7193
- const local = localName(key);
7194
- if (local === "nvGrpSpPr" || local === "grpSpPr") continue;
7195
- const value = spTree[key];
6950
+ const kind = localName(key);
6951
+ const transformKind = parseEnumValue(kind, COLOR_TRANSFORM_KINDS);
6952
+ if (transformKind === void 0) continue;
6953
+ const value = colorNode[key];
7196
6954
  const items = Array.isArray(value) ? value : [value];
7197
6955
  for (const item of items) {
7198
- const node = unsafeOoxmlBoundaryAssertion(item);
7199
- if (local === "sp") {
7200
- nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7201
- } else if (local === "pic") {
7202
- nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7203
- } else if (local === "cxnSp") {
7204
- nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
7205
- } else if (local === "grpSp") {
7206
- nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
7207
- } else if (local === "graphicFrame") {
7208
- nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
7209
- } else if (local === "AlternateContent") {
7210
- const parsed = parseAlternateContent(node, partPath, nextId, orderingSlot);
7211
- nodes.push(...parsed);
7212
- } else {
7213
- nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
7214
- }
7215
- orderingSlot++;
6956
+ const raw = getAttr(unsafeOoxmlBoundaryAssertion(item), "val");
6957
+ if (raw === void 0) continue;
6958
+ const numeric = Number(raw);
6959
+ if (!Number.isFinite(numeric)) continue;
6960
+ transforms.push({
6961
+ kind: transformKind,
6962
+ value: asOoxmlPercent(numeric)
6963
+ });
7216
6964
  }
7217
6965
  }
7218
- return nodes;
6966
+ return transforms.length > 0 ? { ...base, transforms } : base;
7219
6967
  }
7220
- function parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren) {
7221
- const nodes = [];
7222
- const tagCounters = {};
7223
- let orderingSlot = 0;
7224
- for (const child of orderedChildren) {
7225
- const key = Object.keys(child).find((candidate) => candidate !== ":@");
7226
- if (key === void 0) continue;
7227
- const local = localName(key);
7228
- if (local === "AlternateContent") {
7229
- const index2 = tagCounters[local] ?? 0;
7230
- tagCounters[local] = index2 + 1;
7231
- const alternateContents = getChildArray(spTree, "AlternateContent");
7232
- const alternateContent = alternateContents[index2];
7233
- if (alternateContent !== void 0) {
7234
- nodes.push(...parseAlternateContent(alternateContent, partPath, nextId, orderingSlot));
7235
- orderingSlot++;
7236
- }
7237
- continue;
7238
- }
7239
- if (!SHAPE_TREE_NODE_TAGS.has(local)) continue;
7240
- const index = tagCounters[local] ?? 0;
7241
- tagCounters[local] = index + 1;
7242
- const node = getChildArray(spTree, local)[index];
7243
- if (node === void 0) continue;
7244
- nodes.push(parseShapeTreeNode(local, node, child, partPath, nextId, orderingSlot));
7245
- orderingSlot++;
7246
- }
7247
- return nodes;
6968
+ function numericAttr2(node, name) {
6969
+ const raw = getAttr(node, name);
6970
+ if (raw === void 0) return void 0;
6971
+ const value = Number(raw);
6972
+ return Number.isFinite(value) ? value : void 0;
7248
6973
  }
7249
- function parseShapeTreeNode(local, node, orderedNode, partPath, nextId, orderingSlot) {
7250
- if (local === "sp") return parseShape(node, partPath, nextId, orderingSlot, orderedNode);
7251
- if (local === "pic") return parseImage(node, partPath, nextId, orderingSlot);
7252
- if (local === "cxnSp") {
7253
- return parseConnector(node, partPath, nextId, orderingSlot, orderedNode);
7254
- }
7255
- if (local === "grpSp") {
7256
- const orderedGroupChildren = unsafeOoxmlBoundaryAssertion(orderedNode?.[local]);
7257
- return parseGroup(node, partPath, nextId, orderingSlot, orderedGroupChildren);
7258
- }
7259
- if (local === "graphicFrame") {
7260
- return parseGraphicFrame(node, partPath, nextId, orderingSlot, orderedNode);
7261
- }
7262
- return parseRawShapeNode(`p:${local}`, node, partPath, nextId, orderingSlot);
6974
+ function isTrue(value) {
6975
+ return value === "1" || value === "true";
7263
6976
  }
7264
- function parseShape(sp, partPath, nextId, orderingSlot, orderedNode) {
7265
- const nvSpPr = getChild(sp, "nvSpPr");
7266
- const cNvPr = getChild(nvSpPr, "cNvPr");
7267
- const nodeId = sourceNodeId(cNvPr);
7268
- const name = getAttr(cNvPr, "name");
7269
- const placeholder = parsePlaceholder(getChild(getChild(nvSpPr, "nvPr"), "ph"));
7270
- const spPr = getChild(sp, "spPr");
7271
- const transform = parseTransform(spPr);
7272
- const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "sp", "spPr"));
7273
- const fill = parseFill(spPr, nextId);
7274
- const outline = parseOutline(spPr, nextId);
7275
- const effects = parseEffectList(getChild(spPr, "effectLst"));
7276
- const style = parseShapeStyle(getChild(sp, "style"));
7277
- const textBody = parseTextBody(
7278
- getChild(sp, "txBody"),
7279
- partPath,
7280
- nextId,
7281
- nodeId,
7282
- orderingSlot,
7283
- orderedNestedChildChildren(orderedNode, "sp", "txBody")
7284
- );
7285
- const rawSidecars = [
7286
- ...collectUnknownSidecars(sp, KNOWN_SHAPE_CHILDREN, nextId),
7287
- ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7288
- ...collectEffectSidecars(spPr, effects, nextId)
7289
- ];
6977
+ function parseDashStyle(prstDash) {
6978
+ const value = getAttr(prstDash, "val");
6979
+ return parseEnumValue(value, DASH_STYLES);
6980
+ }
6981
+ function parseCustomDash(ln) {
6982
+ const custDash = getChild(ln, "custDash");
6983
+ const segments = getChildArray(custDash, "ds");
6984
+ if (segments.length === 0) return void 0;
6985
+ return segments.flatMap((segment) => [
6986
+ (numericAttr2(segment, "d") ?? 1e5) / 1e5,
6987
+ (numericAttr2(segment, "sp") ?? 1e5) / 1e5
6988
+ ]);
6989
+ }
6990
+ var LINE_CAP_MAP = {
6991
+ flat: "butt",
6992
+ sq: "square",
6993
+ rnd: "round"
6994
+ };
6995
+ function parseLineCap(value) {
6996
+ return value !== void 0 ? LINE_CAP_MAP[value] : void 0;
6997
+ }
6998
+ function parseLineJoin(ln) {
6999
+ if (hasChild(ln, "round")) return "round";
7000
+ if (hasChild(ln, "bevel")) return "bevel";
7001
+ if (hasChild(ln, "miter")) return "miter";
7002
+ return void 0;
7003
+ }
7004
+ function parseArrowEndpoint(node) {
7005
+ if (!node) return void 0;
7006
+ const type = parseEnumValue(getAttr(node, "type"), ARROW_TYPES);
7007
+ if (type === void 0) return void 0;
7008
+ const width = getAttr(node, "w") ?? "med";
7009
+ const length = getAttr(node, "len") ?? "med";
7290
7010
  return {
7291
- kind: "shape",
7292
- ...nodeId !== void 0 ? { nodeId } : {},
7293
- ...name !== void 0 ? { name } : {},
7294
- ...transform !== void 0 ? { transform } : {},
7295
- ...geometry !== void 0 ? { geometry } : {},
7296
- ...fill !== void 0 ? { fill } : {},
7297
- ...outline !== void 0 ? { outline } : {},
7298
- ...effects !== void 0 ? { effects } : {},
7299
- ...style !== void 0 ? { style } : {},
7300
- ...textBody !== void 0 ? { textBody } : {},
7301
- ...placeholder !== void 0 ? { placeholder } : {},
7302
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7303
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7011
+ type,
7012
+ width: parseEnumValueWithDefault(width, ARROW_SIZES, "med"),
7013
+ length: parseEnumValueWithDefault(length, ARROW_SIZES, "med")
7304
7014
  };
7305
7015
  }
7306
- function parseConnector(cxnSp, partPath, nextId, orderingSlot, orderedNode) {
7307
- const nvCxnSpPr = getChild(cxnSp, "nvCxnSpPr");
7308
- const cNvPr = getChild(nvCxnSpPr, "cNvPr");
7309
- const cNvCxnSpPr = getChild(nvCxnSpPr, "cNvCxnSpPr");
7310
- const nodeId = sourceNodeId(cNvPr);
7311
- const name = getAttr(cNvPr, "name");
7312
- const connection = parseConnectorConnection(cNvCxnSpPr);
7313
- const spPr = getChild(cxnSp, "spPr");
7314
- const transform = parseTransform(spPr);
7315
- const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "cxnSp", "spPr"));
7316
- const outline = parseOutline(spPr, nextId);
7317
- const effects = parseEffectList(getChild(spPr, "effectLst"));
7318
- const style = parseShapeStyle(getChild(cxnSp, "style"));
7319
- const rawSidecars = [
7320
- ...collectUnknownSidecars(cxnSp, KNOWN_CONNECTOR_CHILDREN, nextId),
7321
- ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7322
- ...collectEffectSidecars(spPr, effects, nextId)
7323
- ];
7324
- return {
7325
- kind: "connector",
7326
- ...nodeId !== void 0 ? { nodeId } : {},
7327
- ...name !== void 0 ? { name } : {},
7328
- ...connection !== void 0 ? { connection } : {},
7329
- ...transform !== void 0 ? { transform } : {},
7330
- ...geometry !== void 0 ? { geometry } : {},
7331
- ...outline !== void 0 ? { outline } : {},
7332
- ...effects !== void 0 ? { effects } : {},
7333
- ...style !== void 0 ? { style } : {},
7334
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7335
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7336
- };
7337
- }
7338
- function parseConnectorConnection(cNvCxnSpPr) {
7339
- const start = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "stCxn"));
7340
- const end = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "endCxn"));
7341
- return start !== void 0 || end !== void 0 ? {
7342
- ...start !== void 0 ? { start } : {},
7343
- ...end !== void 0 ? { end } : {}
7344
- } : void 0;
7345
- }
7346
- function parseConnectorConnectionEndpoint(node) {
7347
- const shapeId = getAttr(node, "id");
7348
- const connectionSiteIndex = numericAttr2(node, "idx");
7349
- if (shapeId === void 0 || connectionSiteIndex === void 0) return void 0;
7350
- return {
7351
- shapeId: asSourceNodeId(shapeId),
7352
- connectionSiteIndex
7353
- };
7354
- }
7355
- function parseShapeStyle(style) {
7356
- if (style === void 0) return void 0;
7357
- const fillRef = parseStyleReference(getChild(style, "fillRef"));
7358
- const lineRef = parseStyleReference(getChild(style, "lnRef"));
7359
- const effectRef = parseStyleReference(getChild(style, "effectRef"));
7360
- const parsed = {
7361
- ...fillRef !== void 0 ? { fillRef } : {},
7362
- ...lineRef !== void 0 ? { lineRef } : {},
7363
- ...effectRef !== void 0 ? { effectRef } : {}
7364
- };
7365
- return Object.keys(parsed).length > 0 ? parsed : void 0;
7366
- }
7367
- function parseStyleReference(ref) {
7368
- if (ref === void 0) return void 0;
7369
- const index = numericAttr2(ref, "idx") ?? 0;
7370
- const color = parseColorElement(ref);
7371
- return {
7372
- index,
7373
- ...color !== void 0 ? { color } : {}
7374
- };
7375
- }
7376
- function parseGroup(grpSp, partPath, nextId, orderingSlot, orderedChildren) {
7377
- const nvGrpSpPr = getChild(grpSp, "nvGrpSpPr");
7378
- const cNvPr = getChild(nvGrpSpPr, "cNvPr");
7379
- const nodeId = sourceNodeId(cNvPr);
7380
- const name = getAttr(cNvPr, "name");
7381
- const grpSpPr = getChild(grpSp, "grpSpPr");
7382
- const transform = parseTransform(grpSpPr);
7383
- const childTransform = parseChildTransform(grpSpPr, transform);
7384
- const fill = parseFill(grpSpPr, nextId);
7385
- const effects = parseEffectList(getChild(grpSpPr, "effectLst"));
7386
- const rawSidecars = [
7387
- ...collectUnknownSidecars(grpSp, KNOWN_GROUP_CHILDREN, nextId),
7388
- ...collectUnknownSidecars(grpSpPr, KNOWN_SP_PR_CHILDREN, nextId),
7389
- ...collectEffectSidecars(grpSpPr, effects, nextId)
7390
- ];
7391
- return {
7392
- kind: "group",
7393
- ...nodeId !== void 0 ? { nodeId } : {},
7394
- ...name !== void 0 ? { name } : {},
7395
- ...transform !== void 0 ? { transform } : {},
7396
- ...childTransform !== void 0 ? { childTransform } : {},
7397
- ...fill !== void 0 ? { fill } : {},
7398
- ...effects !== void 0 ? { effects } : {},
7399
- children: parseShapeTree(grpSp, partPath, nextId, orderedChildren),
7400
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7401
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7402
- };
7403
- }
7404
- function parseImage(pic, partPath, nextId, orderingSlot) {
7405
- const cNvPr = getChild(getChild(pic, "nvPicPr"), "cNvPr");
7406
- const nodeId = sourceNodeId(cNvPr);
7407
- const name = getAttr(cNvPr, "name");
7408
- const blipFill = getChild(pic, "blipFill");
7409
- const blip = getChild(blipFill, "blip");
7410
- const embed = getNamespacedAttr(blip, "embed");
7411
- const crop = parseCrop(getChild(blipFill, "srcRect"));
7412
- const stretch = parseStretch(getChild(blipFill, "stretch"));
7413
- const tile = parseImageFillTile(getChild(blipFill, "tile"));
7414
- const blipEffects = parseBlipEffects(blip);
7415
- const spPr = getChild(pic, "spPr");
7416
- const transform = parseTransform(spPr);
7417
- const effects = parseEffectList(getChild(spPr, "effectLst"));
7418
- const rawSidecars = [
7419
- ...collectUnknownSidecars(pic, KNOWN_PICTURE_CHILDREN, nextId),
7420
- ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7421
- ...collectEffectSidecars(spPr, effects, nextId),
7422
- // Retains fill mode such as `a:stretch` / `a:tile` and recolor operation under blip.
7423
- ...collectUnknownSidecars(blipFill, KNOWN_BLIP_FILL_CHILDREN, nextId),
7424
- ...collectBlipEffectSidecars(blip, blipEffects, nextId)
7425
- ];
7016
+ var DASH_STYLES = /* @__PURE__ */ new Set([
7017
+ "solid",
7018
+ "dash",
7019
+ "dot",
7020
+ "dashDot",
7021
+ "lgDash",
7022
+ "lgDashDot",
7023
+ "sysDash",
7024
+ "sysDot"
7025
+ ]);
7026
+ var ARROW_TYPES = /* @__PURE__ */ new Set([
7027
+ "triangle",
7028
+ "stealth",
7029
+ "diamond",
7030
+ "oval",
7031
+ "arrow"
7032
+ ]);
7033
+ var ARROW_SIZES = /* @__PURE__ */ new Set(["sm", "med", "lg"]);
7034
+ var KNOWN_TXBODY_CHILDREN = /* @__PURE__ */ new Set(["bodyPr", "lstStyle", "p"]);
7035
+ var KNOWN_PARAGRAPH_CHILDREN = /* @__PURE__ */ new Set([
7036
+ "pPr",
7037
+ "r",
7038
+ "fld",
7039
+ "br",
7040
+ "endParaRPr"
7041
+ ]);
7042
+ var KNOWN_RUN_CHILDREN = /* @__PURE__ */ new Set(["rPr", "t"]);
7043
+ var KNOWN_RUN_PROPERTY_CHILDREN = /* @__PURE__ */ new Set([
7044
+ "latin",
7045
+ "ea",
7046
+ "cs",
7047
+ "solidFill"
7048
+ ]);
7049
+ var ALIGN_MAP = {
7050
+ l: "left",
7051
+ ctr: "center",
7052
+ r: "right",
7053
+ just: "justify"
7054
+ };
7055
+ var ANCHOR_MAP = {
7056
+ t: "top",
7057
+ ctr: "middle",
7058
+ b: "bottom"
7059
+ };
7060
+ var WRAP_VALUES = /* @__PURE__ */ new Set(["square", "none"]);
7061
+ var VERTICAL_VALUES = /* @__PURE__ */ new Set([
7062
+ "horz",
7063
+ "vert",
7064
+ "vert270",
7065
+ "eaVert",
7066
+ "wordArtVert",
7067
+ "mongolianVert"
7068
+ ]);
7069
+ var VALID_AUTO_NUM_SCHEMES = /* @__PURE__ */ new Set([
7070
+ "arabicPeriod",
7071
+ "arabicParenR",
7072
+ "romanUcPeriod",
7073
+ "romanLcPeriod",
7074
+ "alphaUcPeriod",
7075
+ "alphaLcPeriod",
7076
+ "alphaLcParenR",
7077
+ "alphaUcParenR",
7078
+ "arabicPlain"
7079
+ ]);
7080
+ function parseTextBody(txBody, partPath, nextId, ownerNodeId, ownerOrderingSlot, orderedTxBody) {
7081
+ if (!txBody) return void 0;
7082
+ const properties = parseBodyProperties(getChild(txBody, "bodyPr"));
7083
+ const listStyle = parseTextStyle(getChild(txBody, "lstStyle"));
7084
+ const orderedParagraphs = orderedTxBody?.filter((child) => orderedLocalName(child) === "p").map((child) => {
7085
+ const key = orderedKey(child);
7086
+ const value = key !== void 0 ? child[key] : void 0;
7087
+ return Array.isArray(value) ? value : void 0;
7088
+ });
7089
+ const paragraphs = [];
7090
+ let logicalParagraphIndex = 0;
7091
+ getChildArray(txBody, "p").forEach((p, paragraphIndex) => {
7092
+ const orderedChildren = orderedParagraphs?.[paragraphIndex];
7093
+ if (orderedChildren !== void 0 && hasMultipleBulletPPr(p, orderedChildren)) {
7094
+ const split = splitInterleavedParagraph(
7095
+ p,
7096
+ orderedChildren,
7097
+ partPath,
7098
+ nextId,
7099
+ ownerNodeId,
7100
+ ownerOrderingSlot,
7101
+ logicalParagraphIndex
7102
+ );
7103
+ paragraphs.push(...split);
7104
+ logicalParagraphIndex += split.length;
7105
+ return;
7106
+ }
7107
+ paragraphs.push(
7108
+ parseParagraph(
7109
+ p,
7110
+ partPath,
7111
+ nextId,
7112
+ ownerNodeId,
7113
+ ownerOrderingSlot,
7114
+ logicalParagraphIndex,
7115
+ orderedChildren
7116
+ )
7117
+ );
7118
+ logicalParagraphIndex++;
7119
+ });
7120
+ const rawSidecars = collectUnknownSidecars(txBody, KNOWN_TXBODY_CHILDREN, nextId);
7426
7121
  return {
7427
- kind: "image",
7428
- ...nodeId !== void 0 ? { nodeId } : {},
7429
- ...name !== void 0 ? { name } : {},
7430
- ...transform !== void 0 ? { transform } : {},
7431
- ...embed !== void 0 ? { blipRelationshipId: asRelationshipId(embed) } : {},
7432
- ...crop !== void 0 ? { crop } : {},
7433
- ...stretch !== void 0 ? { stretch } : {},
7434
- ...tile !== void 0 ? { tile } : {},
7435
- ...effects !== void 0 ? { effects } : {},
7436
- ...blipEffects !== void 0 ? { blipEffects } : {},
7437
- handle: {
7438
- partPath,
7439
- ...nodeId !== void 0 ? { nodeId } : {},
7440
- ...embed !== void 0 ? { relationshipId: asRelationshipId(embed) } : {},
7441
- orderingSlot
7442
- },
7122
+ paragraphs,
7123
+ ...properties !== void 0 ? { properties } : {},
7124
+ ...listStyle !== void 0 ? { listStyle } : {},
7125
+ handle: { partPath },
7443
7126
  ...rawSidecars.length > 0 ? { rawSidecars } : {}
7444
7127
  };
7445
7128
  }
7446
- function collectEffectSidecars(spPr, effects, nextId) {
7447
- const effectList = getChild(spPr, "effectLst");
7448
- if (effectList === void 0) return [];
7449
- const sidecars = collectUnknownSidecars(effectList, KNOWN_EFFECT_CHILDREN, nextId);
7450
- const supportedChildren = [
7451
- ["outerShdw", effects?.outerShadow],
7452
- ["innerShdw", effects?.innerShadow],
7453
- ["glow", effects?.glow],
7454
- ["softEdge", effects?.softEdge]
7455
- ];
7456
- for (const [name, parsed] of supportedChildren) {
7457
- const node = getChild(effectList, name);
7458
- if (node !== void 0 && parsed === void 0) {
7459
- sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7460
- }
7461
- }
7462
- return sidecars;
7463
- }
7464
- function collectBlipEffectSidecars(blip, effects, nextId) {
7465
- if (blip === void 0) return [];
7466
- const sidecars = collectUnknownSidecars(blip, KNOWN_BLIP_CHILDREN, nextId);
7467
- const supportedChildren = [
7468
- ["grayscl", effects?.grayscale === true],
7469
- ["biLevel", effects?.biLevel],
7470
- ["blur", effects?.blur],
7471
- ["lum", effects?.lum],
7472
- ["duotone", effects?.duotone],
7473
- ["clrChange", effects?.clrChange]
7474
- ];
7475
- for (const [name, parsed] of supportedChildren) {
7476
- const node = getChild(blip, name);
7477
- if (node !== void 0 && (parsed === void 0 || parsed === false)) {
7478
- sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7479
- }
7480
- }
7481
- return sidecars;
7482
- }
7483
- function parseGraphicFrame(graphicFrame, partPath, nextId, orderingSlot, orderedNode) {
7484
- const graphic = getChild(graphicFrame, "graphic");
7485
- const graphicData = getChild(graphic, "graphicData");
7486
- const uri = getAttr(graphicData, "uri");
7487
- if (uri !== void 0 && CHART_GRAPHIC_DATA_URIS.has(uri)) {
7488
- const parsedChart = parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7489
- if (parsedChart !== void 0) return parsedChart;
7490
- }
7491
- if (uri !== void 0 && SMARTART_DIAGRAM_URIS.has(uri)) {
7492
- const parsedSmartArt = parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7493
- if (parsedSmartArt !== void 0) return parsedSmartArt;
7494
- }
7495
- const table = getChild(graphicData, "tbl");
7496
- if (table === void 0) {
7497
- return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
7498
- }
7499
- const orderedGraphicChildren = orderedNestedChildChildren(orderedNode, "graphicFrame", "graphic");
7500
- const orderedGraphicDataChildren = orderedChildChildren2(orderedGraphicChildren, "graphicData");
7501
- const orderedTableChildren = orderedChildChildren2(orderedGraphicDataChildren, "tbl");
7502
- const parsedTable = parseTable(
7503
- table,
7504
- graphicFrame,
7505
- partPath,
7506
- nextId,
7507
- orderingSlot,
7508
- orderedTableChildren
7509
- );
7510
- if (parsedTable === void 0) {
7511
- return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
7512
- }
7513
- return parsedTable;
7514
- }
7515
- function parseAlternateContent(alternateContent, partPath, nextId, orderingSlot) {
7516
- const branches = [
7517
- ...getChildArray(alternateContent, "Choice"),
7518
- ...getChildArray(alternateContent, "Fallback")
7519
- ];
7520
- for (const branch of branches) {
7521
- const parsed = parseAlternateContentBranch(branch, partPath, nextId, orderingSlot);
7522
- if (parsed.length > 0) {
7523
- if (parsed.every((node) => node.kind === "raw")) {
7524
- continue;
7525
- }
7526
- return parsed.map(
7527
- (node) => attachRawSidecar(node, makeSidecar("mc:AlternateContent", alternateContent, nextId))
7528
- );
7529
- }
7129
+ function parseTextStyle(node) {
7130
+ if (node === void 0) return void 0;
7131
+ const defaultParagraph = parseParagraphProperties(getChild(node, "defPPr"));
7132
+ const levels = Array.from(
7133
+ { length: 9 },
7134
+ (_, index) => parseParagraphProperties(getChild(node, `lvl${index + 1}pPr`))
7135
+ );
7136
+ if (defaultParagraph === void 0 && levels.every((level) => level === void 0)) {
7137
+ return void 0;
7530
7138
  }
7531
- return [
7532
- parseRawShapeNode("mc:AlternateContent", alternateContent, partPath, nextId, orderingSlot)
7533
- ];
7139
+ return { ...defaultParagraph !== void 0 ? { defaultParagraph } : {}, levels };
7534
7140
  }
7535
- function attachRawSidecar(node, sidecar) {
7536
- if (node.kind === "raw") return node;
7537
- return {
7538
- ...node,
7539
- rawSidecars: [...node.rawSidecars ?? [], sidecar]
7540
- };
7141
+ function hasMultipleBulletPPr(p, orderedChildren) {
7142
+ const pPrList = getChildArray(p, "pPr");
7143
+ let bulletPPrCount = 0;
7144
+ let pPrCounter = 0;
7145
+ for (const child of orderedChildren) {
7146
+ if (orderedLocalName(child) !== "pPr") continue;
7147
+ const pPr = pPrList[pPrCounter];
7148
+ if (pPr !== void 0 && (getChild(pPr, "buChar") !== void 0 || getChild(pPr, "buAutoNum") !== void 0)) {
7149
+ bulletPPrCount++;
7150
+ if (bulletPPrCount >= 2) return true;
7151
+ }
7152
+ pPrCounter++;
7153
+ }
7154
+ return false;
7541
7155
  }
7542
- function parseAlternateContentBranch(branch, partPath, nextId, orderingSlot) {
7543
- const nodes = [];
7544
- for (const key of Object.keys(branch)) {
7545
- if (key.startsWith("@_") || key === "#text") continue;
7546
- const local = localName(key);
7547
- const value = branch[key];
7548
- const items = Array.isArray(value) ? value : [value];
7549
- for (const item of items) {
7550
- const node = unsafeOoxmlBoundaryAssertion(item);
7551
- if (local === "sp") nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7552
- else if (local === "pic") nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7553
- else if (local === "cxnSp") {
7554
- nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
7555
- } else if (local === "grpSp") {
7556
- nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
7557
- } else if (local === "graphicFrame") {
7558
- nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
7156
+ function splitInterleavedParagraph(p, orderedChildren, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex) {
7157
+ const pPrList = getChildArray(p, "pPr");
7158
+ const rList = getChildArray(p, "r");
7159
+ const fldList = getChildArray(p, "fld");
7160
+ const brList = getChildArray(p, "br");
7161
+ const groups = [];
7162
+ let currentGroup;
7163
+ let pPrCounter = 0;
7164
+ let runCounter = 0;
7165
+ let fieldCounter = 0;
7166
+ let breakCounter = 0;
7167
+ for (const child of orderedChildren) {
7168
+ const tag = orderedLocalName(child);
7169
+ if (tag === "pPr") {
7170
+ const pPr = pPrList[pPrCounter];
7171
+ const hasBullet = pPr !== void 0 && (getChild(pPr, "buChar") !== void 0 || getChild(pPr, "buAutoNum") !== void 0);
7172
+ if (hasBullet || currentGroup === void 0) {
7173
+ if (currentGroup !== void 0) groups.push(currentGroup);
7174
+ currentGroup = {
7175
+ pPrIndex: pPrCounter,
7176
+ rNodes: [],
7177
+ fldNodes: [],
7178
+ brNodes: [],
7179
+ orderedChildren: [child]
7180
+ };
7559
7181
  } else {
7560
- nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
7182
+ currentGroup.orderedChildren.push(child);
7561
7183
  }
7184
+ pPrCounter++;
7185
+ } else if (tag === "r") {
7186
+ currentGroup ??= {
7187
+ pPrIndex: -1,
7188
+ rNodes: [],
7189
+ fldNodes: [],
7190
+ brNodes: [],
7191
+ orderedChildren: []
7192
+ };
7193
+ currentGroup.orderedChildren.push(child);
7194
+ if (rList[runCounter] !== void 0) currentGroup.rNodes.push(rList[runCounter]);
7195
+ runCounter++;
7196
+ } else if (tag === "fld") {
7197
+ currentGroup ??= {
7198
+ pPrIndex: -1,
7199
+ rNodes: [],
7200
+ fldNodes: [],
7201
+ brNodes: [],
7202
+ orderedChildren: []
7203
+ };
7204
+ currentGroup.orderedChildren.push(child);
7205
+ if (fldList[fieldCounter] !== void 0) currentGroup.fldNodes.push(fldList[fieldCounter]);
7206
+ fieldCounter++;
7207
+ } else if (tag === "br") {
7208
+ currentGroup ??= {
7209
+ pPrIndex: -1,
7210
+ rNodes: [],
7211
+ fldNodes: [],
7212
+ brNodes: [],
7213
+ orderedChildren: []
7214
+ };
7215
+ currentGroup.orderedChildren.push(child);
7216
+ if (brList[breakCounter] !== void 0) currentGroup.brNodes.push(brList[breakCounter]);
7217
+ breakCounter++;
7562
7218
  }
7563
7219
  }
7564
- return nodes;
7565
- }
7566
- function parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
7567
- const graphic = getChild(graphicFrame, "graphic");
7568
- const graphicData = getChild(graphic, "graphicData");
7569
- const chart = getChild(graphicData, "chart");
7570
- const rId = getNamespacedAttr(chart, "id") ?? getAttr(chart, "id");
7571
- if (rId === void 0) return void 0;
7572
- const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
7573
- const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
7574
- const nodeId = sourceNodeId(cNvPr);
7575
- const name = getAttr(cNvPr, "name");
7576
- const transform = parseTransform(graphicFrame);
7577
- const rawSidecars = [
7578
- ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
7579
- ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
7580
- ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
7581
- ];
7582
- return {
7583
- kind: "chart",
7584
- ...nodeId !== void 0 ? { nodeId } : {},
7585
- ...name !== void 0 ? { name } : {},
7586
- ...transform !== void 0 ? { transform } : {},
7587
- chartRelationshipId: asRelationshipId(rId),
7588
- handle: {
7589
- partPath,
7590
- ...nodeId !== void 0 ? { nodeId } : {},
7591
- relationshipId: asRelationshipId(rId),
7592
- orderingSlot
7593
- },
7594
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7595
- };
7596
- }
7597
- function parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
7598
- const graphic = getChild(graphicFrame, "graphic");
7599
- const graphicData = getChild(graphic, "graphicData");
7600
- const relIds = getChild(graphicData, "relIds");
7601
- const dmRId = getNamespacedAttr(relIds, "dm") ?? getAttr(relIds, "dm");
7602
- if (dmRId === void 0) return void 0;
7603
- const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
7604
- const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
7605
- const nodeId = sourceNodeId(cNvPr);
7606
- const name = getAttr(cNvPr, "name");
7607
- const transform = parseTransform(graphicFrame);
7608
- const rawSidecars = [
7609
- ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
7610
- ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
7611
- ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
7612
- ];
7613
- return {
7614
- kind: "smartArt",
7615
- ...nodeId !== void 0 ? { nodeId } : {},
7616
- ...name !== void 0 ? { name } : {},
7617
- ...transform !== void 0 ? { transform } : {},
7618
- dataRelationshipId: asRelationshipId(dmRId),
7619
- handle: {
7220
+ if (currentGroup !== void 0) groups.push(currentGroup);
7221
+ return groups.map((group, groupIndex) => {
7222
+ const synthetic = {};
7223
+ if (group.pPrIndex >= 0) synthetic.pPr = pPrList[group.pPrIndex];
7224
+ synthetic.r = group.rNodes;
7225
+ synthetic.fld = group.fldNodes;
7226
+ synthetic.br = group.brNodes;
7227
+ if (groupIndex === groups.length - 1 && getChild(p, "endParaRPr") !== void 0) {
7228
+ synthetic.endParaRPr = getChild(p, "endParaRPr");
7229
+ }
7230
+ const paragraph = parseParagraph(
7231
+ synthetic,
7620
7232
  partPath,
7621
- ...nodeId !== void 0 ? { nodeId } : {},
7622
- relationshipId: asRelationshipId(dmRId),
7623
- orderingSlot
7624
- },
7625
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7626
- };
7233
+ nextId,
7234
+ ownerNodeId,
7235
+ ownerOrderingSlot,
7236
+ paragraphIndex + groupIndex,
7237
+ group.orderedChildren
7238
+ );
7239
+ if (groupIndex < groups.length - 1 && paragraph.runs.length > 0) {
7240
+ const lastRun = paragraph.runs[paragraph.runs.length - 1];
7241
+ if (lastRun.text.endsWith("\n")) {
7242
+ const trimmed = lastRun.text.slice(0, -1);
7243
+ const precedingRuns = paragraph.runs.slice(0, -1);
7244
+ return {
7245
+ ...paragraph,
7246
+ runs: trimmed === "" ? precedingRuns : [...precedingRuns, { ...lastRun, text: trimmed }]
7247
+ };
7248
+ }
7249
+ }
7250
+ return paragraph;
7251
+ });
7627
7252
  }
7628
- function parseTable(tbl, graphicFrame, partPath, nextId, orderingSlot, orderedTableChildren) {
7629
- const columns = parseTableColumns(getChild(tbl, "tblGrid"));
7630
- if (columns.length === 0) return void 0;
7631
- const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
7632
- const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
7633
- const nodeId = sourceNodeId(cNvPr);
7634
- const name = getAttr(cNvPr, "name");
7635
- const tblPr = getChild(tbl, "tblPr");
7636
- const tableStyleId = getChildText(tblPr, "tableStyleId");
7637
- const graphic = getChild(graphicFrame, "graphic");
7638
- const graphicData = getChild(graphic, "graphicData");
7639
- const transform = parseTransform(graphicFrame);
7640
- const rows = parseTableRows(tbl, partPath, nextId, nodeId, orderingSlot, orderedTableChildren);
7641
- const rawSidecars = [
7642
- ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
7643
- ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
7644
- ...collectUnknownSidecars(graphicData, KNOWN_GRAPHIC_DATA_CHILDREN, nextId),
7645
- ...collectUnknownSidecars(tbl, KNOWN_TABLE_CHILDREN, nextId)
7646
- ];
7647
- return {
7648
- kind: "table",
7649
- ...nodeId !== void 0 ? { nodeId } : {},
7650
- ...name !== void 0 ? { name } : {},
7651
- ...transform !== void 0 ? { transform } : {},
7652
- table: {
7653
- columns,
7654
- rows,
7655
- ...tableStyleId !== void 0 ? { tableStyleId } : {}
7656
- },
7657
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7658
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7253
+ function parseBodyProperties(bodyPr) {
7254
+ if (!bodyPr) return void 0;
7255
+ const marginLeft = numericAttr2(bodyPr, "lIns");
7256
+ const marginRight = numericAttr2(bodyPr, "rIns");
7257
+ const marginTop = numericAttr2(bodyPr, "tIns");
7258
+ const marginBottom = numericAttr2(bodyPr, "bIns");
7259
+ const anchorToken = getAttr(bodyPr, "anchor");
7260
+ const anchor = anchorToken !== void 0 ? ANCHOR_MAP[anchorToken] : void 0;
7261
+ const wrap = parseWrap(getAttr(bodyPr, "wrap"));
7262
+ const vert = parseVerticalType(getAttr(bodyPr, "vert"));
7263
+ const numCol = numericAttr2(bodyPr, "numCol");
7264
+ const normAutofit = getChild(bodyPr, "normAutofit");
7265
+ const hasSpAutofit = getChild(bodyPr, "spAutoFit") !== void 0;
7266
+ const hasNoAutofit = getChild(bodyPr, "noAutofit") !== void 0;
7267
+ const fontScale = numericAttr2(normAutofit, "fontScale");
7268
+ const lnSpcReduction = numericAttr2(normAutofit, "lnSpcReduction");
7269
+ const properties = {
7270
+ ...marginLeft !== void 0 ? { marginLeft: emu(marginLeft) } : {},
7271
+ ...marginRight !== void 0 ? { marginRight: emu(marginRight) } : {},
7272
+ ...marginTop !== void 0 ? { marginTop: emu(marginTop) } : {},
7273
+ ...marginBottom !== void 0 ? { marginBottom: emu(marginBottom) } : {},
7274
+ ...anchor !== void 0 ? { anchor } : {},
7275
+ ...wrap !== void 0 ? { wrap } : {},
7276
+ ...normAutofit !== void 0 ? {
7277
+ autoFit: "normAutofit",
7278
+ fontScale: fontScale !== void 0 ? fontScale / 1e5 : 1,
7279
+ lnSpcReduction: lnSpcReduction !== void 0 ? lnSpcReduction / 1e5 : 0
7280
+ } : hasSpAutofit ? { autoFit: "spAutofit", fontScale: 1, lnSpcReduction: 0 } : hasNoAutofit ? { autoFit: "noAutofit", fontScale: 1, lnSpcReduction: 0 } : {},
7281
+ ...numCol !== void 0 ? { numCol: Math.max(1, numCol) } : {},
7282
+ ...vert !== void 0 ? { vert } : {}
7659
7283
  };
7284
+ return Object.keys(properties).length > 0 ? properties : void 0;
7660
7285
  }
7661
- function parseTableColumns(tblGrid) {
7662
- return getChildArray(tblGrid, "gridCol").map((col) => ({ width: emuAttr(col, "w") }));
7286
+ function parseWrap(value) {
7287
+ return parseEnumValue(value, WRAP_VALUES);
7663
7288
  }
7664
- function parseTableRows(tbl, partPath, nextId, tableNodeId, tableOrderingSlot, orderedTableChildren) {
7665
- const orderedRows = orderedChildChildrenList(orderedTableChildren, "tr");
7666
- return getChildArray(tbl, "tr").map((tr, rowIndex) => ({
7667
- height: emuAttr(tr, "h"),
7668
- cells: getChildArray(tr, "tc").map((tc, cellIndex) => {
7669
- const orderedCells = orderedChildChildrenList(orderedRows[rowIndex], "tc");
7670
- return parseTableCell(
7671
- tc,
7672
- partPath,
7673
- nextId,
7674
- tableNodeId,
7675
- tableOrderingSlot,
7676
- rowIndex,
7677
- cellIndex,
7678
- orderedCells[cellIndex]
7679
- );
7680
- })
7681
- }));
7289
+ function parseVerticalType(value) {
7290
+ return parseEnumValue(value, VERTICAL_VALUES);
7682
7291
  }
7683
- function parseTableCell(tc, partPath, nextId, tableNodeId, tableOrderingSlot, rowIndex, cellIndex, orderedCellChildren) {
7684
- const tcPr = getChild(tc, "tcPr");
7685
- const textOrderingSlot = tableOrderingSlot * 1e9 + rowIndex * 1e6 + cellIndex;
7686
- const textBody = parseTextBody(
7687
- getChild(tc, "txBody"),
7292
+ function parseParagraph(p, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, orderedChildren) {
7293
+ const properties = parseParagraphProperties(getChild(p, "pPr"));
7294
+ const runs = parseRunsInOrder(
7295
+ p,
7688
7296
  partPath,
7689
7297
  nextId,
7690
- tableNodeId,
7691
- textOrderingSlot,
7692
- orderedChildChildren2(orderedCellChildren, "txBody")
7298
+ ownerNodeId,
7299
+ ownerOrderingSlot,
7300
+ paragraphIndex,
7301
+ orderedChildren
7693
7302
  );
7694
- const fill = parseFill(tcPr, nextId);
7695
- const borders = parseCellBorders(tcPr, nextId);
7696
- const rawSidecars = [
7697
- ...collectUnknownSidecars(tc, KNOWN_TABLE_CELL_CHILDREN, nextId),
7698
- ...collectUnknownSidecars(tcPr, KNOWN_TABLE_CELL_PROPERTIES_CHILDREN, nextId)
7699
- ];
7303
+ const rawSidecars = collectUnknownSidecars(p, KNOWN_PARAGRAPH_CHILDREN, nextId);
7700
7304
  return {
7701
- ...textBody !== void 0 ? { textBody } : {},
7702
- ...fill !== void 0 ? { fill } : {},
7703
- ...borders !== void 0 ? { borders } : {},
7704
- gridSpan: numericAttr2(tc, "gridSpan") ?? 1,
7705
- rowSpan: numericAttr2(tc, "rowSpan") ?? 1,
7706
- hMerge: isTrue(getAttr(tc, "hMerge") ?? getAttr(tcPr, "hMerge")),
7707
- vMerge: isTrue(getAttr(tc, "vMerge") ?? getAttr(tcPr, "vMerge")),
7305
+ runs,
7306
+ ...properties !== void 0 ? { properties } : {},
7307
+ handle: {
7308
+ partPath,
7309
+ nodeId: textNodeId("paragraph", ownerNodeId, ownerOrderingSlot, paragraphIndex),
7310
+ orderingSlot: paragraphIndex
7311
+ },
7708
7312
  ...rawSidecars.length > 0 ? { rawSidecars } : {}
7709
7313
  };
7710
7314
  }
7711
- function parseCellBorders(tcPr, nextId) {
7712
- const left = parseLine(getChild(tcPr, "lnL"), nextId);
7713
- const right = parseLine(getChild(tcPr, "lnR"), nextId);
7714
- const top = parseLine(getChild(tcPr, "lnT"), nextId);
7715
- const bottom = parseLine(getChild(tcPr, "lnB"), nextId);
7716
- if (left === void 0 && right === void 0 && top === void 0 && bottom === void 0) {
7717
- return void 0;
7718
- }
7719
- return {
7720
- ...top !== void 0 ? { top } : {},
7721
- ...bottom !== void 0 ? { bottom } : {},
7722
- ...left !== void 0 ? { left } : {},
7723
- ...right !== void 0 ? { right } : {}
7724
- };
7725
- }
7726
- function parseRawShapeNode(key, node, partPath, nextId, orderingSlot) {
7727
- const nodeId = sourceNodeId(getChild(getChild(node, "nvSpPr"), "cNvPr"));
7728
- return {
7729
- kind: "raw",
7730
- ...nodeId !== void 0 ? { nodeId } : {},
7731
- raw: makeSidecar(key, node, nextId),
7732
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot }
7733
- };
7734
- }
7735
- function parsePlaceholder(ph) {
7736
- if (!ph) return void 0;
7737
- const type = getAttr(ph, "type");
7738
- const index = numericAttr2(ph, "idx");
7739
- if (type === void 0 && index === void 0) return void 0;
7740
- return {
7741
- ...type !== void 0 ? { type } : {},
7742
- ...index !== void 0 ? { index } : {}
7743
- };
7744
- }
7745
- function parseGeometry(spPr, orderedSpPr) {
7746
- const prstGeom = getChild(spPr, "prstGeom");
7747
- if (prstGeom) {
7748
- const preset = getAttr(prstGeom, "prst");
7749
- const adjustValues = parseAdjustValues(getChild(prstGeom, "avLst"));
7750
- return preset !== void 0 ? {
7751
- preset,
7752
- ...Object.keys(adjustValues).length > 0 ? { adjustValues } : {}
7753
- } : void 0;
7315
+ function parseRunsInOrder(p, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, orderedChildren) {
7316
+ const rList = getChildArray(p, "r");
7317
+ const fldList = getChildArray(p, "fld");
7318
+ const brList = getChildArray(p, "br");
7319
+ if (orderedChildren === void 0) {
7320
+ return [
7321
+ ...rList.map(
7322
+ (r, runIndex) => parseRun(r, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex)
7323
+ ),
7324
+ ...fldList.map(
7325
+ (fld, index) => parseRun(
7326
+ fld,
7327
+ partPath,
7328
+ nextId,
7329
+ ownerNodeId,
7330
+ ownerOrderingSlot,
7331
+ paragraphIndex,
7332
+ rList.length + index
7333
+ )
7334
+ ),
7335
+ ...brList.map(
7336
+ (br, index) => parseBreakRun(
7337
+ br,
7338
+ partPath,
7339
+ nextId,
7340
+ ownerNodeId,
7341
+ ownerOrderingSlot,
7342
+ paragraphIndex,
7343
+ rList.length + fldList.length + index
7344
+ )
7345
+ )
7346
+ ];
7754
7347
  }
7755
- const customPaths = parseCustomGeometry(
7756
- getChild(spPr, "custGeom"),
7757
- orderedChildChildren2(orderedSpPr, "custGeom")
7758
- );
7759
- if (customPaths !== void 0) return { kind: "custom", paths: customPaths };
7760
- return void 0;
7761
- }
7762
- function parseAdjustValues(avLst) {
7763
- const adjustValues = {};
7764
- for (const guide of getChildArray(avLst, "gd")) {
7765
- const name = getAttr(guide, "name");
7766
- const formula = getAttr(guide, "fmla");
7767
- const match = formula?.match(/val\s+(-?\d+)/);
7768
- if (name !== void 0 && match !== void 0 && match !== null) {
7769
- adjustValues[name] = Number(match[1]);
7348
+ const counters = {};
7349
+ const runs = [];
7350
+ for (const child of orderedChildren) {
7351
+ const tag = orderedLocalName(child);
7352
+ if (tag !== "r" && tag !== "fld" && tag !== "br") continue;
7353
+ const index = counters[tag] ?? 0;
7354
+ counters[tag] = index + 1;
7355
+ const runIndex = runs.length;
7356
+ if (tag === "r" && rList[index] !== void 0) {
7357
+ runs.push(
7358
+ parseRun(
7359
+ rList[index],
7360
+ partPath,
7361
+ nextId,
7362
+ ownerNodeId,
7363
+ ownerOrderingSlot,
7364
+ paragraphIndex,
7365
+ runIndex
7366
+ )
7367
+ );
7368
+ } else if (tag === "fld" && fldList[index] !== void 0) {
7369
+ runs.push(
7370
+ parseRun(
7371
+ fldList[index],
7372
+ partPath,
7373
+ nextId,
7374
+ ownerNodeId,
7375
+ ownerOrderingSlot,
7376
+ paragraphIndex,
7377
+ runIndex
7378
+ )
7379
+ );
7380
+ } else if (tag === "br" && brList[index] !== void 0) {
7381
+ runs.push(
7382
+ parseBreakRun(
7383
+ brList[index],
7384
+ partPath,
7385
+ nextId,
7386
+ ownerNodeId,
7387
+ ownerOrderingSlot,
7388
+ paragraphIndex,
7389
+ runIndex
7390
+ )
7391
+ );
7770
7392
  }
7771
7393
  }
7772
- return adjustValues;
7773
- }
7774
- function parseChildTransform(grpSpPr, fallback) {
7775
- const xfrm = getChild(grpSpPr, "xfrm");
7776
- const childOff = getChild(xfrm, "chOff");
7777
- const childExt = getChild(xfrm, "chExt");
7778
- const offsetX = numericAttr2(childOff, "x") ?? 0;
7779
- const offsetY = numericAttr2(childOff, "y") ?? 0;
7780
- const width = numericAttr2(childExt, "cx") ?? fallback?.width;
7781
- const height = numericAttr2(childExt, "cy") ?? fallback?.height;
7782
- if (width === void 0 || height === void 0) return void 0;
7783
- return {
7784
- offsetX: asEmu2(offsetX),
7785
- offsetY: asEmu2(offsetY),
7786
- width: asEmu2(Number(width)),
7787
- height: asEmu2(Number(height))
7788
- };
7394
+ return runs;
7789
7395
  }
7790
- function parseCrop(srcRect) {
7791
- if (!srcRect) return void 0;
7792
- const left = numericAttr2(srcRect, "l");
7793
- const top = numericAttr2(srcRect, "t");
7794
- const right = numericAttr2(srcRect, "r");
7795
- const bottom = numericAttr2(srcRect, "b");
7796
- const crop = {
7797
- ...left !== void 0 ? { left: asOoxmlPercent(left) } : {},
7798
- ...top !== void 0 ? { top: asOoxmlPercent(top) } : {},
7799
- ...right !== void 0 ? { right: asOoxmlPercent(right) } : {},
7800
- ...bottom !== void 0 ? { bottom: asOoxmlPercent(bottom) } : {}
7396
+ function parseParagraphProperties(pPr) {
7397
+ if (!pPr) return void 0;
7398
+ const alignToken = getAttr(pPr, "algn");
7399
+ const align = alignToken !== void 0 ? ALIGN_MAP[alignToken] : void 0;
7400
+ const level = numericAttr2(pPr, "lvl");
7401
+ const lineSpacing = parseSpacing(getChild(pPr, "lnSpc"));
7402
+ const spaceBefore = parseSpacing(getChild(pPr, "spcBef"));
7403
+ const spaceAfter = parseSpacing(getChild(pPr, "spcAft"));
7404
+ const marginLeft = numericAttr2(pPr, "marL");
7405
+ const indent = numericAttr2(pPr, "indent");
7406
+ const bullet = parseBullet(pPr);
7407
+ const bulletFont = getAttr(getChild(pPr, "buFont"), "typeface");
7408
+ const bulletColor = parseColorElement(getChild(pPr, "buClr"));
7409
+ const bulletSizePct = numericAttr2(getChild(pPr, "buSzPct"), "val");
7410
+ const tabStops = parseTabStops(pPr);
7411
+ const defaultRunProperties = parseRunProperties(getChild(pPr, "defRPr"));
7412
+ const properties = {
7413
+ ...align !== void 0 ? { align } : {},
7414
+ ...level !== void 0 ? { level } : {},
7415
+ ...lineSpacing !== void 0 ? { lineSpacing } : {},
7416
+ ...spaceBefore !== void 0 ? { spaceBefore } : {},
7417
+ ...spaceAfter !== void 0 ? { spaceAfter } : {},
7418
+ ...marginLeft !== void 0 ? { marginLeft: emu(marginLeft) } : {},
7419
+ ...indent !== void 0 ? { indent: emu(indent) } : {},
7420
+ ...bullet !== void 0 ? { bullet } : {},
7421
+ ...bulletFont !== void 0 ? { bulletFont } : {},
7422
+ ...bulletColor !== void 0 ? { bulletColor } : {},
7423
+ ...bulletSizePct !== void 0 ? { bulletSizePct } : {},
7424
+ ...tabStops.length > 0 ? { tabStops } : {},
7425
+ ...defaultRunProperties !== void 0 ? { defaultRunProperties } : {}
7801
7426
  };
7802
- return Object.keys(crop).length > 0 ? crop : void 0;
7803
- }
7804
- function parseStretch(stretch) {
7805
- const fillRect = getChild(stretch, "fillRect");
7806
- if (fillRect === void 0) return void 0;
7807
- const left = (numericAttr2(fillRect, "l") ?? 0) / 1e5;
7808
- const top = (numericAttr2(fillRect, "t") ?? 0) / 1e5;
7809
- const right = (numericAttr2(fillRect, "r") ?? 0) / 1e5;
7810
- const bottom = (numericAttr2(fillRect, "b") ?? 0) / 1e5;
7811
- if (left === 0 && top === 0 && right === 0 && bottom === 0) return void 0;
7812
- return { left, top, right, bottom };
7813
- }
7814
- function sourceNodeId(cNvPr) {
7815
- const id = getAttr(cNvPr, "id");
7816
- return id !== void 0 ? asSourceNodeId(id) : void 0;
7427
+ return Object.keys(properties).length > 0 ? properties : void 0;
7817
7428
  }
7818
- function emuAttr(node, attrName) {
7819
- return asEmu2(numericAttr2(node, attrName) ?? 0);
7429
+ function parseTabStops(pPr) {
7430
+ return getChildArray(getChild(pPr, "tabLst"), "tab").map((tab) => ({
7431
+ position: emu(numericAttr2(tab, "pos") ?? 0),
7432
+ alignment: unsafeOoxmlBoundaryAssertion(getAttr(tab, "algn")) ?? "l"
7433
+ }));
7820
7434
  }
7821
- var EMPTY_KNOWN = /* @__PURE__ */ new Set();
7822
- function orderedChildChildren2(parent, childLocalName) {
7823
- const child = parent?.find((entry) => {
7824
- const key2 = Object.keys(entry).find((candidate) => candidate !== ":@");
7825
- return key2 !== void 0 && localName(key2) === childLocalName;
7826
- });
7827
- if (child === void 0) return void 0;
7828
- const key = Object.keys(child).find((candidate) => candidate !== ":@");
7829
- const value = key !== void 0 ? child[key] : void 0;
7830
- return Array.isArray(value) ? value : void 0;
7435
+ function parseSpacing(node) {
7436
+ const points = numericAttr2(getChild(node, "spcPts"), "val");
7437
+ if (points !== void 0) return { type: "pts", value: asHundredthPt2(points) };
7438
+ const percent = numericAttr2(getChild(node, "spcPct"), "val");
7439
+ if (percent !== void 0) return { type: "pct", value: percent };
7440
+ return void 0;
7831
7441
  }
7832
- function orderedChildChildrenList(parent, childLocalName) {
7833
- if (parent === void 0) return [];
7834
- return parent.filter((entry) => {
7835
- const key = Object.keys(entry).find((candidate) => candidate !== ":@");
7836
- return key !== void 0 && localName(key) === childLocalName;
7837
- }).map((entry) => {
7838
- const key = Object.keys(entry).find((candidate) => candidate !== ":@");
7839
- const value = key !== void 0 ? entry[key] : void 0;
7840
- return Array.isArray(value) ? value : void 0;
7841
- });
7442
+ function parseBullet(pPr) {
7443
+ if (pPr === void 0) return void 0;
7444
+ if (getChild(pPr, "buNone") !== void 0) return { type: "none" };
7445
+ const buChar = getChild(pPr, "buChar");
7446
+ if (buChar !== void 0) {
7447
+ return { type: "char", char: decodeXmlCharRef(getAttr(buChar, "char") ?? "\u2022") };
7448
+ }
7449
+ const buAutoNum = getChild(pPr, "buAutoNum");
7450
+ if (buAutoNum !== void 0) {
7451
+ const scheme = getAttr(buAutoNum, "type") ?? "arabicPeriod";
7452
+ return {
7453
+ type: "autoNum",
7454
+ scheme: parseEnumValueWithDefault(scheme, VALID_AUTO_NUM_SCHEMES, "arabicPeriod"),
7455
+ startAt: numericAttr2(buAutoNum, "startAt") ?? 1
7456
+ };
7457
+ }
7458
+ return void 0;
7842
7459
  }
7843
- function orderedNestedChildChildren(node, parentLocalName, childLocalName) {
7844
- if (node === void 0) return void 0;
7845
- const parentChildren = node[parentLocalName];
7846
- return orderedChildChildren2(
7847
- Array.isArray(parentChildren) ? parentChildren : void 0,
7848
- childLocalName
7460
+ function decodeXmlCharRef(value) {
7461
+ return value.replace(
7462
+ /&#x([0-9a-fA-F]+);|&#([0-9]+);/g,
7463
+ (_match, hex, decimal) => String.fromCodePoint(parseInt(hex ?? decimal ?? "0", hex !== void 0 ? 16 : 10))
7849
7464
  );
7850
7465
  }
7851
- var xmlBuilder = new import_fast_xml_parser2.XMLBuilder({
7852
- ignoreAttributes: false,
7853
- attributeNamePrefix: "@_",
7854
- format: false,
7855
- suppressEmptyNode: true
7856
- });
7857
- var EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS = {
7858
- bold: (value) => requireBooleanOrUndefined(value, "bold"),
7859
- italic: (value) => requireBooleanOrUndefined(value, "italic"),
7860
- underline: (value) => requireBooleanOrUndefined(value, "underline"),
7861
- fontSize: (value) => {
7862
- if (value !== void 0 && (!Number.isFinite(value) || value <= 0)) {
7863
- throw new Error("updateTextRunProperties: fontSize must be a finite positive pt value");
7864
- }
7865
- },
7866
- color: (value) => {
7867
- if (value === void 0) return;
7868
- if (value.kind !== "srgb") {
7869
- throw new Error("updateTextRunProperties: only srgb text run color is supported");
7870
- }
7871
- if (!/^[0-9A-Fa-f]{6}$/.test(value.hex)) {
7872
- throw new Error("updateTextRunProperties: srgb text run color must be a 6-digit hex value");
7873
- }
7874
- },
7875
- typeface: (value) => {
7876
- if (value !== void 0 && value.trim() === "") {
7877
- throw new Error("updateTextRunProperties: typeface must be a non-empty string");
7466
+ function parseRun(r, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7467
+ const properties = parseRunProperties(getChild(r, "rPr"));
7468
+ const rawSidecars = collectRunSidecars(r, nextId);
7469
+ return {
7470
+ kind: "textRun",
7471
+ text: decodeXmlCharRef(getChildText(r, "t") ?? ""),
7472
+ ...properties !== void 0 ? { properties } : {},
7473
+ handle: {
7474
+ partPath,
7475
+ nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7476
+ orderingSlot: runIndex
7477
+ },
7478
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7479
+ };
7480
+ }
7481
+ function parseBreakRun(br, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7482
+ const properties = parseRunProperties(getChild(br, "rPr"));
7483
+ return {
7484
+ kind: "textRun",
7485
+ text: "\n",
7486
+ ...properties !== void 0 ? { properties } : {},
7487
+ handle: {
7488
+ partPath,
7489
+ nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7490
+ orderingSlot: runIndex
7878
7491
  }
7879
- }
7880
- };
7881
- var EDITABLE_TEXT_RUN_PROPERTIES = Object.keys(EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS).filter(
7882
- (property) => property in EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS
7883
- );
7884
- var EDITABLE_TEXT_RUN_PROPERTY_SET = new Set(EDITABLE_TEXT_RUN_PROPERTIES);
7885
- function requireBooleanOrUndefined(value, fieldName) {
7886
- if (value !== void 0 && typeof value !== "boolean") {
7887
- throw new Error(`updateTextRunProperties: ${fieldName} must be a boolean value`);
7888
- }
7492
+ };
7889
7493
  }
7890
- function asEmu2(value) {
7891
- return unsafeBrandAssertion2(value);
7494
+ function parseRunProperties(rPr) {
7495
+ if (!rPr) return void 0;
7496
+ const bold = getAttr(rPr, "b");
7497
+ const italic = getAttr(rPr, "i");
7498
+ const underline = getAttr(rPr, "u");
7499
+ const strike = getAttr(rPr, "strike");
7500
+ const baseline = numericAttr2(rPr, "baseline");
7501
+ const size = numericAttr2(rPr, "sz");
7502
+ const typeface = getAttr(getChild(rPr, "latin"), "typeface");
7503
+ const typefaceEa = getAttr(getChild(rPr, "ea"), "typeface");
7504
+ const typefaceCs = getAttr(getChild(rPr, "cs"), "typeface");
7505
+ const hasHyperlink = getChild(rPr, "hlinkClick") !== void 0;
7506
+ const color = parseColorElement(getChild(rPr, "solidFill"));
7507
+ const properties = {
7508
+ ...bold !== void 0 ? { bold: isTrue(bold) } : {},
7509
+ ...italic !== void 0 ? { italic: isTrue(italic) } : {},
7510
+ ...underline !== void 0 ? { underline: underline !== "none" } : hasHyperlink ? { underline: true } : {},
7511
+ ...strike !== void 0 ? { strikethrough: strike !== "noStrike" } : {},
7512
+ ...baseline !== void 0 ? { baseline: baseline / 1e3 } : {},
7513
+ // `a:rPr@sz` is in 1/100 pt unit. Convert to pt and save.
7514
+ ...size !== void 0 ? { fontSize: asPt(size / 100) } : {},
7515
+ ...typeface !== void 0 ? { typeface } : {},
7516
+ ...typefaceEa !== void 0 ? { typefaceEa } : {},
7517
+ ...typefaceCs !== void 0 ? { typefaceCs } : {},
7518
+ ...color !== void 0 ? { color } : hasHyperlink ? { color: { kind: "scheme", scheme: "hlink" } } : {}
7519
+ };
7520
+ return Object.keys(properties).length > 0 ? properties : void 0;
7892
7521
  }
7893
- function asPt(value) {
7894
- return unsafeBrandAssertion2(value);
7522
+ function collectRunSidecars(r, nextId) {
7523
+ const runLevel = collectUnknownSidecars(r, KNOWN_RUN_CHILDREN, nextId);
7524
+ const propLevel = collectUnknownSidecars(getChild(r, "rPr"), KNOWN_RUN_PROPERTY_CHILDREN, nextId);
7525
+ return [...runLevel, ...propLevel];
7895
7526
  }
7896
- function asHundredthPt2(value) {
7897
- return unsafeBrandAssertion2(value);
7527
+ function emu(value) {
7528
+ return asEmu2(value);
7898
7529
  }
7899
- function asOoxmlPercent(value) {
7900
- return unsafeBrandAssertion2(value);
7530
+ function textNodeId(kind, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7531
+ const owner = ownerNodeId !== void 0 ? `shape:${ownerNodeId}` : `shapeSlot:${ownerOrderingSlot}`;
7532
+ const suffix = kind === "paragraph" ? `p:${paragraphIndex}` : `p:${paragraphIndex}:r:${runIndex}`;
7533
+ return asSourceNodeId(`text:${owner}:${suffix}`);
7901
7534
  }
7902
- function asOoxmlAngle(value) {
7903
- return unsafeBrandAssertion2(value);
7535
+ function orderedKey(node) {
7536
+ return Object.keys(node).find((key) => key !== ":@");
7904
7537
  }
7905
- var RECTANGLE_ALIGNMENT_TOKENS = /* @__PURE__ */ new Set([
7906
- "tl",
7907
- "t",
7908
- "tr",
7909
- "l",
7910
- "ctr",
7911
- "r",
7912
- "bl",
7913
- "b",
7914
- "br"
7538
+ function orderedLocalName(node) {
7539
+ const key = orderedKey(node);
7540
+ return key !== void 0 ? localName(key) : void 0;
7541
+ }
7542
+ var KNOWN_SHAPE_CHILDREN = /* @__PURE__ */ new Set(["nvSpPr", "spPr", "style", "txBody"]);
7543
+ var KNOWN_CONNECTOR_CHILDREN = /* @__PURE__ */ new Set(["nvCxnSpPr", "spPr", "style"]);
7544
+ var KNOWN_GROUP_CHILDREN = /* @__PURE__ */ new Set(["nvGrpSpPr", "grpSpPr"]);
7545
+ var KNOWN_PICTURE_CHILDREN = /* @__PURE__ */ new Set(["nvPicPr", "blipFill", "spPr"]);
7546
+ var KNOWN_BLIP_FILL_CHILDREN = /* @__PURE__ */ new Set([
7547
+ "blip",
7548
+ "srcRect",
7549
+ "stretch",
7550
+ "tile"
7551
+ ]);
7552
+ var KNOWN_BLIP_CHILDREN = /* @__PURE__ */ new Set([
7553
+ "grayscl",
7554
+ "biLevel",
7555
+ "blur",
7556
+ "lum",
7557
+ "duotone",
7558
+ "clrChange"
7559
+ ]);
7560
+ var KNOWN_EFFECT_CHILDREN = /* @__PURE__ */ new Set([
7561
+ "outerShdw",
7562
+ "innerShdw",
7563
+ "glow",
7564
+ "softEdge"
7565
+ ]);
7566
+ var KNOWN_GRAPHIC_FRAME_CHILDREN = /* @__PURE__ */ new Set([
7567
+ "nvGraphicFramePr",
7568
+ "xfrm",
7569
+ "graphic"
7570
+ ]);
7571
+ var KNOWN_GRAPHIC_CHILDREN = /* @__PURE__ */ new Set(["graphicData"]);
7572
+ var KNOWN_GRAPHIC_DATA_CHILDREN = /* @__PURE__ */ new Set(["tbl"]);
7573
+ var KNOWN_TABLE_CHILDREN = /* @__PURE__ */ new Set(["tblPr", "tblGrid", "tr"]);
7574
+ var KNOWN_TABLE_CELL_CHILDREN = /* @__PURE__ */ new Set(["txBody", "tcPr"]);
7575
+ var KNOWN_TABLE_CELL_PROPERTIES_CHILDREN = /* @__PURE__ */ new Set([
7576
+ "lnL",
7577
+ "lnR",
7578
+ "lnT",
7579
+ "lnB",
7580
+ "solidFill",
7581
+ "noFill",
7582
+ "gradFill",
7583
+ "blipFill",
7584
+ "pattFill",
7585
+ "grpFill"
7586
+ ]);
7587
+ var KNOWN_SP_PR_CHILDREN = /* @__PURE__ */ new Set([
7588
+ "xfrm",
7589
+ "prstGeom",
7590
+ "solidFill",
7591
+ "noFill",
7592
+ "gradFill",
7593
+ "blipFill",
7594
+ "pattFill",
7595
+ "grpFill",
7596
+ "ln",
7597
+ "effectLst"
7915
7598
  ]);
7916
- var COLOR_TRANSFORM_KINDS = /* @__PURE__ */ new Set([
7917
- "lumMod",
7918
- "lumOff",
7919
- "tint",
7920
- "shade",
7921
- "alpha"
7599
+ var SHAPE_TREE_NODE_TAGS = /* @__PURE__ */ new Set([
7600
+ "sp",
7601
+ "pic",
7602
+ "cxnSp",
7603
+ "grpSp",
7604
+ "graphicFrame"
7922
7605
  ]);
7923
- var RAW_FILL_LOCAL_NAMES = ["grpFill"];
7924
- var PRESET_COLOR_HEX = {
7925
- black: "000000",
7926
- white: "FFFFFF",
7927
- red: "FF0000",
7928
- green: "008000",
7929
- blue: "0000FF",
7930
- yellow: "FFFF00",
7931
- cyan: "00FFFF",
7932
- magenta: "FF00FF"
7933
- };
7934
- function parseColorElement(parent) {
7935
- if (!parent) return void 0;
7936
- const srgb = getChild(parent, "srgbClr");
7937
- if (srgb) {
7938
- const hex = getAttr(srgb, "val");
7939
- if (hex !== void 0) {
7940
- return withTransforms({ kind: "srgb", hex: hex.toUpperCase() }, srgb);
7941
- }
7606
+ var CHART_GRAPHIC_DATA_URIS = /* @__PURE__ */ new Set([
7607
+ "http://schemas.openxmlformats.org/drawingml/2006/chart",
7608
+ "http://purl.oclc.org/ooxml/drawingml/chart"
7609
+ ]);
7610
+ var SMARTART_DIAGRAM_URIS = /* @__PURE__ */ new Set([
7611
+ "http://schemas.openxmlformats.org/drawingml/2006/diagram",
7612
+ "http://purl.oclc.org/ooxml/drawingml/diagram"
7613
+ ]);
7614
+ function parseShapeTree(spTree, partPath, nextId, orderedChildren) {
7615
+ if (!spTree) return [];
7616
+ if (orderedChildren !== void 0) {
7617
+ return parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren);
7942
7618
  }
7943
- const scheme = getChild(parent, "schemeClr");
7944
- if (scheme) {
7945
- const name = getAttr(scheme, "val");
7946
- if (name !== void 0) {
7947
- return withTransforms({ kind: "scheme", scheme: name }, scheme);
7619
+ const nodes = [];
7620
+ let orderingSlot = 0;
7621
+ for (const key of Object.keys(spTree)) {
7622
+ if (key.startsWith("@_")) continue;
7623
+ if (key === "#text") continue;
7624
+ const local = localName(key);
7625
+ if (local === "nvGrpSpPr" || local === "grpSpPr") continue;
7626
+ const value = spTree[key];
7627
+ const items = Array.isArray(value) ? value : [value];
7628
+ for (const item of items) {
7629
+ const node = unsafeOoxmlBoundaryAssertion(item);
7630
+ if (local === "sp") {
7631
+ nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7632
+ } else if (local === "pic") {
7633
+ nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7634
+ } else if (local === "cxnSp") {
7635
+ nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
7636
+ } else if (local === "grpSp") {
7637
+ nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
7638
+ } else if (local === "graphicFrame") {
7639
+ nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
7640
+ } else if (local === "AlternateContent") {
7641
+ const parsed = parseAlternateContent(node, partPath, nextId, orderingSlot);
7642
+ nodes.push(...parsed);
7643
+ } else {
7644
+ nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
7645
+ }
7646
+ orderingSlot++;
7948
7647
  }
7949
7648
  }
7950
- const sys = getChild(parent, "sysClr");
7951
- if (sys) {
7952
- const val = getAttr(sys, "val");
7953
- if (val !== void 0) {
7954
- const lastClr = getAttr(sys, "lastClr");
7955
- return withTransforms(
7956
- {
7957
- kind: "system",
7958
- value: val,
7959
- ...lastClr !== void 0 ? { lastColor: lastClr.toUpperCase() } : {}
7960
- },
7961
- sys
7962
- );
7649
+ return nodes;
7650
+ }
7651
+ function parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren) {
7652
+ const nodes = [];
7653
+ const tagCounters = {};
7654
+ let orderingSlot = 0;
7655
+ for (const child of orderedChildren) {
7656
+ const key = Object.keys(child).find((candidate) => candidate !== ":@");
7657
+ if (key === void 0) continue;
7658
+ const local = localName(key);
7659
+ if (local === "AlternateContent") {
7660
+ const index2 = tagCounters[local] ?? 0;
7661
+ tagCounters[local] = index2 + 1;
7662
+ const alternateContents = getChildArray(spTree, "AlternateContent");
7663
+ const alternateContent = alternateContents[index2];
7664
+ if (alternateContent !== void 0) {
7665
+ nodes.push(...parseAlternateContent(alternateContent, partPath, nextId, orderingSlot));
7666
+ orderingSlot++;
7667
+ }
7668
+ continue;
7963
7669
  }
7670
+ if (!SHAPE_TREE_NODE_TAGS.has(local)) continue;
7671
+ const index = tagCounters[local] ?? 0;
7672
+ tagCounters[local] = index + 1;
7673
+ const node = getChildArray(spTree, local)[index];
7674
+ if (node === void 0) continue;
7675
+ nodes.push(parseShapeTreeNode(local, node, child, partPath, nextId, orderingSlot));
7676
+ orderingSlot++;
7964
7677
  }
7965
- return void 0;
7966
- }
7967
- function parseEffectList(effectList) {
7968
- if (effectList === void 0) return void 0;
7969
- const outerShadow = parseOuterShadow(getChild(effectList, "outerShdw"));
7970
- const innerShadow = parseInnerShadow(getChild(effectList, "innerShdw"));
7971
- const glow = parseGlow(getChild(effectList, "glow"));
7972
- const softEdge = parseSoftEdge(getChild(effectList, "softEdge"));
7973
- const parsed = {
7974
- ...outerShadow !== void 0 ? { outerShadow } : {},
7975
- ...innerShadow !== void 0 ? { innerShadow } : {},
7976
- ...glow !== void 0 ? { glow } : {},
7977
- ...softEdge !== void 0 ? { softEdge } : {}
7978
- };
7979
- return Object.keys(parsed).length > 0 ? parsed : void 0;
7678
+ return nodes;
7980
7679
  }
7981
- function parseBlipEffects(blip) {
7982
- if (blip === void 0) return void 0;
7983
- const grayscale = getChild(blip, "grayscl") !== void 0;
7984
- const biLevel = parseBiLevel(getChild(blip, "biLevel"));
7985
- const blur = parseBlurEffect(getChild(blip, "blur"));
7986
- const lum = parseLumEffect(getChild(blip, "lum"));
7987
- const duotone = parseDuotoneEffect(getChild(blip, "duotone"));
7988
- const clrChange = parseColorChangeEffect(getChild(blip, "clrChange"));
7989
- const parsed = {
7990
- grayscale,
7991
- ...biLevel !== void 0 ? { biLevel } : {},
7992
- ...blur !== void 0 ? { blur } : {},
7993
- ...lum !== void 0 ? { lum } : {},
7994
- ...duotone !== void 0 ? { duotone } : {},
7995
- ...clrChange !== void 0 ? { clrChange } : {}
7996
- };
7997
- return grayscale || biLevel !== void 0 || blur !== void 0 || lum !== void 0 || duotone !== void 0 || clrChange !== void 0 ? parsed : void 0;
7680
+ function parseShapeTreeNode(local, node, orderedNode, partPath, nextId, orderingSlot) {
7681
+ if (local === "sp") return parseShape(node, partPath, nextId, orderingSlot, orderedNode);
7682
+ if (local === "pic") return parseImage(node, partPath, nextId, orderingSlot);
7683
+ if (local === "cxnSp") {
7684
+ return parseConnector(node, partPath, nextId, orderingSlot, orderedNode);
7685
+ }
7686
+ if (local === "grpSp") {
7687
+ const orderedGroupChildren = unsafeOoxmlBoundaryAssertion(orderedNode?.[local]);
7688
+ return parseGroup(node, partPath, nextId, orderingSlot, orderedGroupChildren);
7689
+ }
7690
+ if (local === "graphicFrame") {
7691
+ return parseGraphicFrame(node, partPath, nextId, orderingSlot, orderedNode);
7692
+ }
7693
+ return parseRawShapeNode(`p:${local}`, node, partPath, nextId, orderingSlot);
7998
7694
  }
7999
- function parseOuterShadow(node) {
8000
- if (node === void 0) return void 0;
8001
- const color = parseColorElement(node);
8002
- if (color === void 0) return void 0;
7695
+ function parseShape(sp, partPath, nextId, orderingSlot, orderedNode) {
7696
+ const nvSpPr = getChild(sp, "nvSpPr");
7697
+ const cNvPr = getChild(nvSpPr, "cNvPr");
7698
+ const nodeId = sourceNodeId(cNvPr);
7699
+ const name = getAttr(cNvPr, "name");
7700
+ const placeholder = parsePlaceholder(getChild(getChild(nvSpPr, "nvPr"), "ph"));
7701
+ const spPr = getChild(sp, "spPr");
7702
+ const transform = parseTransform(spPr);
7703
+ const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "sp", "spPr"));
7704
+ const fill = parseFill(spPr, nextId);
7705
+ const outline = parseOutline(spPr, nextId);
7706
+ const effects = parseEffectList(getChild(spPr, "effectLst"));
7707
+ const style = parseShapeStyle(getChild(sp, "style"));
7708
+ const textBody = parseTextBody(
7709
+ getChild(sp, "txBody"),
7710
+ partPath,
7711
+ nextId,
7712
+ nodeId,
7713
+ orderingSlot,
7714
+ orderedNestedChildChildren(orderedNode, "sp", "txBody")
7715
+ );
7716
+ const rawSidecars = [
7717
+ ...collectUnknownSidecars(sp, KNOWN_SHAPE_CHILDREN, nextId),
7718
+ ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7719
+ ...collectEffectSidecars(spPr, effects, nextId)
7720
+ ];
8003
7721
  return {
8004
- blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
8005
- distance: asEmu2(numericAttr2(node, "dist") ?? 0),
8006
- direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
8007
- color,
8008
- alignment: parseRectangleAlignment(getAttr(node, "algn"), "b"),
8009
- rotateWithShape: getAttr(node, "rotWithShape") !== "0"
7722
+ kind: "shape",
7723
+ ...nodeId !== void 0 ? { nodeId } : {},
7724
+ ...name !== void 0 ? { name } : {},
7725
+ ...transform !== void 0 ? { transform } : {},
7726
+ ...geometry !== void 0 ? { geometry } : {},
7727
+ ...fill !== void 0 ? { fill } : {},
7728
+ ...outline !== void 0 ? { outline } : {},
7729
+ ...effects !== void 0 ? { effects } : {},
7730
+ ...style !== void 0 ? { style } : {},
7731
+ ...textBody !== void 0 ? { textBody } : {},
7732
+ ...placeholder !== void 0 ? { placeholder } : {},
7733
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7734
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8010
7735
  };
8011
7736
  }
8012
- function parseInnerShadow(node) {
8013
- if (node === void 0) return void 0;
8014
- const color = parseColorElement(node);
8015
- if (color === void 0) return void 0;
7737
+ function parseConnector(cxnSp, partPath, nextId, orderingSlot, orderedNode) {
7738
+ const nvCxnSpPr = getChild(cxnSp, "nvCxnSpPr");
7739
+ const cNvPr = getChild(nvCxnSpPr, "cNvPr");
7740
+ const cNvCxnSpPr = getChild(nvCxnSpPr, "cNvCxnSpPr");
7741
+ const nodeId = sourceNodeId(cNvPr);
7742
+ const name = getAttr(cNvPr, "name");
7743
+ const connection = parseConnectorConnection(cNvCxnSpPr);
7744
+ const spPr = getChild(cxnSp, "spPr");
7745
+ const transform = parseTransform(spPr);
7746
+ const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "cxnSp", "spPr"));
7747
+ const outline = parseOutline(spPr, nextId);
7748
+ const effects = parseEffectList(getChild(spPr, "effectLst"));
7749
+ const style = parseShapeStyle(getChild(cxnSp, "style"));
7750
+ const rawSidecars = [
7751
+ ...collectUnknownSidecars(cxnSp, KNOWN_CONNECTOR_CHILDREN, nextId),
7752
+ ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7753
+ ...collectEffectSidecars(spPr, effects, nextId)
7754
+ ];
8016
7755
  return {
8017
- blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
8018
- distance: asEmu2(numericAttr2(node, "dist") ?? 0),
8019
- direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
8020
- color
7756
+ kind: "connector",
7757
+ ...nodeId !== void 0 ? { nodeId } : {},
7758
+ ...name !== void 0 ? { name } : {},
7759
+ ...connection !== void 0 ? { connection } : {},
7760
+ ...transform !== void 0 ? { transform } : {},
7761
+ ...geometry !== void 0 ? { geometry } : {},
7762
+ ...outline !== void 0 ? { outline } : {},
7763
+ ...effects !== void 0 ? { effects } : {},
7764
+ ...style !== void 0 ? { style } : {},
7765
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7766
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8021
7767
  };
8022
7768
  }
8023
- function parseGlow(node) {
8024
- if (node === void 0) return void 0;
8025
- const color = parseColorElement(node);
8026
- if (color === void 0) return void 0;
7769
+ function parseConnectorConnection(cNvCxnSpPr) {
7770
+ const start = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "stCxn"));
7771
+ const end = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "endCxn"));
7772
+ return start !== void 0 || end !== void 0 ? {
7773
+ ...start !== void 0 ? { start } : {},
7774
+ ...end !== void 0 ? { end } : {}
7775
+ } : void 0;
7776
+ }
7777
+ function parseConnectorConnectionEndpoint(node) {
7778
+ const shapeId = getAttr(node, "id");
7779
+ const connectionSiteIndex = numericAttr2(node, "idx");
7780
+ if (shapeId === void 0 || connectionSiteIndex === void 0) return void 0;
8027
7781
  return {
8028
- radius: asEmu2(numericAttr2(node, "rad") ?? 0),
8029
- color
7782
+ shapeId: asSourceNodeId(shapeId),
7783
+ connectionSiteIndex
8030
7784
  };
8031
7785
  }
8032
- function parseSoftEdge(node) {
8033
- if (node === void 0) return void 0;
8034
- return {
8035
- radius: asEmu2(numericAttr2(node, "rad") ?? 0)
7786
+ function parseShapeStyle(style) {
7787
+ if (style === void 0) return void 0;
7788
+ const fillRef = parseStyleReference(getChild(style, "fillRef"));
7789
+ const lineRef = parseStyleReference(getChild(style, "lnRef"));
7790
+ const effectRef = parseStyleReference(getChild(style, "effectRef"));
7791
+ const parsed = {
7792
+ ...fillRef !== void 0 ? { fillRef } : {},
7793
+ ...lineRef !== void 0 ? { lineRef } : {},
7794
+ ...effectRef !== void 0 ? { effectRef } : {}
8036
7795
  };
7796
+ return Object.keys(parsed).length > 0 ? parsed : void 0;
8037
7797
  }
8038
- function parseBiLevel(node) {
8039
- if (node === void 0) return void 0;
7798
+ function parseStyleReference(ref) {
7799
+ if (ref === void 0) return void 0;
7800
+ const index = numericAttr2(ref, "idx") ?? 0;
7801
+ const color = parseColorElement(ref);
8040
7802
  return {
8041
- threshold: (numericAttr2(node, "thresh") ?? 5e4) / 1e5
7803
+ index,
7804
+ ...color !== void 0 ? { color } : {}
8042
7805
  };
8043
7806
  }
8044
- function parseBlurEffect(node) {
8045
- if (node === void 0) return void 0;
7807
+ function parseGroup(grpSp, partPath, nextId, orderingSlot, orderedChildren) {
7808
+ const nvGrpSpPr = getChild(grpSp, "nvGrpSpPr");
7809
+ const cNvPr = getChild(nvGrpSpPr, "cNvPr");
7810
+ const nodeId = sourceNodeId(cNvPr);
7811
+ const name = getAttr(cNvPr, "name");
7812
+ const grpSpPr = getChild(grpSp, "grpSpPr");
7813
+ const transform = parseTransform(grpSpPr);
7814
+ const childTransform = parseChildTransform(grpSpPr, transform);
7815
+ const fill = parseFill(grpSpPr, nextId);
7816
+ const effects = parseEffectList(getChild(grpSpPr, "effectLst"));
7817
+ const rawSidecars = [
7818
+ ...collectUnknownSidecars(grpSp, KNOWN_GROUP_CHILDREN, nextId),
7819
+ ...collectUnknownSidecars(grpSpPr, KNOWN_SP_PR_CHILDREN, nextId),
7820
+ ...collectEffectSidecars(grpSpPr, effects, nextId)
7821
+ ];
8046
7822
  return {
8047
- radius: asEmu2(numericAttr2(node, "rad") ?? 0),
8048
- grow: getAttr(node, "grow") !== "0"
7823
+ kind: "group",
7824
+ ...nodeId !== void 0 ? { nodeId } : {},
7825
+ ...name !== void 0 ? { name } : {},
7826
+ ...transform !== void 0 ? { transform } : {},
7827
+ ...childTransform !== void 0 ? { childTransform } : {},
7828
+ ...fill !== void 0 ? { fill } : {},
7829
+ ...effects !== void 0 ? { effects } : {},
7830
+ children: parseShapeTree(grpSp, partPath, nextId, orderedChildren),
7831
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7832
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8049
7833
  };
8050
7834
  }
8051
- function parseLumEffect(node) {
8052
- if (node === void 0) return void 0;
7835
+ function parseImage(pic, partPath, nextId, orderingSlot) {
7836
+ const cNvPr = getChild(getChild(pic, "nvPicPr"), "cNvPr");
7837
+ const nodeId = sourceNodeId(cNvPr);
7838
+ const name = getAttr(cNvPr, "name");
7839
+ const blipFill = getChild(pic, "blipFill");
7840
+ const blip = getChild(blipFill, "blip");
7841
+ const embed = getNamespacedAttr(blip, "embed");
7842
+ const crop = parseCrop(getChild(blipFill, "srcRect"));
7843
+ const stretch = parseStretch(getChild(blipFill, "stretch"));
7844
+ const tile = parseImageFillTile(getChild(blipFill, "tile"));
7845
+ const blipEffects = parseBlipEffects(blip);
7846
+ const spPr = getChild(pic, "spPr");
7847
+ const transform = parseTransform(spPr);
7848
+ const effects = parseEffectList(getChild(spPr, "effectLst"));
7849
+ const rawSidecars = [
7850
+ ...collectUnknownSidecars(pic, KNOWN_PICTURE_CHILDREN, nextId),
7851
+ ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7852
+ ...collectEffectSidecars(spPr, effects, nextId),
7853
+ // Retains fill mode such as `a:stretch` / `a:tile` and recolor operation under blip.
7854
+ ...collectUnknownSidecars(blipFill, KNOWN_BLIP_FILL_CHILDREN, nextId),
7855
+ ...collectBlipEffectSidecars(blip, blipEffects, nextId)
7856
+ ];
8053
7857
  return {
8054
- brightness: (numericAttr2(node, "bright") ?? 0) / 1e5,
8055
- contrast: (numericAttr2(node, "contrast") ?? 0) / 1e5
7858
+ kind: "image",
7859
+ ...nodeId !== void 0 ? { nodeId } : {},
7860
+ ...name !== void 0 ? { name } : {},
7861
+ ...transform !== void 0 ? { transform } : {},
7862
+ ...embed !== void 0 ? { blipRelationshipId: asRelationshipId(embed) } : {},
7863
+ ...crop !== void 0 ? { crop } : {},
7864
+ ...stretch !== void 0 ? { stretch } : {},
7865
+ ...tile !== void 0 ? { tile } : {},
7866
+ ...effects !== void 0 ? { effects } : {},
7867
+ ...blipEffects !== void 0 ? { blipEffects } : {},
7868
+ handle: {
7869
+ partPath,
7870
+ ...nodeId !== void 0 ? { nodeId } : {},
7871
+ ...embed !== void 0 ? { relationshipId: asRelationshipId(embed) } : {},
7872
+ orderingSlot
7873
+ },
7874
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8056
7875
  };
8057
7876
  }
8058
- function parseDuotoneEffect(node) {
8059
- if (node === void 0) return void 0;
8060
- const colors = collectColorChildren(node);
8061
- if (colors.length < 2) return void 0;
8062
- return { color1: colors[0], color2: colors[1] };
8063
- }
8064
- function parseColorChangeEffect(node) {
8065
- if (node === void 0) return void 0;
8066
- const from = firstColorChild(getChild(node, "clrFrom"));
8067
- const to = firstColorChild(getChild(node, "clrTo"));
8068
- return from !== void 0 && to !== void 0 ? { from, to } : void 0;
8069
- }
8070
- function collectColorChildren(parent) {
8071
- const colors = [];
8072
- for (const [key, value] of Object.entries(parent)) {
8073
- if (key.startsWith("@_")) continue;
8074
- const nodes = Array.isArray(value) ? value : [value];
8075
- for (const node of nodes) {
8076
- if (!isXmlNode(node)) continue;
8077
- const color = parseColorChild(key, node);
8078
- if (color !== void 0) colors.push(color);
7877
+ function collectEffectSidecars(spPr, effects, nextId) {
7878
+ const effectList = getChild(spPr, "effectLst");
7879
+ if (effectList === void 0) return [];
7880
+ const sidecars = collectUnknownSidecars(effectList, KNOWN_EFFECT_CHILDREN, nextId);
7881
+ const supportedChildren = [
7882
+ ["outerShdw", effects?.outerShadow],
7883
+ ["innerShdw", effects?.innerShadow],
7884
+ ["glow", effects?.glow],
7885
+ ["softEdge", effects?.softEdge]
7886
+ ];
7887
+ for (const [name, parsed] of supportedChildren) {
7888
+ const node = getChild(effectList, name);
7889
+ if (node !== void 0 && parsed === void 0) {
7890
+ sidecars.push(makeSidecar(`a:${name}`, node, nextId));
8079
7891
  }
8080
7892
  }
8081
- return colors;
8082
- }
8083
- function firstColorChild(parent) {
8084
- return parent !== void 0 ? collectColorChildren(parent)[0] : void 0;
8085
- }
8086
- function parseColorChild(key, node) {
8087
- const name = localName(key);
8088
- return name === "prstClr" ? parsePresetColor(node) : parseColorElement({ [name]: node });
8089
- }
8090
- function isXmlNode(value) {
8091
- return typeof value === "object" && value !== null;
7893
+ return sidecars;
8092
7894
  }
8093
- function parsePresetColor(node) {
8094
- const value = getAttr(node, "val");
8095
- const hex = value !== void 0 ? PRESET_COLOR_HEX[value] : void 0;
8096
- return hex !== void 0 ? withTransforms({ kind: "srgb", hex }, node) : void 0;
7895
+ function collectBlipEffectSidecars(blip, effects, nextId) {
7896
+ if (blip === void 0) return [];
7897
+ const sidecars = collectUnknownSidecars(blip, KNOWN_BLIP_CHILDREN, nextId);
7898
+ const supportedChildren = [
7899
+ ["grayscl", effects?.grayscale === true],
7900
+ ["biLevel", effects?.biLevel],
7901
+ ["blur", effects?.blur],
7902
+ ["lum", effects?.lum],
7903
+ ["duotone", effects?.duotone],
7904
+ ["clrChange", effects?.clrChange]
7905
+ ];
7906
+ for (const [name, parsed] of supportedChildren) {
7907
+ const node = getChild(blip, name);
7908
+ if (node !== void 0 && (parsed === void 0 || parsed === false)) {
7909
+ sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7910
+ }
7911
+ }
7912
+ return sidecars;
8097
7913
  }
8098
- function parseFill(parent, nextId) {
8099
- if (!parent) return void 0;
8100
- const solid = getChild(parent, "solidFill");
8101
- if (solid) {
8102
- const color = parseColorElement(solid);
8103
- if (color) return { kind: "solid", color };
8104
- return { kind: "raw", raw: makeSidecar("a:solidFill", solid, nextId) };
7914
+ function parseGraphicFrame(graphicFrame, partPath, nextId, orderingSlot, orderedNode) {
7915
+ const graphic = getChild(graphicFrame, "graphic");
7916
+ const graphicData = getChild(graphic, "graphicData");
7917
+ const uri = getAttr(graphicData, "uri");
7918
+ if (uri !== void 0 && CHART_GRAPHIC_DATA_URIS.has(uri)) {
7919
+ const parsedChart = parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7920
+ if (parsedChart !== void 0) return parsedChart;
8105
7921
  }
8106
- if (hasChild(parent, "noFill")) return { kind: "none" };
8107
- const grad = getChild(parent, "gradFill");
8108
- if (grad) {
8109
- const fill = parseGradientFill(grad);
8110
- return fill ?? { kind: "raw", raw: makeSidecar("a:gradFill", grad, nextId) };
7922
+ if (uri !== void 0 && SMARTART_DIAGRAM_URIS.has(uri)) {
7923
+ const parsedSmartArt = parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7924
+ if (parsedSmartArt !== void 0) return parsedSmartArt;
8111
7925
  }
8112
- const blip = getChild(parent, "blipFill");
8113
- if (blip) {
8114
- return parseBlipFill(blip) ?? { kind: "raw", raw: makeSidecar("a:blipFill", blip, nextId) };
7926
+ const table = getChild(graphicData, "tbl");
7927
+ if (table === void 0) {
7928
+ return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
8115
7929
  }
8116
- const pattern = getChild(parent, "pattFill");
8117
- if (pattern) {
8118
- const fill = parsePatternFill(pattern);
8119
- return fill ?? { kind: "raw", raw: makeSidecar("a:pattFill", pattern, nextId) };
7930
+ const orderedGraphicChildren = orderedNestedChildChildren(orderedNode, "graphicFrame", "graphic");
7931
+ const orderedGraphicDataChildren = orderedChildChildren2(orderedGraphicChildren, "graphicData");
7932
+ const orderedTableChildren = orderedChildChildren2(orderedGraphicDataChildren, "tbl");
7933
+ const parsedTable = parseTable(
7934
+ table,
7935
+ graphicFrame,
7936
+ partPath,
7937
+ nextId,
7938
+ orderingSlot,
7939
+ orderedTableChildren
7940
+ );
7941
+ if (parsedTable === void 0) {
7942
+ return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
8120
7943
  }
8121
- for (const name of RAW_FILL_LOCAL_NAMES) {
8122
- if (hasChild(parent, name)) {
8123
- return { kind: "raw", raw: makeSidecar(`a:${name}`, getChild(parent, name) ?? {}, nextId) };
7944
+ return parsedTable;
7945
+ }
7946
+ function parseAlternateContent(alternateContent, partPath, nextId, orderingSlot) {
7947
+ const branches = [
7948
+ ...getChildArray(alternateContent, "Choice"),
7949
+ ...getChildArray(alternateContent, "Fallback")
7950
+ ];
7951
+ for (const branch of branches) {
7952
+ const parsed = parseAlternateContentBranch(branch, partPath, nextId, orderingSlot);
7953
+ if (parsed.length > 0) {
7954
+ if (parsed.every((node) => node.kind === "raw")) {
7955
+ continue;
7956
+ }
7957
+ return parsed.map(
7958
+ (node) => attachRawSidecar(node, makeSidecar("mc:AlternateContent", alternateContent, nextId))
7959
+ );
7960
+ }
7961
+ }
7962
+ return [
7963
+ parseRawShapeNode("mc:AlternateContent", alternateContent, partPath, nextId, orderingSlot)
7964
+ ];
7965
+ }
7966
+ function attachRawSidecar(node, sidecar) {
7967
+ if (node.kind === "raw") return node;
7968
+ return {
7969
+ ...node,
7970
+ rawSidecars: [...node.rawSidecars ?? [], sidecar]
7971
+ };
7972
+ }
7973
+ function parseAlternateContentBranch(branch, partPath, nextId, orderingSlot) {
7974
+ const nodes = [];
7975
+ for (const key of Object.keys(branch)) {
7976
+ if (key.startsWith("@_") || key === "#text") continue;
7977
+ const local = localName(key);
7978
+ const value = branch[key];
7979
+ const items = Array.isArray(value) ? value : [value];
7980
+ for (const item of items) {
7981
+ const node = unsafeOoxmlBoundaryAssertion(item);
7982
+ if (local === "sp") nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7983
+ else if (local === "pic") nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7984
+ else if (local === "cxnSp") {
7985
+ nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
7986
+ } else if (local === "grpSp") {
7987
+ nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
7988
+ } else if (local === "graphicFrame") {
7989
+ nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
7990
+ } else {
7991
+ nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
7992
+ }
8124
7993
  }
8125
7994
  }
8126
- return void 0;
7995
+ return nodes;
8127
7996
  }
8128
- function parseGradientFill(grad) {
8129
- const stops = [];
8130
- for (const gs of getChildArray(getChild(grad, "gsLst"), "gs")) {
8131
- const color = parseColorElement(gs);
8132
- if (color === void 0) continue;
8133
- stops.push({
8134
- position: (numericAttr2(gs, "pos") ?? 0) / 1e5,
8135
- color
8136
- });
8137
- }
8138
- if (stops.length === 0) return void 0;
8139
- const path = getChild(grad, "path");
8140
- if (path !== void 0) {
8141
- const fillToRect = getChild(path, "fillToRect");
8142
- const l = numericAttr2(fillToRect, "l") ?? 0;
8143
- const t = numericAttr2(fillToRect, "t") ?? 0;
8144
- const r = numericAttr2(fillToRect, "r") ?? 0;
8145
- const b = numericAttr2(fillToRect, "b") ?? 0;
8146
- return {
8147
- kind: "gradient",
8148
- gradientType: "radial",
8149
- stops,
8150
- centerX: (l + (1e5 - r)) / 2 / 1e5,
8151
- centerY: (t + (1e5 - b)) / 2 / 1e5
8152
- };
8153
- }
7997
+ function parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
7998
+ const graphic = getChild(graphicFrame, "graphic");
7999
+ const graphicData = getChild(graphic, "graphicData");
8000
+ const chart = getChild(graphicData, "chart");
8001
+ const rId = getNamespacedAttr(chart, "id") ?? getAttr(chart, "id");
8002
+ if (rId === void 0) return void 0;
8003
+ const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
8004
+ const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
8005
+ const nodeId = sourceNodeId(cNvPr);
8006
+ const name = getAttr(cNvPr, "name");
8007
+ const transform = parseTransform(graphicFrame);
8008
+ const rawSidecars = [
8009
+ ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
8010
+ ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
8011
+ ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
8012
+ ];
8154
8013
  return {
8155
- kind: "gradient",
8156
- gradientType: "linear",
8157
- stops,
8158
- angle: asOoxmlAngle(numericAttr2(getChild(grad, "lin"), "ang") ?? 0)
8014
+ kind: "chart",
8015
+ ...nodeId !== void 0 ? { nodeId } : {},
8016
+ ...name !== void 0 ? { name } : {},
8017
+ ...transform !== void 0 ? { transform } : {},
8018
+ chartRelationshipId: asRelationshipId(rId),
8019
+ handle: {
8020
+ partPath,
8021
+ ...nodeId !== void 0 ? { nodeId } : {},
8022
+ relationshipId: asRelationshipId(rId),
8023
+ orderingSlot
8024
+ },
8025
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8159
8026
  };
8160
8027
  }
8161
- function parseBlipFill(blipFill) {
8162
- const blip = getChild(blipFill, "blip");
8163
- const embed = getNamespacedAttr(blip, "embed");
8164
- if (embed === void 0) return void 0;
8165
- const tile = parseImageFillTile(getChild(blipFill, "tile"));
8028
+ function parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
8029
+ const graphic = getChild(graphicFrame, "graphic");
8030
+ const graphicData = getChild(graphic, "graphicData");
8031
+ const relIds = getChild(graphicData, "relIds");
8032
+ const dmRId = getNamespacedAttr(relIds, "dm") ?? getAttr(relIds, "dm");
8033
+ if (dmRId === void 0) return void 0;
8034
+ const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
8035
+ const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
8036
+ const nodeId = sourceNodeId(cNvPr);
8037
+ const name = getAttr(cNvPr, "name");
8038
+ const transform = parseTransform(graphicFrame);
8039
+ const rawSidecars = [
8040
+ ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
8041
+ ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
8042
+ ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
8043
+ ];
8166
8044
  return {
8167
- kind: "image",
8168
- blipRelationshipId: asRelationshipId(embed),
8169
- ...tile !== void 0 ? { tile } : {}
8045
+ kind: "smartArt",
8046
+ ...nodeId !== void 0 ? { nodeId } : {},
8047
+ ...name !== void 0 ? { name } : {},
8048
+ ...transform !== void 0 ? { transform } : {},
8049
+ dataRelationshipId: asRelationshipId(dmRId),
8050
+ handle: {
8051
+ partPath,
8052
+ ...nodeId !== void 0 ? { nodeId } : {},
8053
+ relationshipId: asRelationshipId(dmRId),
8054
+ orderingSlot
8055
+ },
8056
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8170
8057
  };
8171
8058
  }
8172
- function parseImageFillTile(tile) {
8173
- if (tile === void 0) return void 0;
8174
- const flip = getAttr(tile, "flip") ?? "none";
8059
+ function parseTable(tbl, graphicFrame, partPath, nextId, orderingSlot, orderedTableChildren) {
8060
+ const columns = parseTableColumns(getChild(tbl, "tblGrid"));
8061
+ if (columns.length === 0) return void 0;
8062
+ const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
8063
+ const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
8064
+ const nodeId = sourceNodeId(cNvPr);
8065
+ const name = getAttr(cNvPr, "name");
8066
+ const tblPr = getChild(tbl, "tblPr");
8067
+ const tableStyleId = getChildText(tblPr, "tableStyleId");
8068
+ const graphic = getChild(graphicFrame, "graphic");
8069
+ const graphicData = getChild(graphic, "graphicData");
8070
+ const transform = parseTransform(graphicFrame);
8071
+ const rows = parseTableRows(tbl, partPath, nextId, nodeId, orderingSlot, orderedTableChildren);
8072
+ const rawSidecars = [
8073
+ ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
8074
+ ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
8075
+ ...collectUnknownSidecars(graphicData, KNOWN_GRAPHIC_DATA_CHILDREN, nextId),
8076
+ ...collectUnknownSidecars(tbl, KNOWN_TABLE_CHILDREN, nextId)
8077
+ ];
8175
8078
  return {
8176
- tx: asEmu2(numericAttr2(tile, "tx") ?? 0),
8177
- ty: asEmu2(numericAttr2(tile, "ty") ?? 0),
8178
- sx: (numericAttr2(tile, "sx") ?? 1e5) / 1e5,
8179
- sy: (numericAttr2(tile, "sy") ?? 1e5) / 1e5,
8180
- flip: flip === "x" || flip === "y" || flip === "xy" ? flip : "none",
8181
- align: parseRectangleAlignment(getAttr(tile, "algn"), "tl")
8079
+ kind: "table",
8080
+ ...nodeId !== void 0 ? { nodeId } : {},
8081
+ ...name !== void 0 ? { name } : {},
8082
+ ...transform !== void 0 ? { transform } : {},
8083
+ table: {
8084
+ columns,
8085
+ rows,
8086
+ ...tableStyleId !== void 0 ? { tableStyleId } : {}
8087
+ },
8088
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
8089
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8182
8090
  };
8183
8091
  }
8184
- function parseRectangleAlignment(value, fallback) {
8185
- return parseEnumValueWithDefault(value, RECTANGLE_ALIGNMENT_TOKENS, fallback);
8092
+ function parseTableColumns(tblGrid) {
8093
+ return getChildArray(tblGrid, "gridCol").map((col) => ({ width: emuAttr(col, "w") }));
8186
8094
  }
8187
- function parsePatternFill(pattern) {
8188
- const foregroundColor = parseColorElement(getChild(pattern, "fgClr"));
8189
- const backgroundColor = parseColorElement(getChild(pattern, "bgClr"));
8190
- if (foregroundColor === void 0 || backgroundColor === void 0) return void 0;
8095
+ function parseTableRows(tbl, partPath, nextId, tableNodeId, tableOrderingSlot, orderedTableChildren) {
8096
+ const orderedRows = orderedChildChildrenList(orderedTableChildren, "tr");
8097
+ return getChildArray(tbl, "tr").map((tr, rowIndex) => ({
8098
+ height: emuAttr(tr, "h"),
8099
+ cells: getChildArray(tr, "tc").map((tc, cellIndex) => {
8100
+ const orderedCells = orderedChildChildrenList(orderedRows[rowIndex], "tc");
8101
+ return parseTableCell(
8102
+ tc,
8103
+ partPath,
8104
+ nextId,
8105
+ tableNodeId,
8106
+ tableOrderingSlot,
8107
+ rowIndex,
8108
+ cellIndex,
8109
+ orderedCells[cellIndex]
8110
+ );
8111
+ })
8112
+ }));
8113
+ }
8114
+ function parseTableCell(tc, partPath, nextId, tableNodeId, tableOrderingSlot, rowIndex, cellIndex, orderedCellChildren) {
8115
+ const tcPr = getChild(tc, "tcPr");
8116
+ const textOrderingSlot = tableOrderingSlot * 1e9 + rowIndex * 1e6 + cellIndex;
8117
+ const textBody = parseTextBody(
8118
+ getChild(tc, "txBody"),
8119
+ partPath,
8120
+ nextId,
8121
+ tableNodeId,
8122
+ textOrderingSlot,
8123
+ orderedChildChildren2(orderedCellChildren, "txBody")
8124
+ );
8125
+ const fill = parseFill(tcPr, nextId);
8126
+ const borders = parseCellBorders(tcPr, nextId);
8127
+ const rawSidecars = [
8128
+ ...collectUnknownSidecars(tc, KNOWN_TABLE_CELL_CHILDREN, nextId),
8129
+ ...collectUnknownSidecars(tcPr, KNOWN_TABLE_CELL_PROPERTIES_CHILDREN, nextId)
8130
+ ];
8191
8131
  return {
8192
- kind: "pattern",
8193
- preset: getAttr(pattern, "prst") ?? "ltDnDiag",
8194
- foregroundColor,
8195
- backgroundColor
8132
+ ...textBody !== void 0 ? { textBody } : {},
8133
+ ...fill !== void 0 ? { fill } : {},
8134
+ ...borders !== void 0 ? { borders } : {},
8135
+ gridSpan: numericAttr2(tc, "gridSpan") ?? 1,
8136
+ rowSpan: numericAttr2(tc, "rowSpan") ?? 1,
8137
+ hMerge: isTrue(getAttr(tc, "hMerge") ?? getAttr(tcPr, "hMerge")),
8138
+ vMerge: isTrue(getAttr(tc, "vMerge") ?? getAttr(tcPr, "vMerge")),
8139
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
8196
8140
  };
8197
8141
  }
8198
- function parseOutline(spPr, nextId) {
8199
- const ln = getChild(spPr, "ln");
8200
- return parseLine(ln, nextId);
8142
+ function parseCellBorders(tcPr, nextId) {
8143
+ const left = parseLine(getChild(tcPr, "lnL"), nextId);
8144
+ const right = parseLine(getChild(tcPr, "lnR"), nextId);
8145
+ const top = parseLine(getChild(tcPr, "lnT"), nextId);
8146
+ const bottom = parseLine(getChild(tcPr, "lnB"), nextId);
8147
+ if (left === void 0 && right === void 0 && top === void 0 && bottom === void 0) {
8148
+ return void 0;
8149
+ }
8150
+ return {
8151
+ ...top !== void 0 ? { top } : {},
8152
+ ...bottom !== void 0 ? { bottom } : {},
8153
+ ...left !== void 0 ? { left } : {},
8154
+ ...right !== void 0 ? { right } : {}
8155
+ };
8201
8156
  }
8202
- function parseLine(ln, nextId) {
8203
- if (!ln) return void 0;
8204
- const width = numericAttr2(ln, "w");
8205
- const fill = parseFill(ln, nextId);
8206
- const dashStyle = parseDashStyle(getChild(ln, "prstDash"));
8207
- const customDash = parseCustomDash(ln);
8208
- const lineCap = parseLineCap(getAttr(ln, "cap"));
8209
- const lineJoin = parseLineJoin(ln);
8210
- const headEnd = parseArrowEndpoint(getChild(ln, "headEnd"));
8211
- const tailEnd = parseArrowEndpoint(getChild(ln, "tailEnd"));
8157
+ function parseRawShapeNode(key, node, partPath, nextId, orderingSlot) {
8158
+ const nodeId = sourceNodeId(getChild(getChild(node, "nvSpPr"), "cNvPr"));
8159
+ return {
8160
+ kind: "raw",
8161
+ ...nodeId !== void 0 ? { nodeId } : {},
8162
+ raw: makeSidecar(key, node, nextId),
8163
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot }
8164
+ };
8165
+ }
8166
+ function parsePlaceholder(ph) {
8167
+ if (!ph) return void 0;
8168
+ const type = getAttr(ph, "type");
8169
+ const index = numericAttr2(ph, "idx");
8170
+ if (type === void 0 && index === void 0) return void 0;
8212
8171
  return {
8213
- ...width !== void 0 ? { width: asEmu2(width) } : {},
8214
- ...fill !== void 0 ? { fill } : {},
8215
- ...dashStyle !== void 0 ? { dashStyle } : {},
8216
- ...customDash !== void 0 ? { customDash } : {},
8217
- ...lineCap !== void 0 ? { lineCap } : {},
8218
- ...lineJoin !== void 0 ? { lineJoin } : {},
8219
- ...headEnd !== void 0 ? { headEnd } : {},
8220
- ...tailEnd !== void 0 ? { tailEnd } : {}
8172
+ ...type !== void 0 ? { type } : {},
8173
+ ...index !== void 0 ? { index } : {}
8221
8174
  };
8222
8175
  }
8223
- function parseTransform(spPr) {
8224
- const xfrm = getChild(spPr, "xfrm");
8225
- if (!xfrm) return void 0;
8226
- const off = getChild(xfrm, "off");
8227
- const ext = getChild(xfrm, "ext");
8228
- const offsetX = numericAttr2(off, "x");
8229
- const offsetY = numericAttr2(off, "y");
8230
- const width = numericAttr2(ext, "cx");
8231
- const height = numericAttr2(ext, "cy");
8232
- if (offsetX === void 0 || offsetY === void 0 || width === void 0 || height === void 0) {
8233
- return void 0;
8176
+ function parseGeometry(spPr, orderedSpPr) {
8177
+ const prstGeom = getChild(spPr, "prstGeom");
8178
+ if (prstGeom) {
8179
+ const preset = getAttr(prstGeom, "prst");
8180
+ const adjustValues = parseAdjustValues(getChild(prstGeom, "avLst"));
8181
+ return preset !== void 0 ? {
8182
+ preset,
8183
+ ...Object.keys(adjustValues).length > 0 ? { adjustValues } : {}
8184
+ } : void 0;
8234
8185
  }
8235
- const rotation = numericAttr2(xfrm, "rot");
8236
- const flipH = getAttr(xfrm, "flipH");
8237
- const flipV = getAttr(xfrm, "flipV");
8186
+ const customPaths = parseCustomGeometry(
8187
+ getChild(spPr, "custGeom"),
8188
+ orderedChildChildren2(orderedSpPr, "custGeom")
8189
+ );
8190
+ if (customPaths !== void 0) return { kind: "custom", paths: customPaths };
8191
+ return void 0;
8192
+ }
8193
+ function parseAdjustValues(avLst) {
8194
+ const adjustValues = {};
8195
+ for (const guide of getChildArray(avLst, "gd")) {
8196
+ const name = getAttr(guide, "name");
8197
+ const formula = getAttr(guide, "fmla");
8198
+ const match = formula?.match(/val\s+(-?\d+)/);
8199
+ if (name !== void 0 && match !== void 0 && match !== null) {
8200
+ adjustValues[name] = Number(match[1]);
8201
+ }
8202
+ }
8203
+ return adjustValues;
8204
+ }
8205
+ function parseChildTransform(grpSpPr, fallback) {
8206
+ const xfrm = getChild(grpSpPr, "xfrm");
8207
+ const childOff = getChild(xfrm, "chOff");
8208
+ const childExt = getChild(xfrm, "chExt");
8209
+ const offsetX = numericAttr2(childOff, "x") ?? 0;
8210
+ const offsetY = numericAttr2(childOff, "y") ?? 0;
8211
+ const width = numericAttr2(childExt, "cx") ?? fallback?.width;
8212
+ const height = numericAttr2(childExt, "cy") ?? fallback?.height;
8213
+ if (width === void 0 || height === void 0) return void 0;
8238
8214
  return {
8239
8215
  offsetX: asEmu2(offsetX),
8240
8216
  offsetY: asEmu2(offsetY),
8241
- width: asEmu2(width),
8242
- height: asEmu2(height),
8243
- ...rotation !== void 0 ? { rotation: asOoxmlAngle(rotation) } : {},
8244
- ...isTrue(flipH) ? { flipHorizontal: true } : {},
8245
- ...isTrue(flipV) ? { flipVertical: true } : {}
8217
+ width: asEmu2(Number(width)),
8218
+ height: asEmu2(Number(height))
8246
8219
  };
8247
8220
  }
8248
- function withTransforms(base, colorNode) {
8249
- const transforms = [];
8250
- for (const key of Object.keys(colorNode)) {
8251
- if (key.startsWith("@_")) continue;
8252
- const kind = localName(key);
8253
- const transformKind = parseEnumValue(kind, COLOR_TRANSFORM_KINDS);
8254
- if (transformKind === void 0) continue;
8255
- const value = colorNode[key];
8256
- const items = Array.isArray(value) ? value : [value];
8257
- for (const item of items) {
8258
- const raw = getAttr(unsafeOoxmlBoundaryAssertion(item), "val");
8259
- if (raw === void 0) continue;
8260
- const numeric = Number(raw);
8261
- if (!Number.isFinite(numeric)) continue;
8262
- transforms.push({
8263
- kind: transformKind,
8264
- value: asOoxmlPercent(numeric)
8265
- });
8266
- }
8267
- }
8268
- return transforms.length > 0 ? { ...base, transforms } : base;
8221
+ function parseCrop(srcRect) {
8222
+ if (!srcRect) return void 0;
8223
+ const left = numericAttr2(srcRect, "l");
8224
+ const top = numericAttr2(srcRect, "t");
8225
+ const right = numericAttr2(srcRect, "r");
8226
+ const bottom = numericAttr2(srcRect, "b");
8227
+ const crop = {
8228
+ ...left !== void 0 ? { left: asOoxmlPercent(left) } : {},
8229
+ ...top !== void 0 ? { top: asOoxmlPercent(top) } : {},
8230
+ ...right !== void 0 ? { right: asOoxmlPercent(right) } : {},
8231
+ ...bottom !== void 0 ? { bottom: asOoxmlPercent(bottom) } : {}
8232
+ };
8233
+ return Object.keys(crop).length > 0 ? crop : void 0;
8269
8234
  }
8270
- function numericAttr2(node, name) {
8271
- const raw = getAttr(node, name);
8272
- if (raw === void 0) return void 0;
8273
- const value = Number(raw);
8274
- return Number.isFinite(value) ? value : void 0;
8235
+ function parseStretch(stretch) {
8236
+ const fillRect = getChild(stretch, "fillRect");
8237
+ if (fillRect === void 0) return void 0;
8238
+ const left = (numericAttr2(fillRect, "l") ?? 0) / 1e5;
8239
+ const top = (numericAttr2(fillRect, "t") ?? 0) / 1e5;
8240
+ const right = (numericAttr2(fillRect, "r") ?? 0) / 1e5;
8241
+ const bottom = (numericAttr2(fillRect, "b") ?? 0) / 1e5;
8242
+ if (left === 0 && top === 0 && right === 0 && bottom === 0) return void 0;
8243
+ return { left, top, right, bottom };
8275
8244
  }
8276
- function isTrue(value) {
8277
- return value === "1" || value === "true";
8245
+ function sourceNodeId(cNvPr) {
8246
+ const id = getAttr(cNvPr, "id");
8247
+ return id !== void 0 ? asSourceNodeId(id) : void 0;
8278
8248
  }
8279
- function parseDashStyle(prstDash) {
8280
- const value = getAttr(prstDash, "val");
8281
- return parseEnumValue(value, DASH_STYLES);
8249
+ function emuAttr(node, attrName) {
8250
+ return asEmu2(numericAttr2(node, attrName) ?? 0);
8282
8251
  }
8283
- function parseCustomDash(ln) {
8284
- const custDash = getChild(ln, "custDash");
8285
- const segments = getChildArray(custDash, "ds");
8286
- if (segments.length === 0) return void 0;
8287
- return segments.flatMap((segment) => [
8288
- (numericAttr2(segment, "d") ?? 1e5) / 1e5,
8289
- (numericAttr2(segment, "sp") ?? 1e5) / 1e5
8290
- ]);
8252
+ var EMPTY_KNOWN = /* @__PURE__ */ new Set();
8253
+ function orderedChildChildren2(parent, childLocalName) {
8254
+ const child = parent?.find((entry) => {
8255
+ const key2 = Object.keys(entry).find((candidate) => candidate !== ":@");
8256
+ return key2 !== void 0 && localName(key2) === childLocalName;
8257
+ });
8258
+ if (child === void 0) return void 0;
8259
+ const key = Object.keys(child).find((candidate) => candidate !== ":@");
8260
+ const value = key !== void 0 ? child[key] : void 0;
8261
+ return Array.isArray(value) ? value : void 0;
8291
8262
  }
8292
- var LINE_CAP_MAP = {
8293
- flat: "butt",
8294
- sq: "square",
8295
- rnd: "round"
8263
+ function orderedChildChildrenList(parent, childLocalName) {
8264
+ if (parent === void 0) return [];
8265
+ return parent.filter((entry) => {
8266
+ const key = Object.keys(entry).find((candidate) => candidate !== ":@");
8267
+ return key !== void 0 && localName(key) === childLocalName;
8268
+ }).map((entry) => {
8269
+ const key = Object.keys(entry).find((candidate) => candidate !== ":@");
8270
+ const value = key !== void 0 ? entry[key] : void 0;
8271
+ return Array.isArray(value) ? value : void 0;
8272
+ });
8273
+ }
8274
+ function orderedNestedChildChildren(node, parentLocalName, childLocalName) {
8275
+ if (node === void 0) return void 0;
8276
+ const parentChildren = node[parentLocalName];
8277
+ return orderedChildChildren2(
8278
+ Array.isArray(parentChildren) ? parentChildren : void 0,
8279
+ childLocalName
8280
+ );
8281
+ }
8282
+ var xmlBuilder = new import_fast_xml_parser2.XMLBuilder({
8283
+ ignoreAttributes: false,
8284
+ attributeNamePrefix: "@_",
8285
+ format: false,
8286
+ suppressEmptyNode: true
8287
+ });
8288
+ var EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS = {
8289
+ bold: (value) => requireBooleanOrUndefined(value, "bold"),
8290
+ italic: (value) => requireBooleanOrUndefined(value, "italic"),
8291
+ underline: (value) => requireBooleanOrUndefined(value, "underline"),
8292
+ fontSize: (value) => {
8293
+ if (value !== void 0 && (!Number.isFinite(value) || value <= 0)) {
8294
+ throw new Error("updateTextRunProperties: fontSize must be a finite positive pt value");
8295
+ }
8296
+ },
8297
+ color: (value) => {
8298
+ if (value === void 0) return;
8299
+ if (value.kind !== "srgb") {
8300
+ throw new Error("updateTextRunProperties: only srgb text run color is supported");
8301
+ }
8302
+ if (!/^[0-9A-Fa-f]{6}$/.test(value.hex)) {
8303
+ throw new Error("updateTextRunProperties: srgb text run color must be a 6-digit hex value");
8304
+ }
8305
+ },
8306
+ typeface: (value) => {
8307
+ if (value !== void 0 && value.trim() === "") {
8308
+ throw new Error("updateTextRunProperties: typeface must be a non-empty string");
8309
+ }
8310
+ }
8296
8311
  };
8297
- function parseLineCap(value) {
8298
- return value !== void 0 ? LINE_CAP_MAP[value] : void 0;
8312
+ var EDITABLE_TEXT_RUN_PROPERTIES = Object.keys(EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS).filter(
8313
+ (property) => property in EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS
8314
+ );
8315
+ var EDITABLE_TEXT_RUN_PROPERTY_SET = new Set(EDITABLE_TEXT_RUN_PROPERTIES);
8316
+ var EDITABLE_PARAGRAPH_PROPERTIES = [
8317
+ "align",
8318
+ "level",
8319
+ "bullet"
8320
+ ];
8321
+ var EDITABLE_PARAGRAPH_PROPERTY_SET = new Set(EDITABLE_PARAGRAPH_PROPERTIES);
8322
+ function requireBooleanOrUndefined(value, fieldName) {
8323
+ if (value !== void 0 && typeof value !== "boolean") {
8324
+ throw new Error(`updateTextRunProperties: ${fieldName} must be a boolean value`);
8325
+ }
8299
8326
  }
8300
- function parseLineJoin(ln) {
8301
- if (hasChild(ln, "round")) return "round";
8302
- if (hasChild(ln, "bevel")) return "bevel";
8303
- if (hasChild(ln, "miter")) return "miter";
8304
- return void 0;
8327
+ function asEmu2(value) {
8328
+ return unsafeBrandAssertion2(value);
8305
8329
  }
8306
- function parseArrowEndpoint(node) {
8307
- if (!node) return void 0;
8308
- const type = parseEnumValue(getAttr(node, "type"), ARROW_TYPES2);
8309
- if (type === void 0) return void 0;
8310
- const width = getAttr(node, "w") ?? "med";
8311
- const length = getAttr(node, "len") ?? "med";
8312
- return {
8313
- type,
8314
- width: parseEnumValueWithDefault(width, ARROW_SIZES2, "med"),
8315
- length: parseEnumValueWithDefault(length, ARROW_SIZES2, "med")
8316
- };
8330
+ function asPt(value) {
8331
+ return unsafeBrandAssertion2(value);
8317
8332
  }
8318
- var DASH_STYLES = /* @__PURE__ */ new Set([
8319
- "solid",
8320
- "dash",
8321
- "dot",
8322
- "dashDot",
8323
- "lgDash",
8324
- "lgDashDot",
8325
- "sysDash",
8326
- "sysDot"
8327
- ]);
8328
- var ARROW_TYPES2 = /* @__PURE__ */ new Set([
8329
- "triangle",
8330
- "stealth",
8331
- "diamond",
8332
- "oval",
8333
- "arrow"
8334
- ]);
8335
- var ARROW_SIZES2 = /* @__PURE__ */ new Set(["sm", "med", "lg"]);
8333
+ function asHundredthPt2(value) {
8334
+ return unsafeBrandAssertion2(value);
8335
+ }
8336
+ function asOoxmlPercent(value) {
8337
+ return unsafeBrandAssertion2(value);
8338
+ }
8339
+ function asOoxmlAngle(value) {
8340
+ return unsafeBrandAssertion2(value);
8341
+ }
8342
+ var textEncoder = new TextEncoder();
8343
+ var ROOT_PART = asPartPath("");
8344
+ var PRESENTATION_PART = asPartPath("ppt/presentation.xml");
8345
+ var SLIDE_PART = asPartPath("ppt/slides/slide1.xml");
8346
+ var SLIDE_LAYOUT_PART = asPartPath("ppt/slideLayouts/slideLayout1.xml");
8347
+ var SLIDE_MASTER_PART = asPartPath("ppt/slideMasters/slideMaster1.xml");
8348
+ var THEME_PART = asPartPath("ppt/theme/theme1.xml");
8349
+ var APP_PROPS_PART = asPartPath("docProps/app.xml");
8350
+ var CORE_PROPS_PART = asPartPath("docProps/core.xml");
8336
8351
  var DEFAULT_COLOR_MAP = {
8337
8352
  bg1: "lt1",
8338
8353
  tx1: "dk1",
@@ -8896,7 +8911,7 @@ function computeConnectorElement(context, connector, layer, partPath) {
8896
8911
  sourceNode: connector,
8897
8912
  ...connector.transform !== void 0 ? { transform: connector.transform } : {},
8898
8913
  ...connector.geometry !== void 0 ? { geometry: connector.geometry } : {},
8899
- ...connector.outline !== void 0 ? { outline: computeOutline(context, connector.outline, partPath) } : connector.style?.lineRef !== void 0 ? { outline: resolveLineReference(context, connector.style.lineRef, partPath) } : {},
8914
+ ...computedOutlineProperty(context, connector.outline, connector.style?.lineRef, partPath),
8900
8915
  ...effects !== void 0 ? { effects } : {}
8901
8916
  };
8902
8917
  }
@@ -8940,7 +8955,7 @@ function computeShapeElement(context, shape, layer, partPath) {
8940
8955
  ...transform !== void 0 ? { transform } : {},
8941
8956
  ...geometry !== void 0 ? { geometry } : {},
8942
8957
  ...shape.fill !== void 0 ? { fill: computeFill(context, shape.fill, partPath) } : shape.style?.fillRef !== void 0 ? { fill: resolveFillReference(context, shape.style.fillRef, partPath) } : {},
8943
- ...shape.outline !== void 0 ? { outline: computeOutline(context, shape.outline, partPath) } : shape.style?.lineRef !== void 0 ? { outline: resolveLineReference(context, shape.style.lineRef, partPath) } : {},
8958
+ ...computedOutlineProperty(context, shape.outline, shape.style?.lineRef, partPath),
8944
8959
  ...effects !== void 0 ? { effects } : {},
8945
8960
  ...shape.textBody !== void 0 ? {
8946
8961
  textBody: computeTextBody(
@@ -8955,7 +8970,7 @@ function computeShapeElement(context, shape, layer, partPath) {
8955
8970
  }
8956
8971
  function computeImageElement(context, image, layer, partPath) {
8957
8972
  const relationship = resolveComputedRelationships(context.source, partPath).find(
8958
- (rel) => rel.id === image.blipRelationshipId && rel.type === IMAGE_REL_TYPE2
8973
+ (rel2) => rel2.id === image.blipRelationshipId && rel2.type === IMAGE_REL_TYPE2
8959
8974
  );
8960
8975
  const effects = image.effects !== void 0 ? computeEffectList(context, image.effects) : void 0;
8961
8976
  const blipEffects = image.blipEffects !== void 0 ? computeBlipEffects(context, image.blipEffects) : void 0;
@@ -8986,7 +9001,7 @@ function computeTableElement(context, table, layer, partPath) {
8986
9001
  }
8987
9002
  function computeChartElement(context, chart, layer, partPath) {
8988
9003
  const relationship = context.relationships.find(
8989
- (rel) => rel.id === chart.chartRelationshipId && CHART_REL_TYPES.has(rel.type)
9004
+ (rel2) => rel2.id === chart.chartRelationshipId && CHART_REL_TYPES.has(rel2.type)
8990
9005
  );
8991
9006
  const chartXml = relationship?.targetPartPath !== void 0 ? readRawPackageText(context.source, relationship.targetPartPath) : void 0;
8992
9007
  const chartData = chartXml !== void 0 ? parseComputedChartData(chartXml, context) : void 0;
@@ -9003,11 +9018,11 @@ function computeChartElement(context, chart, layer, partPath) {
9003
9018
  }
9004
9019
  function computeSmartArtElement(context, smartArt, layer, partPath) {
9005
9020
  const dataRelationship = context.relationships.find(
9006
- (rel) => rel.id === smartArt.dataRelationshipId && DIAGRAM_DATA_REL_TYPES.has(rel.type)
9021
+ (rel2) => rel2.id === smartArt.dataRelationshipId && DIAGRAM_DATA_REL_TYPES.has(rel2.type)
9007
9022
  );
9008
9023
  const dataRelationships = dataRelationship?.targetPartPath !== void 0 ? resolveComputedRelationships(context.source, dataRelationship.targetPartPath) : [];
9009
9024
  const drawingRelationship = dataRelationships.find(
9010
- (rel) => DIAGRAM_DRAWING_REL_TYPES.has(rel.type)
9025
+ (rel2) => DIAGRAM_DRAWING_REL_TYPES.has(rel2.type)
9011
9026
  );
9012
9027
  const drawingPartPath = drawingRelationship?.targetPartPath;
9013
9028
  const drawingXml = drawingPartPath !== void 0 ? readRawPackageText(context.source, drawingPartPath) : void 0;
@@ -9153,7 +9168,7 @@ function computeFill(context, fill, partPath) {
9153
9168
  };
9154
9169
  case "image": {
9155
9170
  const relationship = resolveComputedRelationships(context.source, partPath).find(
9156
- (rel) => rel.id === fill.blipRelationshipId && rel.type === IMAGE_REL_TYPE2
9171
+ (rel2) => rel2.id === fill.blipRelationshipId && rel2.type === IMAGE_REL_TYPE2
9157
9172
  );
9158
9173
  return {
9159
9174
  kind: "image",
@@ -9178,6 +9193,24 @@ function computeOutline(context, outline, partPath) {
9178
9193
  ...outline.fill !== void 0 ? { fill: computeFill(context, outline.fill, partPath) } : {}
9179
9194
  };
9180
9195
  }
9196
+ function computedOutlineProperty(context, outline, lineRef, partPath) {
9197
+ const styleOutline = lineRef !== void 0 ? resolveLineReference(context, lineRef, partPath) : void 0;
9198
+ if (outline === void 0) {
9199
+ return styleOutline !== void 0 ? { outline: styleOutline } : {};
9200
+ }
9201
+ const computed = mergeComputedOutline(styleOutline, computeOutline(context, outline, partPath));
9202
+ return { outline: computed };
9203
+ }
9204
+ function mergeComputedOutline(base, override) {
9205
+ if (base === void 0) return override;
9206
+ const width = override.width ?? base.width;
9207
+ const fill = override.fill ?? base.fill;
9208
+ return {
9209
+ source: { ...base.source, ...override.source },
9210
+ ...width !== void 0 ? { width } : {},
9211
+ ...fill !== void 0 ? { fill } : {}
9212
+ };
9213
+ }
9181
9214
  function resolveFillReference(context, ref, partPath) {
9182
9215
  if (ref.index === 0) return void 0;
9183
9216
  const list = ref.index >= 1e3 ? context.theme?.formatScheme?.backgroundFillStyles : context.theme?.formatScheme?.fillStyles;
@@ -9766,7 +9799,7 @@ var SLIDE_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/rel
9766
9799
  var SLIDE_LAYOUT_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout";
9767
9800
  var SLIDE_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster";
9768
9801
  var THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
9769
- var PRESENTATION_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
9802
+ var PRESENTATION_CONTENT_TYPE2 = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
9770
9803
  var textDecoder3 = new TextDecoder();
9771
9804
  function readPptx(input) {
9772
9805
  const entries = unzipPackage(input);
@@ -9933,15 +9966,15 @@ function parsePartRoot(entries, partPath, rootLocalName, diagnostics, includeOrd
9933
9966
  return { root, orderedRoot };
9934
9967
  }
9935
9968
  function resolveSingleRel(relationships, sourcePart, relType) {
9936
- const rels = relationships.find((rel) => rel.sourcePartPath === sourcePart)?.relationships;
9937
- const match = rels?.find((rel) => rel.type === relType && rel.targetMode !== "External");
9969
+ const rels = relationships.find((rel2) => rel2.sourcePartPath === sourcePart)?.relationships;
9970
+ const match = rels?.find((rel2) => rel2.type === relType && rel2.targetMode !== "External");
9938
9971
  if (match === void 0) return void 0;
9939
9972
  return resolveInternalRelationshipTarget(sourcePart, match);
9940
9973
  }
9941
9974
  function resolveAllRels(relationships, sourcePart, relType) {
9942
- const rels = relationships.find((rel) => rel.sourcePartPath === sourcePart)?.relationships ?? [];
9943
- return rels.filter((rel) => rel.type === relType && rel.targetMode !== "External").flatMap((rel) => {
9944
- const target = resolveInternalRelationshipTarget(sourcePart, rel);
9975
+ const rels = relationships.find((rel2) => rel2.sourcePartPath === sourcePart)?.relationships ?? [];
9976
+ return rels.filter((rel2) => rel2.type === relType && rel2.targetMode !== "External").flatMap((rel2) => {
9977
+ const target = resolveInternalRelationshipTarget(sourcePart, rel2);
9945
9978
  return target === void 0 ? [] : [target];
9946
9979
  });
9947
9980
  }
@@ -10030,7 +10063,7 @@ function readPresentation(entries, relationships, overrides, diagnostics) {
10030
10063
  const slideSize = readSlideSize(root);
10031
10064
  const defaultTextStyle = parseTextStyle(getChild(root, "defaultTextStyle"));
10032
10065
  const presentationRels = relationships.find(
10033
- (rel) => rel.sourcePartPath === presentationPath
10066
+ (rel2) => rel2.sourcePartPath === presentationPath
10034
10067
  )?.relationships;
10035
10068
  const slidePartPaths = [];
10036
10069
  const sldIdLst = getChild(root, "sldIdLst");
@@ -10038,7 +10071,7 @@ function readPresentation(entries, relationships, overrides, diagnostics) {
10038
10071
  const relId = getNamespacedAttr(sldId, "id");
10039
10072
  if (relId === void 0) continue;
10040
10073
  const handle = { partPath: presentationPartPath, relationshipId: asRelationshipId(relId) };
10041
- const relationship = presentationRels?.find((rel) => rel.id === relId);
10074
+ const relationship = presentationRels?.find((rel2) => rel2.id === relId);
10042
10075
  if (relationship === void 0) {
10043
10076
  diagnostics.push({
10044
10077
  severity: "warning",
@@ -10081,15 +10114,15 @@ function readSlideSize(presentationRoot) {
10081
10114
  }
10082
10115
  function locatePresentationPart(relationships, overrides) {
10083
10116
  const rootRels = relationships.find(
10084
- (rel) => rel.sourcePartPath === PACKAGE_ROOT_PART
10117
+ (rel2) => rel2.sourcePartPath === PACKAGE_ROOT_PART
10085
10118
  )?.relationships;
10086
10119
  const officeDocumentRel = rootRels?.find(
10087
- (rel) => rel.type === OFFICE_DOCUMENT_REL_TYPE && rel.targetMode !== "External"
10120
+ (rel2) => rel2.type === OFFICE_DOCUMENT_REL_TYPE && rel2.targetMode !== "External"
10088
10121
  );
10089
10122
  if (officeDocumentRel !== void 0) {
10090
10123
  return resolveRelationshipTarget(PACKAGE_ROOT_PART, officeDocumentRel.target);
10091
10124
  }
10092
- const override = overrides.find((entry) => entry.contentType === PRESENTATION_CONTENT_TYPE);
10125
+ const override = overrides.find((entry) => entry.contentType === PRESENTATION_CONTENT_TYPE2);
10093
10126
  return override?.partName;
10094
10127
  }
10095
10128
  var MEDIA_CONTENT_TYPE_PREFIXES = ["image/", "audio/", "video/"];
@@ -10117,7 +10150,7 @@ function extensionOf(path) {
10117
10150
  function stripLeadingSlash(path) {
10118
10151
  return path.startsWith("/") ? path.slice(1) : path;
10119
10152
  }
10120
- var textEncoder = new TextEncoder();
10153
+ var textEncoder2 = new TextEncoder();
10121
10154
  var textDecoder4 = new TextDecoder();
10122
10155
  var xmlBuilder2 = new import_fast_xml_parser3.XMLBuilder({
10123
10156
  ignoreAttributes: false,