@neosjs/screen-shot
Version:
JS截屏插件
6 lines • 55.8 kB
JavaScript
/*!
* @neosjs/screen-shot
* Version: 1.1.0
* ReleaseTime: 2025/4/18 15:48:49
*/import Xt from"html2canvas";const Wt=[{id:1,title:"square"},{id:2,title:"round"},{id:3,title:"right-top"},{id:4,title:"brush"},{id:5,title:"mosaicPen"},{id:6,title:"text"},{id:7,title:"separateLine"},{id:8,title:"save"},{id:9,title:"undo"},{id:10,title:"close"},{id:11,title:"confirm"}];function Nt(e){let t="";switch(e){case 1:t="square-active";break;case 2:t="round-active";break;case 3:t="right-top-active";break;case 4:t="brush-active";break;case 5:t="mosaicPen-active";break;case 6:t="text-active"}return t}function Vt(e){let t="";switch(e){case 1:t="brush-small-active";break;case 2:t="brush-medium-active";break;case 3:t="brush-big-active";break}return t}function j(e,t,o){let n=Nt(t);o&&(n=Vt(t));const i=(e.path||e.composedPath&&e.composedPath())[1].children;for(let r=0;r<i.length;r++){const s=i[r];s.className.includes("active")&&s.classList.remove(s.classList[2])}e.target.className+=" "+n}function Ut(e){switch(e){case 1:return 16;case 2:return 24*2+8;case 3:return 24*4-6;case 4:return 24*5+8;case 5:return 24*7+6;case 6:return 24*9-6;default:return 0}}function It(){var e;const t=new B;t.popHistory();const o=(e=t.getScreenShotContainer())==null?void 0:e.getContext("2d");o!=null&&t.getHistory().length>0&&o.putImageData(t.getHistory()[t.getHistory().length-1].data,0,0),t.setUndoClickNum(t.getUndoClickNum()+1),t.getHistory().length-1<=0&&(t.setUndoClickNum(0),t.setUndoStatus(!1))}function _(e,t,o=document.body){const n=o.getBoundingClientRect();return{left:e||Math.abs(n.left),top:t||Math.abs(n.top)}}let K=!1,q=null,W=!1,Z=0,J=0,Q=!1,tt=null;const R={r:0,g:0,b:0,a:.3};let et=!0,ot="#6cb6ff",nt=!1,it=15,rt=!1,st=!1,lt=null,at=null,E=class{constructor(){W&&(K=!1,Z=0,J=0,ot="#6cb6ff",nt=!1,Q=!1,et=!0,q=null,W=!1,tt=null,lt=null,it=15,rt=!1,st=!1,at=null)}setInitStatus(t){W=t}getInitStatus(){return W}getWebRtcStatus(){return K}setWebRtcStatus(t){K=t}setScreenShotDom(t){tt=t}getCutBoxBdColor(){return ot}setCutBoxBdColor(t){ot=t}getCutDotRound(){return nt}setCutDotRound(t){nt=t}getScreenShotDom(){return tt}getScreenFlow(){return q}setScreenFlow(t){q=t}getCanvasSize(){return{canvasWidth:Z,canvasHeight:J}}setCanvasSize(t,o){Z=t,J=o}getShowScreenDataStatus(){return Q}setShowScreenDataStatus(t){Q=t}setMaskColor(t){R.r=t.r,R.g=t.g,R.b=t.b,R.a=t.a}getMaskColor(){return R}setWriteImgState(t){et=t}getWriteImgState(){return et}setSaveCallback(t){lt=t}getSaveCallback(){return lt}setMaxUndoNum(t){it=t}getMaxUndoNum(){return it}setRatioArrow(t){rt=t}getRatioArrow(){return rt}setImgAutoFit(t){st=t}getImgAutoFit(){return st}setSaveImgTitle(t){at=t}getSaveImgTitle(){return at}};const N=["#f03e3e","#1c7ed6","#37b24d","#f59f00","#ae3ec9","#F66632","#000000","#FEFFFF"];let bt=!1,ht=!1,ct=!1,ut="#f03e3e",dt="",gt=2,pt=10,Bt=6,mt=0,Y=[];const jt=!1;let St=!1,A={startX:0,startY:0,width:0,height:0},y=null,P=null,I=null,D=null,x=null,O=null,z=null,M=null,Ct=18,b=null,F=null,H=null,ft=null,k=null,kt=null,V=!1,vt=!1,Tt="",Et,U=!1,wt=!1;class B{constructor(){vt&&(vt=!1,y=null,ht=!1,P=null,D=null,b=null,x=null,O=null,z=null,M=null,I=null,A={startX:0,startY:0,width:0,height:0},ct=!1,U=!1,wt=!1,St=!1,ut="#F53340",dt="",gt=2,Ct=18,pt=10,Y=[],mt=0,F=null,H=null,ft=null,k=null)}setInitStatus(t){vt=t}setScreenShotInfo(t,o){this.getScreenShotContainer(),y!=null&&(V&&document.body.classList.add("__screenshot-lock-scroll"),y.width=t,y.height=o)}setScreenShotPosition(t,o){if(this.getScreenShotContainer(),y==null)return;const{left:n,top:i}=_(t,o);y.style.left=n+"px",y.style.top=i+"px"}showScreenShotPanel(){this.getScreenShotContainer(),y!=null&&(y.style.display="block")}getScreenShotContainer(){return y=document.getElementById("screenShotContainer"),y}getToolController(){return P=document.getElementById("toolPanel"),P}getCutBoxSizeContainer(){return I=document.getElementById("cutBoxSizePanel"),I}getTextInputController(){return D=document.getElementById("textInputPanel"),D}getTextStatus(){return jt}getScreenShotImageController(){return kt}setScreenShotImageController(t){kt=t}setToolStatus(t){if(P=this.getToolController(),t){P.style.display="flex";return}P.style.display="none"}setCutBoxSizeStatus(t){if(I!=null){if(t){I.style.display="flex";return}I.style.display="none"}}setCutBoxSizePosition(t,o){if(I==null)return;const{left:n,top:i}=_(t,o);I.style.left=n+"px";let r=0;y&&(r=parseInt(y.style.top)),I.style.top=i+r+"px"}setTextEditState(t){wt=t}getTextEditState(){return wt}setCutBoxSize(t,o){if(I==null)return;t=Math.floor(t),o=Math.floor(o);const n=I.childNodes;if(n.length>0){n[0].innerText=`${t} * ${o}`;return}const i=document.createElement("p");i.innerText=`${t} * ${o}`,I.appendChild(i)}setTextStatus(t){if(D=this.getTextInputController(),D!=null){if(t){D.style.display="block";return}D.style.display="none"}}setToolInfo(t,o){P=document.getElementById("toolPanel");const{left:n,top:i}=_(t,o);P.style.left=n+"px";let r=0;y&&(r=parseInt(y.style.top)),P.style.top=i+r+"px"}getToolClickStatus(){return ct}setToolClickStatus(t){ct=t}setResetScrollbarState(t){U=t}getResetScrollbarState(){return U}getCutOutBoxPosition(){return A}getDragging(){return ht}setDragging(t){ht=t}getDraggingTrim(){return bt}getToolPositionStatus(){return St}setToolPositionStatus(t){St=t}setDraggingTrim(t){bt=t}setCutOutBoxPosition(t,o,n,i){A.startX=t,A.startY=o,A.width=n,A.height=i}setFontSize(t){Ct=t}setOptionStatus(t){if(x=this.getOptionIcoController(),b=this.getOptionController(),!(x==null||b==null)){if(t){x.style.display="block",b.style.display="flex";return}x.style.display="none",b.style.display="none"}}getFontSize(){return Ct}setTextSizeOptionStatus(t){if(O=this.getOptionTextSizeController(),O!=null){if(t){O.style.display="flex";return}O.style.display="none"}}setTextSizePanelStatus(t){if(M=this.getTextSizeContainer(),M!=null){if(t){console.log("\u663E\u793A"),M.style.display="flex";return}M.style.display="none"}}setBrushSelectionStatus(t){if(z=this.getBrushSelectionController(),z!=null){if(t){z.style.display="flex";return}z.style.display="none"}}hiddenOptionIcoStatus(){x=this.getOptionIcoController(),x!=null&&(x.style.display="none")}getOptionIcoController(){return x=document.getElementById("optionIcoController"),x}getTextSizeContainer(){return M=document.getElementById("textSizePanel"),M}getOptionTextSizeController(){return O=document.getElementById("textSelectPanel"),O}getBrushSelectionController(){return z=document.getElementById("brushSelectPanel"),z}getOptionController(){return b=document.getElementById("optionPanel"),b}setOptionPosition(t){if(x=this.getOptionIcoController(),b=this.getOptionController(),x==null||b==null)return;const o=this.getToolPosition();if(o==null)return;const n=o.left+t+"px",i=o.top+44+"px",r=o.left+"px",s=o.top+44+6+"px";x.style.left=n,x.style.top=i,b.style.left=r,b.style.top=s}getToolPosition(){if(P=this.getToolController(),P!=null)return{left:P.offsetLeft,top:P.offsetTop}}getSelectedColor(){return ut}setSelectedColor(t,o){ut=t,this.setColorSelectPanel(o)}setColorSelectPanel(t){for(let n=0;n<N.length;n++){const i=document.getElementById(`colorItem_${n}`);if(i==null)return;i.style.borderColor="transparent"}const o=document.getElementById(`colorItem_${t}`);o!=null&&(o.style.borderColor="#fff")}getColorSelectPanel(){return ft=document.getElementById("colorSelectPanel"),ft}getToolName(){return dt}setToolName(t){dt=t}getPenSize(){return gt}setPenSize(t){gt=t}getMosaicPenSize(){return pt}setMosaicPenSize(t){pt=t}getBorderSize(){return Bt}setBorderSize(t){Bt=t||6}getHistory(){return Y}shiftHistory(){return Y.shift()}popHistory(){return Y.pop()}pushHistory(t){Y.push(t)}getUndoClickNum(){return mt}setUndoClickNum(t){mt=t}getColorPanel(){return F=document.getElementById("colorPanel"),F}setColorPanelStatus(t){if(F=this.getColorPanel(),F!=null){if(t){F.style.display="flex";return}F.style.display="none"}}getNoScrollStatus(){return V}setNoScrollStatus(t){t!=null&&(V=t)}setActiveToolName(t){Tt=t}getActiveToolName(){return Tt}setTextInfo(t){Et=t}getTextInfo(){return Et}getRightPanel(){return H=document.getElementById("rightPanel"),H}setRightPanel(t){if(H=this.getRightPanel(),H!=null){if(t){H.style.display="flex";return}H.style.display="none"}}setUndoStatus(t){if(k=this.getUndoController(),k!=null){if(t){k.classList.add("undo"),k.classList.remove("undo-disabled"),k.addEventListener("click",this.cancelEvent);return}k.classList.add("undo-disabled"),k.classList.remove("undo"),k.removeEventListener("click",this.cancelEvent)}}cancelEvent(){It()}getUndoController(){return k=document.getElementById("undoPanel"),k}destroyDOM(){if(y==null||P==null||x==null||b==null||D==null||I==null)return;const t=new E;V&&document.body.classList.remove("__screenshot-lock-scroll"),document.body.removeChild(y),document.body.removeChild(P),document.body.removeChild(x),document.body.removeChild(b),document.body.removeChild(D),document.body.removeChild(I),document.body.classList.contains("no-cursor")&&document.body.classList.remove("no-cursor"),U&&(document.documentElement.classList.remove("hidden-screen-shot-scroll"),document.body.classList.remove("hidden-screen-shot-scroll")),t.setInitStatus(!0)}}function $(e,t,o){const n=window.devicePixelRatio||1;e.width=Math.round(t*n),e.height=Math.round(o*n),e.style.width=t+"px",e.style.height=o+"px";const i=e.getContext("2d");return i&&i.scale(n,n),i}function _t(e,t,o,n,i){const r=new E,s=window.devicePixelRatio||1,l=e.getImageData(t*s,o*s,n*s,i*s),a=document.createElement("canvas"),h=$(a,n,i);if(h){h.putImageData(l,0,0);const c=document.createElement("a");c.href=a.toDataURL("png");const p=(r==null?void 0:r.getSaveImgTitle())||new Date().getTime();c.download=`${p}.png`,c.click()}}function Kt(e,t,o,n,i,r=100,s=!0){const l=window.devicePixelRatio||1,a=e.getImageData(t*l,o*l,n*l,i*l),h=document.createElement("canvas"),c=$(h,n,i);return c?(c.putImageData(a,0,0),s&&(h==null||h.toBlob(p=>{var d;if(p==null)return;const C=window.ClipboardItem;if(C==null)return h.toDataURL("png");const S=new C({[p.type]:p});(d=navigator.clipboard)==null||d.write([S]).then(()=>"\u5199\u5165\u6210\u529F")},"image/png",r)),h.toDataURL("png")):""}function Dt(e){var t;const o=new B,n=new E,i=(t=o.getScreenShotContainer())==null?void 0:t.getContext("2d"),{startX:r,startY:s,width:l,height:a}=o.getCutOutBoxPosition();let h="";return i&&(e?_t(i,r,s,l,a):h=Kt(i,r,s,l,a,100,n.getWriteImgState())),h}function G(e,t,o,n,i,r,s,l,a=!0){const h=s==null?void 0:s.width,c=s==null?void 0:s.height,p=window.devicePixelRatio||1,d=new E,C=d.getCutDotRound();if(!h||!c||!l||!s)return;i.clearRect(0,0,h,c),o=o!=0?o:5,n=n!=0?n:5,i.save();const S=d.getMaskColor();if(i.fillStyle="rgba(0, 0, 0, .5)",S&&(i.fillStyle=`rgba(${S.r}, ${S.g}, ${S.b}, ${S.a})`),i.fillRect(0,0,h,c),i.globalCompositeOperation="source-atop",i.clearRect(e,t,o,n),i.globalCompositeOperation="source-over",i.strokeStyle=d.getCutBoxBdColor(),i.strokeRect(e-1,t-1,o+2,n+2),i.closePath(),a){i.fillStyle=d.getCutBoxBdColor();let u=r;C?(u=r/2,i.strokeStyle=d.getCutBoxBdColor(),i.beginPath(),i.arc(e,t,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/2+o/2,t,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/10+o,t,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/10,t-u/2+n/2,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/10+o,t-u/2+n/2,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/10,t-u/5+n,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/2+o/2,t+n,u,0,2*Math.PI),i.fill(),i.stroke(),i.beginPath(),i.arc(e-u/10+o,t-u/5+n,u,0,2*Math.PI),i.fill(),i.stroke()):(i.fill(),i.fillRect(e-u/2,t-u/2,u,u),i.fillRect(e-u/2+o/2,t-u/2,u,u),i.fillRect(e-u/2+o,t-u/2,u,u),i.fillRect(e-u/2,t-u/2+n/2,u,u),i.fillRect(e-u/2+o,t-u/2+n/2,u,u),i.fillRect(e-u/2,t-u/2+n,u,u),i.fillRect(e-u/2+o/2,t-u/2+n,u,u),i.fillRect(e-u/2+o,t-u/2+n,u,u),i.stroke())}i.restore(),i.save(),i.globalCompositeOperation="destination-over";let{imgWidth:f,imgHeight:m}={imgWidth:parseInt(s==null?void 0:s.style.width),imgHeight:parseInt(s==null?void 0:s.style.height)};const v=d.getScreenShotDom();return v!=null&&(f=v.clientWidth,m=v.clientHeight),!d.getWebRtcStatus()&&!d.getImgAutoFit()&&v==null&&(f=l.width/p,m=l.height/p),i.drawImage(l,0,0,f,m),i.restore(),o>0&&n>0?{startX:e,startY:t,width:o,height:n}:o<0&&n<0?{startX:e+o,startY:t+n,width:Math.abs(o),height:Math.abs(n)}:o>0&&n<0?{startX:e,startY:t+n,width:o,height:Math.abs(n)}:o<0&&n>0?{startX:e+o,startY:t,width:Math.abs(o),height:n}:{startX:e,startY:t,width:o,height:n}}function yt(e,t,o,n,i,r){r.save(),r.lineWidth=1,r.fillStyle=n,r.textBaseline="middle",r.font=`bold ${i}px none`;const s=e.split(`
`);console.log(s);const l=i*1.4;s.forEach((a,h)=>{const c=o+l*h;r.fillText(a,t,c)}),r.restore()}function X(){const e=new B,t=new E,o=e.getScreenShotContainer();if(o==null)return;const n=o.getContext("2d"),i=o;e.getHistory().length>t.getMaxUndoNum()&&e.shiftHistory(),e.pushHistory({data:n.getImageData(0,0,i.width,i.height)}),e.setUndoStatus(!0)}function qt(e,t,o,n,i){var r,s,l;const a=new B,h=new E,c=a.getTextInputController(),p=a.getScreenShotContainer(),d=a.getScreenShotImageController();if(a.setActiveToolName(e),p==null||d==null)return;const C=p.getContext("2d");if(!a.getToolClickStatus()){const S=((r=a.getToolPosition())==null?void 0:r.left)||0,f=((s=a.getToolPosition())==null?void 0:s.top)||0;f&&a.getToolPositionStatus()&&a.setToolInfo(S,f-46),a.setToolStatus(!0);const m=a.getCutOutBoxPosition();G(m.startX,m.startY,m.width,m.height,C,a.getBorderSize(),p,d,!1)}if(a.setToolName(e),j(o,t,!1),e==="text"?(a.setTextSizePanelStatus(!0),a.setBrushSelectionStatus(!1),(l=a.getColorSelectPanel())==null||l.classList.add("text-select-status")):(a.setTextSizePanelStatus(!1),a.setBrushSelectionStatus(!0)),a.setOptionStatus(!0),a.setOptionPosition(Ut(t)),a.setRightPanel(!0),e=="mosaicPen"&&(a.setRightPanel(!1),a.hiddenOptionIcoStatus()),c!=null&&a.getTextStatus()||c!=null&&e!=="text"){const S=c.innerText;if(S&&S!==""){const{positionX:f,positionY:m,color:v,size:u}=a.getTextInfo();yt(S,f,m,v,u,C),X()}c.innerHTML="",a.setTextStatus(!1)}if(a.setDragging(!1),a.setDraggingTrim(!1),e=="save"){Dt(!0);const S=h.getSaveCallback();S&&S(0,"\u4FDD\u5B58\u6210\u529F"),a.destroyDOM(),a.setInitStatus(!0)}if(e=="close"&&(i&&i(),a.destroyDOM(),a.setInitStatus(!0)),e=="confirm"){const S=Dt(!1);n&&n({base64:S,cutInfo:a.getCutOutBoxPosition()}),a.destroyDOM(),a.setInitStatus(!0)}e=="undo"&&(a.setOptionStatus(!1),It()),a.setToolClickStatus(!0)}function xt(e,t,o){const n=new B;j(o,t,!0);let i=2;switch(e){case"small":i=2;break;case"medium":i=5;break;case"big":i=10;break}return n.setPenSize(i),i}function Pt(e,t,o){const n=new B;j(o,t,!0);let i=10;switch(e){case"small":i=10;break;case"medium":i=20;break;case"big":i=40;break}return n.setMosaicPenSize(i),i}function Zt(e){const t=new B,o=N[e];return t.setSelectedColor(o,e),t.setColorPanelStatus(!0),o}function Jt(){new B().setTextSizeOptionStatus(!0)}function Qt(e){new B().setFontSize(e)}function te(){new B().setTextSizeOptionStatus(!1)}var ee=Object.defineProperty,oe=(e,t,o)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,T=(e,t,o)=>(oe(e,typeof t!="symbol"?t+"":t,o),o);class ne{constructor(t){T(this,"screenShotController"),T(this,"toolController"),T(this,"optionIcoController"),T(this,"optionController"),T(this,"cutBoxSizeContainer"),T(this,"textInputController"),T(this,"completeCallback"),T(this,"closeCallback"),T(this,"showIconArr"),T(this,"toolbar"),T(this,"textFontSizeList",[{name:"\u5927",value:28},{name:"\u4E2D",value:16},{name:"\u5C0F",value:12}]);var o;this.screenShotController=document.createElement("canvas"),this.toolController=document.createElement("div"),this.optionIcoController=document.createElement("div"),this.optionController=document.createElement("div"),this.cutBoxSizeContainer=document.createElement("div"),this.textInputController=document.createElement("div"),this.completeCallback=t==null?void 0:t.onComplete,this.closeCallback=t==null?void 0:t.onClose,this.showIconArr=["close"],this.optionController.addEventListener("click",n=>{const i=n.target;i.id==="colorSelectPanel"||i.id==="textSizePanel"||te()}),(!t||!Object.prototype.hasOwnProperty.call(t,"onComplete"))&&(this.completeCallback=n=>{sessionStorage.setItem("screenShotImg",JSON.stringify(n))}),(o=t==null?void 0:t.showToolIcon)!=null&&o.length&&t.showToolIcon.forEach(n=>this.showIconArr.push(n)),this.setAllControllerId(),this.setOptionIcoClassName(),this.toolbar=Wt,this.setToolBarIcon(t),this.setTextSizeSelectPanel(),this.setBrushSelectPanel(),this.setTextInputPanel(),this.setDomToBody(),this.hiddenAllDom()}setToolBarIcon(t){for(let o=0;o<this.toolbar.length;o++){const n=this.toolbar[o];let i=!0;for(let l=0;l<this.showIconArr.length;l++)if(this.showIconArr[l]===n.title){i=!1;break}if(i)continue;const r=document.createElement("div");r.className="tool-panel";const s=document.createElement("div");if(n.title=="undo"?(s.className="item-panel undo-disabled",s.id="undoPanel"):(s.className=`item-panel ${n.title}`,r.addEventListener("click",l=>{qt(n.title,n.id,l,this.completeCallback,this.closeCallback)})),t!=null&&t.confirmBtnText&&n.title==="confirm"){const l=document.createElement("span");l.innerHTML=t.confirmBtnText,r.className="tool-panel tool-panel--confirm",r.appendChild(l)}s.setAttribute("data-title",n.title),s.setAttribute("data-id",n.id+""),r.setAttribute("data-title",n.title),r.setAttribute("data-id",n.id+""),r.appendChild(s),this.toolController.appendChild(r)}this.showIconArr.length||(this.toolController.style.padding="0")}setTextSizeSelectPanel(){const t=document.createElement("div");t.className="text-size-panel",t.innerText="\u4E2D",t.id="textSizePanel";const o=document.createElement("div");o.className="text-select-panel",o.id="textSelectPanel";for(let n=0;n<this.textFontSizeList.length;n++){const i=document.createElement("div"),r=this.textFontSizeList[n];i.className="text-item",i.setAttribute("data-value",`${r.value}`),i.setAttribute("data-name",`${r.name}`),i.innerText=`${r.name}`,i.addEventListener("click",()=>{o.style.display="none";const s=i.getAttribute("data-value"),l=i.getAttribute("data-name");t.innerText=`${l}`,s&&Qt(+s)}),o.appendChild(i)}t.style.display="none",o.style.display="none",t.addEventListener("click",()=>{Jt()}),this.optionController.appendChild(t),this.optionController.appendChild(o)}setBrushSelectPanel(){const t=document.createElement("div");t.id="brushSelectPanel",t.className="brush-select-panel";for(let i=0;i<3;i++){const r=document.createElement("div");switch(r.className="item-panel",i){case 0:r.classList.add("brush-small"),r.classList.add("brush-small-active"),r.addEventListener("click",s=>{xt("small",1,s),Pt("small",1,s)});break;case 1:r.classList.add("brush-medium"),r.addEventListener("click",s=>{xt("medium",2,s),Pt("medium",2,s)});break;case 2:r.classList.add("brush-big"),r.addEventListener("click",s=>{xt("big",3,s),Pt("big",3,s)});break}t.appendChild(r)}const o=document.createElement("div");o.className="right-panel";const n=document.createElement("div");n.id="colorPanel",n.className="color-panel";for(let i=0;i<N.length;i++){const r=document.createElement("div");r.className="color-item",r.id=`colorItem_${i}`,r.style.backgroundColor=N[i],r.addEventListener("click",()=>Zt(i)),r.setAttribute("data-index",i+""),n.appendChild(r)}o.appendChild(n),o.id="rightPanel",this.optionController.appendChild(t),this.optionController.appendChild(o)}setTextInputPanel(){this.textInputController.contentEditable="true",this.textInputController.spellcheck=!1}setAllControllerId(){this.screenShotController.id="screenShotContainer",this.toolController.id="toolPanel",this.optionIcoController.id="optionIcoController",this.optionController.id="optionPanel",this.cutBoxSizeContainer.id="cutBoxSizePanel",this.textInputController.id="textInputPanel"}hiddenAllDom(){this.screenShotController.style.display="none",this.toolController.style.display="none",this.optionIcoController.style.display="none",this.optionController.style.display="none",this.cutBoxSizeContainer.style.display="none",this.textInputController.style.display="none"}setDomToBody(){this.clearBody(),document.body.appendChild(this.screenShotController),document.body.appendChild(this.toolController),document.body.appendChild(this.optionIcoController),document.body.appendChild(this.optionController),document.body.appendChild(this.cutBoxSizeContainer),document.body.appendChild(this.textInputController)}clearBody(){var t,o,n,i,r,s;(t=document.getElementById("screenShotContainer"))==null||t.remove(),(o=document.getElementById("toolPanel"))==null||o.remove(),(n=document.getElementById("optionIcoController"))==null||n.remove(),(i=document.getElementById("optionPanel"))==null||i.remove(),(r=document.getElementById("optionPanel"))==null||r.remove(),(s=document.getElementById("textInputPanel"))==null||s.remove()}setOptionIcoClassName(){this.optionIcoController.className="icon-panel"}}function ie(e,t){const o=new E,n=new E,i=n.getCanvasSize(),r={width:parseFloat(window.getComputedStyle(document.body).width),height:parseFloat(window.getComputedStyle(document.body).height)},s=Math.max(r.width||0,Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),Math.max(document.body.offsetWidth,document.documentElement.offsetWidth),Math.max(document.body.clientWidth,document.documentElement.clientWidth)),l=Math.max(r.height||0,Math.max(document.body.scrollHeight,document.documentElement.scrollHeight),Math.max(document.body.offsetHeight,document.documentElement.offsetHeight),Math.max(document.body.clientHeight,document.documentElement.clientHeight));e.clearRect(0,0,s,l),t!=null&&n.getShowScreenDataStatus()&&(i.canvasWidth!==0&&i.canvasHeight!==0?e.drawImage(t,0,0,i.canvasWidth,i.canvasHeight):e.drawImage(t,0,0,s,l)),e.save();const a=o.getMaskColor();e.fillStyle="rgba(0, 0, 0, .6)",a&&(e.fillStyle=`rgba(${a.r}, ${a.g}, ${a.b}, ${a.a})`),i.canvasWidth!==0&&i.canvasHeight!==0?e.fillRect(0,0,i.canvasWidth,i.canvasHeight):e.fillRect(0,0,s,l),e.restore()}function w(e){return e>0?e:0}function Ot(e,t,o){return w(e)+t>o?w(o-t):w(e)}function zt(e,t,o){return!(e<o.startX||t<o.startY||e>o.startX+o.width||t>o.startY+o.height)}var re=Object.defineProperty,se=(e,t,o)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,le=(e,t,o)=>(se(e,typeof t!="symbol"?t+"":t,o),o);class ae{constructor(t,o){le(this,"toolController",null);const n=new B,i=document.getElementById("textInputPanel");this.toolController=o,t.tabIndex=9999,document.body.addEventListener("keydown",r=>{if(n.getTextEditState()){n.setTextEditState(!1);return}r.code==="Escape"&&this.triggerEvent("close"),r.code==="Enter"&&i&&i.style.display!=="block"&&this.triggerEvent("confirm"),(r.metaKey||r.ctrlKey)&&r.code==="KeyZ"&&this.triggerEvent("undo")})}triggerEvent(t){if(this.toolController!=null)for(let o=0;o<this.toolController.childNodes.length;o++){const n=this.toolController.childNodes[o];n.getAttribute("data-title")===t&&n.click()}}}function he(e){const t=new E;(e==null?void 0:e.enableWebRtc)===!0&&t.setWebRtcStatus(!0),(e==null?void 0:e.screenFlow)instanceof MediaStream&&t.setScreenFlow(e.screenFlow),e!=null&&e.canvasWidth&&e!=null&&e.canvasHeight&&t.setCanvasSize(e.canvasWidth,e.canvasHeight),(e==null?void 0:e.showScreenData)===!0&&t.setShowScreenDataStatus(!0),e!=null&&e.maskColor&&typeof e.maskColor=="object"&&t.setMaskColor(e.maskColor),(e==null?void 0:e.writeBase64)===!1&&t.setWriteImgState(e.writeBase64),e!=null&&e.screenShotDom&&t.setScreenShotDom(e.screenShotDom),e!=null&&e.cutDotColor&&t.setCutBoxBdColor(e.cutDotColor),e!=null&&e.cutDotRound&&t.setCutDotRound(e.cutDotRound),e!=null&&e.onSave&&t.setSaveCallback(e.onSave),e!=null&&e.maxUndoNum&&t.setMaxUndoNum(e.maxUndoNum),e!=null&&e.useRatioArrow&&t.setRatioArrow(e.useRatioArrow),e!=null&&e.imgAutoFit&&t.setImgAutoFit(e.imgAutoFit),e!=null&&e.saveImgTitle&&t.setSaveImgTitle(e.saveImgTitle)}function ce(e,t,o,n,i){let r=(e.width-t)/2+(e.startX-i.left);n==="left"&&(r=e.startX),n==="right"&&(r=e.startX+e.width-t),r<0&&(r=0),r+t>o&&(r=o-t);let s=e.startY+e.height+10;return(e.width<0&&e.height<0||e.width>0&&e.height<0)&&(s=e.startY+10),s-=i.top,{mouseX:r,mouseY:s}}function ue(e){const t=[];return e.querySelectorAll("img").forEach(o=>{const n=o.getAttribute("src");if(!n||n&&n.startsWith("base64"))return;const i=new Promise((r,s)=>{const l=new Image;l.crossOrigin="anonymous",l.src=`${n}&time=${+new Date().getTime()}`,l.onload=function(){const a=o.width,h=o.height,c=document.createElement("canvas");c.width=a,c.height=h,c.getContext("2d").drawImage(l,0,0,a,h);const p=c==null?void 0:c.toDataURL();o.setAttribute("src",p),r("\u8F6C\u6362\u6210\u529F")},l.onerror=s,n!==null&&(l.src=n)});t.push(i)}),Promise.all(t)}function de(e,t,o,n,i){e.save(),e.lineWidth=n,e.strokeStyle=i,e.lineTo(t,o),e.stroke(),e.restore()}function ge(e,t,o){e.beginPath(),e.moveTo(t,o)}function pe(e,t,o,n,i,r,s){s.save(),s.strokeStyle=i,s.lineWidth=r,s.beginPath(),s.rect(e,t,o,n),s.stroke(),s.restore()}function me(e,t,o,n,i,r,s){const l=t<n?t:n,a=o<i?o:i,h=t>=n?t:n,c=o>=i?o:i,p=(h-l)*.5,d=(c-a)*.5,C=l+p,S=a+d;if(e.save(),e.beginPath(),e.lineWidth=r,e.strokeStyle=s,typeof e.ellipse=="function")e.ellipse(C,S,p,d,0,0,2*Math.PI);else throw"\u4F60\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301ellipse\uFF0C\u65E0\u6CD5\u7ED8\u5236\u692D\u5706";e.stroke(),e.closePath(),e.restore()}function Se(e,t,o,n,i,r,s,l,a){const h=Math.atan2(o-i,t-n)*180/Math.PI,c=(h+r)*Math.PI/180,p=(h-r)*Math.PI/180,d=s*Math.cos(c),C=s*Math.sin(c),S=s*Math.cos(p),f=s*Math.sin(p);e.save(),e.beginPath();let m=t-d,v=o-C;e.moveTo(m,v),e.moveTo(t,o),e.lineTo(n,i),m=n+d,v=i+C,e.moveTo(m,v),e.lineTo(n,i),m=n+S,v=i+f,e.lineTo(m,v),e.strokeStyle=a,e.lineWidth=l,e.stroke(),e.restore()}var Ce=Object.defineProperty,Mt=Math.pow,fe=(e,t,o)=>t in e?Ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,L=(e,t,o)=>(fe(e,typeof t!="symbol"?t+"":t,o),o);class ve{constructor(){L(this,"beginPoint",{x:0,y:0}),L(this,"stopPoint",{x:0,y:0}),L(this,"polygonVertex",[]),L(this,"angle",0),L(this,"arrowInfo",{edgeLen:50,angle:30}),L(this,"size",1)}draw(t,o,n,i,r,s,l){switch(this.beginPoint.x=o,this.beginPoint.y=n,this.stopPoint.x=i,this.stopPoint.y=r,this.arrowCord(this.beginPoint,this.stopPoint),this.sideCord(),this.drawArrow(t,s),l){case 2:this.size=1;break;case 5:this.size=1.3;break;case 10:this.size=1.7;break;default:this.size=1;break}}arrowCord(t,o){this.polygonVertex[0]=t.x,this.polygonVertex[1]=t.y,this.polygonVertex[6]=o.x,this.polygonVertex[7]=o.y,this.getRadian(t,o),this.polygonVertex[8]=o.x-this.arrowInfo.edgeLen*Math.cos(Math.PI/180*(this.angle+this.arrowInfo.angle)),this.polygonVertex[9]=o.y-this.arrowInfo.edgeLen*Math.sin(Math.PI/180*(this.angle+this.arrowInfo.angle)),this.polygonVertex[4]=o.x-this.arrowInfo.edgeLen*Math.cos(Math.PI/180*(this.angle-this.arrowInfo.angle)),this.polygonVertex[5]=o.y-this.arrowInfo.edgeLen*Math.sin(Math.PI/180*(this.angle-this.arrowInfo.angle))}getRadian(t,o){this.angle=Math.atan2(o.y-t.y,o.x-t.x)/Math.PI*180,this.setArrowInfo(50*this.size,30*this.size),this.dynArrowSize()}sideCord(){const t={x:0,y:0};t.x=(this.polygonVertex[4]+this.polygonVertex[8])/2,t.y=(this.polygonVertex[5]+this.polygonVertex[9])/2,this.polygonVertex[2]=(this.polygonVertex[4]+t.x)/2,this.polygonVertex[3]=(this.polygonVertex[5]+t.y)/2,this.polygonVertex[10]=(this.polygonVertex[8]+t.x)/2,this.polygonVertex[11]=(this.polygonVertex[9]+t.y)/2}setArrowInfo(t,o){this.arrowInfo.edgeLen=t,this.arrowInfo.angle=o}dynArrowSize(){const t=this.stopPoint.x-this.beginPoint.x,o=this.stopPoint.y-this.beginPoint.y,n=Math.sqrt(Mt(t,2)+Mt(o,2));n<50?this.arrowInfo.edgeLen=n/2:n<250?this.arrowInfo.edgeLen/=2:n<500&&(this.arrowInfo.edgeLen=this.arrowInfo.edgeLen*n/500)}drawArrow(t,o){t.fillStyle=o,t.beginPath(),t.moveTo(this.polygonVertex[0],this.polygonVertex[1]),t.lineTo(this.polygonVertex[2],this.polygonVertex[3]),t.lineTo(this.polygonVertex[4],this.polygonVertex[5]),t.lineTo(this.polygonVertex[6],this.polygonVertex[7]),t.lineTo(this.polygonVertex[8],this.polygonVertex[9]),t.lineTo(this.polygonVertex[10],this.polygonVertex[11]),t.closePath(),t.fill()}}const we=(e,t,o)=>{const n=e.width,i=e.data,r=[];return r[0]=i[4*(o*n+t)],r[1]=i[4*(o*n+t)+1],r[2]=i[4*(o*n+t)+2],r[3]=i[4*(o*n+t)+3],r},ye=(e,t,o,n)=>{const i=e.width,r=e.data;r[4*(o*i+t)]=n[0],r[4*(o*i+t)+1]=n[1],r[4*(o*i+t)+2]=n[2],r[4*(o*i+t)+3]=n[3]};function xe(e,t,o,n,i){const r=window.devicePixelRatio||1,s=i.getImageData(e*r,t*r,o*r,o*r),l=s.width,a=s.height,h=l/n,c=a/n;for(let p=0;p<c;p++)for(let d=0;d<h;d++){const C=we(s,d*n+Math.floor(Math.random()*n),p*n+Math.floor(Math.random()*n));for(let S=0;S<n;S++)for(let f=0;f<n;f++)ye(s,d*n+f,p*n+S,C)}i.putImageData(s,e*r,t*r)}function Pe(e,t){switch(t){case"text":e.style.cursor="text";break;default:e.style.cursor="default";break}}function Ie(e,t,o,n,i,r,s){let l,a,h,c=0;switch(s){case 2:return a=t-(n+r)>0?n+r:t,c=w(r-(t-n)),{tempStartX:o,tempStartY:a,tempWidth:i,tempHeight:c};case 3:return c=w(t-n),{tempStartX:o,tempStartY:n,tempWidth:i,tempHeight:c};case 4:return l=e-(o+i)>0?o+i:e,h=w(i-(e-o)),{tempStartX:l,tempStartY:n,tempWidth:h,tempHeight:r};case 5:return h=w(e-o),{tempStartX:o,tempStartY:n,tempWidth:h,tempHeight:r};case 6:return l=e-(o+i)>0?o+i:e,a=t-(n+r)>0?n+r:t,h=w(i-(e-o)),c=w(r-(t-n)),{tempStartX:l,tempStartY:a,tempWidth:h,tempHeight:c};case 7:return h=w(e-o),c=w(t-n),{tempStartX:o,tempStartY:n,tempWidth:h,tempHeight:c};case 8:return a=t-(n+r)>0?n+r:t,h=w(e-o),c=w(r-(t-n)),{tempStartX:o,tempStartY:a,tempWidth:h,tempHeight:c};case 9:return l=e-(o+i)>0?o+i:e,h=w(i-(e-o)),c=w(t-n),{tempStartX:l,tempStartY:n,tempWidth:h,tempHeight:c}}}function Ft(e,t){const{startX:o,startY:n,width:i,height:r}=t,s=e/2,l=[];return l[0]={x:o+s,y:n+s,width:i-e,height:r-e,index:1,option:1},l[1]={x:o+s,y:n,width:i-e,height:s,index:2,option:2},l[2]={x:o-s+i/2,y:n-s,width:e,height:s,index:2,option:2},l[3]={x:o+s,y:n-s+r,width:i-e,height:s,index:2,option:3},l[4]={x:o-s+i/2,y:n+r,width:e,height:s,index:2,option:3},l[5]={x:o,y:n+s,width:s,height:r-e,index:3,option:4},l[6]={x:o-s,y:n-s+r/2,width:s,height:e,index:3,option:4},l[7]={x:o-s+i,y:n+s,width:s,height:r-e,index:3,option:5},l[8]={x:o+i,y:n-s+r/2,width:s,height:e,index:3,option:5},l[9]={x:o-s,y:n-s,width:e,height:e,index:4,option:6},l[10]={x:o-s+i,y:n-s+r,width:e,height:e,index:4,option:7},l[11]={x:o-s+i,y:n-s,width:e,height:e,index:5,option:8},l[12]={x:o-s,y:n-s+r,width:e,height:e,index:5,option:9},l}function Ht(){const e=navigator.userAgent,t=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];let o=!0;for(let n=0;n<t.length;n++)if(e.indexOf(t[n])>0){o=!1;break}return o}function be(){const e="maxTouchPoints"in navigator&&navigator.maxTouchPoints>0,t="msMaxTouchPoints"in navigator&&navigator.msMaxTouchPoints>0,o="ontouchstart"in window,n=window.matchMedia&&window.matchMedia("(pointer: coarse)").matches;return e||t||o||n}var Be=Object.defineProperty,At=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,$t=(e,t,o)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,Ee=(e,t)=>{for(var o in t||(t={}))ke.call(t,o)&&$t(e,o,t[o]);if(At)for(var o of At(t))Te.call(t,o)&&$t(e,o,t[o]);return e},De=(e,t,o)=>new Promise((n,i)=>{var r=a=>{try{l(o.next(a))}catch(h){i(h)}},s=a=>{try{l(o.throw(a))}catch(h){i(h)}},l=a=>a.done?n(a.value):Promise.resolve(a.value).then(r,s);l((o=o.apply(e,t)).next())});const Oe=(e,t,o)=>{e.addEventListener("contextmenu",n=>{if(n.preventDefault(),o){o();return}t.destroyDOM(),t.setInitStatus(!0)})},ze=(e,t,o,n,i,r)=>{const s=document.createElement("canvas");s.width=e,s.height=t;const l=$(s,e,t);if(l){l.drawImage(i,0,0);const a=0,h=t-n,c=o,p=t-h;return l.getImageData(a*r,h*r,c*r,p*r)}return null},Me=(e,t,o,n)=>{e.addEventListener("keydown",i=>{if(t!=null&&((i.metaKey||i.ctrlKey)&&i.code==="Enter"||i.code==="Escape")){o.setTextEditState(!0);const r=e.innerText;if(!r||r===""){o.setTextStatus(!1);return}yt(r,n.mouseX,n.mouseY,o.getSelectedColor(),o.getFontSize(),t),e.innerHTML="",o.setTextStatus(!1),X()}})},Gt=(e,t,o,n,i)=>{if(o.toolController==null||o.screenShotContainer==null)return;const r={code:0,data:null,msg:""},s=ce(n.drawGraphPosition,o.toolController.offsetWidth,o.screenShotContainer.width/e,n.placement,n.position),l=o.screenShotContainer.height/e;if(s.mouseY>l-64){if(s.mouseY-=n.drawGraphPosition.height+64,s.mouseY<0){const a=parseInt(o.screenShotContainer.style.height);s.mouseY=a-n.fullScreenDiffHeight}t.setToolPositionStatus(!0),t.setCutBoxSizeStatus(!1)}if(n.getFullScreenStatus){const a=parseInt(o.screenShotContainer.style.height),h=(n.drawGraphPosition.width/e-o.toolController.offsetWidth)/2;s.mouseY=a-n.fullScreenDiffHeight,s.mouseX=h}t.setToolInfo(s.mouseX+n.position.left,s.mouseY+n.position.top),t.setCutBoxSizePosition(n.drawGraphPosition.startX,n.drawGraphPosition.startY-35),t.setCutBoxSize(n.drawGraphPosition.width,n.drawGraphPosition.height),r.code=1,r.data=!1,i(r)},Fe=(e,t,o)=>{const n=new Image,i={code:0,data:null,msg:""};n.src=e,n.width=t.width,n.height=t.height,n.crossOrigin="Anonymous",n.onload=()=>{var r;(r=t.getContext("2d"))==null||r.drawImage(n,0,0,t.width,t.height),i.code=1,o(i)}},He=(e,t,o,n,i)=>{t.setScreenShotInfo(n.width,n.height),t.setScreenShotPosition(i.left,i.top),e.width=n.width,e.height=n.height,o.canvasWidth!==0&&o.canvasHeight!==0&&(t.setScreenShotInfo(o.canvasWidth,o.canvasHeight),e.width=o.canvasWidth,e.height=o.canvasHeight)},Ae=(e,t,o,n)=>new Promise((i,r)=>{Xt(t||document.body,{onclone:o?ue:void 0,proxy:n}).then(s=>{i({code:0,data:{canvas:s}})}).catch(s=>{const l={code:-1,msg:s};e!=null&&e(l),r(l)})}),$e=(e,t,o,n)=>{let i=t==null?void 0:t.width,r=t==null?void 0:t.height;e.canvasWidth!==0&&e.canvasHeight!==0&&(i=e.canvasWidth,r=e.canvasHeight);let s=i,l=r;return o&&(s=i*n,l=r*n),{containerWidth:i,containerHeight:r,imgContainerWidth:s,imgContainerHeight:l}},Ge=(e,t,o,n,i,r,s,l)=>{let a=e,h=n*e/o;h>t&&(a=e*t/h,h=t),a=i.w>0?i.w:a,h=i.h>0?i.h:h,r==null||r.drawImage(s,i.x,i.y,a,h);const c=t-h;if(l.state&&c>0&&l.fillState){r.beginPath();let p=e,d=c;l!=null&&l.fillWidth&&l.fillWidth>0&&(p=l.fillWidth),l!=null&&l.fillHeight&&l.fillHeight>0&&(d=l.fillHeight),r.rect(0,h,p,d),r.fillStyle=l.color||"",r.fill()}},Le=(e,t,o)=>{let n=e.width*t,i=e.height*t,r=!0,s={};return o&&(n=window.screen.width*t,i=window.screen.height*t,r=!1,s={displaySurface:"window"}),{audio:!1,video:Ee({width:n,height:i},s),preferCurrentTab:r}},Re=(e,t,o,n,i,r,s,l)=>{if(e.getToolClickStatus()&&(t.startX=r,t.startY=s),e.getToolName()=="brush"&&l.screenShotCanvas&&ge(l.screenShotCanvas,r,s),e.getToolName()=="text"&&l.textInputController&&l.screenShotContainer&&l.screenShotCanvas){if(!o)return;e.setTextStatus(!0),n.mouseX!=0&&n.mouseY!=0&&n.mouseX!=r&&n.mouseY!=s&&(yt(l.textInputController.innerText,n.mouseX,n.mouseY,e.getSelectedColor(),e.getFontSize(),l.screenShotCanvas),l.textInputController.innerText!==""&&e.setTextStatus(!1),l.textInputController.innerHTML="",X());const a=r+i.left;l.textInputController.style.left=a+"px",l.textInputController.style.fontSize=e.getFontSize()+"px",l.textInputController.style.fontFamily="none",l.textInputController.style.color=e.getSelectedColor(),setTimeout(()=>{if(l.textInputController){const h=l.textInputController.offsetHeight,c=s-Math.floor(h/2)+i.top;l.textInputController.style.top=c+"px",l.textInputController.focus(),n.mouseX=r,n.mouseY=s,e.setTextInfo({positionX:r,positionY:s,color:e.getSelectedColor(),size:e.getFontSize()})}})}},Ye=(e,t,o,n,i,r,s,l,a,h,c,p,d)=>{const C={code:0,data:null,msg:""};switch(a.getToolName()){case"square":pe(t,o,n,i,a.getSelectedColor(),a.getPenSize(),c.screenShotCanvas);break;case"round":me(c.screenShotCanvas,r,s,t,o,a.getPenSize(),a.getSelectedColor());break;case"right-top":if(h){Se(c.screenShotCanvas,t,o,r,s,30,10,a.getPenSize(),a.getSelectedColor());break}new ve().draw(c.screenShotCanvas,t,o,r,s,a.getSelectedColor(),a.getPenSize());break;case"brush":de(c.screenShotCanvas,r,s,a.getPenSize(),a.getSelectedColor());break;case"mosaicPen":e||(p.showLastHistory(),C.code=1,C.data=!0,C.msg="\u9700\u8981\u66F4\u65B0\u7EC4\u4EF6\u72B6\u6001",d(C)),xe(r-10,s-10,a.getMosaicPenSize(),l,c.screenShotCanvas);break}return C},Lt=(e,t,o,n,i,r,s,l,a,h,c,p)=>{const d={code:0,msg:"",data:null};if(h.screenShotContainer==null)return;const{moveStartX:C,moveStartY:S}=c.movePosition;if(c.cutOutBoxBorderArr.length>0&&!l.getDraggingTrim()){let f=!1;s.beginPath();for(let m=0;m<c.cutOutBoxBorderArr.length;m++)if(s.rect(c.cutOutBoxBorderArr[m].x,c.cutOutBoxBorderArr[m].y,c.cutOutBoxBorderArr[m].width,c.cutOutBoxBorderArr[m].height),s.isPointInPath(e*a,t*a)){switch(c.cutOutBoxBorderArr[m].index){case 1:l.getToolClickStatus()?Pe(h.screenShotContainer,l.getActiveToolName()):h.screenShotContainer.style.cursor="move";break;case 2:if(l.getToolClickStatus())break;h.screenShotContainer.style.cursor="ns-resize";break;case 3:if(l.getToolClickStatus())break;h.screenShotContainer.style.cursor="ew-resize";break;case 4:if(l.getToolClickStatus())break;h.screenShotContainer.style.cursor="nwse-resize";break;case 5:if(l.getToolClickStatus())break;h.screenShotContainer.style.cursor="nesw-resize";break}d.code=1,d.data=c.cutOutBoxBorderArr[m].option,d.msg="\u4FEE\u6539borderOption\u7684\u503C",p(d),f=!0;break}d.code=2,d.data=f,d.msg="\u4FEE\u6539mouseInsideCropBox\u7684\u503C",p(d),s.closePath(),f||(h.screenShotContainer.style.cursor="default",d.code=3,d.data=null,d.msg="\u91CD\u7F6EborderOption\u7684\u503C",p(d))}if(l.getDraggingTrim())if(c.borderOption===1){let f=Ot(e-(C-o),i,h.screenShotContainer.width),m=Ot(t-(S-n),r,h.screenShotContainer.height);const v=h.screenShotContainer.width/a,u=h.screenShotContainer.height/a,Rt=f+i,Yt=m+r;Rt>v&&(f=v-i),Yt>u&&(m=u-r),Object.assign(c.tempGraphPosition,G(f,m,i,r,s,l.getBorderSize(),h.screenShotContainer,h.screenShotImageController))}else{const{tempStartX:f,tempStartY:m,tempWidth:v,tempHeight:u}=Ie(e,t,o,n,i,r,c.borderOption);Object.assign(c.tempGraphPosition,G(f,m,v,u,s,l.getBorderSize(),h.screenShotContainer,h.screenShotImageController))}},Xe=(e,t)=>{t.screenShotContainer==null||t.toolController==null||t.textInputController==null||t.optionIcoController==null||t.optionController==null||t.cutBoxSizeContainer==null||e<=0||(t.screenShotContainer.style.zIndex=`${e}`,t.toolController.style.zIndex=`${e+1}`,t.textInputController.style.zIndex=`${e+1}`,t.optionIcoController.style.zIndex=`${e+1}`,t.optionController.style.zIndex=`${e+1}`,t.cutBoxSizeContainer.style.zIndex=`${e+1}`)},We=(e,t,o,n,i,r)=>{const s=t.x,l=t.y,a=t.w,h=t.h;n.screenShotContainer!=null&&(i.drawGraphPosition.startX=s,i.drawGraphPosition.startY=l,i.drawGraphPosition.width=a,i.drawGraphPosition.height=h,o.setCutOutBoxPosition(s,l,a,h),G(s,l,a,h,n.screenShotCanvas,o.getBorderSize(),n.screenShotContainer,n.screenShotImageController),i.cutOutBoxBorderArr.length=0,i.cutOutBoxBorderArr.push(...Ft(o.getBorderSize(),i.drawGraphPosition)),n.screenShotContainer.style.cursor="move",o.setToolStatus(!0),o.setCutBoxSizeStatus(!0),n.toolController!=null&&Gt(e,o,{toolController:n.toolController,screenShotContainer:n.screenShotContainer},{drawGraphPosition:i.drawGraphPosition,placement:i.placement,position:i.position,fullScreenDiffHeight:i.fullScreenDiffHeight,getFullScreenStatus:i.getFullScreenStatus},r.toolBarCallerCallback))},Ne=(e,t)=>{Ht()&&(e==null||e.addEventListener("mousedown",t.mouseDownEvent),e==null||e.addEventListener("mousemove",t.mouseMoveEvent),e==null||e.addEventListener("mouseup",t.mouseUpEvent)),be()&&(e==null||e.addEventListener("touchstart",t.mouseDownEvent,!1),e==null||e.addEventListener("touchmove",t.mouseMoveEvent,!1),e==null||e.addEventListener("touchend",t.mouseUpEvent,!1))},Ve=(e,t,o,n,i,r)=>{if(e instanceof MediaStream)i.videoController.srcObject=e,r.loadScreenFlowData(o);else throw t!=null&&t({code:-1,msg:"\u89C6\u9891\u6D41\u63A5\u5165\u5931\u8D25"}),n.destroyDOM(),"\u89C6\u9891\u6D41\u63A5\u5165\u5931\u8D25";return e},Ue=(e,t,o,n,i)=>De(void 0,null,function*(){let r=null;try{r=yield navigator.mediaDevices.getDisplayMedia(Le(o.screenShotImageController,n.dpr,n.wrcWindowMode)),o.videoController.srcObject=r,i({code:1,data:r,msg:"\u66F4\u65B0captureStream\u6570\u636E"})}catch(s){const l="\u6D4F\u89C8\u5668\u4E0D\u652F\u6301webrtc\u6216\u8005\u7528\u6237\u672A\u6388\u6743";throw e!=null&&e({code:-1,msg:l,errorInfo:s}),t.destroyDOM(),`${l}( ${s} )`}return r}),je=e=>{const t=e.srcObject;t&&"getTracks"in t&&(t.getTracks().forEach(o=>o.stop()),e.srcObject=null)},_e=(e,t,o,n,i)=>{if(!Ht()&&e instanceof TouchEvent&&o.screenShotCanvas&&Lt(e.touches[0].pageX,e.touches[0].pageY,n.tempGraphPosition.startX,n.tempGraphPosition.startY,n.tempGraphPosition.width,n.tempGraphPosition.height,o.screenShotCanvas,t,n.dpr,{screenShotContainer:o.screenShotContainer,screenShotImageController:o.screenShotImageController},{movePosition:n.movePosition,tempGraphPosition:n.tempGraphPosition,cutOutBoxBorderArr:n.cutOutBoxBorderArr,borderOption:n.borderOption},i.croppingBoxCallerCallback),t.getToolName()=="undo")return;t.setDragging(!0),t.setToolPositionStatus(!1);const r=w(e instanceof MouseEvent?e.offsetX:e.touches[0].pageX),s=w(e instanceof MouseEvent?e.offsetY:e.touches[0].pageY);Re(t,n.drawGraphPosition,n.mouseInsideCropBox,n.textInputPosition,n.position,r,s,{textInputController:o.textInputController,screenShotContainer:o.screenShotContainer,screenShotCanvas:o.screenShotCanvas}),n.borderOption?(t.setDraggingTrim(!0),n.movePosition.moveStartX=r,n.movePosition.moveStartY=s):(i.saveDrawGraphCallerCallback({code:1,msg:"\u4FDD\u5B58\u5F53\u524D\u88C1\u526A\u6846\u7684\u5750\u6807",data:{drawGraphPrevX:n.drawGraphPosition.startX,drawGraphPrevY:n.drawGraphPosition.startY}}),n.drawGraphPosition.startX=r,n.drawGraphPosition.startY=s)},Ke=(e,t,o,n)=>{if(!e.getToolClickStatus()&&!t.dragFlag&&!t.clickCutFullScreen){t.drawGraphPosition.startX=t.drawGraphPrevX,t.drawGraphPosition.startY=t.drawGraphPrevY;return}const i=e.getCutOutBoxPosition();if(i.width===0&&i.height===0&&i.startX===0&&i.startY===0&&!t.dragFlag&&t.clickCutFullScreen){const r=e.getBorderSize();n.updateTempGraphPositionCallback({code:1,msg:"\u66F4\u65B0getFullScreenStatus\u4E0EtempGraphPosition",data:{getFullScreenStatus:!0,tempGraphPosition:G(0,0,o.screenShotContainer.width-r/2,o.screenShotContainer.height-r/2,o.screenShotCanvas,r,o.screenShotContainer,o.screenShotImageController)}})}if(!(o.screenShotContainer==null||o.screenShotCanvas==null)){if(e.getToolClickStatus()&&t.drawStatus){X();return}else if(e.getToolClickStatus()&&!t.drawStatus)return;if(Object.assign(t.drawGraphPosition,t.tempGraphPosition),!e.getToolClickStatus()){const{startX:r,startY:s,width:l,height:a}=t.drawGraphPosition;e.setCutOutBoxPosition(r,s,l,a)}Object.assign(t.cutOutBoxBorderArr,Ft(e.getBorderSize(),t.drawGraphPosition)),(o.screenShotContainer!=null&&t.dragFlag||t.clickCutFullScreen)&&(o.screenShotContainer.style.cursor="move",e.setToolStatus(!0),e.setCutBoxSizeStatus(!0),n.updateDrawStatusCallback({code:1,msg:"\u66F4\u65B0dragFlag",data:!1}),o.toolController!=null&&Gt(t.dpr,e,{toolController:o.toolController,screenShotContainer:o.screenShotContainer},{drawGraphPosition:t.drawGraphPosition,placement:t.placement,position:t.position,fullScreenDiffHeight:t.fullScreenDiffHeight,getFullScreenStatus:t.getFullScreenStatus},n.toolBarCallerCallback))}};var qe=Object.defineProperty,Ze=(e,t,o)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t,o)=>(Ze(e,typeof t!="symbol"?t+"":t,o),o),Je=(e,t,o)=>new Promise((n,i)=>{var r=a=>{try{l(o.next(a))}catch(h){i(h)}},s=a=>{try{l(o.throw(a))}catch(h){i(h)}},l=a=>a.done?n(a.value):Promise.resolve(a.value).then(r,s);l((o=o.apply(e,t)).next())});class Qe{constructor(t){g(this,"version","1.1.0"),g(this,"buildTime","1744962529947"),g(this,"data"),g(this,"videoController"),g(this,"screenShotContainer"),g(this,"screenShotDom",null),g(this,"toolController"),g(this,"screenShotImageController"),g(this,"screenShotCanvas"),g(this,"textInputController"),g(this,"optionController"),g(this,"optionIcoController"),g(this,"cutBoxSizeContainer"),g(this,"plugInParameters"),g(this,"webrtcReplyTime",500),g(this,"keyboardEventHandle",null),g(this,"drawGraphPosition",{startX:0,startY:0,width:0,height:0}),g(this,"tempGraphPosition",{startX:0,startY:0,width:0,height:0}),g(this,"wrcImgPosition",{x:0,y:0,w:0,h:0}),g(this,"hiddenScrollBar",{color:"#000000",fillState:!1,state:!1,fillWidth:0,fillHeight:0}),g(this,"wrcWindowMode",!1),g(this,"cutOutBoxBorderArr",[]),g(this,"borderOption",null),g(this,"movePosition",{moveStartX:0,moveStartY:0}),g(this,"dragFlag",!1),g(this,"clickCutFullScreen",!1),g(this,"getFullScreenStatus",!1),g(this,"drawGraphPrevX",0),g(this,"drawGraphPrevY",0),g(this,"degreeOfBlur",5),g(this,"dpr",window.devicePixelRatio||1),g(this,"fullScreenDiffHeight",60),g(this,"position",{left:0,top:0}),g(this,"imgSrc",null),g(this,"loadCrossImg",!1),g(this,"mouseInsideCropBox",!1),g(this,"proxyUrl"),g(this,"drawStatus",!1),g(this,"captureStream",null),g(this,"cropBoxInfo",null),g(this,"textInputPosition",{mouseX:0,mouseY:0}),g(this,"placement","right"),g(this,"customRightClickEvent",{state:!1}),g(this,"wrcScreenShot",(l,a)=>{document.body.classList.add("no-cursor");const h=c=>{c.code===1&&c.data instanceof MediaStream&&(this.captureStream=c.data)};Ue(l,this.data,{screenShotImageController:this.screenShotImageController,videoController:this.videoController},{dpr:this.dpr,wrcWindowMode:this.wrcWindowMode},h).then(()=>{this.loadScreenFlowData(a)})}),g(this,"mouseDownEvent",l=>{if(this.drawStatus=!1,this.data.setColorPanelStatus(!0),this.data.setTextSizeOptionStatus(!1),l instanceof MouseEvent&&l.button!=0)return;const a=h=>{h.code===1&&h.data!=null&&(this.drawGraphPrevX=h.data.startX,this.drawGraphPrevY=h.data.startY)};_e(l,this.data,{screenShotCanvas:this.screenShotCanvas,screenShotContainer:this.screenShotContainer,screenShotImageController:this.screenShotImageController,textInputController:this.textInputController},{tempGraphPosition:this.tempGraphPosition,dpr:this.dpr,movePosition:this.movePosition,cutOutBoxBorderArr:this.cutOutBoxBorderArr,borderOption:this.borderOption,drawGraphPosition:this.drawGraphPosition,mouseInsideCropBox:this.mouseInsideCropBox,textInputPosition:this.textInputPosition,position:this.position},{croppingBoxCallerCallback:this.croppingBoxCallerCallback,saveDrawGraphCallerCallback:a})}),g(this,"mouseMoveEvent",l=>{if(this.screenShotCanvas==null||this.screenShotContainer==null||this.data.getToolName()=="undo")return;l.preventDefault(),!this.data.getToolClickStatus()&&this.data.getDragging()&&(this.dragFlag=!0,this.data.setToolStatus(!1),this.data.setCutBoxSizeStatus(!1));const{startX:a,startY:h,width:c,height:p}=this.drawGraphPosition,d=w(l instanceof MouseEvent?l.offsetX:l.touches[0].pageX),C=w(l instanceof MouseEvent?l.offsetY:l.touches[0].pageY),S=d-a,f=C-h;if(this.data.getToolClickStatus()&&this.data.getDragging()){const m=this.data.getCutOutBoxPosition();if(!zt(a,h,m)||!zt(d,C,m))return;this.data.getToolName()!="mosaicPen"&&(this.showLastHistory(),this.drawStatus=!0);const v=u=>{u.code===1&&u.data!=null&&typeof u.data=="boolean"&&(this.drawStatus=u.data)};Ye(this.drawStatus,a,h,S,f,d,C,this.degreeOfBlur,this.data,this.plugInParameters.getRatioArrow(),{screenShotCanvas:this.screenShotCanvas},{showLastHistory:this.showLastHistory},v);return}Lt(d,C,a,h,c,p,this.screenShotCanvas,this.data,this.dpr,{screenShotContainer:this.screenShotContainer,screenShotImageController:this.screenShotImageController},{movePosition:this.movePosition,tempGraphPosition:this.tempGraphPosition,cutOutBoxBorderArr:this.cutOutBoxBorderArr,borderOption:this.borderOption},this.croppingBoxCallerCallback),!(!this.data.getDragging()||this.data.getDraggingTrim())&&(this.tempGraphPosition=G(a,h,S,f,this.screenShotCanvas,this.data.getBorderSize(),this.screenShotContainer,this.screenShotImageController))}),g(this,"mouseUpEvent",()=>{if(this.data.getToolName()=="undo"||(this.data.setDragging(!1),this.data.setDraggingTrim(!1),this.screenShotCanvas==null||this.screenShotContainer==null))return;const l=h=>{if(h.code===1&&h.data!=null){const{getFullScreenStatus:c,tempGraphPosition:p}=h.data;this.getFullScreenStatus=c,this.tempGraphPosition=p}},a=h=>{h.code===1&&typeof h.data=="boolean"&&(this.drawStatus=h.data)};Ke(this.data,{dragFlag:this.dragFlag,drawStatus:this.drawStatus,clickCutFullScreen:this.clickCutFullScreen,drawGraphPosition:this.drawGraphPosition,cutOutBoxBorderArr:this.cutOutBoxBorderArr,drawGraphPrevX:this.drawGraphPrevX,drawGraphPrevY:this.drawGraphPrevY,tempGraphPosition:this.tempGraphPosition,placement:this.placement,position:this.position,fullScreenDiffHeight:this.fullScreenDiffHeight,getFullScreenStatus:this.getFullScreenStatus,dpr:this.dpr},{screenShotCanvas:this.screenShotCanvas,screenShotContainer:this.screenShotContainer,screenShotImageController:this.screenShotImageController,toolController:this.toolController},{toolBarCallerCallback:this.toolBarCallerCallback,updateTempGraphPositionCallback:l,updateDrawStatusCallback:a})}),g(this,"croppingBoxCallerCallback",l=>{const{code:a,data:h}=l;a===1&&typeof h=="number"&&(this.borderOption=h),a===2&&typeof h=="boolean"&&(this.mouseInsideCropBox=h),a===3&&typeof h===null&&(this.borderOption=null)}),g(this,"toolBarCallerCallback",l=>{l.code===1&&typeof l.data=="boolean"&&(this.getFullScreenStatus=l.data)}),this.plugInParameters=new E,he(t),new ne(t),this.videoController=document.createElement("video"),this.videoController.autoplay=!0,this.screenShotImageController=document.createElement("canvas"),this.data=new B,this.setOptionalParameter(t);const{lockScroll:o,cutDotSize:n,onLoaded:i,onCancel:r,level:s}=t;this.setGlobalParameter(),this.data.setNoScrollStatus(o),n&&this.data.setBorderSize(n),this.load(i,r).then(()=>{this.toolController==null||this.screenShotContainer==null||this.textInputController==null||(Xe(s||0,{screenShotCo