@storyblok/js 3.0.8 → 3.0.10

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