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