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.36 kB
JavaScript
const w=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 ${w.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 ${w.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=(i,s)=>typeof s[i]=="string"?s[i]:S[i],A=(i,s)=>{const t=l=>{const o=i.parentElement||document.body,n=o.offsetWidth,c=o.offsetHeight,{clientWidth:r,clientHeight:d}=document.documentElement,h=l.offsetX,g=l.offsetY,f=E=>{let u=E.x+document.body.scrollLeft-document.body.clientLeft-h,a=E.y+document.body.scrollTop-document.body.clientTop-g;u=u<1?1:u<r-n-1?u:r-n-1,a=a<1?1:a<d-c-1?a:d-c-1,s?s(u,a):(o.style.left=u+"px",o.style.top=a+"px")};document.addEventListener("mousemove",f);const v=()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",v)};document.addEventListener("mouseup",v)};return i.addEventListener("mousedown",t),()=>{i.removeEventListener("mousedown",t)}},D=(i,s,t="")=>{const l=document.getElementById(s.id);if(l)t!==""&&(Reflect.get(window,t)?s.onload?.call(l,new Event("load")):s.onload&&l.addEventListener("load",s.onload));else{const o={...s};o.onload=null;const n=I(i,o);s.onload&&n.addEventListener("load",s.onload),document.head.appendChild(n)}},j=(i,s)=>{document.getElementById(s.id)?.remove(),D(i,s)},I=(i,s)=>{const t=document.createElement(i);return Object.keys(s).forEach(l=>{s[l]!==void 0&&(t[l]=s[l])}),t},V=(()=>{const i=t=>{if(!t)return()=>{};const l=t.firstChild;let o=1,n=0,c=0,r=!1,d,h,g,f=1;const v=()=>{l.style.transform=`translate(${n}px, ${c}px) scale(${o})`},E=e=>{e.touches.length===1?(r=!0,d=e.touches[0].clientX-n,h=e.touches[0].clientY-c):e.touches.length===2&&(g=Math.hypot(e.touches[0].clientX-e.touches[1].clientX,e.touches[0].clientY-e.touches[1].clientY),f=o)},u=e=>{if(e.preventDefault(),r&&e.touches.length===1)n=e.touches[0].clientX-d,c=e.touches[0].clientY-h,v();else if(e.touches.length===2){const m=Math.hypot(e.touches[0].clientX-e.touches[1].clientX,e.touches[0].clientY-e.touches[1].clientY)/g,p=o;o=f*(1+(m-1));const k=(e.touches[0].clientX+e.touches[1].clientX)/2,x=(e.touches[0].clientY+e.touches[1].clientY)/2,T=l.getBoundingClientRect(),$=(k-T.left)/p,B=(x-T.top)/p;n-=$*(o-p),c-=B*(o-p),v()}},a=()=>{r=!1},y=e=>{e.preventDefault();const M=.02,m=o;e.deltaY<0?o+=M:o=Math.max(.1,o-M);const p=l.getBoundingClientRect(),k=e.clientX-p.left,x=e.clientY-p.top;n-=k/m*(o-m),c-=x/m*(o-m),v()},Y=e=>{r=!0,d=e.clientX-n,h=e.clientY-c},X=e=>{r&&(n=e.clientX-d,c=e.clientY-h,v())},C=()=>{r=!1},H=()=>{r=!1};return t.addEventListener("touchstart",E,{passive:!1}),t.addEventListener("touchmove",u,{passive:!1}),t.addEventListener("touchend",a),t.addEventListener("wheel",y,{passive:!1}),t.addEventListener("mousedown",Y),t.addEventListener("mousemove",X),t.addEventListener("mouseup",C),t.addEventListener("mouseleave",H),()=>{t.removeEventListener("touchstart",E),t.removeEventListener("touchmove",u),t.removeEventListener("touchend",a),t.removeEventListener("wheel",y),t.removeEventListener("mousedown",Y),t.removeEventListener("mousemove",X),t.removeEventListener("mouseup",C),t.removeEventListener("mouseleave",H)}};return(t,l)=>{const o=new Map;return t?.forEach(n=>{let c=n.querySelector(`.${w.prefix}-mermaid-action`);c||(n.insertAdjacentHTML("beforeend",`<div class="${w.prefix}-mermaid-action">${L("pin-off",l.customIcon)}</div>`),c=n.querySelector(`.${w.prefix}-mermaid-action`));const r=()=>{const d=o.get(n);if(d?.removeEvent)d.removeEvent(),n.removeAttribute("data-grab"),o.set(n,{removeClick:d.removeClick}),c.innerHTML=L("pin-off",l.customIcon);else{const h=i(n);n.setAttribute("data-grab",""),o.set(n,{removeEvent:h,removeClick:d?.removeClick}),c.innerHTML=L("pin",l.customIcon)}};c.addEventListener("click",r),o.set(n,{removeClick:()=>c.removeEventListener("click",r)})}),()=>{o.forEach(({removeEvent:n,removeClick:c})=>{n?.(),c?.()}),o.clear()}}})();exports.StrIcon=L;exports.appendHandler=D;exports.keyMove=A;exports.updateHandler=j;exports.zoomMermaid=V;
;