@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.
@@ -207,11 +207,13 @@ async function initHB(wasmBaseURL) {
207
207
  }
208
208
 
209
209
  // src/core/font-registry.ts
210
+ import * as fontkit from "fontkit";
210
211
  var FontRegistry = class _FontRegistry {
211
212
  hb;
212
213
  faces = /* @__PURE__ */ new Map();
213
214
  fonts = /* @__PURE__ */ new Map();
214
215
  blobs = /* @__PURE__ */ new Map();
216
+ fontkitFonts = /* @__PURE__ */ new Map();
215
217
  wasmBaseURL;
216
218
  initPromise;
217
219
  static fallbackLoader;
@@ -238,7 +240,9 @@ var FontRegistry = class _FontRegistry {
238
240
  }
239
241
  async _doInit() {
240
242
  try {
241
- this.hb = await initHB("https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm");
243
+ this.hb = await initHB(
244
+ "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm"
245
+ );
242
246
  } catch (error) {
243
247
  this.initPromise = void 0;
244
248
  throw error;
@@ -269,9 +273,31 @@ var FontRegistry = class _FontRegistry {
269
273
  const font = this.hb.createFont(face);
270
274
  const upem = face.upem || 1e3;
271
275
  font.setScale(upem, upem);
276
+ const weight = desc.weight ?? "400";
277
+ const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
278
+ if (weightNum !== 400 && typeof font.setVariations === "function") {
279
+ try {
280
+ font.setVariations(`wght=${weightNum}`);
281
+ } catch (e) {
282
+ }
283
+ }
272
284
  this.blobs.set(k, blob);
273
285
  this.faces.set(k, face);
274
286
  this.fonts.set(k, font);
287
+ try {
288
+ const buffer = typeof Buffer !== "undefined" ? Buffer.from(bytes) : new Uint8Array(bytes);
289
+ const fkFont = fontkit.create(buffer);
290
+ if (fkFont.variationAxes && Object.keys(fkFont.variationAxes).length > 0) {
291
+ const variationFont = fkFont.getVariation({ wght: weightNum });
292
+ this.fontkitFonts.set(k, variationFont);
293
+ console.log(`\u2705 Registered variable font: ${desc.family} weight=${weightNum}`);
294
+ } else {
295
+ this.fontkitFonts.set(k, fkFont);
296
+ console.log(`\u2705 Registered static font: ${desc.family}`);
297
+ }
298
+ } catch (err) {
299
+ console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
300
+ }
275
301
  } catch (err) {
276
302
  throw new Error(
277
303
  `Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
@@ -345,7 +371,15 @@ var FontRegistry = class _FontRegistry {
345
371
  }
346
372
  }
347
373
  async glyphPath(desc, glyphId) {
374
+ const k = this.key(desc);
348
375
  try {
376
+ const fkFont = this.fontkitFonts.get(k);
377
+ if (fkFont) {
378
+ const glyph = fkFont.getGlyph(glyphId);
379
+ if (glyph && glyph.path) {
380
+ return glyph.path.toSVG();
381
+ }
382
+ }
349
383
  const font = await this.getFont(desc);
350
384
  const path = font.glyphToPath(glyphId);
351
385
  return path && path !== "" ? path : "M 0 0";
@@ -387,6 +421,7 @@ var FontRegistry = class _FontRegistry {
387
421
  this.fonts.clear();
388
422
  this.faces.clear();
389
423
  this.blobs.clear();
424
+ this.fontkitFonts.clear();
390
425
  this.hb = void 0;
391
426
  this.initPromise = void 0;
392
427
  } catch (err) {