@lofcz/pptxtojson 2.2.0 → 2.2.1

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.js CHANGED
@@ -2718,6 +2718,7 @@ function getInlineMathRuns(pNode) {
2718
2718
  if (latex) runs.push({
2719
2719
  type: 'math',
2720
2720
  latex,
2721
+ node,
2721
2722
  attrs: {
2722
2723
  order
2723
2724
  }
@@ -2736,6 +2737,33 @@ function getInlineMathRuns(pNode) {
2736
2737
  ])for (const node of toArray(pNode[key]))push(node, node && node.attrs && node.attrs.order || 0);
2737
2738
  return runs;
2738
2739
  }
2740
+ const findMathRunPr = (node, skipCtrlPr)=>{
2741
+ if (!node || 'object' != typeof node) return null;
2742
+ if (node['a:rPr']) {
2743
+ const rPr = node['a:rPr'];
2744
+ return Array.isArray(rPr) ? rPr[0] : rPr;
2745
+ }
2746
+ for (const [key, value] of Object.entries(node))if ('attrs' !== key && (!skipCtrlPr || 'm:ctrlPr' !== key)) for (const child of toArray(value)){
2747
+ const found = findMathRunPr(child, skipCtrlPr);
2748
+ if (found) return found;
2749
+ }
2750
+ return null;
2751
+ };
2752
+ function getMathRunStyleNode(mathRun) {
2753
+ const mathNode = mathRun && mathRun.node;
2754
+ const rPr = findMathRunPr(mathNode, true) || findMathRunPr(mathNode, false);
2755
+ return rPr ? {
2756
+ 'a:rPr': rPr
2757
+ } : {};
2758
+ }
2759
+ function mathRunHasOwnSize(styleNode) {
2760
+ const rPr = styleNode && styleNode['a:rPr'];
2761
+ return !!(rPr && rPr.attrs && rPr.attrs.sz);
2762
+ }
2763
+ function mathRunHasOwnColor(styleNode) {
2764
+ const rPr = styleNode && styleNode['a:rPr'];
2765
+ return !!(rPr && (rPr['a:solidFill'] || rPr['a:gradFill'] || rPr['a:pattFill']));
2766
+ }
2739
2767
  function latexFormart(latex) {
2740
2768
  return latex.replaceAll(/&lt;/g, '<').replaceAll(/&gt;/g, '>').replaceAll(/&amp;/g, '&').replaceAll(/&apos;/g, "'").replaceAll(/&quot;/g, '"');
2741
2769
  }
@@ -3173,6 +3201,8 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
3173
3201
  if (rNode) {
3174
3202
  let prevStyleInfo = null;
3175
3203
  let accumulatedText = '';
3204
+ const firstTextRun = rNode.find((item)=>!item.type);
3205
+ let lastTextRun = null;
3176
3206
  for (const rNodeItem of rNode){
3177
3207
  if ('math' === rNodeItem.type) {
3178
3208
  if (accumulatedText && prevStyleInfo) {
@@ -3182,9 +3212,12 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
3182
3212
  accumulatedText = '';
3183
3213
  prevStyleInfo = null;
3184
3214
  const latex = escapeHtml(rNodeItem.latex);
3185
- text += `<span class="omml-math" data-latex="${latex}">${latex}</span>`;
3215
+ const siblingRun = lastTextRun || firstTextRun;
3216
+ const mathStyle = getMathRunStyleText(rNodeItem, siblingRun, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj);
3217
+ text += `<span class="omml-math" data-latex="${latex}"${mathStyle ? ` style="${mathStyle}"` : ''}>${latex}</span>`;
3186
3218
  continue;
3187
3219
  }
3220
+ if (!rNodeItem.type) lastTextRun = rNodeItem;
3188
3221
  const styleInfo = getSpanStyleInfo(rNodeItem, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj);
3189
3222
  if (!prevStyleInfo || prevStyleInfo.styleText !== styleInfo.styleText || prevStyleInfo.hasLink !== styleInfo.hasLink || styleInfo.hasLink) {
3190
3223
  if (accumulatedText) {
@@ -3216,6 +3249,24 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
3216
3249
  }
3217
3250
  return text;
3218
3251
  }
3252
+ function getMathRunStyleText(mathRun, siblingRun, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
3253
+ let lvl = 1;
3254
+ const lvlNode = getTextByPathList(pNode, [
3255
+ 'a:pPr',
3256
+ 'attrs',
3257
+ 'lvl'
3258
+ ]);
3259
+ if (void 0 !== lvlNode) lvl = parseInt(lvlNode) + 1;
3260
+ const styleNode = getMathRunStyleNode(mathRun);
3261
+ const sizeNode = mathRunHasOwnSize(styleNode) || !siblingRun ? styleNode : siblingRun;
3262
+ const colorNode = mathRunHasOwnColor(styleNode) || !siblingRun ? styleNode : siblingRun;
3263
+ const fontSize = getFontSize(sizeNode, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, defaultTextStyle);
3264
+ const fontColor = getFontColor(colorNode, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, pFontStyle, warpObj);
3265
+ let styleText = '';
3266
+ if (fontSize) styleText += `font-size: ${fontSize};`;
3267
+ if (fontColor && 'string' == typeof fontColor) styleText += `color: ${fontColor};`;
3268
+ return styleText;
3269
+ }
3219
3270
  function getListType(node) {
3220
3271
  const pPrNode = node['a:pPr'];
3221
3272
  if (!pPrNode) return '';