@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 +52 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +52 -1
- 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.d.ts
CHANGED
|
@@ -43,8 +43,12 @@ export interface PatternFill {
|
|
|
43
43
|
|
|
44
44
|
export type Fill = ColorFill | ImageFill | GradientFill | PatternFill
|
|
45
45
|
|
|
46
|
+
export type BorderColor =
|
|
47
|
+
| { type: 'color', value: string }
|
|
48
|
+
| { type: 'gradient', value: GradientFill['value'] }
|
|
49
|
+
|
|
46
50
|
export interface Border {
|
|
47
|
-
borderColor:
|
|
51
|
+
borderColor: BorderColor
|
|
48
52
|
borderWidth: number
|
|
49
53
|
borderType:'solid' | 'dashed' | 'dotted'
|
|
50
54
|
}
|
|
@@ -81,7 +85,7 @@ export interface Shape {
|
|
|
81
85
|
top: number
|
|
82
86
|
width: number
|
|
83
87
|
height: number
|
|
84
|
-
borderColor:
|
|
88
|
+
borderColor: BorderColor
|
|
85
89
|
borderWidth: number
|
|
86
90
|
borderType: 'solid' | 'dashed' | 'dotted'
|
|
87
91
|
borderStrokeDasharray: string
|
|
@@ -114,7 +118,7 @@ export interface Text {
|
|
|
114
118
|
top: number
|
|
115
119
|
width: number
|
|
116
120
|
height: number
|
|
117
|
-
borderColor:
|
|
121
|
+
borderColor: BorderColor
|
|
118
122
|
borderWidth: number
|
|
119
123
|
borderType: 'solid' | 'dashed' | 'dotted'
|
|
120
124
|
borderStrokeDasharray: string
|
|
@@ -155,7 +159,7 @@ export interface Image {
|
|
|
155
159
|
r?: number
|
|
156
160
|
}
|
|
157
161
|
geom: string
|
|
158
|
-
borderColor:
|
|
162
|
+
borderColor: BorderColor
|
|
159
163
|
borderWidth: number
|
|
160
164
|
borderType: 'solid' | 'dashed' | 'dotted'
|
|
161
165
|
borderStrokeDasharray: string
|
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(/</g, '<').replaceAll(/>/g, '>').replaceAll(/&/g, '&').replaceAll(/'/g, "'").replaceAll(/"/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
|
-
|
|
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 '';
|