@lofcz/pptxtojson 2.2.4 → 2.2.6
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 +130 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +130 -36
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2700,10 +2700,25 @@ function findOMath(obj) {
|
|
|
2700
2700
|
});
|
|
2701
2701
|
return results;
|
|
2702
2702
|
}
|
|
2703
|
+
function localName(tag) {
|
|
2704
|
+
if (!tag) return '';
|
|
2705
|
+
const i = tag.indexOf(':');
|
|
2706
|
+
return i >= 0 ? tag.slice(i + 1) : tag;
|
|
2707
|
+
}
|
|
2708
|
+
function firstRawOMath(node) {
|
|
2709
|
+
if (!node || 'object' != typeof node) return null;
|
|
2710
|
+
if ('oMath' === localName(node.tagName)) return node;
|
|
2711
|
+
for (const child of node.children || [])if ('object' == typeof child) {
|
|
2712
|
+
const found = firstRawOMath(child);
|
|
2713
|
+
if (found) return found;
|
|
2714
|
+
}
|
|
2715
|
+
return null;
|
|
2716
|
+
}
|
|
2703
2717
|
function oMathToLatex(simplifiedNode) {
|
|
2704
2718
|
const rawNode = simplifiedNode && simplifiedNode.__rawNode;
|
|
2705
2719
|
if (!rawNode) return '';
|
|
2706
|
-
|
|
2720
|
+
const math = firstRawOMath(rawNode) || rawNode;
|
|
2721
|
+
return latexFormart(ommlNodeToLatex(math)).trim();
|
|
2707
2722
|
}
|
|
2708
2723
|
const toArray = (value)=>{
|
|
2709
2724
|
if (!value) return [];
|
|
@@ -2711,6 +2726,17 @@ const toArray = (value)=>{
|
|
|
2711
2726
|
value
|
|
2712
2727
|
];
|
|
2713
2728
|
};
|
|
2729
|
+
function mathPayloads(container) {
|
|
2730
|
+
const direct = toArray(container && container['m:oMath']);
|
|
2731
|
+
if (direct.length) return direct;
|
|
2732
|
+
const out = [];
|
|
2733
|
+
for (const para of toArray(container && container['m:oMathPara'])){
|
|
2734
|
+
const inner = toArray(para['m:oMath']);
|
|
2735
|
+
if (inner.length) out.push(...inner);
|
|
2736
|
+
else out.push(para);
|
|
2737
|
+
}
|
|
2738
|
+
return out;
|
|
2739
|
+
}
|
|
2714
2740
|
function getInlineMathRuns(pNode) {
|
|
2715
2741
|
const runs = [];
|
|
2716
2742
|
const push = (node, order)=>{
|
|
@@ -2726,15 +2752,9 @@ function getInlineMathRuns(pNode) {
|
|
|
2726
2752
|
};
|
|
2727
2753
|
for (const wrapper of toArray(pNode['a14:m'])){
|
|
2728
2754
|
const order = wrapper && wrapper.attrs && wrapper.attrs.order || 0;
|
|
2729
|
-
for (const
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
])for (const node of toArray(wrapper[key]))push(node, order);
|
|
2733
|
-
}
|
|
2734
|
-
for (const key of [
|
|
2735
|
-
'm:oMath',
|
|
2736
|
-
'm:oMathPara'
|
|
2737
|
-
])for (const node of toArray(pNode[key]))push(node, node && node.attrs && node.attrs.order || 0);
|
|
2755
|
+
for (const node of mathPayloads(wrapper))push(node, order);
|
|
2756
|
+
}
|
|
2757
|
+
for (const node of mathPayloads(pNode))push(node, node && node.attrs && node.attrs.order || 0);
|
|
2738
2758
|
return runs;
|
|
2739
2759
|
}
|
|
2740
2760
|
const findMathRunPr = (node, skipCtrlPr)=>{
|
|
@@ -3162,17 +3182,18 @@ function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode,
|
|
|
3162
3182
|
const align = getHorizontalAlign(pNode, spNode, type, slideLayoutSpNode, slideMasterSpNode, warpObj);
|
|
3163
3183
|
const spacing = getParagraphSpacing(pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj);
|
|
3164
3184
|
const indent = getParagraphIndent(pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj);
|
|
3165
|
-
const listType = getListType(pNode);
|
|
3185
|
+
const listType = getListType(pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj);
|
|
3166
3186
|
const listLevel = getListLevel(pNode);
|
|
3167
3187
|
let alignStyle = align;
|
|
3168
3188
|
if ('distribute' === align) alignStyle = 'justify';
|
|
3169
|
-
let styleText = `text-align: ${alignStyle}
|
|
3189
|
+
let styleText = `text-align: ${alignStyle};`;
|
|
3170
3190
|
if ('distribute' === align) styleText += "text-align-last: justify;text-justify: distribute;";
|
|
3171
3191
|
if (spacing) {
|
|
3172
3192
|
if (spacing.lineSpacing) styleText += `line-height: ${spacing.lineSpacing};`;
|
|
3193
|
+
else styleText += "line-height: 1.2;";
|
|
3173
3194
|
if (spacing.spaceBefore) styleText += `margin-top: ${spacing.spaceBefore};`;
|
|
3174
3195
|
if (spacing.spaceAfter) styleText += `margin-bottom: ${spacing.spaceAfter};`;
|
|
3175
|
-
}
|
|
3196
|
+
} else styleText += "line-height: 1.2;";
|
|
3176
3197
|
if (indent) {
|
|
3177
3198
|
if (!listType && indent.marginLeft) styleText += `margin-left: ${indent.marginLeft};`;
|
|
3178
3199
|
if (!listType && indent.textIndent) styleText += `text-indent: ${indent.textIndent};`;
|
|
@@ -3267,19 +3288,21 @@ function getMathRunStyleText(mathRun, siblingRun, pNode, textBodyNode, pFontStyl
|
|
|
3267
3288
|
if (fontColor && 'string' == typeof fontColor) styleText += `color: ${fontColor};`;
|
|
3268
3289
|
return styleText;
|
|
3269
3290
|
}
|
|
3270
|
-
function getListType(node) {
|
|
3271
|
-
const pPrNode = node['a:pPr'];
|
|
3272
|
-
if (!pPrNode) return '';
|
|
3273
|
-
if (pPrNode['a:buNone']) return '';
|
|
3291
|
+
function getListType(node, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj) {
|
|
3274
3292
|
const hasContent = node['a:r'] || node['a:br'] || node['a:fld'];
|
|
3275
3293
|
if (!hasContent) return '';
|
|
3276
|
-
|
|
3277
|
-
if (
|
|
3294
|
+
const styleNodes = getParagraphStyleNodes(node, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj);
|
|
3295
|
+
if (!styleNodes) return '';
|
|
3296
|
+
for (const styleNode of styleNodes){
|
|
3297
|
+
if (styleNode['a:buNone']) break;
|
|
3298
|
+
if (styleNode['a:buChar'] || styleNode['a:buBlip']) return 'ul';
|
|
3299
|
+
if (styleNode['a:buAutoNum']) return 'ol';
|
|
3300
|
+
}
|
|
3278
3301
|
return '';
|
|
3279
3302
|
}
|
|
3280
3303
|
function getListLevel(node) {
|
|
3281
3304
|
const pPrNode = node['a:pPr'];
|
|
3282
|
-
if (!pPrNode) return
|
|
3305
|
+
if (!pPrNode) return 0;
|
|
3283
3306
|
const lvlNode = getTextByPathList(pPrNode, [
|
|
3284
3307
|
'attrs',
|
|
3285
3308
|
'lvl'
|
|
@@ -3287,6 +3310,30 @@ function getListLevel(node) {
|
|
|
3287
3310
|
if (void 0 !== lvlNode) return parseInt(lvlNode);
|
|
3288
3311
|
return 0;
|
|
3289
3312
|
}
|
|
3313
|
+
function schemeColorToCss(color) {
|
|
3314
|
+
if (!color) return '';
|
|
3315
|
+
return color.startsWith('#') ? color : `#${color}`;
|
|
3316
|
+
}
|
|
3317
|
+
function applyHyperlinkRunStyle(styleText, node, warpObj) {
|
|
3318
|
+
let next = styleText;
|
|
3319
|
+
const runStyleNode = getTextByPathList(node, [
|
|
3320
|
+
'a:rPr'
|
|
3321
|
+
]);
|
|
3322
|
+
const runFill = runStyleNode ? getFillType(runStyleNode) : '';
|
|
3323
|
+
const runHasOwnColor = 'SOLID_FILL' === runFill || 'GRADIENT_FILL' === runFill;
|
|
3324
|
+
if (!runHasOwnColor) {
|
|
3325
|
+
const hlinkColor = schemeColorToCss(getSchemeColorFromTheme('a:hlink', warpObj)) || '#0563C1';
|
|
3326
|
+
if (/color\s*:/.test(next)) next = next.replace(/color\s*:\s*[^;]+;/, `color: ${hlinkColor};`);
|
|
3327
|
+
else next += `color: ${hlinkColor};`;
|
|
3328
|
+
}
|
|
3329
|
+
const runUnderline = getTextByPathList(node, [
|
|
3330
|
+
'a:rPr',
|
|
3331
|
+
'attrs',
|
|
3332
|
+
'u'
|
|
3333
|
+
]);
|
|
3334
|
+
if ('none' !== runUnderline && !/text-decoration\s*:\s*underline/.test(next)) next += 'text-decoration: underline;';
|
|
3335
|
+
return next;
|
|
3336
|
+
}
|
|
3290
3337
|
function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
|
|
3291
3338
|
const { styleText, text, hasLink, linkURL } = getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj);
|
|
3292
3339
|
const processedText = text.replace(/\t/g, ' ').replace(/\s/g, ' ');
|
|
@@ -3343,6 +3390,7 @@ function getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNo
|
|
|
3343
3390
|
'r:id'
|
|
3344
3391
|
]);
|
|
3345
3392
|
const hasLink = linkID && warpObj['slideResObj'][linkID];
|
|
3393
|
+
if (hasLink) styleText = applyHyperlinkRunStyle(styleText, node, warpObj);
|
|
3346
3394
|
return {
|
|
3347
3395
|
styleText,
|
|
3348
3396
|
text,
|
|
@@ -9797,21 +9845,62 @@ function sortSlideXml(p1, p2) {
|
|
|
9797
9845
|
const n2 = +(/(\d+)\.xml/.exec(p2)?.[1] || 0);
|
|
9798
9846
|
return n1 - n2;
|
|
9799
9847
|
}
|
|
9800
|
-
function
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9848
|
+
function normalizePartName(name) {
|
|
9849
|
+
return String(name || '').replace(/\\/g, '/').replace(/^\//, '');
|
|
9850
|
+
}
|
|
9851
|
+
function relationshipsPartFor(partName) {
|
|
9852
|
+
const name = normalizePartName(partName);
|
|
9853
|
+
const slash = name.lastIndexOf('/');
|
|
9854
|
+
const dir = -1 === slash ? '' : name.slice(0, slash + 1);
|
|
9855
|
+
const file = -1 === slash ? name : name.slice(slash + 1);
|
|
9856
|
+
return `${dir}_rels/${file}.rels`;
|
|
9857
|
+
}
|
|
9858
|
+
function resolvePartTarget(sourcePart, target) {
|
|
9859
|
+
const raw = String(target || '').replace(/\\/g, '/');
|
|
9860
|
+
if (!raw) return '';
|
|
9861
|
+
if (raw.startsWith('/')) return normalizePartName(raw);
|
|
9862
|
+
const source = normalizePartName(sourcePart);
|
|
9863
|
+
const slash = source.lastIndexOf('/');
|
|
9864
|
+
const dir = -1 === slash ? '' : source.slice(0, slash + 1);
|
|
9865
|
+
const out = [];
|
|
9866
|
+
for (const seg of `${dir}${raw}`.split('/'))if (seg && '.' !== seg) if ('..' === seg) out.pop();
|
|
9867
|
+
else out.push(seg);
|
|
9868
|
+
return out.join('/');
|
|
9807
9869
|
}
|
|
9808
9870
|
function relationshipRid(attrs) {
|
|
9809
9871
|
if (!attrs) return '';
|
|
9810
9872
|
return attrs['r:id'] || attrs.rId || '';
|
|
9811
9873
|
}
|
|
9874
|
+
async function getPresentationPart(zip) {
|
|
9875
|
+
const rels = asNodeArray(getTextByPathList(await readXmlFile(zip, '_rels/.rels'), [
|
|
9876
|
+
'Relationships',
|
|
9877
|
+
'Relationship'
|
|
9878
|
+
]));
|
|
9879
|
+
for (const rel of rels){
|
|
9880
|
+
const type = getTextByPathList(rel, [
|
|
9881
|
+
'attrs',
|
|
9882
|
+
'Type'
|
|
9883
|
+
]);
|
|
9884
|
+
const target = getTextByPathList(rel, [
|
|
9885
|
+
'attrs',
|
|
9886
|
+
'Target'
|
|
9887
|
+
]);
|
|
9888
|
+
const targetMode = getTextByPathList(rel, [
|
|
9889
|
+
'attrs',
|
|
9890
|
+
'TargetMode'
|
|
9891
|
+
]);
|
|
9892
|
+
if (!targetMode || 'external' !== String(targetMode).toLowerCase()) {
|
|
9893
|
+
if ('officeDocument' === getRelTypeName(type) && target) {
|
|
9894
|
+
const loc = resolvePartTarget('', target);
|
|
9895
|
+
if (loc) return loc;
|
|
9896
|
+
}
|
|
9897
|
+
}
|
|
9898
|
+
}
|
|
9899
|
+
return 'ppt/presentation.xml';
|
|
9900
|
+
}
|
|
9812
9901
|
async function getSlidesFromPresentation(zip) {
|
|
9813
|
-
const
|
|
9814
|
-
const relItems = asNodeArray(getTextByPathList(
|
|
9902
|
+
const presentationPart = await getPresentationPart(zip);
|
|
9903
|
+
const relItems = asNodeArray(getTextByPathList(await readXmlFile(zip, relationshipsPartFor(presentationPart)), [
|
|
9815
9904
|
'Relationships',
|
|
9816
9905
|
'Relationship'
|
|
9817
9906
|
]));
|
|
@@ -9830,14 +9919,19 @@ async function getSlidesFromPresentation(zip) {
|
|
|
9830
9919
|
'attrs',
|
|
9831
9920
|
'Target'
|
|
9832
9921
|
]);
|
|
9922
|
+
const targetMode = getTextByPathList(rel, [
|
|
9923
|
+
'attrs',
|
|
9924
|
+
'TargetMode'
|
|
9925
|
+
]);
|
|
9833
9926
|
if (!id || !target) continue;
|
|
9834
|
-
|
|
9927
|
+
if (targetMode && 'external' === String(targetMode).toLowerCase()) continue;
|
|
9928
|
+
const loc = resolvePartTarget(presentationPart, target);
|
|
9835
9929
|
if (loc) {
|
|
9836
9930
|
relsMap[id] = loc;
|
|
9837
9931
|
if ('slide' === getRelTypeName(type)) slideTargets.push(loc);
|
|
9838
9932
|
}
|
|
9839
9933
|
}
|
|
9840
|
-
const presentation = await readXmlFile(zip,
|
|
9934
|
+
const presentation = await readXmlFile(zip, presentationPart);
|
|
9841
9935
|
const sldIds = asNodeArray(getTextByPathList(presentation, [
|
|
9842
9936
|
'p:presentation',
|
|
9843
9937
|
'p:sldIdLst',
|
|
@@ -9849,7 +9943,7 @@ async function getSlidesFromPresentation(zip) {
|
|
|
9849
9943
|
if (rid && relsMap[rid]) ordered.push(relsMap[rid]);
|
|
9850
9944
|
}
|
|
9851
9945
|
if (ordered.length) return ordered;
|
|
9852
|
-
return slideTargets
|
|
9946
|
+
return slideTargets;
|
|
9853
9947
|
}
|
|
9854
9948
|
async function getContentTypes(zip) {
|
|
9855
9949
|
const ContentTypesJson = await readXmlFile(zip, '[Content_Types].xml');
|
|
@@ -9857,7 +9951,7 @@ async function getContentTypes(zip) {
|
|
|
9857
9951
|
'Types',
|
|
9858
9952
|
'Override'
|
|
9859
9953
|
]));
|
|
9860
|
-
|
|
9954
|
+
const overrideSlides = [];
|
|
9861
9955
|
let slideLayoutsLocArray = [];
|
|
9862
9956
|
for (const item of overrides){
|
|
9863
9957
|
const contentType = item?.attrs?.ContentType;
|
|
@@ -9866,7 +9960,7 @@ async function getContentTypes(zip) {
|
|
|
9866
9960
|
const loc = String(partName).replace(/^\//, '');
|
|
9867
9961
|
switch(contentType){
|
|
9868
9962
|
case 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml':
|
|
9869
|
-
|
|
9963
|
+
overrideSlides.push(loc);
|
|
9870
9964
|
break;
|
|
9871
9965
|
case 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml':
|
|
9872
9966
|
slideLayoutsLocArray.push(loc);
|
|
@@ -9874,9 +9968,9 @@ async function getContentTypes(zip) {
|
|
|
9874
9968
|
default:
|
|
9875
9969
|
}
|
|
9876
9970
|
}
|
|
9877
|
-
slidesLocArray = slidesLocArray.sort(sortSlideXml);
|
|
9878
9971
|
slideLayoutsLocArray = slideLayoutsLocArray.sort(sortSlideXml);
|
|
9879
|
-
|
|
9972
|
+
let slidesLocArray = await getSlidesFromPresentation(zip);
|
|
9973
|
+
if (!slidesLocArray.length) slidesLocArray = overrideSlides.sort(sortSlideXml);
|
|
9880
9974
|
return {
|
|
9881
9975
|
slides: slidesLocArray,
|
|
9882
9976
|
slideLayouts: slideLayoutsLocArray
|