@shotstack/shotstack-canvas 1.2.0 → 1.2.1

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