@shotstack/shotstack-canvas 2.0.0 → 2.0.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.node.cjs +20 -1
- package/dist/entry.node.d.cts +16 -0
- package/dist/entry.node.d.ts +16 -0
- package/dist/entry.node.js +20 -1
- package/dist/entry.web.d.ts +16 -0
- package/dist/entry.web.js +20 -1
- package/package.json +1 -1
package/dist/entry.node.cjs
CHANGED
|
@@ -612,7 +612,8 @@ var richCaptionAssetSchema = import_zod.z.object({
|
|
|
612
612
|
wordAnimation: richCaptionWordAnimationSchema.optional(),
|
|
613
613
|
position: import_zod.z.enum(["top", "center", "bottom"]).default("bottom"),
|
|
614
614
|
maxWidth: import_zod.z.number().min(0.1).max(1).default(0.9),
|
|
615
|
-
maxLines: import_zod.z.number().int().min(1).max(10).default(2)
|
|
615
|
+
maxLines: import_zod.z.number().int().min(1).max(10).default(2),
|
|
616
|
+
customFonts: import_zod.z.array(customFontSchema).optional()
|
|
616
617
|
}).superRefine((data, ctx) => {
|
|
617
618
|
if (data.src && data.words) {
|
|
618
619
|
ctx.addIssue({
|
|
@@ -871,6 +872,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
871
872
|
fontkitBaseFonts = /* @__PURE__ */ new Map();
|
|
872
873
|
colorEmojiFonts = /* @__PURE__ */ new Set();
|
|
873
874
|
colorEmojiFontBytes = /* @__PURE__ */ new Map();
|
|
875
|
+
registeredCanvasFonts = /* @__PURE__ */ new Set();
|
|
874
876
|
wasmBaseURL;
|
|
875
877
|
initPromise;
|
|
876
878
|
emojiFallbackDesc;
|
|
@@ -1068,6 +1070,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
1068
1070
|
} catch (err) {
|
|
1069
1071
|
console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
|
|
1070
1072
|
}
|
|
1073
|
+
await this.registerWithCanvas(desc.family, bytes);
|
|
1071
1074
|
} catch (err) {
|
|
1072
1075
|
throw new Error(
|
|
1073
1076
|
`Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -1210,6 +1213,21 @@ var FontRegistry = class _FontRegistry {
|
|
|
1210
1213
|
);
|
|
1211
1214
|
}
|
|
1212
1215
|
}
|
|
1216
|
+
async registerWithCanvas(family, bytes) {
|
|
1217
|
+
if (this.registeredCanvasFonts.has(family)) {
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
try {
|
|
1221
|
+
const canvasMod = await import("canvas");
|
|
1222
|
+
const GlobalFonts = canvasMod.GlobalFonts;
|
|
1223
|
+
if (GlobalFonts && typeof GlobalFonts.register === "function") {
|
|
1224
|
+
const buffer = Buffer.from(bytes);
|
|
1225
|
+
GlobalFonts.register(buffer, family);
|
|
1226
|
+
this.registeredCanvasFonts.add(family);
|
|
1227
|
+
}
|
|
1228
|
+
} catch {
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1213
1231
|
destroy() {
|
|
1214
1232
|
try {
|
|
1215
1233
|
for (const [, f] of this.fonts) {
|
|
@@ -1246,6 +1264,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
1246
1264
|
this.fontkitBaseFonts.clear();
|
|
1247
1265
|
this.colorEmojiFonts.clear();
|
|
1248
1266
|
this.colorEmojiFontBytes.clear();
|
|
1267
|
+
this.registeredCanvasFonts.clear();
|
|
1249
1268
|
this.hb = void 0;
|
|
1250
1269
|
this.initPromise = void 0;
|
|
1251
1270
|
} catch (err) {
|
package/dist/entry.node.d.cts
CHANGED
|
@@ -373,6 +373,13 @@ declare const richCaptionAssetSchema: z.ZodObject<{
|
|
|
373
373
|
}>>;
|
|
374
374
|
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
375
375
|
maxLines: z.ZodDefault<z.ZodNumber>;
|
|
376
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
377
|
+
src: z.ZodString;
|
|
378
|
+
family: z.ZodString;
|
|
379
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
380
|
+
style: z.ZodOptional<z.ZodString>;
|
|
381
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
382
|
+
}, z.core.$strip>>>;
|
|
376
383
|
}, z.core.$strip>;
|
|
377
384
|
declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
|
|
378
385
|
type: z.ZodLiteral<"rich-caption">;
|
|
@@ -492,6 +499,13 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
|
|
|
492
499
|
}>>;
|
|
493
500
|
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
494
501
|
maxLines: z.ZodDefault<z.ZodNumber>;
|
|
502
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
503
|
+
src: z.ZodString;
|
|
504
|
+
family: z.ZodString;
|
|
505
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
506
|
+
style: z.ZodOptional<z.ZodString>;
|
|
507
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
508
|
+
}, z.core.$strip>>>;
|
|
495
509
|
}, z.core.$strip>;
|
|
496
510
|
type CanvasRichCaptionAsset = z.infer<typeof CanvasRichCaptionAssetSchema>;
|
|
497
511
|
type CanvasSvgAsset = z.infer<typeof CanvasSvgAssetSchema>;
|
|
@@ -544,6 +558,7 @@ declare class FontRegistry {
|
|
|
544
558
|
private fontkitBaseFonts;
|
|
545
559
|
private colorEmojiFonts;
|
|
546
560
|
private colorEmojiFontBytes;
|
|
561
|
+
private registeredCanvasFonts;
|
|
547
562
|
private wasmBaseURL?;
|
|
548
563
|
private initPromise?;
|
|
549
564
|
private emojiFallbackDesc?;
|
|
@@ -575,6 +590,7 @@ declare class FontRegistry {
|
|
|
575
590
|
getFace(desc: FontDescriptor): Promise<HBFace | undefined>;
|
|
576
591
|
getUnitsPerEm(desc: FontDescriptor): Promise<number>;
|
|
577
592
|
glyphPath(desc: FontDescriptor, glyphId: number): Promise<string>;
|
|
593
|
+
private registerWithCanvas;
|
|
578
594
|
destroy(): void;
|
|
579
595
|
}
|
|
580
596
|
|
package/dist/entry.node.d.ts
CHANGED
|
@@ -373,6 +373,13 @@ declare const richCaptionAssetSchema: z.ZodObject<{
|
|
|
373
373
|
}>>;
|
|
374
374
|
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
375
375
|
maxLines: z.ZodDefault<z.ZodNumber>;
|
|
376
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
377
|
+
src: z.ZodString;
|
|
378
|
+
family: z.ZodString;
|
|
379
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
380
|
+
style: z.ZodOptional<z.ZodString>;
|
|
381
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
382
|
+
}, z.core.$strip>>>;
|
|
376
383
|
}, z.core.$strip>;
|
|
377
384
|
declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
|
|
378
385
|
type: z.ZodLiteral<"rich-caption">;
|
|
@@ -492,6 +499,13 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
|
|
|
492
499
|
}>>;
|
|
493
500
|
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
494
501
|
maxLines: z.ZodDefault<z.ZodNumber>;
|
|
502
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
503
|
+
src: z.ZodString;
|
|
504
|
+
family: z.ZodString;
|
|
505
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
506
|
+
style: z.ZodOptional<z.ZodString>;
|
|
507
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
508
|
+
}, z.core.$strip>>>;
|
|
495
509
|
}, z.core.$strip>;
|
|
496
510
|
type CanvasRichCaptionAsset = z.infer<typeof CanvasRichCaptionAssetSchema>;
|
|
497
511
|
type CanvasSvgAsset = z.infer<typeof CanvasSvgAssetSchema>;
|
|
@@ -544,6 +558,7 @@ declare class FontRegistry {
|
|
|
544
558
|
private fontkitBaseFonts;
|
|
545
559
|
private colorEmojiFonts;
|
|
546
560
|
private colorEmojiFontBytes;
|
|
561
|
+
private registeredCanvasFonts;
|
|
547
562
|
private wasmBaseURL?;
|
|
548
563
|
private initPromise?;
|
|
549
564
|
private emojiFallbackDesc?;
|
|
@@ -575,6 +590,7 @@ declare class FontRegistry {
|
|
|
575
590
|
getFace(desc: FontDescriptor): Promise<HBFace | undefined>;
|
|
576
591
|
getUnitsPerEm(desc: FontDescriptor): Promise<number>;
|
|
577
592
|
glyphPath(desc: FontDescriptor, glyphId: number): Promise<string>;
|
|
593
|
+
private registerWithCanvas;
|
|
578
594
|
destroy(): void;
|
|
579
595
|
}
|
|
580
596
|
|
package/dist/entry.node.js
CHANGED
|
@@ -224,7 +224,8 @@ var richCaptionAssetSchema = z.object({
|
|
|
224
224
|
wordAnimation: richCaptionWordAnimationSchema.optional(),
|
|
225
225
|
position: z.enum(["top", "center", "bottom"]).default("bottom"),
|
|
226
226
|
maxWidth: z.number().min(0.1).max(1).default(0.9),
|
|
227
|
-
maxLines: z.number().int().min(1).max(10).default(2)
|
|
227
|
+
maxLines: z.number().int().min(1).max(10).default(2),
|
|
228
|
+
customFonts: z.array(customFontSchema).optional()
|
|
228
229
|
}).superRefine((data, ctx) => {
|
|
229
230
|
if (data.src && data.words) {
|
|
230
231
|
ctx.addIssue({
|
|
@@ -482,6 +483,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
482
483
|
fontkitBaseFonts = /* @__PURE__ */ new Map();
|
|
483
484
|
colorEmojiFonts = /* @__PURE__ */ new Set();
|
|
484
485
|
colorEmojiFontBytes = /* @__PURE__ */ new Map();
|
|
486
|
+
registeredCanvasFonts = /* @__PURE__ */ new Set();
|
|
485
487
|
wasmBaseURL;
|
|
486
488
|
initPromise;
|
|
487
489
|
emojiFallbackDesc;
|
|
@@ -679,6 +681,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
679
681
|
} catch (err) {
|
|
680
682
|
console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
|
|
681
683
|
}
|
|
684
|
+
await this.registerWithCanvas(desc.family, bytes);
|
|
682
685
|
} catch (err) {
|
|
683
686
|
throw new Error(
|
|
684
687
|
`Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -821,6 +824,21 @@ var FontRegistry = class _FontRegistry {
|
|
|
821
824
|
);
|
|
822
825
|
}
|
|
823
826
|
}
|
|
827
|
+
async registerWithCanvas(family, bytes) {
|
|
828
|
+
if (this.registeredCanvasFonts.has(family)) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
try {
|
|
832
|
+
const canvasMod = await import("canvas");
|
|
833
|
+
const GlobalFonts = canvasMod.GlobalFonts;
|
|
834
|
+
if (GlobalFonts && typeof GlobalFonts.register === "function") {
|
|
835
|
+
const buffer = Buffer.from(bytes);
|
|
836
|
+
GlobalFonts.register(buffer, family);
|
|
837
|
+
this.registeredCanvasFonts.add(family);
|
|
838
|
+
}
|
|
839
|
+
} catch {
|
|
840
|
+
}
|
|
841
|
+
}
|
|
824
842
|
destroy() {
|
|
825
843
|
try {
|
|
826
844
|
for (const [, f] of this.fonts) {
|
|
@@ -857,6 +875,7 @@ var FontRegistry = class _FontRegistry {
|
|
|
857
875
|
this.fontkitBaseFonts.clear();
|
|
858
876
|
this.colorEmojiFonts.clear();
|
|
859
877
|
this.colorEmojiFontBytes.clear();
|
|
878
|
+
this.registeredCanvasFonts.clear();
|
|
860
879
|
this.hb = void 0;
|
|
861
880
|
this.initPromise = void 0;
|
|
862
881
|
} catch (err) {
|
package/dist/entry.web.d.ts
CHANGED
|
@@ -373,6 +373,13 @@ declare const richCaptionAssetSchema: z.ZodObject<{
|
|
|
373
373
|
}>>;
|
|
374
374
|
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
375
375
|
maxLines: z.ZodDefault<z.ZodNumber>;
|
|
376
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
377
|
+
src: z.ZodString;
|
|
378
|
+
family: z.ZodString;
|
|
379
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
380
|
+
style: z.ZodOptional<z.ZodString>;
|
|
381
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
382
|
+
}, z.core.$strip>>>;
|
|
376
383
|
}, z.core.$strip>;
|
|
377
384
|
declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
|
|
378
385
|
type: z.ZodLiteral<"rich-caption">;
|
|
@@ -492,6 +499,13 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
|
|
|
492
499
|
}>>;
|
|
493
500
|
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
494
501
|
maxLines: z.ZodDefault<z.ZodNumber>;
|
|
502
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
503
|
+
src: z.ZodString;
|
|
504
|
+
family: z.ZodString;
|
|
505
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
506
|
+
style: z.ZodOptional<z.ZodString>;
|
|
507
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
508
|
+
}, z.core.$strip>>>;
|
|
495
509
|
}, z.core.$strip>;
|
|
496
510
|
type CanvasRichCaptionAsset = z.infer<typeof CanvasRichCaptionAssetSchema>;
|
|
497
511
|
type CanvasSvgAsset = z.infer<typeof CanvasSvgAssetSchema>;
|
|
@@ -544,6 +558,7 @@ declare class FontRegistry {
|
|
|
544
558
|
private fontkitBaseFonts;
|
|
545
559
|
private colorEmojiFonts;
|
|
546
560
|
private colorEmojiFontBytes;
|
|
561
|
+
private registeredCanvasFonts;
|
|
547
562
|
private wasmBaseURL?;
|
|
548
563
|
private initPromise?;
|
|
549
564
|
private emojiFallbackDesc?;
|
|
@@ -575,6 +590,7 @@ declare class FontRegistry {
|
|
|
575
590
|
getFace(desc: FontDescriptor): Promise<HBFace | undefined>;
|
|
576
591
|
getUnitsPerEm(desc: FontDescriptor): Promise<number>;
|
|
577
592
|
glyphPath(desc: FontDescriptor, glyphId: number): Promise<string>;
|
|
593
|
+
private registerWithCanvas;
|
|
578
594
|
destroy(): void;
|
|
579
595
|
}
|
|
580
596
|
|
package/dist/entry.web.js
CHANGED
|
@@ -18102,7 +18102,8 @@ var richCaptionAssetSchema = external_exports.object({
|
|
|
18102
18102
|
wordAnimation: richCaptionWordAnimationSchema.optional(),
|
|
18103
18103
|
position: external_exports.enum(["top", "center", "bottom"]).default("bottom"),
|
|
18104
18104
|
maxWidth: external_exports.number().min(0.1).max(1).default(0.9),
|
|
18105
|
-
maxLines: external_exports.number().int().min(1).max(10).default(2)
|
|
18105
|
+
maxLines: external_exports.number().int().min(1).max(10).default(2),
|
|
18106
|
+
customFonts: external_exports.array(customFontSchema).optional()
|
|
18106
18107
|
}).superRefine((data, ctx) => {
|
|
18107
18108
|
if (data.src && data.words) {
|
|
18108
18109
|
ctx.addIssue({
|
|
@@ -31755,6 +31756,7 @@ var _FontRegistry = class _FontRegistry {
|
|
|
31755
31756
|
__publicField(this, "fontkitBaseFonts", /* @__PURE__ */ new Map());
|
|
31756
31757
|
__publicField(this, "colorEmojiFonts", /* @__PURE__ */ new Set());
|
|
31757
31758
|
__publicField(this, "colorEmojiFontBytes", /* @__PURE__ */ new Map());
|
|
31759
|
+
__publicField(this, "registeredCanvasFonts", /* @__PURE__ */ new Set());
|
|
31758
31760
|
__publicField(this, "wasmBaseURL");
|
|
31759
31761
|
__publicField(this, "initPromise");
|
|
31760
31762
|
__publicField(this, "emojiFallbackDesc");
|
|
@@ -31947,6 +31949,7 @@ var _FontRegistry = class _FontRegistry {
|
|
|
31947
31949
|
} catch (err) {
|
|
31948
31950
|
console.warn(`\u26A0\uFE0F Fontkit failed for ${desc.family}:`, err);
|
|
31949
31951
|
}
|
|
31952
|
+
await this.registerWithCanvas(desc.family, bytes);
|
|
31950
31953
|
} catch (err) {
|
|
31951
31954
|
throw new Error(
|
|
31952
31955
|
`Failed to register font "${desc.family}": ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -32089,6 +32092,21 @@ var _FontRegistry = class _FontRegistry {
|
|
|
32089
32092
|
);
|
|
32090
32093
|
}
|
|
32091
32094
|
}
|
|
32095
|
+
async registerWithCanvas(family, bytes) {
|
|
32096
|
+
if (this.registeredCanvasFonts.has(family)) {
|
|
32097
|
+
return;
|
|
32098
|
+
}
|
|
32099
|
+
try {
|
|
32100
|
+
const canvasMod = await import("canvas");
|
|
32101
|
+
const GlobalFonts = canvasMod.GlobalFonts;
|
|
32102
|
+
if (GlobalFonts && typeof GlobalFonts.register === "function") {
|
|
32103
|
+
const buffer = Buffer.from(bytes);
|
|
32104
|
+
GlobalFonts.register(buffer, family);
|
|
32105
|
+
this.registeredCanvasFonts.add(family);
|
|
32106
|
+
}
|
|
32107
|
+
} catch {
|
|
32108
|
+
}
|
|
32109
|
+
}
|
|
32092
32110
|
destroy() {
|
|
32093
32111
|
try {
|
|
32094
32112
|
for (const [, f] of this.fonts) {
|
|
@@ -32125,6 +32143,7 @@ var _FontRegistry = class _FontRegistry {
|
|
|
32125
32143
|
this.fontkitBaseFonts.clear();
|
|
32126
32144
|
this.colorEmojiFonts.clear();
|
|
32127
32145
|
this.colorEmojiFontBytes.clear();
|
|
32146
|
+
this.registeredCanvasFonts.clear();
|
|
32128
32147
|
this.hb = void 0;
|
|
32129
32148
|
this.initPromise = void 0;
|
|
32130
32149
|
} catch (err) {
|
package/package.json
CHANGED