@webtypen/webframez-react 0.0.46 → 0.0.48

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/dist/client.cjs CHANGED
@@ -1 +1 @@
1
- var fe=Object.create;var E=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of me(t))!he.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(o=pe(t,r))||o.enumerable});return e};var M=(e,t,n)=>(n=e!=null?fe(Re(e)):{},D(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),we=e=>D(E({},"__esModule",{value:!0}),e);var Fe={};_e(Fe,{mountWebframezClient:()=>We,useCookie:()=>ke,useRouter:()=>Ue});module.exports=we(Fe);var s=M(require("react"),1),Q=require("react-dom/client"),h=require("react-server-dom-webpack/client"),ee=require("@webtypen/webframez-react/route-slot");var ge=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function l(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function $(e,t){let n=e.trim(),o=l(t);return!n||!o||ge.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function x(e,t){if(!e)return;let n=l(e.basename)??l(t),o=l(e.routeBasePath),r=l(e.transportBasePath),a={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return a.favicon&&(a.favicon=$(a.favicon,n)),a.links&&(a.links=a.links.map(c=>({...c,href:$(c.href,n)}))),a}var p=M(require("react"),1),G="webframez-route-children",q="__webframezRouteChildren",Y="WebframezRouteChildren",Ce="__webframezRouteChildrenSlot",ye="WebframezRouteChildrenSlot",I=()=>p.default.createElement(G);I.displayName=Y;I[q]=!0;var Ee=I;function W(e){if(e===G||e===Ee)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[q]===!0||t.displayName===Y||t.name==="RouteChildren"}catch{return!1}}function F(e){if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[Ce]===!0||t.displayName===ye||t.name==="RouteChildrenSlot"}catch{return!1}}function j(e){if(!e||typeof e!="object")return!1;try{return"type"in e&&"props"in e}catch{return!1}}function T(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let u=!1,_=e.map(m=>{let w=T(m,t);return w!==m&&(u=!0),w});return u?_:e}if(j(e)&&(W(e.type)||F(e.type)))return t;let n=p.default.isValidElement(e);if(!n&&!j(e))return e;if(n&&(W(e.type)||F(e.type)))return t;let o=e.props??{};if(!("children"in o))return e;let r=T(o.children,t);if(r===o.children)return e;if(n)return Array.isArray(r)?p.default.cloneElement(e,void 0,...r):p.default.cloneElement(e,void 0,r);let a=e,c={...a.props??{},children:r,...a.key!==void 0&&a.key!==null?{key:a.key}:{}};return p.default.createElement(a.type,c)}var d=require("react/jsx-runtime"),Te={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},A=typeof s.default.createContext=="function"?s.default.createContext(null):null,te="__WEBFRAMEZ_ROUTER__",Ae="__WEBFRAMEZ_REACT_BUILD_ID",Ne="x-webframez-react-build",Se="[data-webframez-head='true']";function Z(){if(typeof window>"u"||typeof document>"u")return;let e=()=>{window.scrollTo({top:0,left:0}),document.scrollingElement&&(document.scrollingElement.scrollTop=0),document.documentElement.scrollTop=0,document.body&&(document.body.scrollTop=0)};if(typeof window.requestAnimationFrame=="function"){window.requestAnimationFrame(e);return}window.setTimeout(e,0)}function b(e){return l(e)??""}function Pe(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function ne(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function xe(){return b(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function oe(e){if(typeof window>"u")return e||"/";let t=b(window.__RSC_BASENAME),n=xe(),o=Pe(e||"/",t);return ne(n,o)}function re(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function Ie(){if(typeof window>"u")return"";let e=window[Ae];return typeof e=="string"?e:""}function ve(e){let t=Ie();return!!t&&!!e&&t!==e}function v(e){typeof window>"u"||window.location.assign(`${e.pathname}${e.search}${e.hash}`)}function Le(){return typeof window>"u"?null:window[te]??null}function be(e){typeof window>"u"||(window[te]=e)}function Be(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function Oe(e){return Be(e)?s.default.use(e):e}function N(e){let t=Oe(e);if(Array.isArray(t)){let r=!1,a=t.map(c=>{let u=N(c);return u!==c&&(r=!0),u});return r?a:t}if(!s.default.isValidElement(t))return t;let n=t.props;if(!("children"in n))return t;let o=N(n.children);return o===n.children?t:Array.isArray(o)?s.default.cloneElement(t,void 0,...o):s.default.cloneElement(t,void 0,o)}function K(){let e={},t=typeof document>"u"?"":document.cookie;if(!t||t.trim()==="")return e;for(let n of t.split(";")){let o=n.trim();if(!o)continue;let r=o.indexOf("="),a=r>=0?o.slice(0,r).trim():o,c=r>=0?o.slice(r+1):"";a&&(e[a]=decodeURIComponent(c))}return e}function V(e,t,n={}){let o=[`${e}=${encodeURIComponent(t)}`];return n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),typeof n.maxAge=="number"&&o.push(`Max-Age=${Math.floor(n.maxAge)}`),n.expires&&o.push(`Expires=${n.expires.toUTCString()}`),n.sameSite&&o.push(`SameSite=${n.sameSite}`),n.secure&&o.push("Secure"),o.join("; ")}function ke(){return s.default.useMemo(()=>({all:()=>K(),get:e=>K()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=V(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=V(e,"",{...t??{},maxAge:0}))}}),[])}function Ue(){let e=A?s.default.useContext(A):null;if(!e){let t=Le();if(t)return t;if(typeof window>"u")return Te;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function He({active:e}){return(0,d.jsx)("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:3,zIndex:9999,transformOrigin:"left",transform:e?"scaleX(1)":"scaleX(0)",transition:"transform 180ms ease",background:"linear-gradient(90deg, #0ea5e9, #22c55e)"}})}function X(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function J(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function L(e){if(typeof document>"u")return;let t=x(e)??e;ie(t),document.body.className=t.bodyClassName||"",document.title=t.title||"Webframez React";for(let n of document.head.querySelectorAll(Se))n.remove();t.description&&X({name:"description",content:t.description}),t.favicon&&J({rel:"icon",href:t.favicon});for(let n of t.meta??[])X(n);for(let n of t.links??[])J(n)}function ie(e){if(typeof window>"u")return;let t=x(e)??e,n=l(t.basename),o=l(t.routeBasePath),r=l(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=ne(r,"/rsc"))}function ze(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function De(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,h.createFromReadableStream)(ze(e)))}function Me(e){let t=re(e),n=oe(window.location.pathname);return De()??(0,h.createFromFetch)(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function $e(e,t){return function(){let o=s.default.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[a,c]=(0,s.useState)(o.model),[u,_]=(0,s.useState)(o.contextModel),[m,w]=(0,s.useState)(o.pageModel),[B,O]=(0,s.useState)(o.head),[ae,g]=(0,s.useState)(!1),[se,ce]=(0,s.useState)(!1),[de,S]=(0,s.useState)(r);async function k(i){let y=re(t),f=oe(i.pathname),R=await fetch(`${y}?path=${encodeURIComponent(f)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return ve(R.headers.get(Ne))?(v(i),await new Promise(()=>{})):await(0,h.createFromFetch)(Promise.resolve(R))}async function C(i,y="push"){g(!0);try{let f=await k(i);L(f.head),O(f.head),c(f.model),_(f.contextModel),w(f.pageModel),S(!1);let R=`${i.pathname}${i.search}${i.hash}`;y==="replace"?(history.replaceState(null,"",R),Z()):y==="push"&&(history.pushState(null,"",R),Z())}catch(f){console.error("[webframez-react] Failed to render route",f),v(i),c((0,d.jsx)("p",{children:"Failed to load route."}))}finally{g(!1)}}async function ue(){g(!0);try{let i=await k(new URL(window.location.href));if(L(i.head),O(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){_(i.contextModel),S(!0);return}c(i.model),S(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i),v(new URL(window.location.href))}finally{g(!1)}}(0,s.useEffect)(()=>{L(B)},[B]),(0,s.useEffect)(()=>{ce(!0);let i=()=>{C(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let U=s.default.useMemo(()=>({push:i=>{C(new URL(i,window.location.origin),"push")},replace:i=>{C(new URL(i,window.location.origin),"replace")},refresh:()=>{C(new URL(window.location.href),"none")},refreshContext:()=>{ue()}}),[]);be(U);let H=N(u),P=N(m),le=de&&typeof m<"u"?H?(0,d.jsx)(ee.RouteChildrenSlotProvider,{page:P,children:T(H,P)}):P:a,z=(0,d.jsxs)(d.Fragment,{children:[se?(0,d.jsx)(He,{active:ae}):null,le??(0,d.jsx)("p",{style:{padding:24},children:"Loading..."})]});return A?(0,d.jsx)(A.Provider,{value:U,children:z}):z}}function We(e={}){let t=e.rootId??"root",n=document.getElementById(t);if(!n)throw new Error(`Missing #${t} element`);let o=typeof window<"u"&&window.__RSC_ENDPOINT,r=e.rscEndpoint??o??"/rsc",a=Promise.resolve(Me(r)).then(u=>(u?.head&&ie(u.head),u)),c=$e(a,r);return(0,Q.hydrateRoot)(n,(0,d.jsx)(c,{}))}
1
+ var le=Object.create;var E=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var ge=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of me(t))!Re.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(o=fe(t,r))||o.enumerable});return e};var D=(e,t,n)=>(n=e!=null?le(pe(e)):{},$(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),he=e=>$(E({},"__esModule",{value:!0}),e);var qe={};ge(qe,{mountWebframezClient:()=>Ge,useCookie:()=>Be,useRouter:()=>He});module.exports=he(qe);var c=D(require("react"),1),J=require("react-dom/client"),h=require("react-server-dom-webpack/client"),Q=require("@webtypen/webframez-react/route-slot");var we=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function l(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function W(e,t){let n=e.trim(),o=l(t);return!n||!o||we.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function P(e,t){if(!e)return;let n=l(e.basename)??l(t),o=l(e.routeBasePath),r=l(e.transportBasePath),i={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return i.favicon&&(i.favicon=W(i.favicon,n)),i.links&&(i.links=i.links.map(s=>({...s,href:W(s.href,n)}))),i}var m=D(require("react"),1),q="webframez-route-children",K="__webframezRouteChildren",Y="WebframezRouteChildren",_e="__webframezRouteChildrenSlot",ye="WebframezRouteChildrenSlot",L=()=>m.default.createElement(q);L.displayName=Y;L[K]=!0;var Ce=L;function F(e){if(e===q||e===Ce)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[K]===!0||t.displayName===Y||t.name==="RouteChildren"}catch{return!1}}function j(e){if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[_e]===!0||t.displayName===ye||t.name==="RouteChildrenSlot"}catch{return!1}}function G(e){if(!e||typeof e!="object")return!1;try{return"type"in e&&"props"in e}catch{return!1}}function T(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let u=!1,w=e.map(p=>{let R=T(p,t);return R!==p&&(u=!0),R});return u?w:e}if(G(e)&&(F(e.type)||j(e.type)))return t;let n=m.default.isValidElement(e);if(!n&&!G(e))return e;if(n&&(F(e.type)||j(e.type)))return t;let o=e.props??{};if(!("children"in o))return e;let r=T(o.children,t);if(r===o.children)return e;if(n)return Array.isArray(r)?m.default.cloneElement(e,void 0,...r):m.default.cloneElement(e,void 0,r);let i=e,s={...i.props??{},children:r,...i.key!==void 0&&i.key!==null?{key:i.key}:{}};return m.default.createElement(i.type,s)}var d=require("react/jsx-runtime"),Ee={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},N=typeof c.default.createContext=="function"?c.default.createContext(null):null,ee="__WEBFRAMEZ_ROUTER__",Te="__WEBFRAMEZ_REACT_BUILD_ID",Ne="x-webframez-react-build",Ae="[data-webframez-head='true']";function Z(){if(typeof window>"u"||typeof document>"u")return;let e=()=>{window.scrollTo({top:0,left:0}),document.scrollingElement&&(document.scrollingElement.scrollTop=0),document.documentElement.scrollTop=0,document.body&&(document.body.scrollTop=0)};if(typeof window.requestAnimationFrame=="function"){window.requestAnimationFrame(e);return}window.setTimeout(e,0)}function x(e){return l(e)??""}function Se(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function te(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function Pe(){return x(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function ne(e){if(typeof window>"u")return e||"/";let t=x(window.__RSC_BASENAME),n=Pe(),o=Se(e||"/",t);return te(n,o)}function oe(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function Le(){if(typeof window>"u")return"";let e=window[Te];return typeof e=="string"?e:""}function ve(e){let t=Le();return!!t&&!!e&&t!==e}function v(e){typeof window>"u"||window.location.assign(`${e.pathname}${e.search}${e.hash}`)}function Ie(){return typeof window>"u"?null:window[ee]??null}function xe(e){typeof window>"u"||(window[ee]=e)}function be(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function ke(e){return be(e)?c.default.use(e):e}function A(e){let t=ke(e);if(Array.isArray(t)){let r=!1,i=t.map(s=>{let u=A(s);return u!==s&&(r=!0),u});return r?i:t}if(!c.default.isValidElement(t))return t;let n=t.props;if(!("children"in n))return t;let o=A(n.children);return o===n.children?t:Array.isArray(o)?c.default.cloneElement(t,void 0,...o):c.default.cloneElement(t,void 0,o)}function V(){let e={},t=typeof document>"u"?"":document.cookie;if(!t||t.trim()==="")return e;for(let n of t.split(";")){let o=n.trim();if(!o)continue;let r=o.indexOf("="),i=r>=0?o.slice(0,r).trim():o,s=r>=0?o.slice(r+1):"";i&&(e[i]=decodeURIComponent(s))}return e}function X(e,t,n={}){let o=[`${e}=${encodeURIComponent(t)}`];return n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),typeof n.maxAge=="number"&&o.push(`Max-Age=${Math.floor(n.maxAge)}`),n.expires&&o.push(`Expires=${n.expires.toUTCString()}`),n.sameSite&&o.push(`SameSite=${n.sameSite}`),n.secure&&o.push("Secure"),o.join("; ")}function Be(){return c.default.useMemo(()=>({all:()=>V(),get:e=>V()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=X(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=X(e,"",{...t??{},maxAge:0}))}}),[])}function He(){let e=N?c.default.useContext(N):null;if(!e){let t=Ie();if(t)return t;if(typeof window>"u")return Ee;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Oe({active:e}){return(0,d.jsx)("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:3,zIndex:9999,transformOrigin:"left",transform:e?"scaleX(1)":"scaleX(0)",transition:"transform 180ms ease",background:"linear-gradient(90deg, #0ea5e9, #22c55e)"}})}function Ue(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function Me(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function b(e,t){let n=Object.entries(t).filter(([o,r])=>o!=="data-webframez-head"&&!!r).map(([o,r])=>[o.toLowerCase(),String(r)]).sort(([o],[r])=>o.localeCompare(r));return`${e.toLowerCase()}:${n.map(([o,r])=>`${o}=${r}`).join(";")}`}function ze(e){let t={};for(let n of Array.from(e.attributes))t[n.name]=n.value;return b(e.tagName,t)}function $e(e){let t=[];e.description&&t.push({tagName:"meta",attrs:{name:"description",content:e.description}}),e.favicon&&t.push({tagName:"link",attrs:{rel:"icon",href:e.favicon}});for(let n of e.meta??[])t.push({tagName:"meta",attrs:n});for(let n of e.links??[])t.push({tagName:"link",attrs:n});return t}function I(e){if(typeof document>"u")return;let t=P(e)??e;re(t),document.body.className=t.bodyClassName||"",document.title=t.title||"Webframez React";let n=$e(t),o=new Set(n.map(i=>b(i.tagName,i.attrs))),r=new Set;for(let i of document.head.querySelectorAll(Ae)){let s=ze(i);if(o.has(s)&&!r.has(s)){r.add(s);continue}i.remove()}for(let i of n){let s=b(i.tagName,i.attrs);r.has(s)||(i.tagName==="meta"?Ue(i.attrs):Me(i.attrs),r.add(s))}}function re(e){if(typeof window>"u")return;let t=P(e)??e,n=l(t.basename),o=l(t.routeBasePath),r=l(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=te(r,"/rsc"))}function De(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function We(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,h.createFromReadableStream)(De(e)))}function Fe(e){let t=oe(e),n=ne(window.location.pathname);return We()??(0,h.createFromFetch)(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function je(e,t){return function(){let o=c.default.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[i,s]=(0,c.useState)(o.model),[u,w]=(0,c.useState)(o.contextModel),[p,R]=(0,c.useState)(o.pageModel),[k,B]=(0,c.useState)(o.head),[ie,_]=(0,c.useState)(!1),[ae,se]=(0,c.useState)(!1),[ce,H]=(0,c.useState)(r);async function O(a){let C=oe(t),f=ne(a.pathname),g=await fetch(`${C}?path=${encodeURIComponent(f)}&search=${encodeURIComponent(a.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return ve(g.headers.get(Ne))?(v(a),await new Promise(()=>{})):await(0,h.createFromFetch)(Promise.resolve(g))}async function y(a,C="push"){_(!0);try{let f=await O(a);I(f.head),B(f.head),s(f.model),w(f.contextModel),R(f.pageModel),H(!1);let g=`${a.pathname}${a.search}${a.hash}`;C==="replace"?(history.replaceState(null,"",g),Z()):C==="push"&&(history.pushState(null,"",g),Z())}catch(f){console.error("[webframez-react] Failed to render route",f),v(a),s((0,d.jsx)("p",{children:"Failed to load route."}))}finally{_(!1)}}async function de(){_(!0);try{let a=await O(new URL(window.location.href));I(a.head),B(a.head),s(a.model),w(a.contextModel),R(a.pageModel),H(!1)}catch(a){console.error("[webframez-react] Failed to refresh route context",a),v(new URL(window.location.href))}finally{_(!1)}}(0,c.useEffect)(()=>{I(k)},[k]),(0,c.useEffect)(()=>{se(!0);let a=()=>{y(new URL(window.location.href),"none")};return window.addEventListener("popstate",a),()=>{window.removeEventListener("popstate",a)}},[]);let U=c.default.useMemo(()=>({push:a=>{y(new URL(a,window.location.origin),"push")},replace:a=>{y(new URL(a,window.location.origin),"replace")},refresh:()=>{y(new URL(window.location.href),"none")},refreshContext:()=>{de()}}),[]);xe(U);let M=A(u),S=A(p),ue=ce&&typeof p<"u"?M?(0,d.jsx)(Q.RouteChildrenSlotProvider,{page:S,children:T(M,S)}):S:i,z=(0,d.jsxs)(d.Fragment,{children:[ae?(0,d.jsx)(Oe,{active:ie}):null,ue??(0,d.jsx)("p",{style:{padding:24},children:"Loading..."})]});return N?(0,d.jsx)(N.Provider,{value:U,children:z}):z}}function Ge(e={}){let t=e.rootId??"root",n=document.getElementById(t);if(!n)throw new Error(`Missing #${t} element`);let o=typeof window<"u"&&window.__RSC_ENDPOINT,r=e.rscEndpoint??o??"/rsc",i=Promise.resolve(Fe(r)).then(u=>(u?.head&&re(u.head),u)),s=je(i,r);return(0,J.hydrateRoot)(n,(0,d.jsx)(s,{}))}
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- import u,{useEffect as G,useState as f}from"react";import{hydrateRoot as pe}from"react-dom/client";import{createFromFetch as X,createFromReadableStream as me}from"react-server-dom-webpack/client";import{RouteChildrenSlotProvider as Re}from"@webtypen/webframez-react/route-slot";var de=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function d(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function z(e,t){let n=e.trim(),o=d(t);return!n||!o||de.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function P(e,t){if(!e)return;let n=d(e.basename)??d(t),o=d(e.routeBasePath),r=d(e.transportBasePath),a={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return a.favicon&&(a.favicon=z(a.favicon,n)),a.links&&(a.links=a.links.map(s=>({...s,href:z(s.href,n)}))),a}import h from"react";var W="webframez-route-children",F="__webframezRouteChildren",j="WebframezRouteChildren",ue="__webframezRouteChildrenSlot",le="WebframezRouteChildrenSlot",x=()=>h.createElement(W);x.displayName=j;x[F]=!0;var fe=x;function D(e){if(e===W||e===fe)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[F]===!0||t.displayName===j||t.name==="RouteChildren"}catch{return!1}}function M(e){if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[ue]===!0||t.displayName===le||t.name==="RouteChildrenSlot"}catch{return!1}}function $(e){if(!e||typeof e!="object")return!1;try{return"type"in e&&"props"in e}catch{return!1}}function E(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let c=!1,_=e.map(m=>{let w=E(m,t);return w!==m&&(c=!0),w});return c?_:e}if($(e)&&(D(e.type)||M(e.type)))return t;let n=h.isValidElement(e);if(!n&&!$(e))return e;if(n&&(D(e.type)||M(e.type)))return t;let o=e.props??{};if(!("children"in o))return e;let r=E(o.children,t);if(r===o.children)return e;if(n)return Array.isArray(r)?h.cloneElement(e,void 0,...r):h.cloneElement(e,void 0,r);let a=e,s={...a.props??{},children:r,...a.key!==void 0&&a.key!==null?{key:a.key}:{}};return h.createElement(a.type,s)}import{Fragment as Be,jsx as p,jsxs as Oe}from"react/jsx-runtime";var he={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},T=typeof u.createContext=="function"?u.createContext(null):null,J="__WEBFRAMEZ_ROUTER__",_e="__WEBFRAMEZ_REACT_BUILD_ID",we="x-webframez-react-build",ge="[data-webframez-head='true']";function q(){if(typeof window>"u"||typeof document>"u")return;let e=()=>{window.scrollTo({top:0,left:0}),document.scrollingElement&&(document.scrollingElement.scrollTop=0),document.documentElement.scrollTop=0,document.body&&(document.body.scrollTop=0)};if(typeof window.requestAnimationFrame=="function"){window.requestAnimationFrame(e);return}window.setTimeout(e,0)}function L(e){return d(e)??""}function Ce(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function Q(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function ye(){return L(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function ee(e){if(typeof window>"u")return e||"/";let t=L(window.__RSC_BASENAME),n=ye(),o=Ce(e||"/",t);return Q(n,o)}function te(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function Ee(){if(typeof window>"u")return"";let e=window[_e];return typeof e=="string"?e:""}function Te(e){let t=Ee();return!!t&&!!e&&t!==e}function I(e){typeof window>"u"||window.location.assign(`${e.pathname}${e.search}${e.hash}`)}function Ae(){return typeof window>"u"?null:window[J]??null}function Ne(e){typeof window>"u"||(window[J]=e)}function Se(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function Pe(e){return Se(e)?u.use(e):e}function A(e){let t=Pe(e);if(Array.isArray(t)){let r=!1,a=t.map(s=>{let c=A(s);return c!==s&&(r=!0),c});return r?a:t}if(!u.isValidElement(t))return t;let n=t.props;if(!("children"in n))return t;let o=A(n.children);return o===n.children?t:Array.isArray(o)?u.cloneElement(t,void 0,...o):u.cloneElement(t,void 0,o)}function Y(){let e={},t=typeof document>"u"?"":document.cookie;if(!t||t.trim()==="")return e;for(let n of t.split(";")){let o=n.trim();if(!o)continue;let r=o.indexOf("="),a=r>=0?o.slice(0,r).trim():o,s=r>=0?o.slice(r+1):"";a&&(e[a]=decodeURIComponent(s))}return e}function Z(e,t,n={}){let o=[`${e}=${encodeURIComponent(t)}`];return n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),typeof n.maxAge=="number"&&o.push(`Max-Age=${Math.floor(n.maxAge)}`),n.expires&&o.push(`Expires=${n.expires.toUTCString()}`),n.sameSite&&o.push(`SameSite=${n.sameSite}`),n.secure&&o.push("Secure"),o.join("; ")}function Ge(){return u.useMemo(()=>({all:()=>Y(),get:e=>Y()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=Z(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=Z(e,"",{...t??{},maxAge:0}))}}),[])}function qe(){let e=T?u.useContext(T):null;if(!e){let t=Ae();if(t)return t;if(typeof window>"u")return he;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function xe({active:e}){return p("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:3,zIndex:9999,transformOrigin:"left",transform:e?"scaleX(1)":"scaleX(0)",transition:"transform 180ms ease",background:"linear-gradient(90deg, #0ea5e9, #22c55e)"}})}function K(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function V(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function v(e){if(typeof document>"u")return;let t=P(e)??e;ne(t),document.body.className=t.bodyClassName||"",document.title=t.title||"Webframez React";for(let n of document.head.querySelectorAll(ge))n.remove();t.description&&K({name:"description",content:t.description}),t.favicon&&V({rel:"icon",href:t.favicon});for(let n of t.meta??[])K(n);for(let n of t.links??[])V(n)}function ne(e){if(typeof window>"u")return;let t=P(e)??e,n=d(t.basename),o=d(t.routeBasePath),r=d(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=Q(r,"/rsc"))}function Ie(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function ve(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,me(Ie(e)))}function Le(e){let t=te(e),n=ee(window.location.pathname);return ve()??X(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function be(e,t){return function(){let o=u.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[a,s]=f(o.model),[c,_]=f(o.contextModel),[m,w]=f(o.pageModel),[b,B]=f(o.head),[oe,g]=f(!1),[re,ie]=f(!1),[ae,N]=f(r);async function O(i){let y=te(t),l=ee(i.pathname),R=await fetch(`${y}?path=${encodeURIComponent(l)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return Te(R.headers.get(we))?(I(i),await new Promise(()=>{})):await X(Promise.resolve(R))}async function C(i,y="push"){g(!0);try{let l=await O(i);v(l.head),B(l.head),s(l.model),_(l.contextModel),w(l.pageModel),N(!1);let R=`${i.pathname}${i.search}${i.hash}`;y==="replace"?(history.replaceState(null,"",R),q()):y==="push"&&(history.pushState(null,"",R),q())}catch(l){console.error("[webframez-react] Failed to render route",l),I(i),s(p("p",{children:"Failed to load route."}))}finally{g(!1)}}async function se(){g(!0);try{let i=await O(new URL(window.location.href));if(v(i.head),B(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){_(i.contextModel),N(!0);return}s(i.model),N(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i),I(new URL(window.location.href))}finally{g(!1)}}G(()=>{v(b)},[b]),G(()=>{ie(!0);let i=()=>{C(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let k=u.useMemo(()=>({push:i=>{C(new URL(i,window.location.origin),"push")},replace:i=>{C(new URL(i,window.location.origin),"replace")},refresh:()=>{C(new URL(window.location.href),"none")},refreshContext:()=>{se()}}),[]);Ne(k);let U=A(c),S=A(m),ce=ae&&typeof m<"u"?U?p(Re,{page:S,children:E(U,S)}):S:a,H=Oe(Be,{children:[re?p(xe,{active:oe}):null,ce??p("p",{style:{padding:24},children:"Loading..."})]});return T?p(T.Provider,{value:k,children:H}):H}}function Ye(e={}){let t=e.rootId??"root",n=document.getElementById(t);if(!n)throw new Error(`Missing #${t} element`);let o=typeof window<"u"&&window.__RSC_ENDPOINT,r=e.rscEndpoint??o??"/rsc",a=Promise.resolve(Le(r)).then(c=>(c?.head&&ne(c.head),c)),s=be(a,r);return pe(n,p(s,{}))}export{Ye as mountWebframezClient,Ge as useCookie,qe as useRouter};
1
+ import u,{useEffect as q,useState as f}from"react";import{hydrateRoot as fe}from"react-dom/client";import{createFromFetch as V,createFromReadableStream as me}from"react-server-dom-webpack/client";import{RouteChildrenSlotProvider as pe}from"@webtypen/webframez-react/route-slot";var ce=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function d(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function z(e,t){let n=e.trim(),o=d(t);return!n||!o||ce.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function S(e,t){if(!e)return;let n=d(e.basename)??d(t),o=d(e.routeBasePath),r=d(e.transportBasePath),i={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return i.favicon&&(i.favicon=z(i.favicon,n)),i.links&&(i.links=i.links.map(s=>({...s,href:z(s.href,n)}))),i}import h from"react";var F="webframez-route-children",j="__webframezRouteChildren",G="WebframezRouteChildren",de="__webframezRouteChildrenSlot",ue="WebframezRouteChildrenSlot",P=()=>h.createElement(F);P.displayName=G;P[j]=!0;var le=P;function $(e){if(e===F||e===le)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[j]===!0||t.displayName===G||t.name==="RouteChildren"}catch{return!1}}function D(e){if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[de]===!0||t.displayName===ue||t.name==="RouteChildrenSlot"}catch{return!1}}function W(e){if(!e||typeof e!="object")return!1;try{return"type"in e&&"props"in e}catch{return!1}}function E(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let c=!1,w=e.map(p=>{let R=E(p,t);return R!==p&&(c=!0),R});return c?w:e}if(W(e)&&($(e.type)||D(e.type)))return t;let n=h.isValidElement(e);if(!n&&!W(e))return e;if(n&&($(e.type)||D(e.type)))return t;let o=e.props??{};if(!("children"in o))return e;let r=E(o.children,t);if(r===o.children)return e;if(n)return Array.isArray(r)?h.cloneElement(e,void 0,...r):h.cloneElement(e,void 0,r);let i=e,s={...i.props??{},children:r,...i.key!==void 0&&i.key!==null?{key:i.key}:{}};return h.createElement(i.type,s)}import{Fragment as Oe,jsx as m,jsxs as Ue}from"react/jsx-runtime";var Re={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},T=typeof u.createContext=="function"?u.createContext(null):null,X="__WEBFRAMEZ_ROUTER__",ge="__WEBFRAMEZ_REACT_BUILD_ID",he="x-webframez-react-build",we="[data-webframez-head='true']";function K(){if(typeof window>"u"||typeof document>"u")return;let e=()=>{window.scrollTo({top:0,left:0}),document.scrollingElement&&(document.scrollingElement.scrollTop=0),document.documentElement.scrollTop=0,document.body&&(document.body.scrollTop=0)};if(typeof window.requestAnimationFrame=="function"){window.requestAnimationFrame(e);return}window.setTimeout(e,0)}function I(e){return d(e)??""}function _e(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function J(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function ye(){return I(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function Q(e){if(typeof window>"u")return e||"/";let t=I(window.__RSC_BASENAME),n=ye(),o=_e(e||"/",t);return J(n,o)}function ee(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function Ce(){if(typeof window>"u")return"";let e=window[ge];return typeof e=="string"?e:""}function Ee(e){let t=Ce();return!!t&&!!e&&t!==e}function L(e){typeof window>"u"||window.location.assign(`${e.pathname}${e.search}${e.hash}`)}function Te(){return typeof window>"u"?null:window[X]??null}function Ne(e){typeof window>"u"||(window[X]=e)}function Ae(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function Se(e){return Ae(e)?u.use(e):e}function N(e){let t=Se(e);if(Array.isArray(t)){let r=!1,i=t.map(s=>{let c=N(s);return c!==s&&(r=!0),c});return r?i:t}if(!u.isValidElement(t))return t;let n=t.props;if(!("children"in n))return t;let o=N(n.children);return o===n.children?t:Array.isArray(o)?u.cloneElement(t,void 0,...o):u.cloneElement(t,void 0,o)}function Y(){let e={},t=typeof document>"u"?"":document.cookie;if(!t||t.trim()==="")return e;for(let n of t.split(";")){let o=n.trim();if(!o)continue;let r=o.indexOf("="),i=r>=0?o.slice(0,r).trim():o,s=r>=0?o.slice(r+1):"";i&&(e[i]=decodeURIComponent(s))}return e}function Z(e,t,n={}){let o=[`${e}=${encodeURIComponent(t)}`];return n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),typeof n.maxAge=="number"&&o.push(`Max-Age=${Math.floor(n.maxAge)}`),n.expires&&o.push(`Expires=${n.expires.toUTCString()}`),n.sameSite&&o.push(`SameSite=${n.sameSite}`),n.secure&&o.push("Secure"),o.join("; ")}function Ye(){return u.useMemo(()=>({all:()=>Y(),get:e=>Y()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=Z(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=Z(e,"",{...t??{},maxAge:0}))}}),[])}function Ze(){let e=T?u.useContext(T):null;if(!e){let t=Te();if(t)return t;if(typeof window>"u")return Re;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Pe({active:e}){return m("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:3,zIndex:9999,transformOrigin:"left",transform:e?"scaleX(1)":"scaleX(0)",transition:"transform 180ms ease",background:"linear-gradient(90deg, #0ea5e9, #22c55e)"}})}function Le(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function ve(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function x(e,t){let n=Object.entries(t).filter(([o,r])=>o!=="data-webframez-head"&&!!r).map(([o,r])=>[o.toLowerCase(),String(r)]).sort(([o],[r])=>o.localeCompare(r));return`${e.toLowerCase()}:${n.map(([o,r])=>`${o}=${r}`).join(";")}`}function Ie(e){let t={};for(let n of Array.from(e.attributes))t[n.name]=n.value;return x(e.tagName,t)}function xe(e){let t=[];e.description&&t.push({tagName:"meta",attrs:{name:"description",content:e.description}}),e.favicon&&t.push({tagName:"link",attrs:{rel:"icon",href:e.favicon}});for(let n of e.meta??[])t.push({tagName:"meta",attrs:n});for(let n of e.links??[])t.push({tagName:"link",attrs:n});return t}function v(e){if(typeof document>"u")return;let t=S(e)??e;te(t),document.body.className=t.bodyClassName||"",document.title=t.title||"Webframez React";let n=xe(t),o=new Set(n.map(i=>x(i.tagName,i.attrs))),r=new Set;for(let i of document.head.querySelectorAll(we)){let s=Ie(i);if(o.has(s)&&!r.has(s)){r.add(s);continue}i.remove()}for(let i of n){let s=x(i.tagName,i.attrs);r.has(s)||(i.tagName==="meta"?Le(i.attrs):ve(i.attrs),r.add(s))}}function te(e){if(typeof window>"u")return;let t=S(e)??e,n=d(t.basename),o=d(t.routeBasePath),r=d(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=J(r,"/rsc"))}function be(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function ke(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,me(be(e)))}function Be(e){let t=ee(e),n=Q(window.location.pathname);return ke()??V(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function He(e,t){return function(){let o=u.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[i,s]=f(o.model),[c,w]=f(o.contextModel),[p,R]=f(o.pageModel),[b,k]=f(o.head),[ne,_]=f(!1),[oe,re]=f(!1),[ie,B]=f(r);async function H(a){let C=ee(t),l=Q(a.pathname),g=await fetch(`${C}?path=${encodeURIComponent(l)}&search=${encodeURIComponent(a.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return Ee(g.headers.get(he))?(L(a),await new Promise(()=>{})):await V(Promise.resolve(g))}async function y(a,C="push"){_(!0);try{let l=await H(a);v(l.head),k(l.head),s(l.model),w(l.contextModel),R(l.pageModel),B(!1);let g=`${a.pathname}${a.search}${a.hash}`;C==="replace"?(history.replaceState(null,"",g),K()):C==="push"&&(history.pushState(null,"",g),K())}catch(l){console.error("[webframez-react] Failed to render route",l),L(a),s(m("p",{children:"Failed to load route."}))}finally{_(!1)}}async function ae(){_(!0);try{let a=await H(new URL(window.location.href));v(a.head),k(a.head),s(a.model),w(a.contextModel),R(a.pageModel),B(!1)}catch(a){console.error("[webframez-react] Failed to refresh route context",a),L(new URL(window.location.href))}finally{_(!1)}}q(()=>{v(b)},[b]),q(()=>{re(!0);let a=()=>{y(new URL(window.location.href),"none")};return window.addEventListener("popstate",a),()=>{window.removeEventListener("popstate",a)}},[]);let O=u.useMemo(()=>({push:a=>{y(new URL(a,window.location.origin),"push")},replace:a=>{y(new URL(a,window.location.origin),"replace")},refresh:()=>{y(new URL(window.location.href),"none")},refreshContext:()=>{ae()}}),[]);Ne(O);let U=N(c),A=N(p),se=ie&&typeof p<"u"?U?m(pe,{page:A,children:E(U,A)}):A:i,M=Ue(Oe,{children:[oe?m(Pe,{active:ne}):null,se??m("p",{style:{padding:24},children:"Loading..."})]});return T?m(T.Provider,{value:O,children:M}):M}}function Ve(e={}){let t=e.rootId??"root",n=document.getElementById(t);if(!n)throw new Error(`Missing #${t} element`);let o=typeof window<"u"&&window.__RSC_ENDPOINT,r=e.rscEndpoint??o??"/rsc",i=Promise.resolve(Be(r)).then(c=>(c?.head&&te(c.head),c)),s=He(i,r);return fe(n,m(s,{}))}export{Ve as mountWebframezClient,Ye as useCookie,Ze as useRouter};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {