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