yvee 0.0.3 → 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/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;
@@ -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: yveeCfg, isYRA?: boolean);
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<{
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 Gn=(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)},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",Mn=(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 x{_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 Ct=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()},y=(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,{});c(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:K,entries:m}=Object;var{hasOwn:Wn,freeze:Pn,defineProperty:In,assign:c}=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 T=hn(e,f);if(q(T.added)||q(T.removed)||q(T.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 $(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}},xt=(n,t)=>{return{property:n,content:t}},yt=(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=yt(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=xt("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 ct=["charset","name","property","http-equiv"],dn=(n,t)=>{t.forEach((r)=>{for(let i of ct)if(i in r){let o=r[i];n[`${i}_${i==="charset"?"":o}`]=r}})},Et=(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 Et(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 x(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=$(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 xn{lang="en";htmlHead=new u;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)})},$t=()=>{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},pt=(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=$t();if(!r)return;if(!pt(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 T=f.match(/(?<=<)[^/].*?(?=>|$)/g);if(T?.length){let[h,E]=T[0].split(":");if(h&&E)s.push(h),e.push(E)}}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"],Zt=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}=Zt.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((E,Y)=>{let Z=Cn(t[Y],t.length-1===Y);if(E===Z[0])return Z[0];if(Ft.includes(Z[1]))return s.push(Z[0]),Z[1];return E}),T=j(f);if(this._storage.has(T)){i=this._storage.get(T),i?.args.forEach((E,Y)=>{r[E]=s[Y]});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=y;static reClass=On;static get O(){return{vals:$,keys:K,items:m,has:Wn,ass:c,len:(n={})=>K(n).length}}}var cn={},S={};class an{stream;url;constructor(n,t){if(this.url=n,n in cn)this.stream=cn[n];else this.stream=new EventSource(n,{withCredentials:t}),cn[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 xn{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,y(5),i)),i}},this.wss=(r)=>{return(i)=>{return this.wssStorage.set(new tt(r,y(5),i)),i}},this.error=(...r)=>{return(i)=>{if(r.length)r.forEach((o)=>{this.errorStorage.set(new en(o.toString(),y(5),i))});else this.errorStorage.set(new en("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 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 Ht=(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 G 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),Ht(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 H(n){return new G(n)}var En=(n)=>{if(l(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 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 $n{attr;constructor(n={}){this.attr=n}get(n,t=this.attr,r){let i=(o,s)=>{if(l(s))n.attr_push(o,En(s));else if(s instanceof G){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,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 P{xid;IDM;map=new u;states=[];events=new u;OZ;constructor(n,t=new x,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,T]=i.apply(r,[r]),h=l(f)?f:[f],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(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 J=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),mn=(n,t)=>{if(l(n))return n.map((r)=>mn(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 mn(n(),t);else if(n!==void 0&&n!==null)return String(n);return""},ot=(n,t)=>{let r=new x(n),i=new P(r.id,r);return{ctx:mn(t,i),catt:i}};function Ut(n){let t=this.id;if(t){let{ctx:r,catt:i}=ot(t,n);if(this.innerHTML!==r)this.innerHTML=r,J.RPS(i.OZ)}}var pn=(n,t,r,i=[])=>{if(l(n))n.forEach((o)=>{pn(o,n.length,r,i)});else if(n instanceof G)if(t>1)pn(Q("div",{},n),t,r,i);else{let o=n.value,s=o instanceof X?"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(Ut,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)=>{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;nn(this,{attr:new $n(t),ctx:new jn(n,r)})}__(n=new x){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 Q(n,t={},...r){if(p(n))return n(t??{},...r);return new X(n,t??{},r)}var Bt=(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={})=>{c(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={}){c(this.opt,n);let t=[0,1].map((r)=>({opacity:r}));return this.e.animate(t,this.opt),this}shake(n="Y",t={}){c(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={}){c(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={}){c(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={}){c(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)=>g(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 M(n);return}get parent(){let n=this.e.parentElement;if(n)return new M(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(p(i))t.on("transitionend",i);if(Mn(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 x(t));return{ctx:n,oz:void 0}},Zn=(n)=>n?`${n}-0`:n;class M 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 c(i,t);let o=this.e.animate(n,i);if(r)o.finished.then(r);return this}}function g(n){if(v(n)){let t=document.querySelector(n);if(t)return new M(t,n);return}else return new M(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;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=await this.import({...this.args,...this.data});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)}),Dt(r,this),i}set data(n){c(this._data,n)}get data(){return this._data}}class Jn extends gn{head(){this.title=`error ${this.status}`}body(){return Q("div",{},this.path+" not found...")}}function Dt(n,t){let{link:r,script:i,meta:o,title:s,base:e,description:f,css:T}=t;if(n.head={title:s,base:e,meta:o,link:r,script:i},f)n.head={meta:[{name:"description",content:f}]};if(T){let h=T.map((E)=>({rel:`${b?"preload ":""}stylesheet`,href:E,as:"style"}));n.head={link:[...h]}}}function st(n){let t=[];if(n?.length){let{href:r,target:i}=n[0],o=g("base");if(o)o.attr.set({href:r,target:i});else{let s=g(document.createElement("base"));s.attr.set({href:r,target:i}),document.head.append(s.e)}}else{let r=g("base")?.unload;r&&t.push(r)}return t}async function et(n){let t={};if(g("link")?.all.forEach((r)=>{let i=g(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 ft(n){let t={};if(g("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)g(t[r]).attr.set(i),delete t[r];else{let o=g(document.createElement("meta"));o.attr.set(i),document.head.append(o.e)}});return $(t).map((r)=>g(r).unload)}async function ut(n){let t={};if(g("script[yid]")?.all.forEach((r)=>{let i=g(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 $(t)}var Gt=(n)=>{return new Promise((t,r)=>{let i=g(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 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??y(5)}">${n}</body>`,"</html>"].join("")}}class Yn{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 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 Mt(n,t,r){let i={...n.on??{},click(o){o.preventDefault(),r.value=g(this).path}};return delete n.on,Q("a",{...n,on:{...i}},...t)}function At(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,...f}=t;return Q("div",{...f,...i&&{class:i},on:o},n.root)}class Bn 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 Un(this),this.A=(i,...o)=>{return Mt(i,o,this.path)},this.Main=(i)=>{return At(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:f}=i;return new s(e,o,f)}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(a(t)&&q(t))n.data=t}}catch(t){A.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{let o=new Jn(n,i,y(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(i)this.path.value=i;if(Tn)this.render(i,404,o).then(()=>{if(i&&this.config.pushState)Xn(i,document.title);It.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 T=[];if(o)T=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)T.forEach((E)=>E());return{heads:f,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 x(this.id));return new Qn(o,s).body(e,this.id)}}function It(n){let t=document.body.id,{oz:r,id:i}=n.__(new x(t));if(this.id=i||this.id,!r)return;J.push(r),requestAnimationFrame(()=>{J.stage})}function wt(){if(Tn)return parseInt(g('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 Dn{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=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,Gn("design:paramtypes",[Object])],Dn);var Ls=(n,t)=>{return`${n.replace(/\/+$/,"")}/${t.replace(/^\.\/+/,"")}`};export{Yn as websocket,W as stateHook,nt as session,Ls as resolvePath,fn as minClient,V as local,Bt as frag,kn as eventStream,Q as dom,gn as doc,yn as cssLoader,qt as addCSS,_n as __,gt as Yvee,G as Stateful,H as State,Bn as Router,rn as Meta,X as Dom,Dn as ColorScheme,A as $$,g 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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}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 $};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yvee",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Yvee JS framework",
5
5
  "author": "Marky <markjotep@gmail.com>",
6
6
  "license": "MIT",