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