@extend-ai/react-pptx 0.2.3 → 0.2.4

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.js CHANGED
@@ -42,6 +42,92 @@ function throwIfAborted(signal) {
42
42
  }
43
43
  }
44
44
 
45
+ // ../../node_modules/.pnpm/@extend-ai+office-fonts@https+++github.com+extend-hq+rust-office+releases+download+office-fon_7r4y6vimjxvcmpreabk5ezevri/node_modules/@extend-ai/office-fonts/families.js
46
+ var families = [
47
+ { id: "carlito", family: "Carlito", original: "Calibri", load: () => import('./carlito-data-LDQ4YMUR.js') },
48
+ { id: "arimo", family: "Arimo", original: "Arial", load: () => import('./arimo-data-4NQ7UA57.js') },
49
+ { id: "tinos", family: "Tinos", original: "Times New Roman", load: () => import('./tinos-data-IPPHZ4Y6.js') },
50
+ { id: "cousine", family: "Cousine", original: "Courier New", load: () => import('./cousine-data-IPO23HJ5.js') },
51
+ { id: "intos", family: "Intos", original: "Aptos", load: () => import('./intos-data-55TEPAXO.js') },
52
+ { id: "intos-narrow", family: "Intos Narrow", original: "Aptos Narrow", load: () => import('./intos-narrow-data-FHJNOFRV.js') }
53
+ ];
54
+
55
+ // ../../node_modules/.pnpm/@extend-ai+office-fonts@https+++github.com+extend-hq+rust-office+releases+download+office-fon_7r4y6vimjxvcmpreabk5ezevri/node_modules/@extend-ai/office-fonts/runtime.js
56
+ var registry = /* @__PURE__ */ Symbol.for("@extend-ai/office-fonts/loads/v2");
57
+ var loads = globalThis[registry] ??= /* @__PURE__ */ new WeakMap();
58
+ var normalize = (family) => family.trim().replace(/^["']|["']$/g, "").toLowerCase();
59
+ var primary = (family) => family.split(",")[0];
60
+ var lookup = new Map(families.flatMap((family) => [family.original, family.family].map((name) => [normalize(name), family])));
61
+ var variants = [
62
+ { style: "normal", weight: "400", suffix: "" },
63
+ { style: "normal", weight: "700", suffix: " Bold" },
64
+ { style: "italic", weight: "400", suffix: " Italic" },
65
+ { style: "italic", weight: "700", suffix: " Bold Italic" }
66
+ ];
67
+ function matches(face, family, variant) {
68
+ const weight = face.weight === "normal" ? "400" : face.weight === "bold" ? "700" : face.weight;
69
+ const range = weight.split(/\s+/).map(Number);
70
+ return normalize(face.family) === normalize(family) && face.style === variant.style && Number(variant.weight) >= range[0] && Number(variant.weight) <= (range[1] ?? range[0]);
71
+ }
72
+ async function loadOfficeFonts(target = globalThis.document, requestedFamilies = ["Calibri"]) {
73
+ const FontFaceClass = target?.defaultView?.FontFace ?? globalThis.FontFace;
74
+ if (!target?.fonts || !FontFaceClass) return;
75
+ const fonts = target.fonts;
76
+ let entries = loads.get(fonts);
77
+ if (!entries) loads.set(fonts, entries = /* @__PURE__ */ new Map());
78
+ const selected = new Set([...requestedFamilies].map((name) => normalize(primary(name))));
79
+ await Promise.all([...selected].map(async (key) => {
80
+ const definition = lookup.get(key);
81
+ if (!definition) return;
82
+ const previous = entries.get(key);
83
+ if (previous && (!previous.ready || previous.faces.every((face) => fonts.has(face)))) return previous.promise;
84
+ const family = key === normalize(definition.original) ? definition.original : definition.family;
85
+ const state = { ready: false, faces: [], promise: void 0 };
86
+ state.promise = (async () => {
87
+ const added = [];
88
+ try {
89
+ const results = await Promise.allSettled(variants.map(async (variant, index) => {
90
+ const existing = [...fonts].filter((face2) => matches(face2, family, variant) && face2.status !== "error");
91
+ if (existing.length) {
92
+ const loaded = await Promise.allSettled(existing.map((face2) => face2.load()));
93
+ const available = loaded.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
94
+ if (available.length) return available;
95
+ }
96
+ let face;
97
+ if (family === definition.original) {
98
+ try {
99
+ face = await new FontFaceClass(family, `local("${family}${variant.suffix}")`, variant).load();
100
+ } catch {
101
+ face = void 0;
102
+ }
103
+ }
104
+ if (!face) {
105
+ const { faces: assets } = await definition.load();
106
+ face = new FontFaceClass(family, `url("${assets[index].source}")`, variant);
107
+ fonts.add(face);
108
+ added.push(face);
109
+ await face.load();
110
+ } else {
111
+ fonts.add(face);
112
+ added.push(face);
113
+ }
114
+ return [face];
115
+ }));
116
+ const failure = results.find((result) => result.status === "rejected");
117
+ if (failure) throw failure.reason;
118
+ state.faces = results.flatMap((result) => result.value);
119
+ state.ready = true;
120
+ } catch (error) {
121
+ for (const face of added) fonts.delete(face);
122
+ entries.delete(key);
123
+ throw error;
124
+ }
125
+ })();
126
+ entries.set(key, state);
127
+ return state.promise;
128
+ }));
129
+ }
130
+
45
131
  // src/fonts.ts
46
132
  var GENERIC_FAMILIES = /* @__PURE__ */ new Set([
47
133
  "serif",
@@ -58,17 +144,18 @@ var GENERIC_FAMILIES = /* @__PURE__ */ new Set([
58
144
  "fangsong"
59
145
  ]);
60
146
  var OFFICE_FONT_FALLBACKS = {
61
- aptos: ["Aptos", "Segoe UI", "Arial", "sans-serif"],
147
+ aptos: ["Aptos", "Intos", "Segoe UI", "Arial", "sans-serif"],
148
+ "aptos narrow": ["Aptos Narrow", "Intos Narrow", "Arial", "sans-serif"],
62
149
  "aptos display": ["Aptos Display", "Segoe UI", "Arial", "sans-serif"],
63
150
  calibri: ["Calibri", "Carlito", "Arial", "sans-serif"],
64
151
  "calibri light": ["Calibri Light", "Carlito", "Arial", "sans-serif"],
65
152
  cambria: ["Cambria", "Caladea", "Georgia", "serif"],
66
153
  "cambria math": ["Cambria Math", "STIX Two Math", "STIXGeneral", "math"],
67
- arial: ["Arial", "Liberation Sans", "Helvetica", "sans-serif"],
154
+ arial: ["Arial", "Arimo", "Liberation Sans", "Helvetica", "sans-serif"],
68
155
  "arial narrow": ["Arial Narrow", "Liberation Sans Narrow", "Arial", "sans-serif"],
69
156
  "arial unicode ms": ["Arial Unicode MS", "Noto Sans", "Segoe UI Symbol", "sans-serif"],
70
- "times new roman": ["Times New Roman", "Liberation Serif", "Times", "serif"],
71
- "courier new": ["Courier New", "Liberation Mono", "Courier", "monospace"],
157
+ "times new roman": ["Times New Roman", "Tinos", "Liberation Serif", "Times", "serif"],
158
+ "courier new": ["Courier New", "Cousine", "Liberation Mono", "Courier", "monospace"],
72
159
  consolas: ["Consolas", "Cascadia Mono", "Liberation Mono", "monospace"],
73
160
  "century gothic": ["Century Gothic", "Avenir Next", "Futura", "Arial", "sans-serif"],
74
161
  "franklin gothic medium": ["Franklin Gothic Medium", "Arial", "sans-serif"],
@@ -142,9 +229,9 @@ function serializeFamily(family) {
142
229
  if (GENERIC_FAMILIES.has(family.toLowerCase())) return family;
143
230
  return `"${family.replaceAll('"', '\\"')}"`;
144
231
  }
145
- function uniqueFamilies(families) {
232
+ function uniqueFamilies(families2) {
146
233
  const seen = /* @__PURE__ */ new Set();
147
- return families.filter((family) => {
234
+ return families2.filter((family) => {
148
235
  const key = normalizeFamily(family).toLowerCase();
149
236
  if (!key || seen.has(key)) return false;
150
237
  seen.add(key);
@@ -153,14 +240,14 @@ function uniqueFamilies(families) {
153
240
  }
154
241
  function resolvePptxFontFamily(fontFamily2, options = {}) {
155
242
  const requested = parseFamilyList(fontFamily2);
156
- const primary = requested[0] ?? "";
157
- const configured = options.fallbacks?.[primary] ?? options.fallbacks?.[primary.toLowerCase()];
243
+ const primary2 = requested[0] ?? "";
244
+ const configured = options.fallbacks?.[primary2] ?? options.fallbacks?.[primary2.toLowerCase()];
158
245
  const configuredList = typeof configured === "string" ? [configured] : configured ?? [];
159
- const office = options.useOfficeFallbacks === false ? [] : OFFICE_FONT_FALLBACKS[primary.toLowerCase()] ?? [];
160
- const lower = primary.toLowerCase();
246
+ const office = options.useOfficeFallbacks === false ? [] : OFFICE_FONT_FALLBACKS[primary2.toLowerCase()] ?? [];
247
+ const lower = primary2.toLowerCase();
161
248
  const generic = /serif|times|cambria|mincho|ming|song|batang|david|garamond|palatino/.test(lower) ? ["Noto Serif", "Noto Serif CJK SC", "serif"] : [...UNIVERSAL_SANS_FALLBACKS];
162
249
  return uniqueFamilies([
163
- ...primary ? [primary] : [],
250
+ ...primary2 ? [primary2] : [],
164
251
  ...configuredList,
165
252
  ...office,
166
253
  ...requested.slice(1),
@@ -269,6 +356,27 @@ var PptxFontManager = class {
269
356
  message: `The supplied font \u201C${family}\u201D could not be loaded; a compatible fallback will be used.`
270
357
  });
271
358
  });
359
+ if (this.options.useOfficeFallbacks !== false) {
360
+ const families2 = /* @__PURE__ */ new Set(["Calibri"]);
361
+ const seen = /* @__PURE__ */ new Set();
362
+ const collect = (value) => {
363
+ if (!value || typeof value !== "object" || seen.has(value)) return;
364
+ seen.add(value);
365
+ for (const [key, child] of Object.entries(value)) {
366
+ if (/fontFamily$/i.test(key) && typeof child === "string") families2.add(child);
367
+ else if (child && typeof child === "object") collect(child);
368
+ }
369
+ };
370
+ collect(presentation.slides);
371
+ collect(presentation.masters);
372
+ collect(presentation.layouts);
373
+ for (const theme of presentation.themes) {
374
+ for (const family of [...Object.values(theme.majorFonts ?? {}), ...Object.values(theme.minorFonts ?? {})]) {
375
+ if (family) families2.add(family);
376
+ }
377
+ }
378
+ await loadOfficeFonts(document, families2).catch(() => void 0);
379
+ }
272
380
  if (document.fonts && this.options.waitForFonts !== false) {
273
381
  await timeout(
274
382
  Promise.resolve(document.fonts.ready).then(() => void 0),
@@ -285,21 +393,21 @@ var PptxFontManager = class {
285
393
  for (const element of elements2) {
286
394
  const raw = (element instanceof HTMLElement || element instanceof SVGElement ? element.style.fontFamily : "") || element.getAttribute("font-family");
287
395
  if (!raw) continue;
288
- const primary = parseFamilyList(raw)[0];
289
- if (!primary || primary.startsWith("+") || GENERIC_FAMILIES.has(primary.toLowerCase()))
396
+ const primary2 = parseFamilyList(raw)[0];
397
+ if (!primary2 || primary2.startsWith("+") || GENERIC_FAMILIES.has(primary2.toLowerCase()))
290
398
  continue;
291
399
  if (element instanceof HTMLElement || element instanceof SVGElement) {
292
400
  element.style.fontFamily = resolvePptxFontFamily(raw, this.options);
293
401
  }
294
- if (this.options.reportMissingFonts === false || this.loadedFamilies.has(primary.toLowerCase()) || browserHasFont(primary)) {
402
+ if (this.options.reportMissingFonts === false || this.loadedFamilies.has(primary2.toLowerCase()) || browserHasFont(primary2)) {
295
403
  continue;
296
404
  }
297
405
  this.warn({
298
406
  code: "missing-font",
299
407
  severity: "warning",
300
- feature: primary,
408
+ feature: primary2,
301
409
  ...slideIndex === void 0 ? {} : { slideIndex },
302
- message: `Font \u201C${primary}\u201D is not available in this browser; the configured fallback stack is being used.`
410
+ message: `Font \u201C${primary2}\u201D is not available in this browser; the configured fallback stack is being used.`
303
411
  });
304
412
  }
305
413
  }
@@ -3377,11 +3485,11 @@ function getCategoryLabels(chart) {
3377
3485
  return series.categories.every((value) => normalizeCategoryLabel(value).length === 0);
3378
3486
  }) || !hasAnyExplicitCategory;
3379
3487
  return Array.from({ length: categoryCount }, (_, categoryIndex) => {
3380
- const primary = primaryCategories[categoryIndex];
3381
- if (primary != null) {
3382
- const normalizedPrimary = normalizeCategoryLabel(primary);
3488
+ const primary2 = primaryCategories[categoryIndex];
3489
+ if (primary2 != null) {
3490
+ const normalizedPrimary = normalizeCategoryLabel(primary2);
3383
3491
  if (normalizedPrimary.length > 0) {
3384
- return formatCategoryLabel(chart, primary, normalizedPrimary);
3492
+ return formatCategoryLabel(chart, primary2, normalizedPrimary);
3385
3493
  }
3386
3494
  }
3387
3495
  const fallback = chart.series.map((series) => series.categories[categoryIndex]).find((value) => normalizeCategoryLabel(value).length > 0);
@@ -9507,10 +9615,10 @@ function runFontFamily(run) {
9507
9615
  run.complexScriptFontFamily,
9508
9616
  run.symbolFontFamily
9509
9617
  ];
9510
- const families = ordered.filter(
9618
+ const families2 = ordered.filter(
9511
9619
  (family, index) => Boolean(family) && ordered.indexOf(family) === index
9512
9620
  );
9513
- return families.length > 0 ? families.join(", ") : void 0;
9621
+ return families2.length > 0 ? families2.join(", ") : void 0;
9514
9622
  }
9515
9623
  function createTextRunElement(run, paragraph, fontScale) {
9516
9624
  const href = safeHyperlink(run.hyperlink);