yvee 0.0.4 → 0.0.6
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/LICENSE +1 -1
- package/dist/index.d.ts +84 -39
- package/dist/index.js +1 -1
- package/package.json +4 -12
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
declare const isFN: (v: any) => v is Function;
|
|
2
|
+
declare const isAsync: (v: any) => v is Function;
|
|
3
|
+
declare const isNumber: (value: any) => boolean;
|
|
4
|
+
declare const isDict: (val: any) => boolean;
|
|
5
|
+
declare const isPlainObject: (value: any) => boolean;
|
|
6
|
+
declare const isArraybuff: (val: any) => val is string | ArrayBuffer | Uint8Array<ArrayBufferLike>;
|
|
7
|
+
declare const isClassOrId: (k: string) => boolean;
|
|
8
|
+
declare const isBool: (v: any) => v is boolean;
|
|
9
|
+
declare const isStr: (v: any) => v is string;
|
|
10
|
+
declare const isArr: (v: any) => v is any[];
|
|
11
|
+
declare const isObj: (v: any) => v is object;
|
|
12
|
+
declare const isNum: (v: any) => v is number;
|
|
13
|
+
declare const isNull: (v: any) => v is null;
|
|
14
|
+
declare const isUndefined: (v: any) => v is undefined;
|
|
15
|
+
declare const isInt: (str: string) => boolean;
|
|
16
|
+
declare const isWindow: boolean;
|
|
17
|
+
declare const isNotWindow: boolean;
|
|
18
|
+
|
|
19
|
+
declare const is_isArr: typeof isArr;
|
|
20
|
+
declare const is_isArraybuff: typeof isArraybuff;
|
|
21
|
+
declare const is_isAsync: typeof isAsync;
|
|
22
|
+
declare const is_isBool: typeof isBool;
|
|
23
|
+
declare const is_isClassOrId: typeof isClassOrId;
|
|
24
|
+
declare const is_isDict: typeof isDict;
|
|
25
|
+
declare const is_isFN: typeof isFN;
|
|
26
|
+
declare const is_isInt: typeof isInt;
|
|
27
|
+
declare const is_isNotWindow: typeof isNotWindow;
|
|
28
|
+
declare const is_isNull: typeof isNull;
|
|
29
|
+
declare const is_isNum: typeof isNum;
|
|
30
|
+
declare const is_isNumber: typeof isNumber;
|
|
31
|
+
declare const is_isObj: typeof isObj;
|
|
32
|
+
declare const is_isPlainObject: typeof isPlainObject;
|
|
33
|
+
declare const is_isStr: typeof isStr;
|
|
34
|
+
declare const is_isUndefined: typeof isUndefined;
|
|
35
|
+
declare const is_isWindow: typeof isWindow;
|
|
36
|
+
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 };
|
|
38
|
+
}
|
|
39
|
+
|
|
1
40
|
type V = string | number | boolean;
|
|
2
41
|
type obj<T> = Record<string, T>;
|
|
3
42
|
|
|
@@ -143,7 +182,7 @@ type CSSinT$1 = {
|
|
|
143
182
|
type headType = Mapper<keyof head, any>;
|
|
144
183
|
declare class htmlHead {
|
|
145
184
|
lang: string;
|
|
146
|
-
htmlHead: headType;
|
|
185
|
+
protected htmlHead: headType;
|
|
147
186
|
head: (heads?: headAttr) => void;
|
|
148
187
|
constructor();
|
|
149
188
|
}
|
|
@@ -177,7 +216,7 @@ declare class __ {
|
|
|
177
216
|
}): HTMLElement;
|
|
178
217
|
static randFrom(arr: any[] | Object): any;
|
|
179
218
|
static makeID: (length: number) => string;
|
|
180
|
-
static
|
|
219
|
+
static class(a: obj<any>, classes: string[]): void;
|
|
181
220
|
static get O(): {
|
|
182
221
|
vals: {
|
|
183
222
|
<T>(o: {
|
|
@@ -204,6 +243,11 @@ declare class __ {
|
|
|
204
243
|
};
|
|
205
244
|
len: (obj?: {}) => number;
|
|
206
245
|
};
|
|
246
|
+
static get is(): typeof is;
|
|
247
|
+
static get return(): typeof returner;
|
|
248
|
+
}
|
|
249
|
+
declare class returner {
|
|
250
|
+
static array(val: any): any[];
|
|
207
251
|
}
|
|
208
252
|
|
|
209
253
|
declare class CATT {
|
|
@@ -237,15 +281,6 @@ declare class OZ {
|
|
|
237
281
|
RPS(oz?: this): this;
|
|
238
282
|
}
|
|
239
283
|
|
|
240
|
-
declare class CTX {
|
|
241
|
-
tag: string;
|
|
242
|
-
ctx: ctx[];
|
|
243
|
-
closing: string;
|
|
244
|
-
constructor(tag: string, ctx: ctx[]);
|
|
245
|
-
private process;
|
|
246
|
-
get(catt: CATT): string;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
284
|
declare class eStream {
|
|
250
285
|
stream: EventSource;
|
|
251
286
|
url: string;
|
|
@@ -344,37 +379,47 @@ interface yveeCfg {
|
|
|
344
379
|
}
|
|
345
380
|
declare class Router extends minClient {
|
|
346
381
|
private isYRA;
|
|
347
|
-
|
|
382
|
+
protected unload: boolean;
|
|
383
|
+
protected hook?: () => void;
|
|
384
|
+
protected root: Stateful<ctx[]>;
|
|
385
|
+
protected socket: socket;
|
|
348
386
|
id: string;
|
|
349
|
-
root: Stateful<ctx[]>;
|
|
350
387
|
path: Stateful<string>;
|
|
351
|
-
|
|
352
|
-
element: Stateful<HTMLElement | null>;
|
|
388
|
+
lastPath: Stateful<string>;
|
|
353
389
|
A: (a: attr & {
|
|
354
390
|
href: string;
|
|
355
391
|
}, ...D: ctx[]) => Dom;
|
|
356
|
-
Main: (a: attr
|
|
392
|
+
Main: (a: attr & {
|
|
393
|
+
load?: string;
|
|
394
|
+
}) => Dom;
|
|
357
395
|
load: (path?: string, data?: obj<string>) => Promise<this>;
|
|
358
396
|
constructor(ImportMeta: ImportMeta, config?: yveeCfg, isYRA?: boolean);
|
|
359
|
-
hooker(): void;
|
|
360
|
-
class(this: Router, _path: string, _error: number, isError?: boolean): Promise<doc<{}>>;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}>;
|
|
364
|
-
fetch(CL?: doc<{}>): Promise<void>;
|
|
365
|
-
}
|
|
366
|
-
declare class Yvee extends Router {
|
|
367
|
-
constructor(ImportMeta: ImportMeta, { classes, pushState }?: yveeCfg);
|
|
368
|
-
processHead(CL?: doc<{}>, head?: headAttr): Promise<headType>;
|
|
397
|
+
protected hooker(): void;
|
|
398
|
+
protected class(this: Router, _path: string, _error: number, isError?: boolean): Promise<doc<{}>>;
|
|
399
|
+
protected fetch(CL?: doc<{}>): Promise<void>;
|
|
400
|
+
protected processHead(CL?: doc<{}>, head?: headAttr): Promise<headType>;
|
|
369
401
|
private processClassHead;
|
|
370
402
|
private processDefaultHead;
|
|
371
|
-
render(_path
|
|
403
|
+
protected render(_path: string, _error?: number, data?: obj<string>, head?: headAttr, isClient?: boolean, isError?: boolean): Promise<{
|
|
372
404
|
lang: string;
|
|
373
405
|
heads: headType;
|
|
374
406
|
done: boolean;
|
|
375
407
|
}>;
|
|
376
|
-
html(path: string, data?: obj<string>, status?: number): Promise<string>;
|
|
377
408
|
}
|
|
409
|
+
declare class Yvee extends Router {
|
|
410
|
+
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;
|
|
378
423
|
|
|
379
424
|
declare class ClientPath extends MinStorage {
|
|
380
425
|
id: string;
|
|
@@ -387,11 +432,11 @@ declare class SocketPath extends MinStorage {
|
|
|
387
432
|
constructor(path: string, id: string, cls: typeof websocket<{}>);
|
|
388
433
|
}
|
|
389
434
|
declare class minClient extends htmlHead {
|
|
390
|
-
ImportMeta: ImportMeta;
|
|
391
|
-
config: yveeCfg;
|
|
392
|
-
storage: Storage$1<ClientPath>;
|
|
393
|
-
errorStorage: Storage$1<ClientPath>;
|
|
394
|
-
wssStorage: Storage$1<SocketPath>;
|
|
435
|
+
protected ImportMeta: ImportMeta;
|
|
436
|
+
protected config: yveeCfg;
|
|
437
|
+
protected storage: Storage$1<ClientPath>;
|
|
438
|
+
protected errorStorage: Storage$1<ClientPath>;
|
|
439
|
+
protected wssStorage: Storage$1<SocketPath>;
|
|
395
440
|
/** --------------------
|
|
396
441
|
* string | int | float | file | uuid
|
|
397
442
|
* - /url/\<string:hell>
|
|
@@ -400,9 +445,9 @@ declare class minClient extends htmlHead {
|
|
|
400
445
|
error: (...codes: number[]) => <Q extends typeof doc<{}>>(f: Q) => Q;
|
|
401
446
|
wss: (path: string) => <Q extends typeof websocket<{}>>(f: Q) => Q;
|
|
402
447
|
constructor(ImportMeta: ImportMeta, config: yveeCfg);
|
|
403
|
-
getPath(path: string): Promise<[ClientPath | undefined, Record<string, string>]>;
|
|
404
|
-
loadError(code: number): Promise<[ClientPath | undefined, Record<string, string>]>;
|
|
405
|
-
loadWSS(path: string): Promise<[SocketPath | undefined, Record<string, string>]>;
|
|
448
|
+
protected getPath(path: string): Promise<[ClientPath | undefined, Record<string, string>]>;
|
|
449
|
+
protected loadError(code: number): Promise<[ClientPath | undefined, Record<string, string>]>;
|
|
450
|
+
protected loadWSS(path: string): Promise<[SocketPath | undefined, Record<string, string>]>;
|
|
406
451
|
}
|
|
407
452
|
|
|
408
453
|
type Elements = HTMLElementTagNameMap[keyof HTMLElementTagNameMap];
|
|
@@ -436,7 +481,6 @@ declare class Stateful<T> extends EventTarget {
|
|
|
436
481
|
declare function State<T>(value: T): Stateful<T>;
|
|
437
482
|
|
|
438
483
|
type X2 = V | V[];
|
|
439
|
-
type ctx = V | Dom | Stateful<V | Dom> | ctx[];
|
|
440
484
|
type X3 = X2 | Stateful<X2>;
|
|
441
485
|
type CSSinT = {
|
|
442
486
|
[P in keyof CSSStyleDeclaration]?: X3;
|
|
@@ -463,7 +507,7 @@ interface baseAttr {
|
|
|
463
507
|
declare class Dom {
|
|
464
508
|
tag: string;
|
|
465
509
|
private attr;
|
|
466
|
-
ctx
|
|
510
|
+
private ctx;
|
|
467
511
|
constructor(tag: string, attr?: attr, ...ctx: ctx[]);
|
|
468
512
|
__(pid?: idm): {
|
|
469
513
|
ctx: string;
|
|
@@ -583,6 +627,7 @@ declare global {
|
|
|
583
627
|
[P in keyof GlobalEventHandlersEventMap]?: (this: Elements, e: GlobalEventHandlersEventMap[P]) => void;
|
|
584
628
|
} & c_events;
|
|
585
629
|
type attr = baseAttr | obj<X3>;
|
|
630
|
+
type ctx = V | Dom | Stateful<V | Dom> | ctx[];
|
|
586
631
|
type obj<T> = Record<string, T>;
|
|
587
632
|
type DomFN<T extends {}> = (a: attr & T, ...D: ctx[]) => Dom;
|
|
588
633
|
namespace JSX {
|
|
@@ -756,4 +801,4 @@ declare global {
|
|
|
756
801
|
}
|
|
757
802
|
declare const resolvePath: (base: string, relative: string) => string;
|
|
758
803
|
|
|
759
|
-
export { $, $$, ColorScheme, Dom, Meta, Router, State, Stateful, Yvee, type _$, __, addCSS, cssLoader,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Sn=function(n,t,r,i){var o=arguments.length,s=o<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,r):i,e;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(n,t,r,i);else for(var f=n.length-1;f>=0;f--)if(e=n[f])s=(o<3?e(s):o>3?e(t,r,s):e(t,r))||s;return o>3&&s&&Object.defineProperty(t,r,s),s};var Mn=(n,t)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(n,t)};var $=(n)=>typeof n==="function";var U=(n)=>{return!isNaN(parseFloat(n))&&isFinite(n)},ln=(n)=>{return typeof n==="object"&&n!==null&&!Array.isArray(n)},a=(n)=>{return typeof n==="object"&&n!==null&&Object.getPrototypeOf(n)===Object.prototype};var k=(n)=>typeof n==="boolean",v=(n)=>typeof n==="string",l=(n)=>Array.isArray(n),F=(n)=>typeof n==="object",Gn=(n)=>typeof n==="number",N=(n)=>n===null,An=(n)=>typeof n==="undefined",Kn=(n)=>{return Number.isInteger(Number(n))},Tn=typeof window!=="undefined",b=typeof window==="undefined";function nn(n,t){m(t).forEach(([r,i])=>{In(n,r,{value:i,writable:!1,configurable:!1,enumerable:!0})})}class A{static set p(n){if(Array.isArray(n))console.log(...n);else console.log(n)}}class c{_c=0;_id="";constructor(n){if(this._c=0,this._id=n??x(5),n?.includes("-")){let[t,r]=[n.split("-").slice(0,-1).join("-"),n.split("-").slice(-1)[0]];this._id=t,this._c=U(r)?parseInt(r):0}}get id(){return this._id+"-"+this._c}get mid(){return this._id+"-"+ ++this._c}}var _t=new RegExp(/(\d+)(\d*)/,"m"),lt=(n)=>Array.from({length:n},(t,r)=>r),Tt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",ht="abcdefghijklmnopqrstuvwxyz",bt=lt(10).join("");var j=(n)=>JSON.stringify(n),wn=(n)=>{return JSON.parse(n)},B=(n)=>{if(n.startsWith("webkit"))n="-"+n;return n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},x=(n)=>{let t=Tt+ht;return Array.from({length:n},(r,i)=>t+(i?bt:"")).reduce((r,i)=>{return r+=i.charAt(Math.floor(Math.random()*i.length))},"")};class u extends Map{obj(n){n&&m(n).forEach(([t,r])=>this.set(t,r))}map(n){n.forEach((t,r)=>{if(t instanceof u)this.set(r,t);else if(l(t)){if(this.lacks(r))this.set(r,[]);this.get(r).push(...t)}else if(F(t))this.ass(r,t);else this.set(r,t)})}ass(n,t){if(!this.has(n))this.set(n,{});y(this.get(n),t)}lacks(n){return!this.has(n)}init(n,t){return this.has(n)?this.get(n):this.set(n,t).get(n)}}var{values:E,keys:K,entries:m}=Object;var{hasOwn:Wn,freeze:Pn,defineProperty:In,assign:y}=Object,q=(n)=>{return Object.keys(n).length},tn=(n,t)=>{if(!t.has(n))t.set(n,new u);return t.get(n)},R=(n,t)=>{if(!t.has(n))t.set(n,[]);return t.get(n)},hn=(n,t)=>{let r={added:{},removed:{},modified:{}},i=K(n),o=K(t);for(let s of o){let e=n[s],f=t[s];if(!(s in n))r.added[s]=f;else if(l(e)&&l(f)){if(j(e)!==j(f))r.modified[s]={old:e,new:f}}else if(F(e)&&F(f)&&!N(e)&&!N(f)){let g=hn(e,f);if(q(g.added)||q(g.removed)||q(g.modified))r.modified[s]={old:e,new:f}}else if(e!==f)r.modified[s]={old:e,new:f}}for(let s of i)if(!(s in t))r.removed[s]=n[s];return r};function zn(n,t){if(n.size!==t.size)return!1;for(let r of n)if(!t.has(r))return!1;return!0}var Nn=(n)=>{return E(n).some((t)=>{return q(t)})};function Rn(n){let t;return class extends n{constructor(...r){if(t)return t;super(...r);Pn(this),t=this}}}var D=(n,t)=>{return{name:n,content:t}},ct=(n,t)=>{return{property:n,content:t}},xt=(n,t)=>{return{"http-equiv":n,content:t}};class rn{metas=[];constructor(n){n&&this.metas.push(D("description",n))}author(n){return this.meta=D("author",n),this}charset(n){return this.meta={charset:n},this}keywords(...n){return this.meta=D("keywords",n.join(", ")),this}viewport(n){let t=m(n).map(([r,i])=>[B(r),String(i)].join("="));return this.meta=D("viewport",t.join(", ")),this}httpEquiv(n){return m(n).forEach(([t,r])=>{this.meta=xt(B(t),String(r))}),this}robots(...n){return this.meta=D("robots",n.join(", ")),this}themeColor(n){return this.meta=D("theme-color",n),this}openGraph(n){return m(n).forEach(([t,r])=>{this.meta=ct("og:"+t,String(r))}),this}twitter(n){return m(n).forEach(([t,r])=>{this.meta=D("twitter:"+t,String(r))}),this}and(n){return this}set meta(n){this.metas.push(n)}}class bn{title;description;base;meta;link;script;css}var yt=["charset","name","property","http-equiv"],dn=(n,t)=>{t.forEach((r)=>{for(let i of yt)if(i in r){let o=r[i];n[`${i}_${i==="charset"?"":o}`]=r}})},pt=(n,t)=>{t.forEach((r)=>{if("href"in r){let i=r.href;n[`${i}`]=r}})};class I{_head;idm;constructor(n){this._head=new u(n)}set head(n){m(n).forEach(([t,r])=>{if(t==="title"||t==="base"){if(r!==void 0)this._head.set(t,r);return}if(r instanceof rn)return dn(this._head.init("meta",{}),r.metas);if(!l(r))return;switch(t){case"meta":return dn(this._head.init("meta",{}),r);case"link":return pt(this._head.init("link",{}),r);case"script":if(r.length){this._head.init(t,[]);let i=r.map((o)=>{if(!o.yid&&this.idm)o.yid="sc"+this.idm.mid;return o});this._head.get(t).push(...i)}return}})}get head(){return this._head}set id(n){this.idm=new c(n)}}var Ln=(n)=>{return m(n).reduce((t,[r,i])=>{return t.push(k(i)&&i?r:`${r}="${i}"`),t},[""]).join(" ")},Vn=(n)=>{if(!n)return"";return[...n].reduce((t,[r,i])=>{if(r==="meta"||r==="link")i=E(i);if(v(i))return t.push(`<${r}>${i}</${r}>`),t;if(!l(i))return t;let o=i.map((s)=>{if(r==="script"){let e={...s};if("yid"in e)return"";let f="";if("importmap"in e)e.type="importmap",f=JSON.stringify(e.importmap),delete e.importmap;else if("body"in e)f=e.body,delete e.body;return`<${r}${Ln(e)}>${f}</${r}>`}return`<${r}${Ln(s)}>`});return t.push(...o),t},[]).join("")};class cn{lang="en";htmlHead=new u;head;constructor(){this.head=(n={})=>{let t=new I(this.htmlHead);t.head=n,this.htmlHead=t.head}}}var xn=(n)=>{if(b)return;return new Promise((t,r)=>{let i=document.createElement("link");if(n.rel!=="stylesheet")n.rel="stylesheet",n.as="style";m(n).forEach(([o,s])=>{i.setAttribute(o,s)}),i.onload=()=>t(i),i.onerror=()=>r(new Error("Failed to load CSS")),document.head.appendChild(i)})},Et=()=>{let t=document.querySelector("#d-css")?.sheet;if(t)return t;let r=document.createElement("style");return r.id="d-css",document.head.appendChild(r),r.sheet},$t=(n,t)=>{for(let r=0;r<n.cssRules.length;r++)if(n.cssRules[r].selectorText===t)return!0;return!1},jt=(n)=>Object.entries(n).map(([t,r])=>`${B(t)}: ${r};`).join(" ");function qt(n,t={}){if(b)return;let r=Et();if(!r)return;if(!$t(r,n))r.insertRule(`${n} { ${jt(t)} }`,r.cssRules.length)}var On=(n,t)=>{let r=t;if(n?.class)r.push(...l(n.class)?n.class:[n.class]);return delete n.class,r.filter((i)=>i)};var Cn=(n,t=!1)=>{if(U(n))return[+n,Kn(n)?"int":"float"];if(t&&/\.\w+$/.test(n))return[n,"file"];if(n==="/")return[n,"-"];if(n.length===36&&n.match(/\-/g)?.length===4)return[n,"uuid"];return[n,"string"]},on=(n)=>{let t=n.startsWith("/")?n:"/"+n,r=t.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[i,o]=r.reduce(([s,e],f)=>{if(f.includes("<")){let g=f.match(/(?<=<)[^/].*?(?=>|$)/g);if(g?.length){let[h,p]=g[0].split(":");if(h&&p)s.push(h),e.push(p)}}else s.push(f===">"?"/":f);return[s,e]},[[],[]]);if(t.endsWith("/")&&t.length>1)i.push("/");return{parsed:i,args:o}};class sn{storage=new u;cache(n,t){if(this.storage.lacks(n))this.storage.set(n,t());return this.storage.get(n)}}var Ft=["int","float","file","uuid","string"],Ht=new sn;class w{_storage=new u;set(n){let{parsed:t,path:r}=n,i=j(t);if(!this._storage.get(i))this._storage.set(i,n);else throw`path: ${r} already used.`}get(n){let{parsed:t}=Ht.cache(n,()=>on(n)),r={},i=this._storage.get(j(t));if(!i&&n!=="/")for(let o of this._storage.keys()){let s=[],e=wn(o);if(t.length===e.length){let f=e.map((p,H)=>{let Z=Cn(t[H],t.length-1===H);if(p===Z[0])return Z[0];if(Ft.includes(Z[1]))return s.push(Z[0]),Z[1];return p}),g=j(f);if(this._storage.has(g)){i=this._storage.get(g),i?.args.forEach((p,H)=>{r[p]=s[H]});break}}}return[i,r]}}class d{path="";parsed=[];args=[];constructor(n){nn(this,{path:n,...on(n)})}}class _n{static rand(n=6,t){if(t)return Math.floor(Math.random()*(t-n+1)+n);return Math.floor(Math.random()*n)+1-1}static fill(n,t=null){return Array(n).fill(t)}static new({dom:n,id:t,inner:r}){let i=document.createElement(n);if(t)i.id=t;if(r)i.innerHTML=r;return i}static randFrom(n){if(Array.isArray(n)){let t=n.length,r=this.rand(0,t-1);return n[r]}else if(typeof n=="object"){let t=K(n),r=t.length,i=this.rand(0,r-1);return t[i]}}static makeID=x;static reClass=On;static get O(){return{vals:E,keys:K,items:m,has:Wn,ass:y,len:(n={})=>K(n).length}}}var yn={},S={};class an{stream;url;constructor(n,t){if(this.url=n,n in yn)this.stream=yn[n];else this.stream=new EventSource(n,{withCredentials:t}),yn[n]=this.stream,S[this.url]={}}on(n){let t=this.stream;return m(n).forEach(([r,i])=>{if(r in S[this.url])S[this.url][r].forEach((o)=>{this.stream.removeEventListener(r,o)}),S[this.url][r]=[];if(t.addEventListener(r,i),!(r in S[this.url]))S[this.url][r]=[];S[this.url][r].push(i)}),this}}function kn(n,t=!0){return new an(n,t)}class vn{value;constructor(n){this.value=n}get str(){return String(this.value).toString()=="null"?null:String(this.value).toString()}get int(){if(U(this.value))return parseInt(this.value);else return null}get float(){if(U(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 L{key;func;storage;constructor(n,t="local"){if(typeof n=="object"){let[r,i]=m(n)[0];this.key=r,this.func=i}else this.key=n,this.func=null;this.storage=t=="local"?localStorage:sessionStorage}get as(){return new vn(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(n){if(typeof n=="object")this.storage.setItem(this.key,JSON.stringify(n));else this.storage.setItem(this.key,String(n))}get remove(){this.storage.removeItem(this.key);return}}var V={get:(n)=>new L(n)};var nt={get:(n)=>new L(n,"session")};class en extends d{id;cls;constructor(n,t,r){super(n);this.id=t;this.cls=r}}class tt extends d{id;cls;constructor(n,t,r){super(n);this.id=t;this.cls=r}}class fn extends cn{ImportMeta;config;storage=new w;errorStorage=new w;wssStorage=new w;route;error;wss;constructor(n,t){super();this.ImportMeta=n;this.config=t;this.route=(r)=>{return(i)=>{return this.storage.set(new en(r,x(5),i)),i}},this.wss=(r)=>{return(i)=>{return this.wssStorage.set(new tt(r,x(5),i)),i}},this.error=(...r)=>{return(i)=>{if(r.length)r.forEach((o)=>{this.errorStorage.set(new en(o.toString(),x(5),i))});else this.errorStorage.set(new en("404",x(5),i));return i}}}async getPath(n){return this.storage.get(n)}async loadError(n){return this.errorStorage.get(n.toString())}async loadWSS(n){return this.wssStorage.get(n)}}var O=new u,C=(n)=>{if(b)return;let t=O.get(n);if(t?.isConnected)return t;O.delete(n);let r=document.getElementById(n);if(!r)return;return O.set(n,r),r};function rt(){let n=[];return O.forEach((t,r)=>{if(!t.isConnected)n.push(r),O.delete(r)}),n}function W(n,t,{id:r="state",init:i}={}){let o=[],s=()=>t.map((f)=>f.value),e=()=>{n(...s())};if(t.forEach((f)=>{o.push(f.hook(e)(r))}),i)e();return()=>{o.forEach((f)=>f())}}var it=(n)=>{n.forEach((t)=>t())};var Zt=(n,t)=>{for(let[r,i]of n){let o=C(r);if(!o){n.delete(r);continue}i.forEach((s)=>{s.call(o,t)})}};class M extends EventTarget{options;hooks=new u;states=new u;_value;listening=!1;end;constructor(n,t){super();this.options=t;this._value=n}get value(){return this._value}set value(n){if(N(n)||An(n))return;if(a(this._value)||l(this._value)){let t=hn(this._value,n);if(!Nn(t))return}else if(this._value instanceof Set){if(!zn(this._value,n))return}else if(this._value===n)return;this._value=n,this.dispatchEvent(new CustomEvent("updated",{detail:this._value}))}get listen(){let n=(t)=>{if(it(this.hooks),Zt(this.states,t.detail),!this.states.size&&!this.hooks.size)this.end?.()};if(!this.listening)this.addEventListener("updated",n,this.options),this.listening=!0;return()=>{this.listening&&this.removeEventListener("updated",n,this.options),this.end=void 0,this.listening=!1}}call(n,t){return(r)=>{if(tn(r,this.states).set(t,n),!b&&!this.listening)this.end=this.listen;return()=>{if(this.states.has(r))this.states.get(r)?.delete(t)}}}hook(n){return(t)=>{if(this.hooks.set(t,n),!b&&!this.listening)this.end=this.listen;return()=>{if(this.hooks.has(t))this.hooks.delete(t)}}}}function J(n){return new M(n)}var pn=(n)=>{if(l(n))return n.join(" ");else if(F(n)){if(ln(n))return j(n)}else if($(n))return pn(n());else if(n!==void 0&&n!==null)return k(n)?n?"":"false":String(n);return""};function Jt(n,t){switch(t??n){case"style":return function(r){this.style.setProperty(n,r)};default:return function(r){this.setAttribute(n,r)}}}class En{attr;constructor(n={}){this.attr=n}get(n,t=this.attr,r){let i=(o,s)=>{if(l(s))n.attr_push(o,pn(s));else if(s instanceof M){let e=r?`${r}_${o}`:o;n.states.push(s.call(Jt(o,r),e)),i(o,s.value)}else if(F(s)){if(ln(s)&&!r)this.get(n,s,o)}else n.attr_push(o,pn(s),r)};m(t).forEach(([o,s])=>{if(["on"].includes(o))F(t.on)&&n.events.obj(t.on);else i(o,s)})}}class P{xid;IDM;map=new u;states=[];events=new u;OZ;constructor(n,t=new c,r){this.xid=n;this.IDM=t;this.OZ=r??new un}attr_push(n,t,r){let i=r??n;if(!this.map.has(i))this.map.set(i,[]);let o=r?`${B(n)}:${t};`:t;this.map.get(i).push(o)}get attr(){let n=[""];return this.map.forEach((t,r)=>{let i=t.join("");n.push(i?`${r}="${i}"`:r)}),n.join(" ")}set id(n){if(!this.map.has("id"))this.map.set("id",[n])}get id(){return this.map.get("id")?.join("")}}var Xt=(n,t,r)=>{return n.addEventListener(t,r),()=>{n.removeEventListener(t,r)}},_={};class un{events=new u;states=new u;winStates=new u;windowEvents=new u;resetST=new u;resetEV=new u;constructor(){}get keys(){return[...new Set([...this.states.keys(),...this.events.keys()])]}set(n){let{id:t,events:r,states:i}=n;if(t){if(r.size)this.events.set(t,r);if(i.length)this.states.set(t,i)}return this}push(n){return n.events.forEach((t,r)=>{t.forEach((i,o)=>{tn(r,this.events).set(o,i)})}),n.states.forEach((t,r)=>{R(r,this.states).push(...t)}),this}get stage(){return this.events.forEach((n,t)=>{this.events.delete(t);let r=C(t);if(!r){this.events.delete(t);return}n.forEach((i,o)=>{switch(o){case"ready":i.apply(r,[r]);break;case"resize":case"beforeunload":case"popstate":case"winscroll":case"winload":case"winfocus":case"winblur":let s=o.replace(/^win/,"");this.windowEvents.init(s,new u).set(t,i);break;case"watch":let[e,f,g]=i.apply(r,[r]),h=l(f)?f:[f],p=()=>h.map((Z)=>Z.value),H=()=>e(...p());if(g)H();h.forEach((Z)=>R(t,this.resetST).push(Z.call(H,t+"_watch")(t)));break;default:R(t,this.resetEV).push(Xt(r,o,i))}})}),this.processWindowEvents,this.states.forEach((n,t)=>{this.states.delete(t),n.forEach((r)=>{R(t,this.resetST).push(r(t))})}),this}get processWindowEvents(){let n=(t,r)=>{let i=(o)=>{r.forEach((s,e)=>{let f=C(e);if(f)s.call(f,o);else this.windowEvents.get(t)?.delete(e)})};return window.addEventListener(t,i),()=>{window.removeEventListener(t,i)}};return this.windowEvents.forEach((t,r)=>{if(t.size){if(!_[r])_[r]=n(r,t)}else if(_[r])_[r](),delete _[r]}),this}reset(n){return n.forEach((t)=>{this.windowEvents.forEach((r,i)=>{if(r.has(t))r.delete(t)}),this.resetEV.get(t)?.forEach((r)=>{r()}),this.resetST.get(t)?.forEach((r)=>{r()}),this.resetST.delete(t),this.resetEV.delete(t)}),this}RPS(n){if(n){let t=rt();this.reset(t);let r=n.keys;if(r.length)this.reset(r).push(n).stage}return this}}var X=new un;var Qt=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],Yt=(n)=>Qt.includes(n);function Ut(n){return String(n).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var mn=(n,t)=>{if(l(n))return n.map((r)=>mn(r,t)).join("");else if(n instanceof Q){let r=n.__(t.IDM),{ctx:i,oz:o}=r;return t.OZ.push(o),i}else if(F(n))return j(n);else if($(n))return mn(n(),t);else if(n!==void 0&&n!==null)return Ut(n);return""},ot=(n,t)=>{let r=new c(n),i=new P(r.id,r);return{ctx:mn(t,i),catt:i}};function Bt(n){let t=this.id;if(t){let{ctx:r,catt:i}=ot(t,n);if(this.innerHTML!==r)this.innerHTML=r,X.RPS(i.OZ)}}var $n=(n,t,r,i=[])=>{if(l(n))n.forEach((o)=>{$n(o,n.length,r,i)});else if(n instanceof M)if(t>1)$n(Y("div",{},n),t,r,i);else{let o=n.value,s=o instanceof Q?"dom":"ctx",{ctx:e,catt:f}=ot(r.xid+"-0",o);r.xid=f.xid,i.push(e),r.OZ.push(f.OZ),r.states.push(n.call(Bt,s))}else i.push(mn(n,r))};class jn{tag;ctx;closing;constructor(n,t){this.tag=n;this.ctx=t;let r=Yt(n);this.closing=r?"":`</${n}>`}process(n,t=this.ctx,r=[]){return t.forEach((i)=>{$n(i,t.length,n,r)}),r.join("")}get(n){let t=this.process(n);if(n.events.size||n.states.length)n.id=n.xid;return`<${this.tag}${n.attr}>${t}${this.closing}`}}class Q{tag;constructor(n,t={},...r){this.tag=n;nn(this,{attr:new En(t),ctx:new jn(n,r)})}__(n=new c){let t=n.mid,r=new P(t,n);return this.attr.get(r),{ctx:this.ctx.get(r),oz:r.OZ.set(r),id:r.id}}}function Y(n,t={},...r){if($(n))return n(t??{},...r);return new Q(n,t??{},r)}var Dt=(n,...t)=>t;class qn{e;opt;constructor(n){this.e=n;this.opt={duration:500,easing:"ease-in-out",fill:"forwards"}}animate(n,t={}){return this.e.animate(n,t)}get slide(){let n=({x:t=0,y:r=0},i={})=>{y(this.opt,i);let o=[[t,r],[0,0]].map(([s,e])=>({transform:`translateX(${s}rem) translateY(${e}rem)`}));return this.e.animate(o,this.opt),this};return{left:(t={})=>{return n({x:-2},t)},right:(t={})=>{return n({x:2},t)},up:(t={})=>{return n({y:2},t)},down:(t={})=>{return n({y:-2},t)}}}fade(n={}){y(this.opt,n);let t=[0,1].map((r)=>({opacity:r}));return this.e.animate(t,this.opt),this}shake(n="Y",t={}){y(this.opt,t);let r=[0,5,-5,5,0].map((i)=>({transform:`translate${n}(${i}px)`}));return this.e.animate(r,this.opt),this}color(n=[],t={}){y(this.opt,t);let r=Array.isArray(n)?n.map((i)=>({color:i})):{color:n};return this.e.animate(r,this.opt),this}bg(n=[],t={}){y(this.opt,t);let r=Array.isArray(n)?n.map((i)=>({backgroundColor:i})):{backgroundColor:n};return this.e.animate(r,this.opt),this}bounce(n=1,t={}){y(this.opt,t);let r=[0.5,n,1].map((i)=>({transform:`scale(${i})`}));return this.e.animate(r),this}}class Zn{e;query;constructor(n,t){this.e=n;this.query=t}get a(){return new qn(this)}get all(){if(this.query){let n=document.querySelectorAll(this.query);if(n.length)return Array.from(n).map((t)=>t)}return[]}get attr(){let n=this.e;return{has:(t)=>{return n.hasAttribute(t)},get:(t)=>{return n.getAttribute(t)},del:(t)=>{return n.removeAttribute(t),this},set:(t)=>{for(let r in t){let i=t[r];if(t[r]!==void 0)n.setAttribute(r,i?i:"")}return this}}}get children(){return Array.from(this.e.children).map((n)=>T(n))}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 n=this.e.offsetParent;if(n)return new G(n);return}get parent(){let n=this.e.parentElement;if(n)return new G(n);return}get path(){return this.e?.pathname??""}get rect(){return this.e.getBoundingClientRect()}get remove_element(){return this.e.remove(),this}get style(){let n=this.e.style,t=this;return{set:(r,i=0)=>{let o=n,s=()=>{m(r).forEach(([e,f])=>{if(e in o){if(o[e]!==f)o[e]=f}else if(f!==null)n.setProperty(e,String(f))})};if($(i))t.on("transitionend",i);if(Gn(i))setTimeout(s,i);else s();return t},get:(r)=>{return n.getPropertyValue(r.toString())},del:(...r)=>{r.forEach((i)=>{n.removeProperty(i.toString())})}}}get submit(){let n=this.e;if("submit"in n)return n.submit();return!1}get tag(){return this.e.tagName.toLowerCase()}get value(){return this.e.value??""}get unload(){return()=>{this.e.remove()}}set append(n){let{ctx:t,oz:r}=Fn(n,Hn(this.id));this.e.insertAdjacentHTML("beforeend",t),X.RPS(r)}set appendfirst(n){let{ctx:t,oz:r}=Fn(n,Hn(this.id));this.e.insertAdjacentHTML("afterbegin",t),X.RPS(r)}set inner(n){let{ctx:t,oz:r}=Fn(n,Hn(this.id));this.e.innerHTML=t,X.RPS(r)}set disabled(n){let t=this.e;if("disabled"in t)t.disabled=n}set id(n){this.e.id=n}set value(n){let t=this.e;t.value=n}}var Fn=(n,t)=>{if(n instanceof Q)return n.__(new c(t));return{ctx:n,oz:void 0}},Hn=(n)=>n?`${n}-0`:n;class G extends Zn{constructor(n,t){super(n,t)}add(...n){return this.e.classList.add(...n.map((t)=>t.replace(/[^\w-]/,""))),this}remove(...n){return this.e.classList.remove(...n.map((t)=>t.replace(/[^\w-]/,""))),this}toggle(n,t){let r=typeof n!="string"?n.apply(this):n,i=this.e.classList;return r.split(" ").forEach((o)=>{i.toggle(o,t)}),this}has(n){return this.e.contains(n)}insert(n){return{HTML:(...t)=>{return t.forEach((r)=>{this.e.insertAdjacentHTML(n,r)}),this},element:(...t)=>{return t.forEach((r)=>{this.e.insertAdjacentElement(n,r)}),this},text:function(...t){return t.forEach((r)=>{this.e.insertAdjacentText(n,r)}),this}}}is(n){let t=this.e.classList.value.split(" "),r=this.e.tagName.toLocaleLowerCase(),i=!0,o=!0;if(n.dom)o=n.dom==r?!0:!1;if(n.class)if(Array.isArray(n.class))n.class.forEach((s)=>{i=i?t.includes(s):!1});else i=i?t.includes(n.class):!1;return i&&o}on(n,t,r=!1){let i=!1;if(n.indexOf("touch")>-1)i=!0;return this.e.addEventListener(n,t,{capture:r,passive:i}),this}remove_on(n,t,r=!1){return this.e.removeEventListener(n,t,r),this}timed(n,t=250){return setTimeout(()=>n(this),t),this}animate(n,t,r){let i={duration:300,easing:"ease",fill:"forwards"};if($(t))r=t;else y(i,t);let o=this.e.animate(n,i);if(r)o.finished.then(r);return this}}function T(n){if(v(n)){let t=document.querySelector(n);if(t)return new G(t,n);return}else return new G(n)}class gn extends bn{path;args;id;status;lang;import;_data={};constructor(n,t={},r,i=200){super();this.path=n;this.args=t;this.id=r;this.status=i}async loader(){if(this.import)try{let n=await this.import;if(n.default)this.import=await n.default({...this.args,...this.data});else this.import=void 0}catch(n){A.p=n,this.import=void 0}if(this.body){let n=await this.body();return l(n)?n:[n]}if(this.import){let n=this.import;return l(n)?n:[n]}return[]}getHeadAttr(n={},...t){let r=new I;if(q(n))r.head=n;r.id=this.id;let i=r.head;return t.forEach((o)=>{i.map(o)}),St(r,this),i}set data(n){y(this._data,n)}get data(){return this._data}}class Jn extends gn{head(){this.title=`error ${this.status}`}body(){return Y("div",{},this.path+" not found...")}}function St(n,t){let{link:r,script:i,meta:o,title:s,base:e,description:f,css:g}=t;if(n.head={title:s,base:e,meta:o,link:r,script:i},f)n.head={meta:[{name:"description",content:f}]};if(g){let p=(l(g)?g:[g]).map((H)=>({rel:`${b?"preload ":""}stylesheet`,href:H,as:"style"}));if(n.head.lacks("link"));n.head={link:[...p]}}}function st(n){let t=[];if(n?.length){let{href:r,target:i}=n[0],o=T("base");if(o)o.attr.set({href:r,target:i});else{let s=T(document.createElement("base"));s.attr.set({href:r,target:i}),document.head.append(s.e)}}else{let r=T("base")?.unload;r&&t.push(r)}return t}async function et(n){let t={};if(T("link")?.all.forEach((r)=>{let i=T(r),o=i.attr.get("href");if(o)t[o]=i.unload}),n&&q(n))for(let r of E(n)){let i=r.href;if(!(i in t))await xn(r);else delete t[i]}return E(t)}var Mt=["charset","name","property","http-equiv"];function ft(n){let t={};if(T("meta")?.all.forEach((r)=>{let i=r.attributes;for(let o of Mt)if(o in i){let s=i[o].value;t[`${o}_${o==="charset"?"":s}`]=r}}),n)m(n).forEach(([r,i])=>{if(r in t)T(t[r]).attr.set(i),delete t[r];else{let o=T(document.createElement("meta"));o.attr.set(i),document.head.append(o.e)}});return E(t).map((r)=>T(r).unload)}async function ut(n){let t={};if(T("script[yid]")?.all.forEach((r)=>{let i=T(r),o=i.attr.get("yid");if(o)t[o]=i.unload}),n){for(let r of n)if("yid"in r)if(r.yid in t)delete t[r.yid];else await Gt(r)}return E(t)}var Gt=(n)=>{return new Promise((t,r)=>{let i=T(document.createElement("script")),o="";if("importmap"in n)n.type="importmap",o=JSON.stringify(n.importmap),delete n.importmap;else if("body"in n)o=n.body,delete n.body;if(o)i.inner=o;i.attr.set(n),i.e.onload=()=>t(i.e),i.e.onerror=()=>r(new Error("Failed to load CSS")),document.head.appendChild(i.e)})};async function mt(n,t){let r=[];if(b)return[];let i=n.get("title")??"",{pushState:o}=this.config,s=this.path.value;if(o)Xn(s,i);return document.documentElement.lang=t,document.title=i,r.push(...st(n.get("base"))),r.push(...ft(n.get("meta"))),r.push(...await et(n.get("link"))),r.push(...await ut(n.get("script"))),r}function Xn(n,t){let r=window.location.pathname;if(n&&r!==n)history.pushState({},t??"",n)}class Qn{lang;head="";constructor(n,t){if(this.lang=n,t)this.head=Vn(t)}body(n,t){return[`<!DOCTYPE html><html lang="${this.lang}">`,`<head>${this.head}</head>`,`<body id="${t??x(5)}">${n}</body>`,"</html>"].join("")}}class Yn{path;args;isConnected=J(!1);data={};constructor(n,t={}){this.path=n;this.args=t}open(n){}message(n){}close(n){}error(n){}get connect(){if(this.ws&&this.ws.readyState<=1)return this;return this.ws=new WebSocket(this.path),this.ws.onopen=async(n)=>{this.isConnected.value=!0,await this.open.call(this,n)},this.ws.onmessage=async(n)=>{await this.message.call(this,n)},this.ws.onclose=async(n)=>{this.isConnected.value=!1,await this.close.call(this,n)},this.ws.onerror=async(n)=>{this.isConnected.value=this.ws.readyState<=1,await this.error.call(this,n)},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(n){this.ws.send(n)}}var z=new u;class Un{yra;constructor(n){this.yra=n}async load(n){if(!z.has(n)){let[r,i]=await this.yra.loadWSS(n);if(!r)return;let{cls:o,path:s,id:e}=r,f=new o(s,i).connect;return z.set(n,f),f}let t=z.get(n);return t.reconnect,t}unload(n){if(z.has(n)){let t=z.get(n);if(!t)return;t.disconnect,z.delete(n)}}}function At(n,t,r){let i={...n.on??{},click(o){o.preventDefault(),r.value=T(this).path}};return delete n.on,Y("a",{...n,on:{...i}},...t)}function Kt(n,t,r){let{classes:i}=n.config,o={...t.on??{},ready(){n.element.value=this,t.render&&n.render(t.render)},...r&&{popstate(g){let h=g.target;n.path.value=h.location.pathname}}},{render:s,on:e,...f}=t;return Y("div",{...f,...i&&{class:i},on:o},n.root)}class Bn extends fn{isYRA;hook;id=x(4);root=J([]);path=J("");socket;element=J(null);A;Main;load;constructor(n,t={},r=!1){super(n,t);this.isYRA=r;this.socket=new Un(this),this.A=(i,...o)=>{return At(i,o,this.path)},this.Main=(i)=>{return Kt(this,i,r)},this.load=async(i,o={})=>{if(this.hook)this.hook();if(i)this.path.value=i,await this.render(i,404,o),this.hooker();return this}}hooker(){let n={},t=this.path.value;if(this.hook)this.hook();this.hook=W(async(r)=>{if(n[t]=window.scrollY,(await this.render(r,404)).done)window.scrollTo({top:n[r]??0,behavior:"instant"}),t=r},[this.path],{id:"router"})}async class(n,t,r=!1){let[i,o]=await this.getPath(n);if(i&&!r){let{cls:s,path:e,id:f}=i;return new s(e,o,f)}else return It.call(this,n,t)}async render(n,t=404,r={}){let i=await this.class(n,t,!1);if(i.data=r,await this.fetch(i),i.head)await i.head();if(!i)return{done:!1};return this.root.value=await i.loader(),{done:!0}}async fetch(n){if(n)try{if(n.fetch){let t=await n.fetch();if(a(t)&&q(t))n.data=t}}catch(t){A.p=t}}}async function It(n,t){let[r,i]=await this.loadError(t??0);if(r){let{cls:o,id:s}=r;return new o(n,i,s,t)}else{let o=new Jn(n,i,x(5));return o.title=`error ${t}`,o}}class gt extends Bn{constructor(n,{classes:t,pushState:r=!0}={}){super(n,{classes:t,pushState:r},!0);this.head({meta:[{charset:"utf-8"},{name:"viewport",content:"width=device-width, initial-scale=1.0"}]}),this.load=async(i,o={})=>{if(this.hook)this.hook();if(i)this.path.value=i;if(Tn)this.render(i,404,o).then(()=>{if(i&&this.config.pushState)Xn(i,document.title);wt.call(this,this.Main({})),this.hooker()});return this}}async processHead(n,t={}){return n?await this.processClassHead(n,t):await this.processDefaultHead(t)}async processClassHead(n,t){if(n.head)await n.head();return n.getHeadAttr(t,this.htmlHead)}async processDefaultHead(n){let t=new I;if(q(n))t.head=n;return t.head.map(this.htmlHead),t.head}async render(n=location.pathname,t,r={},i={},o=!0,s=!1){if(b)this.path.value=n;let e=await this.class(n,t??Wt(),s);e.data=r,await this.fetch(e);let f=await this.processHead(e,i);if(!e)return{lang:this.lang,heads:f,done:!1};let g=[];if(o)g=await mt.call(this,f,e?.lang||this.lang);let h=await e.loader();if(h.length)this.root.value=h;else await this.render(n,t,r,i,o,!0);if(o)g.forEach((p)=>p());return{heads:f,lang:e.lang??this.lang,done:!0}}async html(n,t={},r){let i={script:[{type:"module",src:this.ImportMeta.file}]};Pt(i,r);let{lang:o,heads:s}=await this.render(n,r,t,i,!1),{ctx:e}=this.Main({}).__(new c(this.id));return new Qn(o,s).body(e,this.id)}}function wt(n){let t=document.body.id,{oz:r,id:i}=n.__(new c(t));if(this.id=i||this.id,!r)return;X.push(r),requestAnimationFrame(()=>{X.stage})}function Wt(){if(Tn)return parseInt(T('meta[name="error-code"]')?.attr.get("content")??"404");return 404}var Pt=(n,t)=>{switch(t){case 404:n.meta=[{name:"error-code",content:t.toString()}];return;default:return}};class Dn{state;body;click;constructor({toggle:n=[],initialState:t=!1}={}){this.state=J(t);let r=this.state;this.click=function(){r.value=!r.value},this.loader(n)}loader(n){if(typeof window==="undefined")return;let t=V.get("LOCAL_SCHEME"),r=this.isDark,i=t.as.bool,o=V.get({IS_DARK:()=>this.state.value});if(i!=null&&i!==r)this.state.value=!i,o.save,t.set=r;if(o.as.bool!==null)this.state.value=o.as.bool;let s=this.toggle,e=document.documentElement.classList;if(s(e,this.state.value,n),W(async(f)=>{s(e,f,n),o.save},[this.state],{id:"colorScheme"}),this.isMatchMediaSupported)window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",(f)=>{let h=(f.matches?"dark":"light")==="dark";this.state.value=h,t.set=h})}get isMatchMediaSupported(){return window.matchMedia&&typeof window.matchMedia==="function"}get isDark(){return window.matchMedia("(prefers-color-scheme: dark)").matches}toggle(n,t,r){if(t)n.add(...r);else n.remove(...r)}}Dn=Sn([Rn,Mn("design:paramtypes",[Object])],Dn);var Vs=(n,t)=>{return`${n.replace(/\/+$/,"")}/${t.replace(/^\.\/+/,"")}`};export{Yn as websocket,W as stateHook,nt as session,Vs as resolvePath,fn as minClient,V as local,Dt as frag,kn as eventStream,Y as dom,gn as doc,xn as cssLoader,qt as addCSS,_n as __,gt as Yvee,M as Stateful,J as State,Bn as Router,rn as Meta,Q as Dom,Dn as ColorScheme,A as $$,T as $};
|
|
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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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 $};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yvee",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Yvee JS framework",
|
|
5
5
|
"author": "Marky <markjotep@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,18 +25,10 @@
|
|
|
25
25
|
"url": "https://github.com/MARKjotep/yvee/issues"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/MARKjotep/yvee#readme",
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"dotenv": "^16.4.7",
|
|
30
|
-
"jsonwebtoken": "^9.0.2",
|
|
31
|
-
"pg": "^8.13.1",
|
|
32
|
-
"authored": "^0.0.2",
|
|
33
|
-
"rollup": "^4.31.0",
|
|
34
|
-
"rollup-plugin-dts": "^6.1.1"
|
|
35
|
-
},
|
|
28
|
+
"dependencies": {},
|
|
36
29
|
"devDependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"@types/bun": "^1.2.2"
|
|
30
|
+
"rollup": "^4.34.8",
|
|
31
|
+
"rollup-plugin-dts": "^6.1.1"
|
|
40
32
|
},
|
|
41
33
|
"peerDependencies": {
|
|
42
34
|
"typescript": "^5.7.3"
|