Files
weiyu/deploy/server/notebase/assets/createText-2e5e7dd3-CI9FmsDJ.js
jack ning 537c32ea09 update
2025-02-16 20:45:30 +08:00

6 lines
4.0 KiB
JavaScript

import{l as b,as as T,at as W}from"./mermaid.core-DmGfg-wx.js";import{a7 as x}from"./index-CveFvPTx.js";function E(n){const t=n.replace(/\n{2,}/g,`
`);return W(t)}function w(n){const t=E(n),{children:e}=x(t),o=[[]];let i=0;function s(r,a="normal"){r.type==="text"?r.value.split(`
`).forEach((l,p)=>{p!==0&&(i++,o.push([])),l.split(" ").forEach(f=>{f&&o[i].push({content:f,type:a})})}):(r.type==="strong"||r.type==="emphasis")&&r.children.forEach(c=>{s(c,r.type)})}return e.forEach(r=>{r.type==="paragraph"&&r.children.forEach(a=>{s(a)})}),o}function S(n){const{children:t}=x(n);function e(o){return o.type==="text"?o.value.replace(/\n/g,"<br/>"):o.type==="strong"?`<strong>${o.children.map(e).join("")}</strong>`:o.type==="emphasis"?`<em>${o.children.map(e).join("")}</em>`:o.type==="paragraph"?`<p>${o.children.map(e).join("")}</p>`:`Unsupported markdown: ${o.type}`}return t.map(e).join("")}function j(n){return Intl.Segmenter?[...new Intl.Segmenter().segment(n)].map(t=>t.segment):[...n]}function v(n,t){const e=j(t.content);return g(n,[],e,t.type)}function g(n,t,e,o){if(e.length===0)return[{content:t.join(""),type:o},{content:"",type:o}];const[i,...s]=e,r=[...t,i];return n([{content:r.join(""),type:o}])?g(n,r,s,o):(t.length===0&&i&&(t.push(i),e.shift()),[{content:t.join(""),type:o},{content:e.join(""),type:o}])}function L(n,t){if(n.some(({content:e})=>e.includes(`
`)))throw new Error("splitLineToFitWidth does not support newlines in the line");return h(n,t)}function h(n,t,e=[],o=[]){if(n.length===0)return o.length>0&&e.push(o),e.length>0?e:[];let i="";n[0].content===" "&&(i=" ",n.shift());const s=n.shift()??{content:" ",type:"normal"},r=[...o];if(i!==""&&r.push({content:i,type:"normal"}),r.push(s),t(r))return h(n,t,e,r);if(o.length>0)e.push(o),n.unshift(s);else if(s.content){const[a,c]=v(t,s);e.push([a]),c.content&&n.unshift(c)}return h(n,t,e)}function $(n,t){t&&n.attr("style",t)}function k(n,t,e,o,i=!1){const s=n.append("foreignObject"),r=s.append("xhtml:div"),a=t.label,c=t.isNode?"nodeLabel":"edgeLabel";r.html(`
<span class="${c} ${o}" `+(t.labelStyle?'style="'+t.labelStyle+'"':"")+">"+a+"</span>"),$(r,t.labelStyle),r.style("display","table-cell"),r.style("white-space","nowrap"),r.style("max-width",e+"px"),r.attr("xmlns","http://www.w3.org/1999/xhtml"),i&&r.attr("class","labelBkg");let l=r.node().getBoundingClientRect();return l.width===e&&(r.style("display","table"),r.style("white-space","break-spaces"),r.style("width",e+"px"),l=r.node().getBoundingClientRect()),s.style("width",l.width),s.style("height",l.height),s.node()}function m(n,t,e){return n.append("tspan").attr("class","text-outer-tspan").attr("x",0).attr("y",t*e-.1+"em").attr("dy",e+"em")}function M(n,t,e){const o=n.append("text"),i=m(o,1,t);d(i,e);const s=i.node().getComputedTextLength();return o.remove(),s}function H(n,t,e){var o;const i=n.append("text"),s=m(i,1,t);d(s,[{content:e,type:"normal"}]);const r=(o=s.node())==null?void 0:o.getBoundingClientRect();return r&&i.remove(),r}function R(n,t,e,o=!1){const s=t.append("g"),r=s.insert("rect").attr("class","background"),a=s.append("text").attr("y","-10.1");let c=0;for(const l of e){const p=u=>M(s,1.1,u)<=n,f=p(l)?[l]:L(l,p);for(const u of f){const y=m(a,c,1.1);d(y,u),c++}}if(o){const l=a.node().getBBox(),p=2;return r.attr("x",-p).attr("y",-p).attr("width",l.width+2*p).attr("height",l.height+2*p),s.node()}else return a.node()}function d(n,t){n.text(""),t.forEach((e,o)=>{const i=n.append("tspan").attr("font-style",e.type==="emphasis"?"italic":"normal").attr("class","text-inner-tspan").attr("font-weight",e.type==="strong"?"bold":"normal");o===0?i.text(e.content):i.text(" "+e.content)})}const I=(n,t="",{style:e="",isTitle:o=!1,classes:i="",useHtmlLabels:s=!0,isNode:r=!0,width:a=200,addSvgBackground:c=!1}={})=>{if(b.info("createText",t,e,o,i,s,r,c),s){const l=S(t),p={isNode:r,label:T(l).replace(/fa[blrs]?:fa-[\w-]+/g,u=>`<i class='${u.replace(":"," ")}'></i>`),labelStyle:e.replace("fill:","color:")};return k(n,p,a,i,c)}else{const l=w(t);return R(a,n,l,c)}};export{I as a,H as c};