@eightshift/ui-components 6.0.13 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/{Button-JRIu2BnS.js → Button-CFnNdpNZ.js} +9 -9
  2. package/dist/{Dialog-Dd1yqNus.js → Dialog-D0jMcN-a.js} +79 -60
  3. package/dist/{FieldError-DmVwL6Dj.js → FieldError-BPG0hKfB.js} +2 -2
  4. package/dist/{FocusScope-Dri1oBcH.js → FocusScope-BJhC1-1e.js} +6 -7
  5. package/dist/{Heading-eA6LXIKB.js → Heading-CY-_gt-U.js} +2 -2
  6. package/dist/{Input-Cuw9UbNb.js → Input-B4X6-x6r.js} +8 -8
  7. package/dist/{Label-DPWyf-gp.js → Label-BDlf9vIY.js} +3 -2
  8. package/dist/{List-CWheI3JH.js → List-CQFXnN4w.js} +1 -1
  9. package/dist/{ListBox-DT1sFY3e.js → ListBox-BaN0n5h3.js} +30 -28
  10. package/dist/{OverlayArrow-DVJTTfZM.js → OverlayArrow-Dy0qw7WL.js} +7 -7
  11. package/dist/{PortalProvider-CHPnqDSH.js → PortalProvider-BQ1X8vGX.js} +1 -1
  12. package/dist/{RadioGroup-Cp5cdBI_.js → RadioGroup-CjCAbUr4.js} +15 -15
  13. package/dist/{SearchField-CLhr5PGZ.js → SearchField-CafsA525.js} +12 -12
  14. package/dist/{SelectionManager-DbBiF5M8.js → SelectionManager-oojq6MOy.js} +38 -34
  15. package/dist/{SharedElementTransition-B_vnQ1uR.js → SharedElementTransition-CtoWSaF0.js} +1 -1
  16. package/dist/{Slider-CZV3HhHY.js → Slider-BIbaMdUE.js} +17 -16
  17. package/dist/{Text-Dae33gHp.js → Text-CjFEHSfr.js} +3 -2
  18. package/dist/{VisuallyHidden-eaCBtXhE.js → VisuallyHidden-CqnizvzQ.js} +2 -2
  19. package/dist/{animation-DY7CNkr6.js → animation-Dfl8uEb3.js} +2 -2
  20. package/dist/assets/style-admin.css +38 -54
  21. package/dist/assets/style-editor.css +38 -54
  22. package/dist/assets/style.css +38 -54
  23. package/dist/{color-swatch-CZj0jHZd.js → color-swatch-bUFkK7ox.js} +6 -6
  24. package/dist/components/base-control/base-control.js +1 -1
  25. package/dist/components/button/button.js +9 -9
  26. package/dist/components/checkbox/checkbox.js +10 -10
  27. package/dist/components/color-pickers/color-picker.js +1 -1
  28. package/dist/components/color-pickers/color-swatch.js +1 -1
  29. package/dist/components/color-pickers/gradient-editor.js +2 -2
  30. package/dist/components/color-pickers/solid-color-picker.js +27 -23
  31. package/dist/components/draggable/draggable-handle.js +1 -1
  32. package/dist/components/draggable/draggable.js +841 -633
  33. package/dist/components/draggable-list/draggable-list-item.js +1 -1
  34. package/dist/components/draggable-list/draggable-list.js +1 -1
  35. package/dist/components/expandable/expandable.js +10 -10
  36. package/dist/components/index.js +4 -2
  37. package/dist/components/input-field/input-field.js +10 -10
  38. package/dist/components/link-input/link-input.js +24 -23
  39. package/dist/components/matrix-align/matrix-align.js +1 -1
  40. package/dist/components/menu/menu.js +1 -1
  41. package/dist/components/modal/modal.js +21 -22
  42. package/dist/components/number-picker/number-picker.js +11 -11
  43. package/dist/components/options-panel/options-panel.js +1 -1
  44. package/dist/components/placeholders/file-picker-shell.js +49 -44
  45. package/dist/components/popover/popover.js +1 -1
  46. package/dist/components/portal-provider/portal-provider.js +1 -1
  47. package/dist/components/radio/radio.js +2 -2
  48. package/dist/components/repeater/repeater.js +1 -1
  49. package/dist/components/responsive/mini-responsive.js +1 -1
  50. package/dist/components/select/async-multi-select.js +53 -32
  51. package/dist/components/select/async-select.js +8 -8
  52. package/dist/components/select/multi-select.js +9 -9
  53. package/dist/components/select/shared.js +4 -4
  54. package/dist/components/select/single-select.js +9 -9
  55. package/dist/components/slider/column-config-slider.js +3 -3
  56. package/dist/components/slider/slider.js +3 -3
  57. package/dist/components/smart-image/image-analysis-worker-next.js +144 -0
  58. package/dist/components/smart-image/smart-image-next.js +294 -0
  59. package/dist/components/smart-image/smart-image.js +2 -2
  60. package/dist/components/smart-image/worker-inline.js +1 -1
  61. package/dist/components/tabs/tabs.js +17 -16
  62. package/dist/components/toggle/switch.js +7 -7
  63. package/dist/components/toggle/toggle.js +1 -1
  64. package/dist/components/toggle-button/toggle-button.js +10 -7
  65. package/dist/components/tooltip/tooltip.js +8 -8
  66. package/dist/{context-DYYO3Ns3.js → context-iUFQCK8m.js} +1 -1
  67. package/dist/{general-C8Q0dvEx.js → general-BfKmjm56.js} +3 -4
  68. package/dist/icons/icons.js +2 -2
  69. package/dist/icons/jsx-svg.js +1 -1
  70. package/dist/{index-sSixe2j_.js → index-BL5gdWX4.js} +52 -52
  71. package/dist/index.js +3 -1
  72. package/dist/{proxy-B_RaYTfe.js → proxy-DFlYXk07.js} +320 -82
  73. package/dist/{react-jsx-parser.min-B_hvYYa1.js → react-jsx-parser.min-DAh4myol.js} +35 -35
  74. package/dist/{shared-Bg9lx3pE.js → shared-CMLCUova.js} +29 -26
  75. package/dist/{textSelection-Cq_Br7RW.js → textSelection-CeoEP4rL.js} +1 -1
  76. package/dist/{useButton-CeuyDay5.js → useButton-5YL_nmpZ.js} +3 -3
  77. package/dist/{useEvent-DoWvho2u.js → useEvent-Zze2g7CX.js} +1 -1
  78. package/dist/{useFilter-DYtfYPua.js → useFilter-8S94U4xM.js} +1 -1
  79. package/dist/{useFocusRing-WEswknAY.js → useFocusRing-rUOwLdTK.js} +10 -5
  80. package/dist/{useFormReset-BDF1K4E4.js → useFormReset-BxtOoO5Q.js} +1 -1
  81. package/dist/{useFormValidation-Dqzjv4jX.js → useFormValidation-DTmPrTD8.js} +3 -3
  82. package/dist/{useHover-CG39Ci3A.js → useHover-CmyvqeWX.js} +18 -17
  83. package/dist/{useLabel--3fT2XKM.js → useLabel-DzXzKZZZ.js} +2 -2
  84. package/dist/{useLabels-vzdDMGCX.js → useLabels-D8O3gOdV.js} +1 -1
  85. package/dist/{useListState-Bya9g7W8.js → useListState-B22CApJO.js} +1 -1
  86. package/dist/{useLocalizedStringFormatter-M3L6Ge2c.js → useLocalizedStringFormatter-CEDs0LsA.js} +1 -1
  87. package/dist/{useNumberField-D6lsi3Vu.js → useNumberField-CTkI-U9a.js} +50 -40
  88. package/dist/{useNumberFormatter-BWOyCamK.js → useNumberFormatter-CG_IQXp9.js} +1 -1
  89. package/dist/{usePress-B9w0X4Ur.js → usePress-CNefMs8d.js} +14 -8
  90. package/dist/{useSingleSelectListState-D9SqGLJ0.js → useSingleSelectListState-CDZGQDLC.js} +2 -2
  91. package/dist/{useToggle-Deq2xxQV.js → useToggle-CFFOmZWi.js} +4 -4
  92. package/dist/{useToggleState-j3o1PvdS.js → useToggleState-BWrKKisg.js} +1 -1
  93. package/dist/utilities/general.js +1 -1
  94. package/dist/utilities/index.js +1 -1
  95. package/dist/{utils-HC9_3Crc.js → utils-Cr3pLd9c.js} +77 -38
  96. package/dist/workers/image-analysis.worker.js +1 -1
  97. package/package.json +17 -17
@@ -0,0 +1,294 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { _ as __ } from "../../default-i18n-CnQeC5Pl.js";
3
+ import { c as clsx } from "../../clsx-DgYk2OaC.js";
4
+ import { useState, useRef, useEffect, cloneElement } from "react";
5
+ import { icons } from "../../icons/icons.js";
6
+ import "../../react-jsx-parser.min-DAh4myol.js";
7
+ import { DecorativeTooltip } from "../tooltip/tooltip.js";
8
+ import { cyrb64Hash } from "../../utilities/hash.js";
9
+ const WORKER_CODE = "const getSaturation = (r, g, b) => {\n // Convert 0-255 to 0-1 range.\n const red = r / 255;\n const green = g / 255;\n const blue = b / 255;\n\n const max = Math.max(red, green, blue);\n const min = Math.min(red, green, blue);\n const delta = max - min;\n\n // If the maximum brightness is less than ~5% (approx RGB 13),\n // the human eye just sees \"black\", regardless of the color math.\n if (max < 0.05) {\n return 0;\n }\n\n // Standard HSV Calculation\n let saturation = 0;\n\n if (max !== 0) {\n saturation = delta / max;\n }\n\n return parseFloat(saturation.toFixed(3));\n};\n\n// Helper to convert RGB to Hex\nconst rgbToHex = (r, g, b) => '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();\n\nself.onmessage = (e) => {\n const { buffer, width, height, config } = e.data;\n const { maxColors = 5, threshold = 96, transparencyThreshold = 255 } = config;\n const stride = 4;\n\n // [1] Check transparency.\n const isTransparent = (idx) => buffer[idx + 3] < transparencyThreshold;\n const getIdx = (x, y) => (y * width + x) * stride;\n\n const corners = {\n topLeft: isTransparent(getIdx(0, 0)),\n topRight: isTransparent(getIdx(width - 1, 0)),\n bottomLeft: isTransparent(getIdx(0, height - 1)),\n bottomRight: isTransparent(getIdx(width - 1, height - 1)),\n };\n\n const sides = { top: false, bottom: false, left: false, right: false };\n\n // Scan top/bottom.\n for (let x = 0; x < width; x += 5) {\n if (!sides.top && isTransparent(getIdx(x, 0))) {\n sides.top = true;\n }\n\n if (!sides.bottom && isTransparent(getIdx(x, height - 1))) {\n sides.bottom = true;\n }\n }\n\n // Scan left/right.\n for (let y = 0; y < height; y += 5) {\n if (!sides.left && isTransparent(getIdx(0, y))) {\n sides.left = true;\n }\n\n if (!sides.right && isTransparent(getIdx(width - 1, y))) {\n sides.right = true;\n }\n }\n\n // Internal transparency check\n let internalTransparent = false;\n const borderIsSolid = !Object.values(sides).some((v) => v);\n\n if (borderIsSolid) {\n const len = buffer.length;\n const step = Math.floor(len / 100);\n\n for (let i = 0; i < len; i += step) {\n const idx = i - (i % 4);\n\n if (buffer[idx + 3] < 255) {\n internalTransparent = true;\n break;\n }\n }\n } else {\n internalTransparent = true;\n }\n\n // [2] Analyze colors (Dominant + average)\n const colorCounts = {};\n const samplingRate = 20;\n let totalSampledPixels = 0;\n\n // Accumulators for Average Color\n let sumR = 0;\n let sumG = 0;\n let sumB = 0;\n\n for (let i = 0; i < buffer.length; i += stride * samplingRate) {\n const rRaw = buffer[i];\n const gRaw = buffer[i + 1];\n const bRaw = buffer[i + 2];\n const a = buffer[i + 3];\n\n // Strict alpha check (ignores anti-aliased SVG edges)\n if (a < 250) continue;\n\n totalSampledPixels++;\n\n // 1. Add to Average Sums (Use raw values for accuracy)\n sumR += rRaw;\n sumG += gRaw;\n sumB += bRaw;\n\n // 2. Add to Dominant Color Buckets (Quantized)\n const q = 5;\n const r = Math.round(rRaw / q) * q;\n const g = Math.round(gRaw / q) * q;\n const b = Math.round(bRaw / q) * q;\n\n const key = `${r},${g},${b}`;\n colorCounts[key] = (colorCounts[key] || 0) + 1;\n }\n\n // [3] Calculate Average Color\n let averageColor = null;\n\n if (totalSampledPixels > 0) {\n const avgR = Math.round(sumR / totalSampledPixels);\n const avgG = Math.round(sumG / totalSampledPixels);\n const avgB = Math.round(sumB / totalSampledPixels);\n const avgLum = 0.2126 * avgR + 0.7152 * avgG + 0.0722 * avgB;\n\n averageColor = {\n color: rgbToHex(avgR, avgG, avgB),\n isDark: avgLum <= 128,\n saturation: getSaturation(avgR, avgG, avgB),\n };\n }\n\n // [4] Process Dominant Colors\n const sortedRawColors = Object.entries(colorCounts)\n .map(([key, count]) => {\n const [r, g, b] = key.split(',').map(Number);\n\n return { r, g, b, count };\n })\n .sort((a, b) => b.count - a.count);\n\n const distinctPalette = [];\n\n for (const candidate of sortedRawColors) {\n if (distinctPalette.length >= maxColors) break;\n\n let isSimilar = false;\n\n for (const existing of distinctPalette) {\n const dist = Math.sqrt(Math.pow(candidate.r - existing.r, 2) + Math.pow(candidate.g - existing.g, 2) + Math.pow(candidate.b - existing.b, 2));\n\n if (dist < threshold) {\n existing.count += candidate.count;\n isSimilar = true;\n break;\n }\n }\n\n if (!isSimilar) {\n distinctPalette.push({ ...candidate });\n }\n }\n\n const palette = distinctPalette.map((item) => {\n const percentage = parseFloat((item.count / totalSampledPixels).toFixed(3));\n const lum = 0.2126 * item.r + 0.7152 * item.g + 0.0722 * item.b;\n\n return {\n color: rgbToHex(item.r, item.g, item.b),\n area: percentage,\n isDark: lum <= 128,\n saturation: getSaturation(item.r, item.g, item.b),\n };\n });\n\n self.postMessage({\n dominantColors: palette,\n averageColor,\n isDark: palette[0]?.isDark || false,\n isTransparent: internalTransparent || Object.values(corners).some((v) => v) || Object.values(sides).some((v) => v),\n transparencyInfo: {\n any: internalTransparent,\n left: sides.left,\n right: sides.right,\n top: sides.top,\n bottom: sides.bottom,\n topLeftCorner: corners.topLeft,\n topRightCorner: corners.topRight,\n bottomLeftCorner: corners.bottomLeft,\n bottomRightCorner: corners.bottomRight,\n },\n });\n};\n";
10
+ /**
11
+ * @typedef {Object} CustomImageProps
12
+ * @property {JSX.Element} [props.renderError] - Component to render if image analysis fails. `(error) => JSX:Element`.
13
+ * @property {string} [props.errorClassName] - Classes to pass to the default error view.
14
+ * @property {string} [props.processingClassName] - Classes to apply while the image is loading / being processed.
15
+ * @property {boolean} [props.hidden] - If `true`, the component is not rendered.
16
+ * @property {boolean} [props.verbose] - If `true`, extra debug info is logged in case of errors.
17
+ * @property {import('../../utilities/general.js').ImageAnalysisSettings} [imageAnalysisSettings] - Settings to pass to the image analysis function.
18
+ * @property {import('../../utilities/general.js').ImageAnalysisResult} [analysisData] - Previous analysis result to pass in directly, skipping analysis.
19
+ *
20
+ * @preserve
21
+ */
22
+ /**
23
+ * @typedef {Omit<JSX.IntrinsicElements['img'], 'crossOrigin'>} BaseImageProps
24
+ *
25
+ * @preserve
26
+ */
27
+ /**
28
+ * @typedef {CustomImageProps & BaseImageProps} ImageProps
29
+ *
30
+ * @preserve
31
+ */
32
+ function isValidUrl(url) {
33
+ try {
34
+ new URL(url);
35
+ return true;
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+ async function urlExists(url) {
41
+ if (!isValidUrl(url)) return false;
42
+ try {
43
+ await fetch(url, { method: "HEAD", mode: "no-cors" });
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+ /**
50
+ * Image that analyzes its contents and can apply different classes based on image transparency.
51
+ * It also provides a CSS variable with the image's dominant color, and optionally custom child rendering with all the data exposed.
52
+ *
53
+ * @component
54
+ * @param {ImageProps} props - Component props.
55
+ *
56
+ * @returns {JSX.Element} The __SmartImageNext component.
57
+ *
58
+ * @example
59
+ * <__SmartImageNext src='https://picsum.photos/600/400' />
60
+ *
61
+ * @example
62
+ * <__SmartImageNext src='https://picsum.photos/600/400'>
63
+ * {({ image, dominantColors, isDark }) => (
64
+ * <div style={{ backgroundColor: dominantColors[0].color }}>
65
+ * {image}
66
+ * <p style={{ color: isDark ? '#000000' : '#FFFFFF' }}>Lorem ipsum</p>
67
+ * </div>
68
+ * )}
69
+ * </__SmartImageNext>
70
+ *
71
+ * @preserve
72
+ */
73
+ const __SmartImageNext = (props) => {
74
+ const { onAnalysisComplete, colorCount = 3, similarityThreshold = 10 } = props;
75
+ const { imageAnalysisSettings, errorClassName, processingClassName = "es:opacity-0 es:fixed", hidden, renderError, analysisData, children, verbose, ...imageProps } = props;
76
+ const { src } = imageProps;
77
+ const [analysis, setAnalysis] = useState(analysisData);
78
+ const [error, setError] = useState(null);
79
+ const [objectUrl, setObjectUrl] = useState(null);
80
+ const workerRef = useRef(null);
81
+ useEffect(() => {
82
+ const blob = new Blob([WORKER_CODE], { type: "application/javascript" });
83
+ workerRef.current = new Worker(URL.createObjectURL(blob));
84
+ return () => workerRef.current.terminate();
85
+ }, []);
86
+ useEffect(() => {
87
+ if (!src) {
88
+ return;
89
+ }
90
+ if (analysisData) {
91
+ setObjectUrl(src);
92
+ return;
93
+ }
94
+ const cacheKey = `es-uic-img-data-${cyrb64Hash(src)}`;
95
+ if (localStorage?.getItem(cacheKey)) {
96
+ const cachedAnalysis = JSON.parse(localStorage.getItem(cacheKey));
97
+ if (cachedAnalysis) {
98
+ setAnalysis(cachedAnalysis);
99
+ setObjectUrl(src);
100
+ return;
101
+ }
102
+ }
103
+ let isActive = true;
104
+ const abortController = new AbortController();
105
+ const processImage = async () => {
106
+ try {
107
+ const response = await fetch(src, {
108
+ signal: abortController.signal,
109
+ mode: "cors"
110
+ });
111
+ if (src.includes("uikit")) {
112
+ console.log("tusam?", src, response);
113
+ }
114
+ if (!response.ok) {
115
+ if (verbose) {
116
+ console.error(`[SmartImageNext]: Failed to fetch (${response.status}) image from ${src}`);
117
+ }
118
+ }
119
+ const blob = await response.clone().blob();
120
+ if (blob.size === 0) {
121
+ if (verbose) {
122
+ console.error(`[SmartImageNext]: Empty image (${src})`);
123
+ }
124
+ }
125
+ const url = URL.createObjectURL(blob);
126
+ if (isActive) {
127
+ setObjectUrl(url);
128
+ }
129
+ let imageSource, width, height;
130
+ const isSVG = blob.type.includes("svg");
131
+ if (isSVG) {
132
+ const img = new Image();
133
+ img.src = url;
134
+ await new Promise((resolve, reject) => {
135
+ img.onload = resolve;
136
+ img.onerror = reject;
137
+ });
138
+ width = img.width || 500;
139
+ height = img.height || 500;
140
+ imageSource = img;
141
+ } else {
142
+ try {
143
+ imageSource = await createImageBitmap(blob);
144
+ width = imageSource.width;
145
+ height = imageSource.height;
146
+ } catch (e) {
147
+ if (verbose) {
148
+ console.warn("[SmartImageNext]: createImageBitmap failed, falling back to HTML Image method.", e);
149
+ }
150
+ }
151
+ }
152
+ let buffer, arrayBuffer;
153
+ if (typeof OffscreenCanvas !== "undefined") {
154
+ const canvas = new OffscreenCanvas(width, height);
155
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
156
+ ctx.clearRect(0, 0, width, height);
157
+ ctx.drawImage(imageSource, 0, 0, width, height);
158
+ buffer = ctx.getImageData(0, 0, width, height).data;
159
+ arrayBuffer = buffer.buffer;
160
+ } else {
161
+ const canvas = document.createElement("canvas");
162
+ canvas.width = width;
163
+ canvas.height = height;
164
+ const ctx = canvas.getContext("2d");
165
+ ctx.clearRect(0, 0, width, height);
166
+ ctx.drawImage(imageSource, 0, 0, width, height);
167
+ buffer = ctx.getImageData(0, 0, width, height).data;
168
+ arrayBuffer = buffer.buffer;
169
+ }
170
+ if (imageSource.close) {
171
+ imageSource.close();
172
+ }
173
+ if (workerRef.current) {
174
+ workerRef.current.onmessage = (e) => {
175
+ if (!isActive) {
176
+ return;
177
+ }
178
+ setAnalysis(e.data);
179
+ localStorage?.setItem(cacheKey, JSON.stringify(e.data));
180
+ if (onAnalysisComplete) {
181
+ onAnalysisComplete(e.data);
182
+ }
183
+ };
184
+ try {
185
+ workerRef.current.postMessage(
186
+ {
187
+ buffer,
188
+ width,
189
+ height,
190
+ config: {
191
+ // TODO
192
+ }
193
+ },
194
+ [arrayBuffer]
195
+ );
196
+ } catch (msgErr) {
197
+ workerRef.current.postMessage({
198
+ buffer,
199
+ width,
200
+ height,
201
+ config: { maxColors: colorCount, threshold: similarityThreshold }
202
+ });
203
+ }
204
+ }
205
+ } catch (err) {
206
+ if (isActive) {
207
+ if (verbose) {
208
+ console.error("[SmartImageNext] Error:", err);
209
+ }
210
+ const exists = await urlExists(src);
211
+ if (exists) {
212
+ setError(err.message);
213
+ } else {
214
+ setError("failedToFetch");
215
+ }
216
+ setObjectUrl(null);
217
+ }
218
+ }
219
+ };
220
+ processImage();
221
+ return () => {
222
+ isActive = false;
223
+ abortController.abort();
224
+ };
225
+ }, [src, colorCount, similarityThreshold]);
226
+ const hasAnalysed = Boolean(analysis) && Boolean(objectUrl);
227
+ const { dominantColors, isDark, isTransparent, transparencyInfo, averageColor } = analysis || {};
228
+ const classFetchProps = {
229
+ isLoaded: true,
230
+ dominantColors,
231
+ isDark,
232
+ hasAnalysed: Boolean(error) || hasAnalysed,
233
+ isTransparent,
234
+ transparencyInfo,
235
+ averageColor,
236
+ hasError: error === "failedToFetch"
237
+ };
238
+ if (hidden) {
239
+ return null;
240
+ }
241
+ const colorfulDominantColor = dominantColors?.find((c) => c.saturation > 0.25 && c.area >= 0.1) || dominantColors?.[0];
242
+ const imageElement = /* @__PURE__ */ jsx(
243
+ "img",
244
+ {
245
+ decoding: "async",
246
+ ...imageProps,
247
+ src: analysis && objectUrl && !error ? objectUrl : imageProps?.src,
248
+ style: {
249
+ ...imageProps.style || {},
250
+ "--es-img-dominant-color": dominantColors?.[0]?.color ?? "",
251
+ "--es-img-colorful-dominant-color": colorfulDominantColor?.color ?? "",
252
+ "--es-img-average-color": averageColor?.color ?? ""
253
+ },
254
+ className: clsx(
255
+ "es:transition-opacity",
256
+ !hasAnalysed && !error && processingClassName,
257
+ typeof imageProps.className === "function" ? imageProps.className(classFetchProps) : imageProps.className
258
+ ),
259
+ "data-is-transparent": isTransparent,
260
+ "data-is-dark": isDark
261
+ }
262
+ );
263
+ if (error && renderError) {
264
+ return renderError(error);
265
+ } else if (error === "failedToFetch") {
266
+ return /* @__PURE__ */ jsxs(
267
+ "div",
268
+ {
269
+ className: clsx(
270
+ typeof children !== "function" && "es:flex es:flex-col es:gap-2 es:items-center-safe es:justify-center-safe es:p-2",
271
+ "es:motion-preset-fade",
272
+ errorClassName
273
+ ),
274
+ children: [
275
+ typeof children !== "function" && /* @__PURE__ */ jsx(DecorativeTooltip, { text: __("Error loading image", "eightshift-ui-components"), children: cloneElement(icons.imageError, { className: "es:text-surface-600 es:size-8" }) }),
276
+ typeof children === "function" ? children({
277
+ image: cloneElement(imageElement, { crossOrigin: null }),
278
+ hasAnalysed,
279
+ isTransparent: false,
280
+ hasError: true,
281
+ errorBadge: /* @__PURE__ */ jsx("div", { className: "es:size-full es:flex es:items-center es:justify-center", children: /* @__PURE__ */ jsx(DecorativeTooltip, { text: __("Error loading image", "eightshift-ui-components"), children: cloneElement(icons.imageError, { className: "es:text-surface-600 es:size-8" }) }) })
282
+ }) : cloneElement(imageElement, { crossOrigin: null })
283
+ ]
284
+ }
285
+ );
286
+ }
287
+ return children && typeof children === "function" ? children({
288
+ image: imageElement,
289
+ ...classFetchProps
290
+ }) : imageElement;
291
+ };
292
+ export {
293
+ __SmartImageNext
294
+ };
@@ -3,12 +3,12 @@ import { _ as __ } from "../../default-i18n-CnQeC5Pl.js";
3
3
  import { c as clsx } from "../../clsx-DgYk2OaC.js";
4
4
  import { useState, useRef, useEffect, cloneElement } from "react";
5
5
  import { icons } from "../../icons/icons.js";
6
- import "../../react-jsx-parser.min-B_hvYYa1.js";
6
+ import "../../react-jsx-parser.min-DAh4myol.js";
7
7
  import { DecorativeTooltip } from "../tooltip/tooltip.js";
8
8
  import { useImageAnalysisWorker } from "../../utilities/web-workers.js";
9
9
  import workerInline from "./worker-inline.js";
10
10
  import { cyrb64Hash } from "../../utilities/hash.js";
11
- import { b as analyzeImage } from "../../general-C8Q0dvEx.js";
11
+ import { b as analyzeImage } from "../../general-BfKmjm56.js";
12
12
  /**
13
13
  * @typedef {Object} CustomImageProps
14
14
  * @property {JSX.Element} [props.renderError] - Component to render if image analysis fails. `(error) => JSX:Element`.
@@ -1,4 +1,4 @@
1
- const workerInline = '(function(){"use strict";var w=(t=>(t[t.ALPHA=0]="ALPHA",t[t.BLUE=1]="BLUE",t[t.GREEN=2]="GREEN",t[t.RED=3]="RED",t))(w||{});const $e=["rotateCW","rotate180","rotateCCW"],Pn=(t,e=t,n,r={})=>{const s=document.createElement("canvas");return Ln(s,t,e,r.dpr),r.pixelated&&(s.style.imageRendering="pixelated"),{canvas:s,ctx:s.getContext("2d",r.ctx)}},jn=(t,e=t,n,r)=>Pn(t,e,n,{dpr:1,...r}),Ln=(t,e,n,r=window.devicePixelRatio||1)=>(r!==1&&(t.style.width=`${e}px`,t.style.height=`${n}px`),t.dataset.origWidth=String(e),t.dataset.origHeight=String(n),t.dataset.dpr=String(r),t.width=e*r,t.height=n*r,r),q=t=>typeof t=="number";function Hn(t,e,n,r){let s,i;if(q(t)){const c=jn(t,e,n,r);s=c.canvas,i=c.ctx}else s=t,i=s.getContext("2d");const a=i.getImageData(0,0,s.width,s.height),o=new Uint32Array(a.data.buffer);return{canvas:s,ctx:i,img:a,data:o}}const rt=(t,e,n)=>{n.configurable=!1},st=(t,e={})=>{const n=Reflect.ownKeys(t),r=Reflect.ownKeys(e),s=Symbol("isa");function i(a){for(const o of n){const c=Object.getOwnPropertyDescriptor(a.prototype,o);(!c||c.configurable)&&Object.defineProperty(a.prototype,o,{value:t[o],writable:!0})}return Object.defineProperty(a.prototype,s,{value:!0}),a}for(const a of r)Object.defineProperty(i,a,{value:e[a],enumerable:e.propertyIsEnumerable(a)});return Object.defineProperty(i,Symbol.hasInstance,{value:a=>!!a[s]}),i};st({order(){return[0]},includes(t){return t>=0&&t<this.size[0]},indexAt(t){return this.includes(t)?this.indexAtUnsafe(t):-1},indexAtUnsafe(t){return this.offset+(t|0)*this.stride[0]},getAt(t){return this.includes(t)?this.data[this.indexAtUnsafe(t)]:0},getAtUnsafe(t){return this.data[this.indexAtUnsafe(t)]},setAt(t,e){return this.includes(t)?(this.data[this.indexAtUnsafe(t)]=e,!0):!1},setAtUnsafe(t,e){return this.data[this.indexAtUnsafe(t)]=e,!0}});const Ce=st({order(){return Math.abs(this.stride[1])>Math.abs(this.stride[0])?[1,0]:[0,1]},includes(t,e){const n=this.size;return t>=0&&t<n[0]&&e>=0&&e<n[1]},indexAt(t,e){return this.includes(t,e)?this.indexAtUnsafe(t,e):-1},indexAtUnsafe(t,e){return this.offset+(t|0)*this.stride[0]+(e|0)*this.stride[1]},getAt(t,e){return this.includes(t,e)?this.data[this.indexAtUnsafe(t,e)]:0},getAtUnsafe(t,e){return this.data[this.indexAtUnsafe(t,e)]},setAt(t,e,n){return this.includes(t,e)?(this.data[this.indexAtUnsafe(t,e)]=n,!0):!1},setAtUnsafe(t,e,n){return this.data[this.indexAtUnsafe(t,e)]=n,!0}});st({order(){return Se(this.stride)},includes(t,e,n){const r=this.size;return t>=0&&t<r[0]&&e>=0&&e<r[1]&&n>=0&&n<r[2]},indexAt(t,e,n){return this.includes(t,e,n)?this.indexAtUnsafe(t,e,n):-1},indexAtUnsafe(t,e,n){const r=this.stride;return this.offset+(t|0)*r[0]+(e|0)*r[1]+(n|0)*r[2]},getAt(t,e,n){return this.includes(t,e,n)?this.data[this.indexAtUnsafe(t,e,n)]:0},getAtUnsafe(t,e,n){return this.data[this.indexAtUnsafe(t,e,n)]},setAt(t,e,n,r){return this.includes(t,e,n)?(this.data[this.indexAtUnsafe(t,e,n)]=r,!0):!1},setAtUnsafe(t,e,n,r){return this.data[this.indexAtUnsafe(t,e,n)]=r,!0}}),st({order(){return Se(this.stride)},includes(t,e,n,r){const s=this.size;return t>=0&&t<s[0]&&e>=0&&e<s[1]&&n>=0&&n<s[2]&&r>=0&&r<s[3]},indexAt(t,e,n,r){return this.includes(t,e,n,r)?this.indexAtUnsafe(t,e,n,r):-1},indexAtUnsafe(t,e,n,r){const s=this.stride;return this.offset+(t|0)*s[0]+(e|0)*s[1]+(n|0)*s[2]+(r|0)*s[3]},getAt(t,e,n,r){return this.includes(t,e,n,r)?this.data[this.indexAtUnsafe(t,e,n,r)]:0},getAtUnsafe(t,e,n,r){return this.data[this.indexAtUnsafe(t,e,n,r)]},setAt(t,e,n,r,s){return this.includes(t,e,n,r)?(this.data[this.indexAtUnsafe(t,e,n,r)]=s,!0):!1},setAtUnsafe(t,e,n,r,s){return this.data[this.indexAtUnsafe(t,e,n,r)]=s,!0}});const Se=t=>[...t].map((e,n)=>[e,n]).sort((e,n)=>Math.abs(n[0])-Math.abs(e[0])).map(e=>e[1]),P=t=>typeof t=="string",ot=(t,e=n=>n!==void 0?": "+n:"")=>class extends Error{origMessage;constructor(n){super(t(n)+e(n)),this.origMessage=n!==void 0?String(n):""}},Wn={};var ve={};const Yn=ot(()=>"Assertion failed"),_=(typeof process<"u"&&ve!==void 0?ve.UMBRELLA_ASSERTS:!Wn)?(t,e)=>{if(typeof t=="function"&&!t()||!t)throw new Yn(typeof e=="function"?e():e)}:()=>{},B=(t,e,n)=>t<e?e:t>n?n:t,y=t=>t<0?0:t>1?1:t,Be=(t,e,n,r,s)=>(t[0]=e,t[1]=n,t[2]=r,t[3]=s,t),Vn=(t,e)=>{const n=e[3];return Be(e,e[0]*n,e[1]*n,e[2]*n,n)},Xn=t=>{const e=(t>>>24)/255;return t&4278190080|(t>>>16&255)*e<<16|(t>>>8&255)*e<<8|(t&255)*e},Kn=(t,e)=>{const n=e[3];return n>0?Be(e,e[0]/n,e[1]/n,e[2]/n,n):e},Zn=t=>{const e=(t>>>24)/255;return e>0?(t&4278190080|Math.min(255,(t>>>16&255)/e)<<16|Math.min(255,(t>>>8&255)/e)<<8|Math.min(255,(t&255)/e))>>>0:t},Jn=t=>{const e=t[3];return t[0]<=e&&t[1]<=e||t[2]<=e},Qn=t=>{const e=t>>>24;return(t>>>16&255)<=e&&(t>>>8&255)<=e&&(t&255)<=e},ke=(t,e,n,r=1)=>_(t.length>=e*n*r,"pixel buffer too small"),Ge=(t,e,n)=>t?(Mt(t,e,n),t):new ImageData(e,n),Mt=(t,e,n)=>_(t.width===e&&t.height===n,"imagedata has wrong dimensions"),O=(t,e)=>{const n=t.channels[e];return _(n!=null,`invalid channel ID: ${e}`),n},tr=t=>_(!!t.alpha,"missing alpha channel"),it=t=>t,It=t=>((t>>>16&255)*29+(t>>>8&255)*150+(t&255)*76)/255,at=(t,e,n,r,s,i,a=0,o=0)=>(t|=0,e|=0,n|=0,r|=0,t<0&&(n+=t,a-=t,t=0),e<0&&(r+=e,o-=e,e=0),[t,e,B(n,0,s-t),B(r,0,i-e),a,o]),ct=(t,e,n={})=>{const r=t.width,s=e.width;let i,a,o,c,l,h;return[i,a,l,h]=at(n.sx||0,n.sy||0,n.w||r,n.h||t.height,r,t.height),[o,c,l,h,i,a]=at(n.dx||0,n.dy||0,l,h,s,e.height,i,a),{sx:i,sy:a,dx:o,dy:c,rw:l,rh:h}},er=(t,e,n)=>{for(let r=t.length;r-- >0;)t[r]=n(t[r],e)},nr=(t,e,n,r)=>{for(let s=t.length;s-- >0;)t[s]=r(t[s],n(e[s]))},rr=(t,e,n,r,s)=>{const i=~s;for(let a=t.length;a-- >0;)t[a]=t[a]&i|n(r(e[a]))&s},Me=(t,e,n)=>{const r=e.fromABGR,s=e.toABGR;for(let i=t.length;i-- >0;)t[i]=r(n(s(t[i])))},Ie=(t,e,n={})=>(e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):e).putImageData(t.toImageData(n.data),n.x||0,n.y||0),lt=t=>{const e=t.channels,n=e.reduce((a,o)=>(a[o]=3-o<<3,a),{}),r={...t,__float:!0,size:e.length,shift:n,range:[0,1],normalized:y,fromNormalized:it};if(t.convert)return Object.assign(r,t.convert),r;const s=(a,o)=>(y(a[o])*255+.5|0)<<n[e[o]],i=(a,o)=>(a>>>n[e[o]]&255)/255;switch(e.length){case 1:t.gray?or(r):sr(r,i,s);break;case 2:t.gray?ar(r,i):ir(r,i,s);break;case 3:cr(r,i,s);break;case 4:lr(r,i,s);break}return r},sr=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s)},or=t=>{t.toABGR=e=>((y(e[0])*255+.5|0)*65793|4278190080)>>>0,t.fromABGR=(e,n=[])=>(n[0]=It(e)/255,n)},ir=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s|=n(r,1),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s[1]=e(r,1),s)},ar=(t,e)=>{const n=~~(t.channels[0]===w.ALPHA),r=n^1;t.toABGR=s=>{let i=(y(s[n])*255+.5|0)*65793;return i|=(s[r]*255+.5|0)<<24,i>>>0},t.fromABGR=(s,i=[])=>(i[n]=It(s)/255,i[r]=e(s,r),i)},cr=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s|=n(r,1),s|=n(r,2),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s[1]=e(r,1),s[2]=e(r,2),s)},lr=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s|=n(r,1),s|=n(r,2),s|=n(r,3),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s[1]=e(r,1),s[2]=e(r,2),s[3]=e(r,3),s)},Ue=lt({gray:!0,channels:[w.RED]}),hr={5120:"i8",5121:"u8",5122:"i16",5123:"u16",5124:"i32",5125:"u32",5126:"f32"},fr={f32:Float32Array,f64:Float64Array},ur={i8:Int8Array,i16:Int16Array,i32:Int32Array},dr={u8:Uint8Array,u8c:Uint8ClampedArray,u16:Uint16Array,u32:Uint32Array},gr={i64:BigInt64Array,u64:BigUint64Array},mr={...fr,...ur,...dr},yr=t=>{const e=hr[t];return e!==void 0?e:t};function ht(t,...e){const n=gr[t];return new(n||mr[yr(t)])(...e)}const br=t=>t>16?"u32":t>8?"u16":"u8",Ut=(t,e)=>e>0?`(${t} << ${e})`:e<0?`(${t} >>> ${-e})`:`${t}`,xt=(t,e)=>Ut(t,-e),xe=t=>`0x${t.toString(16)}`,Ar=t=>{const e=8-t,n=(1<<t)-1;return new Function("luma",`return (x) => ${xt("luma(x)",e)} & ${n};`)(It)},_r=t=>{let e;if(t!==8){const n=(1<<t)-1,r=255/n;e=`(((x & ${n}) * ${r}) | 0)`}else e="x";return new Function("x",`return 0xff000000 | (${e} * 0x010101);`)},pr=t=>new Function("x","return ("+t.map(e=>{const n=e.abgrShift+(8-e.size);return`(${xt("x",n)} & ${xe(e.maskA)})`}).join(" | ")+") >>> 0;"),wr=(t,e)=>{const n=t.map(s=>{if(s.size!==8){const i=s.mask0,a=255/i,o=xt("x",s.shift);return Ut(`((${o} & ${i}) * ${a})`,24-s.lane*8)}else return Ut(`(x & ${xe(s.maskA)})`,s.abgrShift)}).join(" | "),r=e?"":"0xff000000 | ";return new Function("x",`return (${r}${n}) >>> 0;`)},Rr=(t,e,n)=>{const r=1<<t.size,s=r-1,i=s<<n>>>0,a=~i>>>0,o=t.lane!=null?t.lane:e,c=h=>h>>>n&s,l=(h,u)=>h&a|(u&s)<<n;return{size:t.size,num:r,abgrShift:24-o*8-n,lane:o,shift:n,mask0:s,maskA:i,int:c,setInt:l,float:h=>c(h)/s,setFloat:(h,u)=>l(h,y(u)*s)}},ze=t=>{_(t.channels.length>0,"no channel specs given");const e=t.channels.reduce(([n,r],s,i)=>(r-=s.size,n.push(Rr(s,i,r)),[n,r]),[[],t.size])[0];return{__packed:!0,type:t.type,size:t.size,alpha:t.alpha||0,channels:e,fromABGR:t.fromABGR||pr(e),toABGR:t.toABGR||wr(e,!!t.alpha)}},zt=ze({type:"u32",size:32,alpha:8,channels:[{size:8,lane:w.ALPHA},{size:8,lane:w.BLUE},{size:8,lane:w.GREEN},{size:8,lane:w.RED}],fromABGR:it,toABGR:it}),Oe=Math.PI,k=Oe*2,$r=1/k;let I=1e-6;const Ee=(t,e,n,r,s,i)=>{const a=1-s,o=1-i;return t*a*o+e*s*o+n*a*i+r*s*i},X=(t,e,n,r,s)=>{r*=.5;const i=-.5*t+1.5*e-1.5*n+r,a=t-2.5*e+2*n-r,o=-.5*t+.5*n,c=e,l=s*s;return s*l*i+l*a+s*o+c},Fe=(t,e,n,r,s,i,a,o,c,l,h,u,f,d,g,m,b,A)=>X(X(t,e,n,r,b),X(s,i,a,o,b),X(c,l,h,u,b),X(f,d,g,m,b),A),ft=(t,e)=>t-e*Math.floor(t/e),p=t=>t-Math.floor(t),De=(t,e=1)=>Math.round(t/e)*e;function Ne(t,e="linear",n="clamp"){const r=!!t.format.__float,s=t.format.channels.length===1?"1":"",i=`${e[0]}${n[0]}${s}`,a=(r?{nc1:ut,nw1:dt,nr1:gt,nc:ut,nw:dt,nr:gt,lc1:o=>Ot(F(o)),lw1:o=>Ot(D(o)),lr1:o=>Ot(N(o)),lc:o=>Ft(o,ut(o)),lw:o=>Ft(o,dt(o)),lr:o=>Ft(o,gt(o)),cc1:o=>Nt(F(o)),cw1:o=>Nt(D(o)),cr1:o=>Nt(N(o)),cc:o=>qt(o,ut(o)),cw:o=>qt(o,dt(o)),cr:o=>qt(o,gt(o))}:{nc1:F,nw1:D,nr1:N,nc:F,nw:D,nr:N,lc1:o=>mt(F(o)),lw1:o=>mt(D(o)),lr1:o=>mt(N(o)),lc:o=>Et(o,F(o)),lw:o=>Et(o,D(o)),lr:o=>Et(o,N(o)),cc1:o=>Dt(o,F(o)),cw1:o=>Dt(o,D(o)),cr1:o=>Dt(o,N(o)),cc:o=>Tt(o,F(o)),cw:o=>Tt(o,D(o)),cr:o=>Tt(o,N(o))})[i];return _(!!a,`missing impl for ${i}`),a(t)}const F=({data:t,width:e,height:n})=>(r,s)=>r>=0&&r<e&&s>=0&&s<n?t[(s|0)*e+(r|0)]:0,D=({data:t,width:e,height:n})=>(r,s)=>t[ft(s|0,n)*e+ft(r|0,e)],N=({data:t,width:e,height:n})=>{const r=e-1,s=n-1;return(i,a)=>t[B(a|0,0,s)*e+B(i|0,0,r)]},ut=({data:t,width:e,height:n,stride:[r,s]})=>(i,a)=>{let o;return i>=0&&i<e&&a>=0&&a<n?(o=(a|0)*s+(i|0)*r,t.slice(o,o+r)):[0]},dt=({data:t,width:e,height:n,stride:[r,s]})=>(i,a)=>{let o=ft(a|0,n)*s+ft(i|0,e)*r;return t.slice(o,o+r)},gt=({data:t,width:e,height:n,stride:[r,s]})=>{const i=e-1,a=n-1;return(o,c)=>{let l=B(c|0,0,a)*s+B(o|0,0,i)*r;return t.slice(l,l+r)}},K=(t,e,n,r,s=4)=>Ee(t[r],t[r+s],t[r+2*s],t[r+3*s],e,n),mt=t=>(e,n)=>(e-=.5,n-=.5,Ee(t(e,n),t(e+1,n),t(e,n+1),t(e+1,n+1),p(e),p(n))),Ot=t=>(t=mt(t),(e,n)=>[t(e,n)]),Et=(t,e)=>{const{fromABGR:n,toABGR:r}=t.format,s=new Uint32Array(4),i=new Uint8Array(s.buffer);return(a,o)=>{a-=.5,o-=.5,s[0]=r(e(a,o)),s[1]=r(e(a+1,o)),s[2]=r(e(a,o+1)),s[3]=r(e(a+1,o+1));const c=p(a),l=p(o);return n(K(i,c,l,0)|K(i,c,l,1)<<8|K(i,c,l,2)<<16|K(i,c,l,3)<<24)>>>0}},Ft=({stride:[t]},e)=>{const n=new Float32Array(t*4);return(r,s)=>{r-=.5,s-=.5,n.set(e(r,s),0),n.set(e(r+1,s),t),n.set(e(r,s+1),t*2),n.set(e(r+1,s+1),t*3);const i=p(r),a=p(s);let o=[];for(let c=0;c<t;c++)o.push(K(n,i,a,c,t));return o}},Te=t=>(e,n)=>{e-=.5,n-=.5;const r=e-1,s=e+1,i=e+2,a=n-1,o=n+1,c=n+2;return Fe(t(r,a),t(e,a),t(s,a),t(i,a),t(r,n),t(e,n),t(s,n),t(i,n),t(r,o),t(e,o),t(s,o),t(i,o),t(r,c),t(e,c),t(s,c),t(i,c),p(e),p(n))},Dt=(t,e)=>{const n=t.format.channels[0].mask0;return e=Te(e),(r,s)=>B(e(r,s),0,n)},Nt=t=>(t=Te(t),(e,n)=>[t(e,n)]),qe=(t,e,n,r,s=4)=>Fe(t[r],t[r+s],t[r+2*s],t[r+3*s],t[r+4*s],t[r+5*s],t[r+6*s],t[r+7*s],t[r+8*s],t[r+9*s],t[r+10*s],t[r+11*s],t[r+12*s],t[r+13*s],t[r+14*s],t[r+15*s],e,n),yt=(t,e,n,r,s=4)=>B(qe(t,e,n,r,s),0,255),Tt=(t,e)=>{const{fromABGR:n,toABGR:r}=t.format,s=new Uint32Array(16),i=new Uint8Array(s.buffer);return(a,o)=>{a-=.5,o-=.5;const c=a-1,l=a+1,h=a+2,u=o-1,f=o+1,d=o+2,g=p(a),m=p(o);return s[0]=r(e(c,u)),s[1]=r(e(a,u)),s[2]=r(e(l,u)),s[3]=r(e(h,u)),s[4]=r(e(c,o)),s[5]=r(e(a,o)),s[6]=r(e(l,o)),s[7]=r(e(h,o)),s[8]=r(e(c,f)),s[9]=r(e(a,f)),s[10]=r(e(l,f)),s[11]=r(e(h,f)),s[12]=r(e(c,d)),s[13]=r(e(a,d)),s[14]=r(e(l,d)),s[15]=r(e(h,d)),n(yt(i,g,m,0)|yt(i,g,m,1)<<8|yt(i,g,m,2)<<16|yt(i,g,m,3)<<24)>>>0}},qt=({stride:[t]},e)=>{const n=new Float32Array(t*16);return(r,s)=>{r-=.5,s-=.5;const i=r-1,a=r+1,o=r+2,c=s-1,l=s+1,h=s+2,u=p(r),f=p(s);n.set(e(i,c),0),n.set(e(r,c),t),n.set(e(a,c),2*t),n.set(e(o,c),3*t),n.set(e(i,s),4*t),n.set(e(r,s),5*t),n.set(e(a,s),6*t),n.set(e(o,s),7*t),n.set(e(i,l),8*t),n.set(e(r,l),9*t),n.set(e(a,l),10*t),n.set(e(o,l),11*t),n.set(e(i,h),12*t),n.set(e(r,h),13*t),n.set(e(a,h),14*t),n.set(e(o,h),15*t);let d=[];for(let g=0;g<t;g++)d.push(qe(n,u,f,g,t));return d}};var Cr=Object.getOwnPropertyDescriptor,Sr=(t,e,n,r)=>{for(var s=r>1?void 0:r?Cr(e,n):e,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=a(s)||s);return s};function vr(...t){return t[0]instanceof U?t[0].as(t[1]):new U(...t)}const Br=(t,e=zt)=>{const{data:n}=Hn(t),r=t.width,s=t.height;let i;if(e===zt)i=n;else{i=ht(e.type,r*s);const a=n,o=e.fromABGR;for(let c=i.length;c-- >0;)i[c]=o(a[c])}return new U(r,s,e,i)};let U=class{size;stride;format;data;constructor(t,e,n=zt,r){this.size=[t,e],this.stride=[1,t],this.format=n.__packed?n:ze(n),this.data=r||ht(n.type,t*e)}get pixels(){return this.data}get width(){return this.size[0]}get height(){return this.size[1]}get offset(){return 0}get dim(){return 2}*[Symbol.iterator](){yield*this.data}as(t){if(!t.__float)return this.getRegion(0,0,this.width,this.height,t);const e=new S(this.width,this.height,t),{data:n,format:r,stride:[s]}=e,{data:i,format:a}=this;for(let o=i.length;o-- >0;)n.set(r.fromABGR(a.toABGR(i[o])),o*s);return e}copy(){const t=this.empty();return t.data.set(this.data),t}empty(){return new U(this.width,this.height,this.format)}order(){}includes(t,e){}indexAt(t,e){}indexAtUnsafe(t,e){}getAt(t,e){}getAtUnsafe(t,e){}setAt(t,e,n){}setAtUnsafe(t,e,n){}getChannelAt(t,e,n,r=!1){const s=O(this.format,n),i=this.getAt(t,e);return r?s.float(i):s.int(i)}setChannelAt(t,e,n,r,s=!1){const i=O(this.format,n),a=this.getAt(t,e);return s?i.setFloat(a,r):i.setInt(a,r),this}blend(t,e,n){let r=this.width,s=e.width;const{sx:i,sy:a,dx:o,dy:c,rw:l,rh:h}=ct(this,e,n);if(l<1||h<1)return e;const u=this.data,f=e.data,d=this.format.toABGR,g=e.format.toABGR,m=e.format.fromABGR;for(let b=(i|0)+(a|0)*r,A=(o|0)+(c|0)*s,E=0;E<h;E++,b+=r,A+=s)for(let z=0;z<l;z++)f[A+z]=m(t(d(u[b+z]),g(f[A+z])));return e}blit(t,e){let n=this.width,r=t.width;const{sx:s,sy:i,dx:a,dy:o,rw:c,rh:l}=ct(this,t,e);if(c<1||l<1)return t;const h=this.data,u=t.data,f=this.format.toABGR,d=t.format.fromABGR,g=this.format!==t.format?(m,b)=>{for(let A=0;A<c;A++)u[b+A]=d(f(h[m+A]))}:(m,b)=>u.set(h.subarray(m,m+c),b);for(let m=(s|0)+(i|0)*n,b=(a|0)+(o|0)*r,A=0;A<l;A++,m+=n,b+=r)g(m,b);return t}blitCanvas(t,e={}){Ie(this,t,e)}setImageData(t){Mt(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),n=this.data,r=this.format.fromABGR;for(let s=e.length;s-- >0;)n[s]=r(e[s]);return this}toImageData(t){t=Ge(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),n=this.data,r=this.format.toABGR;for(let s=e.length;s-- >0;)e[s]=r(n[s]);return t}getRegion(t,e,n,r,s){const[i,a,o,c]=at(t,e,n,r,this.width,this.height);if(!(o<1||c<1))return this.blit(new U(o,c,s||this.format),{sx:i,sy:a,w:o,h:c})}getChannel(t){const e=O(this.format,t),n=new U(this.width,this.height,{type:br(e.size),size:e.size,channels:[{size:e.size,lane:w.RED}],fromABGR:Ar(e.size),toABGR:_r(e.size)}),r=this.data,s=n.data,i=e.int;for(let a=r.length;a-- >0;)s[a]=i(r[a]);return n}setChannel(t,e){const n=O(this.format,t),r=this.data,s=n.setInt;if(q(e))er(r,e,s);else{const i=e.data,a=e.format.channels[0];ke(i,this.width,this.height),n.size===a.size?nr(r,i,a.int,s):rr(r,i,this.format.fromABGR,e.format.toABGR,n.maskA)}return this}invert(){const{data:t,format:e}=this,n=Math.pow(2,e.size-e.alpha)-1;for(let r=t.length;r-- >0;)t[r]^=n;return this}premultiply(){return tr(this.format),Me(this.data,this.format,Xn),this}postmultiply(){return Me(this.data,this.format,Zn),this}isPremultiplied(){const t=this.data,e=this.format.toABGR;for(let n=t.length;n-- >0;)if(!Qn(e(t[n])))return!1;return!0}forEach(t){const e=this.data;for(let n=e.length;n-- >0;)e[n]=t(e[n],n);return this}fill(t){this.data.fill(t)}flipX(){const{data:t,width:e}=this;for(let n=0;n<t.length;n+=e)t.subarray(n,n+e).reverse();return this}flipY(){const{data:t,width:e}=this,n=ht(this.format.type,e);for(let r=0,s=t.length-e;r<s;r+=e,s-=e)n.set(t.subarray(r,r+e)),t.copyWithin(r,s,s+e),t.set(n,s);return this}rotateByID(t){return t>0?this[$e[t-1]]():this}rotateCW(){const{width:t,height:e}=this,n=e-1;return this._rotate((r,s)=>r*e+n-s),this.size[0]=e,this.size[1]=t,this}rotateCCW(){const{width:t,height:e}=this,n=t-1;return this._rotate((r,s)=>(n-r)*e+s),this.size[0]=e,this.size[1]=t,this}rotate180(){const{width:t,height:e}=this,n=t-1,r=e-1;return this._rotate((s,i)=>(r-i)*t+n-s),this}scale(t,e="linear"){return _(t>0,"scale must be > 0"),this.resize(this.width*t,this.height*t,e)}resize(t,e,n="linear"){t|=0,e|=0,_(t>0&&e>0,"target width & height must be > 0");const r=vr(t,e,this.format),s=r.data,i=t>0?this.width/t:0,a=e>0?this.height/e:0;n=P(n)?Ne(this,n,"repeat"):n;for(let o=0,c=0;o<e;o++){const l=o*a;for(let h=0;h<t;h++,c++)s[c]=n(h*i,l)}return r}upsize(){const{width:t,height:e,data:n}=this,r=new U(t*2,e*2,this.format),s=r.data;for(let i=0,a=0;i<e;i++)for(let o=0,c=i*t*4;o<t;o++,a++,c+=2)s[c]=n[a];return r}_rotate(t){const{data:e,format:n,width:r,height:s}=this,i=ht(n.type,r*s);for(let a=0;a<s;a++)for(let o=0;o<r;o++)i[t(o,a)]=e[a*r+o];this.data=i}};U=Sr([Ce],U);var kr=Object.defineProperty,Gr=Object.getOwnPropertyDescriptor,Z=(t,e,n,r)=>{for(var s=r>1?void 0:r?Gr(e,n):e,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(e,n,s):a(s))||s);return r&&s&&kr(e,n,s),s};function Pe(...t){return t[0]instanceof U?Mr(...t):new S(...t)}const Mr=(t,e)=>{const n=new S(t.width,t.height,e),{data:r,format:s,stride:[i]}=n,{data:a,format:o}=t;for(let c=a.length;c-- >0;)r.set(s.fromABGR(o.toABGR(a[c])),c*i);return n},Ir=(t,e=j)=>Br(t).as(e);let S=class{size;stride;format;data;__empty;constructor(t,e,n=j,r){this.size=[t,e],this.format=n.__float?n:lt(n);const s=this.format.channels.length;this.stride=[s,t*s],this.data=r||new Float32Array(t*e*s),this.__empty=Object.freeze(new Array(s).fill(0))}get pixels(){return this.data}get width(){return this.size[0]}get height(){return this.size[1]}get offset(){return 0}get dim(){return 2}*[Symbol.iterator](){const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)yield t.subarray(n,n+e)}as(t){const{width:e,height:n,stride:[r],data:s,format:{size:i,normalized:a,toABGR:o}}=this;let c=0,l=0,h=s.length;if(t.__float){const u=t,f=new S(e,n,u),{data:d,stride:[g]}=f;if(i===1&&u.channels.length===1){const m=u.fromNormalized;for(;c<h;c+=r,l+=g)d[l]=m(a(s[c]))}else for(;c<h;c+=r,l+=g)d.set(u.fromABGR(o(s.subarray(c,c+r))),l);return f}else{const u=t,f=new U(e,n,u),d=f.data;if(i===1&&u.channels.length===1){const g=u.channels[0].setFloat;for(;c<h;c+=r,l++)d[l]=g(0,a(s[c]))}else for(;c<h;c+=r,l++)d[l]=u.fromABGR(o(s.subarray(c,c+r)));return f}}copy(){const t=this.empty();return t.data.set(this.data),t}empty(){return new S(this.width,this.height,this.format)}order(){}includes(t,e){}indexAt(t,e){}indexAtUnsafe(t,e){}getAt(t,e){return this.includes(t,e)?this.getAtUnsafe(t,e):this.__empty}getAtUnsafe(t,e){const n=this.indexAtUnsafe(t,e);return this.data.subarray(n,n+this.stride[0])}setAt(t,e,n){return this.includes(t,e)?(this.data.set(n,this.indexAtUnsafe(t,e)),!0):!1}setAtUnsafe(t,e,n){return this.data.set(n,this.indexAtUnsafe(t,e)),!0}getChannelAt(t,e,n){return O(this.format,n),this.includes(t,e)?this.data[this.indexAtUnsafe(t,e)+n]:void 0}setChannelAt(t,e,n,r){return O(this.format,n),this.includes(t,e)&&(this.data[this.indexAtUnsafe(t,e)+n]=r),this}getChannel(t){O(this.format,t);const{data:e,stride:[n]}=this,[r,s]=this.format.range,i=new Float32Array(this.width*this.height);for(let a=t,o=0,c=e.length;a<c;a+=n,o++)i[o]=B(e[a],r,s);return new S(this.width,this.height,Ue,i)}setChannel(t,e){O(this.format,t);const{data:n,stride:[r]}=this;if(q(e))for(let s=t,i=n.length;s<i;s+=r)n[s]=e;else{const{data:s,stride:[i]}=e;ke(s,this.width,this.height,i);for(let a=t,o=0,c=n.length;a<c;a+=r,o+=i)n[a]=s[o]}return this}blend(t,e,n){this.ensureFormat(e);const{sx:r,sy:s,dx:i,dy:a,rw:o,rh:c}=ct(this,e,n);if(o<1||c<1)return e;const l=this.data,h=e.data,[u,f]=this.stride,d=e.stride[1];for(let g=(r|0)*u+(s|0)*f,m=(i|0)*u+(a|0)*d,b=0;b<c;b++,g+=f,m+=d)for(let A=o,E=g,z=m;A-- >0;E+=u,z+=u){const Gt=h.subarray(z,z+u);t(Gt,l.subarray(E,E+u),Gt)}return e}blit(t,e){this.ensureFormat(t);const{sx:n,sy:r,dx:s,dy:i,rw:a,rh:o}=ct(this,t,e);if(a<1||o<1)return t;const c=this.data,l=t.data,[h,u]=this.stride,f=t.stride[1],d=a*h;for(let g=(n|0)*h+(r|0)*u,m=(s|0)*h+(i|0)*f,b=0;b<o;b++,g+=u,m+=f)l.set(c.subarray(g,g+d),m);return t}blitCanvas(t,e={}){Ie(this,t,e)}setImageData(t){Mt(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),{data:n,format:{fromABGR:r},stride:[s]}=this,i=[];for(let a=e.length;a-- >0;)n.set(r(e[a],i),a*s);return this}toImageData(t){t=Ge(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),{stride:[n],data:r,format:s}=this;for(let i=0,a=0,o=r.length;i<o;i+=n,a++)e[a]=s.toABGR(r.subarray(i,i+n));return t}getRegion(t,e,n,r){const[s,i,a,o]=at(t,e,n,r,this.width,this.height);if(!(a<1||o<1))return this.blit(new S(a,o,this.format),{sx:s,sy:i,w:a,h:o})}forEach(t){const{data:e,stride:[n]}=this;for(let r=0,s=0,i=e.length;r<i;r+=n,s++)e.set(t(e.subarray(r,r+n),s),r);return this}fill(t){_(t.length<=this.format.channels.length,"fill value has too many channels");const{data:e,stride:[n]}=this;for(let r=0,s=e.length;r<s;r+=n)e.set(t,r)}premultiply(){this.ensureRGBA();const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)Vn(null,t.subarray(n,n+e));return this}postmultiply(){this.ensureRGBA();const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)Kn(null,t.subarray(n,n+e));return this}isPremultiplied(){this.ensureRGBA();const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)if(!Jn(t.subarray(n,n+e)))return!1;return!0}clamp(){const t=this.data,[e,n]=this.format.range;for(let r=t.length;r-- >0;)t[r]=B(t[r],e,n);return this}clampChannel(t){O(this.format,t);const{data:e,stride:[n]}=this,[r,s]=this.format.range;for(let i=t,a=e.length;i<a;i+=n)e[i]=B(e[i],r,s)}flipX(){const{data:t,width:e,height:n,stride:[r,s]}=this,i=new Float32Array(r),a=e-1,o=e>>>1;for(let c=0;c<n;c++)for(let l=0,h=c*s,u=h+a*r;l<o;l++,h+=r,u-=r)i.set(t.subarray(h,h+r)),t.copyWithin(h,u,u+r),t.set(i,u);return this}flipY(){const t=this.data,e=this.stride[1],n=new Float32Array(e);for(let r=0,s=t.length-e;r<s;r+=e,s-=e)n.set(t.subarray(r,r+e)),t.copyWithin(r,s,s+e),t.set(n,s);return this}rotateByID(t){return t>0?this[$e[t-1]]():this}rotateCW(){const{width:t,height:e}=this,n=e-1;return this._rotate((r,s)=>r*e+n-s),this.size[0]=e,this.size[1]=t,this}rotateCCW(){const{width:t,height:e}=this,n=t-1;return this._rotate((r,s)=>(n-r)*e+s),this.size[0]=e,this.size[1]=t,this}rotate180(){const{width:t,height:e}=this,n=t-1,r=e-1;return this._rotate((s,i)=>(r-i)*t+n-s),this}invert(){const{data:t,format:e,stride:[n]}=this;for(let r=0,s=t.length,i=e.alpha?n-1:n;r<s;r+=n)for(let a=0;a<i;a++)t[r+a]=1-t[r+a];return this}scale(t,e){return _(t>0,"scale must be > 0"),this.resize(this.width*t,this.height*t,e)}resize(t,e,n="linear"){t|=0,e|=0,_(t>0&&e>0,"target width & height must be > 0");const r=Pe(t,e,this.format),s=r.data,i=t>0?this.width/t:0,a=e>0?this.height/e:0,o=this.stride[0];n=P(n)?Ne(this,n,"repeat"):n;for(let c=0,l=0;c<e;c++){const h=c*a;for(let u=0;u<t;u++,l+=o)s.set(n(u*i,h),l)}return r}upsize(){const{width:t,height:e,data:n,stride:[r,s]}=this,i=r*2,a=Pe(t*2,e*2,this.format),o=a.data;for(let c=0,l=0;c<e;c++)for(let h=0,u=c*s*4;h<t;h++,l+=r,u+=i)o.set(n.subarray(l,l+r),u);return a}_rotate(t){const{data:e,width:n,height:r,stride:[s]}=this,i=new Float32Array(n*r*s);for(let a=0,o=0;a<r;a++)for(let c=0;c<n;c++,o+=s)i.set(e.subarray(o,o+s),t(c,a)*s);this.data=i}ensureFormat(t){_(t.format===this.format,"dest buffer format must be same as src")}ensureRGBA(){_(this.format===j,"require FLOAT_RGBA format")}};Z([rt],S.prototype,"getAt",1),Z([rt],S.prototype,"getAtUnsafe",1),Z([rt],S.prototype,"setAt",1),Z([rt],S.prototype,"setAtUnsafe",1),S=Z([Ce],S);const Ur=(t,e,n)=>(t-e)/(n-e),xr=(t,e,n,r,s)=>r+(s-r)*Ur(t,e,n),bt=Math.abs,zr=Math.min,Or=lt({alpha:!0,channels:[w.RED,w.GREEN,w.BLUE,w.ALPHA],convert:{fromABGR:(t,e=[])=>{const n=(t>>>24&255)/255,r=(t>>>16&255)/255,s=(t>>>8&255)/255,i=(t&255)/255;let a,o,c,l,h,u,f,d;s<r?(a=r,o=s,c=-1,l=2/3):(a=s,o=r,c=0,l=-1/3),i<a?(h=a,u=o,f=l,d=i):(h=i,u=o,f=c,d=a);const g=h-zr(u,d);return h=y(h),e[0]=y(bt((d-u)/(6*g+I)+f)),e[1]=y(g/(h+I)),e[2]=h,e[3]=n,e},toABGR:t=>{const e=t[0]*6,n=t[1],r=t[2]*255,s=t[3]*255,i=((y(bt(e-3)-1)-1)*n+1)*r,a=((y(2-bt(e-2))-1)*n+1)*r,o=((y(2-bt(e-4))-1)*n+1)*r;return(s<<24|o<<16|a<<8|i)>>>0}}}),j=lt({alpha:!0,channels:[w.RED,w.GREEN,w.BLUE,w.ALPHA]}),Er=ot(()=>"unsupported operation"),Pt=t=>{throw new Er(t)},G=(t=1,e,...n)=>{const r=[,,].concat(n),s=(...i)=>{const a=r[i[t].length]||e;return a?a(...i):Pt(`no impl for vec size ${i[t].length}`)};return s.add=(i,a)=>r[i]=a,s.default=i=>e=i,s.impl=i=>i!=null&&r[i]||e,s},Fr=(t,e)=>t[0]*e[0]+t[1]*e[1],jt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Dr=G(0,(t,e)=>{let n=0;for(let r=t.length;r-- >0;)n+=t[r]*e[r];return n},Fr,jt,(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]);function je(t,e=Object.create(null)){return(...n)=>{const r=JSON.stringify(n);return r!==void 0?r in e?e[r]:e[r]=t.apply(null,n):t.apply(null,n)}}function Le(t,e=Object.create(null)){return(...n)=>{const r=n.join("-");return r in e?e[r]:e[r]=t(...n)}}const Nr=Le((t,e)=>t.repeat(e)),He=je((t,e=!1)=>e?n=>Tr(n)||n.toFixed(t):n=>n.toFixed(t)),Tr=t=>isNaN(t)?"NaN":t===1/0?"+∞":t===-1/0?"-∞":void 0,qr=(t=0)=>e=>(e*100).toFixed(t)+"%",Pr=[.299,.587,.114],We=[.2126,.7152,.0722],jr=[3.1338561,-.9787684,.0719453,-1.6168667,1.9161415,-.2289914,-.4906146,.033454,1.4052427],Lr=[3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252],Hr=[.96422,1,.82521],Wr=[.95047,1,1.08883],Yr=[.2104542553,1.9779984951,.0259040371,.793617785,-2.428592205,.7827717662,-.0040720468,.4505937099,-.808675766];let At=He(3),Ye=qr(3);const M=1/255,Lt=(t,e=We)=>jt(t,e),Vr=t=>jt(t,Pr),Xr=(t,e)=>(!t&&(t=[]),t[0]=e[0],t[1]=e[1],t),Kr=(t,e)=>(!t&&(t=[]),t[0]=e[0],t[1]=e[1],t[2]=e[2],t),L=(t,e)=>(!t&&(t=[]),t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t),Zr=G(1,(t,e)=>{!t&&(t=[]);for(let n=e.length;n-- >0;)t[n]=e[n];return t},Xr,Kr,L),J=(t,e)=>typeof t?.[e]=="function",Ht=t=>t!=null&&typeof t!="function"&&t.length!==void 0,Jr=ot(()=>"illegal argument(s)"),Wt=t=>{throw new Jr(t)},Qr=je((t,e=3,n=",",r="[",s="]")=>{const i=typeof e=="number"?He(e):e;switch(t){case 1:return a=>`${r}${i(a[0])}${s}`;case 2:return a=>`${r}${i(a[0])}${n}${i(a[1])}${s}`;case 3:return a=>`${r}${i(a[0])}${n}${i(a[1])}${n}${i(a[2])}${s}`;case 4:return a=>`${r}${i(a[0])}${n}${i(a[1])}${n}${i(a[2])}${n}${i(a[3])}${s}`;default:return a=>{const o=[];for(let c=0;c<a.length;c++)o.push(i(a[c]));return`${r}${o.join(n)}${s}`}}}),ts=(t,e,n,r,s,i)=>{const a=[];for(;n-- >0;)a.push(new t(e,r,s)),r+=i;return a},es=(t,e=1,n=!0)=>{const r=n?(o,c,l,h)=>{!o&&(o=c);for(let u=c.length;u-- >0;)o[u]=t(c[u],l[u],h[u]);return o}:(o,c,l,h)=>{!o&&(o=h);for(let u=c.length;u-- >0;)o[u]=t(c[u],l[u],h[u]);return o},s=n?(o,c,l,h)=>(!o&&(o=c),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o):(o,c,l,h)=>(!o&&(o=h),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o),i=n?(o,c,l,h)=>(!o&&(o=c),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o):(o,c,l,h)=>(!o&&(o=h),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o),a=n?(o,c,l,h)=>(!o&&(o=c),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o[3]=t(c[3],l[3],h[3]),o):(o,c,l,h)=>(!o&&(o=h),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o[3]=t(c[3],l[3],h[3]),o);return[G(e,r,s,i,a),s,i,a]},[hi,fi,ui,ns]=es(B),rs=ns,ss=(t,e,n,r=!0,s=!0)=>{const i=n>0?r?function(){return this.buf[this.offset+n*this.stride]}:function(){return this.buf[this.offset+n]}:function(){return this.buf[this.offset]},a=n>0?r?function(o){this.buf[this.offset+n*this.stride]=o}:function(o){this.buf[this.offset+n]=o}:function(o){this.buf[this.offset]=o};s&&Object.defineProperty(t,n,{get:i,set:a,enumerable:!0}),Object.defineProperty(t,e,{get:i,set:a,enumerable:!0})},os=(t,e,n,r)=>e.forEach((s,i)=>ss(t,s,i,n,r)),is=Math.abs,x=(t,e,n=I)=>is(t-e)<=n,as=(t,e,n=I)=>t.length===e.length&&x(t[0],e[0],n)&&x(t[1],e[1],n),cs=(t,e,n=I)=>t.length===e.length&&x(t[0],e[0],n)&&x(t[1],e[1],n)&&x(t[2],e[2],n),Ve=(t,e,n=I)=>t.length===e.length&&x(t[0],e[0],n)&&x(t[1],e[1],n)&&x(t[2],e[2],n)&&x(t[3],e[3],n);G(0,(t,e,n=I)=>J(t,"eqDelta")?t.eqDelta(e,n):J(e,"eqDelta")?e.eqDelta(t,n):ls(t,e,t.length,n),as,cs,Ve);const ls=(t,e,n,r=I,s=0,i=0,a=1,o=1)=>{for(;n>0;n--,s+=a,i+=o)if(!x(t[s],e[i],r))return!1;return!0};function*hs(t,e,n,r){for(;e-- >0;)yield t[n],n+=r}const Xe=1/2**32;class fs{float(e=1){return this.int()*Xe*e}probability(e){return this.float()<e}norm(e=1){return(this.int()*Xe-.5)*2*e}normMinMax(e,n){const r=this.minmax(e,n);return this.float()<.5?r:-r}minmax(e,n){return this.float()*(n-e)+e}minmaxInt(e,n){e|=0;const r=(n|0)-e;return r?e+this.int()%r:e}minmaxUint(e,n){e>>>=0;const r=(n>>>0)-e;return r?e+this.int()%r:e}}class us extends fs{constructor(e){super(),this.rnd=e}float(e=1){return this.rnd()*e}norm(e=1){return(this.rnd()-.5)*2*e}int(){return this.rnd()*4294967296>>>0}}const Yt=new us(Math.random),ds=(t,e,n=Yt)=>{const r=t.length;_(r>0,"no choices given");const s=e?t.map((a,o)=>[e[o]||0,a]).sort((a,o)=>o[0]-a[0]):t.map(a=>[1,a]),i=s.reduce((a,o)=>a+o[0],0);return i<=0&&console.warn("total weights <= 0"),()=>{const a=n.float(i);let o=i;for(let c=0;c<r;c++)if(o-=s[c][0],o<=a)return s[c][1]}},gs=G(1,(t,e,n,r=Yt)=>{!t&&(t=e);for(let s=e.length;s-- >0;)t[s]=r.minmax(e[s],n[s]);return t}),Ke=Array.isArray,Q={},Ze=(t,e)=>{for(const n in e){const r=e[n];if(Ke(r)){const[s,i,a,o]=r;e[n]=r.length===2?(c,l)=>i(c,s(c,l)):r.length===3?(c,l)=>a(c,i(c,s(c,l))):(c,l)=>o(c,a(c,i(c,s(c,l))))}}Q[t]={...Q[t],...e}},Je=(t,e,n,r)=>{const s=Q[n];_(!!s,`no conversions available for ${n}`);let i=s[r];return i?i(t,e):Q.rgb[r]?s.rgb(t,Q.rgb[r]([],e)):Pt(`can\'t convert: ${r} -> ${n}`)},Qe=(t,e)=>(t>>>e|t<<32-e)>>>0,ms=t=>(t&3840)*4352|(t&240)*272|(t&15)*17,ys=t=>((t&61440)*69632|(t&3840)*4352|(t&240)*272|(t&15)*17)>>>0;class T{constructor(e,n){this.mode=e,this.value=n}deref(){return this.value}}const bs={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32",transparent:"0000",rebeccapurple:"639"};let As={canvas:"fff",canvastext:"000",linktext:"001ee4",visitedtext:"4e2386",activetext:"eb3323",buttonface:"ddd",buttontext:"000",buttonborder:"000",field:"fff",fieldtext:"000",highlight:"bbd5fb",highlighttext:"000",mark:"000",marktext:"fff",graytext:"808080"};const v=(t,e,n,r)=>(!t&&(t=[]),t[0]=e,t[1]=n,t[2]=r,t),R=(t,e,n,r,s)=>(!t&&(t=[]),t[0]=e,t[1]=n,t[2]=r,t[3]=s,t),_t=(t,e)=>R(t||[],(e>>>16&255)*M,(e>>>8&255)*M,(e&255)*M,(e>>>24)*M),tn=(t,e)=>R(t||[],(e&255)*M,(e>>>8&255)*M,(e>>>16&255)*M,(e>>>24)*M),_s=t=>{t=(P(t)?t:t.deref()).toLowerCase();const e=bs[t]||As[t];if(e||t[0]==="#")return new T("srgb",_t([],ws(e||t)));const n=t.split(/[(),/ ]+/),[r,s,i,a,o]=n;switch(_(n.length===5||n.length===6,`invalid color: ${t}`),r){case"rgb":case"rgba":return new T("srgb",[C(s,1,M,!0),C(i,1,M,!0),C(a,1,M,!0),H(o)]);case"hsl":case"hsla":return new T("hsl",[Vt(s),en(i),en(a),H(o)]);case"lab":return new T("lab50",[C(s),C(i,1.25),C(a,1.25),H(o)]);case"lch":return new T(r,[C(s),C(i,1.5),Vt(a),H(o)]);case"oklab":return new T(r,[C(s,1,1),C(i,.4,1),C(a,.4,1),H(o)]);case"oklch":return new T(r,[C(s,1,1),C(i,.4,1),Vt(a),H(o)]);default:Pt(`color mode: ${r}`)}},ps={rad:k,grad:400,turn:1,deg:360},Vt=t=>{const e=/^(-?[0-9.]+)(deg|rad|grad|turn)?$/.exec(t);return _(!!e,`expected hue, got: ${t}`),p(parseFloat(e[1])/(ps[e[2]]||360))},H=t=>t?C(t,1,1,!0):1,en=(t,e=!0)=>{_(/^([0-9.]+)%$/.test(t),`expected percentage, got: ${t}`);const n=parseFloat(t)/100;return e?y(n):n},C=(t,e=1,n=.01,r=!1)=>{_(/^-?[0-9.]+%?$/.test(t),`expected number or percentage, got: ${t}`);const s=parseFloat(t)*(t.endsWith("%")?.01*e:n);return r?y(s):s},ws=t=>{const e=/^#?([0-9a-f]{3,8})$/i.exec(t);if(e){const n=e[1],r=parseInt(n,16);switch(n.length){case 3:return(ms(r)|4278190080)>>>0;case 4:return Qe(ys(r),8);case 6:return(r|4278190080)>>>0;case 8:return Qe(r,8)}}return Wt(`invalid hex color: "${t}"`)},$=(t,e=1)=>t!=null?y(t):e,Rs=t=>{if(typeof t[0]=="number")switch(t.length){case 1:return t.push(0,0,1),[t];case 2:return t.push(0,1),[t];case 3:return t.push(1),[t];default:return[t]}return t},pt=t=>{const e=t.channels||{},n=t.order,r=n.length;n.reduce((f,d)=>(f[d]={range:[0,1],...e[d]},f),e);const s=Object.freeze(n.map(f=>e[f].range[0])),i=Object.freeze(n.map(f=>e[f].range[1])),a=L([],s),o=L([],i);a[r-1]=1;const c=n.findIndex(f=>!!e[f].hue),l=class{constructor(f,d=0,g=1){this.offset=d,this.stride=g,this.buf=f||[0,0,0,0],this.offset=d,this.stride=g}buf;get mode(){return t.mode}get length(){return r}get range(){return[s,i]}get[Symbol.toStringTag](){return t.mode}get xyz(){return[this[0],this[1],this[2]]}[Symbol.iterator](){return hs(this.buf,this.length,this.offset,this.stride)}copy(){return new l(this.deref())}copyView(){return new l(this.buf,this.offset,this.stride)}empty(){return new l}deref(){return[this[0],this[1],this[2],this[3]]}set(f){return L(this,f)}clamp(){return c>=0&&(this[c]=p(this[c])),rs(null,this,s,i),this}eqDelta(f,d=I){return Ve(this,f,d)}randomize(f){return gs(this,a,o,f)}toJSON(){return this.deref()}toString(){return Qr(4,4)(this)}};os(l.prototype,n),Ze(t.mode,t.from),Ze("rgb",{[t.mode]:t.toRgb});const h=(f,d,g)=>{const m=new l(...g);return d!==t.mode?Je(m,f,t.mode,d):m.set(f)},u=(f,...d)=>f==null?new l:P(f)?u(_s(f),...d):Ht(f)?P(f.mode)?h(f,f.mode,d):new l(f,...d):J(f,"deref")?h(f.deref(),f.mode,d):q(f)?d.length&&d.every(q)?new l(...Rs([f,...d])):h(_t([],f),"srgb",d):Wt(`can\'t create a ${t.mode} color from: ${f}`);return u.class=l,u.range=[s,i],u.random=(f,d,g,m)=>new l(d,g,m).randomize(f),u.mapBuffer=(f,d=f.length/r|0,g=0,m=1,b=r)=>ts(l,f,d,g,m,b),u},Xt=(t,e,n=1)=>(e=p(e)*6,R(t||[],y(Math.abs(e-3)-1),y(2-Math.abs(e-2)),y(2-Math.abs(e-4)),n)),nn=(t,e)=>{const n=e[0];let r=e[1];const s=e[2],i=Xt(t||e,n,$(e[3])),a=Lt(i);return s<a?r*=s/a:a<1&&(r*=(1-s)/(1-a)),v(i,y((i[0]-a)*r+s),y((i[1]-a)*r+s),y((i[2]-a)*r+s))},$s=(t,e,n=1)=>R(t||e,y(e[0]),y(e[1]),y(e[2]),$(e[3],n)),wt=(t,e,n=1)=>R(t||e,p(e[0]),y(e[1]),y(e[2]),$(e[3],n)),rn=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2];if(n<1e-6)return v(t,r,r,r);const s=t[0]*6%6,i=r*(1-n),a=1-Math.abs(s%2-1);let o=3*r*n/(1+a);const c=o*a+i;switch(o+=i,s|0){case 0:return v(t,o,c,i);case 1:return v(t,c,o,i);case 2:return v(t,i,o,c);case 3:return v(t,i,c,o);case 4:return v(t,c,i,o);case 5:return v(t,o,i,c);default:return v(t,i,i,i)}},sn=(t,e)=>{const n=y(e[1]),r=y(e[2]);t=Xt(t||e,e[0],$(e[3]));const s=(1-Math.abs(2*r-1))*n;return v(t,(t[0]-.5)*s+r,(t[1]-.5)*s+r,(t[2]-.5)*s+r)},Kt=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2];return Xt(t,e[0],t[3]),v(t,((t[0]-1)*n+1)*r,((t[1]-1)*n+1)*r,((t[2]-1)*n+1)*r)},Zt=t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,Jt=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),Rt=(t,e)=>R(t||e,Jt(e[0]),Jt(e[1]),Jt(e[2]),$(e[3])),Cs=(t,e)=>Rt(null,_t(t,e)),Ss=(t,e)=>Rt(null,tn(t,e)),Qt=(t,e=1)=>[Math.cos(t)*e,Math.sin(t)*e],vs=t=>(t%=k,t<0?k+t:t),on=(t,e)=>vs(Math.atan2(t,e)),te=(t,e)=>{let{1:n,2:r}=e;r*=k;const s=$(e[3]);return n>0?R(t||e,e[0],Math.cos(r)*n,Math.sin(r)*n,s):R(t||e,e[0],0,0,s)},ee=t=>{const e=t**3;return e>.008856?e:(t-16/116)/7.787},an=(t,e,n=Hr)=>{const r=(e[0]+.16)/1.16;return R(t||e,ee(e[1]/5+r)*n[0],ee(r)*n[1],ee(r-e[2]/2)*n[2],$(e[3]))},Bs=(t,e)=>an(t,e,Wr),ne=(t,e,n=0,r=0,s=1,i=1)=>t[n]*e[r]+t[n+s]*e[r+i]+t[n+2*s]*e[r+2*i],$t=(t,e,n,r=!1)=>{const s=ne(e,n,0,0,3),i=ne(e,n,1,0,3),a=ne(e,n,2,0,3),o=$(n[3]);return r?R(t||n,y(s),y(i),y(a),o):R(t||n,s,i,a,o)},re=(t,e,n=jr)=>$t(t,n,e),se=(t,e)=>re(t,e,Lr),tt=(t,e)=>re(null,an(t,e)),cn=(t,e)=>se(null,Bs(t,e)),ks=[4.0767416621,-1.2684380046,-.0041960863,-3.307711591,2.6097574011,-.7034186147,.2309699292,-.3413193965,1.707614701],ln=(t,{0:e,1:n,2:r,3:s})=>$t(t,ks,[(e+.3963377774*n+.2158037573*r)**3,(e-.1055613458*n-.0638541728*r)**3,(e-.0894841775*n-1.291485548*r)**3,s]),hn=(t,e)=>e!==0?t/e:0,fn=pt({mode:"rgb",order:["r","g","b","alpha"],from:{abgr32:(t,e)=>Ss(t,e[0]),argb32:(t,e)=>Cs(t,e[0]),hcy:nn,hsi:rn,hsl:sn,hsv:Kt,lab50:tt,lab65:cn,lch:[te,tt],oklab:ln,rgb:L,srgb:Rt,xyy:[(t,e)=>{const{0:n,1:r,2:s}=e;return R(t||e,hn(s*n,r),s,hn(s*(1-n-r),r),$(e[3]))},se],xyz50:re,xyz65:se,ycc:(t,e,n=We)=>{const r=e[0],s=(2-2*n[2])*e[1],i=(2-2*n[0])*e[2];return R(t||e,r+i,r-n[2]/n[1]*s-n[0]/n[1]*i,r+s,$(e[3]))}},toRgb:L}),Gs=(t,e)=>{const n=Lt(fn(t))+.05,r=Lt(fn(e))+.05;return n>r?n/r:r/n},un=t=>((t==null||!t[Symbol.iterator])&&Wt(`value is not iterable: ${t}`),t),Ms=t=>Ke(t)?t:[...un(t)],Is=t=>Ht(t)?t:[...un(t)],dn=t=>{const e=At(p(t[0])*360),n=Ye(y(t[1])),r=Ye(y(t[2])),s=$(t[3]);return s<1?`hsla(${e},${n},${r},${At(s)})`:`hsl(${e},${n},${r})`},Us=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2],s=(2-n)*r/2;return t[2]=s,t[1]=s&&s<1?n*r/(s<.5?s*2:2-s*2):n,t},xs=t=>dn(Us([],t)),gn="0123456789abcdef",oe=t=>gn[t>>>4&15]+gn[t&15],zs=t=>oe(t>>>8)+oe(t&255),Os=t=>oe(t>>>16)+zs(t),ie=Le((t,e,n="")=>{const r=Nr("0",e);return s=>(s=(s>>>0).toString(t),n+(s.length<e?r.substring(s.length)+s:s))});ie(2,8),ie(2,16),ie(2,32);const mn=Os,ae=t=>{const e=t>>>24;return e<255?`rgba(${t>>16&255},${t>>8&255},${t&255},${At(e*M)})`:`#${mn(t&16777215)}`},Es=t=>(t&255)<<16|t>>16&255|t&4278255360,W=(t,e)=>R(t||e,Zt(e[0]),Zt(e[1]),Zt(e[2]),$(e[3])),ce=(t,e=0)=>(t<0?0:t>1?1:t)*255+.5<<e,Y=t=>{const e=ce(t[0]),n=ce(t[1]),r=ce(t[2]),s=$(t[3]);return s<1?`rgba(${e},${n},${r},${At(s)})`:`#${mn(e<<16|n<<8|r)}`},yn={abgr32:t=>ae(Es(t[0])),argb32:t=>ae(t[0]),hsl:dn,hsv:xs,lab50:t=>Y(W(null,tt([],t))),lab65:t=>Y(W(null,cn([],t))),lch:t=>Y(W(null,tt(null,te([],t)))),rgb:t=>Y(W([],t)),srgb:Y};({...yn});let Fs=yn;const bn=(t,e=Fs)=>{let n;return P(t)?t:q(t)?ae(t):t.mode?(n=e[t.mode])?n(t):e.rgb(Je([],t,"rgb",t.mode)):Y(t)},Ds=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2],s=2*r,i=(s+n*(1-Math.abs(s-1)))*.5;return t[1]=2*(i-r)/i,t[2]=i,t},Ns=(t,e)=>{t=$s(t||e,e);const n=t[1]<t[2]?[t[2],t[1],-1,2/3]:[t[1],t[2],0,-1/3],r=t[0]<n[0]?[n[0],n[1],n[3],t[0]]:[t[0],n[1],n[2],n[0]],s=r[0]-Math.min(r[1],r[3]);return v(t,y(Math.abs((r[3]-r[1])/(6*s+I)+r[2])),y(s),y(r[0]))},le=(t,e)=>(t=Ns(t,e),t[1]/=t[2]+I,t),Ts=pt({mode:"hsv",channels:{h:{hue:!0}},order:["h","s","v","alpha"],from:{rgb:le,srgb:le,hsl:Ds,lch:[te,tt,W,le]},toRgb:Kt}),Ct=(t,e=1)=>{const n=(a,o,c)=>{!a&&(a=o);for(let l=o.length;l-- >0;)a[l]=t(o[l],c);return a},r=(a,o,c)=>(!a&&(a=o),a[0]=t(o[0],c),a[1]=t(o[1],c),a),s=(a,o,c)=>(!a&&(a=o),a[0]=t(o[0],c),a[1]=t(o[1],c),a[2]=t(o[2],c),a),i=(a,o,c)=>(!a&&(a=o),a[0]=t(o[0],c),a[1]=t(o[1],c),a[2]=t(o[2],c),a[3]=t(o[3],c),a);return[G(e,n,r,s,i),r,s,i]},[bi,Ai,qs]=Ct(Math.pow),Ps=qs,js=[.4122214708,.2119034982,.0883024619,.5363325363,.6806995451,.2817188376,.0514459929,.1073969566,.6299787005],Ls=(t,e)=>$t(null,Yr,Ps(null,$t(t,js,e),1/3)),An=(t,e)=>R(t||e,e[0],Math.hypot(e[1],e[2]),on(e[2],e[1])*$r,$(e[3])),Hs=pt({mode:"oklch",channels:{c:{range:[0,.3225]}},order:["l","c","h","alpha"],from:{oklab:An,rgb:(t,e)=>An(null,Ls(t,e))},toRgb:[(t,e)=>R(t||e,e[0],...Qt(e[2]*k,e[1]),$(e[3])),ln]}),_n=pt({mode:"srgb",order:["r","g","b","alpha"],from:{abgr32:(t,e)=>tn(t,e[0]),argb32:(t,e)=>_t(t,e[0]),hcy:nn,hsi:rn,hsl:sn,hsv:Kt,rgb:W},toRgb:Rt}),Ws=(t,e)=>t===e?0:t==null?e==null?0:-1:e==null?t==null?0:1:typeof t.compare=="function"?t.compare(e):typeof e.compare=="function"?-e.compare(t):t<e?-1:t>e?1:0,Ys=t=>typeof t=="function"?t:e=>e[t];function pn(t,e=Ws){const n=Ys(t);return(r,s)=>e(n(r),n(s))}const Vs=(t,e)=>e-t,he=(t,e=1,n=!0)=>{const r=n?(o,c,l)=>{!o&&(o=c);for(let h=c.length;h-- >0;)o[h]=t(c[h],l[h]);return o}:(o,c,l)=>{!o&&(o=l);for(let h=c.length;h-- >0;)o[h]=t(c[h],l[h]);return o},s=n?(o,c,l)=>(!o&&(o=c),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o):(o,c,l)=>(!o&&(o=l),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o),i=n?(o,c,l)=>(!o&&(o=c),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o):(o,c,l)=>(!o&&(o=l),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o),a=n?(o,c,l)=>(!o&&(o=c),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o[3]=t(c[3],l[3]),o):(o,c,l)=>(!o&&(o=l),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o[3]=t(c[3],l[3]),o);return[G(e,r,s,i,a),s,i,a]},Xs=(t,e)=>t+e,Ks=(t,e)=>t*e,Zs=(t,e)=>t-e,[Js,Qs]=he(Xs),wn=Js,to=Qs,eo=Object.freeze([0,0]),no=Object.freeze([0,0,0]),Rn=Math.cos,$n=Math.sin,Cn=G(1);Cn.add(2,(t,e,n=eo)=>to(t||e,Qt(e[1],e[0]),n)),Cn.add(3,(t,e,n=no)=>{const r=e[0],s=e[1],i=e[2],a=Rn(s);return v(t||e,r*a*Rn(i)+n[0],r*a*$n(i)+n[1],r*$n(s)+n[2])});const ro=(t,e)=>{const n=[];for(const r of t)n.push(Qt(r,e));return n},so=t=>_(t.length>0,"no inputs given"),[oo]=Ct(Ks),Sn=oo,io=G(0,t=>{let e=0;for(let n=t.length;n-- >0;)e+=t[n];return e},t=>t[0]+t[1],t=>t[0]+t[1]+t[2],t=>t[0]+t[1]+t[2]+t[3]),ao=(t,e)=>{so(e),t=Zr(t||[],e[0]);for(let n=e.length;n-- >1;)wn(t,t,e[n]);return Sn(t,t,1/e.length)},fe=t=>t.length>0?io(t)/t.length:0,[co]=Ct(Zs),lo=co,vn=(t,e)=>lo(t,e,fe(e)),ho=t=>on(t[1],t[0]),fo=G(0,t=>{let e=0;for(let n=t.length;n-- >0;)e+=t[n]*t[n];return e},t=>t[0]*t[0]+t[1]*t[1],t=>t[0]*t[0]+t[1]*t[1]+t[2]*t[2],t=>t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]),uo=(t,e=!1,n=!1)=>{const r=~~n;return t.length>r?fo(e?t:vn([],t))/(t.length-r):0},ue=(t,e=!1,n=!1)=>Math.sqrt(uo(t,e,n)),de=t=>ho(ao([],ro(t))),go=(t,e)=>{const n=de(e);!t&&(t=[]);for(let r=0,s=e.length;r<s;r++)t[r]=(e[r]-n+Oe)%k;return vn(null,t)},mo=(t,e)=>ue(go([],t),!0,e);he(Math.max);const yo=t=>{let e=-1/0;for(let n=t.length;n-- >0;)e=Math.max(e,t[n]);return e},ge=t=>{if(!t.length)return 0;const e=t.length,n=e>>1;return t=[...t].sort((r,s)=>r-s),e&1?t[n]:(t[n-1]+t[n])*.5};he(Math.min);const bo=t=>{let e=1/0;for(let n=t.length;n-- >0;)e=Math.min(e,t[n]);return e},Ao=t=>{const[e,n]=ye(t);return{min:e,max:n,mean:fe(t),median:ge(t),sd:ue(t)}},me=(t,e)=>{const[n,r]=ye(t);return{min:n,max:r,mean:fe(t),median:ge(t),sd:ue(t),weighted:Dr(t,e)}},_o=t=>{const e=t.map(i=>i*k),n=p(de(e)/k),[r,s]=po(t,n);return{min:r,max:s,mean:n,median:wo(t,r,s),sd:mo(e)/k}},ye=t=>[bo(t),yo(t)],po=(t,e)=>{const n=ye(t),[r,s]=n;return e<r||e>s?[t.reduce((i,a)=>{const o=p(e-a);return o<.5&&o>i[1]?[a,o]:i},[s,p(e-s)])[0],t.reduce((i,a)=>{const o=p(a-e);return o<.5&&o>i[1]?[a,o]:i},[r,p(r-e)])[0]]:n},wo=(t,e,n)=>{if(e<=n)return ge(t);const r=t.length,s=r>>1,i=[...t].sort((c,l)=>c-l),a=i.findIndex(c=>c===e),o=i.slice(a).concat(i.slice(0,a));return r&1?o[s]:(o[s-1]+o[s])*.5},Ro=t=>typeof t=="function",$o=G(0,(t,e)=>{let n=0;for(let r=t.length;r-- >0;){const s=t[r]-e[r];n+=s*s}return n},(t,e)=>{const n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},(t,e)=>{const n=t[0]-e[0],r=t[1]-e[1],s=t[2]-e[2];return n*n+r*r+s*s},(t,e)=>{const n=t[0]-e[0],r=t[1]-e[1],s=t[2]-e[2],i=t[3]-e[3];return n*n+r*r+s*s+i*i});class Co{constructor(e){this.metric=e}to(e){return e*e}from(e){return Math.sqrt(e)}}const be=new Co($o),Bn=(t,e,n=be)=>{const r=Ro(n)?n:n.metric;let s=1/0,i=-1;for(let a=0,o=e.length;a<o;a++){const c=r(t,e[a]);c<s&&(s=c,i=a)}return i};G(0,(t,e)=>{for(let n=t.length;n-- >0;)t[n]=e;return t},(t,e)=>(t[0]=e,t[1]=e,t),(t,e)=>(t[0]=e,t[1]=e,t[2]=e,t),(t,e)=>(t[0]=e,t[1]=e,t[2]=e,t[3]=e,t));const So=t=>Array(t).fill(0),vo=t=>Array(t).fill(1),Bo=(t,e,n={})=>{let{dim:r=e[0].length,dist:s=be,maxIter:i=32,strategy:a=Io,exponent:o,initial:c,rnd:l}=n;const h=e.length,u=Array.isArray(c)?c:c?c(t,e,s,l):ko(t,e,s,l,o);_(u.length>0,"missing initial centroids"),t=u.length;const f=new Uint32Array(h).fill(t);let d=!0;for(;d&&i-- >0&&(d=Go(e,u,f,s),!!d);)for(let g=0;g<t;g++){const m=a(r);for(let A=0;A<h;A++)g===f[A]&&m.update(e[A]);const b=m.finish();b&&(u[g]=b)}return Mo(u,f)},ko=(t,e,n=be,r=Yt,s=2)=>{const i=e.length;_(i>0,"missing samples"),t=Math.min(t,i);const a=[r.int()%i],o=[e[a[0]]],c=new Array(i).fill(0).map((h,u)=>u),l=n.metric;for(;a.length<t;){let h=0;const u=e.map(d=>{const g=n.from(l(d,o[Bn(d,o,n)]))**s;return h+=g,g});if(!h)break;let f;do f=ds(c,u,r)();while(a.includes(f));a.push(f),o.push(e[f])}return o},Go=(t,e,n,r)=>{let s=!1;for(let i=t.length;i-- >0;){const a=Bn(t[i],e,r);a!==n[i]&&(n[i]=a,s=!0)}return s},Mo=(t,e)=>{const n=[];for(let r=0,s=e.length;r<s;r++){const i=e[r];(n[i]||(n[i]={id:i,centroid:t[i],items:[]})).items.push(r)}return n.filter(r=>!!r)},Io=t=>{const e=So(t);let n=0;return{update:r=>{wn(e,e,r),n++},finish:()=>n?Sn(e,e,1/n):void 0}},Uo=(t,e)=>{const n=[];let r=0;for(const s of e)t(s,r)&&n.push(s),r++;return n},kn=(t,e,n)=>{const r=n?.filter?Uo(n.filter,t):Array.isArray(t)?t:[...t];return r.length?Bo(Math.min(e,r.length),r,n).sort((s,i)=>i.items.length-s.items.length).map(s=>({color:[...s.centroid],area:s.items.length/r.length,ids:s.items})):[]},Ae=t=>typeof t?.[Symbol.iterator]=="function",Gn=(t,e)=>[t[0],t[1],e],_e=Symbol(),Mn=()=>{},St=t=>J(t,"xform")?t.xform():t,xo=ot(()=>"illegal arity"),pe=t=>{throw new xo(t)};class vt{value;constructor(e){this.value=e}deref(){return this.value}}const V=t=>t instanceof vt,zo=t=>t instanceof vt?t:new vt(t),et=t=>t instanceof vt?t.deref():t,Oo=t=>t.length===2?[void 0,t[1]]:t.length===3?[t[1],t[2]]:pe(t.length);function Bt(...t){const e=t[0],n=e[0],r=e[1],s=e[2];t=Oo(t);const i=t[0]==null?n():t[0],a=t[1];return et(r(J(a,"$reduce")?a.$reduce(s,i):Ht(a)?Eo(s,i,a):Fo(s,i,a)))}const Eo=(t,e,n)=>{for(let r=0,s=n.length;r<s;r++)if(e=t(e,n[r]),V(e)){e=e.deref();break}return e},Fo=(t,e,n)=>{for(const r of n)if(e=t(e,r),V(e)){e=e.deref();break}return e},we=(t,e)=>[t,it,e],kt=(t,e)=>{const n=e.length-1;return Ae(e[n])?e.length>1?Bt(t.apply(null,e.slice(0,n)),e[n]):Bt(t(),e[0]):void 0};function In(t){return t?[...t]:we(()=>[],(e,n)=>(e.push(n),e))}function*Do(t,e){const n=St(t)(In()),r=n[1],s=n[2];for(const i of e){const a=s([],i);if(V(a)){yield*et(r(a.deref()));return}a.length&&(yield*a)}yield*et(r([]))}function*No(t,e){const n=St(t)([Mn,Mn,(r,s)=>s])[2];for(const r of e){let s=n(_e,r);if(V(s)){s=et(s.deref()),s!==_e&&(yield s);return}s!==_e&&(yield s)}}function nt(t,e){return Ae(e)?No(nt(t),e):n=>{const r=n[2];return Gn(n,(s,i)=>r(s,t(i)))}}function Un(t){return t?Bt(Un(),t):we(()=>-1/0,(e,n)=>Math.max(e,n))}function*To(...t){const e=t.length-1;if(e<0)return;const n=new Array(e+1).fill(0),r=t.map(Is),s=r.reduce((i,a)=>i*a.length,1);for(let i=0;i<s;i++){const a=[];for(let o=e;o>=0;o--){const c=r[o];let l=n[o];l===c.length&&(n[o]=l=0,o>0&&n[o-1]++),a[o]=c[l]}n[e]++,yield a}}function Re(...t){return qo(Re,Bt,t)}const qo=(t,e,n)=>{let r,s;switch(n.length){case 4:s=n[3],r=n[2];break;case 3:s=n[2];break;case 2:return nt(i=>t(n[0],n[1],i));default:pe(n.length)}return e(St(n[0])(n[1]),r,s)},[Po]=Ct(De),jo=Po,xn=(t,e,n)=>Lo(y((n-t)/(e-t))),Lo=t=>t*t*(3-2*t);function zn(...t){let[e,n,r,s,i,a,o,c,l,h]=t;switch(t.length){case 0:pe(0);case 1:return e;case 2:return(...f)=>e(n(...f));case 3:return(...f)=>e(n(r(...f)));case 4:return(...f)=>e(n(r(s(...f))));case 5:return(...f)=>e(n(r(s(i(...f)))));case 6:return(...f)=>e(n(r(s(i(a(...f))))));case 7:return(...f)=>e(n(r(s(i(a(o(...f)))))));case 8:return(...f)=>e(n(r(s(i(a(o(c(...f))))))));case 9:return(...f)=>e(n(r(s(i(a(o(c(l(...f)))))))));default:const u=(...f)=>e(n(r(s(i(a(o(c(l(h(...f))))))))));return t.length===10?u:zn(u,...t.slice(10))}}function Ho(...t){return t=t.map(St),zn.apply(null,t)}function On(...t){const e=kt(On,t);if(e!==void 0)return e;const[n=0,r=1]=t;return we(()=>n,(s,i)=>s+r)}const Wo=t=>t,Yo=t=>({key:e=>e,group:In(),...t});function En(...t){const e=kt(En,t);if(e!==void 0)return e;const n=Yo(t[0]),[r,s,i]=n.group;return[()=>new Map,a=>{for(const o of a.keys())a.set(o,s(a.get(o)));return a},(a,o)=>{const c=n.key(o);return a.set(c,a.has(c)?i(a.get(c),o):i(r(),o))}]}function Fn(...t){return kt(Fn,t)||En({key:t[0]||Wo,group:On()})}function Dn(...t){const e=kt(Dn,t);if(e!==void 0)return e;const[n,r,s]=Fn(...t);let i=0;return[n,a=>{a=r(a);for(const o of a)a.set(o[0],o[1]/i);return a},(a,o)=>(i++,s(a,o))]}const Vo=()=>t=>{const e=t[2];return Gn(t,(n,r)=>{if(r){for(const s of et(r)||[])if(n=e(n,s),V(n))break}return V(r)?zo(n):n})};function Nn(t,e){return Ae(e)?Do(Nn(t),e):Ho(nt(t),Vo())}function*Xo(t,e=1/0){for(;e-- >0;)yield t}const Tn=(t,e=.2,n)=>{const r=Ms(t),s=r.filter(u=>u[1]>=e),i=s.length/r.length,a=[...Re(nt(u=>De(u[0],1/12)%1),Dn(),s)].sort(pn(0)),o=[...Nn(([u,f])=>(f*=50,f>=1?Xo(u*k,f):null),a)];if(!o.length)return{hues:a,meanHue:0,temp:0,areaTemp:0,area:0};const c=de(o)/k,l=Zo(c,n),h=l*i;return{hues:a,meanHue:c,temp:l,areaTemp:h,area:i}},Ko=[.1,.6,.72,.92],Zo=(t,[e,n,r,s]=Ko)=>2*(t<2/3?xn(n,e,t):xn(r,s,t))-1,Jo=(t,e)=>{let n=t.format!==j?t.as(j):t;e?.size&&(n=ei(n,e.size));const r=n.as(Ue),s=n.as(Or),i=ti(n,e),a=i.map(l=>l.area),o=Qo(i.map(l=>l.color),a,e?.minSat,e?.tempCoeffs),c=Ao(r.data);return{...o,img:n,imgGray:r,imgHsv:s,lumImg:c,temperature:Tn(s,e?.minSat,e?.tempCoeffs),contrastImg:c.max-c.min}},Qo=(t,e=vo(t.length),n,r)=>{const s=t.map(f=>Vr(f)),i=t.map(f=>_n(f)),a=i.map(f=>Ts(f)),o=i.map(f=>Hs(f)),c=i.map(f=>bn(f)),l=a.map(f=>f[0]),h=a.map(f=>f[1]),u=me(s,e);return{css:c,srgb:i,hsv:a,oklch:o,hue:_o(l),sat:me(h,e),chroma:me(o.map(f=>f[1]),e),lum:u,areas:e,contrast:u.max-u.min,colorContrast:xr(Re(nt(f=>Gs(...f)),Un(),To(i,i)),1,21,0,1),temperature:Tn(a,n,r)}},ti=(t,{dominantFn:e=kn,numColors:n=4,prec:r=.001}={})=>e(t,n).sort(pn("area",Vs)).map(s=>(jo(null,s.color,r),s)),ei=(t,e)=>{e=~~e;let n=t.width,r=t.height;return[n,r]=n>r?[e,~~Math.max(1,r/n*e)]:[~~Math.max(1,n/r*e),e],t.resize(n,r)};const ni={numColors:3,lightnessThreshold:.5,yFrom:0,yTo:1,maxSize:320,alphaThreshold:30};const ri=(t,e,n,r={})=>{const{alphaThreshold:s}={...ni,...r},i={any:!0,left:!0,right:!0,top:!0,bottom:!0};let a={any:0,left:0,right:0,top:0,bottom:0};const o=Math.floor(.15*e),c=Math.floor((n>100?.05:.5)*n),l=Math.floor(e*n*.001);if(e>0&&n>0){for(let h=0;h<e;h++){const u=(0*e+h)*4+3;if(t[u]>s&&(a.top++,a.top>=o)){i.top=!1;break}}for(let h=0;h<e;h++){const u=((n-1)*e+h)*4+3;if(t[u]>s&&(a.bottom++,a.bottom>=o)){i.bottom=!1;break}}for(let h=0;h<n;h++){const u=(h*e+0)*4+3;if(t[u]>s&&(a.left++,a.left>=c)){i.left=!1;break}}for(let h=0;h<n;h++){const u=(h*e+(e-1))*4+3;if(t[u]>s&&(a.right++,a.right>=c)){i.right=!1;break}}if(!i.top&&!i.bottom&&!i.left&&!i.right){for(let h=3;h<t.length;h+=4)if(t[h]>s&&(a.any++,a.any>=l)){i.any=!1;break}}else i.any=!0}return i};const si=(t,e,n,r=.5)=>(.299*t+.587*e+.114*n)/255<r;const oi=({buffer:t,imageData:e,width:n,height:r,settings:s,skipTransparencyCheck:i=!1})=>{const{numColors:a,lightnessThreshold:o}=s,c=Jo(t,{numColors:a,dominantFn:(d,g)=>kn(d,g,{filter:m=>_n(m).alpha>0}),prec:.01}),{lumImg:l,srgb:h,areas:u}=c;let f=!1;return!i&&e&&(f=ri(e,n,r,s)),{isDark:l.mean<o,isTransparent:i?!1:f?.any,transparencyInfo:i?null:f,dominantColors:h.map(({r:d,g,b:m},b)=>({color:bn([d,g,m]),area:u?.[b],isDark:si(d*255,g*255,m*255,o)}))}};self.onmessage=async t=>{const{imageBitmap:e,settings:n}=t.data;try{const r=await ii(e,n);self.postMessage({success:!0,data:r})}catch(r){self.postMessage({success:!1,error:r.message,stack:r.stack})}};async function ii(t,e){const r={...{numColors:3,lightnessThreshold:.5,yFrom:0,yTo:1,maxSize:600,alphaThreshold:50},...e},{yFrom:s,yTo:i,maxSize:a}=r,o=t.width,c=t.height;if(!o||!c)return!1;let l=1;(o>a||c>a)&&(l=Math.min(a/o,a/c));const h=Math.floor(o*l),u=Math.floor(c*l),f=0,d=Math.floor(s*c),g=Math.max(1,o),m=Math.max(1,Math.ceil((i-s)*c)),b=Math.max(1,h),A=Math.max(1,Math.ceil((i-s)*u)),E=new OffscreenCanvas(b,A);E.getContext("2d").drawImage(t,f,d,g,m,0,0,b,A);const Gt=Ir(E,j),qn=new OffscreenCanvas(h,u).getContext("2d");qn.drawImage(t,0,0,o,c,0,0,h,u);const ai=qn.getImageData(0,0,h,u).data;return oi({buffer:Gt,imageData:ai,width:h,height:u,settings:r})}})();\n';
1
+ const workerInline = '(function(){"use strict";var w=(t=>(t[t.ALPHA=0]="ALPHA",t[t.BLUE=1]="BLUE",t[t.GREEN=2]="GREEN",t[t.RED=3]="RED",t))(w||{});const $e=["rotateCW","rotate180","rotateCCW"],Pn=(t,e=t,n,r={})=>{const s=document.createElement("canvas");return Ln(s,t,e,r.dpr),r.pixelated&&(s.style.imageRendering="pixelated"),{canvas:s,ctx:s.getContext("2d",r.ctx)}},jn=(t,e=t,n,r)=>Pn(t,e,n,{dpr:1,...r}),Ln=(t,e,n,r=window.devicePixelRatio||1)=>(r!==1&&(t.style.width=`${e}px`,t.style.height=`${n}px`),t.dataset.origWidth=String(e),t.dataset.origHeight=String(n),t.dataset.dpr=String(r),t.width=e*r,t.height=n*r,r),q=t=>typeof t=="number";function Hn(t,e,n,r){let s,i;if(q(t)){const c=jn(t,e,n,r);s=c.canvas,i=c.ctx}else s=t,i=s.getContext("2d");const a=i.getImageData(0,0,s.width,s.height),o=new Uint32Array(a.data.buffer);return{canvas:s,ctx:i,img:a,data:o}}const rt=(t,e,n)=>{n.configurable=!1},st=(t,e={})=>{const n=Reflect.ownKeys(t),r=Reflect.ownKeys(e),s=Symbol("isa");function i(a){for(const o of n){const c=Object.getOwnPropertyDescriptor(a.prototype,o);(!c||c.configurable)&&Object.defineProperty(a.prototype,o,{value:t[o],writable:!0})}return Object.defineProperty(a.prototype,s,{value:!0}),a}for(const a of r)Object.defineProperty(i,a,{value:e[a],enumerable:e.propertyIsEnumerable(a)});return Object.defineProperty(i,Symbol.hasInstance,{value:a=>!!a[s]}),i};st({order(){return[0]},includes(t){return t>=0&&t<this.size[0]},indexAt(t){return this.includes(t)?this.indexAtUnsafe(t):-1},indexAtUnsafe(t){return this.offset+(t|0)*this.stride[0]},getAt(t){return this.includes(t)?this.data[this.indexAtUnsafe(t)]:0},getAtUnsafe(t){return this.data[this.indexAtUnsafe(t)]},setAt(t,e){return this.includes(t)?(this.data[this.indexAtUnsafe(t)]=e,!0):!1},setAtUnsafe(t,e){return this.data[this.indexAtUnsafe(t)]=e,!0}});const Ce=st({order(){return Math.abs(this.stride[1])>Math.abs(this.stride[0])?[1,0]:[0,1]},includes(t,e){const n=this.size;return t>=0&&t<n[0]&&e>=0&&e<n[1]},indexAt(t,e){return this.includes(t,e)?this.indexAtUnsafe(t,e):-1},indexAtUnsafe(t,e){return this.offset+(t|0)*this.stride[0]+(e|0)*this.stride[1]},getAt(t,e){return this.includes(t,e)?this.data[this.indexAtUnsafe(t,e)]:0},getAtUnsafe(t,e){return this.data[this.indexAtUnsafe(t,e)]},setAt(t,e,n){return this.includes(t,e)?(this.data[this.indexAtUnsafe(t,e)]=n,!0):!1},setAtUnsafe(t,e,n){return this.data[this.indexAtUnsafe(t,e)]=n,!0}});st({order(){return Se(this.stride)},includes(t,e,n){const r=this.size;return t>=0&&t<r[0]&&e>=0&&e<r[1]&&n>=0&&n<r[2]},indexAt(t,e,n){return this.includes(t,e,n)?this.indexAtUnsafe(t,e,n):-1},indexAtUnsafe(t,e,n){const r=this.stride;return this.offset+(t|0)*r[0]+(e|0)*r[1]+(n|0)*r[2]},getAt(t,e,n){return this.includes(t,e,n)?this.data[this.indexAtUnsafe(t,e,n)]:0},getAtUnsafe(t,e,n){return this.data[this.indexAtUnsafe(t,e,n)]},setAt(t,e,n,r){return this.includes(t,e,n)?(this.data[this.indexAtUnsafe(t,e,n)]=r,!0):!1},setAtUnsafe(t,e,n,r){return this.data[this.indexAtUnsafe(t,e,n)]=r,!0}}),st({order(){return Se(this.stride)},includes(t,e,n,r){const s=this.size;return t>=0&&t<s[0]&&e>=0&&e<s[1]&&n>=0&&n<s[2]&&r>=0&&r<s[3]},indexAt(t,e,n,r){return this.includes(t,e,n,r)?this.indexAtUnsafe(t,e,n,r):-1},indexAtUnsafe(t,e,n,r){const s=this.stride;return this.offset+(t|0)*s[0]+(e|0)*s[1]+(n|0)*s[2]+(r|0)*s[3]},getAt(t,e,n,r){return this.includes(t,e,n,r)?this.data[this.indexAtUnsafe(t,e,n,r)]:0},getAtUnsafe(t,e,n,r){return this.data[this.indexAtUnsafe(t,e,n,r)]},setAt(t,e,n,r,s){return this.includes(t,e,n,r)?(this.data[this.indexAtUnsafe(t,e,n,r)]=s,!0):!1},setAtUnsafe(t,e,n,r,s){return this.data[this.indexAtUnsafe(t,e,n,r)]=s,!0}});const Se=t=>[...t].map((e,n)=>[e,n]).sort((e,n)=>Math.abs(n[0])-Math.abs(e[0])).map(e=>e[1]),P=t=>typeof t=="string",ot=(t,e=n=>n!==void 0?": "+n:"")=>class extends Error{origMessage;constructor(n){super(t(n)+e(n)),this.origMessage=n!==void 0?String(n):""}},Wn={};var ve={};const Yn=ot(()=>"Assertion failed"),_=(typeof process<"u"&&ve!==void 0?ve.UMBRELLA_ASSERTS:!Wn)?(t,e)=>{if(typeof t=="function"&&!t()||!t)throw new Yn(typeof e=="function"?e():e)}:()=>{},B=(t,e,n)=>t<e?e:t>n?n:t,y=t=>t<0?0:t>1?1:t,Be=(t,e,n,r,s)=>(t[0]=e,t[1]=n,t[2]=r,t[3]=s,t),Vn=(t,e)=>{const n=e[3];return Be(e,e[0]*n,e[1]*n,e[2]*n,n)},Xn=t=>{const e=(t>>>24)/255;return t&4278190080|(t>>>16&255)*e<<16|(t>>>8&255)*e<<8|(t&255)*e},Kn=(t,e)=>{const n=e[3];return n>0?Be(e,e[0]/n,e[1]/n,e[2]/n,n):e},Zn=t=>{const e=(t>>>24)/255;return e>0?(t&4278190080|Math.min(255,(t>>>16&255)/e)<<16|Math.min(255,(t>>>8&255)/e)<<8|Math.min(255,(t&255)/e))>>>0:t},Jn=t=>{const e=t[3];return t[0]<=e&&t[1]<=e||t[2]<=e},Qn=t=>{const e=t>>>24;return(t>>>16&255)<=e&&(t>>>8&255)<=e&&(t&255)<=e},ke=(t,e,n,r=1)=>_(t.length>=e*n*r,"pixel buffer too small"),Ge=(t,e,n)=>t?(Mt(t,e,n),t):new ImageData(e,n),Mt=(t,e,n)=>_(t.width===e&&t.height===n,"imagedata has wrong dimensions"),O=(t,e)=>{const n=t.channels[e];return _(n!=null,`invalid channel ID: ${e}`),n},tr=t=>_(!!t.alpha,"missing alpha channel"),it=t=>t,It=t=>((t>>>16&255)*29+(t>>>8&255)*150+(t&255)*76)/255,at=(t,e,n,r,s,i,a=0,o=0)=>(t|=0,e|=0,n|=0,r|=0,t<0&&(n+=t,a-=t,t=0),e<0&&(r+=e,o-=e,e=0),[t,e,B(n,0,s-t),B(r,0,i-e),a,o]),ct=(t,e,n={})=>{const r=t.width,s=e.width;let i,a,o,c,l,h;return[i,a,l,h]=at(n.sx||0,n.sy||0,n.w||r,n.h||t.height,r,t.height),[o,c,l,h,i,a]=at(n.dx||0,n.dy||0,l,h,s,e.height,i,a),{sx:i,sy:a,dx:o,dy:c,rw:l,rh:h}},er=(t,e,n)=>{for(let r=t.length;r-- >0;)t[r]=n(t[r],e)},nr=(t,e,n,r)=>{for(let s=t.length;s-- >0;)t[s]=r(t[s],n(e[s]))},rr=(t,e,n,r,s)=>{const i=~s;for(let a=t.length;a-- >0;)t[a]=t[a]&i|n(r(e[a]))&s},Me=(t,e,n)=>{const r=e.fromABGR,s=e.toABGR;for(let i=t.length;i-- >0;)t[i]=r(n(s(t[i])))},Ie=(t,e,n={})=>(e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):e).putImageData(t.toImageData(n.data),n.x||0,n.y||0),lt=t=>{const e=t.channels,n=e.reduce((a,o)=>(a[o]=3-o<<3,a),{}),r={...t,__float:!0,size:e.length,shift:n,range:[0,1],normalized:y,fromNormalized:it};if(t.convert)return Object.assign(r,t.convert),r;const s=(a,o)=>(y(a[o])*255+.5|0)<<n[e[o]],i=(a,o)=>(a>>>n[e[o]]&255)/255;switch(e.length){case 1:t.gray?or(r):sr(r,i,s);break;case 2:t.gray?ar(r,i):ir(r,i,s);break;case 3:cr(r,i,s);break;case 4:lr(r,i,s);break}return r},sr=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s)},or=t=>{t.toABGR=e=>((y(e[0])*255+.5|0)*65793|4278190080)>>>0,t.fromABGR=(e,n=[])=>(n[0]=It(e)/255,n)},ir=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s|=n(r,1),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s[1]=e(r,1),s)},ar=(t,e)=>{const n=~~(t.channels[0]===w.ALPHA),r=n^1;t.toABGR=s=>{let i=(y(s[n])*255+.5|0)*65793;return i|=(s[r]*255+.5|0)<<24,i>>>0},t.fromABGR=(s,i=[])=>(i[n]=It(s)/255,i[r]=e(s,r),i)},cr=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s|=n(r,1),s|=n(r,2),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s[1]=e(r,1),s[2]=e(r,2),s)},lr=(t,e,n)=>{t.toABGR=r=>{let s=t.alpha?0:4278190080;return s|=n(r,0),s|=n(r,1),s|=n(r,2),s|=n(r,3),s>>>0},t.fromABGR=(r,s=[])=>(s[0]=e(r,0),s[1]=e(r,1),s[2]=e(r,2),s[3]=e(r,3),s)},Ue=lt({gray:!0,channels:[w.RED]}),hr={5120:"i8",5121:"u8",5122:"i16",5123:"u16",5124:"i32",5125:"u32",5126:"f32"},fr={f32:Float32Array,f64:Float64Array},ur={i8:Int8Array,i16:Int16Array,i32:Int32Array},dr={u8:Uint8Array,u8c:Uint8ClampedArray,u16:Uint16Array,u32:Uint32Array},gr={i64:BigInt64Array,u64:BigUint64Array},mr={...fr,...ur,...dr},yr=t=>{const e=hr[t];return e!==void 0?e:t};function ht(t,...e){const n=gr[t];return new(n||mr[yr(t)])(...e)}const br=t=>t>16?"u32":t>8?"u16":"u8",Ut=(t,e)=>e>0?`(${t} << ${e})`:e<0?`(${t} >>> ${-e})`:`${t}`,xt=(t,e)=>Ut(t,-e),xe=t=>`0x${t.toString(16)}`,Ar=t=>{const e=8-t,n=(1<<t)-1;return new Function("luma",`return (x) => ${xt("luma(x)",e)} & ${n};`)(It)},_r=t=>{let e;if(t!==8){const n=(1<<t)-1,r=255/n;e=`(((x & ${n}) * ${r}) | 0)`}else e="x";return new Function("x",`return 0xff000000 | (${e} * 0x010101);`)},pr=t=>new Function("x","return ("+t.map(e=>{const n=e.abgrShift+(8-e.size);return`(${xt("x",n)} & ${xe(e.maskA)})`}).join(" | ")+") >>> 0;"),wr=(t,e)=>{const n=t.map(s=>{if(s.size!==8){const i=s.mask0,a=255/i,o=xt("x",s.shift);return Ut(`((${o} & ${i}) * ${a})`,24-s.lane*8)}else return Ut(`(x & ${xe(s.maskA)})`,s.abgrShift)}).join(" | "),r=e?"":"0xff000000 | ";return new Function("x",`return (${r}${n}) >>> 0;`)},Rr=(t,e,n)=>{const r=1<<t.size,s=r-1,i=s<<n>>>0,a=~i>>>0,o=t.lane!=null?t.lane:e,c=h=>h>>>n&s,l=(h,u)=>h&a|(u&s)<<n;return{size:t.size,num:r,abgrShift:24-o*8-n,lane:o,shift:n,mask0:s,maskA:i,int:c,setInt:l,float:h=>c(h)/s,setFloat:(h,u)=>l(h,y(u)*s)}},ze=t=>{_(t.channels.length>0,"no channel specs given");const e=t.channels.reduce(([n,r],s,i)=>(r-=s.size,n.push(Rr(s,i,r)),[n,r]),[[],t.size])[0];return{__packed:!0,type:t.type,size:t.size,alpha:t.alpha||0,channels:e,fromABGR:t.fromABGR||pr(e),toABGR:t.toABGR||wr(e,!!t.alpha)}},zt=ze({type:"u32",size:32,alpha:8,channels:[{size:8,lane:w.ALPHA},{size:8,lane:w.BLUE},{size:8,lane:w.GREEN},{size:8,lane:w.RED}],fromABGR:it,toABGR:it}),Oe=Math.PI,k=Oe*2,$r=1/k;let I=1e-6;const Ee=(t,e,n,r,s,i)=>{const a=1-s,o=1-i;return t*a*o+e*s*o+n*a*i+r*s*i},X=(t,e,n,r,s)=>{r*=.5;const i=-.5*t+1.5*e-1.5*n+r,a=t-2.5*e+2*n-r,o=-.5*t+.5*n,c=e,l=s*s;return s*l*i+l*a+s*o+c},Fe=(t,e,n,r,s,i,a,o,c,l,h,u,f,d,g,m,b,A)=>X(X(t,e,n,r,b),X(s,i,a,o,b),X(c,l,h,u,b),X(f,d,g,m,b),A),ft=(t,e)=>t-e*Math.floor(t/e),p=t=>t-Math.floor(t),De=(t,e=1)=>Math.round(t/e)*e;function Ne(t,e="linear",n="clamp"){const r=!!t.format.__float,s=t.format.channels.length===1?"1":"",i=`${e[0]}${n[0]}${s}`,a=(r?{nc1:ut,nw1:dt,nr1:gt,nc:ut,nw:dt,nr:gt,lc1:o=>Ot(F(o)),lw1:o=>Ot(D(o)),lr1:o=>Ot(N(o)),lc:o=>Ft(o,ut(o)),lw:o=>Ft(o,dt(o)),lr:o=>Ft(o,gt(o)),cc1:o=>Nt(F(o)),cw1:o=>Nt(D(o)),cr1:o=>Nt(N(o)),cc:o=>qt(o,ut(o)),cw:o=>qt(o,dt(o)),cr:o=>qt(o,gt(o))}:{nc1:F,nw1:D,nr1:N,nc:F,nw:D,nr:N,lc1:o=>mt(F(o)),lw1:o=>mt(D(o)),lr1:o=>mt(N(o)),lc:o=>Et(o,F(o)),lw:o=>Et(o,D(o)),lr:o=>Et(o,N(o)),cc1:o=>Dt(o,F(o)),cw1:o=>Dt(o,D(o)),cr1:o=>Dt(o,N(o)),cc:o=>Tt(o,F(o)),cw:o=>Tt(o,D(o)),cr:o=>Tt(o,N(o))})[i];return _(!!a,`missing impl for ${i}`),a(t)}const F=({data:t,width:e,height:n})=>(r,s)=>r>=0&&r<e&&s>=0&&s<n?t[(s|0)*e+(r|0)]:0,D=({data:t,width:e,height:n})=>(r,s)=>t[ft(s|0,n)*e+ft(r|0,e)],N=({data:t,width:e,height:n})=>{const r=e-1,s=n-1;return(i,a)=>t[B(a|0,0,s)*e+B(i|0,0,r)]},ut=({data:t,width:e,height:n,stride:[r,s]})=>(i,a)=>{let o;return i>=0&&i<e&&a>=0&&a<n?(o=(a|0)*s+(i|0)*r,t.slice(o,o+r)):[0]},dt=({data:t,width:e,height:n,stride:[r,s]})=>(i,a)=>{let o=ft(a|0,n)*s+ft(i|0,e)*r;return t.slice(o,o+r)},gt=({data:t,width:e,height:n,stride:[r,s]})=>{const i=e-1,a=n-1;return(o,c)=>{let l=B(c|0,0,a)*s+B(o|0,0,i)*r;return t.slice(l,l+r)}},K=(t,e,n,r,s=4)=>Ee(t[r],t[r+s],t[r+2*s],t[r+3*s],e,n),mt=t=>(e,n)=>(e-=.5,n-=.5,Ee(t(e,n),t(e+1,n),t(e,n+1),t(e+1,n+1),p(e),p(n))),Ot=t=>(t=mt(t),(e,n)=>[t(e,n)]),Et=(t,e)=>{const{fromABGR:n,toABGR:r}=t.format,s=new Uint32Array(4),i=new Uint8Array(s.buffer);return(a,o)=>{a-=.5,o-=.5,s[0]=r(e(a,o)),s[1]=r(e(a+1,o)),s[2]=r(e(a,o+1)),s[3]=r(e(a+1,o+1));const c=p(a),l=p(o);return n(K(i,c,l,0)|K(i,c,l,1)<<8|K(i,c,l,2)<<16|K(i,c,l,3)<<24)>>>0}},Ft=({stride:[t]},e)=>{const n=new Float32Array(t*4);return(r,s)=>{r-=.5,s-=.5,n.set(e(r,s),0),n.set(e(r+1,s),t),n.set(e(r,s+1),t*2),n.set(e(r+1,s+1),t*3);const i=p(r),a=p(s);let o=[];for(let c=0;c<t;c++)o.push(K(n,i,a,c,t));return o}},Te=t=>(e,n)=>{e-=.5,n-=.5;const r=e-1,s=e+1,i=e+2,a=n-1,o=n+1,c=n+2;return Fe(t(r,a),t(e,a),t(s,a),t(i,a),t(r,n),t(e,n),t(s,n),t(i,n),t(r,o),t(e,o),t(s,o),t(i,o),t(r,c),t(e,c),t(s,c),t(i,c),p(e),p(n))},Dt=(t,e)=>{const n=t.format.channels[0].mask0;return e=Te(e),(r,s)=>B(e(r,s),0,n)},Nt=t=>(t=Te(t),(e,n)=>[t(e,n)]),qe=(t,e,n,r,s=4)=>Fe(t[r],t[r+s],t[r+2*s],t[r+3*s],t[r+4*s],t[r+5*s],t[r+6*s],t[r+7*s],t[r+8*s],t[r+9*s],t[r+10*s],t[r+11*s],t[r+12*s],t[r+13*s],t[r+14*s],t[r+15*s],e,n),yt=(t,e,n,r,s=4)=>B(qe(t,e,n,r,s),0,255),Tt=(t,e)=>{const{fromABGR:n,toABGR:r}=t.format,s=new Uint32Array(16),i=new Uint8Array(s.buffer);return(a,o)=>{a-=.5,o-=.5;const c=a-1,l=a+1,h=a+2,u=o-1,f=o+1,d=o+2,g=p(a),m=p(o);return s[0]=r(e(c,u)),s[1]=r(e(a,u)),s[2]=r(e(l,u)),s[3]=r(e(h,u)),s[4]=r(e(c,o)),s[5]=r(e(a,o)),s[6]=r(e(l,o)),s[7]=r(e(h,o)),s[8]=r(e(c,f)),s[9]=r(e(a,f)),s[10]=r(e(l,f)),s[11]=r(e(h,f)),s[12]=r(e(c,d)),s[13]=r(e(a,d)),s[14]=r(e(l,d)),s[15]=r(e(h,d)),n(yt(i,g,m,0)|yt(i,g,m,1)<<8|yt(i,g,m,2)<<16|yt(i,g,m,3)<<24)>>>0}},qt=({stride:[t]},e)=>{const n=new Float32Array(t*16);return(r,s)=>{r-=.5,s-=.5;const i=r-1,a=r+1,o=r+2,c=s-1,l=s+1,h=s+2,u=p(r),f=p(s);n.set(e(i,c),0),n.set(e(r,c),t),n.set(e(a,c),2*t),n.set(e(o,c),3*t),n.set(e(i,s),4*t),n.set(e(r,s),5*t),n.set(e(a,s),6*t),n.set(e(o,s),7*t),n.set(e(i,l),8*t),n.set(e(r,l),9*t),n.set(e(a,l),10*t),n.set(e(o,l),11*t),n.set(e(i,h),12*t),n.set(e(r,h),13*t),n.set(e(a,h),14*t),n.set(e(o,h),15*t);let d=[];for(let g=0;g<t;g++)d.push(qe(n,u,f,g,t));return d}};var Cr=Object.getOwnPropertyDescriptor,Sr=(t,e,n,r)=>{for(var s=r>1?void 0:r?Cr(e,n):e,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=a(s)||s);return s};function vr(...t){return t[0]instanceof U?t[0].as(t[1]):new U(...t)}const Br=(t,e=zt)=>{const{data:n}=Hn(t),r=t.width,s=t.height;let i;if(e===zt)i=n;else{i=ht(e.type,r*s);const a=n,o=e.fromABGR;for(let c=i.length;c-- >0;)i[c]=o(a[c])}return new U(r,s,e,i)};let U=class{size;stride;format;data;constructor(t,e,n=zt,r){this.size=[t,e],this.stride=[1,t],this.format=n.__packed?n:ze(n),this.data=r||ht(n.type,t*e)}get pixels(){return this.data}get width(){return this.size[0]}get height(){return this.size[1]}get offset(){return 0}get dim(){return 2}*[Symbol.iterator](){yield*this.data}as(t){if(!t.__float)return this.getRegion(0,0,this.width,this.height,t);const e=new S(this.width,this.height,t),{data:n,format:r,stride:[s]}=e,{data:i,format:a}=this;for(let o=i.length;o-- >0;)n.set(r.fromABGR(a.toABGR(i[o])),o*s);return e}copy(){const t=this.empty();return t.data.set(this.data),t}empty(){return new U(this.width,this.height,this.format)}order(){}includes(t,e){}indexAt(t,e){}indexAtUnsafe(t,e){}getAt(t,e){}getAtUnsafe(t,e){}setAt(t,e,n){}setAtUnsafe(t,e,n){}getChannelAt(t,e,n,r=!1){const s=O(this.format,n),i=this.getAt(t,e);return r?s.float(i):s.int(i)}setChannelAt(t,e,n,r,s=!1){const i=O(this.format,n),a=this.getAt(t,e);return s?i.setFloat(a,r):i.setInt(a,r),this}blend(t,e,n){let r=this.width,s=e.width;const{sx:i,sy:a,dx:o,dy:c,rw:l,rh:h}=ct(this,e,n);if(l<1||h<1)return e;const u=this.data,f=e.data,d=this.format.toABGR,g=e.format.toABGR,m=e.format.fromABGR;for(let b=(i|0)+(a|0)*r,A=(o|0)+(c|0)*s,E=0;E<h;E++,b+=r,A+=s)for(let z=0;z<l;z++)f[A+z]=m(t(d(u[b+z]),g(f[A+z])));return e}blit(t,e){let n=this.width,r=t.width;const{sx:s,sy:i,dx:a,dy:o,rw:c,rh:l}=ct(this,t,e);if(c<1||l<1)return t;const h=this.data,u=t.data,f=this.format.toABGR,d=t.format.fromABGR,g=this.format!==t.format?(m,b)=>{for(let A=0;A<c;A++)u[b+A]=d(f(h[m+A]))}:(m,b)=>u.set(h.subarray(m,m+c),b);for(let m=(s|0)+(i|0)*n,b=(a|0)+(o|0)*r,A=0;A<l;A++,m+=n,b+=r)g(m,b);return t}blitCanvas(t,e={}){Ie(this,t,e)}setImageData(t){Mt(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),n=this.data,r=this.format.fromABGR;for(let s=e.length;s-- >0;)n[s]=r(e[s]);return this}toImageData(t){t=Ge(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),n=this.data,r=this.format.toABGR;for(let s=e.length;s-- >0;)e[s]=r(n[s]);return t}getRegion(t,e,n,r,s){const[i,a,o,c]=at(t,e,n,r,this.width,this.height);if(!(o<1||c<1))return this.blit(new U(o,c,s||this.format),{sx:i,sy:a,w:o,h:c})}getChannel(t){const e=O(this.format,t),n=new U(this.width,this.height,{type:br(e.size),size:e.size,channels:[{size:e.size,lane:w.RED}],fromABGR:Ar(e.size),toABGR:_r(e.size)}),r=this.data,s=n.data,i=e.int;for(let a=r.length;a-- >0;)s[a]=i(r[a]);return n}setChannel(t,e){const n=O(this.format,t),r=this.data,s=n.setInt;if(q(e))er(r,e,s);else{const i=e.data,a=e.format.channels[0];ke(i,this.width,this.height),n.size===a.size?nr(r,i,a.int,s):rr(r,i,this.format.fromABGR,e.format.toABGR,n.maskA)}return this}invert(){const{data:t,format:e}=this,n=Math.pow(2,e.size-e.alpha)-1;for(let r=t.length;r-- >0;)t[r]^=n;return this}premultiply(){return tr(this.format),Me(this.data,this.format,Xn),this}postmultiply(){return Me(this.data,this.format,Zn),this}isPremultiplied(){const t=this.data,e=this.format.toABGR;for(let n=t.length;n-- >0;)if(!Qn(e(t[n])))return!1;return!0}forEach(t){const e=this.data;for(let n=e.length;n-- >0;)e[n]=t(e[n],n);return this}fill(t){this.data.fill(t)}flipX(){const{data:t,width:e}=this;for(let n=0;n<t.length;n+=e)t.subarray(n,n+e).reverse();return this}flipY(){const{data:t,width:e}=this,n=ht(this.format.type,e);for(let r=0,s=t.length-e;r<s;r+=e,s-=e)n.set(t.subarray(r,r+e)),t.copyWithin(r,s,s+e),t.set(n,s);return this}rotateByID(t){return t>0?this[$e[t-1]]():this}rotateCW(){const{width:t,height:e}=this,n=e-1;return this._rotate((r,s)=>r*e+n-s),this.size[0]=e,this.size[1]=t,this}rotateCCW(){const{width:t,height:e}=this,n=t-1;return this._rotate((r,s)=>(n-r)*e+s),this.size[0]=e,this.size[1]=t,this}rotate180(){const{width:t,height:e}=this,n=t-1,r=e-1;return this._rotate((s,i)=>(r-i)*t+n-s),this}scale(t,e="linear"){return _(t>0,"scale must be > 0"),this.resize(this.width*t,this.height*t,e)}resize(t,e,n="linear"){t|=0,e|=0,_(t>0&&e>0,"target width & height must be > 0");const r=vr(t,e,this.format),s=r.data,i=t>0?this.width/t:0,a=e>0?this.height/e:0;n=P(n)?Ne(this,n,"repeat"):n;for(let o=0,c=0;o<e;o++){const l=o*a;for(let h=0;h<t;h++,c++)s[c]=n(h*i,l)}return r}upsize(){const{width:t,height:e,data:n}=this,r=new U(t*2,e*2,this.format),s=r.data;for(let i=0,a=0;i<e;i++)for(let o=0,c=i*t*4;o<t;o++,a++,c+=2)s[c]=n[a];return r}_rotate(t){const{data:e,format:n,width:r,height:s}=this,i=ht(n.type,r*s);for(let a=0;a<s;a++)for(let o=0;o<r;o++)i[t(o,a)]=e[a*r+o];this.data=i}};U=Sr([Ce],U);var kr=Object.defineProperty,Gr=Object.getOwnPropertyDescriptor,Z=(t,e,n,r)=>{for(var s=r>1?void 0:r?Gr(e,n):e,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(e,n,s):a(s))||s);return r&&s&&kr(e,n,s),s};function Pe(...t){return t[0]instanceof U?Mr(...t):new S(...t)}const Mr=(t,e)=>{const n=new S(t.width,t.height,e),{data:r,format:s,stride:[i]}=n,{data:a,format:o}=t;for(let c=a.length;c-- >0;)r.set(s.fromABGR(o.toABGR(a[c])),c*i);return n},Ir=(t,e=j)=>Br(t).as(e);let S=class{size;stride;format;data;__empty;constructor(t,e,n=j,r){this.size=[t,e],this.format=n.__float?n:lt(n);const s=this.format.channels.length;this.stride=[s,t*s],this.data=r||new Float32Array(t*e*s),this.__empty=Object.freeze(new Array(s).fill(0))}get pixels(){return this.data}get width(){return this.size[0]}get height(){return this.size[1]}get offset(){return 0}get dim(){return 2}*[Symbol.iterator](){const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)yield t.subarray(n,n+e)}as(t){const{width:e,height:n,stride:[r],data:s,format:{size:i,normalized:a,toABGR:o}}=this;let c=0,l=0,h=s.length;if(t.__float){const u=t,f=new S(e,n,u),{data:d,stride:[g]}=f;if(i===1&&u.channels.length===1){const m=u.fromNormalized;for(;c<h;c+=r,l+=g)d[l]=m(a(s[c]))}else for(;c<h;c+=r,l+=g)d.set(u.fromABGR(o(s.subarray(c,c+r))),l);return f}else{const u=t,f=new U(e,n,u),d=f.data;if(i===1&&u.channels.length===1){const g=u.channels[0].setFloat;for(;c<h;c+=r,l++)d[l]=g(0,a(s[c]))}else for(;c<h;c+=r,l++)d[l]=u.fromABGR(o(s.subarray(c,c+r)));return f}}copy(){const t=this.empty();return t.data.set(this.data),t}empty(){return new S(this.width,this.height,this.format)}order(){}includes(t,e){}indexAt(t,e){}indexAtUnsafe(t,e){}getAt(t,e){return this.includes(t,e)?this.getAtUnsafe(t,e):this.__empty}getAtUnsafe(t,e){const n=this.indexAtUnsafe(t,e);return this.data.subarray(n,n+this.stride[0])}setAt(t,e,n){return this.includes(t,e)?(this.data.set(n,this.indexAtUnsafe(t,e)),!0):!1}setAtUnsafe(t,e,n){return this.data.set(n,this.indexAtUnsafe(t,e)),!0}getChannelAt(t,e,n){return O(this.format,n),this.includes(t,e)?this.data[this.indexAtUnsafe(t,e)+n]:void 0}setChannelAt(t,e,n,r){return O(this.format,n),this.includes(t,e)&&(this.data[this.indexAtUnsafe(t,e)+n]=r),this}getChannel(t){O(this.format,t);const{data:e,stride:[n]}=this,[r,s]=this.format.range,i=new Float32Array(this.width*this.height);for(let a=t,o=0,c=e.length;a<c;a+=n,o++)i[o]=B(e[a],r,s);return new S(this.width,this.height,Ue,i)}setChannel(t,e){O(this.format,t);const{data:n,stride:[r]}=this;if(q(e))for(let s=t,i=n.length;s<i;s+=r)n[s]=e;else{const{data:s,stride:[i]}=e;ke(s,this.width,this.height,i);for(let a=t,o=0,c=n.length;a<c;a+=r,o+=i)n[a]=s[o]}return this}blend(t,e,n){this.ensureFormat(e);const{sx:r,sy:s,dx:i,dy:a,rw:o,rh:c}=ct(this,e,n);if(o<1||c<1)return e;const l=this.data,h=e.data,[u,f]=this.stride,d=e.stride[1];for(let g=(r|0)*u+(s|0)*f,m=(i|0)*u+(a|0)*d,b=0;b<c;b++,g+=f,m+=d)for(let A=o,E=g,z=m;A-- >0;E+=u,z+=u){const Gt=h.subarray(z,z+u);t(Gt,l.subarray(E,E+u),Gt)}return e}blit(t,e){this.ensureFormat(t);const{sx:n,sy:r,dx:s,dy:i,rw:a,rh:o}=ct(this,t,e);if(a<1||o<1)return t;const c=this.data,l=t.data,[h,u]=this.stride,f=t.stride[1],d=a*h;for(let g=(n|0)*h+(r|0)*u,m=(s|0)*h+(i|0)*f,b=0;b<o;b++,g+=u,m+=f)l.set(c.subarray(g,g+d),m);return t}blitCanvas(t,e={}){Ie(this,t,e)}setImageData(t){Mt(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),{data:n,format:{fromABGR:r},stride:[s]}=this,i=[];for(let a=e.length;a-- >0;)n.set(r(e[a],i),a*s);return this}toImageData(t){t=Ge(t,this.width,this.height);const e=new Uint32Array(t.data.buffer),{stride:[n],data:r,format:s}=this;for(let i=0,a=0,o=r.length;i<o;i+=n,a++)e[a]=s.toABGR(r.subarray(i,i+n));return t}getRegion(t,e,n,r){const[s,i,a,o]=at(t,e,n,r,this.width,this.height);if(!(a<1||o<1))return this.blit(new S(a,o,this.format),{sx:s,sy:i,w:a,h:o})}forEach(t){const{data:e,stride:[n]}=this;for(let r=0,s=0,i=e.length;r<i;r+=n,s++)e.set(t(e.subarray(r,r+n),s),r);return this}fill(t){_(t.length<=this.format.channels.length,"fill value has too many channels");const{data:e,stride:[n]}=this;for(let r=0,s=e.length;r<s;r+=n)e.set(t,r)}premultiply(){this.ensureRGBA();const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)Vn(null,t.subarray(n,n+e));return this}postmultiply(){this.ensureRGBA();const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)Kn(null,t.subarray(n,n+e));return this}isPremultiplied(){this.ensureRGBA();const{data:t,stride:[e]}=this;for(let n=0,r=t.length;n<r;n+=e)if(!Jn(t.subarray(n,n+e)))return!1;return!0}clamp(){const t=this.data,[e,n]=this.format.range;for(let r=t.length;r-- >0;)t[r]=B(t[r],e,n);return this}clampChannel(t){O(this.format,t);const{data:e,stride:[n]}=this,[r,s]=this.format.range;for(let i=t,a=e.length;i<a;i+=n)e[i]=B(e[i],r,s)}flipX(){const{data:t,width:e,height:n,stride:[r,s]}=this,i=new Float32Array(r),a=e-1,o=e>>>1;for(let c=0;c<n;c++)for(let l=0,h=c*s,u=h+a*r;l<o;l++,h+=r,u-=r)i.set(t.subarray(h,h+r)),t.copyWithin(h,u,u+r),t.set(i,u);return this}flipY(){const t=this.data,e=this.stride[1],n=new Float32Array(e);for(let r=0,s=t.length-e;r<s;r+=e,s-=e)n.set(t.subarray(r,r+e)),t.copyWithin(r,s,s+e),t.set(n,s);return this}rotateByID(t){return t>0?this[$e[t-1]]():this}rotateCW(){const{width:t,height:e}=this,n=e-1;return this._rotate((r,s)=>r*e+n-s),this.size[0]=e,this.size[1]=t,this}rotateCCW(){const{width:t,height:e}=this,n=t-1;return this._rotate((r,s)=>(n-r)*e+s),this.size[0]=e,this.size[1]=t,this}rotate180(){const{width:t,height:e}=this,n=t-1,r=e-1;return this._rotate((s,i)=>(r-i)*t+n-s),this}invert(){const{data:t,format:e,stride:[n]}=this;for(let r=0,s=t.length,i=e.alpha?n-1:n;r<s;r+=n)for(let a=0;a<i;a++)t[r+a]=1-t[r+a];return this}scale(t,e){return _(t>0,"scale must be > 0"),this.resize(this.width*t,this.height*t,e)}resize(t,e,n="linear"){t|=0,e|=0,_(t>0&&e>0,"target width & height must be > 0");const r=Pe(t,e,this.format),s=r.data,i=t>0?this.width/t:0,a=e>0?this.height/e:0,o=this.stride[0];n=P(n)?Ne(this,n,"repeat"):n;for(let c=0,l=0;c<e;c++){const h=c*a;for(let u=0;u<t;u++,l+=o)s.set(n(u*i,h),l)}return r}upsize(){const{width:t,height:e,data:n,stride:[r,s]}=this,i=r*2,a=Pe(t*2,e*2,this.format),o=a.data;for(let c=0,l=0;c<e;c++)for(let h=0,u=c*s*4;h<t;h++,l+=r,u+=i)o.set(n.subarray(l,l+r),u);return a}_rotate(t){const{data:e,width:n,height:r,stride:[s]}=this,i=new Float32Array(n*r*s);for(let a=0,o=0;a<r;a++)for(let c=0;c<n;c++,o+=s)i.set(e.subarray(o,o+s),t(c,a)*s);this.data=i}ensureFormat(t){_(t.format===this.format,"dest buffer format must be same as src")}ensureRGBA(){_(this.format===j,"require FLOAT_RGBA format")}};Z([rt],S.prototype,"getAt",1),Z([rt],S.prototype,"getAtUnsafe",1),Z([rt],S.prototype,"setAt",1),Z([rt],S.prototype,"setAtUnsafe",1),S=Z([Ce],S);const Ur=(t,e,n)=>(t-e)/(n-e),xr=(t,e,n,r,s)=>r+(s-r)*Ur(t,e,n),bt=Math.abs,zr=Math.min,Or=lt({alpha:!0,channels:[w.RED,w.GREEN,w.BLUE,w.ALPHA],convert:{fromABGR:(t,e=[])=>{const n=(t>>>24&255)/255,r=(t>>>16&255)/255,s=(t>>>8&255)/255,i=(t&255)/255;let a,o,c,l,h,u,f,d;s<r?(a=r,o=s,c=-1,l=2/3):(a=s,o=r,c=0,l=-1/3),i<a?(h=a,u=o,f=l,d=i):(h=i,u=o,f=c,d=a);const g=h-zr(u,d);return h=y(h),e[0]=y(bt((d-u)/(6*g+I)+f)),e[1]=y(g/(h+I)),e[2]=h,e[3]=n,e},toABGR:t=>{const e=t[0]*6,n=t[1],r=t[2]*255,s=t[3]*255,i=((y(bt(e-3)-1)-1)*n+1)*r,a=((y(2-bt(e-2))-1)*n+1)*r,o=((y(2-bt(e-4))-1)*n+1)*r;return(s<<24|o<<16|a<<8|i)>>>0}}}),j=lt({alpha:!0,channels:[w.RED,w.GREEN,w.BLUE,w.ALPHA]}),Er=ot(()=>"unsupported operation"),Pt=t=>{throw new Er(t)},G=(t=1,e,...n)=>{const r=[,,].concat(n),s=(...i)=>{const a=r[i[t].length]||e;return a?a(...i):Pt(`no impl for vec size ${i[t].length}`)};return s.add=(i,a)=>r[i]=a,s.default=i=>e=i,s.impl=i=>i!=null&&r[i]||e,s},Fr=(t,e)=>t[0]*e[0]+t[1]*e[1],jt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Dr=G(0,(t,e)=>{let n=0;for(let r=t.length;r-- >0;)n+=t[r]*e[r];return n},Fr,jt,(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]);function je(t,e=Object.create(null)){return(...n)=>{const r=JSON.stringify(n);return r!==void 0?r in e?e[r]:e[r]=t.apply(null,n):t.apply(null,n)}}function Le(t,e=Object.create(null)){return(...n)=>{const r=n.join("-");return r in e?e[r]:e[r]=t(...n)}}const Nr=Le((t,e)=>t.repeat(e)),He=je((t,e=!1)=>e?n=>Tr(n)||n.toFixed(t):n=>n.toFixed(t)),Tr=t=>isNaN(t)?"NaN":t===1/0?"+∞":t===-1/0?"-∞":void 0,qr=(t=0)=>e=>(e*100).toFixed(t)+"%",Pr=[.299,.587,.114],We=[.2126,.7152,.0722],jr=[3.1338561,-.9787684,.0719453,-1.6168667,1.9161415,-.2289914,-.4906146,.033454,1.4052427],Lr=[3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252],Hr=[.96422,1,.82521],Wr=[.95047,1,1.08883],Yr=[.2104542553,1.9779984951,.0259040371,.793617785,-2.428592205,.7827717662,-.0040720468,.4505937099,-.808675766];let At=He(3),Ye=qr(3);const M=1/255,Lt=(t,e=We)=>jt(t,e),Vr=t=>jt(t,Pr),Xr=(t,e)=>(!t&&(t=[]),t[0]=e[0],t[1]=e[1],t),Kr=(t,e)=>(!t&&(t=[]),t[0]=e[0],t[1]=e[1],t[2]=e[2],t),L=(t,e)=>(!t&&(t=[]),t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t),Zr=G(1,(t,e)=>{!t&&(t=[]);for(let n=e.length;n-- >0;)t[n]=e[n];return t},Xr,Kr,L),J=(t,e)=>typeof t?.[e]=="function",Ht=t=>t!=null&&typeof t!="function"&&t.length!==void 0,Jr=ot(()=>"illegal argument(s)"),Wt=t=>{throw new Jr(t)},Qr=je((t,e=3,n=",",r="[",s="]")=>{const i=typeof e=="number"?He(e):e;switch(t){case 1:return a=>`${r}${i(a[0])}${s}`;case 2:return a=>`${r}${i(a[0])}${n}${i(a[1])}${s}`;case 3:return a=>`${r}${i(a[0])}${n}${i(a[1])}${n}${i(a[2])}${s}`;case 4:return a=>`${r}${i(a[0])}${n}${i(a[1])}${n}${i(a[2])}${n}${i(a[3])}${s}`;default:return a=>{const o=[];for(let c=0;c<a.length;c++)o.push(i(a[c]));return`${r}${o.join(n)}${s}`}}}),ts=(t,e,n,r,s,i)=>{const a=[];for(;n-- >0;)a.push(new t(e,r,s)),r+=i;return a},es=(t,e=1,n=!0)=>{const r=n?(o,c,l,h)=>{!o&&(o=c);for(let u=c.length;u-- >0;)o[u]=t(c[u],l[u],h[u]);return o}:(o,c,l,h)=>{!o&&(o=h);for(let u=c.length;u-- >0;)o[u]=t(c[u],l[u],h[u]);return o},s=n?(o,c,l,h)=>(!o&&(o=c),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o):(o,c,l,h)=>(!o&&(o=h),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o),i=n?(o,c,l,h)=>(!o&&(o=c),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o):(o,c,l,h)=>(!o&&(o=h),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o),a=n?(o,c,l,h)=>(!o&&(o=c),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o[3]=t(c[3],l[3],h[3]),o):(o,c,l,h)=>(!o&&(o=h),o[0]=t(c[0],l[0],h[0]),o[1]=t(c[1],l[1],h[1]),o[2]=t(c[2],l[2],h[2]),o[3]=t(c[3],l[3],h[3]),o);return[G(e,r,s,i,a),s,i,a]},[li,hi,fi,ns]=es(B),rs=ns,ss=(t,e,n,r=!0,s=!0)=>{const i=n>0?r?function(){return this.buf[this.offset+n*this.stride]}:function(){return this.buf[this.offset+n]}:function(){return this.buf[this.offset]},a=n>0?r?function(o){this.buf[this.offset+n*this.stride]=o}:function(o){this.buf[this.offset+n]=o}:function(o){this.buf[this.offset]=o};s&&Object.defineProperty(t,n,{get:i,set:a,enumerable:!0}),Object.defineProperty(t,e,{get:i,set:a,enumerable:!0})},os=(t,e,n,r)=>e.forEach((s,i)=>ss(t,s,i,n,r)),is=Math.abs,x=(t,e,n=I)=>is(t-e)<=n,as=(t,e,n=I)=>t.length===e.length&&x(t[0],e[0],n)&&x(t[1],e[1],n),cs=(t,e,n=I)=>t.length===e.length&&x(t[0],e[0],n)&&x(t[1],e[1],n)&&x(t[2],e[2],n),Ve=(t,e,n=I)=>t.length===e.length&&x(t[0],e[0],n)&&x(t[1],e[1],n)&&x(t[2],e[2],n)&&x(t[3],e[3],n);G(0,(t,e,n=I)=>J(t,"eqDelta")?t.eqDelta(e,n):J(e,"eqDelta")?e.eqDelta(t,n):ls(t,e,t.length,n),as,cs,Ve);const ls=(t,e,n,r=I,s=0,i=0,a=1,o=1)=>{for(;n>0;n--,s+=a,i+=o)if(!x(t[s],e[i],r))return!1;return!0};function*hs(t,e,n,r){for(;e-- >0;)yield t[n],n+=r}const Xe=1/2**32;class fs{float(e=1){return this.int()*Xe*e}probability(e){return this.float()<e}norm(e=1){return(this.int()*Xe-.5)*2*e}normMinMax(e,n){const r=this.minmax(e,n);return this.float()<.5?r:-r}minmax(e,n){return this.float()*(n-e)+e}minmaxInt(e,n){e|=0;const r=(n|0)-e;return r?e+this.int()%r:e}minmaxUint(e,n){e>>>=0;const r=(n>>>0)-e;return r?e+this.int()%r:e}}class us extends fs{constructor(e){super(),this.rnd=e}float(e=1){return this.rnd()*e}norm(e=1){return(this.rnd()-.5)*2*e}int(){return this.rnd()*4294967296>>>0}}const Yt=new us(Math.random),ds=(t,e,n=Yt)=>{const r=t.length;_(r>0,"no choices given");const s=e?t.map((a,o)=>[e[o]||0,a]).sort((a,o)=>o[0]-a[0]):t.map(a=>[1,a]),i=s.reduce((a,o)=>a+o[0],0);return i<=0&&console.warn("total weights <= 0"),()=>{const a=n.float(i);let o=i;for(let c=0;c<r;c++)if(o-=s[c][0],o<=a)return s[c][1]}},gs=G(1,(t,e,n,r=Yt)=>{!t&&(t=e);for(let s=e.length;s-- >0;)t[s]=r.minmax(e[s],n[s]);return t}),Ke=Array.isArray,Q={},Ze=(t,e)=>{for(const n in e){const r=e[n];if(Ke(r)){const[s,i,a,o]=r;e[n]=r.length===2?(c,l)=>i(c,s(c,l)):r.length===3?(c,l)=>a(c,i(c,s(c,l))):(c,l)=>o(c,a(c,i(c,s(c,l))))}}Q[t]={...Q[t],...e}},Je=(t,e,n,r)=>{const s=Q[n];_(!!s,`no conversions available for ${n}`);let i=s[r];return i?i(t,e):Q.rgb[r]?s.rgb(t,Q.rgb[r]([],e)):Pt(`can\'t convert: ${r} -> ${n}`)},Qe=(t,e)=>(t>>>e|t<<32-e)>>>0,ms=t=>(t&3840)*4352|(t&240)*272|(t&15)*17,ys=t=>((t&61440)*69632|(t&3840)*4352|(t&240)*272|(t&15)*17)>>>0;class T{constructor(e,n){this.mode=e,this.value=n}deref(){return this.value}}const bs={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32",transparent:"0000",rebeccapurple:"639"};let As={canvas:"fff",canvastext:"000",linktext:"001ee4",visitedtext:"4e2386",activetext:"eb3323",buttonface:"ddd",buttontext:"000",buttonborder:"000",field:"fff",fieldtext:"000",highlight:"bbd5fb",highlighttext:"000",mark:"000",marktext:"fff",graytext:"808080"};const v=(t,e,n,r)=>(!t&&(t=[]),t[0]=e,t[1]=n,t[2]=r,t),R=(t,e,n,r,s)=>(!t&&(t=[]),t[0]=e,t[1]=n,t[2]=r,t[3]=s,t),_t=(t,e)=>R(t||[],(e>>>16&255)*M,(e>>>8&255)*M,(e&255)*M,(e>>>24)*M),tn=(t,e)=>R(t||[],(e&255)*M,(e>>>8&255)*M,(e>>>16&255)*M,(e>>>24)*M),_s=t=>{t=(P(t)?t:t.deref()).toLowerCase();const e=bs[t]||As[t];if(e||t[0]==="#")return new T("srgb",_t([],ws(e||t)));const n=t.split(/[(),/ ]+/),[r,s,i,a,o]=n;switch(_(n.length===5||n.length===6,`invalid color: ${t}`),r){case"rgb":case"rgba":return new T("srgb",[C(s,1,M,!0),C(i,1,M,!0),C(a,1,M,!0),H(o)]);case"hsl":case"hsla":return new T("hsl",[Vt(s),en(i),en(a),H(o)]);case"lab":return new T("lab50",[C(s),C(i,1.25),C(a,1.25),H(o)]);case"lch":return new T(r,[C(s),C(i,1.5),Vt(a),H(o)]);case"oklab":return new T(r,[C(s,1,1),C(i,.4,1),C(a,.4,1),H(o)]);case"oklch":return new T(r,[C(s,1,1),C(i,.4,1),Vt(a),H(o)]);default:Pt(`color mode: ${r}`)}},ps={rad:k,grad:400,turn:1,deg:360},Vt=t=>{const e=/^(-?[0-9.]+)(deg|rad|grad|turn)?$/.exec(t);return _(!!e,`expected hue, got: ${t}`),p(parseFloat(e[1])/(ps[e[2]]||360))},H=t=>t?C(t,1,1,!0):1,en=(t,e=!0)=>{_(/^([0-9.]+)%$/.test(t),`expected percentage, got: ${t}`);const n=parseFloat(t)/100;return e?y(n):n},C=(t,e=1,n=.01,r=!1)=>{_(/^-?[0-9.]+%?$/.test(t),`expected number or percentage, got: ${t}`);const s=parseFloat(t)*(t.endsWith("%")?.01*e:n);return r?y(s):s},ws=t=>{const e=/^#?([0-9a-f]{3,8})$/i.exec(t);if(e){const n=e[1],r=parseInt(n,16);switch(n.length){case 3:return(ms(r)|4278190080)>>>0;case 4:return Qe(ys(r),8);case 6:return(r|4278190080)>>>0;case 8:return Qe(r,8)}}return Wt(`invalid hex color: "${t}"`)},$=(t,e=1)=>t!=null?y(t):e,Rs=t=>{if(typeof t[0]=="number")switch(t.length){case 1:return t.push(0,0,1),[t];case 2:return t.push(0,1),[t];case 3:return t.push(1),[t];default:return[t]}return t},pt=t=>{const e=t.channels||{},n=t.order,r=n.length;n.reduce((f,d)=>(f[d]={range:[0,1],...e[d]},f),e);const s=Object.freeze(n.map(f=>e[f].range[0])),i=Object.freeze(n.map(f=>e[f].range[1])),a=L([],s),o=L([],i);a[r-1]=1;const c=n.findIndex(f=>!!e[f].hue),l=class{constructor(f,d=0,g=1){this.offset=d,this.stride=g,this.buf=f||[0,0,0,0],this.offset=d,this.stride=g}buf;get mode(){return t.mode}get length(){return r}get range(){return[s,i]}get[Symbol.toStringTag](){return t.mode}get xyz(){return[this[0],this[1],this[2]]}[Symbol.iterator](){return hs(this.buf,this.length,this.offset,this.stride)}copy(){return new l(this.deref())}copyView(){return new l(this.buf,this.offset,this.stride)}empty(){return new l}deref(){return[this[0],this[1],this[2],this[3]]}set(f){return L(this,f)}clamp(){return c>=0&&(this[c]=p(this[c])),rs(null,this,s,i),this}eqDelta(f,d=I){return Ve(this,f,d)}randomize(f){return gs(this,a,o,f)}toJSON(){return this.deref()}toString(){return Qr(4,4)(this)}};os(l.prototype,n),Ze(t.mode,t.from),Ze("rgb",{[t.mode]:t.toRgb});const h=(f,d,g)=>{const m=new l(...g);return d!==t.mode?Je(m,f,t.mode,d):m.set(f)},u=(f,...d)=>f==null?new l:P(f)?u(_s(f),...d):Ht(f)?P(f.mode)?h(f,f.mode,d):new l(f,...d):J(f,"deref")?h(f.deref(),f.mode,d):q(f)?d.length&&d.every(q)?new l(...Rs([f,...d])):h(_t([],f),"srgb",d):Wt(`can\'t create a ${t.mode} color from: ${f}`);return u.class=l,u.range=[s,i],u.random=(f,d,g,m)=>new l(d,g,m).randomize(f),u.mapBuffer=(f,d=f.length/r|0,g=0,m=1,b=r)=>ts(l,f,d,g,m,b),u},Xt=(t,e,n=1)=>(e=p(e)*6,R(t||[],y(Math.abs(e-3)-1),y(2-Math.abs(e-2)),y(2-Math.abs(e-4)),n)),nn=(t,e)=>{const n=e[0];let r=e[1];const s=e[2],i=Xt(t||e,n,$(e[3])),a=Lt(i);return s<a?r*=s/a:a<1&&(r*=(1-s)/(1-a)),v(i,y((i[0]-a)*r+s),y((i[1]-a)*r+s),y((i[2]-a)*r+s))},$s=(t,e,n=1)=>R(t||e,y(e[0]),y(e[1]),y(e[2]),$(e[3],n)),wt=(t,e,n=1)=>R(t||e,p(e[0]),y(e[1]),y(e[2]),$(e[3],n)),rn=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2];if(n<1e-6)return v(t,r,r,r);const s=t[0]*6%6,i=r*(1-n),a=1-Math.abs(s%2-1);let o=3*r*n/(1+a);const c=o*a+i;switch(o+=i,s|0){case 0:return v(t,o,c,i);case 1:return v(t,c,o,i);case 2:return v(t,i,o,c);case 3:return v(t,i,c,o);case 4:return v(t,c,i,o);case 5:return v(t,o,i,c);default:return v(t,i,i,i)}},sn=(t,e)=>{const n=y(e[1]),r=y(e[2]);t=Xt(t||e,e[0],$(e[3]));const s=(1-Math.abs(2*r-1))*n;return v(t,(t[0]-.5)*s+r,(t[1]-.5)*s+r,(t[2]-.5)*s+r)},Kt=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2];return Xt(t,e[0],t[3]),v(t,((t[0]-1)*n+1)*r,((t[1]-1)*n+1)*r,((t[2]-1)*n+1)*r)},Zt=t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,Jt=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),Rt=(t,e)=>R(t||e,Jt(e[0]),Jt(e[1]),Jt(e[2]),$(e[3])),Cs=(t,e)=>Rt(null,_t(t,e)),Ss=(t,e)=>Rt(null,tn(t,e)),Qt=(t,e=1)=>[Math.cos(t)*e,Math.sin(t)*e],vs=t=>(t%=k,t<0?k+t:t),on=(t,e)=>vs(Math.atan2(t,e)),te=(t,e)=>{let{1:n,2:r}=e;r*=k;const s=$(e[3]);return n>0?R(t||e,e[0],Math.cos(r)*n,Math.sin(r)*n,s):R(t||e,e[0],0,0,s)},ee=t=>{const e=t**3;return e>.008856?e:(t-16/116)/7.787},an=(t,e,n=Hr)=>{const r=(e[0]+.16)/1.16;return R(t||e,ee(e[1]/5+r)*n[0],ee(r)*n[1],ee(r-e[2]/2)*n[2],$(e[3]))},Bs=(t,e)=>an(t,e,Wr),ne=(t,e,n=0,r=0,s=1,i=1)=>t[n]*e[r]+t[n+s]*e[r+i]+t[n+2*s]*e[r+2*i],$t=(t,e,n,r=!1)=>{const s=ne(e,n,0,0,3),i=ne(e,n,1,0,3),a=ne(e,n,2,0,3),o=$(n[3]);return r?R(t||n,y(s),y(i),y(a),o):R(t||n,s,i,a,o)},re=(t,e,n=jr)=>$t(t,n,e),se=(t,e)=>re(t,e,Lr),tt=(t,e)=>re(null,an(t,e)),cn=(t,e)=>se(null,Bs(t,e)),ks=[4.0767416621,-1.2684380046,-.0041960863,-3.307711591,2.6097574011,-.7034186147,.2309699292,-.3413193965,1.707614701],ln=(t,{0:e,1:n,2:r,3:s})=>$t(t,ks,[(e+.3963377774*n+.2158037573*r)**3,(e-.1055613458*n-.0638541728*r)**3,(e-.0894841775*n-1.291485548*r)**3,s]),hn=(t,e)=>e!==0?t/e:0,fn=pt({mode:"rgb",order:["r","g","b","alpha"],from:{abgr32:(t,e)=>Ss(t,e[0]),argb32:(t,e)=>Cs(t,e[0]),hcy:nn,hsi:rn,hsl:sn,hsv:Kt,lab50:tt,lab65:cn,lch:[te,tt],oklab:ln,rgb:L,srgb:Rt,xyy:[(t,e)=>{const{0:n,1:r,2:s}=e;return R(t||e,hn(s*n,r),s,hn(s*(1-n-r),r),$(e[3]))},se],xyz50:re,xyz65:se,ycc:(t,e,n=We)=>{const r=e[0],s=(2-2*n[2])*e[1],i=(2-2*n[0])*e[2];return R(t||e,r+i,r-n[2]/n[1]*s-n[0]/n[1]*i,r+s,$(e[3]))}},toRgb:L}),Gs=(t,e)=>{const n=Lt(fn(t))+.05,r=Lt(fn(e))+.05;return n>r?n/r:r/n},un=t=>((t==null||!t[Symbol.iterator])&&Wt(`value is not iterable: ${t}`),t),Ms=t=>Ke(t)?t:[...un(t)],Is=t=>Ht(t)?t:[...un(t)],dn=t=>{const e=At(p(t[0])*360),n=Ye(y(t[1])),r=Ye(y(t[2])),s=$(t[3]);return s<1?`hsla(${e},${n},${r},${At(s)})`:`hsl(${e},${n},${r})`},Us=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2],s=(2-n)*r/2;return t[2]=s,t[1]=s&&s<1?n*r/(s<.5?s*2:2-s*2):n,t},xs=t=>dn(Us([],t)),gn="0123456789abcdef",oe=t=>gn[t>>>4&15]+gn[t&15],zs=t=>oe(t>>>8)+oe(t&255),Os=t=>oe(t>>>16)+zs(t),ie=Le((t,e,n="")=>{const r=Nr("0",e);return s=>(s=(s>>>0).toString(t),n+(s.length<e?r.substring(s.length)+s:s))});ie(2,8),ie(2,16),ie(2,32);const mn=Os,ae=t=>{const e=t>>>24;return e<255?`rgba(${t>>16&255},${t>>8&255},${t&255},${At(e*M)})`:`#${mn(t&16777215)}`},Es=t=>(t&255)<<16|t>>16&255|t&4278255360,W=(t,e)=>R(t||e,Zt(e[0]),Zt(e[1]),Zt(e[2]),$(e[3])),ce=(t,e=0)=>(t<0?0:t>1?1:t)*255+.5<<e,Y=t=>{const e=ce(t[0]),n=ce(t[1]),r=ce(t[2]),s=$(t[3]);return s<1?`rgba(${e},${n},${r},${At(s)})`:`#${mn(e<<16|n<<8|r)}`},yn={abgr32:t=>ae(Es(t[0])),argb32:t=>ae(t[0]),hsl:dn,hsv:xs,lab50:t=>Y(W(null,tt([],t))),lab65:t=>Y(W(null,cn([],t))),lch:t=>Y(W(null,tt(null,te([],t)))),rgb:t=>Y(W([],t)),srgb:Y};({...yn});let Fs=yn;const bn=(t,e=Fs)=>{let n;return P(t)?t:q(t)?ae(t):t.mode?(n=e[t.mode])?n(t):e.rgb(Je([],t,"rgb",t.mode)):Y(t)},Ds=(t,e)=>{t=wt(t||e,e);const n=t[1],r=t[2],s=2*r,i=(s+n*(1-Math.abs(s-1)))*.5;return t[1]=2*(i-r)/i,t[2]=i,t},Ns=(t,e)=>{t=$s(t||e,e);const n=t[1]<t[2]?[t[2],t[1],-1,2/3]:[t[1],t[2],0,-1/3],r=t[0]<n[0]?[n[0],n[1],n[3],t[0]]:[t[0],n[1],n[2],n[0]],s=r[0]-Math.min(r[1],r[3]);return v(t,y(Math.abs((r[3]-r[1])/(6*s+I)+r[2])),y(s),y(r[0]))},le=(t,e)=>(t=Ns(t,e),t[1]/=t[2]+I,t),Ts=pt({mode:"hsv",channels:{h:{hue:!0}},order:["h","s","v","alpha"],from:{rgb:le,srgb:le,hsl:Ds,lch:[te,tt,W,le]},toRgb:Kt}),Ct=(t,e=1)=>{const n=(a,o,c)=>{!a&&(a=o);for(let l=o.length;l-- >0;)a[l]=t(o[l],c);return a},r=(a,o,c)=>(!a&&(a=o),a[0]=t(o[0],c),a[1]=t(o[1],c),a),s=(a,o,c)=>(!a&&(a=o),a[0]=t(o[0],c),a[1]=t(o[1],c),a[2]=t(o[2],c),a),i=(a,o,c)=>(!a&&(a=o),a[0]=t(o[0],c),a[1]=t(o[1],c),a[2]=t(o[2],c),a[3]=t(o[3],c),a);return[G(e,n,r,s,i),r,s,i]},[yi,bi,qs]=Ct(Math.pow),Ps=qs,js=[.4122214708,.2119034982,.0883024619,.5363325363,.6806995451,.2817188376,.0514459929,.1073969566,.6299787005],Ls=(t,e)=>$t(null,Yr,Ps(null,$t(t,js,e),1/3)),An=(t,e)=>R(t||e,e[0],Math.hypot(e[1],e[2]),on(e[2],e[1])*$r,$(e[3])),Hs=pt({mode:"oklch",channels:{c:{range:[0,.3225]}},order:["l","c","h","alpha"],from:{oklab:An,rgb:(t,e)=>An(null,Ls(t,e))},toRgb:[(t,e)=>R(t||e,e[0],...Qt(e[2]*k,e[1]),$(e[3])),ln]}),_n=pt({mode:"srgb",order:["r","g","b","alpha"],from:{abgr32:(t,e)=>tn(t,e[0]),argb32:(t,e)=>_t(t,e[0]),hcy:nn,hsi:rn,hsl:sn,hsv:Kt,rgb:W},toRgb:Rt}),Ws=(t,e)=>t===e?0:t==null?e==null?0:-1:e==null?t==null?0:1:typeof t.compare=="function"?t.compare(e):typeof e.compare=="function"?-e.compare(t):t<e?-1:t>e?1:0,Ys=t=>typeof t=="function"?t:e=>e[t];function pn(t,e=Ws){const n=Ys(t);return(r,s)=>e(n(r),n(s))}const Vs=(t,e)=>e-t,he=(t,e=1,n=!0)=>{const r=n?(o,c,l)=>{!o&&(o=c);for(let h=c.length;h-- >0;)o[h]=t(c[h],l[h]);return o}:(o,c,l)=>{!o&&(o=l);for(let h=c.length;h-- >0;)o[h]=t(c[h],l[h]);return o},s=n?(o,c,l)=>(!o&&(o=c),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o):(o,c,l)=>(!o&&(o=l),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o),i=n?(o,c,l)=>(!o&&(o=c),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o):(o,c,l)=>(!o&&(o=l),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o),a=n?(o,c,l)=>(!o&&(o=c),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o[3]=t(c[3],l[3]),o):(o,c,l)=>(!o&&(o=l),o[0]=t(c[0],l[0]),o[1]=t(c[1],l[1]),o[2]=t(c[2],l[2]),o[3]=t(c[3],l[3]),o);return[G(e,r,s,i,a),s,i,a]},Xs=(t,e)=>t+e,Ks=(t,e)=>t*e,Zs=(t,e)=>t-e,[Js,Qs]=he(Xs),wn=Js,to=Qs,eo=Object.freeze([0,0]),no=Object.freeze([0,0,0]),Rn=Math.cos,$n=Math.sin,Cn=G(1);Cn.add(2,(t,e,n=eo)=>to(t||e,Qt(e[1],e[0]),n)),Cn.add(3,(t,e,n=no)=>{const r=e[0],s=e[1],i=e[2],a=Rn(s);return v(t||e,r*a*Rn(i)+n[0],r*a*$n(i)+n[1],r*$n(s)+n[2])});const ro=(t,e)=>{const n=[];for(const r of t)n.push(Qt(r,e));return n},so=t=>_(t.length>0,"no inputs given"),[oo]=Ct(Ks),Sn=oo,io=G(0,t=>{let e=0;for(let n=t.length;n-- >0;)e+=t[n];return e},t=>t[0]+t[1],t=>t[0]+t[1]+t[2],t=>t[0]+t[1]+t[2]+t[3]),ao=(t,e)=>{so(e),t=Zr(t||[],e[0]);for(let n=e.length;n-- >1;)wn(t,t,e[n]);return Sn(t,t,1/e.length)},fe=t=>t.length>0?io(t)/t.length:0,[co]=Ct(Zs),lo=co,vn=(t,e)=>lo(t,e,fe(e)),ho=t=>on(t[1],t[0]),fo=G(0,t=>{let e=0;for(let n=t.length;n-- >0;)e+=t[n]*t[n];return e},t=>t[0]*t[0]+t[1]*t[1],t=>t[0]*t[0]+t[1]*t[1]+t[2]*t[2],t=>t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]),uo=(t,e=!1,n=!1)=>{const r=~~n;return t.length>r?fo(e?t:vn([],t))/(t.length-r):0},ue=(t,e=!1,n=!1)=>Math.sqrt(uo(t,e,n)),de=t=>ho(ao([],ro(t))),go=(t,e)=>{const n=de(e);!t&&(t=[]);for(let r=0,s=e.length;r<s;r++)t[r]=(e[r]-n+Oe)%k;return vn(null,t)},mo=(t,e)=>ue(go([],t),!0,e);he(Math.max);const yo=t=>{let e=-1/0;for(let n=t.length;n-- >0;)e=Math.max(e,t[n]);return e},ge=t=>{if(!t.length)return 0;const e=t.length,n=e>>1;return t=[...t].sort((r,s)=>r-s),e&1?t[n]:(t[n-1]+t[n])*.5};he(Math.min);const bo=t=>{let e=1/0;for(let n=t.length;n-- >0;)e=Math.min(e,t[n]);return e},Ao=t=>{const[e,n]=ye(t);return{min:e,max:n,mean:fe(t),median:ge(t),sd:ue(t)}},me=(t,e)=>{const[n,r]=ye(t);return{min:n,max:r,mean:fe(t),median:ge(t),sd:ue(t),weighted:Dr(t,e)}},_o=t=>{const e=t.map(i=>i*k),n=p(de(e)/k),[r,s]=po(t,n);return{min:r,max:s,mean:n,median:wo(t,r,s),sd:mo(e)/k}},ye=t=>[bo(t),yo(t)],po=(t,e)=>{const n=ye(t),[r,s]=n;return e<r||e>s?[t.reduce((i,a)=>{const o=p(e-a);return o<.5&&o>i[1]?[a,o]:i},[s,p(e-s)])[0],t.reduce((i,a)=>{const o=p(a-e);return o<.5&&o>i[1]?[a,o]:i},[r,p(r-e)])[0]]:n},wo=(t,e,n)=>{if(e<=n)return ge(t);const r=t.length,s=r>>1,i=[...t].sort((c,l)=>c-l),a=i.findIndex(c=>c===e),o=i.slice(a).concat(i.slice(0,a));return r&1?o[s]:(o[s-1]+o[s])*.5},Ro=t=>typeof t=="function",$o=G(0,(t,e)=>{let n=0;for(let r=t.length;r-- >0;){const s=t[r]-e[r];n+=s*s}return n},(t,e)=>{const n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},(t,e)=>{const n=t[0]-e[0],r=t[1]-e[1],s=t[2]-e[2];return n*n+r*r+s*s},(t,e)=>{const n=t[0]-e[0],r=t[1]-e[1],s=t[2]-e[2],i=t[3]-e[3];return n*n+r*r+s*s+i*i});class Co{constructor(e){this.metric=e}to(e){return e*e}from(e){return Math.sqrt(e)}}const be=new Co($o),Bn=(t,e,n=be)=>{const r=Ro(n)?n:n.metric;let s=1/0,i=-1;for(let a=0,o=e.length;a<o;a++){const c=r(t,e[a]);c<s&&(s=c,i=a)}return i};G(0,(t,e)=>{for(let n=t.length;n-- >0;)t[n]=e;return t},(t,e)=>(t[0]=e,t[1]=e,t),(t,e)=>(t[0]=e,t[1]=e,t[2]=e,t),(t,e)=>(t[0]=e,t[1]=e,t[2]=e,t[3]=e,t));const So=t=>Array(t).fill(0),vo=t=>Array(t).fill(1),Bo=(t,e,n={})=>{let{dim:r=e[0].length,dist:s=be,maxIter:i=32,strategy:a=Io,exponent:o,initial:c,rnd:l}=n;const h=e.length,u=Array.isArray(c)?c:c?c(t,e,s,l):ko(t,e,s,l,o);_(u.length>0,"missing initial centroids"),t=u.length;const f=new Uint32Array(h).fill(t);let d=!0;for(;d&&i-- >0&&(d=Go(e,u,f,s),!!d);)for(let g=0;g<t;g++){const m=a(r);for(let A=0;A<h;A++)g===f[A]&&m.update(e[A]);const b=m.finish();b&&(u[g]=b)}return Mo(u,f)},ko=(t,e,n=be,r=Yt,s=2)=>{const i=e.length;_(i>0,"missing samples"),t=Math.min(t,i);const a=[r.int()%i],o=[e[a[0]]],c=new Array(i).fill(0).map((h,u)=>u),l=n.metric;for(;a.length<t;){let h=0;const u=e.map(d=>{const g=n.from(l(d,o[Bn(d,o,n)]))**s;return h+=g,g});if(!h)break;let f;do f=ds(c,u,r)();while(a.includes(f));a.push(f),o.push(e[f])}return o},Go=(t,e,n,r)=>{let s=!1;for(let i=t.length;i-- >0;){const a=Bn(t[i],e,r);a!==n[i]&&(n[i]=a,s=!0)}return s},Mo=(t,e)=>{const n=[];for(let r=0,s=e.length;r<s;r++){const i=e[r];(n[i]||(n[i]={id:i,centroid:t[i],items:[]})).items.push(r)}return n.filter(r=>!!r)},Io=t=>{const e=So(t);let n=0;return{update:r=>{wn(e,e,r),n++},finish:()=>n?Sn(e,e,1/n):void 0}},Uo=(t,e)=>{const n=[];let r=0;for(const s of e)t(s,r)&&n.push(s),r++;return n},kn=(t,e,n)=>{const r=n?.filter?Uo(n.filter,t):Array.isArray(t)?t:[...t];return r.length?Bo(Math.min(e,r.length),r,n).sort((s,i)=>i.items.length-s.items.length).map(s=>({color:[...s.centroid],area:s.items.length/r.length,ids:s.items})):[]},Ae=t=>typeof t?.[Symbol.iterator]=="function",Gn=(t,e)=>[t[0],t[1],e],_e=Symbol(),Mn=()=>{},St=t=>J(t,"xform")?t.xform():t,xo=ot(()=>"illegal arity"),pe=t=>{throw new xo(t)};class vt{value;constructor(e){this.value=e}deref(){return this.value}}const V=t=>t instanceof vt,zo=t=>t instanceof vt?t:new vt(t),et=t=>t instanceof vt?t.deref():t,Oo=t=>t.length===2?[void 0,t[1]]:t.length===3?[t[1],t[2]]:pe(t.length);function Bt(...t){const e=t[0],n=e[0],r=e[1],s=e[2];t=Oo(t);const i=t[0]==null?n():t[0],a=t[1];return et(r(J(a,"$reduce")?a.$reduce(s,i):Ht(a)?Eo(s,i,a):Fo(s,i,a)))}const Eo=(t,e,n)=>{for(let r=0,s=n.length;r<s;r++)if(e=t(e,n[r]),V(e)){e=e.deref();break}return e},Fo=(t,e,n)=>{for(const r of n)if(e=t(e,r),V(e)){e=e.deref();break}return e},we=(t,e)=>[t,it,e],kt=(t,e)=>{const n=e.length-1;return Ae(e[n])?e.length>1?Bt(t.apply(null,e.slice(0,n)),e[n]):Bt(t(),e[0]):void 0};function In(t){return t?[...t]:we(()=>[],(e,n)=>(e.push(n),e))}function*Do(t,e){const n=St(t)(In()),r=n[1],s=n[2];for(const i of e){const a=s([],i);if(V(a)){yield*et(r(a.deref()));return}a.length&&(yield*a)}yield*et(r([]))}function*No(t,e){const n=St(t)([Mn,Mn,(r,s)=>s])[2];for(const r of e){let s=n(_e,r);if(V(s)){s=et(s.deref()),s!==_e&&(yield s);return}s!==_e&&(yield s)}}function nt(t,e){return Ae(e)?No(nt(t),e):n=>{const r=n[2];return Gn(n,(s,i)=>r(s,t(i)))}}function Un(t){return t?Bt(Un(),t):we(()=>-1/0,(e,n)=>Math.max(e,n))}function*To(...t){const e=t.length-1;if(e<0)return;const n=new Array(e+1).fill(0),r=t.map(Is),s=r.reduce((i,a)=>i*a.length,1);for(let i=0;i<s;i++){const a=[];for(let o=e;o>=0;o--){const c=r[o];let l=n[o];l===c.length&&(n[o]=l=0,o>0&&n[o-1]++),a[o]=c[l]}n[e]++,yield a}}function Re(...t){return qo(Re,Bt,t)}const qo=(t,e,n)=>{let r,s;switch(n.length){case 4:s=n[3],r=n[2];break;case 3:s=n[2];break;case 2:return nt(i=>t(n[0],n[1],i));default:pe(n.length)}return e(St(n[0])(n[1]),r,s)},[Po]=Ct(De),jo=Po,xn=(t,e,n)=>Lo(y((n-t)/(e-t))),Lo=t=>t*t*(3-2*t);function zn(...t){let[e,n,r,s,i,a,o,c,l,h]=t;switch(t.length){case 0:pe(0);case 1:return e;case 2:return(...f)=>e(n(...f));case 3:return(...f)=>e(n(r(...f)));case 4:return(...f)=>e(n(r(s(...f))));case 5:return(...f)=>e(n(r(s(i(...f)))));case 6:return(...f)=>e(n(r(s(i(a(...f))))));case 7:return(...f)=>e(n(r(s(i(a(o(...f)))))));case 8:return(...f)=>e(n(r(s(i(a(o(c(...f))))))));case 9:return(...f)=>e(n(r(s(i(a(o(c(l(...f)))))))));default:const u=(...f)=>e(n(r(s(i(a(o(c(l(h(...f))))))))));return t.length===10?u:zn(u,...t.slice(10))}}function Ho(...t){return t=t.map(St),zn.apply(null,t)}function On(...t){const e=kt(On,t);if(e!==void 0)return e;const[n=0,r=1]=t;return we(()=>n,(s,i)=>s+r)}const Wo=t=>t,Yo=t=>({key:e=>e,group:In(),...t});function En(...t){const e=kt(En,t);if(e!==void 0)return e;const n=Yo(t[0]),[r,s,i]=n.group;return[()=>new Map,a=>{for(const o of a.keys())a.set(o,s(a.get(o)));return a},(a,o)=>{const c=n.key(o);return a.set(c,a.has(c)?i(a.get(c),o):i(r(),o))}]}function Fn(...t){return kt(Fn,t)||En({key:t[0]||Wo,group:On()})}function Dn(...t){const e=kt(Dn,t);if(e!==void 0)return e;const[n,r,s]=Fn(...t);let i=0;return[n,a=>{a=r(a);for(const o of a)a.set(o[0],o[1]/i);return a},(a,o)=>(i++,s(a,o))]}const Vo=()=>t=>{const e=t[2];return Gn(t,(n,r)=>{if(r){for(const s of et(r)||[])if(n=e(n,s),V(n))break}return V(r)?zo(n):n})};function Nn(t,e){return Ae(e)?Do(Nn(t),e):Ho(nt(t),Vo())}function*Xo(t,e=1/0){for(;e-- >0;)yield t}const Tn=(t,e=.2,n)=>{const r=Ms(t),s=r.filter(u=>u[1]>=e),i=s.length/r.length,a=[...Re(nt(u=>De(u[0],1/12)%1),Dn(),s)].sort(pn(0)),o=[...Nn(([u,f])=>(f*=50,f>=1?Xo(u*k,f):null),a)];if(!o.length)return{hues:a,meanHue:0,temp:0,areaTemp:0,area:0};const c=de(o)/k,l=Zo(c,n),h=l*i;return{hues:a,meanHue:c,temp:l,areaTemp:h,area:i}},Ko=[.1,.6,.72,.92],Zo=(t,[e,n,r,s]=Ko)=>2*(t<2/3?xn(n,e,t):xn(r,s,t))-1,Jo=(t,e)=>{let n=t.format!==j?t.as(j):t;e?.size&&(n=ei(n,e.size));const r=n.as(Ue),s=n.as(Or),i=ti(n,e),a=i.map(l=>l.area),o=Qo(i.map(l=>l.color),a,e?.minSat,e?.tempCoeffs),c=Ao(r.data);return{...o,img:n,imgGray:r,imgHsv:s,lumImg:c,temperature:Tn(s,e?.minSat,e?.tempCoeffs),contrastImg:c.max-c.min}},Qo=(t,e=vo(t.length),n,r)=>{const s=t.map(f=>Vr(f)),i=t.map(f=>_n(f)),a=i.map(f=>Ts(f)),o=i.map(f=>Hs(f)),c=i.map(f=>bn(f)),l=a.map(f=>f[0]),h=a.map(f=>f[1]),u=me(s,e);return{css:c,srgb:i,hsv:a,oklch:o,hue:_o(l),sat:me(h,e),chroma:me(o.map(f=>f[1]),e),lum:u,areas:e,contrast:u.max-u.min,colorContrast:xr(Re(nt(f=>Gs(...f)),Un(),To(i,i)),1,21,0,1),temperature:Tn(a,n,r)}},ti=(t,{dominantFn:e=kn,numColors:n=4,prec:r=.001}={})=>e(t,n).sort(pn("area",Vs)).map(s=>(jo(null,s.color,r),s)),ei=(t,e)=>{e=~~e;let n=t.width,r=t.height;return[n,r]=n>r?[e,~~Math.max(1,r/n*e)]:[~~Math.max(1,n/r*e),e],t.resize(n,r)};const ni={numColors:3,lightnessThreshold:.5,yFrom:0,yTo:1,maxSize:320,alphaThreshold:30};const ri=(t,e,n,r={})=>{const{alphaThreshold:s}={...ni,...r},i={any:!0,left:!0,right:!0,top:!0,bottom:!0};let a={any:0,left:0,right:0,top:0,bottom:0};const o=Math.floor(.15*e),c=Math.floor((n>100?.05:.5)*n),l=Math.floor(e*n*.001);if(e>0&&n>0){for(let h=0;h<e;h++){const u=(0*e+h)*4+3;if(t[u]>s&&(a.top++,a.top>=o)){i.top=!1;break}}for(let h=0;h<e;h++){const u=((n-1)*e+h)*4+3;if(t[u]>s&&(a.bottom++,a.bottom>=o)){i.bottom=!1;break}}for(let h=0;h<n;h++){const u=(h*e+0)*4+3;if(t[u]>s&&(a.left++,a.left>=c)){i.left=!1;break}}for(let h=0;h<n;h++){const u=(h*e+(e-1))*4+3;if(t[u]>s&&(a.right++,a.right>=c)){i.right=!1;break}}if(!i.top&&!i.bottom&&!i.left&&!i.right){for(let h=3;h<t.length;h+=4)if(t[h]>s&&(a.any++,a.any>=l)){i.any=!1;break}}else i.any=!0}return i};const si=(t,e,n,r=.5)=>(.299*t+.587*e+.114*n)/255<r;const oi=({buffer:t,imageData:e,width:n,height:r,settings:s,skipTransparencyCheck:i=!1})=>{const{numColors:a,lightnessThreshold:o}=s,c=Jo(t,{numColors:a,dominantFn:(d,g)=>kn(d,g,{filter:m=>_n(m).alpha>0}),prec:.01}),{lumImg:l,srgb:h,areas:u}=c;let f=!1;return!i&&e&&(f=ri(e,n,r,s)),{isDark:l.mean<o,isTransparent:i?!1:f?.any,transparencyInfo:i?null:f,dominantColors:h.map(({r:d,g,b:m},b)=>({color:bn([d,g,m]),area:u?.[b],isDark:si(d*255,g*255,m*255,o)}))}};self.onmessage=async t=>{const{imageBitmap:e,settings:n}=t.data;try{const r=await ii(e,n);self.postMessage({success:!0,data:r})}catch(r){self.postMessage({success:!1,error:r.message,stack:r.stack})}};async function ii(t,e){const r={...{numColors:3,lightnessThreshold:.5,yFrom:0,yTo:1,maxSize:600,alphaThreshold:50},...e},{yFrom:s,yTo:i,maxSize:a}=r,o=t.width,c=t.height;if(!o||!c)return!1;let l=1;(o>a||c>a)&&(l=Math.min(a/o,a/c));const h=Math.floor(o*l),u=Math.floor(c*l),f=0,d=Math.floor(s*c),g=Math.max(1,o),m=Math.max(1,Math.ceil((i-s)*c)),b=Math.max(1,h),A=Math.max(1,Math.ceil((i-s)*u)),E=new OffscreenCanvas(b,A);E.getContext("2d").drawImage(t,f,d,g,m,0,0,b,A);const Gt=Ir(E,j),qn=new OffscreenCanvas(h,u).getContext("2d");qn.drawImage(t,0,0,o,c,0,0,h,u);const ai=qn.getImageData(0,0,h,u).data;return oi({buffer:Gt,imageData:ai,width:h,height:u,settings:r})}})();\n';
2
2
  export {
3
3
  workerInline as default
4
4
  };