pptx-browser 4.1.0
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/LICENSE +9 -0
- package/README.md +209 -0
- package/package.json +53 -0
- package/src/animation.js +817 -0
- package/src/charts.js +989 -0
- package/src/clipboard.js +416 -0
- package/src/colors.js +297 -0
- package/src/effects3d.js +312 -0
- package/src/extract.js +535 -0
- package/src/fntdata.js +265 -0
- package/src/fonts.js +676 -0
- package/src/index.js +751 -0
- package/src/pdf.js +298 -0
- package/src/render.js +1964 -0
- package/src/shapes.js +666 -0
- package/src/slideshow.js +492 -0
- package/src/smartart.js +696 -0
- package/src/svg.js +732 -0
- package/src/theme.js +88 -0
- package/src/utils.js +50 -0
- package/src/writer.js +1015 -0
- package/src/zip-writer.js +214 -0
- package/src/zip.js +194 -0
package/src/theme.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* theme.js — Parse OOXML theme XML and build effective theme colour tables.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { g1 } from './utils.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parse ppt/theme/theme1.xml and return:
|
|
10
|
+
* { colors, majorFont, minorFont }
|
|
11
|
+
* where `colors` maps scheme names → hex strings.
|
|
12
|
+
*/
|
|
13
|
+
export function parseTheme(themeDoc) {
|
|
14
|
+
if (!themeDoc) {
|
|
15
|
+
return { colors: {}, majorFont: 'Calibri Light', minorFont: 'Calibri' };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ── Colour scheme ──────────────────────────────────────────────────────────
|
|
19
|
+
const clrScheme = g1(themeDoc, 'clrScheme');
|
|
20
|
+
const colors = {};
|
|
21
|
+
|
|
22
|
+
if (clrScheme) {
|
|
23
|
+
const slots = ['dk1','lt1','dk2','lt2',
|
|
24
|
+
'accent1','accent2','accent3','accent4','accent5','accent6',
|
|
25
|
+
'hlink','folHlink'];
|
|
26
|
+
for (const key of slots) {
|
|
27
|
+
const el = g1(clrScheme, key);
|
|
28
|
+
if (!el) continue;
|
|
29
|
+
const srgb = g1(el, 'srgbClr');
|
|
30
|
+
const sysClr = g1(el, 'sysClr');
|
|
31
|
+
if (srgb) {
|
|
32
|
+
colors[key] = srgb.getAttribute('val') || '';
|
|
33
|
+
} else if (sysClr) {
|
|
34
|
+
colors[key] = sysClr.getAttribute('lastClr') || '';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ── Font scheme ────────────────────────────────────────────────────────────
|
|
40
|
+
const fontScheme = g1(themeDoc, 'fontScheme');
|
|
41
|
+
let majorFont = 'Calibri Light', minorFont = 'Calibri';
|
|
42
|
+
|
|
43
|
+
if (fontScheme) {
|
|
44
|
+
const majorFontEl = g1(fontScheme, 'majorFont');
|
|
45
|
+
const minorFontEl = g1(fontScheme, 'minorFont');
|
|
46
|
+
if (majorFontEl) {
|
|
47
|
+
const latin = g1(majorFontEl, 'latin');
|
|
48
|
+
if (latin) majorFont = latin.getAttribute('typeface') || majorFont;
|
|
49
|
+
}
|
|
50
|
+
if (minorFontEl) {
|
|
51
|
+
const latin = g1(minorFontEl, 'latin');
|
|
52
|
+
if (latin) minorFont = latin.getAttribute('typeface') || minorFont;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { colors, majorFont, minorFont };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parse the <p:clrMap> element from a slide master.
|
|
61
|
+
* Returns a map like { bg1: 'lt1', tx1: 'dk1', … }
|
|
62
|
+
*/
|
|
63
|
+
export function parseClrMap(masterDoc) {
|
|
64
|
+
if (!masterDoc) return {};
|
|
65
|
+
const clrMap = g1(masterDoc, 'clrMap');
|
|
66
|
+
if (!clrMap) return {};
|
|
67
|
+
const map = {};
|
|
68
|
+
const attrs = ['bg1','tx1','bg2','tx2',
|
|
69
|
+
'accent1','accent2','accent3','accent4','accent5','accent6',
|
|
70
|
+
'hlink','folHlink'];
|
|
71
|
+
for (const a of attrs) {
|
|
72
|
+
const v = clrMap.getAttribute(a);
|
|
73
|
+
if (v) map[a] = v;
|
|
74
|
+
}
|
|
75
|
+
return map;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Build effective theme colours by applying clrMap remapping.
|
|
80
|
+
* e.g. if clrMap says bg1→lt1, then themeColors.bg1 = themeColors.lt1.
|
|
81
|
+
*/
|
|
82
|
+
export function buildThemeColors(themeData, clrMap) {
|
|
83
|
+
const base = { ...themeData.colors };
|
|
84
|
+
for (const [key, ref] of Object.entries(clrMap)) {
|
|
85
|
+
if (base[ref] !== undefined) base[key] = base[ref];
|
|
86
|
+
}
|
|
87
|
+
return base;
|
|
88
|
+
}
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* utils.js — XML parsing helpers and shared constants.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function parseXml(str) {
|
|
6
|
+
return new DOMParser().parseFromString(str, 'application/xml');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Get all descendant elements with a given local name (namespace-agnostic). */
|
|
10
|
+
export function gtn(node, localName) {
|
|
11
|
+
if (!node) return [];
|
|
12
|
+
const results = [];
|
|
13
|
+
const all = node.getElementsByTagName('*');
|
|
14
|
+
for (let i = 0; i < all.length; i++) {
|
|
15
|
+
if (all[i].localName === localName) results.push(all[i]);
|
|
16
|
+
}
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Get the first descendant element with the given local name, or null. */
|
|
21
|
+
export function g1(node, localName) {
|
|
22
|
+
return gtn(node, localName)[0] ?? null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Get an attribute value, or `def` if absent. */
|
|
26
|
+
export function attr(el, name, def = null) {
|
|
27
|
+
if (!el) return def;
|
|
28
|
+
const v = el.getAttribute(name);
|
|
29
|
+
return v !== null ? v : def;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Get an attribute value as an integer, or `def` if absent. */
|
|
33
|
+
export function attrInt(el, name, def = 0) {
|
|
34
|
+
const v = attr(el, name);
|
|
35
|
+
return v !== null ? parseInt(v, 10) : def;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Get an attribute value as a float, or `def` if absent. */
|
|
39
|
+
export function attrFloat(el, name, def = 0) {
|
|
40
|
+
const v = attr(el, name);
|
|
41
|
+
return v !== null ? parseFloat(v) : def;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function clamp(v, lo, hi) { return Math.max(lo, Math.min(hi, v)); }
|
|
45
|
+
|
|
46
|
+
// ── Unit constants ──────────────────────────────────────────────────────────
|
|
47
|
+
/** EMU (English Metric Units) per inch */
|
|
48
|
+
export const EMU_PER_INCH = 914400;
|
|
49
|
+
/** EMU per typographic point */
|
|
50
|
+
export const EMU_PER_PT = 12700;
|