/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@storyblok/nuxt-2@3.0.8/dist/storyblok-nuxt.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
(function(c,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@storyblok/vue-2"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@storyblok/vue-2","vue"],i):(c=typeof globalThis<"u"?globalThis:c||self,i(c.storyblokNuxt={},c["@storyblok/vue-2"],c.Vue))})(this,function(c,i,a){"use strict";var h={};Object.defineProperty(h,"__esModule",{value:!0});const R="$nuxt",D="__NUXT__",N=!1,j="/static-path",T="/_nuxt/";var C=h.globalContext=D,l=h.globalNuxt=R,E=h.isFullStatic=N;h.publicPath=T,h.staticPath=j;function M(e){if(!e)throw new Error("You must provide a key. You can have it generated automatically by adding '@nuxtjs/composition-api/dist/babel-plugin' to your Babel plugins.")}const g=()=>{const e=a.getCurrentInstance();if(e)return e.proxy};function $(e){return e instanceof Function?e():e}let m={};const I=()=>{const e=g(),r=e?"ssrRefs":"globalRefs";let t;if(e&&process.server){const n=(e[l]||e.$options).context.ssrContext;t=n.nuxt.ssrRefs=n.nuxt.ssrRefs||{}}return{type:r,setData:(n,s)=>{const u=t||m;u[n]=V(s)}}},O=e=>!!e&&typeof e=="object",V=e=>e&&JSON.parse(JSON.stringify(e))||e,B=(e,r,t="globalRefs")=>{var o,n,s,u;return process.client?process.env.NODE_ENV==="development"&&((o=window[l])!=null&&o.context.isHMR)?$(e):(u=(s=(n=window[C])==null?void 0:n[t])==null?void 0:s[r])!=null?u:$(e):$(e)},A=(e,r)=>{M(r);const{type:t,setData:o}=I();let n=B(e,r,t);if(process.client)return a.ref(n);e instanceof Function&&o(r,n);const s=(f,y,S)=>new Proxy(S,{get(d,p){if(f(),O(d[p]))return s(f,y,d[p]);const b=Reflect.get(d,p);return typeof b=="function"?b.bind(d):b},set(d,p,b){const U=Reflect.set(d,p,b);return o(r,n),y(),U}});return a.customRef((f,y)=>({get:()=>(f(),O(n)?s(f,y,n):n),set:S=>{o(r,S),n=S,y()}}))},J=process.client&&window[C];function k(e){let r;if(e.message||typeof e=="string")r=e.message||e;else try{r=JSON.stringify(e,null,2)}catch{r=`[${e.constructor.name}]`}return{...e,message:r,statusCode:e.statusCode||e.status||e.response&&e.response.status||500}}function v(e,r=""){return function(o=r){return e[o]===void 0&&(e[o]=0),e[o]++}}const x=new WeakMap,_=new Map,q=e=>{var r,t,o;return(o=(t=(r=e.$vnode)==null?void 0:r.elm)==null?void 0:t.dataset)==null?void 0:o.fetchKey};function H(e,r){const t=x.get(e)||[];x.set(e,[...t,r])}async function w(){const e=x.get(this);if(!e)return;this[l].nbFetching++,this.$fetchState.pending=!0,this.$fetchState.error=null,this._hydrated=!1;let r=null;const t=Date.now();try{await Promise.all(e.map(n=>{if(_.has(n))return _.get(n);const s=Promise.resolve(n(this)).finally(()=>_.delete(n));return _.set(n,s),s}))}catch(n){process.dev&&console.error("Error in fetch():",n),r=k(n)}const o=(this._fetchDelay||0)-(Date.now()-t);o>0&&await new Promise(n=>setTimeout(n,o)),this.$fetchState.error=r,this.$fetchState.pending=!1,this.$fetchState.timestamp=Date.now(),this.$nextTick(()=>this[l].nbFetching--)}const K=e=>{e.$fetchState=e.$fetchState||a.reactive({error:null,pending:!1,timestamp:0})},F=e=>{const r=g();if(!r)throw new Error("This must be called within a setup function.");a.onBeforeMount(()=>{const t=r._setupProxy||r;for(const o in e)try{if(o in t){const n=o;if(t[n]===e[o]||typeof t[n]=="function")continue;if(a.isReactive(t[n])){for(const s in t[n])s in e[o]||delete t[n][s];Object.assign(t[n],e[o]);continue}}a.set(t,o,e[o])}catch{process.env.NODE_ENV==="development"&&console.warn(`Could not hydrate ${o}.`)}})},Y=e=>{e._fetchKey=P(e);const{fetchOnServer:r}=e.$options,t=typeof r=="function"?r.call(e)!==!1:r!==!1,o=e[l];if(!t||o!=null&&o.isPreview||!(o!=null&&o._pagePayload))return;e._hydrated=!0;const n=o._pagePayload.fetch[e._fetchKey];if(n&&n._error){e.$fetchState.error=n._error;return}F(n)};async function z(e){if(!e._fetchOnServer)return;K(e);try{await w.call(e)}catch(n){process.dev&&console.error("Error in fetch():",n),e.$fetchState.error=k(n)}e.$fetchState.pending=!1,e._fetchKey="push"in e.$ssrContext.nuxt.fetch?e.$ssrContext.nuxt.fetch.length:e._fetchKey||e.$ssrContext.fetchCounters[""]++,e.$vnode.data||(e.$vnode.data={});const r=e.$vnode.data.attrs=e.$vnode.data.attrs||{};r["data-fetch-key"]=e._fetchKey;const t=Object.fromEntries(Object.entries((e==null?void 0:e._setupProxy)||(e==null?void 0:e._setupState)).filter(([n,s])=>!(s&&typeof s=="object"&&"_compiled"in s||s instanceof Function||s instanceof Promise)).map(([n,s])=>[n,a.isRef(s)?s.value:s])),o=e.$fetchState.error?{_error:e.$fetchState.error}:JSON.parse(JSON.stringify(t));"push"in e.$ssrContext.nuxt.fetch?e.$ssrContext.nuxt.fetch.push(o):e.$ssrContext.nuxt.fetch[e._fetchKey]=o}function P(e){const r=e[l];if(process.server&&"push"in e.$ssrContext.nuxt.fetch)return;if(process.client&&"_payloadFetchIndex"in r)return r._payloadFetchIndex=r._payloadFetchIndex||0,r._payloadFetchIndex++;const t=e.$options._scopeId||e.$options.name||"",o=v(process.server?e.$ssrContext.fetchCounters:e[l]._fetchCounters,t),n=e.$options;if(typeof n.fetchKey=="function")return n.fetchKey.call(e,o);{const s=typeof n.fetchKey=="string"?n.fetchKey:t;return s?s+":"+o(s):String(o(s))}}const G=e=>{var r;const t=g();if(!t)throw new Error("This must be called within a setup function.");H(t,e),typeof t.$options.fetchOnServer=="function"?t._fetchOnServer=t.$options.fetchOnServer.call(t)!==!1:t._fetchOnServer=t.$options.fetchOnServer!==!1,process.server&&(t._fetchKey=P(t)),K(t),a.onServerPrefetch(()=>z(t));function o(){return{fetch:t.$fetch,fetchState:t.$fetchState,$fetch:t.$fetch,$fetchState:t.$fetchState}}if(t._fetchDelay=typeof t.$options.fetchDelay=="number"?t.$options.fetchDelay:0,t.$fetch=w.bind(t),a.onBeforeMount(()=>!t._hydrated&&w.call(t)),process.server||!q(t))return process.client&&E&&Y(t),o();t._hydrated=!0,t._fetchKey=((r=t.$vnode.elm)==null?void 0:r.dataset.fetchKey)||P(t);const n=J.fetch[t._fetchKey];return n&&n._error?(t.$fetchState.error=n._error,o()):(F(n),o())},L=(e,r={},t={})=>{const o=i.useStoryblokApi(r);if(!o)return console.error("useStoryblok cannot be used if you disabled useApiClient when adding @storyblok/nuxt-2 to your nuxt.config.js");const n=A(null,e);a.onMounted(()=>{n.value&&n.value.id&&i.useStoryblokBridge(n.value.id,f=>n.value=f,t)});const{fetch:s,fetchState:u}=G(async()=>{const{data:f}=await o.get(`cdn/stories/${e}`,r);n.value=f.story});return s(),{story:n,fetchState:u}};Object.defineProperty(c,"StoryblokVue",{enumerable:!0,get:()=>i.StoryblokVue}),Object.defineProperty(c,"apiPlugin",{enumerable:!0,get:()=>i.apiPlugin}),Object.defineProperty(c,"renderRichText",{enumerable:!0,get:()=>i.renderRichText}),Object.defineProperty(c,"useStoryblokApi",{enumerable:!0,get:()=>i.useStoryblokApi}),Object.defineProperty(c,"useStoryblokBridge",{enumerable:!0,get:()=>i.useStoryblokBridge}),c.useStoryblok=L,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
