@velumo/core 0.1.0-beta.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/background-validation.d.ts +3 -0
- package/dist/background-validation.d.ts.map +1 -0
- package/dist/background-validation.js +177 -0
- package/dist/background-validation.js.map +1 -0
- package/dist/builders.d.ts +134 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/builders.js +332 -0
- package/dist/builders.js.map +1 -0
- package/dist/capabilities.d.ts +7 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +59 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/layout-validation.d.ts +4 -0
- package/dist/layout-validation.d.ts.map +1 -0
- package/dist/layout-validation.js +745 -0
- package/dist/layout-validation.js.map +1 -0
- package/dist/manifest-schema.d.ts +1328 -0
- package/dist/manifest-schema.d.ts.map +1 -0
- package/dist/manifest-schema.js +774 -0
- package/dist/manifest-schema.js.map +1 -0
- package/dist/theme-validation.d.ts +3 -0
- package/dist/theme-validation.d.ts.map +1 -0
- package/dist/theme-validation.js +239 -0
- package/dist/theme-validation.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +398 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validation-issue.d.ts +18 -0
- package/dist/validation-issue.d.ts.map +1 -0
- package/dist/validation-issue.js +30 -0
- package/dist/validation-issue.js.map +1 -0
- package/dist/validation.d.ts +4 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +274 -0
- package/dist/validation.js.map +1 -0
- package/package.json +16 -0
- package/src/background-validation.ts +315 -0
- package/src/builders.ts +626 -0
- package/src/capabilities.ts +99 -0
- package/src/index.ts +147 -0
- package/src/layout-validation.ts +1385 -0
- package/src/manifest-schema.ts +823 -0
- package/src/theme-validation.ts +410 -0
- package/src/types.ts +560 -0
- package/src/validation-issue.ts +43 -0
- package/src/validation.ts +468 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { validateBackground } from "./background-validation.js";
|
|
2
|
+
import { validateLayoutNode } from "./layout-validation.js";
|
|
3
|
+
import { validateTheme } from "./theme-validation.js";
|
|
4
|
+
import { describeType, issue } from "./validation-issue.js";
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function isNonEmptyString(value) {
|
|
9
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
10
|
+
}
|
|
11
|
+
function typeIssue(path, message, expected, received) {
|
|
12
|
+
return issue(path, "wrong_type", message, {
|
|
13
|
+
expected,
|
|
14
|
+
received: describeType(received),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function requiredIssue(path, message) {
|
|
18
|
+
return issue(path, "required", message, {
|
|
19
|
+
suggestion: `Provide a value for \`${path}\`.`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const CAMERA_EASINGS = [
|
|
23
|
+
"linear",
|
|
24
|
+
"ease",
|
|
25
|
+
"ease-in",
|
|
26
|
+
"ease-out",
|
|
27
|
+
"ease-in-out",
|
|
28
|
+
];
|
|
29
|
+
const CAMERA_VIEW_KEYS = new Set(["x", "y", "zoom"]);
|
|
30
|
+
const CAMERA_TRANSITION_KEYS = new Set(["duration", "easing"]);
|
|
31
|
+
const CAMERA_STOP_KEYS = new Set(["camera", "transition", "cues", "hold"]);
|
|
32
|
+
function isPercent(value) {
|
|
33
|
+
return (typeof value === "number" &&
|
|
34
|
+
Number.isFinite(value) &&
|
|
35
|
+
value >= 0 &&
|
|
36
|
+
value <= 100);
|
|
37
|
+
}
|
|
38
|
+
function valueIssue(path, message, received) {
|
|
39
|
+
return issue(path, "invalid_value", message, {
|
|
40
|
+
received: describeType(received),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function unknownFieldIssues(record, allowed, path) {
|
|
44
|
+
return Object.keys(record)
|
|
45
|
+
.filter((key) => !allowed.has(key))
|
|
46
|
+
.map((key) => issue(`${path}.${key}`, "unknown_field", `${path}.${key} is not allowed`, {
|
|
47
|
+
expected: [...allowed].join(", "),
|
|
48
|
+
suggestion: `Remove \`${key}\`; it is not a recognized field here.`,
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
function validateCameraView(view, path) {
|
|
52
|
+
if (!isRecord(view)) {
|
|
53
|
+
return [typeIssue(path, `${path} must be an object`, "object", view)];
|
|
54
|
+
}
|
|
55
|
+
const issues = [];
|
|
56
|
+
for (const axis of ["x", "y"]) {
|
|
57
|
+
if (view[axis] === undefined) {
|
|
58
|
+
issues.push(requiredIssue(`${path}.${axis}`, `${path}.${axis} is required`));
|
|
59
|
+
}
|
|
60
|
+
else if (!isPercent(view[axis])) {
|
|
61
|
+
issues.push(valueIssue(`${path}.${axis}`, `${path}.${axis} must be a percentage 0-100`, view[axis]));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (view.zoom !== undefined) {
|
|
65
|
+
if (typeof view.zoom !== "number" ||
|
|
66
|
+
!Number.isFinite(view.zoom) ||
|
|
67
|
+
view.zoom <= 0) {
|
|
68
|
+
issues.push(valueIssue(`${path}.zoom`, `${path}.zoom must be a number > 0`, view.zoom));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
issues.push(...unknownFieldIssues(view, CAMERA_VIEW_KEYS, path));
|
|
72
|
+
return issues;
|
|
73
|
+
}
|
|
74
|
+
function validateCameraTransition(transition, path) {
|
|
75
|
+
if (!isRecord(transition)) {
|
|
76
|
+
return [typeIssue(path, `${path} must be an object`, "object", transition)];
|
|
77
|
+
}
|
|
78
|
+
const issues = [];
|
|
79
|
+
if (transition.duration !== undefined) {
|
|
80
|
+
if (typeof transition.duration !== "number" ||
|
|
81
|
+
!Number.isFinite(transition.duration) ||
|
|
82
|
+
transition.duration < 0) {
|
|
83
|
+
issues.push(valueIssue(`${path}.duration`, `${path}.duration must be a number >= 0`, transition.duration));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (transition.easing !== undefined &&
|
|
87
|
+
!CAMERA_EASINGS.includes(transition.easing)) {
|
|
88
|
+
issues.push(issue(`${path}.easing`, "invalid_enum", `${path}.easing must be a known easing`, {
|
|
89
|
+
expected: CAMERA_EASINGS.join(", "),
|
|
90
|
+
received: typeof transition.easing === "string"
|
|
91
|
+
? transition.easing
|
|
92
|
+
: describeType(transition.easing),
|
|
93
|
+
suggestion: `Use one of: ${CAMERA_EASINGS.join(", ")}.`,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
issues.push(...unknownFieldIssues(transition, CAMERA_TRANSITION_KEYS, path));
|
|
97
|
+
return issues;
|
|
98
|
+
}
|
|
99
|
+
function validateCameraStop(stop, path) {
|
|
100
|
+
if (!isRecord(stop)) {
|
|
101
|
+
return [typeIssue(path, `${path} must be an object`, "object", stop)];
|
|
102
|
+
}
|
|
103
|
+
const issues = [];
|
|
104
|
+
if (stop.camera === undefined) {
|
|
105
|
+
issues.push(requiredIssue(`${path}.camera`, `${path}.camera is required`));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
issues.push(...validateCameraView(stop.camera, `${path}.camera`));
|
|
109
|
+
}
|
|
110
|
+
if (stop.transition !== undefined) {
|
|
111
|
+
issues.push(...validateCameraTransition(stop.transition, `${path}.transition`));
|
|
112
|
+
}
|
|
113
|
+
if (stop.cues !== undefined) {
|
|
114
|
+
if (!Array.isArray(stop.cues)) {
|
|
115
|
+
issues.push(typeIssue(`${path}.cues`, `${path}.cues must be an array`, "array", stop.cues));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
stop.cues.forEach((cue, cueIndex) => {
|
|
119
|
+
const cuePath = `${path}.cues[${cueIndex}]`;
|
|
120
|
+
if (!isRecord(cue)) {
|
|
121
|
+
issues.push(typeIssue(cuePath, `${cuePath} must be an object`, "object", cue));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (typeof cue.time !== "number") {
|
|
125
|
+
issues.push(requiredIssue(`${cuePath}.time`, `${cuePath}.time is required`));
|
|
126
|
+
}
|
|
127
|
+
else if (!Number.isFinite(cue.time) || cue.time < 0) {
|
|
128
|
+
issues.push(valueIssue(`${cuePath}.time`, `${cuePath}.time must be a finite number >= 0`, cue.time));
|
|
129
|
+
}
|
|
130
|
+
if (!isRecord(cue.action) || typeof cue.action.type !== "string") {
|
|
131
|
+
issues.push(requiredIssue(`${cuePath}.action`, `${cuePath}.action.type is required`));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (stop.hold !== undefined) {
|
|
137
|
+
if (typeof stop.hold !== "number" ||
|
|
138
|
+
!Number.isFinite(stop.hold) ||
|
|
139
|
+
stop.hold < 0) {
|
|
140
|
+
issues.push(valueIssue(`${path}.hold`, `${path}.hold must be a number >= 0`, stop.hold));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
issues.push(...unknownFieldIssues(stop, CAMERA_STOP_KEYS, path));
|
|
144
|
+
return issues;
|
|
145
|
+
}
|
|
146
|
+
function validateCameraPath(value, path) {
|
|
147
|
+
if (!Array.isArray(value)) {
|
|
148
|
+
return [typeIssue(path, `${path} must be an array`, "array", value)];
|
|
149
|
+
}
|
|
150
|
+
const issues = [];
|
|
151
|
+
if (value.length === 0) {
|
|
152
|
+
issues.push(issue(path, "constraint", `${path} must contain at least one stop`, {
|
|
153
|
+
suggestion: "Add a cameraStop, or remove the empty cameraPath.",
|
|
154
|
+
}));
|
|
155
|
+
return issues;
|
|
156
|
+
}
|
|
157
|
+
value.forEach((stop, index) => {
|
|
158
|
+
issues.push(...validateCameraStop(stop, `${path}[${index}]`));
|
|
159
|
+
});
|
|
160
|
+
return issues;
|
|
161
|
+
}
|
|
162
|
+
function validateSlideEntry(entry, index) {
|
|
163
|
+
const issues = [];
|
|
164
|
+
const path = `slides[${index}]`;
|
|
165
|
+
if (!isRecord(entry)) {
|
|
166
|
+
return [typeIssue(path, `${path} must be an object`, "object", entry)];
|
|
167
|
+
}
|
|
168
|
+
if (!isNonEmptyString(entry.id)) {
|
|
169
|
+
issues.push(requiredIssue(`${path}.id`, `${path}.id is required`));
|
|
170
|
+
}
|
|
171
|
+
if (entry.layout !== undefined) {
|
|
172
|
+
issues.push(...validateLayoutNode(entry.layout, `${path}.layout`));
|
|
173
|
+
}
|
|
174
|
+
if (Array.isArray(entry.layers)) {
|
|
175
|
+
entry.layers.forEach((layer, layerIndex) => {
|
|
176
|
+
const layerPath = `${path}.layers[${layerIndex}]`;
|
|
177
|
+
if (!isRecord(layer)) {
|
|
178
|
+
issues.push(typeIssue(layerPath, `${layerPath} must be an object`, "object", layer));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!isNonEmptyString(layer.type)) {
|
|
182
|
+
issues.push(requiredIssue(`${layerPath}.type`, `${layerPath}.type is required`));
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (Array.isArray(entry.cues)) {
|
|
187
|
+
entry.cues.forEach((cue, cueIndex) => {
|
|
188
|
+
const cuePath = `${path}.cues[${cueIndex}]`;
|
|
189
|
+
if (!isRecord(cue)) {
|
|
190
|
+
issues.push(typeIssue(cuePath, `${cuePath} must be an object`, "object", cue));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (typeof cue.time !== "number") {
|
|
194
|
+
issues.push(requiredIssue(`${cuePath}.time`, `${cuePath}.time is required`));
|
|
195
|
+
}
|
|
196
|
+
else if (!Number.isFinite(cue.time) || cue.time < 0) {
|
|
197
|
+
issues.push(valueIssue(`${cuePath}.time`, `${cuePath}.time must be a finite number >= 0`, cue.time));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(entry.fragments)) {
|
|
202
|
+
entry.fragments.forEach((fragment, fragmentIndex) => {
|
|
203
|
+
const fragmentPath = `${path}.fragments[${fragmentIndex}]`;
|
|
204
|
+
if (!isRecord(fragment)) {
|
|
205
|
+
issues.push(typeIssue(fragmentPath, `${fragmentPath} must be an object`, "object", fragment));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!isNonEmptyString(fragment.id)) {
|
|
209
|
+
issues.push(requiredIssue(`${fragmentPath}.id`, `${fragmentPath}.id is required`));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (entry.background !== undefined) {
|
|
214
|
+
issues.push(...validateBackground(entry.background, `${path}.background`));
|
|
215
|
+
}
|
|
216
|
+
if (entry.cameraPath !== undefined) {
|
|
217
|
+
if (entry.kind !== "scene") {
|
|
218
|
+
issues.push(issue(`${path}.cameraPath`, "unknown_field", `${path}.cameraPath is only allowed on a scene (kind: "scene")`, {
|
|
219
|
+
suggestion: `Change this entry's kind to "scene", or remove cameraPath.`,
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
issues.push(...validateCameraPath(entry.cameraPath, `${path}.cameraPath`));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (entry.chrome !== undefined && typeof entry.chrome !== "boolean") {
|
|
227
|
+
issues.push(typeIssue(`${path}.chrome`, `${path}.chrome must be a boolean`, "boolean", entry.chrome));
|
|
228
|
+
}
|
|
229
|
+
return issues;
|
|
230
|
+
}
|
|
231
|
+
function collectIssues(manifest) {
|
|
232
|
+
if (!isRecord(manifest)) {
|
|
233
|
+
return [
|
|
234
|
+
typeIssue("manifest", "manifest must be an object", "object", manifest),
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
const issues = [];
|
|
238
|
+
if (!isRecord(manifest.deck)) {
|
|
239
|
+
issues.push(typeIssue("deck", "deck must be an object", "object", manifest.deck));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (!isNonEmptyString(manifest.deck.title)) {
|
|
243
|
+
issues.push(requiredIssue("deck.title", "deck.title is required"));
|
|
244
|
+
}
|
|
245
|
+
if (manifest.deck.watermark !== undefined &&
|
|
246
|
+
typeof manifest.deck.watermark !== "string") {
|
|
247
|
+
issues.push(typeIssue("deck.watermark", "deck.watermark must be a string", "string", manifest.deck.watermark));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (!Array.isArray(manifest.slides)) {
|
|
251
|
+
issues.push(typeIssue("slides", "slides must be an array", "array", manifest.slides));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
manifest.slides.forEach((slide, index) => {
|
|
255
|
+
issues.push(...validateSlideEntry(slide, index));
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (manifest.theme !== undefined) {
|
|
259
|
+
issues.push(...validateTheme(manifest.theme));
|
|
260
|
+
}
|
|
261
|
+
return issues;
|
|
262
|
+
}
|
|
263
|
+
export function validateManifest(manifest) {
|
|
264
|
+
const issues = collectIssues(manifest);
|
|
265
|
+
return {
|
|
266
|
+
valid: issues.length === 0,
|
|
267
|
+
errors: issues.map((current) => current.message),
|
|
268
|
+
issues,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export function isValidManifest(manifest) {
|
|
272
|
+
return validateManifest(manifest).valid;
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI5D,SAAS,QAAQ,CAA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"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -b"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import type { ValidationIssue } from "./types.js";
|
|
2
|
+
import { describeType, issue } from "./validation-issue.js";
|
|
3
|
+
|
|
4
|
+
type IndexedRecord = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
const BLEND_MODES = ["normal", "screen", "multiply", "overlay"] as const;
|
|
7
|
+
const SHAPE_VALUES = ["circle", "ellipse"] as const;
|
|
8
|
+
const BACKGROUND_KEYS = new Set(["color", "layers"]);
|
|
9
|
+
const LINEAR_KEYS = new Set(["type", "stops", "angle", "blend", "opacity"]);
|
|
10
|
+
const RADIAL_KEYS = new Set([
|
|
11
|
+
"type",
|
|
12
|
+
"stops",
|
|
13
|
+
"shape",
|
|
14
|
+
"position",
|
|
15
|
+
"blend",
|
|
16
|
+
"opacity",
|
|
17
|
+
]);
|
|
18
|
+
const STOP_KEYS = new Set(["color", "at"]);
|
|
19
|
+
const POSITION_KEYS = new Set(["x", "y"]);
|
|
20
|
+
const LAYER_TYPES = "linear, radial";
|
|
21
|
+
|
|
22
|
+
function isRecord(value: unknown): value is IndexedRecord {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isNonEmptyString(value: unknown): value is string {
|
|
27
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isFiniteInRange(value: unknown, min: number, max: number): boolean {
|
|
31
|
+
return (
|
|
32
|
+
typeof value === "number" &&
|
|
33
|
+
Number.isFinite(value) &&
|
|
34
|
+
value >= min &&
|
|
35
|
+
value <= max
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function typeIssue(
|
|
40
|
+
path: string,
|
|
41
|
+
message: string,
|
|
42
|
+
expected: string,
|
|
43
|
+
received: unknown,
|
|
44
|
+
): ValidationIssue {
|
|
45
|
+
return issue(path, "wrong_type", message, {
|
|
46
|
+
expected,
|
|
47
|
+
received: describeType(received),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function requiredIssue(path: string, message: string): ValidationIssue {
|
|
52
|
+
return issue(path, "required", message, {
|
|
53
|
+
suggestion: `Provide a value for \`${path}\`.`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function enumIssue(
|
|
58
|
+
path: string,
|
|
59
|
+
message: string,
|
|
60
|
+
allowed: readonly string[],
|
|
61
|
+
received: unknown,
|
|
62
|
+
): ValidationIssue {
|
|
63
|
+
return issue(path, "invalid_enum", message, {
|
|
64
|
+
expected: allowed.join(", "),
|
|
65
|
+
received: typeof received === "string" ? received : describeType(received),
|
|
66
|
+
suggestion: `Use one of: ${allowed.join(", ")}.`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function valueIssue(
|
|
71
|
+
path: string,
|
|
72
|
+
message: string,
|
|
73
|
+
received: unknown,
|
|
74
|
+
): ValidationIssue {
|
|
75
|
+
return issue(path, "invalid_value", message, {
|
|
76
|
+
received:
|
|
77
|
+
typeof received === "number" ? String(received) : describeType(received),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function unknownFields(
|
|
82
|
+
node: IndexedRecord,
|
|
83
|
+
allowed: ReadonlySet<string>,
|
|
84
|
+
path: string,
|
|
85
|
+
): readonly ValidationIssue[] {
|
|
86
|
+
return Object.keys(node)
|
|
87
|
+
.filter((key) => !allowed.has(key))
|
|
88
|
+
.map((key) =>
|
|
89
|
+
issue(
|
|
90
|
+
`${path}.${key}`,
|
|
91
|
+
"unknown_field",
|
|
92
|
+
`${path}.${key} is not allowed`,
|
|
93
|
+
{
|
|
94
|
+
expected: [...allowed].join(", "),
|
|
95
|
+
suggestion: `Remove \`${key}\`; it is not a recognized field here.`,
|
|
96
|
+
},
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function validateStop(
|
|
102
|
+
value: unknown,
|
|
103
|
+
path: string,
|
|
104
|
+
): readonly ValidationIssue[] {
|
|
105
|
+
if (!isRecord(value)) {
|
|
106
|
+
return [typeIssue(path, `${path} must be an object`, "object", value)];
|
|
107
|
+
}
|
|
108
|
+
const issues: ValidationIssue[] = [];
|
|
109
|
+
issues.push(...unknownFields(value, STOP_KEYS, path));
|
|
110
|
+
if (!isNonEmptyString(value.color)) {
|
|
111
|
+
issues.push(requiredIssue(`${path}.color`, `${path}.color is required`));
|
|
112
|
+
}
|
|
113
|
+
if (value.at !== undefined && !isFiniteInRange(value.at, 0, 100)) {
|
|
114
|
+
issues.push(
|
|
115
|
+
valueIssue(
|
|
116
|
+
`${path}.at`,
|
|
117
|
+
`${path}.at must be a percentage 0-100`,
|
|
118
|
+
value.at,
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return issues;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function validateStops(
|
|
126
|
+
value: unknown,
|
|
127
|
+
path: string,
|
|
128
|
+
): readonly ValidationIssue[] {
|
|
129
|
+
if (!Array.isArray(value)) {
|
|
130
|
+
if (value === undefined) {
|
|
131
|
+
return [requiredIssue(path, `${path} is required`)];
|
|
132
|
+
}
|
|
133
|
+
return [typeIssue(path, `${path} must be an array`, "array", value)];
|
|
134
|
+
}
|
|
135
|
+
if (value.length === 0) {
|
|
136
|
+
return [
|
|
137
|
+
issue(path, "required", `${path} must have at least one stop`, {
|
|
138
|
+
suggestion: "A gradient needs one or more color stops.",
|
|
139
|
+
}),
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
const issues: ValidationIssue[] = [];
|
|
143
|
+
value.forEach((stop, index) => {
|
|
144
|
+
issues.push(...validateStop(stop, `${path}[${index}]`));
|
|
145
|
+
});
|
|
146
|
+
return issues;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function validateCompositing(
|
|
150
|
+
node: IndexedRecord,
|
|
151
|
+
path: string,
|
|
152
|
+
): readonly ValidationIssue[] {
|
|
153
|
+
const issues: ValidationIssue[] = [];
|
|
154
|
+
if (
|
|
155
|
+
node.blend !== undefined &&
|
|
156
|
+
!(
|
|
157
|
+
typeof node.blend === "string" &&
|
|
158
|
+
BLEND_MODES.includes(node.blend as never)
|
|
159
|
+
)
|
|
160
|
+
) {
|
|
161
|
+
issues.push(
|
|
162
|
+
enumIssue(
|
|
163
|
+
`${path}.blend`,
|
|
164
|
+
`${path}.blend must be normal, screen, multiply, or overlay`,
|
|
165
|
+
BLEND_MODES,
|
|
166
|
+
node.blend,
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (node.opacity !== undefined && !isFiniteInRange(node.opacity, 0, 1)) {
|
|
171
|
+
issues.push(
|
|
172
|
+
valueIssue(
|
|
173
|
+
`${path}.opacity`,
|
|
174
|
+
`${path}.opacity must be a number 0-1`,
|
|
175
|
+
node.opacity,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return issues;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function validateLayer(
|
|
183
|
+
value: unknown,
|
|
184
|
+
path: string,
|
|
185
|
+
): readonly ValidationIssue[] {
|
|
186
|
+
if (!isRecord(value)) {
|
|
187
|
+
return [typeIssue(path, `${path} must be an object`, "object", value)];
|
|
188
|
+
}
|
|
189
|
+
const issues: ValidationIssue[] = [];
|
|
190
|
+
|
|
191
|
+
if (value.type === "linear") {
|
|
192
|
+
issues.push(...unknownFields(value, LINEAR_KEYS, path));
|
|
193
|
+
issues.push(...validateStops(value.stops, `${path}.stops`));
|
|
194
|
+
if (
|
|
195
|
+
value.angle !== undefined &&
|
|
196
|
+
!(typeof value.angle === "number" && Number.isFinite(value.angle))
|
|
197
|
+
) {
|
|
198
|
+
issues.push(
|
|
199
|
+
valueIssue(
|
|
200
|
+
`${path}.angle`,
|
|
201
|
+
`${path}.angle must be a finite number`,
|
|
202
|
+
value.angle,
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
issues.push(...validateCompositing(value, path));
|
|
207
|
+
} else if (value.type === "radial") {
|
|
208
|
+
issues.push(...unknownFields(value, RADIAL_KEYS, path));
|
|
209
|
+
issues.push(...validateStops(value.stops, `${path}.stops`));
|
|
210
|
+
if (
|
|
211
|
+
value.shape !== undefined &&
|
|
212
|
+
!(
|
|
213
|
+
typeof value.shape === "string" &&
|
|
214
|
+
SHAPE_VALUES.includes(value.shape as never)
|
|
215
|
+
)
|
|
216
|
+
) {
|
|
217
|
+
issues.push(
|
|
218
|
+
enumIssue(
|
|
219
|
+
`${path}.shape`,
|
|
220
|
+
`${path}.shape must be circle or ellipse`,
|
|
221
|
+
SHAPE_VALUES,
|
|
222
|
+
value.shape,
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (value.position !== undefined) {
|
|
227
|
+
if (!isRecord(value.position)) {
|
|
228
|
+
issues.push(
|
|
229
|
+
typeIssue(
|
|
230
|
+
`${path}.position`,
|
|
231
|
+
`${path}.position must be an object`,
|
|
232
|
+
"object",
|
|
233
|
+
value.position,
|
|
234
|
+
),
|
|
235
|
+
);
|
|
236
|
+
} else {
|
|
237
|
+
issues.push(
|
|
238
|
+
...unknownFields(value.position, POSITION_KEYS, `${path}.position`),
|
|
239
|
+
);
|
|
240
|
+
for (const axis of ["x", "y"] as const) {
|
|
241
|
+
if (!isFiniteInRange(value.position[axis], 0, 100)) {
|
|
242
|
+
issues.push(
|
|
243
|
+
valueIssue(
|
|
244
|
+
`${path}.position.${axis}`,
|
|
245
|
+
`${path}.position.${axis} must be a percentage 0-100`,
|
|
246
|
+
value.position[axis],
|
|
247
|
+
),
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
issues.push(...validateCompositing(value, path));
|
|
254
|
+
} else {
|
|
255
|
+
issues.push(
|
|
256
|
+
issue(
|
|
257
|
+
`${path}.type`,
|
|
258
|
+
"unknown_kind",
|
|
259
|
+
`${path}.type must be a known gradient type`,
|
|
260
|
+
{
|
|
261
|
+
expected: LAYER_TYPES,
|
|
262
|
+
received:
|
|
263
|
+
typeof value.type === "string"
|
|
264
|
+
? value.type
|
|
265
|
+
: describeType(value.type),
|
|
266
|
+
suggestion: `Use one of: ${LAYER_TYPES}.`,
|
|
267
|
+
},
|
|
268
|
+
),
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return issues;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function validateBackground(
|
|
275
|
+
value: unknown,
|
|
276
|
+
path: string,
|
|
277
|
+
): readonly ValidationIssue[] {
|
|
278
|
+
if (!isRecord(value)) {
|
|
279
|
+
return [typeIssue(path, `${path} must be an object`, "object", value)];
|
|
280
|
+
}
|
|
281
|
+
const issues: ValidationIssue[] = [];
|
|
282
|
+
issues.push(...unknownFields(value, BACKGROUND_KEYS, path));
|
|
283
|
+
|
|
284
|
+
if (value.color !== undefined && !isNonEmptyString(value.color)) {
|
|
285
|
+
issues.push(
|
|
286
|
+
value.color === ""
|
|
287
|
+
? requiredIssue(`${path}.color`, `${path}.color must not be empty`)
|
|
288
|
+
: typeIssue(
|
|
289
|
+
`${path}.color`,
|
|
290
|
+
`${path}.color must be a string`,
|
|
291
|
+
"string",
|
|
292
|
+
value.color,
|
|
293
|
+
),
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (value.layers !== undefined) {
|
|
298
|
+
if (!Array.isArray(value.layers)) {
|
|
299
|
+
issues.push(
|
|
300
|
+
typeIssue(
|
|
301
|
+
`${path}.layers`,
|
|
302
|
+
`${path}.layers must be an array`,
|
|
303
|
+
"array",
|
|
304
|
+
value.layers,
|
|
305
|
+
),
|
|
306
|
+
);
|
|
307
|
+
} else {
|
|
308
|
+
value.layers.forEach((layer, index) => {
|
|
309
|
+
issues.push(...validateLayer(layer, `${path}.layers[${index}]`));
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return issues;
|
|
315
|
+
}
|