gemi 0.118.0 → 0.119.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.
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ef as $G}from"./chunk-hkf2k2eq.js";import{yf as eX}from"./chunk-eke2frrm.js";import{$f as J$,Ag as Gz,Bg as A$,Cg as fX,Df as TX,Dg as pX,Ef as J5,Ff as W5,Fg as hX,Gf as f8,Hf as H8,Kf as C8,Lf as _8,Mf as CZ,Nf as rz,Of as HX,Pf as gJ,Qf as g,Vf as S,Wf as l8,Xf as m$,Yf as E8,Zf as A3,ag as c,bg as Z8,pg as f3,wg as p$,zf as wZ}from"./chunk-3zxfd7pn.js";import{Ig as _Z,Jg as q0,Kg as w1,Lg as X5}from"./chunk-1m3hvy3q.js";import{Mg as hz,Ng as Q8,Og as C}from"./chunk-490sbcma.js";import{Rg as Jz,Ug as D3}from"./chunk-k31qfe7a.js";import{$g as vX,Yg as h5}from"./chunk-y09r0wsw.js";import{rh as M3,wh as SZ}from"./chunk-9pkj7sk6.js";import{Mh as RX}from"./chunk-xx3zvc3g.js";import{Nh as V8}from"./chunk-gqfqnv3f.js";import{Oh as IX,Ph as V1,Qh as z$,Rh as aX,Sh as rX,Uh as xJ,Vh as gX,ci as tX}from"./chunk-kkte8nze.js";import{ri as X$}from"./chunk-hr1r3g0d.js";import{Bi as UJ,wi as DX}from"./chunk-g9hhdcax.js";import{Ii as BX,Ni as o}from"./chunk-z759yah5.js";import{Oi as HZ,Ri as T}from"./chunk-g5ppst76.js";import{Ui as cX}from"./chunk-8wcpxm41.js";import{dj as MX}from"./chunk-jf6qqzat.js";import{ij as K8}from"./chunk-hm9cjxy2.js";function L3($){return typeof $==="function"&&$.prototype!==void 0}function K1($){return typeof $==="string"?[$]:$}function H3($,Z){let j=Z?"attachment":"inline",J=$.replace(/["\\]/g,"").replace(/[^\x20-\x7e]/g,"_");return`${j}; filename="${J}"; filename*=UTF-8''${encodeURIComponent($)}`}function KG($){return"total"in $&&"partial"in $&&"body"in $}function RJ(){return new Response("Not found",{status:404,headers:{"X-Content-Type-Options":"nosniff"}})}function fZ($){return new Response(null,{status:416,headers:{"Accept-Ranges":"bytes","Content-Range":_8($),"Content-Length":"0","Cache-Control":"no-store","X-Content-Type-Options":"nosniff"}})}async function OG($){if($ instanceof Blob)return{body:$,start:0,end:$.size-1,total:$.size,partial:!1,type:$.type,name:$.name,download:!1,status:200,extraHeaders:{}};if(KG($))return{body:$.body,start:$.start,end:$.end,total:$.total,partial:$.partial,type:$.type,name:$.name,download:$.download??!1,etag:$.etag,lastModified:$.lastModified,status:$.status??200,extraHeaders:$.headers??{}};let Z=$.file,j=Z instanceof Blob?Z:null,J=$.total??j?.size??-1;return{body:Z,start:$.start??0,end:$.end??J-1,total:J,partial:$.partial??!1,type:$.type??j?.type??"",name:$.name??Z?.name,download:$.download??!1,etag:$.etag,lastModified:$.lastModified,status:$.status??200,extraHeaders:$.headers??{}}}async function S8($,Z){if($ instanceof Response)return $;if(!$)return RJ();let j=await OG($),{body:J,start:W,end:Y,total:z,partial:X}=j;if(J instanceof Blob&&"exists"in J&&typeof J.exists==="function"){if(!await J.exists())return RJ()}let{range:G}=Z;if(G){if(z<=0)return fZ(Math.max(z,0));if(!X){if(J instanceof Blob){let K=H8(G,z);if(!K)return fZ(z);J=J.slice(K.start,K.end+1),W=K.start,Y=K.end,X=!0}}}let F=Boolean(G)&&X,Q=F?206:j.status,O=new Headers;if(O.set("Accept-Ranges","bytes"),O.set("Content-Type",j.type||"application/octet-stream"),O.set("X-Content-Type-Options","nosniff"),F)O.set("Content-Range",C8(W,Y,z)),O.set("Content-Length",String(Y-W+1));else if(z>=0)O.set("Content-Length",String(z));if(j.name)O.set("Content-Disposition",H3(j.name,j.download));if(j.etag)O.set("ETag",j.etag);if(j.lastModified)O.set("Last-Modified",j.lastModified.toUTCString());for(let[K,D]of Object.entries(j.extraHeaders))O.set(K,D);if((Z.method??"GET").toUpperCase()==="HEAD"){if(J&&"cancel"in J&&typeof J.cancel==="function")await J.cancel();return new Response(null,{status:Q,headers:O})}return new Response(J,{status:Q,headers:O})}class k$ extends q0{limit;constructor($){super("The request body is too large.",{status:413});this.limit=$}}var bJ={b:1,k:1024,kb:1024,m:1048576,mb:1048576,g:1073741824,gb:1073741824};function RZ($){if(typeof $==="number"){if(Number.isFinite($)&&$>=0)return Math.floor($);if($===1/0)return 1/0}else{let Z=$.trim().toLowerCase();if(Z==="none"||Z==="off")return 1/0;let j=/^(\d+(?:\.\d+)?)\s*([a-z]*)$/.exec(Z);if(j&&(j[2]===""||(j[2]in bJ)))return Math.floor(Number(j[1])*(bJ[j[2]]??1))}throw Error(`Invalid body limit ${JSON.stringify($)}. Use a byte count or a size such as "64kb", "1mb" or "none".`)}var EZ=new WeakMap;function wJ($){return EZ.has($)}function kJ($){return EZ.get($)?.limit??null}function qJ($){let Z=EZ.get($);return Z?Z.read>Z.limit:!1}function BG($){let Z=$.headers.get("Content-Length");if(Z===null||!/^\s*\d+\s*$/.test(Z))return null;return Number(Z)}function A8($,Z){let j=BG($);if(j!==null&&j>Z)throw new k$(Z)}function C3($,Z,j={}){let J=EZ.get($);if(J)J.limit=Z;else{let W={limit:Z,read:0,stream:void 0,used:!1};EZ.set($,W),UG($,W)}if(j.checkDeclared!==!1)A8($,Z)}function DG($){return Reflect.get(Object.getPrototypeOf($),"body",$)??null}function x8($,Z){if(Z.stream!==void 0)return Z.stream;let j=DG($);if(!j)return Z.stream=null;let J;return Z.stream=new ReadableStream({async pull(W){J??=j.getReader();let{done:Y,value:z}=await J.read();if(Y){W.close();return}if(Z.read+=z.byteLength,Z.read>Z.limit){let X=new k$(Z.limit);W.error(X),J.cancel(X).catch(()=>{});return}W.enqueue(z)},cancel(W){return J?J.cancel(W):j.cancel(W)}},{highWaterMark:0}),Z.stream}async function w$($,Z){if(A8($,Z.limit),Z.used||Z.stream?.locked)throw TypeError("Body already used");Z.used=!0;let j=x8($,Z);if(!j)return new Uint8Array(0);let J=j.getReader(),W=[],Y=0;for(;;){let{done:G,value:F}=await J.read();if(G)break;W.push(F),Y+=F.byteLength}let z=new Uint8Array(Y),X=0;for(let G of W)z.set(G,X),X+=G.byteLength;return z}function vJ($){return $.headers.get("Content-Type")??""}function UG($,Z){let j=(J,W)=>Object.defineProperty($,J,{configurable:!0,...W});j("body",{get:()=>x8($,Z)}),j("bodyUsed",{get:()=>Z.used||Boolean(Z.stream?.locked)||Reflect.get(Object.getPrototypeOf($),"bodyUsed",$)}),j("bytes",{value:()=>w$($,Z)}),j("arrayBuffer",{value:async()=>{let J=await w$($,Z);return J.buffer.slice(J.byteOffset,J.byteOffset+J.byteLength)}}),j("text",{value:async()=>new TextDecoder().decode(await w$($,Z))}),j("json",{value:async()=>JSON.parse(new TextDecoder().decode(await w$($,Z)))}),j("blob",{value:async()=>new Blob([await w$($,Z)],{type:vJ($)})}),j("formData",{value:async()=>new Response(await w$($,Z),{headers:{"Content-Type":vJ($)}}).formData()}),j("clone",{value:()=>{A8($,Z.limit);let J=x8($,Z),W=null;if(J){let[Y,z]=J.tee();Z.stream=Y,W=z}return new Request($.url,{method:$.method,headers:$.headers,body:W,signal:$.signal,duplex:"half"})}})}function yJ($){return L3($)}class Z0{method;handler;methodName;__internal_brand="RouteHandler";middlewares=[];constructor($,Z,j){this.method=$;this.handler=Z;this.methodName=j;this.handler=Z,this.methodName=j,this.method=$}get source(){if(!yJ(this.handler)||typeof this.methodName!=="string")return;return{controller:this.handler,methodName:this.methodName}}__internal_use(){return{run:this.run.bind(this),middlewares:this.middlewares}}run($){if(yJ(this.handler)){let Z=new this.handler;return Z[this.methodName].bind(Z)()}return this.handler()}middleware($){return this.middlewares=K1($),this}}class mJ{url;headers;__internal_brand="ProxyHandler";middlewares=[];constructor($,Z){this.url=$;this.headers=Z}middleware($){return this.middlewares=K1($),this}async run(){let $=new S,Z=$.headers.toJSON();for(let j of gJ($.rawRequest))delete Z[j];try{return await fetch(this.url,{method:$.rawRequest.method,headers:{...Z,...this.headers},body:$.rawRequest.body})}catch(j){if(qJ($.rawRequest))throw new k$(kJ($.rawRequest));throw j}}}class pJ{constructor(...$){return new Z0(...$)}}class hJ extends Z0{__internal_brand="StreamHandler";async run($){let Z=C.getStore(),j=Z?.req?.rawRequest,J=f8(j?.headers.get("Range"));if(Z)Z.rangeRequest=J;try{let W=await super.run($);return await S8(W,{range:J,method:j?.method})}catch(W){if(W instanceof E8)return fZ(W.total);throw W}finally{if(Z)Z.rangeRequest=null}}}class cJ{constructor(...$){return new hJ(...$)}}class dJ{__internal_brand="ResourceRoutes";first;second;constructor($){this.first={get:new Z0("GET",$,"list"),post:new Z0("POST",$,"store")},this.second={get:new Z0("GET",$,"show"),put:new Z0("PUT",$,"update"),delete:new Z0("DELETE",$,"delete")}}middleware($){if($.list)this.first.get.middleware($.list);if($.store)this.first.post.middleware($.store);if($.show)this.second.get.middleware($.show);if($.update)this.second.put.middleware($.update);if($.delete)this.second.delete.middleware($.delete);return this}}class A0{static __brand="ApiRouter";routes={};middlewares=[];middleware($){}get($,Z){return new Z0("GET",$,Z)}post($,Z){return new Z0("POST",$,Z)}put($,Z){return new Z0("PUT",$,Z)}patch($,Z){return new Z0("PATCH",$,Z)}delete($,Z){return new Z0("DELETE",$,Z)}resource($){return new dJ($)}agent($){if($.kind!=="agent-controller")throw TypeError(`this.agent() takes an AgentController class, and got ${VG($)}.`);return TG($,this)}file($,Z){return new pJ("GET",$,Z)}stream($,Z){return new cJ("GET",$,Z)}proxy($,Z={}){return new mJ($,Z)}}function VG($){if(typeof $==="function"&&$.name)return $.name;return typeof $}function TG($,Z){let j={stream:new Z0("POST",$,"stream"),attach:new Z0("POST",$,"attach"),stop:new Z0("POST",$,"stop"),upload:new Z0("POST",$,"upload")};return class extends A0{static __internal_brand="AgentRoute";static controller=$;static handlers=j;constructor(){super();this.middlewares=[...Z?.middlewares??[]]}routes={"/":j.stream,"/attach":j.attach,"/stop":j.stop,"/files":j.upload};static middleware(W){if(W.stream)j.stream.middleware(W.stream);if(W.attach)j.attach.middleware(W.attach);if(W.stop)j.stop.middleware(W.stop);if(W.upload)j.upload.middleware(W.upload);return this}}}class R8{as;input;bind;__internal_brand="McpModelParam";constructor($,Z,j){this.as=$;this.input=Z;this.bind=j}}class b8{method;url;meta;__internal_brand="McpRoute";constructor($,Z,j){this.method=$;this.url=Z;this.meta=j}}class uJ{static __brand="McpRouter";routes={};scopes;param($){return new R8($.as,$.input,$.bind)}fromApiRoute($,Z,j){return new b8($,Z,j)}}function G0($,Z){return $.replace(/:([^/]+[*?]?)/g,(j,J)=>{let W=J.endsWith("?")||J.endsWith("*"),Y=W?J.slice(0,-1):J,z=Z[Y];if(z===void 0){if(W)return"";if(import.meta.env.DEV)throw Error(`Missing parameter: ${Y}`);console.error(`Missing parameter: ${Y} in URL: ${$}`)}return String(z)}).replace(/\/\//g,"/").replace(/\/$/,"")}class v8 extends q0{constructor($,Z=307){super("Redirect error");this.name="RedirectError",this.payload={api:{status:200,data:{},directive:{kind:"Redirect",path:$}},view:{status:Z,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:$}}}}}class O1{static to($,...Z){let[j={}]=Z,{search:J={},params:W={},permanent:Y,status:z}={params:{},status:307,permanent:!1,...j},X=new URLSearchParams(J).toString();throw new v8([G0($,W)||"/",X.toString()].filter(Boolean).join("?"),z??(Y?301:307))}static external($,Z=307){throw new v8($,Z)}}var lJ=Symbol.for("gemi.HttpResponse");class j${kind;body;status;headers;[lJ]=!0;constructor($,Z,j,J){this.kind=$;this.body=Z;this.status=j;this.headers=J}static json($,Z={}){let j=Z.status??200;return IG(j),new j$("json",$,j,new Headers(Z.headers))}static error($,Z,j={}){if(!Number.isInteger($)||$<400||$>599)throw RangeError(`HttpResponse.error: status must be an integer from 400 to 599, got ${$}.`);return j$.json({error:Z},{...j,status:$})}get ok(){return this.status>=200&&this.status<300}toResponse($,Z){let j=$,J=this.serialize(j);for(let W of Z)j.append("Set-Cookie",W);this.headers.forEach((W,Y)=>{if(Y.toLowerCase()!=="set-cookie")j.set(Y,W)});for(let W of this.headers.getSetCookie())j.append("Set-Cookie",W);if(this.status>=400&&!this.headers.has("Cache-Control"))j.set("Cache-Control","no-store");return new Response(J,{status:this.status,headers:j})}serialize($){switch(this.kind){case"json":return $.set("Content-Type","application/json"),JSON.stringify(this.body)??null}}}function IG($){if(!Number.isInteger($)||$<200||$>599)throw RangeError(`HttpResponse: status must be an integer from 200 to 599, got ${$}.`);if($===204||$===205||$===304)throw RangeError(`HttpResponse.json: a ${$} response has no body.`)}function q$($){return typeof $==="object"&&$!==null&&$[lJ]===!0}function MG($,Z,j={}){return j$.error($,Z,j)}class iJ{kind="redirect";viewPath="REDIRECT";middlewares=[];featureGates=[];handler;constructor($){if(!$)this.handler=()=>({});else if(typeof $==="function")this.handler=$;else{let[Z,j]=$;this.handler=(J)=>{return new Z()[j](J)}}}async run($,Z){let{destination:j,permanent:J=!1,status:W=307}=await this.handler($);if(!j)throw Error(`Redirect destination is required see ${Z}`);return O1.to(j,{permanent:J,status:W}),{}}middleware($){return this.middlewares=K1($),this}feature($){return this.featureGates=[...this.featureGates,$],this}}async function w8($,Z){if($ instanceof Response)return $;let j=$ instanceof Blob,J=j?$:$.file,W=j?$.name:$.name??$.file?.name,Y=(j?$.type:$.type??$.file?.type)||"",z=j?!1:$.download??!1,X=j?200:$.status??200;if(!j)for(let[G,F]of Object.entries($.headers??{}))Z.set(G,F);if(J instanceof Blob&&"exists"in J&&typeof J.exists==="function"){if(!await J.exists())return new Response("Not found",{status:404})}if(Z.set("Content-Type",Y||"application/octet-stream"),J instanceof Blob)Z.set("Content-Length",String(J.size));if(W)Z.set("Content-Disposition",H3(W,z));return new Response(J instanceof Blob?J.stream():J,{status:X,headers:Z})}class sJ{kind="file";viewPath="FILE";middlewares=[];featureGates=[];handler;constructor($){if(!$)this.handler=()=>null;else if(typeof $==="function")this.handler=$;else{let[Z,j]=$;this.handler=(J)=>{return new Z()[j](J)}}}async run($,Z){let j=await this.handler($);if(!j)throw Error(`File route handler must return a file see ${Z}`);return{FILE:j}}middleware($){return this.middlewares=K1($),this}feature($){return this.featureGates=[...this.featureGates,$],this}}function nJ($,Z){if(q$($))throw Error(`The handler of view "${Z}" returned an HttpResponse. HttpResponse is for api routes; a view handler returns its props.`);return $}class oJ{viewPath;middlewares=[];featureGates=[];staticOptions=null;handler;constructor($,Z){this.viewPath=$;if(!Z)this.handler=()=>({});else if(typeof Z==="function")this.handler=Z;else{let[j,J]=Z;this.handler=(W)=>{return new j()[J](W)}}}async run($,Z){let j=nJ(await this.handler($),this.viewPath);return{[this.viewPath]:{...j,breadcrumb:{label:j?.breadcrumb??"",href:Z}}}}middleware($){return this.middlewares=K1($),this}static($={}){return this.staticOptions={...$},this}feature($){return this.featureGates=[...this.featureGates,$],this}}class aJ{viewPath;children;middlewares=[];featureGates=[];alwaysRuns=!1;handler=()=>({});constructor($,Z,j){this.viewPath=$;if(typeof Z==="function")this.handler=Z,this.children=class extends B1{routes=j??{}};else if(Array.isArray(Z)){let[J,W]=Z;this.handler=(Y)=>{return new J()[W](Y)},this.children=class extends B1{routes=j??{}}}else this.children=class extends B1{routes=Z},this.handler=()=>({})}async run($,Z){let j=nJ(await this.handler($),this.viewPath);return{[this.viewPath]:{...j,breadcrumb:{label:j?.breadcrumb??"",href:Z}}}}alwaysRun(){return this.alwaysRuns=!0,this}middleware($){return this.middlewares=K1($),this}feature($){return this.featureGates=[...this.featureGates,$],this}}class B1{middlewares=[];featureGates=[];routes={};view($,Z){return new oJ($,Z)}file($){return new sJ($)}redirect($){return new iJ($)}layout($,Z,j){return new aJ($,Z,j)}}class F0{req;static runsOnRefusal=!1;config={};constructor($){this.req=$}run(...$){return{}}static configure($){let Z=this;return class extends Z{config=$}}}function PG($){return $}function NG(){return{aliases:{},global:[],bodyLimit:null}}var D1="redirect";function U1($,Z="/"){if(typeof $!=="string"||!$.startsWith("/"))return Z;if(/[\u0000-\u001f\u007f\\]/.test($)||$.startsWith("//"))return Z;try{let j=new URL($,"http://gemi.invalid");if(j.origin!=="http://gemi.invalid")return Z;let J=`${j.search}${j.hash}`.replaceAll("/","%2F"),W=`${j.pathname}${J}`.replaceAll(":","%3A");return W.startsWith("//")?Z:W}catch{return Z}}function y$($){let Z=$.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();return Z?Z==="https":new URL($.url).protocol==="https:"}function LG($,Z=!0){let j=new URL($.rawRequest.url),J=j.pathname.replace(/\.(json|og)$/,""),[,W,...Y]=J.split("/");if(T(o).supportedLocales.includes(W))J=`/${Y.join("/")}`;return Z?`${J}${j.search}`:J}function HG($,Z){let j=(J)=>J.replace(/\/+$/,"")||"/";return j($)===j(Z)}function _3($,Z){let j=Z||T(E).config.signInPath,J=/^[a-z][a-z\d+.-]*:/i.test(j);if(J?!/^https?:\/\//i.test(j):!j.startsWith("/"))throw Error(`\`auth.signInPath\` must be a path like "/auth/sign-in", or an http(s) URL for sign-in hosted elsewhere. Got "${j}". A route's own \`"auth:<path>"\` cannot carry a URL, because the alias parser splits it on the colon.`);let W=new URL(j,"http://gemi.invalid");if($?.kind==="view"){let Y=LG($,!J);if(J||!HG(new URL(Y,W).pathname,W.pathname))W.searchParams.set(D1,Y)}return J?W.href:`${W.pathname}${W.search}`}var v1="access_token";function k8($){return $?.cookies?.get("access_token")||$?.headers?.get("access_token")||null}async function S3($,Z){let j=k8(Z);if(!j)return null;return(await $.getSession(j,Z.headers.get("User-Agent")))?.user??null}class rJ extends F0{async run($){let Z=C.getStore(),j=Z.req;if(Z.user)return{};let J=await S3(T(E),j);if(!J)throw new J$({redirectTo:_3(j,$)});return Z.setUser(J),{}}}class tJ extends F0{async run(...$){let[Z="public",j="864000",...J]=$,W=`${Z}, max-age=${j}${J.length>0?", ":""}${J.join(", ")}`;if($.length===0)W="public, max-age=864000, stale-while-revalidate=300, stale-if-error=600";if($.length===1&&$[0]==="public")W="public, max-age=864000, stale-while-revalidate=300, stale-if-error=600";if($.length===1&&$[0]==="private")W="private, max-age=0, stale-while-revalidate=300, stale-if-error=600";if(this.req.rawRequest.method==="GET")this.req.ctx().setHeaders("Cache-Control",W);return{}}}var eJ={"Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Allow-Credentials":"true"};class $5 extends F0{static runsOnRefusal=!0;config={origins:{"":{"Access-Control-Allow-Methods":"GET, HEAD, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Allow-Credentials":"true"}}};run(){let $=this.req,Z=$.rawRequest.headers.get("Origin");if(Z&&this.config.origins[Z]){$.ctx().setHeaders("Access-Control-Allow-Origin",Z);let j={...eJ,...this.config.origins[Z]};for(let[J,W]of Object.entries(j))$.ctx().setHeaders(J,W)}else if(Z&&this.config.origins["*"]){$.ctx().setHeaders("Access-Control-Allow-Origin","*");let j={...eJ,...this.config.origins["*"]};delete j["Access-Control-Allow-Credentials"];for(let[J,W]of Object.entries(j))$.ctx().setHeaders(J,W)}return{}}}class e0{config;static token="ratelimiter";constructor($){this.config=$}get driver(){return this.config.driver}async consume($,Z={}){let j=Z.limit??this.config.limit,J=Z.window??this.config.window,W=Z.cost??1;if(Z5("window",J),Z5("limit",j),!Number.isFinite(W)||W<0)throw Error(`Rate limiter cost must be zero or greater, got ${W}`);return await this.config.driver.consume({key:$,limit:j,window:J*1000,cost:W})}}function Z5($,Z){if(!Number.isFinite(Z)||Z<=0)throw Error(`Rate limiter ${$} must be greater than zero, got ${Z}`)}class bZ extends q0{constructor($){super("Rate limit exceeded");let Z={"Content-Type":"application/json",...$?z5($):{}};this.payload={api:{status:429,data:{error:w1("rate_limit","Rate limit exceeded",429)},headers:Z},view:{error:{message:"Rate limit exceeded"},status:429,headers:Z}}}}class Y5 extends F0{async run($,Z){let j=CG();if(!j)return{};let J=await j.consume(this.key(),{limit:j5($)??this.config.limit,window:j5(Z)??this.config.window});if(this.config.headers!==!1){let W=this.req.ctx?.();if(W)for(let[Y,z]of Object.entries(z5(J)))W.setHeaders(Y,z)}if(!J.allowed)throw new bZ(J);return{}}key(){if(this.config.key)return this.config.key(this.req);let $=J5(this.req.rawRequest);if($)return`mcp:${$.via}:${$.id}:${this.req.routePath??"*"}`;return`${g$(this.req)}:${this.req.routePath??"*"}`}}function CG(){try{let $=T();return $.bound(e0)?$.make(e0):null}catch{return null}}function g$($){let Z=W5($.rawRequest);if(Z!==void 0)return Z;let j=$.headers.get("x-forwarded-for");if(j){let[J]=j.split(",");if(J?.trim())return J.trim()}return $.headers.get("x-real-ip")?.trim()||"unknown"}function z5($){let Z={"X-RateLimit-Limit":String($.limit),"X-RateLimit-Remaining":String($.remaining),"X-RateLimit-Reset":String(Math.ceil($.resetAt/1000))};if(!$.allowed)Z["Retry-After"]=String(Math.max(1,Math.ceil($.retryAfter/1000)));return Z}function j5($){if($===void 0||$===null||$==="")return;let Z=Number($);if(!Number.isFinite(Z)||Z<=0)return;return Z}class G5 extends F0{async run(){let $=this.req.cookies.get("csrf_token");if(!$)throw new q8;if(!["POST","PUT","PATCH","DELETE"].includes(this.req.rawRequest.method))return{};if(!Bun.CSRF.verify($,{secret:process.env.SECRET}))throw new q8;return{}}}class q8 extends q0{constructor(){super("Invalid CSRF token");this.name="InvalidCSRFTokenError"}payload={api:{status:403,data:{error:X5("csrf","Invalid CSRF token",403)}},view:{}}}class x3 extends F0{run($){let Z=$??this.config.limit;if(Z===void 0||Z==="")throw Error('`body-limit` needs a size, as in "body-limit:64kb".');return C3(this.req.rawRequest,RZ(Z)),{}}}class F5{policiesList={};constructor(){let $=this.register();for(let Z of $){let j=new Z;this.policiesList[Z.name]=j}}register(){return[]}}class Q5{all($,Z){return!0}}class y8{options;param;refuse;answers=new WeakMap;constructor($){this.options=$;this.param=$.param,this.refuse=$.refuse??"not_found"}refusal(){return this.refuse==="forbidden"?new m$:new A3}authorize($,Z){if(typeof Z==="number"&&Number.isFinite(Z))Z=String(Z);if(typeof Z!=="string"||Z==="")return Promise.reject(this.refusal());let j=this.answers.get($.rawRequest);if(!j)j=new Map,this.answers.set($.rawRequest,j);let J=j.get(Z);if(!J)J=this.decide($,Z),j.set(Z,J);return J}async allows($,Z){try{return await this.authorize($,Z),!0}catch(j){if(this.isRefusal(j))return!1;throw j}}fromRoute($=new S,Z=this.param){if(Z===void 0)throw Error('This resource policy has no `param`. Give `defineResourcePolicy` one, or name it: `fromRoute(req, "pageId")`, or `alias:pageId` on the middleware.');return this.authorize($,$.params?.[Z])}get middleware(){if(!this.middlewareClass){let $=(Z,j)=>this.fromRoute(Z,j||void 0);this.middlewareClass=class extends F0{async run(j){await $(this.req,j)}}}return this.middlewareClass}middlewareClass;forAgent($){return{authorize:async(Z,{threadId:j,body:J})=>{let W;if(j!==void 0){if(W=$.thread?await $.thread(j,Z):null,W===null||W===void 0)throw this.refusal()}if(J!==void 0){let Y=await $.body(J,Z);if(await this.authorize(Z,Y),j!==void 0&&String(W)!==String(Y))throw this.refusal();return}if(j!==void 0)await this.authorize(Z,W)}}}async decide($,Z){let j=await this.options.load(Z,$);if(j===null||j===void 0||!await this.options.allow(j,$))throw this.refusal();return j}isRefusal($){return this.refuse==="forbidden"?$ instanceof m$:$ instanceof A3}}function _G($){return new y8($)}async function E3($,Z,j=!1){if(!$.body)return new Uint8Array;let[J,W]=await mG($.body),z=J.length>=2&&J[0]===31&&J[1]===139?W.pipeThrough(new DecompressionStream("gzip")):W;return gG(z,Z,j,$.url)}async function gG($,Z,j,J){let W=$.getReader(),Y=[],z=0;try{for(;;){let{done:F,value:Q}=await W.read();if(F)break;if(z+Q.byteLength>Z){if(!j)throw new f3(J,Z);Y.push(Q.subarray(0,Z-z)),z=Z;break}Y.push(Q),z+=Q.byteLength}}finally{W.cancel().catch(()=>{})}let X=new Uint8Array(z),G=0;for(let F of Y)X.set(F,G),G+=F.byteLength;return X}async function mG($){let Z=$.getReader(),j=await Z.read(),J=j.done?new Uint8Array:j.value,W=new ReadableStream({start(Y){if(j.done)Y.close();else Y.enqueue(J)},async pull(Y){let z=await Z.read();if(z.done)Y.close();else Y.enqueue(z.value)},cancel(Y){return Z.cancel(Y)}});return[J,W]}function R3($){return new TextDecoder("utf-8").decode($)}var pG={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;"};function W$($){return $.replace(/[&<>"']/g,(Z)=>pG[Z])}var hG={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function g8($){if(!$.includes("&"))return $;return $.replace(/&(#x[0-9a-fA-F]{1,6}|#[0-9]{1,7}|[a-zA-Z]{2,4});/g,(Z,j)=>{if(j[0]!=="#")return hG[j]??Z;let J=j[1]==="x"?parseInt(j.slice(2),16):parseInt(j.slice(1),10);return J>0&&J<=1114111?String.fromCodePoint(J):Z})}function m8($){let Z=$.indexOf(":");return(Z===-1?$:$.slice(Z+1)).toLowerCase()}function K5($,Z){let j=$.length,J=0;while(J<j){if(Z.stopped?.())return;let W=$.indexOf("<",J);if(W===-1){Z.text(g8($.slice(J)));return}if(W>J)Z.text(g8($.slice(J,W)));if($.startsWith("<!--",W)){let Y=$.indexOf("-->",W+4);if(Y===-1)return;J=Y+3}else if($.startsWith("<![CDATA[",W)){let Y=$.indexOf("]]>",W+9);if(Y===-1)return;Z.text($.slice(W+9,Y)),J=Y+3}else if($.startsWith("<?",W)){let Y=$.indexOf("?>",W+2);if(Y===-1)return;J=Y+2}else if($.startsWith("<!",W)){let Y=$.indexOf(">",W+2);if(Y===-1)return;let z=$.indexOf("[",W+2);if(z!==-1&&z<Y){let X=$.indexOf("]",z+1);if(X===-1)return;let G=$.indexOf(">",X+1);if(G===-1)return;J=G+1}else J=Y+1}else if($[W+1]==="/"){let Y=$.indexOf(">",W+2);if(Y===-1)return;Z.close(m8($.slice(W+2,Y).trim())),J=Y+1}else{let Y=cG($,W+1);if(Y===-1)return;let z=$.slice(W+1,Y),X=z.endsWith("/");if(X)z=z.slice(0,-1);let G=z.search(/[\s]|$/),F=m8(z.slice(0,G));if(F){if(Z.open(F,dG(z.slice(G)),X),X)Z.close(F)}J=Y+1}}}function cG($,Z){let j=null;for(let J=Z;J<$.length;J++){let W=$[J];if(j){if(W===j)j=null}else if(W==='"'||W==="'")j=W;else if(W===">")return J}return-1}function dG($){let Z={},j=/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;for(let J of $.matchAll(j))Z[m8(J[1])]=g8(J[2]??J[3]??"");return Z}class j0 extends Error{url;status;constructor($,Z=null,j=null){super($);this.url=Z;this.status=j;this.name="SitemapError"}}var V5="http://www.sitemaps.org/schemas/sitemap/0.9",uG="http://www.w3.org/1999/xhtml",c8=`<?xml version="1.0" encoding="UTF-8"?>
2
+ import{ef as $G}from"./chunk-hkf2k2eq.js";import{yf as eX}from"./chunk-eke2frrm.js";import{$f as J$,Ag as Gz,Bg as A$,Cg as fX,Df as TX,Dg as pX,Ef as J5,Ff as W5,Fg as hX,Gf as f8,Hf as H8,Kf as C8,Lf as _8,Mf as CZ,Nf as rz,Of as HX,Pf as gJ,Qf as g,Vf as S,Wf as l8,Xf as m$,Yf as E8,Zf as A3,ag as c,bg as Z8,pg as f3,wg as p$,zf as wZ}from"./chunk-3zxfd7pn.js";import{Ig as _Z,Jg as y0,Kg as w1,Lg as X5}from"./chunk-1m3hvy3q.js";import{Mg as hz,Ng as Q8,Og as C}from"./chunk-490sbcma.js";import{Rg as Jz,Ug as D3}from"./chunk-xx7necqt.js";import{$g as vX,Yg as h5}from"./chunk-y09r0wsw.js";import{rh as M3,wh as SZ}from"./chunk-9pkj7sk6.js";import{Mh as RX}from"./chunk-xx3zvc3g.js";import{Nh as V8}from"./chunk-gqfqnv3f.js";import{Oh as IX,Ph as V1,Qh as z$,Rh as aX,Sh as rX,Uh as xJ,Vh as gX,ci as tX}from"./chunk-kkte8nze.js";import{ri as X$}from"./chunk-hr1r3g0d.js";import{Bi as UJ,wi as DX}from"./chunk-g9hhdcax.js";import{Ii as BX,Ni as o}from"./chunk-z759yah5.js";import{Oi as HZ,Ri as T}from"./chunk-g5ppst76.js";import{Ui as cX}from"./chunk-8wcpxm41.js";import{dj as MX}from"./chunk-jf6qqzat.js";import{ij as K8}from"./chunk-hm9cjxy2.js";function L3($){return typeof $==="function"&&$.prototype!==void 0}function K1($){return typeof $==="string"?[$]:$}function H3($,Z){let j=Z?"attachment":"inline",J=$.replace(/["\\]/g,"").replace(/[^\x20-\x7e]/g,"_");return`${j}; filename="${J}"; filename*=UTF-8''${encodeURIComponent($)}`}function KG($){return"total"in $&&"partial"in $&&"body"in $}function RJ(){return new Response("Not found",{status:404,headers:{"X-Content-Type-Options":"nosniff"}})}function fZ($){return new Response(null,{status:416,headers:{"Accept-Ranges":"bytes","Content-Range":_8($),"Content-Length":"0","Cache-Control":"no-store","X-Content-Type-Options":"nosniff"}})}async function OG($){if($ instanceof Blob)return{body:$,start:0,end:$.size-1,total:$.size,partial:!1,type:$.type,name:$.name,download:!1,status:200,extraHeaders:{}};if(KG($))return{body:$.body,start:$.start,end:$.end,total:$.total,partial:$.partial,type:$.type,name:$.name,download:$.download??!1,etag:$.etag,lastModified:$.lastModified,status:$.status??200,extraHeaders:$.headers??{}};let Z=$.file,j=Z instanceof Blob?Z:null,J=$.total??j?.size??-1;return{body:Z,start:$.start??0,end:$.end??J-1,total:J,partial:$.partial??!1,type:$.type??j?.type??"",name:$.name??Z?.name,download:$.download??!1,etag:$.etag,lastModified:$.lastModified,status:$.status??200,extraHeaders:$.headers??{}}}async function S8($,Z){if($ instanceof Response)return $;if(!$)return RJ();let j=await OG($),{body:J,start:W,end:Y,total:z,partial:X}=j;if(J instanceof Blob&&"exists"in J&&typeof J.exists==="function"){if(!await J.exists())return RJ()}let{range:G}=Z;if(G){if(z<=0)return fZ(Math.max(z,0));if(!X){if(J instanceof Blob){let K=H8(G,z);if(!K)return fZ(z);J=J.slice(K.start,K.end+1),W=K.start,Y=K.end,X=!0}}}let F=Boolean(G)&&X,Q=F?206:j.status,O=new Headers;if(O.set("Accept-Ranges","bytes"),O.set("Content-Type",j.type||"application/octet-stream"),O.set("X-Content-Type-Options","nosniff"),F)O.set("Content-Range",C8(W,Y,z)),O.set("Content-Length",String(Y-W+1));else if(z>=0)O.set("Content-Length",String(z));if(j.name)O.set("Content-Disposition",H3(j.name,j.download));if(j.etag)O.set("ETag",j.etag);if(j.lastModified)O.set("Last-Modified",j.lastModified.toUTCString());for(let[K,D]of Object.entries(j.extraHeaders))O.set(K,D);if((Z.method??"GET").toUpperCase()==="HEAD"){if(J&&"cancel"in J&&typeof J.cancel==="function")await J.cancel();return new Response(null,{status:Q,headers:O})}return new Response(J,{status:Q,headers:O})}class k$ extends y0{limit;constructor($){super("The request body is too large.",{status:413});this.limit=$}}var bJ={b:1,k:1024,kb:1024,m:1048576,mb:1048576,g:1073741824,gb:1073741824};function RZ($){if(typeof $==="number"){if(Number.isFinite($)&&$>=0)return Math.floor($);if($===1/0)return 1/0}else{let Z=$.trim().toLowerCase();if(Z==="none"||Z==="off")return 1/0;let j=/^(\d+(?:\.\d+)?)\s*([a-z]*)$/.exec(Z);if(j&&(j[2]===""||(j[2]in bJ)))return Math.floor(Number(j[1])*(bJ[j[2]]??1))}throw Error(`Invalid body limit ${JSON.stringify($)}. Use a byte count or a size such as "64kb", "1mb" or "none".`)}var EZ=new WeakMap;function wJ($){return EZ.has($)}function kJ($){return EZ.get($)?.limit??null}function yJ($){let Z=EZ.get($);return Z?Z.read>Z.limit:!1}function BG($){let Z=$.headers.get("Content-Length");if(Z===null||!/^\s*\d+\s*$/.test(Z))return null;return Number(Z)}function A8($,Z){let j=BG($);if(j!==null&&j>Z)throw new k$(Z)}function C3($,Z,j={}){let J=EZ.get($);if(J)J.limit=Z;else{let W={limit:Z,read:0,stream:void 0,used:!1};EZ.set($,W),UG($,W)}if(j.checkDeclared!==!1)A8($,Z)}function DG($){return Reflect.get(Object.getPrototypeOf($),"body",$)??null}function x8($,Z){if(Z.stream!==void 0)return Z.stream;let j=DG($);if(!j)return Z.stream=null;let J;return Z.stream=new ReadableStream({async pull(W){J??=j.getReader();let{done:Y,value:z}=await J.read();if(Y){W.close();return}if(Z.read+=z.byteLength,Z.read>Z.limit){let X=new k$(Z.limit);W.error(X),J.cancel(X).catch(()=>{});return}W.enqueue(z)},cancel(W){return J?J.cancel(W):j.cancel(W)}},{highWaterMark:0}),Z.stream}async function w$($,Z){if(A8($,Z.limit),Z.used||Z.stream?.locked)throw TypeError("Body already used");Z.used=!0;let j=x8($,Z);if(!j)return new Uint8Array(0);let J=j.getReader(),W=[],Y=0;for(;;){let{done:G,value:F}=await J.read();if(G)break;W.push(F),Y+=F.byteLength}let z=new Uint8Array(Y),X=0;for(let G of W)z.set(G,X),X+=G.byteLength;return z}function vJ($){return $.headers.get("Content-Type")??""}function UG($,Z){let j=(J,W)=>Object.defineProperty($,J,{configurable:!0,...W});j("body",{get:()=>x8($,Z)}),j("bodyUsed",{get:()=>Z.used||Boolean(Z.stream?.locked)||Reflect.get(Object.getPrototypeOf($),"bodyUsed",$)}),j("bytes",{value:()=>w$($,Z)}),j("arrayBuffer",{value:async()=>{let J=await w$($,Z);return J.buffer.slice(J.byteOffset,J.byteOffset+J.byteLength)}}),j("text",{value:async()=>new TextDecoder().decode(await w$($,Z))}),j("json",{value:async()=>JSON.parse(new TextDecoder().decode(await w$($,Z)))}),j("blob",{value:async()=>new Blob([await w$($,Z)],{type:vJ($)})}),j("formData",{value:async()=>new Response(await w$($,Z),{headers:{"Content-Type":vJ($)}}).formData()}),j("clone",{value:()=>{A8($,Z.limit);let J=x8($,Z),W=null;if(J){let[Y,z]=J.tee();Z.stream=Y,W=z}return new Request($.url,{method:$.method,headers:$.headers,body:W,signal:$.signal,duplex:"half"})}})}function qJ($){return L3($)}class Z0{method;handler;methodName;__internal_brand="RouteHandler";middlewares=[];constructor($,Z,j){this.method=$;this.handler=Z;this.methodName=j;this.handler=Z,this.methodName=j,this.method=$}get source(){if(!qJ(this.handler)||typeof this.methodName!=="string")return;return{controller:this.handler,methodName:this.methodName}}__internal_use(){return{run:this.run.bind(this),middlewares:this.middlewares}}run($){if(qJ(this.handler)){let Z=new this.handler;return Z[this.methodName].bind(Z)()}return this.handler()}middleware($){return this.middlewares=K1($),this}}class mJ{url;headers;__internal_brand="ProxyHandler";middlewares=[];constructor($,Z){this.url=$;this.headers=Z}middleware($){return this.middlewares=K1($),this}async run(){let $=new S,Z=$.headers.toJSON();for(let j of gJ($.rawRequest))delete Z[j];try{return await fetch(this.url,{method:$.rawRequest.method,headers:{...Z,...this.headers},body:$.rawRequest.body})}catch(j){if(yJ($.rawRequest))throw new k$(kJ($.rawRequest));throw j}}}class pJ{constructor(...$){return new Z0(...$)}}class hJ extends Z0{__internal_brand="StreamHandler";async run($){let Z=C.getStore(),j=Z?.req?.rawRequest,J=f8(j?.headers.get("Range"));if(Z)Z.rangeRequest=J;try{let W=await super.run($);return await S8(W,{range:J,method:j?.method})}catch(W){if(W instanceof E8)return fZ(W.total);throw W}finally{if(Z)Z.rangeRequest=null}}}class cJ{constructor(...$){return new hJ(...$)}}class dJ{__internal_brand="ResourceRoutes";first;second;constructor($){this.first={get:new Z0("GET",$,"list"),post:new Z0("POST",$,"store")},this.second={get:new Z0("GET",$,"show"),put:new Z0("PUT",$,"update"),delete:new Z0("DELETE",$,"delete")}}middleware($){if($.list)this.first.get.middleware($.list);if($.store)this.first.post.middleware($.store);if($.show)this.second.get.middleware($.show);if($.update)this.second.put.middleware($.update);if($.delete)this.second.delete.middleware($.delete);return this}}class A0{static __brand="ApiRouter";routes={};middlewares=[];middleware($){}get($,Z){return new Z0("GET",$,Z)}post($,Z){return new Z0("POST",$,Z)}put($,Z){return new Z0("PUT",$,Z)}patch($,Z){return new Z0("PATCH",$,Z)}delete($,Z){return new Z0("DELETE",$,Z)}resource($){return new dJ($)}agent($){if($.kind!=="agent-controller")throw TypeError(`this.agent() takes an AgentController class, and got ${VG($)}.`);return TG($,this)}file($,Z){return new pJ("GET",$,Z)}stream($,Z){return new cJ("GET",$,Z)}proxy($,Z={}){return new mJ($,Z)}}function VG($){if(typeof $==="function"&&$.name)return $.name;return typeof $}function TG($,Z){let j={stream:new Z0("POST",$,"stream"),attach:new Z0("POST",$,"attach"),stop:new Z0("POST",$,"stop"),upload:new Z0("POST",$,"upload")};return class extends A0{static __internal_brand="AgentRoute";static controller=$;static handlers=j;constructor(){super();this.middlewares=[...Z?.middlewares??[]]}routes={"/":j.stream,"/attach":j.attach,"/stop":j.stop,"/files":j.upload};static middleware(W){if(W.stream)j.stream.middleware(W.stream);if(W.attach)j.attach.middleware(W.attach);if(W.stop)j.stop.middleware(W.stop);if(W.upload)j.upload.middleware(W.upload);return this}}}class R8{as;input;bind;__internal_brand="McpModelParam";constructor($,Z,j){this.as=$;this.input=Z;this.bind=j}}class b8{method;url;meta;__internal_brand="McpRoute";constructor($,Z,j){this.method=$;this.url=Z;this.meta=j}}class uJ{static __brand="McpRouter";routes={};scopes;param($){return new R8($.as,$.input,$.bind)}fromApiRoute($,Z,j){return new b8($,Z,j)}}function G0($,Z){return $.replace(/:([^/]+[*?]?)/g,(j,J)=>{let W=J.endsWith("?")||J.endsWith("*"),Y=W?J.slice(0,-1):J,z=Z[Y];if(z===void 0){if(W)return"";if(import.meta.env.DEV)throw Error(`Missing parameter: ${Y}`);console.error(`Missing parameter: ${Y} in URL: ${$}`)}return String(z)}).replace(/\/\//g,"/").replace(/\/$/,"")}class v8 extends y0{constructor($,Z=307){super("Redirect error");this.name="RedirectError",this.payload={api:{status:200,data:{},directive:{kind:"Redirect",path:$}},view:{status:Z,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:$}}}}}class O1{static to($,...Z){let[j={}]=Z,{search:J={},params:W={},permanent:Y,status:z}={params:{},status:307,permanent:!1,...j},X=new URLSearchParams(J).toString();throw new v8([G0($,W)||"/",X.toString()].filter(Boolean).join("?"),z??(Y?301:307))}static external($,Z=307){throw new v8($,Z)}}var lJ=Symbol.for("gemi.HttpResponse");class j${kind;body;status;headers;[lJ]=!0;constructor($,Z,j,J){this.kind=$;this.body=Z;this.status=j;this.headers=J}static json($,Z={}){let j=Z.status??200;return IG(j),new j$("json",$,j,new Headers(Z.headers))}static error($,Z,j={}){if(!Number.isInteger($)||$<400||$>599)throw RangeError(`HttpResponse.error: status must be an integer from 400 to 599, got ${$}.`);return j$.json({error:Z},{...j,status:$})}get ok(){return this.status>=200&&this.status<300}toResponse($,Z){let j=$,J=this.serialize(j);for(let W of Z)j.append("Set-Cookie",W);this.headers.forEach((W,Y)=>{if(Y.toLowerCase()!=="set-cookie")j.set(Y,W)});for(let W of this.headers.getSetCookie())j.append("Set-Cookie",W);if(this.status>=400&&!this.headers.has("Cache-Control"))j.set("Cache-Control","no-store");return new Response(J,{status:this.status,headers:j})}serialize($){switch(this.kind){case"json":return $.set("Content-Type","application/json"),JSON.stringify(this.body)??null}}}function IG($){if(!Number.isInteger($)||$<200||$>599)throw RangeError(`HttpResponse: status must be an integer from 200 to 599, got ${$}.`);if($===204||$===205||$===304)throw RangeError(`HttpResponse.json: a ${$} response has no body.`)}function y$($){return typeof $==="object"&&$!==null&&$[lJ]===!0}function MG($,Z,j={}){return j$.error($,Z,j)}class iJ{kind="redirect";viewPath="REDIRECT";middlewares=[];featureGates=[];handler;constructor($){if(!$)this.handler=()=>({});else if(typeof $==="function")this.handler=$;else{let[Z,j]=$;this.handler=(J)=>{return new Z()[j](J)}}}async run($,Z){let{destination:j,permanent:J=!1,status:W=307}=await this.handler($);if(!j)throw Error(`Redirect destination is required see ${Z}`);return O1.to(j,{permanent:J,status:W}),{}}middleware($){return this.middlewares=K1($),this}feature($){return this.featureGates=[...this.featureGates,$],this}}async function w8($,Z){if($ instanceof Response)return $;let j=$ instanceof Blob,J=j?$:$.file,W=j?$.name:$.name??$.file?.name,Y=(j?$.type:$.type??$.file?.type)||"",z=j?!1:$.download??!1,X=j?200:$.status??200;if(!j)for(let[G,F]of Object.entries($.headers??{}))Z.set(G,F);if(J instanceof Blob&&"exists"in J&&typeof J.exists==="function"){if(!await J.exists())return new Response("Not found",{status:404})}if(Z.set("Content-Type",Y||"application/octet-stream"),J instanceof Blob)Z.set("Content-Length",String(J.size));if(W)Z.set("Content-Disposition",H3(W,z));return new Response(J instanceof Blob?J.stream():J,{status:X,headers:Z})}class sJ{kind="file";viewPath="FILE";middlewares=[];featureGates=[];handler;constructor($){if(!$)this.handler=()=>null;else if(typeof $==="function")this.handler=$;else{let[Z,j]=$;this.handler=(J)=>{return new Z()[j](J)}}}async run($,Z){let j=await this.handler($);if(!j)throw Error(`File route handler must return a file see ${Z}`);return{FILE:j}}middleware($){return this.middlewares=K1($),this}feature($){return this.featureGates=[...this.featureGates,$],this}}function nJ($,Z){if(y$($))throw Error(`The handler of view "${Z}" returned an HttpResponse. HttpResponse is for api routes; a view handler returns its props.`);return $}class oJ{viewPath;middlewares=[];featureGates=[];staticOptions=null;handler;constructor($,Z){this.viewPath=$;if(!Z)this.handler=()=>({});else if(typeof Z==="function")this.handler=Z;else{let[j,J]=Z;this.handler=(W)=>{return new j()[J](W)}}}async run($,Z){let j=nJ(await this.handler($),this.viewPath);return{[this.viewPath]:{...j,breadcrumb:{label:j?.breadcrumb??"",href:Z}}}}middleware($){return this.middlewares=K1($),this}static($={}){return this.staticOptions={...$},this}feature($){return this.featureGates=[...this.featureGates,$],this}}class aJ{viewPath;children;middlewares=[];featureGates=[];alwaysRuns=!1;handler=()=>({});constructor($,Z,j){this.viewPath=$;if(typeof Z==="function")this.handler=Z,this.children=class extends B1{routes=j??{}};else if(Array.isArray(Z)){let[J,W]=Z;this.handler=(Y)=>{return new J()[W](Y)},this.children=class extends B1{routes=j??{}}}else this.children=class extends B1{routes=Z},this.handler=()=>({})}async run($,Z){let j=nJ(await this.handler($),this.viewPath);return{[this.viewPath]:{...j,breadcrumb:{label:j?.breadcrumb??"",href:Z}}}}alwaysRun(){return this.alwaysRuns=!0,this}middleware($){return this.middlewares=K1($),this}feature($){return this.featureGates=[...this.featureGates,$],this}}class B1{middlewares=[];featureGates=[];routes={};view($,Z){return new oJ($,Z)}file($){return new sJ($)}redirect($){return new iJ($)}layout($,Z,j){return new aJ($,Z,j)}}class F0{req;static runsOnRefusal=!1;config={};constructor($){this.req=$}run(...$){return{}}static configure($){let Z=this;return class extends Z{config=$}}}function PG($){return $}function NG(){return{aliases:{},global:[],bodyLimit:null}}var D1="redirect";function U1($,Z="/"){if(typeof $!=="string"||!$.startsWith("/"))return Z;if(/[\u0000-\u001f\u007f\\]/.test($)||$.startsWith("//"))return Z;try{let j=new URL($,"http://gemi.invalid");if(j.origin!=="http://gemi.invalid")return Z;let J=`${j.search}${j.hash}`.replaceAll("/","%2F"),W=`${j.pathname}${J}`.replaceAll(":","%3A");return W.startsWith("//")?Z:W}catch{return Z}}function q$($){let Z=$.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();return Z?Z==="https":new URL($.url).protocol==="https:"}function LG($,Z=!0){let j=new URL($.rawRequest.url),J=j.pathname.replace(/\.(json|og)$/,""),[,W,...Y]=J.split("/");if(T(o).supportedLocales.includes(W))J=`/${Y.join("/")}`;return Z?`${J}${j.search}`:J}function HG($,Z){let j=(J)=>J.replace(/\/+$/,"")||"/";return j($)===j(Z)}function _3($,Z){let j=Z||T(E).config.signInPath,J=/^[a-z][a-z\d+.-]*:/i.test(j);if(J?!/^https?:\/\//i.test(j):!j.startsWith("/"))throw Error(`\`auth.signInPath\` must be a path like "/auth/sign-in", or an http(s) URL for sign-in hosted elsewhere. Got "${j}". A route's own \`"auth:<path>"\` cannot carry a URL, because the alias parser splits it on the colon.`);let W=new URL(j,"http://gemi.invalid");if($?.kind==="view"){let Y=LG($,!J);if(J||!HG(new URL(Y,W).pathname,W.pathname))W.searchParams.set(D1,Y)}return J?W.href:`${W.pathname}${W.search}`}var v1="access_token";function k8($){return $?.cookies?.get("access_token")||$?.headers?.get("access_token")||null}async function S3($,Z){let j=k8(Z);if(!j)return null;return(await $.getSession(j,Z.headers.get("User-Agent")))?.user??null}class rJ extends F0{async run($){let Z=C.getStore(),j=Z.req;if(Z.user)return{};let J=await S3(T(E),j);if(!J)throw new J$({redirectTo:_3(j,$)});return Z.setUser(J),{}}}class tJ extends F0{async run(...$){let[Z="public",j="864000",...J]=$,W=`${Z}, max-age=${j}${J.length>0?", ":""}${J.join(", ")}`;if($.length===0)W="public, max-age=864000, stale-while-revalidate=300, stale-if-error=600";if($.length===1&&$[0]==="public")W="public, max-age=864000, stale-while-revalidate=300, stale-if-error=600";if($.length===1&&$[0]==="private")W="private, max-age=0, stale-while-revalidate=300, stale-if-error=600";if(this.req.rawRequest.method==="GET")this.req.ctx().setHeaders("Cache-Control",W);return{}}}var eJ={"Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Allow-Credentials":"true"};class $5 extends F0{static runsOnRefusal=!0;config={origins:{"":{"Access-Control-Allow-Methods":"GET, HEAD, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Allow-Credentials":"true"}}};run(){let $=this.req,Z=$.rawRequest.headers.get("Origin");if(Z&&this.config.origins[Z]){$.ctx().setHeaders("Access-Control-Allow-Origin",Z);let j={...eJ,...this.config.origins[Z]};for(let[J,W]of Object.entries(j))$.ctx().setHeaders(J,W)}else if(Z&&this.config.origins["*"]){$.ctx().setHeaders("Access-Control-Allow-Origin","*");let j={...eJ,...this.config.origins["*"]};delete j["Access-Control-Allow-Credentials"];for(let[J,W]of Object.entries(j))$.ctx().setHeaders(J,W)}return{}}}class e0{config;static token="ratelimiter";constructor($){this.config=$}get driver(){return this.config.driver}async consume($,Z={}){let j=Z.limit??this.config.limit,J=Z.window??this.config.window,W=Z.cost??1;if(Z5("window",J),Z5("limit",j),!Number.isFinite(W)||W<0)throw Error(`Rate limiter cost must be zero or greater, got ${W}`);return await this.config.driver.consume({key:$,limit:j,window:J*1000,cost:W})}}function Z5($,Z){if(!Number.isFinite(Z)||Z<=0)throw Error(`Rate limiter ${$} must be greater than zero, got ${Z}`)}class bZ extends y0{constructor($){super("Rate limit exceeded");let Z={"Content-Type":"application/json",...$?z5($):{}};this.payload={api:{status:429,data:{error:w1("rate_limit","Rate limit exceeded",429)},headers:Z},view:{error:{message:"Rate limit exceeded"},status:429,headers:Z}}}}class Y5 extends F0{async run($,Z){let j=CG();if(!j)return{};let J=await j.consume(this.key(),{limit:j5($)??this.config.limit,window:j5(Z)??this.config.window});if(this.config.headers!==!1){let W=this.req.ctx?.();if(W)for(let[Y,z]of Object.entries(z5(J)))W.setHeaders(Y,z)}if(!J.allowed)throw new bZ(J);return{}}key(){if(this.config.key)return this.config.key(this.req);let $=J5(this.req.rawRequest);if($)return`mcp:${$.via}:${$.id}:${this.req.routePath??"*"}`;return`${g$(this.req)}:${this.req.routePath??"*"}`}}function CG(){try{let $=T();return $.bound(e0)?$.make(e0):null}catch{return null}}function g$($){let Z=W5($.rawRequest);if(Z!==void 0)return Z;let j=$.headers.get("x-forwarded-for");if(j){let[J]=j.split(",");if(J?.trim())return J.trim()}return $.headers.get("x-real-ip")?.trim()||"unknown"}function z5($){let Z={"X-RateLimit-Limit":String($.limit),"X-RateLimit-Remaining":String($.remaining),"X-RateLimit-Reset":String(Math.ceil($.resetAt/1000))};if(!$.allowed)Z["Retry-After"]=String(Math.max(1,Math.ceil($.retryAfter/1000)));return Z}function j5($){if($===void 0||$===null||$==="")return;let Z=Number($);if(!Number.isFinite(Z)||Z<=0)return;return Z}class G5 extends F0{async run(){let $=this.req.cookies.get("csrf_token");if(!$)throw new y8;if(!["POST","PUT","PATCH","DELETE"].includes(this.req.rawRequest.method))return{};if(!Bun.CSRF.verify($,{secret:process.env.SECRET}))throw new y8;return{}}}class y8 extends y0{constructor(){super("Invalid CSRF token");this.name="InvalidCSRFTokenError"}payload={api:{status:403,data:{error:X5("csrf","Invalid CSRF token",403)}},view:{}}}class x3 extends F0{run($){let Z=$??this.config.limit;if(Z===void 0||Z==="")throw Error('`body-limit` needs a size, as in "body-limit:64kb".');return C3(this.req.rawRequest,RZ(Z)),{}}}class F5{policiesList={};constructor(){let $=this.register();for(let Z of $){let j=new Z;this.policiesList[Z.name]=j}}register(){return[]}}class Q5{all($,Z){return!0}}class q8{options;param;refuse;answers=new WeakMap;constructor($){this.options=$;this.param=$.param,this.refuse=$.refuse??"not_found"}refusal(){return this.refuse==="forbidden"?new m$:new A3}authorize($,Z){if(typeof Z==="number"&&Number.isFinite(Z))Z=String(Z);if(typeof Z!=="string"||Z==="")return Promise.reject(this.refusal());let j=this.answers.get($.rawRequest);if(!j)j=new Map,this.answers.set($.rawRequest,j);let J=j.get(Z);if(!J)J=this.decide($,Z),j.set(Z,J);return J}async allows($,Z){try{return await this.authorize($,Z),!0}catch(j){if(this.isRefusal(j))return!1;throw j}}fromRoute($=new S,Z=this.param){if(Z===void 0)throw Error('This resource policy has no `param`. Give `defineResourcePolicy` one, or name it: `fromRoute(req, "pageId")`, or `alias:pageId` on the middleware.');return this.authorize($,$.params?.[Z])}get middleware(){if(!this.middlewareClass){let $=(Z,j)=>this.fromRoute(Z,j||void 0);this.middlewareClass=class extends F0{async run(j){await $(this.req,j)}}}return this.middlewareClass}middlewareClass;forAgent($){return{authorize:async(Z,{threadId:j,body:J})=>{let W;if(j!==void 0){if(W=$.thread?await $.thread(j,Z):null,W===null||W===void 0)throw this.refusal()}if(J!==void 0){let Y=await $.body(J,Z);if(await this.authorize(Z,Y),j!==void 0&&String(W)!==String(Y))throw this.refusal();return}if(j!==void 0)await this.authorize(Z,W)}}}async decide($,Z){let j=await this.options.load(Z,$);if(j===null||j===void 0||!await this.options.allow(j,$))throw this.refusal();return j}isRefusal($){return this.refuse==="forbidden"?$ instanceof m$:$ instanceof A3}}function _G($){return new q8($)}async function E3($,Z,j=!1){if(!$.body)return new Uint8Array;let[J,W]=await mG($.body),z=J.length>=2&&J[0]===31&&J[1]===139?W.pipeThrough(new DecompressionStream("gzip")):W;return gG(z,Z,j,$.url)}async function gG($,Z,j,J){let W=$.getReader(),Y=[],z=0;try{for(;;){let{done:F,value:Q}=await W.read();if(F)break;if(z+Q.byteLength>Z){if(!j)throw new f3(J,Z);Y.push(Q.subarray(0,Z-z)),z=Z;break}Y.push(Q),z+=Q.byteLength}}finally{W.cancel().catch(()=>{})}let X=new Uint8Array(z),G=0;for(let F of Y)X.set(F,G),G+=F.byteLength;return X}async function mG($){let Z=$.getReader(),j=await Z.read(),J=j.done?new Uint8Array:j.value,W=new ReadableStream({start(Y){if(j.done)Y.close();else Y.enqueue(J)},async pull(Y){let z=await Z.read();if(z.done)Y.close();else Y.enqueue(z.value)},cancel(Y){return Z.cancel(Y)}});return[J,W]}function R3($){return new TextDecoder("utf-8").decode($)}var pG={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;"};function W$($){return $.replace(/[&<>"']/g,(Z)=>pG[Z])}var hG={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function g8($){if(!$.includes("&"))return $;return $.replace(/&(#x[0-9a-fA-F]{1,6}|#[0-9]{1,7}|[a-zA-Z]{2,4});/g,(Z,j)=>{if(j[0]!=="#")return hG[j]??Z;let J=j[1]==="x"?parseInt(j.slice(2),16):parseInt(j.slice(1),10);return J>0&&J<=1114111?String.fromCodePoint(J):Z})}function m8($){let Z=$.indexOf(":");return(Z===-1?$:$.slice(Z+1)).toLowerCase()}function K5($,Z){let j=$.length,J=0;while(J<j){if(Z.stopped?.())return;let W=$.indexOf("<",J);if(W===-1){Z.text(g8($.slice(J)));return}if(W>J)Z.text(g8($.slice(J,W)));if($.startsWith("<!--",W)){let Y=$.indexOf("-->",W+4);if(Y===-1)return;J=Y+3}else if($.startsWith("<![CDATA[",W)){let Y=$.indexOf("]]>",W+9);if(Y===-1)return;Z.text($.slice(W+9,Y)),J=Y+3}else if($.startsWith("<?",W)){let Y=$.indexOf("?>",W+2);if(Y===-1)return;J=Y+2}else if($.startsWith("<!",W)){let Y=$.indexOf(">",W+2);if(Y===-1)return;let z=$.indexOf("[",W+2);if(z!==-1&&z<Y){let X=$.indexOf("]",z+1);if(X===-1)return;let G=$.indexOf(">",X+1);if(G===-1)return;J=G+1}else J=Y+1}else if($[W+1]==="/"){let Y=$.indexOf(">",W+2);if(Y===-1)return;Z.close(m8($.slice(W+2,Y).trim())),J=Y+1}else{let Y=cG($,W+1);if(Y===-1)return;let z=$.slice(W+1,Y),X=z.endsWith("/");if(X)z=z.slice(0,-1);let G=z.search(/[\s]|$/),F=m8(z.slice(0,G));if(F){if(Z.open(F,dG(z.slice(G)),X),X)Z.close(F)}J=Y+1}}}function cG($,Z){let j=null;for(let J=Z;J<$.length;J++){let W=$[J];if(j){if(W===j)j=null}else if(W==='"'||W==="'")j=W;else if(W===">")return J}return-1}function dG($){let Z={},j=/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;for(let J of $.matchAll(j))Z[m8(J[1])]=g8(J[2]??J[3]??"");return Z}class j0 extends Error{url;status;constructor($,Z=null,j=null){super($);this.url=Z;this.status=j;this.name="SitemapError"}}var V5="http://www.sitemaps.org/schemas/sitemap/0.9",uG="http://www.w3.org/1999/xhtml",c8=`<?xml version="1.0" encoding="UTF-8"?>
3
3
  `,O5=`<urlset xmlns="${V5}" xmlns:xhtml="${uG}">
4
4
  `,B5=`</urlset>
5
5
  `,Y$=50000,vZ=52428800,D5=2048,lG=new Set(["always","hourly","daily","weekly","monthly","yearly","never"]),iG=/^\d{4}(-\d{2}(-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2}))?)?)?$/,sG="application/xml; charset=utf-8",U5=new TextEncoder;function d8($,Z){let j;try{j=new URL($)}catch{throw new j0(`Sitemap: ${Z} "${$}" is not an absolute URL.`)}if(j.protocol!=="http:"&&j.protocol!=="https:")throw new j0(`Sitemap: ${Z} "${$}" is not an http(s) URL.`);let J=j.href;if(J.length>D5)throw new j0(`Sitemap: ${Z} is over ${D5} characters: "${J.slice(0,80)}\u2026".`);return J}function T5($,Z){if($ instanceof Date){if(Number.isNaN($.getTime()))throw new j0(`Sitemap: lastmod of ${Z} is an invalid Date.`);return $.toISOString()}if(!iG.test($))throw new j0(`Sitemap: lastmod "${$}" of ${Z} is not a W3C datetime (e.g. "2026-10-07" or "2026-10-07T12:00:00Z").`);return $}function nG($){let Z=d8($.loc,"loc"),j=`<url><loc>${W$(Z)}</loc>`;if($.lastmod!=null)j+=`<lastmod>${W$(T5($.lastmod,Z))}</lastmod>`;if($.changefreq!=null){if(!lG.has($.changefreq))throw new j0(`Sitemap: changefreq "${$.changefreq}" of ${Z} is not one the protocol knows.`);j+=`<changefreq>${$.changefreq}</changefreq>`}if($.priority!=null){let J=$.priority;if(!Number.isFinite(J)||J<0||J>1)throw new j0(`Sitemap: priority ${J} of ${Z} is not between 0 and 1.`);j+=`<priority>${Number(J.toFixed(4))}</priority>`}for(let J of $.alternates??[]){let W=J.hrefLang?.trim();if(!W)throw new j0(`Sitemap: an alternate of ${Z} has no hrefLang.`);let Y=d8(J.href,`alternate href of ${Z}`);j+=`<xhtml:link rel="alternate" hreflang="${W$(W)}" href="${W$(Y)}"/>`}return`${j}</url>
@@ -10,7 +10,7 @@ ${Z}</sitemapindex>
10
10
  `)));return C5(G,{url:Y.url})}function u8($){return $===void 0?[]:typeof $==="string"?[$]:$}function b3($,Z){if(/[\r\n]/.test(Z))throw TypeError(`Robots: the ${$} value ${JSON.stringify(Z)} has a line break in it.`);return`${$}: ${Z}
11
11
  `}function _5($){let Z=[];for(let J of $.rules??[]){let W=u8(J.userAgent);if(W.length===0)throw TypeError("Robots: a rule needs at least one userAgent.");let Y=W.map((X)=>b3("User-agent",X)).join(""),z=[...u8(J.allow).map((X)=>["Allow",X]),...u8(J.disallow).map((X)=>["Disallow",X])];for(let[X,G]of z){if(!G.startsWith("/")&&!G.startsWith("*"))throw TypeError(`Robots: ${X} "${G}" must start with "/" or "*".`);Y+=b3(X,G)}if(z.length===0)Y+=`Disallow:
12
12
  `;if(J.crawlDelay!==void 0){if(!Number.isFinite(J.crawlDelay)||J.crawlDelay<0)throw TypeError(`Robots: crawlDelay ${J.crawlDelay} is not a number of seconds.`);Y+=b3("Crawl-delay",String(J.crawlDelay))}Z.push(Y)}let j=($.sitemaps??[]).map((J)=>{let W;try{W=new URL(J)}catch{throw TypeError(`Robots: sitemap "${J}" is not an absolute URL.`)}return b3("Sitemap",W.href)});if(j.length>0)Z.push(j.join(""));return Z.join(`
13
- `)}function WF($,Z={}){let j=new Headers(Z.headers);if(!j.has("content-type"))j.set("content-type","text/plain; charset=utf-8");return new Response(_5($),{status:200,headers:j})}var S5={response:WF,text:_5,parse:C5,fetch:JF};import{createHmac as x5,randomBytes as YF}from"crypto";var i8="v2.";function s8($){return $.startsWith(i8)}function c$(){let $=process.env.SECRET;if(!$)throw Error("Signing in needs a secret to mint session tokens with. Set SECRET in the environment.");return $}function A5($){let Z=YF(16).toString("hex"),j=x5("sha256",c$()).update(`${$}:${Z}`).digest("hex");return`${i8}${j}`}function v3($,Z){let j=x5("sha256",c$()).update(`legacy-session:${Z}:${$}`).digest("hex");return`${i8}${j}`}import{createHash as GF,createHmac as FF,randomInt as QF,timingSafeEqual as R5}from"crypto";function f5($,Z){return Math.floor($/Z)*Z}function zF($,Z){if(Z<=0)return 0;return Math.min(1,Math.max(0,(Z-$)/Z))}function n8($,Z,j,J){return Z*zF(j,J)+$}function XF($){let{current:Z,previous:j,elapsed:J,window:W,limit:Y,cost:z}=$,X=Y-z;if(X<0)return W;let G=Math.max(0,W-J);if(j>0){let Q=W*(1-(X-Z)/j);if(Q<=W)return Math.max(0,Math.ceil(Q-J))}if(Z<=X)return G;if(Z<=0)return G;let F=W*(1-X/Z);return G+Math.max(0,Math.ceil(F))}function E5($){let{allowed:Z,current:j,previous:J,now:W,elapsed:Y,window:z,limit:X,cost:G}=$;if(Z){let Q=n8(j,J,Y,z);return{allowed:!0,limit:X,remaining:Math.max(0,Math.floor(X-Q)),resetAt:W-Y+z,retryAfter:0}}let F=XF({current:j,previous:J,elapsed:Y,window:z,limit:X,cost:G});return{allowed:!1,limit:X,remaining:0,resetAt:W+F,retryAfter:F}}class o8{}class a8 extends o8{buckets=new Map;maxKeys;constructor($={}){super();this.maxKeys=Math.max(1,$.maxKeys??1e5)}consume($){let{key:Z,limit:j,window:J}=$,W=$.cost??1,Y=Date.now(),z=f5(Y,J),X=Y-z,G=this.roll(Z,J,z);G.limit=j;let Q=n8(G.current,G.previous,X,J)+W<=j;if(Q)G.current+=W;if(this.buckets.delete(Z),this.buckets.set(Z,G),this.buckets.size>this.maxKeys)this.evict(Y);return E5({allowed:Q,current:G.current,previous:G.previous,now:Y,elapsed:X,window:J,limit:j,cost:W})}clear(){this.buckets.clear()}get size(){return this.buckets.size}roll($,Z,j){let J=this.buckets.get($);if(!J||J.window!==Z)return{window:Z,limit:0,windowStart:j,current:0,previous:0};if(J.windowStart===j)return J;if(J.windowStart+Z===j)return J.previous=J.current,J.current=0,J.windowStart=j,J;return J.previous=0,J.current=0,J.windowStart=j,J}evict($){for(let[J,W]of this.buckets)if($-W.windowStart>=W.window*2)this.buckets.delete(J);let Z=this.maxKeys-Math.floor(this.maxKeys/10);if(this.buckets.size<=Z)return;let j=[...this.buckets].map(([J,W],Y)=>({key:J,order:Y,spent:W.limit>0?(W.current+W.previous)/W.limit:0}));j.sort((J,W)=>J.spent-W.spent||J.order-W.order);for(let{key:J}of j){if(this.buckets.size<=Z)break;this.buckets.delete(J)}}}var w5="h1.";function w3($,Z,j){let J=FF("sha256",c$()).update(`gemi:one-time:${$}:${Z}:${j}`).digest("hex");return`${w5}${J}`}function kZ($,Z,j,J){let W=typeof J==="string"?J:"",Y=typeof j==="string"?j:"",z=Y.startsWith(w5),X=w3($,Z,W),G=Buffer.from(z?X:W),F=Buffer.from(Y);if(G.length!==F.length||W===""||Y==="")return R5(G,G),!1;return R5(G,F)}function k5($){let Z="";for(let j=0;j<$;j++)Z+=String(QF(0,10));return Z}var q5=320;function qZ($){if(typeof $!=="string")return null;let Z=$.trim();if(Z===""||Z.length>q5)return null;return Z.toLowerCase()}function k3($){if(typeof $!=="string")return null;let Z=$.trim();if(Z.length>q5)return null;let j=Z.toLowerCase();if(j.length<3||j.length>254||!/^[^\s@]+@[^\s@]+$/.test(j))return null;return j}var b5=null;function y5(){try{let $=T();if(typeof $?.bound==="function"&&$.bound(e0))return $.make(e0)}catch{}return b5??=new e0({driver:new a8,limit:1000,window:60}),b5}function v5($){return $.length<=64?$:`sha256:${GF("sha256").update($).digest("hex")}`}async function d$($,Z,j,J){let W=y5(),Y=[[`auth:code-${$}:ip:${v5(g$(j))}`,J.perIp]];if(Z!==null)Y.push([`auth:code-${$}:email:${v5(Z)}`,J.perEmail]);for(let[z,X]of Y){if(!X)continue;let[G,F]=X,Q=await W.consume(z,{limit:G,window:F});if(!Q.allowed)throw new bZ(Q)}}async function g5($,Z,j,J=10){let W=Math.max(86400,Math.ceil(J*60*(j+1)));return(await y5().consume(`auth:code-attempt:${$}:${Z}`,{limit:j,window:W})).allowed}import{randomBytes as t8}from"crypto";class r8 extends S{schema={name:{string:"Invalid name",required:"Name is required","min:2":"Name must be at least 3 characters"},email:{string:"Invalid email",required:"Email is required",email:"Invalid email"},password:{"min:8":"Password must be at least 9 characters"}}}function q3($,Z,j,J=1/0){if(!Number.isInteger(Z)||Z<j||Z>J){let W=J===1/0?`an integer of at least ${j}`:`an integer from ${j} to ${J}`;throw Error(`auth.emailCode.${$} must be ${W}, got ${Z}`)}}function e8($={}){let Z=$.length??6,j=$.expiresInMinutes??10,J=$.linkExpiresInMinutes??10080,W=$.maxAttempts??5;return q3("length",Z,4,12),q3("expiresInMinutes",j,1),q3("linkExpiresInMinutes",J,1),q3("maxAttempts",W,1),{enabled:$.enabled??!1,createUser:$.createUser??!1,length:Z,expiresInMinutes:j,linkExpiresInMinutes:J,maxAttempts:W,requestLimit:{perEmail:$.requestLimit?.perEmail??[5,900],perIp:$.requestLimit?.perIp??[20,900]},verifyLimit:{perEmail:$.verifyLimit?.perEmail??[10,900],perIp:$.verifyLimit?.perIp??[50,900]},uniformMagicLinkResponse:$.uniformMagicLinkResponse??!1,send:$.send??(({email:Y,code:z})=>{if(Bun.env.NODE_ENV!=="production")console.info(`[gemi] email code for ${Y}: ${z} (set auth.emailCode.send to deliver it)`)})}}async function KF($,Z){if(typeof Z!=="string"||Z==="")return!1;try{return await Bun.password.verify($,Z)}catch{return!1}}function FV($){return $}function m5($={}){return{basePath:"/auth",verifyEmail:!0,redirectPath:"/dashboard",signInPath:"/auth/sign-in",sessionExpiresInHours:24,sessionAbsoluteExpiresInHours:672,cookieDomain:null,migrateLegacySession:null,signUpRequest:r8,oauthProviders:{},oauthFailurePath:null,connections:{},connectionStore:null,onConnected:()=>{},verifyPassword:KF,hashPassword:async(Z)=>await Bun.password.hash(Z),generateForgotPasswordToken:async()=>t8(32).toString("hex"),generateEmailVerificationToken:()=>{if(!($.verifyEmail??!0))return"";return t8(32).toString("hex")},generateMagicLinkToken:()=>t8(32).toString("hex"),extendSession:()=>({}),onUserCreated:async()=>{},onSignUp:()=>{},onSignIn:()=>{},onSignOut:()=>{},onForgotPassword:()=>{},onResetPassword:()=>{},onMagicLinkCreated:()=>{},emailCode:e8($.emailCode),generateCode:()=>{return},onAuthenticated:()=>{}}}function $j($){if($&&typeof $==="object")delete $.password;return $}function OF(){return new Proxy({},{get:($,Z)=>h5(Z)})}var p5=new WeakMap;function c5($){if($&&typeof $==="object"){for(let Z of Object.values($))c5(Z);Object.freeze($)}return $}var BF={select:{id:!0,publicId:!0,email:!0,name:!0,locale:!0,globalRole:!0,accounts:{select:{id:!0,publicId:!0,organizationRole:!0,organization:!0}}}},DF=c5({token:!0,expiresAt:!0,absoluteExpiresAt:!0,updatedAt:!0,location:!0,userAgent:!0,user:BF});class Zj{models;constructor($=OF()){this.models=$}run($){return this.models.User.asSystem($)}sessionSelect(){return DF}transaction($){return this.models.User.transaction($)}withLegacySessionLock($,Z){let j=this.models.User.$connection??z$(),J=T(X$).connection(j),W=()=>this.transaction(async()=>{if(J.dialect==="postgres"){let X=`gemi:legacy-session:${$}`;await V1()`SELECT pg_advisory_xact_lock(hashtextextended(${X}, 0))`}return Z()});if(J.dialect!=="sqlite"||V1())return W();let z=(p5.get(J)??Promise.resolve()).then(W,W);return p5.set(J,z.catch(()=>{})),z}async createUser($){let Z=await this.run(()=>this.models.User.create({data:$}));return $j(Z)}async updateUserPassword($){let Z=await this.run(()=>this.models.User.update({where:{id:$.id},data:{password:$.password}}));return $j(Z)}async findUserByEmailAddress($,Z){return await this.run(()=>this.models.User.findUnique({where:Z?{email:$,emailVerifiedAt:{not:null}}:{email:$}}))}async findUserByVerificationToken($){if(typeof $!=="string"||$==="")return null;return await this.run(()=>this.models.User.findFirst({where:{verificationToken:$}}))}async verifyUser($){return await this.run(()=>this.models.User.update({where:{email:$},data:{emailVerifiedAt:new Date}}))}async createSession($){return await this.run(()=>this.models.Session.create({data:$,include:{user:!0}}))}async createSessionV2($){return await this.run(()=>this.models.Session.create({data:$,select:this.sessionSelect()}))}async findSession($){if(!$.token)return null;try{return await this.run(()=>this.models.Session.findUnique({where:{token:$.token},select:this.sessionSelect()}))}catch(Z){return console.error("findSession failed:",Z),null}}async updateSession($){return await this.run(()=>this.models.Session.update({where:{token:$.token},data:{expiresAt:$.expiresAt},select:this.sessionSelect()}))}async deleteSession($){if(!$.token)return;await this.run(()=>this.models.Session.deleteMany({where:{token:$.token}}))}async claimLegacySession($){if(!$.token)return!1;let{count:Z}=await this.run(()=>this.models.Session.deleteMany({where:{token:$.token}}));return Z>0}async deleteAllUserSessions($){await this.run(()=>this.models.Session.deleteMany({where:{userId:$}}))}async createPasswordResetToken($){return await this.run(()=>this.models.PasswordResetToken.create({data:{token:$.token,user:{connect:{id:$.user.id}}}}))}async findPasswordResetToken($){if(typeof $.token!=="string"||$.token==="")return null;return await this.run(()=>this.models.PasswordResetToken.findUnique({where:{token:$.token},include:{user:!0}}))}async deletePasswordResetToken($){return await this.run(()=>this.models.PasswordResetToken.delete({where:{token:$.token}}))}async findInvitation($,Z){if(typeof $!=="string"||typeof Z!=="string")return null;return await this.run(()=>this.models.OrganizationInvitation.findFirst({where:{publicId:$,email:Z}}))}async deleteInvitationById($){await this.run(()=>this.models.OrganizationInvitation.delete({where:{publicId:$}}))}async createAccount($){return await this.run(()=>this.models.Account.create({data:{userId:$.userId,organizationId:$.organizationId,organizationRole:$.organizationRole}}))}async createMagicLinkToken($){return await this.run(()=>this.models.MagicLinkToken.create({data:{email:$.email,token:$.token,pin:$.pin}}))}async findUserMagicLinkToken($){let Z=(j)=>typeof j==="string"&&j!=="";if(!Z($.email))return null;if($.token!==void 0&&!Z($.token))return null;if($.token===void 0&&!Z($.pin))return null;return await this.run(()=>$.token?this.models.MagicLinkToken.findUnique({where:{token_email:{token:$.token,email:$.email}}}):this.models.MagicLinkToken.findUnique({where:{pin_email:{pin:$.pin,email:$.email}}}))}async findMagicLinkTokenByEmail($){return await this.run(()=>this.models.MagicLinkToken.findFirst({where:{email:$},orderBy:{id:"desc"}}))}async claimMagicLinkToken($){let{count:Z}=await this.run(()=>this.models.MagicLinkToken.deleteMany({where:{id:$}}));return Z===1}async deleteMagicLinkToken($){await this.run(()=>this.models.MagicLinkToken.deleteMany({where:{email:$}}))}async createSocialAccount($){return await this.run(()=>this.models.SocialAccount.create({data:$}))}async findUserBySocialAccount($,Z){if(!Z)return null;let j=await this.run(()=>this.models.SocialAccount.findFirst({where:{provider:$,providerId:Z},include:{user:!0}}));return j?$j(j.user):null}async findSocialAccounts($,Z){return await this.run(()=>this.models.SocialAccount.findMany({where:{userId:$,provider:Z},orderBy:{id:"asc"}}))}async claimSocialAccount($,Z){let{count:j}=await this.run(()=>this.models.SocialAccount.updateMany({where:{id:$.id,providerId:$.providerId},data:{providerId:Z}}));return j===1}}import{randomBytes as WO}from"crypto";function f0($,Z,j,J,W){return p0(Z,WW($,Z),j,J,W)}function p0($,Z,j,J,W,Y){let z=zj(Z,j,J);if(W&&Z!==z)throw RangeError(h9($,Z,j,J,Y));return z}function WW($,Z){let j=$[Z];if(j===void 0)throw TypeError(k2(Z));return j}function K0($){return $!==null&&/object|function/.test(typeof $)}function b0($,Z=Map){let j=new Z;return(J,...W)=>{if(j.has(J))return j.get(J);let Y=$(J,...W);return j.set(J,Y),Y}}function Dj($){return K$({name:$},1)}function K$($,Z){return u0((j)=>({value:j,configurable:1,writable:!Z}),$)}function YW($){return u0((Z)=>({get:Z,configurable:1}),$)}function t3($){return{[Symbol.toStringTag]:{value:$,configurable:1}}}function a$($,Z){let j={},J=$.length;for(let W of Z)j[$[--J]]=W;return j}function u0($,Z,j){let J={};for(let W in Z)J[W]=$(Z[W],W,j);return J}function lZ($,Z,j){let J={};for(let W=0;W<Z.length;W++){let Y=Z[W];J[Y]=$(Y,W,j)}return J}function UF($,Z,j){let J={};for(let W=0;W<$.length;W++)J[Z[W]]=j[$[W]];return J}function w0($,Z){let j={};for(let J of $)j[J]=Z[J];return j}function Uj($,Z){let j={};for(let J in Z)$.has(J)||(j[J]=Z[J]);return j}function Vj($){$={...$};let Z=Object.keys($);for(let j of Z)$[j]===void 0&&delete $[j];return $}function zW($,Z){for(let j of Z)if(!(j in $))return 0;return 1}function XW($,Z,j){for(let J of $)if(Z[J]!==j[J])return 0;return 1}function GW($,Z,j){let J={...j};for(let W=0;W<Z;W++)J[$[W]]=0;return J}function b($,...Z){return(...j)=>$(...Z,...j)}function d5($){return $[0].toUpperCase()+$.substring(1)}function iZ($){return $.slice().sort()}function d3($,Z){return String(Z).padStart($,"0")}function k1($,Z){return Math.sign($-Z)}function zj($,Z,j){return Math.min(Math.max($,Z),j)}function I1($,Z){return[Math.floor($/Z),gZ($,Z)]}function gZ($,Z){return($%Z+Z)%Z}function g1($,Z){return[e3($,Z),Tj($,Z)]}function e3($,Z){return Math.trunc($/Z)||0}function Tj($,Z){return $%Z||0}function y3($){return Math.abs($%1)===0.5}function FW($,Z,j){let J=0,W=0;for(let X=0;X<=Z;X++){let G=$[j[X]],F=Z1[X],Q=m/F,[O,K]=g1(G,Q);J+=K*F,W+=O}let[Y,z]=g1(J,m);return[W+Y,z]}function $6($,Z,j){let J={};for(let W=Z;W>=0;W--){let Y=Z1[W];J[j[W]]=e3($,Y),$=Tj($,Y)}return J}function QW($){return $===v?w6:[]}function KW($){return $===v?j3:[]}function OW($){return $===v?["year","day"]:[]}function BW($){if($!==void 0)return a($)}function DW($){if($!==void 0)return l0($)}function Ij($){if($!==void 0)return sZ($)}function l0($){return TW(sZ($))}function sZ($){return VW(zQ($))}function Mj($){if($==null)throw TypeError("Cannot be null or undefined");return $}function UW($,Z){if(Z==null)throw RangeError(k2($));return Z}function P1($){if(!K0($))throw TypeError(p9);return $}function Z6($,Z,j=$){if(typeof Z!==$)throw TypeError(eZ(j,Z));return Z}function VW($,Z="number"){if(!Number.isInteger($))throw RangeError(RF(Z,$));return $||0}function TW($,Z="number"){if($<=0)throw RangeError(bF(Z,$));return $}function Pj($){if(typeof $=="symbol")throw TypeError(qF);return String($)}function u3($,Z){return K0($)?String($):a($,Z)}function j6($){if(typeof $=="string")return BigInt($);if(typeof $!="bigint")throw TypeError(kF($));return $}function IW($,Z="number"){if(typeof $=="bigint")throw TypeError(wF(Z));if($=Number($),!Number.isFinite($))throw RangeError(vF(Z,$));return $}function P0($,Z){return Math.trunc(IW($,Z))||0}function MW($,Z){return VW(IW($,Z),Z)}function u5($,Z){return TW(P0($,Z),Z)}function Nj($,Z){let[j,J]=g1(Z,m),W=$+j,Y=Math.sign(W);return Y&&Y===-Math.sign(J)&&(W-=Y,J+=Y*m),[W,J]}function l$($,Z,j=1){return Nj($[0]+Z[0]*j,$[1]+Z[1]*j)}function i$($,Z){return Nj($[0],$[1]+Z)}function y0($,Z){return l$(Z,$,-1)}function L0($,Z){return k1($[0],Z[0])||k1($[1],Z[1])}function PW($,Z,j){return L0($,Z)===-1||L0($,j)===1}function J6($,Z=1){let j=BigInt(m/Z);return[Number($/j),Number($%j)*Z]}function s$($,Z=1){let j=m/Z,[J,W]=g1($,j);return[J,W*Z]}function NW($,Z=1){let[j,J]=$,W=Math.floor(J/Z),Y=m/Z;return BigInt(j)*BigInt(Y)+BigInt(W)}function g0($,Z=1,j){let[J,W]=$,[Y,z]=g1(W,Z);return J*(m/Z)+(Y+(j?z/Z:0))}function Lj($,Z,j=I1){let[J,W]=$,[Y,z]=j(W,Z);return[J*(m/Z)+Y,z]}function Hj($,Z){let j=$.formatToParts(Z),J={};for(let W of j)J[W.type]=W.value;return J}function Cj($){return f0($,"isoYear",uZ,dZ,1),$.isoYear===uZ?f0($,"isoMonth",4,12,1):$.isoYear===dZ&&f0($,"isoMonth",1,9,1),$}function q1($){return N1({...$,...d0,isoHour:12}),$}function N1($){let Z=f0($,"isoYear",uZ,dZ,1),j=Z===uZ?1:Z===dZ?-1:0;return j&&m0(N0({...$,isoDay:$.isoDay+j,isoNanosecond:$.isoNanosecond-j})),$}function m0($){if(!$||PW($,BQ,OQ))throw RangeError(E6);return $}function m1($){return FW($,5,o0)[1]}function W6($){let[Z,j]=I1($,m);return[$6(j,5,o0),Z]}function LW($){return HW($)[0]}function HW($){return Lj($,c0)}function H0($){return r$($.isoYear,$.isoMonth,$.isoDay,$.isoHour,$.isoMinute,$.isoSecond,$.isoMillisecond)}function N0($){let Z=H0($);if(Z!==void 0){let[j,J]=g1(Z,R0);return[j,J*j1+($.isoMicrosecond||0)*P$+($.isoNanosecond||0)]}}function _j($,Z){let[j,J]=W6(m1($)-Z);return m0(N0({...$,isoDay:$.isoDay+J,...j}))}function l3(...$){return r$(...$)/t9}function r$(...$){let[Z,j]=CW(...$),J=Z.valueOf();if(!isNaN(J))return J-j*R0}function CW($,Z=1,j=1,J=0,W=0,Y=0,z=0){let X=$===uZ?1:$===dZ?-1:0,G=new Date;return G.setUTCHours(J,W,Y,z),G.setUTCFullYear($,Z-1,j+X),[G,X]}function h1($,Z){let[j,J]=i$($,Z);J<0&&(J+=m,j-=1);let[W,Y]=I1(J,j1),[z,X]=I1(Y,P$);return Y6(j*R0+W,z,X)}function Y6($,Z=0,j=0){let J=Math.ceil(Math.max(0,Math.abs($)-KQ)/R0)*Math.sign($),W=new Date($-J*R0);return a$(q6,[W.getUTCFullYear(),W.getUTCMonth()+1,W.getUTCDate()+J,W.getUTCHours(),W.getUTCMinutes(),W.getUTCSeconds(),W.getUTCMilliseconds(),Z,j])}function _W($){return[$.isoYear,$.isoMonth,$.isoDay]}function SW(){return T1}function Sj($,Z){switch(Z){case 2:return xj($)?29:28;case 4:case 6:case 9:case 11:return 30}return 31}function xW($){return xj($)?366:365}function xj($){return $%4==0&&($%100!=0||$%400==0)}function AW($){let[Z,j]=CW($.isoYear,$.isoMonth,$.isoDay);return gZ(Z.getUTCDay()-j,7)||7}function fW({isoYear:$}){return $<1?["bce",1-$]:["ce",$]}function VF($){let Z=H0($);if(Z<UQ)return fW($);let j=Hj(e2(n$),Z),{era:J,eraYear:W}=p7(j,n$);return[J,W]}function z6($){return O$($),X6($,1),$}function O$($){return EW($,1),$}function l5($){return XW(l2,$,EW($))}function EW($,Z){let{isoYear:j}=$,J=f0($,"isoMonth",1,SW(),Z);return{isoYear:j,isoMonth:J,isoDay:f0($,"isoDay",1,Sj(j,J),Z)}}function X6($,Z){return a$(o0,[f0($,"isoHour",0,23,Z),f0($,"isoMinute",0,59,Z),f0($,"isoSecond",0,59,Z),f0($,"isoMillisecond",0,999,Z),f0($,"isoMicrosecond",0,999,Z),f0($,"isoNanosecond",0,999,Z)])}function k($){return $===void 0?0:UY(P1($))}function nZ($,Z=0){$=i0($);let j=VY($),J=_Q($,Z);return[UY($),J,j]}function Aj($){return VY(i0($))}function RW($){return $=i0($),n2($,9,6,1)}function t$($,Z,j,J=9,W=0,Y=4){Z=i0(Z);let z=n2(Z,J,W),X=Rj(Z),G=W3(Z,Y),F=J3(Z,J,W,1);return z==null?z=Math.max(j,F):kW(z,F),X=bj(X,F,1),$&&(G=((Q)=>Q<4?(Q+2)%4:Q)(G)),[z,F,X,G]}function G6($,Z=6,j){let J=Rj($=vj($,r3)),W=W3($,7),Y=J3($,Z);return Y=UW(r3,Y),J=bj(J,Y,void 0,j),[Y,J,W]}function fj($){return o2(i0($))}function bW($,Z){return Ej(i0($),Z)}function Ej($,Z=4){let j=wW($);return[W3($,4),...vW(J3($,Z),j)]}function vW($,Z){return $!=null?[Z1[$],$<4?9-3*$:-1]:[Z===void 0?1:10**(9-Z),Z]}function Rj($){let Z=$[mZ];return Z===void 0?1:P0(Z,mZ)}function bj($,Z,j,J){let W=J?m:Z1[Z+1];if(W){let Y=Z1[Z];if(W%(($=p0(mZ,$,1,W/Y-(J?0:1),1))*Y))throw RangeError(eZ(mZ,$))}else $=p0(mZ,$,1,j?1e9:1,1);return $}function wW($){let Z=$[Yj];if(Z!==void 0){if(typeof Z!="number"){if(Pj(Z)==="auto")return;throw RangeError(eZ(Yj,Z))}Z=p0(Yj,Math.floor(Z),0,9,1)}return Z}function i0($){return $===void 0?{}:P1($)}function vj($,Z){return typeof $=="string"?{[Z]:$}:P1($)}function J0($){if($!==void 0){if(K0($))return Object.assign(Object.create(null),$);throw TypeError(p9)}}function F6($,Z){return $&&Object.assign(Object.create(null),$,{overflow:TQ[Z]})}function wj($,Z,j=9,J=0,W){let Y=Z[$];if(Y===void 0)return W?J:void 0;if(Y=Pj(Y),Y==="auto")return W?J:null;let z=Qj[Y];if(z===void 0&&(z=FQ[Y]),z===void 0)throw RangeError(u9($,Y,Qj));return p0($,z,J,j,1,Z3),z}function B$($,Z,j,J=0){let W=j[$];if(W===void 0)return J;let Y=Pj(W),z=Z[Y];if(z===void 0)throw RangeError(u9($,Y,Z));return z}function kW($,Z){if(Z>$)throw RangeError(ZQ)}function O0($){return{branding:g6,epochNanoseconds:$}}function V0($,Z,j){return{branding:_1,calendar:j,timeZone:Z,epochNanoseconds:$}}function W0($,Z=$.calendar){return{branding:L$,calendar:Z,...w0(KY,$)}}function Y0($,Z=$.calendar){return{branding:N$,calendar:Z,...w0(i2,$)}}function F$($,Z=$.calendar){return{branding:zZ,calendar:Z,...w0(i2,$)}}function i3($,Z=$.calendar){return{branding:XZ,calendar:Z,...w0(i2,$)}}function s0($){return{branding:y6,...w0(QY,$)}}function i($){return{branding:m6,sign:c1($),...w0(c2,$)}}function qW($){return LW($.epochNanoseconds)}function Q6($){return Lj($.epochNanoseconds,j1)[0]}function yW($){return NW($.epochNanoseconds,P$)}function gW($){return NW($.epochNanoseconds)}function mW($){return $.epochNanoseconds}function D0($){return typeof $=="string"?$:a($.id)}function e$($,Z){return $===Z||D0($)===D0(Z)}function pW($,Z,j,J,W){let Y=Q$(J),[z,X]=((V,I)=>{let P=I((V=vj(V,Bj))[BY]),M=CQ(V);return M=UW(Bj,M),[M,P]})(W,$);if(hZ(Math.max(z,Y),X))return i5(J,z);if(!X)throw RangeError(R6);let[G,F,Q]=V6(Z,j,X),O=W2(Q),K=T6(Q),D=Y2(Q),B=K(F,G,J),U=D(F,G,B,z);return hZ(z,X)?i5(U,z):((V,I,P,M,x,f,A)=>{let _=c1(V),[L,N]=kj(M,u2(P,V),P,_,x,f,A),l=qj(I,L,N);return V[q[P]]+l*_})(U,O(B),z,F,G,O,K)}function i5($,Z){return g0(Q0($),Z1[Z],1)}function kj($,Z,j,J,W,Y,z){let X=q[j],G={...Z,[X]:Z[X]+J},F=z($,W,Z),Q=z($,W,G);return[Y(F),Y(Q)]}function qj($,Z,j){let J=g0(y0(Z,j));if(!J)throw RangeError($3);return g0(y0(Z,$))/J}function hW($,Z){let[j,J,W]=G6(Z,5,1);return O0(O6($.epochNanoseconds,j,J,W,1))}function cW($,Z,j){let{epochNanoseconds:J,timeZone:W,calendar:Y}=Z,[z,X,G]=G6(j);if(z===0&&X===1)return Z;let F=$(W);if(z===6)J=((Q,O,K,D)=>{let B=C0(K,O),[U,V]=Q(B),I=K.epochNanoseconds,P=v0(O,U),M=v0(O,V);if(PW(I,P,M))throw RangeError($3);return rW(qj(I,P,M),D)?M:P})(oW,F,Z,G);else{let Q=F.getOffsetNanosecondsFor(J);J=U$(F,sW(h1(J,Q),z,X,G),Q,2,0,1)}return V0(J,W,Y)}function dW($,Z){return W0(sW($,...G6(Z)),$.calendar)}function uW($,Z){let[j,J,W]=G6(Z,5);var Y;return s0((Y=W,yj($,oZ(j,J),Y)[0]))}function lW($,Z){let j=$(Z.timeZone),J=C0(Z,j),[W,Y]=oW(J),z=g0(y0(v0(j,W),v0(j,Y)),v6,1);if(z<=0)throw RangeError($3);return z}function iW($,Z){let{timeZone:j,calendar:J}=Z,W=((Y,z,X)=>v0(z,Y(C0(X,z))))(aW,$(j),Z);return V0(W,j,J)}function sW($,Z,j,J){return nW($,oZ(Z,j),J)}function nW($,Z,j){let[J,W]=yj($,Z,j);return N1({...V$($,W),...J})}function yj($,Z,j){return W6(p1(m1($),Z,j))}function s3($){return p1($,b6,7)}function oZ($,Z){return Z1[$]*Z}function oW($){let Z=aW($);return[Z,V$(Z,1)]}function aW($){return QQ(6,$)}function TF($,Z,j){let J=Math.min(Q$($),6);return ZZ(B6(Q0($,J),Z,j),J)}function K6($,Z,j,J,W,Y,z,X,G,F){if(J===0&&W===1)return $;let Q=hZ(J,X)?I6(X)&&J<6&&j>=6?MF:IF:PF,[O,K,D]=Q($,Z,j,J,W,Y,z,X,G,F);return D&&J!==7&&(O=((B,U,V,I,P,M,x,f)=>{let A=c1(B);for(let _=I+1;_<=V;_++){if(_===7&&V!==7)continue;let L=u2(_,B);L[q[_]]+=A;let N=g0(y0(x(f(P,M,L)),U));if(N&&Math.sign(N)!==A)break;B=L}return B})(O,K,j,Math.max(6,J),z,X,G,F)),O}function O6($,Z,j,J,W){if(Z===6){let Y=((z)=>z[0]+z[1]/m)($);return[p1(Y,j,J),0]}return B6($,oZ(Z,j),J,W)}function B6($,Z,j,J){let[W,Y]=$;J&&Y<0&&(Y+=m,W-=1);let[z,X]=I1(p1(Y,Z,j),m);return Nj(W+z,X)}function p1($,Z,j){return rW($/Z,j)*Z}function rW($,Z){return AQ[Z]($)}function IF($,Z,j,J,W,Y){let z=c1($),X=Q0($),G=O6(X,J,W,Y),F=y0(X,G),Q=Math.sign(G[0]-X[0])===z,O=ZZ(G,Math.min(j,6));return[{...$,...O},l$(Z,F),Q]}function MF($,Z,j,J,W,Y,z,X,G,F){let Q=c1($),O=g0(Q0($,5)),K=oZ(J,W),D=p1(O,K,Y),[B,U]=kj(z,{...$,...d2},6,Q,X,G,F),V=D-g0(y0(B,U)),I=0;V&&Math.sign(V)!==Q?Z=i$(B,D):(I+=Q,D=p1(V,K,Y),Z=i$(U,D));let P=P6(D);return[{...$,...P,days:$.days+I},Z,Boolean(I)]}function PF($,Z,j,J,W,Y,z,X,G,F){let Q=c1($),O=q[J],K=u2(J,$);J===7&&($={...$,weeks:$.weeks+Math.trunc($.days/7)});let D=e3($[O],W)*W;K[O]=D;let[B,U]=kj(z,K,J,W*Q,X,G,F),V=D+qj(Z,B,U)*Q*W,I=p1(V,W,Y),P=Math.sign(I-V)===Q;return K[O]=I,[K,P?U:B,P]}function gj($,Z,j,J){let[W,Y,z,X]=((F)=>{let Q=Ej(F=i0(F));return[F.timeZone,...Q]})(J),G=W!==void 0;return((F,Q,O,K,D,B)=>{O=B6(O,D,K,1);let U=Q.getOffsetNanosecondsFor(O);return lj(h1(O,U),B)+(F?D$(s3(U)):"Z")})(G,Z(G?$(W):H$),j.epochNanoseconds,Y,z,X)}function mj($,Z,j){let[J,W,Y,z,X,G]=((F)=>{F=i0(F);let Q=o2(F),O=wW(F),K=xQ(F),D=W3(F,4),B=J3(F,4);return[Q,SQ(F),K,D,...vW(B,O)]})(j);return((F,Q,O,K,D,B,U,V,I,P)=>{K=B6(K,I,V,1);let M=F(O).getOffsetNanosecondsFor(K);return lj(h1(K,M),P)+D$(s3(M),U)+((x,f)=>f!==1?"["+(f===2?"!":"")+D0(x)+"]":"")(O,B)+ij(Q,D)})($,Z.calendar,Z.timeZone,Z.epochNanoseconds,J,W,Y,z,X,G)}function pj($,Z){let[j,J,W,Y]=((F)=>(F=i0(F),[o2(F),...Ej(F)]))(Z);return z=$.calendar,X=j,G=Y,lj(nW($,W,J),G)+ij(z,X);var z,X,G}function hj($,Z){return j=$.calendar,J=$,W=fj(Z),n3(J)+ij(j,W);var j,J,W}function cj($,Z){return tW($.calendar,eW,$,fj(Z))}function dj($,Z){return tW($.calendar,NF,$,fj(Z))}function uj($,Z){let[j,J,W]=bW(Z);return Y=W,$7(yj($,J,j)[0],Y);var Y}function D6($,Z){let[j,J,W]=bW(Z,3);return J>1&&($={...$,...TF($,J,j)}),((Y,z)=>{let{sign:X}=Y,G=X===-1?_0(Y):Y,{hours:F,minutes:Q}=G,[O,K]=Lj(Q0(G,3),c0,g1);G7(O);let D=sj(K,z),B=z>=0||!X||D;return(X<0?"-":"")+"P"+s5({Y:G$(G.years),M:G$(G.months),W:G$(G.weeks),D:G$(G.days)})+(F||Q||O||B?"T"+s5({H:G$(F),M:G$(Q),S:G$(O,B)+D}):"")})($,W)}function tW($,Z,j,J){let W=D0($),Y=J>1||J===0&&W!==v;return J===1?W===v?Z(j):n3(j):Y?n3(j)+Z7(W,J===2):Z(j)}function s5($){let Z=[];for(let j in $){let J=$[j];J&&Z.push(J,j)}return Z.join("")}function lj($,Z){return n3($)+"T"+$7($,Z)}function n3($){return eW($)+"-"+h0($.isoDay)}function eW($){let{isoYear:Z}=$;return(Z<0||Z>9999?j7(Z)+d3(6,Math.abs(Z)):d3(4,Z))+"-"+h0($.isoMonth)}function NF($){return h0($.isoMonth)+"-"+h0($.isoDay)}function $7($,Z){let j=[h0($.isoHour),h0($.isoMinute)];return Z!==-1&&j.push(h0($.isoSecond)+((J,W,Y,z)=>sj(J*j1+W*P$+Y,z))($.isoMillisecond,$.isoMicrosecond,$.isoNanosecond,Z)),j.join(":")}function D$($,Z=0){if(Z===1)return"";let[j,J]=I1(Math.abs($),v6),[W,Y]=I1(J,b6),[z,X]=I1(Y,c0);return j7($)+h0(j)+":"+h0(W)+(z||X?":"+h0(z)+sj(X):"")}function ij($,Z){if(Z!==1){let j=D0($);if(Z>1||Z===0&&j!==v)return Z7(j,Z===2)}return""}function Z7($,Z){return"["+(Z?"!":"")+"u-ca="+$+"]"}function sj($,Z){let j=d3(9,$);return j=Z===void 0?j.replace(RQ,""):j.slice(0,Z),j?"."+j:""}function j7($){return $<0?"-":"+"}function G$($,Z){return $||Z?$.toLocaleString("fullwide",{useGrouping:0}):""}function LF($,Z){let{epochNanoseconds:j}=$,J=(Z.getOffsetNanosecondsFor?Z:Z($.timeZone)).getOffsetNanosecondsFor(j),W=h1(j,J);return{calendar:$.calendar,...W,offsetNanoseconds:J}}function J7($,Z){let j=C0(Z,$);return{calendar:Z.calendar,...w0(KY,j),offset:D$(j.offsetNanoseconds),timeZone:Z.timeZone}}function U$($,Z,j,J=0,W=0,Y,z){if(j!==void 0&&J===1&&(J===1||z))return _j(Z,j);let X=$.getPossibleInstantsFor(Z);if(j!==void 0&&J!==3){let G=((F,Q,O,K)=>{let D=N0(Q);K&&(O=s3(O));for(let B of F){let U=g0(y0(B,D));if(K&&(U=s3(U)),U===O)return B}})(X,Z,j,Y);if(G!==void 0)return G;if(J===0)throw RangeError(oF)}return z?N0(Z):v0($,Z,W,X)}function v0($,Z,j=0,J=$.getPossibleInstantsFor(Z)){if(J.length===1)return J[0];if(j===1)throw RangeError(aF);if(J.length)return J[j===3?1:0];let W=N0(Z),Y=((X,G)=>{let F=X.getOffsetNanosecondsFor(i$(G,-m));return oj(X.getOffsetNanosecondsFor(i$(G,m))-F)})($,W),z=Y*(j===2?-1:1);return(J=$.getPossibleInstantsFor(h1(W,z)))[j===2?0:J.length-1]}function nj($){if(Math.abs($)>=m)throw RangeError(sF);return $}function oj($){if($>m)throw RangeError(nF);return $}function aj($,Z,j){return O0(m0(l$(Z.epochNanoseconds,((J)=>{if(F7(J))throw RangeError(eF);return Q0(J,5)})($?_0(j):j))))}function rj($,Z,j,J,W,Y=Object.create(null)){let z=Z(J.timeZone),X=$(J.calendar);return{...J,...j2(z,X,J,j?_0(W):W,Y)}}function tj($,Z,j,J,W=Object.create(null)){let{calendar:Y}=j;return W0(J2($(Y),j,Z?_0(J):J,W),Y)}function ej($,Z,j,J,W){let{calendar:Y}=j;return Y0(U6($(Y),j,Z?_0(J):J,W),Y)}function $2($,Z,j,J,W=Object.create(null)){let Y=j.calendar,z=$(Y),X=pZ(z,j);Z&&(J=M6(J)),J.sign<0&&(X=z.dateAdd(X,{...U0,months:1}),X=V$(X,-1));let G=z.dateAdd(X,J,W);return F$(pZ(z,G),Y)}function Z2($,Z,j){return s0(W7(Z,$?_0(j):j)[0])}function j2($,Z,j,J,W){let Y=Q0(J,5),z=j.epochNanoseconds;if(F7(J)){let X=C0(j,$);z=l$(v0($,{...U6(Z,X,{...J,...d2},W),...w0(o0,X)}),Y)}else z=l$(z,Y),k(W);return{epochNanoseconds:m0(z)}}function J2($,Z,j,J){let[W,Y]=W7(Z,j);return N1({...U6($,Z,{...j,...d2,days:j.days+Y},J),...W})}function U6($,Z,j,J){if(j.years||j.months||j.weeks)return $.dateAdd(Z,j,J);k(J);let W=j.days+Q0(j,5)[0];return W?q1(V$(Z,W)):Z}function pZ($,Z,j=1){return V$(Z,j-$.day(Z))}function W7($,Z){let[j,J]=Q0(Z,5),[W,Y]=W6(m1($)+J);return[W,j+Y]}function V$($,Z){return Z?{...$,...Y6(H0($)+Z*R0)}:$}function V6($,Z,j){let J=$(j.calendar);return I6(j)?[j,J,Z(j.timeZone)]:[{...j,...d0},J]}function W2($){return $?mW:N0}function T6($){return $?b(j2,$):J2}function Y2($){return $?b(CF,$):_F}function I6($){return $&&$.epochNanoseconds}function hZ($,Z){return $<=6-(I6(Z)?1:0)}function z2($,Z,j,J,W,Y,z){let X=$(i0(z).relativeTo),G=Math.max(Q$(W),Q$(Y));if(hZ(G,X))return i($Z(((U,V,I,P)=>{let M=l$(Q0(U),Q0(V),P?-1:1);if(!Number.isFinite(M[0]))throw RangeError(E6);return{...U0,...ZZ(M,I)}})(W,Y,G,J)));if(!X)throw RangeError(R6);J&&(Y=_0(Y));let[F,Q,O]=V6(Z,j,X),K=T6(O),D=Y2(O),B=K(Q,F,W);return i(D(Q,F,K(Q,B,Y),G))}function Y7($,Z,j,J,W){let Y=Q$(J),[z,X,G,F,Q]=((A,_,L)=>{A=vj(A,r3);let N=n2(A),l=L(A[BY]),d=Rj(A),E1=W3(A,7),e=J3(A);if(N===void 0&&e===void 0)throw RangeError($Q);return e==null&&(e=0),N==null&&(N=Math.max(e,_)),kW(N,e),d=bj(d,e,1),[N,e,d,E1,l]})(W,Y,$),O=Math.max(Y,z);if(!I6(Q)&&O<=6)return i($Z(((A,_,L,N,l)=>{let d=O6(Q0(A),L,N,l);return{...U0,...ZZ(d,_)}})(J,z,X,G,F)));if(!Q)throw RangeError(R6);let[K,D,B]=V6(Z,j,Q),U=W2(B),V=T6(B),I=Y2(B),P=V(D,K,J),M=I(D,K,P,z),x=J.sign,f=c1(M);if(x&&f&&x!==f)throw RangeError($3);return f&&(M=K6(M,U(P),z,X,G,F,D,K,U,V)),i(M)}function z7($){return $.sign===-1?M6($):$}function M6($){return i(_0($))}function _0($){let Z={};for(let j of q)Z[j]=-1*$[j]||0;return Z}function X7($){return!$.sign}function c1($,Z=q){let j=0;for(let J of Z){let W=Math.sign($[J]);if(W){if(j&&j!==W)throw RangeError(tF);j=W}}return j}function $Z($){for(let Z of GQ)p0(Z,$[Z],-$W,$W,1);return G7(g0(Q0($),c0)),$}function G7($){if(!Number.isSafeInteger($))throw RangeError(rF)}function Q0($,Z=6){return FW($,Z,q)}function ZZ($,Z=6){let[j,J]=$,W=$6(J,Z,q);if(W[q[Z]]+=j*(m/Z1[Z]),!Number.isFinite(W[q[Z]]))throw RangeError(E6);return W}function P6($,Z=5){return $6($,Z,q)}function F7($){return Boolean(c1($,FY))}function Q$($){let Z=9;for(;Z>0&&!$[q[Z]];Z--);return Z}function HF($,Z){return[$,Z]}function n5($){let Z=Math.floor($/h3)*h3;return[Z,Z+h3]}function Q7($){let Z=d1($=u3($));if(!Z)throw RangeError(E0($));let j;if(Z.m)j=0;else{if(!Z.offset)throw RangeError(E0($));j=jZ(Z.offset)}return Z.timeZone&&Q2(Z.timeZone,1),O0(_j(z6(Z),j))}function K7($){let Z=d1(a($));if(!Z)throw RangeError(E0($));if(Z.timeZone)return P7(Z,Z.offset?jZ(Z.offset):void 0);if(Z.m)throw RangeError(E0($));return L7(Z)}function O7($,Z){let j=d1(a($));if(!j||!j.timeZone)throw RangeError(E0($));let{offset:J}=j,W=J?jZ(J):void 0,[,Y,z]=nZ(Z);return P7(j,W,Y,z)}function jZ($){let Z=Q2($);if(Z===void 0)throw RangeError(E0($));return Z}function B7($){let Z=d1(a($));if(!Z||Z.m)throw RangeError(E0($));return W0(N7(Z))}function N6($){let Z=d1(a($));if(!Z||Z.m)throw RangeError(E0($));return Y0(Z.p?N7(Z):L7(Z))}function D7($,Z){let j=G2(a(Z));if(j)return X2(j),F$(Cj(O$(j)));let J=N6(Z);return F$(pZ($(J.calendar),J))}function X2($){if($.calendar!==v)throw RangeError(M1($.calendar))}function U7($,Z){let j=F2(a(Z));if(j)return X2(j),i3(O$(j));let J=N6(Z),{calendar:W}=J,Y=$(W),[z,X,G]=Y.h(J),[F,Q]=Y.I(z,X),[O,K]=Y.N(F,Q,G);return i3(q1(Y.P(O,K,G)),W)}function V7($){let Z,j=((J)=>{let W=qQ.exec(J);return W?(L6(W[10]),_7(W)):void 0})(a($));if(!j){if(j=d1($),!j)throw RangeError(E0($));if(!j.p)throw RangeError(E0($));if(j.m)throw RangeError(M1("Z"));X2(j)}if((Z=G2($))&&l5(Z))throw RangeError(E0($));if((Z=F2($))&&l5(Z))throw RangeError(E0($));return s0(X6(j,1))}function T7($){let Z=((j)=>{let J=mQ.exec(j);return J?((W)=>{function Y(Q,O,K){let D=0,B=0;if(K&&([D,G]=I1(G,Z1[K])),Q!==void 0){if(X)throw RangeError(M1(Q));B=((U)=>{let V=parseInt(U);if(!Number.isFinite(V))throw RangeError(M1(U));return V})(Q),z=1,O&&(G=K2(O)*(Z1[K]/c0),X=1)}return D+B}let z=0,X=0,G=0,F={...a$(q,[Y(W[2]),Y(W[3]),Y(W[4]),Y(W[5]),Y(W[6],W[7],5),Y(W[8],W[9],4),Y(W[10],W[11],3)]),...$6(G,2,q)};if(!z)throw RangeError(c9(q));return O2(W[1])<0&&(F=_0(F)),F})(J):void 0})(a($));if(!Z)throw RangeError(E0($));return i($Z(Z))}function I7($){let Z=d1($)||G2($)||F2($);return Z?Z.calendar:$}function M7($){let Z=d1($);return Z&&(Z.timeZone||Z.m&&H$||Z.offset)||$}function P7($,Z,j=0,J=0){let W=H6($.timeZone),Y=p6(W);return V0(U$(Y,z6($),Z,j,J,!Y.v,$.m),W,aZ($.calendar))}function N7($){return H7(N1(z6($)))}function L7($){return H7(q1(O$($)))}function H7($){return{...$,calendar:aZ($.calendar)}}function d1($){let Z=kQ.exec($);return Z?((j)=>{let J=j[10],W=(J||"").toUpperCase()==="Z";return{isoYear:C7(j),isoMonth:parseInt(j[4]),isoDay:parseInt(j[5]),..._7(j.slice(5)),...L6(j[16]),p:Boolean(j[6]),m:W,offset:W?void 0:J}})(Z):void 0}function G2($){let Z=vQ.exec($);return Z?((j)=>({isoYear:C7(j),isoMonth:parseInt(j[4]),isoDay:1,...L6(j[5])}))(Z):void 0}function F2($){let Z=wQ.exec($);return Z?((j)=>({isoYear:o$,isoMonth:parseInt(j[1]),isoDay:parseInt(j[2]),...L6(j[3])}))(Z):void 0}function Q2($,Z){let j=yQ.exec($);return j?((J,W)=>{let Y=J[4]||J[5];if(W&&Y)throw RangeError(M1(Y));return nj((u$(J[2])*v6+u$(J[3])*b6+u$(J[4])*c0+K2(J[5]||""))*O2(J[1]))})(j,Z):void 0}function C7($){let Z=O2($[1]),j=parseInt($[2]||$[3]);if(Z<0&&!j)throw RangeError(M1(-0));return Z*j}function _7($){let Z=u$($[3]);return{...W6(K2($[4]||""))[0],isoHour:u$($[1]),isoMinute:u$($[2]),isoSecond:Z===60?59:Z}}function L6($){let Z,j,J=[];if($.replace(gQ,(W,Y,z)=>{let X=Boolean(Y),[G,F]=z.split("=").reverse();if(F){if(F==="u-ca")J.push(G),Z||(Z=X);else if(X||/[A-Z]/.test(F))throw RangeError(M1(W))}else{if(j)throw RangeError(M1(W));j=G}return""}),J.length>1&&Z)throw RangeError(M1($));return{timeZone:j,calendar:J[0]||v}}function K2($){return parseInt($.padEnd(9,"0"))}function JZ($){return new RegExp(`^${$}$`,"i")}function O2($){return $&&$!=="+"?-1:1}function u$($){return $===void 0?0:parseInt($)}function S7($){return H6(a($))}function H6($){let Z=B2($);return typeof Z=="number"?D$(Z):Z?((j)=>{if(hQ.test(j))throw RangeError(iF);return j.toLowerCase().split("/").map((J,W)=>(J.length<=3||/\d/.test(J))&&!/etc|yap/.test(J)?J.toUpperCase():J.replace(/baja|dumont|[a-z]+/g,(Y,z)=>Y.length<=2&&!W||Y==="in"||Y==="chat"?Y.toUpperCase():Y.length>2||!z?d5(Y).replace(/island|noronha|murdo|rivadavia|urville/,d5):Y)).join("/")})($):H$}function o5($){let Z=B2($);return typeof Z=="number"?Z:Z?Z.resolvedOptions().timeZone:H$}function B2($){let Z=Q2($=$.toUpperCase(),1);return Z!==void 0?Z:$!==H$?pQ($):void 0}function D2($,Z){return L0($.epochNanoseconds,Z.epochNanoseconds)}function U2($,Z){return L0($.epochNanoseconds,Z.epochNanoseconds)}function x7($,Z,j,J,W,Y){let z=$(i0(Y).relativeTo),X=Math.max(Q$(J),Q$(W));if(XW(q,J,W))return 0;if(hZ(X,z))return L0(Q0(J),Q0(W));if(!z)throw RangeError(R6);let[G,F,Q]=V6(Z,j,z),O=W2(Q),K=T6(Q);return L0(O(K(F,G,J)),O(K(F,G,W)))}function V2($,Z){return T$($,Z)||C6($,Z)}function T$($,Z){return k1(H0($),H0(Z))}function C6($,Z){return k1(m1($),m1(Z))}function A7($,Z){return!D2($,Z)}function f7($,Z){return!U2($,Z)&&!!_6($.timeZone,Z.timeZone)&&e$($.calendar,Z.calendar)}function E7($,Z){return!V2($,Z)&&e$($.calendar,Z.calendar)}function R7($,Z){return!T$($,Z)&&e$($.calendar,Z.calendar)}function b7($,Z){return!T$($,Z)&&e$($.calendar,Z.calendar)}function v7($,Z){return!T$($,Z)&&e$($.calendar,Z.calendar)}function w7($,Z){return!C6($,Z)}function _6($,Z){if($===Z)return 1;let j=D0($),J=D0(Z);if(j===J)return 1;try{return o5(j)===o5(J)}catch(W){}}function T2($,Z,j,J){let W=t$($,J0(J),3,5),Y=S6(Z.epochNanoseconds,j.epochNanoseconds,...W);return i($?_0(Y):Y)}function I2($,Z,j,J,W,Y){let z=A6(J.calendar,W.calendar),X=J0(Y),[G,F,Q,O]=t$(j,X,5),K=J.epochNanoseconds,D=W.epochNanoseconds,B=L0(D,K),U;if(B)if(G<6)U=S6(K,D,G,F,Q,O);else{let V=Z(((P,M)=>{if(!_6(P,M))throw RangeError(n9);return P})(J.timeZone,W.timeZone)),I=$(z);U=q7(I,V,J,W,B,G,X),U=K6(U,D,G,F,Q,O,I,J,mW,b(j2,V))}else U=U0;return i(j?_0(U):U)}function M2($,Z,j,J,W){let Y=A6(j.calendar,J.calendar),z=J0(W),[X,G,F,Q]=t$(Z,z,6),O=N0(j),K=N0(J),D=L0(K,O),B;if(D)if(X<=6)B=S6(O,K,X,G,F,Q);else{let U=$(Y);B=y7(U,j,J,D,X,z),B=K6(B,K,X,G,F,Q,U,j,N0,J2)}else B=U0;return i(Z?_0(B):B)}function P2($,Z,j,J,W){let Y=A6(j.calendar,J.calendar),z=J0(W);return k7(Z,()=>$(Y),j,J,...t$(Z,z,6,9,6),z)}function N2($,Z,j,J,W){let Y=A6(j.calendar,J.calendar),z=J0(W),X=t$(Z,z,9,9,8),G=$(Y);return k7(Z,()=>G,pZ(G,j),pZ(G,J),...X,z)}function k7($,Z,j,J,W,Y,z,X,G){let F=N0(j),Q=N0(J),O;if(L0(Q,F))if(W===6)O=S6(F,Q,W,Y,z,X);else{let K=Z();O=K.dateUntil(j,J,W,G),Y===6&&z===1||(O=K6(O,Q,W,Y,z,X,K,j,N0,U6))}else O=U0;return i($?_0(O):O)}function L2($,Z,j,J){let W=J0(J),[Y,z,X,G]=t$($,W,5,5),F=p1(H2(Z,j),oZ(z,X),G),Q={...U0,...P6(F,Y)};return i($?_0(Q):Q)}function CF($,Z,j,J,W,Y){let z=L0(J.epochNanoseconds,j.epochNanoseconds);return z?W<6?g7(j.epochNanoseconds,J.epochNanoseconds,W):q7(Z,$,j,J,z,W,Y):U0}function _F($,Z,j,J,W){let Y=N0(Z),z=N0(j),X=L0(z,Y);return X?J<=6?g7(Y,z,J):y7($,Z,j,X,J,W):U0}function q7($,Z,j,J,W,Y,z){let[X,G,F]=((K,D,B,U)=>{function V(){return _={...V$(M,f++*-U),...P},L=v0(K,_),L0(x,L)===-U}let I=C0(D,K),P=w0(o0,I),M=C0(B,K),x=B.epochNanoseconds,f=0,A=H2(I,M),_,L;if(Math.sign(A)===-U&&f++,V()&&(U===-1||V()))throw RangeError($3);let N=g0(y0(L,x));return[I,_,N]})(Z,j,J,W);var Q,O;return{...Y===6?(Q=X,O=G,{...U0,days:m7(Q,O)}):$.dateUntil(X,G,Y,z),...P6(F)}}function y7($,Z,j,J,W,Y){let[z,X,G]=((F,Q,O)=>{let K=Q,D=H2(F,Q);return Math.sign(D)===-O&&(K=V$(Q,-O),D+=m*O),[F,K,D]})(Z,j,J);return{...$.dateUntil(z,X,W,Y),...P6(G)}}function S6($,Z,j,J,W,Y){return{...U0,...ZZ(O6(y0($,Z),J,W,Y),j)}}function g7($,Z,j){return{...U0,...ZZ(y0($,Z),j)}}function m7($,Z){return x6(H0($),H0(Z))}function x6($,Z){return Math.trunc((Z-$)/R0)}function H2($,Z){return m1(Z)-m1($)}function A6($,Z){if(!e$($,Z))throw RangeError(g2);return $}function SF($){function Z(W){return((Y,z)=>({...p7(Y,z),F:Y.month,day:parseInt(Y.day)}))(Hj(j,W),J)}let j=e2($),J=o3($);return{id:$,O:xF(Z),B:AF(Z)}}function xF($){return b0((Z)=>{let j=H0(Z);return $(j)},WeakMap)}function AF($){let Z=$(0).year-DQ;return b0((j)=>{let J,W=r$(j-Z),Y=[],z=[];do W+=400*R0;while((J=$(W)).year<=j);do W+=(1-J.day)*R0,J.year===j&&(Y.push(W),z.push(J.F)),W-=R0;while((J=$(W)).year>=j);return{k:Y.reverse(),C:r9(z.reverse())}})}function p7($,Z){let j,J,W=h7($);if($.era){let Y=zY[Z];Y!==void 0&&(j=Z==="islamic"?"ah":$.era.normalize("NFD").toLowerCase().replace(/[^a-z0-9]/g,""),j==="bc"||j==="b"?j="bce":j!=="ad"&&j!=="a"||(j="ce"),J=W,W=i7(J,Y[j]||0))}return{era:j,eraYear:J,year:W}}function h7($){return parseInt($.relatedYear||$.year)}function Xj($){let{year:Z,F:j,day:J}=this.O($),{C:W}=this.B(Z);return[Z,W[j]+1,J]}function cZ($,Z=1,j=1){return this.B($).k[Z-1]+(j-1)*R0}function g3($){let Z=r5(this,$),j=r5(this,$-1),J=Z.length;if(J>j.length){let W=s7(this);if(W<0)return-W;for(let Y=0;Y<J;Y++)if(Z[Y]!==j[Y])return Y+1}}function m3($){return x6(cZ.call(this,$),cZ.call(this,$+1))}function a5($,Z){let{k:j}=this.B($),J=Z+1,W=j;return J>j.length&&(J=1,W=this.B($+1).k),x6(j[Z-1],W[J-1])}function p3($){return this.B($).k.length}function r5($,Z){return Object.keys($.B(Z).C)}function c7($){return aZ(a($))}function aZ($){if(($=$.toLowerCase())!==v&&$!==k6&&o3($)!==o3(e2($).resolvedOptions().calendar))throw RangeError(lF($));return $}function o3($){return $==="islamicc"&&($="islamic"),$.split("-")[0]}function d7($){return this.R($)[0]}function u7($){return this.R($)[1]}function C2($){let[Z]=this.h($);return x6(this.q(Z),H0($))+1}function l7($){let Z=dQ.exec($);if(!Z)throw RangeError(dF($));return[parseInt(Z[1]),Boolean(Z[2])]}function a3($,Z,j){return $+(Z||j&&$>=j?1:0)}function Gj($,Z){return $-(Z&&$>=Z?1:0)}function i7($,Z){return(Z+$)*(Math.sign(Z)||1)||0}function Fj($){return zY[n7($)]}function s7($){return YQ[n7($)]}function n7($){return o3($.id||v)}function o7($,Z,j,J){let W=u1(j,J,n0,[],jY);if(W.timeZone!==void 0){let Y=j.dateFromFields(W),z=I$(W),X=$(W.timeZone);return{epochNanoseconds:U$(Z(X),{...Y,...z},W.offset!==void 0?jZ(W.offset):void 0),timeZone:X}}return{...j.dateFromFields(W),...d0}}function a7($,Z,j,J,W,Y){let z=u1(j,W,n0,$Y,jY),X=$(z.timeZone),[G,F,Q]=nZ(Y),O=j.dateFromFields(z,F6(Y,G)),K=I$(z,G);return V0(U$(Z(X),{...O,...K},z.offset!==void 0?jZ(z.offset):void 0,F,Q),X,J)}function r7($,Z,j){let J=u1($,Z,n0,[],C1),W=k(j);return W0(N1({...$.dateFromFields(J,F6(j,W)),...I$(J,W)}))}function _2($,Z,j,J=[]){let W=u1($,Z,n0,J);return $.dateFromFields(W,j)}function S2($,Z,j,J){let W=u1($,Z,h2,J);return $.yearMonthFromFields(W,j)}function x2($,Z,j,J,W=[]){let Y=u1($,j,n0,W);return Z&&Y.month!==void 0&&Y.monthCode===void 0&&Y.year===void 0&&(Y.year=o$),$.monthDayFromFields(Y,J)}function t7($,Z){let j=k(Z);return s0(I$($1($,Kj,[],1),j))}function e7($){let Z=$1($,c2);return i($Z({...U0,...Z}))}function u1($,Z,j,J=[],W=[]){return $1(Z,[...$.fields(j),...W].sort(),J)}function $1($,Z,j,J=!j){let W={},Y,z=0;for(let X of Z){if(X===Y)throw RangeError(yF(X));if(X==="constructor"||X==="__proto__")throw RangeError(q2(X));let G=$[X];if(G!==void 0)z=1,ZW[X]&&(G=ZW[X](G,X)),W[X]=G;else if(j){if(j.includes(X))throw TypeError(k2(X));W[X]=YY[X]}Y=X}if(J&&!z)throw TypeError(c9(Z));return W}function I$($,Z){return X6(sQ({...YY,...$}),Z)}function $9($,Z,j,J,W,Y){let z=J0(Y),{calendar:X,timeZone:G}=j;return V0(((F,Q,O,K,D)=>{let B=rZ(F,O,K,n0,ZY,e9),[U,V,I]=nZ(D,2);return U$(Q,{...F.dateFromFields(B,F6(D,U)),...I$(B,U)},jZ(B.offset),V,I)})($(X),Z(G),J,W,z),G,X)}function Z9($,Z,j,J,W){let Y=J0(W);return W0(((z,X,G,F)=>{let Q=rZ(z,X,G,n0,C1),O=k(F);return N1({...z.dateFromFields(Q,F6(F,O)),...I$(Q,O)})})($(Z.calendar),j,J,Y))}function j9($,Z,j,J,W){let Y=J0(W);return((z,X,G,F)=>{let Q=rZ(z,X,G,n0);return z.dateFromFields(Q,F)})($(Z.calendar),j,J,Y)}function J9($,Z,j,J,W){let Y=J0(W);return F$(((z,X,G,F)=>{let Q=rZ(z,X,G,h2);return z.yearMonthFromFields(Q,F)})($(Z.calendar),j,J,Y))}function W9($,Z,j,J,W){let Y=J0(W);return((z,X,G,F)=>{let Q=rZ(z,X,G,n0);return z.monthDayFromFields(Q,F)})($(Z.calendar),j,J,Y)}function Y9($,Z,j){return s0(((J,W,Y)=>{let z=k(Y);return I$({...w0(Kj,J),...$1(W,Kj)},z)})($,Z,j))}function z9($,Z){return i((j=$,J=Z,$Z({...j,...$1(J,c2)})));var j,J}function rZ($,Z,j,J,W=[],Y=[]){let z=[...$.fields(J),...W].sort(),X=$1(Z,z,Y),G=$1(j,z);return X=$.mergeFields(X,G),$1(X,z,[])}function A2($,Z){let j=u1($,Z,WY);return $.monthDayFromFields(j)}function f2($,Z,j){let J=u1($,Z,JY);return $.yearMonthFromFields(J,j)}function X9($,Z,j,J,W){Z=w0(j=$.fields(j),Z),J=$1(J,W=$.fields(W),[]);let Y=$.mergeFields(Z,J);return Y=$1(Y,[...j,...W].sort(),[]),$.dateFromFields(Y)}function jj($,Z){let{era:j,eraYear:J,year:W}=Z,Y=Fj($);if(j!==void 0||J!==void 0){if(j===void 0||J===void 0)throw TypeError(mF);if(!Y)throw RangeError(gF);let z=Y[j];if(z===void 0)throw RangeError(hF(j));let X=i7(J,z);if(W!==void 0&&W!==X)throw RangeError(pF);W=X}else if(W===void 0)throw TypeError(cF(Y));return W}function Jj($,Z,j,J){let{month:W,monthCode:Y}=Z;if(Y!==void 0){let z=((X,G,F,Q)=>{let O=X.U(F),[K,D]=l7(G),B=a3(K,D,O);if(D){let U=s7(X);if(U===void 0)throw RangeError(yZ);if(U>0){if(B>U)throw RangeError(yZ);if(O===void 0){if(Q===1)throw RangeError(yZ);B--}}else{if(B!==-U)throw RangeError(yZ);if(O===void 0&&Q===1)throw RangeError(yZ)}}return B})($,Y,j,J);if(W!==void 0&&W!==z)throw RangeError(i9);W=z,J=1}else if(W===void 0)throw TypeError(uF);return p0("month",W,1,$.L(j),J)}function t5($,Z,j,J,W){return f0(Z,"day",1,$.j(J,j),W)}function Wj($,Z,j,J){let W=0,Y=[];for(let z of j)Z[z]!==void 0?W=1:Y.push(z);if(Object.assign($,Z),W)for(let z of J||Y)delete $[z]}function G9($){return O0(m0(J6(j6($))))}function F9($,Z,j,J,W=v){return V0(m0(J6(j6(j))),Z(J),$(W))}function Q9($,Z,j,J,W=0,Y=0,z=0,X=0,G=0,F=0,Q=v){return W0(N1(z6(u0(P0,a$(q6,[Z,j,J,W,Y,z,X,G,F])))),$(Q))}function K9($,Z,j,J,W=v){return Y0(q1(O$(u0(P0,{isoYear:Z,isoMonth:j,isoDay:J}))),$(W))}function O9($,Z,j,J=v,W=1){let Y=P0(Z),z=P0(j),X=$(J);return F$(Cj(O$({isoYear:Y,isoMonth:z,isoDay:P0(W)})),X)}function B9($,Z,j,J=v,W=o$){let Y=P0(Z),z=P0(j),X=$(J);return i3(q1(O$({isoYear:P0(W),isoMonth:Y,isoDay:z})),X)}function D9($=0,Z=0,j=0,J=0,W=0,Y=0){return s0(X6(u0(P0,a$(o0,[$,Z,j,J,W,Y])),1))}function U9($=0,Z=0,j=0,J=0,W=0,Y=0,z=0,X=0,G=0,F=0){return i($Z(u0(MW,a$(q,[$,Z,j,J,W,Y,z,X,G,F]))))}function E2($,Z,j=v){return V0($.epochNanoseconds,Z,j)}function V9($){return O0($.epochNanoseconds)}function R2($,Z){return W0(C0(Z,$))}function b2($,Z){return Y0(C0(Z,$))}function T9($,Z,j){return f2($(Z.calendar),j)}function I9($,Z,j){return A2($(Z.calendar),j)}function v2($,Z){return s0(C0(Z,$))}function M9($,Z,j,J){let W=((Y,z,X,G)=>{let F=Aj(G);return v0(Y(z),X,F)})($,j,Z,J);return V0(m0(W),j,Z.calendar)}function P9($,Z,j){let J=$(Z.calendar);return F$({...Z,...f2(J,j)})}function N9($,Z,j){return A2($(Z.calendar),j)}function L9($,Z,j,J,W){let Y=$(W.timeZone),z=W.plainTime,X=z!==void 0?Z(z):d0;return V0(v0(j(Y),{...J,...X}),Y,J.calendar)}function H9($,Z=d0){return W0(N1({...$,...Z}))}function C9($,Z,j){return f2($(Z.calendar),j)}function _9($,Z,j){return A2($(Z.calendar),j)}function S9($,Z,j,J){return((W,Y,z)=>X9(W,Y,JY,P1(z),j3))($(Z.calendar),j,J)}function x9($,Z,j,J){return((W,Y,z)=>X9(W,Y,WY,P1(z),w6))($(Z.calendar),j,J)}function A9($,Z,j,J,W){let Y=P1(W),z=Z(Y.plainDate),X=$(Y.timeZone);return V0(v0(j(X),{...z,...J}),X,z.calendar)}function f9($,Z){return W0(N1({...$,...Z}))}function E9($){return O0(m0(s$($,c0)))}function R9($){return O0(m0(s$($,j1)))}function b9($){return O0(m0(J6(j6($),P$)))}function v9($){return O0(m0(J6(j6($))))}function w9($,Z,j=d0){let J=Z.timeZone,W=$(J),Y={...C0(Z,W),...j};return V0(U$(W,Y,Y.offsetNanoseconds,2),J,Z.calendar)}function k9($,Z,j){let J=Z.timeZone,W=$(J),Y={...C0(Z,W),...j},z=m9(Z.calendar,j.calendar);return V0(U$(W,Y,Y.offsetNanoseconds,2),J,z)}function q9($,Z=d0){return W0({...$,...Z})}function y9($,Z){return W0({...$,...Z},m9($.calendar,Z.calendar))}function f6($,Z){return{...$,calendar:Z}}function g9($,Z){return{...$,timeZone:Z}}function m9($,Z){if($===Z)return $;let j=D0($),J=D0(Z);if(j===J||j===v)return Z;if(J===v)return $;throw RangeError(g2)}function fF($,Z){return(j)=>j===v?$:j===k6||j===n$?Object.assign(Object.create($),{id:j}):Object.assign(Object.create(Z),cQ(j))}function M$($,Z,j){let J=new Set(j);return(W)=>(((Y,z)=>{for(let X of z)if(X in Y)return 1;return 0})(W=Uj(J,W),$)||Object.assign(W,Z),j&&(W.timeZone=H$,["full","long"].includes(W.timeStyle)&&(W.timeStyle="medium")),W)}function L1($,Z=w2){let[j,,,J]=$;return(W,Y=FK,...z)=>{let X=Z(J&&J(...z),W,Y,j),G=X.resolvedOptions();return[X,...EF($,G,z)]}}function w2($,Z,j,J){if(j=J(j),$){if(j.timeZone!==void 0)throw TypeError(jQ);j.timeZone=$}return new l1(Z,j)}function EF($,Z,j){let[,J,W]=$;return j.map((Y)=>(Y.calendar&&((z,X,G)=>{if((G||z!==v)&&z!==X)throw RangeError(g2)})(D0(Y.calendar),Z.calendar,W),J(Y,Z)))}function WZ($){let Z=tZ();return h1(Z,$.getOffsetNanosecondsFor(Z))}function tZ(){return s$(Date.now(),j1)}function H1(){return JW||(JW=new l1().resolvedOptions().timeZone)}var RF=($,Z)=>`Non-integer ${$}: ${Z}`,bF=($,Z)=>`Non-positive ${$}: ${Z}`,vF=($,Z)=>`Non-finite ${$}: ${Z}`,wF=($)=>`Cannot convert bigint to ${$}`,kF=($)=>`Invalid bigint: ${$}`,qF="Cannot convert Symbol to string",p9="Invalid object",h9=($,Z,j,J,W)=>W?h9($,W[Z],W[j],W[J]):eZ($,Z)+`; must be between ${j}-${J}`,eZ=($,Z)=>`Invalid ${$}: ${Z}`,k2=($)=>`Missing ${$}`,q2=($)=>`Invalid field ${$}`,yF=($)=>`Duplicate field ${$}`,c9=($)=>"No valid fields: "+$.join(),d9="Invalid bag",u9=($,Z,j)=>eZ($,Z)+"; must be "+Object.keys(j).join(),l9="Cannot use valueOf",y2="Invalid calling context",gF="Forbidden era/eraYear",mF="Mismatching era/eraYear",pF="Mismatching year/eraYear",hF=($)=>`Invalid era: ${$}`,cF=($)=>"Missing year"+($?"/era/eraYear":""),dF=($)=>`Invalid monthCode: ${$}`,i9="Mismatching month/monthCode",uF="Missing month/monthCode",e5="Cannot guess year",yZ="Invalid leap month",s9="Invalid protocol",$3="Invalid protocol results",g2="Mismatching Calendars",lF=($)=>`Invalid Calendar: ${$}`,n9="Mismatching TimeZones",iF="Forbidden ICU TimeZone",sF="Out-of-bounds offset",nF="Out-of-bounds TimeZone gap",oF="Invalid TimeZone offset",aF="Ambiguous offset",E6="Out-of-bounds date",rF="Out-of-bounds duration",tF="Cannot mix duration signs",R6="Missing relativeTo",eF="Cannot use large units",$Q="Required smallestUnit or largestUnit",ZQ="smallestUnit > largestUnit",E0=($)=>`Cannot parse: ${$}`,M1=($)=>`Invalid substring: ${$}`,o9=($)=>`Cannot format ${$}`,a9="Mismatching types for formatting",jQ="Cannot specify TimeZone",r9=b(lZ,($,Z)=>Z),YZ=b(lZ,($,Z,j)=>j),h0=b(d3,2),Qj={nanosecond:0,microsecond:1,millisecond:2,second:3,minute:4,hour:5,day:6,week:7,month:8,year:9},Z3=Object.keys(Qj),R0=86400000,t9=1000,P$=1000,j1=1e6,c0=1e9,b6=60000000000,v6=3600000000000,m=86400000000000,Z1=[1,P$,j1,c0,b6,v6,m],C1=Z3.slice(0,6),Kj=iZ(C1),e9=["offset"],$Y=["timeZone"],ZY=C1.concat(e9),jY=ZY.concat($Y),Oj=["era","eraYear"],JQ=Oj.concat(["year"]),w6=["year"],m2=["monthCode"],p2=["month"].concat(m2),j3=["day"],h2=p2.concat(w6),JY=m2.concat(w6),n0=j3.concat(h2),WQ=j3.concat(p2),WY=j3.concat(m2),YY=YZ(C1,0),v="iso8601",k6="gregory",n$="japanese",zY={[k6]:{bce:-1,ce:0},[n$]:{bce:-1,ce:0,meiji:1867,taisho:1911,showa:1925,heisei:1988,reiwa:2018},ethioaa:{era0:0},ethiopic:{era0:0,era1:5500},coptic:{era0:-1,era1:0},roc:{beforeroc:-1,minguo:0},buddhist:{be:0},islamic:{ah:0},indian:{saka:0},persian:{ap:0}},YQ={chinese:13,dangi:13,hebrew:-6},a=b(Z6,"string"),XY=b(Z6,"boolean"),zQ=b(Z6,"number"),GY=b(Z6,"function"),q=Z3.map(($)=>$+"s"),c2=iZ(q),XQ=q.slice(0,6),FY=q.slice(6),GQ=FY.slice(1),FQ=r9(q),U0=YZ(q,0),d2=YZ(XQ,0),u2=b(GW,q),o0=["isoNanosecond","isoMicrosecond","isoMillisecond","isoSecond","isoMinute","isoHour"],l2=["isoDay","isoMonth","isoYear"],q6=o0.concat(l2),i2=iZ(l2),QY=iZ(o0),KY=iZ(q6),d0=YZ(QY,0),QQ=b(GW,q6),l1=Intl.DateTimeFormat,OY="en-GB",s2=1e8,KQ=s2*R0,OQ=[s2,0],BQ=[-s2,0],dZ=275760,uZ=-271821,DQ=1970,o$=1972,T1=12,UQ=r$(1868,9,8),VQ=b0(VF,WeakMap),r3="smallestUnit",Bj="unit",mZ="roundingIncrement",Yj="fractionalSecondDigits",BY="relativeTo",DY={constrain:0,reject:1},TQ=Object.keys(DY),IQ={compatible:0,reject:1,earlier:2,later:3},MQ={reject:0,use:1,prefer:2,ignore:3},PQ={auto:0,never:1,critical:2,always:3},NQ={auto:0,never:1,critical:2},LQ={auto:0,never:1},HQ={floor:0,halfFloor:1,ceil:2,halfCeil:3,trunc:4,halfTrunc:5,expand:6,halfExpand:7,halfEven:8},J3=b(wj,r3),n2=b(wj,"largestUnit"),CQ=b(wj,Bj),UY=b(B$,"overflow",DY),VY=b(B$,"disambiguation",IQ),_Q=b(B$,"offset",MQ),o2=b(B$,"calendarName",PQ),SQ=b(B$,"timeZoneName",NQ),xQ=b(B$,"offset",LQ),W3=b(B$,"roundingMode",HQ),zZ="PlainYearMonth",XZ="PlainMonthDay",N$="PlainDate",L$="PlainDateTime",y6="PlainTime",_1="ZonedDateTime",g6="Instant",m6="Duration",AQ=[Math.floor,($)=>y3($)?Math.floor($):Math.round($),Math.ceil,($)=>y3($)?Math.ceil($):Math.round($),Math.trunc,($)=>y3($)?Math.trunc($)||0:Math.round($),($)=>$<0?Math.floor($):Math.ceil($),($)=>Math.sign($)*Math.round(Math.abs($))||0,($)=>y3($)?($=Math.trunc($)||0)+$%2:Math.round($)],H$="UTC",h3=5184000,fQ=l3(1847),EQ=l3(new Date().getUTCFullYear()+10),RQ=/0+$/,C0=b0(LF,WeakMap),$W=4294967295,p6=b0(($)=>{let Z=B2($);return typeof Z=="object"?new IY(Z):new TY(Z||0)});class TY{constructor($){this.v=$}getOffsetNanosecondsFor(){return this.v}getPossibleInstantsFor($){return[_j($,this.v)]}l(){}}class IY{constructor($){this.$=((Z)=>{function j(G){let F=zj(G,z,X),[Q,O]=n5(F),K=W(Q),D=W(O);return K===D?K:J(Y(Q,O),K,D,G)}function J(G,F,Q,O){let K,D;for(;(O===void 0||(K=O<G[0]?F:O>=G[1]?Q:void 0)===void 0)&&(D=G[1]-G[0]);){let B=G[0]+Math.floor(D/2);Z(B)===Q?G[1]=B:G[0]=B+1}return K}let W=b0(Z),Y=b0(HF),z=fQ,X=EQ;return{G(G){let F=j(G-86400),Q=j(G+86400),O=G-F,K=G-Q;if(F===Q)return[O];let D=j(O);return D===j(K)?[G-D]:F>Q?[O,K]:[]},V:j,l(G,F){let Q=zj(G,z,X),[O,K]=n5(Q),D=h3*F,B=F<0?()=>K>z||(z=Q,0):()=>O<X||(X=Q,0);for(;B();){let U=W(O),V=W(K);if(U!==V){let I=Y(O,K);J(I,U,V);let P=I[0];if((k1(P,G)||1)===F)return P}O+=D,K+=D}}}})(((Z)=>(j)=>{let J=Hj(Z,j*t9);return l3(h7(J),parseInt(J.month),parseInt(J.day),parseInt(J.hour),parseInt(J.minute),parseInt(J.second))-j})($))}getOffsetNanosecondsFor($){return this.$.V(LW($))*c0}getPossibleInstantsFor($){let[Z,j]=[l3((J=$).isoYear,J.isoMonth,J.isoDay,J.isoHour,J.isoMinute,J.isoSecond),J.isoMillisecond*j1+J.isoMicrosecond*P$+J.isoNanosecond];var J;return this.$.G(Z).map((W)=>m0(i$(s$(W,c0),j)))}l($,Z){let[j,J]=HW($),W=this.$.l(j+(Z>0||J?1:0),Z);if(W!==void 0)return s$(W,c0)}}var a2="([+\u2212-])",c3="(?:[.,](\\d{1,9}))?",MY=`(?:(?:${a2}(\\d{6}))|(\\d{4}))-?(\\d{2})`,r2="(\\d{2})(?::?(\\d{2})(?::?(\\d{2})"+c3+")?)?",t2=a2+r2,bQ=MY+"-?(\\d{2})(?:[T ]"+r2+"(Z|"+t2+")?)?",PY="\\[(!?)([^\\]]*)\\]",h6=`((?:${PY}){0,9})`,vQ=JZ(MY+h6),wQ=JZ("(?:--)?(\\d{2})-?(\\d{2})"+h6),kQ=JZ(bQ+h6),qQ=JZ("T?"+r2+"(?:"+t2+")?"+h6),yQ=JZ(t2),gQ=new RegExp(PY,"g"),mQ=JZ(`${a2}?P(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(?:T(?:(\\d+)${c3}H)?(?:(\\d+)${c3}M)?(?:(\\d+)${c3}S)?)?`),pQ=b0(($)=>new l1(OY,{timeZone:$,era:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})),hQ=/^(AC|AE|AG|AR|AS|BE|BS|CA|CN|CS|CT|EA|EC|IE|IS|JS|MI|NE|NS|PL|PN|PR|PS|SS|VS)T$/,cQ=b0(SF),e2=b0(($)=>new l1(OY,{calendar:$,timeZone:H$,era:"short",year:"numeric",month:"short",day:"numeric"})),dQ=/^M(\d{2})(L?)$/,uQ={era:u3,eraYear:P0,year:P0,month:u5,monthCode:u3,day:u5},lQ=YZ(C1,P0),iQ=YZ(q,MW),ZW=Object.assign({},uQ,lQ,iQ,{offset:u3}),sQ=b(UF,C1,o0),jW={dateAdd($,Z,j){let J=k(j),W,{years:Y,months:z,weeks:X,days:G}=Z;if(G+=Q0(Z,5)[0],Y||z)W=((F,Q,O,K,D)=>{let[B,U,V]=F.h(Q);if(O){let[I,P]=F.I(B,U);B+=O,U=a3(I,P,F.U(B)),U=p0("month",U,1,F.L(B),D)}return K&&([B,U]=F._(B,U,K)),V=p0("day",V,1,F.j(B,U),D),F.q(B,U,V)})(this,$,Y,z,J);else{if(!X&&!G)return $;W=H0($)}return W+=(7*X+G)*R0,q1(Y6(W))},dateUntil($,Z,j){if(j<=7){let G=0,F=m7({...$,...d0},{...Z,...d0});return j===7&&([G,F]=g1(F,7)),{...U0,weeks:G,days:F}}let J=this.h($),W=this.h(Z),[Y,z,X]=((G,F,Q,O,K,D,B)=>{let U=K-F,V=D-Q,I=B-O;if(U||V){let P=Math.sign(U||V),M=G.j(K,D),x=0;if(Math.sign(I)===-P){let f=M;[K,D]=G._(K,D,-P),U=K-F,V=D-Q,M=G.j(K,D),x=P<0?-f:M}if(I=B-Math.min(O,M)+x,U){let[f,A]=G.I(F,Q),[_,L]=G.I(K,D);if(V=_-f||Number(L)-Number(A),Math.sign(V)===-P){let N=P<0&&-G.L(K);U=(K-=P)-F,V=D-a3(f,A,G.U(K))+(N||G.L(K))}}}return[U,V,I]})(this,...J,...W);return j===8&&(z+=this.J(Y,J[0]),Y=0),{...U0,years:Y,months:z,days:X}},dateFromFields($,Z){let j=k(Z),J=jj(this,$),W=Jj(this,$,J,j),Y=t5(this,$,W,J,j);return Y0(q1(this.P(J,W,Y)),this.id||v)},yearMonthFromFields($,Z){let j=k(Z),J=jj(this,$),W=Jj(this,$,J,j);return F$(Cj(this.P(J,W,1)),this.id||v)},monthDayFromFields($,Z){let j=k(Z),J=!this.id,{monthCode:W,year:Y,month:z}=$,X,G,F,Q,O;if(W!==void 0){[X,G]=l7(W),O=WW($,"day");let K=this.N(X,G,O);if(!K)throw RangeError(e5);if([F,Q]=K,z!==void 0&&z!==Q)throw RangeError(i9);J&&(Q=p0("month",Q,1,T1,1),O=p0("day",O,1,Sj(Y!==void 0?Y:F,Q),j))}else{F=Y===void 0&&J?o$:jj(this,$),Q=Jj(this,$,F,j),O=t5(this,$,Q,F,j);let K=this.U(F);G=Q===K,X=Gj(Q,K);let D=this.N(X,G,O);if(!D)throw RangeError(e5);[F,Q]=D}return i3(q1(this.P(F,Q,O)),this.id||v)},fields($){return Fj(this)&&$.includes("year")?[...$,...Oj]:$},mergeFields($,Z){let j=Object.assign(Object.create(null),$);return Wj(j,Z,p2),Fj(this)&&(Wj(j,Z,JQ),this.id===n$&&Wj(j,Z,WQ,Oj)),j},inLeapYear($){let[Z]=this.h($);return this.K(Z)},monthsInYear($){let[Z]=this.h($);return this.L(Z)},daysInMonth($){let[Z,j]=this.h($);return this.j(Z,j)},daysInYear($){let[Z]=this.h($);return this.X(Z)},dayOfYear:C2,era($){return this.ee($)[0]},eraYear($){return this.ee($)[1]},monthCode($){let[Z,j]=this.h($),[J,W]=this.I(Z,j);return((Y,z)=>"M"+h0(Y)+(z?"L":""))(J,W)},dayOfWeek:AW,daysInWeek(){return 7}},nQ={dayOfYear:C2,h:_W,q:r$},oQ=Object.assign({},nQ,{weekOfYear:d7,yearOfWeek:u7,R($){function Z(D){return(7-D<J?7:0)-D}function j(D){let B=xW(K+D),U=D||1,V=Z(gZ(G+B*U,7));return Q=(B+(V-F)*U)/7}let J=this.id?1:4,W=AW($),Y=this.dayOfYear($),z=gZ(W-1,7),X=Y-1,G=gZ(z-X,7),F=Z(G),Q,O=Math.floor((X-F)/7)+1,K=$.isoYear;return O?O>j(0)&&(O=1,K++):(O=j(-1),K--),[O,K,Q]}}),aQ={dayOfYear:C2,h:Xj,q:cZ,weekOfYear:d7,yearOfWeek:u7,R(){return[]}},GZ=fF(Object.assign({},jW,oQ,{h:_W,ee($){return this.id===k6?fW($):this.id===n$?VQ($):[]},I:($,Z)=>[Z,0],N($,Z){if(!Z)return[o$,$]},K:xj,U(){},L:SW,J:($)=>$*T1,j:Sj,X:xW,P:($,Z,j)=>({isoYear:$,isoMonth:Z,isoDay:j}),q:r$,_:($,Z,j)=>($+=e3(j,T1),(Z+=Tj(j,T1))<1?($--,Z+=T1):Z>T1&&($++,Z-=T1),[$,Z]),year($){return $.isoYear},month($){return $.isoMonth},day:($)=>$.isoDay}),Object.assign({},jW,aQ,{h:Xj,ee($){let Z=this.O($);return[Z.era,Z.eraYear]},I($,Z){let j=g3.call(this,$);return[Gj(Z,j),j===Z]},N($,Z,j){let[J,W,Y]=Xj.call(this,{isoYear:o$,isoMonth:T1,isoDay:31}),z=g3.call(this,J),X=W===z;(k1($,Gj(W,z))||k1(Number(Z),Number(X))||k1(j,Y))===1&&J--;for(let G=0;G<100;G++){let F=J-G,Q=g3.call(this,F),O=a3($,Z,Q);if(Z===(O===Q)&&j<=a5.call(this,F,O))return[F,O]}},K($){let Z=m3.call(this,$);return Z>m3.call(this,$-1)&&Z>m3.call(this,$+1)},U:g3,L:p3,J($,Z){let j=Z+$,J=Math.sign($),W=J<0?-1:0,Y=0;for(let z=Z;z!==j;z+=J)Y+=p3.call(this,z+W);return Y},j:a5,X:m3,P($,Z,j){return Y6(cZ.call(this,$,Z,j))},q:cZ,_($,Z,j){if(j){if(Z+=j,!Number.isSafeInteger(Z))throw RangeError(E6);if(j<0)for(;Z<1;)Z+=p3.call(this,--$);else{let J;for(;Z>(J=p3.call(this,$));)Z-=J,$++}}return[$,Z]},year($){return this.O($).year},month($){let{year:Z,F:j}=this.O($),{C:J}=this.B(Z);return J[j]+1},day($){return this.O($).day}})),y1="numeric",FZ=["timeZoneName"],NY={month:y1,day:y1},$4={year:y1,month:y1},Z4=Object.assign({},$4,{day:y1}),j4={hour:y1,minute:y1,second:y1},J4=Object.assign({},Z4,j4),rQ=Object.assign({},J4,{timeZoneName:"short"}),tQ=Object.keys($4),eQ=Object.keys(NY),$K=Object.keys(Z4),ZK=Object.keys(j4),W4=["dateStyle"],jK=tQ.concat(W4),JK=eQ.concat(W4),Y4=$K.concat(W4,["weekday"]),Y3=ZK.concat(["dayPeriod","timeStyle"]),z4=Y4.concat(Y3),WK=z4.concat(FZ),YK=FZ.concat(Y3),zK=FZ.concat(Y4),XK=FZ.concat(["day","weekday"],Y3),GK=FZ.concat(["year","weekday"],Y3),FK={},X4=[M$(z4,J4),Q6],LY=[M$(WK,rQ),Q6,0,($,Z)=>{let j=D0($.timeZone);if(Z&&D0(Z.timeZone)!==j)throw RangeError(n9);return j}],G4=[M$(z4,J4,FZ),H0],F4=[M$(Y4,Z4,YK),H0],Q4=[M$(Y3,j4,zK),($)=>m1($)/j1],K4=[M$(jK,$4,XK),H0,1],O4=[M$(JK,NY,GK),H0,1],JW;function Y1($,Z,j,J,W){function Y(...G){if(!(this instanceof Y))throw TypeError(y2);SY(this,Z(...G))}function z(G,F){return Object.defineProperties(function(...Q){return G.call(this,X(this),...Q)},Dj(F))}function X(G){let F=M0(G);if(!F||F.branding!==$)throw TypeError(y2);return F}return Object.defineProperties(Y.prototype,{...YW(u0(z,j)),...K$(u0(z,J)),...t3("Temporal."+$)}),Object.defineProperties(Y,{...K$(W),...Dj($)}),[Y,(G)=>{let F=Object.create(Y.prototype);return SY(F,G),F},X]}function fY($){return $=$.concat("id").sort(),(Z)=>{if(!zW(Z,$))throw TypeError(s9);return Z}}function BZ($){if(M0($)||$.calendar!==void 0||$.timeZone!==void 0)throw TypeError(d9);return $}function c6($,Z){let j={};for(let J in $)j[J]=({o:W},Y)=>{let z=M0(Y)||{},{branding:X}=z,G=X===N$||Z.includes(X)?z:x0(Y);return W[J](G)};return j}function U4($){let Z={};for(let j in $)Z[j]=(J)=>{let{calendar:W}=J;return(Y=W,typeof Y=="string"?GZ(Y):(z=Y,Object.assign(Object.create(_K),{i:z})))[j](J);var Y,z};return Z}function a1(){throw TypeError(l9)}function X3({calendar:$}){return typeof $=="string"?new C4($):$}function HY($,Z){if(Z=J0(Z),K0($)){let J=M0($);if(J&&J.branding===XZ)return k(Z),J;let W=bY($);return x2(o6(W||v),!W,$,Z)}let j=U7(GZ,$);return k(Z),j}function EY($,Z,j){return J=Z.call($,S0(O0(j))),nj(sZ(J));var J}function d6($,Z=qY){let j=Object.keys(Z).sort(),J={};for(let W of j)J[W]=b(Z[W],$,GY($[W]));return J}function p($,Z){return typeof $=="string"?p6($):d6($,Z)}function X0($){return p($,D4)}function J1($){if(K0($)){let Z=M0($);if(Z)switch(Z.branding){case g6:return Z;case _1:return O0(Z.epochNanoseconds)}}return Q7($)}function CY($,Z,j){let J=Z.l(J1(j).epochNanoseconds,$);return J?S0(O0(J)):null}function u($){return K0($)?(M0($)||{}).timeZone||RK($):((Z)=>H6(M7(a(Z))))($)}function i1($,Z){if(K0($)){let j=M0($)||{};switch(j.branding){case y6:return k(Z),j;case L$:return k(Z),s0(j);case _1:return k(Z),v2(X0,j)}return t7($,Z)}return k(Z),V7($)}function V4($){return $===void 0?void 0:i1($)}function QZ($,Z){if(Z=J0(Z),K0($)){let J=M0($);return J&&J.branding===zZ?(k(Z),J):S2(s6(G3($)),$,Z)}let j=D7(GZ,$);return k(Z),j}function s1($,Z){if(Z=J0(Z),K0($)){let J=M0($)||{};switch(J.branding){case L$:return k(Z),J;case N$:return k(Z),W0({...J,...d0});case _1:return k(Z),R2(X0,J)}return r7(n6(G3($)),$,Z)}let j=B7($);return k(Z),j}function x0($,Z){if(Z=J0(Z),K0($)){let J=M0($)||{};switch(J.branding){case N$:return k(Z),J;case L$:return k(Z),Y0(J);case _1:return k(Z),b2(X0,J)}return _2(n6(G3($)),$,Z)}let j=N6($);return k(Z),j}function RY($,Z,j){return l0(Z.call($,t(Y0(j,$))))}function z1($){return(Z)=>typeof Z=="string"?GZ(Z):((j,J)=>{let W=Object.keys(J).sort(),Y={};for(let z of W)Y[z]=b(J[z],j,j[z]);return Y})(Z,$)}function r($){if(K0($)){let Z=M0($);return Z&&Z.branding===m6?Z:e7($)}return T7($)}function z3($){if($!==void 0){if(K0($)){let Z=M0($)||{};switch(Z.branding){case _1:case N$:return Z;case L$:return Y0(Z)}let j=G3($);return{...o7(u,p,n6(j),$),calendar:j}}return K7($)}}function G3($){return bY($)||v}function bY($){let{calendar:Z}=$;if(Z!==void 0)return I0(Z)}function I0($){return K0($)?(M0($)||{}).calendar||iK($):((Z)=>aZ(I7(a(Z))))($)}function KZ($,Z){if(Z=J0(Z),K0($)){let j=M0($);if(j&&j.branding===_1)return nZ(Z),j;let J=G3($);return a7(u,p,n6(J),J,$,Z)}return O7($,Z)}function _Y($){return u0((Z)=>(j)=>Z(B4(j)),$)}function B4($){return C0($,X0)}function QK(){let $=l1.prototype,Z=Object.getOwnPropertyDescriptors($),j=Object.getOwnPropertyDescriptors(l1),J=function(W,Y={}){if(!(this instanceof J))return new J(W,Y);_4.set(this,((z,X={})=>{let G=new l1(z,X),F=G.resolvedOptions(),Q=F.locale,O=w0(Object.keys(X),F),K=b0(BK),D=(...B)=>{let U,V=B.map((I,P)=>{let M=M0(I),x=(M||{}).branding;if(P&&U&&U!==x)throw TypeError(a9);return U=x,M});return U?K(U)(Q,O,...V):[G,...B]};return D.u=G,D})(W,Y))};for(let W in Z){let Y=Z[W],z=W.startsWith("format")&&KK(W);typeof Y.value=="function"?Y.value=W==="constructor"?J:z||OK(W):z&&(Y.get=function(){return z.bind(this)})}return j.prototype.value=Object.create($,Z),Object.defineProperties(J,j),J}function KK($){return function(...Z){let j=_4.get(this),[J,...W]=j(...Z);return J[$](...W)}}function OK($){return function(...Z){return _4.get(this).u[$](...Z)}}function BK($){let Z=DK[$];if(!Z)throw TypeError(o9($));return L1(Z,b0(w2))}var DK={Instant:X4,PlainDateTime:G4,PlainDate:F4,PlainTime:Q4,PlainYearMonth:K4,PlainMonthDay:O4},UK=L1(X4),VK=L1(LY),TK=L1(G4),IK=L1(F4),MK=L1(Q4),PK=L1(K4),NK=L1(O4),T4={era:BW,eraYear:Ij,year:sZ,month:l0,daysInMonth:l0,daysInYear:l0,inLeapYear:XY,monthsInYear:l0},l6={monthCode:a},I4={day:l0},vY={dayOfWeek:l0,dayOfYear:l0,weekOfYear:DW,yearOfWeek:Ij,daysInWeek:l0},wY=Object.assign({},T4,l6,I4,vY),u6=new WeakMap,M0=u6.get.bind(u6),SY=u6.set.bind(u6),LK={...c6(T4,[zZ]),...c6(vY,[]),...c6(l6,[zZ,XZ]),...c6(I4,[XZ])},M4=U4(wY),HK=U4({...T4,...l6}),CK=U4({...l6,...I4}),F3={calendarId:($)=>D0($.calendar)},_K=u0(($,Z)=>function(j){let{i:J}=this;return $(J[Z](t(Y0(j,J))))},wY),SK=lZ(($)=>(Z)=>Z[$],q.concat("sign")),P4=lZ(($,Z)=>(j)=>j[o0[Z]],C1),kY={epochSeconds:qW,epochMilliseconds:Q6,epochMicroseconds:yW,epochNanoseconds:gW},Q3=b(Uj,new Set(["branding"])),[xK,OZ,AK]=Y1(XZ,b(B9,I0),{...F3,...CK},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return OZ(W9(dK,$,this,BZ(Z),j))},equals:($,Z)=>v7($,HY(Z)),toPlainDate($,Z){return t(x9(K3,$,this,Z))},toLocaleString($,Z,j){let[J,W]=NK(Z,j,$);return J.format(W)},toString:dj,toJSON:($)=>dj($),valueOf:a1},{from:($,Z)=>OZ(HY($,Z))}),qY={getOffsetNanosecondsFor:EY,getPossibleInstantsFor($,Z,j){let J=[...Z.call($,T0(W0(j,v)))].map((Y)=>EK(Y).epochNanoseconds),W=J.length;return W>1&&(J.sort(L0),oj(g0(y0(J[0],J[W-1])))),J}},D4={getOffsetNanosecondsFor:EY},[fK,S0,EK]=Y1(g6,G9,kY,{add:($,Z)=>S0(aj(0,$,r(Z))),subtract:($,Z)=>S0(aj(1,$,r(Z))),until:($,Z,j)=>h(T2(0,$,J1(Z),j)),since:($,Z,j)=>h(T2(1,$,J1(Z),j)),round:($,Z)=>S0(hW($,Z)),equals:($,Z)=>A7($,J1(Z)),toZonedDateTime($,Z){let j=P1(Z);return z0(E2($,u(j.timeZone),I0(j.calendar)))},toZonedDateTimeISO:($,Z)=>z0(E2($,u(Z))),toLocaleString($,Z,j){let[J,W]=UK(Z,j,$);return J.format(W)},toString:($,Z)=>gj(u,X0,$,Z),toJSON:($)=>gj(u,X0,$),valueOf:a1},{from:($)=>S0(J1($)),fromEpochSeconds:($)=>S0(E9($)),fromEpochMilliseconds:($)=>S0(R9($)),fromEpochMicroseconds:($)=>S0(b9($)),fromEpochNanoseconds:($)=>S0(v9($)),compare:($,Z)=>D2(J1($),J1(Z))}),[i6,IV]=Y1("TimeZone",($)=>{let Z=S7($);return{branding:"TimeZone",id:Z,o:p6(Z)}},{id:($)=>$.id},{getPossibleInstantsFor:({o:$},Z)=>$.getPossibleInstantsFor(s1(Z)).map((j)=>S0(O0(j))),getOffsetNanosecondsFor:({o:$},Z)=>$.getOffsetNanosecondsFor(J1(Z).epochNanoseconds),getOffsetStringFor($,Z){let j=J1(Z).epochNanoseconds,J=d6(this,D4).getOffsetNanosecondsFor(j);return D$(J)},getPlainDateTimeFor($,Z,j=v){let J=J1(Z).epochNanoseconds,W=d6(this,D4).getOffsetNanosecondsFor(J);return T0(W0(h1(J,W),I0(j)))},getInstantFor($,Z,j){let J=s1(Z),W=Aj(j),Y=d6(this);return S0(O0(v0(Y,J,W)))},getNextTransition:({o:$},Z)=>CY(1,$,Z),getPreviousTransition:({o:$},Z)=>CY(-1,$,Z),equals($,Z){return!!_6(this,u(Z))},toString:($)=>$.id,toJSON:($)=>$.id},{from($){let Z=u($);return typeof Z=="string"?new i6(Z):Z}}),RK=fY(Object.keys(qY)),[bK,n1]=Y1(y6,D9,P4,{getISOFields:Q3,with($,Z,j){return n1(Y9(this,BZ(Z),j))},add:($,Z)=>n1(Z2(0,$,r(Z))),subtract:($,Z)=>n1(Z2(1,$,r(Z))),until:($,Z,j)=>h(L2(0,$,i1(Z),j)),since:($,Z,j)=>h(L2(1,$,i1(Z),j)),round:($,Z)=>n1(uW($,Z)),equals:($,Z)=>w7($,i1(Z)),toZonedDateTime:($,Z)=>z0(A9(u,x0,p,$,Z)),toPlainDateTime:($,Z)=>T0(f9($,x0(Z))),toLocaleString($,Z,j){let[J,W]=MK(Z,j,$);return J.format(W)},toString:uj,toJSON:($)=>uj($),valueOf:a1},{from:($,Z)=>n1(i1($,Z)),compare:($,Z)=>C6(i1($),i1(Z))}),[vK,o1,wK]=Y1(zZ,b(O9,I0),{...F3,...HK},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return o1(J9(cK,$,this,BZ(Z),j))},add:($,Z,j)=>o1($2(xY,0,$,r(Z),j)),subtract:($,Z,j)=>o1($2(xY,1,$,r(Z),j)),until:($,Z,j)=>h(N2(AY,0,$,QZ(Z),j)),since:($,Z,j)=>h(N2(AY,1,$,QZ(Z),j)),equals:($,Z)=>b7($,QZ(Z)),toPlainDate($,Z){return t(S9(K3,$,this,Z))},toLocaleString($,Z,j){let[J,W]=PK(Z,j,$);return J.format(W)},toString:cj,toJSON:($)=>cj($),valueOf:a1},{from:($,Z)=>o1(QZ($,Z)),compare:($,Z)=>T$(QZ($),QZ(Z))}),[kK,T0]=Y1(L$,b(Q9,I0),{...F3,...M4,...P4},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return T0(Z9(K3,$,this,BZ(Z),j))},withCalendar:($,Z)=>T0(f6($,I0(Z))),withPlainDate:($,Z)=>T0(y9($,x0(Z))),withPlainTime:($,Z)=>T0(q9($,V4(Z))),add:($,Z,j)=>T0(tj(C$,0,$,r(Z),j)),subtract:($,Z,j)=>T0(tj(C$,1,$,r(Z),j)),until:($,Z,j)=>h(M2(W1,0,$,s1(Z),j)),since:($,Z,j)=>h(M2(W1,1,$,s1(Z),j)),round:($,Z)=>T0(dW($,Z)),equals:($,Z)=>E7($,s1(Z)),toZonedDateTime:($,Z,j)=>z0(M9(p,$,u(Z),j)),toPlainDate:($)=>t(Y0($)),toPlainTime:($)=>n1(s0($)),toPlainYearMonth($){return o1(P9(s6,$,this))},toPlainMonthDay($){return OZ(N9(o6,$,this))},toLocaleString($,Z,j){let[J,W]=TK(Z,j,$);return J.format(W)},toString:pj,toJSON:($)=>pj($),valueOf:a1},{from:($,Z)=>T0(s1($,Z)),compare:($,Z)=>V2(s1($),s1(Z))}),[qK,t,yY]=Y1(N$,b(K9,I0),{...F3,...M4},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return t(j9(K3,$,this,BZ(Z),j))},withCalendar:($,Z)=>t(f6($,I0(Z))),add:($,Z,j)=>t(ej(C$,0,$,r(Z),j)),subtract:($,Z,j)=>t(ej(C$,1,$,r(Z),j)),until:($,Z,j)=>h(P2(W1,0,$,x0(Z),j)),since:($,Z,j)=>h(P2(W1,1,$,x0(Z),j)),equals:($,Z)=>R7($,x0(Z)),toZonedDateTime($,Z){let j=!K0(Z)||Z instanceof i6?{timeZone:Z}:Z;return z0(L9(u,i1,p,$,j))},toPlainDateTime:($,Z)=>T0(H9($,V4(Z))),toPlainYearMonth($){return o1(C9(s6,$,this))},toPlainMonthDay($){return OZ(_9(o6,$,this))},toLocaleString($,Z,j){let[J,W]=IK(Z,j,$);return J.format(W)},toString:hj,toJSON:($)=>hj($),valueOf:a1},{from:($,Z)=>t(x0($,Z)),compare:($,Z)=>T$(x0($),x0(Z))}),N4={fields($,Z,j){return[...Z.call($,j)]}},gY=Object.assign({dateFromFields($,Z,j,J){return yY(Z.call($,Object.assign(Object.create(null),j),J))}},N4),mY=Object.assign({yearMonthFromFields($,Z,j,J){return wK(Z.call($,Object.assign(Object.create(null),j),J))}},N4),pY=Object.assign({monthDayFromFields($,Z,j,J){return AK(Z.call($,Object.assign(Object.create(null),j),J))}},N4),L4={mergeFields($,Z,j,J){return P1(Z.call($,Object.assign(Object.create(null),j),Object.assign(Object.create(null),J)))}},yK=Object.assign({},gY,L4),gK=Object.assign({},mY,L4),mK=Object.assign({},pY,L4),H4={dateAdd($,Z,j,J,W){return yY(Z.call($,t(Y0(j,$)),h(i(J)),W))}},hY=Object.assign({},H4,{dateUntil($,Z,j,J,W,Y){return lK(Z.call($,t(Y0(j,$)),t(Y0(J,$)),Object.assign(Object.create(null),Y,{largestUnit:Z3[W]})))}}),pK=Object.assign({},H4,{day:RY}),hK=Object.assign({},hY,{day:RY}),s6=z1(mY),n6=z1(gY),o6=z1(pY),cK=z1(gK),K3=z1(yK),dK=z1(mK),C$=z1(H4),W1=z1(hY),xY=z1(pK),AY=z1(hK),[uK,h,lK]=Y1(m6,U9,{...SK,blank:X7},{with:($,Z)=>h(z9($,Z)),negated:($)=>h(M6($)),abs:($)=>h(z7($)),add:($,Z,j)=>h(z2(z3,W1,p,0,$,r(Z),j)),subtract:($,Z,j)=>h(z2(z3,W1,p,1,$,r(Z),j)),round:($,Z)=>h(Y7(z3,W1,p,$,Z)),total:($,Z)=>pW(z3,W1,p,$,Z),toLocaleString($,Z,j){return Intl.DurationFormat?new Intl.DurationFormat(Z,j).format(this):D6($)},toString:D6,toJSON:($)=>D6($),valueOf:a1},{from:($)=>h(r($)),compare:($,Z,j)=>x7(z3,C$,p,r($),r(Z),j)}),cY={toString:($)=>$.id,toJSON:($)=>$.id,...LK,dateAdd:({id:$,o:Z},j,J,W)=>t(Y0(Z.dateAdd(x0(j),r(J),W),$)),dateUntil:({o:$},Z,j,J)=>h(i($.dateUntil(x0(Z),x0(j),RW(J)))),dateFromFields:({id:$,o:Z},j,J)=>t(_2(Z,j,J,OW($))),yearMonthFromFields:({id:$,o:Z},j,J)=>o1(S2(Z,j,J,QW($))),monthDayFromFields:({id:$,o:Z},j,J)=>OZ(x2(Z,0,j,J,KW($))),fields({o:$},Z){let j=new Set(n0),J=[];for(let W of Z){if(a(W),!j.has(W))throw RangeError(q2(W));j.delete(W),J.push(W)}return $.fields(J)},mergeFields:({o:$},Z,j)=>$.mergeFields(Vj(Mj(Z)),Vj(Mj(j)))},[C4]=Y1("Calendar",($)=>{let Z=c7($);return{branding:"Calendar",id:Z,o:GZ(Z)}},{id:($)=>$.id},cY,{from($){let Z=I0($);return typeof Z=="string"?new C4(Z):Z}}),iK=fY(Object.keys(cY).slice(4)),[sK,z0]=Y1(_1,b(F9,I0,u),{...kY,...F3,..._Y(M4),..._Y(P4),offset:($)=>D$(B4($).offsetNanoseconds),offsetNanoseconds:($)=>B4($).offsetNanoseconds,timeZoneId:($)=>D0($.timeZone),hoursInDay:($)=>lW(p,$)},{getISOFields:($)=>J7(X0,$),getCalendar:X3,getTimeZone:({timeZone:$})=>typeof $=="string"?new i6($):$,with($,Z,j){return z0($9(K3,p,$,this,BZ(Z),j))},withCalendar:($,Z)=>z0(f6($,I0(Z))),withTimeZone:($,Z)=>z0(g9($,u(Z))),withPlainDate:($,Z)=>z0(k9(p,$,x0(Z))),withPlainTime:($,Z)=>z0(w9(p,$,V4(Z))),add:($,Z,j)=>z0(rj(C$,p,0,$,r(Z),j)),subtract:($,Z,j)=>z0(rj(C$,p,1,$,r(Z),j)),until:($,Z,j)=>h(i(I2(W1,p,0,$,KZ(Z),j))),since:($,Z,j)=>h(i(I2(W1,p,1,$,KZ(Z),j))),round:($,Z)=>z0(cW(p,$,Z)),startOfDay:($)=>z0(iW(p,$)),equals:($,Z)=>f7($,KZ(Z)),toInstant:($)=>S0(V9($)),toPlainDateTime:($)=>T0(R2(X0,$)),toPlainDate:($)=>t(b2(X0,$)),toPlainTime:($)=>n1(v2(X0,$)),toPlainYearMonth($){return o1(T9(s6,$,this))},toPlainMonthDay($){return OZ(I9(o6,$,this))},toLocaleString($,Z,j={}){let[J,W]=VK(Z,j,$);return J.format(W)},toString:($,Z)=>mj(X0,$,Z),toJSON:($)=>mj(X0,$),valueOf:a1},{from:($,Z)=>z0(KZ($,Z)),compare:($,Z)=>U2(KZ($),KZ(Z))}),nK=Object.defineProperties({},{...t3("Temporal.Now"),...K$({timeZoneId:()=>H1(),instant:()=>S0(O0(tZ())),zonedDateTime:($,Z=H1())=>z0(V0(tZ(),u(Z),I0($))),zonedDateTimeISO:($=H1())=>z0(V0(tZ(),u($),v)),plainDateTime:($,Z=H1())=>T0(W0(WZ(X0(u(Z))),I0($))),plainDateTimeISO:($=H1())=>T0(W0(WZ(X0(u($))),v)),plainDate:($,Z=H1())=>t(Y0(WZ(X0(u(Z))),I0($))),plainDateISO:($=H1())=>t(Y0(WZ(X0(u($))),v)),plainTimeISO:($=H1())=>n1(s0(WZ(X0(u($)))))})}),DZ=Object.defineProperties({},{...t3("Temporal"),...K$({PlainYearMonth:vK,PlainMonthDay:xK,PlainDate:qK,PlainTime:bK,PlainDateTime:kK,ZonedDateTime:sK,Instant:fK,Calendar:C4,TimeZone:i6,Duration:uK,Now:nK})}),oK=QK(),_4=new WeakMap,aK=Object.defineProperties(Object.create(Intl),K$({DateTimeFormat:oK}));class S4 extends Error{code;constructor($,Z=`OAuth callback failed: ${$}`){super(Z);this.name="OAuthCallbackError",this.code=$}}class rK{}import{createHash as x4,createHmac as tK,randomBytes as dY,timingSafeEqual as iY}from"crypto";var B3=600,a6="gemi_oauth",eK=`__Host-${a6}`;function UZ($,Z=a6){if(Z===a6)return $?eK:a6;return $?`__Host-${Z}`:Z}function O3($){return $.toString("base64url")}function sY($){return tK("sha256",c$()).update(`gemi-oauth-state:${$}`).digest()}function uY($,Z){let j=x4("sha256").update($).digest(),J=x4("sha256").update(Z).digest();return iY(j,J)&&$.length===Z.length}function r6($,Z=Date.now(),j={}){let J=O3(dY(32)),W=O3(dY(32)),Y=$O(W),z={provider:$,state:J,codeVerifier:W,expiresAt:Z+B3*1000,...j.subject!==void 0?{subject:j.subject}:{},...j.returnTo!==void 0?{returnTo:j.returnTo}:{}};return{state:J,codeVerifier:W,codeChallenge:Y,cookieValue:ZO(z)}}function $O($){return O3(x4("sha256").update($).digest())}function ZO($){let Z=O3(Buffer.from(JSON.stringify($)));return`${Z}.${O3(sY(Z))}`}function jO($){if(typeof $!=="string"||$==="")return null;let Z=$.indexOf(".");if(Z<=0||Z!==$.lastIndexOf("."))return null;let j=$.slice(0,Z),J=Buffer.from($.slice(Z+1),"base64url"),W=sY(j);if(J.length!==W.length||!iY(J,W))return null;try{let Y=JSON.parse(Buffer.from(j,"base64url").toString("utf8"));if(typeof Y?.provider!=="string"||typeof Y?.state!=="string"||typeof Y?.codeVerifier!=="string"||typeof Y?.expiresAt!=="number"||Y.subject!==void 0&&typeof Y.subject!=="string"||Y.returnTo!==void 0&&typeof Y.returnTo!=="string")return null;return Y}catch{return null}}var r1=new Map,lY=1e4;function JO($,Z,j){if(r1.size>=lY){for(let[J,W]of r1)if(W<=j)r1.delete(J);while(r1.size>=lY){let J=r1.keys().next().value;if(J===void 0)break;r1.delete(J)}}r1.set($,Z)}function t6($){let Z=$.now??Date.now();if(!$.cookieValue||!$.returnedState)return{ok:!1,reason:"missing_state"};let j=jO($.cookieValue);if(!j)return{ok:!1,reason:"invalid_state"};let J=uY(j.state,$.returnedState),W=uY(j.provider,$.provider);if(!J||!W)return{ok:!1,reason:"invalid_state"};if(j.expiresAt<=Z)return{ok:!1,reason:"expired_state"};if(r1.has(j.state))return{ok:!1,reason:"invalid_state"};return JO(j.state,j.expiresAt,Z),{ok:!0,payload:j}}var A4=new WeakMap;function YO($){let Z=A4.get($);if(!Z)Z=$(WO(32).toString("hex")),A4.set($,Z),Z.catch(()=>A4.delete($));return Z}async function f4($,Z,j){if(typeof j==="string"&&j!=="")return await $.verifyPassword(Z,j);try{await $.verifyPassword(Z,await YO($.hashPassword))}catch{}return!1}async function _$($,Z){let j=Z.user??Z.session?.user;if(!j||!$.onAuthenticated)return;let{password:J,...W}=j;await $.onAuthenticated({...Z,user:W})}class R4 extends Error{}function E4($){return typeof $==="string"&&$!==""?$:null}function nY($){return qZ($)}var zO=256;function oY($){return typeof $==="string"&&$!==""&&$.length<=zO?$:null}var e6="intended_url";function rY($){if($.cookies.get(e6))$.ctx().setCookie(e6,"",{maxAge:-1})}function aY($){let Z=$.cookies.get(e6);if(!Z)return null;rY($);try{return U1(decodeURIComponent(Z),"")||null}catch{return null}}class b4 extends S{schema={email:{required:"Email is required",string:"Invalid email",email:"Invalid email"},password:{required:"Password is required"}}}class tY extends S{schema={email:{required:"Email is required",email:"Invalid email"}}}class eY extends S{schema={password:{required:"Password is required",password:"Invalid password"}}}class s extends wZ{async me(){let $=await X1.user();if(!$)throw new l8;return $}async verifyEmail($=new S){let Z=await $.input(),{userProvider:j}=T(E),J=E4(Z.get("token"));if(!J)return{email:null};let W=await j.findUserByVerificationToken(J);if(!W)return{email:null};return await j.verifyUser(W.email),{email:W.email}}async signInWithMagicLink($=new S){let Z=T(E),{userProvider:j}=Z,J=E4($.search.get("token")),W=null;try{W=qZ(decodeURIComponent($.search.get("email")??""))}catch{}if(await d$("link",null,$,{perIp:Z.config.emailCode.verifyLimit.perIp}),!W||!J||!await Z.verifyMagicLinkToken(W,J))return{error:"Invalid token"};await j.verifyUser(W);let Y=await Z.createOrUpdateSession({email:W});return $.ctx().setCookie("access_token",Y.token,T(E).accessTokenCookieOptions($,Y.expiresAt)),await Z.config.onSignIn(Y,$.search.toJSON()),await _$(Z.config,{session:Y,isNewUser:!1,method:"magic-link",req:$}),{session:Y}}async verifyPinRequest($){let Z=T(E),j=await $.input(),{email:J,pin:W}=j.toJSON(),Y=qZ(J),z=oY(W);if(await d$("verify",Y,$,Z.config.emailCode.verifyLimit),!Y||!z)throw new g({pin:["Invalid pin"]});let X=await Z.verifyOneTimeCode(Y,z);if(X.status==="too_many_attempts")throw new g({pin:["Too many attempts"]});if(X.status!=="ok")throw new g({pin:["Invalid pin"]});return await Z.userProvider.verifyUser(Y),Y}async signInWithPinV2($=new S){let Z=T(E),j=await this.verifyPinRequest($),J=await Z.createOrUpdateSessionV2({email:j});return $.ctx().setCookie("access_token",J.token,T(E).accessTokenCookieOptions($,J.expiresAt)),await Z.config.onSignIn(J,$.search.toJSON()),await _$(Z.config,{session:J,isNewUser:!1,method:"magic-link",req:$}),J}async signInWithPin($=new S){let Z=T(E),j=await this.verifyPinRequest($),J=await Z.createOrUpdateSession({email:j});return $.ctx().setCookie("access_token",J.token,T(E).accessTokenCookieOptions($,J.expiresAt)),await Z.config.onSignIn(J,$.search.toJSON()),await _$(Z.config,{session:J,isNewUser:!1,method:"magic-link",req:$}),{session:J}}async signInV2($=new b4){let Z=await $.input(),{email:j,password:J}=Z.toJSON(),W=j.toLowerCase().trim(),Y=T(E),z=await Y.userProvider.findUserByEmailAddress(W,Y.config.verifyEmail),X=typeof J==="string"&&await f4(Y.config,J,z?.password);if(!z||!X)throw new g({invalid_credentials:["Invalid credentials"]});let G=await Y.createOrUpdateSessionV2({email:z.email,id:z.id});$.ctx().setCookie("access_token",G.token,T(E).accessTokenCookieOptions($,G.expiresAt)),await Y.config.onSignIn(z,$.search.toJSON()),await _$(Y.config,{session:G,user:z,isNewUser:!1,method:"password",req:$});let{password:F,...Q}=z;return Q}async signIn($=new b4){let Z=await $.input(),{email:j,password:J}=Z.toJSON(),W=j.toLowerCase().trim(),Y=T(E),z=await Y.userProvider.findUserByEmailAddress(W,Y.config.verifyEmail),X=typeof J==="string"&&await f4(Y.config,J,z?.password);if(!z||!X)throw new g({invalid_credentials:["Invalid credentials"]});let G=await Y.createOrUpdateSession({email:z.email,id:z.id});$.ctx().setCookie("access_token",G.token,T(E).accessTokenCookieOptions($,G.expiresAt)),await Y.config.onSignIn(z,$.search.toJSON()),await _$(Y.config,{session:G,user:z,isNewUser:!1,method:"password",req:$});let{password:F,...Q}=z;return Q}async signUp(){let $=T(E),{userProvider:Z,config:j}=$,J=new j.signUpRequest,W=await J.input(),{email:Y,password:z,name:X,invitationId:G}=W.toJSON(),F=nY(Y);if(!F)throw new g({email:["Invalid email"]});if(z!=null&&typeof z!=="string")throw new g({password:["Invalid password"]});if(G!=null&&typeof G!=="string")throw new g({invitationId:["Invalid invitation"]});if(await Z.findUserByEmailAddress(F,!1))throw new g({email:["Email address already exists"]});let O=await j.hashPassword(z),K=T(o).detectLocale(J),D;if(G)D=await Z.findInvitation(G,F);let B,U="";if(D)B=await Z.transaction(async()=>{await Z.deleteInvitationById(G);let V=await Z.createUser({email:F,name:X,password:O,emailVerifiedAt:new Date,locale:K});return await Z.createAccount({organizationId:D.organizationId,userId:V.id,organizationRole:D.role}),await j.onUserCreated(V),V});else U=await j.generateEmailVerificationToken(F),B=await Z.transaction(async()=>{let V=await Z.createUser({email:F,name:X,password:O,verificationToken:U,locale:K});return await j.onUserCreated(V),V});return await j.onSignUp(B,U,J.search.toJSON()),B}async signOut($=new S){let Z=k8($),j=T(E),{config:J}=j,W=await j.revokeSession(Z,$.headers.get("User-Agent"));if($.ctx().setCookie("access_token","",T(E).accessTokenCookieOptions($,new Date(0))),T(E).cookieDomain($))$.ctx().setCookie("access_token","",{...T(E).accessTokenCookieOptions($,new Date(0)),domain:void 0});if(W?.user)W.user.extension=await J.extendSession(W.user),await J.onSignOut(W.user);return{}}async forgotPassword($=new tY){let Z=await $.input(),j=nY(Z.get("email"));if(!j)return{};let{userProvider:J,config:W}=T(E),Y=await J.findUserByEmailAddress(j,W.verifyEmail);if(!Y)return{};let z=await W.generateForgotPasswordToken(Y);return await J.createPasswordResetToken({user:Y,token:z}),await W.onForgotPassword(Y,z),{}}async resetPassword($=new eY){let{userProvider:Z,config:j}=T(E),J=await $.input(),{password:W,token:Y}=J.toJSON(),z=E4(Y),X=z?await Z.findPasswordResetToken({token:z}):null;if(!X)throw new g({token:["Invalid token"]});if(DZ.Instant.from(X.createdAt.toISOString()).add({hours:24}).until(DZ.Now.instant()).sign>=0)throw new g({token:["Token expired"]});await Z.deletePasswordResetToken({token:z});let F=await Z.findUserByEmailAddress(X.user.email,j.verifyEmail);if(!F)throw new g({email:["User not found"]});let Q=await j.hashPassword(W);return await Z.updateUserPassword({id:F.id,password:Q}),await Z.deleteAllUserSessions(F.id),await j.onResetPassword(F),{}}async changePassword($=new S){let{userProvider:Z,config:j}=T(E),J=await X1.user(),W=await $.input(),{oldPassword:Y,newPassword:z}=W.toJSON();if(typeof z!=="string")throw new g({newPassword:["Invalid password"]});let X=await Z.findUserByEmailAddress(J.email,j.verifyEmail);if(!(typeof Y==="string"&&await f4(j,Y,X?.password)))throw new g({oldPassword:["Incorrect password"]});let F=await j.hashPassword(z);return await Z.updateUserPassword({id:J.id,password:F}),await Z.deleteAllUserSessions(J.id),{}}async oauthRedirect($=new S){let{provider:Z}=$.params,j=T(E).config.oauthProviders[Z];if(!j)throw Error(`Invalid provider: ${Z}`);let J=y$($.rawRequest),W=U1($.search.get(D1),"");if(W)$.ctx().setCookie(e6,encodeURIComponent(W),{httpOnly:!0,sameSite:"Lax",secure:J,maxAge:600});else rY($);let{state:Y,codeChallenge:z,cookieValue:X}=r6(Z);return $.ctx().setCookie(UZ(J),X,{httpOnly:!0,sameSite:"Lax",secure:J,maxAge:B3}),{destination:await j.getRedirectUrl($,{state:Y,codeChallenge:z,codeChallengeMethod:"S256"})}}async oauthCallback($=new S){let{provider:Z}=$.params,j=T(E),{userProvider:J,config:W}=j,Y=W.oauthProviders[Z],z=y$($.rawRequest),X=UZ(z),G=$.cookies.get(X);if(G!==void 0&&G!==null)$.ctx().setCookie(X,"",{httpOnly:!0,sameSite:"Lax",secure:z,maxAge:-1});if(!Y)return this.oauthFailure($,"unknown_provider");let F=$.search.get("error");if(F)return this.oauthFailure($,/^[a-z0-9_]{1,64}$/.test(F)?F:"provider_error");let Q=t6({provider:Z,cookieValue:G,returnedState:$.search.get("state")});if("reason"in Q)return console.error(`Authentication error: OAuth callback refused (${Q.reason})`),this.oauthFailure($,Q.reason);if(!$.search.get("code"))return this.oauthFailure($,"missing_code");let O;try{O=await Y.onCallback($,{state:Q.payload.state,codeVerifier:Q.payload.codeVerifier})}catch(A){if(A instanceof S4)return this.oauthFailure($,A.code);return console.error("Authentication error: OAuth provider callback failed",A),this.oauthFailure($,"provider_error")}let{name:K,username:D,providerId:B,emailVerified:U}=O??{},V=typeof O?.email==="string"?O.email:void 0,I=V?k3(V):null,P=B?await J.findUserBySocialAccount(Z,B):null,M="signin";if(!P){if(!I)return console.error("Authentication error: No usable email returned from OAuth provider callback"),this.oauthFailure($,V?"invalid_email":B?"missing_email":"no_identity");if(U===!1)return console.error("Authentication error: OAuth provider returned an unverified email"),this.oauthFailure($,"email_not_verified");let A=T(o).detectLocale($);try{let _=await this.linkOAuthAccount({provider:Z,providerId:B,email:I,rawEmail:V,name:K,username:D,locale:A});if(_)P=_.user,M=_.action}catch(_){let L=B?await J.findUserBySocialAccount(Z,B):null;if(!L)throw _;P=L}if(!P)return this.oauthFailure($,"account_conflict")}let x=await j.createOrUpdateSessionV2({email:P.email,id:P.id});if($.ctx().setCookie("access_token",x.token,T(E).accessTokenCookieOptions($,x.expiresAt)),M==="signup")await W.onSignUp(P,"",$.search.toJSON());else await W.onSignIn(P,$.search.toJSON());await _$(j.config,{session:x,user:P,isNewUser:M==="signup",method:"oauth",req:$});let f=aY($)??W.redirectPath;return{session:x,redirectTo:f}}oauthFailure($,Z){let j=aY($),J=T(E).config.oauthFailurePath;if(J){let W=U1(J,"");if(W){let Y=new URL(W,"http://gemi.invalid");if(Y.searchParams.set("error",Z),j)Y.searchParams.set(D1,j);O1.external(`${Y.pathname}${Y.search}${Y.hash}`)}else console.error(`auth.oauthFailurePath must be a same-origin path, got ${JSON.stringify(J)}`)}return{session:null,error:Z,redirectTo:j}}async linkOAuthAccount($){let{provider:Z,providerId:j,email:J,rawEmail:W,name:Y,username:z,locale:X}=$,{userProvider:G,config:F}=T(E),Q=(B)=>({provider:Z,userId:B,email:J,username:z,providerId:j,expiresAt:new Date,accessToken:"",refreshToken:""}),O=await G.findUserByEmailAddress(J,!1),K=W?.trim();if(!O&&K&&K!==J)O=await G.findUserByEmailAddress(K,!1);if(O){if(!j)return{user:O,action:"signin"};let B=await G.findSocialAccounts(O.id,Z);if(B.some((V)=>V.providerId===j))return{user:O,action:"signin"};if(B.some((V)=>V.providerId))return console.error(`Authentication error: user ${O.id} is already linked to a different ${Z} account`),null;let U=B[0];if(U){if(!await G.claimSocialAccount(U,j))throw Error(`${Z} account link changed concurrently`)}else await G.createSocialAccount(Q(O.id));return{user:O,action:"signin"}}return{user:await G.transaction(async()=>{let B=await G.createUser({email:J,name:Y,locale:X,emailVerifiedAt:new Date});if(j)await G.createSocialAccount(Q(B.id));return await F.onUserCreated(B),B}),action:"signup"}}async createMagicLinkToken($=new S){let Z=await $.input(),j=qZ(Z.get("email")),J=T(E),{uniformMagicLinkResponse:W,requestLimit:Y}=J.config.emailCode;if(await d$("request",j,$,Y),!j)return{email:null};let{user:z,pin:X,token:G}=await J.createMagicLinkToken(j);if(z)return await J.config.onMagicLinkCreated(z,{email:j,pin:X,token:G}),{email:j};return{email:W?j:null}}async requestEmailCode($=new S){let Z=T(E),j=Z.config.emailCode;if(!j.enabled)throw new q0("Not found",{status:404});let J=await $.input(),W=k3(J.get("email"));if(await d$("request",W,$,j.requestLimit),!W)throw new g({email:["Invalid email"]});let Y=await Z.userProvider.findUserByEmailAddress(W,!1);if(Y||j.createUser){let{pin:z,token:X}=await Z.issueOneTimeCode(W,j.length);await j.send({email:W,code:z,token:X,isNewUser:!Y,req:$})}return{ok:!0}}async verifyEmailCode($=new S){let Z=T(E),{userProvider:j,config:J}=Z;if(!J.emailCode.enabled)throw new q0("Not found",{status:404});let W=await $.input(),{email:Y,code:z,name:X}=W.toJSON(),G=k3(Y),F=oY(z);if(await d$("verify",G,$,J.emailCode.verifyLimit),!G||!F)throw new g({code:["invalid_code"]});let Q=await Z.verifyOneTimeCode(G,F,{claim:!1});if(Q.status==="too_many_attempts")throw new g({code:["too_many_attempts"]});if(Q.status!=="ok")throw new g({code:["invalid_code"]});let O=Q.row,K=await j.findUserByEmailAddress(G,!1),D=!1;if(K){if(!await j.claimMagicLinkToken(O.id))throw new g({code:["invalid_code"]});await j.verifyUser(G)}else if(J.emailCode.createUser){let U=T(o).detectLocale($);try{K=await j.transaction(async()=>{if(!await j.claimMagicLinkToken(O.id))throw new R4;let V=await j.createUser({email:G,name:typeof X==="string"?X.trim():"",emailVerifiedAt:new Date,locale:U});return await J.onUserCreated(V),V}),D=!0}catch(V){if(V instanceof R4)throw new g({code:["invalid_code"]});throw V}}else throw await j.claimMagicLinkToken(O.id),new g({code:["invalid_code"]});let B=await Z.createOrUpdateSessionV2({email:G,id:K.id});return $.ctx().setCookie("access_token",B.token,T(E).accessTokenCookieOptions($,B.expiresAt)),await J.onSignIn(B,$.search.toJSON()),await _$(Z.config,{session:B,isNewUser:D,method:"email-code",req:$}),{session:B,isNewUser:D}}}var $z="gemi_oauth_connection";class $8 extends wZ{async connect($=new S){let Z=String($.params.provider??""),J=T(D3).providers[Z],W=await X1.user(),Y=U1($.search.get(D1),"");if(!J)return this.finish(Y,Z,"unknown_provider");let z=y$($.rawRequest),{state:X,codeChallenge:G,cookieValue:F}=r6(Zz(Z),Date.now(),{subject:String(W.id),...Y?{returnTo:Y}:{}});return $.ctx().setCookie(UZ(z,$z),F,{httpOnly:!0,sameSite:"Lax",secure:z,maxAge:B3}),O1.external(J.authorizationUrl({state:X,codeChallenge:G,redirectUri:jz($,Z,J.config.redirectUri)})),{destination:"/"}}async callback($=new S){let Z=String($.params.provider??""),j=T(D3),J=await X1.user(),W=y$($.rawRequest),Y=UZ(W,$z),z=$.cookies.get(Y);if(z!==void 0&&z!==null)$.ctx().setCookie(Y,"",{httpOnly:!0,sameSite:"Lax",secure:W,maxAge:-1});let X=t6({provider:Zz(Z),cookieValue:z,returnedState:$.search.get("state")}),G="payload"in X?X.payload.returnTo??"":"",F=j.providers[Z];if(!F)return this.finish(G,Z,"unknown_provider");let Q=$.search.get("error");if(Q)return this.finish(G,Z,/^[a-z0-9_]{1,64}$/.test(Q)?Q:"provider_error");if("reason"in X)return console.error(`OAuth connection refused (${X.reason})`),this.finish(G,Z,X.reason);if(X.payload.subject!==String(J.id))return this.finish(G,Z,"user_mismatch");let O=$.search.get("code");if(!O)return this.finish(G,Z,"missing_code");try{let K=await F.exchangeCode({code:O,codeVerifier:X.payload.codeVerifier,redirectUri:jz($,Z,F.config.redirectUri)}),D=await j.save(J,Z,K);await T(E).config.onConnected({user:J,provider:Z,connection:D,req:$})}catch(K){if(K instanceof Jz)return console.error(`OAuth connection to ${Z} failed: ${K.message}`),this.finish(G,Z,K.providerError??K.code);throw K}return this.finish(G,Z)}finish($,Z,j){let J=$||U1(T(E).config.redirectPath,"/"),W=new URL(J,"http://gemi.invalid");if(W.searchParams.set("connection",Z),j)W.searchParams.set("connection_error",j);throw O1.external(`${W.pathname}${W.search}${W.hash}`),Error("unreachable: Redirect.external throws")}}function Zz($){return`connection:${$}`}function jz($,Z,j){if(j)return j;return`${(process.env.HOST_NAME||new URL($.rawRequest.url).origin).replace(/\/$/,"")}/auth/connections/${encodeURIComponent(Z)}/callback`}class Wz extends B1{middlewares=["cache:private"];routes={"/:provider":this.view("_Redirect",[s,"oauthRedirect"]),"/:provider/callback":this.view("auth/OauthCallback",[s,"oauthCallback"])}}class Yz extends B1{middlewares=["cache:private","auth"];routes={"/:provider":this.redirect([$8,"connect"]),"/:provider/callback":this.redirect([$8,"callback"])}}class v4 extends B1{middlewares=["cache:private"];routes={"/sign-in/magic-link":this.view("auth/MagicLinkSignIn",[s,"signInWithMagicLink"]),"/oauth":Wz,"/connections":Yz}}class w4 extends A0{middlewares=["cache:private"];routes={"/sign-in":this.post(s,"signIn"),"/sign-in-v2":this.post(s,"signInV2"),"/sign-up":this.post(s,"signUp"),"/sign-out":this.post(s,"signOut"),"/forgot-password":this.post(s,"forgotPassword"),"/reset-password":this.post(s,"resetPassword"),"/change-password":this.post(s,"changePassword"),"/verify-email":this.post(s,"verifyEmail"),"/me":this.get(s,"me").middleware(["auth"]),"/magic-link":this.post(s,"createMagicLinkToken"),"/sign-in-with-pin":this.post(s,"signInWithPin"),"/sign-in-with-pin-v2":this.post(s,"signInWithPinV2"),"/email-code":this.post(s,"requestEmailCode"),"/email-code/verify":this.post(s,"verifyEmailCode")}}class k4 extends A0{middlewares=["cache:private,0,no-store"];routes={"/set-locale/:locale":this.get(async()=>{let Z=new S().params.locale;return await T(o).onLocaleChange(Z),{locale:Z}}),"/translations/:locale/:scope*":this.get(async()=>{let $=new S,Z=`/${$.params.scope??""}`,j=$.params.locale,J=T(o),W=j??J.detectLocale($),Y=J.getPageTranslations(W,Z);return $.ctx().setCookie("i18n-locale",W,{expires:new Date(Date.now()+31536000000)}),{[W]:Y}})}}class q4{}class y4 extends q4{async resize($,Z){let{height:j,width:J,quality:W,fit:Y}=Z;return await(await Z8("The Sharp image optimization driver"))($).resize(J>0?J:void 0,j>0?j:void 0,{fit:Y}).webp({quality:W>0?W:80,force:!0}).toBuffer()}}function VT($){return $}function zz(){return{driver:new y4}}class g4 extends A0{routes={"/resize":this.file(async()=>{let $=new S,Z=new URL($.rawRequest.url),j=Z.searchParams.get("url"),J=Number(Z.searchParams.get("w")),W=Number(Z.searchParams.get("h")),Y=Z.searchParams.get("fit")??"cover",z=Number(Z.searchParams.get("q"));if(!j)return new Response(JSON.stringify({error:"url query parameter is required"}),{headers:{"Content-Type":"application/json"},status:404});let G=`${j.startsWith("http")?"":`http://localhost:${process.env.PORT||5173}`}${j}`,F=await fetch(G);if(!F.ok)return new Response(JSON.stringify({error:"Image not found",info:G}),{headers:{"Content-Type":"application/json"},status:404});let Q=Buffer.from(await F.arrayBuffer()),O=await T(Xz).resize(Q,{height:W,width:J,fit:Y,quality:z});F.headers.delete("Content-Type"),F.headers.delete("Content-Length");let K=new Headers(F.headers);return K.set("Content-Type","image/webp"),K.set("Content-Length",`${O.byteLength}`),new Response(new Uint8Array(O),{headers:K})})}}class Xz{static token="image";driver;constructor($={}){this.driver=$.driver??zz().driver}resize($,Z){return this.driver.resize($,Z)}}class m4 extends A0{middlewares=["cache:private,0"];routes={"/live":this.get(async()=>{let $=Bun.file(T(Gz).currentLogFilePath);return new Response(await $.text(),{headers:{"Content-Type":"text/plain"}})})}}function XO($){let Z=new Map;for(let j of $)if(typeof j==="string"){let[J,W=""]=j.split(":");if(J.startsWith("-")){if(Z.has(J.replace("-","")))Z.delete(J.replace("-",""))}else Z.set(J,W.split(",").filter(Boolean))}else Z.set(j,[]);return Z}var GO={"body-limit":x3};class VZ{config;static token="middleware";defaultBodyLimit;constructor($){this.config=$;this.defaultBodyLimit=$.bodyLimit===null||$.bodyLimit===void 0?null:RZ($.bodyLimit)}get aliases(){return{...GO,...this.config.aliases}}applyDefaultBodyLimit($){if(this.defaultBodyLimit!==null&&!wJ($))C3($,this.defaultBodyLimit,{checkDeclared:!1})}assertGlobalMiddleware(){for(let $ of this.config.global){if(typeof $!=="string")continue;let[Z]=$.split(":");if(Z.startsWith("-"))throw Error(`Global middleware "${$}" cancels an alias, but nothing is inherited into the global list. Remove it.`);if(!this.aliases[Z])throw Error(`Global middleware "${Z}" is not a registered alias. Add it to \`aliases\` in the middleware config, or list the class itself.`)}}runGlobalMiddleware(){return this.runMiddleware(this.config.global)}runMiddleware($){let Z=new S,j=this.aliases,J=[];for(let[W,Y]of XO($).entries())if(typeof W==="string"){let z=j[W];if(z){let X=new z(Z);J.push({run:()=>X.run.call(X,...Y),runsOnRefusal:Fz(z)})}}else if(L3(W)){let z=new W(Z);J.push({run:z.run.bind(z),runsOnRefusal:Fz(W)})}else J.push({run:W,runsOnRefusal:!1});return(async()=>{let W={};for(let Y=0;Y<J.length;Y++)try{W={...W,...await J[Y].run()}}catch(z){throw await FO(J.slice(Y+1)),z}return W})()}}function Fz($){return $?.runsOnRefusal===!0}async function FO($){for(let Z of $){if(!Z.runsOnRefusal)continue;try{await Z.run()}catch(j){console.error(j)}}}function bT($){return $}function Qz(){return{onRequestStart:()=>{},onRequestEnd:()=>{},onRequestFail:()=>{}}}function Kz(){return{partialRendering:!0,localeRouting:"prefix",onRequestStart:()=>{},onRequestEnd:()=>{},onRequestFail:()=>{},onStreamComplete:()=>{}}}function QO($){return"run"in $}function KO($){return Object.hasOwn($,"get")||Object.hasOwn($,"post")||Object.hasOwn($,"put")||Object.hasOwn($,"patch")||Object.hasOwn($,"delete")}function OO($){return Object.hasOwn($,"first")&&Object.hasOwn($,"second")}function BO($){if("__brand"in $)return $.__brand==="ApiRouter";return!1}function DO($){if("__internal_brand"in $)return $.__internal_brand==="ProxyHandler";return!1}function Oz($){if("__internal_brand"in $)return $.__internal_brand==="StreamHandler";return!1}function p4($,Z="",j=[]){let J={};function W(Y,z,X,G,F){let Q=Y==="/"?"":Y,O=Z==="/"?"":Z,K=(`${O}${Q}`===""?"/":`${O}${Q}`).replaceAll("//","/");if(!J[K])J[K]={};J[K][z.toUpperCase()]={exec:X,middleware:[...j,...G],...F?{source:F}:{}},J[K].OPTIONS={exec:()=>{let B=new S().ctx().headers;return new Response(null,{headers:B,status:204})},middleware:[]}}for(let[Y,z]of Object.entries($)){if(DO(z)){let X=z;for(let G of["GET","POST","PUT","DELETE"])W(Y,G,X.run.bind(X),X.middlewares);continue}if(QO(z)){let X=z,G=X.method,F=X.middlewares,Q=X.run.bind(X);if(W(Y,G,Q,F,X.source),Oz(z))W(Y,"HEAD",Q,F,X.source)}if(KO(z))for(let[X,G]of Object.entries(z)){let F=G,Q=F.middlewares,O=F.run.bind(F);if(W(Y,X,O,Q,F.source),X==="get"&&Oz(F))W(Y,"HEAD",O,Q,F.source)}if(BO(z)){let X=new z,G=p4(X.routes,`${Z}${Y}`,X.middlewares);for(let[F,Q]of Object.entries(G))J[F.replaceAll("//","/")]=Q}if(OO(z)){let{first:X,second:G}=z;for(let[F,Q]of Object.entries(X)){let O=Q.middlewares,K=Q.run.bind(Q),[D,...B]=Y.split("/").reverse();if(!D.startsWith(":"))throw Error("Resource route must end with a dynamic segment");W(B.reverse().join("/"),F,K,O,Q.source)}for(let[F,Q]of Object.entries(G)){let O=Q.middlewares,K=Q.run.bind(Q);W(Y,F,K,O,Q.source)}}}return Object.fromEntries(Object.entries(J).sort(([Y],[z])=>{let X=Y.split("/").length+Y.split(":").length,G=z.split("/").length+z.split(":").length;return X-G}))}function j8($){return $.replace(/\([^)]*\)/g,"").replace(/\/\//g,"/")}function h4($,Z){if($==="/")return Z;if(Z==="/")return $;return`${$}${Z}`}function c4($){let Z=j8($);return Z.length>1?Z.replace(/\/$/,""):Z}function Bz($,Z){return Z.map((j)=>({...j,path:c4(h4($,j.path))}))}function J8($){let Z={};for(let[j,J]of Object.entries($))if("run"in J){let W=J;if("children"in W){let Y=new W.children,z=J8(Y.routes);for(let[X,{exec:G,middleware:F,segments:Q,features:O,static:K}]of Object.entries(z)){let D=h4(j,X),B=(U)=>W.run.call(W,U,j);Z[j8(D)]={exec:[B,...G],middleware:[...W.middlewares,...F],features:[...W.featureGates,...O],viewPath:W.viewPath,segments:[{path:c4(j),viewPath:W.viewPath,...W.alwaysRuns?{alwaysRun:!0}:{}},...Bz(j,Q)],...K?{static:K}:{}}}}else{let Y=(z)=>W.run.call(W,z,j);Z[j8(j)]={exec:[Y],middleware:W.middlewares,features:W.featureGates,viewPath:W.viewPath,segments:[{path:c4(j),viewPath:W.viewPath}],..."staticOptions"in W&&W.staticOptions?{static:W.staticOptions}:{}}}}else{let W=new J,Y=J8(W.routes);for(let[z,{exec:X,middleware:G,viewPath:F,segments:Q,features:O,static:K}]of Object.entries(Y)){let D=h4(j,z);Z[j8(D)]={exec:X,middleware:[...W.middlewares,...G],features:[...W.featureGates,...O],viewPath:F,segments:Bz(j,Q),...K?{static:K}:{}}}}return Object.fromEntries(Object.entries(Z).sort(([j],[J])=>{let W=j.split("/").length+j.split(":").length,Y=J.split("/").length+J.split(":").length;return W-Y}))}var UO=Object.defineProperty,H=($,Z)=>UO($,"name",{value:Z,configurable:!0}),MZ=class{type=3;name="";prefix="";value="";suffix="";modifier=3;constructor($,Z,j,J,W,Y){this.type=$,this.name=Z,this.prefix=j,this.value=J,this.suffix=W,this.modifier=Y}hasCustomName(){return this.name!==""&&typeof this.name!="number"}};H(MZ,"Part");var VO=/[$_\p{ID_Start}]/u,TO=/[$_\u200C\u200D\p{ID_Continue}]/u,u4=".*";function Dz($,Z){return(Z?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test($)}H(Dz,"isASCII");function s4($,Z=!1){let j=[],J=0;for(;J<$.length;){let W=$[J],Y=H(function(z){if(!Z)throw TypeError(z);j.push({type:"INVALID_CHAR",index:J,value:$[J++]})},"ErrorOrInvalid");if(W==="*"){j.push({type:"ASTERISK",index:J,value:$[J++]});continue}if(W==="+"||W==="?"){j.push({type:"OTHER_MODIFIER",index:J,value:$[J++]});continue}if(W==="\\"){j.push({type:"ESCAPED_CHAR",index:J++,value:$[J++]});continue}if(W==="{"){j.push({type:"OPEN",index:J,value:$[J++]});continue}if(W==="}"){j.push({type:"CLOSE",index:J,value:$[J++]});continue}if(W===":"){let z="",X=J+1;for(;X<$.length;){let G=$.substr(X,1);if(X===J+1&&VO.test(G)||X!==J+1&&TO.test(G)){z+=$[X++];continue}break}if(!z){Y(`Missing parameter name at ${J}`);continue}j.push({type:"NAME",index:J,value:z}),J=X;continue}if(W==="("){let z=1,X="",G=J+1,F=!1;if($[G]==="?"){Y(`Pattern cannot start with "?" at ${G}`);continue}for(;G<$.length;){if(!Dz($[G],!1)){Y(`Invalid character '${$[G]}' at ${G}.`),F=!0;break}if($[G]==="\\"){X+=$[G++]+$[G++];continue}if($[G]===")"){if(z--,z===0){G++;break}}else if($[G]==="("&&(z++,$[G+1]!=="?")){Y(`Capturing groups are not allowed at ${G}`),F=!0;break}X+=$[G++]}if(F)continue;if(z){Y(`Unbalanced pattern at ${J}`);continue}if(!X){Y(`Missing pattern at ${J}`);continue}j.push({type:"REGEX",index:J,value:X}),J=G;continue}j.push({type:"CHAR",index:J,value:$[J++]})}return j.push({type:"END",index:J,value:""}),j}H(s4,"lexer");function n4($,Z={}){let j=s4($);Z.delimiter??="/#?",Z.prefixes??="./";let J=`[^${k0(Z.delimiter)}]+?`,W=[],Y=0,z=0,X="",G=new Set,F=H((M)=>{if(z<j.length&&j[z].type===M)return j[z++].value},"tryConsume"),Q=H(()=>F("OTHER_MODIFIER")??F("ASTERISK"),"tryConsumeModifier"),O=H((M)=>{let x=F(M);if(x!==void 0)return x;let{type:f,index:A}=j[z];throw TypeError(`Unexpected ${f} at ${A}, expected ${M}`)},"mustConsume"),K=H(()=>{let M="",x;for(;x=F("CHAR")??F("ESCAPED_CHAR");)M+=x;return M},"consumeText"),D=H((M)=>M,"DefaultEncodePart"),B=Z.encodePart||D,U="",V=H((M)=>{U+=M},"appendToPendingFixedValue"),I=H(()=>{U.length&&(W.push(new MZ(3,"","",B(U),"",3)),U="")},"maybeAddPartFromPendingFixedValue"),P=H((M,x,f,A,_)=>{let L=3;switch(_){case"?":L=1;break;case"*":L=0;break;case"+":L=2;break}if(!x&&!f&&L===3){V(M);return}if(I(),!x&&!f){if(!M)return;W.push(new MZ(3,"","",B(M),"",L));return}let N;f?f==="*"?N=u4:N=f:N=J;let l=2;N===J?(l=1,N=""):N===u4&&(l=0,N="");let d;if(x?d=x:f&&(d=Y++),G.has(d))throw TypeError(`Duplicate name '${d}'.`);G.add(d),W.push(new MZ(l,d,B(M),N,B(A),L))},"addPart");for(;z<j.length;){let M=F("CHAR"),x=F("NAME"),f=F("REGEX");if(!x&&!f&&(f=F("ASTERISK")),x||f){let _=M??"";Z.prefixes.indexOf(_)===-1&&(V(_),_=""),I();let L=Q();P(_,x,f,"",L);continue}let A=M??F("ESCAPED_CHAR");if(A){V(A);continue}if(F("OPEN")){let _=K(),L=F("NAME"),N=F("REGEX");!L&&!N&&(N=F("ASTERISK"));let l=K();O("CLOSE");let d=Q();P(_,L,N,l,d);continue}I(),O("END")}return W}H(n4,"parse");function k0($){return $.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}H(k0,"escapeString");function l4($){return $&&$.ignoreCase?"ui":"u"}H(l4,"flags");function Uz($,Z,j){return o4(n4($,j),Z,j)}H(Uz,"stringToRegexp");function S$($){switch($){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}H(S$,"modifierToString");function o4($,Z,j={}){j.delimiter??="/#?",j.prefixes??="./",j.sensitive??=!1,j.strict??=!1,j.end??=!0,j.start??=!0,j.endsWith="";let J=j.start?"^":"";for(let X of $){if(X.type===3){X.modifier===3?J+=k0(X.value):J+=`(?:${k0(X.value)})${S$(X.modifier)}`;continue}Z&&Z.push(X.name);let G=`[^${k0(j.delimiter)}]+?`,F=X.value;if(X.type===1?F=G:X.type===0&&(F=u4),!X.prefix.length&&!X.suffix.length){X.modifier===3||X.modifier===1?J+=`(${F})${S$(X.modifier)}`:J+=`((?:${F})${S$(X.modifier)})`;continue}if(X.modifier===3||X.modifier===1){J+=`(?:${k0(X.prefix)}(${F})${k0(X.suffix)})`,J+=S$(X.modifier);continue}J+=`(?:${k0(X.prefix)}`,J+=`((?:${F})(?:`,J+=k0(X.suffix),J+=k0(X.prefix),J+=`(?:${F}))*)${k0(X.suffix)})`,X.modifier===0&&(J+="?")}let W=`[${k0(j.endsWith)}]|$`,Y=`[${k0(j.delimiter)}]`;if(j.end)return j.strict||(J+=`${Y}?`),j.endsWith.length?J+=`(?=${W})`:J+="$",new RegExp(J,l4(j));j.strict||(J+=`(?:${Y}(?=${W}))?`);let z=!1;if($.length){let X=$[$.length-1];X.type===3&&X.modifier===3&&(z=j.delimiter.indexOf(X)>-1)}return z||(J+=`(?=${Y}|${W})`),new RegExp(J,l4(j))}H(o4,"partsToRegexp");var e1={delimiter:"",prefixes:"",sensitive:!0,strict:!0},IO={delimiter:".",prefixes:"",sensitive:!0,strict:!0},MO={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Vz($,Z){return $.length?$[0]==="/"?!0:!Z||$.length<2?!1:($[0]=="\\"||$[0]=="{")&&$[1]=="/":!1}H(Vz,"isAbsolutePathname");function a4($,Z){return $.startsWith(Z)?$.substring(Z.length,$.length):$}H(a4,"maybeStripPrefix");function Tz($,Z){return $.endsWith(Z)?$.substr(0,$.length-Z.length):$}H(Tz,"maybeStripSuffix");function r4($){return!$||$.length<2?!1:$[0]==="["||($[0]==="\\"||$[0]==="{")&&$[1]==="["}H(r4,"treatAsIPv6Hostname");var Iz=["ftp","file","http","https","ws","wss"];function t4($){if(!$)return!0;for(let Z of Iz)if($.test(Z))return!0;return!1}H(t4,"isSpecialScheme");function Mz($,Z){if($=a4($,"#"),Z||$==="")return $;let j=new URL("https://example.com");return j.hash=$,j.hash?j.hash.substring(1,j.hash.length):""}H(Mz,"canonicalizeHash");function Pz($,Z){if($=a4($,"?"),Z||$==="")return $;let j=new URL("https://example.com");return j.search=$,j.search?j.search.substring(1,j.search.length):""}H(Pz,"canonicalizeSearch");function Nz($,Z){return Z||$===""?$:r4($)?ZJ($):$J($)}H(Nz,"canonicalizeHostname");function Lz($,Z){if(Z||$==="")return $;let j=new URL("https://example.com");return j.password=$,j.password}H(Lz,"canonicalizePassword");function Hz($,Z){if(Z||$==="")return $;let j=new URL("https://example.com");return j.username=$,j.username}H(Hz,"canonicalizeUsername");function Cz($,Z,j){if(j||$==="")return $;if(Z&&!Iz.includes(Z))return new URL(`${Z}:${$}`).pathname;let J=$[0]=="/";return $=new URL(J?$:"/-"+$,"https://example.com").pathname,J||($=$.substring(2,$.length)),$}H(Cz,"canonicalizePathname");function _z($,Z,j){return e4(Z)===$&&($=""),j||$===""?$:jJ($)}H(_z,"canonicalizePort");function Sz($,Z){return $=Tz($,":"),Z||$===""?$:W8($)}H(Sz,"canonicalizeProtocol");function e4($){switch($){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}H(e4,"defaultPortForProtocol");function W8($){if($==="")return $;if(/^[-+.A-Za-z0-9]*$/.test($))return $.toLowerCase();throw TypeError(`Invalid protocol '${$}'.`)}H(W8,"protocolEncodeCallback");function xz($){if($==="")return $;let Z=new URL("https://example.com");return Z.username=$,Z.username}H(xz,"usernameEncodeCallback");function Az($){if($==="")return $;let Z=new URL("https://example.com");return Z.password=$,Z.password}H(Az,"passwordEncodeCallback");function $J($){if($==="")return $;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test($))throw TypeError(`Invalid hostname '${$}'`);let Z=new URL("https://example.com");return Z.hostname=$,Z.hostname}H($J,"hostnameEncodeCallback");function ZJ($){if($==="")return $;if(/[^0-9a-fA-F[\]:]/g.test($))throw TypeError(`Invalid IPv6 hostname '${$}'`);return $.toLowerCase()}H(ZJ,"ipv6HostnameEncodeCallback");function jJ($){if($===""||/^[0-9]*$/.test($)&&parseInt($)<=65535)return $;throw TypeError(`Invalid port '${$}'.`)}H(jJ,"portEncodeCallback");function fz($){if($==="")return $;let Z=new URL("https://example.com");return Z.pathname=$[0]!=="/"?"/-"+$:$,$[0]!=="/"?Z.pathname.substring(2,Z.pathname.length):Z.pathname}H(fz,"standardURLPathnameEncodeCallback");function Ez($){return $===""?$:new URL(`data:${$}`).pathname}H(Ez,"pathURLPathnameEncodeCallback");function Rz($){if($==="")return $;let Z=new URL("https://example.com");return Z.search=$,Z.search.substring(1,Z.search.length)}H(Rz,"searchEncodeCallback");function bz($){if($==="")return $;let Z=new URL("https://example.com");return Z.hash=$,Z.hash.substring(1,Z.hash.length)}H(bz,"hashEncodeCallback");var vz=class{#Y;#J=[];#Z={};#$=0;#W=1;#F=0;#X=0;#B=0;#D=0;#U=!1;constructor($){this.#Y=$}get result(){return this.#Z}parse(){for(this.#J=s4(this.#Y,!0);this.#$<this.#J.length;this.#$+=this.#W){if(this.#W=1,this.#J[this.#$].type==="END"){if(this.#X===0){this.#M(),this.#Q()?this.#j(9,1):this.#K()?this.#j(8,1):this.#j(7,0);continue}else if(this.#X===2){this.#O(5);continue}this.#j(10,0);break}if(this.#B>0)if(this.#S())this.#B-=1;else continue;if(this.#_()){this.#B+=1;continue}switch(this.#X){case 0:this.#P()&&this.#O(1);break;case 1:if(this.#P()){this.#f();let $=7,Z=1;this.#L()?($=2,Z=3):this.#U&&($=2),this.#j($,Z)}break;case 2:this.#T()?this.#O(3):(this.#I()||this.#K()||this.#Q())&&this.#O(5);break;case 3:this.#H()?this.#j(4,1):this.#T()&&this.#j(5,1);break;case 4:this.#T()&&this.#j(5,1);break;case 5:this.#x()?this.#D+=1:this.#A()&&(this.#D-=1),this.#C()&&!this.#D?this.#j(6,1):this.#I()?this.#j(7,0):this.#K()?this.#j(8,1):this.#Q()&&this.#j(9,1);break;case 6:this.#I()?this.#j(7,0):this.#K()?this.#j(8,1):this.#Q()&&this.#j(9,1);break;case 7:this.#K()?this.#j(8,1):this.#Q()&&this.#j(9,1);break;case 8:this.#Q()&&this.#j(9,1);break;case 9:break;case 10:break}}this.#Z.hostname!==void 0&&this.#Z.port===void 0&&(this.#Z.port="")}#j($,Z){switch(this.#X){case 0:break;case 1:this.#Z.protocol=this.#G();break;case 2:break;case 3:this.#Z.username=this.#G();break;case 4:this.#Z.password=this.#G();break;case 5:this.#Z.hostname=this.#G();break;case 6:this.#Z.port=this.#G();break;case 7:this.#Z.pathname=this.#G();break;case 8:this.#Z.search=this.#G();break;case 9:this.#Z.hash=this.#G();break;case 10:break}this.#X!==0&&$!==10&&([1,2,3,4].includes(this.#X)&&[6,7,8,9].includes($)&&(this.#Z.hostname??=""),[1,2,3,4,5,6].includes(this.#X)&&[8,9].includes($)&&(this.#Z.pathname??=this.#U?"/":""),[1,2,3,4,5,6,7].includes(this.#X)&&$===9&&(this.#Z.search??="")),this.#N($,Z)}#N($,Z){this.#X=$,this.#F=this.#$+Z,this.#$+=Z,this.#W=0}#M(){this.#$=this.#F,this.#W=0}#O($){this.#M(),this.#X=$}#V($){return $<0&&($=this.#J.length-$),$<this.#J.length?this.#J[$]:this.#J[this.#J.length-1]}#z($,Z){let j=this.#V($);return j.value===Z&&(j.type==="CHAR"||j.type==="ESCAPED_CHAR"||j.type==="INVALID_CHAR")}#P(){return this.#z(this.#$,":")}#L(){return this.#z(this.#$+1,"/")&&this.#z(this.#$+2,"/")}#T(){return this.#z(this.#$,"@")}#H(){return this.#z(this.#$,":")}#C(){return this.#z(this.#$,":")}#I(){return this.#z(this.#$,"/")}#K(){if(this.#z(this.#$,"?"))return!0;if(this.#J[this.#$].value!=="?")return!1;let $=this.#V(this.#$-1);return $.type!=="NAME"&&$.type!=="REGEX"&&$.type!=="CLOSE"&&$.type!=="ASTERISK"}#Q(){return this.#z(this.#$,"#")}#_(){return this.#J[this.#$].type=="OPEN"}#S(){return this.#J[this.#$].type=="CLOSE"}#x(){return this.#z(this.#$,"[")}#A(){return this.#z(this.#$,"]")}#G(){let $=this.#J[this.#$],Z=this.#V(this.#F).index;return this.#Y.substring(Z,$.index)}#f(){let $={};Object.assign($,e1),$.encodePart=W8;let Z=Uz(this.#G(),void 0,$);this.#U=t4(Z)}};H(vz,"Parser");var d4=["protocol","username","password","hostname","port","pathname","search","hash"],t1="*";function i4($,Z){if(typeof $!="string")throw TypeError("parameter 1 is not of type 'string'.");let j=new URL($,Z);return{protocol:j.protocol.substring(0,j.protocol.length-1),username:j.username,password:j.password,hostname:j.hostname,port:j.port,pathname:j.pathname,search:j.search!==""?j.search.substring(1,j.search.length):void 0,hash:j.hash!==""?j.hash.substring(1,j.hash.length):void 0}}H(i4,"extractValues");function G1($,Z){return Z?IZ($):$}H(G1,"processBaseURLString");function TZ($,Z,j){let J;if(typeof Z.baseURL=="string")try{J=new URL(Z.baseURL),Z.protocol===void 0&&($.protocol=G1(J.protocol.substring(0,J.protocol.length-1),j)),!j&&Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.username===void 0&&($.username=G1(J.username,j)),!j&&Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.username===void 0&&Z.password===void 0&&($.password=G1(J.password,j)),Z.protocol===void 0&&Z.hostname===void 0&&($.hostname=G1(J.hostname,j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&($.port=G1(J.port,j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.pathname===void 0&&($.pathname=G1(J.pathname,j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.pathname===void 0&&Z.search===void 0&&($.search=G1(J.search.substring(1,J.search.length),j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.pathname===void 0&&Z.search===void 0&&Z.hash===void 0&&($.hash=G1(J.hash.substring(1,J.hash.length),j))}catch{throw TypeError(`invalid baseURL '${Z.baseURL}'.`)}if(typeof Z.protocol=="string"&&($.protocol=Sz(Z.protocol,j)),typeof Z.username=="string"&&($.username=Hz(Z.username,j)),typeof Z.password=="string"&&($.password=Lz(Z.password,j)),typeof Z.hostname=="string"&&($.hostname=Nz(Z.hostname,j)),typeof Z.port=="string"&&($.port=_z(Z.port,$.protocol,j)),typeof Z.pathname=="string"){if($.pathname=Z.pathname,J&&!Vz($.pathname,j)){let W=J.pathname.lastIndexOf("/");W>=0&&($.pathname=G1(J.pathname.substring(0,W+1),j)+$.pathname)}$.pathname=Cz($.pathname,$.protocol,j)}return typeof Z.search=="string"&&($.search=Pz(Z.search,j)),typeof Z.hash=="string"&&($.hash=Mz(Z.hash,j)),$}H(TZ,"applyInit");function IZ($){return $.replace(/([+*?:{}()\\])/g,"\\$1")}H(IZ,"escapePatternString");function wz($){return $.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}H(wz,"escapeRegexpString");function kz($,Z){Z.delimiter??="/#?",Z.prefixes??="./",Z.sensitive??=!1,Z.strict??=!1,Z.end??=!0,Z.start??=!0,Z.endsWith="";let j=".*",J=`[^${wz(Z.delimiter)}]+?`,W=/[$_\u200C\u200D\p{ID_Continue}]/u,Y="";for(let z=0;z<$.length;++z){let X=$[z];if(X.type===3){if(X.modifier===3){Y+=IZ(X.value);continue}Y+=`{${IZ(X.value)}}${S$(X.modifier)}`;continue}let G=X.hasCustomName(),F=!!X.suffix.length||!!X.prefix.length&&(X.prefix.length!==1||!Z.prefixes.includes(X.prefix)),Q=z>0?$[z-1]:null,O=z<$.length-1?$[z+1]:null;if(!F&&G&&X.type===1&&X.modifier===3&&O&&!O.prefix.length&&!O.suffix.length)if(O.type===3){let K=O.value.length>0?O.value[0]:"";F=W.test(K)}else F=!O.hasCustomName();if(!F&&!X.prefix.length&&Q&&Q.type===3){let K=Q.value[Q.value.length-1];F=Z.prefixes.includes(K)}F&&(Y+="{"),Y+=IZ(X.prefix),G&&(Y+=`:${X.name}`),X.type===2?Y+=`(${X.value})`:X.type===1?G||(Y+=`(${J})`):X.type===0&&(!G&&(!Q||Q.type===3||Q.modifier!==3||F||X.prefix!=="")?Y+="*":Y+=`(${j})`),X.type===1&&G&&X.suffix.length&&W.test(X.suffix[0])&&(Y+="\\"),Y+=IZ(X.suffix),F&&(Y+="}"),X.modifier!==3&&(Y+=S$(X.modifier))}return Y}H(kz,"partsToPattern");var JJ=class{#Y;#J={};#Z={};#$={};#W={};#F=!1;constructor($={},Z,j){try{let J;if(typeof Z=="string"?J=Z:j=Z,typeof $=="string"){let X=new vz($);if(X.parse(),$=X.result,J===void 0&&typeof $.protocol!="string")throw TypeError("A base URL must be provided for a relative constructor string.");$.baseURL=J}else{if(!$||typeof $!="object")throw TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(J)throw TypeError("parameter 1 is not of type 'string'.")}typeof j>"u"&&(j={ignoreCase:!1});let W={ignoreCase:j.ignoreCase===!0},Y={pathname:t1,protocol:t1,username:t1,password:t1,hostname:t1,port:t1,search:t1,hash:t1};this.#Y=TZ(Y,$,!0),e4(this.#Y.protocol)===this.#Y.port&&(this.#Y.port="");let z;for(z of d4){if(!(z in this.#Y))continue;let X={},G=this.#Y[z];switch(this.#Z[z]=[],z){case"protocol":Object.assign(X,e1),X.encodePart=W8;break;case"username":Object.assign(X,e1),X.encodePart=xz;break;case"password":Object.assign(X,e1),X.encodePart=Az;break;case"hostname":Object.assign(X,IO),r4(G)?X.encodePart=ZJ:X.encodePart=$J;break;case"port":Object.assign(X,e1),X.encodePart=jJ;break;case"pathname":t4(this.#J.protocol)?(Object.assign(X,MO,W),X.encodePart=fz):(Object.assign(X,e1,W),X.encodePart=Ez);break;case"search":Object.assign(X,e1,W),X.encodePart=Rz;break;case"hash":Object.assign(X,e1,W),X.encodePart=bz;break}try{this.#W[z]=n4(G,X),this.#J[z]=o4(this.#W[z],this.#Z[z],X),this.#$[z]=kz(this.#W[z],X),this.#F=this.#F||this.#W[z].some((F)=>F.type===2)}catch{throw TypeError(`invalid ${z} pattern '${this.#Y[z]}'.`)}}}catch(J){throw TypeError(`Failed to construct 'URLPattern': ${J.message}`)}}get[Symbol.toStringTag](){return"URLPattern"}test($={},Z){let j={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof $!="string"&&Z)throw TypeError("parameter 1 is not of type 'string'.");if(typeof $>"u")return!1;try{typeof $=="object"?j=TZ(j,$,!1):j=TZ(j,i4($,Z),!1)}catch{return!1}let J;for(J of d4)if(!this.#J[J].exec(j[J]))return!1;return!0}exec($={},Z){let j={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof $!="string"&&Z)throw TypeError("parameter 1 is not of type 'string'.");if(typeof $>"u")return;try{typeof $=="object"?j=TZ(j,$,!1):j=TZ(j,i4($,Z),!1)}catch{return null}let J={};Z?J.inputs=[$,Z]:J.inputs=[$];let W;for(W of d4){let Y=this.#J[W].exec(j[W]);if(!Y)return null;let z={};for(let[X,G]of this.#Z[W].entries())if(typeof G=="string"||typeof G=="number"){let F=Y[X+1];z[G]=F}J[W]={input:j[W]??"",groups:z}}return J}static compareComponent($,Z,j){let J=H((X,G)=>{for(let F of["type","modifier","prefix","value","suffix"]){if(X[F]<G[F])return-1;if(X[F]===G[F])continue;return 1}return 0},"comparePart"),W=new MZ(3,"","","","",3),Y=new MZ(0,"","","","",3),z=H((X,G)=>{let F=0;for(;F<Math.min(X.length,G.length);++F){let Q=J(X[F],G[F]);if(Q)return Q}return X.length===G.length?0:J(X[F]??W,G[F]??W)},"comparePartList");return!Z.#$[$]&&!j.#$[$]?0:Z.#$[$]&&!j.#$[$]?z(Z.#W[$],[Y]):!Z.#$[$]&&j.#$[$]?z([Y],j.#W[$]):z(Z.#W[$],j.#W[$])}get protocol(){return this.#$.protocol}get username(){return this.#$.username}get password(){return this.#$.password}get hostname(){return this.#$.hostname}get port(){return this.#$.port}get pathname(){return this.#$.pathname}get search(){return this.#$.search}get hash(){return this.#$.hash}get hasRegExpGroups(){return this.#F}};H(JJ,"URLPattern");function U3($,Z){for(let[j,J]of Object.entries($)){let W=new JJ({pathname:j});if(W.test({pathname:Z}))return{routePath:j,params:W.exec({pathname:Z})?.pathname.groups??{},route:J}}return null}var x$={startIndex:0,carriedViews:[]};function qz($,Z){let j=G0($.path,Z);return j.includes("*")?null:j}function PO($,Z){if(!$)return x$;if($.search!==Z.search)return x$;let j=Math.min($.segments.length,Z.segments.length-1),J=0;while(J<j){let W=$.segments[J],Y=Z.segments[J];if(Y.alwaysRun)break;if(W.viewPath!==Y.viewPath)break;let z=qz(W,$.params),X=qz(Y,Z.params);if(z===null||X===null||z!==X)break;J++}if(J===0)return x$;return{startIndex:J,carriedViews:Z.segments.slice(0,J).map(({viewPath:W})=>W)}}function NO($,Z){let[,j,...J]=$.split("/");if(!Z.includes(j))return $;let W=`/${J.join("/")}`;return W==="/"?"/":W.replace(/\/$/,"")}function yz($){let{flatViewRoutes:Z,supportedLocales:j,from:J,origin:W,to:Y}=$;if(!J)return x$;let z;try{z=new URL(J,W)}catch{return x$}if(z.origin!==W)return x$;let X=U3(Z,NO(z.pathname,j));if(!X)return x$;return PO({segments:X.route.segments,params:X.params,search:z.search},Y)}var WJ="x-gemi-from";import{createElement as A1,Fragment as QX}from"react";function LO($){return $.replace(/\([^)]*\)/g,"").replace(/\/\//g,"/")}function Y8($){let Z={};for(let[j,J]of Object.entries($))if("run"in J){let W=J.viewPath;if("children"in J){Z[j]=[W];let Y=new J.children,z=Y8(Y.routes);for(let[X,G]of Object.entries(z)){let F=j==="/"?X:`${j}${X}`,Q=X==="/"&&j!=="/"?j:F;Z[Q]=[W,...G]}if(Z[j].length===1)delete Z[j]}else Z[j]=[W]}else{let W=new J,Y=Y8(W.routes);for(let[z,X]of Object.entries(Y)){let G=j==="/"?z:`${j}${z}`,F=z==="/"&&j!=="/"?j:G;Z[F]=X}}return Object.fromEntries(Object.entries(Z).map(([j,J])=>[LO(j),J]))}function z8($,Z){let[j,J]=Z,W=$.find(([Y])=>Y===j);if(!W){$.push([j,[...J]]);return}for(let Y of J)z8(W[1],Y)}function X8($){let Z=[];for(let[j,J]of Object.entries($))if("run"in J){let W=J.viewPath;if(W==="__")continue;if(W==="REDIRECT")continue;if(W==="FILE")continue;if("children"in J){let Y=new J.children,z=X8(Y.routes);z8(Z,[W,z])}else z8(Z,[W,[]])}else{let W=new J,Y=X8(W.routes);for(let z of Y)z8(Z,z)}return Z}function YJ($){let Z=[];for(let[j,J]of $)Z.push(j,...YJ(J).flat());return Array.from(new Set(Z))}class $$ extends c{static getFacadeAccessor(){return o}static getSupportedLocales(){return this.getFacadeRoot().supportedLocales}static getDefaultLocale(){return this.getFacadeRoot().defaultLocale}static locale(){let $=this.getFacadeRoot(),Z=C.getStore();if(Z)return Z.locale??$.detectLocale(Z.req);return $.defaultLocale}static timeZone(){return this.getFacadeRoot().detectTimeZone(C.getStore()?.req)}static formatter($={}){return this.getFacadeRoot().formatter($.locale??$$.locale(),$.timeZone??$$.timeZone())}static setLocale($=$$.locale(),Z={}){let j=this.getFacadeRoot(),J=$;if(!j.supportedLocales.includes($))J=j.defaultLocale;let W=C.getStore();if(Z.cookie!==!1)W.setCookie("i18n-locale",J,{expires:new Date(Date.now()+31536000000),secure:!1,httpOnly:!1});return W.setLocale(J),J}}class zJ{id;static token="kernel.id";constructor($=crypto.randomUUID()){this.id=$}}var HO=new Set(["script","style","textarea","title","xmp","iframe","noembed","noframes","noscript"]),CO=new Set(["svg","math"]);function gz($){return $===32||$===9||$===10||$===12||$===13}function mz($){return $>=65&&$<=90||$>=97&&$<=122}function G8($){return $>=65&&$<=90?$+32:$}function pz(){let $="data",Z="",j=!1,J="",W=0,Y=0,z=!1,X=0,G=0,F=()=>$==="data"&&X===0&&G===0,Q=()=>{if(!j&&HO.has(Z)){$="rawText",J=`</${Z}`,W=0,Z="";return}if($="data",Z==="template")if(j)X=Math.max(0,X-1);else X+=1;else if(CO.has(Z)){if(j)G=Math.max(0,G-1);else if(!z)G+=1}Z=""},O=(K)=>{switch($){case"data":if(K===60)$="tagOpen";return;case"tagOpen":if(K===33)$="bang",Y=0;else if(K===47)$="endTagOpen";else if(mz(K))$="tagName",j=!1,z=!1,Z=String.fromCharCode(G8(K));else if(K===63)$="bogus";else if(K===60)$="tagOpen";else $="data";return;case"endTagOpen":if(mz(K))$="tagName",j=!0,z=!1,Z=String.fromCharCode(G8(K));else if(K===62)$="data";else $="bogus";return;case"tagName":if(gz(K)||K===47)$="inTag",z=K===47;else if(K===62)Q();else Z+=String.fromCharCode(G8(K));return;case"inTag":if(K===62){Q();return}if(z=K===47,K===34)$="attrDouble";else if(K===39)$="attrSingle";return;case"attrDouble":if(K===34)$="inTag";z=!1;return;case"attrSingle":if(K===39)$="inTag";z=!1;return;case"bang":if(K===45){if(Y+=1,Y===2)$="comment",Y=0}else if(K===62)$="data";else $="bogus";return;case"bogus":if(K===62)$="data";return;case"comment":if(K===45)Y=Y<2?Y+1:2;else if(K===62&&Y>=2)$="data",Y=0;else Y=0;return;case"rawText":{if(W<J.length){if(G8(K)===J.charCodeAt(W))W+=1;else W=K===60?1:0;return}if(K===62)$="data",Z="";else if(gz(K)||K===47)$="inTag",Z="";else W=K===60?1:0;return}}};return{scanToInsertionPoint(K){for(let D=0;D<K.length;D++){if(F())return D;O(K[D])}return K.length},write(K){for(let D=0;D<K.length;D++)O(K[D])},isSafe:F}}function S1($){let Z=JSON.stringify($);if(Z===void 0)return"undefined";return Z.replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function _O($){return`<script>(self.__GEMI_STREAM__=self.__GEMI_STREAM__||[]).push(${S1([$.path,$.variantKey,$.data])})</script>`}function SO($){return`<script>(self.__GEMI_DICT__=self.__GEMI_DICT__||[]).push(${S1([$.id,$.locale,$.strings])})</script>`}function XJ($,Z,j={},J){let W=new TextEncoder,Y=[],z=!1,X=!1,G=()=>{if(X)return;X=!0,j.onClose?.()};Z.onSettle((B)=>{if(B.status!=="resolved")return;Y.push(_O(B))}),J?.onUse((B)=>{Y.push(SO(B))});let F=$.getReader(),Q=pz(),O=(B,U)=>{B.enqueue(U),j.onChunk?.(U)},K=(B)=>{while(Y.length>0){let U=W.encode(Y.shift());Q.write(U),O(B,U)}},D=(B,U)=>{if(Y.length===0){Q.write(U),O(B,U);return}let V=Q.scanToInsertionPoint(U);if(V>0)O(B,U.subarray(0,V));if(Q.isSafe())K(B);let I=U.subarray(V);if(I.length>0)Q.write(I),O(B,I)};return new ReadableStream({async pull(B){let U;try{U=await F.read()}catch(P){throw G(),P}let{done:V,value:I}=U;if(V){K(B),B.close(),G();return}if(!z){if(z=!0,Q.write(I),O(B,I),j.onShell?.(),Q.isSafe())K(B);return}D(B,I)},cancel(B){return G(),F.cancel(B)}})}var xO=/bot|crawler|spider|crawling|slurp|bingpreview|mediapartners|headless|lighthouse|prerender|facebookexternalhit|whatsapp|telegram|discord|twitterbot|linkedinbot/i;function F8($){if(!$)return!1;return xO.test($)}async function cz($,Z=()=>{}){let j=C.getStore(),J=j?.req??null,W=null;if(J?.rawRequest?.url)try{W=new URL(J.rawRequest.url).pathname}catch{W=null}return{user:j?.user??null,attributes:await AO($,Z),request:{path:W,routePath:J?.routePath??null,locale:j?.locale??null},anonymousId:hz(),isBot:F8(J?.rawRequest?.headers?.get("user-agent")??null),now:new Date}}function dz($){return{user:$.user??null,attributes:$.attributes??{},request:{path:null,routePath:null,locale:null},anonymousId:$.subjectId??null,isBot:!1,now:new Date}}async function AO($,Z){if(!$.context)return{};try{let j=C.getStore();return await $.context(j?.req??null)??{}}catch(j){return Z(`The \`context\` hook in app/config/features.ts threw; evaluating with no attributes. ${j instanceof Error?j.message:String(j)}`),{}}}function uz($,Z){return`${$}:${Z}`}function GJ($){let Z=new Bun.CryptoHasher("sha1").update($).digest("hex"),j=Number.parseInt(Z.slice(0,8),16);return Math.floor(j/4294967296*1e4)}function lz($,Z){if(Z>=100)return!0;if(Z<=0)return!1;return $<Math.round(Z*100)}function iz($,Z,j,J){if(J.unavailable)return{value:!1,reason:"unavailable"};if(J.active!==!0)return{value:!1,reason:"inactive"};if(Z.when){let Y;try{Y=Z.when(j)}catch(z){return J.warn?.(`The \`when\` for feature "${$}" threw; treating it as off. ${z instanceof Error?z.message:String(z)}`),{value:!1,reason:"error"}}if(typeof Y==="boolean")return{value:Y,reason:"attributed"}}if(Z.rollout===void 0)return{value:!0,reason:"on"};if(j.isBot)return{value:!1,reason:"bot"};let W=EO($,Z,j,J.buckets);return lz(W,Z.rollout)?{value:!0,reason:"rollout"}:{value:!1,reason:"excluded"}}function fO($){let Z=$.user?.publicId??$.user?.id;if(Z!==void 0&&Z!==null)return String(Z);return $.anonymousId??""}function EO($,Z,j,J){let W=uz(Z.salt??$,fO(j));if(!J)return GJ(W);let Y=J.get(W);if(Y!==void 0)return Y;let z=GJ(W);return J.set(W,z),z}class sz extends Error{cause;kind="FeatureReloadFailed";constructor($){super(`Could not reload feature switches after a write, so the cached switches may still predate it: ${$ instanceof Error?$.message:String($)}`);this.cause=$}}class FJ{source;declared;ttlMs;warn;snapshot=null;inflight=null;lastFailureLoggedAt=0;generation=0;lastError=null;retryAfter=0;constructor($,Z,j,J=()=>{}){this.source=$;this.declared=Z;this.ttlMs=j;this.warn=J}async get(){let $=this.snapshot;if($&&Date.now()-$.loadedAt<this.ttlMs)return $;if($){if(Date.now()>=this.retryAfter)this.refresh().catch(()=>{});return $}return await this.refresh()}refresh(){return this.inflight??=this.load().finally(()=>{this.inflight=null}),this.inflight}async invalidate(){await this.inflight?.catch(()=>{});let $=this.generation,Z=await this.refresh();if(this.generation===$)throw new sz(this.lastError);return Z}peek(){return this.snapshot}async load(){try{let $=await this.source.load(),{active:Z,audit:j}=this.readRows($);return this.snapshot={active:Z,audit:j,loadedAt:Date.now(),unavailable:!1},this.generation++,this.lastError=null,this.retryAfter=0,this.snapshot}catch($){return this.handleFailure($)}}readRows($){let Z=new Map,j=new Map;for(let J of $??[]){let W=typeof J?.key==="string"?J.key:null;if(!W){this.warn("Ignoring a feature row with no `key`.");continue}if(!(W in this.declared)){this.warn(`Feature row "${W}" is not declared in app/features, so it is ignored. Delete the row, or declare the feature.`);continue}Z.set(W,J.active===!0);let Y=RO(J);if(Y)j.set(W,Y)}return{active:Z,audit:j}}handleFailure($){let Z=$ instanceof Error?$.message:String($),j=Date.now();if(this.lastError=$,this.retryAfter=j+this.ttlMs,j-this.lastFailureLoggedAt>=this.ttlMs)this.lastFailureLoggedAt=j,this.warn(`Could not load feature switches: ${Z}`);if(this.snapshot)return this.snapshot;return this.snapshot={active:new Map,audit:new Map,loadedAt:j,unavailable:!0},this.snapshot}}function RO($){let Z={},j=$.updatedBy;if(typeof j==="string")Z.updatedBy=j;else if(j===null)Z.updatedBy=null;let J=$.updatedAt;if(J instanceof Date||typeof J==="string"||typeof J==="number"){let W=J instanceof Date?J:new Date(J);if(!Number.isNaN(W.getTime()))Z.updatedAt=W}return"updatedBy"in Z||"updatedAt"in Z?Z:null}class bO{}class vO extends Error{modelName;kind="FeatureModelMissing";constructor($){super(`No "${$}" model is registered, so every feature stays off. Add the model to prisma/schema.prisma and export it from app/models \u2014 see docs/feature-flags.md.`);this.modelName=$}}class QJ extends Error{sourceName;kind="FeatureSourceReadOnly";constructor($){super(`The feature source (${$}) is read-only, so Features.set() cannot write to it. Change the switch where that source reads from, or give the source a write() method.`);this.sourceName=$}}class nz extends Error{key;kind="UndeclaredFeature";constructor($){super(`"${$}" is not declared in app/features, so it cannot be switched. A row for it would be ignored \u2014 declare the feature first.`);this.key=$}}class oz{manager;ctx;constructor($,Z){this.manager=$;this.ctx=Z}async enabled($){return(await this.explain($)).value}async explain($){return await this.manager.evaluateIn($,this.ctx,new Map)}async all(){return await this.manager.evaluateAllIn(this.ctx,new Map,{clientOnly:!1})}}class PZ{config;log;static token="features";store;declared;warnedAboutSize=!1;warnedAboutActor=!1;constructor($,Z=()=>{}){this.config=$;this.log=Z;this.declared=$.features??{},this.store=new FJ($.source,this.declared,Math.max(0,$.ttl)*1000,this.log)}declarations(){return this.declared}async list(){let{active:$,audit:Z,unavailable:j}=await this.switches();return{unavailable:j,features:Object.entries(this.declared).map(([J,W])=>({key:J,describe:W.describe,rollout:W.rollout,targeted:W.when!==void 0,serverOnly:W.serverOnly,salt:W.salt,active:$.get(J),...Z.get(J)}))}}async refresh(){if(!this.config.enabled)return;if(Object.keys(this.declared).length===0)return;await this.store.refresh()}async invalidate(){try{if(this.config.enabled&&Object.keys(this.declared).length>0)await this.store.invalidate()}finally{C.getStore()?.featureEvaluations?.clear()}}async set($,Z,j={}){if(typeof $!=="string"||!Object.hasOwn(this.declared,$))throw new nz(String($));if(typeof Z!=="boolean")throw TypeError(`Features.set("${$}", \u2026) takes a boolean, not ${Z===null?"null":typeof Z}.`);let J=wO(j.actor),W=this.config.source;if(typeof W.write!=="function")throw new QJ(W.constructor?.name||"an anonymous source");let{actorRecorded:Y}=await W.write($,Z,{actor:J});if(J!==null&&!Y&&!this.warnedAboutActor)this.warnedAboutActor=!0,this.log('Features.set() was given an actor, but the feature source has nowhere to record it. For the database source, add a nullable `updatedBy String?` column to the feature flag model to keep "last changed by".');await this.invalidate()}async enabled($){return(await this.explain($)).value}async explain($){let Z=await this.requestContext();return await this.evaluateIn($,Z,this.requestBuckets())}async all(){let $=await this.requestContext();return await this.evaluateAllIn($,this.requestBuckets(),{clientOnly:!1})}async forClient(){if(!this.config.enabled)return{};let $=await this.requestContext(),Z=await this.evaluateAllIn($,this.requestBuckets(),{clientOnly:!0});return this.warnIfOversized(Object.keys(Z).length),Z}for($){return new oz(this,dz($))}async evaluateIn($,Z,j){let J=this.memoFor(Z),W=J?.get($);if(W)return W;let Y=this.declared[$];if(!Y)return{value:!1,reason:"undeclared"};let{active:z,unavailable:X}=await this.switchFor($),G=iz($,Y,Z,{active:z,unavailable:X,buckets:j,warn:this.log});return J?.set($,G),this.notify($,G,Z),G}async evaluateAllIn($,Z,j){let J={};for(let[W,Y]of Object.entries(this.declared)){if(j.clientOnly&&Y.serverOnly)continue;J[W]=(await this.evaluateIn(W,$,Z)).value}return J}async switches(){if(!this.config.enabled||Object.keys(this.declared).length===0)return{active:new Map,audit:new Map,unavailable:!1};let $=await this.store.get();return{active:$.active,audit:$.audit,unavailable:$.unavailable}}async switchFor($){if(!this.config.enabled)return{active:!1,unavailable:!1};let Z=await this.store.get();return{active:Z.active.get($),unavailable:Z.unavailable}}async requestContext(){let $=C.getStore();if($?.featureContext)return $.featureContext;let Z=await cz(this.config,this.log);if($)$.featureContext=Z;return Z}memoFor($){let Z=C.getStore();if(!Z||Z.featureContext!==$)return null;return Z.featureEvaluations??=new Map,Z.featureEvaluations}requestBuckets(){let $=C.getStore();if(!$)return new Map;return $.featureBuckets??=new Map,$.featureBuckets}notify($,Z,j){if(!this.config.onEvaluate)return;try{this.config.onEvaluate($,Z,j)}catch(J){this.log(`The \`onEvaluate\` hook in app/config/features.ts threw for "${$}". ${J instanceof Error?J.message:String(J)}`)}}warnIfOversized($){if(this.warnedAboutSize||$<=this.config.maxClientFlags)return;this.warnedAboutSize=!0,this.log(`${$} client-visible features are embedded in every document. Mark the ones only the server reads with \`serverOnly: true\` to keep them out of the payload.`)}}function wO($){if($===void 0||$===null)return null;if(typeof $==="string"){if($.length>0)return $}else if(typeof $==="object"){let{publicId:Z,id:j}=$;if(typeof Z==="string"&&Z.length>0)return Z;if(typeof j==="string"&&j.length>0||typeof j==="number")return String(j)}throw TypeError("Features.set() was given an `actor` that identifies nobody. Pass a string, or a user with a `publicId` or an `id`.")}function az($){return Object.fromEntries(Object.entries($).filter(([,Z])=>{return Z!==null&&Z!==void 0}))}var kO=50;class NZ{fetcher;entries=new Map;settleListener=null;failListener=null;shellAt=null;settledBacklog=[];shipped=new Set;requestStartedAt=performance.now();renderStartedAt=null;discoveryHintsMuted=!1;constructor($){this.fetcher=$}elapsed(){return Math.round(performance.now()-this.requestStartedAt)}keyFor($,Z){return[$,Z].filter((j)=>j.length>0).join("?")}markRenderStart(){if(this.renderStartedAt===null)this.renderStartedAt=performance.now()}markShell(){if(this.shellAt===null)this.shellAt=this.elapsed()}summarize($){let Z=this.elapsed();return{shellAt:this.shellAt??Z,settledAt:Z,aborted:$,queries:Array.from(this.entries.values(),(j)=>({path:j.path,variantKey:j.variantKey,startedAt:j.startedAt,settledAt:j.settledAt,status:j.status,source:j.source}))}}onQueryFail($){this.failListener=$}muteDiscoveryHints(){this.discoveryHintsMuted=!0}maybeLogLateDiscovery($){if(!$.lateBy||this.discoveryHintsMuted)return;if($.status!=="resolved")return;if(Bun.env.NODE_ENV==="production")return;let Z="";try{let W=JSON.stringify($.data)?.length??0;Z=W>=1024?`${(W/1024).toFixed(1)} kB`:`${W} B`}catch{Z="an unserializable payload"}let j=($.settledAt??0)-$.startedAt,J=$.variantKey?`, { search: ${JSON.stringify(Object.fromEntries(new URLSearchParams($.variantKey)))} }`:"";console.warn(`[gemi] useQuery("${$.patternPath}") was discovered ${$.lateBy}ms into the `+`server render \u2014 under a suspended segment, so its fetch (${j}ms, resolved ${Z}) could not overlap the others. It still streamed. If the query belongs on this route, \`Query.prefetch("${$.patternPath}"${J})\` in the view `+"handler starts it at request time \u2014 but note prefetched data is also re-fetched and "+`streamed into every client-side navigation payload for the route, even when the client already holds it, so weigh that bandwidth against the ${Z}. If the data is only needed conditionally (a closed popover, a hidden tab), \`{ lazy: true }\` + \`trigger()\` avoids running it here at all. \`Query.noPrefetch()\` in the handler marks the omission intentional and silences this hint for the route.`)}read($,Z){return this.entries.get(this.keyFor($,Z))}ensure($,Z={},j="render"){let J=Z.params??{},W=new URLSearchParams(az(Z.search??{}));W.delete("json"),W.sort();let Y=G0($,J),z=W.toString(),X=this.keyFor(Y,z),G=this.entries.get(X);if(G)return G;let F;if(j==="render"&&this.renderStartedAt!==null){let D=Math.round(performance.now()-this.renderStartedAt);if(D>kO)F=D}let Q,O=new Promise((D)=>{Q=D}),K={path:Y,patternPath:$,variantKey:z,lateBy:F,status:"pending",promise:O,source:j,startedAt:this.elapsed()};return this.entries.set(X,K),this.fetcher($,J,W).then((D)=>{K.status="resolved",K.data=D},(D)=>{K.status="rejected",K.error=D}).then(()=>{if(K.settledAt=this.elapsed(),this.maybeLogLateDiscovery(K),K.status==="rejected"&&this.failListener)this.failListener(K);if(this.settleListener)this.settleListener(K);else this.settledBacklog.push(K);Q()}),K}async allSettled(){let $=0;while($!==this.entries.size)$=this.entries.size,await Promise.all(Array.from(this.entries.values(),(Z)=>Z.promise))}snapshotResolved(){let $={};for(let[Z,j]of this.entries){if(j.status!=="resolved")continue;this.shipped.add(Z),$[j.path]??={},$[j.path][j.variantKey]=j.data}return $}onSettle($){this.settleListener=(j)=>{if(this.shipped.has(this.keyFor(j.path,j.variantKey)))return;$(j)};let Z=this.settledBacklog;this.settledBacklog=[];for(let j of Z)this.settleListener(j)}}class x1 extends Error{path;variantKey;status;body;retryAfter;constructor($,Z,j,J,W){super(typeof J?.message==="string"?J.message:`Request to /api${$} failed with status ${j}`);this.path=$;this.variantKey=Z;this.status=j;this.body=J;this.retryAfter=W;this.name="QueryError"}}function LZ(){let $=JSON.stringify({error:w1("permission","Forbidden",403)});return new Response($,{status:403,headers:{"Content-Type":"application/json","Content-Length":String(Buffer.byteLength($)),"Cache-Control":"no-store"}})}function KJ(){return{status:403,error:{message:"Forbidden"}}}function V3($){let Z=HZ.getStore();return(j,J,W)=>{let Y=new URL($.url).origin,z=[G0(j,J),W.toString()].filter((Q)=>Q.length>0).join("?"),X=new Request(`${Y}/${z}`,{headers:$.headers,signal:$.signal}),G=rz($);if(G)CZ(X,G);let F=new S(X,J);return HZ.run(Z,()=>C.run(F,async()=>{try{let Q=await T(a0).dispatchers(G).api.getRouteData(j);if(q$(Q)){if(!Q.ok)throw new x1(G0(j,J),W.toString(),Q.status,Q.body);return Q.body}if(Q instanceof Response){let O=await Q.json().catch(()=>null);if(!Q.ok)throw new x1(G0(j,J),W.toString(),Q.status,O);return O}return Q}catch(Q){if(Q instanceof x1)throw Q;let O=new x1(G0(j,J),W.toString(),500,{message:Q instanceof Error?Q.message:String(Q)});throw O.cause=Q,O}}))}}var qO=new Set(["script","style","template","title"]),yO=/\shidden([\s=/]|$)/i,gO=/"[^"]*"|'[^']*'/g;function mO($){let Z=0,j=0,J=0,W=0;while(W<$.length){let Y=$.indexOf("<",W),z=Y===-1?$.length:Y;if(z>W){let O=$.slice(W,z).replace(/\s+/g,"").length;if(J>0)j+=O;else Z+=O}if(Y===-1)break;if($.startsWith("<!--",Y)){let O=$.indexOf("-->",Y+4);W=O===-1?$.length:O+3;continue}let X=$.indexOf(">",Y);if(X===-1)break;let G=$.slice(Y+1,X);W=X+1;let F=/^\/?([a-zA-Z][a-zA-Z0-9-]*)/.exec(G)?.[1]?.toLowerCase();if(!F)continue;let Q=G.startsWith("/");if(!Q&&qO.has(F)&&!G.endsWith("/")){let O=$.indexOf(`</${F}`,W);W=O===-1?$.length:O;continue}if(F!=="div")continue;if(Q){if(J>0)J-=1}else if(J>0)J+=1;else if(yO.test(G.replace(gO,'""')))J=1}return{shellChars:Z,deferredChars:j}}var pO=1000,hO=64;function cO($){return $>=1000?`${($/1000).toFixed(1)} kB`:`${$} chars`}function dO($,Z){if(Z.deferredChars<pO)return null;if(Z.shellChars>=hO)return null;return`[gemi] GET ${$} streams ${cO(Z.deferredChars)} of its `+`content behind reveal scripts \u2014 a no-JS visitor sees ~${Z.shellChars} chars. If this is a public/content route, add "no-stream" to its middleware.`}function tz($=console.warn){let Z=new Set;return{shouldObserve(j){return!Z.has(j)},report(j,J){if(Z.has(j))return;let W=dO(j,J);if(!W)return;Z.add(j),$(W)}}}function ez(){let $=new TextDecoder,Z="";return{onChunk(j){Z+=$.decode(j,{stream:!0})},measure(){return Z+=$.decode(),mO(Z)}}}function $X($,Z,j=1e4,J){let W=new TextEncoder,Y=()=>{};return new ReadableStream({start(z){let X=!1,G=(Q)=>{if(X)return;X=!0,clearTimeout(F);try{z.close()}catch{}J?.({aborted:Q})};Y=G,z.enqueue(W.encode(`${JSON.stringify($)}
13
+ `)}function WF($,Z={}){let j=new Headers(Z.headers);if(!j.has("content-type"))j.set("content-type","text/plain; charset=utf-8");return new Response(_5($),{status:200,headers:j})}var S5={response:WF,text:_5,parse:C5,fetch:JF};import{createHmac as x5,randomBytes as YF}from"crypto";var i8="v2.";function s8($){return $.startsWith(i8)}function c$(){let $=process.env.SECRET;if(!$)throw Error("Signing in needs a secret to mint session tokens with. Set SECRET in the environment.");return $}function A5($){let Z=YF(16).toString("hex"),j=x5("sha256",c$()).update(`${$}:${Z}`).digest("hex");return`${i8}${j}`}function v3($,Z){let j=x5("sha256",c$()).update(`legacy-session:${Z}:${$}`).digest("hex");return`${i8}${j}`}import{createHash as GF,createHmac as FF,randomInt as QF,timingSafeEqual as R5}from"crypto";function f5($,Z){return Math.floor($/Z)*Z}function zF($,Z){if(Z<=0)return 0;return Math.min(1,Math.max(0,(Z-$)/Z))}function n8($,Z,j,J){return Z*zF(j,J)+$}function XF($){let{current:Z,previous:j,elapsed:J,window:W,limit:Y,cost:z}=$,X=Y-z;if(X<0)return W;let G=Math.max(0,W-J);if(j>0){let Q=W*(1-(X-Z)/j);if(Q<=W)return Math.max(0,Math.ceil(Q-J))}if(Z<=X)return G;if(Z<=0)return G;let F=W*(1-X/Z);return G+Math.max(0,Math.ceil(F))}function E5($){let{allowed:Z,current:j,previous:J,now:W,elapsed:Y,window:z,limit:X,cost:G}=$;if(Z){let Q=n8(j,J,Y,z);return{allowed:!0,limit:X,remaining:Math.max(0,Math.floor(X-Q)),resetAt:W-Y+z,retryAfter:0}}let F=XF({current:j,previous:J,elapsed:Y,window:z,limit:X,cost:G});return{allowed:!1,limit:X,remaining:0,resetAt:W+F,retryAfter:F}}class o8{}class a8 extends o8{buckets=new Map;maxKeys;constructor($={}){super();this.maxKeys=Math.max(1,$.maxKeys??1e5)}consume($){let{key:Z,limit:j,window:J}=$,W=$.cost??1,Y=Date.now(),z=f5(Y,J),X=Y-z,G=this.roll(Z,J,z);G.limit=j;let Q=n8(G.current,G.previous,X,J)+W<=j;if(Q)G.current+=W;if(this.buckets.delete(Z),this.buckets.set(Z,G),this.buckets.size>this.maxKeys)this.evict(Y);return E5({allowed:Q,current:G.current,previous:G.previous,now:Y,elapsed:X,window:J,limit:j,cost:W})}clear(){this.buckets.clear()}get size(){return this.buckets.size}roll($,Z,j){let J=this.buckets.get($);if(!J||J.window!==Z)return{window:Z,limit:0,windowStart:j,current:0,previous:0};if(J.windowStart===j)return J;if(J.windowStart+Z===j)return J.previous=J.current,J.current=0,J.windowStart=j,J;return J.previous=0,J.current=0,J.windowStart=j,J}evict($){for(let[J,W]of this.buckets)if($-W.windowStart>=W.window*2)this.buckets.delete(J);let Z=this.maxKeys-Math.floor(this.maxKeys/10);if(this.buckets.size<=Z)return;let j=[...this.buckets].map(([J,W],Y)=>({key:J,order:Y,spent:W.limit>0?(W.current+W.previous)/W.limit:0}));j.sort((J,W)=>J.spent-W.spent||J.order-W.order);for(let{key:J}of j){if(this.buckets.size<=Z)break;this.buckets.delete(J)}}}var w5="h1.";function w3($,Z,j){let J=FF("sha256",c$()).update(`gemi:one-time:${$}:${Z}:${j}`).digest("hex");return`${w5}${J}`}function kZ($,Z,j,J){let W=typeof J==="string"?J:"",Y=typeof j==="string"?j:"",z=Y.startsWith(w5),X=w3($,Z,W),G=Buffer.from(z?X:W),F=Buffer.from(Y);if(G.length!==F.length||W===""||Y==="")return R5(G,G),!1;return R5(G,F)}function k5($){let Z="";for(let j=0;j<$;j++)Z+=String(QF(0,10));return Z}var y5=320;function yZ($){if(typeof $!=="string")return null;let Z=$.trim();if(Z===""||Z.length>y5)return null;return Z.toLowerCase()}function k3($){if(typeof $!=="string")return null;let Z=$.trim();if(Z.length>y5)return null;let j=Z.toLowerCase();if(j.length<3||j.length>254||!/^[^\s@]+@[^\s@]+$/.test(j))return null;return j}var b5=null;function q5(){try{let $=T();if(typeof $?.bound==="function"&&$.bound(e0))return $.make(e0)}catch{}return b5??=new e0({driver:new a8,limit:1000,window:60}),b5}function v5($){return $.length<=64?$:`sha256:${GF("sha256").update($).digest("hex")}`}async function d$($,Z,j,J){let W=q5(),Y=[[`auth:code-${$}:ip:${v5(g$(j))}`,J.perIp]];if(Z!==null)Y.push([`auth:code-${$}:email:${v5(Z)}`,J.perEmail]);for(let[z,X]of Y){if(!X)continue;let[G,F]=X,Q=await W.consume(z,{limit:G,window:F});if(!Q.allowed)throw new bZ(Q)}}async function g5($,Z,j,J=10){let W=Math.max(86400,Math.ceil(J*60*(j+1)));return(await q5().consume(`auth:code-attempt:${$}:${Z}`,{limit:j,window:W})).allowed}import{randomBytes as t8}from"crypto";class r8 extends S{schema={name:{string:"Invalid name",required:"Name is required","min:2":"Name must be at least 3 characters"},email:{string:"Invalid email",required:"Email is required",email:"Invalid email"},password:{"min:8":"Password must be at least 9 characters"}}}function y3($,Z,j,J=1/0){if(!Number.isInteger(Z)||Z<j||Z>J){let W=J===1/0?`an integer of at least ${j}`:`an integer from ${j} to ${J}`;throw Error(`auth.emailCode.${$} must be ${W}, got ${Z}`)}}function e8($={}){let Z=$.length??6,j=$.expiresInMinutes??10,J=$.linkExpiresInMinutes??10080,W=$.maxAttempts??5;return y3("length",Z,4,12),y3("expiresInMinutes",j,1),y3("linkExpiresInMinutes",J,1),y3("maxAttempts",W,1),{enabled:$.enabled??!1,createUser:$.createUser??!1,length:Z,expiresInMinutes:j,linkExpiresInMinutes:J,maxAttempts:W,requestLimit:{perEmail:$.requestLimit?.perEmail??[5,900],perIp:$.requestLimit?.perIp??[20,900]},verifyLimit:{perEmail:$.verifyLimit?.perEmail??[10,900],perIp:$.verifyLimit?.perIp??[50,900]},uniformMagicLinkResponse:$.uniformMagicLinkResponse??!1,send:$.send??(({email:Y,code:z})=>{if(Bun.env.NODE_ENV!=="production")console.info(`[gemi] email code for ${Y}: ${z} (set auth.emailCode.send to deliver it)`)})}}async function KF($,Z){if(typeof Z!=="string"||Z==="")return!1;try{return await Bun.password.verify($,Z)}catch{return!1}}function FV($){return $}function m5($={}){return{basePath:"/auth",verifyEmail:!0,redirectPath:"/dashboard",signInPath:"/auth/sign-in",sessionExpiresInHours:24,sessionAbsoluteExpiresInHours:672,cookieDomain:null,migrateLegacySession:null,signUpRequest:r8,oauthProviders:{},oauthFailurePath:null,connections:{},connectionStore:null,onConnected:()=>{},verifyPassword:KF,hashPassword:async(Z)=>await Bun.password.hash(Z),generateForgotPasswordToken:async()=>t8(32).toString("hex"),generateEmailVerificationToken:()=>{if(!($.verifyEmail??!0))return"";return t8(32).toString("hex")},generateMagicLinkToken:()=>t8(32).toString("hex"),extendSession:()=>({}),onUserCreated:async()=>{},onSignUp:()=>{},onSignIn:()=>{},onSignOut:()=>{},onForgotPassword:()=>{},onResetPassword:()=>{},onMagicLinkCreated:()=>{},emailCode:e8($.emailCode),generateCode:()=>{return},onAuthenticated:()=>{}}}function $j($){if($&&typeof $==="object")delete $.password;return $}function OF(){return new Proxy({},{get:($,Z)=>h5(Z)})}var p5=new WeakMap;function c5($){if($&&typeof $==="object"){for(let Z of Object.values($))c5(Z);Object.freeze($)}return $}var BF={select:{id:!0,publicId:!0,email:!0,name:!0,locale:!0,globalRole:!0,accounts:{select:{id:!0,publicId:!0,organizationRole:!0,organization:!0}}}},DF=c5({token:!0,expiresAt:!0,absoluteExpiresAt:!0,updatedAt:!0,location:!0,userAgent:!0,user:BF});class Zj{models;constructor($=OF()){this.models=$}run($){return this.models.User.asSystem($)}sessionSelect(){return DF}transaction($){return this.models.User.transaction($)}withLegacySessionLock($,Z){let j=this.models.User.$connection??z$(),J=T(X$).connection(j),W=()=>this.transaction(async()=>{if(J.dialect==="postgres"){let X=`gemi:legacy-session:${$}`;await V1()`SELECT pg_advisory_xact_lock(hashtextextended(${X}, 0))`}return Z()});if(J.dialect!=="sqlite"||V1())return W();let z=(p5.get(J)??Promise.resolve()).then(W,W);return p5.set(J,z.catch(()=>{})),z}async createUser($){let Z=await this.run(()=>this.models.User.create({data:$}));return $j(Z)}async updateUserPassword($){let Z=await this.run(()=>this.models.User.update({where:{id:$.id},data:{password:$.password}}));return $j(Z)}async findUserByEmailAddress($,Z){return await this.run(()=>this.models.User.findUnique({where:Z?{email:$,emailVerifiedAt:{not:null}}:{email:$}}))}async findUserByVerificationToken($){if(typeof $!=="string"||$==="")return null;return await this.run(()=>this.models.User.findFirst({where:{verificationToken:$}}))}async verifyUser($){return await this.run(()=>this.models.User.update({where:{email:$},data:{emailVerifiedAt:new Date}}))}async createSession($){return await this.run(()=>this.models.Session.create({data:$,include:{user:!0}}))}async createSessionV2($){return await this.run(()=>this.models.Session.create({data:$,select:this.sessionSelect()}))}async findSession($){if(!$.token)return null;try{return await this.run(()=>this.models.Session.findUnique({where:{token:$.token},select:this.sessionSelect()}))}catch(Z){return console.error("findSession failed:",Z),null}}async updateSession($){return await this.run(()=>this.models.Session.update({where:{token:$.token},data:{expiresAt:$.expiresAt},select:this.sessionSelect()}))}async deleteSession($){if(!$.token)return;await this.run(()=>this.models.Session.deleteMany({where:{token:$.token}}))}async claimLegacySession($){if(!$.token)return!1;let{count:Z}=await this.run(()=>this.models.Session.deleteMany({where:{token:$.token}}));return Z>0}async deleteAllUserSessions($){await this.run(()=>this.models.Session.deleteMany({where:{userId:$}}))}async createPasswordResetToken($){return await this.run(()=>this.models.PasswordResetToken.create({data:{token:$.token,user:{connect:{id:$.user.id}}}}))}async findPasswordResetToken($){if(typeof $.token!=="string"||$.token==="")return null;return await this.run(()=>this.models.PasswordResetToken.findUnique({where:{token:$.token},include:{user:!0}}))}async deletePasswordResetToken($){return await this.run(()=>this.models.PasswordResetToken.delete({where:{token:$.token}}))}async findInvitation($,Z){if(typeof $!=="string"||typeof Z!=="string")return null;return await this.run(()=>this.models.OrganizationInvitation.findFirst({where:{publicId:$,email:Z}}))}async deleteInvitationById($){await this.run(()=>this.models.OrganizationInvitation.delete({where:{publicId:$}}))}async createAccount($){return await this.run(()=>this.models.Account.create({data:{userId:$.userId,organizationId:$.organizationId,organizationRole:$.organizationRole}}))}async createMagicLinkToken($){return await this.run(()=>this.models.MagicLinkToken.create({data:{email:$.email,token:$.token,pin:$.pin}}))}async findUserMagicLinkToken($){let Z=(j)=>typeof j==="string"&&j!=="";if(!Z($.email))return null;if($.token!==void 0&&!Z($.token))return null;if($.token===void 0&&!Z($.pin))return null;return await this.run(()=>$.token?this.models.MagicLinkToken.findUnique({where:{token_email:{token:$.token,email:$.email}}}):this.models.MagicLinkToken.findUnique({where:{pin_email:{pin:$.pin,email:$.email}}}))}async findMagicLinkTokenByEmail($){return await this.run(()=>this.models.MagicLinkToken.findFirst({where:{email:$},orderBy:{id:"desc"}}))}async claimMagicLinkToken($){let{count:Z}=await this.run(()=>this.models.MagicLinkToken.deleteMany({where:{id:$}}));return Z===1}async deleteMagicLinkToken($){await this.run(()=>this.models.MagicLinkToken.deleteMany({where:{email:$}}))}async createSocialAccount($){return await this.run(()=>this.models.SocialAccount.create({data:$}))}async findUserBySocialAccount($,Z){if(!Z)return null;let j=await this.run(()=>this.models.SocialAccount.findFirst({where:{provider:$,providerId:Z},include:{user:!0}}));return j?$j(j.user):null}async findSocialAccounts($,Z){return await this.run(()=>this.models.SocialAccount.findMany({where:{userId:$,provider:Z},orderBy:{id:"asc"}}))}async claimSocialAccount($,Z){let{count:j}=await this.run(()=>this.models.SocialAccount.updateMany({where:{id:$.id,providerId:$.providerId},data:{providerId:Z}}));return j===1}}import{randomBytes as WO}from"crypto";function f0($,Z,j,J,W){return p0(Z,WW($,Z),j,J,W)}function p0($,Z,j,J,W,Y){let z=zj(Z,j,J);if(W&&Z!==z)throw RangeError(h9($,Z,j,J,Y));return z}function WW($,Z){let j=$[Z];if(j===void 0)throw TypeError(k2(Z));return j}function K0($){return $!==null&&/object|function/.test(typeof $)}function b0($,Z=Map){let j=new Z;return(J,...W)=>{if(j.has(J))return j.get(J);let Y=$(J,...W);return j.set(J,Y),Y}}function Dj($){return K$({name:$},1)}function K$($,Z){return u0((j)=>({value:j,configurable:1,writable:!Z}),$)}function YW($){return u0((Z)=>({get:Z,configurable:1}),$)}function t3($){return{[Symbol.toStringTag]:{value:$,configurable:1}}}function a$($,Z){let j={},J=$.length;for(let W of Z)j[$[--J]]=W;return j}function u0($,Z,j){let J={};for(let W in Z)J[W]=$(Z[W],W,j);return J}function lZ($,Z,j){let J={};for(let W=0;W<Z.length;W++){let Y=Z[W];J[Y]=$(Y,W,j)}return J}function UF($,Z,j){let J={};for(let W=0;W<$.length;W++)J[Z[W]]=j[$[W]];return J}function w0($,Z){let j={};for(let J of $)j[J]=Z[J];return j}function Uj($,Z){let j={};for(let J in Z)$.has(J)||(j[J]=Z[J]);return j}function Vj($){$={...$};let Z=Object.keys($);for(let j of Z)$[j]===void 0&&delete $[j];return $}function zW($,Z){for(let j of Z)if(!(j in $))return 0;return 1}function XW($,Z,j){for(let J of $)if(Z[J]!==j[J])return 0;return 1}function GW($,Z,j){let J={...j};for(let W=0;W<Z;W++)J[$[W]]=0;return J}function b($,...Z){return(...j)=>$(...Z,...j)}function d5($){return $[0].toUpperCase()+$.substring(1)}function iZ($){return $.slice().sort()}function d3($,Z){return String(Z).padStart($,"0")}function k1($,Z){return Math.sign($-Z)}function zj($,Z,j){return Math.min(Math.max($,Z),j)}function I1($,Z){return[Math.floor($/Z),gZ($,Z)]}function gZ($,Z){return($%Z+Z)%Z}function g1($,Z){return[e3($,Z),Tj($,Z)]}function e3($,Z){return Math.trunc($/Z)||0}function Tj($,Z){return $%Z||0}function q3($){return Math.abs($%1)===0.5}function FW($,Z,j){let J=0,W=0;for(let X=0;X<=Z;X++){let G=$[j[X]],F=Z1[X],Q=m/F,[O,K]=g1(G,Q);J+=K*F,W+=O}let[Y,z]=g1(J,m);return[W+Y,z]}function $6($,Z,j){let J={};for(let W=Z;W>=0;W--){let Y=Z1[W];J[j[W]]=e3($,Y),$=Tj($,Y)}return J}function QW($){return $===v?w6:[]}function KW($){return $===v?j3:[]}function OW($){return $===v?["year","day"]:[]}function BW($){if($!==void 0)return a($)}function DW($){if($!==void 0)return l0($)}function Ij($){if($!==void 0)return sZ($)}function l0($){return TW(sZ($))}function sZ($){return VW(zQ($))}function Mj($){if($==null)throw TypeError("Cannot be null or undefined");return $}function UW($,Z){if(Z==null)throw RangeError(k2($));return Z}function P1($){if(!K0($))throw TypeError(p9);return $}function Z6($,Z,j=$){if(typeof Z!==$)throw TypeError(eZ(j,Z));return Z}function VW($,Z="number"){if(!Number.isInteger($))throw RangeError(RF(Z,$));return $||0}function TW($,Z="number"){if($<=0)throw RangeError(bF(Z,$));return $}function Pj($){if(typeof $=="symbol")throw TypeError(yF);return String($)}function u3($,Z){return K0($)?String($):a($,Z)}function j6($){if(typeof $=="string")return BigInt($);if(typeof $!="bigint")throw TypeError(kF($));return $}function IW($,Z="number"){if(typeof $=="bigint")throw TypeError(wF(Z));if($=Number($),!Number.isFinite($))throw RangeError(vF(Z,$));return $}function P0($,Z){return Math.trunc(IW($,Z))||0}function MW($,Z){return VW(IW($,Z),Z)}function u5($,Z){return TW(P0($,Z),Z)}function Nj($,Z){let[j,J]=g1(Z,m),W=$+j,Y=Math.sign(W);return Y&&Y===-Math.sign(J)&&(W-=Y,J+=Y*m),[W,J]}function l$($,Z,j=1){return Nj($[0]+Z[0]*j,$[1]+Z[1]*j)}function i$($,Z){return Nj($[0],$[1]+Z)}function q0($,Z){return l$(Z,$,-1)}function L0($,Z){return k1($[0],Z[0])||k1($[1],Z[1])}function PW($,Z,j){return L0($,Z)===-1||L0($,j)===1}function J6($,Z=1){let j=BigInt(m/Z);return[Number($/j),Number($%j)*Z]}function s$($,Z=1){let j=m/Z,[J,W]=g1($,j);return[J,W*Z]}function NW($,Z=1){let[j,J]=$,W=Math.floor(J/Z),Y=m/Z;return BigInt(j)*BigInt(Y)+BigInt(W)}function g0($,Z=1,j){let[J,W]=$,[Y,z]=g1(W,Z);return J*(m/Z)+(Y+(j?z/Z:0))}function Lj($,Z,j=I1){let[J,W]=$,[Y,z]=j(W,Z);return[J*(m/Z)+Y,z]}function Hj($,Z){let j=$.formatToParts(Z),J={};for(let W of j)J[W.type]=W.value;return J}function Cj($){return f0($,"isoYear",uZ,dZ,1),$.isoYear===uZ?f0($,"isoMonth",4,12,1):$.isoYear===dZ&&f0($,"isoMonth",1,9,1),$}function y1($){return N1({...$,...d0,isoHour:12}),$}function N1($){let Z=f0($,"isoYear",uZ,dZ,1),j=Z===uZ?1:Z===dZ?-1:0;return j&&m0(N0({...$,isoDay:$.isoDay+j,isoNanosecond:$.isoNanosecond-j})),$}function m0($){if(!$||PW($,BQ,OQ))throw RangeError(E6);return $}function m1($){return FW($,5,o0)[1]}function W6($){let[Z,j]=I1($,m);return[$6(j,5,o0),Z]}function LW($){return HW($)[0]}function HW($){return Lj($,c0)}function H0($){return r$($.isoYear,$.isoMonth,$.isoDay,$.isoHour,$.isoMinute,$.isoSecond,$.isoMillisecond)}function N0($){let Z=H0($);if(Z!==void 0){let[j,J]=g1(Z,R0);return[j,J*j1+($.isoMicrosecond||0)*P$+($.isoNanosecond||0)]}}function _j($,Z){let[j,J]=W6(m1($)-Z);return m0(N0({...$,isoDay:$.isoDay+J,...j}))}function l3(...$){return r$(...$)/t9}function r$(...$){let[Z,j]=CW(...$),J=Z.valueOf();if(!isNaN(J))return J-j*R0}function CW($,Z=1,j=1,J=0,W=0,Y=0,z=0){let X=$===uZ?1:$===dZ?-1:0,G=new Date;return G.setUTCHours(J,W,Y,z),G.setUTCFullYear($,Z-1,j+X),[G,X]}function h1($,Z){let[j,J]=i$($,Z);J<0&&(J+=m,j-=1);let[W,Y]=I1(J,j1),[z,X]=I1(Y,P$);return Y6(j*R0+W,z,X)}function Y6($,Z=0,j=0){let J=Math.ceil(Math.max(0,Math.abs($)-KQ)/R0)*Math.sign($),W=new Date($-J*R0);return a$(y6,[W.getUTCFullYear(),W.getUTCMonth()+1,W.getUTCDate()+J,W.getUTCHours(),W.getUTCMinutes(),W.getUTCSeconds(),W.getUTCMilliseconds(),Z,j])}function _W($){return[$.isoYear,$.isoMonth,$.isoDay]}function SW(){return T1}function Sj($,Z){switch(Z){case 2:return xj($)?29:28;case 4:case 6:case 9:case 11:return 30}return 31}function xW($){return xj($)?366:365}function xj($){return $%4==0&&($%100!=0||$%400==0)}function AW($){let[Z,j]=CW($.isoYear,$.isoMonth,$.isoDay);return gZ(Z.getUTCDay()-j,7)||7}function fW({isoYear:$}){return $<1?["bce",1-$]:["ce",$]}function VF($){let Z=H0($);if(Z<UQ)return fW($);let j=Hj(e2(n$),Z),{era:J,eraYear:W}=p7(j,n$);return[J,W]}function z6($){return O$($),X6($,1),$}function O$($){return EW($,1),$}function l5($){return XW(l2,$,EW($))}function EW($,Z){let{isoYear:j}=$,J=f0($,"isoMonth",1,SW(),Z);return{isoYear:j,isoMonth:J,isoDay:f0($,"isoDay",1,Sj(j,J),Z)}}function X6($,Z){return a$(o0,[f0($,"isoHour",0,23,Z),f0($,"isoMinute",0,59,Z),f0($,"isoSecond",0,59,Z),f0($,"isoMillisecond",0,999,Z),f0($,"isoMicrosecond",0,999,Z),f0($,"isoNanosecond",0,999,Z)])}function k($){return $===void 0?0:UY(P1($))}function nZ($,Z=0){$=i0($);let j=VY($),J=_Q($,Z);return[UY($),J,j]}function Aj($){return VY(i0($))}function RW($){return $=i0($),n2($,9,6,1)}function t$($,Z,j,J=9,W=0,Y=4){Z=i0(Z);let z=n2(Z,J,W),X=Rj(Z),G=W3(Z,Y),F=J3(Z,J,W,1);return z==null?z=Math.max(j,F):kW(z,F),X=bj(X,F,1),$&&(G=((Q)=>Q<4?(Q+2)%4:Q)(G)),[z,F,X,G]}function G6($,Z=6,j){let J=Rj($=vj($,r3)),W=W3($,7),Y=J3($,Z);return Y=UW(r3,Y),J=bj(J,Y,void 0,j),[Y,J,W]}function fj($){return o2(i0($))}function bW($,Z){return Ej(i0($),Z)}function Ej($,Z=4){let j=wW($);return[W3($,4),...vW(J3($,Z),j)]}function vW($,Z){return $!=null?[Z1[$],$<4?9-3*$:-1]:[Z===void 0?1:10**(9-Z),Z]}function Rj($){let Z=$[mZ];return Z===void 0?1:P0(Z,mZ)}function bj($,Z,j,J){let W=J?m:Z1[Z+1];if(W){let Y=Z1[Z];if(W%(($=p0(mZ,$,1,W/Y-(J?0:1),1))*Y))throw RangeError(eZ(mZ,$))}else $=p0(mZ,$,1,j?1e9:1,1);return $}function wW($){let Z=$[Yj];if(Z!==void 0){if(typeof Z!="number"){if(Pj(Z)==="auto")return;throw RangeError(eZ(Yj,Z))}Z=p0(Yj,Math.floor(Z),0,9,1)}return Z}function i0($){return $===void 0?{}:P1($)}function vj($,Z){return typeof $=="string"?{[Z]:$}:P1($)}function J0($){if($!==void 0){if(K0($))return Object.assign(Object.create(null),$);throw TypeError(p9)}}function F6($,Z){return $&&Object.assign(Object.create(null),$,{overflow:TQ[Z]})}function wj($,Z,j=9,J=0,W){let Y=Z[$];if(Y===void 0)return W?J:void 0;if(Y=Pj(Y),Y==="auto")return W?J:null;let z=Qj[Y];if(z===void 0&&(z=FQ[Y]),z===void 0)throw RangeError(u9($,Y,Qj));return p0($,z,J,j,1,Z3),z}function B$($,Z,j,J=0){let W=j[$];if(W===void 0)return J;let Y=Pj(W),z=Z[Y];if(z===void 0)throw RangeError(u9($,Y,Z));return z}function kW($,Z){if(Z>$)throw RangeError(ZQ)}function O0($){return{branding:g6,epochNanoseconds:$}}function V0($,Z,j){return{branding:_1,calendar:j,timeZone:Z,epochNanoseconds:$}}function W0($,Z=$.calendar){return{branding:L$,calendar:Z,...w0(KY,$)}}function Y0($,Z=$.calendar){return{branding:N$,calendar:Z,...w0(i2,$)}}function F$($,Z=$.calendar){return{branding:zZ,calendar:Z,...w0(i2,$)}}function i3($,Z=$.calendar){return{branding:XZ,calendar:Z,...w0(i2,$)}}function s0($){return{branding:q6,...w0(QY,$)}}function i($){return{branding:m6,sign:c1($),...w0(c2,$)}}function yW($){return LW($.epochNanoseconds)}function Q6($){return Lj($.epochNanoseconds,j1)[0]}function qW($){return NW($.epochNanoseconds,P$)}function gW($){return NW($.epochNanoseconds)}function mW($){return $.epochNanoseconds}function D0($){return typeof $=="string"?$:a($.id)}function e$($,Z){return $===Z||D0($)===D0(Z)}function pW($,Z,j,J,W){let Y=Q$(J),[z,X]=((V,I)=>{let P=I((V=vj(V,Bj))[BY]),M=CQ(V);return M=UW(Bj,M),[M,P]})(W,$);if(hZ(Math.max(z,Y),X))return i5(J,z);if(!X)throw RangeError(R6);let[G,F,Q]=V6(Z,j,X),O=W2(Q),K=T6(Q),D=Y2(Q),B=K(F,G,J),U=D(F,G,B,z);return hZ(z,X)?i5(U,z):((V,I,P,M,x,f,A)=>{let _=c1(V),[L,N]=kj(M,u2(P,V),P,_,x,f,A),l=yj(I,L,N);return V[y[P]]+l*_})(U,O(B),z,F,G,O,K)}function i5($,Z){return g0(Q0($),Z1[Z],1)}function kj($,Z,j,J,W,Y,z){let X=y[j],G={...Z,[X]:Z[X]+J},F=z($,W,Z),Q=z($,W,G);return[Y(F),Y(Q)]}function yj($,Z,j){let J=g0(q0(Z,j));if(!J)throw RangeError($3);return g0(q0(Z,$))/J}function hW($,Z){let[j,J,W]=G6(Z,5,1);return O0(O6($.epochNanoseconds,j,J,W,1))}function cW($,Z,j){let{epochNanoseconds:J,timeZone:W,calendar:Y}=Z,[z,X,G]=G6(j);if(z===0&&X===1)return Z;let F=$(W);if(z===6)J=((Q,O,K,D)=>{let B=C0(K,O),[U,V]=Q(B),I=K.epochNanoseconds,P=v0(O,U),M=v0(O,V);if(PW(I,P,M))throw RangeError($3);return rW(yj(I,P,M),D)?M:P})(oW,F,Z,G);else{let Q=F.getOffsetNanosecondsFor(J);J=U$(F,sW(h1(J,Q),z,X,G),Q,2,0,1)}return V0(J,W,Y)}function dW($,Z){return W0(sW($,...G6(Z)),$.calendar)}function uW($,Z){let[j,J,W]=G6(Z,5);var Y;return s0((Y=W,qj($,oZ(j,J),Y)[0]))}function lW($,Z){let j=$(Z.timeZone),J=C0(Z,j),[W,Y]=oW(J),z=g0(q0(v0(j,W),v0(j,Y)),v6,1);if(z<=0)throw RangeError($3);return z}function iW($,Z){let{timeZone:j,calendar:J}=Z,W=((Y,z,X)=>v0(z,Y(C0(X,z))))(aW,$(j),Z);return V0(W,j,J)}function sW($,Z,j,J){return nW($,oZ(Z,j),J)}function nW($,Z,j){let[J,W]=qj($,Z,j);return N1({...V$($,W),...J})}function qj($,Z,j){return W6(p1(m1($),Z,j))}function s3($){return p1($,b6,7)}function oZ($,Z){return Z1[$]*Z}function oW($){let Z=aW($);return[Z,V$(Z,1)]}function aW($){return QQ(6,$)}function TF($,Z,j){let J=Math.min(Q$($),6);return ZZ(B6(Q0($,J),Z,j),J)}function K6($,Z,j,J,W,Y,z,X,G,F){if(J===0&&W===1)return $;let Q=hZ(J,X)?I6(X)&&J<6&&j>=6?MF:IF:PF,[O,K,D]=Q($,Z,j,J,W,Y,z,X,G,F);return D&&J!==7&&(O=((B,U,V,I,P,M,x,f)=>{let A=c1(B);for(let _=I+1;_<=V;_++){if(_===7&&V!==7)continue;let L=u2(_,B);L[y[_]]+=A;let N=g0(q0(x(f(P,M,L)),U));if(N&&Math.sign(N)!==A)break;B=L}return B})(O,K,j,Math.max(6,J),z,X,G,F)),O}function O6($,Z,j,J,W){if(Z===6){let Y=((z)=>z[0]+z[1]/m)($);return[p1(Y,j,J),0]}return B6($,oZ(Z,j),J,W)}function B6($,Z,j,J){let[W,Y]=$;J&&Y<0&&(Y+=m,W-=1);let[z,X]=I1(p1(Y,Z,j),m);return Nj(W+z,X)}function p1($,Z,j){return rW($/Z,j)*Z}function rW($,Z){return AQ[Z]($)}function IF($,Z,j,J,W,Y){let z=c1($),X=Q0($),G=O6(X,J,W,Y),F=q0(X,G),Q=Math.sign(G[0]-X[0])===z,O=ZZ(G,Math.min(j,6));return[{...$,...O},l$(Z,F),Q]}function MF($,Z,j,J,W,Y,z,X,G,F){let Q=c1($),O=g0(Q0($,5)),K=oZ(J,W),D=p1(O,K,Y),[B,U]=kj(z,{...$,...d2},6,Q,X,G,F),V=D-g0(q0(B,U)),I=0;V&&Math.sign(V)!==Q?Z=i$(B,D):(I+=Q,D=p1(V,K,Y),Z=i$(U,D));let P=P6(D);return[{...$,...P,days:$.days+I},Z,Boolean(I)]}function PF($,Z,j,J,W,Y,z,X,G,F){let Q=c1($),O=y[J],K=u2(J,$);J===7&&($={...$,weeks:$.weeks+Math.trunc($.days/7)});let D=e3($[O],W)*W;K[O]=D;let[B,U]=kj(z,K,J,W*Q,X,G,F),V=D+yj(Z,B,U)*Q*W,I=p1(V,W,Y),P=Math.sign(I-V)===Q;return K[O]=I,[K,P?U:B,P]}function gj($,Z,j,J){let[W,Y,z,X]=((F)=>{let Q=Ej(F=i0(F));return[F.timeZone,...Q]})(J),G=W!==void 0;return((F,Q,O,K,D,B)=>{O=B6(O,D,K,1);let U=Q.getOffsetNanosecondsFor(O);return lj(h1(O,U),B)+(F?D$(s3(U)):"Z")})(G,Z(G?$(W):H$),j.epochNanoseconds,Y,z,X)}function mj($,Z,j){let[J,W,Y,z,X,G]=((F)=>{F=i0(F);let Q=o2(F),O=wW(F),K=xQ(F),D=W3(F,4),B=J3(F,4);return[Q,SQ(F),K,D,...vW(B,O)]})(j);return((F,Q,O,K,D,B,U,V,I,P)=>{K=B6(K,I,V,1);let M=F(O).getOffsetNanosecondsFor(K);return lj(h1(K,M),P)+D$(s3(M),U)+((x,f)=>f!==1?"["+(f===2?"!":"")+D0(x)+"]":"")(O,B)+ij(Q,D)})($,Z.calendar,Z.timeZone,Z.epochNanoseconds,J,W,Y,z,X,G)}function pj($,Z){let[j,J,W,Y]=((F)=>(F=i0(F),[o2(F),...Ej(F)]))(Z);return z=$.calendar,X=j,G=Y,lj(nW($,W,J),G)+ij(z,X);var z,X,G}function hj($,Z){return j=$.calendar,J=$,W=fj(Z),n3(J)+ij(j,W);var j,J,W}function cj($,Z){return tW($.calendar,eW,$,fj(Z))}function dj($,Z){return tW($.calendar,NF,$,fj(Z))}function uj($,Z){let[j,J,W]=bW(Z);return Y=W,$7(qj($,J,j)[0],Y);var Y}function D6($,Z){let[j,J,W]=bW(Z,3);return J>1&&($={...$,...TF($,J,j)}),((Y,z)=>{let{sign:X}=Y,G=X===-1?_0(Y):Y,{hours:F,minutes:Q}=G,[O,K]=Lj(Q0(G,3),c0,g1);G7(O);let D=sj(K,z),B=z>=0||!X||D;return(X<0?"-":"")+"P"+s5({Y:G$(G.years),M:G$(G.months),W:G$(G.weeks),D:G$(G.days)})+(F||Q||O||B?"T"+s5({H:G$(F),M:G$(Q),S:G$(O,B)+D}):"")})($,W)}function tW($,Z,j,J){let W=D0($),Y=J>1||J===0&&W!==v;return J===1?W===v?Z(j):n3(j):Y?n3(j)+Z7(W,J===2):Z(j)}function s5($){let Z=[];for(let j in $){let J=$[j];J&&Z.push(J,j)}return Z.join("")}function lj($,Z){return n3($)+"T"+$7($,Z)}function n3($){return eW($)+"-"+h0($.isoDay)}function eW($){let{isoYear:Z}=$;return(Z<0||Z>9999?j7(Z)+d3(6,Math.abs(Z)):d3(4,Z))+"-"+h0($.isoMonth)}function NF($){return h0($.isoMonth)+"-"+h0($.isoDay)}function $7($,Z){let j=[h0($.isoHour),h0($.isoMinute)];return Z!==-1&&j.push(h0($.isoSecond)+((J,W,Y,z)=>sj(J*j1+W*P$+Y,z))($.isoMillisecond,$.isoMicrosecond,$.isoNanosecond,Z)),j.join(":")}function D$($,Z=0){if(Z===1)return"";let[j,J]=I1(Math.abs($),v6),[W,Y]=I1(J,b6),[z,X]=I1(Y,c0);return j7($)+h0(j)+":"+h0(W)+(z||X?":"+h0(z)+sj(X):"")}function ij($,Z){if(Z!==1){let j=D0($);if(Z>1||Z===0&&j!==v)return Z7(j,Z===2)}return""}function Z7($,Z){return"["+(Z?"!":"")+"u-ca="+$+"]"}function sj($,Z){let j=d3(9,$);return j=Z===void 0?j.replace(RQ,""):j.slice(0,Z),j?"."+j:""}function j7($){return $<0?"-":"+"}function G$($,Z){return $||Z?$.toLocaleString("fullwide",{useGrouping:0}):""}function LF($,Z){let{epochNanoseconds:j}=$,J=(Z.getOffsetNanosecondsFor?Z:Z($.timeZone)).getOffsetNanosecondsFor(j),W=h1(j,J);return{calendar:$.calendar,...W,offsetNanoseconds:J}}function J7($,Z){let j=C0(Z,$);return{calendar:Z.calendar,...w0(KY,j),offset:D$(j.offsetNanoseconds),timeZone:Z.timeZone}}function U$($,Z,j,J=0,W=0,Y,z){if(j!==void 0&&J===1&&(J===1||z))return _j(Z,j);let X=$.getPossibleInstantsFor(Z);if(j!==void 0&&J!==3){let G=((F,Q,O,K)=>{let D=N0(Q);K&&(O=s3(O));for(let B of F){let U=g0(q0(B,D));if(K&&(U=s3(U)),U===O)return B}})(X,Z,j,Y);if(G!==void 0)return G;if(J===0)throw RangeError(oF)}return z?N0(Z):v0($,Z,W,X)}function v0($,Z,j=0,J=$.getPossibleInstantsFor(Z)){if(J.length===1)return J[0];if(j===1)throw RangeError(aF);if(J.length)return J[j===3?1:0];let W=N0(Z),Y=((X,G)=>{let F=X.getOffsetNanosecondsFor(i$(G,-m));return oj(X.getOffsetNanosecondsFor(i$(G,m))-F)})($,W),z=Y*(j===2?-1:1);return(J=$.getPossibleInstantsFor(h1(W,z)))[j===2?0:J.length-1]}function nj($){if(Math.abs($)>=m)throw RangeError(sF);return $}function oj($){if($>m)throw RangeError(nF);return $}function aj($,Z,j){return O0(m0(l$(Z.epochNanoseconds,((J)=>{if(F7(J))throw RangeError(eF);return Q0(J,5)})($?_0(j):j))))}function rj($,Z,j,J,W,Y=Object.create(null)){let z=Z(J.timeZone),X=$(J.calendar);return{...J,...j2(z,X,J,j?_0(W):W,Y)}}function tj($,Z,j,J,W=Object.create(null)){let{calendar:Y}=j;return W0(J2($(Y),j,Z?_0(J):J,W),Y)}function ej($,Z,j,J,W){let{calendar:Y}=j;return Y0(U6($(Y),j,Z?_0(J):J,W),Y)}function $2($,Z,j,J,W=Object.create(null)){let Y=j.calendar,z=$(Y),X=pZ(z,j);Z&&(J=M6(J)),J.sign<0&&(X=z.dateAdd(X,{...U0,months:1}),X=V$(X,-1));let G=z.dateAdd(X,J,W);return F$(pZ(z,G),Y)}function Z2($,Z,j){return s0(W7(Z,$?_0(j):j)[0])}function j2($,Z,j,J,W){let Y=Q0(J,5),z=j.epochNanoseconds;if(F7(J)){let X=C0(j,$);z=l$(v0($,{...U6(Z,X,{...J,...d2},W),...w0(o0,X)}),Y)}else z=l$(z,Y),k(W);return{epochNanoseconds:m0(z)}}function J2($,Z,j,J){let[W,Y]=W7(Z,j);return N1({...U6($,Z,{...j,...d2,days:j.days+Y},J),...W})}function U6($,Z,j,J){if(j.years||j.months||j.weeks)return $.dateAdd(Z,j,J);k(J);let W=j.days+Q0(j,5)[0];return W?y1(V$(Z,W)):Z}function pZ($,Z,j=1){return V$(Z,j-$.day(Z))}function W7($,Z){let[j,J]=Q0(Z,5),[W,Y]=W6(m1($)+J);return[W,j+Y]}function V$($,Z){return Z?{...$,...Y6(H0($)+Z*R0)}:$}function V6($,Z,j){let J=$(j.calendar);return I6(j)?[j,J,Z(j.timeZone)]:[{...j,...d0},J]}function W2($){return $?mW:N0}function T6($){return $?b(j2,$):J2}function Y2($){return $?b(CF,$):_F}function I6($){return $&&$.epochNanoseconds}function hZ($,Z){return $<=6-(I6(Z)?1:0)}function z2($,Z,j,J,W,Y,z){let X=$(i0(z).relativeTo),G=Math.max(Q$(W),Q$(Y));if(hZ(G,X))return i($Z(((U,V,I,P)=>{let M=l$(Q0(U),Q0(V),P?-1:1);if(!Number.isFinite(M[0]))throw RangeError(E6);return{...U0,...ZZ(M,I)}})(W,Y,G,J)));if(!X)throw RangeError(R6);J&&(Y=_0(Y));let[F,Q,O]=V6(Z,j,X),K=T6(O),D=Y2(O),B=K(Q,F,W);return i(D(Q,F,K(Q,B,Y),G))}function Y7($,Z,j,J,W){let Y=Q$(J),[z,X,G,F,Q]=((A,_,L)=>{A=vj(A,r3);let N=n2(A),l=L(A[BY]),d=Rj(A),E1=W3(A,7),e=J3(A);if(N===void 0&&e===void 0)throw RangeError($Q);return e==null&&(e=0),N==null&&(N=Math.max(e,_)),kW(N,e),d=bj(d,e,1),[N,e,d,E1,l]})(W,Y,$),O=Math.max(Y,z);if(!I6(Q)&&O<=6)return i($Z(((A,_,L,N,l)=>{let d=O6(Q0(A),L,N,l);return{...U0,...ZZ(d,_)}})(J,z,X,G,F)));if(!Q)throw RangeError(R6);let[K,D,B]=V6(Z,j,Q),U=W2(B),V=T6(B),I=Y2(B),P=V(D,K,J),M=I(D,K,P,z),x=J.sign,f=c1(M);if(x&&f&&x!==f)throw RangeError($3);return f&&(M=K6(M,U(P),z,X,G,F,D,K,U,V)),i(M)}function z7($){return $.sign===-1?M6($):$}function M6($){return i(_0($))}function _0($){let Z={};for(let j of y)Z[j]=-1*$[j]||0;return Z}function X7($){return!$.sign}function c1($,Z=y){let j=0;for(let J of Z){let W=Math.sign($[J]);if(W){if(j&&j!==W)throw RangeError(tF);j=W}}return j}function $Z($){for(let Z of GQ)p0(Z,$[Z],-$W,$W,1);return G7(g0(Q0($),c0)),$}function G7($){if(!Number.isSafeInteger($))throw RangeError(rF)}function Q0($,Z=6){return FW($,Z,y)}function ZZ($,Z=6){let[j,J]=$,W=$6(J,Z,y);if(W[y[Z]]+=j*(m/Z1[Z]),!Number.isFinite(W[y[Z]]))throw RangeError(E6);return W}function P6($,Z=5){return $6($,Z,y)}function F7($){return Boolean(c1($,FY))}function Q$($){let Z=9;for(;Z>0&&!$[y[Z]];Z--);return Z}function HF($,Z){return[$,Z]}function n5($){let Z=Math.floor($/h3)*h3;return[Z,Z+h3]}function Q7($){let Z=d1($=u3($));if(!Z)throw RangeError(E0($));let j;if(Z.m)j=0;else{if(!Z.offset)throw RangeError(E0($));j=jZ(Z.offset)}return Z.timeZone&&Q2(Z.timeZone,1),O0(_j(z6(Z),j))}function K7($){let Z=d1(a($));if(!Z)throw RangeError(E0($));if(Z.timeZone)return P7(Z,Z.offset?jZ(Z.offset):void 0);if(Z.m)throw RangeError(E0($));return L7(Z)}function O7($,Z){let j=d1(a($));if(!j||!j.timeZone)throw RangeError(E0($));let{offset:J}=j,W=J?jZ(J):void 0,[,Y,z]=nZ(Z);return P7(j,W,Y,z)}function jZ($){let Z=Q2($);if(Z===void 0)throw RangeError(E0($));return Z}function B7($){let Z=d1(a($));if(!Z||Z.m)throw RangeError(E0($));return W0(N7(Z))}function N6($){let Z=d1(a($));if(!Z||Z.m)throw RangeError(E0($));return Y0(Z.p?N7(Z):L7(Z))}function D7($,Z){let j=G2(a(Z));if(j)return X2(j),F$(Cj(O$(j)));let J=N6(Z);return F$(pZ($(J.calendar),J))}function X2($){if($.calendar!==v)throw RangeError(M1($.calendar))}function U7($,Z){let j=F2(a(Z));if(j)return X2(j),i3(O$(j));let J=N6(Z),{calendar:W}=J,Y=$(W),[z,X,G]=Y.h(J),[F,Q]=Y.I(z,X),[O,K]=Y.N(F,Q,G);return i3(y1(Y.P(O,K,G)),W)}function V7($){let Z,j=((J)=>{let W=yQ.exec(J);return W?(L6(W[10]),_7(W)):void 0})(a($));if(!j){if(j=d1($),!j)throw RangeError(E0($));if(!j.p)throw RangeError(E0($));if(j.m)throw RangeError(M1("Z"));X2(j)}if((Z=G2($))&&l5(Z))throw RangeError(E0($));if((Z=F2($))&&l5(Z))throw RangeError(E0($));return s0(X6(j,1))}function T7($){let Z=((j)=>{let J=mQ.exec(j);return J?((W)=>{function Y(Q,O,K){let D=0,B=0;if(K&&([D,G]=I1(G,Z1[K])),Q!==void 0){if(X)throw RangeError(M1(Q));B=((U)=>{let V=parseInt(U);if(!Number.isFinite(V))throw RangeError(M1(U));return V})(Q),z=1,O&&(G=K2(O)*(Z1[K]/c0),X=1)}return D+B}let z=0,X=0,G=0,F={...a$(y,[Y(W[2]),Y(W[3]),Y(W[4]),Y(W[5]),Y(W[6],W[7],5),Y(W[8],W[9],4),Y(W[10],W[11],3)]),...$6(G,2,y)};if(!z)throw RangeError(c9(y));return O2(W[1])<0&&(F=_0(F)),F})(J):void 0})(a($));if(!Z)throw RangeError(E0($));return i($Z(Z))}function I7($){let Z=d1($)||G2($)||F2($);return Z?Z.calendar:$}function M7($){let Z=d1($);return Z&&(Z.timeZone||Z.m&&H$||Z.offset)||$}function P7($,Z,j=0,J=0){let W=H6($.timeZone),Y=p6(W);return V0(U$(Y,z6($),Z,j,J,!Y.v,$.m),W,aZ($.calendar))}function N7($){return H7(N1(z6($)))}function L7($){return H7(y1(O$($)))}function H7($){return{...$,calendar:aZ($.calendar)}}function d1($){let Z=kQ.exec($);return Z?((j)=>{let J=j[10],W=(J||"").toUpperCase()==="Z";return{isoYear:C7(j),isoMonth:parseInt(j[4]),isoDay:parseInt(j[5]),..._7(j.slice(5)),...L6(j[16]),p:Boolean(j[6]),m:W,offset:W?void 0:J}})(Z):void 0}function G2($){let Z=vQ.exec($);return Z?((j)=>({isoYear:C7(j),isoMonth:parseInt(j[4]),isoDay:1,...L6(j[5])}))(Z):void 0}function F2($){let Z=wQ.exec($);return Z?((j)=>({isoYear:o$,isoMonth:parseInt(j[1]),isoDay:parseInt(j[2]),...L6(j[3])}))(Z):void 0}function Q2($,Z){let j=qQ.exec($);return j?((J,W)=>{let Y=J[4]||J[5];if(W&&Y)throw RangeError(M1(Y));return nj((u$(J[2])*v6+u$(J[3])*b6+u$(J[4])*c0+K2(J[5]||""))*O2(J[1]))})(j,Z):void 0}function C7($){let Z=O2($[1]),j=parseInt($[2]||$[3]);if(Z<0&&!j)throw RangeError(M1(-0));return Z*j}function _7($){let Z=u$($[3]);return{...W6(K2($[4]||""))[0],isoHour:u$($[1]),isoMinute:u$($[2]),isoSecond:Z===60?59:Z}}function L6($){let Z,j,J=[];if($.replace(gQ,(W,Y,z)=>{let X=Boolean(Y),[G,F]=z.split("=").reverse();if(F){if(F==="u-ca")J.push(G),Z||(Z=X);else if(X||/[A-Z]/.test(F))throw RangeError(M1(W))}else{if(j)throw RangeError(M1(W));j=G}return""}),J.length>1&&Z)throw RangeError(M1($));return{timeZone:j,calendar:J[0]||v}}function K2($){return parseInt($.padEnd(9,"0"))}function JZ($){return new RegExp(`^${$}$`,"i")}function O2($){return $&&$!=="+"?-1:1}function u$($){return $===void 0?0:parseInt($)}function S7($){return H6(a($))}function H6($){let Z=B2($);return typeof Z=="number"?D$(Z):Z?((j)=>{if(hQ.test(j))throw RangeError(iF);return j.toLowerCase().split("/").map((J,W)=>(J.length<=3||/\d/.test(J))&&!/etc|yap/.test(J)?J.toUpperCase():J.replace(/baja|dumont|[a-z]+/g,(Y,z)=>Y.length<=2&&!W||Y==="in"||Y==="chat"?Y.toUpperCase():Y.length>2||!z?d5(Y).replace(/island|noronha|murdo|rivadavia|urville/,d5):Y)).join("/")})($):H$}function o5($){let Z=B2($);return typeof Z=="number"?Z:Z?Z.resolvedOptions().timeZone:H$}function B2($){let Z=Q2($=$.toUpperCase(),1);return Z!==void 0?Z:$!==H$?pQ($):void 0}function D2($,Z){return L0($.epochNanoseconds,Z.epochNanoseconds)}function U2($,Z){return L0($.epochNanoseconds,Z.epochNanoseconds)}function x7($,Z,j,J,W,Y){let z=$(i0(Y).relativeTo),X=Math.max(Q$(J),Q$(W));if(XW(y,J,W))return 0;if(hZ(X,z))return L0(Q0(J),Q0(W));if(!z)throw RangeError(R6);let[G,F,Q]=V6(Z,j,z),O=W2(Q),K=T6(Q);return L0(O(K(F,G,J)),O(K(F,G,W)))}function V2($,Z){return T$($,Z)||C6($,Z)}function T$($,Z){return k1(H0($),H0(Z))}function C6($,Z){return k1(m1($),m1(Z))}function A7($,Z){return!D2($,Z)}function f7($,Z){return!U2($,Z)&&!!_6($.timeZone,Z.timeZone)&&e$($.calendar,Z.calendar)}function E7($,Z){return!V2($,Z)&&e$($.calendar,Z.calendar)}function R7($,Z){return!T$($,Z)&&e$($.calendar,Z.calendar)}function b7($,Z){return!T$($,Z)&&e$($.calendar,Z.calendar)}function v7($,Z){return!T$($,Z)&&e$($.calendar,Z.calendar)}function w7($,Z){return!C6($,Z)}function _6($,Z){if($===Z)return 1;let j=D0($),J=D0(Z);if(j===J)return 1;try{return o5(j)===o5(J)}catch(W){}}function T2($,Z,j,J){let W=t$($,J0(J),3,5),Y=S6(Z.epochNanoseconds,j.epochNanoseconds,...W);return i($?_0(Y):Y)}function I2($,Z,j,J,W,Y){let z=A6(J.calendar,W.calendar),X=J0(Y),[G,F,Q,O]=t$(j,X,5),K=J.epochNanoseconds,D=W.epochNanoseconds,B=L0(D,K),U;if(B)if(G<6)U=S6(K,D,G,F,Q,O);else{let V=Z(((P,M)=>{if(!_6(P,M))throw RangeError(n9);return P})(J.timeZone,W.timeZone)),I=$(z);U=y7(I,V,J,W,B,G,X),U=K6(U,D,G,F,Q,O,I,J,mW,b(j2,V))}else U=U0;return i(j?_0(U):U)}function M2($,Z,j,J,W){let Y=A6(j.calendar,J.calendar),z=J0(W),[X,G,F,Q]=t$(Z,z,6),O=N0(j),K=N0(J),D=L0(K,O),B;if(D)if(X<=6)B=S6(O,K,X,G,F,Q);else{let U=$(Y);B=q7(U,j,J,D,X,z),B=K6(B,K,X,G,F,Q,U,j,N0,J2)}else B=U0;return i(Z?_0(B):B)}function P2($,Z,j,J,W){let Y=A6(j.calendar,J.calendar),z=J0(W);return k7(Z,()=>$(Y),j,J,...t$(Z,z,6,9,6),z)}function N2($,Z,j,J,W){let Y=A6(j.calendar,J.calendar),z=J0(W),X=t$(Z,z,9,9,8),G=$(Y);return k7(Z,()=>G,pZ(G,j),pZ(G,J),...X,z)}function k7($,Z,j,J,W,Y,z,X,G){let F=N0(j),Q=N0(J),O;if(L0(Q,F))if(W===6)O=S6(F,Q,W,Y,z,X);else{let K=Z();O=K.dateUntil(j,J,W,G),Y===6&&z===1||(O=K6(O,Q,W,Y,z,X,K,j,N0,U6))}else O=U0;return i($?_0(O):O)}function L2($,Z,j,J){let W=J0(J),[Y,z,X,G]=t$($,W,5,5),F=p1(H2(Z,j),oZ(z,X),G),Q={...U0,...P6(F,Y)};return i($?_0(Q):Q)}function CF($,Z,j,J,W,Y){let z=L0(J.epochNanoseconds,j.epochNanoseconds);return z?W<6?g7(j.epochNanoseconds,J.epochNanoseconds,W):y7(Z,$,j,J,z,W,Y):U0}function _F($,Z,j,J,W){let Y=N0(Z),z=N0(j),X=L0(z,Y);return X?J<=6?g7(Y,z,J):q7($,Z,j,X,J,W):U0}function y7($,Z,j,J,W,Y,z){let[X,G,F]=((K,D,B,U)=>{function V(){return _={...V$(M,f++*-U),...P},L=v0(K,_),L0(x,L)===-U}let I=C0(D,K),P=w0(o0,I),M=C0(B,K),x=B.epochNanoseconds,f=0,A=H2(I,M),_,L;if(Math.sign(A)===-U&&f++,V()&&(U===-1||V()))throw RangeError($3);let N=g0(q0(L,x));return[I,_,N]})(Z,j,J,W);var Q,O;return{...Y===6?(Q=X,O=G,{...U0,days:m7(Q,O)}):$.dateUntil(X,G,Y,z),...P6(F)}}function q7($,Z,j,J,W,Y){let[z,X,G]=((F,Q,O)=>{let K=Q,D=H2(F,Q);return Math.sign(D)===-O&&(K=V$(Q,-O),D+=m*O),[F,K,D]})(Z,j,J);return{...$.dateUntil(z,X,W,Y),...P6(G)}}function S6($,Z,j,J,W,Y){return{...U0,...ZZ(O6(q0($,Z),J,W,Y),j)}}function g7($,Z,j){return{...U0,...ZZ(q0($,Z),j)}}function m7($,Z){return x6(H0($),H0(Z))}function x6($,Z){return Math.trunc((Z-$)/R0)}function H2($,Z){return m1(Z)-m1($)}function A6($,Z){if(!e$($,Z))throw RangeError(g2);return $}function SF($){function Z(W){return((Y,z)=>({...p7(Y,z),F:Y.month,day:parseInt(Y.day)}))(Hj(j,W),J)}let j=e2($),J=o3($);return{id:$,O:xF(Z),B:AF(Z)}}function xF($){return b0((Z)=>{let j=H0(Z);return $(j)},WeakMap)}function AF($){let Z=$(0).year-DQ;return b0((j)=>{let J,W=r$(j-Z),Y=[],z=[];do W+=400*R0;while((J=$(W)).year<=j);do W+=(1-J.day)*R0,J.year===j&&(Y.push(W),z.push(J.F)),W-=R0;while((J=$(W)).year>=j);return{k:Y.reverse(),C:r9(z.reverse())}})}function p7($,Z){let j,J,W=h7($);if($.era){let Y=zY[Z];Y!==void 0&&(j=Z==="islamic"?"ah":$.era.normalize("NFD").toLowerCase().replace(/[^a-z0-9]/g,""),j==="bc"||j==="b"?j="bce":j!=="ad"&&j!=="a"||(j="ce"),J=W,W=i7(J,Y[j]||0))}return{era:j,eraYear:J,year:W}}function h7($){return parseInt($.relatedYear||$.year)}function Xj($){let{year:Z,F:j,day:J}=this.O($),{C:W}=this.B(Z);return[Z,W[j]+1,J]}function cZ($,Z=1,j=1){return this.B($).k[Z-1]+(j-1)*R0}function g3($){let Z=r5(this,$),j=r5(this,$-1),J=Z.length;if(J>j.length){let W=s7(this);if(W<0)return-W;for(let Y=0;Y<J;Y++)if(Z[Y]!==j[Y])return Y+1}}function m3($){return x6(cZ.call(this,$),cZ.call(this,$+1))}function a5($,Z){let{k:j}=this.B($),J=Z+1,W=j;return J>j.length&&(J=1,W=this.B($+1).k),x6(j[Z-1],W[J-1])}function p3($){return this.B($).k.length}function r5($,Z){return Object.keys($.B(Z).C)}function c7($){return aZ(a($))}function aZ($){if(($=$.toLowerCase())!==v&&$!==k6&&o3($)!==o3(e2($).resolvedOptions().calendar))throw RangeError(lF($));return $}function o3($){return $==="islamicc"&&($="islamic"),$.split("-")[0]}function d7($){return this.R($)[0]}function u7($){return this.R($)[1]}function C2($){let[Z]=this.h($);return x6(this.q(Z),H0($))+1}function l7($){let Z=dQ.exec($);if(!Z)throw RangeError(dF($));return[parseInt(Z[1]),Boolean(Z[2])]}function a3($,Z,j){return $+(Z||j&&$>=j?1:0)}function Gj($,Z){return $-(Z&&$>=Z?1:0)}function i7($,Z){return(Z+$)*(Math.sign(Z)||1)||0}function Fj($){return zY[n7($)]}function s7($){return YQ[n7($)]}function n7($){return o3($.id||v)}function o7($,Z,j,J){let W=u1(j,J,n0,[],jY);if(W.timeZone!==void 0){let Y=j.dateFromFields(W),z=I$(W),X=$(W.timeZone);return{epochNanoseconds:U$(Z(X),{...Y,...z},W.offset!==void 0?jZ(W.offset):void 0),timeZone:X}}return{...j.dateFromFields(W),...d0}}function a7($,Z,j,J,W,Y){let z=u1(j,W,n0,$Y,jY),X=$(z.timeZone),[G,F,Q]=nZ(Y),O=j.dateFromFields(z,F6(Y,G)),K=I$(z,G);return V0(U$(Z(X),{...O,...K},z.offset!==void 0?jZ(z.offset):void 0,F,Q),X,J)}function r7($,Z,j){let J=u1($,Z,n0,[],C1),W=k(j);return W0(N1({...$.dateFromFields(J,F6(j,W)),...I$(J,W)}))}function _2($,Z,j,J=[]){let W=u1($,Z,n0,J);return $.dateFromFields(W,j)}function S2($,Z,j,J){let W=u1($,Z,h2,J);return $.yearMonthFromFields(W,j)}function x2($,Z,j,J,W=[]){let Y=u1($,j,n0,W);return Z&&Y.month!==void 0&&Y.monthCode===void 0&&Y.year===void 0&&(Y.year=o$),$.monthDayFromFields(Y,J)}function t7($,Z){let j=k(Z);return s0(I$($1($,Kj,[],1),j))}function e7($){let Z=$1($,c2);return i($Z({...U0,...Z}))}function u1($,Z,j,J=[],W=[]){return $1(Z,[...$.fields(j),...W].sort(),J)}function $1($,Z,j,J=!j){let W={},Y,z=0;for(let X of Z){if(X===Y)throw RangeError(qF(X));if(X==="constructor"||X==="__proto__")throw RangeError(y2(X));let G=$[X];if(G!==void 0)z=1,ZW[X]&&(G=ZW[X](G,X)),W[X]=G;else if(j){if(j.includes(X))throw TypeError(k2(X));W[X]=YY[X]}Y=X}if(J&&!z)throw TypeError(c9(Z));return W}function I$($,Z){return X6(sQ({...YY,...$}),Z)}function $9($,Z,j,J,W,Y){let z=J0(Y),{calendar:X,timeZone:G}=j;return V0(((F,Q,O,K,D)=>{let B=rZ(F,O,K,n0,ZY,e9),[U,V,I]=nZ(D,2);return U$(Q,{...F.dateFromFields(B,F6(D,U)),...I$(B,U)},jZ(B.offset),V,I)})($(X),Z(G),J,W,z),G,X)}function Z9($,Z,j,J,W){let Y=J0(W);return W0(((z,X,G,F)=>{let Q=rZ(z,X,G,n0,C1),O=k(F);return N1({...z.dateFromFields(Q,F6(F,O)),...I$(Q,O)})})($(Z.calendar),j,J,Y))}function j9($,Z,j,J,W){let Y=J0(W);return((z,X,G,F)=>{let Q=rZ(z,X,G,n0);return z.dateFromFields(Q,F)})($(Z.calendar),j,J,Y)}function J9($,Z,j,J,W){let Y=J0(W);return F$(((z,X,G,F)=>{let Q=rZ(z,X,G,h2);return z.yearMonthFromFields(Q,F)})($(Z.calendar),j,J,Y))}function W9($,Z,j,J,W){let Y=J0(W);return((z,X,G,F)=>{let Q=rZ(z,X,G,n0);return z.monthDayFromFields(Q,F)})($(Z.calendar),j,J,Y)}function Y9($,Z,j){return s0(((J,W,Y)=>{let z=k(Y);return I$({...w0(Kj,J),...$1(W,Kj)},z)})($,Z,j))}function z9($,Z){return i((j=$,J=Z,$Z({...j,...$1(J,c2)})));var j,J}function rZ($,Z,j,J,W=[],Y=[]){let z=[...$.fields(J),...W].sort(),X=$1(Z,z,Y),G=$1(j,z);return X=$.mergeFields(X,G),$1(X,z,[])}function A2($,Z){let j=u1($,Z,WY);return $.monthDayFromFields(j)}function f2($,Z,j){let J=u1($,Z,JY);return $.yearMonthFromFields(J,j)}function X9($,Z,j,J,W){Z=w0(j=$.fields(j),Z),J=$1(J,W=$.fields(W),[]);let Y=$.mergeFields(Z,J);return Y=$1(Y,[...j,...W].sort(),[]),$.dateFromFields(Y)}function jj($,Z){let{era:j,eraYear:J,year:W}=Z,Y=Fj($);if(j!==void 0||J!==void 0){if(j===void 0||J===void 0)throw TypeError(mF);if(!Y)throw RangeError(gF);let z=Y[j];if(z===void 0)throw RangeError(hF(j));let X=i7(J,z);if(W!==void 0&&W!==X)throw RangeError(pF);W=X}else if(W===void 0)throw TypeError(cF(Y));return W}function Jj($,Z,j,J){let{month:W,monthCode:Y}=Z;if(Y!==void 0){let z=((X,G,F,Q)=>{let O=X.U(F),[K,D]=l7(G),B=a3(K,D,O);if(D){let U=s7(X);if(U===void 0)throw RangeError(qZ);if(U>0){if(B>U)throw RangeError(qZ);if(O===void 0){if(Q===1)throw RangeError(qZ);B--}}else{if(B!==-U)throw RangeError(qZ);if(O===void 0&&Q===1)throw RangeError(qZ)}}return B})($,Y,j,J);if(W!==void 0&&W!==z)throw RangeError(i9);W=z,J=1}else if(W===void 0)throw TypeError(uF);return p0("month",W,1,$.L(j),J)}function t5($,Z,j,J,W){return f0(Z,"day",1,$.j(J,j),W)}function Wj($,Z,j,J){let W=0,Y=[];for(let z of j)Z[z]!==void 0?W=1:Y.push(z);if(Object.assign($,Z),W)for(let z of J||Y)delete $[z]}function G9($){return O0(m0(J6(j6($))))}function F9($,Z,j,J,W=v){return V0(m0(J6(j6(j))),Z(J),$(W))}function Q9($,Z,j,J,W=0,Y=0,z=0,X=0,G=0,F=0,Q=v){return W0(N1(z6(u0(P0,a$(y6,[Z,j,J,W,Y,z,X,G,F])))),$(Q))}function K9($,Z,j,J,W=v){return Y0(y1(O$(u0(P0,{isoYear:Z,isoMonth:j,isoDay:J}))),$(W))}function O9($,Z,j,J=v,W=1){let Y=P0(Z),z=P0(j),X=$(J);return F$(Cj(O$({isoYear:Y,isoMonth:z,isoDay:P0(W)})),X)}function B9($,Z,j,J=v,W=o$){let Y=P0(Z),z=P0(j),X=$(J);return i3(y1(O$({isoYear:P0(W),isoMonth:Y,isoDay:z})),X)}function D9($=0,Z=0,j=0,J=0,W=0,Y=0){return s0(X6(u0(P0,a$(o0,[$,Z,j,J,W,Y])),1))}function U9($=0,Z=0,j=0,J=0,W=0,Y=0,z=0,X=0,G=0,F=0){return i($Z(u0(MW,a$(y,[$,Z,j,J,W,Y,z,X,G,F]))))}function E2($,Z,j=v){return V0($.epochNanoseconds,Z,j)}function V9($){return O0($.epochNanoseconds)}function R2($,Z){return W0(C0(Z,$))}function b2($,Z){return Y0(C0(Z,$))}function T9($,Z,j){return f2($(Z.calendar),j)}function I9($,Z,j){return A2($(Z.calendar),j)}function v2($,Z){return s0(C0(Z,$))}function M9($,Z,j,J){let W=((Y,z,X,G)=>{let F=Aj(G);return v0(Y(z),X,F)})($,j,Z,J);return V0(m0(W),j,Z.calendar)}function P9($,Z,j){let J=$(Z.calendar);return F$({...Z,...f2(J,j)})}function N9($,Z,j){return A2($(Z.calendar),j)}function L9($,Z,j,J,W){let Y=$(W.timeZone),z=W.plainTime,X=z!==void 0?Z(z):d0;return V0(v0(j(Y),{...J,...X}),Y,J.calendar)}function H9($,Z=d0){return W0(N1({...$,...Z}))}function C9($,Z,j){return f2($(Z.calendar),j)}function _9($,Z,j){return A2($(Z.calendar),j)}function S9($,Z,j,J){return((W,Y,z)=>X9(W,Y,JY,P1(z),j3))($(Z.calendar),j,J)}function x9($,Z,j,J){return((W,Y,z)=>X9(W,Y,WY,P1(z),w6))($(Z.calendar),j,J)}function A9($,Z,j,J,W){let Y=P1(W),z=Z(Y.plainDate),X=$(Y.timeZone);return V0(v0(j(X),{...z,...J}),X,z.calendar)}function f9($,Z){return W0(N1({...$,...Z}))}function E9($){return O0(m0(s$($,c0)))}function R9($){return O0(m0(s$($,j1)))}function b9($){return O0(m0(J6(j6($),P$)))}function v9($){return O0(m0(J6(j6($))))}function w9($,Z,j=d0){let J=Z.timeZone,W=$(J),Y={...C0(Z,W),...j};return V0(U$(W,Y,Y.offsetNanoseconds,2),J,Z.calendar)}function k9($,Z,j){let J=Z.timeZone,W=$(J),Y={...C0(Z,W),...j},z=m9(Z.calendar,j.calendar);return V0(U$(W,Y,Y.offsetNanoseconds,2),J,z)}function y9($,Z=d0){return W0({...$,...Z})}function q9($,Z){return W0({...$,...Z},m9($.calendar,Z.calendar))}function f6($,Z){return{...$,calendar:Z}}function g9($,Z){return{...$,timeZone:Z}}function m9($,Z){if($===Z)return $;let j=D0($),J=D0(Z);if(j===J||j===v)return Z;if(J===v)return $;throw RangeError(g2)}function fF($,Z){return(j)=>j===v?$:j===k6||j===n$?Object.assign(Object.create($),{id:j}):Object.assign(Object.create(Z),cQ(j))}function M$($,Z,j){let J=new Set(j);return(W)=>(((Y,z)=>{for(let X of z)if(X in Y)return 1;return 0})(W=Uj(J,W),$)||Object.assign(W,Z),j&&(W.timeZone=H$,["full","long"].includes(W.timeStyle)&&(W.timeStyle="medium")),W)}function L1($,Z=w2){let[j,,,J]=$;return(W,Y=FK,...z)=>{let X=Z(J&&J(...z),W,Y,j),G=X.resolvedOptions();return[X,...EF($,G,z)]}}function w2($,Z,j,J){if(j=J(j),$){if(j.timeZone!==void 0)throw TypeError(jQ);j.timeZone=$}return new l1(Z,j)}function EF($,Z,j){let[,J,W]=$;return j.map((Y)=>(Y.calendar&&((z,X,G)=>{if((G||z!==v)&&z!==X)throw RangeError(g2)})(D0(Y.calendar),Z.calendar,W),J(Y,Z)))}function WZ($){let Z=tZ();return h1(Z,$.getOffsetNanosecondsFor(Z))}function tZ(){return s$(Date.now(),j1)}function H1(){return JW||(JW=new l1().resolvedOptions().timeZone)}var RF=($,Z)=>`Non-integer ${$}: ${Z}`,bF=($,Z)=>`Non-positive ${$}: ${Z}`,vF=($,Z)=>`Non-finite ${$}: ${Z}`,wF=($)=>`Cannot convert bigint to ${$}`,kF=($)=>`Invalid bigint: ${$}`,yF="Cannot convert Symbol to string",p9="Invalid object",h9=($,Z,j,J,W)=>W?h9($,W[Z],W[j],W[J]):eZ($,Z)+`; must be between ${j}-${J}`,eZ=($,Z)=>`Invalid ${$}: ${Z}`,k2=($)=>`Missing ${$}`,y2=($)=>`Invalid field ${$}`,qF=($)=>`Duplicate field ${$}`,c9=($)=>"No valid fields: "+$.join(),d9="Invalid bag",u9=($,Z,j)=>eZ($,Z)+"; must be "+Object.keys(j).join(),l9="Cannot use valueOf",q2="Invalid calling context",gF="Forbidden era/eraYear",mF="Mismatching era/eraYear",pF="Mismatching year/eraYear",hF=($)=>`Invalid era: ${$}`,cF=($)=>"Missing year"+($?"/era/eraYear":""),dF=($)=>`Invalid monthCode: ${$}`,i9="Mismatching month/monthCode",uF="Missing month/monthCode",e5="Cannot guess year",qZ="Invalid leap month",s9="Invalid protocol",$3="Invalid protocol results",g2="Mismatching Calendars",lF=($)=>`Invalid Calendar: ${$}`,n9="Mismatching TimeZones",iF="Forbidden ICU TimeZone",sF="Out-of-bounds offset",nF="Out-of-bounds TimeZone gap",oF="Invalid TimeZone offset",aF="Ambiguous offset",E6="Out-of-bounds date",rF="Out-of-bounds duration",tF="Cannot mix duration signs",R6="Missing relativeTo",eF="Cannot use large units",$Q="Required smallestUnit or largestUnit",ZQ="smallestUnit > largestUnit",E0=($)=>`Cannot parse: ${$}`,M1=($)=>`Invalid substring: ${$}`,o9=($)=>`Cannot format ${$}`,a9="Mismatching types for formatting",jQ="Cannot specify TimeZone",r9=b(lZ,($,Z)=>Z),YZ=b(lZ,($,Z,j)=>j),h0=b(d3,2),Qj={nanosecond:0,microsecond:1,millisecond:2,second:3,minute:4,hour:5,day:6,week:7,month:8,year:9},Z3=Object.keys(Qj),R0=86400000,t9=1000,P$=1000,j1=1e6,c0=1e9,b6=60000000000,v6=3600000000000,m=86400000000000,Z1=[1,P$,j1,c0,b6,v6,m],C1=Z3.slice(0,6),Kj=iZ(C1),e9=["offset"],$Y=["timeZone"],ZY=C1.concat(e9),jY=ZY.concat($Y),Oj=["era","eraYear"],JQ=Oj.concat(["year"]),w6=["year"],m2=["monthCode"],p2=["month"].concat(m2),j3=["day"],h2=p2.concat(w6),JY=m2.concat(w6),n0=j3.concat(h2),WQ=j3.concat(p2),WY=j3.concat(m2),YY=YZ(C1,0),v="iso8601",k6="gregory",n$="japanese",zY={[k6]:{bce:-1,ce:0},[n$]:{bce:-1,ce:0,meiji:1867,taisho:1911,showa:1925,heisei:1988,reiwa:2018},ethioaa:{era0:0},ethiopic:{era0:0,era1:5500},coptic:{era0:-1,era1:0},roc:{beforeroc:-1,minguo:0},buddhist:{be:0},islamic:{ah:0},indian:{saka:0},persian:{ap:0}},YQ={chinese:13,dangi:13,hebrew:-6},a=b(Z6,"string"),XY=b(Z6,"boolean"),zQ=b(Z6,"number"),GY=b(Z6,"function"),y=Z3.map(($)=>$+"s"),c2=iZ(y),XQ=y.slice(0,6),FY=y.slice(6),GQ=FY.slice(1),FQ=r9(y),U0=YZ(y,0),d2=YZ(XQ,0),u2=b(GW,y),o0=["isoNanosecond","isoMicrosecond","isoMillisecond","isoSecond","isoMinute","isoHour"],l2=["isoDay","isoMonth","isoYear"],y6=o0.concat(l2),i2=iZ(l2),QY=iZ(o0),KY=iZ(y6),d0=YZ(QY,0),QQ=b(GW,y6),l1=Intl.DateTimeFormat,OY="en-GB",s2=1e8,KQ=s2*R0,OQ=[s2,0],BQ=[-s2,0],dZ=275760,uZ=-271821,DQ=1970,o$=1972,T1=12,UQ=r$(1868,9,8),VQ=b0(VF,WeakMap),r3="smallestUnit",Bj="unit",mZ="roundingIncrement",Yj="fractionalSecondDigits",BY="relativeTo",DY={constrain:0,reject:1},TQ=Object.keys(DY),IQ={compatible:0,reject:1,earlier:2,later:3},MQ={reject:0,use:1,prefer:2,ignore:3},PQ={auto:0,never:1,critical:2,always:3},NQ={auto:0,never:1,critical:2},LQ={auto:0,never:1},HQ={floor:0,halfFloor:1,ceil:2,halfCeil:3,trunc:4,halfTrunc:5,expand:6,halfExpand:7,halfEven:8},J3=b(wj,r3),n2=b(wj,"largestUnit"),CQ=b(wj,Bj),UY=b(B$,"overflow",DY),VY=b(B$,"disambiguation",IQ),_Q=b(B$,"offset",MQ),o2=b(B$,"calendarName",PQ),SQ=b(B$,"timeZoneName",NQ),xQ=b(B$,"offset",LQ),W3=b(B$,"roundingMode",HQ),zZ="PlainYearMonth",XZ="PlainMonthDay",N$="PlainDate",L$="PlainDateTime",q6="PlainTime",_1="ZonedDateTime",g6="Instant",m6="Duration",AQ=[Math.floor,($)=>q3($)?Math.floor($):Math.round($),Math.ceil,($)=>q3($)?Math.ceil($):Math.round($),Math.trunc,($)=>q3($)?Math.trunc($)||0:Math.round($),($)=>$<0?Math.floor($):Math.ceil($),($)=>Math.sign($)*Math.round(Math.abs($))||0,($)=>q3($)?($=Math.trunc($)||0)+$%2:Math.round($)],H$="UTC",h3=5184000,fQ=l3(1847),EQ=l3(new Date().getUTCFullYear()+10),RQ=/0+$/,C0=b0(LF,WeakMap),$W=4294967295,p6=b0(($)=>{let Z=B2($);return typeof Z=="object"?new IY(Z):new TY(Z||0)});class TY{constructor($){this.v=$}getOffsetNanosecondsFor(){return this.v}getPossibleInstantsFor($){return[_j($,this.v)]}l(){}}class IY{constructor($){this.$=((Z)=>{function j(G){let F=zj(G,z,X),[Q,O]=n5(F),K=W(Q),D=W(O);return K===D?K:J(Y(Q,O),K,D,G)}function J(G,F,Q,O){let K,D;for(;(O===void 0||(K=O<G[0]?F:O>=G[1]?Q:void 0)===void 0)&&(D=G[1]-G[0]);){let B=G[0]+Math.floor(D/2);Z(B)===Q?G[1]=B:G[0]=B+1}return K}let W=b0(Z),Y=b0(HF),z=fQ,X=EQ;return{G(G){let F=j(G-86400),Q=j(G+86400),O=G-F,K=G-Q;if(F===Q)return[O];let D=j(O);return D===j(K)?[G-D]:F>Q?[O,K]:[]},V:j,l(G,F){let Q=zj(G,z,X),[O,K]=n5(Q),D=h3*F,B=F<0?()=>K>z||(z=Q,0):()=>O<X||(X=Q,0);for(;B();){let U=W(O),V=W(K);if(U!==V){let I=Y(O,K);J(I,U,V);let P=I[0];if((k1(P,G)||1)===F)return P}O+=D,K+=D}}}})(((Z)=>(j)=>{let J=Hj(Z,j*t9);return l3(h7(J),parseInt(J.month),parseInt(J.day),parseInt(J.hour),parseInt(J.minute),parseInt(J.second))-j})($))}getOffsetNanosecondsFor($){return this.$.V(LW($))*c0}getPossibleInstantsFor($){let[Z,j]=[l3((J=$).isoYear,J.isoMonth,J.isoDay,J.isoHour,J.isoMinute,J.isoSecond),J.isoMillisecond*j1+J.isoMicrosecond*P$+J.isoNanosecond];var J;return this.$.G(Z).map((W)=>m0(i$(s$(W,c0),j)))}l($,Z){let[j,J]=HW($),W=this.$.l(j+(Z>0||J?1:0),Z);if(W!==void 0)return s$(W,c0)}}var a2="([+\u2212-])",c3="(?:[.,](\\d{1,9}))?",MY=`(?:(?:${a2}(\\d{6}))|(\\d{4}))-?(\\d{2})`,r2="(\\d{2})(?::?(\\d{2})(?::?(\\d{2})"+c3+")?)?",t2=a2+r2,bQ=MY+"-?(\\d{2})(?:[T ]"+r2+"(Z|"+t2+")?)?",PY="\\[(!?)([^\\]]*)\\]",h6=`((?:${PY}){0,9})`,vQ=JZ(MY+h6),wQ=JZ("(?:--)?(\\d{2})-?(\\d{2})"+h6),kQ=JZ(bQ+h6),yQ=JZ("T?"+r2+"(?:"+t2+")?"+h6),qQ=JZ(t2),gQ=new RegExp(PY,"g"),mQ=JZ(`${a2}?P(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(?:T(?:(\\d+)${c3}H)?(?:(\\d+)${c3}M)?(?:(\\d+)${c3}S)?)?`),pQ=b0(($)=>new l1(OY,{timeZone:$,era:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})),hQ=/^(AC|AE|AG|AR|AS|BE|BS|CA|CN|CS|CT|EA|EC|IE|IS|JS|MI|NE|NS|PL|PN|PR|PS|SS|VS)T$/,cQ=b0(SF),e2=b0(($)=>new l1(OY,{calendar:$,timeZone:H$,era:"short",year:"numeric",month:"short",day:"numeric"})),dQ=/^M(\d{2})(L?)$/,uQ={era:u3,eraYear:P0,year:P0,month:u5,monthCode:u3,day:u5},lQ=YZ(C1,P0),iQ=YZ(y,MW),ZW=Object.assign({},uQ,lQ,iQ,{offset:u3}),sQ=b(UF,C1,o0),jW={dateAdd($,Z,j){let J=k(j),W,{years:Y,months:z,weeks:X,days:G}=Z;if(G+=Q0(Z,5)[0],Y||z)W=((F,Q,O,K,D)=>{let[B,U,V]=F.h(Q);if(O){let[I,P]=F.I(B,U);B+=O,U=a3(I,P,F.U(B)),U=p0("month",U,1,F.L(B),D)}return K&&([B,U]=F._(B,U,K)),V=p0("day",V,1,F.j(B,U),D),F.q(B,U,V)})(this,$,Y,z,J);else{if(!X&&!G)return $;W=H0($)}return W+=(7*X+G)*R0,y1(Y6(W))},dateUntil($,Z,j){if(j<=7){let G=0,F=m7({...$,...d0},{...Z,...d0});return j===7&&([G,F]=g1(F,7)),{...U0,weeks:G,days:F}}let J=this.h($),W=this.h(Z),[Y,z,X]=((G,F,Q,O,K,D,B)=>{let U=K-F,V=D-Q,I=B-O;if(U||V){let P=Math.sign(U||V),M=G.j(K,D),x=0;if(Math.sign(I)===-P){let f=M;[K,D]=G._(K,D,-P),U=K-F,V=D-Q,M=G.j(K,D),x=P<0?-f:M}if(I=B-Math.min(O,M)+x,U){let[f,A]=G.I(F,Q),[_,L]=G.I(K,D);if(V=_-f||Number(L)-Number(A),Math.sign(V)===-P){let N=P<0&&-G.L(K);U=(K-=P)-F,V=D-a3(f,A,G.U(K))+(N||G.L(K))}}}return[U,V,I]})(this,...J,...W);return j===8&&(z+=this.J(Y,J[0]),Y=0),{...U0,years:Y,months:z,days:X}},dateFromFields($,Z){let j=k(Z),J=jj(this,$),W=Jj(this,$,J,j),Y=t5(this,$,W,J,j);return Y0(y1(this.P(J,W,Y)),this.id||v)},yearMonthFromFields($,Z){let j=k(Z),J=jj(this,$),W=Jj(this,$,J,j);return F$(Cj(this.P(J,W,1)),this.id||v)},monthDayFromFields($,Z){let j=k(Z),J=!this.id,{monthCode:W,year:Y,month:z}=$,X,G,F,Q,O;if(W!==void 0){[X,G]=l7(W),O=WW($,"day");let K=this.N(X,G,O);if(!K)throw RangeError(e5);if([F,Q]=K,z!==void 0&&z!==Q)throw RangeError(i9);J&&(Q=p0("month",Q,1,T1,1),O=p0("day",O,1,Sj(Y!==void 0?Y:F,Q),j))}else{F=Y===void 0&&J?o$:jj(this,$),Q=Jj(this,$,F,j),O=t5(this,$,Q,F,j);let K=this.U(F);G=Q===K,X=Gj(Q,K);let D=this.N(X,G,O);if(!D)throw RangeError(e5);[F,Q]=D}return i3(y1(this.P(F,Q,O)),this.id||v)},fields($){return Fj(this)&&$.includes("year")?[...$,...Oj]:$},mergeFields($,Z){let j=Object.assign(Object.create(null),$);return Wj(j,Z,p2),Fj(this)&&(Wj(j,Z,JQ),this.id===n$&&Wj(j,Z,WQ,Oj)),j},inLeapYear($){let[Z]=this.h($);return this.K(Z)},monthsInYear($){let[Z]=this.h($);return this.L(Z)},daysInMonth($){let[Z,j]=this.h($);return this.j(Z,j)},daysInYear($){let[Z]=this.h($);return this.X(Z)},dayOfYear:C2,era($){return this.ee($)[0]},eraYear($){return this.ee($)[1]},monthCode($){let[Z,j]=this.h($),[J,W]=this.I(Z,j);return((Y,z)=>"M"+h0(Y)+(z?"L":""))(J,W)},dayOfWeek:AW,daysInWeek(){return 7}},nQ={dayOfYear:C2,h:_W,q:r$},oQ=Object.assign({},nQ,{weekOfYear:d7,yearOfWeek:u7,R($){function Z(D){return(7-D<J?7:0)-D}function j(D){let B=xW(K+D),U=D||1,V=Z(gZ(G+B*U,7));return Q=(B+(V-F)*U)/7}let J=this.id?1:4,W=AW($),Y=this.dayOfYear($),z=gZ(W-1,7),X=Y-1,G=gZ(z-X,7),F=Z(G),Q,O=Math.floor((X-F)/7)+1,K=$.isoYear;return O?O>j(0)&&(O=1,K++):(O=j(-1),K--),[O,K,Q]}}),aQ={dayOfYear:C2,h:Xj,q:cZ,weekOfYear:d7,yearOfWeek:u7,R(){return[]}},GZ=fF(Object.assign({},jW,oQ,{h:_W,ee($){return this.id===k6?fW($):this.id===n$?VQ($):[]},I:($,Z)=>[Z,0],N($,Z){if(!Z)return[o$,$]},K:xj,U(){},L:SW,J:($)=>$*T1,j:Sj,X:xW,P:($,Z,j)=>({isoYear:$,isoMonth:Z,isoDay:j}),q:r$,_:($,Z,j)=>($+=e3(j,T1),(Z+=Tj(j,T1))<1?($--,Z+=T1):Z>T1&&($++,Z-=T1),[$,Z]),year($){return $.isoYear},month($){return $.isoMonth},day:($)=>$.isoDay}),Object.assign({},jW,aQ,{h:Xj,ee($){let Z=this.O($);return[Z.era,Z.eraYear]},I($,Z){let j=g3.call(this,$);return[Gj(Z,j),j===Z]},N($,Z,j){let[J,W,Y]=Xj.call(this,{isoYear:o$,isoMonth:T1,isoDay:31}),z=g3.call(this,J),X=W===z;(k1($,Gj(W,z))||k1(Number(Z),Number(X))||k1(j,Y))===1&&J--;for(let G=0;G<100;G++){let F=J-G,Q=g3.call(this,F),O=a3($,Z,Q);if(Z===(O===Q)&&j<=a5.call(this,F,O))return[F,O]}},K($){let Z=m3.call(this,$);return Z>m3.call(this,$-1)&&Z>m3.call(this,$+1)},U:g3,L:p3,J($,Z){let j=Z+$,J=Math.sign($),W=J<0?-1:0,Y=0;for(let z=Z;z!==j;z+=J)Y+=p3.call(this,z+W);return Y},j:a5,X:m3,P($,Z,j){return Y6(cZ.call(this,$,Z,j))},q:cZ,_($,Z,j){if(j){if(Z+=j,!Number.isSafeInteger(Z))throw RangeError(E6);if(j<0)for(;Z<1;)Z+=p3.call(this,--$);else{let J;for(;Z>(J=p3.call(this,$));)Z-=J,$++}}return[$,Z]},year($){return this.O($).year},month($){let{year:Z,F:j}=this.O($),{C:J}=this.B(Z);return J[j]+1},day($){return this.O($).day}})),q1="numeric",FZ=["timeZoneName"],NY={month:q1,day:q1},$4={year:q1,month:q1},Z4=Object.assign({},$4,{day:q1}),j4={hour:q1,minute:q1,second:q1},J4=Object.assign({},Z4,j4),rQ=Object.assign({},J4,{timeZoneName:"short"}),tQ=Object.keys($4),eQ=Object.keys(NY),$K=Object.keys(Z4),ZK=Object.keys(j4),W4=["dateStyle"],jK=tQ.concat(W4),JK=eQ.concat(W4),Y4=$K.concat(W4,["weekday"]),Y3=ZK.concat(["dayPeriod","timeStyle"]),z4=Y4.concat(Y3),WK=z4.concat(FZ),YK=FZ.concat(Y3),zK=FZ.concat(Y4),XK=FZ.concat(["day","weekday"],Y3),GK=FZ.concat(["year","weekday"],Y3),FK={},X4=[M$(z4,J4),Q6],LY=[M$(WK,rQ),Q6,0,($,Z)=>{let j=D0($.timeZone);if(Z&&D0(Z.timeZone)!==j)throw RangeError(n9);return j}],G4=[M$(z4,J4,FZ),H0],F4=[M$(Y4,Z4,YK),H0],Q4=[M$(Y3,j4,zK),($)=>m1($)/j1],K4=[M$(jK,$4,XK),H0,1],O4=[M$(JK,NY,GK),H0,1],JW;function Y1($,Z,j,J,W){function Y(...G){if(!(this instanceof Y))throw TypeError(q2);SY(this,Z(...G))}function z(G,F){return Object.defineProperties(function(...Q){return G.call(this,X(this),...Q)},Dj(F))}function X(G){let F=M0(G);if(!F||F.branding!==$)throw TypeError(q2);return F}return Object.defineProperties(Y.prototype,{...YW(u0(z,j)),...K$(u0(z,J)),...t3("Temporal."+$)}),Object.defineProperties(Y,{...K$(W),...Dj($)}),[Y,(G)=>{let F=Object.create(Y.prototype);return SY(F,G),F},X]}function fY($){return $=$.concat("id").sort(),(Z)=>{if(!zW(Z,$))throw TypeError(s9);return Z}}function BZ($){if(M0($)||$.calendar!==void 0||$.timeZone!==void 0)throw TypeError(d9);return $}function c6($,Z){let j={};for(let J in $)j[J]=({o:W},Y)=>{let z=M0(Y)||{},{branding:X}=z,G=X===N$||Z.includes(X)?z:x0(Y);return W[J](G)};return j}function U4($){let Z={};for(let j in $)Z[j]=(J)=>{let{calendar:W}=J;return(Y=W,typeof Y=="string"?GZ(Y):(z=Y,Object.assign(Object.create(_K),{i:z})))[j](J);var Y,z};return Z}function a1(){throw TypeError(l9)}function X3({calendar:$}){return typeof $=="string"?new C4($):$}function HY($,Z){if(Z=J0(Z),K0($)){let J=M0($);if(J&&J.branding===XZ)return k(Z),J;let W=bY($);return x2(o6(W||v),!W,$,Z)}let j=U7(GZ,$);return k(Z),j}function EY($,Z,j){return J=Z.call($,S0(O0(j))),nj(sZ(J));var J}function d6($,Z=yY){let j=Object.keys(Z).sort(),J={};for(let W of j)J[W]=b(Z[W],$,GY($[W]));return J}function p($,Z){return typeof $=="string"?p6($):d6($,Z)}function X0($){return p($,D4)}function J1($){if(K0($)){let Z=M0($);if(Z)switch(Z.branding){case g6:return Z;case _1:return O0(Z.epochNanoseconds)}}return Q7($)}function CY($,Z,j){let J=Z.l(J1(j).epochNanoseconds,$);return J?S0(O0(J)):null}function u($){return K0($)?(M0($)||{}).timeZone||RK($):((Z)=>H6(M7(a(Z))))($)}function i1($,Z){if(K0($)){let j=M0($)||{};switch(j.branding){case q6:return k(Z),j;case L$:return k(Z),s0(j);case _1:return k(Z),v2(X0,j)}return t7($,Z)}return k(Z),V7($)}function V4($){return $===void 0?void 0:i1($)}function QZ($,Z){if(Z=J0(Z),K0($)){let J=M0($);return J&&J.branding===zZ?(k(Z),J):S2(s6(G3($)),$,Z)}let j=D7(GZ,$);return k(Z),j}function s1($,Z){if(Z=J0(Z),K0($)){let J=M0($)||{};switch(J.branding){case L$:return k(Z),J;case N$:return k(Z),W0({...J,...d0});case _1:return k(Z),R2(X0,J)}return r7(n6(G3($)),$,Z)}let j=B7($);return k(Z),j}function x0($,Z){if(Z=J0(Z),K0($)){let J=M0($)||{};switch(J.branding){case N$:return k(Z),J;case L$:return k(Z),Y0(J);case _1:return k(Z),b2(X0,J)}return _2(n6(G3($)),$,Z)}let j=N6($);return k(Z),j}function RY($,Z,j){return l0(Z.call($,t(Y0(j,$))))}function z1($){return(Z)=>typeof Z=="string"?GZ(Z):((j,J)=>{let W=Object.keys(J).sort(),Y={};for(let z of W)Y[z]=b(J[z],j,j[z]);return Y})(Z,$)}function r($){if(K0($)){let Z=M0($);return Z&&Z.branding===m6?Z:e7($)}return T7($)}function z3($){if($!==void 0){if(K0($)){let Z=M0($)||{};switch(Z.branding){case _1:case N$:return Z;case L$:return Y0(Z)}let j=G3($);return{...o7(u,p,n6(j),$),calendar:j}}return K7($)}}function G3($){return bY($)||v}function bY($){let{calendar:Z}=$;if(Z!==void 0)return I0(Z)}function I0($){return K0($)?(M0($)||{}).calendar||iK($):((Z)=>aZ(I7(a(Z))))($)}function KZ($,Z){if(Z=J0(Z),K0($)){let j=M0($);if(j&&j.branding===_1)return nZ(Z),j;let J=G3($);return a7(u,p,n6(J),J,$,Z)}return O7($,Z)}function _Y($){return u0((Z)=>(j)=>Z(B4(j)),$)}function B4($){return C0($,X0)}function QK(){let $=l1.prototype,Z=Object.getOwnPropertyDescriptors($),j=Object.getOwnPropertyDescriptors(l1),J=function(W,Y={}){if(!(this instanceof J))return new J(W,Y);_4.set(this,((z,X={})=>{let G=new l1(z,X),F=G.resolvedOptions(),Q=F.locale,O=w0(Object.keys(X),F),K=b0(BK),D=(...B)=>{let U,V=B.map((I,P)=>{let M=M0(I),x=(M||{}).branding;if(P&&U&&U!==x)throw TypeError(a9);return U=x,M});return U?K(U)(Q,O,...V):[G,...B]};return D.u=G,D})(W,Y))};for(let W in Z){let Y=Z[W],z=W.startsWith("format")&&KK(W);typeof Y.value=="function"?Y.value=W==="constructor"?J:z||OK(W):z&&(Y.get=function(){return z.bind(this)})}return j.prototype.value=Object.create($,Z),Object.defineProperties(J,j),J}function KK($){return function(...Z){let j=_4.get(this),[J,...W]=j(...Z);return J[$](...W)}}function OK($){return function(...Z){return _4.get(this).u[$](...Z)}}function BK($){let Z=DK[$];if(!Z)throw TypeError(o9($));return L1(Z,b0(w2))}var DK={Instant:X4,PlainDateTime:G4,PlainDate:F4,PlainTime:Q4,PlainYearMonth:K4,PlainMonthDay:O4},UK=L1(X4),VK=L1(LY),TK=L1(G4),IK=L1(F4),MK=L1(Q4),PK=L1(K4),NK=L1(O4),T4={era:BW,eraYear:Ij,year:sZ,month:l0,daysInMonth:l0,daysInYear:l0,inLeapYear:XY,monthsInYear:l0},l6={monthCode:a},I4={day:l0},vY={dayOfWeek:l0,dayOfYear:l0,weekOfYear:DW,yearOfWeek:Ij,daysInWeek:l0},wY=Object.assign({},T4,l6,I4,vY),u6=new WeakMap,M0=u6.get.bind(u6),SY=u6.set.bind(u6),LK={...c6(T4,[zZ]),...c6(vY,[]),...c6(l6,[zZ,XZ]),...c6(I4,[XZ])},M4=U4(wY),HK=U4({...T4,...l6}),CK=U4({...l6,...I4}),F3={calendarId:($)=>D0($.calendar)},_K=u0(($,Z)=>function(j){let{i:J}=this;return $(J[Z](t(Y0(j,J))))},wY),SK=lZ(($)=>(Z)=>Z[$],y.concat("sign")),P4=lZ(($,Z)=>(j)=>j[o0[Z]],C1),kY={epochSeconds:yW,epochMilliseconds:Q6,epochMicroseconds:qW,epochNanoseconds:gW},Q3=b(Uj,new Set(["branding"])),[xK,OZ,AK]=Y1(XZ,b(B9,I0),{...F3,...CK},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return OZ(W9(dK,$,this,BZ(Z),j))},equals:($,Z)=>v7($,HY(Z)),toPlainDate($,Z){return t(x9(K3,$,this,Z))},toLocaleString($,Z,j){let[J,W]=NK(Z,j,$);return J.format(W)},toString:dj,toJSON:($)=>dj($),valueOf:a1},{from:($,Z)=>OZ(HY($,Z))}),yY={getOffsetNanosecondsFor:EY,getPossibleInstantsFor($,Z,j){let J=[...Z.call($,T0(W0(j,v)))].map((Y)=>EK(Y).epochNanoseconds),W=J.length;return W>1&&(J.sort(L0),oj(g0(q0(J[0],J[W-1])))),J}},D4={getOffsetNanosecondsFor:EY},[fK,S0,EK]=Y1(g6,G9,kY,{add:($,Z)=>S0(aj(0,$,r(Z))),subtract:($,Z)=>S0(aj(1,$,r(Z))),until:($,Z,j)=>h(T2(0,$,J1(Z),j)),since:($,Z,j)=>h(T2(1,$,J1(Z),j)),round:($,Z)=>S0(hW($,Z)),equals:($,Z)=>A7($,J1(Z)),toZonedDateTime($,Z){let j=P1(Z);return z0(E2($,u(j.timeZone),I0(j.calendar)))},toZonedDateTimeISO:($,Z)=>z0(E2($,u(Z))),toLocaleString($,Z,j){let[J,W]=UK(Z,j,$);return J.format(W)},toString:($,Z)=>gj(u,X0,$,Z),toJSON:($)=>gj(u,X0,$),valueOf:a1},{from:($)=>S0(J1($)),fromEpochSeconds:($)=>S0(E9($)),fromEpochMilliseconds:($)=>S0(R9($)),fromEpochMicroseconds:($)=>S0(b9($)),fromEpochNanoseconds:($)=>S0(v9($)),compare:($,Z)=>D2(J1($),J1(Z))}),[i6,IV]=Y1("TimeZone",($)=>{let Z=S7($);return{branding:"TimeZone",id:Z,o:p6(Z)}},{id:($)=>$.id},{getPossibleInstantsFor:({o:$},Z)=>$.getPossibleInstantsFor(s1(Z)).map((j)=>S0(O0(j))),getOffsetNanosecondsFor:({o:$},Z)=>$.getOffsetNanosecondsFor(J1(Z).epochNanoseconds),getOffsetStringFor($,Z){let j=J1(Z).epochNanoseconds,J=d6(this,D4).getOffsetNanosecondsFor(j);return D$(J)},getPlainDateTimeFor($,Z,j=v){let J=J1(Z).epochNanoseconds,W=d6(this,D4).getOffsetNanosecondsFor(J);return T0(W0(h1(J,W),I0(j)))},getInstantFor($,Z,j){let J=s1(Z),W=Aj(j),Y=d6(this);return S0(O0(v0(Y,J,W)))},getNextTransition:({o:$},Z)=>CY(1,$,Z),getPreviousTransition:({o:$},Z)=>CY(-1,$,Z),equals($,Z){return!!_6(this,u(Z))},toString:($)=>$.id,toJSON:($)=>$.id},{from($){let Z=u($);return typeof Z=="string"?new i6(Z):Z}}),RK=fY(Object.keys(yY)),[bK,n1]=Y1(q6,D9,P4,{getISOFields:Q3,with($,Z,j){return n1(Y9(this,BZ(Z),j))},add:($,Z)=>n1(Z2(0,$,r(Z))),subtract:($,Z)=>n1(Z2(1,$,r(Z))),until:($,Z,j)=>h(L2(0,$,i1(Z),j)),since:($,Z,j)=>h(L2(1,$,i1(Z),j)),round:($,Z)=>n1(uW($,Z)),equals:($,Z)=>w7($,i1(Z)),toZonedDateTime:($,Z)=>z0(A9(u,x0,p,$,Z)),toPlainDateTime:($,Z)=>T0(f9($,x0(Z))),toLocaleString($,Z,j){let[J,W]=MK(Z,j,$);return J.format(W)},toString:uj,toJSON:($)=>uj($),valueOf:a1},{from:($,Z)=>n1(i1($,Z)),compare:($,Z)=>C6(i1($),i1(Z))}),[vK,o1,wK]=Y1(zZ,b(O9,I0),{...F3,...HK},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return o1(J9(cK,$,this,BZ(Z),j))},add:($,Z,j)=>o1($2(xY,0,$,r(Z),j)),subtract:($,Z,j)=>o1($2(xY,1,$,r(Z),j)),until:($,Z,j)=>h(N2(AY,0,$,QZ(Z),j)),since:($,Z,j)=>h(N2(AY,1,$,QZ(Z),j)),equals:($,Z)=>b7($,QZ(Z)),toPlainDate($,Z){return t(S9(K3,$,this,Z))},toLocaleString($,Z,j){let[J,W]=PK(Z,j,$);return J.format(W)},toString:cj,toJSON:($)=>cj($),valueOf:a1},{from:($,Z)=>o1(QZ($,Z)),compare:($,Z)=>T$(QZ($),QZ(Z))}),[kK,T0]=Y1(L$,b(Q9,I0),{...F3,...M4,...P4},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return T0(Z9(K3,$,this,BZ(Z),j))},withCalendar:($,Z)=>T0(f6($,I0(Z))),withPlainDate:($,Z)=>T0(q9($,x0(Z))),withPlainTime:($,Z)=>T0(y9($,V4(Z))),add:($,Z,j)=>T0(tj(C$,0,$,r(Z),j)),subtract:($,Z,j)=>T0(tj(C$,1,$,r(Z),j)),until:($,Z,j)=>h(M2(W1,0,$,s1(Z),j)),since:($,Z,j)=>h(M2(W1,1,$,s1(Z),j)),round:($,Z)=>T0(dW($,Z)),equals:($,Z)=>E7($,s1(Z)),toZonedDateTime:($,Z,j)=>z0(M9(p,$,u(Z),j)),toPlainDate:($)=>t(Y0($)),toPlainTime:($)=>n1(s0($)),toPlainYearMonth($){return o1(P9(s6,$,this))},toPlainMonthDay($){return OZ(N9(o6,$,this))},toLocaleString($,Z,j){let[J,W]=TK(Z,j,$);return J.format(W)},toString:pj,toJSON:($)=>pj($),valueOf:a1},{from:($,Z)=>T0(s1($,Z)),compare:($,Z)=>V2(s1($),s1(Z))}),[yK,t,qY]=Y1(N$,b(K9,I0),{...F3,...M4},{getISOFields:Q3,getCalendar:X3,with($,Z,j){return t(j9(K3,$,this,BZ(Z),j))},withCalendar:($,Z)=>t(f6($,I0(Z))),add:($,Z,j)=>t(ej(C$,0,$,r(Z),j)),subtract:($,Z,j)=>t(ej(C$,1,$,r(Z),j)),until:($,Z,j)=>h(P2(W1,0,$,x0(Z),j)),since:($,Z,j)=>h(P2(W1,1,$,x0(Z),j)),equals:($,Z)=>R7($,x0(Z)),toZonedDateTime($,Z){let j=!K0(Z)||Z instanceof i6?{timeZone:Z}:Z;return z0(L9(u,i1,p,$,j))},toPlainDateTime:($,Z)=>T0(H9($,V4(Z))),toPlainYearMonth($){return o1(C9(s6,$,this))},toPlainMonthDay($){return OZ(_9(o6,$,this))},toLocaleString($,Z,j){let[J,W]=IK(Z,j,$);return J.format(W)},toString:hj,toJSON:($)=>hj($),valueOf:a1},{from:($,Z)=>t(x0($,Z)),compare:($,Z)=>T$(x0($),x0(Z))}),N4={fields($,Z,j){return[...Z.call($,j)]}},gY=Object.assign({dateFromFields($,Z,j,J){return qY(Z.call($,Object.assign(Object.create(null),j),J))}},N4),mY=Object.assign({yearMonthFromFields($,Z,j,J){return wK(Z.call($,Object.assign(Object.create(null),j),J))}},N4),pY=Object.assign({monthDayFromFields($,Z,j,J){return AK(Z.call($,Object.assign(Object.create(null),j),J))}},N4),L4={mergeFields($,Z,j,J){return P1(Z.call($,Object.assign(Object.create(null),j),Object.assign(Object.create(null),J)))}},qK=Object.assign({},gY,L4),gK=Object.assign({},mY,L4),mK=Object.assign({},pY,L4),H4={dateAdd($,Z,j,J,W){return qY(Z.call($,t(Y0(j,$)),h(i(J)),W))}},hY=Object.assign({},H4,{dateUntil($,Z,j,J,W,Y){return lK(Z.call($,t(Y0(j,$)),t(Y0(J,$)),Object.assign(Object.create(null),Y,{largestUnit:Z3[W]})))}}),pK=Object.assign({},H4,{day:RY}),hK=Object.assign({},hY,{day:RY}),s6=z1(mY),n6=z1(gY),o6=z1(pY),cK=z1(gK),K3=z1(qK),dK=z1(mK),C$=z1(H4),W1=z1(hY),xY=z1(pK),AY=z1(hK),[uK,h,lK]=Y1(m6,U9,{...SK,blank:X7},{with:($,Z)=>h(z9($,Z)),negated:($)=>h(M6($)),abs:($)=>h(z7($)),add:($,Z,j)=>h(z2(z3,W1,p,0,$,r(Z),j)),subtract:($,Z,j)=>h(z2(z3,W1,p,1,$,r(Z),j)),round:($,Z)=>h(Y7(z3,W1,p,$,Z)),total:($,Z)=>pW(z3,W1,p,$,Z),toLocaleString($,Z,j){return Intl.DurationFormat?new Intl.DurationFormat(Z,j).format(this):D6($)},toString:D6,toJSON:($)=>D6($),valueOf:a1},{from:($)=>h(r($)),compare:($,Z,j)=>x7(z3,C$,p,r($),r(Z),j)}),cY={toString:($)=>$.id,toJSON:($)=>$.id,...LK,dateAdd:({id:$,o:Z},j,J,W)=>t(Y0(Z.dateAdd(x0(j),r(J),W),$)),dateUntil:({o:$},Z,j,J)=>h(i($.dateUntil(x0(Z),x0(j),RW(J)))),dateFromFields:({id:$,o:Z},j,J)=>t(_2(Z,j,J,OW($))),yearMonthFromFields:({id:$,o:Z},j,J)=>o1(S2(Z,j,J,QW($))),monthDayFromFields:({id:$,o:Z},j,J)=>OZ(x2(Z,0,j,J,KW($))),fields({o:$},Z){let j=new Set(n0),J=[];for(let W of Z){if(a(W),!j.has(W))throw RangeError(y2(W));j.delete(W),J.push(W)}return $.fields(J)},mergeFields:({o:$},Z,j)=>$.mergeFields(Vj(Mj(Z)),Vj(Mj(j)))},[C4]=Y1("Calendar",($)=>{let Z=c7($);return{branding:"Calendar",id:Z,o:GZ(Z)}},{id:($)=>$.id},cY,{from($){let Z=I0($);return typeof Z=="string"?new C4(Z):Z}}),iK=fY(Object.keys(cY).slice(4)),[sK,z0]=Y1(_1,b(F9,I0,u),{...kY,...F3,..._Y(M4),..._Y(P4),offset:($)=>D$(B4($).offsetNanoseconds),offsetNanoseconds:($)=>B4($).offsetNanoseconds,timeZoneId:($)=>D0($.timeZone),hoursInDay:($)=>lW(p,$)},{getISOFields:($)=>J7(X0,$),getCalendar:X3,getTimeZone:({timeZone:$})=>typeof $=="string"?new i6($):$,with($,Z,j){return z0($9(K3,p,$,this,BZ(Z),j))},withCalendar:($,Z)=>z0(f6($,I0(Z))),withTimeZone:($,Z)=>z0(g9($,u(Z))),withPlainDate:($,Z)=>z0(k9(p,$,x0(Z))),withPlainTime:($,Z)=>z0(w9(p,$,V4(Z))),add:($,Z,j)=>z0(rj(C$,p,0,$,r(Z),j)),subtract:($,Z,j)=>z0(rj(C$,p,1,$,r(Z),j)),until:($,Z,j)=>h(i(I2(W1,p,0,$,KZ(Z),j))),since:($,Z,j)=>h(i(I2(W1,p,1,$,KZ(Z),j))),round:($,Z)=>z0(cW(p,$,Z)),startOfDay:($)=>z0(iW(p,$)),equals:($,Z)=>f7($,KZ(Z)),toInstant:($)=>S0(V9($)),toPlainDateTime:($)=>T0(R2(X0,$)),toPlainDate:($)=>t(b2(X0,$)),toPlainTime:($)=>n1(v2(X0,$)),toPlainYearMonth($){return o1(T9(s6,$,this))},toPlainMonthDay($){return OZ(I9(o6,$,this))},toLocaleString($,Z,j={}){let[J,W]=VK(Z,j,$);return J.format(W)},toString:($,Z)=>mj(X0,$,Z),toJSON:($)=>mj(X0,$),valueOf:a1},{from:($,Z)=>z0(KZ($,Z)),compare:($,Z)=>U2(KZ($),KZ(Z))}),nK=Object.defineProperties({},{...t3("Temporal.Now"),...K$({timeZoneId:()=>H1(),instant:()=>S0(O0(tZ())),zonedDateTime:($,Z=H1())=>z0(V0(tZ(),u(Z),I0($))),zonedDateTimeISO:($=H1())=>z0(V0(tZ(),u($),v)),plainDateTime:($,Z=H1())=>T0(W0(WZ(X0(u(Z))),I0($))),plainDateTimeISO:($=H1())=>T0(W0(WZ(X0(u($))),v)),plainDate:($,Z=H1())=>t(Y0(WZ(X0(u(Z))),I0($))),plainDateISO:($=H1())=>t(Y0(WZ(X0(u($))),v)),plainTimeISO:($=H1())=>n1(s0(WZ(X0(u($)))))})}),DZ=Object.defineProperties({},{...t3("Temporal"),...K$({PlainYearMonth:vK,PlainMonthDay:xK,PlainDate:yK,PlainTime:bK,PlainDateTime:kK,ZonedDateTime:sK,Instant:fK,Calendar:C4,TimeZone:i6,Duration:uK,Now:nK})}),oK=QK(),_4=new WeakMap,aK=Object.defineProperties(Object.create(Intl),K$({DateTimeFormat:oK}));class S4 extends Error{code;constructor($,Z=`OAuth callback failed: ${$}`){super(Z);this.name="OAuthCallbackError",this.code=$}}class rK{linkByEmail=!0;createUsers=!0}import{createHash as x4,createHmac as tK,randomBytes as dY,timingSafeEqual as iY}from"crypto";var B3=600,a6="gemi_oauth",eK=`__Host-${a6}`;function UZ($,Z=a6){if(Z===a6)return $?eK:a6;return $?`__Host-${Z}`:Z}function O3($){return $.toString("base64url")}function sY($){return tK("sha256",c$()).update(`gemi-oauth-state:${$}`).digest()}function uY($,Z){let j=x4("sha256").update($).digest(),J=x4("sha256").update(Z).digest();return iY(j,J)&&$.length===Z.length}function r6($,Z=Date.now(),j={}){let J=O3(dY(32)),W=O3(dY(32)),Y=$O(W),z={provider:$,state:J,codeVerifier:W,expiresAt:Z+B3*1000,...j.subject!==void 0?{subject:j.subject}:{},...j.returnTo!==void 0?{returnTo:j.returnTo}:{}};return{state:J,codeVerifier:W,codeChallenge:Y,cookieValue:ZO(z)}}function $O($){return O3(x4("sha256").update($).digest())}function ZO($){let Z=O3(Buffer.from(JSON.stringify($)));return`${Z}.${O3(sY(Z))}`}function jO($){if(typeof $!=="string"||$==="")return null;let Z=$.indexOf(".");if(Z<=0||Z!==$.lastIndexOf("."))return null;let j=$.slice(0,Z),J=Buffer.from($.slice(Z+1),"base64url"),W=sY(j);if(J.length!==W.length||!iY(J,W))return null;try{let Y=JSON.parse(Buffer.from(j,"base64url").toString("utf8"));if(typeof Y?.provider!=="string"||typeof Y?.state!=="string"||typeof Y?.codeVerifier!=="string"||typeof Y?.expiresAt!=="number"||Y.subject!==void 0&&typeof Y.subject!=="string"||Y.returnTo!==void 0&&typeof Y.returnTo!=="string")return null;return Y}catch{return null}}var r1=new Map,lY=1e4;function JO($,Z,j){if(r1.size>=lY){for(let[J,W]of r1)if(W<=j)r1.delete(J);while(r1.size>=lY){let J=r1.keys().next().value;if(J===void 0)break;r1.delete(J)}}r1.set($,Z)}function t6($){let Z=$.now??Date.now();if(!$.cookieValue||!$.returnedState)return{ok:!1,reason:"missing_state"};let j=jO($.cookieValue);if(!j)return{ok:!1,reason:"invalid_state"};let J=uY(j.state,$.returnedState),W=uY(j.provider,$.provider);if(!J||!W)return{ok:!1,reason:"invalid_state"};if(j.expiresAt<=Z)return{ok:!1,reason:"expired_state"};if(r1.has(j.state))return{ok:!1,reason:"invalid_state"};return JO(j.state,j.expiresAt,Z),{ok:!0,payload:j}}var A4=new WeakMap;function YO($){let Z=A4.get($);if(!Z)Z=$(WO(32).toString("hex")),A4.set($,Z),Z.catch(()=>A4.delete($));return Z}async function f4($,Z,j){if(typeof j==="string"&&j!=="")return await $.verifyPassword(Z,j);try{await $.verifyPassword(Z,await YO($.hashPassword))}catch{}return!1}async function _$($,Z){let j=Z.user??Z.session?.user;if(!j||!$.onAuthenticated)return;let{password:J,...W}=j;await $.onAuthenticated({...Z,user:W})}class R4 extends Error{}function E4($){return typeof $==="string"&&$!==""?$:null}function nY($){return yZ($)}var zO=256;function oY($){return typeof $==="string"&&$!==""&&$.length<=zO?$:null}var e6="intended_url";function rY($){if($.cookies.get(e6))$.ctx().setCookie(e6,"",{maxAge:-1})}function aY($){let Z=$.cookies.get(e6);if(!Z)return null;rY($);try{return U1(decodeURIComponent(Z),"")||null}catch{return null}}class b4 extends S{schema={email:{required:"Email is required",string:"Invalid email",email:"Invalid email"},password:{required:"Password is required"}}}class tY extends S{schema={email:{required:"Email is required",email:"Invalid email"}}}class eY extends S{schema={password:{required:"Password is required",password:"Invalid password"}}}class s extends wZ{async me(){let $=await X1.user();if(!$)throw new l8;return $}async verifyEmail($=new S){let Z=await $.input(),{userProvider:j}=T(E),J=E4(Z.get("token"));if(!J)return{email:null};let W=await j.findUserByVerificationToken(J);if(!W)return{email:null};return await j.verifyUser(W.email),{email:W.email}}async signInWithMagicLink($=new S){let Z=T(E),{userProvider:j}=Z,J=E4($.search.get("token")),W=null;try{W=yZ(decodeURIComponent($.search.get("email")??""))}catch{}if(await d$("link",null,$,{perIp:Z.config.emailCode.verifyLimit.perIp}),!W||!J||!await Z.verifyMagicLinkToken(W,J))return{error:"Invalid token"};await j.verifyUser(W);let Y=await Z.createOrUpdateSession({email:W});return $.ctx().setCookie("access_token",Y.token,T(E).accessTokenCookieOptions($,Y.expiresAt)),await Z.config.onSignIn(Y,$.search.toJSON()),await _$(Z.config,{session:Y,isNewUser:!1,method:"magic-link",req:$}),{session:Y}}async verifyPinRequest($){let Z=T(E),j=await $.input(),{email:J,pin:W}=j.toJSON(),Y=yZ(J),z=oY(W);if(await d$("verify",Y,$,Z.config.emailCode.verifyLimit),!Y||!z)throw new g({pin:["Invalid pin"]});let X=await Z.verifyOneTimeCode(Y,z);if(X.status==="too_many_attempts")throw new g({pin:["Too many attempts"]});if(X.status!=="ok")throw new g({pin:["Invalid pin"]});return await Z.userProvider.verifyUser(Y),Y}async signInWithPinV2($=new S){let Z=T(E),j=await this.verifyPinRequest($),J=await Z.createOrUpdateSessionV2({email:j});return $.ctx().setCookie("access_token",J.token,T(E).accessTokenCookieOptions($,J.expiresAt)),await Z.config.onSignIn(J,$.search.toJSON()),await _$(Z.config,{session:J,isNewUser:!1,method:"magic-link",req:$}),J}async signInWithPin($=new S){let Z=T(E),j=await this.verifyPinRequest($),J=await Z.createOrUpdateSession({email:j});return $.ctx().setCookie("access_token",J.token,T(E).accessTokenCookieOptions($,J.expiresAt)),await Z.config.onSignIn(J,$.search.toJSON()),await _$(Z.config,{session:J,isNewUser:!1,method:"magic-link",req:$}),{session:J}}async signInV2($=new b4){let Z=await $.input(),{email:j,password:J}=Z.toJSON(),W=j.toLowerCase().trim(),Y=T(E),z=await Y.userProvider.findUserByEmailAddress(W,Y.config.verifyEmail),X=typeof J==="string"&&await f4(Y.config,J,z?.password);if(!z||!X)throw new g({invalid_credentials:["Invalid credentials"]});let G=await Y.createOrUpdateSessionV2({email:z.email,id:z.id});$.ctx().setCookie("access_token",G.token,T(E).accessTokenCookieOptions($,G.expiresAt)),await Y.config.onSignIn(z,$.search.toJSON()),await _$(Y.config,{session:G,user:z,isNewUser:!1,method:"password",req:$});let{password:F,...Q}=z;return Q}async signIn($=new b4){let Z=await $.input(),{email:j,password:J}=Z.toJSON(),W=j.toLowerCase().trim(),Y=T(E),z=await Y.userProvider.findUserByEmailAddress(W,Y.config.verifyEmail),X=typeof J==="string"&&await f4(Y.config,J,z?.password);if(!z||!X)throw new g({invalid_credentials:["Invalid credentials"]});let G=await Y.createOrUpdateSession({email:z.email,id:z.id});$.ctx().setCookie("access_token",G.token,T(E).accessTokenCookieOptions($,G.expiresAt)),await Y.config.onSignIn(z,$.search.toJSON()),await _$(Y.config,{session:G,user:z,isNewUser:!1,method:"password",req:$});let{password:F,...Q}=z;return Q}async signUp(){let $=T(E),{userProvider:Z,config:j}=$,J=new j.signUpRequest,W=await J.input(),{email:Y,password:z,name:X,invitationId:G}=W.toJSON(),F=nY(Y);if(!F)throw new g({email:["Invalid email"]});if(z!=null&&typeof z!=="string")throw new g({password:["Invalid password"]});if(G!=null&&typeof G!=="string")throw new g({invitationId:["Invalid invitation"]});if(await Z.findUserByEmailAddress(F,!1))throw new g({email:["Email address already exists"]});let O=await j.hashPassword(z),K=T(o).detectLocale(J),D;if(G)D=await Z.findInvitation(G,F);let B,U="";if(D)B=await Z.transaction(async()=>{await Z.deleteInvitationById(G);let V=await Z.createUser({email:F,name:X,password:O,emailVerifiedAt:new Date,locale:K});return await Z.createAccount({organizationId:D.organizationId,userId:V.id,organizationRole:D.role}),await j.onUserCreated(V),V});else U=await j.generateEmailVerificationToken(F),B=await Z.transaction(async()=>{let V=await Z.createUser({email:F,name:X,password:O,verificationToken:U,locale:K});return await j.onUserCreated(V),V});return await j.onSignUp(B,U,J.search.toJSON()),B}async signOut($=new S){let Z=k8($),j=T(E),{config:J}=j,W=await j.revokeSession(Z,$.headers.get("User-Agent"));if($.ctx().setCookie("access_token","",T(E).accessTokenCookieOptions($,new Date(0))),T(E).cookieDomain($))$.ctx().setCookie("access_token","",{...T(E).accessTokenCookieOptions($,new Date(0)),domain:void 0});if(W?.user)W.user.extension=await J.extendSession(W.user),await J.onSignOut(W.user);return{}}async forgotPassword($=new tY){let Z=await $.input(),j=nY(Z.get("email"));if(!j)return{};let{userProvider:J,config:W}=T(E),Y=await J.findUserByEmailAddress(j,W.verifyEmail);if(!Y)return{};let z=await W.generateForgotPasswordToken(Y);return await J.createPasswordResetToken({user:Y,token:z}),await W.onForgotPassword(Y,z),{}}async resetPassword($=new eY){let{userProvider:Z,config:j}=T(E),J=await $.input(),{password:W,token:Y}=J.toJSON(),z=E4(Y),X=z?await Z.findPasswordResetToken({token:z}):null;if(!X)throw new g({token:["Invalid token"]});if(DZ.Instant.from(X.createdAt.toISOString()).add({hours:24}).until(DZ.Now.instant()).sign>=0)throw new g({token:["Token expired"]});await Z.deletePasswordResetToken({token:z});let F=await Z.findUserByEmailAddress(X.user.email,j.verifyEmail);if(!F)throw new g({email:["User not found"]});let Q=await j.hashPassword(W);return await Z.updateUserPassword({id:F.id,password:Q}),await Z.deleteAllUserSessions(F.id),await j.onResetPassword(F),{}}async changePassword($=new S){let{userProvider:Z,config:j}=T(E),J=await X1.user(),W=await $.input(),{oldPassword:Y,newPassword:z}=W.toJSON();if(typeof z!=="string")throw new g({newPassword:["Invalid password"]});let X=await Z.findUserByEmailAddress(J.email,j.verifyEmail);if(!(typeof Y==="string"&&await f4(j,Y,X?.password)))throw new g({oldPassword:["Incorrect password"]});let F=await j.hashPassword(z);return await Z.updateUserPassword({id:J.id,password:F}),await Z.deleteAllUserSessions(J.id),{}}async oauthRedirect($=new S){let{provider:Z}=$.params,j=T(E).config.oauthProviders[Z];if(!j)throw Error(`Invalid provider: ${Z}`);let J=q$($.rawRequest),W=U1($.search.get(D1),"");if(W)$.ctx().setCookie(e6,encodeURIComponent(W),{httpOnly:!0,sameSite:"Lax",secure:J,maxAge:600});else rY($);let{state:Y,codeChallenge:z,cookieValue:X}=r6(Z);return $.ctx().setCookie(UZ(J),X,{httpOnly:!0,sameSite:"Lax",secure:J,maxAge:B3}),{destination:await j.getRedirectUrl($,{state:Y,codeChallenge:z,codeChallengeMethod:"S256"})}}async oauthCallback($=new S){let{provider:Z}=$.params,j=T(E),{userProvider:J,config:W}=j,Y=W.oauthProviders[Z],z=q$($.rawRequest),X=UZ(z),G=$.cookies.get(X);if(G!==void 0&&G!==null)$.ctx().setCookie(X,"",{httpOnly:!0,sameSite:"Lax",secure:z,maxAge:-1});if(!Y)return this.oauthFailure($,"unknown_provider");let F=$.search.get("error");if(F)return this.oauthFailure($,/^[a-z0-9_]{1,64}$/.test(F)?F:"provider_error");let Q=t6({provider:Z,cookieValue:G,returnedState:$.search.get("state")});if("reason"in Q)return console.error(`Authentication error: OAuth callback refused (${Q.reason})`),this.oauthFailure($,Q.reason);if(!$.search.get("code"))return this.oauthFailure($,"missing_code");let O;try{O=await Y.onCallback($,{state:Q.payload.state,codeVerifier:Q.payload.codeVerifier})}catch(A){if(A instanceof S4)return this.oauthFailure($,A.code);return console.error("Authentication error: OAuth provider callback failed",A),this.oauthFailure($,"provider_error")}let{name:K,username:D,providerId:B,emailVerified:U}=O??{},V=typeof O?.email==="string"?O.email:void 0,I=V?k3(V):null,P=B?await J.findUserBySocialAccount(Z,B):null,M="signin";if(!P){if(!I)return console.error("Authentication error: No usable email returned from OAuth provider callback"),this.oauthFailure($,V?"invalid_email":B?"missing_email":"no_identity");if(U===!1)return console.error("Authentication error: OAuth provider returned an unverified email"),this.oauthFailure($,"email_not_verified");let A=T(o).detectLocale($);try{let _=await this.linkOAuthAccount({provider:Z,providerId:B,email:I,rawEmail:V,name:K,username:D,locale:A,linkExisting:Y.linkByEmail!==!1,createUser:Y.createUsers!==!1});if(_==="account_exists")return console.error(`Authentication error: a ${Z} sign-in matched an existing user by email, and ${Z} does not link by email`),this.oauthFailure($,"account_exists");if(_==="signup_disabled")return console.error(`Authentication error: a ${Z} sign-in is not linked to a user, and ${Z} does not create users`),this.oauthFailure($,"signup_disabled");if(_)P=_.user,M=_.action}catch(_){let L=B?await J.findUserBySocialAccount(Z,B):null;if(!L)throw _;P=L}if(!P)return this.oauthFailure($,"account_conflict")}let x=await j.createOrUpdateSessionV2({email:P.email,id:P.id});if($.ctx().setCookie("access_token",x.token,T(E).accessTokenCookieOptions($,x.expiresAt)),M==="signup")await W.onSignUp(P,"",$.search.toJSON());else await W.onSignIn(P,$.search.toJSON());await _$(j.config,{session:x,user:P,isNewUser:M==="signup",method:"oauth",req:$});let f=aY($)??W.redirectPath;return{session:x,redirectTo:f}}oauthFailure($,Z){let j=aY($),J=T(E).config.oauthFailurePath;if(J){let W=U1(J,"");if(W){let Y=new URL(W,"http://gemi.invalid");if(Y.searchParams.set("error",Z),j)Y.searchParams.set(D1,j);O1.external(`${Y.pathname}${Y.search}${Y.hash}`)}else console.error(`auth.oauthFailurePath must be a same-origin path, got ${JSON.stringify(J)}`)}return{session:null,error:Z,redirectTo:j}}async linkOAuthAccount($){let{provider:Z,providerId:j,email:J,rawEmail:W,name:Y,username:z,locale:X}=$,{userProvider:G,config:F}=T(E),Q=(B)=>({provider:Z,userId:B,email:J,username:z,providerId:j,expiresAt:new Date,accessToken:"",refreshToken:""}),O=await G.findUserByEmailAddress(J,!1),K=W?.trim();if(!O&&K&&K!==J)O=await G.findUserByEmailAddress(K,!1);if(O){if($.linkExisting===!1)return"account_exists";if(!j)return{user:O,action:"signin"};let B=await G.findSocialAccounts(O.id,Z);if(B.some((V)=>V.providerId===j))return{user:O,action:"signin"};if(B.some((V)=>V.providerId))return console.error(`Authentication error: user ${O.id} is already linked to a different ${Z} account`),null;let U=B[0];if(U){if(!await G.claimSocialAccount(U,j))throw Error(`${Z} account link changed concurrently`)}else await G.createSocialAccount(Q(O.id));return{user:O,action:"signin"}}if($.createUser===!1)return"signup_disabled";return{user:await G.transaction(async()=>{let B=await G.createUser({email:J,name:Y,locale:X,emailVerifiedAt:new Date});if(j)await G.createSocialAccount(Q(B.id));return await F.onUserCreated(B),B}),action:"signup"}}async createMagicLinkToken($=new S){let Z=await $.input(),j=yZ(Z.get("email")),J=T(E),{uniformMagicLinkResponse:W,requestLimit:Y}=J.config.emailCode;if(await d$("request",j,$,Y),!j)return{email:null};let{user:z,pin:X,token:G}=await J.createMagicLinkToken(j);if(z)return await J.config.onMagicLinkCreated(z,{email:j,pin:X,token:G}),{email:j};return{email:W?j:null}}async requestEmailCode($=new S){let Z=T(E),j=Z.config.emailCode;if(!j.enabled)throw new y0("Not found",{status:404});let J=await $.input(),W=k3(J.get("email"));if(await d$("request",W,$,j.requestLimit),!W)throw new g({email:["Invalid email"]});let Y=await Z.userProvider.findUserByEmailAddress(W,!1);if(Y||j.createUser){let{pin:z,token:X}=await Z.issueOneTimeCode(W,j.length);await j.send({email:W,code:z,token:X,isNewUser:!Y,req:$})}return{ok:!0}}async verifyEmailCode($=new S){let Z=T(E),{userProvider:j,config:J}=Z;if(!J.emailCode.enabled)throw new y0("Not found",{status:404});let W=await $.input(),{email:Y,code:z,name:X}=W.toJSON(),G=k3(Y),F=oY(z);if(await d$("verify",G,$,J.emailCode.verifyLimit),!G||!F)throw new g({code:["invalid_code"]});let Q=await Z.verifyOneTimeCode(G,F,{claim:!1});if(Q.status==="too_many_attempts")throw new g({code:["too_many_attempts"]});if(Q.status!=="ok")throw new g({code:["invalid_code"]});let O=Q.row,K=await j.findUserByEmailAddress(G,!1),D=!1;if(K){if(!await j.claimMagicLinkToken(O.id))throw new g({code:["invalid_code"]});await j.verifyUser(G)}else if(J.emailCode.createUser){let U=T(o).detectLocale($);try{K=await j.transaction(async()=>{if(!await j.claimMagicLinkToken(O.id))throw new R4;let V=await j.createUser({email:G,name:typeof X==="string"?X.trim():"",emailVerifiedAt:new Date,locale:U});return await J.onUserCreated(V),V}),D=!0}catch(V){if(V instanceof R4)throw new g({code:["invalid_code"]});throw V}}else throw await j.claimMagicLinkToken(O.id),new g({code:["invalid_code"]});let B=await Z.createOrUpdateSessionV2({email:G,id:K.id});return $.ctx().setCookie("access_token",B.token,T(E).accessTokenCookieOptions($,B.expiresAt)),await J.onSignIn(B,$.search.toJSON()),await _$(Z.config,{session:B,isNewUser:D,method:"email-code",req:$}),{session:B,isNewUser:D}}}var $z="gemi_oauth_connection";class $8 extends wZ{async connect($=new S){let Z=String($.params.provider??""),J=T(D3).providers[Z],W=await X1.user(),Y=U1($.search.get(D1),"");if(!J)return this.finish(Y,Z,"unknown_provider");let z=q$($.rawRequest),{state:X,codeChallenge:G,cookieValue:F}=r6(Zz(Z),Date.now(),{subject:String(W.id),...Y?{returnTo:Y}:{}});return $.ctx().setCookie(UZ(z,$z),F,{httpOnly:!0,sameSite:"Lax",secure:z,maxAge:B3}),O1.external(J.authorizationUrl({state:X,codeChallenge:G,redirectUri:jz($,Z,J.config.redirectUri)})),{destination:"/"}}async callback($=new S){let Z=String($.params.provider??""),j=T(D3),J=await X1.user(),W=q$($.rawRequest),Y=UZ(W,$z),z=$.cookies.get(Y);if(z!==void 0&&z!==null)$.ctx().setCookie(Y,"",{httpOnly:!0,sameSite:"Lax",secure:W,maxAge:-1});let X=t6({provider:Zz(Z),cookieValue:z,returnedState:$.search.get("state")}),G="payload"in X?X.payload.returnTo??"":"",F=j.providers[Z];if(!F)return this.finish(G,Z,"unknown_provider");let Q=$.search.get("error");if(Q)return this.finish(G,Z,/^[a-z0-9_]{1,64}$/.test(Q)?Q:"provider_error");if("reason"in X)return console.error(`OAuth connection refused (${X.reason})`),this.finish(G,Z,X.reason);if(X.payload.subject!==String(J.id))return this.finish(G,Z,"user_mismatch");let O=$.search.get("code");if(!O)return this.finish(G,Z,"missing_code");try{let K=await F.exchangeCode({code:O,codeVerifier:X.payload.codeVerifier,redirectUri:jz($,Z,F.config.redirectUri)}),D=await j.save(J,Z,K);await T(E).config.onConnected({user:J,provider:Z,connection:D,req:$})}catch(K){if(K instanceof Jz)return console.error(`OAuth connection to ${Z} failed: ${K.message}`),this.finish(G,Z,K.providerError??K.code);throw K}return this.finish(G,Z)}finish($,Z,j){let J=$||U1(T(E).config.redirectPath,"/"),W=new URL(J,"http://gemi.invalid");if(W.searchParams.set("connection",Z),j)W.searchParams.set("connection_error",j);throw O1.external(`${W.pathname}${W.search}${W.hash}`),Error("unreachable: Redirect.external throws")}}function Zz($){return`connection:${$}`}function jz($,Z,j){if(j)return j;return`${(process.env.HOST_NAME||new URL($.rawRequest.url).origin).replace(/\/$/,"")}/auth/connections/${encodeURIComponent(Z)}/callback`}class Wz extends B1{middlewares=["cache:private"];routes={"/:provider":this.view("_Redirect",[s,"oauthRedirect"]),"/:provider/callback":this.view("auth/OauthCallback",[s,"oauthCallback"])}}class Yz extends B1{middlewares=["cache:private","auth"];routes={"/:provider":this.redirect([$8,"connect"]),"/:provider/callback":this.redirect([$8,"callback"])}}class v4 extends B1{middlewares=["cache:private"];routes={"/sign-in/magic-link":this.view("auth/MagicLinkSignIn",[s,"signInWithMagicLink"]),"/oauth":Wz,"/connections":Yz}}class w4 extends A0{middlewares=["cache:private"];routes={"/sign-in":this.post(s,"signIn"),"/sign-in-v2":this.post(s,"signInV2"),"/sign-up":this.post(s,"signUp"),"/sign-out":this.post(s,"signOut"),"/forgot-password":this.post(s,"forgotPassword"),"/reset-password":this.post(s,"resetPassword"),"/change-password":this.post(s,"changePassword"),"/verify-email":this.post(s,"verifyEmail"),"/me":this.get(s,"me").middleware(["auth"]),"/magic-link":this.post(s,"createMagicLinkToken"),"/sign-in-with-pin":this.post(s,"signInWithPin"),"/sign-in-with-pin-v2":this.post(s,"signInWithPinV2"),"/email-code":this.post(s,"requestEmailCode"),"/email-code/verify":this.post(s,"verifyEmailCode")}}class k4 extends A0{middlewares=["cache:private,0,no-store"];routes={"/set-locale/:locale":this.get(async()=>{let Z=new S().params.locale;return await T(o).onLocaleChange(Z),{locale:Z}}),"/translations/:locale/:scope*":this.get(async()=>{let $=new S,Z=`/${$.params.scope??""}`,j=$.params.locale,J=T(o),W=j??J.detectLocale($),Y=J.getPageTranslations(W,Z);return $.ctx().setCookie("i18n-locale",W,{expires:new Date(Date.now()+31536000000)}),{[W]:Y}})}}class y4{}class q4 extends y4{async resize($,Z){let{height:j,width:J,quality:W,fit:Y}=Z;return await(await Z8("The Sharp image optimization driver"))($).resize(J>0?J:void 0,j>0?j:void 0,{fit:Y}).webp({quality:W>0?W:80,force:!0}).toBuffer()}}function VT($){return $}function zz(){return{driver:new q4}}class g4 extends A0{routes={"/resize":this.file(async()=>{let $=new S,Z=new URL($.rawRequest.url),j=Z.searchParams.get("url"),J=Number(Z.searchParams.get("w")),W=Number(Z.searchParams.get("h")),Y=Z.searchParams.get("fit")??"cover",z=Number(Z.searchParams.get("q"));if(!j)return new Response(JSON.stringify({error:"url query parameter is required"}),{headers:{"Content-Type":"application/json"},status:404});let G=`${j.startsWith("http")?"":`http://localhost:${process.env.PORT||5173}`}${j}`,F=await fetch(G);if(!F.ok)return new Response(JSON.stringify({error:"Image not found",info:G}),{headers:{"Content-Type":"application/json"},status:404});let Q=Buffer.from(await F.arrayBuffer()),O=await T(Xz).resize(Q,{height:W,width:J,fit:Y,quality:z});F.headers.delete("Content-Type"),F.headers.delete("Content-Length");let K=new Headers(F.headers);return K.set("Content-Type","image/webp"),K.set("Content-Length",`${O.byteLength}`),new Response(new Uint8Array(O),{headers:K})})}}class Xz{static token="image";driver;constructor($={}){this.driver=$.driver??zz().driver}resize($,Z){return this.driver.resize($,Z)}}class m4 extends A0{middlewares=["cache:private,0"];routes={"/live":this.get(async()=>{let $=Bun.file(T(Gz).currentLogFilePath);return new Response(await $.text(),{headers:{"Content-Type":"text/plain"}})})}}function XO($){let Z=new Map;for(let j of $)if(typeof j==="string"){let[J,W=""]=j.split(":");if(J.startsWith("-")){if(Z.has(J.replace("-","")))Z.delete(J.replace("-",""))}else Z.set(J,W.split(",").filter(Boolean))}else Z.set(j,[]);return Z}var GO={"body-limit":x3};class VZ{config;static token="middleware";defaultBodyLimit;constructor($){this.config=$;this.defaultBodyLimit=$.bodyLimit===null||$.bodyLimit===void 0?null:RZ($.bodyLimit)}get aliases(){return{...GO,...this.config.aliases}}applyDefaultBodyLimit($){if(this.defaultBodyLimit!==null&&!wJ($))C3($,this.defaultBodyLimit,{checkDeclared:!1})}assertGlobalMiddleware(){for(let $ of this.config.global){if(typeof $!=="string")continue;let[Z]=$.split(":");if(Z.startsWith("-"))throw Error(`Global middleware "${$}" cancels an alias, but nothing is inherited into the global list. Remove it.`);if(!this.aliases[Z])throw Error(`Global middleware "${Z}" is not a registered alias. Add it to \`aliases\` in the middleware config, or list the class itself.`)}}runGlobalMiddleware(){return this.runMiddleware(this.config.global)}runMiddleware($){let Z=new S,j=this.aliases,J=[];for(let[W,Y]of XO($).entries())if(typeof W==="string"){let z=j[W];if(z){let X=new z(Z);J.push({run:()=>X.run.call(X,...Y),runsOnRefusal:Fz(z)})}}else if(L3(W)){let z=new W(Z);J.push({run:z.run.bind(z),runsOnRefusal:Fz(W)})}else J.push({run:W,runsOnRefusal:!1});return(async()=>{let W={};for(let Y=0;Y<J.length;Y++)try{W={...W,...await J[Y].run()}}catch(z){throw await FO(J.slice(Y+1)),z}return W})()}}function Fz($){return $?.runsOnRefusal===!0}async function FO($){for(let Z of $){if(!Z.runsOnRefusal)continue;try{await Z.run()}catch(j){console.error(j)}}}function bT($){return $}function Qz(){return{onRequestStart:()=>{},onRequestEnd:()=>{},onRequestFail:()=>{}}}function Kz(){return{partialRendering:!0,localeRouting:"prefix",onRequestStart:()=>{},onRequestEnd:()=>{},onRequestFail:()=>{},onStreamComplete:()=>{}}}function QO($){return"run"in $}function KO($){return Object.hasOwn($,"get")||Object.hasOwn($,"post")||Object.hasOwn($,"put")||Object.hasOwn($,"patch")||Object.hasOwn($,"delete")}function OO($){return Object.hasOwn($,"first")&&Object.hasOwn($,"second")}function BO($){if("__brand"in $)return $.__brand==="ApiRouter";return!1}function DO($){if("__internal_brand"in $)return $.__internal_brand==="ProxyHandler";return!1}function Oz($){if("__internal_brand"in $)return $.__internal_brand==="StreamHandler";return!1}function p4($,Z="",j=[]){let J={};function W(Y,z,X,G,F){let Q=Y==="/"?"":Y,O=Z==="/"?"":Z,K=(`${O}${Q}`===""?"/":`${O}${Q}`).replaceAll("//","/");if(!J[K])J[K]={};J[K][z.toUpperCase()]={exec:X,middleware:[...j,...G],...F?{source:F}:{}},J[K].OPTIONS={exec:()=>{let B=new S().ctx().headers;return new Response(null,{headers:B,status:204})},middleware:[]}}for(let[Y,z]of Object.entries($)){if(DO(z)){let X=z;for(let G of["GET","POST","PUT","DELETE"])W(Y,G,X.run.bind(X),X.middlewares);continue}if(QO(z)){let X=z,G=X.method,F=X.middlewares,Q=X.run.bind(X);if(W(Y,G,Q,F,X.source),Oz(z))W(Y,"HEAD",Q,F,X.source)}if(KO(z))for(let[X,G]of Object.entries(z)){let F=G,Q=F.middlewares,O=F.run.bind(F);if(W(Y,X,O,Q,F.source),X==="get"&&Oz(F))W(Y,"HEAD",O,Q,F.source)}if(BO(z)){let X=new z,G=p4(X.routes,`${Z}${Y}`,X.middlewares);for(let[F,Q]of Object.entries(G))J[F.replaceAll("//","/")]=Q}if(OO(z)){let{first:X,second:G}=z;for(let[F,Q]of Object.entries(X)){let O=Q.middlewares,K=Q.run.bind(Q),[D,...B]=Y.split("/").reverse();if(!D.startsWith(":"))throw Error("Resource route must end with a dynamic segment");W(B.reverse().join("/"),F,K,O,Q.source)}for(let[F,Q]of Object.entries(G)){let O=Q.middlewares,K=Q.run.bind(Q);W(Y,F,K,O,Q.source)}}}return Object.fromEntries(Object.entries(J).sort(([Y],[z])=>{let X=Y.split("/").length+Y.split(":").length,G=z.split("/").length+z.split(":").length;return X-G}))}function j8($){return $.replace(/\([^)]*\)/g,"").replace(/\/\//g,"/")}function h4($,Z){if($==="/")return Z;if(Z==="/")return $;return`${$}${Z}`}function c4($){let Z=j8($);return Z.length>1?Z.replace(/\/$/,""):Z}function Bz($,Z){return Z.map((j)=>({...j,path:c4(h4($,j.path))}))}function J8($){let Z={};for(let[j,J]of Object.entries($))if("run"in J){let W=J;if("children"in W){let Y=new W.children,z=J8(Y.routes);for(let[X,{exec:G,middleware:F,segments:Q,features:O,static:K}]of Object.entries(z)){let D=h4(j,X),B=(U)=>W.run.call(W,U,j);Z[j8(D)]={exec:[B,...G],middleware:[...W.middlewares,...F],features:[...W.featureGates,...O],viewPath:W.viewPath,segments:[{path:c4(j),viewPath:W.viewPath,...W.alwaysRuns?{alwaysRun:!0}:{}},...Bz(j,Q)],...K?{static:K}:{}}}}else{let Y=(z)=>W.run.call(W,z,j);Z[j8(j)]={exec:[Y],middleware:W.middlewares,features:W.featureGates,viewPath:W.viewPath,segments:[{path:c4(j),viewPath:W.viewPath}],..."staticOptions"in W&&W.staticOptions?{static:W.staticOptions}:{}}}}else{let W=new J,Y=J8(W.routes);for(let[z,{exec:X,middleware:G,viewPath:F,segments:Q,features:O,static:K}]of Object.entries(Y)){let D=h4(j,z);Z[j8(D)]={exec:X,middleware:[...W.middlewares,...G],features:[...W.featureGates,...O],viewPath:F,segments:Bz(j,Q),...K?{static:K}:{}}}}return Object.fromEntries(Object.entries(Z).sort(([j],[J])=>{let W=j.split("/").length+j.split(":").length,Y=J.split("/").length+J.split(":").length;return W-Y}))}var UO=Object.defineProperty,H=($,Z)=>UO($,"name",{value:Z,configurable:!0}),MZ=class{type=3;name="";prefix="";value="";suffix="";modifier=3;constructor($,Z,j,J,W,Y){this.type=$,this.name=Z,this.prefix=j,this.value=J,this.suffix=W,this.modifier=Y}hasCustomName(){return this.name!==""&&typeof this.name!="number"}};H(MZ,"Part");var VO=/[$_\p{ID_Start}]/u,TO=/[$_\u200C\u200D\p{ID_Continue}]/u,u4=".*";function Dz($,Z){return(Z?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test($)}H(Dz,"isASCII");function s4($,Z=!1){let j=[],J=0;for(;J<$.length;){let W=$[J],Y=H(function(z){if(!Z)throw TypeError(z);j.push({type:"INVALID_CHAR",index:J,value:$[J++]})},"ErrorOrInvalid");if(W==="*"){j.push({type:"ASTERISK",index:J,value:$[J++]});continue}if(W==="+"||W==="?"){j.push({type:"OTHER_MODIFIER",index:J,value:$[J++]});continue}if(W==="\\"){j.push({type:"ESCAPED_CHAR",index:J++,value:$[J++]});continue}if(W==="{"){j.push({type:"OPEN",index:J,value:$[J++]});continue}if(W==="}"){j.push({type:"CLOSE",index:J,value:$[J++]});continue}if(W===":"){let z="",X=J+1;for(;X<$.length;){let G=$.substr(X,1);if(X===J+1&&VO.test(G)||X!==J+1&&TO.test(G)){z+=$[X++];continue}break}if(!z){Y(`Missing parameter name at ${J}`);continue}j.push({type:"NAME",index:J,value:z}),J=X;continue}if(W==="("){let z=1,X="",G=J+1,F=!1;if($[G]==="?"){Y(`Pattern cannot start with "?" at ${G}`);continue}for(;G<$.length;){if(!Dz($[G],!1)){Y(`Invalid character '${$[G]}' at ${G}.`),F=!0;break}if($[G]==="\\"){X+=$[G++]+$[G++];continue}if($[G]===")"){if(z--,z===0){G++;break}}else if($[G]==="("&&(z++,$[G+1]!=="?")){Y(`Capturing groups are not allowed at ${G}`),F=!0;break}X+=$[G++]}if(F)continue;if(z){Y(`Unbalanced pattern at ${J}`);continue}if(!X){Y(`Missing pattern at ${J}`);continue}j.push({type:"REGEX",index:J,value:X}),J=G;continue}j.push({type:"CHAR",index:J,value:$[J++]})}return j.push({type:"END",index:J,value:""}),j}H(s4,"lexer");function n4($,Z={}){let j=s4($);Z.delimiter??="/#?",Z.prefixes??="./";let J=`[^${k0(Z.delimiter)}]+?`,W=[],Y=0,z=0,X="",G=new Set,F=H((M)=>{if(z<j.length&&j[z].type===M)return j[z++].value},"tryConsume"),Q=H(()=>F("OTHER_MODIFIER")??F("ASTERISK"),"tryConsumeModifier"),O=H((M)=>{let x=F(M);if(x!==void 0)return x;let{type:f,index:A}=j[z];throw TypeError(`Unexpected ${f} at ${A}, expected ${M}`)},"mustConsume"),K=H(()=>{let M="",x;for(;x=F("CHAR")??F("ESCAPED_CHAR");)M+=x;return M},"consumeText"),D=H((M)=>M,"DefaultEncodePart"),B=Z.encodePart||D,U="",V=H((M)=>{U+=M},"appendToPendingFixedValue"),I=H(()=>{U.length&&(W.push(new MZ(3,"","",B(U),"",3)),U="")},"maybeAddPartFromPendingFixedValue"),P=H((M,x,f,A,_)=>{let L=3;switch(_){case"?":L=1;break;case"*":L=0;break;case"+":L=2;break}if(!x&&!f&&L===3){V(M);return}if(I(),!x&&!f){if(!M)return;W.push(new MZ(3,"","",B(M),"",L));return}let N;f?f==="*"?N=u4:N=f:N=J;let l=2;N===J?(l=1,N=""):N===u4&&(l=0,N="");let d;if(x?d=x:f&&(d=Y++),G.has(d))throw TypeError(`Duplicate name '${d}'.`);G.add(d),W.push(new MZ(l,d,B(M),N,B(A),L))},"addPart");for(;z<j.length;){let M=F("CHAR"),x=F("NAME"),f=F("REGEX");if(!x&&!f&&(f=F("ASTERISK")),x||f){let _=M??"";Z.prefixes.indexOf(_)===-1&&(V(_),_=""),I();let L=Q();P(_,x,f,"",L);continue}let A=M??F("ESCAPED_CHAR");if(A){V(A);continue}if(F("OPEN")){let _=K(),L=F("NAME"),N=F("REGEX");!L&&!N&&(N=F("ASTERISK"));let l=K();O("CLOSE");let d=Q();P(_,L,N,l,d);continue}I(),O("END")}return W}H(n4,"parse");function k0($){return $.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}H(k0,"escapeString");function l4($){return $&&$.ignoreCase?"ui":"u"}H(l4,"flags");function Uz($,Z,j){return o4(n4($,j),Z,j)}H(Uz,"stringToRegexp");function S$($){switch($){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}H(S$,"modifierToString");function o4($,Z,j={}){j.delimiter??="/#?",j.prefixes??="./",j.sensitive??=!1,j.strict??=!1,j.end??=!0,j.start??=!0,j.endsWith="";let J=j.start?"^":"";for(let X of $){if(X.type===3){X.modifier===3?J+=k0(X.value):J+=`(?:${k0(X.value)})${S$(X.modifier)}`;continue}Z&&Z.push(X.name);let G=`[^${k0(j.delimiter)}]+?`,F=X.value;if(X.type===1?F=G:X.type===0&&(F=u4),!X.prefix.length&&!X.suffix.length){X.modifier===3||X.modifier===1?J+=`(${F})${S$(X.modifier)}`:J+=`((?:${F})${S$(X.modifier)})`;continue}if(X.modifier===3||X.modifier===1){J+=`(?:${k0(X.prefix)}(${F})${k0(X.suffix)})`,J+=S$(X.modifier);continue}J+=`(?:${k0(X.prefix)}`,J+=`((?:${F})(?:`,J+=k0(X.suffix),J+=k0(X.prefix),J+=`(?:${F}))*)${k0(X.suffix)})`,X.modifier===0&&(J+="?")}let W=`[${k0(j.endsWith)}]|$`,Y=`[${k0(j.delimiter)}]`;if(j.end)return j.strict||(J+=`${Y}?`),j.endsWith.length?J+=`(?=${W})`:J+="$",new RegExp(J,l4(j));j.strict||(J+=`(?:${Y}(?=${W}))?`);let z=!1;if($.length){let X=$[$.length-1];X.type===3&&X.modifier===3&&(z=j.delimiter.indexOf(X)>-1)}return z||(J+=`(?=${Y}|${W})`),new RegExp(J,l4(j))}H(o4,"partsToRegexp");var e1={delimiter:"",prefixes:"",sensitive:!0,strict:!0},IO={delimiter:".",prefixes:"",sensitive:!0,strict:!0},MO={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Vz($,Z){return $.length?$[0]==="/"?!0:!Z||$.length<2?!1:($[0]=="\\"||$[0]=="{")&&$[1]=="/":!1}H(Vz,"isAbsolutePathname");function a4($,Z){return $.startsWith(Z)?$.substring(Z.length,$.length):$}H(a4,"maybeStripPrefix");function Tz($,Z){return $.endsWith(Z)?$.substr(0,$.length-Z.length):$}H(Tz,"maybeStripSuffix");function r4($){return!$||$.length<2?!1:$[0]==="["||($[0]==="\\"||$[0]==="{")&&$[1]==="["}H(r4,"treatAsIPv6Hostname");var Iz=["ftp","file","http","https","ws","wss"];function t4($){if(!$)return!0;for(let Z of Iz)if($.test(Z))return!0;return!1}H(t4,"isSpecialScheme");function Mz($,Z){if($=a4($,"#"),Z||$==="")return $;let j=new URL("https://example.com");return j.hash=$,j.hash?j.hash.substring(1,j.hash.length):""}H(Mz,"canonicalizeHash");function Pz($,Z){if($=a4($,"?"),Z||$==="")return $;let j=new URL("https://example.com");return j.search=$,j.search?j.search.substring(1,j.search.length):""}H(Pz,"canonicalizeSearch");function Nz($,Z){return Z||$===""?$:r4($)?ZJ($):$J($)}H(Nz,"canonicalizeHostname");function Lz($,Z){if(Z||$==="")return $;let j=new URL("https://example.com");return j.password=$,j.password}H(Lz,"canonicalizePassword");function Hz($,Z){if(Z||$==="")return $;let j=new URL("https://example.com");return j.username=$,j.username}H(Hz,"canonicalizeUsername");function Cz($,Z,j){if(j||$==="")return $;if(Z&&!Iz.includes(Z))return new URL(`${Z}:${$}`).pathname;let J=$[0]=="/";return $=new URL(J?$:"/-"+$,"https://example.com").pathname,J||($=$.substring(2,$.length)),$}H(Cz,"canonicalizePathname");function _z($,Z,j){return e4(Z)===$&&($=""),j||$===""?$:jJ($)}H(_z,"canonicalizePort");function Sz($,Z){return $=Tz($,":"),Z||$===""?$:W8($)}H(Sz,"canonicalizeProtocol");function e4($){switch($){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}H(e4,"defaultPortForProtocol");function W8($){if($==="")return $;if(/^[-+.A-Za-z0-9]*$/.test($))return $.toLowerCase();throw TypeError(`Invalid protocol '${$}'.`)}H(W8,"protocolEncodeCallback");function xz($){if($==="")return $;let Z=new URL("https://example.com");return Z.username=$,Z.username}H(xz,"usernameEncodeCallback");function Az($){if($==="")return $;let Z=new URL("https://example.com");return Z.password=$,Z.password}H(Az,"passwordEncodeCallback");function $J($){if($==="")return $;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test($))throw TypeError(`Invalid hostname '${$}'`);let Z=new URL("https://example.com");return Z.hostname=$,Z.hostname}H($J,"hostnameEncodeCallback");function ZJ($){if($==="")return $;if(/[^0-9a-fA-F[\]:]/g.test($))throw TypeError(`Invalid IPv6 hostname '${$}'`);return $.toLowerCase()}H(ZJ,"ipv6HostnameEncodeCallback");function jJ($){if($===""||/^[0-9]*$/.test($)&&parseInt($)<=65535)return $;throw TypeError(`Invalid port '${$}'.`)}H(jJ,"portEncodeCallback");function fz($){if($==="")return $;let Z=new URL("https://example.com");return Z.pathname=$[0]!=="/"?"/-"+$:$,$[0]!=="/"?Z.pathname.substring(2,Z.pathname.length):Z.pathname}H(fz,"standardURLPathnameEncodeCallback");function Ez($){return $===""?$:new URL(`data:${$}`).pathname}H(Ez,"pathURLPathnameEncodeCallback");function Rz($){if($==="")return $;let Z=new URL("https://example.com");return Z.search=$,Z.search.substring(1,Z.search.length)}H(Rz,"searchEncodeCallback");function bz($){if($==="")return $;let Z=new URL("https://example.com");return Z.hash=$,Z.hash.substring(1,Z.hash.length)}H(bz,"hashEncodeCallback");var vz=class{#Y;#J=[];#Z={};#$=0;#W=1;#F=0;#X=0;#B=0;#D=0;#U=!1;constructor($){this.#Y=$}get result(){return this.#Z}parse(){for(this.#J=s4(this.#Y,!0);this.#$<this.#J.length;this.#$+=this.#W){if(this.#W=1,this.#J[this.#$].type==="END"){if(this.#X===0){this.#M(),this.#Q()?this.#j(9,1):this.#K()?this.#j(8,1):this.#j(7,0);continue}else if(this.#X===2){this.#O(5);continue}this.#j(10,0);break}if(this.#B>0)if(this.#S())this.#B-=1;else continue;if(this.#_()){this.#B+=1;continue}switch(this.#X){case 0:this.#P()&&this.#O(1);break;case 1:if(this.#P()){this.#f();let $=7,Z=1;this.#L()?($=2,Z=3):this.#U&&($=2),this.#j($,Z)}break;case 2:this.#T()?this.#O(3):(this.#I()||this.#K()||this.#Q())&&this.#O(5);break;case 3:this.#H()?this.#j(4,1):this.#T()&&this.#j(5,1);break;case 4:this.#T()&&this.#j(5,1);break;case 5:this.#x()?this.#D+=1:this.#A()&&(this.#D-=1),this.#C()&&!this.#D?this.#j(6,1):this.#I()?this.#j(7,0):this.#K()?this.#j(8,1):this.#Q()&&this.#j(9,1);break;case 6:this.#I()?this.#j(7,0):this.#K()?this.#j(8,1):this.#Q()&&this.#j(9,1);break;case 7:this.#K()?this.#j(8,1):this.#Q()&&this.#j(9,1);break;case 8:this.#Q()&&this.#j(9,1);break;case 9:break;case 10:break}}this.#Z.hostname!==void 0&&this.#Z.port===void 0&&(this.#Z.port="")}#j($,Z){switch(this.#X){case 0:break;case 1:this.#Z.protocol=this.#G();break;case 2:break;case 3:this.#Z.username=this.#G();break;case 4:this.#Z.password=this.#G();break;case 5:this.#Z.hostname=this.#G();break;case 6:this.#Z.port=this.#G();break;case 7:this.#Z.pathname=this.#G();break;case 8:this.#Z.search=this.#G();break;case 9:this.#Z.hash=this.#G();break;case 10:break}this.#X!==0&&$!==10&&([1,2,3,4].includes(this.#X)&&[6,7,8,9].includes($)&&(this.#Z.hostname??=""),[1,2,3,4,5,6].includes(this.#X)&&[8,9].includes($)&&(this.#Z.pathname??=this.#U?"/":""),[1,2,3,4,5,6,7].includes(this.#X)&&$===9&&(this.#Z.search??="")),this.#N($,Z)}#N($,Z){this.#X=$,this.#F=this.#$+Z,this.#$+=Z,this.#W=0}#M(){this.#$=this.#F,this.#W=0}#O($){this.#M(),this.#X=$}#V($){return $<0&&($=this.#J.length-$),$<this.#J.length?this.#J[$]:this.#J[this.#J.length-1]}#z($,Z){let j=this.#V($);return j.value===Z&&(j.type==="CHAR"||j.type==="ESCAPED_CHAR"||j.type==="INVALID_CHAR")}#P(){return this.#z(this.#$,":")}#L(){return this.#z(this.#$+1,"/")&&this.#z(this.#$+2,"/")}#T(){return this.#z(this.#$,"@")}#H(){return this.#z(this.#$,":")}#C(){return this.#z(this.#$,":")}#I(){return this.#z(this.#$,"/")}#K(){if(this.#z(this.#$,"?"))return!0;if(this.#J[this.#$].value!=="?")return!1;let $=this.#V(this.#$-1);return $.type!=="NAME"&&$.type!=="REGEX"&&$.type!=="CLOSE"&&$.type!=="ASTERISK"}#Q(){return this.#z(this.#$,"#")}#_(){return this.#J[this.#$].type=="OPEN"}#S(){return this.#J[this.#$].type=="CLOSE"}#x(){return this.#z(this.#$,"[")}#A(){return this.#z(this.#$,"]")}#G(){let $=this.#J[this.#$],Z=this.#V(this.#F).index;return this.#Y.substring(Z,$.index)}#f(){let $={};Object.assign($,e1),$.encodePart=W8;let Z=Uz(this.#G(),void 0,$);this.#U=t4(Z)}};H(vz,"Parser");var d4=["protocol","username","password","hostname","port","pathname","search","hash"],t1="*";function i4($,Z){if(typeof $!="string")throw TypeError("parameter 1 is not of type 'string'.");let j=new URL($,Z);return{protocol:j.protocol.substring(0,j.protocol.length-1),username:j.username,password:j.password,hostname:j.hostname,port:j.port,pathname:j.pathname,search:j.search!==""?j.search.substring(1,j.search.length):void 0,hash:j.hash!==""?j.hash.substring(1,j.hash.length):void 0}}H(i4,"extractValues");function G1($,Z){return Z?IZ($):$}H(G1,"processBaseURLString");function TZ($,Z,j){let J;if(typeof Z.baseURL=="string")try{J=new URL(Z.baseURL),Z.protocol===void 0&&($.protocol=G1(J.protocol.substring(0,J.protocol.length-1),j)),!j&&Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.username===void 0&&($.username=G1(J.username,j)),!j&&Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.username===void 0&&Z.password===void 0&&($.password=G1(J.password,j)),Z.protocol===void 0&&Z.hostname===void 0&&($.hostname=G1(J.hostname,j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&($.port=G1(J.port,j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.pathname===void 0&&($.pathname=G1(J.pathname,j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.pathname===void 0&&Z.search===void 0&&($.search=G1(J.search.substring(1,J.search.length),j)),Z.protocol===void 0&&Z.hostname===void 0&&Z.port===void 0&&Z.pathname===void 0&&Z.search===void 0&&Z.hash===void 0&&($.hash=G1(J.hash.substring(1,J.hash.length),j))}catch{throw TypeError(`invalid baseURL '${Z.baseURL}'.`)}if(typeof Z.protocol=="string"&&($.protocol=Sz(Z.protocol,j)),typeof Z.username=="string"&&($.username=Hz(Z.username,j)),typeof Z.password=="string"&&($.password=Lz(Z.password,j)),typeof Z.hostname=="string"&&($.hostname=Nz(Z.hostname,j)),typeof Z.port=="string"&&($.port=_z(Z.port,$.protocol,j)),typeof Z.pathname=="string"){if($.pathname=Z.pathname,J&&!Vz($.pathname,j)){let W=J.pathname.lastIndexOf("/");W>=0&&($.pathname=G1(J.pathname.substring(0,W+1),j)+$.pathname)}$.pathname=Cz($.pathname,$.protocol,j)}return typeof Z.search=="string"&&($.search=Pz(Z.search,j)),typeof Z.hash=="string"&&($.hash=Mz(Z.hash,j)),$}H(TZ,"applyInit");function IZ($){return $.replace(/([+*?:{}()\\])/g,"\\$1")}H(IZ,"escapePatternString");function wz($){return $.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}H(wz,"escapeRegexpString");function kz($,Z){Z.delimiter??="/#?",Z.prefixes??="./",Z.sensitive??=!1,Z.strict??=!1,Z.end??=!0,Z.start??=!0,Z.endsWith="";let j=".*",J=`[^${wz(Z.delimiter)}]+?`,W=/[$_\u200C\u200D\p{ID_Continue}]/u,Y="";for(let z=0;z<$.length;++z){let X=$[z];if(X.type===3){if(X.modifier===3){Y+=IZ(X.value);continue}Y+=`{${IZ(X.value)}}${S$(X.modifier)}`;continue}let G=X.hasCustomName(),F=!!X.suffix.length||!!X.prefix.length&&(X.prefix.length!==1||!Z.prefixes.includes(X.prefix)),Q=z>0?$[z-1]:null,O=z<$.length-1?$[z+1]:null;if(!F&&G&&X.type===1&&X.modifier===3&&O&&!O.prefix.length&&!O.suffix.length)if(O.type===3){let K=O.value.length>0?O.value[0]:"";F=W.test(K)}else F=!O.hasCustomName();if(!F&&!X.prefix.length&&Q&&Q.type===3){let K=Q.value[Q.value.length-1];F=Z.prefixes.includes(K)}F&&(Y+="{"),Y+=IZ(X.prefix),G&&(Y+=`:${X.name}`),X.type===2?Y+=`(${X.value})`:X.type===1?G||(Y+=`(${J})`):X.type===0&&(!G&&(!Q||Q.type===3||Q.modifier!==3||F||X.prefix!=="")?Y+="*":Y+=`(${j})`),X.type===1&&G&&X.suffix.length&&W.test(X.suffix[0])&&(Y+="\\"),Y+=IZ(X.suffix),F&&(Y+="}"),X.modifier!==3&&(Y+=S$(X.modifier))}return Y}H(kz,"partsToPattern");var JJ=class{#Y;#J={};#Z={};#$={};#W={};#F=!1;constructor($={},Z,j){try{let J;if(typeof Z=="string"?J=Z:j=Z,typeof $=="string"){let X=new vz($);if(X.parse(),$=X.result,J===void 0&&typeof $.protocol!="string")throw TypeError("A base URL must be provided for a relative constructor string.");$.baseURL=J}else{if(!$||typeof $!="object")throw TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(J)throw TypeError("parameter 1 is not of type 'string'.")}typeof j>"u"&&(j={ignoreCase:!1});let W={ignoreCase:j.ignoreCase===!0},Y={pathname:t1,protocol:t1,username:t1,password:t1,hostname:t1,port:t1,search:t1,hash:t1};this.#Y=TZ(Y,$,!0),e4(this.#Y.protocol)===this.#Y.port&&(this.#Y.port="");let z;for(z of d4){if(!(z in this.#Y))continue;let X={},G=this.#Y[z];switch(this.#Z[z]=[],z){case"protocol":Object.assign(X,e1),X.encodePart=W8;break;case"username":Object.assign(X,e1),X.encodePart=xz;break;case"password":Object.assign(X,e1),X.encodePart=Az;break;case"hostname":Object.assign(X,IO),r4(G)?X.encodePart=ZJ:X.encodePart=$J;break;case"port":Object.assign(X,e1),X.encodePart=jJ;break;case"pathname":t4(this.#J.protocol)?(Object.assign(X,MO,W),X.encodePart=fz):(Object.assign(X,e1,W),X.encodePart=Ez);break;case"search":Object.assign(X,e1,W),X.encodePart=Rz;break;case"hash":Object.assign(X,e1,W),X.encodePart=bz;break}try{this.#W[z]=n4(G,X),this.#J[z]=o4(this.#W[z],this.#Z[z],X),this.#$[z]=kz(this.#W[z],X),this.#F=this.#F||this.#W[z].some((F)=>F.type===2)}catch{throw TypeError(`invalid ${z} pattern '${this.#Y[z]}'.`)}}}catch(J){throw TypeError(`Failed to construct 'URLPattern': ${J.message}`)}}get[Symbol.toStringTag](){return"URLPattern"}test($={},Z){let j={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof $!="string"&&Z)throw TypeError("parameter 1 is not of type 'string'.");if(typeof $>"u")return!1;try{typeof $=="object"?j=TZ(j,$,!1):j=TZ(j,i4($,Z),!1)}catch{return!1}let J;for(J of d4)if(!this.#J[J].exec(j[J]))return!1;return!0}exec($={},Z){let j={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof $!="string"&&Z)throw TypeError("parameter 1 is not of type 'string'.");if(typeof $>"u")return;try{typeof $=="object"?j=TZ(j,$,!1):j=TZ(j,i4($,Z),!1)}catch{return null}let J={};Z?J.inputs=[$,Z]:J.inputs=[$];let W;for(W of d4){let Y=this.#J[W].exec(j[W]);if(!Y)return null;let z={};for(let[X,G]of this.#Z[W].entries())if(typeof G=="string"||typeof G=="number"){let F=Y[X+1];z[G]=F}J[W]={input:j[W]??"",groups:z}}return J}static compareComponent($,Z,j){let J=H((X,G)=>{for(let F of["type","modifier","prefix","value","suffix"]){if(X[F]<G[F])return-1;if(X[F]===G[F])continue;return 1}return 0},"comparePart"),W=new MZ(3,"","","","",3),Y=new MZ(0,"","","","",3),z=H((X,G)=>{let F=0;for(;F<Math.min(X.length,G.length);++F){let Q=J(X[F],G[F]);if(Q)return Q}return X.length===G.length?0:J(X[F]??W,G[F]??W)},"comparePartList");return!Z.#$[$]&&!j.#$[$]?0:Z.#$[$]&&!j.#$[$]?z(Z.#W[$],[Y]):!Z.#$[$]&&j.#$[$]?z([Y],j.#W[$]):z(Z.#W[$],j.#W[$])}get protocol(){return this.#$.protocol}get username(){return this.#$.username}get password(){return this.#$.password}get hostname(){return this.#$.hostname}get port(){return this.#$.port}get pathname(){return this.#$.pathname}get search(){return this.#$.search}get hash(){return this.#$.hash}get hasRegExpGroups(){return this.#F}};H(JJ,"URLPattern");function U3($,Z){for(let[j,J]of Object.entries($)){let W=new JJ({pathname:j});if(W.test({pathname:Z}))return{routePath:j,params:W.exec({pathname:Z})?.pathname.groups??{},route:J}}return null}var x$={startIndex:0,carriedViews:[]};function yz($,Z){let j=G0($.path,Z);return j.includes("*")?null:j}function PO($,Z){if(!$)return x$;if($.search!==Z.search)return x$;let j=Math.min($.segments.length,Z.segments.length-1),J=0;while(J<j){let W=$.segments[J],Y=Z.segments[J];if(Y.alwaysRun)break;if(W.viewPath!==Y.viewPath)break;let z=yz(W,$.params),X=yz(Y,Z.params);if(z===null||X===null||z!==X)break;J++}if(J===0)return x$;return{startIndex:J,carriedViews:Z.segments.slice(0,J).map(({viewPath:W})=>W)}}function NO($,Z){let[,j,...J]=$.split("/");if(!Z.includes(j))return $;let W=`/${J.join("/")}`;return W==="/"?"/":W.replace(/\/$/,"")}function qz($){let{flatViewRoutes:Z,supportedLocales:j,from:J,origin:W,to:Y}=$;if(!J)return x$;let z;try{z=new URL(J,W)}catch{return x$}if(z.origin!==W)return x$;let X=U3(Z,NO(z.pathname,j));if(!X)return x$;return PO({segments:X.route.segments,params:X.params,search:z.search},Y)}var WJ="x-gemi-from";import{createElement as A1,Fragment as QX}from"react";function LO($){return $.replace(/\([^)]*\)/g,"").replace(/\/\//g,"/")}function Y8($){let Z={};for(let[j,J]of Object.entries($))if("run"in J){let W=J.viewPath;if("children"in J){Z[j]=[W];let Y=new J.children,z=Y8(Y.routes);for(let[X,G]of Object.entries(z)){let F=j==="/"?X:`${j}${X}`,Q=X==="/"&&j!=="/"?j:F;Z[Q]=[W,...G]}if(Z[j].length===1)delete Z[j]}else Z[j]=[W]}else{let W=new J,Y=Y8(W.routes);for(let[z,X]of Object.entries(Y)){let G=j==="/"?z:`${j}${z}`,F=z==="/"&&j!=="/"?j:G;Z[F]=X}}return Object.fromEntries(Object.entries(Z).map(([j,J])=>[LO(j),J]))}function z8($,Z){let[j,J]=Z,W=$.find(([Y])=>Y===j);if(!W){$.push([j,[...J]]);return}for(let Y of J)z8(W[1],Y)}function X8($){let Z=[];for(let[j,J]of Object.entries($))if("run"in J){let W=J.viewPath;if(W==="__")continue;if(W==="REDIRECT")continue;if(W==="FILE")continue;if("children"in J){let Y=new J.children,z=X8(Y.routes);z8(Z,[W,z])}else z8(Z,[W,[]])}else{let W=new J,Y=X8(W.routes);for(let z of Y)z8(Z,z)}return Z}function YJ($){let Z=[];for(let[j,J]of $)Z.push(j,...YJ(J).flat());return Array.from(new Set(Z))}class $$ extends c{static getFacadeAccessor(){return o}static getSupportedLocales(){return this.getFacadeRoot().supportedLocales}static getDefaultLocale(){return this.getFacadeRoot().defaultLocale}static locale(){let $=this.getFacadeRoot(),Z=C.getStore();if(Z)return Z.locale??$.detectLocale(Z.req);return $.defaultLocale}static timeZone(){return this.getFacadeRoot().detectTimeZone(C.getStore()?.req)}static formatter($={}){return this.getFacadeRoot().formatter($.locale??$$.locale(),$.timeZone??$$.timeZone())}static setLocale($=$$.locale(),Z={}){let j=this.getFacadeRoot(),J=$;if(!j.supportedLocales.includes($))J=j.defaultLocale;let W=C.getStore();if(Z.cookie!==!1)W.setCookie("i18n-locale",J,{expires:new Date(Date.now()+31536000000),secure:!1,httpOnly:!1});return W.setLocale(J),J}}class zJ{id;static token="kernel.id";constructor($=crypto.randomUUID()){this.id=$}}var HO=new Set(["script","style","textarea","title","xmp","iframe","noembed","noframes","noscript"]),CO=new Set(["svg","math"]);function gz($){return $===32||$===9||$===10||$===12||$===13}function mz($){return $>=65&&$<=90||$>=97&&$<=122}function G8($){return $>=65&&$<=90?$+32:$}function pz(){let $="data",Z="",j=!1,J="",W=0,Y=0,z=!1,X=0,G=0,F=()=>$==="data"&&X===0&&G===0,Q=()=>{if(!j&&HO.has(Z)){$="rawText",J=`</${Z}`,W=0,Z="";return}if($="data",Z==="template")if(j)X=Math.max(0,X-1);else X+=1;else if(CO.has(Z)){if(j)G=Math.max(0,G-1);else if(!z)G+=1}Z=""},O=(K)=>{switch($){case"data":if(K===60)$="tagOpen";return;case"tagOpen":if(K===33)$="bang",Y=0;else if(K===47)$="endTagOpen";else if(mz(K))$="tagName",j=!1,z=!1,Z=String.fromCharCode(G8(K));else if(K===63)$="bogus";else if(K===60)$="tagOpen";else $="data";return;case"endTagOpen":if(mz(K))$="tagName",j=!0,z=!1,Z=String.fromCharCode(G8(K));else if(K===62)$="data";else $="bogus";return;case"tagName":if(gz(K)||K===47)$="inTag",z=K===47;else if(K===62)Q();else Z+=String.fromCharCode(G8(K));return;case"inTag":if(K===62){Q();return}if(z=K===47,K===34)$="attrDouble";else if(K===39)$="attrSingle";return;case"attrDouble":if(K===34)$="inTag";z=!1;return;case"attrSingle":if(K===39)$="inTag";z=!1;return;case"bang":if(K===45){if(Y+=1,Y===2)$="comment",Y=0}else if(K===62)$="data";else $="bogus";return;case"bogus":if(K===62)$="data";return;case"comment":if(K===45)Y=Y<2?Y+1:2;else if(K===62&&Y>=2)$="data",Y=0;else Y=0;return;case"rawText":{if(W<J.length){if(G8(K)===J.charCodeAt(W))W+=1;else W=K===60?1:0;return}if(K===62)$="data",Z="";else if(gz(K)||K===47)$="inTag",Z="";else W=K===60?1:0;return}}};return{scanToInsertionPoint(K){for(let D=0;D<K.length;D++){if(F())return D;O(K[D])}return K.length},write(K){for(let D=0;D<K.length;D++)O(K[D])},isSafe:F}}function S1($){let Z=JSON.stringify($);if(Z===void 0)return"undefined";return Z.replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function _O($){return`<script>(self.__GEMI_STREAM__=self.__GEMI_STREAM__||[]).push(${S1([$.path,$.variantKey,$.data])})</script>`}function SO($){return`<script>(self.__GEMI_DICT__=self.__GEMI_DICT__||[]).push(${S1([$.id,$.locale,$.strings])})</script>`}function XJ($,Z,j={},J){let W=new TextEncoder,Y=[],z=!1,X=!1,G=()=>{if(X)return;X=!0,j.onClose?.()};Z.onSettle((B)=>{if(B.status!=="resolved")return;Y.push(_O(B))}),J?.onUse((B)=>{Y.push(SO(B))});let F=$.getReader(),Q=pz(),O=(B,U)=>{B.enqueue(U),j.onChunk?.(U)},K=(B)=>{while(Y.length>0){let U=W.encode(Y.shift());Q.write(U),O(B,U)}},D=(B,U)=>{if(Y.length===0){Q.write(U),O(B,U);return}let V=Q.scanToInsertionPoint(U);if(V>0)O(B,U.subarray(0,V));if(Q.isSafe())K(B);let I=U.subarray(V);if(I.length>0)Q.write(I),O(B,I)};return new ReadableStream({async pull(B){let U;try{U=await F.read()}catch(P){throw G(),P}let{done:V,value:I}=U;if(V){K(B),B.close(),G();return}if(!z){if(z=!0,Q.write(I),O(B,I),j.onShell?.(),Q.isSafe())K(B);return}D(B,I)},cancel(B){return G(),F.cancel(B)}})}var xO=/bot|crawler|spider|crawling|slurp|bingpreview|mediapartners|headless|lighthouse|prerender|facebookexternalhit|whatsapp|telegram|discord|twitterbot|linkedinbot/i;function F8($){if(!$)return!1;return xO.test($)}async function cz($,Z=()=>{}){let j=C.getStore(),J=j?.req??null,W=null;if(J?.rawRequest?.url)try{W=new URL(J.rawRequest.url).pathname}catch{W=null}return{user:j?.user??null,attributes:await AO($,Z),request:{path:W,routePath:J?.routePath??null,locale:j?.locale??null},anonymousId:hz(),isBot:F8(J?.rawRequest?.headers?.get("user-agent")??null),now:new Date}}function dz($){return{user:$.user??null,attributes:$.attributes??{},request:{path:null,routePath:null,locale:null},anonymousId:$.subjectId??null,isBot:!1,now:new Date}}async function AO($,Z){if(!$.context)return{};try{let j=C.getStore();return await $.context(j?.req??null)??{}}catch(j){return Z(`The \`context\` hook in app/config/features.ts threw; evaluating with no attributes. ${j instanceof Error?j.message:String(j)}`),{}}}function uz($,Z){return`${$}:${Z}`}function GJ($){let Z=new Bun.CryptoHasher("sha1").update($).digest("hex"),j=Number.parseInt(Z.slice(0,8),16);return Math.floor(j/4294967296*1e4)}function lz($,Z){if(Z>=100)return!0;if(Z<=0)return!1;return $<Math.round(Z*100)}function iz($,Z,j,J){if(J.unavailable)return{value:!1,reason:"unavailable"};if(J.active!==!0)return{value:!1,reason:"inactive"};if(Z.when){let Y;try{Y=Z.when(j)}catch(z){return J.warn?.(`The \`when\` for feature "${$}" threw; treating it as off. ${z instanceof Error?z.message:String(z)}`),{value:!1,reason:"error"}}if(typeof Y==="boolean")return{value:Y,reason:"attributed"}}if(Z.rollout===void 0)return{value:!0,reason:"on"};if(j.isBot)return{value:!1,reason:"bot"};let W=EO($,Z,j,J.buckets);return lz(W,Z.rollout)?{value:!0,reason:"rollout"}:{value:!1,reason:"excluded"}}function fO($){let Z=$.user?.publicId??$.user?.id;if(Z!==void 0&&Z!==null)return String(Z);return $.anonymousId??""}function EO($,Z,j,J){let W=uz(Z.salt??$,fO(j));if(!J)return GJ(W);let Y=J.get(W);if(Y!==void 0)return Y;let z=GJ(W);return J.set(W,z),z}class sz extends Error{cause;kind="FeatureReloadFailed";constructor($){super(`Could not reload feature switches after a write, so the cached switches may still predate it: ${$ instanceof Error?$.message:String($)}`);this.cause=$}}class FJ{source;declared;ttlMs;warn;snapshot=null;inflight=null;lastFailureLoggedAt=0;generation=0;lastError=null;retryAfter=0;constructor($,Z,j,J=()=>{}){this.source=$;this.declared=Z;this.ttlMs=j;this.warn=J}async get(){let $=this.snapshot;if($&&Date.now()-$.loadedAt<this.ttlMs)return $;if($){if(Date.now()>=this.retryAfter)this.refresh().catch(()=>{});return $}return await this.refresh()}refresh(){return this.inflight??=this.load().finally(()=>{this.inflight=null}),this.inflight}async invalidate(){await this.inflight?.catch(()=>{});let $=this.generation,Z=await this.refresh();if(this.generation===$)throw new sz(this.lastError);return Z}peek(){return this.snapshot}async load(){try{let $=await this.source.load(),{active:Z,audit:j}=this.readRows($);return this.snapshot={active:Z,audit:j,loadedAt:Date.now(),unavailable:!1},this.generation++,this.lastError=null,this.retryAfter=0,this.snapshot}catch($){return this.handleFailure($)}}readRows($){let Z=new Map,j=new Map;for(let J of $??[]){let W=typeof J?.key==="string"?J.key:null;if(!W){this.warn("Ignoring a feature row with no `key`.");continue}if(!(W in this.declared)){this.warn(`Feature row "${W}" is not declared in app/features, so it is ignored. Delete the row, or declare the feature.`);continue}Z.set(W,J.active===!0);let Y=RO(J);if(Y)j.set(W,Y)}return{active:Z,audit:j}}handleFailure($){let Z=$ instanceof Error?$.message:String($),j=Date.now();if(this.lastError=$,this.retryAfter=j+this.ttlMs,j-this.lastFailureLoggedAt>=this.ttlMs)this.lastFailureLoggedAt=j,this.warn(`Could not load feature switches: ${Z}`);if(this.snapshot)return this.snapshot;return this.snapshot={active:new Map,audit:new Map,loadedAt:j,unavailable:!0},this.snapshot}}function RO($){let Z={},j=$.updatedBy;if(typeof j==="string")Z.updatedBy=j;else if(j===null)Z.updatedBy=null;let J=$.updatedAt;if(J instanceof Date||typeof J==="string"||typeof J==="number"){let W=J instanceof Date?J:new Date(J);if(!Number.isNaN(W.getTime()))Z.updatedAt=W}return"updatedBy"in Z||"updatedAt"in Z?Z:null}class bO{}class vO extends Error{modelName;kind="FeatureModelMissing";constructor($){super(`No "${$}" model is registered, so every feature stays off. Add the model to prisma/schema.prisma and export it from app/models \u2014 see docs/feature-flags.md.`);this.modelName=$}}class QJ extends Error{sourceName;kind="FeatureSourceReadOnly";constructor($){super(`The feature source (${$}) is read-only, so Features.set() cannot write to it. Change the switch where that source reads from, or give the source a write() method.`);this.sourceName=$}}class nz extends Error{key;kind="UndeclaredFeature";constructor($){super(`"${$}" is not declared in app/features, so it cannot be switched. A row for it would be ignored \u2014 declare the feature first.`);this.key=$}}class oz{manager;ctx;constructor($,Z){this.manager=$;this.ctx=Z}async enabled($){return(await this.explain($)).value}async explain($){return await this.manager.evaluateIn($,this.ctx,new Map)}async all(){return await this.manager.evaluateAllIn(this.ctx,new Map,{clientOnly:!1})}}class PZ{config;log;static token="features";store;declared;warnedAboutSize=!1;warnedAboutActor=!1;constructor($,Z=()=>{}){this.config=$;this.log=Z;this.declared=$.features??{},this.store=new FJ($.source,this.declared,Math.max(0,$.ttl)*1000,this.log)}declarations(){return this.declared}async list(){let{active:$,audit:Z,unavailable:j}=await this.switches();return{unavailable:j,features:Object.entries(this.declared).map(([J,W])=>({key:J,describe:W.describe,rollout:W.rollout,targeted:W.when!==void 0,serverOnly:W.serverOnly,salt:W.salt,active:$.get(J),...Z.get(J)}))}}async refresh(){if(!this.config.enabled)return;if(Object.keys(this.declared).length===0)return;await this.store.refresh()}async invalidate(){try{if(this.config.enabled&&Object.keys(this.declared).length>0)await this.store.invalidate()}finally{C.getStore()?.featureEvaluations?.clear()}}async set($,Z,j={}){if(typeof $!=="string"||!Object.hasOwn(this.declared,$))throw new nz(String($));if(typeof Z!=="boolean")throw TypeError(`Features.set("${$}", \u2026) takes a boolean, not ${Z===null?"null":typeof Z}.`);let J=wO(j.actor),W=this.config.source;if(typeof W.write!=="function")throw new QJ(W.constructor?.name||"an anonymous source");let{actorRecorded:Y}=await W.write($,Z,{actor:J});if(J!==null&&!Y&&!this.warnedAboutActor)this.warnedAboutActor=!0,this.log('Features.set() was given an actor, but the feature source has nowhere to record it. For the database source, add a nullable `updatedBy String?` column to the feature flag model to keep "last changed by".');await this.invalidate()}async enabled($){return(await this.explain($)).value}async explain($){let Z=await this.requestContext();return await this.evaluateIn($,Z,this.requestBuckets())}async all(){let $=await this.requestContext();return await this.evaluateAllIn($,this.requestBuckets(),{clientOnly:!1})}async forClient(){if(!this.config.enabled)return{};let $=await this.requestContext(),Z=await this.evaluateAllIn($,this.requestBuckets(),{clientOnly:!0});return this.warnIfOversized(Object.keys(Z).length),Z}for($){return new oz(this,dz($))}async evaluateIn($,Z,j){let J=this.memoFor(Z),W=J?.get($);if(W)return W;let Y=this.declared[$];if(!Y)return{value:!1,reason:"undeclared"};let{active:z,unavailable:X}=await this.switchFor($),G=iz($,Y,Z,{active:z,unavailable:X,buckets:j,warn:this.log});return J?.set($,G),this.notify($,G,Z),G}async evaluateAllIn($,Z,j){let J={};for(let[W,Y]of Object.entries(this.declared)){if(j.clientOnly&&Y.serverOnly)continue;J[W]=(await this.evaluateIn(W,$,Z)).value}return J}async switches(){if(!this.config.enabled||Object.keys(this.declared).length===0)return{active:new Map,audit:new Map,unavailable:!1};let $=await this.store.get();return{active:$.active,audit:$.audit,unavailable:$.unavailable}}async switchFor($){if(!this.config.enabled)return{active:!1,unavailable:!1};let Z=await this.store.get();return{active:Z.active.get($),unavailable:Z.unavailable}}async requestContext(){let $=C.getStore();if($?.featureContext)return $.featureContext;let Z=await cz(this.config,this.log);if($)$.featureContext=Z;return Z}memoFor($){let Z=C.getStore();if(!Z||Z.featureContext!==$)return null;return Z.featureEvaluations??=new Map,Z.featureEvaluations}requestBuckets(){let $=C.getStore();if(!$)return new Map;return $.featureBuckets??=new Map,$.featureBuckets}notify($,Z,j){if(!this.config.onEvaluate)return;try{this.config.onEvaluate($,Z,j)}catch(J){this.log(`The \`onEvaluate\` hook in app/config/features.ts threw for "${$}". ${J instanceof Error?J.message:String(J)}`)}}warnIfOversized($){if(this.warnedAboutSize||$<=this.config.maxClientFlags)return;this.warnedAboutSize=!0,this.log(`${$} client-visible features are embedded in every document. Mark the ones only the server reads with \`serverOnly: true\` to keep them out of the payload.`)}}function wO($){if($===void 0||$===null)return null;if(typeof $==="string"){if($.length>0)return $}else if(typeof $==="object"){let{publicId:Z,id:j}=$;if(typeof Z==="string"&&Z.length>0)return Z;if(typeof j==="string"&&j.length>0||typeof j==="number")return String(j)}throw TypeError("Features.set() was given an `actor` that identifies nobody. Pass a string, or a user with a `publicId` or an `id`.")}function az($){return Object.fromEntries(Object.entries($).filter(([,Z])=>{return Z!==null&&Z!==void 0}))}var kO=50;class NZ{fetcher;entries=new Map;settleListener=null;failListener=null;shellAt=null;settledBacklog=[];shipped=new Set;requestStartedAt=performance.now();renderStartedAt=null;discoveryHintsMuted=!1;constructor($){this.fetcher=$}elapsed(){return Math.round(performance.now()-this.requestStartedAt)}keyFor($,Z){return[$,Z].filter((j)=>j.length>0).join("?")}markRenderStart(){if(this.renderStartedAt===null)this.renderStartedAt=performance.now()}markShell(){if(this.shellAt===null)this.shellAt=this.elapsed()}summarize($){let Z=this.elapsed();return{shellAt:this.shellAt??Z,settledAt:Z,aborted:$,queries:Array.from(this.entries.values(),(j)=>({path:j.path,variantKey:j.variantKey,startedAt:j.startedAt,settledAt:j.settledAt,status:j.status,source:j.source}))}}onQueryFail($){this.failListener=$}muteDiscoveryHints(){this.discoveryHintsMuted=!0}maybeLogLateDiscovery($){if(!$.lateBy||this.discoveryHintsMuted)return;if($.status!=="resolved")return;if(Bun.env.NODE_ENV==="production")return;let Z="";try{let W=JSON.stringify($.data)?.length??0;Z=W>=1024?`${(W/1024).toFixed(1)} kB`:`${W} B`}catch{Z="an unserializable payload"}let j=($.settledAt??0)-$.startedAt,J=$.variantKey?`, { search: ${JSON.stringify(Object.fromEntries(new URLSearchParams($.variantKey)))} }`:"";console.warn(`[gemi] useQuery("${$.patternPath}") was discovered ${$.lateBy}ms into the `+`server render \u2014 under a suspended segment, so its fetch (${j}ms, resolved ${Z}) could not overlap the others. It still streamed. If the query belongs on this route, \`Query.prefetch("${$.patternPath}"${J})\` in the view `+"handler starts it at request time \u2014 but note prefetched data is also re-fetched and "+`streamed into every client-side navigation payload for the route, even when the client already holds it, so weigh that bandwidth against the ${Z}. If the data is only needed conditionally (a closed popover, a hidden tab), \`{ lazy: true }\` + \`trigger()\` avoids running it here at all. \`Query.noPrefetch()\` in the handler marks the omission intentional and silences this hint for the route.`)}read($,Z){return this.entries.get(this.keyFor($,Z))}ensure($,Z={},j="render"){let J=Z.params??{},W=new URLSearchParams(az(Z.search??{}));W.delete("json"),W.sort();let Y=G0($,J),z=W.toString(),X=this.keyFor(Y,z),G=this.entries.get(X);if(G)return G;let F;if(j==="render"&&this.renderStartedAt!==null){let D=Math.round(performance.now()-this.renderStartedAt);if(D>kO)F=D}let Q,O=new Promise((D)=>{Q=D}),K={path:Y,patternPath:$,variantKey:z,lateBy:F,status:"pending",promise:O,source:j,startedAt:this.elapsed()};return this.entries.set(X,K),this.fetcher($,J,W).then((D)=>{K.status="resolved",K.data=D},(D)=>{K.status="rejected",K.error=D}).then(()=>{if(K.settledAt=this.elapsed(),this.maybeLogLateDiscovery(K),K.status==="rejected"&&this.failListener)this.failListener(K);if(this.settleListener)this.settleListener(K);else this.settledBacklog.push(K);Q()}),K}async allSettled(){let $=0;while($!==this.entries.size)$=this.entries.size,await Promise.all(Array.from(this.entries.values(),(Z)=>Z.promise))}snapshotResolved(){let $={};for(let[Z,j]of this.entries){if(j.status!=="resolved")continue;this.shipped.add(Z),$[j.path]??={},$[j.path][j.variantKey]=j.data}return $}onSettle($){this.settleListener=(j)=>{if(this.shipped.has(this.keyFor(j.path,j.variantKey)))return;$(j)};let Z=this.settledBacklog;this.settledBacklog=[];for(let j of Z)this.settleListener(j)}}class x1 extends Error{path;variantKey;status;body;retryAfter;constructor($,Z,j,J,W){super(typeof J?.message==="string"?J.message:`Request to /api${$} failed with status ${j}`);this.path=$;this.variantKey=Z;this.status=j;this.body=J;this.retryAfter=W;this.name="QueryError"}}function LZ(){let $=JSON.stringify({error:w1("permission","Forbidden",403)});return new Response($,{status:403,headers:{"Content-Type":"application/json","Content-Length":String(Buffer.byteLength($)),"Cache-Control":"no-store"}})}function KJ(){return{status:403,error:{message:"Forbidden"}}}function V3($){let Z=HZ.getStore();return(j,J,W)=>{let Y=new URL($.url).origin,z=[G0(j,J),W.toString()].filter((Q)=>Q.length>0).join("?"),X=new Request(`${Y}/${z}`,{headers:$.headers,signal:$.signal}),G=rz($);if(G)CZ(X,G);let F=new S(X,J);return HZ.run(Z,()=>C.run(F,async()=>{try{let Q=await T(a0).dispatchers(G).api.getRouteData(j);if(y$(Q)){if(!Q.ok)throw new x1(G0(j,J),W.toString(),Q.status,Q.body);return Q.body}if(Q instanceof Response){let O=await Q.json().catch(()=>null);if(!Q.ok)throw new x1(G0(j,J),W.toString(),Q.status,O);return O}return Q}catch(Q){if(Q instanceof x1)throw Q;let O=new x1(G0(j,J),W.toString(),500,{message:Q instanceof Error?Q.message:String(Q)});throw O.cause=Q,O}}))}}var yO=new Set(["script","style","template","title"]),qO=/\shidden([\s=/]|$)/i,gO=/"[^"]*"|'[^']*'/g;function mO($){let Z=0,j=0,J=0,W=0;while(W<$.length){let Y=$.indexOf("<",W),z=Y===-1?$.length:Y;if(z>W){let O=$.slice(W,z).replace(/\s+/g,"").length;if(J>0)j+=O;else Z+=O}if(Y===-1)break;if($.startsWith("<!--",Y)){let O=$.indexOf("-->",Y+4);W=O===-1?$.length:O+3;continue}let X=$.indexOf(">",Y);if(X===-1)break;let G=$.slice(Y+1,X);W=X+1;let F=/^\/?([a-zA-Z][a-zA-Z0-9-]*)/.exec(G)?.[1]?.toLowerCase();if(!F)continue;let Q=G.startsWith("/");if(!Q&&yO.has(F)&&!G.endsWith("/")){let O=$.indexOf(`</${F}`,W);W=O===-1?$.length:O;continue}if(F!=="div")continue;if(Q){if(J>0)J-=1}else if(J>0)J+=1;else if(qO.test(G.replace(gO,'""')))J=1}return{shellChars:Z,deferredChars:j}}var pO=1000,hO=64;function cO($){return $>=1000?`${($/1000).toFixed(1)} kB`:`${$} chars`}function dO($,Z){if(Z.deferredChars<pO)return null;if(Z.shellChars>=hO)return null;return`[gemi] GET ${$} streams ${cO(Z.deferredChars)} of its `+`content behind reveal scripts \u2014 a no-JS visitor sees ~${Z.shellChars} chars. If this is a public/content route, add "no-stream" to its middleware.`}function tz($=console.warn){let Z=new Set;return{shouldObserve(j){return!Z.has(j)},report(j,J){if(Z.has(j))return;let W=dO(j,J);if(!W)return;Z.add(j),$(W)}}}function ez(){let $=new TextDecoder,Z="";return{onChunk(j){Z+=$.decode(j,{stream:!0})},measure(){return Z+=$.decode(),mO(Z)}}}function $X($,Z,j=1e4,J){let W=new TextEncoder,Y=()=>{};return new ReadableStream({start(z){let X=!1,G=(Q)=>{if(X)return;X=!0,clearTimeout(F);try{z.close()}catch{}J?.({aborted:Q})};Y=G,z.enqueue(W.encode(`${JSON.stringify($)}
14
14
  `)),Z.onSettle((Q)=>{if(X||Q.status!=="resolved")return;z.enqueue(W.encode(`${JSON.stringify([Q.path,Q.variantKey,Q.data])}
15
15
  `))});let F=setTimeout(()=>G(!0),j);Z.allSettled().then(()=>G(!1),()=>G(!1))},cancel(){Y(!1)}})}import{Fragment as mI,createContext as uO,createElement as pI,lazy as hI,use as cI,useContext as dI}from"react";function ZX($){return{islands:[],render:$,instances:new WeakMap,count:0}}var T3="gemi-slot",jX="data-slot",JX="data-gemi-slot";var lO=Symbol.for("gemi.staticRender"),WX=globalThis[lO]??=uO(null);import{createHash as iO}from"crypto";var sO="gemi-islands",OJ='const d=document,c=JSON.parse(d.getElementById("gemi-islands").textContent),w=f=>(window.requestIdleCallback||setTimeout)(f),m=(e,o)=>{if(!e.g){e.g=1;import(o.s).then(x=>x.h(e,x.m[o.e])).catch(r=>console.error(r))}};for(const e of d.querySelectorAll("gemi-island")){const o=c.i[e.dataset.island];if(!o)continue;if(o.l=="eager")m(e,o);else if(o.l=="idle"||!window.IntersectionObserver||!e.children.length)w(()=>m(e,o));else{const v=new IntersectionObserver(n=>{if(n.some(x=>x.isIntersecting)){v.disconnect();m(e,o)}});for(const k of e.children)v.observe(k)}}',nI=`'sha256-${iO("sha256").update(OJ).digest("base64")}'`,nO='await import("/refresh.js").catch(()=>{});await import("/@vite/client").catch(()=>{});'+OJ;function YX($,Z,j,J){if(!j)return $;let W=J?$.lastIndexOf(Z):$.indexOf(Z);return W===-1?$+j:$.slice(0,W)+j+$.slice(W)}var oO=($)=>$.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;");function zX($,Z,j,J){if(Z.islands.length===0||!j)return $;let W=new Set,Y=Z.islands.map((G)=>{let F=G.module?j(G.module):void 0;if(!F)return console.error(`[gemi] island ${G.module??"(unknown module)"}: no client build entry. Declare it as island(() => import("./Component")) so gemi's Vite plugin builds it.`),null;if(G.load==="eager")for(let Q of F.preload)W.add(Q);return{s:F.src,e:G.export,l:G.load}});if(Y.every((G)=>G===null))return $;let z=[...W].map((G)=>`<link rel="modulepreload" href="${oO(G)}"/>`).join(""),X=`<script type="application/json" id="${sO}">${S1({i:Y})}</script><script type="module">${J?nO:OJ}</script>`;return YX(YX($,"</head>",z,!1),"</body>",X,!0)}function aO($,Z){let j=/<(\/?)template\b[^>]*>/gi;j.lastIndex=Z;let J=0;for(let W=j.exec($);W;W=j.exec($))if(J+=W[1]?-1:1,J===0)return j.lastIndex;return-1}function XX($){let Z=`<template ${JX}="`;for(let j=$.lastIndexOf(Z);j!==-1;j=$.lastIndexOf(Z)){let J=aO($,j);if(J===-1)break;let W=j+Z.length,Y=$.slice(W,$.indexOf('"',W)),z=$.indexOf(">",W)+1,X=$.slice(z,J-11);$=$.slice(0,j)+$.slice(J);let G=`<${T3} ${jX}="${Y}" style="display:contents"></${T3}>`;$=$.split(G).join(`<${T3} style="display:contents">${X}</${T3}>`)}return $}function GX($){if(!$)return{locale:!0,session:!0,csrf:!0};return{locale:!1,session:$.session===!0,csrf:$.csrf===!0}}function FX($,Z){if($.getSetCookie().length>0){if(Z.cacheControl&&Bun.env.NODE_ENV!=="production")console.warn(`[gemi] A static view with cacheControl "${Z.cacheControl}" set a cookie, so it was sent "private, no-store" instead. Static pages are cacheable only when nothing on them sets a cookie.`);$.set("Cache-Control","private, no-store");return}if(Z.cacheControl&&!$.has("Cache-Control"))$.set("Cache-Control",Z.cacheControl)}var rO=async()=>(await import("./chunk-ebret82e.js")).default,BJ,I3=async(...$)=>{return BJ??=import("react-dom/server.browser").catch((Z)=>{throw BJ=void 0,Z}),(await BJ).renderToReadableStream(...$)},KX=1e4,OX="no-locale",tO=`
16
16
  !function(){try{var d=document.documentElement,c=d.classList;
@@ -23,7 +23,7 @@ if('system'===e||(!e&&'system'===defaultTheme)){
23
23
  }else if(e){
24
24
  c.add(e||'')
25
25
  }}catch(e){}}()
26
- `;async function eO($,Z,j){let J=`${j==="italic"?"italic,":""}wght@${j==="italic"?"1,":""}${Z}`,z=(await(await fetch(`https://fonts.googleapis.com/css2?family=${$}:${J}&display=swap`,{headers:{"User-Agent":"Mozilla/5.0 Firefox/1.0"}})).text()).match(/url\(([^)]+)\)/)?.[1];return await fetch(z).then((X)=>X.arrayBuffer())}var VJ="/assets";function $B($){return $===VJ||$.startsWith(`${VJ}/`)}function ZB($){let Z=$.filter($B);if(Z.length>0){let j=Z.length>1;throw Error(`View route path${j?"s":""} ${Z.map((J)=>`"${J}"`).join(", ")} use${j?"":"s"} the reserved "${VJ}" prefix. The client build output is served from there before the router runs, so the route would never match. Mount it somewhere else.`)}}function jB($){let Z=T(a0).resolver;return{...$.domain,root:Z.root,origin:Z.publicOrigin($.rawRequest)}}function DJ($){let{status:Z=400,error:j}=$;return new Response(j?.message,{...$,status:Z})}function JB($){let{status:Z=400,data:j,directive:J,headers:W}=$;return new Response(JSON.stringify({data:j,directive:J}),{headers:W,status:Z})}class P3{static token="router.view";flatViewRoutes={};routeManifest={};clientRouteManifest={};componentTree=[];flatComponentTree=[];staticRoutes=[];root=null;shellReporter=tz();preloadCache=new WeakMap;hooks;partialRendering;localeRouting;constructor($){let Z=Kz();this.partialRendering=$.partialRendering??Z.partialRendering,this.localeRouting=$.localeRouting??Z.localeRouting,this.hooks={onRequestStart:$.onRequestStart??Z.onRequestStart,onRequestEnd:$.onRequestEnd??Z.onRequestEnd,onRequestFail:$.onRequestFail??Z.onRequestFail,onStreamComplete:$.onStreamComplete??Z.onStreamComplete};let j={"/":$.rootRouter,"/auth":v4};this.flatViewRoutes=J8(j),ZB(Object.keys(this.flatViewRoutes)),this.routeManifest=Y8(j),this.clientRouteManifest=Object.fromEntries(Object.entries(this.routeManifest).filter(([,J])=>J.at(-1)!=="FILE")),this.componentTree=X8(j),this.flatComponentTree=YJ(this.componentTree),this.staticRoutes=Object.entries(this.flatViewRoutes).filter(([,J])=>J.static).map(([J])=>J);for(let J of this.staticRoutes){let W=this.flatViewRoutes[J].static?.layout;if(W&&!this.flatComponentTree.includes(W))this.flatComponentTree.push(W)}this.root=$.root}async passesFeatureGates($){let Z=T(PZ);for(let j of $)if(!await Z.enabled(j))return!1;return!0}async onRequestEnd($,Z={}){if(Z.mintSession!==!1)Q8();return await this.hooks.onRequestEnd($)}completeStream($,Z){let j=(J)=>{A$.error(J?.message??'Error in "onStreamComplete" event handler',{err:JSON.stringify(J)})};try{Promise.resolve(this.hooks.onStreamComplete($,Z)).catch(j)}catch(J){j(J)}}modulePreloadLinks($){let{clientEntry:Z,modulePreloadManifest:j,views:J,routeKey:W}=$,Y=()=>{let G=new Set(Z?.preload??[]);for(let F of J)for(let Q of j?.[F]??[])G.add(Q);return[...G].map((F)=>A1("link",{key:`modulepreload:${F}`,rel:"modulepreload",href:F}))};if(!j)return Y();let z=this.preloadCache.get(j);if(!z||z.clientEntry!==Z)z={clientEntry:Z,byRoute:new Map},this.preloadCache.set(j,z);let X=z.byRoute.get(W);if(!X)X=Y(),z.byRoute.set(W,X);return X}async renderStatic($){let{req:Z,runInRequestScope:j,staticView:J,currentViews:W,data:Y,serverQueries:z,headers:X}=$,G;if(J.layout){if(G=$.viewImportMap[J.layout],!G)throw Error(`The static layout "${J.layout}" was not found. It is a view path: a file at app/views/${J.layout}.tsx whose default export renders the document.`)}let F=await $.getStyles(W,{static:!0,layout:J.layout});z.markRenderStart();let Q=UJ(),O=new AbortController,K=setTimeout(()=>O.abort(),KX),D=(U)=>{if(Bun.env.NODE_ENV!=="production")console.error(U)},B=ZX(async(U,V)=>{let I=await I3(U,{signal:O.signal,identifierPrefix:V,progressiveChunkSize:Number.MAX_SAFE_INTEGER,onError:D});return await I.allReady.catch(()=>{}),await new Response(I).text()});try{let U=await I3(A1(WX.Provider,{value:B,children:A1(QX,{children:[...F,A1(this.root,{data:Y,viewImportMap:$.viewImportMap,viewModules:$.viewModules,serverQueries:z,dictionarySink:Q,rootLayout:G,key:"root"})]})}),{signal:O.signal,progressiveChunkSize:Number.MAX_SAFE_INTEGER,onError:D});await U.allReady.catch(()=>{});let V=XX(await new Response(U).text());return new Response(zX(V,B,$.resolveIsland,Bun.env.NODE_ENV!=="production"),{status:200,headers:X})}finally{clearTimeout(K),j(()=>this.completeStream(Z,z.summarize(O.signal.aborted)))}}async render($){let{req:Z,runInRequestScope:j,csrfTokenHMAC:J,currentPathName:W,headers:Y,i18n:z,params:X,pathname:G,serverQueries:F,userAgent:Q,noStream:O,url:K,user:D,viewData:B,breadcrumbs:U,urlLocaleSegment:V,meta:I,isOgRequest:P,appId:M,features:x,staticView:f}=$,A=G.replace(`/${V}`,""),_={kind:"view",data:{meta:I,pageData:{[A]:B},__csrf:J.toString("base64"),prefetchedData:{},i18n:z,auth:{user:D},routeManifest:this.clientRouteManifest,breadcrumbs:U,router:{urlLocaleSegment:V,pathname:W,params:X,currentPath:G,searchParams:K.search,is404:!W?!0:!1,domain:Z.domain?jB(Z):null},appId:M,features:x,componentTree:[["404",[]],...this.componentTree],...this.staticRoutes.length>0?{staticRoutes:this.staticRoutes}:{}},head:{}},L=this.root,N=this.routeManifest[W];return async(l)=>{let{bootstrapModules:d=[],loaders:E1,getStyles:e,viewImportMap:n,cssManifest:w,ogMap:B0,viewModules:f$,clientEntry:E$,modulePreloadManifest:AZ,assetBase:Q1,resolveIsland:R$}=l,R1=E$?[]:d,$0=(y)=>[y,`window.loaders=${E1}`,...E$?[`import(${JSON.stringify(E$.module)}).catch(function(e){setTimeout(function(){throw e})})`]:[]].join(";");if(P){let y=null,t0=null;for(let v$ of N??[])if(typeof B0[v$]==="function")t0=v$,y=B0[v$];if(!y)return new Response("Not found",{status:404});let jG=Object.values(_.data.pageData)[0];try{await I3(A1(y,jG[t0]),{onError:()=>{}})}catch(v$){let{fonts:JG,...WG}=v$.satoriOptions,YG=await Promise.all(JG.map((N3)=>{return eO(N3.name,N3.weight,N3.style).then((QG)=>({...N3,data:QG}))})),EJ=new Headers(Y);EJ.set("Content-Type","image/png");let[zG,XG]=await Promise.all([rO(),Z8("Rendering an OG image")]),GG=await zG(v$.jsx,{...WG,fonts:YG}),FG=await XG(Buffer.from(GG)).png({compressionLevel:0,effort:10}).toBuffer();return new Response(new Uint8Array(FG),{headers:EJ})}return new Response("data")}if(f&&W)return await this.renderStatic({req:Z,runInRequestScope:j,staticView:f,currentViews:N,data:_.data,serverQueries:F,headers:Y,getStyles:e,viewImportMap:n,viewModules:f$,resolveIsland:R$});if(_.data.cssManifest=w,_.data.modulePreloadManifest=AZ??{},Q1&&Q1!=="/")_.data.assetBase=Q1;let N8=this.modulePreloadLinks({clientEntry:E$,modulePreloadManifest:AZ,views:N??["404"],routeKey:W??"404"}),L8=await e(N);_.data.prefetchedData=F.snapshotResolved(),F.markRenderStart();let r0=new AbortController,b$=setTimeout(()=>r0.abort(),KX),Z$=F8(Q)||O,b1=Bun.env.NODE_ENV!=="production"&&!Z$&&W&&this.shellReporter.shouldObserve(W)?ez():null,R=UJ();try{let y=await I3(A1(QX,{children:[...N8,...L8,A1("script",{key:"theme-script",dangerouslySetInnerHTML:{__html:tO}}),A1(L,{data:_.data,viewImportMap:n,viewModules:f$,serverQueries:F,dictionarySink:R,key:"root"})]}),{bootstrapScriptContent:$0(`window.__GEMI_DATA__ = ${S1(_.data)}`),bootstrapModules:R1,signal:r0.signal,...Z$?{progressiveChunkSize:Number.MAX_SAFE_INTEGER}:{},onError(t0){if(Bun.env.NODE_ENV!=="production")console.error(t0)}});if(y.allReady.catch(()=>{}).finally(()=>clearTimeout(b$)),Z$)await y.allReady.catch(()=>{});return new Response(XJ(y,F,{onShell:Z$?void 0:()=>F.markShell(),onChunk:b1?.onChunk,onClose:()=>j(()=>{if(this.completeStream(Z,F.summarize(r0.signal.aborted)),b1)this.shellReporter.report(W,b1.measure())})},R),{status:!W?$.refusedStatus??404:200,headers:Y})}catch(y){if(clearTimeout(b$),Bun.env.NODE_ENV==="production")throw j(()=>this.completeStream(Z,F.summarize(r0.signal.aborted))),y;let t0=await I3(A1("div"),{bootstrapScriptContent:$0(`window.error= ${S1(y.message)}; window.stack_trace=${S1(y.stack)};window.__GEMI_DATA__ = ${S1(_.data)}`),bootstrapModules:Bun.env.NODE_ENV==="development"?["/render-error.js",...R1]:R1});return new Response(XJ(t0,F,{onClose:()=>j(()=>this.completeStream(Z,F.summarize(r0.signal.aborted)))}),{status:!W?$.refusedStatus??404:200,headers:Y})}}}viewRefusalStatus($,Z,j){if(M3(Z))return 404;if(Z?.kind===_Z){let J=Z.payload?.view?.status;return J===403||J===404?J:null}if(SZ(Z)){if(!j.has(Z))this.hooks.onRequestFail($,Z);return console.error(Z),403}if(Z instanceof x1&&(Z.status===403||Z.status===404))return Z.status;return null}async handleViewRequest($,Z){let j=new URL($.url),J=j.pathname.endsWith(".json"),W=j.pathname.endsWith(".og"),Y=j.pathname.replace(".json","").replace(".og",""),[,z,...X]=Y.split("/"),G=Y,F=null,Q=null,O=T(o),K=U3(this.flatViewRoutes,Y),D=O.isLocaleAware&&this.localeRouting==="prefix"&&!K?.route.middleware.includes(OX);if(D&&O.supportedLocales.includes(z))G=`/${X.join("/")}`,F=z,Q=z;if(D&&!W&&Q===null&&!(Q===null&&K!==null)){let L=BX(z,O.supportedLocales,O.defaultLocale);if(L){let N=X.length?`/${X.join("/")}`:"";return new Response("",{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:`/${L}${N}${J?".json":""}${j.search}`}})}}if(D&&!W){let L=T(o).detectLocale(new S($,{},"view",G));if(Q===null&&L!==O.defaultLocale){let N=j.pathname==="/"?"":j.pathname;return new Response("",{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:`/${L}${N}${j.search}`}})}}G=G.replace("//","/");let U=[],V=[],I=null,P={},M=null,x=!1,f=[],A;try{let L=U3(this.flatViewRoutes,G);if(Q&&L?.route.middleware.includes(OX))L=null;if(L){if(I=L.routePath,P=L.params,U=L.route.exec,V=L.route.middleware,f=L.route.features,x=V.includes("no-stream"),A=L.route.static,J&&this.partialRendering){let N=$.headers.get(WJ),l=yz({flatViewRoutes:this.flatViewRoutes,supportedLocales:T(o).supportedLocales,from:N,origin:j.origin,to:{segments:L.route.segments,params:P,search:j.search}});if(l.startIndex>0)U=U.slice(l.startIndex),M={from:N,carriedViews:l.carriedViews}}}}catch(L){throw L}if(A&&J)return new Response("Not found",{status:404});let _=new S($,P,"view",I);return this.hooks.onRequestStart(_),await C.run(_,async()=>{let L=null,N=C.getStore(),l=HZ.getStore(),d=(w)=>HZ.run(l,()=>C.runWith(N,w));N.serverQueries=new NZ(V3($));let E1=new Set;N.serverQueries.onQueryFail((w)=>{E1.add(w.error);try{d(()=>Promise.resolve(this.hooks.onRequestFail(n,w.error)).catch(()=>{}))}catch{}});let e=GX(A);if(Q){let w=Q.replaceAll("/","");$$.setLocale(w,{cookie:e.locale})}else if(O.isLocaleAware&&!D)N.setLocale(O.defaultLocale);else $$.setLocale(void 0,{cookie:e.locale});let n=N.req;if(e.session)Q8();try{let w=null;try{await T(VZ).runMiddleware(V)}catch(R){if(w=this.viewRefusalStatus(n,R,E1),w===null)throw R}if(w!==null||f.length>0&&!await this.passesFeatureGates(f))I=null,U=[],n.routePath="";let B0=T(o),f$=B0.isEnabled,E$=B0.isLocaleAware,AZ=new S($,n.params),Q1={defaultLocale:B0.defaultLocale,timeZone:B0.detectTimeZone(AZ)};if(E$){let R=null;if(Q)R=Q.replaceAll("/",""),N.setLocale(R);else if(!D)R=N.locale??B0.defaultLocale;else R=B0.detectLocale(AZ),N.setLocale(R);let y=f$?B0.getPageTranslations(R,n.routePath):{};Q1={...Q1,supportedLocales:B0.supportedLocales,currentLocale:R,dictionary:{[R]:y},defaultLocale:B0.defaultLocale,...D?{}:{localeRouting:"off"}}}await DX(Q1.currentLocale??"");let R$;try{R$=await Promise.all(U.map((R)=>R(n)))}catch(R){if(w=this.viewRefusalStatus(n,R,E1),w===null)throw R;I=null,U=[],n.routePath="",R$=[]}let{cookies:R1,headers:$0}=N;if(w!==null)$0.set("Cache-Control","no-store");L={data:R$,cookies:R1,headers:$0,user:N.user,prefetchedData:N.serverQueries.snapshotResolved(),currentPathName:I,params:n.params,urlLocaleSegment:F,meta:N.renderMeta(),appId:T(zJ).id,features:await T(PZ).forClient()};let{params:N8,user:L8}=L,r0={},b$={};for(let R of R$??[]){let[y,t0]=Object.entries(R)?.[0]??[];if(!y||!t0)continue;b$[`${y}:${I}`]=t0.breadcrumb,r0[y]=t0}let Z$=r0.FILE;if(Z$){for(let R of R1)$0.append("Set-Cookie",R.toString());try{await this.onRequestEnd(n)}catch(R){A$.error(R?.message??'Error in "onRequestEnd" event handler',{err:JSON.stringify(R)})}return await w8(Z$,$0)}if(J){$0.set("Content-Type","application/x-ndjson; charset=utf-8"),$0.append("Vary",WJ),R1.forEach((y)=>$0.append("Set-Cookie",y.toString())),await this.hooks.onRequestEnd(n);let R={meta:M&&!N.metadata.touched?null:L.meta,data:{[G]:r0},breadcrumbs:b$,prefetchedData:N.serverQueries.snapshotResolved(),i18n:Q1,features:L.features,is404:!I,appId:L.appId,partial:M};return new Response($X(R,N.serverQueries,void 0,({aborted:y})=>d(()=>this.completeStream(n,N.serverQueries.summarize(y)))),{headers:$0})}if($0.set("Content-Type","text/html; charset=utf-8"),!x&&!(A&&I))$0.append("Vary","User-Agent");let b1=Boolean(A&&I);if(!b1||e.session)Q8();for(let R of R1)$0.append("Set-Cookie",R.toString());if(!b1||e.csrf){let R=Bun.CSRF.generate(process.env.SECRET);$0.append("Set-Cookie",`csrf_token=${R}; HttpOnly; Secure; SameSite=Strict; Expires=${new Date(Date.now()+86400000).toUTCString()}`)}try{await this.onRequestEnd(n,{mintSession:!b1||e.session})}catch(R){A$.error(R?.message??'Error in "onRequestEnd" event handler',{err:JSON.stringify(R)})}if(b1)FX($0,A);return await this.render({req:n,runInRequestScope:d,csrfTokenHMAC:Buffer.from(""),currentPathName:I,headers:$0,i18n:Q1,params:N8,pathname:j.pathname,serverQueries:N.serverQueries,userAgent:$.headers.get("user-agent"),noStream:x,url:j,user:L8,viewData:r0,breadcrumbs:b$,urlLocaleSegment:F,meta:L.meta,appId:L.appId,features:L.features,isOgRequest:W,staticView:I?A:void 0,refusedStatus:w??void 0})}catch(w){if(w.kind===_Z){let B0=J?JB(w.payload.viewData??w.payload.api):DJ(w.payload.view);for(let f$ of N.cookies)B0.headers.append("Set-Cookie",f$.toString());return B0}if(!E1.has(w))this.hooks.onRequestFail(n,w);if(SZ(w))return console.error(w),J?LZ():DJ(KJ());if(w instanceof x1&&w.status===403)return J?LZ():DJ(KJ());throw w}},Z)}}function TJ(){let $=JSON.stringify({error:w1("not_found","Not found",404)});return new Response($,{status:404,headers:{"Content-Type":"application/json","Content-Length":String(Buffer.byteLength($)),"Cache-Control":"no-store"}})}class PX extends A0{routes={"/api-routes":this.get(()=>{let $=T(O8).flatRoutes,Z=[];for(let[j,J]of Object.entries($))for(let[W,Y]of Object.entries(J)){let{exec:z,middleware:X}=Y;Z.push({path:j,method:W,middleware:X})}return Z}),"/view-routes":this.get(()=>{let $=T(P3).flatViewRoutes,Z=[];for(let[j,{middleware:J,viewPath:W}]of Object.entries($))Z.push({path:j,method:"GET",viewPath:W,middleware:J});return Z})}}var WB=new Set([v1,"cookie","content-type","content-length","transfer-encoding","connection","host","user-agent","forwarded"]),YB=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,zB=/^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]*$/;function XB($,Z,j,J){for(let[W,Y]of Object.entries(j.headers??{})){if(Y===void 0||Y===null)continue;let z=W.toLowerCase();if(WB.has(z)||z.startsWith("x-forwarded-"))throw Error(`dispatchAs: credentials may not set the "${W}" header. The access token stays the initiator's, and the request's framing is dispatchAs's own.`);if(J&&z==="authorization")throw Error(`dispatchAs: credentials may not set "Authorization" on a call dispatched as an identity. The caller's token is for the MCP endpoint and is never passed on.`);$.set(W,Y)}for(let[W,Y]of Object.entries(j.cookies??{})){if(Y===void 0||Y===null)continue;if(W===v1)throw Error(`dispatchAs: credentials may not set the "${v1}" cookie. The access token stays the initiator's.`);if(!YB.test(W)||!zB.test(Y))throw Error(`dispatchAs: "${W}" is not a cookie a Cookie header can carry.`);Z.push(`${W}=${Y}`)}}function GB($,Z){let j=$.body.getReader(),J=!1,W=()=>{if(J)return;J=!0;try{Z()}catch(z){console.error(z)}},Y=new ReadableStream({async pull(z){let X;try{X=await j.read()}catch(G){W(),z.error(G);return}if(X.done){W();try{z.close()}catch{}return}try{z.enqueue(X.value)}catch{}},async cancel(z){try{await j.cancel(z)}finally{W()}}},{highWaterMark:0});return new Response(Y,{status:$.status,statusText:$.statusText,headers:$.headers})}function UX($){let{status:Z=400,data:j,headers:J}=$,W=new Headers({"Content-Type":"application/json",...J});if(!W.has("Cache-Control"))W.set("Cache-Control","no-store");return new Response(JSON.stringify(j),{status:Z,headers:W})}function VX($,Z,j){let J=[];Z?.forEach((z,X)=>J.push([X,z]));let W=[...typeof Z?.getSetCookie==="function"?Z.getSetCookie():[],...Array.from(j??[])];if(J.length===0&&W.length===0)return $;let Y=(z)=>{for(let[X,G]of J){if(X.toLowerCase()==="set-cookie")continue;if(!z.has(X))z.set(X,G)}for(let X of W)z.append("Set-Cookie",X)};try{return Y($.headers),$}catch{let z=new Headers($.headers);return Y(z),new Response($.body,{status:$.status,statusText:$.statusText,headers:z})}}class O8{static token="router.api";flatRoutes={};onRequestStart;onRequestEnd;onRequestFail;constructor($){let Z=Qz();this.onRequestStart=$.onRequestStart??Z.onRequestStart,this.onRequestEnd=$.onRequestEnd??Z.onRequestEnd,this.onRequestFail=$.onRequestFail??Z.onRequestFail,this.flatRoutes=p4({"/":$.rootRouter,"/auth":w4,"/__gemi__/services/i18n":k4,"/__gemi__/services/logs":m4,"/__gemi__/services/image":g4,"/__gemi__/debug":PX})}getRouteHandlerAndParams($){let Z=new URL($.url),j=MX(Z.pathname),J={},W;for(let[Y]of Object.entries(this.flatRoutes))try{let z=new URLPattern({pathname:Y});if(z.test({pathname:j})){W=Y,J=z.exec({pathname:j})?.pathname.groups;break}}catch(z){console.error(z)}return{params:J,path:W}}async runRouteMiddleware($,Z){let J=this.flatRoutes[$][Z.rawRequest.method].middleware;try{await T(VZ).runMiddleware(J)}catch(W){if(W.kind===_Z)return UX(W.payload.api);else{if(M3(W))return TJ();if(this.onRequestFail(Z,W),console.error(W),SZ(W))return LZ();throw W}}}async getRouteData($){let Z=this.flatRoutes[$],j=C.getStore(),J=Z[j.req.rawRequest.method].exec??(()=>Promise.resolve({})),W={};try{W=await J()}catch(Y){if(Y.kind===_Z)return UX(Y.payload.api);if(M3(Y))return TJ();if(this.onRequestFail(j.req,Y),console.error(Y),SZ(Y))return LZ();throw Y}return W}isFrameworkRoute($){return $.startsWith("/__gemi__")}async endRequest($,Z,j){let J=async()=>{try{if(!this.isFrameworkRoute(j))await this.onRequestEnd(Z)}catch(W){A$.error(W?.message??'Error in "onRequestEnd" event handler',{err:JSON.stringify(W)})}finally{$.destroy()}};if(!$.hasPendingWork()){await J();return}$.whenIdle().then(J).catch((W)=>{console.error(W)})}isOpenEndedBody($,Z){return $.method!=="HEAD"&&!Z.headers.has("Content-Length")&&Z.body!==null}async handleApiRequest($,Z){let{params:j,path:J}=this.getRouteHandlerAndParams($),W=this.flatRoutes[J];if(!W||!W[$.method])return new Response(JSON.stringify({error:w1("not_found","Not found",404)}),{status:404});let Y=new S($,j,"api",J);if(!this.isFrameworkRoute(J))this.onRequestStart(Y);return await C.run(Y,async()=>{let z=C.getStore(),X=!1,G=async()=>{X=!0,await this.endRequest(z,Y,J)};try{let F=T(o);if(F.isEnabled){let U=F.detectLocale(Y);z.setLocale(U)}z.setRequest(Y),T(VZ).applyDefaultBodyLimit($);let Q=await this.runRouteMiddleware(J,Y);if(Q instanceof Response){let U=VX(Q,z.headers,z.cookies);return await G(),U}let O=await this.getRouteData(J),K=z.headers,D=z.cookies;if(O instanceof Response){let U=VX(O,K,D);if(this.isOpenEndedBody($,U)){let V=GB(U,()=>this.endRequest(z,Y,J));return X=!0,V}return await G(),U}let B=(q$(O)?O:j$.json(O)).toResponse(K,D);return await G(),B}catch(F){if(!X)try{await G()}catch(Q){console.error(Q)}throw F}},Z)}async dispatchAs($,Z,j,J,W){let Y=new URL($.rawRequest.url).origin,z=new URL(`${Y}/api${j}`),X=`/api${j.split(/[?#]/)[0]}`;if(!j.startsWith("/")||z.origin!==Y||z.pathname!==X||z.hash!==""||z.pathname.startsWith("/api/__gemi__")||z.pathname==="/api/auth"||z.pathname.startsWith("/api/auth/"))throw Error(`dispatchAs: "${j}" is not an app api path. Pass the route's own path, without "/api", with every param encoded.`);let G=W?.identity;if(G!==void 0&&(typeof G!=="object"||!G?.user))throw Error("dispatchAs: identity needs the user to dispatch as.");let F=new Headers,Q=[],O=G?null:$.cookies.get(v1);if(O)Q.push(`${v1}=${O}`);if(W?.credentials)XB(F,Q,W.credentials,G!==void 0);if(Q.length>0)F.set("Cookie",Q.join("; "));let K=G?null:$.headers.get(v1);if(K)F.set(v1,K);let D=$.headers.get("User-Agent");if(D)F.set("User-Agent",D);let B;if(J instanceof FormData)B=J;else if(J!==void 0)F.set("Content-Type","application/json"),B=JSON.stringify(J);let U=new Request(z,{method:Z,headers:F,body:B,...W?.signal?{signal:W.signal}:{}});if(TX(U,g$($),G?.grant,W?.progress),$.domain)CZ(U,$.domain);let V=G?{user:G.user}:void 0;return C.exit(()=>IX.exit(()=>this.handleApiRequest(U,V)))}}import{timingSafeEqual as FB}from"crypto";var D8="",PJ="*",QB=60000,KB=1e4,IJ=/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/,B8=16,NX=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,MJ="x-forwarded-host";function LX($){return $.startsWith(":")}function NJ($,Z){if($===null)return!1;let j=Buffer.from($,"utf8"),J=Buffer.from(Z,"utf8");return j.length===J.length&&FB(j,J)}function OB($){if(!$)return null;if($===!0)return{header:MJ,secret:null};return{header:($.hostHeader??MJ).toLowerCase(),secret:$.secret?{header:$.secret.header.toLowerCase(),value:$.secret.value}:null}}function BB($){if(!$||$===!0)return;let{hostHeader:Z,secret:j}=$;if(Z!==void 0&&(typeof Z!=="string"||!NX.test(Z)))throw Error(`\`route.domains.trustProxy.hostHeader\` must be a single header name, e.g. "x-forwarded-host". Got ${JSON.stringify(Z)}.`);if(!j)return;if(typeof j.header!=="string"||!NX.test(j.header))throw Error(`\`route.domains.trustProxy.secret.header\` must be a header name. Got "${j.header}".`);if(j.header.toLowerCase()===(Z??MJ).toLowerCase())throw Error("`route.domains.trustProxy.secret.header` names the same header as `hostHeader`; the secret needs a header of its own.");if(typeof j.value!=="string"||j.value.length<B8)throw Error(`\`route.domains.trustProxy.secret.value\` must be at least ${B8} characters. A guessable one lets any client name its own host.`)}function F1($){if(!$)return null;try{return new URL(`http://${$.trim()}`).hostname.toLowerCase().replace(/\.$/,"")||null}catch{return null}}function DB($){try{let Z=new URL(`http://${$.trim()}`),j=Z.hostname.toLowerCase().replace(/\.$/,"");return j?Z.port?`${j}:${Z.port}`:j:null}catch{return null}}function UB($){let Z=F1($.root),j=$.root?.trim().toLowerCase().replace(/\.$/,"");if(!Z||Z!==j||!Z.split(".").every((Y)=>IJ.test(Y)))throw Error(`\`route.domains.root\` must be a bare hostname, e.g. "example.com" \u2014 no scheme, port or path. Got "${$.root}".`);if($.custom&&($.custom.cacheTtlMs??0)<0)throw Error(`\`route.domains.custom.cacheTtlMs\` is ${$.custom.cacheTtlMs}; it cannot be negative. Use 0 to disable the cache.`);if($.ask&&$.ask.secret.length<B8)throw Error(`\`route.domains.ask.secret\` must be at least ${B8} characters. A guessable one is worse than leaving \`ask\` out.`);BB($.trustProxy);let J=new Set,W=null;for(let Y of $.groups??[]){let{subdomain:z}=Y;if(J.has(z))throw Error(`\`route.domains\` declares the subdomain "${z}" twice.`);if(J.add(z),LX(z)){if(!/^:[A-Za-z_][A-Za-z0-9_]*$/.test(z))throw Error(`"${z}" is not a valid param subdomain. It must be a single \`:name\` label.`);if(W)throw Error(`\`route.domains\` declares two param subdomains, "${W.subdomain}" and "${z}"; a host could match either.`);W=Y;continue}if(Y.exists)throw Error(`The subdomain "${z}" is fixed, so \`exists\` has no param to check. It only applies to a \`:param\` subdomain.`);if(!z.split(".").every((X)=>IJ.test(X)))throw Error(`"${z}" is not a valid subdomain.`)}if($.custom&&!J.has($.custom.group))throw Error(`\`route.domains.custom.group\` is "${$.custom.group}", but no group declares that subdomain.`);if($.ask&&W&&!W.exists)throw Error(`\`route.domains.ask\` is set, so "${W.subdomain}" needs an \`exists\` to say which tenants are real. Without one every host under the root would be approved for a certificate.`)}class LJ{root;hostTrust;fixed=new Map;param=null;custom;cacheTtlMs;cache=new Map;inFlight=new Map;askSecret;proxySecretHeader;constructor($){UB($),this.root=F1($.root),this.hostTrust=OB($.trustProxy);for(let Z of $.groups??[])if(LX(Z.subdomain))this.param={...Z,name:Z.subdomain.slice(1)};else this.fixed.set(Z.subdomain.toLowerCase(),Z);this.custom=$.custom??null,this.cacheTtlMs=this.custom?.cacheTtlMs??QB,this.askSecret=$.ask?.secret??null,this.proxySecretHeader=this.hostTrust?.secret?.header??null}forwardedHost($){let Z=this.hostTrust;if(!Z)return null;if(Z.secret&&!NJ($.headers.get(Z.secret.header),Z.secret.value))return null;return $.headers.get(Z.header)?.split(",")[0]?.trim()||null}hostOf($){return F1(this.forwardedHost($))??F1(new URL($.url).host)}publicOrigin($){let Z=new URL($.url),j=$.headers.get("x-forwarded-proto")?.split(",")[0]?.trim(),J=j==="http"||j==="https"?j:Z.protocol.replace(/:$/,""),W=this.forwardedHost($),Y=W&&F1(W)?DB(W):null;return`${J}://${Y??Z.host}`}async resolve($){let Z=this.hostOf($);if(!Z)return null;let j=await this.match(Z,$);if(j)return j;if(this.custom?.fallback&&!this.isUnderRoot(Z))return{host:Z,group:PJ,params:{},custom:!0};return null}async allows($,Z){let j=F1($);return j?await this.match(j,Z)!==null:!1}isUnderRoot($){return $===this.root||$.endsWith(`.${this.root}`)}async match($,Z){if($===this.root)return{host:$,group:D8,params:{},custom:!1};if($.endsWith(`.${this.root}`)){let J=$.slice(0,-(this.root.length+1)),W=this.fixed.get(J);if(W)return{host:$,group:W.subdomain,params:{},custom:!1};if(this.param&&IJ.test(J)){let Y={[this.param.name]:J};if(this.param.exists&&!await this.param.exists(Y,Z))return null;return{host:$,group:this.param.subdomain,params:Y,custom:!1}}return null}if(!this.custom)return null;let j=await this.resolveCustom($);return j?{host:$,group:this.custom.group,params:j,custom:!0}:null}async resolveCustom($){let Z=Date.now(),j=this.cache.get($);if(j&&j.expiresAt>Z)return this.cache.delete($),this.cache.set($,j),j.value;let J=this.inFlight.get($);if(J)return J;let W=(async()=>await this.custom.resolve($)??null)();this.inFlight.set($,W);let Y;try{Y=await W}finally{this.inFlight.delete($)}if(this.cacheTtlMs>0){if(this.cache.size>=KB)this.cache.delete(this.cache.keys().next().value);this.cache.delete($),this.cache.set($,{value:Y,expiresAt:Date.now()+this.cacheTtlMs})}return Y}forget($){if($===void 0)this.cache.clear();else{let Z=F1($);if(Z)this.cache.delete(Z)}}}var VB="/__gemi__/domains/ask";class a0{static token="router.domains";resolver;acceptsCustomDomains;groups=new Map;constructor($,Z){this.groups.set(D8,$);let{domains:j}=Z;if(this.acceptsCustomDomains=Boolean(j?.custom),!j){this.resolver=null;return}this.resolver=new LJ(j);let J=(W)=>({api:W.api?new O8({...Z.api,...W.api}):$.api,view:W.view?new P3({...Z.view,...W.view}):$.view});for(let W of j.groups??[])this.groups.set(W.subdomain,J(W));if(j.custom?.fallback)this.groups.set(PJ,J(j.custom.fallback))}async route($){if(!this.resolver)return this.dispatchers(null);if(this.resolver.proxySecretHeader)HX($,this.resolver.proxySecretHeader);let Z=await this.resolver.resolve($);if(!Z)return null;return CZ($,Z),this.dispatchers(Z)}async ask($){if(!this.resolver?.askSecret||$.method!=="GET")return null;let Z=new URL($.url);if(Z.pathname!==VB)return null;if(!NJ(Z.searchParams.get("secret"),this.resolver.askSecret))return null;let j=Z.searchParams.get("domain"),J=j?await this.resolver.allows(j,$):!1;return new Response(null,{status:J?200:404})}dispatchers($){return this.groups.get($?.group??D8)}viewDispatchers(){return Array.from(new Set(Array.from(this.groups.values(),($)=>$.view)))}viewGroups(){let $=new Set,Z=[];for(let[j,J]of this.groups){if($.has(J.view))continue;$.add(J.view),Z.push({group:j,view:J.view})}return Z}}function U8($){let Z=new Date($??0).getTime();return Number.isFinite(Z)?Z:0}var CX=600000;function _X($,Z){return[v3($,Z),v3($,Z-1)]}class E{static token="auth";config;provider;constructor($={},Z=new Zj){this.config={...V8(m5($),$),emailCode:e8($.emailCode)},this.provider=Z}get userProvider(){return this.provider}accessTokenCookieOptions($,Z){return{expires:Z,secure:this.publicOrigin($).startsWith("https://"),httpOnly:!0,domain:this.cookieDomain($)}}publicOrigin($){let Z=T().bound(a0)?T(a0).resolver:null;return Z?Z.publicOrigin($.rawRequest):new URL($.rawRequest.url).origin}cookieDomain($){let Z=this.config.cookieDomain;if(!Z)return;let j=Z==="root"?T(a0).resolver?.root:F1(Z);if(!j)throw Error('`auth.cookieDomain` is "root", but `route.domains` is not configured.');let J=$.domain?.host??F1(new URL($.rawRequest.url).host);return J===j||J?.endsWith(`.${j}`)?j:void 0}async getSession($,Z){if(!$)return null;if(!s8($))return this.config.migrateLegacySession?this.convertLegacySession($,Z,this.config.migrateLegacySession):null;let j=await this.userProvider.findSession({token:$,userAgent:Z});if(!j?.user)return null;let J=Date.now(),W=U8(j.expiresAt),Y=U8(j.absoluteExpiresAt);if(W<=J||Y<=J)return await this.userProvider.deleteSession({token:$}),null;let X=await this.slideSession(j,J);return X.user.extension=await this.config.extendSession(X.user),X}async convertLegacySession($,Z,j){let J=C.getStore()?.req;if(!J)return null;let W=Date.now(),Y=Math.floor(W/CX),z=null,X=await this.userProvider.findSession({token:$,userAgent:Z});if(X?.user){if(!await j(X,{token:$,req:J,userAgent:Z}))return null;let F=v3($,Y),Q=X.user.id;if(await this.userProvider.withLegacySessionLock($,async()=>{if(!await this.userProvider.claimLegacySession({token:$}))return!1;return await this.userProvider.createSessionV2({token:F,userId:Q,userAgent:Z,...this.freshLifetime(W)}),!0}))z=F}if(!z){for(let F of _X($,Y))if((await this.userProvider.findSession({token:F,userAgent:Z}))?.user){z=F;break}}if(!z)return null;let G=await this.getSession(z,Z);if(G)J.ctx().setCookie("access_token",z,this.accessTokenCookieOptions(J,new Date(G.expiresAt)));return G}async revokeSession($,Z){if(!$)return await this.userProvider.deleteSession({token:$}),null;if(s8($)||!this.config.migrateLegacySession){let W=await this.userProvider.findSession({token:$,userAgent:Z});return await this.userProvider.deleteSession({token:$}),W}let j=Math.floor(Date.now()/CX),J=_X($,j);return this.userProvider.withLegacySessionLock($,async()=>{let W=await this.userProvider.findSession({token:$,userAgent:Z});for(let Y of J){if(W?.user)break;W=await this.userProvider.findSession({token:Y,userAgent:Z})}await this.userProvider.deleteSession({token:$});for(let Y of J)await this.userProvider.deleteSession({token:Y});return W})}requestCarryingCookie($){let Z=C.getStore()?.req;return Z?.cookies.get("access_token")===$?Z:null}async slideSession($,Z){let j=this.config.sessionExpiresInHours*3600000;if(new Date($.expiresAt).getTime()-Z>=j/2)return $;let J=new Date(Math.min(Z+j,new Date($.absoluteExpiresAt).getTime())),W=await this.userProvider.updateSession({token:$.token,expiresAt:J}),Y=this.requestCarryingCookie($.token);if(Y)Y.ctx().setCookie("access_token",$.token,this.accessTokenCookieOptions(Y,J));if(!W)return $;return{...$,expiresAt:W.expiresAt??J}}freshLifetime($){return{expiresAt:new Date($+this.config.sessionExpiresInHours*3600000),absoluteExpiresAt:new Date($+this.config.sessionAbsoluteExpiresInHours*3600000)}}async generateMagicLink($){}async upsertSession($){await this.userProvider.findSession({token:"",userAgent:""})}async authenticate($){try{let Z=await this.userProvider.findUserByEmailAddress($,!1);if(!Z)throw Error(`User not found with email: ${$}`);let j=await this.createOrUpdateSession({email:$,id:Z.id}),J=new S;if(J.ctx().setCookie("access_token",j.token,this.accessTokenCookieOptions(J,j.expiresAt)),j?.user)j.user.extension=await this.config.extendSession(j.user);return j}catch(Z){console.log(Z)}}async createOrUpdateSessionV2($){let Z=await this.createOrUpdateSession($),j=null;if(Z?.user)j=await this.config.extendSession(Z.user),Z.user.extension=j;return Z}async createOrUpdateSession($){let Z=new S,j=$.id??(await this.userProvider.findUserByEmailAddress($.email,!1))?.id;if(!j)throw new J$;let J=Bun.env.NODE_ENV==="development"?"local":Z.headers.get("User-Agent"),W=A5(j),Y=await this.userProvider.createSessionV2({token:W,userId:j,userAgent:J,...this.freshLifetime(Date.now())}),z=await this.userProvider.findSession({token:W,userAgent:J??""});return z?.user?z:Y}async createMagicLinkToken($){let Z=await this.userProvider.findUserByEmailAddress($,!1);if(Z){let{pin:j,token:J}=await this.issueOneTimeCode($,6);return{user:Z,email:$,pin:j,token:J}}return{}}async issueOneTimeCode($,Z){await this.userProvider.deleteMagicLinkToken($);let j=await this.config.generateMagicLinkToken($),J=await this.config.generateCode($),W=typeof J==="string"&&J!==""?J:k5(Z);return await this.userProvider.createMagicLinkToken({email:$,token:w3("link",$,j),pin:w3("pin",$,W)}),{email:$,pin:W,token:j}}async verifyOneTimeCode($,Z,j={}){let{expiresInMinutes:J,maxAttempts:W}=this.config.emailCode,Y=await this.userProvider.findMagicLinkTokenByEmail($);if(!Y)return kZ("pin",$,null,Z),{status:"invalid"};let z=U8(Y.createdAt);if(z+J*60000<=Date.now())return kZ("pin",$,null,Z),{status:"expired"};if(!await g5(Y.id,z,W,J))return await this.userProvider.claimMagicLinkToken(Y.id),{status:"too_many_attempts"};if(!kZ("pin",$,Y.pin,Z))return{status:"invalid"};if(j.claim!==!1&&!await this.userProvider.claimMagicLinkToken(Y.id))return{status:"invalid"};return{status:"ok",row:Y}}async verifyMagicLinkToken($,Z){let j=await this.userProvider.findMagicLinkTokenByEmail($),J=kZ("link",$,j?.token,Z);if(!j||!J)return!1;if(U8(j.createdAt)+this.config.emailCode.linkExpiresInMinutes*60000<=Date.now())return!1;return await this.userProvider.claimMagicLinkToken(j.id)}}class X1 extends c{static getFacadeAccessor(){return E}static async user(){let $=C.getStore(),Z=$?.user;if(!Z){if(Z=await S3(this.getFacadeRoot(),$?.req),Z)$?.setUser(Z)}if(Z)return Z;throw new J$({redirectTo:_3($?.req,this.getFacadeRoot().config.signInPath)})}static intendedUrl($){let Z=C.getStore()?.req;return U1(Z?.search.get(D1),$??this.getFacadeRoot().config.redirectPath)}static async guard($){let Z=await X1.user();if(!await $(Z))throw new m$}static async guardSafe($){let Z=await X1.user();try{return await $(Z)}catch(j){return!1}}static async authenticate($){return await this.getFacadeRoot().authenticate($)}static async createMagicLink($){return await this.getFacadeRoot().createMagicLinkToken($)}}class T8{static ensure($,Z={}){let j=C.getStore();if(j.req.kind==="api")throw Error("Query.prefetch() cannot be called from an API request");return j.serverQueries??=new NZ(V3(j.req.rawRequest)),j.serverQueries.ensure($,Z,"prefetch")}static async instant($,...Z){let j=T8.ensure($,Z[0]);if(await j.promise,j.status==="rejected")throw j.error;return j.data}static prefetch($,...Z){T8.ensure($,Z[0])}static noPrefetch(){let $=C.getStore();if($.req.kind==="api")throw Error("Query.noPrefetch() cannot be called from an API request");$.serverQueries??=new NZ(V3($.req.rawRequest)),$.serverQueries.muteDiscoveryHints()}}function SX($,Z,j="/"){let J=new URL($.origin),W=Z.host?Z.host:Z.subdomain?`${Z.subdomain}.${$.root}`:$.root,Y=new URL(j.startsWith("/")?j:`/${j}`,J),z=TB(W);if(!z)throw Error(`"${W}" is not a hostname, so there is no URL for it. Give a bare host, optionally with a port \u2014 no scheme, path or credentials.`);if(Y.hostname=z.hostname,z.port)Y.port=z.port;return Y.toString()}function TB($){try{let Z=new URL(`http://${$.trim()}`);return Z.host===$.trim().toLowerCase()&&Z.pathname==="/"?{hostname:Z.hostname,port:Z.port}:null}catch{return null}}class xX{static absolute($,...Z){return`${process.env.HOST_NAME}${G0(String($),Z[0]??{})}`}static relative($,...Z){return G0(String($),Z[0]??{})}static forDomain($,Z,...j){let J=T(a0).resolver;if(!J)throw Error("`Url.forDomain` needs `route.domains` to be configured.");let W=C.getStore()?.req?.rawRequest,Y=W?J.publicOrigin(W):process.env.HOST_NAME;if(!Y)throw Error("`Url.forDomain` outside a request needs `HOST_NAME` for the protocol.");return SX({root:J.root,origin:Y},$,G0(String(Z),j[0]??{}))}}class AX{name="Meta";static description($){C.getStore().metadata.description($)}static title($){C.getStore().metadata.title($)}static openGraph($){C.getStore().metadata.openGraph($)}static htmlAttributes($){C.getStore().metadata.htmlAttributes($)}static canonical($){C.getStore().metadata.canonical($)}static alternates($){C.getStore().metadata.alternates($)}static fonts($){C.getStore().metadata.fonts($)}}var IB={set($,Z,j){C.getStore().setCookie($,Z,j)},setIfAbsent($,Z,j){if(C.getStore().req.cookies.has($))return!1;return C.getStore().setCookie($,Z,j),!0},delete($,Z){C.getStore().deleteCookie($,Z)}};class f1 extends c{static getFacadeAccessor(){return fX}static get client(){return this.getFacadeRoot().client}static get($){return f1.client.get($)}static set($,Z){return f1.client.set($,Z)}static del(...$){return f1.client.del(...$)}static exists($){return f1.client.exists($)}static incr($){return f1.client.incr($)}static expire($,Z){return f1.client.expire($,Z)}static ttl($){return f1.client.ttl($)}}class EX extends c{static getFacadeAccessor(){return e0}static consume($,Z={}){return this.getFacadeRoot().consume($,Z)}}class bX extends c{static getFacadeAccessor(){return RX}static run($,Z,j){return this.getFacadeRoot().run($,Z,j)}static acquire($,Z={}){return this.getFacadeRoot().acquire($,Z)}}class wX extends c{static getFacadeAccessor(){return vX}static encrypt($){return this.getFacadeRoot().encrypt($)}static decrypt($){return this.getFacadeRoot().decrypt($)}static needsReencryption($){return this.getFacadeRoot().needsReencryption($)}}class kX extends c{static getFacadeAccessor(){return D3}static for($,Z){return this.getFacadeRoot().for($,Z)}static list($){return this.getFacadeRoot().list($)}static save($,Z,j){return this.getFacadeRoot().save($,Z,j)}static fake($={}){return this.getFacadeRoot().fake($)}static restore(){this.getFacadeRoot().restore()}}function ON($){return $}function qX(){return{driver:"memory",pollInterval:30000,maxSubscriptions:1e4,batchSize:100,keepaliveInterval:5000}}function I8($){let Z=new URLSearchParams;for(let[j,J]of $)Z.append(j,String(J));return Z.toString()}function HJ($){let Z=new Map;if(!$)return Z;let j;try{j=new URLSearchParams($)}catch{return Z}for(let[J,W]of j){let Y=Number(W);if(W!==""&&Number.isSafeInteger(Y)&&Y>=0)Z.set(J,Y)}return Z}var{SQL:MB}=globalThis.Bun;function PB(){return Bun.semver.satisfies(Bun.version,">=1.4.0")}var NB=async($)=>{let Z=new MB($,{max:1,idleTimeout:0,maxLifetime:0});return{listen:(j,J,W)=>Z.listen(j,J,W),close:()=>Z.close({timeout:1})}},LB=async($)=>{let Z;try{Z=(await import("./chunk-33s2xqv1.js")).default}catch(J){throw Error("The change feed's database driver needs a Postgres client that can LISTEN: Bun 1.4 or later, or the `postgres` package (bun add postgres).",{cause:J})}let j=Z($,{max:1,idle_timeout:0,max_lifetime:null,fetch_types:!1,onnotice:()=>{}});return{listen:(J,W,Y)=>j.listen(J,W,Y),close:()=>j.end({timeout:1}).catch(()=>{})}},yX=($)=>PB()?NB($):LB($);var HB=/^[A-Za-z_][A-Za-z0-9_]*$/;class CJ{headsTable;entriesTable;notifyChannel;sql;dialect;connection;url;retain;listener;sqliteTurn=Promise.resolve();constructor($,Z={}){if($.dialect!=="postgres"&&$.dialect!=="sqlite")throw Error(`The change feed's database driver supports Postgres and SQLite, not ${$.dialect}.`);let j=Z.headsTable??"gemi_change_heads",J=Z.entriesTable??"gemi_changes",W=Z.notifyChannel??"gemi_changes";for(let z of[j,J,W])if(!HB.test(z))throw Error(`"${z}" is not a plain identifier. Use letters, digits and underscores.`);let Y=Z.retain??1000;if(!Number.isInteger(Y)||Y<1)throw Error(`The change feed's retain must be a whole number, 1 or more; got ${Y}.`);this.headsTable=j,this.entriesTable=J,this.notifyChannel=W,this.sql=$.sql,this.dialect=$.dialect,this.connection=$.name,this.url=$.url,this.retain=Y,this.listener=Z.listener??yX}async createTable(){for(let $ of CB(this.headsTable,this.entriesTable))await this.sql.unsafe($)}joinsTransaction(){return this.transaction()!==void 0}publish($,Z){let j=this.transaction();if(!j){let W=()=>this.sql.begin((z)=>this.append(z,$,Z));if(this.dialect!=="sqlite")return W();let Y=this.sqliteTurn.then(W);return this.sqliteTurn=Y.catch(()=>{}),Y}let J=this.append(j,$,Z);return gX(J),J}async append($,Z,j){let J=$.unsafe(`"${this.headsTable}"`),W=$.unsafe(`"${this.entriesTable}"`),[Y]=await $`
26
+ `;async function eO($,Z,j){let J=`${j==="italic"?"italic,":""}wght@${j==="italic"?"1,":""}${Z}`,z=(await(await fetch(`https://fonts.googleapis.com/css2?family=${$}:${J}&display=swap`,{headers:{"User-Agent":"Mozilla/5.0 Firefox/1.0"}})).text()).match(/url\(([^)]+)\)/)?.[1];return await fetch(z).then((X)=>X.arrayBuffer())}var VJ="/assets";function $B($){return $===VJ||$.startsWith(`${VJ}/`)}function ZB($){let Z=$.filter($B);if(Z.length>0){let j=Z.length>1;throw Error(`View route path${j?"s":""} ${Z.map((J)=>`"${J}"`).join(", ")} use${j?"":"s"} the reserved "${VJ}" prefix. The client build output is served from there before the router runs, so the route would never match. Mount it somewhere else.`)}}function jB($){let Z=T(a0).resolver;return{...$.domain,root:Z.root,origin:Z.publicOrigin($.rawRequest)}}function DJ($){let{status:Z=400,error:j}=$;return new Response(j?.message,{...$,status:Z})}function JB($){let{status:Z=400,data:j,directive:J,headers:W}=$;return new Response(JSON.stringify({data:j,directive:J}),{headers:W,status:Z})}class P3{static token="router.view";flatViewRoutes={};routeManifest={};clientRouteManifest={};componentTree=[];flatComponentTree=[];staticRoutes=[];root=null;shellReporter=tz();preloadCache=new WeakMap;hooks;partialRendering;localeRouting;constructor($){let Z=Kz();this.partialRendering=$.partialRendering??Z.partialRendering,this.localeRouting=$.localeRouting??Z.localeRouting,this.hooks={onRequestStart:$.onRequestStart??Z.onRequestStart,onRequestEnd:$.onRequestEnd??Z.onRequestEnd,onRequestFail:$.onRequestFail??Z.onRequestFail,onStreamComplete:$.onStreamComplete??Z.onStreamComplete};let j={"/":$.rootRouter,"/auth":v4};this.flatViewRoutes=J8(j),ZB(Object.keys(this.flatViewRoutes)),this.routeManifest=Y8(j),this.clientRouteManifest=Object.fromEntries(Object.entries(this.routeManifest).filter(([,J])=>J.at(-1)!=="FILE")),this.componentTree=X8(j),this.flatComponentTree=YJ(this.componentTree),this.staticRoutes=Object.entries(this.flatViewRoutes).filter(([,J])=>J.static).map(([J])=>J);for(let J of this.staticRoutes){let W=this.flatViewRoutes[J].static?.layout;if(W&&!this.flatComponentTree.includes(W))this.flatComponentTree.push(W)}this.root=$.root}async passesFeatureGates($){let Z=T(PZ);for(let j of $)if(!await Z.enabled(j))return!1;return!0}async onRequestEnd($,Z={}){if(Z.mintSession!==!1)Q8();return await this.hooks.onRequestEnd($)}completeStream($,Z){let j=(J)=>{A$.error(J?.message??'Error in "onStreamComplete" event handler',{err:JSON.stringify(J)})};try{Promise.resolve(this.hooks.onStreamComplete($,Z)).catch(j)}catch(J){j(J)}}modulePreloadLinks($){let{clientEntry:Z,modulePreloadManifest:j,views:J,routeKey:W}=$,Y=()=>{let G=new Set(Z?.preload??[]);for(let F of J)for(let Q of j?.[F]??[])G.add(Q);return[...G].map((F)=>A1("link",{key:`modulepreload:${F}`,rel:"modulepreload",href:F}))};if(!j)return Y();let z=this.preloadCache.get(j);if(!z||z.clientEntry!==Z)z={clientEntry:Z,byRoute:new Map},this.preloadCache.set(j,z);let X=z.byRoute.get(W);if(!X)X=Y(),z.byRoute.set(W,X);return X}async renderStatic($){let{req:Z,runInRequestScope:j,staticView:J,currentViews:W,data:Y,serverQueries:z,headers:X}=$,G;if(J.layout){if(G=$.viewImportMap[J.layout],!G)throw Error(`The static layout "${J.layout}" was not found. It is a view path: a file at app/views/${J.layout}.tsx whose default export renders the document.`)}let F=await $.getStyles(W,{static:!0,layout:J.layout});z.markRenderStart();let Q=UJ(),O=new AbortController,K=setTimeout(()=>O.abort(),KX),D=(U)=>{if(Bun.env.NODE_ENV!=="production")console.error(U)},B=ZX(async(U,V)=>{let I=await I3(U,{signal:O.signal,identifierPrefix:V,progressiveChunkSize:Number.MAX_SAFE_INTEGER,onError:D});return await I.allReady.catch(()=>{}),await new Response(I).text()});try{let U=await I3(A1(WX.Provider,{value:B,children:A1(QX,{children:[...F,A1(this.root,{data:Y,viewImportMap:$.viewImportMap,viewModules:$.viewModules,serverQueries:z,dictionarySink:Q,rootLayout:G,key:"root"})]})}),{signal:O.signal,progressiveChunkSize:Number.MAX_SAFE_INTEGER,onError:D});await U.allReady.catch(()=>{});let V=XX(await new Response(U).text());return new Response(zX(V,B,$.resolveIsland,Bun.env.NODE_ENV!=="production"),{status:200,headers:X})}finally{clearTimeout(K),j(()=>this.completeStream(Z,z.summarize(O.signal.aborted)))}}async render($){let{req:Z,runInRequestScope:j,csrfTokenHMAC:J,currentPathName:W,headers:Y,i18n:z,params:X,pathname:G,serverQueries:F,userAgent:Q,noStream:O,url:K,user:D,viewData:B,breadcrumbs:U,urlLocaleSegment:V,meta:I,isOgRequest:P,appId:M,features:x,staticView:f}=$,A=G.replace(`/${V}`,""),_={kind:"view",data:{meta:I,pageData:{[A]:B},__csrf:J.toString("base64"),prefetchedData:{},i18n:z,auth:{user:D},routeManifest:this.clientRouteManifest,breadcrumbs:U,router:{urlLocaleSegment:V,pathname:W,params:X,currentPath:G,searchParams:K.search,is404:!W?!0:!1,domain:Z.domain?jB(Z):null},appId:M,features:x,componentTree:[["404",[]],...this.componentTree],...this.staticRoutes.length>0?{staticRoutes:this.staticRoutes}:{}},head:{}},L=this.root,N=this.routeManifest[W];return async(l)=>{let{bootstrapModules:d=[],loaders:E1,getStyles:e,viewImportMap:n,cssManifest:w,ogMap:B0,viewModules:f$,clientEntry:E$,modulePreloadManifest:AZ,assetBase:Q1,resolveIsland:R$}=l,R1=E$?[]:d,$0=(q)=>[q,`window.loaders=${E1}`,...E$?[`import(${JSON.stringify(E$.module)}).catch(function(e){setTimeout(function(){throw e})})`]:[]].join(";");if(P){let q=null,t0=null;for(let v$ of N??[])if(typeof B0[v$]==="function")t0=v$,q=B0[v$];if(!q)return new Response("Not found",{status:404});let jG=Object.values(_.data.pageData)[0];try{await I3(A1(q,jG[t0]),{onError:()=>{}})}catch(v$){let{fonts:JG,...WG}=v$.satoriOptions,YG=await Promise.all(JG.map((N3)=>{return eO(N3.name,N3.weight,N3.style).then((QG)=>({...N3,data:QG}))})),EJ=new Headers(Y);EJ.set("Content-Type","image/png");let[zG,XG]=await Promise.all([rO(),Z8("Rendering an OG image")]),GG=await zG(v$.jsx,{...WG,fonts:YG}),FG=await XG(Buffer.from(GG)).png({compressionLevel:0,effort:10}).toBuffer();return new Response(new Uint8Array(FG),{headers:EJ})}return new Response("data")}if(f&&W)return await this.renderStatic({req:Z,runInRequestScope:j,staticView:f,currentViews:N,data:_.data,serverQueries:F,headers:Y,getStyles:e,viewImportMap:n,viewModules:f$,resolveIsland:R$});if(_.data.cssManifest=w,_.data.modulePreloadManifest=AZ??{},Q1&&Q1!=="/")_.data.assetBase=Q1;let N8=this.modulePreloadLinks({clientEntry:E$,modulePreloadManifest:AZ,views:N??["404"],routeKey:W??"404"}),L8=await e(N);_.data.prefetchedData=F.snapshotResolved(),F.markRenderStart();let r0=new AbortController,b$=setTimeout(()=>r0.abort(),KX),Z$=F8(Q)||O,b1=Bun.env.NODE_ENV!=="production"&&!Z$&&W&&this.shellReporter.shouldObserve(W)?ez():null,R=UJ();try{let q=await I3(A1(QX,{children:[...N8,...L8,A1("script",{key:"theme-script",dangerouslySetInnerHTML:{__html:tO}}),A1(L,{data:_.data,viewImportMap:n,viewModules:f$,serverQueries:F,dictionarySink:R,key:"root"})]}),{bootstrapScriptContent:$0(`window.__GEMI_DATA__ = ${S1(_.data)}`),bootstrapModules:R1,signal:r0.signal,...Z$?{progressiveChunkSize:Number.MAX_SAFE_INTEGER}:{},onError(t0){if(Bun.env.NODE_ENV!=="production")console.error(t0)}});if(q.allReady.catch(()=>{}).finally(()=>clearTimeout(b$)),Z$)await q.allReady.catch(()=>{});return new Response(XJ(q,F,{onShell:Z$?void 0:()=>F.markShell(),onChunk:b1?.onChunk,onClose:()=>j(()=>{if(this.completeStream(Z,F.summarize(r0.signal.aborted)),b1)this.shellReporter.report(W,b1.measure())})},R),{status:!W?$.refusedStatus??404:200,headers:Y})}catch(q){if(clearTimeout(b$),Bun.env.NODE_ENV==="production")throw j(()=>this.completeStream(Z,F.summarize(r0.signal.aborted))),q;let t0=await I3(A1("div"),{bootstrapScriptContent:$0(`window.error= ${S1(q.message)}; window.stack_trace=${S1(q.stack)};window.__GEMI_DATA__ = ${S1(_.data)}`),bootstrapModules:Bun.env.NODE_ENV==="development"?["/render-error.js",...R1]:R1});return new Response(XJ(t0,F,{onClose:()=>j(()=>this.completeStream(Z,F.summarize(r0.signal.aborted)))}),{status:!W?$.refusedStatus??404:200,headers:Y})}}}viewRefusalStatus($,Z,j){if(M3(Z))return 404;if(Z?.kind===_Z){let J=Z.payload?.view?.status;return J===403||J===404?J:null}if(SZ(Z)){if(!j.has(Z))this.hooks.onRequestFail($,Z);return console.error(Z),403}if(Z instanceof x1&&(Z.status===403||Z.status===404))return Z.status;return null}async handleViewRequest($,Z){let j=new URL($.url),J=j.pathname.endsWith(".json"),W=j.pathname.endsWith(".og"),Y=j.pathname.replace(".json","").replace(".og",""),[,z,...X]=Y.split("/"),G=Y,F=null,Q=null,O=T(o),K=U3(this.flatViewRoutes,Y),D=O.isLocaleAware&&this.localeRouting==="prefix"&&!K?.route.middleware.includes(OX);if(D&&O.supportedLocales.includes(z))G=`/${X.join("/")}`,F=z,Q=z;if(D&&!W&&Q===null&&!(Q===null&&K!==null)){let L=BX(z,O.supportedLocales,O.defaultLocale);if(L){let N=X.length?`/${X.join("/")}`:"";return new Response("",{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:`/${L}${N}${J?".json":""}${j.search}`}})}}if(D&&!W){let L=T(o).detectLocale(new S($,{},"view",G));if(Q===null&&L!==O.defaultLocale){let N=j.pathname==="/"?"":j.pathname;return new Response("",{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:`/${L}${N}${j.search}`}})}}G=G.replace("//","/");let U=[],V=[],I=null,P={},M=null,x=!1,f=[],A;try{let L=U3(this.flatViewRoutes,G);if(Q&&L?.route.middleware.includes(OX))L=null;if(L){if(I=L.routePath,P=L.params,U=L.route.exec,V=L.route.middleware,f=L.route.features,x=V.includes("no-stream"),A=L.route.static,J&&this.partialRendering){let N=$.headers.get(WJ),l=qz({flatViewRoutes:this.flatViewRoutes,supportedLocales:T(o).supportedLocales,from:N,origin:j.origin,to:{segments:L.route.segments,params:P,search:j.search}});if(l.startIndex>0)U=U.slice(l.startIndex),M={from:N,carriedViews:l.carriedViews}}}}catch(L){throw L}if(A&&J)return new Response("Not found",{status:404});let _=new S($,P,"view",I);return this.hooks.onRequestStart(_),await C.run(_,async()=>{let L=null,N=C.getStore(),l=HZ.getStore(),d=(w)=>HZ.run(l,()=>C.runWith(N,w));N.serverQueries=new NZ(V3($));let E1=new Set;N.serverQueries.onQueryFail((w)=>{E1.add(w.error);try{d(()=>Promise.resolve(this.hooks.onRequestFail(n,w.error)).catch(()=>{}))}catch{}});let e=GX(A);if(Q){let w=Q.replaceAll("/","");$$.setLocale(w,{cookie:e.locale})}else if(O.isLocaleAware&&!D)N.setLocale(O.defaultLocale);else $$.setLocale(void 0,{cookie:e.locale});let n=N.req;if(e.session)Q8();try{let w=null;try{await T(VZ).runMiddleware(V)}catch(R){if(w=this.viewRefusalStatus(n,R,E1),w===null)throw R}if(w!==null||f.length>0&&!await this.passesFeatureGates(f))I=null,U=[],n.routePath="";let B0=T(o),f$=B0.isEnabled,E$=B0.isLocaleAware,AZ=new S($,n.params),Q1={defaultLocale:B0.defaultLocale,timeZone:B0.detectTimeZone(AZ)};if(E$){let R=null;if(Q)R=Q.replaceAll("/",""),N.setLocale(R);else if(!D)R=N.locale??B0.defaultLocale;else R=B0.detectLocale(AZ),N.setLocale(R);let q=f$?B0.getPageTranslations(R,n.routePath):{};Q1={...Q1,supportedLocales:B0.supportedLocales,currentLocale:R,dictionary:{[R]:q},defaultLocale:B0.defaultLocale,...D?{}:{localeRouting:"off"}}}await DX(Q1.currentLocale??"");let R$;try{R$=await Promise.all(U.map((R)=>R(n)))}catch(R){if(w=this.viewRefusalStatus(n,R,E1),w===null)throw R;I=null,U=[],n.routePath="",R$=[]}let{cookies:R1,headers:$0}=N;if(w!==null)$0.set("Cache-Control","no-store");L={data:R$,cookies:R1,headers:$0,user:N.user,prefetchedData:N.serverQueries.snapshotResolved(),currentPathName:I,params:n.params,urlLocaleSegment:F,meta:N.renderMeta(),appId:T(zJ).id,features:await T(PZ).forClient()};let{params:N8,user:L8}=L,r0={},b$={};for(let R of R$??[]){let[q,t0]=Object.entries(R)?.[0]??[];if(!q||!t0)continue;b$[`${q}:${I}`]=t0.breadcrumb,r0[q]=t0}let Z$=r0.FILE;if(Z$){for(let R of R1)$0.append("Set-Cookie",R.toString());try{await this.onRequestEnd(n)}catch(R){A$.error(R?.message??'Error in "onRequestEnd" event handler',{err:JSON.stringify(R)})}return await w8(Z$,$0)}if(J){$0.set("Content-Type","application/x-ndjson; charset=utf-8"),$0.append("Vary",WJ),R1.forEach((q)=>$0.append("Set-Cookie",q.toString())),await this.hooks.onRequestEnd(n);let R={meta:M&&!N.metadata.touched?null:L.meta,data:{[G]:r0},breadcrumbs:b$,prefetchedData:N.serverQueries.snapshotResolved(),i18n:Q1,features:L.features,is404:!I,appId:L.appId,partial:M};return new Response($X(R,N.serverQueries,void 0,({aborted:q})=>d(()=>this.completeStream(n,N.serverQueries.summarize(q)))),{headers:$0})}if($0.set("Content-Type","text/html; charset=utf-8"),!x&&!(A&&I))$0.append("Vary","User-Agent");let b1=Boolean(A&&I);if(!b1||e.session)Q8();for(let R of R1)$0.append("Set-Cookie",R.toString());if(!b1||e.csrf){let R=Bun.CSRF.generate(process.env.SECRET);$0.append("Set-Cookie",`csrf_token=${R}; HttpOnly; Secure; SameSite=Strict; Expires=${new Date(Date.now()+86400000).toUTCString()}`)}try{await this.onRequestEnd(n,{mintSession:!b1||e.session})}catch(R){A$.error(R?.message??'Error in "onRequestEnd" event handler',{err:JSON.stringify(R)})}if(b1)FX($0,A);return await this.render({req:n,runInRequestScope:d,csrfTokenHMAC:Buffer.from(""),currentPathName:I,headers:$0,i18n:Q1,params:N8,pathname:j.pathname,serverQueries:N.serverQueries,userAgent:$.headers.get("user-agent"),noStream:x,url:j,user:L8,viewData:r0,breadcrumbs:b$,urlLocaleSegment:F,meta:L.meta,appId:L.appId,features:L.features,isOgRequest:W,staticView:I?A:void 0,refusedStatus:w??void 0})}catch(w){if(w.kind===_Z){let B0=J?JB(w.payload.viewData??w.payload.api):DJ(w.payload.view);for(let f$ of N.cookies)B0.headers.append("Set-Cookie",f$.toString());return B0}if(!E1.has(w))this.hooks.onRequestFail(n,w);if(SZ(w))return console.error(w),J?LZ():DJ(KJ());if(w instanceof x1&&w.status===403)return J?LZ():DJ(KJ());throw w}},Z)}}function TJ(){let $=JSON.stringify({error:w1("not_found","Not found",404)});return new Response($,{status:404,headers:{"Content-Type":"application/json","Content-Length":String(Buffer.byteLength($)),"Cache-Control":"no-store"}})}class PX extends A0{routes={"/api-routes":this.get(()=>{let $=T(O8).flatRoutes,Z=[];for(let[j,J]of Object.entries($))for(let[W,Y]of Object.entries(J)){let{exec:z,middleware:X}=Y;Z.push({path:j,method:W,middleware:X})}return Z}),"/view-routes":this.get(()=>{let $=T(P3).flatViewRoutes,Z=[];for(let[j,{middleware:J,viewPath:W}]of Object.entries($))Z.push({path:j,method:"GET",viewPath:W,middleware:J});return Z})}}var WB=new Set([v1,"cookie","content-type","content-length","transfer-encoding","connection","host","user-agent","forwarded"]),YB=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,zB=/^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]*$/;function XB($,Z,j,J){for(let[W,Y]of Object.entries(j.headers??{})){if(Y===void 0||Y===null)continue;let z=W.toLowerCase();if(WB.has(z)||z.startsWith("x-forwarded-"))throw Error(`dispatchAs: credentials may not set the "${W}" header. The access token stays the initiator's, and the request's framing is dispatchAs's own.`);if(J&&z==="authorization")throw Error(`dispatchAs: credentials may not set "Authorization" on a call dispatched as an identity. The caller's token is for the MCP endpoint and is never passed on.`);$.set(W,Y)}for(let[W,Y]of Object.entries(j.cookies??{})){if(Y===void 0||Y===null)continue;if(W===v1)throw Error(`dispatchAs: credentials may not set the "${v1}" cookie. The access token stays the initiator's.`);if(!YB.test(W)||!zB.test(Y))throw Error(`dispatchAs: "${W}" is not a cookie a Cookie header can carry.`);Z.push(`${W}=${Y}`)}}function GB($,Z){let j=$.body.getReader(),J=!1,W=()=>{if(J)return;J=!0;try{Z()}catch(z){console.error(z)}},Y=new ReadableStream({async pull(z){let X;try{X=await j.read()}catch(G){W(),z.error(G);return}if(X.done){W();try{z.close()}catch{}return}try{z.enqueue(X.value)}catch{}},async cancel(z){try{await j.cancel(z)}finally{W()}}},{highWaterMark:0});return new Response(Y,{status:$.status,statusText:$.statusText,headers:$.headers})}function UX($){let{status:Z=400,data:j,headers:J}=$,W=new Headers({"Content-Type":"application/json",...J});if(!W.has("Cache-Control"))W.set("Cache-Control","no-store");return new Response(JSON.stringify(j),{status:Z,headers:W})}function VX($,Z,j){let J=[];Z?.forEach((z,X)=>J.push([X,z]));let W=[...typeof Z?.getSetCookie==="function"?Z.getSetCookie():[],...Array.from(j??[])];if(J.length===0&&W.length===0)return $;let Y=(z)=>{for(let[X,G]of J){if(X.toLowerCase()==="set-cookie")continue;if(!z.has(X))z.set(X,G)}for(let X of W)z.append("Set-Cookie",X)};try{return Y($.headers),$}catch{let z=new Headers($.headers);return Y(z),new Response($.body,{status:$.status,statusText:$.statusText,headers:z})}}class O8{static token="router.api";flatRoutes={};onRequestStart;onRequestEnd;onRequestFail;constructor($){let Z=Qz();this.onRequestStart=$.onRequestStart??Z.onRequestStart,this.onRequestEnd=$.onRequestEnd??Z.onRequestEnd,this.onRequestFail=$.onRequestFail??Z.onRequestFail,this.flatRoutes=p4({"/":$.rootRouter,"/auth":w4,"/__gemi__/services/i18n":k4,"/__gemi__/services/logs":m4,"/__gemi__/services/image":g4,"/__gemi__/debug":PX})}getRouteHandlerAndParams($){let Z=new URL($.url),j=MX(Z.pathname),J={},W;for(let[Y]of Object.entries(this.flatRoutes))try{let z=new URLPattern({pathname:Y});if(z.test({pathname:j})){W=Y,J=z.exec({pathname:j})?.pathname.groups;break}}catch(z){console.error(z)}return{params:J,path:W}}async runRouteMiddleware($,Z){let J=this.flatRoutes[$][Z.rawRequest.method].middleware;try{await T(VZ).runMiddleware(J)}catch(W){if(W.kind===_Z)return UX(W.payload.api);else{if(M3(W))return TJ();if(this.onRequestFail(Z,W),console.error(W),SZ(W))return LZ();throw W}}}async getRouteData($){let Z=this.flatRoutes[$],j=C.getStore(),J=Z[j.req.rawRequest.method].exec??(()=>Promise.resolve({})),W={};try{W=await J()}catch(Y){if(Y.kind===_Z)return UX(Y.payload.api);if(M3(Y))return TJ();if(this.onRequestFail(j.req,Y),console.error(Y),SZ(Y))return LZ();throw Y}return W}isFrameworkRoute($){return $.startsWith("/__gemi__")}async endRequest($,Z,j){let J=async()=>{try{if(!this.isFrameworkRoute(j))await this.onRequestEnd(Z)}catch(W){A$.error(W?.message??'Error in "onRequestEnd" event handler',{err:JSON.stringify(W)})}finally{$.destroy()}};if(!$.hasPendingWork()){await J();return}$.whenIdle().then(J).catch((W)=>{console.error(W)})}isOpenEndedBody($,Z){return $.method!=="HEAD"&&!Z.headers.has("Content-Length")&&Z.body!==null}async handleApiRequest($,Z){let{params:j,path:J}=this.getRouteHandlerAndParams($),W=this.flatRoutes[J];if(!W||!W[$.method])return new Response(JSON.stringify({error:w1("not_found","Not found",404)}),{status:404});let Y=new S($,j,"api",J);if(!this.isFrameworkRoute(J))this.onRequestStart(Y);return await C.run(Y,async()=>{let z=C.getStore(),X=!1,G=async()=>{X=!0,await this.endRequest(z,Y,J)};try{let F=T(o);if(F.isEnabled){let U=F.detectLocale(Y);z.setLocale(U)}z.setRequest(Y),T(VZ).applyDefaultBodyLimit($);let Q=await this.runRouteMiddleware(J,Y);if(Q instanceof Response){let U=VX(Q,z.headers,z.cookies);return await G(),U}let O=await this.getRouteData(J),K=z.headers,D=z.cookies;if(O instanceof Response){let U=VX(O,K,D);if(this.isOpenEndedBody($,U)){let V=GB(U,()=>this.endRequest(z,Y,J));return X=!0,V}return await G(),U}let B=(y$(O)?O:j$.json(O)).toResponse(K,D);return await G(),B}catch(F){if(!X)try{await G()}catch(Q){console.error(Q)}throw F}},Z)}async dispatchAs($,Z,j,J,W){let Y=new URL($.rawRequest.url).origin,z=new URL(`${Y}/api${j}`),X=`/api${j.split(/[?#]/)[0]}`;if(!j.startsWith("/")||z.origin!==Y||z.pathname!==X||z.hash!==""||z.pathname.startsWith("/api/__gemi__")||z.pathname==="/api/auth"||z.pathname.startsWith("/api/auth/"))throw Error(`dispatchAs: "${j}" is not an app api path. Pass the route's own path, without "/api", with every param encoded.`);let G=W?.identity;if(G!==void 0&&(typeof G!=="object"||!G?.user))throw Error("dispatchAs: identity needs the user to dispatch as.");let F=new Headers,Q=[],O=G?null:$.cookies.get(v1);if(O)Q.push(`${v1}=${O}`);if(W?.credentials)XB(F,Q,W.credentials,G!==void 0);if(Q.length>0)F.set("Cookie",Q.join("; "));let K=G?null:$.headers.get(v1);if(K)F.set(v1,K);let D=$.headers.get("User-Agent");if(D)F.set("User-Agent",D);let B;if(J instanceof FormData)B=J;else if(J!==void 0)F.set("Content-Type","application/json"),B=JSON.stringify(J);let U=new Request(z,{method:Z,headers:F,body:B,...W?.signal?{signal:W.signal}:{}});if(TX(U,g$($),G?.grant,W?.progress),$.domain)CZ(U,$.domain);let V=G?{user:G.user}:void 0;return C.exit(()=>IX.exit(()=>this.handleApiRequest(U,V)))}}import{timingSafeEqual as FB}from"crypto";var D8="",PJ="*",QB=60000,KB=1e4,IJ=/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/,B8=16,NX=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,MJ="x-forwarded-host";function LX($){return $.startsWith(":")}function NJ($,Z){if($===null)return!1;let j=Buffer.from($,"utf8"),J=Buffer.from(Z,"utf8");return j.length===J.length&&FB(j,J)}function OB($){if(!$)return null;if($===!0)return{header:MJ,secret:null};return{header:($.hostHeader??MJ).toLowerCase(),secret:$.secret?{header:$.secret.header.toLowerCase(),value:$.secret.value}:null}}function BB($){if(!$||$===!0)return;let{hostHeader:Z,secret:j}=$;if(Z!==void 0&&(typeof Z!=="string"||!NX.test(Z)))throw Error(`\`route.domains.trustProxy.hostHeader\` must be a single header name, e.g. "x-forwarded-host". Got ${JSON.stringify(Z)}.`);if(!j)return;if(typeof j.header!=="string"||!NX.test(j.header))throw Error(`\`route.domains.trustProxy.secret.header\` must be a header name. Got "${j.header}".`);if(j.header.toLowerCase()===(Z??MJ).toLowerCase())throw Error("`route.domains.trustProxy.secret.header` names the same header as `hostHeader`; the secret needs a header of its own.");if(typeof j.value!=="string"||j.value.length<B8)throw Error(`\`route.domains.trustProxy.secret.value\` must be at least ${B8} characters. A guessable one lets any client name its own host.`)}function F1($){if(!$)return null;try{return new URL(`http://${$.trim()}`).hostname.toLowerCase().replace(/\.$/,"")||null}catch{return null}}function DB($){try{let Z=new URL(`http://${$.trim()}`),j=Z.hostname.toLowerCase().replace(/\.$/,"");return j?Z.port?`${j}:${Z.port}`:j:null}catch{return null}}function UB($){let Z=F1($.root),j=$.root?.trim().toLowerCase().replace(/\.$/,"");if(!Z||Z!==j||!Z.split(".").every((Y)=>IJ.test(Y)))throw Error(`\`route.domains.root\` must be a bare hostname, e.g. "example.com" \u2014 no scheme, port or path. Got "${$.root}".`);if($.custom&&($.custom.cacheTtlMs??0)<0)throw Error(`\`route.domains.custom.cacheTtlMs\` is ${$.custom.cacheTtlMs}; it cannot be negative. Use 0 to disable the cache.`);if($.ask&&$.ask.secret.length<B8)throw Error(`\`route.domains.ask.secret\` must be at least ${B8} characters. A guessable one is worse than leaving \`ask\` out.`);BB($.trustProxy);let J=new Set,W=null;for(let Y of $.groups??[]){let{subdomain:z}=Y;if(J.has(z))throw Error(`\`route.domains\` declares the subdomain "${z}" twice.`);if(J.add(z),LX(z)){if(!/^:[A-Za-z_][A-Za-z0-9_]*$/.test(z))throw Error(`"${z}" is not a valid param subdomain. It must be a single \`:name\` label.`);if(W)throw Error(`\`route.domains\` declares two param subdomains, "${W.subdomain}" and "${z}"; a host could match either.`);W=Y;continue}if(Y.exists)throw Error(`The subdomain "${z}" is fixed, so \`exists\` has no param to check. It only applies to a \`:param\` subdomain.`);if(!z.split(".").every((X)=>IJ.test(X)))throw Error(`"${z}" is not a valid subdomain.`)}if($.custom&&!J.has($.custom.group))throw Error(`\`route.domains.custom.group\` is "${$.custom.group}", but no group declares that subdomain.`);if($.ask&&W&&!W.exists)throw Error(`\`route.domains.ask\` is set, so "${W.subdomain}" needs an \`exists\` to say which tenants are real. Without one every host under the root would be approved for a certificate.`)}class LJ{root;hostTrust;fixed=new Map;param=null;custom;cacheTtlMs;cache=new Map;inFlight=new Map;askSecret;proxySecretHeader;constructor($){UB($),this.root=F1($.root),this.hostTrust=OB($.trustProxy);for(let Z of $.groups??[])if(LX(Z.subdomain))this.param={...Z,name:Z.subdomain.slice(1)};else this.fixed.set(Z.subdomain.toLowerCase(),Z);this.custom=$.custom??null,this.cacheTtlMs=this.custom?.cacheTtlMs??QB,this.askSecret=$.ask?.secret??null,this.proxySecretHeader=this.hostTrust?.secret?.header??null}forwardedHost($){let Z=this.hostTrust;if(!Z)return null;if(Z.secret&&!NJ($.headers.get(Z.secret.header),Z.secret.value))return null;return $.headers.get(Z.header)?.split(",")[0]?.trim()||null}hostOf($){return F1(this.forwardedHost($))??F1(new URL($.url).host)}publicOrigin($){let Z=new URL($.url),j=$.headers.get("x-forwarded-proto")?.split(",")[0]?.trim(),J=j==="http"||j==="https"?j:Z.protocol.replace(/:$/,""),W=this.forwardedHost($),Y=W&&F1(W)?DB(W):null;return`${J}://${Y??Z.host}`}async resolve($){let Z=this.hostOf($);if(!Z)return null;let j=await this.match(Z,$);if(j)return j;if(this.custom?.fallback&&!this.isUnderRoot(Z))return{host:Z,group:PJ,params:{},custom:!0};return null}async allows($,Z){let j=F1($);return j?await this.match(j,Z)!==null:!1}isUnderRoot($){return $===this.root||$.endsWith(`.${this.root}`)}async match($,Z){if($===this.root)return{host:$,group:D8,params:{},custom:!1};if($.endsWith(`.${this.root}`)){let J=$.slice(0,-(this.root.length+1)),W=this.fixed.get(J);if(W)return{host:$,group:W.subdomain,params:{},custom:!1};if(this.param&&IJ.test(J)){let Y={[this.param.name]:J};if(this.param.exists&&!await this.param.exists(Y,Z))return null;return{host:$,group:this.param.subdomain,params:Y,custom:!1}}return null}if(!this.custom)return null;let j=await this.resolveCustom($);return j?{host:$,group:this.custom.group,params:j,custom:!0}:null}async resolveCustom($){let Z=Date.now(),j=this.cache.get($);if(j&&j.expiresAt>Z)return this.cache.delete($),this.cache.set($,j),j.value;let J=this.inFlight.get($);if(J)return J;let W=(async()=>await this.custom.resolve($)??null)();this.inFlight.set($,W);let Y;try{Y=await W}finally{this.inFlight.delete($)}if(this.cacheTtlMs>0){if(this.cache.size>=KB)this.cache.delete(this.cache.keys().next().value);this.cache.delete($),this.cache.set($,{value:Y,expiresAt:Date.now()+this.cacheTtlMs})}return Y}forget($){if($===void 0)this.cache.clear();else{let Z=F1($);if(Z)this.cache.delete(Z)}}}var VB="/__gemi__/domains/ask";class a0{static token="router.domains";resolver;acceptsCustomDomains;groups=new Map;constructor($,Z){this.groups.set(D8,$);let{domains:j}=Z;if(this.acceptsCustomDomains=Boolean(j?.custom),!j){this.resolver=null;return}this.resolver=new LJ(j);let J=(W)=>({api:W.api?new O8({...Z.api,...W.api}):$.api,view:W.view?new P3({...Z.view,...W.view}):$.view});for(let W of j.groups??[])this.groups.set(W.subdomain,J(W));if(j.custom?.fallback)this.groups.set(PJ,J(j.custom.fallback))}async route($){if(!this.resolver)return this.dispatchers(null);if(this.resolver.proxySecretHeader)HX($,this.resolver.proxySecretHeader);let Z=await this.resolver.resolve($);if(!Z)return null;return CZ($,Z),this.dispatchers(Z)}async ask($){if(!this.resolver?.askSecret||$.method!=="GET")return null;let Z=new URL($.url);if(Z.pathname!==VB)return null;if(!NJ(Z.searchParams.get("secret"),this.resolver.askSecret))return null;let j=Z.searchParams.get("domain"),J=j?await this.resolver.allows(j,$):!1;return new Response(null,{status:J?200:404})}dispatchers($){return this.groups.get($?.group??D8)}viewDispatchers(){return Array.from(new Set(Array.from(this.groups.values(),($)=>$.view)))}viewGroups(){let $=new Set,Z=[];for(let[j,J]of this.groups){if($.has(J.view))continue;$.add(J.view),Z.push({group:j,view:J.view})}return Z}}function U8($){let Z=new Date($??0).getTime();return Number.isFinite(Z)?Z:0}var CX=600000;function _X($,Z){return[v3($,Z),v3($,Z-1)]}class E{static token="auth";config;provider;constructor($={},Z=new Zj){this.config={...V8(m5($),$),emailCode:e8($.emailCode)},this.provider=Z}get userProvider(){return this.provider}accessTokenCookieOptions($,Z){return{expires:Z,secure:this.publicOrigin($).startsWith("https://"),httpOnly:!0,domain:this.cookieDomain($)}}publicOrigin($){let Z=T().bound(a0)?T(a0).resolver:null;return Z?Z.publicOrigin($.rawRequest):new URL($.rawRequest.url).origin}cookieDomain($){let Z=this.config.cookieDomain;if(!Z)return;let j=Z==="root"?T(a0).resolver?.root:F1(Z);if(!j)throw Error('`auth.cookieDomain` is "root", but `route.domains` is not configured.');let J=$.domain?.host??F1(new URL($.rawRequest.url).host);return J===j||J?.endsWith(`.${j}`)?j:void 0}async getSession($,Z){if(!$)return null;if(!s8($))return this.config.migrateLegacySession?this.convertLegacySession($,Z,this.config.migrateLegacySession):null;let j=await this.userProvider.findSession({token:$,userAgent:Z});if(!j?.user)return null;let J=Date.now(),W=U8(j.expiresAt),Y=U8(j.absoluteExpiresAt);if(W<=J||Y<=J)return await this.userProvider.deleteSession({token:$}),null;let X=await this.slideSession(j,J);return X.user.extension=await this.config.extendSession(X.user),X}async convertLegacySession($,Z,j){let J=C.getStore()?.req;if(!J)return null;let W=Date.now(),Y=Math.floor(W/CX),z=null,X=await this.userProvider.findSession({token:$,userAgent:Z});if(X?.user){if(!await j(X,{token:$,req:J,userAgent:Z}))return null;let F=v3($,Y),Q=X.user.id;if(await this.userProvider.withLegacySessionLock($,async()=>{if(!await this.userProvider.claimLegacySession({token:$}))return!1;return await this.userProvider.createSessionV2({token:F,userId:Q,userAgent:Z,...this.freshLifetime(W)}),!0}))z=F}if(!z){for(let F of _X($,Y))if((await this.userProvider.findSession({token:F,userAgent:Z}))?.user){z=F;break}}if(!z)return null;let G=await this.getSession(z,Z);if(G)J.ctx().setCookie("access_token",z,this.accessTokenCookieOptions(J,new Date(G.expiresAt)));return G}async revokeSession($,Z){if(!$)return await this.userProvider.deleteSession({token:$}),null;if(s8($)||!this.config.migrateLegacySession){let W=await this.userProvider.findSession({token:$,userAgent:Z});return await this.userProvider.deleteSession({token:$}),W}let j=Math.floor(Date.now()/CX),J=_X($,j);return this.userProvider.withLegacySessionLock($,async()=>{let W=await this.userProvider.findSession({token:$,userAgent:Z});for(let Y of J){if(W?.user)break;W=await this.userProvider.findSession({token:Y,userAgent:Z})}await this.userProvider.deleteSession({token:$});for(let Y of J)await this.userProvider.deleteSession({token:Y});return W})}requestCarryingCookie($){let Z=C.getStore()?.req;return Z?.cookies.get("access_token")===$?Z:null}async slideSession($,Z){let j=this.config.sessionExpiresInHours*3600000;if(new Date($.expiresAt).getTime()-Z>=j/2)return $;let J=new Date(Math.min(Z+j,new Date($.absoluteExpiresAt).getTime())),W=await this.userProvider.updateSession({token:$.token,expiresAt:J}),Y=this.requestCarryingCookie($.token);if(Y)Y.ctx().setCookie("access_token",$.token,this.accessTokenCookieOptions(Y,J));if(!W)return $;return{...$,expiresAt:W.expiresAt??J}}freshLifetime($){return{expiresAt:new Date($+this.config.sessionExpiresInHours*3600000),absoluteExpiresAt:new Date($+this.config.sessionAbsoluteExpiresInHours*3600000)}}async generateMagicLink($){}async upsertSession($){await this.userProvider.findSession({token:"",userAgent:""})}async authenticate($){try{let Z=await this.userProvider.findUserByEmailAddress($,!1);if(!Z)throw Error(`User not found with email: ${$}`);let j=await this.createOrUpdateSession({email:$,id:Z.id}),J=new S;if(J.ctx().setCookie("access_token",j.token,this.accessTokenCookieOptions(J,j.expiresAt)),j?.user)j.user.extension=await this.config.extendSession(j.user);return j}catch(Z){console.log(Z)}}async createOrUpdateSessionV2($){let Z=await this.createOrUpdateSession($),j=null;if(Z?.user)j=await this.config.extendSession(Z.user),Z.user.extension=j;return Z}async createOrUpdateSession($){let Z=new S,j=$.id??(await this.userProvider.findUserByEmailAddress($.email,!1))?.id;if(!j)throw new J$;let J=Bun.env.NODE_ENV==="development"?"local":Z.headers.get("User-Agent"),W=A5(j),Y=await this.userProvider.createSessionV2({token:W,userId:j,userAgent:J,...this.freshLifetime(Date.now())}),z=await this.userProvider.findSession({token:W,userAgent:J??""});return z?.user?z:Y}async createMagicLinkToken($){let Z=await this.userProvider.findUserByEmailAddress($,!1);if(Z){let{pin:j,token:J}=await this.issueOneTimeCode($,6);return{user:Z,email:$,pin:j,token:J}}return{}}async issueOneTimeCode($,Z){await this.userProvider.deleteMagicLinkToken($);let j=await this.config.generateMagicLinkToken($),J=await this.config.generateCode($),W=typeof J==="string"&&J!==""?J:k5(Z);return await this.userProvider.createMagicLinkToken({email:$,token:w3("link",$,j),pin:w3("pin",$,W)}),{email:$,pin:W,token:j}}async verifyOneTimeCode($,Z,j={}){let{expiresInMinutes:J,maxAttempts:W}=this.config.emailCode,Y=await this.userProvider.findMagicLinkTokenByEmail($);if(!Y)return kZ("pin",$,null,Z),{status:"invalid"};let z=U8(Y.createdAt);if(z+J*60000<=Date.now())return kZ("pin",$,null,Z),{status:"expired"};if(!await g5(Y.id,z,W,J))return await this.userProvider.claimMagicLinkToken(Y.id),{status:"too_many_attempts"};if(!kZ("pin",$,Y.pin,Z))return{status:"invalid"};if(j.claim!==!1&&!await this.userProvider.claimMagicLinkToken(Y.id))return{status:"invalid"};return{status:"ok",row:Y}}async verifyMagicLinkToken($,Z){let j=await this.userProvider.findMagicLinkTokenByEmail($),J=kZ("link",$,j?.token,Z);if(!j||!J)return!1;if(U8(j.createdAt)+this.config.emailCode.linkExpiresInMinutes*60000<=Date.now())return!1;return await this.userProvider.claimMagicLinkToken(j.id)}}class X1 extends c{static getFacadeAccessor(){return E}static async user(){let $=C.getStore(),Z=$?.user;if(!Z){if(Z=await S3(this.getFacadeRoot(),$?.req),Z)$?.setUser(Z)}if(Z)return Z;throw new J$({redirectTo:_3($?.req,this.getFacadeRoot().config.signInPath)})}static intendedUrl($){let Z=C.getStore()?.req;return U1(Z?.search.get(D1),$??this.getFacadeRoot().config.redirectPath)}static async guard($){let Z=await X1.user();if(!await $(Z))throw new m$}static async guardSafe($){let Z=await X1.user();try{return await $(Z)}catch(j){return!1}}static async authenticate($){return await this.getFacadeRoot().authenticate($)}static async createMagicLink($){return await this.getFacadeRoot().createMagicLinkToken($)}}class T8{static ensure($,Z={}){let j=C.getStore();if(j.req.kind==="api")throw Error("Query.prefetch() cannot be called from an API request");return j.serverQueries??=new NZ(V3(j.req.rawRequest)),j.serverQueries.ensure($,Z,"prefetch")}static async instant($,...Z){let j=T8.ensure($,Z[0]);if(await j.promise,j.status==="rejected")throw j.error;return j.data}static prefetch($,...Z){T8.ensure($,Z[0])}static noPrefetch(){let $=C.getStore();if($.req.kind==="api")throw Error("Query.noPrefetch() cannot be called from an API request");$.serverQueries??=new NZ(V3($.req.rawRequest)),$.serverQueries.muteDiscoveryHints()}}function SX($,Z,j="/"){let J=new URL($.origin),W=Z.host?Z.host:Z.subdomain?`${Z.subdomain}.${$.root}`:$.root,Y=new URL(j.startsWith("/")?j:`/${j}`,J),z=TB(W);if(!z)throw Error(`"${W}" is not a hostname, so there is no URL for it. Give a bare host, optionally with a port \u2014 no scheme, path or credentials.`);if(Y.hostname=z.hostname,z.port)Y.port=z.port;return Y.toString()}function TB($){try{let Z=new URL(`http://${$.trim()}`);return Z.host===$.trim().toLowerCase()&&Z.pathname==="/"?{hostname:Z.hostname,port:Z.port}:null}catch{return null}}class xX{static absolute($,...Z){return`${process.env.HOST_NAME}${G0(String($),Z[0]??{})}`}static relative($,...Z){return G0(String($),Z[0]??{})}static forDomain($,Z,...j){let J=T(a0).resolver;if(!J)throw Error("`Url.forDomain` needs `route.domains` to be configured.");let W=C.getStore()?.req?.rawRequest,Y=W?J.publicOrigin(W):process.env.HOST_NAME;if(!Y)throw Error("`Url.forDomain` outside a request needs `HOST_NAME` for the protocol.");return SX({root:J.root,origin:Y},$,G0(String(Z),j[0]??{}))}}class AX{name="Meta";static description($){C.getStore().metadata.description($)}static title($){C.getStore().metadata.title($)}static openGraph($){C.getStore().metadata.openGraph($)}static htmlAttributes($){C.getStore().metadata.htmlAttributes($)}static canonical($){C.getStore().metadata.canonical($)}static alternates($){C.getStore().metadata.alternates($)}static fonts($){C.getStore().metadata.fonts($)}}var IB={set($,Z,j){C.getStore().setCookie($,Z,j)},setIfAbsent($,Z,j){if(C.getStore().req.cookies.has($))return!1;return C.getStore().setCookie($,Z,j),!0},delete($,Z){C.getStore().deleteCookie($,Z)}};class f1 extends c{static getFacadeAccessor(){return fX}static get client(){return this.getFacadeRoot().client}static get($){return f1.client.get($)}static set($,Z){return f1.client.set($,Z)}static del(...$){return f1.client.del(...$)}static exists($){return f1.client.exists($)}static incr($){return f1.client.incr($)}static expire($,Z){return f1.client.expire($,Z)}static ttl($){return f1.client.ttl($)}}class EX extends c{static getFacadeAccessor(){return e0}static consume($,Z={}){return this.getFacadeRoot().consume($,Z)}}class bX extends c{static getFacadeAccessor(){return RX}static run($,Z,j){return this.getFacadeRoot().run($,Z,j)}static acquire($,Z={}){return this.getFacadeRoot().acquire($,Z)}}class wX extends c{static getFacadeAccessor(){return vX}static encrypt($){return this.getFacadeRoot().encrypt($)}static decrypt($){return this.getFacadeRoot().decrypt($)}static needsReencryption($){return this.getFacadeRoot().needsReencryption($)}}class kX extends c{static getFacadeAccessor(){return D3}static for($,Z){return this.getFacadeRoot().for($,Z)}static list($){return this.getFacadeRoot().list($)}static save($,Z,j){return this.getFacadeRoot().save($,Z,j)}static fake($={}){return this.getFacadeRoot().fake($)}static restore(){this.getFacadeRoot().restore()}}function ON($){return $}function yX(){return{driver:"memory",pollInterval:30000,maxSubscriptions:1e4,batchSize:100,keepaliveInterval:5000}}function I8($){let Z=new URLSearchParams;for(let[j,J]of $)Z.append(j,String(J));return Z.toString()}function HJ($){let Z=new Map;if(!$)return Z;let j;try{j=new URLSearchParams($)}catch{return Z}for(let[J,W]of j){let Y=Number(W);if(W!==""&&Number.isSafeInteger(Y)&&Y>=0)Z.set(J,Y)}return Z}var{SQL:MB}=globalThis.Bun;function PB(){return Bun.semver.satisfies(Bun.version,">=1.4.0")}var NB=async($)=>{let Z=new MB($,{max:1,idleTimeout:0,maxLifetime:0});return{listen:(j,J,W)=>Z.listen(j,J,W),close:()=>Z.close({timeout:1})}},LB=async($)=>{let Z;try{Z=(await import("./chunk-33s2xqv1.js")).default}catch(J){throw Error("The change feed's database driver needs a Postgres client that can LISTEN: Bun 1.4 or later, or the `postgres` package (bun add postgres).",{cause:J})}let j=Z($,{max:1,idle_timeout:0,max_lifetime:null,fetch_types:!1,onnotice:()=>{}});return{listen:(J,W,Y)=>j.listen(J,W,Y),close:()=>j.end({timeout:1}).catch(()=>{})}},qX=($)=>PB()?NB($):LB($);var HB=/^[A-Za-z_][A-Za-z0-9_]*$/;class CJ{headsTable;entriesTable;notifyChannel;sql;dialect;connection;url;retain;listener;sqliteTurn=Promise.resolve();constructor($,Z={}){if($.dialect!=="postgres"&&$.dialect!=="sqlite")throw Error(`The change feed's database driver supports Postgres and SQLite, not ${$.dialect}.`);let j=Z.headsTable??"gemi_change_heads",J=Z.entriesTable??"gemi_changes",W=Z.notifyChannel??"gemi_changes";for(let z of[j,J,W])if(!HB.test(z))throw Error(`"${z}" is not a plain identifier. Use letters, digits and underscores.`);let Y=Z.retain??1000;if(!Number.isInteger(Y)||Y<1)throw Error(`The change feed's retain must be a whole number, 1 or more; got ${Y}.`);this.headsTable=j,this.entriesTable=J,this.notifyChannel=W,this.sql=$.sql,this.dialect=$.dialect,this.connection=$.name,this.url=$.url,this.retain=Y,this.listener=Z.listener??qX}async createTable(){for(let $ of CB(this.headsTable,this.entriesTable))await this.sql.unsafe($)}joinsTransaction(){return this.transaction()!==void 0}publish($,Z){let j=this.transaction();if(!j){let W=()=>this.sql.begin((z)=>this.append(z,$,Z));if(this.dialect!=="sqlite")return W();let Y=this.sqliteTurn.then(W);return this.sqliteTurn=Y.catch(()=>{}),Y}let J=this.append(j,$,Z);return gX(J),J}async append($,Z,j){let J=$.unsafe(`"${this.headsTable}"`),W=$.unsafe(`"${this.entriesTable}"`),[Y]=await $`
27
27
  INSERT INTO ${J} (channel, seq) VALUES (${Z}, 1)
28
28
  ON CONFLICT (channel) DO UPDATE SET seq = ${J}.seq + 1
29
29
  RETURNING seq
@@ -52,6 +52,6 @@ if('system'===e||(!e&&'system'===defaultTheme)){
52
52
  )`]}class _J{logs=new Map;retain;constructor($={}){let Z=$.retain??1000;if(!Number.isInteger(Z)||Z<1)throw Error(`The change feed's retain must be a whole number, 1 or more; got ${Z}.`);this.retain=Z}async publish($,Z){let j=this.logs.get($);if(!j)j={head:0,entries:[]},this.logs.set($,j);let J=++j.head;if(j.entries.push({seq:J,data:Z===void 0?null:structuredClone(Z)}),j.entries.length>this.retain)j.entries.splice(0,j.entries.length-this.retain);return J}async heads($){return new Map($.map((Z)=>[Z,this.logs.get(Z)?.head??0]))}async read($,Z,j){let J=this.logs.get($),W=J?.head??0;if(Z>W)return{entries:[],head:W,gap:!0};if(!J||Z===W)return{entries:[],head:W,gap:!1};let Y=J.entries[0]?.seq??W+1;if(Y>Z+1)return{entries:[],head:W,gap:!0};let z=Z+1-Y;return{entries:J.entries.slice(z,z+j),head:W,gap:!1}}}var dX=new TextEncoder;function mX($,Z){return dX.encode(`id: ${$}
53
53
  data: ${JSON.stringify(Z)}
54
54
 
55
- `)}function uX($,Z,j,J){let W=Z instanceof Request?Z:Z.rawRequest,Y=J.cursor??W.headers.get("Last-Event-ID")??new URL(W.url).searchParams.get("cursor"),z;try{z=$.subscribe(j,{cursor:Y,signal:W.signal})}catch(K){if(!(K instanceof M8))throw K;return new Response(JSON.stringify({error:"The change feed is at capacity."}),{status:503,headers:{"Content-Type":"application/json","Retry-After":String(J.retryAfter??5)}})}let X=null,G=!1,F=!1,Q=(K)=>{if(X)clearInterval(X);if(X=null,z.close(),F)return;F=!0;try{K.close()}catch{}},O=new ReadableStream({start(K){X=setInterval(()=>{if(cX())return Q(K);try{K.enqueue(dX.encode(pX))}catch{Q(K)}},$.config.keepaliveInterval)},async pull(K){try{if(!G){if(await z.ready(),G=!0,!F)K.enqueue(mX(z.cursor,{type:"ready"}));return}let D=await z.next();if(D.done||F)return Q(K);K.enqueue(mX(z.cursor,D.value))}catch(D){if(!F)console.error("[gemi] A change feed stream failed.",D);Q(K)}},cancel(){if(F=!0,X)clearInterval(X);X=null,z.close()}});return new Response(O,{headers:hX()})}var lX=255,iX=500,_B=30000;class M8 extends Error{limit;constructor($){super(`The change feed holds its limit of ${$} subscriptions.`);this.limit=$;this.name="ChangeFeedFullError"}}class fJ{options;static token="changeFeed";driver;config;followers=new Map;all=new Set;listenState="off";listening=null;retryTimer=null;backoffMs=iX;pollTimer=null;polling=null;constructor($={},Z={}){this.options=Z;this.config=V8(qX(),$),this.driver=xB(this.config.driver,Z.application)}get subscriptions(){return this.all.size}get isListening(){return this.listenState==="listening"}async publish($,Z){AJ($);let j=Z===void 0?null:Z;if(V1()!==void 0&&!this.driver.joinsTransaction?.())return xJ(async()=>{this.wake($,await this.driver.publish($,j))}),null;let J=await this.driver.publish($,j);return xJ(()=>this.wake($,J)),J}async head($){return AJ($),(await this.driver.heads([$])).get($)??0}async cursor($){let Z=SJ($);return I8(await this.driver.heads(Z))}subscribe($,Z={}){let j=SJ($);if(this.all.size>=this.config.maxSubscriptions)throw new M8(this.config.maxSubscriptions);let J=new sX(this,j,SB(Z.cursor),this.config,Z.signal);this.all.add(J);for(let W of j){let Y=this.followers.get(W);if(!Y)this.followers.set(W,Y=new Set);Y.add(J)}return this.startListening(),this.startPolling(),J}stream($,Z,j={}){return uX(this,$,SJ(Z),j)}async close(){if(this.listenState="closed",this.retryTimer)clearTimeout(this.retryTimer);this.retryTimer=null,this.stopPolling();for(let Z of this.all)Z.close();let $=this.listening;this.listening=null,await $?.close(),await this.driver.close?.()}forget($){if(!this.all.delete($))return;for(let Z of $.channels){let j=this.followers.get(Z);if(j?.delete($),j?.size===0)this.followers.delete(Z)}if(this.all.size===0)this.stopPolling()}poll(){return this.polling??=(async()=>{try{let $=[...this.followers.keys()];for(let Z=0;Z<$.length;Z+=500){let j=await this.driver.heads($.slice(Z,Z+500));for(let[J,W]of j)this.wake(J,W)}}catch($){console.error("[gemi] The change feed could not read its channels' heads.",$)}finally{this.polling=null}})(),this.polling}startPolling(){if(this.pollTimer)return;this.pollTimer=setInterval(()=>void this.poll(),this.config.pollInterval),this.pollTimer.unref?.()}stopPolling(){if(this.pollTimer)clearInterval(this.pollTimer);this.pollTimer=null}wake($,Z){for(let j of this.followers.get($)??[])j.moved($,Z)}resync(){this.poll()}startListening(){if(this.listenState!=="off"||!this.driver.listen)return;this.connect()}async connect(){this.listenState="connecting",this.retryTimer=null;try{let $=await this.driver.listen((Z,j)=>this.wake(Z,j),()=>this.resync());if(this.listenState!=="connecting"){await $.close();return}this.listening=$,this.listenState="listening",this.backoffMs=iX,this.resync()}catch($){if(this.listenState!=="connecting")return;console.error(`[gemi] The change feed could not listen for other instances' changes; retrying in ${this.backoffMs}ms.`,$),this.listenState="retrying",this.retryTimer=setTimeout(()=>void this.connect(),this.backoffMs),this.retryTimer.unref?.(),this.backoffMs=Math.min(this.backoffMs*2,_B)}}}class sX{manager;config;signal;channels;positions=new Map;readTo=new Map;dirty=new Set;pending=[];started=null;wakeUp=null;closed=!1;onAbort=()=>this.close();constructor($,Z,j,J,W){this.manager=$;this.config=J;this.signal=W;this.channels=Z;for(let Y of Z){let z=j.get(Y);if(z!==void 0)this.positions.set(Y,z),this.readTo.set(Y,z),this.dirty.add(Y)}if(W?.aborted)this.close();else W?.addEventListener("abort",this.onAbort,{once:!0})}get cursor(){return I8(this.positions)}get isClosed(){return this.closed}ready(){return this.started??=(async()=>{let $=this.channels.filter((j)=>!this.positions.has(j));if($.length===0)return;let Z=await this.manager.driver.heads($);for(let j of $){let J=Z.get(j)??0;this.positions.set(j,J),this.readTo.set(j,J)}})(),this.started}async next(){await this.ready();for(;;){if(this.closed)return{done:!0,value:void 0};let $=this.pending.shift();if($)return this.positions.set($.channel,$.seq),{done:!1,value:$};let Z=this.dirty.values().next().value;if(Z!==void 0){await this.read(Z);continue}await this.idle()}}async return(){return this.close(),{done:!0,value:void 0}}[Symbol.asyncIterator](){return this}close(){if(this.closed)return;this.closed=!0,this.pending.length=0,this.signal?.removeEventListener("abort",this.onAbort),this.manager.forget(this),this.wake()}moved($,Z){let j=this.readTo.get($);if(j!==void 0&&Z===j)return;this.dirty.add($),this.wake()}async read($){let Z=this.readTo.get($)??0;this.dirty.delete($);let{batchSize:j}=this.config,{entries:J,head:W,gap:Y}=await this.manager.driver.read($,Z,j);if(this.closed)return;if(Y){this.readTo.set($,W),this.pending.push({type:"reset",channel:$,seq:W});return}for(let z of J)this.readTo.set($,z.seq),this.pending.push({type:"change",channel:$,seq:z.seq,data:z.data});if(J.length===j)this.dirty.add($)}idle(){return new Promise(($)=>{this.wakeUp=$})}wake(){let $=this.wakeUp;this.wakeUp=null,$?.()}}function AJ($){if(typeof $!=="string"||$===""||$.length>lX)throw Error(`A change feed channel is a string of 1 to ${lX} characters; got ${JSON.stringify($)}.`)}function SJ($){let Z=[...new Set(typeof $==="string"?[$]:$)];if(Z.length===0)throw Error("A change feed subscription needs at least one channel.");for(let j of Z)AJ(j);return Z}function SB($){if($===void 0||$===null)return new Map;if(typeof $==="string")return HJ($);let Z=$ instanceof Map?[...$]:Object.entries($);return HJ(I8(new Map(Z)))}function xB($,Z){if($==="memory")return new _J;if($==="database"||typeof $==="function"){if(!Z&&($==="database"||$.length>0))throw Error("The change feed driver needs the application it belongs to, and this ChangeFeedManager was built without one. Pass { application }.");if($==="database")return new CJ(Z.make(X$));return $(Z)}if(typeof $==="string")throw Error(`Unknown change feed driver "${$}". The changeFeed slice's driver is "memory", "database", a ChangeFeedDriver, or a function returning one.`);return $}class nX extends c{static getFacadeAccessor(){return fJ}static publish($,Z){return this.getFacadeRoot().publish($,Z)}static head($){return this.getFacadeRoot().head($)}static cursor($){return this.getFacadeRoot().cursor($)}static subscribe($,Z){return this.getFacadeRoot().subscribe($,Z)}static stream($,Z,j){return this.getFacadeRoot().stream($,Z,j)}}class oX extends c{static getFacadeAccessor(){return PZ}static enabled($){return this.getFacadeRoot().enabled($)}static all(){return this.getFacadeRoot().forClient()}static explain($){return this.getFacadeRoot().explain($)}static for($){return this.getFacadeRoot().for($)}static list(){return this.getFacadeRoot().list()}static set($,Z,j){return this.getFacadeRoot().set($,Z,j)}static refresh(){return this.getFacadeRoot().refresh()}static invalidate(){return this.getFacadeRoot().invalidate()}}class P8{bound;constructor($){this.bound=$}get name(){return this.bound??z$()}get sql(){return this.connection().sql}get dialect(){return this.connection().dialect}async query($){return await this.run($,"query")}async execute($){let Z=await this.run($,"execute");return Number(Z?.count??0)}async transaction($){let Z=this.name,j=this.connection(Z);return tX(j.sql,(J)=>aX(Z,()=>$(J)),{slowTransactionThreshold:j.config.slowTransactionThreshold,connection:Z})}async schema(){let $=this.connection(),{introspect:Z}=await import("./chunk-nrezmscd.js");return Z(this.handle()??$.sql,$.dialect)}run($,Z){let j=this.connection(),{text:J,values:W}=$G($,eX(j.dialect),Z);return(this.handle()??j.sql).unsafe(J,W)}handle(){let $=V1();if($===void 0)return;return z$()===this.name?$:void 0}connection($=this.name){return rX($),T(X$).connection($)}}var xZ=new P8;class ZG extends c{static getFacadeAccessor(){return X$}static connection($){return new P8($)}static get sql(){return xZ.sql}static get dialect(){return xZ.dialect}static query($){return xZ.query($)}static execute($){return xZ.execute($)}static transaction($){return xZ.transaction($)}static schema(){return xZ.schema()}static close(){return this.getFacadeRoot().close()}}export{K1 as Zc,fZ as _c,S8 as $c,k$ as ad,RZ as bd,A0 as cd,R8 as dd,b8 as ed,uJ as fd,O1 as gd,j$ as hd,MG as id,w8 as jd,B1 as kd,F0 as ld,PG as md,NG as nd,i8 as od,s8 as pd,A5 as qd,e0 as rd,bZ as sd,Y5 as td,g$ as ud,f5 as vd,E5 as wd,o8 as xd,a8 as yd,w3 as zd,kZ as Ad,FV as Bd,m5 as Cd,DF as Dd,Zj as Ed,S3 as Fd,X1 as Gd,$$ as Hd,T8 as Id,xX as Jd,AX as Kd,IB as Ld,f1 as Md,EX as Nd,bX as Od,wX as Pd,kX as Qd,ON as Rd,qX as Sd,I8 as Td,HJ as Ud,CJ as Vd,_J as Wd,M8 as Xd,fJ as Yd,sX as Zd,nX as _d,uz as $d,GJ as ae,lz as be,iz as ce,fO as de,sz as ee,FJ as fe,bO as ge,vO as he,QJ as ie,nz as je,oz as ke,PZ as le,oX as me,P8 as ne,ZG as oe,S4 as pe,rK as qe,q4 as re,y4 as se,VT as te,zz as ue,Xz as ve,x3 as we,VZ as xe,bT as ye,Qz as ze,Kz as Ae,zJ as Be,LZ as Ce,KJ as De,nI as Ee,VJ as Fe,$B as Ge,DJ as He,JB as Ie,P3 as Je,TJ as Ke,UX as Le,VX as Me,O8 as Ne,a0 as Oe,E as Pe,rJ as Qe,tJ as Re,$5 as Se,G5 as Te,F5 as Ue,Q5 as Ve,y8 as We,_G as Xe,j0 as Ye,N5 as Ze,h$ as _e,S5 as $e};
55
+ `)}function uX($,Z,j,J){let W=Z instanceof Request?Z:Z.rawRequest,Y=J.cursor??W.headers.get("Last-Event-ID")??new URL(W.url).searchParams.get("cursor"),z;try{z=$.subscribe(j,{cursor:Y,signal:W.signal})}catch(K){if(!(K instanceof M8))throw K;return new Response(JSON.stringify({error:"The change feed is at capacity."}),{status:503,headers:{"Content-Type":"application/json","Retry-After":String(J.retryAfter??5)}})}let X=null,G=!1,F=!1,Q=(K)=>{if(X)clearInterval(X);if(X=null,z.close(),F)return;F=!0;try{K.close()}catch{}},O=new ReadableStream({start(K){X=setInterval(()=>{if(cX())return Q(K);try{K.enqueue(dX.encode(pX))}catch{Q(K)}},$.config.keepaliveInterval)},async pull(K){try{if(!G){if(await z.ready(),G=!0,!F)K.enqueue(mX(z.cursor,{type:"ready"}));return}let D=await z.next();if(D.done||F)return Q(K);K.enqueue(mX(z.cursor,D.value))}catch(D){if(!F)console.error("[gemi] A change feed stream failed.",D);Q(K)}},cancel(){if(F=!0,X)clearInterval(X);X=null,z.close()}});return new Response(O,{headers:hX()})}var lX=255,iX=500,_B=30000;class M8 extends Error{limit;constructor($){super(`The change feed holds its limit of ${$} subscriptions.`);this.limit=$;this.name="ChangeFeedFullError"}}class fJ{options;static token="changeFeed";driver;config;followers=new Map;all=new Set;listenState="off";listening=null;retryTimer=null;backoffMs=iX;pollTimer=null;polling=null;constructor($={},Z={}){this.options=Z;this.config=V8(yX(),$),this.driver=xB(this.config.driver,Z.application)}get subscriptions(){return this.all.size}get isListening(){return this.listenState==="listening"}async publish($,Z){AJ($);let j=Z===void 0?null:Z;if(V1()!==void 0&&!this.driver.joinsTransaction?.())return xJ(async()=>{this.wake($,await this.driver.publish($,j))}),null;let J=await this.driver.publish($,j);return xJ(()=>this.wake($,J)),J}async head($){return AJ($),(await this.driver.heads([$])).get($)??0}async cursor($){let Z=SJ($);return I8(await this.driver.heads(Z))}subscribe($,Z={}){let j=SJ($);if(this.all.size>=this.config.maxSubscriptions)throw new M8(this.config.maxSubscriptions);let J=new sX(this,j,SB(Z.cursor),this.config,Z.signal);this.all.add(J);for(let W of j){let Y=this.followers.get(W);if(!Y)this.followers.set(W,Y=new Set);Y.add(J)}return this.startListening(),this.startPolling(),J}stream($,Z,j={}){return uX(this,$,SJ(Z),j)}async close(){if(this.listenState="closed",this.retryTimer)clearTimeout(this.retryTimer);this.retryTimer=null,this.stopPolling();for(let Z of this.all)Z.close();let $=this.listening;this.listening=null,await $?.close(),await this.driver.close?.()}forget($){if(!this.all.delete($))return;for(let Z of $.channels){let j=this.followers.get(Z);if(j?.delete($),j?.size===0)this.followers.delete(Z)}if(this.all.size===0)this.stopPolling()}poll(){return this.polling??=(async()=>{try{let $=[...this.followers.keys()];for(let Z=0;Z<$.length;Z+=500){let j=await this.driver.heads($.slice(Z,Z+500));for(let[J,W]of j)this.wake(J,W)}}catch($){console.error("[gemi] The change feed could not read its channels' heads.",$)}finally{this.polling=null}})(),this.polling}startPolling(){if(this.pollTimer)return;this.pollTimer=setInterval(()=>void this.poll(),this.config.pollInterval),this.pollTimer.unref?.()}stopPolling(){if(this.pollTimer)clearInterval(this.pollTimer);this.pollTimer=null}wake($,Z){for(let j of this.followers.get($)??[])j.moved($,Z)}resync(){this.poll()}startListening(){if(this.listenState!=="off"||!this.driver.listen)return;this.connect()}async connect(){this.listenState="connecting",this.retryTimer=null;try{let $=await this.driver.listen((Z,j)=>this.wake(Z,j),()=>this.resync());if(this.listenState!=="connecting"){await $.close();return}this.listening=$,this.listenState="listening",this.backoffMs=iX,this.resync()}catch($){if(this.listenState!=="connecting")return;console.error(`[gemi] The change feed could not listen for other instances' changes; retrying in ${this.backoffMs}ms.`,$),this.listenState="retrying",this.retryTimer=setTimeout(()=>void this.connect(),this.backoffMs),this.retryTimer.unref?.(),this.backoffMs=Math.min(this.backoffMs*2,_B)}}}class sX{manager;config;signal;channels;positions=new Map;readTo=new Map;dirty=new Set;pending=[];started=null;wakeUp=null;closed=!1;onAbort=()=>this.close();constructor($,Z,j,J,W){this.manager=$;this.config=J;this.signal=W;this.channels=Z;for(let Y of Z){let z=j.get(Y);if(z!==void 0)this.positions.set(Y,z),this.readTo.set(Y,z),this.dirty.add(Y)}if(W?.aborted)this.close();else W?.addEventListener("abort",this.onAbort,{once:!0})}get cursor(){return I8(this.positions)}get isClosed(){return this.closed}ready(){return this.started??=(async()=>{let $=this.channels.filter((j)=>!this.positions.has(j));if($.length===0)return;let Z=await this.manager.driver.heads($);for(let j of $){let J=Z.get(j)??0;this.positions.set(j,J),this.readTo.set(j,J)}})(),this.started}async next(){await this.ready();for(;;){if(this.closed)return{done:!0,value:void 0};let $=this.pending.shift();if($)return this.positions.set($.channel,$.seq),{done:!1,value:$};let Z=this.dirty.values().next().value;if(Z!==void 0){await this.read(Z);continue}await this.idle()}}async return(){return this.close(),{done:!0,value:void 0}}[Symbol.asyncIterator](){return this}close(){if(this.closed)return;this.closed=!0,this.pending.length=0,this.signal?.removeEventListener("abort",this.onAbort),this.manager.forget(this),this.wake()}moved($,Z){let j=this.readTo.get($);if(j!==void 0&&Z===j)return;this.dirty.add($),this.wake()}async read($){let Z=this.readTo.get($)??0;this.dirty.delete($);let{batchSize:j}=this.config,{entries:J,head:W,gap:Y}=await this.manager.driver.read($,Z,j);if(this.closed)return;if(Y){this.readTo.set($,W),this.pending.push({type:"reset",channel:$,seq:W});return}for(let z of J)this.readTo.set($,z.seq),this.pending.push({type:"change",channel:$,seq:z.seq,data:z.data});if(J.length===j)this.dirty.add($)}idle(){return new Promise(($)=>{this.wakeUp=$})}wake(){let $=this.wakeUp;this.wakeUp=null,$?.()}}function AJ($){if(typeof $!=="string"||$===""||$.length>lX)throw Error(`A change feed channel is a string of 1 to ${lX} characters; got ${JSON.stringify($)}.`)}function SJ($){let Z=[...new Set(typeof $==="string"?[$]:$)];if(Z.length===0)throw Error("A change feed subscription needs at least one channel.");for(let j of Z)AJ(j);return Z}function SB($){if($===void 0||$===null)return new Map;if(typeof $==="string")return HJ($);let Z=$ instanceof Map?[...$]:Object.entries($);return HJ(I8(new Map(Z)))}function xB($,Z){if($==="memory")return new _J;if($==="database"||typeof $==="function"){if(!Z&&($==="database"||$.length>0))throw Error("The change feed driver needs the application it belongs to, and this ChangeFeedManager was built without one. Pass { application }.");if($==="database")return new CJ(Z.make(X$));return $(Z)}if(typeof $==="string")throw Error(`Unknown change feed driver "${$}". The changeFeed slice's driver is "memory", "database", a ChangeFeedDriver, or a function returning one.`);return $}class nX extends c{static getFacadeAccessor(){return fJ}static publish($,Z){return this.getFacadeRoot().publish($,Z)}static head($){return this.getFacadeRoot().head($)}static cursor($){return this.getFacadeRoot().cursor($)}static subscribe($,Z){return this.getFacadeRoot().subscribe($,Z)}static stream($,Z,j){return this.getFacadeRoot().stream($,Z,j)}}class oX extends c{static getFacadeAccessor(){return PZ}static enabled($){return this.getFacadeRoot().enabled($)}static all(){return this.getFacadeRoot().forClient()}static explain($){return this.getFacadeRoot().explain($)}static for($){return this.getFacadeRoot().for($)}static list(){return this.getFacadeRoot().list()}static set($,Z,j){return this.getFacadeRoot().set($,Z,j)}static refresh(){return this.getFacadeRoot().refresh()}static invalidate(){return this.getFacadeRoot().invalidate()}}class P8{bound;constructor($){this.bound=$}get name(){return this.bound??z$()}get sql(){return this.connection().sql}get dialect(){return this.connection().dialect}async query($){return await this.run($,"query")}async execute($){let Z=await this.run($,"execute");return Number(Z?.count??0)}async transaction($){let Z=this.name,j=this.connection(Z);return tX(j.sql,(J)=>aX(Z,()=>$(J)),{slowTransactionThreshold:j.config.slowTransactionThreshold,connection:Z})}async schema(){let $=this.connection(),{introspect:Z}=await import("./chunk-nrezmscd.js");return Z(this.handle()??$.sql,$.dialect)}run($,Z){let j=this.connection(),{text:J,values:W}=$G($,eX(j.dialect),Z);return(this.handle()??j.sql).unsafe(J,W)}handle(){let $=V1();if($===void 0)return;return z$()===this.name?$:void 0}connection($=this.name){return rX($),T(X$).connection($)}}var xZ=new P8;class ZG extends c{static getFacadeAccessor(){return X$}static connection($){return new P8($)}static get sql(){return xZ.sql}static get dialect(){return xZ.dialect}static query($){return xZ.query($)}static execute($){return xZ.execute($)}static transaction($){return xZ.transaction($)}static schema(){return xZ.schema()}static close(){return this.getFacadeRoot().close()}}export{K1 as Zc,fZ as _c,S8 as $c,k$ as ad,RZ as bd,A0 as cd,R8 as dd,b8 as ed,uJ as fd,O1 as gd,j$ as hd,MG as id,w8 as jd,B1 as kd,F0 as ld,PG as md,NG as nd,i8 as od,s8 as pd,A5 as qd,e0 as rd,bZ as sd,Y5 as td,g$ as ud,f5 as vd,E5 as wd,o8 as xd,a8 as yd,w3 as zd,kZ as Ad,FV as Bd,m5 as Cd,DF as Dd,Zj as Ed,S3 as Fd,X1 as Gd,$$ as Hd,T8 as Id,xX as Jd,AX as Kd,IB as Ld,f1 as Md,EX as Nd,bX as Od,wX as Pd,kX as Qd,ON as Rd,yX as Sd,I8 as Td,HJ as Ud,CJ as Vd,_J as Wd,M8 as Xd,fJ as Yd,sX as Zd,nX as _d,uz as $d,GJ as ae,lz as be,iz as ce,fO as de,sz as ee,FJ as fe,bO as ge,vO as he,QJ as ie,nz as je,oz as ke,PZ as le,oX as me,P8 as ne,ZG as oe,S4 as pe,rK as qe,y4 as re,q4 as se,VT as te,zz as ue,Xz as ve,x3 as we,VZ as xe,bT as ye,Qz as ze,Kz as Ae,zJ as Be,LZ as Ce,KJ as De,nI as Ee,VJ as Fe,$B as Ge,DJ as He,JB as Ie,P3 as Je,TJ as Ke,UX as Le,VX as Me,O8 as Ne,a0 as Oe,E as Pe,rJ as Qe,tJ as Re,$5 as Se,G5 as Te,F5 as Ue,Q5 as Ve,q8 as We,_G as Xe,j0 as Ye,N5 as Ze,h$ as _e,S5 as $e};
56
56
 
57
- //# debugId=5F324E40C927E5DA64756E2164756E21
57
+ //# debugId=20FC016B96D96F6164756E2164756E21