UNPKG

19.3 kBTypeScriptView Raw
1/// <reference path="./imba.types.d.ts" />
2/// <reference path="./imba.dom.d.ts" />
3/// <reference path="./imba.events.d.ts" />
4/// <reference path="./imba.router.d.ts" />
5/// <reference path="./imba.snippets.d.ts" />
6/// <reference path="./imba.meta.d.ts" />
7
8/// <reference path="./styles.d.ts" />
9/// <reference path="./styles.generated.d.ts" />
10/// <reference path="./styles.modifiers.d.ts" />
11
12import type { UserConfig } from 'vite'
13import type { UserConfig as TestConfig } from 'vitest'
14
15
16
17interface Node {
18 /**
19 * @custom
20 * @summary Proxy to reference data on elements up the tree
21 */
22 readonly Ψcontext: imba.Context;
23
24 /**
25 * @custom
26 * @summary Reference to the parentNode even before element has been attached
27 */
28 readonly Ψparent: Element;
29}
30
31interface Element {
32
33 /**
34 * @idl
35 * @summary Default property for setting the data of an element
36 */
37 data: any;
38
39 /**
40 * @private
41 */
42 private route__: any;
43
44 /**
45 * Gives elements a stable identity inside lists
46 * @idl
47 * @deprecated Use key instead
48 */
49 $key: any;
50
51 /**
52 * Gives elements a stable identity inside lists.
53 * Any value (both objects and primitive values) may be used as a key.
54 * @idl
55 */
56 key: any;
57
58 /**
59 * Sets whether `@hotkey` events inside of this element
60 * is enabled or not. If explicitly set to true, only
61 * `@hotkey` events inside this group will be triggered
62 * when this element or a child has focus.
63 * @summary Sets whether `@hotkey` events inside of this element
64 * is enabled or not
65 * @idl
66 */
67 hotkeys: boolean;
68
69 /**
70 * Enable transitions for when element is attached / detached
71 * @see[Transitions](https://imba.io/css/transitions)
72 * @idl
73 */
74 ease: any;
75
76 // itemid: any;
77 // itemprop: any;
78 // itemref: any;
79 // itemscope: any;
80 // itemtype: any;
81 // enterkeyhint: any;
82 // autofocus: any;
83 // autocapitalize: any;
84 // autocomplete: any;
85 // accesskey: any;
86 // inputmode: any;
87 // spellcheck: any;
88 // translate: any;
89 // is: any;
90
91 /**
92 * @summary Allows for manipulation of element's class content attribute
93 */
94 readonly flags: imba.Flags;
95
96 /**
97 * Emits event
98 * @param event
99 * @param params
100 * @param options
101 * @custom
102 */
103 emit(event: string, params?: any, options?: any): Event;
104 focus(options?: any): void;
105 blur(): void;
106
107 // [key: string]: any;
108
109 setAttribute(name: string, value: boolean): void;
110 setAttribute(name: string, value: number): void;
111
112 addEventListener(event: string, listener: (event: Event) => void, options?: {
113 passive?: boolean;
114 once?: boolean;
115 capture?: boolean;
116 });
117
118 removeEventListener(event: string, listener: (event: Event) => void, options?: {
119 passive?: boolean;
120 once?: boolean;
121 capture?: boolean;
122 });
123
124 log(...arguments: any[]): void;
125}
126
127interface Document {
128 readonly flags: imba.Flags;
129}
130
131interface HTMLMetaElement {
132 property?: string;
133 charset?: string;
134}
135
136interface EventListenerOptions {
137 passive?: boolean;
138 once?: boolean;
139}
140
141interface Storage {
142 setItem(key: string, value: number): void;
143}
144
145interface HTMLStyleElement {
146 /**
147 * The supplied path will be run through the imba bundler
148 */
149 src: ImbaAsset | string;
150}
151
152interface SVGSVGElement {
153 /**
154 * Reference to svg asset that will be inlined
155 */
156 src: ImbaAsset | string;
157}
158
159declare class ΤObject {
160 [key: string]: any;
161}
162
163declare class ImbaElement extends imba.Component {
164
165}
166
167/** Portal to declare window/document event handlers from
168 * inside custom tags.
169 */
170declare class Γglobal extends HTMLElement {
171
172}
173
174declare class Γteleport extends HTMLElement {
175 /** The element (or selector) you want to add listeners and content to */
176 to: string | Element;
177}
178
179declare class Γany extends HTMLElement {
180 [key: string]: any;
181}
182
183interface HTMLElementTagNameMap {
184 "global": Γglobal,
185 "teleport": Γteleport
186}
187
188interface ImbaAsset {
189 body: string;
190 url: string;
191 absPath: string;
192 path: string;
193}
194
195interface Event {
196 detail: any;
197 originalEvent: Event | null;
198}
199
200// interface Object {
201// [key: string]: any;
202// }
203
204declare namespace imba {
205
206 interface Globals {
207 /** The global clearInterval() method cancels a timed, repeating action which was previously established by a call to setInterval(). */
208 clearInterval(handle?: number): void;
209 /** The global clearTimeout() method cancels a timeout previously established by calling setTimeout(). */
210 clearTimeout(handle?: number): void;
211 fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
212 queueMicrotask(callback: VoidFunction): void;
213 /**
214 * The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.
215 */
216 setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
217 /** The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires. */
218 setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
219
220 /**
221 * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
222 * @param number A numeric value.
223 */
224 isNaN(number: number): boolean;
225
226 /**
227 * Determines whether a supplied number is finite.
228 * @param number Any numeric value.
229 */
230 isFinite(number: number): boolean;
231
232 /** Reference to the current window */
233 readonly window: Window;
234
235 /** Reference to the current document */
236 readonly document: Document;
237
238 /** Reference to the current document */
239 readonly process: any;
240
241 /** Dirname */
242 readonly __dirname: string;
243
244 /** Filename */
245 readonly __filename: string;
246
247 /** Real filename */
248 readonly __realname: string;
249
250 /** Reference to the global object */
251 readonly global: typeof globalThis;
252
253 /**
254 * Converts a string to an integer.
255 * @param string A string to convert into a number.
256 * @param radix A value between 2 and 36 that specifies the base of the number in `string`.
257 * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
258 * All other strings are considered decimal.
259 */
260 parseInt(string: string, radix?: number): number;
261
262 /**
263 * Converts a string to a floating-point number.
264 * @param string A string that contains a floating-point number.
265 */
266 parseFloat(string: string): number;
267
268 /** Access to the global console object */
269 console: Console;
270 }
271
272 interface Context {
273 [key: string]: any;
274 }
275
276 interface Flags {
277 /**
278 *
279 * @summary Returns true if the list contains the given token, otherwise false.
280 */
281 contains(flag: string): boolean;
282 /**
283 *
284 * @summary Adds the specified token to the list.
285 */
286 add(flag: string): void;
287 /**
288 *
289 * @summary Removes the specified token from the list.
290 */
291 remove(flag: string): void;
292 /**
293 *
294 * @summary Toggles specified token in the list.
295 */
296 toggle(flag: string, toggler?: any): void;
297 /**
298 *
299 * @summary Adds the specified token to the list
300 */
301 incr(flag: string): number;
302 /**
303 *
304 * @summary Removes the specified token from the list if zero increments remain
305 */
306 decr(flag: string): number;
307 }
308
309 interface units {
310 /**
311 * Milliseconds
312 */
313 ms: number;
314
315 /**
316 * Seconds. Compiles to n * 1000 (milliseconds in one second)
317 */
318 s: number;
319
320 /**
321 * Days. Compiles to n * 60000 (milliseconds in one minute)
322 */
323 minutes: number;
324
325 /**
326 * Hours. Compiles to n * 3600000 (milliseconds in 1 hour)
327 */
328 hours: number;
329
330 /**
331 * Days. Compiles to n * 86400000 (milliseconds in one day)
332 */
333 days: number;
334
335 /**
336 * Frames per second. Compiles to 1000 / n
337 * Ie 60fps => 1000 / 60.
338 */
339 fps: number;
340
341 /**
342 * Pixels
343 */
344 px: string;
345 }
346
347 namespace hotkeys {
348 function trigger(combo: string): void;
349
350 /**
351 * Format combo as readable label
352 */
353 function humanize(combo: string, platform?: string): string;
354
355 /**
356 * Format combo as html (readable keys wrapped in <kbd> elements)
357 */
358 function htmlify(combo: string, platform?: string): string;
359 }
360
361 /**
362 * @custom
363 */
364 class Component extends HTMLElement {
365
366 /**
367 * @summary Called to update the element and their children
368 * @abstract
369 * @lifecycle
370 */
371 render(): any;
372
373 /**
374 * @summary Called on client to hydrate SSR element
375 * @abstract
376 * @lifecycle
377 */
378 hydrate(): any;
379
380 /**
381 * @summary Called on server when stringifying a component
382 * @abstract
383 * @lifecycle
384 */
385 dehydrate(): any;
386
387 /**
388 * @summary Suspend rendering of component
389 * @lifecycle
390 */
391 suspend(): this;
392
393 /**
394 * @summary Unsuspend rendering of component
395 * @lifecycle
396 */
397 unsuspend(): this;
398
399 /**
400 * @summary Called to update element via scheduler
401 * @abstract
402 * @lifecycle
403 */
404 tick(): any;
405
406 /**
407 * @summary Tells whether the component should render
408 * @abstract
409 * @lifecycle
410 */
411 get renderΦ(): boolean;
412
413 /**
414 * @readonly
415 * @summary Tells whether the component is currently being mounted
416 * @lifecycle
417 */
418 get mountingΦ(): boolean;
419
420 /**
421 * @readonly
422 * @summary Tells whether the component is currently mounted in document
423 * @lifecycle */
424 get mountedΦ(): boolean;
425
426 /**
427 * @readonly
428 * @summary Tells whether the component has been awakened
429 * @lifecycle */
430 get awakenedΦ(): boolean;
431
432 /**
433 * @readonly
434 * @summary Tells whether the component has been rendered
435 * @lifecycle */
436 get renderedΦ(): boolean;
437
438 /**
439 * @readonly
440 * @summary Tells whether the component has been suspended
441 * @lifecycle */
442 get suspendedΦ(): boolean;
443
444 /**
445 * @readonly
446 * @summary Tells whether the component is currently rendering
447 * @lifecycle */
448 get renderingΦ(): boolean;
449
450 /**
451 * @readonly
452 * @summary Tells whether the component is scheduled to automatically render
453 * @lifecycle
454 * */
455 get scheduledΦ(): boolean;
456
457 /**
458 * @readonly
459 * @summary Tells whether the component has been hydrated on the client
460 * @lifecycle */
461 get hydratedΦ(): boolean;
462
463 /**
464 * @readonly
465 * @summary Tells whether the component was originally rendered on the server */
466 get ssrΦ(): boolean;
467
468 /**
469 * @summary Start rendering the component on every imba.commit
470 */
471 schedule(): this;
472
473 /**
474 * @summary Stop rendering the component automatically on every imba.commit
475 */
476 unschedule(): this;
477
478 /**
479 * @summary Called before any properties are set
480 * @lifecycle
481 * @abstract
482 */
483 build(): any;
484
485 /**
486 * @summary Called before any properties are set
487 * @lifecycle
488 * @abstract
489 */
490 setup(): any;
491
492 /**
493 * @summary Called when element is *first* attached to document
494 * @lifecycle
495 * @abstract
496 */
497 awaken(): any;
498
499 /**
500 * @summary Called when element is attached to document
501 * @lifecycle
502 * @abstract
503 */
504 mount(): any;
505
506 /**
507 * @summary Called when element is detached from document
508 * @lifecycle
509 * @abstract
510 */
511 unmount(): any;
512
513 /**
514 * @summary Called after render
515 * @lifecycle
516 * @abstract
517 */
518 rendered(): any;
519
520 /**
521 Schedule the element to update itself
522 yes = render on events / imba.commit
523 no = force manual render
524 null / undefined = render via parent
525 (n)s = render every n s
526 (n)ms = render every n ms
527 (n)fps = render n times per second
528
529 @summary Specify how / when the component should re-render
530 @idl
531 */
532 autorender: boolean | number | null | `${number}ms` | `${number}s` | `${number}fps`;
533 }
534
535 function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
536 function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
537 function clearInterval(handle?: number): void;
538 function clearTimeout(handle?: number): void;
539
540 /**
541 * Schedule re-render
542 */
543 function commit(): Promise<void>;
544
545 type mode = "development" | "production"
546 interface setupCallback {
547 (dist:string) : any
548 }
549 interface setupOptions {
550 mode: mode
551 serverOptions: import("Vite").ServerOptions
552 }
553 /**
554 * Render elements in custom context
555 */
556 function render(func: Function, context?: any): any;
557
558 /**
559 * Attach an element to the dom
560 * @param element
561 * @param into
562 */
563 function mount<T>(element: T, into?: Element): T;
564 function mount(func: Function, into?: Element): Element;
565
566 /**
567 * Detach element from document
568 * @param element
569 */
570 function unmount<T>(element: T): T;
571
572 /**
573 * Mark field as observable
574 */
575 function αobservable(): void;
576
577 /**
578 * Mark getter as computed
579 */
580 function αcomputed(): void;
581
582 /**
583 * Runs the method immediately after instance is initialized
584 * and re-runs whenever any of the referenced observables
585 * change. Methods marked with autorun in tag declarations
586 * will run immediately after mount, and automatically dispose
587 * when element unmounts.
588 */
589 function αautorun(options?: any): void;
590
591 /**
592 * Mark getter as lazy. It will only be evaluated once,
593 * and then return the resulting value forever after.
594 */
595 function αlazy(): void;
596
597 let colors: string[];
598
599 interface ImbaProcess {
600 on(event:string,callback:Function);
601 }
602
603 let process: ImbaProcess;
604
605 namespace types {
606 let events: GlobalEventHandlersEventMap;
607 let eventHandlers: GlobalEventHandlers;
608
609 namespace html {
610 let tags: HTMLElementTagNameMap;
611 let events: GlobalEventHandlersEventMap;
612 }
613
614 namespace svg {
615 let tags: SVGElementTagNameMap;
616 let events: SVGElementEventMap;
617 }
618 }
619
620 let Element: Component;
621
622 /**
623 * Class for scheduling
624 * @custom
625 */
626 export interface Scheduler {
627 add(target: any, force?: boolean): void;
628 on(group: string, target: any): void;
629 un(group: string, target: any): void;
630
631 /** Milliseconds since previous tick */
632 dt: number;
633 }
634
635 /**
636 * Reference to global scheduler
637 */
638 let scheduler: Scheduler;
639
640 function createIndexedFragment(...arguments: any[]): DocumentFragment;
641 function createKeyedFragment(...arguments: any[]): DocumentFragment;
642 function createLiveFragment(...arguments: any[]): DocumentFragment;
643
644 function emit(source: any, event: string, params: any[]): void;
645 function listen(target: any, event: string, listener: any, path?: any): void;
646 function once(target: any, event: string, listener: any, path?: any): void;
647 function unlisten(target: any, event: string, listener: any, path?: any): void;
648 function indexOf(target: any, source: any): boolean;
649
650 /**
651 * Start an asset-aware server
652 */
653 function serve(target: any, options?: any): any;
654
655 /*
656 Observability
657 TODO Complete & document types
658 */
659
660 interface Reaction {
661 dispose(): this;
662 }
663
664 function observable<T>(value: T): T;
665
666 function run(callback: any): void;
667 function autorun(callback: any): Reaction;
668
669 // TODO check if T responds to accessor method - if so, return the result of that type
670 function accessor<T>(accessor: T,...rest:any[]): T extends {$accessor: (...args: any[]) => infer X} ? X : T;
671
672 interface AccessorGenerator {
673 $accessor(target: any, key: symbol, name: string | symbol, slot: symbol, context: any);
674 }
675
676 interface Accessor {
677 $get(target: any, key: string | symbol, name: string | symbol): any;
678 $set(value: any, target: any, key: string | symbol, name: string | symbol): void;
679 }
680
681 interface Storage {
682 [key: string]: any;
683 }
684
685 /**
686 * localStorage as a rich object
687 */
688 let locals: Storage;
689
690 /**
691 * sessionStorage as a rich object
692 */
693 let session: Storage;
694}
695
696declare module "data:text/asset;*" {
697 const value: ImbaAsset;
698 export default value;
699 export const body: string;
700 export const url: string;
701 export const absPath: string;
702 export const path: string;
703}
704
705declare module "imba/compiler" {
706 export function compile(fileName: string, options: any): any;
707}
708
709declare module "imba" {
710
711 interface ThemeColors {
712 [key: string]: {
713 [key: string]: string;
714 };
715 }
716
717 interface Theme {
718 colors?: ThemeColors;
719 }
720
721 interface ImbaConfig {
722 /**
723 * create aliases for color keywords, make your own keywords,
724 * or redefine the default keywords to new color values
725 *
726 * @example <caption>create an alias for the `indigo` color called `primary`</caption>
727 * { theme: {colors: {primary: 'indigo'}}}
728 * // now use it like this <h1[c:primary4]> "hey"
729 *
730 * @example <caption>Override default colors. Make `gray` an alias for `warmer` instead of the default gray color</caption>
731 * { theme: {colors: {gray: 'warmer'}}}
732 *
733 * @example <caption>create your own color keywords with specified tint values. Any unspecified tint values will be interpolated</caption>
734 * { theme: {colors: { coral: {
735 * "0": "hsl(40,33%,98%)",
736 * "4": "hsl(6,56%,65%)",
737 * "9": "hsl(6,52%,15%)"
738 * }}}}
739 **/
740 theme?: Theme
741 }
742
743 interface ViteConfig extends UserConfig { }
744 interface VitestConfig extends TestConfig { }
745
746 interface Config {
747 imba?: ImbaConfig;
748 test?: TestConfig;
749 client?: UserConfig;
750 server?: UserConfig;
751 }
752
753 export function defineConfig(config: Config): Config;
754}