@lengkapp/edge 0.0.53 → 0.0.55
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/README.md +1 -0
- package/dist/README.md +1 -0
- package/dist/edge-client.js +2 -2
- package/dist/edge-server.d.ts +1 -1
- package/dist/edge-server.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/README.md
CHANGED
package/dist/edge-client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @lengkapp/edge v0.0.
|
|
2
|
+
* @lengkapp/edge v0.0.55
|
|
3
3
|
* MIT License
|
|
4
4
|
*
|
|
5
5
|
* LengkApp License
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
31
31
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
32
|
*/
|
|
33
|
-
!function(){if(!window.__ec){window.__ec=1;for(var r=document,n=window,t=0,o=r.currentScript,i=r.querySelector.bind(r),
|
|
33
|
+
!function(){if(!window.__ec){window.__ec=1;for(var r=document,n=window,t=0,o=r.currentScript,i=r.querySelector.bind(r),a=r.createElement.bind(r),e=r.addEventListener.bind(r),f=["click","submit","change","input","keyup","dblclick"],u=new WeakSet,v=new WeakSet,c=new WeakMap,l={},s=n.IntersectionObserver?new IntersectionObserver(function(r){for(var n=0;n<r.length;n++){var t=r[n];t.isIntersecting&&(s.unobserve(t.target),v.delete(t.target),b(t.target,"visible"))}}):null,_=0;_<f.length;_++)(function(r){e(r,function(n){var t=k(n.target,r);t&&(n.cancelable&&n.preventDefault(),l={},b(t,r))},!0)})(f[_]);new MutationObserver(function(r){for(var n=0;n<r.length;n++){var t,o=r[n].addedNodes,i=r[n].removedNodes;for(t=0;t<o.length;t++)1===o[t].nodeType&&g(o[t]);for(t=0;t<i.length;t++)O(i[t])}}).observe(r.documentElement,{childList:!0,subtree:!0}),"loading"===r.readyState?e("DOMContentLoaded",function(){g(r.body)}):g(r.body)}function w(r){return r.hasAttribute("_get")||r.hasAttribute("_post")}function d(r){if(!u.has(r)){u.add(r);var n=r.getAttribute("_in"),o=r.getAttribute("_out"),i=r.hasAttribute("_out")?!o||"this"===o:!n||"this"===n;w(r)&&!r.id&&i&&(r.id="_g"+ ++t);var a=r.getAttribute("_trigger");"load"===a?b(r,"load"):"visible"===a&&s&&(v.add(r),s.observe(r))}}function g(r){if(r&&1===r.nodeType){w(r)&&d(r);for(var n=r.querySelectorAll("[_get],[_post]"),t=0;t<n.length;t++)d(n[t])}}function m(r){for(var n=r.querySelectorAll("script,style"),t=0;t<n.length;t++){var i=n[t];if(!(i===o||o&&o.src&&i.src===o.src)){for(var e=a(i.tagName),f=0;f<i.attributes.length;f++)e.setAttribute(i.attributes[f].name,i.attributes[f].value);e.textContent=i.textContent,i.parentNode.replaceChild(e,i)}}}function h(r,n){var o=r.getAttribute(n);return o&&"this"!==o?o:(r.id||(r.id="_g"+ ++t),"#"+r.id)}function b(r,n){var t=r.getAttribute("_get"),o=r.getAttribute("_post");if(t||o){var a=t||o,e=t?"GET":"POST";if("load"!==n&&"visible"!==n||!((l[a]=(l[a]||0)+1)>8)){var f=c.get(r);f&&f.abort(),f=new AbortController,c.set(r,f);var u=null,v={"x-edge":"1"},s=function(){const r=[navigator.hardwareConcurrency,navigator.deviceMemory,navigator.userAgentData?.platform||navigator.platform,navigator.language,Intl.DateTimeFormat().resolvedOptions().timeZone].join("|");let n=2166136261;for(const t of r)n=Math.imul(n^t.charCodeAt(0),16777619)>>>0;let t="";for(;t.length<16;)n=Math.imul(n,1664525)+1013904223>>>0,t+="abcdefghijklmnopqrstuvwxyz0123456789"[n%36];return t}(),_=(i('meta[name="_csrf"]')||{}).content,w=(i('meta[name="_auth"]')||{}).content;if(_&&(v["x-csrf-token"]=_),w&&(v["x-auth-token"]=w),s&&(v["x-edge-id"]=s),"POST"===e){var d=r.getAttribute("_form"),g=r.getAttribute("_json");if(d){var m=i(d);m&&(u=new URLSearchParams(new FormData(m)).toString(),v["Content-Type"]="application/x-www-form-urlencoded")}else if(g){var b=i(g),k={};b&&("FORM"===b.tagName?new FormData(b).forEach(function(r,n){k[n]=r}):k[b.name||b.id]=b.value),u=JSON.stringify(k),v["Content-Type"]="application/json"}}var O=r.hasAttribute("_out"),M=h(r,O?"_out":"_in"),S=r.hasAttribute("_error");fetch(a,{method:e,headers:v,body:u,signal:f.signal}).then(function(n){return n.text().then(function(t){n.ok?p(M,t,O):S&&p(h(r,"_error"),t,!1)})}).catch(function(r){if(!r||"AbortError"!==r.name)throw r})}}}function p(r,n,t){var o=i(r);if(o)if(t){var e=o.parentNode;if(!e)return;var f=a("template");f.innerHTML=n,m(f.content);for(var u=[],v=f.content.firstChild;v;v=v.nextSibling)u.push(v);e.replaceChild(f.content,o);for(var c=0;c<u.length;c++)1===u[c].nodeType&&g(u[c])}else o.innerHTML=n,m(o),g(o)}function k(r,n){for(;r&&1===r.nodeType;){if(w(r)&&(r.getAttribute("_trigger")||("FORM"===r.tagName?"submit":"click"))===n)return r;r=r.parentNode}return null}function O(r){if(r&&1===r.nodeType){v.has(r)&&(s&&s.unobserve(r),v.delete(r));var n=c.get(r);n&&(n.abort(),c.delete(r));for(var t=r.getElementsByTagName("*"),o=0;o<t.length;o++){var i=t[o];v.has(i)&&(s&&s.unobserve(i),v.delete(i));var a=c.get(i);a&&(a.abort(),c.delete(i))}}}}();
|
package/dist/edge-server.d.ts
CHANGED
package/dist/edge-server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @lengkapp/edge v0.0.
|
|
2
|
+
* @lengkapp/edge v0.0.55
|
|
3
3
|
* MIT License
|
|
4
4
|
*
|
|
5
5
|
* LengkApp License
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
31
31
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
32
|
*/
|
|
33
|
-
function t(t){const e=[],n=t.length;let r=1;for(let o=1;o<=n;o++)o!==n&&47!==t.charCodeAt(o)||(o>r&&e.push(t.slice(r,o)),r=o+1);return e}function e(t){const e=t.length;return e>1&&47===t.charCodeAt(e-1)?t.slice(0,-1):t}function n(t,e){if(!e)return t||"/";if(!t||"/"===t)return 47===e.charCodeAt(0)?e:"/"+e;const n=t.charCodeAt(t.length-1),r=e.charCodeAt(0);let o;o=47===n?47===r?t+e.slice(1):t+e:47===r?t+e:t+"/"+e;const s=o.length;return s>1&&47===o.charCodeAt(s-1)?o.slice(0,-1):o}var r=new Set(["__proto__","constructor","prototype"]);function o(t){return"string"==typeof t&&!r.has(t)}function s(t){const e=t.length;let n=0;for(;n<e;){const e=t.charCodeAt(n);if(38===e||60===e||62===e||34===e||39===e)break;n++}if(n===e)return t;let r=t.slice(0,n),o=n;for(;n<e;n++){const e=t.charCodeAt(n);let s;if(38===e)s="&";else if(60===e)s="<";else if(62===e)s=">";else if(34===e)s=""";else{if(39!==e)continue;s="'"}n>o&&(r+=t.slice(o,n)),r+=s,o=n+1}return o<e&&(r+=t.slice(o)),r}function i(t){return t>=65&&t<=90||t>=97&&t<=122}function c(t){return t>=48&&t<=57}function a(t){const e=t.length;if(0===e)return!1;const n=t.charCodeAt(0);if(!i(n)&&95!==n&&58!==n)return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!i(e)&&!c(e)&&95!==e&&58!==e&&46!==e&&45!==e)return!1}return!0}function l(t){const e=t.charCodeAt(0),n=t.charCodeAt(1);return!(111!==e&&79!==e||110!==n&&78!==n)}var Fragment=Symbol("Fragment");function jsx(t,e,...n){return{type:t,props:e||{},children:n,__isJSX:!0}}var u=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),f=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),h=new Set(["animation-iteration-count","border-image-outset","border-image-slice","border-image-width","box-flex","box-flex-group","box-ordinal-group","column-count","columns","flex","flex-grow","flex-positive","flex-shrink","flex-negative","flex-order","grid-row","grid-row-end","grid-row-span","grid-row-start","grid-column","grid-column-end","grid-column-span","grid-column-start","font-weight","line-clamp","line-height","opacity","order","orphans","tab-size","widows","z-index","zoom","fill-opacity","flood-opacity","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-miterlimit","stroke-opacity","stroke-width"]),p=new Map;function d(t){const e=p.get(t);if(void 0!==e)return e;const n=t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,"");return p.size>=2e3&&p.clear(),p.set(t,n),n}function y(t){if(!t||"object"!=typeof t)return"";let e="";for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const r=d(n);let o=t[n];"number"!=typeof o||h.has(r)||(o+="px"),e&&(e+=";"),e+=r+":"+o}return e}var w=new Set(["href","src","xlink:href","action","formaction"]),m=[];function useCtx(){const t=m[m.length-1];if(!t)throw new Error("useCtx() must be called synchronously at the top of a component (before any await). It is not available after an await, nor outside a render.");return t}async function renderToString(t,e){if(void 0===e&&(e=m[m.length-1]),null==t||"boolean"==typeof t)return"";const n=typeof t;if("string"===n)return s(t);if("number"===n)return s(String(t));if("object"===n&&"function"==typeof t.then)return renderToString(await t,e);if(Array.isArray(t)){let n="";for(let r=0;r<t.length;r++)n+=await renderToString(t[r],e);return n}if(!t.__isJSX)return s(String(t));const{type:r,props:h,children:p}=t;if(r===Fragment){let t="";for(let n=0;n<p.length;n++)t+=await renderToString(p[n],e);return t}if("symbol"==typeof r)return"";if("function"==typeof r){let t;if(e){m.push(e);try{t=r({...h,children:p})}finally{m.pop()}}else t=r({...h,children:p});return renderToString(await t,e)}if("string"!=typeof r||!function(t){const e=t.length;if(0===e||!i(t.charCodeAt(0)))return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!i(e)&&!c(e)&&45!==e)return!1}return!0}(r))return"";const d=u.has(r);let g="";for(const t in h){if(!Object.prototype.hasOwnProperty.call(h,t))continue;if("children"===t||"key"===t||"ref"===t)continue;const e=h[t];if(null==e||!1===e)continue;if("dangerouslySetInnerHTML"===t)continue;let n=t;if("className"===t||"class"===t?n="class":"htmlFor"!==t&&"for"!==t||(n="for"),o(n)&&!l(n)&&a(n)){if(w.has(n)){const t=String(e).replace(/[\u0000-\u0020]/g,"").toLowerCase();if(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text/html"))continue}if(f.has(n))!0===e&&(g+=" "+n);else if(!0!==e){if("style"===n&&"object"==typeof e){const t=y(e);t&&(g+=' style="'+s(t)+'"');continue}g+=" "+n+'="'+s(String(e))+'"'}else g+=" "+n+'="true"'}}let b="";const S=h.dangerouslySetInnerHTML;if(S&&null!=S.__html)b=S.__html;else for(let t=0;t<p.length;t++)b+=await renderToString(p[t],e);return d?"<"+r+g+"/>":"<"+r+g+">"+b+"</"+r+">"}var g=Object.freeze([["X-Content-Type-Options","nosniff"],["X-Frame-Options","DENY"],["Referrer-Policy","strict-origin-when-cross-origin"],["Permissions-Policy","geolocation=(), microphone=(), camera=()"]]),b=Object.freeze(Object.create(null)),Context=class{constructor(t,e,n={},r=null,o=null){this.req=t,this.env=e,this.ctx=o,this.executionCtx=o,this.params=n,this.status=200,this.headers=new Headers(g),this.t=null,this.url=r||new URL(t.url)}o(){if(null!==this.t)return this.t;const t=this.req.headers.get("Cookie");if(!t)return this.t=b,b;const e=Object.create(null);let n=0;const r=t.length;for(;n<r;){let s=t.indexOf(";",n);-1===s&&(s=r);let i=n,c=s;for(;i<c&&32===t.charCodeAt(i);)i++;for(;c>i&&32===t.charCodeAt(c-1);)c--;if(c>i){const n=t.indexOf("=",i);if(n>i&&n<c)try{const r=decodeURIComponent(t.slice(i,n));o(r)&&(e[r]=decodeURIComponent(t.slice(n+1,c)))}catch{}}n=s+1}return this.t=e,e}getCookie(t){const e=this.o()[t];return void 0===e?null:e}get query(){return this.url.searchParams}waitUntil(t){return this.ctx&&"function"==typeof this.ctx.waitUntil&&this.ctx.waitUntil(t),t}passThroughOnException(){this.ctx&&"function"==typeof this.ctx.passThroughOnException&&this.ctx.passThroughOnException()}setCookie(t,e,n={}){if("string"!=typeof t||!o(t)||/[\r\n;=]/.test(t))return;let r=encodeURIComponent(t)+"="+encodeURIComponent(e);n.path&&(r+="; Path="+n.path),n.domain&&(r+="; Domain="+n.domain),void 0!==n.maxAge&&(r+="; Max-Age="+n.maxAge),n.expires&&(r+="; Expires="+n.expires.toUTCString()),n.secure&&(r+="; Secure"),n.httpOnly&&(r+="; HttpOnly"),n.sameSite&&(r+="; SameSite="+n.sameSite),this.headers.append("Set-Cookie",r)}deleteCookie(t,e={}){this.setCookie(t,"",{...e,maxAge:0,expires:new Date(0)})}i(t){if(!t)return this.headers;const e=Object.keys(t);if(0===e.length)return this.headers;const n=new Headers(this.headers);for(let r=0;r<e.length;r++)n.set(e[r],t[e[r]]);return n}text(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","text/plain; charset=utf-8"),new Response(t,{status:e,headers:r})}json(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(t),{status:e,headers:r})}async html(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),new Response(o,{status:e,headers:r})}async page(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),/^\s*<!doctype\s/i.test(o)||(o="<!DOCTYPE html>"+o),new Response(o,{status:e,headers:r})}redirect(t,e=302){const n=new Headers(this.headers);return n.set("Location",String(t)),n.delete("Content-Type"),new Response(null,{status:e,headers:n})}},S=class{constructor(){this.children=null,this.paramChild=null,this.handler=null}},C=class{constructor(){this.root=new S}add(t,e){let n=this.root;const r=[];for(let e=0;e<t.length;e++){const s=t[e];if(58===s.charCodeAt(0)){const t=s.slice(1);r.push(o(t)?t:"_p"+e),n.paramChild||(n.paramChild=new S),n=n.paramChild}else{n.children||(n.children=new Map);let t=n.children.get(s);t||(t=new S,n.children.set(s,t)),n=t}}n.handler={handler:e,paramNames:r}}match(t){const e=[],n=this.l(this.root,t,0,e);if(!n)return null;const{handler:r,paramNames:o}=n,s=Object.create(null);for(let t=0;t<o.length;t++)s[o[t]]=e[t];return{handler:r,params:s}}l(t,e,n,r){if(n===e.length)return t.handler;const o=e[n],s=t.children;if(s){const t=s.get(o);if(t){const o=this.l(t,e,n+1,r);if(o)return o}}const i=t.paramChild;if(i){r.push(o);const t=this.l(i,e,n+1,r);if(t)return t;r.pop()}return null}},x=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"],Edge=class r{constructor(t=""){this.prefix=t&&"/"!==t?e(t):"",this.staticRoutes=new Map;for(let t=0;t<x.length;t++)this.staticRoutes.set(x[t],new Map);this.dynamicTries={};for(let t=0;t<x.length;t++)this.dynamicTries[x[t]]=new C;this.u=[],this.scheduledHandler=null,this.notFoundHandler=null,this.errorHandler=null}set routes(t){const e=Array.isArray(t)?t:t?[t]:[];for(let t=0;t<e.length;t++){const n=e[t];if(!(n instanceof r))throw new Error("app.routes entries must be Edge instances");this.h(n)}}h(t){const e=t.u,r=this.prefix;for(let t=0;t<e.length;t++){const o=e[t],s=n(r,o.path);this.u.push({method:o.method,path:s,handler:o.handler}),this.p(o.method,s,o.handler)}}m(t,e,r,o){if("function"==typeof r&&(o=r),"function"!=typeof o)throw new Error("Handler for "+t+" "+e+" must be a function");const s=n(this.prefix,e);this.u.push({method:t,path:s,handler:o}),this.p(t,s,o)}p(e,n,r){-1===n.indexOf(":")?this.staticRoutes.get(e).set(n,r):this.dynamicTries[e].add(t(n),r)}get(t,e,n){this.m("GET",t,e,n)}post(t,e,n){this.m("POST",t,e,n)}put(t,e,n){this.m("PUT",t,e,n)}delete(t,e,n){this.m("DELETE",t,e,n)}patch(t,e,n){this.m("PATCH",t,e,n)}options(t,e,n){this.m("OPTIONS",t,e,n)}head(t,e,n){this.m("HEAD",t,e,n)}scheduled(t){this.scheduledHandler=t}notFound(t){if("function"!=typeof t)throw new Error("notFound(handler) requires a function");this.notFoundHandler=t}onError(t){if("function"!=typeof t)throw new Error("onError(handler) requires a function");this.errorHandler=t}S(t,e){const n=new Headers(e.headers);t.headers.forEach((t,e)=>{"set-cookie"!==e.toLowerCase()&&(n.has(e)||n.set(e,t))});const r="function"==typeof t.headers.getSetCookie?t.headers.getSetCookie():t.headers.get("Set-Cookie")?[t.headers.get("Set-Cookie")]:[];if(r.length){const t="function"==typeof n.getSetCookie?n.getSetCookie():n.get("Set-Cookie")?[n.get("Set-Cookie")]:[],e=new Set(t);for(let t=0;t<r.length;t++){const o=r[t];e.has(o)||(n.append("Set-Cookie",o),e.add(o))}}const o=204===e.status||304===e.status?null:e.body;return new Response(o,{status:e.status,statusText:e.statusText,headers:n})}async fetch(n,r,o){const s=new URL(n.url),i=e(s.pathname),c=n.method,a=this.staticRoutes.get(c);if(a){const t=a.get(i);if(t)return this.C(t,n,r,Object.create(null),s,o)}const l=this.dynamicTries[c];if(l){const e=l.match(t(i));if(e)return this.C(e.handler,n,r,e.params,s,o)}if("OPTIONS"===c){const t=new Context(n,r,Object.create(null),s,o);return this.S(t,new Response(null,{status:204}))}if(this.notFoundHandler)return this.C(this.notFoundHandler,n,r,Object.create(null),s,o);const u=new Context(n,r,Object.create(null),s,o);return this.S(u,new Response("Not Found",{status:404}))}async O(t,e){const n=this.errorHandler;if(!n)return t.text("Internal Server Error",500);try{const r=await n(t,e);return r instanceof Response?this.S(t,r):r&&r.__isJSX||Array.isArray(r)?t.html(r,500):t.text("Internal Server Error",500)}catch{return t.text("Internal Server Error",500)}}async C(t,e,n,r,o,s){const i=new Context(e,n,r,o,s);let c;try{const e=await t(i);c=e instanceof Response?this.S(i,e):e&&e.__isJSX?await i.html(e):i.text("OK")}catch(t){c=await this.O(i,t)}return c}},O=Edge;export{Context,Edge,Fragment,O as default,jsx,renderToString,useCtx};
|
|
33
|
+
function t(t){const e=[],n=t.length;let r=1;for(let o=1;o<=n;o++)o!==n&&47!==t.charCodeAt(o)||(o>r&&e.push(t.slice(r,o)),r=o+1);return e}function e(t){const e=t.length;return e>1&&47===t.charCodeAt(e-1)?t.slice(0,-1):t}function n(t,e){if(!e)return t||"/";if(!t||"/"===t)return 47===e.charCodeAt(0)?e:"/"+e;const n=t.charCodeAt(t.length-1),r=e.charCodeAt(0);let o;o=47===n?47===r?t+e.slice(1):t+e:47===r?t+e:t+"/"+e;const s=o.length;return s>1&&47===o.charCodeAt(s-1)?o.slice(0,-1):o}var r=new Set(["__proto__","constructor","prototype"]);function o(t){return"string"==typeof t&&!r.has(t)}function s(t){const e=t.length;let n=0;for(;n<e;){const e=t.charCodeAt(n);if(38===e||60===e||62===e||34===e||39===e)break;n++}if(n===e)return t;let r=t.slice(0,n),o=n;for(;n<e;n++){const e=t.charCodeAt(n);let s;if(38===e)s="&";else if(60===e)s="<";else if(62===e)s=">";else if(34===e)s=""";else{if(39!==e)continue;s="'"}n>o&&(r+=t.slice(o,n)),r+=s,o=n+1}return o<e&&(r+=t.slice(o)),r}function i(t){return t>=65&&t<=90||t>=97&&t<=122}function c(t){return t>=48&&t<=57}function a(t){const e=t.length;if(0===e)return!1;const n=t.charCodeAt(0);if(!i(n)&&95!==n&&58!==n)return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!i(e)&&!c(e)&&95!==e&&58!==e&&46!==e&&45!==e)return!1}return!0}function l(t){const e=t.charCodeAt(0),n=t.charCodeAt(1);return!(111!==e&&79!==e||110!==n&&78!==n)}var Fragment=Symbol("Fragment");function jsx(t,e,...n){return{type:t,props:e||{},children:n,__isJSX:!0}}var u=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),f=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),h=new Set(["animation-iteration-count","border-image-outset","border-image-slice","border-image-width","box-flex","box-flex-group","box-ordinal-group","column-count","columns","flex","flex-grow","flex-positive","flex-shrink","flex-negative","flex-order","grid-row","grid-row-end","grid-row-span","grid-row-start","grid-column","grid-column-end","grid-column-span","grid-column-start","font-weight","line-clamp","line-height","opacity","order","orphans","tab-size","widows","z-index","zoom","fill-opacity","flood-opacity","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-miterlimit","stroke-opacity","stroke-width"]),p=new Map;function d(t){const e=p.get(t);if(void 0!==e)return e;const n=t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,"");return p.size>=2e3&&p.clear(),p.set(t,n),n}function y(t){if(!t||"object"!=typeof t)return"";let e="";for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const r=d(n);let o=t[n];"number"!=typeof o||h.has(r)||(o+="px"),e&&(e+=";"),e+=r+":"+o}return e}var w=new Set(["href","src","xlink:href","action","formaction"]),m=[];function useCtx(){const t=m[m.length-1];if(!t)throw new Error("useCtx() must be called synchronously at the top of a component (before any await). It is not available after an await, nor outside a render.");return t}async function renderToString(t,e){if(void 0===e&&(e=m[m.length-1]),null==t||"boolean"==typeof t)return"";const n=typeof t;if("string"===n)return s(t);if("number"===n)return s(String(t));if("object"===n&&"function"==typeof t.then)return renderToString(await t,e);if(Array.isArray(t)){let n="";for(let r=0;r<t.length;r++)n+=await renderToString(t[r],e);return n}if(!t.__isJSX)return s(String(t));const{type:r,props:h,children:p}=t;if(r===Fragment){let t="";for(let n=0;n<p.length;n++)t+=await renderToString(p[n],e);return t}if("symbol"==typeof r)return"";if("function"==typeof r){let t;if(e){m.push(e);try{t=r({...h,children:p})}finally{m.pop()}}else t=r({...h,children:p});return renderToString(await t,e)}if("string"!=typeof r||!function(t){const e=t.length;if(0===e||!i(t.charCodeAt(0)))return!1;for(let n=1;n<e;n++){const e=t.charCodeAt(n);if(!i(e)&&!c(e)&&45!==e)return!1}return!0}(r))return"";const d=u.has(r);let g="";for(const t in h){if(!Object.prototype.hasOwnProperty.call(h,t))continue;if("children"===t||"key"===t||"ref"===t)continue;const e=h[t];if(null==e||!1===e)continue;if("dangerouslySetInnerHTML"===t)continue;let n=t;if("className"===t||"class"===t?n="class":"htmlFor"!==t&&"for"!==t||(n="for"),o(n)&&!l(n)&&a(n)){if(w.has(n)){const t=String(e).replace(/[\u0000-\u0020]/g,"").toLowerCase();if(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text/html"))continue}if(f.has(n))!0===e&&(g+=" "+n);else if(!0!==e){if("style"===n&&"object"==typeof e){const t=y(e);t&&(g+=' style="'+s(t)+'"');continue}g+=" "+n+'="'+s(String(e))+'"'}else g+=" "+n+'="true"'}}let b="";const S=h.dangerouslySetInnerHTML;if(S&&null!=S.__html)b=S.__html;else for(let t=0;t<p.length;t++)b+=await renderToString(p[t],e);return d?"<"+r+g+"/>":"<"+r+g+">"+b+"</"+r+">"}var g=Object.freeze([["X-Content-Type-Options","nosniff"],["X-Frame-Options","DENY"],["Referrer-Policy","strict-origin-when-cross-origin"],["Permissions-Policy","geolocation=(), microphone=(), camera=()"]]),b=Object.freeze(Object.create(null)),Context=class{constructor(t,e,n={},r=null,o=null){this.req=t,this.env=e,this.ctx=o,this.executionCtx=o,this.params=n,this.status=200,this.headers=new Headers(g),this.t=null,this.url=r||new URL(t.url)}o(){if(null!==this.t)return this.t;const t=this.req.headers.get("Cookie");if(!t)return this.t=b,b;const e=Object.create(null);let n=0;const r=t.length;for(;n<r;){let s=t.indexOf(";",n);-1===s&&(s=r);let i=n,c=s;for(;i<c&&32===t.charCodeAt(i);)i++;for(;c>i&&32===t.charCodeAt(c-1);)c--;if(c>i){const n=t.indexOf("=",i);if(n>i&&n<c)try{const r=decodeURIComponent(t.slice(i,n));o(r)&&(e[r]=decodeURIComponent(t.slice(n+1,c)))}catch{}}n=s+1}return this.t=e,e}getCookie(t){const e=this.o()[t];return void 0===e?null:e}get query(){return this.url.searchParams}waitUntil(t){return this.ctx&&"function"==typeof this.ctx.waitUntil&&this.ctx.waitUntil(t),t}passThroughOnException(){this.ctx&&"function"==typeof this.ctx.passThroughOnException&&this.ctx.passThroughOnException()}setCookie(t,e,n={}){if("string"!=typeof t||!o(t)||/[\r\n;=]/.test(t))return;let r=encodeURIComponent(t)+"="+encodeURIComponent(e);n.path&&(r+="; Path="+n.path),n.domain&&(r+="; Domain="+n.domain),void 0!==n.maxAge&&(r+="; Max-Age="+n.maxAge),n.expires&&(r+="; Expires="+n.expires.toUTCString()),n.secure&&(r+="; Secure"),n.httpOnly&&(r+="; HttpOnly"),n.sameSite&&(r+="; SameSite="+n.sameSite),this.headers.append("Set-Cookie",r)}deleteCookie(t,e={}){this.setCookie(t,"",{...e,maxAge:0,expires:new Date(0)})}i(t){if(!t)return this.headers;const e=Object.keys(t);if(0===e.length)return this.headers;const n=new Headers(this.headers);for(let r=0;r<e.length;r++)n.set(e[r],t[e[r]]);return n}text(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","text/plain; charset=utf-8"),new Response(t,{status:e,headers:r})}json(t,e=this.status,n={}){const r=this.i(n);return r.has("Content-Type")||r.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(t),{status:e,headers:r})}async html(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),new Response(o,{status:e,headers:r})}async page(t,e=this.status,n={}){const r=this.i(n);let o;return r.has("Content-Type")||r.set("Content-Type","text/html; charset=utf-8"),o="string"==typeof t?t:t&&t.__isJSX||Array.isArray(t)?await renderToString(t,this):null==t?"":String(t),/^\s*<!doctype\s/i.test(o)||(o="<!DOCTYPE html>"+o),new Response(o,{status:e,headers:r})}redirect(t,e=302){const n=new Headers(this.headers);return n.set("Location",String(t)),n.delete("Content-Type"),new Response(null,{status:e,headers:n})}},S=class{constructor(){this.children=null,this.paramChild=null,this.handler=null,this.wildcardHandler=null}},C=class{constructor(){this.root=new S}add(t,e){let n=this.root;const r=[];for(let s=0;s<t.length;s++){const i=t[s];if("*"===i)return void(n.wildcardHandler={handler:e,paramNames:r.slice()});if(58===i.charCodeAt(0)){const t=i.slice(1);r.push(o(t)?t:"_p"+s),n.paramChild||(n.paramChild=new S),n=n.paramChild}else{n.children||(n.children=new Map);let t=n.children.get(i);t||(t=new S,n.children.set(i,t)),n=t}}n.handler={handler:e,paramNames:r}}match(t){const e=[],n=this.l(this.root,t,0,e);if(!n)return null;const{handler:r,paramNames:o}=n,s=Object.create(null);for(let t=0;t<o.length;t++)s[o[t]]=e[t];return{handler:r,params:s}}l(t,e,n,r){if(n===e.length)return t.handler||t.wildcardHandler;const o=e[n],s=t.children;if(s){const t=s.get(o);if(t){const o=this.l(t,e,n+1,r);if(o)return o}}const i=t.paramChild;if(i){r.push(o);const t=this.l(i,e,n+1,r);if(t)return t;r.pop()}return t.wildcardHandler?t.wildcardHandler:null}},x=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"],Edge=class r{constructor(t=""){this.prefix=t&&"/"!==t?e(t):"",this.staticRoutes=new Map;for(let t=0;t<x.length;t++)this.staticRoutes.set(x[t],new Map);this.dynamicTries={};for(let t=0;t<x.length;t++)this.dynamicTries[x[t]]=new C;this.u=[],this.scheduledHandler=null,this.notFoundHandler=null,this.errorHandler=null}set routes(t){const e=Array.isArray(t)?t:t?[t]:[];for(let t=0;t<e.length;t++){const n=e[t];if(!(n instanceof r))throw new Error("app.routes entries must be Edge instances");this.h(n)}}h(t){const e=t.u,r=this.prefix;for(let t=0;t<e.length;t++){const o=e[t],s=n(r,o.path);this.u.push({method:o.method,path:s,handler:o.handler}),this.p(o.method,s,o.handler)}}m(t,e,r,o){if("function"==typeof r&&(o=r),"function"!=typeof o)throw new Error("Handler for "+t+" "+e+" must be a function");const s=n(this.prefix,e);this.u.push({method:t,path:s,handler:o}),this.p(t,s,o)}p(e,n,r){-1===n.indexOf(":")&&-1===n.indexOf("*")?this.staticRoutes.get(e).set(n,r):this.dynamicTries[e].add(t(n),r)}get(t,e,n){this.m("GET",t,e,n)}post(t,e,n){this.m("POST",t,e,n)}put(t,e,n){this.m("PUT",t,e,n)}delete(t,e,n){this.m("DELETE",t,e,n)}patch(t,e,n){this.m("PATCH",t,e,n)}options(t,e,n){this.m("OPTIONS",t,e,n)}head(t,e,n){this.m("HEAD",t,e,n)}scheduled(t){this.scheduledHandler=t}notFound(t){if("function"!=typeof t)throw new Error("notFound(handler) requires a function");this.notFoundHandler=t}onError(t){if("function"!=typeof t)throw new Error("onError(handler) requires a function");this.errorHandler=t}S(t,e){const n=new Headers(e.headers);t.headers.forEach((t,e)=>{"set-cookie"!==e.toLowerCase()&&(n.has(e)||n.set(e,t))});const r="function"==typeof t.headers.getSetCookie?t.headers.getSetCookie():t.headers.get("Set-Cookie")?[t.headers.get("Set-Cookie")]:[];if(r.length){const t="function"==typeof n.getSetCookie?n.getSetCookie():n.get("Set-Cookie")?[n.get("Set-Cookie")]:[],e=new Set(t);for(let t=0;t<r.length;t++){const o=r[t];e.has(o)||(n.append("Set-Cookie",o),e.add(o))}}const o=204===e.status||304===e.status?null:e.body;return new Response(o,{status:e.status,statusText:e.statusText,headers:n})}async fetch(n,r,o){const s=new URL(n.url),i=e(s.pathname),c=n.method,a=this.staticRoutes.get(c);if(a){const t=a.get(i);if(t)return this.C(t,n,r,Object.create(null),s,o)}const l=this.dynamicTries[c];if(l){const e=l.match(t(i));if(e)return this.C(e.handler,n,r,e.params,s,o)}if("OPTIONS"===c){const t=new Context(n,r,Object.create(null),s,o);return this.S(t,new Response(null,{status:204}))}if(this.notFoundHandler)return this.C(this.notFoundHandler,n,r,Object.create(null),s,o);const u=new Context(n,r,Object.create(null),s,o);return this.S(u,new Response("Not Found",{status:404}))}async O(t,e){const n=this.errorHandler;if(!n)return t.text("Internal Server Error",500);try{const r=await n(t,e);return r instanceof Response?this.S(t,r):r&&r.__isJSX||Array.isArray(r)?t.html(r,500):t.text("Internal Server Error",500)}catch{return t.text("Internal Server Error",500)}}async C(t,e,n,r,o,s){const i=new Context(e,n,r,o,s);let c;try{const e=await t(i);c=e instanceof Response?this.S(i,e):e&&e.__isJSX?await i.html(e):i.text("OK")}catch(t){c=await this.O(i,t)}return c}},O=Edge;export{Context,Edge,Fragment,O as default,jsx,renderToString,useCtx};
|