k99 0.9.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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
@@ -486,7 +486,7 @@ class Router {
486
486
  * @returns {Promise<T[] | null>}
487
487
  */
488
488
  static async find(routers, method, path, signal, setParams) {
489
- const m = `${method}`.toLowerCase();
489
+ const m = `${method}`.toUpperCase();
490
490
  for (const route of routers.flat()) {
491
491
  const res = await Router.#find(route, m, path, {}, signal, setParams);
492
492
  if (res) { return res; }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
@@ -490,7 +490,7 @@
490
490
  * @returns {Promise<T[] | null>}
491
491
  */
492
492
  static async find(routers, method, path, signal, setParams) {
493
- const m = `${method}`.toLowerCase();
493
+ const m = `${method}`.toUpperCase();
494
494
  for (const route of routers.flat()) {
495
495
  const res = await Router.#find(route, m, path, {}, signal, setParams);
496
496
  if (res) { return res; }
package/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * k99 v0.9.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,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,A=null,U=()=>{},v=()=>{};const x=new Promise(((t,e)=>{U=t,v=e}));x.catch((()=>{}));let P={};const L={environment:l,parent:p,get error(){return A},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}),L);const a=o(s,f,h);return t(new Request(u,{method:n,headers:f,signal:r,body:a}),L)},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(L),"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 C(){return Promise.race([b,Promise.resolve().then((()=>e(L,(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(L)]),void 0!==n)break;if(n instanceof Response)return n;const r=new Headers(L.responseHeaders),{status:s}=L;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,U(),t)),(t=>(S=!0,A=t||!0,v(A),Promise.reject(t)))).catch(f)}return n?n(L,C):C()}(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}`.toLowerCase();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}}));
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.9.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=[],j=new Headers,E=p?.root;let R=200,A=!1,U=null,S=()=>{},P=()=>{};const x=new Promise(((t,e)=>{S=t,P=e}));x.catch((()=>{}));let L={};const v={environment:l,parent:p,get error(){return U},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}),v);const f=r(i,a,h);return t(new Request(u,{method:n,headers:a,signal:o,body:f}),v)},done(t,e){if(A)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(v),"function"!=typeof n)return;w.set(t,n)}return n(...e)},method:y,get params(){return L},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 A},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 C(){return Promise.race([b,Promise.resolve().then((()=>e(v,(t=>{L=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(v)]),void 0!==n)break;if(n instanceof Response)return n;const o=new Headers(v.responseHeaders),{status:s}=v;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=>(A=!0,S(),t)),(t=>(A=!0,U=t||!0,P(U),Promise.reject(t)))).catch(a)}return n?n(v,C):C()}(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}`.toLowerCase();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 A;return t.push({match:b(e,!1),router:r}),r}class A 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 U(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{A as MapRouter,S as Param,a as Router,p as bind,U as createFetch,u as main,l as make,h as service,y as stateService,d 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};
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
@@ -484,7 +484,7 @@ class Router {
484
484
  * @returns {Promise<T[] | null>}
485
485
  */
486
486
  static async find(routers, method, path, signal, setParams) {
487
- const m = `${method}`.toLowerCase();
487
+ const m = `${method}`.toUpperCase();
488
488
  for (const route of routers.flat()) {
489
489
  const res = await Router.#find(route, m, path, {}, signal, setParams);
490
490
  if (res) { return res; }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "k99",
3
3
  "description": "前后端均可用的 web 服务器",
4
- "version": "0.9.0",
4
+ "version": "0.9.1",
5
5
  "dependencies": {},
6
6
  "keywords": [
7
7
  "k99",
package/services.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
package/services.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
package/services.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
package/services.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
package/services.min.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
package/services.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * k99 v0.9.0
2
+ * k99 v0.9.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */