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