@storyblok/js 2.2.7 → 2.2.9

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