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