@json-to-office/shared 0.33.0 → 0.35.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/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
+ FONT_URL_ALLOWLIST,
2
3
  detectFontFormat,
3
4
  isAllowedFontUrl
4
- } from "./chunk-CP2I5NPP.js";
5
+ } from "./chunk-FDSJYZ5W.js";
5
6
  import {
6
7
  convertToJsonSchema,
7
8
  createComponentSchema,
@@ -66,6 +67,8 @@ function clampVisualDpi(dpi) {
66
67
  return DEFAULT_VISUAL_DPI;
67
68
  return Math.min(MAX_VISUAL_DPI, Math.max(MIN_VISUAL_DPI, Math.round(dpi)));
68
69
  }
70
+ var MAX_RASTERIZE_FONTS = 32;
71
+ var MAX_RASTERIZE_FONT_BYTES = 8 * 1024 * 1024;
69
72
  var MAX_RASTERIZE_BATCH_SLIDES = 32;
70
73
 
71
74
  // src/fonts/collect.ts
@@ -79,6 +82,7 @@ var FONT_NAME_KEYS = /* @__PURE__ */ new Set([
79
82
  "valAxisLabelFontFace"
80
83
  ]);
81
84
  var THEME_FONT_KEYS = /* @__PURE__ */ new Set(["heading", "body", "mono", "light"]);
85
+ var FONT_DECLARATION_KEYS = /* @__PURE__ */ new Set(["fontRegistry"]);
82
86
  function collect(node, out, parentKey) {
83
87
  if (node == null) return;
84
88
  if (typeof node === "string") {
@@ -111,6 +115,7 @@ function collect(node, out, parentKey) {
111
115
  }
112
116
  }
113
117
  for (const [k, v] of Object.entries(node)) {
118
+ if (FONT_DECLARATION_KEYS.has(k)) continue;
114
119
  collect(v, out, k);
115
120
  }
116
121
  }
@@ -123,6 +128,41 @@ function collectFontNames(doc) {
123
128
  var collectFontNamesFromDocx = collectFontNames;
124
129
  var collectFontNamesFromPptx = collectFontNames;
125
130
 
131
+ // src/fonts/document-registry.ts
132
+ function isEntry(v) {
133
+ if (!v || typeof v !== "object") return false;
134
+ const e = v;
135
+ return typeof e.id === "string" && typeof e.family === "string" && Array.isArray(e.sources);
136
+ }
137
+ function readAt(node, key) {
138
+ if (!node || typeof node !== "object") return [];
139
+ const raw = node[key];
140
+ return Array.isArray(raw) ? raw.filter(isEntry) : [];
141
+ }
142
+ function documentFontRegistry(document) {
143
+ if (!document || typeof document !== "object") return [];
144
+ return readAt(document.props, "fontRegistry");
145
+ }
146
+ function themeFontRegistry(theme) {
147
+ return readAt(theme, "fontRegistry");
148
+ }
149
+ function mergeFontRegistries(...groups) {
150
+ const out = [];
151
+ for (const group of groups) {
152
+ for (const entry of group ?? []) {
153
+ const family = entry.family.toLowerCase();
154
+ const id = entry.id.toLowerCase();
155
+ for (let i = out.length - 1; i >= 0; i--) {
156
+ if (out[i].family.toLowerCase() === family && out[i].id.toLowerCase() === id) {
157
+ out.splice(i, 1);
158
+ }
159
+ }
160
+ out.push(entry);
161
+ }
162
+ }
163
+ return out;
164
+ }
165
+
126
166
  // src/fonts/validator.ts
127
167
  function buildRegistryIndex(registeredEntries) {
128
168
  const idx = /* @__PURE__ */ new Set();
@@ -1044,6 +1084,24 @@ var POPULAR_GOOGLE_FONTS = [
1044
1084
  weights: [100, 200, 300, 400, 500, 600, 700],
1045
1085
  hasItalic: true
1046
1086
  },
1087
+ {
1088
+ family: "Archivo",
1089
+ category: "sans",
1090
+ weights: [100, 200, 300, 400, 500, 600, 700, 800, 900],
1091
+ hasItalic: true
1092
+ },
1093
+ {
1094
+ family: "Geist",
1095
+ category: "sans",
1096
+ weights: [100, 200, 300, 400, 500, 600, 700, 800, 900],
1097
+ hasItalic: true
1098
+ },
1099
+ {
1100
+ family: "Space Grotesk",
1101
+ category: "sans",
1102
+ weights: [300, 400, 500, 600, 700],
1103
+ hasItalic: false
1104
+ },
1047
1105
  // Serif
1048
1106
  {
1049
1107
  family: "Playfair Display",
@@ -1118,6 +1176,12 @@ var POPULAR_GOOGLE_FONTS = [
1118
1176
  weights: [400, 700],
1119
1177
  hasItalic: true
1120
1178
  },
1179
+ {
1180
+ family: "Geist Mono",
1181
+ category: "mono",
1182
+ weights: [100, 200, 300, 400, 500, 600, 700, 800, 900],
1183
+ hasItalic: true
1184
+ },
1121
1185
  // Display
1122
1186
  {
1123
1187
  family: "Bebas Neue",
@@ -1209,6 +1273,10 @@ function rewrite(node, mapping, seen, parentKey) {
1209
1273
  if (typeof node === "object") {
1210
1274
  const out = {};
1211
1275
  for (const [k, v] of Object.entries(node)) {
1276
+ if (FONT_DECLARATION_KEYS.has(k)) {
1277
+ out[k] = v;
1278
+ continue;
1279
+ }
1212
1280
  if (parentKey === "theme" && k === "fonts" && v && typeof v === "object") {
1213
1281
  const nextFonts = {};
1214
1282
  for (const [fk, fv] of Object.entries(v)) {
@@ -1251,6 +1319,9 @@ var EXPLICIT_OVERRIDES = {
1251
1319
  "Source Sans 3": "Calibri",
1252
1320
  "Source Sans Pro": "Calibri",
1253
1321
  "IBM Plex Sans": "Calibri",
1322
+ Archivo: "Calibri",
1323
+ Geist: "Calibri",
1324
+ "Space Grotesk": "Calibri",
1254
1325
  "Work Sans": "Calibri",
1255
1326
  Manrope: "Calibri",
1256
1327
  Nunito: "Calibri",
@@ -1270,7 +1341,8 @@ var EXPLICIT_OVERRIDES = {
1270
1341
  "Fira Code": "Consolas",
1271
1342
  "IBM Plex Mono": "Consolas",
1272
1343
  "Source Code Pro": "Consolas",
1273
- "Roboto Mono": "Consolas"
1344
+ "Roboto Mono": "Consolas",
1345
+ "Geist Mono": "Consolas"
1274
1346
  };
1275
1347
  var CATEGORY_FALLBACK = {
1276
1348
  sans: "Calibri",
@@ -1400,12 +1472,15 @@ export {
1400
1472
  DEFAULT_VISUAL_DPI,
1401
1473
  DuplicateComponentError,
1402
1474
  ERROR_EMOJIS,
1475
+ FONT_URL_ALLOWLIST,
1403
1476
  FontFamilyNameSchema,
1404
1477
  FontRegistry,
1405
1478
  FontRegistryEntrySchema,
1406
1479
  FontRegistrySchema,
1407
1480
  FontSourceSchema,
1408
1481
  MAX_RASTERIZE_BATCH_SLIDES,
1482
+ MAX_RASTERIZE_FONTS,
1483
+ MAX_RASTERIZE_FONT_BYTES,
1409
1484
  MAX_VISUAL_DPI,
1410
1485
  MIN_VISUAL_DPI,
1411
1486
  POPULAR_GOOGLE_FONTS,
@@ -1431,6 +1506,7 @@ export {
1431
1506
  createVersion,
1432
1507
  defaultSubstituteFor,
1433
1508
  detectFontFormat,
1509
+ documentFontRegistry,
1434
1510
  exportSchemaToFile,
1435
1511
  extractStandardComponentNames,
1436
1512
  fetchGoogleFontSources,
@@ -1443,6 +1519,7 @@ export {
1443
1519
  getUpstreamOverride,
1444
1520
  getValidationSummary,
1445
1521
  groupErrorsByPath,
1522
+ isAllowedFontUrl,
1446
1523
  isLiteralSchema,
1447
1524
  isObjectSchema,
1448
1525
  isSafeFont,
@@ -1450,6 +1527,7 @@ export {
1450
1527
  isValidSemver,
1451
1528
  isValidationSuccess,
1452
1529
  latestVersion,
1530
+ mergeFontRegistries,
1453
1531
  mergeWithDefaults,
1454
1532
  parseSemver,
1455
1533
  resolveComponentVersion,
@@ -1457,6 +1535,7 @@ export {
1457
1535
  rewriteFontFamilyName,
1458
1536
  scopedThemeName,
1459
1537
  synthesizeFamilyName,
1538
+ themeFontRegistry,
1460
1539
  transformValueError,
1461
1540
  transformValueErrors,
1462
1541
  unionBranches,