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