@storyblok/richtext
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -7,21 +7,21 @@ /** | ||
*/ | ||
function U(e, r) { | ||
function p(e, r) { | ||
if (!r) | ||
return { src: e, attrs: {} }; | ||
let a = 0, R = 0; | ||
const b = {}, l = []; | ||
function d(c, g, S, E, n) { | ||
typeof c != "number" || c <= g || c >= S ? console.warn(`[StoryblokRichText] - ${E.charAt(0).toUpperCase() + E.slice(1)} value must be a number between ${g} and ${S} (inclusive)`) : n.push(`${E}(${c})`); | ||
let a = 0, S = 0; | ||
const m = {}, l = []; | ||
function $(n, b, d, R, I) { | ||
typeof n != "number" || n <= b || n >= d ? console.warn(`[StoryblokRichText] - ${R.charAt(0).toUpperCase() + R.slice(1)} value must be a number between ${b} and ${d} (inclusive)`) : I.push(`${R}(${n})`); | ||
} | ||
if (typeof r == "object") { | ||
if (typeof r.width == "number" && r.width > 0 ? (b.width = r.width, a = r.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), r.height && typeof r.height == "number" && r.height > 0 ? (b.height = r.height, R = r.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), r.loading && ["lazy", "eager"].includes(r.loading) && (b.loading = r.loading), r.class && (b.class = r.class), r.filters) { | ||
const { filters: c } = r || {}, { blur: g, brightness: S, fill: E, format: n, grayscale: L, quality: T, rotate: v } = c || {}; | ||
g && d(g, 0, 100, "blur", l), T && d(T, 0, 100, "quality", l), S && d(S, 0, 100, "brightness", l), E && l.push(`fill(${E})`), L && l.push("grayscale()"), v && [0, 90, 180, 270].includes(r.filters.rotate || 0) && l.push(`rotate(${v})`), n && ["webp", "png", "jpeg"].includes(n) && l.push(`format(${n})`); | ||
if (typeof r.width == "number" && r.width > 0 ? (m.width = r.width, a = r.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), r.height && typeof r.height == "number" && r.height > 0 ? (m.height = r.height, S = r.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), r.loading && ["lazy", "eager"].includes(r.loading) && (m.loading = r.loading), r.class && (m.class = r.class), r.filters) { | ||
const { filters: n } = r || {}, { blur: b, brightness: d, fill: R, format: I, grayscale: h, quality: v, rotate: T } = n || {}; | ||
b && $(b, 0, 100, "blur", l), v && $(v, 0, 100, "quality", l), d && $(d, 0, 100, "brightness", l), R && l.push(`fill(${R})`), h && l.push("grayscale()"), T && [0, 90, 180, 270].includes(r.filters.rotate || 0) && l.push(`rotate(${T})`), I && ["webp", "png", "jpeg"].includes(I) && l.push(`format(${I})`); | ||
} | ||
r.srcset && (b.srcset = r.srcset.map((c) => { | ||
if (typeof c == "number") | ||
return `${e}/m/${c}x0/${l.length > 0 ? `filters:${l.join(":")}` : ""} ${c}w`; | ||
if (Array.isArray(c) && c.length === 2) { | ||
const [g, S] = c; | ||
return `${e}/m/${g}x${S}/${l.length > 0 ? `filters:${l.join(":")}` : ""} ${g}w`; | ||
r.srcset && (m.srcset = r.srcset.map((n) => { | ||
if (typeof n == "number") | ||
return `${e}/m/${n}x0/${l.length > 0 ? `filters:${l.join(":")}` : ""} ${n}w`; | ||
if (Array.isArray(n) && n.length === 2) { | ||
const [b, d] = n; | ||
return `${e}/m/${b}x${d}/${l.length > 0 ? `filters:${l.join(":")}` : ""} ${b}w`; | ||
} else { | ||
@@ -31,12 +31,12 @@ console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers"); | ||
} | ||
}).join(", ")), r.sizes && (b.sizes = r.sizes.join(", ")); | ||
}).join(", ")), r.sizes && (m.sizes = r.sizes.join(", ")); | ||
} | ||
let u = `${e}/m/`; | ||
return a > 0 && R > 0 && (u = `${u}${a}x${R}/`), l.length > 0 && (u = `${u}filters:${l.join(":")}`), { | ||
src: u, | ||
attrs: b | ||
let E = `${e}/m/`; | ||
return a > 0 && S > 0 && (E = `${E}${a}x${S}/`), l.length > 0 && (E = `${E}filters:${l.join(":")}`), { | ||
src: E, | ||
attrs: m | ||
}; | ||
} | ||
var f = /* @__PURE__ */ ((e) => (e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e))(f || {}), m = /* @__PURE__ */ ((e) => (e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e))(m || {}), _ = /* @__PURE__ */ ((e) => (e.TEXT = "text", e))(_ || {}), D = /* @__PURE__ */ ((e) => (e.SELF = "_self", e.BLANK = "_blank", e))(D || {}), A = /* @__PURE__ */ ((e) => (e.URL = "url", e.STORY = "story", e.ASSET = "asset", e.EMAIL = "email", e))(A || {}); | ||
const G = [ | ||
var o = /* @__PURE__ */ ((e) => (e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e))(o || {}), f = /* @__PURE__ */ ((e) => (e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e))(f || {}), C = /* @__PURE__ */ ((e) => (e.TEXT = "text", e))(C || {}), G = /* @__PURE__ */ ((e) => (e.SELF = "_self", e.BLANK = "_blank", e))(G || {}), L = /* @__PURE__ */ ((e) => (e.URL = "url", e.STORY = "story", e.ASSET = "asset", e.EMAIL = "email", e))(L || {}); | ||
const z = [ | ||
"area", | ||
@@ -56,143 +56,147 @@ "base", | ||
"wbr" | ||
], z = (e = {}) => Object.keys(e).map((r) => `${r}="${e[r]}"`).join(" "), p = (e = {}) => Object.keys(e).map((r) => `${r}: ${e[r]}`).join("; "); | ||
function k(e) { | ||
], k = (e = {}) => Object.keys(e).map((r) => `${r}="${e[r]}"`).join(" "), K = (e = {}) => Object.keys(e).map((r) => `${r}: ${e[r]}`).join("; "); | ||
function F(e) { | ||
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"); | ||
} | ||
const y = (e) => Object.fromEntries(Object.entries(e).filter(([r, a]) => a !== void 0)); | ||
function K(e, r = {}, a) { | ||
const R = z(r), b = R ? `${e} ${R}` : e; | ||
return G.includes(e) ? `<${b}>` : `<${b}>${Array.isArray(a) ? a.join("") : a || ""}</${e}>`; | ||
const _ = (e) => Object.fromEntries(Object.entries(e).filter(([r, a]) => a !== void 0)); | ||
function w(e, r = {}, a) { | ||
const S = k(r), m = S ? `${e} ${S}` : e, l = Array.isArray(a) ? a.join("") : a || ""; | ||
if (e) { | ||
if (z.includes(e)) | ||
return `<${m}>`; | ||
} else return l; | ||
return `<${m}>${l}</${e}>`; | ||
} | ||
function F(e = {}) { | ||
function Y(e = {}) { | ||
let r = 0; | ||
const { | ||
renderFn: a = K, | ||
textFn: R = k, | ||
resolvers: b = {}, | ||
renderFn: a = w, | ||
textFn: S = F, | ||
resolvers: m = {}, | ||
optimizeImages: l = !1, | ||
keyedResolvers: d = !1 | ||
} = e, u = (t) => (i) => { | ||
const s = i.attrs || {}; | ||
return d && (s.key = `${t}-${r}`), a(t, s, i.children || null); | ||
}, c = (t) => { | ||
const { src: i, alt: s, title: o, srcset: $, sizes: h } = t.attrs || {}; | ||
let I = i, O = {}; | ||
keyedResolvers: $ = !1 | ||
} = e, E = a !== w, n = (t) => (s) => { | ||
const i = s.attrs || {}; | ||
return $ && (i.key = `${t}-${r}`), a(t, i, s.children || null); | ||
}, b = (t) => { | ||
const { src: s, alt: i, title: c, srcset: g, sizes: u } = t.attrs || {}; | ||
let O = s, A = {}; | ||
if (l) { | ||
const { src: H, attrs: P } = U(i, l); | ||
I = H, O = P; | ||
const { src: U, attrs: D } = p(s, l); | ||
O = U, A = D; | ||
} | ||
d && (O = { | ||
...O, | ||
$ && (A = { | ||
...A, | ||
key: `img-${r}` | ||
}); | ||
const x = { | ||
src: I, | ||
alt: s, | ||
title: o, | ||
srcset: $, | ||
sizes: h, | ||
...O | ||
const P = { | ||
src: O, | ||
alt: i, | ||
title: c, | ||
srcset: g, | ||
sizes: u, | ||
...A | ||
}; | ||
return a("img", y(x)); | ||
}, g = (t) => { | ||
const { level: i, ...s } = t.attrs || {}, o = { | ||
...s | ||
return a("img", _(P)); | ||
}, d = (t) => { | ||
const { level: s, ...i } = t.attrs || {}, c = { | ||
...i | ||
}; | ||
return d && (o.key = `h${i}-${r}`), a(`h${i}`, o, t.children); | ||
}, S = (t) => { | ||
var o, $, h, I; | ||
const i = a("img", { | ||
src: (o = t.attrs) == null ? void 0 : o.fallbackImage, | ||
alt: ($ = t.attrs) == null ? void 0 : $.alt, | ||
return $ && (c.key = `h${s}-${r}`), a(`h${s}`, c, t.children); | ||
}, R = (t) => { | ||
var c, g, u, O; | ||
const s = a("img", { | ||
src: (c = t.attrs) == null ? void 0 : c.fallbackImage, | ||
alt: (g = t.attrs) == null ? void 0 : g.alt, | ||
style: "width: 1.25em; height: 1.25em; vertical-align: text-top", | ||
draggable: "false", | ||
loading: "lazy" | ||
}), s = { | ||
}), i = { | ||
"data-type": "emoji", | ||
"data-name": (h = t.attrs) == null ? void 0 : h.name, | ||
"data-emoji": (I = t.attrs) == null ? void 0 : I.emoji | ||
"data-name": (u = t.attrs) == null ? void 0 : u.name, | ||
"data-emoji": (O = t.attrs) == null ? void 0 : O.emoji | ||
}; | ||
return d && (s.key = `emoji-${r}`), a("span", s, i); | ||
}, E = (t) => a("pre", { | ||
return $ && (i.key = `emoji-${r}`), a("span", i, s); | ||
}, I = (t) => a("pre", { | ||
...t.attrs, | ||
key: `code-${r}` | ||
}, a("code", { key: `code-${r}` }, t.children || "")), n = (t, i = !1) => ({ text: s, attrs: o }) => { | ||
const { class: $, id: h, ...I } = o || {}, O = i ? { | ||
class: $, | ||
id: h, | ||
style: p(I) || void 0 | ||
} : o || {}; | ||
return d && (O.key = `${t}-${r}`), a(t, y(O), s); | ||
}, L = (t) => N(t), T = (t) => { | ||
const { marks: i, ...s } = t; | ||
return "text" in t ? i ? i.reduce( | ||
(o, $) => L({ ...$, text: o }), | ||
}, a("code", { key: `code-${r}` }, t.children || "")), h = (t, s = !1) => ({ text: i, attrs: c }) => { | ||
const { class: g, id: u, ...O } = c || {}, A = s ? { | ||
class: g, | ||
id: u, | ||
style: K(O) || void 0 | ||
} : c || {}; | ||
return $ && (A.key = `${t}-${r}`), a(t, _(A), i); | ||
}, v = (t) => N(t), T = (t) => { | ||
const { marks: s, ...i } = t; | ||
return "text" in t ? s ? s.reduce( | ||
(c, g) => v({ ...g, text: c }), | ||
// Fix: Ensure render function returns a string | ||
L({ ...s, children: s.children }) | ||
v({ ...i, children: i.children }) | ||
// Fix: Cast children to string | ||
) : R(s.text) : ""; | ||
}, v = (t) => { | ||
const { linktype: i, href: s, anchor: o, ...$ } = t.attrs || {}; | ||
let h = ""; | ||
switch (i) { | ||
case A.ASSET: | ||
case A.URL: | ||
h = s; | ||
) : S(i.text) : ""; | ||
}, y = (t) => { | ||
const { linktype: s, href: i, anchor: c, ...g } = t.attrs || {}; | ||
let u = ""; | ||
switch (s) { | ||
case L.ASSET: | ||
case L.URL: | ||
u = i; | ||
break; | ||
case A.EMAIL: | ||
h = `mailto:${s}`; | ||
case L.EMAIL: | ||
u = `mailto:${i}`; | ||
break; | ||
case A.STORY: | ||
h = s; | ||
case L.STORY: | ||
u = i; | ||
break; | ||
} | ||
return o && (h = `${h}#${o}`), a("a", { ...$, href: h, key: `a-${r}` }, t.text); | ||
}, w = (t) => { | ||
var i, s; | ||
return c && (u = `${u}#${c}`), a("a", { ...g, href: u, key: `a-${r}` }, t.text); | ||
}, x = (t) => { | ||
var s, i; | ||
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), a("span", { | ||
blok: (i = t == null ? void 0 : t.attrs) == null ? void 0 : i.body[0], | ||
id: (s = t.attrs) == null ? void 0 : s.id, | ||
blok: (s = t == null ? void 0 : t.attrs) == null ? void 0 : s.body[0], | ||
id: (i = t.attrs) == null ? void 0 : i.id, | ||
key: `component-${r}`, | ||
style: "display: none" | ||
}); | ||
}, C = new Map([ | ||
[f.DOCUMENT, u("div")], | ||
[f.HEADING, g], | ||
[f.PARAGRAPH, u("p")], | ||
[f.UL_LIST, u("ul")], | ||
[f.OL_LIST, u("ol")], | ||
[f.LIST_ITEM, u("li")], | ||
[f.IMAGE, c], | ||
[f.EMOJI, S], | ||
[f.CODE_BLOCK, E], | ||
[f.HR, u("hr")], | ||
[f.BR, u("br")], | ||
[f.QUOTE, u("blockquote")], | ||
[f.COMPONENT, w], | ||
[_.TEXT, T], | ||
[m.LINK, v], | ||
[m.ANCHOR, v], | ||
[m.STYLED, n("span", !0)], | ||
[m.BOLD, n("strong")], | ||
[m.TEXT_STYLE, n("span", !0)], | ||
[m.ITALIC, n("em")], | ||
[m.UNDERLINE, n("u")], | ||
[m.STRIKE, n("s")], | ||
[m.CODE, n("code")], | ||
[m.SUPERSCRIPT, n("sup")], | ||
[m.SUBSCRIPT, n("sub")], | ||
[m.HIGHLIGHT, n("mark")], | ||
...Object.entries(b).map(([t, i]) => [t, i]) | ||
}, H = new Map([ | ||
[o.DOCUMENT, n("")], | ||
[o.HEADING, d], | ||
[o.PARAGRAPH, n("p")], | ||
[o.UL_LIST, n("ul")], | ||
[o.OL_LIST, n("ol")], | ||
[o.LIST_ITEM, n("li")], | ||
[o.IMAGE, b], | ||
[o.EMOJI, R], | ||
[o.CODE_BLOCK, I], | ||
[o.HR, n("hr")], | ||
[o.BR, n("br")], | ||
[o.QUOTE, n("blockquote")], | ||
[o.COMPONENT, x], | ||
[C.TEXT, T], | ||
[f.LINK, y], | ||
[f.ANCHOR, y], | ||
[f.STYLED, h("span", !0)], | ||
[f.BOLD, h("strong")], | ||
[f.TEXT_STYLE, h("span", !0)], | ||
[f.ITALIC, h("em")], | ||
[f.UNDERLINE, h("u")], | ||
[f.STRIKE, h("s")], | ||
[f.CODE, h("code")], | ||
[f.SUPERSCRIPT, h("sup")], | ||
[f.SUBSCRIPT, h("sub")], | ||
[f.HIGHLIGHT, h("mark")], | ||
...Object.entries(m).map(([t, s]) => [t, s]) | ||
]); | ||
function j(t) { | ||
r += 1; | ||
const i = C.get(t.type); | ||
if (!i) | ||
const s = H.get(t.type); | ||
if (!s) | ||
return console.error("<Storyblok>", `No resolver found for node type ${t.type}`), ""; | ||
if (t.type === "text") | ||
return i(t); | ||
const s = t.content ? t.content.map(N) : void 0; | ||
return i({ | ||
return s(t); | ||
const i = t.content ? t.content.map(N) : void 0; | ||
return s({ | ||
...t, | ||
children: s | ||
children: i | ||
// Fix: Update the type of 'children' to Node[] | ||
@@ -202,3 +206,3 @@ }); | ||
function N(t) { | ||
return Array.isArray(t) ? t.map(j) : j(t); | ||
return t.type === "doc" ? E ? t.content.map(j) : t.content.map(j).join("") : Array.isArray(t) ? t.map(j) : j(t); | ||
} | ||
@@ -210,8 +214,8 @@ return { | ||
export { | ||
f as BlockTypes, | ||
D as LinkTargets, | ||
A as LinkTypes, | ||
m as MarkTypes, | ||
_ as TextTypes, | ||
F as richTextResolver | ||
o as BlockTypes, | ||
G as LinkTargets, | ||
L as LinkTypes, | ||
f as MarkTypes, | ||
C as TextTypes, | ||
Y as richTextResolver | ||
}; |
@@ -7,2 +7,2 @@ /** | ||
*/ | ||
(function(d,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(d=typeof globalThis<"u"?globalThis:d||self,L(d.StoryblokRichText={}))})(this,function(d){"use strict";function L(e,r){if(!r)return{src:e,attrs:{}};let n=0,E=0;const b={},a=[];function S(o,g,R,I,l){typeof o!="number"||o<=g||o>=R?console.warn(`[StoryblokRichText] - ${I.charAt(0).toUpperCase()+I.slice(1)} value must be a number between ${g} and ${R} (inclusive)`):l.push(`${I}(${o})`)}if(typeof r=="object"){if(typeof r.width=="number"&&r.width>0?(b.width=r.width,n=r.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),r.height&&typeof r.height=="number"&&r.height>0?(b.height=r.height,E=r.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),r.loading&&["lazy","eager"].includes(r.loading)&&(b.loading=r.loading),r.class&&(b.class=r.class),r.filters){const{filters:o}=r||{},{blur:g,brightness:R,fill:I,format:l,grayscale:y,quality:j,rotate:A}=o||{};g&&S(g,0,100,"blur",a),j&&S(j,0,100,"quality",a),R&&S(R,0,100,"brightness",a),I&&a.push(`fill(${I})`),y&&a.push("grayscale()"),A&&[0,90,180,270].includes(r.filters.rotate||0)&&a.push(`rotate(${A})`),l&&["webp","png","jpeg"].includes(l)&&a.push(`format(${l})`)}r.srcset&&(b.srcset=r.srcset.map(o=>{if(typeof o=="number")return`${e}/m/${o}x0/${a.length>0?`filters:${a.join(":")}`:""} ${o}w`;if(Array.isArray(o)&&o.length===2){const[g,R]=o;return`${e}/m/${g}x${R}/${a.length>0?`filters:${a.join(":")}`:""} ${g}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),r.sizes&&(b.sizes=r.sizes.join(", "))}let h=`${e}/m/`;return n>0&&E>0&&(h=`${h}${n}x${E}/`),a.length>0&&(h=`${h}filters:${a.join(":")}`),{src:h,attrs:b}}var c=(e=>(e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e))(c||{}),f=(e=>(e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e))(f||{}),N=(e=>(e.TEXT="text",e))(N||{}),w=(e=>(e.SELF="_self",e.BLANK="_blank",e))(w||{}),O=(e=>(e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e))(O||{});const x=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],P=(e={})=>Object.keys(e).map(r=>`${r}="${e[r]}"`).join(" "),p=(e={})=>Object.keys(e).map(r=>`${r}: ${e[r]}`).join("; ");function U(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const C=e=>Object.fromEntries(Object.entries(e).filter(([r,n])=>n!==void 0));function k(e,r={},n){const E=P(r),b=E?`${e} ${E}`:e;return x.includes(e)?`<${b}>`:`<${b}>${Array.isArray(n)?n.join(""):n||""}</${e}>`}function D(e={}){let r=0;const{renderFn:n=k,textFn:E=U,resolvers:b={},optimizeImages:a=!1,keyedResolvers:S=!1}=e,h=t=>i=>{const s=i.attrs||{};return S&&(s.key=`${t}-${r}`),n(t,s,i.children||null)},o=t=>{const{src:i,alt:s,title:u,srcset:$,sizes:m}=t.attrs||{};let T=i,v={};if(a){const{src:F,attrs:Y}=L(i,a);T=F,v=Y}S&&(v={...v,key:`img-${r}`});const K={src:T,alt:s,title:u,srcset:$,sizes:m,...v};return n("img",C(K))},g=t=>{const{level:i,...s}=t.attrs||{},u={...s};return S&&(u.key=`h${i}-${r}`),n(`h${i}`,u,t.children)},R=t=>{var u,$,m,T;const i=n("img",{src:(u=t.attrs)==null?void 0:u.fallbackImage,alt:($=t.attrs)==null?void 0:$.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),s={"data-type":"emoji","data-name":(m=t.attrs)==null?void 0:m.name,"data-emoji":(T=t.attrs)==null?void 0:T.emoji};return S&&(s.key=`emoji-${r}`),n("span",s,i)},I=t=>n("pre",{...t.attrs,key:`code-${r}`},n("code",{key:`code-${r}`},t.children||"")),l=(t,i=!1)=>({text:s,attrs:u})=>{const{class:$,id:m,...T}=u||{},v=i?{class:$,id:m,style:p(T)||void 0}:u||{};return S&&(v.key=`${t}-${r}`),n(t,C(v),s)},y=t=>_(t),j=t=>{const{marks:i,...s}=t;return"text"in t?i?i.reduce((u,$)=>y({...$,text:u}),y({...s,children:s.children})):E(s.text):""},A=t=>{const{linktype:i,href:s,anchor:u,...$}=t.attrs||{};let m="";switch(i){case O.ASSET:case O.URL:m=s;break;case O.EMAIL:m=`mailto:${s}`;break;case O.STORY:m=s;break}return u&&(m=`${m}#${u}`),n("a",{...$,href:m,key:`a-${r}`},t.text)},G=t=>{var i,s;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),n("span",{blok:(i=t==null?void 0:t.attrs)==null?void 0:i.body[0],id:(s=t.attrs)==null?void 0:s.id,key:`component-${r}`,style:"display: none"})},z=new Map([[c.DOCUMENT,h("div")],[c.HEADING,g],[c.PARAGRAPH,h("p")],[c.UL_LIST,h("ul")],[c.OL_LIST,h("ol")],[c.LIST_ITEM,h("li")],[c.IMAGE,o],[c.EMOJI,R],[c.CODE_BLOCK,I],[c.HR,h("hr")],[c.BR,h("br")],[c.QUOTE,h("blockquote")],[c.COMPONENT,G],[N.TEXT,j],[f.LINK,A],[f.ANCHOR,A],[f.STYLED,l("span",!0)],[f.BOLD,l("strong")],[f.TEXT_STYLE,l("span",!0)],[f.ITALIC,l("em")],[f.UNDERLINE,l("u")],[f.STRIKE,l("s")],[f.CODE,l("code")],[f.SUPERSCRIPT,l("sup")],[f.SUBSCRIPT,l("sub")],[f.HIGHLIGHT,l("mark")],...Object.entries(b).map(([t,i])=>[t,i])]);function H(t){r+=1;const i=z.get(t.type);if(!i)return console.error("<Storyblok>",`No resolver found for node type ${t.type}`),"";if(t.type==="text")return i(t);const s=t.content?t.content.map(_):void 0;return i({...t,children:s})}function _(t){return Array.isArray(t)?t.map(H):H(t)}return{render:_}}d.BlockTypes=c,d.LinkTargets=w,d.LinkTypes=O,d.MarkTypes=f,d.TextTypes=N,d.richTextResolver=D,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}); | ||
(function(b,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(b=typeof globalThis<"u"?globalThis:b||self,A(b.StoryblokRichText={}))})(this,function(b){"use strict";function A(e,r){if(!r)return{src:e,attrs:{}};let a=0,R=0;const h={},l=[];function $(s,d,S,E,T){typeof s!="number"||s<=d||s>=S?console.warn(`[StoryblokRichText] - ${E.charAt(0).toUpperCase()+E.slice(1)} value must be a number between ${d} and ${S} (inclusive)`):T.push(`${E}(${s})`)}if(typeof r=="object"){if(typeof r.width=="number"&&r.width>0?(h.width=r.width,a=r.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),r.height&&typeof r.height=="number"&&r.height>0?(h.height=r.height,R=r.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),r.loading&&["lazy","eager"].includes(r.loading)&&(h.loading=r.loading),r.class&&(h.class=r.class),r.filters){const{filters:s}=r||{},{blur:d,brightness:S,fill:E,format:T,grayscale:m,quality:y,rotate:j}=s||{};d&&$(d,0,100,"blur",l),y&&$(y,0,100,"quality",l),S&&$(S,0,100,"brightness",l),E&&l.push(`fill(${E})`),m&&l.push("grayscale()"),j&&[0,90,180,270].includes(r.filters.rotate||0)&&l.push(`rotate(${j})`),T&&["webp","png","jpeg"].includes(T)&&l.push(`format(${T})`)}r.srcset&&(h.srcset=r.srcset.map(s=>{if(typeof s=="number")return`${e}/m/${s}x0/${l.length>0?`filters:${l.join(":")}`:""} ${s}w`;if(Array.isArray(s)&&s.length===2){const[d,S]=s;return`${e}/m/${d}x${S}/${l.length>0?`filters:${l.join(":")}`:""} ${d}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),r.sizes&&(h.sizes=r.sizes.join(", "))}let I=`${e}/m/`;return a>0&&R>0&&(I=`${I}${a}x${R}/`),l.length>0&&(I=`${I}filters:${l.join(":")}`),{src:I,attrs:h}}var c=(e=>(e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e))(c||{}),u=(e=>(e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e))(u||{}),_=(e=>(e.TEXT="text",e))(_||{}),C=(e=>(e.SELF="_self",e.BLANK="_blank",e))(C||{}),L=(e=>(e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e))(L||{});const P=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],U=(e={})=>Object.keys(e).map(r=>`${r}="${e[r]}"`).join(" "),k=(e={})=>Object.keys(e).map(r=>`${r}: ${e[r]}`).join("; ");function D(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const p=e=>Object.fromEntries(Object.entries(e).filter(([r,a])=>a!==void 0));function x(e,r={},a){const R=U(r),h=R?`${e} ${R}`:e,l=Array.isArray(a)?a.join(""):a||"";if(e){if(P.includes(e))return`<${h}>`}else return l;return`<${h}>${l}</${e}>`}function G(e={}){let r=0;const{renderFn:a=x,textFn:R=D,resolvers:h={},optimizeImages:l=!1,keyedResolvers:$=!1}=e,I=a!==x,s=t=>i=>{const n=i.attrs||{};return $&&(n.key=`${t}-${r}`),a(t,n,i.children||null)},d=t=>{const{src:i,alt:n,title:o,srcset:g,sizes:f}=t.attrs||{};let O=i,v={};if(l){const{src:Y,attrs:q}=A(i,l);O=Y,v=q}$&&(v={...v,key:`img-${r}`});const F={src:O,alt:n,title:o,srcset:g,sizes:f,...v};return a("img",p(F))},S=t=>{const{level:i,...n}=t.attrs||{},o={...n};return $&&(o.key=`h${i}-${r}`),a(`h${i}`,o,t.children)},E=t=>{var o,g,f,O;const i=a("img",{src:(o=t.attrs)==null?void 0:o.fallbackImage,alt:(g=t.attrs)==null?void 0:g.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),n={"data-type":"emoji","data-name":(f=t.attrs)==null?void 0:f.name,"data-emoji":(O=t.attrs)==null?void 0:O.emoji};return $&&(n.key=`emoji-${r}`),a("span",n,i)},T=t=>a("pre",{...t.attrs,key:`code-${r}`},a("code",{key:`code-${r}`},t.children||"")),m=(t,i=!1)=>({text:n,attrs:o})=>{const{class:g,id:f,...O}=o||{},v=i?{class:g,id:f,style:k(O)||void 0}:o||{};return $&&(v.key=`${t}-${r}`),a(t,p(v),n)},y=t=>w(t),j=t=>{const{marks:i,...n}=t;return"text"in t?i?i.reduce((o,g)=>y({...g,text:o}),y({...n,children:n.children})):R(n.text):""},H=t=>{const{linktype:i,href:n,anchor:o,...g}=t.attrs||{};let f="";switch(i){case L.ASSET:case L.URL:f=n;break;case L.EMAIL:f=`mailto:${n}`;break;case L.STORY:f=n;break}return o&&(f=`${f}#${o}`),a("a",{...g,href:f,key:`a-${r}`},t.text)},z=t=>{var i,n;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),a("span",{blok:(i=t==null?void 0:t.attrs)==null?void 0:i.body[0],id:(n=t.attrs)==null?void 0:n.id,key:`component-${r}`,style:"display: none"})},K=new Map([[c.DOCUMENT,s("")],[c.HEADING,S],[c.PARAGRAPH,s("p")],[c.UL_LIST,s("ul")],[c.OL_LIST,s("ol")],[c.LIST_ITEM,s("li")],[c.IMAGE,d],[c.EMOJI,E],[c.CODE_BLOCK,T],[c.HR,s("hr")],[c.BR,s("br")],[c.QUOTE,s("blockquote")],[c.COMPONENT,z],[_.TEXT,j],[u.LINK,H],[u.ANCHOR,H],[u.STYLED,m("span",!0)],[u.BOLD,m("strong")],[u.TEXT_STYLE,m("span",!0)],[u.ITALIC,m("em")],[u.UNDERLINE,m("u")],[u.STRIKE,m("s")],[u.CODE,m("code")],[u.SUPERSCRIPT,m("sup")],[u.SUBSCRIPT,m("sub")],[u.HIGHLIGHT,m("mark")],...Object.entries(h).map(([t,i])=>[t,i])]);function N(t){r+=1;const i=K.get(t.type);if(!i)return console.error("<Storyblok>",`No resolver found for node type ${t.type}`),"";if(t.type==="text")return i(t);const n=t.content?t.content.map(w):void 0;return i({...t,children:n})}function w(t){return t.type==="doc"?I?t.content.map(N):t.content.map(N).join(""):Array.isArray(t)?t.map(N):N(t)}return{render:w}}b.BlockTypes=c,b.LinkTargets=C,b.LinkTypes=L,b.MarkTypes=u,b.TextTypes=_,b.richTextResolver=G,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "@storyblok/richtext", | ||
"type": "module", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"packageManager": "pnpm@9.12.2", | ||
@@ -6,0 +6,0 @@ "description": "Storyblok RichText Resolver", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38744
601