-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzephyr-framework.d.ts
More file actions
526 lines (445 loc) · 16.4 KB
/
Copy pathzephyr-framework.d.ts
File metadata and controls
526 lines (445 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/**
* Zephyr Framework — TypeScript Declarations
* @version 0.3.1
*/
// ---------------------------------------------------------------------------
// Component Elements
// ---------------------------------------------------------------------------
/** Base class for all Zephyr components. */
export declare class ZephyrElement extends HTMLElement {
connectedCallback(): void;
disconnectedCallback(): void;
/** Override in subclasses to set up component DOM structure. */
attachTemplate(): void;
/** Auto-wires declarative behaviors from data attributes. */
attachBehaviors(): void;
/** Wraps a DOM mutation in a View Transition if available. */
static withTransition(fn: () => void): void;
}
/** Minimal custom element for accordion items. */
export declare class ZAccordionItem extends HTMLElement {}
/** Collapsible accordion using CSS Grid transitions. Dispatches 'toggle' events. */
export declare class ZAccordion extends ZephyrElement {}
/** Modal dialog wrapping native <dialog> with View Transitions. */
export declare class ZModal extends ZephyrElement {
/** Opens the modal with a View Transition animation. */
open(): void;
/** Closes the modal with a View Transition animation. */
close(): void;
}
/** Tab panel component with keyboard navigation and View Transitions. */
export declare class ZTabs extends ZephyrElement {}
/** Form-associated custom select using ElementInternals. */
export declare class ZSelect extends ZephyrElement {
static formAssociated: true;
/** The current selected value. */
value: string;
}
/** Slide carousel with autoplay and View Transitions. */
export declare class ZCarousel extends ZephyrElement {
/** Transitions to the next slide. */
next(): void;
/** Transitions to the previous slide. */
prev(): void;
}
/** Toast notification component. */
export declare class ZToast extends ZephyrElement {
/**
* Displays a toast message for the given duration.
* @param message - The message to display
* @param duration - Duration in milliseconds before auto-hide (default: 3000)
*/
show(message: string, duration?: number): void;
}
/** Dropdown menu with click-outside handling. */
export declare class ZDropdown extends ZephyrElement {}
/** Filterable combobox with keyboard navigation and form association. */
export declare class ZCombobox extends ZephyrElement {
static formAssociated: true;
/** The current selected value. */
value: string;
}
/** Enhanced date picker wrapping native input[type="date"]. */
export declare class ZDatepicker extends ZephyrElement {
static formAssociated: true;
/** The current date value (YYYY-MM-DD format). */
value: string;
}
/** IntersectionObserver-based infinite scroll container. */
export declare class ZInfiniteScroll extends ZephyrElement {
/** Call when all data has been loaded to stop observing. */
complete(): void;
}
/** Drag & drop sortable list using the native HTML Drag and Drop API. */
export declare class ZSortable extends ZephyrElement {}
/** File upload component with drag-and-drop zone and progress display. */
export declare class ZFileUpload extends ZephyrElement {
/**
* Updates the progress bar for a specific file.
* @param index - File index in the list
* @param percent - Progress percentage (0-100)
*/
setProgress(index: number, percent: number): void;
}
/** Virtual scrolling list for efficiently rendering large datasets. */
export declare class ZVirtualList extends ZephyrElement {
/**
* Sets the data items for the list.
* @param items - Array of data objects to render
*/
setItems(items: any[]): void;
/**
* Sets the render function that converts a data item to HTML.
* @param fn - Renderer function returning an HTML string
*/
setRenderer(fn: (item: any, index: number) => string): void;
}
// ---------------------------------------------------------------------------
// Custom Element Tag Name Map
// ---------------------------------------------------------------------------
declare global {
interface HTMLElementTagNameMap {
'z-accordion-item': ZAccordionItem;
'z-accordion': ZAccordion;
'z-modal': ZModal;
'z-tabs': ZTabs;
'z-select': ZSelect;
'z-carousel': ZCarousel;
'z-toast': ZToast;
'z-dropdown': ZDropdown;
'z-combobox': ZCombobox;
'z-datepicker': ZDatepicker;
'z-infinite-scroll': ZInfiniteScroll;
'z-sortable': ZSortable;
'z-file-upload': ZFileUpload;
'z-virtual-list': ZVirtualList;
'z-stat': ZStat;
'z-dashboard-panel': ZDashboardPanel;
'z-dashboard': ZDashboard;
'z-data-grid': ZDataGrid;
'z-chart': ZChart;
}
}
// ---------------------------------------------------------------------------
// Component Registry Entry
// ---------------------------------------------------------------------------
interface ZephyrComponentDef {
tag: string;
slots: string[];
attributes: string[];
events: string[];
methods: string[];
}
// ---------------------------------------------------------------------------
// Agent API Types
// ---------------------------------------------------------------------------
interface ZephyrComponentState {
tag: string;
id: string | null;
state: Record<string, string | true>;
actions: string[];
}
interface ZephyrComponentDescription extends ZephyrComponentState {
description: string;
slots: Record<string, string | null>;
events: string[];
methods: string[];
}
interface ZephyrActResult {
success: boolean;
error?: string;
/** Present when a guard intercepts the action. */
pending?: boolean;
/** The ID to pass to confirm() or deny(). */
confirmId?: string;
}
interface ZephyrDenyResult {
success: boolean;
denied?: boolean;
error?: string;
}
interface ZephyrPendingAction {
confirmId: string;
selector: string;
action: string;
params: Record<string, any> | null;
timestamp: number;
}
interface ZephyrSetStateResult {
success: boolean;
state?: Record<string, string | true>;
error?: string;
}
interface ZephyrObserverDetail {
element: Element;
tag: string;
attribute: string;
oldValue: string | null;
newValue: string | null;
}
interface ZephyrDiffDetail {
component: string;
id: string | null;
property: string;
from: string | null;
to: string | null;
timestamp: number;
}
interface ZephyrRecordedAction {
selector: string;
action: string;
params: Record<string, any> | null;
timestamp: number;
}
interface ZephyrRecordingHandle {
/** Stops recording and returns the captured actions. */
stop(): ZephyrRecordedAction[];
}
interface ZephyrReplayOptions {
/** Milliseconds between each action (default: 0). Ignored if realtime is true. */
delay?: number;
/** If true, uses original timestamps to space out actions. */
realtime?: boolean;
}
interface ZephyrReplayResult {
selector: string;
action: string;
result: ZephyrActResult;
}
interface ZephyrAgentAPI {
/** Returns the enriched component schema with descriptions, actions, and examples. */
getSchema(): Record<string, ZephyrComponentDef & { actions: string[]; description: string }>;
/**
* Snapshots the state of all Zephyr components on the page.
* @param selector - Optional CSS selector to scope the query
*/
getState(selector?: string): ZephyrComponentState[];
/**
* Sets or removes data attributes on a Zephyr component.
* @param selector - CSS selector for the target element
* @param attributes - Attributes to set (null/false to remove)
*/
setState(selector: string, attributes: Record<string, string | boolean | null>): ZephyrSetStateResult;
/**
* Returns a structured description of a specific component instance.
* @param selector - CSS selector for the target element
*/
describe(selector: string): ZephyrComponentDescription | { error: string };
/**
* Performs a high-level action on a Zephyr component.
* @param selector - CSS selector for the target element
* @param action - Action name (e.g., 'open', 'close', 'select', 'next')
* @param params - Action parameters
*/
act(selector: string, action: string, params?: Record<string, any>): ZephyrActResult;
/**
* Observes state attribute changes on all Zephyr components.
* @param callback - Called with change details on every state mutation
*/
observe(callback: (detail: ZephyrObserverDetail) => void): void;
/**
* Removes an observer callback.
* @param callback - The callback to remove
*/
unobserve(callback: (detail: ZephyrObserverDetail) => void): void;
/**
* Observes state changes with structured diff objects.
* @param callback - Called with enriched diff details
*/
observeDiffs(callback: (diff: ZephyrDiffDetail) => void): void;
/**
* Removes a diff observer callback.
* @param callback - The callback to remove
*/
unobserveDiffs(callback: (diff: ZephyrDiffDetail) => void): void;
/**
* Enables or disables headless mode.
* @param enabled - true to enable, false to disable, omit to toggle
* @returns Current headless state
*/
headless(enabled?: boolean): boolean;
/**
* Starts recording agent actions.
* @returns Recording handle with stop() method
* @throws If a recording is already in progress
*/
record(): ZephyrRecordingHandle;
/**
* Replays a recorded sequence of agent actions.
* @param recording - Array of recorded actions
* @param options - Replay options
* @returns Resolves with results of each action
*/
replay(recording: ZephyrRecordedAction[], options?: ZephyrReplayOptions): Promise<ZephyrReplayResult[]>;
/**
* Locks a component so only the specified agent can act on it.
* @param selector - CSS selector for the component
* @param agentId - Unique identifier for the locking agent
*/
lock(selector: string, agentId: string): ZephyrActResult;
/**
* Unlocks a component.
* @param selector - CSS selector for the component
* @param agentId - The agent requesting the unlock
* @param options - Unlock options
*/
unlock(selector: string, agentId: string, options?: { force?: boolean }): ZephyrActResult;
/**
* Returns all currently locked components and their owning agents.
*/
locks(): Array<{ selector: string; agentId: string }>;
/**
* Registers a guard requiring confirmation before executing specified actions.
* @param selector - CSS selector, tag name, or '*' for all components
* @param actions - Array of action names to guard, or '*' for all actions
* @param handler - Optional function returning false to bypass the guard
* @param options - Options: { timeout: number } (default 30000ms auto-deny)
*/
guard(
selector: string,
actions: string[] | '*',
handler?: (selector: string, action: string, params?: Record<string, any>) => boolean,
options?: { timeout?: number }
): { success: true };
/** Removes a guard and cleans up related pending confirmations. */
unguard(selector: string): { success: true };
/** Confirms a pending guarded action, executing it immediately. */
confirm(confirmId: string): ZephyrActResult;
/** Denies a pending guarded action, discarding it without executing. */
deny(confirmId: string): ZephyrDenyResult;
/** Returns all pending guarded actions awaiting confirmation. */
guarded(): ZephyrPendingAction[];
/** Generates a markdown prompt describing all Zephyr components on the page. */
getPrompt(): string;
/** Annotates all Zephyr components with data-z-actions for agent discovery. */
annotate(): void;
/**
* Safely creates and inserts a Zephyr component into the DOM.
* Uses DOM manipulation (no innerHTML) with a tag whitelist.
*/
render(containerSelector: string, spec: ZephyrRenderSpec): ZephyrRenderResult;
/**
* Composes a complete dashboard layout from a declarative spec.
* Sugar over render() for dashboard/panel patterns.
*/
compose(containerSelector: string, layout: ZephyrComposeLayout): ZephyrComposeResult;
/**
* Auto-selects and renders the best Zephyr component for the given data.
* Analyzes data shape: time series → z-chart, stat objects → z-stat cards,
* simple arrays → z-sortable/z-virtual-list, object arrays → z-data-grid.
* Clears the container before rendering.
* @param data - Any data: time series array, stat array/object, string list, or object array
* @param containerSelector - CSS selector for the target container
* @param options - Optional hint and title
*/
visualize(data: any, containerSelector: string, options?: ZephyrVisualizeOptions): ZephyrVisualizeResult;
}
// ---------------------------------------------------------------------------
// Visualize API Types
// ---------------------------------------------------------------------------
interface ZephyrVisualizeOptions {
/** Override auto-detection: 'chart', 'stats', 'list', or 'table'. */
hint?: 'chart' | 'stats' | 'list' | 'table';
/** Title for chart visualizations. */
title?: string;
}
interface ZephyrVisualizeResult {
success: boolean;
/** The component tag that was rendered (e.g., 'z-chart', 'z-stat'). */
component?: string;
selector?: string;
error?: string;
}
// ---------------------------------------------------------------------------
// Render API Types
// ---------------------------------------------------------------------------
interface ZephyrRenderSpec {
tag: string;
id?: string;
attributes?: Record<string, string>;
text?: string;
children?: ZephyrRenderSpec[];
setup?: { method: string; params?: any };
position?: number;
}
interface ZephyrRenderResult {
success: boolean;
selector?: string;
error?: string;
warning?: string;
}
interface ZephyrComposePanelSpec {
id: string;
colspan?: number;
rowspan?: number;
title?: string;
component?: ZephyrRenderSpec;
}
interface ZephyrComposeLayout {
tag?: string;
id?: string;
attributes?: Record<string, string>;
panels: ZephyrComposePanelSpec[];
}
interface ZephyrComposeResult extends ZephyrRenderResult {
panels?: string[];
}
// ---------------------------------------------------------------------------
// Dashboard Add-on Components (zephyr-dashboard.js)
// ---------------------------------------------------------------------------
/** KPI stat card with label, value, and trend indicator. */
export declare class ZStat extends ZephyrElement {
static observedAttributes: string[];
setValue(value?: string, trend?: string, trendValue?: string): void;
}
/** Dashboard panel container. */
export declare class ZDashboardPanel extends HTMLElement {}
/** Responsive grid layout container for dashboard panels. */
export declare class ZDashboard extends ZephyrElement {
addPanel(config: { id: string; colspan?: number; rowspan?: number; title?: string; position?: number }): ZDashboardPanel;
removePanel(id: string): void;
movePanel(id: string, position: number): void;
}
/** Sortable, filterable data table. */
export declare class ZDataGrid extends ZephyrElement {
setColumns(columns: Array<{ key: string; label: string; sortable?: boolean; width?: string; align?: string }>): void;
setRows(rows: Array<Record<string, any>>): void;
sort(column: string, direction?: string): void;
filter(query: string): void;
}
/** Chart component wrapping lightweight-charts. */
export declare class ZChart extends ZephyrElement {
setType(type: 'line' | 'candlestick' | 'area' | 'histogram'): void;
setData(data: Array<{ time: number; value?: number; open?: number; high?: number; low?: number; close?: number }>): void;
addPoint(point: { time: number; value?: number; open?: number; high?: number; low?: number; close?: number }): void;
addSeries(config: { type?: string; data?: any[]; options?: any }): any;
setTimeRange(from: number, to: number): void;
}
// ---------------------------------------------------------------------------
// Global Zephyr API
// ---------------------------------------------------------------------------
interface ZephyrAPI {
/**
* Returns a modal element by ID.
* @param id - The modal element's ID attribute
*/
modal(id: string): ZModal | null;
/**
* Displays a toast notification.
* @param message - The message to display
* @param duration - Duration in milliseconds (default: 3000)
*/
toast(message: string, duration?: number): void;
/** Registry of all Zephyr components and their capabilities. */
components: Record<string, ZephyrComponentDef>;
/** Structured interface for AI agents and LLMs. */
agent: ZephyrAgentAPI;
}
declare global {
interface Window {
Zephyr: ZephyrAPI;
}
/** Global Zephyr API. */
var Zephyr: ZephyrAPI;
}
export {};