UNPKG

md-editor-rt

Version:

Markdown editor for react, developed in jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...

2 lines (1 loc) 5.44 kB
"use strict";const g=require("./config.cjs"),S={copy:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy ${g.prefix}-icon"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,"collapse-tips":`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-chevron-left ${g.prefix}-icon"><circle cx="12" cy="12" r="10"/><path d="m14 16-4-4 4-4"/></svg>`,pin:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/></svg>',"pin-off":'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin-off"><path d="M12 17v5"/><path d="M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89"/><path d="m2 2 20 20"/><path d="M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11"/></svg>'},L=(d,c)=>typeof c[d]=="string"?c[d]:S[d],A=(d,c)=>{const e=l=>{const n=d.parentElement||document.body,o=n.offsetWidth,s=n.offsetHeight,{clientWidth:r,clientHeight:i}=document.documentElement,h=l.offsetX,E=l.offsetY,m=w=>{let u=w.x+document.body.scrollLeft-document.body.clientLeft-h,a=w.y+document.body.scrollTop-document.body.clientTop-E;u=u<1?1:u<r-o-1?u:r-o-1,a=a<1?1:a<i-s-1?a:i-s-1,c?c(u,a):(n.style.left=u+"px",n.style.top=a+"px")};document.addEventListener("mousemove",m);const p=()=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",p)};document.addEventListener("mouseup",p)};return d.addEventListener("mousedown",e),()=>{d.removeEventListener("mousedown",e)}},D=(d,c,e="")=>{var n;const l=document.getElementById(c.id);if(l)e!==""&&(Reflect.get(window,e)?(n=c.onload)==null||n.call(l,new Event("load")):c.onload&&l.addEventListener("load",c.onload));else{const o={...c};o.onload=null;const s=I(d,o);c.onload&&s.addEventListener("load",c.onload),document.head.appendChild(s)}},j=(d,c)=>{const e=document.getElementById(c.id);e==null||e.remove(),D(d,c)},I=(d,c)=>{const e=document.createElement(d);return Object.keys(c).forEach(l=>{c[l]!==void 0&&(e[l]=c[l])}),e},V=(()=>{const d=e=>{if(!e)return()=>{};const l=e.firstChild;let n=1,o=0,s=0,r=!1,i,h,E,m=1;const p=()=>{l.style.transform=`translate(${o}px, ${s}px) scale(${n})`},w=t=>{t.touches.length===1?(r=!0,i=t.touches[0].clientX-o,h=t.touches[0].clientY-s):t.touches.length===2&&(E=Math.hypot(t.touches[0].clientX-t.touches[1].clientX,t.touches[0].clientY-t.touches[1].clientY),m=n)},u=t=>{if(t.preventDefault(),r&&t.touches.length===1)o=t.touches[0].clientX-i,s=t.touches[0].clientY-h,p();else if(t.touches.length===2){const v=Math.hypot(t.touches[0].clientX-t.touches[1].clientX,t.touches[0].clientY-t.touches[1].clientY)/E,f=n;n=m*(1+(v-1));const x=(t.touches[0].clientX+t.touches[1].clientX)/2,y=(t.touches[0].clientY+t.touches[1].clientY)/2,T=l.getBoundingClientRect(),$=(x-T.left)/f,B=(y-T.top)/f;o-=$*(n-f),s-=B*(n-f),p()}},a=()=>{r=!1},k=t=>{t.preventDefault();const M=.02,v=n;t.deltaY<0?n+=M:n=Math.max(.1,n-M);const f=l.getBoundingClientRect(),x=t.clientX-f.left,y=t.clientY-f.top;o-=x/v*(n-v),s-=y/v*(n-v),p()},Y=t=>{r=!0,i=t.clientX-o,h=t.clientY-s},X=t=>{r&&(o=t.clientX-i,s=t.clientY-h,p())},H=()=>{r=!1},C=()=>{r=!1};return e.addEventListener("touchstart",w,{passive:!1}),e.addEventListener("touchmove",u,{passive:!1}),e.addEventListener("touchend",a),e.addEventListener("wheel",k,{passive:!1}),e.addEventListener("mousedown",Y),e.addEventListener("mousemove",X),e.addEventListener("mouseup",H),e.addEventListener("mouseleave",C),()=>{e.removeEventListener("touchstart",w),e.removeEventListener("touchmove",u),e.removeEventListener("touchend",a),e.removeEventListener("wheel",k),e.removeEventListener("mousedown",Y),e.removeEventListener("mousemove",X),e.removeEventListener("mouseup",H),e.removeEventListener("mouseleave",C)}};return(e,l)=>{const n=new Map;return e==null||e.forEach(o=>{let s=o.querySelector(`.${g.prefix}-mermaid-action`);s||(o.insertAdjacentHTML("beforeend",`<div class="${g.prefix}-mermaid-action">${L("pin-off",l.customIcon)}</div>`),s=o.querySelector(`.${g.prefix}-mermaid-action`));const r=()=>{const i=n.get(o);if(i!=null&&i.removeEvent)i.removeEvent(),o.removeAttribute("data-grab"),n.set(o,{removeClick:i.removeClick}),s.innerHTML=L("pin-off",l.customIcon);else{const h=d(o);o.setAttribute("data-grab",""),n.set(o,{removeEvent:h,removeClick:i==null?void 0:i.removeClick}),s.innerHTML=L("pin",l.customIcon)}};s.addEventListener("click",r),n.set(o,{removeClick:()=>s.removeEventListener("click",r)})}),()=>{n.forEach(({removeEvent:o,removeClick:s})=>{o==null||o(),s==null||s()}),n.clear()}}})();exports.StrIcon=L;exports.appendHandler=D;exports.keyMove=A;exports.updateHandler=j;exports.zoomMermaid=V;