UNPKG

@tarojs/components

Version:
1 lines 825 B
import{r as t,h as r,H as e}from"./p-f05e1558.js";let n=class{constructor(e){t(this,e),this.renderNode=t=>{if("type"in t&&"text"===t.type)return(t.text||"").replace(/ /g," ");if("name"in t&&t.name){const{name:e,attrs:n,children:s}=t,o={};let i=[];if(n&&"object"==typeof n)for(const t in n){const r=n[t];if("style"!==t||"string"!=typeof r)o[t]=r;else{const t=r.split(";").map((t=>t.trim())).filter((t=>t)),e={};t.forEach((t=>{if(!t)return;const r=/(.+): *(.+)/g.exec(t);if(!r)return;const[,n,s]=r,o=n.replace(/-([a-z])/g,((...t)=>t[1].toUpperCase()));e[o]=s})),Object.keys(e).length&&(o.style=e)}}return s&&s.length&&(i=s.map((t=>this.renderNode(t)))),r(e,o,i)}return null}}render(){const{nodes:t,renderNode:n}=this;return Array.isArray(t)?r(e,null,t.map((t=>n(t)))):r(e,{innerHTML:t})}};export{n as taro_rich_text_core}