@fleox/agentphoto 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/LICENSE +143 -0
  2. package/README.md +229 -2
  3. package/changelog.json +17 -0
  4. package/dist/agent/agentphoto.mjs +3307 -0
  5. package/dist/agent/chunks/assets-CDQo3VqD.mjs +151 -0
  6. package/dist/agent/chunks/catalog-DIZ5dnH5.mjs +953 -0
  7. package/dist/agent/chunks/context-DoLoLF9f.mjs +75 -0
  8. package/dist/agent/chunks/doc-BjY_j4Su.mjs +773 -0
  9. package/dist/agent/chunks/export-CLmpFART.mjs +140 -0
  10. package/dist/agent/chunks/ids-DAmiNwd9.mjs +28 -0
  11. package/dist/agent/chunks/imageInfo-QxAfu8R6.mjs +173 -0
  12. package/dist/agent/chunks/jsonPath-B7vAPXsi.mjs +155 -0
  13. package/dist/agent/chunks/library-C_EXiphj.mjs +16 -0
  14. package/dist/agent/chunks/models-C4i_hicr.mjs +387 -0
  15. package/dist/agent/chunks/output-3F12IR9O.mjs +130 -0
  16. package/dist/agent/chunks/package-DSmAxrla.mjs +71 -0
  17. package/dist/agent/chunks/project-CUykGysG.mjs +198 -0
  18. package/dist/agent/chunks/rolldown-runtime-CMQPkI6i.mjs +18 -0
  19. package/dist/agent/chunks/server-I0trf5tM.mjs +241 -0
  20. package/dist/agent/chunks/templates--YGpGuHh.mjs +40 -0
  21. package/dist/agent/chunks/tools-Dnh8g6F9.mjs +1354 -0
  22. package/dist/agent/chunks/tree-DO7N0UDV.mjs +127 -0
  23. package/dist/agent/chunks/types-DOK7tAAu.mjs +30 -0
  24. package/dist/agent/chunks/validate-CXPFB-i6.mjs +936 -0
  25. package/dist/engine/agentphoto-engine.js +2777 -0
  26. package/dist/engine/chunks/transformers.web-D5Vsg6-A.js +18494 -0
  27. package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.mjs +124 -0
  28. package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.wasm +0 -0
  29. package/dist/studio/assets/index-Be8JnaFy.js +28 -0
  30. package/dist/studio/assets/index-DwPms2S5.css +1 -0
  31. package/dist/studio/assets/transformers.web-DgnCIB_X.js +38 -0
  32. package/dist/studio/index.html +15 -0
  33. package/dist/studio/library/LICENSES.md +57 -0
  34. package/dist/studio/library/fonts/OFL.txt +90 -0
  35. package/dist/studio/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
  36. package/dist/studio/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
  37. package/dist/studio/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
  38. package/dist/studio/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
  39. package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
  40. package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
  41. package/dist/studio/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
  42. package/dist/studio/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
  43. package/dist/studio/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
  44. package/dist/studio/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
  45. package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
  46. package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
  47. package/dist/studio/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
  48. package/dist/studio/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
  49. package/dist/studio/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
  50. package/dist/studio/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
  51. package/dist/studio/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
  52. package/dist/studio/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
  53. package/dist/studio/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
  54. package/dist/studio/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
  55. package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
  56. package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
  57. package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
  58. package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
  59. package/dist/studio/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
  60. package/dist/studio/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
  61. package/dist/studio/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
  62. package/dist/studio/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
  63. package/dist/studio/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
  64. package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
  65. package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
  66. package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
  67. package/dist/studio/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
  68. package/dist/studio/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
  69. package/dist/studio/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
  70. package/dist/studio/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
  71. package/dist/studio/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
  72. package/dist/studio/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
  73. package/dist/studio/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
  74. package/dist/studio/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
  75. package/dist/studio/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
  76. package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
  77. package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
  78. package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
  79. package/dist/studio/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
  80. package/dist/studio/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
  81. package/dist/studio/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
  82. package/dist/studio/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
  83. package/dist/studio/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
  84. package/dist/studio/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
  85. package/dist/studio/library/fonts/roboto-slab/LICENSE.txt +202 -0
  86. package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
  87. package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
  88. package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
  89. package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
  90. package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
  91. package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
  92. package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
  93. package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
  94. package/dist/studio/library/images/city.jpg +0 -0
  95. package/dist/studio/library/images/food.jpg +0 -0
  96. package/dist/studio/library/images/landscape.jpg +0 -0
  97. package/dist/studio/library/images/pet.jpg +0 -0
  98. package/dist/studio/library/images/portrait.jpg +0 -0
  99. package/dist/studio/library/images/product.jpg +0 -0
  100. package/dist/studio/library/index.json +752 -0
  101. package/dist/studio/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
  102. package/dist/studio/templates/avatar-pro/photo.json +13 -0
  103. package/dist/studio/templates/avatar-pro/preview.jpg +0 -0
  104. package/dist/studio/templates/avatar-pro/template.json +1 -0
  105. package/dist/studio/templates/index.json +1 -0
  106. package/dist/studio/templates/og-article/photo.json +13 -0
  107. package/dist/studio/templates/og-article/preview.jpg +0 -0
  108. package/dist/studio/templates/og-article/template.json +1 -0
  109. package/dist/studio/templates/polaroid/photo.json +13 -0
  110. package/dist/studio/templates/polaroid/preview.jpg +0 -0
  111. package/dist/studio/templates/polaroid/template.json +1 -0
  112. package/dist/studio/templates/product-white/assets/masks/photo-cutout.png +0 -0
  113. package/dist/studio/templates/product-white/photo.json +72 -0
  114. package/dist/studio/templates/product-white/preview.jpg +0 -0
  115. package/dist/studio/templates/product-white/template.json +1 -0
  116. package/dist/studio/templates/sale-banner/photo.json +125 -0
  117. package/dist/studio/templates/sale-banner/preview.jpg +0 -0
  118. package/dist/studio/templates/sale-banner/template.json +1 -0
  119. package/dist/studio/templates/social-quote/photo.json +13 -0
  120. package/dist/studio/templates/social-quote/preview.jpg +0 -0
  121. package/dist/studio/templates/social-quote/template.json +1 -0
  122. package/dist/studio/templates/story-promo/photo.json +13 -0
  123. package/dist/studio/templates/story-promo/preview.jpg +0 -0
  124. package/dist/studio/templates/story-promo/template.json +1 -0
  125. package/dist/studio/templates/youtube-thumbnail/photo.json +12 -0
  126. package/dist/studio/templates/youtube-thumbnail/preview.jpg +0 -0
  127. package/dist/studio/templates/youtube-thumbnail/template.json +1 -0
  128. package/library/LICENSES.md +57 -0
  129. package/library/fonts/OFL.txt +90 -0
  130. package/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
  131. package/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
  132. package/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
  133. package/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
  134. package/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
  135. package/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
  136. package/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
  137. package/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
  138. package/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
  139. package/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
  140. package/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
  141. package/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
  142. package/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
  143. package/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
  144. package/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
  145. package/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
  146. package/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
  147. package/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
  148. package/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
  149. package/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
  150. package/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
  151. package/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
  152. package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
  153. package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
  154. package/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
  155. package/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
  156. package/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
  157. package/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
  158. package/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
  159. package/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
  160. package/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
  161. package/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
  162. package/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
  163. package/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
  164. package/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
  165. package/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
  166. package/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
  167. package/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
  168. package/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
  169. package/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
  170. package/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
  171. package/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
  172. package/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
  173. package/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
  174. package/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
  175. package/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
  176. package/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
  177. package/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
  178. package/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
  179. package/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
  180. package/library/fonts/roboto-slab/LICENSE.txt +202 -0
  181. package/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
  182. package/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
  183. package/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
  184. package/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
  185. package/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
  186. package/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
  187. package/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
  188. package/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
  189. package/library/images/city.jpg +0 -0
  190. package/library/images/food.jpg +0 -0
  191. package/library/images/landscape.jpg +0 -0
  192. package/library/images/pet.jpg +0 -0
  193. package/library/images/portrait.jpg +0 -0
  194. package/library/images/product.jpg +0 -0
  195. package/library/index.json +752 -0
  196. package/package.json +65 -4
  197. package/plugin/.claude-plugin/plugin.json +19 -0
  198. package/plugin/skills/agentphoto-cutout/SKILL.md +132 -0
  199. package/plugin/skills/agentphoto-design/SKILL.md +104 -0
  200. package/plugin/skills/agentphoto-design/references/layouts.md +60 -0
  201. package/plugin/skills/agentphoto-publish/SKILL.md +79 -0
  202. package/plugin/skills/agentphoto-retouch/SKILL.md +144 -0
  203. package/plugin/skills/agentphoto-retouch/references/filters.md +51 -0
  204. package/plugin/skills/agentphoto-retouch/references/patch-ops.md +66 -0
  205. package/plugin/skills/agentphoto-retouch/references/recipes.md +129 -0
  206. package/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
  207. package/templates/avatar-pro/photo.json +13 -0
  208. package/templates/avatar-pro/preview.jpg +0 -0
  209. package/templates/avatar-pro/template.json +1 -0
  210. package/templates/og-article/photo.json +13 -0
  211. package/templates/og-article/preview.jpg +0 -0
  212. package/templates/og-article/template.json +1 -0
  213. package/templates/polaroid/photo.json +13 -0
  214. package/templates/polaroid/preview.jpg +0 -0
  215. package/templates/polaroid/template.json +1 -0
  216. package/templates/product-white/assets/masks/photo-cutout.png +0 -0
  217. package/templates/product-white/photo.json +72 -0
  218. package/templates/product-white/preview.jpg +0 -0
  219. package/templates/product-white/template.json +1 -0
  220. package/templates/sale-banner/photo.json +125 -0
  221. package/templates/sale-banner/preview.jpg +0 -0
  222. package/templates/sale-banner/template.json +1 -0
  223. package/templates/social-quote/photo.json +13 -0
  224. package/templates/social-quote/preview.jpg +0 -0
  225. package/templates/social-quote/template.json +1 -0
  226. package/templates/story-promo/photo.json +13 -0
  227. package/templates/story-promo/preview.jpg +0 -0
  228. package/templates/story-promo/template.json +1 -0
  229. package/templates/youtube-thumbnail/photo.json +12 -0
  230. package/templates/youtube-thumbnail/preview.jpg +0 -0
  231. package/templates/youtube-thumbnail/template.json +1 -0
@@ -0,0 +1,2777 @@
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 oe(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 se(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 ce(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 le(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 ue(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 = ce(r[2]);
1110
+ if (!i || i.length !== 3 && i.length !== 4) return null;
1111
+ let a = i.length === 4 ? oe(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) => oe(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 = se(i[0]), s = oe(i[1], 1), c = oe(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] = le(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 de({ 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 T = (e) => e < 0 ? 0 : e > 255 ? 255 : e, E = (e) => e < 0 ? 0 : e > 1 ? 1 : e;
1141
+ function fe(e) {
1142
+ return {
1143
+ data: new Uint8ClampedArray(e.data),
1144
+ width: e.width,
1145
+ height: e.height
1146
+ };
1147
+ }
1148
+ function D(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 O(e) {
1153
+ let t = /* @__PURE__ */ new Uint8ClampedArray(256);
1154
+ for (let n = 0; n < 256; n++) t[n] = Math.round(T(e(n)));
1155
+ return t;
1156
+ }
1157
+ var k = (e, t, n) => .299 * e + .587 * t + .114 * n, pe = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4, me = (e) => e <= .0031308 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - .055;
1158
+ function he(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 ge(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 A(e, t, n, r) {
1184
+ if (r < .5) return;
1185
+ let i = new Float32Array(e.length);
1186
+ for (let a of ge(r / 2)) he(e, t, n, Math.round(a), i);
1187
+ }
1188
+ function _e(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
+ A(o, r, i, t), A(s, r, i, t), A(c, r, i, t), u || A(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 ve(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] = k(n[e], n[e + 1], n[e + 2]) / 255;
1204
+ return A(a, r, i, t), a;
1205
+ }
1206
+ function ye(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
+ A(i, t, n, r);
1211
+ for (let t = 0; t < i.length; t++) e[t] = i[t];
1212
+ }
1213
+ function be(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 xe(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 Se(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 Ce(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
+ Se(i, r, e + 1 / 3) * 255,
1248
+ Se(i, r, e) * 255,
1249
+ Se(i, r, e - 1 / 3) * 255
1250
+ ];
1251
+ }
1252
+ function we(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 O((e) => e);
1255
+ if (n === 1) return O(() => 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] = T(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 Te(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(k(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 j(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 M = (e, t) => O((n) => (n - e) * 255 / Math.max(1, t - e));
1307
+ // src/engine/analyze.ts
1308
+ function Ee(e) {
1309
+ let { data: t, width: n, height: r } = e, i = Te(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 = k(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] = j(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 k(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: N(d / (n * r) * 100),
1332
+ brightness: N(f),
1333
+ contrast: N(p),
1334
+ range: [m, h],
1335
+ clippedShadows: N(g / a * 100),
1336
+ clippedHighlights: N(_ / a * 100),
1337
+ saturation: N(c / a * 100),
1338
+ cast: {
1339
+ warm: N(l / a),
1340
+ magenta: N(u / a)
1341
+ },
1342
+ sharpness: N(y ? v / y : 0),
1343
+ dominant: De(e, 5),
1344
+ suggestions: []
1345
+ };
1346
+ return x.suggestions = Oe(x), x;
1347
+ }
1348
+ var N = (e) => Math.round(e * 10) / 10;
1349
+ function De(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: de({
1373
+ r: e.r,
1374
+ g: e.g,
1375
+ b: e.b,
1376
+ a: 1
1377
+ }),
1378
+ share: N(e.n / Math.max(1, a) * 100)
1379
+ }));
1380
+ }
1381
+ function Oe(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: N(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: N(-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: N(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: N(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 ke = 16384;
1451
+ function P(e, t) {
1452
+ let n = Math.max(1, Math.min(ke, Math.ceil(e))), r = Math.max(1, Math.min(ke, 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 F(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 I(e) {
1466
+ let t = F(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 Ae(e, t) {
1474
+ F(e).putImageData(new ImageData(t.data, t.width, t.height), 0, 0);
1475
+ }
1476
+ function je(e) {
1477
+ return !e || e === "normal" ? "source-over" : e;
1478
+ }
1479
+ function L(e, t) {
1480
+ let n = P(e.width, e.height), r = F(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 Me(e) {
1484
+ let t = I(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 Ne(e, t, n, r = [
1489
+ 255,
1490
+ 255,
1491
+ 255
1492
+ ]) {
1493
+ let i = P(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 Ae(i, {
1496
+ data: a,
1497
+ width: t,
1498
+ height: n
1499
+ }), i;
1500
+ }
1501
+ async function Pe(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 Fe = (e) => !!e && typeof e == "object" && !Array.isArray(e);
1510
+ function Ie(e) {
1511
+ return JSON.stringify(Le(e));
1512
+ }
1513
+ function Le(e) {
1514
+ if (Array.isArray(e)) return e.map(Le);
1515
+ if (Fe(e)) {
1516
+ let t = {};
1517
+ for (let n of Object.keys(e).sort()) e[n] !== void 0 && (t[n] = Le(e[n]));
1518
+ return t;
1519
+ }
1520
+ return e;
1521
+ }
1522
+ // src/engine/effects.ts
1523
+ var R = (e, t) => typeof e == "number" && Number.isFinite(e) ? e : t;
1524
+ function Re(e, t) {
1525
+ if (!e) return 0;
1526
+ let n = 0;
1527
+ return e.dropShadow && (n = Math.max(n, (R(e.dropShadow.distance, 12) + R(e.dropShadow.blur, 16) * 1.5 + R(e.dropShadow.spread, 0)) * t)), e.outerGlow && (n = Math.max(n, (R(e.outerGlow.blur, 20) * 1.5 + R(e.outerGlow.spread, 0)) * t)), e.stroke && (e.stroke.position ?? "outside") !== "inside" && (n = Math.max(n, R(e.stroke.width, 6) * t)), Math.ceil(n) + (n ? 2 : 0);
1528
+ }
1529
+ var ze = (e) => !!e && Object.values(e).some(Boolean);
1530
+ function z(e, t) {
1531
+ let n = P(e.width, e.height), r = F(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 Be(e, t = 96) {
1544
+ let n = Me(e);
1545
+ for (let e = 0; e < n.length; e++) n[e] = n[e] >= t ? 255 : n[e] * 255 / t;
1546
+ return Ne(n, e.width, e.height);
1547
+ }
1548
+ function Ve(e) {
1549
+ let t = P(e.width, e.height), n = F(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 He(e, t, n) {
1553
+ if (t < .5) return L(e, n);
1554
+ let r = Me(e);
1555
+ return ye(r, e.width, e.height, t), L(Ne(r, e.width, e.height), n);
1556
+ }
1557
+ function Ue(e, t, n) {
1558
+ let r = e.canvas, i = r.width, a = r.height, o = P(i, a), s = F(o);
1559
+ if (t.dropShadow) {
1560
+ let e = t.dropShadow, i = R(e.spread, 0) * n, a = He(i ? z(r, i) : r, R(e.blur, 16) * n, e.color ?? "#000000"), o = R(e.angle, 135) * Math.PI / 180, c = R(e.distance, 12) * n;
1561
+ s.globalAlpha = R(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 = R(e.spread, 0) * n, a = He(i ? z(r, i) : r, R(e.blur, 20) * n, e.color ?? "#ffffff");
1565
+ s.globalAlpha = R(e.opacity, .6), s.drawImage(a, 0, 0), s.globalAlpha = R(e.opacity, .6) * .5, s.drawImage(a, 0, 0), s.globalAlpha = 1;
1566
+ }
1567
+ let c = t.stroke, l = c ? R(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 = R(c.opacity, 1), s.drawImage(L(z(Be(r), e), c.color ?? "#ffffff"), 0, 0), s.globalAlpha = 1;
1571
+ }
1572
+ let d = P(i, a), f = F(d);
1573
+ if (f.drawImage(r, 0, 0), t.colorOverlay) {
1574
+ let e = t.colorOverlay, n = L(r, e.color ?? "#ffffff");
1575
+ f.globalAlpha = R(e.opacity, 1), f.globalCompositeOperation = je(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 = He(Ve(r), R(e.blur, 10) * n, e.color ?? "#000000"), s = R(e.angle, 135) * Math.PI / 180, c = R(e.distance, 6) * n, l = P(i, a), u = F(l);
1579
+ u.drawImage(o, -Math.cos(s) * c, Math.sin(s) * c), u.globalCompositeOperation = "destination-in", u.drawImage(r, 0, 0), f.globalAlpha = R(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 = Ve(z(Ve(r), e)), n = L(r, c.color ?? "#ffffff"), i = F(n);
1583
+ i.globalCompositeOperation = "destination-out", i.drawImage(t, 0, 0), f.globalAlpha = R(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 B(e, t, n, r, i = 1, a = 1, o = 1) {
1593
+ for (let s = 0; s < e.length; s += 4) e[s] = T((e[s] + t) * i), e[s + 1] = T((e[s + 1] + n) * a), e[s + 2] = T((e[s + 2] + r) * o);
1594
+ }
1595
+ function V(e, t) {
1596
+ for (let n = 0; n < e.length; n += 4) e[n] = T((e[n] - 128) * t + 128), e[n + 1] = T((e[n + 1] - 128) * t + 128), e[n + 2] = T((e[n + 2] - 128) * t + 128);
1597
+ }
1598
+ function H(e, t) {
1599
+ for (let n = 0; n < e.length; n += 4) {
1600
+ let r = k(e[n], e[n + 1], e[n + 2]);
1601
+ e[n] = T(r + (e[n] - r) * t), e[n + 1] = T(r + (e[n + 1] - r) * t), e[n + 2] = T(r + (e[n + 2] - r) * t);
1602
+ }
1603
+ }
1604
+ function U(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 W(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 We(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 G(e, t, n) {
1627
+ for (let r = 0; r < e.length; r += 4) {
1628
+ let i = k(e[r], e[r + 1], e[r + 2]) / 255, a = 1 - i;
1629
+ e[r] = T(e[r] + n[0] * i + t[0] * a), e[r + 1] = T(e[r + 1] + n[1] * i + t[1] * a), e[r + 2] = T(e[r + 2] + n[2] * i + t[2] * a);
1630
+ }
1631
+ }
1632
+ var Ge = {
1633
+ bw: (e) => H(e.data, 0),
1634
+ noir: (e) => {
1635
+ H(e.data, 0), V(e.data, 1.55), U(e.data, .85, .85, .85), W(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] = T(n * .393 + r * .769 + i * .189), t[e + 1] = T(n * .349 + r * .686 + i * .168), t[e + 2] = T(n * .272 + r * .534 + i * .131);
1642
+ }
1643
+ },
1644
+ vintage: (e) => {
1645
+ B(e.data, 8, -6, -16, 1, 1, .92), H(e.data, .7), V(e.data, .92), U(e.data, 1.05, 1, .9), W(e, .35);
1646
+ },
1647
+ polaroid: (e) => {
1648
+ B(e.data, 12, 4, -8), H(e.data, .85), V(e.data, .95);
1649
+ },
1650
+ lomo: (e) => {
1651
+ H(e.data, 1.45), V(e.data, 1.25), W(e, .55);
1652
+ },
1653
+ warm: (e) => {
1654
+ B(e.data, 18, 6, -14), H(e.data, 1.1);
1655
+ },
1656
+ cool: (e) => {
1657
+ B(e.data, -10, 0, 16), H(e.data, .95);
1658
+ },
1659
+ sunset: (e) => {
1660
+ B(e.data, 28, -4, -24, 1, 1, .95), H(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
+ H(t, .85);
1666
+ },
1667
+ punch: (e) => {
1668
+ H(e.data, 1.4), V(e.data, 1.2);
1669
+ },
1670
+ cinema: (e) => {
1671
+ G(e.data, [
1672
+ -6,
1673
+ 2,
1674
+ 14
1675
+ ], [
1676
+ 20,
1677
+ 6,
1678
+ -14
1679
+ ]), V(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] = T(t[e] * 1.05 + 18), t[e + 1] = T(t[e + 1] * .85), t[e + 2] = T(t[e + 2] * 1.1 + 22);
1684
+ V(t, 1.25), H(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] = T(t[e] * 1.1), t[e + 1] = T(t[e + 1] + (255 - t[e + 1]) * .15), t[e + 2] = T(t[e + 2] * .85);
1689
+ V(t, 1.18), H(t, 1.15);
1690
+ },
1691
+ dramatic: (e) => {
1692
+ V(e.data, 1.5), U(e.data, .85, .85, .85), H(e.data, .6), W(e, .4);
1693
+ },
1694
+ dreamy: (e) => {
1695
+ B(e.data, 14, 8, 16), H(e.data, .85), V(e.data, .88), U(e.data, 1.1, 1.05, 1.1);
1696
+ },
1697
+ matte: (e) => {
1698
+ We(e.data, 28, .86), H(e.data, .82), G(e.data, [
1699
+ 0,
1700
+ 4,
1701
+ 8
1702
+ ], [
1703
+ 6,
1704
+ 2,
1705
+ -4
1706
+ ]);
1707
+ },
1708
+ "golden-hour": (e) => {
1709
+ G(e.data, [
1710
+ 6,
1711
+ -2,
1712
+ -10
1713
+ ], [
1714
+ 26,
1715
+ 12,
1716
+ -20
1717
+ ]), H(e.data, 1.12), U(e.data, 1.06, 1.02, .96);
1718
+ },
1719
+ film: (e) => {
1720
+ We(e.data, 14, .92), V(e.data, 1.06), G(e.data, [
1721
+ -4,
1722
+ 2,
1723
+ 8
1724
+ ], [
1725
+ 10,
1726
+ 4,
1727
+ -6
1728
+ ]), H(e.data, .92);
1729
+ let t = be(7), n = e.data;
1730
+ for (let e = 0; e < n.length; e += 4) {
1731
+ let r = (t() - .5) * 14;
1732
+ n[e] = T(n[e] + r), n[e + 1] = T(n[e + 1] + r), n[e + 2] = T(n[e + 2] + r);
1733
+ }
1734
+ },
1735
+ clean: (e) => {
1736
+ U(e.data, 1.08, 1.08, 1.1), B(e.data, -2, 0, 4), V(e.data, 1.06), H(e.data, 1.05);
1737
+ }
1738
+ }, K = (e, t) => typeof e == "number" && Number.isFinite(e) ? e : t, q = (e, t) => typeof e == "boolean" ? e : t, Ke = (e) => Array.isArray(e) && e.length === 3 ? [
1739
+ K(e[0], 0),
1740
+ K(e[1], 0),
1741
+ K(e[2], 0)
1742
+ ] : [
1743
+ 0,
1744
+ 0,
1745
+ 0
1746
+ ], J = (e, t) => ue(typeof e == "string" ? e : t) ?? ue(t);
1747
+ function qe(e) {
1748
+ let t = (Array.isArray(e) && e.length >= 2 ? e : ["#000", "#fff"]).map((e, t, n) => Array.isArray(e) ? [K(e[0], t / (n.length - 1)), J(e[1], "#000")] : [t / (n.length - 1), J(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 ? E((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 - k(e[t], e[t + 1], e[t + 2]);
1765
+ e[t] = T(e[t] + r), e[t + 1] = T(e[t + 1] + r), e[t + 2] = T(e[t + 2] + r);
1766
+ }
1767
+ var Ye = {
1768
+ brightnessContrast(e, t) {
1769
+ let n = K(t.brightness, 0) / 100, r = K(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
+ D(e, O((e) => (255 * (e / 255) ** i - 128) * a + 128));
1771
+ },
1772
+ exposure(e, t) {
1773
+ let n = 2 ** K(t.exposure, 0), r = K(t.offset, 0), i = K(t.gamma, 1);
1774
+ D(e, O((e) => 255 * me(E(Math.max(0, pe(e / 255) * n + r) ** (1 / i)))));
1775
+ },
1776
+ shadowsHighlights(e, t, n) {
1777
+ let r = K(t.shadows, 35) / 100, i = K(t.highlights, 0) / 100;
1778
+ if (!r && !i) return;
1779
+ let a = ve(e, Math.max(1, K(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 = K(t.black, 0), r = Math.max(n + 1, K(t.white, 255)), i = K(t.gamma, 1), a = K(t.outBlack, 0), o = K(t.outWhite, 255);
1790
+ D(e, O((e) => a + (o - a) * E((e - n) / (r - n)) ** (1 / i)));
1791
+ },
1792
+ curves(e, t) {
1793
+ let n = O((e) => e), r = Array.isArray(t.rgb) ? we(t.rgb) : n, i = (e) => Array.isArray(e) ? we(e) : n, [a, o, s] = [
1794
+ i(t.red),
1795
+ i(t.green),
1796
+ i(t.blue)
1797
+ ];
1798
+ D(e, O((e) => a[r[e]]), O((e) => o[r[e]]), O((e) => s[r[e]]));
1799
+ },
1800
+ hueSaturation(e, t) {
1801
+ let n = K(t.hue, 0), r = K(t.saturation, 0) / 100, i = K(t.lightness, 0) / 100, a = q(t.colorize, !1), o = e.data;
1802
+ for (let e = 0; e < o.length; e += 4) {
1803
+ let [t, s, c] = xe(o[e], o[e + 1], o[e + 2]);
1804
+ a ? (t = n, s = E(.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] = Ce(t, E(s), E(c));
1806
+ o[e] = l, o[e + 1] = u, o[e + 2] = d;
1807
+ }
1808
+ },
1809
+ vibrance(e, t) {
1810
+ let n = K(t.vibrance, 30) / 100, r = K(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 = k(t, a, o);
1815
+ i[e] = T(d + (t - d) * u), i[e + 1] = T(d + (a - d) * u), i[e + 2] = T(d + (o - d) * u);
1816
+ }
1817
+ },
1818
+ temperature(e, t) {
1819
+ let n = K(t.temperature, 0) / 100, r = K(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) => O((t) => 255 * me(E(pe(t / 255) * e)));
1820
+ D(e, s(i), s(a), s(o));
1821
+ },
1822
+ colorBalance(e, t) {
1823
+ let n = Ke(t.shadows), r = Ke(t.midtones), i = Ke(t.highlights), a = q(t.preserveLuminosity, !0), o = e.data;
1824
+ for (let e = 0; e < o.length; e += 4) {
1825
+ let t = k(o[e], o[e + 1], o[e + 2]), s = t / 255, c = E(1 - s * 2.2) * .8, l = E(1 - Math.abs(s - .5) * 2.5) * .8, u = E((s - .55) * 2.2) * .8;
1826
+ for (let t = 0; t < 3; t++) o[e + t] = T(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 = J(t.color, "#ec8a00"), r = E(K(t.density, 25) / 100), i = q(t.preserveLuminosity, !0), a = e.data;
1832
+ for (let e = 0; e < a.length; e += 4) {
1833
+ let t = k(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(k(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 = K(t.red, 30) / 100, r = K(t.green, 59) / 100, i = K(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 = T(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 = E(K(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 + (T(t * .393 + i * .769 + a * .189) - t) * n, r[e + 1] = i + (T(t * .349 + i * .686 + a * .168) - i) * n, r[e + 2] = a + (T(t * .272 + i * .534 + a * .131) - a) * n;
1862
+ }
1863
+ },
1864
+ invert(e) {
1865
+ D(e, O((e) => 255 - e));
1866
+ },
1867
+ threshold(e, t) {
1868
+ let n = K(t.level, 128), r = e.data;
1869
+ for (let e = 0; e < r.length; e += 4) {
1870
+ let t = k(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(K(t.levels, 6))) - 1);
1876
+ D(e, O((e) => Math.round(e / n) * n));
1877
+ },
1878
+ blur(e, t, n) {
1879
+ _e(e, K(t.radius, 6) * n.scale);
1880
+ },
1881
+ motionBlur(e, t, n) {
1882
+ let r = Math.round(K(t.distance, 20) * n.scale);
1883
+ if (r < 1) return;
1884
+ let i = K(t.angle, 0) * Math.PI / 180, a = Math.cos(i), o = Math.sin(i), { data: s, width: c, height: l } = fe(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(K(t.radius, 8) * n.scale)), i = K(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 A(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] = T((s[t] * u[t] + c[t]) * 255);
1912
+ }
1913
+ },
1914
+ sharpen(e, t, n) {
1915
+ let r = K(t.amount, 80) / 100, i = Math.max(.3, K(t.radius, 1.2) * n.scale), a = K(t.threshold, 2), o = fe(e);
1916
+ _e(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] = T(s[e + t] + n * r));
1921
+ }
1922
+ },
1923
+ clarity(e, t, n) {
1924
+ let r = K(t.amount, 30) / 100, i = ve(e, Math.max(2, K(t.radius, 24) * n.scale)), a = e.data;
1925
+ for (let e = 0, t = 0; t < i.length; e += 4, t++) {
1926
+ let n = k(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] = T(a[e] + s), a[e + 1] = T(a[e + 1] + s), a[e + 2] = T(a[e + 2] + s);
1928
+ }
1929
+ },
1930
+ noise(e, t, n) {
1931
+ let r = K(t.amount, 12) / 100 * 110, i = q(t.monochrome, !0), a = be(Math.round(K(t.seed, 1)) * 7919 + 17), o = Math.max(1, Math.round(K(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] = T(s[a] + f[i] * r), s[a + 1] = T(s[a + 1] + f[i + 1] * r), s[a + 2] = T(s[a + 2] + f[i + 2] * r);
1941
+ }
1942
+ }
1943
+ },
1944
+ pixelate(e, t, n) {
1945
+ let r = Math.max(1, Math.round(K(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 = K(t.amount, 40) / 100, r = K(t.size, 50) / 100, i = Math.max(.01, K(t.feather, 60) / 100), a = J(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 = E((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 = K(t.clip, .5), r = Te(e);
1977
+ if (!r.count) return;
1978
+ let [i, a] = j(r.r, r.count, n), [o, s] = j(r.g, r.count, n), [c, l] = j(r.b, r.count, n);
1979
+ D(e, M(i, a), M(o, s), M(c, l));
1980
+ },
1981
+ autoContrast(e, t) {
1982
+ let n = Te(e);
1983
+ if (!n.count) return;
1984
+ let [r, i] = j(n.l, n.count, K(t.clip, .5));
1985
+ D(e, M(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
+ D(e, O((e) => e * u(s)), O((e) => e * u(c)), O((e) => e * u(l))), Ye.autoContrast(e, { clip: .3 }, { scale: 1 });
1997
+ },
1998
+ look(e, t) {
1999
+ let n = Ge[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" ? E(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
+ new Set(f.filter((e) => e.group === "blur" || e.group === "detail" || e.id === "shadowsHighlights" || e.id === "pixelate").map((e) => e.id));
2030
+ // src/engine/paint.ts
2031
+ function Qe(e) {
2032
+ let t = Array.isArray(e) && e.length ? e : ["#000", "#fff"], n = t.length;
2033
+ 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)]);
2034
+ }
2035
+ function Y(e, t, n, r = "#ffffff") {
2036
+ if (t == null) return r;
2037
+ if (typeof t == "string") return t;
2038
+ let i;
2039
+ if (t.type === "radial") {
2040
+ let r = n.x + (t.cx ?? .5) * n.w, a = n.y + (t.cy ?? .5) * n.h, o = Math.max(.5, (t.radius ?? 1) * Math.hypot(n.w, n.h) * .5);
2041
+ i = e.createRadialGradient(r, a, 0, r, a, o);
2042
+ } else {
2043
+ let r = (t.angle ?? 90) * Math.PI / 180, a = Math.cos(r), o = Math.sin(r), 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;
2044
+ i = e.createLinearGradient(c - a * s, l - o * s, c + a * s, l + o * s);
2045
+ }
2046
+ for (let [e, n] of Qe(t.stops)) try {
2047
+ i.addColorStop(e, n);
2048
+ } catch {}
2049
+ return i;
2050
+ }
2051
+ // src/engine/text.ts
2052
+ var $e = null, et = () => $e ??= F(P(8, 8));
2053
+ function tt(e, t, n) {
2054
+ let r = /[\s,'"]/.test(t) && !/^["']/.test(t) && !t.includes(",") ? `"${t}"` : t;
2055
+ return `${e.italic ? "italic " : ""}${e.weight ?? 400} ${n}px ${r}, system-ui, sans-serif`;
2056
+ }
2057
+ var nt = (e, t) => e.transform === "uppercase" ? t.toUpperCase() : e.transform === "lowercase" ? t.toLowerCase() : t;
2058
+ function rt(e, t) {
2059
+ return "letterSpacing" in e && (e.letterSpacing = `${t}px`, !0);
2060
+ }
2061
+ function X(e, t, n, r) {
2062
+ return t ? r || !n ? e.measureText(t).width : e.measureText(t).width + n * (Array.from(t).length - 1) : 0;
2063
+ }
2064
+ function it(e, t, n = 1) {
2065
+ let r = et(), i = (e.size ?? 64) * n, a = (e.letterSpacing ?? 0) * n, o = tt(e, t, i);
2066
+ r.font = o;
2067
+ let s = rt(r, a), c = e.width === void 0 ? Infinity : e.width * n, l = [];
2068
+ for (let t of nt(e, String(e.text ?? "")).split("\n")) {
2069
+ let e = t.split(/(\s+)/), n = "";
2070
+ for (let t of e) {
2071
+ let e = n + t;
2072
+ if (n && X(r, e.trimEnd(), a, s) > c && t.trim()) for (l.push({
2073
+ text: n.trimEnd(),
2074
+ width: X(r, n.trimEnd(), a, s)
2075
+ }), n = t.trimStart(); X(r, n, a, s) > c && n.length > 1;) {
2076
+ let e = n.length - 1;
2077
+ for (; e > 1 && X(r, n.slice(0, e), a, s) > c;) e--;
2078
+ l.push({
2079
+ text: n.slice(0, e),
2080
+ width: X(r, n.slice(0, e), a, s)
2081
+ }), n = n.slice(e);
2082
+ }
2083
+ else n = e;
2084
+ }
2085
+ l.push({
2086
+ text: n.trimEnd(),
2087
+ width: X(r, n.trimEnd(), a, s)
2088
+ });
2089
+ }
2090
+ 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;
2091
+ return s && rt(r, 0), {
2092
+ font: o,
2093
+ lines: l,
2094
+ width: (e.width === void 0 ? m : e.width * n) / n,
2095
+ height: (e.height === void 0 ? h : e.height * n) / n,
2096
+ lineHeight: p,
2097
+ ascent: d,
2098
+ descent: f,
2099
+ textHeight: h
2100
+ };
2101
+ }
2102
+ function at(e) {
2103
+ let t = e.background?.padding ?? 0;
2104
+ return Array.isArray(t) ? [t[0], t[1]] : [t, t];
2105
+ }
2106
+ function ot(e, t, n) {
2107
+ let r = it(e, t, n), i = r.width * n, a = r.height * n, [o, s] = e.background ? at(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 = P(i + l * 2, a + u * 2), f = F(d);
2108
+ if (e.background) {
2109
+ f.fillStyle = e.background.color;
2110
+ let t = (e.background.radius ?? 0) * n;
2111
+ f.beginPath(), st(f, l - o, u - s, i + o * 2, a + s * 2, t), f.fill();
2112
+ }
2113
+ f.font = r.font;
2114
+ let p = rt(f, (e.letterSpacing ?? 0) * n);
2115
+ f.textBaseline = "alphabetic", f.fillStyle = Y(f, e.color ?? "#ffffff", {
2116
+ x: l,
2117
+ y: u,
2118
+ w: i,
2119
+ h: a
2120
+ });
2121
+ let m = e.valign ?? "top", h = u + (m === "middle" ? (a - r.textHeight) / 2 : m === "bottom" ? a - r.textHeight : 0), g = (e.letterSpacing ?? 0) * n;
2122
+ return r.lines.forEach((t, n) => {
2123
+ 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);
2124
+ if (p || !g) f.fillText(t.text, s, a);
2125
+ else {
2126
+ let e = s;
2127
+ for (let n of Array.from(t.text)) f.fillText(n, e, a), e += f.measureText(n).width + g;
2128
+ }
2129
+ }), {
2130
+ canvas: d,
2131
+ ox: l,
2132
+ oy: u,
2133
+ w: i,
2134
+ h: a
2135
+ };
2136
+ }
2137
+ function st(e, t, n, r, i, a) {
2138
+ let o = Math.max(0, Math.min(a, r / 2, i / 2));
2139
+ 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);
2140
+ }
2141
+ // src/engine/compositor.ts
2142
+ var ct = 96, lt = class {
2143
+ loader;
2144
+ cache = /* @__PURE__ */ new Map();
2145
+ tick = 0;
2146
+ natural = /* @__PURE__ */ new Map();
2147
+ constructor(e) {
2148
+ this.loader = e;
2149
+ }
2150
+ clearCache() {
2151
+ this.cache.clear();
2152
+ }
2153
+ async render(e, t = {}) {
2154
+ 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 = P(r, i), o = F(a);
2155
+ if (t.backdrop === "checker") {
2156
+ let e = Math.max(6, Math.round(12 * Math.min(1, n * 2)));
2157
+ o.fillStyle = "#ffffff", o.fillRect(0, 0, r, i), o.fillStyle = "#d9d9d9";
2158
+ 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);
2159
+ } else t.backdrop && (o.fillStyle = t.backdrop, o.fillRect(0, 0, r, i));
2160
+ return t.background !== !1 && e.canvas.background && (o.fillStyle = Y(o, e.canvas.background, {
2161
+ x: 0,
2162
+ y: 0,
2163
+ w: r,
2164
+ h: i
2165
+ }), o.fillRect(0, 0, r, i)), await this.preload(e), await this.compose(e.layers, a, e, n, t), this.evict(), a;
2166
+ }
2167
+ async layerSurface(e, t, n) {
2168
+ return await this.preload({
2169
+ ...t,
2170
+ layers: [e]
2171
+ }), this.surface(e, t, n, {});
2172
+ }
2173
+ async layerBox(t) {
2174
+ if (!e(t)) return null;
2175
+ let n = t.x ?? 0, r = t.y ?? 0, i = t.rotation ?? 0;
2176
+ if (t.type === "text") {
2177
+ let e = it(t, await this.family(t), 1);
2178
+ return {
2179
+ x: n,
2180
+ y: r,
2181
+ width: e.width,
2182
+ height: e.height,
2183
+ rotation: i
2184
+ };
2185
+ }
2186
+ if (t.type === "image") {
2187
+ let { w: e, h: a } = ft(t, await this.naturalSize(t.src).catch(() => null));
2188
+ return {
2189
+ x: n,
2190
+ y: r,
2191
+ width: e,
2192
+ height: a,
2193
+ rotation: i
2194
+ };
2195
+ }
2196
+ return {
2197
+ x: n,
2198
+ y: r,
2199
+ width: t.width ?? 0,
2200
+ height: t.height ?? 0,
2201
+ rotation: i
2202
+ };
2203
+ }
2204
+ async naturalSize(e) {
2205
+ let t = this.natural.get(e);
2206
+ if (t) return t;
2207
+ let n = await this.loader.image(e), r = {
2208
+ width: n.width,
2209
+ height: n.height
2210
+ };
2211
+ return this.natural.set(e, r), r;
2212
+ }
2213
+ async preload(e) {
2214
+ let t = [], n = (e) => {
2215
+ 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 ?? []);
2216
+ };
2217
+ n(e.layers ?? []), await Promise.all(t);
2218
+ }
2219
+ async compose(e, t, n, r, i) {
2220
+ let a = F(t), o = null, s = !0;
2221
+ for (let c of e ?? []) {
2222
+ if (!c || typeof c != "object") continue;
2223
+ let e = c.visible === !1 || i.skip?.has(c.id) || i.only && !dt(c, i.only);
2224
+ if (c.clip && (e || !o || !s)) continue;
2225
+ if (e) {
2226
+ c.clip || (o = null, s = !1);
2227
+ continue;
2228
+ }
2229
+ let l;
2230
+ try {
2231
+ l = c.type === "adjustment" ? await this.adjust(c, t, r) : await this.surface(c, n, r, i);
2232
+ } catch (e) {
2233
+ i.onError?.(c.id, e.message), l = null;
2234
+ }
2235
+ l ? (c.clip && o && (l = gt(l, o)), a.save(), a.globalAlpha = ut(c.opacity ?? 1), a.globalCompositeOperation = je(c.blend), a.drawImage(l.canvas, l.x, l.y), a.restore(), c.clip || (o = l, s = !0)) : c.clip || (o = null, s = !1);
2236
+ }
2237
+ }
2238
+ async surface(t, n, r, i) {
2239
+ let a = await this.cacheKey(t, n, r, i), o = this.cache.get(t.id);
2240
+ if (o && o.key === a) return o.used = ++this.tick, o.surface;
2241
+ let s = null;
2242
+ 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 = {
2243
+ ...s,
2244
+ canvas: await this.maskCanvasSpace(s.canvas, t.mask, n, r)
2245
+ }), s && ze(t.effects) && (s = Ue(s, t.effects, r)), this.cache.set(t.id, {
2246
+ key: a,
2247
+ surface: s,
2248
+ used: ++this.tick
2249
+ }), s;
2250
+ }
2251
+ async cacheKey(e, n, r, i) {
2252
+ let a = [], o = this.loader.version, s = (e) => {
2253
+ 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);
2254
+ };
2255
+ 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(",")}|${Ie(e)}`;
2256
+ }
2257
+ evict() {
2258
+ if (this.cache.size <= ct) return;
2259
+ let e = [...this.cache.entries()].sort((e, t) => e[1].used - t[1].used);
2260
+ for (let [t] of e.slice(0, this.cache.size - ct)) this.cache.delete(t);
2261
+ }
2262
+ async groupSurface(e, t, n, r) {
2263
+ let i = P(Math.max(1, Math.round(t.canvas.width * n)), Math.max(1, Math.round(t.canvas.height * n)));
2264
+ return await this.compose(e.children ?? [], i, t, n, r), e.filters?.length && pt(i, e.filters, n), {
2265
+ canvas: e.mask ? await this.maskCanvasSpace(i, e.mask, t, n) : i,
2266
+ x: 0,
2267
+ y: 0
2268
+ };
2269
+ }
2270
+ fillSurface(e, t, n) {
2271
+ let r = Math.max(1, Math.round(t.canvas.width * n)), i = Math.max(1, Math.round(t.canvas.height * n)), a = P(r, i), o = F(a);
2272
+ return o.fillStyle = Y(o, e.fill, {
2273
+ x: 0,
2274
+ y: 0,
2275
+ w: r,
2276
+ h: i
2277
+ }), o.fillRect(0, 0, r, i), e.filters?.length && pt(a, e.filters, n), {
2278
+ canvas: a,
2279
+ x: 0,
2280
+ y: 0
2281
+ };
2282
+ }
2283
+ async adjust(e, t, n) {
2284
+ if (!e.filters?.length) return null;
2285
+ let r = P(t.width, t.height);
2286
+ return F(r).drawImage(t, 0, 0), pt(r, e.filters, n), e.mask && e.mask.enabled !== !1 && ht(r, await this.maskPlane(e.mask, r.width, r.height, n, null)), {
2287
+ canvas: r,
2288
+ x: 0,
2289
+ y: 0
2290
+ };
2291
+ }
2292
+ async boxSurface(e, t) {
2293
+ let n;
2294
+ if (n = e.type === "image" ? await this.imageContent(e, t) : e.type === "text" ? ot(e, await this.family(e), t) : _t(e, t), !n || n.w <= 0 || n.h <= 0) return null;
2295
+ if (e.filters?.length && pt(n.canvas, e.filters, t), e.mask && e.mask.enabled !== !1) {
2296
+ 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);
2297
+ for (let e = 0; e < o; e++) {
2298
+ let t = e + c;
2299
+ if (!(t < 0 || t >= n.canvas.height)) for (let o = 0; o < a; o++) {
2300
+ let c = o + s;
2301
+ c < 0 || c >= n.canvas.width || (i[t * n.canvas.width + c] = r[e * a + o]);
2302
+ }
2303
+ }
2304
+ ht(n.canvas, i);
2305
+ }
2306
+ let r = Re(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 = [
2307
+ [d, f],
2308
+ [d + n.canvas.width, f],
2309
+ [d, f + n.canvas.height],
2310
+ [d + n.canvas.width, f + n.canvas.height]
2311
+ ].map(([e, t]) => {
2312
+ let n = e * l, r = t * u;
2313
+ return [o + n * Math.cos(c) - r * Math.sin(c), s + n * Math.sin(c) + r * Math.cos(c)];
2314
+ }), 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;
2315
+ if (!c && l === 1 && u === 1 && !r) return {
2316
+ canvas: n.canvas,
2317
+ x: Math.round(i - n.ox),
2318
+ y: Math.round(a - n.oy)
2319
+ };
2320
+ let v = P(g - m, _ - h), y = F(v);
2321
+ return y.translate(o - m, s - h), y.rotate(c), y.scale(l, u), y.drawImage(n.canvas, d, f), {
2322
+ canvas: v,
2323
+ x: m,
2324
+ y: h
2325
+ };
2326
+ }
2327
+ async imageContent(e, t) {
2328
+ let n = await this.loader.image(e.src);
2329
+ this.natural.set(e.src, {
2330
+ width: n.width,
2331
+ height: n.height
2332
+ });
2333
+ let { w: r, h: i } = ft(e, {
2334
+ width: n.width,
2335
+ height: n.height
2336
+ }), a = Math.max(1, Math.round(r * t)), o = Math.max(1, Math.round(i * t)), s = e.crop ?? {
2337
+ x: 0,
2338
+ y: 0,
2339
+ width: n.width,
2340
+ height: n.height
2341
+ }, c = P(a, o), l = F(c), u = e.fit ?? "fill", [d, f] = e.focus ?? [.5, .5];
2342
+ if (u === "fill") l.drawImage(n, s.x, s.y, s.width, s.height, 0, 0, a, o);
2343
+ else if (u === "cover") {
2344
+ let e = Math.max(a / s.width, o / s.height), t = a / e, r = o / e;
2345
+ l.drawImage(n, s.x + (s.width - t) * d, s.y + (s.height - r) * f, t, r, 0, 0, a, o);
2346
+ } else {
2347
+ let e = Math.min(a / s.width, o / s.height), t = s.width * e, r = s.height * e;
2348
+ l.drawImage(n, s.x, s.y, s.width, s.height, (a - t) * d, (o - r) * f, t, r);
2349
+ }
2350
+ return {
2351
+ canvas: c,
2352
+ ox: 0,
2353
+ oy: 0,
2354
+ w: a,
2355
+ h: o
2356
+ };
2357
+ }
2358
+ async family(e) {
2359
+ let t = e.font ?? "inter", n = _(t);
2360
+ if (n && this.loader.font) {
2361
+ let n = await this.loader.font(t, e.weight ?? 400, !!e.italic).catch(() => null);
2362
+ if (n) return n;
2363
+ }
2364
+ return n ? n.family : t;
2365
+ }
2366
+ maskPlane(e, i, a, o, s) {
2367
+ let c = (t) => {
2368
+ e.feather && ye(t, i, a, e.feather * o);
2369
+ let n = ut(e.density ?? 1);
2370
+ for (let r = 0; r < t.length; r++) {
2371
+ let i = e.invert ? 255 - t[r] : t[r];
2372
+ n < 1 && (i = 255 - (255 - i) * n), t[r] = i;
2373
+ }
2374
+ return t;
2375
+ };
2376
+ if (t(e)) return this.loader.image(e.src).then((e) => {
2377
+ let t = P(i, a);
2378
+ return F(t).drawImage(e, 0, 0, i, a), c(mt(t));
2379
+ });
2380
+ let l = P(i, a), u = F(l);
2381
+ if (n(e)) {
2382
+ u.fillStyle = "#fff", u.beginPath();
2383
+ let t = e.x * o, n = e.y * o, r = e.width * o, i = e.height * o;
2384
+ 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) : st(u, t, n, r, i, (e.radius ?? 0) * o), u.fill();
2385
+ } else r(e) && (u.fillStyle = Y(u, e.gradient, {
2386
+ x: 0,
2387
+ y: 0,
2388
+ w: i,
2389
+ h: a
2390
+ }), u.fillRect(0, 0, i, a));
2391
+ return c(mt(l));
2392
+ }
2393
+ async maskCanvasSpace(e, t, n, r) {
2394
+ return t.enabled === !1 || ht(e, await this.maskPlane(t, e.width, e.height, r, null)), e;
2395
+ }
2396
+ }, ut = (e) => e < 0 ? 0 : e > 1 ? 1 : e;
2397
+ function dt(e, t) {
2398
+ return t.has(e.id) ? !0 : e.type === "group" && (e.children ?? []).some((e) => dt(e, t));
2399
+ }
2400
+ function ft(e, t) {
2401
+ let n = e.crop ? {
2402
+ width: e.crop.width,
2403
+ height: e.crop.height
2404
+ } : t ?? {
2405
+ width: e.width ?? 1,
2406
+ height: e.height ?? 1
2407
+ };
2408
+ return e.width !== void 0 && e.height !== void 0 ? {
2409
+ w: e.width,
2410
+ h: e.height
2411
+ } : e.width === void 0 ? e.height === void 0 ? {
2412
+ w: n.width,
2413
+ h: n.height
2414
+ } : {
2415
+ w: e.height * n.width / n.height,
2416
+ h: e.height
2417
+ } : {
2418
+ w: e.width,
2419
+ h: e.width * n.height / n.width
2420
+ };
2421
+ }
2422
+ function pt(e, t, n) {
2423
+ if (!t?.some((e) => e && e.enabled !== !1)) return;
2424
+ let r = I(e);
2425
+ Xe(r, t, { scale: n }), Ae(e, r);
2426
+ }
2427
+ function mt(e) {
2428
+ let t = I(e).data, n = new Uint8ClampedArray(t.length / 4);
2429
+ 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;
2430
+ return n;
2431
+ }
2432
+ function ht(e, t) {
2433
+ let n = I(e), r = n.data;
2434
+ for (let e = 0, n = 3; e < t.length; e++, n += 4) r[n] = r[n] * t[e] / 255;
2435
+ Ae(e, n);
2436
+ }
2437
+ function gt(e, t) {
2438
+ let n = P(e.canvas.width, e.canvas.height), r = F(n);
2439
+ return r.drawImage(e.canvas, 0, 0), r.globalCompositeOperation = "destination-in", r.drawImage(t.canvas, t.x - e.x, t.y - e.y), {
2440
+ canvas: n,
2441
+ x: e.x,
2442
+ y: e.y
2443
+ };
2444
+ }
2445
+ function _t(e, t) {
2446
+ 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 = P(Math.max(1, n + a * 2), Math.max(1, r + a * 2)), s = F(o), c = {
2447
+ x: a,
2448
+ y: a,
2449
+ w: n,
2450
+ h: r
2451
+ };
2452
+ return s.beginPath(), vt(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()), {
2453
+ canvas: o,
2454
+ ox: a,
2455
+ oy: a,
2456
+ w: Math.max(n, 1),
2457
+ h: Math.max(r, 1)
2458
+ };
2459
+ }
2460
+ function vt(e, t, n, r) {
2461
+ let { x: i, y: a, w: o, h: s } = n;
2462
+ switch (t.shape) {
2463
+ case "ellipse":
2464
+ e.ellipse(i + o / 2, a + s / 2, o / 2, s / 2, 0, 0, Math.PI * 2);
2465
+ break;
2466
+ case "line":
2467
+ e.moveTo(i, a), e.lineTo(i + o, a + s);
2468
+ break;
2469
+ case "polygon":
2470
+ case "star": {
2471
+ 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;
2472
+ for (let n = 0; n < c; n++) {
2473
+ 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;
2474
+ n ? e.lineTo(d, f) : e.moveTo(d, f);
2475
+ }
2476
+ e.closePath();
2477
+ break;
2478
+ }
2479
+ default: st(e, i, a, o, s, (t.radius ?? 0) * r);
2480
+ }
2481
+ }
2482
+ function yt(e) {
2483
+ return typeof e == "string" && e.startsWith("library:");
2484
+ }
2485
+ function bt(e) {
2486
+ return e.slice(8);
2487
+ }
2488
+ function xt(e, t) {
2489
+ return e?.assets.find((e) => e.id === t);
2490
+ }
2491
+ // src/engine/loader.ts
2492
+ var St = (e, t) => `${e.replace(/\/?$/, "/")}${t.split("/").map(encodeURIComponent).join("/")}`;
2493
+ async function Ct(e) {
2494
+ let t = e.type.includes("svg");
2495
+ if (!t && typeof createImageBitmap == "function") try {
2496
+ return await createImageBitmap(e, { imageOrientation: "from-image" });
2497
+ } catch {}
2498
+ if (typeof Image > "u") throw Error(`Cannot decode ${e.type || "image"} here.`);
2499
+ let n = URL.createObjectURL(e);
2500
+ try {
2501
+ let e = new Image();
2502
+ return e.decoding = "async", e.src = n, await e.decode(), !t || e.naturalWidth && e.naturalHeight || (e.width = 512, e.height = 512), e;
2503
+ } finally {
2504
+ setTimeout(() => URL.revokeObjectURL(n), 3e4);
2505
+ }
2506
+ }
2507
+ function wt(e) {
2508
+ 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) => {
2509
+ if (yt(t)) {
2510
+ let r = xt(n, bt(t));
2511
+ if (!r?.path) throw Error(`Unknown library image "${t}".`);
2512
+ return St(e.libraryBase, r.path);
2513
+ }
2514
+ if (/^(blob:|data:)/.test(t)) return t;
2515
+ let r = e.resolve ? await e.resolve(t) : St(e.assetBase, t), a = i.get(t);
2516
+ return a ? `${r}${r.includes("?") ? "&" : "?"}v=${a}` : r;
2517
+ };
2518
+ return {
2519
+ image(e) {
2520
+ let n = r.get(e);
2521
+ return n || (n = (async () => {
2522
+ let n = await t(await o(e), { cache: "no-store" });
2523
+ if (!n.ok) throw Error(`${e}: HTTP ${n.status}`);
2524
+ return Ct(await n.blob());
2525
+ })(), n.catch(() => r.delete(e)), r.set(e, n)), n;
2526
+ },
2527
+ version: (e) => i.get(e) ?? 0,
2528
+ invalidate(e) {
2529
+ r.delete(e), i.set(e, (i.get(e) ?? 0) + 1);
2530
+ },
2531
+ setLibrary(e) {
2532
+ n = e;
2533
+ },
2534
+ font(t, r, i) {
2535
+ let o = _(t), s = xt(n, t);
2536
+ if (!o || !s?.files?.length || typeof FontFace > "u") return Promise.resolve(o?.family ?? null);
2537
+ 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);
2538
+ return f || (f = (async () => {
2539
+ let t = globalThis.document?.fonts ?? globalThis.fonts, n = l.filter((e) => e.weight === u);
2540
+ return await Promise.all(n.map(async (n) => {
2541
+ let i = new FontFace(o.family, `url(${St(e.libraryBase, n.path)}) format("woff2")`, {
2542
+ weight: String(r),
2543
+ style: c,
2544
+ ...n.unicodeRange ? { unicodeRange: n.unicodeRange } : {}
2545
+ });
2546
+ await i.load(), t?.add(i);
2547
+ })), o.family;
2548
+ })(), f.catch(() => a.delete(d)), a.set(d, f)), f;
2549
+ }
2550
+ };
2551
+ }
2552
+ // src/engine/index.ts
2553
+ var Tt = class {
2554
+ loader;
2555
+ compositor;
2556
+ constructor(e, t) {
2557
+ this.loader = t ?? wt(e), this.compositor = new lt(this.loader), e.ai && S(e.ai);
2558
+ }
2559
+ setLibrary(e) {
2560
+ this.loader.setLibrary?.(e);
2561
+ }
2562
+ render(e, t) {
2563
+ return this.compositor.render(e, t);
2564
+ }
2565
+ async exportImage(e, t, n = {}) {
2566
+ let r = await this.compositor.render(e, {
2567
+ ...n,
2568
+ scale: t.scale
2569
+ }), i = P(t.width, t.height), a = F(i);
2570
+ t.background && (a.fillStyle = t.background, a.fillRect(0, 0, t.width, t.height));
2571
+ let o = t.scale;
2572
+ 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), At(i, t.mime, t.quality);
2573
+ }
2574
+ async analyze(e, t = {}) {
2575
+ return Ee(I(t.layer ? await this.layerPixels(e, t.layer, {
2576
+ maxSide: t.maxSide ?? 1200,
2577
+ withFilters: !0
2578
+ }) : await this.render(e, { scale: Math.min(1, (t.maxSide ?? 1200) / Math.max(e.canvas.width, e.canvas.height)) })));
2579
+ }
2580
+ async layerPixels(t, n, r = {}) {
2581
+ let a = i(t.layers, n);
2582
+ if (!a) throw Error(`No layer "${n}".`);
2583
+ let o = a.layer, s = r.maxSide ?? 2048;
2584
+ if (!e(o)) {
2585
+ let e = Math.min(1, s / Math.max(t.canvas.width, t.canvas.height));
2586
+ return this.compositor.render({
2587
+ ...t,
2588
+ canvas: {
2589
+ ...t.canvas,
2590
+ background: null
2591
+ },
2592
+ layers: [Et(o, r.withFilters)]
2593
+ }, { scale: e });
2594
+ }
2595
+ let c = await this.compositor.layerBox(o);
2596
+ if (!c) throw Error(`Layer "${n}" has no size.`);
2597
+ let l = 1;
2598
+ if (o.type === "image") {
2599
+ let e = await this.compositor.naturalSize(o.src), t = o.crop ?? e;
2600
+ l = Math.max(t.width / c.width, t.height / c.height);
2601
+ }
2602
+ l = Math.min(l, s / Math.max(c.width, c.height));
2603
+ let u = {
2604
+ ...Et(o, r.withFilters),
2605
+ x: 0,
2606
+ y: 0,
2607
+ rotation: 0,
2608
+ flipX: !1,
2609
+ flipY: !1
2610
+ }, d = Math.max(1, Math.round(c.width * l)), f = Math.max(1, Math.round(c.height * l));
2611
+ return this.compositor.render({
2612
+ version: 1,
2613
+ id: "layer",
2614
+ canvas: {
2615
+ width: d / l,
2616
+ height: f / l
2617
+ },
2618
+ layers: [u]
2619
+ }, { scale: l });
2620
+ }
2621
+ async backgroundMask(e, t, n = {}) {
2622
+ let r = await this.layerPixels(e, t, {
2623
+ maxSide: 2048,
2624
+ withFilters: !1
2625
+ });
2626
+ return kt(Dt(await ne(r, n.model), r.width, r.height, n), r.width, r.height);
2627
+ }
2628
+ async segmentMask(e, t, n, r = {}) {
2629
+ let a = await this.layerPixels(e, t, {
2630
+ maxSide: 1600,
2631
+ withFilters: !1
2632
+ }), o = await this.compositor.layerBox(i(e.layers, t).layer), s = o ? a.width / o.width : 1;
2633
+ return kt(Dt(await re(a, {
2634
+ ...n.points ? { points: n.points.map(([e, t, n]) => [
2635
+ e * s,
2636
+ t * s,
2637
+ n
2638
+ ]) } : {},
2639
+ ...n.box ? { box: n.box.map((e) => e * s) } : {}
2640
+ }, r.model), a.width, a.height, { feather: r.feather ?? 1 }), a.width, a.height);
2641
+ }
2642
+ async colorRangeMask(e, t, n) {
2643
+ let r = I(await this.layerPixels(e, t, {
2644
+ maxSide: 2048,
2645
+ withFilters: !0
2646
+ })), i = F(P(1, 1));
2647
+ i.fillStyle = n.color, i.fillRect(0, 0, 1, 1);
2648
+ let [a, o, s] = i.getImageData(0, 0, 1, 1).data, c = (n.tolerance ?? 32) / 100 * 441, l = new Uint8ClampedArray(r.width * r.height);
2649
+ for (let e = 0, t = 0; e < l.length; e++, t += 4) {
2650
+ let n = Math.hypot(r.data[t] - a, r.data[t + 1] - o, r.data[t + 2] - s);
2651
+ l[e] = r.data[t + 3] < 8 ? 0 : n <= c ? 255 : n <= c * 1.25 ? 255 * (1 - (n - c) / (c * .25)) : 0;
2652
+ }
2653
+ return kt(Dt(l, r.width, r.height, { feather: n.feather }), r.width, r.height);
2654
+ }
2655
+ };
2656
+ function Et(e, t) {
2657
+ let { mask: n, effects: r, opacity: i, blend: a, clip: o, ...s } = e, c = {
2658
+ ...s,
2659
+ visible: !0
2660
+ };
2661
+ return !t && c.type !== "adjustment" && delete c.filters, c;
2662
+ }
2663
+ function Dt(e, t, n, r) {
2664
+ if (r.threshold !== void 0) {
2665
+ let t = Math.max(0, Math.min(255, r.threshold));
2666
+ for (let n = 0; n < e.length; n++) e[n] = e[n] >= t ? 255 : 0;
2667
+ }
2668
+ return r.feather && ye(e, t, n, r.feather), e;
2669
+ }
2670
+ function Ot(e, t, n) {
2671
+ let r = t, i = n, a = -1, o = -1;
2672
+ for (let s = 0; s < n; s++) {
2673
+ let n = s * t;
2674
+ 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);
2675
+ }
2676
+ return a < 0 ? null : {
2677
+ x: r,
2678
+ y: i,
2679
+ width: a - r + 1,
2680
+ height: o - i + 1
2681
+ };
2682
+ }
2683
+ async function kt(e, t, n) {
2684
+ let r = Ot(e, t, n), i = P(t, n), a = F(i);
2685
+ return a.fillStyle = "#000", a.fillRect(0, 0, t, n), a.drawImage(Ne(e, t, n), 0, 0), {
2686
+ ...await At(i, "image/png"),
2687
+ bbox: r
2688
+ };
2689
+ }
2690
+ async function At(e, t, n = 100) {
2691
+ let r = await Pe(e, t, t === "image/png" ? void 0 : n / 100);
2692
+ return {
2693
+ bytes: new Uint8Array(await r.arrayBuffer()),
2694
+ mime: r.type || t,
2695
+ width: e.width,
2696
+ height: e.height
2697
+ };
2698
+ }
2699
+ function jt(e) {
2700
+ let t = "", n = 32768;
2701
+ for (let r = 0; r < e.length; r += n) t += String.fromCharCode(...e.subarray(r, r + n));
2702
+ return btoa(t);
2703
+ }
2704
+ // src/engine/headless.ts
2705
+ var Z = (e) => ({
2706
+ base64: jt(e.bytes),
2707
+ mime: e.mime,
2708
+ width: e.width,
2709
+ height: e.height,
2710
+ ...e.bbox === void 0 ? {} : { bbox: e.bbox }
2711
+ }), Mt = null, Q = [], $ = () => {
2712
+ if (!Mt) throw Error("agentphoto.init() was not called.");
2713
+ return Mt;
2714
+ };
2715
+ globalThis.agentphoto = {
2716
+ version: 1,
2717
+ async init(e) {
2718
+ return Mt = new Tt({
2719
+ assetBase: e.assetBase,
2720
+ libraryBase: e.libraryBase,
2721
+ library: e.library,
2722
+ ai: e.ai
2723
+ }), !0;
2724
+ },
2725
+ async render(e, t = {}) {
2726
+ Q.length = 0;
2727
+ let n = t.scale ?? 1;
2728
+ return t.maxWidth && (n = Math.min(n, t.maxWidth / e.canvas.width)), t.maxHeight && (n = Math.min(n, t.maxHeight / e.canvas.height)), {
2729
+ ...Z(await At(await $().render(e, {
2730
+ scale: n,
2731
+ backdrop: t.backdrop,
2732
+ background: t.background,
2733
+ only: t.only ? new Set(t.only) : void 0,
2734
+ onError: (e, t) => Q.push({
2735
+ layer: e,
2736
+ message: t
2737
+ })
2738
+ }), t.format === "jpeg" ? "image/jpeg" : "image/png", t.quality ?? 88)),
2739
+ scale: n,
2740
+ errors: [...Q]
2741
+ };
2742
+ },
2743
+ async exportImage(e, t) {
2744
+ return Q.length = 0, {
2745
+ ...Z(await $().exportImage(e, t, { onError: (e, t) => Q.push({
2746
+ layer: e,
2747
+ message: t
2748
+ }) })),
2749
+ errors: [...Q]
2750
+ };
2751
+ },
2752
+ analyze(e, t = {}) {
2753
+ return $().analyze(e, t);
2754
+ },
2755
+ async backgroundMask(e, t, n = {}) {
2756
+ return Z(await $().backgroundMask(e, t, n));
2757
+ },
2758
+ async segmentMask(e, t, n, r = {}) {
2759
+ return Z(await $().segmentMask(e, t, n, r));
2760
+ },
2761
+ async colorRangeMask(e, t, n) {
2762
+ return Z(await $().colorRangeMask(e, t, n));
2763
+ },
2764
+ invalidate(e) {
2765
+ for (let t of e) $().loader.invalidate(t);
2766
+ return e.length;
2767
+ },
2768
+ async layerBoxes(e) {
2769
+ let t = {}, n = [];
2770
+ a(e.layers, (e) => void n.push(e));
2771
+ for (let e of n) {
2772
+ let n = await $().compositor.layerBox(e).catch(() => null);
2773
+ n && (t[e.id] = n);
2774
+ }
2775
+ return t;
2776
+ }
2777
+ };