@pacem/pacem-theme-less 1.0.0-archimedes → 1.0.0-babbage

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.
@@ -1,10 +1,4 @@
1
- // tag prefix
2
- @tag_prefix: pacem;
3
- @P: @tag_prefix;
4
- @class_prefix: @tag_prefix;
5
- @PCSS: @class_prefix;
6
-
7
- // screen sizes
1
+ // screen sizes
8
2
  @threshold_xs: 0;
9
3
  @threshold_sm: 768px;
10
4
  @threshold_md: 992px;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-archimedes",
2
+ "version": "1.0.0-babbage",
3
3
  "name": "@pacem/pacem-theme-less",
4
4
  "type": "module",
5
5
  "homepage": "https://js.pacem.it",
package/shared.less CHANGED
@@ -1,4 +1,9 @@
1
- 
1
+ // tag prefix
2
+ @tag_prefix: pacem;
3
+ @P: @tag_prefix;
4
+ @class_prefix: @tag_prefix;
5
+ @PCSS: @class_prefix;
6
+
2
7
  @font_icons_apiurl: e("");
3
8
  @font_std_apiurl: e("");
4
9
  @font_tech_apiurl: e("");
package/themebuilder.js CHANGED
@@ -1,290 +1,9 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import yargs from 'yargs';
4
- import { hideBin } from 'yargs/helpers';
5
- import { Colors, NullChecker } from '@pacem/pacem-foundation';
6
- import { Mathematics } from '@pacem/pacem-numerical';
7
- const argv = yargs(hideBin(process.argv))
8
- .option('theme', {
9
- alias: 't',
10
- type: 'string',
11
- description: 'Theme (dark or light)',
12
- })
13
- .option('name', {
14
- alias: 'n',
15
- type: 'string',
16
- description: 'Theme name',
17
- })
18
- .option('src', {
19
- alias: 's',
20
- type: 'string',
21
- description: 'Palette file containing the color variables in JSON format.',
22
- })
23
- .option('out', {
24
- alias: 'o',
25
- type: 'string',
26
- description: 'Output file (overrides name option).',
27
- })
28
- .option('void', {
29
- type: 'string',
30
- description: 'Creates an empty palette file.',
31
- })
32
- .option('mincontrast', {
33
- type: 'number',
34
- description: 'The minimum WCAG contrast (1 to 21) container-to-background (default 1.5).',
35
- })
36
- .option('maxcontrast', {
37
- type: 'number',
38
- description: 'The maximum WCAG contrast (1 to 21) default-to-background (default 15).',
39
- })
40
- .option('contrast', {
41
- type: 'number',
42
- description: 'The minimim WCAG contrast (1 to 21) solid color-to-background (default 4.5).',
43
- })
44
- .help()
45
- .argv;
46
- const darkTheme = argv.theme === 'dark';
47
- const themeName = argv.name ?? (darkTheme ? 'dark' : 'light');
48
- function absolutePath(relativePath) {
49
- return path.join(import.meta.dirname, relativePath);
50
- }
51
- function readFile(src) {
52
- if (src == null) {
53
- return null;
54
- }
55
- const json = fs.readFileSync(src, 'utf-8');
56
- return JSON.parse(json);
57
- }
58
- const palette = Object.assign({
59
- background: '#1e2336',
60
- primary: '#429bbb',
61
- secondary: '#5e7881',
62
- accent: '#ff0085',
63
- success: '#4dc2b4',
64
- warning: '#c5c023',
65
- error: '#BF215B',
66
- danger: '#fa1f1f',
67
- info: '#99d4ff',
68
- green: '#1ebb8f',
69
- yellow: '#c2b010',
70
- brown: '#a6715e',
71
- red: '#dd2020',
72
- pink: '#ff0085',
73
- blue: '#116e8b',
74
- orange: '#d46d00',
75
- purple: '#624472',
76
- teal: '#429bbb',
77
- gray: '#808080',
78
- }, readFile(argv.src) ?? {});
79
- const WCAG_MINIMUM_CONTRAST = argv.mincontrast ?? 1.5;
80
- const WCAG_NORMAL_TEXT_CONTRAST = 4.5;
81
- const WCAG_NORMAL_COLOR_CONTRAST = argv.contrast ?? WCAG_NORMAL_TEXT_CONTRAST;
82
- const WCAG_SAFE_CONTRAST = 7;
83
- const WCAG_MAX_CONTRAST = argv.maxcontrast ?? 15;
84
- const WCAG_DISABLED_CONTRAST = 1.6;
85
- const SURFACE_LIGHT = .95;
86
- const SURFACE_DARK = .02;
87
- const MIN_SATURATION = .175;
88
- const searchFn = Mathematics.DataAnalysis.SearchFunctions.goldenRatio;
89
- let backgroundModule;
90
- let rootModule;
91
- function isColorLight(clr) {
92
- return Colors.luminance(clr) >= .2;
93
- }
94
- function contrastColor(baseColor, arg1 = baseColor, arg2 = WCAG_NORMAL_TEXT_CONTRAST, arg3 = null) {
95
- const benchmarkColor = typeof arg1 === 'object' ? arg1 : baseColor;
96
- const targetContrast = typeof arg1 === 'number' ? arg1 : (typeof arg2 === 'number' ? arg2 : WCAG_NORMAL_TEXT_CONTRAST);
97
- const lighterColor = typeof arg2 === 'boolean' ? arg2 : arg3;
98
- const { h, s, l, a } = Colors.hsl(baseColor);
99
- const isDark = lighterColor ?? !isColorLight(baseColor);
100
- const min = isDark ? l : 0;
101
- const max = isDark ? 1 : l;
102
- const newL = searchFn(min, max, x => Math.abs(targetContrast - Colors.contrastRatio(benchmarkColor, { h, s, l: x, a })).roundoff());
103
- return Colors.rgb({ h, s, l: newL, a });
104
- }
105
- function luminanceColor(baseColor, targetLuminance) {
106
- const { h, s, a } = Colors.hsl(baseColor);
107
- const newL = searchFn(0, 1, x => Math.abs(targetLuminance - Colors.luminance({ h, s, l: x, a })));
108
- return Colors.rgb({ h, s, l: newL, a });
109
- }
110
- function invertModule(mod) {
111
- return {
112
- base: mod.contrast,
113
- contrast: mod.base,
114
- active: mod.activeContrast,
115
- activeContrast: mod.active,
116
- emphasis: mod.base,
117
- container: mod.containerContrast,
118
- containerContrast: mod.container,
119
- containerActive: mod.containerActiveContrast,
120
- containerActiveContrast: mod.containerActive,
121
- };
122
- }
123
- function desaturateColor(clr, threshold = MIN_SATURATION) {
124
- const { h, s, l, a } = Colors.hsl(clr);
125
- if (s > threshold) {
126
- return Colors.rgb({ h, s: threshold, l, a });
127
- }
128
- else
129
- return clr;
130
- }
131
- function colorModuleBackground(clr, name, arg2) {
132
- const forcedContrast = (arg2 && typeof arg2 === 'number') ? arg2 : null;
133
- const baseContrast = forcedContrast ?? WCAG_MAX_CONTRAST;
134
- const contrastClr = arg2 && typeof arg2 === 'object' ? arg2 : null;
135
- const surfaceLight = name === 'background' ? SURFACE_LIGHT + .015 : SURFACE_LIGHT;
136
- const isColorRight = (darkTheme ? Colors.luminance(clr) <= SURFACE_DARK : Colors.luminance(clr) >= surfaceLight);
137
- const darkTargetLuminance = SURFACE_DARK;
138
- const lightTargetLuminance = surfaceLight;
139
- const referenceColor = isColorRight ? clr
140
- : (!darkTheme ? luminanceColor(clr, lightTargetLuminance) : luminanceColor(clr, darkTargetLuminance));
141
- let actualColor = contrastClr ? clr : referenceColor;
142
- const luminanceBackActiveOffset = darkTheme ? .035 : -.08;
143
- const contrastForeActive = forcedContrast ?? WCAG_SAFE_CONTRAST;
144
- const contrast = contrastClr ?? contrastColor(actualColor, baseContrast);
145
- const containerTargetContrast = WCAG_MINIMUM_CONTRAST;
146
- const containerBenchmarkColor = actualColor;
147
- const container = contrastColor(actualColor, containerBenchmarkColor, containerTargetContrast, darkTheme);
148
- const containerContrast = contrastColor(container, WCAG_NORMAL_TEXT_CONTRAST);
149
- const active = luminanceColor(actualColor, Colors.luminance(actualColor) + luminanceBackActiveOffset);
150
- const activeContrast = contrastColor(active, contrastForeActive);
151
- const containerActive = luminanceColor(container, Colors.luminance(container) + luminanceBackActiveOffset);
152
- const containerActiveContrast = contrastColor(containerActive, contrastForeActive);
153
- const emphasis = Colors.saturate(actualColor, 1.2);
154
- return {
155
- base: actualColor,
156
- contrast,
157
- active,
158
- activeContrast,
159
- containerActive,
160
- container,
161
- emphasis,
162
- containerActiveContrast,
163
- containerContrast
164
- };
165
- }
166
- function colorModuleDisabled(clr) {
167
- const baseContrast = Math.min(WCAG_MINIMUM_CONTRAST, WCAG_DISABLED_CONTRAST);
168
- const containerBenchmarkColor = backgroundModule.base;
169
- const preferBaseWithLighterColor = darkTheme;
170
- const preferContrastWithLighterColor = !preferBaseWithLighterColor;
171
- const referenceColor = contrastColor(clr, containerBenchmarkColor, 1);
172
- const actualColor = contrastColor(desaturateColor(referenceColor), containerBenchmarkColor, baseContrast, preferBaseWithLighterColor);
173
- const luminanceBackActiveOffset = darkTheme ? .1 : -.06;
174
- const contrast = contrastColor(actualColor, baseContrast, preferContrastWithLighterColor);
175
- const containerTargetContrast = 1.1;
176
- const container = contrastColor(actualColor, containerBenchmarkColor, containerTargetContrast, preferContrastWithLighterColor);
177
- const containerContrast = contrastColor(container, baseContrast, preferBaseWithLighterColor);
178
- const active = luminanceColor(actualColor, Colors.luminance(actualColor) + luminanceBackActiveOffset);
179
- const activeContrast = contrastColor(active, baseContrast, preferContrastWithLighterColor);
180
- const containerActive = luminanceColor(container, Colors.luminance(container) + luminanceBackActiveOffset);
181
- const containerActiveContrast = contrastColor(containerActive, baseContrast);
182
- const emphasis = Colors.lighten(actualColor, .1);
183
- return {
184
- base: actualColor,
185
- contrast,
186
- active,
187
- activeContrast,
188
- containerActive,
189
- container,
190
- emphasis,
191
- containerActiveContrast,
192
- containerContrast
193
- };
194
- }
195
- function colorModule(clr, name, arg2) {
196
- const isDesaturated = name === 'gray';
197
- const forcedContrast = (arg2 && typeof arg2 === 'number') ? arg2 : null;
198
- const baseContrast = forcedContrast ?? WCAG_SAFE_CONTRAST;
199
- const contrastClr = arg2 && typeof arg2 === 'object' ? arg2 : null;
200
- const isColorRight = isColorLight(clr) === darkTheme && Colors.contrastRatio(clr, backgroundModule.base) >= WCAG_NORMAL_COLOR_CONTRAST;
201
- const referenceColor = isColorRight ? clr
202
- : contrastColor(clr, backgroundModule.base, WCAG_NORMAL_COLOR_CONTRAST, darkTheme);
203
- let actualColor = contrastClr ? clr : referenceColor;
204
- if (isDesaturated) {
205
- actualColor = desaturateColor(actualColor);
206
- }
207
- const luminanceBackActiveOffset = darkTheme ? .1 : -.06;
208
- const contrastForeActive = forcedContrast ?? WCAG_SAFE_CONTRAST;
209
- const contrast = contrastClr ?? contrastColor(actualColor, baseContrast, !darkTheme);
210
- const containerTargetContrast = WCAG_MINIMUM_CONTRAST;
211
- const containerBenchmarkColor = backgroundModule.base;
212
- const container = contrastColor(actualColor, containerBenchmarkColor, containerTargetContrast, !darkTheme);
213
- const containerContrast = contrastColor(container, WCAG_NORMAL_TEXT_CONTRAST, darkTheme);
214
- const active = luminanceColor(actualColor, Colors.luminance(actualColor) + luminanceBackActiveOffset);
215
- const activeContrast = contrastColor(active, contrastForeActive, !darkTheme);
216
- const containerActive = luminanceColor(container, Colors.luminance(container) + luminanceBackActiveOffset);
217
- const containerActiveContrast = contrastColor(containerActive, contrastForeActive, darkTheme);
218
- const emphasis = isDesaturated ? Colors.lighten(actualColor, .1) : Colors.saturate(actualColor, 1.2);
219
- return {
220
- base: actualColor,
221
- contrast,
222
- active,
223
- activeContrast,
224
- containerActive,
225
- container,
226
- emphasis,
227
- containerActiveContrast,
228
- containerContrast
229
- };
230
- }
231
- const lessVariables = {};
232
- const a255 = (x) => Math.round(x * 255);
233
- const a255s = (c) => `${a255(c.r)}, ${a255(c.g)}, ${a255(c.b)}`;
234
- const pushLessVariables = (name, mod) => {
235
- lessVariables[`@color_${name}`] = Colors.stringify(mod.base);
236
- lessVariables[`@color_${name}_rgb`] = a255s(mod.base);
237
- lessVariables[`@color_${name}_inv`] = Colors.stringify(mod.contrast);
238
- lessVariables[`@color_${name}_inv_rgb`] = a255s(mod.contrast);
239
- lessVariables[`@color_${name}_container`] = Colors.stringify(mod.container);
240
- lessVariables[`@color_${name}_container_rgb`] = a255s(mod.container);
241
- lessVariables[`@color_${name}_container_inv`] = Colors.stringify(mod.containerContrast);
242
- lessVariables[`@color_${name}_container_inv_rgb`] = a255s(mod.containerContrast);
243
- lessVariables[`@color_${name}_active`] = Colors.stringify(mod.active);
244
- lessVariables[`@color_${name}_active_rgb`] = a255s(mod.active);
245
- lessVariables[`@color_${name}_active_inv`] = Colors.stringify(mod.activeContrast);
246
- lessVariables[`@color_${name}_active_inv_rgb`] = a255s(mod.activeContrast);
247
- lessVariables[`@color_${name}_container_active`] = Colors.stringify(mod.containerActive);
248
- lessVariables[`@color_${name}_container_active_rgb`] = a255s(mod.containerActive);
249
- lessVariables[`@color_${name}_container_active_inv`] = Colors.stringify(mod.containerActiveContrast);
250
- lessVariables[`@color_${name}_container_active_inv_rgb`] = a255s(mod.containerActiveContrast);
251
- lessVariables[`@color_${name}_emphasis`] = Colors.stringify(mod.emphasis);
252
- lessVariables[`@color_${name}_emphasis_rgb`] = a255s(mod.emphasis);
253
- };
254
- const backgroundColor = Colors.parse(palette['background']);
255
- backgroundModule = colorModuleBackground(backgroundColor, 'background');
256
- pushLessVariables('background', backgroundModule);
257
- const rootColor = 'root' in palette ? Colors.parse(palette['root']) : Colors.darken(backgroundModule.base, darkTheme ? .02 : .01);
258
- rootModule = colorModuleBackground(rootColor, 'root');
259
- pushLessVariables('root', rootModule);
260
- if ('default' in palette) {
261
- const defaultColor = contrastColor(Colors.parse(palette['default']), rootModule.base, WCAG_MAX_CONTRAST, darkTheme);
262
- const defaultModule = colorModule(defaultColor, 'default');
263
- pushLessVariables('default', defaultModule);
264
- }
265
- else {
266
- pushLessVariables('default', invertModule(rootModule));
267
- }
268
- const disabledColor = ('disabled' in palette) ? Colors.parse(palette['disabled']) : backgroundModule.base;
269
- pushLessVariables('disabled', colorModuleDisabled(disabledColor));
270
- for (let name in palette) {
271
- if (['default', 'background', 'root', 'disabled'].indexOf(name) >= 0) {
272
- continue;
273
- }
274
- const color = Colors.parse(palette[name]);
275
- const mod = colorModule(color, name);
276
- pushLessVariables(name, mod);
277
- }
278
- if (!('invert' in palette)) {
279
- pushLessVariables('invert', invertModule(backgroundModule));
280
- }
281
- let lessText = '@palette_prebuilt: true;\r\n';
282
- for (let name in lessVariables) {
283
- const hex = lessVariables[name];
284
- lessText += `${name}: ${hex};\r\n`;
285
- }
286
- const target = argv.out ?? absolutePath('./pacem/palette-' + themeName + '.less');
287
- if (!NullChecker.isNull(argv.void)) {
288
- lessText = '';
289
- }
290
- fs.writeFileSync(target, lessText);
1
+ import We from"node:fs";import zr from"node:path";import Pr from"yargs";import{hideBin as Sr}from"yargs/helpers";var cn=Object.defineProperty,ke=(n,t)=>{for(var e in t)cn(n,e,{get:t[e],enumerable:!0})};Number.prototype.isCloseTo=function(n,t=14){let e=+`1e-${t}`;return this>n-e&&this<n+e};Number.prototype.roundoff=function(n=14){return parseFloat(this.toFixed(n))};Number.prototype.clamp=function(n,t){let e=this;return n!=null&&!isNaN(n)&&(e=Math.max(e,n)),t!=null&&!isNaN(t)&&(e=Math.min(e,t)),e};Number.prototype.toBase62=function(){for(var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t=this,e="";t!=0;){var r=t%62;e=n.charAt(r)+e,t=Math.floor(t/62)}return e};Number.prototype.toBase36=function(){return this.toString(36)};var ln=/^\/Date\([\d]+\)\/$/i,un=class qt{static parse(t){let e;return typeof t=="string"?(ln.test(t)?e=parseInt(t.substring(6)):e=Date.parse(t),new Date(e)):typeof t=="number"?new Date(t):t}static isLeapYear(t){return t%4===0&&t%100!==0||t%400===0}static daysInMonth(t,e){return[31,qt.isLeapYear(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]}static isDate(t){return t instanceof Date&&!isNaN(t.valueOf())}static dateOnly(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}static addMonths(t,e){let r=t.getDate(),s=new Date(t),i=s.getMonth()+e,o=0;for(;i<0;)i+=12,o--;return s.setDate(1),s.setMonth(i%12),s.setFullYear(s.getFullYear()+o+Math.floor(i/12)),s.setDate(Math.min(r,qt.daysInMonth(s.getFullYear(),s.getMonth()))),s}static addDays(t,e){return new Date(t.valueOf()+e*864e5)}static daysBetween(t,e){return(e.valueOf()-t.valueOf())/864e5}},X=class Wt{static isNull(t){return t==null}static isEmpty(t){try{return Array.isArray(t)&&t.length===0||typeof t=="string"&&t===""||typeof t=="object"&&Object.keys(t).length===0&&!un.isDate(t)&&!(t instanceof RegExp)&&!(t instanceof FileSystemDirectoryHandle)&&!(t instanceof FileSystemFileHandle)}catch{return!1}}static isNullOrEmpty(t){return Wt.isNull(t)||Wt.isEmpty(t)}};Array.prototype.distinct=function(){return Array.from(new Set(this))};Array.prototype.union=function(n){let t=X.isNullOrEmpty(this),e=X.isNullOrEmpty(n);return t&&e?[]:e?this.slice():t?n.slice():this.concat(n).distinct()};Array.prototype.moveWithin=function(n,t){let e="Index must be greater or equal than 0 and less or equal than the length of the array.";var r=this;if(n<0||n>r.length)throw new Error(e);if(t<0||t>r.length)throw new Error(e);r.splice(t,0,Array.prototype.splice.apply(r,[n,1])[0])};Array.prototype.equalsContent=function(n){if(n==null||this.length!==n.length)return!1;for(let t=0;t<this.length;t++)if(this[t]!==n[t])return!1;return!0};Array.prototype.cloneFrom=function(n){if(n==null)throw"Cannot clone array from null object.";let t=n.length;var e=this.length!==n.length;for(let r=0;r<t;r++){let s=n[r];this.length>r?this[r]!==s&&(this[r]=s,e=!0):(Array.prototype.push.apply(this,[s]),e=!0)}e&&this.splice(t)};var ye=/^hsl\s*\(\s*([\d\.]+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*\)$/,me=/^hsla\s*\(\s*([\d\.]+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)\)$/,pe=/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/,xe=/^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\)$/,be=/^#[a-f0-9]{6}$/,we=/^#[a-f0-9]{3}$/;function It(n){return!X.isNullOrEmpty(n)&&typeof n=="object"&&"r"in n&&"g"in n&&"b"in n&&typeof n.r=="number"&&typeof n.b=="number"&&typeof n.g=="number"?(n.a??=1,n.r>=0&&n.r<=1&&n.g>=0&&n.g<=1&&n.b>=0&&n.b<=1&&n.a>=0&&n.a<=1):!1}function Q(n){return!X.isNullOrEmpty(n)&&typeof n=="object"&&"h"in n&&"s"in n&&"l"in n&&typeof n.h=="number"&&typeof n.s=="number"&&typeof n.l=="number"?(n.a??=1,n.h>=0&&n.h<=360&&n.s>=0&&n.s<=1&&n.l>=0&&n.l<=1&&n.a>=0&&n.a<=1):!1}function fn(n){let t=n.r,e=n.g,r=n.b;return(.5*(Math.max(t,e,r)+Math.min(t,e,r))).clamp(0,1)}var D={adjustRgbChannel:n=>n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4),adjustRgbChannelInv:n=>n<=.00304?n*12.92:1.055*(Math.pow(n,1/2.4)-.055),adjustRgb:n=>({r:D.adjustRgbChannel(n.r),g:D.adjustRgbChannel(n.g),b:D.adjustRgbChannel(n.b),a:n.a}),adjustRgbInv:n=>({r:D.adjustRgbChannelInv(n.r),g:D.adjustRgbChannelInv(n.g),b:D.adjustRgbChannelInv(n.b),a:n.a}),X:n=>.4125*n.r+.3576*n.g+.1804*n.b,Y:n=>.2126*n.r+.7152*n.g+.0722*n.b,Z:n=>.0193*n.r+.1191*n.g+.9503*n.b,relativeLuminance:n=>{let t=D.adjustRgb(n);return D.Y(t)},rgbToCieXYZ:n=>{let t=D.adjustRgb(n);return{x:D.X(t),y:D.Y(t),z:D.Z(t),a:n.a}},cieXYZToRgb:n=>{let t=3.241*n.x-1.5374*n.y-.4986*n.z,e=-.9692*n.x+1.876*n.y+.0416*n.z,r=.0556*n.x-.204*n.y+1.057*n.z;return D.adjustRgbInv({r:t,g:e,b:r,a:n.a})},contrastRatio:(n,t)=>{let e=D.relativeLuminance(n)+.05,r=D.relativeLuminance(t)+.05;return e>r?e/r:r/e}};function hn(n,t){let e=n.r,r=n.g,s=n.b,i=Math.max(e,r,s),o=Math.min(e,r,s);return(t===0||t===1?0:(i-o)/(1-Math.abs(2*t-1))).clamp(0,1)}function dn(n){let t=n.r,e=n.g,r=n.b,s=Math.max(t,e,r),i=Math.min(t,e,r),o=0;return s!==i&&(s===t?o=(60*((e-r)/(s-i))+360)%360:s===e?o=(60*((r-t)/(s-i))+120)%360:o=(60*((t-e)/(s-i))+240)%360),o.clamp(0,360)}function Vt(n){return n.toString(16).padStart(2,"0")}var I=class Mt{static{this.WCAG_MINIMUM_CONTRAST=3}static{this.WCAG_NORMAL_TEXT_CONTRAST=4.5}static{this.WCAG_SAFE_CONTRAST=7}static _clampRGB(t){let e=r=>Math.min(1,Math.max(0,r));return t[3]==null&&(t[3]=1),{r:e(t[0]),g:e(t[1]),b:e(t[2]),a:Math.min(1,Math.max(0,t[3]))}}static _normalize(t){return[t[0]/255,t[1]/255,t[2]/255,t[3]]}static parse(t){if(t=(t||"").toLowerCase(),pe.test(t)){let e=pe.exec(t);return this._clampRGB(this._normalize([parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),1]))}if(xe.test(t)){let e=xe.exec(t);return this._clampRGB(this._normalize([parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),parseFloat(e[4])]))}if(be.test(t)){let e=be.exec(t)[0];return this._clampRGB(this._normalize([parseInt("0x"+e.substr(1,2)),parseInt("0x"+e.substr(3,2)),parseInt("0x"+e.substr(5,2)),1]))}if(we.test(t)){let e=we.exec(t)[0],r=e.substr(1,1),s=e.substr(2,1),i=e.substr(3,1);return this._clampRGB(this._normalize([parseInt("0x"+r+r),parseInt("0x"+s+s),parseInt("0x"+i+i),1]))}if(ye.test(t)){let e=ye.exec(t),r={h:parseFloat(e[1]),s:parseFloat(e[2])*.01,l:parseFloat(e[3])*.01};return this.rgb(r)}if(me.test(t)){let e=me.exec(t),r={h:parseFloat(e[1]),s:parseFloat(e[2])*.01,l:parseFloat(e[3])*.01,a:parseFloat(e[4])};return this.rgb(r)}}static hsl(t){let e=fn(t),r=hn(t,e);return{h:dn(t),s:r,l:e,a:t.a}}static cieXYZ(t){return Q(t)&&(t=this.rgb(t)),D.rgbToCieXYZ(t)}static rgb(t){if(Q(t)){let e=t.h,r=t.s,s=t.l,i=e/60,o=(1-Math.abs(2*s-1))*r,a=o*(1-Math.abs(i%2-1)),c=s-o/2,l=(f,d,m)=>this._clampRGB([f+c,d+c,m+c,t.a]);if(i<=1)return l(o,a,0);if(i<=2)return l(a,o,0);if(i<=3)return l(0,o,a);if(i<=4)return l(0,a,o);if(i<=5)return l(a,0,o);if(i<=6)return l(o,0,a)}else{let e=D.cieXYZToRgb(t);return this._clampRGB([e.r,e.g,e.b,e.a])}}static stringify(t,e=1){if(Q(t)){e??=1,t.a??=1;let r=typeof e=="number"?e:1;return`hsla(${t.h.roundoff(r)},${(t.s*100).roundoff(r)}%,${(t.l*100).roundoff(r)}%,${t.a.roundoff()})`}else if(It(t)){e??=!0,t.a??=1;let r=typeof e=="boolean"?e:!!e,s=Math.round(t.r*255),i=Math.round(t.g*255),o=Math.round(t.b*255),a=t.a.roundoff();return a===1?r?("#"+Vt(s)+Vt(i)+Vt(o)).toUpperCase():`rgb(${s},${i},${o})`:`rgba(${s},${i},${o},${a})`}}static contrastRatio(t,e){return Q(t)&&(t=this.rgb(t)),Q(e)&&(e=this.rgb(e)),D.contrastRatio(t,e)}static luminance(t){return Q(t)&&(t=Mt.rgb(t)),D.relativeLuminance(t)}static lighten(t,e=.1){if(e||=0,Q(t)){let r=Math.min(1,Math.max(0,t.l+e));return Object.assign({},t,{l:r})}if(It(t)){let r=this.lighten(this.hsl(t),e);return this.rgb(r)}return t}static darken(t,e=.1){return this.lighten(t,-e)}static saturate(t,e=.1){if(e||=0,Q(t)){let r=Math.min(1,Math.max(0,t.s+e));return Object.assign({},t,{s:r})}if(It(t)){let r=this.saturate(this.hsl(t),e);return this.rgb(r)}return t}static desaturate(t,e=.1){return this.saturate(t,-e)}static interpolate(t,e,r,s){r??=.5,s??=r;let i=(r+s).roundoff(),o=(r/i).roundoff(),a=(s/i).roundoff(),c=It(t),l=Q(t),f=m=>It(m)||Q(m)?Mt.cieXYZ(m):m;t=f(t),e=f(e);let d={x:(t.x*o+e.x*a).roundoff(),y:(t.y*o+e.y*a).roundoff(),z:(t.z*o+e.z*a).roundoff(),a:(t.a*o+e.a*a).roundoff()};return c?Mt.rgb(d):l?Mt.hsl(Mt.rgb(d)):d}};var gn={};ke(gn,{Markdown:()=>Te,Parser:()=>Me});var Te={};ke(Te,{Parser:()=>Fn});var yn=class{tokenize(n,t){let e=[];for(;n;){let r=n.length;for(let s of t){let i=s.exec(n,this),o=i?.length;if(o>0){Array.prototype.push.apply(e,i);let a=i[o-1];n=n.substr((a.index||0)+a.raw.length);break}}if(n.length>=r)throw new Error(`Cannot parse
2
+ "${n}"
3
+ using the provided grammar.`)}return e}},Me=class{constructor(n=new yn){this._lexer=n}parse(n,t,e){let r=this._lexer.tokenize(n,t);return e.render(r)}};function Qt(n){return(n??"").replace(/</g,"&lt;")}function mn(n){if(!X.isNullOrEmpty(n)&&!(/^\(/.test(n)&&/\)$/.test(n)))return/^\[/.test(n)&&/\]$/.test(n)&&(n=n.substr(1,n.length-2)),n}function J(n){return n?.index||void 0}function pn(n){if(!X.isNullOrEmpty(n)&&!(/^\[/.test(n)&&/\]$/.test(n)))return/^\(/.test(n)&&/\)$/.test(n)&&(n=n.substr(1,n.length-2)),n}function Ot(n){return n?.replace(/[^\w]+/g," ").trim().replace(/ +/g,"-").toLowerCase()}function Z(n,t,e){let r=t.exec(n);return r&&r.length?e(r):null}var xn=/(<!--)([\s\S]*?)(-->|$)/,bn=/^ {0,3}(={3,}|_{3,}|-{3,})(\r?\n|$)/,wn=/^ {0,3}(#{1,6})\s+([^\n]+)(\r?\n|$)+/,vn=/^ {0,3}([^\n]+)(\r?\n=+(\r?\n|$))+/,Cn=/^ {0,3}([^\n]+)(\r?\n-+(\r?\n|$))+/,kn=/^ {4,}.+(\r?\n {4,}.+)*(\r?\n|$)+/,Tn=/^ {0,3}``` *([^\n]*)\r?\n(([\s\S](?!\r?\n {0,3}```))*.(\r?\n)+) {0,3}```(\r?\n|$)+/,Mn=/^ {0,3}> *([^\n]+)(\r?\n {0,3}> *([^\n]*))*(\r?\n|$)+/,Rn=/^( {0,3}([-+]).*\r?\n|$)((?!(?: {0,3}(?:\d+[.\)]|\r?\n\S))).*(\r?\n|$))*/,An=/^( {0,3}(\d+[.\)]).*\r?\n|$)((?!(?: {0,3}(?:[+-]|\r?\n\S))).*(\r?\n|$))*/,ve=/^(?:[-+*]|\d+[.\)])/m,En=/^(?! {4,})(.+(\n(?! {0,3}```)(?! {0,3}([-+]|\d+[.\)]))(?! {4,})(?! {0,3}>).+)*)/,In=/^ {0,3}(!?)\[([^\]]+)\]: +(\S+)(?: +['"\(](.+)['"\)])?(\r?\n|$)+/,Nn=/!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?(\[[^\[\]]*\]|\([^\(\)]*\))?/,$n=/(\*\*?|__?)(\[[^\]]*]\([^\)]+\))\1/,Jt=/(?:(?<!\\)`)(.+?)(?:(?<!\\)`)/,Bn=/(\*\*?|__?)((?!\1\s?)(?:(?!\1)[\S\s])*[^\s])\1/,zn=/(~~?|__?)(?!\1\s?)([^\s][\s\S]*?(?!\1)[^\s])\1/,Pn=/(:")(?!":\s?)([^\s][\s\S]*?(?!":)[^\s])":/,Sn=/^\s+/,Ln=/ {2,}\r?\n/,On=/^[^\r\n]+/,v;(function(n){n.Html="html",n.Text="text",n.Paragraph="paragraph",n.BlockQuote="blockquote",n.Space="space",n.Heading="heading",n.Bold="bold",n.Italic="italic",n.CodeBlock="codeblock",n.Code="code",n.Image="img",n.ImageLike="imglike",n.Link="link",n.LinkLike="linklike",n.LineBreak="br",n.StrikeThrough="strike",n.Quote="quote",n.HorizontalRule="hr",n.OrderedList="ol",n.UnorderedList="ul",n.ListItem="listitem",n.Reference="ref"})(v||(v={}));var N;(function(n){n[n.Comment=0]="Comment",n[n.Reference=1]="Reference",n[n.HorizontalRule=2]="HorizontalRule",n[n.Heading=3]="Heading",n[n.Heading1=4]="Heading1",n[n.Heading2=5]="Heading2",n[n.CodeBlock=6]="CodeBlock",n[n.Fences=7]="Fences",n[n.BlockQuote=8]="BlockQuote",n[n.OrderedList=9]="OrderedList",n[n.UnorderedList=10]="UnorderedList",n[n.Paragraph=11]="Paragraph",n[n.EmphasizedLink=12]="EmphasizedLink",n[n.ImageOrLink=13]="ImageOrLink",n[n.Emphasize=14]="Emphasize",n[n.StrikeThrough=15]="StrikeThrough",n[n.Quote=16]="Quote",n[n.Code=17]="Code",n[n.LineBreak=18]="LineBreak",n[n.Text=254]="Text",n[n.Space=255]="Space"})(N||(N={}));function Dt(n=[]){let t={[N.Comment]:{exec:(g,h)=>Z(g,xn,u=>{let y=J(u),p=[{type:v.Html,index:y,raw:u[0],text:u[2]}];if(y>0){let C=g.substr(0,y),M=h.tokenize(C,b);Array.prototype.unshift.apply(p,M)}return p})},[N.Reference]:{exec:g=>Z(g,In,h=>{let u=J(h),y=h[0],p=y,C=h[1]==="!",M=h[2],R=h[3],T=h[4];return[{type:v.Reference,index:u,raw:y,text:p,id:M,image:C,url:R,title:T}]})}},e=[],r=[],s={};for(let g of n){let h,u="inline";switch("type"in g?(u=g.type,h=g.rule):h=g,u){case"block":e.push(h);break;case"code":if("lang"in g){let p=g.lang.toLowerCase();(s[p]=s[p]||[]).push(h)}break;default:let y={exec:(p,C)=>{let M=h.exec(p,C);return a(p,M,C),M}};r.push(y);break}}let i={[N.Text]:{exec:g=>Z(g,On,h=>{let u=h[0],y=u;return[{index:J(h),raw:u,text:y,type:v.Text}]})},[N.Space]:{exec:g=>Z(g,Sn,h=>{let u=h[0];return[{type:v.Space,raw:u,text:u}]})}},o={[N.ImageOrLink]:{exec:(g,h)=>c(g,Nn,h,u=>{let y=J(u),p=u[0],C=p.charAt(0)==="!",M=u[1],R=pn(u[2]),T=Ot(mn(u[2])??M);return C?[{index:y,type:R?v.Image:v.ImageLike,raw:p,text:M,src:R,ref:T,tokens:h.tokenize(M,l)}]:[{index:y,type:R?v.Link:v.LinkLike,raw:p,text:M,href:R,ref:T,tokens:h.tokenize(M,l)}]})},[N.Code]:{exec:(g,h)=>c(g,Jt,h,u=>{let y=Qt(u[1]);return[{type:v.Code,raw:u[0],text:y,index:J(u)}]})},[N.EmphasizedLink]:{exec:(g,h)=>c(g,$n,h,u=>{if(u.length<3||X.isNullOrEmpty(u[2]))return null;let y=u[1].length>1?v.Bold:v.Italic,p=u[2];return[{index:J(u),type:y,raw:u[0],text:p,tokens:h.tokenize(p,l)}]})},[N.Emphasize]:{exec:(g,h)=>c(g,Bn,h,u=>{if(u.length<3||X.isNullOrEmpty(u[2]))return null;let y=u[1].length>1?v.Bold:v.Italic,p=u[2];return[{index:J(u),type:y,raw:u[0],text:p,tokens:h.tokenize(p,l)}]})},[N.StrikeThrough]:{exec:(g,h)=>c(g,zn,h,u=>{if(u.length<3||X.isNullOrEmpty(u[2]))return null;let y=v.StrikeThrough,p=u[2];return[{index:J(u),type:y,raw:u[0],text:p,tokens:h.tokenize(p,l)}]})},[N.Quote]:{exec:(g,h)=>c(g,Pn,h,u=>{if(u.length<3||X.isNullOrEmpty(u[2]))return null;let y=v.Quote,p=u[2];return[{index:J(u),type:y,raw:u[0],text:p,tokens:h.tokenize(p,l)}]})},[N.LineBreak]:{exec:(g,h)=>c(g,Ln,h,u=>{let y=u[0],p=y;return[{index:J(u),raw:y,text:p,type:v.LineBreak}]})}},a=(g,h,u)=>{let y=h?.length>0&&h[0].index;if(y>0){let p=g.substr(0,y),C=u.tokenize(p,l)||[];Array.prototype.unshift.apply(h,C)}},c=(g,h,u,y)=>{let p=Z(g,h,C=>{if(h!=Jt){let M=Jt.exec(g);if(M&&M.length&&M.index<C.index)return null}return y(C)});return a(g,p,u),p},l=Object.values(o);Array.prototype.push.apply(l,r),l.push(i[N.Text],i[N.Space]);let f=g=>{let h=[i[N.Text],i[N.Space]],u=g?.toLowerCase()||"";return u&&u in s&&Array.prototype.unshift.apply(h,s[u]),h},d={[N.Paragraph]:{exec:(g,h)=>Z(g,En,u=>{let y=u[0],p=y;return[{type:v.Paragraph,raw:y,text:p,tokens:h.tokenize(p,l)}]})},[N.Space]:i[N.Space]},m=(g,h)=>{let u=/^ {0,3}(`{3,}|$|>|[+-]\s|\d+[.\)])/m.test(g)?b:l;return h.tokenize(g,u)},x={[N.HorizontalRule]:{exec:(g,h)=>Z(g,bn,u=>{let y=u[0],p=y;return[{type:v.HorizontalRule,raw:y,text:p}]})},[N.Heading]:{exec:(g,h)=>Z(g,wn,u=>{let y=u[2];return[{type:v.Heading,raw:u[0],text:y,level:u[1].length,ref:Ot(y),tokens:h.tokenize(y,l)}]})},[N.Heading1]:{exec:(g,h)=>Z(g,vn,u=>{let y=u[1];return[{type:v.Heading,raw:u[0],text:y,level:1,ref:Ot(y),tokens:h.tokenize(y,l)}]})},[N.Heading2]:{exec:(g,h)=>Z(g,Cn,u=>{let y=u[1];return[{type:v.Heading,raw:u[0],text:y,level:2,ref:Ot(y),tokens:h.tokenize(y,l)}]})},[N.CodeBlock]:{exec:(g,h)=>Z(g,kn,u=>{let y=u[0],p=Qt(y);return[{type:v.CodeBlock,raw:y,text:p,tokens:h.tokenize(p,[])}]})},[N.Fences]:{exec:(g,h)=>Z(g,Tn,u=>{let y=Qt(u[2]),p=u[1]?.toLowerCase();return[{type:v.CodeBlock,raw:u[0],text:y,lang:p,tokens:h.tokenize(y,f(p))}]})},[N.BlockQuote]:{exec:(g,h)=>Z(g,Mn,u=>{let y=u[0],p=y.replace(/^ {0,3}> */gm,"");return[{type:v.BlockQuote,raw:y,text:p,tokens:h.tokenize(p,[d[N.Paragraph],d[N.Space]])}]})},[N.OrderedList]:{exec:(g,h)=>Z(g,An,u=>{let y=u[0],p=y.replace(/^ {0,3}/gm,"").split(ve).filter(C=>!X.isNullOrEmpty(C)).map(C=>C.trim());return[{type:v.OrderedList,start:parseInt(/\d/.exec(u[0])[0]),raw:y,text:y,tokens:p.map(C=>({type:v.ListItem,raw:C,text:C,tokens:m(C,h)}))}]})},[N.UnorderedList]:{exec:(g,h)=>Z(g,Rn,u=>{let y=u[0],p=y.replace(/^ {0,3}/gm,"").split(ve).filter(C=>!X.isNullOrEmpty(C)).map(C=>C.trim());return[{type:v.UnorderedList,raw:y,text:y,tokens:p.map(C=>({type:v.ListItem,raw:C,text:C,tokens:m(C,h)}))}]})}},b=Object.values(x);return Array.prototype.push.apply(b,e),b.push(d[N.Paragraph],d[N.Space]),[t[N.Comment],t[N.Reference]].concat(b)}var Dn="\0",Hn=/[ \r\n]*\0+[ \r\n]*/g;function _n(n){return n?.replace(Hn,`
4
+ `).trim()}var Ce=class{constructor(n=(t,e)=>t?.text||""){this._extraItemRender=n,this._renderContent=t=>{let e=t.tokens;return X.isNullOrEmpty(e)?t.text:this._render(e)}}_rendeItem(n,t){let e=this._renderContent,r=Dn;switch(n?.type){case v.Reference:return"";case v.Html:return n.raw;case v.BlockQuote:return`<blockquote>
5
+ ${e(n)}</blockquote>${r}`;case v.Bold:return`<b>${e(n)}</b>`;case v.CodeBlock:let s=n.lang;return`<pre>${r}<code${s?' class="'+s+'"':""}>${e(n)}</code>${r}</pre>${r}`;case v.Code:return`<code>${e(n)}</code>`;case v.HorizontalRule:return`<hr />${r}`;case v.Heading:let i=n.level,o=n.ref;return`<h${i} id="${o}">${e(n)}</h${i}>${r}`;case v.Image:case v.ImageLike:let a=n,c=a.src,l="",f=a.text,d=a.ref;if(!c&&d){let h=t.find(u=>u.type===v.Reference&&u.image===!0&&u.id?.toLowerCase()===d.toLowerCase());h&&(c=h.url,l=h.title??"")}return c?`<img src="${c}" alt="${f}"${l?' title="'+l+'"':""} />`:`![${e(n)}]`;case v.Italic:return`<i>${e(n)}</i>`;case v.StrikeThrough:return`<s>${e(n)}</s>`;case v.Quote:return`<q>${e(n)}</q>`;case v.LineBreak:return"<br />"+r;case v.OrderedList:return`<ol start="${n.start}">
6
+ ${e(n)}</ol>${r}`;case v.UnorderedList:return`<ul>
7
+ ${e(n)}</ul>${r}`;case v.ListItem:return` <li>${e(n)}</li>${r}`;case v.Link:case v.LinkLike:let m=n,x=m.href,b="",g=m.ref;if(!x&&g){let h=t.find(u=>u.type===v.Reference&&u.image!==!0&&u.id?.toLowerCase()===g.toLowerCase());h&&(x=h.url,b=h.title??"")}return x?`<a href="${x}"${b?' title="'+b+'"':""}>${e(n)}</a>`:`[${e(n)}]`;case v.Paragraph:return`<p>${e(n)}</p>${r}`;case v.Text:case v.Space:return n.text}return this._extraItemRender(n,t)}_render(n){let t="";for(let e of n||[])t+=this._rendeItem(e,n);return t}render(n){return _n(this._render(n))}},Yn=class{_render(n){return X.isNullOrEmpty(n)?"":JSON.stringify(n)}render(n){return"["+n.filter(t=>!X.isNullOrEmpty(t)).map(this._render).join(",")+"]"}};function Xn(n){return n&&typeof n=="object"&&typeof n.render=="function"}var Fn=class extends Me{toHtml(n,t,e){let r=new Ce(e);return X.isNullOrEmpty(t)?this.parse(n,r):this.parse(n,Dt(t),r)}tokenize(n,t){let e=this.parse(n,Dt(t),new Yn);return JSON.parse(e)}parse(n,t=Dt(),e=new Ce){return Xn(t)?super.parse(n,Dt(),t):super.parse(n,t,e)}};Number.prototype.isCloseTo=function(n,t=14){let e=+`1e-${t}`;return this>n-e&&this<n+e};Number.prototype.roundoff=function(n=14){return parseFloat(this.toFixed(n))};Number.prototype.clamp=function(n,t){let e=this;return n!=null&&!isNaN(n)&&(e=Math.max(e,n)),t!=null&&!isNaN(t)&&(e=Math.min(e,t)),e};Number.prototype.toBase62=function(){for(var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t=this,e="";t!=0;){var r=t%62;e=n.charAt(r)+e,t=Math.floor(t/62)}return e};Number.prototype.toBase36=function(){return this.toString(36)};var jn=/^\/Date\([\d]+\)\/$/i,Ht=class n{static parse(t){let e;return typeof t=="string"?(jn.test(t)?e=parseInt(t.substring(6)):e=Date.parse(t),new Date(e)):typeof t=="number"?new Date(t):t}static isLeapYear(t){return t%4===0&&t%100!==0||t%400===0}static daysInMonth(t,e){return[31,n.isLeapYear(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]}static isDate(t){return t instanceof Date&&!isNaN(t.valueOf())}static dateOnly(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}static addMonths(t,e){let r=t.getDate(),s=new Date(t),i=s.getMonth()+e,o=0;for(;i<0;)i+=12,o--;return s.setDate(1),s.setMonth(i%12),s.setFullYear(s.getFullYear()+o+Math.floor(i/12)),s.setDate(Math.min(r,n.daysInMonth(s.getFullYear(),s.getMonth()))),s}static addDays(t,e){return new Date(t.valueOf()+e*864e5)}static daysBetween(t,e){return(e.valueOf()-t.valueOf())/864e5}};var z=class n{static isNull(t){return t==null}static isEmpty(t){try{return Array.isArray(t)&&t.length===0||typeof t=="string"&&t===""||typeof t=="object"&&Object.keys(t).length===0&&!Ht.isDate(t)&&!(t instanceof RegExp)&&!(t instanceof FileSystemDirectoryHandle)&&!(t instanceof FileSystemFileHandle)}catch{return!1}}static isNullOrEmpty(t){return n.isNull(t)||n.isEmpty(t)}};Array.prototype.distinct=function(){return Array.from(new Set(this))};Array.prototype.union=function(n){let t=z.isNullOrEmpty(this),e=z.isNullOrEmpty(n);return t&&e?[]:e?this.slice():t?n.slice():this.concat(n).distinct()};Array.prototype.moveWithin=function(n,t){let e="Index must be greater or equal than 0 and less or equal than the length of the array.";var r=this;if(n<0||n>r.length)throw new Error(e);if(t<0||t>r.length)throw new Error(e);r.splice(t,0,Array.prototype.splice.apply(r,[n,1])[0])};Array.prototype.equalsContent=function(n){if(n==null||this.length!==n.length)return!1;for(let t=0;t<this.length;t++)if(this[t]!==n[t])return!1;return!0};Array.prototype.cloneFrom=function(n){if(n==null)throw"Cannot clone array from null object.";let t=n.length;var e=this.length!==n.length;for(let r=0;r<t;r++){let s=n[r];this.length>r?this[r]!==s&&(this[r]=s,e=!0):(Array.prototype.push.apply(this,[s]),e=!0)}e&&this.splice(t)};var Re=/^hsl\s*\(\s*([\d\.]+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*\)$/,Ae=/^hsla\s*\(\s*([\d\.]+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)\)$/,Ee=/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/,Ie=/^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\)$/,Ne=/^#[a-f0-9]{6}$/,$e=/^#[a-f0-9]{3}$/;function Nt(n){return!z.isNullOrEmpty(n)&&typeof n=="object"&&"r"in n&&"g"in n&&"b"in n&&typeof n.r=="number"&&typeof n.b=="number"&&typeof n.g=="number"?(n.a??=1,n.r>=0&&n.r<=1&&n.g>=0&&n.g<=1&&n.b>=0&&n.b<=1&&n.a>=0&&n.a<=1):!1}function q(n){return!z.isNullOrEmpty(n)&&typeof n=="object"&&"h"in n&&"s"in n&&"l"in n&&typeof n.h=="number"&&typeof n.s=="number"&&typeof n.l=="number"?(n.a??=1,n.h>=0&&n.h<=360&&n.s>=0&&n.s<=1&&n.l>=0&&n.l<=1&&n.a>=0&&n.a<=1):!1}function Zn(n){let t=n.r,e=n.g,r=n.b;return(.5*(Math.max(t,e,r)+Math.min(t,e,r))).clamp(0,1)}var H={adjustRgbChannel:n=>n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4),adjustRgbChannelInv:n=>n<=.00304?n*12.92:1.055*(Math.pow(n,1/2.4)-.055),adjustRgb:n=>({r:H.adjustRgbChannel(n.r),g:H.adjustRgbChannel(n.g),b:H.adjustRgbChannel(n.b),a:n.a}),adjustRgbInv:n=>({r:H.adjustRgbChannelInv(n.r),g:H.adjustRgbChannelInv(n.g),b:H.adjustRgbChannelInv(n.b),a:n.a}),X:n=>.4125*n.r+.3576*n.g+.1804*n.b,Y:n=>.2126*n.r+.7152*n.g+.0722*n.b,Z:n=>.0193*n.r+.1191*n.g+.9503*n.b,relativeLuminance:n=>{let t=H.adjustRgb(n);return H.Y(t)},rgbToCieXYZ:n=>{let t=H.adjustRgb(n);return{x:H.X(t),y:H.Y(t),z:H.Z(t),a:n.a}},cieXYZToRgb:n=>{let t=3.241*n.x-1.5374*n.y-.4986*n.z,e=-.9692*n.x+1.876*n.y+.0416*n.z,r=.0556*n.x-.204*n.y+1.057*n.z;return H.adjustRgbInv({r:t,g:e,b:r,a:n.a})},contrastRatio:(n,t)=>{let e=H.relativeLuminance(n)+.05,r=H.relativeLuminance(t)+.05;return e>r?e/r:r/e}};function Gn(n,t){let e=n.r,r=n.g,s=n.b,i=Math.max(e,r,s),o=Math.min(e,r,s);return(t===0||t===1?0:(i-o)/(1-Math.abs(2*t-1))).clamp(0,1)}function Un(n){let t=n.r,e=n.g,r=n.b,s=Math.max(t,e,r),i=Math.min(t,e,r),o=0;return s!==i&&(s===t?o=(60*((e-r)/(s-i))+360)%360:s===e?o=(60*((r-t)/(s-i))+120)%360:o=(60*((t-e)/(s-i))+240)%360),o.clamp(0,360)}function Kt(n){return n.toString(16).padStart(2,"0")}var Be=class n{static{this.WCAG_MINIMUM_CONTRAST=3}static{this.WCAG_NORMAL_TEXT_CONTRAST=4.5}static{this.WCAG_SAFE_CONTRAST=7}static _clampRGB(t){let e=r=>Math.min(1,Math.max(0,r));return t[3]==null&&(t[3]=1),{r:e(t[0]),g:e(t[1]),b:e(t[2]),a:Math.min(1,Math.max(0,t[3]))}}static _normalize(t){return[t[0]/255,t[1]/255,t[2]/255,t[3]]}static parse(t){if(t=(t||"").toLowerCase(),Ee.test(t)){let e=Ee.exec(t);return this._clampRGB(this._normalize([parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),1]))}if(Ie.test(t)){let e=Ie.exec(t);return this._clampRGB(this._normalize([parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),parseFloat(e[4])]))}if(Ne.test(t)){let e=Ne.exec(t)[0];return this._clampRGB(this._normalize([parseInt("0x"+e.substr(1,2)),parseInt("0x"+e.substr(3,2)),parseInt("0x"+e.substr(5,2)),1]))}if($e.test(t)){let e=$e.exec(t)[0],r=e.substr(1,1),s=e.substr(2,1),i=e.substr(3,1);return this._clampRGB(this._normalize([parseInt("0x"+r+r),parseInt("0x"+s+s),parseInt("0x"+i+i),1]))}if(Re.test(t)){let e=Re.exec(t),r={h:parseFloat(e[1]),s:parseFloat(e[2])*.01,l:parseFloat(e[3])*.01};return this.rgb(r)}if(Ae.test(t)){let e=Ae.exec(t),r={h:parseFloat(e[1]),s:parseFloat(e[2])*.01,l:parseFloat(e[3])*.01,a:parseFloat(e[4])};return this.rgb(r)}}static hsl(t){let e=Zn(t),r=Gn(t,e);return{h:Un(t),s:r,l:e,a:t.a}}static cieXYZ(t){return q(t)&&(t=this.rgb(t)),H.rgbToCieXYZ(t)}static rgb(t){if(q(t)){let e=t.h,r=t.s,s=t.l,i=e/60,o=(1-Math.abs(2*s-1))*r,a=o*(1-Math.abs(i%2-1)),c=s-o/2,l=(f,d,m)=>this._clampRGB([f+c,d+c,m+c,t.a]);if(i<=1)return l(o,a,0);if(i<=2)return l(a,o,0);if(i<=3)return l(0,o,a);if(i<=4)return l(0,a,o);if(i<=5)return l(a,0,o);if(i<=6)return l(o,0,a)}else{let e=H.cieXYZToRgb(t);return this._clampRGB([e.r,e.g,e.b,e.a])}}static stringify(t,e=1){if(q(t)){e??=1,t.a??=1;let r=typeof e=="number"?e:1;return`hsla(${t.h.roundoff(r)},${(t.s*100).roundoff(r)}%,${(t.l*100).roundoff(r)}%,${t.a.roundoff()})`}else if(Nt(t)){e??=!0,t.a??=1;let r=typeof e=="boolean"?e:!!e,s=Math.round(t.r*255),i=Math.round(t.g*255),o=Math.round(t.b*255),a=t.a.roundoff();return a===1?r?("#"+Kt(s)+Kt(i)+Kt(o)).toUpperCase():`rgb(${s},${i},${o})`:`rgba(${s},${i},${o},${a})`}}static contrastRatio(t,e){return q(t)&&(t=this.rgb(t)),q(e)&&(e=this.rgb(e)),H.contrastRatio(t,e)}static luminance(t){return q(t)&&(t=n.rgb(t)),H.relativeLuminance(t)}static lighten(t,e=.1){if(e||=0,q(t)){let r=Math.min(1,Math.max(0,t.l+e));return Object.assign({},t,{l:r})}if(Nt(t)){let r=this.lighten(this.hsl(t),e);return this.rgb(r)}return t}static darken(t,e=.1){return this.lighten(t,-e)}static saturate(t,e=.1){if(e||=0,q(t)){let r=Math.min(1,Math.max(0,t.s+e));return Object.assign({},t,{s:r})}if(Nt(t)){let r=this.saturate(this.hsl(t),e);return this.rgb(r)}return t}static desaturate(t,e=.1){return this.saturate(t,-e)}static interpolate(t,e,r,s){r??=.5,s??=r;let i=(r+s).roundoff(),o=(r/i).roundoff(),a=(s/i).roundoff(),c=Nt(t),l=q(t),f=m=>Nt(m)||q(m)?n.cieXYZ(m):m;t=f(t),e=f(e);let d={x:(t.x*o+e.x*a).roundoff(),y:(t.y*o+e.y*a).roundoff(),z:(t.z*o+e.z*a).roundoff(),a:(t.a*o+e.a*a).roundoff()};return c?n.rgb(d):l?n.hsl(n.rgb(d)):d}};var Vn=/[-+]?([\d]+(\.[\d]+(e-[\d]+)?)?|[\d]*(\.[\d]+(e-[\d]+)?))/g;function ft(n){let t=[],e=n.match(Vn);return e&&e.length>0&&e.forEach(r=>t.push(parseFloat(r))),t}var Rt=class n{static isAngle(t){return typeof t=="object"&&"vertex"in t&&S.isPoint(t.vertex)&&"start"in t&&S.isPoint(t.start)&&"end"in t&&S.isPoint(t.end)}static value(t){if(z.isNullOrEmpty(t)||!n.isAngle(t))return Number.NaN;let{vertex:e,start:r,end:s}=t;return n.angleBetween(e,r,s)}static angleBetween(t,e,r){let s={x:e.x-t.x,y:e.y-t.y},i={x:r.x-t.x,y:r.y-t.y},o=s.x*i.x+s.y*i.y,a=s.x*i.y-s.y*i.x;return-Math.atan2(a,o)}},_t=class{static parse(t){let e=ft(t);if(e&&e.length===2)return{width:e[0],height:e[1]};throw new Error(`Cannot parse "${t}" as a valid Size.`)}static isSize(t){return typeof t=="object"&&"width"in t&&typeof t.width=="number"&&"height"in t&&typeof t.height=="number"}},S=class{static parse(t){let e=ft(t);if(e&&e.length===2)return{x:e[0],y:e[1]};throw new Error(`Cannot parse "${t}" as a valid Point.`)}static isPoint(t){return typeof t=="object"&&"x"in t&&typeof t.x=="number"&&"y"in t&&typeof t.y=="number"}static distance(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}static subtract(t,e){return{x:e.x-t.x,y:e.y-t.y}}static add(...t){var e={x:0,y:0};for(var r of t)e.x+=r.x,e.y+=r.y;return e}static multiply(t,e){return{x:t.x*e,y:t.y*e}}};var rt=class n{static isIdentity(t){return t.a===1&&t.d===1&&t.b===0&&t.f===0&&t.c===0&&t.e===0}static get identity(){return{a:1,b:0,c:0,d:1,e:0,f:0}}static copy(t){return{a:t.a,b:t.b,c:t.c,d:t.d,e:t.e,f:t.f}}static scale(t,e,r=e){return{a:t.a*e,b:t.b,c:t.c,d:t.d*r,e:t.e,f:t.f}}static translate(t,e){return{a:t.a,b:t.b,c:t.c,d:t.d,e:t.e+e.x,f:t.f+e.y}}static rotate(t,e){let r=Math.cos(e),s=Math.sin(e);return n.multiply(t,{a:r,b:s,c:-s,d:r,e:0,f:0})}static multiply(t,e){return"x"in t&&"y"in t?typeof e=="number"?{x:t.x*e,y:t.y*e}:{x:t.x*e.a+t.y*e.c+e.e,y:t.x*e.b+t.y*e.d+e.f}:typeof e=="number"?{a:t.a*e,b:t.b*e,c:t.c*e,d:t.d*e,e:t.e*e,f:t.f*e}:{a:t.a*e.a+t.b*e.c,b:t.a*e.b+t.b*e.d,c:t.c*e.a+t.d*e.c,d:t.c*e.b+t.d*e.d,e:t.e*e.a+t.f*e.c+e.e,f:t.e*e.b+t.f*e.d+e.f}}static det(t){return t.a*t.d-t.c*t.b}static invert(t){let e=this.det(t);if(e===0)return null;let r=1/e;return this.multiply({a:t.d,b:-t.b,c:-t.c,d:t.a,e:-t.e*t.d+t.c*t.f,f:t.e*t.b-t.a*t.f},r)}static toComponents(t,e={x:0,y:0}){let r=Math.sqrt(t.a*t.a+t.c*t.c),s=Math.sqrt(t.b*t.b+t.d*t.d),i=r!=0?t.a/r:0,o=r!=0?t.c/r:0,a=Math.atan2(o,i),{x:c,y:l}=e,f={x:t.e-c*(r*i-1)+l*r*o,y:t.f-l*(s*i-1)-c*s*o};return{scaleX:r,scaleY:s,rotation:a,translation:f}}static fromTransform([t,e,r],[s,i,o]){let a=t.x*(e.y-r.y)-t.y*(e.x-r.x)+(e.x*r.y-r.x*e.y);if(Math.abs(a)<1e-10)throw new Error("Points are collinear; matrix is singular and cannot be solved.");let c=1/a;return{a:c*(s.x*(e.y-r.y)+i.x*(r.y-t.y)+o.x*(t.y-e.y)),b:c*(s.y*(e.y-r.y)+i.y*(r.y-t.y)+o.y*(t.y-e.y)),c:c*(s.x*(r.x-e.x)+i.x*(t.x-r.x)+o.x*(e.x-t.x)),d:c*(s.y*(r.x-e.x)+i.y*(t.x-r.x)+o.y*(e.x-t.x)),e:c*(s.x*(e.x*r.y-r.x*e.y)+i.x*(r.x*t.y-t.x*r.y)+o.x*(t.x*e.y-e.x*t.y)),f:c*(s.y*(e.x*r.y-r.x*e.y)+i.y*(r.x*t.y-t.x*r.y)+o.y*(t.x*e.y-e.x*t.y))}}static areClose(t,e,r=12){return t.a.isCloseTo(e.a,r)&&t.b.isCloseTo(e.b,r)&&t.c.isCloseTo(e.c,r)&&t.d.isCloseTo(e.d,r)&&t.e.isCloseTo(e.e,r)&&t.f.isCloseTo(e.f,r)}};var xt=class n{static parse(t){let e=ft(t);if(e&&e.length===4)return{x:e[0],y:e[1],width:e[2],height:e[3]};throw new Error(`Cannot parse "${t}" as a valid Rect.`)}static isRect(t){return S.isPoint(t)&&_t.isSize(t)}static _stretch(t,e){return{a:e.width/t.width,b:0,c:0,d:e.height/t.height,e:e.x-t.x,f:e.y-t.y}}static _contain(t,e,r,s){let i=1,o=t.width/t.height,a=e.width/e.height;o>=a?i=e.width/t.width:i=e.height/t.height;let c=t.width*i,l=t.height*i,f=this._align({x:t.x,y:t.y,width:c,height:l},e,r,s);return rt.translate({a:i,b:0,c:0,d:i,e:0,f:0},f)}static _cover(t,e,r,s){let i=1,o=t.width/t.height,a=e.width/e.height;o<a?i=e.width/t.width:i=e.height/t.height;let c=t.width*i,l=t.height*i,f=this._align({x:t.x,y:t.y,width:c,height:l},e,r,s);return rt.translate({a:i,b:0,c:0,d:i,e:0,f:0},f)}static _align(t,e,r,s){let i=0,o=0;switch(r){case"left":i=e.x-t.x;break;case"right":i=e.x+e.width-t.width-t.x;break;default:i=e.x+e.width*.5-t.width*.5-t.x;break}switch(s){case"top":o=e.y-t.y;break;case"bottom":o=e.y+e.height-t.height-t.y;break;default:o=e.y+e.height*.5-t.height*.5-t.y;break}return{x:i,y:o}}static findTransform(t,e,r="stretch",s="center",i="middle"){switch(r){case"contain":return this._contain(t,e,s,i);case"cover":return this._cover(t,e,s,i);default:return this._stretch(t,e)}}static intersect(...t){let e={x:0,y:0,height:0,width:0},r=Array.from(t||[]);if(r.length<=0)return e;for(var s=r[0],i=1;i<r.length;i++){let o=r[i],a=Math.max(o.x,s.x),c=Math.max(o.y,s.y),l=Math.min(o.x+o.width,s.x+s.width),f=Math.min(o.y+o.height,s.y+s.height),d=l-a,m=f-c;if(d<0||m<=0)return e;s={x:a,y:c,width:d,height:m}}return s}static expand(t,...e){let r=Array.from(e||[]),s=t.x,i=t.y,o=s,a=i;n.isRect(t)&&(o+=t.width,a+=t.height);for(let c of r)s=Math.min(c.x,s),i=Math.min(c.y,i),o=Math.max(c.x,o),a=Math.max(c.y,a);return{x:s,y:i,width:o-s,height:a-i}}};var ze=class n{static#t;static uniqueId(){let t=n.#t||Date.now();return n.#t=++t}static uniqueCode(){return n.uniqueId().toBase62()}static randomString(t){let e="";do e+=(Math.random()*62).toBase62();while(e.length<t);return e}};var $t=class{static round(t,e=1){return Math.round(t/e)*e}static log(t,e){return Math.log10(t)/Math.log10(e)}static rebase(t,e,r){let s=t.toString(),i=parseInt(s,e);return s.endsWith(i.toString(e))?parseInt(t.toString(),e).toString(r):Number.NaN.toString()}};var Wn=Object.defineProperty,St=(n,t)=>{for(var e in t)Wn(n,e,{get:t[e],enumerable:!0})},Kn={};St(Kn,{LinearAlgebra:()=>_e,Polygon:()=>ur,Utils:()=>wt,Utils3D:()=>dr});var ht=class ne{static unit(t){let e={x:t.x,y:t.y};return this.normalize(e),e}static magSqr(t){return t.x*t.x+t.y*t.y}static mag(t){return Math.sqrt(ne.magSqr(t))}static normalize(t){let e=ne.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";let r=1/e;t.x*=r,t.y*=r}static from(t,e){return S.subtract(t,e)}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)}},Yt=class{constructor(n,t,e=-1){this.x=n,this.y=t,this.index=e}equals(n){return this.x===n.x&&this.y===n.y}};function tr(n,t,e){let r=n.x,s=n.y,i=t.x,o=t.y,a=e.x,c=e.y,l=2*(r*(o-c)+i*(c-s)+a*(s-o));if(Math.abs(l)<1e-12)return{c:{x:0,y:0},r:1/0};let f=((r*r+s*s)*(o-c)+(i*i+o*o)*(c-s)+(a*a+c*c)*(s-o))/l,d=((r*r+s*s)*(a-i)+(i*i+o*o)*(r-a)+(a*a+c*c)*(i-r))/l,m=Math.hypot(f-r,d-s);return{c:{x:f,y:d},r:m}}var De=class{constructor(n,t,e){this.v0=n,this.v1=t,this.v2=e,this.circumCirc=tr(n,t,e)}inCircumcircle(n){let t=this.circumCirc.c.x-n.x,e=this.circumCirc.c.y-n.y;return Math.hypot(t,e)<=this.circumCirc.r+1e-9}};function er(n){let t=1/0,e=1/0,r=-1/0,s=-1/0;for(let f of n)t=Math.min(t,f.x),e=Math.min(e,f.y),r=Math.max(r,f.x),s=Math.max(s,f.y);let i=(r-t)*10,o=(s-e)*10,a=new Yt(t-i,e-o*3),c=new Yt(t-i,s+o),l=new Yt(r+i*3,s+o);return new De(a,c,l)}function nr(n){let t=[];for(let e=0;e<n.length;++e){let r=!0;for(let s=0;s<n.length;++s)if(e!==s){let i=n[e],o=n[s];if(i.v0.equals(o.v0)&&i.v1.equals(o.v1)||i.v0.equals(o.v1)&&i.v1.equals(o.v0)){r=!1;break}}r&&t.push(n[e])}return t}function rr(n,t){let e=[];t=t.filter(s=>s.inCircumcircle(n)?(e.push({v0:s.v0,v1:s.v1}),e.push({v0:s.v1,v1:s.v2}),e.push({v0:s.v2,v1:s.v0}),!1):!0);let r=nr(e);for(let s of r)t.push(new De(s.v0,s.v1,n));return t}function sr(n){if(n.length<3)return[];let t=er(n),e=[t];for(let r of n)e=rr(r,e);return e=e.filter(r=>!(r.v0===t.v0||r.v0===t.v1||r.v0===t.v2||r.v1===t.v0||r.v1===t.v1||r.v1===t.v2||r.v2===t.v0||r.v2===t.v1||r.v2===t.v2)),e}function ir(n){if(n.length<3)return[];let t=n.map((s,i)=>new Yt(s.x,s.y,i)),e=sr(t),r=[];for(let s of e)r.push(s.v0.index,s.v1.index,s.v2.index);return r}var or=class{static triangulate(n){return ir(n)}},ar=180/Math.PI,Pe=2*Math.PI,bt=12;function Ft(n){return S.isPoint(n)}function cr(n){return n!=null&&Array.isArray(n)&&n.length===2&&Ft(n[0])&&Ft(n[1])}var wt=class w{static slopeRad(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static slopeRad2(t,e){return(Pe+w.slopeRad(t,e))%Pe}static slopeDeg(t,e){return w.slopeRad(t,e)*ar}static slopeDeg2(t,e){return(360+w.slopeDeg(t,e))%360}static intersect(t,e,...r){return Array.isArray(t)&&Array.isArray(e)?w._intersectSegments(t,e,!0):xt.isRect(t)?w._intersectRects(...arguments):"vertices"in t?w._mergePolygons(t,e,"intersect")?.polygons??null:null}static boundingBox(t){let e=Number.MAX_VALUE,r=Number.MAX_VALUE,s=-Number.MAX_VALUE,i=-Number.MAX_VALUE,o=t.length;for(let a of t)e=Math.min(e,a.x),r=Math.min(r,a.y),s=Math.max(s,a.x),i=Math.max(i,a.y);return{x:e,y:r,width:s-e,height:i-r}}static combinePolygons(t,e,r){return w._mergePolygons(t,e,r)}static _mergePolygons(t,e,r){if(z.isNullOrEmpty(t?.vertices)||z.isNullOrEmpty(e?.vertices))return null;let s=t.vertices.filter(k=>w.inPolygon(k,e.vertices));if(t.vertices.length==s.length)return{polygons:r==="intersect"?[t]:[e]};let i=e.vertices.filter(k=>w.inPolygon(k,t.vertices));if(e.vertices.length===i.length)return{polygons:r==="intersect"?[e]:[t]};let o=w.boundingBox(t.vertices),a=w.boundingBox(e.vertices),c=w.intersect(o,a);if(r!=="union"&&(!xt.isRect(c)||!(c.width>0)||!(c.height>0)))return null;let{vertices:l}=t,{vertices:f}=e;if(l.length<3||f.length<3)return null;let d=(k,E,A)=>[k,A[(E+1)%A.length]],m=(k,E)=>k.x===E.x?k.y-E.y:k.x-E.x,x=l.map(d),b=f.map(d),g=l.concat(f),h=new Map,u=k=>{if(!h.has(k)){let E=[];h.set(k,E)}return h.get(k)},y=!1;for(let k of x){let E=u(k);for(let A of b){let $=u(A),G=w.intersect(k,A);z.isNull(G)||(y=!0,g.push(G),E.push(G),$.push(G))}}if(s.length===0&&i.length===0&&!y)return r==="union"?{polygons:[t,e]}:null;let p=[];for(let k of x.concat(b)){let E=u(k);if(z.isNullOrEmpty(E))p.push(k);else{let A=k.concat(E).sort(m);for(let $=0;$<A.length-1;$++)p.push([A[$],A[$+1]])}}var C=!1,M;do{g.sort(m),g.filter((A,$,G)=>$===0||!w.areClose(A,G[$-1])),M=w.mesh(g);let{vertices:k,triangleIndices:E}=M;C=!1;for(let A=0;A<E.length;A+=3){let $=E[A],G=E[A+1],yt=E[A+2],lt=k[$],mt=k[G],nt=k[yt],ut=[[lt,mt],[mt,nt],[nt,lt]];for(let pt of p)for(let P of ut){let Ut=w.areClose(P[0],pt[0])||w.areClose(P[1],pt[1])||w.areClose(P[0],pt[1])||w.areClose(P[1],pt[0])?null:w.intersect(P,pt);!z.isNull(Ut)&&g.findIndex(an=>w.areClose(an,Ut,4))===-1&&(C=!0,g.push(Ut))}}}while(C);let{vertices:R,triangleIndices:T}=M,et=[];for(let k=0;k<T.length;k+=3){let E=k,A=k+1,$=k+2,G=R[T[E]],yt=R[T[A]],lt=R[T[$]],mt={x:(G.x+yt.x+lt.x)/3,y:(G.y+yt.y+lt.y)/3},nt=w.inPolygon(mt,l),ut=w.inPolygon(mt,f);(nt&&ut&&r==="intersect"||(nt||ut)&&r==="union"||(nt&&!ut||!nt&&ut)&&r==="difference")&&et.push([G,yt,lt])}let at=et.flatMap(([k,E,A])=>[[k,E],[E,A],[A,k]]),j=[];for(let k=0;k<at.length;k++){let E=at[k];if(k==0){j.push(E);continue}let A=j.findIndex($=>w.areClose($[0],E[0])&&w.areClose($[1],E[1])||w.areClose($[0],E[1])&&w.areClose($[1],E[0]));A===-1?j.push(E):j.splice(A,1)}if(j.length<3)return null;let ct=[],kt=k=>{let{length:E}=k,A=w.areClose(k[0],k[E-1]),$=k.slice(0,A?E-1:E);return $.length>3&&w.inSegment($[0],[$[1],$[$.length-1]])&&$.shift(),$},[Et,Tt]=j.shift(),Y=[Et,Tt];for(;j.length>1;){let k=Y[Y.length-1],E=j.findIndex(A=>w.areClose(A[0],k)||w.areClose(A[1],k));if(E===-1){ct.push({vertices:kt(Y.splice(0))});let[A,$]=j.shift();Y.push(A,$)}else{let[A]=j.splice(E,1),$=w.areClose(A[0],k)?A[1]:w.areClose(A[1],k)?A[0]:null;Y.length>1&&w.inSegment(Y[Y.length-1],[Y[Y.length-2],$])?Y.splice(Y.length-1,1,$):Y.push($)}}return ct.push({vertices:kt(Y)}),{polygons:ct,mesh:M,triangles:et.map(k=>({vertices:k}))}}static mesh(t,...e){let r=[].concat(t).concat(e),s=or.triangulate(r);return{vertices:r,triangleIndices:s}}static intersectLines(t,e,r,s){let i,o;if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&typeof t[0]=="number"&&typeof e[0]=="number"&&typeof t[1]=="number"&&typeof e[1]=="number"&&(r=e[0],s=e[1],e=t[1],t=t[0]),typeof t=="number"&&typeof e=="number"){let a=t,c=e;i=[{x:0,y:c},{x:1,y:a+c}],o=[{x:0,y:s},{x:1,y:r+s}]}else i=t,o=e;return w._intersectSegments(i,o,!1)}static cramer(t,e){Array.isArray(t)&&(t={a:t[0],b:t[1],c:t[2]}),Array.isArray(e)&&(e={a:e[0],b:e[1],c:e[2]});let r=(t.b*e.c-t.c*e.b)/(t.b*e.a-t.a*e.b),s=(t.c*e.a-t.a*e.c)/(t.b*e.a-t.a*e.b);return{x:-r.roundoff(),y:-s.roundoff()}}static mq(t,e){let r;if(Ft(t)?r=t:(r=t[0],e=t[1]),r.x===e.x)return[Number.NaN,Number.NaN];let s=(e.y-r.y)/(e.x-r.x),i=r.y-s*r.x;return[s,i]}static _intersectSegments(t,e,r){let s=t[0],i=t[1],o=e[0],a=e[1],c=Math.min(s.x,i.x),l=Math.min(s.y,i.y),f=Math.max(s.x,i.x),d=f-c,m=Math.max(s.y,i.y),x=m-l,b=Math.min(o.x,a.x),g=Math.min(o.y,a.y),h=Math.max(o.x,a.x),u=h-b,y=Math.max(o.y,a.y),p=y-g;if(d===0&&u===0||x===0&&p===0)return null;let C=T=>T.x<b||T.x>h||T.x<c||T.x>f,M=T=>T.y<g||T.y>y||T.y<l||T.y>m;var R=null;if(d===0){if(r&&(b>c||h<f))return null;let T=w.mq(o,a);R=w.cramer([1,0,-c],[T[0],-1,T[1]]),r&&M(R)&&(R=null)}else if(u===0){if(r&&(c>b||f<h))return null;let T=w.mq(s,i);R=w.cramer([T[0],-1,T[1]],[1,0,-b]),r&&M(R)&&(R=null)}else if(x===0){if(r&&(g>l||y<m))return null;let T=w.mq(o,a);R=w.cramer([0,1,-l],[T[0],-1,T[1]]),r&&C(R)&&(R=null)}else if(p===0){if(r&&(l>g||m<y))return null;let T=w.mq(s,i);R=w.cramer([T[0],-1,T[1]],[0,1,-g]),r&&C(R)&&(R=null)}else{let T;if(!r||(T=w._intersectRects({x:c,y:l,width:d,height:x},{x:b,y:g,width:u,height:p}))&&T.width>0&&T.height>0){let et=w.mq(s,i),at=w.mq(o,a),j=et[0],ct=at[0],kt=et[1],Et=at[1];if(j!==ct){R=w.cramer([j,-1,kt],[ct,-1,Et]);let Tt=R.x,Y=R.y;r&&(Tt<T.x||Tt>T.x+T.width||Y<T.y||Y>T.y+T.height)&&(R=null)}}}return R===null?null:{x:R.x,y:R.y}}static _intersectRects(...t){return xt.intersect(...t)}static _areClose(t,e,r=bt){return Math.abs(t.x-e.x).isCloseTo(0,r)&&Math.abs(t.y-e.y).isCloseTo(0,r)}static areClose(t,e,r=bt){return w._areClose(t,e,r)}static dot(t,e){return ht.dot(t,e)}static cross(t,e){return ht.cross(t,e)}static distance(t,e){if(cr(t))return S.distance(t[0],t[1]);if(Ft(e))return S.distance(t,e);{let r=e[0],s=e[1];return Math.abs(r*t.x-t.y+s)/Math.sqrt(Math.pow(r,2)+1)}}static _pointSegmentDistance(t,e){let r=ht.from(e[0],e[1]),s=ht.from(e[0],t);return w.cross(r,s)}static isWithin(t,e,r,s=bt){let i=w._pointSegmentDistance(t,e);return i.isCloseTo(0,s)?!1:r?i<0:i>0}static isBeyond(t,e,r,s=bt){return w.isWithin(t,e,!r,s)}static inLine(t,e,r=bt){return w._pointSegmentDistance(t,e).isCloseTo(0,r)}static inSegment(t,e,r=bt){let s=Math.min(e[0].x,e[1].x),i=Math.max(e[0].x,e[1].x),o=Math.min(e[0].y,e[1].y),a=Math.max(e[0].y,e[1].y);return t.x>=s&&t.x<=i&&t.y>=o&&t.y<=a&&w.inLine(t,e,r)}static inTriangle(t,e){let r;for(let s=0;s<3;s++){let i=e[s],o=e[(s+1)%3],a=S.subtract(o,t),c=S.subtract(i,t),l=w.cross(a,c);if(s>0&&l*r<=0)return!1;r=l}return!0}static inPolygon(t,e,r=bt){if(!(e?.length>=3))throw"Not enough vertices";let s=e.length;if(s===3)return w.inTriangle(t,[e[0],e[1],e[2]]);r>0&&(e=e.map(m=>({x:m.x.roundoff(r),y:m.y.roundoff(r)})),t={x:t.x.roundoff(r),y:t.y.roundoff(r)});let i=Number.MAX_VALUE,o=Number.MAX_VALUE,a=Number.MIN_VALUE,c=Number.MIN_VALUE;for(let m=0;m<s;m++){let x=e[m];i=Math.min(i,x.x),o=Math.min(o,x.y),a=Math.max(a,x.x),c=Math.max(c,x.y)}if(t.x<i||t.x>a||t.y<o||t.y>c)return!1;let l={x:i-1,y:t.y},f=[l,t],d=0;for(let m=0;m<s;m++){let x=e[m],b=e[(m+1)%s],g=[x,b];if(x.y===t.y){let h=e[(m-1+s)%s];t.x>x.x&&(h.y-t.y)*(b.y-t.y)<0&&d++}else{if(b.y===t.y)continue;w.intersect(g,f)!=null&&d++}}return d%2===1}static area(t,...e){let r=[].concat(t).concat(e),s=0,i=r.length;if(i>=3){for(let o=0;o<r.length;o++){let{x:a,y:c}=r[o],l=o===i-1?0:o+1,{x:f,y:d}=r[l];s+=a*d-c*f}s*=.5}return Math.abs(s.roundoff())}static convexHull(t,...e){let r=[].concat(t).concat(e);if(!(r?.length>1))return r?.slice()??[];let s=r.map(l=>({x:l.x,y:l.y})).sort((l,f)=>l.x===f.x?l.y-f.y:l.x-f.x),i=[];for(let l of s){let f=i[i.length-1];(!f||f.x!==l.x||f.y!==l.y)&&i.push(l)}if(i.length<=2)return i;let o=(l,f,d)=>(f.x-l.x)*(d.y-l.y)-(f.y-l.y)*(d.x-l.x),a=[];for(let l of i){for(;a.length>=2&&o(a[a.length-2],a[a.length-1],l)<=0;)a.pop();a.push(l)}let c=[];for(let l=i.length-1;l>=0;l--){let f=i[l];for(;c.length>=2&&o(c[c.length-2],c[c.length-1],f)<=0;)c.pop();c.push(f)}return a.pop(),c.pop(),a.concat(c)}};function lr(n){let t;return"vertices"in n&&Array.isArray(n.vertices)&&(t=n.vertices).length>=3&&t.every(e=>S.isPoint(e))}var ur=class re{static{this._eps=1e-12}static isPolygon(t){return lr(t)}static from(...t){return{vertices:Array.from(t)}}static contains(t,e){return wt.inPolygon(e,t.vertices,12)}static centroid(t){let e=re.boundingBox(t);return{x:e.x+e.width/2,y:e.y+e.height/2}}static boundingBox(t){return wt.boundingBox(t.vertices)}static sides(t){let{vertices:e}=t,r=[];for(let s=1;s<=e.length;s++){let i=e[s%e.length],o=e[s-1];r.push([o,i])}return r}static isConvex(t){let{vertices:e}=t,r=e.length;if(r<=3)return!0;let s=0;for(let i=0;i<e.length;i++){let o=e[(i-1+r)%r],a=e[i],c=e[(i+1)%r],l=Rt.angleBetween(a,o,c);if(s===0){s=Math.sign(l);continue}if(s!=Math.sign(l))return!1}return!0}static isSelfIntersecting(t){let{vertices:e}=t;if(e.length<=3)return!1;let r=re.sides(t);for(let s of r)for(let i of r){if(i===s||i[0]===s[1]||s[0]===i[1])continue;let o=wt.intersect(i,s);if(!z.isNull(o))return!0}return!1}static isCounterClockwise(t){let{vertices:[e,r,s]}=t;return Rt.angleBetween(r,e,s)>0}static expand(t,e){let{vertices:r}=t,s=r.length,i=[];for(let o=0;o<r.length;o++){let a=r[(o-1+s)%s],c=r[o],l=r[(o+1)%s],f=Rt.angleBetween(c,a,l),d=-e/Math.sin(Math.abs(f)/2),m=rt.scale(rt.identity,d),x=S.subtract(c,a);ht.normalize(x);let b=S.subtract(c,l);ht.normalize(b);let g=S.add(x,b);ht.normalize(g);let h=rt.multiply(g,m);i.push(S.add(c,{x:h.x.roundoff(),y:h.y.roundoff()}))}return{vertices:i}}static area(t){return wt.area(t.vertices)}static intersect(t,e){return wt.intersect(t,e)}static convexHull(t){return{vertices:wt.convexHull(t.vertices)}}},jt=180/Math.PI,zt=1/jt,B=class st{static from(...t){if(t.length!==3)throw new RangeError("Must provide exactly 3 numbers");return{x:t[0],y:t[1],z:t[2]}}static parse(t){let e=ft(t);if(e&&e.length===3)return st.from.apply(null,e);throw new Error(`Cannot parse "${t}" as a valid Vector3D.`)}static i(){return{x:1,y:0,z:0}}static j(){return{x:0,y:1,z:0}}static k(){return{x:0,y:0,z:1}}static zero(){return{x:0,y:0,z:0}}static subtract(t,e){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static add(...t){var e={x:0,y:0,z:0};for(var r of t)e.x+=r.x,e.y+=r.y,e.z+=r.z;return e}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static scale(t,e,r=e,s=e){return{x:t.x*e,y:t.y*r,z:t.z*s}}static magSqr(t){return t.x*t.x+t.y*t.y+t.z*t.z}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)&&(e.z-t.z).isCloseTo(0)}static mag(t){return Math.sqrt(st.magSqr(t))}static negate(t){return{x:-t.x,y:-t.y,z:-t.z}}static unit(t){let e={x:t.x,y:t.y,z:t.z};return this.normalize(e),e}static normalize(t){let e=st.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";let r=1/e;t.x*=r,t.y*=r,t.z*=r}static angleBetween(t,e){let r,s=st.unit(t),i=st.unit(e);if(st.dot(s,i)<0){let a={x:-s.x-i.x,y:-s.y-i.y,z:-s.z-i.z},c=st.mag(a);r=Math.PI-2*Math.asin(c/2)}else{let a={x:s.x-i.x,y:s.y-i.y,z:s.z-i.z},c=st.mag(a);r=2*Math.asin(c/2)}return jt*r}},fr=class se{static from(t,e,r){return{rho:t.clamp(0,1/0),theta:e.clamp(-180,180),phi:r.clamp(0,360)}}static fromVector(t,e,r){typeof t=="number"&&(t=B.from(t,e,r));let s=B.mag(t);if(s.isCloseTo(0))return se.from(0,0,0);let i=Math.atan2(t.x,t.z),o=Math.acos((t.y/s).clamp(-1,1));return se.from(s,i*jt,o*jt)}static toVector(t){let{rho:e,theta:r,phi:s}=t,i=s*zt,o=r*zt,a=Math.sin(i)*e;return{x:a*Math.sin(o),y:Math.cos(i)*e,z:a*Math.cos(o)}}static toRotationMatrix(t){let{theta:e,phi:r}=t,s=zt*e,i=Math.sin(s),o=Math.cos(s),a=zt*r,c=Math.sin(a),l=Math.cos(a);return At.from(i*l,i*c,o,0,o*l,o*c,-i,0,-c,l,0,0,0,0,0,1)}},Bt=class He{static modify(t,e){let{m11:r,m12:s,m13:i,m14:o,m21:a,m22:c,m23:l,m24:f,m31:d,m32:m,m33:x,m34:b,offsetX:g,offsetY:h,offsetZ:u,m44:y}=t,p={m11:r,m12:s,m13:i,m14:o,m21:a,m22:c,m23:l,m24:f,m31:d,m32:m,m33:x,m34:b,offsetX:g,offsetY:h,offsetZ:u,m44:y};return e(p),p}static clone(t){return He.modify(t,e=>{})}static multiply(t,e){return At.isIdentity(t)?e:At.isIdentity(e)?t:At.from(t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.offsetX,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.offsetY,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.offsetZ,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.offsetX,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.offsetY,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.offsetZ,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.offsetX,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.offsetY,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.offsetZ,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.offsetX*e.m11+t.offsetY*e.m21+t.offsetZ*e.m31+t.m44*e.offsetX,t.offsetX*e.m12+t.offsetY*e.m22+t.offsetZ*e.m32+t.m44*e.offsetY,t.offsetX*e.m13+t.offsetY*e.m23+t.offsetZ*e.m33+t.m44*e.offsetZ,t.offsetX*e.m14+t.offsetY*e.m24+t.offsetZ*e.m34+t.m44*e.m44)}},At=class U{static identity(){return{m11:1,m12:0,m13:0,m14:0,m21:0,m22:1,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,offsetX:0,offsetY:0,offsetZ:0,m44:1}}static from(...t){if(t.length!==16)throw new RangeError("Must provide exactly 16 numbers");return{m11:t[0],m12:t[1],m13:t[2],m14:t[3],m21:t[4],m22:t[5],m23:t[6],m24:t[7],m31:t[8],m32:t[9],m33:t[10],m34:t[11],offsetX:t[12],offsetY:t[13],offsetZ:t[14],m44:t[15]}}static transpose(t){return U.from(t.m11,t.m21,t.m31,t.offsetX,t.m12,t.m22,t.m32,t.offsetY,t.m13,t.m23,t.m33,t.offsetZ,t.m14,t.m24,t.m34,t.m44)}static toArray(t){return[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.offsetX,t.offsetY,t.offsetZ,t.m44]}static clone(t,e){return typeof e=="function"?Bt.modify(t,e):Bt.clone(t)}static scale(t,e,r,s){return typeof e=="number"?(r??=e,s??=e):(s=e.z,r=e.y,e=e.x),Bt.modify(t,i=>{i.m11*=e,i.m22*=r,i.m33*=s})}static translate(t,e){return Bt.modify(t,r=>{r.offsetX+=e.x,r.offsetY+=e.y,r.offsetZ+=e.z})}static parse(t){let e=ft(t);if(e&&e.length===16)return U.from.apply(null,e);throw new Error(`Cannot parse "${t}" as a valid Matrix3D.`)}static isIdentity(t){return t.m11==1&&t.m12==0&&t.m13==0&&t.m14==0&&t.m21==0&&t.m22==1&&t.m23==0&&t.m24==0&&t.m31==0&&t.m32==0&&t.m33==1&&t.m34==0&&t.offsetX==0&&t.offsetY==0&&t.offsetZ==0&&t.m44==1}static isAffine(t){return t.m14==0&&t.m24==0&&t.m34==0&&t.m44==1}static determinant(t){if(U.isIdentity(t))return 1;if(U.isAffine(t))return t.m11*(t.m22*t.m33-t.m32*t.m23)-t.m12*(t.m21*t.m33-t.m31*t.m23)+t.m13*(t.m21*t.m32-t.m31*t.m22);{let e=t.m13*t.m24-t.m23*t.m14,r=t.m13*t.m34-t.m33*t.m14,s=t.m13*t.m44-t.offsetZ*t.m14,i=t.m23*t.m34-t.m33*t.m24,o=t.m23*t.m44-t.offsetZ*t.m24,a=t.m33*t.m44-t.offsetZ*t.m34,c=t.m22*r-t.m32*e-t.m12*i,l=t.m12*o-t.m22*s+t.offsetY*e,f=t.m32*s-t.offsetY*r-t.m12*a,d=t.m22*a-t.m32*o+t.offsetY*i;return t.offsetX*c+t.m31*l+t.m21*f+t.m11*d}}static multiply(...t){if(t.length===0)throw new ReferenceError("Matrix not provided.");let e=Array.from(t),r=e[0];for(let s=1;s<e.length;s++)r=Bt.multiply(r,e[s]);return r}static invert(t){if(U.isAffine(t)){let e=U.determinant(t);if(e==0)return null;let r=t.m12*t.m23-t.m22*t.m13,s=t.m32*t.m13-t.m12*t.m33,i=t.m22*t.m33-t.m32*t.m23,o=t.m21*t.m13-t.m11*t.m23,a=t.m11*t.m33-t.m31*t.m13,c=t.m31*t.m23-t.m21*t.m33,l=t.m11*t.m22-t.m21*t.m12,f=t.m11*t.m32-t.m31*t.m12,d=t.m11*t.offsetY-t.offsetX*t.m12,m=t.m21*t.m32-t.m31*t.m22,x=t.m21*t.offsetY-t.offsetX*t.m22,b=t.m31*t.offsetY-t.offsetX*t.m32,g=t.m23*d-t.offsetZ*l-t.m13*x,h=t.m13*b-t.m33*d+t.offsetZ*f,u=t.m33*x-t.offsetZ*m-t.m23*b,y=l,p=-f,C=m,M=1/e;return U.from(i*M,s*M,r*M,0,c*M,a*M,o*M,0,C*M,p*M,y*M,0,u*M,h*M,g*M,1)}else{let e=U.determinant(t);if(e==0)return null;let r=t.m33*t.m44-t.m34*t.offsetZ,s=t.m32*t.m44-t.m34*t.offsetY,i=t.m31*t.m44-t.m34*t.offsetX,o=t.m32*t.offsetZ-t.m33*t.offsetY,a=t.m31*t.offsetZ-t.m33*t.offsetX,c=t.m31*t.offsetY-t.m32*t.offsetX,l=t.m33*t.m44-t.m34*t.offsetZ,f=t.m32*t.m44-t.m34*t.offsetY,d=t.m31*t.m44-t.m34*t.offsetX,m=t.m32*t.offsetZ-t.m33*t.offsetY,x=t.m31*t.offsetZ-t.m33*t.offsetX,b=t.m31*t.offsetY-t.m32*t.offsetX,g=t.m23*t.m44-t.m24*t.offsetZ,h=t.m22*t.m44-t.m24*t.offsetY,u=t.m21*t.m44-t.m24*t.offsetX,y=t.m22*t.offsetZ-t.m23*t.offsetY,p=t.m21*t.offsetZ-t.m23*t.offsetX,C=t.m21*t.offsetY-t.m22*t.offsetX,M=t.m23*t.m34-t.m24*t.m33,R=t.m22*t.m34-t.m24*t.m32,T=t.m21*t.m34-t.m24*t.m31,et=t.m22*t.m33-t.m23*t.m32,at=t.m21*t.m33-t.m23*t.m31,j=t.m21*t.m32-t.m22*t.m31,ct=t.m22*r-t.m23*s+t.m24*o,kt=-(t.m21*r-t.m23*i+t.m24*a),Et=t.m21*s-t.m22*i+t.m24*c,Tt=-(t.m21*o-t.m22*a+t.m23*c),Y=-(t.m12*l-t.m13*f+t.m14*m),k=t.m11*l-t.m13*d+t.m14*x,E=-(t.m11*f-t.m12*d+t.m14*b),A=t.m11*m-t.m12*x+t.m13*b,$=t.m12*g-t.m13*h+t.m14*y,G=-(t.m11*g-t.m13*u+t.m14*p),yt=t.m11*h-t.m12*u+t.m14*C,lt=-(t.m11*y-t.m12*p+t.m13*C),mt=-(t.m12*M-t.m13*R+t.m14*et),nt=t.m11*M-t.m13*T+t.m14*at,ut=-(t.m11*R-t.m12*T+t.m14*j),pt=t.m11*et-t.m12*at+t.m13*j,P=1/e;return U.from(ct*P,Y*P,$*P,mt*P,kt*P,k*P,G*P,nt*P,Et*P,E*P,yt*P,ut*P,Tt*P,A*P,lt*P,pt*P)}}static transform(t,e){var r={x:t.x,y:t.y,z:t.z};if(!U.isIdentity(e)){var s=r.x,i=r.y,o=r.z;if(r.x=s*e.m11+i*e.m21+o*e.m31+e.offsetX,r.y=s*e.m12+i*e.m22+o*e.m32+e.offsetY,r.z=s*e.m13+i*e.m23+o*e.m33+e.offsetZ,!U.isAffine(e)){var a=s*e.m14+i*e.m24+o*e.m34+e.m44;a!=0&&(r.x/=a,r.y/=a,r.z/=a)}}return r}},hr=class L{static identity(){return L.from(0,0,0,1)}static from(...t){if(t.length!==4)throw new RangeError("Must provide exactly 4 numbers");return{x:t[0],y:t[1],z:t[2],w:t[3]}}static parse(t){let e=ft(t);if(e&&e.length===4)return L.from.apply(null,e);throw new Error(`Cannot parse "${t}" as a valid Quaternion.`)}static fromVectors(t,e){B.normalize(t),B.normalize(e);let r=(i,o,a,c)=>{let l=L.from(i,o,a,c);return L.normalize(l),l},s=B.dot(t,e)+1;return s.isCloseTo(0)?Math.abs(t.x)>Math.abs(t.z)?r(-t.y,t.x,0,0):r(0,-t.z,t.y,0):r(t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x,s)}static normalize(t){let e=L.mag(t);if(e.isCloseTo(0))t.x=t.y=t.z=0,t.w=1;else{let r=1/e;t.x*=r,t.y*=r,t.z*=r,t.w*=r}}static unit(t){let e=L.from(t.x,t.y,t.z,t.w);return L.normalize(e),e}static fromAxisAngle(t,e){e%=360;var r=zt*e,s=B.mag(t);if(s==0)throw new RangeError("Invalid argument");var i=Math.sin(.5*r)/s,o=t.x*i,a=t.y*i,c=t.z*i;return L.from(o,a,c,Math.cos(.5*r))}static fromRotationMatrix(t){let e=t.m11+t.m22+t.m33+t.m44;if(e>0){let r=.5/Math.sqrt(e),s=.25/r,i=(t.m23-t.m32)*r,o=(t.m31-t.m13)*r,a=(t.m12-t.m21)*r;return L.from(i,o,a,s)}else if(t.m11>t.m22&&t.m11>t.m22){let r=.5/Math.sqrt(t.m44+t.m11-t.m22-t.m33),s=(t.m23-t.m32)*r,i=.25/r,o=(t.m12+t.m21)*r,a=(t.m31+t.m13)*r;return L.from(i,o,a,s)}else if(t.m22>t.m33){let r=.5/Math.sqrt(t.m44+t.m22-t.m11-t.m33),s=(t.m23+t.m32)*r,i=.25/r,o=(t.m12+t.m21)*r,a=(t.m31-t.m13)*r;return L.from(o,i,s,a)}else{let r=.5/Math.sqrt(t.m44+t.m33-t.m11-t.m22),s=(t.m23+t.m32)*r,i=.25/r,o=(t.m12-t.m21)*r,a=(t.m31-t.m13)*r;return L.from(a,s,i,o)}}static conjugate(t){return L.from(-t.x,-t.y,-t.z,t.w)}static mag(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w)}static norm(t){return t.x*t.x+t.y*t.y+t.z*t.z}static axis(t){return t.x==0&&t.y==0&&t.z==0?B.j():B.unit(t)}static transform(t,e){L.normalize(e);let r=B.cross(e,t),s=B.scale(r,2),i=B.cross(e,s);return{x:t.x+e.w*s.x+i.x,y:t.y+e.w*s.y+i.y,z:t.z+e.w*s.z+i.z}}static angle(t){let e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),r=t.w;if(e>Number.MAX_VALUE){let s=Math.max(Math.abs(t.x),Math.max(Math.abs(t.y),Math.abs(t.z))),i=t.x/s,o=t.y/s,a=t.z/s;e=Math.sqrt(i*i+o*o+a*a),r/=s}return Math.atan2(e,r)*114.59155902616465}static toRotationMatrix(t){var e=At.identity(),r=t.x,s=t.y,i=t.z,o=t.w;return e.m11=1-2*s*s-2*i*i,e.m12=2*r*s+2*o*i,e.m13=2*r*i-2*o*s,e.m21=2*r*s-2*o*i,e.m22=1-2*r*r-2*i*i,e.m23=2*s*i+2*o*r,e.m31=2*o*s+2*r*i,e.m32=2*s*i-2*o*r,e.m33=1-2*r*r-2*s*s,e}static invert(t){let e=L.unit(t);return L.conjugate(e)}static multiply(t,e){return L.from(t.w*e.x+t.x+e.w+t.y*e.z-t.z*e.y,t.w*e.y-t.x*e.z+t.y*e.w+t.z*e.x,t.w*e.z+t.x*e.y-t.y*e.x+t.z*e.w,t.w*e.w-t.x*e.x-t.y*e.y-t.z*e.z)}static dot(t,e){var r=L.multiply(t,L.conjugate(e));return r.w}},dr=class{static intersect(n,t){let[e,r]=n,s=B.subtract(e,r),[i,o,a]=t,c=B.subtract(i,o),l=B.subtract(i,a),f=B.cross(s,l),d=B.dot(c,f);if(d.isCloseTo(0))return null;let m=1/d,x=B.subtract(e,i),b=m*B.dot(x,f);if(b<0||b>1)return null;let g=B.cross(x,c),h=m*B.dot(s,g);if(h<0||b+h>1)return null;let u=m*B.dot(l,g);return u<0||u.isCloseTo(0)?null:B.add(e,B.scale(s,u))}},_e={};St(_e,{Matrix3D:()=>At,Quaternion:()=>hr,Spherical:()=>fr,Vector:()=>ht,Vector3D:()=>B});var ae={};St(ae,{Complex:()=>V,DataAnalysis:()=>Ye,NumberTheory:()=>Ve});function W(n){return typeof n=="number"&&(n={real:n,img:0}),n}var Se;function vt(n,t){let e={};return Object.defineProperty(e,"real",{value:n,writable:!1}),Object.defineProperty(e,"img",{value:t,writable:!1}),e}function te(){return Se||(Se=vt(Number.NaN,Number.NaN))}var V=class{static build(n,t){return this.isComplex(n)?n:(t??=0,typeof n!="number"||typeof t!="number"?te():vt(n,t||0))}static add(n,t){let e=W(n),r=W(t);return vt(e.real+r.real,e.img+r.img)}static subtract(n,t){let e=W(n),r=W(t);return vt(e.real-r.real,e.img-r.img)}static multiply(n,t){let e=W(n),r=W(t);return vt(e.real*r.real-e.img*r.img,e.real*r.img+e.img*r.real)}static divide(n,t){let e=W(n),r=W(t),s=this.absSquare(r).roundoff();if(s===0)return te();let i=1/s;return vt(i*(e.real*r.real+e.img*r.img),i*(e.img*r.real-e.real*r.img))}static absSquare(n){let t=W(n);return Math.pow(t.real,2)+Math.pow(t.img,2)}static modulus(n){return Math.sqrt(this.absSquare(n))}static isComplex(n){return n!=null&&typeof n=="object"&&"real"in n&&"img"in n&&typeof n.real=="number"&&typeof n.img=="number"}static conjugate(n){return n=W(n),vt(n.real,Math.abs(n.img)==0?0:-n.img)}static equals(n,t){let e=this.build(n),r=this.build(t);return!this.isComplex(n)||!this.isComplex(t)?!1:e.real===r.real&&e.img===r.img}static get NaC(){return te()}},Ye={};St(Ye,{Fourier:()=>mr,Gaussian:()=>ce,Lagrange:()=>Fe,Lagrangian:()=>wr,Newton:()=>Cr,Pchip:()=>vr,SearchFunctions:()=>$r,Utils:()=>Ar});function gr(n,t){let e=2*Math.PI*n/t;return V.build(Math.cos(e),Math.sin(e))}var Le={};function Xe(n,t){let e=Le[t]=Le[t]||{};return e[n]=e[n]||gr(n,t)}function yr(n){return n>0&&(n&n-1)===0}function ie(n){let t=[],e=n.length;if(e===1)return[V.build(n[0])];let r=ie(n.filter((o,a)=>a%2===0)),s=ie(n.filter((o,a)=>a%2===1));for(var i=0;i<e/2;i++){let o=r[i],a=V.multiply(Xe(i,e),s[i]);t[i]=V.add(o,a),t[i+e/2]=V.subtract(o,a)}return t}var mr=class{static transform(n,t=!0){return n=n||[],yr(n.length)?this.fft(n,t):this.dft(n,t)}static invert(n,t=!0){return this.idft(n||[],t)}static dft(n,t=!0){let e=(n||[])?.length,r=t?1/Math.sqrt(e):1,s=[];for(let i=0;i<e;i++){s.push({real:0,img:0});for(let o=0;o<e;o++){let a=Xe(i*o,e),c=V.multiply(n[o],a),l=V.multiply(c,r);s[i]=V.add(s[i],l)}}return s}static idft(n,t=!0){let e=n.map(s=>V.build(s.img,s.real));return this.transform(e,t).map(s=>V.build(s.img,s.real))}static fft(n,t=!0){let e=ie(n);if(!t)return e;let r=1/Math.sqrt(n.length);return e.map(s=>V.multiply(s,r))}},pr=Math.sqrt(Math.PI);function xr(n){let t=Math.abs(n),e=1/(1+.5*t),r=e*Math.exp(-t*t-1.26551223+e*(1.00002368+e*(.37409196+e*(.09678418+e*(-.18628806+e*(.27886807+e*(-1.13520398+e*(1.48851587+e*(-.82215223+e*.17087277)))))))));return n>=0?r:2-r}var ce=class{constructor(n,t){this.mean=n,this.stdev=Math.abs(t),this.variance=Math.pow(t,2)}static get normal(){return br}weight(n){return Math.exp(-.5*Math.pow(this._z(n),2))}probabilityDensity(n){let t=this.stdev*Math.SQRT2*pr;return this.weight(n)/t}_z(n){return(n-this.mean)/this.stdev}probability(n){return .5*xr(-this._z(n)/Math.SQRT2)}},br=new ce(0,1),Fe=class je{constructor(t){this.#t=t}#t;#e=null;_prepareBarycentric(){if(this.#e)return;let t=this.#t||[],e=t.length;if(e===0){this.#e=[];return}let r=new Array(e),s=new Array(e);for(let a=0;a<e;a++){let c=0,l=1,f=t[a].x;for(let d=0;d<e;d++){if(d===a)continue;let m=f-t[d].x;if(m===0)throw new Error("Invalid function provided.");m<0&&(l=-l),c+=Math.log(Math.abs(m))}r[a]=-c,s[a]=l}let i=r[0];for(let a=1;a<e;a++)r[a]>i&&(i=r[a]);let o=new Array(e);for(let a=0;a<e;a++){let c=Math.exp(r[a]-i);o[a]=s[a]*c}this.#e=o}_computeBarycentric(t){let e=this.#t||[];this.#e||this._prepareBarycentric();let r=this.#e||[],s=0,i=0;for(let o=0;o<e.length;o++){let a=e[o].x;if(t===a)return e[o].y;let c=r[o]/(t-a);s+=c*e[o].y,i+=c}return s/i}interpolate(t){return this._computeBarycentric(t)}static create(...t){var e=[];arguments.length>0&&Array.isArray(arguments[0])?e=arguments[0]:e=Array.from(t);let r=e.map((s,i)=>typeof s=="number"?{x:i,y:s}:s);return new je(r)}},wr={create:Fe.create},vr=class Ze{constructor(t){if(!t||t.length<2)throw new Error("Need at least 2 points");let e=t.slice().sort((r,s)=>r.x-s.x);this.xs=e.map(r=>r.x),this.ys=e.map(r=>r.y),this.ms=this.computeDerivatives()}computeDerivatives(){let t=this.xs.length,e=new Array(t-1),r=new Array(t-1);for(let i=0;i<t-1;i++)e[i]=this.xs[i+1]-this.xs[i],r[i]=(this.ys[i+1]-this.ys[i])/e[i];let s=new Array(t).fill(0);s[0]=r[0],s[t-1]=r[t-2];for(let i=1;i<t-1;i++){let o=r[i-1],a=r[i];if(o===0||a===0||o*a<=0)s[i]=0;else{let c=2*e[i]+e[i-1],l=e[i]+2*e[i-1];s[i]=(c+l)/(c/o+l/a)}}for(let i=0;i<t-1;i++)if(r[i]===0)s[i]=0,s[i+1]=0;else{let o=s[i]/r[i],a=s[i+1]/r[i],c=o*o+a*a;if(c>9){let l=3/Math.sqrt(c);s[i]=l*o*r[i],s[i+1]=l*a*r[i]}}return s}interpolate(t){let e=this.xs,r=this.ys,s=this.ms,i=e.length;if(t<=e[0]){let h=s[0];return r[0]+h*(t-e[0])}if(t>=e[i-1]){let h=s[i-1];return r[i-1]+h*(t-e[i-1])}let o=0,a=i-1;for(;a-o>1;){let h=o+a>>1;e[h]<=t?o=h:a=h}let c=e[o+1]-e[o],l=(t-e[o])/c,f=l*l,d=f*l,m=2*d-3*f+1,x=d-2*f+l,b=-2*d+3*f,g=d-f;return m*r[o]+x*(s[o]*c)+b*r[o+1]+g*(s[o+1]*c)}static create(...t){var e=[];arguments.length>0&&Array.isArray(arguments[0])?e=arguments[0]:e=Array.from(t);let r=e.map((s,i)=>typeof s=="number"?{x:i,y:s}:s);return new Ze(r)}},Cr=class Ge{constructor(t){if(!t||t.length===0)throw new Error("Need at least 1 point");let e=t.slice().sort((i,o)=>i.x-o.x);this.xs=e.map(i=>i.x);let r=e.length,s=e.map(i=>i.y);for(let i=1;i<r;i++)for(let o=r-1;o>=i;o--){let a=this.xs[o]-this.xs[o-i];if(a===0)throw new Error("Invalid function provided.");s[o]=(s[o]-s[o-1])/a}this.coeffs=s}interpolate(t){let e=this.xs,r=this.coeffs,s=r.length;if(s===0)return NaN;let i=r[s-1];for(let o=s-2;o>=0;o--)i=i*(t-e[o])+r[o];return i}static create(...t){var e=[];arguments.length>0&&Array.isArray(arguments[0])?e=arguments[0]:e=Array.from(t);let r=e.map((s,i)=>typeof s=="number"?{x:i,y:s}:s);return new Ge(r)}},K=(n,t)=>n;function kr(n,t=K){let e=Object.groupBy(n,t),r,s=0;for(let i in e){let o=e[i].length;o>s&&(r=parseInt(i),s=o)}return r}function Tr(n,t=K){let e=n.slice(0),r=e.length;e.sort((i,o)=>{let a=t(i),c=t(o);return a-c});let s=Math.ceil(e.length/2)-1;return r%2==1?e[s]:.5*(e[s+1]+e[s])}function Ue(n,t=K){return n.reduce((e,r,s)=>e+t(r,s),0)}function Zt(n,t=K){return Ue(n,t)/n.length}function oe(n,t=K,e=!1){let r=Zt(n,t);return n.reduce((s,i)=>Math.pow(i-r,2)+s,0)/(n.length-(e?1:0))}function Oe(n,t=K,e=!1){let r=oe(n,t,e);return Math.sqrt(r)}function Mr(n,t,e=K,r=K){let s=Array.isArray(t);if(s&&t.length!==n.length)throw new Error("Sets must be of the same length.");let i=n.length,o=n,a=s?t:n,c=s?e:t,l=s?r:e,f=Zt(o,c),d=Zt(a,l),m=0,x=0,b=0;for(let g=0;g<i;g++){let h=o[g],u=a[g],y=c(h,g)-f,p=l(u,g)-d;m+=y*p,x+=y*y,b+=p*p}return m/Math.sqrt(x*b)}function Rr(n,t,e=K,r=K){let s=Array.isArray(t);if(s&&t.length!==n.length)throw new Error("Sets must be of the same length.");let i=n,o=s?t:n,a=s?e:t,c=s?r:a,l=a??(p=>p.x),f=c??(p=>p.y),d=n.length,m=0,x=0,b=0,g=0,h=0;for(let p=0;p<d;p++){let C=i[p],M=o[p],R=l(C,p),T=f(M,p);m+=R*T,x+=R,b+=T,g+=R*R,h+=T*T}let u=(d*m-x*b)/(d*g-Math.pow(x,2)),y=(b-u*x)/d;return[u,y]}var Ar=class{static sum(n,t){return Ue(n,t)}static mean(n,t){return Zt(n,t)}static median(n,t){return Tr(n,t)}static mode(n,t){return kr(n,t)}static var(n,t){return oe(n,t,!0)}static varp(n,t){return oe(n,t,!1)}static stdevp(n,t){return Oe(n,t,!1)}static stdev(n,t){return Oe(n,t,!0)}static correlation(n,t,e,r){return Mr(n,t,e,r)}static linearRegression(n,t,e,r){return Rr(n,t,e,r)}static gaussian(n,t){return new ce(n,t)}};function le(n,t){return(r,s,i,o)=>{let a=r,c=s,l=n(a,c),f=t(a,c),d=i(l),m=i(f);for(;c-a>o;)d<m?(c=f,f=l,m=d,l=n(a,c),d=i(l)):(a=l,l=f,d=m,f=t(a,c),m=i(f));return .5*(l+f)}}var ue=.001,Er=(n,t,e,r=ue)=>le((c,l)=>l-(l-c)/1.618,(c,l)=>c+(l-c)/1.618)(n,t,e,r);function Ir(n){if(n<=1)throw new RangeError("segments must be a number grater than 1.");return(t,e,r,s=ue)=>le((c,l)=>c+(l-c)/n,(c,l)=>l-(l-c)/n)(t,e,r,s)}var Nr=(n,t,e,r=ue)=>{var s=null,i=null;let o=(f,d)=>(i??=d-f,s??=i/Math.sqrt(12),s*(d-f)/i);return le((f,d)=>Math.max(f,(d+f)/2-o(f,d)),(f,d)=>Math.min(d,(d+f)/2+o(f,d)))(n,t,e,r)},$r={linear:(n=2)=>Ir(n),goldenRatio:Er,gaussian:Nr},Ve={};St(Ve,{Utils:()=>Br});var Xt="0123456789abcdefghijklmnopqrstuvwxyz",ee=`Radix out of range: possible values go between positive 1 exclusive and ${Xt.length} inclusive`,Br=class Pt{static lcd(...t){if(z.isNullOrEmpty(t)||t.length<=1)throw"Insufficient set of numbers.";function e(i,o){return o?e(o,i%o):o===0?i:NaN}function r(i,o){return i*o/e(i,o)}let s=Math.round(t[0]);for(let i=1;i<t.length;i++)s=r(s,Math.round(t[i]));return s}static gcd(t,e){return t=Math.round(t),e=Math.round(e),t===0?e:Pt.gcd(e%t,t)}static rebaseInt(t,e,r){return $t.rebase(t,e,r)}static rebaseFloat(t,e,r,s=12){let i=Pt.rebaseFloat10ToN,o=Pt.rebaseFloatNTo10;if(e===10){let c=parseFloat(t.toString());return r%1===0?Pt.rebaseFloat10ToNIntBase(c,r,s):i(c,r,s)}if(r===10)return o(t.toString(),e,s);let a=o(t.toString(),e,s+1);return i(a,r,s)}static rebaseFloatNTo10(t,e,r=12){let s=Xt;if(e<=1||e>s.length)throw new Error(ee);let i=(t??"0").toString().toLowerCase(),o=Number.NaN;if(i==="0")return 0;let a=/^([-+]?) *([\da-z]+)?(.[\da-z]+)?$/.exec(i);if(a.length<2)return o;let c=a[1]==="-"?-1:1,l=a[2]||"0",f=a[3]||".0",d=0,m=0;for(let x of l+f.substr(1)){let b=s.indexOf(x);if(b===-1||b>=e)return o;d+=b*Math.pow(e,l.length-m-1),m++}return c*d}static rebaseFloat10ToNIntBase(t,e,r=12){let s=Xt;if(e<=1||e>s.length)throw new Error(ee);let i=e,o=Math.abs(t??0);if(o===0||Number.isNaN(o))return t.toString();let a=(o%1).roundoff(),c="";do{let f=o/i,d=Math.floor(f),m=(o-d*i).roundoff(),x=Math.floor(m);if(x>=s.length?c=`[${x}]`+c:c=s[x]+c,d<=0)break;o=d}while(!0);if(c=c.replace(/^0+/,""),c||="0",a===0)return c;let l="";do{o=(a*i).roundoff();let f=Math.floor(o),d=(o-f).roundoff();f>=s.length?l=`[${f}]`:l+=s[f],a=d}while(!a.isCloseTo(0)&&l.length<r);return/^0*$/.test(l)?c:(Math.sign(t)<0?"-":"")+c+"."+l.replace(/0+$/,"")}static rebaseFloat10ToN(t,e,r=12){let s=Xt;if(e<=1||e>s.length)throw new Error(ee);let i=e,o=Math.abs(t??0);if(o===0||Number.isNaN(o))return t.toString();let a=Math.sign(t)<0?"-":"",c=[],l=[];for(let x=0;x<20;x++)c.push("0"),l.push("0");let f=i%1===0?i:Math.ceil(i);function d(x,b,g){let h=x?c:l,u=h[b]=h[b]||"0",y=s.indexOf(u)+g,p=y%f,C=Math.floor(y/f);return h[b]=s[p],C>0&&(x?d(x,b+1,C):b===0?d(!0,0,C):d(!1,b-1,C)),C}let m=0;do{let x=Math.floor($t.log(o,i)),b=x>=0,g=b?x:Math.abs(1+x);if(d(b,g,1),o=(o-Math.pow(i,x).roundoff()).roundoff(),b||m++,o===0||m>=100){let h=a+(c.reverse().map(y=>y||"0").join("").replace(/^0+/,"")||"0"),u=l.map(y=>y||"0").join("").substr(0,r).replace(/0+$/,"");return/^0*$/.test(u)?h:h+"."+u}}while(!0)}};var gt=Pr(Sr(process.argv)).option("theme",{alias:"t",type:"string",description:"Theme (dark or light)"}).option("name",{alias:"n",type:"string",description:"Theme name"}).option("src",{alias:"s",type:"string",description:"Palette file containing the color variables in JSON format."}).option("out",{alias:"o",type:"string",description:"Output file (overrides name option)."}).option("void",{type:"string",description:"Creates an empty palette file."}).option("mincontrast",{type:"number",description:"The minimum WCAG contrast (1 to 21) container-to-background (default 1.5)."}).option("maxcontrast",{type:"number",description:"The maximum WCAG contrast (1 to 21) default-to-background (default 15)."}).option("contrast",{type:"number",description:"The minimim WCAG contrast (1 to 21) solid color-to-background (default 4.5)."}).help().argv,F=gt.theme==="dark",Lr=gt.name??(F?"dark":"light");function Or(n){return zr.join(import.meta.dirname,n)}function Dr(n){if(n==null)return null;let t=We.readFileSync(n,"utf-8");return JSON.parse(t)}var tt=Object.assign({background:"#1e2336",primary:"#429bbb",secondary:"#5e7881",accent:"#ff0085",success:"#4dc2b4",warning:"#c5c023",error:"#BF215B",danger:"#fa1f1f",info:"#99d4ff",green:"#1ebb8f",yellow:"#c2b010",brown:"#a6715e",red:"#dd2020",pink:"#ff0085",blue:"#116e8b",orange:"#d46d00",purple:"#624472",teal:"#429bbb",gray:"#808080"},Dr(gt.src)??{}),de=gt.mincontrast??1.5,Lt=4.5,Qe=gt.contrast??Lt,he=7,Ke=gt.maxcontrast??15,Hr=1.6,Je=.95,qe=.02,_r=.175,tn=ae.DataAnalysis.SearchFunctions.goldenRatio,ot,Gt;function en(n){return I.luminance(n)>=.2}function _(n,t=n,e=Lt,r=null){let s=typeof t=="object"?t:n,i=typeof t=="number"?t:typeof e=="number"?e:Lt,o=typeof e=="boolean"?e:r,{h:a,s:c,l,a:f}=I.hsl(n),d=o??!en(n),b=tn(d?l:0,d?1:l,g=>Math.abs(i-I.contrastRatio(s,{h:a,s:c,l:g,a:f})).roundoff());return I.rgb({h:a,s:c,l:b,a:f})}function dt(n,t){let{h:e,s:r,a:s}=I.hsl(n),i=tn(0,1,o=>Math.abs(t-I.luminance({h:e,s:r,l:o,a:s})));return I.rgb({h:e,s:r,l:i,a:s})}function nn(n){return{base:n.contrast,contrast:n.base,active:n.activeContrast,activeContrast:n.active,emphasis:n.base,container:n.containerContrast,containerContrast:n.container,containerActive:n.containerActiveContrast,containerActiveContrast:n.containerActive}}function rn(n,t=_r){let{h:e,s:r,l:s,a:i}=I.hsl(n);return r>t?I.rgb({h:e,s:t,l:s,a:i}):n}function sn(n,t,e){let r=e&&typeof e=="number"?e:null,s=r??Ke,i=e&&typeof e=="object"?e:null,o=t==="background"?Je+.015:Je,f=(F?I.luminance(n)<=qe:I.luminance(n)>=o)?n:F?dt(n,qe):dt(n,o),d=i?n:f,m=F?.035:-.08,x=r??he,b=i??_(d,s),u=_(d,d,de,F),y=_(u,Lt),p=dt(d,I.luminance(d)+m),C=_(p,x),M=dt(u,I.luminance(u)+m),R=_(M,x),T=I.saturate(d,1.2);return{base:d,contrast:b,active:p,activeContrast:C,containerActive:M,container:u,emphasis:T,containerActiveContrast:R,containerContrast:y}}function Yr(n){let t=Math.min(de,Hr),e=ot.base,r=F,s=!r,i=_(n,e,1),o=_(rn(i),e,t,r),a=F?.1:-.06,c=_(o,t,s),f=_(o,e,1.1,s),d=_(f,t,r),m=dt(o,I.luminance(o)+a),x=_(m,t,s),b=dt(f,I.luminance(f)+a),g=_(b,t),h=I.lighten(o,.1);return{base:o,contrast:c,active:m,activeContrast:x,containerActive:b,container:f,emphasis:h,containerActiveContrast:g,containerContrast:d}}function on(n,t,e){let r=t==="gray",s=e&&typeof e=="number"?e:null,i=s??he,o=e&&typeof e=="object"?e:null,c=en(n)===F&&I.contrastRatio(n,ot.base)>=Qe?n:_(n,ot.base,Qe,F),l=o?n:c;r&&(l=rn(l));let f=F?.1:-.06,d=s??he,m=o??_(l,i,!F),x=de,b=ot.base,g=_(l,b,x,!F),h=_(g,Lt,F),u=dt(l,I.luminance(l)+f),y=_(u,d,!F),p=dt(g,I.luminance(g)+f),C=_(p,d,F),M=r?I.lighten(l,.1):I.saturate(l,1.2);return{base:l,contrast:m,active:u,activeContrast:y,containerActive:p,container:g,emphasis:M,containerActiveContrast:C,containerContrast:h}}var O={},fe=n=>Math.round(n*255),it=n=>`${fe(n.r)}, ${fe(n.g)}, ${fe(n.b)}`,Ct=(n,t)=>{O[`@color_${n}`]=I.stringify(t.base),O[`@color_${n}_rgb`]=it(t.base),O[`@color_${n}_inv`]=I.stringify(t.contrast),O[`@color_${n}_inv_rgb`]=it(t.contrast),O[`@color_${n}_container`]=I.stringify(t.container),O[`@color_${n}_container_rgb`]=it(t.container),O[`@color_${n}_container_inv`]=I.stringify(t.containerContrast),O[`@color_${n}_container_inv_rgb`]=it(t.containerContrast),O[`@color_${n}_active`]=I.stringify(t.active),O[`@color_${n}_active_rgb`]=it(t.active),O[`@color_${n}_active_inv`]=I.stringify(t.activeContrast),O[`@color_${n}_active_inv_rgb`]=it(t.activeContrast),O[`@color_${n}_container_active`]=I.stringify(t.containerActive),O[`@color_${n}_container_active_rgb`]=it(t.containerActive),O[`@color_${n}_container_active_inv`]=I.stringify(t.containerActiveContrast),O[`@color_${n}_container_active_inv_rgb`]=it(t.containerActiveContrast),O[`@color_${n}_emphasis`]=I.stringify(t.emphasis),O[`@color_${n}_emphasis_rgb`]=it(t.emphasis)},Xr=I.parse(tt.background);ot=sn(Xr,"background");Ct("background",ot);var Fr="root"in tt?I.parse(tt.root):I.darken(ot.base,F?.02:.01);Gt=sn(Fr,"root");Ct("root",Gt);if("default"in tt){let n=_(I.parse(tt.default),Gt.base,Ke,F),t=on(n,"default");Ct("default",t)}else Ct("default",nn(Gt));var jr="disabled"in tt?I.parse(tt.disabled):ot.base;Ct("disabled",Yr(jr));for(let n in tt){if(["default","background","root","disabled"].indexOf(n)>=0)continue;let t=I.parse(tt[n]),e=on(t,n);Ct(n,e)}"invert"in tt||Ct("invert",nn(ot));var ge=`@palette_prebuilt: true;\r
8
+ `;for(let n in O){let t=O[n];ge+=`${n}: ${t};\r
9
+ `}var Zr=gt.out??Or("./pacem/palette-"+Lr+".less");X.isNull(gt.void)||(ge="");We.writeFileSync(Zr,ge);