@symbo.ls/utils 3.14.702 → 3.14.735

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,17 @@
1
1
  # @symbo.ls/utils
2
2
 
3
+ ## 3.14.735
4
+
5
+ ### Patch Changes
6
+
7
+ - Auto-generated cross-repo patch release.
8
+
9
+ ## 3.14.707
10
+
11
+ ### Patch Changes
12
+
13
+ - Auto-generated cross-repo patch release.
14
+
3
15
  ## 3.14.702
4
16
 
5
17
  ### Patch Changes
package/cdn.js CHANGED
@@ -1,9 +1,5 @@
1
1
  'use strict'
2
2
 
3
- function onlyDotsAndNumbers (str) {
4
- return /^[0-9.]+$/.test(str) && str !== ''
5
- }
6
-
7
3
  export const CDN_PROVIDERS = {
8
4
  skypack: {
9
5
  url: 'https://cdn.skypack.dev',
@@ -25,14 +21,25 @@ export const CDN_PROVIDERS = {
25
21
  formatUrl: (pkg, version) =>
26
22
  `${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version !== 'latest' ? `@${version}` : ''}/+esm`
27
23
  },
24
+ // pkg.symbo.ls — our own proxy (server/workers/packages). It is a raw file
25
+ // PASSTHROUGH (GCS bucket → jsDelivr → unpkg), not a CJS→ESM transformer,
26
+ // so the artifact you get is entirely decided by the path you ask for:
27
+ //
28
+ // /smbls@3.14.706 → jsDelivr's default file = dist/smbls.iife.js
29
+ // /smbls@3.14.706/+esm → jsDelivr's ESM build ✅ importable
30
+ //
31
+ // This provider previously emitted the bare/`/<version>.js` forms, both of
32
+ // which resolve to the IIFE — `var Smbls=(()=>{…})()`, a script with zero
33
+ // exports. Any `import … from 'smbls'` against an importmap built that way
34
+ // fails at link time, and `smbls init --runtime browser` scaffolds shipped
35
+ // exactly that. `/+esm` is jsDelivr's on-the-fly ESM transform and works
36
+ // for CJS-only third-party packages too (js-beautify, prismjs, lottie-web
37
+ // all verified), which is what makes this a complete esm.sh replacement on
38
+ // a domain we control rather than a smbls-only special case.
28
39
  symbols: {
29
40
  url: 'https://pkg.symbo.ls',
30
- formatUrl: (pkg, version) => {
31
- if (pkg.split('/').length > 2 || !onlyDotsAndNumbers(version)) {
32
- return `${CDN_PROVIDERS.symbols.url}/${pkg}`
33
- }
34
- return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version}.js`
35
- }
41
+ formatUrl: (pkg, version) =>
42
+ `${CDN_PROVIDERS.symbols.url}/${pkg}${version !== 'latest' ? `@${version}` : ''}/+esm`
36
43
  }
37
44
  }
38
45
 
@@ -77,15 +84,29 @@ export const getCDNUrl = (
77
84
  * bundle onto the page as raw HTML (tickets/smbls.md — the ~355KB "fake
78
85
  * importmap" bug). Splitting the tag here means neither the source nor any
79
86
  * minified/bundled copy of it ever carries that literal substring.
87
+ *
88
+ * `options.pin` — `{ [pkgName]: version }` — overrides the version declared in
89
+ * the project's dependencies. A host that INJECTS a runtime into the page must
90
+ * pin the matching importmap entry to the version it injected, or the page
91
+ * carries two different copies of the same package: one inlined, one resolved
92
+ * from whatever the registry's floating tag points at that hour. Deployed
93
+ * *.at.symbo.ls pages shipped `"smbls": "latest"` against an inlined IIFE from
94
+ * a months-old pin, and the client half moved 683 → 704 in a single evening
95
+ * under already-published sites (tickets/smbls.md).
80
96
  */
81
- export const getImportMapScript = (data, defaultProvider = 'skypack') => {
97
+ export const getImportMapScript = (
98
+ data,
99
+ defaultProvider = 'skypack',
100
+ options = {}
101
+ ) => {
82
102
  const dependencies = data.dependencies || {}
83
103
  const keys = Object.keys(dependencies)
84
104
  if (!keys.length) return ''
85
105
 
106
+ const pin = options.pin || {}
86
107
  const imports = {}
87
108
  for (const pkgName of keys) {
88
- const version = dependencies[pkgName] || 'latest'
109
+ const version = pin[pkgName] || dependencies[pkgName] || 'latest'
89
110
  imports[pkgName] = getCDNUrl(pkgName, version, defaultProvider)
90
111
  }
91
112
 
package/dist/cjs/cdn.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var p=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=(s,t)=>{for(var r in t)p(s,r,{get:t[r],enumerable:!0})},f=(s,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!g.call(s,n)&&n!==r&&p(s,n,{get:()=>t[n],enumerable:!(o=i(t,n))||o.enumerable});return s};var h=s=>f(p({},"__esModule",{value:!0}),s);var N={};y(N,{CDN_PROVIDERS:()=>e,PACKAGE_MANAGER_TO_CDN:()=>c,getCDNUrl:()=>m,getCdnProviderFromConfig:()=>C,getImportMapScript:()=>j});module.exports=h(N);function b(s){return/^[0-9.]+$/.test(s)&&s!==""}const e={skypack:{url:"https://cdn.skypack.dev",formatUrl:(s,t)=>`${e.skypack.url}/${s}${t!=="latest"?`@${t}`:""}`},esmsh:{url:"https://esm.sh",formatUrl:(s,t)=>`${e.esmsh.url}/${s}${t!=="latest"?`@${t}`:""}`},unpkg:{url:"https://unpkg.com",formatUrl:(s,t)=>`${e.unpkg.url}/${s}${t!=="latest"?`@${t}`:""}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(s,t)=>`${e.jsdelivr.url}/${s}${t!=="latest"?`@${t}`:""}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(s,t)=>s.split("/").length>2||!b(t)?`${e.symbols.url}/${s}`:`${e.symbols.url}/${s}/${t}.js`}},c={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},C=(s={})=>{const{packageManager:t}=s;return c[t]||null},m=(s,t="latest",r="esmsh")=>(e[r]||e.esmsh).formatUrl(s,t),j=(s,t="skypack")=>{const r=s.dependencies||{},o=Object.keys(r);if(!o.length)return"";const n={};for(const l of o){const k=r[l]||"latest";n[l]=m(l,k,t)}const u='<script type="importmap">',a="<\/script>",$=`{
2
- "imports": ${JSON.stringify(n,null,2)}
3
- }`;return`${u}${$}${a}`};
1
+ "use strict";var p=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(t,s)=>{for(var e in s)p(t,e,{get:s[e],enumerable:!0})},C=(t,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of y(s))!f.call(t,r)&&r!==e&&p(t,r,{get:()=>s[r],enumerable:!(n=d(s,r))||n.enumerable});return t};var b=t=>C(p({},"__esModule",{value:!0}),t);var N={};h(N,{CDN_PROVIDERS:()=>o,PACKAGE_MANAGER_TO_CDN:()=>m,getCDNUrl:()=>a,getCdnProviderFromConfig:()=>U,getImportMapScript:()=>j});module.exports=b(N);const o={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s)=>`${o.skypack.url}/${t}${s!=="latest"?`@${s}`:""}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s)=>`${o.esmsh.url}/${t}${s!=="latest"?`@${s}`:""}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s)=>`${o.unpkg.url}/${t}${s!=="latest"?`@${s}`:""}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s)=>`${o.jsdelivr.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s)=>`${o.symbols.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`}},m={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},U=(t={})=>{const{packageManager:s}=t;return m[s]||null},a=(t,s="latest",e="esmsh")=>(o[e]||o.esmsh).formatUrl(t,s),j=(t,s="skypack",e={})=>{const n=t.dependencies||{},r=Object.keys(n);if(!r.length)return"";const $=e.pin||{},c={};for(const l of r){const i=$[l]||n[l]||"latest";c[l]=a(l,i,s)}const k='<script type="importmap">',u="<\/script>",g=`{
2
+ "imports": ${JSON.stringify(c,null,2)}
3
+ }`;return`${k}${g}${u}`};
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var j=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R(e))!U.call(n,i)&&i!==t&&u(n,i,{get:()=>e[i],enumerable:!(r=A(e,i))||r.enumerable});return n};var S=n=>I(u({},"__esModule",{value:!0}),n);var K={};j(K,{deepDefaults:()=>f,fetchLibraryData:()=>k,isWrappedLibrary:()=>p,mergeSharedLibraries:()=>T,normalizeIgnoreList:()=>d,normalizeLibraryKey:()=>c,resolveSharedLibraries:()=>G,sharedLibrary:()=>P});module.exports=S(K);var s=require("./types.js");const h="system",E="https://smbls-kv.nika-980.workers.dev",_="https://api.symbols.app";function c(n){const e=String(n||"").trim();if(!e)return{owner:h,key:"",full:""};let t=null,r=e;if(e.includes("/")){const o=e.indexOf("/");t=e.slice(0,o),r=e.slice(o+1)}r=r.replace(/\.symbo\.ls$/iu,""),t||(t=h);const i=r?`${t}/${r}`:"";return{owner:t,key:r,full:i}}const f=(n,e,t,r)=>{for(const i in e){const o=r?`${r}/${i}`:i;t&&t.has(o)||(i in n?(0,s.isObject)(n[i])&&(0,s.isObject)(e[i])&&f(n[i],e[i],t,o):n[i]=e[i])}},O=new Set,B=n=>n.replace(/\.js$/iu,""),d=n=>{const e=new Set;if(!Array.isArray(n))return e;for(const t of n){if(!(0,s.isString)(t))continue;const r=t.split("/").map(i=>B(i.trim())).filter(Boolean).join("/");r&&e.add(r)}return e},P=(n,e={})=>({library:n,ignoreList:Array.isArray(e.ignoreList)?e.ignoreList:[]}),p=n=>(0,s.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),x=n=>n.library!==void 0?n.library:n.key??n.name,C=(n,e,t)=>{const r=d(e.sharedLibIgnore);e.sharePages===!1&&r.add("pages");const i=r.size?new Set([...t,...r]):t;for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)&&!(o==="sharePages"||o==="sharedLibIgnore")&&!i.has(o))if((0,s.isObject)(e[o])&&(0,s.isObject)(n[o]))if(o==="designSystem")f(n[o],e[o],i,o);else for(const a in e[o])i.has(`${o}/${a}`)||a in n[o]||(n[o][a]=e[o][a]);else o in n||(n[o]=e[o])},T=(n,e)=>{if(!(!e||!e.length))for(let t=0;t<e.length;t++){let r=e[t],i=O;p(r)&&(i=d(r.ignoreList),r=r.library),(0,s.isObject)(r)&&C(n,r,i)}};async function k(n,e={}){if((e.provider||"kv")==="api")return b(n,e);const r=await F(n,e);return r||b(n,e)}async function F(n,e={}){const t=e.kvBaseUrl||E,r=e.env||"production",i=`${t}/kv/${encodeURIComponent(n)}?env=${r}`;try{const o=await fetch(i,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function b(n,e={}){const t=e.apiBaseUrl||_,{key:r}=c(n);try{const i=`${t}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,o=await fetch(i,{method:"GET"});if(!o.ok)return null;const a=await o.json(),l=(a?.items||a?.data||(Array.isArray(a)?a:[])).find(g=>{const{key:$}=c(g?.key);return $.toLowerCase()===r.toLowerCase()});if(!l?.id&&!l?._id)return null;const L=l.id||l._id,v=`${t}/core/projects/${encodeURIComponent(L)}/data?branch=main`,y=await fetch(v,{method:"GET"});if(!y.ok)return null;const m=await y.json();return m?.data||m||null}catch{return null}}async function w(n,e={}){if((0,s.isObject)(n))return n;if((0,s.isString)(n)){const{full:t}=c(n);if(!t)return null;try{const r=await k(t,e);return r||console.warn(`[smbls] Shared library "${t}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${t}":`,r.message),null}}return null}async function G(n,e={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(p(r)){const i=await w(x(r),e);return i?{library:i,ignoreList:r.ignoreList}:null}return w(r,e)}))).filter(Boolean)}
1
+ "use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var e in t)u(n,e,{get:t[e],enumerable:!0})},E=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of R(t))!U.call(n,o)&&o!==e&&u(n,o,{get:()=>t[o],enumerable:!(r=j(t,o))||r.enumerable});return n};var O=n=>E(u({},"__esModule",{value:!0}),n);var N={};S(N,{deepDefaults:()=>d,fetchLibraryData:()=>k,isWrappedLibrary:()=>y,mergeSharedLibraries:()=>F,normalizeIgnoreList:()=>p,normalizeLibraryKey:()=>l,resolveSharedLibraries:()=>K,sharedLibrary:()=>C});module.exports=O(N);var a=require("./types.js");const b="system",_="https://smbls-kv.nika-980.workers.dev",P="https://api.symbols.app";function l(n){const t=String(n||"").trim();if(!t)return{owner:b,key:"",full:""};let e=null,r=t;if(t.includes("/")){const s=t.indexOf("/");e=t.slice(0,s),r=t.slice(s+1)}r=r.replace(/\.symbo\.ls$/iu,""),e||(e=b);const o=r?`${e}/${r}`:"";return{owner:e,key:r,full:o}}const d=(n,t,e,r)=>{for(const o in t){const s=r?`${r}/${o}`:o;e&&e.has(s)||(o in n?(0,a.isObject)(n[o])&&(0,a.isObject)(t[o])&&d(n[o],t[o],e,s):n[o]=t[o])}},w=(n,t,e)=>{if(!(0,a.isObject)(n)||!t.size)return n;const r=`${e}/`;let o=!1;for(const i of t)if(i.startsWith(r)){o=!0;break}if(!o)return n;const s={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const f=`${e}/${i}`;t.has(f)||(s[i]=w(n[i],t,f))}return s},B=new Set,x=n=>n.replace(/\.js$/iu,""),p=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const e of n){if(!(0,a.isString)(e))continue;const r=e.split("/").map(o=>x(o.trim())).filter(Boolean).join("/");r&&t.add(r)}return t},C=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),y=n=>(0,a.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),T=n=>n.library!==void 0?n.library:n.key??n.name,z=(n,t,e)=>{const r=p(t.sharedLibIgnore);t.sharePages===!1&&r.add("pages");const o=r.size?new Set([...e,...r]):e;for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&!(s==="sharePages"||s==="sharedLibIgnore")&&!o.has(s))if((0,a.isObject)(t[s])&&(0,a.isObject)(n[s]))if(s==="designSystem")d(n[s],t[s],o,s);else for(const i in t[s])o.has(`${s}/${i}`)||i in n[s]||(n[s][i]=t[s][i]);else s in n||(n[s]=w(t[s],o,s))},F=(n,t)=>{if(!(!t||!t.length))for(let e=0;e<t.length;e++){let r=t[e],o=B;y(r)&&(o=p(r.ignoreList),r=r.library),(0,a.isObject)(r)&&z(n,r,o)}};async function k(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const r=await G(n,t);return r||$(n,t)}async function G(n,t={}){const e=t.kvBaseUrl||_,r=t.env||"production",o=`${e}/kv/${encodeURIComponent(n)}?env=${r}`;try{const s=await fetch(o,{method:"GET"});return s.ok&&(await s.json())?.value||null}catch{return null}}async function $(n,t={}){const e=t.apiBaseUrl||P,{key:r}=l(n);try{const o=`${e}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,s=await fetch(o,{method:"GET"});if(!s.ok)return null;const i=await s.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(v=>{const{key:I}=l(v?.key);return I.toLowerCase()===r.toLowerCase()});if(!c?.id&&!c?._id)return null;const L=c.id||c._id,A=`${e}/core/projects/${encodeURIComponent(L)}/data?branch=main`,h=await fetch(A,{method:"GET"});if(!h.ok)return null;const m=await h.json();return m?.data||m||null}catch{return null}}async function g(n,t={}){if((0,a.isObject)(n))return n;if((0,a.isString)(n)){const{full:e}=l(n);if(!e)return null;try{const r=await k(e,t);return r||console.warn(`[smbls] Shared library "${e}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${e}":`,r.message),null}}return null}async function K(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(y(r)){const o=await g(T(r),t);return o?{library:o,ignoreList:r.ignoreList}:null}return g(r,t)}))).filter(Boolean)}
package/dist/esm/cdn.js CHANGED
@@ -1,3 +1,3 @@
1
- function a(t){return/^[0-9.]+$/.test(t)&&t!==""}const r={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s)=>`${r.skypack.url}/${t}${s!=="latest"?`@${s}`:""}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s)=>`${r.esmsh.url}/${t}${s!=="latest"?`@${s}`:""}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s)=>`${r.unpkg.url}/${t}${s!=="latest"?`@${s}`:""}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s)=>`${r.jsdelivr.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s)=>t.split("/").length>2||!a(s)?`${r.symbols.url}/${t}`:`${r.symbols.url}/${t}/${s}.js`}},$={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},i=(t={})=>{const{packageManager:s}=t;return $[s]||null},k=(t,s="latest",e="esmsh")=>(r[e]||r.esmsh).formatUrl(t,s),d=(t,s="skypack")=>{const e=t.dependencies||{},n=Object.keys(e);if(!n.length)return"";const l={};for(const o of n){const u=e[o]||"latest";l[o]=k(o,u,s)}const p='<script type="importmap">',c="<\/script>",m=`{
2
- "imports": ${JSON.stringify(l,null,2)}
3
- }`;return`${p}${m}${c}`};export{r as CDN_PROVIDERS,$ as PACKAGE_MANAGER_TO_CDN,k as getCDNUrl,i as getCdnProviderFromConfig,d as getImportMapScript};
1
+ const e={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s)=>`${e.skypack.url}/${t}${s!=="latest"?`@${s}`:""}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s)=>`${e.esmsh.url}/${t}${s!=="latest"?`@${s}`:""}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s)=>`${e.unpkg.url}/${t}${s!=="latest"?`@${s}`:""}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s)=>`${e.jsdelivr.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s)=>`${e.symbols.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`}},u={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},i=(t={})=>{const{packageManager:s}=t;return u[s]||null},g=(t,s="latest",o="esmsh")=>(e[o]||e.esmsh).formatUrl(t,s),d=(t,s="skypack",o={})=>{const n=t.dependencies||{},l=Object.keys(n);if(!l.length)return"";const c=o.pin||{},p={};for(const r of l){const k=c[r]||n[r]||"latest";p[r]=g(r,k,s)}const m='<script type="importmap">',a="<\/script>",$=`{
2
+ "imports": ${JSON.stringify(p,null,2)}
3
+ }`;return`${m}${$}${a}`};export{e as CDN_PROVIDERS,u as PACKAGE_MANAGER_TO_CDN,g as getCDNUrl,i as getCdnProviderFromConfig,d as getImportMapScript};
@@ -1 +1 @@
1
- import{isObject as a,isString as d}from"./types.js";const p="system",$="https://smbls-kv.nika-980.workers.dev",A="https://api.symbols.app";function c(n){const e=String(n||"").trim();if(!e)return{owner:p,key:"",full:""};let t=null,r=e;if(e.includes("/")){const i=e.indexOf("/");t=e.slice(0,i),r=e.slice(i+1)}r=r.replace(/\.symbo\.ls$/iu,""),t||(t=p);const o=r?`${t}/${r}`:"";return{owner:t,key:r,full:o}}const y=(n,e,t,r)=>{for(const o in e){const i=r?`${r}/${o}`:o;t&&t.has(i)||(o in n?a(n[o])&&a(e[o])&&y(n[o],e[o],t,i):n[o]=e[o])}},R=new Set,U=n=>n.replace(/\.js$/iu,""),m=n=>{const e=new Set;if(!Array.isArray(n))return e;for(const t of n){if(!d(t))continue;const r=t.split("/").map(o=>U(o.trim())).filter(Boolean).join("/");r&&e.add(r)}return e},B=(n,e={})=>({library:n,ignoreList:Array.isArray(e.ignoreList)?e.ignoreList:[]}),h=n=>a(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),j=n=>n.library!==void 0?n.library:n.key??n.name,I=(n,e,t)=>{const r=m(e.sharedLibIgnore);e.sharePages===!1&&r.add("pages");const o=r.size?new Set([...t,...r]):t;for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&!(i==="sharePages"||i==="sharedLibIgnore")&&!o.has(i))if(a(e[i])&&a(n[i]))if(i==="designSystem")y(n[i],e[i],o,i);else for(const s in e[i])o.has(`${i}/${s}`)||s in n[i]||(n[i][s]=e[i][s]);else i in n||(n[i]=e[i])},P=(n,e)=>{if(!(!e||!e.length))for(let t=0;t<e.length;t++){let r=e[t],o=R;h(r)&&(o=m(r.ignoreList),r=r.library),a(r)&&I(n,r,o)}};async function S(n,e={}){if((e.provider||"kv")==="api")return b(n,e);const r=await E(n,e);return r||b(n,e)}async function E(n,e={}){const t=e.kvBaseUrl||$,r=e.env||"production",o=`${t}/kv/${encodeURIComponent(n)}?env=${r}`;try{const i=await fetch(o,{method:"GET"});return i.ok&&(await i.json())?.value||null}catch{return null}}async function b(n,e={}){const t=e.apiBaseUrl||A,{key:r}=c(n);try{const o=`${t}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,i=await fetch(o,{method:"GET"});if(!i.ok)return null;const s=await i.json(),l=(s?.items||s?.data||(Array.isArray(s)?s:[])).find(v=>{const{key:g}=c(v?.key);return g.toLowerCase()===r.toLowerCase()});if(!l?.id&&!l?._id)return null;const k=l.id||l._id,L=`${t}/core/projects/${encodeURIComponent(k)}/data?branch=main`,u=await fetch(L,{method:"GET"});if(!u.ok)return null;const f=await u.json();return f?.data||f||null}catch{return null}}async function w(n,e={}){if(a(n))return n;if(d(n)){const{full:t}=c(n);if(!t)return null;try{const r=await S(t,e);return r||console.warn(`[smbls] Shared library "${t}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${t}":`,r.message),null}}return null}async function x(n,e={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(h(r)){const o=await w(j(r),e);return o?{library:o,ignoreList:r.ignoreList}:null}return w(r,e)}))).filter(Boolean)}export{y as deepDefaults,S as fetchLibraryData,h as isWrappedLibrary,P as mergeSharedLibraries,m as normalizeIgnoreList,c as normalizeLibraryKey,x as resolveSharedLibraries,B as sharedLibrary};
1
+ import{isObject as a,isString as p}from"./types.js";const y="system",I="https://smbls-kv.nika-980.workers.dev",j="https://api.symbols.app";function f(n){const t=String(n||"").trim();if(!t)return{owner:y,key:"",full:""};let e=null,r=t;if(t.includes("/")){const o=t.indexOf("/");e=t.slice(0,o),r=t.slice(o+1)}r=r.replace(/\.symbo\.ls$/iu,""),e||(e=y);const s=r?`${e}/${r}`:"";return{owner:e,key:r,full:s}}const h=(n,t,e,r)=>{for(const s in t){const o=r?`${r}/${s}`:s;e&&e.has(o)||(s in n?a(n[s])&&a(t[s])&&h(n[s],t[s],e,o):n[s]=t[s])}},m=(n,t,e)=>{if(!a(n)||!t.size)return n;const r=`${e}/`;let s=!1;for(const i of t)if(i.startsWith(r)){s=!0;break}if(!s)return n;const o={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const l=`${e}/${i}`;t.has(l)||(o[i]=m(n[i],t,l))}return o},R=new Set,U=n=>n.replace(/\.js$/iu,""),b=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const e of n){if(!p(e))continue;const r=e.split("/").map(s=>U(s.trim())).filter(Boolean).join("/");r&&t.add(r)}return t},B=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),w=n=>a(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),S=n=>n.library!==void 0?n.library:n.key??n.name,E=(n,t,e)=>{const r=b(t.sharedLibIgnore);t.sharePages===!1&&r.add("pages");const s=r.size?new Set([...e,...r]):e;for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&!(o==="sharePages"||o==="sharedLibIgnore")&&!s.has(o))if(a(t[o])&&a(n[o]))if(o==="designSystem")h(n[o],t[o],s,o);else for(const i in t[o])s.has(`${o}/${i}`)||i in n[o]||(n[o][i]=t[o][i]);else o in n||(n[o]=m(t[o],s,o))},x=(n,t)=>{if(!(!t||!t.length))for(let e=0;e<t.length;e++){let r=t[e],s=R;w(r)&&(s=b(r.ignoreList),r=r.library),a(r)&&E(n,r,s)}};async function O(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const r=await _(n,t);return r||$(n,t)}async function _(n,t={}){const e=t.kvBaseUrl||I,r=t.env||"production",s=`${e}/kv/${encodeURIComponent(n)}?env=${r}`;try{const o=await fetch(s,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function $(n,t={}){const e=t.apiBaseUrl||j,{key:r}=f(n);try{const s=`${e}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,o=await fetch(s,{method:"GET"});if(!o.ok)return null;const i=await o.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(A=>{const{key:v}=f(A?.key);return v.toLowerCase()===r.toLowerCase()});if(!c?.id&&!c?._id)return null;const k=c.id||c._id,L=`${e}/core/projects/${encodeURIComponent(k)}/data?branch=main`,u=await fetch(L,{method:"GET"});if(!u.ok)return null;const d=await u.json();return d?.data||d||null}catch{return null}}async function g(n,t={}){if(a(n))return n;if(p(n)){const{full:e}=f(n);if(!e)return null;try{const r=await O(e,t);return r||console.warn(`[smbls] Shared library "${e}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${e}":`,r.message),null}}return null}async function C(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(w(r)){const s=await g(S(r),t);return s?{library:s,ignoreList:r.ignoreList}:null}return g(r,t)}))).filter(Boolean)}export{h as deepDefaults,O as fetchLibraryData,w as isWrappedLibrary,x as mergeSharedLibraries,b as normalizeIgnoreList,f as normalizeLibraryKey,C as resolveSharedLibraries,B as sharedLibrary};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/utils",
3
- "version": "3.14.702",
3
+ "version": "3.14.735",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -60,6 +60,49 @@ export const deepDefaults = (target, source, ignore, prefix) => {
60
60
  }
61
61
  }
62
62
 
63
+ /**
64
+ * Recursively drop any subtree of `value` whose '/'-joined path (relative to
65
+ * `prefix`) is in `skip`. Used by `mergeOneLibrary`'s wholesale-copy branch:
66
+ * when the consumer has NO object at all at a top-level key, the whole
67
+ * section is copied in one shot — a nested `sharedLibIgnore` path declared
68
+ * under that key (e.g. 'functions/router') must be honored there too, not
69
+ * only in the per-key defaults-fill branch below. Recurses to whatever depth
70
+ * the ignore path names — `normalizeIgnoreList` has no depth cap, so a
71
+ * library author's declaration stays private regardless of which merge
72
+ * branch a given consumer happens to hit.
73
+ *
74
+ * Returns `value` unchanged (same reference) whenever nothing under `prefix`
75
+ * is ignored — the common case — so this never allocates when there is
76
+ * nothing to filter.
77
+ *
78
+ * @param {*} value - the subtree being wholesale-copied
79
+ * @param {Set<string>} skip - normalized '/'-joined ignore paths (whole-key
80
+ * entries already short-circuited by the caller before this runs)
81
+ * @param {string} prefix - the top-level key this subtree lives under
82
+ */
83
+ const copyWithNestedIgnores = (value, skip, prefix) => {
84
+ if (!isObject(value) || !skip.size) return value
85
+
86
+ const branchPrefix = `${prefix}/`
87
+ let hasNestedIgnore = false
88
+ for (const path of skip) {
89
+ if (path.startsWith(branchPrefix)) {
90
+ hasNestedIgnore = true
91
+ break
92
+ }
93
+ }
94
+ if (!hasNestedIgnore) return value
95
+
96
+ const copy = {}
97
+ for (const k in value) {
98
+ if (!Object.prototype.hasOwnProperty.call(value, k)) continue
99
+ const path = `${prefix}/${k}`
100
+ if (skip.has(path)) continue
101
+ copy[k] = copyWithNestedIgnores(value[k], skip, path)
102
+ }
103
+ return copy
104
+ }
105
+
63
106
  const EMPTY_IGNORE = new Set()
64
107
 
65
108
  const stripJsExt = (segment) => segment.replace(/\.js$/iu, '')
@@ -151,7 +194,7 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
151
194
  }
152
195
  }
153
196
  } else if (!(key in context)) {
154
- context[key] = sharedLib[key]
197
+ context[key] = copyWithNestedIgnores(sharedLib[key], skip, key)
155
198
  }
156
199
  }
157
200
  }