yvee 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  declare const isFN: (v: any) => v is Function;
2
2
  declare const isAsync: (v: any) => v is Function;
3
+ declare const isPromise: (v: any) => v is Function;
3
4
  declare const isNumber: (value: any) => boolean;
4
- declare const isDict: (val: any) => boolean;
5
5
  declare const isPlainObject: (value: any) => boolean;
6
6
  declare const isArraybuff: (val: any) => val is string | ArrayBuffer | Uint8Array<ArrayBufferLike>;
7
7
  declare const isClassOrId: (k: string) => boolean;
@@ -11,7 +11,9 @@ declare const isArr: (v: any) => v is any[];
11
11
  declare const isObj: (v: any) => v is object;
12
12
  declare const isNum: (v: any) => v is number;
13
13
  declare const isNull: (v: any) => v is null;
14
+ declare const isNotNull: <T>(v: T) => v is Exclude<T, null>;
14
15
  declare const isUndefined: (v: any) => v is undefined;
16
+ declare const isDefined: <T>(v: T) => v is Exclude<T, undefined>;
15
17
  declare const isInt: (str: string) => boolean;
16
18
  declare const isWindow: boolean;
17
19
  declare const isNotWindow: boolean;
@@ -21,24 +23,26 @@ declare const is_isArraybuff: typeof isArraybuff;
21
23
  declare const is_isAsync: typeof isAsync;
22
24
  declare const is_isBool: typeof isBool;
23
25
  declare const is_isClassOrId: typeof isClassOrId;
24
- declare const is_isDict: typeof isDict;
26
+ declare const is_isDefined: typeof isDefined;
25
27
  declare const is_isFN: typeof isFN;
26
28
  declare const is_isInt: typeof isInt;
29
+ declare const is_isNotNull: typeof isNotNull;
27
30
  declare const is_isNotWindow: typeof isNotWindow;
28
31
  declare const is_isNull: typeof isNull;
29
32
  declare const is_isNum: typeof isNum;
30
33
  declare const is_isNumber: typeof isNumber;
31
34
  declare const is_isObj: typeof isObj;
32
35
  declare const is_isPlainObject: typeof isPlainObject;
36
+ declare const is_isPromise: typeof isPromise;
33
37
  declare const is_isStr: typeof isStr;
34
38
  declare const is_isUndefined: typeof isUndefined;
35
39
  declare const is_isWindow: typeof isWindow;
36
40
  declare namespace is {
37
- export { is_isArr as isArr, is_isArraybuff as isArraybuff, is_isAsync as isAsync, is_isBool as isBool, is_isClassOrId as isClassOrId, is_isDict as isDict, is_isFN as isFN, is_isInt as isInt, is_isNotWindow as isNotWindow, is_isNull as isNull, is_isNum as isNum, is_isNumber as isNumber, is_isObj as isObj, is_isPlainObject as isPlainObject, is_isStr as isStr, is_isUndefined as isUndefined, is_isWindow as isWindow };
41
+ export { is_isArr as isArr, is_isArraybuff as isArraybuff, is_isAsync as isAsync, is_isBool as isBool, is_isClassOrId as isClassOrId, is_isDefined as isDefined, is_isFN as isFN, is_isInt as isInt, is_isNotNull as isNotNull, is_isNotWindow as isNotWindow, is_isNull as isNull, is_isNum as isNum, is_isNumber as isNumber, is_isObj as isObj, is_isPlainObject as isPlainObject, is_isPromise as isPromise, is_isStr as isStr, is_isUndefined as isUndefined, is_isWindow as isWindow };
38
42
  }
39
43
 
40
44
  type V = string | number | boolean;
41
- type obj<T> = Record<string, T>;
45
+ type obj$1<T> = Record<string, T>;
42
46
 
43
47
  /**
44
48
  * A custom Map implementation that provides additional utility methods for working with objects and maps.
@@ -54,8 +58,10 @@ declare class Mapper<K, V> extends Map<K, V> {
54
58
  init(key: K, val: V): V;
55
59
  }
56
60
 
57
- declare class $$ {
58
- static set p(a: any);
61
+ declare class log {
62
+ static set i(a: any);
63
+ static set e(a: any);
64
+ static set w(a: any);
59
65
  }
60
66
  declare class idm {
61
67
  _c: number;
@@ -111,7 +117,7 @@ declare class Meta {
111
117
  themeColor(color: string): this;
112
118
  openGraph(og: Omit<OG, "card">): this;
113
119
  twitter(og: OG): this;
114
- and(metas: meta$1<string>[]): this;
120
+ push(metas: meta$1<string>[]): void;
115
121
  private set meta(value);
116
122
  }
117
123
 
@@ -137,9 +143,9 @@ type link<T> = {
137
143
  crossorigin?: T;
138
144
  };
139
145
  type impmap = {
140
- imports?: obj<string>;
141
- scopes?: obj<string>;
142
- integrity?: obj<string>;
146
+ imports?: obj$1<string>;
147
+ scopes?: obj$1<string>;
148
+ integrity?: obj$1<string>;
143
149
  };
144
150
  type script<T> = {
145
151
  async?: T;
@@ -164,6 +170,8 @@ interface headAttr {
164
170
  meta?: meta<string>[] | Meta;
165
171
  link?: link<string>[];
166
172
  script?: script<string | boolean>[];
173
+ css?: string[] | string;
174
+ description?: string;
167
175
  }
168
176
  declare class head implements headAttr {
169
177
  title?: string;
@@ -182,7 +190,7 @@ type CSSinT$1 = {
182
190
  type headType = Mapper<keyof head, any>;
183
191
  declare class htmlHead {
184
192
  lang: string;
185
- protected htmlHead: headType;
193
+ htmlHead: headType;
186
194
  head: (heads?: headAttr) => void;
187
195
  constructor();
188
196
  }
@@ -202,6 +210,8 @@ declare class MinStorage {
202
210
  */
203
211
  declare class Storage$1<T extends MinStorage> {
204
212
  private _storage;
213
+ private CC;
214
+ constructor();
205
215
  set(min: T): void;
206
216
  get(path: string): [T | undefined, Record<string, string>];
207
217
  }
@@ -215,8 +225,9 @@ declare class __ {
215
225
  inner?: any;
216
226
  }): HTMLElement;
217
227
  static randFrom(arr: any[] | Object): any;
228
+ static randomAZ: () => string;
218
229
  static makeID: (length: number) => string;
219
- static class(a: obj<any>, classes: string[]): void;
230
+ static class(a: obj$1<any>, classes: string[]): void;
220
231
  static get O(): {
221
232
  vals: {
222
233
  <T>(o: {
@@ -245,9 +256,21 @@ declare class __ {
245
256
  };
246
257
  static get is(): typeof is;
247
258
  static get return(): typeof returner;
259
+ static sleep: (ms?: number) => Promise<unknown>;
260
+ static get screen(): "xs" | "sm" | "smd" | "md" | "lg" | "xl" | "xxl" | undefined;
261
+ bytes(bytes: number): string;
262
+ static format(val: any): Formatteer;
248
263
  }
249
264
  declare class returner {
250
- static array(val: any): any[];
265
+ static arr(val: any): any[];
266
+ static num(val: any, iferr?: any): number;
267
+ }
268
+ declare class Formatteer {
269
+ val: any;
270
+ constructor(val: any);
271
+ get px(): string;
272
+ get rem(): string;
273
+ get pr(): string;
251
274
  }
252
275
 
253
276
  declare class CATT {
@@ -285,7 +308,7 @@ declare class eStream {
285
308
  stream: EventSource;
286
309
  url: string;
287
310
  constructor(eurl: string, withCredentials: boolean);
288
- on(event: obj<(a: MessageEvent) => void>): this;
311
+ on(event: obj$1<(a: MessageEvent) => void>): this;
289
312
  }
290
313
  declare function eventStream(url: string, withCredentials?: boolean): eStream;
291
314
 
@@ -298,14 +321,14 @@ declare class __I {
298
321
  get bool(): boolean | null;
299
322
  get json(): any | null;
300
323
  }
301
- declare class storageInterface {
324
+ type storeValTypes = keyof __I;
325
+ declare class storageInterface<T> {
302
326
  key: string;
303
- func: (() => any) | null;
327
+ state: Stateful<T> | null;
304
328
  storage: Storage;
305
- constructor(item: obj<() => any> | string, _type?: "local" | "session");
329
+ constructor(item: obj$1<Stateful<T>> | string, _type?: "local" | "session", init?: storeValTypes);
306
330
  get as(): __I;
307
331
  get value(): string | null;
308
- get save(): void;
309
332
  set set(val: any);
310
333
  get remove(): void;
311
334
  }
@@ -314,45 +337,155 @@ declare class storageInterface {
314
337
  * Local Storage
315
338
  */
316
339
  declare const local: {
317
- get: (item: obj<() => any> | string) => storageInterface;
340
+ get: <T>(item: obj$1<Stateful<T>> | string) => storageInterface<T>;
341
+ init: <T>(item: obj$1<Stateful<T>>, as: storeValTypes) => storageInterface<T>;
318
342
  };
319
343
 
320
344
  /**
321
345
  * Session Storage
322
346
  */
323
347
  declare const session: {
324
- get: (item: obj<() => any> | string) => storageInterface;
348
+ get: <T>(item: obj$1<Stateful<T>> | string) => storageInterface<T>;
325
349
  };
326
350
 
327
- declare class doc<T = Record<string, string>> extends head {
351
+ type kf = KeyframeAnimationOptions;
352
+ type KFType = (CSSinT | obj$1<V>)[] | CSSinT | obj$1<V>;
353
+ declare class anim {
354
+ private e;
355
+ opt: kf;
356
+ constructor(e: Elem);
357
+ animate(keyframes: CSSinT[] | CSSinT, options?: kf): Elem<HTMLElement>;
358
+ get slide(): {
359
+ left: (options?: kf) => anim;
360
+ right: (options?: kf) => anim;
361
+ up: (options?: kf) => anim;
362
+ down: (options?: kf) => anim;
363
+ };
364
+ fade(options?: kf): this;
365
+ shake(XorY?: string, opt?: kf): this;
366
+ color(c?: string[], opt?: kf): this;
367
+ bg(c?: string | string[], opt?: kf): this;
368
+ bounce(sVal?: number, opt?: kf): this;
369
+ }
370
+
371
+ declare class Eget<T extends Elements = HTMLElement> {
372
+ e: T;
373
+ query?: string | undefined;
374
+ constructor(e: T, query?: string | undefined);
375
+ get a(): anim;
376
+ get all(): T[];
377
+ get attr(): {
378
+ has: (attr: string) => boolean;
379
+ get: (attr: string) => string | null;
380
+ del: (attr: string) => Eget<T>;
381
+ set: (attrs: obj$1<any>) => Eget<T>;
382
+ };
383
+ get children(): Elem<T>[];
384
+ get click(): this;
385
+ get delete(): this;
386
+ get disabled(): boolean;
387
+ get focus(): this;
388
+ get href(): string;
389
+ get id(): string;
390
+ get inner(): string;
391
+ get offsetParent(): Elem | undefined;
392
+ get parent(): Elem | undefined;
393
+ get hash(): string;
394
+ get path(): string;
395
+ get rect(): DOMRect;
396
+ get remove_element(): this;
397
+ get style(): {
398
+ set: (style: CSSinT | obj$1<V | null>, delayOrFN?: number | ((e?: any) => void)) => Elem<HTMLElement>;
399
+ get: (prop: keyof CSSStyleDeclaration | string) => string;
400
+ del: (...props: (keyof CSSStyleDeclaration | string)[]) => void;
401
+ };
402
+ get submit(): any;
403
+ get tag(): string;
404
+ get value(): any;
405
+ get unload(): () => void;
406
+ set append(val: any);
407
+ set appendfirst(val: any);
408
+ set inner(val: any);
409
+ set disabled(vl: boolean);
410
+ set id(did: string);
411
+ set value(vl: any);
412
+ }
413
+
414
+ type fn<E, T> = (e?: E) => T;
415
+ declare class Elem<T extends Elements = HTMLElement> extends Eget<T> {
416
+ constructor(e: T, query?: string);
417
+ add(...className: string[]): this;
418
+ remove(...className: string[]): this;
419
+ toggle(className: string | fn<any, string>, force?: boolean): this;
420
+ has(e: any | null): boolean;
421
+ insert(position: InsertPosition): {
422
+ HTML: (...text: string[]) => Elem<T>;
423
+ element: (...elem: HTMLElement[]) => Elem<T>;
424
+ text: (this: Elem<T>, ...text: string[]) => Elem<T>;
425
+ };
426
+ is(tp: {
427
+ dom?: string;
428
+ class?: string | string[];
429
+ }): boolean;
430
+ on(event: keyof events, handler: (e?: any) => void, useCapture?: boolean): this;
431
+ remove_on(event: keyof DocumentEventMap, handler: EventListenerOrEventListenerObject, useCapture?: boolean): this;
432
+ timed(fn: (ee?: Elem<T>) => void, timeout?: number): this;
433
+ animate(keyframes: KFType, options?: kf, onComplete?: fn<any, void>): this;
434
+ animate(keyframes: KFType, onComplete?: fn<any, void>): this;
435
+ }
436
+
437
+ interface CLI {
438
+ id?: string;
439
+ class?: string;
440
+ }
441
+ declare function $<T extends Elements = HTMLElement>(query: CLI): Elem<T> | undefined;
442
+ declare function $<T extends Elements = HTMLElement>(query: string): Elem<T> | undefined;
443
+ declare function $<T extends Elements = HTMLElement>(element: T): Elem<T>;
444
+ type _$<T extends Elements = HTMLElement> = Elem<T> | undefined;
445
+ type $E<T extends Elements = HTMLElement> = Elem<T>;
446
+ declare class Ref<T extends Elements = HTMLElement> {
447
+ state: Stateful<_$<T>>;
448
+ constructor();
449
+ get element(): T | undefined;
450
+ set element(elem: T | undefined);
451
+ get $(): _$<T>;
452
+ }
453
+ declare const useRef: <T extends Elements = HTMLElement>() => Ref<T>;
454
+
455
+ declare class doc<T extends {
456
+ args?: Record<string, any>;
457
+ data?: Record<string, any>;
458
+ } = Record<string, any>> extends head {
328
459
  path: string;
329
- args: T;
460
+ args: T["args"];
330
461
  id: string;
331
462
  status: number;
332
463
  lang?: string;
333
464
  import?: any;
334
- _data: T;
335
- constructor(path: string, args: T | undefined, id: string, status?: number);
336
- fetch?(): Promise<Record<string, string>>;
465
+ _data: T["data"];
466
+ static route: string;
467
+ constructor(path: string, args: T["args"] | undefined, id: string, status?: number);
468
+ fetch?(): Promise<Record<string, any>>;
337
469
  head?(): Promise<void> | void;
338
470
  body?(): Promise<Dom> | Dom;
339
471
  loader(): Promise<any[]>;
340
472
  getHeadAttr(head?: headAttr, ...toMap: headType[]): headType;
341
- set data(data: obj<any>);
342
- get data(): T;
473
+ set data(data: obj$1<any>);
474
+ get data(): T["data"];
343
475
  }
344
476
 
345
- declare class websocket<T = Record<string, string>> {
477
+ declare class websocket<T = Record<string, any>> {
346
478
  path: string;
347
- args: T;
479
+ protected args: T;
348
480
  ws: WebSocket;
481
+ static route: string;
349
482
  isConnected: Stateful<boolean>;
350
483
  data: T;
351
484
  constructor(path: string, args?: T);
352
- open(event: Event): Promise<void> | void;
353
- message(event: MessageEvent): Promise<void> | void;
354
- close(event: CloseEvent): Promise<void> | void;
355
- error(event: Event): Promise<void> | void;
485
+ protected open(event: Event): Promise<void> | void;
486
+ protected message(event: MessageEvent): Promise<void> | void;
487
+ protected close(event: CloseEvent): Promise<void> | void;
488
+ protected error(event: Event): Promise<void> | void;
356
489
  get connect(): this;
357
490
  get reconnect(): this;
358
491
  get disconnect(): this;
@@ -367,59 +500,74 @@ declare class websocket<T = Record<string, string>> {
367
500
  set send(message: string | ArrayBufferLike | Blob | ArrayBufferView);
368
501
  }
369
502
  declare class socket {
370
- private yra;
371
- constructor(yra: Router);
503
+ protected yvee: Pager;
504
+ constructor(yvee: Pager);
372
505
  load(_path: string): Promise<websocket<{}> | undefined>;
373
506
  unload(_path: string): void;
374
507
  }
375
508
 
376
- interface yveeCfg {
377
- pushState?: boolean;
378
- classes?: string | string[];
379
- }
380
- declare class Router extends minClient {
381
- private isYRA;
382
- protected unload: boolean;
509
+ declare class Pager extends minClient {
510
+ protected config: routerCfg;
383
511
  protected hook?: () => void;
384
512
  protected root: Stateful<ctx[]>;
385
- protected socket: socket;
513
+ socket: socket;
386
514
  id: string;
387
515
  path: Stateful<string>;
388
516
  lastPath: Stateful<string>;
517
+ loading: Stateful<boolean>;
518
+ mainElement?: HTMLElement;
389
519
  A: (a: attr & {
390
520
  href: string;
521
+ topRef?: Stateful<_$>;
522
+ top?: number | (() => number);
391
523
  }, ...D: ctx[]) => Dom;
392
- Main: (a: attr & {
393
- load?: string;
394
- }) => Dom;
524
+ Main: (a: attr) => Dom;
395
525
  load: (path?: string, data?: obj<string>) => Promise<this>;
396
- constructor(ImportMeta: ImportMeta, config?: yveeCfg, isYRA?: boolean);
526
+ matchPath: (str: string) => boolean;
527
+ protected isYvee: boolean;
528
+ constructor(config?: routerCfg, events?: events);
397
529
  protected hooker(): void;
398
- protected class(this: Router, _path: string, _error: number, isError?: boolean): Promise<doc<{}>>;
530
+ protected class(this: Pager, _path: string, _error: number, isError?: boolean): Promise<doc<{}>>;
399
531
  protected fetch(CL?: doc<{}>): Promise<void>;
400
532
  protected processHead(CL?: doc<{}>, head?: headAttr): Promise<headType>;
401
533
  private processClassHead;
402
534
  private processDefaultHead;
403
- protected render(_path: string, _error?: number, data?: obj<string>, head?: headAttr, isClient?: boolean, isError?: boolean): Promise<{
535
+ render(_path: string, _error?: number, data?: obj<string>, head?: headAttr, isClient?: boolean, isError?: boolean): Promise<{
404
536
  lang: string;
405
537
  heads: headType;
406
538
  done: boolean;
407
539
  }>;
408
540
  }
409
- declare class Yvee extends Router {
541
+
542
+ declare function pushHistory(path?: string, title?: string): void;
543
+
544
+ interface routerCfg {
545
+ classes?: string | string[];
546
+ id?: string;
547
+ base?: string;
548
+ }
549
+ interface yveeCfg extends routerCfg {
550
+ pushState?: boolean;
551
+ }
552
+ declare class Yvee extends Pager {
553
+ protected config: yveeCfg;
554
+ protected isYvee: boolean;
410
555
  protected unload: boolean;
411
- constructor(ImportMeta: ImportMeta, { classes, pushState }?: yveeCfg);
412
- html({ path, data, status, attr, }: {
413
- path: string;
414
- data?: Record<string, string>;
415
- status?: number;
416
- attr?: string;
417
- }): Promise<string>;
418
- }
419
- type RouteType = (path: string) => <Q extends typeof doc<{}>>(f: Q) => Q;
420
- declare const Routes: (fn: (route: RouteType) => void) => (route: RouteType) => void;
421
- type ErrorType = (...codes: number[]) => <Q extends typeof doc<{}>>(f: Q) => Q;
422
- declare const Errors: (fn: (error: ErrorType) => void) => (error: ErrorType) => void;
556
+ constructor(config?: yveeCfg, events?: events);
557
+ }
558
+ declare const Routes: (fn: (Yvee: Yvee) => void) => (Yvee: Yvee) => void;
559
+ interface headAttrPlus {
560
+ route?: string;
561
+ base?: string;
562
+ index?: string;
563
+ id?: string;
564
+ bodyattr?: obj$1<V>;
565
+ data?: Record<string, any> | (() => Promise<Record<string, any>> | Record<string, any>);
566
+ }
567
+ type headFN<T = {}> = (a: Record<string, any> & T) => Promise<headAttr> | headAttr;
568
+ type ND<T = Record<string, any>> = (a: renderConfig & T) => Dom | Promise<Dom>;
569
+ declare function Render<T = Record<string, any>>(DOM: ND<T>, head?: headAttr | headFN<T>, cfg?: headAttrPlus): Promise<({ path, data, status }: serverRender) => Promise<string>>;
570
+ declare function Render<T = Record<string, any>>(DOM: ND<T>, App: Yvee): Promise<({ path, data, status }: serverRender) => Promise<string>>;
423
571
 
424
572
  declare class ClientPath extends MinStorage {
425
573
  id: string;
@@ -432,8 +580,6 @@ declare class SocketPath extends MinStorage {
432
580
  constructor(path: string, id: string, cls: typeof websocket<{}>);
433
581
  }
434
582
  declare class minClient extends htmlHead {
435
- protected ImportMeta: ImportMeta;
436
- protected config: yveeCfg;
437
583
  protected storage: Storage$1<ClientPath>;
438
584
  protected errorStorage: Storage$1<ClientPath>;
439
585
  protected wssStorage: Storage$1<SocketPath>;
@@ -444,20 +590,22 @@ declare class minClient extends htmlHead {
444
590
  route: (path: string) => <Q extends typeof doc<{}>>(f: Q) => Q;
445
591
  error: (...codes: number[]) => <Q extends typeof doc<{}>>(f: Q) => Q;
446
592
  wss: (path: string) => <Q extends typeof websocket<{}>>(f: Q) => Q;
447
- constructor(ImportMeta: ImportMeta, config: yveeCfg);
593
+ base: string;
594
+ constructor(base?: string);
595
+ protected _base(str: string): string;
448
596
  protected getPath(path: string): Promise<[ClientPath | undefined, Record<string, string>]>;
449
597
  protected loadError(code: number): Promise<[ClientPath | undefined, Record<string, string>]>;
450
598
  protected loadWSS(path: string): Promise<[SocketPath | undefined, Record<string, string>]>;
451
599
  }
452
600
 
453
- type Elements = HTMLElementTagNameMap[keyof HTMLElementTagNameMap];
601
+ type Elements = HTMLElementTagNameMap[keyof HTMLElementTagNameMap] | SVGElementTagNameMap[keyof SVGElementTagNameMap];
454
602
 
455
603
  type hookFN<T extends any[]> = (...args: statefulValue<T>) => void;
456
604
  interface stateCFG {
457
605
  id?: string;
458
606
  init?: boolean;
459
607
  }
460
- declare function stateHook<T extends any[]>(callback: hookFN<T>, statefuls: [...{
608
+ declare function StateHook<T extends any[]>(callback: hookFN<T>, statefuls: [...{
461
609
  [K in keyof T]: Stateful<T[K]>;
462
610
  }], { id, init }?: stateCFG): () => void;
463
611
 
@@ -478,31 +626,33 @@ declare class Stateful<T> extends EventTarget {
478
626
  call<Q>(callback: (this: Elements, arg: T) => Q, entry: string): (id: string) => () => void;
479
627
  hook<T extends any[]>(callback: hookFN<T>): (id: string) => () => void;
480
628
  }
481
- declare function State<T>(value: T): Stateful<T>;
629
+ declare function State<T>(value: T, options?: AddEventListenerOptions): Stateful<T>;
482
630
 
483
631
  type X2 = V | V[];
484
- type X3 = X2 | Stateful<X2>;
632
+ type X3 = X2 | Stateful<X2> | null | undefined;
485
633
  type CSSinT = {
486
634
  [P in keyof CSSStyleDeclaration]?: X3;
487
635
  } & {
488
636
  [key: string]: X3;
489
637
  };
490
- interface c_events {
491
- watch?: (this: Elements, e: Elements) => [(...args: any[]) => void, Stateful<any> | Stateful<any>[], boolean?];
492
- ready?: (this: Elements, e: Elements) => void;
493
- resize?: (this: Elements, e: UIEvent) => void;
494
- beforeunload?: (this: Elements, e: BeforeUnloadEvent) => void;
495
- popstate?: (this: Elements, e: PopStateEvent) => void;
496
- winscroll?: (this: Elements, e: Event) => void;
497
- winload?: (this: Elements, e: Event) => void;
498
- winfocus?: (this: Elements, e: Event) => void;
499
- winblur?: (this: Elements, e: Event) => void;
500
- }
638
+ interface c_events<T extends Elements = HTMLElement> {
639
+ state?: (this: T, e: T) => [(...args: any[]) => void, Stateful<any>[], boolean?];
640
+ ready?: (this: T, e: T) => void;
641
+ resize?: (this: T, e: UIEvent) => void;
642
+ beforeunload?: (this: T, e: BeforeUnloadEvent) => void;
643
+ popstate?: (this: T, e: PopStateEvent) => void;
644
+ winscroll?: (this: T, e: Event) => void;
645
+ winload?: (this: T, e: Event) => void;
646
+ winfocus?: (this: T, e: Event) => void;
647
+ winblur?: (this: T, e: Event) => void;
648
+ }
649
+ type XU4 = V | undefined | XU4[];
501
650
  interface baseAttr {
502
- style?: CSSinT;
503
- on?: events;
651
+ style?: CSSinT | string;
652
+ on?: events<any>;
504
653
  id?: string;
505
- class?: X3;
654
+ class?: XU4 | Stateful<X2>;
655
+ ref?: Ref;
506
656
  }
507
657
  declare class Dom {
508
658
  tag: string;
@@ -518,121 +668,21 @@ declare class Dom {
518
668
  declare function dom(tag: string | ((attr: attr, ...ctx: ctx[]) => Dom), attr?: attr | null, ...ctx: ctx[]): Dom;
519
669
  declare const frag: (attr: attr, ...dom: Dom[]) => Dom[];
520
670
 
521
- type kf = KeyframeAnimationOptions;
522
- type KFType = (CSSinT | obj<V>)[] | CSSinT | obj<V>;
523
- declare class anim {
524
- private e;
525
- opt: kf;
526
- constructor(e: Elem);
527
- animate(keyframes: CSSinT[] | CSSinT, options?: kf): Elem<HTMLElement>;
528
- get slide(): {
529
- left: (options?: kf) => anim;
530
- right: (options?: kf) => anim;
531
- up: (options?: kf) => anim;
532
- down: (options?: kf) => anim;
533
- };
534
- fade(options?: kf): this;
535
- shake(XorY?: string, opt?: kf): this;
536
- color(c?: string[], opt?: kf): this;
537
- bg(c?: string | string[], opt?: kf): this;
538
- bounce(sVal?: number, opt?: kf): this;
539
- }
540
-
541
- declare class Eget<T extends TElem = HTMLElement> {
542
- e: T;
543
- query?: string | undefined;
544
- constructor(e: T, query?: string | undefined);
545
- get a(): anim;
546
- get all(): T[];
547
- get attr(): {
548
- has: (attr: string) => boolean;
549
- get: (attr: string) => string | null;
550
- del: (attr: string) => Eget;
551
- set: (attrs: obj<any>) => Eget;
552
- };
553
- get children(): Elem<T>[];
554
- get click(): this;
555
- get delete(): this;
556
- get disabled(): boolean;
557
- get focus(): this;
558
- get href(): string;
559
- get id(): string;
560
- get inner(): string;
561
- get offsetParent(): Elem | undefined;
562
- get parent(): Elem | undefined;
563
- get path(): string;
564
- get rect(): DOMRect;
565
- get remove_element(): this;
566
- get style(): {
567
- set: (style: CSSinT | obj<V | null>, delayOrFN?: number | ((e?: any) => void)) => Elem<HTMLElement>;
568
- get: (prop: keyof CSSStyleDeclaration | string) => string;
569
- del: (...props: (keyof CSSStyleDeclaration | string)[]) => void;
570
- };
571
- get submit(): any;
572
- get tag(): string;
573
- get value(): any;
574
- get unload(): () => void;
575
- set append(val: any);
576
- set appendfirst(val: any);
577
- set inner(val: any);
578
- set disabled(vl: boolean);
579
- set id(did: string);
580
- set value(vl: any);
581
- }
582
-
583
- type TElem = HTMLElement & InstanceType<typeof Element>;
584
- type fn<E, T> = (e?: E) => T;
585
- declare class Elem<T extends TElem = HTMLElement> extends Eget {
586
- constructor(e: T, query?: string);
587
- add(...className: string[]): this;
588
- remove(...className: string[]): this;
589
- toggle(className: string | fn<any, string>, force?: boolean): this;
590
- has(e: any | null): boolean;
591
- insert(position: InsertPosition): {
592
- HTML: (...text: string[]) => Elem;
593
- element: (...elem: HTMLElement[]) => Elem;
594
- text: (this: Elem, ...text: string[]) => Elem;
595
- };
596
- is(tp: {
597
- dom?: string;
598
- class?: string | string[];
599
- }): boolean;
600
- on(event: keyof events, handler: (e?: any) => void, useCapture?: boolean): this;
601
- remove_on(event: keyof DocumentEventMap, handler: EventListenerOrEventListenerObject, useCapture?: boolean): this;
602
- timed(fn: (ee?: Elem) => void, timeout?: number): this;
603
- animate(keyframes: KFType, options?: kf, onComplete?: fn<any, void>): this;
604
- animate(keyframes: KFType, onComplete?: fn<any, void>): this;
605
- }
606
-
607
- declare function $<T extends TElem = HTMLElement>(query: string): Elem<T> | undefined;
608
- declare function $<T extends TElem = HTMLElement>(element: T): Elem<T>;
609
- type _$ = Elem | undefined;
610
-
611
- declare class ColorScheme {
612
- state: Stateful<boolean>;
613
- body?: HTMLElement;
614
- click: () => void;
615
- constructor({ toggle, initialState, }?: {
616
- toggle?: string[];
617
- initialState?: boolean;
618
- });
619
- private loader;
620
- get isMatchMediaSupported(): boolean;
621
- get isDark(): boolean;
622
- toggle(clist: DOMTokenList, isDark: boolean, toggles: string[]): void;
623
- }
624
-
625
671
  declare global {
626
- type events = {
627
- [P in keyof GlobalEventHandlersEventMap]?: (this: Elements, e: GlobalEventHandlersEventMap[P]) => void;
628
- } & c_events;
672
+ type events<T extends Elements = HTMLElement> = {
673
+ [P in keyof GlobalEventHandlersEventMap]?: (this: T, e: GlobalEventHandlersEventMap[P]) => void;
674
+ } & c_events<T>;
629
675
  type attr = baseAttr | obj<X3>;
630
676
  type ctx = V | Dom | Stateful<V | Dom> | ctx[];
631
677
  type obj<T> = Record<string, T>;
632
- type DomFN<T extends {}> = (a: attr & T, ...D: ctx[]) => Dom;
678
+ type DomFN<T = {}> = (a: attr & T, ...D: ctx[]) => Dom;
679
+ const BASE_STRING: string;
633
680
  namespace JSX {
634
681
  type Element = Dom;
635
682
  interface IntrinsicElements {
683
+ link: attr;
684
+ base: attr;
685
+ meta: attr;
636
686
  p: attr;
637
687
  br: attr;
638
688
  hr: attr;
@@ -800,5 +850,16 @@ declare global {
800
850
  }
801
851
  }
802
852
  declare const resolvePath: (base: string, relative: string) => string;
853
+ interface renderConfig {
854
+ path: string;
855
+ status: number;
856
+ base: string;
857
+ }
858
+ interface serverRender {
859
+ path: string;
860
+ data?: Record<string, any>;
861
+ status?: number;
862
+ }
863
+ declare const IfClient: <T>(fn: () => T) => T | undefined;
803
864
 
804
- export { $, $$, ColorScheme, Dom, Errors, Meta, Router, Routes, State, Stateful, Yvee, type _$, __, addCSS, cssLoader, doc, dom, eventStream, frag, type headAttr, local, resolvePath, session, stateHook, websocket };
865
+ export { $, type $E, Dom, IfClient, Meta, Pager, Ref, Render, Routes, State, StateHook, Stateful, Yvee, type _$, __, addCSS, cssLoader, doc, dom, eventStream, frag, type headAttr, local, log, pushHistory, type renderConfig, resolvePath, type serverRender, session, useRef, websocket };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var dr=Object.defineProperty;var pr=(t,r)=>{for(var n in r)dr(t,n,{get:r[n],enumerable:!0,configurable:!0,set:(i)=>r[n]=()=>i})};var Xt=function(t,r,n,i){var o=arguments.length,e=o<3?r:i===null?i=Object.getOwnPropertyDescriptor(r,n):i,s;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")e=Reflect.decorate(t,r,n,i);else for(var u=t.length-1;u>=0;u--)if(s=t[u])e=(o<3?s(e):o>3?s(r,n,e):s(r,n))||e;return o>3&&e&&Object.defineProperty(r,n,e),e};var Jt=(t,r)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,r)};var pt={};pr(pt,{isWindow:()=>N,isUndefined:()=>ct,isStr:()=>K,isPlainObject:()=>G,isObj:()=>E,isNumber:()=>q,isNum:()=>gt,isNull:()=>X,isNotWindow:()=>y,isInt:()=>dt,isFN:()=>b,isDict:()=>it,isClassOrId:()=>br,isBool:()=>z,isAsync:()=>Tr,isArraybuff:()=>yr,isArr:()=>h});var b=(t)=>typeof t==="function",Tr=(t)=>t.constructor.name==="AsyncFunction",q=(t)=>{return!isNaN(parseFloat(t))&&isFinite(t)},it=(t)=>{return typeof t==="object"&&t!==null&&!Array.isArray(t)},G=(t)=>{return typeof t==="object"&&t!==null&&Object.getPrototypeOf(t)===Object.prototype},yr=(t)=>{return t instanceof Uint8Array||t instanceof ArrayBuffer||typeof t==="string"},br=(t)=>{return t.startsWith(".")||t.startsWith("#")},z=(t)=>typeof t==="boolean",K=(t)=>typeof t==="string",h=(t)=>Array.isArray(t),E=(t)=>typeof t==="object",gt=(t)=>typeof t==="number",X=(t)=>t===null,ct=(t)=>typeof t==="undefined",dt=(t)=>{return Number.isInteger(Number(t))},N=typeof window!=="undefined",y=typeof window==="undefined";function ot(t,r){a(r).forEach(([n,i])=>{Ut(t,n,{value:i,writable:!1,configurable:!1,enumerable:!0})})}class H{static set p(t){if(Array.isArray(t))console.log(...t);else console.log(t)}}class d{_c=0;_id="";constructor(t){if(this._c=0,this._id=t??p(5),t?.includes("-")){let[r,n]=[t.split("-").slice(0,-1).join("-"),t.split("-").slice(-1)[0]];this._id=r,this._c=q(n)?parseInt(n):0}}get id(){return this._id+"-"+this._c}get mid(){return this._id+"-"+ ++this._c}}var sn=new RegExp(/(\d+)(\d*)/,"m"),xr=(t)=>Array.from({length:t},(r,n)=>n),Er="ABCDEFGHIJKLMNOPQRSTUVWXYZ",$r="abcdefghijklmnopqrstuvwxyz",wr=xr(10).join("");var $=(t)=>JSON.stringify(t),Yt=(t)=>{return JSON.parse(t)},S=(t)=>{if(t.startsWith("webkit"))t="-"+t;return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},p=(t)=>{let r=Er+$r;return Array.from({length:t},(n,i)=>r+(i?wr:"")).reduce((n,i)=>{return n+=i.charAt(Math.floor(Math.random()*i.length))},"")};class f extends Map{obj(t){t&&a(t).forEach(([r,n])=>this.set(r,n))}map(t){t.forEach((r,n)=>{if(r instanceof f)this.set(n,r);else if(h(r)){if(this.lacks(n))this.set(n,[]);this.get(n).push(...r)}else if(E(r))this.ass(n,r);else this.set(n,r)})}ass(t,r){if(!this.has(t))this.set(t,{});T(this.get(t),r)}lacks(t){return!this.has(t)}init(t,r){return this.has(t)?this.get(t):this.set(t,r).get(t)}}var{values:x,keys:J,entries:a}=Object;var{hasOwn:Wt,freeze:Bt,defineProperty:Ut,assign:T}=Object,w=(t)=>{return Object.keys(t).length},et=(t,r)=>{if(!r.has(t))r.set(t,new f);return r.get(t)},V=(t,r)=>{if(!r.has(t))r.set(t,[]);return r.get(t)},Tt=(t,r)=>{let n={added:{},removed:{},modified:{}},i=J(t),o=J(r);for(let e of o){let s=t[e],u=r[e];if(!(e in t))n.added[e]=u;else if(h(s)&&h(u)){if($(s)!==$(u))n.modified[e]={old:s,new:u}}else if(E(s)&&E(u)&&!X(s)&&!X(u)){let m=Tt(s,u);if(w(m.added)||w(m.removed)||w(m.modified))n.modified[e]={old:s,new:u}}else if(s!==u)n.modified[e]={old:s,new:u}}for(let e of i)if(!(e in r))n.removed[e]=t[e];return n};function Pt(t,r){if(t.size!==r.size)return!1;for(let n of t)if(!r.has(n))return!1;return!0}var Ct=(t)=>{return x(t).some((r)=>{return w(r)})};function Gt(t){let r;return class extends t{constructor(...n){if(r)return r;super(...n);Bt(this),r=this}}}var Q=(t,r)=>{return{name:t,content:r}},Hr=(t,r)=>{return{property:t,content:r}},jr=(t,r)=>{return{"http-equiv":t,content:r}};class st{metas=[];constructor(t){t&&this.metas.push(Q("description",t))}author(t){return this.meta=Q("author",t),this}charset(t){return this.meta={charset:t},this}keywords(...t){return this.meta=Q("keywords",t.join(", ")),this}viewport(t){let r=a(t).map(([n,i])=>[S(n),String(i)].join("="));return this.meta=Q("viewport",r.join(", ")),this}httpEquiv(t){return a(t).forEach(([r,n])=>{this.meta=jr(S(r),String(n))}),this}robots(...t){return this.meta=Q("robots",t.join(", ")),this}themeColor(t){return this.meta=Q("theme-color",t),this}openGraph(t){return a(t).forEach(([r,n])=>{this.meta=Hr("og:"+r,String(n))}),this}twitter(t){return a(t).forEach(([r,n])=>{this.meta=Q("twitter:"+r,String(n))}),this}and(t){return this}set meta(t){this.metas.push(t)}}class yt{title;description;base;meta;link;script;css}var Ar=["charset","name","property","http-equiv"],zt=(t,r)=>{r.forEach((n)=>{for(let i of Ar)if(i in n){let o=n[i];t[`${i}_${i==="charset"?"":o}`]=n}})},Dr=(t,r)=>{r.forEach((n)=>{if("href"in n){let i=n.href;t[`${i}`]=n}})};class U{_head;idm;constructor(t){this._head=new f(t)}set head(t){a(t).forEach(([r,n])=>{if(r==="title"||r==="base"){if(n!==void 0)this._head.set(r,n);return}if(n instanceof st)return zt(this._head.init("meta",{}),n.metas);if(!h(n))return;switch(r){case"meta":return zt(this._head.init("meta",{}),n);case"link":return Dr(this._head.init("link",{}),n);case"script":if(n.length){this._head.init(r,[]);let i=n.map((o)=>{if(!o.yid&&this.idm)o.yid="sc"+this.idm.mid;return o});this._head.get(r).push(...i)}return}})}get head(){return this._head}set id(t){this.idm=new d(t)}}var Kt=(t)=>{return a(t).reduce((r,[n,i])=>{return r.push(z(i)&&i?n:`${n}="${i}"`),r},[""]).join(" ")},Nt=(t)=>{if(!t)return"";return[...t].reduce((r,[n,i])=>{if(n==="meta"||n==="link")i=x(i);if(K(i))return r.push(`<${n}>${i}</${n}>`),r;if(!h(i))return r;let o=i.map((e)=>{if(n==="script"){let s={...e};if("yid"in s)return"";let u="";if("importmap"in s)s.type="importmap",u=JSON.stringify(s.importmap),delete s.importmap;else if("body"in s)u=s.body,delete s.body;return`<${n}${Kt(s)}>${u}</${n}>`}return`<${n}${Kt(e)}>`});return r.push(...o),r},[]).join("")};class bt{lang="en";htmlHead=new f;head;constructor(){this.head=(t={})=>{let r=new U(this.htmlHead);r.head=t,this.htmlHead=r.head}}}var xt=(t)=>{if(y)return;return new Promise((r,n)=>{let i=document.createElement("link");if(t.rel!=="stylesheet")t.rel="stylesheet",t.as="style";a(t).forEach(([o,e])=>{i.setAttribute(o,e)}),i.onload=()=>r(i),i.onerror=()=>n(new Error("Failed to load CSS")),document.head.appendChild(i)})},Vt=(t)=>{return new Promise((r,n)=>{let i=document.createElement("script"),o="";if("importmap"in t)t.type="importmap",o=JSON.stringify(t.importmap),delete t.importmap;else if("body"in t)o=t.body,delete t.body;if(o)i.innerHTML=o;a(t).forEach(([e,s])=>{i.setAttribute(e,s)}),i.onload=()=>r(i),i.onerror=()=>n(new Error("Failed to load Script")),document.head.appendChild(i)})},Rr=()=>{let r=document.querySelector("#d-css")?.sheet;if(r)return r;let n=document.createElement("style");return n.id="d-css",document.head.appendChild(n),n.sheet},qr=(t,r)=>{for(let n=0;n<t.cssRules.length;n++)if(t.cssRules[n].selectorText===r)return!0;return!1},Lr=(t)=>Object.entries(t).map(([r,n])=>`${S(r)}: ${n};`).join(" ");function Mr(t,r={}){if(y)return;let n=Rr();if(!n)return;if(!qr(n,t))n.insertRule(`${t} { ${Lr(r)} }`,n.cssRules.length)}var Ot=(t,r=!1)=>{if(q(t))return[+t,dt(t)?"int":"float"];if(r&&/\.\w+$/.test(t))return[t,"file"];if(t==="/")return[t,"-"];if(t.length===36&&t.match(/\-/g)?.length===4)return[t,"uuid"];return[t,"string"]},ut=(t)=>{let r=t.startsWith("/")?t:"/"+t,n=r.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[i,o]=n.reduce(([e,s],u)=>{if(u.includes("<")){let m=u.match(/(?<=<)[^/].*?(?=>|$)/g);if(m?.length){let[l,c]=m[0].split(":");if(l&&c)e.push(l),s.push(c)}}else e.push(u===">"?"/":u);return[e,s]},[[],[]]);if(r.endsWith("/")&&r.length>1)i.push("/");return{parsed:i,args:o}};class ft{storage=new f;cache(t,r){if(this.storage.lacks(t))this.storage.set(t,r());return this.storage.get(t)}}var Sr=["int","float","file","uuid","string"],Qr=new ft;class Y{_storage=new f;set(t){let{parsed:r,path:n}=t,i=$(r);if(!this._storage.get(i))this._storage.set(i,t);else throw`path: ${n} already used.`}get(t){let{parsed:r}=Qr.cache(t,()=>ut(t)),n={},i=this._storage.get($(r));if(!i&&t!=="/")for(let o of this._storage.keys()){let e=[],s=Yt(o);if(r.length===s.length){let u=s.map((c,A)=>{let D=Ot(r[A],r.length-1===A);if(c===D[0])return D[0];if(Sr.includes(D[1]))return e.push(D[0]),D[1];return c}),m=$(u);if(this._storage.has(m)){i=this._storage.get(m),i?.args.forEach((c,A)=>{n[c]=e[A]});break}}}return[i,n]}}class O{path="";parsed=[];args=[];constructor(t){ot(this,{path:t,...ut(t)})}}class _t{static rand(t=6,r){if(r)return Math.floor(Math.random()*(r-t+1)+t);return Math.floor(Math.random()*t)+1-1}static fill(t,r=null){return Array(t).fill(r)}static new({dom:t,id:r,inner:n}){let i=document.createElement(t);if(r)i.id=r;if(n)i.innerHTML=n;return i}static randFrom(t){if(Array.isArray(t)){let r=t.length,n=this.rand(0,r-1);return t[n]}else if(typeof t=="object"){let r=J(t),n=r.length,i=this.rand(0,n-1);return r[i]}}static makeID=p;static class(t,r){let n=r;if(t?.class)n.push(...h(t.class)?t.class:[t.class]);t.class=r}static get O(){return{vals:x,keys:J,items:a,has:Wt,ass:T,len:(t={})=>J(t).length}}static get is(){return pt}static get return(){return kt}}class kt{static array(t){return h(t)?t:[t]}}var Et={},F={};class vt{stream;url;constructor(t,r){if(this.url=t,t in Et)this.stream=Et[t];else this.stream=new EventSource(t,{withCredentials:r}),Et[t]=this.stream,F[this.url]={}}on(t){let r=this.stream;return a(t).forEach(([n,i])=>{if(n in F[this.url])F[this.url][n].forEach((o)=>{this.stream.removeEventListener(n,o)}),F[this.url][n]=[];if(r.addEventListener(n,i),!(n in F[this.url]))F[this.url][n]=[];F[this.url][n].push(i)}),this}}function tr(t,r=!0){return new vt(t,r)}class rr{value;constructor(t){this.value=t}get str(){return String(this.value).toString()=="null"?null:String(this.value).toString()}get int(){if(q(this.value))return parseInt(this.value);else return null}get float(){if(q(this.value))return parseFloat(this.value);else return null}get bool(){if(this.value==="true")return!0;else if(this.value=="false")return!1;else return null}get json(){if(this.value)return JSON.parse(this.value);return null}}class _{key;func;storage;constructor(t,r="local"){if(typeof t=="object"){let[n,i]=a(t)[0];this.key=n,this.func=i}else this.key=t,this.func=null;this.storage=r=="local"?localStorage:sessionStorage}get as(){return new rr(this.storage.getItem(this.key))}get value(){return this.storage.getItem(this.key)}get save(){if(this.func)this.set=this.func();return}set set(t){if(typeof t=="object")this.storage.setItem(this.key,JSON.stringify(t));else this.storage.setItem(this.key,String(t))}get remove(){this.storage.removeItem(this.key);return}}var k={get:(t)=>new _(t)};var nr={get:(t)=>new _(t,"session")};class mt extends O{id;cls;constructor(t,r,n){super(t);this.id=r;this.cls=n}}class ir extends O{id;cls;constructor(t,r,n){super(t);this.id=r;this.cls=n}}class $t extends bt{ImportMeta;config;storage=new Y;errorStorage=new Y;wssStorage=new Y;route;error;wss;constructor(t,r){super();this.ImportMeta=t;this.config=r;this.route=(n)=>{return(i)=>{return this.storage.set(new mt(n,p(5),i)),i}},this.wss=(n)=>{return(i)=>{return this.wssStorage.set(new ir(n,p(5),i)),i}},this.error=(...n)=>{return(i)=>{if(n.length)n.forEach((o)=>{this.errorStorage.set(new mt(o.toString(),p(5),i))});else this.errorStorage.set(new mt("404",p(5),i));return i}}}async getPath(t){return this.storage.get(t)}async loadError(t){return this.errorStorage.get(t.toString())}async loadWSS(t){return this.wssStorage.get(t)}}var v=new f,tt=(t)=>{if(y)return;let r=v.get(t);if(r?.isConnected)return r;v.delete(t);let n=document.getElementById(t);if(!n)return;return v.set(t,n),n};function or(){let t=[];return v.forEach((r,n)=>{if(!r.isConnected)t.push(n),v.delete(n)}),t}function W(t,r,{id:n="state",init:i}={}){let o=[],e=()=>r.map((u)=>u.value),s=()=>{t(...e())};if(r.forEach((u)=>{o.push(u.hook(s)(n))}),i)s();return()=>{o.forEach((u)=>u())}}var er=(t)=>{t.forEach((r)=>r())};var Fr=(t,r)=>{for(let[n,i]of t){let o=tt(n);if(!o){t.delete(n);continue}i.forEach((e)=>{e.call(o,r)})}};class Z extends EventTarget{options;hooks=new f;states=new f;_value;listening=!1;end;constructor(t,r){super();this.options=r;this._value=t}get value(){return this._value}set value(t){if(X(t)||ct(t))return;if(G(this._value)||h(this._value)){let r=Tt(this._value,t);if(!Ct(r))return}else if(this._value instanceof Set){if(!Pt(this._value,t))return}else if(this._value===t)return;this._value=t,this.dispatchEvent(new CustomEvent("updated",{detail:this._value}))}get listen(){let t=(r)=>{if(er(this.hooks),Fr(this.states,r.detail),!this.states.size&&!this.hooks.size)this.end?.()};if(!this.listening)this.addEventListener("updated",t,this.options),this.listening=!0;return()=>{this.listening&&this.removeEventListener("updated",t,this.options),this.end=void 0,this.listening=!1}}call(t,r){return(n)=>{if(et(n,this.states).set(r,t),!y&&!this.listening)this.end=this.listen;return()=>{if(this.states.has(n))this.states.get(n)?.delete(r)}}}hook(t){return(r)=>{if(this.hooks.set(r,t),!y&&!this.listening)this.end=this.listen;return()=>{if(this.hooks.has(r))this.hooks.delete(r)}}}}function j(t){return new Z(t)}var B=(t)=>{if(h(t))return t.join(" ");else if(E(t)){if(it(t))return $(t)}else if(b(t))return B(t());else if(t!==void 0&&t!==null)return z(t)?t?"":"false":String(t);return""};function Zr(t,r){switch(r??t){case"style":return function(n){this.style.setProperty(t,n)};default:return function(n){this.setAttribute(t,n)}}}class wt{attr;constructor(t={}){this.attr=t}get(t,r=this.attr,n){let i=(o,e)=>{if(h(e))t.attr_push(o,B(e));else if(e instanceof Z){let s=n?`${n}_${o}`:o;t.states.push(e.call(Zr(o,n),s)),i(o,e.value)}else if(E(e)){if(it(e)&&!n)this.get(t,e,o)}else t.attr_push(o,B(e),n)};a(r).forEach(([o,e])=>{if(["on"].includes(o))E(r.on)&&t.events.obj(r.on);else i(o,e)})}}class P{xid;IDM;map=new f;states=[];events=new f;OZ;constructor(t,r=new d,n){this.xid=t;this.IDM=r;this.OZ=n??new ht}attr_push(t,r,n){let i=n??t;if(!this.map.has(i))this.map.set(i,[]);let o=n?`${S(t)}:${r};`:r;this.map.get(i).push(o)}get attr(){let t=[""];return this.map.forEach((r,n)=>{let i=r.join("");t.push(i?`${n}="${i}"`:n)}),t.join(" ")}set id(t){if(!this.map.has("id"))this.map.set("id",[t])}get id(){return this.map.get("id")?.join("")}}var Ir=(t,r,n)=>{return t.addEventListener(r,n),()=>{t.removeEventListener(r,n)}},rt={};class ht{events=new f;states=new f;winStates=new f;windowEvents=new f;resetST=new f;resetEV=new f;constructor(){}get keys(){return[...new Set([...this.states.keys(),...this.events.keys()])]}set(t){let{id:r,events:n,states:i}=t;if(r){if(n.size)this.events.set(r,n);if(i.length)this.states.set(r,i)}return this}push(t){return t.events.forEach((r,n)=>{r.forEach((i,o)=>{et(n,this.events).set(o,i)})}),t.states.forEach((r,n)=>{V(n,this.states).push(...r)}),this}get stage(){return this.events.forEach((t,r)=>{this.events.delete(r);let n=tt(r);if(!n){this.events.delete(r);return}t.forEach((i,o)=>{switch(o){case"ready":i.apply(n,[n]);break;case"resize":case"beforeunload":case"popstate":case"winscroll":case"winload":case"winfocus":case"winblur":let e=o.replace(/^win/,"");this.windowEvents.init(e,new f).set(r,i);break;case"watch":let[s,u,m]=i.apply(n,[n]),l=h(u)?u:[u],c=()=>l.map((D)=>D.value),A=()=>s(...c());if(m)A();l.forEach((D)=>V(r,this.resetST).push(D.call(A,r+"_watch")(r)));break;default:V(r,this.resetEV).push(Ir(n,o,i))}})}),this.processWindowEvents,this.states.forEach((t,r)=>{this.states.delete(r),t.forEach((n)=>{V(r,this.resetST).push(n(r))})}),this}get processWindowEvents(){let t=(r,n)=>{let i=(o)=>{n.forEach((e,s)=>{let u=tt(s);if(u)e.call(u,o);else this.windowEvents.get(r)?.delete(s)})};return window.addEventListener(r,i),()=>{window.removeEventListener(r,i)}};return this.windowEvents.forEach((r,n)=>{if(r.size){if(!rt[n])rt[n]=t(n,r)}else if(rt[n])rt[n](),delete rt[n]}),this}reset(t){return t.forEach((r)=>{this.windowEvents.forEach((n,i)=>{if(n.has(r))n.delete(r)}),this.resetEV.get(r)?.forEach((n)=>{n()}),this.resetST.get(r)?.forEach((n)=>{n()}),this.resetST.delete(r),this.resetEV.delete(r)}),this}RPS(t){if(t){let r=or();this.reset(r);let n=t.keys;if(n.length)this.reset(n).push(t).stage}return this}}var R=new ht;var Xr=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],Jr=(t)=>Xr.includes(t);function Ur(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}var at=(t,r)=>{if(h(t))return t.map((n)=>at(n,r)).join("");else if(t instanceof L){let n=t.__(r.IDM),{ctx:i,oz:o}=n;return r.OZ.push(o),i}else if(E(t))return $(t);else if(b(t))return at(t(),r);else if(t!==void 0&&t!==null)return Ur(t);return""},sr=(t,r)=>{let n=new d(t),i=new P(n.id,n);return{ctx:at(r,i),catt:i}};function Yr(t){let r=this.id;if(r){let{ctx:n,catt:i}=sr(r,t);if(this.innerHTML!==n)this.innerHTML=n,R.RPS(i.OZ)}}var Ht=(t,r,n,i=[])=>{if(h(t))t.forEach((o)=>{Ht(o,t.length,n,i)});else if(t instanceof Z)if(r>1)Ht(M("div",{},t),r,n,i);else{let o=t.value,e=o instanceof L?"dom":"ctx",{ctx:s,catt:u}=sr(n.xid+"-0",o);n.xid=u.xid,i.push(s),n.OZ.push(u.OZ),n.states.push(t.call(Yr,e))}else i.push(at(t,n))};class jt{tag;ctx;closing;constructor(t,r){this.tag=t;this.ctx=r;let n=Jr(t);this.closing=n?"":`</${t}>`}process(t,r=this.ctx,n=[]){return r.forEach((i)=>{Ht(i,r.length,t,n)}),n.join("")}get(t){let r=this.process(t);if(t.events.size||t.states.length)t.id=t.xid;return`<${this.tag}${t.attr}>${r}${this.closing}`}}class L{tag;constructor(t,r={},...n){this.tag=t;ot(this,{attr:new wt(r),ctx:new jt(t,n)})}__(t=new d){let r=t.mid,n=new P(r,t);return this.attr.get(n),{ctx:this.ctx.get(n),oz:n.OZ.set(n),id:n.id}}}function M(t,r={},...n){if(b(t))return t(r??{},...n);return new L(t,r??{},n)}var Wr=(t,...r)=>r;class At{e;opt;constructor(t){this.e=t;this.opt={duration:500,easing:"ease-in-out",fill:"forwards"}}animate(t,r={}){return this.e.animate(t,r)}get slide(){let t=({x:r=0,y:n=0},i={})=>{T(this.opt,i);let o=[[r,n],[0,0]].map(([e,s])=>({transform:`translateX(${e}rem) translateY(${s}rem)`}));return this.e.animate(o,this.opt),this};return{left:(r={})=>{return t({x:-2},r)},right:(r={})=>{return t({x:2},r)},up:(r={})=>{return t({y:2},r)},down:(r={})=>{return t({y:-2},r)}}}fade(t={}){T(this.opt,t);let r=[0,1].map((n)=>({opacity:n}));return this.e.animate(r,this.opt),this}shake(t="Y",r={}){T(this.opt,r);let n=[0,5,-5,5,0].map((i)=>({transform:`translate${t}(${i}px)`}));return this.e.animate(n,this.opt),this}color(t=[],r={}){T(this.opt,r);let n=Array.isArray(t)?t.map((i)=>({color:i})):{color:t};return this.e.animate(n,this.opt),this}bg(t=[],r={}){T(this.opt,r);let n=Array.isArray(t)?t.map((i)=>({backgroundColor:i})):{backgroundColor:t};return this.e.animate(n,this.opt),this}bounce(t=1,r={}){T(this.opt,r);let n=[0.5,t,1].map((i)=>({transform:`scale(${i})`}));return this.e.animate(n),this}}class qt{e;query;constructor(t,r){this.e=t;this.query=r}get a(){return new At(this)}get all(){if(this.query){let t=document.querySelectorAll(this.query);if(t.length)return Array.from(t).map((r)=>r)}return[]}get attr(){let t=this.e;return{has:(r)=>{return t.hasAttribute(r)},get:(r)=>{return t.getAttribute(r)},del:(r)=>{return t.removeAttribute(r),this},set:(r)=>{for(let n in r){let i=r[n];if(r[n]!==void 0)t.setAttribute(n,B(i))}return this}}}get children(){return Array.from(this.e.children).map((t)=>g(t))}get click(){return this.e.click(),this}get delete(){return this.e.remove(),this}get disabled(){return this.e.disabled??!1}get focus(){return this.e.focus(),this}get href(){return this.e?.href??""}get id(){return this.e.id}get inner(){return this.e.innerHTML}get offsetParent(){let t=this.e.offsetParent;if(t)return new I(t);return}get parent(){let t=this.e.parentElement;if(t)return new I(t);return}get path(){return this.e?.pathname??""}get rect(){return this.e.getBoundingClientRect()}get remove_element(){return this.e.remove(),this}get style(){let t=this.e.style,r=this;return{set:(n,i=0)=>{let o=t,e=()=>{a(n).forEach(([s,u])=>{if(s in o){if(o[s]!==u)o[s]=u}else if(u!==null)t.setProperty(s,String(u))})};if(b(i))r.on("transitionend",i);if(gt(i))setTimeout(e,i);else e();return r},get:(n)=>{return t.getPropertyValue(n.toString())},del:(...n)=>{n.forEach((i)=>{t.removeProperty(i.toString())})}}}get submit(){let t=this.e;if("submit"in t)return t.submit();return!1}get tag(){return this.e.tagName.toLowerCase()}get value(){return this.e.value??""}get unload(){return()=>{this.e.remove()}}set append(t){let{ctx:r,oz:n}=Dt(t,Rt(this.id));this.e.insertAdjacentHTML("beforeend",r),R.RPS(n)}set appendfirst(t){let{ctx:r,oz:n}=Dt(t,Rt(this.id));this.e.insertAdjacentHTML("afterbegin",r),R.RPS(n)}set inner(t){let{ctx:r,oz:n}=Dt(t,Rt(this.id));this.e.innerHTML=r,R.RPS(n)}set disabled(t){let r=this.e;if("disabled"in r)r.disabled=t}set id(t){this.e.id=t}set value(t){let r=this.e;r.value=t}}var Dt=(t,r)=>{if(t instanceof L)return t.__(new d(r));return{ctx:t,oz:void 0}},Rt=(t)=>t?`${t}-0`:t;class I extends qt{constructor(t,r){super(t,r)}add(...t){return this.e.classList.add(...t.map((r)=>r.replace(/[^\w-]/,""))),this}remove(...t){return this.e.classList.remove(...t.map((r)=>r.replace(/[^\w-]/,""))),this}toggle(t,r){let n=typeof t!="string"?t.apply(this):t,i=this.e.classList;return n.split(" ").forEach((o)=>{i.toggle(o,r)}),this}has(t){return this.e.contains(t)}insert(t){return{HTML:(...r)=>{return r.forEach((n)=>{this.e.insertAdjacentHTML(t,n)}),this},element:(...r)=>{return r.forEach((n)=>{this.e.insertAdjacentElement(t,n)}),this},text:function(...r){return r.forEach((n)=>{this.e.insertAdjacentText(t,n)}),this}}}is(t){let r=this.e.classList.value.split(" "),n=this.e.tagName.toLocaleLowerCase(),i=!0,o=!0;if(t.dom)o=t.dom==n?!0:!1;if(t.class)if(Array.isArray(t.class))t.class.forEach((e)=>{i=i?r.includes(e):!1});else i=i?r.includes(t.class):!1;return i&&o}on(t,r,n=!1){let i=!1;if(t.indexOf("touch")>-1)i=!0;return this.e.addEventListener(t,r,{capture:n,passive:i}),this}remove_on(t,r,n=!1){return this.e.removeEventListener(t,r,n),this}timed(t,r=250){return setTimeout(()=>t(this),r),this}animate(t,r,n){let i={duration:300,easing:"ease",fill:"forwards"};if(b(r))n=r;else T(i,r);let o=this.e.animate(t,i);if(n)o.finished.then(n);return this}}function g(t){if(K(t)){let r=document.querySelector(t);if(r)return new I(r,t);return}else return new I(t)}class lt extends yt{path;args;id;status;lang;import;_data={};constructor(t,r={},n,i=200){super();this.path=t;this.args=r;this.id=n;this.status=i}async loader(){if(this.import)try{let t=await this.import;if(t.default)this.import=await t.default({...this.args,...this.data});else this.import=void 0}catch(t){H.p=t,this.import=void 0}if(this.body){let t=await this.body();return h(t)?t:[t]}if(this.import){let t=this.import;return h(t)?t:[t]}return[]}getHeadAttr(t={},...r){let n=new U;if(w(t))n.head=t;n.id=this.id;let i=n.head;return r.forEach((o)=>{i.map(o)}),Br(n,this),i}set data(t){T(this._data,t)}get data(){return this._data}}class Lt extends lt{head(){this.title=`error ${this.status}`}body(){return M("div",{},this.path+" not found...")}}function Br(t,r){let{link:n,script:i,meta:o,title:e,base:s,description:u,css:m}=r;if(t.head={title:e,base:s,meta:o,link:n,script:i},u)t.head={meta:[{name:"description",content:u}]};if(m){let c=(h(m)?m:[m]).map((A)=>({rel:`${y?"preload ":""}stylesheet`,href:A,as:"style"}));if(t.head.lacks("link"));t.head={link:[...c]}}}function ur(t){let r=[];if(t?.length){let{href:n,target:i}=t[0],o=g("base");if(o)o.attr.set({href:n,target:i});else{let e=g(document.createElement("base"));e.attr.set({href:n,target:i}),document.head.append(e.e)}}else{let n=g("base")?.unload;n&&r.push(n)}return r}var fr=new f;async function mr(t,r={},n=!1){let i=nt.value,o={};if(g("link")?.all.forEach((e)=>{let s=g(e),u=s.attr.get("href");if(u){let m=s.attr.get("rt");if(n){let l=fr.get(i);if(l){if(!l.has(u))o[u]=s.unload}else o[u]=s.unload}else if(m){if(m===t)o[u]=s.unload}}}),r&&w(r))for(let e of x(r)){let s=e.href;if(!(s in o))try{if(!n){e.rt=t;let u=fr.init(i,new Set);if(!u.has(s))u.add(s)}await xt(e)}catch(u){H.p=u}else delete o[s]}return x(o)}var Pr=["charset","name","property","http-equiv"];function hr(t){let r={};if(g("meta")?.all.forEach((n)=>{let i=n.attributes;for(let o of Pr)if(o in i){let e=i[o].value;r[`${o}_${o==="charset"?"":e}`]=n}}),t)a(t).forEach(([n,i])=>{if(n in r)g(r[n]).attr.set(i),delete r[n];else{let o=g(document.createElement("meta"));o.attr.set(i),document.head.append(o.e)}});return x(r).map((n)=>g(n).unload)}var ar=new f;async function lr(t,r,n=!1){let i=nt.value,o={};if(g("script[yid]")?.all.forEach((e)=>{let s=g(e),u=s.attr.get("yid");if(u){let m=s.attr.get("rt");if(n){let l=ar.get(i);if(l){if(!l.has(u))o[u]=s.unload}else o[u]=s.unload}else if(m){if(m===t)o[u]=s.unload}}}),r){for(let e of r)if("yid"in e)if(e.yid in o)delete o[e.yid];else try{if(!n){e.rt=t;let s=e.yid,u=ar.init(i,new Set);if(!u.has(s))u.add(s)}await Vt(e)}catch(s){H.p=s}}return x(o)}async function gr(t,r,n=!1){let i=[];if(y)return[];let o=t.get("title")??"";if(n){let{pushState:e}=this.config,s=this.path.value;if(e)Mt(s,o);document.documentElement.lang=r,document.title=o}if(n)i.push(...ur(t.get("base"))),i.push(...hr(t.get("meta")));return i.push(...await mr(this.id,t.get("link"),n)),i.push(...await lr(this.id,t.get("script"),n)),i}function Mt(t,r){let n=window.location.pathname;if(t&&n!==t)history.pushState({},r??"",t)}class St{lang;head="";constructor(t,r){if(this.lang=t,r)this.head=Nt(r)}body(t,r,n){return[`<!DOCTYPE html><html lang="${this.lang}">`,`<head>${this.head}</head>`,`<body id="${r??p(5)}"${n?" "+n:""}>${t}</body>`,"</html>"].join("")}}class Qt{path;args;isConnected=j(!1);data={};constructor(t,r={}){this.path=t;this.args=r}open(t){}message(t){}close(t){}error(t){}get connect(){if(this.ws&&this.ws.readyState<=1)return this;return this.ws=new WebSocket(this.path),this.ws.onopen=async(t)=>{this.isConnected.value=!0,await this.open.call(this,t)},this.ws.onmessage=async(t)=>{await this.message.call(this,t)},this.ws.onclose=async(t)=>{this.isConnected.value=!1,await this.close.call(this,t)},this.ws.onerror=async(t)=>{this.isConnected.value=this.ws.readyState<=1,await this.error.call(this,t)},this}get reconnect(){if(this.state>=2)this.connect;return this}get disconnect(){if(this.state<=1)this.ws.close();return this}get state(){return this.ws?.readyState??3}set send(t){this.ws.send(t)}}var C=new f;class Ft{yra;constructor(t){this.yra=t}async load(t){if(!C.has(t)){let[n,i]=await this.yra.loadWSS(t);if(!n)return;let{cls:o,path:e,id:s}=n,u=new o(e,i).connect;return C.set(t,u),u}let r=C.get(t);return r.reconnect,r}unload(t){if(C.has(t)){let r=C.get(t);if(!r)return;r.disconnect,C.delete(t)}}}function Cr(t,r,n,i){let o={...t.on??{},click(e){e.preventDefault(),i.value=n.value,n.value=g(this).path}};return delete t.on,M("a",{...t,on:{...o}},...r)}function Gr(t,r,n){let{classes:i}=t.config,{load:o,on:e,...s}=r,u={...r.on??{},...!n&&o&&{ready(m){t.load(o)}},...n&&{popstate(m){let l=m.target;t.path.value=l.location.pathname}}};return M("div",{...s,...i&&{class:i},on:u},t.root)}class Zt extends $t{isYRA;unload=!1;hook;root=j([]);socket;id=p(4);path=j("");lastPath=j("");A;Main;load;constructor(t,r={},n=!1){super(t,r);this.isYRA=n;this.socket=new Ft(this),this.A=(i,...o)=>{return Cr(i,o,this.path,this.lastPath)},this.Main=(i)=>{return Gr(this,i,n)},this.load=async(i,o={})=>{if(this.hook)this.hook();if(i)this.path.value=i,this.lastPath.value=i,this.lang=i,await this.render(i,404,o),this.hooker();return this}}hooker(){let t={},r=this.path.value;if(this.hook)this.hook();this.hook=W(async(n)=>{if(t[r]=window.scrollY,(await this.render(n,404)).done)window.scrollTo({top:t[n]??0,behavior:"instant"}),r=n},[this.path],{id:"router"})}async class(t,r,n=!1){let[i,o]=await this.getPath(t);if(i&&!n){let{cls:e,path:s,id:u}=i;return new e(s,o,u)}else return zr.call(this,t,r)}async fetch(t){if(t)try{if(t.fetch){let r=await t.fetch();if(G(r)&&w(r))t.data=r}}catch(r){H.p=r}}async processHead(t,r={}){return t?await this.processClassHead(t,r):await this.processDefaultHead(r)}async processClassHead(t,r){if(t.head)await t.head();return t.getHeadAttr(r,this.htmlHead)}async processDefaultHead(t){let r=new U;if(w(t))r.head=t;return r.head.map(this.htmlHead),r.head}async render(t,r=404,n={},i={},o=!0,e=!1){let s=await this.class(t,r??Nr(),e);s.data=n,await this.fetch(s);let u=await this.processHead(s,i);if(!s)return{lang:this.lang,heads:u,done:!1};let m=[];if(this.unload)m=await s.loader();let l=[];if(o)l=await gr.call(this,u,s?.lang||this.lang,this.unload);if(!this.unload)l.forEach((c)=>c()),m=await s.loader();if(this.unload)l.forEach((c)=>c());if(m.length)this.root.value=m;else await this.render(t,r,n,i,o,!0);return{heads:u,lang:s.lang??this.lang,done:!0}}}async function zr(t,r){let[n,i]=await this.loadError(r??0);if(n){let{cls:o,id:e}=n;return new o(t,i,e,r)}else{let o=new Lt(t,i,p(5));return o.title=`error ${r}`,o}}var nt=j("");class cr extends Zt{unload=!0;constructor(t,{classes:r,pushState:n=!0}={}){super(t,{classes:r,pushState:n},!0);this.path=nt,this.head({meta:[{charset:"utf-8"},{name:"viewport",content:"width=device-width, initial-scale=1.0"}]}),this.load=async(i,o={})=>{if(N)i=i||location.pathname;if(this.hook)this.hook();if(i)this.path.value=i;if(N&&i)this.render(i,404,o).then(()=>{if(i&&this.config.pushState)Mt(i,document.title);Kr.call(this,this.Main({})),this.hooker()});return this}}async html({path:t,data:r={},status:n=200,attr:i=""}){let o={script:[{type:"module",src:this.ImportMeta.file}]};Vr(o,n),this.path.value=t;let{lang:e,heads:s}=await this.render(t,n,r,o,!1),{ctx:u}=this.Main({}).__(new d(this.id));return new St(e,s).body(u,this.id,i)}}function Kr(t){let r=document.body.id,{oz:n,id:i}=t.__(new d(r));if(this.id=i||this.id,!n)return;R.push(n),requestAnimationFrame(()=>{R.stage})}function Nr(){if(N)return parseInt(g('meta[name="error-code"]')?.attr.get("content")??"404");return 404}var Vr=(t,r)=>{switch(r){case 404:t.meta=[{name:"error-code",content:r.toString()}];return;default:return}},Or=(t)=>{return(r)=>{t(r)}},_r=(t)=>{return(r)=>{t(r)}};class It{state;body;click;constructor({toggle:t=[],initialState:r=!1}={}){this.state=j(r);let n=this.state;this.click=function(){n.value=!n.value},this.loader(t)}loader(t){if(typeof window==="undefined")return;let r=k.get("LOCAL_SCHEME"),n=this.isDark,i=r.as.bool,o=k.get({IS_DARK:()=>this.state.value});if(i!=null&&i!==n)this.state.value=!i,o.save,r.set=n;if(o.as.bool!==null)this.state.value=o.as.bool;let e=this.toggle,s=document.documentElement.classList;if(e(s,this.state.value,t),W(async(u)=>{e(s,u,t),o.save},[this.state],{id:"colorScheme"}),this.isMatchMediaSupported)window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",(u)=>{let l=(u.matches?"dark":"light")==="dark";this.state.value=l,r.set=l})}get isMatchMediaSupported(){return window.matchMedia&&typeof window.matchMedia==="function"}get isDark(){return window.matchMedia("(prefers-color-scheme: dark)").matches}toggle(t,r,n){if(r)t.add(...n);else t.remove(...n)}}It=Xt([Gt,Jt("design:paramtypes",[Object])],It);var es=(t,r)=>{return`${t.replace(/\/+$/,"")}/${r.replace(/^\.\/+/,"")}`};export{Qt as websocket,W as stateHook,nr as session,es as resolvePath,k as local,Wr as frag,tr as eventStream,M as dom,lt as doc,xt as cssLoader,Mr as addCSS,_t as __,cr as Yvee,Z as Stateful,j as State,Or as Routes,Zt as Router,st as Meta,_r as Errors,L as Dom,It as ColorScheme,H as $$,g as $};
1
+ var Yr=Object.defineProperty;var Lr=(t,r)=>{for(var n in r)Yr(t,n,{get:r[n],enumerable:!0,configurable:!0,set:(i)=>r[n]=()=>i})};var At={};Lr(At,{isWindow:()=>B,isUndefined:()=>qr,isStr:()=>tt,isPromise:()=>Cr,isPlainObject:()=>D,isObj:()=>$,isNumber:()=>Z,isNum:()=>St,isNull:()=>gt,isNotWindow:()=>T,isNotNull:()=>Xr,isInt:()=>Rt,isFN:()=>w,isDefined:()=>Br,isClassOrId:()=>Fr,isBool:()=>v,isAsync:()=>Pr,isArraybuff:()=>Zr,isArr:()=>m});var w=(t)=>typeof t==="function",Pr=(t)=>t.constructor.name==="AsyncFunction",Cr=(t)=>!!t&&typeof t.then==="function",Z=(t)=>{return!isNaN(parseFloat(t))&&isFinite(t)},D=(t)=>{return typeof t==="object"&&t!==null&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)},Zr=(t)=>{return t instanceof Uint8Array||t instanceof ArrayBuffer||typeof t==="string"},Fr=(t)=>{return t.startsWith(".")||t.startsWith("#")},v=(t)=>typeof t==="boolean",tt=(t)=>typeof t==="string",m=(t)=>Array.isArray(t),$=(t)=>typeof t==="object",St=(t)=>typeof t==="number",gt=(t)=>t===null,Xr=(t)=>t===null,qr=(t)=>typeof t==="undefined",Br=(t)=>typeof t!=="undefined",Rt=(t)=>{return Number.isInteger(Number(t))},B=typeof window!=="undefined",T=typeof window==="undefined";function ct(t,r){g(r).forEach(([n,i])=>{Nt(t,n,{value:i,writable:!1,configurable:!1,enumerable:!0})})}var Ht=(t)=>{return m(t)?t:[t]};class E{static set i(t){console.info(...Ht(t))}static set e(t){console.error(...Ht(t))}static set w(t){console.info(...Ht(t))}}class H{_c=0;_id="";constructor(t){if(this._c=0,this._id=t??x(5),t?.includes("-")){let[r,n]=[t.split("-").slice(0,-1).join("-"),t.split("-").slice(-1)[0]];this._id=r,this._c=Z(n)?parseInt(n):0}}get id(){return this._id+"-"+this._c}get mid(){return this._id+"-"+ ++this._c}}var Ir=(t)=>Array.from({length:t},(r,n)=>n),_t="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Ot="abcdefghijklmnopqrstuvwxyz";var S=(t)=>JSON.stringify(t),kt=(t)=>{return JSON.parse(t)};var j=(t)=>{if(t.startsWith("webkit"))t="-"+t;return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},x=(t)=>{let r=_t+Ot,n=Ir(10).join("");return Array.from({length:t},(i,o)=>r+(o?n:"")).reduce((i,o)=>{return i+=o.charAt(Math.floor(Math.random()*o.length))},"")},Ur=(t=6,r)=>{if(!r)return Math.floor(Math.random()*t);return Math.round(Math.random()*(r-t)+t)},vt=()=>{let t=[..._t,...Ot],r=Ur(0,t.length);return t[r]};var tr=(t,r)=>{let n=r==="/"?"":r;if(r.startsWith("#"))return t+r;return r.startsWith("/")?t+n:r};class a extends Map{obj(t){t&&g(t).forEach(([r,n])=>this.set(r,n))}map(t){t.forEach((r,n)=>{if(r instanceof a)this.set(n,r);else if(m(r)){if(this.lacks(n))this.set(n,[]);this.get(n).push(...r)}else if($(r))this.ass(n,r);else this.set(n,r)})}ass(t,r){if(!this.has(t))this.set(t,{});p(this.get(t),r)}lacks(t){return!this.has(t)}init(t,r){return this.has(t)?this.get(t):this.set(t,r).get(t)}}var{values:A,keys:W,entries:g}=Object;var{defineProperty:Nt,assign:p}=Object,rr=(t,r)=>Object.hasOwn(t,r),R=(t)=>{return Object.keys(t).length},dt=(t,r)=>{if(!r.has(t))r.set(t,new a);return r.get(t)},rt=(t,r)=>{if(!r.has(t))r.set(t,[]);return r.get(t)},Dt=(t,r)=>{let n={added:{},removed:{},modified:{}},i=W(t),o=W(r);for(let e of o){let f=t[e],s=r[e];if(!(e in t))n.added[e]=s;else if(m(f)&&m(s)){if(S(f)!==S(s))n.modified[e]={old:f,new:s}}else if($(f)&&$(s)&&!gt(f)&&!gt(s)){let u=Dt(f,s);if(R(u.added)||R(u.removed)||R(u.modified))n.modified[e]={old:f,new:s}}else if(f!==s)n.modified[e]={old:f,new:s}}for(let e of i)if(!(e in r))n.removed[e]=t[e];return n};function nr(t,r){if(t.size!==r.size)return!1;for(let n of t)if(!r.has(n))return!1;return!0}var ir=(t)=>{return A(t).some((r)=>{return R(r)})};var I=(t,r)=>{return{name:t,content:r}},Jr=(t,r)=>{return{property:t,content:r}},Wr=(t,r)=>{return{"http-equiv":t,content:r}};class nt{metas=[];constructor(t){t&&this.metas.push(I("description",t))}author(t){return this.meta=I("author",t),this}charset(t){return this.meta={charset:t},this}keywords(...t){return this.meta=I("keywords",t.join(", ")),this}viewport(t){let r=g(t).map(([n,i])=>[j(n),String(i)].join("="));return this.meta=I("viewport",r.join(", ")),this}httpEquiv(t){return g(t).forEach(([r,n])=>{this.meta=Wr(j(r),String(n))}),this}robots(...t){return this.meta=I("robots",t.join(", ")),this}themeColor(t){return this.meta=I("theme-color",t),this}openGraph(t){return g(t).forEach(([r,n])=>{this.meta=Jr("og:"+r,String(n))}),this}twitter(t){return g(t).forEach(([r,n])=>{this.meta=I("twitter:"+r,String(n))}),this}push(t){this.metas.unshift(...t)}set meta(t){this.metas.push(t)}}class jt{title;description;base;meta;link;script;css}var Qr=["charset","name","property","http-equiv"],or=(t,r)=>{r.forEach((n)=>{for(let i of Qr)if(i in n){let o=n[i];t[`${i}_${i==="charset"?"":o}`]=n}})},Gr=(t,r)=>{r.forEach((n)=>{if("href"in n){let i=n.href;t[`${i}`]=n}})};class Q{_head;idm;constructor(t){this._head=new a(t)}set head(t){g(t).forEach(([r,n])=>{if(r==="title"||r==="base"){if(n!==void 0)this._head.set(r,n);return}if(n instanceof nt)return or(this._head.init("meta",{}),n.metas);if(!m(n))return;switch(r){case"meta":return or(this._head.init("meta",{}),n);case"link":return Gr(this._head.init("link",{}),n);case"script":if(n.length){this._head.init(r,[]);let i=n.map((o)=>{if(!o.yid&&this.idm)o.yid="sc"+this.idm.mid;return o});this._head.get(r).push(...i)}return}})}get head(){return this._head}set id(t){this.idm=new H(t)}}var it=(t)=>{return g(t??{}).reduce((r,[n,i])=>{return r.push(v(i)&&i?n:`${n}="${i}"`),r},[""]).join(" ")},er=(t)=>{let r=new Set;if(!t)return"";let n=[...t].reduce((i,[o,e])=>{if(o==="meta"||o==="link")e=A(e);if(tt(e)){if(o==="title")r.add(`<${o}>${e}</${o}>`);else i.add(`<${o}>${e}</${o}>`);return i}if(!m(e))return i;if(o==="base"){let s=e.slice(-1);if(s)return r.add(`<${o}${it(s[0])}>`),i}return e.map((s)=>{if(o==="script"){let u={...s},h="";if("importmap"in u)u.type="importmap",h=JSON.stringify(u.importmap),delete u.importmap;else if("body"in u)h=u.body,delete u.body;return`<${o}${it(u)}>${h}</${o}>`}return`<${o}${it(s)}>`}).forEach((s)=>{if(s.includes('type="module"'))r.add(s);else if(s.includes("<meta"))r.add(s);else i.add(s)}),i},new Set);return[...r,...n].join("")};class ot{lang="en";htmlHead;head;constructor(){this.htmlHead=new a,this.head=(t={})=>{let r=new Q(this.htmlHead),{css:n,description:i,...o}=t;if(i)r.head={meta:[{name:"description",content:i}]};if(n){let f=(m(n)?n:[n]).map((s)=>({rel:"preload stylesheet",href:s,as:"style"}));r.head={link:[...f]}}r.head=o,this.htmlHead=r.head}}}var Mt=(t)=>{if(T)return;return new Promise((r,n)=>{let i=document.createElement("link");if(t.rel!=="stylesheet")t.rel="stylesheet",t.as="style";g(t).forEach(([o,e])=>{i.setAttribute(o,e)}),i.onload=()=>r(i),i.onerror=()=>n(new Error("Failed to load CSS")),document.head.appendChild(i)})},sr=(t)=>{if(T)return;return new Promise((r,n)=>{let i=document.createElement("script"),o="";if("importmap"in t)t.type="importmap",o=JSON.stringify(t.importmap),delete t.importmap;else if("body"in t)o=t.body,delete t.body;if(o)i.textContent=o;g(t).forEach(([e,f])=>{i.setAttribute(e,f)}),i.onload=()=>r(i),i.onerror=()=>n(new Error("Failed to load Script")),document.head.appendChild(i),requestAnimationFrame(()=>r("Script executed"))})},Kr=()=>{let r=document.querySelector("#d-css")?.sheet;if(r)return r;let n=document.createElement("style");return n.id="d-css",document.head.appendChild(n),n.sheet},zr=(t,r)=>{for(let n=0;n<t.cssRules.length;n++)if(t.cssRules[n].selectorText===r)return!0;return!1},Vr=(t)=>Object.entries(t).map(([r,n])=>`${j(r)}: ${n};`).join(" ");function Nr(t,r={}){if(T)return;let n=Kr();if(!n)return;if(!zr(n,t))n.insertRule(`${t} { ${Vr(r)} }`,n.cssRules.length)}var Yt=(t,r=!1)=>{if(Z(t))return[+t,Rt(t)?"int":"float"];if(r&&/\.\w+$/.test(t))return[t,"file"];if(t==="/")return[t,"-"];if(t.length===36&&t.match(/\-/g)?.length===4)return[t,"uuid"];return[t,"string"]},G=(t)=>{let r=t.startsWith("/")?t:"/"+t,n=r.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[i,o]=n.reduce(([e,f],s)=>{if(s.includes("<")){let u=s.match(/(?<=<)[^/].*?(?=>|$)/g);if(u?.length){let[h,l]=u[0].split(":");if(h&&l)e.push(h),f.push(l)}}else e.push(s===">"?"/":s);return[e,f]},[[],[]]);if(r.endsWith("/")&&r.length>1)i.push("/");return{parsed:i,args:o}};class pt{storage;constructor(){this.storage=new a}cache(t,r){if(this.storage.lacks(t))this.storage.set(t,r());return this.storage.get(t)}}var fr=["int","float","file","uuid","string"],Tt=(t,r)=>{let n={},i=[],{parsed:o}=G(t),{parsed:e,args:f}=G(r);if(o.length===e.length)e.map((s,u)=>{let h=Yt(o[u],o.length-1===u);if(s===h[0])return h[0];if(fr.includes(h[1]))return i.push(h[0]),h[1];return s}),f.forEach((s,u)=>{n[s]=i[u]});return n};class K{_storage;CC;constructor(){this._storage=new a,this.CC=new pt}set(t){let{parsed:r,path:n}=t,i=S(r);if(!this._storage.get(i))this._storage.set(i,t);else throw`path: ${n} already used.`}get(t){let{parsed:r}=this.CC.cache(t,()=>G(t)),n={},i=this._storage.get(S(r));if(!i&&t!=="/")for(let o of this._storage.keys()){let e=[],f=kt(o);if(r.length===f.length){let s=f.map((l,b)=>{let c=Yt(r[b],r.length-1===b);if(l===c[0])return c[0];if(fr.includes(c[1]))return e.push(c[0]),c[1];return l}),u=S(s);if(this._storage.has(u)){i=this._storage.get(u),i?.args.forEach((l,b)=>{n[l]=e[b]});break}}}return[i,n]}}class et{path="";parsed=[];args=[];constructor(t){ct(this,{path:t,...G(t)})}}class ur{static rand(t=6,r){if(r)return Math.floor(Math.random()*(r-t+1)+t);return Math.floor(Math.random()*t)+1-1}static fill(t,r=null){return Array(t).fill(r)}static new({dom:t,id:r,inner:n}){let i=document.createElement(t);if(r)i.id=r;if(n)i.innerHTML=n;return i}static randFrom(t){if(Array.isArray(t)){let r=t.length,n=this.rand(0,r-1);return t[n]}else if(typeof t=="object"){let r=W(t),n=r.length,i=this.rand(0,n-1);return r[i]}}static randomAZ=vt;static makeID=x;static class(t,r){let n=r;if(t?.class)n.push(...m(t.class)?t.class:[t.class]);t.class=r}static get O(){return{vals:A,keys:W,items:g,has:rr,ass:p,len:(t={})=>W(t).length}}static get is(){return At}static get return(){return hr}static sleep=(t=1000)=>new Promise((r)=>setTimeout(r,t));static get screen(){let{innerWidth:t}=window,r={xs:t<=480,sm:t>=480,smd:t>=624,md:t>=768,lg:t>=1024,xl:t>=1280,xxl:t>=1536},n=g(r).reverse();for(let i=0;i<n.length;i++){let[o,e]=n[i];if(e)return o}return}bytes(t){if(t===0)return"0 Bytes";let r=1024,n=["Bytes","KB","MB","GB"],i=Math.floor(Math.log(t)/Math.log(r));return parseFloat((t/Math.pow(r,i)).toFixed(2))+" "+n[i]}static format(t){return new ar(t)}}class hr{static arr(t){return m(t)?t:[t]}static num(t,r=0){let n=parseFloat(t);return isNaN(n)?r:n}}class ar{val;constructor(t){this.val=t}get px(){return`${this.val}px`}get rem(){return`${this.val}rem`}get pr(){return`${this.val}%`}}var Lt={},U={};class lr{stream;url;constructor(t,r){if(this.url=t,t in Lt)this.stream=Lt[t];else this.stream=new EventSource(t,{withCredentials:r}),Lt[t]=this.stream,U[this.url]={}}on(t){let r=this.stream;return g(t).forEach(([n,i])=>{if(n in U[this.url])U[this.url][n].forEach((o)=>{this.stream.removeEventListener(n,o)}),U[this.url][n]=[];if(r.addEventListener(n,i),!(n in U[this.url]))U[this.url][n]=[];U[this.url][n].push(i)}),this}}function mr(t,r=!0){return new lr(t,r)}class gr{value;constructor(t){this.value=t}get str(){return String(this.value).toString()=="null"?null:String(this.value).toString()}get int(){if(Z(this.value))return parseInt(this.value);else return null}get float(){if(Z(this.value))return parseFloat(this.value);else return null}get bool(){if(this.value==="true")return!0;else if(this.value=="false")return!1;else return null}get json(){if(this.value)return JSON.parse(this.value);return null}}class z{key;state;storage;constructor(t,r="local",n){if(this.storage=r=="local"?localStorage:sessionStorage,typeof t=="object"){let[i,o]=g(t)[0];if(this.key=i,this.state=o,n){let e=this.as[n];this.state.value=e}V((e)=>{this.set=e},[this.state],{id:this.key})}else this.key=t,this.state=null}get as(){return new gr(this.storage.getItem(this.key))}get value(){return this.storage.getItem(this.key)}set set(t){let r=$(t)?S(t):String(t);this.storage.setItem(this.key,r)}get remove(){this.storage.removeItem(this.key);return}}var cr={get:(t)=>new z(t,"local"),init:(t,r)=>new z(t,"local",r)};var dr={get:(t)=>new z(t,"session")};class bt extends et{id;cls;constructor(t,r,n){super(t);this.id=r;this.cls=n}}class pr extends et{id;cls;constructor(t,r,n){super(t);this.id=r;this.cls=n}}class Pt extends ot{storage=new K;errorStorage=new K;wssStorage=new K;route;error;wss;base;constructor(t=""){super();this.base=t?t.startsWith("/")?t:`/${t}`:"",this.route=(r)=>{let n=this._base(r);return(i)=>{return i.route=n,this.storage.set(new bt(n,x(5),i)),i}},this.wss=(r)=>{let n=this._base(r);return(i)=>{return i.route=n,this.wssStorage.set(new pr(n,x(5),i)),i}},this.error=(...r)=>{return(n)=>{if(r.length)r.forEach((i)=>{this.errorStorage.set(new bt(i.toString(),x(5),n))});else this.errorStorage.set(new bt("404",x(5),n));return n}}}_base(t){return tr(this.base,t)}async getPath(t){return this.storage.get(t)}async loadError(t){return this.errorStorage.get(t.toString())}async loadWSS(t){return this.wssStorage.get(t)}}var st=new a,N=(t)=>{if(T)return;let r=st.get(t);if(r?.isConnected)return r;st.delete(t);let n=document.getElementById(t);if(!n)return;return st.set(t,n),n};function Tr(){let t=[];return st.forEach((r,n)=>{if(!r.isConnected)t.push(n),st.delete(n)}),t}function V(t,r,{id:n="stateHook",init:i}={}){if(T)return()=>{};let o=[],e=()=>r.map((s)=>s.value),f=()=>{t(...e())};if(r.forEach((s)=>{o.push(s.hook(f)(n))}),i)f();return()=>{o.forEach((s)=>s())}}var br=(t)=>{t.forEach((r)=>r())};var _r=(t,r)=>{for(let[n,i]of t){let o=N(n);if(!o){t.delete(n);continue}i.forEach((e)=>{e.call(o,r)})}};class Y extends EventTarget{options;hooks=new a;states=new a;_value;listening=!1;end;constructor(t,r){super();this.options=r;this._value=t}get value(){return this._value}set value(t){if(D(this._value)||m(this._value)){let r=Dt(this._value,t);if(!ir(r))return}else if(this._value instanceof Set){if(!nr(this._value,t))return}else if(this._value===t)return;this._value=t,this.dispatchEvent(new CustomEvent("updated",{detail:this._value}))}get listen(){let t=(r)=>{if(br(this.hooks),_r(this.states,r.detail),!this.states.size&&!this.hooks.size)this.end?.()};if(!this.listening)this.addEventListener("updated",t,this.options),this.listening=!0;return()=>{this.listening&&this.removeEventListener("updated",t,this.options),this.end=void 0,this.listening=!1}}call(t,r){return(n)=>{if(dt(n,this.states).set(r,t),!T&&!this.listening)this.end=this.listen;return()=>{if(this.states.has(n))this.states.get(n)?.delete(r)}}}hook(t){return(r)=>{if(this.hooks.set(r,t),!T&&!this.listening)this.end=this.listen;return()=>{if(this.hooks.has(r))this.hooks.delete(r)}}}}function M(t,r){return new Y(t,r)}var _=(t)=>{if(m(t))return t.filter((r)=>r!==void 0).join(" ");else if($(t)){if(D(t))return S(t)}else if(w(t))return _(t());else if(t!==void 0&&t!==null)return v(t)?t?"":"false":String(t);return""};function Or(t,r){switch(r??t){case"style":return function(n){this.style.setProperty(t,n)};default:return function(n){this.setAttribute(t,n)}}}class Ct{attr;constructor(t={}){this.attr=t}get(t,r=this.attr,n){let i=(o,e)=>{if(m(e))t.attr_push(o,_(e));else if(e instanceof Y){let f=n?`${n}_${o}`:o;t.states.push(e.call(Or(o,n),f)),i(o,e.value)}else if($(e)){if(D(e)&&!n)this.get(t,e,o)}else t.attr_push(o,_(e),n)};g(r).forEach(([o,e])=>{if(o==="ref"){if(e instanceof ft)t.events.obj({element(){e.element=this}})}else if(["on"].includes(o))$(r.on)&&t.events.obj(r.on);else i(o,e)})}}class F{xid;IDM;map=new a;states=[];events=new a;OZ;constructor(t,r=new H,n){this.xid=t;this.IDM=r;this.OZ=n??new yt}attr_push(t,r,n){let i=n??t;if(!this.map.has(i))this.map.set(i,[]);let o=n?`${j(t)}:${r};`:r;this.map.get(i).push(o)}get attr(){let t=[""];return this.map.forEach((r,n)=>{let i=r.join("");t.push(i?`${n}="${i}"`:n)}),t.join(" ")}set id(t){if(!this.map.has("id"))this.map.set("id",[t])}get id(){return this.map.get("id")?.join("")}}var kr=(t,r,n)=>{return t.addEventListener(r,n),()=>{t.removeEventListener(r,n)}},ut={};class yt{events=new a;states=new a;winStates=new a;windowEvents=new a;resetST=new a;resetEV=new a;constructor(){}get keys(){return[...new Set([...this.states.keys(),...this.events.keys()])]}set(t){let{id:r,events:n,states:i}=t;if(r){if(n.size)this.events.set(r,n);if(i.length)this.states.set(r,i)}return this}push(t){return t.events.forEach((r,n)=>{r.forEach((i,o)=>{dt(n,this.events).set(o,i)})}),t.states.forEach((r,n)=>{rt(n,this.states).push(...r)}),this}get stage(){return this.events.forEach((t,r)=>{this.events.delete(r);let n=N(r);if(!n){this.events.delete(r);return}t.forEach((i,o)=>{switch(o){case"ready":case"element":i.apply(n,[n]);break;case"resize":case"beforeunload":case"popstate":case"winscroll":case"winload":case"winfocus":case"winblur":let e=o.replace(/^win/,"");this.windowEvents.init(e,new a).set(r,i);break;case"state":let[f,s,u]=i.apply(n,[n]),h=m(s)?s:[s],l=()=>h.map((c)=>c.value),b=()=>f(...l());if(u)b();h.forEach((c)=>rt(r,this.resetST).push(c.call(b,r+"_state")(r)));break;default:rt(r,this.resetEV).push(kr(n,o,i))}})}),this.processWindowEvents,this.states.forEach((t,r)=>{this.states.delete(r),t.forEach((n)=>{rt(r,this.resetST).push(n(r))})}),this}get processWindowEvents(){let t=(r,n)=>{let i=0,o=!1,e=(s)=>{if(i=window.scrollY,!o)window.requestAnimationFrame(()=>{n.forEach((u,h)=>{let l=N(h);if(l)u.call(l,s);else this.windowEvents.get(r)?.delete(h)}),o=!1}),o=!0},f=(s)=>{n.forEach((u,h)=>{let l=N(h);if(l)u.call(l,s);else this.windowEvents.get(r)?.delete(h)})};return window.addEventListener(r,r==="scroll"?e:f),()=>{window.removeEventListener(r,r==="scroll"?e:f)}};return this.windowEvents.forEach((r,n)=>{if(r.size){if(!ut[n])ut[n]=t(n,r)}else if(ut[n])ut[n](),delete ut[n]}),this}reset(t){return t.forEach((r)=>{this.windowEvents.forEach((n,i)=>{if(n.has(r))n.delete(r)}),this.resetEV.get(r)?.forEach((n)=>{n()}),this.resetST.get(r)?.forEach((n)=>{n()}),this.resetST.delete(r),this.resetEV.delete(r)}),this}RPS(t){if(t){let r=Tr();this.reset(r);let n=t.keys;if(n.length)this.reset(n).push(t).stage}return this}}var L=new yt;var vr=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],tn=(t)=>vr.includes(t);function rn(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}var xt=(t,r)=>{if(m(t))return t.map((n)=>xt(n,r)).join("");else if(t instanceof O){let n=t.__(r.IDM),{ctx:i,oz:o}=n;return r.OZ.push(o),i}else if($(t))return S(t);else if(w(t))return xt(t(),r);else if(t!==void 0&&t!==null)return rn(t);return""},wt=(t,r)=>{let n=new H(r),i=new F(n.id,n);return{ctx:xt(t,i),catt:i}};function nn(t){let r=this.id;if(r){let{ctx:n,catt:i}=wt(t,r);if(this.innerHTML!==n)this.innerHTML=n,L.RPS(i.OZ)}}var ht=(t,r,n,i=[])=>{if(m(t))t.forEach((o)=>{ht(o,t.length,n,i)});else if(t instanceof Y)if(r>1)ht(X("div",{},t),r,n,i);else{let o=t.value,e=o instanceof O?"dom":"ctx",{ctx:f,catt:s}=wt(o,n.xid+"-0");n.xid=s.xid,i.push(f),n.OZ.push(s.OZ),n.states.push(t.call(nn,e))}else i.push(xt(t,n))};class Zt{tag;ctx;closing;constructor(t,r){this.tag=t;this.ctx=r;let n=tn(t);this.closing=n?"":`</${t}>`}process(t,r=this.ctx,n=[]){return r.forEach((i)=>{ht(i,r.length,t,n)}),n.join("")}get(t){let r=this.process(t);if(t.events.size||t.states.length)t.id=t.xid;return`<${this.tag}${t.attr}>${r}${this.closing}`}}class O{tag;constructor(t,r={},...n){this.tag=t;ct(this,{attr:new Ct(r),ctx:new Zt(t,n)})}__(t=new H){let r=t.mid,n=new F(r,t);return this.attr.get(n),{ctx:this.ctx.get(n),oz:n.OZ.set(n),id:n.id}}}function X(t,r={},...n){if(w(t))return t(r??{},...n);return new O(t,r??{},n)}var on=(t,...r)=>r;class Ft{e;opt;constructor(t){this.e=t;this.opt={duration:500,easing:"ease-in-out",fill:"forwards"}}animate(t,r={}){return this.e.animate(t,r)}get slide(){let t=({x:r=0,y:n=0},i={})=>{p(this.opt,i);let o=[[r,n],[0,0]].map(([e,f])=>({transform:`translateX(${e}rem) translateY(${f}rem)`}));return this.e.animate(o,this.opt),this};return{left:(r={})=>{return t({x:-2},r)},right:(r={})=>{return t({x:2},r)},up:(r={})=>{return t({y:2},r)},down:(r={})=>{return t({y:-2},r)}}}fade(t={}){p(this.opt,t);let r=[0,1].map((n)=>({opacity:n}));return this.e.animate(r,this.opt),this}shake(t="Y",r={}){p(this.opt,r);let n=[0,5,-5,5,0].map((i)=>({transform:`translate${t}(${i}px)`}));return this.e.animate(n,this.opt),this}color(t=[],r={}){p(this.opt,r);let n=Array.isArray(t)?t.map((i)=>({color:i})):{color:t};return this.e.animate(n,this.opt),this}bg(t=[],r={}){p(this.opt,r);let n=Array.isArray(t)?t.map((i)=>({backgroundColor:i})):{backgroundColor:t};return this.e.animate(n,this.opt),this}bounce(t=1,r={}){p(this.opt,r);let n=[0.5,t,1].map((i)=>({transform:`scale(${i})`}));return this.e.animate(n),this}}class Bt{e;query;constructor(t,r){this.e=t;this.query=r}get a(){return new Ft(this)}get all(){if(this.query){let t=document.querySelectorAll(this.query);if(t.length)return Array.from(t).map((r)=>r)}return[]}get attr(){let t=this.e;return{has:(r)=>{return t.hasAttribute(r)},get:(r)=>{return t.getAttribute(r)},del:(r)=>{return t.removeAttribute(r),this},set:(r)=>{for(let n in r){let i=r[n];if(r[n]!==void 0)t.setAttribute(n,_(i))}return this}}}get children(){return Array.from(this.e.children).map((t)=>d(t))}get click(){return this.e.click(),this}get delete(){return this.e.remove(),this}get disabled(){return this.e.disabled??!1}get focus(){return this.e.focus(),this}get href(){return this.e?.href??""}get id(){return this.e.id}get inner(){return this.e.innerHTML}get offsetParent(){let t=this.e.offsetParent;if(t)return new P(t);return}get parent(){let t=this.e.parentElement;if(t)return new P(t);return}get hash(){return this.e?.hash??""}get path(){return this.e?.pathname??""}get rect(){return this.e.getBoundingClientRect()}get remove_element(){return this.e.remove(),this}get style(){let t=this.e.style,r=this;return{set:(n,i=0)=>{let o=t,e=()=>{g(n).forEach(([f,s])=>{if(f in o){if(o[f]!==s)o[f]=s}else if(s!==null)t.setProperty(f,String(s))})};if(w(i))r.on("transitionend",i);if(St(i))setTimeout(e,i);else e();return r},get:(n)=>{let i=j(String(n));return t.getPropertyValue(i)},del:(...n)=>{n.forEach((i)=>{let o=j(String(i));t.removeProperty(o)})}}}get submit(){let t=this.e;if("submit"in t)return t.submit();return!1}get tag(){return this.e.tagName.toLowerCase()}get value(){return this.e.value??""}get unload(){return()=>{this.e.remove()}}set append(t){let{ctx:r,oz:n}=Xt(t,qt(this.id));this.e.insertAdjacentHTML("beforeend",r),L.RPS(n)}set appendfirst(t){let{ctx:r,oz:n}=Xt(t,qt(this.id));this.e.insertAdjacentHTML("afterbegin",r),L.RPS(n)}set inner(t){let{ctx:r,oz:n}=Xt(t,qt(this.id));this.e.innerHTML=r,L.RPS(n)}set disabled(t){let r=this.e;if("disabled"in r)r.disabled=t}set id(t){this.e.id=t}set value(t){let r=this.e;r.value=t}}var Xt=(t,r)=>{let{ctx:n,catt:i}=wt(t,r);return{ctx:n,oz:i.OZ}},qt=(t)=>t?`${t}-0`:t;class P extends Bt{constructor(t,r){super(t,r)}add(...t){return this.e.classList.add(...t.map((r)=>r.replace(/[^\w-]/,""))),this}remove(...t){return this.e.classList.remove(...t.map((r)=>r.replace(/[^\w-]/,""))),this}toggle(t,r){let n=typeof t!="string"?t.apply(this):t,i=this.e.classList;return n.split(" ").forEach((o)=>{i.toggle(o,r)}),this}has(t){return this.e.contains(t)}insert(t){return{HTML:(...r)=>{return r.forEach((n)=>{this.e.insertAdjacentHTML(t,n)}),this},element:(...r)=>{return r.forEach((n)=>{this.e.insertAdjacentElement(t,n)}),this},text:function(...r){return r.forEach((n)=>{this.e.insertAdjacentText(t,n)}),this}}}is(t){let r=this.e.classList.value.split(" "),n=this.e.tagName.toLocaleLowerCase(),i=!0,o=!0;if(t.dom)o=t.dom==n?!0:!1;if(t.class)if(Array.isArray(t.class))t.class.forEach((e)=>{i=i?r.includes(e):!1});else i=i?r.includes(t.class):!1;return i&&o}on(t,r,n=!1){let i=!1;if(t.indexOf("touch")>-1)i=!0;return this.e.addEventListener(t,r,{capture:n,passive:i}),this}remove_on(t,r,n=!1){return this.e.removeEventListener(t,r,n),this}timed(t,r=250){return setTimeout(()=>t(this),r),this}animate(t,r,n){let i={duration:300,easing:"ease",fill:"forwards"};if(w(r))n=r;else p(i,r);let o=this.e.animate(t,i);if(n)o.finished.then(n);return this}}function d(t){if(tt(t)){let r=document.querySelector(t);if(r)return new P(r,t);return}else if(D(t)){let[[r,n]]=g(t),o=`${r==="id"?"#":"."}${n}`,e=document.querySelector(o);if(e)return new P(e,o);return}else return new P(t)}class ft{state=new Y(void 0);constructor(){}get element(){return this.state.value?.e}set element(t){if(t)this.state.value=new P(t);else this.state.value=void 0}get $(){return this.state.value}}var en=()=>{return new ft};class It{lang;head="";constructor(t,r){if(this.lang=t,r)this.head=er(r)}body(t,r,n){return[`<!DOCTYPE html><html lang="${this.lang}">`,`<head>${this.head}</head>`,`<body id="${r??x(5)}"${n?" "+n:""}>${t}</body>`,"</html>"].join("")}}class $t extends jt{path;args;id;status;lang;import;_data={};static route="/";constructor(t,r={},n,i=200){super();this.path=t;this.args=r;this.id=n;this.status=i}async loader(){if(this.import)try{let t=await this.import;if(t.default)this.import=await t.default({...this.args,...this.data});else this.import=void 0}catch(t){return E.e=["import",{error:"loader"}],this.import=void 0,[]}if(this.body){let t=await this.body();return m(t)?t:[t]}if(this.import){let t=this.import;return m(t)?t:[t]}return[]}getHeadAttr(t={},...r){let n=new Q;if(R(t))n.head=t;n.id=this.id;let i=n.head;return r.forEach((o)=>{i.map(o)}),sn(n,this),i}set data(t){p(this._data,t)}get data(){return this._data}}class Ut extends $t{head(){this.title=`error ${this.status}`}body(){return X("div",{},this.path+" not found...")}}function sn(t,r){let{link:n,script:i,meta:o,title:e,base:f,description:s,css:u}=r;if(t.head={title:e,base:f,meta:o,link:n,script:i},s)t.head={meta:[{name:"description",content:s}]};if(u){let l=(m(u)?u:[u]).map((b)=>({rel:"preload stylesheet",href:b,as:"style"}));t.head={link:[...l]}}}function yr(t){let r=[];if(t?.length){let{href:n,target:i}=t[0],o=d("base");if(o){if(o.attr.get("href")!==n)o.attr.set({href:n,target:i})}else{let e=d(document.createElement("base"));e.attr.set({href:n,target:i}),document.head.append(e.e)}}return r}var xr=new a;async function wr(t,r={},n=!1){let i=at.value,o={};if(d("link")?.all.forEach((e)=>{let f=d(e),s=f.attr.get("href");if(s){let u=f.attr.get("rt");if(n){let h=xr.get(i);if(h){if(!h.has(s))o[s]=f.unload}else o[s]=f.unload}else if(u){if(u===t)o[s]=f.unload}}}),r&&R(r))for(let e of A(r)){let f=e.href;if(!(f in o))try{let s=void 0;if(!n){if(s=d(`link[href='${f}']`),s)s.attr.set({rt:t});e.rt=t;let u=xr.init(i,new Set);if(!u.has(f))u.add(f)}if(!s)await Mt(e)}catch(s){E.e=["link error",{error:"yvee @ link"}]}else delete o[f]}return A(o)}var fn=["charset","name","property","http-equiv"];function $r(t){let r={};if(d("meta")?.all.forEach((n)=>{let i=n.attributes;for(let o of fn)if(o in i){let e=i[o].value;r[`${o}_${o==="charset"?"":e}`]=n}}),t)g(t).forEach(([n,i])=>{if(n in r)d(r[n]).attr.set(i),delete r[n];else{let o=d(document.createElement("meta"));o.attr.set(i),document.head.append(o.e)}});return A(r).map((n)=>d(n).unload)}var Er=new a;async function Sr(t,r,n=!1){let i=at.value,o={};if(d("script[yid]")?.all.forEach((e)=>{let f=d(e),s=f.attr.get("yid");if(s){let u=f.attr.get("rt");if(n){let h=Er.get(i);if(h){if(!h.has(s))o[s]=f.unload}else o[s]=f.unload}else if(u){if(u===t)o[s]=f.unload}}}),r){for(let e of r)if("yid"in e)if(e.yid in o)delete o[e.yid];else try{if(!n){e.rt=t;let f=e.yid,s=Er.init(i,new Set);if(!s.has(f))s.add(f)}await sr(e)}catch(f){E.e=["script error",{error:"yvee @ script"}]}}return A(o)}async function Rr(t,r){let n=[];if(T)return[];let i=t.get("title")??"",{pushState:o}=this.config;if(o){let e=this.path.value,f=this.lastPath.value;if(f!==e)if(!f.startsWith(e))q(e,i);else if(e===this.base)q(e,i);else q(e,i)}if(this.isYvee)document.documentElement.lang=r,document.title=i,n.push(...yr(t.get("base"))),n.push(...$r(t.get("meta")));return n.push(...await wr(this.id,t.get("link"),this.isYvee)),n.push(...await Sr(this.id,t.get("script"),this.isYvee)),n}function q(t,r){if(T)return;let{pathname:n,hash:i}=window.location,o=n+i;if(t&&o!==t)history.pushState({},r??"",t)}class Jt{path;args;static route="/";isConnected=M(!1);data={};constructor(t,r={}){this.path=t;this.args=r;this.data=r}open(t){}message(t){}close(t){}error(t){}get connect(){if(this.ws&&this.ws.readyState<=1)return this;return this.ws=new WebSocket(this.path),this.ws.onopen=async(t)=>{this.isConnected.value=!0,await this.open.call(this,t)},this.ws.onmessage=async(t)=>{await this.message.call(this,t)},this.ws.onclose=async(t)=>{this.isConnected.value=!1,await this.close.call(this,t)},this.ws.onerror=async(t)=>{this.isConnected.value=this.ws.readyState<=1,await this.error.call(this,t)},this}get reconnect(){if(this.state>=2)this.connect;return this}get disconnect(){if(this.state<=1)this.ws.close();return this}get state(){return this.ws?.readyState??3}set send(t){if(this.isConnected.value)this.ws.send(t);else throw new Error(`websocket path ${this.path} not connected`)}}var k=new a;class Wt{yvee;constructor(t){this.yvee=t}async load(t){if(T)return;if(!k.has(t)){let[n,i]=await this.yvee.loadWSS(t);if(!n)return;let{cls:o,path:e,id:f}=n,s=new o(e,i).connect;return k.set(t,s),s}let r=k.get(t);return r.reconnect,r}unload(t){if(T)return;if(k.has(t)){let r=k.get(t);if(!r)return;r.disconnect,k.delete(t)}}}var Qt=new a;function un(t,r,n,i){let{on:o,top:e,topRef:f,...s}=t,u={...o??{},click(h){h.preventDefault();let l=d(this),b=l.path;i.value=n.value,n.value=b;let c=l.hash;if(c){let J=d(c),y=window.scrollY;if(J)y+=J.rect.top;if(f)y-=f?.value?.e.offsetHeight||0;if(e)if(typeof e==="number")y-=e;else y-=e();window.scrollTo({top:y,behavior:"smooth"}),q(b+c)}else if(i.value===n.value)window.scrollTo({top:l.rect.top||0,behavior:"smooth"}),q(window.location.pathname)}};return X("a",{...s,on:{...u}},...r)}function hn(t,r,n){let{classes:i}=t.config,{on:o,...e}=r,f={...r.on??{},...n&&{popstate(s){let h=s.target.location.pathname;t.path.value=h}},...{element(s){t.mainElement=this}}};return X("div",{...e,...i&&{class:i},on:f},t.root)}async function an(t,r){let[n,i]=await this.loadError(r??0);if(n){let{cls:o,id:e}=n;return new o(t,i,e,r)}else{let o=new Ut(t,i,x(5));return o.title=`error ${r}`,o}}function Gt(){if(B)return parseInt(d('meta[name="error"]')?.attr.get("content")??"200");return 200}class lt extends Pt{config;hook;root=M([]);socket;id=x(4);path=M("");lastPath=M("");loading=M(!1);mainElement;A;Main;load;matchPath;isYvee=!1;constructor(t={},r={}){super(t.base??"");this.config=t;if(this.socket=new Wt(this),t.id)this.id=t.id;this.A=(n,...i)=>{if(this.base){if(!n.href.startsWith(this.base))n.href=this._base(n.href)}return un(n,i,this.path,this.lastPath)},this.Main=(n)=>{if(R(r))if(!n.on)n.on=r;else p(n.on,r);return hn(this,n,this.isYvee)},this.load=async(n,i={})=>{if(this.hook)this.hook();if(n){this.path.value=n,this.lastPath.value=n;try{await this.render(n,404,i),this.hooker()}catch(o){E.e=["render error",{error:"Pager loader"}]}}return this},this.matchPath=(n)=>{let i=this._base(n),o=this.path.value,e=this.base;if(o===i)return!0;else{let f=o.replace(e,""),s=i.replace(e,"");if(s){if(f.startsWith(s))return!0}else if(!o)return!0}return!1}}hooker(){let t={},r={},n=this.path.value;if(this.hook)this.hook();this.hook=V(async(i)=>{if(r[n]=window.scrollY,t[n]=this.mainElement?.scrollTop??0,(await this.render(i,404)).done){let o=r[i]??0;if(o)window.scrollTo({top:o,behavior:"instant"});let e=t[i]??0;if(e)this.mainElement?.scrollTo({top:e,behavior:"instant"});n=i}},[this.path],{id:"router"})}async class(t,r,n=!1){let[i,o]=await this.getPath(t);if(i&&!n){let{cls:e,id:f}=i;return new e(t,o,f)}else return await an.call(this,t,404)}async fetch(t){if(t)try{if(t.fetch){let r=await t.fetch();if(D(r)&&R(r))t.data=r}}catch(r){E.e=["class fetch",{error:"fetch"}]}}async processHead(t,r={}){return t?await this.processClassHead(t,r):await this.processDefaultHead(r)}async processClassHead(t,r){if(t.head)await t.head();return t.getHeadAttr(r,this.htmlHead)}async processDefaultHead(t){let r=new Q;if(R(t))r.head=t;return r.head.map(this.htmlHead),r.head}async render(t,r=404,n={},i={},o=!0,e=!1){let f=await this.class(t,r??Gt(),e);f.data=n,await this.fetch(f);let s=await this.processHead(f,i);if(T)Qt.set(this.id,s);if(!f)return{lang:this.lang,heads:s,done:!1};let u=[];if(this.loading.value=!0,this.isYvee)u=await f.loader();let h=[];if(o)h=await Rr.call(this,s,f?.lang||this.lang);if(!this.isYvee)u=await f.loader(),h.forEach((l)=>l());if(this.isYvee)h.forEach((l)=>l());if(u.length)this.root.value=u;else await this.render(t,r,n,i,o,!0);return this.loading.value=!1,{heads:s,lang:f.lang??this.lang,done:!0}}}var at=M("");class Et extends lt{config;isYvee=!0;unload=!0;constructor(t={},r={}){super(t,r);this.config=t;this.path=at,this.load=async(n,i={})=>{if(B)n=mn()||this._base(n??"/");if(this.hook)this.hook();if(n){this.path.value=n,this.lastPath.value=n;try{await this.render(n,404,i),this.hooker()}catch(o){E.e=["render error",{error:"Yvee loader"}]}}return this}}}var ln=(t)=>{return(r)=>{t(r)}};function mn(){if(B)return d('meta[name="yvee"]')?.attr.get("content")??"/";return""}var Ar=(t,r,n,i=!1)=>{let o=[];if(o.push({charset:"utf-8"}),o.push({name:"viewport",content:"width=device-width, initial-scale=1.0"}),n)switch(n){case 404:o.push({name:"error",content:n.toString()});break;default:break}if(i)o.push({name:"yvee",content:r});if(t.meta)if(m(t.meta))t.meta.unshift(...o);else t.meta.push(o);else t.meta=o},Hr=async(t,r,n={},i=[])=>{let o=await r(n),e=m(o)?o:[o],f=new F(t,new H(t));return e.forEach((s)=>{ht(s,e.length,f,i)}),f.OZ.set(f),f.OZ};async function gn(t,r,n={}){let{bodyattr:i={},id:o,route:e,base:f="",index:s,data:u}=n;if(B){let h={},l=document.body.id;if(r)if(r instanceof Et)await r.load();else{if(u)if(w(u))h=await u();else h=u;let c=window.location.pathname;if(p(h,{path:c,status:Gt()}),e){if(e.length>1&&e.slice(-1)!=="/")c=c.replace(/^\/|\/$/g,"");p(h,Tt(c,e))}}let b=await Hr(l,t,h);L.push(b),requestAnimationFrame(()=>{L.stage})}return async({path:h,data:l={},status:b=200})=>{let c=x(4),J=new a,y={};if(o)c=o;if(i.id)c=i.id.toString();let Kt="en";if(r instanceof Et){let{base:C,path:mt,id:Dr,lang:jr}=r;if(y.base=[{href:C==="/"?C:`${C}/`,target:"_blank"}],y.script)y.script.push({type:"module",src:"./index.js"});else y.script=[{type:"module",src:"./index.js"}];mt.value=h,Ar(y,h,b,!0);let{heads:Vt}=await r.render(h,b,l,y,!1);Qt.values().forEach((Mr)=>{p(Vt.init("link",{}),Mr.get("link")??{})}),c=Dr,J=Vt,Kt=jr}else{let C=h==="/"?h:`${h}/`;if(s)C=`${s}/`;if(f)C=`${f}${C}`;if(y.base=[{href:C,target:"_self"}],y.script)y.script.push({type:"module",src:"./index.js"});else y.script=[{type:"module",src:"./index.js"}];if(e)p(l,Tt(h,e));p(l,{status:b,path:h,base:f}),p(y,w(r)?await r(l):r),Ar(y,h,b);let mt=new ot;mt.head(y),J=mt.htmlHead}let zt=[];return await Hr(c,t,l,zt),new It(Kt,J).body(zt.join(""),c,it(i))}}var Fs=(t,r)=>{return`${t.replace(/\/+$/,"")}/${r.replace(/^\.\/+/,"")}`},Xs=(t)=>{if(T)return;return t()};export{Jt as websocket,en as useRef,dr as session,Fs as resolvePath,q as pushHistory,E as log,cr as local,on as frag,mr as eventStream,X as dom,$t as doc,Mt as cssLoader,Nr as addCSS,ur as __,Et as Yvee,Y as Stateful,V as StateHook,M as State,ln as Routes,gn as Render,ft as Ref,lt as Pager,nt as Meta,Xs as IfClient,O as Dom,d as $};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yvee",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Yvee JS framework",
5
5
  "author": "Marky <markjotep@gmail.com>",
6
6
  "license": "MIT",