@symbo.ls/utils 3.14.769 → 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 +58 -13
- package/dist/cjs/cdn.js +2 -2
- package/dist/cjs/object.js +17 -17
- 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 -18
- package/dist/esm/state.js +1 -1
- package/dist/esm/string.js +3 -3
- package/object.js +96 -27
- package/package.json +2 -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,10 @@ 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)
|
|
92
118
|
}
|
|
93
119
|
|
|
94
120
|
// The package DIRECTORY on the CDN — `<cdn>/<pkg>@<version>/` — i.e. the
|
|
@@ -107,7 +133,11 @@ export const getCDNDirUrl = (
|
|
|
107
133
|
) => {
|
|
108
134
|
const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh
|
|
109
135
|
const v = stripVersionRangePrefix(version)
|
|
110
|
-
|
|
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)}/`
|
|
111
141
|
}
|
|
112
142
|
|
|
113
143
|
// SMBLS-IMPORTMAP-SKIP — shared with packages/smbls/src/prepare.js's own
|
|
@@ -146,6 +176,20 @@ const MALFORMED_DEP_RE = /[<>…]/
|
|
|
146
176
|
export const isMalformedDependency = (name) =>
|
|
147
177
|
typeof name === 'string' && MALFORMED_DEP_RE.test(name)
|
|
148
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
|
+
|
|
149
193
|
/**
|
|
150
194
|
* Generate an HTML <script type="importmap"> tag from project dependencies.
|
|
151
195
|
*
|
|
@@ -190,7 +234,8 @@ export const getImportMapScript = (
|
|
|
190
234
|
defaultProvider = 'skypack',
|
|
191
235
|
options = {}
|
|
192
236
|
) => {
|
|
193
|
-
const dependencies = data.dependencies
|
|
237
|
+
const dependencies = data.dependencies
|
|
238
|
+
if (!isValidDependencyMap(dependencies)) return ''
|
|
194
239
|
const keys = Object.keys(dependencies)
|
|
195
240
|
if (!keys.length) return ''
|
|
196
241
|
|
package/dist/cjs/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
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
2
|
"imports": ${JSON.stringify(p,null,2)}
|
|
3
|
-
}`;return`${
|
|
3
|
+
}`;return`${x}${j}${D}`};
|
package/dist/cjs/object.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var
|
|
2
|
-
`;for(const
|
|
3
|
-
`;for(const c of
|
|
4
|
-
`:(0,
|
|
5
|
-
`:(0,
|
|
6
|
-
`:n+=`${
|
|
7
|
-
`;n+=`${
|
|
8
|
-
`,"'"])?`\`${
|
|
9
|
-
`}return n+=`${
|
|
10
|
-
`,
|
|
11
|
-
`)){p++;break}p++}n.push([d,p]),
|
|
12
|
-
First 200 chars of source: `+String(e).slice(0,200)),e)}},
|
|
13
|
-
`);try{const
|
|
14
|
-
`),f="{ "+n.map(([c])=>`${JSON.stringify(c)}: ${c}`).join(", ")+" }",
|
|
15
|
-
${
|
|
16
|
-
return ${f}; })`)(t);Object.assign(t,
|
|
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
17
|
`);t[f]=O.window.eval(`(function(__gs__) { ${c}
|
|
18
|
-
return (${
|
|
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};
|
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 r={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,18 +1,18 @@
|
|
|
1
|
-
import{window as
|
|
2
|
-
`;for(const
|
|
3
|
-
`;for(const c of
|
|
4
|
-
`:g(c)&&c!==null?
|
|
5
|
-
`:O(c)?
|
|
6
|
-
`:
|
|
7
|
-
`;
|
|
8
|
-
`,"'"])?`\`${
|
|
9
|
-
`}return
|
|
10
|
-
`,
|
|
11
|
-
`)){a++;break}a++}
|
|
12
|
-
First 200 chars of source: `+String(e).slice(0,200)),e)}},
|
|
13
|
-
`);try{const
|
|
14
|
-
`),f="{ "+
|
|
15
|
-
${
|
|
16
|
-
return ${f}; })`)(t);Object.assign(t,
|
|
17
|
-
`);t[f]
|
|
18
|
-
return (${
|
|
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};
|
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
|
@@ -629,9 +629,9 @@ export const deepDestringifyFunctions = (
|
|
|
629
629
|
? _destringifyFnString(arrProp, `array index ${i} (prop "${prop}")`, opts)
|
|
630
630
|
: arrProp)
|
|
631
631
|
} else if (isObject(arrProp)) {
|
|
632
|
-
const
|
|
633
|
-
if (
|
|
634
|
-
arr.push(
|
|
632
|
+
const tagged = _rehydrateTagged(arrProp)
|
|
633
|
+
if (tagged) {
|
|
634
|
+
arr.push(tagged)
|
|
635
635
|
} else {
|
|
636
636
|
const child = {}
|
|
637
637
|
arr.push(child)
|
|
@@ -642,13 +642,14 @@ export const deepDestringifyFunctions = (
|
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
644
|
} else if (isObject(objProp)) {
|
|
645
|
-
// `{__type:'RegExp',
|
|
646
|
-
// tagged
|
|
647
|
-
// the walk would clone
|
|
648
|
-
// (FRANK-EMIT-REGEXP-SCOPE-VALUE-DIES-TO-EMPTY-OBJECT-1
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
|
652
653
|
continue
|
|
653
654
|
}
|
|
654
655
|
// Preserve any pre-existing container the caller passed in for this
|
|
@@ -672,34 +673,99 @@ export const deepDestringifyFunctions = (
|
|
|
672
673
|
const TYPE_TAG_SET = 'Set'
|
|
673
674
|
const TYPE_TAG_MAP = 'Map'
|
|
674
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
|
+
}
|
|
675
690
|
|
|
676
691
|
/**
|
|
677
|
-
* Rehydrate Set / Map / RegExp tagged forms back into real
|
|
678
|
-
* Pass-through for any other value (including user
|
|
679
|
-
* happen to carry an unrelated `__type` field — only
|
|
680
|
-
*
|
|
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.
|
|
681
713
|
*/
|
|
682
|
-
const _rehydrateTaggedValue = (val) => {
|
|
714
|
+
const _rehydrateTaggedValue = (val, seen) => {
|
|
683
715
|
if (!val || typeof val !== 'object') return val
|
|
684
|
-
|
|
685
|
-
if (val.__type ===
|
|
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()
|
|
686
723
|
if (val.__type === TYPE_TAG_REGEXP && isString(val.source)) {
|
|
687
724
|
// Guard: a corrupt flags string must not take down the whole
|
|
688
725
|
// destringify pass — leave the tagged object as-is instead.
|
|
689
726
|
try { return new RegExp(val.source, isString(val.flags) ? val.flags : '') } catch (e) { return val }
|
|
690
727
|
}
|
|
691
|
-
|
|
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
|
|
692
749
|
}
|
|
693
750
|
|
|
694
|
-
// deepDestringifyFunctions rehydrates
|
|
695
|
-
//
|
|
696
|
-
//
|
|
697
|
-
// Set
|
|
698
|
-
//
|
|
699
|
-
|
|
700
|
-
|
|
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
|
|
701
767
|
const revived = _rehydrateTaggedValue(val)
|
|
702
|
-
return revived
|
|
768
|
+
return revived === val ? null : revived
|
|
703
769
|
}
|
|
704
770
|
|
|
705
771
|
/**
|
|
@@ -708,7 +774,10 @@ const _rehydrateTaggedRegExp = (val) => {
|
|
|
708
774
|
* function, so helpers can reference constants and other helpers naturally.
|
|
709
775
|
*
|
|
710
776
|
* Also rehydrates Set/Map tagged forms (FT-FRANK-1) so `globalScope.X.has(y)`
|
|
711
|
-
* 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.
|
|
712
781
|
*/
|
|
713
782
|
export const destringifyGlobalScope = (gs) => {
|
|
714
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/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
|