@symbo.ls/utils 3.14.768 → 3.14.770
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 +95 -12
- package/dist/cjs/cdn.js +3 -3
- package/dist/cjs/object.js +18 -17
- package/dist/cjs/sharedLibraries.js +1 -1
- package/dist/cjs/state.js +1 -1
- package/dist/cjs/string.js +2 -2
- package/dist/esm/cdn.js +2 -2
- package/dist/esm/object.js +18 -17
- package/dist/esm/sharedLibraries.js +1 -1
- package/dist/esm/state.js +1 -1
- package/dist/esm/string.js +3 -3
- package/object.js +153 -15
- package/package.json +2 -2
- package/sharedLibraries.js +42 -2
- package/state.js +70 -0
- package/string.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @symbo.ls/utils
|
|
2
2
|
|
|
3
|
+
## 3.14.770
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Seed the raw design system at BOOT rather than only in the socket's `onSnapshot`, so every livesync/HMR push re-paints correctly without a manual reload (RUNTIME-LIVESYNC-STYLE-LOSS-1).
|
|
8
|
+
|
|
9
|
+
`onOps` re-inits the design system from `ctx.__rawDesignSystem`. That copy was seeded only in `onSnapshot`, so transports that echo a boot snapshot were covered while the dev-server runner — which emits ops and never a snapshot — was not. `buildReinitDesignSystem` then returned null and `onOps` fell back to `init(ctx.designSystem)`, re-feeding scratch's PROCESSED config through the token transformers: alpha was stripped (`--color-transparent` rgba(0,0,0,0) → rgba(0,0,0,1)) and new tokens never reached the sheet.
|
|
10
|
+
|
|
11
|
+
`seedRawDesignSystem` is now called in `createDomql.js` immediately before `prepareDesignSystem` — shared libraries merged, scratch processing not yet run — and re-exported from `@symbo.ls/sync`. brender's sync stub gains the same export.
|
|
12
|
+
|
|
13
|
+
`@symbo.ls/utils` is republished because its shipped dist was missing `isPolyglotWritableKey`, which exists at `packages/utils/state.js:261` and is imported by `@symbo.ls/element` and `smbls/src/prepare.js`. The published 3.14.769 tarball lacks it, so any consumer importing that symbol from the package root fails at import time.
|
|
14
|
+
|
|
3
15
|
## 3.14.768
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/cdn.js
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
// `<pkg>@<version>` grammar helpers shared by every provider below. The
|
|
4
|
+
// version ALWAYS attaches to the package NAME, never to a deep file path —
|
|
5
|
+
// `panzoom@9.4.4/dist/panzoom.js`, not `panzoom/dist/panzoom.js@9.4.4`
|
|
6
|
+
// (IMPORTMAP-SUBPATH-1 side finding: pkg.symbo.ls tolerated the latter,
|
|
7
|
+
// every other provider 404s on it). `splitPackageSpecifier` is what makes a
|
|
8
|
+
// deep specifier reach `formatUrl` as (name, version, subpath).
|
|
9
|
+
const versionPart = (version) => (version !== 'latest' ? `@${version}` : '')
|
|
10
|
+
const subpathPart = (subpath) => (subpath ? `/${subpath}` : '')
|
|
11
|
+
|
|
12
|
+
// 'panzoom/dist/panzoom.js' → { name: 'panzoom', subpath: 'dist/panzoom.js' }
|
|
13
|
+
// '@symbo.ls/utils/cdn.js' → { name: '@symbo.ls/utils', subpath: 'cdn.js' }
|
|
14
|
+
// 'smbls' → { name: 'smbls', subpath: '' }
|
|
15
|
+
export const splitPackageSpecifier = (specifier) => {
|
|
16
|
+
const spec = typeof specifier === 'string' ? specifier.replace(/\/+$/, '') : ''
|
|
17
|
+
if (!spec) return { name: '', subpath: '' }
|
|
18
|
+
const parts = spec.split('/')
|
|
19
|
+
const nameSegments = spec.startsWith('@') ? 2 : 1
|
|
20
|
+
return {
|
|
21
|
+
name: parts.slice(0, nameSegments).join('/'),
|
|
22
|
+
subpath: parts.slice(nameSegments).join('/')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
3
26
|
export const CDN_PROVIDERS = {
|
|
4
27
|
skypack: {
|
|
5
28
|
url: 'https://cdn.skypack.dev',
|
|
6
|
-
formatUrl: (pkg, version) =>
|
|
7
|
-
`${CDN_PROVIDERS.skypack.url}/${pkg}${version
|
|
29
|
+
formatUrl: (pkg, version, subpath) =>
|
|
30
|
+
`${CDN_PROVIDERS.skypack.url}/${pkg}${versionPart(version)}${subpathPart(subpath)}`
|
|
8
31
|
},
|
|
9
32
|
esmsh: {
|
|
10
33
|
url: 'https://esm.sh',
|
|
11
|
-
formatUrl: (pkg, version) =>
|
|
12
|
-
`${CDN_PROVIDERS.esmsh.url}/${pkg}${version
|
|
34
|
+
formatUrl: (pkg, version, subpath) =>
|
|
35
|
+
`${CDN_PROVIDERS.esmsh.url}/${pkg}${versionPart(version)}${subpathPart(subpath)}`
|
|
13
36
|
},
|
|
14
37
|
unpkg: {
|
|
15
38
|
url: 'https://unpkg.com',
|
|
16
|
-
formatUrl: (pkg, version) =>
|
|
17
|
-
`${CDN_PROVIDERS.unpkg.url}/${pkg}${version
|
|
39
|
+
formatUrl: (pkg, version, subpath) =>
|
|
40
|
+
`${CDN_PROVIDERS.unpkg.url}/${pkg}${versionPart(version)}${subpathPart(subpath)}?module`
|
|
18
41
|
},
|
|
19
42
|
jsdelivr: {
|
|
20
43
|
url: 'https://cdn.jsdelivr.net/npm',
|
|
21
|
-
formatUrl: (pkg, version) =>
|
|
22
|
-
`${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version
|
|
44
|
+
formatUrl: (pkg, version, subpath) =>
|
|
45
|
+
`${CDN_PROVIDERS.jsdelivr.url}/${pkg}${versionPart(version)}${subpathPart(subpath)}/+esm`
|
|
23
46
|
},
|
|
24
47
|
// pkg.symbo.ls — our own proxy (server/workers/packages). It is a raw file
|
|
25
48
|
// PASSTHROUGH (GCS bucket → jsDelivr → unpkg), not a CJS→ESM transformer,
|
|
@@ -38,8 +61,8 @@ export const CDN_PROVIDERS = {
|
|
|
38
61
|
// a domain we control rather than a smbls-only special case.
|
|
39
62
|
symbols: {
|
|
40
63
|
url: 'https://pkg.symbo.ls',
|
|
41
|
-
formatUrl: (pkg, version) =>
|
|
42
|
-
`${CDN_PROVIDERS.symbols.url}/${pkg}${version
|
|
64
|
+
formatUrl: (pkg, version, subpath) =>
|
|
65
|
+
`${CDN_PROVIDERS.symbols.url}/${pkg}${versionPart(version)}${subpathPart(subpath)}/+esm`
|
|
43
66
|
}
|
|
44
67
|
}
|
|
45
68
|
|
|
@@ -88,7 +111,33 @@ export const getCDNUrl = (
|
|
|
88
111
|
provider = 'esmsh'
|
|
89
112
|
) => {
|
|
90
113
|
const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh
|
|
91
|
-
|
|
114
|
+
// A deep specifier ('pkg/dist/file.js') pins its version on the package
|
|
115
|
+
// NAME and keeps the file path after it — see splitPackageSpecifier.
|
|
116
|
+
const { name, subpath } = splitPackageSpecifier(packageName)
|
|
117
|
+
return cdnConfig.formatUrl(name || packageName, stripVersionRangePrefix(version), subpath)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// The package DIRECTORY on the CDN — `<cdn>/<pkg>@<version>/` — i.e. the
|
|
121
|
+
// exact-entry URL without its module-entry suffix (`/+esm`, `?module`) and
|
|
122
|
+
// WITH a trailing slash. This is the address an importmap prefix entry
|
|
123
|
+
// (`"pkg/": "<dir>/"`) needs so `import('pkg/<subpath>')` resolves to
|
|
124
|
+
// `<dir>/<subpath>` — a raw file path every provider here serves
|
|
125
|
+
// (pkg.symbo.ls is a raw passthrough; esm.sh / jsDelivr / unpkg / skypack
|
|
126
|
+
// all accept `/<pkg>@<v>/<file>`). Kept separate from `formatUrl` on purpose:
|
|
127
|
+
// the exact entry MUST keep its suffix (the IIFE-vs-ESM lesson above), the
|
|
128
|
+
// prefix entry MUST NOT have one.
|
|
129
|
+
export const getCDNDirUrl = (
|
|
130
|
+
packageName,
|
|
131
|
+
version = 'latest',
|
|
132
|
+
provider = 'esmsh'
|
|
133
|
+
) => {
|
|
134
|
+
const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh
|
|
135
|
+
const v = stripVersionRangePrefix(version)
|
|
136
|
+
// Same name/subpath grammar as getCDNUrl: the version pins the package
|
|
137
|
+
// name, a deep specifier's path follows it, and the directory URL still
|
|
138
|
+
// ends with the trailing slash an importmap prefix entry requires.
|
|
139
|
+
const { name, subpath } = splitPackageSpecifier(packageName)
|
|
140
|
+
return `${cdnConfig.url}/${name || packageName}${versionPart(v)}${subpathPart(subpath)}/`
|
|
92
141
|
}
|
|
93
142
|
|
|
94
143
|
// SMBLS-IMPORTMAP-SKIP — shared with packages/smbls/src/prepare.js's own
|
|
@@ -127,6 +176,20 @@ const MALFORMED_DEP_RE = /[<>…]/
|
|
|
127
176
|
export const isMalformedDependency = (name) =>
|
|
128
177
|
typeof name === 'string' && MALFORMED_DEP_RE.test(name)
|
|
129
178
|
|
|
179
|
+
// A dependency MAP is `{ [pkgName]: version }` — a plain object keyed by
|
|
180
|
+
// package name. Manifest v2.1's `dependencies` field (a project config.js
|
|
181
|
+
// app-dependency GRAPH: `[{ id, requirement, kind, provides, reason }, …]`)
|
|
182
|
+
// reuses the same key name for an unrelated shape, and a project's
|
|
183
|
+
// generated context.js spreads `...config` AFTER the real map from
|
|
184
|
+
// dependencies.js, so config's array can end up occupying this exact spot
|
|
185
|
+
// (APP-CONFIG-DEPENDENCIES-COLLIDES-WITH-PACKAGE-LOADER-1). Indexing an
|
|
186
|
+
// array by package name indexes it by NUMERIC POSITION instead —
|
|
187
|
+
// `dependencies['0']` yields the first manifest entry OBJECT, not a
|
|
188
|
+
// version string — so both callers below must refuse anything that isn't
|
|
189
|
+
// a plain object before treating a value as a package spec.
|
|
190
|
+
export const isValidDependencyMap = (dependencies) =>
|
|
191
|
+
!!dependencies && typeof dependencies === 'object' && !Array.isArray(dependencies)
|
|
192
|
+
|
|
130
193
|
/**
|
|
131
194
|
* Generate an HTML <script type="importmap"> tag from project dependencies.
|
|
132
195
|
*
|
|
@@ -150,13 +213,29 @@ export const isMalformedDependency = (name) =>
|
|
|
150
213
|
* *.at.symbo.ls pages shipped `"smbls": "latest"` against an inlined IIFE from
|
|
151
214
|
* a months-old pin, and the client half moved 683 → 704 in a single evening
|
|
152
215
|
* under already-published sites (tickets/smbls.md).
|
|
216
|
+
*
|
|
217
|
+
* SUBPATH TWIN (tickets/fable.md IMPORTMAP-SUBPATH-1). Browser importmap
|
|
218
|
+
* semantics do NOT satisfy a subpath import from a bare entry:
|
|
219
|
+
* `"typesense-docsearch.js": "…@3.4.1/+esm"` resolves `import('typesense-
|
|
220
|
+
* docsearch.js')` and NOTHING else — `import('typesense-docsearch.js/dist/
|
|
221
|
+
* umd/index.js')` rejects with `TypeError: Failed to resolve module
|
|
222
|
+
* specifier` BEFORE any network request (measured live on docs.symbols.app,
|
|
223
|
+
* silent unless the caller awaits). A prefix entry — a key ending in `/`
|
|
224
|
+
* mapped to an address ending in `/` — is how importmaps express "and every
|
|
225
|
+
* subpath under it". So every dependency gets a TWIN:
|
|
226
|
+
* "pkg": "<cdn>/pkg@X/+esm" (exact — the importable module entry)
|
|
227
|
+
* "pkg/": "<cdn>/pkg@X/" (prefix — `pkg/<file>` → `<cdn>/pkg@X/<file>`)
|
|
228
|
+
* Same pinned version on both. A key that already ends with `/` gets no twin
|
|
229
|
+
* (it IS one). The address MUST end with `/` — the browser silently drops a
|
|
230
|
+
* prefix entry whose address does not.
|
|
153
231
|
*/
|
|
154
232
|
export const getImportMapScript = (
|
|
155
233
|
data,
|
|
156
234
|
defaultProvider = 'skypack',
|
|
157
235
|
options = {}
|
|
158
236
|
) => {
|
|
159
|
-
const dependencies = data.dependencies
|
|
237
|
+
const dependencies = data.dependencies
|
|
238
|
+
if (!isValidDependencyMap(dependencies)) return ''
|
|
160
239
|
const keys = Object.keys(dependencies)
|
|
161
240
|
if (!keys.length) return ''
|
|
162
241
|
|
|
@@ -172,6 +251,10 @@ export const getImportMapScript = (
|
|
|
172
251
|
if (isUnresolvableDependency(pkgName) || isMalformedDependency(pkgName)) continue
|
|
173
252
|
const version = pin[pkgName] || dependencies[pkgName] || 'latest'
|
|
174
253
|
imports[pkgName] = getCDNUrl(pkgName, version, defaultProvider)
|
|
254
|
+
// See SUBPATH TWIN above.
|
|
255
|
+
if (!pkgName.endsWith('/')) {
|
|
256
|
+
imports[pkgName + '/'] = getCDNDirUrl(pkgName, version, defaultProvider)
|
|
257
|
+
}
|
|
175
258
|
}
|
|
176
259
|
if (!Object.keys(imports).length) return ''
|
|
177
260
|
|
package/dist/cjs/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
"imports": ${JSON.stringify(
|
|
3
|
-
}`;return`${
|
|
1
|
+
"use strict";var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var A=(t,s)=>{for(var e in s)m(t,e,{get:s[e],enumerable:!0})},P=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of U(s))!C.call(t,n)&&n!==e&&m(t,n,{get:()=>s[n],enumerable:!(r=E(s,n))||r.enumerable});return t};var R=t=>P(m({},"__esModule",{value:!0}),t);var N={};A(N,{CDN_PROVIDERS:()=>o,PACKAGE_MANAGER_TO_CDN:()=>g,getCDNDirUrl:()=>h,getCDNUrl:()=>f,getCdnProviderFromConfig:()=>_,getImportMapScript:()=>v,isMalformedDependency:()=>d,isUnresolvableDependency:()=>k,isValidDependencyMap:()=>b,splitPackageSpecifier:()=>u,stripVersionRangePrefix:()=>$});module.exports=R(N);const l=t=>t!=="latest"?`@${t}`:"",i=t=>t?`/${t}`:"",u=t=>{const s=typeof t=="string"?t.replace(/\/+$/,""):"";if(!s)return{name:"",subpath:""};const e=s.split("/"),r=s.startsWith("@")?2:1;return{name:e.slice(0,r).join("/"),subpath:e.slice(r).join("/")}},o={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s,e)=>`${o.skypack.url}/${t}${l(s)}${i(e)}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s,e)=>`${o.esmsh.url}/${t}${l(s)}${i(e)}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s,e)=>`${o.unpkg.url}/${t}${l(s)}${i(e)}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s,e)=>`${o.jsdelivr.url}/${t}${l(s)}${i(e)}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s,e)=>`${o.symbols.url}/${t}${l(s)}${i(e)}/+esm`}},g={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},_=(t={})=>{const{packageManager:s}=t;return g[s]||null},$=t=>{if(typeof t!="string")return t;const s=t.trim().match(/^[\^~](\d.*)$/);return s?s[1]:t},f=(t,s="latest",e="esmsh")=>{const r=o[e]||o.esmsh,{name:n,subpath:a}=u(t);return r.formatUrl(n||t,$(s),a)},h=(t,s="latest",e="esmsh")=>{const r=o[e]||o.esmsh,n=$(s),{name:a,subpath:p}=u(t);return`${r.url}/${a||t}${l(n)}${i(p)}/`},M=/^node:|^@symbo-ls\//,k=t=>typeof t=="string"&&M.test(t),O=/[<>…]/,d=t=>typeof t=="string"&&O.test(t),b=t=>!!t&&typeof t=="object"&&!Array.isArray(t),v=(t,s="skypack",e={})=>{const r=t.dependencies;if(!b(r))return"";const n=Object.keys(r);if(!n.length)return"";const a=e.pin||{},p={};for(const c of n){if(k(c)||d(c))continue;const y=a[c]||r[c]||"latest";p[c]=f(c,y,s),c.endsWith("/")||(p[c+"/"]=h(c,y,s))}if(!Object.keys(p).length)return"";const x='<script type="importmap">',D="<\/script>",j=`{
|
|
2
|
+
"imports": ${JSON.stringify(p,null,2)}
|
|
3
|
+
}`;return`${x}${j}${D}`};
|
package/dist/cjs/object.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var
|
|
2
|
-
`;for(const
|
|
3
|
-
`;for(const
|
|
4
|
-
`:(0,
|
|
5
|
-
`:n+=`${
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`)
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
`);t[c
|
|
17
|
-
|
|
1
|
+
"use strict";var x=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var U=(e,t)=>{for(var o in t)x(e,o,{get:t[o],enumerable:!0})},Z=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of H(t))!K.call(e,n)&&n!==o&&x(e,n,{get:()=>t[n],enumerable:!(i=z(t,n))||i.enumerable});return e};var V=e=>Z(x({},"__esModule",{value:!0}),e);var $e={};U($e,{clone:()=>j,createNestedObject:()=>we,createObjectWithoutPrototype:()=>Y,deepClone:()=>ee,deepContains:()=>ge,deepDestringifyFunctions:()=>ce,deepMerge:()=>Q,deepStringifyFunctions:()=>P,destringifyGlobalScope:()=>fe,detectInfiniteLoop:()=>xe,excludeKeysFromObject:()=>Pe,exec:()=>E,getInObjectByPath:()=>ke,hasFunction:()=>k,hasOwnProperty:()=>le,isCyclic:()=>Ee,isEmpty:()=>m,isEmptyObject:()=>ae,isEqualDeep:()=>J,makeObjectWithoutPrototype:()=>pe,map:()=>X,merge:()=>v,objectToString:()=>$,overwrite:()=>ye,overwriteDeep:()=>B,overwriteShallow:()=>he,removeFromObject:()=>_e,removeNestedKeyByPath:()=>Oe,setInObjectByPath:()=>Se,stringToObject:()=>ue});module.exports=V($e);var O=require("./globals.js"),u=require("./types.js"),G=require("./array.js"),L=require("./string.js"),_=require("./node.js"),F=require("./keys.js");const A="production",w=e=>e.charCodeAt(0)===95&&e.charCodeAt(1)===95,E=(e,t,o,i)=>{if((0,u.isFunction)(e))return t?typeof e.call!="function"?e:e.call(t,t,o||t.state,i||t.context):void 0;if(e!=null&&t?.context?.plugins&&((0,u.isArray)(e)||(0,u.isObject)(e)&&!(0,_.isDOMNode)(e))){const n=t.context.plugins;for(const r of n)if(r.resolveHandler){const s=r.resolveHandler(e,t);if(typeof s=="function")return E(s,t,o,i)}}return e},X=(e,t,o)=>{for(const i in t)e[i]=E(t[i],o)},v=(e,t,o=[])=>{const i=o instanceof Set;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(w(n)||(i?o.has(n):o.includes(n))||e[n]===void 0&&(e[n]=t[n]));return e},Q=(e,t,o=F.METHODS_EXL)=>T(e,t,o,null),T=(e,t,o,i)=>{if(e===t)return e;if(i){for(let r=0;r<i.length;r+=2)if(i[r]===e&&i[r+1]===t)return e}const n=o instanceof Set;for(const r in t){if(!Object.prototype.hasOwnProperty.call(t,r)||w(r)||r==="constructor"||r==="prototype"||(n?o.has(r):o.includes(r)))continue;const s=e[r],f=t[r];if((0,u.isObjectLike)(s)&&(0,u.isObjectLike)(f)){const l=i||[];l.push(e,t),T(s,f,o,l),l.length-=2}else s===void 0&&(e[r]=f)}return e},j=(e,t=[])=>{const o=t instanceof Set,i={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(w(n)||(o?t.has(n):t.includes(n))||(i[n]=e[n]));return i},ee=(e,t={})=>{const{exclude:o=[],cleanUndefined:i=!1,cleanNull:n=!1,visited:r=new WeakMap,handleExtends:s=!1}=t;if(!(0,u.isObjectLike)(e)||(0,_.isDOMNode)(e))return e;if(r.has(e))return r.get(e);const f=o instanceof Set?o:o.length>3?new Set(o):null,l=y=>f?f.has(y):o.includes(y),c=(0,u.isArray)(e)?[]:{};r.set(e,c);const a=[[e,c]];for(;a.length;){const[y,d]=a.pop();for(const h in y){if(!Object.prototype.hasOwnProperty.call(y,h)||w(h)||h==="__proto__"||l(h))continue;const p=y[h];if(!(i&&p===void 0)&&!(n&&p===null)){if((0,_.isDOMNode)(p)){d[h]=p;continue}if(s&&h==="extends"&&(0,u.isArray)(p)){d[h]=(0,G.unstackArrayOfObjects)(p,o);continue}if((0,u.isFunction)(p)){d[h]=p;continue}if((0,u.isObjectLike)(p))if(r.has(p))d[h]=r.get(p);else{const g=(0,u.isArray)(p)?[]:{};r.set(p,g),d[h]=g,a.push([p,g])}else d[h]=p}}}return c},P=(e,t={})=>{(e.node||e.__ref||e.parent||e.__element||e.parse)&&((e.__element||e.parent?.__element).warn("Trying to clone element or state at",e),e=e.parse?.());for(const o in e){const i=e[o];if((0,u.isFunction)(i))t[o]=i.toString();else if((0,u.isObject)(i))t[o]={},P(i,t[o]);else if((0,u.isArray)(i)){const n=t[o]=[];for(let r=0;r<i.length;r++){const s=i[r];(0,u.isObject)(s)?(n[r]={},P(s,n[r])):(0,u.isFunction)(s)?n[r]=s.toString():n[r]=s}}else t[o]=i}return t},te=new Set(["&","*","-",":","%","{","}",">","<","@",".","/","!"," "]),$=(e={},t=0)=>{if(e===null||typeof e!="object"||e instanceof RegExp)return String(e);let o=!1;for(const r in e){o=!0;break}if(!o)return"{}";const i=" ".repeat(t);let n=`{
|
|
2
|
+
`;for(const r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;const s=e[r];let f=!1;for(let c=0;c<r.length;c++)if(te.has(r[c])){f=!0;break}const l=f?`'${r}'`:r;if(n+=`${i} ${l}: `,s instanceof RegExp)n+=String(s);else if((0,u.isArray)(s)){n+=`[
|
|
3
|
+
`;for(const c of s)c instanceof RegExp?n+=`${i} ${String(c)},
|
|
4
|
+
`:(0,u.isObjectLike)(c)&&c!==null?n+=`${i} ${$(c,t+2)},
|
|
5
|
+
`:(0,u.isString)(c)?n+=`${i} '${c}',
|
|
6
|
+
`:n+=`${i} ${c},
|
|
7
|
+
`;n+=`${i} ]`}else(0,u.isObjectLike)(s)?n+=$(s,t+1):(0,u.isString)(s)?n+=(0,L.stringIncludesAny)(s,[`
|
|
8
|
+
`,"'"])?`\`${s}\``:`'${s}'`:n+=s;n+=`,
|
|
9
|
+
`}return n+=`${i}}`,n},ne=[/^\(\s*\{[^}]*\}\s*\)\s*=>/,/^(\([^)]*\)|[^=]*)\s*=>/,/^function[\s(]/,/^async\s+/,/^\(\s*function/,/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/,/^(?:\*\s*)?[a-zA-Z_$][\w$]*\s*\((?:[^()]|\([^()]*\))*\)\s*\{[\s\S]*\}$/],re=/^["[{]/,oe=/^(export|import)\s/,k=e=>{if(!e)return!1;const t=e.trim().replace(/\n\s*/g," ").trim();if(t===""||t==="{}"||t==="[]"||oe.test(t)||!ne.some(r=>r.test(t)))return!1;const i=t.charCodeAt(0),n=t.includes("=>");return!(i===123&&!n||i===91||re.test(t)&&!n)},ie=e=>(0,eval)(e),se=(e,t)=>{const o=/^(\s*(?:async\s+)?function\s*[\w$]*\s*\([^)]*\)\s*)\{/.exec(e);if(!o)return null;const i=o[0].length,n=[];let r=i,s=1,f=null;const l=e.length,c=new RegExp("^(?:const|let|var)\\s+"+t+"\\b");for(;r<l&&s>0;){const y=e[r];if(y==="/"&&e[r+1]==="/"){const d=e.indexOf(`
|
|
10
|
+
`,r);r=d===-1?l:d;continue}if(y==="/"&&e[r+1]==="*"){const d=e.indexOf("*/",r+2);r=d===-1?l:d+2;continue}if(y==='"'||y==="'"||y==="`"){const d=y;for(r++;r<l;){if(e[r]==="\\"){r+=2;continue}if(e[r]===d){r++;break}if(d==="`"&&e[r]==="$"&&e[r+1]==="{"){r+=2;let h=1;for(;r<l&&h>0;)e[r]==="{"?h++:e[r]==="}"&&h--,r++;continue}r++}continue}if(y==="{"){s++,r++;continue}if(y==="}"){s--,r++;continue}if(s===1&&c.test(e.slice(r))){const d=r;let h=0,p=r;for(;p<l;){const g=e[p];if(g==='"'||g==="'"||g==="`"){const q=g;for(p++;p<l;){if(e[p]==="\\"){p+=2;continue}if(e[p]===q){p++;break}p++}continue}if(g==="("||g==="["||g==="{"){h++,p++;continue}if(g===")"||g==="]"||g==="}"){if(h===0)break;h--,p++;continue}if(h===0&&(g===";"||g===`
|
|
11
|
+
`)){p++;break}p++}n.push([d,p]),r=p;continue}r++}if(!n.length)return null;let a=e;for(let y=n.length-1;y>=0;y--)a=a.slice(0,n[y][0])+a.slice(n[y][1]);return a},N=(e,t,o)=>{const i=String(e).trimStart();if(/^(export|import)\s/.test(i))return e;try{return o.window.eval(`(${e})`)}catch(n){const r=n&&n.message?n.message:String(n),s=/await is only valid in async/.test(r),f=/Identifier '([^']+)' has already been declared/.exec(r);let l=null;if(s){const c=String(e).trim();if(/^function[\s(]/.test(c))try{l=o.window.eval("(async "+c+")")}catch{}}else if(f){let c=String(e),a=f[1];for(let y=0;y<5;y++){const d=se(c,a);if(!d||d===c)break;c=d;try{l=o.window.eval("("+c+")");break}catch(h){const p=/Identifier '([^']+)' has already been declared/.exec(h&&h.message||String(h));if(!p||p[1]!==a)break}}}if(!l&&/Unexpected (token '\{'|identifier)/.test(r))try{const c=o.window.eval("({"+e+"})");if(c&&typeof c=="object"){const a=Object.keys(c);a.length===1&&typeof c[a[0]]=="function"&&(l=c[a[0]])}}catch{}return l||(typeof console<"u"&&console.warn&&console.warn(`[smbls] deepDestringifyFunctions: eval failed on ${t} \u2014 value will be left as a string. Reason: `+r+`.
|
|
12
|
+
First 200 chars of source: `+String(e).slice(0,200)),e)}},ce=(e,t={},o={window:{eval:ie}})=>{if(!e||typeof e!="object")return t;const i=[[e,t]];for(;i.length;){const[n,r]=i.pop();for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const f=n[s];if((0,u.isString)(f))k(f)?r[s]=N(f,`"${s}"`,o):r[s]=f;else if((0,u.isArray)(f)){const l=r[s]=[];for(let c=0;c<f.length;c++){const a=f[c];if((0,u.isString)(a))l.push(k(a)?N(a,`array index ${c} (prop "${s}")`,o):a);else if((0,u.isObject)(a)){const y=b(a);if(y)l.push(y);else{const d={};l.push(d),i.push([a,d])}}else l.push(a)}}else if((0,u.isObject)(f)){const l=b(f);if(l){r[s]=l;continue}const c=r[s]&&typeof r[s]=="object"&&!(0,u.isArray)(r[s])?r[s]:r[s]={};i.push([f,c])}else r[s]=f}}return t},R="Set",M="Map",D="RegExp",W="WeakMap",C="WeakSet",I=e=>{const t=Object.keys(e);return t.length===1&&t[0]==="__type"},S=(e,t)=>{if(!e||typeof e!="object")return e;const o=r=>S(r,t||(t=new WeakMap));if(e.__type===R&&(0,u.isArray)(e.values))return new Set(e.values.map(o));if(e.__type===M&&(0,u.isArray)(e.entries))return new Map(e.entries.map(r=>(0,u.isArray)(r)?[o(r[0]),o(r[1])]:r));if(e.__type===W&&I(e))return new WeakMap;if(e.__type===C&&I(e))return new WeakSet;if(e.__type===D&&(0,u.isString)(e.source))try{return new RegExp(e.source,(0,u.isString)(e.flags)?e.flags:"")}catch{return e}if(t||(t=new WeakMap),t.has(e))return t.get(e);let i=!1;if((0,u.isArray)(e)){const r=new Array(e.length);t.set(e,r);for(let s=0;s<e.length;s++)r[s]=S(e[s],t),r[s]!==e[s]&&(i=!0);return i||t.set(e,e),i?r:e}const n={};t.set(e,n);for(const r of Object.keys(e))n[r]=S(e[r],t),n[r]!==e[r]&&(i=!0);return i||t.set(e,e),i?n:e},b=e=>{if(!e||typeof e!="object")return null;const t=e.__type;if(t!==D&&t!==R&&t!==M&&t!==W&&t!==C)return null;const o=S(e);return o===e?null:o},fe=e=>{if(!e||typeof e!="object")return e;const t={},o=[];for(const s of Object.keys(e)){const f=e[s];(0,u.isString)(f)&&k(f)?o.push([s,f]):t[s]=S(f)}if(o.length===0)return t;const i=s=>/^[A-Za-z_$][\w$]*$/.test(s),n=o.filter(([s])=>i(s)),r=Object.keys(t).filter(i).map(s=>`var ${s} = __gs__[${JSON.stringify(s)}];`).join(`
|
|
13
|
+
`);try{const s=n.map(([c,a])=>`var ${c} = (${a});`).join(`
|
|
14
|
+
`),f="{ "+n.map(([c])=>`${JSON.stringify(c)}: ${c}`).join(", ")+" }",l=O.window.eval(`(function(__gs__) { ${r}
|
|
15
|
+
${s}
|
|
16
|
+
return ${f}; })`)(t);Object.assign(t,l)}catch{for(const[f,l]of n)try{const c=Object.keys(t).filter(i).map(a=>`var ${a} = __gs__[${JSON.stringify(a)}];`).join(`
|
|
17
|
+
`);t[f]=O.window.eval(`(function(__gs__) { ${c}
|
|
18
|
+
return (${l}); })`)(t)}catch{try{t[f]=O.window.eval(`(${l})`)}catch{t[f]=l}}}for(const[s,f]of o)if(!i(s))try{t[s]=O.window.eval(`(${f})`)}catch{t[s]=f}return t},ue=(e,t={verbose:!0})=>{try{return e?O.window.eval("("+e+")"):{}}catch(o){t.verbose&&console.warn(o)}},le=(e,...t)=>Object.prototype.hasOwnProperty.call(e,...t),m=e=>{for(const t in e)return!1;return!0},ae=e=>(0,u.isObject)(e)&&m(e),pe=()=>Object.create(null),ye=(e,t,o={})=>{const i=o.exclude||[],n=o.preventUnderscore;for(const r in t)i.includes(r)||!n&&w(r)||r==="constructor"||r==="prototype"||t[r]!==void 0&&(e[r]=t[r]);return e},he=(e,t,o=[])=>{const i=o instanceof Set;for(const n in t)w(n)||n==="constructor"||n==="prototype"||(i?o.has(n):o.includes(n))||(e[n]=t[n]);return e},B=(e,t,o={},i=new WeakMap)=>{if(!(0,u.isObjectLike)(e)||!(0,u.isObjectLike)(t)||(0,_.isDOMNode)(e)||(0,_.isDOMNode)(t))return t;if(i.has(e))return i.get(e);i.set(e,e);const n=o.exclude,r=n?n instanceof Set?n:new Set(n):null,s=!o.preventForce;for(const f in t){if(!Object.prototype.hasOwnProperty.call(t,f)||r&&r.has(f)||s&&w(f)||f==="constructor"||f==="prototype")continue;const l=e[f],c=t[f];(0,_.isDOMNode)(c)?e[f]=c:(0,u.isObjectLike)(l)&&(0,u.isObjectLike)(c)?e[f]=B(l,c,o,i):c!==void 0&&(e[f]=c)}return e},J=(e,t,o=new Set)=>{if(typeof e!="object"||typeof t!="object"||e===null||t===null)return e===t;if(o.has(e)||o.has(t))return!0;o.add(e),o.add(t);const i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(let r=0;r<i.length;r++){const s=i[r];if(!Object.prototype.hasOwnProperty.call(t,s)||!J(e[s],t[s],o))return!1}return!0},de=new Set(["node","__ref"]),ge=(e,t,o=de)=>{if(e===t)return!0;if(!(0,u.isObjectLike)(e)||!(0,u.isObjectLike)(t)||(0,_.isDOMNode)(e)||(0,_.isDOMNode)(t))return e===t;const i=o instanceof Set?o:new Set(o),n=new WeakSet;function r(s,f){if(n.has(f))return!0;n.add(f);for(const l in f){if(!Object.prototype.hasOwnProperty.call(f,l)||i.has(l))continue;if(!Object.prototype.hasOwnProperty.call(s,l))return!1;const c=f[l],a=s[l];if((0,_.isDOMNode)(c)||(0,_.isDOMNode)(a)){if(c!==a)return!1}else if((0,u.isObjectLike)(c)&&(0,u.isObjectLike)(a)){if(!r(a,c))return!1}else if(c!==a)return!1}return!0}return r(e,t)},_e=(e,t)=>{if(t==null)return e;if((0,u.is)(t)("string","number"))delete e[t];else if((0,u.isArray)(t))for(let o=0;o<t.length;o++)delete e[t[o]];else throw new Error("Invalid input: props must be a string or an array of strings");return e},Y=e=>{if(e===null||typeof e!="object")return e;const t=Object.create(null);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=Y(e[o]));return t},we=(e,t)=>{if(e.length===0)return t;const o={};let i=o;for(let n=0;n<e.length;n++)n===e.length-1&&t?i[e[n]]=t:(i[e[n]]={},i=i[e[n]]);return o},Oe=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let n=0;n<t.length-1;n++){if(o[t[n]]===void 0)return;o=o[t[n]]}const i=t[t.length-1];o&&Object.prototype.hasOwnProperty.call(o,i)&&delete o[i]},Se=(e,t,o)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let i=e;for(let n=0;n<t.length-1;n++)(!i[t[n]]||typeof i[t[n]]!="object")&&(i[t[n]]={}),i=i[t[n]];return i[t[t.length-1]]=o,e},ke=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let i=0;i<t.length;i++){if(o==null)return;o=o[t[i]]}return o},xe=e=>{let o=[],i=0;for(let n=0;n<e.length;n++)if(o.length<2)o.push(e[n]);else if(e[n]===o[n%2]?i++:(o=[e[n-1],e[n]],i=1),i>=20)return(A==="test"||A==="development")&&console.warn("Warning: Potential infinite loop detected due to repeated sequence:",o),!0},Ee=e=>{const t=new WeakSet;function o(i){if(i&&typeof i=="object"){if(t.has(i))return!0;t.add(i);for(const n in i)if(Object.prototype.hasOwnProperty.call(i,n)&&o(i[n]))return console.log(i,"cycle at "+n),!0}return!1}return o(e)},Pe=(e,t)=>{const o=t instanceof Set?t:new Set(t),i={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&!o.has(n)&&(i[n]=e[n]);return i};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var E=(n,t)=>{for(var o in t)u(n,o,{get:t[o],enumerable:!0})},O=(n,t,o,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of R(t))!U.call(n,s)&&s!==o&&u(n,s,{get:()=>t[s],enumerable:!(e=j(t,s))||e.enumerable});return n};var _=n=>O(u({},"__esModule",{value:!0}),n);var x={};E(x,{deepDefaults:()=>p,fetchLibraryData:()=>L,isWrappedLibrary:()=>d,mergeSharedLibraries:()=>K,normalizeIgnoreList:()=>y,normalizeLibraryKey:()=>l,resolveSharedLibraries:()=>W,sharedLibrary:()=>z});module.exports=_(x);var a=require("./types.js");const b="system",B="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 o=null,e=t;if(t.includes("/")){const r=t.indexOf("/");o=t.slice(0,r),e=t.slice(r+1)}e=e.replace(/\.symbo\.ls$/iu,""),o||(o=b);const s=e?`${o}/${e}`:"";return{owner:o,key:e,full:s}}const p=(n,t,o,e)=>{for(const s in t){const r=e?`${e}/${s}`:s;o&&o.has(r)||(s in n?(0,a.isObject)(n[s])&&(0,a.isObject)(t[s])&&p(n[s],t[s],o,r):n[s]=t[s])}},w=(n,t,o)=>{if(!(0,a.isObject)(n)||!t.size)return n;const e=`${o}/`;let s=!1;for(const i of t)if(i.startsWith(e)){s=!0;break}if(!s)return n;const r={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const f=`${o}/${i}`;t.has(f)||(r[i]=w(n[i],t,f))}return r},C=new Set,T=new Set(["components","pages","functions","snippets","methods"]),g=(n,t)=>t===""&&T.has(n),G=n=>n.replace(/\.js$/iu,""),y=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const o of n){if(!(0,a.isString)(o))continue;const e=o.split("/").map(s=>G(s.trim())).filter(Boolean).join("/");e&&t.add(e)}return t},z=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),d=n=>(0,a.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),F=n=>n.library!==void 0?n.library:n.key??n.name,J=(n,t,o)=>{const e=y(t.sharedLibIgnore);t.sharePages===!1&&e.add("pages");const s=e.size?new Set([...o,...e]):o;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&!(r==="sharePages"||r==="sharedLibIgnore")&&!s.has(r))if((0,a.isObject)(t[r])&&(0,a.isObject)(n[r]))if(r==="designSystem")p(n[r],t[r],s,r);else for(const i in t[r])s.has(`${r}/${i}`)||(i in n[r]?g(r,n[r][i])&&!g(r,t[r][i])&&(n[r][i]=t[r][i]):n[r][i]=t[r][i]);else r in n||(n[r]=w(t[r],s,r))},K=(n,t)=>{if(!(!t||!t.length))for(let o=0;o<t.length;o++){let e=t[o],s=C;d(e)&&(s=y(e.ignoreList),e=e.library),(0,a.isObject)(e)&&J(n,e,s)}};async function L(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const e=await N(n,t);return e||$(n,t)}async function N(n,t={}){const o=t.kvBaseUrl||B,e=t.env||"production",s=`${o}/kv/${encodeURIComponent(n)}?env=${e}`;try{const r=await fetch(s,{method:"GET"});return r.ok&&(await r.json())?.value||null}catch{return null}}async function $(n,t={}){const o=t.apiBaseUrl||P,{key:e}=l(n);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(e)}&limit=10`,r=await fetch(s,{method:"GET"});if(!r.ok)return null;const i=await r.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(v=>{const{key:I}=l(v?.key);return I.toLowerCase()===e.toLowerCase()});if(!c?.id&&!c?._id)return null;const A=c.id||c._id,S=`${o}/core/projects/${encodeURIComponent(A)}/data?branch=main`,h=await fetch(S,{method:"GET"});if(!h.ok)return null;const m=await h.json();return m?.data||m||null}catch{return null}}async function k(n,t={}){if((0,a.isObject)(n))return n;if((0,a.isString)(n)){const{full:o}=l(n);if(!o)return null;try{const e=await L(o,t);return e||console.warn(`[smbls] Shared library "${o}" not found`),e}catch(e){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,e.message),null}}return null}async function W(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async e=>{if(d(e)){const s=await k(F(e),t);return s?{library:s,ignoreList:e.ignoreList}:null}return k(e,t)}))).filter(Boolean)}
|
package/dist/cjs/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var v=(e,r)=>{for(var o in r)a(e,o,{get:r[o],enumerable:!0})},O=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of w(r))!x.call(e,n)&&n!==o&&a(e,n,{get:()=>r[n],enumerable:!(t=m(r,n))||t.enumerable});return e};var I=e=>O(a({},"__esModule",{value:!0}),e);var C={};v(C,{applyDependentState:()=>E,checkForStateTypes:()=>j,checkIfInherits:()=>P,createInheritedState:()=>k,createNestedObjectByKeyPath:()=>D,findInheritedState:()=>b,getChildStateInKey:()=>S,getParentStateInKey:()=>h,getRootStateInKey:()=>g,isPolyglotWritableKey:()=>T,isState:()=>A,markPolyglotSeeded:()=>B,overwriteState:()=>K,polyglotSeededKeys:()=>d});module.exports=I(C);var y=require("./array.js"),p=require("./keys.js"),l=require("./object.js"),c=require("./types.js");const j=e=>{const{state:r,props:o,__ref:t}=e,n=o?.state||r;return(0,c.is)(n)("string","number")?(t.__state=n,{value:n}):n===!0?(t.__state=e.key,{}):n?(t.__hasRootState=!0,n):!1},g=(e,r)=>{if(!e.includes("~/"))return;if(e.split("~/").length>1)return r.root},h=(e,r)=>{if(!e.includes("../"))return;const t=e.split("../").length-1;for(let n=0;n<t;n++){if(!r.parent)return null;r=r.parent}return r},S=(e,r,o={})=>{const t=(0,c.isString)(e)?e.split("/"):[e],n=t.length-1;for(let s=0;s<n;s++){const i=t[s],f=t[s+1];if(i==="__proto__"||f==="__proto__")return;let u=r[i];u||(u=r[i]={}),u[f]||(u[f]={}),e=f,r=u}return o.returnParent?r:r[e]},b=(e,r,o={})=>{let n=e.__ref.__state;if(!P(e))return;const s=g(n,r.state);let i=r.state;if(s)i=s,n=n.replaceAll("~/","");else{const f=h(n,r.state);f&&(i=f,n=n.replaceAll("../",""))}if(i)return S(n,i,o)},k=(e,r)=>{const o=e.__ref,t=b(e,r);if(t===void 0)return e.state;if((0,c.is)(t)("object","array"))return(0,l.deepClone)(t);if((0,c.is)(t)("string","number","boolean"))return o.__stateType=typeof t,{value:t};console.warn(o.__state,"is not present. Replacing with",{})},P=e=>{const{__ref:r}=e,o=r?.__state;return!!(o&&(0,c.is)(o)("number","string","boolean"))},A=function(e){return(0,c.isObjectLike)(e)?!!(e.update&&e.parse&&e.clean&&e.create&&e.parent&&e.destroy&&e.rootUpdate&&e.parentUpdate&&e.keys&&e.values&&e.toggle&&e.replace&&e.quietUpdate&&e.quietReplace&&e.add&&e.apply&&e.applyReplace&&e.setByPath&&e.setPathCollection&&e.removeByPath&&e.removePathCollection&&e.getByPath&&e.applyFunction&&e.__element&&e.__children):!1},D=(e,r)=>{if(!e)return r||{};const o=e.split("/"),t={};let n=t;const s=o.length-1;for(let i=0;i<=s;i++)n[o[i]]=i===s?r||{}:{},n=n[o[i]];return t},E=(e,r)=>{const{__element:o}=r,t=o?.state;if(!t)return;const n=(0,l.deepClone)(t,p.STATE_METHODS),s={[e.key]:n},i=(0,c.isObject)(t.__depends)?{...t.__depends,...s}:s;return Array.isArray(t)?(0,y.addProtoToArray)(t,{...Object.getPrototypeOf(t),__depends:i}):Object.setPrototypeOf(t,{...Object.getPrototypeOf(t),__depends:i}),n},K=(e,r,o={})=>{const{overwrite:t}=o;if(!t)return;const n=t==="shallow";if(t==="merge"){(0,l.deepMerge)(e,r,p.STATE_METHODS);return}(n?l.overwriteShallow:l.overwriteDeep)(e,r,p.STATE_METHODS)},_="__polyglotSeededKeys",d=e=>{if(!(0,c.isObject)(e))return new Set;let r=e[_];if(!(r instanceof Set)){r=new Set;try{Object.defineProperty(e,_,{value:r,enumerable:!1,writable:!0,configurable:!0})}catch{}}return r},T=(e,r,o)=>d(e).has(r)?!0:!(0,c.isObject)(o)||o[r]===void 0,B=(e,r)=>(d(e).add(r),r);
|
package/dist/cjs/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var
|
|
2
|
-
`);let c=-1,
|
|
1
|
+
"use strict";var w=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var O=(e,n)=>{for(var t in n)w(e,t,{get:n[t],enumerable:!0})},I=(e,n,t,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of A(n))!N.call(e,s)&&s!==t&&w(e,s,{get:()=>n[s],enumerable:!(c=j(n,s))||c.enumerable});return e};var R=e=>I(w({},"__esModule",{value:!0}),e);var z={};O(z,{customDecodeURIComponent:()=>q,customEncodeURIComponent:()=>T,decodeNewlines:()=>K,encodeNewlines:()=>D,findKeyPosition:()=>v,lowercaseFirstLetter:()=>_,replaceLiteralsWithObjectFields:()=>F,replaceOctalEscapeSequences:()=>V,stringIncludesAny:()=>k,trimStringFromSymbols:()=>E});module.exports=R(z);const k=(e,n)=>{for(const t of n)if(e.includes(t))return!0;return!1},E=(e,n)=>{const t=new RegExp(`[${n.join("\\")}]`,"g");return e.replace(t,"")},$={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},x=(e,n)=>n.split(".").reduce((t,c)=>t?.[c],e);function F(e,n,t={}){const{bracketsLength:c=2}=t,s=c===3?"{{{":"{{";if(!e.includes(s))return e;const m=$[c],a=n||this.state||{},u=this;return e.replace(m,(g,d,r,i)=>{const p=r.trim();if(i){const l=u?.context,o=l?.functions?.[i]||l?.utils?.[i]||l?.methods?.[i]||l?.snippets?.[i]||u?.[i];if(o&&typeof o=="function")try{return String(o.call(u,p)??"")}catch{return""}return""}if(d){const l=(d.match(/\.\.\//g)||[]).length;let o=a;for(let f=0;f<l;f++){if(!o||!o.parent)return"";o=o.parent}if(p==="parent")return String(o.value??"");const h=x(o,p);return h!=null&&typeof h=="object"?"":String(h??"")}else{const l=x(a,p);if(l!=null&&typeof l!="object")return String(l);const o=u?.context?.polyglot;if(o?.translations){const h=a?.root?.lang||a?.lang||u?.context?.state?.lang||o.defaultLang||"en",f=o.translations[h];if(f){const C=x(f,p);if(C!=null&&typeof C!="object")return String(C);for(const L in f){const b=f[L];if(b&&typeof b=="object"&&!Array.isArray(b)){const S=x(b,p);if(S!=null&&typeof S!="object")return String(S)}}}const y=x(o.translations,p);if(y!=null&&typeof y!="object")return String(y)}return""}})}const _=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,v=(e,n)=>{const t=e.split(`
|
|
2
|
+
`);let c=-1,s=-1,m=-1,a=-1;const u=new RegExp(`\\b${n}\\b\\s*:\\s*`);let g=0,d=!1;for(let r=0;r<t.length;r++)if(u.test(t[r])&&!d){if(d=!0,c=r+1,m=t[r].indexOf(n)+1,t[r].includes("{}")){s=c,a=t[r].indexOf("{}")+3;break}const i=t[r].slice(m+n.length);if(i.includes("{")||i.includes("["))g=1;else{s=r+1,a=t[r].length+1;break}}else if(d&&(g+=(t[r].match(/{/g)||[]).length,g+=(t[r].match(/\[/g)||[]).length,g-=(t[r].match(/}/g)||[]).length,g-=(t[r].match(/]/g)||[]).length,g===0)){s=r+1,a=t[r].lastIndexOf("}")!==-1?t[r].lastIndexOf("}")+2:t[r].length+1;break}return{startColumn:m,endColumn:a,startLineNumber:c,endLineNumber:s}},U=/\\([0-7]{1,3})/g,V=e=>e.replace(U,(n,t)=>String.fromCharCode(parseInt(t,8))),D=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),K=e=>e.replace(/\/\/\/\/\/n/g,`
|
|
3
3
|
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),P=/[^a-zA-Z0-9\s]/g,T=e=>e.replace(P,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase()),q=e=>e.replace(/%[0-9A-Fa-f]{2}/g,n=>String.fromCharCode(parseInt(n.slice(1),16)));
|
package/dist/esm/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const e={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s)=>`${
|
|
1
|
+
const l=t=>t!=="latest"?`@${t}`:"",i=t=>t?`/${t}`:"",u=t=>{const s=typeof t=="string"?t.replace(/\/+$/,""):"";if(!s)return{name:"",subpath:""};const e=s.split("/"),r=s.startsWith("@")?2:1;return{name:e.slice(0,r).join("/"),subpath:e.slice(r).join("/")}},o={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s,e)=>`${o.skypack.url}/${t}${l(s)}${i(e)}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s,e)=>`${o.esmsh.url}/${t}${l(s)}${i(e)}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s,e)=>`${o.unpkg.url}/${t}${l(s)}${i(e)}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s,e)=>`${o.jsdelivr.url}/${t}${l(s)}${i(e)}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s,e)=>`${o.symbols.url}/${t}${l(s)}${i(e)}/+esm`}},h={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},U=(t={})=>{const{packageManager:s}=t;return h[s]||null},$=t=>{if(typeof t!="string")return t;const s=t.trim().match(/^[\^~](\d.*)$/);return s?s[1]:t},k=(t,s="latest",e="esmsh")=>{const r=o[e]||o.esmsh,{name:c,subpath:a}=u(t);return r.formatUrl(c||t,$(s),a)},d=(t,s="latest",e="esmsh")=>{const r=o[e]||o.esmsh,c=$(s),{name:a,subpath:p}=u(t);return`${r.url}/${a||t}${l(c)}${i(p)}/`},b=/^node:|^@symbo-ls\//,x=t=>typeof t=="string"&&b.test(t),D=/[<>…]/,j=t=>typeof t=="string"&&D.test(t),E=t=>!!t&&typeof t=="object"&&!Array.isArray(t),C=(t,s="skypack",e={})=>{const r=t.dependencies;if(!E(r))return"";const c=Object.keys(r);if(!c.length)return"";const a=e.pin||{},p={};for(const n of c){if(x(n)||j(n))continue;const m=a[n]||r[n]||"latest";p[n]=k(n,m,s),n.endsWith("/")||(p[n+"/"]=d(n,m,s))}if(!Object.keys(p).length)return"";const y='<script type="importmap">',g="<\/script>",f=`{
|
|
2
2
|
"imports": ${JSON.stringify(p,null,2)}
|
|
3
|
-
}`;return`${
|
|
3
|
+
}`;return`${y}${f}${g}`};export{o as CDN_PROVIDERS,h as PACKAGE_MANAGER_TO_CDN,d as getCDNDirUrl,k as getCDNUrl,U as getCdnProviderFromConfig,C as getImportMapScript,j as isMalformedDependency,x as isUnresolvableDependency,E as isValidDependencyMap,u as splitPackageSpecifier,$ as stripVersionRangePrefix};
|
package/dist/esm/object.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import{window as x}from"./globals.js";import{isFunction as
|
|
2
|
-
`;for(const
|
|
3
|
-
`;for(const
|
|
4
|
-
`:
|
|
5
|
-
`:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`)
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
`);t[c
|
|
17
|
-
|
|
1
|
+
import{window as x}from"./globals.js";import{isFunction as P,isObjectLike as g,isObject as k,isArray as _,isString as O,is as B}from"./types.js";import{unstackArrayOfObjects as J}from"./array.js";import{stringIncludesAny as Y}from"./string.js";import{isDOMNode as w}from"./node.js";import{METHODS_EXL as q}from"./keys.js";const A="production",S=e=>e.charCodeAt(0)===95&&e.charCodeAt(1)===95,T=(e,t,o,i)=>{if(P(e))return t?typeof e.call!="function"?e:e.call(t,t,o||t.state,i||t.context):void 0;if(e!=null&&t?.context?.plugins&&(_(e)||k(e)&&!w(e))){const r=t.context.plugins;for(const n of r)if(n.resolveHandler){const s=n.resolveHandler(e,t);if(typeof s=="function")return T(s,t,o,i)}}return e},ce=(e,t,o)=>{for(const i in t)e[i]=T(t[i],o)},fe=(e,t,o=[])=>{const i=o instanceof Set;for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(S(r)||(i?o.has(r):o.includes(r))||e[r]===void 0&&(e[r]=t[r]));return e},ue=(e,t,o=q)=>N(e,t,o,null),N=(e,t,o,i)=>{if(e===t)return e;if(i){for(let n=0;n<i.length;n+=2)if(i[n]===e&&i[n+1]===t)return e}const r=o instanceof Set;for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n)||S(n)||n==="constructor"||n==="prototype"||(r?o.has(n):o.includes(n)))continue;const s=e[n],f=t[n];if(g(s)&&g(f)){const u=i||[];u.push(e,t),N(s,f,o,u),u.length-=2}else s===void 0&&(e[n]=f)}return e},le=(e,t=[])=>{const o=t instanceof Set,i={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(S(r)||(o?t.has(r):t.includes(r))||(i[r]=e[r]));return i},ae=(e,t={})=>{const{exclude:o=[],cleanUndefined:i=!1,cleanNull:r=!1,visited:n=new WeakMap,handleExtends:s=!1}=t;if(!g(e)||w(e))return e;if(n.has(e))return n.get(e);const f=o instanceof Set?o:o.length>3?new Set(o):null,u=p=>f?f.has(p):o.includes(p),c=_(e)?[]:{};n.set(e,c);const l=[[e,c]];for(;l.length;){const[p,h]=l.pop();for(const y in p){if(!Object.prototype.hasOwnProperty.call(p,y)||S(y)||y==="__proto__"||u(y))continue;const a=p[y];if(!(i&&a===void 0)&&!(r&&a===null)){if(w(a)){h[y]=a;continue}if(s&&y==="extends"&&_(a)){h[y]=J(a,o);continue}if(P(a)){h[y]=a;continue}if(g(a))if(n.has(a))h[y]=n.get(a);else{const d=_(a)?[]:{};n.set(a,d),h[y]=d,l.push([a,d])}else h[y]=a}}}return c},R=(e,t={})=>{(e.node||e.__ref||e.parent||e.__element||e.parse)&&((e.__element||e.parent?.__element).warn("Trying to clone element or state at",e),e=e.parse?.());for(const o in e){const i=e[o];if(P(i))t[o]=i.toString();else if(k(i))t[o]={},R(i,t[o]);else if(_(i)){const r=t[o]=[];for(let n=0;n<i.length;n++){const s=i[n];k(s)?(r[n]={},R(s,r[n])):P(s)?r[n]=s.toString():r[n]=s}}else t[o]=i}return t},z=new Set(["&","*","-",":","%","{","}",">","<","@",".","/","!"," "]),M=(e={},t=0)=>{if(e===null||typeof e!="object"||e instanceof RegExp)return String(e);let o=!1;for(const n in e){o=!0;break}if(!o)return"{}";const i=" ".repeat(t);let r=`{
|
|
2
|
+
`;for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const s=e[n];let f=!1;for(let c=0;c<n.length;c++)if(z.has(n[c])){f=!0;break}const u=f?`'${n}'`:n;if(r+=`${i} ${u}: `,s instanceof RegExp)r+=String(s);else if(_(s)){r+=`[
|
|
3
|
+
`;for(const c of s)c instanceof RegExp?r+=`${i} ${String(c)},
|
|
4
|
+
`:g(c)&&c!==null?r+=`${i} ${M(c,t+2)},
|
|
5
|
+
`:O(c)?r+=`${i} '${c}',
|
|
6
|
+
`:r+=`${i} ${c},
|
|
7
|
+
`;r+=`${i} ]`}else g(s)?r+=M(s,t+1):O(s)?r+=Y(s,[`
|
|
8
|
+
`,"'"])?`\`${s}\``:`'${s}'`:r+=s;r+=`,
|
|
9
|
+
`}return r+=`${i}}`,r},H=[/^\(\s*\{[^}]*\}\s*\)\s*=>/,/^(\([^)]*\)|[^=]*)\s*=>/,/^function[\s(]/,/^async\s+/,/^\(\s*function/,/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/,/^(?:\*\s*)?[a-zA-Z_$][\w$]*\s*\((?:[^()]|\([^()]*\))*\)\s*\{[\s\S]*\}$/],K=/^["[{]/,U=/^(export|import)\s/,$=e=>{if(!e)return!1;const t=e.trim().replace(/\n\s*/g," ").trim();if(t===""||t==="{}"||t==="[]"||U.test(t)||!H.some(n=>n.test(t)))return!1;const i=t.charCodeAt(0),r=t.includes("=>");return!(i===123&&!r||i===91||K.test(t)&&!r)},Z=e=>(0,eval)(e),V=(e,t)=>{const o=/^(\s*(?:async\s+)?function\s*[\w$]*\s*\([^)]*\)\s*)\{/.exec(e);if(!o)return null;const i=o[0].length,r=[];let n=i,s=1,f=null;const u=e.length,c=new RegExp("^(?:const|let|var)\\s+"+t+"\\b");for(;n<u&&s>0;){const p=e[n];if(p==="/"&&e[n+1]==="/"){const h=e.indexOf(`
|
|
10
|
+
`,n);n=h===-1?u:h;continue}if(p==="/"&&e[n+1]==="*"){const h=e.indexOf("*/",n+2);n=h===-1?u:h+2;continue}if(p==='"'||p==="'"||p==="`"){const h=p;for(n++;n<u;){if(e[n]==="\\"){n+=2;continue}if(e[n]===h){n++;break}if(h==="`"&&e[n]==="$"&&e[n+1]==="{"){n+=2;let y=1;for(;n<u&&y>0;)e[n]==="{"?y++:e[n]==="}"&&y--,n++;continue}n++}continue}if(p==="{"){s++,n++;continue}if(p==="}"){s--,n++;continue}if(s===1&&c.test(e.slice(n))){const h=n;let y=0,a=n;for(;a<u;){const d=e[a];if(d==='"'||d==="'"||d==="`"){const m=d;for(a++;a<u;){if(e[a]==="\\"){a+=2;continue}if(e[a]===m){a++;break}a++}continue}if(d==="("||d==="["||d==="{"){y++,a++;continue}if(d===")"||d==="]"||d==="}"){if(y===0)break;y--,a++;continue}if(y===0&&(d===";"||d===`
|
|
11
|
+
`)){a++;break}a++}r.push([h,a]),n=a;continue}n++}if(!r.length)return null;let l=e;for(let p=r.length-1;p>=0;p--)l=l.slice(0,r[p][0])+l.slice(r[p][1]);return l},D=(e,t,o)=>{const i=String(e).trimStart();if(/^(export|import)\s/.test(i))return e;try{return o.window.eval(`(${e})`)}catch(r){const n=r&&r.message?r.message:String(r),s=/await is only valid in async/.test(n),f=/Identifier '([^']+)' has already been declared/.exec(n);let u=null;if(s){const c=String(e).trim();if(/^function[\s(]/.test(c))try{u=o.window.eval("(async "+c+")")}catch{}}else if(f){let c=String(e),l=f[1];for(let p=0;p<5;p++){const h=V(c,l);if(!h||h===c)break;c=h;try{u=o.window.eval("("+c+")");break}catch(y){const a=/Identifier '([^']+)' has already been declared/.exec(y&&y.message||String(y));if(!a||a[1]!==l)break}}}if(!u&&/Unexpected (token '\{'|identifier)/.test(n))try{const c=o.window.eval("({"+e+"})");if(c&&typeof c=="object"){const l=Object.keys(c);l.length===1&&typeof c[l[0]]=="function"&&(u=c[l[0]])}}catch{}return u||(typeof console<"u"&&console.warn&&console.warn(`[smbls] deepDestringifyFunctions: eval failed on ${t} \u2014 value will be left as a string. Reason: `+n+`.
|
|
12
|
+
First 200 chars of source: `+String(e).slice(0,200)),e)}},pe=(e,t={},o={window:{eval:Z}})=>{if(!e||typeof e!="object")return t;const i=[[e,t]];for(;i.length;){const[r,n]=i.pop();for(const s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;const f=r[s];if(O(f))$(f)?n[s]=D(f,`"${s}"`,o):n[s]=f;else if(_(f)){const u=n[s]=[];for(let c=0;c<f.length;c++){const l=f[c];if(O(l))u.push($(l)?D(l,`array index ${c} (prop "${s}")`,o):l);else if(k(l)){const p=F(l);if(p)u.push(p);else{const h={};u.push(h),i.push([l,h])}}else u.push(l)}}else if(k(f)){const u=F(f);if(u){n[s]=u;continue}const c=n[s]&&typeof n[s]=="object"&&!_(n[s])?n[s]:n[s]={};i.push([f,c])}else n[s]=f}}return t},W="Set",C="Map",I="RegExp",b="WeakMap",G="WeakSet",L=e=>{const t=Object.keys(e);return t.length===1&&t[0]==="__type"},E=(e,t)=>{if(!e||typeof e!="object")return e;const o=n=>E(n,t||(t=new WeakMap));if(e.__type===W&&_(e.values))return new Set(e.values.map(o));if(e.__type===C&&_(e.entries))return new Map(e.entries.map(n=>_(n)?[o(n[0]),o(n[1])]:n));if(e.__type===b&&L(e))return new WeakMap;if(e.__type===G&&L(e))return new WeakSet;if(e.__type===I&&O(e.source))try{return new RegExp(e.source,O(e.flags)?e.flags:"")}catch{return e}if(t||(t=new WeakMap),t.has(e))return t.get(e);let i=!1;if(_(e)){const n=new Array(e.length);t.set(e,n);for(let s=0;s<e.length;s++)n[s]=E(e[s],t),n[s]!==e[s]&&(i=!0);return i||t.set(e,e),i?n:e}const r={};t.set(e,r);for(const n of Object.keys(e))r[n]=E(e[n],t),r[n]!==e[n]&&(i=!0);return i||t.set(e,e),i?r:e},F=e=>{if(!e||typeof e!="object")return null;const t=e.__type;if(t!==I&&t!==W&&t!==C&&t!==b&&t!==G)return null;const o=E(e);return o===e?null:o},ye=e=>{if(!e||typeof e!="object")return e;const t={},o=[];for(const s of Object.keys(e)){const f=e[s];O(f)&&$(f)?o.push([s,f]):t[s]=E(f)}if(o.length===0)return t;const i=s=>/^[A-Za-z_$][\w$]*$/.test(s),r=o.filter(([s])=>i(s)),n=Object.keys(t).filter(i).map(s=>`var ${s} = __gs__[${JSON.stringify(s)}];`).join(`
|
|
13
|
+
`);try{const s=r.map(([c,l])=>`var ${c} = (${l});`).join(`
|
|
14
|
+
`),f="{ "+r.map(([c])=>`${JSON.stringify(c)}: ${c}`).join(", ")+" }",u=x.eval(`(function(__gs__) { ${n}
|
|
15
|
+
${s}
|
|
16
|
+
return ${f}; })`)(t);Object.assign(t,u)}catch{for(const[f,u]of r)try{const c=Object.keys(t).filter(i).map(l=>`var ${l} = __gs__[${JSON.stringify(l)}];`).join(`
|
|
17
|
+
`);t[f]=x.eval(`(function(__gs__) { ${c}
|
|
18
|
+
return (${u}); })`)(t)}catch{try{t[f]=x.eval(`(${u})`)}catch{t[f]=u}}}for(const[s,f]of o)if(!i(s))try{t[s]=x.eval(`(${f})`)}catch{t[s]=f}return t},he=(e,t={verbose:!0})=>{try{return e?x.eval("("+e+")"):{}}catch(o){t.verbose&&console.warn(o)}},de=(e,...t)=>Object.prototype.hasOwnProperty.call(e,...t),X=e=>{for(const t in e)return!1;return!0},ge=e=>k(e)&&X(e),_e=()=>Object.create(null),we=(e,t,o={})=>{const i=o.exclude||[],r=o.preventUnderscore;for(const n in t)i.includes(n)||!r&&S(n)||n==="constructor"||n==="prototype"||t[n]!==void 0&&(e[n]=t[n]);return e},Oe=(e,t,o=[])=>{const i=o instanceof Set;for(const r in t)S(r)||r==="constructor"||r==="prototype"||(i?o.has(r):o.includes(r))||(e[r]=t[r]);return e},v=(e,t,o={},i=new WeakMap)=>{if(!g(e)||!g(t)||w(e)||w(t))return t;if(i.has(e))return i.get(e);i.set(e,e);const r=o.exclude,n=r?r instanceof Set?r:new Set(r):null,s=!o.preventForce;for(const f in t){if(!Object.prototype.hasOwnProperty.call(t,f)||n&&n.has(f)||s&&S(f)||f==="constructor"||f==="prototype")continue;const u=e[f],c=t[f];w(c)?e[f]=c:g(u)&&g(c)?e[f]=v(u,c,o,i):c!==void 0&&(e[f]=c)}return e},Q=(e,t,o=new Set)=>{if(typeof e!="object"||typeof t!="object"||e===null||t===null)return e===t;if(o.has(e)||o.has(t))return!0;o.add(e),o.add(t);const i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(let n=0;n<i.length;n++){const s=i[n];if(!Object.prototype.hasOwnProperty.call(t,s)||!Q(e[s],t[s],o))return!1}return!0},j=new Set(["node","__ref"]),Se=(e,t,o=j)=>{if(e===t)return!0;if(!g(e)||!g(t)||w(e)||w(t))return e===t;const i=o instanceof Set?o:new Set(o),r=new WeakSet;function n(s,f){if(r.has(f))return!0;r.add(f);for(const u in f){if(!Object.prototype.hasOwnProperty.call(f,u)||i.has(u))continue;if(!Object.prototype.hasOwnProperty.call(s,u))return!1;const c=f[u],l=s[u];if(w(c)||w(l)){if(c!==l)return!1}else if(g(c)&&g(l)){if(!n(l,c))return!1}else if(c!==l)return!1}return!0}return n(e,t)},ke=(e,t)=>{if(t==null)return e;if(B(t)("string","number"))delete e[t];else if(_(t))for(let o=0;o<t.length;o++)delete e[t[o]];else throw new Error("Invalid input: props must be a string or an array of strings");return e},ee=e=>{if(e===null||typeof e!="object")return e;const t=Object.create(null);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=ee(e[o]));return t},xe=(e,t)=>{if(e.length===0)return t;const o={};let i=o;for(let r=0;r<e.length;r++)r===e.length-1&&t?i[e[r]]=t:(i[e[r]]={},i=i[e[r]]);return o},Ee=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let r=0;r<t.length-1;r++){if(o[t[r]]===void 0)return;o=o[t[r]]}const i=t[t.length-1];o&&Object.prototype.hasOwnProperty.call(o,i)&&delete o[i]},Pe=(e,t,o)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let i=e;for(let r=0;r<t.length-1;r++)(!i[t[r]]||typeof i[t[r]]!="object")&&(i[t[r]]={}),i=i[t[r]];return i[t[t.length-1]]=o,e},$e=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let i=0;i<t.length;i++){if(o==null)return;o=o[t[i]]}return o},Ae=e=>{let o=[],i=0;for(let r=0;r<e.length;r++)if(o.length<2)o.push(e[r]);else if(e[r]===o[r%2]?i++:(o=[e[r-1],e[r]],i=1),i>=20)return(A==="test"||A==="development")&&console.warn("Warning: Potential infinite loop detected due to repeated sequence:",o),!0},Te=e=>{const t=new WeakSet;function o(i){if(i&&typeof i=="object"){if(t.has(i))return!0;t.add(i);for(const r in i)if(Object.prototype.hasOwnProperty.call(i,r)&&o(i[r]))return console.log(i,"cycle at "+r),!0}return!1}return o(e)},Ne=(e,t)=>{const o=t instanceof Set?t:new Set(t),i={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&!o.has(r)&&(i[r]=e[r]);return i};export{le as clone,xe as createNestedObject,ee as createObjectWithoutPrototype,ae as deepClone,Se as deepContains,pe as deepDestringifyFunctions,ue as deepMerge,R as deepStringifyFunctions,ye as destringifyGlobalScope,Ae as detectInfiniteLoop,Ne as excludeKeysFromObject,T as exec,$e as getInObjectByPath,$ as hasFunction,de as hasOwnProperty,Te as isCyclic,X as isEmpty,ge as isEmptyObject,Q as isEqualDeep,_e as makeObjectWithoutPrototype,ce as map,fe as merge,M as objectToString,we as overwrite,v as overwriteDeep,Oe as overwriteShallow,ke as removeFromObject,Ee as removeNestedKeyByPath,Pe as setInObjectByPath,he as stringToObject};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as a,isString as
|
|
1
|
+
import{isObject as a,isString as y}from"./types.js";const d="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:d,key:"",full:""};let o=null,e=t;if(t.includes("/")){const r=t.indexOf("/");o=t.slice(0,r),e=t.slice(r+1)}e=e.replace(/\.symbo\.ls$/iu,""),o||(o=d);const s=e?`${o}/${e}`:"";return{owner:o,key:e,full:s}}const h=(n,t,o,e)=>{for(const s in t){const r=e?`${e}/${s}`:s;o&&o.has(r)||(s in n?a(n[s])&&a(t[s])&&h(n[s],t[s],o,r):n[s]=t[s])}},m=(n,t,o)=>{if(!a(n)||!t.size)return n;const e=`${o}/`;let s=!1;for(const i of t)if(i.startsWith(e)){s=!0;break}if(!s)return n;const r={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const l=`${o}/${i}`;t.has(l)||(r[i]=m(n[i],t,l))}return r},R=new Set,U=new Set(["components","pages","functions","snippets","methods"]),b=(n,t)=>t===""&&U.has(n),E=n=>n.replace(/\.js$/iu,""),w=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const o of n){if(!y(o))continue;const e=o.split("/").map(s=>E(s.trim())).filter(Boolean).join("/");e&&t.add(e)}return t},T=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),g=n=>a(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),O=n=>n.library!==void 0?n.library:n.key??n.name,_=(n,t,o)=>{const e=w(t.sharedLibIgnore);t.sharePages===!1&&e.add("pages");const s=e.size?new Set([...o,...e]):o;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&!(r==="sharePages"||r==="sharedLibIgnore")&&!s.has(r))if(a(t[r])&&a(n[r]))if(r==="designSystem")h(n[r],t[r],s,r);else for(const i in t[r])s.has(`${r}/${i}`)||(i in n[r]?b(r,n[r][i])&&!b(r,t[r][i])&&(n[r][i]=t[r][i]):n[r][i]=t[r][i]);else r in n||(n[r]=m(t[r],s,r))},G=(n,t)=>{if(!(!t||!t.length))for(let o=0;o<t.length;o++){let e=t[o],s=R;g(e)&&(s=w(e.ignoreList),e=e.library),a(e)&&_(n,e,s)}};async function B(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const e=await P(n,t);return e||$(n,t)}async function P(n,t={}){const o=t.kvBaseUrl||I,e=t.env||"production",s=`${o}/kv/${encodeURIComponent(n)}?env=${e}`;try{const r=await fetch(s,{method:"GET"});return r.ok&&(await r.json())?.value||null}catch{return null}}async function $(n,t={}){const o=t.apiBaseUrl||j,{key:e}=f(n);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(e)}&limit=10`,r=await fetch(s,{method:"GET"});if(!r.ok)return null;const i=await r.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(S=>{const{key:v}=f(S?.key);return v.toLowerCase()===e.toLowerCase()});if(!c?.id&&!c?._id)return null;const L=c.id||c._id,A=`${o}/core/projects/${encodeURIComponent(L)}/data?branch=main`,u=await fetch(A,{method:"GET"});if(!u.ok)return null;const p=await u.json();return p?.data||p||null}catch{return null}}async function k(n,t={}){if(a(n))return n;if(y(n)){const{full:o}=f(n);if(!o)return null;try{const e=await B(o,t);return e||console.warn(`[smbls] Shared library "${o}" not found`),e}catch(e){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,e.message),null}}return null}async function z(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async e=>{if(g(e)){const s=await k(O(e),t);return s?{library:s,ignoreList:e.ignoreList}:null}return k(e,t)}))).filter(Boolean)}export{h as deepDefaults,B as fetchLibraryData,g as isWrappedLibrary,G as mergeSharedLibraries,w as normalizeIgnoreList,f as normalizeLibraryKey,z as resolveSharedLibraries,T as sharedLibrary};
|
package/dist/esm/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addProtoToArray as
|
|
1
|
+
import{addProtoToArray as y}from"./array.js";import{STATE_METHODS as u}from"./keys.js";import{deepClone as a,deepMerge as g,overwriteDeep as h,overwriteShallow as S}from"./object.js";import{is as f,isObject as p,isObjectLike as b,isString as P}from"./types.js";const D=e=>{const{state:r,props:o,__ref:t}=e,n=o?.state||r;return f(n)("string","number")?(t.__state=n,{value:n}):n===!0?(t.__state=e.key,{}):n?(t.__hasRootState=!0,n):!1},m=(e,r)=>{if(!e.includes("~/"))return;if(e.split("~/").length>1)return r.root},w=(e,r)=>{if(!e.includes("../"))return;const t=e.split("../").length-1;for(let n=0;n<t;n++){if(!r.parent)return null;r=r.parent}return r},x=(e,r,o={})=>{const t=P(e)?e.split("/"):[e],n=t.length-1;for(let s=0;s<n;s++){const i=t[s],c=t[s+1];if(i==="__proto__"||c==="__proto__")return;let l=r[i];l||(l=r[i]={}),l[c]||(l[c]={}),e=c,r=l}return o.returnParent?r:r[e]},v=(e,r,o={})=>{let n=e.__ref.__state;if(!O(e))return;const s=m(n,r.state);let i=r.state;if(s)i=s,n=n.replaceAll("~/","");else{const c=w(n,r.state);c&&(i=c,n=n.replaceAll("../",""))}if(i)return x(n,i,o)},E=(e,r)=>{const o=e.__ref,t=v(e,r);if(t===void 0)return e.state;if(f(t)("object","array"))return a(t);if(f(t)("string","number","boolean"))return o.__stateType=typeof t,{value:t};console.warn(o.__state,"is not present. Replacing with",{})},O=e=>{const{__ref:r}=e,o=r?.__state;return!!(o&&f(o)("number","string","boolean"))},K=function(e){return b(e)?!!(e.update&&e.parse&&e.clean&&e.create&&e.parent&&e.destroy&&e.rootUpdate&&e.parentUpdate&&e.keys&&e.values&&e.toggle&&e.replace&&e.quietUpdate&&e.quietReplace&&e.add&&e.apply&&e.applyReplace&&e.setByPath&&e.setPathCollection&&e.removeByPath&&e.removePathCollection&&e.getByPath&&e.applyFunction&&e.__element&&e.__children):!1},T=(e,r)=>{if(!e)return r||{};const o=e.split("/"),t={};let n=t;const s=o.length-1;for(let i=0;i<=s;i++)n[o[i]]=i===s?r||{}:{},n=n[o[i]];return t},B=(e,r)=>{const{__element:o}=r,t=o?.state;if(!t)return;const n=a(t,u),s={[e.key]:n},i=p(t.__depends)?{...t.__depends,...s}:s;return Array.isArray(t)?y(t,{...Object.getPrototypeOf(t),__depends:i}):Object.setPrototypeOf(t,{...Object.getPrototypeOf(t),__depends:i}),n},C=(e,r,o={})=>{const{overwrite:t}=o;if(!t)return;const n=t==="shallow";if(t==="merge"){g(e,r,u);return}(n?S:h)(e,r,u)},d="__polyglotSeededKeys",_=e=>{if(!p(e))return new Set;let r=e[d];if(!(r instanceof Set)){r=new Set;try{Object.defineProperty(e,d,{value:r,enumerable:!1,writable:!0,configurable:!0})}catch{}}return r},R=(e,r,o)=>_(e).has(r)?!0:!p(o)||o[r]===void 0,F=(e,r)=>(_(e).add(r),r);export{B as applyDependentState,D as checkForStateTypes,O as checkIfInherits,E as createInheritedState,T as createNestedObjectByKeyPath,v as findInheritedState,x as getChildStateInKey,w as getParentStateInKey,m as getRootStateInKey,R as isPolyglotWritableKey,K as isState,F as markPolyglotSeeded,C as overwriteState,_ as polyglotSeededKeys};
|
package/dist/esm/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const
|
|
2
|
-
`);let a=-1,f=-1,
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),
|
|
1
|
+
const N=(e,r)=>{for(const t of r)if(e.includes(t))return!0;return!1},O=(e,r)=>{const t=new RegExp(`[${r.join("\\")}]`,"g");return e.replace(t,"")},L={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},x=(e,r)=>r.split(".").reduce((t,a)=>t?.[a],e);function I(e,r,t={}){const{bracketsLength:a=2}=t,f=a===3?"{{{":"{{";if(!e.includes(f))return e;const m=L[a],c=r||this.state||{},i=this;return e.replace(m,(u,d,n,l)=>{const g=n.trim();if(l){const s=i?.context,o=s?.functions?.[l]||s?.utils?.[l]||s?.methods?.[l]||s?.snippets?.[l]||i?.[l];if(o&&typeof o=="function")try{return String(o.call(i,g)??"")}catch{return""}return""}if(d){const s=(d.match(/\.\.\//g)||[]).length;let o=c;for(let p=0;p<s;p++){if(!o||!o.parent)return"";o=o.parent}if(g==="parent")return String(o.value??"");const h=x(o,g);return h!=null&&typeof h=="object"?"":String(h??"")}else{const s=x(c,g);if(s!=null&&typeof s!="object")return String(s);const o=i?.context?.polyglot;if(o?.translations){const h=c?.root?.lang||c?.lang||i?.context?.state?.lang||o.defaultLang||"en",p=o.translations[h];if(p){const C=x(p,g);if(C!=null&&typeof C!="object")return String(C);for(const w in p){const b=p[w];if(b&&typeof b=="object"&&!Array.isArray(b)){const S=x(b,g);if(S!=null&&typeof S!="object")return String(S)}}}const y=x(o.translations,g);if(y!=null&&typeof y!="object")return String(y)}return""}})}const R=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,k=(e,r)=>{const t=e.split(`
|
|
2
|
+
`);let a=-1,f=-1,m=-1,c=-1;const i=new RegExp(`\\b${r}\\b\\s*:\\s*`);let u=0,d=!1;for(let n=0;n<t.length;n++)if(i.test(t[n])&&!d){if(d=!0,a=n+1,m=t[n].indexOf(r)+1,t[n].includes("{}")){f=a,c=t[n].indexOf("{}")+3;break}const l=t[n].slice(m+r.length);if(l.includes("{")||l.includes("["))u=1;else{f=n+1,c=t[n].length+1;break}}else if(d&&(u+=(t[n].match(/{/g)||[]).length,u+=(t[n].match(/\[/g)||[]).length,u-=(t[n].match(/}/g)||[]).length,u-=(t[n].match(/]/g)||[]).length,u===0)){f=n+1,c=t[n].lastIndexOf("}")!==-1?t[n].lastIndexOf("}")+2:t[n].length+1;break}return{startColumn:m,endColumn:c,startLineNumber:a,endLineNumber:f}},j=/\\([0-7]{1,3})/g,E=e=>e.replace(j,(r,t)=>String.fromCharCode(parseInt(t,8))),$=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),F=e=>e.replace(/\/\/\/\/\/n/g,`
|
|
3
|
+
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),A=/[^a-zA-Z0-9\s]/g,_=e=>e.replace(A,r=>"%"+r.charCodeAt(0).toString(16).toUpperCase()),v=e=>e.replace(/%[0-9A-Fa-f]{2}/g,r=>String.fromCharCode(parseInt(r.slice(1),16)));export{v as customDecodeURIComponent,_ as customEncodeURIComponent,F as decodeNewlines,$ as encodeNewlines,k as findKeyPosition,R as lowercaseFirstLetter,I as replaceLiteralsWithObjectFields,E as replaceOctalEscapeSequences,N as stringIncludesAny,O as trimStringFromSymbols};
|
package/object.js
CHANGED
|
@@ -289,6 +289,12 @@ export const objectToString = (obj = {}, indent = 0) => {
|
|
|
289
289
|
return String(obj)
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
// A RegExp has no own enumerable keys, so the generic walk below would
|
|
293
|
+
// print `{}`. `String(/foo/g)` is the valid source literal `/foo/g` —
|
|
294
|
+
// exactly what a written-back .js file needs
|
|
295
|
+
// (FRANK-EMIT-REGEXP-SCOPE-VALUE-DIES-TO-EMPTY-OBJECT-1).
|
|
296
|
+
if (obj instanceof RegExp) return String(obj)
|
|
297
|
+
|
|
292
298
|
// Handle empty object case - avoid Object.keys allocation
|
|
293
299
|
let hasKeys = false
|
|
294
300
|
for (const _k in obj) {
|
|
@@ -313,10 +319,14 @@ export const objectToString = (obj = {}, indent = 0) => {
|
|
|
313
319
|
const stringedKey = keyNeedsQuotes ? `'${key}'` : key
|
|
314
320
|
str += `${spaces} ${stringedKey}: `
|
|
315
321
|
|
|
316
|
-
if (
|
|
322
|
+
if (value instanceof RegExp) {
|
|
323
|
+
str += String(value)
|
|
324
|
+
} else if (isArray(value)) {
|
|
317
325
|
str += '[\n'
|
|
318
326
|
for (const element of value) {
|
|
319
|
-
if (
|
|
327
|
+
if (element instanceof RegExp) {
|
|
328
|
+
str += `${spaces} ${String(element)},\n`
|
|
329
|
+
} else if (isObjectLike(element) && element !== null) {
|
|
320
330
|
str += `${spaces} ${objectToString(element, indent + 2)},\n`
|
|
321
331
|
} else if (isString(element)) {
|
|
322
332
|
str += `${spaces} '${element}',\n`
|
|
@@ -348,7 +358,16 @@ const FN_PATTERNS = [
|
|
|
348
358
|
/^function[\s(]/,
|
|
349
359
|
/^async\s+/,
|
|
350
360
|
/^\(\s*function/,
|
|
351
|
-
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s
|
|
361
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/,
|
|
362
|
+
// OBJECT-METHOD-SHORTHAND toString: `stopTracks(v4) { … }`, `*walk() { … }`.
|
|
363
|
+
// frank emissions predating plugins/frank/fnString.js normalization stored
|
|
364
|
+
// these verbatim; without this pattern the PLAIN (non-async) shape was
|
|
365
|
+
// never even recognized as a function string, so the shorthand recovery in
|
|
366
|
+
// _destringifyFnString could not run and the value stayed a string
|
|
367
|
+
// (silent dead handler). Anchored to a `{…}`-terminated body so ordinary
|
|
368
|
+
// prose containing `word(…)` never matches; params allow one nesting level
|
|
369
|
+
// for parenthesized defaults.
|
|
370
|
+
/^(?:\*\s*)?[a-zA-Z_$][\w$]*\s*\((?:[^()]|\([^()]*\))*\)\s*\{[\s\S]*\}$/
|
|
352
371
|
]
|
|
353
372
|
const RE_JSON_LIKE = /^["[{]/
|
|
354
373
|
// Module-source prefixes. A string starting with `export ` or `import ` is a
|
|
@@ -542,6 +561,25 @@ const _destringifyFnString = (str, label, opts) => {
|
|
|
542
561
|
}
|
|
543
562
|
}
|
|
544
563
|
}
|
|
564
|
+
// OBJECT-METHOD-SHORTHAND recovery: `refresh() {…}` / `async mic() {…}`
|
|
565
|
+
// (a Function.prototype.toString of a shorthand method, stored by frank
|
|
566
|
+
// emissions predating plugins/frank/fnString.js normalization) is not a
|
|
567
|
+
// standalone expression — `('(' + str + ')')` throws
|
|
568
|
+
// "Unexpected token '{'" (plain) or "Unexpected identifier" (async) —
|
|
569
|
+
// but it IS valid inside an object literal. Wrap, eval, pluck the single
|
|
570
|
+
// method. This also faithfully revives `super`-using and quoted-name
|
|
571
|
+
// methods, which no standalone rewrite can.
|
|
572
|
+
if (!recovered && /Unexpected (token '\{'|identifier)/.test(msg)) {
|
|
573
|
+
try {
|
|
574
|
+
const wrapped = opts.window.eval('({' + str + '})')
|
|
575
|
+
if (wrapped && typeof wrapped === 'object') {
|
|
576
|
+
const wkeys = Object.keys(wrapped)
|
|
577
|
+
if (wkeys.length === 1 && typeof wrapped[wkeys[0]] === 'function') {
|
|
578
|
+
recovered = wrapped[wkeys[0]]
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
} catch (_) { /* fall through to the warning below */ }
|
|
582
|
+
}
|
|
545
583
|
if (recovered) return recovered
|
|
546
584
|
// FR-1 (FRANK-RUNNER.md): make the silent fallback loud so consumers
|
|
547
585
|
// notice when a handler ends up stored as a string instead of a
|
|
@@ -591,14 +629,29 @@ export const deepDestringifyFunctions = (
|
|
|
591
629
|
? _destringifyFnString(arrProp, `array index ${i} (prop "${prop}")`, opts)
|
|
592
630
|
: arrProp)
|
|
593
631
|
} else if (isObject(arrProp)) {
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
632
|
+
const tagged = _rehydrateTagged(arrProp)
|
|
633
|
+
if (tagged) {
|
|
634
|
+
arr.push(tagged)
|
|
635
|
+
} else {
|
|
636
|
+
const child = {}
|
|
637
|
+
arr.push(child)
|
|
638
|
+
stack.push([arrProp, child])
|
|
639
|
+
}
|
|
597
640
|
} else {
|
|
598
641
|
arr.push(arrProp)
|
|
599
642
|
}
|
|
600
643
|
}
|
|
601
644
|
} else if (isObject(objProp)) {
|
|
645
|
+
// `{__type:'RegExp'|'Set'|'Map', …}` (frank's stringifyFunctions
|
|
646
|
+
// tagged forms) revive to real instances instead of being walked —
|
|
647
|
+
// the walk would clone each to a dead plain object
|
|
648
|
+
// (FRANK-EMIT-REGEXP-SCOPE-VALUE-DIES-TO-EMPTY-OBJECT-1,
|
|
649
|
+
// FRANK-GLOBALSCOPE-CONST-PROTOTYPE-LOSS-1).
|
|
650
|
+
const tagged = _rehydrateTagged(objProp)
|
|
651
|
+
if (tagged) {
|
|
652
|
+
dest[prop] = tagged
|
|
653
|
+
continue
|
|
654
|
+
}
|
|
602
655
|
// Preserve any pre-existing container the caller passed in for this
|
|
603
656
|
// key (matches the legacy `destringified[prop]` argument); otherwise
|
|
604
657
|
// allocate one.
|
|
@@ -619,18 +672,100 @@ export const deepDestringifyFunctions = (
|
|
|
619
672
|
// destringifyGlobalScope-set-map.test.js.
|
|
620
673
|
const TYPE_TAG_SET = 'Set'
|
|
621
674
|
const TYPE_TAG_MAP = 'Map'
|
|
675
|
+
const TYPE_TAG_REGEXP = 'RegExp'
|
|
676
|
+
const TYPE_TAG_WEAKMAP = 'WeakMap'
|
|
677
|
+
const TYPE_TAG_WEAKSET = 'WeakSet'
|
|
678
|
+
|
|
679
|
+
// A weak tag carries NO payload (frank cannot read one out of a WeakMap, and no
|
|
680
|
+
// consumer could use one — the keys are object identities the transport drops),
|
|
681
|
+
// so the shape guard the other three use on their payload key is not available
|
|
682
|
+
// here. The discriminator instead is "the tag IS the whole object": exactly one
|
|
683
|
+
// own key, `__type`. A user object that carries data beside such a field is the
|
|
684
|
+
// user's own object and passes through with its contents intact
|
|
685
|
+
// (FRANK-WEAKMAP-CONST-STILL-DIES-TO-EMPTY-OBJECT-1).
|
|
686
|
+
const _isBareTag = (val) => {
|
|
687
|
+
const keys = Object.keys(val)
|
|
688
|
+
return keys.length === 1 && keys[0] === '__type'
|
|
689
|
+
}
|
|
622
690
|
|
|
623
691
|
/**
|
|
624
|
-
* Rehydrate Set / Map tagged forms back into real
|
|
625
|
-
* Pass-through for any other value (including user
|
|
626
|
-
* happen to carry an unrelated `__type` field — only
|
|
627
|
-
* rehydrate).
|
|
692
|
+
* Rehydrate Set / Map / RegExp / WeakMap / WeakSet tagged forms back into real
|
|
693
|
+
* instances, at ANY DEPTH. Pass-through for any other value (including user
|
|
694
|
+
* objects that happen to carry an unrelated `__type` field — only the five tags
|
|
695
|
+
* above rehydrate).
|
|
696
|
+
*
|
|
697
|
+
* A revived WeakMap / WeakSet is EMPTY by construction, and that is the whole
|
|
698
|
+
* contract: what a consumer needs back from one is its PROTOTYPE, and the shape
|
|
699
|
+
* both types are authored in — a memo cache — starts empty on every page load
|
|
700
|
+
* anyway.
|
|
701
|
+
*
|
|
702
|
+
* The walk into plain objects and arrays is what
|
|
703
|
+
* FRANK-GLOBALSCOPE-CONST-PROTOTYPE-LOSS-1 added: frank tags a nested
|
|
704
|
+
* `{ re: /x/g }` / `[new Set([1])]` too, and a top-level-only revive would
|
|
705
|
+
* hand those back as the dead tagged shell — the same
|
|
706
|
+
* `TypeError: … is not a function` one level down. A container is rebuilt
|
|
707
|
+
* ONLY when a descendant actually revived, so ordinary data keeps its
|
|
708
|
+
* identity.
|
|
709
|
+
*
|
|
710
|
+
* Function STRINGS inside a revived Set or Map stay strings: a member of a
|
|
711
|
+
* Set was `{}` before this existed, so there is no prior contract that
|
|
712
|
+
* destringified one.
|
|
628
713
|
*/
|
|
629
|
-
const _rehydrateTaggedValue = (val) => {
|
|
714
|
+
const _rehydrateTaggedValue = (val, seen) => {
|
|
630
715
|
if (!val || typeof val !== 'object') return val
|
|
631
|
-
|
|
632
|
-
if (val.__type ===
|
|
633
|
-
|
|
716
|
+
const walk = (v) => _rehydrateTaggedValue(v, seen || (seen = new WeakMap()))
|
|
717
|
+
if (val.__type === TYPE_TAG_SET && isArray(val.values)) return new Set(val.values.map(walk))
|
|
718
|
+
if (val.__type === TYPE_TAG_MAP && isArray(val.entries)) {
|
|
719
|
+
return new Map(val.entries.map((e) => (isArray(e) ? [walk(e[0]), walk(e[1])] : e)))
|
|
720
|
+
}
|
|
721
|
+
if (val.__type === TYPE_TAG_WEAKMAP && _isBareTag(val)) return new WeakMap()
|
|
722
|
+
if (val.__type === TYPE_TAG_WEAKSET && _isBareTag(val)) return new WeakSet()
|
|
723
|
+
if (val.__type === TYPE_TAG_REGEXP && isString(val.source)) {
|
|
724
|
+
// Guard: a corrupt flags string must not take down the whole
|
|
725
|
+
// destringify pass — leave the tagged object as-is instead.
|
|
726
|
+
try { return new RegExp(val.source, isString(val.flags) ? val.flags : '') } catch (e) { return val }
|
|
727
|
+
}
|
|
728
|
+
if (!seen) seen = new WeakMap()
|
|
729
|
+
if (seen.has(val)) return seen.get(val)
|
|
730
|
+
let changed = false
|
|
731
|
+
if (isArray(val)) {
|
|
732
|
+
const out = new Array(val.length)
|
|
733
|
+
seen.set(val, out)
|
|
734
|
+
for (let i = 0; i < val.length; i++) {
|
|
735
|
+
out[i] = _rehydrateTaggedValue(val[i], seen)
|
|
736
|
+
if (out[i] !== val[i]) changed = true
|
|
737
|
+
}
|
|
738
|
+
if (!changed) seen.set(val, val)
|
|
739
|
+
return changed ? out : val
|
|
740
|
+
}
|
|
741
|
+
const out = {}
|
|
742
|
+
seen.set(val, out)
|
|
743
|
+
for (const key of Object.keys(val)) {
|
|
744
|
+
out[key] = _rehydrateTaggedValue(val[key], seen)
|
|
745
|
+
if (out[key] !== val[key]) changed = true
|
|
746
|
+
}
|
|
747
|
+
if (!changed) seen.set(val, val)
|
|
748
|
+
return changed ? out : val
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// deepDestringifyFunctions rehydrates every tagged form frank's
|
|
752
|
+
// `stringifyFunctions` can emit for an element-scope value: RegExp
|
|
753
|
+
// (FRANK-EMIT-REGEXP-SCOPE-VALUE-DIES-TO-EMPTY-OBJECT-1) and, since
|
|
754
|
+
// FRANK-GLOBALSCOPE-CONST-PROTOTYPE-LOSS-1, Set and Map — which used to be
|
|
755
|
+
// tagged on the globalScope channel only, so the same const worked in
|
|
756
|
+
// globalScope and threw in an element-scope method. WeakMap and WeakSet joined
|
|
757
|
+
// them in FRANK-WEAKMAP-CONST-STILL-DIES-TO-EMPTY-OBJECT-1: `const
|
|
758
|
+
// _columnIndexCache = new WeakMap()` read from an element-scope method threw
|
|
759
|
+
// `this._columnIndexCache.get is not a function` on a live board. Returns null
|
|
760
|
+
// (never a revived value) when `val` is not a tagged form; all five revive to
|
|
761
|
+
// objects, so null is unambiguous.
|
|
762
|
+
const _rehydrateTagged = (val) => {
|
|
763
|
+
if (!val || typeof val !== 'object') return null
|
|
764
|
+
const tag = val.__type
|
|
765
|
+
if (tag !== TYPE_TAG_REGEXP && tag !== TYPE_TAG_SET && tag !== TYPE_TAG_MAP &&
|
|
766
|
+
tag !== TYPE_TAG_WEAKMAP && tag !== TYPE_TAG_WEAKSET) return null
|
|
767
|
+
const revived = _rehydrateTaggedValue(val)
|
|
768
|
+
return revived === val ? null : revived
|
|
634
769
|
}
|
|
635
770
|
|
|
636
771
|
/**
|
|
@@ -639,7 +774,10 @@ const _rehydrateTaggedValue = (val) => {
|
|
|
639
774
|
* function, so helpers can reference constants and other helpers naturally.
|
|
640
775
|
*
|
|
641
776
|
* Also rehydrates Set/Map tagged forms (FT-FRANK-1) so `globalScope.X.has(y)`
|
|
642
|
-
* works for the original Set/Map constructors authors put on globalScope.js
|
|
777
|
+
* works for the original Set/Map constructors authors put on globalScope.js,
|
|
778
|
+
* and the contentless WeakMap/WeakSet tags
|
|
779
|
+
* (FRANK-WEAKMAP-CONST-STILL-DIES-TO-EMPTY-OBJECT-1) so `globalScope.X.get(o)`
|
|
780
|
+
* works for a weak memo cache.
|
|
643
781
|
*/
|
|
644
782
|
export const destringifyGlobalScope = (gs) => {
|
|
645
783
|
if (!gs || typeof gs !== 'object') return gs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/utils",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.770",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"browser": "./dist/esm/index.js",
|
|
61
61
|
"sideEffects": false,
|
|
62
62
|
"publishConfig": {
|
|
63
|
-
"access": "
|
|
63
|
+
"access": "public"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/sharedLibraries.js
CHANGED
|
@@ -105,6 +105,37 @@ const copyWithNestedIgnores = (value, skip, prefix) => {
|
|
|
105
105
|
|
|
106
106
|
const EMPTY_IGNORE = new Set()
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* The section bags whose values are always objects or functions, never text.
|
|
110
|
+
* Same list frank's stub-phantom sweep walks (`plugins/frank/toJSON.js`), for
|
|
111
|
+
* the same reason: these are the bags a stubbed external import can land in.
|
|
112
|
+
*/
|
|
113
|
+
const OBJECT_BAGS = new Set(['components', 'pages', 'functions', 'snippets', 'methods'])
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Is the value sitting at `bag[key]` a STUB PHANTOM rather than a real value?
|
|
117
|
+
*
|
|
118
|
+
* When frank bundles a project, `stubExternalsPlugin` replaces an import it
|
|
119
|
+
* cannot resolve with a no-op proxy; `stringifyFunctions` then reduces that
|
|
120
|
+
* proxy to the empty string, so the published payload carries `""` where a
|
|
121
|
+
* component/page/function should be. In `OBJECT_BAGS` an empty string is never
|
|
122
|
+
* a value a library can legitimately mean — it is only ever that signature.
|
|
123
|
+
*
|
|
124
|
+
* This matters because the merge below is FIRST-WINS, which is correct for
|
|
125
|
+
* real values (an earlier declaration outranks a later one, and the consumer
|
|
126
|
+
* outranks every library) but wrong for a phantom: an earlier library's `""`
|
|
127
|
+
* would permanently shadow the real object a LATER declared library carries
|
|
128
|
+
* under the same name, and the consumer that declared the good library would
|
|
129
|
+
* still get `""`. Measured live 2026-08-21 on the published `workspace-ui`
|
|
130
|
+
* payload: 25 names held a real object in a later library and every one was
|
|
131
|
+
* thrown away (FRANK-STUB-PHANTOM-SHADOWS-REAL-LIB-VALUE-1).
|
|
132
|
+
*
|
|
133
|
+
* So a phantom does not occupy its slot. Precedence is untouched everywhere
|
|
134
|
+
* else — `designSystem`, `state` and every other key keep empty strings,
|
|
135
|
+
* because there `''` is a legal value.
|
|
136
|
+
*/
|
|
137
|
+
const isStubPhantom = (bag, value) => value === '' && OBJECT_BAGS.has(bag)
|
|
138
|
+
|
|
108
139
|
const stripJsExt = (segment) => segment.replace(/\.js$/iu, '')
|
|
109
140
|
|
|
110
141
|
/**
|
|
@@ -190,7 +221,14 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
190
221
|
} else {
|
|
191
222
|
for (const k in sharedLib[key]) {
|
|
192
223
|
if (skip.has(`${key}/${k}`)) continue // nested skip: 'components/Header'
|
|
193
|
-
if (!(k in context[key]))
|
|
224
|
+
if (!(k in context[key])) {
|
|
225
|
+
context[key][k] = sharedLib[key][k]
|
|
226
|
+
} else if (isStubPhantom(key, context[key][k]) && !isStubPhantom(key, sharedLib[key][k])) {
|
|
227
|
+
// The slot holds a stub phantom, not a value — a real value fills it.
|
|
228
|
+
// Order-independent: a real value already in the slot is never a
|
|
229
|
+
// phantom, so a later library's `''` can never overwrite it.
|
|
230
|
+
context[key][k] = sharedLib[key][k]
|
|
231
|
+
}
|
|
194
232
|
}
|
|
195
233
|
}
|
|
196
234
|
} else if (!(key in context)) {
|
|
@@ -202,7 +240,9 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
202
240
|
/**
|
|
203
241
|
* Merge an array of shared library objects into a context.
|
|
204
242
|
* - designSystem: deep defaults (non-destructive recursive)
|
|
205
|
-
* - other object keys (components, pages, etc.): shallow add missing
|
|
243
|
+
* - other object keys (components, pages, etc.): shallow add missing. A slot
|
|
244
|
+
* holding a STUB PHANTOM counts as missing in the object bags — see
|
|
245
|
+
* `isStubPhantom`.
|
|
206
246
|
* - new top-level keys: copy from library
|
|
207
247
|
*
|
|
208
248
|
* Entries may be a bare library context, or a wrapped `{ library, ignoreList }`
|
package/state.js
CHANGED
|
@@ -201,3 +201,73 @@ export const overwriteState = (state, obj, options = {}) => {
|
|
|
201
201
|
const overwriteFunc = shallow ? overwriteShallow : overwriteDeep
|
|
202
202
|
overwriteFunc(state, obj, STATE_METHODS)
|
|
203
203
|
}
|
|
204
|
+
|
|
205
|
+
// ── Polyglot key ownership ───────────────────────────────────────────────
|
|
206
|
+
//
|
|
207
|
+
// `prepareState` seeds the active language's translation map into the ROOT
|
|
208
|
+
// STATE so a bare `{{ key }}` resolves without the `| polyglot` filter. That
|
|
209
|
+
// seeding shares ONE namespace with every declared state key — the project's
|
|
210
|
+
// `state.js`, an app-level `state`, and every shared library's state — and a
|
|
211
|
+
// library author cannot see a consumer's translations (nor the consumer the
|
|
212
|
+
// library's state keys), so neither side can avoid a collision by review.
|
|
213
|
+
//
|
|
214
|
+
// The runtime holds the precedence instead:
|
|
215
|
+
//
|
|
216
|
+
// project state.js > shared library state.js > translations[lang]
|
|
217
|
+
//
|
|
218
|
+
// Polyglot owns ONLY the keys it seeded itself. `SEEDED_KEYS` records them on
|
|
219
|
+
// the context, non-enumerable so no `for…in`, serializer or JSON.stringify
|
|
220
|
+
// ever sees it, and both the boot seeding and a later `setLang` ask this
|
|
221
|
+
// before they write (RUNTIME-POLYGLOT-SEED-CLOBBERS-LIBRARY-STATE-1: gita
|
|
222
|
+
// booted with `a11yContrast` holding a Georgian panel label instead of
|
|
223
|
+
// `false`, so every a11y gate read truthy on first paint).
|
|
224
|
+
const SEEDED_KEYS = '__polyglotSeededKeys'
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The set of root-state keys polyglot seeded on this context. Created on
|
|
228
|
+
* first use; always a Set, never null, for any object context.
|
|
229
|
+
*/
|
|
230
|
+
export const polyglotSeededKeys = (context) => {
|
|
231
|
+
if (!isObject(context)) return new Set()
|
|
232
|
+
let keys = context[SEEDED_KEYS]
|
|
233
|
+
if (!(keys instanceof Set)) {
|
|
234
|
+
keys = new Set()
|
|
235
|
+
try {
|
|
236
|
+
Object.defineProperty(context, SEEDED_KEYS, {
|
|
237
|
+
value: keys,
|
|
238
|
+
enumerable: false,
|
|
239
|
+
writable: true,
|
|
240
|
+
configurable: true
|
|
241
|
+
})
|
|
242
|
+
} catch (e) {
|
|
243
|
+
// A frozen or trapped context keeps no record. Seeding still runs and
|
|
244
|
+
// still refuses to overwrite a declared key — only the language switch
|
|
245
|
+
// loses the memory of what it seeded, and falls back to "fill what is
|
|
246
|
+
// undefined". Never let bookkeeping break boot.
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return keys
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* May polyglot write `key` into the root state? Only when polyglot seeded it
|
|
254
|
+
* before, or when nothing declares it yet. A key a project, an app or a
|
|
255
|
+
* shared library declares is never polyglot's to overwrite.
|
|
256
|
+
*
|
|
257
|
+
* @param {object} context - the app context carrying the seeded-key record
|
|
258
|
+
* @param {string} key - the translation key about to be written
|
|
259
|
+
* @param {object} [declared] - the state to test the key against
|
|
260
|
+
*/
|
|
261
|
+
export const isPolyglotWritableKey = (context, key, declared) => {
|
|
262
|
+
if (polyglotSeededKeys(context).has(key)) return true
|
|
263
|
+
return !isObject(declared) || declared[key] === undefined
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Record that polyglot seeded `key`, so a later language switch may retranslate
|
|
268
|
+
* it. Returns the key, for use inline.
|
|
269
|
+
*/
|
|
270
|
+
export const markPolyglotSeeded = (context, key) => {
|
|
271
|
+
polyglotSeededKeys(context).add(key)
|
|
272
|
+
return key
|
|
273
|
+
}
|
package/string.js
CHANGED
|
@@ -76,11 +76,15 @@ export function replaceLiteralsWithObjectFields (str, state, options = {}) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
const value = getNestedValue(parentState, key)
|
|
79
|
+
// `String()` on an object/array falls back to `Object.prototype.toString`
|
|
80
|
+
// (each array element joins in as literal "[object Object]"). A `{{ }}`
|
|
81
|
+
// template interpolates a scalar; render nothing rather than that.
|
|
82
|
+
if (value != null && typeof value === 'object') return ''
|
|
79
83
|
return String(value ?? '')
|
|
80
84
|
} else {
|
|
81
85
|
// Check state value first
|
|
82
86
|
const value = getNestedValue(obj, key)
|
|
83
|
-
if (value != null) return String(value)
|
|
87
|
+
if (value != null && typeof value !== 'object') return String(value)
|
|
84
88
|
|
|
85
89
|
// Fall back to polyglot translations for current language
|
|
86
90
|
const poly = element?.context?.polyglot
|