@storyblok/js 3.0.6 → 3.0.7

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