@storyblok/astro 5.1.0-next.1 → 5.1.0

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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -13
  3. package/{components → dist/components}/FallbackComponent.astro +1 -1
  4. package/dist/components/FallbackComponent.d.ts +6 -0
  5. package/{components → dist/components}/StoryblokComponent.astro +3 -3
  6. package/dist/components/StoryblokComponent.d.ts +6 -0
  7. package/dist/dev-toolbar/toolbarApp.d.ts +3 -0
  8. package/{dev-toolbar → dist/dev-toolbar}/toolbarApp.ts +146 -151
  9. package/dist/{types/index.d.ts → index.d.ts} +11 -14
  10. package/dist/{types/live-preview → live-preview}/handleStoryblokMessage.d.ts +1 -1
  11. package/dist/live-preview/middleware.d.ts +1 -0
  12. package/dist/live-preview/middleware.ts +25 -0
  13. package/dist/storyblok-astro.es.js +1324 -0
  14. package/dist/storyblok-astro.umd.js +69 -0
  15. package/dist/types.d.ts +12 -0
  16. package/dist/utils/generateFinalBridgeObject.d.ts +3 -0
  17. package/dist/{types/utils → utils}/parseAstCode.d.ts +2 -2
  18. package/dist/utils/toCamelCase.d.ts +1 -0
  19. package/dist/{types/vite-plugins → vite-plugins}/vite-plugin-storyblok-bridge.d.ts +2 -2
  20. package/dist/vite-plugins/vite-plugin-storyblok-components.d.ts +2 -0
  21. package/dist/vite-plugins/vite-plugin-storyblok-init.d.ts +3 -0
  22. package/dist/{types/vite-plugins → vite-plugins}/vite-plugin-storyblok-options.d.ts +1 -1
  23. package/package.json +123 -62
  24. package/components/FallbackComponent.ts +0 -2
  25. package/components/StoryblokComponent.ts +0 -2
  26. package/dist/storyblok-astro.js +0 -68
  27. package/dist/storyblok-astro.mjs +0 -1314
  28. package/dist/types/components/FallbackComponent.d.ts +0 -2
  29. package/dist/types/components/StoryblokComponent.d.ts +0 -2
  30. package/dist/types/cypress/e2e/index.cy.d.ts +0 -0
  31. package/dist/types/cypress/plugins/index.d.ts +0 -2
  32. package/dist/types/cypress/support/commands.d.ts +0 -0
  33. package/dist/types/cypress/support/e2e.d.ts +0 -1
  34. package/dist/types/cypress.config.d.ts +0 -2
  35. package/dist/types/dev-toolbar/toolbarApp.d.ts +0 -7
  36. package/dist/types/live-preview/middleware.d.ts +0 -1
  37. package/dist/types/node_modules/camelcase/index.d.ts +0 -102
  38. package/dist/types/types.d.ts +0 -12
  39. package/dist/types/utils/generateFinalBridgeObject.d.ts +0 -3
  40. package/dist/types/vite-plugins/vite-plugin-storyblok-components.d.ts +0 -2
  41. package/dist/types/vite-plugins/vite-plugin-storyblok-init.d.ts +0 -3
  42. package/live-preview/handleStoryblokMessage.ts +0 -76
  43. package/live-preview/middleware.ts +0 -24
  44. package/utils/generateFinalBridgeObject.ts +0 -33
  45. package/utils/parseAstCode.ts +0 -66
@@ -0,0 +1,69 @@
1
+ (function(k,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(k=typeof globalThis<"u"?globalThis:k||self,N(k.storyblokAstro={}))})(this,function(k){"use strict";function N(o,t,r){const i="virtual:storyblok-init",s=`\0${i}`;return{name:"vite-plugin-storyblok-init",async resolveId(l){if(l===i)return s},async load(l){if(l===s)return`
2
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
3
+ const { storyblokApi } = storyblokInit({
4
+ accessToken: "${o}",
5
+ use: ${t?"[]":"[apiPlugin]"},
6
+ apiOptions: ${JSON.stringify(r)},
7
+ });
8
+ export const storyblokApiInstance = storyblokApi;
9
+ `}}}const Xe=/[\p{Lu}]/u,Ye=/[\p{Ll}]/u,he=/^[\p{Lu}](?![\p{Lu}])/gu,be=/([\p{Alpha}\p{N}_]|$)/u,te=/[_.\- ]+/,Qe=new RegExp("^"+te.source),ye=new RegExp(te.source+be.source,"gu"),me=new RegExp("\\d+"+be.source,"gu"),et=(o,t,r,i)=>{let s=!1,l=!1,u=!1,f=!1;for(let g=0;g<o.length;g++){const y=o[g];f=g>2?o[g-3]==="-":!0,s&&Xe.test(y)?(o=o.slice(0,g)+"-"+o.slice(g),s=!1,u=l,l=!0,g++):l&&u&&Ye.test(y)&&(!f||i)?(o=o.slice(0,g-1)+"-"+o.slice(g-1),u=l,l=!1,s=!0):(s=t(y)===y&&r(y)!==y,u=l,l=r(y)===y&&t(y)!==y)}return o},tt=(o,t)=>(he.lastIndex=0,o.replaceAll(he,r=>t(r))),rt=(o,t)=>(ye.lastIndex=0,me.lastIndex=0,o.replaceAll(me,(r,i,s)=>["_","-"].includes(o.charAt(s+r.length))?r:t(r)).replaceAll(ye,(r,i)=>t(i)));function nt(o,t){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(o)?o=o.map(l=>l.trim()).filter(l=>l.length).join("-"):o=o.trim(),o.length===0)return"";const r=t.locale===!1?l=>l.toLowerCase():l=>l.toLocaleLowerCase(t.locale),i=t.locale===!1?l=>l.toUpperCase():l=>l.toLocaleUpperCase(t.locale);return o.length===1?te.test(o)?"":t.pascalCase?i(o):r(o):(o!==r(o)&&(o=et(o,r,i,t.preserveConsecutiveUppercase)),o=o.replace(Qe,""),o=t.preserveConsecutiveUppercase?tt(o,r):r(o),t.pascalCase&&(o=i(o.charAt(0))+o.slice(1)),rt(o,i))}function re(o){return nt(o)}function ot(o,t={},r,i){const s="virtual:storyblok-components",l=`\0${s}`;return{name:"vite-plugin-storyblok-components",async resolveId(u){if(u===s)return l},async load(u){if(u===l){const f=[],g=[];for await(const[_,A]of Object.entries(t)){const C=await this.resolve(`/${o}/${A}.astro`);if(C)f.push(`import ${re(_)} from "${C.id}"`);else if(r)g.push(_);else throw new Error(`Component could not be found for blok "${_}"! Does "${`/${o}/${A}`}.astro" exist?`)}let y="";if(r)if(y=",FallbackComponent",i){const _=await this.resolve(`/${o}/${i}.astro`);if(!_)throw new Error(`Custom fallback component could not be found. Does "${`/${o}/${i}`}.astro" exist?`);f.push(`import FallbackComponent from "${_.id}"`)}else f.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${f.join(";")};export default {${Object.keys(t).filter(_=>!g.includes(_)).map(_=>re(_)).join(",")}${y}}`;if(r)return`${f[0]}; export default {${y.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
10
+ Please register your components or enable the fallback component.
11
+ Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function at(o){const t="virtual:storyblok-options",r=`\0${t}`;return{name:"vite-plugin-storyblok-options",async resolveId(i){if(i===t)return r},async load(i){if(i===r)return`export default ${JSON.stringify(o)}`}}}let ve=!1;const _e=[],it=o=>new Promise((t,r)=>{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}ve?s():_e.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const i=document.createElement("script");i.async=!0,i.src=o,i.id="storyblok-javascript-bridge",i.onerror=s=>r(s),i.onload=s=>{_e.forEach(l=>l()),ve=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(i)});var st=Object.defineProperty,lt=(o,t,r)=>t in o?st(o,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[t]=r,I=(o,t,r)=>lt(o,typeof t!="symbol"?t+"":t,r);let ct=class{constructor(){I(this,"isCDNUrl",(o="")=>o.includes("/cdn/")),I(this,"getOptionsPage",(o,t=25,r=1)=>({...o,per_page:t,page:r})),I(this,"delay",o=>new Promise(t=>setTimeout(t,o))),I(this,"arrayFrom",(o=0,t)=>Array.from({length:o},t)),I(this,"range",(o=0,t=o)=>{const r=Math.abs(t-o)||0,i=o<t?1:-1;return this.arrayFrom(r,(s,l)=>l*i+o)}),I(this,"asyncMap",async(o,t)=>Promise.all(o.map(t))),I(this,"flatMap",(o=[],t)=>o.map(t).reduce((r,i)=>[...r,...i],[])),I(this,"escapeHTML",function(o){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,i=new RegExp(r.source);return o&&i.test(o)?o.replace(r,s=>t[s]):o})}stringify(o,t,r){const i=[];for(const s in o){if(!Object.prototype.hasOwnProperty.call(o,s))continue;const l=o[s],u=r?"":encodeURIComponent(s);let f;typeof l=="object"?f=this.stringify(l,t?t+encodeURIComponent(`[${u}]`):u,Array.isArray(l)):f=`${t?t+encodeURIComponent(`[${u}]`):u}=${encodeURIComponent(l)}`,i.push(f)}return i.join("&")}getRegionURL(o){const t="api.storyblok.com",r="api-us.storyblok.com",i="app.storyblokchina.cn",s="api-ap.storyblok.com",l="api-ca.storyblok.com";switch(o){case"us":return r;case"cn":return i;case"ap":return s;case"ca":return l;default:return t}}};const ut=function(o,t){const r={};for(const i in o){const s=o[i];t.includes(i)&&s!==null&&(r[i]=s)}return r},ft=o=>o==="email",dt=()=>({singleTag:"hr"}),pt=()=>({tag:"blockquote"}),gt=()=>({tag:"ul"}),ht=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),bt=()=>({singleTag:"br"}),yt=o=>({tag:`h${o.attrs.level}`}),mt=o=>({singleTag:[{tag:"img",attrs:ut(o.attrs,["src","alt","title"])}]}),vt=()=>({tag:"li"}),_t=()=>({tag:"ol"}),wt=()=>({tag:"p"}),kt=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),Tt=()=>({tag:"b"}),Ct=()=>({tag:"s"}),At=()=>({tag:"u"}),St=()=>({tag:"strong"}),It=()=>({tag:"code"}),$t=()=>({tag:"i"}),Ot=o=>{if(!o.attrs)return{tag:""};const t=new ct().escapeHTML,r={...o.attrs},{linktype:i="url"}=o.attrs;if(delete r.linktype,r.href&&(r.href=t(o.attrs.href||"")),ft(i)&&(r.href=`mailto:${r.href}`),r.anchor&&(r.href=`${r.href}#${r.anchor}`,delete r.anchor),r.custom){for(const s in r.custom)r[s]=r.custom[s];delete r.custom}return{tag:[{tag:"a",attrs:r}]}},jt=o=>({tag:[{tag:"span",attrs:o.attrs}]}),xt=()=>({tag:"sub"}),Et=()=>({tag:"sup"}),Rt=o=>({tag:[{tag:"span",attrs:o.attrs}]}),Pt=o=>{var t;return(t=o.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},Lt=o=>{var t;return(t=o.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},we={nodes:{horizontal_rule:dt,blockquote:pt,bullet_list:gt,code_block:ht,hard_break:bt,heading:yt,image:mt,list_item:vt,ordered_list:_t,paragraph:wt,emoji:kt},marks:{bold:Tt,strike:Ct,underline:At,strong:St,code:It,italic:$t,link:Ot,styled:jt,subscript:xt,superscript:Et,anchor:Rt,highlight:Pt,textStyle:Lt}},Mt=function(o){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,i=new RegExp(r.source);return o&&i.test(o)?o.replace(r,s=>t[s]):o};let ke=!1;class Nt{constructor(t){I(this,"marks"),I(this,"nodes"),t||(t=we),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,r){this.nodes[t]=r}addMark(t,r){this.marks[t]=r}render(t,r={optimizeImages:!1},i=!0){if(!ke&&i&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),ke=!0),t&&t.content&&Array.isArray(t.content)){let s="";return t.content.forEach(l=>{s+=this.renderNode(l)}),r.optimizeImages?this.optimizeImages(s,r.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
12
+ The "content" field must be an array of nodes as the type ISbRichtext.
13
+ ISbRichtext:
14
+ content?: ISbRichtext[]
15
+ marks?: ISbRichtext[]
16
+ attrs?: any
17
+ text?: string
18
+ type: string
19
+
20
+ Example:
21
+ {
22
+ content: [
23
+ {
24
+ content: [
25
+ {
26
+ text: 'Hello World',
27
+ type: 'text'
28
+ }
29
+ ],
30
+ type: 'paragraph'
31
+ }
32
+ ],
33
+ type: 'doc'
34
+ }`),""}optimizeImages(t,r){let i=0,s=0,l="",u="";typeof r!="boolean"&&(typeof r.width=="number"&&r.width>0&&(l+=`width="${r.width}" `,i=r.width),typeof r.height=="number"&&r.height>0&&(l+=`height="${r.height}" `,s=r.height),(r.loading==="lazy"||r.loading==="eager")&&(l+=`loading="${r.loading}" `),typeof r.class=="string"&&r.class.length>0&&(l+=`class="${r.class}" `),r.filters&&(typeof r.filters.blur=="number"&&r.filters.blur>=0&&r.filters.blur<=100&&(u+=`:blur(${r.filters.blur})`),typeof r.filters.brightness=="number"&&r.filters.brightness>=-100&&r.filters.brightness<=100&&(u+=`:brightness(${r.filters.brightness})`),r.filters.fill&&(r.filters.fill.match(/[0-9A-F]{6}/gi)||r.filters.fill==="transparent")&&(u+=`:fill(${r.filters.fill})`),r.filters.format&&["webp","png","jpeg"].includes(r.filters.format)&&(u+=`:format(${r.filters.format})`),typeof r.filters.grayscale=="boolean"&&r.filters.grayscale&&(u+=":grayscale()"),typeof r.filters.quality=="number"&&r.filters.quality>=0&&r.filters.quality<=100&&(u+=`:quality(${r.filters.quality})`),r.filters.rotate&&[90,180,270].includes(r.filters.rotate)&&(u+=`:rotate(${r.filters.rotate})`),u.length>0&&(u=`/filters${u}`))),l.length>0&&(t=t.replace(/<img/g,`<img ${l.trim()}`));const f=i>0||s>0||u.length>0?`${i}x${s}${u}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${f}`),typeof r!="boolean"&&(r.sizes||r.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,g=>{var y,_;const A=g.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(A&&A.length>0){const C={srcset:(y=r.srcset)==null?void 0:y.map(w=>{if(typeof w=="number")return`//${A}/m/${w}x0${u} ${w}w`;if(typeof w=="object"&&w.length===2){let x=0,J=0;return typeof w[0]=="number"&&(x=w[0]),typeof w[1]=="number"&&(J=w[1]),`//${A}/m/${x}x${J}${u} ${x}w`}return""}).join(", "),sizes:(_=r.sizes)==null?void 0:_.map(w=>w).join(", ")};let O="";return C.srcset&&(O+=`srcset="${C.srcset}" `),C.sizes&&(O+=`sizes="${C.sizes}" `),g.replace(/<img/g,`<img ${O.trim()}`)}return g})),t}renderNode(t){const r=[];t.marks&&t.marks.forEach(s=>{const l=this.getMatchingMark(s);l&&l.tag!==""&&r.push(this.renderOpeningTag(l.tag))});const i=this.getMatchingNode(t);return i&&i.tag&&r.push(this.renderOpeningTag(i.tag)),t.content?t.content.forEach(s=>{r.push(this.renderNode(s))}):t.text?r.push(Mt(t.text)):i&&i.singleTag?r.push(this.renderTag(i.singleTag," /")):i&&i.html?r.push(i.html):t.type==="emoji"&&r.push(this.renderEmoji(t)),i&&i.tag&&r.push(this.renderClosingTag(i.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const l=this.getMatchingMark(s);l&&l.tag!==""&&r.push(this.renderClosingTag(l.tag))}),r.join("")}renderTag(t,r){return t.constructor===String?`<${t}${r}>`:t.map(i=>{if(i.constructor===String)return`<${i}${r}>`;{let s=`<${i.tag}`;if(i.attrs){for(const l in i.attrs)if(Object.prototype.hasOwnProperty.call(i.attrs,l)){const u=i.attrs[l];u!==null&&(s+=` ${l}="${u}"`)}}return`${s}${r}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(t){const r=this.nodes[t.type];if(typeof r=="function")return r(t)}getMatchingMark(t){const r=this.marks[t.type];if(typeof r=="function")return r(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const r=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(r," /")}}const Te=Nt,zt=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}:{}}catch{return{}}};let Ft,Dt="https://app.storyblok.com/f/storyblok-v2-latest.js";const Bt=(o,t)=>{o.addNode("blok",r=>{let i="";return r.attrs.body.forEach(s=>{i+=t(s.component,s)}),{html:i}})},Ut=o=>!o||!(o!=null&&o.content.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule")),Ht=(o,t,r)=>{let i=r||Ft;if(!i){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ut(o)?"":(t&&(i=new Te(t.schema),t.resolver&&Bt(i,t.resolver)),i.render(o,{},!1))},qt=()=>it(Dt);function Gt(o){const t={resolveRelations:[]};function r(i){i&&Array.isArray(t.resolveRelations)&&t.resolveRelations.push(...Array.isArray(i)?i:[i])}for(const i of o)if(i.options){const{apiOptions:s,bridgeOptions:l}=i.options;if(r(s==null?void 0:s.resolve_relations),l){const{resolveRelations:u,...f}=l;r(u),Object.assign(t,f)}}return t.resolveRelations=[...new Set(t.resolveRelations)],t}var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Jt(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var z={exports:{}};z.exports;var Ce;function Wt(){return Ce||(Ce=1,function(o,t){var r=200,i="__lodash_hash_undefined__",s=800,l=16,u=9007199254740991,f="[object Arguments]",g="[object Array]",y="[object AsyncFunction]",_="[object Boolean]",A="[object Date]",C="[object Error]",O="[object Function]",w="[object GeneratorFunction]",x="[object Map]",J="[object Number]",sr="[object Null]",Ie="[object Object]",lr="[object Proxy]",cr="[object RegExp]",ur="[object Set]",fr="[object String]",dr="[object Undefined]",pr="[object WeakMap]",gr="[object ArrayBuffer]",hr="[object DataView]",br="[object Float32Array]",yr="[object Float64Array]",mr="[object Int8Array]",vr="[object Int16Array]",_r="[object Int32Array]",wr="[object Uint8Array]",kr="[object Uint8ClampedArray]",Tr="[object Uint16Array]",Cr="[object Uint32Array]",Ar=/[\\^$.*+?()[\]{}|]/g,Sr=/^\[object .+?Constructor\]$/,Ir=/^(?:0|[1-9]\d*)$/,b={};b[br]=b[yr]=b[mr]=b[vr]=b[_r]=b[wr]=b[kr]=b[Tr]=b[Cr]=!0,b[f]=b[g]=b[gr]=b[_]=b[hr]=b[A]=b[C]=b[O]=b[x]=b[J]=b[Ie]=b[cr]=b[ur]=b[fr]=b[pr]=!1;var $e=typeof G=="object"&&G&&G.Object===Object&&G,$r=typeof self=="object"&&self&&self.Object===Object&&self,D=$e||$r||Function("return this")(),Oe=t&&!t.nodeType&&t,B=Oe&&!0&&o&&!o.nodeType&&o,je=B&&B.exports===Oe,ne=je&&$e.process,xe=function(){try{var e=B&&B.require&&B.require("util").types;return e||ne&&ne.binding&&ne.binding("util")}catch{}}(),Ee=xe&&xe.isTypedArray;function Or(e,n,a){switch(a.length){case 0:return e.call(n);case 1:return e.call(n,a[0]);case 2:return e.call(n,a[0],a[1]);case 3:return e.call(n,a[0],a[1],a[2])}return e.apply(n,a)}function jr(e,n){for(var a=-1,c=Array(e);++a<e;)c[a]=n(a);return c}function xr(e){return function(n){return e(n)}}function Er(e,n){return e==null?void 0:e[n]}function Rr(e,n){return function(a){return e(n(a))}}var Pr=Array.prototype,Lr=Function.prototype,W=Object.prototype,oe=D["__core-js_shared__"],K=Lr.toString,j=W.hasOwnProperty,Re=function(){var e=/[^.]+$/.exec(oe&&oe.keys&&oe.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Pe=W.toString,Mr=K.call(Object),Nr=RegExp("^"+K.call(j).replace(Ar,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Z=je?D.Buffer:void 0,Le=D.Symbol,Me=D.Uint8Array;Z&&Z.allocUnsafe;var Ne=Rr(Object.getPrototypeOf,Object),ze=Object.create,zr=W.propertyIsEnumerable,Fr=Pr.splice,E=Le?Le.toStringTag:void 0,V=function(){try{var e=se(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Dr=Z?Z.isBuffer:void 0,Fe=Math.max,Br=Date.now,De=se(D,"Map"),U=se(Object,"create"),Ur=function(){function e(){}return function(n){if(!P(n))return{};if(ze)return ze(n);e.prototype=n;var a=new e;return e.prototype=void 0,a}}();function R(e){var n=-1,a=e==null?0:e.length;for(this.clear();++n<a;){var c=e[n];this.set(c[0],c[1])}}function Hr(){this.__data__=U?U(null):{},this.size=0}function qr(e){var n=this.has(e)&&delete this.__data__[e];return this.size-=n?1:0,n}function Gr(e){var n=this.__data__;if(U){var a=n[e];return a===i?void 0:a}return j.call(n,e)?n[e]:void 0}function Jr(e){var n=this.__data__;return U?n[e]!==void 0:j.call(n,e)}function Wr(e,n){var a=this.__data__;return this.size+=this.has(e)?0:1,a[e]=U&&n===void 0?i:n,this}R.prototype.clear=Hr,R.prototype.delete=qr,R.prototype.get=Gr,R.prototype.has=Jr,R.prototype.set=Wr;function $(e){var n=-1,a=e==null?0:e.length;for(this.clear();++n<a;){var c=e[n];this.set(c[0],c[1])}}function Kr(){this.__data__=[],this.size=0}function Zr(e){var n=this.__data__,a=X(n,e);if(a<0)return!1;var c=n.length-1;return a==c?n.pop():Fr.call(n,a,1),--this.size,!0}function Vr(e){var n=this.__data__,a=X(n,e);return a<0?void 0:n[a][1]}function Xr(e){return X(this.__data__,e)>-1}function Yr(e,n){var a=this.__data__,c=X(a,e);return c<0?(++this.size,a.push([e,n])):a[c][1]=n,this}$.prototype.clear=Kr,$.prototype.delete=Zr,$.prototype.get=Vr,$.prototype.has=Xr,$.prototype.set=Yr;function L(e){var n=-1,a=e==null?0:e.length;for(this.clear();++n<a;){var c=e[n];this.set(c[0],c[1])}}function Qr(){this.size=0,this.__data__={hash:new R,map:new(De||$),string:new R}}function en(e){var n=Q(this,e).delete(e);return this.size-=n?1:0,n}function tn(e){return Q(this,e).get(e)}function rn(e){return Q(this,e).has(e)}function nn(e,n){var a=Q(this,e),c=a.size;return a.set(e,n),this.size+=a.size==c?0:1,this}L.prototype.clear=Qr,L.prototype.delete=en,L.prototype.get=tn,L.prototype.has=rn,L.prototype.set=nn;function M(e){var n=this.__data__=new $(e);this.size=n.size}function on(){this.__data__=new $,this.size=0}function an(e){var n=this.__data__,a=n.delete(e);return this.size=n.size,a}function sn(e){return this.__data__.get(e)}function ln(e){return this.__data__.has(e)}function cn(e,n){var a=this.__data__;if(a instanceof $){var c=a.__data__;if(!De||c.length<r-1)return c.push([e,n]),this.size=++a.size,this;a=this.__data__=new L(c)}return a.set(e,n),this.size=a.size,this}M.prototype.clear=on,M.prototype.delete=an,M.prototype.get=sn,M.prototype.has=ln,M.prototype.set=cn;function un(e,n){var a=ue(e),c=!a&&ce(e),d=!a&&!c&&Ge(e),h=!a&&!c&&!d&&We(e),m=a||c||d||h,p=m?jr(e.length,String):[],v=p.length;for(var S in e)m&&(S=="length"||d&&(S=="offset"||S=="parent")||h&&(S=="buffer"||S=="byteLength"||S=="byteOffset")||He(S,v))||p.push(S);return p}function ae(e,n,a){(a!==void 0&&!ee(e[n],a)||a===void 0&&!(n in e))&&ie(e,n,a)}function fn(e,n,a){var c=e[n];(!(j.call(e,n)&&ee(c,a))||a===void 0&&!(n in e))&&ie(e,n,a)}function X(e,n){for(var a=e.length;a--;)if(ee(e[a][0],n))return a;return-1}function ie(e,n,a){n=="__proto__"&&V?V(e,n,{configurable:!0,enumerable:!0,value:a,writable:!0}):e[n]=a}var dn=An();function Y(e){return e==null?e===void 0?dr:sr:E&&E in Object(e)?Sn(e):En(e)}function Be(e){return H(e)&&Y(e)==f}function pn(e){if(!P(e)||jn(e))return!1;var n=de(e)?Nr:Sr;return n.test(Mn(e))}function gn(e){return H(e)&&Je(e.length)&&!!b[Y(e)]}function hn(e){if(!P(e))return xn(e);var n=qe(e),a=[];for(var c in e)c=="constructor"&&(n||!j.call(e,c))||a.push(c);return a}function Ue(e,n,a,c,d){e!==n&&dn(n,function(h,m){if(d||(d=new M),P(h))bn(e,n,m,a,Ue,c,d);else{var p=c?c(le(e,m),h,m+"",e,n,d):void 0;p===void 0&&(p=h),ae(e,m,p)}},Ke)}function bn(e,n,a,c,d,h,m){var p=le(e,a),v=le(n,a),S=m.get(v);if(S){ae(e,a,S);return}var T=h?h(p,v,a+"",e,n,m):void 0,q=T===void 0;if(q){var pe=ue(v),ge=!pe&&Ge(v),Ve=!pe&&!ge&&We(v);T=v,pe||ge||Ve?ue(p)?T=p:Nn(p)?T=kn(p):ge?(q=!1,T=vn(v)):Ve?(q=!1,T=wn(v)):T=[]:zn(v)||ce(v)?(T=p,ce(p)?T=Fn(p):(!P(p)||de(p))&&(T=In(v))):q=!1}q&&(m.set(v,T),d(T,v,c,h,m),m.delete(v)),ae(e,a,T)}function yn(e,n){return Pn(Rn(e,n,Ze),e+"")}var mn=V?function(e,n){return V(e,"toString",{configurable:!0,enumerable:!1,value:Bn(n),writable:!0})}:Ze;function vn(e,n){return e.slice()}function _n(e){var n=new e.constructor(e.byteLength);return new Me(n).set(new Me(e)),n}function wn(e,n){var a=_n(e.buffer);return new e.constructor(a,e.byteOffset,e.length)}function kn(e,n){var a=-1,c=e.length;for(n||(n=Array(c));++a<c;)n[a]=e[a];return n}function Tn(e,n,a,c){var d=!a;a||(a={});for(var h=-1,m=n.length;++h<m;){var p=n[h],v=void 0;v===void 0&&(v=e[p]),d?ie(a,p,v):fn(a,p,v)}return a}function Cn(e){return yn(function(n,a){var c=-1,d=a.length,h=d>1?a[d-1]:void 0,m=d>2?a[2]:void 0;for(h=e.length>3&&typeof h=="function"?(d--,h):void 0,m&&$n(a[0],a[1],m)&&(h=d<3?void 0:h,d=1),n=Object(n);++c<d;){var p=a[c];p&&e(n,p,c,h)}return n})}function An(e){return function(n,a,c){for(var d=-1,h=Object(n),m=c(n),p=m.length;p--;){var v=m[++d];if(a(h[v],v,h)===!1)break}return n}}function Q(e,n){var a=e.__data__;return On(n)?a[typeof n=="string"?"string":"hash"]:a.map}function se(e,n){var a=Er(e,n);return pn(a)?a:void 0}function Sn(e){var n=j.call(e,E),a=e[E];try{e[E]=void 0;var c=!0}catch{}var d=Pe.call(e);return c&&(n?e[E]=a:delete e[E]),d}function In(e){return typeof e.constructor=="function"&&!qe(e)?Ur(Ne(e)):{}}function He(e,n){var a=typeof e;return n=n??u,!!n&&(a=="number"||a!="symbol"&&Ir.test(e))&&e>-1&&e%1==0&&e<n}function $n(e,n,a){if(!P(a))return!1;var c=typeof n;return(c=="number"?fe(a)&&He(n,a.length):c=="string"&&n in a)?ee(a[n],e):!1}function On(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function jn(e){return!!Re&&Re in e}function qe(e){var n=e&&e.constructor,a=typeof n=="function"&&n.prototype||W;return e===a}function xn(e){var n=[];if(e!=null)for(var a in Object(e))n.push(a);return n}function En(e){return Pe.call(e)}function Rn(e,n,a){return n=Fe(n===void 0?e.length-1:n,0),function(){for(var c=arguments,d=-1,h=Fe(c.length-n,0),m=Array(h);++d<h;)m[d]=c[n+d];d=-1;for(var p=Array(n+1);++d<n;)p[d]=c[d];return p[n]=a(m),Or(e,this,p)}}function le(e,n){if(!(n==="constructor"&&typeof e[n]=="function")&&n!="__proto__")return e[n]}var Pn=Ln(mn);function Ln(e){var n=0,a=0;return function(){var c=Br(),d=l-(c-a);if(a=c,d>0){if(++n>=s)return arguments[0]}else n=0;return e.apply(void 0,arguments)}}function Mn(e){if(e!=null){try{return K.call(e)}catch{}try{return e+""}catch{}}return""}function ee(e,n){return e===n||e!==e&&n!==n}var ce=Be(function(){return arguments}())?Be:function(e){return H(e)&&j.call(e,"callee")&&!zr.call(e,"callee")},ue=Array.isArray;function fe(e){return e!=null&&Je(e.length)&&!de(e)}function Nn(e){return H(e)&&fe(e)}var Ge=Dr||Un;function de(e){if(!P(e))return!1;var n=Y(e);return n==O||n==w||n==y||n==lr}function Je(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=u}function P(e){var n=typeof e;return e!=null&&(n=="object"||n=="function")}function H(e){return e!=null&&typeof e=="object"}function zn(e){if(!H(e)||Y(e)!=Ie)return!1;var n=Ne(e);if(n===null)return!0;var a=j.call(n,"constructor")&&n.constructor;return typeof a=="function"&&a instanceof a&&K.call(a)==Mr}var We=Ee?xr(Ee):gn;function Fn(e){return Tn(e,Ke(e))}function Ke(e){return fe(e)?un(e):hn(e)}var Dn=Cn(function(e,n,a,c){Ue(e,n,a,c)});function Bn(e){return function(){return e}}function Ze(e){return e}function Un(){return!1}o.exports=Dn}(z,z.exports)),z.exports}var Kt=Wt();const Zt=Jt(Kt);function Vt(o){let t={};function r(i,s){if((s==null?void 0:s.type)==="AwaitExpression"&&s.argument.type==="CallExpression"&&s.argument.callee.type==="Identifier"&&s.argument.callee.name==="useStoryblok"){const l=s.argument.arguments;if(l&&l[1].type==="ObjectExpression"){const u=Ae(l[1].properties);t={...t,apiOptions:u}}if(l&&l[2].type==="ObjectExpression"){const u=Ae(l[2].properties);t={...t,bridgeOptions:u}}}}return Zt({},o,r),t}function Ae(o){const t={};return o.reduce((r,i)=>{if(i.type!=="Property")return r;const{key:s,value:l}=i,{type:u}=l;if(s.type!=="Identifier")return r;if(u==="Literal")r[s.name]=l.value;else if(u==="ArrayExpression"){const f=l.elements.reduce((g,y)=>y.type==="Literal"&&y.value?[...g,y.value]:g,[]);r[s.name]=f}return r},t)}let F=[];function Xt(o,t){const r="virtual:storyblok-bridge",i=`\0${r}`;if(!o||t!=="server")return{name:"vite-plugin-storyblok-bridge",resolveId(f){if(f===r)return i},load(f){if(f===i)return"export const bridgeOptions = null"}};let s=[],l=null,u;return{name:"vite-plugin-storyblok-bridge",async resolveId(f){if(f===r)return i},async transform(f,g){var w;if(g.includes("node_modules")&&!g.includes("/pages/")||!f.includes("useStoryblok"))return;const _=this.getModuleInfo(g);if(!((w=_==null?void 0:_.meta)!=null&&w.astro))return;const[,...A]=g.split("src/pages/"),C=A.join("/").replace(".astro",""),O=Vt(this.parse(f));F.length&&(s=F.filter(x=>x.url!==C)),s.push({url:C,options:O}),l&&(u&&clearTimeout(u),u=setTimeout(()=>{Yt(F,s)||(F.length!==0&&(l==null||l.restart(),console.info("Bridge options updated. Restarting...")),F=[...s])},1e3))},async load(f){if(f===i)return`export const bridgeOptions = ${JSON.stringify(Gt(s))}`},configureServer(f){l=f}}}function Yt(o=[],t=[]){return t.every(({url:r,options:i})=>{const s=o.find(l=>(l==null?void 0:l.url)===r);return s&&JSON.stringify(i)===JSON.stringify(s.options)})}const Qt=`<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
35
+ <g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
36
+ <g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
37
+ <g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
38
+ <path d="M2.32662261,0 C1.03405449,0 0,1.0331384 0,2.27290448 L0,42.8752437 C0,44.1150097 1.03405449,44.8898635 2.27491989,44.8898635 L8.27243596,44.8898635 L8.27243596,53 L15.7176283,44.9415205 L42.9132615,44.9415205 C44.1541269,44.9415205 44.9296678,44.1666667 44.9296678,42.8752437 L44.9296678,2.3245614 C44.9296678,1.08479532 44.2058296,0 42.9132615,0 L2.32662261,0 Z" id="Shape-path-Copy" fill="#0AB3AF"></path>
39
+ <path d="M29.1016723,8.11483254 C30.1351059,8.11483254 31.0135245,8.32132604 31.8402713,8.78593643 C32.6153465,9.19892344 33.33875,9.76678059 33.9071385,10.4378845 C35.0647615,11.8482391 35.6869248,13.6215753 35.6639755,15.445352 C35.6639755,16.7875598 35.3022738,18.0781442 34.630542,19.3171053 C33.9341248,20.5632996 32.8438147,21.5436614 31.5302412,22.1047676 C33.183735,22.569378 34.4755269,23.395352 35.4572888,24.5826897 C36.387379,25.8216507 36.8524241,27.4219754 36.8524241,29.4352871 C36.8524241,30.7258715 36.6168825,31.8756998 36.1290206,32.7391832 C35.6123039,33.668404 34.8372287,34.4427546 33.9071385,35.0106118 C32.9253766,35.6300923 31.8402713,36.1979494 30.600151,36.4560663 C29.3600307,36.7658066 28.0165671,37.0239234 26.6214318,37.0239234 L8.32965751,37.0239234 L8.32965751,8.11483254 L29.1016723,8.11483254 Z M26.1340815,24.271851 L15.77813,24.271851 L15.77813,29.1552028 L25.8851404,29.1552028 C26.4825991,29.1552028 27.0302696,28.9110352 27.4783637,28.5203671 C27.8766695,28.1296989 28.1256107,27.5436967 28.1256107,26.811194 C28.140051,26.1827412 27.948041,25.5663945 27.5779401,25.0531873 C27.1796343,24.5648522 26.7315403,24.271851 26.1340815,24.271851 Z M25.2876816,14.5051475 L15.77813,14.5051475 L15.77813,18.9001641 L25.0885287,18.9001641 C25.586411,18.9001641 26.0842933,18.6559965 26.4825991,18.3629954 C26.9306932,18.0699943 27.1298461,17.4351586 27.1298461,16.6049888 C27.1298461,15.872486 26.9306932,15.3353173 26.5821756,14.9934827 C26.233658,14.7004816 25.7855639,14.5051475 25.2876816,14.5051475 Z" id="Combined-Shape-Copy-3" fill="#FFFFFF"></path>
40
+ </g>
41
+ </g>
42
+ </g>
43
+ </svg>`;let Se;async function er(o){const{action:t,story:r}=o||{};if(t==="input"&&r){const i=async()=>{const l=await rr(r),u=document.body;if(l.outerHTML===u.outerHTML)return;const f=document.querySelector('[data-blok-focused="true"]');tr(u,l,f)};clearTimeout(Se),Se=setTimeout(i,500)}["published","change"].includes(o==null?void 0:o.action)&&location.reload()}function tr(o,t,r){if(r){const i=r.getAttribute("data-blok-uid"),s=t.querySelector(`[data-blok-uid="${i}"]`);s&&(s.setAttribute("data-blok-focused","true"),r.replaceWith(s))}else o.replaceWith(t)}async function rr(o){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...o,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function nr(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function or(o,t={},r={},i){var l;if(!globalThis.storyblokApiInstance)throw new Error("storyblokApiInstance has not been initialized correctly");let s=null;if(i&&i.locals._storyblok_preview_data)s=i.locals._storyblok_preview_data;else{const{data:u}=await((l=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:l.get(o,t));s=u.story}return s}function ar(o,t){var i;const r=(i=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:i.richTextResolver;if(!r)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Ht(o,t,r)}function ir(o){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...o};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:i,addDevToolbarApp:s,addMiddleware:l,config:u})=>{if(i({vite:{plugins:[N(t.accessToken,t.useCustomApi,t.apiOptions),ot(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),at(t),Xt(t.livePreview,u.output)]}}),t.livePreview&&(u==null?void 0:u.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");if(r("page-ssr",`
44
+ import { storyblokApiInstance } from "virtual:storyblok-init";
45
+ globalThis.storyblokApiInstance = storyblokApiInstance;
46
+ `),t.bridge&&!t.livePreview){let f="";if(typeof t.bridge=="object"){const g={...t.bridge};f=`const storyblokInstance = new StoryblokBridge(${JSON.stringify(g)});`}else f="const storyblokInstance = new StoryblokBridge()";r("page",`
47
+ import { loadStoryblokBridge } from "@storyblok/astro";
48
+ loadStoryblokBridge().then(() => {
49
+ const { StoryblokBridge, location } = window;
50
+ ${f}
51
+
52
+ storyblokInstance.on(["published", "change"], (event) => {
53
+ if (!event.slugChanged) {
54
+ location.reload(true);
55
+ }
56
+ });
57
+ });
58
+ `)}t.livePreview&&(r("page",`
59
+ import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
60
+ import { bridgeOptions } from "virtual:storyblok-bridge";
61
+ console.info("The Storyblok Astro live preview feature is currently in an experimental phase, and its API is subject to change in the future.")
62
+ loadStoryblokBridge().then(() => {
63
+ const { StoryblokBridge, location } = window;
64
+ if(bridgeOptions){
65
+ const storyblokInstance = new StoryblokBridge(bridgeOptions);
66
+ storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
67
+ };
68
+ });
69
+ `),l({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),s({id:"storyblok",name:"Storyblok",icon:Qt,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}k.RichTextResolver=Te,k.RichTextSchema=we,k.default=ir,k.handleStoryblokMessage=er,k.loadStoryblokBridge=qt,k.renderRichText=ar,k.storyblokEditable=zt,k.toCamelCase=re,k.useStoryblok=or,k.useStoryblokApi=nr,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,12 @@
1
+ export type { ArrayFn, AsyncFn, ISbAlternateObject, // previously AlternateObject
2
+ ISbCache, // previously StoryblokCache
3
+ ISbConfig, // previously StoryblokConfig
4
+ ISbContentMangmntAPI, ISbDimensions, ISbError, ISbEventPayload, ISbManagmentApiResult, // previously StoryblokManagmentApiResult
5
+ ISbNode, ISbResponse, ISbResult, // previously StoryblokResult
6
+ ISbRichtext, // previously Richtext
7
+ ISbSchema, ISbStories, // previously Stories
8
+ ISbStoriesParams, // previously StoriesParams
9
+ ISbStory, // previously Story
10
+ ISbStoryData, // previously StoryData
11
+ ISbStoryParams, // previously StoryParams
12
+ SbBlokData, SbBlokKeyDataTypes, SbPluginFactory, SbRichTextOptions, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, } from '@storyblok/js';
@@ -0,0 +1,3 @@
1
+ import { StoryblokBridgeConfigV2 } from '@storyblok/js';
2
+ import { RawCode } from '../vite-plugins/vite-plugin-storyblok-bridge';
3
+ export declare function generateFinalBridgeObject(rawCode: RawCode): StoryblokBridgeConfigV2;
@@ -1,5 +1,5 @@
1
- import type { RawCodeItemOptions } from "../vite-plugins/vite-plugin-storyblok-bridge";
2
- import type { Rollup } from "vite";
1
+ import { RawCodeItemOptions } from '../vite-plugins/vite-plugin-storyblok-bridge';
2
+ import { Rollup } from 'vite';
3
3
  /**
4
4
  * Parses through the Abstract Syntax Tree (AST) code to locate the 'useStoryblok' function and its properties.
5
5
  * This functionality is crucial for generating a virtual module that can be utilized during the initialization of the Storyblok bridge.
@@ -0,0 +1 @@
1
+ export declare function toCamelCase(str: string): string;
@@ -1,5 +1,5 @@
1
- import type { ISbStoriesParams, StoryblokBridgeConfigV2 } from "@storyblok/js";
2
- import type { Plugin } from "vite";
1
+ import { ISbStoriesParams, StoryblokBridgeConfigV2 } from '@storyblok/js';
2
+ import { Plugin } from 'vite';
3
3
  export interface RawCodeItem {
4
4
  url: string;
5
5
  options?: RawCodeItemOptions;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function vitePluginStoryblokComponents(componentsDir: string, components?: Record<string, string>, enableFallbackComponent?: boolean, customFallbackComponent?: string): Plugin;
@@ -0,0 +1,3 @@
1
+ import { ISbConfig } from '../types';
2
+ import { Plugin } from 'vite';
3
+ export declare function vitePluginStoryblokInit(accessToken: string, useCustomApi: boolean, apiOptions?: ISbConfig): Plugin;
@@ -1,2 +1,2 @@
1
- import type { Plugin } from "vite";
1
+ import { Plugin } from 'vite';
2
2
  export declare function vitePluginStoryblokOptions(options: object): Plugin;
package/package.json CHANGED
@@ -1,90 +1,151 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "5.1.0-next.1",
3
+ "type": "module",
4
+ "version": "5.1.0",
5
+ "private": false,
6
+ "packageManager": "pnpm@9.13.2",
4
7
  "description": "Official Astro integration for the Storyblok Headless CMS",
5
- "main": "./dist/storyblok-astro.js",
6
- "module": "./dist/storyblok-astro.mjs",
7
- "files": [
8
- "dist",
9
- "components",
10
- "dev-toolbar",
11
- "live-preview",
12
- "utils"
8
+ "author": "Storyblok",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/storyblok/storyblok-astro"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/storyblok/storyblok-astro/issues"
16
+ },
17
+ "keywords": [
18
+ "astro",
19
+ "storyblok",
20
+ "astro-sdk"
13
21
  ],
14
22
  "exports": {
15
23
  ".": {
16
- "types": "./dist/types/index.d.ts",
17
- "import": "./dist/storyblok-astro.mjs",
18
- "require": "./dist/storyblok-astro.js"
19
- },
20
- "./StoryblokComponent.astro": {
21
- "types": "./components/StoryblokComponent.ts",
22
- "import": "./components/StoryblokComponent.ts",
23
- "require": "./components/StoryblokComponent.ts"
24
+ "types": "./dist/storyblok-astro.d.ts",
25
+ "import": "./dist/storyblok-astro.es.js",
26
+ "require": "./dist/storyblok-astro.umd.js"
24
27
  },
25
- "./FallbackComponent.astro": {
26
- "types": "./components/FallbackComponent.ts",
27
- "import": "./components/FallbackComponent.ts",
28
- "require": "./components/FallbackComponent.ts"
28
+ "./middleware.ts": {
29
+ "types": "./dist/live-preview/middleware.d.ts",
30
+ "import": "./dist/live-preview/middleware.ts",
31
+ "require": "./dist/live-preview/middleware.ts"
29
32
  },
30
33
  "./toolbarApp.ts": {
31
- "types": "./dev-toolbar/toolbarApp.ts",
32
- "import": "./dev-toolbar/toolbarApp.ts",
33
- "require": "./dev-toolbar/toolbarApp.ts"
34
+ "types": "./dist/dev-toolbar/toolbarApp.d.ts",
35
+ "import": "./dist/dev-toolbar/toolbarApp.ts",
36
+ "require": "./dist/dev-toolbar/toolbarApp.ts"
34
37
  },
35
- "./middleware.ts": {
36
- "types": "./live-preview/middleware.ts",
37
- "import": "./live-preview/middleware.ts",
38
- "require": "./live-preview/middleware.ts"
38
+ "./FallbackComponent.astro": "./dist/components/FallbackComponent.astro",
39
+ "./StoryblokComponent.astro": {
40
+ "types": "./dist/components/StoryblokComponent.d.ts",
41
+ "import": "./dist/components/StoryblokComponent.astro",
42
+ "require": "./dist/components/StoryblokComponent.astro"
39
43
  }
40
44
  },
41
- "types": "./dist/types/index.d.ts",
45
+ "main": "./dist/storyblok-astro.es.js",
46
+ "module": "./dist/storyblok-astro.js",
47
+ "types": "./dist/storyblok-astro.d.ts",
48
+ "files": [
49
+ "*.d.ts",
50
+ "dist"
51
+ ],
42
52
  "scripts": {
43
- "dev": "vite build --watch",
44
- "build": "vite build",
45
- "test": "npm run test:e2e",
46
- "test:e2e": "start-server-and-test cy:playground http-get://localhost:4321/ cy:run",
47
- "test:e2e-watch": "start-server-and-test cy:playground http-get://localhost:4321/ cy:open",
48
- "cy:playground": "npm run dev --prefix ../playground-test",
53
+ "dev": "vite",
54
+ "build": "vite build && tsc --project tsconfig.json",
55
+ "playground": "pnpm run --filter ./playground/ssg dev",
56
+ "playground:ssr": "pnpm run --filter ./playground/ssr dev",
57
+ "playground:test": "pnpm run --filter ./playground/test dev",
58
+ "lint": "eslint .",
59
+ "lint:fix": "eslint . --fix",
60
+ "lint:playground": "pnpm -r --parallel --filter='./playground/*' run lint",
61
+ "lint:playground:fix": "pnpm -r --parallel --filter='./playground/*' run lint:fix",
62
+ "test": "pnpm run test:unit:ci && pnpm run test:e2e",
63
+ "test:unit": "vitest",
64
+ "test:unit:ci": "vitest run",
65
+ "test:e2e": "start-server-and-test playground:test http://localhost:4321/ cy:run",
66
+ "test:e2e-watch": "start-server-and-test playground:test http://localhost:4321/ cy:open",
49
67
  "cy:run": "cypress run",
50
- "cy:open": "cypress open",
51
- "prepublishOnly": "npm run build && cp ../README.md ./"
68
+ "cy:open": "cypress open"
69
+ },
70
+ "peerDependencies": {
71
+ "astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
52
72
  },
53
73
  "dependencies": {
54
- "@storyblok/js": "^3.0.8",
74
+ "@storyblok/js": "^3.1.9",
55
75
  "camelcase": "^8.0.0",
56
76
  "lodash.mergewith": "^4.6.2"
57
77
  },
58
78
  "devDependencies": {
59
- "@cypress/vite-dev-server": "^5.0.7",
60
- "@rollup/plugin-dynamic-import-vars": "^2.1.2",
79
+ "@commitlint/cli": "^19.5.0",
80
+ "@commitlint/config-conventional": "^19.5.0",
81
+ "@cypress/vite-dev-server": "^5.2.0",
82
+ "@rollup/plugin-dynamic-import-vars": "^2.1.5",
83
+ "@storyblok/eslint-config": "^0.3.0",
61
84
  "@types/lodash.mergewith": "^4.6.9",
62
- "@types/node": "20.14.9",
63
- "astro": "^4.12.1",
64
- "cypress": "^13.12.0",
65
- "eslint-plugin-cypress": "^3.2.0",
66
- "start-server-and-test": "^2.0.4",
67
- "typescript": "5.4.5",
68
- "vite": "^5.3.1",
69
- "vite-plugin-dts": "^3.7.3"
85
+ "@types/node": "22.10.2",
86
+ "astro": "^5.0.9",
87
+ "cypress": "^13.15.2",
88
+ "eslint": "^9.15.0",
89
+ "eslint-config-prettier": "^9.1.0",
90
+ "eslint-plugin-astro": "^1.3.1",
91
+ "eslint-plugin-cypress": "^4.1.0",
92
+ "lint-staged": "^15.2.10",
93
+ "prettier": "^3.3.3",
94
+ "prettier-plugin-astro": "^0.13.0",
95
+ "simple-git-hooks": "^2.11.1",
96
+ "start-server-and-test": "^2.0.8",
97
+ "typescript": "5.7.2",
98
+ "vite": "^6.0.1",
99
+ "vite-plugin-dts": "^4.3.0",
100
+ "vite-plugin-static-copy": "^2.2.0",
101
+ "vitest": "^2.1.8"
70
102
  },
71
- "peerDependencies": {
72
- "astro": "^3.0.0 || ^4.0.0"
103
+ "simple-git-hooks": {
104
+ "pre-commit": "pnpm lint",
105
+ "pre-push": "pnpm commitlint --last --verbose"
73
106
  },
74
- "repository": {
75
- "type": "git",
76
- "url": "https://github.com/storyblok/storyblok-astro"
107
+ "lint-staged": {
108
+ "*.{astro,js,css}": [
109
+ "prettier --write",
110
+ "eslint"
111
+ ],
112
+ "*.md": [
113
+ "prettier --write"
114
+ ]
77
115
  },
78
- "keywords": [
79
- "astro",
80
- "storyblok",
81
- "astro-component"
82
- ],
83
- "author": "Alexander Feiglstorfer",
84
- "bugs": {
85
- "url": "https://github.com/storyblok/storyblok-astro/issues"
116
+ "commitlint": {
117
+ "extends": [
118
+ "@commitlint/config-conventional"
119
+ ]
120
+ },
121
+ "eslintConfig": {
122
+ "env": {
123
+ "node": true
124
+ },
125
+ "parserOptions": {
126
+ "ecmaVersion": "latest",
127
+ "sourceType": "module"
128
+ },
129
+ "extends": [
130
+ "plugin:astro/recommended",
131
+ "prettier"
132
+ ],
133
+ "globals": {
134
+ "globalThis": true
135
+ },
136
+ "overrides": [
137
+ {
138
+ "files": [
139
+ "*.astro"
140
+ ],
141
+ "parser": "astro-eslint-parser",
142
+ "parserOptions": {
143
+ "parser": "@typescript-eslint/parser"
144
+ }
145
+ }
146
+ ],
147
+ "ignorePatterns": "dist/"
86
148
  },
87
- "homepage": "https://github.com/storyblok/storyblok-astro",
88
149
  "release": {
89
150
  "branches": [
90
151
  "main",
@@ -1,2 +0,0 @@
1
- import FallbackComponent from "./FallbackComponent.astro";
2
- export default FallbackComponent;
@@ -1,2 +0,0 @@
1
- import StoryblokComponent from "./StoryblokComponent.astro";
2
- export default StoryblokComponent;
@@ -1,68 +0,0 @@
1
- (function(T,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(T=typeof globalThis<"u"?globalThis:T||self,N(T.storyblokAstro={}))})(this,function(T){"use strict";function N(o,t,r){const s="virtual:storyblok-init",a="\0"+s;return{name:"vite-plugin-storyblok-init",async resolveId(l){if(l===s)return a},async load(l){if(l===a)return`
2
- import { storyblokInit, apiPlugin } from "@storyblok/js";
3
- const { storyblokApi } = storyblokInit({
4
- accessToken: "${o}",
5
- use: ${t?"[]":"[apiPlugin]"},
6
- apiOptions: ${JSON.stringify(r)},
7
- });
8
- export const storyblokApiInstance = storyblokApi;
9
- `}}}const Ve=/[\p{Lu}]/u,Xe=/[\p{Ll}]/u,ge=/^[\p{Lu}](?![\p{Lu}])/gu,he=/([\p{Alpha}\p{N}_]|$)/u,te=/[_.\- ]+/,Ze=new RegExp("^"+te.source),be=new RegExp(te.source+he.source,"gu"),ye=new RegExp("\\d+"+he.source,"gu"),Qe=(o,t,r,s)=>{let a=!1,l=!1,u=!1,f=!1;for(let d=0;d<o.length;d++){const y=o[d];f=d>2?o[d-3]==="-":!0,a&&Ve.test(y)?(o=o.slice(0,d)+"-"+o.slice(d),a=!1,u=l,l=!0,d++):l&&u&&Xe.test(y)&&(!f||s)?(o=o.slice(0,d-1)+"-"+o.slice(d-1),u=l,l=!1,a=!0):(a=t(y)===y&&r(y)!==y,u=l,l=r(y)===y&&t(y)!==y)}return o},et=(o,t)=>(ge.lastIndex=0,o.replaceAll(ge,r=>t(r))),tt=(o,t)=>(be.lastIndex=0,ye.lastIndex=0,o.replaceAll(ye,(r,s,a)=>["_","-"].includes(o.charAt(a+r.length))?r:t(r)).replaceAll(be,(r,s)=>t(s)));function me(o,t){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(o)?o=o.map(l=>l.trim()).filter(l=>l.length).join("-"):o=o.trim(),o.length===0)return"";const r=t.locale===!1?l=>l.toLowerCase():l=>l.toLocaleLowerCase(t.locale),s=t.locale===!1?l=>l.toUpperCase():l=>l.toLocaleUpperCase(t.locale);return o.length===1?te.test(o)?"":t.pascalCase?s(o):r(o):(o!==r(o)&&(o=Qe(o,r,s,t.preserveConsecutiveUppercase)),o=o.replace(Ze,""),o=t.preserveConsecutiveUppercase?et(o,r):r(o),t.pascalCase&&(o=s(o.charAt(0))+o.slice(1)),tt(o,s))}function rt(o,t,r,s){const a="virtual:storyblok-components",l="\0"+a;return{name:"vite-plugin-storyblok-components",async resolveId(u){if(u===a)return l},async load(u){if(u===l){const f=[],d=[];for await(const[_,A]of Object.entries(t)){const I=await this.resolve("/"+o+"/"+A+".astro");if(I)f.push(`import ${me(_)} from "${I.id}"`);else if(r)d.push(_);else throw new Error(`Component could not be found for blok "${_}"! Does "${"/"+o+"/"+A}.astro" exist?`)}let y="";if(r)if(y=",FallbackComponent",s){const _=await this.resolve("/"+o+"/"+s+".astro");if(!_)throw new Error(`Custom fallback component could not be found. Does "${"/"+o+"/"+s}.astro" exist?`);f.push(`import FallbackComponent from "${_.id}"`)}else f.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${f.join(";")};export default {${Object.keys(t).filter(_=>!d.includes(_)).map(_=>me(_)).join(",")}${y}}`;if(r)return`${f[0]}; export default {${y.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
10
- Please register your components or enable the fallback component.
11
- Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function nt(o){const t="virtual:storyblok-options",r="\0"+t;return{name:"vite-plugin-storyblok-options",async resolveId(s){if(s===t)return r},async load(s){if(s===r)return`export default ${JSON.stringify(o)}`}}}let ve=!1;const _e=[],ot=o=>new Promise((t,r)=>{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}ve?a():_e.push(a)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=a=>r(a),s.onload=a=>{_e.forEach(l=>l()),ve=!0,t(a)},document.getElementsByTagName("head")[0].appendChild(s)});var it=Object.defineProperty,st=(o,t,r)=>t in o?it(o,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[t]=r,O=(o,t,r)=>(st(o,typeof t!="symbol"?t+"":t,r),r);class at{constructor(){O(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),O(this,"getOptionsPage",(t,r=25,s=1)=>({...t,per_page:r,page:s})),O(this,"delay",t=>new Promise(r=>setTimeout(r,t))),O(this,"arrayFrom",(t=0,r)=>[...Array(t)].map(r)),O(this,"range",(t=0,r=t)=>{const s=Math.abs(r-t)||0,a=t<r?1:-1;return this.arrayFrom(s,(l,u)=>u*a+t)}),O(this,"asyncMap",async(t,r)=>Promise.all(t.map(r))),O(this,"flatMap",(t=[],r)=>t.map(r).reduce((s,a)=>[...s,...a],[])),O(this,"escapeHTML",function(t){const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},s=/[&<>"']/g,a=RegExp(s.source);return t&&a.test(t)?t.replace(s,l=>r[l]):t})}stringify(t,r,s){const a=[];for(const l in t){if(!Object.prototype.hasOwnProperty.call(t,l))continue;const u=t[l],f=s?"":encodeURIComponent(l);let d;typeof u=="object"?d=this.stringify(u,r?r+encodeURIComponent("["+f+"]"):f,Array.isArray(u)):d=(r?r+encodeURIComponent("["+f+"]"):f)+"="+encodeURIComponent(u),a.push(d)}return a.join("&")}getRegionURL(t){const r="api.storyblok.com",s="api-us.storyblok.com",a="app.storyblokchina.cn",l="api-ap.storyblok.com",u="api-ca.storyblok.com";switch(t){case"us":return s;case"cn":return a;case"ap":return l;case"ca":return u;default:return r}}}const lt=function(o,t){const r={};for(const s in o){const a=o[s];t.indexOf(s)>-1&&a!==null&&(r[s]=a)}return r},ct=o=>o==="email",ut=()=>({singleTag:"hr"}),ft=()=>({tag:"blockquote"}),dt=()=>({tag:"ul"}),pt=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),gt=()=>({singleTag:"br"}),ht=o=>({tag:`h${o.attrs.level}`}),bt=o=>({singleTag:[{tag:"img",attrs:lt(o.attrs,["src","alt","title"])}]}),yt=()=>({tag:"li"}),mt=()=>({tag:"ol"}),vt=()=>({tag:"p"}),_t=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),wt=()=>({tag:"b"}),Tt=()=>({tag:"s"}),kt=()=>({tag:"u"}),At=()=>({tag:"strong"}),St=()=>({tag:"code"}),It=()=>({tag:"i"}),Ot=o=>{if(!o.attrs)return{tag:""};const t=new at().escapeHTML,r={...o.attrs},{linktype:s="url"}=o.attrs;if(delete r.linktype,r.href&&(r.href=t(o.attrs.href||"")),ct(s)&&(r.href=`mailto:${r.href}`),r.anchor&&(r.href=`${r.href}#${r.anchor}`,delete r.anchor),r.custom){for(const a in r.custom)r[a]=r.custom[a];delete r.custom}return{tag:[{tag:"a",attrs:r}]}},Ct=o=>({tag:[{tag:"span",attrs:o.attrs}]}),jt=()=>({tag:"sub"}),$t=()=>({tag:"sup"}),xt=o=>({tag:[{tag:"span",attrs:o.attrs}]}),Et=o=>{var t;return(t=o.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},Rt=o=>{var t;return(t=o.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},we={nodes:{horizontal_rule:ut,blockquote:ft,bullet_list:dt,code_block:pt,hard_break:gt,heading:ht,image:bt,list_item:yt,ordered_list:mt,paragraph:vt,emoji:_t},marks:{bold:wt,strike:Tt,underline:kt,strong:At,code:St,italic:It,link:Ot,styled:Ct,subscript:jt,superscript:$t,anchor:xt,highlight:Et,textStyle:Rt}},Pt=function(o){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,s=RegExp(r.source);return o&&s.test(o)?o.replace(r,a=>t[a]):o};class Te{constructor(t){O(this,"marks"),O(this,"nodes"),t||(t=we),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,r){this.nodes[t]=r}addMark(t,r){this.marks[t]=r}render(t,r={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let s="";return t.content.forEach(a=>{s+=this.renderNode(a)}),r.optimizeImages?this.optimizeImages(s,r.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
12
- The "content" field must be an array of nodes as the type ISbRichtext.
13
- ISbRichtext:
14
- content?: ISbRichtext[]
15
- marks?: ISbRichtext[]
16
- attrs?: any
17
- text?: string
18
- type: string
19
-
20
- Example:
21
- {
22
- content: [
23
- {
24
- content: [
25
- {
26
- text: 'Hello World',
27
- type: 'text'
28
- }
29
- ],
30
- type: 'paragraph'
31
- }
32
- ],
33
- type: 'doc'
34
- }`),""}optimizeImages(t,r){let s=0,a=0,l="",u="";typeof r!="boolean"&&(typeof r.width=="number"&&r.width>0&&(l+=`width="${r.width}" `,s=r.width),typeof r.height=="number"&&r.height>0&&(l+=`height="${r.height}" `,a=r.height),(r.loading==="lazy"||r.loading==="eager")&&(l+=`loading="${r.loading}" `),typeof r.class=="string"&&r.class.length>0&&(l+=`class="${r.class}" `),r.filters&&(typeof r.filters.blur=="number"&&r.filters.blur>=0&&r.filters.blur<=100&&(u+=`:blur(${r.filters.blur})`),typeof r.filters.brightness=="number"&&r.filters.brightness>=-100&&r.filters.brightness<=100&&(u+=`:brightness(${r.filters.brightness})`),r.filters.fill&&(r.filters.fill.match(/[0-9A-Fa-f]{6}/g)||r.filters.fill==="transparent")&&(u+=`:fill(${r.filters.fill})`),r.filters.format&&["webp","png","jpeg"].includes(r.filters.format)&&(u+=`:format(${r.filters.format})`),typeof r.filters.grayscale=="boolean"&&r.filters.grayscale&&(u+=":grayscale()"),typeof r.filters.quality=="number"&&r.filters.quality>=0&&r.filters.quality<=100&&(u+=`:quality(${r.filters.quality})`),r.filters.rotate&&[90,180,270].includes(r.filters.rotate)&&(u+=`:rotate(${r.filters.rotate})`),u.length>0&&(u="/filters"+u))),l.length>0&&(t=t.replace(/<img/g,`<img ${l.trim()}`));const f=s>0||a>0||u.length>0?`${s}x${a}${u}`:"";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/${f}`),typeof r!="boolean"&&(r.sizes||r.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,d=>{var y,_;const A=d.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(A&&A.length>0){const I={srcset:(y=r.srcset)==null?void 0:y.map(w=>{if(typeof w=="number")return`//${A}/m/${w}x0${u} ${w}w`;if(typeof w=="object"&&w.length===2){let L=0,J=0;return typeof w[0]=="number"&&(L=w[0]),typeof w[1]=="number"&&(J=w[1]),`//${A}/m/${L}x${J}${u} ${L}w`}}).join(", "),sizes:(_=r.sizes)==null?void 0:_.map(w=>w).join(", ")};let C="";return I.srcset&&(C+=`srcset="${I.srcset}" `),I.sizes&&(C+=`sizes="${I.sizes}" `),d.replace(/<img/g,`<img ${C.trim()}`)}return d})),t}renderNode(t){const r=[];t.marks&&t.marks.forEach(a=>{const l=this.getMatchingMark(a);l&&l.tag!==""&&r.push(this.renderOpeningTag(l.tag))});const s=this.getMatchingNode(t);return s&&s.tag&&r.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach(a=>{r.push(this.renderNode(a))}):t.text?r.push(Pt(t.text)):s&&s.singleTag?r.push(this.renderTag(s.singleTag," /")):s&&s.html?r.push(s.html):t.type==="emoji"&&r.push(this.renderEmoji(t)),s&&s.tag&&r.push(this.renderClosingTag(s.tag)),t.marks&&t.marks.slice(0).reverse().forEach(a=>{const l=this.getMatchingMark(a);l&&l.tag!==""&&r.push(this.renderClosingTag(l.tag))}),r.join("")}renderTag(t,r){return t.constructor===String?`<${t}${r}>`:t.map(s=>{if(s.constructor===String)return`<${s}${r}>`;{let a=`<${s.tag}`;if(s.attrs)for(const l in s.attrs){const u=s.attrs[l];u!==null&&(a+=` ${l}="${u}"`)}return`${a}${r}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(t){const r=this.nodes[t.type];if(typeof r=="function")return r(t)}getMatchingMark(t){const r=this.marks[t.type];if(typeof r=="function")return r(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const r=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(r," /")}}const Mt=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}:{}}catch{return{}}};let Nt,zt="https://app.storyblok.com/f/storyblok-v2-latest.js";const Lt=(o,t)=>{o.addNode("blok",r=>{let s="";return r.attrs.body.forEach(a=>{s+=t(a.component,a)}),{html:s}})},Bt=o=>!o||!(o!=null&&o.content.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule")),Dt=(o,t,r)=>{let s=r||Nt;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Bt(o)?"":(t&&(s=new Te(t.schema),t.resolver&&Lt(s,t.resolver)),s.render(o))},Ut=()=>ot(zt);function Ft(o){let t={resolveRelations:[]};function r(s){s&&Array.isArray(t.resolveRelations)&&t.resolveRelations.push(...Array.isArray(s)?s:[s])}for(const s of o)if(s.options){const{apiOptions:a,bridgeOptions:l}=s.options;if(r(a==null?void 0:a.resolve_relations),l){const{resolveRelations:u,...f}=l;r(u),Object.assign(t,f)}}return t.resolveRelations=[...new Set(t.resolveRelations)],t}var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ht(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var G={exports:{}};G.exports,function(o,t){var r=200,s="__lodash_hash_undefined__",a=800,l=16,u=9007199254740991,f="[object Arguments]",d="[object Array]",y="[object AsyncFunction]",_="[object Boolean]",A="[object Date]",I="[object Error]",C="[object Function]",w="[object GeneratorFunction]",L="[object Map]",J="[object Number]",rr="[object Null]",Se="[object Object]",nr="[object Proxy]",or="[object RegExp]",ir="[object Set]",sr="[object String]",ar="[object Undefined]",lr="[object WeakMap]",cr="[object ArrayBuffer]",ur="[object DataView]",fr="[object Float32Array]",dr="[object Float64Array]",pr="[object Int8Array]",gr="[object Int16Array]",hr="[object Int32Array]",br="[object Uint8Array]",yr="[object Uint8ClampedArray]",mr="[object Uint16Array]",vr="[object Uint32Array]",_r=/[\\^$.*+?()[\]{}|]/g,wr=/^\[object .+?Constructor\]$/,Tr=/^(?:0|[1-9]\d*)$/,b={};b[fr]=b[dr]=b[pr]=b[gr]=b[hr]=b[br]=b[yr]=b[mr]=b[vr]=!0,b[f]=b[d]=b[cr]=b[_]=b[ur]=b[A]=b[I]=b[C]=b[L]=b[J]=b[Se]=b[or]=b[ir]=b[sr]=b[lr]=!1;var Ie=typeof q=="object"&&q&&q.Object===Object&&q,kr=typeof self=="object"&&self&&self.Object===Object&&self,B=Ie||kr||Function("return this")(),Oe=t&&!t.nodeType&&t,D=Oe&&!0&&o&&!o.nodeType&&o,Ce=D&&D.exports===Oe,re=Ce&&Ie.process,je=function(){try{var e=D&&D.require&&D.require("util").types;return e||re&&re.binding&&re.binding("util")}catch{}}(),$e=je&&je.isTypedArray;function Ar(e,n,i){switch(i.length){case 0:return e.call(n);case 1:return e.call(n,i[0]);case 2:return e.call(n,i[0],i[1]);case 3:return e.call(n,i[0],i[1],i[2])}return e.apply(n,i)}function Sr(e,n){for(var i=-1,c=Array(e);++i<e;)c[i]=n(i);return c}function Ir(e){return function(n){return e(n)}}function Or(e,n){return e==null?void 0:e[n]}function Cr(e,n){return function(i){return e(n(i))}}var jr=Array.prototype,$r=Function.prototype,K=Object.prototype,ne=B["__core-js_shared__"],W=$r.toString,j=K.hasOwnProperty,xe=function(){var e=/[^.]+$/.exec(ne&&ne.keys&&ne.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Ee=K.toString,xr=W.call(Object),Er=RegExp("^"+W.call(j).replace(_r,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Y=Ce?B.Buffer:void 0,Re=B.Symbol,Pe=B.Uint8Array,Me=Y?Y.allocUnsafe:void 0,Ne=Cr(Object.getPrototypeOf,Object),ze=Object.create,Rr=K.propertyIsEnumerable,Pr=jr.splice,x=Re?Re.toStringTag:void 0,V=function(){try{var e=se(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Mr=Y?Y.isBuffer:void 0,Le=Math.max,Nr=Date.now,Be=se(B,"Map"),U=se(Object,"create"),zr=function(){function e(){}return function(n){if(!R(n))return{};if(ze)return ze(n);e.prototype=n;var i=new e;return e.prototype=void 0,i}}();function E(e){var n=-1,i=e==null?0:e.length;for(this.clear();++n<i;){var c=e[n];this.set(c[0],c[1])}}function Lr(){this.__data__=U?U(null):{},this.size=0}function Br(e){var n=this.has(e)&&delete this.__data__[e];return this.size-=n?1:0,n}function Dr(e){var n=this.__data__;if(U){var i=n[e];return i===s?void 0:i}return j.call(n,e)?n[e]:void 0}function Ur(e){var n=this.__data__;return U?n[e]!==void 0:j.call(n,e)}function Fr(e,n){var i=this.__data__;return this.size+=this.has(e)?0:1,i[e]=U&&n===void 0?s:n,this}E.prototype.clear=Lr,E.prototype.delete=Br,E.prototype.get=Dr,E.prototype.has=Ur,E.prototype.set=Fr;function $(e){var n=-1,i=e==null?0:e.length;for(this.clear();++n<i;){var c=e[n];this.set(c[0],c[1])}}function Hr(){this.__data__=[],this.size=0}function qr(e){var n=this.__data__,i=X(n,e);if(i<0)return!1;var c=n.length-1;return i==c?n.pop():Pr.call(n,i,1),--this.size,!0}function Gr(e){var n=this.__data__,i=X(n,e);return i<0?void 0:n[i][1]}function Jr(e){return X(this.__data__,e)>-1}function Kr(e,n){var i=this.__data__,c=X(i,e);return c<0?(++this.size,i.push([e,n])):i[c][1]=n,this}$.prototype.clear=Hr,$.prototype.delete=qr,$.prototype.get=Gr,$.prototype.has=Jr,$.prototype.set=Kr;function P(e){var n=-1,i=e==null?0:e.length;for(this.clear();++n<i;){var c=e[n];this.set(c[0],c[1])}}function Wr(){this.size=0,this.__data__={hash:new E,map:new(Be||$),string:new E}}function Yr(e){var n=Q(this,e).delete(e);return this.size-=n?1:0,n}function Vr(e){return Q(this,e).get(e)}function Xr(e){return Q(this,e).has(e)}function Zr(e,n){var i=Q(this,e),c=i.size;return i.set(e,n),this.size+=i.size==c?0:1,this}P.prototype.clear=Wr,P.prototype.delete=Yr,P.prototype.get=Vr,P.prototype.has=Xr,P.prototype.set=Zr;function M(e){var n=this.__data__=new $(e);this.size=n.size}function Qr(){this.__data__=new $,this.size=0}function en(e){var n=this.__data__,i=n.delete(e);return this.size=n.size,i}function tn(e){return this.__data__.get(e)}function rn(e){return this.__data__.has(e)}function nn(e,n){var i=this.__data__;if(i instanceof $){var c=i.__data__;if(!Be||c.length<r-1)return c.push([e,n]),this.size=++i.size,this;i=this.__data__=new P(c)}return i.set(e,n),this.size=i.size,this}M.prototype.clear=Qr,M.prototype.delete=en,M.prototype.get=tn,M.prototype.has=rn,M.prototype.set=nn;function on(e,n){var i=ce(e),c=!i&&le(e),g=!i&&!c&&qe(e),h=!i&&!c&&!g&&Je(e),m=i||c||g||h,p=m?Sr(e.length,String):[],v=p.length;for(var S in e)(n||j.call(e,S))&&!(m&&(S=="length"||g&&(S=="offset"||S=="parent")||h&&(S=="buffer"||S=="byteLength"||S=="byteOffset")||Fe(S,v)))&&p.push(S);return p}function oe(e,n,i){(i!==void 0&&!ee(e[n],i)||i===void 0&&!(n in e))&&ie(e,n,i)}function sn(e,n,i){var c=e[n];(!(j.call(e,n)&&ee(c,i))||i===void 0&&!(n in e))&&ie(e,n,i)}function X(e,n){for(var i=e.length;i--;)if(ee(e[i][0],n))return i;return-1}function ie(e,n,i){n=="__proto__"&&V?V(e,n,{configurable:!0,enumerable:!0,value:i,writable:!0}):e[n]=i}var an=_n();function Z(e){return e==null?e===void 0?ar:rr:x&&x in Object(e)?wn(e):On(e)}function De(e){return F(e)&&Z(e)==f}function ln(e){if(!R(e)||Sn(e))return!1;var n=fe(e)?Er:wr;return n.test(xn(e))}function cn(e){return F(e)&&Ge(e.length)&&!!b[Z(e)]}function un(e){if(!R(e))return In(e);var n=He(e),i=[];for(var c in e)c=="constructor"&&(n||!j.call(e,c))||i.push(c);return i}function Ue(e,n,i,c,g){e!==n&&an(n,function(h,m){if(g||(g=new M),R(h))fn(e,n,m,i,Ue,c,g);else{var p=c?c(ae(e,m),h,m+"",e,n,g):void 0;p===void 0&&(p=h),oe(e,m,p)}},Ke)}function fn(e,n,i,c,g,h,m){var p=ae(e,i),v=ae(n,i),S=m.get(v);if(S){oe(e,i,S);return}var k=h?h(p,v,i+"",e,n,m):void 0,H=k===void 0;if(H){var de=ce(v),pe=!de&&qe(v),Ye=!de&&!pe&&Je(v);k=v,de||pe||Ye?ce(p)?k=p:En(p)?k=yn(p):pe?(H=!1,k=gn(v,!0)):Ye?(H=!1,k=bn(v,!0)):k=[]:Rn(v)||le(v)?(k=p,le(p)?k=Pn(p):(!R(p)||fe(p))&&(k=Tn(v))):H=!1}H&&(m.set(v,k),g(k,v,c,h,m),m.delete(v)),oe(e,i,k)}function dn(e,n){return jn(Cn(e,n,We),e+"")}var pn=V?function(e,n){return V(e,"toString",{configurable:!0,enumerable:!1,value:Nn(n),writable:!0})}:We;function gn(e,n){if(n)return e.slice();var i=e.length,c=Me?Me(i):new e.constructor(i);return e.copy(c),c}function hn(e){var n=new e.constructor(e.byteLength);return new Pe(n).set(new Pe(e)),n}function bn(e,n){var i=n?hn(e.buffer):e.buffer;return new e.constructor(i,e.byteOffset,e.length)}function yn(e,n){var i=-1,c=e.length;for(n||(n=Array(c));++i<c;)n[i]=e[i];return n}function mn(e,n,i,c){var g=!i;i||(i={});for(var h=-1,m=n.length;++h<m;){var p=n[h],v=c?c(i[p],e[p],p,i,e):void 0;v===void 0&&(v=e[p]),g?ie(i,p,v):sn(i,p,v)}return i}function vn(e){return dn(function(n,i){var c=-1,g=i.length,h=g>1?i[g-1]:void 0,m=g>2?i[2]:void 0;for(h=e.length>3&&typeof h=="function"?(g--,h):void 0,m&&kn(i[0],i[1],m)&&(h=g<3?void 0:h,g=1),n=Object(n);++c<g;){var p=i[c];p&&e(n,p,c,h)}return n})}function _n(e){return function(n,i,c){for(var g=-1,h=Object(n),m=c(n),p=m.length;p--;){var v=m[e?p:++g];if(i(h[v],v,h)===!1)break}return n}}function Q(e,n){var i=e.__data__;return An(n)?i[typeof n=="string"?"string":"hash"]:i.map}function se(e,n){var i=Or(e,n);return ln(i)?i:void 0}function wn(e){var n=j.call(e,x),i=e[x];try{e[x]=void 0;var c=!0}catch{}var g=Ee.call(e);return c&&(n?e[x]=i:delete e[x]),g}function Tn(e){return typeof e.constructor=="function"&&!He(e)?zr(Ne(e)):{}}function Fe(e,n){var i=typeof e;return n=n??u,!!n&&(i=="number"||i!="symbol"&&Tr.test(e))&&e>-1&&e%1==0&&e<n}function kn(e,n,i){if(!R(i))return!1;var c=typeof n;return(c=="number"?ue(i)&&Fe(n,i.length):c=="string"&&n in i)?ee(i[n],e):!1}function An(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function Sn(e){return!!xe&&xe in e}function He(e){var n=e&&e.constructor,i=typeof n=="function"&&n.prototype||K;return e===i}function In(e){var n=[];if(e!=null)for(var i in Object(e))n.push(i);return n}function On(e){return Ee.call(e)}function Cn(e,n,i){return n=Le(n===void 0?e.length-1:n,0),function(){for(var c=arguments,g=-1,h=Le(c.length-n,0),m=Array(h);++g<h;)m[g]=c[n+g];g=-1;for(var p=Array(n+1);++g<n;)p[g]=c[g];return p[n]=i(m),Ar(e,this,p)}}function ae(e,n){if(!(n==="constructor"&&typeof e[n]=="function")&&n!="__proto__")return e[n]}var jn=$n(pn);function $n(e){var n=0,i=0;return function(){var c=Nr(),g=l-(c-i);if(i=c,g>0){if(++n>=a)return arguments[0]}else n=0;return e.apply(void 0,arguments)}}function xn(e){if(e!=null){try{return W.call(e)}catch{}try{return e+""}catch{}}return""}function ee(e,n){return e===n||e!==e&&n!==n}var le=De(function(){return arguments}())?De:function(e){return F(e)&&j.call(e,"callee")&&!Rr.call(e,"callee")},ce=Array.isArray;function ue(e){return e!=null&&Ge(e.length)&&!fe(e)}function En(e){return F(e)&&ue(e)}var qe=Mr||zn;function fe(e){if(!R(e))return!1;var n=Z(e);return n==C||n==w||n==y||n==nr}function Ge(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=u}function R(e){var n=typeof e;return e!=null&&(n=="object"||n=="function")}function F(e){return e!=null&&typeof e=="object"}function Rn(e){if(!F(e)||Z(e)!=Se)return!1;var n=Ne(e);if(n===null)return!0;var i=j.call(n,"constructor")&&n.constructor;return typeof i=="function"&&i instanceof i&&W.call(i)==xr}var Je=$e?Ir($e):cn;function Pn(e){return mn(e,Ke(e))}function Ke(e){return ue(e)?on(e,!0):un(e)}var Mn=vn(function(e,n,i,c){Ue(e,n,i,c)});function Nn(e){return function(){return e}}function We(e){return e}function zn(){return!1}o.exports=Mn}(G,G.exports);var qt=G.exports;const Gt=Ht(qt);function Jt(o){let t={};function r(s,a){if((a==null?void 0:a.type)==="AwaitExpression"&&a.argument.type==="CallExpression"&&a.argument.callee.type==="Identifier"&&a.argument.callee.name==="useStoryblok"){const l=a.argument.arguments;if(l&&l[1].type==="ObjectExpression"){const u=ke(l[1].properties);t={...t,apiOptions:u}}if(l&&l[2].type==="ObjectExpression"){const u=ke(l[2].properties);t={...t,bridgeOptions:u}}}}return Gt({},o,r),t}function ke(o){const t={};return o.reduce((r,s)=>{if(s.type!=="Property")return r;const{key:a,value:l}=s,{type:u}=l;if(a.type!=="Identifier")return r;if(u==="Literal")r[a.name]=l.value;else if(u==="ArrayExpression"){const f=l.elements.reduce((d,y)=>y.type==="Literal"&&y.value?[...d,y.value]:d,[]);r[a.name]=f}return r},t)}let z=[];function Kt(o,t){const r="virtual:storyblok-bridge",s="\0"+r;if(!o||t!=="server")return{name:"vite-plugin-storyblok-bridge",resolveId(f){if(f===r)return s},load(f){if(f===s)return"export const bridgeOptions = null"}};let a=[],l=null,u;return{name:"vite-plugin-storyblok-bridge",async resolveId(f){if(f===r)return s},async transform(f,d){var C;if(d.includes("node_modules")&&!d.includes("/pages/")||!f.includes("useStoryblok")||!((C=this.getModuleInfo(d).meta)!=null&&C.astro))return;const[,..._]=d.split("src/pages/"),A=_.join("/").replace(".astro",""),I=Jt(this.parse(f));z.length&&(a=z.filter(w=>w.url!==A)),a.push({url:A,options:I}),l&&(u&&clearTimeout(u),u=setTimeout(()=>{Wt(z,a)||(z.length!==0&&(l.restart(),console.info("Bridge options updated. Restarting...")),z=[...a])},1e3))},async load(f){if(f===s)return`export const bridgeOptions = ${JSON.stringify(Ft(a))}`},configureServer(f){l=f}}}function Wt(o=[],t=[]){return t.every(({url:r,options:s})=>{const a=o.find(l=>(l==null?void 0:l.url)===r);return a&&JSON.stringify(s)===JSON.stringify(a.options)})}let Ae;async function Yt(o){const{action:t,story:r}=o||{};if(t==="input"&&r){const s=async()=>{const l=await Xt(r),u=document.body;if(l.outerHTML===u.outerHTML)return;const f=document.querySelector('[data-blok-focused="true"]');Vt(u,l,f)};clearTimeout(Ae),Ae=setTimeout(s,500)}["published","change"].includes(o==null?void 0:o.action)&&location.reload()}function Vt(o,t,r){if(r){const s=r.getAttribute("data-blok-uid"),a=t.querySelector(`[data-blok-uid="${s}"]`);a&&(a.setAttribute("data-blok-focused","true"),r.replaceWith(a))}else o.replaceWith(t)}async function Xt(o){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...o,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function Zt(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}async function Qt(o,t={},r={},s){globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly");let a=null;if(s&&s.locals._storyblok_preview_data)a=s.locals._storyblok_preview_data;else{const{data:l}=await globalThis.storyblokApiInstance.get(o,t,r);a=l.story}return a}function er(o,t){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Dt(o,t,r)}function tr(o){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,bridgeFromAstroConfig:!1,...o};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:s,addDevToolbarApp:a,addMiddleware:l,config:u})=>{if(s({vite:{plugins:[N(t.accessToken,t.useCustomApi,t.apiOptions),rt(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),nt(t),...t.bridgeFromAstroConfig?[]:[Kt(t.livePreview,u.output)]]}}),t.livePreview&&(u==null?void 0:u.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");if(r("page-ssr",`
35
- import { storyblokApiInstance } from "virtual:storyblok-init";
36
- globalThis.storyblokApiInstance = storyblokApiInstance;
37
- `),t.bridge&&!t.livePreview){let f="";if(typeof t.bridge=="object"){const d={...t.bridge};f=`const storyblokInstance = new StoryblokBridge(${JSON.stringify(d)});`}else f="const storyblokInstance = new StoryblokBridge()";r("page",`
38
- import { loadStoryblokBridge } from "@storyblok/astro";
39
- loadStoryblokBridge().then(() => {
40
- const { StoryblokBridge, location } = window;
41
- ${f}
42
-
43
- storyblokInstance.on(["published", "change"], (event) => {
44
- if (!event.slugChanged) {
45
- location.reload(true);
46
- }
47
- });
48
- });
49
- `)}if(t.livePreview&&t.bridgeFromAstroConfig){let f="";if(typeof t.bridge=="object"){const d={...t.bridge};f=`const storyblokInstance = new StoryblokBridge(${JSON.stringify(d)});`}else f="const storyblokInstance = new StoryblokBridge()";r("page",`
50
- import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
51
- console.info("The Storyblok Astro live preview feature is currently in an experimental phase, and its API is subject to change in the future.")
52
- loadStoryblokBridge().then(() => {
53
- const { StoryblokBridge, location } = window;
54
- ${f}
55
- storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
56
- });
57
- `),l({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})}t.livePreview&&!t.bridgeFromAstroConfig&&(r("page",`
58
- import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
59
- import { bridgeOptions } from "virtual:storyblok-bridge";
60
- console.info("The Storyblok Astro live preview feature is currently in an experimental phase, and its API is subject to change in the future.")
61
- loadStoryblokBridge().then(() => {
62
- const { StoryblokBridge, location } = window;
63
- if(bridgeOptions){
64
- const storyblokInstance = new StoryblokBridge(bridgeOptions);
65
- storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
66
- };
67
- });
68
- `),l({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),a("@storyblok/astro/toolbarApp.ts")}}}}T.RichTextResolver=Te,T.RichTextSchema=we,T.default=tr,T.handleStoryblokMessage=Yt,T.loadStoryblokBridge=Ut,T.renderRichText=er,T.storyblokEditable=Mt,T.useStoryblok=Qt,T.useStoryblokApi=Zt,Object.defineProperties(T,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});