@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.node.js
CHANGED
|
@@ -207,11 +207,14 @@ 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();
|
|
217
|
+
// fontkit fonts for variable outlines
|
|
215
218
|
wasmBaseURL;
|
|
216
219
|
initPromise;
|
|
217
220
|
static fallbackLoader;
|
|
@@ -238,7 +241,9 @@ var FontRegistry = class _FontRegistry {
|
|
|
238
241
|
}
|
|
239
242
|
async _doInit() {
|
|
240
243
|
try {
|
|
241
|
-
this.hb = await initHB(
|
|
244
|
+
this.hb = await initHB(
|
|
245
|
+
"https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm"
|
|
246
|
+
);
|
|
242
247
|
} catch (error) {
|
|
243
248
|
this.initPromise = void 0;
|
|
244
249
|
throw error;
|
|
@@ -269,9 +274,31 @@ var FontRegistry = class _FontRegistry {
|
|
|
269
274
|
const font = this.hb.createFont(face);
|
|
270
275
|
const upem = face.upem || 1e3;
|
|
271
276
|
font.setScale(upem, upem);
|
|
277
|
+
const weight = desc.weight ?? "400";
|
|
278
|
+
const weightNum = typeof weight === "string" ? parseInt(weight, 10) : weight;
|
|
279
|
+
if (weightNum !== 400 && typeof font.setVariations === "function") {
|
|
280
|
+
try {
|
|
281
|
+
font.setVariations(`wght=${weightNum}`);
|
|
282
|
+
} catch (e) {
|
|
283
|
+
}
|
|
284
|
+
}
|
|
272
285
|
this.blobs.set(k, blob);
|
|
273
286
|
this.faces.set(k, face);
|
|
274
287
|
this.fonts.set(k, font);
|
|
288
|
+
try {
|
|
289
|
+
const buffer = typeof Buffer !== "undefined" ? Buffer.from(bytes) : new Uint8Array(bytes);
|
|
290
|
+
const fkFont = fontkit.create(buffer);
|
|
291
|
+
if (fkFont.variationAxes && Object.keys(fkFont.variationAxes).length > 0) {
|
|
292
|
+
const variationFont = fkFont.getVariation({ wght: weightNum });
|
|
293
|
+
this.fontkitFonts.set(k, variationFont);
|
|
294
|
+
console.log(`\u2705 Registered variable font: ${desc.family} weight=${weightNum}`);
|
|
295
|
+
} else {
|
|
296
|
+
this.fontkitFonts.set(k, fkFont);
|
|
297
|
+
console.log(`\u2705 Registered static font: ${desc.family}`);
|
|
298
|
+
}
|
|
299
|
+
} catch (err) {
|
|
300
|
+
console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
|
|
301
|
+
}
|
|
275
302
|
} catch (err) {
|
|
276
303
|
throw new Error(
|
|
277
304
|
`Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -345,7 +372,15 @@ var FontRegistry = class _FontRegistry {
|
|
|
345
372
|
}
|
|
346
373
|
}
|
|
347
374
|
async glyphPath(desc, glyphId) {
|
|
375
|
+
const k = this.key(desc);
|
|
348
376
|
try {
|
|
377
|
+
const fkFont = this.fontkitFonts.get(k);
|
|
378
|
+
if (fkFont) {
|
|
379
|
+
const glyph = fkFont.getGlyph(glyphId);
|
|
380
|
+
if (glyph && glyph.path) {
|
|
381
|
+
return glyph.path.toSVG();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
349
384
|
const font = await this.getFont(desc);
|
|
350
385
|
const path = font.glyphToPath(glyphId);
|
|
351
386
|
return path && path !== "" ? path : "M 0 0";
|
|
@@ -387,6 +422,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
387
422
|
this.fonts.clear();
|
|
388
423
|
this.faces.clear();
|
|
389
424
|
this.blobs.clear();
|
|
425
|
+
this.fontkitFonts.clear();
|
|
390
426
|
this.hb = void 0;
|
|
391
427
|
this.initPromise = void 0;
|
|
392
428
|
} catch (err) {
|
|
@@ -1284,7 +1320,6 @@ async function createNodePainter(opts) {
|
|
|
1284
1320
|
if (!fill) {
|
|
1285
1321
|
fill = makeGradientFromBBox(context, fillOp.fill, localBBox);
|
|
1286
1322
|
gradientCache.set(cacheKey, fill);
|
|
1287
|
-
console.log("[Node Painter] Created NEW gradient for local bbox:", localBBox);
|
|
1288
1323
|
}
|
|
1289
1324
|
context.fillStyle = fill;
|
|
1290
1325
|
context.beginPath();
|