@storyblok/vue 7.1.13 → 7.1.14

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