@lofcz/pptxtojson 2.2.0 → 2.2.2

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/index.cjs CHANGED
@@ -2750,6 +2750,7 @@ function getInlineMathRuns(pNode) {
2750
2750
  if (latex) runs.push({
2751
2751
  type: 'math',
2752
2752
  latex,
2753
+ node,
2753
2754
  attrs: {
2754
2755
  order
2755
2756
  }
@@ -2768,6 +2769,33 @@ function getInlineMathRuns(pNode) {
2768
2769
  ])for (const node of toArray(pNode[key]))push(node, node && node.attrs && node.attrs.order || 0);
2769
2770
  return runs;
2770
2771
  }
2772
+ const findMathRunPr = (node, skipCtrlPr)=>{
2773
+ if (!node || 'object' != typeof node) return null;
2774
+ if (node['a:rPr']) {
2775
+ const rPr = node['a:rPr'];
2776
+ return Array.isArray(rPr) ? rPr[0] : rPr;
2777
+ }
2778
+ for (const [key, value] of Object.entries(node))if ('attrs' !== key && (!skipCtrlPr || 'm:ctrlPr' !== key)) for (const child of toArray(value)){
2779
+ const found = findMathRunPr(child, skipCtrlPr);
2780
+ if (found) return found;
2781
+ }
2782
+ return null;
2783
+ };
2784
+ function getMathRunStyleNode(mathRun) {
2785
+ const mathNode = mathRun && mathRun.node;
2786
+ const rPr = findMathRunPr(mathNode, true) || findMathRunPr(mathNode, false);
2787
+ return rPr ? {
2788
+ 'a:rPr': rPr
2789
+ } : {};
2790
+ }
2791
+ function mathRunHasOwnSize(styleNode) {
2792
+ const rPr = styleNode && styleNode['a:rPr'];
2793
+ return !!(rPr && rPr.attrs && rPr.attrs.sz);
2794
+ }
2795
+ function mathRunHasOwnColor(styleNode) {
2796
+ const rPr = styleNode && styleNode['a:rPr'];
2797
+ return !!(rPr && (rPr['a:solidFill'] || rPr['a:gradFill'] || rPr['a:pattFill']));
2798
+ }
2771
2799
  function latexFormart(latex) {
2772
2800
  return latex.replaceAll(/&lt;/g, '<').replaceAll(/&gt;/g, '>').replaceAll(/&amp;/g, '&').replaceAll(/&apos;/g, "'").replaceAll(/&quot;/g, '"');
2773
2801
  }
@@ -3205,6 +3233,8 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
3205
3233
  if (rNode) {
3206
3234
  let prevStyleInfo = null;
3207
3235
  let accumulatedText = '';
3236
+ const firstTextRun = rNode.find((item)=>!item.type);
3237
+ let lastTextRun = null;
3208
3238
  for (const rNodeItem of rNode){
3209
3239
  if ('math' === rNodeItem.type) {
3210
3240
  if (accumulatedText && prevStyleInfo) {
@@ -3214,9 +3244,12 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
3214
3244
  accumulatedText = '';
3215
3245
  prevStyleInfo = null;
3216
3246
  const latex = escapeHtml(rNodeItem.latex);
3217
- text += `<span class="omml-math" data-latex="${latex}">${latex}</span>`;
3247
+ const siblingRun = lastTextRun || firstTextRun;
3248
+ const mathStyle = getMathRunStyleText(rNodeItem, siblingRun, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj);
3249
+ text += `<span class="omml-math" data-latex="${latex}"${mathStyle ? ` style="${mathStyle}"` : ''}>${latex}</span>`;
3218
3250
  continue;
3219
3251
  }
3252
+ if (!rNodeItem.type) lastTextRun = rNodeItem;
3220
3253
  const styleInfo = getSpanStyleInfo(rNodeItem, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj);
3221
3254
  if (!prevStyleInfo || prevStyleInfo.styleText !== styleInfo.styleText || prevStyleInfo.hasLink !== styleInfo.hasLink || styleInfo.hasLink) {
3222
3255
  if (accumulatedText) {
@@ -3248,6 +3281,24 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
3248
3281
  }
3249
3282
  return text;
3250
3283
  }
3284
+ function getMathRunStyleText(mathRun, siblingRun, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
3285
+ let lvl = 1;
3286
+ const lvlNode = getTextByPathList(pNode, [
3287
+ 'a:pPr',
3288
+ 'attrs',
3289
+ 'lvl'
3290
+ ]);
3291
+ if (void 0 !== lvlNode) lvl = parseInt(lvlNode) + 1;
3292
+ const styleNode = getMathRunStyleNode(mathRun);
3293
+ const sizeNode = mathRunHasOwnSize(styleNode) || !siblingRun ? styleNode : siblingRun;
3294
+ const colorNode = mathRunHasOwnColor(styleNode) || !siblingRun ? styleNode : siblingRun;
3295
+ const fontSize = getFontSize(sizeNode, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, defaultTextStyle);
3296
+ const fontColor = getFontColor(colorNode, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, pFontStyle, warpObj);
3297
+ let styleText = '';
3298
+ if (fontSize) styleText += `font-size: ${fontSize};`;
3299
+ if (fontColor && 'string' == typeof fontColor) styleText += `color: ${fontColor};`;
3300
+ return styleText;
3301
+ }
3251
3302
  function getListType(node) {
3252
3303
  const pPrNode = node['a:pPr'];
3253
3304
  if (!pPrNode) return '';