@storyblok/astro 2.0.14 → 2.0.16

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/README.md CHANGED
@@ -63,7 +63,7 @@ export default defineConfig({
63
63
 
64
64
  ### Options
65
65
 
66
- When you initialize the integration, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api). For spaces created in the United States, you have to set the `region` parameter accordingly `{ apiOptions: { region: 'us' } }`.
66
+ When you initialize the integration, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api).
67
67
 
68
68
  ```js
69
69
  // Defaults
@@ -71,12 +71,31 @@ storyblok({
71
71
  accessToken: "<your-access-token>",
72
72
  bridge: true,
73
73
  apiOptions: {}, // storyblok-js-client options
74
+ components: {},
74
75
  useCustomApi: false,
75
76
  });
76
77
  ```
77
78
 
78
79
  > Note: By default, the apiPlugin from `@storyblok/js` is loaded. If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
79
80
 
81
+ #### Region parameter
82
+ Possible values:
83
+ - `eu` (default): For spaces created in the EU
84
+ - `us`: For spaces created in the US
85
+ - `cn`: For spaces created in China
86
+
87
+ Full example for a space created in the US:
88
+ ```js
89
+ storyblok({
90
+ accessToken: "<your-access-token>",
91
+ apiOptions: {
92
+ region: 'us'
93
+ },
94
+ });
95
+ ```
96
+
97
+ > Note: For spaces created in the United States or China, the `region` parameter **must** be specified.
98
+
80
99
  ## Getting started
81
100
 
82
101
  ### 1. Creating and linking your components to the Storyblok Visual Editor
@@ -262,6 +281,9 @@ const renderedRichText = renderRichText(blok.text, {
262
281
 
263
282
  Returns the instance of the `storyblok-js-client`.
264
283
 
284
+ ## The Storyblok JavaScript SDK Ecosystem
285
+ ![A visual representation of the Storyblok JavaScript SDK Ecosystem](https://a.storyblok.com/f/88751/2400x1350/be4a4a4180/sdk-ecosystem.png/m/1200x0)
286
+
265
287
  ## Acknowledgements
266
288
 
267
289
  A huge thank you goes to the Astro Team. In particular to [Tony Sullivan](https://github.com/tony-sull), who has provided extraordinary support and made _automagically_ rendering Storyblok components a reality.
@@ -1,17 +1,17 @@
1
- (function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(a=typeof globalThis<"u"?globalThis:a||self,d(a.storyblokAstro={}))})(this,function(a){"use strict";function d(t,e,r){const o="virtual:storyblok-init",n="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return n},async load(s){if(s===n)return`
1
+ (function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c.storyblokAstro={}))})(this,function(c){"use strict";function f(r,e,t){const s="virtual:storyblok-init",a="\0"+s;return{name:"vite-plugin-storyblok-init",async resolveId(o){if(o===s)return a},async load(o){if(o===a)return`
2
2
  import { storyblokInit, apiPlugin } from "@storyblok/js";
3
3
  const { storyblokApi } = storyblokInit({
4
- accessToken: "${t}",
4
+ accessToken: "${r}",
5
5
  use: ${e?"[]":"[apiPlugin]"},
6
- apiOptions: ${JSON.stringify(r)},
6
+ apiOptions: ${JSON.stringify(t)},
7
7
  });
8
8
  export const storyblokApiInstance = storyblokApi;
9
- `}}}const A=/[\p{Lu}]/u,E=/[\p{Ll}]/u,h=/^[\p{Lu}](?![\p{Lu}])/gu,f=/([\p{Alpha}\p{N}_]|$)/u,g=/[_.\- ]+/,w=new RegExp("^"+g.source),p=new RegExp(g.source+f.source,"gu"),b=new RegExp("\\d+"+f.source,"gu"),C=(t,e,r,o)=>{let n=!1,s=!1,i=!1,u=!1;for(let l=0;l<t.length;l++){const c=t[l];u=l>2?t[l-3]==="-":!0,n&&A.test(c)?(t=t.slice(0,l)+"-"+t.slice(l),n=!1,i=s,s=!0,l++):s&&i&&E.test(c)&&(!u||o)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),i=s,s=!1,n=!0):(n=e(c)===c&&r(c)!==c,i=s,s=r(c)===c&&e(c)!==c)}return t},S=(t,e)=>(h.lastIndex=0,t.replace(h,r=>e(r))),$=(t,e)=>(p.lastIndex=0,b.lastIndex=0,t.replace(p,(r,o)=>e(o)).replace(b,r=>e(r)));function y(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(s=>s.trim()).filter(s=>s.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return t.length===1?g.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=C(t,r,o,e.preserveConsecutiveUppercase)),t=t.replace(w,""),t=e.preserveConsecutiveUppercase?S(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),$(t,o))}function R(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const n=[];for await(const[s,i]of Object.entries(t)){const u=await this.resolve("/src/"+i+".astro");if(!u)throw new Error(`Component could not be found for blok "${s}"! Does "/src/${i}.astro" exist?`);n.push(`import ${y(s)} from "${u.id}"`)}return`${n.join(";")};export default {${Object.keys(t).map(s=>y(s)).join(",")}}`}}}}let k=!1;const m=[],x=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=n=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}k?n():m.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=n=>r(n),o.onload=n=>{m.forEach(s=>s()),k=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,j=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(j(t,typeof e!="symbol"?e+"":e,r),r);const L=function(t,e){const r={};for(const o in t){const n=t[o];e.indexOf(o)>-1&&n!==null&&(r[o]=n)}return r},_=t=>t==="email",O=()=>({singleTag:"hr"}),M=()=>({tag:"blockquote"}),P=()=>({tag:"ul"}),D=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),U=()=>({singleTag:"br"}),B=t=>({tag:`h${t.attrs.level}`}),z=t=>({singleTag:[{tag:"img",attrs:L(t.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),q=()=>({tag:"ol"}),J=()=>({tag:"p"}),V=()=>({tag:"b"}),K=()=>({tag:"strike"}),G=()=>({tag:"u"}),Y=()=>({tag:"strong"}),H=()=>({tag:"code"}),Q=()=>({tag:"i"}),W=t=>{const e={...t.attrs},{linktype:r="url"}=t.attrs;return _(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Z=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:O,blockquote:M,bullet_list:P,code_block:D,hard_break:U,heading:B,image:z,list_item:F,ordered_list:q,paragraph:J},marks:{bold:V,strike:K,underline:G,strong:Y,code:H,italic:Q,link:W,styled:Z}},X=function(t){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,n=>e[n]):t};class I{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(n=>{r.push(this.renderNode(n))}):e.text?r.push(X(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderClosingTag(s.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let n=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const i=o.attrs[s];i!==null&&(n+=` ${s}="${i}"`)}return`${n}${r}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}const ee=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let te;const re="https://app.storyblok.com/f/storyblok-v2-latest.js",oe=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},se=(t,e,r)=>{let o=r||te;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new I(e.schema),e.resolver&&oe(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
9
+ `}}}const x=/[\p{Lu}]/u,R=/[\p{Ll}]/u,y=/^[\p{Lu}](?![\p{Lu}])/gu,k=/([\p{Alpha}\p{N}_]|$)/u,p=/[_.\- ]+/,N=new RegExp("^"+p.source),$=new RegExp(p.source+k.source,"gu"),v=new RegExp("\\d+"+k.source,"gu"),L=(r,e,t,s)=>{let a=!1,o=!1,i=!1,u=!1;for(let n=0;n<r.length;n++){const l=r[n];u=n>2?r[n-3]==="-":!0,a&&x.test(l)?(r=r.slice(0,n)+"-"+r.slice(n),a=!1,i=o,o=!0,n++):o&&i&&R.test(l)&&(!u||s)?(r=r.slice(0,n-1)+"-"+r.slice(n-1),i=o,o=!1,a=!0):(a=e(l)===l&&t(l)!==l,i=o,o=t(l)===l&&e(l)!==l)}return r},O=(r,e)=>(y.lastIndex=0,r.replace(y,t=>e(t))),_=(r,e)=>($.lastIndex=0,v.lastIndex=0,r.replace($,(t,s)=>e(s)).replace(v,t=>e(t)));function I(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(o=>o.trim()).filter(o=>o.length).join("-"):r=r.trim(),r.length===0)return"";const t=e.locale===!1?o=>o.toLowerCase():o=>o.toLocaleLowerCase(e.locale),s=e.locale===!1?o=>o.toUpperCase():o=>o.toLocaleUpperCase(e.locale);return r.length===1?p.test(r)?"":e.pascalCase?s(r):t(r):(r!==t(r)&&(r=L(r,t,s,e.preserveConsecutiveUppercase)),r=r.replace(N,""),r=e.preserveConsecutiveUppercase?O(r,t):t(r),e.pascalCase&&(r=s(r.charAt(0))+r.slice(1)),_(r,s))}function z(r){const e="virtual:storyblok-components",t="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(s){if(s===e)return t},async load(s){if(s===t){const a=[];for await(const[o,i]of Object.entries(r)){const u=await this.resolve("/src/"+i+".astro");if(!u)throw new Error(`Component could not be found for blok "${o}"! Does "/src/${i}.astro" exist?`);a.push(`import ${I(o)} from "${u.id}"`)}return`${a.join(";")};export default {${Object.keys(r).map(o=>I(o)).join(",")}}`}}}}let T=!1;const w=[],M=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():w.push(a)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=r,s.id="storyblok-javascript-bridge",s.onerror=a=>t(a),s.onload=a=>{w.forEach(o=>o()),T=!0,e(a)},document.getElementsByTagName("head")[0].appendChild(s)});var P=Object.defineProperty,D=(r,e,t)=>e in r?P(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,A=(r,e,t)=>(D(r,typeof e!="symbol"?e+"":e,t),t);const U=function(r,e){const t={};for(const s in r){const a=r[s];e.indexOf(s)>-1&&a!==null&&(t[s]=a)}return t},q=r=>r==="email",B=()=>({singleTag:"hr"}),F=()=>({tag:"blockquote"}),J=()=>({tag:"ul"}),V=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),K=r=>({tag:`h${r.attrs.level}`}),W=r=>({singleTag:[{tag:"img",attrs:U(r.attrs,["src","alt","title"])}]}),Y=()=>({tag:"li"}),H=()=>({tag:"ol"}),Q=()=>({tag:"p"}),X=r=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:r.attrs.name,emoji:r.attrs.emoji}}]}),Z=()=>({tag:"b"}),ee=()=>({tag:"strike"}),te=()=>({tag:"u"}),re=()=>({tag:"strong"}),se=()=>({tag:"code"}),oe=()=>({tag:"i"}),ae=r=>{const e={...r.attrs},{linktype:t="url"}=r.attrs;if(q(t)&&(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}]}),ne=()=>({tag:"sub"}),le=()=>({tag:"sup"}),ce=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ge=r=>({tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}),ue=r=>({tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color}`}}]}),E={nodes:{horizontal_rule:B,blockquote:F,bullet_list:J,code_block:V,hard_break:G,heading:K,image:W,list_item:Y,ordered_list:H,paragraph:Q,emoji:X},marks:{bold:Z,strike:ee,underline:te,strong:re,code:se,italic:oe,link:ae,styled:ie,subscript:ne,superscript:le,anchor:ce,highlight:ge,textStyle:ue}},fe=function(r){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return r&&s.test(r)?r.replace(t,a=>e[a]):r};class j{constructor(e){A(this,"marks"),A(this,"nodes"),e||(e=E),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 s="";return e.content.forEach(a=>{s+=this.renderNode(a)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn("The render method must receive an object with a content field, which is an array"),""}optimizeImages(e,t){let s=0,a=0,o="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,a=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const u=s>0||a>0||i.length>0?`${s}x${a}${i}`:"";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/${u}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,n=>{var l,C;const d=n.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const h={srcset:(l=t.srcset)==null?void 0:l.map(g=>{if(typeof g=="number")return`//${d}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let m=0,S=0;return typeof g[0]=="number"&&(m=g[0]),typeof g[1]=="number"&&(S=g[1]),`//${d}/m/${m}x${S}${i} ${m}w`}}).join(", "),sizes:(C=t.sizes)==null?void 0:C.map(g=>g).join(", ")};let b="";return h.srcset&&(b+=`srcset="${h.srcset}" `),h.sizes&&(b+=`sizes="${h.sizes}" `),n.replace(/<img/g,`<img ${b.trim()}`)}return n})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(a=>{const o=this.getMatchingMark(a);o&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(a=>{t.push(this.renderNode(a))}):e.text?t.push(fe(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(a=>{const o=this.getMatchingMark(a);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let a=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const i=s.attrs[o];i!==null&&(a+=` ${o}="${i}"`)}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 de=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 pe="https://app.storyblok.com/f/storyblok-v2-latest.js",be=(r,e)=>{r.addNode("blok",t=>{let s="";return t.attrs.body.forEach(a=>{s+=e(a.component,a)}),{html:s}})},me=(r,e,t)=>{let s=t||he;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return r===""?"":r?(e&&(s=new j(e.schema),e.resolver&&be(s,e.resolver)),s.render(r)):(console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
10
10
 
11
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ne=()=>x(re);function ae(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function ie(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return se(t,e,r)}function le(t){const e={useCustomApi:!1,bridge:!0,...t};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:o})=>{o({vite:{plugins:[d(e.accessToken,e.useCustomApi,e.apiOptions),R(e.components)]}}),r("page-ssr",`
11
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ye=()=>M(pe);function ke(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function $e(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return me(r,e,t)}function ve(r){const e={useCustomApi:!1,bridge:!0,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:s})=>{s({vite:{plugins:[f(e.accessToken,e.useCustomApi,e.apiOptions),z(e.components)]}}),t("page-ssr",`
12
12
  import { storyblokApiInstance } from "virtual:storyblok-init";
13
13
  globalThis.storyblokApiInstance = storyblokApiInstance;
14
- `),e.bridge&&r("page",`
14
+ `),e.bridge&&t("page",`
15
15
  import { loadStoryblokBridge } from "@storyblok/astro";
16
16
  loadStoryblokBridge().then(() => {
17
17
  const { StoryblokBridge, location } = window;
@@ -23,4 +23,4 @@
23
23
  }
24
24
  });
25
25
  });
26
- `)}}}}a.RichTextResolver=I,a.RichTextSchema=T,a.default=le,a.loadStoryblokBridge=ne,a.renderRichText=ie,a.storyblokEditable=ee,a.useStoryblokApi=ae,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
26
+ `)}}}}c.RichTextResolver=j,c.RichTextSchema=E,c.default=ve,c.loadStoryblokBridge=ye,c.renderRichText=$e,c.storyblokEditable=de,c.useStoryblokApi=ke,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,138 +1,154 @@
1
- function m(t, e, r) {
2
- const o = "virtual:storyblok-init", n = "\0" + o;
1
+ function A(r, e, t) {
2
+ const s = "virtual:storyblok-init", a = "\0" + s;
3
3
  return {
4
4
  name: "vite-plugin-storyblok-init",
5
- async resolveId(s) {
6
- if (s === o)
7
- return n;
5
+ async resolveId(o) {
6
+ if (o === s)
7
+ return a;
8
8
  },
9
- async load(s) {
10
- if (s === n)
9
+ async load(o) {
10
+ if (o === a)
11
11
  return `
12
12
  import { storyblokInit, apiPlugin } from "@storyblok/js";
13
13
  const { storyblokApi } = storyblokInit({
14
- accessToken: "${t}",
14
+ accessToken: "${r}",
15
15
  use: ${e ? "[]" : "[apiPlugin]"},
16
- apiOptions: ${JSON.stringify(r)},
16
+ apiOptions: ${JSON.stringify(t)},
17
17
  });
18
18
  export const storyblokApiInstance = storyblokApi;
19
19
  `;
20
20
  }
21
21
  };
22
22
  }
23
- const v = /[\p{Lu}]/u, I = /[\p{Ll}]/u, u = /^[\p{Lu}](?![\p{Lu}])/gu, k = /([\p{Alpha}\p{N}_]|$)/u, d = /[_.\- ]+/, T = new RegExp("^" + d.source), g = new RegExp(d.source + k.source, "gu"), h = new RegExp("\\d+" + k.source, "gu"), A = (t, e, r, o) => {
24
- let n = !1, s = !1, a = !1, c = !1;
25
- for (let l = 0; l < t.length; l++) {
26
- const i = t[l];
27
- c = l > 2 ? t[l - 3] === "-" : !0, n && v.test(i) ? (t = t.slice(0, l) + "-" + t.slice(l), n = !1, a = s, s = !0, l++) : s && a && I.test(i) && (!c || o) ? (t = t.slice(0, l - 1) + "-" + t.slice(l - 1), a = s, s = !1, n = !0) : (n = e(i) === i && r(i) !== i, a = s, s = r(i) === i && e(i) !== i);
23
+ const j = /[\p{Lu}]/u, C = /[\p{Ll}]/u, y = /^[\p{Lu}](?![\p{Lu}])/gu, E = /([\p{Alpha}\p{N}_]|$)/u, p = /[_.\- ]+/, x = new RegExp("^" + p.source), k = new RegExp(p.source + E.source, "gu"), $ = new RegExp("\\d+" + E.source, "gu"), S = (r, e, t, s) => {
24
+ let a = !1, o = !1, i = !1, g = !1;
25
+ for (let n = 0; n < r.length; n++) {
26
+ const l = r[n];
27
+ g = n > 2 ? r[n - 3] === "-" : !0, a && j.test(l) ? (r = r.slice(0, n) + "-" + r.slice(n), a = !1, i = o, o = !0, n++) : o && i && C.test(l) && (!g || s) ? (r = r.slice(0, n - 1) + "-" + r.slice(n - 1), i = o, o = !1, a = !0) : (a = e(l) === l && t(l) !== l, i = o, o = t(l) === l && e(l) !== l);
28
28
  }
29
- return t;
30
- }, E = (t, e) => (u.lastIndex = 0, t.replace(u, (r) => e(r))), w = (t, e) => (g.lastIndex = 0, h.lastIndex = 0, t.replace(g, (r, o) => e(o)).replace(h, (r) => e(r)));
31
- function p(t, e) {
32
- if (!(typeof t == "string" || Array.isArray(t)))
29
+ return r;
30
+ }, R = (r, e) => (y.lastIndex = 0, r.replace(y, (t) => e(t))), N = (r, e) => (k.lastIndex = 0, $.lastIndex = 0, r.replace(k, (t, s) => e(s)).replace($, (t) => e(t)));
31
+ function v(r, e) {
32
+ if (!(typeof r == "string" || Array.isArray(r)))
33
33
  throw new TypeError("Expected the input to be `string | string[]`");
34
34
  if (e = {
35
35
  pascalCase: !1,
36
36
  preserveConsecutiveUppercase: !1,
37
37
  ...e
38
- }, Array.isArray(t) ? t = t.map((s) => s.trim()).filter((s) => s.length).join("-") : t = t.trim(), t.length === 0)
38
+ }, Array.isArray(r) ? r = r.map((o) => o.trim()).filter((o) => o.length).join("-") : r = r.trim(), r.length === 0)
39
39
  return "";
40
- const r = 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 t.length === 1 ? d.test(t) ? "" : e.pascalCase ? o(t) : r(t) : (t !== r(t) && (t = A(t, r, o, e.preserveConsecutiveUppercase)), t = t.replace(T, ""), t = e.preserveConsecutiveUppercase ? E(t, r) : r(t), e.pascalCase && (t = o(t.charAt(0)) + t.slice(1)), w(t, o));
40
+ const t = e.locale === !1 ? (o) => o.toLowerCase() : (o) => o.toLocaleLowerCase(e.locale), s = e.locale === !1 ? (o) => o.toUpperCase() : (o) => o.toLocaleUpperCase(e.locale);
41
+ return r.length === 1 ? p.test(r) ? "" : e.pascalCase ? s(r) : t(r) : (r !== t(r) && (r = S(r, t, s, e.preserveConsecutiveUppercase)), r = r.replace(x, ""), r = e.preserveConsecutiveUppercase ? R(r, t) : t(r), e.pascalCase && (r = s(r.charAt(0)) + r.slice(1)), N(r, s));
42
42
  }
43
- function C(t) {
44
- const e = "virtual:storyblok-components", r = "\0" + e;
43
+ function L(r) {
44
+ const e = "virtual:storyblok-components", t = "\0" + e;
45
45
  return {
46
46
  name: "vite-plugin-storyblok-components",
47
- async resolveId(o) {
48
- if (o === e)
49
- return r;
47
+ async resolveId(s) {
48
+ if (s === e)
49
+ return t;
50
50
  },
51
- async load(o) {
52
- if (o === r) {
53
- const n = [];
54
- for await (const [s, a] of Object.entries(t)) {
55
- const c = await this.resolve("/src/" + a + ".astro");
56
- if (!c)
51
+ async load(s) {
52
+ if (s === t) {
53
+ const a = [];
54
+ for await (const [o, i] of Object.entries(r)) {
55
+ const g = await this.resolve("/src/" + i + ".astro");
56
+ if (!g)
57
57
  throw new Error(
58
- `Component could not be found for blok "${s}"! Does "/src/${a}.astro" exist?`
58
+ `Component could not be found for blok "${o}"! Does "/src/${i}.astro" exist?`
59
59
  );
60
- n.push(`import ${p(s)} from "${c.id}"`);
60
+ a.push(`import ${v(o)} from "${g.id}"`);
61
61
  }
62
- return `${n.join(";")};export default {${Object.keys(t).map((s) => p(s)).join(",")}}`;
62
+ return `${a.join(";")};export default {${Object.keys(r).map((o) => v(o)).join(",")}}`;
63
63
  }
64
64
  }
65
65
  };
66
66
  }
67
- let f = !1;
68
- const b = [], S = (t) => new Promise((e, r) => {
69
- if (typeof window > "u" || (window.storyblokRegisterEvent = (n) => {
67
+ let I = !1;
68
+ const w = [], z = (r) => new Promise((e, t) => {
69
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (a) => {
70
70
  if (window.location === window.parent.location) {
71
71
  console.warn("You are not in Draft Mode or in the Visual Editor.");
72
72
  return;
73
73
  }
74
- f ? n() : b.push(n);
74
+ I ? a() : w.push(a);
75
75
  }, document.getElementById("storyblok-javascript-bridge")))
76
76
  return;
77
- const o = document.createElement("script");
78
- o.async = !0, o.src = t, o.id = "storyblok-javascript-bridge", o.onerror = (n) => r(n), o.onload = (n) => {
79
- b.forEach((s) => s()), f = !0, e(n);
80
- }, document.getElementsByTagName("head")[0].appendChild(o);
77
+ const s = document.createElement("script");
78
+ s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (a) => t(a), s.onload = (a) => {
79
+ w.forEach((o) => o()), I = !0, e(a);
80
+ }, document.getElementsByTagName("head")[0].appendChild(s);
81
81
  });
82
- var $ = Object.defineProperty, x = (t, e, r) => e in t ? $(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e, r) => (x(t, typeof e != "symbol" ? e + "" : e, r), r);
83
- const R = function(t, e) {
84
- const r = {};
85
- for (const o in t) {
86
- const n = t[o];
87
- e.indexOf(o) > -1 && n !== null && (r[o] = n);
82
+ var O = Object.defineProperty, P = (r, e, t) => e in r ? O(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, T = (r, e, t) => (P(r, typeof e != "symbol" ? e + "" : e, t), t);
83
+ const _ = function(r, e) {
84
+ const t = {};
85
+ for (const s in r) {
86
+ const a = r[s];
87
+ e.indexOf(s) > -1 && a !== null && (t[s] = a);
88
88
  }
89
- return r;
90
- }, N = (t) => t === "email", L = () => ({
89
+ return t;
90
+ }, M = (r) => r === "email", D = () => ({
91
91
  singleTag: "hr"
92
- }), j = () => ({
92
+ }), U = () => ({
93
93
  tag: "blockquote"
94
- }), O = () => ({
94
+ }), q = () => ({
95
95
  tag: "ul"
96
- }), _ = (t) => ({
96
+ }), B = (r) => ({
97
97
  tag: [
98
98
  "pre",
99
99
  {
100
100
  tag: "code",
101
- attrs: t.attrs
101
+ attrs: r.attrs
102
102
  }
103
103
  ]
104
- }), P = () => ({
104
+ }), F = () => ({
105
105
  singleTag: "br"
106
- }), M = (t) => ({
107
- tag: `h${t.attrs.level}`
108
- }), D = (t) => ({
106
+ }), J = (r) => ({
107
+ tag: `h${r.attrs.level}`
108
+ }), V = (r) => ({
109
109
  singleTag: [
110
110
  {
111
111
  tag: "img",
112
- attrs: R(t.attrs, ["src", "alt", "title"])
112
+ attrs: _(r.attrs, ["src", "alt", "title"])
113
113
  }
114
114
  ]
115
- }), U = () => ({
115
+ }), G = () => ({
116
116
  tag: "li"
117
- }), B = () => ({
117
+ }), K = () => ({
118
118
  tag: "ol"
119
- }), z = () => ({
119
+ }), W = () => ({
120
120
  tag: "p"
121
- }), F = () => ({
121
+ }), Y = (r) => ({
122
+ tag: [
123
+ {
124
+ tag: "span",
125
+ attrs: {
126
+ ["data-type"]: "emoji",
127
+ ["data-name"]: r.attrs.name,
128
+ emoji: r.attrs.emoji
129
+ }
130
+ }
131
+ ]
132
+ }), H = () => ({
122
133
  tag: "b"
123
- }), q = () => ({
134
+ }), Q = () => ({
124
135
  tag: "strike"
125
- }), J = () => ({
136
+ }), X = () => ({
126
137
  tag: "u"
127
- }), V = () => ({
138
+ }), Z = () => ({
128
139
  tag: "strong"
129
- }), K = () => ({
140
+ }), ee = () => ({
130
141
  tag: "code"
131
- }), G = () => ({
142
+ }), te = () => ({
132
143
  tag: "i"
133
- }), Y = (t) => {
134
- const e = { ...t.attrs }, { linktype: r = "url" } = t.attrs;
135
- return N(r) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
144
+ }), re = (r) => {
145
+ const e = { ...r.attrs }, { linktype: t = "url" } = r.attrs;
146
+ if (M(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
147
+ for (const s in e.custom)
148
+ e[s] = e.custom[s];
149
+ delete e.custom;
150
+ }
151
+ return {
136
152
  tag: [
137
153
  {
138
154
  tag: "a",
@@ -140,93 +156,158 @@ const R = function(t, e) {
140
156
  }
141
157
  ]
142
158
  };
143
- }, H = (t) => ({
159
+ }, se = (r) => ({
160
+ tag: [
161
+ {
162
+ tag: "span",
163
+ attrs: r.attrs
164
+ }
165
+ ]
166
+ }), oe = () => ({
167
+ tag: "sub"
168
+ }), ae = () => ({
169
+ tag: "sup"
170
+ }), ie = (r) => ({
171
+ tag: [
172
+ {
173
+ tag: "span",
174
+ attrs: r.attrs
175
+ }
176
+ ]
177
+ }), ne = (r) => ({
144
178
  tag: [
145
179
  {
146
180
  tag: "span",
147
- attrs: t.attrs
181
+ attrs: {
182
+ style: `background-color:${r.attrs.color};`
183
+ }
184
+ }
185
+ ]
186
+ }), le = (r) => ({
187
+ tag: [
188
+ {
189
+ tag: "span",
190
+ attrs: {
191
+ style: `background-color:${r.attrs.color}`
192
+ }
148
193
  }
149
194
  ]
150
- }), Q = {
195
+ }), ce = {
151
196
  nodes: {
152
- horizontal_rule: L,
153
- blockquote: j,
154
- bullet_list: O,
155
- code_block: _,
156
- hard_break: P,
157
- heading: M,
158
- image: D,
159
- list_item: U,
160
- ordered_list: B,
161
- paragraph: z
197
+ horizontal_rule: D,
198
+ blockquote: U,
199
+ bullet_list: q,
200
+ code_block: B,
201
+ hard_break: F,
202
+ heading: J,
203
+ image: V,
204
+ list_item: G,
205
+ ordered_list: K,
206
+ paragraph: W,
207
+ emoji: Y
162
208
  },
163
209
  marks: {
164
- bold: F,
165
- strike: q,
166
- underline: J,
167
- strong: V,
168
- code: K,
169
- italic: G,
170
- link: Y,
171
- styled: H
210
+ bold: H,
211
+ strike: Q,
212
+ underline: X,
213
+ strong: Z,
214
+ code: ee,
215
+ italic: te,
216
+ link: re,
217
+ styled: se,
218
+ subscript: oe,
219
+ superscript: ae,
220
+ anchor: ie,
221
+ highlight: ne,
222
+ textStyle: le
172
223
  }
173
- }, W = function(t) {
224
+ }, ge = function(r) {
174
225
  const e = {
175
226
  "&": "&amp;",
176
227
  "<": "&lt;",
177
228
  ">": "&gt;",
178
229
  '"': "&quot;",
179
230
  "'": "&#39;"
180
- }, r = /[&<>"']/g, o = RegExp(r.source);
181
- return t && o.test(t) ? t.replace(r, (n) => e[n]) : t;
231
+ }, t = /[&<>"']/g, s = RegExp(t.source);
232
+ return r && s.test(r) ? r.replace(t, (a) => e[a]) : r;
182
233
  };
183
- class Z {
234
+ class ue {
184
235
  constructor(e) {
185
- y(this, "marks"), y(this, "nodes"), e || (e = Q), this.marks = e.marks || [], this.nodes = e.nodes || [];
236
+ T(this, "marks"), T(this, "nodes"), e || (e = ce), this.marks = e.marks || [], this.nodes = e.nodes || [];
186
237
  }
187
- addNode(e, r) {
188
- this.nodes[e] = r;
238
+ addNode(e, t) {
239
+ this.nodes[e] = t;
189
240
  }
190
- addMark(e, r) {
191
- this.marks[e] = r;
241
+ addMark(e, t) {
242
+ this.marks[e] = t;
192
243
  }
193
- render(e) {
244
+ render(e, t = { optimizeImages: !1 }) {
194
245
  if (e && e.content && Array.isArray(e.content)) {
195
- let r = "";
196
- return e.content.forEach((o) => {
197
- r += this.renderNode(o);
198
- }), r;
246
+ let s = "";
247
+ return e.content.forEach((a) => {
248
+ s += this.renderNode(a);
249
+ }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
199
250
  }
200
251
  return console.warn(
201
252
  "The render method must receive an object with a content field, which is an array"
202
253
  ), "";
203
254
  }
255
+ optimizeImages(e, t) {
256
+ let s = 0, a = 0, o = "", i = "";
257
+ typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, a = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = "/filters" + i))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
258
+ const g = s > 0 || a > 0 || i.length > 0 ? `${s}x${a}${i}` : "";
259
+ return e = e.replace(
260
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
261
+ `a.storyblok.com/f/$1/$2.$3/m/${g}`
262
+ ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (n) => {
263
+ var l, m;
264
+ const u = n.match(
265
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
266
+ );
267
+ if (u && u.length > 0) {
268
+ const f = {
269
+ srcset: (l = t.srcset) == null ? void 0 : l.map((c) => {
270
+ if (typeof c == "number")
271
+ return `//${u}/m/${c}x0${i} ${c}w`;
272
+ if (typeof c == "object" && c.length === 2) {
273
+ let h = 0, b = 0;
274
+ return typeof c[0] == "number" && (h = c[0]), typeof c[1] == "number" && (b = c[1]), `//${u}/m/${h}x${b}${i} ${h}w`;
275
+ }
276
+ }).join(", "),
277
+ sizes: (m = t.sizes) == null ? void 0 : m.map((c) => c).join(", ")
278
+ };
279
+ let d = "";
280
+ return f.srcset && (d += `srcset="${f.srcset}" `), f.sizes && (d += `sizes="${f.sizes}" `), n.replace(/<img/g, `<img ${d.trim()}`);
281
+ }
282
+ return n;
283
+ })), e;
284
+ }
204
285
  renderNode(e) {
205
- const r = [];
206
- e.marks && e.marks.forEach((n) => {
207
- const s = this.getMatchingMark(n);
208
- s && r.push(this.renderOpeningTag(s.tag));
286
+ const t = [];
287
+ e.marks && e.marks.forEach((a) => {
288
+ const o = this.getMatchingMark(a);
289
+ o && t.push(this.renderOpeningTag(o.tag));
209
290
  });
210
- const o = this.getMatchingNode(e);
211
- return o && o.tag && r.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((n) => {
212
- r.push(this.renderNode(n));
213
- }) : e.text ? r.push(W(e.text)) : o && o.singleTag ? r.push(this.renderTag(o.singleTag, " /")) : o && o.html && r.push(o.html), o && o.tag && r.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((n) => {
214
- const s = this.getMatchingMark(n);
215
- s && r.push(this.renderClosingTag(s.tag));
216
- }), r.join("");
291
+ const s = this.getMatchingNode(e);
292
+ return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((a) => {
293
+ t.push(this.renderNode(a));
294
+ }) : e.text ? t.push(ge(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((a) => {
295
+ const o = this.getMatchingMark(a);
296
+ o && t.push(this.renderClosingTag(o.tag));
297
+ }), t.join("");
217
298
  }
218
- renderTag(e, r) {
219
- return e.constructor === String ? `<${e}${r}>` : e.map((o) => {
220
- if (o.constructor === String)
221
- return `<${o}${r}>`;
299
+ renderTag(e, t) {
300
+ return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
301
+ if (s.constructor === String)
302
+ return `<${s}${t}>`;
222
303
  {
223
- let n = `<${o.tag}`;
224
- if (o.attrs)
225
- for (const s in o.attrs) {
226
- const a = o.attrs[s];
227
- a !== null && (n += ` ${s}="${a}"`);
304
+ let a = `<${s.tag}`;
305
+ if (s.attrs)
306
+ for (const o in s.attrs) {
307
+ const i = s.attrs[o];
308
+ i !== null && (a += ` ${o}="${i}"`);
228
309
  }
229
- return `${n}${r}>`;
310
+ return `${a}${t}>`;
230
311
  }
231
312
  }).join("");
232
313
  }
@@ -234,93 +315,109 @@ class Z {
234
315
  return this.renderTag(e, "");
235
316
  }
236
317
  renderClosingTag(e) {
237
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
318
+ return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
238
319
  }
239
320
  getMatchingNode(e) {
240
- const r = this.nodes[e.type];
241
- if (typeof r == "function")
242
- return r(e);
321
+ const t = this.nodes[e.type];
322
+ if (typeof t == "function")
323
+ return t(e);
243
324
  }
244
325
  getMatchingMark(e) {
245
- const r = this.marks[e.type];
246
- if (typeof r == "function")
247
- return r(e);
326
+ const t = this.marks[e.type];
327
+ if (typeof t == "function")
328
+ return t(e);
329
+ }
330
+ renderEmoji(e) {
331
+ if (e.attrs.emoji)
332
+ return e.attrs.emoji;
333
+ const t = [
334
+ {
335
+ tag: "img",
336
+ attrs: {
337
+ src: e.attrs.fallbackImage,
338
+ draggable: "false",
339
+ loading: "lazy",
340
+ align: "absmiddle"
341
+ }
342
+ }
343
+ ];
344
+ return this.renderTag(t, " /");
248
345
  }
249
346
  }
250
- const oe = (t) => {
251
- if (typeof t != "object" || typeof t._editable > "u")
347
+ const me = (r) => {
348
+ if (typeof r != "object" || typeof r._editable > "u")
252
349
  return {};
253
350
  const e = JSON.parse(
254
- t._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
351
+ r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
255
352
  );
256
353
  return {
257
354
  "data-blok-c": JSON.stringify(e),
258
355
  "data-blok-uid": e.id + "-" + e.uid
259
356
  };
260
357
  };
261
- let X;
262
- const ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", te = (t, e) => {
263
- t.addNode("blok", (r) => {
264
- let o = "";
265
- return r.attrs.body.forEach((n) => {
266
- o += e(n.component, n);
358
+ let fe;
359
+ const de = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) => {
360
+ r.addNode("blok", (t) => {
361
+ let s = "";
362
+ return t.attrs.body.forEach((a) => {
363
+ s += e(a.component, a);
267
364
  }), {
268
- html: o
365
+ html: s
269
366
  };
270
367
  });
271
- }, re = (t, e, r) => {
272
- let o = r || X;
273
- if (!o) {
368
+ }, pe = (r, e, t) => {
369
+ let s = t || fe;
370
+ if (!s) {
274
371
  console.error(
275
372
  "Please initialize the Storyblok SDK before calling the renderRichText function"
276
373
  );
277
374
  return;
278
375
  }
279
- return t === "" ? "" : t ? (e && (o = new Z(e.schema), e.resolver && te(o, e.resolver)), o.render(t)) : (console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
376
+ return r === "" ? "" : r ? (e && (s = new ue(e.schema), e.resolver && he(s, e.resolver)), s.render(r)) : (console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
280
377
 
281
378
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
282
- }, se = () => S(ee);
283
- function ne() {
379
+ }, be = () => z(de);
380
+ function ye() {
284
381
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
285
382
  }
286
- function ae(t, e) {
287
- const r = globalThis.storyblokApiInstance.richTextResolver;
288
- if (!r) {
383
+ function ke(r, e) {
384
+ const t = globalThis.storyblokApiInstance.richTextResolver;
385
+ if (!t) {
289
386
  console.error(
290
387
  "Please initialize the Storyblok SDK before calling the renderRichText function"
291
388
  );
292
389
  return;
293
390
  }
294
- return re(t, e, r);
391
+ return pe(r, e, t);
295
392
  }
296
- function le(t) {
393
+ function $e(r) {
297
394
  const e = {
298
395
  useCustomApi: !1,
299
396
  bridge: !0,
300
- ...t
397
+ ...r
301
398
  };
302
399
  return {
303
400
  name: "@storyblok/astro",
304
401
  hooks: {
305
- "astro:config:setup": ({ injectScript: r, updateConfig: o }) => {
306
- o({
402
+ "astro:config:setup": ({ injectScript: t, updateConfig: s }) => {
403
+ s({
307
404
  vite: {
308
405
  plugins: [
309
- m(
406
+ A(
310
407
  e.accessToken,
311
408
  e.useCustomApi,
312
409
  e.apiOptions
313
410
  ),
314
- C(e.components)
411
+ L(e.components)
315
412
  ]
316
413
  }
317
- }), r(
414
+ }), t(
318
415
  "page-ssr",
319
416
  `
320
417
  import { storyblokApiInstance } from "virtual:storyblok-init";
321
418
  globalThis.storyblokApiInstance = storyblokApiInstance;
322
419
  `
323
- ), e.bridge && r(
420
+ ), e.bridge && t(
324
421
  "page",
325
422
  `
326
423
  import { loadStoryblokBridge } from "@storyblok/astro";
@@ -341,11 +438,11 @@ function le(t) {
341
438
  };
342
439
  }
343
440
  export {
344
- Z as RichTextResolver,
345
- Q as RichTextSchema,
346
- le as default,
347
- se as loadStoryblokBridge,
348
- ae as renderRichText,
349
- oe as storyblokEditable,
350
- ne as useStoryblokApi
441
+ ue as RichTextResolver,
442
+ ce as RichTextSchema,
443
+ $e as default,
444
+ be as loadStoryblokBridge,
445
+ ke as renderRichText,
446
+ me as storyblokEditable,
447
+ ye as useStoryblokApi
351
448
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
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",
@@ -28,19 +28,19 @@
28
28
  "prepublishOnly": "npm run build && cp ../README.md ./"
29
29
  },
30
30
  "dependencies": {
31
- "@storyblok/js": "^2.1.0",
31
+ "@storyblok/js": "^2.1.3",
32
32
  "camelcase": "^7.0.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@cypress/vite-dev-server": "^5.0.4",
36
36
  "@rollup/plugin-dynamic-import-vars": "^2.0.3",
37
- "@types/node": "18.15.2",
38
- "astro": "2.1.0",
39
- "cypress": "^12.7.0",
37
+ "@types/node": "18.15.11",
38
+ "astro": "2.1.8",
39
+ "cypress": "^12.9.0",
40
40
  "eslint-plugin-cypress": "^2.12.1",
41
41
  "start-server-and-test": "^2.0.0",
42
42
  "typescript": "4.9.5",
43
- "vite": "^4.1.4",
43
+ "vite": "^4.2.1",
44
44
  "vite-plugin-dts": "^2.1.0"
45
45
  },
46
46
  "repository": {