@shotstack/shotstack-canvas 1.1.9 → 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.
- package/dist/entry.node.cjs +37 -2
- package/dist/entry.node.cjs.map +1 -1
- package/dist/entry.node.js +37 -2
- package/dist/entry.node.js.map +1 -1
- package/dist/entry.web.js +37 -2
- package/dist/entry.web.js.map +1 -1
- package/package.json +2 -1
package/dist/entry.web.js
CHANGED
|
@@ -211,12 +211,15 @@ 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());
|
|
222
|
+
// fontkit fonts for variable outlines
|
|
220
223
|
__publicField(this, "wasmBaseURL");
|
|
221
224
|
__publicField(this, "initPromise");
|
|
222
225
|
this.wasmBaseURL = wasmBaseURL;
|
|
@@ -241,7 +244,9 @@ var _FontRegistry = class _FontRegistry {
|
|
|
241
244
|
}
|
|
242
245
|
async _doInit() {
|
|
243
246
|
try {
|
|
244
|
-
this.hb = await initHB(
|
|
247
|
+
this.hb = await initHB(
|
|
248
|
+
"https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm"
|
|
249
|
+
);
|
|
245
250
|
} catch (error) {
|
|
246
251
|
this.initPromise = void 0;
|
|
247
252
|
throw error;
|
|
@@ -272,9 +277,31 @@ var _FontRegistry = class _FontRegistry {
|
|
|
272
277
|
const font = this.hb.createFont(face);
|
|
273
278
|
const upem = face.upem || 1e3;
|
|
274
279
|
font.setScale(upem, upem);
|
|
280
|
+
const weight = desc.weight ?? "400";
|
|
281
|
+
const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
|
|
282
|
+
if (weightNum !== 400 && typeof font.setVariations === "function") {
|
|
283
|
+
try {
|
|
284
|
+
font.setVariations(`wght=${weightNum}`);
|
|
285
|
+
} catch (e) {
|
|
286
|
+
}
|
|
287
|
+
}
|
|
275
288
|
this.blobs.set(k, blob);
|
|
276
289
|
this.faces.set(k, face);
|
|
277
290
|
this.fonts.set(k, font);
|
|
291
|
+
try {
|
|
292
|
+
const buffer = typeof Buffer !== "undefined" ? Buffer.from(bytes) : new Uint8Array(bytes);
|
|
293
|
+
const fkFont = fontkit.create(buffer);
|
|
294
|
+
if (fkFont.variationAxes && Object.keys(fkFont.variationAxes).length > 0) {
|
|
295
|
+
const variationFont = fkFont.getVariation({ wght: weightNum });
|
|
296
|
+
this.fontkitFonts.set(k, variationFont);
|
|
297
|
+
console.log(`\u2705 Registered variable font: ${desc.family} weight=${weightNum}`);
|
|
298
|
+
} else {
|
|
299
|
+
this.fontkitFonts.set(k, fkFont);
|
|
300
|
+
console.log(`\u2705 Registered static font: ${desc.family}`);
|
|
301
|
+
}
|
|
302
|
+
} catch (err) {
|
|
303
|
+
console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
|
|
304
|
+
}
|
|
278
305
|
} catch (err) {
|
|
279
306
|
throw new Error(
|
|
280
307
|
`Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -348,7 +375,15 @@ var _FontRegistry = class _FontRegistry {
|
|
|
348
375
|
}
|
|
349
376
|
}
|
|
350
377
|
async glyphPath(desc, glyphId) {
|
|
378
|
+
const k = this.key(desc);
|
|
351
379
|
try {
|
|
380
|
+
const fkFont = this.fontkitFonts.get(k);
|
|
381
|
+
if (fkFont) {
|
|
382
|
+
const glyph = fkFont.getGlyph(glyphId);
|
|
383
|
+
if (glyph && glyph.path) {
|
|
384
|
+
return glyph.path.toSVG();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
352
387
|
const font = await this.getFont(desc);
|
|
353
388
|
const path = font.glyphToPath(glyphId);
|
|
354
389
|
return path && path !== "" ? path : "M 0 0";
|
|
@@ -390,6 +425,7 @@ var _FontRegistry = class _FontRegistry {
|
|
|
390
425
|
this.fonts.clear();
|
|
391
426
|
this.faces.clear();
|
|
392
427
|
this.blobs.clear();
|
|
428
|
+
this.fontkitFonts.clear();
|
|
393
429
|
this.hb = void 0;
|
|
394
430
|
this.initPromise = void 0;
|
|
395
431
|
} catch (err) {
|
|
@@ -1260,7 +1296,6 @@ function createWebPainter(canvas) {
|
|
|
1260
1296
|
if (!fill) {
|
|
1261
1297
|
fill = makeGradientFromBBox(ctx, fillOp.fill, localBBox);
|
|
1262
1298
|
gradientCache.set(cacheKey, fill);
|
|
1263
|
-
console.log("[Web Painter] Created NEW gradient for local bbox:", localBBox);
|
|
1264
1299
|
}
|
|
1265
1300
|
ctx.fillStyle = fill;
|
|
1266
1301
|
ctx.fill(p);
|