docgen-utils 1.0.23 → 1.0.24

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/bundle.js CHANGED
@@ -26853,6 +26853,7 @@ var docgen = (() => {
26853
26853
  exportPptx: () => exportPptx,
26854
26854
  importDocx: () => importDocx,
26855
26855
  importPptx: () => importPptx,
26856
+ parseSlideHtml: () => parseSlideHtml,
26856
26857
  transformHtmlForPptx: () => transformHtmlForPptx
26857
26858
  });
26858
26859
 
@@ -65552,6 +65553,31 @@ ${generateStylesCss(styleMap, themeFonts)}
65552
65553
  }
65553
65554
  return null;
65554
65555
  }
65556
+ function extractTranslation(computed) {
65557
+ const transform = computed.transform;
65558
+ if (!transform || transform === "none")
65559
+ return null;
65560
+ const matrix2dMatch = transform.match(/matrix\(([-\d.e]+),\s*([-\d.e]+),\s*([-\d.e]+),\s*([-\d.e]+),\s*([-\d.e]+),\s*([-\d.e]+)\)/);
65561
+ if (matrix2dMatch) {
65562
+ const tx = parseFloat(matrix2dMatch[5]);
65563
+ const ty = parseFloat(matrix2dMatch[6]);
65564
+ if (tx !== 0 || ty !== 0) {
65565
+ return { x: tx, y: ty };
65566
+ }
65567
+ }
65568
+ const matrix3dMatch = transform.match(/matrix3d\(([^)]+)\)/);
65569
+ if (matrix3dMatch) {
65570
+ const values = matrix3dMatch[1].split(",").map((v) => parseFloat(v.trim()));
65571
+ if (values.length >= 14) {
65572
+ const tx = values[12];
65573
+ const ty = values[13];
65574
+ if (tx !== 0 || ty !== 0) {
65575
+ return { x: tx, y: ty };
65576
+ }
65577
+ }
65578
+ }
65579
+ return null;
65580
+ }
65555
65581
  function getEffectiveOpacity(el, win) {
65556
65582
  let opacity = 1;
65557
65583
  let node = el;
@@ -66543,7 +66569,7 @@ ${generateStylesCss(styleMap, themeFonts)}
66543
66569
  pHeight = parentRect.height;
66544
66570
  }
66545
66571
  }
66546
- if (pWidth < 1 || pHeight < 1)
66572
+ if (pWidth < 0.5 || pHeight < 0.5)
66547
66573
  continue;
66548
66574
  let pLeft = parseFloat(pComputed.left);
66549
66575
  let pTop = parseFloat(pComputed.top);
@@ -66648,8 +66674,11 @@ ${generateStylesCss(styleMap, themeFonts)}
66648
66674
  borderOffsetLeft = parseFloat(parentComputedForBorder.borderLeftWidth) || 0;
66649
66675
  borderOffsetTop = parseFloat(parentComputedForBorder.borderTopWidth) || 0;
66650
66676
  }
66651
- const absLeft = parentRect.left + pLeft + borderOffsetLeft;
66652
- const absTop = parentRect.top + pTop + borderOffsetTop;
66677
+ const translation = extractTranslation(pComputed);
66678
+ const transformOffsetX = translation?.x ?? 0;
66679
+ const transformOffsetY = translation?.y ?? 0;
66680
+ const absLeft = parentRect.left + pLeft + borderOffsetLeft + transformOffsetX;
66681
+ const absTop = parentRect.top + pTop + borderOffsetTop + transformOffsetY;
66653
66682
  const hasBg = pComputed.backgroundColor && pComputed.backgroundColor !== "rgba(0, 0, 0, 0)";
66654
66683
  const bgImage = pComputed.backgroundImage;
66655
66684
  const hasGradient = bgImage && bgImage !== "none" && (bgImage.includes("linear-gradient") || bgImage.includes("radial-gradient"));
@@ -66854,7 +66883,18 @@ ${generateStylesCss(styleMap, themeFonts)}
66854
66883
  const transformStr = computed.textTransform;
66855
66884
  textTransform = (text) => applyTextTransform2(text, transformStr);
66856
66885
  }
66886
+ const runsBeforeRecurse = runs.length;
66887
+ const hadPendingSoftBreak = pendingSoftBreak;
66888
+ if (pendingSoftBreak) {
66889
+ pendingSoftBreak = false;
66890
+ }
66857
66891
  parseInlineFormatting(el, options, runs, textTransform, win);
66892
+ if (hadPendingSoftBreak && runs.length > runsBeforeRecurse) {
66893
+ runs[runsBeforeRecurse].options = {
66894
+ ...runs[runsBeforeRecurse].options,
66895
+ softBreakBefore: true
66896
+ };
66897
+ }
66858
66898
  }
66859
66899
  prevNodeIsText = false;
66860
66900
  }
@@ -67601,8 +67641,21 @@ ${generateStylesCss(styleMap, themeFonts)}
67601
67641
  const textTagSet = /* @__PURE__ */ new Set(["P", "H1", "H2", "H3", "H4", "H5", "H6", "SPAN"]);
67602
67642
  const allChildren = Array.from(el.children);
67603
67643
  const textChildren = allChildren.filter((child) => {
67604
- if (textTagSet.has(child.tagName))
67644
+ if (textTagSet.has(child.tagName)) {
67645
+ if (child.tagName === "SPAN") {
67646
+ const spanComputed = win.getComputedStyle(child);
67647
+ const spanHasBg = spanComputed.backgroundColor && spanComputed.backgroundColor !== "rgba(0, 0, 0, 0)";
67648
+ const spanHasBorder = (parseFloat(spanComputed.borderTopWidth) || 0) > 0 || (parseFloat(spanComputed.borderRightWidth) || 0) > 0 || (parseFloat(spanComputed.borderBottomWidth) || 0) > 0 || (parseFloat(spanComputed.borderLeftWidth) || 0) > 0;
67649
+ const spanHasGradient = spanComputed.backgroundImage && spanComputed.backgroundImage !== "none" && (spanComputed.backgroundImage.includes("linear-gradient") || spanComputed.backgroundImage.includes("radial-gradient"));
67650
+ const spanBgClip = spanComputed.webkitBackgroundClip || spanComputed.backgroundClip;
67651
+ const spanTextFillColor = spanComputed.webkitTextFillColor;
67652
+ const isGradientText = spanBgClip === "text" && (spanTextFillColor === "transparent" || spanTextFillColor === "rgba(0, 0, 0, 0)" || spanTextFillColor && spanTextFillColor.includes("rgba") && spanTextFillColor.endsWith(", 0)"));
67653
+ if ((spanHasBg || spanHasBorder || spanHasGradient) && !isGradientText) {
67654
+ return false;
67655
+ }
67656
+ }
67605
67657
  return true;
67658
+ }
67606
67659
  if (child.tagName === "DIV") {
67607
67660
  const childComputed = win.getComputedStyle(child);
67608
67661
  const childDisplay = childComputed.display;
@@ -67703,7 +67756,9 @@ ${generateStylesCss(styleMap, themeFonts)}
67703
67756
  }
67704
67757
  }
67705
67758
  const hasDirectText = directTextContent.length > 0;
67706
- const shouldMergeText = hasTextChildren && (isSingleTextChild || nonTextChildren.length === 0) || hasDirectText;
67759
+ const isParentFlexRow = isFlexContainer2 && (computed2.flexDirection === "row" || computed2.flexDirection === "row-reverse" || !computed2.flexDirection) && allChildren.length > 1;
67760
+ const isParentGrid = display === "grid" || display === "inline-grid";
67761
+ const shouldMergeText = !isParentFlexRow && !isParentGrid && (hasTextChildren && (isSingleTextChild || nonTextChildren.length === 0) || hasDirectText);
67707
67762
  if (shouldMergeText) {
67708
67763
  if (isSingleTextChild) {
67709
67764
  const textEl = textChildren[0];
@@ -68080,10 +68135,34 @@ ${generateStylesCss(styleMap, themeFonts)}
68080
68135
  const plainDivChildCount = el.children.length;
68081
68136
  const isPlainDivFlexRow = (plainDivDisplay === "flex" || plainDivDisplay === "inline-flex") && (plainDivFlexDir === "row" || plainDivFlexDir === "row-reverse") && plainDivChildCount > 1;
68082
68137
  const isPlainDivGrid = plainDivDisplay === "grid" || plainDivDisplay === "inline-grid";
68083
- const allChildrenAreInlineText = !isPlainDivFlexRow && !isPlainDivGrid && (childElements.length === 0 || childElements.every((ce) => inlineTextTagsSet.has(ce.tagName.toUpperCase())));
68138
+ const isInlineTextChild = (ce) => {
68139
+ const tagName19 = ce.tagName.toUpperCase();
68140
+ if (!inlineTextTagsSet.has(tagName19))
68141
+ return false;
68142
+ if (tagName19 === "SPAN" || tagName19 === "A") {
68143
+ const ceComputed = win.getComputedStyle(ce);
68144
+ const ceHasBg = ceComputed.backgroundColor && ceComputed.backgroundColor !== "rgba(0, 0, 0, 0)";
68145
+ const ceHasBorder = (parseFloat(ceComputed.borderTopWidth) || 0) > 0 || (parseFloat(ceComputed.borderRightWidth) || 0) > 0 || (parseFloat(ceComputed.borderBottomWidth) || 0) > 0 || (parseFloat(ceComputed.borderLeftWidth) || 0) > 0;
68146
+ const ceHasGradient = ceComputed.backgroundImage && ceComputed.backgroundImage !== "none" && (ceComputed.backgroundImage.includes("linear-gradient") || ceComputed.backgroundImage.includes("radial-gradient"));
68147
+ const ceBgClip = ceComputed.webkitBackgroundClip || ceComputed.backgroundClip;
68148
+ const ceTextFillColor = ceComputed.webkitTextFillColor;
68149
+ const isGradientText = ceBgClip === "text" && (ceTextFillColor === "transparent" || ceTextFillColor === "rgba(0, 0, 0, 0)" || ceTextFillColor && ceTextFillColor.includes("rgba") && ceTextFillColor.endsWith(", 0)"));
68150
+ if ((ceHasBg || ceHasBorder || ceHasGradient) && !isGradientText) {
68151
+ return false;
68152
+ }
68153
+ }
68154
+ return true;
68155
+ };
68156
+ const allChildrenAreInlineText = !isPlainDivFlexRow && !isPlainDivGrid && (childElements.length === 0 || childElements.every((ce) => isInlineTextChild(ce)));
68084
68157
  const structuralChildElements = childElements.filter((ce) => {
68085
68158
  const tagName19 = ce.tagName.toUpperCase();
68086
- return tagName19 !== "BR" && tagName19 !== "SVG" && !inlineTextTagsSet.has(tagName19);
68159
+ if (tagName19 === "BR" || tagName19 === "SVG")
68160
+ return false;
68161
+ if (!inlineTextTagsSet.has(tagName19))
68162
+ return true;
68163
+ if (!isInlineTextChild(ce))
68164
+ return true;
68165
+ return false;
68087
68166
  });
68088
68167
  const hasStructuralChildren = structuralChildElements.length > 0;
68089
68168
  let extractedText = "";
@@ -68120,6 +68199,7 @@ ${generateStylesCss(styleMap, themeFonts)}
68120
68199
  const textTop = rect2.top;
68121
68200
  const textHeight = rect2.height;
68122
68201
  let textRuns;
68202
+ const isFlexColumn = (plainDivDisplay === "flex" || plainDivDisplay === "inline-flex") && (plainDivFlexDir === "column" || plainDivFlexDir === "column-reverse") && childElements.length > 1;
68123
68203
  if (allChildrenAreInlineText && childElements.length > 0) {
68124
68204
  const baseRunOptions = {
68125
68205
  fontSize: pxToPoints(computed22.fontSize),
@@ -68134,7 +68214,44 @@ ${generateStylesCss(styleMap, themeFonts)}
68134
68214
  if (computed22.textTransform && computed22.textTransform !== "none") {
68135
68215
  textTransformFn = (text2) => applyTextTransform2(text2, computed22.textTransform);
68136
68216
  }
68137
- textRuns = parseInlineFormatting(el, baseRunOptions, [], textTransformFn, win);
68217
+ if (isFlexColumn) {
68218
+ textRuns = [];
68219
+ for (let ci = 0; ci < childElements.length; ci++) {
68220
+ const childEl = childElements[ci];
68221
+ const childComputed = win.getComputedStyle(childEl);
68222
+ const childText = getTransformedText(childEl, childComputed);
68223
+ if (!childText)
68224
+ continue;
68225
+ const transformedChildText = textTransformFn(childText);
68226
+ const childRunOptions = { ...baseRunOptions };
68227
+ const childFontSize = pxToPoints(childComputed.fontSize);
68228
+ if (childFontSize)
68229
+ childRunOptions.fontSize = childFontSize;
68230
+ const childFontFace = extractFontFace(childComputed.fontFamily);
68231
+ if (childFontFace)
68232
+ childRunOptions.fontFace = childFontFace;
68233
+ const childColor = rgbToHex(childComputed.color);
68234
+ if (childColor)
68235
+ childRunOptions.color = childColor;
68236
+ if (parseInt(childComputed.fontWeight) >= 600) {
68237
+ childRunOptions.bold = true;
68238
+ } else if (parseInt(childComputed.fontWeight) < 600) {
68239
+ childRunOptions.bold = false;
68240
+ }
68241
+ if (childComputed.fontStyle === "italic") {
68242
+ childRunOptions.italic = true;
68243
+ } else if (childComputed.fontStyle !== "italic") {
68244
+ childRunOptions.italic = false;
68245
+ }
68246
+ const childLs = extractLetterSpacing(childComputed);
68247
+ if (childLs !== null)
68248
+ childRunOptions.charSpacing = childLs;
68249
+ const textWithBreak = ci < childElements.length - 1 ? transformedChildText + "\n" : transformedChildText;
68250
+ textRuns.push({ text: textWithBreak, options: childRunOptions });
68251
+ }
68252
+ } else {
68253
+ textRuns = parseInlineFormatting(el, baseRunOptions, [], textTransformFn, win);
68254
+ }
68138
68255
  if (textRuns.length === 0) {
68139
68256
  textRuns = [{ text: extractedText, options: {} }];
68140
68257
  }
@@ -68473,9 +68590,9 @@ ${generateStylesCss(styleMap, themeFonts)}
68473
68590
  elements.push(...pseudoElements);
68474
68591
  });
68475
68592
  doc.querySelectorAll("div").forEach((divEl) => {
68593
+ const htmlDiv = divEl;
68476
68594
  if (processed.has(divEl))
68477
68595
  return;
68478
- const htmlDiv = divEl;
68479
68596
  if (htmlDiv === body)
68480
68597
  return;
68481
68598
  const rect = htmlDiv.getBoundingClientRect();