ansimax 1.3.3 → 1.3.5
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 +279 -0
- package/README.es.md +61 -3
- package/README.md +61 -3
- package/dist/index.d.mts +556 -225
- package/dist/index.d.ts +556 -225
- package/dist/index.js +478 -51
- package/dist/index.mjs +460 -51
- package/examples/all-in-one.cjs +1 -1
- package/examples/all-in-one.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -60,8 +60,10 @@ __export(index_exports, {
|
|
|
60
60
|
chain: () => chain,
|
|
61
61
|
charWidth: () => charWidth,
|
|
62
62
|
clamp: () => clamp,
|
|
63
|
+
clampByte: () => clampByte2,
|
|
63
64
|
clearAnsiCache: () => clearAnsiCache,
|
|
64
65
|
clearColorCache: () => clearColorCache,
|
|
66
|
+
clearLine: () => clearLine,
|
|
65
67
|
clearRenderCache: () => clearRenderCache,
|
|
66
68
|
clearThemeColorCache: () => clearThemeColorCache,
|
|
67
69
|
color: () => color,
|
|
@@ -79,6 +81,8 @@ __export(index_exports, {
|
|
|
79
81
|
debounce: () => debounce,
|
|
80
82
|
default: () => index_default,
|
|
81
83
|
diffLines: () => diffLines,
|
|
84
|
+
easings: () => easings,
|
|
85
|
+
escapeForRegex: () => escapeForRegex,
|
|
82
86
|
escapeRegex: () => escapeRegex,
|
|
83
87
|
fg256: () => fg256,
|
|
84
88
|
fgRgb: () => fgRgb,
|
|
@@ -99,13 +103,17 @@ __export(index_exports, {
|
|
|
99
103
|
gradient: () => gradient,
|
|
100
104
|
gradientColor: () => gradientColor,
|
|
101
105
|
gradientRect: () => gradientRect,
|
|
106
|
+
gradientStops: () => gradientStops,
|
|
102
107
|
graphemes: () => graphemes,
|
|
103
108
|
grid: () => grid,
|
|
104
109
|
hasFont: () => hasFont,
|
|
105
110
|
hexToRgb: () => hexToRgb,
|
|
106
111
|
hideCursor: () => hideCursor,
|
|
112
|
+
hslToRgb: () => hslToRgb,
|
|
107
113
|
hsplit: () => hsplit,
|
|
114
|
+
hyperlink: () => hyperlink,
|
|
108
115
|
images: () => images,
|
|
116
|
+
isFiniteNumber: () => isFiniteNumber2,
|
|
109
117
|
isHexColor: () => isHexColor,
|
|
110
118
|
isNoColor: () => isNoColor,
|
|
111
119
|
json: () => json,
|
|
@@ -117,9 +125,12 @@ __export(index_exports, {
|
|
|
117
125
|
listPresets: () => listPresets,
|
|
118
126
|
loader: () => loader,
|
|
119
127
|
mapTree: () => mapTree,
|
|
128
|
+
measureBlock: () => measureBlock,
|
|
120
129
|
measureTree: () => measureTree,
|
|
121
130
|
memoize: () => memoize,
|
|
131
|
+
mixColors: () => mixColors,
|
|
122
132
|
nextTick: () => nextTick,
|
|
133
|
+
oklabToRgb: () => oklabToRgb,
|
|
123
134
|
onConfigChange: () => onConfigChange,
|
|
124
135
|
onConfigKeyChange: () => onConfigKeyChange,
|
|
125
136
|
onResize: () => onResize,
|
|
@@ -132,6 +143,7 @@ __export(index_exports, {
|
|
|
132
143
|
pauseListeners: () => pauseListeners,
|
|
133
144
|
presetNames: () => presetNames,
|
|
134
145
|
presets: () => presets,
|
|
146
|
+
quantizeColor: () => quantizeColor,
|
|
135
147
|
rainbow: () => rainbow,
|
|
136
148
|
registerFont: () => registerFont,
|
|
137
149
|
registerPreset: () => registerPreset,
|
|
@@ -147,13 +159,18 @@ __export(index_exports, {
|
|
|
147
159
|
resetFramesCursorCount: () => resetFramesCursorCount,
|
|
148
160
|
resetLoaderCursorCount: () => resetLoaderCursorCount,
|
|
149
161
|
resetNoColor: () => resetNoColor,
|
|
162
|
+
resolveEasingByName: () => resolveEasingByName,
|
|
150
163
|
resumeListeners: () => resumeListeners,
|
|
151
164
|
reverseGradient: () => reverseGradient,
|
|
152
165
|
rgbTo256: () => rgbTo256,
|
|
153
166
|
rgbToHex: () => rgbToHex,
|
|
167
|
+
rgbToHsl: () => rgbToHsl,
|
|
168
|
+
rgbToOklab: () => rgbToOklab,
|
|
154
169
|
rotate90: () => rotate90,
|
|
170
|
+
safeInt: () => safeInt,
|
|
155
171
|
safeJson: () => safeJson,
|
|
156
172
|
screen: () => screen,
|
|
173
|
+
setConfigValue: () => setConfigValue,
|
|
157
174
|
setNoColor: () => setNoColor,
|
|
158
175
|
setTitle: () => setTitle,
|
|
159
176
|
sgr: () => sgr,
|
|
@@ -164,6 +181,7 @@ __export(index_exports, {
|
|
|
164
181
|
stripAnsi: () => stripAnsi2,
|
|
165
182
|
stripAnsiCodes: () => stripAnsi,
|
|
166
183
|
stripAnsiColors: () => stripAnsi3,
|
|
184
|
+
subscribeConfig: () => subscribeConfig,
|
|
167
185
|
supportsColor: () => supportsColor,
|
|
168
186
|
supportsColorLevel: () => supportsColorLevel,
|
|
169
187
|
termSize: () => termSize,
|
|
@@ -567,8 +585,26 @@ var sleepFrame = (ms = FRAME_MS, opts = {}) => sleep(
|
|
|
567
585
|
Math.max(FRAME_MS, Math.round((isFiniteNumber(ms) ? ms : FRAME_MS) / FRAME_MS) * FRAME_MS),
|
|
568
586
|
opts
|
|
569
587
|
);
|
|
588
|
+
var hyperlink = (url, label) => {
|
|
589
|
+
if (typeof url !== "string" || url.length === 0) {
|
|
590
|
+
return typeof label === "string" ? label : "";
|
|
591
|
+
}
|
|
592
|
+
const safeLabel = typeof label === "string" && label.length > 0 ? label : url;
|
|
593
|
+
return `${OSC}8;;${url}${ST}${safeLabel}${OSC}8;;${ST}`;
|
|
594
|
+
};
|
|
595
|
+
var clearLine = () => `${CSI}2K\r`;
|
|
570
596
|
|
|
571
597
|
// src/utils/helpers.ts
|
|
598
|
+
var isFiniteNumber2 = (n) => typeof n === "number" && Number.isFinite(n);
|
|
599
|
+
var safeInt = (value, fallback = 0, min = -Infinity, max = Infinity) => {
|
|
600
|
+
const isRealNumeric = typeof value === "number" || typeof value === "string" && value.trim().length > 0 && Number.isFinite(Number(value));
|
|
601
|
+
if (!isRealNumeric) {
|
|
602
|
+
return Math.max(min, Math.min(max, Math.floor(fallback)));
|
|
603
|
+
}
|
|
604
|
+
const n = Number(value);
|
|
605
|
+
if (!Number.isFinite(n)) return Math.max(min, Math.min(max, Math.floor(fallback)));
|
|
606
|
+
return Math.max(min, Math.min(max, Math.floor(n)));
|
|
607
|
+
};
|
|
572
608
|
var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
573
609
|
var lerp = (a, b, t) => a + (b - a) * t;
|
|
574
610
|
var clampByte2 = (v) => clamp(Math.round(v), 0, 255);
|
|
@@ -584,25 +620,148 @@ var hexToRgb = (hex) => {
|
|
|
584
620
|
return { r: int >> 16 & 255, g: int >> 8 & 255, b: int & 255 };
|
|
585
621
|
};
|
|
586
622
|
var rgbToHex = (r, g, b) => "#" + [clampByte2(r), clampByte2(g), clampByte2(b)].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
587
|
-
var
|
|
623
|
+
var rgbToHsl = (rgb) => {
|
|
624
|
+
const r = clamp(rgb.r, 0, 255) / 255;
|
|
625
|
+
const g = clamp(rgb.g, 0, 255) / 255;
|
|
626
|
+
const b = clamp(rgb.b, 0, 255) / 255;
|
|
627
|
+
const max = Math.max(r, g, b);
|
|
628
|
+
const min = Math.min(r, g, b);
|
|
629
|
+
const l = (max + min) / 2;
|
|
630
|
+
if (max === min) {
|
|
631
|
+
return { h: 0, s: 0, l };
|
|
632
|
+
}
|
|
633
|
+
const d = max - min;
|
|
634
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
635
|
+
let h;
|
|
636
|
+
if (max === r) {
|
|
637
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) * 60;
|
|
638
|
+
} else if (max === g) {
|
|
639
|
+
h = ((b - r) / d + 2) * 60;
|
|
640
|
+
} else {
|
|
641
|
+
h = ((r - g) / d + 4) * 60;
|
|
642
|
+
}
|
|
643
|
+
return { h, s, l };
|
|
644
|
+
};
|
|
645
|
+
var hslToRgb = (hsl) => {
|
|
646
|
+
const h = (hsl.h % 360 + 360) % 360 / 360;
|
|
647
|
+
const s = clamp(hsl.s, 0, 1);
|
|
648
|
+
const l = clamp(hsl.l, 0, 1);
|
|
649
|
+
if (s === 0) {
|
|
650
|
+
const v = Math.round(l * 255);
|
|
651
|
+
return { r: v, g: v, b: v };
|
|
652
|
+
}
|
|
653
|
+
const hue2rgb = (p2, q2, t) => {
|
|
654
|
+
let tt = t;
|
|
655
|
+
if (tt < 0) tt += 1;
|
|
656
|
+
if (tt > 1) tt -= 1;
|
|
657
|
+
if (tt < 1 / 6) return p2 + (q2 - p2) * 6 * tt;
|
|
658
|
+
if (tt < 1 / 2) return q2;
|
|
659
|
+
if (tt < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - tt) * 6;
|
|
660
|
+
return p2;
|
|
661
|
+
};
|
|
662
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
663
|
+
const p = 2 * l - q;
|
|
664
|
+
return {
|
|
665
|
+
r: Math.round(hue2rgb(p, q, h + 1 / 3) * 255),
|
|
666
|
+
g: Math.round(hue2rgb(p, q, h) * 255),
|
|
667
|
+
b: Math.round(hue2rgb(p, q, h - 1 / 3) * 255)
|
|
668
|
+
};
|
|
669
|
+
};
|
|
670
|
+
var _srgbToLinear = (c) => {
|
|
671
|
+
const x = c / 255;
|
|
672
|
+
return x <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
|
673
|
+
};
|
|
674
|
+
var _linearToSrgb = (c) => {
|
|
675
|
+
const x = c <= 31308e-7 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
676
|
+
return clampByte2(x * 255);
|
|
677
|
+
};
|
|
678
|
+
var rgbToOklab = (rgb) => {
|
|
679
|
+
const r = _srgbToLinear(rgb.r);
|
|
680
|
+
const g = _srgbToLinear(rgb.g);
|
|
681
|
+
const b = _srgbToLinear(rgb.b);
|
|
682
|
+
const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
|
|
683
|
+
const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
|
|
684
|
+
const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
|
|
685
|
+
const l_ = Math.cbrt(l);
|
|
686
|
+
const m_ = Math.cbrt(m);
|
|
687
|
+
const s_ = Math.cbrt(s);
|
|
688
|
+
return {
|
|
689
|
+
L: 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_,
|
|
690
|
+
a: 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_,
|
|
691
|
+
b: 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_
|
|
692
|
+
};
|
|
693
|
+
};
|
|
694
|
+
var oklabToRgb = (oklab) => {
|
|
695
|
+
const l_ = oklab.L + 0.3963377774 * oklab.a + 0.2158037573 * oklab.b;
|
|
696
|
+
const m_ = oklab.L - 0.1055613458 * oklab.a - 0.0638541728 * oklab.b;
|
|
697
|
+
const s_ = oklab.L - 0.0894841775 * oklab.a - 1.291485548 * oklab.b;
|
|
698
|
+
const l = l_ * l_ * l_;
|
|
699
|
+
const m = m_ * m_ * m_;
|
|
700
|
+
const s = s_ * s_ * s_;
|
|
701
|
+
const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
|
|
702
|
+
const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
|
|
703
|
+
const b = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s;
|
|
704
|
+
return {
|
|
705
|
+
r: _linearToSrgb(r),
|
|
706
|
+
g: _linearToSrgb(g),
|
|
707
|
+
b: _linearToSrgb(b)
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
var lerpColor = (a, b, t, space = "rgb") => {
|
|
588
711
|
const ct = clamp(t, 0, 1);
|
|
712
|
+
if (space === "oklab") {
|
|
713
|
+
const la = rgbToOklab(a);
|
|
714
|
+
const lb = rgbToOklab(b);
|
|
715
|
+
return oklabToRgb({
|
|
716
|
+
L: lerp(la.L, lb.L, ct),
|
|
717
|
+
a: lerp(la.a, lb.a, ct),
|
|
718
|
+
b: lerp(la.b, lb.b, ct)
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
if (space === "hsl") {
|
|
722
|
+
const ha = rgbToHsl(a);
|
|
723
|
+
const hb = rgbToHsl(b);
|
|
724
|
+
let dh = hb.h - ha.h;
|
|
725
|
+
if (dh > 180) dh -= 360;
|
|
726
|
+
else if (dh < -180) dh += 360;
|
|
727
|
+
const h = ha.h + dh * ct;
|
|
728
|
+
return hslToRgb({
|
|
729
|
+
h,
|
|
730
|
+
s: lerp(ha.s, hb.s, ct),
|
|
731
|
+
l: lerp(ha.l, hb.l, ct)
|
|
732
|
+
});
|
|
733
|
+
}
|
|
589
734
|
return {
|
|
590
735
|
r: Math.round(lerp(a.r, b.r, ct)),
|
|
591
736
|
g: Math.round(lerp(a.g, b.g, ct)),
|
|
592
737
|
b: Math.round(lerp(a.b, b.b, ct))
|
|
593
738
|
};
|
|
594
739
|
};
|
|
595
|
-
var
|
|
740
|
+
var mixColors = (a, b, t, space = "rgb") => {
|
|
741
|
+
const ra = typeof a === "string" ? hexToRgb(a) : a;
|
|
742
|
+
const rb = typeof b === "string" ? hexToRgb(b) : b;
|
|
743
|
+
return lerpColor(ra, rb, t, space);
|
|
744
|
+
};
|
|
745
|
+
var quantizeColor = (color2, levels = 4) => {
|
|
746
|
+
const safeLevels = Math.max(2, Math.floor(levels));
|
|
747
|
+
const step = 255 / (safeLevels - 1);
|
|
748
|
+
return {
|
|
749
|
+
r: Math.round(clampByte2(color2.r) / step) * step | 0,
|
|
750
|
+
g: Math.round(clampByte2(color2.g) / step) * step | 0,
|
|
751
|
+
b: Math.round(clampByte2(color2.b) / step) * step | 0
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
var gradientColor = (colors, t, space = "rgb") => {
|
|
596
755
|
if (!Array.isArray(colors) || colors.length === 0) {
|
|
597
756
|
throw new Error("gradientColor requires at least one color stop");
|
|
598
757
|
}
|
|
599
758
|
if (colors.length === 1) return colors[0];
|
|
600
|
-
const safeT =
|
|
759
|
+
const safeT = isFiniteNumber2(t) ? t : 0;
|
|
601
760
|
const ct = clamp(safeT, 0, 1);
|
|
602
761
|
const scaled = ct * (colors.length - 1);
|
|
603
762
|
const lo = Math.floor(scaled);
|
|
604
763
|
const hi = Math.min(lo + 1, colors.length - 1);
|
|
605
|
-
return lerpColor(colors[lo], colors[hi], scaled - lo);
|
|
764
|
+
return lerpColor(colors[lo], colors[hi], scaled - lo, space);
|
|
606
765
|
};
|
|
607
766
|
var rgbTo256 = (r, g, b) => {
|
|
608
767
|
const cr = clampByte2(r), cg = clampByte2(g), cb = clampByte2(b);
|
|
@@ -989,6 +1148,35 @@ var padBoth = (str, width, ch = " ") => {
|
|
|
989
1148
|
const r = pad - l;
|
|
990
1149
|
return ch.repeat(l) + str + ch.repeat(r);
|
|
991
1150
|
};
|
|
1151
|
+
var gradientStops = (start, end, count, space = "rgb") => {
|
|
1152
|
+
const safeCount = Math.max(2, Math.floor(Number.isFinite(count) ? count : 2));
|
|
1153
|
+
if (!isHexColor(start) || !isHexColor(end)) return [];
|
|
1154
|
+
const a = hexToRgb(start);
|
|
1155
|
+
const b = hexToRgb(end);
|
|
1156
|
+
const result = [];
|
|
1157
|
+
for (let i = 0; i < safeCount; i++) {
|
|
1158
|
+
const t = i / (safeCount - 1);
|
|
1159
|
+
const c = lerpColor(a, b, t, space);
|
|
1160
|
+
result.push(rgbToHex(c.r, c.g, c.b));
|
|
1161
|
+
}
|
|
1162
|
+
return result;
|
|
1163
|
+
};
|
|
1164
|
+
var escapeForRegex = (str) => {
|
|
1165
|
+
if (typeof str !== "string") return "";
|
|
1166
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1167
|
+
};
|
|
1168
|
+
var measureBlock = (block) => {
|
|
1169
|
+
if (typeof block !== "string" || block.length === 0) {
|
|
1170
|
+
return { width: 0, height: 0 };
|
|
1171
|
+
}
|
|
1172
|
+
const lines = block.split("\n");
|
|
1173
|
+
let width = 0;
|
|
1174
|
+
for (const line of lines) {
|
|
1175
|
+
const w = visibleLen(line);
|
|
1176
|
+
if (w > width) width = w;
|
|
1177
|
+
}
|
|
1178
|
+
return { width, height: lines.length };
|
|
1179
|
+
};
|
|
992
1180
|
|
|
993
1181
|
// src/colors/index.ts
|
|
994
1182
|
var _noColor = null;
|
|
@@ -1852,8 +2040,8 @@ var pulse = async (text, opts = {}) => {
|
|
|
1852
2040
|
fireDone(hooks, isAborted(signal));
|
|
1853
2041
|
return;
|
|
1854
2042
|
}
|
|
1855
|
-
const
|
|
1856
|
-
const
|
|
2043
|
+
const c12 = resolveRgb(color1);
|
|
2044
|
+
const c22 = resolveRgb(color2);
|
|
1857
2045
|
const cycles = Math.max(1, Math.round(times));
|
|
1858
2046
|
const halfInterval = Math.max(FRAME_MS, interval);
|
|
1859
2047
|
registerCrashHandlers();
|
|
@@ -1867,7 +2055,7 @@ var pulse = async (text, opts = {}) => {
|
|
|
1867
2055
|
break;
|
|
1868
2056
|
}
|
|
1869
2057
|
await safeWriteAsync(
|
|
1870
|
-
cursor.save() + fgRgb(
|
|
2058
|
+
cursor.save() + fgRgb(c12.r, c12.g, c12.b) + text + reset() + cursor.restore()
|
|
1871
2059
|
);
|
|
1872
2060
|
fireFrame(hooks, frame2++);
|
|
1873
2061
|
await sleep(halfInterval, { signal });
|
|
@@ -1876,14 +2064,14 @@ var pulse = async (text, opts = {}) => {
|
|
|
1876
2064
|
break;
|
|
1877
2065
|
}
|
|
1878
2066
|
await safeWriteAsync(
|
|
1879
|
-
cursor.save() + fgRgb(
|
|
2067
|
+
cursor.save() + fgRgb(c22.r, c22.g, c22.b) + text + reset() + cursor.restore()
|
|
1880
2068
|
);
|
|
1881
2069
|
fireFrame(hooks, frame2++);
|
|
1882
2070
|
await sleep(halfInterval, { signal });
|
|
1883
2071
|
}
|
|
1884
2072
|
if (!aborted) {
|
|
1885
2073
|
await safeWriteAsync(
|
|
1886
|
-
cursor.save() + fgRgb(
|
|
2074
|
+
cursor.save() + fgRgb(c12.r, c12.g, c12.b) + text + reset() + cursor.restore()
|
|
1887
2075
|
);
|
|
1888
2076
|
}
|
|
1889
2077
|
} finally {
|
|
@@ -2112,6 +2300,131 @@ var delay = (ms) => async (opts = {}) => {
|
|
|
2112
2300
|
} catch {
|
|
2113
2301
|
}
|
|
2114
2302
|
};
|
|
2303
|
+
var shake = async (text, opts = {}) => {
|
|
2304
|
+
const {
|
|
2305
|
+
times = 5,
|
|
2306
|
+
intensity = 2,
|
|
2307
|
+
interval = 50,
|
|
2308
|
+
newline = true,
|
|
2309
|
+
signal,
|
|
2310
|
+
reducedMotion = false,
|
|
2311
|
+
onFrame,
|
|
2312
|
+
onDone,
|
|
2313
|
+
onAbort
|
|
2314
|
+
} = opts;
|
|
2315
|
+
const hooks = { onFrame, onDone, onAbort };
|
|
2316
|
+
if (reducedMotion || isAborted(signal)) {
|
|
2317
|
+
safeWrite(text);
|
|
2318
|
+
if (newline) writeln();
|
|
2319
|
+
fireDone(hooks, isAborted(signal));
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
const safeText = typeof text === "string" ? text : "";
|
|
2323
|
+
const safeTimes = Math.max(1, Math.round(times));
|
|
2324
|
+
const safeIntensity = Math.max(1, Math.round(intensity));
|
|
2325
|
+
const safeInterval = Math.max(FRAME_MS, interval);
|
|
2326
|
+
const pattern = [0, safeIntensity, 0, -safeIntensity];
|
|
2327
|
+
registerCrashHandlers();
|
|
2328
|
+
hideCursorSafe();
|
|
2329
|
+
let aborted = false;
|
|
2330
|
+
let frame2 = 0;
|
|
2331
|
+
try {
|
|
2332
|
+
for (let cycle = 0; cycle < safeTimes; cycle++) {
|
|
2333
|
+
for (const offset of pattern) {
|
|
2334
|
+
if (isAborted(signal)) {
|
|
2335
|
+
aborted = true;
|
|
2336
|
+
break;
|
|
2337
|
+
}
|
|
2338
|
+
const prefix = offset > 0 ? " ".repeat(offset) : "";
|
|
2339
|
+
await safeWriteAsync(
|
|
2340
|
+
cursor.save() + screen.clearLine() + "\r" + prefix + safeText + cursor.restore()
|
|
2341
|
+
);
|
|
2342
|
+
fireFrame(hooks, frame2++);
|
|
2343
|
+
await sleep(safeInterval, { signal });
|
|
2344
|
+
}
|
|
2345
|
+
if (aborted) break;
|
|
2346
|
+
}
|
|
2347
|
+
if (!aborted) {
|
|
2348
|
+
await safeWriteAsync(cursor.save() + screen.clearLine() + "\r" + safeText + cursor.restore());
|
|
2349
|
+
}
|
|
2350
|
+
} finally {
|
|
2351
|
+
showCursorSafe();
|
|
2352
|
+
if (newline) writeln();
|
|
2353
|
+
fireDone(hooks, aborted);
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
var countUp = async (from, to, opts = {}) => {
|
|
2357
|
+
const {
|
|
2358
|
+
duration = 1500,
|
|
2359
|
+
steps = 60,
|
|
2360
|
+
decimals = 0,
|
|
2361
|
+
format = (n) => n.toString(),
|
|
2362
|
+
easing = (t) => t,
|
|
2363
|
+
newline = true,
|
|
2364
|
+
signal,
|
|
2365
|
+
reducedMotion = false,
|
|
2366
|
+
onFrame,
|
|
2367
|
+
onDone,
|
|
2368
|
+
onAbort
|
|
2369
|
+
} = opts;
|
|
2370
|
+
const hooks = { onFrame, onDone, onAbort };
|
|
2371
|
+
const safeFrom = Number.isFinite(from) ? from : 0;
|
|
2372
|
+
const safeTo = Number.isFinite(to) ? to : 0;
|
|
2373
|
+
const safeDecimals = Math.max(0, Math.min(20, Math.floor(decimals)));
|
|
2374
|
+
const safeFormat = typeof format === "function" ? format : (n) => n.toString();
|
|
2375
|
+
const safeEasing = typeof easing === "function" ? easing : (t) => t;
|
|
2376
|
+
if (reducedMotion || isAborted(signal)) {
|
|
2377
|
+
safeWrite(safeFormat(parseFloat(safeTo.toFixed(safeDecimals))));
|
|
2378
|
+
if (newline) writeln();
|
|
2379
|
+
fireDone(hooks, isAborted(signal));
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
const safeSteps2 = Math.max(1, Math.round(steps));
|
|
2383
|
+
const interval = Math.max(FRAME_MS, Math.round(duration / safeSteps2));
|
|
2384
|
+
registerCrashHandlers();
|
|
2385
|
+
hideCursorSafe();
|
|
2386
|
+
let aborted = false;
|
|
2387
|
+
let frame2 = 0;
|
|
2388
|
+
try {
|
|
2389
|
+
for (let i = 0; i <= safeSteps2; i++) {
|
|
2390
|
+
if (isAborted(signal)) {
|
|
2391
|
+
aborted = true;
|
|
2392
|
+
break;
|
|
2393
|
+
}
|
|
2394
|
+
const t = i / safeSteps2;
|
|
2395
|
+
const eased = safeEasing(Math.max(0, Math.min(1, t)));
|
|
2396
|
+
const current = safeFrom + (safeTo - safeFrom) * eased;
|
|
2397
|
+
const rounded = parseFloat(current.toFixed(safeDecimals));
|
|
2398
|
+
let display;
|
|
2399
|
+
try {
|
|
2400
|
+
display = safeFormat(rounded);
|
|
2401
|
+
} catch {
|
|
2402
|
+
display = String(rounded);
|
|
2403
|
+
}
|
|
2404
|
+
await safeWriteAsync(
|
|
2405
|
+
cursor.save() + screen.clearLine() + "\r" + display + cursor.restore()
|
|
2406
|
+
);
|
|
2407
|
+
fireFrame(hooks, frame2++);
|
|
2408
|
+
if (i < safeSteps2) await sleep(interval, { signal });
|
|
2409
|
+
}
|
|
2410
|
+
if (!aborted) {
|
|
2411
|
+
const final = parseFloat(safeTo.toFixed(safeDecimals));
|
|
2412
|
+
let display;
|
|
2413
|
+
try {
|
|
2414
|
+
display = safeFormat(final);
|
|
2415
|
+
} catch {
|
|
2416
|
+
display = String(final);
|
|
2417
|
+
}
|
|
2418
|
+
await safeWriteAsync(
|
|
2419
|
+
cursor.save() + screen.clearLine() + "\r" + display + cursor.restore()
|
|
2420
|
+
);
|
|
2421
|
+
}
|
|
2422
|
+
} finally {
|
|
2423
|
+
showCursorSafe();
|
|
2424
|
+
if (newline) writeln();
|
|
2425
|
+
fireDone(hooks, aborted);
|
|
2426
|
+
}
|
|
2427
|
+
};
|
|
2115
2428
|
var animate = {
|
|
2116
2429
|
typewriter,
|
|
2117
2430
|
fadeIn,
|
|
@@ -2124,7 +2437,10 @@ var animate = {
|
|
|
2124
2437
|
sequence,
|
|
2125
2438
|
chain: chain2,
|
|
2126
2439
|
parallel,
|
|
2127
|
-
delay
|
|
2440
|
+
delay,
|
|
2441
|
+
// v1.3.4
|
|
2442
|
+
shake,
|
|
2443
|
+
countUp
|
|
2128
2444
|
};
|
|
2129
2445
|
|
|
2130
2446
|
// src/ascii/index.ts
|
|
@@ -2926,14 +3242,14 @@ var ascii = {
|
|
|
2926
3242
|
|
|
2927
3243
|
// src/loaders/index.ts
|
|
2928
3244
|
var canAnimate2 = () => Boolean(process.stdout?.isTTY) && supportsColor() !== "none";
|
|
2929
|
-
var
|
|
3245
|
+
var isFiniteNumber3 = (n) => typeof n === "number" && Number.isFinite(n);
|
|
2930
3246
|
var ensureString3 = (v) => typeof v === "string" ? v : String(v ?? "");
|
|
2931
3247
|
var clampPositiveInt = (n, fallback) => {
|
|
2932
|
-
if (!
|
|
3248
|
+
if (!isFiniteNumber3(n)) return fallback;
|
|
2933
3249
|
return Math.max(1, Math.floor(n));
|
|
2934
3250
|
};
|
|
2935
3251
|
var clampPercent = (p) => {
|
|
2936
|
-
if (!
|
|
3252
|
+
if (!isFiniteNumber3(p)) return 0;
|
|
2937
3253
|
return Math.max(0, Math.min(100, p));
|
|
2938
3254
|
};
|
|
2939
3255
|
var isUnicodeCapable = () => {
|
|
@@ -3325,7 +3641,7 @@ var custom = (frames2, text = "", opts = {}) => {
|
|
|
3325
3641
|
};
|
|
3326
3642
|
var countdown = async (seconds, opts = {}) => {
|
|
3327
3643
|
const { label = "Starting in", color: hex, signal } = opts;
|
|
3328
|
-
const safeSeconds =
|
|
3644
|
+
const safeSeconds = isFiniteNumber3(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
|
|
3329
3645
|
const safeLabel = ensureString3(label);
|
|
3330
3646
|
const colorToUse = safeColor(hex) ? hex : "#ffd700";
|
|
3331
3647
|
if (!canAnimate2() || signal?.aborted) {
|
|
@@ -3532,11 +3848,11 @@ var loader = {
|
|
|
3532
3848
|
};
|
|
3533
3849
|
|
|
3534
3850
|
// src/frames/index.ts
|
|
3535
|
-
var
|
|
3851
|
+
var isFiniteNumber4 = (n) => typeof n === "number" && Number.isFinite(n);
|
|
3536
3852
|
var ensureString4 = (v) => typeof v === "string" ? v : String(v ?? "");
|
|
3537
3853
|
var MAX_FPS = 60;
|
|
3538
3854
|
var clampFps = (fps, fallback) => {
|
|
3539
|
-
if (!
|
|
3855
|
+
if (!isFiniteNumber4(fps)) return fallback;
|
|
3540
3856
|
return Math.max(1, Math.min(MAX_FPS, Math.floor(fps)));
|
|
3541
3857
|
};
|
|
3542
3858
|
var _cursorHiddenCount2 = 0;
|
|
@@ -3635,14 +3951,14 @@ var play = (frames2, opts = {}) => {
|
|
|
3635
3951
|
if (fps !== void 0) {
|
|
3636
3952
|
const safeFps = clampFps(fps, 60);
|
|
3637
3953
|
tickMs = Math.max(FRAME_MS, Math.floor(1e3 / safeFps));
|
|
3638
|
-
} else if (
|
|
3954
|
+
} else if (isFiniteNumber4(interval)) {
|
|
3639
3955
|
tickMs = Math.max(FRAME_MS, Math.floor(interval));
|
|
3640
3956
|
} else {
|
|
3641
3957
|
tickMs = 100;
|
|
3642
3958
|
}
|
|
3643
3959
|
let safeRepeat;
|
|
3644
3960
|
let infinite;
|
|
3645
|
-
if (!
|
|
3961
|
+
if (!isFiniteNumber4(repeat)) {
|
|
3646
3962
|
safeRepeat = 1;
|
|
3647
3963
|
infinite = false;
|
|
3648
3964
|
} else if (repeat === 0) {
|
|
@@ -3767,7 +4083,7 @@ var play = (frames2, opts = {}) => {
|
|
|
3767
4083
|
paused = false;
|
|
3768
4084
|
},
|
|
3769
4085
|
seek: (idx) => {
|
|
3770
|
-
if (!
|
|
4086
|
+
if (!isFiniteNumber4(idx)) return;
|
|
3771
4087
|
const safe = Math.max(0, Math.floor(idx));
|
|
3772
4088
|
frameIdx = frames2.length > 0 ? safe % frames2.length : 0;
|
|
3773
4089
|
},
|
|
@@ -3780,7 +4096,7 @@ var play = (frames2, opts = {}) => {
|
|
|
3780
4096
|
};
|
|
3781
4097
|
};
|
|
3782
4098
|
var generate = (count, fn) => {
|
|
3783
|
-
const safeCount =
|
|
4099
|
+
const safeCount = isFiniteNumber4(count) ? Math.max(0, Math.floor(count)) : 0;
|
|
3784
4100
|
if (typeof fn !== "function") return Array(safeCount).fill("");
|
|
3785
4101
|
return Array.from({ length: safeCount }, (_, i) => {
|
|
3786
4102
|
try {
|
|
@@ -3852,7 +4168,7 @@ var morph = (frameA, frameB, steps = 8, charset = "\u2591\u2592\u2593\u2588\u259
|
|
|
3852
4168
|
const a0 = ensureString4(frameA);
|
|
3853
4169
|
const b0 = ensureString4(frameB);
|
|
3854
4170
|
if (!a0 && !b0) return [""];
|
|
3855
|
-
const n = Math.max(2,
|
|
4171
|
+
const n = Math.max(2, isFiniteNumber4(steps) ? Math.floor(steps) : 8);
|
|
3856
4172
|
const len = Math.max(a0.length, b0.length);
|
|
3857
4173
|
const a = a0.padEnd(len);
|
|
3858
4174
|
const b = b0.padEnd(len);
|
|
@@ -3874,7 +4190,7 @@ var morph = (frameA, frameB, steps = 8, charset = "\u2591\u2592\u2593\u2588\u259
|
|
|
3874
4190
|
var presets2 = {
|
|
3875
4191
|
loadingBar: (opts = {}) => {
|
|
3876
4192
|
const { width = 20, char = "\u2588", empty = "\u2591", label = "Loading" } = opts;
|
|
3877
|
-
const safeWidth = Math.max(0,
|
|
4193
|
+
const safeWidth = Math.max(0, isFiniteNumber4(width) ? Math.floor(width) : 20);
|
|
3878
4194
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2588";
|
|
3879
4195
|
const safeEmpty = typeof empty === "string" && empty.length > 0 ? empty : "\u2591";
|
|
3880
4196
|
const safeLabel = ensureString4(label);
|
|
@@ -3888,7 +4204,7 @@ var presets2 = {
|
|
|
3888
4204
|
/* istanbul ignore next — default opts {} */
|
|
3889
4205
|
ball: (opts = {}) => {
|
|
3890
4206
|
const { width = 20, char = "\u25CF" } = opts;
|
|
3891
|
-
const safeWidth = Math.max(1,
|
|
4207
|
+
const safeWidth = Math.max(1, isFiniteNumber4(width) ? Math.floor(width) : 20);
|
|
3892
4208
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u25CF";
|
|
3893
4209
|
const forward = generate(safeWidth, (i) => " ".repeat(i) + safeChar);
|
|
3894
4210
|
const backward = generate(safeWidth, (i) => " ".repeat(safeWidth - i - 1) + safeChar);
|
|
@@ -3898,7 +4214,7 @@ var presets2 = {
|
|
|
3898
4214
|
breathe: (text, opts = {}) => {
|
|
3899
4215
|
const { steps = 8 } = opts;
|
|
3900
4216
|
const safeText = ensureString4(text);
|
|
3901
|
-
const safeSteps2 = Math.max(1,
|
|
4217
|
+
const safeSteps2 = Math.max(1, isFiniteNumber4(steps) ? Math.floor(steps) : 8);
|
|
3902
4218
|
const shades = ["\u2591", "\u2592", "\u2593", "\u2588"];
|
|
3903
4219
|
return generate(safeSteps2 * 2, (i) => {
|
|
3904
4220
|
const t = i < safeSteps2 ? i / safeSteps2 : 1 - (i - safeSteps2) / safeSteps2;
|
|
@@ -3919,22 +4235,22 @@ var presets2 = {
|
|
|
3919
4235
|
var frames = { play, generate, live, morph, presets: presets2 };
|
|
3920
4236
|
|
|
3921
4237
|
// src/components/index.ts
|
|
3922
|
-
var
|
|
4238
|
+
var isFiniteNumber5 = (n) => typeof n === "number" && Number.isFinite(n);
|
|
3923
4239
|
var ensureString5 = (v) => typeof v === "string" ? v : String(v ?? "");
|
|
3924
4240
|
var clampPercent2 = (p) => {
|
|
3925
|
-
if (!
|
|
4241
|
+
if (!isFiniteNumber5(p)) return 0;
|
|
3926
4242
|
return Math.max(0, Math.min(100, p));
|
|
3927
4243
|
};
|
|
3928
4244
|
var clampNonNeg = (n, fallback) => {
|
|
3929
|
-
if (!
|
|
4245
|
+
if (!isFiniteNumber5(n)) return fallback;
|
|
3930
4246
|
return Math.max(0, Math.floor(n));
|
|
3931
4247
|
};
|
|
3932
4248
|
var clampPositive2 = (n, fallback) => {
|
|
3933
|
-
if (!
|
|
4249
|
+
if (!isFiniteNumber5(n)) return fallback;
|
|
3934
4250
|
return Math.max(1, Math.floor(n));
|
|
3935
4251
|
};
|
|
3936
4252
|
var safeSgrCode = (code, fallback) => {
|
|
3937
|
-
if (!
|
|
4253
|
+
if (!isFiniteNumber5(code)) return fallback;
|
|
3938
4254
|
return Math.max(0, Math.min(255, Math.floor(code)));
|
|
3939
4255
|
};
|
|
3940
4256
|
var truncateVisible = (str, maxWidth, ellipsis = "\u2026") => {
|
|
@@ -3972,7 +4288,7 @@ var table = (rows, opts = {}) => {
|
|
|
3972
4288
|
const b = TABLE_BORDERS[borderStyle] ?? TABLE_BORDERS.rounded;
|
|
3973
4289
|
const safePadding = clampNonNeg(padding, 1);
|
|
3974
4290
|
const pad = " ".repeat(safePadding);
|
|
3975
|
-
const safeMaxCol = maxColWidth !== null &&
|
|
4291
|
+
const safeMaxCol = maxColWidth !== null && isFiniteNumber5(maxColWidth) ? Math.max(1, Math.floor(maxColWidth)) : null;
|
|
3976
4292
|
const validRows = rows.filter((r) => Array.isArray(r));
|
|
3977
4293
|
if (validRows.length === 0) return "";
|
|
3978
4294
|
const cols = Math.max(...validRows.map((r) => r.length), 0);
|
|
@@ -4053,7 +4369,7 @@ var progressBar = (percent, opts = {}) => {
|
|
|
4053
4369
|
showPercentage = true,
|
|
4054
4370
|
label = "",
|
|
4055
4371
|
color: color2 = null,
|
|
4056
|
-
gradient:
|
|
4372
|
+
gradient: gradientStops2 = null
|
|
4057
4373
|
} = opts;
|
|
4058
4374
|
const safeWidth = clampPositive2(width, 30);
|
|
4059
4375
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2588";
|
|
@@ -4063,9 +4379,9 @@ var progressBar = (percent, opts = {}) => {
|
|
|
4063
4379
|
const filled = Math.floor(clamped / 100 * safeWidth);
|
|
4064
4380
|
const empty = Math.max(0, safeWidth - filled);
|
|
4065
4381
|
let filledStr = safeChar.repeat(filled);
|
|
4066
|
-
if (Array.isArray(
|
|
4067
|
-
filledStr = gradient(filledStr,
|
|
4068
|
-
} else if (color2 !== null &&
|
|
4382
|
+
if (Array.isArray(gradientStops2) && gradientStops2.length >= 1 && filled > 0) {
|
|
4383
|
+
filledStr = gradient(filledStr, gradientStops2);
|
|
4384
|
+
} else if (color2 !== null && isFiniteNumber5(color2)) {
|
|
4069
4385
|
filledStr = sgr(safeSgrCode(color2, FG.white)) + filledStr + reset();
|
|
4070
4386
|
}
|
|
4071
4387
|
const emptyStr = safeEmpty.repeat(empty);
|
|
@@ -4101,7 +4417,7 @@ var section = (title, opts = {}) => {
|
|
|
4101
4417
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2500";
|
|
4102
4418
|
const safeColor2 = safeSgrCode(colorCode, FG.cyan);
|
|
4103
4419
|
const titleLen = visibleLen(safeTitle);
|
|
4104
|
-
const requestedWidth = width !== null &&
|
|
4420
|
+
const requestedWidth = width !== null && isFiniteNumber5(width) ? Math.max(1, Math.floor(width)) : cols;
|
|
4105
4421
|
const w = Math.max(requestedWidth, titleLen + 2);
|
|
4106
4422
|
const side = Math.floor((w - titleLen - 2) / 2);
|
|
4107
4423
|
const dividerL = sgr(safeColor2) + safeChar.repeat(Math.max(0, side)) + reset();
|
|
@@ -4115,7 +4431,7 @@ var columns = (items, opts = {}) => {
|
|
|
4115
4431
|
const safeCols = clampPositive2(numCols, 2);
|
|
4116
4432
|
const safeGap = clampNonNeg(gap, 2);
|
|
4117
4433
|
const { cols: termCols } = termSize();
|
|
4118
|
-
const totalW = width !== null &&
|
|
4434
|
+
const totalW = width !== null && isFiniteNumber5(width) ? Math.max(safeCols, Math.floor(width)) : termCols;
|
|
4119
4435
|
const colW = Math.max(1, Math.floor((totalW - safeGap * (safeCols - 1)) / safeCols));
|
|
4120
4436
|
const gapStr = " ".repeat(safeGap);
|
|
4121
4437
|
const rows = [];
|
|
@@ -4155,7 +4471,7 @@ var timeline = (events, opts = {}) => {
|
|
|
4155
4471
|
const safeColor2 = safeSgrCode(colorCode, FG.cyan);
|
|
4156
4472
|
const safeDoneColor = safeSgrCode(doneColor, FG.green);
|
|
4157
4473
|
const safePendingColor = safeSgrCode(pendingColor, FG.brightBlack);
|
|
4158
|
-
const computedTimeWidth = timeColumnWidth !== null &&
|
|
4474
|
+
const computedTimeWidth = timeColumnWidth !== null && isFiniteNumber5(timeColumnWidth) ? Math.max(0, Math.floor(timeColumnWidth)) : Math.max(0, ...events.map((e) => e.time ? visibleLen(ensureString5(e.time)) : 0));
|
|
4159
4475
|
const lines = [];
|
|
4160
4476
|
events.forEach((ev, i) => {
|
|
4161
4477
|
const isLast = i === events.length - 1;
|
|
@@ -4347,10 +4663,10 @@ var STYLES = {
|
|
|
4347
4663
|
heavy: { branch: "\u2523\u2501\u2501 ", last: "\u2517\u2501\u2501 ", vert: "\u2503 ", space: " " },
|
|
4348
4664
|
ascii: { branch: "+-- ", last: "`-- ", vert: "| ", space: " " }
|
|
4349
4665
|
};
|
|
4350
|
-
var
|
|
4666
|
+
var isFiniteNumber6 = (n) => typeof n === "number" && Number.isFinite(n);
|
|
4351
4667
|
var ensureString6 = (v) => typeof v === "string" ? v : String(v ?? "");
|
|
4352
4668
|
var clampNonNeg2 = (n, fallback) => {
|
|
4353
|
-
if (!
|
|
4669
|
+
if (!isFiniteNumber6(n)) return fallback;
|
|
4354
4670
|
return Math.max(0, Math.floor(n));
|
|
4355
4671
|
};
|
|
4356
4672
|
var normalizeNewlines = (s) => s.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
@@ -4422,7 +4738,7 @@ var renderChildren = (children, parentContinuation, lines, indentStr, defaultSty
|
|
|
4422
4738
|
if (!Array.isArray(children)) return;
|
|
4423
4739
|
let visible = children;
|
|
4424
4740
|
let collapsedCount = 0;
|
|
4425
|
-
const safeCollapse =
|
|
4741
|
+
const safeCollapse = isFiniteNumber6(collapse) ? Math.floor(collapse) : 0;
|
|
4426
4742
|
if (safeCollapse > 0 && safeCollapse < children.length) {
|
|
4427
4743
|
visible = children.slice(safeCollapse);
|
|
4428
4744
|
collapsedCount = safeCollapse;
|
|
@@ -4492,7 +4808,7 @@ var renderTree = (root, opts = {}) => {
|
|
|
4492
4808
|
} = opts;
|
|
4493
4809
|
const safeStyle = style && STYLES[style] ? style : "normal";
|
|
4494
4810
|
const safeIndent = clampNonNeg2(indent, 0);
|
|
4495
|
-
const safeMaxDepth =
|
|
4811
|
+
const safeMaxDepth = isFiniteNumber6(maxDepth) ? Math.max(0, Math.floor(maxDepth)) : Infinity;
|
|
4496
4812
|
const indentStr = " ".repeat(safeIndent);
|
|
4497
4813
|
const lines = [];
|
|
4498
4814
|
const rootLabel = formatNode(root, 0, palette);
|
|
@@ -5111,13 +5427,13 @@ var themes = {
|
|
|
5111
5427
|
var FULL_BLOCK = "\u2588";
|
|
5112
5428
|
var UPPER_HALF = "\u2580";
|
|
5113
5429
|
var LOWER_HALF = "\u2584";
|
|
5114
|
-
var
|
|
5430
|
+
var isFiniteNumber7 = (n) => typeof n === "number" && Number.isFinite(n);
|
|
5115
5431
|
var clampInt = (n, min, max, fallback) => {
|
|
5116
|
-
if (!
|
|
5432
|
+
if (!isFiniteNumber7(n)) return fallback;
|
|
5117
5433
|
return Math.max(min, Math.min(max, Math.floor(n)));
|
|
5118
5434
|
};
|
|
5119
5435
|
var clampByte3 = (n) => {
|
|
5120
|
-
if (!
|
|
5436
|
+
if (!isFiniteNumber7(n)) return 0;
|
|
5121
5437
|
return Math.max(0, Math.min(255, Math.round(n)));
|
|
5122
5438
|
};
|
|
5123
5439
|
var MAX_DIMENSION = 1e4;
|
|
@@ -5422,7 +5738,7 @@ var gradientRect = (opts = {}) => {
|
|
|
5422
5738
|
const safeW = clampInt(width, 2, MAX_DIMENSION, 40);
|
|
5423
5739
|
const safeH = clampInt(height, 2, MAX_DIMENSION, 10);
|
|
5424
5740
|
let cosA = 1, sinA = 0;
|
|
5425
|
-
if (
|
|
5741
|
+
if (isFiniteNumber7(angle)) {
|
|
5426
5742
|
const rad = angle * Math.PI / 180;
|
|
5427
5743
|
cosA = Math.cos(rad);
|
|
5428
5744
|
sinA = Math.sin(rad);
|
|
@@ -5432,7 +5748,7 @@ var gradientRect = (opts = {}) => {
|
|
|
5432
5748
|
const line = [];
|
|
5433
5749
|
for (let col = 0; col < safeW; col++) {
|
|
5434
5750
|
let t;
|
|
5435
|
-
if (
|
|
5751
|
+
if (isFiniteNumber7(angle)) {
|
|
5436
5752
|
const projection = col / (safeW - 1) * cosA + row / (safeH - 1) * sinA;
|
|
5437
5753
|
t = clamp((projection + 1) / 2, 0, 1);
|
|
5438
5754
|
} else if (style === "horizontal") t = col / (safeW - 1);
|
|
@@ -5489,7 +5805,7 @@ var createCanvas = (width, height, fillColor = null) => {
|
|
|
5489
5805
|
if (y > dirtyMaxY) dirtyMaxY = y;
|
|
5490
5806
|
};
|
|
5491
5807
|
const setInternal = (x, y, color2) => {
|
|
5492
|
-
if (!
|
|
5808
|
+
if (!isFiniteNumber7(x) || !isFiniteNumber7(y)) return;
|
|
5493
5809
|
const ix = Math.floor(x);
|
|
5494
5810
|
const iy = Math.floor(y);
|
|
5495
5811
|
if (iy < 0 || iy >= h || ix < 0 || ix >= w) return;
|
|
@@ -5504,7 +5820,7 @@ var createCanvas = (width, height, fillColor = null) => {
|
|
|
5504
5820
|
},
|
|
5505
5821
|
set: setInternal,
|
|
5506
5822
|
get(x, y) {
|
|
5507
|
-
if (!
|
|
5823
|
+
if (!isFiniteNumber7(x) || !isFiniteNumber7(y)) return null;
|
|
5508
5824
|
const ix = Math.floor(x), iy = Math.floor(y);
|
|
5509
5825
|
return cloneColor(pixels[iy]?.[ix] ?? null);
|
|
5510
5826
|
},
|
|
@@ -5520,7 +5836,7 @@ var createCanvas = (width, height, fillColor = null) => {
|
|
|
5520
5836
|
dirtyMaxY = h - 1;
|
|
5521
5837
|
},
|
|
5522
5838
|
drawRect(x, y, rw, rh, color2, fill = false) {
|
|
5523
|
-
if (!
|
|
5839
|
+
if (!isFiniteNumber7(x) || !isFiniteNumber7(y) || !isFiniteNumber7(rw) || !isFiniteNumber7(rh)) return;
|
|
5524
5840
|
if (rw <= 0 || rh <= 0) return;
|
|
5525
5841
|
const ix = Math.floor(x);
|
|
5526
5842
|
const iy = Math.floor(y);
|
|
@@ -5542,7 +5858,7 @@ var createCanvas = (width, height, fillColor = null) => {
|
|
|
5542
5858
|
}
|
|
5543
5859
|
},
|
|
5544
5860
|
drawCircle(cx, cy, radius, color2, fill = false) {
|
|
5545
|
-
if (!
|
|
5861
|
+
if (!isFiniteNumber7(cx) || !isFiniteNumber7(cy) || !isFiniteNumber7(radius)) return;
|
|
5546
5862
|
if (radius <= 0) return;
|
|
5547
5863
|
const x0 = Math.max(0, Math.floor(cx - radius - 1));
|
|
5548
5864
|
const y0 = Math.max(0, Math.floor(cy - radius - 1));
|
|
@@ -5565,7 +5881,7 @@ var createCanvas = (width, height, fillColor = null) => {
|
|
|
5565
5881
|
}
|
|
5566
5882
|
},
|
|
5567
5883
|
drawSprite(x, y, sprite) {
|
|
5568
|
-
if (!
|
|
5884
|
+
if (!isFiniteNumber7(x) || !isFiniteNumber7(y)) return;
|
|
5569
5885
|
if (!Array.isArray(sprite)) return;
|
|
5570
5886
|
const sx = Math.floor(x);
|
|
5571
5887
|
const sy = Math.floor(y);
|
|
@@ -6322,6 +6638,99 @@ var withConfig = (overrides, fn) => {
|
|
|
6322
6638
|
throw err;
|
|
6323
6639
|
}
|
|
6324
6640
|
};
|
|
6641
|
+
var setConfigValue = (key, value) => {
|
|
6642
|
+
configure({ [key]: value });
|
|
6643
|
+
};
|
|
6644
|
+
var subscribeConfig = onConfigChange;
|
|
6645
|
+
|
|
6646
|
+
// src/utils/easing.ts
|
|
6647
|
+
var c1 = 1.70158;
|
|
6648
|
+
var c2 = c1 * 1.525;
|
|
6649
|
+
var c3 = c1 + 1;
|
|
6650
|
+
var c4 = 2 * Math.PI / 3;
|
|
6651
|
+
var c5 = 2 * Math.PI / 4.5;
|
|
6652
|
+
var _bounceOut = (t) => {
|
|
6653
|
+
const n1 = 7.5625;
|
|
6654
|
+
const d1 = 2.75;
|
|
6655
|
+
if (t < 1 / d1) return n1 * t * t;
|
|
6656
|
+
if (t < 2 / d1) {
|
|
6657
|
+
const x2 = t - 1.5 / d1;
|
|
6658
|
+
return n1 * x2 * x2 + 0.75;
|
|
6659
|
+
}
|
|
6660
|
+
if (t < 2.5 / d1) {
|
|
6661
|
+
const x2 = t - 2.25 / d1;
|
|
6662
|
+
return n1 * x2 * x2 + 0.9375;
|
|
6663
|
+
}
|
|
6664
|
+
const x = t - 2.625 / d1;
|
|
6665
|
+
return n1 * x * x + 0.984375;
|
|
6666
|
+
};
|
|
6667
|
+
var easings = {
|
|
6668
|
+
// ── Linear ──
|
|
6669
|
+
linear: (t) => t,
|
|
6670
|
+
// ── Quadratic (t²) ──
|
|
6671
|
+
easeInQuad: (t) => t * t,
|
|
6672
|
+
easeOutQuad: (t) => 1 - (1 - t) * (1 - t),
|
|
6673
|
+
easeInOutQuad: (t) => t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2,
|
|
6674
|
+
// ── Cubic (t³) ──
|
|
6675
|
+
easeInCubic: (t) => t * t * t,
|
|
6676
|
+
easeOutCubic: (t) => 1 - Math.pow(1 - t, 3),
|
|
6677
|
+
easeInOutCubic: (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2,
|
|
6678
|
+
// ── Quartic (t⁴) ──
|
|
6679
|
+
easeInQuart: (t) => t * t * t * t,
|
|
6680
|
+
easeOutQuart: (t) => 1 - Math.pow(1 - t, 4),
|
|
6681
|
+
easeInOutQuart: (t) => t < 0.5 ? 8 * t * t * t * t : 1 - Math.pow(-2 * t + 2, 4) / 2,
|
|
6682
|
+
// ── Quintic (t⁵) ──
|
|
6683
|
+
easeInQuint: (t) => t * t * t * t * t,
|
|
6684
|
+
easeOutQuint: (t) => 1 - Math.pow(1 - t, 5),
|
|
6685
|
+
easeInOutQuint: (t) => t < 0.5 ? 16 * t * t * t * t * t : 1 - Math.pow(-2 * t + 2, 5) / 2,
|
|
6686
|
+
// ── Sinusoidal ──
|
|
6687
|
+
easeInSine: (t) => 1 - Math.cos(t * Math.PI / 2),
|
|
6688
|
+
easeOutSine: (t) => Math.sin(t * Math.PI / 2),
|
|
6689
|
+
easeInOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
|
|
6690
|
+
// ── Exponential ──
|
|
6691
|
+
easeInExpo: (t) => t === 0 ? 0 : Math.pow(2, 10 * t - 10),
|
|
6692
|
+
easeOutExpo: (t) => t === 1 ? 1 : 1 - Math.pow(2, -10 * t),
|
|
6693
|
+
easeInOutExpo: (t) => {
|
|
6694
|
+
if (t === 0) return 0;
|
|
6695
|
+
if (t === 1) return 1;
|
|
6696
|
+
return t < 0.5 ? Math.pow(2, 20 * t - 10) / 2 : (2 - Math.pow(2, -20 * t + 10)) / 2;
|
|
6697
|
+
},
|
|
6698
|
+
// ── Circular ──
|
|
6699
|
+
easeInCirc: (t) => 1 - Math.sqrt(1 - Math.pow(t, 2)),
|
|
6700
|
+
easeOutCirc: (t) => Math.sqrt(1 - Math.pow(t - 1, 2)),
|
|
6701
|
+
easeInOutCirc: (t) => t < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * t, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * t + 2, 2)) + 1) / 2,
|
|
6702
|
+
// ── Back (overshoots) ──
|
|
6703
|
+
easeInBack: (t) => c3 * t * t * t - c1 * t * t,
|
|
6704
|
+
easeOutBack: (t) => 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2),
|
|
6705
|
+
easeInOutBack: (t) => t < 0.5 ? Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2) / 2 : (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2,
|
|
6706
|
+
// ── Elastic (oscillates) ──
|
|
6707
|
+
easeInElastic: (t) => {
|
|
6708
|
+
if (t === 0) return 0;
|
|
6709
|
+
if (t === 1) return 1;
|
|
6710
|
+
return -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
|
|
6711
|
+
},
|
|
6712
|
+
easeOutElastic: (t) => {
|
|
6713
|
+
if (t === 0) return 0;
|
|
6714
|
+
if (t === 1) return 1;
|
|
6715
|
+
return Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
|
|
6716
|
+
},
|
|
6717
|
+
easeInOutElastic: (t) => {
|
|
6718
|
+
if (t === 0) return 0;
|
|
6719
|
+
if (t === 1) return 1;
|
|
6720
|
+
return t < 0.5 ? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2 : Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5) / 2 + 1;
|
|
6721
|
+
},
|
|
6722
|
+
// ── Bounce (bouncing ball) ──
|
|
6723
|
+
easeInBounce: (t) => 1 - _bounceOut(1 - t),
|
|
6724
|
+
easeOutBounce: _bounceOut,
|
|
6725
|
+
easeInOutBounce: (t) => t < 0.5 ? (1 - _bounceOut(1 - 2 * t)) / 2 : (1 + _bounceOut(2 * t - 1)) / 2
|
|
6726
|
+
};
|
|
6727
|
+
var resolveEasingByName = (e) => {
|
|
6728
|
+
if (typeof e === "function") return e;
|
|
6729
|
+
if (typeof e === "string" && easings[e]) {
|
|
6730
|
+
return easings[e];
|
|
6731
|
+
}
|
|
6732
|
+
return easings.linear;
|
|
6733
|
+
};
|
|
6325
6734
|
|
|
6326
6735
|
// src/index.ts
|
|
6327
6736
|
var ansimax = { color, animate, ascii, loader, frames, components, trees, themes, images, configure };
|
|
@@ -6358,8 +6767,10 @@ var index_default = ansimax;
|
|
|
6358
6767
|
chain,
|
|
6359
6768
|
charWidth,
|
|
6360
6769
|
clamp,
|
|
6770
|
+
clampByte,
|
|
6361
6771
|
clearAnsiCache,
|
|
6362
6772
|
clearColorCache,
|
|
6773
|
+
clearLine,
|
|
6363
6774
|
clearRenderCache,
|
|
6364
6775
|
clearThemeColorCache,
|
|
6365
6776
|
color,
|
|
@@ -6376,6 +6787,8 @@ var index_default = ansimax;
|
|
|
6376
6787
|
cursor,
|
|
6377
6788
|
debounce,
|
|
6378
6789
|
diffLines,
|
|
6790
|
+
easings,
|
|
6791
|
+
escapeForRegex,
|
|
6379
6792
|
escapeRegex,
|
|
6380
6793
|
fg256,
|
|
6381
6794
|
fgRgb,
|
|
@@ -6396,13 +6809,17 @@ var index_default = ansimax;
|
|
|
6396
6809
|
gradient,
|
|
6397
6810
|
gradientColor,
|
|
6398
6811
|
gradientRect,
|
|
6812
|
+
gradientStops,
|
|
6399
6813
|
graphemes,
|
|
6400
6814
|
grid,
|
|
6401
6815
|
hasFont,
|
|
6402
6816
|
hexToRgb,
|
|
6403
6817
|
hideCursor,
|
|
6818
|
+
hslToRgb,
|
|
6404
6819
|
hsplit,
|
|
6820
|
+
hyperlink,
|
|
6405
6821
|
images,
|
|
6822
|
+
isFiniteNumber,
|
|
6406
6823
|
isHexColor,
|
|
6407
6824
|
isNoColor,
|
|
6408
6825
|
json,
|
|
@@ -6414,9 +6831,12 @@ var index_default = ansimax;
|
|
|
6414
6831
|
listPresets,
|
|
6415
6832
|
loader,
|
|
6416
6833
|
mapTree,
|
|
6834
|
+
measureBlock,
|
|
6417
6835
|
measureTree,
|
|
6418
6836
|
memoize,
|
|
6837
|
+
mixColors,
|
|
6419
6838
|
nextTick,
|
|
6839
|
+
oklabToRgb,
|
|
6420
6840
|
onConfigChange,
|
|
6421
6841
|
onConfigKeyChange,
|
|
6422
6842
|
onResize,
|
|
@@ -6429,6 +6849,7 @@ var index_default = ansimax;
|
|
|
6429
6849
|
pauseListeners,
|
|
6430
6850
|
presetNames,
|
|
6431
6851
|
presets,
|
|
6852
|
+
quantizeColor,
|
|
6432
6853
|
rainbow,
|
|
6433
6854
|
registerFont,
|
|
6434
6855
|
registerPreset,
|
|
@@ -6444,13 +6865,18 @@ var index_default = ansimax;
|
|
|
6444
6865
|
resetFramesCursorCount,
|
|
6445
6866
|
resetLoaderCursorCount,
|
|
6446
6867
|
resetNoColor,
|
|
6868
|
+
resolveEasingByName,
|
|
6447
6869
|
resumeListeners,
|
|
6448
6870
|
reverseGradient,
|
|
6449
6871
|
rgbTo256,
|
|
6450
6872
|
rgbToHex,
|
|
6873
|
+
rgbToHsl,
|
|
6874
|
+
rgbToOklab,
|
|
6451
6875
|
rotate90,
|
|
6876
|
+
safeInt,
|
|
6452
6877
|
safeJson,
|
|
6453
6878
|
screen,
|
|
6879
|
+
setConfigValue,
|
|
6454
6880
|
setNoColor,
|
|
6455
6881
|
setTitle,
|
|
6456
6882
|
sgr,
|
|
@@ -6461,6 +6887,7 @@ var index_default = ansimax;
|
|
|
6461
6887
|
stripAnsi,
|
|
6462
6888
|
stripAnsiCodes,
|
|
6463
6889
|
stripAnsiColors,
|
|
6890
|
+
subscribeConfig,
|
|
6464
6891
|
supportsColor,
|
|
6465
6892
|
supportsColorLevel,
|
|
6466
6893
|
termSize,
|