k99 0.6.1 → 0.7.0

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