@fairyhunter13/opentui-spinner 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-CSHLsh12.d.mts +80 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/solid.d.mts +8 -0
- package/dist/solid.mjs +1 -0
- package/dist/src-DJPZjJMl.mjs +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ColorInput, LayoutOptions, OptimizedBuffer, RenderContext, Renderable, RenderableOptions } from "@fairyhunter13/opentui-core";
|
|
2
|
+
import spinners from "cli-spinners";
|
|
3
|
+
|
|
4
|
+
//#region src/utils.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function that generates a color for a specific character at a specific frame
|
|
8
|
+
* @param frameIndex - Current frame index (0 to totalFrames-1)
|
|
9
|
+
* @param charIndex - Current character index (0 to totalChars-1)
|
|
10
|
+
* @param totalFrames - Total number of frames in the animation
|
|
11
|
+
* @param totalChars - Total number of characters in the current frame
|
|
12
|
+
* @returns Color for this specific character at this specific frame
|
|
13
|
+
*/
|
|
14
|
+
type ColorGenerator = (frameIndex: number, charIndex: number, totalFrames: number, totalChars: number) => ColorInput;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a pulsing color effect that cycles through colors
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const colorGen = createPulse(["red", "orange", "yellow"], 0.5);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare function createPulse(colors: ColorInput[], speed?: number): ColorGenerator;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a wave pattern that moves across characters
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const colorGen = createWave(["#ff0000", "#00ff00", "#0000ff"]);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function createWave(colors: ColorInput[]): ColorGenerator;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/index.d.ts
|
|
33
|
+
type SpinnerName = keyof typeof spinners;
|
|
34
|
+
interface SpinnerOptions extends Omit<RenderableOptions<SpinnerRenderable>, "width" | "height" | "buffered" | "live" | keyof LayoutOptions> {
|
|
35
|
+
name?: SpinnerName;
|
|
36
|
+
frames?: string[];
|
|
37
|
+
interval?: number;
|
|
38
|
+
autoplay?: boolean;
|
|
39
|
+
backgroundColor?: ColorInput;
|
|
40
|
+
color?: ColorInput | ColorGenerator;
|
|
41
|
+
}
|
|
42
|
+
declare class SpinnerRenderable extends Renderable {
|
|
43
|
+
private _name;
|
|
44
|
+
private _frames;
|
|
45
|
+
private _interval;
|
|
46
|
+
private _autoplay;
|
|
47
|
+
private _backgroundColor;
|
|
48
|
+
private _color;
|
|
49
|
+
private _currentFrameIndex;
|
|
50
|
+
private _encodedFrames;
|
|
51
|
+
private _lib;
|
|
52
|
+
private _intervalId;
|
|
53
|
+
protected _defaultOptions: {
|
|
54
|
+
name: "dots";
|
|
55
|
+
frames: string[];
|
|
56
|
+
interval: number;
|
|
57
|
+
autoplay: true;
|
|
58
|
+
backgroundColor: string;
|
|
59
|
+
color: string;
|
|
60
|
+
};
|
|
61
|
+
constructor(ctx: RenderContext, options: SpinnerOptions);
|
|
62
|
+
private _encodeFrames;
|
|
63
|
+
private _freeFrames;
|
|
64
|
+
get interval(): number;
|
|
65
|
+
set interval(value: number);
|
|
66
|
+
get name(): SpinnerName | undefined;
|
|
67
|
+
set name(value: SpinnerName | undefined);
|
|
68
|
+
get frames(): string[];
|
|
69
|
+
set frames(value: string[]);
|
|
70
|
+
get color(): ColorInput | ColorGenerator;
|
|
71
|
+
set color(value: ColorInput | ColorGenerator);
|
|
72
|
+
get backgroundColor(): ColorInput;
|
|
73
|
+
set backgroundColor(value: ColorInput);
|
|
74
|
+
start(): void;
|
|
75
|
+
stop(): void;
|
|
76
|
+
protected renderSelf(buffer: OptimizedBuffer): void;
|
|
77
|
+
protected destroySelf(): void;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createWave as a, createPulse as i, SpinnerRenderable as n, ColorGenerator as r, SpinnerOptions as t };
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t,t as n}from"./src-DJPZjJMl.mjs";export{n as SpinnerRenderable,e as createPulse,t as createWave};
|
package/dist/solid.d.mts
ADDED
package/dist/solid.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./src-DJPZjJMl.mjs";import{extend as t}from"@fairyhunter13/opentui-solid";t({spinner:e});export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Renderable as e,parseColor as t,resolveRenderLib as n}from"@fairyhunter13/opentui-core";import r from"cli-spinners";function i(e,t=1){return n=>e[Math.floor(n*t)%e.length]}function a(e){return(t,n,r,i)=>{let a=(n+t)%i;return e[Math.floor(a/i*e.length)]??e[0]}}var o=class extends e{_name;_frames;_interval;_autoplay;_backgroundColor;_color;_currentFrameIndex=0;_encodedFrames={};_lib=n();_intervalId=null;_defaultOptions={name:`dots`,frames:r.dots.frames,interval:r.dots.interval,autoplay:!0,backgroundColor:`transparent`,color:`white`};constructor(e,t){super(e,t),this._name=t.name,this._frames=this._name?r[this._name].frames:t.frames??this._defaultOptions.frames,this._interval=this._name?r[this._name].interval:t.interval??this._defaultOptions.interval,this._autoplay=t.autoplay??this._defaultOptions.autoplay,this._backgroundColor=t.backgroundColor??this._defaultOptions.backgroundColor,this._color=t.color??this._defaultOptions.color,this.width=Math.max(...this._frames.map(e=>e.length)),this.height=1,this._encodeFrames(),this._autoplay&&this.start()}_encodeFrames(){for(let e of this._frames){let t=this._lib.encodeUnicode(e,this.ctx.widthMethod);t&&(this._encodedFrames[e]=t)}}_freeFrames(){for(let e in this._encodedFrames)this._encodedFrames[e]&&this._lib.freeUnicode(this._encodedFrames[e]);this._encodedFrames={}}get interval(){return this._interval}set interval(e){this.stop(),this._interval=e,this.start()}get name(){return this._name}set name(e){this._freeFrames(),this._name=e,this._frames=this._name?r[this._name].frames:this._defaultOptions.frames,this._interval=this._name?r[this._name].interval:this._defaultOptions.interval,this.width=Math.max(...this._frames.map(e=>e.length)),this._encodeFrames(),this.requestRender()}get frames(){return this._frames}set frames(e){this._freeFrames(),this._frames=e.length===0?this._defaultOptions.frames:e,this._encodeFrames(),this.width=Math.max(...this._frames.map(e=>e.length)),this.requestRender()}get color(){return this._color}set color(e){this._color=e,this.requestRender()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){this._backgroundColor=e,this.requestRender()}start(){this._intervalId||=setInterval(()=>{this._currentFrameIndex=(this._currentFrameIndex+1)%this._frames.length,this.requestRender()},this._interval)}stop(){this._intervalId&&=(clearInterval(this._intervalId),null)}renderSelf(e){if(!this.visible)return;let n=this._frames[this._currentFrameIndex];if(!n)return;let r=this._encodedFrames[n];if(!r)return;let i=this.x;for(let n=0;n<r.data.length;n++){let a=typeof this._color==`function`?this._color(this._currentFrameIndex,n,this._frames.length,r.data.length):this._color;e.drawChar(r.data[n].char,i,this.y,t(a),t(this._backgroundColor)),i+=r.data[n].width}}destroySelf(){this.stop(),this._freeFrames(),super.destroySelf()}};export{i as n,a as r,o as t};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fairyhunter13/opentui-spinner",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A small & opinionated spinner library",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"./solid": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/solid.d.mts",
|
|
19
|
+
"default": "./dist/solid.mjs"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"lint": "biome check .",
|
|
29
|
+
"lint:fix": "biome check . --write"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"opentui",
|
|
33
|
+
"spinner",
|
|
34
|
+
"cli",
|
|
35
|
+
"terminal",
|
|
36
|
+
"console",
|
|
37
|
+
"tui"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"cli-spinners": "^3.3.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@biomejs/biome": "2.3.4",
|
|
44
|
+
"@fairyhunter13/opentui-core": "^0.1.113",
|
|
45
|
+
"@fairyhunter13/opentui-solid": "^0.1.113",
|
|
46
|
+
"@types/bun": "latest",
|
|
47
|
+
"tsdown": "^0.16.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@fairyhunter13/opentui-core": "^0.1.113",
|
|
51
|
+
"@fairyhunter13/opentui-solid": "^0.1.113",
|
|
52
|
+
"typescript": "^5"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"@fairyhunter13/opentui-solid": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/fairyhunter13/opentui-spinner.git"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
}
|
|
66
|
+
}
|