yvee 0.0.2 → 0.0.4
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 +21 -0
- package/dist/index.d.ts +8 -9
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mark Joseph Yalung
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ declare class head implements headAttr {
|
|
|
133
133
|
meta?: meta<string>[] | Meta;
|
|
134
134
|
link?: link<string>[];
|
|
135
135
|
script?: script<string | boolean>[];
|
|
136
|
-
css?: string[];
|
|
136
|
+
css?: string[] | string;
|
|
137
137
|
}
|
|
138
138
|
type CSSinT$1 = {
|
|
139
139
|
[P in keyof CSSStyleDeclaration]?: V;
|
|
@@ -299,8 +299,8 @@ declare class doc<T = Record<string, string>> extends head {
|
|
|
299
299
|
_data: T;
|
|
300
300
|
constructor(path: string, args: T | undefined, id: string, status?: number);
|
|
301
301
|
fetch?(): Promise<Record<string, string>>;
|
|
302
|
-
head(): Promise<void> | void;
|
|
303
|
-
body(): Promise<Dom> | Dom;
|
|
302
|
+
head?(): Promise<void> | void;
|
|
303
|
+
body?(): Promise<Dom> | Dom;
|
|
304
304
|
loader(): Promise<any[]>;
|
|
305
305
|
getHeadAttr(head?: headAttr, ...toMap: headType[]): headType;
|
|
306
306
|
set data(data: obj<any>);
|
|
@@ -343,6 +343,7 @@ interface yveeCfg {
|
|
|
343
343
|
classes?: string | string[];
|
|
344
344
|
}
|
|
345
345
|
declare class Router extends minClient {
|
|
346
|
+
private isYRA;
|
|
346
347
|
hook?: () => void;
|
|
347
348
|
id: string;
|
|
348
349
|
root: Stateful<ctx[]>;
|
|
@@ -352,11 +353,9 @@ declare class Router extends minClient {
|
|
|
352
353
|
A: (a: attr & {
|
|
353
354
|
href: string;
|
|
354
355
|
}, ...D: ctx[]) => Dom;
|
|
355
|
-
Main: (a: attr
|
|
356
|
-
render?: string;
|
|
357
|
-
}) => Dom;
|
|
356
|
+
Main: (a: attr) => Dom;
|
|
358
357
|
load: (path?: string, data?: obj<string>) => Promise<this>;
|
|
359
|
-
constructor(ImportMeta: ImportMeta, config
|
|
358
|
+
constructor(ImportMeta: ImportMeta, config?: yveeCfg, isYRA?: boolean);
|
|
360
359
|
hooker(): void;
|
|
361
360
|
class(this: Router, _path: string, _error: number, isError?: boolean): Promise<doc<{}>>;
|
|
362
361
|
render(_path: string, _error?: number, data?: obj<string>): Promise<{
|
|
@@ -365,7 +364,7 @@ declare class Router extends minClient {
|
|
|
365
364
|
fetch(CL?: doc<{}>): Promise<void>;
|
|
366
365
|
}
|
|
367
366
|
declare class Yvee extends Router {
|
|
368
|
-
constructor(ImportMeta: ImportMeta, { classes, pushState }
|
|
367
|
+
constructor(ImportMeta: ImportMeta, { classes, pushState }?: yveeCfg);
|
|
369
368
|
processHead(CL?: doc<{}>, head?: headAttr): Promise<headType>;
|
|
370
369
|
private processClassHead;
|
|
371
370
|
private processDefaultHead;
|
|
@@ -757,4 +756,4 @@ declare global {
|
|
|
757
756
|
}
|
|
758
757
|
declare const resolvePath: (base: string, relative: string) => string;
|
|
759
758
|
|
|
760
|
-
export { $, $$, ColorScheme, Dom, Meta, Router, State, Stateful, Yvee, type _$, __, addCSS, cssLoader, type ctx, doc, dom, eventStream, frag, local, minClient, resolvePath, session, stateHook, websocket };
|
|
759
|
+
export { $, $$, ColorScheme, Dom, Meta, Router, State, Stateful, Yvee, type _$, __, addCSS, cssLoader, type ctx, doc, dom, eventStream, frag, type headAttr, local, minClient, 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 u=n.length-1;u>=0;u--)if(e=n[u])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 An=(n,t)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(n,t)};var p=(n)=>typeof n==="function";var U=(n)=>{return!isNaN(parseFloat(n))&&isFinite(n)},ln=(n)=>{return typeof n==="object"&&n!==null&&!Array.isArray(n)},k=(n)=>{return typeof n==="object"&&n!==null&&Object.getPrototypeOf(n)===Object.prototype};var v=(n)=>typeof n==="boolean",nn=(n)=>typeof n==="string",g=(n)=>Array.isArray(n),F=(n)=>typeof n==="object",Dn=(n)=>typeof n==="number",P=(n)=>n===null,Gn=(n)=>typeof n==="undefined",Kn=(n)=>{return Number.isInteger(Number(n))},Tn=typeof window!=="undefined",b=typeof window==="undefined";function tn(n,t){m(t).forEach(([r,i])=>{Mn(n,r,{value:i,writable:!1,configurable:!1,enumerable:!0})})}class K{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??y(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 Ot=new RegExp(/(\d+)(\d*)/,"m"),gt=(n)=>Array.from({length:n},(t,r)=>r),lt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Tt="abcdefghijklmnopqrstuvwxyz",ht=gt(10).join("");var j=(n)=>JSON.stringify(n),In=(n)=>{return JSON.parse(n)},B=(n)=>{if(n.startsWith("webkit"))n="-"+n;return n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},y=(n)=>{let t=lt+Tt;return Array.from({length:n},(r,i)=>t+(i?ht:"")).reduce((r,i)=>{return r+=i.charAt(Math.floor(Math.random()*i.length))},"")};class f extends Map{obj(n){n&&m(n).forEach(([t,r])=>this.set(t,r))}map(n){n.forEach((t,r)=>{if(t instanceof f)this.set(r,t);else if(g(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,{});x(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:$,keys:M,entries:m}=Object;var{hasOwn:wn,freeze:Wn,defineProperty:Mn,assign:x}=Object,q=(n)=>{return Object.keys(n).length},rn=(n,t)=>{if(!t.has(n))t.set(n,new f);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=M(n),o=M(t);for(let s of o){let e=n[s],u=t[s];if(!(s in n))r.added[s]=u;else if(g(e)&&g(u)){if(j(e)!==j(u))r.modified[s]={old:e,new:u}}else if(F(e)&&F(u)&&!P(e)&&!P(u)){let T=hn(e,u);if(q(T.added)||q(T.removed)||q(T.modified))r.modified[s]={old:e,new:u}}else if(e!==u)r.modified[s]={old:e,new:u}}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 $(n).some((t)=>{return q(t)})};function Pn(n){let t;return class extends n{constructor(...r){if(t)return t;super(...r);Wn(this),t=this}}}var S=(n,t)=>{return{name:n,content:t}},bt=(n,t)=>{return{property:n,content:t}},ct=(n,t)=>{return{"http-equiv":n,content:t}};class on{metas=[];constructor(n){n&&this.metas.push(S("description",n))}author(n){return this.meta=S("author",n),this}charset(n){return this.meta={charset:n},this}keywords(...n){return this.meta=S("keywords",n.join(", ")),this}viewport(n){let t=m(n).map(([r,i])=>[B(r),String(i)].join("="));return this.meta=S("viewport",t.join(", ")),this}httpEquiv(n){return m(n).forEach(([t,r])=>{this.meta=ct(B(t),String(r))}),this}robots(...n){return this.meta=S("robots",n.join(", ")),this}themeColor(n){return this.meta=S("theme-color",n),this}openGraph(n){return m(n).forEach(([t,r])=>{this.meta=bt("og:"+t,String(r))}),this}twitter(n){return m(n).forEach(([t,r])=>{this.meta=S("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"],Rn=(n,t)=>{t.forEach((r)=>{for(let i of yt)if(i in r){let o=r[i];n[`${i}_${i==="charset"?"":o}`]=r}})},xt=(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 f(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 on)return Rn(this._head.init("meta",{}),r.metas);if(!g(r))return;switch(t){case"meta":return Rn(this._head.init("meta",{}),r);case"link":return xt(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(v(i)&&i?r:`${r}="${i}"`),t},[""]).join(" ")},Vn=(n)=>{if(!n)return"";return[...n].reduce((t,[r,i])=>{if(r==="meta"||r==="link")i=$(i);if(nn(i))return t.push(`<${r}>${i}</${r}>`),t;if(!g(i))return t;let o=i.map((s)=>{if(r==="script"){let e={...s};if("yid"in e)return"";let u="";if("importmap"in e)e.type="importmap",u=JSON.stringify(e.importmap),delete e.importmap;else if("body"in e)u=e.body,delete e.body;return`<${r}${Ln(e)}>${u}</${r}>`}return`<${r}${Ln(s)}>`});return t.push(...o),t},[]).join("")};class cn{lang="en";htmlHead=new f;head;constructor(){this.head=(n={})=>{let t=new I(this.htmlHead);t.head=n,this.htmlHead=t.head}}}var yn=(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.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},pt=(n)=>Object.entries(n).map(([t,r])=>`${B(t)}: ${r};`).join(" ");function jt(n,t={}){if(b)return;let r=Et();if(!r)return;if(!$t(r,n))r.insertRule(`${n} { ${pt(t)} }`,r.cssRules.length)}var dn=(n,t)=>{let r=t;if(n?.class)r.push(...g(n.class)?n.class:[n.class]);return delete n.class,r.filter((i)=>i)};var On=(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"]},sn=(n)=>{let t=n.startsWith("/")?n:"/"+n,r=t.match(/(?<=\/)[^/].*?(?=\/|$)/g)??["/"],[i,o]=r.reduce(([s,e],u)=>{if(u.includes("<")){let T=u.match(/(?<=<)[^/].*?(?=>|$)/g);if(T?.length){let[h,E]=T[0].split(":");if(h&&E)s.push(h),e.push(E)}}else s.push(u===">"?"/":u);return[s,e]},[[],[]]);if(t.endsWith("/")&&t.length>1)i.push("/");return{parsed:i,args:o}};class en{storage=new f;cache(n,t){if(this.storage.lacks(n))this.storage.set(n,t());return this.storage.get(n)}}var qt=["int","float","file","uuid","string"],Ft=new en;class w{_storage=new f;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}=Ft.cache(n,()=>sn(n)),r={},i=this._storage.get(j(t));if(!i&&n!=="/")for(let o of this._storage.keys()){let s=[],e=In(o);if(t.length===e.length){let u=e.map((E,Y)=>{let Z=On(t[Y],t.length-1===Y);if(E===Z[0])return Z[0];if(qt.includes(Z[1]))return s.push(Z[0]),Z[1];return E}),T=j(u);if(this._storage.has(T)){i=this._storage.get(T),i?.args.forEach((E,Y)=>{r[E]=s[Y]});break}}}return[i,r]}}class L{path="";parsed=[];args=[];constructor(n){tn(this,{path:n,...sn(n)})}}class Cn{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=M(n),r=t.length,i=this.rand(0,r-1);return t[i]}}static makeID=y;static reClass=dn;static get O(){return{vals:$,keys:M,items:m,has:wn,ass:x,len:(n={})=>M(n).length}}}var xn={},A={};class _n{stream;url;constructor(n,t){if(this.url=n,n in xn)this.stream=xn[n];else this.stream=new EventSource(n,{withCredentials:t}),xn[n]=this.stream,A[this.url]={}}on(n){let t=this.stream;return m(n).forEach(([r,i])=>{if(r in A[this.url])A[this.url][r].forEach((o)=>{this.stream.removeEventListener(r,o)}),A[this.url][r]=[];if(t.addEventListener(r,i),!(r in A[this.url]))A[this.url][r]=[];A[this.url][r].push(i)}),this}}function an(n,t=!0){return new _n(n,t)}class kn{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 V{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 kn(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 d={get:(n)=>new V(n)};var vn={get:(n)=>new V(n,"session")};class un extends L{id;cls;constructor(n,t,r){super(n);this.id=t;this.cls=r}}class nt extends L{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 un(r,y(5),i)),i}},this.wss=(r)=>{return(i)=>{return this.wssStorage.set(new nt(r,y(5),i)),i}},this.error=(...r)=>{return(i)=>{if(r.length)r.forEach((o)=>{this.errorStorage.set(new un(o.toString(),y(5),i))});else this.errorStorage.set(new un("404",y(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 f,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 tt(){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((u)=>u.value),e=()=>{n(...s())};if(t.forEach((u)=>{o.push(u.hook(e)(r))}),i)e();return()=>{o.forEach((u)=>u())}}var rt=(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 D extends EventTarget{options;hooks=new f;states=new f;_value;listening=!1;end;constructor(n,t){super();this.options=t;this._value=n}get value(){return this._value}set value(n){if(P(n)||Gn(n))return;if(k(this._value)||g(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(rt(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(rn(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 H(n){return new D(n)}var En=(n)=>{if(g(n))return n.join(" ");else if(F(n)){if(ln(n))return j(n)}else if(p(n))return En(n());else if(n!==void 0&&n!==null)return v(n)?n?"":"false":String(n);return""};function Ht(n,t){switch(t??n){case"style":return function(r){this.style.setProperty(n,r)};default:return function(r){this.setAttribute(n,r)}}}class $n{attr;constructor(n={}){this.attr=n}get(n,t=this.attr,r){let i=(o,s)=>{if(g(s))n.attr_push(o,En(s));else if(s instanceof D){let e=r?`${r}_${o}`:o;n.states.push(s.call(Ht(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,En(s),r)};m(t).forEach(([o,s])=>{if(["on"].includes(o))F(t.on)&&n.events.obj(t.on);else i(o,s)})}}class z{xid;IDM;map=new f;states=[];events=new f;OZ;constructor(n,t=new c,r){this.xid=n;this.IDM=t;this.OZ=r??new mn}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 Jt=(n,t,r)=>{return n.addEventListener(t,r),()=>{n.removeEventListener(t,r)}},_={};class mn{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(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)=>{rn(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 f).set(t,i);break;case"watch":let[e,u,T]=i.apply(r,[r]),h=g(u)?u:[u],E=()=>h.map((Z)=>Z.value),Y=()=>e(...E());if(T)Y();h.forEach((Z)=>R(t,this.resetST).push(Z.call(Y,t+"_watch")(t)));break;default:R(t,this.resetEV).push(Jt(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 u=C(e);if(u)s.call(u,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=tt();this.reset(t);let r=n.keys;if(r.length)this.reset(r).push(n).stage}return this}}var J=new mn;var Xt=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],Qt=(n)=>Xt.includes(n),gn=(n,t)=>{if(g(n))return n.map((r)=>gn(r,t)).join("");else if(n instanceof X){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(p(n))return gn(n(),t);else if(n!==void 0&&n!==null)return String(n);return""},it=(n,t)=>{let r=new c(n),i=new z(r.id,r);return{ctx:gn(t,i),catt:i}};function Yt(n){let t=this.id;if(t){let{ctx:r,catt:i}=it(t,n);if(this.innerHTML!==r)this.innerHTML=r,J.RPS(i.OZ)}}var pn=(n,t,r,i=[])=>{if(g(n))n.forEach((o)=>{pn(o,n.length,r,i)});else if(n instanceof D)if(t>1)pn(Q("div",{},n),t,r,i);else{let o=n.value,s=o instanceof X?"dom":"ctx",{ctx:e,catt:u}=it(r.xid+"-0",o);r.xid=u.xid,i.push(e),r.OZ.push(u.OZ),r.states.push(n.call(Yt,s))}else i.push(gn(n,r))};class jn{tag;ctx;closing;constructor(n,t){this.tag=n;this.ctx=t;let r=Qt(n);this.closing=r?"":`</${n}>`}process(n,t=this.ctx,r=[]){return t.forEach((i)=>{pn(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 X{tag;constructor(n,t={},...r){this.tag=n;tn(this,{attr:new $n(t),ctx:new jn(n,r)})}__(n=new c){let t=n.mid,r=new z(t,n);return this.attr.get(r),{ctx:this.ctx.get(r),oz:r.OZ.set(r),id:r.id}}}function Q(n,t={},...r){if(p(n))return n(t??{},...r);return new X(n,t??{},r)}var Ut=(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={})=>{x(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={}){x(this.opt,n);let t=[0,1].map((r)=>({opacity:r}));return this.e.animate(t,this.opt),this}shake(n="Y",t={}){x(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={}){x(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={}){x(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={}){x(this.opt,t);let r=[0.5,n,1].map((i)=>({transform:`scale(${i})`}));return this.e.animate(r),this}}class Hn{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)=>l(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,u])=>{if(e in o){if(o[e]!==u)o[e]=u}else if(u!==null)n.setProperty(e,String(u))})};if(p(i))t.on("transitionend",i);if(Dn(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,Zn(this.id));this.e.insertAdjacentHTML("beforeend",t),J.RPS(r)}set appendfirst(n){let{ctx:t,oz:r}=Fn(n,Zn(this.id));this.e.insertAdjacentHTML("afterbegin",t),J.RPS(r)}set inner(n){let{ctx:t,oz:r}=Fn(n,Zn(this.id));this.e.innerHTML=t,J.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 X)return n.__(new c(t));return{ctx:n,oz:void 0}},Zn=(n)=>n?`${n}-0`:n;class G extends Hn{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(p(t))r=t;else x(i,t);let o=this.e.animate(n,i);if(r)o.finished.then(r);return this}}function l(n){if(nn(n)){let t=document.querySelector(n);if(t)return new G(t,n);return}else return new G(n)}class a 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}head(){this.title="error "+this.status}body(){return Q("div",{},this.path+" not found...")}async loader(){if(this.import)try{let n=await this.import;if(n.default){let t=await n.default({...this.args,...this.data});return g(t)?t:[t]}}catch(n){K.p=n;let t=await this.body();return g(t)?t:[t]}else{let n=await this.body();return g(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)}),Bt(r,this),i}set data(n){x(this._data,n)}get data(){return this._data}}function Bt(n,t){let{link:r,script:i,meta:o,title:s,base:e,description:u,css:T}=t;if(n.head={title:s,base:e,meta:o,link:r,script:i},u)n.head={meta:[{name:"description",content:u}]};if(T){let h=T.map((E)=>({rel:`${b?"preload ":""}stylesheet`,href:E,as:"style"}));n.head={link:[...h]}}}function ot(n){let t=[];if(n?.length){let{href:r,target:i}=n[0],o=l("base");if(o)o.attr.set({href:r,target:i});else{let s=l(document.createElement("base"));s.attr.set({href:r,target:i}),document.head.append(s.e)}}else{let r=l("base")?.unload;r&&t.push(r)}return t}async function st(n){let t={};if(l("link")?.all.forEach((r)=>{let i=l(r),o=i.attr.get("href");if(o)t[o]=i.unload}),n&&q(n))for(let r of $(n)){let i=r.href;if(!(i in t))await yn(r);else delete t[i]}return $(t)}var St=["charset","name","property","http-equiv"];function et(n){let t={};if(l("meta")?.all.forEach((r)=>{let i=r.attributes;for(let o of St)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)l(t[r]).attr.set(i),delete t[r];else{let o=l(document.createElement("meta"));o.attr.set(i),document.head.append(o.e)}});return $(t).map((r)=>l(r).unload)}async function ut(n){let t={};if(l("script[yid]")?.all.forEach((r)=>{let i=l(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 At(r)}return $(t)}var At=(n)=>{return new Promise((t,r)=>{let i=l(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.onerror=()=>r(new Error("Failed to load CSS")),document.head.appendChild(i.e)})};async function ft(n,t){let r=[];if(b)return[];let i=n.get("title")??"",{pushState:o}=this.config,s=this.path.value;if(o)Jn(s,i);return document.documentElement.lang=t,document.title=i,r.push(...ot(n.get("base"))),r.push(...et(n.get("meta"))),r.push(...await st(n.get("link"))),r.push(...await ut(n.get("script"))),r}function Jn(n,t){let r=window.location.pathname;if(n&&r!==n)history.pushState({},t??"",n)}class Xn{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??y(5)}">${n}</body>`,"</html>"].join("")}}class Qn{path;args;isConnected=H(!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 N=new f;class Yn{yra;constructor(n){this.yra=n}async load(n){if(!N.has(n)){let[r,i]=await this.yra.loadWSS(n);if(!r)return;let{cls:o,path:s,id:e}=r,u=new o(s,i).connect;return N.set(n,u),u}let t=N.get(n);return t.reconnect,t}unload(n){if(N.has(n)){let t=N.get(n);if(!t)return;t.disconnect,N.delete(n)}}}function Dt(n,t,r){let i={...n.on??{},click(o){o.preventDefault(),r.value=l(this).path}};return delete n.on,Q("a",{...n,on:{...i}},...t)}function Gt(n,t,r){let{classes:i}=n.config,o={...t.on??{},ready(){n.element.value=this,t.render&&n.render(t.render)},...r&&{popstate(T){let h=T.target;n.path.value=h.location.pathname}}},{render:s,on:e,...u}=t;return Q("div",{...u,...i&&{class:i},on:o},n.root)}class Un extends fn{hook;id=y(4);root=H([]);path=H("");socket;element=H(null);A;Main;load;constructor(n,t,r=!1){super(n,t);this.socket=new Yn(this),this.A=(i,...o)=>{return Dt(i,o,this.path)},this.Main=(i)=>{return Gt(this,i,r)},this.load=async(i,o={})=>{if(i)this.path.value=i,await this.render(i,404,o);return this.hooker(),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:u}=i;return new s(e,o,u)}else return Kt.call(this,n,t)}async render(n,t=404,r={}){let i=await this.class(n,t,!1);if(i.data=r,!i)return{done:!1};return await this.fetch(i),this.root.value=await i.loader(),{done:!0}}async fetch(n){if(n)try{if(n.fetch){let t=await n.fetch();if(k(t)&&q(t))n.data=t}}catch(t){K.p=t}}}async function Kt(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 return new a(n,i,y(5))}class mt extends Un{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(i)this.path.value=i;if(Tn)this.render(i,404,o).then(()=>{if(i&&this.config.pushState)Jn(i,document.title);Mt.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){return await n.head(),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??It(),s);e.data=r,await this.fetch(e);let u=await this.processHead(e,i);if(!e)return{lang:this.lang,heads:u,done:!1};let T=[];if(o)T=await ft.call(this,u,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)T.forEach((E)=>E());return{heads:u,lang:e.lang??this.lang,done:!0}}async html(n,t={},r){let i={script:[{type:"module",src:this.ImportMeta.file}]};wt(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 Xn(o,s).body(e,this.id)}}function Mt(n){let t=document.body.id,{oz:r,id:i}=n.__(new c(t));if(this.id=i||this.id,!r)return;J.push(r),requestAnimationFrame(()=>{J.stage})}function It(){if(Tn)return parseInt(l('meta[name="error-code"]')?.attr.get("content")??"404");return 404}var wt=(n,t)=>{switch(t){case 404:n.meta=[{name:"error-code",content:t.toString()}];return;default:return}};class Bn{state;body;click;constructor({toggle:n=[],initialState:t=!1}={}){this.state=H(t);let r=this.state;this.click=function(){r.value=!r.value},this.loader(n)}loader(n){if(typeof window==="undefined")return;let t=d.get("LOCAL_SCHEME"),r=this.isDark,i=t.as.bool,o=d.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(u)=>{s(e,u,n),o.save},[this.state],{id:"colorScheme"}),this.isMatchMediaSupported)window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",(u)=>{let h=(u.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)}}Bn=Sn([Pn,An("design:paramtypes",[Object])],Bn);var Os=(n,t)=>{return`${n.replace(/\/+$/,"")}/${t.replace(/^\.\/+/,"")}`};export{Qn as websocket,W as stateHook,vn as session,Os as resolvePath,fn as minClient,d as local,Ut as frag,an as eventStream,Q as dom,a as doc,yn as cssLoader,jt as addCSS,Cn as __,mt as Yvee,D as Stateful,H as State,Un as Router,on as Meta,X as Dom,Bn as ColorScheme,K as $$,l as $};
|
|
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 $};
|