@symbo.ls/utils 3.14.599 → 3.14.656
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 +14 -0
- package/dist/cjs/metadata.js +2 -2
- package/dist/cjs/methods.js +5 -5
- package/dist/esm/metadata.js +2 -2
- package/dist/esm/methods.js +5 -5
- package/metadata.js +107 -0
- package/methods.js +2 -22
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @symbo.ls/utils
|
|
2
2
|
|
|
3
|
+
## 3.14.656
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Auto-generated cross-repo patch release.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @symbo.ls/fetch@3.14.656
|
|
10
|
+
|
|
11
|
+
## 3.14.651
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Auto-generated cross-repo patch release.
|
|
16
|
+
|
|
3
17
|
## 3.14.599
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cjs/metadata.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)
|
|
1
|
+
"use strict";var A=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var W=(i,r)=>{for(var t in r)A(i,t,{get:r[t],enumerable:!0})},T=(i,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of O(r))!E.call(i,s)&&s!==t&&A(i,s,{get:()=>r[s],enumerable:!(e=L(r,s))||e.enumerable});return i};var x=i=>T(A({},"__esModule",{value:!0}),i);var C={};W(C,{generateHeadArrayTags:()=>w,generateMetaTags:()=>_,getPageMetadata:()=>P,hashContent:()=>b});module.exports=x(C);var M=require("./types.js");const a=i=>{if(i==null)return"";const r={"&":"&","<":"<",">":">",'"':""","'":"'"};return i.toString().replace(/[&<>"']/g,t=>r[t])},D=i=>Object.entries(i||{}).filter(([r,t])=>t!==void 0).map(([r,t])=>`${r}="${a(t)}"`).join(" "),b=i=>{let r=5381;const t=String(i);for(let e=0;e<t.length;e++)r=(r*33^t.charCodeAt(e))>>>0;return r.toString(36)},R=new Set(["jsonLd","styles","scripts"]),w=i=>{const r=[];if(Array.isArray(i.jsonLd))for(const t of i.jsonLd){if(t==null)continue;const e=typeof t=="string"?t:JSON.stringify(t),s=String(e).replace(/<\/script/gi,"<\\/script");r.push(`<script type="application/ld+json" data-smbls-jsonld="${b(e)}">${s}<\/script>`)}if(Array.isArray(i.styles))for(const t of i.styles){if(t==null||!String(t).trim())continue;const e=String(t).replace(/<\/style/gi,"<\\/style");r.push(`<style data-smbls-style="${b(e)}">${e}</style>`)}if(Array.isArray(i.scripts))for(const t of i.scripts){if(!t)continue;const e=typeof t=="string",s=e?t:t.src;if(!s&&!t.body)continue;const o=[];s&&o.push(`src="${a(s)}"`),e||(t.type&&o.push(`type="${a(t.type)}"`),t.async&&o.push("async"),t.defer&&o.push("defer"),t.integrity&&o.push(`integrity="${a(t.integrity)}"`),t.crossorigin&&o.push(`crossorigin="${a(t.crossorigin)}"`),t.referrerpolicy&&o.push(`referrerpolicy="${a(t.referrerpolicy)}"`),t.nomodule&&o.push("nomodule"));const f=` data-smbls-script="${a(s||b(t.body||""))}"`;if(!e&&t.body){const h=String(t.body).replace(/<\/script/gi,"<\\/script");r.push(`<script ${o.join(" ")}${f}>${h}<\/script>`)}else r.push(`<script ${o.join(" ")}${f}><\/script>`)}return r},_=(i,r)=>{r||(i={...i,robots:"noindex"});const t=Object.entries(i).reduce((e,[s,o])=>{if(!o&&o!==0&&o!==!1||R.has(s))return e;if(s==="title")return e.push(`<title>${a(o)}</title>`),e;if(s==="canonical")return e.push(`<link rel="canonical" href="${a(o)}">`),e;if(s==="manifest")return e.push(`<link rel="manifest" href="${a(o)}">`),e;if(s==="favicon"||s==="favicons"||s==="icon"||s==="icons")return(Array.isArray(o)?o:[o]).forEach(p=>{if(typeof p=="string")e.push(`<link rel="icon" href="${a(p)}">`);else if(typeof p=="object"){const u=D(p);/rel=/.test(u)?e.push(`<link ${u}>`):e.push(`<link rel="icon" ${u}>`)}}),e;if(s==="alternate")return(Array.isArray(o)?o:[o]).forEach(p=>{if(typeof p=="object"){const u=Object.entries(p).filter(([n,g])=>g!==void 0).map(([n,g])=>`${n}="${a(g)}"`).join(" ");e.push(`<link rel="alternate" ${u}>`)}}),e;const f=(l,p,u="name")=>{if(typeof p=="string"||typeof p=="number"||typeof p=="boolean")e.push(`<meta ${u}="${a(l)}" content="${a(p)}">`);else if(Array.isArray(p))p.forEach(n=>{if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")e.push(`<meta ${u}="${a(l)}" content="${a(n)}">`);else if(typeof n=="object"){const g=Object.entries(n).filter(([d,c])=>c!==void 0).map(([d,c])=>`${d}="${a(c)}"`).join(" ");e.push(`<meta ${g}>`)}});else if(typeof p=="object"){const n=Object.entries(p).filter(([g,d])=>d!==void 0).map(([g,d])=>`${g}="${a(d)}"`).join(" ");e.push(`<meta ${n}>`)}};if(s.startsWith("http-equiv:")){const l=s.replace("http-equiv:","");return f(l,o,"http-equiv"),e}if(s.startsWith("itemprop:")){const l=s.replace("itemprop:","");return f(l,o,"itemprop"),e}const y=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(l=>s.startsWith(l));if(y){const l=s.replace(y,"");return f(`${y.replace(":","")}:${l}`,o,y==="twitter:"||y==="DC:"||y==="DCTERMS:"?"name":"property"),e}if(s.startsWith("apple:")||s.startsWith("msapplication:")){const l=s.startsWith("apple:")?"apple-":"msapplication-",p=s.replace(/^apple:|^msapplication:/,"");return f(`${l}${p}`,o,"name"),e}return f(s,o),e},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return t.push(...w(i)),t.join(`
|
|
2
|
+
`)},q=i=>typeof i=="string"&&i.length>0&&!i.startsWith("/")&&!i.startsWith("http");function F(i,r){if(!r||typeof r!="object")return i;const t=s=>{if(!q(s))return s;const o=r[s];return o?.src?o.src:s},e={...i};for(const[s,o]of Object.entries(e))typeof o=="string"?e[s]=t(o):Array.isArray(o)&&(e[s]=o.map(f=>typeof f=="string"?t(f):f));return e}function m(i,r){if(!i||!r)return;const t=r.split(".");let e=i;for(const s of t){if(e==null||typeof e!="object")return;e=e[s]}return e}function K(i,r,t){const s=(r.config||r.settings||{}).polyglot||r.polyglot,o=t?.lang||s?.defaultLang||"en",h=(s?.translations||{})[o]||{},y=t?.state||{},l={...i};for(const[p,u]of Object.entries(l))typeof u!="string"||!u.includes("{{")||(l[p]=u.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(n,g,d)=>{const c=g.trim();if(d==="polyglot")return h[c]??m(h,c)??n;if(d==="getLocalStateLang")return m(y,c+o)??n;const $=m(y,c);return $!==void 0?$:h[c]??m(h,c)??n}));return l}function S(i){const r={...i};for(const[t,e]of Object.entries(r))if(typeof e=="function"){const s=e.toString(),o=s.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[t]=`{{ ${o[1]} | getLocalStateLang }}`;continue}const f=s.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(f){r[t]=`{{ ${f[1]} | polyglot }}`;continue}const h=s.match(/s\.(\w+(?:\.\w+)+)/);if(h){r[t]=`{{ ${h[1]} }}`;continue}delete r[t]}else if(typeof e=="string"){const s=e.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(s){r[t]=`{{ ${s[1]} | getLocalStateLang }}`;continue}const o=e.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(o){r[t]=`{{ ${o[1]} | polyglot }}`;continue}if(e.includes("=>")&&e.includes("s.")){const f=e.match(/s\.(\w+(?:\.\w+)+)/);if(f){r[t]=`{{ ${f[1]} }}`;continue}}}return r}function P(i,r,t,{isProduction:e=!1,channel:s="production"}={}){const o=i.pages?.[r],f=(0,M.isObject)(o?.state)&&o?.state,h=o?.metadata||o?.helmet||f||{},y=S(h),l=new Set(Object.keys(y)),p=i.app?.metadata||{},u=S(p);let n={};if(i.integrations?.seo?n={...i.integrations.seo,...u,...y}:Object.keys(u).length?n={...u,...y}:n={...y},!n.title){const c=i.name||i.key;c?e?n.title=c:s==="development"?n.title=`${c} / dev:symbo.ls`:s==="staging"?n.title=`${c} / staging:symbo.ls`:n.title=`${c} / symbo.ls`:n.title="Symbols demo"}n=K(n,i,t),n.title&&(l.has("title")||!n["og:title"])&&(l.has("og:title")||(n["og:title"]=n.title)),n.description&&(l.has("description")||!n["og:description"])&&(l.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=t?.actualPathname||r;if(n["og:url"]||n.url){const c=(n["og:url"]||n.url||"").replace(/\/$/,"");if(c&&g&&g!=="/"){const $=g.startsWith("/")?g:"/"+g;n["og:url"]=c+$}}n=F(n,i.files);const d=i.name||i.app?.metadata?.title||i.app?.name||"";for(const[c,$]of Object.entries(n))if(typeof $=="string"&&$.includes("{{")){const j=$.replace(/\{\{[^}]*\}\}/g,"").trim();j?n[c]=j:c==="title"?n[c]=d:delete n[c]}return n}
|
package/dist/cjs/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var D=Object.create;var g=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})}
|
|
2
|
-
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function st(...e){(h==="test"||h==="development")&&console.log(...e)}function it(...e){(h==="test"||h==="development")&&console.warn(...e)}function O(...e){if(h==="test"||h==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&N.call(this),new Error(...e)}}function ct(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function lt(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function ft(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,(0,E.deepClone)(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function ut(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o)try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{O.call(this,s)}),r}catch(r){if(O.call(this,r),n?.strictMode)throw r}}async function at(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=import("@symbo.ls/fetch").then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(o,e.context)}return o}function ht(e){const t=this,n=e||b.OPTIONS.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(y(t,o),n===!0)return o;const r=
|
|
3
|
-
${
|
|
1
|
+
"use strict";var D=Object.create;var g=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},w=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of I(t))!F.call(e,r)&&r!==n&&g(e,r,{get:()=>t[r],enumerable:!(o=T(t,r))||o.enumerable});return e};var m=(e,t,n)=>(n=e!=null?D(L(e)):{},w(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),J=e=>w(g({},"__esModule",{value:!0}),e);var vt={};M(vt,{call:()=>ut,defineSetter:()=>rt,error:()=>O,get:()=>U,getChildren:()=>Z,getContext:()=>ot,getDB:()=>at,getPath:()=>K,getQuery:()=>ht,getRef:()=>Y,getRoot:()=>tt,getRootContext:()=>nt,getRootData:()=>et,getRootState:()=>q,isMethod:()=>St,keys:()=>j,log:()=>st,lookdown:()=>z,lookdownAll:()=>G,lookup:()=>B,nextElement:()=>ct,parse:()=>Q,parseDeep:()=>v,previousElement:()=>lt,remove:()=>H,setActiveRootState:()=>X,setNodeStyles:()=>C,setProps:()=>W,spotByPath:()=>V,variables:()=>ft,verbose:()=>N,warn:()=>it});module.exports=J(vt);var S=require("./triggerEvent.js"),d=require("./keys.js"),f=require("./types.js"),E=require("./object.js"),P=require("./env.js"),A=require("./array.js"),b=require("./cache.js");const h="production";function V(e){const t=this,{__ref:n}=t,o=[].concat(e);let r=n.root[o[0]];if(!o||!o.length)return console.log(o,"on",t.key,"is undefined");for(;r.key===o[0]&&(o.shift(),!!o.length);)if(r=r[o[0]],!r)return;return r}function B(e){const t=this;let{parent:n}=t;if((0,f.isFunction)(e))return n.state&&e(n,n.state,n.context)?n:n.parent?n.lookup(e):void 0;if(t[e])return t[e];for(;n.param!==e;){if(n[e])return n[e];if(n=n.parent,!n)return}return n}function z(e){const t=this,{__ref:n}=t,o=n?.__children;if(o)for(let r=0;r<o.length;r++){const s=o[r],i=t[s];if(s===e)return i;if((0,f.isFunction)(e)){const l=e(i,i.state,i.context);if(i.state&&l)return i}const c=i?.lookdown?.(e);if(c)return c}}function G(e,t=[]){const n=this,{__ref:o}=n,r=o?.__children;if(r){for(let s=0;s<r.length;s++){const i=r[s],c=n[i];if(i===e)t.push(c);else if((0,f.isFunction)(e)){const l=e(c,c.state,c.context);c.state&&l&&t.push(c)}c?.lookdownAll?.(e,t)}return t.length?t:void 0}}function C(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if((0,f.isObject)(o)&&r)C.call(r,o);else if(o!=null){const s=n.replace(/[A-Z]/g,c=>"-"+c.toLowerCase()),i=String(o).replace(/\s*!important\s*$/,"");t.node.style.setProperty(s,i,"important")}}return t}}function H(e){const t=this;if((0,S.triggerEventOn)("beforeRemove",t,e)===!1)return t;(0,f.isFunction)(t.node.remove)?t.node.remove():(0,P.isProduction)()||(console.warn("This item cant be removed"),t.log()),delete t.parent[t.key],t.parent.__ref&&(t.parent.__ref.__children=(0,A.removeValueFromArray)(t.parent.__ref.__children,t.key)),(0,S.triggerEventOn)("remove",t,e)}function U(e){return this[e]}function W(e,t){const n=this;if(e)return n.update(e,t),n}function Y(e){return e?this.__ref&&this.__ref[e]:this.__ref}function Z(){return this.getRef("__children").map(t=>this[t])}function K(){return this.getRef().path}let R=null;const X=e=>{R=e||null},$=()=>R||null;function q(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=$();else if(n(this))t=this.root;else if(this.__ref&&this.__ref.path){const o=this.state&&n(this.state),r=(0,f.isFunction)(this.state)&&this.parent.state&&n(this.parent.state);(o||r)&&(t=this.state.root||this.parent.state.root)}return t||(t=$()),e?t?.[e]:t}function tt(e){const t=this.getRootState()?.__element;return t&&Object.keys(t).length>0&&e?t[e]:t}function et(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function nt(e){const t=this.getRoot()?.context;return e?t[e]:t}function ot(e){const t=this.context;return e?t[e]:t}const rt=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function j(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||d.DOMQ_PROPERTIES.has(n)&&!d.PARSED_DOMQ_PROPERTIES.has(n)||t.push(n);return t}function Q(e=[]){const t=this,n={},o=j.call(t),r=o.includes("children"),s=e.length?new Set(e):null;for(let i=0;i<o.length;i++){const c=o[i];if(s&&s.has(c)||!Object.prototype.hasOwnProperty.call(t,c)||r&&c==="content")continue;const l=t[c];if(c==="state"){if(t.__ref&&!t.__ref.__hasRootState)continue;const u=(0,f.isFunction)(l&&l.parse)?l.parse():l;n[c]=(0,f.isFunction)(u)?u:JSON.parse(JSON.stringify(u||{}))}else if(c==="scope"){if(t.__ref&&!t.__ref.__hasRootScope)continue;n[c]=JSON.parse(JSON.stringify(l||{}))}else if(c==="props"){const{__element:u,update:a,...p}=t[c];n[c]=p}else(0,f.isDefined)(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function v(e=[],t=new WeakSet){const n=this;if(t.has(n))return;t.add(n);const o=Q.call(n,e),r=e.length?new Set(e):null;for(const s in o){if(r&&r.has(s)||!Object.prototype.hasOwnProperty.call(n,s))continue;const i=o[s];Array.isArray(i)?o[s]=i.map(c=>(0,f.isObjectLike)(c)?v.call(c,e,t):c):(0,f.isObjectLike)(i)&&(o[s]=v.call(i,e,t))}return o}function N(...e){if(h!=="test"&&h!=="development")return;const t=this,{__ref:n}=t;return console.groupCollapsed(t.key),e.length?e.forEach(o=>console.log(`%c${o}:
|
|
2
|
+
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function st(...e){(h==="test"||h==="development")&&console.log(...e)}function it(...e){(h==="test"||h==="development")&&console.warn(...e)}function O(...e){if(h==="test"||h==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&N.call(this),new Error(...e)}}function ct(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function lt(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function ft(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,(0,E.deepClone)(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function ut(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o)try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{O.call(this,s)}),r}catch(r){if(O.call(this,r),n?.strictMode)throw r}}async function at(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=import("@symbo.ls/fetch").then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(o,e.context)}return o}function ht(e){const t=this,n=e||b.OPTIONS.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(y(t,o),n===!0)return o;const r=yt[n];return r?r(o):o}const y=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&&pt(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&y(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&y(i,t)},pt=(e,t)=>{const o=t.replaceAll("../","").replaceAll("~/","").split("/");let r=e;for(let s=0;s<o.length;s++){const i=o[s];s===o.length-1?r[i]||(r[i]=!0):(r[i]===!0&&(r[i]={}),r[i]||(r[i]={}),r=r[i])}},k=(e,t=0)=>{const n=" ".repeat(t),o=Object.entries(e);return o.length?o.map(([s,i])=>i===!0?`${n}${s}`:`${n}${s} {
|
|
3
|
+
${k(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
5
|
`):""},dt=e=>`{
|
|
6
|
-
${
|
|
6
|
+
${k(e,1)}
|
|
7
7
|
}`,_t=e=>{const t={fields:{},include:[]},n=(o,r)=>{const s=[];for(const i in o)if(o[i]===!0)s.push(i);else{const c=r?`${r}.${i}`:i;t.include.push(c),n(o[i],c)}s.length&&(t.fields[r||"_root"]=s)};return n(e,""),t},gt=e=>{const t=s=>{const i=[],c=[];for(const l in s)if(s[l]===!0)i.push(l);else{const u=t(s[l]),a=[];u.select&&a.push(`$select=${u.select}`),u.expand&&a.push(`$expand=${u.expand}`),c.push(a.length?`${l}(${a.join(";")})`:l)}return{select:i.length?i.join(","):"",expand:c.length?c.join(","):""}},{select:n,expand:o}=t(e),r=[];return n&&r.push(`$select=${n}`),o&&r.push(`$expand=${o}`),r.join("&")},mt=(e,t)=>{const n=[],o=[],r=new Set,s=(a,p,x)=>{r.add(p),x&&o.push(`LEFT JOIN ${p} ON ${p}.${x}_id = ${x}.id`);for(const _ in a)a[_]===!0?n.push(`${p}.${_}`):s(a[_],_,p)},i=Object.keys(e);i.length===1&&e[i[0]]!==!0?s(e[i[0]],i[0],null):s(e,"_root",null);const c=[...r][0]||"_root",l=n.length?n.join(", "):"*",u=o.length?`
|
|
8
8
|
`+o.join(`
|
|
9
9
|
`):"";return`SELECT ${l}
|
|
10
|
-
FROM ${c}${u}`},xt=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},yt=
|
|
10
|
+
FROM ${c}${u}`},xt=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},yt={graphql:dt,"json-api":_t,odata:gt,sql:mt,paths:xt};function St(e,t){return!!(d.METHODS.has(e)||t?.context?.methods?.[e])}
|
package/dist/esm/metadata.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isObject as
|
|
2
|
-
`)
|
|
1
|
+
import{isObject as S}from"./types.js";const a=r=>{if(r==null)return"";const o={"&":"&","<":"<",">":">",'"':""","'":"'"};return r.toString().replace(/[&<>"']/g,e=>o[e])},M=r=>Object.entries(r||{}).filter(([o,e])=>e!==void 0).map(([o,e])=>`${o}="${a(e)}"`).join(" "),j=r=>{let o=5381;const e=String(r);for(let t=0;t<e.length;t++)o=(o*33^e.charCodeAt(t))>>>0;return o.toString(36)},w=new Set(["jsonLd","styles","scripts"]),L=r=>{const o=[];if(Array.isArray(r.jsonLd))for(const e of r.jsonLd){if(e==null)continue;const t=typeof e=="string"?e:JSON.stringify(e),n=String(t).replace(/<\/script/gi,"<\\/script");o.push(`<script type="application/ld+json" data-smbls-jsonld="${j(t)}">${n}<\/script>`)}if(Array.isArray(r.styles))for(const e of r.styles){if(e==null||!String(e).trim())continue;const t=String(e).replace(/<\/style/gi,"<\\/style");o.push(`<style data-smbls-style="${j(t)}">${t}</style>`)}if(Array.isArray(r.scripts))for(const e of r.scripts){if(!e)continue;const t=typeof e=="string",n=t?e:e.src;if(!n&&!e.body)continue;const i=[];n&&i.push(`src="${a(n)}"`),t||(e.type&&i.push(`type="${a(e.type)}"`),e.async&&i.push("async"),e.defer&&i.push("defer"),e.integrity&&i.push(`integrity="${a(e.integrity)}"`),e.crossorigin&&i.push(`crossorigin="${a(e.crossorigin)}"`),e.referrerpolicy&&i.push(`referrerpolicy="${a(e.referrerpolicy)}"`),e.nomodule&&i.push("nomodule"));const f=` data-smbls-script="${a(n||j(e.body||""))}"`;if(!t&&e.body){const h=String(e.body).replace(/<\/script/gi,"<\\/script");o.push(`<script ${i.join(" ")}${f}>${h}<\/script>`)}else o.push(`<script ${i.join(" ")}${f}><\/script>`)}return o},x=(r,o)=>{o||(r={...r,robots:"noindex"});const e=Object.entries(r).reduce((t,[n,i])=>{if(!i&&i!==0&&i!==!1||w.has(n))return t;if(n==="title")return t.push(`<title>${a(i)}</title>`),t;if(n==="canonical")return t.push(`<link rel="canonical" href="${a(i)}">`),t;if(n==="manifest")return t.push(`<link rel="manifest" href="${a(i)}">`),t;if(n==="favicon"||n==="favicons"||n==="icon"||n==="icons")return(Array.isArray(i)?i:[i]).forEach(p=>{if(typeof p=="string")t.push(`<link rel="icon" href="${a(p)}">`);else if(typeof p=="object"){const u=M(p);/rel=/.test(u)?t.push(`<link ${u}>`):t.push(`<link rel="icon" ${u}>`)}}),t;if(n==="alternate")return(Array.isArray(i)?i:[i]).forEach(p=>{if(typeof p=="object"){const u=Object.entries(p).filter(([s,g])=>g!==void 0).map(([s,g])=>`${s}="${a(g)}"`).join(" ");t.push(`<link rel="alternate" ${u}>`)}}),t;const f=(l,p,u="name")=>{if(typeof p=="string"||typeof p=="number"||typeof p=="boolean")t.push(`<meta ${u}="${a(l)}" content="${a(p)}">`);else if(Array.isArray(p))p.forEach(s=>{if(typeof s=="string"||typeof s=="number"||typeof s=="boolean")t.push(`<meta ${u}="${a(l)}" content="${a(s)}">`);else if(typeof s=="object"){const g=Object.entries(s).filter(([d,c])=>c!==void 0).map(([d,c])=>`${d}="${a(c)}"`).join(" ");t.push(`<meta ${g}>`)}});else if(typeof p=="object"){const s=Object.entries(p).filter(([g,d])=>d!==void 0).map(([g,d])=>`${g}="${a(d)}"`).join(" ");t.push(`<meta ${s}>`)}};if(n.startsWith("http-equiv:")){const l=n.replace("http-equiv:","");return f(l,i,"http-equiv"),t}if(n.startsWith("itemprop:")){const l=n.replace("itemprop:","");return f(l,i,"itemprop"),t}const y=["og:","twitter:","fb:","article:","profile:","book:","business:","music:","product:","video:","DC:","DCTERMS:"].find(l=>n.startsWith(l));if(y){const l=n.replace(y,"");return f(`${y.replace(":","")}:${l}`,i,y==="twitter:"||y==="DC:"||y==="DCTERMS:"?"name":"property"),t}if(n.startsWith("apple:")||n.startsWith("msapplication:")){const l=n.startsWith("apple:")?"apple-":"msapplication-",p=n.replace(/^apple:|^msapplication:/,"");return f(`${l}${p}`,i,"name"),t}return f(n,i),t},['<meta charset="UTF-8">','<meta name="viewport" content="width=device-width, initial-scale=1">']);return e.push(...L(r)),e.join(`
|
|
2
|
+
`)},O=r=>typeof r=="string"&&r.length>0&&!r.startsWith("/")&&!r.startsWith("http");function E(r,o){if(!o||typeof o!="object")return r;const e=n=>{if(!O(n))return n;const i=o[n];return i?.src?i.src:n},t={...r};for(const[n,i]of Object.entries(t))typeof i=="string"?t[n]=e(i):Array.isArray(i)&&(t[n]=i.map(f=>typeof f=="string"?e(f):f));return t}function m(r,o){if(!r||!o)return;const e=o.split(".");let t=r;for(const n of e){if(t==null||typeof t!="object")return;t=t[n]}return t}function W(r,o,e){const n=(o.config||o.settings||{}).polyglot||o.polyglot,i=e?.lang||n?.defaultLang||"en",h=(n?.translations||{})[i]||{},y=e?.state||{},l={...r};for(const[p,u]of Object.entries(l))typeof u!="string"||!u.includes("{{")||(l[p]=u.replace(/\{\{\s*([^|{}]+?)\s*(?:\|\s*(\w+)\s*)?\}\}/g,(s,g,d)=>{const c=g.trim();if(d==="polyglot")return h[c]??m(h,c)??s;if(d==="getLocalStateLang")return m(y,c+i)??s;const $=m(y,c);return $!==void 0?$:h[c]??m(h,c)??s}));return l}function A(r){const o={...r};for(const[e,t]of Object.entries(o))if(typeof t=="function"){const n=t.toString(),i=n.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(i){o[e]=`{{ ${i[1]} | getLocalStateLang }}`;continue}const f=n.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(f){o[e]=`{{ ${f[1]} | polyglot }}`;continue}const h=n.match(/s\.(\w+(?:\.\w+)+)/);if(h){o[e]=`{{ ${h[1]} }}`;continue}delete o[e]}else if(typeof t=="string"){const n=t.match(/el\.call\(\s*["']getLocalStateLang["']\s*,\s*["']([^"']+)["']\s*\)/);if(n){o[e]=`{{ ${n[1]} | getLocalStateLang }}`;continue}const i=t.match(/el\.call\(\s*["']polyglot["']\s*,\s*["']([^"']+)["']\s*\)/);if(i){o[e]=`{{ ${i[1]} | polyglot }}`;continue}if(t.includes("=>")&&t.includes("s.")){const f=t.match(/s\.(\w+(?:\.\w+)+)/);if(f){o[e]=`{{ ${f[1]} }}`;continue}}}return o}function D(r,o,e,{isProduction:t=!1,channel:n="production"}={}){const i=r.pages?.[o],f=S(i?.state)&&i?.state,h=i?.metadata||i?.helmet||f||{},y=A(h),l=new Set(Object.keys(y)),p=r.app?.metadata||{},u=A(p);let s={};if(r.integrations?.seo?s={...r.integrations.seo,...u,...y}:Object.keys(u).length?s={...u,...y}:s={...y},!s.title){const c=r.name||r.key;c?t?s.title=c:n==="development"?s.title=`${c} / dev:symbo.ls`:n==="staging"?s.title=`${c} / staging:symbo.ls`:s.title=`${c} / symbo.ls`:s.title="Symbols demo"}s=W(s,r,e),s.title&&(l.has("title")||!s["og:title"])&&(l.has("og:title")||(s["og:title"]=s.title)),s.description&&(l.has("description")||!s["og:description"])&&(l.has("og:description")||(s["og:description"]=s.description)),s.title&&!s["twitter:title"]&&(s["twitter:title"]=s.title),s.description&&!s["twitter:description"]&&(s["twitter:description"]=s.description);const g=e?.actualPathname||o;if(s["og:url"]||s.url){const c=(s["og:url"]||s.url||"").replace(/\/$/,"");if(c&&g&&g!=="/"){const $=g.startsWith("/")?g:"/"+g;s["og:url"]=c+$}}s=E(s,r.files);const d=r.name||r.app?.metadata?.title||r.app?.name||"";for(const[c,$]of Object.entries(s))if(typeof $=="string"&&$.includes("{{")){const b=$.replace(/\{\{[^}]*\}\}/g,"").trim();b?s[c]=b:c==="title"?s[c]=d:delete s[c]}return s}export{L as generateHeadArrayTags,x as generateMetaTags,D as getPageMetadata,j as hashContent};
|
package/dist/esm/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{triggerEventOn as m}from"./triggerEvent.js";import{DOMQ_PROPERTIES as
|
|
2
|
-
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function
|
|
3
|
-
${
|
|
1
|
+
import{triggerEventOn as m}from"./triggerEvent.js";import{DOMQ_PROPERTIES as R,METHODS as $,PARSED_DOMQ_PROPERTIES as k}from"./keys.js";import{isDefined as E,isFunction as p,isObject as P,isObjectLike as x}from"./types.js";import{deepClone as A}from"./object.js";import{isProduction as b}from"./env.js";import{removeValueFromArray as C}from"./array.js";import{OPTIONS as j}from"./cache.js";const a="production";function K(e){const t=this,{__ref:n}=t,o=[].concat(e);let r=n.root[o[0]];if(!o||!o.length)return console.log(o,"on",t.key,"is undefined");for(;r.key===o[0]&&(o.shift(),!!o.length);)if(r=r[o[0]],!r)return;return r}function X(e){const t=this;let{parent:n}=t;if(p(e))return n.state&&e(n,n.state,n.context)?n:n.parent?n.lookup(e):void 0;if(t[e])return t[e];for(;n.param!==e;){if(n[e])return n[e];if(n=n.parent,!n)return}return n}function q(e){const t=this,{__ref:n}=t,o=n?.__children;if(o)for(let r=0;r<o.length;r++){const s=o[r],i=t[s];if(s===e)return i;if(p(e)){const l=e(i,i.state,i.context);if(i.state&&l)return i}const c=i?.lookdown?.(e);if(c)return c}}function tt(e,t=[]){const n=this,{__ref:o}=n,r=o?.__children;if(r){for(let s=0;s<r.length;s++){const i=r[s],c=n[i];if(i===e)t.push(c);else if(p(e)){const l=e(c,c.state,c.context);c.state&&l&&t.push(c)}c?.lookdownAll?.(e,t)}return t.length?t:void 0}}function Q(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if(P(o)&&r)Q.call(r,o);else if(o!=null){const s=n.replace(/[A-Z]/g,c=>"-"+c.toLowerCase()),i=String(o).replace(/\s*!important\s*$/,"");t.node.style.setProperty(s,i,"important")}}return t}}function et(e){const t=this;if(m("beforeRemove",t,e)===!1)return t;p(t.node.remove)?t.node.remove():b()||(console.warn("This item cant be removed"),t.log()),delete t.parent[t.key],t.parent.__ref&&(t.parent.__ref.__children=C(t.parent.__ref.__children,t.key)),m("remove",t,e)}function nt(e){return this[e]}function ot(e,t){const n=this;if(e)return n.update(e,t),n}function rt(e){return e?this.__ref&&this.__ref[e]:this.__ref}function st(){return this.getRef("__children").map(t=>this[t])}function it(){return this.getRef().path}let y=null;const ct=e=>{y=e||null},S=()=>y||null;function lt(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=S();else if(n(this))t=this.root;else if(this.__ref&&this.__ref.path){const o=this.state&&n(this.state),r=p(this.state)&&this.parent.state&&n(this.parent.state);(o||r)&&(t=this.state.root||this.parent.state.root)}return t||(t=S()),e?t?.[e]:t}function ft(e){const t=this.getRootState()?.__element;return t&&Object.keys(t).length>0&&e?t[e]:t}function ut(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function at(e){const t=this.getRoot()?.context;return e?t[e]:t}function ht(e){const t=this.context;return e?t[e]:t}const pt=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function N(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||R.has(n)&&!k.has(n)||t.push(n);return t}function D(e=[]){const t=this,n={},o=N.call(t),r=o.includes("children"),s=e.length?new Set(e):null;for(let i=0;i<o.length;i++){const c=o[i];if(s&&s.has(c)||!Object.prototype.hasOwnProperty.call(t,c)||r&&c==="content")continue;const l=t[c];if(c==="state"){if(t.__ref&&!t.__ref.__hasRootState)continue;const f=p(l&&l.parse)?l.parse():l;n[c]=p(f)?f:JSON.parse(JSON.stringify(f||{}))}else if(c==="scope"){if(t.__ref&&!t.__ref.__hasRootScope)continue;n[c]=JSON.parse(JSON.stringify(l||{}))}else if(c==="props"){const{__element:f,update:u,...h}=t[c];n[c]=h}else E(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function v(e=[],t=new WeakSet){const n=this;if(t.has(n))return;t.add(n);const o=D.call(n,e),r=e.length?new Set(e):null;for(const s in o){if(r&&r.has(s)||!Object.prototype.hasOwnProperty.call(n,s))continue;const i=o[s];Array.isArray(i)?o[s]=i.map(c=>x(c)?v.call(c,e,t):c):x(i)&&(o[s]=v.call(i,e,t))}return o}function T(...e){if(a!=="test"&&a!=="development")return;const t=this,{__ref:n}=t;return console.groupCollapsed(t.key),e.length?e.forEach(o=>console.log(`%c${o}:
|
|
2
|
+
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function dt(...e){(a==="test"||a==="development")&&console.log(...e)}function _t(...e){(a==="test"||a==="development")&&console.warn(...e)}function O(...e){if(a==="test"||a==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&T.call(this),new Error(...e)}}function gt(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function mt(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function xt(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,A(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function yt(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o)try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{O.call(this,s)}),r}catch(r){if(O.call(this,r),n?.strictMode)throw r}}async function St(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=import("@symbo.ls/fetch").then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(o,e.context)}return o}function vt(e){const t=this,n=e||j.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(g(t,o),n===!0)return o;const r=B[n];return r?r(o):o}const g=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&&I(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&g(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&g(i,t)},I=(e,t)=>{const o=t.replaceAll("../","").replaceAll("~/","").split("/");let r=e;for(let s=0;s<o.length;s++){const i=o[s];s===o.length-1?r[i]||(r[i]=!0):(r[i]===!0&&(r[i]={}),r[i]||(r[i]={}),r=r[i])}},w=(e,t=0)=>{const n=" ".repeat(t),o=Object.entries(e);return o.length?o.map(([s,i])=>i===!0?`${n}${s}`:`${n}${s} {
|
|
3
|
+
${w(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
5
|
`):""},L=e=>`{
|
|
6
|
-
${
|
|
6
|
+
${w(e,1)}
|
|
7
7
|
}`,F=e=>{const t={fields:{},include:[]},n=(o,r)=>{const s=[];for(const i in o)if(o[i]===!0)s.push(i);else{const c=r?`${r}.${i}`:i;t.include.push(c),n(o[i],c)}s.length&&(t.fields[r||"_root"]=s)};return n(e,""),t},M=e=>{const t=s=>{const i=[],c=[];for(const l in s)if(s[l]===!0)i.push(l);else{const f=t(s[l]),u=[];f.select&&u.push(`$select=${f.select}`),f.expand&&u.push(`$expand=${f.expand}`),c.push(u.length?`${l}(${u.join(";")})`:l)}return{select:i.length?i.join(","):"",expand:c.length?c.join(","):""}},{select:n,expand:o}=t(e),r=[];return n&&r.push(`$select=${n}`),o&&r.push(`$expand=${o}`),r.join("&")},J=(e,t)=>{const n=[],o=[],r=new Set,s=(u,h,_)=>{r.add(h),_&&o.push(`LEFT JOIN ${h} ON ${h}.${_}_id = ${_}.id`);for(const d in u)u[d]===!0?n.push(`${h}.${d}`):s(u[d],d,h)},i=Object.keys(e);i.length===1&&e[i[0]]!==!0?s(e[i[0]],i[0],null):s(e,"_root",null);const c=[...r][0]||"_root",l=n.length?n.join(", "):"*",f=o.length?`
|
|
8
8
|
`+o.join(`
|
|
9
9
|
`):"";return`SELECT ${l}
|
|
10
|
-
FROM ${c}${f}`},V=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},B=
|
|
10
|
+
FROM ${c}${f}`},V=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},B={graphql:L,"json-api":F,odata:M,sql:J,paths:V};function Ot(e,t){return!!($.has(e)||t?.context?.methods?.[e])}export{yt as call,pt as defineSetter,O as error,nt as get,st as getChildren,ht as getContext,St as getDB,it as getPath,vt as getQuery,rt as getRef,ft as getRoot,at as getRootContext,ut as getRootData,lt as getRootState,Ot as isMethod,N as keys,dt as log,q as lookdown,tt as lookdownAll,X as lookup,gt as nextElement,D as parse,v as parseDeep,mt as previousElement,et as remove,ct as setActiveRootState,Q as setNodeStyles,ot as setProps,K as spotByPath,xt as variables,T as verbose,_t as warn};
|
package/metadata.js
CHANGED
|
@@ -14,6 +14,106 @@ const buildAttrs = (obj) =>
|
|
|
14
14
|
.map(([k, v]) => `${k}="${escapeHtml(v)}"`)
|
|
15
15
|
.join(' ')
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Stable signature used to content-key the `<script>` / `<style>` tags that
|
|
19
|
+
* `metadata.jsonLd` / `metadata.styles` / `metadata.scripts` emit. Not
|
|
20
|
+
* cryptographic — it only has to be deterministic per identical content so
|
|
21
|
+
* the three head pipelines (SSR `generateHeadHtml`, client runtime
|
|
22
|
+
* `applyMetadata`, published-site `generateMetaTags`) produce the same key
|
|
23
|
+
* and never double-emit or pile up duplicate tags after hydration.
|
|
24
|
+
*
|
|
25
|
+
* Lives here because `utils` is the lowest package in the graph:
|
|
26
|
+
* `@symbo.ls/helmet` already depends on `@symbo.ls/utils`, never the
|
|
27
|
+
* reverse, so this is the only place the three pipelines can share one
|
|
28
|
+
* implementation without a cycle. The helmet plugin still carries a
|
|
29
|
+
* byte-identical private `_hashContent` (`plugins/helmet/index.js`); it can
|
|
30
|
+
* drop it in favour of this export whenever that package is next touched.
|
|
31
|
+
*/
|
|
32
|
+
export const hashContent = (s) => {
|
|
33
|
+
let h = 5381
|
|
34
|
+
const str = String(s)
|
|
35
|
+
for (let i = 0; i < str.length; i++) h = ((h * 33) ^ str.charCodeAt(i)) >>> 0
|
|
36
|
+
return h.toString(36)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Array-shaped head extensions. These are NOT meta tags — they carry their
|
|
41
|
+
* own tag shape (`<script type="application/ld+json">`, `<style>`,
|
|
42
|
+
* `<script src>`), so they must never reach the generic `processMetaTag`
|
|
43
|
+
* path (which would serialize `{ '@context': … }` object keys straight into
|
|
44
|
+
* `<meta @context="…">`). The client runtime skips them the same way — see
|
|
45
|
+
* `applyMetadata` in `plugins/helmet/index.js`.
|
|
46
|
+
*/
|
|
47
|
+
const HEAD_ARRAY_KEYS = new Set(['jsonLd', 'styles', 'scripts'])
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Render the `jsonLd` / `styles` / `scripts` head extensions.
|
|
51
|
+
*
|
|
52
|
+
* Emission semantics mirror `generateHeadHtml` (`plugins/helmet/index.js`)
|
|
53
|
+
* exactly — same `data-smbls-*` key attributes, same escaping, same hash
|
|
54
|
+
* inputs — so a published page and an SSR'd page produce interchangeable
|
|
55
|
+
* head markup and the client runtime reconciles both without re-emitting.
|
|
56
|
+
*
|
|
57
|
+
* metadata.jsonLd: [{ '@context': 'https://schema.org', '@type': 'Organization', … }]
|
|
58
|
+
* metadata.styles: ['@media (prefers-color-scheme: dark) { :root { --c: #111 } }']
|
|
59
|
+
* metadata.scripts: [{ src: 'https://…', async: true, defer: true, integrity: '…' }]
|
|
60
|
+
*/
|
|
61
|
+
export const generateHeadArrayTags = (metadata) => {
|
|
62
|
+
const tags = []
|
|
63
|
+
|
|
64
|
+
// jsonLd: one <script type="application/ld+json"> per entry.
|
|
65
|
+
if (Array.isArray(metadata.jsonLd)) {
|
|
66
|
+
for (const item of metadata.jsonLd) {
|
|
67
|
+
if (item == null) continue
|
|
68
|
+
const body = typeof item === 'string' ? item : JSON.stringify(item)
|
|
69
|
+
// Defense in depth: script bodies must not contain '</script>'. Escape
|
|
70
|
+
// the forward slash so a malicious or accidental value can't break out.
|
|
71
|
+
// The key hashes the RAW body so the escaping never shifts the key.
|
|
72
|
+
const safe = String(body).replace(/<\/script/gi, '<\\/script')
|
|
73
|
+
tags.push(`<script type="application/ld+json" data-smbls-jsonld="${hashContent(body)}">${safe}</script>`)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// styles: inline <style> blocks.
|
|
78
|
+
if (Array.isArray(metadata.styles)) {
|
|
79
|
+
for (const s of metadata.styles) {
|
|
80
|
+
if (s == null || !String(s).trim()) continue
|
|
81
|
+
const body = String(s).replace(/<\/style/gi, '<\\/style')
|
|
82
|
+
tags.push(`<style data-smbls-style="${hashContent(body)}">${body}</style>`)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// scripts: src-keyed <script> with async/defer/integrity passthrough.
|
|
87
|
+
if (Array.isArray(metadata.scripts)) {
|
|
88
|
+
for (const spec of metadata.scripts) {
|
|
89
|
+
if (!spec) continue
|
|
90
|
+
const isStr = typeof spec === 'string'
|
|
91
|
+
const src = isStr ? spec : spec.src
|
|
92
|
+
if (!src && !spec.body) continue
|
|
93
|
+
const attrs = []
|
|
94
|
+
if (src) attrs.push(`src="${escapeHtml(src)}"`)
|
|
95
|
+
if (!isStr) {
|
|
96
|
+
if (spec.type) attrs.push(`type="${escapeHtml(spec.type)}"`)
|
|
97
|
+
if (spec.async) attrs.push('async')
|
|
98
|
+
if (spec.defer) attrs.push('defer')
|
|
99
|
+
if (spec.integrity) attrs.push(`integrity="${escapeHtml(spec.integrity)}"`)
|
|
100
|
+
if (spec.crossorigin) attrs.push(`crossorigin="${escapeHtml(spec.crossorigin)}"`)
|
|
101
|
+
if (spec.referrerpolicy) attrs.push(`referrerpolicy="${escapeHtml(spec.referrerpolicy)}"`)
|
|
102
|
+
if (spec.nomodule) attrs.push('nomodule')
|
|
103
|
+
}
|
|
104
|
+
const keyAttr = ` data-smbls-script="${escapeHtml(src || hashContent(spec.body || ''))}"`
|
|
105
|
+
if (!isStr && spec.body) {
|
|
106
|
+
const safe = String(spec.body).replace(/<\/script/gi, '<\\/script')
|
|
107
|
+
tags.push(`<script ${attrs.join(' ')}${keyAttr}>${safe}</script>`)
|
|
108
|
+
} else {
|
|
109
|
+
tags.push(`<script ${attrs.join(' ')}${keyAttr}></script>`)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return tags
|
|
115
|
+
}
|
|
116
|
+
|
|
17
117
|
/**
|
|
18
118
|
* Generates HTML meta tags from a flat metadata object.
|
|
19
119
|
* Works on both server (SSR head injection) and client (dynamic meta updates).
|
|
@@ -29,6 +129,10 @@ export const generateMetaTags = (metadata, isProduction) => {
|
|
|
29
129
|
(acc, [key, value]) => {
|
|
30
130
|
if (!value && value !== 0 && value !== false) return acc
|
|
31
131
|
|
|
132
|
+
// Array-shaped head extensions carry their own tag shape — emitted
|
|
133
|
+
// after the reduce by generateHeadArrayTags, never as <meta>.
|
|
134
|
+
if (HEAD_ARRAY_KEYS.has(key)) return acc
|
|
135
|
+
|
|
32
136
|
if (key === 'title') {
|
|
33
137
|
acc.push(`<title>${escapeHtml(value)}</title>`)
|
|
34
138
|
return acc
|
|
@@ -148,6 +252,9 @@ export const generateMetaTags = (metadata, isProduction) => {
|
|
|
148
252
|
]
|
|
149
253
|
)
|
|
150
254
|
|
|
255
|
+
// jsonLd / styles / scripts trail the meta tags, matching generateHeadHtml.
|
|
256
|
+
tags.push(...generateHeadArrayTags(metadata))
|
|
257
|
+
|
|
151
258
|
return tags.join('\n')
|
|
152
259
|
}
|
|
153
260
|
|
package/methods.js
CHANGED
|
@@ -475,8 +475,8 @@ export async function getDB () {
|
|
|
475
475
|
element.context.fetch = resolved
|
|
476
476
|
delete db.__resolving
|
|
477
477
|
// resolveDb returns null when the config has no `adapter` field or the
|
|
478
|
-
// adapter's setup() bails (e.g. cross-realm
|
|
479
|
-
//
|
|
478
|
+
// adapter's setup() bails (e.g. a cross-realm client factory returns a
|
|
479
|
+
// client without `.auth` — see workspace
|
|
480
480
|
// attachDbAdapters.js:resolveDbAdapters for the consumer-side
|
|
481
481
|
// pre-resolve that bypasses this path). Without `?.`, the next line
|
|
482
482
|
// throws `Cannot read properties of null (reading 'getSession')` and
|
|
@@ -659,31 +659,11 @@ const formatPaths = query => {
|
|
|
659
659
|
return paths
|
|
660
660
|
}
|
|
661
661
|
|
|
662
|
-
const formatSupabase = query => {
|
|
663
|
-
const build = obj => {
|
|
664
|
-
const parts = []
|
|
665
|
-
for (const key in obj) {
|
|
666
|
-
if (obj[key] === true) {
|
|
667
|
-
parts.push(key)
|
|
668
|
-
} else {
|
|
669
|
-
parts.push(`${key}(${build(obj[key])})`)
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
return parts.join(', ')
|
|
673
|
-
}
|
|
674
|
-
const roots = Object.keys(query)
|
|
675
|
-
if (roots.length === 1 && query[roots[0]] !== true) {
|
|
676
|
-
return { from: roots[0], select: build(query[roots[0]]) }
|
|
677
|
-
}
|
|
678
|
-
return { from: null, select: build(query) }
|
|
679
|
-
}
|
|
680
|
-
|
|
681
662
|
const QUERY_FORMATTERS = {
|
|
682
663
|
graphql: formatGraphQL,
|
|
683
664
|
'json-api': formatJsonApi,
|
|
684
665
|
odata: formatOData,
|
|
685
666
|
sql: formatSQL,
|
|
686
|
-
supabase: formatSupabase,
|
|
687
667
|
paths: formatPaths
|
|
688
668
|
}
|
|
689
669
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/utils",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.656",
|
|
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.656"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"@symbo.ls/fetch": {
|