@storyblok/astro 4.0.4-next.5 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,76 +1,147 @@
1
- let _ = !1;
2
- const C = [], P = (o) => new Promise((e, t) => {
3
- if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
1
+ function E(r, t, e) {
2
+ const o = "virtual:storyblok-init", s = "\0" + o;
3
+ return {
4
+ name: "vite-plugin-storyblok-init",
5
+ async resolveId(a) {
6
+ if (a === o)
7
+ return s;
8
+ },
9
+ async load(a) {
10
+ if (a === s)
11
+ return `
12
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
13
+ const { storyblokApi } = storyblokInit({
14
+ accessToken: "${r}",
15
+ use: ${t ? "[]" : "[apiPlugin]"},
16
+ apiOptions: ${JSON.stringify(e)},
17
+ });
18
+ export const storyblokApiInstance = storyblokApi;
19
+ `;
20
+ }
21
+ };
22
+ }
23
+ const T = /[\p{Lu}]/u, x = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, C = /([\p{Alpha}\p{N}_]|$)/u, m = /[_.\- ]+/, S = new RegExp("^" + m.source), $ = new RegExp(m.source + C.source, "gu"), v = new RegExp("\\d+" + C.source, "gu"), j = (r, t, e, o) => {
24
+ let s = !1, a = !1, n = !1, c = !1;
25
+ for (let l = 0; l < r.length; l++) {
26
+ const i = r[l];
27
+ c = l > 2 ? r[l - 3] === "-" : !0, s && T.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), s = !1, n = a, a = !0, l++) : a && n && x.test(i) && (!c || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = a, a = !1, s = !0) : (s = t(i) === i && e(i) !== i, n = a, a = e(i) === i && t(i) !== i);
28
+ }
29
+ return r;
30
+ }, R = (r, t) => (k.lastIndex = 0, r.replaceAll(k, (e) => t(e))), O = (r, t) => ($.lastIndex = 0, v.lastIndex = 0, r.replaceAll(v, (e, o, s) => ["_", "-"].includes(r.charAt(s + e.length)) ? e : t(e)).replaceAll($, (e, o) => t(o)));
31
+ function I(r, t) {
32
+ if (!(typeof r == "string" || Array.isArray(r)))
33
+ throw new TypeError("Expected the input to be `string | string[]`");
34
+ if (t = {
35
+ pascalCase: !1,
36
+ preserveConsecutiveUppercase: !1,
37
+ ...t
38
+ }, Array.isArray(r) ? r = r.map((a) => a.trim()).filter((a) => a.length).join("-") : r = r.trim(), r.length === 0)
39
+ return "";
40
+ const e = t.locale === !1 ? (a) => a.toLowerCase() : (a) => a.toLocaleLowerCase(t.locale), o = t.locale === !1 ? (a) => a.toUpperCase() : (a) => a.toLocaleUpperCase(t.locale);
41
+ return r.length === 1 ? m.test(r) ? "" : t.pascalCase ? o(r) : e(r) : (r !== e(r) && (r = j(r, e, o, t.preserveConsecutiveUppercase)), r = r.replace(S, ""), r = t.preserveConsecutiveUppercase ? R(r, e) : e(r), t.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
42
+ }
43
+ function N(r, t, e, o) {
44
+ const s = "virtual:storyblok-components", a = "\0" + s;
45
+ return {
46
+ name: "vite-plugin-storyblok-components",
47
+ async resolveId(n) {
48
+ if (n === s)
49
+ return a;
50
+ },
51
+ async load(n) {
52
+ if (n === a) {
53
+ const c = [], l = [];
54
+ for await (const [g, f] of Object.entries(t)) {
55
+ const d = await this.resolve(
56
+ "/" + r + "/" + f + ".astro"
57
+ );
58
+ if (d)
59
+ c.push(`import ${I(g)} from "${d.id}"`);
60
+ else if (e)
61
+ l.push(g);
62
+ else
63
+ throw new Error(
64
+ `Component could not be found for blok "${g}"! Does "${"/" + r + "/" + f}.astro" exist?`
65
+ );
66
+ }
67
+ let i = "";
68
+ if (e)
69
+ if (i = ",FallbackComponent", o) {
70
+ const g = await this.resolve(
71
+ "/" + r + "/" + o + ".astro"
72
+ );
73
+ if (!g)
74
+ throw new Error(
75
+ `Custom fallback component could not be found. Does "${"/" + r + "/" + o}.astro" exist?`
76
+ );
77
+ c.push(
78
+ `import FallbackComponent from "${g.id}"`
79
+ );
80
+ } else
81
+ c.push(
82
+ "import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
83
+ );
84
+ if (Object.values(t).length)
85
+ return `${c.join(";")};export default {${Object.keys(t).filter((g) => !l.includes(g)).map((g) => I(g)).join(",")}${i}}`;
86
+ if (e)
87
+ return `${c[0]}; export default {${i.replace(",", "")}}`;
88
+ throw new Error(
89
+ `Currently, no Storyblok components are registered in astro.config.mjs.
90
+ Please register your components or enable the fallback component.
91
+ Detailed information can be found here: https://github.com/storyblok/storyblok-astro`
92
+ );
93
+ }
94
+ }
95
+ };
96
+ }
97
+ function L(r) {
98
+ const t = "virtual:storyblok-options", e = "\0" + t;
99
+ return {
100
+ name: "vite-plugin-storyblok-options",
101
+ async resolveId(o) {
102
+ if (o === t)
103
+ return e;
104
+ },
105
+ async load(o) {
106
+ if (o === e)
107
+ return `export default ${JSON.stringify(r)}`;
108
+ }
109
+ };
110
+ }
111
+ let w = !1;
112
+ const A = [], M = (r) => new Promise((t, e) => {
113
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
4
114
  if (window.location === window.parent.location) {
5
115
  console.warn("You are not in Draft Mode or in the Visual Editor.");
6
116
  return;
7
117
  }
8
- _ ? r() : C.push(r);
118
+ w ? s() : A.push(s);
9
119
  }, document.getElementById("storyblok-javascript-bridge")))
10
120
  return;
11
- const s = document.createElement("script");
12
- s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
13
- C.forEach((i) => i()), _ = !0, e(r);
14
- }, document.getElementsByTagName("head")[0].appendChild(s);
121
+ const o = document.createElement("script");
122
+ o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => e(s), o.onload = (s) => {
123
+ A.forEach((a) => a()), w = !0, t(s);
124
+ }, document.getElementsByTagName("head")[0].appendChild(o);
15
125
  });
16
- var M = Object.defineProperty, U = (o, e, t) => e in o ? M(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, u = (o, e, t) => (U(o, typeof e != "symbol" ? e + "" : e, t), t);
17
- function A(o) {
18
- return !(o !== o || o === 1 / 0 || o === -1 / 0);
19
- }
20
- function z(o, e, t) {
21
- if (!A(e))
22
- throw new TypeError("Expected `limit` to be a finite number");
23
- if (!A(t))
24
- throw new TypeError("Expected `interval` to be a finite number");
25
- const s = [];
26
- let r = [], i = 0;
27
- const n = function() {
28
- i++;
29
- const a = setTimeout(function() {
30
- i--, s.length > 0 && n(), r = r.filter(function(h) {
31
- return h !== a;
32
- });
33
- }, t);
34
- r.indexOf(a) < 0 && r.push(a);
35
- const l = s.shift();
36
- l.resolve(o.apply(l.self, l.args));
37
- }, c = function(...a) {
38
- const l = this;
39
- return new Promise(function(h, p) {
40
- s.push({
41
- resolve: h,
42
- reject: p,
43
- args: a,
44
- self: l
45
- }), i < e && n();
46
- });
47
- };
48
- return c.abort = function() {
49
- r.forEach(clearTimeout), r = [], s.forEach(function(a) {
50
- a.reject(function() {
51
- Error.call(this, "Throttled function aborted"), this.name = "AbortError";
52
- });
53
- }), s.length = 0;
54
- }, c;
55
- }
56
- class b {
126
+ var P = Object.defineProperty, _ = (r, t, e) => t in r ? P(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, p = (r, t, e) => (_(r, typeof t != "symbol" ? t + "" : t, e), e);
127
+ class z {
57
128
  constructor() {
58
- u(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), u(this, "getOptionsPage", (e, t = 25, s = 1) => ({
59
- ...e,
60
- per_page: t,
61
- page: s
62
- })), u(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), u(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), u(this, "range", (e = 0, t = e) => {
63
- const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
64
- return this.arrayFrom(s, (i, n) => n * r + e);
65
- }), u(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), u(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), u(this, "escapeHTML", function(e) {
66
- const t = {
129
+ p(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), p(this, "getOptionsPage", (t, e = 25, o = 1) => ({
130
+ ...t,
131
+ per_page: e,
132
+ page: o
133
+ })), p(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), p(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), p(this, "range", (t = 0, e = t) => {
134
+ const o = Math.abs(e - t) || 0, s = t < e ? 1 : -1;
135
+ return this.arrayFrom(o, (a, n) => n * s + t);
136
+ }), p(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), p(this, "flatMap", (t = [], e) => t.map(e).reduce((o, s) => [...o, ...s], [])), p(this, "escapeHTML", function(t) {
137
+ const e = {
67
138
  "&": "&amp;",
68
139
  "<": "&lt;",
69
140
  ">": "&gt;",
70
141
  '"': "&quot;",
71
142
  "'": "&#39;"
72
- }, s = /[&<>"']/g, r = RegExp(s.source);
73
- return e && r.test(e) ? e.replace(s, (i) => t[i]) : e;
143
+ }, o = /[&<>"']/g, s = RegExp(o.source);
144
+ return t && s.test(t) ? t.replace(o, (a) => e[a]) : t;
74
145
  });
75
146
  }
76
147
  /**
@@ -80,223 +151,223 @@ class b {
80
151
  * @param {Boolean} isArray
81
152
  * @return {String} Stringified object
82
153
  */
83
- stringify(e, t, s) {
84
- const r = [];
85
- for (const i in e) {
86
- if (!Object.prototype.hasOwnProperty.call(e, i))
154
+ stringify(t, e, o) {
155
+ const s = [];
156
+ for (const a in t) {
157
+ if (!Object.prototype.hasOwnProperty.call(t, a))
87
158
  continue;
88
- const n = e[i], c = s ? "" : encodeURIComponent(i);
89
- let a;
90
- typeof n == "object" ? a = this.stringify(
159
+ const n = t[a], c = o ? "" : encodeURIComponent(a);
160
+ let l;
161
+ typeof n == "object" ? l = this.stringify(
91
162
  n,
92
- t ? t + encodeURIComponent("[" + c + "]") : c,
163
+ e ? e + encodeURIComponent("[" + c + "]") : c,
93
164
  Array.isArray(n)
94
- ) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), r.push(a);
165
+ ) : l = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), s.push(l);
95
166
  }
96
- return r.join("&");
167
+ return s.join("&");
97
168
  }
98
169
  /**
99
170
  * @method getRegionURL
100
171
  * @param {String} regionCode region code, could be eu, us, cn, ap or ca
101
172
  * @return {String} The base URL of the region
102
173
  */
103
- getRegionURL(e) {
104
- const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
105
- switch (e) {
174
+ getRegionURL(t) {
175
+ const e = "api.storyblok.com", o = "api-us.storyblok.com", s = "app.storyblokchina.cn", a = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
176
+ switch (t) {
106
177
  case "us":
107
- return s;
178
+ return o;
108
179
  case "cn":
109
- return r;
180
+ return s;
110
181
  case "ap":
111
- return i;
182
+ return a;
112
183
  case "ca":
113
184
  return n;
114
185
  default:
115
- return t;
186
+ return e;
116
187
  }
117
188
  }
118
189
  }
119
- const F = function(o, e) {
120
- const t = {};
121
- for (const s in o) {
122
- const r = o[s];
123
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
124
- }
125
- return t;
126
- }, H = (o) => o === "email", q = () => ({
190
+ const U = function(r, t) {
191
+ const e = {};
192
+ for (const o in r) {
193
+ const s = r[o];
194
+ t.indexOf(o) > -1 && s !== null && (e[o] = s);
195
+ }
196
+ return e;
197
+ }, D = (r) => r === "email", B = () => ({
127
198
  singleTag: "hr"
128
- }), B = () => ({
199
+ }), q = () => ({
129
200
  tag: "blockquote"
130
- }), D = () => ({
201
+ }), F = () => ({
131
202
  tag: "ul"
132
- }), V = (o) => ({
203
+ }), J = (r) => ({
133
204
  tag: [
134
205
  "pre",
135
206
  {
136
207
  tag: "code",
137
- attrs: o.attrs
208
+ attrs: r.attrs
138
209
  }
139
210
  ]
140
- }), J = () => ({
211
+ }), K = () => ({
141
212
  singleTag: "br"
142
- }), K = (o) => ({
143
- tag: `h${o.attrs.level}`
144
- }), G = (o) => ({
213
+ }), V = (r) => ({
214
+ tag: `h${r.attrs.level}`
215
+ }), H = (r) => ({
145
216
  singleTag: [
146
217
  {
147
218
  tag: "img",
148
- attrs: F(o.attrs, ["src", "alt", "title"])
219
+ attrs: U(r.attrs, ["src", "alt", "title"])
149
220
  }
150
221
  ]
151
- }), W = () => ({
222
+ }), G = () => ({
152
223
  tag: "li"
153
- }), Y = () => ({
224
+ }), W = () => ({
154
225
  tag: "ol"
155
- }), Q = () => ({
226
+ }), Y = () => ({
156
227
  tag: "p"
157
- }), X = (o) => ({
228
+ }), Q = (r) => ({
158
229
  tag: [
159
230
  {
160
231
  tag: "span",
161
232
  attrs: {
162
233
  "data-type": "emoji",
163
- "data-name": o.attrs.name,
164
- emoji: o.attrs.emoji
234
+ "data-name": r.attrs.name,
235
+ emoji: r.attrs.emoji
165
236
  }
166
237
  }
167
238
  ]
168
- }), Z = () => ({
239
+ }), X = () => ({
169
240
  tag: "b"
170
- }), ee = () => ({
241
+ }), Z = () => ({
171
242
  tag: "s"
172
- }), te = () => ({
243
+ }), ee = () => ({
173
244
  tag: "u"
174
- }), se = () => ({
245
+ }), te = () => ({
175
246
  tag: "strong"
176
247
  }), re = () => ({
177
248
  tag: "code"
178
249
  }), oe = () => ({
179
250
  tag: "i"
180
- }), ie = (o) => {
181
- if (!o.attrs)
251
+ }), se = (r) => {
252
+ if (!r.attrs)
182
253
  return {
183
254
  tag: ""
184
255
  };
185
- const e = new b().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
186
- if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), H(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
187
- for (const r in t.custom)
188
- t[r] = t.custom[r];
189
- delete t.custom;
256
+ const t = new z().escapeHTML, e = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
257
+ if (delete e.linktype, e.href && (e.href = t(r.attrs.href || "")), D(o) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
258
+ for (const s in e.custom)
259
+ e[s] = e.custom[s];
260
+ delete e.custom;
190
261
  }
191
262
  return {
192
263
  tag: [
193
264
  {
194
265
  tag: "a",
195
- attrs: t
266
+ attrs: e
196
267
  }
197
268
  ]
198
269
  };
199
- }, ne = (o) => ({
270
+ }, ae = (r) => ({
200
271
  tag: [
201
272
  {
202
273
  tag: "span",
203
- attrs: o.attrs
274
+ attrs: r.attrs
204
275
  }
205
276
  ]
206
- }), ae = () => ({
277
+ }), ne = () => ({
207
278
  tag: "sub"
208
279
  }), le = () => ({
209
280
  tag: "sup"
210
- }), ce = (o) => ({
281
+ }), ie = (r) => ({
211
282
  tag: [
212
283
  {
213
284
  tag: "span",
214
- attrs: o.attrs
285
+ attrs: r.attrs
215
286
  }
216
287
  ]
217
- }), he = (o) => {
218
- var e;
219
- return (e = o.attrs) != null && e.color ? {
288
+ }), ce = (r) => {
289
+ var t;
290
+ return (t = r.attrs) != null && t.color ? {
220
291
  tag: [
221
292
  {
222
293
  tag: "span",
223
294
  attrs: {
224
- style: `background-color:${o.attrs.color};`
295
+ style: `background-color:${r.attrs.color};`
225
296
  }
226
297
  }
227
298
  ]
228
299
  } : {
229
300
  tag: ""
230
301
  };
231
- }, ue = (o) => {
232
- var e;
233
- return (e = o.attrs) != null && e.color ? {
302
+ }, ge = (r) => {
303
+ var t;
304
+ return (t = r.attrs) != null && t.color ? {
234
305
  tag: [
235
306
  {
236
307
  tag: "span",
237
308
  attrs: {
238
- style: `color:${o.attrs.color}`
309
+ style: `color:${r.attrs.color}`
239
310
  }
240
311
  }
241
312
  ]
242
313
  } : {
243
314
  tag: ""
244
315
  };
245
- }, pe = {
316
+ }, ue = {
246
317
  nodes: {
247
- horizontal_rule: q,
248
- blockquote: B,
249
- bullet_list: D,
250
- code_block: V,
251
- hard_break: J,
252
- heading: K,
253
- image: G,
254
- list_item: W,
255
- ordered_list: Y,
256
- paragraph: Q,
257
- emoji: X
318
+ horizontal_rule: B,
319
+ blockquote: q,
320
+ bullet_list: F,
321
+ code_block: J,
322
+ hard_break: K,
323
+ heading: V,
324
+ image: H,
325
+ list_item: G,
326
+ ordered_list: W,
327
+ paragraph: Y,
328
+ emoji: Q
258
329
  },
259
330
  marks: {
260
- bold: Z,
261
- strike: ee,
262
- underline: te,
263
- strong: se,
331
+ bold: X,
332
+ strike: Z,
333
+ underline: ee,
334
+ strong: te,
264
335
  code: re,
265
336
  italic: oe,
266
- link: ie,
267
- styled: ne,
268
- subscript: ae,
337
+ link: se,
338
+ styled: ae,
339
+ subscript: ne,
269
340
  superscript: le,
270
- anchor: ce,
271
- highlight: he,
272
- textStyle: ue
341
+ anchor: ie,
342
+ highlight: ce,
343
+ textStyle: ge
273
344
  }
274
- }, ge = function(o) {
275
- const e = {
345
+ }, pe = function(r) {
346
+ const t = {
276
347
  "&": "&amp;",
277
348
  "<": "&lt;",
278
349
  ">": "&gt;",
279
350
  '"': "&quot;",
280
351
  "'": "&#39;"
281
- }, t = /[&<>"']/g, s = RegExp(t.source);
282
- return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
352
+ }, e = /[&<>"']/g, o = RegExp(e.source);
353
+ return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
283
354
  };
284
- class k {
285
- constructor(e) {
286
- u(this, "marks"), u(this, "nodes"), e || (e = pe), this.marks = e.marks || [], this.nodes = e.nodes || [];
287
- }
288
- addNode(e, t) {
289
- this.nodes[e] = t;
290
- }
291
- addMark(e, t) {
292
- this.marks[e] = t;
293
- }
294
- render(e, t = { optimizeImages: !1 }) {
295
- if (e && e.content && Array.isArray(e.content)) {
296
- let s = "";
297
- return e.content.forEach((r) => {
298
- s += this.renderNode(r);
299
- }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
355
+ class fe {
356
+ constructor(t) {
357
+ p(this, "marks"), p(this, "nodes"), t || (t = ue), this.marks = t.marks || [], this.nodes = t.nodes || [];
358
+ }
359
+ addNode(t, e) {
360
+ this.nodes[t] = e;
361
+ }
362
+ addMark(t, e) {
363
+ this.marks[t] = e;
364
+ }
365
+ render(t, e = { optimizeImages: !1 }) {
366
+ if (t && t.content && Array.isArray(t.content)) {
367
+ let o = "";
368
+ return t.content.forEach((s) => {
369
+ o += this.renderNode(s);
370
+ }), e.optimizeImages ? this.optimizeImages(o, e.optimizeImages) : o;
300
371
  }
301
372
  return console.warn(
302
373
  `The render method must receive an Object with a "content" field.
@@ -325,731 +396,201 @@ class k {
325
396
  }`
326
397
  ), "";
327
398
  }
328
- optimizeImages(e, t) {
329
- let s = 0, r = 0, i = "", n = "";
330
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
331
- const c = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
332
- return e = e.replace(
399
+ optimizeImages(t, e) {
400
+ let o = 0, s = 0, a = "", n = "";
401
+ typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (a += `width="${e.width}" `, o = e.width), typeof e.height == "number" && e.height > 0 && (a += `height="${e.height}" `, s = e.height), (e.loading === "lazy" || e.loading === "eager") && (a += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (a += `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-Fa-f]{6}/g) || 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))), a.length > 0 && (t = t.replace(/<img/g, `<img ${a.trim()}`));
402
+ const c = o > 0 || s > 0 || n.length > 0 ? `${o}x${s}${n}` : "";
403
+ return t = t.replace(
333
404
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
334
405
  `a.storyblok.com/f/$1/$2.$3/m/${c}`
335
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
336
- var l, h;
337
- const p = a.match(
406
+ ), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
407
+ var i, g;
408
+ const f = l.match(
338
409
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
339
410
  );
340
- if (p && p.length > 0) {
341
- const g = {
342
- srcset: (l = t.srcset) == null ? void 0 : l.map((d) => {
343
- if (typeof d == "number")
344
- return `//${p}/m/${d}x0${n} ${d}w`;
345
- if (typeof d == "object" && d.length === 2) {
346
- let v = 0, I = 0;
347
- return typeof d[0] == "number" && (v = d[0]), typeof d[1] == "number" && (I = d[1]), `//${p}/m/${v}x${I}${n} ${v}w`;
411
+ if (f && f.length > 0) {
412
+ const d = {
413
+ srcset: (i = e.srcset) == null ? void 0 : i.map((u) => {
414
+ if (typeof u == "number")
415
+ return `//${f}/m/${u}x0${n} ${u}w`;
416
+ if (typeof u == "object" && u.length === 2) {
417
+ let b = 0, y = 0;
418
+ return typeof u[0] == "number" && (b = u[0]), typeof u[1] == "number" && (y = u[1]), `//${f}/m/${b}x${y}${n} ${b}w`;
348
419
  }
349
420
  }).join(", "),
350
- sizes: (h = t.sizes) == null ? void 0 : h.map((d) => d).join(", ")
421
+ sizes: (g = e.sizes) == null ? void 0 : g.map((u) => u).join(", ")
351
422
  };
352
- let f = "";
353
- return g.srcset && (f += `srcset="${g.srcset}" `), g.sizes && (f += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
423
+ let h = "";
424
+ return d.srcset && (h += `srcset="${d.srcset}" `), d.sizes && (h += `sizes="${d.sizes}" `), l.replace(/<img/g, `<img ${h.trim()}`);
354
425
  }
355
- return a;
356
- })), e;
357
- }
358
- renderNode(e) {
359
- const t = [];
360
- e.marks && e.marks.forEach((r) => {
361
- const i = this.getMatchingMark(r);
362
- i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
426
+ return l;
427
+ })), t;
428
+ }
429
+ renderNode(t) {
430
+ const e = [];
431
+ t.marks && t.marks.forEach((s) => {
432
+ const a = this.getMatchingMark(s);
433
+ a && a.tag !== "" && e.push(this.renderOpeningTag(a.tag));
363
434
  });
364
- const s = this.getMatchingNode(e);
365
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
366
- t.push(this.renderNode(r));
367
- }) : e.text ? t.push(ge(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
368
- const i = this.getMatchingMark(r);
369
- i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
370
- }), t.join("");
371
- }
372
- renderTag(e, t) {
373
- return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
374
- if (s.constructor === String)
375
- return `<${s}${t}>`;
435
+ const o = this.getMatchingNode(t);
436
+ return o && o.tag && e.push(this.renderOpeningTag(o.tag)), t.content ? t.content.forEach((s) => {
437
+ e.push(this.renderNode(s));
438
+ }) : t.text ? e.push(pe(t.text)) : o && o.singleTag ? e.push(this.renderTag(o.singleTag, " /")) : o && o.html ? e.push(o.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), o && o.tag && e.push(this.renderClosingTag(o.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
439
+ const a = this.getMatchingMark(s);
440
+ a && a.tag !== "" && e.push(this.renderClosingTag(a.tag));
441
+ }), e.join("");
442
+ }
443
+ renderTag(t, e) {
444
+ return t.constructor === String ? `<${t}${e}>` : t.map((o) => {
445
+ if (o.constructor === String)
446
+ return `<${o}${e}>`;
376
447
  {
377
- let r = `<${s.tag}`;
378
- if (s.attrs)
379
- for (const i in s.attrs) {
380
- const n = s.attrs[i];
381
- n !== null && (r += ` ${i}="${n}"`);
448
+ let s = `<${o.tag}`;
449
+ if (o.attrs)
450
+ for (const a in o.attrs) {
451
+ const n = o.attrs[a];
452
+ n !== null && (s += ` ${a}="${n}"`);
382
453
  }
383
- return `${r}${t}>`;
454
+ return `${s}${e}>`;
384
455
  }
385
456
  }).join("");
386
457
  }
387
- renderOpeningTag(e) {
388
- return this.renderTag(e, "");
458
+ renderOpeningTag(t) {
459
+ return this.renderTag(t, "");
389
460
  }
390
- renderClosingTag(e) {
391
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
461
+ renderClosingTag(t) {
462
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
392
463
  }
393
- getMatchingNode(e) {
394
- const t = this.nodes[e.type];
395
- if (typeof t == "function")
396
- return t(e);
464
+ getMatchingNode(t) {
465
+ const e = this.nodes[t.type];
466
+ if (typeof e == "function")
467
+ return e(t);
397
468
  }
398
- getMatchingMark(e) {
399
- const t = this.marks[e.type];
400
- if (typeof t == "function")
401
- return t(e);
469
+ getMatchingMark(t) {
470
+ const e = this.marks[t.type];
471
+ if (typeof e == "function")
472
+ return e(t);
402
473
  }
403
- renderEmoji(e) {
404
- if (e.attrs.emoji)
405
- return e.attrs.emoji;
406
- const t = [
474
+ renderEmoji(t) {
475
+ if (t.attrs.emoji)
476
+ return t.attrs.emoji;
477
+ const e = [
407
478
  {
408
479
  tag: "img",
409
480
  attrs: {
410
- src: e.attrs.fallbackImage,
481
+ src: t.attrs.fallbackImage,
411
482
  draggable: "false",
412
483
  loading: "lazy",
413
484
  align: "absmiddle"
414
485
  }
415
486
  }
416
487
  ];
417
- return this.renderTag(t, " /");
488
+ return this.renderTag(e, " /");
418
489
  }
419
490
  }
420
- class de {
421
- constructor(e) {
422
- u(this, "baseURL"), u(this, "timeout"), u(this, "headers"), u(this, "responseInterceptor"), u(this, "fetch"), u(this, "ejectInterceptor"), u(this, "url"), u(this, "parameters"), u(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 = {};
423
- }
424
- /**
425
- *
426
- * @param url string
427
- * @param params ISbStoriesParams
428
- * @returns Promise<ISbResponse | Error>
429
- */
430
- get(e, t) {
431
- return this.url = e, this.parameters = t, this._methodHandler("get");
432
- }
433
- post(e, t) {
434
- return this.url = e, this.parameters = t, this._methodHandler("post");
435
- }
436
- put(e, t) {
437
- return this.url = e, this.parameters = t, this._methodHandler("put");
438
- }
439
- delete(e, t) {
440
- return this.url = e, this.parameters = t, this._methodHandler("delete");
441
- }
442
- async _responseHandler(e) {
443
- const t = [], s = {
444
- data: {},
445
- headers: {},
446
- status: 0,
447
- statusText: ""
448
- };
449
- e.status !== 204 && await e.json().then((r) => {
450
- s.data = r;
451
- });
452
- for (const r of e.headers.entries())
453
- t[r[0]] = r[1];
454
- return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
455
- }
456
- async _methodHandler(e) {
457
- let t = `${this.baseURL}${this.url}`, s = null;
458
- if (e === "get") {
459
- const a = new b();
460
- t = `${this.baseURL}${this.url}?${a.stringify(
461
- this.parameters
462
- )}`;
463
- } else
464
- s = JSON.stringify(this.parameters);
465
- const r = new URL(t), i = new AbortController(), { signal: n } = i;
466
- let c;
467
- this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
468
- try {
469
- const a = await fetch(`${r}`, {
470
- method: e,
471
- headers: this.headers,
472
- body: s,
473
- signal: n,
474
- ...this.fetchOptions
475
- });
476
- this.timeout && clearTimeout(c);
477
- const l = await this._responseHandler(
478
- a
479
- );
480
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
481
- } catch (a) {
482
- return {
483
- message: a
484
- };
485
- }
486
- }
487
- setFetchOptions(e = {}) {
488
- Object.keys(e).length > 0 && "method" in e && delete e.method, this.fetchOptions = { ...e };
489
- }
490
- eject() {
491
- this.ejectInterceptor = !0;
492
- }
493
- _statusHandler(e) {
494
- const t = /20[0-6]/g;
495
- return new Promise((s, r) => {
496
- if (t.test(`${e.status}`))
497
- return s(e);
498
- const i = {
499
- message: e.statusText,
500
- status: e.status,
501
- response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
502
- };
503
- r(i);
504
- });
505
- }
506
- }
507
- var fe = { npm_package_version: "6.6.3" };
508
- const S = "SB-Agent", w = {
509
- defaultAgentName: "SB-JS-CLIENT",
510
- defaultAgentVersion: "SB-Agent-Version",
511
- packageVersion: fe.npm_package_version
512
- };
513
- let y = {};
514
- const m = {};
515
- class me {
516
- /**
517
- *
518
- * @param config ISbConfig interface
519
- * @param endpoint string, optional
520
- */
521
- constructor(e, t) {
522
- u(this, "client"), u(this, "maxRetries"), u(this, "throttle"), u(this, "accessToken"), u(this, "cache"), u(this, "helpers"), u(this, "resolveCounter"), u(this, "relations"), u(this, "links"), u(this, "richTextResolver"), u(this, "resolveNestedRelations"), u(this, "stringifiedStoriesCache");
523
- let s = e.endpoint || t;
524
- const r = new b().getRegionURL, i = e.https === !1 ? "http" : "https";
525
- e.oauthToken ? s = `${i}://${r(e.region)}/v1` : s = `${i}://${r(e.region)}/v2`;
526
- const n = new Headers();
527
- if (n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), e.headers)
528
- for (const a in e.headers)
529
- n.set(a, e.headers[a]);
530
- n.has(S) || (n.set(S, w.defaultAgentName), n.set(
531
- w.defaultAgentVersion,
532
- w.packageVersion
533
- ));
534
- let c = 5;
535
- e.oauthToken && (n.set("Authorization", e.oauthToken), c = 3), e.rateLimit && (c = e.rateLimit), e.richTextSchema ? this.richTextResolver = new k(e.richTextSchema) : this.richTextResolver = new k(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = z(this.throttledRequest, c, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new de({
536
- baseURL: s,
537
- timeout: e.timeout || 0,
538
- headers: n,
539
- responseInterceptor: e.responseInterceptor,
540
- fetch: e.fetch
541
- });
542
- }
543
- setComponentResolver(e) {
544
- this.richTextResolver.addNode("blok", (t) => {
545
- let s = "";
546
- return t.attrs.body && t.attrs.body.forEach((r) => {
547
- s += e(r.component, r);
548
- }), {
549
- html: s
550
- };
551
- });
552
- }
553
- parseParams(e) {
554
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = m[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
555
- }
556
- factoryParamOptions(e, t) {
557
- return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
558
- }
559
- makeRequest(e, t, s, r) {
560
- const i = this.factoryParamOptions(
561
- e,
562
- this.helpers.getOptionsPage(t, s, r)
563
- );
564
- return this.cacheResponse(e, i);
565
- }
566
- get(e, t, s) {
567
- t || (t = {});
568
- const r = `/${e}`, i = this.factoryParamOptions(r, t);
569
- return this.client.setFetchOptions(s), this.cacheResponse(r, i);
570
- }
571
- async getAll(e, t, s, r) {
572
- const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`, c = n.split("/"), a = s || c[c.length - 1], l = 1, h = await this.makeRequest(n, t, i, l), p = h.total ? Math.ceil(h.total / i) : 1;
573
- this.client.setFetchOptions(r);
574
- const g = await this.helpers.asyncMap(
575
- this.helpers.range(l, p),
576
- (f) => this.makeRequest(n, t, i, f + 1)
577
- );
578
- return this.helpers.flatMap(
579
- [h, ...g],
580
- (f) => Object.values(f.data[a])
581
- );
582
- }
583
- post(e, t, s) {
584
- const r = `/${e}`;
585
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, t));
586
- }
587
- put(e, t, s) {
588
- const r = `/${e}`;
589
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, t));
590
- }
591
- delete(e, t, s) {
592
- const r = `/${e}`;
593
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, t));
594
- }
595
- getStories(e, t) {
596
- return this.client.setFetchOptions(t), this.get("cdn/stories", e);
597
- }
598
- getStory(e, t, s) {
599
- return this.client.setFetchOptions(s), this.get(`cdn/stories/${e}`, t);
600
- }
601
- getToken() {
602
- return this.accessToken;
603
- }
604
- ejectInterceptor() {
605
- this.client.eject();
606
- }
607
- _cleanCopy(e) {
608
- return JSON.parse(JSON.stringify(e));
609
- }
610
- _insertLinks(e, t, s) {
611
- const r = e[t];
612
- r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
613
- }
614
- /**
615
- *
616
- * @param resolveId A counter number as a string
617
- * @param uuid The uuid of the story
618
- * @returns string | object
619
- */
620
- getStoryReference(e, t) {
621
- return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
622
- this.relations[e][t]
623
- )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
624
- }
625
- _insertRelations(e, t, s, r) {
626
- s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
627
- }
628
- iterateTree(e, t, s) {
629
- const r = (i) => {
630
- if (i != null) {
631
- if (i.constructor === Array)
632
- for (let n = 0; n < i.length; n++)
633
- r(i[n]);
634
- else if (i.constructor === Object) {
635
- if (i._stopResolving)
636
- return;
637
- for (const n in i)
638
- (i.component && i._uid || i.type === "link") && (this._insertRelations(
639
- i,
640
- n,
641
- t,
642
- s
643
- ), this._insertLinks(
644
- i,
645
- n,
646
- s
647
- )), r(i[n]);
648
- }
649
- }
650
- };
651
- r(e.content);
652
- }
653
- async resolveLinks(e, t, s) {
654
- let r = [];
655
- if (e.link_uuids) {
656
- const i = e.link_uuids.length, n = [], c = 50;
657
- for (let a = 0; a < i; a += c) {
658
- const l = Math.min(i, a + c);
659
- n.push(e.link_uuids.slice(a, l));
660
- }
661
- for (let a = 0; a < n.length; a++)
662
- (await this.getStories({
663
- per_page: c,
664
- language: t.language,
665
- version: t.version,
666
- by_uuids: n[a].join(",")
667
- })).data.stories.forEach(
668
- (l) => {
669
- r.push(l);
670
- }
671
- );
672
- } else
673
- r = e.links;
674
- r.forEach((i) => {
675
- this.links[s][i.uuid] = {
676
- ...i,
677
- _stopResolving: !0
678
- };
679
- });
680
- }
681
- async resolveRelations(e, t, s) {
682
- let r = [];
683
- if (e.rel_uuids) {
684
- const i = e.rel_uuids.length, n = [], c = 50;
685
- for (let a = 0; a < i; a += c) {
686
- const l = Math.min(i, a + c);
687
- n.push(e.rel_uuids.slice(a, l));
688
- }
689
- for (let a = 0; a < n.length; a++)
690
- (await this.getStories({
691
- per_page: c,
692
- language: t.language,
693
- version: t.version,
694
- by_uuids: n[a].join(","),
695
- excluding_fields: t.excluding_fields
696
- })).data.stories.forEach((l) => {
697
- r.push(l);
698
- });
699
- } else
700
- r = e.rels;
701
- r && r.length > 0 && r.forEach((i) => {
702
- this.relations[s][i.uuid] = {
703
- ...i,
704
- _stopResolving: !0
705
- };
706
- });
707
- }
708
- /**
709
- *
710
- * @param responseData
711
- * @param params
712
- * @param resolveId
713
- * @description Resolves the relations and links of the stories
714
- * @returns Promise<void>
715
- *
716
- */
717
- async resolveStories(e, t, s) {
718
- var r, i;
719
- let n = [];
720
- if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
721
- for (const c in this.relations[s])
722
- this.iterateTree(
723
- this.relations[s][c],
724
- n,
725
- s
726
- );
727
- e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((c) => {
728
- this.iterateTree(c, n, s);
729
- }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
730
- }
731
- async cacheResponse(e, t, s) {
732
- (typeof s > "u" || !s) && (s = 0);
733
- const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
734
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
735
- const n = await i.get(r);
736
- if (n)
737
- return Promise.resolve(n);
738
- }
739
- return new Promise(async (n, c) => {
740
- var a;
741
- try {
742
- const l = await this.throttle("get", e, t);
743
- if (l.status !== 200)
744
- return c(l);
745
- let h = { data: l.data, headers: l.headers };
746
- if ((a = l.headers) != null && a["per-page"] && (h = Object.assign({}, h, {
747
- perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
748
- total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
749
- })), h.data.story || h.data.stories) {
750
- const p = this.resolveCounter = ++this.resolveCounter % 1e3;
751
- await this.resolveStories(h.data, t, `${p}`);
752
- }
753
- return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, h), h.data.cv && t.token && (t.version === "draft" && m[t.token] != h.data.cv && await this.flushCache(), m[t.token] = t.cv ? t.cv : h.data.cv), n(h);
754
- } catch (l) {
755
- if (l.response && l.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
756
- return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(n).catch(c);
757
- c(l);
758
- }
759
- });
760
- }
761
- throttledRequest(e, t, s) {
762
- return this.client[e](t, s);
763
- }
764
- cacheVersions() {
765
- return m;
766
- }
767
- cacheVersion() {
768
- return m[this.accessToken];
769
- }
770
- setCacheVersion(e) {
771
- this.accessToken && (m[this.accessToken] = e);
772
- }
773
- cacheProvider() {
774
- switch (this.cache.type) {
775
- case "memory":
776
- return {
777
- get(e) {
778
- return Promise.resolve(y[e]);
779
- },
780
- getAll() {
781
- return Promise.resolve(y);
782
- },
783
- set(e, t) {
784
- return y[e] = t, Promise.resolve(void 0);
785
- },
786
- flush() {
787
- return y = {}, Promise.resolve(void 0);
788
- }
789
- };
790
- case "custom":
791
- if (this.cache.custom)
792
- return this.cache.custom;
793
- default:
794
- return {
795
- get() {
796
- return Promise.resolve();
797
- },
798
- getAll() {
799
- return Promise.resolve(void 0);
800
- },
801
- set() {
802
- return Promise.resolve(void 0);
803
- },
804
- flush() {
805
- return Promise.resolve(void 0);
806
- }
807
- };
808
- }
809
- }
810
- async flushCache() {
811
- return await this.cacheProvider().flush(), this;
812
- }
813
- }
814
- const ye = (o = {}) => {
815
- const { apiOptions: e } = o;
816
- if (!e.accessToken) {
817
- console.error(
818
- "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
819
- );
820
- return;
821
- }
822
- return { storyblokApi: new me(e) };
823
- }, xe = (o) => {
824
- if (typeof o != "object" || typeof o._editable > "u")
491
+ const ke = (r) => {
492
+ if (typeof r != "object" || typeof r._editable > "u")
825
493
  return {};
826
494
  try {
827
- const e = JSON.parse(
828
- o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
495
+ const t = JSON.parse(
496
+ r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
829
497
  );
830
- return e ? {
831
- "data-blok-c": JSON.stringify(e),
832
- "data-blok-uid": e.id + "-" + e.uid
498
+ return t ? {
499
+ "data-blok-c": JSON.stringify(t),
500
+ "data-blok-uid": t.id + "-" + t.uid
833
501
  } : {};
834
502
  } catch {
835
503
  return {};
836
504
  }
837
505
  };
838
- let $, T = "https://app.storyblok.com/f/storyblok-v2-latest.js";
839
- const be = (o = {}) => {
840
- var e, t;
841
- const {
842
- bridge: s,
843
- accessToken: r,
844
- use: i = [],
845
- apiOptions: n = {},
846
- richText: c = {},
847
- bridgeUrl: a
848
- } = o;
849
- n.accessToken = n.accessToken || r;
850
- const l = { bridge: s, apiOptions: n };
851
- let h = {};
852
- i.forEach((g) => {
853
- h = { ...h, ...g(l) };
854
- }), a && (T = a);
855
- const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
856
- return s !== !1 && p && P(T), $ = new k(c.schema), c.resolver && L($, c.resolver), h;
857
- }, L = (o, e) => {
858
- o.addNode("blok", (t) => {
859
- let s = "";
860
- return t.attrs.body.forEach((r) => {
861
- s += e(r.component, r);
506
+ let de, he = "https://app.storyblok.com/f/storyblok-v2-latest.js";
507
+ const be = (r, t) => {
508
+ r.addNode("blok", (e) => {
509
+ let o = "";
510
+ return e.attrs.body.forEach((s) => {
511
+ o += t(s.component, s);
862
512
  }), {
863
- html: s
513
+ html: o
864
514
  };
865
515
  });
866
- }, ke = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), ve = (o, e, t) => {
867
- let s = t || $;
868
- if (!s) {
516
+ }, me = (r) => !r || !(r != null && r.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), ye = (r, t, e) => {
517
+ let o = e || de;
518
+ if (!o) {
869
519
  console.error(
870
520
  "Please initialize the Storyblok SDK before calling the renderRichText function"
871
521
  );
872
522
  return;
873
523
  }
874
- return ke(o) ? "" : (e && (s = new k(e.schema), e.resolver && L(s, e.resolver)), s.render(o));
875
- }, Oe = () => P(T);
876
- function we(o, e, t) {
877
- const s = "virtual:storyblok-init", r = "\0" + s;
878
- return globalThis.apiPlugin = ye, globalThis.storyblokInit = be, {
879
- name: "vite-plugin-storyblok-init",
880
- async resolveId(i) {
881
- if (i === s)
882
- return r;
883
- },
884
- async load(i) {
885
- if (i === r)
886
- return `
887
- const { storyblokApi } = globalThis.storyblokInit({
888
- accessToken: "${o}",
889
- use: ${e ? "[]" : "[globalThis.apiPlugin]"},
890
- apiOptions: ${JSON.stringify(t)},
891
- });
892
- export const storyblokApiInstance = storyblokApi;
893
- `;
894
- }
895
- };
896
- }
897
- const $e = /[\p{Lu}]/u, Te = /[\p{Ll}]/u, x = /^[\p{Lu}](?![\p{Lu}])/gu, N = /([\p{Alpha}\p{N}_]|$)/u, R = /[_.\- ]+/, Re = new RegExp("^" + R.source), O = new RegExp(R.source + N.source, "gu"), E = new RegExp("\\d+" + N.source, "gu"), Ie = (o, e, t, s) => {
898
- let r = !1, i = !1, n = !1, c = !1;
899
- for (let a = 0; a < o.length; a++) {
900
- const l = o[a];
901
- c = a > 2 ? o[a - 3] === "-" : !0, r && $e.test(l) ? (o = o.slice(0, a) + "-" + o.slice(a), r = !1, n = i, i = !0, a++) : i && n && Te.test(l) && (!c || s) ? (o = o.slice(0, a - 1) + "-" + o.slice(a - 1), n = i, i = !1, r = !0) : (r = e(l) === l && t(l) !== l, n = i, i = t(l) === l && e(l) !== l);
902
- }
903
- return o;
904
- }, _e = (o, e) => (x.lastIndex = 0, o.replaceAll(x, (t) => e(t))), Ce = (o, e) => (O.lastIndex = 0, E.lastIndex = 0, o.replaceAll(E, (t, s, r) => ["_", "-"].includes(o.charAt(r + t.length)) ? t : e(t)).replaceAll(O, (t, s) => e(s)));
905
- function j(o, e) {
906
- if (!(typeof o == "string" || Array.isArray(o)))
907
- throw new TypeError("Expected the input to be `string | string[]`");
908
- if (e = {
909
- pascalCase: !1,
910
- preserveConsecutiveUppercase: !1,
911
- ...e
912
- }, Array.isArray(o) ? o = o.map((i) => i.trim()).filter((i) => i.length).join("-") : o = o.trim(), o.length === 0)
913
- return "";
914
- const t = e.locale === !1 ? (i) => i.toLowerCase() : (i) => i.toLocaleLowerCase(e.locale), s = e.locale === !1 ? (i) => i.toUpperCase() : (i) => i.toLocaleUpperCase(e.locale);
915
- return o.length === 1 ? R.test(o) ? "" : e.pascalCase ? s(o) : t(o) : (o !== t(o) && (o = Ie(o, t, s, e.preserveConsecutiveUppercase)), o = o.replace(Re, ""), o = e.preserveConsecutiveUppercase ? _e(o, t) : t(o), e.pascalCase && (o = s(o.charAt(0)) + o.slice(1)), Ce(o, s));
916
- }
917
- function Ae(o, e, t, s) {
918
- const r = "virtual:storyblok-components", i = "\0" + r;
919
- return {
920
- name: "vite-plugin-storyblok-components",
921
- async resolveId(n) {
922
- if (n === r)
923
- return i;
924
- },
925
- async load(n) {
926
- if (n === i) {
927
- const c = [], a = [];
928
- for await (const [h, p] of Object.entries(e)) {
929
- const g = await this.resolve(
930
- "/" + o + "/" + p + ".astro"
931
- );
932
- if (g)
933
- c.push(`import ${j(h)} from "${g.id}"`);
934
- else if (t)
935
- a.push(h);
936
- else
937
- throw new Error(
938
- `Component could not be found for blok "${h}"! Does "${"/" + o + "/" + p}.astro" exist?`
939
- );
940
- }
941
- let l = "";
942
- if (t)
943
- if (l = ",FallbackComponent", s) {
944
- const h = await this.resolve(
945
- "/" + o + "/" + s + ".astro"
946
- );
947
- if (!h)
948
- throw new Error(
949
- `Custom fallback component could not be found. Does "${"/" + o + "/" + s}.astro" exist?`
950
- );
951
- c.push(
952
- `import FallbackComponent from "${h.id}"`
953
- );
954
- } else
955
- c.push(
956
- "import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
957
- );
958
- if (Object.values(e).length)
959
- return `${c.join(";")};export default {${Object.keys(e).filter((h) => !a.includes(h)).map((h) => j(h)).join(",")}${l}}`;
960
- if (t)
961
- return `${c[0]}; export default {${l.replace(",", "")}}`;
962
- throw new Error(
963
- `Currently, no Storyblok components are registered in astro.config.mjs.
964
- Please register your components or enable the fallback component.
965
- Detailed information can be found here: https://github.com/storyblok/storyblok-astro`
966
- );
967
- }
968
- }
969
- };
970
- }
971
- function Se(o) {
972
- const e = "virtual:storyblok-options", t = "\0" + e;
973
- return {
974
- name: "vite-plugin-storyblok-options",
975
- async resolveId(s) {
976
- if (s === e)
977
- return t;
978
- },
979
- async load(s) {
980
- if (s === t)
981
- return `export default ${JSON.stringify(o)}`;
982
- }
983
- };
984
- }
985
- function Ee() {
524
+ return me(r) ? "" : (t && (o = new fe(t.schema), t.resolver && be(o, t.resolver)), o.render(r));
525
+ }, $e = () => M(he);
526
+ function ve() {
986
527
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
987
528
  }
988
- function je(o, e) {
989
- const t = globalThis.storyblokApiInstance.richTextResolver;
990
- if (!t) {
529
+ function Ie(r, t) {
530
+ const e = globalThis.storyblokApiInstance.richTextResolver;
531
+ if (!e) {
991
532
  console.error(
992
533
  "Please initialize the Storyblok SDK before calling the renderRichText function"
993
534
  );
994
535
  return;
995
536
  }
996
- return ve(o, e, t);
537
+ return ye(r, t, e);
997
538
  }
998
- function Pe(o) {
999
- const e = {
539
+ function we(r) {
540
+ const t = {
1000
541
  useCustomApi: !1,
1001
542
  bridge: !0,
1002
543
  componentsDir: "src",
1003
544
  enableFallbackComponent: !1,
1004
- ...o
545
+ ...r
1005
546
  };
1006
547
  return {
1007
548
  name: "@storyblok/astro",
1008
549
  hooks: {
1009
550
  "astro:config:setup": ({
1010
- injectScript: t,
1011
- updateConfig: s,
1012
- addDevToolbarApp: r
551
+ injectScript: e,
552
+ updateConfig: o,
553
+ addDevToolbarApp: s
1013
554
  }) => {
1014
- if (s({
555
+ if (o({
1015
556
  vite: {
1016
557
  plugins: [
1017
- we(
1018
- e.accessToken,
1019
- e.useCustomApi,
1020
- e.apiOptions
558
+ E(
559
+ t.accessToken,
560
+ t.useCustomApi,
561
+ t.apiOptions
1021
562
  ),
1022
- Ae(
1023
- e.componentsDir,
1024
- e.components,
1025
- e.enableFallbackComponent,
1026
- e.customFallbackComponent
563
+ N(
564
+ t.componentsDir,
565
+ t.components,
566
+ t.enableFallbackComponent,
567
+ t.customFallbackComponent
1027
568
  ),
1028
- Se(e)
569
+ L(t)
1029
570
  ]
1030
571
  }
1031
- }), t(
572
+ }), e(
1032
573
  "page-ssr",
1033
574
  `
1034
575
  import { storyblokApiInstance } from "virtual:storyblok-init";
1035
576
  globalThis.storyblokApiInstance = storyblokApiInstance;
1036
577
  `
1037
- ), e.bridge) {
1038
- let i = "";
1039
- if (typeof e.bridge == "object") {
1040
- const n = { ...e.bridge };
1041
- i = `const storyblokInstance = new StoryblokBridge(${JSON.stringify(
578
+ ), t.bridge) {
579
+ let a = "";
580
+ if (typeof t.bridge == "object") {
581
+ const n = { ...t.bridge };
582
+ a = `const storyblokInstance = new StoryblokBridge(${JSON.stringify(
1042
583
  n
1043
584
  )});`;
1044
585
  } else
1045
- i = "const storyblokInstance = new StoryblokBridge()";
1046
- t(
586
+ a = "const storyblokInstance = new StoryblokBridge()";
587
+ e(
1047
588
  "page",
1048
589
  `
1049
590
  import { loadStoryblokBridge } from "@storyblok/astro";
1050
591
  loadStoryblokBridge().then(() => {
1051
592
  const { StoryblokBridge, location } = window;
1052
- ${i}
593
+ ${a}
1053
594
 
1054
595
  storyblokInstance.on(["published", "change"], (event) => {
1055
596
  if (!event.slugChanged) {
@@ -1060,17 +601,17 @@ function Pe(o) {
1060
601
  `
1061
602
  );
1062
603
  }
1063
- r("@storyblok/astro/toolbar-app-storyblok.ts");
604
+ s("@storyblok/astro/toolbar-app-storyblok.ts");
1064
605
  }
1065
606
  }
1066
607
  };
1067
608
  }
1068
609
  export {
1069
- k as RichTextResolver,
1070
- pe as RichTextSchema,
1071
- Pe as default,
1072
- Oe as loadStoryblokBridge,
1073
- je as renderRichText,
1074
- xe as storyblokEditable,
1075
- Ee as useStoryblokApi
610
+ fe as RichTextResolver,
611
+ ue as RichTextSchema,
612
+ we as default,
613
+ $e as loadStoryblokBridge,
614
+ Ie as renderRichText,
615
+ ke as storyblokEditable,
616
+ ve as useStoryblokApi
1076
617
  };