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