@storyblok/react 4.2.1 → 4.3.1

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,45 +1,45 @@
1
- let _ = !1;
2
- const j = [], E = (o) => new Promise((e, t) => {
3
- if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
1
+ let H = !1;
2
+ const U = [], q = (r) => new Promise((e, t) => {
3
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
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() : j.push(r);
8
+ H ? o() : U.push(o);
9
9
  }, document.getElementById("storyblok-javascript-bridge"))) return;
10
10
  const s = document.createElement("script");
11
- s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
12
- j.forEach((i) => i()), _ = !0, e(r);
11
+ s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (o) => t(o), s.onload = (o) => {
12
+ U.forEach((n) => n()), H = !0, e(o);
13
13
  }, document.getElementsByTagName("head")[0].appendChild(s);
14
14
  });
15
- var O = Object.defineProperty, I = (o, e, t) => e in o ? O(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, c = (o, e, t) => I(o, typeof e != "symbol" ? e + "" : e, t);
16
- class C extends Error {
15
+ var X = Object.defineProperty, W = (r, e, t) => e in r ? X(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => W(r, typeof e != "symbol" ? e + "" : e, t);
16
+ class Q extends Error {
17
17
  constructor(e) {
18
18
  super(e), this.name = "AbortError";
19
19
  }
20
20
  }
21
- function N(o, e, t) {
21
+ function Z(r, e, t) {
22
22
  if (!Number.isFinite(e))
23
23
  throw new TypeError("Expected `limit` to be a finite number");
24
24
  if (!Number.isFinite(t))
25
25
  throw new TypeError("Expected `interval` to be a finite number");
26
26
  const s = [];
27
- let r = [], i = 0, n = !1;
28
- const a = async () => {
29
- i++;
27
+ let o = [], n = 0, i = !1;
28
+ const l = async () => {
29
+ n++;
30
30
  const h = s.shift();
31
31
  if (h)
32
32
  try {
33
- const d = await o(...h.args);
33
+ const d = await r(...h.args);
34
34
  h.resolve(d);
35
35
  } catch (d) {
36
36
  h.reject(d);
37
37
  }
38
38
  const u = setTimeout(() => {
39
- i--, s.length > 0 && a(), r = r.filter((d) => d !== u);
39
+ n--, s.length > 0 && l(), o = o.filter((d) => d !== u);
40
40
  }, t);
41
- r.includes(u) || r.push(u);
42
- }, l = (...h) => n ? Promise.reject(
41
+ o.includes(u) || o.push(u);
42
+ }, a = (...h) => i ? Promise.reject(
43
43
  new Error(
44
44
  "Throttled function is already aborted and not accepting new promises"
45
45
  )
@@ -48,24 +48,24 @@ function N(o, e, t) {
48
48
  resolve: u,
49
49
  reject: d,
50
50
  args: h
51
- }), i < e && a();
51
+ }), n < e && l();
52
52
  });
53
- return l.abort = () => {
54
- n = !0, r.forEach(clearTimeout), r = [], s.forEach(
55
- (h) => h.reject(() => new C("Throttle function aborted"))
53
+ return a.abort = () => {
54
+ i = !0, o.forEach(clearTimeout), o = [], s.forEach(
55
+ (h) => h.reject(() => new Q("Throttle function aborted"))
56
56
  ), s.length = 0;
57
- }, l;
57
+ }, a;
58
58
  }
59
- let y = class {
59
+ let O = class {
60
60
  constructor() {
61
- c(this, "isCDNUrl", (o = "") => o.includes("/cdn/")), c(this, "getOptionsPage", (o, e = 25, t = 1) => ({
62
- ...o,
61
+ p(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), p(this, "getOptionsPage", (r, e = 25, t = 1) => ({
62
+ ...r,
63
63
  per_page: e,
64
64
  page: t
65
- })), c(this, "delay", (o) => new Promise((e) => setTimeout(e, o))), c(this, "arrayFrom", (o = 0, e) => Array.from({ length: o }, e)), c(this, "range", (o = 0, e = o) => {
66
- const t = Math.abs(e - o) || 0, s = o < e ? 1 : -1;
67
- return this.arrayFrom(t, (r, i) => i * s + o);
68
- }), c(this, "asyncMap", async (o, e) => Promise.all(o.map(e))), c(this, "flatMap", (o = [], e) => o.map(e).reduce((t, s) => [...t, ...s], [])), c(this, "escapeHTML", function(o) {
65
+ })), p(this, "delay", (r) => new Promise((e) => setTimeout(e, r))), p(this, "arrayFrom", (r = 0, e) => Array.from({ length: r }, e)), p(this, "range", (r = 0, e = r) => {
66
+ const t = Math.abs(e - r) || 0, s = r < e ? 1 : -1;
67
+ return this.arrayFrom(t, (o, n) => n * s + r);
68
+ }), p(this, "asyncMap", async (r, e) => Promise.all(r.map(e))), p(this, "flatMap", (r = [], e) => r.map(e).reduce((t, s) => [...t, ...s], [])), p(this, "escapeHTML", function(r) {
69
69
  const e = {
70
70
  "&": "&amp;",
71
71
  "<": "&lt;",
@@ -73,7 +73,7 @@ let y = class {
73
73
  '"': "&quot;",
74
74
  "'": "&#39;"
75
75
  }, t = /[&<>"']/g, s = new RegExp(t.source);
76
- return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
76
+ return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
77
77
  });
78
78
  }
79
79
  /**
@@ -83,18 +83,18 @@ let y = class {
83
83
  * @param {boolean} isArray
84
84
  * @return {string} Stringified object
85
85
  */
86
- stringify(o, e, t) {
86
+ stringify(r, e, t) {
87
87
  const s = [];
88
- for (const r in o) {
89
- if (!Object.prototype.hasOwnProperty.call(o, r))
88
+ for (const o in r) {
89
+ if (!Object.prototype.hasOwnProperty.call(r, o))
90
90
  continue;
91
- const i = o[r], n = t ? "" : encodeURIComponent(r);
92
- let a;
93
- typeof i == "object" ? a = this.stringify(
94
- i,
95
- e ? e + encodeURIComponent(`[${n}]`) : n,
96
- Array.isArray(i)
97
- ) : a = `${e ? e + encodeURIComponent(`[${n}]`) : n}=${encodeURIComponent(i)}`, s.push(a);
91
+ const n = r[o], i = t ? "" : encodeURIComponent(o);
92
+ let l;
93
+ typeof n == "object" ? l = this.stringify(
94
+ n,
95
+ e ? e + encodeURIComponent(`[${i}]`) : i,
96
+ Array.isArray(n)
97
+ ) : l = `${e ? e + encodeURIComponent(`[${i}]`) : i}=${encodeURIComponent(n)}`, s.push(l);
98
98
  }
99
99
  return s.join("&");
100
100
  }
@@ -103,92 +103,92 @@ let y = class {
103
103
  * @param {string} regionCode region code, could be eu, us, cn, ap or ca
104
104
  * @return {string} The base URL of the region
105
105
  */
106
- getRegionURL(o) {
107
- const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", r = "api-ap.storyblok.com", i = "api-ca.storyblok.com";
108
- switch (o) {
106
+ getRegionURL(r) {
107
+ const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", o = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
108
+ switch (r) {
109
109
  case "us":
110
110
  return t;
111
111
  case "cn":
112
112
  return s;
113
113
  case "ap":
114
- return r;
114
+ return o;
115
115
  case "ca":
116
- return i;
116
+ return n;
117
117
  default:
118
118
  return e;
119
119
  }
120
120
  }
121
121
  };
122
- const A = function(o, e) {
122
+ const ee = function(r, e) {
123
123
  const t = {};
124
- for (const s in o) {
125
- const r = o[s];
126
- e.includes(s) && r !== null && (t[s] = r);
124
+ for (const s in r) {
125
+ const o = r[s];
126
+ e.includes(s) && o !== null && (t[s] = o);
127
127
  }
128
128
  return t;
129
- }, L = (o) => o === "email", M = () => ({
129
+ }, te = (r) => r === "email", re = () => ({
130
130
  singleTag: "hr"
131
- }), z = () => ({
131
+ }), se = () => ({
132
132
  tag: "blockquote"
133
- }), H = () => ({
133
+ }), oe = () => ({
134
134
  tag: "ul"
135
- }), U = (o) => ({
135
+ }), ne = (r) => ({
136
136
  tag: [
137
137
  "pre",
138
138
  {
139
139
  tag: "code",
140
- attrs: o.attrs
140
+ attrs: r.attrs
141
141
  }
142
142
  ]
143
- }), q = () => ({
143
+ }), ie = () => ({
144
144
  singleTag: "br"
145
- }), B = (o) => ({
146
- tag: `h${o.attrs.level}`
147
- }), V = (o) => ({
145
+ }), ae = (r) => ({
146
+ tag: `h${r.attrs.level}`
147
+ }), le = (r) => ({
148
148
  singleTag: [
149
149
  {
150
150
  tag: "img",
151
- attrs: A(o.attrs, ["src", "alt", "title"])
151
+ attrs: ee(r.attrs, ["src", "alt", "title"])
152
152
  }
153
153
  ]
154
- }), D = () => ({
154
+ }), ce = () => ({
155
155
  tag: "li"
156
- }), F = () => ({
156
+ }), he = () => ({
157
157
  tag: "ol"
158
- }), J = () => ({
158
+ }), ue = () => ({
159
159
  tag: "p"
160
- }), W = (o) => ({
160
+ }), de = (r) => ({
161
161
  tag: [
162
162
  {
163
163
  tag: "span",
164
164
  attrs: {
165
165
  "data-type": "emoji",
166
- "data-name": o.attrs.name,
167
- emoji: o.attrs.emoji
166
+ "data-name": r.attrs.name,
167
+ emoji: r.attrs.emoji
168
168
  }
169
169
  }
170
170
  ]
171
- }), Y = () => ({
171
+ }), pe = () => ({
172
172
  tag: "b"
173
- }), G = () => ({
173
+ }), ge = () => ({
174
174
  tag: "s"
175
- }), K = () => ({
175
+ }), me = () => ({
176
176
  tag: "u"
177
- }), Q = () => ({
177
+ }), fe = () => ({
178
178
  tag: "strong"
179
- }), X = () => ({
179
+ }), ye = () => ({
180
180
  tag: "code"
181
- }), Z = () => ({
181
+ }), be = () => ({
182
182
  tag: "i"
183
- }), ee = (o) => {
184
- if (!o.attrs)
183
+ }), ke = (r) => {
184
+ if (!r.attrs)
185
185
  return {
186
186
  tag: ""
187
187
  };
188
- const e = new y().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
189
- if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), L(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
190
- for (const r in t.custom)
191
- t[r] = t.custom[r];
188
+ const e = new O().escapeHTML, t = { ...r.attrs }, { linktype: s = "url" } = r.attrs;
189
+ if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), te(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
190
+ for (const o in t.custom)
191
+ t[o] = t.custom[o];
192
192
  delete t.custom;
193
193
  }
194
194
  return {
@@ -199,82 +199,82 @@ const A = function(o, e) {
199
199
  }
200
200
  ]
201
201
  };
202
- }, te = (o) => ({
202
+ }, ve = (r) => ({
203
203
  tag: [
204
204
  {
205
205
  tag: "span",
206
- attrs: o.attrs
206
+ attrs: r.attrs
207
207
  }
208
208
  ]
209
- }), se = () => ({
209
+ }), $e = () => ({
210
210
  tag: "sub"
211
- }), re = () => ({
211
+ }), Te = () => ({
212
212
  tag: "sup"
213
- }), oe = (o) => ({
213
+ }), we = (r) => ({
214
214
  tag: [
215
215
  {
216
216
  tag: "span",
217
- attrs: o.attrs
217
+ attrs: r.attrs
218
218
  }
219
219
  ]
220
- }), ie = (o) => {
220
+ }), Re = (r) => {
221
221
  var e;
222
- return (e = o.attrs) != null && e.color ? {
222
+ return (e = r.attrs) != null && e.color ? {
223
223
  tag: [
224
224
  {
225
225
  tag: "span",
226
226
  attrs: {
227
- style: `background-color:${o.attrs.color};`
227
+ style: `background-color:${r.attrs.color};`
228
228
  }
229
229
  }
230
230
  ]
231
231
  } : {
232
232
  tag: ""
233
233
  };
234
- }, ne = (o) => {
234
+ }, Se = (r) => {
235
235
  var e;
236
- return (e = o.attrs) != null && e.color ? {
236
+ return (e = r.attrs) != null && e.color ? {
237
237
  tag: [
238
238
  {
239
239
  tag: "span",
240
240
  attrs: {
241
- style: `color:${o.attrs.color}`
241
+ style: `color:${r.attrs.color}`
242
242
  }
243
243
  }
244
244
  ]
245
245
  } : {
246
246
  tag: ""
247
247
  };
248
- }, ae = {
248
+ }, _e = {
249
249
  nodes: {
250
- horizontal_rule: M,
251
- blockquote: z,
252
- bullet_list: H,
253
- code_block: U,
254
- hard_break: q,
255
- heading: B,
256
- image: V,
257
- list_item: D,
258
- ordered_list: F,
259
- paragraph: J,
260
- emoji: W
250
+ horizontal_rule: re,
251
+ blockquote: se,
252
+ bullet_list: oe,
253
+ code_block: ne,
254
+ hard_break: ie,
255
+ heading: ae,
256
+ image: le,
257
+ list_item: ce,
258
+ ordered_list: he,
259
+ paragraph: ue,
260
+ emoji: de
261
261
  },
262
262
  marks: {
263
- bold: Y,
264
- strike: G,
265
- underline: K,
266
- strong: Q,
267
- code: X,
268
- italic: Z,
269
- link: ee,
270
- styled: te,
271
- subscript: se,
272
- superscript: re,
273
- anchor: oe,
274
- highlight: ie,
275
- textStyle: ne
276
- }
277
- }, le = function(o) {
263
+ bold: pe,
264
+ strike: ge,
265
+ underline: me,
266
+ strong: fe,
267
+ code: ye,
268
+ italic: be,
269
+ link: ke,
270
+ styled: ve,
271
+ subscript: $e,
272
+ superscript: Te,
273
+ anchor: we,
274
+ highlight: Re,
275
+ textStyle: Se
276
+ }
277
+ }, Ee = function(r) {
278
278
  const e = {
279
279
  "&": "&amp;",
280
280
  "<": "&lt;",
@@ -282,12 +282,12 @@ const A = function(o, e) {
282
282
  '"': "&quot;",
283
283
  "'": "&#39;"
284
284
  }, t = /[&<>"']/g, s = new RegExp(t.source);
285
- return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
285
+ return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
286
286
  };
287
- let x = !1;
288
- class ce {
287
+ let z = !1;
288
+ class je {
289
289
  constructor(e) {
290
- c(this, "marks"), c(this, "nodes"), e || (e = ae), this.marks = e.marks || [], this.nodes = e.nodes || [];
290
+ p(this, "marks"), p(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
291
291
  }
292
292
  addNode(e, t) {
293
293
  this.nodes[e] = t;
@@ -296,13 +296,13 @@ class ce {
296
296
  this.marks[e] = t;
297
297
  }
298
298
  render(e, t = { optimizeImages: !1 }, s = !0) {
299
- if (!x && s && (console.warn(
299
+ if (!z && s && (console.warn(
300
300
  "Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
301
- ), x = !0), e && e.content && Array.isArray(e.content)) {
302
- let r = "";
303
- return e.content.forEach((i) => {
304
- r += this.renderNode(i);
305
- }), t.optimizeImages ? this.optimizeImages(r, t.optimizeImages) : r;
301
+ ), z = !0), e && e.content && Array.isArray(e.content)) {
302
+ let o = "";
303
+ return e.content.forEach((n) => {
304
+ o += this.renderNode(n);
305
+ }), t.optimizeImages ? this.optimizeImages(o, t.optimizeImages) : o;
306
306
  }
307
307
  return console.warn(
308
308
  `The render method must receive an Object with a "content" field.
@@ -332,48 +332,48 @@ class ce {
332
332
  ), "";
333
333
  }
334
334
  optimizeImages(e, t) {
335
- let s = 0, r = 0, i = "", n = "";
336
- 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-F]{6}/gi) || 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()}`));
337
- const a = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
335
+ let s = 0, o = 0, n = "", i = "";
336
+ 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}" `, o = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = `/filters${i}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
337
+ const l = s > 0 || o > 0 || i.length > 0 ? `${s}x${o}${i}` : "";
338
338
  return e = e.replace(
339
339
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
340
- `a.storyblok.com/f/$1/$2.$3/m/${a}`
341
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
340
+ `a.storyblok.com/f/$1/$2.$3/m/${l}`
341
+ ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
342
342
  var h, u;
343
- const d = l.match(
343
+ const d = a.match(
344
344
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
345
345
  );
346
346
  if (d && d.length > 0) {
347
- const p = {
348
- srcset: (h = t.srcset) == null ? void 0 : h.map((g) => {
349
- if (typeof g == "number")
350
- return `//${d}/m/${g}x0${n} ${g}w`;
351
- if (typeof g == "object" && g.length === 2) {
352
- let k = 0, T = 0;
353
- return typeof g[0] == "number" && (k = g[0]), typeof g[1] == "number" && (T = g[1]), `//${d}/m/${k}x${T}${n} ${k}w`;
347
+ const g = {
348
+ srcset: (h = t.srcset) == null ? void 0 : h.map((y) => {
349
+ if (typeof y == "number")
350
+ return `//${d}/m/${y}x0${i} ${y}w`;
351
+ if (typeof y == "object" && y.length === 2) {
352
+ let w = 0, I = 0;
353
+ return typeof y[0] == "number" && (w = y[0]), typeof y[1] == "number" && (I = y[1]), `//${d}/m/${w}x${I}${i} ${w}w`;
354
354
  }
355
355
  return "";
356
356
  }).join(", "),
357
- sizes: (u = t.sizes) == null ? void 0 : u.map((g) => g).join(", ")
357
+ sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
358
358
  };
359
- let v = "";
360
- return p.srcset && (v += `srcset="${p.srcset}" `), p.sizes && (v += `sizes="${p.sizes}" `), l.replace(/<img/g, `<img ${v.trim()}`);
359
+ let R = "";
360
+ return g.srcset && (R += `srcset="${g.srcset}" `), g.sizes && (R += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${R.trim()}`);
361
361
  }
362
- return l;
362
+ return a;
363
363
  })), e;
364
364
  }
365
365
  renderNode(e) {
366
366
  const t = [];
367
- e.marks && e.marks.forEach((r) => {
368
- const i = this.getMatchingMark(r);
369
- i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
367
+ e.marks && e.marks.forEach((o) => {
368
+ const n = this.getMatchingMark(o);
369
+ n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
370
370
  });
371
371
  const s = this.getMatchingNode(e);
372
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
373
- t.push(this.renderNode(r));
374
- }) : e.text ? t.push(le(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) => {
375
- const i = this.getMatchingMark(r);
376
- i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
372
+ return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((o) => {
373
+ t.push(this.renderNode(o));
374
+ }) : e.text ? t.push(Ee(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((o) => {
375
+ const n = this.getMatchingMark(o);
376
+ n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
377
377
  }), t.join("");
378
378
  }
379
379
  renderTag(e, t) {
@@ -381,15 +381,15 @@ class ce {
381
381
  if (s.constructor === String)
382
382
  return `<${s}${t}>`;
383
383
  {
384
- let r = `<${s.tag}`;
384
+ let o = `<${s.tag}`;
385
385
  if (s.attrs) {
386
- for (const i in s.attrs)
387
- if (Object.prototype.hasOwnProperty.call(s.attrs, i)) {
388
- const n = s.attrs[i];
389
- n !== null && (r += ` ${i}="${n}"`);
386
+ for (const n in s.attrs)
387
+ if (Object.prototype.hasOwnProperty.call(s.attrs, n)) {
388
+ const i = s.attrs[n];
389
+ i !== null && (o += ` ${n}="${i}"`);
390
390
  }
391
391
  }
392
- return `${r}${t}>`;
392
+ return `${o}${t}>`;
393
393
  }
394
394
  }).join("");
395
395
  }
@@ -426,10 +426,10 @@ class ce {
426
426
  return this.renderTag(t, " /");
427
427
  }
428
428
  }
429
- const b = ce;
430
- class he {
429
+ const A = je;
430
+ class Ie {
431
431
  constructor(e) {
432
- c(this, "baseURL"), c(this, "timeout"), c(this, "headers"), c(this, "responseInterceptor"), c(this, "fetch"), c(this, "ejectInterceptor"), c(this, "url"), c(this, "parameters"), c(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 = {};
432
+ p(this, "baseURL"), p(this, "timeout"), p(this, "headers"), p(this, "responseInterceptor"), p(this, "fetch"), p(this, "ejectInterceptor"), p(this, "url"), p(this, "parameters"), p(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 = {};
433
433
  }
434
434
  /**
435
435
  *
@@ -456,41 +456,41 @@ class he {
456
456
  status: 0,
457
457
  statusText: ""
458
458
  };
459
- e.status !== 204 && await e.json().then((r) => {
460
- s.data = r;
459
+ e.status !== 204 && await e.json().then((o) => {
460
+ s.data = o;
461
461
  });
462
- for (const r of e.headers.entries())
463
- t[r[0]] = r[1];
462
+ for (const o of e.headers.entries())
463
+ t[o[0]] = o[1];
464
464
  return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
465
465
  }
466
466
  async _methodHandler(e) {
467
467
  let t = `${this.baseURL}${this.url}`, s = null;
468
468
  if (e === "get") {
469
- const l = new y();
470
- t = `${this.baseURL}${this.url}?${l.stringify(
469
+ const a = new O();
470
+ t = `${this.baseURL}${this.url}?${a.stringify(
471
471
  this.parameters
472
472
  )}`;
473
473
  } else
474
474
  s = JSON.stringify(this.parameters);
475
- const r = new URL(t), i = new AbortController(), { signal: n } = i;
476
- let a;
477
- this.timeout && (a = setTimeout(() => i.abort(), this.timeout));
475
+ const o = new URL(t), n = new AbortController(), { signal: i } = n;
476
+ let l;
477
+ this.timeout && (l = setTimeout(() => n.abort(), this.timeout));
478
478
  try {
479
- const l = await this.fetch(`${r}`, {
479
+ const a = await this.fetch(`${o}`, {
480
480
  method: e,
481
481
  headers: this.headers,
482
482
  body: s,
483
- signal: n,
483
+ signal: i,
484
484
  ...this.fetchOptions
485
485
  });
486
- this.timeout && clearTimeout(a);
486
+ this.timeout && clearTimeout(l);
487
487
  const h = await this._responseHandler(
488
- l
488
+ a
489
489
  );
490
490
  return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
491
- } catch (l) {
491
+ } catch (a) {
492
492
  return {
493
- message: l
493
+ message: a
494
494
  };
495
495
  }
496
496
  }
@@ -502,54 +502,54 @@ class he {
502
502
  }
503
503
  _statusHandler(e) {
504
504
  const t = /20[0-6]/g;
505
- return new Promise((s, r) => {
505
+ return new Promise((s, o) => {
506
506
  if (t.test(`${e.status}`))
507
507
  return s(e);
508
- const i = {
508
+ const n = {
509
509
  message: e.statusText,
510
510
  status: e.status,
511
511
  response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
512
512
  };
513
- r(i);
513
+ o(n);
514
514
  });
515
515
  }
516
516
  }
517
- const ue = he, S = "SB-Agent", w = {
517
+ const xe = Ie, D = "SB-Agent", L = {
518
518
  defaultAgentName: "SB-JS-CLIENT",
519
519
  defaultAgentVersion: "SB-Agent-Version",
520
520
  packageVersion: "6.0.0"
521
521
  };
522
- let m = {};
523
- const f = {};
524
- class de {
522
+ let x = {};
523
+ const E = {};
524
+ class Oe {
525
525
  /**
526
526
  *
527
527
  * @param config ISbConfig interface
528
528
  * @param pEndpoint string, optional
529
529
  */
530
530
  constructor(e, t) {
531
- c(this, "client"), c(this, "maxRetries"), c(this, "retriesDelay"), c(this, "throttle"), c(this, "accessToken"), c(this, "cache"), c(this, "helpers"), c(this, "resolveCounter"), c(this, "relations"), c(this, "links"), c(this, "richTextResolver"), c(this, "resolveNestedRelations"), c(this, "stringifiedStoriesCache");
531
+ p(this, "client"), p(this, "maxRetries"), p(this, "retriesDelay"), p(this, "throttle"), p(this, "accessToken"), p(this, "cache"), p(this, "helpers"), p(this, "resolveCounter"), p(this, "relations"), p(this, "links"), p(this, "richTextResolver"), p(this, "resolveNestedRelations"), p(this, "stringifiedStoriesCache");
532
532
  let s = e.endpoint || t;
533
533
  if (!s) {
534
- const n = new y().getRegionURL, a = e.https === !1 ? "http" : "https";
535
- e.oauthToken ? s = `${a}://${n(e.region)}/v1` : s = `${a}://${n(e.region)}/v2`;
534
+ const i = new O().getRegionURL, l = e.https === !1 ? "http" : "https";
535
+ e.oauthToken ? s = `${l}://${i(e.region)}/v1` : s = `${l}://${i(e.region)}/v2`;
536
536
  }
537
- const r = new Headers();
538
- r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([n, a]) => {
539
- r.set(n, a);
540
- }), r.has(S) || (r.set(S, w.defaultAgentName), r.set(
541
- w.defaultAgentVersion,
542
- w.packageVersion
537
+ const o = new Headers();
538
+ o.set("Content-Type", "application/json"), o.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([i, l]) => {
539
+ o.set(i, l);
540
+ }), o.has(D) || (o.set(D, L.defaultAgentName), o.set(
541
+ L.defaultAgentVersion,
542
+ L.packageVersion
543
543
  ));
544
- let i = 5;
545
- e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new b(e.richTextSchema) : this.richTextResolver = new b(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = N(
544
+ let n = 5;
545
+ e.oauthToken && (o.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new A(e.richTextSchema) : this.richTextResolver = new A(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = Z(
546
546
  this.throttledRequest.bind(this),
547
- i,
547
+ n,
548
548
  1e3
549
- ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new y(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new ue({
549
+ ), 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 xe({
550
550
  baseURL: s,
551
551
  timeout: e.timeout || 0,
552
- headers: r,
552
+ headers: o,
553
553
  responseInterceptor: e.responseInterceptor,
554
554
  fetch: e.fetch
555
555
  });
@@ -557,60 +557,60 @@ class de {
557
557
  setComponentResolver(e) {
558
558
  this.richTextResolver.addNode("blok", (t) => {
559
559
  let s = "";
560
- return t.attrs.body && t.attrs.body.forEach((r) => {
561
- s += e(r.component, r);
560
+ return t.attrs.body && t.attrs.body.forEach((o) => {
561
+ s += e(o.component, o);
562
562
  }), {
563
563
  html: s
564
564
  };
565
565
  });
566
566
  }
567
567
  parseParams(e) {
568
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = f[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
568
+ return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
569
569
  }
570
570
  factoryParamOptions(e, t) {
571
571
  return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
572
572
  }
573
- makeRequest(e, t, s, r, i) {
574
- const n = this.factoryParamOptions(
573
+ makeRequest(e, t, s, o, n) {
574
+ const i = this.factoryParamOptions(
575
575
  e,
576
- this.helpers.getOptionsPage(t, s, r)
576
+ this.helpers.getOptionsPage(t, s, o)
577
577
  );
578
- return this.cacheResponse(e, n, void 0, i);
578
+ return this.cacheResponse(e, i, void 0, n);
579
579
  }
580
580
  get(e, t, s) {
581
581
  t || (t = {});
582
- const r = `/${e}`, i = this.factoryParamOptions(r, t);
583
- return this.cacheResponse(r, i, void 0, s);
582
+ const o = `/${e}`, n = this.factoryParamOptions(o, t);
583
+ return this.cacheResponse(o, n, void 0, s);
584
584
  }
585
- async getAll(e, t, s, r) {
586
- const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), a = s ?? n.substring(n.lastIndexOf("/") + 1), l = 1, h = await this.makeRequest(
587
- n,
588
- t,
585
+ async getAll(e, t, s, o) {
586
+ const n = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`.replace(/\/$/, ""), l = s ?? i.substring(i.lastIndexOf("/") + 1), a = 1, h = await this.makeRequest(
589
587
  i,
590
- l,
591
- r
592
- ), u = h.total ? Math.ceil(h.total / i) : 1, d = await this.helpers.asyncMap(
593
- this.helpers.range(l, u),
594
- (p) => this.makeRequest(n, t, i, p + 1, r)
588
+ t,
589
+ n,
590
+ a,
591
+ o
592
+ ), u = h.total ? Math.ceil(h.total / n) : 1, d = await this.helpers.asyncMap(
593
+ this.helpers.range(a, u),
594
+ (g) => this.makeRequest(i, t, n, g + 1, o)
595
595
  );
596
- return this.helpers.flatMap([h, ...d], (p) => Object.values(p.data[a]));
596
+ return this.helpers.flatMap([h, ...d], (g) => Object.values(g.data[l]));
597
597
  }
598
598
  post(e, t, s) {
599
- const r = `/${e}`;
599
+ const o = `/${e}`;
600
600
  return Promise.resolve(
601
- this.throttle("post", r, t, s)
601
+ this.throttle("post", o, t, s)
602
602
  );
603
603
  }
604
604
  put(e, t, s) {
605
- const r = `/${e}`;
605
+ const o = `/${e}`;
606
606
  return Promise.resolve(
607
- this.throttle("put", r, t, s)
607
+ this.throttle("put", o, t, s)
608
608
  );
609
609
  }
610
610
  delete(e, t, s) {
611
- const r = `/${e}`;
611
+ const o = `/${e}`;
612
612
  return Promise.resolve(
613
- this.throttle("delete", r, t, s)
613
+ this.throttle("delete", o, t, s)
614
614
  );
615
615
  }
616
616
  getStories(e, t) {
@@ -632,8 +632,8 @@ class de {
632
632
  return JSON.parse(JSON.stringify(e));
633
633
  }
634
634
  _insertLinks(e, t, s) {
635
- const r = e[t];
636
- 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]));
635
+ const o = e[t];
636
+ o && o.fieldtype === "multilink" && o.linktype === "story" && typeof o.id == "string" && this.links[s][o.id] ? o.story = this._cleanCopy(this.links[s][o.id]) : o && o.linktype === "story" && typeof o.uuid == "string" && this.links[s][o.uuid] && (o.story = this._cleanCopy(this.links[s][o.uuid]));
637
637
  }
638
638
  /**
639
639
  *
@@ -646,85 +646,85 @@ class de {
646
646
  this.relations[e][t]
647
647
  )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
648
648
  }
649
- _insertRelations(e, t, s, r) {
650
- s.includes(`${e.component}.${t}`) && (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)));
649
+ _insertRelations(e, t, s, o) {
650
+ s.includes(`${e.component}.${t}`) && (typeof e[t] == "string" ? e[t] = this.getStoryReference(o, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((n) => this.getStoryReference(o, n)).filter(Boolean)));
651
651
  }
652
652
  iterateTree(e, t, s) {
653
- const r = (i) => {
654
- if (i != null) {
655
- if (i.constructor === Array)
656
- for (let n = 0; n < i.length; n++)
657
- r(i[n]);
658
- else if (i.constructor === Object) {
659
- if (i._stopResolving)
653
+ const o = (n) => {
654
+ if (n != null) {
655
+ if (n.constructor === Array)
656
+ for (let i = 0; i < n.length; i++)
657
+ o(n[i]);
658
+ else if (n.constructor === Object) {
659
+ if (n._stopResolving)
660
660
  return;
661
- for (const n in i)
662
- (i.component && i._uid || i.type === "link") && (this._insertRelations(
663
- i,
661
+ for (const i in n)
662
+ (n.component && n._uid || n.type === "link") && (this._insertRelations(
664
663
  n,
664
+ i,
665
665
  t,
666
666
  s
667
667
  ), this._insertLinks(
668
- i,
669
668
  n,
669
+ i,
670
670
  s
671
- )), r(i[n]);
671
+ )), o(n[i]);
672
672
  }
673
673
  }
674
674
  };
675
- r(e.content);
675
+ o(e.content);
676
676
  }
677
677
  async resolveLinks(e, t, s) {
678
- let r = [];
678
+ let o = [];
679
679
  if (e.link_uuids) {
680
- const i = e.link_uuids.length, n = [], a = 50;
681
- for (let l = 0; l < i; l += a) {
682
- const h = Math.min(i, l + a);
683
- n.push(e.link_uuids.slice(l, h));
680
+ const n = e.link_uuids.length, i = [], l = 50;
681
+ for (let a = 0; a < n; a += l) {
682
+ const h = Math.min(n, a + l);
683
+ i.push(e.link_uuids.slice(a, h));
684
684
  }
685
- for (let l = 0; l < n.length; l++)
685
+ for (let a = 0; a < i.length; a++)
686
686
  (await this.getStories({
687
- per_page: a,
687
+ per_page: l,
688
688
  language: t.language,
689
689
  version: t.version,
690
- by_uuids: n[l].join(",")
690
+ by_uuids: i[a].join(",")
691
691
  })).data.stories.forEach(
692
692
  (h) => {
693
- r.push(h);
693
+ o.push(h);
694
694
  }
695
695
  );
696
696
  } else
697
- r = e.links;
698
- r.forEach((i) => {
699
- this.links[s][i.uuid] = {
700
- ...i,
697
+ o = e.links;
698
+ o.forEach((n) => {
699
+ this.links[s][n.uuid] = {
700
+ ...n,
701
701
  _stopResolving: !0
702
702
  };
703
703
  });
704
704
  }
705
705
  async resolveRelations(e, t, s) {
706
- let r = [];
706
+ let o = [];
707
707
  if (e.rel_uuids) {
708
- const i = e.rel_uuids.length, n = [], a = 50;
709
- for (let l = 0; l < i; l += a) {
710
- const h = Math.min(i, l + a);
711
- n.push(e.rel_uuids.slice(l, h));
708
+ const n = e.rel_uuids.length, i = [], l = 50;
709
+ for (let a = 0; a < n; a += l) {
710
+ const h = Math.min(n, a + l);
711
+ i.push(e.rel_uuids.slice(a, h));
712
712
  }
713
- for (let l = 0; l < n.length; l++)
713
+ for (let a = 0; a < i.length; a++)
714
714
  (await this.getStories({
715
- per_page: a,
715
+ per_page: l,
716
716
  language: t.language,
717
717
  version: t.version,
718
- by_uuids: n[l].join(","),
718
+ by_uuids: i[a].join(","),
719
719
  excluding_fields: t.excluding_fields
720
720
  })).data.stories.forEach((h) => {
721
- r.push(h);
721
+ o.push(h);
722
722
  });
723
723
  } else
724
- r = e.rels;
725
- r && r.length > 0 && r.forEach((i) => {
726
- this.relations[s][i.uuid] = {
727
- ...i,
724
+ o = e.rels;
725
+ o && o.length > 0 && o.forEach((n) => {
726
+ this.relations[s][n.uuid] = {
727
+ ...n,
728
728
  _stopResolving: !0
729
729
  };
730
730
  });
@@ -739,85 +739,85 @@ class de {
739
739
  *
740
740
  */
741
741
  async resolveStories(e, t, s) {
742
- var r, i;
743
- let n = [];
744
- 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"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
745
- for (const a in this.relations[s])
742
+ var o, n;
743
+ let i = [];
744
+ if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (i = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((o = e.links) != null && o.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
745
+ for (const l in this.relations[s])
746
746
  this.iterateTree(
747
- this.relations[s][a],
748
- n,
747
+ this.relations[s][l],
748
+ i,
749
749
  s
750
750
  );
751
- e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((a) => {
752
- this.iterateTree(a, n, s);
751
+ e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((l) => {
752
+ this.iterateTree(l, i, s);
753
753
  }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
754
754
  }
755
- async cacheResponse(e, t, s, r) {
756
- const i = this.helpers.stringify({ url: e, params: t }), n = this.cacheProvider();
755
+ async cacheResponse(e, t, s, o) {
756
+ const n = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
757
757
  if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
758
- const a = await n.get(i);
759
- if (a)
760
- return Promise.resolve(a);
758
+ const l = await i.get(n);
759
+ if (l)
760
+ return Promise.resolve(l);
761
761
  }
762
- return new Promise(async (a, l) => {
762
+ return new Promise(async (l, a) => {
763
763
  var h;
764
764
  try {
765
765
  const u = await this.throttle(
766
766
  "get",
767
767
  e,
768
768
  t,
769
- r
769
+ o
770
770
  );
771
771
  if (u.status !== 200)
772
- return l(u);
772
+ return a(u);
773
773
  let d = { data: u.data, headers: u.headers };
774
774
  if ((h = u.headers) != null && h["per-page"] && (d = Object.assign({}, d, {
775
775
  perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
776
776
  total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
777
777
  })), d.data.story || d.data.stories) {
778
- const p = this.resolveCounter = ++this.resolveCounter % 1e3;
779
- await this.resolveStories(d.data, t, `${p}`);
778
+ const g = this.resolveCounter = ++this.resolveCounter % 1e3;
779
+ await this.resolveStories(d.data, t, `${g}`);
780
780
  }
781
- return t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, d), d.data.cv && t.token && f[t.token] !== d.data.cv && (await this.flushCache(), f[t.token] = d.data.cv), a(d);
781
+ return t.version === "published" && e !== "/cdn/spaces/me" && await i.set(n, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
782
782
  } catch (u) {
783
783
  if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
784
784
  return console.log(
785
785
  `Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
786
- ), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(a).catch(l);
787
- l(u);
786
+ ), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
787
+ a(u);
788
788
  }
789
789
  });
790
790
  }
791
- throttledRequest(e, t, s, r) {
792
- return this.client.setFetchOptions(r), this.client[e](t, s);
791
+ throttledRequest(e, t, s, o) {
792
+ return this.client.setFetchOptions(o), this.client[e](t, s);
793
793
  }
794
794
  cacheVersions() {
795
- return f;
795
+ return E;
796
796
  }
797
797
  cacheVersion() {
798
- return f[this.accessToken];
798
+ return E[this.accessToken];
799
799
  }
800
800
  setCacheVersion(e) {
801
- this.accessToken && (f[this.accessToken] = e);
801
+ this.accessToken && (E[this.accessToken] = e);
802
802
  }
803
803
  clearCacheVersion() {
804
- this.accessToken && (f[this.accessToken] = 0);
804
+ this.accessToken && (E[this.accessToken] = 0);
805
805
  }
806
806
  cacheProvider() {
807
807
  switch (this.cache.type) {
808
808
  case "memory":
809
809
  return {
810
810
  get(e) {
811
- return Promise.resolve(m[e]);
811
+ return Promise.resolve(x[e]);
812
812
  },
813
813
  getAll() {
814
- return Promise.resolve(m);
814
+ return Promise.resolve(x);
815
815
  },
816
816
  set(e, t) {
817
- return m[e] = t, Promise.resolve(void 0);
817
+ return x[e] = t, Promise.resolve(void 0);
818
818
  },
819
819
  flush() {
820
- return m = {}, Promise.resolve(void 0);
820
+ return x = {}, Promise.resolve(void 0);
821
821
  }
822
822
  };
823
823
  case "custom":
@@ -844,21 +844,21 @@ class de {
844
844
  return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
845
845
  }
846
846
  }
847
- const ge = (o = {}) => {
848
- const { apiOptions: e } = o;
847
+ const Ue = (r = {}) => {
848
+ const { apiOptions: e } = r;
849
849
  if (!e.accessToken) {
850
850
  console.error(
851
851
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
852
852
  );
853
853
  return;
854
854
  }
855
- return { storyblokApi: new de(e) };
856
- }, fe = (o) => {
857
- if (typeof o != "object" || typeof o._editable > "u")
855
+ return { storyblokApi: new Oe(e) };
856
+ }, ze = (r) => {
857
+ if (typeof r != "object" || typeof r._editable > "u")
858
858
  return {};
859
859
  try {
860
860
  const e = JSON.parse(
861
- o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
861
+ r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
862
862
  );
863
863
  return e ? {
864
864
  "data-blok-c": JSON.stringify(e),
@@ -868,69 +868,271 @@ const ge = (o = {}) => {
868
868
  return {};
869
869
  }
870
870
  };
871
- let $, R = "https://app.storyblok.com/f/storyblok-v2-latest.js";
872
- const me = (o, e, t = {}) => {
871
+ function Ae(r, e) {
872
+ if (!e)
873
+ return { src: r, attrs: {} };
874
+ let t = 0, s = 0;
875
+ const o = {}, n = [];
876
+ function i(a, h, u, d, g) {
877
+ typeof a != "number" || a <= h || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${h} and ${u} (inclusive)`) : g.push(`${d}(${a})`);
878
+ }
879
+ if (typeof e == "object") {
880
+ if (typeof e.width == "number" && e.width > 0 ? (o.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (o.height = e.height, s = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (o.loading = e.loading), e.class && (o.class = e.class), e.filters) {
881
+ const { filters: a } = e || {}, { blur: h, brightness: u, fill: d, format: g, grayscale: R, quality: y, rotate: w } = a || {};
882
+ h && i(h, 0, 100, "blur", n), y && i(y, 0, 100, "quality", n), u && i(u, 0, 100, "brightness", n), d && n.push(`fill(${d})`), R && n.push("grayscale()"), w && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${w})`), g && ["webp", "png", "jpeg"].includes(g) && n.push(`format(${g})`);
883
+ }
884
+ e.srcset && (o.srcset = e.srcset.map((a) => {
885
+ if (typeof a == "number")
886
+ return `${r}/m/${a}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
887
+ if (Array.isArray(a) && a.length === 2) {
888
+ const [h, u] = a;
889
+ return `${r}/m/${h}x${u}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${h}w`;
890
+ } else {
891
+ console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
892
+ return;
893
+ }
894
+ }).join(", ")), e.sizes && (o.sizes = e.sizes.join(", "));
895
+ }
896
+ let l = `${r}/m/`;
897
+ return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
898
+ src: l,
899
+ attrs: o
900
+ };
901
+ }
902
+ var k = /* @__PURE__ */ ((r) => (r.DOCUMENT = "doc", r.HEADING = "heading", r.PARAGRAPH = "paragraph", r.QUOTE = "blockquote", r.OL_LIST = "ordered_list", r.UL_LIST = "bullet_list", r.LIST_ITEM = "list_item", r.CODE_BLOCK = "code_block", r.HR = "horizontal_rule", r.BR = "hard_break", r.IMAGE = "image", r.EMOJI = "emoji", r.COMPONENT = "blok", r))(k || {}), v = /* @__PURE__ */ ((r) => (r.BOLD = "bold", r.STRONG = "strong", r.STRIKE = "strike", r.UNDERLINE = "underline", r.ITALIC = "italic", r.CODE = "code", r.LINK = "link", r.ANCHOR = "anchor", r.STYLED = "styled", r.SUPERSCRIPT = "superscript", r.SUBSCRIPT = "subscript", r.TEXT_STYLE = "textStyle", r.HIGHLIGHT = "highlight", r))(v || {}), G = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(G || {}), j = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(j || {});
903
+ const Ce = [
904
+ "area",
905
+ "base",
906
+ "br",
907
+ "col",
908
+ "embed",
909
+ "hr",
910
+ "img",
911
+ "input",
912
+ "link",
913
+ "meta",
914
+ "param",
915
+ "source",
916
+ "track",
917
+ "wbr"
918
+ ], Le = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), Pe = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
919
+ function Ne(r) {
920
+ return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
921
+ }
922
+ const B = (r) => Object.fromEntries(Object.entries(r).filter(([e, t]) => t !== void 0));
923
+ function Me(r, e = {}, t) {
924
+ const s = Le(e), o = s ? `${r} ${s}` : r;
925
+ return Ce.includes(r) ? `<${o}>` : `<${o}>${Array.isArray(t) ? t.join("") : t || ""}</${r}>`;
926
+ }
927
+ function De(r = {}) {
928
+ let e = 0;
929
+ const {
930
+ renderFn: t = Me,
931
+ textFn: s = Ne,
932
+ resolvers: o = {},
933
+ optimizeImages: n = !1,
934
+ keyedResolvers: i = !1
935
+ } = r, l = (c) => (m) => {
936
+ const f = m.attrs || {};
937
+ return i && (f.key = `${c}-${e}`), t(c, f, m.children || null);
938
+ }, a = (c) => {
939
+ const { src: m, alt: f, title: b, srcset: T, sizes: $ } = c.attrs || {};
940
+ let S = m, _ = {};
941
+ if (n) {
942
+ const { src: K, attrs: Y } = Ae(m, n);
943
+ S = K, _ = Y;
944
+ }
945
+ i && (_ = {
946
+ ..._,
947
+ key: `img-${e}`
948
+ });
949
+ const J = {
950
+ src: S,
951
+ alt: f,
952
+ title: b,
953
+ srcset: T,
954
+ sizes: $,
955
+ ..._
956
+ };
957
+ return t("img", B(J));
958
+ }, h = (c) => {
959
+ const { level: m, ...f } = c.attrs || {}, b = {
960
+ ...f
961
+ };
962
+ return i && (b.key = `h${m}-${e}`), t(`h${m}`, b, c.children);
963
+ }, u = (c) => {
964
+ var m, f, b, T;
965
+ const $ = t("img", {
966
+ src: (m = c.attrs) == null ? void 0 : m.fallbackImage,
967
+ alt: (f = c.attrs) == null ? void 0 : f.alt,
968
+ style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
969
+ draggable: "false",
970
+ loading: "lazy"
971
+ }), S = {
972
+ "data-type": "emoji",
973
+ "data-name": (b = c.attrs) == null ? void 0 : b.name,
974
+ "data-emoji": (T = c.attrs) == null ? void 0 : T.emoji
975
+ };
976
+ return i && (S.key = `emoji-${e}`), t("span", S, $);
977
+ }, d = (c) => t("pre", {
978
+ ...c.attrs,
979
+ key: `code-${e}`
980
+ }, t("code", { key: `code-${e}` }, c.children || "")), g = (c, m = !1) => ({ text: f, attrs: b }) => {
981
+ const { class: T, id: $, ...S } = b || {}, _ = m ? {
982
+ class: T,
983
+ id: $,
984
+ style: Pe(S) || void 0
985
+ } : b || {};
986
+ return i && (_.key = `${c}-${e}`), t(c, B(_), f);
987
+ }, R = (c) => C(c), y = (c) => {
988
+ const { marks: m, ...f } = c;
989
+ return "text" in c ? m ? m.reduce(
990
+ (b, T) => R({ ...T, text: b }),
991
+ // Fix: Ensure render function returns a string
992
+ R({ ...f, children: f.children })
993
+ // Fix: Cast children to string
994
+ ) : s(f.text) : "";
995
+ }, w = (c) => {
996
+ const { linktype: m, href: f, anchor: b, ...T } = c.attrs || {};
997
+ let $ = "";
998
+ switch (m) {
999
+ case j.ASSET:
1000
+ case j.URL:
1001
+ $ = f;
1002
+ break;
1003
+ case j.EMAIL:
1004
+ $ = `mailto:${f}`;
1005
+ break;
1006
+ case j.STORY:
1007
+ $ = f;
1008
+ break;
1009
+ }
1010
+ return b && ($ = `${$}#${b}`), t("a", { ...T, href: $, key: `a-${e}` }, c.text);
1011
+ }, I = (c) => {
1012
+ var m, f;
1013
+ return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
1014
+ blok: (m = c == null ? void 0 : c.attrs) == null ? void 0 : m.body[0],
1015
+ id: (f = c.attrs) == null ? void 0 : f.id,
1016
+ key: `component-${e}`,
1017
+ style: "display: none"
1018
+ });
1019
+ }, F = new Map([
1020
+ [k.DOCUMENT, l("div")],
1021
+ [k.HEADING, h],
1022
+ [k.PARAGRAPH, l("p")],
1023
+ [k.UL_LIST, l("ul")],
1024
+ [k.OL_LIST, l("ol")],
1025
+ [k.LIST_ITEM, l("li")],
1026
+ [k.IMAGE, a],
1027
+ [k.EMOJI, u],
1028
+ [k.CODE_BLOCK, d],
1029
+ [k.HR, l("hr")],
1030
+ [k.BR, l("br")],
1031
+ [k.QUOTE, l("blockquote")],
1032
+ [k.COMPONENT, I],
1033
+ [G.TEXT, y],
1034
+ [v.LINK, w],
1035
+ [v.ANCHOR, w],
1036
+ [v.STYLED, g("span", !0)],
1037
+ [v.BOLD, g("strong")],
1038
+ [v.TEXT_STYLE, g("span", !0)],
1039
+ [v.ITALIC, g("em")],
1040
+ [v.UNDERLINE, g("u")],
1041
+ [v.STRIKE, g("s")],
1042
+ [v.CODE, g("code")],
1043
+ [v.SUPERSCRIPT, g("sup")],
1044
+ [v.SUBSCRIPT, g("sub")],
1045
+ [v.HIGHLIGHT, g("mark")],
1046
+ ...Object.entries(o).map(([c, m]) => [c, m])
1047
+ ]);
1048
+ function M(c) {
1049
+ e += 1;
1050
+ const m = F.get(c.type);
1051
+ if (!m)
1052
+ return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
1053
+ if (c.type === "text")
1054
+ return m(c);
1055
+ const f = c.content ? c.content.map(C) : void 0;
1056
+ return m({
1057
+ ...c,
1058
+ children: f
1059
+ // Fix: Update the type of 'children' to Node[]
1060
+ });
1061
+ }
1062
+ function C(c) {
1063
+ return Array.isArray(c) ? c.map(M) : M(c);
1064
+ }
1065
+ return {
1066
+ render: C
1067
+ };
1068
+ }
1069
+ let P, N = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1070
+ const Be = (r, e, t = {}) => {
873
1071
  var s;
874
- const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
1072
+ const o = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
875
1073
  "_storyblok"
876
- ) === o;
877
- if (!(!r || !i)) {
878
- if (!o) {
1074
+ ) === r;
1075
+ if (!(!o || !n)) {
1076
+ if (!r) {
879
1077
  console.warn("Story ID is not defined. Please provide a valid ID.");
880
1078
  return;
881
1079
  }
882
1080
  window.storyblokRegisterEvent(() => {
883
- new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
884
- n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
1081
+ new window.StoryblokBridge(t).on(["input", "published", "change"], (i) => {
1082
+ i.action === "input" && i.story.id === r ? e(i.story) : (i.action === "change" || i.action === "published") && i.storyId === r && window.location.reload();
885
1083
  });
886
1084
  });
887
1085
  }
888
- }, ye = (o = {}) => {
1086
+ }, qe = (r = {}) => {
889
1087
  var e, t;
890
1088
  const {
891
1089
  bridge: s,
892
- accessToken: r,
893
- use: i = [],
894
- apiOptions: n = {},
895
- richText: a = {},
896
- bridgeUrl: l
897
- } = o;
898
- n.accessToken = n.accessToken || r;
899
- const h = { bridge: s, apiOptions: n };
1090
+ accessToken: o,
1091
+ use: n = [],
1092
+ apiOptions: i = {},
1093
+ richText: l = {},
1094
+ bridgeUrl: a
1095
+ } = r;
1096
+ i.accessToken = i.accessToken || o;
1097
+ const h = { bridge: s, apiOptions: i };
900
1098
  let u = {};
901
- i.forEach((p) => {
902
- u = { ...u, ...p(h) };
903
- }), l && (R = l);
1099
+ n.forEach((g) => {
1100
+ u = { ...u, ...g(h) };
1101
+ }), a && (N = a);
904
1102
  const d = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
905
- return s !== !1 && d && E(R), $ = new b(a.schema), a.resolver && P($, a.resolver), u;
906
- }, P = (o, e) => {
907
- o.addNode("blok", (t) => {
1103
+ return s !== !1 && d && q(N), P = new A(l.schema), l.resolver && V(P, l.resolver), u;
1104
+ }, V = (r, e) => {
1105
+ r.addNode("blok", (t) => {
908
1106
  let s = "";
909
- return t.attrs.body.forEach((r) => {
910
- s += e(r.component, r);
1107
+ return t.attrs.body.forEach((o) => {
1108
+ s += e(o.component, o);
911
1109
  }), {
912
1110
  html: s
913
1111
  };
914
1112
  });
915
- }, pe = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), be = (o, e, t) => {
916
- let s = t || $;
1113
+ }, He = (r) => !r || !(r != null && r.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Ge = (r, e, t) => {
1114
+ let s = t || P;
917
1115
  if (!s) {
918
1116
  console.error(
919
1117
  "Please initialize the Storyblok SDK before calling the renderRichText function"
920
1118
  );
921
1119
  return;
922
1120
  }
923
- return pe(o) ? "" : (e && (s = new b(e.schema), e.resolver && P(s, e.resolver)), s.render(o, {}, !1));
924
- }, ve = () => E(R);
1121
+ return He(r) ? "" : (e && (s = new A(e.schema), e.resolver && V(s, e.resolver)), s.render(r, {}, !1));
1122
+ }, Ve = () => q(N);
925
1123
  export {
926
- b as RichTextResolver,
927
- ae as RichTextSchema,
928
- ge as apiPlugin,
929
- pe as isRichTextEmpty,
930
- ve as loadStoryblokBridge,
931
- me as registerStoryblokBridge,
932
- be as renderRichText,
933
- fe as storyblokEditable,
934
- ye as storyblokInit,
935
- me as useStoryblokBridge
1124
+ k as BlockTypes,
1125
+ v as MarkTypes,
1126
+ A as RichTextResolver,
1127
+ _e as RichTextSchema,
1128
+ G as TextTypes,
1129
+ Ue as apiPlugin,
1130
+ He as isRichTextEmpty,
1131
+ Ve as loadStoryblokBridge,
1132
+ Be as registerStoryblokBridge,
1133
+ Ge as renderRichText,
1134
+ De as richTextResolver,
1135
+ ze as storyblokEditable,
1136
+ qe as storyblokInit,
1137
+ Be as useStoryblokBridge
936
1138
  };