@gridland/utils 0.2.44 → 0.2.46
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.d.ts +271 -2
- package/dist/index.js +718 -41549
- package/dist/index.js.map +4 -4
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @gridland/utils type declarations.
|
|
2
|
+
// Portable hooks, types, and React context — no engine code.
|
|
3
|
+
|
|
4
|
+
import type React from "react"
|
|
5
|
+
|
|
6
|
+
// ── Hooks ────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
export interface UseKeyboardOptions {
|
|
9
|
+
release?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare const useKeyboard: (handler: (key: KeyEvent) => void, options?: UseKeyboardOptions) => void
|
|
13
|
+
export declare const useOnResize: (callback: (width: number, height: number) => void) => any
|
|
14
|
+
export declare const useRenderer: () => any
|
|
15
|
+
export declare const useTerminalDimensions: () => { width: number; height: number }
|
|
16
|
+
export declare const useTimeline: (options?: TimelineOptions) => Timeline
|
|
17
|
+
|
|
18
|
+
// ── React context ────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
export declare const AppContext: React.Context<{
|
|
21
|
+
keyHandler: any | null
|
|
22
|
+
renderer: any | null
|
|
23
|
+
}>
|
|
24
|
+
export declare const useAppContext: () => { keyHandler: any | null; renderer: any | null }
|
|
25
|
+
export declare class ErrorBoundary extends React.Component<
|
|
26
|
+
{ children: React.ReactNode },
|
|
27
|
+
{ hasError: boolean; error: Error | null }
|
|
28
|
+
> {}
|
|
29
|
+
export { createElement } from "react"
|
|
30
|
+
|
|
31
|
+
// ── Animation ────────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
export interface TimelineOptions {
|
|
34
|
+
duration?: number
|
|
35
|
+
loop?: boolean
|
|
36
|
+
autoplay?: boolean
|
|
37
|
+
onComplete?: () => void
|
|
38
|
+
onPause?: () => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AnimationOptions {
|
|
42
|
+
duration: number
|
|
43
|
+
ease?: EasingFunctions
|
|
44
|
+
onUpdate?: (animation: JSAnimation) => void
|
|
45
|
+
onComplete?: () => void
|
|
46
|
+
onStart?: () => void
|
|
47
|
+
onLoop?: () => void
|
|
48
|
+
loop?: boolean | number
|
|
49
|
+
loopDelay?: number
|
|
50
|
+
alternate?: boolean
|
|
51
|
+
once?: boolean
|
|
52
|
+
[key: string]: any
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface JSAnimation {
|
|
56
|
+
targets: any[]
|
|
57
|
+
deltaTime: number
|
|
58
|
+
progress: number
|
|
59
|
+
currentTime: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type EasingFunctions =
|
|
63
|
+
| "linear" | "inQuad" | "outQuad" | "inOutQuad"
|
|
64
|
+
| "inExpo" | "outExpo" | "inOutSine"
|
|
65
|
+
| "outBounce" | "outElastic" | "inBounce"
|
|
66
|
+
| "inCirc" | "outCirc" | "inOutCirc"
|
|
67
|
+
| "inBack" | "outBack" | "inOutBack"
|
|
68
|
+
|
|
69
|
+
export declare class Timeline {
|
|
70
|
+
items: any[]
|
|
71
|
+
subTimelines: any[]
|
|
72
|
+
currentTime: number
|
|
73
|
+
isPlaying: boolean
|
|
74
|
+
isComplete: boolean
|
|
75
|
+
duration: number
|
|
76
|
+
loop: boolean
|
|
77
|
+
synced: boolean
|
|
78
|
+
|
|
79
|
+
constructor(options?: TimelineOptions)
|
|
80
|
+
add(target: any, properties: AnimationOptions, startTime?: number | string): this
|
|
81
|
+
once(target: any, properties: AnimationOptions): this
|
|
82
|
+
call(callback: () => void, startTime?: number | string): this
|
|
83
|
+
sync(timeline: Timeline, startTime?: number): this
|
|
84
|
+
play(): this
|
|
85
|
+
pause(): this
|
|
86
|
+
restart(): this
|
|
87
|
+
update(deltaTime: number): void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare const engine: {
|
|
91
|
+
attach(renderer: any): void
|
|
92
|
+
detach(): void
|
|
93
|
+
register(timeline: Timeline): void
|
|
94
|
+
unregister(timeline: Timeline): void
|
|
95
|
+
clear(): void
|
|
96
|
+
update(deltaTime: number): void
|
|
97
|
+
defaults: { frameRate: number }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export declare function createTimeline(options?: TimelineOptions): Timeline
|
|
101
|
+
|
|
102
|
+
// ── Color utilities ──────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
export declare class RGBA {
|
|
105
|
+
buffer: Float32Array
|
|
106
|
+
constructor(buffer: Float32Array)
|
|
107
|
+
static fromArray(array: Float32Array): RGBA
|
|
108
|
+
static fromValues(r: number, g: number, b: number, a?: number): RGBA
|
|
109
|
+
static fromInts(r: number, g: number, b: number, a?: number): RGBA
|
|
110
|
+
static fromHex(hex: string): RGBA
|
|
111
|
+
toInts(): [number, number, number, number]
|
|
112
|
+
get r(): number
|
|
113
|
+
set r(value: number)
|
|
114
|
+
get g(): number
|
|
115
|
+
set g(value: number)
|
|
116
|
+
get b(): number
|
|
117
|
+
set b(value: number)
|
|
118
|
+
get a(): number
|
|
119
|
+
set a(value: number)
|
|
120
|
+
map<R>(fn: (value: number) => R): R[]
|
|
121
|
+
toString(): string
|
|
122
|
+
equals(other?: RGBA): boolean
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type ColorInput = string | RGBA
|
|
126
|
+
|
|
127
|
+
export declare function parseColor(color: ColorInput): RGBA
|
|
128
|
+
export declare function hexToRgb(hex: string): RGBA
|
|
129
|
+
export declare function rgbToHex(rgb: RGBA): string
|
|
130
|
+
export declare function hsvToRgb(h: number, s: number, v: number): RGBA
|
|
131
|
+
|
|
132
|
+
// ── Types ────────────────────────────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
export declare const TextAttributes: {
|
|
135
|
+
NONE: number
|
|
136
|
+
BOLD: number
|
|
137
|
+
DIM: number
|
|
138
|
+
ITALIC: number
|
|
139
|
+
UNDERLINE: number
|
|
140
|
+
BLINK: number
|
|
141
|
+
INVERSE: number
|
|
142
|
+
HIDDEN: number
|
|
143
|
+
STRIKETHROUGH: number
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export declare const ATTRIBUTE_BASE_BITS: number
|
|
147
|
+
export declare const ATTRIBUTE_BASE_MASK: number
|
|
148
|
+
export declare function getBaseAttributes(attr: number): number
|
|
149
|
+
|
|
150
|
+
export type CursorStyle = "block" | "line" | "underline"
|
|
151
|
+
export type MousePointerStyle = "default" | "pointer" | "text" | "crosshair" | "move" | "not-allowed"
|
|
152
|
+
export type ThemeMode = "dark" | "light"
|
|
153
|
+
export type WidthMethod = "wcwidth" | "unicode"
|
|
154
|
+
export type Timeout = ReturnType<typeof setTimeout> | undefined
|
|
155
|
+
|
|
156
|
+
export interface CursorStyleOptions {
|
|
157
|
+
style?: CursorStyle
|
|
158
|
+
blinking?: boolean
|
|
159
|
+
color?: RGBA
|
|
160
|
+
cursor?: MousePointerStyle
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export declare enum DebugOverlayCorner {
|
|
164
|
+
topLeft = 0,
|
|
165
|
+
topRight = 1,
|
|
166
|
+
bottomLeft = 2,
|
|
167
|
+
bottomRight = 3,
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface RenderContext {
|
|
171
|
+
width: number
|
|
172
|
+
height: number
|
|
173
|
+
requestRender: () => void
|
|
174
|
+
setCursorPosition: (x: number, y: number, visible: boolean) => void
|
|
175
|
+
setCursorStyle: (options: CursorStyleOptions) => void
|
|
176
|
+
setCursorColor: (color: RGBA) => void
|
|
177
|
+
setMousePointer: (shape: MousePointerStyle) => void
|
|
178
|
+
widthMethod: WidthMethod
|
|
179
|
+
capabilities: any | null
|
|
180
|
+
requestLive: () => void
|
|
181
|
+
dropLive: () => void
|
|
182
|
+
[key: string]: any
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface RendererEvents {
|
|
186
|
+
resize: (width: number, height: number) => void
|
|
187
|
+
key: (data: Buffer) => void
|
|
188
|
+
[key: string]: (...args: any[]) => void
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface ViewportBounds {
|
|
192
|
+
x: number
|
|
193
|
+
y: number
|
|
194
|
+
width: number
|
|
195
|
+
height: number
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface Highlight {
|
|
199
|
+
start: number
|
|
200
|
+
end: number
|
|
201
|
+
styleId: number
|
|
202
|
+
priority?: number | null
|
|
203
|
+
hlRef?: number | null
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface LineInfo {
|
|
207
|
+
lineStarts: number[]
|
|
208
|
+
lineWidths: number[]
|
|
209
|
+
maxLineWidth: number
|
|
210
|
+
lineSources: number[]
|
|
211
|
+
lineWraps: number[]
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface LineInfoProvider {
|
|
215
|
+
get lineInfo(): LineInfo
|
|
216
|
+
get lineCount(): number
|
|
217
|
+
get virtualLineCount(): number
|
|
218
|
+
get scrollY(): number
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface CapturedSpan {
|
|
222
|
+
text: string
|
|
223
|
+
fg: RGBA
|
|
224
|
+
bg: RGBA
|
|
225
|
+
attributes: number
|
|
226
|
+
width: number
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface CapturedLine {
|
|
230
|
+
spans: CapturedSpan[]
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface CapturedFrame {
|
|
234
|
+
cols: number
|
|
235
|
+
rows: number
|
|
236
|
+
cursor: [number, number]
|
|
237
|
+
lines: CapturedLine[]
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ── Key events ───────────────────────────────────────────────────────────
|
|
241
|
+
|
|
242
|
+
export type KeyEventType = "press" | "repeat" | "release"
|
|
243
|
+
|
|
244
|
+
export declare class KeyEvent {
|
|
245
|
+
name: string
|
|
246
|
+
ctrl: boolean
|
|
247
|
+
meta: boolean
|
|
248
|
+
shift: boolean
|
|
249
|
+
option: boolean
|
|
250
|
+
sequence: string
|
|
251
|
+
number: boolean
|
|
252
|
+
raw: string
|
|
253
|
+
repeated: boolean
|
|
254
|
+
eventType: KeyEventType
|
|
255
|
+
source: string
|
|
256
|
+
defaultPrevented: boolean
|
|
257
|
+
propagationStopped: boolean
|
|
258
|
+
preventDefault(): void
|
|
259
|
+
stopPropagation(): void
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ── Browser utilities ────────────────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
export declare function isBrowser(): boolean
|
|
265
|
+
export declare function isCanvasSupported(): boolean
|
|
266
|
+
export declare function calculateGridSize(
|
|
267
|
+
widthPx: number,
|
|
268
|
+
heightPx: number,
|
|
269
|
+
cellWidth: number,
|
|
270
|
+
cellHeight: number,
|
|
271
|
+
): { cols: number; rows: number }
|