@shotstack/shotstack-canvas 1.6.5 → 1.7.0
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 +127 -114
- package/dist/entry.node.d.cts +124 -102
- package/dist/entry.node.d.ts +124 -102
- package/dist/entry.node.js +135 -114
- package/dist/entry.web.d.ts +123 -101
- package/dist/entry.web.js +135 -114
- package/package.json +63 -62
package/dist/entry.web.d.ts
CHANGED
|
@@ -1,102 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
width: number;
|
|
4
|
-
height: number;
|
|
5
|
-
pixelRatio: number;
|
|
6
|
-
fontFamily: string;
|
|
7
|
-
fontSize: number;
|
|
8
|
-
color: string;
|
|
9
|
-
textAlign: "center";
|
|
10
|
-
};
|
|
11
|
-
LIMITS: {
|
|
12
|
-
minWidth: number;
|
|
13
|
-
maxWidth: number;
|
|
14
|
-
minHeight: number;
|
|
15
|
-
maxHeight: number;
|
|
16
|
-
minFontSize: number;
|
|
17
|
-
maxFontSize: number;
|
|
18
|
-
minDuration: number;
|
|
19
|
-
maxDuration: number;
|
|
20
|
-
maxTextLength: number;
|
|
21
|
-
};
|
|
22
|
-
ANIMATION_TYPES: readonly ["typewriter", "fadeIn", "slideIn", "shift", "ascend", "movingLetters"];
|
|
23
|
-
};
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { components } from '@shotstack/schemas';
|
|
24
3
|
|
|
25
|
-
|
|
26
|
-
type: "rich-text"
|
|
27
|
-
text:
|
|
28
|
-
width
|
|
29
|
-
height
|
|
30
|
-
font
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
4
|
+
declare const CanvasRichTextAssetSchema: z.ZodObject<{
|
|
5
|
+
type: z.ZodLiteral<"rich-text">;
|
|
6
|
+
text: z.ZodDefault<z.ZodString>;
|
|
7
|
+
width: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
8
|
+
height: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
9
|
+
font: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
normal: "normal";
|
|
12
|
+
italic: "italic";
|
|
13
|
+
oblique: "oblique";
|
|
14
|
+
}>>;
|
|
15
|
+
family: z.ZodDefault<z.ZodString>;
|
|
16
|
+
size: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
weight: z.ZodDefault<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
18
|
+
color: z.ZodDefault<z.ZodString>;
|
|
19
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
background: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
style: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
letterSpacing: z.ZodDefault<z.ZodNumber>;
|
|
24
|
+
lineHeight: z.ZodDefault<z.ZodNumber>;
|
|
25
|
+
textTransform: z.ZodDefault<z.ZodEnum<{
|
|
26
|
+
none: "none";
|
|
27
|
+
uppercase: "uppercase";
|
|
28
|
+
lowercase: "lowercase";
|
|
29
|
+
capitalize: "capitalize";
|
|
30
|
+
}>>;
|
|
31
|
+
textDecoration: z.ZodDefault<z.ZodEnum<{
|
|
32
|
+
none: "none";
|
|
33
|
+
underline: "underline";
|
|
34
|
+
"line-through": "line-through";
|
|
35
|
+
}>>;
|
|
36
|
+
gradient: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
38
|
+
linear: "linear";
|
|
39
|
+
radial: "radial";
|
|
40
|
+
}>>;
|
|
41
|
+
angle: z.ZodDefault<z.ZodNumber>;
|
|
42
|
+
stops: z.ZodArray<z.ZodObject<{
|
|
43
|
+
offset: z.ZodNumber;
|
|
44
|
+
color: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
stroke: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
50
|
+
color: z.ZodDefault<z.ZodString>;
|
|
51
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
shadow: z.ZodOptional<z.ZodObject<{
|
|
54
|
+
offsetX: z.ZodDefault<z.ZodNumber>;
|
|
55
|
+
offsetY: z.ZodDefault<z.ZodNumber>;
|
|
56
|
+
blur: z.ZodDefault<z.ZodNumber>;
|
|
57
|
+
color: z.ZodDefault<z.ZodString>;
|
|
58
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
59
|
+
}, z.core.$strip>>;
|
|
60
|
+
background: z.ZodOptional<z.ZodObject<{
|
|
61
|
+
borderRadius: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
62
|
+
color: z.ZodOptional<z.ZodString>;
|
|
63
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
border: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
67
|
+
color: z.ZodDefault<z.ZodString>;
|
|
68
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
69
|
+
radius: z.ZodDefault<z.ZodNumber>;
|
|
70
|
+
}, z.core.$strip>>;
|
|
71
|
+
padding: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
72
|
+
top: z.ZodDefault<z.ZodNumber>;
|
|
73
|
+
right: z.ZodDefault<z.ZodNumber>;
|
|
74
|
+
bottom: z.ZodDefault<z.ZodNumber>;
|
|
75
|
+
left: z.ZodDefault<z.ZodNumber>;
|
|
76
|
+
}, z.core.$strip>]>>;
|
|
77
|
+
align: z.ZodOptional<z.ZodObject<{
|
|
78
|
+
horizontal: z.ZodDefault<z.ZodEnum<{
|
|
79
|
+
center: "center";
|
|
80
|
+
right: "right";
|
|
81
|
+
left: "left";
|
|
82
|
+
}>>;
|
|
83
|
+
vertical: z.ZodDefault<z.ZodEnum<{
|
|
84
|
+
top: "top";
|
|
85
|
+
bottom: "bottom";
|
|
86
|
+
middle: "middle";
|
|
87
|
+
}>>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
animation: z.ZodOptional<z.ZodObject<{
|
|
90
|
+
preset: z.ZodEnum<{
|
|
91
|
+
typewriter: "typewriter";
|
|
92
|
+
fadeIn: "fadeIn";
|
|
93
|
+
slideIn: "slideIn";
|
|
94
|
+
shift: "shift";
|
|
95
|
+
ascend: "ascend";
|
|
96
|
+
movingLetters: "movingLetters";
|
|
97
|
+
}>;
|
|
98
|
+
speed: z.ZodDefault<z.ZodNumber>;
|
|
99
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
101
|
+
character: "character";
|
|
102
|
+
word: "word";
|
|
103
|
+
}>>;
|
|
104
|
+
direction: z.ZodOptional<z.ZodEnum<{
|
|
105
|
+
right: "right";
|
|
106
|
+
left: "left";
|
|
107
|
+
up: "up";
|
|
108
|
+
down: "down";
|
|
109
|
+
}>>;
|
|
110
|
+
}, z.core.$strip>>;
|
|
111
|
+
customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
112
|
+
src: z.ZodString;
|
|
113
|
+
family: z.ZodString;
|
|
114
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
115
|
+
style: z.ZodOptional<z.ZodString>;
|
|
116
|
+
originalFamily: z.ZodOptional<z.ZodString>;
|
|
117
|
+
}, z.core.$strip>>>;
|
|
118
|
+
}, z.core.$strict>;
|
|
119
|
+
type CanvasRichTextAsset = z.infer<typeof CanvasRichTextAssetSchema>;
|
|
99
120
|
|
|
121
|
+
type ShotstackRichTextAsset = components["schemas"]["RichTextAsset"];
|
|
100
122
|
type RGBA = {
|
|
101
123
|
r: number;
|
|
102
124
|
g: number;
|
|
@@ -218,7 +240,7 @@ type Renderer = {
|
|
|
218
240
|
render(ops: DrawOp[]): Promise<void>;
|
|
219
241
|
toPNG?: () => Promise<Buffer>;
|
|
220
242
|
};
|
|
221
|
-
type ValidAsset =
|
|
243
|
+
type ValidAsset = CanvasRichTextAsset;
|
|
222
244
|
declare const isShadowFill: (op: DrawOp) => op is Extract<DrawOp, {
|
|
223
245
|
op: "FillPath";
|
|
224
246
|
}> & {
|
|
@@ -238,7 +260,7 @@ declare function createTextEngine(opts?: {
|
|
|
238
260
|
wasmBaseURL?: string;
|
|
239
261
|
}): Promise<{
|
|
240
262
|
validate(input: unknown): {
|
|
241
|
-
value:
|
|
263
|
+
value: CanvasRichTextAsset;
|
|
242
264
|
};
|
|
243
265
|
registerFontFromUrl(url: string, desc: {
|
|
244
266
|
family: string;
|
|
@@ -248,11 +270,11 @@ declare function createTextEngine(opts?: {
|
|
|
248
270
|
family: string;
|
|
249
271
|
weight?: string | number;
|
|
250
272
|
}): Promise<void>;
|
|
251
|
-
renderFrame(asset:
|
|
273
|
+
renderFrame(asset: CanvasRichTextAsset, tSeconds: number, clipDuration?: number): Promise<DrawOp[]>;
|
|
252
274
|
createRenderer(canvas: HTMLCanvasElement | OffscreenCanvas): {
|
|
253
275
|
render(ops: DrawOp[]): Promise<void>;
|
|
254
276
|
};
|
|
255
277
|
destroy(): void;
|
|
256
278
|
}>;
|
|
257
279
|
|
|
258
|
-
export { type DrawOp, type EngineInit, type Glyph, type GradientSpec, type RGBA, type Renderer, type ShapedLine, type ValidAsset, createTextEngine, isGlyphFill, isShadowFill };
|
|
280
|
+
export { type CanvasRichTextAsset, CanvasRichTextAssetSchema, type DrawOp, type EngineInit, type Glyph, type GradientSpec, type RGBA, type Renderer, type ShapedLine, type ShotstackRichTextAsset, type ValidAsset, createTextEngine, isGlyphFill, isShadowFill };
|
package/dist/entry.web.js
CHANGED
|
@@ -2,8 +2,18 @@ import {
|
|
|
2
2
|
__publicField
|
|
3
3
|
} from "./chunk-HYGMWVDX.js";
|
|
4
4
|
|
|
5
|
-
// src/schema/
|
|
6
|
-
import
|
|
5
|
+
// src/schema/zod-schema.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import {
|
|
8
|
+
richTextAssetSchema,
|
|
9
|
+
richTextFontSchema,
|
|
10
|
+
richTextStyleSchema,
|
|
11
|
+
richTextStrokeSchema,
|
|
12
|
+
richTextShadowSchema,
|
|
13
|
+
richTextBackgroundSchema,
|
|
14
|
+
richTextAlignmentSchema,
|
|
15
|
+
richTextAnimationSchema
|
|
16
|
+
} from "@shotstack/schemas/zod";
|
|
7
17
|
|
|
8
18
|
// src/config/canvas-constants.ts
|
|
9
19
|
var CANVAS_CONFIG = {
|
|
@@ -37,110 +47,127 @@ var CANVAS_CONFIG = {
|
|
|
37
47
|
]
|
|
38
48
|
};
|
|
39
49
|
|
|
40
|
-
// src/schema/
|
|
50
|
+
// src/schema/zod-schema.ts
|
|
41
51
|
var HEX6 = /^#[A-Fa-f0-9]{6}$/;
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
).min(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
opacity: Joi.number().min(0).max(1).default(1)
|
|
63
|
-
}).unknown(false);
|
|
64
|
-
var fontSchema = Joi.object({
|
|
65
|
-
family: Joi.string().default(CANVAS_CONFIG.DEFAULTS.fontFamily),
|
|
66
|
-
size: Joi.number().min(CANVAS_CONFIG.LIMITS.minFontSize).max(CANVAS_CONFIG.LIMITS.maxFontSize).default(CANVAS_CONFIG.DEFAULTS.fontSize),
|
|
67
|
-
weight: Joi.alternatives().try(Joi.string(), Joi.number()).default("400"),
|
|
68
|
-
color: Joi.string().pattern(HEX6).default(CANVAS_CONFIG.DEFAULTS.color),
|
|
69
|
-
opacity: Joi.number().min(0).max(1).default(1),
|
|
70
|
-
background: Joi.string().pattern(HEX6).optional()
|
|
71
|
-
}).unknown(false);
|
|
72
|
-
var styleSchema = Joi.object({
|
|
73
|
-
letterSpacing: Joi.number().default(0),
|
|
74
|
-
lineHeight: Joi.number().min(0).max(10).default(1.2),
|
|
75
|
-
textTransform: Joi.string().valid("none", "uppercase", "lowercase", "capitalize").default("none"),
|
|
76
|
-
textDecoration: Joi.string().valid("none", "underline", "line-through").default("none"),
|
|
77
|
-
gradient: gradientSchema.optional()
|
|
78
|
-
}).unknown(false);
|
|
79
|
-
var alignmentSchema = Joi.object({
|
|
80
|
-
horizontal: Joi.string().valid("left", "center", "right").default(CANVAS_CONFIG.DEFAULTS.textAlign),
|
|
81
|
-
vertical: Joi.string().valid("top", "middle", "bottom").default("middle")
|
|
82
|
-
}).unknown(false);
|
|
83
|
-
var animationSchema = Joi.object({
|
|
84
|
-
preset: Joi.string().valid(...CANVAS_CONFIG.ANIMATION_TYPES),
|
|
85
|
-
speed: Joi.number().min(0.1).max(10).default(1),
|
|
86
|
-
duration: Joi.number().min(CANVAS_CONFIG.LIMITS.minDuration).max(CANVAS_CONFIG.LIMITS.maxDuration).optional(),
|
|
87
|
-
style: Joi.string().valid("character", "word").optional().when("preset", {
|
|
88
|
-
is: Joi.valid("typewriter", "shift", "fadeIn", "slideIn"),
|
|
89
|
-
then: Joi.optional(),
|
|
90
|
-
otherwise: Joi.forbidden()
|
|
91
|
-
}),
|
|
92
|
-
direction: Joi.string().optional().when("preset", {
|
|
93
|
-
switch: [
|
|
94
|
-
{ is: "ascend", then: Joi.valid("up", "down") },
|
|
95
|
-
{ is: "shift", then: Joi.valid("left", "right", "up", "down") },
|
|
96
|
-
{ is: "slideIn", then: Joi.valid("left", "right", "up", "down") },
|
|
97
|
-
{ is: "movingLetters", then: Joi.valid("left", "right", "up", "down") }
|
|
98
|
-
],
|
|
99
|
-
otherwise: Joi.forbidden()
|
|
52
|
+
var customFontSchema = z.object({
|
|
53
|
+
src: z.string().url(),
|
|
54
|
+
family: z.string(),
|
|
55
|
+
weight: z.union([z.string(), z.number()]).optional(),
|
|
56
|
+
style: z.string().optional(),
|
|
57
|
+
originalFamily: z.string().optional()
|
|
58
|
+
});
|
|
59
|
+
var borderSchema = z.object({
|
|
60
|
+
width: z.number().min(0).default(0),
|
|
61
|
+
color: z.string().regex(HEX6).default("#000000"),
|
|
62
|
+
opacity: z.number().min(0).max(1).default(1),
|
|
63
|
+
radius: z.number().min(0).default(0)
|
|
64
|
+
});
|
|
65
|
+
var paddingSchema = z.union([
|
|
66
|
+
z.number().min(0),
|
|
67
|
+
z.object({
|
|
68
|
+
top: z.number().min(0).default(0),
|
|
69
|
+
right: z.number().min(0).default(0),
|
|
70
|
+
bottom: z.number().min(0).default(0),
|
|
71
|
+
left: z.number().min(0).default(0)
|
|
100
72
|
})
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
73
|
+
]);
|
|
74
|
+
var canvasFontSchema = richTextFontSchema.extend({
|
|
75
|
+
family: z.string().default(CANVAS_CONFIG.DEFAULTS.fontFamily),
|
|
76
|
+
size: z.number().int().min(CANVAS_CONFIG.LIMITS.minFontSize).max(CANVAS_CONFIG.LIMITS.maxFontSize).default(CANVAS_CONFIG.DEFAULTS.fontSize),
|
|
77
|
+
weight: z.union([z.string(), z.number()]).default("400"),
|
|
78
|
+
color: z.string().regex(HEX6).default(CANVAS_CONFIG.DEFAULTS.color),
|
|
79
|
+
opacity: z.number().min(0).max(1).default(1),
|
|
80
|
+
background: z.string().regex(HEX6).optional()
|
|
81
|
+
});
|
|
82
|
+
var canvasGradientSchema = z.object({
|
|
83
|
+
type: z.enum(["linear", "radial"]).default("linear"),
|
|
84
|
+
angle: z.number().min(0).max(360).default(0),
|
|
85
|
+
stops: z.array(z.object({
|
|
86
|
+
offset: z.number().min(0).max(1),
|
|
87
|
+
color: z.string().regex(HEX6)
|
|
88
|
+
})).min(2)
|
|
89
|
+
});
|
|
90
|
+
var canvasStyleSchema = richTextStyleSchema.extend({
|
|
91
|
+
letterSpacing: z.number().default(0),
|
|
92
|
+
lineHeight: z.number().min(0).max(10).default(1.2),
|
|
93
|
+
textTransform: z.enum(["none", "uppercase", "lowercase", "capitalize"]).default("none"),
|
|
94
|
+
textDecoration: z.enum(["none", "underline", "line-through"]).default("none"),
|
|
95
|
+
gradient: canvasGradientSchema.optional()
|
|
96
|
+
});
|
|
97
|
+
var canvasStrokeSchema = richTextStrokeSchema.extend({
|
|
98
|
+
width: z.number().min(0).default(0),
|
|
99
|
+
color: z.string().regex(HEX6).default("#000000"),
|
|
100
|
+
opacity: z.number().min(0).max(1).default(1)
|
|
101
|
+
});
|
|
102
|
+
var canvasShadowSchema = richTextShadowSchema.extend({
|
|
103
|
+
offsetX: z.number().default(0),
|
|
104
|
+
offsetY: z.number().default(0),
|
|
105
|
+
blur: z.number().min(0).default(0),
|
|
106
|
+
color: z.string().regex(HEX6).default("#000000"),
|
|
107
|
+
opacity: z.number().min(0).max(1).default(0.5)
|
|
108
|
+
});
|
|
109
|
+
var canvasBackgroundSchema = richTextBackgroundSchema.extend({
|
|
110
|
+
color: z.string().regex(HEX6).optional(),
|
|
111
|
+
opacity: z.number().min(0).max(1).default(1)
|
|
112
|
+
});
|
|
113
|
+
var canvasAlignmentSchema = richTextAlignmentSchema.extend({
|
|
114
|
+
horizontal: z.enum(["left", "center", "right"]).default(CANVAS_CONFIG.DEFAULTS.textAlign),
|
|
115
|
+
vertical: z.enum(["top", "middle", "bottom"]).default("middle")
|
|
116
|
+
});
|
|
117
|
+
var canvasAnimationSchema = richTextAnimationSchema.extend({
|
|
118
|
+
preset: z.enum(CANVAS_CONFIG.ANIMATION_TYPES),
|
|
119
|
+
speed: z.number().min(0.1).max(10).default(1),
|
|
120
|
+
duration: z.number().min(CANVAS_CONFIG.LIMITS.minDuration).max(CANVAS_CONFIG.LIMITS.maxDuration).optional(),
|
|
121
|
+
style: z.enum(["character", "word"]).optional(),
|
|
122
|
+
direction: z.enum(["left", "right", "up", "down"]).optional()
|
|
123
|
+
}).superRefine((data, ctx) => {
|
|
124
|
+
const presetsWithStyle = ["typewriter", "shift", "fadeIn", "slideIn"];
|
|
125
|
+
if (data.style && !presetsWithStyle.includes(data.preset)) {
|
|
126
|
+
ctx.addIssue({
|
|
127
|
+
code: z.ZodIssueCode.custom,
|
|
128
|
+
message: `style is not allowed for preset "${data.preset}"`,
|
|
129
|
+
path: ["style"]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const directionRules = {
|
|
133
|
+
ascend: ["up", "down"],
|
|
134
|
+
shift: ["left", "right", "up", "down"],
|
|
135
|
+
slideIn: ["left", "right", "up", "down"],
|
|
136
|
+
movingLetters: ["left", "right", "up", "down"]
|
|
137
|
+
};
|
|
138
|
+
if (data.direction) {
|
|
139
|
+
const allowedDirections = directionRules[data.preset];
|
|
140
|
+
if (!allowedDirections) {
|
|
141
|
+
ctx.addIssue({
|
|
142
|
+
code: z.ZodIssueCode.custom,
|
|
143
|
+
message: `direction is not allowed for preset "${data.preset}"`,
|
|
144
|
+
path: ["direction"]
|
|
145
|
+
});
|
|
146
|
+
} else if (!allowedDirections.includes(data.direction)) {
|
|
147
|
+
ctx.addIssue({
|
|
148
|
+
code: z.ZodIssueCode.custom,
|
|
149
|
+
message: `direction "${data.direction}" is not valid for preset "${data.preset}"`,
|
|
150
|
+
path: ["direction"]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
var CanvasRichTextAssetSchema = richTextAssetSchema.extend({
|
|
156
|
+
type: z.literal("rich-text"),
|
|
157
|
+
text: z.string().max(CANVAS_CONFIG.LIMITS.maxTextLength).default(""),
|
|
158
|
+
width: z.number().int().min(CANVAS_CONFIG.LIMITS.minWidth).max(CANVAS_CONFIG.LIMITS.maxWidth).default(CANVAS_CONFIG.DEFAULTS.width).optional(),
|
|
159
|
+
height: z.number().int().min(CANVAS_CONFIG.LIMITS.minHeight).max(CANVAS_CONFIG.LIMITS.maxHeight).default(CANVAS_CONFIG.DEFAULTS.height).optional(),
|
|
160
|
+
font: canvasFontSchema.optional(),
|
|
161
|
+
style: canvasStyleSchema.optional(),
|
|
162
|
+
stroke: canvasStrokeSchema.optional(),
|
|
163
|
+
shadow: canvasShadowSchema.optional(),
|
|
164
|
+
background: canvasBackgroundSchema.optional(),
|
|
138
165
|
border: borderSchema.optional(),
|
|
139
166
|
padding: paddingSchema.optional(),
|
|
140
|
-
align:
|
|
141
|
-
animation:
|
|
142
|
-
customFonts:
|
|
143
|
-
}).
|
|
167
|
+
align: canvasAlignmentSchema.optional(),
|
|
168
|
+
animation: canvasAnimationSchema.optional(),
|
|
169
|
+
customFonts: z.array(customFontSchema).optional()
|
|
170
|
+
}).strict();
|
|
144
171
|
|
|
145
172
|
// src/wasm/hb-loader.ts
|
|
146
173
|
var hbSingleton = null;
|
|
@@ -2133,19 +2160,12 @@ async function createTextEngine(opts = {}) {
|
|
|
2133
2160
|
}
|
|
2134
2161
|
return {
|
|
2135
2162
|
validate(input) {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
});
|
|
2141
|
-
if (error) throw error;
|
|
2142
|
-
return { value };
|
|
2143
|
-
} catch (err) {
|
|
2144
|
-
if (err instanceof Error) {
|
|
2145
|
-
throw new Error(`Validation failed: ${err.message}`);
|
|
2146
|
-
}
|
|
2147
|
-
throw new Error(`Validation failed: ${String(err)}`);
|
|
2163
|
+
const result = CanvasRichTextAssetSchema.safeParse(input);
|
|
2164
|
+
if (!result.success) {
|
|
2165
|
+
const messages = result.error.issues.map((i) => i.message).join(". ");
|
|
2166
|
+
throw new Error(`Validation failed: ${messages}`);
|
|
2148
2167
|
}
|
|
2168
|
+
return { value: result.data };
|
|
2149
2169
|
},
|
|
2150
2170
|
async registerFontFromUrl(url, desc) {
|
|
2151
2171
|
try {
|
|
@@ -2321,6 +2341,7 @@ async function createTextEngine(opts = {}) {
|
|
|
2321
2341
|
};
|
|
2322
2342
|
}
|
|
2323
2343
|
export {
|
|
2344
|
+
CanvasRichTextAssetSchema,
|
|
2324
2345
|
createTextEngine,
|
|
2325
2346
|
isGlyphFill2 as isGlyphFill,
|
|
2326
2347
|
isShadowFill2 as isShadowFill
|