k99 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.8.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).k99={})}(this,(function(t){"use strict";function e(t){return(new TextEncoder).encode(t)}function n(t){return Symbol.asyncIterator in t||Symbol.iterator in t}async function r(t,o){if("string"==typeof o)return t.write(e(o));if("object"==typeof o){if(ArrayBuffer.isView(o))return t.write(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));if(o instanceof ArrayBuffer)return t.write(new Uint8Array(o));if(n(o))for await(const e of o)e&&await r(t,e)}}function o(t,o,s,i){const c=function(t,o,s){if(t instanceof ReadableStream)return[t,0,""];if(t instanceof URLSearchParams)return[t,0,""];if(t instanceof Blob)return[t,t.size,t.type];if(t instanceof FormData)return[t,0,""];if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer)return[t,t.byteLength,""];if("string"==typeof t){const n=e(t);return[n,n.byteLength,"text/plain"]}if(["bigint","boolean","number"].includes(typeof t)){const n=e(JSON.stringify(t,o));return[n,n.byteLength,"application/json"]}if("object"!=typeof t)return null;if(Array.isArray(t)||!n(t)){const n=e(JSON.stringify(t,o));return[n,n.byteLength,"application/json"]}const{writable:i,readable:c}=new TransformStream,f=i.getWriter();return s?.catch((t=>{i.abort(t||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const e of t)e&&await r(f,e)})().then((()=>i.close()),(t=>i.abort(t))).catch((()=>{})),[c,0,""]}(t,s,i);if(!c)return null;const[f,a,u]=c;return u&&!o.get("Content-Type")&&o.set("Content-Type",u),a>0&&!o.get("Content-Length")&&o.set("Content-Length",String(a)),f}function s(t,e){t.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:c,httpOnly:f}of e)n&&t.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,c&&"Secure",f&&"HttpOnly"].filter(Boolean).join("; "))}const i=new Set(["GET","OPTIONS"]);function c(t,e,n){n?t.set(e,n):t.delete(e)}function f(t,e){return"bigint"==typeof e?String(e):e}function a(t,e,{runner:n,error:r,catch:a,method:u,environment:l,replacer:p}={}){const h="function"==typeof p?p:f;return function t(f,p){const y=function(t,e){let n="";return"string"==typeof e?n=e:"function"==typeof e&&(n=e(t)),n&&"string"==typeof n||(n=t.method||"GET"),n.toUpperCase()}(f,u),d=new URL(f.url),{signal:g,headers:m}=f,b=function(t){return new Promise(((e,n)=>{if(t.aborted)return n(t.reason);t.addEventListener("abort",(()=>n(t.reason)),{once:!0})}))}(g),w=new Map,O=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(m.get("cookie")||""),T=[],E=new Headers,j=p?.root;let R=200,S=!1,A=null,P=()=>{},U=()=>{};const k=new Promise(((t,e)=>{P=t,U=e}));k.catch((()=>{}));let v={};const x={environment:l,parent:p,get error(){return A},get root(){return j||this},signal:g,url:d,fetch(e,{method:n="get",signal:r,body:s,headers:c}={}){const f=new URL(e,d),a=new Headers(c||{});if(!s||i.has(n.toUpperCase()))return t(new Request(f,{method:n,headers:a,signal:r}),x);const u=o(s,a,h);return t(new Request(f,{method:n,headers:a,signal:r,body:u}),x)},done(t,e){if(S)return null;const n=k.then(t,e);return n.catch(r),n},service(t,...e){if(t.rootOnly&&j)return j.service(t,...e);let n=w.get(t);if(!n){if(n=t(x),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:y,get params(){return v},requestHeaders:m,requestType:m.get("content-type")||"",referer:m.get("referer")||"",userAgent:m.get("user-agent")||"",accept:(m.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(m.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:O,request:f,get destroyed(){return S},get status(){return R},set status(t){R=t},responseHeaders:E,get location(){return E.get("location")||""},set location(t){c(E,"location",t)},get responseType(){return E.get("content-type")||""},set responseType(t){c(E,"content-type",t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(T,t),setCookie(t,e,{expire:n,domain:r,path:o,secure:i,httpOnly:c}={}){T.push({name:t,value:e,expire:n,domain:r,path:o,secure:i,httpOnly:c}),s(E,T)},clearCookie(t,e){!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:c}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:c})}else{const{domain:s,path:i,secure:c,httpOnly:f}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:c,httpOnly:f})}}(T,O,t,e),s(E,T)}};function L(){return Promise.race([b,Promise.resolve().then((()=>e(x,(t=>{v=t}))))]).then((async t=>{const e=[t].flat().filter((t=>"function"==typeof t));if(!e.length)return null;let n;for(const t of e)if(n=await Promise.race([b,t(x)]),void 0!==n)break;if(n instanceof Response)return n;const r=new Headers(x.responseHeaders),{status:s}=x;if(!n)return new Response(null,{status:s,headers:r});const i=o(n,r,h,b);return new Response(i,{status:s,headers:r})})).then((t=>(S=!0,P(),t)),(t=>(S=!0,A=t||!0,U(A),Promise.reject(t)))).catch(a)}return n?n(x,L):L()}(t)}async function u(t,e){for(const n of e){const e=await n(t);if(void 0!==e)return e}}const l=t=>t;function p(t,e=l){return n=>{const r=e(n);return async e=>t(e,(async()=>u(e,[r].flat())))}}function h(t){try{return decodeURIComponent(t)}catch{return t}}class y{disabled=!1;static async#t(t,e,n,r,o){if(!(t instanceof y))return r(o),[t].flat();if(t.disabled)return null;if(n.destroyed)return null;for await(const[s,i,c]of t.find(n.method,e,n)){if(n.destroyed)return null;const e=await y.#t(s,c,n,r,{...o,...i});if(e)return[t.#e,t.#n(e)].flat()}return null}find(t,e,n){return[]}static make(t){return async(e,n)=>{const r=t.flat(),o=e.url.pathname.split("/").filter(Boolean).map(h);for(const t of r){const r=await y.#t(t,o,e,n,{});if(r)return r}return null}}#e=[];guard(...t){const e=this.#e;for(const n of t.flat())"function"==typeof n&&e.push(n)}static create(t){return Object.defineProperties(new y,{find:{configurable:!0,value:t,writable:!0}})}#n=t=>t;onionskin(t){this.#n=p(t,this.#n)}}const d=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function g(t){const e=d.exec(t);if(!e)return t;const[,n,r=".*",o,s]=e;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,c=0;const f=["^(?:"];for(;i<r.length;){const e=r[i++];if(f.push(e),"\\"!==e)if(")"!==e)if("["!==e){if("("===e&&(c++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return t}else for(;i<r.length;){const t=r[i++];if(f.push(t),"]"===t)break;"\\"===t&&f.push(r[i++])}else{if(0===c)return t;c--}else f.push(r[i++])}return c?t:(f.push(")$"),{name:n,pattern:new RegExp(f.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function m(t,e){const n=[];if("string"==typeof t)for(const e of t.split("/"))e&&!/^\.+$/.test(e)&&n.push(g(e));else for(const[e,r]of function*([...t],[...e]){let n=(t.shift()||"").split("/"),r=[n.pop()||""];for(const t of n)yield[[t],[]];for(const n of t){const t=n.split("/");if(t.length<=1){r.push(n);continue}const o=e.splice(0,r.length);r.push(t.shift()||""),yield[r,o],r=[t.pop()||""];for(const e of t)yield[[e],[]]}yield[r,e]}(...t)){if(2===e.length&&!e[0]){const t=e[1];if(["","?","+","*"].includes(t)){const e=r[0];if("symbol"==typeof e){n.push({name:e,pattern:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}if(e&&"object"==typeof e){const{name:r,pattern:o}=e;if("symbol"==typeof r){n.push({name:r,pattern:o instanceof RegExp?o:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}}}}const t=e.pop()||"",o=e.map(((t,e)=>[t,r[e]])).flat();o.push(t);const s=o.join("");s&&!/^\.+$/.test(s)&&n.push(g(s))}if(n.length)return t=>function(t,e,n){const r={};for(let n=0;n<t.length;n++){const o=t[n],s=e[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,e.slice(t.length)];if(e.length<=t.length)return[r,[]];const o=t[t.length-1];if("string"!=typeof o&&(o.many||!(e.length>t.length))){for(let n=t.length;n<e.length;n++)if(!o.pattern.test(e[n]))return;return r[o.name]=e.slice(t.length-1),[r,[]]}}(n,t,e)}function b(t,e,n,r){const o={match:n,methods:e,handlers:r};t.push(o);let s=!1;return()=>{if(s)return;s=!0;const e=t.indexOf(o);e<0||t.splice(e,1)}}const w=t=>"function"==typeof t;function O(t,e,n){const r=new Set(e);if(!n.length){const e=void 0;return(...n)=>b(t,r,e,n)}const[o]=n;if(o&&"object"==typeof o){const e=m([o,n.slice(1)],!0);return(...n)=>b(t,r,e,n)}const s=m("string"==typeof o?o:"",!0),i=n.filter(w);return i.length?b(t,r,s,i):(...e)=>b(t,r,s,e)}const T=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function E(t){return T.has(t)}function j(t,e,n){const r=n instanceof y?n:"function"==typeof n?y.create(n):new R;return t.push({match:m(e,!1),router:r}),r}class R extends y{#r=[];route(...t){const[e]=t;if(e&&"object"==typeof e&&!(e instanceof y))return n=>j(this.#r,[e,t.slice(1)],n);const n="string"==typeof e?e:"",r="string"==typeof e?t[1]:e;return j(this.#r,n,r)}*find(t,e,n){for(const n of Array.from(this.#r)){if(!n.router&&!n.methods.has(t))continue;const{match:r}=n;if(!r){!n.router&&e.length||(yield[n.router||n.handlers,{},e]);continue}if(!e.length)continue;const o=r(e);o&&(yield[n.router||n.handlers,...o])}}verb(t,e,...n){const r=function(t){return t?"string"==typeof t?[t.toUpperCase()].filter(E):Array.from(t).map((t=>"string"==typeof t&&t.toUpperCase())).filter(E):["GET","POST","PUT","DELETE"]}(t);return r.length?O(this.#r,r,[e,...n]):()=>{}}match(...t){return O(this.#r,["GET","POST","PUT","DELETE"],t)}get(...t){return O(this.#r,["GET"],t)}post(...t){return O(this.#r,["POST"],t)}put(...t){return O(this.#r,["PUT"],t)}delete(...t){return O(this.#r,["DELETE"],t)}head(...t){return O(this.#r,["HEAD"],t)}options(...t){return O(this.#r,["OPTIONS"],t)}}const S=()=>{};t.ApiRouter=R,t.Param=class{#o=Symbol();get name(){return this.#o}#s;get pattern(){return this.#s}constructor(t){this.#s=t}param(t){const e=t.params[this.#o];return Array.isArray(e)?e[0]??null:e??null}params(t){const e=t.params[this.#o];return"string"==typeof e?[e]:Array.isArray(e)?e:null}},t.Router=y,t.createFetch=function(t,e){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await t(o);return i||("function"==typeof e?e(o):new Response(null,{status:404}))}},t.main=a,t.make=function(t,e){return n=>a(n,t,e)},t.merge=function(...t){return e=>u(e,t.flat())},t.onionskin=function(...t){let e=S;for(const n of t.flat()){const t=e;e=async e=>n(e,(async()=>t(e)))}return e},t.packer=p,t.service=function(t,e,n){const r=function(n){return"function"==typeof e&&n.done((()=>e(n)),(t=>e(n,t))),(...e)=>t(n,...e)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r},t.stateService=function(t,e,n,r){const o=function(r){const o=t(r)||{};return"function"==typeof e&&r.done((()=>e(o,r)),(t=>e(o,r,t))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof e&&e||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o},t.storeService=function(t,e,n){const r=function(n){let r;return"function"==typeof t&&n.done((()=>t(r,n)),(e=>t(r,n,e))),"function"!=typeof e?(...t)=>(t.length&&([r]=t),r):(...t)=>(t.length&&([r]=t,e(r,n)),r)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}}));
6
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).k99={})}(this,(function(t){"use strict";function e(t){return(new TextEncoder).encode(t)}function n(t){return Symbol.asyncIterator in t||Symbol.iterator in t}async function r(t,o){if("string"==typeof o)return t.write(e(o));if("object"==typeof o){if(ArrayBuffer.isView(o))return t.write(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));if(o instanceof ArrayBuffer)return t.write(new Uint8Array(o));if(n(o))for await(const e of o)e&&await r(t,e)}}function o(t,o,s,i){const c=function(t,o,s){if(t instanceof ReadableStream)return[t,0,""];if(t instanceof URLSearchParams)return[t,0,""];if(t instanceof Blob)return[t,t.size,t.type];if(t instanceof FormData)return[t,0,""];if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer)return[t,t.byteLength,""];if("string"==typeof t){const n=e(t);return[n,n.byteLength,"text/plain"]}if(["bigint","boolean","number"].includes(typeof t)){const n=e(JSON.stringify(t,o));return[n,n.byteLength,"application/json"]}if("object"!=typeof t)return null;if(Array.isArray(t)||!n(t)){const n=e(JSON.stringify(t,o));return[n,n.byteLength,"application/json"]}const{writable:i,readable:c}=new TransformStream,u=i.getWriter();return s?.catch((t=>{i.abort(t||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const e of t)e&&await r(u,e)})().then((()=>i.close()),(t=>i.abort(t))).catch((()=>{})),[c,0,""]}(t,s,i);if(!c)return null;const[u,f,a]=c;return a&&!o.get("Content-Type")&&o.set("Content-Type",a),f>0&&!o.get("Content-Length")&&o.set("Content-Length",String(f)),u}function s(t,e){t.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:c,httpOnly:u}of e)n&&t.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,c&&"Secure",u&&"HttpOnly"].filter(Boolean).join("; "))}const i=new Set(["GET","OPTIONS"]);function c(t,e,n){n?t.set(e,n):t.delete(e)}function u(t,e){return"bigint"==typeof e?String(e):e}function f(t,e,{runner:n,error:r,catch:f,method:a,environment:l,replacer:p}={}){const h="function"==typeof p?p:u;return function t(u,p){const y=function(t,e){let n="";return"string"==typeof e?n=e:"function"==typeof e&&(n=e(t)),n&&"string"==typeof n||(n=t.method||"GET"),n.toUpperCase()}(u,a),d=new URL(u.url),{signal:g,headers:m}=u,b=function(t){return new Promise(((e,n)=>{if(t.aborted)return n(t.reason);t.addEventListener("abort",(()=>n(t.reason)),{once:!0})}))}(g),w=new Map,O=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(m.get("cookie")||""),T=[],j=new Headers,R=p?.root;let E=200,S=!1,U=null,A=()=>{},v=()=>{};const x=new Promise(((t,e)=>{A=t,v=e}));x.catch((()=>{}));let P={};const C={environment:l,parent:p,get error(){return U},get root(){return R||this},signal:g,url:d,fetch(e,{method:n="get",signal:r,body:s,headers:c}={}){const u=new URL(e,d),f=new Headers(c||{});if(!s||i.has(n.toUpperCase()))return t(new Request(u,{method:n,headers:f,signal:r}),C);const a=o(s,f,h);return t(new Request(u,{method:n,headers:f,signal:r,body:a}),C)},done(t,e){if(S)return null;const n=x.then(t,e);return n.catch(r),n},service(t,...e){if(t.rootOnly&&R)return R.service(t,...e);let n=w.get(t);if(!n){if(n=t(C),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:y,get params(){return P},requestHeaders:m,requestType:m.get("content-type")||"",referer:m.get("referer")||"",userAgent:m.get("user-agent")||"",accept:(m.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(m.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:O,request:u,get destroyed(){return S},get status(){return E},set status(t){E=t},responseHeaders:j,get location(){return j.get("location")||""},set location(t){c(j,"location",t)},get responseType(){return j.get("content-type")||""},set responseType(t){c(j,"content-type",t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(T,t),setCookie(t,e,{expire:n,domain:r,path:o,secure:i,httpOnly:c}={}){T.push({name:t,value:e,expire:n,domain:r,path:o,secure:i,httpOnly:c}),s(j,T)},clearCookie(t,e){!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:c}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:c})}else{const{domain:s,path:i,secure:c,httpOnly:u}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:c,httpOnly:u})}}(T,O,t,e),s(j,T)}};function L(){return Promise.race([b,Promise.resolve().then((()=>e(C,(t=>{P=t}))))]).then((async t=>{const e=[t].flat().filter((t=>"function"==typeof t));if(!e.length)return null;let n;for(const t of e)if(n=await Promise.race([b,t(C)]),void 0!==n)break;if(n instanceof Response)return n;const r=new Headers(C.responseHeaders),{status:s}=C;if(null==!n)return new Response(null,{status:s,headers:r});const i=o(n,r,h,b);return new Response(i,{status:s,headers:r})})).then((t=>(S=!0,A(),t)),(t=>(S=!0,U=t||!0,v(U),Promise.reject(t)))).catch(f)}return n?n(C,L):L()}(t)}class a{disabled=!1;static async#t(t,e,n,r,o,s){if(!(t instanceof a))return"function"==typeof s&&s(r),[t].flat();if(t.disabled)return null;if(o?.aborted)return null;for await(const[i,c,u]of t.find(e,n)){if(o?.aborted)return null;const n=await a.#t(i,e,u,{...r,...c},o,s);if(n)return[...t.#e,...n]}return null}static async find(t,e,n,r,o){const s=`${e}`.toUpperCase();for(const e of t.flat()){const t=await a.#t(e,s,n,{},r,o);if(t)return t}return null}find(t,e){return[]}#e=[];guard(...t){const e=this.#e;for(const n of t.flat())"function"==typeof n&&e.push(n)}static create(t){return Object.defineProperties(new a,{find:{configurable:!0,value:t,writable:!0}})}}function l(t){try{return decodeURIComponent(t)}catch{return t}}const p=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function h(t){const e=p.exec(t);if(!e)return t;const[,n,r=".*",o,s]=e;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,c=0;const u=["^(?:"];for(;i<r.length;){const e=r[i++];if(u.push(e),"\\"!==e)if(")"!==e)if("["!==e){if("("===e&&(c++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return t}else for(;i<r.length;){const t=r[i++];if(u.push(t),"]"===t)break;"\\"===t&&u.push(r[i++])}else{if(0===c)return t;c--}else u.push(r[i++])}return c?t:(u.push(")$"),{name:n,pattern:new RegExp(u.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function y(t,e){const n=[];if("string"==typeof t)for(const e of t.split("/"))e&&!/^\.+$/.test(e)&&n.push(h(e));else for(const[e,r]of function*([...t],[...e]){let n=(t.shift()||"").split("/"),r=[n.pop()||""];for(const t of n)yield[[t],[]];for(const n of t){const t=n.split("/");if(t.length<=1){r.push(n);continue}const o=e.splice(0,r.length);r.push(t.shift()||""),yield[r,o],r=[t.pop()||""];for(const e of t)yield[[e],[]]}yield[r,e]}(...t)){if(2===e.length&&!e[0]){const t=e[1];if(["","?","+","*"].includes(t)){const e=r[0];if("symbol"==typeof e){n.push({name:e,pattern:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}if(e&&"object"==typeof e){const{name:r,pattern:o}=e;if("symbol"==typeof r){n.push({name:r,pattern:o instanceof RegExp?o:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}}}}const t=e.pop()||"",o=e.map(((t,e)=>[t,r[e]])).flat();o.push(t);const s=o.join("");s&&!/^\.+$/.test(s)&&n.push(h(s))}if(n.length)return t=>function(t,e,n){const r={};for(let n=0;n<t.length;n++){const o=t[n],s=e[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,e.slice(t.length)];if(e.length<=t.length)return[r,[]];const o=t[t.length-1];if("string"!=typeof o&&(o.many||!(e.length>t.length))){for(let n=t.length;n<e.length;n++)if(!o.pattern.test(e[n]))return;return r[o.name]=e.slice(t.length-1),[r,[]]}}(n,t,e)}function d(t,e,n,r){const o={match:n,methods:e,handlers:r};t.push(o);let s=!1;return()=>{if(s)return;s=!0;const e=t.indexOf(o);e<0||t.splice(e,1)}}const g=t=>"function"==typeof t;function m(t,e,n){const r=new Set(e);if(!n.length){const e=void 0;return(...n)=>d(t,r,e,n)}const[o]=n;if(o&&"object"==typeof o){const e=y([o,n.slice(1)],!0);return(...n)=>d(t,r,e,n)}const s=y("string"==typeof o?o:"",!0),i=n.filter(g);return i.length?d(t,r,s,i):(...e)=>d(t,r,s,e)}function b(t){return Boolean(t)}function w(t){return t?"string"==typeof t?[t.toUpperCase()].filter(b):Array.from(t).map((t=>"string"==typeof t&&t.toUpperCase())).filter(b):["GET","POST","PUT","DELETE"]}function O(t,e,n){const r=n instanceof a?n:"function"==typeof n?a.create(n):new T;return t.push({match:y(e,!1),router:r}),r}class T extends a{#n=[];route(...t){const[e]=t;if(e&&"object"==typeof e&&!(e instanceof a))return n=>O(this.#n,[e,t.slice(1)],n);const n="string"==typeof e?e:"",r="string"==typeof e?t[1]:e;return O(this.#n,n,r)}*find(t,e){for(const n of Array.from(this.#n)){if(!n.router&&!n.methods.has(t))continue;const{match:r}=n;if(!r){!n.router&&e.length||(yield[n.router||n.handlers,{},e]);continue}if(!e.length)continue;const o=r(e);o&&(yield[n.router||n.handlers,...o])}}verb(t,e,...n){const r=w(t);return r.length?m(this.#n,r,[e,...n]):()=>{}}method(t){const e=w(t);return(...t)=>m(this.#n,e,t)}match(...t){return m(this.#n,["GET","POST","PUT","DELETE"],t)}get(...t){return m(this.#n,["GET"],t)}post(...t){return m(this.#n,["POST"],t)}put(...t){return m(this.#n,["PUT"],t)}delete(...t){return m(this.#n,["DELETE"],t)}head(...t){return m(this.#n,["HEAD"],t)}options(...t){return m(this.#n,["OPTIONS"],t)}}t.MapRouter=T,t.Param=class{#r=Symbol();get name(){return this.#r}#o;get pattern(){return this.#o}constructor(t){this.#o=t}param(t){const e=t.params[this.#r];return Array.isArray(e)?e[0]??null:e??null}params(t){const e=t.params[this.#r];return"string"==typeof e?[e]:Array.isArray(e)?e:null}},t.Router=a,t.bind=function(t,e){return n=>f(n,t,e)},t.createFetch=function(t,e){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await t(o);return i||("function"==typeof e?e(o):new Response(null,{status:404}))}},t.main=f,t.make=function(t,e){if("function"==typeof t)return n=>f(n,t,e);const n=[t].flat(),r=(t,e)=>{const r=t.url.pathname.split("/").filter(Boolean).map(l);return a.find(n,t.method,r,t.signal,e)};return t=>f(t,r,e)},t.service=function(t,e,n){const r=function(n){return"function"==typeof e&&n.done((()=>e(n)),(t=>e(n,t))),(...e)=>t(n,...e)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r},t.stateService=function(t,e,n,r){const o=function(r){const o=t(r)||{};return"function"==typeof e&&r.done((()=>e(o,r)),(t=>e(o,r,t))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof e&&e||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o},t.storeService=function(t,e,n){const r=function(n){let r;return"function"==typeof t&&n.done((()=>t(r,n)),(e=>t(r,n,e))),"function"!=typeof e?(...t)=>(t.length&&([r]=t),r):(...t)=>(t.length&&([r]=t,e(r,n)),r)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}}));
package/index.min.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.8.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
- function t(t){return(new TextEncoder).encode(t)}function e(t){return Symbol.asyncIterator in t||Symbol.iterator in t}async function n(r,o){if("string"==typeof o)return r.write(t(o));if("object"==typeof o){if(ArrayBuffer.isView(o))return r.write(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));if(o instanceof ArrayBuffer)return r.write(new Uint8Array(o));if(e(o))for await(const t of o)t&&await n(r,t)}}function r(r,o,s,i){const c=function(r,o,s){if(r instanceof ReadableStream)return[r,0,""];if(r instanceof URLSearchParams)return[r,0,""];if(r instanceof Blob)return[r,r.size,r.type];if(r instanceof FormData)return[r,0,""];if(ArrayBuffer.isView(r)||r instanceof ArrayBuffer)return[r,r.byteLength,""];if("string"==typeof r){const e=t(r);return[e,e.byteLength,"text/plain"]}if(["bigint","boolean","number"].includes(typeof r)){const e=t(JSON.stringify(r,o));return[e,e.byteLength,"application/json"]}if("object"!=typeof r)return null;if(Array.isArray(r)||!e(r)){const e=t(JSON.stringify(r,o));return[e,e.byteLength,"application/json"]}const{writable:i,readable:c}=new TransformStream,u=i.getWriter();return s?.catch((t=>{i.abort(t||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const t of r)t&&await n(u,t)})().then((()=>i.close()),(t=>i.abort(t))).catch((()=>{})),[c,0,""]}(r,s,i);if(!c)return null;const[u,a,f]=c;return f&&!o.get("Content-Type")&&o.set("Content-Type",f),a>0&&!o.get("Content-Length")&&o.set("Content-Length",String(a)),u}function o(t,e){t.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:c,httpOnly:u}of e)n&&t.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,c&&"Secure",u&&"HttpOnly"].filter(Boolean).join("; "))}const s=new Set(["GET","OPTIONS"]);function i(t,e,n){n?t.set(e,n):t.delete(e)}function c(t,e){return"bigint"==typeof e?String(e):e}function u(t,e,{runner:n,error:u,catch:a,method:f,environment:l,replacer:p}={}){const h="function"==typeof p?p:c;return function t(c,p){const y=function(t,e){let n="";return"string"==typeof e?n=e:"function"==typeof e&&(n=e(t)),n&&"string"==typeof n||(n=t.method||"GET"),n.toUpperCase()}(c,f),d=new URL(c.url),{signal:g,headers:m}=c,b=function(t){return new Promise(((e,n)=>{if(t.aborted)return n(t.reason);t.addEventListener("abort",(()=>n(t.reason)),{once:!0})}))}(g),w=new Map,O=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(m.get("cookie")||""),T=[],E=new Headers,j=p?.root;let R=200,S=!1,A=null,P=()=>{},U=()=>{};const v=new Promise(((t,e)=>{P=t,U=e}));v.catch((()=>{}));let x={};const L={environment:l,parent:p,get error(){return A},get root(){return j||this},signal:g,url:d,fetch(e,{method:n="get",signal:o,body:i,headers:c}={}){const u=new URL(e,d),a=new Headers(c||{});if(!i||s.has(n.toUpperCase()))return t(new Request(u,{method:n,headers:a,signal:o}),L);const f=r(i,a,h);return t(new Request(u,{method:n,headers:a,signal:o,body:f}),L)},done(t,e){if(S)return null;const n=v.then(t,e);return n.catch(u),n},service(t,...e){if(t.rootOnly&&j)return j.service(t,...e);let n=w.get(t);if(!n){if(n=t(L),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:y,get params(){return x},requestHeaders:m,requestType:m.get("content-type")||"",referer:m.get("referer")||"",userAgent:m.get("user-agent")||"",accept:(m.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(m.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:O,request:c,get destroyed(){return S},get status(){return R},set status(t){R=t},responseHeaders:E,get location(){return E.get("location")||""},set location(t){i(E,"location",t)},get responseType(){return E.get("content-type")||""},set responseType(t){i(E,"content-type",t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(T,t),setCookie(t,e,{expire:n,domain:r,path:s,secure:i,httpOnly:c}={}){T.push({name:t,value:e,expire:n,domain:r,path:s,secure:i,httpOnly:c}),o(E,T)},clearCookie(t,e){!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:c}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:c})}else{const{domain:s,path:i,secure:c,httpOnly:u}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:c,httpOnly:u})}}(T,O,t,e),o(E,T)}};function k(){return Promise.race([b,Promise.resolve().then((()=>e(L,(t=>{x=t}))))]).then((async t=>{const e=[t].flat().filter((t=>"function"==typeof t));if(!e.length)return null;let n;for(const t of e)if(n=await Promise.race([b,t(L)]),void 0!==n)break;if(n instanceof Response)return n;const o=new Headers(L.responseHeaders),{status:s}=L;if(!n)return new Response(null,{status:s,headers:o});const i=r(n,o,h,b);return new Response(i,{status:s,headers:o})})).then((t=>(S=!0,P(),t)),(t=>(S=!0,A=t||!0,U(A),Promise.reject(t)))).catch(a)}return n?n(L,k):k()}(t)}function a(t,e){return n=>u(n,t,e)}async function f(t,e){for(const n of e){const e=await n(t);if(void 0!==e)return e}}function l(...t){return e=>f(e,t.flat())}function p(t,e,n){const r=function(n){return"function"==typeof e&&n.done((()=>e(n)),(t=>e(n,t))),(...e)=>t(n,...e)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}function h(t,e,n,r){const o=function(r){const o=t(r)||{};return"function"==typeof e&&r.done((()=>e(o,r)),(t=>e(o,r,t))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof e&&e||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o}function y(t,e,n){const r=function(n){let r;return"function"==typeof t&&n.done((()=>t(r,n)),(e=>t(r,n,e))),"function"!=typeof e?(...t)=>(t.length&&([r]=t),r):(...t)=>(t.length&&([r]=t,e(r,n)),r)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}const d=t=>t;function g(t,e=d){return n=>{const r=e(n);return async e=>t(e,(async()=>f(e,[r].flat())))}}function m(t){try{return decodeURIComponent(t)}catch{return t}}class b{disabled=!1;static async#t(t,e,n,r,o){if(!(t instanceof b))return r(o),[t].flat();if(t.disabled)return null;if(n.destroyed)return null;for await(const[s,i,c]of t.find(n.method,e,n)){if(n.destroyed)return null;const e=await b.#t(s,c,n,r,{...o,...i});if(e)return[t.#e,t.#n(e)].flat()}return null}find(t,e,n){return[]}static make(t){return async(e,n)=>{const r=t.flat(),o=e.url.pathname.split("/").filter(Boolean).map(m);for(const t of r){const r=await b.#t(t,o,e,n,{});if(r)return r}return null}}#e=[];guard(...t){const e=this.#e;for(const n of t.flat())"function"==typeof n&&e.push(n)}static create(t){return Object.defineProperties(new b,{find:{configurable:!0,value:t,writable:!0}})}#n=t=>t;onionskin(t){this.#n=g(t,this.#n)}}const w=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function O(t){const e=w.exec(t);if(!e)return t;const[,n,r=".*",o,s]=e;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,c=0;const u=["^(?:"];for(;i<r.length;){const e=r[i++];if(u.push(e),"\\"!==e)if(")"!==e)if("["!==e){if("("===e&&(c++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return t}else for(;i<r.length;){const t=r[i++];if(u.push(t),"]"===t)break;"\\"===t&&u.push(r[i++])}else{if(0===c)return t;c--}else u.push(r[i++])}return c?t:(u.push(")$"),{name:n,pattern:new RegExp(u.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function T(t,e){const n=[];if("string"==typeof t)for(const e of t.split("/"))e&&!/^\.+$/.test(e)&&n.push(O(e));else for(const[e,r]of function*([...t],[...e]){let n=(t.shift()||"").split("/"),r=[n.pop()||""];for(const t of n)yield[[t],[]];for(const n of t){const t=n.split("/");if(t.length<=1){r.push(n);continue}const o=e.splice(0,r.length);r.push(t.shift()||""),yield[r,o],r=[t.pop()||""];for(const e of t)yield[[e],[]]}yield[r,e]}(...t)){if(2===e.length&&!e[0]){const t=e[1];if(["","?","+","*"].includes(t)){const e=r[0];if("symbol"==typeof e){n.push({name:e,pattern:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}if(e&&"object"==typeof e){const{name:r,pattern:o}=e;if("symbol"==typeof r){n.push({name:r,pattern:o instanceof RegExp?o:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}}}}const t=e.pop()||"",o=e.map(((t,e)=>[t,r[e]])).flat();o.push(t);const s=o.join("");s&&!/^\.+$/.test(s)&&n.push(O(s))}if(n.length)return t=>function(t,e,n){const r={};for(let n=0;n<t.length;n++){const o=t[n],s=e[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,e.slice(t.length)];if(e.length<=t.length)return[r,[]];const o=t[t.length-1];if("string"!=typeof o&&(o.many||!(e.length>t.length))){for(let n=t.length;n<e.length;n++)if(!o.pattern.test(e[n]))return;return r[o.name]=e.slice(t.length-1),[r,[]]}}(n,t,e)}function E(t,e,n,r){const o={match:n,methods:e,handlers:r};t.push(o);let s=!1;return()=>{if(s)return;s=!0;const e=t.indexOf(o);e<0||t.splice(e,1)}}const j=t=>"function"==typeof t;function R(t,e,n){const r=new Set(e);if(!n.length){const e=void 0;return(...n)=>E(t,r,e,n)}const[o]=n;if(o&&"object"==typeof o){const e=T([o,n.slice(1)],!0);return(...n)=>E(t,r,e,n)}const s=T("string"==typeof o?o:"",!0),i=n.filter(j);return i.length?E(t,r,s,i):(...e)=>E(t,r,s,e)}const S=new Set(["GET","POST","PUT","DELETE","HEAD","OPTIONS"]);function A(t){return S.has(t)}function P(t,e,n){const r=n instanceof b?n:"function"==typeof n?b.create(n):new U;return t.push({match:T(e,!1),router:r}),r}class U extends b{#r=[];route(...t){const[e]=t;if(e&&"object"==typeof e&&!(e instanceof b))return n=>P(this.#r,[e,t.slice(1)],n);const n="string"==typeof e?e:"",r="string"==typeof e?t[1]:e;return P(this.#r,n,r)}*find(t,e,n){for(const n of Array.from(this.#r)){if(!n.router&&!n.methods.has(t))continue;const{match:r}=n;if(!r){!n.router&&e.length||(yield[n.router||n.handlers,{},e]);continue}if(!e.length)continue;const o=r(e);o&&(yield[n.router||n.handlers,...o])}}verb(t,e,...n){const r=function(t){return t?"string"==typeof t?[t.toUpperCase()].filter(A):Array.from(t).map((t=>"string"==typeof t&&t.toUpperCase())).filter(A):["GET","POST","PUT","DELETE"]}(t);return r.length?R(this.#r,r,[e,...n]):()=>{}}match(...t){return R(this.#r,["GET","POST","PUT","DELETE"],t)}get(...t){return R(this.#r,["GET"],t)}post(...t){return R(this.#r,["POST"],t)}put(...t){return R(this.#r,["PUT"],t)}delete(...t){return R(this.#r,["DELETE"],t)}head(...t){return R(this.#r,["HEAD"],t)}options(...t){return R(this.#r,["OPTIONS"],t)}}function v(t,e){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await t(o);return i||("function"==typeof e?e(o):new Response(null,{status:404}))}}const x=()=>{};function L(...t){let e=x;for(const n of t.flat()){const t=e;e=async e=>n(e,(async()=>t(e)))}return e}class k{#o=Symbol();get name(){return this.#o}#s;get pattern(){return this.#s}constructor(t){this.#s=t}param(t){const e=t.params[this.#o];return Array.isArray(e)?e[0]??null:e??null}params(t){const e=t.params[this.#o];return"string"==typeof e?[e]:Array.isArray(e)?e:null}}export{U as ApiRouter,k as Param,b as Router,v as createFetch,u as main,a as make,l as merge,L as onionskin,g as packer,p as service,h as stateService,y as storeService};
6
+ function t(t){return(new TextEncoder).encode(t)}function e(t){return Symbol.asyncIterator in t||Symbol.iterator in t}async function n(r,o){if("string"==typeof o)return r.write(t(o));if("object"==typeof o){if(ArrayBuffer.isView(o))return r.write(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));if(o instanceof ArrayBuffer)return r.write(new Uint8Array(o));if(e(o))for await(const t of o)t&&await n(r,t)}}function r(r,o,s,i){const c=function(r,o,s){if(r instanceof ReadableStream)return[r,0,""];if(r instanceof URLSearchParams)return[r,0,""];if(r instanceof Blob)return[r,r.size,r.type];if(r instanceof FormData)return[r,0,""];if(ArrayBuffer.isView(r)||r instanceof ArrayBuffer)return[r,r.byteLength,""];if("string"==typeof r){const e=t(r);return[e,e.byteLength,"text/plain"]}if(["bigint","boolean","number"].includes(typeof r)){const e=t(JSON.stringify(r,o));return[e,e.byteLength,"application/json"]}if("object"!=typeof r)return null;if(Array.isArray(r)||!e(r)){const e=t(JSON.stringify(r,o));return[e,e.byteLength,"application/json"]}const{writable:i,readable:c}=new TransformStream,u=i.getWriter();return s?.catch((t=>{i.abort(t||new DOMException("The user aborted a request.")).catch((()=>{}))})),(async()=>{for await(const t of r)t&&await n(u,t)})().then((()=>i.close()),(t=>i.abort(t))).catch((()=>{})),[c,0,""]}(r,s,i);if(!c)return null;const[u,a,f]=c;return f&&!o.get("Content-Type")&&o.set("Content-Type",f),a>0&&!o.get("Content-Length")&&o.set("Content-Length",String(a)),u}function o(t,e){t.delete("set-cookie");for(const{name:n,value:r,expire:o,domain:s,path:i,secure:c,httpOnly:u}of e)n&&t.append("set-cookie",[`${encodeURI(n)}=${encodeURI(r||"")}`,o&&`Expires=${o}`,s&&`Domain=${encodeURI(s)}`,i&&`Path=${encodeURI(i)}`,c&&"Secure",u&&"HttpOnly"].filter(Boolean).join("; "))}const s=new Set(["GET","OPTIONS"]);function i(t,e,n){n?t.set(e,n):t.delete(e)}function c(t,e){return"bigint"==typeof e?String(e):e}function u(t,e,{runner:n,error:u,catch:a,method:f,environment:l,replacer:p}={}){const h="function"==typeof p?p:c;return function t(c,p){const y=function(t,e){let n="";return"string"==typeof e?n=e:"function"==typeof e&&(n=e(t)),n&&"string"==typeof n||(n=t.method||"GET"),n.toUpperCase()}(c,f),d=new URL(c.url),{signal:g,headers:m}=c,b=function(t){return new Promise(((e,n)=>{if(t.aborted)return n(t.reason);t.addEventListener("abort",(()=>n(t.reason)),{once:!0})}))}(g),w=new Map,O=function(t){let e={};for(const n of t.replace(/\s/g,"").split(";")){const t=n.split("=");e[decodeURIComponent(t.shift())]=decodeURIComponent(t.join("="))}return e}(m.get("cookie")||""),T=[],j=new Headers,E=p?.root;let R=200,U=!1,A=null,S=()=>{},P=()=>{};const x=new Promise(((t,e)=>{S=t,P=e}));x.catch((()=>{}));let v={};const C={environment:l,parent:p,get error(){return A},get root(){return E||this},signal:g,url:d,fetch(e,{method:n="get",signal:o,body:i,headers:c}={}){const u=new URL(e,d),a=new Headers(c||{});if(!i||s.has(n.toUpperCase()))return t(new Request(u,{method:n,headers:a,signal:o}),C);const f=r(i,a,h);return t(new Request(u,{method:n,headers:a,signal:o,body:f}),C)},done(t,e){if(U)return null;const n=x.then(t,e);return n.catch(u),n},service(t,...e){if(t.rootOnly&&E)return E.service(t,...e);let n=w.get(t);if(!n){if(n=t(C),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:y,get params(){return v},requestHeaders:m,requestType:m.get("content-type")||"",referer:m.get("referer")||"",userAgent:m.get("user-agent")||"",accept:(m.get("accept")||"").split(/,\s*/).filter(Boolean),acceptLanguage:(m.get("accept-language")||"").split(/,\s*/).filter(Boolean),cookies:O,request:c,get destroyed(){return U},get status(){return R},set status(t){R=t},responseHeaders:j,get location(){return j.get("location")||""},set location(t){i(j,"location",t)},get responseType(){return j.get("content-type")||""},set responseType(t){i(j,"content-type",t)},getCookie:t=>function*(t,e){const n=t;for(const t of n)e&&t.name!==e||(yield{...t})}(T,t),setCookie(t,e,{expire:n,domain:r,path:s,secure:i,httpOnly:c}={}){T.push({name:t,value:e,expire:n,domain:r,path:s,secure:i,httpOnly:c}),o(j,T)},clearCookie(t,e){!function(t,e,n,r){let o="Fri, 31 Dec 1999 16:00:00 GMT";if("string"==typeof n){if(!n)return;const{domain:e,path:s,secure:i,httpOnly:c}=!0!==r&&r||{};t.push({name:n,value:"delete",expire:o,domain:e,path:s,secure:i,httpOnly:c})}else{const{domain:s,path:i,secure:c,httpOnly:u}=n||{};if(t.length=0,r)for(let n in e)t.push({name:n,value:"delete",expire:o,domain:s,path:i,secure:c,httpOnly:u})}}(T,O,t,e),o(j,T)}};function L(){return Promise.race([b,Promise.resolve().then((()=>e(C,(t=>{v=t}))))]).then((async t=>{const e=[t].flat().filter((t=>"function"==typeof t));if(!e.length)return null;let n;for(const t of e)if(n=await Promise.race([b,t(C)]),void 0!==n)break;if(n instanceof Response)return n;const o=new Headers(C.responseHeaders),{status:s}=C;if(null==!n)return new Response(null,{status:s,headers:o});const i=r(n,o,h,b);return new Response(i,{status:s,headers:o})})).then((t=>(U=!0,S(),t)),(t=>(U=!0,A=t||!0,P(A),Promise.reject(t)))).catch(a)}return n?n(C,L):L()}(t)}class a{disabled=!1;static async#t(t,e,n,r,o,s){if(!(t instanceof a))return"function"==typeof s&&s(r),[t].flat();if(t.disabled)return null;if(o?.aborted)return null;for await(const[i,c,u]of t.find(e,n)){if(o?.aborted)return null;const n=await a.#t(i,e,u,{...r,...c},o,s);if(n)return[...t.#e,...n]}return null}static async find(t,e,n,r,o){const s=`${e}`.toUpperCase();for(const e of t.flat()){const t=await a.#t(e,s,n,{},r,o);if(t)return t}return null}find(t,e){return[]}#e=[];guard(...t){const e=this.#e;for(const n of t.flat())"function"==typeof n&&e.push(n)}static create(t){return Object.defineProperties(new a,{find:{configurable:!0,value:t,writable:!0}})}}function f(t){try{return decodeURIComponent(t)}catch{return t}}function l(t,e){if("function"==typeof t)return n=>u(n,t,e);const n=[t].flat(),r=(t,e)=>{const r=t.url.pathname.split("/").filter(Boolean).map(f);return a.find(n,t.method,r,t.signal,e)};return t=>u(t,r,e)}function p(t,e){return n=>u(n,t,e)}function h(t,e,n){const r=function(n){return"function"==typeof e&&n.done((()=>e(n)),(t=>e(n,t))),(...e)=>t(n,...e)},{rootOnly:o}="object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}function y(t,e,n,r){const o=function(r){const o=t(r)||{};return"function"==typeof e&&r.done((()=>e(o,r)),(t=>e(o,r,t))),"function"!=typeof n?()=>o:()=>(n(o,r),o)},{rootOnly:s}="object"==typeof e&&e||"object"==typeof n&&n||"object"==typeof r&&r||{};return Object.assign(o,{rootOnly:Boolean(s)}),o}function d(t,e,n){const r=function(n){let r;return"function"==typeof t&&n.done((()=>t(r,n)),(e=>t(r,n,e))),"function"!=typeof e?(...t)=>(t.length&&([r]=t),r):(...t)=>(t.length&&([r]=t,e(r,n)),r)},{rootOnly:o}="object"==typeof t&&t||"object"==typeof e&&e||"object"==typeof n&&n||{};return Object.assign(r,{rootOnly:Boolean(o)}),r}const g=/^:([a-zA-Z][a-zA-Z0-9]*)(?:\((.+)\))?([ius]+)?([?+*]?)$/;function m(t){const e=g.exec(t);if(!e)return t;const[,n,r=".*",o,s]=e;if(!r)return{name:n,pattern:new RegExp("^.*$",o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s};let i=0,c=0;const u=["^(?:"];for(;i<r.length;){const e=r[i++];if(u.push(e),"\\"!==e)if(")"!==e)if("["!==e){if("("===e&&(c++,"?"===r[i]&&(i+=2,":"!==r[i-1])))return t}else for(;i<r.length;){const t=r[i++];if(u.push(t),"]"===t)break;"\\"===t&&u.push(r[i++])}else{if(0===c)return t;c--}else u.push(r[i++])}return c?t:(u.push(")$"),{name:n,pattern:new RegExp(u.join(""),o),optional:"?"===s||"*"===s,many:"+"===s||"*"===s})}function b(t,e){const n=[];if("string"==typeof t)for(const e of t.split("/"))e&&!/^\.+$/.test(e)&&n.push(m(e));else for(const[e,r]of function*([...t],[...e]){let n=(t.shift()||"").split("/"),r=[n.pop()||""];for(const t of n)yield[[t],[]];for(const n of t){const t=n.split("/");if(t.length<=1){r.push(n);continue}const o=e.splice(0,r.length);r.push(t.shift()||""),yield[r,o],r=[t.pop()||""];for(const e of t)yield[[e],[]]}yield[r,e]}(...t)){if(2===e.length&&!e[0]){const t=e[1];if(["","?","+","*"].includes(t)){const e=r[0];if("symbol"==typeof e){n.push({name:e,pattern:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}if(e&&"object"==typeof e){const{name:r,pattern:o}=e;if("symbol"==typeof r){n.push({name:r,pattern:o instanceof RegExp?o:/^.*$/,optional:"?"===t||"*"===t,many:"+"===t||"*"===t});continue}}}}const t=e.pop()||"",o=e.map(((t,e)=>[t,r[e]])).flat();o.push(t);const s=o.join("");s&&!/^\.+$/.test(s)&&n.push(m(s))}if(n.length)return t=>function(t,e,n){const r={};for(let n=0;n<t.length;n++){const o=t[n],s=e[n];if(o!==s){if("string"==typeof o)return;if(!s)return o.optional?[r,[]]:void 0;if(!o.pattern.test(s))return;r[o.name]=s}}if(!n)return[r,e.slice(t.length)];if(e.length<=t.length)return[r,[]];const o=t[t.length-1];if("string"!=typeof o&&(o.many||!(e.length>t.length))){for(let n=t.length;n<e.length;n++)if(!o.pattern.test(e[n]))return;return r[o.name]=e.slice(t.length-1),[r,[]]}}(n,t,e)}function w(t,e,n,r){const o={match:n,methods:e,handlers:r};t.push(o);let s=!1;return()=>{if(s)return;s=!0;const e=t.indexOf(o);e<0||t.splice(e,1)}}const O=t=>"function"==typeof t;function T(t,e,n){const r=new Set(e);if(!n.length){const e=void 0;return(...n)=>w(t,r,e,n)}const[o]=n;if(o&&"object"==typeof o){const e=b([o,n.slice(1)],!0);return(...n)=>w(t,r,e,n)}const s=b("string"==typeof o?o:"",!0),i=n.filter(O);return i.length?w(t,r,s,i):(...e)=>w(t,r,s,e)}function j(t){return Boolean(t)}function E(t){return t?"string"==typeof t?[t.toUpperCase()].filter(j):Array.from(t).map((t=>"string"==typeof t&&t.toUpperCase())).filter(j):["GET","POST","PUT","DELETE"]}function R(t,e,n){const r=n instanceof a?n:"function"==typeof n?a.create(n):new U;return t.push({match:b(e,!1),router:r}),r}class U extends a{#n=[];route(...t){const[e]=t;if(e&&"object"==typeof e&&!(e instanceof a))return n=>R(this.#n,[e,t.slice(1)],n);const n="string"==typeof e?e:"",r="string"==typeof e?t[1]:e;return R(this.#n,n,r)}*find(t,e){for(const n of Array.from(this.#n)){if(!n.router&&!n.methods.has(t))continue;const{match:r}=n;if(!r){!n.router&&e.length||(yield[n.router||n.handlers,{},e]);continue}if(!e.length)continue;const o=r(e);o&&(yield[n.router||n.handlers,...o])}}verb(t,e,...n){const r=E(t);return r.length?T(this.#n,r,[e,...n]):()=>{}}method(t){const e=E(t);return(...t)=>T(this.#n,e,t)}match(...t){return T(this.#n,["GET","POST","PUT","DELETE"],t)}get(...t){return T(this.#n,["GET"],t)}post(...t){return T(this.#n,["POST"],t)}put(...t){return T(this.#n,["PUT"],t)}delete(...t){return T(this.#n,["DELETE"],t)}head(...t){return T(this.#n,["HEAD"],t)}options(...t){return T(this.#n,["OPTIONS"],t)}}function A(t,e){return async function(n,r){const o=new Request(n,r),{signal:s}=o;s.throwIfAborted();const i=await t(o);return i||("function"==typeof e?e(o):new Response(null,{status:404}))}}class S{#r=Symbol();get name(){return this.#r}#o;get pattern(){return this.#o}constructor(t){this.#o=t}param(t){const e=t.params[this.#r];return Array.isArray(e)?e[0]??null:e??null}params(t){const e=t.params[this.#r];return"string"==typeof e?[e]:Array.isArray(e)?e:null}}export{U as MapRouter,S as Param,a as Router,p as bind,A as createFetch,u as main,l as make,h as service,y as stateService,d as storeService};