UNPKG

@venuecms/sdk-next

Version:

This is a work in progress and is heavily in flux until we launch 1.0 in February.

6 lines (4 loc) 4.49 kB
import{b as y}from"./chunk-SRGIKZIK.mjs";import{a as f}from"./chunk-AYVYS7LK.mjs";import S from"markdown-to-jsx";import{Fragment as u,jsx as t,jsxs as g}from"react/jsx-runtime";var k={bold:"font-bold",italic:"italic",underline:"underline",strike:"line-through",link:"underline underline-offset-[3px] cursor-pointer"},x=(n={})=>{let a={link:e=>{let{class:r,className:s,...l}=e,i=[s,n.a??k.link,r].filter(Boolean).join(" ")||void 0;return t("a",{...l,className:i})}};return{text:e=>{if(e.node.marks){let r=e.node.marks.reduce((i,d)=>a[d.type]?i:`${k[d.type]??""} ${i}`,"").trim(),s=!1,l=e.node.marks.reduce((i,d)=>{if(d.type in a){s=!0;let c=a[d.type];return c({...d.attrs,className:r,children:i})}return i},e.node.text);return s?l:t("span",{className:`${r}`,children:e.node.text})}return n.text&&(n.text,e.node.text),t(u,{children:e.node.text})},paragraph:e=>t("p",{className:n.p,children:e.children}),bulletList:e=>t("ul",{className:n.ul,children:e.children}),orderedList:e=>t("ol",{className:n.ol,children:e.children}),listItem:e=>t("li",{className:n.li,children:e.children}),codeBlock:e=>t("pre",{children:t("code",{className:n.code,children:e.children})}),heading:e=>{switch(e.node.attrs?.level){case 1:return t("h1",{className:n.h1,children:e.children});case 2:return t("h2",{className:n.h2,children:e.children});case 3:return t("h3",{className:n.h3,children:e.children});default:return t(u,{children:e.children})}},hardBreak:()=>t("br",{}),image:e=>{let{src:r,alt:s}=e.node.attrs??{},l={url:r.split(/^\/media\//).join(""),metadata:{altText:s}};return t(f,{className:n.image,image:l})},img:e=>{let{src:r,alt:s}=e.node,l={url:r.split(/^\/media\//).join(""),metadata:{altText:s}};return t(f,{className:n.img,image:l})},youtube:e=>{let{src:r,start:s}=e.node.attrs,l=r.split("v=")[1];return t("iframe",{src:`https://www.youtube.com/embed/${l}?modestbranding=1${s?`&start=${s}`:""}`,frameBorder:"0",allowFullScreen:!0,width:"100%",height:"auto",style:{aspectRatio:"4 / 3",maxWidth:"100%"}})},iframe:e=>{let{src:r,style:s,frameborder:l,allowfullscreen:i,referrerpolicy:d,aspectRatio:c,...m}=e.node?.attrs??e,h=typeof s=="string"?s?.split(";").reduce((p,C)=>{let[H,N]=C.split(":");return N!==void 0?{...p,[H]:N.trim()}:p},{}):s;if(c)return t("iframe",{src:r,style:{...h,width:"100%",aspectRatio:String(c),height:"auto"},frameBorder:l,allowFullScreen:i,referrerPolicy:d,...m});let b=!!(r.match(/youtube.com/)||r.match(/vimeo.com/)),w=!!r.match(/bandcamp.com/),v=!!r.match(/vimeo.com/);return t("iframe",{src:r,style:{...h,...b?{maxWidth:"100%",aspectRatio:"4 / 3",height:"auto"}:{},...w&&!h?.height?{width:"100%",maxWidth:"700px",height:"42px"}:{},...v&&!h?.height?{width:"100%",aspectRatio:m.width/m.height}:{}},frameBorder:l,allowFullScreen:i,referrerPolicy:d,...m})},linkCard:e=>{let{href:r,title:s,description:l,site:i,image:d}=e.node?.attrs??e;return g("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:n.linkCard??"my-4 block overflow-hidden bg-card no-underline transition-opacity hover:opacity-80",children:[d?t("img",{src:d,alt:s??"",className:"aspect-video w-full object-cover"}):null,g("div",{className:"p-4",children:[s?t("h3",{className:"mb-2 text-base font-semibold text-primary",children:s}):null,i?t("span",{className:"text-xs text-secondary",children:i}):null,l?t("p",{className:"mt-2 text-sm text-secondary",children:l}):null]})]})}}},B=(n={})=>{let a=x(n);return{...a,p:a.paragraph,ul:a.bulletList,ol:a.orderedList,li:a.listItem,code:a.codeBlock,h1:o=>a.heading({...o,node:{attrs:{level:1}}}),h2:o=>a.heading({...o,node:{attrs:{level:2}}}),h3:o=>a.heading({...o,node:{attrs:{level:3}}}),img:o=>a.image({...o,node:{attrs:{src:o.src,alt:o.alt}}}),hr:o=>t("hr",{...o}),a:o=>t("a",{href:o.href,className:n.a,children:o.children}),span:({children:o})=>t("span",{children:o})}},R=n=>{let{node:a,handlers:o={}}=n,e={...x(n.classes),...o},r=[];if(a.content&&a.content.forEach((l,i)=>{r.push(t(R,{node:l,handlers:e},`${l.type}- ${i} `))}),!(a.type in e))return console.warn("missing type",a),t(u,{});let s=e[a.type];return t(s,{node:a,children:r})},M=({content:n,contentStyles:a,className:o,components:e})=>{let{contentJSON:r}=n;return r?g("div",{className:o,children:[t(y,{}),r.content.map((s,l)=>t(R,{classes:a,node:s,handlers:e},l))]}):n.content?g(u,{children:[t(y,{}),t(S,{className:o,options:{overrides:{...B(a)}},children:n.content.replaceAll(/(?:\n|\r\n)\*\*\*(?:\n|\r\n)/g,` *** `)})]}):null};export{M as a}; //# sourceMappingURL=chunk-3EQCCI4N.mjs.map