@fleox/agentphoto 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +143 -0
- package/README.md +334 -2
- package/changelog.json +35 -0
- package/dist/agent/agentphoto.mjs +3354 -0
- package/dist/agent/chunks/assets-BZVUUHjg.mjs +151 -0
- package/dist/agent/chunks/catalog-DIZ5dnH5.mjs +953 -0
- package/dist/agent/chunks/context-CNpRboiC.mjs +75 -0
- package/dist/agent/chunks/doc-D_v_yE07.mjs +512 -0
- package/dist/agent/chunks/export-aNJcPNbJ.mjs +140 -0
- package/dist/agent/chunks/geometry-BKIhUO9x.mjs +315 -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-CxrjmA0W.mjs +387 -0
- package/dist/agent/chunks/output-3F12IR9O.mjs +130 -0
- package/dist/agent/chunks/package-Cu1GyvKL.mjs +71 -0
- package/dist/agent/chunks/project-o1DH2nOw.mjs +200 -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-BJ2me4XZ.mjs +61 -0
- package/dist/agent/chunks/tools-DKaAPEV5.mjs +1419 -0
- package/dist/agent/chunks/tree-D8qZKPAb.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 +2833 -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-CmOzzoXv.css +1 -0
- package/dist/studio/assets/index-D3Iw5q8v.js +28 -0
- package/dist/studio/assets/transformers.web-osEqoMhg.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 +137 -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 +67 -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,2833 @@
|
|
|
1
|
+
// src/core/types.ts
|
|
2
|
+
var e = (e) => e.type === "image" || e.type === "text" || e.type === "shape", t = (e) => typeof e.src == "string", n = (e) => typeof e.shape == "string", r = (e) => !!e.gradient;
|
|
3
|
+
// src/ops/tree.ts
|
|
4
|
+
function i(e, t, n = null, r = 0) {
|
|
5
|
+
if (!Array.isArray(e)) return null;
|
|
6
|
+
for (let i = 0; i < e.length; i++) {
|
|
7
|
+
let a = e[i];
|
|
8
|
+
if (a && a.id === t) return {
|
|
9
|
+
layer: a,
|
|
10
|
+
parent: n,
|
|
11
|
+
container: e,
|
|
12
|
+
index: i,
|
|
13
|
+
depth: r
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
for (let n of e) {
|
|
17
|
+
let e = n && n.type === "group" && Array.isArray(n.children) ? i(n.children, t, n, r + 1) : null;
|
|
18
|
+
if (e) return e;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
function a(e, t, n = null, r = 0) {
|
|
23
|
+
if (Array.isArray(e)) for (let i of e) i && typeof i == "object" && t(i, n, r) !== !1 && i.type === "group" && a(i.children, t, i, r + 1);
|
|
24
|
+
}
|
|
25
|
+
// src/core/catalog.ts
|
|
26
|
+
var o = (e, t, n, r, i, a = {}) => ({
|
|
27
|
+
name: e,
|
|
28
|
+
type: "number",
|
|
29
|
+
description: t,
|
|
30
|
+
default: n,
|
|
31
|
+
min: r,
|
|
32
|
+
max: i,
|
|
33
|
+
...a
|
|
34
|
+
}), s = (e, t, n, r, i, a = {}) => ({
|
|
35
|
+
name: e,
|
|
36
|
+
type: "int",
|
|
37
|
+
description: t,
|
|
38
|
+
default: n,
|
|
39
|
+
min: r,
|
|
40
|
+
max: i,
|
|
41
|
+
step: 1,
|
|
42
|
+
...a
|
|
43
|
+
}), c = (e, t, n) => ({
|
|
44
|
+
name: e,
|
|
45
|
+
type: "boolean",
|
|
46
|
+
description: t,
|
|
47
|
+
default: n
|
|
48
|
+
}), l = (e, t, n) => ({
|
|
49
|
+
name: e,
|
|
50
|
+
type: "color",
|
|
51
|
+
description: t,
|
|
52
|
+
default: n
|
|
53
|
+
}), u = (e, t, n, r) => ({
|
|
54
|
+
name: e,
|
|
55
|
+
type: "enum",
|
|
56
|
+
description: t,
|
|
57
|
+
default: n,
|
|
58
|
+
options: r
|
|
59
|
+
}), d = (e, t) => ({
|
|
60
|
+
name: e,
|
|
61
|
+
type: "rgb",
|
|
62
|
+
description: t,
|
|
63
|
+
default: [
|
|
64
|
+
0,
|
|
65
|
+
0,
|
|
66
|
+
0
|
|
67
|
+
],
|
|
68
|
+
min: -100,
|
|
69
|
+
max: 100
|
|
70
|
+
}), f = [
|
|
71
|
+
{
|
|
72
|
+
id: "brightnessContrast",
|
|
73
|
+
title: "Brightness / Contrast",
|
|
74
|
+
group: "light",
|
|
75
|
+
description: "Lighten or darken the image and increase or reduce contrast.",
|
|
76
|
+
params: [o("brightness", "-100 (darker) … 100 (lighter).", 0, -100, 100), o("contrast", "-100 (flat) … 100 (punchy).", 0, -100, 100)],
|
|
77
|
+
example: {
|
|
78
|
+
type: "brightnessContrast",
|
|
79
|
+
brightness: 10,
|
|
80
|
+
contrast: 15
|
|
81
|
+
},
|
|
82
|
+
cost: 1
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: "exposure",
|
|
86
|
+
title: "Exposure",
|
|
87
|
+
group: "light",
|
|
88
|
+
description: "Photographic exposure in stops (linear light), with offset and gamma.",
|
|
89
|
+
params: [
|
|
90
|
+
o("exposure", "Stops: +1 doubles the light.", 0, -5, 5, { step: .05 }),
|
|
91
|
+
o("offset", "Lifts (+) or crushes (−) the blacks.", 0, -.5, .5, { step: .01 }),
|
|
92
|
+
o("gamma", "Midtone gamma (1 = unchanged).", 1, .1, 5, { step: .01 })
|
|
93
|
+
],
|
|
94
|
+
example: {
|
|
95
|
+
type: "exposure",
|
|
96
|
+
exposure: .5
|
|
97
|
+
},
|
|
98
|
+
cost: 1
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "shadowsHighlights",
|
|
102
|
+
title: "Shadows / Highlights",
|
|
103
|
+
group: "light",
|
|
104
|
+
description: "Open up dark areas and recover bright ones, using local luminance (backlit portraits, skies).",
|
|
105
|
+
params: [
|
|
106
|
+
o("shadows", "How much to lighten the shadows.", 35, 0, 100),
|
|
107
|
+
o("highlights", "How much to darken the highlights.", 0, 0, 100),
|
|
108
|
+
o("radius", "Neighbourhood size, px.", 30, 1, 200, { px: !0 })
|
|
109
|
+
],
|
|
110
|
+
example: {
|
|
111
|
+
type: "shadowsHighlights",
|
|
112
|
+
shadows: 40,
|
|
113
|
+
highlights: 20
|
|
114
|
+
},
|
|
115
|
+
cost: 4
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "levels",
|
|
119
|
+
title: "Levels",
|
|
120
|
+
group: "tone",
|
|
121
|
+
description: "Input black / white points and midtone gamma, output range.",
|
|
122
|
+
params: [
|
|
123
|
+
o("black", "Input black point.", 0, 0, 254),
|
|
124
|
+
o("white", "Input white point.", 255, 1, 255),
|
|
125
|
+
o("gamma", "Midtones (>1 lighter).", 1, .1, 9.99, { step: .01 }),
|
|
126
|
+
o("outBlack", "Output black.", 0, 0, 255),
|
|
127
|
+
o("outWhite", "Output white.", 255, 0, 255)
|
|
128
|
+
],
|
|
129
|
+
example: {
|
|
130
|
+
type: "levels",
|
|
131
|
+
black: 12,
|
|
132
|
+
white: 240,
|
|
133
|
+
gamma: 1.1
|
|
134
|
+
},
|
|
135
|
+
cost: 1
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "curves",
|
|
139
|
+
title: "Curves",
|
|
140
|
+
group: "tone",
|
|
141
|
+
description: "Tone curves through control points [input, output] (0..255), smooth (monotone cubic). `rgb` affects all channels; `red` / `green` / `blue` affect one.",
|
|
142
|
+
params: [
|
|
143
|
+
{
|
|
144
|
+
name: "rgb",
|
|
145
|
+
type: "curve",
|
|
146
|
+
description: "Master curve points, e.g. [[0,0],[64,50],[192,210],[255,255]] (an S-curve).",
|
|
147
|
+
default: [[0, 0], [255, 255]]
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "red",
|
|
151
|
+
type: "curve",
|
|
152
|
+
description: "Red channel curve (optional)."
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "green",
|
|
156
|
+
type: "curve",
|
|
157
|
+
description: "Green channel curve (optional)."
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "blue",
|
|
161
|
+
type: "curve",
|
|
162
|
+
description: "Blue channel curve (optional)."
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
example: {
|
|
166
|
+
type: "curves",
|
|
167
|
+
rgb: [
|
|
168
|
+
[0, 0],
|
|
169
|
+
[64, 52],
|
|
170
|
+
[192, 206],
|
|
171
|
+
[255, 255]
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
cost: 1
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
id: "hueSaturation",
|
|
178
|
+
title: "Hue / Saturation",
|
|
179
|
+
group: "color",
|
|
180
|
+
description: "Rotate hues, change saturation and lightness. `colorize` tints the whole image with one hue.",
|
|
181
|
+
params: [
|
|
182
|
+
o("hue", "Hue rotation, degrees.", 0, -180, 180),
|
|
183
|
+
o("saturation", "-100 (grey) … 100.", 0, -100, 100),
|
|
184
|
+
o("lightness", "-100 … 100.", 0, -100, 100),
|
|
185
|
+
c("colorize", "Tint everything with `hue` (0..360 then) at `saturation`.", !1)
|
|
186
|
+
],
|
|
187
|
+
example: {
|
|
188
|
+
type: "hueSaturation",
|
|
189
|
+
saturation: 20
|
|
190
|
+
},
|
|
191
|
+
cost: 2
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: "vibrance",
|
|
195
|
+
title: "Vibrance",
|
|
196
|
+
group: "color",
|
|
197
|
+
description: "Boost muted colours more than saturated ones (skin-safe saturation).",
|
|
198
|
+
params: [o("vibrance", "-100 … 100.", 30, -100, 100), o("saturation", "Plain saturation on top, -100 … 100.", 0, -100, 100)],
|
|
199
|
+
example: {
|
|
200
|
+
type: "vibrance",
|
|
201
|
+
vibrance: 30
|
|
202
|
+
},
|
|
203
|
+
cost: 1
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: "temperature",
|
|
207
|
+
title: "White balance",
|
|
208
|
+
group: "color",
|
|
209
|
+
description: "Colour temperature (blue ↔ yellow) and tint (green ↔ magenta). Fixes colour casts.",
|
|
210
|
+
params: [o("temperature", "-100 (cooler) … 100 (warmer).", 0, -100, 100), o("tint", "-100 (green) … 100 (magenta).", 0, -100, 100)],
|
|
211
|
+
example: {
|
|
212
|
+
type: "temperature",
|
|
213
|
+
temperature: 15
|
|
214
|
+
},
|
|
215
|
+
cost: 1
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
id: "colorBalance",
|
|
219
|
+
title: "Color balance",
|
|
220
|
+
group: "color",
|
|
221
|
+
description: "Shift shadows, midtones and highlights towards cyan/red, magenta/green, yellow/blue: [r, g, b] each -100..100.",
|
|
222
|
+
params: [
|
|
223
|
+
d("shadows", "[cyan↔red, magenta↔green, yellow↔blue] for the shadows."),
|
|
224
|
+
d("midtones", "Same for the midtones."),
|
|
225
|
+
d("highlights", "Same for the highlights."),
|
|
226
|
+
c("preserveLuminosity", "Keep the brightness unchanged.", !0)
|
|
227
|
+
],
|
|
228
|
+
example: {
|
|
229
|
+
type: "colorBalance",
|
|
230
|
+
shadows: [
|
|
231
|
+
-10,
|
|
232
|
+
0,
|
|
233
|
+
10
|
|
234
|
+
],
|
|
235
|
+
highlights: [
|
|
236
|
+
10,
|
|
237
|
+
0,
|
|
238
|
+
-10
|
|
239
|
+
]
|
|
240
|
+
},
|
|
241
|
+
cost: 1
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "photoFilter",
|
|
245
|
+
title: "Photo filter",
|
|
246
|
+
group: "color",
|
|
247
|
+
description: "Warming / cooling / coloured lens filter.",
|
|
248
|
+
params: [
|
|
249
|
+
l("color", "Filter colour (warming #ec8a00, cooling #006dff…).", "#ec8a00"),
|
|
250
|
+
o("density", "Strength, 0 … 100.", 25, 0, 100),
|
|
251
|
+
c("preserveLuminosity", "Keep the brightness unchanged.", !0)
|
|
252
|
+
],
|
|
253
|
+
example: {
|
|
254
|
+
type: "photoFilter",
|
|
255
|
+
color: "#ec8a00",
|
|
256
|
+
density: 25
|
|
257
|
+
},
|
|
258
|
+
cost: 1
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: "gradientMap",
|
|
262
|
+
title: "Gradient map",
|
|
263
|
+
group: "color",
|
|
264
|
+
description: "Map luminance to a gradient (duotones, tritones): shadows take the first stop, highlights the last.",
|
|
265
|
+
params: [{
|
|
266
|
+
name: "stops",
|
|
267
|
+
type: "stops",
|
|
268
|
+
description: "Colours dark → light: [\"#1b1340\", \"#ff7a59\"] or [[0,\"#000\"],[1,\"#fff\"]].",
|
|
269
|
+
default: ["#000000", "#ffffff"]
|
|
270
|
+
}],
|
|
271
|
+
example: {
|
|
272
|
+
type: "gradientMap",
|
|
273
|
+
stops: [
|
|
274
|
+
"#1b1340",
|
|
275
|
+
"#ff7a59",
|
|
276
|
+
"#fff3d6"
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
cost: 1
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
id: "grayscale",
|
|
283
|
+
title: "Black & white",
|
|
284
|
+
group: "color",
|
|
285
|
+
description: "Convert to grey with adjustable channel weights (red / green / blue contributions, %).",
|
|
286
|
+
params: [
|
|
287
|
+
o("red", "Red contribution.", 30, -200, 300),
|
|
288
|
+
o("green", "Green contribution.", 59, -200, 300),
|
|
289
|
+
o("blue", "Blue contribution.", 11, -200, 300)
|
|
290
|
+
],
|
|
291
|
+
example: { type: "grayscale" },
|
|
292
|
+
cost: 1
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: "sepia",
|
|
296
|
+
title: "Sepia",
|
|
297
|
+
group: "color",
|
|
298
|
+
description: "Brown monochrome tone.",
|
|
299
|
+
params: [o("intensity", "0 … 100.", 100, 0, 100)],
|
|
300
|
+
example: {
|
|
301
|
+
type: "sepia",
|
|
302
|
+
intensity: 80
|
|
303
|
+
},
|
|
304
|
+
cost: 1
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
id: "invert",
|
|
308
|
+
title: "Invert",
|
|
309
|
+
group: "color",
|
|
310
|
+
description: "Negative image.",
|
|
311
|
+
params: [],
|
|
312
|
+
example: { type: "invert" },
|
|
313
|
+
cost: 1
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
id: "threshold",
|
|
317
|
+
title: "Threshold",
|
|
318
|
+
group: "stylize",
|
|
319
|
+
description: "Pure black & white at a luminance level.",
|
|
320
|
+
params: [o("level", "0 … 255.", 128, 0, 255)],
|
|
321
|
+
example: {
|
|
322
|
+
type: "threshold",
|
|
323
|
+
level: 128
|
|
324
|
+
},
|
|
325
|
+
cost: 1
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
id: "posterize",
|
|
329
|
+
title: "Posterize",
|
|
330
|
+
group: "stylize",
|
|
331
|
+
description: "Reduce the number of tones per channel.",
|
|
332
|
+
params: [s("levels", "Tones per channel.", 6, 2, 32)],
|
|
333
|
+
example: {
|
|
334
|
+
type: "posterize",
|
|
335
|
+
levels: 5
|
|
336
|
+
},
|
|
337
|
+
cost: 1
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
id: "blur",
|
|
341
|
+
title: "Gaussian blur",
|
|
342
|
+
group: "blur",
|
|
343
|
+
description: "Soft blur (backgrounds, depth of field when masked, privacy).",
|
|
344
|
+
params: [o("radius", "Radius, px.", 6, 0, 250, { px: !0 })],
|
|
345
|
+
example: {
|
|
346
|
+
type: "blur",
|
|
347
|
+
radius: 12
|
|
348
|
+
},
|
|
349
|
+
cost: 3
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
id: "motionBlur",
|
|
353
|
+
title: "Motion blur",
|
|
354
|
+
group: "blur",
|
|
355
|
+
description: "Directional blur (speed, panning).",
|
|
356
|
+
params: [o("angle", "Direction, degrees.", 0, -180, 180), o("distance", "Length, px.", 20, 0, 400, { px: !0 })],
|
|
357
|
+
example: {
|
|
358
|
+
type: "motionBlur",
|
|
359
|
+
angle: 0,
|
|
360
|
+
distance: 30
|
|
361
|
+
},
|
|
362
|
+
cost: 6
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
id: "surfaceBlur",
|
|
366
|
+
title: "Surface blur",
|
|
367
|
+
group: "blur",
|
|
368
|
+
description: "Edge-preserving smoothing (skin retouch, noise): flattens texture while keeping edges sharp. Usually masked to the area to smooth.",
|
|
369
|
+
params: [o("radius", "Neighbourhood, px.", 8, 1, 60, { px: !0 }), o("threshold", "Edge sensitivity, 1 (only flat areas) … 100 (smooth everything).", 25, 1, 100)],
|
|
370
|
+
example: {
|
|
371
|
+
type: "surfaceBlur",
|
|
372
|
+
radius: 8,
|
|
373
|
+
threshold: 25
|
|
374
|
+
},
|
|
375
|
+
cost: 6
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
id: "sharpen",
|
|
379
|
+
title: "Sharpen",
|
|
380
|
+
group: "detail",
|
|
381
|
+
description: "Unsharp mask: amount %, radius px, threshold (skip low-contrast detail such as skin / noise).",
|
|
382
|
+
params: [
|
|
383
|
+
o("amount", "Strength, %.", 80, 0, 500),
|
|
384
|
+
o("radius", "Px.", 1.2, .3, 20, {
|
|
385
|
+
px: !0,
|
|
386
|
+
step: .1
|
|
387
|
+
}),
|
|
388
|
+
o("threshold", "0 … 255.", 2, 0, 255)
|
|
389
|
+
],
|
|
390
|
+
example: {
|
|
391
|
+
type: "sharpen",
|
|
392
|
+
amount: 80,
|
|
393
|
+
radius: 1.2
|
|
394
|
+
},
|
|
395
|
+
cost: 3
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
id: "clarity",
|
|
399
|
+
title: "Clarity",
|
|
400
|
+
group: "detail",
|
|
401
|
+
description: "Local midtone contrast (texture, punch) — negative values soften.",
|
|
402
|
+
params: [o("amount", "-100 … 100.", 30, -100, 100), o("radius", "Px.", 24, 2, 200, { px: !0 })],
|
|
403
|
+
example: {
|
|
404
|
+
type: "clarity",
|
|
405
|
+
amount: 25
|
|
406
|
+
},
|
|
407
|
+
cost: 4
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
id: "noise",
|
|
411
|
+
title: "Grain / noise",
|
|
412
|
+
group: "stylize",
|
|
413
|
+
description: "Film grain (deterministic: same seed, same grain).",
|
|
414
|
+
params: [
|
|
415
|
+
o("amount", "0 … 100.", 12, 0, 100),
|
|
416
|
+
c("monochrome", "Grey grain instead of colour.", !0),
|
|
417
|
+
s("seed", "Random seed.", 1, 0, 999999),
|
|
418
|
+
o("size", "Grain size, px.", 1, 1, 8, {
|
|
419
|
+
px: !0,
|
|
420
|
+
step: .5
|
|
421
|
+
})
|
|
422
|
+
],
|
|
423
|
+
example: {
|
|
424
|
+
type: "noise",
|
|
425
|
+
amount: 10
|
|
426
|
+
},
|
|
427
|
+
cost: 1
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
id: "pixelate",
|
|
431
|
+
title: "Pixelate",
|
|
432
|
+
group: "stylize",
|
|
433
|
+
description: "Big square pixels (mosaic, anonymise a face when masked).",
|
|
434
|
+
params: [o("size", "Cell size, px.", 16, 2, 400, { px: !0 })],
|
|
435
|
+
example: {
|
|
436
|
+
type: "pixelate",
|
|
437
|
+
size: 20
|
|
438
|
+
},
|
|
439
|
+
cost: 1
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
id: "vignette",
|
|
443
|
+
title: "Vignette",
|
|
444
|
+
group: "stylize",
|
|
445
|
+
description: "Darken (or lighten, negative amount) the edges to draw the eye to the centre.",
|
|
446
|
+
params: [
|
|
447
|
+
o("amount", "-100 (white) … 100 (dark).", 40, -100, 100),
|
|
448
|
+
o("size", "Clear centre size, 0 … 100.", 50, 0, 100),
|
|
449
|
+
o("feather", "Softness, 0 … 100.", 60, 0, 100),
|
|
450
|
+
l("color", "Edge colour.", "#000000")
|
|
451
|
+
],
|
|
452
|
+
example: {
|
|
453
|
+
type: "vignette",
|
|
454
|
+
amount: 40
|
|
455
|
+
},
|
|
456
|
+
cost: 1
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
id: "autoTone",
|
|
460
|
+
title: "Auto tone",
|
|
461
|
+
group: "auto",
|
|
462
|
+
description: "Stretch each channel's range (clips 0.5 % at each end) — fixes dull / hazy photos and colour casts.",
|
|
463
|
+
params: [o("clip", "Percent clipped at each end.", .5, 0, 5, { step: .1 })],
|
|
464
|
+
example: { type: "autoTone" },
|
|
465
|
+
cost: 1
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
id: "autoContrast",
|
|
469
|
+
title: "Auto contrast",
|
|
470
|
+
group: "auto",
|
|
471
|
+
description: "Stretch the luminance range without changing colours.",
|
|
472
|
+
params: [o("clip", "Percent clipped at each end.", .5, 0, 5, { step: .1 })],
|
|
473
|
+
example: { type: "autoContrast" },
|
|
474
|
+
cost: 1
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
id: "autoColor",
|
|
478
|
+
title: "Auto color",
|
|
479
|
+
group: "auto",
|
|
480
|
+
description: "Neutralise the colour cast (grey-world white balance) and stretch contrast.",
|
|
481
|
+
params: [],
|
|
482
|
+
example: { type: "autoColor" },
|
|
483
|
+
cost: 1
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
id: "look",
|
|
487
|
+
title: "Look",
|
|
488
|
+
group: "look",
|
|
489
|
+
description: "One-click photo grade (Instagram-style preset). Use `amount` (0..1) to dial it in.",
|
|
490
|
+
params: [u("look", "Look id.", "vintage", [
|
|
491
|
+
{
|
|
492
|
+
id: "bw",
|
|
493
|
+
title: "B&W",
|
|
494
|
+
description: "Neutral black & white."
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
id: "noir",
|
|
498
|
+
title: "Noir",
|
|
499
|
+
description: "Contrasty black & white with a dark vignette."
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
id: "sepia",
|
|
503
|
+
title: "Sepia",
|
|
504
|
+
description: "Warm brown monochrome, old print."
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
id: "vintage",
|
|
508
|
+
title: "Vintage",
|
|
509
|
+
description: "Faded warm colours, soft contrast, light vignette."
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
id: "polaroid",
|
|
513
|
+
title: "Polaroid",
|
|
514
|
+
description: "Warm, slightly washed instant-film look."
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
id: "lomo",
|
|
518
|
+
title: "Lomo",
|
|
519
|
+
description: "Saturated, contrasty, strong vignette."
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
id: "warm",
|
|
523
|
+
title: "Warm",
|
|
524
|
+
description: "Golden warm cast."
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
id: "cool",
|
|
528
|
+
title: "Cool",
|
|
529
|
+
description: "Blue cool cast."
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
id: "sunset",
|
|
533
|
+
title: "Sunset",
|
|
534
|
+
description: "Orange-pink evening glow."
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
id: "fade",
|
|
538
|
+
title: "Fade",
|
|
539
|
+
description: "Lifted blacks, matte pastel finish."
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
id: "punch",
|
|
543
|
+
title: "Punch",
|
|
544
|
+
description: "Vivid colours and extra contrast."
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
id: "cinema",
|
|
548
|
+
title: "Cinema",
|
|
549
|
+
description: "Teal shadows, orange highlights (blockbuster grade)."
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
id: "cyberpunk",
|
|
553
|
+
title: "Cyberpunk",
|
|
554
|
+
description: "Magenta / cyan neon grade."
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
id: "cross-process",
|
|
558
|
+
title: "Cross process",
|
|
559
|
+
description: "Green shadows, warm highlights (XPro film)."
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
id: "dramatic",
|
|
563
|
+
title: "Dramatic",
|
|
564
|
+
description: "Desaturated, hard contrast, dark edges."
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
id: "dreamy",
|
|
568
|
+
title: "Dreamy",
|
|
569
|
+
description: "Soft, airy, pastel lift."
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
id: "matte",
|
|
573
|
+
title: "Matte",
|
|
574
|
+
description: "Flat matte finish with lifted shadows and gentle colours."
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
id: "golden-hour",
|
|
578
|
+
title: "Golden hour",
|
|
579
|
+
description: "Late-afternoon warmth with soft highlights."
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
id: "film",
|
|
583
|
+
title: "Film",
|
|
584
|
+
description: "Subtle film emulation: soft contrast, warm mids, fine grain."
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
id: "clean",
|
|
588
|
+
title: "Clean",
|
|
589
|
+
description: "Bright, crisp, slightly cool — product / e-commerce."
|
|
590
|
+
}
|
|
591
|
+
].map((e) => e.id))],
|
|
592
|
+
example: {
|
|
593
|
+
type: "look",
|
|
594
|
+
look: "cinema",
|
|
595
|
+
amount: .7
|
|
596
|
+
},
|
|
597
|
+
cost: 2
|
|
598
|
+
}
|
|
599
|
+
];
|
|
600
|
+
o("amount", "Blend with the unfiltered pixels, 0 … 1.", 1, 0, 1, { step: .01 }), o("opacity", "0 … 1.", .5, 0, 1, { step: .01 }), o("angle", "Light angle, degrees (135 = shadow down-right).", 135, -180, 180), o("distance", "Offset, px.", 12, 0, 500, { px: !0 }), o("blur", "Softness, px.", 16, 0, 250, { px: !0 }), o("spread", "Grow before blurring, px.", 0, 0, 100, { px: !0 }), o("opacity", "0 … 1.", .6, 0, 1, { step: .01 }), o("blur", "Size, px.", 20, 0, 250, { px: !0 }), o("spread", "Grow before blurring, px.", 0, 0, 100, { px: !0 }), o("opacity", "0 … 1.", .5, 0, 1, { step: .01 }), o("angle", "Light angle, degrees.", 135, -180, 180), o("distance", "Offset, px.", 6, 0, 200, { px: !0 }), o("blur", "Softness, px.", 10, 0, 200, { px: !0 }), o("width", "Px.", 6, 0, 200, { px: !0 }), o("opacity", "0 … 1.", 1, 0, 1, { step: .01 }), o("opacity", "0 … 1.", 1, 0, 1, { step: .01 });
|
|
601
|
+
var p = [
|
|
602
|
+
{
|
|
603
|
+
id: "inter",
|
|
604
|
+
family: "Inter",
|
|
605
|
+
weights: [
|
|
606
|
+
400,
|
|
607
|
+
600,
|
|
608
|
+
700,
|
|
609
|
+
800
|
|
610
|
+
],
|
|
611
|
+
style: "sans",
|
|
612
|
+
description: "Neutral modern sans — UI, body text, clean headlines."
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
id: "montserrat",
|
|
616
|
+
family: "Montserrat",
|
|
617
|
+
weights: [
|
|
618
|
+
400,
|
|
619
|
+
700,
|
|
620
|
+
800
|
|
621
|
+
],
|
|
622
|
+
style: "sans",
|
|
623
|
+
description: "Geometric sans — bold marketing headlines."
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
id: "poppins",
|
|
627
|
+
family: "Poppins",
|
|
628
|
+
weights: [
|
|
629
|
+
400,
|
|
630
|
+
600,
|
|
631
|
+
700
|
|
632
|
+
],
|
|
633
|
+
style: "sans",
|
|
634
|
+
description: "Friendly geometric sans — social posts, thumbnails."
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
id: "space-grotesk",
|
|
638
|
+
family: "Space Grotesk",
|
|
639
|
+
weights: [500, 700],
|
|
640
|
+
style: "sans",
|
|
641
|
+
description: "Techy grotesk — startups, tech."
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
id: "playfair",
|
|
645
|
+
family: "Playfair Display",
|
|
646
|
+
weights: [400, 700],
|
|
647
|
+
italic: [400],
|
|
648
|
+
style: "serif",
|
|
649
|
+
description: "Elegant high-contrast serif — luxury, editorial, quotes."
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
id: "dm-serif",
|
|
653
|
+
family: "DM Serif Display",
|
|
654
|
+
weights: [400],
|
|
655
|
+
style: "serif",
|
|
656
|
+
description: "Display serif — magazine covers, titles."
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
id: "roboto-slab",
|
|
660
|
+
family: "Roboto Slab",
|
|
661
|
+
weights: [400, 700],
|
|
662
|
+
style: "slab",
|
|
663
|
+
description: "Sturdy slab serif — posters, labels."
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
id: "bebas-neue",
|
|
667
|
+
family: "Bebas Neue",
|
|
668
|
+
weights: [400],
|
|
669
|
+
style: "display",
|
|
670
|
+
description: "Tall all-caps condensed — YouTube thumbnails, posters, sports."
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
id: "anton",
|
|
674
|
+
family: "Anton",
|
|
675
|
+
weights: [400],
|
|
676
|
+
style: "display",
|
|
677
|
+
description: "Heavy condensed — impact headlines."
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
id: "oswald",
|
|
681
|
+
family: "Oswald",
|
|
682
|
+
weights: [400, 600],
|
|
683
|
+
style: "display",
|
|
684
|
+
description: "Condensed gothic — banners, sale tags."
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
id: "archivo-black",
|
|
688
|
+
family: "Archivo Black",
|
|
689
|
+
weights: [400],
|
|
690
|
+
style: "display",
|
|
691
|
+
description: "Very bold grotesk — loud short words."
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
id: "lobster",
|
|
695
|
+
family: "Lobster",
|
|
696
|
+
weights: [400],
|
|
697
|
+
style: "script",
|
|
698
|
+
description: "Retro bold script — food, vintage, fun."
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
id: "pacifico",
|
|
702
|
+
family: "Pacifico",
|
|
703
|
+
weights: [400],
|
|
704
|
+
style: "script",
|
|
705
|
+
description: "Surf brush script — casual, summer."
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
id: "caveat",
|
|
709
|
+
family: "Caveat",
|
|
710
|
+
weights: [400, 700],
|
|
711
|
+
style: "script",
|
|
712
|
+
description: "Handwriting — notes, annotations, personal touch."
|
|
713
|
+
},
|
|
714
|
+
{
|
|
715
|
+
id: "jetbrains-mono",
|
|
716
|
+
family: "JetBrains Mono",
|
|
717
|
+
weights: [400, 700],
|
|
718
|
+
style: "mono",
|
|
719
|
+
description: "Monospace — code, tech labels."
|
|
720
|
+
}
|
|
721
|
+
], m = [
|
|
722
|
+
{
|
|
723
|
+
id: "rmbg-1.4",
|
|
724
|
+
task: "background-removal",
|
|
725
|
+
repo: "briaai/RMBG-1.4",
|
|
726
|
+
sizeMb: 168,
|
|
727
|
+
license: "bria-rmbg-1.4 (non-commercial)",
|
|
728
|
+
description: "General background removal — products, people, animals, objects. Best default."
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
id: "modnet",
|
|
732
|
+
task: "background-removal",
|
|
733
|
+
repo: "Xenova/modnet",
|
|
734
|
+
sizeMb: 25,
|
|
735
|
+
license: "Apache-2.0",
|
|
736
|
+
description: "Portrait matting — people only, soft hair edges."
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
id: "slimsam",
|
|
740
|
+
task: "segmentation",
|
|
741
|
+
repo: "Xenova/slimsam-77-uniform",
|
|
742
|
+
sizeMb: 30,
|
|
743
|
+
license: "Apache-2.0",
|
|
744
|
+
description: "Segment Anything (light): select an object from points or a box."
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
id: "sam-base",
|
|
748
|
+
task: "segmentation",
|
|
749
|
+
repo: "Xenova/sam-vit-base",
|
|
750
|
+
sizeMb: 100,
|
|
751
|
+
license: "Apache-2.0",
|
|
752
|
+
description: "Segment Anything (base): more precise selections, slower."
|
|
753
|
+
}
|
|
754
|
+
], h = {
|
|
755
|
+
"background-removal": "rmbg-1.4",
|
|
756
|
+
segmentation: "slimsam"
|
|
757
|
+
}, g = (e) => f.find((t) => t.id === e), _ = (e) => p.find((t) => t.id === e), v = (e) => m.find((t) => t.id === e), y = null, b = /* @__PURE__ */ new Map(), x = {};
|
|
758
|
+
function S(e) {
|
|
759
|
+
x = {
|
|
760
|
+
...x,
|
|
761
|
+
...e
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
async function C() {
|
|
765
|
+
return y || (y = import("./chunks/transformers.web-D5Vsg6-A.js").then((e) => (e.env.allowLocalModels = !1, x.remoteHost && (e.env.remoteHost = x.remoteHost), x.remotePathTemplate && (e.env.remotePathTemplate = x.remotePathTemplate), x.wasmPaths && e.env.backends?.onnx?.wasm && (e.env.backends.onnx.wasm.wasmPaths = x.wasmPaths), e.env.backends?.onnx?.wasm && typeof crossOriginIsolated < "u" && !crossOriginIsolated && (e.env.backends.onnx.wasm.numThreads = 1), e)), y.catch(() => y = null)), y;
|
|
766
|
+
}
|
|
767
|
+
function ee(e) {
|
|
768
|
+
let t = /* @__PURE__ */ new Map();
|
|
769
|
+
return (n) => {
|
|
770
|
+
if (!n?.file) return;
|
|
771
|
+
n.status === "progress" && typeof n.progress == "number" ? t.set(n.file, n.progress) : n.status === "done" ? t.set(n.file, 100) : n.status === "initiate" && !t.has(n.file) && t.set(n.file, 0);
|
|
772
|
+
let r = [...t.values()], i = r.length ? r.reduce((e, t) => e + t, 0) / r.length : 0;
|
|
773
|
+
x.onProgress?.({
|
|
774
|
+
model: e,
|
|
775
|
+
progress: i / 100,
|
|
776
|
+
label: `Loading ${e} (${Math.round(i)} %)`
|
|
777
|
+
});
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
async function te(e) {
|
|
781
|
+
let t = v(e);
|
|
782
|
+
if (!t) throw Error(`Unknown model "${e}". Models: ${m.map((e) => e.id).join(", ")}.`);
|
|
783
|
+
let n = await C(), r = b.get(e);
|
|
784
|
+
if (!r) {
|
|
785
|
+
let i = ee(e);
|
|
786
|
+
r = (async () => {
|
|
787
|
+
if (x.onProgress?.({
|
|
788
|
+
model: e,
|
|
789
|
+
progress: 0,
|
|
790
|
+
label: `Loading ${e}`
|
|
791
|
+
}), t.task === "segmentation") {
|
|
792
|
+
let [e, r] = await Promise.all([n.SamModel.from_pretrained(t.repo, {
|
|
793
|
+
progress_callback: i,
|
|
794
|
+
dtype: "fp32"
|
|
795
|
+
}), n.AutoProcessor.from_pretrained(t.repo, { progress_callback: i })]);
|
|
796
|
+
return {
|
|
797
|
+
model: e,
|
|
798
|
+
processor: r
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
let r = t.id === "rmbg-1.4", [a, o] = await Promise.all([n.AutoModel.from_pretrained(t.repo, {
|
|
802
|
+
progress_callback: i,
|
|
803
|
+
dtype: "fp32",
|
|
804
|
+
...r ? { config: { model_type: "custom" } } : {}
|
|
805
|
+
}), n.AutoProcessor.from_pretrained(t.repo, {
|
|
806
|
+
progress_callback: i,
|
|
807
|
+
...r ? { config: {
|
|
808
|
+
do_normalize: !0,
|
|
809
|
+
do_pad: !1,
|
|
810
|
+
do_rescale: !0,
|
|
811
|
+
do_resize: !0,
|
|
812
|
+
image_mean: [
|
|
813
|
+
.5,
|
|
814
|
+
.5,
|
|
815
|
+
.5
|
|
816
|
+
],
|
|
817
|
+
image_std: [
|
|
818
|
+
1,
|
|
819
|
+
1,
|
|
820
|
+
1
|
|
821
|
+
],
|
|
822
|
+
resample: 2,
|
|
823
|
+
rescale_factor: 1 / 255,
|
|
824
|
+
size: {
|
|
825
|
+
width: 1024,
|
|
826
|
+
height: 1024
|
|
827
|
+
}
|
|
828
|
+
} } : {}
|
|
829
|
+
})]);
|
|
830
|
+
return {
|
|
831
|
+
model: a,
|
|
832
|
+
processor: o
|
|
833
|
+
};
|
|
834
|
+
})(), r.catch(() => b.delete(e)), b.set(e, r);
|
|
835
|
+
}
|
|
836
|
+
let i = await r;
|
|
837
|
+
return x.onProgress?.({
|
|
838
|
+
model: e,
|
|
839
|
+
progress: 1,
|
|
840
|
+
label: `${e} ready`
|
|
841
|
+
}), {
|
|
842
|
+
...i,
|
|
843
|
+
tf: n
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
async function ne(e, t = h["background-removal"]) {
|
|
847
|
+
if (v(t)?.task !== "background-removal") throw Error(`"${t}" is not a background-removal model.`);
|
|
848
|
+
let { model: n, processor: r, tf: i } = await te(t), { pixel_values: a } = await r(i.RawImage.fromCanvas(e)), o = await n({ input: a }), s = o.output ?? o.alphas ?? Object.values(o)[0], c = s[0] ?? s, l = await i.RawImage.fromTensor(c.mul(255).to("uint8")).resize(e.width, e.height), u = l.data, d = l.channels ?? 1, f = new Uint8ClampedArray(e.width * e.height);
|
|
849
|
+
for (let e = 0; e < f.length; e++) f[e] = u[e * d];
|
|
850
|
+
return f;
|
|
851
|
+
}
|
|
852
|
+
async function re(e, t, n = h.segmentation) {
|
|
853
|
+
if (v(n)?.task !== "segmentation") throw Error(`"${n}" is not a segmentation model.`);
|
|
854
|
+
let { model: r, processor: i, tf: a } = await te(n), o = e.width, s = e.height, c = a.RawImage.fromCanvas(e), l = (t.points ?? []).map((e) => [Math.max(0, Math.min(o - 1, e[0])), Math.max(0, Math.min(s - 1, e[1]))]), u = (t.points ?? []).map((e) => +!!e[2]), d = t.box ? [
|
|
855
|
+
Math.max(0, t.box[0]),
|
|
856
|
+
Math.max(0, t.box[1]),
|
|
857
|
+
Math.min(o, t.box[2]),
|
|
858
|
+
Math.min(s, t.box[3])
|
|
859
|
+
] : null;
|
|
860
|
+
l.length || (l = [d ? [(d[0] + d[2]) / 2, (d[1] + d[3]) / 2] : [o / 2, s / 2]], u = [1]);
|
|
861
|
+
let f = await i(c, {
|
|
862
|
+
input_points: [[l]],
|
|
863
|
+
input_labels: [[u]],
|
|
864
|
+
...d ? { input_boxes: [[d]] } : {}
|
|
865
|
+
}), p = await r(f), m = await i.post_process_masks(p.pred_masks, f.original_sizes, f.reshaped_input_sizes), g = Array.isArray(m) ? m[0] : m, _ = p.iou_scores?.data ?? [1], y = 0;
|
|
866
|
+
for (let e = 1; e < _.length; e++) _[e] > _[y] && (y = e);
|
|
867
|
+
let b = g.dims, x = b.length >= 3 ? b[b.length - 3] : 1, S = b[b.length - 2], C = b[b.length - 1], ee = Math.min(y, x - 1), ne = g.data, re = new Uint8ClampedArray(o * s), ie = ee * S * C;
|
|
868
|
+
for (let e = 0; e < s; e++) {
|
|
869
|
+
let t = Math.min(S - 1, Math.floor(e * S / s));
|
|
870
|
+
for (let n = 0; n < o; n++) {
|
|
871
|
+
let r = Math.min(C - 1, Math.floor(n * C / o));
|
|
872
|
+
re[e * o + n] = ne[ie + t * C + r] ? 255 : 0;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return re;
|
|
876
|
+
}
|
|
877
|
+
// src/core/color.ts
|
|
878
|
+
var ie = {
|
|
879
|
+
aliceblue: "f0f8ff",
|
|
880
|
+
antiquewhite: "faebd7",
|
|
881
|
+
aqua: "00ffff",
|
|
882
|
+
aquamarine: "7fffd4",
|
|
883
|
+
azure: "f0ffff",
|
|
884
|
+
beige: "f5f5dc",
|
|
885
|
+
bisque: "ffe4c4",
|
|
886
|
+
black: "000000",
|
|
887
|
+
blanchedalmond: "ffebcd",
|
|
888
|
+
blue: "0000ff",
|
|
889
|
+
blueviolet: "8a2be2",
|
|
890
|
+
brown: "a52a2a",
|
|
891
|
+
burlywood: "deb887",
|
|
892
|
+
cadetblue: "5f9ea0",
|
|
893
|
+
chartreuse: "7fff00",
|
|
894
|
+
chocolate: "d2691e",
|
|
895
|
+
coral: "ff7f50",
|
|
896
|
+
cornflowerblue: "6495ed",
|
|
897
|
+
cornsilk: "fff8dc",
|
|
898
|
+
crimson: "dc143c",
|
|
899
|
+
cyan: "00ffff",
|
|
900
|
+
darkblue: "00008b",
|
|
901
|
+
darkcyan: "008b8b",
|
|
902
|
+
darkgoldenrod: "b8860b",
|
|
903
|
+
darkgray: "a9a9a9",
|
|
904
|
+
darkgreen: "006400",
|
|
905
|
+
darkgrey: "a9a9a9",
|
|
906
|
+
darkkhaki: "bdb76b",
|
|
907
|
+
darkmagenta: "8b008b",
|
|
908
|
+
darkolivegreen: "556b2f",
|
|
909
|
+
darkorange: "ff8c00",
|
|
910
|
+
darkorchid: "9932cc",
|
|
911
|
+
darkred: "8b0000",
|
|
912
|
+
darksalmon: "e9967a",
|
|
913
|
+
darkseagreen: "8fbc8f",
|
|
914
|
+
darkslateblue: "483d8b",
|
|
915
|
+
darkslategray: "2f4f4f",
|
|
916
|
+
darkslategrey: "2f4f4f",
|
|
917
|
+
darkturquoise: "00ced1",
|
|
918
|
+
darkviolet: "9400d3",
|
|
919
|
+
deeppink: "ff1493",
|
|
920
|
+
deepskyblue: "00bfff",
|
|
921
|
+
dimgray: "696969",
|
|
922
|
+
dimgrey: "696969",
|
|
923
|
+
dodgerblue: "1e90ff",
|
|
924
|
+
firebrick: "b22222",
|
|
925
|
+
floralwhite: "fffaf0",
|
|
926
|
+
forestgreen: "228b22",
|
|
927
|
+
fuchsia: "ff00ff",
|
|
928
|
+
gainsboro: "dcdcdc",
|
|
929
|
+
ghostwhite: "f8f8ff",
|
|
930
|
+
gold: "ffd700",
|
|
931
|
+
goldenrod: "daa520",
|
|
932
|
+
gray: "808080",
|
|
933
|
+
green: "008000",
|
|
934
|
+
greenyellow: "adff2f",
|
|
935
|
+
grey: "808080",
|
|
936
|
+
honeydew: "f0fff0",
|
|
937
|
+
hotpink: "ff69b4",
|
|
938
|
+
indianred: "cd5c5c",
|
|
939
|
+
indigo: "4b0082",
|
|
940
|
+
ivory: "fffff0",
|
|
941
|
+
khaki: "f0e68c",
|
|
942
|
+
lavender: "e6e6fa",
|
|
943
|
+
lavenderblush: "fff0f5",
|
|
944
|
+
lawngreen: "7cfc00",
|
|
945
|
+
lemonchiffon: "fffacd",
|
|
946
|
+
lightblue: "add8e6",
|
|
947
|
+
lightcoral: "f08080",
|
|
948
|
+
lightcyan: "e0ffff",
|
|
949
|
+
lightgoldenrodyellow: "fafad2",
|
|
950
|
+
lightgray: "d3d3d3",
|
|
951
|
+
lightgreen: "90ee90",
|
|
952
|
+
lightgrey: "d3d3d3",
|
|
953
|
+
lightpink: "ffb6c1",
|
|
954
|
+
lightsalmon: "ffa07a",
|
|
955
|
+
lightseagreen: "20b2aa",
|
|
956
|
+
lightskyblue: "87cefa",
|
|
957
|
+
lightslategray: "778899",
|
|
958
|
+
lightslategrey: "778899",
|
|
959
|
+
lightsteelblue: "b0c4de",
|
|
960
|
+
lightyellow: "ffffe0",
|
|
961
|
+
lime: "00ff00",
|
|
962
|
+
limegreen: "32cd32",
|
|
963
|
+
linen: "faf0e6",
|
|
964
|
+
magenta: "ff00ff",
|
|
965
|
+
maroon: "800000",
|
|
966
|
+
mediumaquamarine: "66cdaa",
|
|
967
|
+
mediumblue: "0000cd",
|
|
968
|
+
mediumorchid: "ba55d3",
|
|
969
|
+
mediumpurple: "9370db",
|
|
970
|
+
mediumseagreen: "3cb371",
|
|
971
|
+
mediumslateblue: "7b68ee",
|
|
972
|
+
mediumspringgreen: "00fa9a",
|
|
973
|
+
mediumturquoise: "48d1cc",
|
|
974
|
+
mediumvioletred: "c71585",
|
|
975
|
+
midnightblue: "191970",
|
|
976
|
+
mintcream: "f5fffa",
|
|
977
|
+
mistyrose: "ffe4e1",
|
|
978
|
+
moccasin: "ffe4b5",
|
|
979
|
+
navajowhite: "ffdead",
|
|
980
|
+
navy: "000080",
|
|
981
|
+
oldlace: "fdf5e6",
|
|
982
|
+
olive: "808000",
|
|
983
|
+
olivedrab: "6b8e23",
|
|
984
|
+
orange: "ffa500",
|
|
985
|
+
orangered: "ff4500",
|
|
986
|
+
orchid: "da70d6",
|
|
987
|
+
palegoldenrod: "eee8aa",
|
|
988
|
+
palegreen: "98fb98",
|
|
989
|
+
paleturquoise: "afeeee",
|
|
990
|
+
palevioletred: "db7093",
|
|
991
|
+
papayawhip: "ffefd5",
|
|
992
|
+
peachpuff: "ffdab9",
|
|
993
|
+
peru: "cd853f",
|
|
994
|
+
pink: "ffc0cb",
|
|
995
|
+
plum: "dda0dd",
|
|
996
|
+
powderblue: "b0e0e6",
|
|
997
|
+
purple: "800080",
|
|
998
|
+
rebeccapurple: "663399",
|
|
999
|
+
red: "ff0000",
|
|
1000
|
+
rosybrown: "bc8f8f",
|
|
1001
|
+
royalblue: "4169e1",
|
|
1002
|
+
saddlebrown: "8b4513",
|
|
1003
|
+
salmon: "fa8072",
|
|
1004
|
+
sandybrown: "f4a460",
|
|
1005
|
+
seagreen: "2e8b57",
|
|
1006
|
+
seashell: "fff5ee",
|
|
1007
|
+
sienna: "a0522d",
|
|
1008
|
+
silver: "c0c0c0",
|
|
1009
|
+
skyblue: "87ceeb",
|
|
1010
|
+
slateblue: "6a5acd",
|
|
1011
|
+
slategray: "708090",
|
|
1012
|
+
slategrey: "708090",
|
|
1013
|
+
snow: "fffafa",
|
|
1014
|
+
springgreen: "00ff7f",
|
|
1015
|
+
steelblue: "4682b4",
|
|
1016
|
+
tan: "d2b48c",
|
|
1017
|
+
teal: "008080",
|
|
1018
|
+
thistle: "d8bfd8",
|
|
1019
|
+
tomato: "ff6347",
|
|
1020
|
+
turquoise: "40e0d0",
|
|
1021
|
+
violet: "ee82ee",
|
|
1022
|
+
wheat: "f5deb3",
|
|
1023
|
+
white: "ffffff",
|
|
1024
|
+
whitesmoke: "f5f5f5",
|
|
1025
|
+
yellow: "ffff00",
|
|
1026
|
+
yellowgreen: "9acd32"
|
|
1027
|
+
}, w = (e, t, n) => Math.min(n, Math.max(t, e));
|
|
1028
|
+
function ae(e) {
|
|
1029
|
+
if (!/^[0-9a-f]+$/i.test(e) || ((e.length === 3 || e.length === 4) && (e = [...e].map((e) => e + e).join("")), e.length !== 6 && e.length !== 8)) return null;
|
|
1030
|
+
let t = (t) => parseInt(e.slice(t, t + 2), 16);
|
|
1031
|
+
return {
|
|
1032
|
+
r: t(0),
|
|
1033
|
+
g: t(2),
|
|
1034
|
+
b: t(4),
|
|
1035
|
+
a: e.length === 8 ? t(6) / 255 : 1
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
function T(e, t) {
|
|
1039
|
+
let n = /^(-?\d*\.?\d+(?:e-?\d+)?)(%?)$/i.exec(e.trim());
|
|
1040
|
+
if (!n) return null;
|
|
1041
|
+
let r = Number(n[1]);
|
|
1042
|
+
return n[2] ? r / 100 * t : r;
|
|
1043
|
+
}
|
|
1044
|
+
function oe(e) {
|
|
1045
|
+
let t = /^(-?\d*\.?\d+)(deg|rad|turn|grad)?$/i.exec(e.trim());
|
|
1046
|
+
if (!t) return null;
|
|
1047
|
+
let n = Number(t[1]);
|
|
1048
|
+
switch ((t[2] ?? "deg").toLowerCase()) {
|
|
1049
|
+
case "rad": return n * 180 / Math.PI;
|
|
1050
|
+
case "turn": return n * 360;
|
|
1051
|
+
case "grad": return n * .9;
|
|
1052
|
+
default: return n;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
function se(e) {
|
|
1056
|
+
let t = e.split("/");
|
|
1057
|
+
if (t.length > 2) return null;
|
|
1058
|
+
let n = (t[0].includes(",") ? t[0].split(",") : t[0].trim().split(/\s+/)).map((e) => e.trim()).filter((e) => e !== "");
|
|
1059
|
+
return t.length === 2 && n.push(t[1].trim()), n;
|
|
1060
|
+
}
|
|
1061
|
+
function ce(e, t, n) {
|
|
1062
|
+
e = (e % 360 + 360) % 360;
|
|
1063
|
+
let r = (1 - Math.abs(2 * n - 1)) * t, i = r * (1 - Math.abs(e / 60 % 2 - 1)), a = n - r / 2, [o, s, c] = e < 60 ? [
|
|
1064
|
+
r,
|
|
1065
|
+
i,
|
|
1066
|
+
0
|
|
1067
|
+
] : e < 120 ? [
|
|
1068
|
+
i,
|
|
1069
|
+
r,
|
|
1070
|
+
0
|
|
1071
|
+
] : e < 180 ? [
|
|
1072
|
+
0,
|
|
1073
|
+
r,
|
|
1074
|
+
i
|
|
1075
|
+
] : e < 240 ? [
|
|
1076
|
+
0,
|
|
1077
|
+
i,
|
|
1078
|
+
r
|
|
1079
|
+
] : e < 300 ? [
|
|
1080
|
+
i,
|
|
1081
|
+
0,
|
|
1082
|
+
r
|
|
1083
|
+
] : [
|
|
1084
|
+
r,
|
|
1085
|
+
0,
|
|
1086
|
+
i
|
|
1087
|
+
];
|
|
1088
|
+
return [
|
|
1089
|
+
(o + a) * 255,
|
|
1090
|
+
(s + a) * 255,
|
|
1091
|
+
(c + a) * 255
|
|
1092
|
+
];
|
|
1093
|
+
}
|
|
1094
|
+
function le(e) {
|
|
1095
|
+
if (typeof e != "string") return null;
|
|
1096
|
+
let t = e.trim().toLowerCase();
|
|
1097
|
+
if (!t) return null;
|
|
1098
|
+
if (t.startsWith("#")) return ae(t.slice(1));
|
|
1099
|
+
if (t === "transparent") return {
|
|
1100
|
+
r: 0,
|
|
1101
|
+
g: 0,
|
|
1102
|
+
b: 0,
|
|
1103
|
+
a: 0
|
|
1104
|
+
};
|
|
1105
|
+
let n = ie[t];
|
|
1106
|
+
if (n) return ae(n);
|
|
1107
|
+
let r = /^(rgba?|hsla?)\((.*)\)$/.exec(t);
|
|
1108
|
+
if (!r) return null;
|
|
1109
|
+
let i = se(r[2]);
|
|
1110
|
+
if (!i || i.length !== 3 && i.length !== 4) return null;
|
|
1111
|
+
let a = i.length === 4 ? T(i[3], 1) : 1;
|
|
1112
|
+
if (a === null) return null;
|
|
1113
|
+
if (r[1].startsWith("rgb")) {
|
|
1114
|
+
let [e, t, n] = i.slice(0, 3).map((e) => T(e, 255));
|
|
1115
|
+
return e === null || t === null || n === null ? null : {
|
|
1116
|
+
r: w(e, 0, 255),
|
|
1117
|
+
g: w(t, 0, 255),
|
|
1118
|
+
b: w(n, 0, 255),
|
|
1119
|
+
a: w(a, 0, 1)
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
let o = oe(i[0]), s = T(i[1], 1), c = T(i[2], 1);
|
|
1123
|
+
if (o === null || s === null || c === null || !i[1].trim().endsWith("%") || !i[2].trim().endsWith("%")) return null;
|
|
1124
|
+
let [l, u, d] = ce(o, w(s, 0, 1), w(c, 0, 1));
|
|
1125
|
+
return {
|
|
1126
|
+
r: l,
|
|
1127
|
+
g: u,
|
|
1128
|
+
b: d,
|
|
1129
|
+
a: w(a, 0, 1)
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function ue({ r: e, g: t, b: n }) {
|
|
1133
|
+
return "#" + [
|
|
1134
|
+
e,
|
|
1135
|
+
t,
|
|
1136
|
+
n
|
|
1137
|
+
].map((e) => Math.round(w(e, 0, 255)).toString(16).padStart(2, "0")).join("");
|
|
1138
|
+
}
|
|
1139
|
+
// src/engine/filters/pixels.ts
|
|
1140
|
+
var E = (e) => e < 0 ? 0 : e > 255 ? 255 : e, D = (e) => e < 0 ? 0 : e > 1 ? 1 : e;
|
|
1141
|
+
function de(e) {
|
|
1142
|
+
return {
|
|
1143
|
+
data: new Uint8ClampedArray(e.data),
|
|
1144
|
+
width: e.width,
|
|
1145
|
+
height: e.height
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
function O(e, t, n = t, r = t) {
|
|
1149
|
+
let i = e.data;
|
|
1150
|
+
for (let e = 0; e < i.length; e += 4) i[e] = t[i[e]], i[e + 1] = n[i[e + 1]], i[e + 2] = r[i[e + 2]];
|
|
1151
|
+
}
|
|
1152
|
+
function k(e) {
|
|
1153
|
+
let t = /* @__PURE__ */ new Uint8ClampedArray(256);
|
|
1154
|
+
for (let n = 0; n < 256; n++) t[n] = Math.round(E(e(n)));
|
|
1155
|
+
return t;
|
|
1156
|
+
}
|
|
1157
|
+
var A = (e, t, n) => .299 * e + .587 * t + .114 * n, fe = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4, pe = (e) => e <= .0031308 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - .055;
|
|
1158
|
+
function me(e, t, n, r, i) {
|
|
1159
|
+
if (r < 1) return;
|
|
1160
|
+
let a = 1 / (r + r + 1);
|
|
1161
|
+
for (let o = 0; o < n; o++) {
|
|
1162
|
+
let n = o * t, s = e[n], c = e[n + t - 1], l = r * s;
|
|
1163
|
+
for (let i = 0; i < r; i++) l += e[n + Math.min(i, t - 1)];
|
|
1164
|
+
for (let o = 0; o < t; o++) {
|
|
1165
|
+
let u = e[n + Math.min(o + r, t - 1)] ?? c;
|
|
1166
|
+
l += u, i[n + o] = l * a;
|
|
1167
|
+
let d = o - r >= 0 ? e[n + o - r] : s;
|
|
1168
|
+
l -= d;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
for (let o = 0; o < t; o++) {
|
|
1172
|
+
let s = i[o], c = r * s;
|
|
1173
|
+
for (let e = 0; e < r; e++) c += i[Math.min(e, n - 1) * t + o];
|
|
1174
|
+
for (let l = 0; l < n; l++) c += i[Math.min(l + r, n - 1) * t + o], e[l * t + o] = c * a, c -= l - r >= 0 ? i[(l - r) * t + o] : s;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
function he(e, t = 3) {
|
|
1178
|
+
let n = Math.sqrt(12 * e * e / t + 1), r = Math.floor(n);
|
|
1179
|
+
r % 2 == 0 && r--;
|
|
1180
|
+
let i = r + 2, a = (12 * e * e - t * r * r - 4 * t * r - 3 * t) / (-4 * r - 4), o = Math.round(a);
|
|
1181
|
+
return Array.from({ length: t }, (e, t) => Math.max(0, ((t < o ? r : i) - 1) / 2));
|
|
1182
|
+
}
|
|
1183
|
+
function j(e, t, n, r) {
|
|
1184
|
+
if (r < .5) return;
|
|
1185
|
+
let i = new Float32Array(e.length);
|
|
1186
|
+
for (let a of he(r / 2)) me(e, t, n, Math.round(a), i);
|
|
1187
|
+
}
|
|
1188
|
+
function ge(e, t) {
|
|
1189
|
+
if (t < .5) return;
|
|
1190
|
+
let { data: n, width: r, height: i } = e, a = r * i, o = new Float32Array(a), s = new Float32Array(a), c = new Float32Array(a), l = new Float32Array(a), u = !0;
|
|
1191
|
+
for (let e = 0, t = 0; t < a; e += 4, t++) {
|
|
1192
|
+
let r = n[e + 3] / 255;
|
|
1193
|
+
r < 1 && (u = !1), o[t] = n[e] * r, s[t] = n[e + 1] * r, c[t] = n[e + 2] * r, l[t] = r;
|
|
1194
|
+
}
|
|
1195
|
+
j(o, r, i, t), j(s, r, i, t), j(c, r, i, t), u || j(l, r, i, t);
|
|
1196
|
+
for (let e = 0, t = 0; t < a; e += 4, t++) {
|
|
1197
|
+
let r = l[t];
|
|
1198
|
+
r <= 1e-6 ? n[e + 3] = 0 : (n[e] = o[t] / r, n[e + 1] = s[t] / r, n[e + 2] = c[t] / r, n[e + 3] = r * 255);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
function _e(e, t) {
|
|
1202
|
+
let { data: n, width: r, height: i } = e, a = new Float32Array(r * i);
|
|
1203
|
+
for (let e = 0, t = 0; t < a.length; e += 4, t++) a[t] = A(n[e], n[e + 1], n[e + 2]) / 255;
|
|
1204
|
+
return j(a, r, i, t), a;
|
|
1205
|
+
}
|
|
1206
|
+
function ve(e, t, n, r) {
|
|
1207
|
+
if (r < .5) return;
|
|
1208
|
+
let i = new Float32Array(e.length);
|
|
1209
|
+
for (let t = 0; t < i.length; t++) i[t] = e[t];
|
|
1210
|
+
j(i, t, n, r);
|
|
1211
|
+
for (let t = 0; t < i.length; t++) e[t] = i[t];
|
|
1212
|
+
}
|
|
1213
|
+
function ye(e) {
|
|
1214
|
+
let t = e >>> 0;
|
|
1215
|
+
return () => {
|
|
1216
|
+
t = t + 1831565813 >>> 0;
|
|
1217
|
+
let e = t;
|
|
1218
|
+
return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function be(e, t, n) {
|
|
1222
|
+
e /= 255, t /= 255, n /= 255;
|
|
1223
|
+
let r = Math.max(e, t, n), i = Math.min(e, t, n), a = (r + i) / 2;
|
|
1224
|
+
if (r === i) return [
|
|
1225
|
+
0,
|
|
1226
|
+
0,
|
|
1227
|
+
a
|
|
1228
|
+
];
|
|
1229
|
+
let o = r - i, s = a > .5 ? o / (2 - r - i) : o / (r + i), c;
|
|
1230
|
+
return c = r === e ? (t - n) / o + (t < n ? 6 : 0) : r === t ? (n - e) / o + 2 : (e - t) / o + 4, [
|
|
1231
|
+
c * 60,
|
|
1232
|
+
s,
|
|
1233
|
+
a
|
|
1234
|
+
];
|
|
1235
|
+
}
|
|
1236
|
+
function xe(e, t, n) {
|
|
1237
|
+
return n < 0 && (n += 1), n > 1 && --n, n < 1 / 6 ? e + (t - e) * 6 * n : n < 1 / 2 ? t : n < 2 / 3 ? e + (t - e) * (2 / 3 - n) * 6 : e;
|
|
1238
|
+
}
|
|
1239
|
+
function Se(e, t, n) {
|
|
1240
|
+
if (e = (e % 360 + 360) % 360 / 360, t === 0) return [
|
|
1241
|
+
n * 255,
|
|
1242
|
+
n * 255,
|
|
1243
|
+
n * 255
|
|
1244
|
+
];
|
|
1245
|
+
let r = n < .5 ? n * (1 + t) : n + t - n * t, i = 2 * n - r;
|
|
1246
|
+
return [
|
|
1247
|
+
xe(i, r, e + 1 / 3) * 255,
|
|
1248
|
+
xe(i, r, e) * 255,
|
|
1249
|
+
xe(i, r, e - 1 / 3) * 255
|
|
1250
|
+
];
|
|
1251
|
+
}
|
|
1252
|
+
function Ce(e) {
|
|
1253
|
+
let t = [...e].sort((e, t) => e[0] - t[0]), n = t.length, r = /* @__PURE__ */ new Uint8ClampedArray(256);
|
|
1254
|
+
if (n === 0) return k((e) => e);
|
|
1255
|
+
if (n === 1) return k(() => t[0][1]);
|
|
1256
|
+
let i = t.map((e) => e[0]), a = t.map((e) => e[1]), o = [], s = [];
|
|
1257
|
+
for (let e = 0; e < n - 1; e++) o.push(i[e + 1] - i[e]), s.push((a[e + 1] - a[e]) / (i[e + 1] - i[e] || 1));
|
|
1258
|
+
let c = [s[0]];
|
|
1259
|
+
for (let e = 1; e < n - 1; e++) c.push(s[e - 1] * s[e] <= 0 ? 0 : (s[e - 1] + s[e]) / 2);
|
|
1260
|
+
c.push(s[n - 2]);
|
|
1261
|
+
for (let e = 0; e < n - 1; e++) {
|
|
1262
|
+
if (s[e] === 0) {
|
|
1263
|
+
c[e] = 0, c[e + 1] = 0;
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
let t = c[e] / s[e], n = c[e + 1] / s[e], r = t * t + n * n;
|
|
1267
|
+
if (r > 9) {
|
|
1268
|
+
let i = 3 / Math.sqrt(r);
|
|
1269
|
+
c[e] = i * t * s[e], c[e + 1] = i * n * s[e];
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
for (let e = 0; e < 256; e++) {
|
|
1273
|
+
if (e <= i[0]) {
|
|
1274
|
+
r[e] = a[0];
|
|
1275
|
+
continue;
|
|
1276
|
+
}
|
|
1277
|
+
if (e >= i[n - 1]) {
|
|
1278
|
+
r[e] = a[n - 1];
|
|
1279
|
+
continue;
|
|
1280
|
+
}
|
|
1281
|
+
let t = 0;
|
|
1282
|
+
for (; t < n - 2 && e > i[t + 1];) t++;
|
|
1283
|
+
let s = o[t], l = (e - i[t]) / s, u = 2 * l ** 3 - 3 * l ** 2 + 1, d = l ** 3 - 2 * l ** 2 + l, f = -2 * l ** 3 + 3 * l ** 2, p = l ** 3 - l ** 2;
|
|
1284
|
+
r[e] = E(Math.round(u * a[t] + d * s * c[t] + f * a[t + 1] + p * s * c[t + 1]));
|
|
1285
|
+
}
|
|
1286
|
+
return r;
|
|
1287
|
+
}
|
|
1288
|
+
function we(e) {
|
|
1289
|
+
let t = /* @__PURE__ */ new Uint32Array(256), n = /* @__PURE__ */ new Uint32Array(256), r = /* @__PURE__ */ new Uint32Array(256), i = /* @__PURE__ */ new Uint32Array(256), a = e.data, o = 0;
|
|
1290
|
+
for (let e = 0; e < a.length; e += 4) a[e + 3] < 8 || (t[a[e]]++, n[a[e + 1]]++, r[a[e + 2]]++, i[Math.round(A(a[e], a[e + 1], a[e + 2]))]++, o++);
|
|
1291
|
+
return {
|
|
1292
|
+
r: t,
|
|
1293
|
+
g: n,
|
|
1294
|
+
b: r,
|
|
1295
|
+
l: i,
|
|
1296
|
+
count: o
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
function M(e, t, n) {
|
|
1300
|
+
let r = t * n / 100, i = 0, a = 0;
|
|
1301
|
+
for (; i < 255 && a + e[i] <= r;) a += e[i++];
|
|
1302
|
+
let o = 255;
|
|
1303
|
+
for (a = 0; o > 0 && a + e[o] <= r;) a += e[o--];
|
|
1304
|
+
return o <= i ? [0, 255] : [i, o];
|
|
1305
|
+
}
|
|
1306
|
+
var N = (e, t) => k((n) => (n - e) * 255 / Math.max(1, t - e));
|
|
1307
|
+
// src/engine/analyze.ts
|
|
1308
|
+
function Te(e) {
|
|
1309
|
+
let { data: t, width: n, height: r } = e, i = we(e), a = Math.max(1, i.count), o = 0, s = 0, c = 0, l = 0, u = 0, d = 0;
|
|
1310
|
+
for (let e = 0; e < t.length; e += 4) {
|
|
1311
|
+
if (t[e + 3] < 250 && d++, t[e + 3] < 8) continue;
|
|
1312
|
+
let n = t[e], r = t[e + 1], i = t[e + 2], a = A(n, r, i);
|
|
1313
|
+
o += a, s += a * a;
|
|
1314
|
+
let f = Math.max(n, r, i);
|
|
1315
|
+
c += f ? (f - Math.min(n, r, i)) / f : 0, l += n - i, u += (n + i) / 2 - r;
|
|
1316
|
+
}
|
|
1317
|
+
let f = o / a, p = Math.sqrt(Math.max(0, s / a - f * f)), [m, h] = M(i.l, a, 1), g = 0, _ = 0;
|
|
1318
|
+
for (let e = 0; e <= 2; e++) g += i.l[e];
|
|
1319
|
+
for (let e = 253; e <= 255; e++) _ += i.l[e];
|
|
1320
|
+
let v = 0, y = 0, b = Math.max(1, Math.floor(Math.sqrt(n * r / 25e4)));
|
|
1321
|
+
for (let e = b; e < r - b; e += b) for (let r = b; r < n - b; r += b) {
|
|
1322
|
+
let i = (e, r) => {
|
|
1323
|
+
let i = (r * n + e) * 4;
|
|
1324
|
+
return A(t[i], t[i + 1], t[i + 2]);
|
|
1325
|
+
}, a = 4 * i(r, e) - i(r - 1, e) - i(r + 1, e) - i(r, e - 1) - i(r, e + 1);
|
|
1326
|
+
v += a * a, y++;
|
|
1327
|
+
}
|
|
1328
|
+
let x = {
|
|
1329
|
+
width: n,
|
|
1330
|
+
height: r,
|
|
1331
|
+
transparent: P(d / (n * r) * 100),
|
|
1332
|
+
brightness: P(f),
|
|
1333
|
+
contrast: P(p),
|
|
1334
|
+
range: [m, h],
|
|
1335
|
+
clippedShadows: P(g / a * 100),
|
|
1336
|
+
clippedHighlights: P(_ / a * 100),
|
|
1337
|
+
saturation: P(c / a * 100),
|
|
1338
|
+
cast: {
|
|
1339
|
+
warm: P(l / a),
|
|
1340
|
+
magenta: P(u / a)
|
|
1341
|
+
},
|
|
1342
|
+
sharpness: P(y ? v / y : 0),
|
|
1343
|
+
dominant: Ee(e, 5),
|
|
1344
|
+
suggestions: []
|
|
1345
|
+
};
|
|
1346
|
+
return x.suggestions = De(x), x;
|
|
1347
|
+
}
|
|
1348
|
+
var P = (e) => Math.round(e * 10) / 10;
|
|
1349
|
+
function Ee(e, t) {
|
|
1350
|
+
let n = e.data, r = /* @__PURE__ */ new Map(), i = Math.max(1, Math.floor(e.width * e.height / 12e4)) * 4, a = 0;
|
|
1351
|
+
for (let e = 0; e < n.length; e += i) {
|
|
1352
|
+
if (n[e + 3] < 128) continue;
|
|
1353
|
+
let t = n[e] >> 4 << 8 | n[e + 1] >> 4 << 4 | n[e + 2] >> 4, i = r.get(t) ?? {
|
|
1354
|
+
r: 0,
|
|
1355
|
+
g: 0,
|
|
1356
|
+
b: 0,
|
|
1357
|
+
n: 0
|
|
1358
|
+
};
|
|
1359
|
+
i.r += n[e], i.g += n[e + 1], i.b += n[e + 2], i.n++, r.set(t, i), a++;
|
|
1360
|
+
}
|
|
1361
|
+
let o = [...r.values()].sort((e, t) => t.n - e.n), s = [];
|
|
1362
|
+
for (let e of o) {
|
|
1363
|
+
let n = {
|
|
1364
|
+
r: e.r / e.n,
|
|
1365
|
+
g: e.g / e.n,
|
|
1366
|
+
b: e.b / e.n,
|
|
1367
|
+
n: e.n
|
|
1368
|
+
}, r = s.find((e) => Math.abs(e.r - n.r) + Math.abs(e.g - n.g) + Math.abs(e.b - n.b) < 60);
|
|
1369
|
+
r ? r.n += n.n : s.length < t && s.push(n);
|
|
1370
|
+
}
|
|
1371
|
+
return s.sort((e, t) => t.n - e.n).map((e) => ({
|
|
1372
|
+
color: ue({
|
|
1373
|
+
r: e.r,
|
|
1374
|
+
g: e.g,
|
|
1375
|
+
b: e.b,
|
|
1376
|
+
a: 1
|
|
1377
|
+
}),
|
|
1378
|
+
share: P(e.n / Math.max(1, a) * 100)
|
|
1379
|
+
}));
|
|
1380
|
+
}
|
|
1381
|
+
function De(e) {
|
|
1382
|
+
let t = [];
|
|
1383
|
+
return e.brightness < 85 ? t.push({
|
|
1384
|
+
issue: `Underexposed (mean brightness ${e.brightness}/255).`,
|
|
1385
|
+
filter: {
|
|
1386
|
+
type: "exposure",
|
|
1387
|
+
exposure: P(Math.min(1.5, (110 - e.brightness) / 45))
|
|
1388
|
+
}
|
|
1389
|
+
}) : e.brightness > 185 && t.push({
|
|
1390
|
+
issue: `Overexposed (mean brightness ${e.brightness}/255).`,
|
|
1391
|
+
filter: {
|
|
1392
|
+
type: "exposure",
|
|
1393
|
+
exposure: P(-Math.min(1.2, (e.brightness - 160) / 50))
|
|
1394
|
+
}
|
|
1395
|
+
}), e.range[0] > 25 || e.range[1] < 230 ? t.push({
|
|
1396
|
+
issue: `Flat / hazy: tones only span ${e.range[0]}–${e.range[1]}.`,
|
|
1397
|
+
filter: { type: "autoContrast" }
|
|
1398
|
+
}) : e.contrast < 40 && t.push({
|
|
1399
|
+
issue: `Low contrast (std-dev ${e.contrast}).`,
|
|
1400
|
+
filter: {
|
|
1401
|
+
type: "curves",
|
|
1402
|
+
rgb: [
|
|
1403
|
+
[0, 0],
|
|
1404
|
+
[64, 52],
|
|
1405
|
+
[192, 206],
|
|
1406
|
+
[255, 255]
|
|
1407
|
+
]
|
|
1408
|
+
}
|
|
1409
|
+
}), e.clippedShadows > 8 && t.push({
|
|
1410
|
+
issue: `${e.clippedShadows} % of the picture is crushed black.`,
|
|
1411
|
+
filter: {
|
|
1412
|
+
type: "shadowsHighlights",
|
|
1413
|
+
shadows: 40
|
|
1414
|
+
}
|
|
1415
|
+
}), e.clippedHighlights > 8 && t.push({
|
|
1416
|
+
issue: `${e.clippedHighlights} % of the picture is blown out.`,
|
|
1417
|
+
filter: {
|
|
1418
|
+
type: "shadowsHighlights",
|
|
1419
|
+
shadows: 0,
|
|
1420
|
+
highlights: 40
|
|
1421
|
+
}
|
|
1422
|
+
}), Math.abs(e.cast.warm) > 18 && t.push({
|
|
1423
|
+
issue: `${e.cast.warm > 0 ? "Warm / orange" : "Cool / blue"} colour cast.`,
|
|
1424
|
+
filter: {
|
|
1425
|
+
type: "temperature",
|
|
1426
|
+
temperature: P(Math.max(-60, Math.min(60, -e.cast.warm * .8)))
|
|
1427
|
+
}
|
|
1428
|
+
}), Math.abs(e.cast.magenta) > 12 && t.push({
|
|
1429
|
+
issue: `${e.cast.magenta > 0 ? "Magenta" : "Green"} tint.`,
|
|
1430
|
+
filter: {
|
|
1431
|
+
type: "temperature",
|
|
1432
|
+
tint: P(Math.max(-60, Math.min(60, -e.cast.magenta * 1.2)))
|
|
1433
|
+
}
|
|
1434
|
+
}), e.saturation < 18 && e.contrast > 10 && t.push({
|
|
1435
|
+
issue: `Muted colours (saturation ${e.saturation}).`,
|
|
1436
|
+
filter: {
|
|
1437
|
+
type: "vibrance",
|
|
1438
|
+
vibrance: 35
|
|
1439
|
+
}
|
|
1440
|
+
}), e.sharpness < 60 && t.push({
|
|
1441
|
+
issue: `Soft image (sharpness ${e.sharpness}).`,
|
|
1442
|
+
filter: {
|
|
1443
|
+
type: "sharpen",
|
|
1444
|
+
amount: 90,
|
|
1445
|
+
radius: 1.2
|
|
1446
|
+
}
|
|
1447
|
+
}), t;
|
|
1448
|
+
}
|
|
1449
|
+
// src/engine/canvas.ts
|
|
1450
|
+
var Oe = 16384;
|
|
1451
|
+
function F(e, t) {
|
|
1452
|
+
let n = Math.max(1, Math.min(Oe, Math.ceil(e))), r = Math.max(1, Math.min(Oe, Math.ceil(t)));
|
|
1453
|
+
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(n, r);
|
|
1454
|
+
let i = document.createElement("canvas");
|
|
1455
|
+
return i.width = n, i.height = r, i;
|
|
1456
|
+
}
|
|
1457
|
+
function I(e, t) {
|
|
1458
|
+
let n = e.getContext("2d", {
|
|
1459
|
+
willReadFrequently: !1,
|
|
1460
|
+
...t
|
|
1461
|
+
});
|
|
1462
|
+
if (!n) throw Error("Canvas 2D is not available.");
|
|
1463
|
+
return n.imageSmoothingEnabled = !0, n.imageSmoothingQuality = "high", n;
|
|
1464
|
+
}
|
|
1465
|
+
function L(e) {
|
|
1466
|
+
let t = I(e).getImageData(0, 0, e.width, e.height);
|
|
1467
|
+
return {
|
|
1468
|
+
data: t.data,
|
|
1469
|
+
width: t.width,
|
|
1470
|
+
height: t.height
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function ke(e, t) {
|
|
1474
|
+
I(e).putImageData(new ImageData(t.data, t.width, t.height), 0, 0);
|
|
1475
|
+
}
|
|
1476
|
+
function Ae(e) {
|
|
1477
|
+
return !e || e === "normal" ? "source-over" : e;
|
|
1478
|
+
}
|
|
1479
|
+
function R(e, t) {
|
|
1480
|
+
let n = F(e.width, e.height), r = I(n);
|
|
1481
|
+
return r.drawImage(e, 0, 0), r.globalCompositeOperation = "source-in", r.fillStyle = t, r.fillRect(0, 0, n.width, n.height), n;
|
|
1482
|
+
}
|
|
1483
|
+
function je(e) {
|
|
1484
|
+
let t = L(e).data, n = new Uint8ClampedArray(t.length / 4);
|
|
1485
|
+
for (let e = 0, r = 3; e < n.length; e++, r += 4) n[e] = t[r];
|
|
1486
|
+
return n;
|
|
1487
|
+
}
|
|
1488
|
+
function Me(e, t, n, r = [
|
|
1489
|
+
255,
|
|
1490
|
+
255,
|
|
1491
|
+
255
|
|
1492
|
+
]) {
|
|
1493
|
+
let i = F(t, n), a = new Uint8ClampedArray(t * n * 4);
|
|
1494
|
+
for (let t = 0, n = 0; t < e.length; t++, n += 4) a[n] = r[0], a[n + 1] = r[1], a[n + 2] = r[2], a[n + 3] = e[t];
|
|
1495
|
+
return ke(i, {
|
|
1496
|
+
data: a,
|
|
1497
|
+
width: t,
|
|
1498
|
+
height: n
|
|
1499
|
+
}), i;
|
|
1500
|
+
}
|
|
1501
|
+
async function Ne(e, t, n) {
|
|
1502
|
+
let r = n === void 0 ? void 0 : Math.max(.01, Math.min(1, n));
|
|
1503
|
+
return "convertToBlob" in e ? e.convertToBlob({
|
|
1504
|
+
type: t,
|
|
1505
|
+
quality: r
|
|
1506
|
+
}) : new Promise((n, i) => e.toBlob((e) => e ? n(e) : i(/* @__PURE__ */ Error("Encoding failed.")), t, r));
|
|
1507
|
+
}
|
|
1508
|
+
// src/core/jsonPath.ts
|
|
1509
|
+
var Pe = (e) => !!e && typeof e == "object" && !Array.isArray(e);
|
|
1510
|
+
function Fe(e) {
|
|
1511
|
+
return JSON.stringify(Ie(e));
|
|
1512
|
+
}
|
|
1513
|
+
function Ie(e) {
|
|
1514
|
+
if (Array.isArray(e)) return e.map(Ie);
|
|
1515
|
+
if (Pe(e)) {
|
|
1516
|
+
let t = {};
|
|
1517
|
+
for (let n of Object.keys(e).sort()) e[n] !== void 0 && (t[n] = Ie(e[n]));
|
|
1518
|
+
return t;
|
|
1519
|
+
}
|
|
1520
|
+
return e;
|
|
1521
|
+
}
|
|
1522
|
+
// src/engine/effects.ts
|
|
1523
|
+
var z = (e, t) => typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
1524
|
+
function Le(e, t) {
|
|
1525
|
+
if (!e) return 0;
|
|
1526
|
+
let n = 0;
|
|
1527
|
+
return e.dropShadow && (n = Math.max(n, (z(e.dropShadow.distance, 12) + z(e.dropShadow.blur, 16) * 1.5 + z(e.dropShadow.spread, 0)) * t)), e.outerGlow && (n = Math.max(n, (z(e.outerGlow.blur, 20) * 1.5 + z(e.outerGlow.spread, 0)) * t)), e.stroke && (e.stroke.position ?? "outside") !== "inside" && (n = Math.max(n, z(e.stroke.width, 6) * t)), Math.ceil(n) + (n ? 2 : 0);
|
|
1528
|
+
}
|
|
1529
|
+
var Re = (e) => !!e && Object.values(e).some(Boolean);
|
|
1530
|
+
function B(e, t) {
|
|
1531
|
+
let n = F(e.width, e.height), r = I(n);
|
|
1532
|
+
if (r.drawImage(e, 0, 0), t < .5) return n;
|
|
1533
|
+
let i = Math.min(8, Math.max(1, Math.ceil(t / 3)));
|
|
1534
|
+
for (let n = 1; n <= i; n++) {
|
|
1535
|
+
let a = t * n / i, o = Math.min(48, Math.max(8, Math.ceil(a * 1.5)));
|
|
1536
|
+
for (let t = 0; t < o; t++) {
|
|
1537
|
+
let n = t / o * Math.PI * 2;
|
|
1538
|
+
r.drawImage(e, Math.cos(n) * a, Math.sin(n) * a);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return n;
|
|
1542
|
+
}
|
|
1543
|
+
function ze(e, t = 96) {
|
|
1544
|
+
let n = je(e);
|
|
1545
|
+
for (let e = 0; e < n.length; e++) n[e] = n[e] >= t ? 255 : n[e] * 255 / t;
|
|
1546
|
+
return Me(n, e.width, e.height);
|
|
1547
|
+
}
|
|
1548
|
+
function Be(e) {
|
|
1549
|
+
let t = F(e.width, e.height), n = I(t);
|
|
1550
|
+
return n.fillStyle = "#000", n.fillRect(0, 0, t.width, t.height), n.globalCompositeOperation = "destination-out", n.drawImage(e, 0, 0), t;
|
|
1551
|
+
}
|
|
1552
|
+
function Ve(e, t, n) {
|
|
1553
|
+
if (t < .5) return R(e, n);
|
|
1554
|
+
let r = je(e);
|
|
1555
|
+
return ve(r, e.width, e.height, t), R(Me(r, e.width, e.height), n);
|
|
1556
|
+
}
|
|
1557
|
+
function He(e, t, n) {
|
|
1558
|
+
let r = e.canvas, i = r.width, a = r.height, o = F(i, a), s = I(o);
|
|
1559
|
+
if (t.dropShadow) {
|
|
1560
|
+
let e = t.dropShadow, i = z(e.spread, 0) * n, a = Ve(i ? B(r, i) : r, z(e.blur, 16) * n, e.color ?? "#000000"), o = z(e.angle, 135) * Math.PI / 180, c = z(e.distance, 12) * n;
|
|
1561
|
+
s.globalAlpha = z(e.opacity, .5), s.drawImage(a, -Math.cos(o) * c, Math.sin(o) * c), s.globalAlpha = 1;
|
|
1562
|
+
}
|
|
1563
|
+
if (t.outerGlow) {
|
|
1564
|
+
let e = t.outerGlow, i = z(e.spread, 0) * n, a = Ve(i ? B(r, i) : r, z(e.blur, 20) * n, e.color ?? "#ffffff");
|
|
1565
|
+
s.globalAlpha = z(e.opacity, .6), s.drawImage(a, 0, 0), s.globalAlpha = z(e.opacity, .6) * .5, s.drawImage(a, 0, 0), s.globalAlpha = 1;
|
|
1566
|
+
}
|
|
1567
|
+
let c = t.stroke, l = c ? z(c.width, 6) * n : 0, u = c?.position ?? "outside";
|
|
1568
|
+
if (c && l > 0 && u !== "inside") {
|
|
1569
|
+
let e = u === "center" ? l / 2 : l;
|
|
1570
|
+
s.globalAlpha = z(c.opacity, 1), s.drawImage(R(B(ze(r), e), c.color ?? "#ffffff"), 0, 0), s.globalAlpha = 1;
|
|
1571
|
+
}
|
|
1572
|
+
let d = F(i, a), f = I(d);
|
|
1573
|
+
if (f.drawImage(r, 0, 0), t.colorOverlay) {
|
|
1574
|
+
let e = t.colorOverlay, n = R(r, e.color ?? "#ffffff");
|
|
1575
|
+
f.globalAlpha = z(e.opacity, 1), f.globalCompositeOperation = Ae(e.blend), f.drawImage(n, 0, 0), f.globalAlpha = 1, f.globalCompositeOperation = "destination-in", f.drawImage(r, 0, 0), f.globalCompositeOperation = "source-over";
|
|
1576
|
+
}
|
|
1577
|
+
if (t.innerShadow) {
|
|
1578
|
+
let e = t.innerShadow, o = Ve(Be(r), z(e.blur, 10) * n, e.color ?? "#000000"), s = z(e.angle, 135) * Math.PI / 180, c = z(e.distance, 6) * n, l = F(i, a), u = I(l);
|
|
1579
|
+
u.drawImage(o, -Math.cos(s) * c, Math.sin(s) * c), u.globalCompositeOperation = "destination-in", u.drawImage(r, 0, 0), f.globalAlpha = z(e.opacity, .5), f.drawImage(l, 0, 0), f.globalAlpha = 1;
|
|
1580
|
+
}
|
|
1581
|
+
if (c && l > 0 && u !== "outside") {
|
|
1582
|
+
let e = u === "center" ? l / 2 : l, t = Be(B(Be(r), e)), n = R(r, c.color ?? "#ffffff"), i = I(n);
|
|
1583
|
+
i.globalCompositeOperation = "destination-out", i.drawImage(t, 0, 0), f.globalAlpha = z(c.opacity, 1), f.drawImage(n, 0, 0), f.globalAlpha = 1;
|
|
1584
|
+
}
|
|
1585
|
+
return s.drawImage(d, 0, 0), {
|
|
1586
|
+
canvas: o,
|
|
1587
|
+
x: e.x,
|
|
1588
|
+
y: e.y
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
// src/engine/filters/looks.ts
|
|
1592
|
+
function V(e, t, n, r, i = 1, a = 1, o = 1) {
|
|
1593
|
+
for (let s = 0; s < e.length; s += 4) e[s] = E((e[s] + t) * i), e[s + 1] = E((e[s + 1] + n) * a), e[s + 2] = E((e[s + 2] + r) * o);
|
|
1594
|
+
}
|
|
1595
|
+
function H(e, t) {
|
|
1596
|
+
for (let n = 0; n < e.length; n += 4) e[n] = E((e[n] - 128) * t + 128), e[n + 1] = E((e[n + 1] - 128) * t + 128), e[n + 2] = E((e[n + 2] - 128) * t + 128);
|
|
1597
|
+
}
|
|
1598
|
+
function U(e, t) {
|
|
1599
|
+
for (let n = 0; n < e.length; n += 4) {
|
|
1600
|
+
let r = A(e[n], e[n + 1], e[n + 2]);
|
|
1601
|
+
e[n] = E(r + (e[n] - r) * t), e[n + 1] = E(r + (e[n + 1] - r) * t), e[n + 2] = E(r + (e[n + 2] - r) * t);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
function W(e, t, n, r) {
|
|
1605
|
+
let i = (e) => {
|
|
1606
|
+
let t = /* @__PURE__ */ new Uint8ClampedArray(256);
|
|
1607
|
+
for (let n = 0; n < 256; n++) t[n] = 255 * (n / 255) ** (1 / e);
|
|
1608
|
+
return t;
|
|
1609
|
+
}, [a, o, s] = [
|
|
1610
|
+
i(t),
|
|
1611
|
+
i(n),
|
|
1612
|
+
i(r)
|
|
1613
|
+
];
|
|
1614
|
+
for (let t = 0; t < e.length; t += 4) e[t] = a[e[t]], e[t + 1] = o[e[t + 1]], e[t + 2] = s[e[t + 2]];
|
|
1615
|
+
}
|
|
1616
|
+
function G(e, t) {
|
|
1617
|
+
let { data: n, width: r, height: i } = e, a = r / 2, o = i / 2, s = Math.hypot(a, o) || 1;
|
|
1618
|
+
for (let e = 0; e < i; e++) for (let i = 0; i < r; i++) {
|
|
1619
|
+
let c = Math.hypot(i - a, e - o) / s, l = 1 - t * c * c, u = (e * r + i) * 4;
|
|
1620
|
+
n[u] *= l, n[u + 1] *= l, n[u + 2] *= l;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
function Ue(e, t, n) {
|
|
1624
|
+
for (let r = 0; r < e.length; r += 4) e[r] = t + e[r] * n, e[r + 1] = t + e[r + 1] * n, e[r + 2] = t + e[r + 2] * n;
|
|
1625
|
+
}
|
|
1626
|
+
function K(e, t, n) {
|
|
1627
|
+
for (let r = 0; r < e.length; r += 4) {
|
|
1628
|
+
let i = A(e[r], e[r + 1], e[r + 2]) / 255, a = 1 - i;
|
|
1629
|
+
e[r] = E(e[r] + n[0] * i + t[0] * a), e[r + 1] = E(e[r + 1] + n[1] * i + t[1] * a), e[r + 2] = E(e[r + 2] + n[2] * i + t[2] * a);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
var We = {
|
|
1633
|
+
bw: (e) => U(e.data, 0),
|
|
1634
|
+
noir: (e) => {
|
|
1635
|
+
U(e.data, 0), H(e.data, 1.55), W(e.data, .85, .85, .85), G(e, .45);
|
|
1636
|
+
},
|
|
1637
|
+
sepia: (e) => {
|
|
1638
|
+
let t = e.data;
|
|
1639
|
+
for (let e = 0; e < t.length; e += 4) {
|
|
1640
|
+
let n = t[e], r = t[e + 1], i = t[e + 2];
|
|
1641
|
+
t[e] = E(n * .393 + r * .769 + i * .189), t[e + 1] = E(n * .349 + r * .686 + i * .168), t[e + 2] = E(n * .272 + r * .534 + i * .131);
|
|
1642
|
+
}
|
|
1643
|
+
},
|
|
1644
|
+
vintage: (e) => {
|
|
1645
|
+
V(e.data, 8, -6, -16, 1, 1, .92), U(e.data, .7), H(e.data, .92), W(e.data, 1.05, 1, .9), G(e, .35);
|
|
1646
|
+
},
|
|
1647
|
+
polaroid: (e) => {
|
|
1648
|
+
V(e.data, 12, 4, -8), U(e.data, .85), H(e.data, .95);
|
|
1649
|
+
},
|
|
1650
|
+
lomo: (e) => {
|
|
1651
|
+
U(e.data, 1.45), H(e.data, 1.25), G(e, .55);
|
|
1652
|
+
},
|
|
1653
|
+
warm: (e) => {
|
|
1654
|
+
V(e.data, 18, 6, -14), U(e.data, 1.1);
|
|
1655
|
+
},
|
|
1656
|
+
cool: (e) => {
|
|
1657
|
+
V(e.data, -10, 0, 16), U(e.data, .95);
|
|
1658
|
+
},
|
|
1659
|
+
sunset: (e) => {
|
|
1660
|
+
V(e.data, 28, -4, -24, 1, 1, .95), U(e.data, 1.2);
|
|
1661
|
+
},
|
|
1662
|
+
fade: (e) => {
|
|
1663
|
+
let t = e.data;
|
|
1664
|
+
for (let e = 0; e < t.length; e += 4) t[e] = 40 + t[e] * .78, t[e + 1] = 40 + t[e + 1] * .78, t[e + 2] = 50 + t[e + 2] * .74;
|
|
1665
|
+
U(t, .85);
|
|
1666
|
+
},
|
|
1667
|
+
punch: (e) => {
|
|
1668
|
+
U(e.data, 1.4), H(e.data, 1.2);
|
|
1669
|
+
},
|
|
1670
|
+
cinema: (e) => {
|
|
1671
|
+
K(e.data, [
|
|
1672
|
+
-6,
|
|
1673
|
+
2,
|
|
1674
|
+
14
|
|
1675
|
+
], [
|
|
1676
|
+
20,
|
|
1677
|
+
6,
|
|
1678
|
+
-14
|
|
1679
|
+
]), H(e.data, 1.1);
|
|
1680
|
+
},
|
|
1681
|
+
cyberpunk: (e) => {
|
|
1682
|
+
let t = e.data;
|
|
1683
|
+
for (let e = 0; e < t.length; e += 4) t[e] = E(t[e] * 1.05 + 18), t[e + 1] = E(t[e + 1] * .85), t[e + 2] = E(t[e + 2] * 1.1 + 22);
|
|
1684
|
+
H(t, 1.25), U(t, 1.5);
|
|
1685
|
+
},
|
|
1686
|
+
"cross-process": (e) => {
|
|
1687
|
+
let t = e.data;
|
|
1688
|
+
for (let e = 0; e < t.length; e += 4) t[e] = E(t[e] * 1.1), t[e + 1] = E(t[e + 1] + (255 - t[e + 1]) * .15), t[e + 2] = E(t[e + 2] * .85);
|
|
1689
|
+
H(t, 1.18), U(t, 1.15);
|
|
1690
|
+
},
|
|
1691
|
+
dramatic: (e) => {
|
|
1692
|
+
H(e.data, 1.5), W(e.data, .85, .85, .85), U(e.data, .6), G(e, .4);
|
|
1693
|
+
},
|
|
1694
|
+
dreamy: (e) => {
|
|
1695
|
+
V(e.data, 14, 8, 16), U(e.data, .85), H(e.data, .88), W(e.data, 1.1, 1.05, 1.1);
|
|
1696
|
+
},
|
|
1697
|
+
matte: (e) => {
|
|
1698
|
+
Ue(e.data, 28, .86), U(e.data, .82), K(e.data, [
|
|
1699
|
+
0,
|
|
1700
|
+
4,
|
|
1701
|
+
8
|
|
1702
|
+
], [
|
|
1703
|
+
6,
|
|
1704
|
+
2,
|
|
1705
|
+
-4
|
|
1706
|
+
]);
|
|
1707
|
+
},
|
|
1708
|
+
"golden-hour": (e) => {
|
|
1709
|
+
K(e.data, [
|
|
1710
|
+
6,
|
|
1711
|
+
-2,
|
|
1712
|
+
-10
|
|
1713
|
+
], [
|
|
1714
|
+
26,
|
|
1715
|
+
12,
|
|
1716
|
+
-20
|
|
1717
|
+
]), U(e.data, 1.12), W(e.data, 1.06, 1.02, .96);
|
|
1718
|
+
},
|
|
1719
|
+
film: (e) => {
|
|
1720
|
+
Ue(e.data, 14, .92), H(e.data, 1.06), K(e.data, [
|
|
1721
|
+
-4,
|
|
1722
|
+
2,
|
|
1723
|
+
8
|
|
1724
|
+
], [
|
|
1725
|
+
10,
|
|
1726
|
+
4,
|
|
1727
|
+
-6
|
|
1728
|
+
]), U(e.data, .92);
|
|
1729
|
+
let t = ye(7), n = e.data;
|
|
1730
|
+
for (let e = 0; e < n.length; e += 4) {
|
|
1731
|
+
let r = (t() - .5) * 14;
|
|
1732
|
+
n[e] = E(n[e] + r), n[e + 1] = E(n[e + 1] + r), n[e + 2] = E(n[e + 2] + r);
|
|
1733
|
+
}
|
|
1734
|
+
},
|
|
1735
|
+
clean: (e) => {
|
|
1736
|
+
W(e.data, 1.08, 1.08, 1.1), V(e.data, -2, 0, 4), H(e.data, 1.06), U(e.data, 1.05);
|
|
1737
|
+
}
|
|
1738
|
+
}, q = (e, t) => typeof e == "number" && Number.isFinite(e) ? e : t, J = (e, t) => typeof e == "boolean" ? e : t, Ge = (e) => Array.isArray(e) && e.length === 3 ? [
|
|
1739
|
+
q(e[0], 0),
|
|
1740
|
+
q(e[1], 0),
|
|
1741
|
+
q(e[2], 0)
|
|
1742
|
+
] : [
|
|
1743
|
+
0,
|
|
1744
|
+
0,
|
|
1745
|
+
0
|
|
1746
|
+
], Ke = (e, t) => le(typeof e == "string" ? e : t) ?? le(t);
|
|
1747
|
+
function qe(e) {
|
|
1748
|
+
let t = (Array.isArray(e) && e.length >= 2 ? e : ["#000", "#fff"]).map((e, t, n) => Array.isArray(e) ? [q(e[0], t / (n.length - 1)), Ke(e[1], "#000")] : [t / (n.length - 1), Ke(e, "#000")]);
|
|
1749
|
+
t.sort((e, t) => e[0] - t[0]);
|
|
1750
|
+
let n = /* @__PURE__ */ new Uint8ClampedArray(256), r = /* @__PURE__ */ new Uint8ClampedArray(256), i = /* @__PURE__ */ new Uint8ClampedArray(256);
|
|
1751
|
+
for (let e = 0; e < 256; e++) {
|
|
1752
|
+
let a = e / 255, o = 0;
|
|
1753
|
+
for (; o < t.length - 2 && a > t[o + 1][0];) o++;
|
|
1754
|
+
let [s, c] = t[o], [l, u] = t[o + 1], d = l > s ? D((a - s) / (l - s)) : +(a >= l);
|
|
1755
|
+
n[e] = c.r + (u.r - c.r) * d, r[e] = c.g + (u.g - c.g) * d, i[e] = c.b + (u.b - c.b) * d;
|
|
1756
|
+
}
|
|
1757
|
+
return [
|
|
1758
|
+
n,
|
|
1759
|
+
r,
|
|
1760
|
+
i
|
|
1761
|
+
];
|
|
1762
|
+
}
|
|
1763
|
+
function Je(e, t, n) {
|
|
1764
|
+
let r = n - A(e[t], e[t + 1], e[t + 2]);
|
|
1765
|
+
e[t] = E(e[t] + r), e[t + 1] = E(e[t + 1] + r), e[t + 2] = E(e[t + 2] + r);
|
|
1766
|
+
}
|
|
1767
|
+
var Ye = {
|
|
1768
|
+
brightnessContrast(e, t) {
|
|
1769
|
+
let n = q(t.brightness, 0) / 100, r = q(t.contrast, 0) / 100, i = n >= 0 ? 1 / (1 + n * 1.2) : 1 - n * 1.2, a = r >= 0 ? 1 / (1 - r * .85) : 1 + r * .85;
|
|
1770
|
+
O(e, k((e) => (255 * (e / 255) ** i - 128) * a + 128));
|
|
1771
|
+
},
|
|
1772
|
+
exposure(e, t) {
|
|
1773
|
+
let n = 2 ** q(t.exposure, 0), r = q(t.offset, 0), i = q(t.gamma, 1);
|
|
1774
|
+
O(e, k((e) => 255 * pe(D(Math.max(0, fe(e / 255) * n + r) ** (1 / i)))));
|
|
1775
|
+
},
|
|
1776
|
+
shadowsHighlights(e, t, n) {
|
|
1777
|
+
let r = q(t.shadows, 35) / 100, i = q(t.highlights, 0) / 100;
|
|
1778
|
+
if (!r && !i) return;
|
|
1779
|
+
let a = _e(e, Math.max(1, q(t.radius, 30) * n.scale)), o = e.data;
|
|
1780
|
+
for (let e = 0, t = 0; t < a.length; e += 4, t++) {
|
|
1781
|
+
let n = a[t], s = (1 - n) ** 2, c = n ** 2;
|
|
1782
|
+
for (let t = 0; t < 3; t++) {
|
|
1783
|
+
let n = o[e + t] / 255;
|
|
1784
|
+
n += r * s * (1 - n) * n * 2.2, n -= i * c * n * (1 - n) * 2.2, o[e + t] = n * 255;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
},
|
|
1788
|
+
levels(e, t) {
|
|
1789
|
+
let n = q(t.black, 0), r = Math.max(n + 1, q(t.white, 255)), i = q(t.gamma, 1), a = q(t.outBlack, 0), o = q(t.outWhite, 255);
|
|
1790
|
+
O(e, k((e) => a + (o - a) * D((e - n) / (r - n)) ** (1 / i)));
|
|
1791
|
+
},
|
|
1792
|
+
curves(e, t) {
|
|
1793
|
+
let n = k((e) => e), r = Array.isArray(t.rgb) ? Ce(t.rgb) : n, i = (e) => Array.isArray(e) ? Ce(e) : n, [a, o, s] = [
|
|
1794
|
+
i(t.red),
|
|
1795
|
+
i(t.green),
|
|
1796
|
+
i(t.blue)
|
|
1797
|
+
];
|
|
1798
|
+
O(e, k((e) => a[r[e]]), k((e) => o[r[e]]), k((e) => s[r[e]]));
|
|
1799
|
+
},
|
|
1800
|
+
hueSaturation(e, t) {
|
|
1801
|
+
let n = q(t.hue, 0), r = q(t.saturation, 0) / 100, i = q(t.lightness, 0) / 100, a = J(t.colorize, !1), o = e.data;
|
|
1802
|
+
for (let e = 0; e < o.length; e += 4) {
|
|
1803
|
+
let [t, s, c] = be(o[e], o[e + 1], o[e + 2]);
|
|
1804
|
+
a ? (t = n, s = D(.25 + r * .75)) : (t += n, s = r >= 0 ? s + (1 - s) * r * s : s * (1 + r)), c = i >= 0 ? c + (1 - c) * i : c * (1 + i);
|
|
1805
|
+
let [l, u, d] = Se(t, D(s), D(c));
|
|
1806
|
+
o[e] = l, o[e + 1] = u, o[e + 2] = d;
|
|
1807
|
+
}
|
|
1808
|
+
},
|
|
1809
|
+
vibrance(e, t) {
|
|
1810
|
+
let n = q(t.vibrance, 30) / 100, r = q(t.saturation, 0) / 100, i = e.data;
|
|
1811
|
+
for (let e = 0; e < i.length; e += 4) {
|
|
1812
|
+
let t = i[e], a = i[e + 1], o = i[e + 2], s = Math.max(t, a, o);
|
|
1813
|
+
(t + a + o) / 3;
|
|
1814
|
+
let c = (s - Math.min(t, a, o)) / 255, l = t > a && a > o ? .5 : 1, u = 1 + r + n * (1 - c) * l * 1.4, d = A(t, a, o);
|
|
1815
|
+
i[e] = E(d + (t - d) * u), i[e + 1] = E(d + (a - d) * u), i[e + 2] = E(d + (o - d) * u);
|
|
1816
|
+
}
|
|
1817
|
+
},
|
|
1818
|
+
temperature(e, t) {
|
|
1819
|
+
let n = q(t.temperature, 0) / 100, r = q(t.tint, 0) / 100, i = 1 + n * .32 + r * .06, a = 1 - r * .22 + Math.abs(n) * .02, o = 1 - n * .36 + r * .08, s = (e) => k((t) => 255 * pe(D(fe(t / 255) * e)));
|
|
1820
|
+
O(e, s(i), s(a), s(o));
|
|
1821
|
+
},
|
|
1822
|
+
colorBalance(e, t) {
|
|
1823
|
+
let n = Ge(t.shadows), r = Ge(t.midtones), i = Ge(t.highlights), a = J(t.preserveLuminosity, !0), o = e.data;
|
|
1824
|
+
for (let e = 0; e < o.length; e += 4) {
|
|
1825
|
+
let t = A(o[e], o[e + 1], o[e + 2]), s = t / 255, c = D(1 - s * 2.2) * .8, l = D(1 - Math.abs(s - .5) * 2.5) * .8, u = D((s - .55) * 2.2) * .8;
|
|
1826
|
+
for (let t = 0; t < 3; t++) o[e + t] = E(o[e + t] + (n[t] * c + r[t] * l + i[t] * u) * 1.28);
|
|
1827
|
+
a && Je(o, e, t);
|
|
1828
|
+
}
|
|
1829
|
+
},
|
|
1830
|
+
photoFilter(e, t) {
|
|
1831
|
+
let n = Ke(t.color, "#ec8a00"), r = D(q(t.density, 25) / 100), i = J(t.preserveLuminosity, !0), a = e.data;
|
|
1832
|
+
for (let e = 0; e < a.length; e += 4) {
|
|
1833
|
+
let t = A(a[e], a[e + 1], a[e + 2]);
|
|
1834
|
+
a[e] = a[e] * (1 - r) + a[e] * n.r / 255 * r + n.r * r * .25, a[e + 1] = a[e + 1] * (1 - r) + a[e + 1] * n.g / 255 * r + n.g * r * .25, a[e + 2] = a[e + 2] * (1 - r) + a[e + 2] * n.b / 255 * r + n.b * r * .25, i && Je(a, e, t);
|
|
1835
|
+
}
|
|
1836
|
+
},
|
|
1837
|
+
gradientMap(e, t) {
|
|
1838
|
+
let [n, r, i] = qe(t.stops), a = e.data;
|
|
1839
|
+
for (let e = 0; e < a.length; e += 4) {
|
|
1840
|
+
let t = Math.round(A(a[e], a[e + 1], a[e + 2]));
|
|
1841
|
+
a[e] = n[t], a[e + 1] = r[t], a[e + 2] = i[t];
|
|
1842
|
+
}
|
|
1843
|
+
},
|
|
1844
|
+
grayscale(e, t) {
|
|
1845
|
+
let n = q(t.red, 30) / 100, r = q(t.green, 59) / 100, i = q(t.blue, 11) / 100, a = n + r + i;
|
|
1846
|
+
Math.abs(a) < .05 && ([n, r, i] = [
|
|
1847
|
+
.3,
|
|
1848
|
+
.59,
|
|
1849
|
+
.11
|
|
1850
|
+
]);
|
|
1851
|
+
let o = e.data;
|
|
1852
|
+
for (let e = 0; e < o.length; e += 4) {
|
|
1853
|
+
let t = E(o[e] * n + o[e + 1] * r + o[e + 2] * i);
|
|
1854
|
+
o[e] = o[e + 1] = o[e + 2] = t;
|
|
1855
|
+
}
|
|
1856
|
+
},
|
|
1857
|
+
sepia(e, t) {
|
|
1858
|
+
let n = D(q(t.intensity, 100) / 100), r = e.data;
|
|
1859
|
+
for (let e = 0; e < r.length; e += 4) {
|
|
1860
|
+
let t = r[e], i = r[e + 1], a = r[e + 2];
|
|
1861
|
+
r[e] = t + (E(t * .393 + i * .769 + a * .189) - t) * n, r[e + 1] = i + (E(t * .349 + i * .686 + a * .168) - i) * n, r[e + 2] = a + (E(t * .272 + i * .534 + a * .131) - a) * n;
|
|
1862
|
+
}
|
|
1863
|
+
},
|
|
1864
|
+
invert(e) {
|
|
1865
|
+
O(e, k((e) => 255 - e));
|
|
1866
|
+
},
|
|
1867
|
+
threshold(e, t) {
|
|
1868
|
+
let n = q(t.level, 128), r = e.data;
|
|
1869
|
+
for (let e = 0; e < r.length; e += 4) {
|
|
1870
|
+
let t = A(r[e], r[e + 1], r[e + 2]) >= n ? 255 : 0;
|
|
1871
|
+
r[e] = r[e + 1] = r[e + 2] = t;
|
|
1872
|
+
}
|
|
1873
|
+
},
|
|
1874
|
+
posterize(e, t) {
|
|
1875
|
+
let n = 255 / (Math.max(2, Math.round(q(t.levels, 6))) - 1);
|
|
1876
|
+
O(e, k((e) => Math.round(e / n) * n));
|
|
1877
|
+
},
|
|
1878
|
+
blur(e, t, n) {
|
|
1879
|
+
ge(e, q(t.radius, 6) * n.scale);
|
|
1880
|
+
},
|
|
1881
|
+
motionBlur(e, t, n) {
|
|
1882
|
+
let r = Math.round(q(t.distance, 20) * n.scale);
|
|
1883
|
+
if (r < 1) return;
|
|
1884
|
+
let i = q(t.angle, 0) * Math.PI / 180, a = Math.cos(i), o = Math.sin(i), { data: s, width: c, height: l } = de(e), u = e.data, d = r + 1;
|
|
1885
|
+
for (let e = 0; e < l; e++) for (let t = 0; t < c; t++) {
|
|
1886
|
+
let n = 0, i = 0, f = 0, p = 0;
|
|
1887
|
+
for (let u = 0; u < d; u++) {
|
|
1888
|
+
let d = u - r / 2, m = Math.min(c - 1, Math.max(0, Math.round(t + a * d))), h = (Math.min(l - 1, Math.max(0, Math.round(e + o * d))) * c + m) * 4, g = s[h + 3];
|
|
1889
|
+
n += s[h] * g, i += s[h + 1] * g, f += s[h + 2] * g, p += g;
|
|
1890
|
+
}
|
|
1891
|
+
let m = (e * c + t) * 4;
|
|
1892
|
+
p > 0 && (u[m] = n / p, u[m + 1] = i / p, u[m + 2] = f / p), u[m + 3] = p / d;
|
|
1893
|
+
}
|
|
1894
|
+
},
|
|
1895
|
+
surfaceBlur(e, t, n) {
|
|
1896
|
+
let r = Math.max(1, Math.round(q(t.radius, 8) * n.scale)), i = q(t.threshold, 25) / 100, a = (i * i * .25) ** 1.2 + 1e-5, { data: o, width: s, height: c } = e, l = s * c, u = new Float32Array(l), d = new Float32Array(l), f = (e) => {
|
|
1897
|
+
let t = new Float32Array(e);
|
|
1898
|
+
return j(t, s, c, r * 2), t;
|
|
1899
|
+
};
|
|
1900
|
+
for (let e = 0; e < 3; e++) {
|
|
1901
|
+
for (let t = 0, n = e; t < l; t++, n += 4) {
|
|
1902
|
+
let e = o[n] / 255;
|
|
1903
|
+
u[t] = e, d[t] = e * e;
|
|
1904
|
+
}
|
|
1905
|
+
let t = f(u), n = f(d), r = new Float32Array(l), i = new Float32Array(l);
|
|
1906
|
+
for (let e = 0; e < l; e++) {
|
|
1907
|
+
let o = n[e] - t[e] * t[e], s = o / (o + a);
|
|
1908
|
+
r[e] = s, i[e] = t[e] - s * t[e];
|
|
1909
|
+
}
|
|
1910
|
+
let s = f(r), c = f(i);
|
|
1911
|
+
for (let t = 0, n = e; t < l; t++, n += 4) o[n] = E((s[t] * u[t] + c[t]) * 255);
|
|
1912
|
+
}
|
|
1913
|
+
},
|
|
1914
|
+
sharpen(e, t, n) {
|
|
1915
|
+
let r = q(t.amount, 80) / 100, i = Math.max(.3, q(t.radius, 1.2) * n.scale), a = q(t.threshold, 2), o = de(e);
|
|
1916
|
+
ge(o, i * 2);
|
|
1917
|
+
let s = e.data, c = o.data;
|
|
1918
|
+
for (let e = 0; e < s.length; e += 4) for (let t = 0; t < 3; t++) {
|
|
1919
|
+
let n = s[e + t] - c[e + t];
|
|
1920
|
+
Math.abs(n) >= a && (s[e + t] = E(s[e + t] + n * r));
|
|
1921
|
+
}
|
|
1922
|
+
},
|
|
1923
|
+
clarity(e, t, n) {
|
|
1924
|
+
let r = q(t.amount, 30) / 100, i = _e(e, Math.max(2, q(t.radius, 24) * n.scale)), a = e.data;
|
|
1925
|
+
for (let e = 0, t = 0; t < i.length; e += 4, t++) {
|
|
1926
|
+
let n = A(a[e], a[e + 1], a[e + 2]) / 255, o = 1 - Math.abs(n - .5) * 1.6, s = (n - i[t]) * r * Math.max(0, o) * 255 * 1.4;
|
|
1927
|
+
a[e] = E(a[e] + s), a[e + 1] = E(a[e + 1] + s), a[e + 2] = E(a[e + 2] + s);
|
|
1928
|
+
}
|
|
1929
|
+
},
|
|
1930
|
+
noise(e, t, n) {
|
|
1931
|
+
let r = q(t.amount, 12) / 100 * 110, i = J(t.monochrome, !0), a = ye(Math.round(q(t.seed, 1)) * 7919 + 17), o = Math.max(1, Math.round(q(t.size, 1) * n.scale)), { data: s, width: c, height: l } = e, u = Math.ceil(c / o), d = Math.ceil(l / o), f = new Float32Array(u * d * 3);
|
|
1932
|
+
for (let e = 0; e < u * d; e++) {
|
|
1933
|
+
let t = a() + a() - 1;
|
|
1934
|
+
f[e * 3] = t, f[e * 3 + 1] = i ? t : a() + a() - 1, f[e * 3 + 2] = i ? t : a() + a() - 1;
|
|
1935
|
+
}
|
|
1936
|
+
for (let e = 0; e < l; e++) {
|
|
1937
|
+
let t = Math.floor(e / o) * u;
|
|
1938
|
+
for (let n = 0; n < c; n++) {
|
|
1939
|
+
let i = (t + Math.floor(n / o)) * 3, a = (e * c + n) * 4;
|
|
1940
|
+
s[a] = E(s[a] + f[i] * r), s[a + 1] = E(s[a + 1] + f[i + 1] * r), s[a + 2] = E(s[a + 2] + f[i + 2] * r);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
},
|
|
1944
|
+
pixelate(e, t, n) {
|
|
1945
|
+
let r = Math.max(1, Math.round(q(t.size, 16) * n.scale));
|
|
1946
|
+
if (r < 2) return;
|
|
1947
|
+
let { data: i, width: a, height: o } = e;
|
|
1948
|
+
for (let e = 0; e < o; e += r) for (let t = 0; t < a; t += r) {
|
|
1949
|
+
let n = 0, s = 0, c = 0, l = 0, u = 0, d = Math.min(o, e + r), f = Math.min(a, t + r);
|
|
1950
|
+
for (let r = e; r < d; r++) for (let e = t; e < f; e++) {
|
|
1951
|
+
let t = (r * a + e) * 4, o = i[t + 3];
|
|
1952
|
+
n += i[t] * o, s += i[t + 1] * o, c += i[t + 2] * o, l += o, u++;
|
|
1953
|
+
}
|
|
1954
|
+
let p = l ? n / l : 0, m = l ? s / l : 0, h = l ? c / l : 0, g = l / u;
|
|
1955
|
+
for (let n = e; n < d; n++) for (let e = t; e < f; e++) {
|
|
1956
|
+
let t = (n * a + e) * 4;
|
|
1957
|
+
i[t] = p, i[t + 1] = m, i[t + 2] = h, i[t + 3] = g;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
},
|
|
1961
|
+
vignette(e, t) {
|
|
1962
|
+
let n = q(t.amount, 40) / 100, r = q(t.size, 50) / 100, i = Math.max(.01, q(t.feather, 60) / 100), a = Ke(t.color, "#000000"), o = n >= 0 ? a : {
|
|
1963
|
+
r: 255,
|
|
1964
|
+
g: 255,
|
|
1965
|
+
b: 255,
|
|
1966
|
+
a: 1
|
|
1967
|
+
}, s = Math.abs(n), { data: c, width: l, height: u } = e, d = l / 2, f = u / 2, p = r * .8;
|
|
1968
|
+
for (let e = 0; e < u; e++) for (let t = 0; t < l; t++) {
|
|
1969
|
+
let n = (t - d) / d, r = (e - f) / f, a = D((Math.sqrt(n * n + r * r) / Math.SQRT2 * 1.25 - p) / i);
|
|
1970
|
+
a = a * a * (3 - 2 * a) * s;
|
|
1971
|
+
let u = (e * l + t) * 4;
|
|
1972
|
+
c[u] += (o.r - c[u]) * a, c[u + 1] += (o.g - c[u + 1]) * a, c[u + 2] += (o.b - c[u + 2]) * a;
|
|
1973
|
+
}
|
|
1974
|
+
},
|
|
1975
|
+
autoTone(e, t) {
|
|
1976
|
+
let n = q(t.clip, .5), r = we(e);
|
|
1977
|
+
if (!r.count) return;
|
|
1978
|
+
let [i, a] = M(r.r, r.count, n), [o, s] = M(r.g, r.count, n), [c, l] = M(r.b, r.count, n);
|
|
1979
|
+
O(e, N(i, a), N(o, s), N(c, l));
|
|
1980
|
+
},
|
|
1981
|
+
autoContrast(e, t) {
|
|
1982
|
+
let n = we(e);
|
|
1983
|
+
if (!n.count) return;
|
|
1984
|
+
let [r, i] = M(n.l, n.count, q(t.clip, .5));
|
|
1985
|
+
O(e, N(r, i));
|
|
1986
|
+
},
|
|
1987
|
+
autoColor(e) {
|
|
1988
|
+
let t = e.data, n = 0, r = 0, i = 0, a = 0;
|
|
1989
|
+
for (let e = 0; e < t.length; e += 4) t[e + 3] < 8 || (n += t[e], r += t[e + 1], i += t[e + 2], a++);
|
|
1990
|
+
if (!a) return;
|
|
1991
|
+
let o = (n + r + i) / 3 / a, [s, c, l] = [
|
|
1992
|
+
o / Math.max(1, n / a),
|
|
1993
|
+
o / Math.max(1, r / a),
|
|
1994
|
+
o / Math.max(1, i / a)
|
|
1995
|
+
], u = (e) => 1 + (Math.min(1.6, Math.max(.6, e)) - 1) * .7;
|
|
1996
|
+
O(e, k((e) => e * u(s)), k((e) => e * u(c)), k((e) => e * u(l))), Ye.autoContrast(e, { clip: .3 }, { scale: 1 });
|
|
1997
|
+
},
|
|
1998
|
+
look(e, t) {
|
|
1999
|
+
let n = We[String(t.look)];
|
|
2000
|
+
n && n(e);
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
function Xe(e, t, n) {
|
|
2004
|
+
for (let r of t ?? []) {
|
|
2005
|
+
if (!r || r.enabled === !1) continue;
|
|
2006
|
+
let t = Ye[r.type];
|
|
2007
|
+
if (!t) continue;
|
|
2008
|
+
let i = !g(r.type)?.params.some((e) => e.name === "amount") && typeof r.amount == "number" ? D(r.amount) : 1;
|
|
2009
|
+
if (i <= 0) continue;
|
|
2010
|
+
let a = Ze(r);
|
|
2011
|
+
if (i >= 1) {
|
|
2012
|
+
t(e, a, n);
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
2015
|
+
let o = new Uint8ClampedArray(e.data);
|
|
2016
|
+
t(e, a, n);
|
|
2017
|
+
let s = e.data;
|
|
2018
|
+
for (let e = 0; e < s.length; e++) s[e] = o[e] + (s[e] - o[e]) * i;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
function Ze(e) {
|
|
2022
|
+
let t = g(e.type), n = {};
|
|
2023
|
+
for (let e of t?.params ?? []) e.default !== void 0 && (n[e.name] = e.default);
|
|
2024
|
+
return {
|
|
2025
|
+
...n,
|
|
2026
|
+
...e
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
function Qe(e, t) {
|
|
2030
|
+
let n = 0;
|
|
2031
|
+
for (let r of e ?? []) {
|
|
2032
|
+
if (!r || typeof r != "object" || r.enabled === !1) continue;
|
|
2033
|
+
let e = Ze(r);
|
|
2034
|
+
r.type === "blur" ? n += q(e.radius, 6) * 1.5 * t : r.type === "motionBlur" && (n += q(e.distance, 20) / 2 * t);
|
|
2035
|
+
}
|
|
2036
|
+
return n >= .5 ? Math.ceil(n) + 2 : 0;
|
|
2037
|
+
}
|
|
2038
|
+
new Set(f.filter((e) => e.group === "blur" || e.group === "detail" || e.id === "shadowsHighlights" || e.id === "pixelate").map((e) => e.id));
|
|
2039
|
+
// src/engine/paint.ts
|
|
2040
|
+
function $e(e) {
|
|
2041
|
+
let t = Array.isArray(e) && e.length ? e : ["#000", "#fff"], n = t.length;
|
|
2042
|
+
return t.map((e, t) => Array.isArray(e) ? [Math.min(1, Math.max(0, Number(e[0]) || 0)), String(e[1])] : [n === 1 ? 0 : t / (n - 1), String(e)]);
|
|
2043
|
+
}
|
|
2044
|
+
function Y(e, t, n, r = "#ffffff") {
|
|
2045
|
+
if (t == null) return r;
|
|
2046
|
+
if (typeof t == "string") return t;
|
|
2047
|
+
if (t.type === "radial") {
|
|
2048
|
+
let r = n.x + (t.cx ?? .5) * n.w, i = n.y + (t.cy ?? .5) * n.h, a = (t.radius ?? 1) / Math.SQRT2, o = Math.max(.5, a * n.w), s = Math.max(.5, a * n.h);
|
|
2049
|
+
if (n.w === n.h || Math.abs(o - s) < .5) {
|
|
2050
|
+
let a = Math.max(.5, (t.radius ?? 1) * Math.hypot(n.w, n.h) * .5);
|
|
2051
|
+
return et(e.createRadialGradient(r, i, 0, r, i, a), t.stops);
|
|
2052
|
+
}
|
|
2053
|
+
return tt(e, r, i, o, s, t.stops);
|
|
2054
|
+
}
|
|
2055
|
+
let i = (t.angle ?? 90) * Math.PI / 180, a = Math.cos(i), o = Math.sin(i), s = Math.abs(n.w / 2 * a) + Math.abs(n.h / 2 * o), c = n.x + n.w / 2, l = n.y + n.h / 2;
|
|
2056
|
+
return et(e.createLinearGradient(c - a * s, l - o * s, c + a * s, l + o * s), t.stops);
|
|
2057
|
+
}
|
|
2058
|
+
function et(e, t) {
|
|
2059
|
+
for (let [n, r] of $e(t)) try {
|
|
2060
|
+
e.addColorStop(n, r);
|
|
2061
|
+
} catch {}
|
|
2062
|
+
return e;
|
|
2063
|
+
}
|
|
2064
|
+
function tt(e, t, n, r, i, a) {
|
|
2065
|
+
let o = e.canvas.width, s = e.canvas.height, c = F(o, s), l = I(c), u = i / r;
|
|
2066
|
+
return l.setTransform(1, 0, 0, u, t, n), l.fillStyle = et(l.createRadialGradient(0, 0, 0, 0, 0, r), a), l.fillRect(-t, -n / u, o, s / u), e.createPattern(c, "no-repeat") ?? et(e.createRadialGradient(t, n, 0, t, n, Math.max(r, i)), a);
|
|
2067
|
+
}
|
|
2068
|
+
// src/engine/text.ts
|
|
2069
|
+
var nt = null, rt = () => nt ??= I(F(8, 8));
|
|
2070
|
+
function it(e, t, n) {
|
|
2071
|
+
let r = /[\s,'"]/.test(t) && !/^["']/.test(t) && !t.includes(",") ? `"${t}"` : t;
|
|
2072
|
+
return `${e.italic ? "italic " : ""}${e.weight ?? 400} ${n}px ${r}, system-ui, sans-serif`;
|
|
2073
|
+
}
|
|
2074
|
+
var at = (e, t) => e.transform === "uppercase" ? t.toUpperCase() : e.transform === "lowercase" ? t.toLowerCase() : t;
|
|
2075
|
+
function ot(e, t) {
|
|
2076
|
+
return "letterSpacing" in e && (e.letterSpacing = `${t}px`, !0);
|
|
2077
|
+
}
|
|
2078
|
+
function X(e, t, n, r) {
|
|
2079
|
+
return t ? r || !n ? e.measureText(t).width : e.measureText(t).width + n * (Array.from(t).length - 1) : 0;
|
|
2080
|
+
}
|
|
2081
|
+
function st(e, t, n = 1) {
|
|
2082
|
+
let r = rt(), i = (e.size ?? 64) * n, a = (e.letterSpacing ?? 0) * n, o = it(e, t, i);
|
|
2083
|
+
r.font = o;
|
|
2084
|
+
let s = ot(r, a), c = e.width === void 0 ? Infinity : e.width * n, l = [];
|
|
2085
|
+
for (let t of at(e, String(e.text ?? "")).split("\n")) {
|
|
2086
|
+
let e = t.split(/(\s+)/), n = "";
|
|
2087
|
+
for (let t of e) {
|
|
2088
|
+
let e = n + t;
|
|
2089
|
+
if (n && X(r, e.trimEnd(), a, s) > c && t.trim()) for (l.push({
|
|
2090
|
+
text: n.trimEnd(),
|
|
2091
|
+
width: X(r, n.trimEnd(), a, s)
|
|
2092
|
+
}), n = t.trimStart(); X(r, n, a, s) > c && n.length > 1;) {
|
|
2093
|
+
let e = n.length - 1;
|
|
2094
|
+
for (; e > 1 && X(r, n.slice(0, e), a, s) > c;) e--;
|
|
2095
|
+
l.push({
|
|
2096
|
+
text: n.slice(0, e),
|
|
2097
|
+
width: X(r, n.slice(0, e), a, s)
|
|
2098
|
+
}), n = n.slice(e);
|
|
2099
|
+
}
|
|
2100
|
+
else n = e;
|
|
2101
|
+
}
|
|
2102
|
+
l.push({
|
|
2103
|
+
text: n.trimEnd(),
|
|
2104
|
+
width: X(r, n.trimEnd(), a, s)
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
let u = r.measureText("Hg"), d = u.fontBoundingBoxAscent ?? u.actualBoundingBoxAscent ?? i * .8, f = u.fontBoundingBoxDescent ?? u.actualBoundingBoxDescent ?? i * .2, p = (e.lineHeight ?? 1.2) * i, m = Math.max(0, ...l.map((e) => e.width)), h = p * l.length;
|
|
2108
|
+
return s && ot(r, 0), {
|
|
2109
|
+
font: o,
|
|
2110
|
+
lines: l,
|
|
2111
|
+
width: (e.width === void 0 ? m : e.width * n) / n,
|
|
2112
|
+
height: (e.height === void 0 ? h : e.height * n) / n,
|
|
2113
|
+
lineHeight: p,
|
|
2114
|
+
ascent: d,
|
|
2115
|
+
descent: f,
|
|
2116
|
+
textHeight: h
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
function ct(e, t) {
|
|
2120
|
+
let n = Infinity, r = Infinity, i = -Infinity, a = -Infinity, o = (e, t, o, s) => {
|
|
2121
|
+
n = Math.min(n, e), r = Math.min(r, t), i = Math.max(i, o), a = Math.max(a, s);
|
|
2122
|
+
}, s = t.width, c = t.height;
|
|
2123
|
+
if (e.background) {
|
|
2124
|
+
let [t, n] = lt(e);
|
|
2125
|
+
o(-t, -n, s + t, c + n);
|
|
2126
|
+
}
|
|
2127
|
+
let l = e.valign ?? "top", u = l === "middle" ? (c - t.textHeight) / 2 : l === "bottom" ? c - t.textHeight : 0, d = e.align ?? "left";
|
|
2128
|
+
return t.lines.forEach((e, n) => {
|
|
2129
|
+
if (!e.text || e.width <= 0) return;
|
|
2130
|
+
let r = u + n * t.lineHeight + (t.lineHeight - (t.ascent + t.descent)) / 2, i = d === "center" ? (s - e.width) / 2 : d === "right" ? s - e.width : 0;
|
|
2131
|
+
o(i, r, i + e.width, r + t.ascent + t.descent);
|
|
2132
|
+
}), Number.isFinite(n) ? {
|
|
2133
|
+
x: n,
|
|
2134
|
+
y: r,
|
|
2135
|
+
width: i - n,
|
|
2136
|
+
height: a - r
|
|
2137
|
+
} : null;
|
|
2138
|
+
}
|
|
2139
|
+
function lt(e) {
|
|
2140
|
+
let t = e.background?.padding ?? 0;
|
|
2141
|
+
return Array.isArray(t) ? [t[0], t[1]] : [t, t];
|
|
2142
|
+
}
|
|
2143
|
+
function ut(e, t, n) {
|
|
2144
|
+
let r = st(e, t, n), i = r.width * n, a = r.height * n, [o, s] = e.background ? lt(e).map((e) => e * n) : [0, 0], c = Math.ceil((e.size ?? 64) * n * .25), l = Math.ceil(o) + c, u = Math.ceil(s) + c, d = F(i + l * 2, a + u * 2), f = I(d);
|
|
2145
|
+
if (e.background) {
|
|
2146
|
+
f.fillStyle = e.background.color;
|
|
2147
|
+
let t = (e.background.radius ?? 0) * n;
|
|
2148
|
+
f.beginPath(), dt(f, l - o, u - s, i + o * 2, a + s * 2, t), f.fill();
|
|
2149
|
+
}
|
|
2150
|
+
f.font = r.font;
|
|
2151
|
+
let p = ot(f, (e.letterSpacing ?? 0) * n);
|
|
2152
|
+
f.textBaseline = "alphabetic", f.fillStyle = Y(f, e.color ?? "#ffffff", {
|
|
2153
|
+
x: l,
|
|
2154
|
+
y: u,
|
|
2155
|
+
w: i,
|
|
2156
|
+
h: a
|
|
2157
|
+
});
|
|
2158
|
+
let m = e.valign ?? "top", h = u + (m === "middle" ? (a - r.textHeight) / 2 : m === "bottom" ? a - r.textHeight : 0), g = (e.letterSpacing ?? 0) * n;
|
|
2159
|
+
return r.lines.forEach((t, n) => {
|
|
2160
|
+
let a = h + n * r.lineHeight + (r.lineHeight - (r.ascent + r.descent)) / 2 + r.ascent, o = e.align ?? "left", s = l + (o === "center" ? (i - t.width) / 2 : o === "right" ? i - t.width : 0);
|
|
2161
|
+
if (p || !g) f.fillText(t.text, s, a);
|
|
2162
|
+
else {
|
|
2163
|
+
let e = s;
|
|
2164
|
+
for (let n of Array.from(t.text)) f.fillText(n, e, a), e += f.measureText(n).width + g;
|
|
2165
|
+
}
|
|
2166
|
+
}), {
|
|
2167
|
+
canvas: d,
|
|
2168
|
+
ox: l,
|
|
2169
|
+
oy: u,
|
|
2170
|
+
w: i,
|
|
2171
|
+
h: a
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
function dt(e, t, n, r, i, a) {
|
|
2175
|
+
let o = Math.max(0, Math.min(a, r / 2, i / 2));
|
|
2176
|
+
o ? (e.moveTo(t + o, n), e.arcTo(t + r, n, t + r, n + i, o), e.arcTo(t + r, n + i, t, n + i, o), e.arcTo(t, n + i, t, n, o), e.arcTo(t, n, t + r, n, o), e.closePath()) : e.rect(t, n, r, i);
|
|
2177
|
+
}
|
|
2178
|
+
// src/engine/compositor.ts
|
|
2179
|
+
var ft = 96, pt = class {
|
|
2180
|
+
loader;
|
|
2181
|
+
cache = /* @__PURE__ */ new Map();
|
|
2182
|
+
tick = 0;
|
|
2183
|
+
natural = /* @__PURE__ */ new Map();
|
|
2184
|
+
constructor(e) {
|
|
2185
|
+
this.loader = e;
|
|
2186
|
+
}
|
|
2187
|
+
clearCache() {
|
|
2188
|
+
this.cache.clear();
|
|
2189
|
+
}
|
|
2190
|
+
async render(e, t = {}) {
|
|
2191
|
+
let n = t.scale ?? 1, r = Math.max(1, Math.round(e.canvas.width * n)), i = Math.max(1, Math.round(e.canvas.height * n)), a = F(r, i), o = I(a);
|
|
2192
|
+
if (t.backdrop === "checker") {
|
|
2193
|
+
let e = Math.max(6, Math.round(12 * Math.min(1, n * 2)));
|
|
2194
|
+
o.fillStyle = "#ffffff", o.fillRect(0, 0, r, i), o.fillStyle = "#d9d9d9";
|
|
2195
|
+
for (let t = 0; t < i; t += e) for (let n = t / e % 2 ? e : 0; n < r; n += e * 2) o.fillRect(n, t, e, e);
|
|
2196
|
+
} else t.backdrop && (o.fillStyle = t.backdrop, o.fillRect(0, 0, r, i));
|
|
2197
|
+
return t.background !== !1 && e.canvas.background && (o.fillStyle = Y(o, e.canvas.background, {
|
|
2198
|
+
x: 0,
|
|
2199
|
+
y: 0,
|
|
2200
|
+
w: r,
|
|
2201
|
+
h: i
|
|
2202
|
+
}), o.fillRect(0, 0, r, i)), await this.preload(e), await this.compose(e.layers, a, e, n, t), this.evict(), a;
|
|
2203
|
+
}
|
|
2204
|
+
async layerSurface(e, t, n) {
|
|
2205
|
+
return await this.preload({
|
|
2206
|
+
...t,
|
|
2207
|
+
layers: [e]
|
|
2208
|
+
}), this.surface(e, t, n, {});
|
|
2209
|
+
}
|
|
2210
|
+
async layerBox(t) {
|
|
2211
|
+
if (!e(t)) return null;
|
|
2212
|
+
let n = t.x ?? 0, r = t.y ?? 0, i = t.rotation ?? 0;
|
|
2213
|
+
if (t.type === "text") {
|
|
2214
|
+
let e = st(t, await this.family(t), 1), a = ct(t, e);
|
|
2215
|
+
return {
|
|
2216
|
+
x: n,
|
|
2217
|
+
y: r,
|
|
2218
|
+
width: e.width,
|
|
2219
|
+
height: e.height,
|
|
2220
|
+
rotation: i,
|
|
2221
|
+
...a ? { ink: {
|
|
2222
|
+
x: n + a.x,
|
|
2223
|
+
y: r + a.y,
|
|
2224
|
+
width: a.width,
|
|
2225
|
+
height: a.height
|
|
2226
|
+
} } : {}
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
if (t.type === "image") {
|
|
2230
|
+
let { w: e, h: a } = gt(t, await this.naturalSize(t.src).catch(() => null));
|
|
2231
|
+
return {
|
|
2232
|
+
x: n,
|
|
2233
|
+
y: r,
|
|
2234
|
+
width: e,
|
|
2235
|
+
height: a,
|
|
2236
|
+
rotation: i
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
return {
|
|
2240
|
+
x: n,
|
|
2241
|
+
y: r,
|
|
2242
|
+
width: t.width ?? 0,
|
|
2243
|
+
height: t.height ?? 0,
|
|
2244
|
+
rotation: i
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
async naturalSize(e) {
|
|
2248
|
+
let t = this.natural.get(e);
|
|
2249
|
+
if (t) return t;
|
|
2250
|
+
let n = await this.loader.image(e), r = {
|
|
2251
|
+
width: n.width,
|
|
2252
|
+
height: n.height
|
|
2253
|
+
};
|
|
2254
|
+
return this.natural.set(e, r), r;
|
|
2255
|
+
}
|
|
2256
|
+
async preload(e) {
|
|
2257
|
+
let t = [], n = (e) => {
|
|
2258
|
+
for (let r of e) r.type === "text" && r.font && _(r.font) && this.loader.font && t.push(this.loader.font(r.font, r.weight ?? 400, !!r.italic).catch(() => null)), r.type === "group" && n(r.children ?? []);
|
|
2259
|
+
};
|
|
2260
|
+
n(e.layers ?? []), await Promise.all(t);
|
|
2261
|
+
}
|
|
2262
|
+
async compose(e, t, n, r, i) {
|
|
2263
|
+
let a = I(t), o = null, s = !0;
|
|
2264
|
+
for (let c of e ?? []) {
|
|
2265
|
+
if (!c || typeof c != "object") continue;
|
|
2266
|
+
let e = c.visible === !1 || i.skip?.has(c.id) || i.only && !ht(c, i.only);
|
|
2267
|
+
if (c.clip && (e || !o || !s)) continue;
|
|
2268
|
+
if (e) {
|
|
2269
|
+
c.clip || (o = null, s = !1);
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
let l;
|
|
2273
|
+
try {
|
|
2274
|
+
l = c.type === "adjustment" ? await this.adjust(c, t, r) : await this.surface(c, n, r, i);
|
|
2275
|
+
} catch (e) {
|
|
2276
|
+
i.onError?.(c.id, e.message), l = null;
|
|
2277
|
+
}
|
|
2278
|
+
l ? (c.clip && o && (l = bt(l, o)), a.save(), a.globalAlpha = mt(c.opacity ?? 1), a.globalCompositeOperation = Ae(c.blend), a.drawImage(l.canvas, l.x, l.y), a.restore(), c.clip || (o = l, s = !0)) : c.clip || (o = null, s = !1);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
async surface(t, n, r, i) {
|
|
2282
|
+
let a = await this.cacheKey(t, n, r, i), o = this.cache.get(t.id);
|
|
2283
|
+
if (o && o.key === a) return o.used = ++this.tick, o.surface;
|
|
2284
|
+
let s = null;
|
|
2285
|
+
return t.type === "group" ? s = await this.groupSurface(t, n, r, i) : t.type === "fill" ? s = this.fillSurface(t, n, r) : e(t) && (s = await this.boxSurface(t, r)), s && t.type !== "group" && t.type !== "adjustment" && !e(t) && t.mask && (s = {
|
|
2286
|
+
...s,
|
|
2287
|
+
canvas: await this.maskCanvasSpace(s.canvas, t.mask, n, r)
|
|
2288
|
+
}), s && Re(t.effects) && (s = He(s, t.effects, r)), this.cache.set(t.id, {
|
|
2289
|
+
key: a,
|
|
2290
|
+
surface: s,
|
|
2291
|
+
used: ++this.tick
|
|
2292
|
+
}), s;
|
|
2293
|
+
}
|
|
2294
|
+
async cacheKey(e, n, r, i) {
|
|
2295
|
+
let a = [], o = this.loader.version, s = (e) => {
|
|
2296
|
+
o && (e.type === "image" && a.push(`${e.src}@${o(e.src)}`), e.mask && t(e.mask) && a.push(`${e.mask.src}@${o(e.mask.src)}`)), e.type === "group" && (e.children ?? []).forEach(s);
|
|
2297
|
+
};
|
|
2298
|
+
return s(e), `${r}|${e.type === "fill" || e.type === "group" ? `${n.canvas.width}x${n.canvas.height}` : ""}|${e.type === "group" ? `${[...i.skip ?? []].join(",")}|${[...i.only ?? []].join(",")}` : ""}|${a.join(",")}|${Fe(e)}`;
|
|
2299
|
+
}
|
|
2300
|
+
evict() {
|
|
2301
|
+
if (this.cache.size <= ft) return;
|
|
2302
|
+
let e = [...this.cache.entries()].sort((e, t) => e[1].used - t[1].used);
|
|
2303
|
+
for (let [t] of e.slice(0, this.cache.size - ft)) this.cache.delete(t);
|
|
2304
|
+
}
|
|
2305
|
+
async groupSurface(e, t, n, r) {
|
|
2306
|
+
let i = F(Math.max(1, Math.round(t.canvas.width * n)), Math.max(1, Math.round(t.canvas.height * n)));
|
|
2307
|
+
return await this.compose(e.children ?? [], i, t, n, r), e.filters?.length && _t(i, e.filters, n), {
|
|
2308
|
+
canvas: e.mask ? await this.maskCanvasSpace(i, e.mask, t, n) : i,
|
|
2309
|
+
x: 0,
|
|
2310
|
+
y: 0
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
fillSurface(e, t, n) {
|
|
2314
|
+
let r = Math.max(1, Math.round(t.canvas.width * n)), i = Math.max(1, Math.round(t.canvas.height * n)), a = F(r, i), o = I(a);
|
|
2315
|
+
return o.fillStyle = Y(o, e.fill, {
|
|
2316
|
+
x: 0,
|
|
2317
|
+
y: 0,
|
|
2318
|
+
w: r,
|
|
2319
|
+
h: i
|
|
2320
|
+
}), o.fillRect(0, 0, r, i), e.filters?.length && _t(a, e.filters, n), {
|
|
2321
|
+
canvas: a,
|
|
2322
|
+
x: 0,
|
|
2323
|
+
y: 0
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
async adjust(e, t, n) {
|
|
2327
|
+
if (!e.filters?.length) return null;
|
|
2328
|
+
let r = F(t.width, t.height);
|
|
2329
|
+
return I(r).drawImage(t, 0, 0), _t(r, e.filters, n), e.mask && e.mask.enabled !== !1 && yt(r, await this.maskPlane(e.mask, r.width, r.height, n, null)), {
|
|
2330
|
+
canvas: r,
|
|
2331
|
+
x: 0,
|
|
2332
|
+
y: 0
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
async boxSurface(e, t) {
|
|
2336
|
+
let n;
|
|
2337
|
+
if (n = e.type === "image" ? await this.imageContent(e, t) : e.type === "text" ? ut(e, await this.family(e), t) : St(e, t), !n || n.w <= 0 || n.h <= 0) return null;
|
|
2338
|
+
if (e.type !== "image" && e.filters?.length) {
|
|
2339
|
+
let r = Qe(e.filters, t);
|
|
2340
|
+
r && (n = xt(n, r));
|
|
2341
|
+
}
|
|
2342
|
+
if (e.filters?.length && _t(n.canvas, e.filters, t), e.mask && e.mask.enabled !== !1) {
|
|
2343
|
+
let r = await this.maskPlane(e.mask, Math.max(1, Math.round(n.w)), Math.max(1, Math.round(n.h)), t, e), i = new Uint8ClampedArray(n.canvas.width * n.canvas.height), a = Math.max(1, Math.round(n.w)), o = Math.max(1, Math.round(n.h)), s = Math.round(n.ox), c = Math.round(n.oy);
|
|
2344
|
+
for (let e = 0; e < o; e++) {
|
|
2345
|
+
let t = e + c;
|
|
2346
|
+
if (!(t < 0 || t >= n.canvas.height)) for (let o = 0; o < a; o++) {
|
|
2347
|
+
let c = o + s;
|
|
2348
|
+
c < 0 || c >= n.canvas.width || (i[t * n.canvas.width + c] = r[e * a + o]);
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
yt(n.canvas, i);
|
|
2352
|
+
}
|
|
2353
|
+
let r = Le(e.effects, t), i = (e.x ?? 0) * t, a = (e.y ?? 0) * t, o = i + n.w / 2, s = a + n.h / 2, c = (e.rotation ?? 0) * Math.PI / 180, l = e.flipX ? -1 : 1, u = e.flipY ? -1 : 1, d = -n.w / 2 - n.ox, f = -n.h / 2 - n.oy, p = [
|
|
2354
|
+
[d, f],
|
|
2355
|
+
[d + n.canvas.width, f],
|
|
2356
|
+
[d, f + n.canvas.height],
|
|
2357
|
+
[d + n.canvas.width, f + n.canvas.height]
|
|
2358
|
+
].map(([e, t]) => {
|
|
2359
|
+
let n = e * l, r = t * u;
|
|
2360
|
+
return [o + n * Math.cos(c) - r * Math.sin(c), s + n * Math.sin(c) + r * Math.cos(c)];
|
|
2361
|
+
}), m = Math.floor(Math.min(...p.map((e) => e[0]))) - r, h = Math.floor(Math.min(...p.map((e) => e[1]))) - r, g = Math.ceil(Math.max(...p.map((e) => e[0]))) + r, _ = Math.ceil(Math.max(...p.map((e) => e[1]))) + r;
|
|
2362
|
+
if (!c && l === 1 && u === 1 && !r) return {
|
|
2363
|
+
canvas: n.canvas,
|
|
2364
|
+
x: Math.round(i - n.ox),
|
|
2365
|
+
y: Math.round(a - n.oy)
|
|
2366
|
+
};
|
|
2367
|
+
let v = F(g - m, _ - h), y = I(v);
|
|
2368
|
+
return y.translate(o - m, s - h), y.rotate(c), y.scale(l, u), y.drawImage(n.canvas, d, f), {
|
|
2369
|
+
canvas: v,
|
|
2370
|
+
x: m,
|
|
2371
|
+
y: h
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
async imageContent(e, t) {
|
|
2375
|
+
let n = await this.loader.image(e.src);
|
|
2376
|
+
this.natural.set(e.src, {
|
|
2377
|
+
width: n.width,
|
|
2378
|
+
height: n.height
|
|
2379
|
+
});
|
|
2380
|
+
let { w: r, h: i } = gt(e, {
|
|
2381
|
+
width: n.width,
|
|
2382
|
+
height: n.height
|
|
2383
|
+
}), a = Math.max(1, Math.round(r * t)), o = Math.max(1, Math.round(i * t)), s = e.crop ?? {
|
|
2384
|
+
x: 0,
|
|
2385
|
+
y: 0,
|
|
2386
|
+
width: n.width,
|
|
2387
|
+
height: n.height
|
|
2388
|
+
}, c = F(a, o), l = I(c), u = e.fit ?? "fill", [d, f] = e.focus ?? [.5, .5];
|
|
2389
|
+
if (u === "fill") l.drawImage(n, s.x, s.y, s.width, s.height, 0, 0, a, o);
|
|
2390
|
+
else if (u === "cover") {
|
|
2391
|
+
let e = Math.max(a / s.width, o / s.height), t = a / e, r = o / e;
|
|
2392
|
+
l.drawImage(n, s.x + (s.width - t) * d, s.y + (s.height - r) * f, t, r, 0, 0, a, o);
|
|
2393
|
+
} else {
|
|
2394
|
+
let e = Math.min(a / s.width, o / s.height), t = s.width * e, r = s.height * e;
|
|
2395
|
+
l.drawImage(n, s.x, s.y, s.width, s.height, (a - t) * d, (o - r) * f, t, r);
|
|
2396
|
+
}
|
|
2397
|
+
return {
|
|
2398
|
+
canvas: c,
|
|
2399
|
+
ox: 0,
|
|
2400
|
+
oy: 0,
|
|
2401
|
+
w: a,
|
|
2402
|
+
h: o
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
async family(e) {
|
|
2406
|
+
let t = e.font ?? "inter", n = _(t);
|
|
2407
|
+
if (n && this.loader.font) {
|
|
2408
|
+
let n = await this.loader.font(t, e.weight ?? 400, !!e.italic).catch(() => null);
|
|
2409
|
+
if (n) return n;
|
|
2410
|
+
}
|
|
2411
|
+
return n ? n.family : t;
|
|
2412
|
+
}
|
|
2413
|
+
maskPlane(e, i, a, o, s) {
|
|
2414
|
+
let c = (t) => {
|
|
2415
|
+
e.feather && ve(t, i, a, e.feather * o);
|
|
2416
|
+
let n = mt(e.density ?? 1);
|
|
2417
|
+
for (let r = 0; r < t.length; r++) {
|
|
2418
|
+
let i = e.invert ? 255 - t[r] : t[r];
|
|
2419
|
+
n < 1 && (i = 255 - (255 - i) * n), t[r] = i;
|
|
2420
|
+
}
|
|
2421
|
+
return t;
|
|
2422
|
+
};
|
|
2423
|
+
if (t(e)) return this.loader.image(e.src).then((e) => {
|
|
2424
|
+
let t = F(i, a);
|
|
2425
|
+
return I(t).drawImage(e, 0, 0, i, a), c(vt(t));
|
|
2426
|
+
});
|
|
2427
|
+
let l = F(i, a), u = I(l);
|
|
2428
|
+
if (n(e)) {
|
|
2429
|
+
u.fillStyle = "#fff", u.beginPath();
|
|
2430
|
+
let t = e.x * o, n = e.y * o, r = e.width * o, i = e.height * o;
|
|
2431
|
+
e.shape === "ellipse" ? u.ellipse(t + r / 2, n + i / 2, Math.max(0, r / 2), Math.max(0, i / 2), 0, 0, Math.PI * 2) : dt(u, t, n, r, i, (e.radius ?? 0) * o), u.fill();
|
|
2432
|
+
} else r(e) && (u.fillStyle = Y(u, e.gradient, {
|
|
2433
|
+
x: 0,
|
|
2434
|
+
y: 0,
|
|
2435
|
+
w: i,
|
|
2436
|
+
h: a
|
|
2437
|
+
}), u.fillRect(0, 0, i, a));
|
|
2438
|
+
return c(vt(l));
|
|
2439
|
+
}
|
|
2440
|
+
async maskCanvasSpace(e, t, n, r) {
|
|
2441
|
+
return t.enabled === !1 || yt(e, await this.maskPlane(t, e.width, e.height, r, null)), e;
|
|
2442
|
+
}
|
|
2443
|
+
}, mt = (e) => e < 0 ? 0 : e > 1 ? 1 : e;
|
|
2444
|
+
function ht(e, t) {
|
|
2445
|
+
return t.has(e.id) ? !0 : e.type === "group" && (e.children ?? []).some((e) => ht(e, t));
|
|
2446
|
+
}
|
|
2447
|
+
function gt(e, t) {
|
|
2448
|
+
let n = e.crop ? {
|
|
2449
|
+
width: e.crop.width,
|
|
2450
|
+
height: e.crop.height
|
|
2451
|
+
} : t ?? {
|
|
2452
|
+
width: e.width ?? 1,
|
|
2453
|
+
height: e.height ?? 1
|
|
2454
|
+
};
|
|
2455
|
+
return e.width !== void 0 && e.height !== void 0 ? {
|
|
2456
|
+
w: e.width,
|
|
2457
|
+
h: e.height
|
|
2458
|
+
} : e.width === void 0 ? e.height === void 0 ? {
|
|
2459
|
+
w: n.width,
|
|
2460
|
+
h: n.height
|
|
2461
|
+
} : {
|
|
2462
|
+
w: e.height * n.width / n.height,
|
|
2463
|
+
h: e.height
|
|
2464
|
+
} : {
|
|
2465
|
+
w: e.width,
|
|
2466
|
+
h: e.width * n.height / n.width
|
|
2467
|
+
};
|
|
2468
|
+
}
|
|
2469
|
+
function _t(e, t, n) {
|
|
2470
|
+
if (!t?.some((e) => e && e.enabled !== !1)) return;
|
|
2471
|
+
let r = L(e);
|
|
2472
|
+
Xe(r, t, { scale: n }), ke(e, r);
|
|
2473
|
+
}
|
|
2474
|
+
function vt(e) {
|
|
2475
|
+
let t = L(e).data, n = new Uint8ClampedArray(t.length / 4);
|
|
2476
|
+
for (let e = 0, r = 0; e < n.length; e++, r += 4) n[e] = (.299 * t[r] + .587 * t[r + 1] + .114 * t[r + 2]) * t[r + 3] / 255;
|
|
2477
|
+
return n;
|
|
2478
|
+
}
|
|
2479
|
+
function yt(e, t) {
|
|
2480
|
+
let n = L(e), r = n.data;
|
|
2481
|
+
for (let e = 0, n = 3; e < t.length; e++, n += 4) r[n] = r[n] * t[e] / 255;
|
|
2482
|
+
ke(e, n);
|
|
2483
|
+
}
|
|
2484
|
+
function bt(e, t) {
|
|
2485
|
+
let n = F(e.canvas.width, e.canvas.height), r = I(n);
|
|
2486
|
+
return r.drawImage(e.canvas, 0, 0), r.globalCompositeOperation = "destination-in", r.drawImage(t.canvas, t.x - e.x, t.y - e.y), {
|
|
2487
|
+
canvas: n,
|
|
2488
|
+
x: e.x,
|
|
2489
|
+
y: e.y
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
function xt(e, t) {
|
|
2493
|
+
let n = F(e.canvas.width + t * 2, e.canvas.height + t * 2);
|
|
2494
|
+
return I(n).drawImage(e.canvas, t, t), {
|
|
2495
|
+
...e,
|
|
2496
|
+
canvas: n,
|
|
2497
|
+
ox: e.ox + t,
|
|
2498
|
+
oy: e.oy + t
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
function St(e, t) {
|
|
2502
|
+
let n = Math.max(0, (e.width ?? 0) * t), r = Math.max(0, (e.height ?? 0) * t), i = e.stroke ? (e.stroke.width ?? 4) * t : e.shape === "line" ? 4 * t : 0, a = Math.ceil(i / 2 + 2), o = F(Math.max(1, n + a * 2), Math.max(1, r + a * 2)), s = I(o), c = {
|
|
2503
|
+
x: a,
|
|
2504
|
+
y: a,
|
|
2505
|
+
w: n,
|
|
2506
|
+
h: r
|
|
2507
|
+
};
|
|
2508
|
+
return s.beginPath(), Ct(s, e, c, t), e.shape !== "line" && e.fill !== null && (s.fillStyle = Y(s, e.fill, c, "#ffffff"), s.fill()), (e.stroke || e.shape === "line") && (s.lineWidth = i, s.strokeStyle = e.stroke?.color ?? "#ffffff", s.lineJoin = "round", s.lineCap = e.shape === "line" ? "round" : "butt", e.stroke?.dash?.length && s.setLineDash(e.stroke.dash.map((e) => e * t)), s.stroke()), {
|
|
2509
|
+
canvas: o,
|
|
2510
|
+
ox: a,
|
|
2511
|
+
oy: a,
|
|
2512
|
+
w: Math.max(n, 1),
|
|
2513
|
+
h: Math.max(r, 1)
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2516
|
+
function Ct(e, t, n, r) {
|
|
2517
|
+
let { x: i, y: a, w: o, h: s } = n;
|
|
2518
|
+
switch (t.shape) {
|
|
2519
|
+
case "ellipse":
|
|
2520
|
+
e.ellipse(i + o / 2, a + s / 2, o / 2, s / 2, 0, 0, Math.PI * 2);
|
|
2521
|
+
break;
|
|
2522
|
+
case "line":
|
|
2523
|
+
e.moveTo(i, a), e.lineTo(i + o, a + s);
|
|
2524
|
+
break;
|
|
2525
|
+
case "polygon":
|
|
2526
|
+
case "star": {
|
|
2527
|
+
let n = Math.max(3, Math.round(t.sides ?? (t.shape === "star" ? 5 : 6))), r = t.shape === "star" ? t.innerRadius ?? .5 : 1, c = t.shape === "star" ? n * 2 : n;
|
|
2528
|
+
for (let n = 0; n < c; n++) {
|
|
2529
|
+
let l = t.shape === "star" && n % 2 ? r : 1, u = -Math.PI / 2 + n / c * Math.PI * 2, d = i + o / 2 + o / 2 * Math.cos(u) * l, f = a + s / 2 + s / 2 * Math.sin(u) * l;
|
|
2530
|
+
n ? e.lineTo(d, f) : e.moveTo(d, f);
|
|
2531
|
+
}
|
|
2532
|
+
e.closePath();
|
|
2533
|
+
break;
|
|
2534
|
+
}
|
|
2535
|
+
default: dt(e, i, a, o, s, (t.radius ?? 0) * r);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function wt(e) {
|
|
2539
|
+
return typeof e == "string" && e.startsWith("library:");
|
|
2540
|
+
}
|
|
2541
|
+
function Tt(e) {
|
|
2542
|
+
return e.slice(8);
|
|
2543
|
+
}
|
|
2544
|
+
function Et(e, t) {
|
|
2545
|
+
return e?.assets.find((e) => e.id === t);
|
|
2546
|
+
}
|
|
2547
|
+
// src/engine/loader.ts
|
|
2548
|
+
var Dt = (e, t) => `${e.replace(/\/?$/, "/")}${t.split("/").map(encodeURIComponent).join("/")}`;
|
|
2549
|
+
async function Ot(e) {
|
|
2550
|
+
let t = e.type.includes("svg");
|
|
2551
|
+
if (!t && typeof createImageBitmap == "function") try {
|
|
2552
|
+
return await createImageBitmap(e, { imageOrientation: "from-image" });
|
|
2553
|
+
} catch {}
|
|
2554
|
+
if (typeof Image > "u") throw Error(`Cannot decode ${e.type || "image"} here.`);
|
|
2555
|
+
let n = URL.createObjectURL(e);
|
|
2556
|
+
try {
|
|
2557
|
+
let e = new Image();
|
|
2558
|
+
return e.decoding = "async", e.src = n, await e.decode(), !t || e.naturalWidth && e.naturalHeight || (e.width = 512, e.height = 512), e;
|
|
2559
|
+
} finally {
|
|
2560
|
+
setTimeout(() => URL.revokeObjectURL(n), 3e4);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
function kt(e) {
|
|
2564
|
+
let t = e.fetchImpl ?? fetch.bind(globalThis), n = e.library, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = async (t) => {
|
|
2565
|
+
if (wt(t)) {
|
|
2566
|
+
let r = Et(n, Tt(t));
|
|
2567
|
+
if (!r?.path) throw Error(`Unknown library image "${t}".`);
|
|
2568
|
+
return Dt(e.libraryBase, r.path);
|
|
2569
|
+
}
|
|
2570
|
+
if (/^(blob:|data:)/.test(t)) return t;
|
|
2571
|
+
let r = e.resolve ? await e.resolve(t) : Dt(e.assetBase, t), a = i.get(t);
|
|
2572
|
+
return a ? `${r}${r.includes("?") ? "&" : "?"}v=${a}` : r;
|
|
2573
|
+
};
|
|
2574
|
+
return {
|
|
2575
|
+
image(e) {
|
|
2576
|
+
let n = r.get(e);
|
|
2577
|
+
return n || (n = (async () => {
|
|
2578
|
+
let n = await t(await o(e), { cache: "no-store" });
|
|
2579
|
+
if (!n.ok) throw Error(`${e}: HTTP ${n.status}`);
|
|
2580
|
+
return Ot(await n.blob());
|
|
2581
|
+
})(), n.catch(() => r.delete(e)), r.set(e, n)), n;
|
|
2582
|
+
},
|
|
2583
|
+
version: (e) => i.get(e) ?? 0,
|
|
2584
|
+
invalidate(e) {
|
|
2585
|
+
r.delete(e), i.set(e, (i.get(e) ?? 0) + 1);
|
|
2586
|
+
},
|
|
2587
|
+
setLibrary(e) {
|
|
2588
|
+
n = e;
|
|
2589
|
+
},
|
|
2590
|
+
font(t, r, i) {
|
|
2591
|
+
let o = _(t), s = Et(n, t);
|
|
2592
|
+
if (!o || !s?.files?.length || typeof FontFace > "u") return Promise.resolve(o?.family ?? null);
|
|
2593
|
+
let c = i ? "italic" : "normal", l = s.files.filter((e) => e.style === c).length ? s.files.filter((e) => e.style === c) : s.files, u = l.reduce((e, t) => Math.abs(t.weight - r) < Math.abs(e.weight - r) ? t : e).weight, d = `${t}|${u}|${c}`, f = a.get(d);
|
|
2594
|
+
return f || (f = (async () => {
|
|
2595
|
+
let t = globalThis.document?.fonts ?? globalThis.fonts, n = l.filter((e) => e.weight === u);
|
|
2596
|
+
return await Promise.all(n.map(async (n) => {
|
|
2597
|
+
let i = new FontFace(o.family, `url(${Dt(e.libraryBase, n.path)}) format("woff2")`, {
|
|
2598
|
+
weight: String(r),
|
|
2599
|
+
style: c,
|
|
2600
|
+
...n.unicodeRange ? { unicodeRange: n.unicodeRange } : {}
|
|
2601
|
+
});
|
|
2602
|
+
await i.load(), t?.add(i);
|
|
2603
|
+
})), o.family;
|
|
2604
|
+
})(), f.catch(() => a.delete(d)), a.set(d, f)), f;
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2608
|
+
// src/engine/index.ts
|
|
2609
|
+
var At = class {
|
|
2610
|
+
loader;
|
|
2611
|
+
compositor;
|
|
2612
|
+
constructor(e, t) {
|
|
2613
|
+
this.loader = t ?? kt(e), this.compositor = new pt(this.loader), e.ai && S(e.ai);
|
|
2614
|
+
}
|
|
2615
|
+
setLibrary(e) {
|
|
2616
|
+
this.loader.setLibrary?.(e);
|
|
2617
|
+
}
|
|
2618
|
+
render(e, t) {
|
|
2619
|
+
return this.compositor.render(e, t);
|
|
2620
|
+
}
|
|
2621
|
+
async exportImage(e, t, n = {}) {
|
|
2622
|
+
let r = await this.compositor.render(e, {
|
|
2623
|
+
...n,
|
|
2624
|
+
scale: t.scale
|
|
2625
|
+
}), i = F(t.width, t.height), a = I(i);
|
|
2626
|
+
t.background && (a.fillStyle = t.background, a.fillRect(0, 0, t.width, t.height));
|
|
2627
|
+
let o = t.scale;
|
|
2628
|
+
return a.drawImage(r, t.source.x * o, t.source.y * o, t.source.width * o, t.source.height * o, t.dest.x, t.dest.y, t.dest.width, t.dest.height), Ft(i, t.mime, t.quality);
|
|
2629
|
+
}
|
|
2630
|
+
async analyze(e, t = {}) {
|
|
2631
|
+
return Te(L(t.layer ? await this.layerPixels(e, t.layer, {
|
|
2632
|
+
maxSide: t.maxSide ?? 1200,
|
|
2633
|
+
withFilters: !0
|
|
2634
|
+
}) : await this.render(e, { scale: Math.min(1, (t.maxSide ?? 1200) / Math.max(e.canvas.width, e.canvas.height)) })));
|
|
2635
|
+
}
|
|
2636
|
+
async layerPixels(t, n, r = {}) {
|
|
2637
|
+
let a = i(t.layers, n);
|
|
2638
|
+
if (!a) throw Error(`No layer "${n}".`);
|
|
2639
|
+
let o = a.layer, s = r.maxSide ?? 2048;
|
|
2640
|
+
if (!e(o)) {
|
|
2641
|
+
let e = Math.min(1, s / Math.max(t.canvas.width, t.canvas.height));
|
|
2642
|
+
return this.compositor.render({
|
|
2643
|
+
...t,
|
|
2644
|
+
canvas: {
|
|
2645
|
+
...t.canvas,
|
|
2646
|
+
background: null
|
|
2647
|
+
},
|
|
2648
|
+
layers: [jt(o, r.withFilters)]
|
|
2649
|
+
}, { scale: e });
|
|
2650
|
+
}
|
|
2651
|
+
let c = await this.compositor.layerBox(o);
|
|
2652
|
+
if (!c) throw Error(`Layer "${n}" has no size.`);
|
|
2653
|
+
let l = 1;
|
|
2654
|
+
if (o.type === "image") {
|
|
2655
|
+
let e = await this.compositor.naturalSize(o.src), t = o.crop ?? e;
|
|
2656
|
+
l = Math.max(t.width / c.width, t.height / c.height);
|
|
2657
|
+
}
|
|
2658
|
+
l = Math.min(l, s / Math.max(c.width, c.height));
|
|
2659
|
+
let u = {
|
|
2660
|
+
...jt(o, r.withFilters),
|
|
2661
|
+
x: 0,
|
|
2662
|
+
y: 0,
|
|
2663
|
+
rotation: 0,
|
|
2664
|
+
flipX: !1,
|
|
2665
|
+
flipY: !1
|
|
2666
|
+
}, d = Math.max(1, Math.round(c.width * l)), f = Math.max(1, Math.round(c.height * l));
|
|
2667
|
+
return this.compositor.render({
|
|
2668
|
+
version: 1,
|
|
2669
|
+
id: "layer",
|
|
2670
|
+
canvas: {
|
|
2671
|
+
width: d / l,
|
|
2672
|
+
height: f / l
|
|
2673
|
+
},
|
|
2674
|
+
layers: [u]
|
|
2675
|
+
}, { scale: l });
|
|
2676
|
+
}
|
|
2677
|
+
async backgroundMask(e, t, n = {}) {
|
|
2678
|
+
let r = await this.layerPixels(e, t, {
|
|
2679
|
+
maxSide: 2048,
|
|
2680
|
+
withFilters: !1
|
|
2681
|
+
});
|
|
2682
|
+
return Pt(Mt(await ne(r, n.model), r.width, r.height, n), r.width, r.height);
|
|
2683
|
+
}
|
|
2684
|
+
async segmentMask(e, t, n, r = {}) {
|
|
2685
|
+
let a = await this.layerPixels(e, t, {
|
|
2686
|
+
maxSide: 1600,
|
|
2687
|
+
withFilters: !1
|
|
2688
|
+
}), o = await this.compositor.layerBox(i(e.layers, t).layer), s = o ? a.width / o.width : 1;
|
|
2689
|
+
return Pt(Mt(await re(a, {
|
|
2690
|
+
...n.points ? { points: n.points.map(([e, t, n]) => [
|
|
2691
|
+
e * s,
|
|
2692
|
+
t * s,
|
|
2693
|
+
n
|
|
2694
|
+
]) } : {},
|
|
2695
|
+
...n.box ? { box: n.box.map((e) => e * s) } : {}
|
|
2696
|
+
}, r.model), a.width, a.height, { feather: r.feather ?? 1 }), a.width, a.height);
|
|
2697
|
+
}
|
|
2698
|
+
async colorRangeMask(e, t, n) {
|
|
2699
|
+
let r = L(await this.layerPixels(e, t, {
|
|
2700
|
+
maxSide: 2048,
|
|
2701
|
+
withFilters: !0
|
|
2702
|
+
})), i = I(F(1, 1));
|
|
2703
|
+
i.fillStyle = n.color, i.fillRect(0, 0, 1, 1);
|
|
2704
|
+
let [a, o, s] = i.getImageData(0, 0, 1, 1).data, c = (n.tolerance ?? 32) / 100 * 441, l = new Uint8ClampedArray(r.width * r.height);
|
|
2705
|
+
for (let e = 0, t = 0; e < l.length; e++, t += 4) {
|
|
2706
|
+
let n = Math.hypot(r.data[t] - a, r.data[t + 1] - o, r.data[t + 2] - s);
|
|
2707
|
+
l[e] = r.data[t + 3] < 8 ? 0 : n <= c ? 255 : n <= c * 1.25 ? 255 * (1 - (n - c) / (c * .25)) : 0;
|
|
2708
|
+
}
|
|
2709
|
+
return Pt(Mt(l, r.width, r.height, { feather: n.feather }), r.width, r.height);
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
function jt(e, t) {
|
|
2713
|
+
let { mask: n, effects: r, opacity: i, blend: a, clip: o, ...s } = e, c = {
|
|
2714
|
+
...s,
|
|
2715
|
+
visible: !0
|
|
2716
|
+
};
|
|
2717
|
+
return !t && c.type !== "adjustment" && delete c.filters, c;
|
|
2718
|
+
}
|
|
2719
|
+
function Mt(e, t, n, r) {
|
|
2720
|
+
if (r.threshold !== void 0) {
|
|
2721
|
+
let t = Math.max(0, Math.min(255, r.threshold));
|
|
2722
|
+
for (let n = 0; n < e.length; n++) e[n] = e[n] >= t ? 255 : 0;
|
|
2723
|
+
}
|
|
2724
|
+
return r.feather && ve(e, t, n, r.feather), e;
|
|
2725
|
+
}
|
|
2726
|
+
function Nt(e, t, n) {
|
|
2727
|
+
let r = t, i = n, a = -1, o = -1;
|
|
2728
|
+
for (let s = 0; s < n; s++) {
|
|
2729
|
+
let n = s * t;
|
|
2730
|
+
for (let c = 0; c < t; c++) e[n + c] < 128 || (c < r && (r = c), c > a && (a = c), s < i && (i = s), o = s);
|
|
2731
|
+
}
|
|
2732
|
+
return a < 0 ? null : {
|
|
2733
|
+
x: r,
|
|
2734
|
+
y: i,
|
|
2735
|
+
width: a - r + 1,
|
|
2736
|
+
height: o - i + 1
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
async function Pt(e, t, n) {
|
|
2740
|
+
let r = Nt(e, t, n), i = F(t, n), a = I(i);
|
|
2741
|
+
return a.fillStyle = "#000", a.fillRect(0, 0, t, n), a.drawImage(Me(e, t, n), 0, 0), {
|
|
2742
|
+
...await Ft(i, "image/png"),
|
|
2743
|
+
bbox: r
|
|
2744
|
+
};
|
|
2745
|
+
}
|
|
2746
|
+
async function Ft(e, t, n = 100) {
|
|
2747
|
+
let r = await Ne(e, t, t === "image/png" ? void 0 : n / 100);
|
|
2748
|
+
return {
|
|
2749
|
+
bytes: new Uint8Array(await r.arrayBuffer()),
|
|
2750
|
+
mime: r.type || t,
|
|
2751
|
+
width: e.width,
|
|
2752
|
+
height: e.height
|
|
2753
|
+
};
|
|
2754
|
+
}
|
|
2755
|
+
function It(e) {
|
|
2756
|
+
let t = "", n = 32768;
|
|
2757
|
+
for (let r = 0; r < e.length; r += n) t += String.fromCharCode(...e.subarray(r, r + n));
|
|
2758
|
+
return btoa(t);
|
|
2759
|
+
}
|
|
2760
|
+
// src/engine/headless.ts
|
|
2761
|
+
var Z = (e) => ({
|
|
2762
|
+
base64: It(e.bytes),
|
|
2763
|
+
mime: e.mime,
|
|
2764
|
+
width: e.width,
|
|
2765
|
+
height: e.height,
|
|
2766
|
+
...e.bbox === void 0 ? {} : { bbox: e.bbox }
|
|
2767
|
+
}), Lt = null, Q = [], $ = () => {
|
|
2768
|
+
if (!Lt) throw Error("agentphoto.init() was not called.");
|
|
2769
|
+
return Lt;
|
|
2770
|
+
};
|
|
2771
|
+
globalThis.agentphoto = {
|
|
2772
|
+
version: 1,
|
|
2773
|
+
async init(e) {
|
|
2774
|
+
return Lt = new At({
|
|
2775
|
+
assetBase: e.assetBase,
|
|
2776
|
+
libraryBase: e.libraryBase,
|
|
2777
|
+
library: e.library,
|
|
2778
|
+
ai: e.ai
|
|
2779
|
+
}), !0;
|
|
2780
|
+
},
|
|
2781
|
+
async render(e, t = {}) {
|
|
2782
|
+
Q.length = 0;
|
|
2783
|
+
let n = t.scale ?? 1;
|
|
2784
|
+
return t.maxWidth && (n = Math.min(n, t.maxWidth / e.canvas.width)), t.maxHeight && (n = Math.min(n, t.maxHeight / e.canvas.height)), {
|
|
2785
|
+
...Z(await Ft(await $().render(e, {
|
|
2786
|
+
scale: n,
|
|
2787
|
+
backdrop: t.backdrop,
|
|
2788
|
+
background: t.background,
|
|
2789
|
+
only: t.only ? new Set(t.only) : void 0,
|
|
2790
|
+
onError: (e, t) => Q.push({
|
|
2791
|
+
layer: e,
|
|
2792
|
+
message: t
|
|
2793
|
+
})
|
|
2794
|
+
}), t.format === "jpeg" ? "image/jpeg" : "image/png", t.quality ?? 88)),
|
|
2795
|
+
scale: n,
|
|
2796
|
+
errors: [...Q]
|
|
2797
|
+
};
|
|
2798
|
+
},
|
|
2799
|
+
async exportImage(e, t) {
|
|
2800
|
+
return Q.length = 0, {
|
|
2801
|
+
...Z(await $().exportImage(e, t, { onError: (e, t) => Q.push({
|
|
2802
|
+
layer: e,
|
|
2803
|
+
message: t
|
|
2804
|
+
}) })),
|
|
2805
|
+
errors: [...Q]
|
|
2806
|
+
};
|
|
2807
|
+
},
|
|
2808
|
+
analyze(e, t = {}) {
|
|
2809
|
+
return $().analyze(e, t);
|
|
2810
|
+
},
|
|
2811
|
+
async backgroundMask(e, t, n = {}) {
|
|
2812
|
+
return Z(await $().backgroundMask(e, t, n));
|
|
2813
|
+
},
|
|
2814
|
+
async segmentMask(e, t, n, r = {}) {
|
|
2815
|
+
return Z(await $().segmentMask(e, t, n, r));
|
|
2816
|
+
},
|
|
2817
|
+
async colorRangeMask(e, t, n) {
|
|
2818
|
+
return Z(await $().colorRangeMask(e, t, n));
|
|
2819
|
+
},
|
|
2820
|
+
invalidate(e) {
|
|
2821
|
+
for (let t of e) $().loader.invalidate(t);
|
|
2822
|
+
return e.length;
|
|
2823
|
+
},
|
|
2824
|
+
async layerBoxes(e) {
|
|
2825
|
+
let t = {}, n = [];
|
|
2826
|
+
a(e.layers, (e) => void n.push(e));
|
|
2827
|
+
for (let e of n) {
|
|
2828
|
+
let n = await $().compositor.layerBox(e).catch(() => null);
|
|
2829
|
+
n && (t[e.id] = n);
|
|
2830
|
+
}
|
|
2831
|
+
return t;
|
|
2832
|
+
}
|
|
2833
|
+
};
|