flexium 0.12.19 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -29
- package/dist/canvas.d.cts +1 -1
- package/dist/canvas.d.ts +1 -1
- package/dist/canvas.js +1 -1
- package/dist/canvas.js.map +1 -1
- package/dist/canvas.mjs +1 -1
- package/dist/canvas.mjs.map +1 -1
- package/dist/chunk-3AKECLKA.mjs +2 -0
- package/dist/chunk-3AKECLKA.mjs.map +1 -0
- package/dist/chunk-3CKIHQIE.js +2 -0
- package/dist/chunk-3CKIHQIE.js.map +1 -0
- package/dist/chunk-ACYN2UKT.js +2 -0
- package/dist/chunk-ACYN2UKT.js.map +1 -0
- package/dist/chunk-E6Z7AI4J.js +2 -0
- package/dist/chunk-E6Z7AI4J.js.map +1 -0
- package/dist/chunk-MI76R42D.mjs +2 -0
- package/dist/chunk-MI76R42D.mjs.map +1 -0
- package/dist/chunk-NRPWBHKP.mjs +2 -0
- package/dist/chunk-NRPWBHKP.mjs.map +1 -0
- package/dist/chunk-PUXZJ7OV.js +2 -0
- package/dist/{chunk-6Z33DLMI.js.map → chunk-PUXZJ7OV.js.map} +1 -1
- package/dist/chunk-TP5HUAIN.mjs +2 -0
- package/dist/{chunk-E75BJDOQ.mjs.map → chunk-TP5HUAIN.mjs.map} +1 -1
- package/dist/core.d.cts +47 -73
- package/dist/core.d.ts +47 -73
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/dom.d.cts +1 -1
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +1 -1
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +1 -1
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/interactive.d.cts +4 -4
- package/dist/interactive.d.ts +4 -4
- package/dist/interactive.js +1 -1
- package/dist/interactive.js.map +1 -1
- package/dist/interactive.mjs +1 -1
- package/dist/interactive.mjs.map +1 -1
- package/dist/jsx-dev-runtime.d.cts +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.cts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/render-4HB53K66.mjs +2 -0
- package/dist/{render-UIWHIMS2.mjs.map → render-4HB53K66.mjs.map} +1 -1
- package/dist/render-MJ2LCNSG.js +2 -0
- package/dist/{render-QZAFAGIM.js.map → render-MJ2LCNSG.js.map} +1 -1
- package/dist/router.d.cts +7 -3
- package/dist/router.d.ts +7 -3
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/dist/router.mjs +1 -1
- package/dist/router.mjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/{types-y2GGaXXk.d.cts → types-DH8L3A5z.d.cts} +1 -1
- package/dist/{types-y2GGaXXk.d.ts → types-DH8L3A5z.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-3DKZ2J4D.mjs +0 -2
- package/dist/chunk-3DKZ2J4D.mjs.map +0 -1
- package/dist/chunk-5PNH2ARD.mjs +0 -2
- package/dist/chunk-5PNH2ARD.mjs.map +0 -1
- package/dist/chunk-6VIRXD2Y.js +0 -2
- package/dist/chunk-6VIRXD2Y.js.map +0 -1
- package/dist/chunk-6Z33DLMI.js +0 -2
- package/dist/chunk-E75BJDOQ.mjs +0 -2
- package/dist/chunk-IWFEXW4F.mjs +0 -2
- package/dist/chunk-IWFEXW4F.mjs.map +0 -1
- package/dist/chunk-JY6CE6RN.mjs +0 -2
- package/dist/chunk-JY6CE6RN.mjs.map +0 -1
- package/dist/chunk-LTT43APF.js +0 -2
- package/dist/chunk-LTT43APF.js.map +0 -1
- package/dist/chunk-PSKDIB7J.js +0 -2
- package/dist/chunk-PSKDIB7J.js.map +0 -1
- package/dist/chunk-UWFVCKRU.js +0 -2
- package/dist/chunk-UWFVCKRU.js.map +0 -1
- package/dist/chunk-WGKD63GN.mjs +0 -2
- package/dist/chunk-WGKD63GN.mjs.map +0 -1
- package/dist/chunk-YWTD32NA.js +0 -2
- package/dist/chunk-YWTD32NA.js.map +0 -1
- package/dist/render-QZAFAGIM.js +0 -2
- package/dist/render-UIWHIMS2.mjs +0 -2
package/dist/router.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as FNodeChild, F as FNode } from './types-DH8L3A5z.cjs';
|
|
2
2
|
|
|
3
3
|
interface Location {
|
|
4
4
|
pathname: string;
|
|
@@ -35,7 +35,11 @@ interface LinkProps {
|
|
|
35
35
|
children?: any;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
declare function
|
|
38
|
+
declare function useLocation(): [Location, (path: string) => void];
|
|
39
|
+
declare function useRouter(): RouterContext;
|
|
40
|
+
declare function useNavigate(): (path: string) => void;
|
|
41
|
+
declare function useParams<T extends Record<string, string> = Record<string, string>>(): T;
|
|
42
|
+
declare function useQuery<T extends Record<string, string> = Record<string, string>>(): T;
|
|
39
43
|
|
|
40
44
|
declare function Routes(props: {
|
|
41
45
|
children: FNodeChild;
|
|
@@ -47,4 +51,4 @@ declare function Outlet(): FNode | null;
|
|
|
47
51
|
|
|
48
52
|
declare function Link(props: LinkProps): FNode;
|
|
49
53
|
|
|
50
|
-
export { Link, type LinkProps, type Location, Outlet, Route, type RouteDefinition, type RouteMatch, type RouteProps, type RouterContext, Routes,
|
|
54
|
+
export { Link, type LinkProps, type Location, Outlet, Route, type RouteDefinition, type RouteMatch, type RouteProps, type RouterContext, Routes, useLocation, useNavigate, useParams, useQuery, useRouter };
|
package/dist/router.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as FNodeChild, F as FNode } from './types-DH8L3A5z.js';
|
|
2
2
|
|
|
3
3
|
interface Location {
|
|
4
4
|
pathname: string;
|
|
@@ -35,7 +35,11 @@ interface LinkProps {
|
|
|
35
35
|
children?: any;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
declare function
|
|
38
|
+
declare function useLocation(): [Location, (path: string) => void];
|
|
39
|
+
declare function useRouter(): RouterContext;
|
|
40
|
+
declare function useNavigate(): (path: string) => void;
|
|
41
|
+
declare function useParams<T extends Record<string, string> = Record<string, string>>(): T;
|
|
42
|
+
declare function useQuery<T extends Record<string, string> = Record<string, string>>(): T;
|
|
39
43
|
|
|
40
44
|
declare function Routes(props: {
|
|
41
45
|
children: FNodeChild;
|
|
@@ -47,4 +51,4 @@ declare function Outlet(): FNode | null;
|
|
|
47
51
|
|
|
48
52
|
declare function Link(props: LinkProps): FNode;
|
|
49
53
|
|
|
50
|
-
export { Link, type LinkProps, type Location, Outlet, Route, type RouteDefinition, type RouteMatch, type RouteProps, type RouterContext, Routes,
|
|
54
|
+
export { Link, type LinkProps, type Location, Outlet, Route, type RouteDefinition, type RouteMatch, type RouteProps, type RouterContext, Routes, useLocation, useNavigate, useParams, useQuery, useRouter };
|
package/dist/router.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkACYN2UKT_js=require('./chunk-ACYN2UKT.js');require('./chunk-3CKIHQIE.js');var chunkE6Z7AI4J_js=require('./chunk-E6Z7AI4J.js'),chunkDUGPBZZ3_js=require('./chunk-DUGPBZZ3.js');function k(t){if(!t)return {};if(typeof URLSearchParams<"u"){let e=new URLSearchParams(t),r={};return e.forEach((n,o)=>r[o]=n),r}return t.substring(1).split("&").reduce((e,r)=>{let[n,o]=r.split("=");return n&&(e[decodeURIComponent(n)]=decodeURIComponent(o||"")),e},{})}function D(t){return !!(t.length>2048||t.includes("__proto__")||t.includes("constructor")||/^\s*javascript:/i.test(t))}function R(t){let e=[];return t.forEach(r=>{if(!r)return;let{path:n,component:o,children:i,beforeEnter:f}=r.props||{},u={path:n||"/",component:o,beforeEnter:f};if(i){let c=Array.isArray(i)?i:[i];u.children=R(c);}!u.children&&r.children&&r.children.length>0&&(u.children=R(r.children)),e.push(u);}),e}function E(t,e){for(let r of t){let n=r.path,o=T(n,e);if(o)return [{route:r,params:o.params,pathname:o.path}]}return null}function T(t,e){let r=t.split("/").filter(Boolean),n=e.split("/").filter(Boolean);if(r.length!==n.length)return null;let o={};for(let i=0;i<r.length;i++){let f=r[i],u=n[i];if(f.startsWith(":")){let c=f.slice(1);o[c]=u;}else if(f!==u)return null}return {params:o,path:e}}var L=new chunkE6Z7AI4J_js.c(null),p=new chunkE6Z7AI4J_js.c(0),U=()=>({pathname:"/",search:"",hash:"",query:{}}),w=()=>typeof window>"u"?U():{pathname:window.location.pathname,search:window.location.search,hash:window.location.hash,query:k(window.location.search)},l=null,y=null,N=false;function d(){if(l&&y)return [l,y];l=chunkACYN2UKT_js.a(w());let t=e=>{l&&(l.pathname=e.pathname,l.search=e.search,l.hash=e.hash,l.query=e.query);};return y=e=>{if(typeof window>"u")return;if(D(e)){console.error("[Flexium Router] Blocked navigation to unsafe path:",e);return}window.history.pushState({},"",e);let r=w();t(r);},typeof window<"u"&&!N&&(window.addEventListener("popstate",()=>{t(w());}),N=true),[l,y]}function m(){let[t]=chunkACYN2UKT_js.c(L);if(!t)throw new Error("useRouter() must be called within a <Routes> component");return t}function j(){let[,t]=d();return t}function q(){return m().params}function _(){let[t]=d();return t.query}function x(t){return null}function F(t){return t&&typeof t=="object"&&("type"in t||Array.isArray(t))}function Q(t){let[e,r]=d(),n=Array.isArray(t.children)?t.children:[t.children],o=n.filter(s=>F(s)&&s.type===x),i=n.filter(s=>!F(s)||s.type!==x),f=R(o),u=e.pathname,c=E(f,u)||[],A=c.length>0?c[c.length-1].params:{},S={location:e,navigate:r,matches:c,params:A},C=null;if(c.length>0){let s=c[0],P=s.route.component,g=u;s.route.beforeEnter?s.route.beforeEnter(s.params)!==false&&(C=chunkDUGPBZZ3_js.a(p.Provider,{value:1,key:g,children:chunkDUGPBZZ3_js.a(P,{params:s.params,key:g})})):C=chunkDUGPBZZ3_js.a(p.Provider,{value:1,key:g,children:chunkDUGPBZZ3_js.a(P,{params:s.params,key:g})});}return chunkDUGPBZZ3_js.a(L.Provider,{value:S,children:[...i,C]})}function B(){let t=m(),[e]=chunkACYN2UKT_js.c(p),r=e??0,[n]=chunkACYN2UKT_js.c(()=>t.matches);if(r>=n.length)return null;let o=n[r],i=o.route.component;return o.route.beforeEnter&&o.route.beforeEnter(o.params)===false?null:chunkDUGPBZZ3_js.a(p.Provider,{value:r+1,children:chunkDUGPBZZ3_js.a(i,{params:o.params})})}function M(t){let e=m();return chunkDUGPBZZ3_js.a("a",{href:t.to,class:t.class,onclick:r=>{r.preventDefault(),e.navigate(t.to);},children:t.children})}exports.Link=M;exports.Outlet=B;exports.Route=x;exports.Routes=Q;exports.useLocation=d;exports.useNavigate=j;exports.useParams=q;exports.useQuery=_;exports.useRouter=m;//# sourceMappingURL=router.js.map
|
|
2
2
|
//# sourceMappingURL=router.js.map
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/router/utils.ts","../src/router/router.ts","../src/router/dom/Route.tsx","../src/router/dom/Routes.tsx","../src/router/dom/Outlet.tsx","../src/router/dom/Link.tsx"],"names":["parseQuery","search","params","result","value","key","accumulator","part","isUnsafePath","path","createRoutesFromChildren","children","routes","child","component","subChildren","beforeEnter","route","nestedChildren","matchRoutes","locationPathname","routePath","matchResult","matchPath","locationPath","routeSegments","locationSegments","i","routeSegment","locationSegment","RouterCtx","createContext","RouteDepthCtx","getDefaultLocation","getCurrentLocation","globalLocation","globalNavigate","popstateListenerAttached","location","reactive","updateLocation","newLocation","router","routerContext","context","Route","_props","isFNode","node","Routes","props","currentLocation","navigate","childrenList","routeNodes","otherChildren","routeDefinitions","currentPath","matches","matchedContent","rootMatch","Component","routeKey","jsx","Outlet","depth","state","match","Link","event"],"mappings":"mRAGA,SAASA,CAAAA,CAAWC,EAAwC,CAC1D,GAAI,CAACA,CAAAA,CAAQ,OAAO,EAAC,CACrB,GAAI,OAAO,eAAA,CAAoB,GAAA,CAAa,CAC1C,IAAMC,CAAAA,CAAS,IAAI,eAAA,CAAgBD,CAAM,EACnCE,CAAAA,CAAiC,GACvC,OAAAD,CAAAA,CAAO,QAAQ,CAACE,CAAAA,CAAOC,IAAQF,CAAAA,CAAOE,CAAG,EAAID,CAAK,CAAA,CAC3CD,CACT,CACA,OAAOF,EACJ,SAAA,CAAU,CAAC,EACX,KAAA,CAAM,GAAG,EACT,MAAA,CAAO,CAACK,EAAaC,CAAAA,GAAS,CAC7B,GAAM,CAACF,CAAAA,CAAKD,CAAK,CAAA,CAAIG,CAAAA,CAAK,MAAM,GAAG,CAAA,CACnC,OAAIF,CAAAA,GAAKC,CAAAA,CAAY,mBAAmBD,CAAG,CAAC,EAAI,kBAAA,CAAmBD,CAAAA,EAAS,EAAE,CAAA,CAAA,CACvEE,CACT,EAAG,EAA4B,CACnC,CAEA,SAASE,EAAaC,CAAAA,CAAuB,CAK3C,OAHI,CAAA,EAAAA,CAAAA,CAAK,OAAS,IAAA,EACdA,CAAAA,CAAK,SAAS,WAAW,CAAA,EAAKA,EAAK,QAAA,CAAS,aAAa,GAEzD,kBAAA,CAAmB,IAAA,CAAKA,CAAI,CAAA,CAElC,CAGA,SAASC,CAAAA,CAAyBC,CAAAA,CAAoC,CACpE,IAAMC,CAAAA,CAA4B,EAAC,CAEnC,OAAAD,EAAS,OAAA,CAAQE,CAAAA,EAAS,CACxB,GAAI,CAACA,EAAO,OAMZ,GAAM,CAAE,IAAA,CAAAJ,CAAAA,CAAM,UAAAK,CAAAA,CAAW,QAAA,CAAUC,EAAa,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ourcesContent":["import { RouteDefinition, RouteMatch } from './types'\n\n// Simple query parser (native URLSearchParams fallback) - internal use only\nfunction parseQuery(search: string): Record<string, string> {\n if (!search) return {}\n if (typeof URLSearchParams !== 'undefined') {\n const params = new URLSearchParams(search)\n const result: Record<string, string> = {}\n params.forEach((value, key) => result[key] = value)\n return result\n }\n return search\n .substring(1)\n .split('&')\n .reduce((accumulator, part) => {\n const [key, value] = part.split('=')\n if (key) accumulator[decodeURIComponent(key)] = decodeURIComponent(value || '')\n return accumulator\n }, {} as Record<string, string>)\n}\n\nfunction isUnsafePath(path: string): boolean {\n // Prevent prototype pollution or massive strings\n if (path.length > 2048) return true\n if (path.includes('__proto__') || path.includes('constructor')) return true\n // Basic XSS check for javascript: protocol\n if (/^\\s*javascript:/i.test(path)) return true\n return false\n}\n\n// Convert children FNodes to RouteDefinitions - internal use only\nfunction createRoutesFromChildren(children: any[]): RouteDefinition[] {\n const routes: RouteDefinition[] = []\n\n children.forEach(child => {\n if (!child) return\n\n // Assuming child is an FNode-like object (config)\n // In Flexium, Route component returns null, but 'createNode' isn't called here.\n // We are traversing the props passed to Router.\n\n const { path, component, children: subChildren, beforeEnter } = child.props || {}\n\n const route: RouteDefinition = {\n path: path || '/',\n component: component,\n beforeEnter\n }\n\n if (subChildren) {\n // If subChildren is array\n const nestedChildren = Array.isArray(subChildren) ? subChildren : [subChildren]\n // We expect the children of a Route to be other Routes\n // However, the 'children' prop in JSX might be the Route components themselves.\n route.children = createRoutesFromChildren(nestedChildren)\n }\n\n // Also check child.children if props.children is empty (direct FNode structure)\n if (!route.children && child.children && child.children.length > 0) {\n route.children = createRoutesFromChildren(child.children)\n }\n\n routes.push(route)\n })\n return routes\n}\n\n// Simple Matcher - internal use only\nfunction matchRoutes(routes: RouteDefinition[], locationPathname: string): RouteMatch[] | null {\n // We want to find the best matching branch\n\n for (const route of routes) {\n // 1. Match current segment\n // Simple exact match or parameter match logic needed?\n // Let's implement simple param matching: /user/:id\n\n const routePath = route.path\n\n const matchResult = matchPath(routePath, locationPathname)\n if (matchResult) {\n return [{ route, params: matchResult.params, pathname: matchResult.path }]\n }\n }\n return null\n}\n\nfunction matchPath(routePath: string, locationPath: string) {\n // 1. Split into segments\n const routeSegments = routePath.split('/').filter(Boolean)\n const locationSegments = locationPath.split('/').filter(Boolean)\n\n if (routeSegments.length !== locationSegments.length) return null\n\n const params: Record<string, string> = {}\n\n for (let i = 0; i < routeSegments.length; i++) {\n const routeSegment = routeSegments[i]\n const locationSegment = locationSegments[i]\n\n if (routeSegment.startsWith(':')) {\n const key = routeSegment.slice(1)\n params[key] = locationSegment\n } else if (routeSegment !== locationSegment) {\n return null\n }\n }\n\n return { params, path: locationPath }\n}\n\n// Export only what's needed by other router files\nexport { parseQuery, isUnsafePath, createRoutesFromChildren, matchRoutes }\n","import { reactive } from '../core/reactive'\nimport { createContext, context } from '../core/context'\nimport type { Location, RouterContext } from './types'\nimport { parseQuery, isUnsafePath } from './utils'\n\n// Contexts\nexport const RouterCtx = createContext<RouterContext>(null as any)\nexport const RouteDepthCtx = createContext<number>(0)\n\n// Helper functions\nconst getDefaultLocation = (): Location => ({\n pathname: '/',\n search: '',\n hash: '',\n query: {},\n})\n\nconst getCurrentLocation = (): Location => {\n if (typeof window === 'undefined') {\n return getDefaultLocation()\n }\n return {\n pathname: window.location.pathname,\n search: window.location.search,\n hash: window.location.hash,\n query: parseQuery(window.location.search),\n }\n}\n\n// Global singleton location state\nlet globalLocation: Location | null = null\nlet globalNavigate: ((path: string) => void) | null = null\nlet popstateListenerAttached = false\n\n// Create location state and navigation (singleton pattern)\nexport function location(): [Location, (path: string) => void] {\n // Return existing singleton if already created\n if (globalLocation && globalNavigate) {\n return [globalLocation, globalNavigate]\n }\n\n // Create a reactive location object (only once)\n globalLocation = reactive<Location>(getCurrentLocation())\n\n const updateLocation = (newLocation: Location) => {\n if (!globalLocation) return\n globalLocation.pathname = newLocation.pathname\n globalLocation.search = newLocation.search\n globalLocation.hash = newLocation.hash\n globalLocation.query = newLocation.query\n }\n\n globalNavigate = (path: string) => {\n if (typeof window === 'undefined') return\n if (isUnsafePath(path)) {\n console.error('[Flexium Router] Blocked navigation to unsafe path:', path)\n return\n }\n window.history.pushState({}, '', path)\n const newLocation = getCurrentLocation()\n updateLocation(newLocation)\n }\n\n // Listen to popstate (only once)\n if (typeof window !== 'undefined' && !popstateListenerAttached) {\n window.addEventListener('popstate', () => {\n updateLocation(getCurrentLocation())\n })\n popstateListenerAttached = true\n }\n\n return [globalLocation, globalNavigate]\n}\n\n// Router hook\nexport function router(): RouterContext {\n const routerContext = context(RouterCtx)\n if (!routerContext) {\n throw new Error('router() must be called within a <Routes> component')\n }\n return routerContext\n}\n","import type { RouteProps } from '../types'\n\nexport function Route(_props: RouteProps) {\n return null\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { FNode, FNodeChild } from '../../dom'\nimport { RouterCtx, RouteDepthCtx, location } from '../router'\nimport { createRoutesFromChildren, matchRoutes } from '../utils'\nimport { Route } from './Route'\n\nfunction isFNode(node: any): node is FNode {\n return node && typeof node === 'object' && ('type' in node || Array.isArray(node))\n}\n\nexport function Routes(props: { children: FNodeChild }) {\n const [currentLocation, navigate] = location()\n\n // Parse children to find <Route> definitions and other content\n let childrenList: any[] = Array.isArray(props.children) ? props.children : [props.children]\n\n // Separate routes from other children (like Nav components)\n const routeNodes = childrenList.filter(child => isFNode(child) && child.type === Route)\n const otherChildren = childrenList.filter(child => !isFNode(child) || child.type !== Route)\n\n // Create route definitions\n const routeDefinitions = createRoutesFromChildren(routeNodes)\n\n // DIRECT access to currentLocation.pathname\n // This should trigger reactive tracking in the component's effect context\n const currentPath = currentLocation.pathname\n const matches = matchRoutes(routeDefinitions, currentPath) || []\n const params = matches.length > 0 ? matches[matches.length - 1].params : {}\n\n const routerContext = {\n location: currentLocation,\n navigate,\n matches: matches,\n params: params\n }\n\n // Render matched component\n let matchedContent: FNodeChild = null\n\n if (matches.length > 0) {\n const rootMatch = matches[0]\n const Component = rootMatch.route.component\n\n // Use pathname as key to force re-mount on route change\n const routeKey = currentPath\n\n // Guard Check\n if (rootMatch.route.beforeEnter) {\n const result = rootMatch.route.beforeEnter(rootMatch.params)\n if (result !== false) {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n } else {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n }\n\n return f(RouterCtx.Provider, {\n value: routerContext,\n children: [...otherChildren, matchedContent]\n })\n}\n","import { state } from '../../core/state'\nimport { context } from '../../core/context'\nimport { jsx as f } from '../../jsx-runtime'\nimport { RouteDepthCtx, router } from '../router'\n\nexport function Outlet() {\n const routerContext = router()\n const depth = (context(RouteDepthCtx) as number) || 0\n\n const [matches] = state(() => routerContext.matches)\n\n if (depth >= matches.length) return null\n\n const match = matches[depth]\n const Component = match.route.component\n\n // Guard\n if (match.route.beforeEnter) {\n if (match.route.beforeEnter(match.params) === false) return null\n }\n\n // Render next level\n return f(RouteDepthCtx.Provider, {\n value: depth + 1,\n children: f(Component, { params: match.params })\n })\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { LinkProps } from '../types'\nimport { router } from '../router'\n\nexport function Link(props: LinkProps) {\n const routerContext = router()\n return f('a', {\n href: props.to,\n class: props.class,\n onclick: (event: Event) => {\n event.preventDefault()\n routerContext.navigate(props.to)\n },\n children: props.children\n })\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/router/utils.ts","../src/router/router.ts","../src/router/dom/Route.tsx","../src/router/dom/Routes.tsx","../src/router/dom/Outlet.tsx","../src/router/dom/Link.tsx"],"names":["parseQuery","search","params","result","value","key","accumulator","part","isUnsafePath","path","createRoutesFromChildren","children","routes","child","component","subChildren","beforeEnter","route","nestedChildren","matchRoutes","locationPathname","routePath","matchResult","matchPath","locationPath","routeSegments","locationSegments","routeSegment","locationSegment","RouterCtx","Context","RouteDepthCtx","getDefaultLocation","getCurrentLocation","globalLocation","globalNavigate","popstateListenerAttached","useLocation","reactive","updateLocation","newLocation","useRouter","routerContext","use","useNavigate","navigate","useParams","useQuery","location","Route","_props","isFNode","node","Routes","props","currentLocation","childrenList","routeNodes","otherChildren","routeDefinitions","currentPath","matches","matchedContent","rootMatch","Component","routeKey","jsx","Outlet","depthValue","depth","match","Link","event"],"mappings":"oMAGA,SAASA,CAAAA,CAAWC,EAAwC,CAC1D,GAAI,CAACA,CAAAA,CAAQ,OAAO,EAAC,CACrB,GAAI,OAAO,eAAA,CAAoB,GAAA,CAAa,CAC1C,IAAMC,CAAAA,CAAS,IAAI,eAAA,CAAgBD,CAAM,CAAA,CACnCE,CAAAA,CAAiC,EAAC,CACxC,OAAAD,CAAAA,CAAO,OAAA,CAAQ,CAACE,CAAAA,CAAOC,CAAAA,GAAQF,EAAOE,CAAG,CAAA,CAAID,CAAK,CAAA,CAC3CD,CACT,CACA,OAAOF,CAAAA,CACJ,UAAU,CAAC,CAAA,CACX,MAAM,GAAG,CAAA,CACT,MAAA,CAAO,CAACK,CAAAA,CAAaC,CAAAA,GAAS,CAC7B,GAAM,CAACF,EAAKD,CAAK,CAAA,CAAIG,EAAK,KAAA,CAAM,GAAG,EACnC,OAAIF,CAAAA,GAAKC,EAAY,kBAAA,CAAmBD,CAAG,CAAC,CAAA,CAAI,kBAAA,CAAmBD,GAAS,EAAE,CAAA,CAAA,CACvEE,CACT,CAAA,CAAG,EAA4B,CACnC,CAEA,SAASE,EAAaC,CAAAA,CAAuB,CAK3C,OAHI,CAAA,EAAAA,CAAAA,CAAK,MAAA,CAAS,IAAA,EACdA,CAAAA,CAAK,QAAA,CAAS,WAAW,CAAA,EAAKA,CAAAA,CAAK,SAAS,aAAa,CAAA,EAEzD,mBAAmB,IAAA,CAAKA,CAAI,CAAA,CAElC,CAGA,SAASC,CAAAA,CAAyBC,EAAoC,CACpE,IAAMC,EAA4B,EAAC,CAEnC,OAAAD,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AAA,CAAM,SAAA,CAG9B,OAAIA,CAAAA,CAAM,KAAA,CAAM,aACRA,CAAAA,CAAM,KAAA,CAAM,YAAYA,CAAAA,CAAM,MAAM,IAAM,KAAA,CAAc,IAAA,CAIzDJ,kBAAAA,CAAEnC,CAAAA,CAAc,QAAA,CAAU,CAC7B,MAAOsC,CAAAA,CAAQ,CAAA,CACf,SAAUH,kBAAAA,CAAEF,CAAAA,CAAW,CAAE,MAAA,CAAQM,CAAAA,CAAM,MAAO,CAAC,CACnD,CAAC,CACL,CCtBO,SAASC,CAAAA,CAAKjB,CAAAA,CAAkB,CACnC,IAAMZ,CAAAA,CAAgBD,CAAAA,EAAU,CAChC,OAAOyB,kBAAAA,CAAE,IAAK,CACV,IAAA,CAAMZ,EAAM,EAAA,CACZ,KAAA,CAAOA,EAAM,KAAA,CACb,OAAA,CAAUkB,CAAAA,EAAiB,CACvBA,CAAAA,CAAM,cAAA,GACN9B,CAAAA,CAAc,QAAA,CAASY,EAAM,EAAE,EACnC,EACA,QAAA,CAAUA,CAAAA,CAAM,QACpB,CAAC,CACL","file":"router.js","sourcesContent":["import { RouteDefinition, RouteMatch } from './types'\n\n// Simple query parser (native URLSearchParams fallback) - internal use only\nfunction parseQuery(search: string): Record<string, string> {\n if (!search) return {}\n if (typeof URLSearchParams !== 'undefined') {\n const params = new URLSearchParams(search)\n const result: Record<string, string> = {}\n params.forEach((value, key) => result[key] = value)\n return result\n }\n return search\n .substring(1)\n .split('&')\n .reduce((accumulator, part) => {\n const [key, value] = part.split('=')\n if (key) accumulator[decodeURIComponent(key)] = decodeURIComponent(value || '')\n return accumulator\n }, {} as Record<string, string>)\n}\n\nfunction isUnsafePath(path: string): boolean {\n // Prevent prototype pollution or massive strings\n if (path.length > 2048) return true\n if (path.includes('__proto__') || path.includes('constructor')) return true\n // Basic XSS check for javascript: protocol\n if (/^\\s*javascript:/i.test(path)) return true\n return false\n}\n\n// Convert children FNodes to RouteDefinitions - internal use only\nfunction createRoutesFromChildren(children: any[]): RouteDefinition[] {\n const routes: RouteDefinition[] = []\n\n children.forEach(child => {\n if (!child) return\n\n // Assuming child is an FNode-like object (config)\n // In Flexium, Route component returns null, but 'createNode' isn't called here.\n // We are traversing the props passed to Router.\n\n const { path, component, children: subChildren, beforeEnter } = child.props || {}\n\n const route: RouteDefinition = {\n path: path || '/',\n component: component,\n beforeEnter\n }\n\n if (subChildren) {\n // If subChildren is array\n const nestedChildren = Array.isArray(subChildren) ? subChildren : [subChildren]\n // We expect the children of a Route to be other Routes\n // However, the 'children' prop in JSX might be the Route components themselves.\n route.children = createRoutesFromChildren(nestedChildren)\n }\n\n // Also check child.children if props.children is empty (direct FNode structure)\n if (!route.children && child.children && child.children.length > 0) {\n route.children = createRoutesFromChildren(child.children)\n }\n\n routes.push(route)\n })\n return routes\n}\n\n// Simple Matcher - internal use only\nfunction matchRoutes(routes: RouteDefinition[], locationPathname: string): RouteMatch[] | null {\n // We want to find the best matching branch\n\n for (const route of routes) {\n // 1. Match current segment\n // Simple exact match or parameter match logic needed?\n // Let's implement simple param matching: /user/:id\n\n const routePath = route.path\n\n const matchResult = matchPath(routePath, locationPathname)\n if (matchResult) {\n return [{ route, params: matchResult.params, pathname: matchResult.path }]\n }\n }\n return null\n}\n\nfunction matchPath(routePath: string, locationPath: string) {\n // 1. Split into segments\n const routeSegments = routePath.split('/').filter(Boolean)\n const locationSegments = locationPath.split('/').filter(Boolean)\n\n if (routeSegments.length !== locationSegments.length) return null\n\n const params: Record<string, string> = {}\n\n for (let i = 0; i < routeSegments.length; i++) {\n const routeSegment = routeSegments[i]\n const locationSegment = locationSegments[i]\n\n if (routeSegment.startsWith(':')) {\n const key = routeSegment.slice(1)\n params[key] = locationSegment\n } else if (routeSegment !== locationSegment) {\n return null\n }\n }\n\n return { params, path: locationPath }\n}\n\n// Export only what's needed by other router files\nexport { parseQuery, isUnsafePath, createRoutesFromChildren, matchRoutes }\n","import { reactive } from '../core/reactive'\nimport { Context } from '../core/context'\nimport { use } from '../core/use'\nimport type { Location, RouterContext } from './types'\nimport { parseQuery, isUnsafePath } from './utils'\n\n// Contexts\nexport const RouterCtx = new Context<RouterContext>(null as any)\nexport const RouteDepthCtx = new Context<number>(0)\n\n// Helper functions\nconst getDefaultLocation = (): Location => ({\n pathname: '/',\n search: '',\n hash: '',\n query: {},\n})\n\nconst getCurrentLocation = (): Location => {\n if (typeof window === 'undefined') {\n return getDefaultLocation()\n }\n return {\n pathname: window.location.pathname,\n search: window.location.search,\n hash: window.location.hash,\n query: parseQuery(window.location.search),\n }\n}\n\n// Global singleton location state\nlet globalLocation: Location | null = null\nlet globalNavigate: ((path: string) => void) | null = null\nlet popstateListenerAttached = false\n\n// Create location state and navigation (singleton pattern)\nexport function useLocation(): [Location, (path: string) => void] {\n // Return existing singleton if already created\n if (globalLocation && globalNavigate) {\n return [globalLocation, globalNavigate]\n }\n\n // Create a reactive location object (only once)\n globalLocation = reactive<Location>(getCurrentLocation())\n\n const updateLocation = (newLocation: Location) => {\n if (!globalLocation) return\n globalLocation.pathname = newLocation.pathname\n globalLocation.search = newLocation.search\n globalLocation.hash = newLocation.hash\n globalLocation.query = newLocation.query\n }\n\n globalNavigate = (path: string) => {\n if (typeof window === 'undefined') return\n if (isUnsafePath(path)) {\n console.error('[Flexium Router] Blocked navigation to unsafe path:', path)\n return\n }\n window.history.pushState({}, '', path)\n const newLocation = getCurrentLocation()\n updateLocation(newLocation)\n }\n\n // Listen to popstate (only once)\n if (typeof window !== 'undefined' && !popstateListenerAttached) {\n window.addEventListener('popstate', () => {\n updateLocation(getCurrentLocation())\n })\n popstateListenerAttached = true\n }\n\n return [globalLocation, globalNavigate]\n}\n\n// Router hook - returns full router context\nexport function useRouter(): RouterContext {\n const [routerContext] = use(RouterCtx)\n if (!routerContext) {\n throw new Error('useRouter() must be called within a <Routes> component')\n }\n return routerContext\n}\n\n// Navigate hook - returns navigate function\nexport function useNavigate(): (path: string) => void {\n const [, navigate] = useLocation()\n return navigate\n}\n\n// Params hook - returns route params\nexport function useParams<T extends Record<string, string> = Record<string, string>>(): T {\n const router = useRouter()\n return router.params as T\n}\n\n// Query hook - returns query params\nexport function useQuery<T extends Record<string, string> = Record<string, string>>(): T {\n const [location] = useLocation()\n return location.query as T\n}\n","import type { RouteProps } from '../types'\n\nexport function Route(_props: RouteProps) {\n return null\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { FNode, FNodeChild } from '../../dom'\nimport { RouterCtx, RouteDepthCtx, useLocation } from '../router'\nimport { createRoutesFromChildren, matchRoutes } from '../utils'\nimport { Route } from './Route'\n\nfunction isFNode(node: any): node is FNode {\n return node && typeof node === 'object' && ('type' in node || Array.isArray(node))\n}\n\nexport function Routes(props: { children: FNodeChild }) {\n const [currentLocation, navigate] = useLocation()\n\n // Parse children to find <Route> definitions and other content\n let childrenList: any[] = Array.isArray(props.children) ? props.children : [props.children]\n\n // Separate routes from other children (like Nav components)\n const routeNodes = childrenList.filter(child => isFNode(child) && child.type === Route)\n const otherChildren = childrenList.filter(child => !isFNode(child) || child.type !== Route)\n\n // Create route definitions\n const routeDefinitions = createRoutesFromChildren(routeNodes)\n\n // DIRECT access to currentLocation.pathname\n // This should trigger reactive tracking in the component's effect context\n const currentPath = currentLocation.pathname\n const matches = matchRoutes(routeDefinitions, currentPath) || []\n const params = matches.length > 0 ? matches[matches.length - 1].params : {}\n\n const routerContext = {\n location: currentLocation,\n navigate,\n matches: matches,\n params: params\n }\n\n // Render matched component\n let matchedContent: FNodeChild = null\n\n if (matches.length > 0) {\n const rootMatch = matches[0]\n const Component = rootMatch.route.component\n\n // Use pathname as key to force re-mount on route change\n const routeKey = currentPath\n\n // Guard Check\n if (rootMatch.route.beforeEnter) {\n const result = rootMatch.route.beforeEnter(rootMatch.params)\n if (result !== false) {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n } else {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n }\n\n return f(RouterCtx.Provider, {\n value: routerContext,\n children: [...otherChildren, matchedContent]\n })\n}\n","import { use } from '../../core/use'\nimport { jsx as f } from '../../jsx-runtime'\nimport { RouteDepthCtx, useRouter } from '../router'\n\nexport function Outlet() {\n const routerContext = useRouter()\n const [depthValue] = use(RouteDepthCtx)\n const depth = depthValue ?? 0\n\n const [matches] = use(() => routerContext.matches)\n\n if (depth >= matches.length) return null\n\n const match = matches[depth]\n const Component = match.route.component\n\n // Guard\n if (match.route.beforeEnter) {\n if (match.route.beforeEnter(match.params) === false) return null\n }\n\n // Render next level\n return f(RouteDepthCtx.Provider, {\n value: depth + 1,\n children: f(Component, { params: match.params })\n })\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { LinkProps } from '../types'\nimport { useRouter } from '../router'\n\nexport function Link(props: LinkProps) {\n const routerContext = useRouter()\n return f('a', {\n href: props.to,\n class: props.class,\n onclick: (event: Event) => {\n event.preventDefault()\n routerContext.navigate(props.to)\n },\n children: props.children\n })\n}\n"]}
|
package/dist/router.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a,
|
|
1
|
+
import {a,c as c$1}from'./chunk-3AKECLKA.mjs';import'./chunk-NRPWBHKP.mjs';import {c}from'./chunk-MI76R42D.mjs';import {a as a$1}from'./chunk-NY6NOGFU.mjs';function k(t){if(!t)return {};if(typeof URLSearchParams<"u"){let e=new URLSearchParams(t),r={};return e.forEach((n,o)=>r[o]=n),r}return t.substring(1).split("&").reduce((e,r)=>{let[n,o]=r.split("=");return n&&(e[decodeURIComponent(n)]=decodeURIComponent(o||"")),e},{})}function D(t){return !!(t.length>2048||t.includes("__proto__")||t.includes("constructor")||/^\s*javascript:/i.test(t))}function R(t){let e=[];return t.forEach(r=>{if(!r)return;let{path:n,component:o,children:i,beforeEnter:f}=r.props||{},u={path:n||"/",component:o,beforeEnter:f};if(i){let c=Array.isArray(i)?i:[i];u.children=R(c);}!u.children&&r.children&&r.children.length>0&&(u.children=R(r.children)),e.push(u);}),e}function E(t,e){for(let r of t){let n=r.path,o=T(n,e);if(o)return [{route:r,params:o.params,pathname:o.path}]}return null}function T(t,e){let r=t.split("/").filter(Boolean),n=e.split("/").filter(Boolean);if(r.length!==n.length)return null;let o={};for(let i=0;i<r.length;i++){let f=r[i],u=n[i];if(f.startsWith(":")){let c=f.slice(1);o[c]=u;}else if(f!==u)return null}return {params:o,path:e}}var L=new c(null),p=new c(0),U=()=>({pathname:"/",search:"",hash:"",query:{}}),w=()=>typeof window>"u"?U():{pathname:window.location.pathname,search:window.location.search,hash:window.location.hash,query:k(window.location.search)},l=null,y=null,N=false;function d(){if(l&&y)return [l,y];l=a(w());let t=e=>{l&&(l.pathname=e.pathname,l.search=e.search,l.hash=e.hash,l.query=e.query);};return y=e=>{if(typeof window>"u")return;if(D(e)){console.error("[Flexium Router] Blocked navigation to unsafe path:",e);return}window.history.pushState({},"",e);let r=w();t(r);},typeof window<"u"&&!N&&(window.addEventListener("popstate",()=>{t(w());}),N=true),[l,y]}function m(){let[t]=c$1(L);if(!t)throw new Error("useRouter() must be called within a <Routes> component");return t}function j(){let[,t]=d();return t}function q(){return m().params}function _(){let[t]=d();return t.query}function x(t){return null}function F(t){return t&&typeof t=="object"&&("type"in t||Array.isArray(t))}function Q(t){let[e,r]=d(),n=Array.isArray(t.children)?t.children:[t.children],o=n.filter(s=>F(s)&&s.type===x),i=n.filter(s=>!F(s)||s.type!==x),f=R(o),u=e.pathname,c=E(f,u)||[],A=c.length>0?c[c.length-1].params:{},S={location:e,navigate:r,matches:c,params:A},C=null;if(c.length>0){let s=c[0],P=s.route.component,g=u;s.route.beforeEnter?s.route.beforeEnter(s.params)!==false&&(C=a$1(p.Provider,{value:1,key:g,children:a$1(P,{params:s.params,key:g})})):C=a$1(p.Provider,{value:1,key:g,children:a$1(P,{params:s.params,key:g})});}return a$1(L.Provider,{value:S,children:[...i,C]})}function B(){let t=m(),[e]=c$1(p),r=e??0,[n]=c$1(()=>t.matches);if(r>=n.length)return null;let o=n[r],i=o.route.component;return o.route.beforeEnter&&o.route.beforeEnter(o.params)===false?null:a$1(p.Provider,{value:r+1,children:a$1(i,{params:o.params})})}function M(t){let e=m();return a$1("a",{href:t.to,class:t.class,onclick:r=>{r.preventDefault(),e.navigate(t.to);},children:t.children})}export{M as Link,B as Outlet,x as Route,Q as Routes,d as useLocation,j as useNavigate,q as useParams,_ as useQuery,m as useRouter};//# sourceMappingURL=router.mjs.map
|
|
2
2
|
//# sourceMappingURL=router.mjs.map
|
package/dist/router.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/router/utils.ts","../src/router/router.ts","../src/router/dom/Route.tsx","../src/router/dom/Routes.tsx","../src/router/dom/Outlet.tsx","../src/router/dom/Link.tsx"],"names":["parseQuery","search","params","result","value","key","accumulator","part","isUnsafePath","path","createRoutesFromChildren","children","routes","child","component","subChildren","beforeEnter","route","nestedChildren","matchRoutes","locationPathname","routePath","matchResult","matchPath","locationPath","routeSegments","locationSegments","i","routeSegment","locationSegment","RouterCtx","createContext","RouteDepthCtx","getDefaultLocation","getCurrentLocation","globalLocation","globalNavigate","popstateListenerAttached","location","reactive","updateLocation","newLocation","router","routerContext","context","Route","_props","isFNode","node","Routes","props","currentLocation","navigate","childrenList","routeNodes","otherChildren","routeDefinitions","currentPath","matches","matchedContent","rootMatch","Component","routeKey","jsx","Outlet","depth","state","match","Link","event"],"mappings":"qOAGA,SAASA,CAAAA,CAAWC,EAAwC,CAC1D,GAAI,CAACA,CAAAA,CAAQ,OAAO,EAAC,CACrB,GAAI,OAAO,eAAA,CAAoB,GAAA,CAAa,CAC1C,IAAMC,CAAAA,CAAS,IAAI,eAAA,CAAgBD,CAAM,EACnCE,CAAAA,CAAiC,GACvC,OAAAD,CAAAA,CAAO,QAAQ,CAACE,CAAAA,CAAOC,IAAQF,CAAAA,CAAOE,CAAG,EAAID,CAAK,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P,CAAAA,CAAQ,OAAQ,OAAO,IAAA,CAEpC,IAAMS,CAAAA,CAAQT,CAAAA,CAAQO,CAAK,CAAA,CACrBJ,CAAAA,CAAYM,EAAM,KAAA,CAAM,SAAA,CAG9B,OAAIA,CAAAA,CAAM,KAAA,CAAM,aACRA,CAAAA,CAAM,KAAA,CAAM,YAAYA,CAAAA,CAAM,MAAM,IAAM,KAAA,CAAc,IAAA,CAIzDJ,IAAE/B,CAAAA,CAAc,QAAA,CAAU,CAC7B,KAAA,CAAOiC,CAAAA,CAAQ,EACf,QAAA,CAAUF,GAAAA,CAAEF,EAAW,CAAE,MAAA,CAAQM,EAAM,MAAO,CAAC,CACnD,CAAC,CACL,CCtBO,SAASC,CAAAA,CAAKlB,EAAkB,CACnC,IAAMP,EAAgBD,CAAAA,EAAO,CAC7B,OAAOqB,GAAAA,CAAE,GAAA,CAAK,CACV,IAAA,CAAMb,CAAAA,CAAM,GACZ,KAAA,CAAOA,CAAAA,CAAM,MACb,OAAA,CAAUmB,CAAAA,EAAiB,CACvBA,CAAAA,CAAM,cAAA,GACN1B,CAAAA,CAAc,QAAA,CAASO,EAAM,EAAE,EACnC,EACA,QAAA,CAAUA,CAAAA,CAAM,QACpB,CAAC,CACL","file":"router.mjs","sourcesContent":["import { RouteDefinition, RouteMatch } from './types'\n\n// Simple query parser (native URLSearchParams fallback) - internal use only\nfunction parseQuery(search: string): Record<string, string> {\n if (!search) return {}\n if (typeof URLSearchParams !== 'undefined') {\n const params = new URLSearchParams(search)\n const result: Record<string, string> = {}\n params.forEach((value, key) => result[key] = value)\n return result\n }\n return search\n .substring(1)\n .split('&')\n .reduce((accumulator, part) => {\n const [key, value] = part.split('=')\n if (key) accumulator[decodeURIComponent(key)] = decodeURIComponent(value || '')\n return accumulator\n }, {} as Record<string, string>)\n}\n\nfunction isUnsafePath(path: string): boolean {\n // Prevent prototype pollution or massive strings\n if (path.length > 2048) return true\n if (path.includes('__proto__') || path.includes('constructor')) return true\n // Basic XSS check for javascript: protocol\n if (/^\\s*javascript:/i.test(path)) return true\n return false\n}\n\n// Convert children FNodes to RouteDefinitions - internal use only\nfunction createRoutesFromChildren(children: any[]): RouteDefinition[] {\n const routes: RouteDefinition[] = []\n\n children.forEach(child => {\n if (!child) return\n\n // Assuming child is an FNode-like object (config)\n // In Flexium, Route component returns null, but 'createNode' isn't called here.\n // We are traversing the props passed to Router.\n\n const { path, component, children: subChildren, beforeEnter } = child.props || {}\n\n const route: RouteDefinition = {\n path: path || '/',\n component: component,\n beforeEnter\n }\n\n if (subChildren) {\n // If subChildren is array\n const nestedChildren = Array.isArray(subChildren) ? subChildren : [subChildren]\n // We expect the children of a Route to be other Routes\n // However, the 'children' prop in JSX might be the Route components themselves.\n route.children = createRoutesFromChildren(nestedChildren)\n }\n\n // Also check child.children if props.children is empty (direct FNode structure)\n if (!route.children && child.children && child.children.length > 0) {\n route.children = createRoutesFromChildren(child.children)\n }\n\n routes.push(route)\n })\n return routes\n}\n\n// Simple Matcher - internal use only\nfunction matchRoutes(routes: RouteDefinition[], locationPathname: string): RouteMatch[] | null {\n // We want to find the best matching branch\n\n for (const route of routes) {\n // 1. Match current segment\n // Simple exact match or parameter match logic needed?\n // Let's implement simple param matching: /user/:id\n\n const routePath = route.path\n\n const matchResult = matchPath(routePath, locationPathname)\n if (matchResult) {\n return [{ route, params: matchResult.params, pathname: matchResult.path }]\n }\n }\n return null\n}\n\nfunction matchPath(routePath: string, locationPath: string) {\n // 1. Split into segments\n const routeSegments = routePath.split('/').filter(Boolean)\n const locationSegments = locationPath.split('/').filter(Boolean)\n\n if (routeSegments.length !== locationSegments.length) return null\n\n const params: Record<string, string> = {}\n\n for (let i = 0; i < routeSegments.length; i++) {\n const routeSegment = routeSegments[i]\n const locationSegment = locationSegments[i]\n\n if (routeSegment.startsWith(':')) {\n const key = routeSegment.slice(1)\n params[key] = locationSegment\n } else if (routeSegment !== locationSegment) {\n return null\n }\n }\n\n return { params, path: locationPath }\n}\n\n// Export only what's needed by other router files\nexport { parseQuery, isUnsafePath, createRoutesFromChildren, matchRoutes }\n","import { reactive } from '../core/reactive'\nimport { createContext, context } from '../core/context'\nimport type { Location, RouterContext } from './types'\nimport { parseQuery, isUnsafePath } from './utils'\n\n// Contexts\nexport const RouterCtx = createContext<RouterContext>(null as any)\nexport const RouteDepthCtx = createContext<number>(0)\n\n// Helper functions\nconst getDefaultLocation = (): Location => ({\n pathname: '/',\n search: '',\n hash: '',\n query: {},\n})\n\nconst getCurrentLocation = (): Location => {\n if (typeof window === 'undefined') {\n return getDefaultLocation()\n }\n return {\n pathname: window.location.pathname,\n search: window.location.search,\n hash: window.location.hash,\n query: parseQuery(window.location.search),\n }\n}\n\n// Global singleton location state\nlet globalLocation: Location | null = null\nlet globalNavigate: ((path: string) => void) | null = null\nlet popstateListenerAttached = false\n\n// Create location state and navigation (singleton pattern)\nexport function location(): [Location, (path: string) => void] {\n // Return existing singleton if already created\n if (globalLocation && globalNavigate) {\n return [globalLocation, globalNavigate]\n }\n\n // Create a reactive location object (only once)\n globalLocation = reactive<Location>(getCurrentLocation())\n\n const updateLocation = (newLocation: Location) => {\n if (!globalLocation) return\n globalLocation.pathname = newLocation.pathname\n globalLocation.search = newLocation.search\n globalLocation.hash = newLocation.hash\n globalLocation.query = newLocation.query\n }\n\n globalNavigate = (path: string) => {\n if (typeof window === 'undefined') return\n if (isUnsafePath(path)) {\n console.error('[Flexium Router] Blocked navigation to unsafe path:', path)\n return\n }\n window.history.pushState({}, '', path)\n const newLocation = getCurrentLocation()\n updateLocation(newLocation)\n }\n\n // Listen to popstate (only once)\n if (typeof window !== 'undefined' && !popstateListenerAttached) {\n window.addEventListener('popstate', () => {\n updateLocation(getCurrentLocation())\n })\n popstateListenerAttached = true\n }\n\n return [globalLocation, globalNavigate]\n}\n\n// Router hook\nexport function router(): RouterContext {\n const routerContext = context(RouterCtx)\n if (!routerContext) {\n throw new Error('router() must be called within a <Routes> component')\n }\n return routerContext\n}\n","import type { RouteProps } from '../types'\n\nexport function Route(_props: RouteProps) {\n return null\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { FNode, FNodeChild } from '../../dom'\nimport { RouterCtx, RouteDepthCtx, location } from '../router'\nimport { createRoutesFromChildren, matchRoutes } from '../utils'\nimport { Route } from './Route'\n\nfunction isFNode(node: any): node is FNode {\n return node && typeof node === 'object' && ('type' in node || Array.isArray(node))\n}\n\nexport function Routes(props: { children: FNodeChild }) {\n const [currentLocation, navigate] = location()\n\n // Parse children to find <Route> definitions and other content\n let childrenList: any[] = Array.isArray(props.children) ? props.children : [props.children]\n\n // Separate routes from other children (like Nav components)\n const routeNodes = childrenList.filter(child => isFNode(child) && child.type === Route)\n const otherChildren = childrenList.filter(child => !isFNode(child) || child.type !== Route)\n\n // Create route definitions\n const routeDefinitions = createRoutesFromChildren(routeNodes)\n\n // DIRECT access to currentLocation.pathname\n // This should trigger reactive tracking in the component's effect context\n const currentPath = currentLocation.pathname\n const matches = matchRoutes(routeDefinitions, currentPath) || []\n const params = matches.length > 0 ? matches[matches.length - 1].params : {}\n\n const routerContext = {\n location: currentLocation,\n navigate,\n matches: matches,\n params: params\n }\n\n // Render matched component\n let matchedContent: FNodeChild = null\n\n if (matches.length > 0) {\n const rootMatch = matches[0]\n const Component = rootMatch.route.component\n\n // Use pathname as key to force re-mount on route change\n const routeKey = currentPath\n\n // Guard Check\n if (rootMatch.route.beforeEnter) {\n const result = rootMatch.route.beforeEnter(rootMatch.params)\n if (result !== false) {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n } else {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n }\n\n return f(RouterCtx.Provider, {\n value: routerContext,\n children: [...otherChildren, matchedContent]\n })\n}\n","import { state } from '../../core/state'\nimport { context } from '../../core/context'\nimport { jsx as f } from '../../jsx-runtime'\nimport { RouteDepthCtx, router } from '../router'\n\nexport function Outlet() {\n const routerContext = router()\n const depth = (context(RouteDepthCtx) as number) || 0\n\n const [matches] = state(() => routerContext.matches)\n\n if (depth >= matches.length) return null\n\n const match = matches[depth]\n const Component = match.route.component\n\n // Guard\n if (match.route.beforeEnter) {\n if (match.route.beforeEnter(match.params) === false) return null\n }\n\n // Render next level\n return f(RouteDepthCtx.Provider, {\n value: depth + 1,\n children: f(Component, { params: match.params })\n })\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { LinkProps } from '../types'\nimport { router } from '../router'\n\nexport function Link(props: LinkProps) {\n const routerContext = router()\n return f('a', {\n href: props.to,\n class: props.class,\n onclick: (event: Event) => {\n event.preventDefault()\n routerContext.navigate(props.to)\n },\n children: props.children\n })\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/router/utils.ts","../src/router/router.ts","../src/router/dom/Route.tsx","../src/router/dom/Routes.tsx","../src/router/dom/Outlet.tsx","../src/router/dom/Link.tsx"],"names":["parseQuery","search","params","result","value","key","accumulator","part","isUnsafePath","path","createRoutesFromChildren","children","routes","child","component","subChildren","beforeEnter","route","nestedChildren","matchRoutes","locationPathname","routePath","matchResult","matchPath","locationPath","routeSegments","locationSegments","routeSegment","locationSegment","RouterCtx","Context","RouteDepthCtx","getDefaultLocation","getCurrentLocation","globalLocation","globalNavigate","popstateListenerAttached","useLocation","reactive","updateLocation","newLocation","useRouter","routerContext","use","useNavigate","navigate","useParams","useQuery","location","Route","_props","isFNode","node","Routes","props","currentLocation","childrenList","routeNodes","otherChildren","routeDefinitions","currentPath","matches","matchedContent","rootMatch","Component","routeKey","jsx","Outlet","depthValue","depth","match","Link","event"],"mappings":"4JAGA,SAASA,CAAAA,CAAWC,EAAwC,CAC1D,GAAI,CAACA,CAAAA,CAAQ,OAAO,EAAC,CACrB,GAAI,OAAO,eAAA,CAAoB,GAAA,CAAa,CAC1C,IAAMC,CAAAA,CAAS,IAAI,eAAA,CAAgBD,CAAM,CAAA,CACnCE,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AAM,EAAA,CACZ,KAAA,CAAOA,EAAM,KAAA,CACb,OAAA,CAAUkB,CAAAA,EAAiB,CACvBA,CAAAA,CAAM,cAAA,GACN9B,CAAAA,CAAc,QAAA,CAASY,EAAM,EAAE,EACnC,EACA,QAAA,CAAUA,CAAAA,CAAM,QACpB,CAAC,CACL","file":"router.mjs","sourcesContent":["import { RouteDefinition, RouteMatch } from './types'\n\n// Simple query parser (native URLSearchParams fallback) - internal use only\nfunction parseQuery(search: string): Record<string, string> {\n if (!search) return {}\n if (typeof URLSearchParams !== 'undefined') {\n const params = new URLSearchParams(search)\n const result: Record<string, string> = {}\n params.forEach((value, key) => result[key] = value)\n return result\n }\n return search\n .substring(1)\n .split('&')\n .reduce((accumulator, part) => {\n const [key, value] = part.split('=')\n if (key) accumulator[decodeURIComponent(key)] = decodeURIComponent(value || '')\n return accumulator\n }, {} as Record<string, string>)\n}\n\nfunction isUnsafePath(path: string): boolean {\n // Prevent prototype pollution or massive strings\n if (path.length > 2048) return true\n if (path.includes('__proto__') || path.includes('constructor')) return true\n // Basic XSS check for javascript: protocol\n if (/^\\s*javascript:/i.test(path)) return true\n return false\n}\n\n// Convert children FNodes to RouteDefinitions - internal use only\nfunction createRoutesFromChildren(children: any[]): RouteDefinition[] {\n const routes: RouteDefinition[] = []\n\n children.forEach(child => {\n if (!child) return\n\n // Assuming child is an FNode-like object (config)\n // In Flexium, Route component returns null, but 'createNode' isn't called here.\n // We are traversing the props passed to Router.\n\n const { path, component, children: subChildren, beforeEnter } = child.props || {}\n\n const route: RouteDefinition = {\n path: path || '/',\n component: component,\n beforeEnter\n }\n\n if (subChildren) {\n // If subChildren is array\n const nestedChildren = Array.isArray(subChildren) ? subChildren : [subChildren]\n // We expect the children of a Route to be other Routes\n // However, the 'children' prop in JSX might be the Route components themselves.\n route.children = createRoutesFromChildren(nestedChildren)\n }\n\n // Also check child.children if props.children is empty (direct FNode structure)\n if (!route.children && child.children && child.children.length > 0) {\n route.children = createRoutesFromChildren(child.children)\n }\n\n routes.push(route)\n })\n return routes\n}\n\n// Simple Matcher - internal use only\nfunction matchRoutes(routes: RouteDefinition[], locationPathname: string): RouteMatch[] | null {\n // We want to find the best matching branch\n\n for (const route of routes) {\n // 1. Match current segment\n // Simple exact match or parameter match logic needed?\n // Let's implement simple param matching: /user/:id\n\n const routePath = route.path\n\n const matchResult = matchPath(routePath, locationPathname)\n if (matchResult) {\n return [{ route, params: matchResult.params, pathname: matchResult.path }]\n }\n }\n return null\n}\n\nfunction matchPath(routePath: string, locationPath: string) {\n // 1. Split into segments\n const routeSegments = routePath.split('/').filter(Boolean)\n const locationSegments = locationPath.split('/').filter(Boolean)\n\n if (routeSegments.length !== locationSegments.length) return null\n\n const params: Record<string, string> = {}\n\n for (let i = 0; i < routeSegments.length; i++) {\n const routeSegment = routeSegments[i]\n const locationSegment = locationSegments[i]\n\n if (routeSegment.startsWith(':')) {\n const key = routeSegment.slice(1)\n params[key] = locationSegment\n } else if (routeSegment !== locationSegment) {\n return null\n }\n }\n\n return { params, path: locationPath }\n}\n\n// Export only what's needed by other router files\nexport { parseQuery, isUnsafePath, createRoutesFromChildren, matchRoutes }\n","import { reactive } from '../core/reactive'\nimport { Context } from '../core/context'\nimport { use } from '../core/use'\nimport type { Location, RouterContext } from './types'\nimport { parseQuery, isUnsafePath } from './utils'\n\n// Contexts\nexport const RouterCtx = new Context<RouterContext>(null as any)\nexport const RouteDepthCtx = new Context<number>(0)\n\n// Helper functions\nconst getDefaultLocation = (): Location => ({\n pathname: '/',\n search: '',\n hash: '',\n query: {},\n})\n\nconst getCurrentLocation = (): Location => {\n if (typeof window === 'undefined') {\n return getDefaultLocation()\n }\n return {\n pathname: window.location.pathname,\n search: window.location.search,\n hash: window.location.hash,\n query: parseQuery(window.location.search),\n }\n}\n\n// Global singleton location state\nlet globalLocation: Location | null = null\nlet globalNavigate: ((path: string) => void) | null = null\nlet popstateListenerAttached = false\n\n// Create location state and navigation (singleton pattern)\nexport function useLocation(): [Location, (path: string) => void] {\n // Return existing singleton if already created\n if (globalLocation && globalNavigate) {\n return [globalLocation, globalNavigate]\n }\n\n // Create a reactive location object (only once)\n globalLocation = reactive<Location>(getCurrentLocation())\n\n const updateLocation = (newLocation: Location) => {\n if (!globalLocation) return\n globalLocation.pathname = newLocation.pathname\n globalLocation.search = newLocation.search\n globalLocation.hash = newLocation.hash\n globalLocation.query = newLocation.query\n }\n\n globalNavigate = (path: string) => {\n if (typeof window === 'undefined') return\n if (isUnsafePath(path)) {\n console.error('[Flexium Router] Blocked navigation to unsafe path:', path)\n return\n }\n window.history.pushState({}, '', path)\n const newLocation = getCurrentLocation()\n updateLocation(newLocation)\n }\n\n // Listen to popstate (only once)\n if (typeof window !== 'undefined' && !popstateListenerAttached) {\n window.addEventListener('popstate', () => {\n updateLocation(getCurrentLocation())\n })\n popstateListenerAttached = true\n }\n\n return [globalLocation, globalNavigate]\n}\n\n// Router hook - returns full router context\nexport function useRouter(): RouterContext {\n const [routerContext] = use(RouterCtx)\n if (!routerContext) {\n throw new Error('useRouter() must be called within a <Routes> component')\n }\n return routerContext\n}\n\n// Navigate hook - returns navigate function\nexport function useNavigate(): (path: string) => void {\n const [, navigate] = useLocation()\n return navigate\n}\n\n// Params hook - returns route params\nexport function useParams<T extends Record<string, string> = Record<string, string>>(): T {\n const router = useRouter()\n return router.params as T\n}\n\n// Query hook - returns query params\nexport function useQuery<T extends Record<string, string> = Record<string, string>>(): T {\n const [location] = useLocation()\n return location.query as T\n}\n","import type { RouteProps } from '../types'\n\nexport function Route(_props: RouteProps) {\n return null\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { FNode, FNodeChild } from '../../dom'\nimport { RouterCtx, RouteDepthCtx, useLocation } from '../router'\nimport { createRoutesFromChildren, matchRoutes } from '../utils'\nimport { Route } from './Route'\n\nfunction isFNode(node: any): node is FNode {\n return node && typeof node === 'object' && ('type' in node || Array.isArray(node))\n}\n\nexport function Routes(props: { children: FNodeChild }) {\n const [currentLocation, navigate] = useLocation()\n\n // Parse children to find <Route> definitions and other content\n let childrenList: any[] = Array.isArray(props.children) ? props.children : [props.children]\n\n // Separate routes from other children (like Nav components)\n const routeNodes = childrenList.filter(child => isFNode(child) && child.type === Route)\n const otherChildren = childrenList.filter(child => !isFNode(child) || child.type !== Route)\n\n // Create route definitions\n const routeDefinitions = createRoutesFromChildren(routeNodes)\n\n // DIRECT access to currentLocation.pathname\n // This should trigger reactive tracking in the component's effect context\n const currentPath = currentLocation.pathname\n const matches = matchRoutes(routeDefinitions, currentPath) || []\n const params = matches.length > 0 ? matches[matches.length - 1].params : {}\n\n const routerContext = {\n location: currentLocation,\n navigate,\n matches: matches,\n params: params\n }\n\n // Render matched component\n let matchedContent: FNodeChild = null\n\n if (matches.length > 0) {\n const rootMatch = matches[0]\n const Component = rootMatch.route.component\n\n // Use pathname as key to force re-mount on route change\n const routeKey = currentPath\n\n // Guard Check\n if (rootMatch.route.beforeEnter) {\n const result = rootMatch.route.beforeEnter(rootMatch.params)\n if (result !== false) {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n } else {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n }\n\n return f(RouterCtx.Provider, {\n value: routerContext,\n children: [...otherChildren, matchedContent]\n })\n}\n","import { use } from '../../core/use'\nimport { jsx as f } from '../../jsx-runtime'\nimport { RouteDepthCtx, useRouter } from '../router'\n\nexport function Outlet() {\n const routerContext = useRouter()\n const [depthValue] = use(RouteDepthCtx)\n const depth = depthValue ?? 0\n\n const [matches] = use(() => routerContext.matches)\n\n if (depth >= matches.length) return null\n\n const match = matches[depth]\n const Component = match.route.component\n\n // Guard\n if (match.route.beforeEnter) {\n if (match.route.beforeEnter(match.params) === false) return null\n }\n\n // Render next level\n return f(RouteDepthCtx.Provider, {\n value: depth + 1,\n children: f(Component, { params: match.params })\n })\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { LinkProps } from '../types'\nimport { useRouter } from '../router'\n\nexport function Link(props: LinkProps) {\n const routerContext = useRouter()\n return f('a', {\n href: props.to,\n class: props.class,\n onclick: (event: Event) => {\n event.preventDefault()\n routerContext.navigate(props.to)\n },\n children: props.children\n })\n}\n"]}
|
package/dist/server.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as SSROptions, b as SSRResult } from './types-CxlS2F2j.cjs';
|
|
2
2
|
export { S as SerializedState } from './types-CxlS2F2j.cjs';
|
|
3
|
-
import {
|
|
3
|
+
import { a as FNodeChild } from './types-DH8L3A5z.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Render component tree to HTML string with hydration markers
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as SSROptions, b as SSRResult } from './types-CxlS2F2j.js';
|
|
2
2
|
export { S as SerializedState } from './types-CxlS2F2j.js';
|
|
3
|
-
import {
|
|
3
|
+
import { a as FNodeChild } from './types-DH8L3A5z.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Render component tree to HTML string with hydration markers
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkE6Z7AI4J_js=require('./chunk-E6Z7AI4J.js');var $={"&":"&","<":"<",">":">",'"':""","'":"'"},F=/[&<>"']/g;function l(e){return String(e).replace(F,r=>$[r])}function a(e){return l(e)}var f=false,d=null,h=0;function I(){return f}function b(){f=true,d=new Map,h=0;}function S(){f=false;let e=Object.fromEntries(d||new Map);return d=null,{states:e}}function x(){return `fid-${h++}`}var T=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),v=new Set(["disabled","checked","readonly","required","hidden","selected","autofocus","autoplay","controls","loop","muted","multiple","open","defer","async","novalidate"]),A={className:"class",htmlFor:"for"};function R(e,r={}){let{hydrate:n=true}=r;b();try{let t;typeof e=="function"&&!N(e)?t={type:e,props:{},children:[],key:void 0}:t=e;let o=p(t,n),i=S();return {html:o,state:i}}catch(t){throw S(),t}}function E(e){let{html:r}=R(e,{hydrate:false});return r}function N(e){return e&&typeof e=="object"&&"type"in e&&"props"in e}function p(e,r){if(e==null||typeof e=="boolean")return "";if(typeof e=="string"||typeof e=="number")return l(String(e));if(Array.isArray(e))return e.map(n=>p(n,r)).join("");if(typeof e=="function")return C({type:e,props:{},children:[]},r);if(typeof e=="object"&&N(e)){if(typeof e.type=="string")return w(e,r);if(typeof e.type=="function")return C(e,r)}return ""}function w(e,r){let n=e.type,t=j(e.props,r);if(e.props?.dangerouslySetInnerHTML){let i=e.props.dangerouslySetInnerHTML.__html||"";return `<${n}${t}>${i}</${n}>`}if(T.has(n))return `<${n}${t}>`;let o=(e.children||[]).map(i=>p(i,r)).join("");return `<${n}${t}>${o}</${n}>`}function j(e,r){if(!e)return "";let n=[];if(r){let t=x();n.push(`data-fid="${t}"`);}for(let[t,o]of Object.entries(e)){if(t.startsWith("on")||t==="ref"||t==="key"||t==="children"||t==="dangerouslySetInnerHTML"||o==null)continue;let i=A[t]||t;if(t==="style"&&typeof o=="object"){let c=Object.entries(o).filter(([,s])=>s!=null).map(([s,u])=>`${k(s)}:${u}`).join(";");c&&n.push(`style="${a(c)}"`);continue}if(v.has(i)){o&&n.push(i);continue}o!==false&&n.push(`${i}="${a(String(o))}"`);}return n.length?" "+n.join(" "):""}function C(e,r){let n=e.type,t={...e.props};e.children&&e.children.length>0&&(t.children=e.children.length===1?e.children[0]:e.children);let o=n._contextId,i=o!==void 0,c;i&&(c=chunkE6Z7AI4J_js.e(o,t.value));let s={hooks:[],hookIndex:0};try{let u=chunkE6Z7AI4J_js.a(s,()=>n(t));return p(u,r)}finally{i&&chunkE6Z7AI4J_js.f(o,c);}}function k(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}exports.getIsServer=I;exports.renderToStaticMarkup=E;exports.renderToString=R;//# sourceMappingURL=server.js.map
|
|
2
2
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/escape.ts","../src/server/serverState.ts","../src/server/renderToString.ts"],"names":["ESCAPE_MAP","ESCAPE_REGEX","escapeHtml","str","char","escapeAttribute","isServerRendering","serverStateCollector","hydrationIdCounter","getIsServer","enterServerRender","exitServerRender","states","generateHydrationId","VOID_ELEMENTS","BOOLEAN_ATTRS","ATTR_ALIASES","renderToString","app","options","hydrate","fnode","isFNode","html","renderNodeToString","state","error","renderToStaticMarkup","value","includeHydrationMarkers","child","renderComponentToString","renderElementToString","tag","attrs","renderAttributes","innerHTML","childrenHtml","props","parts","fid","key","attrName","styleStr","v","k","kebabCase","Component","contextId","isProvider","prevContextValue","pushContext","instance","result","runWithComponent","popContext"],"mappings":"iHAAA,IAAMA,EAAqC,CACzC,GAAA,CAAK,OAAA,CACL,GAAA,CAAK,OACL,GAAA,CAAK,MAAA,CACL,GAAA,CAAK,QAAA,CACL,IAAK,QACP,CAAA,CAEMC,CAAAA,CAAe,UAAA,CAEd,SAASC,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAO,OAAOA,CAAG,CAAA,CAAE,OAAA,CAAQF,CAAAA,CAAcG,GAAQJ,CAAAA,CAAWI,CAAI,CAAC,CACnE,CAEO,SAASC,CAAAA,CAAgBF,EAAqB,CACnD,OAAOD,EAAWC,CAAG,CACvB,CCdA,IAAIG,EAAoB,KAAA,CACpBC,CAAAA,CAAoD,IAAA,CACpDC,CAAAA,CAAqB,EAElB,SAASC,CAAAA,EAAuB,CACrC,OAAOH,CACT,CAEO,SAASI,CAAAA,EAA0B,CACxCJ,EAAoB,IAAA,CACpBC,CAAAA,CAAuB,IAAI,GAAA,CAC3BC,EAAqB,EACvB,CAEO,SAASG,CAAAA,EAAoC,CAClDL,CAAAA,CAAoB,KAAA,CACpB,IAAMM,CAAAA,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,CAAM,QAAA,EAAYA,CAAAA,CAAM,QAAA,CAAS,OAAS,CAAA,GAC5CiB,CAAAA,CAAM,QAAA,CAAWjB,CAAAA,CAAM,SAAS,MAAA,GAAW,CAAA,CACvCA,CAAAA,CAAM,QAAA,CAAS,CAAC,CAAA,CAChBA,CAAAA,CAAM,QAAA,CAAA,CAIZ,IAAM2B,EAAaD,CAAAA,CAAkB,UAAA,CAC/BE,CAAAA,CAAaD,CAAAA,GAAc,OAC7BE,CAAAA,CAEAD,CAAAA,GACFC,CAAAA,CAAmBC,kBAAAA,CAAYH,EAAWV,CAAAA,CAAM,KAAK,GAIvD,IAAMc,CAAAA,CAA8B,CAClC,KAAA,CAAO,EAAC,CACR,SAAA,CAAW,CACb,CAAA,CAEA,GAAI,CAEF,IAAMC,EAASC,kBAAAA,CAAiBF,CAAAA,CAAU,IAAML,CAAAA,CAAUT,CAAK,CAAC,CAAA,CAGhE,OAAOd,CAAAA,CAAmB6B,CAAAA,CAAQxB,CAAuB,CAC3D,CAAA,OAAE,CAEIoB,CAAAA,EACFM,mBAAWP,CAAAA,CAAWE,CAAgB,EAE1C,CACF,CAEA,SAASJ,CAAAA,CAAU3C,CAAAA,CAAqB,CACtC,OAAOA,CAAAA,CAAI,OAAA,CAAQ,WAAY,KAAK,CAAA,CAAE,aACxC","file":"server.js","sourcesContent":["const ESCAPE_MAP: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": '''\n}\n\nconst ESCAPE_REGEX = /[&<>\"']/g\n\nexport function escapeHtml(str: string): string {\n return String(str).replace(ESCAPE_REGEX, char => ESCAPE_MAP[char])\n}\n\nexport function escapeAttribute(str: string): string {\n return escapeHtml(str)\n}\n","import type { SerializedState } from './types'\n\nlet isServerRendering = false\nlet serverStateCollector: Map<string, unknown> | null = null\nlet hydrationIdCounter = 0\n\nexport function getIsServer(): boolean {\n return isServerRendering\n}\n\nexport function enterServerRender(): void {\n isServerRendering = true\n serverStateCollector = new Map()\n hydrationIdCounter = 0\n}\n\nexport function exitServerRender(): SerializedState {\n isServerRendering = false\n const states = Object.fromEntries(serverStateCollector || new Map())\n serverStateCollector = null\n\n return { states }\n}\n\nexport function collectServerState(key: string, value: unknown): void {\n if (serverStateCollector) {\n serverStateCollector.set(key, value)\n }\n}\n\nexport function generateHydrationId(): string {\n return `fid-${hydrationIdCounter++}`\n}\n\nexport function resetHydrationIdCounter(): void {\n hydrationIdCounter = 0\n}\n","import type { FNode, FNodeChild } from '../dom/types'\nimport type { SSROptions, SSRResult } from './types'\nimport { escapeHtml, escapeAttribute } from './escape'\nimport {\n enterServerRender,\n exitServerRender,\n generateHydrationId\n} from './serverState'\nimport { runWithComponent, ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\n\n// Self-closing HTML tags\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// Attributes that should be rendered as boolean\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'checked', 'readonly', 'required', 'hidden',\n 'selected', 'autofocus', 'autoplay', 'controls', 'loop', 'muted',\n 'multiple', 'open', 'defer', 'async', 'novalidate'\n])\n\n// Attributes that need special handling\nconst ATTR_ALIASES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for'\n}\n\n/**\n * Render component tree to HTML string with hydration markers\n */\nexport function renderToString(\n app: FNodeChild | (() => FNodeChild),\n options: SSROptions = {}\n): SSRResult {\n const { hydrate = true } = options\n\n enterServerRender()\n\n try {\n // Normalize input - wrap function in FNode if needed\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n const html = renderNodeToString(fnode, hydrate)\n const state = exitServerRender()\n\n return { html, state }\n } catch (error) {\n exitServerRender()\n throw error\n }\n}\n\n/**\n * Render component tree to static HTML (no hydration markers)\n * Use for email templates, static pages, etc.\n */\nexport function renderToStaticMarkup(app: FNodeChild | (() => FNodeChild)): string {\n const { html } = renderToString(app, { hydrate: false })\n return html\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction renderNodeToString(fnode: FNodeChild, includeHydrationMarkers: boolean): string {\n // Null/undefined/boolean -> empty string\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n return ''\n }\n\n // String/number -> escaped text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return escapeHtml(String(fnode))\n }\n\n // Array -> concatenate children\n if (Array.isArray(fnode)) {\n return fnode.map(child => renderNodeToString(child, includeHydrationMarkers)).join('')\n }\n\n // Function (standalone) -> wrap in FNode and render\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return renderComponentToString(wrappedFnode, includeHydrationMarkers)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n // HTML element\n if (typeof fnode.type === 'string') {\n return renderElementToString(fnode, includeHydrationMarkers)\n }\n\n // Function component\n if (typeof fnode.type === 'function') {\n return renderComponentToString(fnode, includeHydrationMarkers)\n }\n }\n\n return ''\n}\n\nfunction renderElementToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const tag = fnode.type as string\n const attrs = renderAttributes(fnode.props, includeHydrationMarkers)\n\n // Handle dangerouslySetInnerHTML\n if (fnode.props?.dangerouslySetInnerHTML) {\n const innerHTML = fnode.props.dangerouslySetInnerHTML.__html || ''\n return `<${tag}${attrs}>${innerHTML}</${tag}>`\n }\n\n // Void elements (self-closing)\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`\n }\n\n // Render children\n const childrenHtml = (fnode.children || [])\n .map(child => renderNodeToString(child, includeHydrationMarkers))\n .join('')\n\n return `<${tag}${attrs}>${childrenHtml}</${tag}>`\n}\n\nfunction renderAttributes(props: Record<string, any>, includeHydrationMarkers: boolean): string {\n if (!props) return ''\n\n const parts: string[] = []\n\n // Add hydration ID if needed\n if (includeHydrationMarkers) {\n const fid = generateHydrationId()\n parts.push(`data-fid=\"${fid}\"`)\n }\n\n for (const [key, value] of Object.entries(props)) {\n // Skip event handlers, refs, and internal props\n if (key.startsWith('on') || key === 'ref' || key === 'key' || key === 'children') continue\n if (key === 'dangerouslySetInnerHTML') continue\n\n // Skip undefined/null values\n if (value === undefined || value === null) continue\n\n // Handle aliased attributes\n const attrName = ATTR_ALIASES[key] || key\n\n // Handle style object\n if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .filter(([, v]) => v !== null && v !== undefined)\n .map(([k, v]) => `${kebabCase(k)}:${v}`)\n .join(';')\n if (styleStr) {\n parts.push(`style=\"${escapeAttribute(styleStr)}\"`)\n }\n continue\n }\n\n // Handle boolean attributes\n if (BOOLEAN_ATTRS.has(attrName)) {\n if (value) parts.push(attrName)\n continue\n }\n\n // Handle false boolean values - skip entirely\n if (value === false) continue\n\n // Regular attribute\n parts.push(`${attrName}=\"${escapeAttribute(String(value))}\"`)\n }\n\n return parts.length ? ' ' + parts.join(' ') : ''\n}\n\nfunction renderComponentToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const Component = fnode.type as Function\n\n // Merge props with children\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Check if this is a Context Provider\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Create minimal component instance for server (hooks support)\n const instance: ComponentInstance = {\n hooks: [],\n hookIndex: 0\n }\n\n try {\n // Run component with hook context\n const result = runWithComponent(instance, () => Component(props))\n\n // Render result\n return renderNodeToString(result, includeHydrationMarkers)\n } finally {\n // Restore context if it was a provider\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n\nfunction kebabCase(str: string): string {\n return str.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/server/escape.ts","../src/server/serverState.ts","../src/server/renderToString.ts"],"names":["ESCAPE_MAP","ESCAPE_REGEX","escapeHtml","str","char","escapeAttribute","isServerRendering","serverStateCollector","hydrationIdCounter","getIsServer","enterServerRender","exitServerRender","states","generateHydrationId","VOID_ELEMENTS","BOOLEAN_ATTRS","ATTR_ALIASES","renderToString","app","options","hydrate","fnode","isFNode","html","renderNodeToString","state","error","renderToStaticMarkup","value","includeHydrationMarkers","child","renderComponentToString","renderElementToString","tag","attrs","renderAttributes","innerHTML","childrenHtml","props","parts","fid","key","attrName","styleStr","v","k","kebabCase","Component","contextId","isProvider","prevContextValue","pushContext","instance","result","runWithComponent","popContext"],"mappings":"iEAAA,IAAMA,EAAqC,CACzC,GAAA,CAAK,OAAA,CACL,GAAA,CAAK,OACL,GAAA,CAAK,MAAA,CACL,GAAA,CAAK,QAAA,CACL,IAAK,QACP,CAAA,CAEMC,CAAAA,CAAe,UAAA,CAEd,SAASC,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAO,OAAOA,CAAG,CAAA,CAAE,OAAA,CAAQF,CAAAA,CAAcG,GAAQJ,CAAAA,CAAWI,CAAI,CAAC,CACnE,CAEO,SAASC,CAAAA,CAAgBF,EAAqB,CACnD,OAAOD,EAAWC,CAAG,CACvB,CCdA,IAAIG,EAAoB,KAAA,CACpBC,CAAAA,CAAoD,IAAA,CACpDC,CAAAA,CAAqB,EAElB,SAASC,CAAAA,EAAuB,CACrC,OAAOH,CACT,CAEO,SAASI,CAAAA,EAA0B,CACxCJ,EAAoB,IAAA,CACpBC,CAAAA,CAAuB,IAAI,GAAA,CAC3BC,EAAqB,EACvB,CAEO,SAASG,CAAAA,EAAoC,CAClDL,CAAAA,CAAoB,KAAA,CACpB,IAAMM,CAAAA,CAAS,OAAO,WAAA,CAAYL,CAAAA,EAAwB,IAAI,GAAK,CAAA,CACnE,OAAA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AAAA,CAAM,QAAA,CAAWjB,CAAAA,CAAM,SAAS,MAAA,GAAW,CAAA,CACvCA,CAAAA,CAAM,QAAA,CAAS,CAAC,CAAA,CAChBA,CAAAA,CAAM,QAAA,CAAA,CAIZ,IAAM2B,EAAaD,CAAAA,CAAkB,UAAA,CAC/BE,CAAAA,CAAaD,CAAAA,GAAc,OAC7BE,CAAAA,CAEAD,CAAAA,GACFC,CAAAA,CAAmBC,kBAAAA,CAAYH,EAAWV,CAAAA,CAAM,KAAK,GAIvD,IAAMc,CAAAA,CAA8B,CAClC,KAAA,CAAO,EAAC,CACR,SAAA,CAAW,CACb,CAAA,CAEA,GAAI,CAEF,IAAMC,EAASC,kBAAAA,CAAiBF,CAAAA,CAAU,IAAML,CAAAA,CAAUT,CAAK,CAAC,CAAA,CAGhE,OAAOd,CAAAA,CAAmB6B,CAAAA,CAAQxB,CAAuB,CAC3D,CAAA,OAAE,CAEIoB,CAAAA,EACFM,mBAAWP,CAAAA,CAAWE,CAAgB,EAE1C,CACF,CAEA,SAASJ,CAAAA,CAAU3C,CAAAA,CAAqB,CACtC,OAAOA,CAAAA,CAAI,OAAA,CAAQ,WAAY,KAAK,CAAA,CAAE,aACxC","file":"server.js","sourcesContent":["const ESCAPE_MAP: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": '''\n}\n\nconst ESCAPE_REGEX = /[&<>\"']/g\n\nexport function escapeHtml(str: string): string {\n return String(str).replace(ESCAPE_REGEX, char => ESCAPE_MAP[char])\n}\n\nexport function escapeAttribute(str: string): string {\n return escapeHtml(str)\n}\n","import type { SerializedState } from './types'\n\nlet isServerRendering = false\nlet serverStateCollector: Map<string, unknown> | null = null\nlet hydrationIdCounter = 0\n\nexport function getIsServer(): boolean {\n return isServerRendering\n}\n\nexport function enterServerRender(): void {\n isServerRendering = true\n serverStateCollector = new Map()\n hydrationIdCounter = 0\n}\n\nexport function exitServerRender(): SerializedState {\n isServerRendering = false\n const states = Object.fromEntries(serverStateCollector || new Map())\n serverStateCollector = null\n\n return { states }\n}\n\nexport function collectServerState(key: string, value: unknown): void {\n if (serverStateCollector) {\n serverStateCollector.set(key, value)\n }\n}\n\nexport function generateHydrationId(): string {\n return `fid-${hydrationIdCounter++}`\n}\n\nexport function resetHydrationIdCounter(): void {\n hydrationIdCounter = 0\n}\n","import type { FNode, FNodeChild } from '../dom/types'\nimport type { SSROptions, SSRResult } from './types'\nimport { escapeHtml, escapeAttribute } from './escape'\nimport {\n enterServerRender,\n exitServerRender,\n generateHydrationId\n} from './serverState'\nimport { runWithComponent, ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\n\n// Self-closing HTML tags\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// Attributes that should be rendered as boolean\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'checked', 'readonly', 'required', 'hidden',\n 'selected', 'autofocus', 'autoplay', 'controls', 'loop', 'muted',\n 'multiple', 'open', 'defer', 'async', 'novalidate'\n])\n\n// Attributes that need special handling\nconst ATTR_ALIASES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for'\n}\n\n/**\n * Render component tree to HTML string with hydration markers\n */\nexport function renderToString(\n app: FNodeChild | (() => FNodeChild),\n options: SSROptions = {}\n): SSRResult {\n const { hydrate = true } = options\n\n enterServerRender()\n\n try {\n // Normalize input - wrap function in FNode if needed\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n const html = renderNodeToString(fnode, hydrate)\n const state = exitServerRender()\n\n return { html, state }\n } catch (error) {\n exitServerRender()\n throw error\n }\n}\n\n/**\n * Render component tree to static HTML (no hydration markers)\n * Use for email templates, static pages, etc.\n */\nexport function renderToStaticMarkup(app: FNodeChild | (() => FNodeChild)): string {\n const { html } = renderToString(app, { hydrate: false })\n return html\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction renderNodeToString(fnode: FNodeChild, includeHydrationMarkers: boolean): string {\n // Null/undefined/boolean -> empty string\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n return ''\n }\n\n // String/number -> escaped text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return escapeHtml(String(fnode))\n }\n\n // Array -> concatenate children\n if (Array.isArray(fnode)) {\n return fnode.map(child => renderNodeToString(child, includeHydrationMarkers)).join('')\n }\n\n // Function (standalone) -> wrap in FNode and render\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return renderComponentToString(wrappedFnode, includeHydrationMarkers)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n // HTML element\n if (typeof fnode.type === 'string') {\n return renderElementToString(fnode, includeHydrationMarkers)\n }\n\n // Function component\n if (typeof fnode.type === 'function') {\n return renderComponentToString(fnode, includeHydrationMarkers)\n }\n }\n\n return ''\n}\n\nfunction renderElementToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const tag = fnode.type as string\n const attrs = renderAttributes(fnode.props, includeHydrationMarkers)\n\n // Handle dangerouslySetInnerHTML\n if (fnode.props?.dangerouslySetInnerHTML) {\n const innerHTML = fnode.props.dangerouslySetInnerHTML.__html || ''\n return `<${tag}${attrs}>${innerHTML}</${tag}>`\n }\n\n // Void elements (self-closing)\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`\n }\n\n // Render children\n const childrenHtml = (fnode.children || [])\n .map(child => renderNodeToString(child, includeHydrationMarkers))\n .join('')\n\n return `<${tag}${attrs}>${childrenHtml}</${tag}>`\n}\n\nfunction renderAttributes(props: Record<string, any>, includeHydrationMarkers: boolean): string {\n if (!props) return ''\n\n const parts: string[] = []\n\n // Add hydration ID if needed\n if (includeHydrationMarkers) {\n const fid = generateHydrationId()\n parts.push(`data-fid=\"${fid}\"`)\n }\n\n for (const [key, value] of Object.entries(props)) {\n // Skip event handlers, refs, and internal props\n if (key.startsWith('on') || key === 'ref' || key === 'key' || key === 'children') continue\n if (key === 'dangerouslySetInnerHTML') continue\n\n // Skip undefined/null values\n if (value === undefined || value === null) continue\n\n // Handle aliased attributes\n const attrName = ATTR_ALIASES[key] || key\n\n // Handle style object\n if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .filter(([, v]) => v !== null && v !== undefined)\n .map(([k, v]) => `${kebabCase(k)}:${v}`)\n .join(';')\n if (styleStr) {\n parts.push(`style=\"${escapeAttribute(styleStr)}\"`)\n }\n continue\n }\n\n // Handle boolean attributes\n if (BOOLEAN_ATTRS.has(attrName)) {\n if (value) parts.push(attrName)\n continue\n }\n\n // Handle false boolean values - skip entirely\n if (value === false) continue\n\n // Regular attribute\n parts.push(`${attrName}=\"${escapeAttribute(String(value))}\"`)\n }\n\n return parts.length ? ' ' + parts.join(' ') : ''\n}\n\nfunction renderComponentToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const Component = fnode.type as Function\n\n // Merge props with children\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Check if this is a Context Provider\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Create minimal component instance for server (hooks support)\n const instance: ComponentInstance = {\n hooks: [],\n hookIndex: 0\n }\n\n try {\n // Run component with hook context\n const result = runWithComponent(instance, () => Component(props))\n\n // Render result\n return renderNodeToString(result, includeHydrationMarkers)\n } finally {\n // Restore context if it was a provider\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n\nfunction kebabCase(str: string): string {\n return str.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n"]}
|
package/dist/server.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {e,a as a$1,f as f$1}from'./chunk-MI76R42D.mjs';var $={"&":"&","<":"<",">":">",'"':""","'":"'"},F=/[&<>"']/g;function l(e){return String(e).replace(F,r=>$[r])}function a(e){return l(e)}var f=false,d=null,h=0;function I(){return f}function b(){f=true,d=new Map,h=0;}function S(){f=false;let e=Object.fromEntries(d||new Map);return d=null,{states:e}}function x(){return `fid-${h++}`}var T=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),v=new Set(["disabled","checked","readonly","required","hidden","selected","autofocus","autoplay","controls","loop","muted","multiple","open","defer","async","novalidate"]),A={className:"class",htmlFor:"for"};function R(e,r={}){let{hydrate:n=true}=r;b();try{let t;typeof e=="function"&&!N(e)?t={type:e,props:{},children:[],key:void 0}:t=e;let o=p(t,n),i=S();return {html:o,state:i}}catch(t){throw S(),t}}function E(e){let{html:r}=R(e,{hydrate:false});return r}function N(e){return e&&typeof e=="object"&&"type"in e&&"props"in e}function p(e,r){if(e==null||typeof e=="boolean")return "";if(typeof e=="string"||typeof e=="number")return l(String(e));if(Array.isArray(e))return e.map(n=>p(n,r)).join("");if(typeof e=="function")return C({type:e,props:{},children:[]},r);if(typeof e=="object"&&N(e)){if(typeof e.type=="string")return w(e,r);if(typeof e.type=="function")return C(e,r)}return ""}function w(e,r){let n=e.type,t=j(e.props,r);if(e.props?.dangerouslySetInnerHTML){let i=e.props.dangerouslySetInnerHTML.__html||"";return `<${n}${t}>${i}</${n}>`}if(T.has(n))return `<${n}${t}>`;let o=(e.children||[]).map(i=>p(i,r)).join("");return `<${n}${t}>${o}</${n}>`}function j(e,r){if(!e)return "";let n=[];if(r){let t=x();n.push(`data-fid="${t}"`);}for(let[t,o]of Object.entries(e)){if(t.startsWith("on")||t==="ref"||t==="key"||t==="children"||t==="dangerouslySetInnerHTML"||o==null)continue;let i=A[t]||t;if(t==="style"&&typeof o=="object"){let c=Object.entries(o).filter(([,s])=>s!=null).map(([s,u])=>`${k(s)}:${u}`).join(";");c&&n.push(`style="${a(c)}"`);continue}if(v.has(i)){o&&n.push(i);continue}o!==false&&n.push(`${i}="${a(String(o))}"`);}return n.length?" "+n.join(" "):""}function C(e$1,r){let n=e$1.type,t={...e$1.props};e$1.children&&e$1.children.length>0&&(t.children=e$1.children.length===1?e$1.children[0]:e$1.children);let o=n._contextId,i=o!==void 0,c;i&&(c=e(o,t.value));let s={hooks:[],hookIndex:0};try{let u=a$1(s,()=>n(t));return p(u,r)}finally{i&&f$1(o,c);}}function k(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}export{I as getIsServer,E as renderToStaticMarkup,R as renderToString};//# sourceMappingURL=server.mjs.map
|
|
2
2
|
//# sourceMappingURL=server.mjs.map
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/escape.ts","../src/server/serverState.ts","../src/server/renderToString.ts"],"names":["ESCAPE_MAP","ESCAPE_REGEX","escapeHtml","str","char","escapeAttribute","isServerRendering","serverStateCollector","hydrationIdCounter","getIsServer","enterServerRender","exitServerRender","states","generateHydrationId","VOID_ELEMENTS","BOOLEAN_ATTRS","ATTR_ALIASES","renderToString","app","options","hydrate","fnode","isFNode","html","renderNodeToString","state","error","renderToStaticMarkup","value","includeHydrationMarkers","child","renderComponentToString","renderElementToString","tag","attrs","renderAttributes","innerHTML","childrenHtml","props","parts","fid","key","attrName","styleStr","v","k","kebabCase","Component","contextId","isProvider","prevContextValue","pushContext","instance","result","runWithComponent","popContext"],"mappings":"0FAAA,IAAMA,EAAqC,CACzC,GAAA,CAAK,OAAA,CACL,GAAA,CAAK,OACL,GAAA,CAAK,MAAA,CACL,GAAA,CAAK,QAAA,CACL,IAAK,QACP,CAAA,CAEMC,CAAAA,CAAe,UAAA,CAEd,SAASC,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAO,OAAOA,CAAG,CAAA,CAAE,OAAA,CAAQF,CAAAA,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s","sourcesContent":["const ESCAPE_MAP: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": '''\n}\n\nconst ESCAPE_REGEX = /[&<>\"']/g\n\nexport function escapeHtml(str: string): string {\n return String(str).replace(ESCAPE_REGEX, char => ESCAPE_MAP[char])\n}\n\nexport function escapeAttribute(str: string): string {\n return escapeHtml(str)\n}\n","import type { SerializedState } from './types'\n\nlet isServerRendering = false\nlet serverStateCollector: Map<string, unknown> | null = null\nlet hydrationIdCounter = 0\n\nexport function getIsServer(): boolean {\n return isServerRendering\n}\n\nexport function enterServerRender(): void {\n isServerRendering = true\n serverStateCollector = new Map()\n hydrationIdCounter = 0\n}\n\nexport function exitServerRender(): SerializedState {\n isServerRendering = false\n const states = Object.fromEntries(serverStateCollector || new Map())\n serverStateCollector = null\n\n return { states }\n}\n\nexport function collectServerState(key: string, value: unknown): void {\n if (serverStateCollector) {\n serverStateCollector.set(key, value)\n }\n}\n\nexport function generateHydrationId(): string {\n return `fid-${hydrationIdCounter++}`\n}\n\nexport function resetHydrationIdCounter(): void {\n hydrationIdCounter = 0\n}\n","import type { FNode, FNodeChild } from '../dom/types'\nimport type { SSROptions, SSRResult } from './types'\nimport { escapeHtml, escapeAttribute } from './escape'\nimport {\n enterServerRender,\n exitServerRender,\n generateHydrationId\n} from './serverState'\nimport { runWithComponent, ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\n\n// Self-closing HTML tags\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// Attributes that should be rendered as boolean\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'checked', 'readonly', 'required', 'hidden',\n 'selected', 'autofocus', 'autoplay', 'controls', 'loop', 'muted',\n 'multiple', 'open', 'defer', 'async', 'novalidate'\n])\n\n// Attributes that need special handling\nconst ATTR_ALIASES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for'\n}\n\n/**\n * Render component tree to HTML string with hydration markers\n */\nexport function renderToString(\n app: FNodeChild | (() => FNodeChild),\n options: SSROptions = {}\n): SSRResult {\n const { hydrate = true } = options\n\n enterServerRender()\n\n try {\n // Normalize input - wrap function in FNode if needed\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n const html = renderNodeToString(fnode, hydrate)\n const state = exitServerRender()\n\n return { html, state }\n } catch (error) {\n exitServerRender()\n throw error\n }\n}\n\n/**\n * Render component tree to static HTML (no hydration markers)\n * Use for email templates, static pages, etc.\n */\nexport function renderToStaticMarkup(app: FNodeChild | (() => FNodeChild)): string {\n const { html } = renderToString(app, { hydrate: false })\n return html\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction renderNodeToString(fnode: FNodeChild, includeHydrationMarkers: boolean): string {\n // Null/undefined/boolean -> empty string\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n return ''\n }\n\n // String/number -> escaped text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return escapeHtml(String(fnode))\n }\n\n // Array -> concatenate children\n if (Array.isArray(fnode)) {\n return fnode.map(child => renderNodeToString(child, includeHydrationMarkers)).join('')\n }\n\n // Function (standalone) -> wrap in FNode and render\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return renderComponentToString(wrappedFnode, includeHydrationMarkers)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n // HTML element\n if (typeof fnode.type === 'string') {\n return renderElementToString(fnode, includeHydrationMarkers)\n }\n\n // Function component\n if (typeof fnode.type === 'function') {\n return renderComponentToString(fnode, includeHydrationMarkers)\n }\n }\n\n return ''\n}\n\nfunction renderElementToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const tag = fnode.type as string\n const attrs = renderAttributes(fnode.props, includeHydrationMarkers)\n\n // Handle dangerouslySetInnerHTML\n if (fnode.props?.dangerouslySetInnerHTML) {\n const innerHTML = fnode.props.dangerouslySetInnerHTML.__html || ''\n return `<${tag}${attrs}>${innerHTML}</${tag}>`\n }\n\n // Void elements (self-closing)\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`\n }\n\n // Render children\n const childrenHtml = (fnode.children || [])\n .map(child => renderNodeToString(child, includeHydrationMarkers))\n .join('')\n\n return `<${tag}${attrs}>${childrenHtml}</${tag}>`\n}\n\nfunction renderAttributes(props: Record<string, any>, includeHydrationMarkers: boolean): string {\n if (!props) return ''\n\n const parts: string[] = []\n\n // Add hydration ID if needed\n if (includeHydrationMarkers) {\n const fid = generateHydrationId()\n parts.push(`data-fid=\"${fid}\"`)\n }\n\n for (const [key, value] of Object.entries(props)) {\n // Skip event handlers, refs, and internal props\n if (key.startsWith('on') || key === 'ref' || key === 'key' || key === 'children') continue\n if (key === 'dangerouslySetInnerHTML') continue\n\n // Skip undefined/null values\n if (value === undefined || value === null) continue\n\n // Handle aliased attributes\n const attrName = ATTR_ALIASES[key] || key\n\n // Handle style object\n if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .filter(([, v]) => v !== null && v !== undefined)\n .map(([k, v]) => `${kebabCase(k)}:${v}`)\n .join(';')\n if (styleStr) {\n parts.push(`style=\"${escapeAttribute(styleStr)}\"`)\n }\n continue\n }\n\n // Handle boolean attributes\n if (BOOLEAN_ATTRS.has(attrName)) {\n if (value) parts.push(attrName)\n continue\n }\n\n // Handle false boolean values - skip entirely\n if (value === false) continue\n\n // Regular attribute\n parts.push(`${attrName}=\"${escapeAttribute(String(value))}\"`)\n }\n\n return parts.length ? ' ' + parts.join(' ') : ''\n}\n\nfunction renderComponentToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const Component = fnode.type as Function\n\n // Merge props with children\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Check if this is a Context Provider\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Create minimal component instance for server (hooks support)\n const instance: ComponentInstance = {\n hooks: [],\n hookIndex: 0\n }\n\n try {\n // Run component with hook context\n const result = runWithComponent(instance, () => Component(props))\n\n // Render result\n return renderNodeToString(result, includeHydrationMarkers)\n } finally {\n // Restore context if it was a provider\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n\nfunction kebabCase(str: string): string {\n return str.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/server/escape.ts","../src/server/serverState.ts","../src/server/renderToString.ts"],"names":["ESCAPE_MAP","ESCAPE_REGEX","escapeHtml","str","char","escapeAttribute","isServerRendering","serverStateCollector","hydrationIdCounter","getIsServer","enterServerRender","exitServerRender","states","generateHydrationId","VOID_ELEMENTS","BOOLEAN_ATTRS","ATTR_ALIASES","renderToString","app","options","hydrate","fnode","isFNode","html","renderNodeToString","state","error","renderToStaticMarkup","value","includeHydrationMarkers","child","renderComponentToString","renderElementToString","tag","attrs","renderAttributes","innerHTML","childrenHtml","props","parts","fid","key","attrName","styleStr","v","k","kebabCase","Component","contextId","isProvider","prevContextValue","pushContext","instance","result","runWithComponent","popContext"],"mappings":"uDAAA,IAAMA,EAAqC,CACzC,GAAA,CAAK,OAAA,CACL,GAAA,CAAK,OACL,GAAA,CAAK,MAAA,CACL,GAAA,CAAK,QAAA,CACL,IAAK,QACP,CAAA,CAEMC,CAAAA,CAAe,UAAA,CAEd,SAASC,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAO,OAAOA,CAAG,CAAA,CAAE,OAAA,CAAQF,CAAAA,CAAcG,GAAQJ,CAAAA,CAAWI,CAAI,CAAC,CACnE,CAEO,SAASC,CAAAA,CA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\"': '"',\n \"'\": '''\n}\n\nconst ESCAPE_REGEX = /[&<>\"']/g\n\nexport function escapeHtml(str: string): string {\n return String(str).replace(ESCAPE_REGEX, char => ESCAPE_MAP[char])\n}\n\nexport function escapeAttribute(str: string): string {\n return escapeHtml(str)\n}\n","import type { SerializedState } from './types'\n\nlet isServerRendering = false\nlet serverStateCollector: Map<string, unknown> | null = null\nlet hydrationIdCounter = 0\n\nexport function getIsServer(): boolean {\n return isServerRendering\n}\n\nexport function enterServerRender(): void {\n isServerRendering = true\n serverStateCollector = new Map()\n hydrationIdCounter = 0\n}\n\nexport function exitServerRender(): SerializedState {\n isServerRendering = false\n const states = Object.fromEntries(serverStateCollector || new Map())\n serverStateCollector = null\n\n return { states }\n}\n\nexport function collectServerState(key: string, value: unknown): void {\n if (serverStateCollector) {\n serverStateCollector.set(key, value)\n }\n}\n\nexport function generateHydrationId(): string {\n return `fid-${hydrationIdCounter++}`\n}\n\nexport function resetHydrationIdCounter(): void {\n hydrationIdCounter = 0\n}\n","import type { FNode, FNodeChild } from '../dom/types'\nimport type { SSROptions, SSRResult } from './types'\nimport { escapeHtml, escapeAttribute } from './escape'\nimport {\n enterServerRender,\n exitServerRender,\n generateHydrationId\n} from './serverState'\nimport { runWithComponent, ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\n\n// Self-closing HTML tags\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// Attributes that should be rendered as boolean\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'checked', 'readonly', 'required', 'hidden',\n 'selected', 'autofocus', 'autoplay', 'controls', 'loop', 'muted',\n 'multiple', 'open', 'defer', 'async', 'novalidate'\n])\n\n// Attributes that need special handling\nconst ATTR_ALIASES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for'\n}\n\n/**\n * Render component tree to HTML string with hydration markers\n */\nexport function renderToString(\n app: FNodeChild | (() => FNodeChild),\n options: SSROptions = {}\n): SSRResult {\n const { hydrate = true } = options\n\n enterServerRender()\n\n try {\n // Normalize input - wrap function in FNode if needed\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n const html = renderNodeToString(fnode, hydrate)\n const state = exitServerRender()\n\n return { html, state }\n } catch (error) {\n exitServerRender()\n throw error\n }\n}\n\n/**\n * Render component tree to static HTML (no hydration markers)\n * Use for email templates, static pages, etc.\n */\nexport function renderToStaticMarkup(app: FNodeChild | (() => FNodeChild)): string {\n const { html } = renderToString(app, { hydrate: false })\n return html\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction renderNodeToString(fnode: FNodeChild, includeHydrationMarkers: boolean): string {\n // Null/undefined/boolean -> empty string\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n return ''\n }\n\n // String/number -> escaped text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return escapeHtml(String(fnode))\n }\n\n // Array -> concatenate children\n if (Array.isArray(fnode)) {\n return fnode.map(child => renderNodeToString(child, includeHydrationMarkers)).join('')\n }\n\n // Function (standalone) -> wrap in FNode and render\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return renderComponentToString(wrappedFnode, includeHydrationMarkers)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n // HTML element\n if (typeof fnode.type === 'string') {\n return renderElementToString(fnode, includeHydrationMarkers)\n }\n\n // Function component\n if (typeof fnode.type === 'function') {\n return renderComponentToString(fnode, includeHydrationMarkers)\n }\n }\n\n return ''\n}\n\nfunction renderElementToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const tag = fnode.type as string\n const attrs = renderAttributes(fnode.props, includeHydrationMarkers)\n\n // Handle dangerouslySetInnerHTML\n if (fnode.props?.dangerouslySetInnerHTML) {\n const innerHTML = fnode.props.dangerouslySetInnerHTML.__html || ''\n return `<${tag}${attrs}>${innerHTML}</${tag}>`\n }\n\n // Void elements (self-closing)\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`\n }\n\n // Render children\n const childrenHtml = (fnode.children || [])\n .map(child => renderNodeToString(child, includeHydrationMarkers))\n .join('')\n\n return `<${tag}${attrs}>${childrenHtml}</${tag}>`\n}\n\nfunction renderAttributes(props: Record<string, any>, includeHydrationMarkers: boolean): string {\n if (!props) return ''\n\n const parts: string[] = []\n\n // Add hydration ID if needed\n if (includeHydrationMarkers) {\n const fid = generateHydrationId()\n parts.push(`data-fid=\"${fid}\"`)\n }\n\n for (const [key, value] of Object.entries(props)) {\n // Skip event handlers, refs, and internal props\n if (key.startsWith('on') || key === 'ref' || key === 'key' || key === 'children') continue\n if (key === 'dangerouslySetInnerHTML') continue\n\n // Skip undefined/null values\n if (value === undefined || value === null) continue\n\n // Handle aliased attributes\n const attrName = ATTR_ALIASES[key] || key\n\n // Handle style object\n if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .filter(([, v]) => v !== null && v !== undefined)\n .map(([k, v]) => `${kebabCase(k)}:${v}`)\n .join(';')\n if (styleStr) {\n parts.push(`style=\"${escapeAttribute(styleStr)}\"`)\n }\n continue\n }\n\n // Handle boolean attributes\n if (BOOLEAN_ATTRS.has(attrName)) {\n if (value) parts.push(attrName)\n continue\n }\n\n // Handle false boolean values - skip entirely\n if (value === false) continue\n\n // Regular attribute\n parts.push(`${attrName}=\"${escapeAttribute(String(value))}\"`)\n }\n\n return parts.length ? ' ' + parts.join(' ') : ''\n}\n\nfunction renderComponentToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const Component = fnode.type as Function\n\n // Merge props with children\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Check if this is a Context Provider\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Create minimal component instance for server (hooks support)\n const instance: ComponentInstance = {\n hooks: [],\n hookIndex: 0\n }\n\n try {\n // Run component with hook context\n const result = runWithComponent(instance, () => Component(props))\n\n // Render result\n return renderNodeToString(result, includeHydrationMarkers)\n } finally {\n // Restore context if it was a provider\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n\nfunction kebabCase(str: string): string {\n return str.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n"]}
|
package/package.json
CHANGED
package/dist/chunk-3DKZ2J4D.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var n=new Map;function a(t){let e=Symbol("context"),o=r=>r.children;return o._contextId=e,{Provider:o,id:e,defaultValue:t}}function p(t){return n.has(t.id)?n.get(t.id):t.defaultValue}function s(t,e){let o=n.get(t);return n.set(t,e),o}function c(t,e){e===void 0?n.delete(t):n.set(t,e);}export{a,p as b,s as c,c as d};//# sourceMappingURL=chunk-3DKZ2J4D.mjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-3DKZ2J4D.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/context.ts"],"names":["contextMap","createContext","defaultValue","id","Provider","props","context","ctx","pushContext","value","prev","popContext","prevValue"],"mappings":"AAIA,IAAMA,EAAa,IAAI,GAAA,CAEhB,SAASC,CAAAA,CAAiBC,EAA6B,CAC1D,IAAMC,CAAAA,CAAK,MAAA,CAAO,SAAS,CAAA,CACrBC,CAAAA,CAAYC,GAAuCA,CAAAA,CAAM,QAAA,CAC/D,OAACD,CAAAA,CAAiB,UAAA,CAAaD,CAAAA,CACxB,CAAE,SAAAC,CAAAA,CAAU,EAAA,CAAAD,CAAAA,CAAI,YAAA,CAAAD,CAAa,CACxC,CAEO,SAASI,CAAAA,CAAWC,EAAoB,CAC3C,OAAOP,EAAW,GAAA,CAAIO,CAAAA,CAAI,EAAE,CAAA,CAAIP,CAAAA,CAAW,GAAA,CAAIO,CAAAA,CAAI,EAAE,CAAA,CAAIA,CAAAA,CAAI,YACjE,CAGO,SAASC,CAAAA,CAAYL,CAAAA,CAAYM,CAAAA,CAAY,CAChD,IAAMC,CAAAA,CAAOV,CAAAA,CAAW,IAAIG,CAAE,CAAA,CAC9B,OAAAH,CAAAA,CAAW,GAAA,CAAIG,CAAAA,CAAIM,CAAK,EACjBC,CACX,CAGO,SAASC,CAAAA,CAAWR,CAAAA,CAAYS,EAAgB,CAC/CA,CAAAA,GAAc,MAAA,CACdZ,CAAAA,CAAW,OAAOG,CAAE,CAAA,CAEpBH,EAAW,GAAA,CAAIG,CAAAA,CAAIS,CAAS,EAEpC","file":"chunk-3DKZ2J4D.mjs","sourcesContent":["import type { Context } from './types'\n\nexport type { Context }\n\nconst contextMap = new Map<symbol, any>()\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('context')\n const Provider = (props: { value: T; children: any }) => props.children;\n (Provider as any)._contextId = id\n return { Provider, id, defaultValue }\n}\n\nexport function context<T>(ctx: Context<T>): T {\n return contextMap.has(ctx.id) ? contextMap.get(ctx.id) : ctx.defaultValue\n}\n\n// Internal helpers for renderer\nexport function pushContext(id: symbol, value: any) {\n const prev = contextMap.get(id)\n contextMap.set(id, value)\n return prev\n}\n\n\nexport function popContext(id: symbol, prevValue: any) {\n if (prevValue === undefined) {\n contextMap.delete(id)\n } else {\n contextMap.set(id, prevValue)\n }\n}\n\nexport function snapshotContext(): Map<symbol, any> {\n return new Map(contextMap)\n}\n\nexport function runWithContext<R>(snapshot: Map<symbol, any>, fn: () => R): R {\n // 1. Save current context\n const prevContext = new Map(contextMap)\n\n // 2. Apply snapshot\n contextMap.clear()\n snapshot.forEach((value, key) => contextMap.set(key, value))\n\n try {\n return fn()\n } finally {\n // 3. Restore previous context\n contextMap.clear()\n prevContext.forEach((value, key) => contextMap.set(key, value))\n }\n}\n"]}
|
package/dist/chunk-5PNH2ARD.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var t=null;function s(n,o){let e=t;t=n,n.hookIndex=0;try{return o()}finally{t=e;}}function c(n){if(!t)return n();let o=t,{hooks:e,hookIndex:r}=o;if(r<e.length)return o.hookIndex++,e[r];let u=n();return e.push(u),o.hookIndex++,u}export{s as a,c as b};//# sourceMappingURL=chunk-5PNH2ARD.mjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-5PNH2ARD.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/hook.ts"],"names":["currentComponent","runWithComponent","component","fn","prev","hook","factory","instance","hooks","hookIndex","value"],"mappings":"AAMA,IAAIA,CAAAA,CAA6C,IAAA,CAM1C,SAASC,CAAAA,CAAoBC,CAAAA,CAA8BC,CAAAA,CAAgB,CAC9E,IAAMC,CAAAA,CAAOJ,CAAAA,CACbA,CAAAA,CAAmBE,CAAAA,CACnBA,EAAU,SAAA,CAAY,CAAA,CACtB,GAAI,CACA,OAAOC,CAAAA,EACX,CAAA,OAAE,CACEH,CAAAA,CAAmBI,EACvB,CACJ,CAEO,SAASC,CAAAA,CAAQC,CAAAA,CAAqB,CACzC,GAAI,CAACN,CAAAA,CAED,OAAOM,CAAAA,EAAQ,CAGnB,IAAMC,CAAAA,CAAWP,CAAAA,CACX,CAAE,KAAA,CAAAQ,CAAAA,CAAO,SAAA,CAAAC,CAAU,CAAA,CAAIF,CAAAA,CAE7B,GAAIE,CAAAA,CAAYD,EAAM,MAAA,CAElB,OAAAD,CAAAA,CAAS,SAAA,EAAA,CACFC,CAAAA,CAAMC,CAAS,CAAA,CAI1B,IAAMC,EAAQJ,CAAAA,EAAQ,CACtB,OAAAE,CAAAA,CAAM,IAAA,CAAKE,CAAK,CAAA,CAChBH,CAAAA,CAAS,YAEFG,CACX","file":"chunk-5PNH2ARD.mjs","sourcesContent":["\nexport interface ComponentInstance {\n hooks: any[]\n hookIndex: number\n}\n\nlet currentComponent: ComponentInstance | null = null\n\nexport function getComponent(): ComponentInstance | null {\n return currentComponent\n}\n\nexport function runWithComponent<T>(component: ComponentInstance, fn: () => T): T {\n const prev = currentComponent\n currentComponent = component\n component.hookIndex = 0\n try {\n return fn()\n } finally {\n currentComponent = prev\n }\n}\n\nexport function hook<T>(factory: () => T): T {\n if (!currentComponent) {\n // Outside component: just run factory\n return factory()\n }\n\n const instance = currentComponent\n const { hooks, hookIndex } = instance\n\n if (hookIndex < hooks.length) {\n // Return existing hook\n instance.hookIndex++\n return hooks[hookIndex] as T\n }\n\n // Create new hook\n const value = factory()\n hooks.push(value)\n instance.hookIndex++\n\n return value\n}\n"]}
|
package/dist/chunk-6VIRXD2Y.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkYWTD32NA_js=require('./chunk-YWTD32NA.js');var p=Symbol("flexium.reactive"),s=new WeakMap,l=new WeakMap;function M(e){if(e&&e[p])return e;let o=l.get(e);if(o)return o;let t=new Proxy(e,{get(n,r,i){if(r===p)return true;let c=Reflect.get(n,r,i);return b(n,r),c!==null&&typeof c=="object"?M(c):c},set(n,r,i,c){let x=n[r],a=Reflect.set(n,r,i,c);return a&&d(i,x)&&w(n,r),a}});return l.set(e,t),t}function b(e,o){if(!chunkYWTD32NA_js.a)return;let t=s.get(e);t||s.set(e,t=new Map);let n=t.get(o);n||t.set(o,n=new Set),chunkYWTD32NA_js.c(n);}function w(e,o){let t=s.get(e);if(!t)return;let n=t.get(o);n&&chunkYWTD32NA_js.d(n);}function d(e,o){return !Object.is(e,o)}function T(e){return !!(e&&e[p])}exports.a=M;exports.b=T;//# sourceMappingURL=chunk-6VIRXD2Y.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-6VIRXD2Y.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/reactive.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive"],"mappings":"iEAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,EAAc,IAAI,OAAA,CAEjB,SAASC,CAAAA,CAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,EAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,CAAAA,CAAgBH,EAAY,GAAA,CAAIE,CAAM,EAC5C,GAAIC,CAAAA,CACA,OAAOA,CAAAA,CAGX,IAAMC,CAAAA,CAAQ,IAAI,KAAA,CAAMF,CAAAA,CAAQ,CAC5B,GAAA,CAAIA,CAAAA,CAAQG,EAAKC,CAAAA,CAAU,CACvB,GAAID,CAAAA,GAAQP,CAAAA,CAAiB,OAAO,KAAA,CAEpC,IAAMS,CAAAA,CAAM,QAAQ,GAAA,CAAIL,CAAAA,CAAQG,EAAKC,CAAQ,CAAA,CAI7C,OAFAE,CAAAA,CAAMN,CAAAA,CAAQG,CAAG,CAAA,CAEbE,CAAAA,GAAQ,MAAQ,OAAOA,CAAAA,EAAQ,SACxBN,CAAAA,CAASM,CAAG,EAGhBA,CACX,CAAA,CACA,GAAA,CAAIL,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,EAAU,CAC9B,IAAMI,EAAYR,CAAAA,CAAeG,CAAG,EAC9BM,CAAAA,CAAS,OAAA,CAAQ,GAAA,CAAIT,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,CAAQ,CAAA,CAEvD,OAAIK,GAAUC,CAAAA,CAAWH,CAAAA,CAAOC,CAAQ,CAAA,EACpCG,CAAAA,CAAQX,CAAAA,CAAQG,CAAG,CAAA,CAGhBM,CACX,CACJ,CAAC,CAAA,CAED,OAAAX,CAAAA,CAAY,GAAA,CAAIE,EAAQE,CAAK,CAAA,CACtBA,CACX,CAEO,SAASI,EAAMN,CAAAA,CAAgBG,CAAAA,CAAc,CAChD,GAAI,CAACS,mBAAc,OAEnB,IAAIC,CAAAA,CAAUhB,CAAAA,CAAU,GAAA,CAAIG,CAAM,EAC7Ba,CAAAA,EACDhB,CAAAA,CAAU,IAAIG,CAAAA,CAASa,CAAAA,CAAU,IAAI,GAAM,CAAA,CAG/C,IAAIC,CAAAA,CAAMD,CAAAA,CAAQ,GAAA,CAAIV,CAAG,CAAA,CACpBW,CAAAA,EACDD,EAAQ,GAAA,CAAIV,CAAAA,CAAMW,EAAM,IAAI,GAAM,CAAA,CAGtCC,kBAAAA,CAAYD,CAAG,EACnB,CAEO,SAASH,CAAAA,CAAQX,EAAgBG,CAAAA,CAAc,CAClD,IAAMU,CAAAA,CAAUhB,CAAAA,CAAU,GAAA,CAAIG,CAAM,CAAA,CACpC,GAAI,CAACa,CAAAA,CAAS,OAEd,IAAMC,CAAAA,CAAMD,CAAAA,CAAQ,IAAIV,CAAG,CAAA,CACvBW,CAAAA,EACAE,kBAAAA,CAAeF,CAAG,EAE1B,CAEA,SAASJ,CAAAA,CAAWH,EAAYC,CAAAA,CAAwB,CACpD,OAAO,CAAC,MAAA,CAAO,EAAA,CAAGD,CAAAA,CAAOC,CAAQ,CACrC,CAEO,SAASS,CAAAA,CAAWV,EAAyB,CAChD,OAAO,CAAC,EAAEA,CAAAA,EAAUA,CAAAA,CAAcX,CAAe,CAAA,CACrD","file":"chunk-6VIRXD2Y.js","sourcesContent":["import { activeEffect, trackEffect, triggerEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n"]}
|