@symbo.ls/utils 3.14.786 → 3.14.788
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 +28 -0
- package/dist/cjs/keys.js +1 -1
- package/dist/cjs/metadata.js +2 -2
- package/dist/cjs/polyglotLang.js +1 -1
- package/dist/cjs/string.js +3 -3
- package/dist/esm/keys.js +1 -1
- package/dist/esm/metadata.js +2 -2
- package/dist/esm/polyglotLang.js +1 -1
- package/dist/esm/string.js +3 -3
- package/keys.js +1 -0
- package/metadata.js +40 -0
- package/package.json +2 -2
- package/polyglotLang.js +62 -0
- package/string.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @symbo.ls/utils
|
|
2
2
|
|
|
3
|
+
## 3.14.788
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Server renders run one at a time per process, and a page at /<lang>/… starts in that language.
|
|
8
|
+
|
|
9
|
+
- brender: `render()` (and `renderRoute` / `renderPage`) run one at a time per process; a per-render `timeout` (default 30 s, `0`/`false` turns it off) rejects with `BRENDER_RENDER_TIMEOUT`, puts the render's globals back and lets the next render start.
|
|
10
|
+
- brender + mermaid: before the app starts, the render stores the address's language (the first path segment, when it is one of the project's languages) under polyglot's key, so the fetch seed is recorded in the language the browser asks in; the served page's start-up script stores the page's language. One helper in utils (`polyglotAddressLang`, `polyglotStartupScript`).
|
|
11
|
+
- cli: the publish pre-render passes its route limit to brender's `timeout`; `symbols.json` `brender.timeout` sets each page's render limit for `smbls build` and `smbls brender`.
|
|
12
|
+
|
|
13
|
+
## 3.14.787
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- xma.info report round (FW-XMA-EXCEPTIONS-UPSTREAM-1), its /simplify pass and the follow-ups.
|
|
18
|
+
|
|
19
|
+
- element: optional features (view events, `always` handler chains, plain-row diff, hydration, yielding mount) are feature slots — `create.js` installs all of them, `src/lean.js` none (the smbls embed); one chunked mount driver and one meter per task; the chunked first render costs about a third of what it did (a resumed row goes after the previous row, one `__ref` shape, the budget is read once); `whenConnected`; `onWindowLoad` after load reaches an element built off-document; a null/false row item under `childExtends` builds nothing; building an n-row list no longer scans the parent's keys per row.
|
|
20
|
+
- smbls: the embed is back under its 72 KiB cap and the iife is 2.6 % smaller (terser renames locals after esbuild in the two classic-script builds; maps chained); kits stay lazy in `smbls/core`, fetch is one chunk; live sync loads only when `wantsLiveSync`; a URL-loaded dependency registers in parcel builds.
|
|
21
|
+
- router: the newest navigation wins over one waiting on an async guard; no lazy chunk rides along a resumed route.
|
|
22
|
+
- default-config: accessible Dropdown writes its attributes straight to the nodes, one tab stop per list, an `active` write re-runs only the rows that change, a key-opened menu focuses its item during the reveal; Dialog and Icon clean-ups.
|
|
23
|
+
- styling (scratch, css, css-in-props): one compound-value resolver; CSS colour functions (`oklch()`, `color()`, `color-mix()`, `light-dark()`, `lab()`, `lch()`, `hwb()`) pass through compound values; border props read the scheme only in literal mode.
|
|
24
|
+
- fetch / brender: every server render starts from an empty query cache (seeds carry every request a page makes); the local adapter stays lazy; shared route loop for `smbls build` and `smbls brender`, `smbls brender --strict`.
|
|
25
|
+
- cli: every command that writes to the platform prints its target and needs a typed "production" or `--yes` for production; `smbls deploy --save` saves the provider, `-y/--yes` is consent; `deploy --dry-run` no longer pushes.
|
|
26
|
+
- frank-audit: FA205 reports only factory calls that run at module load.
|
|
27
|
+
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
- @symbo.ls/fetch@3.14.665
|
|
30
|
+
|
|
3
31
|
## 3.14.786
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/cjs/keys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},h=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!i.call(e,o)&&o!==n&&a(e,o,{get:()=>t[o],enumerable:!(s=c(t,o))||s.enumerable});return e};var x=e=>h(a({},"__esModule",{value:!0}),e);var y={};E(y,{DOMQL_EVENTS:()=>g,DOMQ_PROPERTIES:()=>S,ELEMENT_METHOD_OVERRIDE_POINTS:()=>l,METHODS:()=>r,METHODS_EXL:()=>f,PARSED_DOMQ_PROPERTIES:()=>R,PROPS_METHODS:()=>d,STATE_METHODS:()=>p,STATE_PROPERTIES:()=>u,isBuiltinElementMethod:()=>m,isProtectedElementMethod:()=>P});module.exports=x(y);const S=new Set(["attr","style","text","html","content","data","classlist","state","scope","root","deps","extend","extends","$router","routes","children","childExtend","childExtends","childExtendRecursive","childExtendsRecursive","props","if","define","__name","__ref","__hash","__text","key","tag","query","parent","node","variables","on","fetch","component","context","preventContentUpdate","preventContentRecreate"]),R=new Set(["attr","style","text","html","content","data","class","state","scope","children","props","if","key","tag","query","on","context"]),u=["ref","parent","__element","__depends","__ref","__children","root"],p=new Set(["update","parse","clean","create","destroy","add","toggle","remove","apply","set","reset","replace","quietReplace","quietUpdate","applyReplace","applyFunction","keys","values","ref","rootUpdate","parentUpdate","parent","__element","__depends","__ref","__children","root","setByPath","setPathCollection","removeByPath","removePathCollection","getByPath"]),d=new Set(["update","__element"]),r=new Set(["set","reset","update","remove","updateContent","removeContent","lookup","lookdown","lookdownAll","getRef","getPath","setNodeStyles","spotByPath","keys","parse","setProps","parseDeep","variables","if","log","verbose","warn","error","call","nextElement","previousElement","getRootState","getRoot","getRootData","getRootContext","getContext","getQuery","getDB","getChildren","preventContentUpdate","preventContentRecreate"]),m=e=>r.has(e),l=new Set(["log","warn","error","verbose"]),P=e=>r.has(e)&&!l.has(e),f=new Set(["node","context","extends","__element","__ref",...r,...p,...d]),g=new Set(["init","beforeClassAssign","render","renderRouter","attachNode","stateInit","stateCreated","beforeStateUpdate","stateUpdate","beforeUpdate","done","create","complete","frame","update","fetchError","fetchComplete"]);
|
|
1
|
+
"use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},h=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!i.call(e,o)&&o!==n&&a(e,o,{get:()=>t[o],enumerable:!(s=c(t,o))||s.enumerable});return e};var x=e=>h(a({},"__esModule",{value:!0}),e);var y={};E(y,{DOMQL_EVENTS:()=>g,DOMQ_PROPERTIES:()=>S,ELEMENT_METHOD_OVERRIDE_POINTS:()=>l,METHODS:()=>r,METHODS_EXL:()=>f,PARSED_DOMQ_PROPERTIES:()=>R,PROPS_METHODS:()=>d,STATE_METHODS:()=>p,STATE_PROPERTIES:()=>u,isBuiltinElementMethod:()=>m,isProtectedElementMethod:()=>P});module.exports=x(y);const S=new Set(["attr","style","text","html","content","data","classlist","state","scope","root","deps","extend","extends","$router","routes","children","childExtend","childExtends","childExtendRecursive","childExtendsRecursive","props","if","define","__name","__ref","__hash","__text","key","tag","query","parent","node","variables","on","fetch","component","context","preventContentUpdate","preventContentRecreate"]),R=new Set(["attr","style","text","html","content","data","class","state","scope","children","props","if","key","tag","query","on","context"]),u=["ref","parent","__element","__depends","__ref","__children","root"],p=new Set(["update","parse","clean","create","destroy","add","toggle","remove","apply","set","reset","replace","quietReplace","quietUpdate","applyReplace","applyFunction","keys","values","ref","rootUpdate","parentUpdate","parent","__element","__depends","__ref","__children","root","setByPath","setPathCollection","removeByPath","removePathCollection","getByPath"]),d=new Set(["update","__element"]),r=new Set(["set","reset","update","remove","updateContent","removeContent","lookup","lookdown","lookdownAll","whenConnected","getRef","getPath","setNodeStyles","spotByPath","keys","parse","setProps","parseDeep","variables","if","log","verbose","warn","error","call","nextElement","previousElement","getRootState","getRoot","getRootData","getRootContext","getContext","getQuery","getDB","getChildren","preventContentUpdate","preventContentRecreate"]),m=e=>r.has(e),l=new Set(["log","warn","error","verbose"]),P=e=>r.has(e)&&!l.has(e),f=new Set(["node","context","extends","__element","__ref",...r,...p,...d]),g=new Set(["init","beforeClassAssign","render","renderRouter","attachNode","stateInit","stateCreated","beforeStateUpdate","stateUpdate","beforeUpdate","done","create","complete","frame","update","fetchError","fetchComplete"]);
|
package/dist/cjs/metadata.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)},
|
|
1
|
+
"use strict";var S=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var _=(t,r)=>{for(var e in r)S(t,e,{get:r[e],enumerable:!0})},q=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of D(r))!F.call(t,s)&&s!==e&&S(t,s,{get:()=>r[s],enumerable:!(n=W(r,s))||n.enumerable});return t};var C=t=>q(S({},"__esModule",{value:!0}),t);var k={};_(k,{BRENDER_REGISTRY_BLOCK:()=>P,alternateLinkKey:()=>R,brenderRegistryBlock:()=>B,escapeHtml:()=>p,faviconLinkKey:()=>K,fileEntryUrl:()=>N,generateHeadArrayTags:()=>E,generateMetaTags:()=>I,getPageMetadata:()=>Z,hashContent:()=>j,jsonForScript:()=>x,readJsonDataBlock:()=>U,resolveFileReferences:()=>T});module.exports=C(k);var m=require("./types.js"),L=require("./function.js");const p=t=>{if(t==null)return"";const r={"&":"&","<":"<",">":">",'"':""","'":"'"};return t.toString().replace(/[&<>"']/g,e=>r[e])},x=t=>JSON.stringify(t).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),U=(t,r,{remove:e=!1,warn:n}={})=>{if(!t||typeof t.querySelector!="function")return null;let s=null;try{s=t.querySelector(r)}catch{return null}if(!s)return null;e&&s.parentNode&&s.parentNode.removeChild(s);let o;try{o=JSON.parse(s.textContent||"")}catch(l){n&&n(l)}return{value:o,block:s}},P='script[type="application/json"][data-brender="registry"]',B=t=>'<script type="application/json" data-brender="registry">'+x(t)+"<\/script>",J=t=>Object.entries(t||{}).filter(([r,e])=>e!==void 0).map(([r,e])=>`${r}="${p(e)}"`).join(" "),j=t=>{let r=5381;const e=String(t);for(let n=0;n<e.length;n++)r=(r*33^e.charCodeAt(n))>>>0;return r.toString(36)},H=new Set(["jsonLd","styles","scripts"]),E=t=>{const r=[];if(Array.isArray(t.jsonLd))for(const e of t.jsonLd){if(e==null)continue;const n=typeof e=="string"?e:JSON.stringify(e),s=String(n).replace(/<\/script/gi,"<\\/script");r.push(`<script type="application/ld+json" data-smbls-jsonld="${j(n)}">${s}<\/script>`)}if(Array.isArray(t.styles))for(const e of t.styles){if(e==null||!String(e).trim())continue;const n=String(e).replace(/<\/style/gi,"<\\/style");r.push(`<style data-smbls-style="${j(n)}">${n}</style>`)}if(Array.isArray(t.scripts))for(const e of t.scripts){if(!e)continue;const n=typeof e=="string",s=n?e:e.src;if(!s&&!e.body)continue;const o=[];s&&o.push(`src="${p(s)}"`),n||(e.type&&o.push(`type="${p(e.type)}"`),e.async&&o.push("async"),e.defer&&o.push("defer"),e.integrity&&o.push(`integrity="${p(e.integrity)}"`),e.crossorigin&&o.push(`crossorigin="${p(e.crossorigin)}"`),e.referrerpolicy&&o.push(`referrerpolicy="${p(e.referrerpolicy)}"`),e.nomodule&&o.push("nomodule"));const l=` data-smbls-script="${p(s||j(e.body||""))}"`;if(!n&&e.body){const d=String(e.body).replace(/<\/script/gi,"<\\/script");r.push(`<script ${o.join(" ")}${l}>${d}<\/script>`)}else r.push(`<script ${o.join(" ")}${l}><\/script>`)}return r},R=t=>`${t.hreflang||""}|${t.href||""}`,K=t=>(0,m.isObject)(t)?j(JSON.stringify(t)):String(t),Y=(t,r,e)=>t==="favicons"?Array.isArray(r)&&(typeof e=="string"||(0,m.isObject)(e))?` data-smbls-favicon="${p(K(e))}"`:"":(t==="icon"||t==="favicon")&&typeof r=="string"?` data-smbls-single-icon="${p(r)}"`:"",G=t=>(0,m.isObject)(t)?` data-smbls-alternate="${p(R(t))}"`:"",I=(t,r)=>{r||(t={...t,robots:"noindex"});const e=Object.entries(t).reduce((n,[s,o])=>{if(!o&&o!==0&&o!==!1||H.has(s))return n;if(s==="title")return n.push(`<title>${p(o)}</title>`),n;if(s==="canonical")return n.push(`<link rel="canonical" href="${p(o)}">`),n;if(s==="manifest")return n.push(`<link rel="manifest" href="${p(o)}">`),n;if(s==="favicon"||s==="favicons"||s==="icon"||s==="icons")return(Array.isArray(o)?o:[o]).forEach(c=>{const u=Y(s,o,c);if(typeof c=="string")n.push(`<link rel="icon" href="${p(c)}"${u}>`);else if(typeof c=="object"){const i=J(c);/rel=/.test(i)?n.push(`<link ${i}${u}>`):n.push(`<link rel="icon" ${i}${u}>`)}}),n;if(s==="alternate")return(Array.isArray(o)?o:[o]).forEach(c=>{if(c&&typeof c=="object"){const u=Object.entries(c).filter(([i,g])=>g!==void 0).map(([i,g])=>`${i}="${p(g)}"`).join(" ");n.push(`<link rel="alternate" ${u}${G(c)}>`)}}),n;const l=(f,c,u="name")=>{if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`<meta ${u}="${p(f)}" content="${p(c)}">`);else if(Array.isArray(c))c.forEach(i=>{if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")n.push(`<meta ${u}="${p(f)}" content="${p(i)}">`);else if(typeof i=="object"){const g=Object.entries(i).filter(([y,$])=>$!==void 0).map(([y,$])=>`${y}="${p($)}"`).join(" ");n.push(`<meta ${g}>`)}});else if(typeof c=="object"){const i=Object.entries(c).filter(([g,y])=>y!==void 0).map(([g,y])=>`${g}="${p(y)}"`).join(" ");n.push(`<meta ${i}>`)}};if(s.startsWith("http-equiv:")){const f=s.replace("http-equiv:","");return l(f,o,"http-equiv"),n}if(s.startsWith("itemprop:")){const f=s.replace("itemprop:","");return l(f,o,"itemprop"),n}const h=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(f=>s.startsWith(f));if(h){const f=s.replace(h,"");return l(`${h.replace(":","")}:${f}`,o,h==="twitter:"||h==="DC:"||h==="DCTERMS:"?"name":"property"),n}if(s.startsWith("apple:")||s.startsWith("msapplication:")){const f=s.startsWith("apple:")?"apple-":"msapplication-",c=s.replace(/^apple:|^msapplication:/,"");return l(`${f}${c}`,o,"name"),n}return l(s,o),n},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return e.push(...E(t)),e.join(`
|
|
2
|
+
`)},z=t=>typeof t=="string"&&t.length>0&&!t.startsWith("/")&&!t.startsWith("http"),A=t=>typeof t=="string"&&t.length>0,N=t=>{if(!t||typeof t!="object")return null;if(A(t.src))return t.src;const r=t.content;return!r||typeof r!="object"?null:A(r.src)?r.src:A(r.storageUrl)?r.storageUrl:null};function T(t,r){if(!r||typeof r!="object")return t;const e=s=>!z(s)||!Object.prototype.hasOwnProperty.call(r,s)?s:N(r[s])||s,n={...t};for(const[s,o]of Object.entries(n))typeof o=="string"?n[s]=e(o):Array.isArray(o)&&(n[s]=o.map(l=>typeof l=="string"?e(l):l));return n}function O(t,r){if(!t||!r)return;const e=r.split(".");let n=t;for(const s of e){if(n==null||typeof n!="object")return;n=n[s]}return n}function Q(t,r){const e=O(t,r);if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e=="string"&&!(0,L.isStringFunction)(e))return e}function X(t,r,e){const s=(r.config||r.settings||{}).polyglot||r.polyglot,o=e?.lang||s?.defaultLang||"en",d=(s?.translations||{})[o]||{},h=[e?.state,r.state].filter(u=>u&&typeof u=="object"),f=u=>{for(const i of h){const g=Q(i,u);if(g!==void 0)return g}},c={...t};for(const[u,i]of Object.entries(c))typeof i!="string"||!i.includes("{{")||(c[u]=i.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(g,y,$)=>{const a=y.trim();if($==="polyglot")return d[a]??O(d,a)??g;if($==="getLocalStateLang")return f(a+o)??g;const b=f(a);return b!==void 0?b:d[a]??O(d,a)??g}));return c}function w(t){if(!(0,m.isObject)(t))return{};const r={...t};for(const[e,n]of Object.entries(r))if(typeof n=="function"){const s=n.toString(),o=s.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[e]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const l=s.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(l){r[e]=`{{ ${l[1]} | polyglot }}`;continue}const d=s.match(/s\.(\w+(?:\.\w+)+)/);if(d){r[e]=`{{ ${d[1]} }}`;continue}delete r[e]}else if(typeof n=="string"){const s=n.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(s){r[e]=`{{ ${s[1]} | getLocalStateLang }}`;continue}const o=n.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[e]=`{{ ${o[1]} | polyglot }}`;continue}if(n.includes("=>")&&n.includes("s.")){const l=n.match(/s\.(\w+(?:\.\w+)+)/);if(l){r[e]=`{{ ${l[1]} }}`;continue}}(0,L.isStringFunction)(n)&&delete r[e]}return r}function Z(t,r,e,{isProduction:n=!1,channel:s="production"}={}){const o=t.pages?.[r],l=(0,m.isObject)(o?.state)&&o?.state,d=o?.metadata||o?.helmet||l||{},h=w(d),f=new Set(Object.keys(h)),c=t.app?.metadata||{},u=w(c);let i={};if(t.integrations?.seo?i={...t.integrations.seo,...u,...h}:Object.keys(u).length?i={...u,...h}:i={...h},!i.title){const a=t.name||t.key;a?n?i.title=a:s==="development"?i.title=`${a} / dev:symbo.ls`:s==="staging"?i.title=`${a} / staging:symbo.ls`:i.title=`${a} / symbo.ls`:i.title="Symbols demo"}i=X(i,t,e),i.title&&(f.has("title")||!i["og:title"])&&(f.has("og:title")||(i["og:title"]=i.title)),i.description&&(f.has("description")||!i["og:description"])&&(f.has("og:description")||(i["og:description"]=i.description)),i.title&&!i["twitter:title"]&&(i["twitter:title"]=i.title),i.description&&!i["twitter:description"]&&(i["twitter:description"]=i.description);const g=f.has("og:url")?i["og:url"]:f.has("url")?i.url:void 0,y=e?.actualPathname||r;if(g)i["og:url"]=g;else if(i["og:url"]||i.url){const a=(i["og:url"]||i.url||"").replace(/\/$/,"");if(a&&y&&y!=="/"){const b=y.startsWith("/")?y:"/"+y;i["og:url"]=a+b}}i=T(i,t.files);const $=t.name||t.app?.metadata?.title||t.app?.name||"";for(const[a,b]of Object.entries(i))if(typeof b=="string"&&b.includes("{{")){const M=b.replace(/\{\{[^}]*\}\}/g,"").trim();M?i[a]=M:a==="title"?i[a]=$:delete i[a]}return i}
|
package/dist/cjs/polyglotLang.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var l=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!p.call(t,n)&&n!==r&&f(t,n,{get:()=>e[n],enumerable:!(s=y(e,n))||s.enumerable});return t};var N=t=>x(f({},"__esModule",{value:!0}),t);var m={};l(m,{POLYGLOT_LANG_STORAGE_KEY:()=>u,polyglotAddressLang:()=>L,polyglotFallbackLang:()=>S,polyglotLangStorageKey:()=>$,polyglotStartupScript:()=>d});module.exports=N(m);const u="smbls_lang",$=t=>t&&t.storageLangKey||u,S=(t,e)=>t||e&&e.defaultLang||"en",L=(t,e)=>{if(!e)return null;const r=Array.isArray(e.languages)&&e.languages.length?e.languages:Object.keys(e.translations||{}),s=/^\/([^/?#]+)/.exec(String(t||""));if(!s)return null;const n=s[1].toLowerCase();for(const a of r)if(typeof a=="string"&&a.toLowerCase()===n)return a;return null},d=({polyglot:t,translations:e,lang:r,pathname:s,attrs:n=""}={})=>{if(!e||typeof e!="object")return"";const a=t&&t.storagePrefix||"",c=t&&t.storageLangKey||"",g=[];for(const i in e){const o=e[i];o&&typeof o=="object"&&g.push(`localStorage.setItem(${JSON.stringify(a+i)},${JSON.stringify(JSON.stringify(o))})`)}if(c){const i=r||L(s,t)||S(void 0,t);g.push(`if(!localStorage.getItem(${JSON.stringify(c)}))localStorage.setItem(${JSON.stringify(c)},${JSON.stringify(i)})`)}return g.length?`<script${n}>try{${g.join(";")}}catch(e){}<\/script>`:""};
|
package/dist/cjs/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var
|
|
2
|
-
`);let s=-1,c=-1,h=-1,p=-1;const
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),
|
|
1
|
+
"use strict";var w=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var t in n)w(e,t,{get:n[t],enumerable:!0})},O=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of j(n))!R.call(e,c)&&c!==t&&w(e,c,{get:()=>n[c],enumerable:!(s=L(n,c))||s.enumerable});return e};var $=e=>O(w({},"__esModule",{value:!0}),e);var Z={};N(Z,{customDecodeURIComponent:()=>W,customEncodeURIComponent:()=>M,decodeNewlines:()=>q,encodeNewlines:()=>P,escapeRegExp:()=>E,findKeyPosition:()=>V,lowercaseFirstLetter:()=>U,replaceLiteralsWithObjectFields:()=>v,replaceOctalEscapeSequences:()=>K,stringIncludesAny:()=>I,trimStringFromSymbols:()=>k});module.exports=$(Z);const E=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),I=(e,n)=>{for(const t of n)if(e.includes(t))return!0;return!1},k=(e,n)=>{const t=new RegExp(`[${n.join("\\")}]`,"g");return e.replace(t,"")},F={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},m=(e,n)=>n.split(".").reduce((t,s)=>t?.[s],e),T=(e,n)=>{if(!e||!e.__ref)return!0;let t=e;for(;t;){if(t.allowRuntimeTemplates===!0)return!0;const s=t.__ref&&t.__ref.__authoredTemplates;if(s&&s.has(n))return!0;t=t.parent}return!1};function v(e,n,t={}){const{bracketsLength:s=2,authored:c=!1}=t,h=s===3?"{{{":"{{";if(!e.includes(h)||c!==!0&&!T(this,e))return e;const p=F[s],g=n||this.state||{},l=this;return e.replace(p,(x,r,b,f)=>{const i=b.trim();if(f){const a=l?.context,o=a?.functions?.[f]||a?.utils?.[f]||a?.methods?.[f]||a?.snippets?.[f]||l?.[f];if(o&&typeof o=="function")try{return String(o.call(l,i)??"")}catch{return""}return""}if(r){const a=(r.match(/\.\.\//g)||[]).length;let o=g;for(let u=0;u<a;u++){if(!o||!o.parent)return"";o=o.parent}if(i==="parent")return String(o.value??"");const d=m(o,i);return d!=null&&typeof d=="object"?"":String(d??"")}else{const a=m(g,i);if(a!=null&&typeof a!="object")return String(a);const o=l?.context?.polyglot;if(o?.translations){const d=g?.root?.lang||g?.lang||l?.context?.state?.lang||o.defaultLang||"en",u=o.translations[d];if(u){const S=m(u,i);if(S!=null&&typeof S!="object")return String(S);for(const A in u){const y=u[A];if(y&&typeof y=="object"&&!Array.isArray(y)){const _=m(y,i);if(_!=null&&typeof _!="object")return String(_)}}}const C=m(o.translations,i);if(C!=null&&typeof C!="object")return String(C)}return""}})}const U=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,V=(e,n)=>{const t=e.split(`
|
|
2
|
+
`);let s=-1,c=-1,h=-1,p=-1;const g=new RegExp(`\\b${n}\\b\\s*:\\s*`);let l=0,x=!1;for(let r=0;r<t.length;r++)if(g.test(t[r])&&!x){if(x=!0,s=r+1,h=t[r].indexOf(n)+1,t[r].includes("{}")){c=s,p=t[r].indexOf("{}")+3;break}const b=t[r].slice(h+n.length);if(b.includes("{")||b.includes("["))l=1;else{c=r+1,p=t[r].length+1;break}}else if(x&&(l+=(t[r].match(/{/g)||[]).length,l+=(t[r].match(/\[/g)||[]).length,l-=(t[r].match(/}/g)||[]).length,l-=(t[r].match(/]/g)||[]).length,l===0)){c=r+1,p=t[r].lastIndexOf("}")!==-1?t[r].lastIndexOf("}")+2:t[r].length+1;break}return{startColumn:h,endColumn:p,startLineNumber:s,endLineNumber:c}},D=/\\([0-7]{1,3})/g,K=e=>e.replace(D,(n,t)=>String.fromCharCode(parseInt(t,8))),P=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),q=e=>e.replace(/\/\/\/\/\/n/g,`
|
|
3
|
+
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),z=/[^a-zA-Z0-9\s]/g,M=e=>e.replace(z,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase()),W=e=>e.replace(/%[0-9A-Fa-f]{2}/g,n=>String.fromCharCode(parseInt(n.slice(1),16)));
|
package/dist/esm/keys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const a=new Set(["attr","style","text","html","content","data","classlist","state","scope","root","deps","extend","extends","$router","routes","children","childExtend","childExtends","childExtendRecursive","childExtendsRecursive","props","if","define","__name","__ref","__hash","__text","key","tag","query","parent","node","variables","on","fetch","component","context","preventContentUpdate","preventContentRecreate"]),s=new Set(["attr","style","text","html","content","data","class","state","scope","children","props","if","key","tag","query","on","context"]),p=["ref","parent","__element","__depends","__ref","__children","root"],o=new Set(["update","parse","clean","create","destroy","add","toggle","remove","apply","set","reset","replace","quietReplace","quietUpdate","applyReplace","applyFunction","keys","values","ref","rootUpdate","parentUpdate","parent","__element","__depends","__ref","__children","root","setByPath","setPathCollection","removeByPath","removePathCollection","getByPath"]),n=new Set(["update","__element"]),t=new Set(["set","reset","update","remove","updateContent","removeContent","lookup","lookdown","lookdownAll","getRef","getPath","setNodeStyles","spotByPath","keys","parse","setProps","parseDeep","variables","if","log","verbose","warn","error","call","nextElement","previousElement","getRootState","getRoot","getRootData","getRootContext","getContext","getQuery","getDB","getChildren","preventContentUpdate","preventContentRecreate"]),d=e=>t.has(e),r=new Set(["log","warn","error","verbose"]),l=e=>t.has(e)&&!r.has(e),c=new Set(["node","context","extends","__element","__ref",...t,...o,...n]),_=new Set(["init","beforeClassAssign","render","renderRouter","attachNode","stateInit","stateCreated","beforeStateUpdate","stateUpdate","beforeUpdate","done","create","complete","frame","update","fetchError","fetchComplete"]);export{_ as DOMQL_EVENTS,a as DOMQ_PROPERTIES,r as ELEMENT_METHOD_OVERRIDE_POINTS,t as METHODS,c as METHODS_EXL,s as PARSED_DOMQ_PROPERTIES,n as PROPS_METHODS,o as STATE_METHODS,p as STATE_PROPERTIES,d as isBuiltinElementMethod,l as isProtectedElementMethod};
|
|
1
|
+
const a=new Set(["attr","style","text","html","content","data","classlist","state","scope","root","deps","extend","extends","$router","routes","children","childExtend","childExtends","childExtendRecursive","childExtendsRecursive","props","if","define","__name","__ref","__hash","__text","key","tag","query","parent","node","variables","on","fetch","component","context","preventContentUpdate","preventContentRecreate"]),s=new Set(["attr","style","text","html","content","data","class","state","scope","children","props","if","key","tag","query","on","context"]),p=["ref","parent","__element","__depends","__ref","__children","root"],o=new Set(["update","parse","clean","create","destroy","add","toggle","remove","apply","set","reset","replace","quietReplace","quietUpdate","applyReplace","applyFunction","keys","values","ref","rootUpdate","parentUpdate","parent","__element","__depends","__ref","__children","root","setByPath","setPathCollection","removeByPath","removePathCollection","getByPath"]),n=new Set(["update","__element"]),t=new Set(["set","reset","update","remove","updateContent","removeContent","lookup","lookdown","lookdownAll","whenConnected","getRef","getPath","setNodeStyles","spotByPath","keys","parse","setProps","parseDeep","variables","if","log","verbose","warn","error","call","nextElement","previousElement","getRootState","getRoot","getRootData","getRootContext","getContext","getQuery","getDB","getChildren","preventContentUpdate","preventContentRecreate"]),d=e=>t.has(e),r=new Set(["log","warn","error","verbose"]),l=e=>t.has(e)&&!r.has(e),c=new Set(["node","context","extends","__element","__ref",...t,...o,...n]),_=new Set(["init","beforeClassAssign","render","renderRouter","attachNode","stateInit","stateCreated","beforeStateUpdate","stateUpdate","beforeUpdate","done","create","complete","frame","update","fetchError","fetchComplete"]);export{_ as DOMQL_EVENTS,a as DOMQ_PROPERTIES,r as ELEMENT_METHOD_OVERRIDE_POINTS,t as METHODS,c as METHODS_EXL,s as PARSED_DOMQ_PROPERTIES,n as PROPS_METHODS,o as STATE_METHODS,p as STATE_PROPERTIES,d as isBuiltinElementMethod,l as isProtectedElementMethod};
|
package/dist/esm/metadata.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isObject as
|
|
2
|
-
`)},
|
|
1
|
+
import{isObject as m}from"./types.js";import{isStringFunction as L}from"./function.js";const p=t=>{if(t==null)return"";const i={"&":"&","<":"<",">":">",'"':""","'":"'"};return t.toString().replace(/[&<>"']/g,e=>i[e])},w=t=>JSON.stringify(t).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),B=(t,i,{remove:e=!1,warn:r}={})=>{if(!t||typeof t.querySelector!="function")return null;let s=null;try{s=t.querySelector(i)}catch{return null}if(!s)return null;e&&s.parentNode&&s.parentNode.removeChild(s);let o;try{o=JSON.parse(s.textContent||"")}catch(l){r&&r(l)}return{value:o,block:s}},J='script[type="application/json"][data-brender="registry"]',H=t=>'<script type="application/json" data-brender="registry">'+w(t)+"<\/script>",x=t=>Object.entries(t||{}).filter(([i,e])=>e!==void 0).map(([i,e])=>`${i}="${p(e)}"`).join(" "),j=t=>{let i=5381;const e=String(t);for(let r=0;r<e.length;r++)i=(i*33^e.charCodeAt(r))>>>0;return i.toString(36)},E=new Set(["jsonLd","styles","scripts"]),R=t=>{const i=[];if(Array.isArray(t.jsonLd))for(const e of t.jsonLd){if(e==null)continue;const r=typeof e=="string"?e:JSON.stringify(e),s=String(r).replace(/<\/script/gi,"<\\/script");i.push(`<script type="application/ld+json" data-smbls-jsonld="${j(r)}">${s}<\/script>`)}if(Array.isArray(t.styles))for(const e of t.styles){if(e==null||!String(e).trim())continue;const r=String(e).replace(/<\/style/gi,"<\\/style");i.push(`<style data-smbls-style="${j(r)}">${r}</style>`)}if(Array.isArray(t.scripts))for(const e of t.scripts){if(!e)continue;const r=typeof e=="string",s=r?e:e.src;if(!s&&!e.body)continue;const o=[];s&&o.push(`src="${p(s)}"`),r||(e.type&&o.push(`type="${p(e.type)}"`),e.async&&o.push("async"),e.defer&&o.push("defer"),e.integrity&&o.push(`integrity="${p(e.integrity)}"`),e.crossorigin&&o.push(`crossorigin="${p(e.crossorigin)}"`),e.referrerpolicy&&o.push(`referrerpolicy="${p(e.referrerpolicy)}"`),e.nomodule&&o.push("nomodule"));const l=` data-smbls-script="${p(s||j(e.body||""))}"`;if(!r&&e.body){const d=String(e.body).replace(/<\/script/gi,"<\\/script");i.push(`<script ${o.join(" ")}${l}>${d}<\/script>`)}else i.push(`<script ${o.join(" ")}${l}><\/script>`)}return i},K=t=>`${t.hreflang||""}|${t.href||""}`,N=t=>m(t)?j(JSON.stringify(t)):String(t),T=(t,i,e)=>t==="favicons"?Array.isArray(i)&&(typeof e=="string"||m(e))?` data-smbls-favicon="${p(N(e))}"`:"":(t==="icon"||t==="favicon")&&typeof i=="string"?` data-smbls-single-icon="${p(i)}"`:"",W=t=>m(t)?` data-smbls-alternate="${p(K(t))}"`:"",Y=(t,i)=>{i||(t={...t,robots:"noindex"});const e=Object.entries(t).reduce((r,[s,o])=>{if(!o&&o!==0&&o!==!1||E.has(s))return r;if(s==="title")return r.push(`<title>${p(o)}</title>`),r;if(s==="canonical")return r.push(`<link rel="canonical" href="${p(o)}">`),r;if(s==="manifest")return r.push(`<link rel="manifest" href="${p(o)}">`),r;if(s==="favicon"||s==="favicons"||s==="icon"||s==="icons")return(Array.isArray(o)?o:[o]).forEach(c=>{const u=T(s,o,c);if(typeof c=="string")r.push(`<link rel="icon" href="${p(c)}"${u}>`);else if(typeof c=="object"){const n=x(c);/rel=/.test(n)?r.push(`<link ${n}${u}>`):r.push(`<link rel="icon" ${n}${u}>`)}}),r;if(s==="alternate")return(Array.isArray(o)?o:[o]).forEach(c=>{if(c&&typeof c=="object"){const u=Object.entries(c).filter(([n,g])=>g!==void 0).map(([n,g])=>`${n}="${p(g)}"`).join(" ");r.push(`<link rel="alternate" ${u}${W(c)}>`)}}),r;const l=(f,c,u="name")=>{if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")r.push(`<meta ${u}="${p(f)}" content="${p(c)}">`);else if(Array.isArray(c))c.forEach(n=>{if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")r.push(`<meta ${u}="${p(f)}" content="${p(n)}">`);else if(typeof n=="object"){const g=Object.entries(n).filter(([y,$])=>$!==void 0).map(([y,$])=>`${y}="${p($)}"`).join(" ");r.push(`<meta ${g}>`)}});else if(typeof c=="object"){const n=Object.entries(c).filter(([g,y])=>y!==void 0).map(([g,y])=>`${g}="${p(y)}"`).join(" ");r.push(`<meta ${n}>`)}};if(s.startsWith("http-equiv:")){const f=s.replace("http-equiv:","");return l(f,o,"http-equiv"),r}if(s.startsWith("itemprop:")){const f=s.replace("itemprop:","");return l(f,o,"itemprop"),r}const h=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(f=>s.startsWith(f));if(h){const f=s.replace(h,"");return l(`${h.replace(":","")}:${f}`,o,h==="twitter:"||h==="DC:"||h==="DCTERMS:"?"name":"property"),r}if(s.startsWith("apple:")||s.startsWith("msapplication:")){const f=s.startsWith("apple:")?"apple-":"msapplication-",c=s.replace(/^apple:|^msapplication:/,"");return l(`${f}${c}`,o,"name"),r}return l(s,o),r},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return e.push(...R(t)),e.join(`
|
|
2
|
+
`)},D=t=>typeof t=="string"&&t.length>0&&!t.startsWith("/")&&!t.startsWith("http"),S=t=>typeof t=="string"&&t.length>0,F=t=>{if(!t||typeof t!="object")return null;if(S(t.src))return t.src;const i=t.content;return!i||typeof i!="object"?null:S(i.src)?i.src:S(i.storageUrl)?i.storageUrl:null};function _(t,i){if(!i||typeof i!="object")return t;const e=s=>!D(s)||!Object.prototype.hasOwnProperty.call(i,s)?s:F(i[s])||s,r={...t};for(const[s,o]of Object.entries(r))typeof o=="string"?r[s]=e(o):Array.isArray(o)&&(r[s]=o.map(l=>typeof l=="string"?e(l):l));return r}function A(t,i){if(!t||!i)return;const e=i.split(".");let r=t;for(const s of e){if(r==null||typeof r!="object")return;r=r[s]}return r}function q(t,i){const e=A(t,i);if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e=="string"&&!L(e))return e}function C(t,i,e){const s=(i.config||i.settings||{}).polyglot||i.polyglot,o=e?.lang||s?.defaultLang||"en",d=(s?.translations||{})[o]||{},h=[e?.state,i.state].filter(u=>u&&typeof u=="object"),f=u=>{for(const n of h){const g=q(n,u);if(g!==void 0)return g}},c={...t};for(const[u,n]of Object.entries(c))typeof n!="string"||!n.includes("{{")||(c[u]=n.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(g,y,$)=>{const a=y.trim();if($==="polyglot")return d[a]??A(d,a)??g;if($==="getLocalStateLang")return f(a+o)??g;const b=f(a);return b!==void 0?b:d[a]??A(d,a)??g}));return c}function M(t){if(!m(t))return{};const i={...t};for(const[e,r]of Object.entries(i))if(typeof r=="function"){const s=r.toString(),o=s.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){i[e]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const l=s.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(l){i[e]=`{{ ${l[1]} | polyglot }}`;continue}const d=s.match(/s\.(\w+(?:\.\w+)+)/);if(d){i[e]=`{{ ${d[1]} }}`;continue}delete i[e]}else if(typeof r=="string"){const s=r.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(s){i[e]=`{{ ${s[1]} | getLocalStateLang }}`;continue}const o=r.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){i[e]=`{{ ${o[1]} | polyglot }}`;continue}if(r.includes("=>")&&r.includes("s.")){const l=r.match(/s\.(\w+(?:\.\w+)+)/);if(l){i[e]=`{{ ${l[1]} }}`;continue}}L(r)&&delete i[e]}return i}function G(t,i,e,{isProduction:r=!1,channel:s="production"}={}){const o=t.pages?.[i],l=m(o?.state)&&o?.state,d=o?.metadata||o?.helmet||l||{},h=M(d),f=new Set(Object.keys(h)),c=t.app?.metadata||{},u=M(c);let n={};if(t.integrations?.seo?n={...t.integrations.seo,...u,...h}:Object.keys(u).length?n={...u,...h}:n={...h},!n.title){const a=t.name||t.key;a?r?n.title=a:s==="development"?n.title=`${a} / dev:symbo.ls`:s==="staging"?n.title=`${a} / staging:symbo.ls`:n.title=`${a} / symbo.ls`:n.title="Symbols demo"}n=C(n,t,e),n.title&&(f.has("title")||!n["og:title"])&&(f.has("og:title")||(n["og:title"]=n.title)),n.description&&(f.has("description")||!n["og:description"])&&(f.has("og:description")||(n["og:description"]=n.description)),n.title&&!n["twitter:title"]&&(n["twitter:title"]=n.title),n.description&&!n["twitter:description"]&&(n["twitter:description"]=n.description);const g=f.has("og:url")?n["og:url"]:f.has("url")?n.url:void 0,y=e?.actualPathname||i;if(g)n["og:url"]=g;else if(n["og:url"]||n.url){const a=(n["og:url"]||n.url||"").replace(/\/$/,"");if(a&&y&&y!=="/"){const b=y.startsWith("/")?y:"/"+y;n["og:url"]=a+b}}n=_(n,t.files);const $=t.name||t.app?.metadata?.title||t.app?.name||"";for(const[a,b]of Object.entries(n))if(typeof b=="string"&&b.includes("{{")){const O=b.replace(/\{\{[^}]*\}\}/g,"").trim();O?n[a]=O:a==="title"?n[a]=$:delete n[a]}return n}export{J as BRENDER_REGISTRY_BLOCK,K as alternateLinkKey,H as brenderRegistryBlock,p as escapeHtml,N as faviconLinkKey,F as fileEntryUrl,R as generateHeadArrayTags,Y as generateMetaTags,G as getPageMetadata,j as hashContent,w as jsonForScript,B as readJsonDataBlock,_ as resolveFileReferences};
|
package/dist/esm/polyglotLang.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const f="smbls_lang",L=e=>e&&e.storageLangKey||f,u=(e,t)=>e||t&&t.defaultLang||"en",S=(e,t)=>{if(!t)return null;const g=Array.isArray(t.languages)&&t.languages.length?t.languages:Object.keys(t.translations||{}),r=/^\/([^/?#]+)/.exec(String(e||""));if(!r)return null;const i=r[1].toLowerCase();for(const n of g)if(typeof n=="string"&&n.toLowerCase()===i)return n;return null},y=({polyglot:e,translations:t,lang:g,pathname:r,attrs:i=""}={})=>{if(!t||typeof t!="object")return"";const n=e&&e.storagePrefix||"",c=e&&e.storageLangKey||"",s=[];for(const a in t){const o=t[a];o&&typeof o=="object"&&s.push(`localStorage.setItem(${JSON.stringify(n+a)},${JSON.stringify(JSON.stringify(o))})`)}if(c){const a=g||S(r,e)||u(void 0,e);s.push(`if(!localStorage.getItem(${JSON.stringify(c)}))localStorage.setItem(${JSON.stringify(c)},${JSON.stringify(a)})`)}return s.length?`<script${i}>try{${s.join(";")}}catch(e){}<\/script>`:""};export{f as POLYGLOT_LANG_STORAGE_KEY,S as polyglotAddressLang,u as polyglotFallbackLang,L as polyglotLangStorageKey,y as polyglotStartupScript};
|
package/dist/esm/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const O=(
|
|
2
|
-
`);let c=-1,u=-1,h=-1,p=-1;const
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),
|
|
1
|
+
const N=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),O=(e,r)=>{for(const t of r)if(e.includes(t))return!0;return!1},$=(e,r)=>{const t=new RegExp(`[${r.join("\\")}]`,"g");return e.replace(t,"")},A={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},m=(e,r)=>r.split(".").reduce((t,c)=>t?.[c],e),L=(e,r)=>{if(!e||!e.__ref)return!0;let t=e;for(;t;){if(t.allowRuntimeTemplates===!0)return!0;const c=t.__ref&&t.__ref.__authoredTemplates;if(c&&c.has(r))return!0;t=t.parent}return!1};function E(e,r,t={}){const{bracketsLength:c=2,authored:u=!1}=t,h=c===3?"{{{":"{{";if(!e.includes(h)||u!==!0&&!L(this,e))return e;const p=A[c],g=r||this.state||{},s=this;return e.replace(p,(x,n,b,f)=>{const a=b.trim();if(f){const l=s?.context,o=l?.functions?.[f]||l?.utils?.[f]||l?.methods?.[f]||l?.snippets?.[f]||s?.[f];if(o&&typeof o=="function")try{return String(o.call(s,a)??"")}catch{return""}return""}if(n){const l=(n.match(/\.\.\//g)||[]).length;let o=g;for(let i=0;i<l;i++){if(!o||!o.parent)return"";o=o.parent}if(a==="parent")return String(o.value??"");const d=m(o,a);return d!=null&&typeof d=="object"?"":String(d??"")}else{const l=m(g,a);if(l!=null&&typeof l!="object")return String(l);const o=s?.context?.polyglot;if(o?.translations){const d=g?.root?.lang||g?.lang||s?.context?.state?.lang||o.defaultLang||"en",i=o.translations[d];if(i){const S=m(i,a);if(S!=null&&typeof S!="object")return String(S);for(const w in i){const y=i[w];if(y&&typeof y=="object"&&!Array.isArray(y)){const _=m(y,a);if(_!=null&&typeof _!="object")return String(_)}}}const C=m(o.translations,a);if(C!=null&&typeof C!="object")return String(C)}return""}})}const I=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,k=(e,r)=>{const t=e.split(`
|
|
2
|
+
`);let c=-1,u=-1,h=-1,p=-1;const g=new RegExp(`\\b${r}\\b\\s*:\\s*`);let s=0,x=!1;for(let n=0;n<t.length;n++)if(g.test(t[n])&&!x){if(x=!0,c=n+1,h=t[n].indexOf(r)+1,t[n].includes("{}")){u=c,p=t[n].indexOf("{}")+3;break}const b=t[n].slice(h+r.length);if(b.includes("{")||b.includes("["))s=1;else{u=n+1,p=t[n].length+1;break}}else if(x&&(s+=(t[n].match(/{/g)||[]).length,s+=(t[n].match(/\[/g)||[]).length,s-=(t[n].match(/}/g)||[]).length,s-=(t[n].match(/]/g)||[]).length,s===0)){u=n+1,p=t[n].lastIndexOf("}")!==-1?t[n].lastIndexOf("}")+2:t[n].length+1;break}return{startColumn:h,endColumn:p,startLineNumber:c,endLineNumber:u}},j=/\\([0-7]{1,3})/g,F=e=>e.replace(j,(r,t)=>String.fromCharCode(parseInt(t,8))),T=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),v=e=>e.replace(/\/\/\/\/\/n/g,`
|
|
3
|
+
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),R=/[^a-zA-Z0-9\s]/g,U=e=>e.replace(R,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,U as customEncodeURIComponent,v as decodeNewlines,T as encodeNewlines,N as escapeRegExp,k as findKeyPosition,I as lowercaseFirstLetter,E as replaceLiteralsWithObjectFields,F as replaceOctalEscapeSequences,O as stringIncludesAny,$ as trimStringFromSymbols};
|
package/keys.js
CHANGED
package/metadata.js
CHANGED
|
@@ -24,6 +24,46 @@ export const jsonForScript = (value) => JSON.stringify(value)
|
|
|
24
24
|
.replace(/\u2028/g, '\\u2028')
|
|
25
25
|
.replace(/\u2029/g, '\\u2029')
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Read a JSON data block — `<script type="application/json" data-…>` — that a
|
|
29
|
+
* server render left in `doc` for the client: the brender element-path
|
|
30
|
+
* registry (BRENDER_REGISTRY_BLOCK), @symbo.ls/fetch's recorded answers. No
|
|
31
|
+
* Content-Security-Policy blocks a data block (only inline scripts do).
|
|
32
|
+
* @param {Document} doc
|
|
33
|
+
* @param {string} selector - the block's CSS selector
|
|
34
|
+
* @param {object} [options]
|
|
35
|
+
* @param {boolean} [options.remove] - take the block out of the document as
|
|
36
|
+
* it is read
|
|
37
|
+
* @param {(err: Error) => void} [options.warn] - told when the block is not
|
|
38
|
+
* JSON (its value is then undefined)
|
|
39
|
+
* @returns {{ value: *, block: Element } | null} null when the document has
|
|
40
|
+
* no such block
|
|
41
|
+
*/
|
|
42
|
+
export const readJsonDataBlock = (doc, selector, { remove = false, warn } = {}) => {
|
|
43
|
+
if (!doc || typeof doc.querySelector !== 'function') return null
|
|
44
|
+
let block = null
|
|
45
|
+
try { block = doc.querySelector(selector) } catch (e) { return null }
|
|
46
|
+
if (!block) return null
|
|
47
|
+
if (remove && block.parentNode) block.parentNode.removeChild(block)
|
|
48
|
+
let value
|
|
49
|
+
try {
|
|
50
|
+
value = JSON.parse(block.textContent || '')
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (warn) warn(err)
|
|
53
|
+
}
|
|
54
|
+
return { value, block }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The data block that carries a pre-rendered page's element-path registry. */
|
|
58
|
+
export const BRENDER_REGISTRY_BLOCK = 'script[type="application/json"][data-brender="registry"]'
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The element-path registry as the data block BRENDER_REGISTRY_BLOCK selects,
|
|
62
|
+
* its JSON embedded with jsonForScript (a key can never close the block).
|
|
63
|
+
*/
|
|
64
|
+
export const brenderRegistryBlock = (registry) =>
|
|
65
|
+
'<script type="application/json" data-brender="registry">' + jsonForScript(registry) + '</script>'
|
|
66
|
+
|
|
27
67
|
const buildAttrs = (obj) =>
|
|
28
68
|
Object.entries(obj || {})
|
|
29
69
|
.filter(([_, v]) => v !== undefined)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/utils",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.788",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@symbo.ls/fetch": "^3.14.
|
|
50
|
+
"@symbo.ls/fetch": "^3.14.665"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"@symbo.ls/fetch": {
|
package/polyglotLang.js
CHANGED
|
@@ -20,3 +20,65 @@ export const polyglotLangStorageKey = (polyglot) =>
|
|
|
20
20
|
*/
|
|
21
21
|
export const polyglotFallbackLang = (stateLang, polyglot) =>
|
|
22
22
|
stateLang || (polyglot && polyglot.defaultLang) || 'en'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The language an address names: its first path segment, when that is one of
|
|
26
|
+
* the project's languages (`polyglot.languages`, else the keys of
|
|
27
|
+
* `polyglot.translations`) — `/en/about` with `['ka', 'en']` gives 'en'.
|
|
28
|
+
* Matched without regard to case, returned as configured; null for any other
|
|
29
|
+
* address. A server render (@symbo.ls/brender) starts in it, the way a page's
|
|
30
|
+
* pre-boot script starts the browser in it: stored under
|
|
31
|
+
* polyglotLangStorageKey before the app starts.
|
|
32
|
+
*/
|
|
33
|
+
export const polyglotAddressLang = (pathname, polyglot) => {
|
|
34
|
+
if (!polyglot) return null
|
|
35
|
+
const languages = Array.isArray(polyglot.languages) && polyglot.languages.length
|
|
36
|
+
? polyglot.languages
|
|
37
|
+
: Object.keys(polyglot.translations || {})
|
|
38
|
+
const first = /^\/([^/?#]+)/.exec(String(pathname || ''))
|
|
39
|
+
if (!first) return null
|
|
40
|
+
const segment = first[1].toLowerCase()
|
|
41
|
+
for (const lang of languages) {
|
|
42
|
+
if (typeof lang === 'string' && lang.toLowerCase() === segment) return lang
|
|
43
|
+
}
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A pre-rendered page's polyglot start-up script, run before the app: the
|
|
49
|
+
* labels the server rendered with, each under `storagePrefix` + its language,
|
|
50
|
+
* and — for a visitor with no language stored yet (`storageLangKey`) — the
|
|
51
|
+
* language the page was rendered in (`lang`), else the language its address
|
|
52
|
+
* names (`pathname`), else the default (polyglotFallbackLang). So the client
|
|
53
|
+
* starts where the server did: on its markup, and on the requests the page's
|
|
54
|
+
* fetch seed recorded. '' without labels.
|
|
55
|
+
*
|
|
56
|
+
* Shared by every server that writes one — @symbo.ls/brender renderPage (an
|
|
57
|
+
* ISR page) and @symbo.ls/mermaid (a publish-time cache entry, a live render)
|
|
58
|
+
* — which each kept a copy that stored the default language.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} options
|
|
61
|
+
* @param {object} [options.polyglot] - the project's polyglot config
|
|
62
|
+
* @param {object} [options.translations] - labels by language
|
|
63
|
+
* @param {string} [options.lang] - the language the page was rendered in
|
|
64
|
+
* @param {string} [options.pathname] - the page's address
|
|
65
|
+
* @param {string} [options.attrs] - attributes for the tag (` nonce="…"`)
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
export const polyglotStartupScript = ({ polyglot, translations, lang, pathname, attrs = '' } = {}) => {
|
|
69
|
+
if (!translations || typeof translations !== 'object') return ''
|
|
70
|
+
const storagePrefix = (polyglot && polyglot.storagePrefix) || ''
|
|
71
|
+
const storageLangKey = (polyglot && polyglot.storageLangKey) || ''
|
|
72
|
+
const entries = []
|
|
73
|
+
for (const code in translations) {
|
|
74
|
+
const map = translations[code]
|
|
75
|
+
if (map && typeof map === 'object') {
|
|
76
|
+
entries.push(`localStorage.setItem(${JSON.stringify(storagePrefix + code)},${JSON.stringify(JSON.stringify(map))})`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (storageLangKey) {
|
|
80
|
+
const pageLang = lang || polyglotAddressLang(pathname, polyglot) || polyglotFallbackLang(undefined, polyglot)
|
|
81
|
+
entries.push(`if(!localStorage.getItem(${JSON.stringify(storageLangKey)}))localStorage.setItem(${JSON.stringify(storageLangKey)},${JSON.stringify(pageLang)})`)
|
|
82
|
+
}
|
|
83
|
+
return entries.length ? `<script${attrs}>try{${entries.join(';')}}catch(e){}</script>` : ''
|
|
84
|
+
}
|
package/string.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
/** `str` with every RegExp special character escaped, to match it literally. */
|
|
4
|
+
export const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
5
|
+
|
|
3
6
|
export const stringIncludesAny = (str, characters) => {
|
|
4
7
|
for (const char of characters) {
|
|
5
8
|
if (str.includes(char)) {
|