@storyblok/vue 7.1.1 → 7.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,404 +1,535 @@
1
- import { defineComponent as $, openBlock as P, createBlock as E, resolveDynamicComponent as j, normalizeProps as S, guardReactiveProps as x, ref as C, onMounted as O } from "vue";
2
- let v = !1;
3
- const b = [], A = (o) => new Promise((e, t) => {
1
+ import { defineComponent as E, openBlock as S, createBlock as C, resolveDynamicComponent as I, normalizeProps as A, guardReactiveProps as O, ref as M, onMounted as N } from "vue";
2
+ let _ = !1;
3
+ const R = [], z = (i) => new Promise((t, e) => {
4
4
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
5
5
  if (window.location === window.parent.location) {
6
6
  console.warn("You are not in Draft Mode or in the Visual Editor.");
7
7
  return;
8
8
  }
9
- v ? r() : b.push(r);
9
+ _ ? r() : R.push(r);
10
10
  }, document.getElementById("storyblok-javascript-bridge")))
11
11
  return;
12
12
  const s = document.createElement("script");
13
- s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
14
- b.forEach((i) => i()), v = !0, e(r);
13
+ s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
14
+ R.forEach((o) => o()), _ = !0, t(r);
15
15
  }, document.getElementsByTagName("head")[0].appendChild(s);
16
16
  });
17
- var I = Object.defineProperty, M = (o, e, t) => e in o ? I(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, h = (o, e, t) => (M(o, typeof e != "symbol" ? e + "" : e, t), t);
18
- function w(o) {
19
- return !(o !== o || o === 1 / 0 || o === -1 / 0);
17
+ var L = Object.defineProperty, U = (i, t, e) => t in i ? L(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, h = (i, t, e) => (U(i, typeof t != "symbol" ? t + "" : t, e), e);
18
+ function j(i) {
19
+ return !(i !== i || i === 1 / 0 || i === -1 / 0);
20
20
  }
21
- function N(o, e, t) {
22
- if (!w(e))
21
+ function q(i, t, e) {
22
+ if (!j(t))
23
23
  throw new TypeError("Expected `limit` to be a finite number");
24
- if (!w(t))
24
+ if (!j(e))
25
25
  throw new TypeError("Expected `interval` to be a finite number");
26
26
  const s = [];
27
- let r = [], i = 0;
27
+ let r = [], o = 0;
28
28
  const n = function() {
29
- i++;
30
- const l = setTimeout(function() {
31
- i--, s.length > 0 && n(), r = r.filter(function(u) {
32
- return u !== l;
29
+ o++;
30
+ const a = setTimeout(function() {
31
+ o--, s.length > 0 && n(), r = r.filter(function(u) {
32
+ return u !== a;
33
33
  });
34
- }, t);
35
- r.indexOf(l) < 0 && r.push(l);
36
- const c = s.shift();
37
- c.resolve(o.apply(c.self, c.args));
38
- }, a = function(...l) {
39
- const c = this;
40
- return new Promise(function(u, p) {
34
+ }, e);
35
+ r.indexOf(a) < 0 && r.push(a);
36
+ const l = s.shift();
37
+ l.resolve(i.apply(l.self, l.args));
38
+ }, c = function(...a) {
39
+ const l = this;
40
+ return new Promise(function(u, d) {
41
41
  s.push({
42
42
  resolve: u,
43
- reject: p,
44
- args: l,
45
- self: c
46
- }), i < e && n();
43
+ reject: d,
44
+ args: a,
45
+ self: l
46
+ }), o < t && n();
47
47
  });
48
48
  };
49
- return a.abort = function() {
50
- r.forEach(clearTimeout), r = [], s.forEach(function(l) {
51
- l.reject(function() {
49
+ return c.abort = function() {
50
+ r.forEach(clearTimeout), r = [], s.forEach(function(a) {
51
+ a.reject(function() {
52
52
  Error.call(this, "Throttled function aborted"), this.name = "AbortError";
53
53
  });
54
54
  }), s.length = 0;
55
- }, a;
55
+ }, c;
56
56
  }
57
- const L = function(o, e) {
58
- const t = {};
59
- for (const s in o) {
60
- const r = o[s];
61
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
62
- }
63
- return t;
64
- }, U = (o) => o === "email", H = () => ({
57
+ const H = function(i, t) {
58
+ const e = {};
59
+ for (const s in i) {
60
+ const r = i[s];
61
+ t.indexOf(s) > -1 && r !== null && (e[s] = r);
62
+ }
63
+ return e;
64
+ }, D = (i) => i === "email", B = () => ({
65
65
  singleTag: "hr"
66
- }), q = () => ({
66
+ }), V = () => ({
67
67
  tag: "blockquote"
68
- }), D = () => ({
68
+ }), J = () => ({
69
69
  tag: "ul"
70
- }), B = (o) => ({
70
+ }), F = (i) => ({
71
71
  tag: [
72
72
  "pre",
73
73
  {
74
74
  tag: "code",
75
- attrs: o.attrs
75
+ attrs: i.attrs
76
76
  }
77
77
  ]
78
- }), V = () => ({
78
+ }), Y = () => ({
79
79
  singleTag: "br"
80
- }), z = (o) => ({
81
- tag: `h${o.attrs.level}`
82
- }), J = (o) => ({
80
+ }), K = (i) => ({
81
+ tag: `h${i.attrs.level}`
82
+ }), G = (i) => ({
83
83
  singleTag: [
84
84
  {
85
85
  tag: "img",
86
- attrs: L(o.attrs, ["src", "alt", "title"])
86
+ attrs: H(i.attrs, ["src", "alt", "title"])
87
87
  }
88
88
  ]
89
- }), F = () => ({
89
+ }), Q = () => ({
90
90
  tag: "li"
91
- }), Y = () => ({
91
+ }), W = () => ({
92
92
  tag: "ol"
93
- }), K = () => ({
93
+ }), X = () => ({
94
94
  tag: "p"
95
- }), G = () => ({
95
+ }), Z = (i) => ({
96
+ tag: [
97
+ {
98
+ tag: "span",
99
+ attrs: {
100
+ ["data-type"]: "emoji",
101
+ ["data-name"]: i.attrs.name,
102
+ emoji: i.attrs.emoji
103
+ }
104
+ }
105
+ ]
106
+ }), tt = () => ({
96
107
  tag: "b"
97
- }), Q = () => ({
108
+ }), et = () => ({
98
109
  tag: "strike"
99
- }), W = () => ({
110
+ }), st = () => ({
100
111
  tag: "u"
101
- }), X = () => ({
112
+ }), rt = () => ({
102
113
  tag: "strong"
103
- }), Z = () => ({
114
+ }), ot = () => ({
104
115
  tag: "code"
105
- }), ee = () => ({
116
+ }), it = () => ({
106
117
  tag: "i"
107
- }), te = (o) => {
108
- const e = { ...o.attrs }, { linktype: t = "url" } = o.attrs;
109
- return U(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
118
+ }), nt = (i) => {
119
+ const t = { ...i.attrs }, { linktype: e = "url" } = i.attrs;
120
+ if (D(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
121
+ for (const s in t.custom)
122
+ t[s] = t.custom[s];
123
+ delete t.custom;
124
+ }
125
+ return {
110
126
  tag: [
111
127
  {
112
128
  tag: "a",
113
- attrs: e
129
+ attrs: t
114
130
  }
115
131
  ]
116
132
  };
117
- }, se = (o) => ({
133
+ }, at = (i) => ({
134
+ tag: [
135
+ {
136
+ tag: "span",
137
+ attrs: i.attrs
138
+ }
139
+ ]
140
+ }), lt = () => ({
141
+ tag: "sub"
142
+ }), ct = () => ({
143
+ tag: "sup"
144
+ }), ht = (i) => ({
145
+ tag: [
146
+ {
147
+ tag: "span",
148
+ attrs: i.attrs
149
+ }
150
+ ]
151
+ }), ut = (i) => ({
118
152
  tag: [
119
153
  {
120
154
  tag: "span",
121
- attrs: o.attrs
155
+ attrs: {
156
+ style: `background-color:${i.attrs.color};`
157
+ }
122
158
  }
123
159
  ]
124
- }), re = {
160
+ }), dt = (i) => ({
161
+ tag: [
162
+ {
163
+ tag: "span",
164
+ attrs: {
165
+ style: `background-color:${i.attrs.color}`
166
+ }
167
+ }
168
+ ]
169
+ }), pt = {
125
170
  nodes: {
126
- horizontal_rule: H,
127
- blockquote: q,
128
- bullet_list: D,
129
- code_block: B,
130
- hard_break: V,
131
- heading: z,
132
- image: J,
133
- list_item: F,
134
- ordered_list: Y,
135
- paragraph: K
171
+ horizontal_rule: B,
172
+ blockquote: V,
173
+ bullet_list: J,
174
+ code_block: F,
175
+ hard_break: Y,
176
+ heading: K,
177
+ image: G,
178
+ list_item: Q,
179
+ ordered_list: W,
180
+ paragraph: X,
181
+ emoji: Z
136
182
  },
137
183
  marks: {
138
- bold: G,
139
- strike: Q,
140
- underline: W,
141
- strong: X,
142
- code: Z,
143
- italic: ee,
144
- link: te,
145
- styled: se
146
- }
147
- }, oe = function(o) {
148
- const e = {
184
+ bold: tt,
185
+ strike: et,
186
+ underline: st,
187
+ strong: rt,
188
+ code: ot,
189
+ italic: it,
190
+ link: nt,
191
+ styled: at,
192
+ subscript: lt,
193
+ superscript: ct,
194
+ anchor: ht,
195
+ highlight: ut,
196
+ textStyle: dt
197
+ }
198
+ }, gt = function(i) {
199
+ const t = {
149
200
  "&": "&amp;",
150
201
  "<": "&lt;",
151
202
  ">": "&gt;",
152
203
  '"': "&quot;",
153
204
  "'": "&#39;"
154
- }, t = /[&<>"']/g, s = RegExp(t.source);
155
- return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
205
+ }, e = /[&<>"']/g, s = RegExp(e.source);
206
+ return i && s.test(i) ? i.replace(e, (r) => t[r]) : i;
156
207
  };
157
- class m {
158
- constructor(e) {
159
- h(this, "marks"), h(this, "nodes"), e || (e = re), this.marks = e.marks || [], this.nodes = e.nodes || [];
160
- }
161
- addNode(e, t) {
162
- this.nodes[e] = t;
163
- }
164
- addMark(e, t) {
165
- this.marks[e] = t;
166
- }
167
- render(e) {
168
- if (e && e.content && Array.isArray(e.content)) {
169
- let t = "";
170
- return e.content.forEach((s) => {
171
- t += this.renderNode(s);
172
- }), t;
208
+ class b {
209
+ constructor(t) {
210
+ h(this, "marks"), h(this, "nodes"), t || (t = pt), this.marks = t.marks || [], this.nodes = t.nodes || [];
211
+ }
212
+ addNode(t, e) {
213
+ this.nodes[t] = e;
214
+ }
215
+ addMark(t, e) {
216
+ this.marks[t] = e;
217
+ }
218
+ render(t, e = { optimizeImages: !1 }) {
219
+ if (t && t.content && Array.isArray(t.content)) {
220
+ let s = "";
221
+ return t.content.forEach((r) => {
222
+ s += this.renderNode(r);
223
+ }), e.optimizeImages ? this.optimizeImages(s, e.optimizeImages) : s;
173
224
  }
174
225
  return console.warn(
175
226
  "The render method must receive an object with a content field, which is an array"
176
227
  ), "";
177
228
  }
178
- renderNode(e) {
179
- const t = [];
180
- e.marks && e.marks.forEach((r) => {
181
- const i = this.getMatchingMark(r);
182
- i && t.push(this.renderOpeningTag(i.tag));
229
+ optimizeImages(t, e) {
230
+ let s = 0, r = 0, o = "", n = "";
231
+ typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (o += `width="${e.width}" `, s = e.width), typeof e.height == "number" && e.height > 0 && (o += `height="${e.height}" `, r = e.height), (e.loading === "lazy" || e.loading === "eager") && (o += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (o += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (n += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (n += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-Fa-f]{6}/g) || e.filters.fill === "transparent") && (n += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (n += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (n += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (n += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (n += `:rotate(${e.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), o.length > 0 && (t = t.replace(/<img/g, `<img ${o.trim()}`));
232
+ const c = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
233
+ return t = t.replace(
234
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
235
+ `a.storyblok.com/f/$1/$2.$3/m/${c}`
236
+ ), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
237
+ var l, u;
238
+ const d = a.match(
239
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
240
+ );
241
+ if (d && d.length > 0) {
242
+ const g = {
243
+ srcset: (l = e.srcset) == null ? void 0 : l.map((p) => {
244
+ if (typeof p == "number")
245
+ return `//${d}/m/${p}x0${n} ${p}w`;
246
+ if (typeof p == "object" && p.length === 2) {
247
+ let v = 0, T = 0;
248
+ return typeof p[0] == "number" && (v = p[0]), typeof p[1] == "number" && (T = p[1]), `//${d}/m/${v}x${T}${n} ${v}w`;
249
+ }
250
+ }).join(", "),
251
+ sizes: (u = e.sizes) == null ? void 0 : u.map((p) => p).join(", ")
252
+ };
253
+ let k = "";
254
+ return g.srcset && (k += `srcset="${g.srcset}" `), g.sizes && (k += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
255
+ }
256
+ return a;
257
+ })), t;
258
+ }
259
+ renderNode(t) {
260
+ const e = [];
261
+ t.marks && t.marks.forEach((r) => {
262
+ const o = this.getMatchingMark(r);
263
+ o && e.push(this.renderOpeningTag(o.tag));
183
264
  });
184
- const s = this.getMatchingNode(e);
185
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
186
- t.push(this.renderNode(r));
187
- }) : e.text ? t.push(oe(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html && t.push(s.html), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
188
- const i = this.getMatchingMark(r);
189
- i && t.push(this.renderClosingTag(i.tag));
190
- }), t.join("");
191
- }
192
- renderTag(e, t) {
193
- return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
265
+ const s = this.getMatchingNode(t);
266
+ return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
267
+ e.push(this.renderNode(r));
268
+ }) : t.text ? e.push(gt(t.text)) : s && s.singleTag ? e.push(this.renderTag(s.singleTag, " /")) : s && s.html ? e.push(s.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), s && s.tag && e.push(this.renderClosingTag(s.tag)), t.marks && t.marks.slice(0).reverse().forEach((r) => {
269
+ const o = this.getMatchingMark(r);
270
+ o && e.push(this.renderClosingTag(o.tag));
271
+ }), e.join("");
272
+ }
273
+ renderTag(t, e) {
274
+ return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
194
275
  if (s.constructor === String)
195
- return `<${s}${t}>`;
276
+ return `<${s}${e}>`;
196
277
  {
197
278
  let r = `<${s.tag}`;
198
279
  if (s.attrs)
199
- for (const i in s.attrs) {
200
- const n = s.attrs[i];
201
- n !== null && (r += ` ${i}="${n}"`);
280
+ for (const o in s.attrs) {
281
+ const n = s.attrs[o];
282
+ n !== null && (r += ` ${o}="${n}"`);
202
283
  }
203
- return `${r}${t}>`;
284
+ return `${r}${e}>`;
204
285
  }
205
286
  }).join("");
206
287
  }
207
- renderOpeningTag(e) {
208
- return this.renderTag(e, "");
288
+ renderOpeningTag(t) {
289
+ return this.renderTag(t, "");
290
+ }
291
+ renderClosingTag(t) {
292
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
209
293
  }
210
- renderClosingTag(e) {
211
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
294
+ getMatchingNode(t) {
295
+ const e = this.nodes[t.type];
296
+ if (typeof e == "function")
297
+ return e(t);
212
298
  }
213
- getMatchingNode(e) {
214
- const t = this.nodes[e.type];
215
- if (typeof t == "function")
216
- return t(e);
299
+ getMatchingMark(t) {
300
+ const e = this.marks[t.type];
301
+ if (typeof e == "function")
302
+ return e(t);
217
303
  }
218
- getMatchingMark(e) {
219
- const t = this.marks[e.type];
220
- if (typeof t == "function")
221
- return t(e);
304
+ renderEmoji(t) {
305
+ if (t.attrs.emoji)
306
+ return t.attrs.emoji;
307
+ const e = [
308
+ {
309
+ tag: "img",
310
+ attrs: {
311
+ src: t.attrs.fallbackImage,
312
+ draggable: "false",
313
+ loading: "lazy",
314
+ align: "absmiddle"
315
+ }
316
+ }
317
+ ];
318
+ return this.renderTag(e, " /");
222
319
  }
223
320
  }
224
- class _ {
321
+ class w {
225
322
  constructor() {
226
- h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => ({
227
- ...e,
228
- per_page: t,
323
+ h(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (t, e = 25, s = 1) => ({
324
+ ...t,
325
+ per_page: e,
229
326
  page: s
230
- })), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
231
- const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
232
- return this.arrayFrom(s, (i, n) => n * r + e);
233
- }), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
234
- }
235
- stringify(e, t, s) {
327
+ })), h(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), h(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), h(this, "range", (t = 0, e = t) => {
328
+ const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
329
+ return this.arrayFrom(s, (o, n) => n * r + t);
330
+ }), h(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), h(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
331
+ }
332
+ /**
333
+ * @method stringify
334
+ * @param {Object} params
335
+ * @param {String} prefix
336
+ * @param {Boolean} isArray
337
+ * @return {String} Stringified object
338
+ */
339
+ stringify(t, e, s) {
236
340
  const r = [];
237
- for (const i in e) {
238
- if (!Object.prototype.hasOwnProperty.call(e, i))
341
+ for (const o in t) {
342
+ if (!Object.prototype.hasOwnProperty.call(t, o))
239
343
  continue;
240
- const n = e[i], a = s ? "" : encodeURIComponent(i);
241
- let l;
242
- typeof n == "object" ? l = this.stringify(
344
+ const n = t[o], c = s ? "" : encodeURIComponent(o);
345
+ let a;
346
+ typeof n == "object" ? a = this.stringify(
243
347
  n,
244
- t ? t + encodeURIComponent("[" + a + "]") : a,
348
+ e ? e + encodeURIComponent("[" + c + "]") : c,
245
349
  Array.isArray(n)
246
- ) : l = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(n), r.push(l);
350
+ ) : a = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), r.push(a);
247
351
  }
248
352
  return r.join("&");
249
353
  }
250
- }
251
- class ie {
252
- constructor(e) {
253
- h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || [], this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
254
- }
255
- get(e, t) {
256
- return this.url = e, this.parameters = t, this._methodHandler("get");
257
- }
258
- post(e, t) {
259
- return this.url = e, this.parameters = t, this._methodHandler("post");
260
- }
261
- put(e, t) {
262
- return this.url = e, this.parameters = t, this._methodHandler("put");
263
- }
264
- delete(e, t) {
265
- return this.url = e, this.parameters = t, this._methodHandler("delete");
354
+ /**
355
+ * @method getRegionURL
356
+ * @param {String} regionCode region code, could be eu, us or cn
357
+ * @return {String} The base URL of the region
358
+ */
359
+ getRegionURL(t) {
360
+ const e = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn";
361
+ switch (t) {
362
+ case "us":
363
+ return s;
364
+ case "cn":
365
+ return r;
366
+ default:
367
+ return e;
368
+ }
266
369
  }
267
- async _responseHandler(e) {
268
- const t = [], s = {
370
+ }
371
+ class ft {
372
+ constructor(t) {
373
+ h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), this.baseURL = t.baseURL, this.headers = t.headers || new Headers(), this.timeout = t != null && t.timeout ? t.timeout * 1e3 : 0, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
374
+ }
375
+ /**
376
+ *
377
+ * @param url string
378
+ * @param params ISbStoriesParams
379
+ * @returns Promise<ISbResponse | Error>
380
+ */
381
+ get(t, e) {
382
+ return this.url = t, this.parameters = e, this._methodHandler("get");
383
+ }
384
+ post(t, e) {
385
+ return this.url = t, this.parameters = e, this._methodHandler("post");
386
+ }
387
+ put(t, e) {
388
+ return this.url = t, this.parameters = e, this._methodHandler("put");
389
+ }
390
+ delete(t, e) {
391
+ return this.url = t, this.parameters = e, this._methodHandler("delete");
392
+ }
393
+ async _responseHandler(t) {
394
+ const e = /* @__PURE__ */ new Map(), s = {
269
395
  data: {},
270
396
  headers: {},
271
397
  status: 0,
272
398
  statusText: ""
273
399
  };
274
- e.status !== 204 && await e.json().then((r) => {
400
+ t.status !== 204 && await t.json().then((r) => {
275
401
  s.data = r;
276
402
  });
277
- for (const r of e.headers.entries())
278
- t[r[0]] = r[1];
279
- return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
280
- }
281
- async _methodHandler(e) {
282
- let t = `${this.baseURL}${this.url}`, s = null;
283
- if (e === "get") {
284
- const l = new _();
285
- t = `${this.baseURL}${this.url}?${l.stringify(
403
+ for (const [r, o] of t.headers.entries())
404
+ e.set(r, o);
405
+ return s.headers = { ...e }, s.status = t.status, s.statusText = t.statusText, s;
406
+ }
407
+ async _methodHandler(t) {
408
+ let e = `${this.baseURL}${this.url}`, s = null;
409
+ if (t === "get") {
410
+ const a = new w();
411
+ e = `${this.baseURL}${this.url}?${a.stringify(
286
412
  this.parameters
287
413
  )}`;
288
414
  } else
289
415
  s = JSON.stringify(this.parameters);
290
- const r = new URL(t), i = new AbortController(), { signal: n } = i;
291
- let a;
292
- this.timeout && (a = setTimeout(() => i.abort(), this.timeout));
416
+ const r = new URL(e), o = new AbortController(), { signal: n } = o;
417
+ let c;
418
+ this.timeout && (c = setTimeout(() => o.abort(), this.timeout));
293
419
  try {
294
- const l = await this.fetch(`${r}`, {
295
- method: e,
420
+ const a = await this.fetch(`${r}`, {
421
+ method: t,
296
422
  headers: this.headers,
297
423
  body: s,
298
424
  signal: n
299
425
  });
300
- this.timeout && clearTimeout(a);
301
- const c = await this._responseHandler(l);
302
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
303
- } catch (l) {
426
+ this.timeout && clearTimeout(c);
427
+ const l = await this._responseHandler(a);
428
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
429
+ } catch (a) {
304
430
  return {
305
- message: l
431
+ message: a
306
432
  };
307
433
  }
308
434
  }
309
435
  eject() {
310
436
  this.ejectInterceptor = !0;
311
437
  }
312
- _statusHandler(e) {
313
- const t = /20[0-6]/g;
438
+ _statusHandler(t) {
439
+ const e = /20[0-6]/g;
314
440
  return new Promise((s, r) => {
315
- if (t.test(`${e.status}`))
316
- return s(e);
317
- const i = {
318
- message: new Error(e.statusText),
319
- status: e.status,
320
- response: e.data.error || e.data.slug
441
+ if (e.test(`${t.status}`))
442
+ return s(t);
443
+ const o = {
444
+ message: new Error(t.statusText),
445
+ status: t.status,
446
+ response: Array.isArray(t.data) ? t.data[0] : t.data.error || t.data.slug
321
447
  };
322
- r(i);
448
+ r(o);
323
449
  });
324
450
  }
325
451
  }
326
- let f = {};
327
- const d = {};
328
- class ne {
329
- constructor(e, t) {
330
- if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !t) {
331
- const i = e.region ? `-${e.region}` : "", n = e.https === !1 ? "http" : "https";
332
- e.oauthToken ? t = `${n}://api${i}.storyblok.com/v1` : t = `${n}://api${i}.storyblok.com/v2`;
452
+ let y = {};
453
+ const f = {};
454
+ class mt {
455
+ /**
456
+ *
457
+ * @param config ISbConfig interface
458
+ * @param endpoint string, optional
459
+ */
460
+ constructor(t, e) {
461
+ if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !e) {
462
+ const o = new w().getRegionURL, n = t.https === !1 ? "http" : "https";
463
+ t.oauthToken ? e = `${n}://${o(t.region)}/v1` : e = `${n}://${o(t.region)}/v2`;
333
464
  }
334
465
  const s = new Headers();
335
- s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((i, n) => {
336
- e.headers && e.headers[n] && s.set(n, e.headers[n]);
466
+ s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((o, n) => {
467
+ t.headers && t.headers[n] && s.set(n, t.headers[n]);
337
468
  });
338
469
  let r = 5;
339
- e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new m(e.richTextSchema) : this.richTextResolver = new m(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = N(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new _(), this.resolveNestedRelations = !1, this.client = new ie({
340
- baseURL: t,
341
- timeout: e.timeout || 0,
470
+ t.oauthToken && (s.set("Authorization", t.oauthToken), r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new b(t.richTextSchema) : this.richTextResolver = new b(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries, this.throttle = q(this.throttledRequest, r, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new w(), this.resolveCounter = 0, this.resolveNestedRelations = t.resolveNestedRelations || !0, this.client = new ft({
471
+ baseURL: e,
472
+ timeout: t.timeout || 0,
342
473
  headers: s,
343
- responseInterceptor: e.responseInterceptor,
344
- fetch: e.fetch
474
+ responseInterceptor: t.responseInterceptor,
475
+ fetch: t.fetch
345
476
  });
346
477
  }
347
- setComponentResolver(e) {
348
- this.richTextResolver.addNode("blok", (t) => {
478
+ setComponentResolver(t) {
479
+ this.richTextResolver.addNode("blok", (e) => {
349
480
  let s = "";
350
- return t.attrs.body.forEach((r) => {
351
- s += e(r.component, r);
481
+ return e.attrs.body.forEach((r) => {
482
+ s += t(r.component, r);
352
483
  }), {
353
484
  html: s
354
485
  };
355
486
  });
356
487
  }
357
- parseParams(e) {
358
- return e.version || (e.version = "published"), e.token || (e.token = this.getToken()), e.cv || (e.cv = d[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
488
+ parseParams(t) {
489
+ return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv = f[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
359
490
  }
360
- factoryParamOptions(e, t) {
361
- return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
491
+ factoryParamOptions(t, e) {
492
+ return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
362
493
  }
363
- makeRequest(e, t, s, r) {
364
- const i = this.factoryParamOptions(
365
- e,
366
- this.helpers.getOptionsPage(t, s, r)
494
+ makeRequest(t, e, s, r) {
495
+ const o = this.factoryParamOptions(
496
+ t,
497
+ this.helpers.getOptionsPage(e, s, r)
367
498
  );
368
- return this.cacheResponse(e, i);
499
+ return this.cacheResponse(t, o);
369
500
  }
370
- get(e, t) {
371
- t || (t = {});
372
- const s = `/${e}`, r = this.factoryParamOptions(s, t);
501
+ get(t, e) {
502
+ e || (e = {});
503
+ const s = `/${t}`, r = this.factoryParamOptions(s, e);
373
504
  return this.cacheResponse(s, r);
374
505
  }
375
- async getAll(e, t, s) {
376
- const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, n = i.split("/"), a = s || n[n.length - 1], l = 1, c = await this.makeRequest(i, t, r, l), u = c.total ? Math.ceil(c.total / r) : 1, p = await this.helpers.asyncMap(
377
- this.helpers.range(l, u),
378
- (y) => this.makeRequest(i, t, r, y + 1)
506
+ async getAll(t, e, s) {
507
+ const r = (e == null ? void 0 : e.per_page) || 25, o = `/${t}`, n = o.split("/"), c = s || n[n.length - 1], a = 1, l = await this.makeRequest(o, e, r, a), u = l.total ? Math.ceil(l.total / r) : 1, d = await this.helpers.asyncMap(
508
+ this.helpers.range(a, u),
509
+ (g) => this.makeRequest(o, e, r, g + 1)
379
510
  );
380
511
  return this.helpers.flatMap(
381
- [c, ...p],
382
- (y) => Object.values(y.data[a])
512
+ [l, ...d],
513
+ (g) => Object.values(g.data[c])
383
514
  );
384
515
  }
385
- post(e, t) {
386
- const s = `/${e}`;
387
- return Promise.resolve(this.throttle("post", s, t));
516
+ post(t, e) {
517
+ const s = `/${t}`;
518
+ return Promise.resolve(this.throttle("post", s, e));
388
519
  }
389
- put(e, t) {
390
- const s = `/${e}`;
391
- return Promise.resolve(this.throttle("put", s, t));
520
+ put(t, e) {
521
+ const s = `/${t}`;
522
+ return Promise.resolve(this.throttle("put", s, e));
392
523
  }
393
- delete(e, t) {
394
- const s = `/${e}`;
395
- return Promise.resolve(this.throttle("delete", s, t));
524
+ delete(t, e) {
525
+ const s = `/${t}`;
526
+ return Promise.resolve(this.throttle("delete", s, e));
396
527
  }
397
- getStories(e) {
398
- return this.get("cdn/stories", e);
528
+ getStories(t) {
529
+ return this.get("cdn/stories", t);
399
530
  }
400
- getStory(e, t) {
401
- return this.get(`cdn/stories/${e}`, t);
531
+ getStory(t, e) {
532
+ return this.get(`cdn/stories/${t}`, e);
402
533
  }
403
534
  getToken() {
404
535
  return this.accessToken;
@@ -406,156 +537,179 @@ class ne {
406
537
  ejectInterceptor() {
407
538
  this.client.eject();
408
539
  }
409
- _cleanCopy(e) {
410
- return JSON.parse(JSON.stringify(e));
411
- }
412
- _insertLinks(e, t) {
413
- const s = e[t];
414
- s && s.fieldtype == "multilink" && s.linktype == "story" && typeof s.id == "string" && this.links[s.id] ? s.story = this._cleanCopy(this.links[s.id]) : s && s.linktype === "story" && typeof s.uuid == "string" && this.links[s.uuid] && (s.story = this._cleanCopy(this.links[s.uuid]));
415
- }
416
- _insertRelations(e, t, s) {
417
- if (s.indexOf(`${e.component}.${t}`) > -1) {
418
- if (typeof e[t] == "string")
419
- this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
420
- else if (e[t] && e[t].constructor === Array) {
421
- const r = [];
422
- e[t].forEach((i) => {
423
- this.relations[i] && r.push(this._cleanCopy(this.relations[i]));
424
- }), e[t] = r;
540
+ _cleanCopy(t) {
541
+ return JSON.parse(JSON.stringify(t));
542
+ }
543
+ _insertLinks(t, e, s) {
544
+ const r = t[e];
545
+ r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
546
+ }
547
+ _insertRelations(t, e, s, r) {
548
+ if (s.indexOf(`${t.component}.${e}`) > -1) {
549
+ if (typeof t[e] == "string")
550
+ this.relations[r][t[e]] && (t[e] = this._cleanCopy(
551
+ this.relations[r][t[e]]
552
+ ));
553
+ else if (t[e] && t[e].constructor === Array) {
554
+ const o = [];
555
+ t[e].forEach((n) => {
556
+ this.relations[r][n] && o.push(this._cleanCopy(this.relations[r][n]));
557
+ }), t[e] = o;
425
558
  }
426
559
  }
427
560
  }
428
- iterateTree(e, t) {
429
- const s = (r) => {
430
- if (r != null) {
431
- if (r.constructor === Array)
432
- for (let i = 0; i < r.length; i++)
433
- s(r[i]);
434
- else if (r.constructor === Object) {
435
- if (r._stopResolving)
561
+ iterateTree(t, e, s) {
562
+ const r = (o) => {
563
+ if (o != null) {
564
+ if (o.constructor === Array)
565
+ for (let n = 0; n < o.length; n++)
566
+ r(o[n]);
567
+ else if (o.constructor === Object) {
568
+ if (o._stopResolving)
436
569
  return;
437
- for (const i in r)
438
- (r.component && r._uid || r.type === "link") && (this._insertRelations(
439
- r,
440
- i,
441
- t
442
- ), this._insertLinks(r, i)), s(r[i]);
570
+ for (const n in o)
571
+ (o.component && o._uid || o.type === "link") && (this._insertRelations(
572
+ o,
573
+ n,
574
+ e,
575
+ s
576
+ ), this._insertLinks(
577
+ o,
578
+ n,
579
+ s
580
+ )), r(o[n]);
443
581
  }
444
582
  }
445
583
  };
446
- s(e.content);
447
- }
448
- async resolveLinks(e, t) {
449
- let s = [];
450
- if (e.link_uuids) {
451
- const r = e.link_uuids.length, i = [], n = 50;
452
- for (let a = 0; a < r; a += n) {
453
- const l = Math.min(r, a + n);
454
- i.push(e.link_uuids.slice(a, l));
584
+ r(t.content);
585
+ }
586
+ async resolveLinks(t, e, s) {
587
+ let r = [];
588
+ if (t.link_uuids) {
589
+ const o = t.link_uuids.length, n = [], c = 50;
590
+ for (let a = 0; a < o; a += c) {
591
+ const l = Math.min(o, a + c);
592
+ n.push(t.link_uuids.slice(a, l));
455
593
  }
456
- for (let a = 0; a < i.length; a++)
594
+ for (let a = 0; a < n.length; a++)
457
595
  (await this.getStories({
458
- per_page: n,
459
- language: t.language,
460
- version: t.version,
461
- by_uuids: i[a].join(",")
596
+ per_page: c,
597
+ language: e.language,
598
+ version: e.version,
599
+ by_uuids: n[a].join(",")
462
600
  })).data.stories.forEach(
463
601
  (l) => {
464
- s.push(l);
602
+ r.push(l);
465
603
  }
466
604
  );
467
605
  } else
468
- s = e.links;
469
- s.forEach((r) => {
470
- this.links[r.uuid] = { ...r, _stopResolving: !0 };
606
+ r = t.links;
607
+ r.forEach((o) => {
608
+ this.links[s][o.uuid] = {
609
+ ...o,
610
+ _stopResolving: !0
611
+ };
471
612
  });
472
613
  }
473
- async resolveRelations(e, t) {
474
- let s = [];
475
- if (e.rel_uuids) {
476
- const r = e.rel_uuids.length, i = [], n = 50;
477
- for (let a = 0; a < r; a += n) {
478
- const l = Math.min(r, a + n);
479
- i.push(e.rel_uuids.slice(a, l));
614
+ async resolveRelations(t, e, s) {
615
+ let r = [];
616
+ if (t.rel_uuids) {
617
+ const o = t.rel_uuids.length, n = [], c = 50;
618
+ for (let a = 0; a < o; a += c) {
619
+ const l = Math.min(o, a + c);
620
+ n.push(t.rel_uuids.slice(a, l));
480
621
  }
481
- for (let a = 0; a < i.length; a++)
622
+ for (let a = 0; a < n.length; a++)
482
623
  (await this.getStories({
483
- per_page: n,
484
- language: t.language,
485
- version: t.version,
486
- by_uuids: i[a].join(",")
624
+ per_page: c,
625
+ language: e.language,
626
+ version: e.version,
627
+ by_uuids: n[a].join(",")
487
628
  })).data.stories.forEach((l) => {
488
- s.push(l);
629
+ r.push(l);
489
630
  });
490
631
  } else
491
- s = e.rels;
492
- s && s.length > 0 && s.forEach((r) => {
493
- this.relations[r.uuid] = { ...r, _stopResolving: !0 };
494
- });
495
- }
496
- async resolveStories(e, t) {
497
- var s, r;
498
- let i = [];
499
- if (typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (i = t.resolve_relations.split(",")), await this.resolveRelations(e, t)), t.resolve_links && ["1", "story", "url"].indexOf(t.resolve_links) > -1 && ((s = e.links) != null && s.length || (r = e.link_uuids) != null && r.length) && await this.resolveLinks(e, t), this.resolveNestedRelations)
500
- for (const n in this.relations)
501
- this.iterateTree(this.relations[n], i);
502
- e.story ? this.iterateTree(e.story, i) : e.stories.forEach((n) => {
503
- this.iterateTree(n, i);
632
+ r = t.rels;
633
+ r && r.length > 0 && r.forEach((o) => {
634
+ this.relations[s][o.uuid] = {
635
+ ...o,
636
+ _stopResolving: !0
637
+ };
504
638
  });
505
639
  }
506
- async cacheResponse(e, t, s) {
507
- const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
508
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
509
- const n = await i.get(r);
640
+ async resolveStories(t, e, s) {
641
+ var r, o;
642
+ let n = [];
643
+ if (this.links[s] = {}, this.relations[s] = {}, typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (n = e.resolve_relations.split(",")), await this.resolveRelations(t, e, s)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && ((r = t.links) != null && r.length || (o = t.link_uuids) != null && o.length) && await this.resolveLinks(t, e, s), this.resolveNestedRelations)
644
+ for (const c in this.relations[s])
645
+ this.iterateTree(
646
+ this.relations[s][c],
647
+ n,
648
+ s
649
+ );
650
+ t.story ? this.iterateTree(t.story, n, s) : t.stories.forEach((c) => {
651
+ this.iterateTree(c, n, s);
652
+ }), delete this.links[s], delete this.relations[s];
653
+ }
654
+ async cacheResponse(t, e, s) {
655
+ const r = this.helpers.stringify({ url: t, params: e }), o = this.cacheProvider();
656
+ if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
657
+ const n = await o.get(r);
510
658
  if (n)
511
659
  return Promise.resolve(n);
512
660
  }
513
- return new Promise((n, a) => {
661
+ return new Promise((n, c) => {
514
662
  try {
515
663
  (async () => {
516
- var l;
664
+ var a;
517
665
  try {
518
- const c = await this.throttle("get", e, t);
519
- let u = { data: c.data, headers: c.headers };
520
- return (l = c.headers) != null && l["per-page"] && (u = Object.assign({}, u, {
521
- perPage: c.headers["per-page"] ? parseInt(c.headers["per-page"]) : 0,
522
- total: c.headers["per-page"] ? parseInt(c.headers.total) : 0
523
- })), c.status != 200 ? a(c) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, t), t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version == "draft" && d[t.token] != u.data.cv && await this.flushCache(), d[t.token] = u.data.cv), n(u));
524
- } catch (c) {
525
- return a(c);
666
+ const l = await this.throttle("get", t, e);
667
+ let u = { data: l.data, headers: l.headers };
668
+ if ((a = l.headers) != null && a["per-page"] && (u = Object.assign({}, u, {
669
+ perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
670
+ total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
671
+ })), l.status != 200)
672
+ return c(l);
673
+ if (u.data.story || u.data.stories) {
674
+ const d = this.resolveCounter = ++this.resolveCounter % 1e3;
675
+ await this.resolveStories(u.data, e, `${d}`);
676
+ }
677
+ return e.version === "published" && t != "/cdn/spaces/me" && await o.set(r, u), u.data.cv && e.token && (e.version == "draft" && f[e.token] != u.data.cv && await this.flushCache(), f[e.token] = u.data.cv), n(u);
678
+ } catch (l) {
679
+ return c(l);
526
680
  }
527
681
  })();
528
682
  } catch {
529
683
  }
530
684
  });
531
685
  }
532
- throttledRequest(e, t, s) {
533
- return this.client[e](t, s);
686
+ throttledRequest(t, e, s) {
687
+ return this.client[t](e, s);
534
688
  }
535
689
  cacheVersions() {
536
- return d;
690
+ return f;
537
691
  }
538
692
  cacheVersion() {
539
- return d[this.accessToken];
693
+ return f[this.accessToken];
540
694
  }
541
- setCacheVersion(e) {
542
- this.accessToken && (d[this.accessToken] = e);
695
+ setCacheVersion(t) {
696
+ this.accessToken && (f[this.accessToken] = t);
543
697
  }
544
698
  cacheProvider() {
545
699
  switch (this.cache.type) {
546
700
  case "memory":
547
701
  return {
548
- get(e) {
549
- return Promise.resolve(f[e]);
702
+ get(t) {
703
+ return Promise.resolve(y[t]);
550
704
  },
551
705
  getAll() {
552
- return Promise.resolve(f);
706
+ return Promise.resolve(y);
553
707
  },
554
- set(e, t) {
555
- return f[e] = t, Promise.resolve(void 0);
708
+ set(t, e) {
709
+ return y[t] = e, Promise.resolve(void 0);
556
710
  },
557
711
  flush() {
558
- return f = {}, Promise.resolve(void 0);
712
+ return y = {}, Promise.resolve(void 0);
559
713
  }
560
714
  };
561
715
  case "custom":
@@ -582,132 +736,132 @@ class ne {
582
736
  return await this.cacheProvider().flush(), this;
583
737
  }
584
738
  }
585
- const ge = (o = {}) => {
586
- const { apiOptions: e } = o;
587
- if (!e.accessToken) {
739
+ const _t = (i = {}) => {
740
+ const { apiOptions: t } = i;
741
+ if (!t.accessToken) {
588
742
  console.error(
589
743
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
590
744
  );
591
745
  return;
592
746
  }
593
- return { storyblokApi: new ne(e) };
594
- }, ae = (o) => {
595
- if (typeof o != "object" || typeof o._editable > "u")
747
+ return { storyblokApi: new mt(t) };
748
+ }, yt = (i) => {
749
+ if (typeof i != "object" || typeof i._editable > "u")
596
750
  return {};
597
- const e = JSON.parse(
598
- o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
751
+ const t = JSON.parse(
752
+ i._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
599
753
  );
600
754
  return {
601
- "data-blok-c": JSON.stringify(e),
602
- "data-blok-uid": e.id + "-" + e.uid
755
+ "data-blok-c": JSON.stringify(t),
756
+ "data-blok-uid": t.id + "-" + t.uid
603
757
  };
604
758
  };
605
- let k;
606
- const le = "https://app.storyblok.com/f/storyblok-v2-latest.js", ce = (o, e, t = {}) => {
759
+ let $;
760
+ const bt = "https://app.storyblok.com/f/storyblok-v2-latest.js", kt = (i, t, e = {}) => {
607
761
  var s;
608
- const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
762
+ const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
609
763
  "_storyblok"
610
- ) === o;
611
- if (!(!r || !i)) {
612
- if (!o) {
764
+ ) === i;
765
+ if (!(!r || !o)) {
766
+ if (!i) {
613
767
  console.warn("Story ID is not defined. Please provide a valid ID.");
614
768
  return;
615
769
  }
616
770
  window.storyblokRegisterEvent(() => {
617
- new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
618
- n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
771
+ new window.StoryblokBridge(e).on(["input", "published", "change"], (n) => {
772
+ n.action === "input" && n.story.id === i ? t(n.story) : (n.action === "change" || n.action === "published") && n.storyId === i && window.location.reload();
619
773
  });
620
774
  });
621
775
  }
622
- }, he = (o = {}) => {
623
- var e, t;
776
+ }, vt = (i = {}) => {
777
+ var t, e;
624
778
  const {
625
779
  bridge: s,
626
780
  accessToken: r,
627
- use: i = [],
781
+ use: o = [],
628
782
  apiOptions: n = {},
629
- richText: a = {}
630
- } = o;
783
+ richText: c = {}
784
+ } = i;
631
785
  n.accessToken = n.accessToken || r;
632
- const l = { bridge: s, apiOptions: n };
633
- let c = {};
634
- i.forEach((p) => {
635
- c = { ...c, ...p(l) };
786
+ const a = { bridge: s, apiOptions: n };
787
+ let l = {};
788
+ o.forEach((d) => {
789
+ l = { ...l, ...d(a) };
636
790
  });
637
- const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
638
- return s !== !1 && u && A(le), k = new m(a.schema), a.resolver && T(k, a.resolver), c;
639
- }, T = (o, e) => {
640
- o.addNode("blok", (t) => {
791
+ const u = !(typeof window > "u") && ((e = (t = window.location) == null ? void 0 : t.search) == null ? void 0 : e.includes("_storyblok_tk"));
792
+ return s !== !1 && u && z(bt), $ = new b(c.schema), c.resolver && P($, c.resolver), l;
793
+ }, P = (i, t) => {
794
+ i.addNode("blok", (e) => {
641
795
  let s = "";
642
- return t.attrs.body.forEach((r) => {
643
- s += e(r.component, r);
796
+ return e.attrs.body.forEach((r) => {
797
+ s += t(r.component, r);
644
798
  }), {
645
799
  html: s
646
800
  };
647
801
  });
648
- }, fe = (o, e, t) => {
649
- let s = t || k;
802
+ }, Rt = (i, t, e) => {
803
+ let s = e || $;
650
804
  if (!s) {
651
805
  console.error(
652
806
  "Please initialize the Storyblok SDK before calling the renderRichText function"
653
807
  );
654
808
  return;
655
809
  }
656
- return o === "" ? "" : o ? (e && (s = new m(e.schema), e.resolver && T(s, e.resolver)), s.render(o)) : (console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
810
+ return i === "" ? "" : i ? (t && (s = new b(t.schema), t.resolver && P(s, t.resolver)), s.render(i)) : (console.warn(`${i} is not a valid Richtext object. This might be because the value of the richtext field is empty.
657
811
 
658
812
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
659
- }, ue = /* @__PURE__ */ $({
813
+ }, wt = /* @__PURE__ */ E({
660
814
  __name: "StoryblokComponent",
661
815
  props: {
662
816
  blok: null
663
817
  },
664
- setup(o) {
665
- return (e, t) => (P(), E(j(o.blok.component), S(x({ ...e.$props, ...e.$attrs })), null, 16));
666
- }
667
- }), de = {
668
- beforeMount(o, e) {
669
- if (e.value) {
670
- const t = ae(e.value);
671
- o.setAttribute("data-blok-c", t["data-blok-c"]), o.setAttribute("data-blok-uid", t["data-blok-uid"]), o.classList.add("storyblok__outline");
818
+ setup(i) {
819
+ return (t, e) => (S(), C(I(i.blok.component), A(O({ ...t.$props, ...t.$attrs })), null, 16));
820
+ }
821
+ }), $t = {
822
+ beforeMount(i, t) {
823
+ if (t.value) {
824
+ const e = yt(t.value);
825
+ i.setAttribute("data-blok-c", e["data-blok-c"]), i.setAttribute("data-blok-uid", e["data-blok-uid"]), i.classList.add("storyblok__outline");
672
826
  }
673
827
  }
674
- }, R = (o) => {
675
- console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
828
+ }, x = (i) => {
829
+ console.error(`You can't use ${i} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
676
830
  `);
677
831
  };
678
- let g = null;
679
- const me = () => (g || R("useStoryblokApi"), g), ye = async (o, e = {}, t = {}) => {
680
- const s = C(null);
681
- if (O(() => {
682
- s.value && s.value.id && ce(
832
+ let m = null;
833
+ const jt = () => (m || x("useStoryblokApi"), m), Pt = async (i, t = {}, e = {}) => {
834
+ const s = M(null);
835
+ if (N(() => {
836
+ s.value && s.value.id && kt(
683
837
  s.value.id,
684
838
  (r) => s.value = r,
685
- t
686
- );
687
- }), g) {
688
- const { data: r } = await g.get(
689
- `cdn/stories/${o}`,
690
839
  e
691
840
  );
841
+ }), m) {
842
+ const { data: r } = await m.get(
843
+ `cdn/stories/${i}`,
844
+ t
845
+ );
692
846
  s.value = r.story;
693
847
  } else
694
- R("useStoryblok");
848
+ x("useStoryblok");
695
849
  return s;
696
- }, ke = {
697
- install(o, e = {}) {
698
- o.directive("editable", de), o.component("StoryblokComponent", ue);
699
- const { storyblokApi: t } = he(e);
700
- g = t;
850
+ }, xt = {
851
+ install(i, t = {}) {
852
+ i.directive("editable", $t), i.component("StoryblokComponent", wt);
853
+ const { storyblokApi: e } = vt(t);
854
+ m = e;
701
855
  }
702
856
  };
703
857
  export {
704
- m as RichTextResolver,
705
- re as RichTextSchema,
706
- ue as StoryblokComponent,
707
- ke as StoryblokVue,
708
- ge as apiPlugin,
709
- fe as renderRichText,
710
- ye as useStoryblok,
711
- me as useStoryblokApi,
712
- ce as useStoryblokBridge
858
+ b as RichTextResolver,
859
+ pt as RichTextSchema,
860
+ wt as StoryblokComponent,
861
+ xt as StoryblokVue,
862
+ _t as apiPlugin,
863
+ Rt as renderRichText,
864
+ Pt as useStoryblok,
865
+ jt as useStoryblokApi,
866
+ kt as useStoryblokBridge
713
867
  };