pptx-glimpse 3.0.0 → 3.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.
@@ -1,62 +1,3 @@
1
- // ../renderer/src/warning-logger.ts
2
- var PREFIX = "[pptx-glimpse]";
3
- var currentLevel = "off";
4
- var entries = [];
5
- var featureCounts = /* @__PURE__ */ new Map();
6
- function initWarningLogger(level) {
7
- currentLevel = level;
8
- entries = [];
9
- featureCounts.clear();
10
- }
11
- function warn(feature, message, context) {
12
- if (currentLevel === "off") return;
13
- entries.push({ feature, message, ...context !== void 0 && { context } });
14
- const existing = featureCounts.get(feature);
15
- if (existing) {
16
- existing.count++;
17
- } else {
18
- featureCounts.set(feature, { message, count: 1 });
19
- }
20
- if (currentLevel === "debug") {
21
- const ctx = context ? ` (${context})` : "";
22
- console.warn(`${PREFIX} SKIP: ${feature} - ${message}${ctx}`);
23
- }
24
- }
25
- function debug(feature, message, context) {
26
- if (currentLevel !== "debug") return;
27
- entries.push({ feature, message, ...context !== void 0 && { context } });
28
- const existing = featureCounts.get(feature);
29
- if (existing) {
30
- existing.count++;
31
- } else {
32
- featureCounts.set(feature, { message, count: 1 });
33
- }
34
- const ctx = context ? ` (${context})` : "";
35
- console.warn(`${PREFIX} DEBUG: ${feature} - ${message}${ctx}`);
36
- }
37
- function getWarningSummary() {
38
- const features = [];
39
- for (const [feature, { message, count }] of featureCounts) {
40
- features.push({ feature, message, count });
41
- }
42
- return { totalCount: entries.length, features };
43
- }
44
- function flushWarnings() {
45
- const summary = getWarningSummary();
46
- if (currentLevel !== "off" && summary.features.length > 0) {
47
- console.warn(`${PREFIX} Summary: ${summary.features.length} unsupported feature(s) detected`);
48
- for (const { feature, count } of summary.features) {
49
- console.warn(` - ${feature}: ${count} occurrence(s)`);
50
- }
51
- }
52
- entries = [];
53
- featureCounts.clear();
54
- return summary;
55
- }
56
- function getWarningEntries() {
57
- return entries;
58
- }
59
-
60
1
  // ../renderer/src/font/font-mapping.ts
61
2
  var DEFAULT_FONT_MAPPING = {
62
3
  // Latin fonts
@@ -111,6 +52,81 @@ function getMappedFont(fontFamily, mapping) {
111
52
  return null;
112
53
  }
113
54
 
55
+ // ../renderer/src/warning-logger.ts
56
+ var PREFIX = "[pptx-glimpse]";
57
+ var InMemoryWarningLogger = class {
58
+ constructor(level) {
59
+ this.level = level;
60
+ }
61
+ level;
62
+ entries = [];
63
+ featureCounts = /* @__PURE__ */ new Map();
64
+ warn(feature, message, context) {
65
+ if (this.level === "off") return;
66
+ this.record(feature, message, context);
67
+ if (this.level === "debug") {
68
+ const ctx = context ? ` (${context})` : "";
69
+ console.warn(`${PREFIX} SKIP: ${feature} - ${message}${ctx}`);
70
+ }
71
+ }
72
+ debug(feature, message, context) {
73
+ if (this.level !== "debug") return;
74
+ this.record(feature, message, context);
75
+ const ctx = context ? ` (${context})` : "";
76
+ console.warn(`${PREFIX} DEBUG: ${feature} - ${message}${ctx}`);
77
+ }
78
+ getWarningSummary() {
79
+ const features = [];
80
+ for (const [feature, { message, count }] of this.featureCounts) {
81
+ features.push({ feature, message, count });
82
+ }
83
+ return { totalCount: this.entries.length, features };
84
+ }
85
+ flushWarnings() {
86
+ const summary = this.getWarningSummary();
87
+ if (this.level !== "off" && summary.features.length > 0) {
88
+ console.warn(`${PREFIX} Summary: ${summary.features.length} unsupported feature(s) detected`);
89
+ for (const { feature, count } of summary.features) {
90
+ console.warn(` - ${feature}: ${count} occurrence(s)`);
91
+ }
92
+ }
93
+ this.entries = [];
94
+ this.featureCounts.clear();
95
+ return summary;
96
+ }
97
+ getWarningEntries() {
98
+ return this.entries;
99
+ }
100
+ getLogLevel() {
101
+ return this.level;
102
+ }
103
+ record(feature, message, context) {
104
+ this.entries.push({ feature, message, ...context !== void 0 && { context } });
105
+ const existing = this.featureCounts.get(feature);
106
+ if (existing) {
107
+ existing.count++;
108
+ } else {
109
+ this.featureCounts.set(feature, { message, count: 1 });
110
+ }
111
+ }
112
+ };
113
+ var activeLogger = createWarningLogger("off");
114
+ function createWarningLogger(level) {
115
+ return new InMemoryWarningLogger(level);
116
+ }
117
+ function getActiveWarningLogger() {
118
+ return activeLogger;
119
+ }
120
+ function warn(feature, message, context) {
121
+ activeLogger.warn(feature, message, context);
122
+ }
123
+ function getWarningSummary() {
124
+ return activeLogger.getWarningSummary();
125
+ }
126
+ function getWarningEntries() {
127
+ return activeLogger.getWarningEntries();
128
+ }
129
+
114
130
  // ../renderer/src/unsafe-type-assertion.ts
115
131
  function unsafeExternalInteropAssertion(value) {
116
132
  return value;
@@ -1099,11 +1115,8 @@ function getCjkFallbackFonts(mappedFontName) {
1099
1115
 
1100
1116
  // ../renderer/src/font/font-mapping-context.ts
1101
1117
  var currentMapping = { ...DEFAULT_FONT_MAPPING };
1102
- function setFontMapping(mapping) {
1103
- currentMapping = mapping;
1104
- }
1105
- function resetFontMapping() {
1106
- currentMapping = { ...DEFAULT_FONT_MAPPING };
1118
+ function getFontMapping() {
1119
+ return currentMapping;
1107
1120
  }
1108
1121
  function getCurrentMappedFont(fontFamily) {
1109
1122
  return getMappedFont(fontFamily, currentMapping);
@@ -1113,20 +1126,22 @@ function getCurrentMappedFont(fontFamily) {
1113
1126
  var PX_PER_PT2 = 96 / 72;
1114
1127
  var BOLD_FACTOR2 = 1.05;
1115
1128
  var OpentypeTextMeasurer = class {
1116
- fonts;
1117
- defaultFont;
1118
- warnedFonts = /* @__PURE__ */ new Set();
1119
1129
  /**
1120
1130
  * @param fonts - font name -> opentype.js Map of Font objects
1121
1131
  * @param defaultFont - fallback font (optional)
1122
1132
  */
1123
- constructor(fonts, defaultFont) {
1133
+ constructor(fonts, defaultFont, fontMapping) {
1134
+ this.fontMapping = fontMapping;
1124
1135
  this.fonts = fonts;
1125
1136
  this.defaultFont = defaultFont ?? null;
1126
1137
  }
1127
- measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa) {
1128
- const latinFont = this.resolveFont(fontFamily);
1129
- const eaFont = this.resolveFont(fontFamilyEa);
1138
+ fontMapping;
1139
+ fonts;
1140
+ defaultFont;
1141
+ warnedFonts = /* @__PURE__ */ new Set();
1142
+ measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa, context) {
1143
+ const latinFont = this.resolveFont(fontFamily, context);
1144
+ const eaFont = this.resolveFont(fontFamilyEa, context);
1130
1145
  const fallbackFont = latinFont ?? eaFont ?? this.defaultFont;
1131
1146
  if (!fallbackFont) {
1132
1147
  return measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa);
@@ -1134,7 +1149,7 @@ var OpentypeTextMeasurer = class {
1134
1149
  const fontSizePx = fontSizePt * PX_PER_PT2;
1135
1150
  const latinFontResolved = latinFont ?? fallbackFont;
1136
1151
  const eaFontResolved = eaFont ?? fallbackFont;
1137
- const boldLatinFont = bold ? this.resolveBoldFont(fontFamily) : null;
1152
+ const boldLatinFont = bold ? this.resolveBoldFont(fontFamily, context) : null;
1138
1153
  const latinGlyphCache = /* @__PURE__ */ new Map();
1139
1154
  const eaGlyphCache = eaFontResolved !== latinFontResolved ? /* @__PURE__ */ new Map() : latinGlyphCache;
1140
1155
  const boldGlyphCache = /* @__PURE__ */ new Map();
@@ -1166,26 +1181,26 @@ var OpentypeTextMeasurer = class {
1166
1181
  }
1167
1182
  return totalWidth;
1168
1183
  }
1169
- getLineHeightRatio(fontFamily, fontFamilyEa) {
1170
- const font = this.resolveFont(fontFamily) ?? this.resolveFont(fontFamilyEa) ?? this.defaultFont;
1184
+ getLineHeightRatio(fontFamily, fontFamilyEa, context) {
1185
+ const font = this.resolveFont(fontFamily, context) ?? this.resolveFont(fontFamilyEa, context) ?? this.defaultFont;
1171
1186
  if (!font) return 1.2;
1172
1187
  return (font.ascender + Math.abs(font.descender)) / font.unitsPerEm;
1173
1188
  }
1174
- getAscenderRatio(fontFamily, fontFamilyEa) {
1175
- const font = this.resolveFont(fontFamily) ?? this.resolveFont(fontFamilyEa) ?? this.defaultFont;
1189
+ getAscenderRatio(fontFamily, fontFamilyEa, context) {
1190
+ const font = this.resolveFont(fontFamily, context) ?? this.resolveFont(fontFamilyEa, context) ?? this.defaultFont;
1176
1191
  if (!font) return 1;
1177
1192
  return font.ascender / font.unitsPerEm;
1178
1193
  }
1179
- resolveBoldFont(name) {
1194
+ resolveBoldFont(name, context) {
1180
1195
  if (!name) return null;
1181
1196
  const bases = [name];
1182
- const mappedBase = getCurrentMappedFont(name);
1197
+ const mappedBase = this.getMappedFont(name, context);
1183
1198
  if (mappedBase && mappedBase !== name) bases.push(mappedBase);
1184
1199
  for (const base of bases) {
1185
1200
  for (const boldName of [`${base} Bold`, `${base}-Bold`]) {
1186
1201
  const direct = this.fonts.get(boldName);
1187
1202
  if (direct) return direct;
1188
- const mapped = getCurrentMappedFont(boldName);
1203
+ const mapped = this.getMappedFont(boldName, context);
1189
1204
  if (mapped) {
1190
1205
  const mappedFont = this.fonts.get(mapped);
1191
1206
  if (mappedFont) return mappedFont;
@@ -1194,11 +1209,11 @@ var OpentypeTextMeasurer = class {
1194
1209
  }
1195
1210
  return null;
1196
1211
  }
1197
- resolveFont(name) {
1212
+ resolveFont(name, context) {
1198
1213
  if (!name) return null;
1199
1214
  const direct = this.fonts.get(name);
1200
1215
  if (direct) return direct;
1201
- const mapped = getCurrentMappedFont(name);
1216
+ const mapped = this.getMappedFont(name, context);
1202
1217
  if (mapped) {
1203
1218
  const mappedFont = this.fonts.get(mapped);
1204
1219
  if (mappedFont) return mappedFont;
@@ -1207,12 +1222,19 @@ var OpentypeTextMeasurer = class {
1207
1222
  if (fallbackFont) return fallbackFont;
1208
1223
  }
1209
1224
  }
1210
- if (!this.warnedFonts.has(name)) {
1225
+ if (context?.warningLogger) {
1226
+ if (context.fontWarningCache?.has(name)) return null;
1227
+ context.fontWarningCache?.add(name);
1228
+ context.warningLogger.warn("font.notFound", `Font not found: "${name}"`);
1229
+ } else if (!this.warnedFonts.has(name)) {
1211
1230
  this.warnedFonts.add(name);
1212
1231
  warn("font.notFound", `Font not found: "${name}"`);
1213
1232
  }
1214
1233
  return null;
1215
1234
  }
1235
+ getMappedFont(name, context) {
1236
+ return context?.fontMapping !== void 0 ? getMappedFont(name, context.fontMapping) : this.fontMapping !== void 0 ? getMappedFont(name, this.fontMapping) : getCurrentMappedFont(name);
1237
+ }
1216
1238
  };
1217
1239
 
1218
1240
  // ../renderer/src/font/text-path-context.ts
@@ -1224,31 +1246,40 @@ var DefaultTextPathFontResolver = class {
1224
1246
  this.fonts = fonts;
1225
1247
  this.defaultFont = defaultFont ?? null;
1226
1248
  }
1227
- resolveFont(fontFamily, fontFamilyEa, jpanFallback) {
1249
+ resolveFont(fontFamily, fontFamilyEa, jpanFallback, context) {
1228
1250
  if (fontFamily) {
1229
- const font = this.findFont(fontFamily);
1251
+ const font = this.findFont(fontFamily, context);
1230
1252
  if (font) return font;
1231
1253
  }
1232
1254
  if (fontFamilyEa) {
1233
- const font = this.findFont(fontFamilyEa);
1255
+ const font = this.findFont(fontFamilyEa, context);
1234
1256
  if (font) return font;
1235
1257
  }
1236
1258
  if (jpanFallback) {
1237
- const font = this.findFont(jpanFallback);
1259
+ const font = this.findFont(jpanFallback, context);
1238
1260
  if (font) return font;
1239
1261
  }
1240
1262
  for (const name of [fontFamily, fontFamilyEa, jpanFallback]) {
1241
- if (name && !this.warnedFonts.has(name)) {
1242
- this.warnedFonts.add(name);
1243
- warn("font.notFound", `Font not found: "${name}"`);
1263
+ if (name) {
1264
+ const logger = context?.warningLogger;
1265
+ if (logger) {
1266
+ if (context.fontWarningCache?.has(name)) continue;
1267
+ context.fontWarningCache?.add(name);
1268
+ logger.warn("font.notFound", `Font not found: "${name}"`);
1269
+ continue;
1270
+ }
1271
+ if (!this.warnedFonts.has(name)) {
1272
+ this.warnedFonts.add(name);
1273
+ warn("font.notFound", `Font not found: "${name}"`);
1274
+ }
1244
1275
  }
1245
1276
  }
1246
1277
  return this.defaultFont;
1247
1278
  }
1248
- findFont(name) {
1279
+ findFont(name, context) {
1249
1280
  const direct = this.fonts.get(name);
1250
1281
  if (direct) return direct;
1251
- const mapped = getCurrentMappedFont(name);
1282
+ const mapped = context?.fontMapping !== void 0 ? getMappedFont(name, context.fontMapping) : getCurrentMappedFont(name);
1252
1283
  if (mapped) {
1253
1284
  const mappedFont = this.fonts.get(mapped);
1254
1285
  if (mappedFont) return mappedFont;
@@ -1261,15 +1292,9 @@ var DefaultTextPathFontResolver = class {
1261
1292
  }
1262
1293
  };
1263
1294
  var currentResolver = null;
1264
- function setTextPathFontResolver(resolver) {
1265
- currentResolver = resolver;
1266
- }
1267
1295
  function getTextPathFontResolver() {
1268
1296
  return currentResolver;
1269
1297
  }
1270
- function resetTextPathFontResolver() {
1271
- currentResolver = null;
1272
- }
1273
1298
 
1274
1299
  // ../renderer/src/font/ttc-parser.ts
1275
1300
  var TTC_TAG = 1953784678;
@@ -1461,11 +1486,12 @@ function collectFontNames(font) {
1461
1486
  }
1462
1487
  return names;
1463
1488
  }
1464
- function buildOpentypeSetupFromState(state) {
1489
+ function buildOpentypeSetupFromState(state, fontMapping) {
1465
1490
  if (state.measurerFonts.size === 0 && !state.firstMeasurerFont) return null;
1466
1491
  const measurer = new OpentypeTextMeasurer(
1467
1492
  state.measurerFonts,
1468
- state.firstMeasurerFont ?? void 0
1493
+ state.firstMeasurerFont ?? void 0,
1494
+ fontMapping
1469
1495
  );
1470
1496
  const fontResolver = new DefaultTextPathFontResolver(
1471
1497
  state.resolverFonts,
@@ -1494,7 +1520,7 @@ async function createOpentypeSetupFromBuffers(fontBuffers, fontMapping) {
1494
1520
  } catch {
1495
1521
  }
1496
1522
  }
1497
- return buildOpentypeSetupFromState(state);
1523
+ return buildOpentypeSetupFromState(state, mapping);
1498
1524
  }
1499
1525
  var SYSTEM_FONT_CACHE_KEY = "__pptxGlimpseSystemFontCache__";
1500
1526
  function getSystemFontCacheStore() {
@@ -1519,26 +1545,21 @@ function clearFontCache() {
1519
1545
 
1520
1546
  export {
1521
1547
  getMetricsFallbackFont,
1522
- unsafeExternalInteropAssertion,
1523
- unsafeBrandAssertion,
1524
- initWarningLogger,
1525
- warn,
1526
- debug,
1527
- getWarningSummary,
1528
- flushWarnings,
1529
- getWarningEntries,
1530
1548
  DEFAULT_FONT_MAPPING,
1531
1549
  createFontMapping,
1532
1550
  getMappedFont,
1533
- setFontMapping,
1534
- resetFontMapping,
1535
- getCurrentMappedFont,
1551
+ getFontMapping,
1536
1552
  getLineHeightRatio,
1537
1553
  getAscenderRatio,
1538
1554
  measureTextWidth,
1539
- setTextPathFontResolver,
1555
+ createWarningLogger,
1556
+ getActiveWarningLogger,
1557
+ warn,
1558
+ getWarningSummary,
1559
+ getWarningEntries,
1540
1560
  getTextPathFontResolver,
1541
- resetTextPathFontResolver,
1561
+ unsafeExternalInteropAssertion,
1562
+ unsafeBrandAssertion,
1542
1563
  tryLoadOpentype,
1543
1564
  buildReverseMapping,
1544
1565
  toArrayBuffer,
@@ -9,7 +9,7 @@ import {
9
9
  setCachedSystemOpentypeSetup,
10
10
  toArrayBuffer,
11
11
  tryLoadOpentype
12
- } from "./chunk-2AYNMYMC.js";
12
+ } from "./chunk-PGCREQQU.js";
13
13
 
14
14
  // ../renderer/src/font/opentype-system-helpers.ts
15
15
  import { readFile } from "fs/promises";
@@ -99,7 +99,8 @@ async function createOpentypeSetupFromSystem(additionalFontDirs, fontMapping, sk
99
99
  if (!opentype) return null;
100
100
  const fontFilePaths = collectFontFilePaths(additionalFontDirs, skipSystemFonts);
101
101
  if (fontFilePaths.length === 0) return null;
102
- const reverseMap = buildReverseMapping(createFontMapping(fontMapping));
102
+ const mapping = createFontMapping(fontMapping);
103
+ const reverseMap = buildReverseMapping(mapping);
103
104
  const state = createOpentypeSetupState();
104
105
  for (const filePath of fontFilePaths) {
105
106
  try {
@@ -112,7 +113,7 @@ async function createOpentypeSetupFromSystem(additionalFontDirs, fontMapping, sk
112
113
  } catch {
113
114
  }
114
115
  }
115
- const setup = buildOpentypeSetupFromState(state);
116
+ const setup = buildOpentypeSetupFromState(state, mapping);
116
117
  if (setup === null) return null;
117
118
  setCachedSystemOpentypeSetup(key, setup);
118
119
  return setup;
@@ -0,0 +1,83 @@
1
+ import {
2
+ DEFAULT_OUTPUT_WIDTH,
3
+ convertPptxToSvg,
4
+ renderPptxSourceModelToSvg
5
+ } from "./chunk-NMAO44T7.js";
6
+
7
+ // src/converter.ts
8
+ async function convertPptxToSvg2(input, options) {
9
+ return convertPptxToSvg(input, options, loadSystemFontSetup);
10
+ }
11
+ async function renderPptxSourceModelToSvg2(source, options) {
12
+ return renderPptxSourceModelToSvg(source, options, loadSystemFontSetup);
13
+ }
14
+ async function convertPptxToPng(input, options) {
15
+ const svgResult = await convertPptxToSvg2(input, {
16
+ ...options,
17
+ textOutput: "path"
18
+ });
19
+ const width = options?.width ?? DEFAULT_OUTPUT_WIDTH;
20
+ const height = options?.height;
21
+ const fontBuffers = await loadPngFontBuffers(options);
22
+ const slides = [];
23
+ for (const { slideNumber, svg } of svgResult.slides) {
24
+ const pngResult = await convertSvgToPng(svg, { width, height, fontBuffers });
25
+ slides.push({
26
+ slideNumber,
27
+ png: toPlainUint8Array(pngResult.png),
28
+ width: pngResult.width,
29
+ height: pngResult.height
30
+ });
31
+ }
32
+ return {
33
+ slides,
34
+ diagnostics: svgResult.diagnostics,
35
+ supportCoverage: svgResult.supportCoverage
36
+ };
37
+ }
38
+ var loadSystemFontSetup = async (options) => {
39
+ if (!shouldLoadSystemFonts(options)) {
40
+ return null;
41
+ }
42
+ const { createOpentypeSetupFromSystem } = await import(
43
+ /* @vite-ignore */
44
+ "./node-E6UXPQSQ.js"
45
+ );
46
+ return createOpentypeSetupFromSystem(
47
+ options?.fontDirs,
48
+ options?.fontMapping,
49
+ options?.skipSystemFonts
50
+ );
51
+ };
52
+ async function loadPngFontBuffers(options) {
53
+ if (options?.fonts !== void 0) {
54
+ return options.fonts.map((font) => toUint8Array(font.data));
55
+ }
56
+ if (!shouldLoadSystemFonts(options)) {
57
+ return [];
58
+ }
59
+ const { loadFontBuffersFromSystem } = await import(
60
+ /* @vite-ignore */
61
+ "./node-font-loader-OE3OLNDI.js"
62
+ );
63
+ return loadFontBuffersFromSystem(options?.fontDirs, options?.skipSystemFonts);
64
+ }
65
+ async function convertSvgToPng(svg, options) {
66
+ const { svgToPng } = await import("./png-IONMVVDQ.js");
67
+ return svgToPng(svg, options);
68
+ }
69
+ function shouldLoadSystemFonts(options) {
70
+ return options?.skipSystemFonts !== true || (options?.fontDirs?.length ?? 0) > 0;
71
+ }
72
+ function toUint8Array(data) {
73
+ return data instanceof Uint8Array ? data : new Uint8Array(data);
74
+ }
75
+ function toPlainUint8Array(data) {
76
+ return new Uint8Array(data);
77
+ }
78
+
79
+ export {
80
+ convertPptxToSvg2 as convertPptxToSvg,
81
+ renderPptxSourceModelToSvg2 as renderPptxSourceModelToSvg,
82
+ convertPptxToPng
83
+ };
@@ -0,0 +1,141 @@
1
+ import {
2
+ createComputedView,
3
+ readPptx
4
+ } from "./chunk-NMAO44T7.js";
5
+
6
+ // src/font/font-collector.ts
7
+ var DEFAULT_THEME_FONTS = {
8
+ majorLatin: "Calibri",
9
+ minorLatin: "Calibri"
10
+ };
11
+ function collectUsedFonts(input) {
12
+ const source = readPptx(input);
13
+ const defaultFontScheme = findDefaultThemeFontScheme(source);
14
+ const computed = createComputedView(source);
15
+ const fonts = /* @__PURE__ */ new Set();
16
+ collectThemeFonts(defaultFontScheme, fonts);
17
+ const visitedTemplateParts = /* @__PURE__ */ new Set();
18
+ for (const slide of computed.slides) {
19
+ const slideFontScheme = findThemeFontScheme(source, slide.themePartPath) ?? defaultFontScheme;
20
+ const templateElementsByPart = /* @__PURE__ */ new Map();
21
+ for (const element of slide.elements) {
22
+ if (element.sourceLayer === "slide") {
23
+ collectFontsFromElements([element], fonts, slideFontScheme);
24
+ continue;
25
+ }
26
+ const key = `${element.sourceLayer}:${element.sourcePartPath}`;
27
+ const elements = templateElementsByPart.get(key);
28
+ if (elements) {
29
+ elements.push(element);
30
+ } else {
31
+ templateElementsByPart.set(key, [element]);
32
+ }
33
+ }
34
+ for (const [key, elements] of templateElementsByPart) {
35
+ if (visitedTemplateParts.has(key)) continue;
36
+ visitedTemplateParts.add(key);
37
+ collectFontsFromElements(elements, fonts, slideFontScheme);
38
+ }
39
+ }
40
+ return {
41
+ theme: {
42
+ majorFont: defaultFontScheme.majorLatin,
43
+ minorFont: defaultFontScheme.minorLatin,
44
+ majorFontEa: defaultFontScheme.majorEastAsian ?? null,
45
+ minorFontEa: defaultFontScheme.minorEastAsian ?? null,
46
+ majorFontCs: defaultFontScheme.majorComplexScript ?? null,
47
+ minorFontCs: defaultFontScheme.minorComplexScript ?? null
48
+ },
49
+ fonts: [...fonts].sort()
50
+ };
51
+ }
52
+ function findDefaultThemeFontScheme(source) {
53
+ const firstThemePartPath = source.slideMasters.find(
54
+ (master) => master.themePartPath !== void 0
55
+ )?.themePartPath;
56
+ const scheme = findThemeFontScheme(source, firstThemePartPath) ?? source.themes[0]?.fontScheme;
57
+ return applyDefaultThemeFonts(scheme);
58
+ }
59
+ function findThemeFontScheme(source, themePartPath) {
60
+ if (themePartPath === void 0) return void 0;
61
+ const scheme = source.themes.find((theme) => theme.partPath === themePartPath)?.fontScheme;
62
+ return scheme !== void 0 ? applyDefaultThemeFonts(scheme) : void 0;
63
+ }
64
+ function applyDefaultThemeFonts(scheme) {
65
+ return {
66
+ ...DEFAULT_THEME_FONTS,
67
+ ...scheme
68
+ };
69
+ }
70
+ function collectThemeFonts(fontScheme, fonts) {
71
+ addFont(fonts, fontScheme.majorLatin, fontScheme);
72
+ addFont(fonts, fontScheme.minorLatin, fontScheme);
73
+ addFont(fonts, fontScheme.majorEastAsian, fontScheme);
74
+ addFont(fonts, fontScheme.minorEastAsian, fontScheme);
75
+ addFont(fonts, fontScheme.majorComplexScript, fontScheme);
76
+ addFont(fonts, fontScheme.minorComplexScript, fontScheme);
77
+ addFont(fonts, fontScheme.majorJapanese, fontScheme);
78
+ addFont(fonts, fontScheme.minorJapanese, fontScheme);
79
+ }
80
+ function collectFontsFromElements(elements, fonts, fontScheme) {
81
+ for (const el of elements) {
82
+ switch (el.kind) {
83
+ case "shape":
84
+ if (el.textBody) collectFontsFromTextBody(el.textBody, fonts, fontScheme);
85
+ break;
86
+ case "group":
87
+ collectFontsFromElements(el.children, fonts, fontScheme);
88
+ break;
89
+ case "table":
90
+ for (const row of el.table.rows) {
91
+ for (const cell of row.cells) {
92
+ if (cell.textBody) collectFontsFromTextBody(cell.textBody, fonts, fontScheme);
93
+ }
94
+ }
95
+ break;
96
+ case "connector":
97
+ case "image":
98
+ case "chart":
99
+ case "smartArt":
100
+ case "raw":
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ function collectFontsFromTextBody(textBody, fonts, fontScheme) {
106
+ for (const para of textBody.paragraphs) {
107
+ addFont(fonts, para.properties?.bulletFont, fontScheme);
108
+ for (const run of para.runs) {
109
+ addFont(fonts, run.properties?.typeface, fontScheme);
110
+ addFont(fonts, run.properties?.typefaceEa, fontScheme);
111
+ addFont(fonts, run.properties?.typefaceCs, fontScheme);
112
+ }
113
+ }
114
+ }
115
+ function addFont(fonts, font, fontScheme) {
116
+ const resolved = resolveThemeFontAlias(font, fontScheme);
117
+ if (resolved) fonts.add(resolved);
118
+ }
119
+ function resolveThemeFontAlias(font, fontScheme) {
120
+ if (font === void 0) return void 0;
121
+ switch (font) {
122
+ case "+mj-lt":
123
+ return fontScheme.majorLatin;
124
+ case "+mn-lt":
125
+ return fontScheme.minorLatin;
126
+ case "+mj-ea":
127
+ return fontScheme.majorEastAsian ?? fontScheme.majorJapanese;
128
+ case "+mn-ea":
129
+ return fontScheme.minorEastAsian ?? fontScheme.minorJapanese;
130
+ case "+mj-cs":
131
+ return fontScheme.majorComplexScript;
132
+ case "+mn-cs":
133
+ return fontScheme.minorComplexScript;
134
+ default:
135
+ return font.startsWith("+mj-") || font.startsWith("+mn-") ? void 0 : font;
136
+ }
137
+ }
138
+
139
+ export {
140
+ collectUsedFonts
141
+ };