pptx2js 0.4.0 → 0.4.3

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.
@@ -1,128 +0,0 @@
1
- /**
2
- * 颜色规范化(srgbClr、schemeClr、渐变首色标)
3
- */
4
- const { asArray, attr, child } = require('../xml-utils');
5
-
6
- /** @type {Record<string, string>} */
7
- const DEFAULT_SCHEME = {
8
- dk1: '000000',
9
- lt1: 'FFFFFF',
10
- dk2: '44546A',
11
- lt2: 'E7E6E6',
12
- accent1: '4472C4',
13
- accent2: 'ED7D31',
14
- accent3: 'A5A5A5',
15
- accent4: 'FFC000',
16
- accent5: '5B9BD5',
17
- accent6: '70AD47',
18
- hlink: '0563C1',
19
- folHlink: '954F72',
20
- };
21
-
22
- /**
23
- * @param {Record<string, object>|null} parsed
24
- * @param {string|null} themePath
25
- * @returns {Record<string, string>}
26
- */
27
- function loadColorScheme(parsed, themePath) {
28
- if (!themePath || !parsed[themePath]) return { ...DEFAULT_SCHEME };
29
-
30
- const theme = child(parsed[themePath], 'a:theme');
31
- const clrScheme = child(child(theme, 'a:themeElements'), 'a:clrScheme');
32
- if (!clrScheme) return { ...DEFAULT_SCHEME };
33
-
34
- const scheme = { ...DEFAULT_SCHEME };
35
- for (const name of Object.keys(DEFAULT_SCHEME)) {
36
- const slot = child(clrScheme, `a:${name}`);
37
- const rgb = extractRgbFromColorNode(slot);
38
- if (rgb) scheme[name] = rgb;
39
- }
40
- return scheme;
41
- }
42
-
43
- /**
44
- * @param {object|null|undefined} colorNode a:srgbClr / a:schemeClr 的父级
45
- * @returns {string|null}
46
- */
47
- function extractRgbFromColorNode(colorNode) {
48
- if (!colorNode) return null;
49
-
50
- const srgb = child(colorNode, 'a:srgbClr');
51
- if (srgb) {
52
- const val = attr(srgb, 'val');
53
- return val ? val.toUpperCase() : null;
54
- }
55
-
56
- const sys = child(colorNode, 'a:sysClr');
57
- if (sys) {
58
- const last = attr(sys, 'lastClr');
59
- return last ? last.toUpperCase() : null;
60
- }
61
-
62
- return null;
63
- }
64
-
65
- /**
66
- * @param {object|null|undefined} fillNode a:solidFill | a:gradFill 等
67
- * @param {Record<string, string>} scheme
68
- * @returns {{ color: string|null, degraded: boolean }}
69
- */
70
- function resolveFillColor(fillNode, scheme) {
71
- if (!fillNode) return { color: null, degraded: false };
72
-
73
- const solid = child(fillNode, 'a:solidFill');
74
- if (solid) {
75
- return { color: resolveColorFromContainer(solid, scheme), degraded: false };
76
- }
77
-
78
- const grad = child(fillNode, 'a:gradFill');
79
- if (grad) {
80
- const gs = asArray(child(child(grad, 'a:gsLst'), 'a:gs'))[0];
81
- return {
82
- color: gs ? resolveColorFromContainer(gs, scheme) : null,
83
- degraded: true,
84
- };
85
- }
86
-
87
- return { color: null, degraded: false };
88
- }
89
-
90
- /**
91
- * @param {object|null|undefined} container 含 a:srgbClr / a:schemeClr
92
- * @param {Record<string, string>} scheme
93
- * @returns {string|null}
94
- */
95
- function resolveColorFromContainer(container, scheme) {
96
- if (!container) return null;
97
-
98
- const srgb = child(container, 'a:srgbClr');
99
- if (srgb) {
100
- const val = attr(srgb, 'val');
101
- return val ? val.toUpperCase() : null;
102
- }
103
-
104
- const schemeClr = child(container, 'a:schemeClr');
105
- if (schemeClr) {
106
- const name = attr(schemeClr, 'val');
107
- return name ? scheme[name] ?? DEFAULT_SCHEME[name] ?? null : null;
108
- }
109
-
110
- return extractRgbFromColorNode(container);
111
- }
112
-
113
- /**
114
- * @param {Record<string, string>} scheme
115
- * @param {object|null|undefined} clrNode
116
- * @returns {string|null}
117
- */
118
- function resolveColor(scheme, clrNode) {
119
- return resolveColorFromContainer(clrNode, scheme);
120
- }
121
-
122
- module.exports = {
123
- DEFAULT_SCHEME,
124
- loadColorScheme,
125
- resolveFillColor,
126
- resolveColor,
127
- resolveColorFromContainer,
128
- };
package/lib/utils/emu.js DELETED
@@ -1,20 +0,0 @@
1
- /** EMU(English Metric Units)与英寸换算,1 英寸 = 914400 EMU */
2
- const EMU_PER_INCH = 914400;
3
-
4
- /**
5
- * @param {number} emu
6
- * @returns {number}
7
- */
8
- function emuToInch(emu) {
9
- return emu / EMU_PER_INCH;
10
- }
11
-
12
- /**
13
- * @param {number} inch
14
- * @returns {number}
15
- */
16
- function inchToEmu(inch) {
17
- return inch * EMU_PER_INCH;
18
- }
19
-
20
- module.exports = { EMU_PER_INCH, emuToInch, inchToEmu };