@symbo.ls/brender 3.14.662 → 3.14.663
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/CHANGELOG.md +31 -0
- package/dist/esm/env.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/render.js +46 -109
- package/dist/esm/shell.js +6 -5
- package/env.js +59 -1
- package/index.js +5 -3
- package/package.json +5 -5
- package/render.js +291 -304
- package/shell.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @symbo.ls/brender
|
|
2
2
|
|
|
3
|
+
## 3.14.663
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Server rendering is correct and fast, opt-in hydration, and Cloudflare deploys run the full build (FW-BRENDER-HYDRATION-AND-CF-DEPLOY-PROVIDER-1, FW-PUBLISH-TIME-PRERENDER-SSRCACHE-1).
|
|
8
|
+
|
|
9
|
+
Behaviour changes (check these first):
|
|
10
|
+
|
|
11
|
+
- `smbls build` copies `public/` into the output root (never replacing a file the bundler wrote), so `_redirects`, `_headers` and `404.html` ship with every bundler.
|
|
12
|
+
- Booting over a pre-rendered page removes only `style[data-emotion="smbls"]` and `style[data-brender]`; the host page's own `<style>` tags stay.
|
|
13
|
+
- The Cloudflare worker (`renderProjectHtml` without eval) keeps the client render instead of painting a wrong pre-render; a stored pre-render (`ssrCache` / `__ssr`) is still served. `ssrWithoutEval: true` opts back in.
|
|
14
|
+
|
|
15
|
+
Fixes:
|
|
16
|
+
|
|
17
|
+
- Every server render after the first one paints its theme colours again (linkedom made `deepClone` copy nothing nested).
|
|
18
|
+
- Server pages ship their own reset, keyframes and `:root` once, also in the Cloudflare worker (`generateGlobalCSS` read the wrong keys, wrote files and cached across projects).
|
|
19
|
+
- A pre-render waits for its own requests instead of a flat 2 s; server renders stop rescanning the head for every inserted rule.
|
|
20
|
+
- The server render gets the project's `globalScope` and context keys, as the client does; a `<select>` with a value no longer drops its parent.
|
|
21
|
+
|
|
22
|
+
New, opt-in:
|
|
23
|
+
|
|
24
|
+
- Hydration: `hydrate: true` (or `window.__BRENDER_HYDRATE__` from the server, with `__BR_REGISTRY__`) adopts the server DOM instead of replacing it; a mismatch falls back to a fresh node, a throw to the fresh render. brender `renderPage({ adoptDom })` ships the registry and the recorded GET answers; `@symbo.ls/fetch` exports `createEarlySeedScript`, `earlyKey`, `EARLY_KEY`.
|
|
25
|
+
- `smbls deploy --provider cloudflare [--target pages|workers] [--dry-run] [--no-brender]` runs the full `smbls build` pipeline; `--target workers` writes Workers Static Assets config.
|
|
26
|
+
- `smbls publish --ssr` (or `"prerender": true` in `symbols.json`) pre-renders every static route and stores it as `__ssr`, which the platform renderer serves; off by default.
|
|
27
|
+
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
- smbls@3.14.828
|
|
30
|
+
- @symbo.ls/element@3.14.800
|
|
31
|
+
- @symbo.ls/css@3.14.775
|
|
32
|
+
- @symbo.ls/fetch@3.14.663
|
|
33
|
+
|
|
3
34
|
## 3.14.662
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/dist/esm/env.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseHTML as
|
|
1
|
+
import{parseHTML as c}from"linkedom";const a=new WeakSet;class h{static[Symbol.hasInstance](e){return a.has(e)}}const u=n=>{let e=Object.getPrototypeOf(n.createElement("select")),l;for(;e&&!(l=Object.getOwnPropertyDescriptor(e,"value"));)e=Object.getPrototypeOf(e);!e||!l||!l.get||l.set||Object.defineProperty(e,"value",{configurable:!0,enumerable:l.enumerable,get:l.get,set(r){const o=r==null?"":String(r);let t=!1;for(const s of this.querySelectorAll("option")){const i=s.hasAttribute("value")?s.getAttribute("value"):s.textContent;!t&&i===o?(s.setAttribute("selected",""),t=!0):s.removeAttribute("selected")}}})},b=(n="<!DOCTYPE html><html><head></head><body></body></html>")=>{const{window:e,document:l}=c(n);e.requestAnimationFrame||(e.requestAnimationFrame=o=>{const t=setTimeout(o,0);return t?.unref&&t.unref(),t}),e.cancelAnimationFrame||(e.cancelAnimationFrame=o=>clearTimeout(o)),e.history||(e.history={pushState:()=>{},replaceState:()=>{},state:null}),e.location||(e.location={pathname:"/",search:"",hash:"",origin:"http://localhost",protocol:"http:",host:"localhost",hostname:"localhost",port:"",href:"http://localhost/"}),e.URL||(e.URL=URL),e.scrollTo||(e.scrollTo=()=>{});const r=()=>{const o={};return{getItem:t=>o[t]??null,setItem:(t,s)=>{o[t]=String(s)},removeItem:t=>{delete o[t]},clear:()=>{for(const t in o)delete o[t]},get length(){return Object.keys(o).length},key:t=>Object.keys(o)[t]??null}};return e.localStorage||(e.localStorage=r()),e.sessionStorage||(e.sessionStorage=r()),globalThis.localStorage||(globalThis.localStorage=e.localStorage),globalThis.sessionStorage||(globalThis.sessionStorage=e.sessionStorage),u(l),e.MutationObserver||(e.MutationObserver=class{constructor(){}observe(){}disconnect(){}takeRecords(){return[]}}),globalThis.window=e,globalThis.document=l,globalThis.Node=e.Node||globalThis.Node,globalThis.Element=e.Element||globalThis.Element,globalThis.HTMLElement=e.HTMLElement||globalThis.HTMLElement,globalThis.MutationObserver=e.MutationObserver,a.add(e),e.constructor&&e.constructor!==Object?globalThis.Window=e.constructor:(typeof globalThis.Window!="function"||globalThis.Window===Object)&&(globalThis.Window=h),{window:e,document:l}};export{b as createEnv};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEnv as e}from"./env.js";import{resetKeys as r,assignKeys as t,mapKeysToElements as o}from"./keys.js";import{loadProject as m,loadAndRenderAll as a}from"./load.js";import{render as
|
|
1
|
+
import{createEnv as e}from"./env.js";import{resetKeys as r,assignKeys as t,mapKeysToElements as o}from"./keys.js";import{loadProject as m,loadAndRenderAll as a}from"./load.js";import{render as p,renderElement as n,renderRoute as d,renderPage as i,resetGlobalCSSCache as l,getAccumulatedEmotionCSS as c,replaceEmotionCSS as f,adoptionScripts as s}from"./render.js";import{extractMetadata as S,generateHeadHtml as g}from"./metadata.js";import{collectBrNodes as h,hydrate as E}from"./hydrate.js";import{generateSitemap as u}from"./sitemap.js";import{prefetchPageData as y,injectPrefetchedState as C}from"./prefetch.js";import{composeIntoShell as P}from"./shell.js";var D={createEnv:e,resetKeys:r,assignKeys:t,mapKeysToElements:o,loadProject:m,loadAndRenderAll:a,render:p,renderElement:n,renderRoute:d,renderPage:i,resetGlobalCSSCache:l,getAccumulatedEmotionCSS:c,replaceEmotionCSS:f,extractMetadata:S,generateHeadHtml:g,collectBrNodes:h,hydrate:E,generateSitemap:u,prefetchPageData:y,injectPrefetchedState:C,composeIntoShell:P,adoptionScripts:s};export{s as adoptionScripts,t as assignKeys,h as collectBrNodes,P as composeIntoShell,e as createEnv,D as default,S as extractMetadata,g as generateHeadHtml,u as generateSitemap,c as getAccumulatedEmotionCSS,E as hydrate,C as injectPrefetchedState,a as loadAndRenderAll,m as loadProject,o as mapKeysToElements,y as prefetchPageData,p as render,n as renderElement,i as renderPage,d as renderRoute,f as replaceEmotionCSS,l as resetGlobalCSSCache,r as resetKeys};
|
package/dist/esm/render.js
CHANGED
|
@@ -1,87 +1,25 @@
|
|
|
1
|
-
import{resolve as m,join as Q,dirname as P}from"path";import{existsSync as y,unlinkSync as Ct,readFileSync as K,realpathSync as Tt}from"fs";import{resolvePackageEntry as Ot}from"./packageEntry.js";import{tmpdir as Lt}from"os";import{randomBytes as It}from"crypto";import{createRequire as tt}from"module";import{createEnv as st}from"./env.js";import{resetKeys as rt,assignKeys as it,mapKeysToElements as ct}from"./keys.js";import{extractMetadata as et,generateHeadHtml as At}from"./metadata.js";import"./hydrate.js";import{composeIntoShell as Et}from"./shell.js";import{prefetchPageData as Pt,injectPrefetchedState as qt,fetchSSRTranslations as vt}from"./prefetch.js";let z=null;const Dt=async()=>{if(z)return z;try{return z=(await import("@symbo.ls/funcql")).funcqlPlugin,z}catch{return null}};import"linkedom";import{reset as Mt}from"@symbo.ls/css";const ot=(t,e)=>{if(!t||!e)return;if(t[e]!==void 0)return t[e];const o=e.split(".");let n=t;for(const r of o){if(n==null||typeof n!="object")return;n=n[r]}return n},Ft=function(t,e){if(!t)return"";const o=this?.context,n=o?.polyglot,r=e||n?.defaultLang||"en";if(n?.translations){const l=n.translations[r];if(l){const c=ot(l,t);if(c!==void 0)return c}}const u=this?.state?.root||o?.state?.root;if(u?.translations){const l=u.translations[r];if(l){const c=ot(l,t);if(c!==void 0)return c}}const p=n?.defaultLang||"en";if(p!==r&&n?.translations){const l=n.translations[p];if(l){const c=ot(l,t);if(c!==void 0)return c}}return t},lt=function(){const t=this?.context;return this?.state?.root?.lang||t?.polyglot?.defaultLang||"en"},F=(t,e=new WeakMap)=>{if(t===null||typeof t!="object")return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const n=[];e.set(t,n);for(const r of t)n.push(typeof r=="object"&&r!==null?F(r,e):r);return n}const o={};e.set(t,o);for(const n of Object.keys(t)){const r=t[n];o[n]=typeof r=="object"&&r!==null?F(r,e):r}return o},at=()=>{const t=new WeakSet;return(e,o)=>{if(typeof o!="function"){if(typeof o=="object"&&o!==null){if(t.has(o))return;t.add(o)}return o}}};let B=null;try{import.meta.url&&(B=tt(import.meta.url))}catch{}const ft=()=>{if(!import.meta.url||!B)return{isMonorepo:!1,monorepoRoot:null,resolvePackage:c=>c};const t=Tt(new URL(".",import.meta.url).pathname),e=m(t,"../..");if(y(m(e,"packages","smbls","src","createDomql.js")))return{isMonorepo:!0,monorepoRoot:e};let n;try{const c=B.resolve("smbls/package.json");n=P(c)}catch{let c=t;for(;c!==P(c);){const s=m(c,"node_modules","smbls");if(y(m(s,"package.json"))){n=s;break}c=P(c)}}let r=B;if(n)try{r=tt(m(n,"package.json"))}catch{}let u,p=process.cwd();for(;p!==P(p);){if(y(m(p,"package.json"))){u=p;break}p=P(p)}let l=r;if(u)try{l=tt(m(u,"package.json"))}catch{}return{isMonorepo:!1,smblsRoot:n,brenderDir:t,projectRoot:u,_smblsRequire:r,_projectRequire:l}},H=(t,e)=>{const o=t.isMonorepo?[B]:[t._smblsRequire,t._projectRequire,B].filter(Boolean);for(const n of o)try{return n.resolve(e)}catch{}return null},he=(t,e,...o)=>{if(t.isMonorepo)return m(t.monorepoRoot,"packages",e,...o);const n=H(t,`${e}/package.json`);return n?m(P(n),...o):null},be=(t,e,...o)=>{if(t.isMonorepo)return m(t.monorepoRoot,"plugins",e,...o);const n=H(t,`@symbo.ls/${e}/package.json`);return n?m(P(n),...o):null},nt=(t,e,...o)=>{if(t.isMonorepo){for(const r of["packages","plugins"]){const u=m(t.monorepoRoot,r,e,...o);if(y(u))return u}return null}const n=H(t,`@symbo.ls/${e}/package.json`);return n?m(P(n),...o):null},Y=(t,e,...o)=>{if(t.isMonorepo)return m(t.monorepoRoot,"packages","domql","packages",e,...o);const n=H(t,`@symbo.ls/${e}/package.json`);return n?m(P(n),...o):null};let W=null;const ut="smbls/ssr",pt=async()=>{const t=await import("smbls/ssr");if(typeof t?.createDomqlElement!="function")throw new Error("smbls/ssr does not export createDomqlElement");return t},Nt=async()=>{if(W)return W;const t=ft();if(!B)try{return W=await pt(),W}catch(l){throw new Error(`brender: ${ut} is not available in this bundled runtime (${l.message}). Bundle smbls \u2265 the release that adds the smbls/ssr export alongside @symbo.ls/brender.`)}let e;if(t.isMonorepo)e=m(t.monorepoRoot,"packages","smbls","src","createDomql.js");else{let l;try{return W=await pt(),W}catch(s){l=s}const c=t.smblsRoot&&m(t.smblsRoot,"src","createDomql.js");if(c&&y(c))e=c;else throw new Error(`brender: cannot load ${ut} (${l.message}). Server rendering needs smbls installed in this project, at a release that exports smbls/ssr`+(t.smblsRoot?` (found smbls at ${t.smblsRoot}).`:" (no smbls package found)."))}const o=await import("esbuild"),n=Q(Lt(),`br_createDomql_${It(6).toString("hex")}.mjs`),r=Ot,u={name:"workspace-resolve",setup(l){l.onResolve({filter:/^smbls/},c=>{const s=c.path.replace(/^smbls\/?/,""),i=t.isMonorepo?m(t.monorepoRoot,"packages","smbls"):t.smblsRoot;if(!i)return;if(!s){const g=r(i);return g?{path:g}:void 0}const a=m(i,s);if(y(a))return{path:a};if(y(a+".js"))return{path:a+".js"};const f=m(a,"index.js");if(y(f))return{path:f}}),l.onResolve({filter:/^domql$/},c=>{if(t.isMonorepo){const s=m(t.monorepoRoot,"packages","domql","src","index.js");if(y(s))return{path:s};const i=m(t.monorepoRoot,"packages","domql","index.js");if(y(i))return{path:i}}else try{const s=_require.resolve("domql/package.json"),i=r(P(s));if(i)return{path:i}}catch{}}),l.onResolve({filter:/^@symbo\.ls\//},c=>{const s=c.path.replace("@symbo.ls/","");if(s==="sync")return{path:"sync-stub",namespace:"brender-stub"};if(t.isMonorepo){for(const a of["packages","plugins"]){const f=m(t.monorepoRoot,a,s,"src","index.js");if(y(f))return{path:f};const g=m(t.monorepoRoot,a,s,"index.js");if(y(g))return{path:g}}const i=m(t.monorepoRoot,"packages","default-config","blank","index.js");if(s==="default-config"&&y(i))return{path:i}}else{const i=nt(t,s,"src","index.js");if(i&&y(i))return{path:i};const a=nt(t,s,"index.js");if(a&&y(a))return{path:a};if(s==="default-config"){const f=nt(t,"default-config","blank","index.js");if(f&&y(f))return{path:f}}}}),l.onResolve({filter:/^@domql\//},c=>{const s=c.path.replace("@symbo.ls/","");if(t.isMonorepo){const i=m(t.monorepoRoot,"packages","domql","packages",s,"src","index.js");if(y(i))return{path:i};const a=m(t.monorepoRoot,"packages","domql","packages",s,"index.js");if(y(a))return{path:a}}else{const i=Y(t,s,"src","index.js");if(i&&y(i))return{path:i};const a=Y(t,s,"index.js");if(a&&y(a))return{path:a}}}),l.onResolve({filter:/^css-in-props/},c=>{let s;if(t.isMonorepo)s=m(t.monorepoRoot,"packages","css-in-props");else{const f=H(t,"css-in-props/package.json");f&&(s=P(f))}if(!s)return;const i=c.path.replace(/^css-in-props\/?/,"");if(i){const f=m(s,i),g=m(f,"index.js");if(y(g))return{path:g};if(y(f+".js"))return{path:f+".js"};if(y(f))return{path:f}}const a=r(s);if(a)return{path:a}}),l.onResolve({filter:/^@emotion\//},c=>{let s;if(t.isMonorepo)s=m(t.monorepoRoot,"node_modules",c.path);else{const i=H(t,`${c.path}/package.json`);if(!i)return;s=P(i)}if(y(s)){const i=m(s,"package.json");if(y(i))try{const a=JSON.parse(K(i,"utf8")),f=a.module||a.main||"dist/emotion-css.esm.js";return{path:m(s,f)}}catch{}return{path:s}}}),l.onResolve({filter:/\.json$/},c=>{if(c.resolveDir){const s=m(c.resolveDir,c.path);if(y(s))return{path:s}}}),l.onLoad({filter:/smbls\/.*options\.js$/},async c=>{if(!c.path.includes("smbls/")||!c.path.endsWith("options.js"))return;let s=K(c.path,"utf8");return s=s.replace(/import\s*\{[^}]*version[^}]*\}\s*from\s*['"][^'"]*package\.json['"][^;\n]*/,"const version = '0.0.0'"),s=s.replace(/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,"// createRequire removed for brender build"),{contents:s,loader:"js"}}),l.onLoad({filter:/smbls\/.*init\.js$/},async c=>{if(!c.path.includes("smbls/")||!c.path.endsWith("init.js"))return;let s=K(c.path,"utf8");return s=s.replace(/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,"// createRequire removed for brender build"),{contents:s,loader:"js"}}),l.onLoad({filter:/.*/,namespace:"brender-stub"},()=>({contents:"export const SyncComponent = {}; export const Inspect = {}; export const Notifications = {}; export const syncPlugin = () => ({}); export const notificationsPlugin = () => ({}); export const seedRawDesignSystem = () => {}; export const inspectPlugin = () => ({}); export default {}",loader:"js"})),l.onLoad({filter:/smbls\/src\/router\.js$/},async c=>{let s=K(c.path,"utf8");return s=s.replace(/import\s*\{\s*Link\s*\}\s*from\s*['"]smbls['"]/,"const Link = { tag: 'a', attr: { href: (el) => el.href } }"),{contents:s,loader:"js"}}),l.onLoad({filter:/fetchOnCreate\.js$/},async c=>{if(!c.path.includes("smbls/"))return;let s=K(c.path,"utf8");return s=s.replace(/window\s*&&\s*window\.location\s*\?\s*window\.location\.host\.includes/g,"window && window.location && window.location.host ? window.location.host.includes"),{contents:s,loader:"js"}})}};await o.build({entryPoints:[e],bundle:!0,format:"esm",platform:"node",outfile:n,write:!0,logLevel:"warning",plugins:[u],nodePaths:t.isMonorepo?[m(t.monorepoRoot,"node_modules")]:[...t.smblsRoot?[m(t.smblsRoot,"node_modules")]:[],...t.projectRoot?[m(t.projectRoot,"node_modules")]:[],...t.smblsRoot?[m(t.smblsRoot,"..","..","node_modules")]:[]].filter(l=>y(l)),supported:{"import-attributes":!1},external:["fs","path","os","crypto","url","http","https","stream","util","events","buffer","child_process","worker_threads","net","tls","dns","dgram","zlib","assert","querystring","string_decoder","readline","perf_hooks","async_hooks","v8","vm","cluster","inspector","module","process","tty","color-contrast-checker","linkedom"]});const p=await import(`file://${n}`);if(process.env.BRENDER_DEBUG)console.log("[brender] Bundle saved:",n);else try{Ct(n)}catch{}return W=p,p},Bt={Box:{},Focusable:{},Block:{display:"block"},Inline:{display:"inline"},Flex:{display:"flex"},InlineFlex:{display:"inline-flex"},Grid:{display:"grid"},InlineGrid:{display:"inline-grid"},Link:{tag:"a",attr:{href:t=>t.href,target:t=>t.target,rel:t=>t.rel}},A:{extends:"Link"},RouteLink:{extends:"Link"},Img:{tag:"img",attr:{src:t=>{let e=t.src;return typeof e=="string"&&e.includes("{{")&&(e=t.call("replaceLiteralsWithObjectFields",e,t.state)),e},alt:t=>t.alt,loading:t=>t.loading}},Image:{extends:"Img"},Button:{tag:"button"},FocusableComponent:{tag:"button"},Form:{tag:"form"},Input:{tag:"input"},TextArea:{tag:"textarea"},Textarea:{tag:"textarea"},Select:{tag:"select"},Label:{tag:"label"},Iframe:{tag:"iframe"},Video:{tag:"video"},Audio:{tag:"audio"},Canvas:{tag:"canvas"},Span:{tag:"span"},P:{tag:"p"},H1:{tag:"h1"},H2:{tag:"h2"},H3:{tag:"h3"},H4:{tag:"h4"},H5:{tag:"h5"},H6:{tag:"h6"},Svg:{tag:"svg",attr:{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}},Text:{tag:"span"}},mt=(t,e="")=>{if(!t||!t.__ref)return{};const o={},n=t.__ref.__brKey;if(n&&(o[e===""?"__root":e]=n),t.__ref.__children)for(const r of t.__ref.__children){const u=t[r];if(u&&u.__ref){const p=e===""?r:`${e}.${r}`;Object.assign(o,mt(u,p))}}return o},dt=async(t,e={})=>{const{route:o="/",pathname:n,state:r,context:u,prefetch:p=!1}=e,l=n||o,c=globalThis.location,s=globalThis.window;(!globalThis.location||globalThis.location.pathname!==l)&&(globalThis.location={pathname:l,href:l,search:"",hash:"",origin:""}),globalThis.window||(globalThis.window={location:globalThis.location});let i;if(p)try{const h=t.pages||{};i={...h};const O=await Pt(t,o);if(O.size){const V=JSON.parse(JSON.stringify(h[o],(v,N)=>{if(typeof N!="function")return N})),U=(v,N)=>{if(!(!v||!N))for(const D in v)typeof v[D]=="function"?N[D]=v[D]:typeof v[D]=="object"&&v[D]!==null&&!Array.isArray(v[D])&&typeof N[D]=="object"&&N[D]!==null&&U(v[D],N[D])};U(h[o],V),qt(V,O),i[o]=V}}catch(h){console.error("[brender] Prefetch error:",h),i=t.pages}let a;if(p)try{a=await vt(t)}catch(h){console.warn("[brender] SSR translation fetch failed:",h.message)}c!==void 0?globalThis.location=c:delete globalThis.location,s!==void 0?globalThis.window=s:delete globalThis.window;const{window:f,document:g}=st(),T=g.body;f.location.pathname=l;const d=globalThis.document,b=globalThis.location;globalThis.document=g,globalThis.location=f.location;const{createDomqlElement:q}=await Nt(),L=F(t.app||{}),S={...t.config||{}};t.polyglot&&!S.polyglot&&(S.polyglot=t.polyglot),t.fetch&&!S.fetch&&(S.fetch=t.fetch),t.router&&!S.router&&(S.router=t.router);for(const h of["useReset","useVariable","useFontImport","useIconSprite","useSvgSprite","useDefaultConfig","useDocumentTheme"])t[h]!=null&&S[h]==null&&(S[h]=t[h]);const _=S.polyglot?{...S.polyglot}:void 0;a&&_&&(_.translations={..._.translations||{},...a});const j=F(t.state||{});(a||_)&&(j.root||(j.root={}),_&&(j.root.lang=j.root.lang||_.defaultLang||"en"),a&&(j.root.translations={...j.root.translations||{},...a})),Mt();const M={state:j,...r?{state:{...j,...r}}:{},dependencies:F(t.dependencies||{}),components:F(t.components||{}),snippets:F(t.snippets||{}),pages:F(i||t.pages||{}),functions:{...t.functions||{},polyglot:Ft,getActiveLang:lt,getLang:lt},methods:t.methods||{},designSystem:F(t.designSystem||{}),files:t.files||{},sharedLibraries:t.sharedLibraries||[],...S,..._?{polyglot:_}:{},document:g,window:f,parent:{node:T},initOptions:{},domqlOptions:{sourcemap:!1},sync:!1,inspect:!1,notifications:!1,...u||{}},k=await Dt();k&&(M.plugins=M.plugins||[],M.plugins.some(h=>h.name==="funcql")||M.plugins.push(k)),rt();const I=await q(L,M),E=p?2e3:50;await new Promise(h=>setTimeout(h,E)),it(T);const w=ct(I),C=mt(I),R=et(t,o,I,I?.state),x=[],$=g.head||g.querySelector("head");if($)for(const h of $.querySelectorAll("style")){if(h.sheet&&h.sheet.cssRules)for(const O of h.sheet.cssRules)O.cssText&&x.push(O.cssText);if(!x.length){const O=h.textContent||"";O&&x.push(O)}}let A=gt(T.innerHTML);if(a){const h=_?.defaultLang||"en",O=a[h]||Object.values(a)[0]||{};A=A.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g,(V,U)=>{const v=U.trim();return O[v]??V})}return d!==void 0?globalThis.document=d:delete globalThis.document,b!==void 0?globalThis.location=b:delete globalThis.location,{html:A,metadata:R,registry:w,brRegistry:C,element:I,emotionCSS:x,document:g,window:f,ssrTranslations:a,prefetchedPages:i}},ye=async(t,e={})=>{const{context:o={}}=e,{window:n,document:r}=st(),u=r.body,{create:p}=await import("@symbo.ls/element"),l=await import("@symbo.ls/utils"),c={...Bt,...o.components||{}},s={...l,...o.utils||{},...o.functions||{}};rt();let i;try{i=p(t,{node:u},"root",{context:{document:r,window:n,...o,components:c,utils:s}})}catch{}it(u);const a=i?ct(i):{};return{html:gt(u.innerHTML),registry:a,element:i}},gt=t=>t.replace(/(<svg\b[^>]*>)([\s\S]*?)(<\/svg>)/gi,(e,o,n,r)=>{if(n.includes("<")){const u=n.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'");return o+u+r}return e});let J=null;const Wt=["globalTheme","themeStorageKey","themeRoot","useReset","useVariable","useFontImport","useIconSprite","useSvgSprite","useDocumentTheme","useDefaultConfig","useDefaultIcons","useThemeSuffixedVars","verbose","semanticIcons"],ht=t=>{if(!t||typeof t!="object")return null;if(t.config&&typeof t.config=="object")return t.config;const e={};let o=!1;for(const n of Wt)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n],o=!0);return o?e:t.settings||null},bt=(t,e,o)=>{const n=Object.entries(e||{}).map(([r,u])=>`${o} ${r}: ${u}`).join(`;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
${o}
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import{resolve as d,join as At,dirname as T}from"path";import{existsSync as y,unlinkSync as Pt,readFileSync as V,realpathSync as qt}from"fs";import{resolvePackageEntry as It}from"./packageEntry.js";import{tmpdir as vt}from"os";import{randomBytes as Dt}from"crypto";import{createRequire as ot}from"module";import{createEnv as at}from"./env.js";import{resetKeys as ft,assignKeys as ut,mapKeysToElements as pt}from"./keys.js";import{extractMetadata as st,generateHeadHtml as Mt}from"./metadata.js";import"./hydrate.js";import{composeIntoShell as Bt}from"./shell.js";import{prefetchPageData as Ft,injectPrefetchedState as Nt,fetchSSRTranslations as Wt}from"./prefetch.js";import{createEarlySeedScript as Ht}from"@symbo.ls/fetch";let X=null;const Gt=async()=>{if(X)return X;try{return X=(await import("@symbo.ls/funcql")).funcqlPlugin,X}catch{return null}};import"linkedom";import{reset as Jt}from"@symbo.ls/css";const rt=(t,e)=>{if(!t||!e)return;if(t[e]!==void 0)return t[e];const n=e.split(".");let o=t;for(const i of n){if(o==null||typeof o!="object")return;o=o[i]}return o},Kt=function(t,e){if(!t)return"";const n=this?.context,o=n?.polyglot,i=e||o?.defaultLang||"en";if(o?.translations){const a=o.translations[i];if(a){const r=rt(a,t);if(r!==void 0)return r}}const c=this?.state?.root||n?.state?.root;if(c?.translations){const a=c.translations[i];if(a){const r=rt(a,t);if(r!==void 0)return r}}const u=o?.defaultLang||"en";if(u!==i&&o?.translations){const a=o.translations[u];if(a){const r=rt(a,t);if(r!==void 0)return r}}return t},dt=function(){const t=this?.context;return this?.state?.root?.lang||t?.polyglot?.defaultLang||"en"},A=(t,e=new WeakMap)=>{if(t===null||typeof t!="object")return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const o=[];e.set(t,o);for(const i of t)o.push(typeof i=="object"&&i!==null?A(i,e):i);return o}const n={};e.set(t,n);for(const o of Object.keys(t)){const i=t[o];n[o]=typeof i=="object"&&i!==null?A(i,e):i}return n};let F=null;try{import.meta.url&&(F=ot(import.meta.url))}catch{}const zt=()=>{if(!import.meta.url||!F)return{isMonorepo:!1,monorepoRoot:null,resolvePackage:r=>r};const t=qt(new URL(".",import.meta.url).pathname),e=d(t,"../..");if(y(d(e,"packages","smbls","src","createDomql.js")))return{isMonorepo:!0,monorepoRoot:e};let o;try{const r=F.resolve("smbls/package.json");o=T(r)}catch{let r=t;for(;r!==T(r);){const s=d(r,"node_modules","smbls");if(y(d(s,"package.json"))){o=s;break}r=T(r)}}let i=F;if(o)try{i=ot(d(o,"package.json"))}catch{}let c,u=process.cwd();for(;u!==T(u);){if(y(d(u,"package.json"))){c=u;break}u=T(u)}let a=i;if(c)try{a=ot(d(c,"package.json"))}catch{}return{isMonorepo:!1,smblsRoot:o,brenderDir:t,projectRoot:c,_smblsRequire:i,_projectRequire:a}},K=(t,e)=>{const n=t.isMonorepo?[F]:[t._smblsRequire,t._projectRequire,F].filter(Boolean);for(const o of n)try{return o.resolve(e)}catch{}return null},qe=(t,e,...n)=>{if(t.isMonorepo)return d(t.monorepoRoot,"packages",e,...n);const o=K(t,`${e}/package.json`);return o?d(T(o),...n):null},Ie=(t,e,...n)=>{if(t.isMonorepo)return d(t.monorepoRoot,"plugins",e,...n);const o=K(t,`@symbo.ls/${e}/package.json`);return o?d(T(o),...n):null},it=(t,e,...n)=>{if(t.isMonorepo){for(const i of["packages","plugins"]){const c=d(t.monorepoRoot,i,e,...n);if(y(c))return c}return null}const o=K(t,`@symbo.ls/${e}/package.json`);return o?d(T(o),...n):null},mt=(t,e,...n)=>{if(t.isMonorepo)return d(t.monorepoRoot,"packages","domql","packages",e,...n);const o=K(t,`@symbo.ls/${e}/package.json`);return o?d(T(o),...n):null};let N=null;const gt="smbls/ssr",ht=async()=>{const t=await import("smbls/ssr");if(typeof t?.createDomqlElement!="function")throw new Error("smbls/ssr does not export createDomqlElement");return t},Ut=async()=>{if(N)return N;const t=zt();if(!F)try{return N=await ht(),N}catch(a){throw new Error(`brender: ${gt} is not available in this bundled runtime (${a.message}). Bundle smbls \u2265 the release that adds the smbls/ssr export alongside @symbo.ls/brender.`)}let e;if(t.isMonorepo)e=d(t.monorepoRoot,"packages","smbls","src","createDomql.js");else{let a;try{return N=await ht(),N}catch(s){a=s}const r=t.smblsRoot&&d(t.smblsRoot,"src","createDomql.js");if(r&&y(r))e=r;else throw new Error(`brender: cannot load ${gt} (${a.message}). Server rendering needs smbls installed in this project, at a release that exports smbls/ssr`+(t.smblsRoot?` (found smbls at ${t.smblsRoot}).`:" (no smbls package found)."))}const n=await import("esbuild"),o=At(vt(),`br_createDomql_${Dt(6).toString("hex")}.mjs`),i=It,c={name:"workspace-resolve",setup(a){a.onResolve({filter:/^smbls/},r=>{const s=r.path.replace(/^smbls\/?/,""),f=t.isMonorepo?d(t.monorepoRoot,"packages","smbls"):t.smblsRoot;if(!f)return;if(!s){const h=i(f);return h?{path:h}:void 0}const l=d(f,s);if(y(l))return{path:l};if(y(l+".js"))return{path:l+".js"};const p=d(l,"index.js");if(y(p))return{path:p}}),a.onResolve({filter:/^domql$/},r=>{if(t.isMonorepo){const s=d(t.monorepoRoot,"packages","domql","src","index.js");if(y(s))return{path:s};const f=d(t.monorepoRoot,"packages","domql","index.js");if(y(f))return{path:f}}else try{const s=_require.resolve("domql/package.json"),f=i(T(s));if(f)return{path:f}}catch{}}),a.onResolve({filter:/^@symbo\.ls\//},r=>{const s=r.path.replace("@symbo.ls/","");if(s==="sync")return{path:"sync-stub",namespace:"brender-stub"};if(t.isMonorepo){for(const l of["packages","plugins"]){const p=d(t.monorepoRoot,l,s,"src","index.js");if(y(p))return{path:p};const h=d(t.monorepoRoot,l,s,"index.js");if(y(h))return{path:h}}const f=d(t.monorepoRoot,"packages","default-config","blank","index.js");if(s==="default-config"&&y(f))return{path:f}}else{const f=it(t,s,"src","index.js");if(f&&y(f))return{path:f};const l=it(t,s,"index.js");if(l&&y(l))return{path:l};if(s==="default-config"){const p=it(t,"default-config","blank","index.js");if(p&&y(p))return{path:p}}}}),a.onResolve({filter:/^@domql\//},r=>{const s=r.path.replace("@symbo.ls/","");if(t.isMonorepo){const f=d(t.monorepoRoot,"packages","domql","packages",s,"src","index.js");if(y(f))return{path:f};const l=d(t.monorepoRoot,"packages","domql","packages",s,"index.js");if(y(l))return{path:l}}else{const f=mt(t,s,"src","index.js");if(f&&y(f))return{path:f};const l=mt(t,s,"index.js");if(l&&y(l))return{path:l}}}),a.onResolve({filter:/^css-in-props/},r=>{let s;if(t.isMonorepo)s=d(t.monorepoRoot,"packages","css-in-props");else{const p=K(t,"css-in-props/package.json");p&&(s=T(p))}if(!s)return;const f=r.path.replace(/^css-in-props\/?/,"");if(f){const p=d(s,f),h=d(p,"index.js");if(y(h))return{path:h};if(y(p+".js"))return{path:p+".js"};if(y(p))return{path:p}}const l=i(s);if(l)return{path:l}}),a.onResolve({filter:/^@emotion\//},r=>{let s;if(t.isMonorepo)s=d(t.monorepoRoot,"node_modules",r.path);else{const f=K(t,`${r.path}/package.json`);if(!f)return;s=T(f)}if(y(s)){const f=d(s,"package.json");if(y(f))try{const l=JSON.parse(V(f,"utf8")),p=l.module||l.main||"dist/emotion-css.esm.js";return{path:d(s,p)}}catch{}return{path:s}}}),a.onResolve({filter:/\.json$/},r=>{if(r.resolveDir){const s=d(r.resolveDir,r.path);if(y(s))return{path:s}}}),a.onLoad({filter:/smbls\/.*options\.js$/},async r=>{if(!r.path.includes("smbls/")||!r.path.endsWith("options.js"))return;let s=V(r.path,"utf8");return s=s.replace(/import\s*\{[^}]*version[^}]*\}\s*from\s*['"][^'"]*package\.json['"][^;\n]*/,"const version = '0.0.0'"),s=s.replace(/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,"// createRequire removed for brender build"),{contents:s,loader:"js"}}),a.onLoad({filter:/smbls\/.*init\.js$/},async r=>{if(!r.path.includes("smbls/")||!r.path.endsWith("init.js"))return;let s=V(r.path,"utf8");return s=s.replace(/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,"// createRequire removed for brender build"),{contents:s,loader:"js"}}),a.onLoad({filter:/.*/,namespace:"brender-stub"},()=>({contents:"export const SyncComponent = {}; export const Inspect = {}; export const Notifications = {}; export const syncPlugin = () => ({}); export const notificationsPlugin = () => ({}); export const seedRawDesignSystem = () => {}; export const inspectPlugin = () => ({}); export default {}",loader:"js"})),a.onLoad({filter:/smbls\/src\/router\.js$/},async r=>{let s=V(r.path,"utf8");return s=s.replace(/import\s*\{\s*Link\s*\}\s*from\s*['"]smbls['"]/,"const Link = { tag: 'a', attr: { href: (el) => el.href } }"),{contents:s,loader:"js"}}),a.onLoad({filter:/fetchOnCreate\.js$/},async r=>{if(!r.path.includes("smbls/"))return;let s=V(r.path,"utf8");return s=s.replace(/window\s*&&\s*window\.location\s*\?\s*window\.location\.host\.includes/g,"window && window.location && window.location.host ? window.location.host.includes"),{contents:s,loader:"js"}})}};await n.build({entryPoints:[e],bundle:!0,format:"esm",platform:"node",outfile:o,write:!0,logLevel:"warning",plugins:[c],nodePaths:t.isMonorepo?[d(t.monorepoRoot,"node_modules")]:[...t.smblsRoot?[d(t.smblsRoot,"node_modules")]:[],...t.projectRoot?[d(t.projectRoot,"node_modules")]:[],...t.smblsRoot?[d(t.smblsRoot,"..","..","node_modules")]:[]].filter(a=>y(a)),supported:{"import-attributes":!1},external:["fs","path","os","crypto","url","http","https","stream","util","events","buffer","child_process","worker_threads","net","tls","dns","dgram","zlib","assert","querystring","string_decoder","readline","perf_hooks","async_hooks","v8","vm","cluster","inspector","module","process","tty","color-contrast-checker","linkedom"]});const u=await import(`file://${o}`);if(process.env.BRENDER_DEBUG)console.log("[brender] Bundle saved:",o);else try{Pt(o)}catch{}return N=u,u},Yt={Box:{},Focusable:{},Block:{display:"block"},Inline:{display:"inline"},Flex:{display:"flex"},InlineFlex:{display:"inline-flex"},Grid:{display:"grid"},InlineGrid:{display:"inline-grid"},Link:{tag:"a",attr:{href:t=>t.href,target:t=>t.target,rel:t=>t.rel}},A:{extends:"Link"},RouteLink:{extends:"Link"},Img:{tag:"img",attr:{src:t=>{let e=t.src;return typeof e=="string"&&e.includes("{{")&&(e=t.call("replaceLiteralsWithObjectFields",e,t.state)),e},alt:t=>t.alt,loading:t=>t.loading}},Image:{extends:"Img"},Button:{tag:"button"},FocusableComponent:{tag:"button"},Form:{tag:"form"},Input:{tag:"input"},TextArea:{tag:"textarea"},Textarea:{tag:"textarea"},Select:{tag:"select"},Label:{tag:"label"},Iframe:{tag:"iframe"},Video:{tag:"video"},Audio:{tag:"audio"},Canvas:{tag:"canvas"},Span:{tag:"span"},P:{tag:"p"},H1:{tag:"h1"},H2:{tag:"h2"},H3:{tag:"h3"},H4:{tag:"h4"},H5:{tag:"h5"},H6:{tag:"h6"},Svg:{tag:"svg",attr:{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}},Text:{tag:"span"}},yt=(t,e="")=>{if(!t||!t.__ref)return{};const n={},o=t.__ref.__brKey;if(o&&(n[e===""?"__root":e]=o),t.__ref.__children)for(const i of t.__ref.__children){const c=t[i];if(c&&c.__ref){const u=e===""?i:`${e}.${i}`;Object.assign(n,yt(c,u))}}return n};let z=0;const bt=Symbol.for("brender.fetchTracked"),St=()=>z,Vt=256*1024,Xt=1024*1024,Zt=new Set(["accept-language","accept"]);let lt=0,q=null;const Qt=t=>{const[e,n]=t,o=e&&typeof e=="object"&&typeof e.url=="string",i=o?e.url:String(e),c=String(n&&n.method||o&&e.method||"GET").toUpperCase(),u={},a=r=>{if(r)if(typeof r.forEach=="function"&&!Array.isArray(r))r.forEach((s,f)=>{u[String(f).toLowerCase()]=String(s)});else if(Array.isArray(r))for(const[s,f]of r)u[String(s).toLowerCase()]=String(f);else for(const s in r)r[s]!=null&&(u[s.toLowerCase()]=String(r[s]))};return o&&a(e.headers),n&&a(n.headers),{url:i,method:c,headers:u}},te=(t,e,n,o)=>{if(!n||!n.ok||typeof n.clone!="function")return;const i=n.headers&&n.headers.get&&n.headers.get("content-type")||"";if(!/json|^text\//i.test(i))return;let c;try{c=n.clone()}catch{return}o(c.text().then(u=>{t.tainted||u.length>Vt||t.bytes+u.length>Xt||(t.bytes+=u.length,t.entries.push({url:e.url,lang:e.headers["accept-language"]||"",status:n.status,type:i,body:u}))},()=>{}))},ee=()=>{const t=globalThis.fetch;if(typeof t!="function"||t[bt])return;const e=function(...n){z++;let o=!1;const i=()=>{o||(o=!0,z--)},c=s=>{z++,s.then(()=>{z--},()=>{z--})},u=q&&!q.tainted?q:null;let a=null;if(u)try{a=Qt(n),(a.method!=="GET"||!/^https?:/i.test(a.url)||Object.keys(a.headers).some(s=>!Zt.has(s)))&&(a=null)}catch{a=null}let r;try{r=t.apply(this,n)}catch(s){throw i(),s}return r&&typeof r.then=="function"?r.then(s=>{a&&te(u,a,s,c),i()},i):i(),r};e[bt]=!0,globalThis.fetch=e},ct=({brRegistry:t,fetchSeed:e}={})=>!t||!Object.keys(t).length?"":`<script>window.__BR_REGISTRY__=${JSON.stringify(t).replace(/</g,"\\u003c")};window.__BRENDER_HYDRATE__=true<\/script>`+(e&&e.length?`
|
|
2
|
+
`+Ht(e):""),wt=async(t,e={})=>{const{route:n="/",pathname:o,state:i,context:c,prefetch:u=!1}=e,a=o||n,r=globalThis.location,s=globalThis.window;(!globalThis.location||globalThis.location.pathname!==a)&&(globalThis.location={pathname:a,href:a,search:"",hash:"",origin:""}),globalThis.window||(globalThis.window={location:globalThis.location});let f;if(u)try{const g=t.pages||{};f={...g};const b=await Ft(t,n);if(b.size){const P=JSON.parse(JSON.stringify(g[n],(C,D)=>{if(typeof D!="function")return D})),J=(C,D)=>{if(!(!C||!D))for(const O in C)typeof C[O]=="function"?D[O]=C[O]:typeof C[O]=="object"&&C[O]!==null&&!Array.isArray(C[O])&&typeof D[O]=="object"&&D[O]!==null&&J(C[O],D[O])};J(g[n],P),Nt(P,b),f[n]=P}}catch(g){console.error("[brender] Prefetch error:",g),f=t.pages}let l;if(u)try{l=await Wt(t)}catch(g){console.warn("[brender] SSR translation fetch failed:",g.message)}r!==void 0?globalThis.location=r:delete globalThis.location,s!==void 0?globalThis.window=s:delete globalThis.window;const{window:p,document:h}=at(),S=h.body;p.location.pathname=a;const w=globalThis.document,m=globalThis.location;globalThis.document=h,globalThis.location=p.location;const{createDomqlElement:R}=await Ut(),E=A(t.app||{}),x={...t.config||{}};t.polyglot&&!x.polyglot&&(x.polyglot=t.polyglot),t.fetch&&!x.fetch&&(x.fetch=t.fetch),t.router&&!x.router&&(x.router=t.router);for(const g of ne)t[g]!=null&&x[g]==null&&(x[g]=t[g]);const _=x.polyglot?{...x.polyglot}:void 0;l&&_&&(_.translations={..._.translations||{},...l});const j=A(t.state||{});(l||_)&&(j.root||(j.root={}),_&&(j.root.lang=j.root.lang||_.defaultLang||"en"),l&&(j.root.translations={...j.root.translations||{},...l})),Jt();const W={};for(const g in t){if(g==="app"||g==="config"||g==="pages"||g==="components"||g==="state"||g==="snippets"||g==="designSystem"||g==="dependencies")continue;const b=t[g];W[g]=b&&typeof b=="object"?A(b):b}const H={...W,state:j,...i?{state:{...j,...i}}:{},dependencies:A(t.dependencies||{}),components:A(t.components||{}),snippets:A(t.snippets||{}),pages:A(f||t.pages||{}),functions:{...t.functions||{},polyglot:Kt,getActiveLang:dt,getLang:dt},methods:t.methods||{},designSystem:A(t.designSystem||{}),files:t.files||{},sharedLibraries:t.sharedLibraries||[],...x,..._?{polyglot:_}:{},document:h,window:p,parent:{node:S},initOptions:{},domqlOptions:{sourcemap:!1},sync:!1,inspect:!1,notifications:!1,...c||{}},k=await Gt();k&&(H.plugins=H.plugins||[],H.plugins.some(g=>g.name==="funcql")||H.plugins.push(k)),ft(),ee(),lt++,lt===1?q={entries:[],bytes:0,tainted:!1}:q&&(q.tainted=!0);const L=q;let $;try{$=await R(E,H);const g=Date.now(),b=u?2e3:50,P=J=>new Promise(C=>setTimeout(C,J));for(await P(Math.min(50,b));u&&St()>0&&Date.now()-g<b;){for(;St()>0&&Date.now()-g<b;)await P(10);await P(Math.max(0,Math.min(50,b-(Date.now()-g))))}}finally{lt--,q===L&&(q=null)}const G=L&&!L.tainted?L.entries.slice():[];ut(S);const U=pt($),M=yt($),et=st(t,n,$,$?.state),I=[],v=[],B=h.head||h.querySelector("head");if(B)for(const g of B.querySelectorAll("style")){if(g.sheet&&g.sheet.cssRules)for(const b of g.sheet.cssRules)b.cssText&&(I.push(b.cssText),v.push(b));if(!I.length){const b=g.textContent||"";b&&(I.push(b),v.push({cssText:b}))}}const{globalCSS:Y,classRules:Ot}=ie(v);let nt=Rt(S.innerHTML);if(l){const g=_?.defaultLang||"en",b=l[g]||Object.values(l)[0]||{};nt=nt.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g,(P,J)=>{const C=J.trim();return b[C]??P})}return w!==void 0?globalThis.document=w:delete globalThis.document,m!==void 0?globalThis.location=m:delete globalThis.location,{html:nt,metadata:et,registry:U,brRegistry:M,element:$,emotionCSS:I,globalCSS:Y,classRules:Ot,fetchSeed:G,document:h,window:p,ssrTranslations:l,prefetchedPages:f}},ve=async(t,e={})=>{const{context:n={}}=e,{window:o,document:i}=at(),c=i.body,{create:u}=await import("@symbo.ls/element"),a=await import("@symbo.ls/utils"),r={...Yt,...n.components||{}},s={...a,...n.utils||{},...n.functions||{}};ft();let f;try{f=u(t,{node:c},"root",{context:{document:i,window:o,...n,components:r,utils:s}})}catch{}ut(c);const l=f?pt(f):{};return{html:Rt(c.innerHTML),registry:l,element:f}},Rt=t=>t.replace(/(<svg\b[^>]*>)([\s\S]*?)(<\/svg>)/gi,(e,n,o,i)=>{if(o.includes("<")){const c=o.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'");return n+c+i}return e}),ne=["globalTheme","themeStorageKey","themeRoot","useReset","useVariable","useFontImport","useIconSprite","useSvgSprite","useDocumentTheme","useDefaultConfig","useDefaultIcons","useThemeSuffixedVars","verbose","semanticIcons"],xt=(t,e,n)=>{const o=Object.entries(e||{}).map(([i,c])=>`${n} ${i}: ${c}`).join(`;
|
|
3
|
+
`);return o?`${n}${t} {
|
|
4
|
+
${o};
|
|
5
|
+
${n}}`:""},De=t=>Object.entries(t||{}).map(([e,n])=>{if(!e.startsWith("@"))return xt(e,n,"");const o=Object.entries(n||{}).map(([i,c])=>xt(i,c," ")).filter(Boolean).join(`
|
|
6
|
+
`);return o?`${e} {
|
|
7
|
+
${o}
|
|
7
8
|
}`:""}).filter(Boolean).join(`
|
|
8
9
|
|
|
9
|
-
`),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import * as scratchNs from '@symbo.ls/scratch'
|
|
15
|
-
import { DEFAULT_CONFIG } from '@symbo.ls/default-config'
|
|
16
|
-
|
|
17
|
-
const ds = ${c}
|
|
18
|
-
const cfg = ${s}
|
|
19
|
-
|
|
20
|
-
// Merge with defaults (same as initEmotion)
|
|
21
|
-
const merged = {}
|
|
22
|
-
for (const k in DEFAULT_CONFIG) merged[k] = DEFAULT_CONFIG[k]
|
|
23
|
-
for (const k in ds) {
|
|
24
|
-
if (typeof ds[k] === 'object' && !Array.isArray(ds[k]) && typeof merged[k] === 'object' && !Array.isArray(merged[k])) {
|
|
25
|
-
merged[k] = { ...merged[k], ...ds[k] }
|
|
26
|
-
} else {
|
|
27
|
-
merged[k] = ds[k]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const conf = set({
|
|
32
|
-
useReset: true,
|
|
33
|
-
useVariable: true,
|
|
34
|
-
useFontImport: true,
|
|
35
|
-
useDocumentTheme: true,
|
|
36
|
-
useDefaultConfig: true,
|
|
37
|
-
globalTheme: 'auto',
|
|
38
|
-
...merged,
|
|
39
|
-
...cfg
|
|
40
|
-
}, { newConfig: {} })
|
|
41
|
-
|
|
42
|
-
const result = {
|
|
43
|
-
CSS_VARS: conf.CSS_VARS || {},
|
|
44
|
-
CSS_MEDIA_VARS: conf.CSS_MEDIA_VARS || {},
|
|
45
|
-
// Skin rules \u2014 the same builder smbls init() injects on the client
|
|
46
|
-
// (FW-SCRATCH-SKINS-DIMENSION-1).
|
|
47
|
-
CSS_SKIN_RULES: typeof scratchNs.buildSkinVarStyles === 'function'
|
|
48
|
-
? scratchNs.buildSkinVarStyles(conf.cssSkinVars, conf.cssSkinFallback, ':root')
|
|
49
|
-
: {},
|
|
50
|
-
reset: conf.reset || {},
|
|
51
|
-
animation: conf.animation || {}
|
|
52
|
-
}
|
|
53
|
-
// Export as globalThis so we can read it
|
|
54
|
-
globalThis.__BR_GLOBAL_CSS__ = result
|
|
55
|
-
export default result
|
|
56
|
-
`);const f=ft(),g={name:"workspace-resolve",setup(w){w.onResolve({filter:/^@symbo\.ls\//},C=>{const R=C.path.replace("@symbo.ls/","");if(f.isMonorepo){for(const $ of["packages","plugins"]){const A=m(f.monorepoRoot,$,R,"src","index.js");if(o(A))return{path:A};const h=m(f.monorepoRoot,$,R,"index.js");if(o(h))return{path:h}}const x=m(f.monorepoRoot,"packages","default-config","blank","index.js");if(R==="default-config"&&o(x))return{path:x}}}),w.onResolve({filter:/^@domql\//},C=>{const R=C.path.replace("@symbo.ls/","");if(f.isMonorepo){const x=m(f.monorepoRoot,"packages","domql","packages",R,"src","index.js");if(o(x))return{path:x}}else{const x=Y(f,R,"src","index.js");if(x&&o(x))return{path:x};const $=Y(f,R,"index.js");if($&&o($))return{path:$}}})}};await l.build({entryPoints:[i],bundle:!0,format:"esm",platform:"node",outfile:a,write:!0,logLevel:"silent",plugins:[g],nodePaths:f.isMonorepo?[m(f.monorepoRoot,"node_modules")]:[...f.smblsRoot?[m(f.smblsRoot,"node_modules")]:[],...f.projectRoot?[m(f.projectRoot,"node_modules")]:[],...f.smblsRoot?[m(f.smblsRoot,"..","..","node_modules")]:[]].filter(w=>o(w)),external:["fs","path","os","crypto","url","http","https","stream","util","events","buffer","child_process","worker_threads","net","tls","dns","dgram","zlib","assert","querystring","string_decoder","readline","perf_hooks","async_hooks","v8","vm","cluster","inspector","module","process","tty","color-contrast-checker"]});const d=(await import(`file://${a}`)).default||{};try{r(i)}catch{}try{r(a)}catch{}const b=d.CSS_VARS||{},q=d.CSS_MEDIA_VARS||{},L=d.RESET||{},S=d.ANIMATION||{},_=Object.entries(b).map(([w,C])=>` ${w}: ${C}`).join(`;
|
|
57
|
-
`);let j=_?`:root {
|
|
58
|
-
${_};
|
|
59
|
-
}`:"";const M=Object.entries(q).map(([w,C])=>{const R=Object.entries(C).map(([x,$])=>` ${x}: ${$}`).join(`;
|
|
60
|
-
`);return R?w.startsWith("@media")?`${w} {
|
|
61
|
-
:root:not([data-theme]) {
|
|
62
|
-
${R};
|
|
63
|
-
}
|
|
64
|
-
}`:`${w} {
|
|
65
|
-
${R};
|
|
66
|
-
}`:""}).filter(Boolean).join(`
|
|
67
|
-
|
|
68
|
-
`);M&&(j+=`
|
|
69
|
-
|
|
70
|
-
`+M);const k=Jt(d.CSS_SKIN_RULES);k&&(j+=(j?`
|
|
71
|
-
|
|
72
|
-
`:"")+k);const I=kt(L),E=[];for(const w in S){const C=S[w];if(!C||typeof C!="object")continue;const R=Object.entries(C).map(([x,$])=>{if(typeof $!="object")return"";const A=Object.entries($).map(([h,O])=>`${G(h)}: ${O}`).join("; ");return` ${x} { ${A}; }`}).join(`
|
|
73
|
-
`);E.push(`@keyframes ${w} {
|
|
74
|
-
${R}
|
|
75
|
-
}`)}return J={rootRule:j,resetRules:I,fontFaceCSS:"",keyframeRules:E.join(`
|
|
76
|
-
`)},J}catch(o){return console.warn("generateGlobalCSS failed:",o.message,o.stack),J={rootRule:"",resetRules:"",fontFaceCSS:"",keyframeRules:""},J}};let Z=new Set;const Se=()=>{J=null,Z=new Set},Re=()=>Array.from(Z).join(`
|
|
77
|
-
`),je=(t,e)=>t.replace(/<style data-emotion="smbls">[\s\S]*?<\/style>/,e?`<style data-emotion="smbls">
|
|
10
|
+
`),oe=/\.[A-Za-z_\\-]/,se=t=>{if(typeof t!="string"||!t)return!1;const e=t.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g,'""').replace(/\[[^\]]*\]/g,"[]");return!oe.test(e)},re=/^\s*(:root|\[data-theme|\[data-skin)/,_t=t=>{const e=t&&t.cssText;if(typeof e!="string")return null;if(/^@(-webkit-)?keyframes\b/.test(e))return"keyframes";if(e.startsWith("@font-face"))return null;if(typeof t.selectorText=="string")return se(t.selectorText)?re.test(t.selectorText)?"root":"reset":null;const n=t.cssRules&&Array.from(t.cssRules);if(n&&n.length&&/^@(media|supports|container)\b/.test(e)){const o=new Set(n.map(_t));return o.has(null)||o.size!==1?o.has(null)?null:"reset":[...o][0]}return null},ie=t=>{const e={root:[],reset:[],keyframes:[]},n=[];for(const o of t||[]){const i=_t(o);i?e[i].push(o.cssText):o&&o.cssText&&n.push(o.cssText)}return{globalCSS:{rootRule:e.root.join(`
|
|
11
|
+
`),resetRules:e.reset.join(`
|
|
12
|
+
`),keyframeRules:e.keyframes.join(`
|
|
13
|
+
`),fontFaceCSS:""},classRules:n}};let Z=new Set;const Me=()=>{Z=new Set},Be=()=>Array.from(Z).join(`
|
|
14
|
+
`),Fe=(t,e)=>t.replace(/<style data-emotion="smbls">[\s\S]*?<\/style>/,e?`<style data-emotion="smbls">
|
|
78
15
|
${e}
|
|
79
|
-
</style>`:""),
|
|
80
|
-
`):
|
|
81
|
-
`),
|
|
82
|
-
`)}const
|
|
83
|
-
`:""
|
|
84
|
-
|
|
16
|
+
</style>`:""),Ne=async(t,e={})=>{const{route:n="/",pathname:o,prefetch:i=!0}=e,c=await wt(t,{route:n,pathname:o,prefetch:i});if(!c)return null;const u=t.designSystem||{},a=c.globalCSS;let r=null,s=null;try{const f=c.element,l=f?.context?.polyglot||t.polyglot||t.config?.polyglot;if(s=f?.state?.root?.lang||l?.defaultLang||"en",c.prefetchedPages&&c.prefetchedPages[n]){const p=c.prefetchedPages[n],h=(S,w={})=>{if(!S||typeof S!="object")return w;if(S.state&&typeof S.state=="object")for(const[m,R]of Object.entries(S.state))R!=null&&typeof R!="function"&&(w[m]=R);for(const[m,R]of Object.entries(S))m==="state"||m==="props"||m==="attr"||m==="on"||m==="define"||m==="__ref"||m.startsWith("__")||R&&typeof R=="object"&&!Array.isArray(R)&&h(R,w);return w};r=h(p)}}catch{}return{html:c.html,css:c.classRules.join(`
|
|
17
|
+
`),classRules:c.classRules.slice(),globalCSS:a,resetCss:a.resetRules,fontLinks:Lt(u),metadata:c.metadata||st(t,n),brKeyCount:c.registry?Object.keys(c.registry).length:0,brRegistry:c.brRegistry||{},fetchSeed:c.fetchSeed||[],ssrTranslations:c.ssrTranslations,prefetchedState:r,activeLang:s}},We=async(t,e="/",n={})=>{const{lang:o,themeColor:i,isr:c,hydrate:u=!0,prefetch:a=!0,shell:r,adoptDom:s=!1}=n,f=o||t.state?.lang||t.app?.metadata?.lang||"en",l=await wt(t,{route:e,prefetch:a});if(!l)return null;const p={...l.metadata};if(i&&(p["theme-color"]=i),typeof r=="string"&&!t.name){const k="\0brender-undeclared-title\0";if(st({...t,name:k},e,l.element,l.element?.state).title===k)for(const $ of["title","og:title","twitter:title"])p[$]===l.metadata.title&&delete p[$]}const h=Mt(p);for(const k of l.classRules)k&&Z.add(k);const S=Array.from(Z).join(`
|
|
18
|
+
`),w=t.designSystem||{},m=l.globalCSS,R=Lt(w),E=Object.keys(l.registry).length;let x="";if(c&&c.clientScript){const k=Number.isInteger(n.depth)?n.depth:e==="/"?0:e.replace(/^\/|\/$/g,"").split("/").length,L=k>0?"../".repeat(k):"./";if(u){let $="";if(l.ssrTranslations){const M=t.polyglot||t.config?.polyglot,et=M?.storagePrefix||"",I=M?.storageLangKey||"",v=[];for(const B in l.ssrTranslations){const Y=l.ssrTranslations[B];Y&&typeof Y=="object"&&v.push(`localStorage.setItem(${JSON.stringify(et+B)},${JSON.stringify(JSON.stringify(Y))})`)}if(I){const B=M?.defaultLang||"en";v.push(`if(!localStorage.getItem(${JSON.stringify(I)}))localStorage.setItem(${JSON.stringify(I)},${JSON.stringify(B)})`)}v.length&&($=`<script>try{${v.join(";")}}catch(e){}<\/script>
|
|
19
|
+
`)}const G=l.brRegistry&&Object.keys(l.brRegistry).length?JSON.stringify(l.brRegistry):null,U=s?ct(l)?ct(l)+`
|
|
20
|
+
`:"":G?`<script>window.__BR_REGISTRY__=${G}<\/script>
|
|
21
|
+
`:"";x=`${$}${U}<script>window.__BRENDER__=true<\/script>
|
|
22
|
+
<script type="module" src="${L}${c.clientScript}"><\/script>`}else x=`<script type="module">
|
|
85
23
|
{
|
|
86
24
|
const brEls = document.querySelectorAll('body > :not(script):not(style)')
|
|
87
25
|
const observer = new MutationObserver((mutations) => {
|
|
@@ -98,37 +36,36 @@ ${e}
|
|
|
98
36
|
observer.observe(document.body, { childList: true })
|
|
99
37
|
}
|
|
100
38
|
<\/script>
|
|
101
|
-
<script type="module" src="${
|
|
102
|
-
${
|
|
103
|
-
${
|
|
104
|
-
${
|
|
105
|
-
</style>`,
|
|
106
|
-
${
|
|
107
|
-
</style>`:""];return{html:
|
|
108
|
-
`),body:
|
|
109
|
-
<html lang="${
|
|
39
|
+
<script type="module" src="${L}${c.clientScript}"><\/script>`}const _={...t.config||{}};t.polyglot&&!_.polyglot&&(_.polyglot=t.polyglot);const j=_.polyglot;let W=h;if(j){const k=j.defaultLang||"en",$={...j.translations||{},...l.ssrTranslations||{}}[k]||{};W=h.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g,(G,U)=>{const M=U.trim();return $[M]??G})}if(typeof r=="string"){const k=[m.fontFaceCSS?`<style data-brender>${m.fontFaceCSS}</style>`:"",`<style data-brender>
|
|
40
|
+
${m.rootRule||""}
|
|
41
|
+
${m.resetRules||""}
|
|
42
|
+
${m.keyframeRules||""}
|
|
43
|
+
</style>`,S?`<style data-emotion="smbls">
|
|
44
|
+
${S}
|
|
45
|
+
</style>`:""];return{html:Bt(r,{headTags:W,headEnd:[R,...k].filter(Boolean).join(`
|
|
46
|
+
`),body:l.html,depth:Number.isInteger(n.depth)?n.depth:0,bootScripts:s?ct(l):""}),route:e,brKeyCount:E,shell:!0}}return{html:`<!DOCTYPE html>
|
|
47
|
+
<html lang="${f}">
|
|
110
48
|
<head>
|
|
111
|
-
${
|
|
112
|
-
${
|
|
113
|
-
${
|
|
114
|
-
<style>
|
|
115
|
-
${
|
|
116
|
-
${
|
|
117
|
-
${
|
|
49
|
+
${W}
|
|
50
|
+
${R}
|
|
51
|
+
${m.fontFaceCSS?`<style data-brender>${m.fontFaceCSS}</style>`:""}
|
|
52
|
+
<style data-brender>
|
|
53
|
+
${m.rootRule||""}
|
|
54
|
+
${m.resetRules||""}
|
|
55
|
+
${m.keyframeRules||""}
|
|
118
56
|
</style>
|
|
119
|
-
${
|
|
120
|
-
${
|
|
57
|
+
${S?`<style data-emotion="smbls">
|
|
58
|
+
${S}
|
|
121
59
|
</style>`:""}
|
|
122
60
|
</head>
|
|
123
61
|
<body>
|
|
124
|
-
${
|
|
125
|
-
${
|
|
62
|
+
${l.html}
|
|
63
|
+
${x}
|
|
126
64
|
</body>
|
|
127
|
-
</html>`,route:e,brKeyCount:
|
|
128
|
-
`)},
|
|
129
|
-
`);
|
|
130
|
-
${
|
|
131
|
-
}`)}return[...
|
|
132
|
-
`)},
|
|
133
|
-
`)
|
|
134
|
-
`):""};export{ut as SMBLS_SSR_SPECIFIER,Re as getAccumulatedEmotionCSS,dt as render,ye as renderElement,xe as renderPage,we as renderRoute,je as replaceEmotionCSS,Se as resetGlobalCSSCache,Jt as skinRulesToCSS};
|
|
65
|
+
</html>`,route:e,brKeyCount:E}},le={U:-6,V:-5,W:-4,X:-3,Y:-2,Z:-1,A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15},jt=new Set(["padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingBlock","paddingInline","paddingBlockStart","paddingBlockEnd","paddingInlineStart","paddingInlineEnd","margin","marginTop","marginRight","marginBottom","marginLeft","marginBlock","marginInline","marginBlockStart","marginBlockEnd","marginInlineStart","marginInlineEnd","gap","rowGap","columnGap","top","right","bottom","left","width","height","minWidth","maxWidth","minHeight","maxHeight","flexBasis","fontSize","lineHeight","letterSpacing","borderWidth","borderRadius","outlineWidth","outlineOffset","inset","insetBlock","insetInline","boxSize","round"]),kt=(t,e)=>{if(!t||typeof t!="string"||!e)return null;const n=e.base||16,o=e.ratio||1.618,i=e.unit||"px",c=e.subSequence!==!1;if(t.includes(" "))return t.split(" ").map(m=>m==="-"||m===""?m:kt(m,e)||m).join(" ");if(/^(none|auto|inherit|initial|unset|0)$/i.test(t)||/\d+(px|em|rem|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr|s|ms)$/i.test(t)||/^(#|rgb|hsl|var\()/i.test(t))return null;const u=t.startsWith("-"),r=(u?t.slice(1):t).match(/^([A-Z])(\d)?$/i);if(!r)return null;const s=r[1].toUpperCase(),f=r[2]?parseInt(r[2]):0,l=le[s];if(l===void 0)return null;let p=n*Math.pow(o,l);if(f>0&&c){const w=n*Math.pow(o,l+1),R=(w-p)/o,E=w-R,x=p+R,_=(E+x)/2,j=~~w-~~p>16?[E,_,x]:[E,x];f<=j.length&&(p=j[f-1])}const h=Math.round(p*100)/100;return`${u?"-":""}${h}${i}`},ce=new Set([...jt].map(t=>t.replace(/[A-Z]/g,e=>"-"+e.toLowerCase()))),Q=(t,e,n)=>{if(typeof e!="string")return e;if(ae.has(t)){const o=n?.color||{};if(o[e])return o[e]}if(jt.has(t)||ce.has(t)){const o=n?.spacing||{},i=kt(e,o);if(i)return i}return e},ae=new Set(["color","background","backgroundColor","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","outlineColor","fill","stroke"]),$t=new Set(["href","src","alt","title","id","name","type","value","placeholder","target","rel","loading","srcset","sizes","media","role","tabindex","for","action","method","enctype","autocomplete","autofocus","theme","__element","update","childrenAs","childExtends","childProps","children"]),tt=t=>t.replace(/[A-Z]/g,e=>"-"+e.toLowerCase()),Ct=(t,e)=>{if(typeof e>"u"||e===null)return null;if(t==="flow"&&typeof e=="string"){let[n,o]=(e||"row").split(" ");return(e.startsWith("x")||e==="row")&&(n="row"),(e.startsWith("y")||e==="column")&&(n="column"),{display:"flex","flex-flow":(n||"")+" "+(o||"")}}if(t==="wrap")return{display:"flex","flex-wrap":e};if((t==="align"||t==="flexAlign")&&typeof e=="string"){const[n,o]=e.split(" "),i={display:"flex","align-items":n};return o&&(i["justify-content"]=o),i}if(t==="gridAlign"&&typeof e=="string"){const[n,o]=e.split(" "),i={display:"grid","align-items":n};return o&&(i["justify-content"]=o),i}if(t==="flexFlow"&&typeof e=="string"){let[n,o]=(e||"row").split(" ");return(e.startsWith("x")||e==="row")&&(n="row"),(e.startsWith("y")||e==="column")&&(n="column"),{display:"flex","flex-flow":(n||"")+" "+(o||"")}}if(t==="flexWrap")return{display:"flex","flex-wrap":e};if(t==="backgroundImage"&&typeof e=="string"&&!e.startsWith("url(")&&!e.startsWith("linear-gradient")&&!e.startsWith("radial-gradient")&&!e.startsWith("none"))return{"background-image":`url(${e})`};if(t==="round"||t==="borderRadius"&&e)return{"border-radius":typeof e=="number"?e+"px":e};if(t==="boxSize"&&typeof e=="string"){const[n,o]=e.split(" ");return{height:n,width:o||n}}if(t==="widthRange"&&typeof e=="string"){const[n,o]=e.split(" ");return{"min-width":n,"max-width":o||n}}if(t==="heightRange"&&typeof e=="string"){const[n,o]=e.split(" ");return{"min-height":n,"max-height":o||n}}return t==="column"?{"grid-column":e}:t==="columns"?{"grid-template-columns":e}:t==="templateColumns"?{"grid-template-columns":e}:t==="row"?{"grid-row":e}:t==="rows"?{"grid-template-rows":e}:t==="templateRows"?{"grid-template-rows":e}:t==="area"?{"grid-area":e}:t==="template"?{"grid-template":e}:t==="templateAreas"?{"grid-template-areas":e}:t==="autoColumns"?{"grid-auto-columns":e}:t==="autoRows"?{"grid-auto-rows":e}:t==="autoFlow"?{"grid-auto-flow":e}:t==="columnStart"?{"grid-column-start":e}:t==="rowStart"?{"grid-row-start":e}:null},Tt=(t,e)=>{const n={};for(const o in t){const i=t[o],c=Ct(o,i);if(c){for(const u in c)n[u]=Q(u,c[u],e);continue}typeof i!="string"&&typeof i!="number"||(n[tt(o)]=Q(o,i,e))}return n},fe=(t,e,n)=>{const o={},i={},c={};for(const u in t){const a=t[u];if(u.charCodeAt(0)===64&&typeof a=="object"){const s=n?.[u.slice(1)];if(s){const f=Tt(a,e);Object.keys(f).length&&(i[s]=f)}continue}if(u.charCodeAt(0)===58&&typeof a=="object"){const s=Tt(a,e);Object.keys(s).length&&(c[u]=s);continue}if(typeof a!="string"&&typeof a!="number"||u.charCodeAt(0)>=65&&u.charCodeAt(0)<=90||$t.has(u))continue;const r=Ct(u,a);if(r){for(const s in r)o[s]=Q(s,r[s],e);continue}o[tt(u)]=Q(u,a,e)}return{base:o,mediaRules:i,pseudoRules:c}},ue=(t,{base:e,mediaRules:n,pseudoRules:o})=>{const i=[],c=Object.entries(e).map(([u,a])=>`${u}: ${a}`).join("; ");c&&i.push(`${t} { ${c}; }`);for(const[u,a]of Object.entries(o)){const r=Object.entries(a).map(([s,f])=>`${s}: ${f}`).join("; ");r&&i.push(`${t}${u} { ${r}; }`)}for(const[u,a]of Object.entries(n)){const r=Object.entries(a).map(([f,l])=>`${f}: ${l}`).join("; "),s=u.startsWith("@")?u:`@media ${u}`;r&&i.push(`${s} { ${t} { ${r}; } }`)}return i.join(`
|
|
66
|
+
`)},Et={Flex:{display:"flex"},InlineFlex:{display:"inline-flex"},Grid:{display:"grid"},InlineGrid:{display:"inline-grid"},Block:{display:"block"},Inline:{display:"inline"}},pe=t=>{const e=t.__ref?.__extends;if(!e||!Array.isArray(e))return null;for(const n of e)if(Et[n])return Et[n];return null},de=t=>{let e;for(const n in t){if(typeof t[n]!="function"||$t.has(n)||n.charCodeAt(0)>=65&&n.charCodeAt(0)<=90||n.startsWith("on")||n.startsWith("__"))continue;e||(e={});let o;try{o=t[n](t,t.state||{})}catch{try{const i={root:{},...t.state||{}};o=t[n](t,i)}catch{}}o!=null&&o!==!1&&(e[n]=o)}return e||t},He=(t,e)=>{const n=e?.media||{},o=e?.animation||{},i=[],c=new Set,u=new Set,a=s=>{if(!s||!s.__ref)return;const f=de(s);if(f&&s.node){const l=s.node.getAttribute?.("class");if(l&&!c.has(l)){c.add(l);const p=fe(f,e,n),h=pe(s);if(h)for(const[m,R]of Object.entries(h)){const E=tt(m);p.base[E]||(p.base[E]=R)}(Object.keys(p.base).length||Object.keys(p.mediaRules).length||Object.keys(p.pseudoRules).length)&&i.push(ue("."+l.split(" ")[0],p));const w=f.animation||f.animationName;if(typeof w=="string"){const m=w.split(" ")[0];o[m]&&u.add(m)}}}if(s.__ref?.__children)for(const l of s.__ref.__children)s[l]?.__ref&&a(s[l])};a(t);const r=[];for(const s of u){const f=o[s],l=Object.entries(f).map(([p,h])=>{const S=Object.entries(h).map(([w,m])=>`${tt(w)}: ${m}`).join("; ");return` ${p} { ${S}; }`}).join(`
|
|
67
|
+
`);r.push(`@keyframes ${s} {
|
|
68
|
+
${l}
|
|
69
|
+
}`)}return[...r,...i].join(`
|
|
70
|
+
`)},Lt=t=>{if(!t)return"";const e=t.font_family||t.fontFamily||{},n=new Set;for(const i of Object.values(e)){if(typeof i!="string")continue;const c=i.match(/'([^']+)'/);c&&n.add(c[1])}return n.size?['<link rel="preconnect" href="https://fonts.googleapis.com">','<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>',`<link href="https://fonts.googleapis.com/css2?${[...n].map(i=>`family=${i.replace(/\s+/g,"+")}:wght@300;400;500;600;700`).join("&")}&display=swap" rel="stylesheet">`].join(`
|
|
71
|
+
`):""};export{gt as SMBLS_SSR_SPECIFIER,ct as adoptionScripts,Be as getAccumulatedEmotionCSS,wt as render,ve as renderElement,We as renderPage,Ne as renderRoute,Fe as replaceEmotionCSS,Me as resetGlobalCSSCache,De as skinRulesToCSS,ie as splitCapturedCSS};
|
package/dist/esm/shell.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
${
|
|
1
|
+
const A=/<head(\s[^>]*)?>/i,C=/<body(\s[^>]*)?>/i,d=(e,t)=>{const s=new RegExp(`\\s${t}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s>]+))`,"i").exec(e);return s?s[2]??s[3]??s[4]??"":null},y=e=>{const t=e.slice(0,12).toLowerCase();if(t.startsWith("<title"))return"title";if(t.startsWith("<meta")){if(d(e,"charset")!==null)return"charset";for(const s of["name","property","http-equiv","itemprop"]){const r=d(e,s);if(r!==null)return`${s}:${r.toLowerCase()}`}return null}if(t.startsWith("<link")){const s=(d(e,"rel")||"").toLowerCase();return s==="canonical"?"link:canonical":s==="icon"||s==="shortcut icon"?`link:${s}:${d(e,"href")||""}`:s==="alternate"&&d(e,"hreflang")!==null?`link:alternate:${(d(e,"hreflang")||"").toLowerCase()}`:null}return null},k=/<title[^>]*>[\s\S]*?<\/title\s*>|<meta\b[^>]*>|<link\b[^>]*>/gi,L=/<(script|style|noscript|template|textarea)\b[\s\S]*?<\/\1\s*>/gi,E=e=>[...e.matchAll(L)].map(t=>[t.index,t.index+t[0].length,t[0]]),R=(e,t,s=r=>r)=>{let r="",i=0;for(const[c,n,l]of E(e))r+=t(e.slice(i,c))+s(l),i=n;return r+t(e.slice(i))},f=(e,t,s=0)=>{const r=E(e),i=new RegExp(t.source,t.flags.includes("g")?t.flags:t.flags+"g");i.lastIndex=s;let c;for(;c=i.exec(e);){const n=c.index,l=r.find(([u,h])=>n>u&&n<h);if(!l)return c;i.lastIndex=l[1]}return null},B=e=>!!e&&!/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(e),_=(e,t)=>e.replace(/(\s(?:src|href)\s*=\s*)(?:(["'])([^"']*)\2|([^\s"'>]+))/gi,(s,r,i,c,n)=>{const l=i?c:n;if(!B(l))return s;const u=i||"";return`${r}${u}${t}${l.replace(/^\.\//,"")}${u}`}),D=(e,t)=>{if(!t)return e;const s="../".repeat(t);return R(e,r=>r.replace(/<link\b[^>]*>/gi,i=>_(i,s)),r=>/^<script\b/i.test(r)?r.replace(/^<script\b[^>]*>/i,i=>_(i,s)):r)},I=(e,{headTags:t="",headEnd:s="",body:r="",depth:i=0,bootScripts:c=""}={})=>{if(typeof e!="string"||!e.trim())throw new Error("brender: the shell document is empty");let n=D(e,i);const l=new Set;for(const o of t.matchAll(k)){const a=y(o[0]);a&&l.add(a)}const u=o=>R(o,a=>a.replace(k,O=>l.has(y(O))?"":O)),h=t?`
|
|
2
|
+
${t}`:"",g=s?`
|
|
3
3
|
${s}
|
|
4
|
-
`:"",p=f(
|
|
4
|
+
`:"",p=f(n,A),w=p&&f(n,/<\/head\s*>/i,p.index);if(p&&w){const o=p.index+p[0].length,a=w.index;n=n.slice(0,o)+h+u(n.slice(o,a))+g+n.slice(a)}else{n=u(n);const o=f(n,/<html(\s[^>]*)?>/i)||f(n,/<!doctype[^>]*>/i),a=o?o.index+o[0].length:0;n=n.slice(0,a)+h+g+n.slice(a)}const $=`
|
|
5
5
|
<script>window.__BRENDER__=true<\/script>
|
|
6
|
-
${
|
|
7
|
-
|
|
6
|
+
${c?c+`
|
|
7
|
+
`:""}${r}
|
|
8
|
+
`,x=f(n,C);if(x){const o=x.index+x[0].length;return n.slice(0,o)+$+n.slice(o)}const m=f(n,/<\/(?:body|html)\s*>/i),b=m?m.index:n.length;return n.slice(0,b)+$+n.slice(b)};export{I as composeIntoShell,y as headTagKey};
|
package/env.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import { parseHTML } from 'linkedom'
|
|
2
2
|
|
|
3
|
+
// The virtual windows createEnv() made — see the `globalThis.Window` note below.
|
|
4
|
+
const ssrWindows = new WeakSet()
|
|
5
|
+
class SSRWindow {
|
|
6
|
+
static [Symbol.hasInstance] (obj) { return ssrWindows.has(obj) }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Give a getter-only HTMLSelectElement#value its setter (see createEnv). The
|
|
10
|
+
// prototype is linkedom's, shared by every document it parses: patched once.
|
|
11
|
+
const patchSelectValue = (document) => {
|
|
12
|
+
let proto = Object.getPrototypeOf(document.createElement('select'))
|
|
13
|
+
let desc
|
|
14
|
+
while (proto && !(desc = Object.getOwnPropertyDescriptor(proto, 'value'))) proto = Object.getPrototypeOf(proto)
|
|
15
|
+
if (!proto || !desc || !desc.get || desc.set) return
|
|
16
|
+
Object.defineProperty(proto, 'value', {
|
|
17
|
+
configurable: true,
|
|
18
|
+
enumerable: desc.enumerable,
|
|
19
|
+
get: desc.get,
|
|
20
|
+
set (value) {
|
|
21
|
+
const wanted = value == null ? '' : String(value)
|
|
22
|
+
let matched = false
|
|
23
|
+
for (const option of this.querySelectorAll('option')) {
|
|
24
|
+
const optionValue = option.hasAttribute('value') ? option.getAttribute('value') : option.textContent
|
|
25
|
+
if (!matched && optionValue === wanted) {
|
|
26
|
+
option.setAttribute('selected', '')
|
|
27
|
+
matched = true
|
|
28
|
+
} else {
|
|
29
|
+
option.removeAttribute('selected')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
3
36
|
/**
|
|
4
37
|
* Creates a virtual DOM environment for server-side rendering.
|
|
5
38
|
* Returns window and document that DOMQL can use as context.
|
|
@@ -54,6 +87,14 @@ export const createEnv = (html = '<!DOCTYPE html><html><head></head><body></body
|
|
|
54
87
|
if (!globalThis.localStorage) globalThis.localStorage = window.localStorage
|
|
55
88
|
if (!globalThis.sessionStorage) globalThis.sessionStorage = window.sessionStorage
|
|
56
89
|
|
|
90
|
+
// linkedom's HTMLSelectElement has a `value` getter and NO setter: a
|
|
91
|
+
// `value` prop on a <select> threw "Cannot set property value … which has
|
|
92
|
+
// only a getter" and dropped the parent's children from the markup
|
|
93
|
+
// (docs.symbols.app lost DocsNavbar and DocSidebar through its language
|
|
94
|
+
// select — FW-BRENDER-HYDRATION-AND-CF-DEPLOY-PROVIDER-1). The browser's
|
|
95
|
+
// setter: the option with that value becomes the selected one.
|
|
96
|
+
patchSelectValue(document)
|
|
97
|
+
|
|
57
98
|
// Stub MutationObserver for SSR (not provided by linkedom)
|
|
58
99
|
if (!window.MutationObserver) {
|
|
59
100
|
window.MutationObserver = class MutationObserver {
|
|
@@ -72,7 +113,24 @@ export const createEnv = (html = '<!DOCTYPE html><html><head></head><body></body
|
|
|
72
113
|
globalThis.Element = window.Element || globalThis.Element
|
|
73
114
|
globalThis.HTMLElement = window.HTMLElement || globalThis.HTMLElement
|
|
74
115
|
globalThis.MutationObserver = window.MutationObserver
|
|
75
|
-
|
|
116
|
+
// NEVER `window.constructor`: linkedom's window is a Proxy whose
|
|
117
|
+
// constructor is `Object`, and it reads unknown properties through to
|
|
118
|
+
// globalThis — so `window.Window` became `Object`, @symbo.ls/utils
|
|
119
|
+
// `isDOMNode(obj)` (`obj instanceof window.Window`) answered true for EVERY
|
|
120
|
+
// object, and `deepClone` (which keeps DOM nodes by reference) stopped
|
|
121
|
+
// cloning anything nested. Every later render in the same process then
|
|
122
|
+
// built on the first render's in-place-processed design system: 18–42
|
|
123
|
+
// self-referential theme variables per page on the platform worker
|
|
124
|
+
// (FW-BRENDER-HYDRATION-AND-CF-DEPLOY-PROVIDER-1). A real Window class (a
|
|
125
|
+
// jsdom host) is kept; otherwise a class whose only instances are the
|
|
126
|
+
// virtual windows this module created, so the window itself stays a host
|
|
127
|
+
// object (kept by reference, as before) and nothing else does.
|
|
128
|
+
ssrWindows.add(window)
|
|
129
|
+
if (window.constructor && window.constructor !== Object) {
|
|
130
|
+
globalThis.Window = window.constructor
|
|
131
|
+
} else if (typeof globalThis.Window !== 'function' || globalThis.Window === Object) {
|
|
132
|
+
globalThis.Window = SSRWindow
|
|
133
|
+
}
|
|
76
134
|
|
|
77
135
|
return { window, document }
|
|
78
136
|
}
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createEnv } from './env.js'
|
|
2
2
|
import { resetKeys, assignKeys, mapKeysToElements } from './keys.js'
|
|
3
3
|
import { loadProject, loadAndRenderAll } from './load.js'
|
|
4
|
-
import { render, renderElement, renderRoute, renderPage, resetGlobalCSSCache, getAccumulatedEmotionCSS, replaceEmotionCSS } from './render.js'
|
|
4
|
+
import { render, renderElement, renderRoute, renderPage, resetGlobalCSSCache, getAccumulatedEmotionCSS, replaceEmotionCSS, adoptionScripts } from './render.js'
|
|
5
5
|
import { extractMetadata, generateHeadHtml } from './metadata.js'
|
|
6
6
|
import { collectBrNodes, hydrate } from './hydrate.js'
|
|
7
7
|
import { generateSitemap } from './sitemap.js'
|
|
@@ -29,7 +29,8 @@ export {
|
|
|
29
29
|
generateSitemap,
|
|
30
30
|
prefetchPageData,
|
|
31
31
|
injectPrefetchedState,
|
|
32
|
-
composeIntoShell
|
|
32
|
+
composeIntoShell,
|
|
33
|
+
adoptionScripts
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export default {
|
|
@@ -53,5 +54,6 @@ export default {
|
|
|
53
54
|
generateSitemap,
|
|
54
55
|
prefetchPageData,
|
|
55
56
|
injectPrefetchedState,
|
|
56
|
-
composeIntoShell
|
|
57
|
+
composeIntoShell,
|
|
58
|
+
adoptionScripts
|
|
57
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/brender",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.663",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"prepublishOnly": "npm run build"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@symbo.ls/css": "^3.14.
|
|
49
|
+
"@symbo.ls/css": "^3.14.775",
|
|
50
50
|
"@symbo.ls/default-config": "^3.14.785",
|
|
51
|
-
"@symbo.ls/element": "^3.14.
|
|
52
|
-
"@symbo.ls/fetch": "^3.14.
|
|
51
|
+
"@symbo.ls/element": "^3.14.800",
|
|
52
|
+
"@symbo.ls/fetch": "^3.14.663",
|
|
53
53
|
"@symbo.ls/helmet": "^3.14.669",
|
|
54
54
|
"@symbo.ls/scratch": "^3.14.786",
|
|
55
55
|
"@symbo.ls/utils": "^3.14.784",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"linkedom": "^0.16.8"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"smbls": "^3.14.
|
|
60
|
+
"smbls": "^3.14.828"
|
|
61
61
|
},
|
|
62
62
|
"optionalDependencies": {
|
|
63
63
|
"@symbo.ls/funcql": "^3.14.0"
|