@symbo.ls/utils 3.14.656 → 3.14.685
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 +12 -0
- package/cdn.js +18 -2
- package/dist/cjs/cdn.js +3 -3
- package/dist/cjs/sharedLibraries.js +1 -1
- package/dist/esm/cdn.js +3 -3
- package/dist/esm/sharedLibraries.js +1 -1
- package/package.json +1 -1
- package/sharedLibraries.js +8 -0
package/CHANGELOG.md
CHANGED
package/cdn.js
CHANGED
|
@@ -65,6 +65,18 @@ export const getCDNUrl = (
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Generate an HTML <script type="importmap"> tag from project dependencies.
|
|
68
|
+
*
|
|
69
|
+
* The closing tag is built via string concatenation (`'</' + 'script>'`) so
|
|
70
|
+
* this module's source never carries the literal closing-tag sequence as a
|
|
71
|
+
* single substring. This package is bundled verbatim into the smbls IIFE
|
|
72
|
+
* that ships to the browser (and can be re-embedded as a string, e.g. for
|
|
73
|
+
* SSR), and HTML parsing terminates a script element at the first such byte
|
|
74
|
+
* sequence regardless of JS string-literal context. That sequence sitting
|
|
75
|
+
* whole in this source would prematurely close ANY outer script tag that
|
|
76
|
+
* happens to inline this bundle's source text, dumping the remainder of the
|
|
77
|
+
* bundle onto the page as raw HTML (tickets/smbls.md — the ~355KB "fake
|
|
78
|
+
* importmap" bug). Splitting the tag here means neither the source nor any
|
|
79
|
+
* minified/bundled copy of it ever carries that literal substring.
|
|
68
80
|
*/
|
|
69
81
|
export const getImportMapScript = (data, defaultProvider = 'skypack') => {
|
|
70
82
|
const dependencies = data.dependencies || {}
|
|
@@ -77,7 +89,11 @@ export const getImportMapScript = (data, defaultProvider = 'skypack') => {
|
|
|
77
89
|
imports[pkgName] = getCDNUrl(pkgName, version, defaultProvider)
|
|
78
90
|
}
|
|
79
91
|
|
|
80
|
-
|
|
92
|
+
const openTag = '<script type="importmap">'
|
|
93
|
+
const closeTag = '</' + 'script>'
|
|
94
|
+
const body = `{
|
|
81
95
|
"imports": ${JSON.stringify(imports, null, 2)}
|
|
82
|
-
}
|
|
96
|
+
}`
|
|
97
|
+
|
|
98
|
+
return `${openTag}${body}${closeTag}`
|
|
83
99
|
}
|
package/dist/cjs/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
2
|
-
"imports": ${JSON.stringify(
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var j=(n,e)=>{for(var i in e)u(n,i,{get:e[i],enumerable:!0})},E=(n,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of R(e))!U.call(n,r)&&r!==i&&u(n,r,{get:()=>e[r],enumerable:!(t=g(e,r))||t.enumerable});return n};var S=n=>E(u({},"__esModule",{value:!0}),n);var K={};j(K,{deepDefaults:()=>f,fetchLibraryData:()=>k,isWrappedLibrary:()=>p,mergeSharedLibraries:()=>T,normalizeIgnoreList:()=>w,normalizeLibraryKey:()=>l,resolveSharedLibraries:()=>G,sharedLibrary:()=>P});module.exports=S(K);var s=require("./types.js");const m="system",_="https://smbls-kv.nika-980.workers.dev",I="https://api.symbols.app";function l(n){const e=String(n||"").trim();if(!e)return{owner:m,key:"",full:""};let i=null,t=e;if(e.includes("/")){const o=e.indexOf("/");i=e.slice(0,o),t=e.slice(o+1)}t=t.replace(/\.symbo\.ls$/iu,""),i||(i=m);const r=t?`${i}/${t}`:"";return{owner:i,key:t,full:r}}const f=(n,e,i,t)=>{for(const r in e){const o=t?`${t}/${r}`:r;i&&i.has(o)||(r in n?(0,s.isObject)(n[r])&&(0,s.isObject)(e[r])&&f(n[r],e[r],i,o):n[r]=e[r])}},O=new Set,B=n=>n.replace(/\.js$/iu,""),w=n=>{const e=new Set;if(!Array.isArray(n))return e;for(const i of n){if(!(0,s.isString)(i))continue;const t=i.split("/").map(r=>B(r.trim())).filter(Boolean).join("/");t&&e.add(t)}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,i)=>{const t=e.sharePages===!1;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&r!=="sharePages"&&!(r==="pages"&&t)&&!i.has(r))if((0,s.isObject)(e[r])&&(0,s.isObject)(n[r]))if(r==="designSystem")f(n[r],e[r],i,r);else for(const o in e[r])i.has(`${r}/${o}`)||o in n[r]||(n[r][o]=e[r][o]);else r in n||(n[r]=e[r])},T=(n,e)=>{if(!(!e||!e.length))for(let i=0;i<e.length;i++){let t=e[i],r=O;p(t)&&(r=w(t.ignoreList),t=t.library),(0,s.isObject)(t)&&C(n,t,r)}};async function k(n,e={}){if((e.provider||"kv")==="api")return h(n,e);const t=await F(n,e);return t||h(n,e)}async function F(n,e={}){const i=e.kvBaseUrl||_,t=e.env||"production",r=`${i}/kv/${encodeURIComponent(n)}?env=${t}`;try{const o=await fetch(r,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function h(n,e={}){const i=e.apiBaseUrl||I,{key:t}=l(n);try{const r=`${i}/core/projects/libraries/available?search=${encodeURIComponent(t)}&limit=10`,o=await fetch(r,{method:"GET"});if(!o.ok)return null;const a=await o.json(),c=(a?.items||a?.data||(Array.isArray(a)?a:[])).find($=>{const{key:A}=l($?.key);return A.toLowerCase()===t.toLowerCase()});if(!c?.id&&!c?._id)return null;const v=c.id||c._id,L=`${i}/core/projects/${encodeURIComponent(v)}/data?branch=main`,y=await fetch(L,{method:"GET"});if(!y.ok)return null;const d=await y.json();return d?.data||d||null}catch{return null}}async function b(n,e={}){if((0,s.isObject)(n))return n;if((0,s.isString)(n)){const{full:i}=l(n);if(!i)return null;try{const t=await k(i,e);return t||console.warn(`[smbls] Shared library "${i}" not found`),t}catch(t){return console.warn(`[smbls] Failed to fetch shared library "${i}":`,t.message),null}}return null}async function G(n,e={}){return!n||!n.length?[]:(await Promise.all(n.map(async t=>{if(p(t)){const r=await b(x(t),e);return r?{library:r,ignoreList:t.ignoreList}:null}return b(t,e)}))).filter(Boolean)}
|
package/dist/esm/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function
|
|
2
|
-
"imports": ${JSON.stringify(
|
|
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 +1 @@
|
|
|
1
|
-
import{isObject as s,isString as
|
|
1
|
+
import{isObject as s,isString as p}from"./types.js";const y="system",$="https://smbls-kv.nika-980.workers.dev",A="https://api.symbols.app";function l(n){const e=String(n||"").trim();if(!e)return{owner:y,key:"",full:""};let i=null,t=e;if(e.includes("/")){const o=e.indexOf("/");i=e.slice(0,o),t=e.slice(o+1)}t=t.replace(/\.symbo\.ls$/iu,""),i||(i=y);const r=t?`${i}/${t}`:"";return{owner:i,key:t,full:r}}const d=(n,e,i,t)=>{for(const r in e){const o=t?`${t}/${r}`:r;i&&i.has(o)||(r in n?s(n[r])&&s(e[r])&&d(n[r],e[r],i,o):n[r]=e[r])}},g=new Set,R=n=>n.replace(/\.js$/iu,""),U=n=>{const e=new Set;if(!Array.isArray(n))return e;for(const i of n){if(!p(i))continue;const t=i.split("/").map(r=>R(r.trim())).filter(Boolean).join("/");t&&e.add(t)}return e},B=(n,e={})=>({library:n,ignoreList:Array.isArray(e.ignoreList)?e.ignoreList:[]}),m=n=>s(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,E=(n,e,i)=>{const t=e.sharePages===!1;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&r!=="sharePages"&&!(r==="pages"&&t)&&!i.has(r))if(s(e[r])&&s(n[r]))if(r==="designSystem")d(n[r],e[r],i,r);else for(const o in e[r])i.has(`${r}/${o}`)||o in n[r]||(n[r][o]=e[r][o]);else r in n||(n[r]=e[r])},P=(n,e)=>{if(!(!e||!e.length))for(let i=0;i<e.length;i++){let t=e[i],r=g;m(t)&&(r=U(t.ignoreList),t=t.library),s(t)&&E(n,t,r)}};async function S(n,e={}){if((e.provider||"kv")==="api")return h(n,e);const t=await _(n,e);return t||h(n,e)}async function _(n,e={}){const i=e.kvBaseUrl||$,t=e.env||"production",r=`${i}/kv/${encodeURIComponent(n)}?env=${t}`;try{const o=await fetch(r,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function h(n,e={}){const i=e.apiBaseUrl||A,{key:t}=l(n);try{const r=`${i}/core/projects/libraries/available?search=${encodeURIComponent(t)}&limit=10`,o=await fetch(r,{method:"GET"});if(!o.ok)return null;const a=await o.json(),c=(a?.items||a?.data||(Array.isArray(a)?a:[])).find(v=>{const{key:L}=l(v?.key);return L.toLowerCase()===t.toLowerCase()});if(!c?.id&&!c?._id)return null;const w=c.id||c._id,k=`${i}/core/projects/${encodeURIComponent(w)}/data?branch=main`,u=await fetch(k,{method:"GET"});if(!u.ok)return null;const f=await u.json();return f?.data||f||null}catch{return null}}async function b(n,e={}){if(s(n))return n;if(p(n)){const{full:i}=l(n);if(!i)return null;try{const t=await S(i,e);return t||console.warn(`[smbls] Shared library "${i}" not found`),t}catch(t){return console.warn(`[smbls] Failed to fetch shared library "${i}":`,t.message),null}}return null}async function x(n,e={}){return!n||!n.length?[]:(await Promise.all(n.map(async t=>{if(m(t)){const r=await b(j(t),e);return r?{library:r,ignoreList:t.ignoreList}:null}return b(t,e)}))).filter(Boolean)}export{d as deepDefaults,S as fetchLibraryData,m as isWrappedLibrary,P as mergeSharedLibraries,U as normalizeIgnoreList,l as normalizeLibraryKey,x as resolveSharedLibraries,B as sharedLibrary};
|
package/package.json
CHANGED
package/sharedLibraries.js
CHANGED
|
@@ -123,8 +123,16 @@ const wrappedLibraryRef = (entry) =>
|
|
|
123
123
|
entry.library !== undefined ? entry.library : (entry.key ?? entry.name)
|
|
124
124
|
|
|
125
125
|
const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
126
|
+
// A library can declare its `pages` private (`sharePages: false` on its
|
|
127
|
+
// context). Library site routes would otherwise auto-mount into every
|
|
128
|
+
// consumer that doesn't define the same route key — a library serving its
|
|
129
|
+
// own doc site (e.g. system/brand) must be able to opt out. Default stays
|
|
130
|
+
// ON (legacy behavior) so no existing library changes meaning.
|
|
131
|
+
const pagesArePrivate = sharedLib.sharePages === false
|
|
126
132
|
for (const key in sharedLib) {
|
|
127
133
|
if (!Object.prototype.hasOwnProperty.call(sharedLib, key)) continue
|
|
134
|
+
if (key === 'sharePages') continue // merge directive, not library content
|
|
135
|
+
if (key === 'pages' && pagesArePrivate) continue
|
|
128
136
|
if (ignore.has(key)) continue // top-level skip: 'designSystem', 'app', 'state'
|
|
129
137
|
if (isObject(sharedLib[key]) && isObject(context[key])) {
|
|
130
138
|
if (key === 'designSystem') {
|