@storyblok/js 3.0.8 → 3.1.0-next.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,39 +1,38 @@
1
- let _ = !1;
2
- const S = [], O = (n) => new Promise((t, e) => {
1
+ let N = !1;
2
+ const M = [], D = (i) => 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
- _ ? r() : S.push(r);
9
- }, document.getElementById("storyblok-javascript-bridge")))
10
- return;
8
+ N ? r() : M.push(r);
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 = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
12
+ M.forEach((n) => n()), N = !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);
17
- function j(n) {
18
- return !(n !== n || n === 1 / 0 || n === -1 / 0);
15
+ var V = Object.defineProperty, J = (i, e, t) => e in i ? V(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, d = (i, e, t) => (J(i, typeof e != "symbol" ? e + "" : e, t), t);
16
+ function U(i) {
17
+ return !(i !== i || i === 1 / 0 || i === -1 / 0);
19
18
  }
20
- function C(n, t, e) {
21
- if (!j(t))
19
+ function K(i, e, t) {
20
+ if (!U(e))
22
21
  throw new TypeError("Expected `limit` to be a finite number");
23
- if (!j(e))
22
+ if (!U(t))
24
23
  throw new TypeError("Expected `interval` to be a finite number");
25
24
  const s = [];
26
- let r = [], i = 0;
25
+ let r = [], n = 0;
27
26
  const o = function() {
28
- i++;
27
+ n++;
29
28
  const a = setTimeout(function() {
30
- i--, s.length > 0 && o(), r = r.filter(function(u) {
29
+ n--, 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
34
  const l = s.shift();
36
- l.resolve(n.apply(l.self, l.args));
35
+ l.resolve(i.apply(l.self, l.args));
37
36
  }, c = function(...a) {
38
37
  const l = this;
39
38
  return new Promise(function(u, p) {
@@ -42,7 +41,7 @@ function C(n, t, e) {
42
41
  reject: p,
43
42
  args: a,
44
43
  self: l
45
- }), i < t && o();
44
+ }), n < e && o();
46
45
  });
47
46
  };
48
47
  return c.abort = function() {
@@ -53,24 +52,24 @@ function C(n, t, e) {
53
52
  }), s.length = 0;
54
53
  }, c;
55
54
  }
56
- class b {
55
+ class O {
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
+ d(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), d(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
+ })), d(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), d(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), d(this, "range", (e = 0, t = e) => {
62
+ const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
63
+ return this.arrayFrom(s, (n, o) => o * r + e);
64
+ }), d(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), d(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), d(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, (n) => t[n]) : 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 n in e) {
85
+ if (!Object.prototype.hasOwnProperty.call(e, n))
87
86
  continue;
88
- const o = t[i], c = s ? "" : encodeURIComponent(i);
87
+ const o = e[n], c = s ? "" : encodeURIComponent(n);
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("[" + c + "]") : c,
93
92
  Array.isArray(o)
94
- ) : a = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(o), r.push(a);
93
+ ) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(o), r.push(a);
95
94
  }
96
95
  return r.join("&");
97
96
  }
@@ -100,203 +99,205 @@ 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", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
104
+ switch (e) {
106
105
  case "us":
107
106
  return s;
108
107
  case "cn":
109
108
  return r;
110
109
  case "ap":
111
- return i;
110
+ return n;
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 = {};
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 = () => ({
118
+ const Y = function(i, e) {
119
+ const t = {};
120
+ for (const s in i) {
121
+ const r = i[s];
122
+ e.indexOf(s) > -1 && r !== null && (t[s] = r);
123
+ }
124
+ return t;
125
+ }, X = (i) => i === "email", W = () => ({
127
126
  singleTag: "hr"
128
- }), M = () => ({
127
+ }), Q = () => ({
129
128
  tag: "blockquote"
130
- }), z = () => ({
129
+ }), Z = () => ({
131
130
  tag: "ul"
132
- }), U = (n) => ({
131
+ }), ee = (i) => ({
133
132
  tag: [
134
133
  "pre",
135
134
  {
136
135
  tag: "code",
137
- attrs: n.attrs
136
+ attrs: i.attrs
138
137
  }
139
138
  ]
140
- }), H = () => ({
139
+ }), te = () => ({
141
140
  singleTag: "br"
142
- }), q = (n) => ({
143
- tag: `h${n.attrs.level}`
144
- }), B = (n) => ({
141
+ }), se = (i) => ({
142
+ tag: `h${i.attrs.level}`
143
+ }), re = (i) => ({
145
144
  singleTag: [
146
145
  {
147
146
  tag: "img",
148
- attrs: A(n.attrs, ["src", "alt", "title"])
147
+ attrs: Y(i.attrs, ["src", "alt", "title"])
149
148
  }
150
149
  ]
151
- }), F = () => ({
150
+ }), ie = () => ({
152
151
  tag: "li"
153
- }), V = () => ({
152
+ }), ne = () => ({
154
153
  tag: "ol"
155
- }), J = () => ({
154
+ }), oe = () => ({
156
155
  tag: "p"
157
- }), D = (n) => ({
156
+ }), ae = (i) => ({
158
157
  tag: [
159
158
  {
160
159
  tag: "span",
161
160
  attrs: {
162
161
  "data-type": "emoji",
163
- "data-name": n.attrs.name,
164
- emoji: n.attrs.emoji
162
+ "data-name": i.attrs.name,
163
+ emoji: i.attrs.emoji
165
164
  }
166
165
  }
167
166
  ]
168
- }), Y = () => ({
167
+ }), le = () => ({
169
168
  tag: "b"
170
- }), K = () => ({
169
+ }), ce = () => ({
171
170
  tag: "s"
172
- }), W = () => ({
171
+ }), he = () => ({
173
172
  tag: "u"
174
- }), G = () => ({
173
+ }), ue = () => ({
175
174
  tag: "strong"
176
- }), Q = () => ({
175
+ }), de = () => ({
177
176
  tag: "code"
178
- }), X = () => ({
177
+ }), pe = () => ({
179
178
  tag: "i"
180
- }), Z = (n) => {
181
- if (!n.attrs)
179
+ }), ge = (i) => {
180
+ if (!i.attrs)
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 O().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
185
+ if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), X(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
+ }, fe = (i) => ({
200
199
  tag: [
201
200
  {
202
201
  tag: "span",
203
- attrs: n.attrs
202
+ attrs: i.attrs
204
203
  }
205
204
  ]
206
- }), et = () => ({
205
+ }), me = () => ({
207
206
  tag: "sub"
208
- }), st = () => ({
207
+ }), ye = () => ({
209
208
  tag: "sup"
210
- }), rt = (n) => ({
209
+ }), be = (i) => ({
211
210
  tag: [
212
211
  {
213
212
  tag: "span",
214
- attrs: n.attrs
213
+ attrs: i.attrs
215
214
  }
216
215
  ]
217
- }), it = (n) => {
218
- var t;
219
- return (t = n.attrs) != null && t.color ? {
216
+ }), ke = (i) => {
217
+ var e;
218
+ return (e = i.attrs) != null && e.color ? {
220
219
  tag: [
221
220
  {
222
221
  tag: "span",
223
222
  attrs: {
224
- style: `background-color:${n.attrs.color};`
223
+ style: `background-color:${i.attrs.color};`
225
224
  }
226
225
  }
227
226
  ]
228
227
  } : {
229
228
  tag: ""
230
229
  };
231
- }, nt = (n) => {
232
- var t;
233
- return (t = n.attrs) != null && t.color ? {
230
+ }, ve = (i) => {
231
+ var e;
232
+ return (e = i.attrs) != null && e.color ? {
234
233
  tag: [
235
234
  {
236
235
  tag: "span",
237
236
  attrs: {
238
- style: `color:${n.attrs.color}`
237
+ style: `color:${i.attrs.color}`
239
238
  }
240
239
  }
241
240
  ]
242
241
  } : {
243
242
  tag: ""
244
243
  };
245
- }, ot = {
244
+ }, $e = {
246
245
  nodes: {
247
- horizontal_rule: L,
248
- blockquote: M,
249
- bullet_list: z,
250
- code_block: U,
251
- hard_break: H,
252
- heading: q,
253
- image: B,
254
- list_item: F,
255
- ordered_list: V,
256
- paragraph: J,
257
- emoji: D
246
+ horizontal_rule: W,
247
+ blockquote: Q,
248
+ bullet_list: Z,
249
+ code_block: ee,
250
+ hard_break: te,
251
+ heading: se,
252
+ image: re,
253
+ list_item: ie,
254
+ ordered_list: ne,
255
+ paragraph: oe,
256
+ emoji: ae
258
257
  },
259
258
  marks: {
260
- bold: Y,
261
- strike: K,
262
- underline: W,
263
- strong: G,
264
- code: Q,
265
- italic: X,
266
- 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 = {
259
+ bold: le,
260
+ strike: ce,
261
+ underline: he,
262
+ strong: ue,
263
+ code: de,
264
+ italic: pe,
265
+ link: ge,
266
+ styled: fe,
267
+ subscript: me,
268
+ superscript: ye,
269
+ anchor: be,
270
+ highlight: ke,
271
+ textStyle: ve
272
+ }
273
+ }, Te = function(i) {
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 i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
283
282
  };
284
- class v {
285
- constructor(t) {
286
- h(this, "marks"), h(this, "nodes"), t || (t = ot), this.marks = t.marks || [], this.nodes = t.nodes || [];
283
+ class x {
284
+ constructor(e) {
285
+ d(this, "marks"), d(this, "nodes"), e || (e = $e), 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 (console.warn(
295
+ "Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` instead. https://github.com/storyblok/richtext/"
296
+ ), e && e.content && Array.isArray(e.content)) {
296
297
  let s = "";
297
- return t.content.forEach((r) => {
298
+ return e.content.forEach((r) => {
298
299
  s += this.renderNode(r);
299
- }), e.optimizeImages ? this.optimizeImages(s, e.optimizeImages) : s;
300
+ }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
300
301
  }
301
302
  return console.warn(
302
303
  `The render method must receive an Object with a "content" field.
@@ -325,101 +326,101 @@ class v {
325
326
  }`
326
327
  ), "";
327
328
  }
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()}`));
329
+ optimizeImages(e, t) {
330
+ let s = 0, r = 0, n = "", o = "";
331
+ typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (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))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
331
332
  const c = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
332
- return t = t.replace(
333
+ return e = e.replace(
333
334
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
334
335
  `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
+ ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
336
337
  var l, u;
337
338
  const p = a.match(
338
339
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
339
340
  );
340
341
  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) {
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`;
342
+ const m = {
343
+ srcset: (l = t.srcset) == null ? void 0 : l.map((y) => {
344
+ if (typeof y == "number")
345
+ return `//${p}/m/${y}x0${o} ${y}w`;
346
+ if (typeof y == "object" && y.length === 2) {
347
+ let w = 0, E = 0;
348
+ return typeof y[0] == "number" && (w = y[0]), typeof y[1] == "number" && (E = y[1]), `//${p}/m/${w}x${E}${o} ${w}w`;
348
349
  }
349
350
  }).join(", "),
350
- sizes: (u = e.sizes) == null ? void 0 : u.map((d) => d).join(", ")
351
+ sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
351
352
  };
352
- let f = "";
353
- return g.srcset && (f += `srcset="${g.srcset}" `), g.sizes && (f += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
353
+ let k = "";
354
+ return m.srcset && (k += `srcset="${m.srcset}" `), m.sizes && (k += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
354
355
  }
355
356
  return a;
356
- })), t;
357
+ })), e;
357
358
  }
358
- renderNode(t) {
359
- const e = [];
360
- t.marks && t.marks.forEach((r) => {
361
- const i = this.getMatchingMark(r);
362
- i && i.tag !== "" && e.push(this.renderOpeningTag(i.tag));
359
+ renderNode(e) {
360
+ const t = [];
361
+ e.marks && e.marks.forEach((r) => {
362
+ const n = this.getMatchingMark(r);
363
+ n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
363
364
  });
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
- const i = this.getMatchingMark(r);
369
- i && i.tag !== "" && e.push(this.renderClosingTag(i.tag));
370
- }), e.join("");
371
- }
372
- renderTag(t, e) {
373
- return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
365
+ const s = this.getMatchingNode(e);
366
+ return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
367
+ t.push(this.renderNode(r));
368
+ }) : e.text ? t.push(Te(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) => {
369
+ const n = this.getMatchingMark(r);
370
+ n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
371
+ }), t.join("");
372
+ }
373
+ renderTag(e, t) {
374
+ return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
374
375
  if (s.constructor === String)
375
- return `<${s}${e}>`;
376
+ return `<${s}${t}>`;
376
377
  {
377
378
  let r = `<${s.tag}`;
378
379
  if (s.attrs)
379
- for (const i in s.attrs) {
380
- const o = s.attrs[i];
381
- o !== null && (r += ` ${i}="${o}"`);
380
+ for (const n in s.attrs) {
381
+ const o = s.attrs[n];
382
+ o !== null && (r += ` ${n}="${o}"`);
382
383
  }
383
- return `${r}${e}>`;
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 Re {
422
+ constructor(e) {
423
+ d(this, "baseURL"), d(this, "timeout"), d(this, "headers"), d(this, "responseInterceptor"), d(this, "fetch"), d(this, "ejectInterceptor"), d(this, "url"), d(this, "parameters"), d(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,47 +428,47 @@ 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;
455
- }
456
- async _methodHandler(t) {
457
- let e = `${this.baseURL}${this.url}`, s = null;
458
- if (t === "get") {
459
- const a = new b();
460
- e = `${this.baseURL}${this.url}?${a.stringify(
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;
456
+ }
457
+ async _methodHandler(e) {
458
+ let t = `${this.baseURL}${this.url}`, s = null;
459
+ if (e === "get") {
460
+ const a = new O();
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
+ const r = new URL(t), n = new AbortController(), { signal: o } = n;
466
467
  let c;
467
- this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
468
+ this.timeout && (c = setTimeout(() => n.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,
@@ -484,120 +485,120 @@ class lt {
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);
498
- 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
497
+ if (t.test(`${e.status}`))
498
+ return s(e);
499
+ const n = {
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
- r(i);
504
+ r(n);
504
505
  });
505
506
  }
506
507
  }
507
- const x = "SB-Agent", w = {
508
+ const H = "SB-Agent", L = {
508
509
  defaultAgentName: "SB-JS-CLIENT",
509
510
  defaultAgentVersion: "SB-Agent-Version",
510
511
  packageVersion: "6.0.0"
511
512
  };
512
- let y = {};
513
- const m = {};
514
- class ct {
513
+ let I = {};
514
+ const S = {};
515
+ class we {
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
+ d(this, "client"), d(this, "maxRetries"), d(this, "retriesDelay"), d(this, "throttle"), d(this, "accessToken"), d(this, "cache"), d(this, "helpers"), d(this, "resolveCounter"), d(this, "relations"), d(this, "links"), d(this, "richTextResolver"), d(this, "resolveNestedRelations"), d(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 O().getRegionURL, c = e.https === !1 ? "http" : "https";
526
+ e.oauthToken ? s = `${c}://${o(e.region)}/v1` : s = `${c}://${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]);
531
- r.has(x) || (r.set(x, w.defaultAgentName), r.set(
532
- w.defaultAgentVersion,
533
- w.packageVersion
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]);
532
+ r.has(H) || (r.set(H, L.defaultAgentName), r.set(
533
+ L.defaultAgentVersion,
534
+ L.packageVersion
534
535
  ));
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
+ let n = 5;
537
+ e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new x(e.richTextSchema) : this.richTextResolver = new x(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = K(this.throttledRequest, n, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new O(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new Re({
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 = S[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) {
562
+ const n = this.factoryParamOptions(
563
+ e,
564
+ this.helpers.getOptionsPage(t, s, r)
564
565
  );
565
- return this.cacheResponse(t, i);
566
+ return this.cacheResponse(e, n);
566
567
  }
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);
568
+ get(e, t, s) {
569
+ t || (t = {});
570
+ const r = `/${e}`, n = this.factoryParamOptions(r, t);
571
+ return this.client.setFetchOptions(s), this.cacheResponse(r, n);
571
572
  }
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
+ async getAll(e, t, s, r) {
574
+ const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, c = o.split("/"), a = s || c[c.length - 1], l = 1, u = await this.makeRequest(o, t, n, l), p = u.total ? Math.ceil(u.total / n) : 1;
574
575
  this.client.setFetchOptions(r);
575
- const g = await this.helpers.asyncMap(
576
+ const m = await this.helpers.asyncMap(
576
577
  this.helpers.range(l, p),
577
- (f) => this.makeRequest(o, e, i, f + 1)
578
+ (k) => this.makeRequest(o, t, n, k + 1)
578
579
  );
579
580
  return this.helpers.flatMap(
580
- [u, ...g],
581
- (f) => Object.values(f.data[a])
581
+ [u, ...m],
582
+ (k) => Object.values(k.data[a])
582
583
  );
583
584
  }
584
- post(t, e, s) {
585
- const r = `/${t}`;
586
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, e));
585
+ post(e, t, s) {
586
+ const r = `/${e}`;
587
+ return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, t));
587
588
  }
588
- put(t, e, s) {
589
- const r = `/${t}`;
590
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, e));
589
+ put(e, t, s) {
590
+ const r = `/${e}`;
591
+ return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, t));
591
592
  }
592
- delete(t, e, s) {
593
- const r = `/${t}`;
594
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, e));
593
+ delete(e, t, s) {
594
+ const r = `/${e}`;
595
+ return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, t));
595
596
  }
596
- getStories(t, e) {
597
- return this.client.setFetchOptions(e), this._addResolveLevel(t), this.get("cdn/stories", t);
597
+ getStories(e, t) {
598
+ return this.client.setFetchOptions(t), this._addResolveLevel(e), this.get("cdn/stories", e);
598
599
  }
599
- getStory(t, e, s) {
600
- return this.client.setFetchOptions(s), this._addResolveLevel(e), this.get(`cdn/stories/${t}`, e);
600
+ getStory(e, t, s) {
601
+ return this.client.setFetchOptions(s), this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t);
601
602
  }
602
603
  getToken() {
603
604
  return this.accessToken;
@@ -605,14 +606,14 @@ class ct {
605
606
  ejectInterceptor() {
606
607
  this.client.eject();
607
608
  }
608
- _addResolveLevel(t) {
609
- typeof t.resolve_relations < "u" && (t.resolve_level = 2);
609
+ _addResolveLevel(e) {
610
+ typeof e.resolve_relations < "u" && (e.resolve_level = 2);
610
611
  }
611
- _cleanCopy(t) {
612
- return JSON.parse(JSON.stringify(t));
612
+ _cleanCopy(e) {
613
+ return JSON.parse(JSON.stringify(e));
613
614
  }
614
- _insertLinks(t, e, s) {
615
- const r = t[e];
615
+ _insertLinks(e, t, s) {
616
+ const r = e[t];
616
617
  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
618
  }
618
619
  /**
@@ -621,52 +622,52 @@ class ct {
621
622
  * @param uuid The uuid of the story
622
623
  * @returns string | object
623
624
  */
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;
628
- }
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)));
631
- }
632
- iterateTree(t, e, s) {
633
- const r = (i) => {
634
- if (i != null) {
635
- if (i.constructor === Array)
636
- for (let o = 0; o < i.length; o++)
637
- r(i[o]);
638
- else if (i.constructor === Object) {
639
- if (i._stopResolving)
625
+ getStoryReference(e, t) {
626
+ return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
627
+ this.relations[e][t]
628
+ )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
629
+ }
630
+ _insertRelations(e, t, s, r) {
631
+ 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((n) => this.getStoryReference(r, n)).filter(Boolean)));
632
+ }
633
+ iterateTree(e, t, s) {
634
+ const r = (n) => {
635
+ if (n != null) {
636
+ if (n.constructor === Array)
637
+ for (let o = 0; o < n.length; o++)
638
+ r(n[o]);
639
+ else if (n.constructor === Object) {
640
+ if (n._stopResolving)
640
641
  return;
641
- for (const o in i)
642
- (i.component && i._uid || i.type === "link") && (this._insertRelations(
643
- i,
642
+ for (const o in n)
643
+ (n.component && n._uid || n.type === "link") && (this._insertRelations(
644
+ n,
644
645
  o,
645
- e,
646
+ t,
646
647
  s
647
648
  ), this._insertLinks(
648
- i,
649
+ n,
649
650
  o,
650
651
  s
651
- )), r(i[o]);
652
+ )), r(n[o]);
652
653
  }
653
654
  }
654
655
  };
655
- r(t.content);
656
+ r(e.content);
656
657
  }
657
- async resolveLinks(t, e, s) {
658
+ async resolveLinks(e, t, s) {
658
659
  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));
660
+ if (e.link_uuids) {
661
+ const n = e.link_uuids.length, o = [], c = 50;
662
+ for (let a = 0; a < n; a += c) {
663
+ const l = Math.min(n, a + c);
664
+ o.push(e.link_uuids.slice(a, l));
664
665
  }
665
666
  for (let a = 0; a < o.length; a++)
666
667
  (await this.getStories({
667
668
  per_page: c,
668
- language: e.language,
669
- version: e.version,
669
+ language: t.language,
670
+ version: t.version,
670
671
  by_uuids: o[a].join(",")
671
672
  })).data.stories.forEach(
672
673
  (l) => {
@@ -674,37 +675,37 @@ class ct {
674
675
  }
675
676
  );
676
677
  } else
677
- r = t.links;
678
- r.forEach((i) => {
679
- this.links[s][i.uuid] = {
680
- ...i,
678
+ r = e.links;
679
+ r.forEach((n) => {
680
+ this.links[s][n.uuid] = {
681
+ ...n,
681
682
  _stopResolving: !0
682
683
  };
683
684
  });
684
685
  }
685
- async resolveRelations(t, e, s) {
686
+ async resolveRelations(e, t, s) {
686
687
  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));
688
+ if (e.rel_uuids) {
689
+ const n = e.rel_uuids.length, o = [], c = 50;
690
+ for (let a = 0; a < n; a += c) {
691
+ const l = Math.min(n, a + c);
692
+ o.push(e.rel_uuids.slice(a, l));
692
693
  }
693
694
  for (let a = 0; a < o.length; a++)
694
695
  (await this.getStories({
695
696
  per_page: c,
696
- language: e.language,
697
- version: e.version,
697
+ language: t.language,
698
+ version: t.version,
698
699
  by_uuids: o[a].join(","),
699
- excluding_fields: e.excluding_fields
700
+ excluding_fields: t.excluding_fields
700
701
  })).data.stories.forEach((l) => {
701
702
  r.push(l);
702
703
  });
703
704
  } else
704
- r = t.rels;
705
- r && r.length > 0 && r.forEach((i) => {
706
- this.relations[s][i.uuid] = {
707
- ...i,
705
+ r = e.rels;
706
+ r && r.length > 0 && r.forEach((n) => {
707
+ this.relations[s][n.uuid] = {
708
+ ...n,
708
709
  _stopResolving: !0
709
710
  };
710
711
  });
@@ -718,32 +719,31 @@ class ct {
718
719
  * @returns Promise<void>
719
720
  *
720
721
  */
721
- async resolveStories(t, e, s) {
722
- var r, i;
722
+ async resolveStories(e, t, s) {
723
+ var r, n;
723
724
  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
+ 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 || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
725
726
  for (const c in this.relations[s])
726
727
  this.iterateTree(
727
728
  this.relations[s][c],
728
729
  o,
729
730
  s
730
731
  );
731
- t.story ? this.iterateTree(t.story, o, s) : t.stories.forEach((c) => {
732
+ e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((c) => {
732
733
  this.iterateTree(c, o, s);
733
734
  }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
734
735
  }
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);
736
+ async cacheResponse(e, t, s) {
737
+ const r = this.helpers.stringify({ url: e, params: t }), n = this.cacheProvider();
738
+ if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
739
+ const o = await n.get(r);
740
740
  if (o)
741
741
  return Promise.resolve(o);
742
742
  }
743
743
  return new Promise(async (o, c) => {
744
744
  var a;
745
745
  try {
746
- const l = await this.throttle("get", t, e);
746
+ const l = await this.throttle("get", e, t);
747
747
  if (l.status !== 200)
748
748
  return c(l);
749
749
  let u = { data: l.data, headers: l.headers };
@@ -752,46 +752,48 @@ class ct {
752
752
  total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
753
753
  })), u.data.story || u.data.stories) {
754
754
  const p = this.resolveCounter = ++this.resolveCounter % 1e3;
755
- await this.resolveStories(u.data, e, `${p}`);
755
+ await this.resolveStories(u.data, t, `${p}`);
756
756
  }
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);
757
+ return t.version === "published" && e != "/cdn/spaces/me" && await n.set(r, u), u.data.cv && t.token && (t.version === "draft" && S[t.token] != u.data.cv && await this.flushCache(), S[t.token] = t.cv ? t.cv : u.data.cv), o(u);
758
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);
759
+ if (l.response && l.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
760
+ return console.log(
761
+ `Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
762
+ ), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(o).catch(c);
761
763
  c(l);
762
764
  }
763
765
  });
764
766
  }
765
- throttledRequest(t, e, s) {
766
- return this.client[t](e, s);
767
+ throttledRequest(e, t, s) {
768
+ return this.client[e](t, s);
767
769
  }
768
770
  cacheVersions() {
769
- return m;
771
+ return S;
770
772
  }
771
773
  cacheVersion() {
772
- return m[this.accessToken];
774
+ return S[this.accessToken];
773
775
  }
774
- setCacheVersion(t) {
775
- this.accessToken && (m[this.accessToken] = t);
776
+ setCacheVersion(e) {
777
+ this.accessToken && (S[this.accessToken] = e);
776
778
  }
777
779
  clearCacheVersion() {
778
- this.accessToken && (m[this.accessToken] = 0);
780
+ this.accessToken && (S[this.accessToken] = 0);
779
781
  }
780
782
  cacheProvider() {
781
783
  switch (this.cache.type) {
782
784
  case "memory":
783
785
  return {
784
- get(t) {
785
- return Promise.resolve(y[t]);
786
+ get(e) {
787
+ return Promise.resolve(I[e]);
786
788
  },
787
789
  getAll() {
788
- return Promise.resolve(y);
790
+ return Promise.resolve(I);
789
791
  },
790
- set(t, e) {
791
- return y[t] = e, Promise.resolve(void 0);
792
+ set(e, t) {
793
+ return I[e] = t, Promise.resolve(void 0);
792
794
  },
793
795
  flush() {
794
- return y = {}, Promise.resolve(void 0);
796
+ return I = {}, Promise.resolve(void 0);
795
797
  }
796
798
  };
797
799
  case "custom":
@@ -818,93 +820,259 @@ class ct {
818
820
  return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
819
821
  }
820
822
  }
821
- const ut = (n = {}) => {
822
- const { apiOptions: t } = n;
823
- if (!t.accessToken) {
823
+ const je = (i = {}) => {
824
+ const { apiOptions: e } = i;
825
+ if (!e.accessToken) {
824
826
  console.error(
825
827
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
826
828
  );
827
829
  return;
828
830
  }
829
- return { storyblokApi: new ct(t) };
830
- }, pt = (n) => {
831
- if (typeof n != "object" || typeof n._editable > "u")
831
+ return { storyblokApi: new we(e) };
832
+ }, Le = (i) => {
833
+ if (typeof i != "object" || typeof i._editable > "u")
832
834
  return {};
833
835
  try {
834
- const t = JSON.parse(
835
- n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
836
+ const e = JSON.parse(
837
+ i._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
836
838
  );
837
- return t ? {
838
- "data-blok-c": JSON.stringify(t),
839
- "data-blok-uid": t.id + "-" + t.uid
839
+ return e ? {
840
+ "data-blok-c": JSON.stringify(e),
841
+ "data-blok-uid": e.id + "-" + e.uid
840
842
  } : {};
841
843
  } catch {
842
844
  return {};
843
845
  }
844
846
  };
845
- let R, $ = "https://app.storyblok.com/f/storyblok-v2-latest.js";
846
- const dt = (n, t, e = {}) => {
847
+ var b = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i))(b || {}), v = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(v || {}), z = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(z || {}), _ = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(_ || {});
848
+ function Se(i, e) {
849
+ if (!e) return { src: i, attrs: {} };
850
+ let t = 0, s = 0;
851
+ const r = {}, n = [];
852
+ function o(a, l, u, p, m) {
853
+ typeof a != "number" || a <= l || a >= u ? console.warn(`[SbRichText] - ${p.charAt(0).toUpperCase() + p.slice(1)} value must be a number between ${l} and ${u} (inclusive)`) : m.push(`${p}(${a})`);
854
+ }
855
+ if (typeof e == "object") {
856
+ if (typeof e.width == "number" && e.width > 0 ? (r.width = e.width, t = e.width) : console.warn("[SbRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (r.height = e.height, s = e.height) : console.warn("[SbRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (r.loading = e.loading), e.class && (r.class = e.class), e.filters) {
857
+ const { filters: a } = e || {}, { blur: l, brightness: u, fill: p, format: m, grayscale: k, quality: y, rotate: w } = a || {};
858
+ l && o(l, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), u && o(u, 0, 100, "brightness", n), p && n.push(`fill(${p})`), k && n.push("grayscale()"), w && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${w})`), m && ["webp", "png", "jpeg"].includes(m) && n.push(`format(${m})`);
859
+ }
860
+ e.srcset && (r.srcset = e.srcset.map((a) => {
861
+ if (typeof a == "number")
862
+ return `${i}/m/${a}x0/${n.length > 0 ? "filters:" + n.join(":") : ""} ${a}w`;
863
+ if (Array.isArray(a) && a.length === 2) {
864
+ const [l, u] = a;
865
+ return `${i}/m/${l}x${u}/${n.length > 0 ? "filters:" + n.join(":") : ""} ${l}w`;
866
+ }
867
+ }).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
868
+ }
869
+ let c = `${i}/m/`;
870
+ return t > 0 && s > 0 && (c = `${c}${t}x${s}/`), n.length > 0 && (c = `${c}filters:${n.join(":")}`), {
871
+ src: c,
872
+ attrs: r
873
+ };
874
+ }
875
+ const _e = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Ee = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
876
+ function Ie(i) {
877
+ return i.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
878
+ }
879
+ function Oe(i, e = {}, t) {
880
+ const s = _e(e);
881
+ return `<${s ? `${i} ${s}` : i}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
882
+ }
883
+ function Ae(i = {}) {
884
+ let e = 0;
885
+ const {
886
+ renderFn: t = Oe,
887
+ textFn: s = Ie,
888
+ resolvers: r = {},
889
+ optimizeImages: n = !1
890
+ } = i, o = (h) => (g) => t(h, { ...g.attrs, key: `${h}-${e}` }, g.children || null), c = (h) => {
891
+ const { src: g, alt: f, ...$ } = h.attrs || {};
892
+ let T = g, R = {};
893
+ if (n) {
894
+ const { src: F, attrs: G } = Se(g, n);
895
+ T = F, R = G;
896
+ }
897
+ const q = {
898
+ src: T,
899
+ alt: f || "",
900
+ key: `img-${e}`,
901
+ ...$,
902
+ ...R
903
+ };
904
+ return t("img", q, "");
905
+ }, a = (h) => {
906
+ const { level: g, ...f } = h.attrs || {};
907
+ return t(`h${g}`, { ...f, key: `h${g}-${e}` }, h.children);
908
+ }, l = (h) => {
909
+ var g, f, $, T;
910
+ return t("span", {
911
+ "data-type": "emoji",
912
+ "data-name": (g = h.attrs) == null ? void 0 : g.name,
913
+ emoji: (f = h.attrs) == null ? void 0 : f.emoji,
914
+ key: `emoji-${e}`
915
+ }, t("img", {
916
+ src: ($ = h.attrs) == null ? void 0 : $.fallbackImage,
917
+ alt: (T = h.attrs) == null ? void 0 : T.alt,
918
+ style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
919
+ draggable: "false",
920
+ loading: "lazy"
921
+ }, ""));
922
+ }, u = (h) => t("pre", { ...h.attrs, key: `code-${e}` }, t("code", { key: `code-${e}` }, h.children || "")), p = (h, g = !1) => ({ text: f, attrs: $ }) => t(h, g ? {
923
+ style: Ee($),
924
+ key: `${h}-${e}`
925
+ } : { ...$, key: `${h}-${e}` }, f), m = (h) => j(h), k = (h) => {
926
+ const { marks: g, ...f } = h;
927
+ return "text" in h ? g ? g.reduce(
928
+ ($, T) => m({ ...T, text: $ }),
929
+ // Fix: Ensure render function returns a string
930
+ m({ ...f, children: f.children })
931
+ // Fix: Cast children to string
932
+ ) : s(f.text) : "";
933
+ }, y = (h) => {
934
+ const { linktype: g, href: f, anchor: $, ...T } = h.attrs || {};
935
+ let R = "";
936
+ switch (g) {
937
+ case _.ASSET:
938
+ case _.URL:
939
+ R = f;
940
+ break;
941
+ case _.EMAIL:
942
+ R = `mailto:${f}`;
943
+ break;
944
+ case _.STORY:
945
+ R = f;
946
+ break;
947
+ }
948
+ return $ && (R = `${R}#${$}`), t("a", { ...T, href: R, key: `a-${e}` }, h.text);
949
+ }, w = (h) => {
950
+ var g, f;
951
+ return console.warn("[SbRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
952
+ blok: (g = h == null ? void 0 : h.attrs) == null ? void 0 : g.body[0],
953
+ id: (f = h.attrs) == null ? void 0 : f.id,
954
+ key: `component-${e}`,
955
+ style: "display: none"
956
+ }, "");
957
+ }, E = new Map([
958
+ [b.DOCUMENT, o("div")],
959
+ [b.HEADING, a],
960
+ [b.PARAGRAPH, o("p")],
961
+ [b.UL_LIST, o("ul")],
962
+ [b.OL_LIST, o("ol")],
963
+ [b.LIST_ITEM, o("li")],
964
+ [b.IMAGE, c],
965
+ [b.EMOJI, l],
966
+ [b.CODE_BLOCK, u],
967
+ [b.HR, o("hr")],
968
+ [b.BR, o("br")],
969
+ [b.QUOTE, o("blockquote")],
970
+ [b.COMPONENT, w],
971
+ [z.TEXT, k],
972
+ [v.LINK, y],
973
+ [v.ANCHOR, y],
974
+ [v.STYLED, p("span", !0)],
975
+ [v.BOLD, p("strong")],
976
+ [v.TEXT_STYLE, p("span", !0)],
977
+ [v.ITALIC, p("em")],
978
+ [v.UNDERLINE, p("u")],
979
+ [v.STRIKE, p("s")],
980
+ [v.CODE, p("code")],
981
+ [v.SUPERSCRIPT, p("sup")],
982
+ [v.SUBSCRIPT, p("sub")],
983
+ [v.HIGHLIGHT, p("mark")],
984
+ ...Object.entries(r).map(([h, g]) => [h, g])
985
+ ]);
986
+ function P(h) {
987
+ e += 1;
988
+ const g = E.get(h.type);
989
+ if (!g)
990
+ return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
991
+ if (h.type === "text")
992
+ return g(h);
993
+ const f = h.content ? h.content.map(j) : void 0;
994
+ return g({
995
+ ...h,
996
+ children: f
997
+ // Fix: Update the type of 'children' to Node[]
998
+ });
999
+ }
1000
+ function j(h) {
1001
+ return Array.isArray(h) ? h.map(P) : P(h);
1002
+ }
1003
+ return {
1004
+ render: j
1005
+ };
1006
+ }
1007
+ let A, C = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1008
+ const Ce = (i, e, t = {}) => {
847
1009
  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(
849
- "_storyblok"
850
- ) === n;
1010
+ const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((c = window.location) == null ? void 0 : c.href).searchParams.get("_storyblok") === i;
851
1011
  if (!(!r || !o)) {
852
- if (!n) {
1012
+ if (!i) {
853
1013
  console.warn("Story ID is not defined. Please provide a valid ID.");
854
1014
  return;
855
1015
  }
856
1016
  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();
1017
+ new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
1018
+ l.action === "input" && l.story.id === i ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === i && window.location.reload();
859
1019
  });
860
1020
  });
861
1021
  }
862
- }, gt = (n = {}) => {
863
- var p, g;
1022
+ }, Pe = (i = {}) => {
1023
+ var p, m;
864
1024
  const {
865
- bridge: t,
866
- accessToken: e,
1025
+ bridge: e,
1026
+ accessToken: t,
867
1027
  use: s = [],
868
1028
  apiOptions: r = {},
869
- richText: i = {},
1029
+ richText: n = {},
870
1030
  bridgeUrl: o
871
- } = n;
872
- r.accessToken = r.accessToken || e;
873
- const c = { bridge: t, apiOptions: r };
1031
+ } = i;
1032
+ r.accessToken = r.accessToken || t;
1033
+ const c = { bridge: e, apiOptions: r };
874
1034
  let a = {};
875
- s.forEach((f) => {
876
- a = { ...a, ...f(c) };
877
- }), 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) => {
1035
+ s.forEach(
1036
+ (k) => {
1037
+ a = { ...a, ...k(c) };
1038
+ }
1039
+ ), o && (C = o);
1040
+ const u = !(typeof window > "u") && ((m = (p = window.location) == null ? void 0 : p.search) == null ? void 0 : m.includes("_storyblok_tk"));
1041
+ return e !== !1 && u && D(C), A = new x(n.schema), n.resolver && B(A, n.resolver), a;
1042
+ }, B = (i, e) => {
1043
+ i.addNode("blok", (t) => {
882
1044
  let s = "";
883
- return e.attrs.body.forEach((r) => {
884
- s += t(r.component, r);
1045
+ return t.attrs.body.forEach((r) => {
1046
+ s += e(r.component, r);
885
1047
  }), {
886
1048
  html: s
887
1049
  };
888
1050
  });
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;
1051
+ }, xe = (i) => !i || !(i != null && i.content.some(
1052
+ (e) => e.content || e.type === "blok" || e.type === "horizontal_rule"
1053
+ )), Ne = (i, e, t) => {
1054
+ let s = t || A;
891
1055
  if (!s) {
892
1056
  console.error(
893
1057
  "Please initialize the Storyblok SDK before calling the renderRichText function"
894
1058
  );
895
1059
  return;
896
1060
  }
897
- return ht(n) ? "" : (t && (s = new v(t.schema), t.resolver && E(s, t.resolver)), s.render(n));
898
- }, mt = () => O($);
1061
+ return xe(i) ? "" : (e && (s = new x(e.schema), e.resolver && B(s, e.resolver)), s.render(i));
1062
+ }, Me = () => D(C);
899
1063
  export {
900
- 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
1064
+ b as BlockTypes,
1065
+ v as MarkTypes,
1066
+ x as RichTextResolver,
1067
+ $e as RichTextSchema,
1068
+ z as TextTypes,
1069
+ je as apiPlugin,
1070
+ xe as isRichTextEmpty,
1071
+ Me as loadStoryblokBridge,
1072
+ Ce as registerStoryblokBridge,
1073
+ Ne as renderRichText,
1074
+ Ae as richTextResolver,
1075
+ Le as storyblokEditable,
1076
+ Pe as storyblokInit,
1077
+ Ce as useStoryblokBridge
910
1078
  };