@domphy/app 0.4.0 → 0.5.0
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/app.global.js +3 -3
- package/dist/app.global.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -2
- package/dist/index.d.ts +83 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}var se="data-domphy-head";function U(r){var e;if(typeof document!="undefined"){for(let t of Array.from(document.head.querySelectorAll(`[${se}]`)))t.remove();for(let t of r){if(t.tag==="title"){document.title=(e=t.content)!=null?e:"";continue}let n=document.createElement(t.tag);for(let o of Object.keys(t.attributes))n.setAttribute(o,t.attributes[o]);n.setAttribute(se,""),document.head.appendChild(n)}}}var L=require("@domphy/core");var Ve=3e4,O=class{constructor(){this.entries=new Map;this.inflight=new Map}seed(e){for(let t of Object.keys(e))this.entries.set(t,{data:e[t],timestamp:Date.now(),consumable:!0})}snapshot(e){let t={};for(let n of e){let o=this.entries.get(n);o&&(t[n]=o.data)}return t}invalidate(e){if(e===void 0){this.entries.clear();return}for(let t of this.entries.keys())t.startsWith(e)&&this.entries.delete(t)}load(e,t,n,o){return R(this,null,function*(){let i=this.entries.get(e);if(i){let l=o!==void 0?o*1e3:0,p=Date.now()-i.timestamp<=l,d=i.consumable&&Date.now()-i.timestamp<=3e4;if(p||d)return i.consumable&&!p&&this.entries.delete(e),i.data;this.entries.delete(e)}let s=this.inflight.get(e);if(s)return s;let a=Promise.resolve(t(n)).then(l=>(this.inflight.delete(e),o!==void 0&&o>0&&this.entries.set(e,{data:l,timestamp:Date.now(),consumable:!1}),l),l=>{throw this.inflight.delete(e),l});return this.inflight.set(e,a),a})}prefetch(e,t,n,o){return R(this,null,function*(){if(o!==void 0){yield this.load(e,t,n,o);return}let i=this.entries.get(e);if(i&&Date.now()-i.timestamp<=3e4||this.inflight.has(e))return;let s=yield t(n);this.entries.set(e,{data:s,timestamp:Date.now(),consumable:!0})})}};function q(){var t,n,o;let r=new Map,e=(n=(t=window.history.state)==null?void 0:t.__domphyIndex)!=null?n:0;return((o=window.history.state)==null?void 0:o.__domphyIndex)===void 0&&window.history.replaceState({__domphyIndex:e},""),"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),{url:()=>new URL(window.location.href),push:i=>{e++,window.history.pushState({__domphyIndex:e},"",i)},replace:i=>{window.history.replaceState({__domphyIndex:e},"",i)},go:i=>window.history.go(i),listen:i=>{let s=()=>{var a,l;e=(l=(a=window.history.state)==null?void 0:a.__domphyIndex)!=null?l:0,i(new URL(window.location.href))};return window.addEventListener("popstate",s),()=>window.removeEventListener("popstate",s)},saveScroll:i=>r.set(e,i),readScroll:()=>{var i;return(i=r.get(e))!=null?i:null}}}var ae="http://localhost";function Pe(r="/"){let e=[r],t=0,n=new Set;return{url:()=>new URL(e[t],ae),push:o=>{e.splice(t+1),e.push(o),t++},replace:o=>{e[t]=o},go:o=>{let i=Math.min(Math.max(t+o,0),e.length-1);if(i===t)return;t=i;let s=new URL(e[t],ae);for(let a of n)a(s)},listen:o=>(n.add(o),()=>n.delete(o))}}function Y(r){return{div:[{h2:"Application error"},{p:r.message}]}}function J(){return{div:[{h2:"404"},{p:"This page could not be found."}]}}function W(r,e){return r.findIndex(t=>t.status===e)}function F(r){var v;let{match:e,baseContext:t,results:n,retry:o,defaultError:i,defaultNotFound:s}=r,{chain:a,chainIds:l}=e.route,p={};for(let u=0;u<a.length;u++)p[l[u]]=(v=n[u])==null?void 0:v.data;let d=a.map((u,y)=>{var M;return b(x({},t),{data:(M=n[y])==null?void 0:M.data,segmentData:p})}),c=W(n,"error"),h=W(n,"notfound"),m=W(n,"pending"),f,g,w;if(c!==-1){let u=V(a,c,M=>!!M.error);f=(u===-1?i:a[u].error)(n[c].error,o),f._key=`${l[Math.max(u,0)]}:error`,g=Math.min(u,c-1),w="error"}else if(h!==-1){let u=V(a,h,M=>!!M.notFound);f=(u===-1?s:a[u].notFound)(),f._key=`${l[Math.max(u,0)]}:notfound`,g=Math.min(u,h-1),w="notfound"}else if(m!==-1){let u=V(a,m,y=>!!y.loading);if(u===-1)return{element:{div:""},status:"loading"};f=a[u].loading(d[u]),f._key=`${l[u]}:loading`,g=Math.min(u,m-1),w="loading"}else f=a[a.length-1].page(d[a.length-1]),f._key=`${e.route.id}:page`,g=a.length-1,w="idle";let E=f;for(let u=g;u>=0;u--){let y=a[u].layout;y&&(E=y(E,d[u]),E._key===void 0&&(E._key=`${l[u]}:layout`))}return{element:E,status:w}}function V(r,e,t){for(let n=e;n>=0;n--)if(t(r[n]))return n;return-1}function X(r){let e=r();return e._key===void 0&&(e._key="app:notfound"),{element:e,status:"notfound"}}var D=null;function Z(){if(!D)throw new Error("No router created yet. Call createApp() or new AppRouter() first.");return D}var P=class{constructor(e,t={}){this.events=new L.Notifier;this.cache=new O;this.navigationToken=0;this.releaseHistory=null;this.currentMatch=null;this.metadata={};this.lastRedirect=null;this.lastData={};var n,o,i;this.routes=H(e),this.middleware=(n=t.middleware)!=null?n:[],this.notFoundBlock=(o=t.notFound)!=null?o:J,this.errorBlock=(i=t.error)!=null?i:(s=>Y(s)),this.headers=t.headers,this.history=t.history!==void 0?t.history:typeof window!="undefined"?q():null,this.state=new L.RecordState({pathname:"/",search:"",hash:"",params:{},status:"idle",error:null}),this.tree=(0,L.toState)({div:""}),D=this}start(){return R(this,null,function*(){this.history&&!this.releaseHistory&&(this.releaseHistory=this.history.listen(t=>{this.transition(t,{fromHistory:!0})}));let e=this.history?this.history.url():new URL("/","http://localhost");yield this.transition(e,{initial:!0})})}destroy(){var e;(e=this.releaseHistory)==null||e.call(this),this.releaseHistory=null,D===this&&(D=null)}currentUrl(){if(this.history)return this.history.url();let e=this.state.get("search");return new URL(`${this.state.get("pathname")}${e}`,"http://localhost")}resolve(e){return new URL(e,this.currentUrl())}navigate(n){return R(this,arguments,function*(e,t={}){let o=this.resolve(e);if(typeof window!="undefined"&&o.origin!==this.currentUrl().origin){window.location.assign(o.href);return}yield this.transition(o,t)})}push(e,t={}){return this.navigate(e,t)}replace(e,t={}){return this.navigate(e,b(x({},t),{replace:!0}))}back(){var e;(e=this.history)==null||e.go(-1)}forward(){var e;(e=this.history)==null||e.go(1)}refresh(){return R(this,null,function*(){this.cache.invalidate(),yield this.transition(this.currentUrl(),{replace:!0,scroll:!1})})}prefetch(e){return R(this,null,function*(){try{let t=this.resolve(e),n=T(this.routes,t.pathname);if(!n)return;let o=this.loaderContext(t,n);yield Promise.all(n.route.chain.map((i,s)=>{if(!i.loader)return Promise.resolve();let a=this.cacheKey(n.route.chainIds[s],t);return this.cache.prefetch(a,i.loader,o,i.revalidate)}))}catch(t){}})}searchParams(e){return new URLSearchParams(this.state.get("search",e))}addEventListener(e,t){return this.events.addListener(e,t)}getMatch(){return this.currentMatch}cacheKey(e,t){return`${e}|${t.pathname}${t.search}`}loaderContext(e,t){return{pathname:t.pathname,url:e.pathname+e.search,params:t.params,searchParams:e.searchParams,headers:this.headers}}transition(n){return R(this,arguments,function*(e,t={}){var s,a;let o=++this.navigationToken,i=e.pathname+e.search+e.hash;t.fromHistory||(this.lastRedirect=null),this.events.notify("routeChangeStart",i),this.saveScroll();try{let l=e.pathname,p={url:e,pathname:e.pathname,searchParams:e.searchParams,headers:this.headers};for(let c of this.middleware){let h=yield c(p);_(h)&&(l=h.__domphyRewrite)}if(o!==this.navigationToken)return;let d=T(this.routes,l);if(d){let c=d.route.chain[d.route.chain.length-1];if(c.redirect)throw new k(c.redirect,(s=c.permanent)!=null?s:!1);for(let h of d.route.chain)for(let m of(a=h.middleware)!=null?a:[]){let f=yield m(p);if(_(f)){yield this.transition(new URL(f.__domphyRewrite,e),t);return}}if(o!==this.navigationToken)return;yield this.renderMatch(e,d,o,t)}else yield this.renderNotFound(e,o,t)}catch(l){if(o!==this.navigationToken)return;if(l instanceof k){yield this.transition(this.resolve(l.to),b(x({},t),{replace:!0})),this.lastRedirect={to:l.to,permanent:l.permanent};return}if(l instanceof S){yield this.renderNotFound(e,o,t);return}let p=l instanceof Error?l:new Error(String(l));this.tree.set(this.errorBlock(p,()=>{this.refresh()})),this.state.set("status","error"),this.state.set("error",p),this.events.notify("routeChangeError",p,i);return}o===this.navigationToken&&this.events.notify("routeChangeComplete",i)})}renderMatch(e,t,n,o){return R(this,null,function*(){let{chain:i,chainIds:s}=t.route,a=this.loaderContext(e,t),l=i.map(()=>({status:"pending"})),p=null,d=i.map((g,w)=>{if(!g.loader)return l[w]={status:"success",data:void 0},Promise.resolve();let E=this.cacheKey(s[w],e);return this.cache.load(E,g.loader,a,g.revalidate).then(v=>{l[w]={status:"success",data:v}},v=>{v instanceof k?p=p!=null?p:v:v instanceof S?l[w]={status:"notfound"}:l[w]={status:"error",error:v instanceof Error?v:new Error(String(v))}})}),c=!1,h=Promise.all(d).then(()=>{c=!0});if(yield new Promise(g=>setTimeout(g,0)),!c&&i.some(g=>g.loading)){let g=F({match:t,baseContext:this.baseContext(e,t),results:l.map(w=>x({},w)),retry:()=>{this.refresh()},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock});n===this.navigationToken&&g.status==="loading"&&(this.state.set("status","loading"),this.tree.set(g.element))}if(yield h,n!==this.navigationToken)return;if(p)throw p;let m=F({match:t,baseContext:this.baseContext(e,t),results:l,retry:()=>{this.refresh()},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock}),f={};i.forEach((g,w)=>{g.loader&&l[w].status==="success"&&(f[this.cacheKey(s[w],e)]=l[w].data)}),this.lastData=f,this.currentMatch=t,yield this.applyMetadata(t,a),n===this.navigationToken&&this.commit(e,t,m.element,m.status,o)})}renderNotFound(e,t,n){return R(this,null,function*(){let o=X(this.notFoundBlock);this.currentMatch=null,this.metadata={},U([]),t===this.navigationToken&&this.commit(e,null,o.element,"notfound",n)})}baseContext(e,t){return{pathname:t.pathname,url:e.pathname+e.search,params:t.params,searchParams:e.searchParams,hash:e.hash,headers:this.headers}}applyMetadata(e,t){return R(this,null,function*(){try{this.metadata=yield K(e.route.chain.map(n=>n.metadata),t)}catch(n){this.metadata={}}U(A(this.metadata))})}commit(e,t,n,o,i){var s;if(this.history&&!i.fromHistory&&!i.initial){let a=e.pathname+e.search+e.hash;i.replace?this.history.replace(a):this.history.push(a)}this.state.set("pathname",e.pathname),this.state.set("search",e.search),this.state.set("hash",e.hash),this.state.set("params",(s=t==null?void 0:t.params)!=null?s:{}),this.state.set("error",null),this.state.set("status",o),this.tree.set(n),this.restoreScroll(e,i)}saveScroll(){var e,t;typeof window!="undefined"&&((t=(e=this.history)==null?void 0:e.saveScroll)==null||t.call(e,{x:window.scrollX,y:window.scrollY}))}restoreScroll(e,t){var n,o,i,s;if(!(typeof window=="undefined"||t.scroll===!1||t.initial)){if(t.fromHistory){let a=(o=(n=this.history)==null?void 0:n.readScroll)==null?void 0:o.call(n);window.scrollTo((i=a==null?void 0:a.x)!=null?i:0,(s=a==null?void 0:a.y)!=null?s:0);return}if(e.hash){let a=document.getElementById(e.hash.slice(1));if(a){a.scrollIntoView();return}}window.scrollTo(0,0)}}};var le="__DOMPHY_APP_DATA__",$=class{constructor(e,t={}){this.node=null;this.routes=e,this.options=t,this.router=new P(e,t)}element(){let e=this.router;return{div:t=>[e.tree.get(t)],style:{display:"contents"}}}render(e){return R(this,null,function*(){return yield this.router.start(),this.node=new j.ElementNode(this.element()),this.node.render(e),this.node})}hydrate(e,t){return R(this,null,function*(){let n=globalThis[le];return n&&typeof n=="object"&&this.router.cache.seed(n),yield this.router.start(),this.node=new j.ElementNode(this.element()),this.node.mount(e,t),this.node})}destroy(){var e;(e=this.node)==null||e.remove(),this.node=null,this.router.destroy()}renderToString(n){return R(this,arguments,function*(e,t={}){let o=typeof e=="string"?new URL(e,"http://localhost"):e,i=new P(this.routes,b(x({},this.options),{history:null,headers:t.headers}));yield i.transition(o,{initial:!0});let s=i.state.get("status"),a=i.lastRedirect,l=new j.ElementNode({div:[i.tree.get()],style:{display:"contents"}}),p=i.lastData,d={html:l.generateHTML(),css:l.generateCSS(),head:z(A(i.metadata)),status:a?a.permanent?308:307:s==="notfound"?404:200,redirect:a==null?void 0:a.to,data:p,bootstrapScript:`<script>window.${le} = ${Le(p)};</script>`};return i.destroy(),d})}};function Le(r){return JSON.stringify(r).replace(/</g,"\\u003c")}function He(r,e={}){return new $(r,e)}var Ie=[640,750,828,1080,1200,1920,2048,3840];function Ce(r){let{src:e,alt:t="",width:n,height:o,fill:i=!1,sizes:s,quality:a=75,priority:l=!1,placeholder:p="empty",blurDataURL:d,loader:c,deviceSizes:h=Ie}=r,m={src:c?c({src:e,width:n!=null?n:h[h.length-1],quality:a}):e,alt:t,loading:l?"eager":"lazy",decoding:"async",fetchPriority:l?"high":"auto",style:{}};return c&&(m.srcSet=h.map(f=>`${c({src:e,width:f,quality:a})} ${f}w`).join(", "),s&&(m.sizes=s)),n!==void 0&&(m.width=n),o!==void 0&&(m.height=o),i&&(m.style=b(x({},m.style),{position:"absolute",inset:"0",width:"100%",height:"100%",objectFit:"cover"})),p==="blur"&&d&&(m.style=b(x({},m.style),{backgroundImage:`url("${d}")`,backgroundSize:"cover",backgroundPosition:"center"}),m.onLoad=f=>{let g=f.target;g.style.backgroundImage=""}),m}function Ae(r){return r.defaultPrevented||r.button!==0||r.metaKey||r.ctrlKey||r.shiftKey||r.altKey}function Oe(r){let{href:e,replace:t=!1,scroll:n=!0,prefetch:o="hover",exact:i=!1}=r,s=()=>{var d;return(d=r.router)!=null?d:Z()},a=d=>{let c=new URL(e,"http://localhost").pathname;return i||c==="/"?d===c:d===c||d.startsWith(`${c}/`)},l=!1,p=()=>{l||(l=!0,s().prefetch(e))};return{href:e,ariaCurrent:d=>a(s().state.get("pathname",d))?"page":null,dataActive:d=>a(s().state.get("pathname",d))?"":null,onClick:d=>{let c=d,h=c.currentTarget;Ae(c)||h.target&&h.target!=="_self"||h.hasAttribute("download")||new URL(h.href,window.location.href).origin===window.location.origin&&(c.preventDefault(),s().navigate(e,{replace:t,scroll:n}))},onMouseEnter:()=>{o==="hover"&&p()},onFocus:()=>{o==="hover"&&p()},_onMount:d=>{if(o!=="visible")return;if(typeof IntersectionObserver=="undefined"){p();return}let c=new IntersectionObserver(h=>{h.some(m=>m.isIntersecting)&&(p(),c.disconnect())});c.observe(d.domElement),d.setMetadata("navLinkObserver",c)},_onRemove:d=>{let c=d.getMetadata("navLinkObserver");c==null||c.disconnect()}}}var Q=new Set;function De(){Q.clear()}function ce(r){let e=globalThis.requestIdleCallback;e?e(r):setTimeout(r,0)}function Ne(r){let{src:e,strategy:t="afterInteractive",id:n,async:o=!0,onLoad:i,onError:s}=r,a=n!=null?n:e,l=d=>{Q.has(a)||(Q.add(a),d.src=e)},p={script:"",async:o,onLoad:()=>i==null?void 0:i(),onError:()=>s==null?void 0:s(),_onMount:d=>{let c=d.domElement;if(t==="afterInteractive"){l(c);return}document.readyState==="complete"?ce(()=>l(c)):window.addEventListener("load",()=>ce(()=>l(c)),{once:!0})}};return n!==void 0&&(p.id=n),p}function Be(r){return r}0&&(module.exports={AppRouter,DataCache,DomphyApp,NotFoundSignal,PREFETCH_LIFETIME,RedirectSignal,applyHeadTags,buildHref,buildNotFoundTree,buildTree,compareSpecificity,compileRoutes,createApiHandler,createApp,createBrowserHistory,createMemoryHistory,defaultErrorBlock,defaultNotFoundBlock,defineRoutes,getRouter,isRewrite,json,matchPath,matchRoute,metadataToHeadTags,navLink,notFound,optimizedImage,parseSegment,permanentRedirect,redirect,renderHeadTags,resetScripts,resolveMetadata,rewrite,script,splitPath});
|
|
1
|
+
"use strict";var K=Object.defineProperty,yt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyDescriptors,vt=Object.getOwnPropertyNames,st=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,xt=Object.prototype.propertyIsEnumerable;var at=(r,t,e)=>t in r?K(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,S=(r,t)=>{for(var e in t||(t={}))lt.call(t,e)&&at(r,e,t[e]);if(st)for(var e of st(t))xt.call(t,e)&&at(r,e,t[e]);return r},k=(r,t)=>yt(r,wt(t));var bt=(r,t)=>{for(var e in t)K(r,e,{get:t[e],enumerable:!0})},St=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of vt(t))!lt.call(r,n)&&n!==e&&K(r,n,{get:()=>t[n],enumerable:!(o=Rt(t,n))||o.enumerable});return r};var kt=r=>St(K({},"__esModule",{value:!0}),r);var y=(r,t,e)=>new Promise((o,n)=>{var i=l=>{try{a(e.next(l))}catch(u){n(u)}},s=l=>{try{a(e.throw(l))}catch(u){n(u)}},a=l=>l.done?o(l.value):Promise.resolve(l.value).then(i,s);a((e=e.apply(r,t)).next())});var qt={};bt(qt,{AppRouter:()=>I,DataCache:()=>$,DomphyApp:()=>V,NotFoundSignal:()=>P,PREFETCH_LIFETIME:()=>X,RedirectSignal:()=>M,applyHeadTags:()=>z,buildHref:()=>Et,buildNotFoundTree:()=>W,buildTree:()=>H,compareSpecificity:()=>dt,compileRoutes:()=>C,createApiHandler:()=>Ht,createApp:()=>Nt,createBrowserHistory:()=>Z,createMemoryHistory:()=>Ot,defaultErrorBlock:()=>et,defaultNotFoundBlock:()=>rt,defineRoutes:()=>Gt,getRouter:()=>nt,isRewrite:()=>N,json:()=>U,matchPath:()=>ut,matchRoute:()=>L,matchRouteSuffix:()=>J,metadataToHeadTags:()=>A,navLink:()=>$t,notFound:()=>Tt,optimizedImage:()=>_t,parseSegment:()=>G,permanentRedirect:()=>Pt,redirect:()=>Mt,renderHeadTags:()=>F,resetScripts:()=>jt,resolveMetadata:()=>q,rewrite:()=>Lt,script:()=>Kt,splitPath:()=>D,urlPartCount:()=>Y});module.exports=kt(qt);function G(r){return r.startsWith("(")&&r.endsWith(")")?{kind:"group",value:r.slice(1,-1)}:r.startsWith("[[...")&&r.endsWith("]]")?{kind:"optional-catchall",value:r.slice(5,-2)}:r.startsWith("[...")&&r.endsWith("]")?{kind:"catchall",value:r.slice(4,-1)}:r.startsWith("[")&&r.endsWith("]")?{kind:"dynamic",value:r.slice(1,-1)}:{kind:"static",value:r}}function D(r){return r.split("/").filter(t=>t.length>0)}function Y(r){return D(r).map(G).filter(t=>t.kind!=="group").length}function J(r,t,e){let o=`/${D(t).slice(e).join("/")}`;return L(r,o)}function C(r){let t=[];function e(o,n,i,s,a){for(let l of o){let u=D(l.path),c=u.map(G),d=[...n,...c.filter(w=>w.kind!=="group")],h=`${a}/${u.join("/")}`.replace(/\/+/g,"/"),m=[...i,l],f=[...s,h===""?"/":h];(l.page||l.redirect)&&t.push({id:h===""?"/":h,segments:d,chain:m,chainIds:f}),l.children&&e(l.children,d,m,f,h)}}return e(r,[],[],[],""),t.sort(dt),t}var ct={static:0,dynamic:1,catchall:2,"optional-catchall":3,group:0};function dt(r,t){let e=Math.max(r.segments.length,t.segments.length);for(let o=0;o<e;o++){let n=r.segments[o],i=t.segments[o];if(!n)return-1;if(!i)return 1;let s=ct[n.kind]-ct[i.kind];if(s!==0)return s}return 0}function ut(r,t){let e=D(t).map(i=>decodeURIComponent(i)),o={},n=0;for(let i=0;i<r.length;i++){let s=r[i],a=i===r.length-1;if(s.kind==="static"){if(e[n]!==s.value)return null;n++;continue}if(s.kind==="dynamic"){if(n>=e.length)return null;o[s.value]=e[n],n++;continue}if(s.kind==="catchall")return!a||n>=e.length?null:(o[s.value]=e.slice(n),o);if(s.kind==="optional-catchall")return a?(o[s.value]=e.slice(n),o):null}return n!==e.length?null:o}function L(r,t){for(let e of r){let o=ut(e.segments,t);if(o)return{route:e,params:o,pathname:t}}return null}function Et(r,t={}){return`/${D(r).map(G).filter(o=>o.kind!=="group").flatMap(o=>{if(o.kind==="static")return[o.value];let n=t[o.value];if(n===void 0){if(o.kind==="optional-catchall")return[];throw new Error(`Missing param "${o.value}" for pattern "${r}".`)}return(Array.isArray(n)?n:[n]).map(s=>encodeURIComponent(s))}).join("/")}`}var M=class extends Error{constructor(t,e){super(`Redirect to ${t}`),this.name="RedirectSignal",this.to=t,this.permanent=e}},P=class extends Error{constructor(){super("Not found"),this.name="NotFoundSignal"}};function Mt(r){throw new M(r,!1)}function Pt(r){throw new M(r,!0)}function Tt(){throw new P}function Lt(r){return{__domphyRewrite:r}}function N(r){return typeof r=="object"&&r!==null&&typeof r.__domphyRewrite=="string"}var Ct=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"];function U(r,t={}){let e=new Headers(t.headers);return e.has("content-type")||e.set("content-type","application/json; charset=utf-8"),new Response(JSON.stringify(r),k(S({},t),{headers:e}))}function Ht(r){let t=r.map(n=>({apiRoute:n,routeNode:{path:n.path,page:()=>({div:""})}})),e=C(t.map(n=>n.routeNode)),o=new Map(t.map(n=>[n.routeNode,n.apiRoute]));return n=>y(null,null,function*(){let i=new URL(n.url),s=L(e,i.pathname);if(!s)return U({error:"Not Found"},{status:404});let a=o.get(s.route.chain[s.route.chain.length-1]),l=Ct.filter(d=>a[d]),u=n.method.toUpperCase(),c=a[u];if(!c&&u==="HEAD"&&a.GET&&(c=a.GET),!c&&u==="OPTIONS")return new Response(null,{status:204,headers:{allow:l.join(", ")}});if(!c)return U({error:"Method Not Allowed"},{status:405,headers:{allow:l.join(", ")}});try{let d=yield c(n,{params:s.params});return u==="HEAD"?new Response(null,{status:d.status,headers:d.headers}):d}catch(d){return d instanceof M?new Response(null,{status:d.permanent?308:307,headers:{location:d.to}}):d instanceof P?U({error:"Not Found"},{status:404}):U({error:"Internal Server Error"},{status:500})}})}var B=require("@domphy/core");function q(r,t){return y(this,null,function*(){let e={},o=null;for(let n of r){if(!n)continue;let i=typeof n=="function"?yield n(t):n;for(let a of Object.keys(i)){if(a==="title")continue;let l=i[a];l!==void 0&&(e[a]=l)}let s=i.title;if(s!==void 0){if(typeof s=="string"){e.title=o?o.replace("%s",s):s;continue}s.absolute!==void 0?e.title=s.absolute:s.default!==void 0&&(e.title=o?o.replace("%s",s.default):s.default),s.template!==void 0&&(o=s.template)}}return e})}function _(r,t){return!t||/^[a-z][a-z0-9+.-]*:/i.test(r)?r:new URL(r,t).toString()}function It(r){if(typeof r=="string")return r;let t=[];return t.push(r.index===!1?"noindex":"index"),t.push(r.follow===!1?"nofollow":"follow"),r.noarchive&&t.push("noarchive"),r.nosnippet&&t.push("nosnippet"),r.noimageindex&&t.push("noimageindex"),t.join(", ")}function A(r){var l,u,c,d,h,m,f,w,v,b,x;let t=[],e=r.metadataBase,o=(p,R)=>{R!==void 0&&t.push({tag:"meta",attributes:{name:p,content:R}})},n=(p,R)=>{R!==void 0&&t.push({tag:"meta",attributes:{property:p,content:R}})};r.title!==void 0&&t.push({tag:"title",attributes:{},content:r.title}),o("description",r.description),o("application-name",r.applicationName),o("generator",r.generator),o("keywords",(l=r.keywords)==null?void 0:l.join(", ")),o("referrer",r.referrer),o("theme-color",r.themeColor),o("color-scheme",r.colorScheme),o("viewport",r.viewport),r.robots!==void 0&&o("robots",It(r.robots));for(let p of(u=r.authors)!=null?u:[])o("author",p.name),p.url&&t.push({tag:"link",attributes:{rel:"author",href:p.url}});if(r.icons!==void 0){let p=typeof r.icons=="string"?{icon:r.icons}:r.icons;p.icon&&t.push({tag:"link",attributes:{rel:"icon",href:p.icon}}),p.shortcut&&t.push({tag:"link",attributes:{rel:"shortcut icon",href:p.shortcut}}),p.apple&&t.push({tag:"link",attributes:{rel:"apple-touch-icon",href:p.apple}})}let i=r.openGraph;if(i){n("og:title",(c=i.title)!=null?c:r.title),n("og:description",(d=i.description)!=null?d:r.description),n("og:url",i.url?_(i.url,e):void 0),n("og:site_name",i.siteName),n("og:type",i.type),n("og:locale",i.locale);for(let p of(h=i.images)!=null?h:[]){let R=typeof p=="string"?{url:p}:p;n("og:image",_(R.url,e)),R.width!==void 0&&n("og:image:width",String(R.width)),R.height!==void 0&&n("og:image:height",String(R.height)),R.alt!==void 0&&n("og:image:alt",R.alt)}}let s=r.twitter;if(s){o("twitter:card",(m=s.card)!=null?m:"summary"),o("twitter:title",(f=s.title)!=null?f:r.title),o("twitter:description",(w=s.description)!=null?w:r.description),o("twitter:site",s.site),o("twitter:creator",s.creator);for(let p of(v=s.images)!=null?v:[])o("twitter:image",_(p,e))}let a=r.alternates;if(a){a.canonical&&t.push({tag:"link",attributes:{rel:"canonical",href:_(a.canonical,e)}});for(let p of Object.keys((b=a.languages)!=null?b:{}))t.push({tag:"link",attributes:{rel:"alternate",hreflang:p,href:_(a.languages[p],e)}})}for(let p of Object.keys((x=r.other)!=null?x:{}))o(p,r.other[p]);return t}function Dt(r){return r.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<")}function At(r){return r.replace(/&/g,"&").replace(/</g,"<")}function F(r){return r.map(t=>{var o;let e=Object.keys(t.attributes).map(n=>` ${n}="${Dt(t.attributes[n])}"`).join("");return t.tag==="title"?`<title>${At((o=t.content)!=null?o:"")}</title>`:`<${t.tag}${e}>`}).join(`
|
|
2
|
+
`)}var ht="data-domphy-head";function z(r){var t;if(typeof document!="undefined"){for(let e of Array.from(document.head.querySelectorAll(`[${ht}]`)))e.remove();for(let e of r){if(e.tag==="title"){document.title=(t=e.content)!=null?t:"";continue}let o=document.createElement(e.tag);for(let n of Object.keys(e.attributes))o.setAttribute(n,e.attributes[n]);o.setAttribute(ht,""),document.head.appendChild(o)}}}var O=require("@domphy/core");var pt=require("@domphy/core");var X=3e4,$=class{constructor(){this.entries=new Map;this.inflight=new Map;this.notifier=new pt.Notifier;this.pending=new Map}onRevalidated(t){return this.notifier.addListener("revalidated",t)}seed(t){for(let e of Object.keys(t))this.entries.set(e,{data:t[e],timestamp:Date.now(),consumable:!0})}snapshot(t){let e={};for(let o of t){let n=this.entries.get(o);n&&(e[o]=n.data)}return e}invalidate(t){if(t===void 0){this.entries.clear();return}for(let e of this.entries.keys())e.startsWith(t)&&this.entries.delete(e)}load(t,e,o,n){return y(this,null,function*(){let i=this.entries.get(t);if(i){let l=n!==void 0?n*1e3:0,u=Date.now()-i.timestamp<=l,c=i.consumable&&Date.now()-i.timestamp<=X;if(u||c)return i.consumable&&!u&&this.entries.delete(t),i.data;if(n!==void 0&&n>0)return this.pending.set(t,()=>this.revalidate(t,e,o)),i.data;this.entries.delete(t)}let s=this.inflight.get(t);if(s)return s;let a=Promise.resolve(e(o)).then(l=>(this.inflight.delete(t),n!==void 0&&n>0&&this.entries.set(t,{data:l,timestamp:Date.now(),consumable:!1}),l),l=>{throw this.inflight.delete(t),l});return this.inflight.set(t,a),a})}flushRevalidations(){if(this.pending.size===0)return;let t=[...this.pending.values()];this.pending.clear();for(let e of t)e()}revalidate(t,e,o){if(this.inflight.has(t))return;let n=Promise.resolve(e(o)).then(i=>(this.inflight.delete(t),this.entries.set(t,{data:i,timestamp:Date.now(),consumable:!1}),this.notifier.notify("revalidated",t),i),i=>{throw this.inflight.delete(t),i});n.catch(()=>{}),this.inflight.set(t,n)}prefetch(t,e,o,n){return y(this,null,function*(){if(n!==void 0){yield this.load(t,e,o,n);return}let i=this.entries.get(t);if(i&&Date.now()-i.timestamp<=X||this.inflight.has(t))return;let s=yield e(o);this.entries.set(t,{data:s,timestamp:Date.now(),consumable:!0})})}};function Z(){var e,o,n;let r=new Map,t=(o=(e=window.history.state)==null?void 0:e.__domphyIndex)!=null?o:0;return((n=window.history.state)==null?void 0:n.__domphyIndex)===void 0&&window.history.replaceState({__domphyIndex:t},""),"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),{url:()=>new URL(window.location.href),push:i=>{t++,window.history.pushState({__domphyIndex:t},"",i)},replace:i=>{window.history.replaceState({__domphyIndex:t},"",i)},go:i=>window.history.go(i),listen:i=>{let s=()=>{var a,l;t=(l=(a=window.history.state)==null?void 0:a.__domphyIndex)!=null?l:0,i(new URL(window.location.href))};return window.addEventListener("popstate",s),()=>window.removeEventListener("popstate",s)},saveScroll:i=>r.set(t,i),readScroll:()=>{var i;return(i=r.get(t))!=null?i:null}}}var mt="http://localhost";function Ot(r="/"){let t=[r],e=0,o=new Set;return{url:()=>new URL(t[e],mt),push:n=>{t.splice(e+1),t.push(n),e++},replace:n=>{t[e]=n},go:n=>{let i=Math.min(Math.max(e+n,0),t.length-1);if(i===e)return;e=i;let s=new URL(t[e],mt);for(let a of o)a(s)},listen:n=>(o.add(n),()=>o.delete(n))}}function et(r){return{div:[{h2:"Application error"},{p:r.message}]}}function rt(){return{div:[{h2:"404"},{p:"This page could not be found."}]}}function Q(r,t){return r.findIndex(e=>e.status===t)}function H(r){var x,p,R;let{match:t,baseContext:e,results:o,retry:n,defaultError:i,defaultNotFound:s}=r,{chain:a,chainIds:l}=t.route,u={};for(let g=0;g<a.length;g++)u[l[g]]=(x=o[g])==null?void 0:x.data;let c=a.map((g,E)=>{var T;return k(S({},e),{data:(T=o[E])==null?void 0:T.data,segmentData:u})}),d=Q(o,"error"),h=Q(o,"notfound"),m=Q(o,"pending"),f,w,v;if(d!==-1){let g=tt(a,d,T=>!!T.error);f=(g===-1?i:a[g].error)(o[d].error,n),f._key=`${l[Math.max(g,0)]}:error`,w=Math.min(g,d-1),v="error"}else if(h!==-1){let g=tt(a,h,T=>!!T.notFound);f=(g===-1?s:a[g].notFound)(),f._key=`${l[Math.max(g,0)]}:notfound`,w=Math.min(g,h-1),v="notfound"}else if(m!==-1){let g=tt(a,m,E=>!!E.loading);if(g===-1)return{element:{div:""},status:"loading"};f=a[g].loading(c[g]),f._key=`${l[g]}:loading`,w=Math.min(g,m-1),v="loading"}else f=a[a.length-1].page(c[a.length-1]),f._key=`${t.route.id}:page`,w=a.length-1,v="idle";let b=f;for(let g=w;g>=0;g--){let E=a[g].layout;E&&(b=E(b,c[g],(R=(p=r.slots)==null?void 0:p[g])!=null?R:{}),b._key===void 0&&(b._key=`${l[g]}:layout`))}return{element:b,status:v}}function tt(r,t,e){for(let o=t;o>=0;o--)if(e(r[o]))return o;return-1}function W(r){let t=r();return t._key===void 0&&(t._key="app:notfound"),{element:t,status:"notfound"}}var j=null;function nt(){if(!j)throw new Error("No router created yet. Call createApp() or new AppRouter() first.");return j}var I=class{constructor(t,e={}){this.events=new O.Notifier;this.cache=new $;this.navigationToken=0;this.releaseHistory=null;this.currentMatch=null;this.currentRenderKeys=new Set;this.slotCompiled=new Map;this.metadata={};this.lastRedirect=null;this.lastData={};var o,n,i;this.routes=C(t),this.compileSlots(t),this.middleware=(o=e.middleware)!=null?o:[],this.notFoundBlock=(n=e.notFound)!=null?n:rt,this.errorBlock=(i=e.error)!=null?i:(s=>et(s)),this.headers=e.headers,this.history=e.history!==void 0?e.history:typeof window!="undefined"?Z():null,this.state=new O.RecordState({pathname:"/",search:"",hash:"",params:{},status:"idle",error:null}),this.tree=(0,O.toState)({div:""}),this.cache.onRevalidated(s=>this.onRevalidated(s)),j=this}compileSlots(t){for(let e of t){if(e.slots){let o={};for(let n of Object.keys(e.slots)){let i=e.slots[n];o[n]={soft:C(i),hard:C(i.filter(s=>!s.intercept))},this.compileSlots(i)}this.slotCompiled.set(e,o)}e.children&&this.compileSlots(e.children)}}loadMatch(t,e){return y(this,null,function*(){let{chain:o,chainIds:n}=t.route,i=this.loaderContext(e,t),s=o.map(()=>({status:"pending"}));return yield Promise.all(o.map((a,l)=>{if(!a.loader)return s[l]={status:"success",data:void 0},Promise.resolve();let u=this.cacheKey(n[l],e);return this.cache.load(u,a.loader,i,a.revalidate).then(c=>{s[l]={status:"success",data:c}},c=>{c instanceof P?s[l]={status:"notfound"}:s[l]={status:"error",error:c instanceof Error?c:new Error(String(c))}})})),s})}renderSlots(t,e,o,n){return y(this,null,function*(){let i=e.route.chain[t],s=this.slotCompiled.get(i);if(!s)return{};let a=0;for(let u=0;u<=t;u++)a+=Y(e.route.chain[u].path);let l={};for(let u of Object.keys(s)){let c=n?s[u].soft:s[u].hard,d=J(c,o.pathname,a);if(!d)continue;d.pathname=o.pathname,d.params=S(S({},e.params),d.params);let h=yield this.loadMatch(d,o);l[u]=H({match:d,baseContext:this.baseContext(o,d),results:h,retry:()=>{this.refresh()},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock}).element}return l})}onRevalidated(t){!this.history||!this.currentRenderKeys.has(t)||this.transition(this.currentUrl(),{replace:!0,scroll:!1,fromHistory:!0})}start(){return y(this,null,function*(){this.history&&!this.releaseHistory&&(this.releaseHistory=this.history.listen(e=>{this.transition(e,{fromHistory:!0})}));let t=this.history?this.history.url():new URL("/","http://localhost");yield this.transition(t,{initial:!0})})}destroy(){var t;(t=this.releaseHistory)==null||t.call(this),this.releaseHistory=null,j===this&&(j=null)}currentUrl(){if(this.history)return this.history.url();let t=this.state.get("search");return new URL(`${this.state.get("pathname")}${t}`,"http://localhost")}resolve(t){return new URL(t,this.currentUrl())}navigate(o){return y(this,arguments,function*(t,e={}){let n=this.resolve(t);if(typeof window!="undefined"&&n.origin!==this.currentUrl().origin){window.location.assign(n.href);return}yield this.transition(n,e)})}push(t,e={}){return this.navigate(t,e)}replace(t,e={}){return this.navigate(t,k(S({},e),{replace:!0}))}back(){var t;(t=this.history)==null||t.go(-1)}forward(){var t;(t=this.history)==null||t.go(1)}refresh(){return y(this,null,function*(){this.cache.invalidate(),yield this.transition(this.currentUrl(),{replace:!0,scroll:!1})})}prefetch(t){return y(this,null,function*(){try{let e=this.resolve(t),o=L(this.routes,e.pathname);if(!o)return;let n=this.loaderContext(e,o);yield Promise.all(o.route.chain.map((i,s)=>{if(!i.loader)return Promise.resolve();let a=this.cacheKey(o.route.chainIds[s],e);return this.cache.prefetch(a,i.loader,n,i.revalidate)}))}catch(e){}})}searchParams(t){return new URLSearchParams(this.state.get("search",t))}addEventListener(t,e){return this.events.addListener(t,e)}getMatch(){return this.currentMatch}renderStream(t){return y(this,null,function*(){let e=t.pathname,o={url:t,pathname:t.pathname,searchParams:t.searchParams,headers:this.headers};for(let c of this.middleware){let d=yield c(o);N(d)&&(e=d.__domphyRewrite)}let n=L(this.routes,e);if(!n){let c=W(this.notFoundBlock);return{shell:c.element,status:404,redirect:null,rest:Promise.resolve({content:c.element,data:{},head:""})}}let i=n.route.chain[n.route.chain.length-1];if(i.redirect)return{shell:{div:""},status:i.permanent?308:307,redirect:i.redirect,rest:Promise.resolve({content:{div:""},data:{},head:""})};let s=this.baseContext(t,n),a=n.route.chain.map(c=>c.loader?{status:"pending"}:{status:"success",data:void 0}),l=H({match:n,baseContext:s,results:a,retry:()=>{},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock}).element,u=y(this,null,function*(){let c=yield this.loadMatch(n,t),d={};yield Promise.all(n.route.chain.map((w,v)=>y(this,null,function*(){this.slotCompiled.has(w)&&(d[v]=yield this.renderSlots(v,n,t,!1))})));let h=H({match:n,baseContext:s,results:c,retry:()=>{},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock,slots:d}).element,m={};n.route.chain.forEach((w,v)=>{w.loader&&c[v].status==="success"&&(m[this.cacheKey(n.route.chainIds[v],t)]=c[v].data)});let f="";try{let w=yield q(n.route.chain.map(v=>v.metadata),this.loaderContext(t,n));f=F(A(w))}catch(w){f=""}return{content:h,data:m,head:f}});return{shell:l,status:200,redirect:null,rest:u}})}cacheKey(t,e){return`${t}|${e.pathname}${e.search}`}loaderContext(t,e){return{pathname:e.pathname,url:t.pathname+t.search,params:e.params,searchParams:t.searchParams,headers:this.headers}}transition(o){return y(this,arguments,function*(t,e={}){var s,a;let n=++this.navigationToken,i=t.pathname+t.search+t.hash;e.fromHistory||(this.lastRedirect=null),this.events.notify("routeChangeStart",i),this.saveScroll();try{let l=t.pathname,u={url:t,pathname:t.pathname,searchParams:t.searchParams,headers:this.headers};for(let d of this.middleware){let h=yield d(u);N(h)&&(l=h.__domphyRewrite)}if(n!==this.navigationToken)return;let c=L(this.routes,l);if(c){let d=c.route.chain[c.route.chain.length-1];if(d.redirect)throw new M(d.redirect,(s=d.permanent)!=null?s:!1);for(let h of c.route.chain)for(let m of(a=h.middleware)!=null?a:[]){let f=yield m(u);if(N(f)){yield this.transition(new URL(f.__domphyRewrite,t),e);return}}if(n!==this.navigationToken)return;yield this.renderMatch(t,c,n,e)}else yield this.renderNotFound(t,n,e)}catch(l){if(n!==this.navigationToken)return;if(l instanceof M){yield this.transition(this.resolve(l.to),k(S({},e),{replace:!0})),this.lastRedirect={to:l.to,permanent:l.permanent};return}if(l instanceof P){yield this.renderNotFound(t,n,e);return}let u=l instanceof Error?l:new Error(String(l));this.tree.set(this.errorBlock(u,()=>{this.refresh()})),this.state.set("status","error"),this.state.set("error",u),this.events.notify("routeChangeError",u,i);return}n===this.navigationToken&&this.events.notify("routeChangeComplete",i)})}renderMatch(t,e,o,n){return y(this,null,function*(){let{chain:i,chainIds:s}=e.route,a=this.loaderContext(t,e),l=i.map(()=>({status:"pending"})),u=null,c=i.map((b,x)=>{if(!b.loader)return l[x]={status:"success",data:void 0},Promise.resolve();let p=this.cacheKey(s[x],t);return this.cache.load(p,b.loader,a,b.revalidate).then(R=>{l[x]={status:"success",data:R}},R=>{R instanceof M?u=u!=null?u:R:R instanceof P?l[x]={status:"notfound"}:l[x]={status:"error",error:R instanceof Error?R:new Error(String(R))}})}),d=!1,h=Promise.all(c).then(()=>{d=!0});if(yield new Promise(b=>setTimeout(b,0)),!d&&i.some(b=>b.loading)){let b=H({match:e,baseContext:this.baseContext(t,e),results:l.map(x=>S({},x)),retry:()=>{this.refresh()},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock});o===this.navigationToken&&b.status==="loading"&&(this.state.set("status","loading"),this.tree.set(b.element))}if(yield h,o!==this.navigationToken)return;if(u)throw u;let m=!n.initial,f={};if(yield Promise.all(i.map((b,x)=>y(this,null,function*(){this.slotCompiled.has(b)&&(f[x]=yield this.renderSlots(x,e,t,m))}))),o!==this.navigationToken)return;let w=H({match:e,baseContext:this.baseContext(t,e),results:l,retry:()=>{this.refresh()},defaultError:this.errorBlock,defaultNotFound:this.notFoundBlock,slots:f}),v={};i.forEach((b,x)=>{b.loader&&l[x].status==="success"&&(v[this.cacheKey(s[x],t)]=l[x].data)}),this.lastData=v,this.currentRenderKeys=new Set(Object.keys(v)),this.currentMatch=e,yield this.applyMetadata(e,a),o===this.navigationToken&&(this.commit(t,e,w.element,w.status,n),this.cache.flushRevalidations())})}renderNotFound(t,e,o){return y(this,null,function*(){let n=W(this.notFoundBlock);this.currentMatch=null,this.metadata={},z([]),e===this.navigationToken&&this.commit(t,null,n.element,"notfound",o)})}baseContext(t,e){return{pathname:e.pathname,url:t.pathname+t.search,params:e.params,searchParams:t.searchParams,hash:t.hash,headers:this.headers}}applyMetadata(t,e){return y(this,null,function*(){try{this.metadata=yield q(t.route.chain.map(o=>o.metadata),e)}catch(o){this.metadata={}}z(A(this.metadata))})}commit(t,e,o,n,i){var s;if(this.history&&!i.fromHistory&&!i.initial){let a=t.pathname+t.search+t.hash;i.replace?this.history.replace(a):this.history.push(a)}this.state.set("pathname",t.pathname),this.state.set("search",t.search),this.state.set("hash",t.hash),this.state.set("params",(s=e==null?void 0:e.params)!=null?s:{}),this.state.set("error",null),this.state.set("status",n),this.tree.set(o),this.restoreScroll(t,i)}saveScroll(){var t,e;typeof window!="undefined"&&((e=(t=this.history)==null?void 0:t.saveScroll)==null||e.call(t,{x:window.scrollX,y:window.scrollY}))}restoreScroll(t,e){var o,n,i,s;if(!(typeof window=="undefined"||e.scroll===!1||e.initial)){if(e.fromHistory){let a=(n=(o=this.history)==null?void 0:o.readScroll)==null?void 0:n.call(o);window.scrollTo((i=a==null?void 0:a.x)!=null?i:0,(s=a==null?void 0:a.y)!=null?s:0);return}if(t.hash){let a=document.getElementById(t.hash.slice(1));if(a){a.scrollIntoView();return}}window.scrollTo(0,0)}}};var Bt="(function(){var h=document.getElementById('domphy-head');if(h){document.head.appendChild(h.content.cloneNode(true));h.remove();}var c=document.getElementById('domphy-content'),a=document.getElementById('domphy-app');if(c&&a){a.replaceChildren(c.content.cloneNode(true));c.remove();}})();",ot="__DOMPHY_APP_DATA__",V=class{constructor(t,e={}){this.node=null;this.routes=t,this.options=e,this.router=new I(t,e)}element(){let t=this.router;return{div:e=>[t.tree.get(e)],style:{display:"contents"}}}render(t){return y(this,null,function*(){return yield this.router.start(),this.node=new B.ElementNode(this.element()),this.node.render(t),this.node})}hydrate(t,e){return y(this,null,function*(){let o=globalThis[ot];return o&&typeof o=="object"&&this.router.cache.seed(o),yield this.router.start(),this.node=new B.ElementNode(this.element()),this.node.mount(t,e),this.node})}destroy(){var t;(t=this.node)==null||t.remove(),this.node=null,this.router.destroy()}renderToString(o){return y(this,arguments,function*(t,e={}){let n=typeof t=="string"?new URL(t,"http://localhost"):t,i=new I(this.routes,k(S({},this.options),{history:null,headers:e.headers}));yield i.transition(n,{initial:!0});let s=i.state.get("status"),a=i.lastRedirect,l=new B.ElementNode({div:[i.tree.get()],style:{display:"contents"}}),u=i.lastData,c={html:l.generateHTML(),css:l.generateCSS(),head:F(A(i.metadata)),status:a?a.permanent?308:307:s==="notfound"?404:200,redirect:a==null?void 0:a.to,data:u,bootstrapScript:`<script>window.${ot} = ${ft(u)};</script>`};return i.destroy(),c})}renderToStream(o){return y(this,arguments,function*(t,e={}){var w,v;let n=typeof t=="string"?new URL(t,"http://localhost"):t,i=new I(this.routes,k(S({},this.options),{history:null,headers:e.headers})),{shell:s,status:a,redirect:l,rest:u}=yield i.renderStream(n),c=new TextEncoder,d=new B.ElementNode({div:[s],style:{display:"contents"}}),h=`<!DOCTYPE html><html><head>${(w=e.head)!=null?w:""}<style id="domphy-style">${d.generateCSS()}</style></head><body><div id="domphy-app">${d.generateHTML()}</div>`,m=(v=e.bootstrap)!=null?v:"";return{stream:new ReadableStream({start(x){return y(this,null,function*(){x.enqueue(c.encode(h));let{content:p,data:R,head:g}=yield u,E=new B.ElementNode({div:[p],style:{display:"contents"}}),T=`<style>${E.generateCSS()}</style><template id="domphy-head">${g}</template><template id="domphy-content">${E.generateHTML()}</template><script>${Bt}</script><script>window.${ot} = ${ft(R)};</script>${m}</body></html>`;x.enqueue(c.encode(T)),x.close(),i.destroy()})}}),status:a,redirect:l!=null?l:void 0}})}};function ft(r){return JSON.stringify(r).replace(/</g,"\\u003c")}function Nt(r,t={}){return new V(r,t)}var Ut=[640,750,828,1080,1200,1920,2048,3840];function _t(r){let{src:t,alt:e="",width:o,height:n,fill:i=!1,sizes:s,quality:a=75,priority:l=!1,placeholder:u="empty",blurDataURL:c,loader:d,deviceSizes:h=Ut}=r,m={src:d?d({src:t,width:o!=null?o:h[h.length-1],quality:a}):t,alt:e,loading:l?"eager":"lazy",decoding:"async",fetchPriority:l?"high":"auto",style:{}};return d&&(m.srcSet=h.map(f=>`${d({src:t,width:f,quality:a})} ${f}w`).join(", "),s&&(m.sizes=s)),o!==void 0&&(m.width=o),n!==void 0&&(m.height=n),i&&(m.style=k(S({},m.style),{position:"absolute",inset:"0",width:"100%",height:"100%",objectFit:"cover"})),u==="blur"&&c&&(m.style=k(S({},m.style),{backgroundImage:`url("${c}")`,backgroundSize:"cover",backgroundPosition:"center"}),m.onLoad=f=>{let w=f.target;w.style.backgroundImage=""}),m}function Ft(r){return r.defaultPrevented||r.button!==0||r.metaKey||r.ctrlKey||r.shiftKey||r.altKey}function $t(r){let{href:t,replace:e=!1,scroll:o=!0,prefetch:n="hover",exact:i=!1}=r,s=()=>{var c;return(c=r.router)!=null?c:nt()},a=c=>{let d=new URL(t,"http://localhost").pathname;return i||d==="/"?c===d:c===d||c.startsWith(`${d}/`)},l=!1,u=()=>{l||(l=!0,s().prefetch(t))};return{href:t,ariaCurrent:c=>a(s().state.get("pathname",c))?"page":null,dataActive:c=>a(s().state.get("pathname",c))?"":null,onClick:c=>{let d=c,h=d.currentTarget;Ft(d)||h.target&&h.target!=="_self"||h.hasAttribute("download")||new URL(h.href,window.location.href).origin===window.location.origin&&(d.preventDefault(),s().navigate(t,{replace:e,scroll:o}))},onMouseEnter:()=>{n==="hover"&&u()},onFocus:()=>{n==="hover"&&u()},_onMount:c=>{if(n!=="visible")return;if(typeof IntersectionObserver=="undefined"){u();return}let d=new IntersectionObserver(h=>{h.some(m=>m.isIntersecting)&&(u(),d.disconnect())});d.observe(c.domElement),c.setMetadata("navLinkObserver",d)},_onRemove:c=>{let d=c.getMetadata("navLinkObserver");d==null||d.disconnect()}}}var it=new Set;function jt(){it.clear()}function gt(r){let t=globalThis.requestIdleCallback;t?t(r):setTimeout(r,0)}function Kt(r){let{src:t,strategy:e="afterInteractive",id:o,async:n=!0,onLoad:i,onError:s}=r,a=o!=null?o:t,l=c=>{it.has(a)||(it.add(a),c.src=t)},u={script:"",async:n,onLoad:()=>i==null?void 0:i(),onError:()=>s==null?void 0:s(),_onMount:c=>{let d=c.domElement;if(e==="afterInteractive"){l(d);return}document.readyState==="complete"?gt(()=>l(d)):window.addEventListener("load",()=>gt(()=>l(d)),{once:!0})}};return o!==void 0&&(u.id=o),u}function Gt(r){return r}0&&(module.exports={AppRouter,DataCache,DomphyApp,NotFoundSignal,PREFETCH_LIFETIME,RedirectSignal,applyHeadTags,buildHref,buildNotFoundTree,buildTree,compareSpecificity,compileRoutes,createApiHandler,createApp,createBrowserHistory,createMemoryHistory,defaultErrorBlock,defaultNotFoundBlock,defineRoutes,getRouter,isRewrite,json,matchPath,matchRoute,matchRouteSuffix,metadataToHeadTags,navLink,notFound,optimizedImage,parseSegment,permanentRedirect,redirect,renderHeadTags,resetScripts,resolveMetadata,rewrite,script,splitPath,urlPartCount});
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|