@symbo.ls/utils 3.14.783 → 3.14.784

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 CHANGED
@@ -1,5 +1,61 @@
1
1
  # @symbo.ls/utils
2
2
 
3
+ ## 3.14.784
4
+
5
+ ### Patch Changes
6
+
7
+ - 13c4922: extends: one precedence law — `LAST wins` on the frank/utils path too
8
+
9
+ The framework shipped two `extends` resolvers implementing OPPOSITE laws for an
10
+ authored `extends: [A, B]` array. `packages/element/src/extends.js` (the browser
11
+ and SSR runtime) merged each top-level entry in order, so LAST wins.
12
+ `packages/utils/extends.js` — the standalone resolver published in this package
13
+ and used on the frank/JSON path — resolved the other way, so FIRST won.
14
+
15
+ `@symbo.ls/utils` now follows the same law as the runtime: for
16
+ `extends: [A, B]`, B wins. A shared fixture pins both resolvers so they cannot
17
+ diverge again.
18
+
19
+ This is a behaviour change to a published API, not an internal refactor. It is
20
+ released as a patch because it aligns the minority path with the law the runtime
21
+ already enforced, and a census across authored projects measured ZERO on-screen
22
+ differences — every observed array either had no conflicting keys or already
23
+ relied on the runtime ordering. If a consumer deliberately depended on FIRST
24
+ winning through the frank/JSON path, that expectation no longer holds and the
25
+ array order must be reversed.
26
+
27
+ Reference: FW-EXTENDS-ARRAY-TWO-RESOLVERS-OPPOSITE-PRECEDENCE-1.
28
+
29
+ - Fixes for the 42 issues reported while building xma.info (FW-XMA-EXCEPTIONS-UPSTREAM-1).
30
+
31
+ Behaviour changes (check these first):
32
+
33
+ - CSS precedence across `extends`: a later layer's shorthand that states a longhand now beats a longhand an earlier layer declared (`borderWidth: '0'` no longer loses to a base `borderBottomWidth`; a derived `border: 'hairline solid …'` now paints over a base `borderWidth: '0'`). Positional shorthands (`background`, `transition`, `font`, `flex`, `grid`…) never remove a base longhand. A `:focus-visible` longhand (`outlineColor`) now paints over Link/Focusable's ring.
34
+ - Built-in `Img` no longer copies `alt` into `title`. `Link` leaves Ctrl/Cmd/Shift/Alt, middle, `target` and `download` clicks to the browser.
35
+ - `X<` breakpoints start at N.02px, so no width matches both `X` and `X<`.
36
+ - Helmet renders the head as the merge of mounted layers: keys a page leaves out fall back instead of staying from the previous page.
37
+ - `smbls build` with `"brender": true` pre-renders again (it rendered nothing since 3.14.6): every static route is written, `/*` becomes `404.html`, `:param` routes are skipped and listed, and the build exits 1 when no route renders.
38
+ - `onStateInit`, `onStateCreated` and `onBeforeStateUpdate` run again (`onBeforeStateUpdate` returning `false` cancels the update).
39
+ - `onWindowLoad` runs once right after creation when the page had already loaded.
40
+ - The first render no longer forces a style+layout pass per microtask.
41
+ - socket.io-client loads only when a sync transport is configured; the ESM build ships it as `dist/smbls.socket-io-client.esm.js` (keep it beside `smbls.esm.js`).
42
+
43
+ New, opt-in:
44
+
45
+ - `designSystem.focusableRing`; `vars` and top-level `'--x'` keys set reactive custom properties; `fill`/`stroke` are CSS outside `<svg>`; attributes inside `.isX` / `'!isX'` blocks apply.
46
+ - Design-system tokens resolve inside `style: {}` blocks; `sizes` tokens negate (`-hairline2`) and publish `--size-<name>`.
47
+ - `fetchpriority` and every multi-word attribute work flat in both spellings.
48
+ - `inertOutside`, the `Bridge` host for DOM-owning libraries, element events with `{ capture, passive, once, selector, handler }`, `TooltipLayer` for `[data-tooltip]` nodes.
49
+ - Router `scrollRestoration: 'restore'`; guards that refuse Back/Forward put the address back; lazy route groups (`context.lazy`, `el.call('loadLazy')`).
50
+ - Fetch: `el.call('invalidateQueries')` and friends, `invalidates` on rpc, `fetch.early` pre-boot requests, `fetch.reads` anonymous GET reads without a CORS preflight.
51
+ - Polyglot `setLang` switches text, `<html lang>` and fonts in one frame; `getPendingLang`.
52
+ - `s.$settled()` / `settled()` await the DOM a state write produces; `onMediaQueryChange` takes design-system media keys; the `animation` shorthand resolves tokens.
53
+ - `smbls/ssr` entry for server rendering; `smbls push` publishes `new URL('<path>', import.meta.url)` assets.
54
+ - frank-audit: FA105 per-tag, FA410 (history writes), wider FA701; opt-in FA211, FA810, FA811, FA812; unknown `--rule` ids are reported.
55
+
56
+ - Updated dependencies
57
+ - @symbo.ls/fetch@3.14.662
58
+
3
59
  ## 3.14.770
4
60
 
5
61
  ### Patch Changes
@@ -1,2 +1,2 @@
1
- "use strict";var j=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var D=(e,s)=>{for(var t in s)j(e,t,{get:s[t],enumerable:!0})},P=(e,s,t,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of T(s))!F.call(e,r)&&r!==t&&j(e,r,{get:()=>s[r],enumerable:!(n=x(s,r))||n.enumerable});return e};var R=e=>P(j({},"__esModule",{value:!0}),e);var Y={};D(Y,{fileEntryUrl:()=>E,generateHeadArrayTags:()=>L,generateMetaTags:()=>q,getPageMetadata:()=>N,hashContent:()=>b,resolveFileReferences:()=>W});module.exports=R(Y);var w=require("./types.js"),M=require("./function.js");const g=e=>{if(e==null)return"";const s={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return e.toString().replace(/[&<>"']/g,t=>s[t])},U=e=>Object.entries(e||{}).filter(([s,t])=>t!==void 0).map(([s,t])=>`${s}="${g(t)}"`).join(" "),b=e=>{let s=5381;const t=String(e);for(let n=0;n<t.length;n++)s=(s*33^t.charCodeAt(n))>>>0;return s.toString(36)},_=new Set(["jsonLd","styles","scripts"]),L=e=>{const s=[];if(Array.isArray(e.jsonLd))for(const t of e.jsonLd){if(t==null)continue;const n=typeof t=="string"?t:JSON.stringify(t),r=String(n).replace(/<\/script/gi,"<\\/script");s.push(`<script type="application/ld+json" data-smbls-jsonld="${b(n)}">${r}<\/script>`)}if(Array.isArray(e.styles))for(const t of e.styles){if(t==null||!String(t).trim())continue;const n=String(t).replace(/<\/style/gi,"<\\/style");s.push(`<style data-smbls-style="${b(n)}">${n}</style>`)}if(Array.isArray(e.scripts))for(const t of e.scripts){if(!t)continue;const n=typeof t=="string",r=n?t:t.src;if(!r&&!t.body)continue;const o=[];r&&o.push(`src="${g(r)}"`),n||(t.type&&o.push(`type="${g(t.type)}"`),t.async&&o.push("async"),t.defer&&o.push("defer"),t.integrity&&o.push(`integrity="${g(t.integrity)}"`),t.crossorigin&&o.push(`crossorigin="${g(t.crossorigin)}"`),t.referrerpolicy&&o.push(`referrerpolicy="${g(t.referrerpolicy)}"`),t.nomodule&&o.push("nomodule"));const l=` data-smbls-script="${g(r||b(t.body||""))}"`;if(!n&&t.body){const h=String(t.body).replace(/<\/script/gi,"<\\/script");s.push(`<script ${o.join(" ")}${l}>${h}<\/script>`)}else s.push(`<script ${o.join(" ")}${l}><\/script>`)}return s},q=(e,s)=>{s||(e={...e,robots:"noindex"});const t=Object.entries(e).reduce((n,[r,o])=>{if(!o&&o!==0&&o!==!1||_.has(r))return n;if(r==="title")return n.push(`<title>${g(o)}</title>`),n;if(r==="canonical")return n.push(`<link rel="canonical" href="${g(o)}">`),n;if(r==="manifest")return n.push(`<link rel="manifest" href="${g(o)}">`),n;if(r==="favicon"||r==="favicons"||r==="icon"||r==="icons")return(Array.isArray(o)?o:[o]).forEach(c=>{if(typeof c=="string")n.push(`<link rel="icon" href="${g(c)}">`);else if(typeof c=="object"){const u=U(c);/rel=/.test(u)?n.push(`<link ${u}>`):n.push(`<link rel="icon" ${u}>`)}}),n;if(r==="alternate")return(Array.isArray(o)?o:[o]).forEach(c=>{if(typeof c=="object"){const u=Object.entries(c).filter(([i,p])=>p!==void 0).map(([i,p])=>`${i}="${g(p)}"`).join(" ");n.push(`<link rel="alternate" ${u}>`)}}),n;const l=(f,c,u="name")=>{if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`<meta ${u}="${g(f)}" content="${g(c)}">`);else if(Array.isArray(c))c.forEach(i=>{if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")n.push(`<meta ${u}="${g(f)}" content="${g(i)}">`);else if(typeof i=="object"){const p=Object.entries(i).filter(([m,a])=>a!==void 0).map(([m,a])=>`${m}="${g(a)}"`).join(" ");n.push(`<meta ${p}>`)}});else if(typeof c=="object"){const i=Object.entries(c).filter(([p,m])=>m!==void 0).map(([p,m])=>`${p}="${g(m)}"`).join(" ");n.push(`<meta ${i}>`)}};if(r.startsWith("http-equiv:")){const f=r.replace("http-equiv:","");return l(f,o,"http-equiv"),n}if(r.startsWith("itemprop:")){const f=r.replace("itemprop:","");return l(f,o,"itemprop"),n}const y=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(f=>r.startsWith(f));if(y){const f=r.replace(y,"");return l(`${y.replace(":","")}:${f}`,o,y==="twitter:"||y==="DC:"||y==="DCTERMS:"?"name":"property"),n}if(r.startsWith("apple:")||r.startsWith("msapplication:")){const f=r.startsWith("apple:")?"apple-":"msapplication-",c=r.replace(/^apple:|^msapplication:/,"");return l(`${f}${c}`,o,"name"),n}return l(r,o),n},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return t.push(...L(e)),t.join(`
2
- `)},K=e=>typeof e=="string"&&e.length>0&&!e.startsWith("/")&&!e.startsWith("http"),S=e=>typeof e=="string"&&e.length>0,E=e=>{if(!e||typeof e!="object")return null;if(S(e.src))return e.src;const s=e.content;return!s||typeof s!="object"?null:S(s.src)?s.src:S(s.storageUrl)?s.storageUrl:null};function W(e,s){if(!s||typeof s!="object")return e;const t=r=>!K(r)||!Object.prototype.hasOwnProperty.call(s,r)?r:E(s[r])||r,n={...e};for(const[r,o]of Object.entries(n))typeof o=="string"?n[r]=t(o):Array.isArray(o)&&(n[r]=o.map(l=>typeof l=="string"?t(l):l));return n}function A(e,s){if(!e||!s)return;const t=s.split(".");let n=e;for(const r of t){if(n==null||typeof n!="object")return;n=n[r]}return n}function C(e,s){const t=A(e,s);if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t=="string"&&!(0,M.isStringFunction)(t))return t}function H(e,s,t){const r=(s.config||s.settings||{}).polyglot||s.polyglot,o=t?.lang||r?.defaultLang||"en",h=(r?.translations||{})[o]||{},y=[t?.state,s.state].filter(u=>u&&typeof u=="object"),f=u=>{for(const i of y){const p=C(i,u);if(p!==void 0)return p}},c={...e};for(const[u,i]of Object.entries(c))typeof i!="string"||!i.includes("{{")||(c[u]=i.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(p,m,a)=>{const d=m.trim();if(a==="polyglot")return h[d]??A(h,d)??p;if(a==="getLocalStateLang")return f(d+o)??p;const $=f(d);return $!==void 0?$:h[d]??A(h,d)??p}));return c}function O(e){if(!(0,w.isObject)(e))return{};const s={...e};for(const[t,n]of Object.entries(s))if(typeof n=="function"){const r=n.toString(),o=r.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){s[t]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const l=r.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(l){s[t]=`{{ ${l[1]} | polyglot }}`;continue}const h=r.match(/s\.(\w+(?:\.\w+)+)/);if(h){s[t]=`{{ ${h[1]} }}`;continue}delete s[t]}else if(typeof n=="string"){const r=n.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(r){s[t]=`{{ ${r[1]} | getLocalStateLang }}`;continue}const o=n.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){s[t]=`{{ ${o[1]} | polyglot }}`;continue}if(n.includes("=>")&&n.includes("s.")){const l=n.match(/s\.(\w+(?:\.\w+)+)/);if(l){s[t]=`{{ ${l[1]} }}`;continue}}(0,M.isStringFunction)(n)&&delete s[t]}return s}function N(e,s,t,{isProduction:n=!1,channel:r="production"}={}){const o=e.pages?.[s],l=(0,w.isObject)(o?.state)&&o?.state,h=o?.metadata||o?.helmet||l||{},y=O(h),f=new Set(Object.keys(y)),c=e.app?.metadata||{},u=O(c);let i={};if(e.integrations?.seo?i={...e.integrations.seo,...u,...y}:Object.keys(u).length?i={...u,...y}:i={...y},!i.title){const a=e.name||e.key;a?n?i.title=a:r==="development"?i.title=`${a} / dev:symbo.ls`:r==="staging"?i.title=`${a} / staging:symbo.ls`:i.title=`${a} / symbo.ls`:i.title="Symbols demo"}i=H(i,e,t),i.title&&(f.has("title")||!i["og:title"])&&(f.has("og:title")||(i["og:title"]=i.title)),i.description&&(f.has("description")||!i["og:description"])&&(f.has("og:description")||(i["og:description"]=i.description)),i.title&&!i["twitter:title"]&&(i["twitter:title"]=i.title),i.description&&!i["twitter:description"]&&(i["twitter:description"]=i.description);const p=t?.actualPathname||s;if(i["og:url"]||i.url){const a=(i["og:url"]||i.url||"").replace(/\/$/,"");if(a&&p&&p!=="/"){const d=p.startsWith("/")?p:"/"+p;i["og:url"]=a+d}}i=W(i,e.files);const m=e.name||e.app?.metadata?.title||e.app?.name||"";for(const[a,d]of Object.entries(i))if(typeof d=="string"&&d.includes("{{")){const $=d.replace(/\{\{[^}]*\}\}/g,"").trim();$?i[a]=$:a==="title"?i[a]=m:delete i[a]}return i}
1
+ "use strict";var A=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var U=(e,n)=>{for(var t in n)A(e,t,{get:n[t],enumerable:!0})},D=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of F(n))!K.call(e,i)&&i!==t&&A(e,i,{get:()=>n[i],enumerable:!(s=T(n,i))||s.enumerable});return e};var P=e=>D(A({},"__esModule",{value:!0}),e);var z={};U(z,{fileEntryUrl:()=>W,generateHeadArrayTags:()=>E,generateMetaTags:()=>N,getPageMetadata:()=>B,hashContent:()=>j,resolveFileReferences:()=>x});module.exports=P(z);var b=require("./types.js"),M=require("./function.js");const p=e=>{if(e==null)return"";const n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return e.toString().replace(/[&<>"']/g,t=>n[t])},R=e=>Object.entries(e||{}).filter(([n,t])=>t!==void 0).map(([n,t])=>`${n}="${p(t)}"`).join(" "),j=e=>{let n=5381;const t=String(e);for(let s=0;s<t.length;s++)n=(n*33^t.charCodeAt(s))>>>0;return n.toString(36)},_=new Set(["jsonLd","styles","scripts"]),E=e=>{const n=[];if(Array.isArray(e.jsonLd))for(const t of e.jsonLd){if(t==null)continue;const s=typeof t=="string"?t:JSON.stringify(t),i=String(s).replace(/<\/script/gi,"<\\/script");n.push(`<script type="application/ld+json" data-smbls-jsonld="${j(s)}">${i}<\/script>`)}if(Array.isArray(e.styles))for(const t of e.styles){if(t==null||!String(t).trim())continue;const s=String(t).replace(/<\/style/gi,"<\\/style");n.push(`<style data-smbls-style="${j(s)}">${s}</style>`)}if(Array.isArray(e.scripts))for(const t of e.scripts){if(!t)continue;const s=typeof t=="string",i=s?t:t.src;if(!i&&!t.body)continue;const o=[];i&&o.push(`src="${p(i)}"`),s||(t.type&&o.push(`type="${p(t.type)}"`),t.async&&o.push("async"),t.defer&&o.push("defer"),t.integrity&&o.push(`integrity="${p(t.integrity)}"`),t.crossorigin&&o.push(`crossorigin="${p(t.crossorigin)}"`),t.referrerpolicy&&o.push(`referrerpolicy="${p(t.referrerpolicy)}"`),t.nomodule&&o.push("nomodule"));const l=` data-smbls-script="${p(i||j(t.body||""))}"`;if(!s&&t.body){const d=String(t.body).replace(/<\/script/gi,"<\\/script");n.push(`<script ${o.join(" ")}${l}>${d}<\/script>`)}else n.push(`<script ${o.join(" ")}${l}><\/script>`)}return n},q=(e,n,t)=>e==="favicons"?Array.isArray(n)?typeof t=="string"?` data-smbls-favicon="${p(t)}"`:(0,b.isObject)(t)?` data-smbls-favicon="${j(JSON.stringify(t))}"`:"":"":(e==="icon"||e==="favicon")&&typeof n=="string"?` data-smbls-single-icon="${p(n)}"`:"",C=e=>(0,b.isObject)(e)?` data-smbls-alternate="${p(`${e.hreflang||""}|${e.href||""}`)}"`:"",N=(e,n)=>{n||(e={...e,robots:"noindex"});const t=Object.entries(e).reduce((s,[i,o])=>{if(!o&&o!==0&&o!==!1||_.has(i))return s;if(i==="title")return s.push(`<title>${p(o)}</title>`),s;if(i==="canonical")return s.push(`<link rel="canonical" href="${p(o)}">`),s;if(i==="manifest")return s.push(`<link rel="manifest" href="${p(o)}">`),s;if(i==="favicon"||i==="favicons"||i==="icon"||i==="icons")return(Array.isArray(o)?o:[o]).forEach(c=>{const u=q(i,o,c);if(typeof c=="string")s.push(`<link rel="icon" href="${p(c)}"${u}>`);else if(typeof c=="object"){const r=R(c);/rel=/.test(r)?s.push(`<link ${r}${u}>`):s.push(`<link rel="icon" ${r}${u}>`)}}),s;if(i==="alternate")return(Array.isArray(o)?o:[o]).forEach(c=>{if(c&&typeof c=="object"){const u=Object.entries(c).filter(([r,g])=>g!==void 0).map(([r,g])=>`${r}="${p(g)}"`).join(" ");s.push(`<link rel="alternate" ${u}${C(c)}>`)}}),s;const l=(f,c,u="name")=>{if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")s.push(`<meta ${u}="${p(f)}" content="${p(c)}">`);else if(Array.isArray(c))c.forEach(r=>{if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")s.push(`<meta ${u}="${p(f)}" content="${p(r)}">`);else if(typeof r=="object"){const g=Object.entries(r).filter(([y,$])=>$!==void 0).map(([y,$])=>`${y}="${p($)}"`).join(" ");s.push(`<meta ${g}>`)}});else if(typeof c=="object"){const r=Object.entries(c).filter(([g,y])=>y!==void 0).map(([g,y])=>`${g}="${p(y)}"`).join(" ");s.push(`<meta ${r}>`)}};if(i.startsWith("http-equiv:")){const f=i.replace("http-equiv:","");return l(f,o,"http-equiv"),s}if(i.startsWith("itemprop:")){const f=i.replace("itemprop:","");return l(f,o,"itemprop"),s}const h=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(f=>i.startsWith(f));if(h){const f=i.replace(h,"");return l(`${h.replace(":","")}:${f}`,o,h==="twitter:"||h==="DC:"||h==="DCTERMS:"?"name":"property"),s}if(i.startsWith("apple:")||i.startsWith("msapplication:")){const f=i.startsWith("apple:")?"apple-":"msapplication-",c=i.replace(/^apple:|^msapplication:/,"");return l(`${f}${c}`,o,"name"),s}return l(i,o),s},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return t.push(...E(e)),t.join(`
2
+ `)},H=e=>typeof e=="string"&&e.length>0&&!e.startsWith("/")&&!e.startsWith("http"),S=e=>typeof e=="string"&&e.length>0,W=e=>{if(!e||typeof e!="object")return null;if(S(e.src))return e.src;const n=e.content;return!n||typeof n!="object"?null:S(n.src)?n.src:S(n.storageUrl)?n.storageUrl:null};function x(e,n){if(!n||typeof n!="object")return e;const t=i=>!H(i)||!Object.prototype.hasOwnProperty.call(n,i)?i:W(n[i])||i,s={...e};for(const[i,o]of Object.entries(s))typeof o=="string"?s[i]=t(o):Array.isArray(o)&&(s[i]=o.map(l=>typeof l=="string"?t(l):l));return s}function w(e,n){if(!e||!n)return;const t=n.split(".");let s=e;for(const i of t){if(s==null||typeof s!="object")return;s=s[i]}return s}function J(e,n){const t=w(e,n);if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t=="string"&&!(0,M.isStringFunction)(t))return t}function Y(e,n,t){const i=(n.config||n.settings||{}).polyglot||n.polyglot,o=t?.lang||i?.defaultLang||"en",d=(i?.translations||{})[o]||{},h=[t?.state,n.state].filter(u=>u&&typeof u=="object"),f=u=>{for(const r of h){const g=J(r,u);if(g!==void 0)return g}},c={...e};for(const[u,r]of Object.entries(c))typeof r!="string"||!r.includes("{{")||(c[u]=r.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(g,y,$)=>{const a=y.trim();if($==="polyglot")return d[a]??w(d,a)??g;if($==="getLocalStateLang")return f(a+o)??g;const m=f(a);return m!==void 0?m:d[a]??w(d,a)??g}));return c}function L(e){if(!(0,b.isObject)(e))return{};const n={...e};for(const[t,s]of Object.entries(n))if(typeof s=="function"){const i=s.toString(),o=i.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){n[t]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const l=i.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(l){n[t]=`{{ ${l[1]} | polyglot }}`;continue}const d=i.match(/s\.(\w+(?:\.\w+)+)/);if(d){n[t]=`{{ ${d[1]} }}`;continue}delete n[t]}else if(typeof s=="string"){const i=s.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(i){n[t]=`{{ ${i[1]} | getLocalStateLang }}`;continue}const o=s.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){n[t]=`{{ ${o[1]} | polyglot }}`;continue}if(s.includes("=>")&&s.includes("s.")){const l=s.match(/s\.(\w+(?:\.\w+)+)/);if(l){n[t]=`{{ ${l[1]} }}`;continue}}(0,M.isStringFunction)(s)&&delete n[t]}return n}function B(e,n,t,{isProduction:s=!1,channel:i="production"}={}){const o=e.pages?.[n],l=(0,b.isObject)(o?.state)&&o?.state,d=o?.metadata||o?.helmet||l||{},h=L(d),f=new Set(Object.keys(h)),c=e.app?.metadata||{},u=L(c);let r={};if(e.integrations?.seo?r={...e.integrations.seo,...u,...h}:Object.keys(u).length?r={...u,...h}:r={...h},!r.title){const a=e.name||e.key;a?s?r.title=a:i==="development"?r.title=`${a} / dev:symbo.ls`:i==="staging"?r.title=`${a} / staging:symbo.ls`:r.title=`${a} / symbo.ls`:r.title="Symbols demo"}r=Y(r,e,t),r.title&&(f.has("title")||!r["og:title"])&&(f.has("og:title")||(r["og:title"]=r.title)),r.description&&(f.has("description")||!r["og:description"])&&(f.has("og:description")||(r["og:description"]=r.description)),r.title&&!r["twitter:title"]&&(r["twitter:title"]=r.title),r.description&&!r["twitter:description"]&&(r["twitter:description"]=r.description);const g=f.has("og:url")?r["og:url"]:f.has("url")?r.url:void 0,y=t?.actualPathname||n;if(g)r["og:url"]=g;else if(r["og:url"]||r.url){const a=(r["og:url"]||r.url||"").replace(/\/$/,"");if(a&&y&&y!=="/"){const m=y.startsWith("/")?y:"/"+y;r["og:url"]=a+m}}r=x(r,e.files);const $=e.name||e.app?.metadata?.title||e.app?.name||"";for(const[a,m]of Object.entries(r))if(typeof m=="string"&&m.includes("{{")){const O=m.replace(/\{\{[^}]*\}\}/g,"").trim();O?r[a]=O:a==="title"?r[a]=$:delete r[a]}return r}
@@ -1,4 +1,4 @@
1
- "use strict";var L=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var o in t)L(e,o,{get:t[o],enumerable:!0})},ie=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of oe(t))!se.call(e,s)&&s!==o&&L(e,s,{get:()=>t[s],enumerable:!(n=ne(t,s))||n.enumerable});return e};var ce=e=>ie(L({},"__esModule",{value:!0}),e);var Je={};re(Je,{LIBRARY_SCOPES_KEY:()=>S,__resetBuiltinMethodWarnings:()=>de,bindLibraryGlobalScopes:()=>Pe,deepDefaults:()=>w,fetchLibraryData:()=>te,isWrappedLibrary:()=>O,mergeSharedLibraries:()=>De,mergeSharedLibraryDesignSystems:()=>Ye,normalizeIgnoreList:()=>I,normalizeLibraryKey:()=>g,resolveSharedLibraries:()=>ze,sharedLibrary:()=>ye});module.exports=ce(Je);var l=require("./types.js"),_=require("./keys.js"),ee=require("./env.js"),d=require("./object.js");const $="system",ae="https://smbls-kv.nika-980.workers.dev",le="https://api.symbols.app";function g(e){const t=String(e||"").trim();if(!t)return{owner:$,key:"",full:""};let o=null,n=t;if(t.includes("/")){const i=t.indexOf("/");o=t.slice(0,i),n=t.slice(i+1)}n=n.replace(/\.symbo\.ls$/iu,""),o||(o=$);const s=n?`${o}/${n}`:"";return{owner:o,key:n,full:s}}const w=(e,t,o,n)=>{for(const s in t){const i=n?`${n}/${s}`:s;o&&o.has(i)||(s in e?(0,l.isObject)(e[s])&&(0,l.isObject)(t[s])&&w(e[s],t[s],o,i):e[s]=t[s])}},P=(e,t,o)=>{if(!(0,l.isObject)(e)||!t.size)return e;const n=`${o}/`;let s=!1;for(const c of t)if(c.startsWith(n)){s=!0;break}if(!s)return e;const i={};for(const c in e){if(!Object.prototype.hasOwnProperty.call(e,c))continue;const r=`${o}/${c}`;t.has(r)||(i[c]=P(e[c],t,r))}return i},fe=new Set,ue=new Set(["components","pages","functions","snippets","methods"]),N=(e,t)=>t===""&&ue.has(e),M=["fontFamily","fontfamily","font_family","FONT_FAMILY"],C=e=>{const t=new Map;if(!(0,l.isObject)(e))return t;for(const o of M){const n=e[o];if((0,l.isObject)(n))for(const s in n)!(0,l.isObject)(n[s])||!n[s].isDefault||(t.has(o)||t.set(o,new Set),t.get(o).add(s))}return t},F=(e,t)=>{for(const o of M){const n=e[o];if(!(0,l.isObject)(n))continue;const s=t.get(o);let i=null;for(const c in n){const r=n[c];if(!(0,l.isObject)(r)||!r.isDefault||s&&s.has(c))continue;const a={...r};delete a.isDefault,i||(i={...n}),i[c]=a}i&&(e[o]=i)}},pe=e=>e.replace(/\.js$/iu,""),I=e=>{const t=new Set;if(!Array.isArray(e))return t;for(const o of e){if(!(0,l.isString)(o))continue;const n=o.split("/").map(s=>pe(s.trim())).filter(Boolean).join("/");n&&t.add(n)}return t},ye=(e,t={})=>({library:e,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),O=e=>(0,l.isObject)(e)&&Array.isArray(e.ignoreList)&&("library"in e||"key"in e||"name"in e),V=e=>e.library!==void 0?e.library:e.key??e.name,A=new Set,de=()=>{A.clear()},he=(e,t)=>{const o=t.filter(n=>!A.has(n));if(o.length){for(const n of o)A.add(n);(0,ee.isLoudDevRuntime)()&&console.warn(`[smbls] shared library "${e}" ships ${o.map(n=>`methods.${n}`).join(", ")} \u2014 named like a built-in element method. Refused: the built-in wins; a library cannot replace an element method on the consuming app. If the app wants this version, declare it in the app's OWN methods.`)}},be=(e,t,o)=>{let n=null;for(const s in e)if((0,_.isProtectedElementMethod)(s)&&(t.has(`methods/${s}`)||o.push(s),!n)){n={};for(const i in e)(0,_.isProtectedElementMethod)(i)||(n[i]=e[i])}return n||e},U=(e,t)=>{const o=I(e.sharedLibIgnore);return e.sharePages===!1&&o.add("pages"),o.size?new Set([...t,...o]):t},R=["functions","methods","snippets"],D=["components","pages"],Y=Symbol.for("smbls.libraryScope"),S="__libraryScopes",W=new Map,me=()=>Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4),b=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ge=/const __scope = |const __peers_* = |const _s = el\?\.scope|\?\.context\?\.globalScope\?\./,z=e=>{try{return(0,d.getFunctionSource)(e)}catch{return null}},J=e=>{if(typeof e!="function")return null;const t=z(e);return(0,l.isString)(t)&&ge.test(t)&&(0,d.hasFunction)(t)?t:null},G=e=>(0,l.isString)(e)&&(0,d.hasFunction)(e)||J(e)!==null,Se=e=>{const t=e.globalScope;return(0,l.isObject)(t)&&Object.keys(t).some(o=>G(t[o]))?!0:R.some(o=>{const n=e[o];return!!n&&typeof n=="object"&&Object.keys(n).some(s=>G(n[s]))})},ke=(e,t,o)=>{const n=e.globalScope,s=t.globalScope;if(o.has("globalScope")||!(0,l.isObject)(n)||!(0,l.isObject)(s)||!Se(t))return 0;let i=0;for(const c of Object.keys(s))o.has(`globalScope/${c}`)||b(n,c)&&i++;return i},_e=[[/const __scope = (\(\(\) => \{ const r = [\s\S]*?\}\)\(\));/g,"const __scope = $RESOLVE($1);"],[/const __scope = this \?\? \{\};/g,"const __scope = $RESOLVE(this ?? {});"],[/const (__peers_*) = (this && this !== globalThis && this\.context && this\.context\.globalScope \? this\.scope \?\? this\.context\.globalScope : this);/g,"const $1 = $RESOLVE($2);"],[/const _s = (el\?\.scope \?\? el\?\.context\?\.globalScope \?\? \{\});/g,"const _s = $RESOLVE($1);"],[/(?<![\w$.])(this|[A-Za-z_$][\w$]*)\?\.context\?\.globalScope\?\./g,"$RESOLVE($1?.context?.globalScope)?."]],we=e=>{const t=e.split(""),o=[];let n=0,s=0;const i=(r,a)=>{for(let u=r;u<a;u++)t[u]!==`
2
- `&&(t[u]="~")},c=()=>{const r=n;for(;n<e.length;){const a=e[n];if(a==="\\"){n+=2;continue}if(a==="`"){i(r,n),n++;return}if(a==="$"&&e[n+1]==="{"){i(r,n),n+=2,o.push(s),s++;return}n++}i(r,n)};for(;n<e.length;){const r=e[n];if(r==="/"&&e[n+1]==="/"){const a=e.indexOf(`
3
- `,n),u=a===-1?e.length:a;i(n,u),n=u;continue}if(r==="/"&&e[n+1]==="*"){const a=e.indexOf("*/",n+2),u=a===-1?e.length:a+2;i(n,u),n=u;continue}if(r==='"'||r==="'"){const a=r,u=++n;for(;n<e.length&&e[n]!==a&&e[n]!==`
4
- `;)e[n]==="\\"&&n++,n++;i(u,n),n++;continue}if(r==="`"){n++,c();continue}if(r==="{"){s++,n++;continue}if(r==="}"){if(s--,o.length&&s===o[o.length-1]){o.pop(),n++,c();continue}n++;continue}n++}return t.join("")},K=(e,t)=>{if(!(0,l.isString)(e)||!e.includes("__scope = ")&&!e.includes("__peers")&&!e.includes("const _s = ")&&!e.includes("?.context?.globalScope?.")||!(0,d.hasFunction)(e))return e;const o=`(globalThis[Symbol.for('smbls.libraryScope')] || ((_, v) => v))(${JSON.stringify(t)}, `;let n=e;for(const[s,i]of _e){const c=we(n);n=n.replace(s,(...r)=>{const a=r[r.length-2];return c[a]==="~"||c[a]!==n[a]?r[0]:i.replace(/\$RESOLVE\(/g,o).replace(/\$(\d)/g,(u,f)=>r[Number(f)])})}return n},k=(e,t)=>{if((0,l.isString)(e))return K(e,t);const o=J(e);return o===null?e:K(o,t)},Oe={lazy:!0,window:globalThis},q=(e,t)=>{const o=k(e,t);if(o===e||!(0,l.isString)(o))return o;try{const n=(0,d.deepDestringifyFunctions)({v:o},{},Oe).v;return typeof n!="function"?o:(Object.defineProperty(n,"toJSON",{value:()=>o,configurable:!0}),n)}catch{return o}},E=e=>{if(!e||typeof e!="object")return!1;if(Array.isArray(e))return!0;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},H=(e,t,o=new WeakMap)=>{if((0,l.isString)(e)||typeof e=="function")return q(e,t);if((0,d.isStringTag)(e)||!E(e))return e;if(o.has(e))return o.get(e);const n=Array.isArray(e)?[]:Object.getPrototypeOf(e)===null?Object.create(null):{};o.set(e,n);for(const s of Object.keys(e))n[s]=H(e[s],t,o);return n},Le=(e,t)=>{const o={...e},n={};for(const s of Object.keys(e.globalScope))n[s]=k(e.globalScope[s],t);o.globalScope=n;for(const s of R){const i=e[s];if(!E(i))continue;const c={};for(const r of Object.keys(i))c[r]=q(i[r],t);o[s]=c}for(const s of D)E(e[s])&&(o[s]=H(e[s],t));return o},Z=new WeakMap,$e=(e,t,o)=>{let n=Z.get(e);n||Z.set(e,n=new Map);let s=n.get(t);if(s)return s;const i=(c,r)=>b(o,c)&&o[c]===r;return s=new Proxy(e,{get(c,r){if(typeof r=="symbol"||b(c,r))return Reflect.get(c,r);const a=Reflect.get(c,r);return b(t,r)&&(a===void 0||i(r,a))||a===void 0?t[r]:a},set(c,r,a){return typeof r!="symbol"&&!b(c,r)&&b(t,r)?(t[r]=a,!0):Reflect.set(c,r,a)},has:(c,r)=>Reflect.has(c,r)||r in t}),n.set(t,s),s},Ae=e=>!!e&&typeof e=="object"&&!!e.__raw&&typeof e.__raw=="object",Re=(e,t)=>{const o=W.get(e);return o?t===o.consumerGs?o.libGs:Ae(t)?$e(t,o.libGs,o.consumerGs):t:t},Ee=()=>{typeof globalThis[Y]!="function"&&Object.defineProperty(globalThis,Y,{value:Re,configurable:!0})},j=e=>{const t=e[S];return Array.isArray(t)?t:null},je=e=>O(e)?e.library:e,Ie=(e,t,o)=>{const n=j(e);return!!n&&n.some(s=>s&&s.index===t&&(!s.key||s.key===o.key)&&(0,l.isString)(s.id)&&Te(e,s.id))},Te=(e,t)=>{const o=JSON.stringify(t),n=new Set,s=i=>{if((0,l.isString)(i))return i.includes(o);if(!i||typeof i!="object"||n.has(i))return!1;n.add(i);for(const c in i)if(s(i[c]))return!0;return!1};for(const i of["globalScope",...R,...D])if(s(e[i]))return!0;return!1},Be=(e,t)=>{const o={};for(const n of Object.keys(e))o[n]=k(e[n],t);return o},Q=new WeakMap,Pe=(e,t=null)=>{const o=e&&j(e);if(!o||!o.length)return 0;const n=e.globalScope;if(!(0,l.isObject)(n))return 0;const s=Array.isArray(e.sharedLibraries)?e.sharedLibraries:[];let i=Q.get(n);i||Q.set(n,i=new Set),Ee();let c=0;for(const r of o){if(!r||!(0,l.isString)(r.id)||i.has(r.id))continue;const a=je(s[r.index]);if(!a||!(0,l.isObject)(a.globalScope)||r.key&&a.key!==r.key)continue;const u=y=>typeof y=="function"?z(y):y,f=(y,m)=>{if(y===m)return!0;const T=u(y),B=u(m);return(0,l.isString)(T)||(0,l.isString)(B)?T===B:JSON.stringify(y)===JSON.stringify(m)},p=(0,l.isObject)(t)?(Array.isArray(r.landed)?r.landed:[]).filter(y=>(0,l.isString)(y)&&b(a.globalScope,y)&&b(t,y)&&f(t[y],k(a.globalScope[y],r.id))):[],h=(0,d.destringifyGlobalScope)(Be(a.globalScope,r.id));Object.setPrototypeOf(h,n),W.set(r.id,{libGs:h,consumerGs:n});for(const y of p)n[y]=h[y];i.add(r.id),c++}return c},Ne=(e,t,o,n="library",s=-1)=>{const i=U(t,o),c=!Ie(e,s,t)&&ke(e,t,i)>0?`${n}#${me()}`:null,r=c?Le(t,c):t,a=c?new Set(Object.keys(e.globalScope)):null,u=[];for(const f in r)if(Object.prototype.hasOwnProperty.call(r,f)&&!(f==="sharePages"||f==="sharedLibIgnore")&&f!==S&&!f.startsWith("__")&&f!=="app"&&!i.has(f)){if((0,l.isObject)(r[f])&&(0,l.isObject)(e[f])){if(f==="designSystem")w(e[f],r[f],i,f);else for(const p in r[f])if(!i.has(`${f}/${p}`)){if(f==="methods"&&(0,_.isProtectedElementMethod)(p)){p in e[f]||u.push(p);continue}p in e[f]?N(f,e[f][p])&&!N(f,r[f][p])&&(e[f][p]=r[f][p]):e[f][p]=r[f][p]}}else if(!(f in e)){const p=r[f],h=f==="methods"&&p&&typeof p=="object"?be(p,i,u):p;e[f]=P(h,i,f)}}c&&(j(e)||(e[S]=[]),e[S].push({id:c,index:s,key:(0,l.isString)(t.key)?t.key:null,landed:Object.keys(r.globalScope).filter(f=>!a.has(f))})),u.length&&he(n,u)},Me=(e,t,o)=>{if(e!==t){const n=V(e);if((0,l.isString)(n)&&n)return n;if(e.key||e.name)return e.key||e.name}return t&&(t.key||t.name)||`sharedLibraries[${o}]`},Ce=`${$}/default`,Fe=e=>(0,l.isString)(e)&&e!==""&&g(e).full===Ce,Ve=(e,t)=>{if((0,l.isString)(t.key)&&t.key)return t.key;if(e!==t){if((0,l.isString)(e.key)&&e.key)return e.key;if((0,l.isString)(e.name)&&e.name)return e.name}return null},Ue=e=>{const t=[],o=[];for(let n=0;n<e.length;n++){const s=e[n];let i=s,c=fe;if(O(i)&&(c=I(i.ignoreList),i=i.library),!(0,l.isObject)(i))continue;const r={entry:s,lib:i,ignore:c,index:n};Fe(Ve(s,i))?o.push(r):t.push(r)}return{linked:t,bases:o}},X=(e,t,o)=>{const n=C(t()),{linked:s,bases:i}=Ue(e);for(const r of s)o(r);const c=!n.size&&i.length?C(t()):null;for(const r of i)o(r);return n.size?n:c&&c.size?c:null},De=(e,t)=>{if(!t||!t.length)return;const o=e.designSystem,n=X(t,()=>e.designSystem,({entry:s,lib:i,ignore:c,index:r})=>Ne(e,i,c,Me(s,i,r),r));n&&(e.designSystem!==o&&(e.designSystem={...e.designSystem}),F(e.designSystem,n))},Ye=(e,t,o=w)=>{if(!(0,l.isObject)(e)||!Array.isArray(t)||!t.length)return e;const n=X(t,()=>e,({lib:s,ignore:i})=>{const c=s.designSystem;if(!c||typeof c!="object")return;const r=U(s,i);r.has("designSystem")||o(e,c,r,"designSystem")});return n&&F(e,n),e};async function te(e,t={}){if((t.provider||"kv")==="api")return x(e,t);const n=await We(e,t);return n||x(e,t)}async function We(e,t={}){const o=t.kvBaseUrl||ae,n=t.env||"production",s=`${o}/kv/${encodeURIComponent(e)}?env=${n}`;try{const i=await fetch(s,{method:"GET"});return i.ok&&(await i.json())?.value||null}catch{return null}}async function x(e,t={}){const o=t.apiBaseUrl||le,{key:n}=g(e);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(n)}&limit=10`,i=await fetch(s,{method:"GET"});if(!i.ok)return null;const c=await i.json(),a=(c?.items||c?.data||(Array.isArray(c)?c:[])).find(y=>{const{key:m}=g(y?.key);return m.toLowerCase()===n.toLowerCase()});if(!a?.id&&!a?._id)return null;const u=a.id||a._id,f=`${o}/core/projects/${encodeURIComponent(u)}/data?branch=main`,p=await fetch(f,{method:"GET"});if(!p.ok)return null;const h=await p.json();return h?.data||h||null}catch{return null}}async function v(e,t={}){if((0,l.isObject)(e))return e;if((0,l.isString)(e)){const{full:o}=g(e);if(!o)return null;try{const n=await te(o,t);return n||console.warn(`[smbls] Shared library "${o}" not found`),n}catch(n){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,n.message),null}}return null}async function ze(e,t={}){return!e||!e.length?[]:(await Promise.all(e.map(async n=>{if(O(n)){const s=await v(V(n),t);return s?{library:s,ignoreList:n.ignoreList}:null}return v(n,t)}))).filter(Boolean)}
1
+ "use strict";var $=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var be=(e,n)=>{for(var o in n)$(e,o,{get:n[o],enumerable:!0})},de=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of pe(n))!ye.call(e,s)&&s!==o&&$(e,s,{get:()=>n[s],enumerable:!(t=ue(n,s))||t.enumerable});return e};var he=e=>de($({},"__esModule",{value:!0}),e);var nt={};be(nt,{LIBRARY_PACKAGES:()=>le,LIBRARY_SCOPES_KEY:()=>k,__resetBuiltinMethodWarnings:()=>Oe,bindLibraryGlobalScopes:()=>Ue,deepDefaults:()=>A,exposeBagGlobalScopes:()=>ze,fetchLibraryData:()=>fe,isWrappedLibrary:()=>_,libraryPackageSpecs:()=>ce,mergeSharedLibraries:()=>ve,mergeSharedLibraryDesignSystems:()=>xe,normalizeIgnoreList:()=>B,normalizeLibraryKey:()=>S,resolveSharedLibraries:()=>tt,sharedLibrary:()=>we,warnLibraryAliasCollision:()=>ae});module.exports=he(nt);var f=require("./types.js"),L=require("./keys.js"),ie=require("./env.js"),b=require("./object.js");const R="system",me="https://smbls-kv.nika-980.workers.dev",ge="https://api.symbols.app";function S(e){const n=String(e||"").trim();if(!n)return{owner:R,key:"",full:""};let o=null,t=n;if(n.includes("/")){const i=n.indexOf("/");o=n.slice(0,i),t=n.slice(i+1)}t=t.replace(/\.symbo\.ls$/iu,""),o||(o=R);const s=t?`${o}/${t}`:"";return{owner:o,key:t,full:s}}const A=(e,n,o,t)=>{for(const s in n){const i=t?`${t}/${s}`:s;o&&o.has(i)||(s in e?(0,f.isObject)(e[s])&&(0,f.isObject)(n[s])&&A(e[s],n[s],o,i):e[s]=n[s])}},N=(e,n,o)=>{if(!(0,f.isObject)(e)||!n.size)return e;const t=`${o}/`;let s=!1;for(const c of n)if(c.startsWith(t)){s=!0;break}if(!s)return e;const i={};for(const c in e){if(!Object.prototype.hasOwnProperty.call(e,c))continue;const r=`${o}/${c}`;n.has(r)||(i[c]=N(e[c],n,r))}return i},Se=new Set,_e=new Set(["components","pages","functions","snippets","methods"]),F=(e,n)=>n===""&&_e.has(e),V=["fontFamily","fontfamily","font_family","FONT_FAMILY"],D=e=>{const n=new Map;if(!(0,f.isObject)(e))return n;for(const o of V){const t=e[o];if((0,f.isObject)(t))for(const s in t)!(0,f.isObject)(t[s])||!t[s].isDefault||(n.has(o)||n.set(o,new Set),n.get(o).add(s))}return n},G=(e,n)=>{for(const o of V){const t=e[o];if(!(0,f.isObject)(t))continue;const s=n.get(o);let i=null;for(const c in t){const r=t[c];if(!(0,f.isObject)(r)||!r.isDefault||s&&s.has(c))continue;const l={...r};delete l.isDefault,i||(i={...t}),i[c]=l}i&&(e[o]=i)}},ke=e=>e.replace(/\.js$/iu,""),B=e=>{const n=new Set;if(!Array.isArray(e))return n;for(const o of e){if(!(0,f.isString)(o))continue;const t=o.split("/").map(s=>ke(s.trim())).filter(Boolean).join("/");t&&n.add(t)}return n},we=(e,n={})=>({library:e,ignoreList:Array.isArray(n.ignoreList)?n.ignoreList:[]}),_=e=>(0,f.isObject)(e)&&Array.isArray(e.ignoreList)&&("library"in e||"key"in e||"name"in e),U=e=>e.library!==void 0?e.library:e.key??e.name,j=new Set,Oe=()=>{j.clear()},Le=(e,n)=>{const o=n.filter(t=>!j.has(t));if(o.length){for(const t of o)j.add(t);(0,ie.isLoudDevRuntime)()&&console.warn(`[smbls] shared library "${e}" ships ${o.map(t=>`methods.${t}`).join(", ")} \u2014 named like a built-in element method. Refused: the built-in wins; a library cannot replace an element method on the consuming app. If the app wants this version, declare it in the app's OWN methods.`)}},Ae=(e,n,o)=>{let t=null;for(const s in e)if((0,L.isProtectedElementMethod)(s)&&(n.has(`methods/${s}`)||o.push(s),!t)){t={};for(const i in e)(0,L.isProtectedElementMethod)(i)||(t[i]=e[i])}return t||e},Y=(e,n)=>{const o=B(e.sharedLibIgnore);return e.sharePages===!1&&o.add("pages"),o.size?new Set([...n,...o]):n},E=["functions","methods","snippets"],W=["components","pages"],K=Symbol.for("smbls.libraryScope"),k="__libraryScopes",I=new Map,$e=()=>Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4),h=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),Re=/const __scope = |const __peers_* = |const _s = el\?\.scope|\?\.context\?\.globalScope\?\./,z=e=>{try{return(0,b.getFunctionSource)(e)}catch{return null}},J=e=>{if(typeof e!="function")return null;const n=z(e);return(0,f.isString)(n)&&Re.test(n)&&(0,b.hasFunction)(n)?n:null},H=e=>(0,f.isString)(e)&&(0,b.hasFunction)(e)||J(e)!==null,je=e=>{const n=e.globalScope;return(0,f.isObject)(n)&&Object.keys(n).some(o=>H(n[o]))?!0:E.some(o=>{const t=e[o];return!!t&&typeof t=="object"&&Object.keys(t).some(s=>H(t[s]))})},Ee=(e,n,o)=>{const t=e.globalScope,s=n.globalScope;if(o.has("globalScope")||!(0,f.isObject)(t)||!(0,f.isObject)(s)||!je(n))return 0;let i=0;for(const c of Object.keys(s))o.has(`globalScope/${c}`)||h(t,c)&&i++;return i},Ie=[[/const __scope = (\(\(\) => \{ const r = [\s\S]*?\}\)\(\));/g,"const __scope = $RESOLVE($1);"],[/const __scope = this \?\? \{\};/g,"const __scope = $RESOLVE(this ?? {});"],[/const (__peers_*) = (this && this !== globalThis && this\.context && this\.context\.globalScope \? this\.scope \?\? this\.context\.globalScope : this);/g,"const $1 = $RESOLVE($2);"],[/const _s = (el\?\.scope \?\? el\?\.context\?\.globalScope \?\? \{\});/g,"const _s = $RESOLVE($1);"],[/(?<![\w$.])(this|[A-Za-z_$][\w$]*)\?\.context\?\.globalScope\?\./g,"$RESOLVE($1?.context?.globalScope)?."]],Pe=e=>{const n=e.split(""),o=[];let t=0,s=0;const i=(r,l)=>{for(let p=r;p<l;p++)n[p]!==`
2
+ `&&(n[p]="~")},c=()=>{const r=t;for(;t<e.length;){const l=e[t];if(l==="\\"){t+=2;continue}if(l==="`"){i(r,t),t++;return}if(l==="$"&&e[t+1]==="{"){i(r,t),t+=2,o.push(s),s++;return}t++}i(r,t)};for(;t<e.length;){const r=e[t];if(r==="/"&&e[t+1]==="/"){const l=e.indexOf(`
3
+ `,t),p=l===-1?e.length:l;i(t,p),t=p;continue}if(r==="/"&&e[t+1]==="*"){const l=e.indexOf("*/",t+2),p=l===-1?e.length:l+2;i(t,p),t=p;continue}if(r==='"'||r==="'"){const l=r,p=++t;for(;t<e.length&&e[t]!==l&&e[t]!==`
4
+ `;)e[t]==="\\"&&t++,t++;i(p,t),t++;continue}if(r==="`"){t++,c();continue}if(r==="{"){s++,t++;continue}if(r==="}"){if(s--,o.length&&s===o[o.length-1]){o.pop(),t++,c();continue}t++;continue}t++}return n.join("")},q=(e,n)=>{if(!(0,f.isString)(e)||!e.includes("__scope = ")&&!e.includes("__peers")&&!e.includes("const _s = ")&&!e.includes("?.context?.globalScope?.")||!(0,b.hasFunction)(e))return e;const o=`(globalThis[Symbol.for('smbls.libraryScope')] || ((_, v) => v))(${JSON.stringify(n)}, `;let t=e;for(const[s,i]of Ie){const c=Pe(t);t=t.replace(s,(...r)=>{const l=r[r.length-2];return c[l]==="~"||c[l]!==t[l]?r[0]:i.replace(/\$RESOLVE\(/g,o).replace(/\$(\d)/g,(p,a)=>r[Number(a)])})}return t},w=(e,n)=>{if((0,f.isString)(e))return q(e,n);const o=J(e);return o===null?e:q(o,n)},Te={lazy:!0,window:globalThis},Z=(e,n)=>{const o=w(e,n);if(o===e||!(0,f.isString)(o))return o;try{const t=(0,b.deepDestringifyFunctions)({v:o},{},Te).v;return typeof t!="function"?o:(Object.defineProperty(t,"toJSON",{value:()=>o,configurable:!0}),t)}catch{return o}},P=e=>{if(!e||typeof e!="object")return!1;if(Array.isArray(e))return!0;const n=Object.getPrototypeOf(e);return n===Object.prototype||n===null},Q=(e,n,o=new WeakMap)=>{if((0,f.isString)(e)||typeof e=="function")return Z(e,n);if((0,b.isStringTag)(e)||!P(e))return e;if(o.has(e))return o.get(e);const t=Array.isArray(e)?[]:Object.getPrototypeOf(e)===null?Object.create(null):{};o.set(e,t);for(const s of Object.keys(e))t[s]=Q(e[s],n,o);return t},Be=(e,n)=>{const o={...e},t={};for(const s of Object.keys(e.globalScope))t[s]=w(e.globalScope[s],n);o.globalScope=t;for(const s of E){const i=e[s];if(!P(i))continue;const c={};for(const r of Object.keys(i))c[r]=Z(i[r],n);o[s]=c}for(const s of W)P(e[s])&&(o[s]=Q(e[s],n));return o},X=new WeakMap,Ce=(e,n,o)=>{let t=X.get(e);t||X.set(e,t=new Map);let s=t.get(n);if(s)return s;const i=(c,r)=>h(o,c)&&o[c]===r;return s=new Proxy(e,{get(c,r){if(typeof r=="symbol"||h(c,r))return Reflect.get(c,r);const l=Reflect.get(c,r);return h(n,r)&&(l===void 0||i(r,l))||l===void 0?n[r]:l},set(c,r,l){return typeof r!="symbol"&&!h(c,r)&&h(n,r)?(n[r]=l,!0):Reflect.set(c,r,l)},has:(c,r)=>Reflect.has(c,r)||r in n}),t.set(n,s),s},Me=e=>!!e&&typeof e=="object"&&!!e.__raw&&typeof e.__raw=="object",Ne=(e,n)=>{const o=I.get(e);return o?n===o.consumerGs?o.libGs:Me(n)?Ce(n,o.libGs,o.consumerGs):n:n},Fe=()=>{typeof globalThis[K]!="function"&&Object.defineProperty(globalThis,K,{value:Ne,configurable:!0})},O=e=>{const n=e[k];return Array.isArray(n)?n:null},T=e=>_(e)?e.library:e,Ve=(e,n,o)=>{const t=O(e);return!!t&&t.some(s=>s&&s.index===n&&(!s.key||s.key===o.key)&&(0,f.isString)(s.id)&&De(e,s.id))},De=(e,n)=>{const o=JSON.stringify(n),t=new Set,s=i=>{if((0,f.isString)(i))return i.includes(o);if(!i||typeof i!="object"||t.has(i))return!1;t.add(i);for(const c in i)if(s(i[c]))return!0;return!1};for(const i of["globalScope",...E,...W])if(s(e[i]))return!0;return!1},Ge=(e,n)=>{const o={};for(const t of Object.keys(e))o[t]=w(e[t],n);return o},v=new WeakMap,Ue=(e,n=null)=>{const o=e&&O(e);if(!o||!o.length)return 0;const t=e.globalScope;if(!(0,f.isObject)(t))return 0;const s=Array.isArray(e.sharedLibraries)?e.sharedLibraries:[];let i=v.get(t);i||v.set(t,i=new Set),Fe();let c=0;for(const r of o){if(!r||!(0,f.isString)(r.id)||i.has(r.id))continue;const l=T(s[r.index]);if(!l||!(0,f.isObject)(l.globalScope)||r.key&&l.key!==r.key)continue;const p=y=>typeof y=="function"?z(y):y,a=(y,m)=>{if(y===m)return!0;const C=p(y),M=p(m);return(0,f.isString)(C)||(0,f.isString)(M)?C===M:JSON.stringify(y)===JSON.stringify(m)},u=(0,f.isObject)(n)?(Array.isArray(r.landed)?r.landed:[]).filter(y=>(0,f.isString)(y)&&h(l.globalScope,y)&&h(n,y)&&a(n[y],w(l.globalScope[y],r.id))):[],d=(0,b.destringifyGlobalScope)(Ge(l.globalScope,r.id));Object.setPrototypeOf(d,t),I.set(r.id,{libGs:d,consumerGs:t});for(const y of u)t[y]=d[y];i.add(r.id),c++}return c},Ye=/^@symbo[-.]ls\//,x=e=>e.includes("/")?e.slice(e.indexOf("/")+1):e,ce=(e,n)=>{const o=[];if(!Array.isArray(e))return o;const t=new Map,s=(c,r,l)=>{for(const p of[`@symbo-ls/${c}`,`@symbo.ls/${c}`]){const a=t.get(p);if(a===void 0){t.set(p,r),o.push([p,r]);continue}a!==r&&l&&typeof n=="function"&&n({spec:p,kept:a,refused:r})}},i=[];for(const c of e){const r=T(c);if(!r||typeof r!="object"||r.__isStub)continue;const l=r.key||r.name||r.__libraryKey,p=[];for(const a of[r.key,r.name,r.__libraryKey,r.__libraryName]){if(typeof a!="string"||!a||a!==l&&!Ye.test(a))continue;const u=x(a);u&&!p.includes(u)&&p.push(u)}p.forEach((a,u)=>{u===0&&l&&x(l)===a?s(a,r,!1):i.push([a,r])})}for(const[c,r]of i)s(c,r,!0);return o},ae=({spec:e,kept:n,refused:o})=>{typeof console>"u"||console.warn(`[smbls] shared library "${o&&o.key}" also claims ${e}, which "${n&&n.key}" already owns; ${e} stays with "${n&&n.key}".`)},ee=["functions","methods","snippets"],le=Symbol.for("smbls.libraryPackages"),g=new WeakMap,We=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Ke=e=>({get globalScope(){return e()}}),te=(e,n,o)=>{const t={};for(const s of Object.keys(e))t[s]=e[s];return Object.defineProperty(t,"context",{configurable:!0,enumerable:!1,writable:!0,value:Ke(n)}),g.set(t,o),t},ne=e=>!We(e)||!g.has(e)&&Object.prototype.hasOwnProperty.call(e,"context"),ze=e=>{if(!e||typeof e!="object")return;const n=()=>e.globalScope;for(const t of ee){const s=e[t];ne(s)||g.get(s)===e||(e[t]=te(s,n,e))}if(Array.isArray(e.sharedLibraries)){const t=O(e)||[];e.sharedLibraries=e.sharedLibraries.map((s,i)=>{const c=_(s)&&s&&"library"in s,r=T(s);if(!r||typeof r!="object"||r.__isStub||g.get(r)===e)return s;const l=t.find(u=>u&&u.index===i&&(!u.key||u.key===r.key)),p=()=>{const u=l&&I.get(l.id);return u&&u.consumerGs===e.globalScope?u.libGs:e.globalScope},a={...r};for(const u of ee)ne(r[u])||(a[u]=te(r[u],p,e));return g.set(a,e),c?{...s,library:a}:a})}const o=e.globalScope;if(o&&typeof o=="object"){const t={};for(const[s,i]of ce(e.sharedLibraries,ae))t[s]=i;try{Object.defineProperty(o,le,{configurable:!0,enumerable:!1,writable:!0,value:t})}catch{}}},Je=(e,n,o,t="library",s=-1)=>{const i=Y(n,o),c=!Ve(e,s,n)&&Ee(e,n,i)>0?`${t}#${$e()}`:null,r=c?Be(n,c):n,l=c?new Set(Object.keys(e.globalScope)):null,p=[];for(const a in r)if(Object.prototype.hasOwnProperty.call(r,a)&&!(a==="sharePages"||a==="sharedLibIgnore")&&a!==k&&!a.startsWith("__")&&a!=="app"&&!i.has(a)){if((0,f.isObject)(r[a])&&(0,f.isObject)(e[a])){if(a==="designSystem")A(e[a],r[a],i,a);else for(const u in r[a])if(!i.has(`${a}/${u}`)){if(a==="methods"&&(0,L.isProtectedElementMethod)(u)){u in e[a]||p.push(u);continue}u in e[a]?F(a,e[a][u])&&!F(a,r[a][u])&&(e[a][u]=r[a][u]):e[a][u]=r[a][u]}}else if(!(a in e)){const u=r[a],d=a==="methods"&&u&&typeof u=="object"?Ae(u,i,p):u;e[a]=N(d,i,a)}}c&&(O(e)||(e[k]=[]),e[k].push({id:c,index:s,key:(0,f.isString)(n.key)?n.key:null,landed:Object.keys(r.globalScope).filter(a=>!l.has(a))})),p.length&&Le(t,p)},He=(e,n,o)=>{if(e!==n){const t=U(e);if((0,f.isString)(t)&&t)return t;if(e.key||e.name)return e.key||e.name}return n&&(n.key||n.name)||`sharedLibraries[${o}]`},qe=`${R}/default`,Ze=e=>(0,f.isString)(e)&&e!==""&&S(e).full===qe,Qe=(e,n)=>{if((0,f.isString)(n.key)&&n.key)return n.key;if(e!==n){if((0,f.isString)(e.key)&&e.key)return e.key;if((0,f.isString)(e.name)&&e.name)return e.name}return null},Xe=e=>{const n=[],o=[];for(let t=0;t<e.length;t++){const s=e[t];let i=s,c=Se;if(_(i)&&(c=B(i.ignoreList),i=i.library),!(0,f.isObject)(i))continue;const r={entry:s,lib:i,ignore:c,index:t};Ze(Qe(s,i))?o.push(r):n.push(r)}return{linked:n,bases:o}},oe=(e,n,o)=>{const t=D(n()),{linked:s,bases:i}=Xe(e);for(const r of s)o(r);const c=!t.size&&i.length?D(n()):null;for(const r of i)o(r);return t.size?t:c&&c.size?c:null},ve=(e,n)=>{if(!n||!n.length)return;const o=e.designSystem,t=oe(n,()=>e.designSystem,({entry:s,lib:i,ignore:c,index:r})=>Je(e,i,c,He(s,i,r),r));t&&(e.designSystem!==o&&(e.designSystem={...e.designSystem}),G(e.designSystem,t))},xe=(e,n,o=A)=>{if(!(0,f.isObject)(e)||!Array.isArray(n)||!n.length)return e;const t=oe(n,()=>e,({lib:s,ignore:i})=>{const c=s.designSystem;if(!c||typeof c!="object")return;const r=Y(s,i);r.has("designSystem")||o(e,c,r,"designSystem")});return t&&G(e,t),e};async function fe(e,n={}){if((n.provider||"kv")==="api")return se(e,n);const t=await et(e,n);return t||se(e,n)}async function et(e,n={}){const o=n.kvBaseUrl||me,t=n.env||"production",s=`${o}/kv/${encodeURIComponent(e)}?env=${t}`;try{const i=await fetch(s,{method:"GET"});return i.ok&&(await i.json())?.value||null}catch{return null}}async function se(e,n={}){const o=n.apiBaseUrl||ge,{key:t}=S(e);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(t)}&limit=10`,i=await fetch(s,{method:"GET"});if(!i.ok)return null;const c=await i.json(),l=(c?.items||c?.data||(Array.isArray(c)?c:[])).find(y=>{const{key:m}=S(y?.key);return m.toLowerCase()===t.toLowerCase()});if(!l?.id&&!l?._id)return null;const p=l.id||l._id,a=`${o}/core/projects/${encodeURIComponent(p)}/data?branch=main`,u=await fetch(a,{method:"GET"});if(!u.ok)return null;const d=await u.json();return d?.data||d||null}catch{return null}}async function re(e,n={}){if((0,f.isObject)(e))return e;if((0,f.isString)(e)){const{full:o}=S(e);if(!o)return null;try{const t=await fe(o,n);return t||console.warn(`[smbls] Shared library "${o}" not found`),t}catch(t){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,t.message),null}}return null}async function tt(e,n={}){return!e||!e.length?[]:(await Promise.all(e.map(async t=>{if(_(t)){const s=await re(U(t),n);return s?{library:s,ignoreList:t.ignoreList}:null}return re(t,n)}))).filter(Boolean)}
@@ -1,2 +1,2 @@
1
- import{isObject as A}from"./types.js";import{isStringFunction as w}from"./function.js";const g=n=>{if(n==null)return"";const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return n.toString().replace(/[&<>"']/g,t=>r[t])},O=n=>Object.entries(n||{}).filter(([r,t])=>t!==void 0).map(([r,t])=>`${r}="${g(t)}"`).join(" "),b=n=>{let r=5381;const t=String(n);for(let e=0;e<t.length;e++)r=(r*33^t.charCodeAt(e))>>>0;return r.toString(36)},L=new Set(["jsonLd","styles","scripts"]),E=n=>{const r=[];if(Array.isArray(n.jsonLd))for(const t of n.jsonLd){if(t==null)continue;const e=typeof t=="string"?t:JSON.stringify(t),i=String(e).replace(/<\/script/gi,"<\\/script");r.push(`<script type="application/ld+json" data-smbls-jsonld="${b(e)}">${i}<\/script>`)}if(Array.isArray(n.styles))for(const t of n.styles){if(t==null||!String(t).trim())continue;const e=String(t).replace(/<\/style/gi,"<\\/style");r.push(`<style data-smbls-style="${b(e)}">${e}</style>`)}if(Array.isArray(n.scripts))for(const t of n.scripts){if(!t)continue;const e=typeof t=="string",i=e?t:t.src;if(!i&&!t.body)continue;const o=[];i&&o.push(`src="${g(i)}"`),e||(t.type&&o.push(`type="${g(t.type)}"`),t.async&&o.push("async"),t.defer&&o.push("defer"),t.integrity&&o.push(`integrity="${g(t.integrity)}"`),t.crossorigin&&o.push(`crossorigin="${g(t.crossorigin)}"`),t.referrerpolicy&&o.push(`referrerpolicy="${g(t.referrerpolicy)}"`),t.nomodule&&o.push("nomodule"));const l=` data-smbls-script="${g(i||b(t.body||""))}"`;if(!e&&t.body){const h=String(t.body).replace(/<\/script/gi,"<\\/script");r.push(`<script ${o.join(" ")}${l}>${h}<\/script>`)}else r.push(`<script ${o.join(" ")}${l}><\/script>`)}return r},U=(n,r)=>{r||(n={...n,robots:"noindex"});const t=Object.entries(n).reduce((e,[i,o])=>{if(!o&&o!==0&&o!==!1||L.has(i))return e;if(i==="title")return e.push(`<title>${g(o)}</title>`),e;if(i==="canonical")return e.push(`<link rel="canonical" href="${g(o)}">`),e;if(i==="manifest")return e.push(`<link rel="manifest" href="${g(o)}">`),e;if(i==="favicon"||i==="favicons"||i==="icon"||i==="icons")return(Array.isArray(o)?o:[o]).forEach(c=>{if(typeof c=="string")e.push(`<link rel="icon" href="${g(c)}">`);else if(typeof c=="object"){const u=O(c);/rel=/.test(u)?e.push(`<link ${u}>`):e.push(`<link rel="icon" ${u}>`)}}),e;if(i==="alternate")return(Array.isArray(o)?o:[o]).forEach(c=>{if(typeof c=="object"){const u=Object.entries(c).filter(([s,p])=>p!==void 0).map(([s,p])=>`${s}="${g(p)}"`).join(" ");e.push(`<link rel="alternate" ${u}>`)}}),e;const l=(f,c,u="name")=>{if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")e.push(`<meta ${u}="${g(f)}" content="${g(c)}">`);else if(Array.isArray(c))c.forEach(s=>{if(typeof s=="string"||typeof s=="number"||typeof s=="boolean")e.push(`<meta ${u}="${g(f)}" content="${g(s)}">`);else if(typeof s=="object"){const p=Object.entries(s).filter(([m,a])=>a!==void 0).map(([m,a])=>`${m}="${g(a)}"`).join(" ");e.push(`<meta ${p}>`)}});else if(typeof c=="object"){const s=Object.entries(c).filter(([p,m])=>m!==void 0).map(([p,m])=>`${p}="${g(m)}"`).join(" ");e.push(`<meta ${s}>`)}};if(i.startsWith("http-equiv:")){const f=i.replace("http-equiv:","");return l(f,o,"http-equiv"),e}if(i.startsWith("itemprop:")){const f=i.replace("itemprop:","");return l(f,o,"itemprop"),e}const y=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(f=>i.startsWith(f));if(y){const f=i.replace(y,"");return l(`${y.replace(":","")}:${f}`,o,y==="twitter:"||y==="DC:"||y==="DCTERMS:"?"name":"property"),e}if(i.startsWith("apple:")||i.startsWith("msapplication:")){const f=i.startsWith("apple:")?"apple-":"msapplication-",c=i.replace(/^apple:|^msapplication:/,"");return l(`${f}${c}`,o,"name"),e}return l(i,o),e},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return t.push(...E(n)),t.join(`
2
- `)},W=n=>typeof n=="string"&&n.length>0&&!n.startsWith("/")&&!n.startsWith("http"),j=n=>typeof n=="string"&&n.length>0,x=n=>{if(!n||typeof n!="object")return null;if(j(n.src))return n.src;const r=n.content;return!r||typeof r!="object"?null:j(r.src)?r.src:j(r.storageUrl)?r.storageUrl:null};function T(n,r){if(!r||typeof r!="object")return n;const t=i=>!W(i)||!Object.prototype.hasOwnProperty.call(r,i)?i:x(r[i])||i,e={...n};for(const[i,o]of Object.entries(e))typeof o=="string"?e[i]=t(o):Array.isArray(o)&&(e[i]=o.map(l=>typeof l=="string"?t(l):l));return e}function S(n,r){if(!n||!r)return;const t=r.split(".");let e=n;for(const i of t){if(e==null||typeof e!="object")return;e=e[i]}return e}function F(n,r){const t=S(n,r);if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t=="string"&&!w(t))return t}function D(n,r,t){const i=(r.config||r.settings||{}).polyglot||r.polyglot,o=t?.lang||i?.defaultLang||"en",h=(i?.translations||{})[o]||{},y=[t?.state,r.state].filter(u=>u&&typeof u=="object"),f=u=>{for(const s of y){const p=F(s,u);if(p!==void 0)return p}},c={...n};for(const[u,s]of Object.entries(c))typeof s!="string"||!s.includes("{{")||(c[u]=s.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(p,m,a)=>{const d=m.trim();if(a==="polyglot")return h[d]??S(h,d)??p;if(a==="getLocalStateLang")return f(d+o)??p;const $=f(d);return $!==void 0?$:h[d]??S(h,d)??p}));return c}function M(n){if(!A(n))return{};const r={...n};for(const[t,e]of Object.entries(r))if(typeof e=="function"){const i=e.toString(),o=i.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[t]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const l=i.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(l){r[t]=`{{ ${l[1]} | polyglot }}`;continue}const h=i.match(/s\.(\w+(?:\.\w+)+)/);if(h){r[t]=`{{ ${h[1]} }}`;continue}delete r[t]}else if(typeof e=="string"){const i=e.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(i){r[t]=`{{ ${i[1]} | getLocalStateLang }}`;continue}const o=e.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[t]=`{{ ${o[1]} | polyglot }}`;continue}if(e.includes("=>")&&e.includes("s.")){const l=e.match(/s\.(\w+(?:\.\w+)+)/);if(l){r[t]=`{{ ${l[1]} }}`;continue}}w(e)&&delete r[t]}return r}function _(n,r,t,{isProduction:e=!1,channel:i="production"}={}){const o=n.pages?.[r],l=A(o?.state)&&o?.state,h=o?.metadata||o?.helmet||l||{},y=M(h),f=new Set(Object.keys(y)),c=n.app?.metadata||{},u=M(c);let s={};if(n.integrations?.seo?s={...n.integrations.seo,...u,...y}:Object.keys(u).length?s={...u,...y}:s={...y},!s.title){const a=n.name||n.key;a?e?s.title=a:i==="development"?s.title=`${a} / dev:symbo.ls`:i==="staging"?s.title=`${a} / staging:symbo.ls`:s.title=`${a} / symbo.ls`:s.title="Symbols demo"}s=D(s,n,t),s.title&&(f.has("title")||!s["og:title"])&&(f.has("og:title")||(s["og:title"]=s.title)),s.description&&(f.has("description")||!s["og:description"])&&(f.has("og:description")||(s["og:description"]=s.description)),s.title&&!s["twitter:title"]&&(s["twitter:title"]=s.title),s.description&&!s["twitter:description"]&&(s["twitter:description"]=s.description);const p=t?.actualPathname||r;if(s["og:url"]||s.url){const a=(s["og:url"]||s.url||"").replace(/\/$/,"");if(a&&p&&p!=="/"){const d=p.startsWith("/")?p:"/"+p;s["og:url"]=a+d}}s=T(s,n.files);const m=n.name||n.app?.metadata?.title||n.app?.name||"";for(const[a,d]of Object.entries(s))if(typeof d=="string"&&d.includes("{{")){const $=d.replace(/\{\{[^}]*\}\}/g,"").trim();$?s[a]=$:a==="title"?s[a]=m:delete s[a]}return s}export{x as fileEntryUrl,E as generateHeadArrayTags,U as generateMetaTags,_ as getPageMetadata,b as hashContent,T as resolveFileReferences};
1
+ import{isObject as b}from"./types.js";import{isStringFunction as M}from"./function.js";const p=e=>{if(e==null)return"";const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return e.toString().replace(/[&<>"']/g,t=>r[t])},L=e=>Object.entries(e||{}).filter(([r,t])=>t!==void 0).map(([r,t])=>`${r}="${p(t)}"`).join(" "),j=e=>{let r=5381;const t=String(e);for(let s=0;s<t.length;s++)r=(r*33^t.charCodeAt(s))>>>0;return r.toString(36)},E=new Set(["jsonLd","styles","scripts"]),W=e=>{const r=[];if(Array.isArray(e.jsonLd))for(const t of e.jsonLd){if(t==null)continue;const s=typeof t=="string"?t:JSON.stringify(t),i=String(s).replace(/<\/script/gi,"<\\/script");r.push(`<script type="application/ld+json" data-smbls-jsonld="${j(s)}">${i}<\/script>`)}if(Array.isArray(e.styles))for(const t of e.styles){if(t==null||!String(t).trim())continue;const s=String(t).replace(/<\/style/gi,"<\\/style");r.push(`<style data-smbls-style="${j(s)}">${s}</style>`)}if(Array.isArray(e.scripts))for(const t of e.scripts){if(!t)continue;const s=typeof t=="string",i=s?t:t.src;if(!i&&!t.body)continue;const o=[];i&&o.push(`src="${p(i)}"`),s||(t.type&&o.push(`type="${p(t.type)}"`),t.async&&o.push("async"),t.defer&&o.push("defer"),t.integrity&&o.push(`integrity="${p(t.integrity)}"`),t.crossorigin&&o.push(`crossorigin="${p(t.crossorigin)}"`),t.referrerpolicy&&o.push(`referrerpolicy="${p(t.referrerpolicy)}"`),t.nomodule&&o.push("nomodule"));const l=` data-smbls-script="${p(i||j(t.body||""))}"`;if(!s&&t.body){const d=String(t.body).replace(/<\/script/gi,"<\\/script");r.push(`<script ${o.join(" ")}${l}>${d}<\/script>`)}else r.push(`<script ${o.join(" ")}${l}><\/script>`)}return r},x=(e,r,t)=>e==="favicons"?Array.isArray(r)?typeof t=="string"?` data-smbls-favicon="${p(t)}"`:b(t)?` data-smbls-favicon="${j(JSON.stringify(t))}"`:"":"":(e==="icon"||e==="favicon")&&typeof r=="string"?` data-smbls-single-icon="${p(r)}"`:"",T=e=>b(e)?` data-smbls-alternate="${p(`${e.hreflang||""}|${e.href||""}`)}"`:"",q=(e,r)=>{r||(e={...e,robots:"noindex"});const t=Object.entries(e).reduce((s,[i,o])=>{if(!o&&o!==0&&o!==!1||E.has(i))return s;if(i==="title")return s.push(`<title>${p(o)}</title>`),s;if(i==="canonical")return s.push(`<link rel="canonical" href="${p(o)}">`),s;if(i==="manifest")return s.push(`<link rel="manifest" href="${p(o)}">`),s;if(i==="favicon"||i==="favicons"||i==="icon"||i==="icons")return(Array.isArray(o)?o:[o]).forEach(c=>{const u=x(i,o,c);if(typeof c=="string")s.push(`<link rel="icon" href="${p(c)}"${u}>`);else if(typeof c=="object"){const n=L(c);/rel=/.test(n)?s.push(`<link ${n}${u}>`):s.push(`<link rel="icon" ${n}${u}>`)}}),s;if(i==="alternate")return(Array.isArray(o)?o:[o]).forEach(c=>{if(c&&typeof c=="object"){const u=Object.entries(c).filter(([n,g])=>g!==void 0).map(([n,g])=>`${n}="${p(g)}"`).join(" ");s.push(`<link rel="alternate" ${u}${T(c)}>`)}}),s;const l=(f,c,u="name")=>{if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")s.push(`<meta ${u}="${p(f)}" content="${p(c)}">`);else if(Array.isArray(c))c.forEach(n=>{if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")s.push(`<meta ${u}="${p(f)}" content="${p(n)}">`);else if(typeof n=="object"){const g=Object.entries(n).filter(([y,$])=>$!==void 0).map(([y,$])=>`${y}="${p($)}"`).join(" ");s.push(`<meta ${g}>`)}});else if(typeof c=="object"){const n=Object.entries(c).filter(([g,y])=>y!==void 0).map(([g,y])=>`${g}="${p(y)}"`).join(" ");s.push(`<meta ${n}>`)}};if(i.startsWith("http-equiv:")){const f=i.replace("http-equiv:","");return l(f,o,"http-equiv"),s}if(i.startsWith("itemprop:")){const f=i.replace("itemprop:","");return l(f,o,"itemprop"),s}const h=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(f=>i.startsWith(f));if(h){const f=i.replace(h,"");return l(`${h.replace(":","")}:${f}`,o,h==="twitter:"||h==="DC:"||h==="DCTERMS:"?"name":"property"),s}if(i.startsWith("apple:")||i.startsWith("msapplication:")){const f=i.startsWith("apple:")?"apple-":"msapplication-",c=i.replace(/^apple:|^msapplication:/,"");return l(`${f}${c}`,o,"name"),s}return l(i,o),s},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return t.push(...W(e)),t.join(`
2
+ `)},F=e=>typeof e=="string"&&e.length>0&&!e.startsWith("/")&&!e.startsWith("http"),A=e=>typeof e=="string"&&e.length>0,K=e=>{if(!e||typeof e!="object")return null;if(A(e.src))return e.src;const r=e.content;return!r||typeof r!="object"?null:A(r.src)?r.src:A(r.storageUrl)?r.storageUrl:null};function U(e,r){if(!r||typeof r!="object")return e;const t=i=>!F(i)||!Object.prototype.hasOwnProperty.call(r,i)?i:K(r[i])||i,s={...e};for(const[i,o]of Object.entries(s))typeof o=="string"?s[i]=t(o):Array.isArray(o)&&(s[i]=o.map(l=>typeof l=="string"?t(l):l));return s}function S(e,r){if(!e||!r)return;const t=r.split(".");let s=e;for(const i of t){if(s==null||typeof s!="object")return;s=s[i]}return s}function D(e,r){const t=S(e,r);if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t=="string"&&!M(t))return t}function P(e,r,t){const i=(r.config||r.settings||{}).polyglot||r.polyglot,o=t?.lang||i?.defaultLang||"en",d=(i?.translations||{})[o]||{},h=[t?.state,r.state].filter(u=>u&&typeof u=="object"),f=u=>{for(const n of h){const g=D(n,u);if(g!==void 0)return g}},c={...e};for(const[u,n]of Object.entries(c))typeof n!="string"||!n.includes("{{")||(c[u]=n.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(g,y,$)=>{const a=y.trim();if($==="polyglot")return d[a]??S(d,a)??g;if($==="getLocalStateLang")return f(a+o)??g;const m=f(a);return m!==void 0?m:d[a]??S(d,a)??g}));return c}function O(e){if(!b(e))return{};const r={...e};for(const[t,s]of Object.entries(r))if(typeof s=="function"){const i=s.toString(),o=i.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[t]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const l=i.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(l){r[t]=`{{ ${l[1]} | polyglot }}`;continue}const d=i.match(/s\.(\w+(?:\.\w+)+)/);if(d){r[t]=`{{ ${d[1]} }}`;continue}delete r[t]}else if(typeof s=="string"){const i=s.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(i){r[t]=`{{ ${i[1]} | getLocalStateLang }}`;continue}const o=s.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[t]=`{{ ${o[1]} | polyglot }}`;continue}if(s.includes("=>")&&s.includes("s.")){const l=s.match(/s\.(\w+(?:\.\w+)+)/);if(l){r[t]=`{{ ${l[1]} }}`;continue}}M(s)&&delete r[t]}return r}function C(e,r,t,{isProduction:s=!1,channel:i="production"}={}){const o=e.pages?.[r],l=b(o?.state)&&o?.state,d=o?.metadata||o?.helmet||l||{},h=O(d),f=new Set(Object.keys(h)),c=e.app?.metadata||{},u=O(c);let n={};if(e.integrations?.seo?n={...e.integrations.seo,...u,...h}:Object.keys(u).length?n={...u,...h}:n={...h},!n.title){const a=e.name||e.key;a?s?n.title=a:i==="development"?n.title=`${a} / dev:symbo.ls`:i==="staging"?n.title=`${a} / staging:symbo.ls`:n.title=`${a} / symbo.ls`:n.title="Symbols demo"}n=P(n,e,t),n.title&&(f.has("title")||!n["og:title"])&&(f.has("og:title")||(n["og:title"]=n.title)),n.description&&(f.has("description")||!n["og:description"])&&(f.has("og:description")||(n["og:description"]=n.description)),n.title&&!n["twitter:title"]&&(n["twitter:title"]=n.title),n.description&&!n["twitter:description"]&&(n["twitter:description"]=n.description);const g=f.has("og:url")?n["og:url"]:f.has("url")?n.url:void 0,y=t?.actualPathname||r;if(g)n["og:url"]=g;else if(n["og:url"]||n.url){const a=(n["og:url"]||n.url||"").replace(/\/$/,"");if(a&&y&&y!=="/"){const m=y.startsWith("/")?y:"/"+y;n["og:url"]=a+m}}n=U(n,e.files);const $=e.name||e.app?.metadata?.title||e.app?.name||"";for(const[a,m]of Object.entries(n))if(typeof m=="string"&&m.includes("{{")){const w=m.replace(/\{\{[^}]*\}\}/g,"").trim();w?n[a]=w:a==="title"?n[a]=$:delete n[a]}return n}export{K as fileEntryUrl,W as generateHeadArrayTags,q as generateMetaTags,C as getPageMetadata,j as hashContent,U as resolveFileReferences};
@@ -1,4 +1,4 @@
1
- import{isObject as p,isString as y}from"./types.js";import{isProtectedElementMethod as _}from"./keys.js";import{isLoudDevRuntime as ee}from"./env.js";import{destringifyGlobalScope as te,hasFunction as w,getFunctionSource as ne,deepDestringifyFunctions as oe,isStringTag as se}from"./object.js";const O="system",re="https://smbls-kv.nika-980.workers.dev",ie="https://api.symbols.app";function g(e){const n=String(e||"").trim();if(!n)return{owner:O,key:"",full:""};let o=null,t=n;if(n.includes("/")){const i=n.indexOf("/");o=n.slice(0,i),t=n.slice(i+1)}t=t.replace(/\.symbo\.ls$/iu,""),o||(o=O);const s=t?`${o}/${t}`:"";return{owner:o,key:t,full:s}}const L=(e,n,o,t)=>{for(const s in n){const i=t?`${t}/${s}`:s;o&&o.has(i)||(s in e?p(e[s])&&p(n[s])&&L(e[s],n[s],o,i):e[s]=n[s])}},B=(e,n,o)=>{if(!p(e)||!n.size)return e;const t=`${o}/`;let s=!1;for(const c of n)if(c.startsWith(t)){s=!0;break}if(!s)return e;const i={};for(const c in e){if(!Object.prototype.hasOwnProperty.call(e,c))continue;const r=`${o}/${c}`;n.has(r)||(i[c]=B(e[c],n,r))}return i},ce=new Set,ae=new Set(["components","pages","functions","snippets","methods"]),P=(e,n)=>n===""&&ae.has(e),N=["fontFamily","fontfamily","font_family","FONT_FAMILY"],M=e=>{const n=new Map;if(!p(e))return n;for(const o of N){const t=e[o];if(p(t))for(const s in t)!p(t[s])||!t[s].isDefault||(n.has(o)||n.set(o,new Set),n.get(o).add(s))}return n},C=(e,n)=>{for(const o of N){const t=e[o];if(!p(t))continue;const s=n.get(o);let i=null;for(const c in t){const r=t[c];if(!p(r)||!r.isDefault||s&&s.has(c))continue;const a={...r};delete a.isDefault,i||(i={...t}),i[c]=a}i&&(e[o]=i)}},le=e=>e.replace(/\.js$/iu,""),F=e=>{const n=new Set;if(!Array.isArray(e))return n;for(const o of e){if(!y(o))continue;const t=o.split("/").map(s=>le(s.trim())).filter(Boolean).join("/");t&&n.add(t)}return n},De=(e,n={})=>({library:e,ignoreList:Array.isArray(n.ignoreList)?n.ignoreList:[]}),$=e=>p(e)&&Array.isArray(e.ignoreList)&&("library"in e||"key"in e||"name"in e),V=e=>e.library!==void 0?e.library:e.key??e.name,A=new Set,Ye=()=>{A.clear()},fe=(e,n)=>{const o=n.filter(t=>!A.has(t));if(o.length){for(const t of o)A.add(t);ee()&&console.warn(`[smbls] shared library "${e}" ships ${o.map(t=>`methods.${t}`).join(", ")} \u2014 named like a built-in element method. Refused: the built-in wins; a library cannot replace an element method on the consuming app. If the app wants this version, declare it in the app's OWN methods.`)}},ue=(e,n,o)=>{let t=null;for(const s in e)if(_(s)&&(n.has(`methods/${s}`)||o.push(s),!t)){t={};for(const i in e)_(i)||(t[i]=e[i])}return t||e},U=(e,n)=>{const o=F(e.sharedLibIgnore);return e.sharePages===!1&&o.add("pages"),o.size?new Set([...n,...o]):n},R=["functions","methods","snippets"],D=["components","pages"],Y=Symbol.for("smbls.libraryScope"),S="__libraryScopes",W=new Map,pe=()=>Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4),b=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),ye=/const __scope = |const __peers_* = |const _s = el\?\.scope|\?\.context\?\.globalScope\?\./,z=e=>{try{return ne(e)}catch{return null}},J=e=>{if(typeof e!="function")return null;const n=z(e);return y(n)&&ye.test(n)&&w(n)?n:null},G=e=>y(e)&&w(e)||J(e)!==null,de=e=>{const n=e.globalScope;return p(n)&&Object.keys(n).some(o=>G(n[o]))?!0:R.some(o=>{const t=e[o];return!!t&&typeof t=="object"&&Object.keys(t).some(s=>G(t[s]))})},he=(e,n,o)=>{const t=e.globalScope,s=n.globalScope;if(o.has("globalScope")||!p(t)||!p(s)||!de(n))return 0;let i=0;for(const c of Object.keys(s))o.has(`globalScope/${c}`)||b(t,c)&&i++;return i},be=[[/const __scope = (\(\(\) => \{ const r = [\s\S]*?\}\)\(\));/g,"const __scope = $RESOLVE($1);"],[/const __scope = this \?\? \{\};/g,"const __scope = $RESOLVE(this ?? {});"],[/const (__peers_*) = (this && this !== globalThis && this\.context && this\.context\.globalScope \? this\.scope \?\? this\.context\.globalScope : this);/g,"const $1 = $RESOLVE($2);"],[/const _s = (el\?\.scope \?\? el\?\.context\?\.globalScope \?\? \{\});/g,"const _s = $RESOLVE($1);"],[/(?<![\w$.])(this|[A-Za-z_$][\w$]*)\?\.context\?\.globalScope\?\./g,"$RESOLVE($1?.context?.globalScope)?."]],me=e=>{const n=e.split(""),o=[];let t=0,s=0;const i=(r,a)=>{for(let f=r;f<a;f++)n[f]!==`
2
- `&&(n[f]="~")},c=()=>{const r=t;for(;t<e.length;){const a=e[t];if(a==="\\"){t+=2;continue}if(a==="`"){i(r,t),t++;return}if(a==="$"&&e[t+1]==="{"){i(r,t),t+=2,o.push(s),s++;return}t++}i(r,t)};for(;t<e.length;){const r=e[t];if(r==="/"&&e[t+1]==="/"){const a=e.indexOf(`
3
- `,t),f=a===-1?e.length:a;i(t,f),t=f;continue}if(r==="/"&&e[t+1]==="*"){const a=e.indexOf("*/",t+2),f=a===-1?e.length:a+2;i(t,f),t=f;continue}if(r==='"'||r==="'"){const a=r,f=++t;for(;t<e.length&&e[t]!==a&&e[t]!==`
4
- `;)e[t]==="\\"&&t++,t++;i(f,t),t++;continue}if(r==="`"){t++,c();continue}if(r==="{"){s++,t++;continue}if(r==="}"){if(s--,o.length&&s===o[o.length-1]){o.pop(),t++,c();continue}t++;continue}t++}return n.join("")},K=(e,n)=>{if(!y(e)||!e.includes("__scope = ")&&!e.includes("__peers")&&!e.includes("const _s = ")&&!e.includes("?.context?.globalScope?.")||!w(e))return e;const o=`(globalThis[Symbol.for('smbls.libraryScope')] || ((_, v) => v))(${JSON.stringify(n)}, `;let t=e;for(const[s,i]of be){const c=me(t);t=t.replace(s,(...r)=>{const a=r[r.length-2];return c[a]==="~"||c[a]!==t[a]?r[0]:i.replace(/\$RESOLVE\(/g,o).replace(/\$(\d)/g,(f,l)=>r[Number(l)])})}return t},k=(e,n)=>{if(y(e))return K(e,n);const o=J(e);return o===null?e:K(o,n)},ge={lazy:!0,window:globalThis},q=(e,n)=>{const o=k(e,n);if(o===e||!y(o))return o;try{const t=oe({v:o},{},ge).v;return typeof t!="function"?o:(Object.defineProperty(t,"toJSON",{value:()=>o,configurable:!0}),t)}catch{return o}},E=e=>{if(!e||typeof e!="object")return!1;if(Array.isArray(e))return!0;const n=Object.getPrototypeOf(e);return n===Object.prototype||n===null},H=(e,n,o=new WeakMap)=>{if(y(e)||typeof e=="function")return q(e,n);if(se(e)||!E(e))return e;if(o.has(e))return o.get(e);const t=Array.isArray(e)?[]:Object.getPrototypeOf(e)===null?Object.create(null):{};o.set(e,t);for(const s of Object.keys(e))t[s]=H(e[s],n,o);return t},Se=(e,n)=>{const o={...e},t={};for(const s of Object.keys(e.globalScope))t[s]=k(e.globalScope[s],n);o.globalScope=t;for(const s of R){const i=e[s];if(!E(i))continue;const c={};for(const r of Object.keys(i))c[r]=q(i[r],n);o[s]=c}for(const s of D)E(e[s])&&(o[s]=H(e[s],n));return o},Z=new WeakMap,ke=(e,n,o)=>{let t=Z.get(e);t||Z.set(e,t=new Map);let s=t.get(n);if(s)return s;const i=(c,r)=>b(o,c)&&o[c]===r;return s=new Proxy(e,{get(c,r){if(typeof r=="symbol"||b(c,r))return Reflect.get(c,r);const a=Reflect.get(c,r);return b(n,r)&&(a===void 0||i(r,a))||a===void 0?n[r]:a},set(c,r,a){return typeof r!="symbol"&&!b(c,r)&&b(n,r)?(n[r]=a,!0):Reflect.set(c,r,a)},has:(c,r)=>Reflect.has(c,r)||r in n}),t.set(n,s),s},_e=e=>!!e&&typeof e=="object"&&!!e.__raw&&typeof e.__raw=="object",we=(e,n)=>{const o=W.get(e);return o?n===o.consumerGs?o.libGs:_e(n)?ke(n,o.libGs,o.consumerGs):n:n},Oe=()=>{typeof globalThis[Y]!="function"&&Object.defineProperty(globalThis,Y,{value:we,configurable:!0})},j=e=>{const n=e[S];return Array.isArray(n)?n:null},Le=e=>$(e)?e.library:e,$e=(e,n,o)=>{const t=j(e);return!!t&&t.some(s=>s&&s.index===n&&(!s.key||s.key===o.key)&&y(s.id)&&Ae(e,s.id))},Ae=(e,n)=>{const o=JSON.stringify(n),t=new Set,s=i=>{if(y(i))return i.includes(o);if(!i||typeof i!="object"||t.has(i))return!1;t.add(i);for(const c in i)if(s(i[c]))return!0;return!1};for(const i of["globalScope",...R,...D])if(s(e[i]))return!0;return!1},Re=(e,n)=>{const o={};for(const t of Object.keys(e))o[t]=k(e[t],n);return o},Q=new WeakMap,We=(e,n=null)=>{const o=e&&j(e);if(!o||!o.length)return 0;const t=e.globalScope;if(!p(t))return 0;const s=Array.isArray(e.sharedLibraries)?e.sharedLibraries:[];let i=Q.get(t);i||Q.set(t,i=new Set),Oe();let c=0;for(const r of o){if(!r||!y(r.id)||i.has(r.id))continue;const a=Le(s[r.index]);if(!a||!p(a.globalScope)||r.key&&a.key!==r.key)continue;const f=d=>typeof d=="function"?z(d):d,l=(d,m)=>{if(d===m)return!0;const I=f(d),T=f(m);return y(I)||y(T)?I===T:JSON.stringify(d)===JSON.stringify(m)},u=p(n)?(Array.isArray(r.landed)?r.landed:[]).filter(d=>y(d)&&b(a.globalScope,d)&&b(n,d)&&l(n[d],k(a.globalScope[d],r.id))):[],h=te(Re(a.globalScope,r.id));Object.setPrototypeOf(h,t),W.set(r.id,{libGs:h,consumerGs:t});for(const d of u)t[d]=h[d];i.add(r.id),c++}return c},Ee=(e,n,o,t="library",s=-1)=>{const i=U(n,o),c=!$e(e,s,n)&&he(e,n,i)>0?`${t}#${pe()}`:null,r=c?Se(n,c):n,a=c?new Set(Object.keys(e.globalScope)):null,f=[];for(const l in r)if(Object.prototype.hasOwnProperty.call(r,l)&&!(l==="sharePages"||l==="sharedLibIgnore")&&l!==S&&!l.startsWith("__")&&l!=="app"&&!i.has(l)){if(p(r[l])&&p(e[l])){if(l==="designSystem")L(e[l],r[l],i,l);else for(const u in r[l])if(!i.has(`${l}/${u}`)){if(l==="methods"&&_(u)){u in e[l]||f.push(u);continue}u in e[l]?P(l,e[l][u])&&!P(l,r[l][u])&&(e[l][u]=r[l][u]):e[l][u]=r[l][u]}}else if(!(l in e)){const u=r[l],h=l==="methods"&&u&&typeof u=="object"?ue(u,i,f):u;e[l]=B(h,i,l)}}c&&(j(e)||(e[S]=[]),e[S].push({id:c,index:s,key:y(n.key)?n.key:null,landed:Object.keys(r.globalScope).filter(l=>!a.has(l))})),f.length&&fe(t,f)},je=(e,n,o)=>{if(e!==n){const t=V(e);if(y(t)&&t)return t;if(e.key||e.name)return e.key||e.name}return n&&(n.key||n.name)||`sharedLibraries[${o}]`},Ie=`${O}/default`,Te=e=>y(e)&&e!==""&&g(e).full===Ie,Be=(e,n)=>{if(y(n.key)&&n.key)return n.key;if(e!==n){if(y(e.key)&&e.key)return e.key;if(y(e.name)&&e.name)return e.name}return null},Pe=e=>{const n=[],o=[];for(let t=0;t<e.length;t++){const s=e[t];let i=s,c=ce;if($(i)&&(c=F(i.ignoreList),i=i.library),!p(i))continue;const r={entry:s,lib:i,ignore:c,index:t};Te(Be(s,i))?o.push(r):n.push(r)}return{linked:n,bases:o}},X=(e,n,o)=>{const t=M(n()),{linked:s,bases:i}=Pe(e);for(const r of s)o(r);const c=!t.size&&i.length?M(n()):null;for(const r of i)o(r);return t.size?t:c&&c.size?c:null},ze=(e,n)=>{if(!n||!n.length)return;const o=e.designSystem,t=X(n,()=>e.designSystem,({entry:s,lib:i,ignore:c,index:r})=>Ee(e,i,c,je(s,i,r),r));t&&(e.designSystem!==o&&(e.designSystem={...e.designSystem}),C(e.designSystem,t))},Je=(e,n,o=L)=>{if(!p(e)||!Array.isArray(n)||!n.length)return e;const t=X(n,()=>e,({lib:s,ignore:i})=>{const c=s.designSystem;if(!c||typeof c!="object")return;const r=U(s,i);r.has("designSystem")||o(e,c,r,"designSystem")});return t&&C(e,t),e};async function Ne(e,n={}){if((n.provider||"kv")==="api")return x(e,n);const t=await Me(e,n);return t||x(e,n)}async function Me(e,n={}){const o=n.kvBaseUrl||re,t=n.env||"production",s=`${o}/kv/${encodeURIComponent(e)}?env=${t}`;try{const i=await fetch(s,{method:"GET"});return i.ok&&(await i.json())?.value||null}catch{return null}}async function x(e,n={}){const o=n.apiBaseUrl||ie,{key:t}=g(e);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(t)}&limit=10`,i=await fetch(s,{method:"GET"});if(!i.ok)return null;const c=await i.json(),a=(c?.items||c?.data||(Array.isArray(c)?c:[])).find(d=>{const{key:m}=g(d?.key);return m.toLowerCase()===t.toLowerCase()});if(!a?.id&&!a?._id)return null;const f=a.id||a._id,l=`${o}/core/projects/${encodeURIComponent(f)}/data?branch=main`,u=await fetch(l,{method:"GET"});if(!u.ok)return null;const h=await u.json();return h?.data||h||null}catch{return null}}async function v(e,n={}){if(p(e))return e;if(y(e)){const{full:o}=g(e);if(!o)return null;try{const t=await Ne(o,n);return t||console.warn(`[smbls] Shared library "${o}" not found`),t}catch(t){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,t.message),null}}return null}async function Ge(e,n={}){return!e||!e.length?[]:(await Promise.all(e.map(async t=>{if($(t)){const s=await v(V(t),n);return s?{library:s,ignoreList:t.ignoreList}:null}return v(t,n)}))).filter(Boolean)}export{S as LIBRARY_SCOPES_KEY,Ye as __resetBuiltinMethodWarnings,We as bindLibraryGlobalScopes,L as deepDefaults,Ne as fetchLibraryData,$ as isWrappedLibrary,ze as mergeSharedLibraries,Je as mergeSharedLibraryDesignSystems,F as normalizeIgnoreList,g as normalizeLibraryKey,Ge as resolveSharedLibraries,De as sharedLibrary};
1
+ import{isObject as p,isString as y}from"./types.js";import{isProtectedElementMethod as L}from"./keys.js";import{isLoudDevRuntime as ie}from"./env.js";import{destringifyGlobalScope as ce,hasFunction as A,getFunctionSource as ae,deepDestringifyFunctions as le,isStringTag as fe}from"./object.js";const $="system",ue="https://smbls-kv.nika-980.workers.dev",pe="https://api.symbols.app";function S(e){const n=String(e||"").trim();if(!n)return{owner:$,key:"",full:""};let o=null,t=n;if(n.includes("/")){const i=n.indexOf("/");o=n.slice(0,i),t=n.slice(i+1)}t=t.replace(/\.symbo\.ls$/iu,""),o||(o=$);const r=t?`${o}/${t}`:"";return{owner:o,key:t,full:r}}const R=(e,n,o,t)=>{for(const r in n){const i=t?`${t}/${r}`:r;o&&o.has(i)||(r in e?p(e[r])&&p(n[r])&&R(e[r],n[r],o,i):e[r]=n[r])}},M=(e,n,o)=>{if(!p(e)||!n.size)return e;const t=`${o}/`;let r=!1;for(const c of n)if(c.startsWith(t)){r=!0;break}if(!r)return e;const i={};for(const c in e){if(!Object.prototype.hasOwnProperty.call(e,c))continue;const s=`${o}/${c}`;n.has(s)||(i[c]=M(e[c],n,s))}return i},ye=new Set,be=new Set(["components","pages","functions","snippets","methods"]),N=(e,n)=>n===""&&be.has(e),F=["fontFamily","fontfamily","font_family","FONT_FAMILY"],V=e=>{const n=new Map;if(!p(e))return n;for(const o of F){const t=e[o];if(p(t))for(const r in t)!p(t[r])||!t[r].isDefault||(n.has(o)||n.set(o,new Set),n.get(o).add(r))}return n},D=(e,n)=>{for(const o of F){const t=e[o];if(!p(t))continue;const r=n.get(o);let i=null;for(const c in t){const s=t[c];if(!p(s)||!s.isDefault||r&&r.has(c))continue;const l={...s};delete l.isDefault,i||(i={...t}),i[c]=l}i&&(e[o]=i)}},de=e=>e.replace(/\.js$/iu,""),G=e=>{const n=new Set;if(!Array.isArray(e))return n;for(const o of e){if(!y(o))continue;const t=o.split("/").map(r=>de(r.trim())).filter(Boolean).join("/");t&&n.add(t)}return n},Xe=(e,n={})=>({library:e,ignoreList:Array.isArray(n.ignoreList)?n.ignoreList:[]}),_=e=>p(e)&&Array.isArray(e.ignoreList)&&("library"in e||"key"in e||"name"in e),U=e=>e.library!==void 0?e.library:e.key??e.name,j=new Set,ve=()=>{j.clear()},he=(e,n)=>{const o=n.filter(t=>!j.has(t));if(o.length){for(const t of o)j.add(t);ie()&&console.warn(`[smbls] shared library "${e}" ships ${o.map(t=>`methods.${t}`).join(", ")} \u2014 named like a built-in element method. Refused: the built-in wins; a library cannot replace an element method on the consuming app. If the app wants this version, declare it in the app's OWN methods.`)}},me=(e,n,o)=>{let t=null;for(const r in e)if(L(r)&&(n.has(`methods/${r}`)||o.push(r),!t)){t={};for(const i in e)L(i)||(t[i]=e[i])}return t||e},Y=(e,n)=>{const o=G(e.sharedLibIgnore);return e.sharePages===!1&&o.add("pages"),o.size?new Set([...n,...o]):n},E=["functions","methods","snippets"],W=["components","pages"],K=Symbol.for("smbls.libraryScope"),k="__libraryScopes",I=new Map,ge=()=>Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4),h=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),Se=/const __scope = |const __peers_* = |const _s = el\?\.scope|\?\.context\?\.globalScope\?\./,z=e=>{try{return ae(e)}catch{return null}},J=e=>{if(typeof e!="function")return null;const n=z(e);return y(n)&&Se.test(n)&&A(n)?n:null},H=e=>y(e)&&A(e)||J(e)!==null,_e=e=>{const n=e.globalScope;return p(n)&&Object.keys(n).some(o=>H(n[o]))?!0:E.some(o=>{const t=e[o];return!!t&&typeof t=="object"&&Object.keys(t).some(r=>H(t[r]))})},ke=(e,n,o)=>{const t=e.globalScope,r=n.globalScope;if(o.has("globalScope")||!p(t)||!p(r)||!_e(n))return 0;let i=0;for(const c of Object.keys(r))o.has(`globalScope/${c}`)||h(t,c)&&i++;return i},we=[[/const __scope = (\(\(\) => \{ const r = [\s\S]*?\}\)\(\));/g,"const __scope = $RESOLVE($1);"],[/const __scope = this \?\? \{\};/g,"const __scope = $RESOLVE(this ?? {});"],[/const (__peers_*) = (this && this !== globalThis && this\.context && this\.context\.globalScope \? this\.scope \?\? this\.context\.globalScope : this);/g,"const $1 = $RESOLVE($2);"],[/const _s = (el\?\.scope \?\? el\?\.context\?\.globalScope \?\? \{\});/g,"const _s = $RESOLVE($1);"],[/(?<![\w$.])(this|[A-Za-z_$][\w$]*)\?\.context\?\.globalScope\?\./g,"$RESOLVE($1?.context?.globalScope)?."]],Oe=e=>{const n=e.split(""),o=[];let t=0,r=0;const i=(s,l)=>{for(let u=s;u<l;u++)n[u]!==`
2
+ `&&(n[u]="~")},c=()=>{const s=t;for(;t<e.length;){const l=e[t];if(l==="\\"){t+=2;continue}if(l==="`"){i(s,t),t++;return}if(l==="$"&&e[t+1]==="{"){i(s,t),t+=2,o.push(r),r++;return}t++}i(s,t)};for(;t<e.length;){const s=e[t];if(s==="/"&&e[t+1]==="/"){const l=e.indexOf(`
3
+ `,t),u=l===-1?e.length:l;i(t,u),t=u;continue}if(s==="/"&&e[t+1]==="*"){const l=e.indexOf("*/",t+2),u=l===-1?e.length:l+2;i(t,u),t=u;continue}if(s==='"'||s==="'"){const l=s,u=++t;for(;t<e.length&&e[t]!==l&&e[t]!==`
4
+ `;)e[t]==="\\"&&t++,t++;i(u,t),t++;continue}if(s==="`"){t++,c();continue}if(s==="{"){r++,t++;continue}if(s==="}"){if(r--,o.length&&r===o[o.length-1]){o.pop(),t++,c();continue}t++;continue}t++}return n.join("")},q=(e,n)=>{if(!y(e)||!e.includes("__scope = ")&&!e.includes("__peers")&&!e.includes("const _s = ")&&!e.includes("?.context?.globalScope?.")||!A(e))return e;const o=`(globalThis[Symbol.for('smbls.libraryScope')] || ((_, v) => v))(${JSON.stringify(n)}, `;let t=e;for(const[r,i]of we){const c=Oe(t);t=t.replace(r,(...s)=>{const l=s[s.length-2];return c[l]==="~"||c[l]!==t[l]?s[0]:i.replace(/\$RESOLVE\(/g,o).replace(/\$(\d)/g,(u,a)=>s[Number(a)])})}return t},w=(e,n)=>{if(y(e))return q(e,n);const o=J(e);return o===null?e:q(o,n)},Le={lazy:!0,window:globalThis},Z=(e,n)=>{const o=w(e,n);if(o===e||!y(o))return o;try{const t=le({v:o},{},Le).v;return typeof t!="function"?o:(Object.defineProperty(t,"toJSON",{value:()=>o,configurable:!0}),t)}catch{return o}},P=e=>{if(!e||typeof e!="object")return!1;if(Array.isArray(e))return!0;const n=Object.getPrototypeOf(e);return n===Object.prototype||n===null},Q=(e,n,o=new WeakMap)=>{if(y(e)||typeof e=="function")return Z(e,n);if(fe(e)||!P(e))return e;if(o.has(e))return o.get(e);const t=Array.isArray(e)?[]:Object.getPrototypeOf(e)===null?Object.create(null):{};o.set(e,t);for(const r of Object.keys(e))t[r]=Q(e[r],n,o);return t},Ae=(e,n)=>{const o={...e},t={};for(const r of Object.keys(e.globalScope))t[r]=w(e.globalScope[r],n);o.globalScope=t;for(const r of E){const i=e[r];if(!P(i))continue;const c={};for(const s of Object.keys(i))c[s]=Z(i[s],n);o[r]=c}for(const r of W)P(e[r])&&(o[r]=Q(e[r],n));return o},X=new WeakMap,$e=(e,n,o)=>{let t=X.get(e);t||X.set(e,t=new Map);let r=t.get(n);if(r)return r;const i=(c,s)=>h(o,c)&&o[c]===s;return r=new Proxy(e,{get(c,s){if(typeof s=="symbol"||h(c,s))return Reflect.get(c,s);const l=Reflect.get(c,s);return h(n,s)&&(l===void 0||i(s,l))||l===void 0?n[s]:l},set(c,s,l){return typeof s!="symbol"&&!h(c,s)&&h(n,s)?(n[s]=l,!0):Reflect.set(c,s,l)},has:(c,s)=>Reflect.has(c,s)||s in n}),t.set(n,r),r},Re=e=>!!e&&typeof e=="object"&&!!e.__raw&&typeof e.__raw=="object",je=(e,n)=>{const o=I.get(e);return o?n===o.consumerGs?o.libGs:Re(n)?$e(n,o.libGs,o.consumerGs):n:n},Ee=()=>{typeof globalThis[K]!="function"&&Object.defineProperty(globalThis,K,{value:je,configurable:!0})},O=e=>{const n=e[k];return Array.isArray(n)?n:null},T=e=>_(e)?e.library:e,Ie=(e,n,o)=>{const t=O(e);return!!t&&t.some(r=>r&&r.index===n&&(!r.key||r.key===o.key)&&y(r.id)&&Pe(e,r.id))},Pe=(e,n)=>{const o=JSON.stringify(n),t=new Set,r=i=>{if(y(i))return i.includes(o);if(!i||typeof i!="object"||t.has(i))return!1;t.add(i);for(const c in i)if(r(i[c]))return!0;return!1};for(const i of["globalScope",...E,...W])if(r(e[i]))return!0;return!1},Te=(e,n)=>{const o={};for(const t of Object.keys(e))o[t]=w(e[t],n);return o},v=new WeakMap,xe=(e,n=null)=>{const o=e&&O(e);if(!o||!o.length)return 0;const t=e.globalScope;if(!p(t))return 0;const r=Array.isArray(e.sharedLibraries)?e.sharedLibraries:[];let i=v.get(t);i||v.set(t,i=new Set),Ee();let c=0;for(const s of o){if(!s||!y(s.id)||i.has(s.id))continue;const l=T(r[s.index]);if(!l||!p(l.globalScope)||s.key&&l.key!==s.key)continue;const u=b=>typeof b=="function"?z(b):b,a=(b,m)=>{if(b===m)return!0;const B=u(b),C=u(m);return y(B)||y(C)?B===C:JSON.stringify(b)===JSON.stringify(m)},f=p(n)?(Array.isArray(s.landed)?s.landed:[]).filter(b=>y(b)&&h(l.globalScope,b)&&h(n,b)&&a(n[b],w(l.globalScope[b],s.id))):[],d=ce(Te(l.globalScope,s.id));Object.setPrototypeOf(d,t),I.set(s.id,{libGs:d,consumerGs:t});for(const b of f)t[b]=d[b];i.add(s.id),c++}return c},Be=/^@symbo[-.]ls\//,x=e=>e.includes("/")?e.slice(e.indexOf("/")+1):e,Ce=(e,n)=>{const o=[];if(!Array.isArray(e))return o;const t=new Map,r=(c,s,l)=>{for(const u of[`@symbo-ls/${c}`,`@symbo.ls/${c}`]){const a=t.get(u);if(a===void 0){t.set(u,s),o.push([u,s]);continue}a!==s&&l&&typeof n=="function"&&n({spec:u,kept:a,refused:s})}},i=[];for(const c of e){const s=T(c);if(!s||typeof s!="object"||s.__isStub)continue;const l=s.key||s.name||s.__libraryKey,u=[];for(const a of[s.key,s.name,s.__libraryKey,s.__libraryName]){if(typeof a!="string"||!a||a!==l&&!Be.test(a))continue;const f=x(a);f&&!u.includes(f)&&u.push(f)}u.forEach((a,f)=>{f===0&&l&&x(l)===a?r(a,s,!1):i.push([a,s])})}for(const[c,s]of i)r(c,s,!0);return o},Me=({spec:e,kept:n,refused:o})=>{typeof console>"u"||console.warn(`[smbls] shared library "${o&&o.key}" also claims ${e}, which "${n&&n.key}" already owns; ${e} stays with "${n&&n.key}".`)},ee=["functions","methods","snippets"],Ne=Symbol.for("smbls.libraryPackages"),g=new WeakMap,Fe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Ve=e=>({get globalScope(){return e()}}),te=(e,n,o)=>{const t={};for(const r of Object.keys(e))t[r]=e[r];return Object.defineProperty(t,"context",{configurable:!0,enumerable:!1,writable:!0,value:Ve(n)}),g.set(t,o),t},ne=e=>!Fe(e)||!g.has(e)&&Object.prototype.hasOwnProperty.call(e,"context"),et=e=>{if(!e||typeof e!="object")return;const n=()=>e.globalScope;for(const t of ee){const r=e[t];ne(r)||g.get(r)===e||(e[t]=te(r,n,e))}if(Array.isArray(e.sharedLibraries)){const t=O(e)||[];e.sharedLibraries=e.sharedLibraries.map((r,i)=>{const c=_(r)&&r&&"library"in r,s=T(r);if(!s||typeof s!="object"||s.__isStub||g.get(s)===e)return r;const l=t.find(f=>f&&f.index===i&&(!f.key||f.key===s.key)),u=()=>{const f=l&&I.get(l.id);return f&&f.consumerGs===e.globalScope?f.libGs:e.globalScope},a={...s};for(const f of ee)ne(s[f])||(a[f]=te(s[f],u,e));return g.set(a,e),c?{...r,library:a}:a})}const o=e.globalScope;if(o&&typeof o=="object"){const t={};for(const[r,i]of Ce(e.sharedLibraries,Me))t[r]=i;try{Object.defineProperty(o,Ne,{configurable:!0,enumerable:!1,writable:!0,value:t})}catch{}}},De=(e,n,o,t="library",r=-1)=>{const i=Y(n,o),c=!Ie(e,r,n)&&ke(e,n,i)>0?`${t}#${ge()}`:null,s=c?Ae(n,c):n,l=c?new Set(Object.keys(e.globalScope)):null,u=[];for(const a in s)if(Object.prototype.hasOwnProperty.call(s,a)&&!(a==="sharePages"||a==="sharedLibIgnore")&&a!==k&&!a.startsWith("__")&&a!=="app"&&!i.has(a)){if(p(s[a])&&p(e[a])){if(a==="designSystem")R(e[a],s[a],i,a);else for(const f in s[a])if(!i.has(`${a}/${f}`)){if(a==="methods"&&L(f)){f in e[a]||u.push(f);continue}f in e[a]?N(a,e[a][f])&&!N(a,s[a][f])&&(e[a][f]=s[a][f]):e[a][f]=s[a][f]}}else if(!(a in e)){const f=s[a],d=a==="methods"&&f&&typeof f=="object"?me(f,i,u):f;e[a]=M(d,i,a)}}c&&(O(e)||(e[k]=[]),e[k].push({id:c,index:r,key:y(n.key)?n.key:null,landed:Object.keys(s.globalScope).filter(a=>!l.has(a))})),u.length&&he(t,u)},Ge=(e,n,o)=>{if(e!==n){const t=U(e);if(y(t)&&t)return t;if(e.key||e.name)return e.key||e.name}return n&&(n.key||n.name)||`sharedLibraries[${o}]`},Ue=`${$}/default`,Ye=e=>y(e)&&e!==""&&S(e).full===Ue,We=(e,n)=>{if(y(n.key)&&n.key)return n.key;if(e!==n){if(y(e.key)&&e.key)return e.key;if(y(e.name)&&e.name)return e.name}return null},Ke=e=>{const n=[],o=[];for(let t=0;t<e.length;t++){const r=e[t];let i=r,c=ye;if(_(i)&&(c=G(i.ignoreList),i=i.library),!p(i))continue;const s={entry:r,lib:i,ignore:c,index:t};Ye(We(r,i))?o.push(s):n.push(s)}return{linked:n,bases:o}},oe=(e,n,o)=>{const t=V(n()),{linked:r,bases:i}=Ke(e);for(const s of r)o(s);const c=!t.size&&i.length?V(n()):null;for(const s of i)o(s);return t.size?t:c&&c.size?c:null},tt=(e,n)=>{if(!n||!n.length)return;const o=e.designSystem,t=oe(n,()=>e.designSystem,({entry:r,lib:i,ignore:c,index:s})=>De(e,i,c,Ge(r,i,s),s));t&&(e.designSystem!==o&&(e.designSystem={...e.designSystem}),D(e.designSystem,t))},nt=(e,n,o=R)=>{if(!p(e)||!Array.isArray(n)||!n.length)return e;const t=oe(n,()=>e,({lib:r,ignore:i})=>{const c=r.designSystem;if(!c||typeof c!="object")return;const s=Y(r,i);s.has("designSystem")||o(e,c,s,"designSystem")});return t&&D(e,t),e};async function ze(e,n={}){if((n.provider||"kv")==="api")return se(e,n);const t=await Je(e,n);return t||se(e,n)}async function Je(e,n={}){const o=n.kvBaseUrl||ue,t=n.env||"production",r=`${o}/kv/${encodeURIComponent(e)}?env=${t}`;try{const i=await fetch(r,{method:"GET"});return i.ok&&(await i.json())?.value||null}catch{return null}}async function se(e,n={}){const o=n.apiBaseUrl||pe,{key:t}=S(e);try{const r=`${o}/core/projects/libraries/available?search=${encodeURIComponent(t)}&limit=10`,i=await fetch(r,{method:"GET"});if(!i.ok)return null;const c=await i.json(),l=(c?.items||c?.data||(Array.isArray(c)?c:[])).find(b=>{const{key:m}=S(b?.key);return m.toLowerCase()===t.toLowerCase()});if(!l?.id&&!l?._id)return null;const u=l.id||l._id,a=`${o}/core/projects/${encodeURIComponent(u)}/data?branch=main`,f=await fetch(a,{method:"GET"});if(!f.ok)return null;const d=await f.json();return d?.data||d||null}catch{return null}}async function re(e,n={}){if(p(e))return e;if(y(e)){const{full:o}=S(e);if(!o)return null;try{const t=await ze(o,n);return t||console.warn(`[smbls] Shared library "${o}" not found`),t}catch(t){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,t.message),null}}return null}async function ot(e,n={}){return!e||!e.length?[]:(await Promise.all(e.map(async t=>{if(_(t)){const r=await re(U(t),n);return r?{library:r,ignoreList:t.ignoreList}:null}return re(t,n)}))).filter(Boolean)}export{Ne as LIBRARY_PACKAGES,k as LIBRARY_SCOPES_KEY,ve as __resetBuiltinMethodWarnings,xe as bindLibraryGlobalScopes,R as deepDefaults,et as exposeBagGlobalScopes,ze as fetchLibraryData,_ as isWrappedLibrary,Ce as libraryPackageSpecs,tt as mergeSharedLibraries,nt as mergeSharedLibraryDesignSystems,G as normalizeIgnoreList,S as normalizeLibraryKey,ot as resolveSharedLibraries,Xe as sharedLibrary,Me as warnLibraryAliasCollision};
package/metadata.js CHANGED
@@ -115,6 +115,33 @@ export const generateHeadArrayTags = (metadata) => {
115
115
  return tags
116
116
  }
117
117
 
118
+ /**
119
+ * The `data-smbls-*` key the client runtime reconciles a link tag by —
120
+ * `@symbo.ls/helmet` renderIcon (`icon` / `favicon`: one href string),
121
+ * renderFavicons (each `favicons` entry: a string's own value, a plain object's
122
+ * content hash) and renderAlternate (each `alternate` entry: `hreflang|href`).
123
+ * Unkeyed, a hydrating client could not take a served tag over: it added a
124
+ * keyed copy of every icon and hreflang link, and a page's served alternates
125
+ * stayed on every page after it. helmet's SSR builder (`generateHeadHtml`)
126
+ * emits the same keys. A shape the client never renders (`icons`, an icon
127
+ * array, a lone `favicons` value) stays unkeyed, so the client never owns it.
128
+ */
129
+ const iconKeyAttr = (key, value, item) => {
130
+ if (key === 'favicons') {
131
+ if (!Array.isArray(value)) return ''
132
+ if (typeof item === 'string') return ` data-smbls-favicon="${escapeHtml(item)}"`
133
+ if (isObject(item)) return ` data-smbls-favicon="${hashContent(JSON.stringify(item))}"`
134
+ return ''
135
+ }
136
+ if ((key === 'icon' || key === 'favicon') && typeof value === 'string') {
137
+ return ` data-smbls-single-icon="${escapeHtml(value)}"`
138
+ }
139
+ return ''
140
+ }
141
+
142
+ const alternateKeyAttr = (alt) =>
143
+ isObject(alt) ? ` data-smbls-alternate="${escapeHtml(`${alt.hreflang || ''}|${alt.href || ''}`)}"` : ''
144
+
118
145
  /**
119
146
  * Generates HTML meta tags from a flat metadata object.
120
147
  * Works on both server (SSR head injection) and client (dynamic meta updates).
@@ -152,14 +179,15 @@ export const generateMetaTags = (metadata, isProduction) => {
152
179
  if (key === 'favicon' || key === 'favicons' || key === 'icon' || key === 'icons') {
153
180
  const items = Array.isArray(value) ? value : [value]
154
181
  items.forEach((item) => {
182
+ const keyAttr = iconKeyAttr(key, value, item)
155
183
  if (typeof item === 'string') {
156
- acc.push(`<link rel="icon" href="${escapeHtml(item)}">`)
184
+ acc.push(`<link rel="icon" href="${escapeHtml(item)}"${keyAttr}>`)
157
185
  } else if (typeof item === 'object') {
158
186
  const attrs = buildAttrs(item)
159
187
  if (!/rel=/.test(attrs)) {
160
- acc.push(`<link rel="icon" ${attrs}>`)
188
+ acc.push(`<link rel="icon" ${attrs}${keyAttr}>`)
161
189
  } else {
162
- acc.push(`<link ${attrs}>`)
190
+ acc.push(`<link ${attrs}${keyAttr}>`)
163
191
  }
164
192
  }
165
193
  })
@@ -169,12 +197,13 @@ export const generateMetaTags = (metadata, isProduction) => {
169
197
  if (key === 'alternate') {
170
198
  const alternates = Array.isArray(value) ? value : [value]
171
199
  alternates.forEach((alt) => {
172
- if (typeof alt === 'object') {
200
+ // A null entry threw (Object.entries(null)); the client skips it.
201
+ if (alt && typeof alt === 'object') {
173
202
  const attrs = Object.entries(alt)
174
203
  .filter(([_, attrValue]) => attrValue !== undefined)
175
204
  .map(([attrKey, attrValue]) => `${attrKey}="${escapeHtml(attrValue)}"`)
176
205
  .join(' ')
177
- acc.push(`<link rel="alternate" ${attrs}>`)
206
+ acc.push(`<link rel="alternate" ${attrs}${alternateKeyAttr(alt)}>`)
178
207
  }
179
208
  })
180
209
  return acc
@@ -556,9 +585,18 @@ export function getPageMetadata (data, pathname, ssrContext, { isProduction = fa
556
585
  merged['twitter:description'] = merged.description
557
586
  }
558
587
 
559
- // Make og:url route-aware — use actual pathname if available
588
+ // og:url is route-aware only as a BASE — helmet extractMetadata's rule. An
589
+ // app-level or integrations.seo og:url (or `url`) gets the actual path; a
590
+ // page's own og:url (or `url` alias) names that page already and stays as
591
+ // written. Appending the path to it doubled it: a detail page's
592
+ // `{{ item.url }}` served `…/blog/abc/blog/abc`.
593
+ const pageUrl = pageExplicitKeys.has('og:url')
594
+ ? merged['og:url']
595
+ : (pageExplicitKeys.has('url') ? merged.url : undefined)
560
596
  const routeForUrl = ssrContext?.actualPathname || pathname
561
- if (merged['og:url'] || merged.url) {
597
+ if (pageUrl) {
598
+ merged['og:url'] = pageUrl
599
+ } else if (merged['og:url'] || merged.url) {
562
600
  const baseUrl = (merged['og:url'] || merged.url || '').replace(/\/$/, '')
563
601
  if (baseUrl && routeForUrl && routeForUrl !== '/') {
564
602
  const cleanRoute = routeForUrl.startsWith('/') ? routeForUrl : '/' + routeForUrl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/utils",
3
- "version": "3.14.783",
3
+ "version": "3.14.784",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
49
49
  "peerDependencies": {
50
- "@symbo.ls/fetch": "^3.14.656"
50
+ "@symbo.ls/fetch": "^3.14.662"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "@symbo.ls/fetch": {
@@ -742,6 +742,149 @@ export const bindLibraryGlobalScopes = (context, mergedGlobalScope = null) => {
742
742
  return n
743
743
  }
744
744
 
745
+ // ── a library's package names ─────────────────────────────────────────────
746
+ //
747
+ // frank emits a declared-library import as a registry read under the
748
+ // specifier the source used: `@symbo-ls/<record key>` or the npm name
749
+ // (`@symbo-ls/workspace-shared`). A library is known by its PRIMARY name
750
+ // (`key || name || __libraryKey`, any form) and by every npm-scoped
751
+ // identifier it carries (`__libraryName`, stamped by frank at the library's
752
+ // push; `__libraryKey`/`name` when scoped). Every primary registers before any
753
+ // alias, so a library cannot take a slot another library owns by record key;
754
+ // an alias two libraries claim stays with the first and is reported.
755
+ const NPM_SCOPED_LIBRARY_ID_RE = /^@symbo[-.]ls\//
756
+ const bareLibraryKey = (raw) => (raw.includes('/') ? raw.slice(raw.indexOf('/') + 1) : raw)
757
+
758
+ /**
759
+ * Ordered [spec, library] pairs for `libraries` (entries or wrappers), stubs
760
+ * skipped. `onCollision({ spec, kept, refused })` is called for an alias a
761
+ * later library could not take.
762
+ */
763
+ export const libraryPackageSpecs = (libraries, onCollision) => {
764
+ const out = []
765
+ if (!Array.isArray(libraries)) return out
766
+ const owner = new Map()
767
+ const take = (key, lib, isAlias) => {
768
+ for (const spec of [`@symbo-ls/${key}`, `@symbo.ls/${key}`]) {
769
+ const have = owner.get(spec)
770
+ if (have === undefined) { owner.set(spec, lib); out.push([spec, lib]); continue }
771
+ if (have !== lib && isAlias && typeof onCollision === 'function') onCollision({ spec, kept: have, refused: lib })
772
+ }
773
+ }
774
+ const aliases = []
775
+ for (const entry of libraries) {
776
+ const lib = unwrapLibrary(entry)
777
+ if (!lib || typeof lib !== 'object' || lib.__isStub) continue
778
+ const primary = lib.key || lib.name || lib.__libraryKey
779
+ const keys = []
780
+ for (const raw of [lib.key, lib.name, lib.__libraryKey, lib.__libraryName]) {
781
+ if (typeof raw !== 'string' || !raw) continue
782
+ if (raw !== primary && !NPM_SCOPED_LIBRARY_ID_RE.test(raw)) continue
783
+ const key = bareLibraryKey(raw)
784
+ if (key && !keys.includes(key)) keys.push(key)
785
+ }
786
+ keys.forEach((key, i) => {
787
+ if (i === 0 && primary && bareLibraryKey(primary) === key) take(key, lib, false)
788
+ else aliases.push([key, lib])
789
+ })
790
+ }
791
+ for (const [key, lib] of aliases) take(key, lib, true)
792
+ return out
793
+ }
794
+
795
+ export const warnLibraryAliasCollision = ({ spec, kept, refused }) => {
796
+ if (typeof console === 'undefined') return
797
+ console.warn(`[smbls] shared library "${refused && refused.key}" also claims ${spec}, which "${kept && kept.key}" already owns; ${spec} stays with "${kept && kept.key}".`)
798
+ }
799
+
800
+ // ── a code bag as receiver ────────────────────────────────────────────────
801
+ //
802
+ // frank's peer statements derive the globalScope from the receiver
803
+ // (`r.scope ?? r.context.globalScope ?? r`). A function reached THROUGH a bag —
804
+ // a declared-library facade (`_wsShared.functions.applyA11yPrefs(...)`, emitted
805
+ // as `__scope.___wsShared.functions.applyA11yPrefs(...)`), or project code
806
+ // calling `el.context.functions.x(...)` — runs with the bag as `this`, which has
807
+ // neither, so every peer read was undefined (`__scope.wsA11yWindow is not a
808
+ // function` in applyA11yPrefs on the served dev shell, 2026-10-07).
809
+ //
810
+ // Everything is PER CONTEXT and nothing is global:
811
+ // - the context's own bags are always COPIES bound to this context (never a
812
+ // library's bag the merge may have reused, never one another context owns);
813
+ // - each `sharedLibraries` entry becomes a per-context VIEW (shallow copy)
814
+ // whose bags are copies answering the library's isolated globalScope in this
815
+ // context (else this context's globalScope); the library object is never
816
+ // mutated;
817
+ // - the views are published on THIS context's globalScope under the
818
+ // non-enumerable `Symbol.for('smbls.libraryPackages')` map (spec -> view).
819
+ // frank's facades read it first (`this` is the globalScope, an element scope
820
+ // chained to it, or an element whose `context.globalScope` carries it), then
821
+ // the process-global `__SMBLS_PKGS__` registry, which keeps RAW library
822
+ // objects only — no context is ever reachable from a global (SSR: one
823
+ // process, many requests).
824
+ const CODE_BAGS_WITH_RECEIVER = ['functions', 'methods', 'snippets']
825
+ export const LIBRARY_PACKAGES = Symbol.for('smbls.libraryPackages')
826
+ const bagOwners = new WeakMap()
827
+
828
+ const isBag = (bag) => !!bag && typeof bag === 'object' && !Array.isArray(bag)
829
+
830
+ const receiverContextFor = (readGlobalScope) => ({
831
+ get globalScope () { return readGlobalScope() }
832
+ })
833
+
834
+ const boundCopy = (bag, readGlobalScope, owner) => {
835
+ const copy = {}
836
+ for (const key of Object.keys(bag)) copy[key] = bag[key]
837
+ Object.defineProperty(copy, 'context', {
838
+ configurable: true,
839
+ enumerable: false,
840
+ writable: true,
841
+ value: receiverContextFor(readGlobalScope)
842
+ })
843
+ bagOwners.set(copy, owner)
844
+ return copy
845
+ }
846
+
847
+ // A bag we did not bind that has its own `context` KEY is the project's data.
848
+ const keepAsIs = (bag) => !isBag(bag) || (!bagOwners.has(bag) && Object.prototype.hasOwnProperty.call(bag, 'context'))
849
+
850
+ export const exposeBagGlobalScopes = (context) => {
851
+ if (!context || typeof context !== 'object') return
852
+ const ownGs = () => context.globalScope
853
+ for (const bag of CODE_BAGS_WITH_RECEIVER) {
854
+ const cur = context[bag]
855
+ if (keepAsIs(cur) || bagOwners.get(cur) === context) continue
856
+ context[bag] = boundCopy(cur, ownGs, context)
857
+ }
858
+ if (Array.isArray(context.sharedLibraries)) {
859
+ const records = libraryScopeRecordsOf(context) || []
860
+ context.sharedLibraries = context.sharedLibraries.map((entry, index) => {
861
+ const wrapped = isWrappedLibrary(entry) && entry && 'library' in entry
862
+ const lib = unwrapLibrary(entry)
863
+ if (!lib || typeof lib !== 'object' || lib.__isStub) return entry
864
+ if (bagOwners.get(lib) === context) return entry // already this context's view
865
+ const rec = records.find((r) => r && r.index === index && (!r.key || r.key === lib.key))
866
+ const readGlobalScope = () => {
867
+ const bound = rec && libraryScopes.get(rec.id)
868
+ return bound && bound.consumerGs === context.globalScope ? bound.libGs : context.globalScope
869
+ }
870
+ const view = { ...lib }
871
+ for (const bag of CODE_BAGS_WITH_RECEIVER) {
872
+ if (!keepAsIs(lib[bag])) view[bag] = boundCopy(lib[bag], readGlobalScope, context)
873
+ }
874
+ bagOwners.set(view, context)
875
+ return wrapped ? { ...entry, library: view } : view
876
+ })
877
+ }
878
+ const gs = context.globalScope
879
+ if (gs && typeof gs === 'object') {
880
+ const map = {}
881
+ for (const [spec, view] of libraryPackageSpecs(context.sharedLibraries, warnLibraryAliasCollision)) map[spec] = view
882
+ try {
883
+ Object.defineProperty(gs, LIBRARY_PACKAGES, { configurable: true, enumerable: false, writable: true, value: map })
884
+ } catch (_) {} // frozen globalScope: facades fall back to the global registry
885
+ }
886
+ }
887
+
745
888
  const mergeOneLibrary = (context, library, ignore, label = 'library', index = -1) => {
746
889
  const skip = librarySkip(library, ignore)
747
890
  // a library sharing a globalScope name keeps its own (see above)