@storyblok/js 3.1.9 → 3.2.0

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