@shotstack/shotstack-canvas 1.2.0 → 1.2.2

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.
@@ -245,11 +245,13 @@ async function initHB(wasmBaseURL) {
245
245
  }
246
246
 
247
247
  // src/core/font-registry.ts
248
+ var fontkit = __toESM(require("fontkit"), 1);
248
249
  var FontRegistry = class _FontRegistry {
249
250
  hb;
250
251
  faces = /* @__PURE__ */ new Map();
251
252
  fonts = /* @__PURE__ */ new Map();
252
253
  blobs = /* @__PURE__ */ new Map();
254
+ fontkitFonts = /* @__PURE__ */ new Map();
253
255
  wasmBaseURL;
254
256
  initPromise;
255
257
  static fallbackLoader;
@@ -276,7 +278,9 @@ var FontRegistry = class _FontRegistry {
276
278
  }
277
279
  async _doInit() {
278
280
  try {
279
- this.hb = await initHB("https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm");
281
+ this.hb = await initHB(
282
+ "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm"
283
+ );
280
284
  } catch (error) {
281
285
  this.initPromise = void 0;
282
286
  throw error;
@@ -307,9 +311,31 @@ var FontRegistry = class _FontRegistry {
307
311
  const font = this.hb.createFont(face);
308
312
  const upem = face.upem || 1e3;
309
313
  font.setScale(upem, upem);
314
+ const weight = desc.weight ?? "400";
315
+ const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
316
+ if (weightNum !== 400 && typeof font.setVariations === "function") {
317
+ try {
318
+ font.setVariations(`wght=${weightNum}`);
319
+ } catch (e) {
320
+ }
321
+ }
310
322
  this.blobs.set(k, blob);
311
323
  this.faces.set(k, face);
312
324
  this.fonts.set(k, font);
325
+ try {
326
+ const buffer = typeof Buffer !== "undefined" ? Buffer.from(bytes) : new Uint8Array(bytes);
327
+ const fkFont = fontkit.create(buffer);
328
+ if (fkFont.variationAxes && Object.keys(fkFont.variationAxes).length > 0) {
329
+ const variationFont = fkFont.getVariation({ wght: weightNum });
330
+ this.fontkitFonts.set(k, variationFont);
331
+ console.log(`\u2705 Registered variable font: ${desc.family} weight=${weightNum}`);
332
+ } else {
333
+ this.fontkitFonts.set(k, fkFont);
334
+ console.log(`\u2705 Registered static font: ${desc.family}`);
335
+ }
336
+ } catch (err) {
337
+ console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
338
+ }
313
339
  } catch (err) {
314
340
  throw new Error(
315
341
  `Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
@@ -383,7 +409,15 @@ var FontRegistry = class _FontRegistry {
383
409
  }
384
410
  }
385
411
  async glyphPath(desc, glyphId) {
412
+ const k = this.key(desc);
386
413
  try {
414
+ const fkFont = this.fontkitFonts.get(k);
415
+ if (fkFont) {
416
+ const glyph = fkFont.getGlyph(glyphId);
417
+ if (glyph && glyph.path) {
418
+ return glyph.path.toSVG();
419
+ }
420
+ }
387
421
  const font = await this.getFont(desc);
388
422
  const path = font.glyphToPath(glyphId);
389
423
  return path && path !== "" ? path : "M 0 0";
@@ -425,6 +459,7 @@ var FontRegistry = class _FontRegistry {
425
459
  this.fonts.clear();
426
460
  this.faces.clear();
427
461
  this.blobs.clear();
462
+ this.fontkitFonts.clear();
428
463
  this.hb = void 0;
429
464
  this.initPromise = void 0;
430
465
  } catch (err) {