@fleox/agentphoto 0.0.0-stage → 0.1.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/LICENSE +143 -0
- package/README.md +229 -2
- package/changelog.json +17 -0
- package/dist/agent/agentphoto.mjs +3307 -0
- package/dist/agent/chunks/assets-CDQo3VqD.mjs +151 -0
- package/dist/agent/chunks/catalog-DIZ5dnH5.mjs +953 -0
- package/dist/agent/chunks/context-DoLoLF9f.mjs +75 -0
- package/dist/agent/chunks/doc-BjY_j4Su.mjs +773 -0
- package/dist/agent/chunks/export-CLmpFART.mjs +140 -0
- package/dist/agent/chunks/ids-DAmiNwd9.mjs +28 -0
- package/dist/agent/chunks/imageInfo-QxAfu8R6.mjs +173 -0
- package/dist/agent/chunks/jsonPath-B7vAPXsi.mjs +155 -0
- package/dist/agent/chunks/library-C_EXiphj.mjs +16 -0
- package/dist/agent/chunks/models-C4i_hicr.mjs +387 -0
- package/dist/agent/chunks/output-3F12IR9O.mjs +130 -0
- package/dist/agent/chunks/package-DSmAxrla.mjs +71 -0
- package/dist/agent/chunks/project-CUykGysG.mjs +198 -0
- package/dist/agent/chunks/rolldown-runtime-CMQPkI6i.mjs +18 -0
- package/dist/agent/chunks/server-I0trf5tM.mjs +241 -0
- package/dist/agent/chunks/templates--YGpGuHh.mjs +40 -0
- package/dist/agent/chunks/tools-Dnh8g6F9.mjs +1354 -0
- package/dist/agent/chunks/tree-DO7N0UDV.mjs +127 -0
- package/dist/agent/chunks/types-DOK7tAAu.mjs +30 -0
- package/dist/agent/chunks/validate-CXPFB-i6.mjs +936 -0
- package/dist/engine/agentphoto-engine.js +2777 -0
- package/dist/engine/chunks/transformers.web-D5Vsg6-A.js +18494 -0
- package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.mjs +124 -0
- package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.wasm +0 -0
- package/dist/studio/assets/index-Be8JnaFy.js +28 -0
- package/dist/studio/assets/index-DwPms2S5.css +1 -0
- package/dist/studio/assets/transformers.web-DgnCIB_X.js +38 -0
- package/dist/studio/index.html +15 -0
- package/dist/studio/library/LICENSES.md +57 -0
- package/dist/studio/library/fonts/OFL.txt +90 -0
- package/dist/studio/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/LICENSE.txt +202 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/images/city.jpg +0 -0
- package/dist/studio/library/images/food.jpg +0 -0
- package/dist/studio/library/images/landscape.jpg +0 -0
- package/dist/studio/library/images/pet.jpg +0 -0
- package/dist/studio/library/images/portrait.jpg +0 -0
- package/dist/studio/library/images/product.jpg +0 -0
- package/dist/studio/library/index.json +752 -0
- package/dist/studio/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
- package/dist/studio/templates/avatar-pro/photo.json +13 -0
- package/dist/studio/templates/avatar-pro/preview.jpg +0 -0
- package/dist/studio/templates/avatar-pro/template.json +1 -0
- package/dist/studio/templates/index.json +1 -0
- package/dist/studio/templates/og-article/photo.json +13 -0
- package/dist/studio/templates/og-article/preview.jpg +0 -0
- package/dist/studio/templates/og-article/template.json +1 -0
- package/dist/studio/templates/polaroid/photo.json +13 -0
- package/dist/studio/templates/polaroid/preview.jpg +0 -0
- package/dist/studio/templates/polaroid/template.json +1 -0
- package/dist/studio/templates/product-white/assets/masks/photo-cutout.png +0 -0
- package/dist/studio/templates/product-white/photo.json +72 -0
- package/dist/studio/templates/product-white/preview.jpg +0 -0
- package/dist/studio/templates/product-white/template.json +1 -0
- package/dist/studio/templates/sale-banner/photo.json +125 -0
- package/dist/studio/templates/sale-banner/preview.jpg +0 -0
- package/dist/studio/templates/sale-banner/template.json +1 -0
- package/dist/studio/templates/social-quote/photo.json +13 -0
- package/dist/studio/templates/social-quote/preview.jpg +0 -0
- package/dist/studio/templates/social-quote/template.json +1 -0
- package/dist/studio/templates/story-promo/photo.json +13 -0
- package/dist/studio/templates/story-promo/preview.jpg +0 -0
- package/dist/studio/templates/story-promo/template.json +1 -0
- package/dist/studio/templates/youtube-thumbnail/photo.json +12 -0
- package/dist/studio/templates/youtube-thumbnail/preview.jpg +0 -0
- package/dist/studio/templates/youtube-thumbnail/template.json +1 -0
- package/library/LICENSES.md +57 -0
- package/library/fonts/OFL.txt +90 -0
- package/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
- package/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
- package/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
- package/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
- package/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
- package/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
- package/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/LICENSE.txt +202 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/library/images/city.jpg +0 -0
- package/library/images/food.jpg +0 -0
- package/library/images/landscape.jpg +0 -0
- package/library/images/pet.jpg +0 -0
- package/library/images/portrait.jpg +0 -0
- package/library/images/product.jpg +0 -0
- package/library/index.json +752 -0
- package/package.json +65 -4
- package/plugin/.claude-plugin/plugin.json +19 -0
- package/plugin/skills/agentphoto-cutout/SKILL.md +132 -0
- package/plugin/skills/agentphoto-design/SKILL.md +104 -0
- package/plugin/skills/agentphoto-design/references/layouts.md +60 -0
- package/plugin/skills/agentphoto-publish/SKILL.md +79 -0
- package/plugin/skills/agentphoto-retouch/SKILL.md +144 -0
- package/plugin/skills/agentphoto-retouch/references/filters.md +51 -0
- package/plugin/skills/agentphoto-retouch/references/patch-ops.md +66 -0
- package/plugin/skills/agentphoto-retouch/references/recipes.md +129 -0
- package/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
- package/templates/avatar-pro/photo.json +13 -0
- package/templates/avatar-pro/preview.jpg +0 -0
- package/templates/avatar-pro/template.json +1 -0
- package/templates/og-article/photo.json +13 -0
- package/templates/og-article/preview.jpg +0 -0
- package/templates/og-article/template.json +1 -0
- package/templates/polaroid/photo.json +13 -0
- package/templates/polaroid/preview.jpg +0 -0
- package/templates/polaroid/template.json +1 -0
- package/templates/product-white/assets/masks/photo-cutout.png +0 -0
- package/templates/product-white/photo.json +72 -0
- package/templates/product-white/preview.jpg +0 -0
- package/templates/product-white/template.json +1 -0
- package/templates/sale-banner/photo.json +125 -0
- package/templates/sale-banner/preview.jpg +0 -0
- package/templates/sale-banner/template.json +1 -0
- package/templates/social-quote/photo.json +13 -0
- package/templates/social-quote/preview.jpg +0 -0
- package/templates/social-quote/template.json +1 -0
- package/templates/story-promo/photo.json +13 -0
- package/templates/story-promo/preview.jpg +0 -0
- package/templates/story-promo/template.json +1 -0
- package/templates/youtube-thumbnail/photo.json +12 -0
- package/templates/youtube-thumbnail/preview.jpg +0 -0
- package/templates/youtube-thumbnail/template.json +1 -0
|
@@ -0,0 +1,936 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
import { a as FONTS, c as filterDef, i as EFFECTS, l as fontDef, n as COMMON_FILTER_PARAMS, t as CATALOG } from "./catalog-DIZ5dnH5.mjs";
|
|
9
|
+
import { n as isValidId } from "./ids-DAmiNwd9.mjs";
|
|
10
|
+
import { t as BLEND_MODES } from "./types-DOK7tAAu.mjs";
|
|
11
|
+
// src/core/suggest.ts
|
|
12
|
+
function levenshtein(a, b) {
|
|
13
|
+
if (a === b) return 0;
|
|
14
|
+
if (!a.length) return b.length;
|
|
15
|
+
if (!b.length) return a.length;
|
|
16
|
+
let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
17
|
+
for (let i = 1; i <= a.length; i++) {
|
|
18
|
+
const cur = [i];
|
|
19
|
+
for (let j = 1; j <= b.length; j++) cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
20
|
+
prev = cur;
|
|
21
|
+
}
|
|
22
|
+
return prev[b.length];
|
|
23
|
+
}
|
|
24
|
+
function closest(input, options) {
|
|
25
|
+
const low = input.toLowerCase();
|
|
26
|
+
let best;
|
|
27
|
+
let bestScore = Infinity;
|
|
28
|
+
for (const opt of options) {
|
|
29
|
+
const o = opt.toLowerCase();
|
|
30
|
+
if (o === low) return opt;
|
|
31
|
+
let d = levenshtein(low, o);
|
|
32
|
+
if (o.startsWith(low) || low.startsWith(o)) d = Math.min(d, 1.5);
|
|
33
|
+
else if (low.length >= 4 && (o.includes(low) || low.includes(o))) d = Math.min(d, 2);
|
|
34
|
+
if (d < bestScore) {
|
|
35
|
+
bestScore = d;
|
|
36
|
+
best = opt;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const max = Math.max(2, Math.floor(low.length / 3));
|
|
40
|
+
return bestScore <= max ? best : void 0;
|
|
41
|
+
}
|
|
42
|
+
function didYouMean(input, options) {
|
|
43
|
+
const s = closest(input, options);
|
|
44
|
+
return s ? `Did you mean "${s}"? ` : "";
|
|
45
|
+
}
|
|
46
|
+
function listOptions(options, max = 40) {
|
|
47
|
+
const shown = options.slice(0, max).map((o) => `"${o}"`).join(", ");
|
|
48
|
+
return options.length > max ? `${shown}, … (${options.length} total)` : shown;
|
|
49
|
+
}
|
|
50
|
+
// src/core/color.ts
|
|
51
|
+
var CSS_COLOR_NAMES = {
|
|
52
|
+
aliceblue: "f0f8ff",
|
|
53
|
+
antiquewhite: "faebd7",
|
|
54
|
+
aqua: "00ffff",
|
|
55
|
+
aquamarine: "7fffd4",
|
|
56
|
+
azure: "f0ffff",
|
|
57
|
+
beige: "f5f5dc",
|
|
58
|
+
bisque: "ffe4c4",
|
|
59
|
+
black: "000000",
|
|
60
|
+
blanchedalmond: "ffebcd",
|
|
61
|
+
blue: "0000ff",
|
|
62
|
+
blueviolet: "8a2be2",
|
|
63
|
+
brown: "a52a2a",
|
|
64
|
+
burlywood: "deb887",
|
|
65
|
+
cadetblue: "5f9ea0",
|
|
66
|
+
chartreuse: "7fff00",
|
|
67
|
+
chocolate: "d2691e",
|
|
68
|
+
coral: "ff7f50",
|
|
69
|
+
cornflowerblue: "6495ed",
|
|
70
|
+
cornsilk: "fff8dc",
|
|
71
|
+
crimson: "dc143c",
|
|
72
|
+
cyan: "00ffff",
|
|
73
|
+
darkblue: "00008b",
|
|
74
|
+
darkcyan: "008b8b",
|
|
75
|
+
darkgoldenrod: "b8860b",
|
|
76
|
+
darkgray: "a9a9a9",
|
|
77
|
+
darkgreen: "006400",
|
|
78
|
+
darkgrey: "a9a9a9",
|
|
79
|
+
darkkhaki: "bdb76b",
|
|
80
|
+
darkmagenta: "8b008b",
|
|
81
|
+
darkolivegreen: "556b2f",
|
|
82
|
+
darkorange: "ff8c00",
|
|
83
|
+
darkorchid: "9932cc",
|
|
84
|
+
darkred: "8b0000",
|
|
85
|
+
darksalmon: "e9967a",
|
|
86
|
+
darkseagreen: "8fbc8f",
|
|
87
|
+
darkslateblue: "483d8b",
|
|
88
|
+
darkslategray: "2f4f4f",
|
|
89
|
+
darkslategrey: "2f4f4f",
|
|
90
|
+
darkturquoise: "00ced1",
|
|
91
|
+
darkviolet: "9400d3",
|
|
92
|
+
deeppink: "ff1493",
|
|
93
|
+
deepskyblue: "00bfff",
|
|
94
|
+
dimgray: "696969",
|
|
95
|
+
dimgrey: "696969",
|
|
96
|
+
dodgerblue: "1e90ff",
|
|
97
|
+
firebrick: "b22222",
|
|
98
|
+
floralwhite: "fffaf0",
|
|
99
|
+
forestgreen: "228b22",
|
|
100
|
+
fuchsia: "ff00ff",
|
|
101
|
+
gainsboro: "dcdcdc",
|
|
102
|
+
ghostwhite: "f8f8ff",
|
|
103
|
+
gold: "ffd700",
|
|
104
|
+
goldenrod: "daa520",
|
|
105
|
+
gray: "808080",
|
|
106
|
+
green: "008000",
|
|
107
|
+
greenyellow: "adff2f",
|
|
108
|
+
grey: "808080",
|
|
109
|
+
honeydew: "f0fff0",
|
|
110
|
+
hotpink: "ff69b4",
|
|
111
|
+
indianred: "cd5c5c",
|
|
112
|
+
indigo: "4b0082",
|
|
113
|
+
ivory: "fffff0",
|
|
114
|
+
khaki: "f0e68c",
|
|
115
|
+
lavender: "e6e6fa",
|
|
116
|
+
lavenderblush: "fff0f5",
|
|
117
|
+
lawngreen: "7cfc00",
|
|
118
|
+
lemonchiffon: "fffacd",
|
|
119
|
+
lightblue: "add8e6",
|
|
120
|
+
lightcoral: "f08080",
|
|
121
|
+
lightcyan: "e0ffff",
|
|
122
|
+
lightgoldenrodyellow: "fafad2",
|
|
123
|
+
lightgray: "d3d3d3",
|
|
124
|
+
lightgreen: "90ee90",
|
|
125
|
+
lightgrey: "d3d3d3",
|
|
126
|
+
lightpink: "ffb6c1",
|
|
127
|
+
lightsalmon: "ffa07a",
|
|
128
|
+
lightseagreen: "20b2aa",
|
|
129
|
+
lightskyblue: "87cefa",
|
|
130
|
+
lightslategray: "778899",
|
|
131
|
+
lightslategrey: "778899",
|
|
132
|
+
lightsteelblue: "b0c4de",
|
|
133
|
+
lightyellow: "ffffe0",
|
|
134
|
+
lime: "00ff00",
|
|
135
|
+
limegreen: "32cd32",
|
|
136
|
+
linen: "faf0e6",
|
|
137
|
+
magenta: "ff00ff",
|
|
138
|
+
maroon: "800000",
|
|
139
|
+
mediumaquamarine: "66cdaa",
|
|
140
|
+
mediumblue: "0000cd",
|
|
141
|
+
mediumorchid: "ba55d3",
|
|
142
|
+
mediumpurple: "9370db",
|
|
143
|
+
mediumseagreen: "3cb371",
|
|
144
|
+
mediumslateblue: "7b68ee",
|
|
145
|
+
mediumspringgreen: "00fa9a",
|
|
146
|
+
mediumturquoise: "48d1cc",
|
|
147
|
+
mediumvioletred: "c71585",
|
|
148
|
+
midnightblue: "191970",
|
|
149
|
+
mintcream: "f5fffa",
|
|
150
|
+
mistyrose: "ffe4e1",
|
|
151
|
+
moccasin: "ffe4b5",
|
|
152
|
+
navajowhite: "ffdead",
|
|
153
|
+
navy: "000080",
|
|
154
|
+
oldlace: "fdf5e6",
|
|
155
|
+
olive: "808000",
|
|
156
|
+
olivedrab: "6b8e23",
|
|
157
|
+
orange: "ffa500",
|
|
158
|
+
orangered: "ff4500",
|
|
159
|
+
orchid: "da70d6",
|
|
160
|
+
palegoldenrod: "eee8aa",
|
|
161
|
+
palegreen: "98fb98",
|
|
162
|
+
paleturquoise: "afeeee",
|
|
163
|
+
palevioletred: "db7093",
|
|
164
|
+
papayawhip: "ffefd5",
|
|
165
|
+
peachpuff: "ffdab9",
|
|
166
|
+
peru: "cd853f",
|
|
167
|
+
pink: "ffc0cb",
|
|
168
|
+
plum: "dda0dd",
|
|
169
|
+
powderblue: "b0e0e6",
|
|
170
|
+
purple: "800080",
|
|
171
|
+
rebeccapurple: "663399",
|
|
172
|
+
red: "ff0000",
|
|
173
|
+
rosybrown: "bc8f8f",
|
|
174
|
+
royalblue: "4169e1",
|
|
175
|
+
saddlebrown: "8b4513",
|
|
176
|
+
salmon: "fa8072",
|
|
177
|
+
sandybrown: "f4a460",
|
|
178
|
+
seagreen: "2e8b57",
|
|
179
|
+
seashell: "fff5ee",
|
|
180
|
+
sienna: "a0522d",
|
|
181
|
+
silver: "c0c0c0",
|
|
182
|
+
skyblue: "87ceeb",
|
|
183
|
+
slateblue: "6a5acd",
|
|
184
|
+
slategray: "708090",
|
|
185
|
+
slategrey: "708090",
|
|
186
|
+
snow: "fffafa",
|
|
187
|
+
springgreen: "00ff7f",
|
|
188
|
+
steelblue: "4682b4",
|
|
189
|
+
tan: "d2b48c",
|
|
190
|
+
teal: "008080",
|
|
191
|
+
thistle: "d8bfd8",
|
|
192
|
+
tomato: "ff6347",
|
|
193
|
+
turquoise: "40e0d0",
|
|
194
|
+
violet: "ee82ee",
|
|
195
|
+
wheat: "f5deb3",
|
|
196
|
+
white: "ffffff",
|
|
197
|
+
whitesmoke: "f5f5f5",
|
|
198
|
+
yellow: "ffff00",
|
|
199
|
+
yellowgreen: "9acd32"
|
|
200
|
+
};
|
|
201
|
+
var clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
202
|
+
function parseHex(hex) {
|
|
203
|
+
if (!/^[0-9a-f]+$/i.test(hex)) return null;
|
|
204
|
+
if (hex.length === 3 || hex.length === 4) hex = [...hex].map((c) => c + c).join("");
|
|
205
|
+
if (hex.length !== 6 && hex.length !== 8) return null;
|
|
206
|
+
const n = (i) => parseInt(hex.slice(i, i + 2), 16);
|
|
207
|
+
return {
|
|
208
|
+
r: n(0),
|
|
209
|
+
g: n(2),
|
|
210
|
+
b: n(4),
|
|
211
|
+
a: hex.length === 8 ? n(6) / 255 : 1
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function component(s, scale) {
|
|
215
|
+
const m = /^(-?\d*\.?\d+(?:e-?\d+)?)(%?)$/i.exec(s.trim());
|
|
216
|
+
if (!m) return null;
|
|
217
|
+
const v = Number(m[1]);
|
|
218
|
+
return m[2] ? v / 100 * scale : v;
|
|
219
|
+
}
|
|
220
|
+
function hue(s) {
|
|
221
|
+
const m = /^(-?\d*\.?\d+)(deg|rad|turn|grad)?$/i.exec(s.trim());
|
|
222
|
+
if (!m) return null;
|
|
223
|
+
const v = Number(m[1]);
|
|
224
|
+
switch ((m[2] ?? "deg").toLowerCase()) {
|
|
225
|
+
case "rad": return v * 180 / Math.PI;
|
|
226
|
+
case "turn": return v * 360;
|
|
227
|
+
case "grad": return v * .9;
|
|
228
|
+
default: return v;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function args(body) {
|
|
232
|
+
const slash = body.split("/");
|
|
233
|
+
if (slash.length > 2) return null;
|
|
234
|
+
const out = (slash[0].includes(",") ? slash[0].split(",") : slash[0].trim().split(/\s+/)).map((x) => x.trim()).filter((x) => x !== "");
|
|
235
|
+
if (slash.length === 2) out.push(slash[1].trim());
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
function hslToRgb(h, s, l) {
|
|
239
|
+
h = (h % 360 + 360) % 360;
|
|
240
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
241
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
242
|
+
const m = l - c / 2;
|
|
243
|
+
const [r, g, b] = h < 60 ? [
|
|
244
|
+
c,
|
|
245
|
+
x,
|
|
246
|
+
0
|
|
247
|
+
] : h < 120 ? [
|
|
248
|
+
x,
|
|
249
|
+
c,
|
|
250
|
+
0
|
|
251
|
+
] : h < 180 ? [
|
|
252
|
+
0,
|
|
253
|
+
c,
|
|
254
|
+
x
|
|
255
|
+
] : h < 240 ? [
|
|
256
|
+
0,
|
|
257
|
+
x,
|
|
258
|
+
c
|
|
259
|
+
] : h < 300 ? [
|
|
260
|
+
x,
|
|
261
|
+
0,
|
|
262
|
+
c
|
|
263
|
+
] : [
|
|
264
|
+
c,
|
|
265
|
+
0,
|
|
266
|
+
x
|
|
267
|
+
];
|
|
268
|
+
return [
|
|
269
|
+
(r + m) * 255,
|
|
270
|
+
(g + m) * 255,
|
|
271
|
+
(b + m) * 255
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
function parseColor(value) {
|
|
275
|
+
if (typeof value !== "string") return null;
|
|
276
|
+
const s = value.trim().toLowerCase();
|
|
277
|
+
if (!s) return null;
|
|
278
|
+
if (s.startsWith("#")) return parseHex(s.slice(1));
|
|
279
|
+
if (s === "transparent") return {
|
|
280
|
+
r: 0,
|
|
281
|
+
g: 0,
|
|
282
|
+
b: 0,
|
|
283
|
+
a: 0
|
|
284
|
+
};
|
|
285
|
+
const named = CSS_COLOR_NAMES[s];
|
|
286
|
+
if (named) return parseHex(named);
|
|
287
|
+
const fn = /^(rgba?|hsla?)\((.*)\)$/.exec(s);
|
|
288
|
+
if (!fn) return null;
|
|
289
|
+
const parts = args(fn[2]);
|
|
290
|
+
if (!parts || parts.length !== 3 && parts.length !== 4) return null;
|
|
291
|
+
const alpha = parts.length === 4 ? component(parts[3], 1) : 1;
|
|
292
|
+
if (alpha === null) return null;
|
|
293
|
+
if (fn[1].startsWith("rgb")) {
|
|
294
|
+
const [r, g, b] = parts.slice(0, 3).map((p) => component(p, 255));
|
|
295
|
+
if (r === null || g === null || b === null) return null;
|
|
296
|
+
return {
|
|
297
|
+
r: clamp(r, 0, 255),
|
|
298
|
+
g: clamp(g, 0, 255),
|
|
299
|
+
b: clamp(b, 0, 255),
|
|
300
|
+
a: clamp(alpha, 0, 1)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const h = hue(parts[0]);
|
|
304
|
+
const sat = component(parts[1], 1);
|
|
305
|
+
const light = component(parts[2], 1);
|
|
306
|
+
if (h === null || sat === null || light === null || !parts[1].trim().endsWith("%") || !parts[2].trim().endsWith("%")) return null;
|
|
307
|
+
const [r, g, b] = hslToRgb(h, clamp(sat, 0, 1), clamp(light, 0, 1));
|
|
308
|
+
return {
|
|
309
|
+
r,
|
|
310
|
+
g,
|
|
311
|
+
b,
|
|
312
|
+
a: clamp(alpha, 0, 1)
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function isValidColor(value) {
|
|
316
|
+
return parseColor(value) !== null;
|
|
317
|
+
}
|
|
318
|
+
// src/core/validate.ts
|
|
319
|
+
var validate_exports = /* @__PURE__ */ __exportAll({ normalizeDoc: () => normalizeDoc });
|
|
320
|
+
var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
321
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
322
|
+
var MAX_CANVAS = 16384;
|
|
323
|
+
var COMMON_LAYER_KEYS = [
|
|
324
|
+
"id",
|
|
325
|
+
"type",
|
|
326
|
+
"name",
|
|
327
|
+
"visible",
|
|
328
|
+
"locked",
|
|
329
|
+
"opacity",
|
|
330
|
+
"blend",
|
|
331
|
+
"mask",
|
|
332
|
+
"clip",
|
|
333
|
+
"filters",
|
|
334
|
+
"effects"
|
|
335
|
+
];
|
|
336
|
+
var PLACEMENT_KEYS = [
|
|
337
|
+
"x",
|
|
338
|
+
"y",
|
|
339
|
+
"width",
|
|
340
|
+
"height",
|
|
341
|
+
"rotation",
|
|
342
|
+
"flipX",
|
|
343
|
+
"flipY"
|
|
344
|
+
];
|
|
345
|
+
var LAYER_KEYS = {
|
|
346
|
+
image: [
|
|
347
|
+
...COMMON_LAYER_KEYS,
|
|
348
|
+
...PLACEMENT_KEYS,
|
|
349
|
+
"src",
|
|
350
|
+
"crop",
|
|
351
|
+
"fit",
|
|
352
|
+
"focus"
|
|
353
|
+
],
|
|
354
|
+
text: [
|
|
355
|
+
...COMMON_LAYER_KEYS,
|
|
356
|
+
...PLACEMENT_KEYS,
|
|
357
|
+
"text",
|
|
358
|
+
"font",
|
|
359
|
+
"size",
|
|
360
|
+
"weight",
|
|
361
|
+
"italic",
|
|
362
|
+
"color",
|
|
363
|
+
"align",
|
|
364
|
+
"valign",
|
|
365
|
+
"lineHeight",
|
|
366
|
+
"letterSpacing",
|
|
367
|
+
"transform",
|
|
368
|
+
"background"
|
|
369
|
+
],
|
|
370
|
+
shape: [
|
|
371
|
+
...COMMON_LAYER_KEYS,
|
|
372
|
+
...PLACEMENT_KEYS,
|
|
373
|
+
"shape",
|
|
374
|
+
"fill",
|
|
375
|
+
"stroke",
|
|
376
|
+
"radius",
|
|
377
|
+
"sides",
|
|
378
|
+
"innerRadius"
|
|
379
|
+
],
|
|
380
|
+
fill: [...COMMON_LAYER_KEYS, "fill"],
|
|
381
|
+
adjustment: [...COMMON_LAYER_KEYS],
|
|
382
|
+
group: [...COMMON_LAYER_KEYS, "children"]
|
|
383
|
+
};
|
|
384
|
+
var LAYER_TYPE_IDS = Object.keys(LAYER_KEYS);
|
|
385
|
+
var ROOT_KEYS = [
|
|
386
|
+
"version",
|
|
387
|
+
"id",
|
|
388
|
+
"title",
|
|
389
|
+
"description",
|
|
390
|
+
"canvas",
|
|
391
|
+
"layers",
|
|
392
|
+
"export"
|
|
393
|
+
];
|
|
394
|
+
var Collector = class {
|
|
395
|
+
issues = [];
|
|
396
|
+
add(severity, code, path, message, hint) {
|
|
397
|
+
this.issues.push({
|
|
398
|
+
severity,
|
|
399
|
+
code,
|
|
400
|
+
path,
|
|
401
|
+
message,
|
|
402
|
+
...hint ? { hint } : {}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
error(code, path, message, hint) {
|
|
406
|
+
this.add("error", code, path, message, hint);
|
|
407
|
+
}
|
|
408
|
+
warn(code, path, message, hint) {
|
|
409
|
+
this.add("warning", code, path, message, hint);
|
|
410
|
+
}
|
|
411
|
+
info(code, path, message, hint) {
|
|
412
|
+
this.add("info", code, path, message, hint);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
function unknownKeys(c, obj, allowed, path, what) {
|
|
416
|
+
for (const k of Object.keys(obj)) {
|
|
417
|
+
if (allowed.includes(k)) continue;
|
|
418
|
+
c.warn("unknown-field", path ? `${path}.${k}` : k, `Unknown field "${k}" on ${what} (ignored).`, `${didYouMean(k, allowed)}Allowed: ${listOptions(allowed)}.`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function number(c, v, path, opts = {}) {
|
|
422
|
+
if (v === void 0) {
|
|
423
|
+
if (opts.required) c.error("missing", path, `${opts.what ?? path} is required.`);
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
if (!isNum(v)) {
|
|
427
|
+
c.error("type", path, `${path} must be a number, got ${JSON.stringify(v)}.`);
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (opts.int && !Number.isInteger(v)) c.error("type", path, `${path} must be an integer, got ${v}.`);
|
|
431
|
+
if (opts.min !== void 0 && v < opts.min) c.error("range", path, `${path} must be ≥ ${opts.min}, got ${v}.`);
|
|
432
|
+
if (opts.max !== void 0 && v > opts.max) c.error("range", path, `${path} must be ≤ ${opts.max}, got ${v}.`);
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
function bool(c, v, path) {
|
|
436
|
+
if (v !== void 0 && typeof v !== "boolean") c.error("type", path, `${path} must be true or false, got ${JSON.stringify(v)}.`);
|
|
437
|
+
}
|
|
438
|
+
function color(c, v, path, required = false) {
|
|
439
|
+
if (v === void 0) {
|
|
440
|
+
if (required) c.error("missing", path, `${path} (a CSS colour) is required.`);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (!isValidColor(v)) c.error("color", path, `${path}: ${JSON.stringify(v)} is not a CSS colour.`, "Use \"#ff3366\", \"rgb(255 51 102)\", \"hsl(340 100% 60%)\", \"rgba(0,0,0,0.5)\" or a named colour.");
|
|
444
|
+
}
|
|
445
|
+
function stops(c, v, path) {
|
|
446
|
+
if (!Array.isArray(v) || v.length < 2) {
|
|
447
|
+
c.error("stops", path, `${path} must list at least 2 colour stops.`, "e.g. [\"#1b1340\", \"#ff7a59\"] or [[0, \"#000\"], [0.6, \"#f80\"], [1, \"#fff\"]].");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
v.forEach((s, i) => {
|
|
451
|
+
const p = `${path}[${i}]`;
|
|
452
|
+
if (typeof s === "string") color(c, s, p);
|
|
453
|
+
else if (Array.isArray(s) && s.length === 2) {
|
|
454
|
+
number(c, s[0], `${p}[0]`, {
|
|
455
|
+
min: 0,
|
|
456
|
+
max: 1
|
|
457
|
+
});
|
|
458
|
+
color(c, s[1], `${p}[1]`, true);
|
|
459
|
+
} else c.error("stops", p, `${p} must be a colour or [offset 0..1, colour].`);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
function validatePaint(c, v, path, opts = {}) {
|
|
463
|
+
if (v === void 0) {
|
|
464
|
+
if (opts.required) c.error("missing", path, `${path} is required (a CSS colour or a gradient).`);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (v === null) {
|
|
468
|
+
if (!opts.allowNull) c.error("type", path, `${path} cannot be null.`);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (typeof v === "string") return color(c, v, path);
|
|
472
|
+
if (!isObj(v)) return c.error("paint", path, `${path} must be a CSS colour or a gradient object.`, "{ \"type\": \"linear\", \"angle\": 90, \"stops\": [\"#ff7a59\", \"#1b1340\"] }");
|
|
473
|
+
if (v.type !== "linear" && v.type !== "radial") c.error("paint", `${path}.type`, `Gradient type must be "linear" or "radial", got ${JSON.stringify(v.type)}.`);
|
|
474
|
+
stops(c, v.stops, `${path}.stops`);
|
|
475
|
+
if (v.type === "linear") {
|
|
476
|
+
unknownKeys(c, v, [
|
|
477
|
+
"type",
|
|
478
|
+
"stops",
|
|
479
|
+
"angle"
|
|
480
|
+
], path, "a linear gradient");
|
|
481
|
+
number(c, v.angle, `${path}.angle`);
|
|
482
|
+
} else if (v.type === "radial") {
|
|
483
|
+
unknownKeys(c, v, [
|
|
484
|
+
"type",
|
|
485
|
+
"stops",
|
|
486
|
+
"cx",
|
|
487
|
+
"cy",
|
|
488
|
+
"radius"
|
|
489
|
+
], path, "a radial gradient");
|
|
490
|
+
number(c, v.cx, `${path}.cx`);
|
|
491
|
+
number(c, v.cy, `${path}.cy`);
|
|
492
|
+
number(c, v.radius, `${path}.radius`, { min: 0 });
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function param(c, def, v, path) {
|
|
496
|
+
switch (def.type) {
|
|
497
|
+
case "number":
|
|
498
|
+
case "int":
|
|
499
|
+
number(c, v, path, {
|
|
500
|
+
min: def.min,
|
|
501
|
+
max: def.max,
|
|
502
|
+
int: def.type === "int"
|
|
503
|
+
});
|
|
504
|
+
return;
|
|
505
|
+
case "boolean":
|
|
506
|
+
bool(c, v, path);
|
|
507
|
+
return;
|
|
508
|
+
case "color":
|
|
509
|
+
color(c, v, path);
|
|
510
|
+
return;
|
|
511
|
+
case "enum":
|
|
512
|
+
if (typeof v !== "string" || !def.options?.includes(v)) c.error("enum", path, `${path}: ${JSON.stringify(v)} is not one of the allowed values.`, `${typeof v === "string" ? didYouMean(v, def.options ?? []) : ""}Allowed: ${listOptions(def.options ?? [])}.`);
|
|
513
|
+
return;
|
|
514
|
+
case "stops":
|
|
515
|
+
stops(c, v, path);
|
|
516
|
+
return;
|
|
517
|
+
case "rgb":
|
|
518
|
+
if (!Array.isArray(v) || v.length !== 3) c.error("type", path, `${path} must be [r, g, b] (each ${def.min}..${def.max}).`);
|
|
519
|
+
else v.forEach((x, k) => number(c, x, `${path}[${k}]`, {
|
|
520
|
+
min: def.min,
|
|
521
|
+
max: def.max
|
|
522
|
+
}));
|
|
523
|
+
return;
|
|
524
|
+
case "curve": {
|
|
525
|
+
if (!Array.isArray(v) || v.length < 2) {
|
|
526
|
+
c.error("curve", path, `${path} must list at least 2 points [input, output] (0..255).`, "e.g. [[0,0],[64,50],[192,210],[255,255]].");
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
let last = -1;
|
|
530
|
+
v.forEach((pt, k) => {
|
|
531
|
+
const p = `${path}[${k}]`;
|
|
532
|
+
if (!Array.isArray(pt) || pt.length !== 2) return c.error("curve", p, `${p} must be [input, output].`);
|
|
533
|
+
number(c, pt[0], `${p}[0]`, {
|
|
534
|
+
min: 0,
|
|
535
|
+
max: 255
|
|
536
|
+
});
|
|
537
|
+
number(c, pt[1], `${p}[1]`, {
|
|
538
|
+
min: 0,
|
|
539
|
+
max: 255
|
|
540
|
+
});
|
|
541
|
+
if (isNum(pt[0])) {
|
|
542
|
+
if (pt[0] <= last) c.error("curve", p, `${path}: inputs must be strictly increasing (point ${k} has ${pt[0]} after ${last}).`);
|
|
543
|
+
last = pt[0];
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function params(c, obj, defs, path, what, skip) {
|
|
551
|
+
const allowed = [...skip, ...defs.map((d) => d.name)];
|
|
552
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
553
|
+
if (skip.includes(k)) continue;
|
|
554
|
+
const def = defs.find((d) => d.name === k);
|
|
555
|
+
if (!def) {
|
|
556
|
+
c.warn("unknown-param", `${path}.${k}`, `Unknown parameter "${k}" for ${what} (ignored).`, `${didYouMean(k, allowed)}Parameters: ${listOptions(defs.map((d) => d.name))}. catalog_get documents them.`);
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
if (v === void 0) continue;
|
|
560
|
+
param(c, def, v, `${path}.${k}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function validateFilter(c, f, path) {
|
|
564
|
+
if (!isObj(f)) return c.error("type", path, `${path} must be a filter object { "type": …, …params }.`, "e.g. { \"type\": \"brightnessContrast\", \"brightness\": 10 }.");
|
|
565
|
+
if (typeof f.type !== "string") return c.error("missing", `${path}.type`, `${path}.type (a filter id) is required.`, `Filters: ${listOptions(CATALOG.filters.map((x) => x.id))}.`);
|
|
566
|
+
const def = filterDef(f.type);
|
|
567
|
+
if (!def) return c.error("unknown-filter", `${path}.type`, `Unknown filter "${f.type}".`, `${didYouMean(f.type, CATALOG.filters.map((x) => x.id))}Filters: ${listOptions(CATALOG.filters.map((x) => x.id))} (catalog_get section "filters").`);
|
|
568
|
+
const common = COMMON_FILTER_PARAMS.filter((p) => !def.params.some((d) => d.name === p.name));
|
|
569
|
+
for (const p of common) if (f[p.name] !== void 0) param(c, p, f[p.name], `${path}.${p.name}`);
|
|
570
|
+
params(c, f, def.params, path, `filter "${def.id}"`, ["type", ...common.map((p) => p.name)]);
|
|
571
|
+
if (def.id === "look" && f.look === void 0) c.error("missing", `${path}.look`, `A "look" filter needs a look id.`, `Looks: ${listOptions(CATALOG.looks.map((l) => l.id))}.`);
|
|
572
|
+
}
|
|
573
|
+
function filters(c, v, path) {
|
|
574
|
+
if (v === void 0) return;
|
|
575
|
+
if (!Array.isArray(v)) return c.error("type", path, `${path} must be an array of filters.`);
|
|
576
|
+
v.forEach((f, k) => validateFilter(c, f, `${path}[${k}]`));
|
|
577
|
+
}
|
|
578
|
+
function mask(c, m, path) {
|
|
579
|
+
if (m === void 0 || m === null) return;
|
|
580
|
+
if (!isObj(m)) return c.error("type", path, `${path} must be a mask object.`, "{ \"src\": \"assets/masks/photo.png\" } | { \"shape\": \"ellipse\", \"x\": 0, \"y\": 0, \"width\": 400, \"height\": 400, \"feather\": 30 } | { \"gradient\": { \"type\": \"linear\", \"angle\": 90, \"stops\": [\"white\", \"black\"] } }");
|
|
581
|
+
const kinds = [
|
|
582
|
+
"src",
|
|
583
|
+
"shape",
|
|
584
|
+
"gradient"
|
|
585
|
+
].filter((k) => m[k] !== void 0);
|
|
586
|
+
if (kinds.length !== 1) c.error("mask", path, `${path} must have exactly one of "src", "shape" or "gradient" (has ${kinds.length ? kinds.join(", ") : "none"}).`);
|
|
587
|
+
const common = [
|
|
588
|
+
"invert",
|
|
589
|
+
"feather",
|
|
590
|
+
"density",
|
|
591
|
+
"enabled"
|
|
592
|
+
];
|
|
593
|
+
bool(c, m.invert, `${path}.invert`);
|
|
594
|
+
bool(c, m.enabled, `${path}.enabled`);
|
|
595
|
+
number(c, m.feather, `${path}.feather`, {
|
|
596
|
+
min: 0,
|
|
597
|
+
max: 1e3
|
|
598
|
+
});
|
|
599
|
+
number(c, m.density, `${path}.density`, {
|
|
600
|
+
min: 0,
|
|
601
|
+
max: 1
|
|
602
|
+
});
|
|
603
|
+
if (m.src !== void 0) {
|
|
604
|
+
unknownKeys(c, m, ["src", ...common], path, "an image mask");
|
|
605
|
+
if (typeof m.src !== "string" || !m.src.trim()) c.error("type", `${path}.src`, `${path}.src must be a project path (e.g. "assets/masks/photo.png").`);
|
|
606
|
+
} else if (m.shape !== void 0) {
|
|
607
|
+
unknownKeys(c, m, [
|
|
608
|
+
"shape",
|
|
609
|
+
"x",
|
|
610
|
+
"y",
|
|
611
|
+
"width",
|
|
612
|
+
"height",
|
|
613
|
+
"radius",
|
|
614
|
+
...common
|
|
615
|
+
], path, "a shape mask");
|
|
616
|
+
if (m.shape !== "rect" && m.shape !== "ellipse") c.error("enum", `${path}.shape`, `${path}.shape must be "rect" or "ellipse".`);
|
|
617
|
+
number(c, m.x, `${path}.x`, { required: true });
|
|
618
|
+
number(c, m.y, `${path}.y`, { required: true });
|
|
619
|
+
number(c, m.width, `${path}.width`, {
|
|
620
|
+
required: true,
|
|
621
|
+
min: 0
|
|
622
|
+
});
|
|
623
|
+
number(c, m.height, `${path}.height`, {
|
|
624
|
+
required: true,
|
|
625
|
+
min: 0
|
|
626
|
+
});
|
|
627
|
+
number(c, m.radius, `${path}.radius`, { min: 0 });
|
|
628
|
+
} else if (m.gradient !== void 0) {
|
|
629
|
+
unknownKeys(c, m, ["gradient", ...common], path, "a gradient mask");
|
|
630
|
+
if (typeof m.gradient === "string") c.error("paint", `${path}.gradient`, `${path}.gradient must be a gradient object, not a colour.`);
|
|
631
|
+
else validatePaint(c, m.gradient, `${path}.gradient`);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function effects(c, v, path) {
|
|
635
|
+
if (v === void 0) return;
|
|
636
|
+
if (!isObj(v)) return c.error("type", path, `${path} must be an object { dropShadow?, outerGlow?, innerShadow?, stroke?, colorOverlay? }.`);
|
|
637
|
+
const ids = EFFECTS.map((e) => e.id);
|
|
638
|
+
for (const [k, val] of Object.entries(v)) {
|
|
639
|
+
const def = EFFECTS.find((e) => e.id === k);
|
|
640
|
+
const p = `${path}.${k}`;
|
|
641
|
+
if (!def) {
|
|
642
|
+
c.warn("unknown-effect", p, `Unknown layer effect "${k}" (ignored).`, `${didYouMean(k, ids)}Effects: ${listOptions(ids)}.`);
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
if (val === null || val === false) continue;
|
|
646
|
+
if (!isObj(val)) {
|
|
647
|
+
c.error("type", p, `${p} must be an object of parameters (or null to remove it).`);
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
params(c, val, def.params, p, `effect "${k}"`, []);
|
|
651
|
+
if (k === "colorOverlay" && val.color === void 0) c.error("missing", `${p}.color`, `colorOverlay needs a color.`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function placement(c, l, path, opts = {}) {
|
|
655
|
+
number(c, l.x, `${path}.x`);
|
|
656
|
+
number(c, l.y, `${path}.y`);
|
|
657
|
+
number(c, l.width, `${path}.width`, {
|
|
658
|
+
min: 0,
|
|
659
|
+
required: opts.sizeRequired
|
|
660
|
+
});
|
|
661
|
+
number(c, l.height, `${path}.height`, {
|
|
662
|
+
min: 0,
|
|
663
|
+
required: opts.sizeRequired
|
|
664
|
+
});
|
|
665
|
+
number(c, l.rotation, `${path}.rotation`);
|
|
666
|
+
bool(c, l.flipX, `${path}.flipX`);
|
|
667
|
+
bool(c, l.flipY, `${path}.flipY`);
|
|
668
|
+
}
|
|
669
|
+
function layer(c, l, path, ids) {
|
|
670
|
+
if (!isObj(l)) return c.error("type", path, `${path} must be a layer object.`);
|
|
671
|
+
const lp = typeof l.id === "string" && isValidId(l.id) ? `layers#${l.id}` : path;
|
|
672
|
+
if (!isValidId(l.id)) c.error("id", `${path}.id`, `Layer id ${JSON.stringify(l.id)} is invalid.`, "Ids start with a letter and contain letters, digits, - and _ (e.g. \"photo\", \"title-2\").");
|
|
673
|
+
else if (ids.has(l.id)) c.error("duplicate-id", `${lp}.id`, `Duplicate layer id "${l.id}".`, "Layer ids are unique across the document (groups included).");
|
|
674
|
+
else ids.add(l.id);
|
|
675
|
+
if (typeof l.type !== "string" || !LAYER_KEYS[l.type]) {
|
|
676
|
+
c.error("layer-type", `${lp}.type`, `Unknown layer type ${JSON.stringify(l.type)}.`, `${typeof l.type === "string" ? didYouMean(l.type, LAYER_TYPE_IDS) : ""}Types: ${listOptions(LAYER_TYPE_IDS)}.`);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
unknownKeys(c, l, LAYER_KEYS[l.type], lp, `a ${l.type} layer`);
|
|
680
|
+
if (l.name !== void 0 && typeof l.name !== "string") c.error("type", `${lp}.name`, `${lp}.name must be a string.`);
|
|
681
|
+
bool(c, l.visible, `${lp}.visible`);
|
|
682
|
+
bool(c, l.locked, `${lp}.locked`);
|
|
683
|
+
bool(c, l.clip, `${lp}.clip`);
|
|
684
|
+
if (l.opacity !== void 0) {
|
|
685
|
+
if (isNum(l.opacity) && l.opacity > 1 && l.opacity <= 100) c.error("range", `${lp}.opacity`, `${lp}.opacity is 0..1, got ${l.opacity}.`, `Use ${Math.round(l.opacity) / 100} for ${l.opacity} %.`);
|
|
686
|
+
else number(c, l.opacity, `${lp}.opacity`, {
|
|
687
|
+
min: 0,
|
|
688
|
+
max: 1
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
if (l.blend !== void 0 && (typeof l.blend !== "string" || !BLEND_MODES.includes(l.blend))) c.error("enum", `${lp}.blend`, `Unknown blend mode ${JSON.stringify(l.blend)}.`, `${typeof l.blend === "string" ? didYouMean(l.blend, BLEND_MODES) : ""}Blend modes: ${listOptions(BLEND_MODES)}.`);
|
|
692
|
+
mask(c, l.mask, `${lp}.mask`);
|
|
693
|
+
effects(c, l.effects, `${lp}.effects`);
|
|
694
|
+
switch (l.type) {
|
|
695
|
+
case "image":
|
|
696
|
+
filters(c, l.filters, `${lp}.filters`);
|
|
697
|
+
placement(c, l, lp);
|
|
698
|
+
if (typeof l.src !== "string" || !l.src.trim()) c.error("missing", `${lp}.src`, `Image layer "${l.id}" needs a src (a project path like "assets/photo.jpg" or "library:<id>").`, "assets_add imports a file into the project; library_list lists the built-in images.");
|
|
699
|
+
if (l.crop !== void 0) {
|
|
700
|
+
if (!isObj(l.crop)) c.error("type", `${lp}.crop`, `${lp}.crop must be { x, y, width, height } in source pixels.`);
|
|
701
|
+
else {
|
|
702
|
+
number(c, l.crop.x, `${lp}.crop.x`, {
|
|
703
|
+
required: true,
|
|
704
|
+
min: 0
|
|
705
|
+
});
|
|
706
|
+
number(c, l.crop.y, `${lp}.crop.y`, {
|
|
707
|
+
required: true,
|
|
708
|
+
min: 0
|
|
709
|
+
});
|
|
710
|
+
number(c, l.crop.width, `${lp}.crop.width`, {
|
|
711
|
+
required: true,
|
|
712
|
+
min: 1
|
|
713
|
+
});
|
|
714
|
+
number(c, l.crop.height, `${lp}.crop.height`, {
|
|
715
|
+
required: true,
|
|
716
|
+
min: 1
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (l.fit !== void 0 && ![
|
|
721
|
+
"fill",
|
|
722
|
+
"cover",
|
|
723
|
+
"contain"
|
|
724
|
+
].includes(l.fit)) c.error("enum", `${lp}.fit`, `${lp}.fit must be "fill", "cover" or "contain".`);
|
|
725
|
+
if (l.focus !== void 0 && (!Array.isArray(l.focus) || l.focus.length !== 2 || !l.focus.every((x) => isNum(x) && x >= 0 && x <= 1))) c.error("type", `${lp}.focus`, `${lp}.focus must be [x, y] with values 0..1.`);
|
|
726
|
+
break;
|
|
727
|
+
case "text":
|
|
728
|
+
filters(c, l.filters, `${lp}.filters`);
|
|
729
|
+
placement(c, l, lp);
|
|
730
|
+
if (typeof l.text !== "string") c.error("missing", `${lp}.text`, `Text layer "${l.id}" needs a text string.`);
|
|
731
|
+
else if (!l.text.trim()) c.warn("empty-text", `${lp}.text`, `Text layer "${l.id}" is empty.`);
|
|
732
|
+
if (l.font !== void 0) {
|
|
733
|
+
if (typeof l.font !== "string" || !l.font.trim()) c.error("type", `${lp}.font`, `${lp}.font must be a font id or a CSS font family.`);
|
|
734
|
+
else if (!fontDef(l.font)) {
|
|
735
|
+
const near = didYouMean(l.font, FONTS.map((f) => f.id));
|
|
736
|
+
c.info("system-font", `${lp}.font`, `Font "${l.font}" is not bundled: it renders with whatever this computer has (exports may differ elsewhere).`, `${near}Bundled fonts: ${listOptions(FONTS.map((f) => f.id))}.`);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
number(c, l.size, `${lp}.size`, {
|
|
740
|
+
min: 1,
|
|
741
|
+
max: 4e3
|
|
742
|
+
});
|
|
743
|
+
number(c, l.weight, `${lp}.weight`, {
|
|
744
|
+
min: 100,
|
|
745
|
+
max: 900
|
|
746
|
+
});
|
|
747
|
+
bool(c, l.italic, `${lp}.italic`);
|
|
748
|
+
validatePaint(c, l.color, `${lp}.color`);
|
|
749
|
+
if (l.align !== void 0 && ![
|
|
750
|
+
"left",
|
|
751
|
+
"center",
|
|
752
|
+
"right"
|
|
753
|
+
].includes(l.align)) c.error("enum", `${lp}.align`, `${lp}.align must be left, center or right.`);
|
|
754
|
+
if (l.valign !== void 0 && ![
|
|
755
|
+
"top",
|
|
756
|
+
"middle",
|
|
757
|
+
"bottom"
|
|
758
|
+
].includes(l.valign)) c.error("enum", `${lp}.valign`, `${lp}.valign must be top, middle or bottom.`);
|
|
759
|
+
number(c, l.lineHeight, `${lp}.lineHeight`, {
|
|
760
|
+
min: .1,
|
|
761
|
+
max: 10
|
|
762
|
+
});
|
|
763
|
+
number(c, l.letterSpacing, `${lp}.letterSpacing`, {
|
|
764
|
+
min: -200,
|
|
765
|
+
max: 1e3
|
|
766
|
+
});
|
|
767
|
+
if (l.transform !== void 0 && ![
|
|
768
|
+
"none",
|
|
769
|
+
"uppercase",
|
|
770
|
+
"lowercase"
|
|
771
|
+
].includes(l.transform)) c.error("enum", `${lp}.transform`, `${lp}.transform must be none, uppercase or lowercase.`);
|
|
772
|
+
if (l.background !== void 0 && l.background !== null) {
|
|
773
|
+
if (!isObj(l.background)) c.error("type", `${lp}.background`, `${lp}.background must be { color, padding?, radius? } or null.`);
|
|
774
|
+
else {
|
|
775
|
+
unknownKeys(c, l.background, [
|
|
776
|
+
"color",
|
|
777
|
+
"padding",
|
|
778
|
+
"radius"
|
|
779
|
+
], `${lp}.background`, "a text background");
|
|
780
|
+
color(c, l.background.color, `${lp}.background.color`, true);
|
|
781
|
+
const pad = l.background.padding;
|
|
782
|
+
if (pad !== void 0 && !isNum(pad) && !(Array.isArray(pad) && pad.length === 2 && pad.every(isNum))) c.error("type", `${lp}.background.padding`, "padding must be a number or [horizontal, vertical].");
|
|
783
|
+
number(c, l.background.radius, `${lp}.background.radius`, { min: 0 });
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
break;
|
|
787
|
+
case "shape":
|
|
788
|
+
filters(c, l.filters, `${lp}.filters`);
|
|
789
|
+
placement(c, l, lp, { sizeRequired: true });
|
|
790
|
+
if (typeof l.shape !== "string" || !CATALOG.shapes.includes(l.shape)) c.error("enum", `${lp}.shape`, `${lp}.shape must be one of ${listOptions(CATALOG.shapes)}.`, typeof l.shape === "string" ? didYouMean(l.shape, CATALOG.shapes) : void 0);
|
|
791
|
+
validatePaint(c, l.fill, `${lp}.fill`, { allowNull: true });
|
|
792
|
+
if (l.stroke !== void 0 && l.stroke !== null) {
|
|
793
|
+
if (!isObj(l.stroke)) c.error("type", `${lp}.stroke`, `${lp}.stroke must be { color, width?, dash? } or null.`);
|
|
794
|
+
else {
|
|
795
|
+
unknownKeys(c, l.stroke, [
|
|
796
|
+
"color",
|
|
797
|
+
"width",
|
|
798
|
+
"dash"
|
|
799
|
+
], `${lp}.stroke`, "a stroke");
|
|
800
|
+
color(c, l.stroke.color, `${lp}.stroke.color`, true);
|
|
801
|
+
number(c, l.stroke.width, `${lp}.stroke.width`, { min: 0 });
|
|
802
|
+
if (l.stroke.dash !== void 0 && (!Array.isArray(l.stroke.dash) || !l.stroke.dash.every((x) => isNum(x) && x >= 0))) c.error("type", `${lp}.stroke.dash`, "dash must be an array of lengths, e.g. [12, 6].");
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (l.fill === void 0 && (l.stroke === void 0 || l.stroke === null) && l.shape !== "line") c.info("invisible-shape", lp, `Shape "${l.id}" has no fill and no stroke: it draws the default fill (#ffffff).`);
|
|
806
|
+
if (l.shape === "line" && (l.stroke === void 0 || l.stroke === null)) c.info("line-stroke", lp, `Line "${l.id}" has no stroke: it draws a 4 px white line.`);
|
|
807
|
+
number(c, l.radius, `${lp}.radius`, { min: 0 });
|
|
808
|
+
number(c, l.sides, `${lp}.sides`, {
|
|
809
|
+
min: 3,
|
|
810
|
+
max: 64,
|
|
811
|
+
int: true
|
|
812
|
+
});
|
|
813
|
+
number(c, l.innerRadius, `${lp}.innerRadius`, {
|
|
814
|
+
min: 0,
|
|
815
|
+
max: 1
|
|
816
|
+
});
|
|
817
|
+
break;
|
|
818
|
+
case "fill":
|
|
819
|
+
filters(c, l.filters, `${lp}.filters`);
|
|
820
|
+
validatePaint(c, l.fill, `${lp}.fill`, { required: true });
|
|
821
|
+
break;
|
|
822
|
+
case "adjustment":
|
|
823
|
+
if (!Array.isArray(l.filters)) c.error("missing", `${lp}.filters`, `Adjustment layer "${l.id}" needs a filters array.`, "e.g. \"filters\": [{ \"type\": \"brightnessContrast\", \"contrast\": 15 }]");
|
|
824
|
+
else {
|
|
825
|
+
if (!l.filters.length) c.warn("empty-adjustment", `${lp}.filters`, `Adjustment layer "${l.id}" has no filters (does nothing).`);
|
|
826
|
+
filters(c, l.filters, `${lp}.filters`);
|
|
827
|
+
}
|
|
828
|
+
break;
|
|
829
|
+
case "group":
|
|
830
|
+
filters(c, l.filters, `${lp}.filters`);
|
|
831
|
+
if (!Array.isArray(l.children)) c.error("missing", `${lp}.children`, `Group "${l.id}" needs a children array.`);
|
|
832
|
+
else l.children.forEach((ch, k) => layer(c, ch, `${lp}.children[${k}]`, ids));
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function validateDoc(doc) {
|
|
836
|
+
const c = new Collector();
|
|
837
|
+
if (!isObj(doc)) {
|
|
838
|
+
c.error("type", "", "The document must be a JSON object.", "Minimal: { \"version\": 1, \"id\": \"photo\", \"canvas\": { \"width\": 1200, \"height\": 630 }, \"layers\": [] }");
|
|
839
|
+
return c.issues;
|
|
840
|
+
}
|
|
841
|
+
unknownKeys(c, doc, ROOT_KEYS, "", "the document");
|
|
842
|
+
if (doc.version === void 0) c.warn("version", "version", `Missing "version" (assumed 1).`);
|
|
843
|
+
else if (doc.version !== 1) c.error("version", "version", `Unsupported document version ${JSON.stringify(doc.version)} (this engine reads 1).`, "Update agentphoto, or set version to 1.");
|
|
844
|
+
if (!isValidId(doc.id)) c.error("id", "id", `Document id ${JSON.stringify(doc.id)} is invalid.`, "Use a slug such as \"summer-sale\".");
|
|
845
|
+
if (doc.title !== void 0 && typeof doc.title !== "string") c.error("type", "title", "title must be a string.");
|
|
846
|
+
if (doc.description !== void 0 && typeof doc.description !== "string") c.error("type", "description", "description must be a string.");
|
|
847
|
+
if (!isObj(doc.canvas)) c.error("missing", "canvas", "canvas { width, height } is required.", "\"canvas\": { \"width\": 1200, \"height\": 630 }");
|
|
848
|
+
else {
|
|
849
|
+
unknownKeys(c, doc.canvas, [
|
|
850
|
+
"width",
|
|
851
|
+
"height",
|
|
852
|
+
"background"
|
|
853
|
+
], "canvas", "canvas");
|
|
854
|
+
number(c, doc.canvas.width, "canvas.width", {
|
|
855
|
+
required: true,
|
|
856
|
+
min: 1,
|
|
857
|
+
max: MAX_CANVAS,
|
|
858
|
+
int: true
|
|
859
|
+
});
|
|
860
|
+
number(c, doc.canvas.height, "canvas.height", {
|
|
861
|
+
required: true,
|
|
862
|
+
min: 1,
|
|
863
|
+
max: MAX_CANVAS,
|
|
864
|
+
int: true
|
|
865
|
+
});
|
|
866
|
+
if (isNum(doc.canvas.width) && isNum(doc.canvas.height) && doc.canvas.width * doc.canvas.height / 1e6 > 40) c.warn("large-canvas", "canvas", `The canvas is ${Math.round(doc.canvas.width * doc.canvas.height / 1e6)} megapixels: renders and exports will be slow and memory-hungry.`, "Most web uses need ≤ 4000 px on the long side (resize_image).");
|
|
867
|
+
validatePaint(c, doc.canvas.background, "canvas.background", { allowNull: true });
|
|
868
|
+
}
|
|
869
|
+
if (!Array.isArray(doc.layers)) c.error("missing", "layers", "layers (an array, bottom → top) is required.");
|
|
870
|
+
else {
|
|
871
|
+
const ids = /* @__PURE__ */ new Set();
|
|
872
|
+
doc.layers.forEach((l, k) => layer(c, l, `layers[${k}]`, ids));
|
|
873
|
+
}
|
|
874
|
+
if (doc.export !== void 0) {
|
|
875
|
+
if (!isObj(doc.export)) c.error("type", "export", "export must be an object of default export settings.");
|
|
876
|
+
else {
|
|
877
|
+
unknownKeys(c, doc.export, [
|
|
878
|
+
"format",
|
|
879
|
+
"quality",
|
|
880
|
+
"scale",
|
|
881
|
+
"width",
|
|
882
|
+
"height",
|
|
883
|
+
"background",
|
|
884
|
+
"name"
|
|
885
|
+
], "export", "export settings");
|
|
886
|
+
if (doc.export.format !== void 0 && ![
|
|
887
|
+
"png",
|
|
888
|
+
"jpeg",
|
|
889
|
+
"webp",
|
|
890
|
+
"avif"
|
|
891
|
+
].includes(doc.export.format)) c.error("enum", "export.format", "export.format must be \"png\", \"jpeg\", \"webp\" or \"avif\".");
|
|
892
|
+
number(c, doc.export.quality, "export.quality", {
|
|
893
|
+
min: 1,
|
|
894
|
+
max: 100
|
|
895
|
+
});
|
|
896
|
+
number(c, doc.export.scale, "export.scale", {
|
|
897
|
+
min: .01,
|
|
898
|
+
max: 8
|
|
899
|
+
});
|
|
900
|
+
number(c, doc.export.width, "export.width", {
|
|
901
|
+
min: 1,
|
|
902
|
+
max: MAX_CANVAS,
|
|
903
|
+
int: true
|
|
904
|
+
});
|
|
905
|
+
number(c, doc.export.height, "export.height", {
|
|
906
|
+
min: 1,
|
|
907
|
+
max: MAX_CANVAS,
|
|
908
|
+
int: true
|
|
909
|
+
});
|
|
910
|
+
if (doc.export.background !== void 0 && doc.export.background !== null) color(c, doc.export.background, "export.background");
|
|
911
|
+
if (doc.export.name !== void 0 && (typeof doc.export.name !== "string" || !/^[\w.-]+$/.test(doc.export.name))) c.error("type", "export.name", "export.name must be a file name without extension (letters, digits, . _ -).");
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return c.issues;
|
|
915
|
+
}
|
|
916
|
+
function normalizeDoc(doc) {
|
|
917
|
+
return {
|
|
918
|
+
...doc,
|
|
919
|
+
version: doc.version ?? 1,
|
|
920
|
+
layers: doc.layers === void 0 || doc.layers === null ? [] : doc.layers
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function defaultDoc(opts = {}) {
|
|
924
|
+
return {
|
|
925
|
+
version: 1,
|
|
926
|
+
id: opts.id ?? "photo",
|
|
927
|
+
...opts.title ? { title: opts.title } : {},
|
|
928
|
+
canvas: {
|
|
929
|
+
width: opts.width ?? 1200,
|
|
930
|
+
height: opts.height ?? 630,
|
|
931
|
+
...opts.background !== void 0 ? { background: opts.background } : {}
|
|
932
|
+
},
|
|
933
|
+
layers: []
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
export { validate_exports as a, closest as c, validateDoc as i, didYouMean as l, defaultDoc as n, isValidColor as o, normalizeDoc as r, parseColor as s, MAX_CANVAS as t, listOptions as u };
|