@json-to-office/shared 1.4.0 → 1.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
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  FONT_URL_ALLOWLIST,
3
3
  detectFontFormat,
4
- isAllowedFontUrl
5
- } from "./chunk-FDSJYZ5W.js";
4
+ isAllowedFontUrl,
5
+ rewriteFontFamilyName,
6
+ standardSubfamilyNames
7
+ } from "./chunk-MCUIFSUN.js";
6
8
  import {
7
9
  ComponentValidationError,
8
10
  DuplicateComponentError,
@@ -13,7 +15,7 @@ import {
13
15
  isValidationSuccess,
14
16
  resolveComponentVersion,
15
17
  validateCustomComponentProps
16
- } from "./chunk-GPNPMKVZ.js";
18
+ } from "./chunk-A4CY2MAM.js";
17
19
  import {
18
20
  DEFAULT_ERROR_CONFIG,
19
21
  ERROR_EMOJIS,
@@ -33,7 +35,19 @@ import {
33
35
  isUnionSchema,
34
36
  transformValueError,
35
37
  transformValueErrors
36
- } from "./chunk-ZKD5BAMU.js";
38
+ } from "./chunk-LLBCT7WL.js";
39
+ import {
40
+ FeatureRequirementCollector,
41
+ RENDERER_DEPENDENCY_MISSING,
42
+ RendererRegistry,
43
+ UnsupportedRendererFeatureError,
44
+ assertNever,
45
+ assertRendererSupports,
46
+ diagnoseUnsupportedFeatures,
47
+ partitionDiagnostics,
48
+ rendererError,
49
+ rendererWarning
50
+ } from "./chunk-QLZNOXT5.js";
37
51
  import {
38
52
  convertToJsonSchema,
39
53
  createComponentSchema,
@@ -51,18 +65,6 @@ import {
51
65
  SAFE_FONTS,
52
66
  isSafeFont
53
67
  } from "./chunk-6KUQYVPT.js";
54
- import {
55
- FeatureRequirementCollector,
56
- RENDERER_DEPENDENCY_MISSING,
57
- RendererRegistry,
58
- UnsupportedRendererFeatureError,
59
- assertNever,
60
- assertRendererSupports,
61
- diagnoseUnsupportedFeatures,
62
- partitionDiagnostics,
63
- rendererError,
64
- rendererWarning
65
- } from "./chunk-QLZNOXT5.js";
66
68
  import {
67
69
  compareSemver,
68
70
  isValidSemver,
@@ -244,172 +246,6 @@ function synthesizeFamilyName(family, weight, italic) {
244
246
  };
245
247
  }
246
248
 
247
- // src/fonts/sources/ttf-name.ts
248
- var TARGET_NAME_IDS = /* @__PURE__ */ new Set([
249
- 1,
250
- // Font Family
251
- 4,
252
- // Full Font Name
253
- 6,
254
- // PostScript Name
255
- 16
256
- // Typographic/Preferred Family
257
- ]);
258
- var MAGIC_HEAD_CHECKSUM = 2981146554;
259
- function sfntChecksum(buf) {
260
- let sum = 0;
261
- const end = buf.length;
262
- const aligned = end - end % 4;
263
- for (let i = 0; i < aligned; i += 4) {
264
- sum = sum + buf.readUInt32BE(i) >>> 0;
265
- }
266
- if (aligned < end) {
267
- let chunk = 0;
268
- const remaining = end - aligned;
269
- if (remaining >= 1) chunk |= buf[aligned] << 24;
270
- if (remaining >= 2) chunk |= buf[aligned + 1] << 16;
271
- if (remaining >= 3) chunk |= buf[aligned + 2] << 8;
272
- sum = sum + chunk >>> 0;
273
- }
274
- return sum >>> 0;
275
- }
276
- function encodeString(record, value) {
277
- if (record.platformID === 1) {
278
- return Buffer.from(value, "ascii");
279
- }
280
- const out = Buffer.alloc(value.length * 2);
281
- for (let i = 0; i < value.length; i += 1) {
282
- out.writeUInt16BE(value.charCodeAt(i), i * 2);
283
- }
284
- return out;
285
- }
286
- function buildNameTable(records) {
287
- const count = records.length;
288
- const headerSize = 6 + count * 12;
289
- let heapSize = 0;
290
- for (const r of records) heapSize += r.bytes.length;
291
- const raw = Buffer.alloc(headerSize + heapSize);
292
- raw.writeUInt16BE(0, 0);
293
- raw.writeUInt16BE(count, 2);
294
- raw.writeUInt16BE(headerSize, 4);
295
- let heapCursor = 0;
296
- for (let i = 0; i < count; i += 1) {
297
- const r = records[i];
298
- const ro = 6 + i * 12;
299
- raw.writeUInt16BE(r.platformID, ro);
300
- raw.writeUInt16BE(r.encodingID, ro + 2);
301
- raw.writeUInt16BE(r.languageID, ro + 4);
302
- raw.writeUInt16BE(r.nameID, ro + 6);
303
- raw.writeUInt16BE(r.bytes.length, ro + 8);
304
- raw.writeUInt16BE(heapCursor, ro + 10);
305
- r.bytes.copy(raw, headerSize + heapCursor);
306
- heapCursor += r.bytes.length;
307
- }
308
- return raw;
309
- }
310
- function rewriteFontFamilyName(input, newFamily) {
311
- if (input.length < 12) return input;
312
- const version = input.readUInt32BE(0);
313
- const isSfnt = version === 65536 || version === 1330926671 || version === 1953658213 || version === 1954115633;
314
- if (!isSfnt) return input;
315
- const numTables = input.readUInt16BE(4);
316
- if (numTables === 0 || input.length < 12 + numTables * 16) return input;
317
- const tables = [];
318
- for (let i = 0; i < numTables; i += 1) {
319
- const eo = 12 + i * 16;
320
- const tag = input.toString("ascii", eo, eo + 4);
321
- const checksum = input.readUInt32BE(eo + 4);
322
- const offset = input.readUInt32BE(eo + 8);
323
- const length = input.readUInt32BE(eo + 12);
324
- if (offset + length > input.length) return input;
325
- tables.push({
326
- tag,
327
- checksum,
328
- offset: 0,
329
- originalOffset: offset,
330
- data: input.slice(offset, offset + length)
331
- });
332
- }
333
- const nameIdx = tables.findIndex((t) => t.tag === "name");
334
- if (nameIdx === -1) return input;
335
- const nameBuf = tables[nameIdx].data;
336
- if (nameBuf.length < 6) return input;
337
- const recordCount = nameBuf.readUInt16BE(2);
338
- const stringOffset = nameBuf.readUInt16BE(4);
339
- if (nameBuf.length < 6 + recordCount * 12) return input;
340
- const records = [];
341
- for (let i = 0; i < recordCount; i += 1) {
342
- const ro = 6 + i * 12;
343
- const platformID = nameBuf.readUInt16BE(ro);
344
- const encodingID = nameBuf.readUInt16BE(ro + 2);
345
- const languageID = nameBuf.readUInt16BE(ro + 4);
346
- const nameID = nameBuf.readUInt16BE(ro + 6);
347
- const length = nameBuf.readUInt16BE(ro + 8);
348
- const offset = nameBuf.readUInt16BE(ro + 10);
349
- const bytes = nameBuf.slice(
350
- stringOffset + offset,
351
- stringOffset + offset + length
352
- );
353
- records.push({ platformID, encodingID, languageID, nameID, bytes });
354
- }
355
- const psForbidden = /[[\](){}<>/%]/g;
356
- const isAscii = /^[\x00-\x7f]*$/.test(newFamily);
357
- const survivors = [];
358
- for (const r of records) {
359
- if (!TARGET_NAME_IDS.has(r.nameID)) {
360
- survivors.push(r);
361
- continue;
362
- }
363
- if (r.platformID === 1 && !isAscii) {
364
- continue;
365
- }
366
- const value = r.nameID === 6 ? newFamily.replace(/\s+/g, "").replace(psForbidden, "").replace(/[^\x21-\x7e]/g, "") : newFamily;
367
- r.bytes = encodeString(r, value);
368
- survivors.push(r);
369
- }
370
- records.length = 0;
371
- records.push(...survivors);
372
- const rebuiltName = buildNameTable(records);
373
- tables[nameIdx] = {
374
- ...tables[nameIdx],
375
- data: rebuiltName,
376
- checksum: sfntChecksum(rebuiltName)
377
- };
378
- tables.sort((a, b) => a.originalOffset - b.originalOffset);
379
- let cursor = 12 + tables.length * 16;
380
- for (const t of tables) {
381
- cursor = cursor + 3 & ~3;
382
- t.offset = cursor;
383
- cursor += t.data.length;
384
- }
385
- const totalSize = cursor + 3 & ~3;
386
- const out = Buffer.alloc(totalSize);
387
- input.copy(out, 0, 0, 12);
388
- out.writeUInt16BE(tables.length, 4);
389
- const dirTables = [...tables].sort(
390
- (a, b) => a.tag < b.tag ? -1 : a.tag > b.tag ? 1 : 0
391
- );
392
- for (let i = 0; i < dirTables.length; i += 1) {
393
- const t = dirTables[i];
394
- const eo = 12 + i * 16;
395
- out.write(t.tag, eo, 4, "ascii");
396
- out.writeUInt32BE(t.checksum, eo + 4);
397
- out.writeUInt32BE(t.offset, eo + 8);
398
- out.writeUInt32BE(t.data.length, eo + 12);
399
- }
400
- for (const t of tables) {
401
- t.data.copy(out, t.offset);
402
- }
403
- const headTable = tables.find((t) => t.tag === "head");
404
- if (headTable && headTable.data.length >= 12) {
405
- out.writeUInt32BE(0, headTable.offset + 8);
406
- const fontSum = sfntChecksum(out);
407
- const adjustment = MAGIC_HEAD_CHECKSUM - fontSum >>> 0;
408
- out.writeUInt32BE(adjustment, headTable.offset + 8);
409
- }
410
- return out;
411
- }
412
-
413
249
  // src/fonts/sources/data-loader.ts
414
250
  var MAX_DATA_FONT_BYTES = 5 * 1024 * 1024;
415
251
  function loadDataFontSource(input) {
@@ -764,17 +600,6 @@ function readNames(ttf, wanted) {
764
600
  }
765
601
  return out;
766
602
  }
767
- var STANDARD_SUBFAMILY = {
768
- 100: "Thin",
769
- 200: "ExtraLight",
770
- 300: "Light",
771
- 400: "Regular",
772
- 500: "Medium",
773
- 600: "SemiBold",
774
- 700: "Bold",
775
- 800: "ExtraBold",
776
- 900: "Black"
777
- };
778
603
  function validateFontMetadata(ttf, weight, italic, familyLabel) {
779
604
  const diags = [];
780
605
  const usWeight = readUsWeightClass(ttf);
@@ -784,10 +609,10 @@ function validateFontMetadata(ttf, weight, italic, familyLabel) {
784
609
  message: `Font "${familyLabel}" weight ${weight}: OS/2.usWeightClass reports ${usWeight}. Likely a defective redistribution \u2014 consider adding an upstream override.`
785
610
  });
786
611
  }
787
- const subfamily = STANDARD_SUBFAMILY[weight];
788
- if (!subfamily) return diags;
789
- const expected17 = italic ? `${subfamily} Italic` : subfamily;
790
- const expected2 = weight >= 600 ? italic ? "Bold Italic" : "Bold" : italic ? "Italic" : "Regular";
612
+ const std = standardSubfamilyNames(weight, italic);
613
+ if (!std) return diags;
614
+ const expected17 = std.typographic;
615
+ const expected2 = std.legacy;
791
616
  const names = readNames(ttf, /* @__PURE__ */ new Set([2, 17]));
792
617
  for (const n of names) {
793
618
  if (n.nameID === 17 && n.value !== expected17) {
@@ -1236,7 +1061,7 @@ var POPULAR_GOOGLE_FONTS = [
1236
1061
 
1237
1062
  // src/fonts/catalog/upstream-overrides.ts
1238
1063
  var INTER_VARIABLE_URL = "https://cdn.jsdelivr.net/gh/rsms/inter@v4.1/docs/font-files/InterVariable.ttf";
1239
- var INTER_VARIABLE_ITALIC_URL = "https://cdn.jsdelivr.net/gh/rsms/inter@v4.1/docs/font-files/InterVariable-Italic.ttf";
1064
+ var INTER_VARIABLE_ITALIC_URL = "https://cdn.jsdelivr.net/gh/rsms/inter@v4.1/docs/font-files/InterVariable-Italic.woff2";
1240
1065
  function interVariants() {
1241
1066
  const weights = [100, 200, 300, 400, 500, 600, 700, 800, 900];
1242
1067
  const upright = weights.map((weight) => ({
@@ -1459,7 +1284,7 @@ function deepMerge(target, source) {
1459
1284
  if (isObject(target) && isObject(source)) {
1460
1285
  Object.keys(source).forEach((key) => {
1461
1286
  if (isObject(source[key])) {
1462
- if (!(key in target)) {
1287
+ if (!(key in target) || !isObject(target[key])) {
1463
1288
  output[key] = source[key];
1464
1289
  } else {
1465
1290
  output[key] = deepMerge(target[key], source[key]);