@json-to-office/shared 1.11.2 → 2.6.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
@@ -38,18 +38,6 @@ import {
38
38
  transformValueError,
39
39
  transformValueErrors
40
40
  } from "./chunk-LLBCT7WL.js";
41
- import {
42
- FeatureRequirementCollector,
43
- RENDERER_DEPENDENCY_MISSING,
44
- RendererRegistry,
45
- UnsupportedRendererFeatureError,
46
- assertNever,
47
- assertRendererSupports,
48
- diagnoseUnsupportedFeatures,
49
- partitionDiagnostics,
50
- rendererError,
51
- rendererWarning
52
- } from "./chunk-QLZNOXT5.js";
53
41
  import {
54
42
  convertToJsonSchema,
55
43
  createComponentSchema,
@@ -60,13 +48,45 @@ import {
60
48
  unionBranches
61
49
  } from "./chunk-6TNT7DGC.js";
62
50
  import {
51
+ CANVASES,
52
+ ChromeSchema,
53
+ DesignSpacingSchema,
54
+ DesignSystemProperties,
55
+ DesignSystemSchema,
63
56
  FontFamilyNameSchema,
64
57
  FontRegistryEntrySchema,
65
58
  FontRegistrySchema,
66
59
  FontSourceSchema,
60
+ MotifSchema,
61
+ PaletteSchema,
62
+ ROLE_SCALE_STEPS,
67
63
  SAFE_FONTS,
68
- isSafeFont
69
- } from "./chunk-6KUQYVPT.js";
64
+ TYPE_ROLES,
65
+ TextCaseSchema,
66
+ TypeRoleNameSchema,
67
+ TypeRoleSchema,
68
+ TypeRolesSchema,
69
+ TypographySchema,
70
+ capsFormatting,
71
+ designCanvas,
72
+ designColors,
73
+ isSafeFont,
74
+ resolveDesignColor,
75
+ resolveTypeRoles,
76
+ validateDesignColors
77
+ } from "./chunk-4MJFAJFW.js";
78
+ import {
79
+ FeatureRequirementCollector,
80
+ RENDERER_DEPENDENCY_MISSING,
81
+ RendererRegistry,
82
+ UnsupportedRendererFeatureError,
83
+ assertNever,
84
+ assertRendererSupports,
85
+ diagnoseUnsupportedFeatures,
86
+ partitionDiagnostics,
87
+ rendererError,
88
+ rendererWarning
89
+ } from "./chunk-QLZNOXT5.js";
70
90
  import {
71
91
  compareSemver,
72
92
  isValidSemver,
@@ -220,21 +240,21 @@ var WEIGHT_LABELS = {
220
240
  800: "ExtraBold",
221
241
  900: "Black"
222
242
  };
223
- function synthesizeFamilyName(family, weight, italic) {
224
- if (weight == null) {
243
+ function synthesizeFamilyName(family, weight2, italic) {
244
+ if (weight2 == null) {
225
245
  return { family, bold: false, italic, nonCanonicalWeight: false };
226
246
  }
227
- if (weight === 400) {
247
+ if (weight2 === 400) {
228
248
  return { family, bold: false, italic, nonCanonicalWeight: false };
229
249
  }
230
- if (weight === 700) {
250
+ if (weight2 === 700) {
231
251
  return { family, bold: true, italic, nonCanonicalWeight: false };
232
252
  }
233
- const label = WEIGHT_LABELS[weight];
253
+ const label = WEIGHT_LABELS[weight2];
234
254
  if (!label) {
235
255
  return {
236
256
  family,
237
- bold: weight >= 600,
257
+ bold: weight2 >= 600,
238
258
  italic,
239
259
  nonCanonicalWeight: true
240
260
  };
@@ -333,8 +353,8 @@ function parseCssFaces(css) {
333
353
  }
334
354
  return out;
335
355
  }
336
- function cacheKey(family, weight, italic) {
337
- return `google|${family}|${weight}|${italic ? "i" : "r"}`;
356
+ function cacheKey(family, weight2, italic) {
357
+ return `google|${family}|${weight2}|${italic ? "i" : "r"}`;
338
358
  }
339
359
  async function fetchGoogleFontSources(opts) {
340
360
  const weights = opts.weights?.length ? opts.weights : [400, 700];
@@ -444,8 +464,8 @@ async function fetchGoogleFontSources(opts) {
444
464
  }
445
465
 
446
466
  // src/fonts/sources/url-fetcher.ts
447
- function cacheKey2(url, weight, italic) {
448
- return `url|${url}|${weight}|${italic ? "i" : "r"}`;
467
+ function cacheKey2(url, weight2, italic) {
468
+ return `url|${url}|${weight2}|${italic ? "i" : "r"}`;
449
469
  }
450
470
  async function fetchUrlFontSource(opts) {
451
471
  if (!isAllowedFontUrl(opts.url)) {
@@ -572,25 +592,25 @@ function readUsWeightClass(ttf) {
572
592
  if (os2.off + 6 > ttf.length) return null;
573
593
  return ttf.readUInt16BE(os2.off + 4);
574
594
  }
575
- function validateFontMetadata(ttf, weight, italic, familyLabel) {
595
+ function validateFontMetadata(ttf, weight2, italic, familyLabel) {
576
596
  const diags = [];
577
597
  const usWeight = readUsWeightClass(ttf);
578
- if (usWeight != null && usWeight !== weight) {
598
+ if (usWeight != null && usWeight !== weight2) {
579
599
  diags.push({
580
600
  code: "WEIGHT_CLASS_MISMATCH",
581
- message: `Font "${familyLabel}" weight ${weight}: OS/2.usWeightClass reports ${usWeight}. Likely a defective redistribution \u2014 consider adding an upstream override.`
601
+ message: `Font "${familyLabel}" weight ${weight2}: OS/2.usWeightClass reports ${usWeight}. Likely a defective redistribution \u2014 consider adding an upstream override.`
582
602
  });
583
603
  }
584
604
  const declaredFamilies = readFontFamilyNames(ttf);
585
605
  if (declaredFamilies.length > 0 && !declaredFamilies.includes(familyLabel.trim())) {
586
606
  diags.push({
587
607
  code: "FAMILY_MISMATCH",
588
- message: `Font "${familyLabel}" weight ${weight}${italic ? " italic" : ""}: name table declares ${declaredFamilies.map((f) => `"${f}"`).join(
608
+ message: `Font "${familyLabel}" weight ${weight2}${italic ? " italic" : ""}: name table declares ${declaredFamilies.map((f) => `"${f}"`).join(
589
609
  " / "
590
610
  )}, not "${familyLabel}". Referencing runs will not resolve this face.`
591
611
  });
592
612
  }
593
- const std = standardSubfamilyNames(weight, italic);
613
+ const std = standardSubfamilyNames(weight2, italic);
594
614
  if (!std) return diags;
595
615
  const expected17 = std.typographic;
596
616
  const expected2 = std.legacy;
@@ -599,13 +619,13 @@ function validateFontMetadata(ttf, weight, italic, familyLabel) {
599
619
  if (n.nameID === 17 && n.value !== expected17) {
600
620
  diags.push({
601
621
  code: "SUBFAMILY_MISMATCH",
602
- message: `Font "${familyLabel}" weight ${weight}${italic ? " italic" : ""}: name record (platform ${n.platformID}) nameID 17 = "${n.value}", expected "${expected17}".`
622
+ message: `Font "${familyLabel}" weight ${weight2}${italic ? " italic" : ""}: name record (platform ${n.platformID}) nameID 17 = "${n.value}", expected "${expected17}".`
603
623
  });
604
624
  }
605
625
  if (n.nameID === 2 && n.value !== expected2) {
606
626
  diags.push({
607
627
  code: "LEGACY_SUBFAMILY_MISMATCH",
608
- message: `Font "${familyLabel}" weight ${weight}${italic ? " italic" : ""}: name record (platform ${n.platformID}) nameID 2 = "${n.value}", expected "${expected2}".`
628
+ message: `Font "${familyLabel}" weight ${weight2}${italic ? " italic" : ""}: name record (platform ${n.platformID}) nameID 2 = "${n.value}", expected "${expected2}".`
609
629
  });
610
630
  }
611
631
  }
@@ -625,8 +645,8 @@ var SFNT_VERSIONS = /* @__PURE__ */ new Set([
625
645
  ]);
626
646
  var HEADER_SIZE2 = 12;
627
647
  var TABLE_RECORD_SIZE2 = 16;
628
- function validateFontStructure(ttf, weight, italic, familyLabel) {
629
- const face = `Font "${familyLabel}" weight ${weight}${italic ? " italic" : ""}`;
648
+ function validateFontStructure(ttf, weight2, italic, familyLabel) {
649
+ const face = `Font "${familyLabel}" weight ${weight2}${italic ? " italic" : ""}`;
630
650
  const unreadable = (reason) => ({
631
651
  code: "FONT_UNREADABLE",
632
652
  message: `${face}: ${reason} The face will not resolve; text referencing it renders in a fallback.`
@@ -1140,16 +1160,16 @@ var INTER_VARIABLE_URL = "https://cdn.jsdelivr.net/gh/rsms/inter@v4.1/docs/font-
1140
1160
  var INTER_VARIABLE_ITALIC_URL = "https://cdn.jsdelivr.net/gh/rsms/inter@v4.1/docs/font-files/InterVariable-Italic.woff2";
1141
1161
  function interVariants() {
1142
1162
  const weights = [100, 200, 300, 400, 500, 600, 700, 800, 900];
1143
- const upright = weights.map((weight) => ({
1163
+ const upright = weights.map((weight2) => ({
1144
1164
  kind: "variable",
1145
1165
  url: INTER_VARIABLE_URL,
1146
- weight,
1166
+ weight: weight2,
1147
1167
  italic: false
1148
1168
  }));
1149
- const italic = weights.map((weight) => ({
1169
+ const italic = weights.map((weight2) => ({
1150
1170
  kind: "variable",
1151
1171
  url: INTER_VARIABLE_ITALIC_URL,
1152
- weight,
1172
+ weight: weight2,
1153
1173
  italic: true
1154
1174
  }));
1155
1175
  return [...upright, ...italic];
@@ -1351,6 +1371,118 @@ var DEFAULT_CHART_THEME_COLORS = [
1351
1371
  "accent6"
1352
1372
  ];
1353
1373
 
1374
+ // src/theme/chart-typography.ts
1375
+ var POINTS_PER_PIXEL_96DPI = 0.75;
1376
+ function chartPointsPerPixel(chartWidthPx, placedWidthPt) {
1377
+ if (!Number.isFinite(chartWidthPx) || chartWidthPx <= 0 || placedWidthPt === void 0 || !Number.isFinite(placedWidthPt) || placedWidthPt <= 0) {
1378
+ return POINTS_PER_PIXEL_96DPI;
1379
+ }
1380
+ return placedWidthPt / chartWidthPx;
1381
+ }
1382
+ var SERIF_FAMILIES = /* @__PURE__ */ new Set(["georgia", "times new roman", "cambria"]);
1383
+ var MONO_FAMILIES = /* @__PURE__ */ new Set(["consolas", "courier new", "menlo", "monaco"]);
1384
+ function cssFontFamily(family, category) {
1385
+ const generic = category === "serif" ? "serif" : category === "mono" ? "monospace" : category === "handwriting" ? "cursive" : category === void 0 && SERIF_FAMILIES.has(family.toLowerCase()) ? "serif" : category === void 0 && MONO_FAMILIES.has(family.toLowerCase()) ? "monospace" : "sans-serif";
1386
+ return `"${family.replace(/["\\]/g, "\\$&")}", ${generic}`;
1387
+ }
1388
+ function chartFamilyResolver(theme) {
1389
+ const categories = new Map(
1390
+ themeFontRegistry(theme).map((entry) => [
1391
+ entry.family.toLowerCase(),
1392
+ entry.category
1393
+ ])
1394
+ );
1395
+ return (family) => cssFontFamily(family, categories.get(family.toLowerCase()));
1396
+ }
1397
+ function isPlainObject(value) {
1398
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1399
+ }
1400
+ function fill(authored, defaults) {
1401
+ if (authored !== void 0 && !isPlainObject(authored)) return authored;
1402
+ const base = isPlainObject(authored) ? { ...authored } : {};
1403
+ for (const [key, value] of Object.entries(defaults)) {
1404
+ if (value === void 0) continue;
1405
+ const current = base[key];
1406
+ if (current === void 0) {
1407
+ base[key] = isPlainObject(value) ? fill(void 0, value) : value;
1408
+ } else if (isPlainObject(current) && isPlainObject(value)) {
1409
+ base[key] = fill(current, value);
1410
+ }
1411
+ }
1412
+ return base;
1413
+ }
1414
+ function fillAxis(authored, defaults) {
1415
+ if (Array.isArray(authored)) {
1416
+ return authored.map((axis) => fill(axis, defaults));
1417
+ }
1418
+ return fill(authored, defaults);
1419
+ }
1420
+ function weight(value) {
1421
+ return value === void 0 ? void 0 : String(value);
1422
+ }
1423
+ function withChartTypography(options, typography, ptPerPx) {
1424
+ const px = (points) => `${Math.round(points / ptPerPx * 10) / 10}px`;
1425
+ const labelPx = px(typography.labelPt);
1426
+ const sourcePx = px(typography.sourcePt);
1427
+ const mutedText = { fontSize: labelPx, color: typography.mutedColor };
1428
+ const mutedSource = { fontSize: sourcePx, color: typography.mutedColor };
1429
+ const labelText = {
1430
+ fontSize: labelPx,
1431
+ color: typography.textColor,
1432
+ fontWeight: weight(typography.labelWeight)
1433
+ };
1434
+ const axis = { labels: { style: mutedText }, title: { style: mutedText } };
1435
+ return {
1436
+ ...options,
1437
+ chart: fill(options.chart, {
1438
+ style: { fontFamily: typography.bodyFamily }
1439
+ }),
1440
+ title: fill(options.title, {
1441
+ style: {
1442
+ fontFamily: typography.headingFamily,
1443
+ fontSize: px(typography.titlePt),
1444
+ fontWeight: weight(typography.titleWeight),
1445
+ color: typography.textColor
1446
+ }
1447
+ }),
1448
+ subtitle: fill(options.subtitle, { style: mutedText }),
1449
+ caption: fill(options.caption, { style: mutedSource }),
1450
+ xAxis: fillAxis(options.xAxis, axis),
1451
+ yAxis: fillAxis(options.yAxis, axis),
1452
+ legend: fill(options.legend, { itemStyle: labelText }),
1453
+ plotOptions: fill(options.plotOptions, {
1454
+ series: { dataLabels: { style: labelText } }
1455
+ }),
1456
+ credits: fill(options.credits, { style: mutedSource })
1457
+ };
1458
+ }
1459
+ var FONT_FORMATS = {
1460
+ ttf: { mime: "font/ttf", format: "truetype" },
1461
+ otf: { mime: "font/otf", format: "opentype" },
1462
+ woff: { mime: "font/woff", format: "woff" },
1463
+ woff2: { mime: "font/woff2", format: "woff2" }
1464
+ };
1465
+ function chartFontFaceCss(faces, families) {
1466
+ const wanted = new Set(families.map((family) => family.toLowerCase()));
1467
+ return faces.filter((face) => wanted.has(face.family.toLowerCase())).map((face) => {
1468
+ const { mime, format } = FONT_FORMATS[face.format ?? "ttf"];
1469
+ return `@font-face{font-family:"${face.family.replace(/["\\]/g, "\\$&")}";font-weight:${face.weight};font-style:${face.italic ? "italic" : "normal"};src:url(data:${mime};base64,${face.data}) format("${format}")}`;
1470
+ }).join("\n");
1471
+ }
1472
+ function withChartFontFaceCss(props, faces, families) {
1473
+ const css = chartFontFaceCss(faces, families);
1474
+ if (!css) return props;
1475
+ const authored = props.resources?.css;
1476
+ return {
1477
+ ...props,
1478
+ resources: {
1479
+ ...props.resources,
1480
+ css: authored ? `${css}
1481
+ ${authored}` : css
1482
+ }
1483
+ };
1484
+ }
1485
+
1354
1486
  // src/utils/deepMerge.ts
1355
1487
  function isObject(item) {
1356
1488
  return item !== null && typeof item === "object" && !Array.isArray(item);
@@ -1376,10 +1508,15 @@ function mergeWithDefaults(userConfig, themeDefaults) {
1376
1508
  return deepMerge(themeDefaults, userConfig);
1377
1509
  }
1378
1510
  export {
1511
+ CANVASES,
1512
+ ChromeSchema,
1379
1513
  ComponentValidationError,
1380
1514
  DEFAULT_CHART_THEME_COLORS,
1381
1515
  DEFAULT_ERROR_CONFIG,
1382
1516
  DEFAULT_VISUAL_DPI,
1517
+ DesignSpacingSchema,
1518
+ DesignSystemProperties,
1519
+ DesignSystemSchema,
1383
1520
  DuplicateComponentError,
1384
1521
  ERROR_EMOJIS,
1385
1522
  FONT_URL_ALLOWLIST,
@@ -1394,10 +1531,20 @@ export {
1394
1531
  MAX_RASTERIZE_FONT_BYTES,
1395
1532
  MAX_VISUAL_DPI,
1396
1533
  MIN_VISUAL_DPI,
1534
+ MotifSchema,
1535
+ POINTS_PER_PIXEL_96DPI,
1397
1536
  POPULAR_GOOGLE_FONTS,
1537
+ PaletteSchema,
1398
1538
  RENDERER_DEPENDENCY_MISSING,
1539
+ ROLE_SCALE_STEPS,
1399
1540
  RendererRegistry,
1400
1541
  SAFE_FONTS,
1542
+ TYPE_ROLES,
1543
+ TextCaseSchema,
1544
+ TypeRoleNameSchema,
1545
+ TypeRoleSchema,
1546
+ TypeRolesSchema,
1547
+ TypographySchema,
1401
1548
  UPSTREAM_OVERRIDES,
1402
1549
  UnknownPreservedComponentError,
1403
1550
  UnsupportedRendererFeatureError,
@@ -1408,6 +1555,10 @@ export {
1408
1555
  assertRendererSupports,
1409
1556
  buildDefaultSubstitutionMap,
1410
1557
  calculatePosition,
1558
+ capsFormatting,
1559
+ chartFamilyResolver,
1560
+ chartFontFaceCss,
1561
+ chartPointsPerPixel,
1411
1562
  clampVisualDpi,
1412
1563
  clearComponentNamesCache,
1413
1564
  collectFontNamesFromDocx,
@@ -1420,7 +1571,10 @@ export {
1420
1571
  createErrorConfig,
1421
1572
  createJsonParseError,
1422
1573
  createVersion,
1574
+ cssFontFamily,
1423
1575
  defaultSubstituteFor,
1576
+ designCanvas,
1577
+ designColors,
1424
1578
  detectFontFormat,
1425
1579
  diagnoseUnsupportedFeatures,
1426
1580
  documentFontRegistry,
@@ -1451,6 +1605,8 @@ export {
1451
1605
  rendererError,
1452
1606
  rendererWarning,
1453
1607
  resolveComponentVersion,
1608
+ resolveDesignColor,
1609
+ resolveTypeRoles,
1454
1610
  restructureNameDiscriminatedUnions,
1455
1611
  rewriteFontFamilyName,
1456
1612
  synthesizeFamilyName,
@@ -1459,6 +1615,9 @@ export {
1459
1615
  transformValueErrors,
1460
1616
  unionBranches,
1461
1617
  validateCustomComponentProps,
1462
- validateFontReferences
1618
+ validateDesignColors,
1619
+ validateFontReferences,
1620
+ withChartFontFaceCss,
1621
+ withChartTypography
1463
1622
  };
1464
1623
  //# sourceMappingURL=index.js.map