@storyblok/js 4.4.1 → 4.4.2

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.
@@ -4,19 +4,19 @@
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
7
- var se = Object.defineProperty;
8
- var ie = (e, t, s) => t in e ? se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
9
- var m = (e, t, s) => ie(e, typeof t != "symbol" ? t + "" : t, s);
10
- let R = /* @__PURE__ */ function(e) {
7
+ var ce = Object.defineProperty;
8
+ var ue = (e, t, r) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
9
+ var m = (e, t, r) => ue(e, typeof t != "symbol" ? t + "" : t, r);
10
+ let v = /* @__PURE__ */ function(e) {
11
11
  return e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e.TABLE = "table", e.TABLE_ROW = "tableRow", e.TABLE_CELL = "tableCell", e.TABLE_HEADER = "tableHeader", e;
12
- }({}), _ = /* @__PURE__ */ function(e) {
12
+ }({}), w = /* @__PURE__ */ function(e) {
13
13
  return e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e;
14
- }({}), ne = /* @__PURE__ */ function(e) {
14
+ }({}), he = /* @__PURE__ */ function(e) {
15
15
  return e.TEXT = "text", e;
16
- }({}), P = /* @__PURE__ */ function(e) {
16
+ }({}), x = /* @__PURE__ */ function(e) {
17
17
  return e.URL = "url", e.STORY = "story", e.ASSET = "asset", e.EMAIL = "email", e;
18
18
  }({});
19
- const oe = [
19
+ const de = [
20
20
  "area",
21
21
  "base",
22
22
  "br",
@@ -31,251 +31,251 @@ const oe = [
31
31
  "source",
32
32
  "track",
33
33
  "wbr"
34
- ], le = (e = {}) => {
35
- const { custom: t, ...s } = e, r = {
36
- ...s,
34
+ ], fe = (e = {}) => {
35
+ const { custom: t, ...r } = e, s = {
36
+ ...r,
37
37
  ...t
38
38
  };
39
- return Object.keys(r).map((i) => `${i}="${r[i]}"`).join(" ");
40
- }, ae = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
41
- function ce(e) {
39
+ return Object.keys(s).map((i) => `${i}="${s[i]}"`).join(" ");
40
+ }, ge = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
41
+ function ye(e) {
42
42
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
43
43
  }
44
- const C = (e) => Object.fromEntries(Object.entries(e).filter(([t, s]) => s !== void 0));
45
- function ue(e, t) {
44
+ const O = (e) => Object.fromEntries(Object.entries(e).filter(([t, r]) => r !== void 0));
45
+ function be(e, t) {
46
46
  if (!t) return {
47
47
  src: e,
48
48
  attrs: {}
49
49
  };
50
- let s = 0, r = 0;
50
+ let r = 0, s = 0;
51
51
  const i = {}, n = [];
52
- function c(u, a, g, p, S) {
53
- typeof u != "number" || u <= a || u >= g ? console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase() + p.slice(1)} value must be a number between ${a} and ${g} (inclusive)`) : S.push(`${p}(${u})`);
52
+ function l(u, c, f, y, A) {
53
+ typeof u != "number" || u <= c || u >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${c} and ${f} (inclusive)`) : A.push(`${y}(${u})`);
54
54
  }
55
55
  if (typeof t == "object") {
56
- if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (i.width = t.width, s = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (i.height = t.height, r = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete i.width, delete i.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (i.loading = t.loading), t.class && (i.class = t.class), t.filters) {
57
- const { filters: u } = t || {}, { blur: a, brightness: g, fill: p, format: S, grayscale: I, quality: k, rotate: T } = u || {};
58
- a && c(a, 0, 100, "blur", n), k && c(k, 0, 100, "quality", n), g && c(g, 0, 100, "brightness", n), p && n.push(`fill(${p})`), I && n.push("grayscale()"), T && [
56
+ if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (i.width = t.width, r = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (i.height = t.height, s = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete i.width, delete i.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (i.loading = t.loading), t.class && (i.class = t.class), t.filters) {
57
+ const { filters: u } = t || {}, { blur: c, brightness: f, fill: y, format: A, grayscale: S, quality: E, rotate: T } = u || {};
58
+ c && l(c, 0, 100, "blur", n), E && l(E, 0, 100, "quality", n), f && l(f, 0, 100, "brightness", n), y && n.push(`fill(${y})`), S && n.push("grayscale()"), T && [
59
59
  0,
60
60
  90,
61
61
  180,
62
62
  270
63
- ].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`), S && [
63
+ ].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`), A && [
64
64
  "webp",
65
65
  "png",
66
66
  "jpeg"
67
- ].includes(S) && n.push(`format(${S})`);
67
+ ].includes(A) && n.push(`format(${A})`);
68
68
  }
69
69
  t.srcset && (i.srcset = t.srcset.map((u) => {
70
70
  if (typeof u == "number") return `${e}/m/${u}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${u}w`;
71
71
  if (Array.isArray(u) && u.length === 2) {
72
- const [a, g] = u;
73
- return `${e}/m/${a}x${g}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
72
+ const [c, f] = u;
73
+ return `${e}/m/${c}x${f}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
74
74
  } else {
75
75
  console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
76
76
  return;
77
77
  }
78
78
  }).join(", ")), t.sizes && (i.sizes = t.sizes.join(", "));
79
79
  }
80
- let l = `${e}/m/`;
81
- return (s > 0 || r > 0) && (l = `${l}${s}x${r}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
82
- src: l,
80
+ let a = `${e}/m/`;
81
+ return (r > 0 || s > 0) && (a = `${a}${r}x${s}/`), n.length > 0 && (a = `${a}filters:${n.join(":")}`), {
82
+ src: a,
83
83
  attrs: i
84
84
  };
85
85
  }
86
- function F(e, t = {}, s) {
87
- const r = le(t), i = r ? `${e} ${r}` : e, n = Array.isArray(s) ? s.join("") : s || "";
86
+ function V(e, t = {}, r) {
87
+ const s = fe(t), i = s ? `${e} ${s}` : e, n = Array.isArray(r) ? r.join("") : r || "";
88
88
  if (e) {
89
- if (oe.includes(e)) return `<${i}>`;
89
+ if (de.includes(e)) return `<${i}>`;
90
90
  } else return n;
91
91
  return `<${i}>${n}</${e}>`;
92
92
  }
93
- function he(e = {}) {
94
- const t = /* @__PURE__ */ new Map(), { renderFn: s = F, textFn: r = ce, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: c = !1 } = e, l = s !== F, u = (o = {}) => {
95
- const { textAlign: h, class: d, id: f, style: y, ...v } = o, b = [];
96
- return y && b.push(y.endsWith(";") ? y : `${y};`), h && b.push(`text-align: ${h};`), C({
97
- ...v,
93
+ function me(e = {}) {
94
+ const t = /* @__PURE__ */ new Map(), { renderFn: r = V, textFn: s = ye, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: l = !1 } = e, a = r !== V, u = (o = {}) => {
95
+ const { textAlign: h, class: d, id: g, style: b, ...R } = o, p = [];
96
+ return b && p.push(b.endsWith(";") ? b : `${b};`), h && p.push(`text-align: ${h};`), O({
97
+ ...R,
98
98
  class: d,
99
- id: f,
100
- ...b.length > 0 ? { style: b.join(" ") } : {}
99
+ id: g,
100
+ ...p.length > 0 ? { style: p.join(" ") } : {}
101
101
  });
102
- }, a = (o) => (h, d) => {
103
- const f = u(h.attrs);
104
- return d.render(o, f, h.children || null);
105
- }, g = (o, h) => {
106
- const { src: d, alt: f, title: y, srcset: v, sizes: b } = o.attrs || {};
107
- let A = d, w = {};
102
+ }, c = (o) => (h, d) => {
103
+ const g = u(h.attrs);
104
+ return d.render(o, g, h.children || null);
105
+ }, f = (o, h) => {
106
+ const { src: d, alt: g, title: b, srcset: R, sizes: p } = o.attrs || {};
107
+ let k = d, _ = {};
108
108
  if (n) {
109
- const { src: te, attrs: re } = ue(d, n);
110
- A = te, w = re;
109
+ const { src: ae, attrs: le } = be(d, n);
110
+ k = ae, _ = le;
111
111
  }
112
- const L = {
113
- src: A,
114
- alt: f,
115
- title: y,
116
- srcset: v,
117
- sizes: b,
118
- ...w
112
+ const C = {
113
+ src: k,
114
+ alt: g,
115
+ title: b,
116
+ srcset: R,
117
+ sizes: p,
118
+ ..._
119
119
  };
120
- return h.render("img", C(L));
121
- }, p = (o, h) => {
122
- const { level: d, ...f } = o.attrs || {}, y = u(f);
123
- return h.render(`h${d}`, y, o.children);
124
- }, S = (o, h) => {
125
- var f, y, v, b;
120
+ return h.render("img", O(C));
121
+ }, y = (o, h) => {
122
+ const { level: d, ...g } = o.attrs || {}, b = u(g);
123
+ return h.render(`h${d}`, b, o.children);
124
+ }, A = (o, h) => {
125
+ var g, b, R, p;
126
126
  const d = h.render("img", {
127
- src: (f = o.attrs) == null ? void 0 : f.fallbackImage,
128
- alt: (y = o.attrs) == null ? void 0 : y.alt,
127
+ src: (g = o.attrs) == null ? void 0 : g.fallbackImage,
128
+ alt: (b = o.attrs) == null ? void 0 : b.alt,
129
129
  style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
130
130
  draggable: "false",
131
131
  loading: "lazy"
132
132
  });
133
133
  return h.render("span", {
134
134
  "data-type": "emoji",
135
- "data-name": (v = o.attrs) == null ? void 0 : v.name,
136
- "data-emoji": (b = o.attrs) == null ? void 0 : b.emoji
135
+ "data-name": (R = o.attrs) == null ? void 0 : R.name,
136
+ "data-emoji": (p = o.attrs) == null ? void 0 : p.emoji
137
137
  }, d);
138
- }, I = (o, h) => h.render("pre", o.attrs || {}, h.render("code", {}, o.children || "")), k = (o, h = !1) => ({ text: d, attrs: f }, y) => {
139
- const { class: v, id: b, ...A } = f || {}, w = h ? {
140
- class: v,
141
- id: b,
142
- style: ae(A) || void 0
143
- } : f || {};
144
- return y.render(o, C(w), d);
145
- }, T = (o) => N(o), K = (o) => {
138
+ }, S = (o, h) => h.render("pre", o.attrs || {}, h.render("code", {}, o.children || "")), E = (o, h = !1) => ({ text: d, attrs: g }, b) => {
139
+ const { class: R, id: p, ...k } = g || {}, _ = h ? {
140
+ class: R,
141
+ id: p,
142
+ style: ge(k) || void 0
143
+ } : g || {};
144
+ return b.render(o, O(_), d);
145
+ }, T = (o) => U(o), ee = (o) => {
146
146
  const { marks: h, ...d } = o;
147
147
  if ("text" in o) {
148
- if (h) return h.reduce((y, v) => T({
149
- ...v,
150
- text: y
148
+ if (h) return h.reduce((b, R) => T({
149
+ ...R,
150
+ text: b
151
151
  }), T({
152
152
  ...d,
153
153
  children: d.children
154
154
  }));
155
- const f = o.attrs || {};
156
- if (c) {
157
- const y = t.get("txt") || 0;
158
- t.set("txt", y + 1), f.key = `txt-${y}`;
155
+ const g = o.attrs || {};
156
+ if (l) {
157
+ const b = t.get("txt") || 0;
158
+ t.set("txt", b + 1), g.key = `txt-${b}`;
159
159
  }
160
- return r(d.text, f);
160
+ return s(d.text, g);
161
161
  }
162
162
  return "";
163
- }, U = (o, h) => {
164
- const { linktype: d, href: f, anchor: y, ...v } = o.attrs || {};
165
- let b = "";
163
+ }, D = (o, h) => {
164
+ const { linktype: d, href: g, anchor: b, ...R } = o.attrs || {};
165
+ let p = "";
166
166
  switch (d) {
167
- case P.ASSET:
168
- case P.URL:
169
- b = f;
167
+ case x.ASSET:
168
+ case x.URL:
169
+ p = g;
170
170
  break;
171
- case P.EMAIL:
172
- b = `mailto:${f}`;
171
+ case x.EMAIL:
172
+ p = `mailto:${g}`;
173
173
  break;
174
- case P.STORY:
175
- b = f, y && (b = `${b}#${y}`);
174
+ case x.STORY:
175
+ p = g, b && (p = `${p}#${b}`);
176
176
  break;
177
177
  default:
178
- b = f;
178
+ p = g;
179
179
  break;
180
180
  }
181
- const A = { ...v };
182
- return b && (A.href = b), h.render("a", A, o.text);
183
- }, Y = (o, h) => {
184
- var d, f;
181
+ const k = { ...R };
182
+ return p && (k.href = p), h.render("a", k, o.text);
183
+ }, te = (o, h) => {
184
+ var d, g;
185
185
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
186
186
  blok: (d = o == null ? void 0 : o.attrs) == null ? void 0 : d.body[0],
187
- id: (f = o.attrs) == null ? void 0 : f.id,
187
+ id: (g = o.attrs) == null ? void 0 : g.id,
188
188
  style: "display: none"
189
189
  });
190
- }, W = (o, h) => {
191
- const d = u(o.attrs), f = o.children || null;
192
- return h.render("table", d, h.render("tbody", {}, f));
193
- }, X = (o, h) => {
190
+ }, re = (o, h) => {
191
+ const d = u(o.attrs), g = o.children || null;
192
+ return h.render("table", d, h.render("tbody", {}, g));
193
+ }, se = (o, h) => {
194
194
  const d = u(o.attrs);
195
195
  return h.render("tr", d, o.children);
196
- }, Q = (o, h) => {
197
- const { colspan: d, rowspan: f, colwidth: y, backgroundColor: v, textAlign: b, ...A } = o.attrs || {}, w = [];
198
- y && w.push(`width: ${y}px;`), v && w.push(`background-color: ${v};`), b && w.push(`text-align: ${b};`);
199
- const L = {
200
- ...A,
196
+ }, ie = (o, h) => {
197
+ const { colspan: d, rowspan: g, colwidth: b, backgroundColor: R, textAlign: p, ...k } = o.attrs || {}, _ = [];
198
+ b && _.push(`width: ${b}px;`), R && _.push(`background-color: ${R};`), p && _.push(`text-align: ${p};`);
199
+ const C = {
200
+ ...k,
201
201
  ...d > 1 ? { colspan: d } : {},
202
- ...f > 1 ? { rowspan: f } : {},
203
- ...w.length > 0 ? { style: w.join(" ") } : {}
202
+ ...g > 1 ? { rowspan: g } : {},
203
+ ..._.length > 0 ? { style: _.join(" ") } : {}
204
204
  };
205
- return h.render("td", C(L), o.children);
206
- }, Z = (o, h) => {
207
- const { colspan: d, rowspan: f, colwidth: y, backgroundColor: v, textAlign: b, ...A } = o.attrs || {}, w = [];
208
- y && w.push(`width: ${y}px;`), v && w.push(`background-color: ${v};`), b && w.push(`text-align: ${b};`);
209
- const L = {
210
- ...A,
205
+ return h.render("td", O(C), o.children);
206
+ }, ne = (o, h) => {
207
+ const { colspan: d, rowspan: g, colwidth: b, backgroundColor: R, textAlign: p, ...k } = o.attrs || {}, _ = [];
208
+ b && _.push(`width: ${b}px;`), R && _.push(`background-color: ${R};`), p && _.push(`text-align: ${p};`);
209
+ const C = {
210
+ ...k,
211
211
  ...d > 1 ? { colspan: d } : {},
212
- ...f > 1 ? { rowspan: f } : {},
213
- ...w.length > 0 ? { style: w.join(" ") } : {}
212
+ ...g > 1 ? { rowspan: g } : {},
213
+ ..._.length > 0 ? { style: _.join(" ") } : {}
214
214
  };
215
- return h.render("th", C(L), o.children);
215
+ return h.render("th", O(C), o.children);
216
216
  }, B = /* @__PURE__ */ new Map([
217
- [R.DOCUMENT, a("")],
218
- [R.HEADING, p],
219
- [R.PARAGRAPH, a("p")],
220
- [R.UL_LIST, a("ul")],
221
- [R.OL_LIST, a("ol")],
222
- [R.LIST_ITEM, a("li")],
223
- [R.IMAGE, g],
224
- [R.EMOJI, S],
225
- [R.CODE_BLOCK, I],
226
- [R.HR, a("hr")],
227
- [R.BR, a("br")],
228
- [R.QUOTE, a("blockquote")],
229
- [R.COMPONENT, Y],
230
- [ne.TEXT, K],
231
- [_.LINK, U],
232
- [_.ANCHOR, U],
233
- [_.STYLED, k("span", !0)],
234
- [_.BOLD, k("strong")],
235
- [_.TEXT_STYLE, k("span", !0)],
236
- [_.ITALIC, k("em")],
237
- [_.UNDERLINE, k("u")],
238
- [_.STRIKE, k("s")],
239
- [_.CODE, k("code")],
240
- [_.SUPERSCRIPT, k("sup")],
241
- [_.SUBSCRIPT, k("sub")],
242
- [_.HIGHLIGHT, k("mark")],
243
- [R.TABLE, W],
244
- [R.TABLE_ROW, X],
245
- [R.TABLE_CELL, Q],
246
- [R.TABLE_HEADER, Z]
247
- ]), z = new Map([...B, ...Object.entries(i).map(([o, h]) => [o, h])]), ee = () => ({
248
- render: (d, f = {}, y) => {
249
- if (c && d) {
250
- const v = t.get(d) || 0;
251
- t.set(d, v + 1), f.key = `${d}-${v}`;
217
+ [v.DOCUMENT, c("")],
218
+ [v.HEADING, y],
219
+ [v.PARAGRAPH, c("p")],
220
+ [v.UL_LIST, c("ul")],
221
+ [v.OL_LIST, c("ol")],
222
+ [v.LIST_ITEM, c("li")],
223
+ [v.IMAGE, f],
224
+ [v.EMOJI, A],
225
+ [v.CODE_BLOCK, S],
226
+ [v.HR, c("hr")],
227
+ [v.BR, c("br")],
228
+ [v.QUOTE, c("blockquote")],
229
+ [v.COMPONENT, te],
230
+ [he.TEXT, ee],
231
+ [w.LINK, D],
232
+ [w.ANCHOR, D],
233
+ [w.STYLED, E("span", !0)],
234
+ [w.BOLD, E("strong")],
235
+ [w.TEXT_STYLE, E("span", !0)],
236
+ [w.ITALIC, E("em")],
237
+ [w.UNDERLINE, E("u")],
238
+ [w.STRIKE, E("s")],
239
+ [w.CODE, E("code")],
240
+ [w.SUPERSCRIPT, E("sup")],
241
+ [w.SUBSCRIPT, E("sub")],
242
+ [w.HIGHLIGHT, E("mark")],
243
+ [v.TABLE, re],
244
+ [v.TABLE_ROW, se],
245
+ [v.TABLE_CELL, ie],
246
+ [v.TABLE_HEADER, ne]
247
+ ]), z = new Map([...B, ...Object.entries(i).map(([o, h]) => [o, h])]), oe = () => ({
248
+ render: (d, g = {}, b) => {
249
+ if (l && d) {
250
+ const R = t.get(d) || 0;
251
+ t.set(d, R + 1), g.key = `${d}-${R}`;
252
252
  }
253
- return s(d, f, y);
253
+ return r(d, g, b);
254
254
  },
255
255
  originalResolvers: B,
256
256
  mergedResolvers: z
257
257
  });
258
- function O(o) {
258
+ function P(o) {
259
259
  const h = z.get(o.type);
260
260
  if (!h)
261
261
  return console.error("<Storyblok>", `No resolver found for node type ${o.type}`), "";
262
- const d = ee();
262
+ const d = oe();
263
263
  if (o.type === "text") return h(o, d);
264
- const f = o.content ? o.content.map(N) : void 0;
264
+ const g = o.content ? o.content.map(U) : void 0;
265
265
  return h({
266
266
  ...o,
267
- children: f
267
+ children: g
268
268
  }, d);
269
269
  }
270
- function N(o) {
271
- return o.type === "doc" ? l ? o.content.map(O) : o.content.map(O).join("") : Array.isArray(o) ? o.map(O) : O(o);
270
+ function U(o) {
271
+ return o.type === "doc" ? a ? o.content.map(P) : o.content.map(P).join("") : Array.isArray(o) ? o.map(P) : P(o);
272
272
  }
273
- return { render: N };
273
+ return { render: U };
274
274
  }
275
- let G = !1;
276
- const q = [], J = (e) => new Promise((t, s) => {
275
+ let Y = !1;
276
+ const J = [], X = (e) => new Promise((t, r) => {
277
277
  if (typeof window > "u") {
278
- s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
278
+ r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
279
279
  return;
280
280
  }
281
281
  if (window.storyblokRegisterEvent = (i) => {
@@ -283,70 +283,34 @@ const q = [], J = (e) => new Promise((t, s) => {
283
283
  console.warn("You are not in Draft Mode or in the Visual Editor.");
284
284
  return;
285
285
  }
286
- G ? i() : q.push(i);
286
+ Y ? i() : J.push(i);
287
287
  }, document.getElementById("storyblok-javascript-bridge")) {
288
288
  t(void 0);
289
289
  return;
290
290
  }
291
- const r = document.createElement("script");
292
- r.async = !0, r.src = e, r.id = "storyblok-javascript-bridge", r.onerror = (i) => s(i), r.onload = (i) => {
293
- q.forEach((n) => n()), G = !0, t(i);
294
- }, document.getElementsByTagName("head")[0].appendChild(r);
295
- });
296
- var de = class extends Error {
297
- constructor(e) {
298
- super(e), this.name = "AbortError";
299
- }
300
- };
301
- function fe(e, t, s) {
302
- if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
303
- if (!Number.isFinite(s)) throw new TypeError("Expected `interval` to be a finite number");
304
- const r = [];
305
- let i = [], n = 0, c = !1;
306
- const l = async () => {
307
- n++;
308
- const a = r.shift();
309
- if (a) try {
310
- const p = await e(...a.args);
311
- a.resolve(p);
312
- } catch (p) {
313
- a.reject(p);
314
- }
315
- const g = setTimeout(() => {
316
- n--, r.length > 0 && l(), i = i.filter((p) => p !== g);
317
- }, s);
318
- i.includes(g) || i.push(g);
319
- }, u = (...a) => c ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((g, p) => {
320
- r.push({
321
- resolve: g,
322
- reject: p,
323
- args: a
324
- }), n < t && l();
325
- });
326
- return u.abort = () => {
327
- c = !0, i.forEach(clearTimeout), i = [], r.forEach((a) => a.reject(() => new de("Throttle function aborted"))), r.length = 0;
328
- }, u;
329
- }
330
- var ge = fe;
331
- const V = (e = "") => e.includes("/cdn/"), ye = (e, t = 25, s = 1) => ({
291
+ const s = document.createElement("script");
292
+ s.async = !0, s.src = e, s.id = "storyblok-javascript-bridge", s.onerror = (i) => r(i), s.onload = (i) => {
293
+ J.forEach((n) => n()), Y = !0, t(i);
294
+ }, document.getElementsByTagName("head")[0].appendChild(s);
295
+ }), K = (e = "") => e.includes("/cdn/"), pe = (e, t = 25, r = 1) => ({
332
296
  ...e,
333
297
  per_page: t,
334
- page: s
335
- }), be = (e) => new Promise((t) => setTimeout(t, e)), pe = (e = 0, t) => Array.from({ length: e }, t), me = (e = 0, t = e) => {
336
- const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
337
- return pe(s, (i, n) => n * r + e);
338
- }, ve = async (e, t) => Promise.all(e.map(t)), Re = (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []), j = (e, t, s) => {
339
- const r = [];
298
+ page: r
299
+ }), Re = (e) => new Promise((t) => setTimeout(t, e)), ve = (e = 0, t) => Array.from({ length: e }, t), _e = (e = 0, t = e) => {
300
+ const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
301
+ return ve(r, (i, n) => n * s + e);
302
+ }, Ee = async (e, t) => Promise.all(e.map(t)), Ae = (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], []), F = (e, t, r) => {
303
+ const s = [];
340
304
  for (const i in e) {
341
305
  if (!Object.prototype.hasOwnProperty.call(e, i)) continue;
342
306
  const n = e[i];
343
307
  if (n == null) continue;
344
- const c = s ? "" : encodeURIComponent(i);
345
- let l;
346
- typeof n == "object" ? l = j(n, t ? t + encodeURIComponent(`[${c}]`) : c, Array.isArray(n)) : l = `${t ? t + encodeURIComponent(`[${c}]`) : c}=${encodeURIComponent(n)}`, r.push(l);
308
+ const l = r ? "" : encodeURIComponent(i);
309
+ let a;
310
+ typeof n == "object" ? a = F(n, t ? t + encodeURIComponent(`[${l}]`) : l, Array.isArray(n)) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, s.push(a);
347
311
  }
348
- return r.join("&");
349
- }, D = (e) => {
312
+ return s.join("&");
313
+ }, W = (e) => {
350
314
  const t = {
351
315
  eu: "api.storyblok.com",
352
316
  us: "api-us.storyblok.com",
@@ -388,37 +352,37 @@ var we = class {
388
352
  return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
389
353
  }
390
354
  async _responseHandler(e) {
391
- const t = [], s = {
355
+ const t = [], r = {
392
356
  data: {},
393
357
  headers: {},
394
358
  status: 0,
395
359
  statusText: ""
396
360
  };
397
- e.status !== 204 && await e.json().then((r) => {
398
- s.data = r;
361
+ e.status !== 204 && await e.json().then((s) => {
362
+ r.data = s;
399
363
  });
400
- for (const r of e.headers.entries()) t[r[0]] = r[1];
401
- return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
364
+ for (const s of e.headers.entries()) t[s[0]] = s[1];
365
+ return r.headers = { ...t }, r.status = e.status, r.statusText = e.statusText, r;
402
366
  }
403
367
  async _methodHandler(e) {
404
- let t = `${this.baseURL}${this.url}`, s = null;
405
- e === "get" ? t = `${this.baseURL}${this.url}?${j(this.parameters)}` : s = JSON.stringify(this.parameters);
406
- const r = new URL(t), i = new AbortController(), { signal: n } = i;
407
- let c = null;
408
- this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
368
+ let t = `${this.baseURL}${this.url}`, r = null;
369
+ e === "get" ? t = `${this.baseURL}${this.url}?${F(this.parameters)}` : r = JSON.stringify(this.parameters);
370
+ const s = new URL(t), i = new AbortController(), { signal: n } = i;
371
+ let l = null;
372
+ this.timeout && (l = setTimeout(() => i.abort(), this.timeout));
409
373
  try {
410
- const l = await this.fetch(`${r}`, {
374
+ const a = await this.fetch(`${s}`, {
411
375
  method: e,
412
376
  headers: this.headers,
413
- body: s,
377
+ body: r,
414
378
  signal: n,
415
379
  ...this.fetchOptions
416
380
  });
417
- this.timeout && c && clearTimeout(c);
418
- const u = await this._responseHandler(l);
381
+ this.timeout && l && clearTimeout(l);
382
+ const u = await this._responseHandler(a);
419
383
  return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(u)) : this._statusHandler(u);
420
- } catch (l) {
421
- return { message: l };
384
+ } catch (a) {
385
+ return { message: a };
422
386
  }
423
387
  }
424
388
  setFetchOptions(e = {}) {
@@ -446,27 +410,148 @@ var we = class {
446
410
  }
447
411
  _statusHandler(e) {
448
412
  const t = /20[0-6]/g;
449
- return new Promise((s, r) => {
450
- if (t.test(`${e.status}`)) return s(e);
413
+ return new Promise((r, s) => {
414
+ if (t.test(`${e.status}`)) return r(e);
451
415
  const i = {
452
416
  message: this._normalizeErrorMessage(e.data),
453
417
  status: e.status,
454
418
  response: e
455
419
  };
456
- r(i);
420
+ s(i);
457
421
  });
458
422
  }
459
423
  }, ke = we;
460
- const M = "SB-Agent", $ = {
424
+ const Q = "SB-Agent", $ = {
461
425
  defaultAgentName: "SB-JS-CLIENT",
462
426
  defaultAgentVersion: "SB-Agent-Version",
463
427
  packageVersion: "7.0.0"
464
- }, _e = {
428
+ }, Z = {
429
+ DRAFT: "draft",
465
430
  PUBLISHED: "published"
431
+ }, Le = 25, M = {
432
+ SMALL: 25,
433
+ MEDIUM: 50,
434
+ LARGE: 75
435
+ }, I = {
436
+ SINGLE_OR_SMALL: 50,
437
+ MEDIUM: 15,
438
+ LARGE: 10,
439
+ VERY_LARGE: 6
440
+ }, j = 1e3, G = 3;
441
+ function Se(e) {
442
+ return e.version === Z.DRAFT;
443
+ }
444
+ function Te(e, t) {
445
+ const r = e.includes("/cdn/stories/"), s = e.split("/").length > 3 && !e.endsWith("/cdn/stories"), i = "find_by" in t;
446
+ return r && s || i;
447
+ }
448
+ function Ce(e) {
449
+ return e <= M.SMALL ? I.SINGLE_OR_SMALL : e <= M.MEDIUM ? I.MEDIUM : e <= M.LARGE ? I.LARGE : I.VERY_LARGE;
450
+ }
451
+ function N(e, t, r = {}, s) {
452
+ if (r.userRateLimit !== void 0) return Math.min(r.userRateLimit, j);
453
+ if (r.serverHeadersRateLimit !== void 0) return Math.min(r.serverHeadersRateLimit, j);
454
+ if (t && !Se(t)) return j;
455
+ if (s !== void 0) return s;
456
+ if (Te(e, t)) return I.SINGLE_OR_SMALL;
457
+ const i = t.per_page || Le;
458
+ return Ce(i);
459
+ }
460
+ function Oe(e) {
461
+ if (!e) return null;
462
+ const t = e["x-ratelimit"] || e["X-RateLimit"], r = e["x-ratelimit-policy"] || e["X-RateLimit-Policy"];
463
+ if (!t && !r) return null;
464
+ const s = {};
465
+ if (t) {
466
+ const i = t.match(/r=(\d+)/);
467
+ i && (s.remaining = Number.parseInt(i[1], 10));
468
+ }
469
+ if (r) {
470
+ const i = r.match(/q=(\d+)/);
471
+ i && (s.max = Number.parseInt(i[1], 10));
472
+ }
473
+ return Object.keys(s).length > 0 ? s : null;
474
+ }
475
+ function Ie(e, t = !1) {
476
+ return {
477
+ userRateLimit: e,
478
+ serverHeadersRateLimit: void 0,
479
+ isManagementApi: t
480
+ };
481
+ }
482
+ var Pe = class extends Error {
483
+ constructor(e) {
484
+ super(e), this.name = "AbortError";
485
+ }
486
+ };
487
+ function xe(e, t, r) {
488
+ if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
489
+ if (!Number.isFinite(r)) throw new TypeError("Expected `interval` to be a finite number");
490
+ const s = [];
491
+ let i = [], n = 0, l = !1;
492
+ const a = async () => {
493
+ n++;
494
+ const c = s.shift();
495
+ if (c) try {
496
+ const y = await e(...c.args);
497
+ c.resolve(y);
498
+ } catch (y) {
499
+ c.reject(y);
500
+ }
501
+ const f = setTimeout(() => {
502
+ n--, s.length > 0 && a(), i = i.filter((y) => y !== f);
503
+ }, r);
504
+ i.includes(f) || i.push(f);
505
+ }, u = (...c) => l ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((f, y) => {
506
+ s.push({
507
+ resolve: f,
508
+ reject: y,
509
+ args: c
510
+ }), n < t && a();
511
+ });
512
+ return u.abort = () => {
513
+ l = !0, i.forEach(clearTimeout), i = [], s.forEach((c) => c.reject(() => new Pe("Throttle function aborted"))), s.length = 0;
514
+ }, u;
515
+ }
516
+ var Ne = xe, He = class {
517
+ constructor(e, t = 1e3) {
518
+ m(this, "queues");
519
+ m(this, "interval");
520
+ m(this, "throttledRequestFn");
521
+ this.queues = /* @__PURE__ */ new Map(), this.interval = t, this.throttledRequestFn = e;
522
+ }
523
+ /**
524
+ * Gets or creates a throttle queue for the specified rate limit
525
+ */
526
+ getQueue(e) {
527
+ let t = this.queues.get(e);
528
+ return t || (t = Ne(this.throttledRequestFn, e, this.interval), this.queues.set(e, t)), t;
529
+ }
530
+ /**
531
+ * Executes a request through the appropriate throttle queue based on rate limit
532
+ */
533
+ execute(e, ...t) {
534
+ return this.getQueue(e)(...t);
535
+ }
536
+ /**
537
+ * Aborts all throttle queues
538
+ */
539
+ abortAll() {
540
+ this.queues.forEach((e) => {
541
+ var t;
542
+ (t = e.abort) == null || t.call(e);
543
+ }), this.queues.clear();
544
+ }
545
+ /**
546
+ * Gets the number of active queues
547
+ */
548
+ getQueueCount() {
549
+ return this.queues.size;
550
+ }
466
551
  };
467
- let x = {};
468
- const E = {};
469
- var Se = class {
552
+ let H = {};
553
+ const L = {};
554
+ var Ue = class {
470
555
  /**
471
556
  *
472
557
  * @param config ISbConfig interface
@@ -476,13 +561,14 @@ var Se = class {
476
561
  m(this, "client");
477
562
  m(this, "maxRetries");
478
563
  m(this, "retriesDelay");
479
- m(this, "throttle");
564
+ m(this, "throttleManager");
480
565
  m(this, "accessToken");
481
566
  m(this, "cache");
482
567
  m(this, "resolveCounter");
483
568
  m(this, "relations");
484
569
  m(this, "links");
485
570
  m(this, "version");
571
+ m(this, "rateLimitConfig");
486
572
  /**
487
573
  * @deprecated This property is deprecated. Use the standalone `richTextResolver` from `@storyblok/richtext` instead.
488
574
  * @see https://github.com/storyblok/richtext
@@ -491,65 +577,63 @@ var Se = class {
491
577
  m(this, "resolveNestedRelations");
492
578
  m(this, "stringifiedStoriesCache");
493
579
  m(this, "inlineAssets");
494
- let s = e.endpoint || t;
495
- if (!s) {
496
- const n = e.https === !1 ? "http" : "https";
497
- e.oauthToken ? s = `${n}://${D(e.region)}/v1` : s = `${n}://${D(e.region)}/v2`;
580
+ let r = e.endpoint || t;
581
+ if (!r) {
582
+ const i = e.https === !1 ? "http" : "https";
583
+ e.oauthToken ? r = `${i}://${W(e.region)}/v1` : r = `${i}://${W(e.region)}/v2`;
498
584
  }
499
- const r = new Headers();
500
- 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(([c, l]) => {
501
- r.set(c, l);
502
- }), r.has(M) || (r.set(M, $.defaultAgentName), r.set($.defaultAgentVersion, $.packageVersion));
503
- let i = 5;
504
- e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ge(this.throttledRequest.bind(this), i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || _e.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new ke({
505
- baseURL: s,
585
+ const s = new Headers();
586
+ s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([n, l]) => {
587
+ s.set(n, l);
588
+ }), s.has(Q) || (s.set(Q, $.defaultAgentName), s.set($.defaultAgentVersion, $.packageVersion)), e.oauthToken && s.set("Authorization", e.oauthToken), this.rateLimitConfig = Ie(e.rateLimit, !!e.oauthToken), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttleManager = new He(this.throttledRequest.bind(this), 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || Z.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new ke({
589
+ baseURL: r,
506
590
  timeout: e.timeout || 0,
507
- headers: r,
591
+ headers: s,
508
592
  responseInterceptor: e.responseInterceptor,
509
593
  fetch: e.fetch
510
594
  });
511
595
  }
512
596
  parseParams(e) {
513
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
597
+ return e.token || (e.token = this.getToken()), e.cv || (e.cv = L[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
514
598
  }
515
599
  factoryParamOptions(e, t) {
516
- return V(e) ? this.parseParams(t) : t;
600
+ return K(e) ? this.parseParams(t) : t;
517
601
  }
518
- makeRequest(e, t, s, r, i) {
519
- const n = this.factoryParamOptions(e, ye(t, s, r));
602
+ makeRequest(e, t, r, s, i) {
603
+ const n = this.factoryParamOptions(e, pe(t, r, s));
520
604
  return this.cacheResponse(e, n, void 0, i);
521
605
  }
522
- get(e, t = {}, s) {
606
+ get(e, t = {}, r) {
523
607
  t || (t = {});
524
- const r = `/${e}`;
525
- V(r) && (t.version = t.version || this.version);
526
- const i = this.factoryParamOptions(r, t);
527
- return this.cacheResponse(r, i, void 0, s);
608
+ const s = `/${e}`;
609
+ K(s) && (t.version = t.version || this.version);
610
+ const i = this.factoryParamOptions(s, t);
611
+ return this.cacheResponse(s, i, void 0, r);
528
612
  }
529
- async getAll(e, t = {}, s, r) {
530
- const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), c = s ?? n.substring(n.lastIndexOf("/") + 1);
613
+ async getAll(e, t = {}, r, s) {
614
+ const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = r ?? n.substring(n.lastIndexOf("/") + 1);
531
615
  t.version = t.version || this.version;
532
- const l = 1, u = await this.makeRequest(n, t, i, l, r), a = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, g = await ve(me(l, a), (p) => this.makeRequest(n, t, i, p + 1, r));
533
- return Re([u, ...g], (p) => Object.values(p.data[c]));
616
+ const a = 1, u = await this.makeRequest(n, t, i, a, s), c = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, f = await Ee(_e(a, c), (y) => this.makeRequest(n, t, i, y + 1, s));
617
+ return Ae([u, ...f], (y) => Object.values(y.data[l]));
534
618
  }
535
- post(e, t = {}, s) {
536
- const r = `/${e}`;
537
- return this.throttle("post", r, t, s);
619
+ post(e, t = {}, r) {
620
+ const s = `/${e}`, i = N(void 0, void 0, this.rateLimitConfig, G);
621
+ return this.throttleManager.execute(i, "post", s, t, r);
538
622
  }
539
- put(e, t = {}, s) {
540
- const r = `/${e}`;
541
- return this.throttle("put", r, t, s);
623
+ put(e, t = {}, r) {
624
+ const s = `/${e}`, i = N(void 0, void 0, this.rateLimitConfig, G);
625
+ return this.throttleManager.execute(i, "put", s, t, r);
542
626
  }
543
- delete(e, t = {}, s) {
627
+ delete(e, t = {}, r) {
544
628
  t || (t = {});
545
- const r = `/${e}`;
546
- return this.throttle("delete", r, t, s);
629
+ const s = `/${e}`, i = N(void 0, void 0, this.rateLimitConfig, G);
630
+ return this.throttleManager.execute(i, "delete", s, t, r);
547
631
  }
548
632
  getStories(e = {}, t) {
549
633
  return this._addResolveLevel(e), this.get("cdn/stories", e, t);
550
634
  }
551
- getStory(e, t = {}, s) {
552
- return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
635
+ getStory(e, t = {}, r) {
636
+ return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, r);
553
637
  }
554
638
  getToken() {
555
639
  return this.accessToken;
@@ -563,9 +647,9 @@ var Se = class {
563
647
  _cleanCopy(e) {
564
648
  return JSON.parse(JSON.stringify(e));
565
649
  }
566
- _insertLinks(e, t, s) {
567
- const r = e[t];
568
- 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]));
650
+ _insertLinks(e, t, r) {
651
+ const s = e[t];
652
+ s && s.fieldtype === "multilink" && s.linktype === "story" && typeof s.id == "string" && this.links[r][s.id] ? s.story = this._cleanCopy(this.links[r][s.id]) : s && s.linktype === "story" && typeof s.uuid == "string" && this.links[r][s.uuid] && (s.story = this._cleanCopy(this.links[r][s.uuid]));
569
653
  }
570
654
  /**
571
655
  *
@@ -586,9 +670,9 @@ var Se = class {
586
670
  * - For single strings: directly replaces the UUID with the story reference
587
671
  * - For arrays: maps through each UUID and replaces with corresponding story references
588
672
  */
589
- _resolveField(e, t, s) {
590
- const r = e[t];
591
- typeof r == "string" ? e[t] = this.getStoryReference(s, r) : Array.isArray(r) && (e[t] = r.map((i) => this.getStoryReference(s, i)).filter(Boolean));
673
+ _resolveField(e, t, r) {
674
+ const s = e[t];
675
+ typeof s == "string" ? e[t] = this.getStoryReference(r, s) : Array.isArray(s) && (e[t] = s.map((i) => this.getStoryReference(r, i)).filter(Boolean));
592
676
  }
593
677
  /**
594
678
  * Inserts relations into the JSON tree by resolving references
@@ -607,13 +691,13 @@ var Se = class {
607
691
  * The method supports both string and array formats for the fields parameter,
608
692
  * allowing flexible specification of relation patterns.
609
693
  */
610
- _insertRelations(e, t, s, r) {
611
- if (Array.isArray(s) ? s.find((c) => c.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
612
- this._resolveField(e, t, r);
694
+ _insertRelations(e, t, r, s) {
695
+ if (Array.isArray(r) ? r.find((l) => l.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
696
+ this._resolveField(e, t, s);
613
697
  return;
614
698
  }
615
699
  const n = e.component ? `${e.component}.${t}` : t;
616
- (Array.isArray(s) ? s.includes(n) : s === n) && this._resolveField(e, t, r);
700
+ (Array.isArray(r) ? r.includes(n) : r === n) && this._resolveField(e, t, s);
617
701
  }
618
702
  /**
619
703
  * Recursively traverses and resolves relations in the story content tree
@@ -621,67 +705,67 @@ var Se = class {
621
705
  * @param fields - The relation patterns to resolve
622
706
  * @param resolveId - The unique identifier for the current resolution context
623
707
  */
624
- iterateTree(e, t, s) {
625
- const r = (i, n = "") => {
708
+ iterateTree(e, t, r) {
709
+ const s = (i, n = "") => {
626
710
  if (!(!i || i._stopResolving)) {
627
- if (Array.isArray(i)) i.forEach((c, l) => r(c, `${n}[${l}]`));
628
- else if (typeof i == "object") for (const c in i) {
629
- const l = n ? `${n}.${c}` : c;
630
- (i.component && i._uid || i.type === "link") && (this._insertRelations(i, c, t, s), this._insertLinks(i, c, s)), r(i[c], l);
711
+ if (Array.isArray(i)) i.forEach((l, a) => s(l, `${n}[${a}]`));
712
+ else if (typeof i == "object") for (const l in i) {
713
+ const a = n ? `${n}.${l}` : l;
714
+ (i.component && i._uid || i.type === "link") && (this._insertRelations(i, l, t, r), this._insertLinks(i, l, r)), s(i[l], a);
631
715
  }
632
716
  }
633
717
  };
634
- r(e.content);
718
+ s(e.content);
635
719
  }
636
- async resolveLinks(e, t, s) {
637
- let r = [];
720
+ async resolveLinks(e, t, r) {
721
+ let s = [];
638
722
  if (e.link_uuids) {
639
- const i = e.link_uuids.length, n = [], c = 50;
640
- for (let l = 0; l < i; l += c) {
641
- const u = Math.min(i, l + c);
642
- n.push(e.link_uuids.slice(l, u));
723
+ const i = e.link_uuids.length, n = [], l = 50;
724
+ for (let a = 0; a < i; a += l) {
725
+ const u = Math.min(i, a + l);
726
+ n.push(e.link_uuids.slice(a, u));
643
727
  }
644
- for (let l = 0; l < n.length; l++)
728
+ for (let a = 0; a < n.length; a++)
645
729
  (await this.getStories({
646
- per_page: c,
730
+ per_page: l,
647
731
  language: t.language,
648
732
  version: t.version,
649
733
  starts_with: t.starts_with,
650
- by_uuids: n[l].join(",")
651
- })).data.stories.forEach((a) => {
652
- r.push(a);
734
+ by_uuids: n[a].join(",")
735
+ })).data.stories.forEach((c) => {
736
+ s.push(c);
653
737
  });
654
- } else r = e.links;
655
- r.forEach((i) => {
656
- this.links[s][i.uuid] = {
738
+ } else s = e.links;
739
+ s.forEach((i) => {
740
+ this.links[r][i.uuid] = {
657
741
  ...i,
658
742
  _stopResolving: !0
659
743
  };
660
744
  });
661
745
  }
662
- async resolveRelations(e, t, s) {
663
- let r = [];
746
+ async resolveRelations(e, t, r) {
747
+ let s = [];
664
748
  if (e.rel_uuids) {
665
- const i = e.rel_uuids.length, n = [], c = 50;
666
- for (let l = 0; l < i; l += c) {
667
- const u = Math.min(i, l + c);
668
- n.push(e.rel_uuids.slice(l, u));
749
+ const i = e.rel_uuids.length, n = [], l = 50;
750
+ for (let a = 0; a < i; a += l) {
751
+ const u = Math.min(i, a + l);
752
+ n.push(e.rel_uuids.slice(a, u));
669
753
  }
670
- for (let l = 0; l < n.length; l++)
754
+ for (let a = 0; a < n.length; a++)
671
755
  (await this.getStories({
672
- per_page: c,
756
+ per_page: l,
673
757
  language: t.language,
674
758
  version: t.version,
675
759
  starts_with: t.starts_with,
676
- by_uuids: n[l].join(","),
760
+ by_uuids: n[a].join(","),
677
761
  excluding_fields: t.excluding_fields
678
- })).data.stories.forEach((a) => {
679
- r.push(a);
762
+ })).data.stories.forEach((c) => {
763
+ s.push(c);
680
764
  });
681
- r.length > 0 && (e.rels = r, delete e.rel_uuids);
682
- } else r = e.rels;
683
- r && r.length > 0 && r.forEach((i) => {
684
- this.relations[s][i.uuid] = {
765
+ s.length > 0 && (e.rels = s, delete e.rel_uuids);
766
+ } else s = e.rels;
767
+ s && s.length > 0 && s.forEach((i) => {
768
+ this.relations[r][i.uuid] = {
685
769
  ...i,
686
770
  _stopResolving: !0
687
771
  };
@@ -696,84 +780,86 @@ var Se = class {
696
780
  * @returns Promise<void>
697
781
  *
698
782
  */
699
- async resolveStories(e, t, s) {
783
+ async resolveStories(e, t, r) {
700
784
  var i, n;
701
- let r = [];
702
- if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (r = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && [
785
+ let s = [];
786
+ if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (s = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && [
703
787
  "1",
704
788
  "story",
705
789
  "url",
706
790
  "link"
707
- ].includes(t.resolve_links) && ((i = e.links) != null && i.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations) for (const c in this.relations[s]) this.iterateTree(this.relations[s][c], r, s);
708
- e.story ? this.iterateTree(e.story, r, s) : e.stories.forEach((c) => {
709
- this.iterateTree(c, r, s);
710
- }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
791
+ ].includes(t.resolve_links) && ((i = e.links) != null && i.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations) for (const l in this.relations[r]) this.iterateTree(this.relations[r][l], s, r);
792
+ e.story ? this.iterateTree(e.story, s, r) : e.stories.forEach((l) => {
793
+ this.iterateTree(l, s, r);
794
+ }), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
711
795
  }
712
- async cacheResponse(e, t, s, r) {
713
- const i = j({
796
+ async cacheResponse(e, t, r, s) {
797
+ const i = F({
714
798
  url: e,
715
799
  params: t
716
800
  }), n = this.cacheProvider();
717
801
  if (t.version === "published" && e !== "/cdn/spaces/me") {
718
- const c = await n.get(i);
719
- if (c) return Promise.resolve(c);
802
+ const a = await n.get(i);
803
+ if (a) return Promise.resolve(a);
720
804
  }
721
- return new Promise(async (c, l) => {
722
- var u;
805
+ const l = N(e, t, this.rateLimitConfig);
806
+ return new Promise(async (a, u) => {
807
+ var c;
723
808
  try {
724
- const a = await this.throttle("get", e, t, r);
725
- if (a.status !== 200) return l(a);
726
- let g = {
727
- data: a.data,
728
- headers: a.headers
809
+ const f = await this.throttleManager.execute(l, "get", e, t, s);
810
+ if (f.status !== 200) return u(f);
811
+ let y = {
812
+ data: f.data,
813
+ headers: f.headers
729
814
  };
730
- if ((u = a.headers) != null && u["per-page"] && (g = Object.assign({}, g, {
731
- perPage: a.headers["per-page"] ? Number.parseInt(a.headers["per-page"]) : 0,
732
- total: a.headers["per-page"] ? Number.parseInt(a.headers.total) : 0
733
- })), g.data.story || g.data.stories) {
734
- const S = this.resolveCounter = ++this.resolveCounter % 1e3;
735
- await this.resolveStories(g.data, t, `${S}`), g = await this.processInlineAssets(g);
815
+ const A = Oe(f.headers);
816
+ if ((A == null ? void 0 : A.max) !== void 0 && (this.rateLimitConfig.serverHeadersRateLimit = A.max), (c = f.headers) != null && c["per-page"] && (y = Object.assign({}, y, {
817
+ perPage: f.headers["per-page"] ? Number.parseInt(f.headers["per-page"]) : 0,
818
+ total: f.headers["per-page"] ? Number.parseInt(f.headers.total) : 0
819
+ })), y.data.story || y.data.stories) {
820
+ const E = this.resolveCounter = ++this.resolveCounter % 1e3;
821
+ await this.resolveStories(y.data, t, `${E}`), y = await this.processInlineAssets(y);
736
822
  }
737
- t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, g);
738
- const p = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
739
- return t.token && g.data.cv && (p && E[t.token] && E[t.token] !== g.data.cv && await this.flushCache(), E[t.token] = g.data.cv), c(g);
740
- } catch (a) {
741
- if (a.response && a.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
742
- return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await be(this.retriesDelay), this.cacheResponse(e, t, s).then(c).catch(l);
743
- l(a);
823
+ t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, y);
824
+ const S = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
825
+ return t.token && y.data.cv && (S && L[t.token] && L[t.token] !== y.data.cv && await this.flushCache(), L[t.token] = y.data.cv), a(y);
826
+ } catch (f) {
827
+ if (f.response && f.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
828
+ return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await Re(this.retriesDelay), this.cacheResponse(e, t, r).then(a).catch(u);
829
+ u(f);
744
830
  }
745
831
  });
746
832
  }
747
- throttledRequest(e, t, s, r) {
748
- return this.client.setFetchOptions(r), this.client[e](t, s);
833
+ throttledRequest(e, t, r, s) {
834
+ return this.client.setFetchOptions(s), this.client[e](t, r);
749
835
  }
750
836
  cacheVersions() {
751
- return E;
837
+ return L;
752
838
  }
753
839
  cacheVersion() {
754
- return E[this.accessToken];
840
+ return L[this.accessToken];
755
841
  }
756
842
  setCacheVersion(e) {
757
- this.accessToken && (E[this.accessToken] = e);
843
+ this.accessToken && (L[this.accessToken] = e);
758
844
  }
759
845
  clearCacheVersion() {
760
- this.accessToken && (E[this.accessToken] = 0);
846
+ this.accessToken && (L[this.accessToken] = 0);
761
847
  }
762
848
  cacheProvider() {
763
849
  switch (this.cache.type) {
764
850
  case "memory":
765
851
  return {
766
852
  get(e) {
767
- return Promise.resolve(x[e]);
853
+ return Promise.resolve(H[e]);
768
854
  },
769
855
  getAll() {
770
- return Promise.resolve(x);
856
+ return Promise.resolve(H);
771
857
  },
772
858
  set(e, t) {
773
- return x[e] = t, Promise.resolve(void 0);
859
+ return H[e] = t, Promise.resolve(void 0);
774
860
  },
775
861
  flush() {
776
- return x = {}, Promise.resolve(void 0);
862
+ return H = {}, Promise.resolve(void 0);
777
863
  }
778
864
  };
779
865
  case "custom":
@@ -800,21 +886,21 @@ var Se = class {
800
886
  }
801
887
  async processInlineAssets(e) {
802
888
  if (!this.inlineAssets) return e;
803
- const t = (s) => {
804
- if (!s || typeof s != "object") return s;
805
- if (Array.isArray(s)) return s.map((i) => t(i));
806
- let r = { ...s };
807
- r.fieldtype === "asset" && Array.isArray(e.data.assets) && (r = {
808
- ...e.data.assets.find((i) => i.id === r.id),
809
- ...r
889
+ const t = (r) => {
890
+ if (!r || typeof r != "object") return r;
891
+ if (Array.isArray(r)) return r.map((i) => t(i));
892
+ let s = { ...r };
893
+ s.fieldtype === "asset" && Array.isArray(e.data.assets) && (s = {
894
+ ...e.data.assets.find((i) => i.id === s.id),
895
+ ...s
810
896
  });
811
- for (const i in r) typeof r[i] == "object" && (r[i] = t(r[i]));
812
- return r;
897
+ for (const i in s) typeof s[i] == "object" && (s[i] = t(s[i]));
898
+ return s;
813
899
  };
814
- return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((s) => (s.content = t(s.content), s))), e;
900
+ return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((r) => (r.content = t(r.content), r))), e;
815
901
  }
816
- }, Ae = Se;
817
- const Te = (e = {}) => {
902
+ }, $e = Ue;
903
+ const je = (e = {}) => {
818
904
  const { apiOptions: t } = e;
819
905
  if (!t || !t.accessToken) {
820
906
  console.error(
@@ -822,8 +908,8 @@ const Te = (e = {}) => {
822
908
  );
823
909
  return;
824
910
  }
825
- return { storyblokApi: new Ae(t) };
826
- }, Le = (e) => {
911
+ return { storyblokApi: new $e(t) };
912
+ }, Ge = (e) => {
827
913
  if (typeof e != "object" || typeof e._editable > "u")
828
914
  return {};
829
915
  try {
@@ -838,57 +924,57 @@ const Te = (e = {}) => {
838
924
  return {};
839
925
  }
840
926
  };
841
- let H = "https://app.storyblok.com/f/storyblok-v2-latest.js";
842
- const Ce = (e, t, s = {}) => {
843
- var l;
844
- const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
927
+ let q = "https://app.storyblok.com/f/storyblok-v2-latest.js";
928
+ const qe = (e, t, r = {}) => {
929
+ var a;
930
+ const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((a = window.location) == null ? void 0 : a.href).searchParams.get(
845
931
  "_storyblok"
846
- ), c = n !== null && +n === e;
847
- if (!(!i || !c)) {
932
+ ), l = n !== null && +n === e;
933
+ if (!(!i || !l)) {
848
934
  if (!e) {
849
935
  console.warn("Story ID is not defined. Please provide a valid ID.");
850
936
  return;
851
937
  }
852
938
  window.storyblokRegisterEvent(() => {
853
- new window.StoryblokBridge(s).on(["input", "published", "change"], (a) => {
854
- var g;
855
- a && (a.action === "input" && ((g = a.story) == null ? void 0 : g.id) === e ? t(a.story) : (a.action === "change" || a.action === "published") && a.storyId === e && window.location.reload());
939
+ new window.StoryblokBridge(r).on(["input", "published", "change"], (c) => {
940
+ var f;
941
+ c && (c.action === "input" && ((f = c.story) == null ? void 0 : f.id) === e ? t(c.story) : (c.action === "change" || c.action === "published") && c.storyId === e && window.location.reload());
856
942
  });
857
943
  });
858
944
  }
859
- }, Oe = (e = {}) => {
860
- var g, p;
945
+ }, Fe = (e = {}) => {
946
+ var f, y;
861
947
  const {
862
948
  bridge: t,
863
- accessToken: s,
864
- use: r = [],
949
+ accessToken: r,
950
+ use: s = [],
865
951
  apiOptions: i = {},
866
952
  bridgeUrl: n
867
953
  } = e;
868
- i.accessToken = i.accessToken || s;
869
- const c = { bridge: t, apiOptions: i };
870
- let l = {};
871
- r.forEach((S) => {
872
- l = { ...l, ...S(c) };
873
- }), n && (H = n);
874
- const a = !(typeof window > "u") && ((p = (g = window.location) == null ? void 0 : g.search) == null ? void 0 : p.includes("_storyblok_tk"));
875
- return t !== !1 && a && J(H), l;
954
+ i.accessToken = i.accessToken || r;
955
+ const l = { bridge: t, apiOptions: i };
956
+ let a = {};
957
+ s.forEach((A) => {
958
+ a = { ...a, ...A(l) };
959
+ }), n && (q = n);
960
+ const c = !(typeof window > "u") && ((y = (f = window.location) == null ? void 0 : f.search) == null ? void 0 : y.includes("_storyblok_tk"));
961
+ return t !== !1 && c && X(q), a;
876
962
  };
877
- function Pe(e, t) {
878
- return he(t).render(e);
963
+ function De(e, t) {
964
+ return me(t).render(e);
879
965
  }
880
- const xe = () => J(H);
966
+ const Be = () => X(q);
881
967
  export {
882
- R as BlockTypes,
883
- _ as MarkTypes,
884
- Ae as StoryblokClient,
885
- ne as TextTypes,
886
- Te as apiPlugin,
887
- xe as loadStoryblokBridge,
888
- Ce as registerStoryblokBridge,
889
- Pe as renderRichText,
890
- he as richTextResolver,
891
- Le as storyblokEditable,
892
- Oe as storyblokInit,
893
- Ce as useStoryblokBridge
968
+ v as BlockTypes,
969
+ w as MarkTypes,
970
+ $e as StoryblokClient,
971
+ he as TextTypes,
972
+ je as apiPlugin,
973
+ Be as loadStoryblokBridge,
974
+ qe as registerStoryblokBridge,
975
+ De as renderRichText,
976
+ me as richTextResolver,
977
+ Ge as storyblokEditable,
978
+ Fe as storyblokInit,
979
+ qe as useStoryblokBridge
894
980
  };