@happeouikit/content-renderer 3.5.4 → 3.5.5
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.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +2 -0
- package/dist/index.es.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
|
|
135
135
|
`}return d}),t.subParser("makeMarkdown.paragraph",function(r,u){var a="";if(r.hasChildNodes())for(var d=r.childNodes,o=d.length,f=0;f<o;++f)a+=t.subParser("makeMarkdown.node")(d[f],u);return a=a.trim(),a}),t.subParser("makeMarkdown.pre",function(r,u){var a=r.getAttribute("prenum");return"<pre>"+u.preList[a]+"</pre>"}),t.subParser("makeMarkdown.strikethrough",function(r,u){var a="";if(r.hasChildNodes()){a+="~~";for(var d=r.childNodes,o=d.length,f=0;f<o;++f)a+=t.subParser("makeMarkdown.node")(d[f],u);a+="~~"}return a}),t.subParser("makeMarkdown.strong",function(r,u){var a="";if(r.hasChildNodes()){a+="**";for(var d=r.childNodes,o=d.length,f=0;f<o;++f)a+=t.subParser("makeMarkdown.node")(d[f],u);a+="**"}return a}),t.subParser("makeMarkdown.table",function(r,u){var a="",d=[[],[]],o=r.querySelectorAll("thead>tr>th"),f=r.querySelectorAll("tbody>tr"),l,p;for(l=0;l<o.length;++l){var T=t.subParser("makeMarkdown.tableCell")(o[l],u),v="---";if(o[l].hasAttribute("style")){var b=o[l].getAttribute("style").toLowerCase().replace(/\s/g,"");switch(b){case"text-align:left;":v=":---";break;case"text-align:right;":v="---:";break;case"text-align:center;":v=":---:";break}}d[0][l]=T.trim(),d[1][l]=v}for(l=0;l<f.length;++l){var _=d.push([])-1,c=f[l].getElementsByTagName("td");for(p=0;p<o.length;++p){var w=" ";typeof c[p]<"u"&&(w=t.subParser("makeMarkdown.tableCell")(c[p],u)),d[_].push(w)}}var A=3;for(l=0;l<d.length;++l)for(p=0;p<d[l].length;++p){var R=d[l][p].length;R>A&&(A=R)}for(l=0;l<d.length;++l){for(p=0;p<d[l].length;++p)l===1?d[l][p].slice(-1)===":"?d[l][p]=t.helper.padEnd(d[l][p].slice(-1),A-1,"-")+":":d[l][p]=t.helper.padEnd(d[l][p],A,"-"):d[l][p]=t.helper.padEnd(d[l][p],A);a+="| "+d[l].join(" | ")+` |
|
|
136
136
|
`}return a.trim()}),t.subParser("makeMarkdown.tableCell",function(r,u){var a="";if(!r.hasChildNodes())return"";for(var d=r.childNodes,o=d.length,f=0;f<o;++f)a+=t.subParser("makeMarkdown.node")(d[f],u,!0);return a.trim()}),t.subParser("makeMarkdown.txt",function(r){var u=r.nodeValue;return u=u.replace(/ +/g," "),u=u.replace(/¨NBSP;/g," "),u=t.helper.unescapeHTMLEntities(u),u=u.replace(/([*_~|`])/g,"\\$1"),u=u.replace(/^(\s*)>/g,"\\$1>"),u=u.replace(/^#/gm,"\\#"),u=u.replace(/^(\s*)([-=]{3,})(\s*)$/,"$1\\$2$3"),u=u.replace(/^( {0,3}\d+)\./gm,"$1\\."),u=u.replace(/^( {0,3})([+-])/gm,"$1\\$2"),u=u.replace(/]([\s]*)\(/g,"\\]$1\\("),u=u.replace(/^ {0,3}\[([\S \t]*?)]:/gm,"\\[$1]:"),u});var x=this;e.exports?e.exports=t:x.showdown=t}).call(Oe)})(aa);var ui=aa.exports;const ze=Vr(ui),at=/@(\d*|channel|editors):\((.*?)\)/,na=["channel","editors"],si=new RegExp(at,"i"),di=new RegExp(at,"gi");let ue;const Dr={color:{type:"lang",regex:/\((.*?)\)\[(rgb\((?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), ?)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), ?)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]))\))\]/gi,replace:(e,n)=>`<span style="color:${e.match(/\[(rgb\((?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), ?)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), ?)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]))\))\]/gi)[0].replace("[","").replace("]","")}">${n}</span>`},mention:{type:"lang",regex:di,replace:e=>{const n=e.match(si),i=n&&n.length>1&&n[1],t=n&&n.length>2&&n[2];return na.find(s=>s.toLowerCase()===String(i).toLowerCase())?`<a class="mention extraMention" data-user-id="${i}">@${t}</a>`:`<a class="mention" data-user-id="${i}">@${t}</a>`}},userMentioTag:{type:"lang",regex:/<user-mentio[^>]*>(.+?)<\/user-mentio>/gi,replace:e=>{const n=e.match(/<user-mentio[^>]*>(.+?)<\/user-mentio>/),i=e.match(/data-user-id=["']([^"]+)["']/),t=n&&n.length>1&&n[1];return`<a class="mention" data-user-id="${i&&i.length>1&&i[1]}">${t}</a>`}}};function oi(){return ue||(ze.extension("color",Dr.color),ze.extension("mention",Dr.mention),ze.extension("usermentiotag",Dr.userMentioTag),ue=new ze.Converter({extensions:["color","mention","usermentiotag"]}),ue.setOption("strikethrough",!0),ue.setOption("tables",!0),ue.setOption("openLinksInNewWindow",!0),ue.setOption("disableForced4SpacesIndentedSublists",!0),ue)}const ci=oi(),li=new RegExp(at,"gi"),fi=new RegExp(/<user-mentio[^>]*data-user-id=["']([^"]+)["'][^>]*>(?:@|(?:@))(.+?)<\/user-mentio>/,"gi"),Tt=(e,n,i)=>na.find(t=>t.toLowerCase()===String(n).toLowerCase())?`<a class="mention extraMention" data-user-id="${n}">@${i}</a>`:`<a class="mention" data-user-id="${n}">@${i}</a>`,pi=(e="")=>e.replace(li,Tt).replace(fi,Tt),hi=(e="")=>Nr(e,{whiteList:ca,css:{whiteList:{...Nr.getDefaultCSSWhiteList(),"vertical-align":!0}},stripIgnoreTag:!0}).replace(/ /g," ").replace(/\u2060/g,""),gi=(e="")=>{const n=/#(?:[0-9a-fA-F]{3}){1,2}|\brgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)|\brgba\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d*(?:\.\d+)?\s*\)/gi;return e.replace(n,i=>`${i}<span class="color-block" style="background-color: ${i};"></span>`)},mi=(e="")=>{try{return Gn(e,{target:"_blank",ignoreTags:["pre","code","script","style"],render:({tagName:n,attributes:i,content:t})=>{let s=t;if(s.length>85){const g=s.slice(0,40),m=s.slice(-40);s=`${g}[...]${m}`}const h=Object.keys(i).reduce((g,m)=>{const y=i[m];return`${g} ${m}="${y}"`});return`<${n} ${h}>${s}</${n}>`},validate:{url(n){return/^(http|ftp)s?:\/\//.test(n)}}})}catch{return e}},bi=(e="",n="html")=>{let i=st.shortToUnicode(e);return i=st.fixEmojioneBug(i),n==="markdown"?i=ci.makeHtml(i):i=pi(i),i=ta(i),i=yi(i),i=mi(i),i},vi=()=>{const e="ibmMonoOnDemand";if(!document.getElementById(e)){const n=document.createElement("style");n.id=e,n.appendChild(document.createTextNode(`@import url(${fa});`)),document.head.appendChild(n)}},At=(e="")=>e.replace(/[^\u0000-\u007E]/g,""),wi=(e="")=>{const n=/<pre\b[^>]*>\s*<code\b[^>]*>([\s\S]*?)<\/code>\s*<\/pre>/g;return e.replace(n,s=>s.replace(/<\/p>\s*<p>/g,`
|
|
137
|
-
`).replace(/<p>/g,"").replace(/<\/p>/g,"")).replace(n,s=>Nr(s,{whiteList:{pre:[],code:[]}}))},yi=e=>e.replace(/<(?![a-zA-Z\/!])/g,"<"),_i=(e,n,i)=>{try{let t;try{t=decodeURIComponent(n)}catch{t=n}const s=t.replace("#",""),h=e.querySelector(`[id="${s}"]`);h&&setTimeout(()=>{window.scrollTo({top:h.getBoundingClientRect().top-i,behavior:"smooth"}),h.classList.add("highlight"),setTimeout(()=>{h.classList.remove("highlight")},5e3)},500)}catch{}},ki=X.forwardRef(({content:e,type:n,widgetType:i="post",createAnchors:t,useHashAutoscroll:s,hashAutoscrollTopMargin:h=0,forceDefaultLinkTarget:g,inheritBrandingStyles:m=!1,addColorBlocks:y=!1,replaceLinkDomains:D=[],enabledLinkSafetyWarning:S=!1,safeLinkDomains:E=[],onSaveToClipboard:k,onTextSelected:q},L)=>{const P=X.useRef(null),z=X.useRef(!1),[j,H]=X.useState([]),x=X.useCallback(a=>{P.current=a,typeof L=="function"?L(a):L&&(L.current=a)},[L]),r=X.useCallback(()=>{const{hash:a}=window.location;if(P.current&&a){const d=Lt(a.substring(1));_i(P.current,`#${d}`,h)}},[h]);X.useEffect(()=>(s&&(r(),document.addEventListener("hashchange",r)),()=>{document.removeEventListener("hashchange",r)}),[s,r]),X.useEffect(()=>{if(!q||!P.current)return;const a=()=>{const o=window.getSelection();if(!o)return;const f=o.toString().trim();if(f.length===0)return;const p=o.getRangeAt(0).getBoundingClientRect(),T={x:p.x,y:p.y,width:p.width,height:p.height,top:p.top,left:p.left,bottom:p.bottom,right:p.right};q(f,T)},d=P.current;return d.addEventListener("mouseup",a),()=>{d.removeEventListener("mouseup",a)}},[q]),X.useLayoutEffect(()=>{if(!P.current||z.current)return;const a=()=>{if(!P.current||!g)return;const v=P.current.querySelectorAll("a")||[];if(v.length>0){const b=window.origin;v.forEach(_=>{const{href:c}=_;c.startsWith(b)?delete _.target:_.target="_blank"})}},d=()=>{P.current&&(P.current.querySelectorAll("a")||[]).forEach(v=>{const{href:b}=v;b.startsWith("mailto:")&&(v.target="_blank")})},o=()=>{const v=[...new Set([...ba,...E])];v.length===0||!S||!P.current||(P.current.querySelectorAll("a")||[]).forEach(b=>{const{href:_}=b,c=new URL(_),{hostname:w}=c;c.origin!==window.location.origin&&(v.some(A=>w.endsWith(A))&&!va.some(A=>w.endsWith(A))||(console.warn(`ContentRenderer: Unsafe link detected with hostname: ${w}`),b.setAttribute("title",`Warning. This link may be unsafe: ${_}`),b.classList.add("unsafe-link"),b.appendChild(document.createTextNode(" ⚠"))))})},f=()=>{if(!P.current)return;const v=P.current.querySelectorAll(ot);v.length>0&&(Er.isDefined("highlightjs")||(vi(),Er([...pa,...ha],"highlightjs")),Er.ready("highlightjs",()=>{window.hljs.configure({languages:ma,useBr:!0}),v.forEach(b=>{const _=b.innerText,c=document.createElement(ga),w=ta(_);c.textContent=w,b.innerHTML="",b.appendChild(c),window.hljs.highlightBlock(b)}),H(b=>[...b,...v])}))},l=()=>{D.length!==0&&D.forEach(({domainToReplace:v,domainToReplaceWith:b})=>{if(!P.current)return;const _=P.current.querySelectorAll("a")||[];_.length>0&&_.forEach(c=>{try{const{href:w}=c,A=new URL(w),{hostname:R}=A;if(R!==v||A.pathname==="/")return;if(b===""){const O=`${A.pathname}${A.search}${A.hash}`;c.href=O}else c.href=w.replace(v,b)}catch{}})})},p=()=>{P.current&&(P.current.querySelectorAll("iframe")||[]).forEach(v=>{const{referrerPolicy:b}=v;if(!b){v.referrerPolicy="strict-origin-when-cross-origin";const _=v.src;v.src="",v.src=_}})};requestAnimationFrame(()=>{a(),d(),f(),l(),o(),p(),s&&r()}),z.current=!0},[P,t,g,s,D,S,E,r]),X.useLayoutEffect(()=>{const a=()=>{if(!P.current||!t)return;const o=P.current.querySelectorAll("h1, h2, h3, h4, h5, h6")||[];o.length>0&&o.forEach(f=>{const{textContent:l=""}=f;(l||"").length>0&&(f.id=f.id||At((l||"").toLowerCase().replace(/\s/g,"-")))}),H(f=>[...f,...o])},d=()=>{if(!P.current)return;P.current.querySelectorAll("td, th").forEach(f=>{var p;const l=f.style.backgroundColor;if(l){const[T,v,b]=((p=l.match(/[.?\d]+/g))==null?void 0:p.map(w=>parseInt(w,10)))??[0,0,0],c=.2126*T+.7152*v+.0722*b>186?"light":"dark";f.style.colorScheme!==c&&f.style.setProperty("color-scheme",c)}else f.style.colorScheme&&f.style.removeProperty("color-scheme")})};a(),d()},[t,e]);const u=X.useMemo(()=>{const a=n&&typeof n=="string"?n.toLowerCase():"html";let d=a==="text"?`<p>${e}</p>`:bi(e,a);return y&&(d=gi(d)),d=wi(d),hi(d)},[e,n,y]);return fe.jsxs(fe.Fragment,{children:[fe.jsx(Ti,{className:`content-renderer ${i==="page"?"fr-view pages-text":""}`,ref:x,widgetType:i,createAnchors:t,hashAutoscrollTopMargin:s&&h,dangerouslySetInnerHTML:{__html:u},inheritBrandingStyles:m}),j.map(a=>{let d=a.textContent?At(a.textContent):"",o=!1;if(a.tagName!==ot){o=!0;const f=Pt(a);d=`${window.location.href.split("#")[0]}#${f}`}return ua.createPortal(fe.jsx(Ei,{className:"content-copy-btn",children:fe.jsx(ia.CopyToClipboardButton,{icon:o?fe.jsx(da,{}):void 0,colorScheme:"blank",clipboardCopyLabel:"Copy heading link",clipboardContent:d,onSaveToClipboard:k,hideSuccessTooltip:!!k})}),a)})]})}),Ei=he.div`
|
|
137
|
+
`).replace(/<p>/g,"").replace(/<\/p>/g,"")).replace(n,s=>Nr(s,{whiteList:{pre:[],code:[]}}))},yi=e=>e.replace(/<(?![a-zA-Z\/!])/g,"<"),_i=(e,n,i)=>{try{let t;try{t=decodeURIComponent(n)}catch{t=n}const s=t.replace("#",""),h=e.querySelector(`[id="${s}"]`);h&&setTimeout(()=>{window.scrollTo({top:h.getBoundingClientRect().top-i,behavior:"smooth"}),h.classList.add("highlight"),setTimeout(()=>{h.classList.remove("highlight")},5e3)},500)}catch{}},ki=X.forwardRef(({content:e,type:n,widgetType:i="post",createAnchors:t,useHashAutoscroll:s,hashAutoscrollTopMargin:h=0,forceDefaultLinkTarget:g,inheritBrandingStyles:m=!1,addColorBlocks:y=!1,replaceLinkDomains:D=[],enabledLinkSafetyWarning:S=!1,safeLinkDomains:E=[],onSaveToClipboard:k,onTextSelected:q},L)=>{const P=X.useRef(null),z=X.useRef(!1),[j,H]=X.useState([]),x=X.useCallback(a=>{P.current=a,typeof L=="function"?L(a):L&&(L.current=a)},[L]),r=X.useCallback(()=>{const{hash:a}=window.location;if(P.current&&a){const d=Lt(a.substring(1));_i(P.current,`#${d}`,h)}},[h]);X.useEffect(()=>(s&&(r(),document.addEventListener("hashchange",r)),()=>{document.removeEventListener("hashchange",r)}),[s,r]),X.useEffect(()=>{if(!q||!P.current)return;const a=()=>{const o=window.getSelection();if(!o)return;const f=o.toString().trim();if(f.length===0)return;const p=o.getRangeAt(0).getBoundingClientRect(),T={x:p.x,y:p.y,width:p.width,height:p.height,top:p.top,left:p.left,bottom:p.bottom,right:p.right};q(f,T)},d=P.current;return d.addEventListener("mouseup",a),()=>{d.removeEventListener("mouseup",a)}},[q]),X.useLayoutEffect(()=>{if(!P.current||z.current)return;const a=()=>{if(!P.current||!g)return;const v=P.current.querySelectorAll("a")||[];if(v.length>0){const b=window.origin;v.forEach(_=>{const{href:c}=_;c.startsWith(b)?delete _.target:_.target="_blank"})}},d=()=>{P.current&&(P.current.querySelectorAll("a")||[]).forEach(v=>{const{href:b}=v;b.startsWith("mailto:")&&(v.target="_blank")})},o=()=>{const v=[...new Set([...ba,...E])];v.length===0||!S||!P.current||(P.current.querySelectorAll("a")||[]).forEach(b=>{const{href:_}=b,c=new URL(_),{hostname:w}=c;c.origin!==window.location.origin&&(v.some(A=>w.endsWith(A))&&!va.some(A=>w.endsWith(A))||(console.warn(`ContentRenderer: Unsafe link detected with hostname: ${w}`),b.setAttribute("title",`Warning. This link may be unsafe: ${_}`),b.classList.add("unsafe-link"),b.appendChild(document.createTextNode(" ⚠"))))})},f=()=>{if(!P.current)return;const v=P.current.querySelectorAll(ot);v.length>0&&(Er.isDefined("highlightjs")||(vi(),Er([...pa,...ha],"highlightjs")),Er.ready("highlightjs",()=>{window.hljs.configure({languages:ma,useBr:!0}),v.forEach(b=>{const _=b.innerText,c=document.createElement(ga),w=ta(_);c.textContent=w,b.innerHTML="",b.appendChild(c),window.hljs.highlightBlock(b)}),H(b=>[...b,...v])}))},l=()=>{D.length!==0&&D.forEach(({domainToReplace:v,domainToReplaceWith:b})=>{if(!P.current)return;const _=P.current.querySelectorAll("a")||[];_.length>0&&_.forEach(c=>{try{const{href:w}=c,A=new URL(w),{hostname:R}=A;if(R!==v||A.pathname==="/")return;if(b===""){const O=`${A.pathname}${A.search}${A.hash}`;c.href=O}else c.href=w.replace(v,b)}catch{}})})},p=()=>{P.current&&(P.current.querySelectorAll("iframe")||[]).forEach(v=>{const{referrerPolicy:b}=v;if(!b){v.referrerPolicy="strict-origin-when-cross-origin";const _=v.src;v.src="",v.src=_}})};requestAnimationFrame(()=>{a(),d(),f(),l(),o(),p(),s&&r()}),z.current=!0},[P,t,g,s,D,S,E,r]),X.useLayoutEffect(()=>{const a=()=>{if(!P.current||!t)return;const o=P.current.querySelectorAll("h1, h2, h3, h4, h5, h6")||[];o.length>0&&o.forEach(f=>{const{textContent:l=""}=f;(l||"").length>0&&(f.id=f.id||At((l||"").toLowerCase().replace(/\s/g,"-")))}),H(f=>[...f,...o])},d=()=>{if(!P.current)return;P.current.querySelectorAll("td, th").forEach(f=>{var p;const l=f.style.backgroundColor;if(l){const[T,v,b]=((p=l.match(/[.?\d]+/g))==null?void 0:p.map(w=>parseInt(w,10)))??[0,0,0],c=.2126*T+.7152*v+.0722*b>186?"light":"dark";f.style.colorScheme!==c&&f.style.setProperty("color-scheme",c)}else f.style.colorScheme&&f.style.removeProperty("color-scheme")})};a(),d()},[t,e]);const u=X.useMemo(()=>{const a=n&&typeof n=="string"?n.toLowerCase():"html";let d=a==="text"?`<p>${e}</p>`:bi(e,a);return y&&(d=gi(d)),d=wi(d),hi(d)},[e,n,y]);return fe.jsxs(fe.Fragment,{children:[fe.jsx(Ti,{className:`content-renderer ${i==="page"?"fr-view pages-text":""}`,ref:x,widgetType:i,createAnchors:t,hashAutoscrollTopMargin:s&&h,dangerouslySetInnerHTML:{__html:u},inheritBrandingStyles:m}),j.map(a=>{if((a.textContent??"").trim().length===0)return null;let d=a.textContent?At(a.textContent):"",o=!1;if(a.tagName!==ot){o=!0;const f=Pt(a);d=`${window.location.href.split("#")[0]}#${f}`}return ua.createPortal(fe.jsx(Ei,{className:"content-copy-btn",children:fe.jsx(ia.CopyToClipboardButton,{icon:o?fe.jsx(da,{}):void 0,colorScheme:"blank",clipboardCopyLabel:"Copy heading link",clipboardContent:d,onSaveToClipboard:k,hideSuccessTooltip:!!k})}),a)})]})}),Ei=he.div`
|
|
138
138
|
position: absolute;
|
|
139
139
|
top: calc(50% - (32 / 2) * 1px);
|
|
140
140
|
right: 0;
|