@storyblok/astro 2.5.7 → 2.5.9

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.
@@ -1,14 +1,14 @@
1
- (function(g,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(g=typeof globalThis<"u"?globalThis:g||self,h(g.storyblokAstro={}))})(this,function(g){"use strict";function h(r,e,t){const o="virtual:storyblok-init",a="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return a},async load(s){if(s===a)return`
1
+ (function(g,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(g=typeof globalThis<"u"?globalThis:g||self,m(g.storyblokAstro={}))})(this,function(g){"use strict";function m(r,t,e){const o="virtual:storyblok-init",s="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===o)return s},async load(n){if(n===s)return`
2
2
  import { storyblokInit, apiPlugin } from "@storyblok/js";
3
3
  const { storyblokApi } = storyblokInit({
4
4
  accessToken: "${r}",
5
- use: ${e?"[]":"[apiPlugin]"},
6
- apiOptions: ${JSON.stringify(t)},
5
+ use: ${t?"[]":"[apiPlugin]"},
6
+ apiOptions: ${JSON.stringify(e)},
7
7
  });
8
8
  export const storyblokApiInstance = storyblokApi;
9
- `}}}const x=/[\p{Lu}]/u,R=/[\p{Ll}]/u,k=/^[\p{Lu}](?![\p{Lu}])/gu,$=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,O=new RegExp("^"+b.source),v=new RegExp(b.source+$.source,"gu"),I=new RegExp("\\d+"+$.source,"gu"),N=(r,e,t,o)=>{let a=!1,s=!1,n=!1,f=!1;for(let l=0;l<r.length;l++){const i=r[l];f=l>2?r[l-3]==="-":!0,a&&x.test(i)?(r=r.slice(0,l)+"-"+r.slice(l),a=!1,n=s,s=!0,l++):s&&n&&R.test(i)&&(!f||o)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),n=s,s=!1,a=!0):(a=e(i)===i&&t(i)!==i,n=s,s=t(i)===i&&e(i)!==i)}return r},_=(r,e)=>(k.lastIndex=0,r.replace(k,t=>e(t))),L=(r,e)=>(v.lastIndex=0,I.lastIndex=0,r.replace(v,(t,o)=>e(o)).replace(I,t=>e(t)));function w(r,e){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(r)?r=r.map(s=>s.trim()).filter(s=>s.length).join("-"):r=r.trim(),r.length===0)return"";const t=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return r.length===1?b.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=N(r,t,o,e.preserveConsecutiveUppercase)),r=r.replace(O,""),r=e.preserveConsecutiveUppercase?_(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),L(r,o))}function M(r,e,t,o){const a="virtual:storyblok-components",s="\0"+a;return{name:"vite-plugin-storyblok-components",async resolveId(n){if(n===a)return s},async load(n){if(n===s){const f=[],l=[];for await(const[c,d]of Object.entries(e)){const p=await this.resolve("/"+r+"/"+d+".astro");if(p)f.push(`import ${w(c)} from "${p.id}"`);else if(t)l.push(c);else throw new Error(`Component could not be found for blok "${c}"! Does "${"/"+r+"/"+d}.astro" exist?`)}let i="";if(t)if(i=",FallbackComponent",o){const c=await this.resolve("/"+r+"/"+o+".astro");if(!c)throw new Error(`Custom fallback component could not be found. Does "${"/"+r+"/"+o}.astro" exist?`);f.push(`import FallbackComponent from "${c.id}"`)}else f.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${f.join(";")};export default {${Object.keys(e).filter(c=>!l.includes(c)).map(c=>w(c)).join(",")}${i}}`;if(t)return`${f[0]}; export default {${i.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
9
+ `}}}const R=/[\p{Lu}]/u,x=/[\p{Ll}]/u,$=/^[\p{Lu}](?![\p{Lu}])/gu,v=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,O=new RegExp("^"+b.source),I=new RegExp(b.source+v.source,"gu"),w=new RegExp("\\d+"+v.source,"gu"),M=(r,t,e,o)=>{let s=!1,n=!1,a=!1,c=!1;for(let l=0;l<r.length;l++){const i=r[l];c=l>2?r[l-3]==="-":!0,s&&R.test(i)?(r=r.slice(0,l)+"-"+r.slice(l),s=!1,a=n,n=!0,l++):n&&a&&x.test(i)&&(!c||o)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),a=n,n=!1,s=!0):(s=t(i)===i&&e(i)!==i,a=n,n=e(i)===i&&t(i)!==i)}return r},N=(r,t)=>($.lastIndex=0,r.replaceAll($,e=>t(e))),P=(r,t)=>(I.lastIndex=0,w.lastIndex=0,r.replaceAll(w,(e,o,s)=>["_","-"].includes(r.charAt(s+e.length))?e:t(e)).replaceAll(I,(e,o)=>t(o)));function T(r,t){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(r)?r=r.map(n=>n.trim()).filter(n=>n.length).join("-"):r=r.trim(),r.length===0)return"";const e=t.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(t.locale),o=t.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(t.locale);return r.length===1?b.test(r)?"":t.pascalCase?o(r):e(r):(r!==e(r)&&(r=M(r,e,o,t.preserveConsecutiveUppercase)),r=r.replace(O,""),r=t.preserveConsecutiveUppercase?N(r,e):e(r),t.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),P(r,o))}function L(r,t,e,o){const s="virtual:storyblok-components",n="\0"+s;return{name:"vite-plugin-storyblok-components",async resolveId(a){if(a===s)return n},async load(a){if(a===n){const c=[],l=[];for await(const[u,d]of Object.entries(t)){const h=await this.resolve("/"+r+"/"+d+".astro");if(h)c.push(`import ${T(u)} from "${h.id}"`);else if(e)l.push(u);else throw new Error(`Component could not be found for blok "${u}"! Does "${"/"+r+"/"+d}.astro" exist?`)}let i="";if(e)if(i=",FallbackComponent",o){const u=await this.resolve("/"+r+"/"+o+".astro");if(!u)throw new Error(`Custom fallback component could not be found. Does "${"/"+r+"/"+o}.astro" exist?`);c.push(`import FallbackComponent from "${u.id}"`)}else c.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${c.join(";")};export default {${Object.keys(t).filter(u=>!l.includes(u)).map(u=>T(u)).join(",")}${i}}`;if(e)return`${c[0]}; export default {${i.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
10
10
  Please register your components or enable the fallback component.
11
- Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function P(r){const e="virtual:storyblok-options",t="\0"+e;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===e)return t},async load(o){if(o===t)return`export default ${JSON.stringify(r)}`}}}let T=!1;const E=[],z=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=a=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}T?a():E.push(a)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=a=>t(a),o.onload=a=>{E.forEach(s=>s()),T=!0,e(a)},document.getElementsByTagName("head")[0].appendChild(o)});var D=Object.defineProperty,U=(r,e,t)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,S=(r,e,t)=>(U(r,typeof e!="symbol"?e+"":e,t),t);const q=function(r,e){const t={};for(const o in r){const a=r[o];e.indexOf(o)>-1&&a!==null&&(t[o]=a)}return t},B=r=>r==="email",F=()=>({singleTag:"hr"}),J=()=>({tag:"blockquote"}),K=()=>({tag:"ul"}),V=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),W=r=>({tag:`h${r.attrs.level}`}),Y=r=>({singleTag:[{tag:"img",attrs:q(r.attrs,["src","alt","title"])}]}),H=()=>({tag:"li"}),Q=()=>({tag:"ol"}),X=()=>({tag:"p"}),Z=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),ee=()=>({tag:"b"}),te=()=>({tag:"strike"}),re=()=>({tag:"u"}),oe=()=>({tag:"strong"}),se=()=>({tag:"code"}),ae=()=>({tag:"i"}),ne=r=>{const e={...r.attrs},{linktype:t="url"}=r.attrs;if(B(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const o in e.custom)e[o]=e.custom[o];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},le=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ie=()=>({tag:"sub"}),ce=()=>({tag:"sup"}),ge=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ue=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},fe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},C={nodes:{horizontal_rule:F,blockquote:J,bullet_list:K,code_block:V,hard_break:G,heading:W,image:Y,list_item:H,ordered_list:Q,paragraph:X,emoji:Z},marks:{bold:ee,strike:te,underline:re,strong:oe,code:se,italic:ae,link:ne,styled:le,subscript:ie,superscript:ce,anchor:ge,highlight:ue,textStyle:fe}},de=function(r){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,a=>e[a]):r};class A{constructor(e){S(this,"marks"),S(this,"nodes"),e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let o="";return e.content.forEach(a=>{o+=this.renderNode(a)}),t.optimizeImages?this.optimizeImages(o,t.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
11
+ Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function _(r){const t="virtual:storyblok-options",e="\0"+t;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===t)return e},async load(o){if(o===e)return`export default ${JSON.stringify(r)}`}}}let A=!1;const C=[],z=r=>new Promise((t,e)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}A?s():C.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=s=>e(s),o.onload=s=>{C.forEach(n=>n()),A=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(o)});var U=Object.defineProperty,D=(r,t,e)=>t in r?U(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,p=(r,t,e)=>(D(r,typeof t!="symbol"?t+"":t,e),e);class q{constructor(){p(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),p(this,"getOptionsPage",(t,e=25,o=1)=>({...t,per_page:e,page:o})),p(this,"delay",t=>new Promise(e=>setTimeout(e,t))),p(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),p(this,"range",(t=0,e=t)=>{const o=Math.abs(e-t)||0,s=t<e?1:-1;return this.arrayFrom(o,(n,a)=>a*s+t)}),p(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),p(this,"flatMap",(t=[],e)=>t.map(e).reduce((o,s)=>[...o,...s],[])),p(this,"escapeHTML",function(t){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},o=/[&<>"']/g,s=RegExp(o.source);return t&&s.test(t)?t.replace(o,n=>e[n]):t})}stringify(t,e,o){const s=[];for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const a=t[n],c=o?"":encodeURIComponent(n);let l;typeof a=="object"?l=this.stringify(a,e?e+encodeURIComponent("["+c+"]"):c,Array.isArray(a)):l=(e?e+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(a),s.push(l)}return s.join("&")}getRegionURL(t){const e="api.storyblok.com",o="api-us.storyblok.com",s="app.storyblokchina.cn";switch(t){case"us":return o;case"cn":return s;default:return e}}}const F=function(r,t){const e={};for(const o in r){const s=r[o];t.indexOf(o)>-1&&s!==null&&(e[o]=s)}return e},B=r=>r==="email",J=()=>({singleTag:"hr"}),K=()=>({tag:"blockquote"}),V=()=>({tag:"ul"}),H=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),W=r=>({tag:`h${r.attrs.level}`}),Y=r=>({singleTag:[{tag:"img",attrs:F(r.attrs,["src","alt","title"])}]}),Q=()=>({tag:"li"}),X=()=>({tag:"ol"}),Z=()=>({tag:"p"}),ee=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),te=()=>({tag:"b"}),re=()=>({tag:"strike"}),oe=()=>({tag:"u"}),se=()=>({tag:"strong"}),ne=()=>({tag:"code"}),ae=()=>({tag:"i"}),le=r=>{const t=new q().escapeHTML,e={...r.attrs},{linktype:o="url"}=r.attrs;if(e.href&&(e.href=t(r.attrs.href||"")),B(o)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const s in e.custom)e[s]=e.custom[s];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},ie=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ce=()=>({tag:"sub"}),ue=()=>({tag:"sup"}),ge=r=>({tag:[{tag:"span",attrs:r.attrs}]}),fe=r=>{var t;return(t=r.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},pe=r=>{var t;return(t=r.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},E={nodes:{horizontal_rule:J,blockquote:K,bullet_list:V,code_block:H,hard_break:G,heading:W,image:Y,list_item:Q,ordered_list:X,paragraph:Z,emoji:ee},marks:{bold:te,strike:re,underline:oe,strong:se,code:ne,italic:ae,link:le,styled:ie,subscript:ce,superscript:ue,anchor:ge,highlight:fe,textStyle:pe}},de=function(r){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,o=RegExp(e.source);return r&&o.test(r)?r.replace(e,s=>t[s]):r};class S{constructor(t){p(this,"marks"),p(this,"nodes"),t||(t=E),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let o="";return t.content.forEach(s=>{o+=this.renderNode(s)}),e.optimizeImages?this.optimizeImages(o,e.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
12
12
  The "content" field must be an array of nodes as the type ISbRichtext.
13
13
  ISbRichtext:
14
14
  content?: ISbRichtext[]
@@ -31,14 +31,14 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
31
31
  }
32
32
  ],
33
33
  type: 'doc'
34
- }`),""}optimizeImages(e,t){let o=0,a=0,s="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(s+=`width="${t.width}" `,o=t.width),typeof t.height=="number"&&t.height>0&&(s+=`height="${t.height}" `,a=t.height),(t.loading==="lazy"||t.loading==="eager")&&(s+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(s+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const f=o>0||a>0||n.length>0?`${o}x${a}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${f}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var i,c;const d=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const p={srcset:(i=t.srcset)==null?void 0:i.map(u=>{if(typeof u=="number")return`//${d}/m/${u}x0${n} ${u}w`;if(typeof u=="object"&&u.length===2){let y=0,j=0;return typeof u[0]=="number"&&(y=u[0]),typeof u[1]=="number"&&(j=u[1]),`//${d}/m/${y}x${j}${n} ${y}w`}}).join(", "),sizes:(c=t.sizes)==null?void 0:c.map(u=>u).join(", ")};let m="";return p.srcset&&(m+=`srcset="${p.srcset}" `),p.sizes&&(m+=`sizes="${p.sizes}" `),l.replace(/<img/g,`<img ${m.trim()}`)}return l})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(a=>{const s=this.getMatchingMark(a);s&&s.tag!==""&&t.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&t.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(a=>{t.push(this.renderNode(a))}):e.text?t.push(de(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html?t.push(o.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(a=>{const s=this.getMatchingMark(a);s&&s.tag!==""&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let a=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const n=o.attrs[s];n!==null&&(a+=` ${s}="${n}"`)}return`${a}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}const pe=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let he;const be="https://app.storyblok.com/f/storyblok-v2-latest.js",me=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(a=>{o+=e(a.component,a)}),{html:o}})},ye=r=>!r||!(r!=null&&r.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ke=(r,e,t)=>{let o=t||he;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ye(r)?"":(e&&(o=new A(e.schema),e.resolver&&me(o,e.resolver)),o.render(r))},$e=()=>z(be);function ve(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function Ie(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(r,e,t)}function we(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:o})=>{if(o({vite:{plugins:[h(e.accessToken,e.useCustomApi,e.apiOptions),M(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),P(e)]}}),t("page-ssr",`
34
+ }`),""}optimizeImages(t,e){let o=0,s=0,n="",a="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(n+=`width="${e.width}" `,o=e.width),typeof e.height=="number"&&e.height>0&&(n+=`height="${e.height}" `,s=e.height),(e.loading==="lazy"||e.loading==="eager")&&(n+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(n+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(a+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(a+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||e.filters.fill==="transparent")&&(a+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(a+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(a+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(a+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(a+=`:rotate(${e.filters.rotate})`),a.length>0&&(a="/filters"+a))),n.length>0&&(t=t.replace(/<img/g,`<img ${n.trim()}`));const c=o>0||s>0||a.length>0?`${o}x${s}${a}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var i,u;const d=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const h={srcset:(i=e.srcset)==null?void 0:i.map(f=>{if(typeof f=="number")return`//${d}/m/${f}x0${a} ${f}w`;if(typeof f=="object"&&f.length===2){let k=0,j=0;return typeof f[0]=="number"&&(k=f[0]),typeof f[1]=="number"&&(j=f[1]),`//${d}/m/${k}x${j}${a} ${k}w`}}).join(", "),sizes:(u=e.sizes)==null?void 0:u.map(f=>f).join(", ")};let y="";return h.srcset&&(y+=`srcset="${h.srcset}" `),h.sizes&&(y+=`sizes="${h.sizes}" `),l.replace(/<img/g,`<img ${y.trim()}`)}return l})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(t);return o&&o.tag&&e.push(this.renderOpeningTag(o.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(de(t.text)):o&&o.singleTag?e.push(this.renderTag(o.singleTag," /")):o&&o.html?e.push(o.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),o&&o.tag&&e.push(this.renderClosingTag(o.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(o=>{if(o.constructor===String)return`<${o}${e}>`;{let s=`<${o.tag}`;if(o.attrs)for(const n in o.attrs){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}const he=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const t=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let me;const be="https://app.storyblok.com/f/storyblok-v2-latest.js",ye=(r,t)=>{r.addNode("blok",e=>{let o="";return e.attrs.body.forEach(s=>{o+=t(s.component,s)}),{html:o}})},ke=r=>!r||!(r!=null&&r.content.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule")),$e=(r,t,e)=>{let o=e||me;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(r)?"":(t&&(o=new S(t.schema),t.resolver&&ye(o,t.resolver)),o.render(r))},ve=()=>z(be);function Ie(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function we(r,t){const e=globalThis.storyblokApiInstance.richTextResolver;if(!e){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return $e(r,t,e)}function Te(r){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:o})=>{if(o({vite:{plugins:[m(t.accessToken,t.useCustomApi,t.apiOptions),L(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),_(t)]}}),e("page-ssr",`
35
35
  import { storyblokApiInstance } from "virtual:storyblok-init";
36
36
  globalThis.storyblokApiInstance = storyblokApiInstance;
37
- `),e.bridge){const a={...e.bridge};t("page",`
37
+ `),t.bridge){const s={...t.bridge};e("page",`
38
38
  import { loadStoryblokBridge } from "@storyblok/astro";
39
39
  loadStoryblokBridge().then(() => {
40
40
  const { StoryblokBridge, location } = window;
41
- const storyblokInstance = new StoryblokBridge(${JSON.stringify(a)});
41
+ const storyblokInstance = new StoryblokBridge(${JSON.stringify(s)});
42
42
 
43
43
  storyblokInstance.on(["published", "change"], (event) => {
44
44
  if (!event.slugChanged) {
@@ -46,4 +46,4 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
46
46
  }
47
47
  });
48
48
  });
49
- `)}}}}}g.RichTextResolver=A,g.RichTextSchema=C,g.default=we,g.loadStoryblokBridge=$e,g.renderRichText=Ie,g.storyblokEditable=pe,g.useStoryblokApi=ve,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
49
+ `)}}}}}g.RichTextResolver=S,g.RichTextSchema=E,g.default=Te,g.loadStoryblokBridge=ve,g.renderRichText=we,g.storyblokEditable=he,g.useStoryblokApi=Ie,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,90 +1,90 @@
1
- function x(r, e, t) {
2
- const o = "virtual:storyblok-init", a = "\0" + o;
1
+ function E(r, t, e) {
2
+ const o = "virtual:storyblok-init", s = "\0" + o;
3
3
  return {
4
4
  name: "vite-plugin-storyblok-init",
5
- async resolveId(s) {
6
- if (s === o)
7
- return a;
5
+ async resolveId(a) {
6
+ if (a === o)
7
+ return s;
8
8
  },
9
- async load(s) {
10
- if (s === a)
9
+ async load(a) {
10
+ if (a === s)
11
11
  return `
12
12
  import { storyblokInit, apiPlugin } from "@storyblok/js";
13
13
  const { storyblokApi } = storyblokInit({
14
14
  accessToken: "${r}",
15
- use: ${e ? "[]" : "[apiPlugin]"},
16
- apiOptions: ${JSON.stringify(t)},
15
+ use: ${t ? "[]" : "[apiPlugin]"},
16
+ apiOptions: ${JSON.stringify(e)},
17
17
  });
18
18
  export const storyblokApiInstance = storyblokApi;
19
19
  `;
20
20
  }
21
21
  };
22
22
  }
23
- const T = /[\p{Lu}]/u, S = /[\p{Ll}]/u, y = /^[\p{Lu}](?![\p{Lu}])/gu, C = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, A = new RegExp("^" + b.source), k = new RegExp(b.source + C.source, "gu"), $ = new RegExp("\\d+" + C.source, "gu"), j = (r, e, t, o) => {
24
- let a = !1, s = !1, n = !1, u = !1;
23
+ const T = /[\p{Lu}]/u, x = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, A = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, S = new RegExp("^" + b.source), $ = new RegExp(b.source + A.source, "gu"), v = new RegExp("\\d+" + A.source, "gu"), R = (r, t, e, o) => {
24
+ let s = !1, a = !1, n = !1, c = !1;
25
25
  for (let l = 0; l < r.length; l++) {
26
26
  const i = r[l];
27
- u = l > 2 ? r[l - 3] === "-" : !0, a && T.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), a = !1, n = s, s = !0, l++) : s && n && S.test(i) && (!u || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = s, s = !1, a = !0) : (a = e(i) === i && t(i) !== i, n = s, s = t(i) === i && e(i) !== i);
27
+ c = l > 2 ? r[l - 3] === "-" : !0, s && T.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), s = !1, n = a, a = !0, l++) : a && n && x.test(i) && (!c || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = a, a = !1, s = !0) : (s = t(i) === i && e(i) !== i, n = a, a = e(i) === i && t(i) !== i);
28
28
  }
29
29
  return r;
30
- }, R = (r, e) => (y.lastIndex = 0, r.replace(y, (t) => e(t))), O = (r, e) => (k.lastIndex = 0, $.lastIndex = 0, r.replace(k, (t, o) => e(o)).replace($, (t) => e(t)));
31
- function v(r, e) {
30
+ }, j = (r, t) => (k.lastIndex = 0, r.replaceAll(k, (e) => t(e))), O = (r, t) => ($.lastIndex = 0, v.lastIndex = 0, r.replaceAll(v, (e, o, s) => ["_", "-"].includes(r.charAt(s + e.length)) ? e : t(e)).replaceAll($, (e, o) => t(o)));
31
+ function I(r, t) {
32
32
  if (!(typeof r == "string" || Array.isArray(r)))
33
33
  throw new TypeError("Expected the input to be `string | string[]`");
34
- if (e = {
34
+ if (t = {
35
35
  pascalCase: !1,
36
36
  preserveConsecutiveUppercase: !1,
37
- ...e
38
- }, Array.isArray(r) ? r = r.map((s) => s.trim()).filter((s) => s.length).join("-") : r = r.trim(), r.length === 0)
37
+ ...t
38
+ }, Array.isArray(r) ? r = r.map((a) => a.trim()).filter((a) => a.length).join("-") : r = r.trim(), r.length === 0)
39
39
  return "";
40
- const t = e.locale === !1 ? (s) => s.toLowerCase() : (s) => s.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (s) => s.toUpperCase() : (s) => s.toLocaleUpperCase(e.locale);
41
- return r.length === 1 ? b.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = j(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(A, ""), r = e.preserveConsecutiveUppercase ? R(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
40
+ const e = t.locale === !1 ? (a) => a.toLowerCase() : (a) => a.toLocaleLowerCase(t.locale), o = t.locale === !1 ? (a) => a.toUpperCase() : (a) => a.toLocaleUpperCase(t.locale);
41
+ return r.length === 1 ? b.test(r) ? "" : t.pascalCase ? o(r) : e(r) : (r !== e(r) && (r = R(r, e, o, t.preserveConsecutiveUppercase)), r = r.replace(S, ""), r = t.preserveConsecutiveUppercase ? j(r, e) : e(r), t.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
42
42
  }
43
- function N(r, e, t, o) {
44
- const a = "virtual:storyblok-components", s = "\0" + a;
43
+ function N(r, t, e, o) {
44
+ const s = "virtual:storyblok-components", a = "\0" + s;
45
45
  return {
46
46
  name: "vite-plugin-storyblok-components",
47
47
  async resolveId(n) {
48
- if (n === a)
49
- return s;
48
+ if (n === s)
49
+ return a;
50
50
  },
51
51
  async load(n) {
52
- if (n === s) {
53
- const u = [], l = [];
54
- for await (const [c, f] of Object.entries(e)) {
52
+ if (n === a) {
53
+ const c = [], l = [];
54
+ for await (const [g, f] of Object.entries(t)) {
55
55
  const d = await this.resolve(
56
56
  "/" + r + "/" + f + ".astro"
57
57
  );
58
58
  if (d)
59
- u.push(`import ${v(c)} from "${d.id}"`);
60
- else if (t)
61
- l.push(c);
59
+ c.push(`import ${I(g)} from "${d.id}"`);
60
+ else if (e)
61
+ l.push(g);
62
62
  else
63
63
  throw new Error(
64
- `Component could not be found for blok "${c}"! Does "${"/" + r + "/" + f}.astro" exist?`
64
+ `Component could not be found for blok "${g}"! Does "${"/" + r + "/" + f}.astro" exist?`
65
65
  );
66
66
  }
67
67
  let i = "";
68
- if (t)
68
+ if (e)
69
69
  if (i = ",FallbackComponent", o) {
70
- const c = await this.resolve(
70
+ const g = await this.resolve(
71
71
  "/" + r + "/" + o + ".astro"
72
72
  );
73
- if (!c)
73
+ if (!g)
74
74
  throw new Error(
75
75
  `Custom fallback component could not be found. Does "${"/" + r + "/" + o}.astro" exist?`
76
76
  );
77
- u.push(
78
- `import FallbackComponent from "${c.id}"`
77
+ c.push(
78
+ `import FallbackComponent from "${g.id}"`
79
79
  );
80
80
  } else
81
- u.push(
81
+ c.push(
82
82
  "import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
83
83
  );
84
- if (Object.values(e).length)
85
- return `${u.join(";")};export default {${Object.keys(e).filter((c) => !l.includes(c)).map((c) => v(c)).join(",")}${i}}`;
86
- if (t)
87
- return `${u[0]}; export default {${i.replace(",", "")}}`;
84
+ if (Object.values(t).length)
85
+ return `${c.join(";")};export default {${Object.keys(t).filter((g) => !l.includes(g)).map((g) => I(g)).join(",")}${i}}`;
86
+ if (e)
87
+ return `${c[0]}; export default {${i.replace(",", "")}}`;
88
88
  throw new Error(
89
89
  `Currently, no Storyblok components are registered in astro.config.mjs.
90
90
  Please register your components or enable the fallback component.
@@ -95,49 +95,108 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
95
95
  };
96
96
  }
97
97
  function L(r) {
98
- const e = "virtual:storyblok-options", t = "\0" + e;
98
+ const t = "virtual:storyblok-options", e = "\0" + t;
99
99
  return {
100
100
  name: "vite-plugin-storyblok-options",
101
101
  async resolveId(o) {
102
- if (o === e)
103
- return t;
102
+ if (o === t)
103
+ return e;
104
104
  },
105
105
  async load(o) {
106
- if (o === t)
106
+ if (o === e)
107
107
  return `export default ${JSON.stringify(r)}`;
108
108
  }
109
109
  };
110
110
  }
111
- let I = !1;
112
- const w = [], z = (r) => new Promise((e, t) => {
113
- if (typeof window > "u" || (window.storyblokRegisterEvent = (a) => {
111
+ let w = !1;
112
+ const C = [], M = (r) => new Promise((t, e) => {
113
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
114
114
  if (window.location === window.parent.location) {
115
115
  console.warn("You are not in Draft Mode or in the Visual Editor.");
116
116
  return;
117
117
  }
118
- I ? a() : w.push(a);
118
+ w ? s() : C.push(s);
119
119
  }, document.getElementById("storyblok-javascript-bridge")))
120
120
  return;
121
121
  const o = document.createElement("script");
122
- o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (a) => t(a), o.onload = (a) => {
123
- w.forEach((s) => s()), I = !0, e(a);
122
+ o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => e(s), o.onload = (s) => {
123
+ C.forEach((a) => a()), w = !0, t(s);
124
124
  }, document.getElementsByTagName("head")[0].appendChild(o);
125
125
  });
126
- var P = Object.defineProperty, _ = (r, e, t) => e in r ? P(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, E = (r, e, t) => (_(r, typeof e != "symbol" ? e + "" : e, t), t);
127
- const M = function(r, e) {
128
- const t = {};
126
+ var P = Object.defineProperty, _ = (r, t, e) => t in r ? P(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, p = (r, t, e) => (_(r, typeof t != "symbol" ? t + "" : t, e), e);
127
+ class z {
128
+ constructor() {
129
+ p(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), p(this, "getOptionsPage", (t, e = 25, o = 1) => ({
130
+ ...t,
131
+ per_page: e,
132
+ page: o
133
+ })), p(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), p(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), p(this, "range", (t = 0, e = t) => {
134
+ const o = Math.abs(e - t) || 0, s = t < e ? 1 : -1;
135
+ return this.arrayFrom(o, (a, n) => n * s + t);
136
+ }), p(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), p(this, "flatMap", (t = [], e) => t.map(e).reduce((o, s) => [...o, ...s], [])), p(this, "escapeHTML", function(t) {
137
+ const e = {
138
+ "&": "&amp;",
139
+ "<": "&lt;",
140
+ ">": "&gt;",
141
+ '"': "&quot;",
142
+ "'": "&#39;"
143
+ }, o = /[&<>"']/g, s = RegExp(o.source);
144
+ return t && s.test(t) ? t.replace(o, (a) => e[a]) : t;
145
+ });
146
+ }
147
+ /**
148
+ * @method stringify
149
+ * @param {Object} params
150
+ * @param {String} prefix
151
+ * @param {Boolean} isArray
152
+ * @return {String} Stringified object
153
+ */
154
+ stringify(t, e, o) {
155
+ const s = [];
156
+ for (const a in t) {
157
+ if (!Object.prototype.hasOwnProperty.call(t, a))
158
+ continue;
159
+ const n = t[a], c = o ? "" : encodeURIComponent(a);
160
+ let l;
161
+ typeof n == "object" ? l = this.stringify(
162
+ n,
163
+ e ? e + encodeURIComponent("[" + c + "]") : c,
164
+ Array.isArray(n)
165
+ ) : l = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), s.push(l);
166
+ }
167
+ return s.join("&");
168
+ }
169
+ /**
170
+ * @method getRegionURL
171
+ * @param {String} regionCode region code, could be eu, us or cn
172
+ * @return {String} The base URL of the region
173
+ */
174
+ getRegionURL(t) {
175
+ const e = "api.storyblok.com", o = "api-us.storyblok.com", s = "app.storyblokchina.cn";
176
+ switch (t) {
177
+ case "us":
178
+ return o;
179
+ case "cn":
180
+ return s;
181
+ default:
182
+ return e;
183
+ }
184
+ }
185
+ }
186
+ const U = function(r, t) {
187
+ const e = {};
129
188
  for (const o in r) {
130
- const a = r[o];
131
- e.indexOf(o) > -1 && a !== null && (t[o] = a);
189
+ const s = r[o];
190
+ t.indexOf(o) > -1 && s !== null && (e[o] = s);
132
191
  }
133
- return t;
134
- }, D = (r) => r === "email", U = () => ({
192
+ return e;
193
+ }, D = (r) => r === "email", q = () => ({
135
194
  singleTag: "hr"
136
- }), q = () => ({
195
+ }), F = () => ({
137
196
  tag: "blockquote"
138
197
  }), B = () => ({
139
198
  tag: "ul"
140
- }), F = (r) => ({
199
+ }), J = (r) => ({
141
200
  tag: [
142
201
  "pre",
143
202
  {
@@ -145,15 +204,15 @@ const M = function(r, e) {
145
204
  attrs: r.attrs
146
205
  }
147
206
  ]
148
- }), J = () => ({
207
+ }), K = () => ({
149
208
  singleTag: "br"
150
- }), K = (r) => ({
151
- tag: `h${r.attrs.level}`
152
209
  }), V = (r) => ({
210
+ tag: `h${r.attrs.level}`
211
+ }), H = (r) => ({
153
212
  singleTag: [
154
213
  {
155
214
  tag: "img",
156
- attrs: M(r.attrs, ["src", "alt", "title"])
215
+ attrs: U(r.attrs, ["src", "alt", "title"])
157
216
  }
158
217
  ]
159
218
  }), G = () => ({
@@ -162,7 +221,7 @@ const M = function(r, e) {
162
221
  tag: "ol"
163
222
  }), Y = () => ({
164
223
  tag: "p"
165
- }), H = (r) => ({
224
+ }), Q = (r) => ({
166
225
  tag: [
167
226
  {
168
227
  tag: "span",
@@ -173,23 +232,23 @@ const M = function(r, e) {
173
232
  }
174
233
  }
175
234
  ]
176
- }), Q = () => ({
177
- tag: "b"
178
235
  }), X = () => ({
179
- tag: "strike"
236
+ tag: "b"
180
237
  }), Z = () => ({
181
- tag: "u"
238
+ tag: "strike"
182
239
  }), ee = () => ({
183
- tag: "strong"
240
+ tag: "u"
184
241
  }), te = () => ({
185
- tag: "code"
242
+ tag: "strong"
186
243
  }), re = () => ({
244
+ tag: "code"
245
+ }), oe = () => ({
187
246
  tag: "i"
188
- }), oe = (r) => {
189
- const e = { ...r.attrs }, { linktype: t = "url" } = r.attrs;
190
- if (D(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
191
- for (const o in e.custom)
192
- e[o] = e.custom[o];
247
+ }), se = (r) => {
248
+ const t = new z().escapeHTML, e = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
249
+ if (e.href && (e.href = t(r.attrs.href || "")), D(o) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
250
+ for (const s in e.custom)
251
+ e[s] = e.custom[s];
193
252
  delete e.custom;
194
253
  }
195
254
  return {
@@ -200,27 +259,27 @@ const M = function(r, e) {
200
259
  }
201
260
  ]
202
261
  };
203
- }, se = (r) => ({
262
+ }, ae = (r) => ({
204
263
  tag: [
205
264
  {
206
265
  tag: "span",
207
266
  attrs: r.attrs
208
267
  }
209
268
  ]
210
- }), ae = () => ({
211
- tag: "sub"
212
269
  }), ne = () => ({
270
+ tag: "sub"
271
+ }), le = () => ({
213
272
  tag: "sup"
214
- }), le = (r) => ({
273
+ }), ie = (r) => ({
215
274
  tag: [
216
275
  {
217
276
  tag: "span",
218
277
  attrs: r.attrs
219
278
  }
220
279
  ]
221
- }), ie = (r) => {
222
- var e;
223
- return (e = r.attrs) != null && e.color ? {
280
+ }), ce = (r) => {
281
+ var t;
282
+ return (t = r.attrs) != null && t.color ? {
224
283
  tag: [
225
284
  {
226
285
  tag: "span",
@@ -232,9 +291,9 @@ const M = function(r, e) {
232
291
  } : {
233
292
  tag: ""
234
293
  };
235
- }, ce = (r) => {
236
- var e;
237
- return (e = r.attrs) != null && e.color ? {
294
+ }, ge = (r) => {
295
+ var t;
296
+ return (t = r.attrs) != null && t.color ? {
238
297
  tag: [
239
298
  {
240
299
  tag: "span",
@@ -246,61 +305,61 @@ const M = function(r, e) {
246
305
  } : {
247
306
  tag: ""
248
307
  };
249
- }, ge = {
308
+ }, ue = {
250
309
  nodes: {
251
- horizontal_rule: U,
252
- blockquote: q,
310
+ horizontal_rule: q,
311
+ blockquote: F,
253
312
  bullet_list: B,
254
- code_block: F,
255
- hard_break: J,
256
- heading: K,
257
- image: V,
313
+ code_block: J,
314
+ hard_break: K,
315
+ heading: V,
316
+ image: H,
258
317
  list_item: G,
259
318
  ordered_list: W,
260
319
  paragraph: Y,
261
- emoji: H
320
+ emoji: Q
262
321
  },
263
322
  marks: {
264
- bold: Q,
265
- strike: X,
266
- underline: Z,
267
- strong: ee,
268
- code: te,
269
- italic: re,
270
- link: oe,
271
- styled: se,
272
- subscript: ae,
273
- superscript: ne,
274
- anchor: le,
275
- highlight: ie,
276
- textStyle: ce
323
+ bold: X,
324
+ strike: Z,
325
+ underline: ee,
326
+ strong: te,
327
+ code: re,
328
+ italic: oe,
329
+ link: se,
330
+ styled: ae,
331
+ subscript: ne,
332
+ superscript: le,
333
+ anchor: ie,
334
+ highlight: ce,
335
+ textStyle: ge
277
336
  }
278
- }, ue = function(r) {
279
- const e = {
337
+ }, pe = function(r) {
338
+ const t = {
280
339
  "&": "&amp;",
281
340
  "<": "&lt;",
282
341
  ">": "&gt;",
283
342
  '"': "&quot;",
284
343
  "'": "&#39;"
285
- }, t = /[&<>"']/g, o = RegExp(t.source);
286
- return r && o.test(r) ? r.replace(t, (a) => e[a]) : r;
344
+ }, e = /[&<>"']/g, o = RegExp(e.source);
345
+ return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
287
346
  };
288
347
  class fe {
289
- constructor(e) {
290
- E(this, "marks"), E(this, "nodes"), e || (e = ge), this.marks = e.marks || [], this.nodes = e.nodes || [];
348
+ constructor(t) {
349
+ p(this, "marks"), p(this, "nodes"), t || (t = ue), this.marks = t.marks || [], this.nodes = t.nodes || [];
291
350
  }
292
- addNode(e, t) {
293
- this.nodes[e] = t;
351
+ addNode(t, e) {
352
+ this.nodes[t] = e;
294
353
  }
295
- addMark(e, t) {
296
- this.marks[e] = t;
354
+ addMark(t, e) {
355
+ this.marks[t] = e;
297
356
  }
298
- render(e, t = { optimizeImages: !1 }) {
299
- if (e && e.content && Array.isArray(e.content)) {
357
+ render(t, e = { optimizeImages: !1 }) {
358
+ if (t && t.content && Array.isArray(t.content)) {
300
359
  let o = "";
301
- return e.content.forEach((a) => {
302
- o += this.renderNode(a);
303
- }), t.optimizeImages ? this.optimizeImages(o, t.optimizeImages) : o;
360
+ return t.content.forEach((s) => {
361
+ o += this.renderNode(s);
362
+ }), e.optimizeImages ? this.optimizeImages(o, e.optimizeImages) : o;
304
363
  }
305
364
  return console.warn(
306
365
  `The render method must receive an Object with a "content" field.
@@ -329,144 +388,144 @@ class fe {
329
388
  }`
330
389
  ), "";
331
390
  }
332
- optimizeImages(e, t) {
333
- let o = 0, a = 0, s = "", n = "";
334
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (s += `width="${t.width}" `, o = t.width), typeof t.height == "number" && t.height > 0 && (s += `height="${t.height}" `, a = t.height), (t.loading === "lazy" || t.loading === "eager") && (s += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (s += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), s.length > 0 && (e = e.replace(/<img/g, `<img ${s.trim()}`));
335
- const u = o > 0 || a > 0 || n.length > 0 ? `${o}x${a}${n}` : "";
336
- return e = e.replace(
391
+ optimizeImages(t, e) {
392
+ let o = 0, s = 0, a = "", n = "";
393
+ typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (a += `width="${e.width}" `, o = e.width), typeof e.height == "number" && e.height > 0 && (a += `height="${e.height}" `, s = e.height), (e.loading === "lazy" || e.loading === "eager") && (a += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (a += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (n += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (n += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-Fa-f]{6}/g) || e.filters.fill === "transparent") && (n += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (n += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (n += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (n += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (n += `:rotate(${e.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), a.length > 0 && (t = t.replace(/<img/g, `<img ${a.trim()}`));
394
+ const c = o > 0 || s > 0 || n.length > 0 ? `${o}x${s}${n}` : "";
395
+ return t = t.replace(
337
396
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
338
- `a.storyblok.com/f/$1/$2.$3/m/${u}`
339
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
340
- var i, c;
397
+ `a.storyblok.com/f/$1/$2.$3/m/${c}`
398
+ ), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
399
+ var i, g;
341
400
  const f = l.match(
342
401
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
343
402
  );
344
403
  if (f && f.length > 0) {
345
404
  const d = {
346
- srcset: (i = t.srcset) == null ? void 0 : i.map((g) => {
347
- if (typeof g == "number")
348
- return `//${f}/m/${g}x0${n} ${g}w`;
349
- if (typeof g == "object" && g.length === 2) {
350
- let h = 0, m = 0;
351
- return typeof g[0] == "number" && (h = g[0]), typeof g[1] == "number" && (m = g[1]), `//${f}/m/${h}x${m}${n} ${h}w`;
405
+ srcset: (i = e.srcset) == null ? void 0 : i.map((u) => {
406
+ if (typeof u == "number")
407
+ return `//${f}/m/${u}x0${n} ${u}w`;
408
+ if (typeof u == "object" && u.length === 2) {
409
+ let m = 0, y = 0;
410
+ return typeof u[0] == "number" && (m = u[0]), typeof u[1] == "number" && (y = u[1]), `//${f}/m/${m}x${y}${n} ${m}w`;
352
411
  }
353
412
  }).join(", "),
354
- sizes: (c = t.sizes) == null ? void 0 : c.map((g) => g).join(", ")
413
+ sizes: (g = e.sizes) == null ? void 0 : g.map((u) => u).join(", ")
355
414
  };
356
- let p = "";
357
- return d.srcset && (p += `srcset="${d.srcset}" `), d.sizes && (p += `sizes="${d.sizes}" `), l.replace(/<img/g, `<img ${p.trim()}`);
415
+ let h = "";
416
+ return d.srcset && (h += `srcset="${d.srcset}" `), d.sizes && (h += `sizes="${d.sizes}" `), l.replace(/<img/g, `<img ${h.trim()}`);
358
417
  }
359
418
  return l;
360
- })), e;
419
+ })), t;
361
420
  }
362
- renderNode(e) {
363
- const t = [];
364
- e.marks && e.marks.forEach((a) => {
365
- const s = this.getMatchingMark(a);
366
- s && s.tag !== "" && t.push(this.renderOpeningTag(s.tag));
421
+ renderNode(t) {
422
+ const e = [];
423
+ t.marks && t.marks.forEach((s) => {
424
+ const a = this.getMatchingMark(s);
425
+ a && a.tag !== "" && e.push(this.renderOpeningTag(a.tag));
367
426
  });
368
- const o = this.getMatchingNode(e);
369
- return o && o.tag && t.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((a) => {
370
- t.push(this.renderNode(a));
371
- }) : e.text ? t.push(ue(e.text)) : o && o.singleTag ? t.push(this.renderTag(o.singleTag, " /")) : o && o.html ? t.push(o.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), o && o.tag && t.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((a) => {
372
- const s = this.getMatchingMark(a);
373
- s && s.tag !== "" && t.push(this.renderClosingTag(s.tag));
374
- }), t.join("");
427
+ const o = this.getMatchingNode(t);
428
+ return o && o.tag && e.push(this.renderOpeningTag(o.tag)), t.content ? t.content.forEach((s) => {
429
+ e.push(this.renderNode(s));
430
+ }) : t.text ? e.push(pe(t.text)) : o && o.singleTag ? e.push(this.renderTag(o.singleTag, " /")) : o && o.html ? e.push(o.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), o && o.tag && e.push(this.renderClosingTag(o.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
431
+ const a = this.getMatchingMark(s);
432
+ a && a.tag !== "" && e.push(this.renderClosingTag(a.tag));
433
+ }), e.join("");
375
434
  }
376
- renderTag(e, t) {
377
- return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
435
+ renderTag(t, e) {
436
+ return t.constructor === String ? `<${t}${e}>` : t.map((o) => {
378
437
  if (o.constructor === String)
379
- return `<${o}${t}>`;
438
+ return `<${o}${e}>`;
380
439
  {
381
- let a = `<${o.tag}`;
440
+ let s = `<${o.tag}`;
382
441
  if (o.attrs)
383
- for (const s in o.attrs) {
384
- const n = o.attrs[s];
385
- n !== null && (a += ` ${s}="${n}"`);
442
+ for (const a in o.attrs) {
443
+ const n = o.attrs[a];
444
+ n !== null && (s += ` ${a}="${n}"`);
386
445
  }
387
- return `${a}${t}>`;
446
+ return `${s}${e}>`;
388
447
  }
389
448
  }).join("");
390
449
  }
391
- renderOpeningTag(e) {
392
- return this.renderTag(e, "");
450
+ renderOpeningTag(t) {
451
+ return this.renderTag(t, "");
393
452
  }
394
- renderClosingTag(e) {
395
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
453
+ renderClosingTag(t) {
454
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
396
455
  }
397
- getMatchingNode(e) {
398
- const t = this.nodes[e.type];
399
- if (typeof t == "function")
400
- return t(e);
456
+ getMatchingNode(t) {
457
+ const e = this.nodes[t.type];
458
+ if (typeof e == "function")
459
+ return e(t);
401
460
  }
402
- getMatchingMark(e) {
403
- const t = this.marks[e.type];
404
- if (typeof t == "function")
405
- return t(e);
461
+ getMatchingMark(t) {
462
+ const e = this.marks[t.type];
463
+ if (typeof e == "function")
464
+ return e(t);
406
465
  }
407
- renderEmoji(e) {
408
- if (e.attrs.emoji)
409
- return e.attrs.emoji;
410
- const t = [
466
+ renderEmoji(t) {
467
+ if (t.attrs.emoji)
468
+ return t.attrs.emoji;
469
+ const e = [
411
470
  {
412
471
  tag: "img",
413
472
  attrs: {
414
- src: e.attrs.fallbackImage,
473
+ src: t.attrs.fallbackImage,
415
474
  draggable: "false",
416
475
  loading: "lazy",
417
476
  align: "absmiddle"
418
477
  }
419
478
  }
420
479
  ];
421
- return this.renderTag(t, " /");
480
+ return this.renderTag(e, " /");
422
481
  }
423
482
  }
424
- const ye = (r) => {
483
+ const ke = (r) => {
425
484
  if (typeof r != "object" || typeof r._editable > "u")
426
485
  return {};
427
- const e = JSON.parse(
486
+ const t = JSON.parse(
428
487
  r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
429
488
  );
430
489
  return {
431
- "data-blok-c": JSON.stringify(e),
432
- "data-blok-uid": e.id + "-" + e.uid
490
+ "data-blok-c": JSON.stringify(t),
491
+ "data-blok-uid": t.id + "-" + t.uid
433
492
  };
434
493
  };
435
494
  let de;
436
- const pe = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) => {
437
- r.addNode("blok", (t) => {
495
+ const he = "https://app.storyblok.com/f/storyblok-v2-latest.js", me = (r, t) => {
496
+ r.addNode("blok", (e) => {
438
497
  let o = "";
439
- return t.attrs.body.forEach((a) => {
440
- o += e(a.component, a);
498
+ return e.attrs.body.forEach((s) => {
499
+ o += t(s.component, s);
441
500
  }), {
442
501
  html: o
443
502
  };
444
503
  });
445
- }, be = (r) => !r || !(r != null && r.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), me = (r, e, t) => {
446
- let o = t || de;
504
+ }, be = (r) => !r || !(r != null && r.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), ye = (r, t, e) => {
505
+ let o = e || de;
447
506
  if (!o) {
448
507
  console.error(
449
508
  "Please initialize the Storyblok SDK before calling the renderRichText function"
450
509
  );
451
510
  return;
452
511
  }
453
- return be(r) ? "" : (e && (o = new fe(e.schema), e.resolver && he(o, e.resolver)), o.render(r));
454
- }, ke = () => z(pe);
455
- function $e() {
512
+ return be(r) ? "" : (t && (o = new fe(t.schema), t.resolver && me(o, t.resolver)), o.render(r));
513
+ }, $e = () => M(he);
514
+ function ve() {
456
515
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
457
516
  }
458
- function ve(r, e) {
459
- const t = globalThis.storyblokApiInstance.richTextResolver;
460
- if (!t) {
517
+ function Ie(r, t) {
518
+ const e = globalThis.storyblokApiInstance.richTextResolver;
519
+ if (!e) {
461
520
  console.error(
462
521
  "Please initialize the Storyblok SDK before calling the renderRichText function"
463
522
  );
464
523
  return;
465
524
  }
466
- return me(r, e, t);
525
+ return ye(r, t, e);
467
526
  }
468
- function Ie(r) {
469
- const e = {
527
+ function we(r) {
528
+ const t = {
470
529
  useCustomApi: !1,
471
530
  bridge: !0,
472
531
  componentsDir: "src",
@@ -476,40 +535,40 @@ function Ie(r) {
476
535
  return {
477
536
  name: "@storyblok/astro",
478
537
  hooks: {
479
- "astro:config:setup": ({ injectScript: t, updateConfig: o }) => {
538
+ "astro:config:setup": ({ injectScript: e, updateConfig: o }) => {
480
539
  if (o({
481
540
  vite: {
482
541
  plugins: [
483
- x(
484
- e.accessToken,
485
- e.useCustomApi,
486
- e.apiOptions
542
+ E(
543
+ t.accessToken,
544
+ t.useCustomApi,
545
+ t.apiOptions
487
546
  ),
488
547
  N(
489
- e.componentsDir,
490
- e.components,
491
- e.enableFallbackComponent,
492
- e.customFallbackComponent
548
+ t.componentsDir,
549
+ t.components,
550
+ t.enableFallbackComponent,
551
+ t.customFallbackComponent
493
552
  ),
494
- L(e)
553
+ L(t)
495
554
  ]
496
555
  }
497
- }), t(
556
+ }), e(
498
557
  "page-ssr",
499
558
  `
500
559
  import { storyblokApiInstance } from "virtual:storyblok-init";
501
560
  globalThis.storyblokApiInstance = storyblokApiInstance;
502
561
  `
503
- ), e.bridge) {
504
- const a = { ...e.bridge };
505
- t(
562
+ ), t.bridge) {
563
+ const s = { ...t.bridge };
564
+ e(
506
565
  "page",
507
566
  `
508
567
  import { loadStoryblokBridge } from "@storyblok/astro";
509
568
  loadStoryblokBridge().then(() => {
510
569
  const { StoryblokBridge, location } = window;
511
570
  const storyblokInstance = new StoryblokBridge(${JSON.stringify(
512
- a
571
+ s
513
572
  )});
514
573
 
515
574
  storyblokInstance.on(["published", "change"], (event) => {
@@ -527,10 +586,10 @@ function Ie(r) {
527
586
  }
528
587
  export {
529
588
  fe as RichTextResolver,
530
- ge as RichTextSchema,
531
- Ie as default,
532
- ke as loadStoryblokBridge,
533
- ve as renderRichText,
534
- ye as storyblokEditable,
535
- $e as useStoryblokApi
589
+ ue as RichTextSchema,
590
+ we as default,
591
+ $e as loadStoryblokBridge,
592
+ Ie as renderRichText,
593
+ ke as storyblokEditable,
594
+ ve as useStoryblokApi
536
595
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "2.5.7",
3
+ "version": "2.5.9",
4
4
  "description": "Official Astro integration for the Storyblok Headless CMS",
5
5
  "main": "./dist/storyblok-astro.js",
6
6
  "module": "./dist/storyblok-astro.mjs",
@@ -33,20 +33,20 @@
33
33
  "prepublishOnly": "npm run build && cp ../README.md ./"
34
34
  },
35
35
  "dependencies": {
36
- "@storyblok/js": "^2.2.7",
37
- "camelcase": "^7.0.1"
36
+ "@storyblok/js": "^2.2.8",
37
+ "camelcase": "^8.0.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@cypress/vite-dev-server": "^5.0.5",
41
41
  "@rollup/plugin-dynamic-import-vars": "^2.0.4",
42
- "@types/node": "20.4.2",
43
- "astro": "2.9.7",
42
+ "@types/node": "20.4.9",
43
+ "astro": "2.10.4",
44
44
  "cypress": "^12.17.3",
45
- "eslint-plugin-cypress": "^2.13.3",
45
+ "eslint-plugin-cypress": "^2.14.0",
46
46
  "start-server-and-test": "^2.0.0",
47
47
  "typescript": "5.1.6",
48
- "vite": "^4.4.8",
49
- "vite-plugin-dts": "^3.4.0"
48
+ "vite": "^4.4.9",
49
+ "vite-plugin-dts": "^3.5.1"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",