@webtypen/webframez-react 0.0.34 → 0.0.35
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
|
|
1
|
+
var se=Object.create;var y=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})},L=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of de(t))!le.call(e,r)&&r!==n&&y(e,r,{get:()=>t[r],enumerable:!(o=ce(t,r))||o.enumerable});return e};var H=(e,t,n)=>(n=e!=null?se(ue(e)):{},L(t||!e||!e.__esModule?y(n,"default",{value:e,enumerable:!0}):n,e)),pe=e=>L(y({},"__esModule",{value:!0}),e);var be={};fe(be,{mountWebframezClient:()=>ve,useCookie:()=>Ee,useRouter:()=>Ae});module.exports=pe(be);var s=H(require("react"),1),Z=require("react-dom/client"),g=require("react-server-dom-webpack/client"),K=require("@webtypen/webframez-react/route-slot");var me=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function u(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function U(e,t){let n=e.trim(),o=u(t);return!n||!o||me.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=u(e.basename)??u(t),o=u(e.routeBasePath),r=u(e.transportBasePath),a={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return a.favicon&&(a.favicon=U(a.favicon,n)),a.links&&(a.links=a.links.map(c=>({...c,href:U(c.href,n)}))),a}var R=H(require("react"),1),$="webframez-route-children",W="__webframezRouteChildren",D="WebframezRouteChildren",N=()=>R.default.createElement($);N.displayName=D;N[W]=!0;var Re=N;function z(e){if(e===$||e===Re)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[W]===!0||t.displayName===D||t.name==="RouteChildren"}catch{return!1}}function M(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 m=!1,f=e.map(p=>{let w=E(p,t);return w!==p&&(m=!0),w});return m?f:e}if(M(e)&&z(e.type))return t;let n=R.default.isValidElement(e);if(!n&&!M(e))return e;if(n&&z(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)?R.default.cloneElement(e,void 0,...r):R.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 R.default.createElement(a.type,c)}var d=require("react/jsx-runtime"),ge={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},A=typeof s.default.createContext=="function"?s.default.createContext(null):null,V="__WEBFRAMEZ_ROUTER__",we="[data-webframez-head='true']";function F(){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 v(e){return u(e)??""}function he(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function X(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function _e(){return v(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function J(e){if(typeof window>"u")return e||"/";let t=v(window.__RSC_BASENAME),n=_e(),o=he(e||"/",t);return X(n,o)}function Q(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function Ce(){return typeof window>"u"?null:window[V]??null}function ye(e){typeof window>"u"||(window[V]=e)}function j(){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 q(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 Ee(){return s.default.useMemo(()=>({all:()=>j(),get:e=>j()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=q(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=q(e,"",{...t??{},maxAge:0}))}}),[])}function Ae(){let e=A?s.default.useContext(A):null;if(!e){let t=Ce();if(t)return t;if(typeof window>"u")return ge;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Te({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 G(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 Y(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=S(e)??e;ee(t),document.title=t.title||"Webframez React";for(let n of document.head.querySelectorAll(we))n.remove();t.description&&G({name:"description",content:t.description}),t.favicon&&Y({rel:"icon",href:t.favicon});for(let n of t.meta??[])G(n);for(let n of t.links??[])Y(n)}function ee(e){if(typeof window>"u")return;let t=S(e)??e,n=u(t.basename),o=u(t.routeBasePath),r=u(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=X(r,"/rsc"))}function Pe(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function Se(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,g.createFromReadableStream)(Pe(e)))}function Ne(e){let t=Q(e),n=J(window.location.pathname);return Se()??(0,g.createFromFetch)(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function xe(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),[m,f]=(0,s.useState)(o.contextModel),[p,w]=(0,s.useState)(o.pageModel),[b,I]=(0,s.useState)(o.head),[te,h]=(0,s.useState)(!1),[ne,oe]=(0,s.useState)(!1),[re,T]=(0,s.useState)(r);async function O(i){let C=Q(t),l=J(i.pathname);return await(0,g.createFromFetch)(fetch(`${C}?path=${encodeURIComponent(l)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}async function _(i,C="push"){h(!0);try{let l=await O(i);x(l.head),I(l.head),c(l.model),f(l.contextModel),w(l.pageModel),T(!0);let P=`${i.pathname}${i.search}`;C==="replace"?(history.replaceState(null,"",P),F()):C==="push"&&(history.pushState(null,"",P),F())}catch(l){console.error("[webframez-react] Failed to render route",l),c((0,d.jsx)("p",{children:"Failed to load route."}))}finally{h(!1)}}async function ie(){h(!0);try{let i=await O(new URL(window.location.href));if(x(i.head),I(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){f(i.contextModel),T(!0);return}c(i.model),T(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i)}finally{h(!1)}}(0,s.useEffect)(()=>{x(b)},[b]),(0,s.useEffect)(()=>{oe(!0);let i=()=>{_(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let k=s.default.useMemo(()=>({push:i=>{_(new URL(i,window.location.origin),"push")},replace:i=>{_(new URL(i,window.location.origin),"replace")},refresh:()=>{_(new URL(window.location.href),"none")},refreshContext:()=>{ie()}}),[]);ye(k);let ae=re&&typeof p<"u"?m?(0,d.jsx)(K.RouteChildrenSlotProvider,{page:p,children:E(m,p)}):p:a,B=(0,d.jsxs)(d.Fragment,{children:[ne?(0,d.jsx)(Te,{active:te}):null,ae??(0,d.jsx)("p",{style:{padding:24},children:"Loading..."})]});return A?(0,d.jsx)(A.Provider,{value:k,children:B}):B}}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",a=Promise.resolve(Ne(r)).then(f=>(f?.head&&ee(f.head),f)),c=xe(a,r);return(0,Z.hydrateRoot)(n,(0,d.jsx)(c,{}))}
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import R,{useEffect as $,useState as f}from"react";import{hydrateRoot as
|
|
1
|
+
import R,{useEffect as $,useState as f}from"react";import{hydrateRoot as ae}from"react-dom/client";import{createFromFetch as G,createFromReadableStream as se}from"react-server-dom-webpack/client";import{RouteChildrenSlotProvider as ce}from"@webtypen/webframez-react/route-slot";var re=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function c(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function B(e,t){let n=e.trim(),o=c(t);return!n||!o||re.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=c(e.basename)??c(t),o=c(e.routeBasePath),r=c(e.transportBasePath),a={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return a.favicon&&(a.favicon=B(a.favicon,n)),a.links&&(a.links=a.links.map(s=>({...s,href:B(s.href,n)}))),a}import g from"react";var U="webframez-route-children",z="__webframezRouteChildren",M="WebframezRouteChildren",S=()=>g.createElement(U);S.displayName=M;S[z]=!0;var ie=S;function L(e){if(e===U||e===ie)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[z]===!0||t.displayName===M||t.name==="RouteChildren"}catch{return!1}}function H(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 m=!1,u=e.map(l=>{let w=y(l,t);return w!==l&&(m=!0),w});return m?u:e}if(H(e)&&L(e.type))return t;let n=g.isValidElement(e);if(!n&&!H(e))return e;if(n&&L(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)?g.cloneElement(e,void 0,...r):g.cloneElement(e,void 0,r);let a=e,s={...a.props??{},children:r,...a.key!==void 0&&a.key!==null?{key:a.key}:{}};return g.createElement(a.type,s)}import{Fragment as Ce,jsx as p,jsxs as ye}from"react/jsx-runtime";var de={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},E=typeof R.createContext=="function"?R.createContext(null):null,Y="__WEBFRAMEZ_ROUTER__",ue="[data-webframez-head='true']";function W(){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 c(e)??""}function le(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function Z(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function fe(){return x(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function K(e){if(typeof window>"u")return e||"/";let t=x(window.__RSC_BASENAME),n=fe(),o=le(e||"/",t);return Z(n,o)}function V(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function pe(){return typeof window>"u"?null:window[Y]??null}function me(e){typeof window>"u"||(window[Y]=e)}function D(){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 F(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 Ie(){return R.useMemo(()=>({all:()=>D(),get:e=>D()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=F(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=F(e,"",{...t??{},maxAge:0}))}}),[])}function Oe(){let e=E?R.useContext(E):null;if(!e){let t=pe();if(t)return t;if(typeof window>"u")return de;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Re({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 j(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 q(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 N(e){if(typeof document>"u")return;let t=P(e)??e;X(t),document.title=t.title||"Webframez React";for(let n of document.head.querySelectorAll(ue))n.remove();t.description&&j({name:"description",content:t.description}),t.favicon&&q({rel:"icon",href:t.favicon});for(let n of t.meta??[])j(n);for(let n of t.links??[])q(n)}function X(e){if(typeof window>"u")return;let t=P(e)??e,n=c(t.basename),o=c(t.routeBasePath),r=c(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=Z(r,"/rsc"))}function ge(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,se(ge(e)))}function he(e){let t=V(e),n=K(window.location.pathname);return we()??G(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=R.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[a,s]=f(o.model),[m,u]=f(o.contextModel),[l,w]=f(o.pageModel),[v,b]=f(o.head),[J,h]=f(!1),[Q,ee]=f(!1),[te,A]=f(r);async function I(i){let C=V(t),d=K(i.pathname);return await G(fetch(`${C}?path=${encodeURIComponent(d)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}async function _(i,C="push"){h(!0);try{let d=await I(i);N(d.head),b(d.head),s(d.model),u(d.contextModel),w(d.pageModel),A(!0);let T=`${i.pathname}${i.search}`;C==="replace"?(history.replaceState(null,"",T),W()):C==="push"&&(history.pushState(null,"",T),W())}catch(d){console.error("[webframez-react] Failed to render route",d),s(p("p",{children:"Failed to load route."}))}finally{h(!1)}}async function ne(){h(!0);try{let i=await I(new URL(window.location.href));if(N(i.head),b(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){u(i.contextModel),A(!0);return}s(i.model),A(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i)}finally{h(!1)}}$(()=>{N(v)},[v]),$(()=>{ee(!0);let i=()=>{_(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let O=R.useMemo(()=>({push:i=>{_(new URL(i,window.location.origin),"push")},replace:i=>{_(new URL(i,window.location.origin),"replace")},refresh:()=>{_(new URL(window.location.href),"none")},refreshContext:()=>{ne()}}),[]);me(O);let oe=te&&typeof l<"u"?m?p(ce,{page:l,children:y(m,l)}):l:a,k=ye(Ce,{children:[Q?p(Re,{active:J}):null,oe??p("p",{style:{padding:24},children:"Loading..."})]});return E?p(E.Provider,{value:O,children:k}):k}}function ke(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(he(r)).then(u=>(u?.head&&X(u.head),u)),s=_e(a,r);return ae(n,p(s,{}))}export{ke as mountWebframezClient,Ie as useCookie,Oe as useRouter};
|