@webtypen/webframez-react 0.0.46 → 0.0.47
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 +1 -1
- package/dist/client.js +1 -1
- package/package.json +1 -1
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 fe=Object.create;var y=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var he=(e,t)=>{for(var n in t)y(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))!_e.call(e,r)&&r!==n&&y(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?y(n,"default",{value:e,enumerable:!0}):n,e)),we=e=>D(y({},"__esModule",{value:!0}),e);var Fe={};he(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 P(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",Ee="WebframezRouteChildrenSlot",I=()=>p.default.createElement(G);I.displayName=Y;I[q]=!0;var ye=I;function W(e){if(e===G||e===ye)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===Ee||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,w=e.map(m=>{let R=T(m,t);return R!==m&&(u=!0),R});return u?w: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 L(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 Ie(){return L(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function oe(e){if(typeof window>"u")return e||"/";let t=L(window.__RSC_BASENAME),n=Ie(),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 ve(){if(typeof window>"u")return"";let e=window[Ae];return typeof e=="string"?e:""}function xe(e){let t=ve();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 x(e){if(typeof document>"u")return;let t=P(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=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=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,w]=(0,s.useState)(o.contextModel),[m,R]=(0,s.useState)(o.pageModel),[b,B]=(0,s.useState)(o.head),[ae,g]=(0,s.useState)(!1),[se,ce]=(0,s.useState)(!1),[de,O]=(0,s.useState)(r);async function k(i){let E=re(t),f=oe(i.pathname),_=await fetch(`${E}?path=${encodeURIComponent(f)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return xe(_.headers.get(Ne))?(v(i),await new Promise(()=>{})):await(0,h.createFromFetch)(Promise.resolve(_))}async function C(i,E="push"){g(!0);try{let f=await k(i);x(f.head),B(f.head),c(f.model),w(f.contextModel),R(f.pageModel),O(!1);let _=`${i.pathname}${i.search}${i.hash}`;E==="replace"?(history.replaceState(null,"",_),Z()):E==="push"&&(history.pushState(null,"",_),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));x(i.head),B(i.head),c(i.model),w(i.contextModel),R(i.pageModel),O(!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)(()=>{x(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),S=N(m),le=de&&typeof m<"u"?H?(0,d.jsx)(ee.RouteChildrenSlotProvider,{page:S,children:T(H,S)}):S: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,{}))}
|
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
|
|
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 S(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",P=()=>h.createElement(W);P.displayName=j;P[F]=!0;var fe=P;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 y(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let c=!1,w=e.map(m=>{let R=y(m,t);return R!==m&&(c=!0),R});return c?w: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=y(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 _e={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},T=typeof u.createContext=="function"?u.createContext(null):null,J="__WEBFRAMEZ_ROUTER__",he="__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 x(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 Ee(){return x(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function ee(e){if(typeof window>"u")return e||"/";let t=x(window.__RSC_BASENAME),n=Ee(),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 ye(){if(typeof window>"u")return"";let e=window[he];return typeof e=="string"?e:""}function Te(e){let t=ye();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 _e;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Ie({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=S(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=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=Q(r,"/rsc"))}function ve(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function xe(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,me(ve(e)))}function Le(e){let t=te(e),n=ee(window.location.pathname);return xe()??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,w]=f(o.contextModel),[m,R]=f(o.pageModel),[L,b]=f(o.head),[oe,g]=f(!1),[re,ie]=f(!1),[ae,B]=f(r);async function O(i){let E=te(t),l=ee(i.pathname),_=await fetch(`${E}?path=${encodeURIComponent(l)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return Te(_.headers.get(we))?(I(i),await new Promise(()=>{})):await X(Promise.resolve(_))}async function C(i,E="push"){g(!0);try{let l=await O(i);v(l.head),b(l.head),s(l.model),w(l.contextModel),R(l.pageModel),B(!1);let _=`${i.pathname}${i.search}${i.hash}`;E==="replace"?(history.replaceState(null,"",_),q()):E==="push"&&(history.pushState(null,"",_),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));v(i.head),b(i.head),s(i.model),w(i.contextModel),R(i.pageModel),B(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i),I(new URL(window.location.href))}finally{g(!1)}}G(()=>{v(L)},[L]),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),N=A(m),ce=ae&&typeof m<"u"?U?p(Re,{page:N,children:y(U,N)}):N:a,H=Oe(Be,{children:[re?p(Ie,{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};
|