@visulima/fmt 1.1.11 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1,664 @@
1
- "use strict";var v=Object.defineProperty;var h=(e,t)=>v(e,"name",{value:t,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var A=Object.defineProperty,m=h((e,t)=>A(e,"name",{value:t,configurable:!0}),"m$1");const x=new Map([["aliceblue","#f0f8ff"],["antiquewhite","#faebd7"],["aqua","#00ffff"],["aquamarine","#7fffd4"],["azure","#f0ffff"],["beige","#f5f5dc"],["bisque","#ffe4c4"],["black","#000000"],["blanchedalmond","#ffebcd"],["blue","#0000ff"],["blueviolet","#8a2be2"],["brown","#a52a2a"],["burlywood","#deb887"],["cadetblue","#5f9ea0"],["chartreuse","#7fff00"],["chocolate","#d2691e"],["coral","#ff7f50"],["cornflowerblue","#6495ed"],["cornsilk","#fff8dc"],["crimson","#dc143c"],["cyan","#00ffff"],["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","#ff00ff"],["gainsboro","#dcdcdc"],["ghostwhite","#f8f8ff"],["gold","#ffd700"],["goldenrod","#daa520"],["gray","#808080"],["green","#008000"],["greenyellow","#adff2f"],["grey","#808080"],["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","#778899"],["lightslategrey","#778899"],["lightsteelblue","#b0c4de"],["lightyellow","#ffffe0"],["lime","#00ff00"],["limegreen","#32cd32"],["linen","#faf0e6"],["magenta","#ff00ff"],["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"],["rebeccapurple","#663399"],["red","#ff0000"],["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","#ffffff"],["whitesmoke","#f5f5f5"],["yellow","#ffff00"],["yellowgreen","#9acd32"]]),C=/^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i,D=/^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i,M=/^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,P=/^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,B=m(()=>({__proto__:null,backgroundColor:null,color:null,fontStyle:null,fontWeight:null,textDecorationColor:null,textDecorationLine:[]}),"getDefaultCss"),p=/\s+/g,g=m(e=>{x.has(e)&&(e=x.get(e));const t=C.exec(e);if(t)return[Number.parseInt(t[1],16),Number.parseInt(t[2],16),Number.parseInt(t[3],16)];const o=D.exec(e);if(o)return[Number.parseInt(`${o[1]}${o[1]}`,16),Number.parseInt(`${o[2]}${o[2]}`,16),Number.parseInt(`${o[3]}${o[3]}`,16)];const f=M.exec(e);if(f)return[Math.round(Math.max(0,Math.min(255,Number(f[1])))),Math.round(Math.max(0,Math.min(255,Number(f[2])))),Math.round(Math.max(0,Math.min(255,Number(f[3]))))];const i=P.exec(e);if(i){let n=Number(i[1])%360;n<0&&(n+=360);const l=Math.max(0,Math.min(100,Number(i[2])))/100,a=Math.max(0,Math.min(100,Number(i[3])))/100,c=(1-Math.abs(2*a-1))*l,u=c*(1-Math.abs(n/60%2-1)),r=a-c/2;let s,d,b;return n<60?{0:s,1:d,2:b}=[c,u,0]:n<120?{0:s,1:d,2:b}=[u,c,0]:n<180?{0:s,1:d,2:b}=[0,c,u]:n<240?{0:s,1:d,2:b}=[0,u,c]:n<300?{0:s,1:d,2:b}=[u,0,c]:{0:s,1:d,2:b}=[c,0,u],[Math.round((s+r)*255),Math.round((d+r)*255),Math.round((b+r)*255)]}return null},"parseCssColor"),k=m((e,t)=>e?.[0]===t?.[0]&&e?.[1]===t?.[1]&&e?.[2]===t?.[2],"colorEquals"),N=m(e=>{const t=B(),o=[];let f=!1,i=null,n=0,l="";for(const a of e){if(a==="(")n++;else if(n>0)a===")"&&n--;else if(f){if(a===";"){const c=l.trim();c!==""&&o.push([i,c]),i=null,l="",f=!1;continue}}else if(a===":"){i=l.trim(),l="",f=!0;continue}l+=a}if(f&&n===0){const a=l.trim();a!==""&&o.push([i,a]),i=null,l=""}for(const{0:a,1:c}of o)switch(a){case"background-color":{c!=null&&(t.backgroundColor=c);break}case"color":{c!=null&&(t.color=c);break}case"font-weight":{c==="bold"&&(t.fontWeight=c);break}case"font-style":{["italic","oblique","oblique 14deg"].includes(c)&&(t.fontStyle="italic");break}case"text-decoration-line":{t.textDecorationLine=[];const u=c.split(p);for(const r of u)["line-through","overline","underline"].includes(r)&&t.textDecorationLine.push(r);break}case"text-decoration-color":{const u=g(c);u!=null&&(t.textDecorationColor=u);break}case"text-decoration":{t.textDecorationColor=null,t.textDecorationLine=[];const u=c.split(p);for(const r of u){const s=g(r);s!=null?t.textDecorationColor=s:["line-through","overline","underline"].includes(r)&&t.textDecorationLine.push(r)}break}}return t},"parseCss"),F=m((e,t=null)=>{t=t??B();let o="";if(!k(e.backgroundColor,t.backgroundColor))if(e.backgroundColor==null)o+="\x1B[49m";else switch(e.backgroundColor){case"black":{o+="\x1B[40m";break}case"red":{o+="\x1B[41m";break}case"green":{o+="\x1B[42m";break}case"yellow":{o+="\x1B[43m";break}case"blue":{o+="\x1B[44m";break}case"magenta":{o+="\x1B[45m";break}case"cyan":{o+="\x1B[46m";break}case"white":{o+="\x1B[47m";break}default:if(Array.isArray(e.backgroundColor)){const{0:f,1:i,2:n}=e.backgroundColor;o+=`\x1B[48;2;${f};${i};${n}m`}else{const f=g(e.backgroundColor);if(f===null)o+="\x1B[49m";else{const{0:i,1:n,2:l}=f;o+=`\x1B[48;2;${i};${n};${l}m`}}}if(!k(e.color,t.color))if(e.color==null)o+="\x1B[39m";else switch(e.color){case"black":{o+="\x1B[30m";break}case"red":{o+="\x1B[31m";break}case"green":{o+="\x1B[32m";break}case"yellow":{o+="\x1B[33m";break}case"blue":{o+="\x1B[34m";break}case"magenta":{o+="\x1B[35m";break}case"cyan":{o+="\x1B[36m";break}case"white":{o+="\x1B[37m";break}default:if(Array.isArray(e.color)){const{0:f,1:i,2:n}=e.color;o+=`\x1B[38;2;${f};${i};${n}m`}else{const f=g(e.color);if(f===null)o+="\x1B[39m";else{const{0:i,1:n,2:l}=f;o+=`\x1B[38;2;${i};${n};${l}m`}}}if(e.fontWeight!==t.fontWeight&&(o+=e.fontWeight==="bold"?"\x1B[1m":"\x1B[22m"),e.fontStyle!==t.fontStyle&&(o+=e.fontStyle==="italic"?"\x1B[3m":"\x1B[23m"),!k(e.textDecorationColor,t.textDecorationColor))if(e.textDecorationColor==null)o+="\x1B[59m";else{const{0:f,1:i,2:n}=e.textDecorationColor;o+=`\x1B[58;2;${f};${i};${n}m`}return e.textDecorationLine.includes("line-through")!==t.textDecorationLine.includes("line-through")&&(o+=e.textDecorationLine.includes("line-through")?"\x1B[9m":"\x1B[29m"),e.textDecorationLine.includes("overline")!==t.textDecorationLine.includes("overline")&&(o+=e.textDecorationLine.includes("overline")?"\x1B[53m":"\x1B[55m"),e.textDecorationLine.includes("underline")!==t.textDecorationLine.includes("underline")&&(o+=e.textDecorationLine.includes("underline")?"\x1B[4m":"\x1B[24m"),o},"cssToAnsi");var L=Object.defineProperty,y=h((e,t)=>L(e,"name",{value:t,configurable:!0}),"y");const j=y(e=>{try{return JSON.stringify(e)}catch{return'"[Circular]"'}},"tryStringify"),w="%".codePointAt(0),q="s".codePointAt(0),S="d".codePointAt(0),E="f".codePointAt(0),O="i".codePointAt(0),I="O".codePointAt(0),T="o".codePointAt(0),W="j".codePointAt(0),_="c".codePointAt(0),$=y((e,t=[],o={})=>{if(typeof e!="string"&&typeof e!="object"||e===null)throw new TypeError(`fmt must be a string or object, got ${e===null?"null":typeof e}`);const f=o.stringify??j,i=1;if(typeof e=="object"){const r=t.length+i;if(r===1)return"{}";const s=Array.from({length:r});s[0]=f(e);for(let d=1;d<r;d++)s[d]=f(t[d-i]);return s.join(" ")}if(t.length===0)return e;let n="",l=1-i,a=-1,c=!1,u=null;for(let r=0;r<e.length;){if(e.codePointAt(r)===w&&r+1<e.length){a=a>-1?a:0;const s=e.codePointAt(r+1);if(s===void 0){++l;break}switch(s){case S:case E:{if(l>=t.length||t[l]==null)break;a<r&&(n+=e.slice(a,r)),n+=Number(t[l]).toString(),a=r+2,r++;break}case O:{if(l>=t.length||t[l]==null)break;a<r&&(n+=e.slice(a,r)),n+=Math.floor(Number(t[l])).toString(),a=r+2,r++;break}case I:case T:case W:{if(l>=t.length||t[l]===void 0)break;a<r&&(n+=e.slice(a,r));const d=t[l],b=typeof d;if(b==="string"){n+=`'${d}'`,a=r+2;break}if(b==="function"){n+=d.name?`[Function: ${d.name}]`:"[Function: <anonymous>]",a=r+2;break}n+=f(d),a=r+2,r++;break}case q:{if(l>=t.length)break;a<r&&(n+=e.slice(a,r)),n+=typeof t[l]=="object"?f(t[l]):String(t[l]),a=r+2,r++;break}case w:{a<r&&(n+=e.slice(a,r)),n+="%",a=r+2,r++,l--;break}case _:{if(typeof window>"u"){const d=N(t[l]);a<r&&(n+=e.slice(a,r)),n+=F(d,u),n!==""&&(c=!0,u=d)}a=r+2,r++;break}default:typeof o.formatters?.[s]=="function"&&(a<r&&(n+=e.slice(a,r)),n+=o.formatters[s](t[l]),a=r+2,r++)}++l}++r}return a===-1?e:(a<e.length&&(n+=e.slice(a)),c&&(n+="\x1B[0m"),n)},"format"),z=y((e={})=>{const t={};return typeof e.formatters=="object"&&Object.entries(e.formatters).forEach(([o,f])=>{if(o.length===0)throw new Error(`Formatter %${o} has no characters`);if(o.length>1)throw new Error(`Formatter %${o} has more than one character`);if(typeof f!="function")throw new TypeError(`Formatter for %${o} is not a function`);const i=o.codePointAt(0);if(i===void 0)throw new Error(`${o}.codePointAt(0) failed to return a value, please report this issue`);t[i]=f}),(o,f=[],i={})=>$(o,f,{...i,formatters:t})},"build");exports.build=z;exports.format=$;
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp$1 = Object.defineProperty;
6
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
7
+ const colorKeywords = /* @__PURE__ */ new Map([
8
+ ["aliceblue", "#f0f8ff"],
9
+ ["antiquewhite", "#faebd7"],
10
+ ["aqua", "#00ffff"],
11
+ ["aquamarine", "#7fffd4"],
12
+ ["azure", "#f0ffff"],
13
+ ["beige", "#f5f5dc"],
14
+ ["bisque", "#ffe4c4"],
15
+ ["black", "#000000"],
16
+ ["blanchedalmond", "#ffebcd"],
17
+ ["blue", "#0000ff"],
18
+ ["blueviolet", "#8a2be2"],
19
+ ["brown", "#a52a2a"],
20
+ ["burlywood", "#deb887"],
21
+ ["cadetblue", "#5f9ea0"],
22
+ ["chartreuse", "#7fff00"],
23
+ ["chocolate", "#d2691e"],
24
+ ["coral", "#ff7f50"],
25
+ ["cornflowerblue", "#6495ed"],
26
+ ["cornsilk", "#fff8dc"],
27
+ ["crimson", "#dc143c"],
28
+ ["cyan", "#00ffff"],
29
+ ["darkblue", "#00008b"],
30
+ ["darkcyan", "#008b8b"],
31
+ ["darkgoldenrod", "#b8860b"],
32
+ ["darkgray", "#a9a9a9"],
33
+ ["darkgreen", "#006400"],
34
+ ["darkgrey", "#a9a9a9"],
35
+ ["darkkhaki", "#bdb76b"],
36
+ ["darkmagenta", "#8b008b"],
37
+ ["darkolivegreen", "#556b2f"],
38
+ ["darkorange", "#ff8c00"],
39
+ ["darkorchid", "#9932cc"],
40
+ ["darkred", "#8b0000"],
41
+ ["darksalmon", "#e9967a"],
42
+ ["darkseagreen", "#8fbc8f"],
43
+ ["darkslateblue", "#483d8b"],
44
+ ["darkslategray", "#2f4f4f"],
45
+ ["darkslategrey", "#2f4f4f"],
46
+ ["darkturquoise", "#00ced1"],
47
+ ["darkviolet", "#9400d3"],
48
+ ["deeppink", "#ff1493"],
49
+ ["deepskyblue", "#00bfff"],
50
+ ["dimgray", "#696969"],
51
+ ["dimgrey", "#696969"],
52
+ ["dodgerblue", "#1e90ff"],
53
+ ["firebrick", "#b22222"],
54
+ ["floralwhite", "#fffaf0"],
55
+ ["forestgreen", "#228b22"],
56
+ ["fuchsia", "#ff00ff"],
57
+ ["gainsboro", "#dcdcdc"],
58
+ ["ghostwhite", "#f8f8ff"],
59
+ ["gold", "#ffd700"],
60
+ ["goldenrod", "#daa520"],
61
+ ["gray", "#808080"],
62
+ ["green", "#008000"],
63
+ ["greenyellow", "#adff2f"],
64
+ ["grey", "#808080"],
65
+ ["honeydew", "#f0fff0"],
66
+ ["hotpink", "#ff69b4"],
67
+ ["indianred", "#cd5c5c"],
68
+ ["indigo", "#4b0082"],
69
+ ["ivory", "#fffff0"],
70
+ ["khaki", "#f0e68c"],
71
+ ["lavender", "#e6e6fa"],
72
+ ["lavenderblush", "#fff0f5"],
73
+ ["lawngreen", "#7cfc00"],
74
+ ["lemonchiffon", "#fffacd"],
75
+ ["lightblue", "#add8e6"],
76
+ ["lightcoral", "#f08080"],
77
+ ["lightcyan", "#e0ffff"],
78
+ ["lightgoldenrodyellow", "#fafad2"],
79
+ ["lightgray", "#d3d3d3"],
80
+ ["lightgreen", "#90ee90"],
81
+ ["lightgrey", "#d3d3d3"],
82
+ ["lightpink", "#ffb6c1"],
83
+ ["lightsalmon", "#ffa07a"],
84
+ ["lightseagreen", "#20b2aa"],
85
+ ["lightskyblue", "#87cefa"],
86
+ ["lightslategray", "#778899"],
87
+ ["lightslategrey", "#778899"],
88
+ ["lightsteelblue", "#b0c4de"],
89
+ ["lightyellow", "#ffffe0"],
90
+ ["lime", "#00ff00"],
91
+ ["limegreen", "#32cd32"],
92
+ ["linen", "#faf0e6"],
93
+ ["magenta", "#ff00ff"],
94
+ ["maroon", "#800000"],
95
+ ["mediumaquamarine", "#66cdaa"],
96
+ ["mediumblue", "#0000cd"],
97
+ ["mediumorchid", "#ba55d3"],
98
+ ["mediumpurple", "#9370db"],
99
+ ["mediumseagreen", "#3cb371"],
100
+ ["mediumslateblue", "#7b68ee"],
101
+ ["mediumspringgreen", "#00fa9a"],
102
+ ["mediumturquoise", "#48d1cc"],
103
+ ["mediumvioletred", "#c71585"],
104
+ ["midnightblue", "#191970"],
105
+ ["mintcream", "#f5fffa"],
106
+ ["mistyrose", "#ffe4e1"],
107
+ ["moccasin", "#ffe4b5"],
108
+ ["navajowhite", "#ffdead"],
109
+ ["navy", "#000080"],
110
+ ["oldlace", "#fdf5e6"],
111
+ ["olive", "#808000"],
112
+ ["olivedrab", "#6b8e23"],
113
+ ["orange", "#ffa500"],
114
+ ["orangered", "#ff4500"],
115
+ ["orchid", "#da70d6"],
116
+ ["palegoldenrod", "#eee8aa"],
117
+ ["palegreen", "#98fb98"],
118
+ ["paleturquoise", "#afeeee"],
119
+ ["palevioletred", "#db7093"],
120
+ ["papayawhip", "#ffefd5"],
121
+ ["peachpuff", "#ffdab9"],
122
+ ["peru", "#cd853f"],
123
+ ["pink", "#ffc0cb"],
124
+ ["plum", "#dda0dd"],
125
+ ["powderblue", "#b0e0e6"],
126
+ ["purple", "#800080"],
127
+ ["rebeccapurple", "#663399"],
128
+ ["red", "#ff0000"],
129
+ ["rosybrown", "#bc8f8f"],
130
+ ["royalblue", "#4169e1"],
131
+ ["saddlebrown", "#8b4513"],
132
+ ["salmon", "#fa8072"],
133
+ ["sandybrown", "#f4a460"],
134
+ ["seagreen", "#2e8b57"],
135
+ ["seashell", "#fff5ee"],
136
+ ["sienna", "#a0522d"],
137
+ ["silver", "#c0c0c0"],
138
+ ["skyblue", "#87ceeb"],
139
+ ["slateblue", "#6a5acd"],
140
+ ["slategray", "#708090"],
141
+ ["slategrey", "#708090"],
142
+ ["snow", "#fffafa"],
143
+ ["springgreen", "#00ff7f"],
144
+ ["steelblue", "#4682b4"],
145
+ ["tan", "#d2b48c"],
146
+ ["teal", "#008080"],
147
+ ["thistle", "#d8bfd8"],
148
+ ["tomato", "#ff6347"],
149
+ ["turquoise", "#40e0d0"],
150
+ ["violet", "#ee82ee"],
151
+ ["wheat", "#f5deb3"],
152
+ ["white", "#ffffff"],
153
+ ["whitesmoke", "#f5f5f5"],
154
+ ["yellow", "#ffff00"],
155
+ ["yellowgreen", "#9acd32"]
156
+ ]);
157
+ const HASH_PATTERN = /^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i;
158
+ const SMALL_HASH_PATTERN = /^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i;
159
+ const RGB_PATTERN = (
160
+ // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-unused-capturing-group
161
+ /^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/
162
+ );
163
+ const HSL_PATTERN = (
164
+ // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-unused-capturing-group
165
+ /^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/
166
+ );
167
+ const getDefaultCss = /* @__PURE__ */ __name$1(() => {
168
+ return {
169
+ __proto__: null,
170
+ backgroundColor: null,
171
+ color: null,
172
+ fontStyle: null,
173
+ fontWeight: null,
174
+ textDecorationColor: null,
175
+ textDecorationLine: []
176
+ };
177
+ }, "getDefaultCss");
178
+ const SPACE_PATTERN = /\s+/g;
179
+ const parseCssColor = /* @__PURE__ */ __name$1((colorString) => {
180
+ if (colorKeywords.has(colorString)) {
181
+ colorString = colorKeywords.get(colorString);
182
+ }
183
+ const hashMatch = HASH_PATTERN.exec(colorString);
184
+ if (hashMatch) {
185
+ return [Number.parseInt(hashMatch[1], 16), Number.parseInt(hashMatch[2], 16), Number.parseInt(hashMatch[3], 16)];
186
+ }
187
+ const smallHashMatch = SMALL_HASH_PATTERN.exec(colorString);
188
+ if (smallHashMatch) {
189
+ return [
190
+ Number.parseInt(`${smallHashMatch[1]}${smallHashMatch[1]}`, 16),
191
+ Number.parseInt(`${smallHashMatch[2]}${smallHashMatch[2]}`, 16),
192
+ Number.parseInt(`${smallHashMatch[3]}${smallHashMatch[3]}`, 16)
193
+ ];
194
+ }
195
+ const rgbMatch = RGB_PATTERN.exec(colorString);
196
+ if (rgbMatch) {
197
+ return [
198
+ Math.round(Math.max(0, Math.min(255, Number(rgbMatch[1])))),
199
+ Math.round(Math.max(0, Math.min(255, Number(rgbMatch[2])))),
200
+ Math.round(Math.max(0, Math.min(255, Number(rgbMatch[3]))))
201
+ ];
202
+ }
203
+ const hslMatch = HSL_PATTERN.exec(colorString);
204
+ if (hslMatch) {
205
+ let h = Number(hslMatch[1]) % 360;
206
+ if (h < 0) {
207
+ h += 360;
208
+ }
209
+ const s = Math.max(0, Math.min(100, Number(hslMatch[2]))) / 100;
210
+ const l = Math.max(0, Math.min(100, Number(hslMatch[3]))) / 100;
211
+ const c = (1 - Math.abs(2 * l - 1)) * s;
212
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
213
+ const m = l - c / 2;
214
+ let r_;
215
+ let g_;
216
+ let b_;
217
+ if (h < 60) {
218
+ ({ 0: r_, 1: g_, 2: b_ } = [c, x, 0]);
219
+ } else if (h < 120) {
220
+ ({ 0: r_, 1: g_, 2: b_ } = [x, c, 0]);
221
+ } else if (h < 180) {
222
+ ({ 0: r_, 1: g_, 2: b_ } = [0, c, x]);
223
+ } else if (h < 240) {
224
+ ({ 0: r_, 1: g_, 2: b_ } = [0, x, c]);
225
+ } else if (h < 300) {
226
+ ({ 0: r_, 1: g_, 2: b_ } = [x, 0, c]);
227
+ } else {
228
+ ({ 0: r_, 1: g_, 2: b_ } = [c, 0, x]);
229
+ }
230
+ return [Math.round((r_ + m) * 255), Math.round((g_ + m) * 255), Math.round((b_ + m) * 255)];
231
+ }
232
+ return null;
233
+ }, "parseCssColor");
234
+ const colorEquals = /* @__PURE__ */ __name$1((color1, color2) => color1?.[0] === color2?.[0] && color1?.[1] === color2?.[1] && color1?.[2] === color2?.[2], "colorEquals");
235
+ const parseCss = /* @__PURE__ */ __name$1((cssString) => {
236
+ const css = getDefaultCss();
237
+ const rawEntries = [];
238
+ let inValue = false;
239
+ let currentKey = null;
240
+ let parenthesesDepth = 0;
241
+ let currentPart = "";
242
+ for (const c of cssString) {
243
+ if (c === "(") {
244
+ parenthesesDepth++;
245
+ } else if (parenthesesDepth > 0) {
246
+ if (c === ")") {
247
+ parenthesesDepth--;
248
+ }
249
+ } else if (inValue) {
250
+ if (c === ";") {
251
+ const value = currentPart.trim();
252
+ if (value !== "") {
253
+ rawEntries.push([currentKey, value]);
254
+ }
255
+ currentKey = null;
256
+ currentPart = "";
257
+ inValue = false;
258
+ continue;
259
+ }
260
+ } else if (c === ":") {
261
+ currentKey = currentPart.trim();
262
+ currentPart = "";
263
+ inValue = true;
264
+ continue;
265
+ }
266
+ currentPart += c;
267
+ }
268
+ if (inValue && parenthesesDepth === 0) {
269
+ const value = currentPart.trim();
270
+ if (value !== "") {
271
+ rawEntries.push([currentKey, value]);
272
+ }
273
+ currentKey = null;
274
+ currentPart = "";
275
+ }
276
+ for (const { 0: key, 1: value } of rawEntries) {
277
+ switch (key) {
278
+ case "background-color": {
279
+ if (value != null) {
280
+ css.backgroundColor = value;
281
+ }
282
+ break;
283
+ }
284
+ case "color": {
285
+ if (value != null) {
286
+ css.color = value;
287
+ }
288
+ break;
289
+ }
290
+ case "font-weight": {
291
+ if (value === "bold") {
292
+ css.fontWeight = value;
293
+ }
294
+ break;
295
+ }
296
+ case "font-style": {
297
+ if (["italic", "oblique", "oblique 14deg"].includes(value)) {
298
+ css.fontStyle = "italic";
299
+ }
300
+ break;
301
+ }
302
+ case "text-decoration-line": {
303
+ css.textDecorationLine = [];
304
+ const lineTypes = value.split(SPACE_PATTERN);
305
+ for (const lineType of lineTypes) {
306
+ if (["line-through", "overline", "underline"].includes(lineType)) {
307
+ css.textDecorationLine.push(lineType);
308
+ }
309
+ }
310
+ break;
311
+ }
312
+ case "text-decoration-color": {
313
+ const color = parseCssColor(value);
314
+ if (color != null) {
315
+ css.textDecorationColor = color;
316
+ }
317
+ break;
318
+ }
319
+ case "text-decoration": {
320
+ css.textDecorationColor = null;
321
+ css.textDecorationLine = [];
322
+ const arguments_ = value.split(SPACE_PATTERN);
323
+ for (const argument of arguments_) {
324
+ const maybeColor = parseCssColor(argument);
325
+ if (maybeColor != null) {
326
+ css.textDecorationColor = maybeColor;
327
+ } else if (["line-through", "overline", "underline"].includes(argument)) {
328
+ css.textDecorationLine.push(argument);
329
+ }
330
+ }
331
+ break;
332
+ }
333
+ }
334
+ }
335
+ return css;
336
+ }, "parseCss");
337
+ const cssToAnsi = /* @__PURE__ */ __name$1((css, previousCss = null) => {
338
+ previousCss = previousCss ?? getDefaultCss();
339
+ let ansi = "";
340
+ if (!colorEquals(css.backgroundColor, previousCss.backgroundColor)) {
341
+ if (css.backgroundColor == null) {
342
+ ansi += "\x1B[49m";
343
+ } else
344
+ switch (css.backgroundColor) {
345
+ case "black": {
346
+ ansi += "\x1B[40m";
347
+ break;
348
+ }
349
+ case "red": {
350
+ ansi += "\x1B[41m";
351
+ break;
352
+ }
353
+ case "green": {
354
+ ansi += "\x1B[42m";
355
+ break;
356
+ }
357
+ case "yellow": {
358
+ ansi += "\x1B[43m";
359
+ break;
360
+ }
361
+ case "blue": {
362
+ ansi += "\x1B[44m";
363
+ break;
364
+ }
365
+ case "magenta": {
366
+ ansi += "\x1B[45m";
367
+ break;
368
+ }
369
+ case "cyan": {
370
+ ansi += "\x1B[46m";
371
+ break;
372
+ }
373
+ case "white": {
374
+ ansi += "\x1B[47m";
375
+ break;
376
+ }
377
+ default: {
378
+ if (Array.isArray(css.backgroundColor)) {
379
+ const { 0: r, 1: g, 2: b } = css.backgroundColor;
380
+ ansi += `\x1B[48;2;${r};${g};${b}m`;
381
+ } else {
382
+ const parsed = parseCssColor(css.backgroundColor);
383
+ if (parsed === null) {
384
+ ansi += "\x1B[49m";
385
+ } else {
386
+ const { 0: r, 1: g, 2: b } = parsed;
387
+ ansi += `\x1B[48;2;${r};${g};${b}m`;
388
+ }
389
+ }
390
+ }
391
+ }
392
+ }
393
+ if (!colorEquals(css.color, previousCss.color)) {
394
+ if (css.color == null) {
395
+ ansi += "\x1B[39m";
396
+ } else
397
+ switch (css.color) {
398
+ case "black": {
399
+ ansi += "\x1B[30m";
400
+ break;
401
+ }
402
+ case "red": {
403
+ ansi += "\x1B[31m";
404
+ break;
405
+ }
406
+ case "green": {
407
+ ansi += "\x1B[32m";
408
+ break;
409
+ }
410
+ case "yellow": {
411
+ ansi += "\x1B[33m";
412
+ break;
413
+ }
414
+ case "blue": {
415
+ ansi += "\x1B[34m";
416
+ break;
417
+ }
418
+ case "magenta": {
419
+ ansi += "\x1B[35m";
420
+ break;
421
+ }
422
+ case "cyan": {
423
+ ansi += "\x1B[36m";
424
+ break;
425
+ }
426
+ case "white": {
427
+ ansi += "\x1B[37m";
428
+ break;
429
+ }
430
+ default: {
431
+ if (Array.isArray(css.color)) {
432
+ const { 0: r, 1: g, 2: b } = css.color;
433
+ ansi += `\x1B[38;2;${r};${g};${b}m`;
434
+ } else {
435
+ const parsed = parseCssColor(css.color);
436
+ if (parsed === null) {
437
+ ansi += "\x1B[39m";
438
+ } else {
439
+ const { 0: r, 1: g, 2: b } = parsed;
440
+ ansi += `\x1B[38;2;${r};${g};${b}m`;
441
+ }
442
+ }
443
+ }
444
+ }
445
+ }
446
+ if (css.fontWeight !== previousCss.fontWeight) {
447
+ ansi += css.fontWeight === "bold" ? "\x1B[1m" : "\x1B[22m";
448
+ }
449
+ if (css.fontStyle !== previousCss.fontStyle) {
450
+ ansi += css.fontStyle === "italic" ? "\x1B[3m" : "\x1B[23m";
451
+ }
452
+ if (!colorEquals(css.textDecorationColor, previousCss.textDecorationColor)) {
453
+ if (css.textDecorationColor == null) {
454
+ ansi += "\x1B[59m";
455
+ } else {
456
+ const { 0: r, 1: g, 2: b } = css.textDecorationColor;
457
+ ansi += `\x1B[58;2;${r};${g};${b}m`;
458
+ }
459
+ }
460
+ if (css.textDecorationLine.includes("line-through") !== previousCss.textDecorationLine.includes("line-through")) {
461
+ ansi += css.textDecorationLine.includes("line-through") ? "\x1B[9m" : "\x1B[29m";
462
+ }
463
+ if (css.textDecorationLine.includes("overline") !== previousCss.textDecorationLine.includes("overline")) {
464
+ ansi += css.textDecorationLine.includes("overline") ? "\x1B[53m" : "\x1B[55m";
465
+ }
466
+ if (css.textDecorationLine.includes("underline") !== previousCss.textDecorationLine.includes("underline")) {
467
+ ansi += css.textDecorationLine.includes("underline") ? "\x1B[4m" : "\x1B[24m";
468
+ }
469
+ return ansi;
470
+ }, "cssToAnsi");
471
+
472
+ var __defProp = Object.defineProperty;
473
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
474
+ const tryStringify = /* @__PURE__ */ __name((o) => {
475
+ try {
476
+ return JSON.stringify(o);
477
+ } catch {
478
+ return '"[Circular]"';
479
+ }
480
+ }, "tryStringify");
481
+ const CHAR_PERCENT = "%".codePointAt(0);
482
+ const CHAR_s = "s".codePointAt(0);
483
+ const CHAR_d = "d".codePointAt(0);
484
+ const CHAR_f = "f".codePointAt(0);
485
+ const CHAR_i = "i".codePointAt(0);
486
+ const CHAR_O = "O".codePointAt(0);
487
+ const CHAR_o = "o".codePointAt(0);
488
+ const CHAR_j = "j".codePointAt(0);
489
+ const CHAR_c = "c".codePointAt(0);
490
+ const format = /* @__PURE__ */ __name((fmt, arguments_ = [], options = {}) => {
491
+ if (typeof fmt !== "string" && typeof fmt !== "object" || fmt === null) {
492
+ throw new TypeError(`fmt must be a string or object, got ${fmt === null ? "null" : typeof fmt}`);
493
+ }
494
+ const stringify = options.stringify ?? tryStringify;
495
+ const offset = 1;
496
+ if (typeof fmt === "object") {
497
+ const argumentsLength = arguments_.length + offset;
498
+ if (argumentsLength === 1) {
499
+ return "{}";
500
+ }
501
+ const objects = Array.from({ length: argumentsLength });
502
+ objects[0] = stringify(fmt);
503
+ for (let index = 1; index < argumentsLength; index++) {
504
+ objects[index] = stringify(arguments_[index - offset]);
505
+ }
506
+ return objects.join(" ");
507
+ }
508
+ if (arguments_.length === 0) {
509
+ return fmt;
510
+ }
511
+ let result = "";
512
+ let a = 1 - offset;
513
+ let lastPosition = -1;
514
+ let usedStyle = false;
515
+ let previousCss = null;
516
+ for (let index = 0; index < fmt.length; ) {
517
+ if (fmt.codePointAt(index) === CHAR_PERCENT && index + 1 < fmt.length) {
518
+ lastPosition = lastPosition > -1 ? lastPosition : 0;
519
+ const c = fmt.codePointAt(index + 1);
520
+ if (c === undefined) {
521
+ ++a;
522
+ break;
523
+ }
524
+ switch (c) {
525
+ case CHAR_d:
526
+ case CHAR_f: {
527
+ if (a >= arguments_.length || arguments_[a] == null) {
528
+ break;
529
+ }
530
+ if (lastPosition < index) {
531
+ result += fmt.slice(lastPosition, index);
532
+ }
533
+ result += Number(arguments_[a]).toString();
534
+ lastPosition = index + 2;
535
+ index++;
536
+ break;
537
+ }
538
+ case CHAR_i: {
539
+ if (a >= arguments_.length || arguments_[a] == null) {
540
+ break;
541
+ }
542
+ if (lastPosition < index) {
543
+ result += fmt.slice(lastPosition, index);
544
+ }
545
+ result += Math.floor(Number(arguments_[a])).toString();
546
+ lastPosition = index + 2;
547
+ index++;
548
+ break;
549
+ }
550
+ case CHAR_O:
551
+ case CHAR_o:
552
+ case CHAR_j: {
553
+ if (a >= arguments_.length || arguments_[a] === undefined) {
554
+ break;
555
+ }
556
+ if (lastPosition < index) {
557
+ result += fmt.slice(lastPosition, index);
558
+ }
559
+ const temporaryArgument = arguments_[a];
560
+ const type = typeof temporaryArgument;
561
+ if (type === "string") {
562
+ result += `'${temporaryArgument}'`;
563
+ lastPosition = index + 2;
564
+ break;
565
+ }
566
+ if (type === "function") {
567
+ result += temporaryArgument.name ? `[Function: ${temporaryArgument.name}]` : "[Function: <anonymous>]";
568
+ lastPosition = index + 2;
569
+ break;
570
+ }
571
+ result += stringify(temporaryArgument);
572
+ lastPosition = index + 2;
573
+ index++;
574
+ break;
575
+ }
576
+ case CHAR_s: {
577
+ if (a >= arguments_.length) {
578
+ break;
579
+ }
580
+ if (lastPosition < index) {
581
+ result += fmt.slice(lastPosition, index);
582
+ }
583
+ result += typeof arguments_[a] === "object" ? stringify(arguments_[a]) : String(arguments_[a]);
584
+ lastPosition = index + 2;
585
+ index++;
586
+ break;
587
+ }
588
+ case CHAR_PERCENT: {
589
+ if (lastPosition < index) {
590
+ result += fmt.slice(lastPosition, index);
591
+ }
592
+ result += "%";
593
+ lastPosition = index + 2;
594
+ index++;
595
+ a--;
596
+ break;
597
+ }
598
+ case CHAR_c: {
599
+ if (typeof window === "undefined") {
600
+ const css = parseCss(arguments_[a]);
601
+ if (lastPosition < index) {
602
+ result += fmt.slice(lastPosition, index);
603
+ }
604
+ result += cssToAnsi(css, previousCss);
605
+ if (result !== "") {
606
+ usedStyle = true;
607
+ previousCss = css;
608
+ }
609
+ }
610
+ lastPosition = index + 2;
611
+ index++;
612
+ break;
613
+ }
614
+ default: {
615
+ if (typeof options.formatters?.[c] === "function") {
616
+ if (lastPosition < index) {
617
+ result += fmt.slice(lastPosition, index);
618
+ }
619
+ result += options.formatters[c](arguments_[a]);
620
+ lastPosition = index + 2;
621
+ index++;
622
+ }
623
+ }
624
+ }
625
+ ++a;
626
+ }
627
+ ++index;
628
+ }
629
+ if (lastPosition === -1) {
630
+ return fmt;
631
+ }
632
+ if (lastPosition < fmt.length) {
633
+ result += fmt.slice(lastPosition);
634
+ }
635
+ if (usedStyle) {
636
+ result += "\x1B[0m";
637
+ }
638
+ return result;
639
+ }, "format");
640
+ const build = /* @__PURE__ */ __name((options = {}) => {
641
+ const formatters = {};
642
+ if (typeof options.formatters === "object") {
643
+ Object.entries(options.formatters).forEach(([key, formatterFunction]) => {
644
+ if (key.length === 0) {
645
+ throw new Error(`Formatter %${key} has no characters`);
646
+ }
647
+ if (key.length > 1) {
648
+ throw new Error(`Formatter %${key} has more than one character`);
649
+ }
650
+ if (typeof formatterFunction !== "function") {
651
+ throw new TypeError(`Formatter for %${key} is not a function`);
652
+ }
653
+ const c = key.codePointAt(0);
654
+ if (c === undefined) {
655
+ throw new Error(`${key}.codePointAt(0) failed to return a value, please report this issue`);
656
+ }
657
+ formatters[c] = formatterFunction;
658
+ });
659
+ }
660
+ return (f, arguments_ = [], formatOptions = {}) => format(f, arguments_, { ...formatOptions, formatters });
661
+ }, "build");
662
+
663
+ exports.build = build;
664
+ exports.format = format;