@webtypen/webframez-react 0.0.45 → 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.
@@ -526,9 +526,18 @@ function getManifestChunkAssetsByName(distRootDir) {
526
526
  return assetsByName;
527
527
  }
528
528
 
529
- for (const fileName of fs.readdirSync(chunksDir)) {
529
+ const fileNames = fs
530
+ .readdirSync(chunksDir)
531
+ .map((fileName) => ({
532
+ fileName,
533
+ mtimeMs: fs.statSync(path.join(chunksDir, fileName)).mtimeMs,
534
+ }))
535
+ .sort((a, b) => b.mtimeMs - a.mtimeMs)
536
+ .map((entry) => entry.fileName);
537
+
538
+ for (const fileName of fileNames) {
530
539
  const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
531
- if (match && match[1]) {
540
+ if (match && match[1] && !assetsByName.has(match[1])) {
532
541
  assetsByName.set(match[1], path.join("chunks", fileName));
533
542
  }
534
543
  }
@@ -34,6 +34,27 @@ const frameworkCacheVersion = frameworkCacheFiles
34
34
  fs.mkdirSync(distDir, { recursive: true });
35
35
  fs.mkdirSync(pagesDir, { recursive: true });
36
36
 
37
+ function getCompilationChunkAssetsByName(compilation) {
38
+ const assetsByName = new Map();
39
+ if (!compilation || !compilation.chunks) {
40
+ return assetsByName;
41
+ }
42
+
43
+ for (const chunk of compilation.chunks) {
44
+ const chunkName = chunk.name || chunk.id;
45
+ if (typeof chunkName !== "string") {
46
+ continue;
47
+ }
48
+
49
+ const jsFile = Array.from(chunk.files || []).find((fileName) => /^chunks\/.*\.js$/.test(fileName));
50
+ if (jsFile) {
51
+ assetsByName.set(chunkName, jsFile);
52
+ }
53
+ }
54
+
55
+ return assetsByName;
56
+ }
57
+
37
58
  function getEmittedChunkAssetsByName() {
38
59
  const chunksDir = path.join(distDir, "chunks");
39
60
  const assetsByName = new Map();
@@ -41,9 +62,18 @@ function getEmittedChunkAssetsByName() {
41
62
  return assetsByName;
42
63
  }
43
64
 
44
- for (const fileName of fs.readdirSync(chunksDir)) {
65
+ const fileNames = fs
66
+ .readdirSync(chunksDir)
67
+ .map((fileName) => ({
68
+ fileName,
69
+ mtimeMs: fs.statSync(path.join(chunksDir, fileName)).mtimeMs,
70
+ }))
71
+ .sort((a, b) => b.mtimeMs - a.mtimeMs)
72
+ .map((entry) => entry.fileName);
73
+
74
+ for (const fileName of fileNames) {
45
75
  const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
46
- if (match && match[1]) {
76
+ if (match && match[1] && !assetsByName.has(match[1])) {
47
77
  assetsByName.set(match[1], "chunks/" + fileName);
48
78
  }
49
79
  }
@@ -51,8 +81,7 @@ function getEmittedChunkAssetsByName() {
51
81
  return assetsByName;
52
82
  }
53
83
 
54
- function normalizeManifestChunkFiles(manifest) {
55
- const assetsByName = getEmittedChunkAssetsByName();
84
+ function normalizeManifestChunkFiles(manifest, assetsByName = getEmittedChunkAssetsByName()) {
56
85
  if (assetsByName.size === 0) {
57
86
  return false;
58
87
  }
@@ -83,13 +112,14 @@ function normalizeManifestChunkFiles(manifest) {
83
112
 
84
113
  class ClientManifestExportAliasesPlugin {
85
114
  apply(compiler) {
86
- compiler.hooks.done.tap("ClientManifestExportAliasesPlugin", () => {
115
+ compiler.hooks.done.tap("ClientManifestExportAliasesPlugin", (stats) => {
87
116
  const manifestPath = path.join(distDir, "react-client-manifest.json");
88
117
  if (!fs.existsSync(manifestPath)) {
89
118
  return;
90
119
  }
91
120
 
92
121
  const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
122
+ const assetsByName = getCompilationChunkAssetsByName(stats && stats.compilation);
93
123
  let changed = false;
94
124
 
95
125
  for (const [key, value] of Object.entries(manifest)) {
@@ -199,7 +229,7 @@ class ClientManifestExportAliasesPlugin {
199
229
  }
200
230
  }
201
231
 
202
- if (normalizeManifestChunkFiles(manifest)) {
232
+ if (normalizeManifestChunkFiles(manifest, assetsByName.size > 0 ? assetsByName : undefined)) {
203
233
  changed = true;
204
234
  }
205
235
 
@@ -47,9 +47,13 @@ function getEmittedChunkAssetsByName(distRootDir) {
47
47
  if (!fileExists(chunksDir)) {
48
48
  return assetsByName;
49
49
  }
50
- for (const fileName of import_node_fs.default.readdirSync(chunksDir)) {
50
+ const fileNames = import_node_fs.default.readdirSync(chunksDir).map((fileName) => ({
51
+ fileName,
52
+ mtimeMs: import_node_fs.default.statSync(import_node_path.default.join(chunksDir, fileName)).mtimeMs
53
+ })).sort((a, b) => b.mtimeMs - a.mtimeMs).map((entry) => entry.fileName);
54
+ for (const fileName of fileNames) {
51
55
  const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
52
- if (match?.[1]) {
56
+ if (match?.[1] && !assetsByName.has(match[1])) {
53
57
  assetsByName.set(match[1], import_node_path.default.join("chunks", fileName));
54
58
  }
55
59
  }
@@ -13,9 +13,13 @@ function getEmittedChunkAssetsByName(distRootDir) {
13
13
  if (!fileExists(chunksDir)) {
14
14
  return assetsByName;
15
15
  }
16
- for (const fileName of fs.readdirSync(chunksDir)) {
16
+ const fileNames = fs.readdirSync(chunksDir).map((fileName) => ({
17
+ fileName,
18
+ mtimeMs: fs.statSync(path.join(chunksDir, fileName)).mtimeMs
19
+ })).sort((a, b) => b.mtimeMs - a.mtimeMs).map((entry) => entry.fileName);
20
+ for (const fileName of fileNames) {
17
21
  const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
18
- if (match?.[1]) {
22
+ if (match?.[1] && !assetsByName.has(match[1])) {
19
23
  assetsByName.set(match[1], path.join("chunks", fileName));
20
24
  }
21
25
  }
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,_e=Object.prototype.hasOwnProperty;var we=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},z=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of me(t))!_e.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(o=pe(t,r))||o.enumerable});return e};var D=(e,t,n)=>(n=e!=null?fe(Re(e)):{},z(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),he=e=>z(E({},"__esModule",{value:!0}),e);var We={};we(We,{mountWebframezClient:()=>$e,useCookie:()=>Oe,useRouter:()=>ke});module.exports=he(We);var s=D(require("react"),1),Q=require("react-dom/client"),_=require("react-server-dom-webpack/client"),ee=require("@webtypen/webframez-react/route-slot");var ge=/^(?:[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 M(e,t){let n=e.trim(),o=u(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=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=M(a.favicon,n)),a.links&&(a.links=a.links.map(c=>({...c,href:M(c.href,n)}))),a}var p=D(require("react"),1),j="webframez-route-children",G="__webframezRouteChildren",q="WebframezRouteChildren",Ce="__webframezRouteChildrenSlot",ye="WebframezRouteChildrenSlot",I=()=>p.default.createElement(j);I.displayName=q;I[G]=!0;var Ee=I;function $(e){if(e===j||e===Ee)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[G]===!0||t.displayName===q||t.name==="RouteChildren"}catch{return!1}}function W(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 F(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 f=!1,w=e.map(m=>{let h=T(m,t);return h!==m&&(f=!0),h});return f?w:e}if(F(e)&&($(e.type)||W(e.type)))return t;let n=p.default.isValidElement(e);if(!n&&!F(e))return e;if(n&&($(e.type)||W(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",Se="x-webframez-react-build",Ne="[data-webframez-head='true']";function Y(){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 u(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 x(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function oe(e){if(typeof window>"u")return e||"/";let t=x(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 Le(){if(typeof window>"u")return"";let e=window[Ae];return typeof e=="string"?e:""}function ve(e){let t=Le();return!!t&&!!e&&t!==e}function L(e){typeof window>"u"||window.location.assign(`${e.pathname}${e.search}${e.hash}`)}function xe(){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 Z(e){return Be(e)?s.default.use(e):e}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 Oe(){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 ke(){let e=A?s.default.useContext(A):null;if(!e){let t=xe();if(t)return t;if(typeof window>"u")return Te;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Ue({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 v(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(Ne))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=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=ne(r,"/rsc"))}function He(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function ze(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,_.createFromReadableStream)(He(e)))}function De(e){let t=re(e),n=oe(window.location.pathname);return ze()??(0,_.createFromFetch)(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function Me(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),[f,w]=(0,s.useState)(o.contextModel),[m,h]=(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,S]=(0,s.useState)(r);async function O(i){let y=re(t),l=oe(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 ve(R.headers.get(Se))?(L(i),await new Promise(()=>{})):await(0,_.createFromFetch)(Promise.resolve(R))}async function C(i,y="push"){g(!0);try{let l=await O(i);v(l.head),B(l.head),c(l.model),w(l.contextModel),h(l.pageModel),S(!0);let R=`${i.pathname}${i.search}${i.hash}`;y==="replace"?(history.replaceState(null,"",R),Y()):y==="push"&&(history.pushState(null,"",R),Y())}catch(l){console.error("[webframez-react] Failed to render route",l),L(i),c((0,d.jsx)("p",{children:"Failed to load route."}))}finally{g(!1)}}async function ue(){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")){w(i.contextModel),S(!0);return}c(i.model),S(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i),L(new URL(window.location.href))}finally{g(!1)}}(0,s.useEffect)(()=>{v(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 k=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(k);let U=Z(f),N=Z(m),le=de&&typeof m<"u"?U?(0,d.jsx)(ee.RouteChildrenSlotProvider,{page:N,children:T(U,N)}):N:a,H=(0,d.jsxs)(d.Fragment,{children:[se?(0,d.jsx)(Ue,{active:ae}):null,le??(0,d.jsx)("p",{style:{padding:24},children:"Loading..."})]});return A?(0,d.jsx)(A.Provider,{value:k,children:H}):H}}function $e(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(De(r)).then(f=>(f?.head&&ie(f.head),f)),c=Me(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 p,{useEffect as j,useState as l}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 c(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function H(e,t){let n=e.trim(),o=c(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 N(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=H(a.favicon,n)),a.links&&(a.links=a.links.map(s=>({...s,href:H(s.href,n)}))),a}import _ from"react";var $="webframez-route-children",W="__webframezRouteChildren",F="WebframezRouteChildren",ue="__webframezRouteChildrenSlot",le="WebframezRouteChildrenSlot",P=()=>_.createElement($);P.displayName=F;P[W]=!0;var fe=P;function z(e){if(e===$||e===fe)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[W]===!0||t.displayName===F||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[ue]===!0||t.displayName===le||t.name==="RouteChildrenSlot"}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 u=!1,w=e.map(m=>{let h=E(m,t);return h!==m&&(u=!0),h});return u?w:e}if(M(e)&&(z(e.type)||D(e.type)))return t;let n=_.isValidElement(e);if(!n&&!M(e))return e;if(n&&(z(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)?_.cloneElement(e,void 0,...r):_.cloneElement(e,void 0,r);let a=e,s={...a.props??{},children:r,...a.key!==void 0&&a.key!==null?{key:a.key}:{}};return _.createElement(a.type,s)}import{Fragment as be,jsx as f,jsxs as Be}from"react/jsx-runtime";var _e={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},T=typeof p.createContext=="function"?p.createContext(null):null,J="__WEBFRAMEZ_ROUTER__",we="__WEBFRAMEZ_REACT_BUILD_ID",he="x-webframez-react-build",ge="[data-webframez-head='true']";function G(){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 c(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 v(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function ee(e){if(typeof window>"u")return e||"/";let t=v(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[we];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 Se(e){typeof window>"u"||(window[J]=e)}function Ne(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function q(e){return Ne(e)?p.use(e):e}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 je(){return p.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 Ge(){let e=T?p.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 Pe({active:e}){return f("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 L(e){if(typeof document>"u")return;let t=N(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=N(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=Q(r,"/rsc"))}function Ie(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function Le(){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 ve(e){let t=te(e),n=ee(window.location.pathname);return Le()??X(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=p.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[a,s]=l(o.model),[u,w]=l(o.contextModel),[m,h]=l(o.pageModel),[x,b]=l(o.head),[oe,g]=l(!1),[re,ie]=l(!1),[ae,A]=l(r);async function B(i){let y=te(t),d=ee(i.pathname),R=await fetch(`${y}?path=${encodeURIComponent(d)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}});return Te(R.headers.get(he))?(I(i),await new Promise(()=>{})):await X(Promise.resolve(R))}async function C(i,y="push"){g(!0);try{let d=await B(i);L(d.head),b(d.head),s(d.model),w(d.contextModel),h(d.pageModel),A(!0);let R=`${i.pathname}${i.search}${i.hash}`;y==="replace"?(history.replaceState(null,"",R),G()):y==="push"&&(history.pushState(null,"",R),G())}catch(d){console.error("[webframez-react] Failed to render route",d),I(i),s(f("p",{children:"Failed to load route."}))}finally{g(!1)}}async function se(){g(!0);try{let i=await B(new URL(window.location.href));if(L(i.head),b(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){w(i.contextModel),A(!0);return}s(i.model),A(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i),I(new URL(window.location.href))}finally{g(!1)}}j(()=>{L(x)},[x]),j(()=>{ie(!0);let i=()=>{C(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let O=p.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()}}),[]);Se(O);let k=q(u),S=q(m),ce=ae&&typeof m<"u"?k?f(Re,{page:S,children:E(k,S)}):S:a,U=Be(be,{children:[re?f(Pe,{active:oe}):null,ce??f("p",{style:{padding:24},children:"Loading..."})]});return T?f(T.Provider,{value:O,children:U}):U}}function qe(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(ve(r)).then(u=>(u?.head&&ne(u.head),u)),s=xe(a,r);return pe(n,f(s,{}))}export{qe as mountWebframezClient,je as useCookie,Ge as useRouter};
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};
package/dist/http.cjs CHANGED
@@ -1781,7 +1781,7 @@ function createNodeRequestHandler(options) {
1781
1781
  transportBasePath,
1782
1782
  clientScriptUrl
1783
1783
  ),
1784
- createClientAssetVersion(distRootDir)
1784
+ manifestState.buildId
1785
1785
  );
1786
1786
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1787
1787
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
package/dist/http.js CHANGED
@@ -1761,7 +1761,7 @@ function createNodeRequestHandler(options) {
1761
1761
  transportBasePath,
1762
1762
  clientScriptUrl
1763
1763
  ),
1764
- createClientAssetVersion(distRootDir)
1764
+ manifestState.buildId
1765
1765
  );
1766
1766
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1767
1767
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
package/dist/index.cjs CHANGED
@@ -1821,7 +1821,7 @@ function createNodeRequestHandler(options) {
1821
1821
  transportBasePath,
1822
1822
  clientScriptUrl
1823
1823
  ),
1824
- createClientAssetVersion(distRootDir)
1824
+ manifestState.buildId
1825
1825
  );
1826
1826
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1827
1827
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
package/dist/index.js CHANGED
@@ -1787,7 +1787,7 @@ function createNodeRequestHandler(options) {
1787
1787
  transportBasePath,
1788
1788
  clientScriptUrl
1789
1789
  ),
1790
- createClientAssetVersion(distRootDir)
1790
+ manifestState.buildId
1791
1791
  );
1792
1792
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1793
1793
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
@@ -1788,7 +1788,7 @@ function createNodeRequestHandler(options) {
1788
1788
  transportBasePath,
1789
1789
  clientScriptUrl
1790
1790
  ),
1791
- createClientAssetVersion(distRootDir)
1791
+ manifestState.buildId
1792
1792
  );
1793
1793
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1794
1794
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
@@ -1764,7 +1764,7 @@ function createNodeRequestHandler(options) {
1764
1764
  transportBasePath,
1765
1765
  clientScriptUrl
1766
1766
  ),
1767
- createClientAssetVersion(distRootDir)
1767
+ manifestState.buildId
1768
1768
  );
1769
1769
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1770
1770
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {