@shotstack/shotstack-canvas 1.5.8 → 1.5.9

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.
@@ -397,6 +397,37 @@ async function initHB(wasmBaseURL) {
397
397
 
398
398
  // src/core/font-registry.ts
399
399
  var fontkit = __toESM(require("fontkit"), 1);
400
+ function normalizeWeight(weight) {
401
+ if (weight === void 0 || weight === null) return "400";
402
+ if (typeof weight === "number") return String(weight);
403
+ const lowerWeight = String(weight).toLowerCase().trim();
404
+ const weightMap = {
405
+ thin: "100",
406
+ hairline: "100",
407
+ extralight: "200",
408
+ ultralight: "200",
409
+ light: "300",
410
+ normal: "400",
411
+ regular: "400",
412
+ medium: "500",
413
+ semibold: "600",
414
+ demibold: "600",
415
+ bold: "700",
416
+ extrabold: "800",
417
+ ultrabold: "800",
418
+ black: "900",
419
+ heavy: "900"
420
+ };
421
+ if (weightMap[lowerWeight]) {
422
+ return weightMap[lowerWeight];
423
+ }
424
+ const numWeight = parseInt(String(weight), 10);
425
+ if (!isNaN(numWeight) && numWeight >= 100 && numWeight <= 900) {
426
+ return String(numWeight);
427
+ }
428
+ console.warn(`Invalid font weight "${weight}", defaulting to 400`);
429
+ return "400";
430
+ }
400
431
  var FontRegistry = class _FontRegistry {
401
432
  hb;
402
433
  faces = /* @__PURE__ */ new Map();
@@ -454,7 +485,8 @@ var FontRegistry = class _FontRegistry {
454
485
  return this.hb;
455
486
  }
456
487
  key(desc) {
457
- return `${desc.family}__${desc.weight ?? "400"}`;
488
+ const normalizedWeight = normalizeWeight(desc.weight);
489
+ return `${desc.family}__${normalizedWeight}`;
458
490
  }
459
491
  async registerFromBytes(bytes, desc) {
460
492
  try {
@@ -466,8 +498,8 @@ var FontRegistry = class _FontRegistry {
466
498
  const font = this.hb.createFont(face);
467
499
  const upem = face.upem || 1e3;
468
500
  font.setScale(upem, upem);
469
- const weight = desc.weight ?? "400";
470
- const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
501
+ const normalizedWeight = normalizeWeight(desc.weight);
502
+ const weightNum = parseInt(normalizedWeight, 10);
471
503
  if (weightNum !== 400 && typeof font.setVariations === "function") {
472
504
  try {
473
505
  font.setVariations(`wght=${weightNum}`);
@@ -501,14 +533,15 @@ var FontRegistry = class _FontRegistry {
501
533
  const loader = _FontRegistry.fallbackLoader;
502
534
  if (!loader) return false;
503
535
  try {
536
+ const normalizedWeight = normalizeWeight(desc.weight);
504
537
  const bytes = await loader({
505
538
  family: desc.family,
506
- weight: desc.weight ?? "400"
539
+ weight: normalizedWeight
507
540
  });
508
541
  if (!bytes) return false;
509
542
  await this.registerFromBytes(bytes, {
510
543
  family: desc.family,
511
- weight: desc.weight ?? "400"
544
+ weight: normalizedWeight
512
545
  });
513
546
  return true;
514
547
  } catch {
@@ -358,6 +358,37 @@ async function initHB(wasmBaseURL) {
358
358
 
359
359
  // src/core/font-registry.ts
360
360
  import * as fontkit from "fontkit";
361
+ function normalizeWeight(weight) {
362
+ if (weight === void 0 || weight === null) return "400";
363
+ if (typeof weight === "number") return String(weight);
364
+ const lowerWeight = String(weight).toLowerCase().trim();
365
+ const weightMap = {
366
+ thin: "100",
367
+ hairline: "100",
368
+ extralight: "200",
369
+ ultralight: "200",
370
+ light: "300",
371
+ normal: "400",
372
+ regular: "400",
373
+ medium: "500",
374
+ semibold: "600",
375
+ demibold: "600",
376
+ bold: "700",
377
+ extrabold: "800",
378
+ ultrabold: "800",
379
+ black: "900",
380
+ heavy: "900"
381
+ };
382
+ if (weightMap[lowerWeight]) {
383
+ return weightMap[lowerWeight];
384
+ }
385
+ const numWeight = parseInt(String(weight), 10);
386
+ if (!isNaN(numWeight) && numWeight >= 100 && numWeight <= 900) {
387
+ return String(numWeight);
388
+ }
389
+ console.warn(`Invalid font weight "${weight}", defaulting to 400`);
390
+ return "400";
391
+ }
361
392
  var FontRegistry = class _FontRegistry {
362
393
  hb;
363
394
  faces = /* @__PURE__ */ new Map();
@@ -415,7 +446,8 @@ var FontRegistry = class _FontRegistry {
415
446
  return this.hb;
416
447
  }
417
448
  key(desc) {
418
- return `${desc.family}__${desc.weight ?? "400"}`;
449
+ const normalizedWeight = normalizeWeight(desc.weight);
450
+ return `${desc.family}__${normalizedWeight}`;
419
451
  }
420
452
  async registerFromBytes(bytes, desc) {
421
453
  try {
@@ -427,8 +459,8 @@ var FontRegistry = class _FontRegistry {
427
459
  const font = this.hb.createFont(face);
428
460
  const upem = face.upem || 1e3;
429
461
  font.setScale(upem, upem);
430
- const weight = desc.weight ?? "400";
431
- const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
462
+ const normalizedWeight = normalizeWeight(desc.weight);
463
+ const weightNum = parseInt(normalizedWeight, 10);
432
464
  if (weightNum !== 400 && typeof font.setVariations === "function") {
433
465
  try {
434
466
  font.setVariations(`wght=${weightNum}`);
@@ -462,14 +494,15 @@ var FontRegistry = class _FontRegistry {
462
494
  const loader = _FontRegistry.fallbackLoader;
463
495
  if (!loader) return false;
464
496
  try {
497
+ const normalizedWeight = normalizeWeight(desc.weight);
465
498
  const bytes = await loader({
466
499
  family: desc.family,
467
- weight: desc.weight ?? "400"
500
+ weight: normalizedWeight
468
501
  });
469
502
  if (!bytes) return false;
470
503
  await this.registerFromBytes(bytes, {
471
504
  family: desc.family,
472
- weight: desc.weight ?? "400"
505
+ weight: normalizedWeight
473
506
  });
474
507
  return true;
475
508
  } catch {
package/dist/entry.web.js CHANGED
@@ -362,6 +362,37 @@ async function initHB(wasmBaseURL) {
362
362
 
363
363
  // src/core/font-registry.ts
364
364
  import * as fontkit from "fontkit";
365
+ function normalizeWeight(weight) {
366
+ if (weight === void 0 || weight === null) return "400";
367
+ if (typeof weight === "number") return String(weight);
368
+ const lowerWeight = String(weight).toLowerCase().trim();
369
+ const weightMap = {
370
+ thin: "100",
371
+ hairline: "100",
372
+ extralight: "200",
373
+ ultralight: "200",
374
+ light: "300",
375
+ normal: "400",
376
+ regular: "400",
377
+ medium: "500",
378
+ semibold: "600",
379
+ demibold: "600",
380
+ bold: "700",
381
+ extrabold: "800",
382
+ ultrabold: "800",
383
+ black: "900",
384
+ heavy: "900"
385
+ };
386
+ if (weightMap[lowerWeight]) {
387
+ return weightMap[lowerWeight];
388
+ }
389
+ const numWeight = parseInt(String(weight), 10);
390
+ if (!isNaN(numWeight) && numWeight >= 100 && numWeight <= 900) {
391
+ return String(numWeight);
392
+ }
393
+ console.warn(`Invalid font weight "${weight}", defaulting to 400`);
394
+ return "400";
395
+ }
365
396
  var _FontRegistry = class _FontRegistry {
366
397
  constructor(wasmBaseURL) {
367
398
  __publicField(this, "hb");
@@ -418,7 +449,8 @@ var _FontRegistry = class _FontRegistry {
418
449
  return this.hb;
419
450
  }
420
451
  key(desc) {
421
- return `${desc.family}__${desc.weight ?? "400"}`;
452
+ const normalizedWeight = normalizeWeight(desc.weight);
453
+ return `${desc.family}__${normalizedWeight}`;
422
454
  }
423
455
  async registerFromBytes(bytes, desc) {
424
456
  try {
@@ -430,8 +462,8 @@ var _FontRegistry = class _FontRegistry {
430
462
  const font = this.hb.createFont(face);
431
463
  const upem = face.upem || 1e3;
432
464
  font.setScale(upem, upem);
433
- const weight = desc.weight ?? "400";
434
- const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
465
+ const normalizedWeight = normalizeWeight(desc.weight);
466
+ const weightNum = parseInt(normalizedWeight, 10);
435
467
  if (weightNum !== 400 && typeof font.setVariations === "function") {
436
468
  try {
437
469
  font.setVariations(`wght=${weightNum}`);
@@ -465,14 +497,15 @@ var _FontRegistry = class _FontRegistry {
465
497
  const loader = _FontRegistry.fallbackLoader;
466
498
  if (!loader) return false;
467
499
  try {
500
+ const normalizedWeight = normalizeWeight(desc.weight);
468
501
  const bytes = await loader({
469
502
  family: desc.family,
470
- weight: desc.weight ?? "400"
503
+ weight: normalizedWeight
471
504
  });
472
505
  if (!bytes) return false;
473
506
  await this.registerFromBytes(bytes, {
474
507
  family: desc.family,
475
- weight: desc.weight ?? "400"
508
+ weight: normalizedWeight
476
509
  });
477
510
  return true;
478
511
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.5.8",
3
+ "version": "1.5.9",
4
4
  "description": "Text layout & animation engine (HarfBuzz) for Node & Web - fully self-contained.",
5
5
  "type": "module",
6
6
  "main": "./dist/entry.node.cjs",