@shotstack/shotstack-canvas 2.0.0 → 2.0.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.
@@ -871,6 +871,7 @@ var FontRegistry = class _FontRegistry {
871
871
  fontkitBaseFonts = /* @__PURE__ */ new Map();
872
872
  colorEmojiFonts = /* @__PURE__ */ new Set();
873
873
  colorEmojiFontBytes = /* @__PURE__ */ new Map();
874
+ registeredCanvasFonts = /* @__PURE__ */ new Set();
874
875
  wasmBaseURL;
875
876
  initPromise;
876
877
  emojiFallbackDesc;
@@ -1068,6 +1069,7 @@ var FontRegistry = class _FontRegistry {
1068
1069
  } catch (err) {
1069
1070
  console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
1070
1071
  }
1072
+ await this.registerWithCanvas(desc.family, bytes);
1071
1073
  } catch (err) {
1072
1074
  throw new Error(
1073
1075
  `Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
@@ -1210,6 +1212,21 @@ var FontRegistry = class _FontRegistry {
1210
1212
  );
1211
1213
  }
1212
1214
  }
1215
+ async registerWithCanvas(family, bytes) {
1216
+ if (this.registeredCanvasFonts.has(family)) {
1217
+ return;
1218
+ }
1219
+ try {
1220
+ const canvasMod = await import("canvas");
1221
+ const GlobalFonts = canvasMod.GlobalFonts;
1222
+ if (GlobalFonts && typeof GlobalFonts.register === "function") {
1223
+ const buffer = Buffer.from(bytes);
1224
+ GlobalFonts.register(buffer, family);
1225
+ this.registeredCanvasFonts.add(family);
1226
+ }
1227
+ } catch {
1228
+ }
1229
+ }
1213
1230
  destroy() {
1214
1231
  try {
1215
1232
  for (const [, f] of this.fonts) {
@@ -1246,6 +1263,7 @@ var FontRegistry = class _FontRegistry {
1246
1263
  this.fontkitBaseFonts.clear();
1247
1264
  this.colorEmojiFonts.clear();
1248
1265
  this.colorEmojiFontBytes.clear();
1266
+ this.registeredCanvasFonts.clear();
1249
1267
  this.hb = void 0;
1250
1268
  this.initPromise = void 0;
1251
1269
  } catch (err) {
@@ -544,6 +544,7 @@ declare class FontRegistry {
544
544
  private fontkitBaseFonts;
545
545
  private colorEmojiFonts;
546
546
  private colorEmojiFontBytes;
547
+ private registeredCanvasFonts;
547
548
  private wasmBaseURL?;
548
549
  private initPromise?;
549
550
  private emojiFallbackDesc?;
@@ -575,6 +576,7 @@ declare class FontRegistry {
575
576
  getFace(desc: FontDescriptor): Promise<HBFace | undefined>;
576
577
  getUnitsPerEm(desc: FontDescriptor): Promise<number>;
577
578
  glyphPath(desc: FontDescriptor, glyphId: number): Promise<string>;
579
+ private registerWithCanvas;
578
580
  destroy(): void;
579
581
  }
580
582
 
@@ -544,6 +544,7 @@ declare class FontRegistry {
544
544
  private fontkitBaseFonts;
545
545
  private colorEmojiFonts;
546
546
  private colorEmojiFontBytes;
547
+ private registeredCanvasFonts;
547
548
  private wasmBaseURL?;
548
549
  private initPromise?;
549
550
  private emojiFallbackDesc?;
@@ -575,6 +576,7 @@ declare class FontRegistry {
575
576
  getFace(desc: FontDescriptor): Promise<HBFace | undefined>;
576
577
  getUnitsPerEm(desc: FontDescriptor): Promise<number>;
577
578
  glyphPath(desc: FontDescriptor, glyphId: number): Promise<string>;
579
+ private registerWithCanvas;
578
580
  destroy(): void;
579
581
  }
580
582
 
@@ -482,6 +482,7 @@ var FontRegistry = class _FontRegistry {
482
482
  fontkitBaseFonts = /* @__PURE__ */ new Map();
483
483
  colorEmojiFonts = /* @__PURE__ */ new Set();
484
484
  colorEmojiFontBytes = /* @__PURE__ */ new Map();
485
+ registeredCanvasFonts = /* @__PURE__ */ new Set();
485
486
  wasmBaseURL;
486
487
  initPromise;
487
488
  emojiFallbackDesc;
@@ -679,6 +680,7 @@ var FontRegistry = class _FontRegistry {
679
680
  } catch (err) {
680
681
  console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
681
682
  }
683
+ await this.registerWithCanvas(desc.family, bytes);
682
684
  } catch (err) {
683
685
  throw new Error(
684
686
  `Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
@@ -821,6 +823,21 @@ var FontRegistry = class _FontRegistry {
821
823
  );
822
824
  }
823
825
  }
826
+ async registerWithCanvas(family, bytes) {
827
+ if (this.registeredCanvasFonts.has(family)) {
828
+ return;
829
+ }
830
+ try {
831
+ const canvasMod = await import("canvas");
832
+ const GlobalFonts = canvasMod.GlobalFonts;
833
+ if (GlobalFonts && typeof GlobalFonts.register === "function") {
834
+ const buffer = Buffer.from(bytes);
835
+ GlobalFonts.register(buffer, family);
836
+ this.registeredCanvasFonts.add(family);
837
+ }
838
+ } catch {
839
+ }
840
+ }
824
841
  destroy() {
825
842
  try {
826
843
  for (const [, f] of this.fonts) {
@@ -857,6 +874,7 @@ var FontRegistry = class _FontRegistry {
857
874
  this.fontkitBaseFonts.clear();
858
875
  this.colorEmojiFonts.clear();
859
876
  this.colorEmojiFontBytes.clear();
877
+ this.registeredCanvasFonts.clear();
860
878
  this.hb = void 0;
861
879
  this.initPromise = void 0;
862
880
  } catch (err) {
@@ -544,6 +544,7 @@ declare class FontRegistry {
544
544
  private fontkitBaseFonts;
545
545
  private colorEmojiFonts;
546
546
  private colorEmojiFontBytes;
547
+ private registeredCanvasFonts;
547
548
  private wasmBaseURL?;
548
549
  private initPromise?;
549
550
  private emojiFallbackDesc?;
@@ -575,6 +576,7 @@ declare class FontRegistry {
575
576
  getFace(desc: FontDescriptor): Promise<HBFace | undefined>;
576
577
  getUnitsPerEm(desc: FontDescriptor): Promise<number>;
577
578
  glyphPath(desc: FontDescriptor, glyphId: number): Promise<string>;
579
+ private registerWithCanvas;
578
580
  destroy(): void;
579
581
  }
580
582
 
package/dist/entry.web.js CHANGED
@@ -31755,6 +31755,7 @@ var _FontRegistry = class _FontRegistry {
31755
31755
  __publicField(this, "fontkitBaseFonts", /* @__PURE__ */ new Map());
31756
31756
  __publicField(this, "colorEmojiFonts", /* @__PURE__ */ new Set());
31757
31757
  __publicField(this, "colorEmojiFontBytes", /* @__PURE__ */ new Map());
31758
+ __publicField(this, "registeredCanvasFonts", /* @__PURE__ */ new Set());
31758
31759
  __publicField(this, "wasmBaseURL");
31759
31760
  __publicField(this, "initPromise");
31760
31761
  __publicField(this, "emojiFallbackDesc");
@@ -31947,6 +31948,7 @@ var _FontRegistry = class _FontRegistry {
31947
31948
  } catch (err) {
31948
31949
  console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
31949
31950
  }
31951
+ await this.registerWithCanvas(desc.family, bytes);
31950
31952
  } catch (err) {
31951
31953
  throw new Error(
31952
31954
  `Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
@@ -32089,6 +32091,21 @@ var _FontRegistry = class _FontRegistry {
32089
32091
  );
32090
32092
  }
32091
32093
  }
32094
+ async registerWithCanvas(family, bytes) {
32095
+ if (this.registeredCanvasFonts.has(family)) {
32096
+ return;
32097
+ }
32098
+ try {
32099
+ const canvasMod = await import("canvas");
32100
+ const GlobalFonts = canvasMod.GlobalFonts;
32101
+ if (GlobalFonts && typeof GlobalFonts.register === "function") {
32102
+ const buffer = Buffer.from(bytes);
32103
+ GlobalFonts.register(buffer, family);
32104
+ this.registeredCanvasFonts.add(family);
32105
+ }
32106
+ } catch {
32107
+ }
32108
+ }
32092
32109
  destroy() {
32093
32110
  try {
32094
32111
  for (const [, f] of this.fonts) {
@@ -32125,6 +32142,7 @@ var _FontRegistry = class _FontRegistry {
32125
32142
  this.fontkitBaseFonts.clear();
32126
32143
  this.colorEmojiFonts.clear();
32127
32144
  this.colorEmojiFontBytes.clear();
32145
+ this.registeredCanvasFonts.clear();
32128
32146
  this.hb = void 0;
32129
32147
  this.initPromise = void 0;
32130
32148
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Text layout & animation engine (HarfBuzz) for Node & Web - fully self-contained.",
5
5
  "type": "module",
6
6
  "main": "./dist/entry.node.cjs",