react-screenshots 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var Qe=Object.defineProperty,Ze=Object.defineProperties;var et=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var Be=(e,t,r)=>t in e?Qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,T=(e,t)=>{for(var r in t||(t={}))Ee.call(t,r)&&Be(e,r,t[r]);if(he)for(var r of he(t))je.call(t,r)&&Be(e,r,t[r]);return e},pe=(e,t)=>Ze(e,et(t));var Me=(e,t)=>{var r={};for(var o in e)Ee.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&he)for(var o of he(e))t.indexOf(o)<0&&je.call(e,o)&&(r[o]=e[o]);return r};import{R as Ve,r as c,j as g,a as _e,b as tt}from"./vendor.e3c417b2.js";const st=function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))o(i);new MutationObserver(i=>{for(const n of i)if(n.type==="childList")for(const s of n.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&o(s)}).observe(document,{childList:!0,subtree:!0});function r(i){const n={};return i.integrity&&(n.integrity=i.integrity),i.referrerpolicy&&(n.referrerPolicy=i.referrerpolicy),i.crossorigin==="use-credentials"?n.credentials="include":i.crossorigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function o(i){if(i.ep)return;i.ep=!0;const n=r(i);fetch(i.href,n)}};st();const $e={magnifier_position_label:"\u5750\u6807",operation_ok_title:"\u786E\u5B9A",operation_cancel_title:"\u53D6\u6D88",operation_save_title:"\u4FDD\u5B58",operation_redo_title:"\u91CD\u505A",operation_undo_title:"\u64A4\u9500",operation_mosaic_title:"\u9A6C\u8D5B\u514B",operation_text_title:"\u6587\u672C",operation_brush_title:"\u753B\u7B14",operation_arrow_title:"\u7BAD\u5934",operation_ellipse_title:"\u692D\u5706",operation_rectangle_title:"\u77E9\u5F62"};var ye=Ve.createContext({store:{url:void 0,image:null,width:0,height:0,lang:$e,emiterRef:{current:{}},canvasContextRef:{current:null},history:{index:-1,stack:[]},bounds:null,cursor:"move",operation:void 0},dispatcher:{call:void 0,setHistory:void 0,setBounds:void 0,setCursor:void 0,setOperation:void 0}});function oe(){const{dispatcher:e}=c.exports.useContext(ye);return e}function $(){const{store:e}=c.exports.useContext(ye);return e}function U(){const{bounds:e}=$(),{setBounds:t}=oe(),r=c.exports.useCallback(i=>{t==null||t(i)},[t]),o=c.exports.useCallback(()=>{t==null||t(null)},[t]);return[e,{set:r,reset:o}]}function L(){const{lang:e}=$();return e}var J="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsMagnifier/index.tsx";const K=100,Q=80;function nt({x:e,y:t}){const{width:r,height:o,image:i}=$(),n=L(),[s,a]=c.exports.useState(null),d=c.exports.useRef(null),u=c.exports.useRef(null),p=c.exports.useRef(null),[l,f]=c.exports.useState("000000");return c.exports.useLayoutEffect(()=>{if(!d.current)return;const h=d.current.getBoundingClientRect();let x=e+20,v=t+20;x+h.width>r&&(x=e-h.width-20),v+h.height>o&&(v=t-h.height-20),x<0&&(x=0),v<0&&(v=0),a({x,y:v})},[r,o,e,t]),c.exports.useEffect(()=>{if(!i||!u.current){p.current=null;return}if(p.current||(p.current=u.current.getContext("2d")),!p.current)return;const h=p.current;h.clearRect(0,0,K,Q);const x=i.naturalWidth/r,v=i.naturalHeight/o;h.drawImage(i,e*x-K/2,t*v-Q/2,K,Q,0,0,K,Q);const{data:y}=h.getImageData(Math.floor(K/2),Math.floor(Q/2),1,1),w=Array.from(y.slice(0,3)).map(R=>R>=16?R.toString(16):`0${R.toString(16)}`).join("").toUpperCase();f(w)},[r,o,i,e,t]),g.exports.jsxDEV("div",{ref:d,className:"screenshots-magnifier",style:{transform:`translate(${s==null?void 0:s.x}px, ${s==null?void 0:s.y}px)`},children:[g.exports.jsxDEV("div",{className:"screenshots-magnifier-body",children:g.exports.jsxDEV("canvas",{ref:u,className:"screenshots-magnifier-body-canvas",width:K,height:Q},void 0,!1,{fileName:J,lineNumber:97,columnNumber:9},this)},void 0,!1,{fileName:J,lineNumber:96,columnNumber:7},this),g.exports.jsxDEV("div",{className:"screenshots-magnifier-footer",children:[g.exports.jsxDEV("div",{className:"screenshots-magnifier-footer-item",children:[n.magnifier_position_label,": (",e,",",t,")"]},void 0,!0,{fileName:J,lineNumber:105,columnNumber:9},this),g.exports.jsxDEV("div",{className:"screenshots-magnifier-footer-item",children:["RGB: #",l]},void 0,!0,{fileName:J,lineNumber:108,columnNumber:9},this)]},void 0,!0,{fileName:J,lineNumber:104,columnNumber:7},this)]},void 0,!0,{fileName:J,lineNumber:89,columnNumber:5},this)}function rt({x:e,y:t},{x:r,y:o},i,n){return e>r&&([e,r]=[r,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0),r>i&&(r=i),t<0&&(t=0),o>n&&(o=n),{x:e,y:t,width:r-e,height:o-t}}var me="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsBackground/index.tsx";function ot(){const{url:e,image:t,width:r,height:o}=$(),[i,n]=U(),s=c.exports.useRef(null),a=c.exports.useRef(null),d=c.exports.useRef(!1),[u,p]=c.exports.useState(null),l=c.exports.useCallback((h,x)=>{if(!s.current)return;const{x:v,y}=s.current.getBoundingClientRect();n.set(rt({x:h.x-v,y:h.y-y},{x:x.x-v,y:x.y-y},r,o))},[r,o,n]),f=c.exports.useCallback(h=>{a.current||i||h.button!==0||(a.current={x:h.clientX,y:h.clientY},d.current=!1)},[i]);return c.exports.useEffect(()=>{const h=v=>{if(s.current){const y=s.current.getBoundingClientRect();v.clientX<y.left||v.clientY<y.top||v.clientX>y.right||v.clientY>y.bottom?p(null):p({x:v.clientX-y.x,y:v.clientY-y.y})}!a.current||(l(a.current,{x:v.clientX,y:v.clientY}),d.current=!0)},x=v=>{!a.current||(d.current&&l(a.current,{x:v.clientX,y:v.clientY}),a.current=null,d.current=!1)};return window.addEventListener("mousemove",h),window.addEventListener("mouseup",x),()=>{window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",x)}},[l]),!e||!t?null:g.exports.jsxDEV("div",{ref:s,className:"screenshots-background",onMouseDown:f,children:[g.exports.jsxDEV("img",{className:"screenshots-background-image",src:e},void 0,!1,{fileName:me,lineNumber:114,columnNumber:7},this),g.exports.jsxDEV("div",{className:"screenshots-background-mask"},void 0,!1,{fileName:me,lineNumber:115,columnNumber:7},this),u&&!i&&g.exports.jsxDEV(nt,{x:u==null?void 0:u.x,y:u==null?void 0:u.y},void 0,!1,{fileName:me,lineNumber:116,columnNumber:31},this)]},void 0,!0,{fileName:me,lineNumber:113,columnNumber:5},this)}var Ke;const Le=(Ke=window.devicePixelRatio)!=null?Ke:2;var de=Le<2?2:Le;function it(e,t,r,o){const i=e.clientX-r.x,n=e.clientY-r.y;let s=o.x,a=o.y,d=o.x+o.width,u=o.y+o.height;switch(t){case"top":a+=n;break;case"top-right":d+=i,a+=n;break;case"right":d+=i;break;case"right-bottom":d+=i,u+=n;break;case"bottom":u+=n;break;case"bottom-left":s+=i,u+=n;break;case"left":s+=i;break;case"left-top":s+=i,a+=n;break;case"move":s+=i,a+=n,d+=i,u+=n;break}return[{x:s,y:a},{x:d,y:u}]}function ct({x:e,y:t},{x:r,y:o},i,n,s,a){return e>r&&([e,r]=[r,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0,a==="move"&&(r=i.width)),r>n&&(r=n,a==="move"&&(e=r-i.width)),t<0&&(t=0,a==="move"&&(o=i.height)),o>s&&(o=s,a==="move"&&(t=o-i.height)),{x:e,y:t,width:Math.max(r-e,1),height:Math.max(o-t,1)}}var j;(function(e){e[e.Edit=0]="Edit",e[e.Source=1]="Source"})(j||(j={}));function Z(){const{emiterRef:e}=$(),t=c.exports.useCallback((n,s)=>{const a=e.current;Array.isArray(a[n])?a[n].push(s):a[n]=[s]},[e]),r=c.exports.useCallback((n,s)=>{const a=e.current;if(Array.isArray(a[n])){const d=a[n].findIndex(u=>u===s);d!==-1&&a[n].splice(d,1)}},[e]),o=c.exports.useCallback((n,...s)=>{const a=e.current;Array.isArray(a[n])&&a[n].forEach(d=>d(...s))},[e]),i=c.exports.useCallback(()=>{e.current={}},[e]);return{on:t,off:r,emit:o,reset:i}}function H(){const{history:e}=$(),{setHistory:t}=oe(),r=c.exports.useCallback(p=>{const{index:l,stack:f}=e;f.forEach(h=>{h.type===j.Source&&(h.isSelected=!1)}),p.type===j.Source?p.isSelected=!0:p.type===j.Edit&&(p.source.isSelected=!0),f.splice(l+1),f.push(p),t==null||t({index:f.length-1,stack:f})},[e,t]),o=c.exports.useCallback(()=>{const{stack:p}=e;p.pop(),t==null||t({index:p.length-1,stack:p})},[e,t]),i=c.exports.useCallback(()=>{const{index:p,stack:l}=e,f=l[p];f&&(f.type===j.Source?f.isSelected=!1:f.type===j.Edit&&f.source.editHistory.pop()),t==null||t({index:p<=0?-1:p-1,stack:l})},[e,t]),n=c.exports.useCallback(()=>{const{index:p,stack:l}=e,f=l[p+1];f&&(f.type===j.Source?f.isSelected=!1:f.type===j.Edit&&f.source.editHistory.push(f)),t==null||t({index:p>=l.length-1?l.length-1:p+1,stack:l})},[e,t]),s=c.exports.useCallback(p=>{t==null||t(T({},p))},[t]),a=c.exports.useCallback(p=>{e.stack.forEach(l=>{l.type===j.Source&&(l===p?l.isSelected=!0:l.isSelected=!1)}),t==null||t(T({},e))},[e,t]),d=c.exports.useCallback(()=>{e.stack.forEach(p=>{p.type===j.Source&&(p.isSelected=!1)}),t==null||t(T({},e))},[e,t]),u=c.exports.useCallback(()=>{t==null||t({index:-1,stack:[]})},[t]);return[{index:e.index,stack:e.stack,top:e.stack.slice(e.index,e.index+1)[0]},{push:r,pop:o,undo:i,redo:n,set:s,select:a,clearSelect:d,reset:u}]}function A(){const{cursor:e}=$(),{setCursor:t}=oe(),r=c.exports.useCallback(i=>{t==null||t(i)},[t]),o=c.exports.useCallback(()=>{t==null||t("move")},[t]);return[e,{set:r,reset:o}]}function G(){const{operation:e}=$(),{setOperation:t}=oe(),r=c.exports.useCallback(i=>{t==null||t(i)},[t]),o=c.exports.useCallback(()=>{t==null||t(void 0)},[t]);return[e,{set:r,reset:o}]}function at(e,t,r,o){if(!t)return!1;const i=document.createElement("canvas");i.width=e.width,i.height=e.height;const n=i.getContext("2d");if(!n)return!1;const{left:s,top:a}=t.getBoundingClientRect(),d=o.clientX-s,u=o.clientY-a;return[...r.stack.slice(0,r.index+1)].reverse().find(l=>{var f;return l.type!==j.Source?!1:(n.clearRect(0,0,e.width,e.height),(f=l.isHit)==null?void 0:f.call(l,n,l,{x:d,y:u}))})}var ie="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsCanvas/index.tsx";const ut=["top","right","bottom","left"];var P;(function(e){e.ResizeTop="top",e.ResizetopRight="top-right",e.ResizeRight="right",e.ResizeRightBottom="right-bottom",e.ResizeBottom="bottom",e.ResizeBottomLeft="bottom-left",e.ResizeLeft="left",e.ResizeLeftTop="left-top",e.Move="move"})(P||(P={}));const lt=[P.ResizeTop,P.ResizetopRight,P.ResizeRight,P.ResizeRightBottom,P.ResizeBottom,P.ResizeBottomLeft,P.ResizeLeft,P.ResizeLeftTop];var ft=c.exports.forwardRef(function(t,r){const{image:o,width:i,height:n}=$(),s=Z(),[a]=H(),[d]=A(),[u,p]=U(),[l]=G(),f=c.exports.useRef(),h=c.exports.useRef(null),x=c.exports.useRef(null),v=c.exports.useRef(null),y=c.exports.useRef(null),w=c.exports.useCallback(()=>{if(!o||!u||!y.current)return;const m=o.naturalWidth/i,b=o.naturalHeight/n,N=y.current;N.imageSmoothingEnabled=!0,N.imageSmoothingQuality="low",N.setTransform(de,0,0,de,0,0),N.clearRect(0,0,u.width,u.height),N.drawImage(o,u.x*m,u.y*b,u.width*m,u.height*b,0,0,u.width,u.height),a.stack.slice(0,a.index+1).forEach(C=>{C.type===j.Source&&C.draw(N,C)})},[o,i,n,u,y,a]),R=c.exports.useCallback((m,b)=>{if(!(m.button!==0||!u))if(!l)f.current=b,h.current={x:m.clientX,y:m.clientY},x.current={x:u.x,y:u.y,width:u.width,height:u.height};else{const N=at(u,v.current,a,m.nativeEvent);N?s.emit("drawselect",N,m.nativeEvent):s.emit("mousedown",m.nativeEvent)}},[u,l,s,a]),z=c.exports.useCallback(m=>{if(!f.current||!h.current||!x.current||!u)return;const b=it(m,f.current,h.current,x.current);p.set(ct(b[0],b[1],u,i,n,f.current))},[i,n,u,p]);return c.exports.useLayoutEffect(()=>{if(!o||!u||!v.current){y.current=null;return}y.current||(y.current=v.current.getContext("2d")),w()},[o,u,w]),c.exports.useEffect(()=>{const m=N=>{if(l)s.emit("mousemove",N);else{if(!f.current||!h.current||!x.current)return;z(N)}},b=N=>{if(l)s.emit("mouseup",N);else{if(!f.current||!h.current||!x.current)return;z(N),f.current=void 0,h.current=null,x.current=null}};return window.addEventListener("mousemove",m),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",b)}},[z,l,s]),c.exports.useImperativeHandle(r,()=>y.current),u?g.exports.jsxDEV("div",{className:"screenshots-canvas",style:{left:u.x,top:u.y,width:u.width,height:u.height},children:[g.exports.jsxDEV("canvas",{ref:v,width:u.width*de,height:u.height*de,style:{width:u.width,height:u.height}},void 0,!1,{fileName:ie,lineNumber:200,columnNumber:7},this),g.exports.jsxDEV("div",{className:"screenshots-canvas-body",style:{cursor:d},onMouseDown:m=>R(m,"move")},void 0,!1,{fileName:ie,lineNumber:209,columnNumber:7},this),ut.map(m=>g.exports.jsxDEV("div",{className:`screenshots-canvas-border-${m}`},m,!1,{fileName:ie,lineNumber:217,columnNumber:16},this)),lt.map(m=>g.exports.jsxDEV("div",{className:`screenshots-canvas-point-${m}`,onMouseDown:b=>R(b,m)},m,!1,{fileName:ie,lineNumber:221,columnNumber:11},this))]},void 0,!0,{fileName:ie,lineNumber:191,columnNumber:5},this):null});function Ne(){const e=oe();return c.exports.useCallback((r,...o)=>{var i;(i=e.call)==null||i.call(e,r,...o)},[e])}function I(){const{canvasContextRef:e}=$();return e}function Ce(){const e=Z(),[,t]=U(),[,r]=A(),[,o]=H(),[,i]=G();return c.exports.useCallback(()=>{e.reset(),o.reset(),t.reset(),r.reset(),i.reset()},[e,o,t,r,i])}var Re="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOption/index.tsx",q;(function(e){e.Bottom="bottom",e.Top="top"})(q||(q={}));function ht({open:e,content:t,children:r}){const o=c.exports.useRef(null),i=c.exports.useRef(null),n=c.exports.useRef(null),s=c.exports.useContext(Oe),[a,d]=c.exports.useState(q.Bottom),[u,p]=c.exports.useState(null),[l,f]=c.exports.useState(0),h=()=>(i.current||(i.current=document.createElement("div")),i.current);return c.exports.useEffect(()=>{const x=h();return e&&document.body.appendChild(x),()=>{x.remove()}},[e]),c.exports.useEffect(()=>{if(!e||!s||!o.current||!n.current)return;const x=o.current.getBoundingClientRect(),v=n.current.getBoundingClientRect();let y=a,w=x.left+x.width/2,R=x.top+x.height,z=l;if(w+v.width/2>s.x+s.width){const m=w;w=s.x+s.width-v.width/2,z=m-w}if(w<s.x+v.width/2){const m=w;w=s.x+v.width/2,z=m-w}R>window.innerHeight-v.height&&(y===q.Bottom&&(y=q.Top),R=x.top-v.height),R<0&&(y===q.Top&&(y=q.Bottom),R=x.top+x.height),y!==a&&d(y),((u==null?void 0:u.x)!==w||u.y!==R)&&p({x:w,y:R}),z!==l&&f(z)}),g.exports.jsxDEV(g.exports.Fragment,{children:[c.exports.cloneElement(r,{ref:o}),e&&t&&_e.exports.createPortal(g.exports.jsxDEV("div",{ref:n,className:"screenshots-option",style:{visibility:u?"visible":"hidden",left:u==null?void 0:u.x,top:u==null?void 0:u.y},"data-placement":a,children:[g.exports.jsxDEV("div",{className:"screenshots-option-container",children:t},void 0,!1,{fileName:Re,lineNumber:121,columnNumber:13},this),g.exports.jsxDEV("div",{className:"screenshots-option-arrow",style:{marginLeft:l}},void 0,!1,{fileName:Re,lineNumber:122,columnNumber:13},this)]},void 0,!0,{fileName:Re,lineNumber:111,columnNumber:11},this),h())]},void 0,!0)}var Se="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsButton/index.tsx";function X({title:e,icon:t,checked:r,disabled:o,option:i,onClick:n}){const s=["screenshots-button"],a=c.exports.useCallback(d=>{o||!n||n(d)},[o,n]);return r&&s.push("screenshots-button-checked"),o&&s.push("screenshots-button-disabled"),g.exports.jsxDEV(ht,{open:r,content:i,children:g.exports.jsxDEV("div",{className:s.join(" "),title:e,onClick:a,children:g.exports.jsxDEV("span",{className:t},void 0,!1,{fileName:Se,lineNumber:44,columnNumber:9},this)},void 0,!1,{fileName:Se,lineNumber:43,columnNumber:7},this)},void 0,!1,{fileName:Se,lineNumber:42,columnNumber:5},this)}var pt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ok/index.tsx";function mt(){const e=L(),t=I(),[,r]=H(),o=Ne(),[i]=U(),n=Ce(),s=c.exports.useCallback(()=>{r.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(a=>{o("onOk",a,i),n()},"image/png")})},[t,r,o,i,n]);return g.exports.jsxDEV(X,{title:e.operation_ok_title,icon:"icon-ok",onClick:s},void 0,!1,{fileName:pt,lineNumber:31,columnNumber:10},this)}var dt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Cancel/index.tsx";function xt(){const e=Ne(),t=Ce(),r=L(),o=c.exports.useCallback(()=>{e("onCancel"),t()},[e,t]);return g.exports.jsxDEV(X,{title:r.operation_cancel_title,icon:"icon-cancel",onClick:o},void 0,!1,{fileName:dt,lineNumber:17,columnNumber:10},this)}var bt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Save/index.tsx";function gt(){const e=L(),t=I(),[,r]=H(),[o]=U(),i=Ne(),n=Ce(),s=c.exports.useCallback(()=>{r.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(a=>{i("onSave",a,o),n()},"image/png")})},[t,r,o,i,n]);return g.exports.jsxDEV(X,{title:e.operation_save_title,icon:"icon-save",onClick:s},void 0,!1,{fileName:bt,lineNumber:31,columnNumber:10},this)}var vt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Redo/index.tsx";function yt(){const e=L(),[t,r]=H(),o=c.exports.useCallback(()=>{r.redo()},[r]);return g.exports.jsxDEV(X,{title:e.operation_redo_title,icon:"icon-redo",disabled:!t.stack.length||t.stack.length-1===t.index,onClick:o},void 0,!1,{fileName:vt,lineNumber:15,columnNumber:5},this)}var Nt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Undo/index.tsx";function Ct(){const e=L(),[t,r]=H(),o=c.exports.useCallback(()=>{r.undo()},[r]);return g.exports.jsxDEV(X,{title:e.operation_undo_title,icon:"icon-undo",disabled:t.index===-1,onClick:o},void 0,!1,{fileName:Nt,lineNumber:15,columnNumber:5},this)}var ke="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSize/index.tsx";function He({value:e,onChange:t}){const r=[3,6,9];return g.exports.jsxDEV("div",{className:"screenshots-size",children:r.map(o=>{const i=["screenshots-size-item"];return o===e&&i.push("screenshots-size-active"),g.exports.jsxDEV("div",{className:i.join(" "),onClick:()=>t&&t(o),children:g.exports.jsxDEV("div",{className:"screenshots-size-pointer",style:{width:o*1.8,height:o*1.8}},void 0,!1,{fileName:ke,lineNumber:22,columnNumber:13},this)},o,!1,{fileName:ke,lineNumber:21,columnNumber:11},this)})},void 0,!1,{fileName:ke,lineNumber:12,columnNumber:5},this)}function ee(e){const t=Z();c.exports.useEffect(()=>(t.on("mousedown",e),()=>{t.off("mousedown",e)}),[e,t])}function te(e){const t=Z();c.exports.useEffect(()=>(t.on("mousemove",e),()=>{t.off("mousemove",e)}),[e,t])}function se(e){const t=Z();c.exports.useEffect(()=>(t.on("mouseup",e),()=>{t.off("mouseup",e)}),[e,t])}var Xe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Mosaic/index.tsx";function xe(e,t,r){if(!r)return[0,0,0,0];const{data:o,width:i}=r,n=t*i*4+e*4;return Array.from(o.slice(n,n+4))}function Rt(e,t){const{tiles:r,size:o}=t.data;r.forEach(i=>{const n=Math.round(i.color[0]),s=Math.round(i.color[1]),a=Math.round(i.color[2]),d=i.color[3]/255;e.fillStyle=`rgba(${n}, ${s}, ${a}, ${d})`,e.fillRect(i.x-o/2,i.y-o/2,o,o)})}function St(){const e=L(),{image:t,width:r,height:o}=$(),[i,n]=G(),s=I(),[a,d]=H(),[u]=U(),[,p]=A(),[l,f]=c.exports.useState(3),h=c.exports.useRef(null),x=c.exports.useRef(null),v=i==="Mosaic",y=c.exports.useCallback(()=>{n.set("Mosaic"),p.set("crosshair")},[n,p]),w=c.exports.useCallback(()=>{v||(y(),d.clearSelect())},[v,y,d]),R=c.exports.useCallback(b=>{if(!v||x.current||!h.current||!s.current)return;const N=s.current.canvas.getBoundingClientRect(),C=b.clientX-N.x,k=b.clientY-N.y,E=l*2;x.current={name:"Mosaic",type:j.Source,data:{size:E,tiles:[{x:C,y:k,color:xe(C,k,h.current)}]},editHistory:[],draw:Rt}},[v,l,s]),z=c.exports.useCallback(b=>{if(!v||!x.current||!s.current||!h.current)return;const N=s.current.canvas.getBoundingClientRect(),C=b.clientX-N.x,k=b.clientY-N.y,E=x.current.data.size,D=x.current.data.tiles;let S=D[D.length-1];if(!S)D.push({x:C,y:k,color:xe(C,k,h.current)});else{const O=S.x-C,B=S.y-k;let _=Math.sqrt(O**2+B**2);const ge=-B/_,ve=-O/_;for(;_>E;){const ne=Math.floor(S.x+E*ve),re=Math.floor(S.y+E*ge);S={x:ne,y:re,color:xe(ne,re,h.current)},D.push(S),_-=E}_>E/2&&D.push({x:C,y:k,color:xe(C,k,h.current)})}a.top!==x.current?d.push(x.current):d.set(a)},[v,s,a,d]),m=c.exports.useCallback(()=>{!v||(x.current=null)},[v]);return ee(R),te(z),se(m),c.exports.useEffect(()=>{if(!u||!t||!v)return;const b=document.createElement("canvas"),N=b.getContext("2d");if(!N)return;b.width=u.width,b.height=u.height;const C=t.naturalWidth/r,k=t.naturalHeight/o;N.drawImage(t,u.x*C,u.y*k,u.width*C,u.height*k,0,0,u.width,u.height),h.current=N.getImageData(0,0,u.width,u.height)},[r,o,u,t,v]),g.exports.jsxDEV(X,{title:e.operation_mosaic_title,icon:"icon-mosaic",checked:v,onClick:w,option:g.exports.jsxDEV(He,{value:l,onChange:f},void 0,!1,{fileName:Xe,lineNumber:220,columnNumber:15},this)},void 0,!1,{fileName:Xe,lineNumber:215,columnNumber:5},this)}var Fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsColor/index.tsx";function kt({value:e,onChange:t}){const r=["#ee5126","#fceb4d","#90e746","#51c0fa","#7a7a7a","#ffffff"];return g.exports.jsxDEV("div",{className:"screenshots-color",children:r.map(o=>{const i=["screenshots-color-item"];return o===e&&i.push("screenshots-color-active"),g.exports.jsxDEV("div",{className:i.join(" "),style:{backgroundColor:o},onClick:()=>t&&t(o)},o,!1,{fileName:Fe,lineNumber:19,columnNumber:11},this)})},void 0,!1,{fileName:Fe,lineNumber:12,columnNumber:5},this)}var we="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSizeColor/index.tsx";function ce({size:e,color:t,onSizeChange:r,onColorChange:o}){return g.exports.jsxDEV("div",{className:"screenshots-sizecolor",children:[g.exports.jsxDEV(He,{value:e,onChange:r},void 0,!1,{fileName:we,lineNumber:16,columnNumber:7},this),g.exports.jsxDEV(kt,{value:t,onChange:o},void 0,!1,{fileName:we,lineNumber:17,columnNumber:7},this)]},void 0,!0,{fileName:we,lineNumber:15,columnNumber:5},this)}const wt=`
|
|
2
|
+
min-width: 0 !important;
|
|
3
|
+
width: 0 !important;
|
|
4
|
+
min-height: 0 !important;
|
|
5
|
+
height:0 !important;
|
|
6
|
+
visibility: hidden !important;
|
|
7
|
+
overflow: hidden !important;
|
|
8
|
+
position: absolute !important;
|
|
9
|
+
z-index: -1000 !important;
|
|
10
|
+
top:0 !important;
|
|
11
|
+
right:0 !important;
|
|
12
|
+
`,Dt=["letter-spacing","line-height","padding-top","padding-bottom","font-family","font-weight","font-size","font-variant","text-rendering","text-transform","text-indent","padding-left","padding-right","border-width","box-sizing","white-space","word-break"];let W;function zt(e){const t=window.getComputedStyle(e),r=t.getPropertyValue("box-sizing")||t.getPropertyValue("-moz-box-sizing")||t.getPropertyValue("-webkit-box-sizing"),o=parseFloat(t.getPropertyValue("padding-bottom"))+parseFloat(t.getPropertyValue("padding-top")),i=parseFloat(t.getPropertyValue("border-bottom-width"))+parseFloat(t.getPropertyValue("border-top-width"));return{sizingStyle:Dt.map(s=>`${s}:${t.getPropertyValue(s)}`).join(";"),paddingSize:o,borderSize:i,boxSizing:r}}function Et(e,t,r,o){W||(W=document.createElement("textarea"),W.setAttribute("tab-index","-1"),document.body.appendChild(W));const{paddingSize:i,borderSize:n,boxSizing:s,sizingStyle:a}=zt(e);W.setAttribute("style",`${a};${wt};max-width:${r}px;max-height:${o}px`),W.value=t||" ";let d=W.scrollWidth,u=W.scrollHeight;return s==="border-box"?(d+=n,u+=n):s==="content-box"&&(d-=i,u-=i),{width:Math.min(d,r),height:Math.min(u,o)}}var jt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsTextarea/index.tsx";function Bt({x:e,y:t,maxWidth:r,maxHeight:o,size:i,color:n,value:s,onChange:a,onBlur:d}){const u=c.exports.useRef(null),p=c.exports.useRef(null),[l,f]=c.exports.useState(0),[h,x]=c.exports.useState(0),v=()=>(u.current||(u.current=document.createElement("div")),u.current);return c.exports.useLayoutEffect(()=>(u.current&&(document.body.appendChild(u.current),requestAnimationFrame(()=>{var y;(y=p.current)==null||y.focus()})),()=>{var y;(y=u.current)==null||y.remove()}),[]),c.exports.useLayoutEffect(()=>{if(!p.current)return;const{width:y,height:w}=Et(p.current,s,r,o);f(y),x(w)},[s,r,o]),_e.exports.createPortal(g.exports.jsxDEV("textarea",{ref:p,className:"screenshots-textarea",style:{left:e,top:t,color:n,width:l,height:h,maxWidth:r,maxHeight:o,fontSize:i,lineHeight:`${i}px`},value:s,onChange:y=>a&&a(y.target.value),onBlur:y=>d&&d(y)},void 0,!1,{fileName:jt,lineNumber:65,columnNumber:5},this),v())}function ae(e){const t=Z();c.exports.useEffect(()=>(t.on("drawselect",e),()=>{t.off("drawselect",e)}),[e,t])}var De="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Text/index.tsx";const ze={3:18,6:32,9:46};function Mt(e,t){const{size:r,color:o,fontFamily:i,x:n,y:s,text:a}=t.data;e.fillStyle=o,e.textAlign="left",e.textBaseline="top",e.font=`${r}px ${i}`;const d=t.editHistory.reduce((u,{data:p})=>({x:u.x+p.x2-p.x1,y:u.y+p.y2-p.y1}),{x:0,y:0});a.split(`
|
|
13
|
+
`).forEach((u,p)=>{e.fillText(u,n+d.x,s+d.y+p*r)})}function Vt(e,t,r){e.textAlign="left",e.textBaseline="top",e.font=`${t.data.size}px ${t.data.fontFamily}`;let o=0,i=0;t.data.text.split(`
|
|
14
|
+
`).forEach(l=>{const f=e.measureText(l);o<f.width&&(o=f.width),i+=t.data.size});const{x:n,y:s}=t.editHistory.reduce((l,{data:f})=>({x:l.x+f.x2-f.x1,y:l.y+f.y2-f.y1}),{x:0,y:0}),a=t.data.x+n,d=t.data.y+s,u=a+o,p=d+i;return r.x>=a&&r.x<=u&&r.y>=d&&r.y<=p}function _t(){const e=L(),[t,r]=H(),[o]=U(),[i,n]=G(),[,s]=A(),a=I(),[d,u]=c.exports.useState(3),[p,l]=c.exports.useState("#ee5126"),f=c.exports.useRef(null),h=c.exports.useRef(null),[x,v]=c.exports.useState(null),[y,w]=c.exports.useState(""),R=i==="Text",z=c.exports.useCallback(()=>{n.set("Text"),s.set("default")},[n,s]),m=c.exports.useCallback(()=>{R||(z(),r.clearSelect())},[R,z,r]),b=c.exports.useCallback(B=>{f.current&&(f.current.data.size=ze[B]),u(B)},[]),N=c.exports.useCallback(B=>{f.current&&(f.current.data.color=B),l(B)},[]),C=c.exports.useCallback(B=>{w(B),R&&f.current&&(f.current.data.text=B)},[R]),k=c.exports.useCallback(()=>{f.current&&f.current.data.text&&r.push(f.current),f.current=null,w(""),v(null)},[r]),E=c.exports.useCallback((B,_)=>{B.name==="Text"&&(z(),h.current={type:j.Edit,data:{x1:_.clientX,y1:_.clientY,x2:_.clientX,y2:_.clientY},source:B},r.select(B))},[z,r]),D=c.exports.useCallback(B=>{if(!R||!a.current||f.current||!o)return;const{left:_,top:ge}=a.current.canvas.getBoundingClientRect(),ve=window.getComputedStyle(a.current.canvas).fontFamily,ne=B.clientX-_,re=B.clientY-ge;f.current={name:"Text",type:j.Source,data:{size:ze[d],color:p,fontFamily:ve,x:ne,y:re,text:""},editHistory:[],draw:Mt,isHit:Vt},v({x:B.clientX,y:B.clientY,maxWidth:o.width-ne,maxHeight:o.height-re})},[R,d,p,o,a]),S=c.exports.useCallback(B=>{!R||h.current&&(h.current.data.x2=B.clientX,h.current.data.y2=B.clientY,t.top!==h.current?(h.current.source.editHistory.push(h.current),r.push(h.current)):r.set(t))},[R,t,r]),O=c.exports.useCallback(()=>{!R||(h.current=null)},[R]);return ae(E),ee(D),te(S),se(O),g.exports.jsxDEV(g.exports.Fragment,{children:[g.exports.jsxDEV(X,{title:e.operation_text_title,icon:"icon-text",checked:R,onClick:m,option:g.exports.jsxDEV(ce,{size:d,color:p,onSizeChange:b,onColorChange:N},void 0,!1,{fileName:De,lineNumber:261,columnNumber:11},this)},void 0,!1,{fileName:De,lineNumber:255,columnNumber:7},this),R&&x&&g.exports.jsxDEV(Bt,{x:x.x,y:x.y,maxWidth:x.maxWidth,maxHeight:x.maxHeight,size:ze[d],color:p,value:y,onChange:C,onBlur:k},void 0,!1,{fileName:De,lineNumber:265,columnNumber:9},this)]},void 0,!0)}const Ye=4;function M(e,t,r){e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.arc(t,r,Ye,0,2*Math.PI),e.fill(),e.stroke()}function be(e,t,r){t.draw(e,t);const{data:o}=e.getImageData(r.x,r.y,1,1);return o.some(i=>i!==0)}function V(e,t,r){if(!e)return!1;const{left:o,top:i}=e.getBoundingClientRect(),n=t.clientX-o,s=t.clientY-i;return(r.x-n)**2+(r.y-s)**2<Ye**2}function $t(e,t){const{size:r,color:o,points:i}=t.data;e.lineCap="round",e.lineJoin="round",e.lineWidth=r,e.strokeStyle=o;const n=t.editHistory.reduce((s,{data:a})=>({x:s.x+a.x2-a.x1,y:s.y+a.y2-a.y1}),{x:0,y:0});e.beginPath(),i.forEach((s,a)=>{a===0?e.moveTo(s.x+n.x,s.y+n.y):e.lineTo(s.x+n.x,s.y+n.y)}),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.beginPath(),i.forEach((s,a)=>{a===0?e.moveTo(s.x+n.x,s.y+n.y):e.lineTo(s.x+n.x,s.y+n.y)}),e.stroke())}var Pe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Brush/index.tsx";function Lt(){const e=L(),[,t]=A(),[r,o]=G(),i=I(),[n,s]=H(),[a,d]=c.exports.useState(3),[u,p]=c.exports.useState("#ee5126"),l=c.exports.useRef(null),f=c.exports.useRef(null),h=r==="Brush",x=c.exports.useCallback(()=>{o.set("Brush"),t.set("default")},[o,t]),v=c.exports.useCallback(()=>{h||(x(),s.clearSelect())},[h,x,s]),y=c.exports.useCallback((m,b)=>{m.name==="Brush"&&(x(),f.current={type:j.Edit,data:{x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:m},s.select(m))},[x,s]),w=c.exports.useCallback(m=>{if(!h||l.current||!i.current)return;const{left:b,top:N}=i.current.canvas.getBoundingClientRect();l.current={name:"Brush",type:j.Source,data:{size:a,color:u,points:[{x:m.clientX-b,y:m.clientY-N}]},editHistory:[],draw:$t,isHit:be}},[h,i,a,u]),R=c.exports.useCallback(m=>{if(!(!h||!i.current)){if(f.current)f.current.data.x2=m.clientX,f.current.data.y2=m.clientY,n.top!==f.current?(f.current.source.editHistory.push(f.current),s.push(f.current)):s.set(n);else if(l.current){const{left:b,top:N}=i.current.canvas.getBoundingClientRect();l.current.data.points.push({x:m.clientX-b,y:m.clientY-N}),n.top!==l.current?s.push(l.current):s.set(n)}}},[h,n,i,s]),z=c.exports.useCallback(()=>{!h||(l.current&&s.clearSelect(),l.current=null,f.current=null)},[h,s]);return ae(y),ee(w),te(R),se(z),g.exports.jsxDEV(X,{title:e.operation_brush_title,icon:"icon-brush",checked:h,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:p},void 0,!1,{fileName:Pe,lineNumber:166,columnNumber:15},this)},void 0,!1,{fileName:Pe,lineNumber:161,columnNumber:5},this)}function Te(e){let{x1:t,y1:r,x2:o,y2:i}=e.data;return e.editHistory.forEach(({data:n})=>{const s=n.x2-n.x1,a=n.y2-n.y1;n.type===ue.Move?(t+=s,r+=a,o+=s,i+=a):n.type===ue.MoveStart?(t+=s,r+=a):n.type===ue.MoveEnd&&(o+=s,i+=a)}),pe(T({},e.data),{x1:t,x2:o,y1:r,y2:i})}function Ht(e,t){const{size:r,color:o,x1:i,x2:n,y1:s,y2:a}=Te(t);e.lineCap="round",e.lineJoin="bevel",e.lineWidth=r,e.strokeStyle=o;const d=n-i,u=a-s,p=r*3,l=Math.atan2(u,d);e.beginPath(),e.moveTo(i,s),e.lineTo(n,a),e.lineTo(n-p*Math.cos(l-Math.PI/6),a-p*Math.sin(l-Math.PI/6)),e.moveTo(n,a),e.lineTo(n-p*Math.cos(l+Math.PI/6),a-p*Math.sin(l+Math.PI/6)),e.stroke(),t.isSelected&&(M(e,i,s),M(e,n,a))}var Ue="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Arrow/index.tsx",ue;(function(e){e[e.Move=0]="Move",e[e.MoveStart=1]="MoveStart",e[e.MoveEnd=2]="MoveEnd"})(ue||(ue={}));function Xt(){const e=L(),[,t]=A(),[r,o]=G(),[i,n]=H(),s=I(),[a,d]=c.exports.useState(3),[u,p]=c.exports.useState("#ee5126"),l=c.exports.useRef(null),f=c.exports.useRef(null),h=r==="Arrow",x=c.exports.useCallback(()=>{o.set("Arrow"),t.set("default")},[o,t]),v=c.exports.useCallback(()=>{h||(x(),n.clearSelect())},[h,x,n]),y=c.exports.useCallback((m,b)=>{if(m.name!=="Arrow"||!s.current)return;const N=m;x();const{x1:C,y1:k,x2:E,y2:D}=Te(N);let S=0;V(s.current.canvas,b,{x:C,y:k})?S=1:V(s.current.canvas,b,{x:E,y:D})&&(S=2),f.current={type:j.Edit,data:{type:S,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:N},n.select(m)},[s,x,n]),w=c.exports.useCallback(m=>{if(!h||l.current||!s.current)return;const{left:b,top:N}=s.current.canvas.getBoundingClientRect();l.current={name:"Arrow",type:j.Source,data:{size:a,color:u,x1:m.clientX-b,y1:m.clientY-N,x2:m.clientX-b,y2:m.clientY-N},editHistory:[],draw:Ht,isHit:be}},[h,u,a,s]),R=c.exports.useCallback(m=>{if(!(!h||!s.current)){if(f.current)f.current.data.x2=m.clientX,f.current.data.y2=m.clientY,i.top!==f.current?(f.current.source.editHistory.push(f.current),n.push(f.current)):n.set(i);else if(l.current){const{left:b,top:N}=s.current.canvas.getBoundingClientRect();l.current.data.x2=m.clientX-b,l.current.data.y2=m.clientY-N,i.top!==l.current?n.push(l.current):n.set(i)}}},[h,i,s,n]),z=c.exports.useCallback(()=>{!h||(l.current&&n.clearSelect(),l.current=null,f.current=null)},[h,n]);return ae(y),ee(w),te(R),se(z),g.exports.jsxDEV(X,{title:e.operation_arrow_title,icon:"icon-arrow",checked:h,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:p},void 0,!1,{fileName:Ue,lineNumber:190,columnNumber:15},this)},void 0,!1,{fileName:Ue,lineNumber:185,columnNumber:5},this)}function Ae(e){let{x1:t,y1:r,x2:o,y2:i}=e.data;return e.editHistory.forEach(({data:n})=>{const s=n.x2-n.x1,a=n.y2-n.y1;n.type===F.Move?(t+=s,r+=a,o+=s,i+=a):n.type===F.ResizeTop?r+=a:n.type===F.ResizeRightTop?(o+=s,r+=a):n.type===F.ResizeRight?o+=s:n.type===F.ResizeRightBottom?(o+=s,i+=a):n.type===F.ResizeBottom?i+=a:n.type===F.ResizeLeftBottom?(t+=s,i+=a):n.type===F.ResizeLeft?t+=s:n.type===F.ResizeLeftTop&&(t+=s,r+=a)}),pe(T({},e.data),{x1:t,x2:o,y1:r,y2:i})}function Ft(e,t){const{size:r,color:o,x1:i,y1:n,x2:s,y2:a}=Ae(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=r,e.strokeStyle=o;const d=(i+s)/2,u=(n+a)/2,p=Math.abs(s-i)/2,l=Math.abs(a-n)/2,f=.5522848,h=p*f,x=l*f;e.beginPath(),e.moveTo(d-p,u),e.bezierCurveTo(d-p,u-x,d-h,u-l,d,u-l),e.bezierCurveTo(d+h,u-l,d+p,u-x,d+p,u),e.bezierCurveTo(d+p,u+x,d+h,u+l,d,u+l),e.bezierCurveTo(d-h,u+l,d-p,u+x,d-p,u),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.moveTo(i,n),e.lineTo(s,n),e.lineTo(s,a),e.lineTo(i,a),e.closePath(),e.stroke(),M(e,(i+s)/2,n),M(e,s,n),M(e,s,(n+a)/2),M(e,s,a),M(e,(i+s)/2,a),M(e,i,a),M(e,i,(n+a)/2),M(e,i,n))}var Ge="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ellipse/index.tsx",F;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(F||(F={}));function Yt(){const e=L(),[t,r]=H(),[o,i]=G(),[,n]=A(),s=I(),[a,d]=c.exports.useState(3),[u,p]=c.exports.useState("#ee5126"),l=c.exports.useRef(null),f=c.exports.useRef(null),h=o==="Ellipse",x=c.exports.useCallback(()=>{i.set("Ellipse"),n.set("crosshair")},[i,n]),v=c.exports.useCallback(()=>{h||(x(),r.clearSelect())},[h,x,r]),y=c.exports.useCallback((m,b)=>{if(m.name!=="Ellipse"||!s.current)return;const N=m;x();const{x1:C,y1:k,x2:E,y2:D}=Ae(N);let S=0;V(s.current.canvas,b,{x:(C+E)/2,y:k})?S=1:V(s.current.canvas,b,{x:E,y:k})?S=2:V(s.current.canvas,b,{x:E,y:(k+D)/2})?S=3:V(s.current.canvas,b,{x:E,y:D})?S=4:V(s.current.canvas,b,{x:(C+E)/2,y:D})?S=5:V(s.current.canvas,b,{x:C,y:D})?S=6:V(s.current.canvas,b,{x:C,y:(k+D)/2})?S=7:V(s.current.canvas,b,{x:C,y:k})&&(S=8),f.current={type:j.Edit,data:{type:S,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:N},r.select(m)},[s,x,r]),w=c.exports.useCallback(m=>{if(!h||!s.current||l.current)return;const{left:b,top:N}=s.current.canvas.getBoundingClientRect(),C=m.clientX-b,k=m.clientY-N;l.current={name:"Ellipse",type:j.Source,data:{size:a,color:u,x1:C,y1:k,x2:C,y2:k},editHistory:[],draw:Ft,isHit:be}},[h,a,u,s]),R=c.exports.useCallback(m=>{if(!(!h||!s.current)){if(f.current)f.current.data.x2=m.clientX,f.current.data.y2=m.clientY,t.top!==f.current?(f.current.source.editHistory.push(f.current),r.push(f.current)):r.set(t);else if(l.current){const{left:b,top:N}=s.current.canvas.getBoundingClientRect();l.current.data.x2=m.clientX-b,l.current.data.y2=m.clientY-N,t.top!==l.current?r.push(l.current):r.set(t)}}},[h,s,t,r]),z=c.exports.useCallback(()=>{!h||(l.current&&r.clearSelect(),l.current=null,f.current=null)},[h,r]);return ae(y),ee(w),te(R),se(z),g.exports.jsxDEV(X,{title:e.operation_ellipse_title,icon:"icon-ellipse",checked:h,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:p},void 0,!1,{fileName:Ge,lineNumber:242,columnNumber:15},this)},void 0,!1,{fileName:Ge,lineNumber:237,columnNumber:5},this)}function Ie(e){let{x1:t,y1:r,x2:o,y2:i}=e.data;return e.editHistory.forEach(({data:n})=>{const s=n.x2-n.x1,a=n.y2-n.y1;n.type===Y.Move?(t+=s,r+=a,o+=s,i+=a):n.type===Y.ResizeTop?r+=a:n.type===Y.ResizeRightTop?(o+=s,r+=a):n.type===Y.ResizeRight?o+=s:n.type===Y.ResizeRightBottom?(o+=s,i+=a):n.type===Y.ResizeBottom?i+=a:n.type===Y.ResizeLeftBottom?(t+=s,i+=a):n.type===Y.ResizeLeft?t+=s:n.type===Y.ResizeLeftTop&&(t+=s,r+=a)}),pe(T({},e.data),{x1:t,x2:o,y1:r,y2:i})}function Pt(e,t){const{size:r,color:o,x1:i,y1:n,x2:s,y2:a}=Ie(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=r,e.strokeStyle=o,e.beginPath(),e.moveTo(i,n),e.lineTo(s,n),e.lineTo(s,a),e.lineTo(i,a),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",M(e,(i+s)/2,n),M(e,s,n),M(e,s,(n+a)/2),M(e,s,a),M(e,(i+s)/2,a),M(e,i,a),M(e,i,(n+a)/2),M(e,i,n))}var We="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Rectangle/index.tsx",Y;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(Y||(Y={}));function Tt(){const e=L(),[t,r]=H(),[o,i]=G(),[,n]=A(),s=I(),[a,d]=c.exports.useState(3),[u,p]=c.exports.useState("#ee5126"),l=c.exports.useRef(null),f=c.exports.useRef(null),h=o==="Rectangle",x=c.exports.useCallback(()=>{i.set("Rectangle"),n.set("crosshair")},[i,n]),v=c.exports.useCallback(()=>{h||(x(),r.clearSelect())},[h,x,r]),y=c.exports.useCallback((m,b)=>{if(m.name!=="Rectangle"||!s.current)return;const N=m;x();const{x1:C,y1:k,x2:E,y2:D}=Ie(N);let S=0;V(s.current.canvas,b,{x:(C+E)/2,y:k})?S=1:V(s.current.canvas,b,{x:E,y:k})?S=2:V(s.current.canvas,b,{x:E,y:(k+D)/2})?S=3:V(s.current.canvas,b,{x:E,y:D})?S=4:V(s.current.canvas,b,{x:(C+E)/2,y:D})?S=5:V(s.current.canvas,b,{x:C,y:D})?S=6:V(s.current.canvas,b,{x:C,y:(k+D)/2})?S=7:V(s.current.canvas,b,{x:C,y:k})&&(S=8),f.current={type:j.Edit,data:{type:S,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:m},r.select(m)},[s,x,r]),w=c.exports.useCallback(m=>{if(!h||!s.current||l.current)return;const{left:b,top:N}=s.current.canvas.getBoundingClientRect(),C=m.clientX-b,k=m.clientY-N;l.current={name:"Rectangle",type:j.Source,data:{size:a,color:u,x1:C,y1:k,x2:C,y2:k},editHistory:[],draw:Pt,isHit:be}},[h,a,u,s]),R=c.exports.useCallback(m=>{if(!(!h||!s.current)){if(f.current)f.current.data.x2=m.clientX,f.current.data.y2=m.clientY,t.top!==f.current?(f.current.source.editHistory.push(f.current),r.push(f.current)):r.set(t);else if(l.current){const{left:b,top:N}=s.current.canvas.getBoundingClientRect(),C=l.current.data;C.x2=m.clientX-b,C.y2=m.clientY-N,t.top!==l.current?r.push(l.current):r.set(t)}}},[h,s,t,r]),z=c.exports.useCallback(()=>{!h||(l.current&&r.clearSelect(),l.current=null,f.current=null)},[h,r]);return ae(y),ee(w),te(R),se(z),g.exports.jsxDEV(X,{title:e.operation_rectangle_title,icon:"icon-rectangle",checked:h,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:p},void 0,!1,{fileName:We,lineNumber:242,columnNumber:15},this)},void 0,!1,{fileName:We,lineNumber:237,columnNumber:5},this)}var Ut=[Tt,Yt,Xt,Lt,_t,St,"|",Ct,yt,"|",gt,xt,mt];var le="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOperations/index.tsx";const Oe=Ve.createContext(null);function At(){const{width:e,height:t}=$(),[r]=U(),[o,i]=c.exports.useState(null),[n,s]=c.exports.useState(null),a=c.exports.useRef(null),d=c.exports.useCallback(p=>{p.stopPropagation()},[]),u=c.exports.useCallback(p=>{p.preventDefault(),p.stopPropagation()},[]);return c.exports.useEffect(()=>{if(!r||!a.current)return;const p=a.current.getBoundingClientRect();let l=r.x+r.width-p.width,f=r.y+r.height+10;l<0&&(l=0),l>e-p.width&&(l=e-p.width),f>t-p.height&&(f=t-p.height-10),((n==null?void 0:n.x)!==l||n.y!==f)&&s({x:l,y:f}),((o==null?void 0:o.x)!==p.x||o.y!==p.y||o.width!==p.width||o.height!==p.height)&&i({x:p.x,y:p.y,width:p.width,height:p.height})}),r?g.exports.jsxDEV(Oe.Provider,{value:o,children:g.exports.jsxDEV("div",{ref:a,className:"screenshots-operations",style:{visibility:n?"visible":"hidden",left:n==null?void 0:n.x,top:n==null?void 0:n.y},onDoubleClick:d,onContextMenu:u,children:g.exports.jsxDEV("div",{className:"screenshots-operations-buttons",children:Ut.map((p,l)=>p==="|"?g.exports.jsxDEV("div",{className:"screenshots-operations-divider"},l,!1,{fileName:le,lineNumber:91,columnNumber:22},this):g.exports.jsxDEV(p,{},l,!1,{fileName:le,lineNumber:93,columnNumber:22},this))},void 0,!1,{fileName:le,lineNumber:88,columnNumber:9},this)},void 0,!1,{fileName:le,lineNumber:77,columnNumber:7},this)},void 0,!1,{fileName:le,lineNumber:76,columnNumber:5},this):null}function Gt(e){const[t,r]=c.exports.useState(null);return c.exports.useEffect(()=>{if(r(null),e==null)return;const o=document.createElement("img"),i=()=>r(o),n=()=>r(null);return o.addEventListener("load",i),o.addEventListener("error",n),o.src=e,()=>{o.removeEventListener("load",i),o.removeEventListener("error",n)}},[e]),t}var fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/index.tsx";function It(s){var a=s,{url:e,width:t,height:r,lang:o,className:i}=a,n=Me(a,["url","width","height","lang","className"]);const d=Gt(e),u=c.exports.useRef(null),p=c.exports.useRef({}),[l,f]=c.exports.useState({index:-1,stack:[]}),[h,x]=c.exports.useState(null),[v,y]=c.exports.useState("move"),[w,R]=c.exports.useState(void 0),z={url:e,width:t,height:r,image:d,lang:T(T({},$e),o),emiterRef:p,canvasContextRef:u,history:l,bounds:h,cursor:v,operation:w},m=c.exports.useCallback((D,...S)=>{const O=n[D];typeof O=="function"&&O(...S)},[n]),b={call:m,setHistory:f,setBounds:x,setCursor:y,setOperation:R},N=["screenshots"];i&&N.push(i);const C=()=>{p.current={},f({index:-1,stack:[]}),x(null),y("move"),R(void 0)},k=c.exports.useCallback(D=>{D.button!==0||!h||!u.current||u.current.canvas.toBlob(S=>{m("onOk",S,h),C()},"image/png")},[h,m]),E=c.exports.useCallback(D=>{D.button===2&&(D.preventDefault(),m("onCancel"),C())},[m]);return c.exports.useLayoutEffect(()=>{C()},[e]),g.exports.jsxDEV(ye.Provider,{value:{store:z,dispatcher:b},children:g.exports.jsxDEV("div",{className:N.join(" "),style:{width:t,height:r},onDoubleClick:k,onContextMenu:E,children:[g.exports.jsxDEV(ot,{},void 0,!1,{fileName:fe,lineNumber:123,columnNumber:9},this),g.exports.jsxDEV(ft,{ref:u},void 0,!1,{fileName:fe,lineNumber:124,columnNumber:9},this),g.exports.jsxDEV(At,{},void 0,!1,{fileName:fe,lineNumber:125,columnNumber:9},this)]},void 0,!0,{fileName:fe,lineNumber:117,columnNumber:7},this)},void 0,!1,{fileName:fe,lineNumber:116,columnNumber:5},this)}var qe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/electron/app.tsx";function Wt(){const[e,t]=c.exports.useState(void 0),[r,o]=c.exports.useState(window.innerWidth),[i,n]=c.exports.useState(window.innerHeight),[s,a]=c.exports.useState(void 0),[d,u]=c.exports.useState(void 0),p=c.exports.useCallback(async(h,x)=>{!s||!h||window.screenshots.save(await h.arrayBuffer(),{bounds:x,display:s})},[s]),l=c.exports.useCallback(()=>{window.screenshots.cancel()},[]),f=c.exports.useCallback(async(h,x)=>{!s||!h||window.screenshots.ok(await h.arrayBuffer(),{bounds:x,display:s})},[s]);return c.exports.useEffect(()=>{const h=y=>{u(y)},x=(y,w)=>{a(y),t(w)},v=()=>{t(void 0),a(void 0),requestAnimationFrame(()=>window.screenshots.reset())};return window.screenshots.on("setLang",h),window.screenshots.on("capture",x),window.screenshots.on("reset",v),window.screenshots.ready(),()=>{window.screenshots.off("capture",x),window.screenshots.off("setLang",h),window.screenshots.off("reset",v)}},[]),c.exports.useEffect(()=>{const h=()=>{o(window.innerWidth),n(window.innerHeight)};return window.addEventListener("resize",h),()=>{window.removeEventListener("resize",h)}},[l]),g.exports.jsxDEV("div",{className:"body",children:g.exports.jsxDEV(It,{url:e,width:r,height:i,lang:d,onSave:p,onCancel:l,onOk:f},void 0,!1,{fileName:qe,lineNumber:89,columnNumber:7},this)},void 0,!1,{fileName:qe,lineNumber:88,columnNumber:5},this)}var Je="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/electron/index.tsx";tt.render(g.exports.jsxDEV(c.exports.StrictMode,{children:g.exports.jsxDEV(Wt,{},void 0,!1,{fileName:Je,lineNumber:7,columnNumber:5},globalThis)},void 0,!1,{fileName:Je,lineNumber:6,columnNumber:3},globalThis),document.getElementById("app"));
|
package/electron/electron.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>react-screenshots</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index.
|
|
7
|
+
<script type="module" crossorigin src="./assets/index.6be07a29.js"></script>
|
|
8
8
|
<link rel="modulepreload" href="./assets/vendor.e3c417b2.js">
|
|
9
9
|
<link rel="stylesheet" href="./assets/index.72e90af8.css">
|
|
10
10
|
</head>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var qe=Object.defineProperty,Je=Object.defineProperties;var Qe=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable;var De=(e,t,s)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,U=(e,t)=>{for(var s in t||(t={}))Ee.call(t,s)&&De(e,s,t[s]);if(he)for(var s of he(t))Be.call(t,s)&&De(e,s,t[s]);return e},me=(e,t)=>Je(e,Qe(t));var Me=(e,t)=>{var s={};for(var o in e)Ee.call(e,o)&&t.indexOf(o)<0&&(s[o]=e[o]);if(e!=null&&he)for(var o of he(e))t.indexOf(o)<0&&Be.call(e,o)&&(s[o]=e[o]);return s};var i=require("react"),$e=require("react-dom");function Ke(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var _=Ke(i);const Le={magnifier_position_label:"\u5750\u6807",operation_ok_title:"\u786E\u5B9A",operation_cancel_title:"\u53D6\u6D88",operation_save_title:"\u4FDD\u5B58",operation_redo_title:"\u91CD\u505A",operation_undo_title:"\u64A4\u9500",operation_mosaic_title:"\u9A6C\u8D5B\u514B",operation_text_title:"\u6587\u672C",operation_brush_title:"\u753B\u7B14",operation_arrow_title:"\u7BAD\u5934",operation_ellipse_title:"\u692D\u5706",operation_rectangle_title:"\u77E9\u5F62"};var xe=_.default.createContext({store:{url:void 0,image:null,width:0,height:0,lang:Le,emiterRef:{current:{}},canvasContextRef:{current:null},history:{index:-1,stack:[]},bounds:null,cursor:"move",operation:void 0},dispatcher:{call:void 0,setHistory:void 0,setBounds:void 0,setCursor:void 0,setOperation:void 0}});function oe(){const{dispatcher:e}=i.useContext(xe);return e}function H(){const{store:e}=i.useContext(xe);return e}function G(){const{bounds:e}=H(),{setBounds:t}=oe(),s=i.useCallback(c=>{t==null||t(c)},[t]),o=i.useCallback(()=>{t==null||t(null)},[t]);return[e,{set:s,reset:o}]}function X(){const{lang:e}=H();return e}var J="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsMagnifier/index.tsx";const Q=100,K=80;function Ze({x:e,y:t}){const{width:s,height:o,image:c}=H(),r=X(),[n,u]=i.useState(null),p=i.useRef(null),l=i.useRef(null),h=i.useRef(null),[f,a]=i.useState("000000");return i.useLayoutEffect(()=>{if(!p.current)return;const m=p.current.getBoundingClientRect();let b=e+20,y=t+20;b+m.width>s&&(b=e-m.width-20),y+m.height>o&&(y=t-m.height-20),b<0&&(b=0),y<0&&(y=0),u({x:b,y})},[s,o,e,t]),i.useEffect(()=>{if(!c||!l.current){h.current=null;return}if(h.current||(h.current=l.current.getContext("2d")),!h.current)return;const m=h.current;m.clearRect(0,0,Q,K);const b=c.naturalWidth/s,y=c.naturalHeight/o;m.drawImage(c,e*b-Q/2,t*y-K/2,Q,K,0,0,Q,K);const{data:v}=m.getImageData(Math.floor(Q/2),Math.floor(K/2),1,1),S=Array.from(v.slice(0,3)).map(C=>C>=16?C.toString(16):`0${C.toString(16)}`).join("").toUpperCase();a(S)},[s,o,c,e,t]),_.default.createElement("div",{ref:p,className:"screenshots-magnifier",style:{transform:`translate(${n==null?void 0:n.x}px, ${n==null?void 0:n.y}px)`},__self:this,__source:{fileName:J,lineNumber:89,columnNumber:5}},_.default.createElement("div",{className:"screenshots-magnifier-body",__self:this,__source:{fileName:J,lineNumber:96,columnNumber:7}},_.default.createElement("canvas",{ref:l,className:"screenshots-magnifier-body-canvas",width:Q,height:K,__self:this,__source:{fileName:J,lineNumber:97,columnNumber:9}})),_.default.createElement("div",{className:"screenshots-magnifier-footer",__self:this,__source:{fileName:J,lineNumber:104,columnNumber:7}},_.default.createElement("div",{className:"screenshots-magnifier-footer-item",__self:this,__source:{fileName:J,lineNumber:105,columnNumber:9}},r.magnifier_position_label,": (",e,",",t,")"),_.default.createElement("div",{className:"screenshots-magnifier-footer-item",__self:this,__source:{fileName:J,lineNumber:108,columnNumber:9}},"RGB: #",f)))}function et({x:e,y:t},{x:s,y:o},c,r){return e>s&&([e,s]=[s,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0),s>c&&(s=c),t<0&&(t=0),o>r&&(o=r),{x:e,y:t,width:s-e,height:o-t}}var de="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsBackground/index.tsx";function tt(){const{url:e,image:t,width:s,height:o}=H(),[c,r]=G(),n=i.useRef(null),u=i.useRef(null),[p,l]=i.useState(null),h=i.useCallback((a,m)=>{if(!n.current)return;const{x:b,y}=n.current.getBoundingClientRect();r.set(et({x:a.x-b,y:a.y-y},{x:m.x-b,y:m.y-y},s,o))},[s,o,r]),f=i.useCallback(a=>{u.current||c||a.button!==0||(u.current={x:a.clientX,y:a.clientY})},[c]);return i.useEffect(()=>{const a=b=>{if(n.current){const y=n.current.getBoundingClientRect();b.clientX<y.left||b.clientY<y.top||b.clientX>y.right||b.clientY>y.bottom?l(null):l({x:b.clientX-y.x,y:b.clientY-y.y})}!u.current||h(u.current,{x:b.clientX,y:b.clientY})},m=b=>{!u.current||(h(u.current,{x:b.clientX,y:b.clientY}),u.current=null)};return window.addEventListener("mousemove",a),window.addEventListener("mouseup",m),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",m)}},[h]),!e||!t?null:_.default.createElement("div",{ref:n,className:"screenshots-background",onMouseDown:f,__self:this,__source:{fileName:de,lineNumber:105,columnNumber:5}},_.default.createElement("img",{className:"screenshots-background-image",src:e,__self:this,__source:{fileName:de,lineNumber:110,columnNumber:7}}),_.default.createElement("div",{className:"screenshots-background-mask",__self:this,__source:{fileName:de,lineNumber:111,columnNumber:7}}),p&&!c&&_.default.createElement(Ze,{x:p==null?void 0:p.x,y:p==null?void 0:p.y,__self:this,__source:{fileName:de,lineNumber:112,columnNumber:31}}))}var Ve;const He=(Ve=window.devicePixelRatio)!=null?Ve:2;var pe=He<2?2:He;function nt(e,t,s,o){const c=e.clientX-s.x,r=e.clientY-s.y;let n=o.x,u=o.y,p=o.x+o.width,l=o.y+o.height;switch(t){case"top":u+=r;break;case"top-right":p+=c,u+=r;break;case"right":p+=c;break;case"right-bottom":p+=c,l+=r;break;case"bottom":l+=r;break;case"bottom-left":n+=c,l+=r;break;case"left":n+=c;break;case"left-top":n+=c,u+=r;break;case"move":n+=c,u+=r,p+=c,l+=r;break}return[{x:n,y:u},{x:p,y:l}]}function st({x:e,y:t},{x:s,y:o},c,r,n,u){return e>s&&([e,s]=[s,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0,u==="move"&&(s=c.width)),s>r&&(s=r,u==="move"&&(e=s-c.width)),t<0&&(t=0,u==="move"&&(o=c.height)),o>n&&(o=n,u==="move"&&(t=o-c.height)),{x:e,y:t,width:Math.max(s-e,1),height:Math.max(o-t,1)}}var B;(function(e){e[e.Edit=0]="Edit",e[e.Source=1]="Source"})(B||(B={}));function Z(){const{emiterRef:e}=H(),t=i.useCallback((r,n)=>{const u=e.current;Array.isArray(u[r])?u[r].push(n):u[r]=[n]},[e]),s=i.useCallback((r,n)=>{const u=e.current;if(Array.isArray(u[r])){const p=u[r].findIndex(l=>l===n);p!==-1&&u[r].splice(p,1)}},[e]),o=i.useCallback((r,...n)=>{const u=e.current;Array.isArray(u[r])&&u[r].forEach(p=>p(...n))},[e]),c=i.useCallback(()=>{e.current={}},[e]);return{on:t,off:s,emit:o,reset:c}}function Y(){const{history:e}=H(),{setHistory:t}=oe(),s=i.useCallback(h=>{const{index:f,stack:a}=e;a.forEach(m=>{m.type===B.Source&&(m.isSelected=!1)}),h.type===B.Source?h.isSelected=!0:h.type===B.Edit&&(h.source.isSelected=!0),a.splice(f+1),a.push(h),t==null||t({index:a.length-1,stack:a})},[e,t]),o=i.useCallback(()=>{const{stack:h}=e;h.pop(),t==null||t({index:h.length-1,stack:h})},[e,t]),c=i.useCallback(()=>{const{index:h,stack:f}=e,a=f[h];a&&(a.type===B.Source?a.isSelected=!1:a.type===B.Edit&&a.source.editHistory.pop()),t==null||t({index:h<=0?-1:h-1,stack:f})},[e,t]),r=i.useCallback(()=>{const{index:h,stack:f}=e,a=f[h+1];a&&(a.type===B.Source?a.isSelected=!1:a.type===B.Edit&&a.source.editHistory.push(a)),t==null||t({index:h>=f.length-1?f.length-1:h+1,stack:f})},[e,t]),n=i.useCallback(h=>{t==null||t(U({},h))},[t]),u=i.useCallback(h=>{e.stack.forEach(f=>{f.type===B.Source&&(f===h?f.isSelected=!0:f.isSelected=!1)}),t==null||t(U({},e))},[e,t]),p=i.useCallback(()=>{e.stack.forEach(h=>{h.type===B.Source&&(h.isSelected=!1)}),t==null||t(U({},e))},[e,t]),l=i.useCallback(()=>{t==null||t({index:-1,stack:[]})},[t]);return[{index:e.index,stack:e.stack,top:e.stack.slice(e.index,e.index+1)[0]},{push:s,pop:o,undo:c,redo:r,set:n,select:u,clearSelect:p,reset:l}]}function A(){const{cursor:e}=H(),{setCursor:t}=oe(),s=i.useCallback(c=>{t==null||t(c)},[t]),o=i.useCallback(()=>{t==null||t("move")},[t]);return[e,{set:s,reset:o}]}function I(){const{operation:e}=H(),{setOperation:t}=oe(),s=i.useCallback(c=>{t==null||t(c)},[t]),o=i.useCallback(()=>{t==null||t(void 0)},[t]);return[e,{set:s,reset:o}]}function rt(e,t,s,o){if(!t)return!1;const c=document.createElement("canvas");c.width=e.width,c.height=e.height;const r=c.getContext("2d");if(!r)return!1;const{left:n,top:u}=t.getBoundingClientRect(),p=o.clientX-n,l=o.clientY-u;return[...s.stack.slice(0,s.index+1)].reverse().find(f=>{var a;return f.type!==B.Source?!1:(r.clearRect(0,0,e.width,e.height),(a=f.isHit)==null?void 0:a.call(f,r,f,{x:p,y:l}))})}var ce="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsCanvas/index.tsx";const ot=["top","right","bottom","left"];var j;(function(e){e.ResizeTop="top",e.ResizetopRight="top-right",e.ResizeRight="right",e.ResizeRightBottom="right-bottom",e.ResizeBottom="bottom",e.ResizeBottomLeft="bottom-left",e.ResizeLeft="left",e.ResizeLeftTop="left-top",e.Move="move"})(j||(j={}));const ct=[j.ResizeTop,j.ResizetopRight,j.ResizeRight,j.ResizeRightBottom,j.ResizeBottom,j.ResizeBottomLeft,j.ResizeLeft,j.ResizeLeftTop];var it=i.forwardRef(function(t,s){const{image:o,width:c,height:r}=H(),n=Z(),[u]=Y(),[p]=A(),[l,h]=G(),[f]=I(),a=i.useRef(),m=i.useRef(null),b=i.useRef(null),y=i.useRef(null),v=i.useRef(null),S=i.useCallback(()=>{if(!o||!l||!v.current)return;const d=o.naturalWidth/c,g=o.naturalHeight/r,x=v.current;x.imageSmoothingEnabled=!0,x.imageSmoothingQuality="low",x.setTransform(pe,0,0,pe,0,0),x.clearRect(0,0,l.width,l.height),x.drawImage(o,l.x*d,l.y*g,l.width*d,l.height*g,0,0,l.width,l.height),u.stack.slice(0,u.index+1).forEach(N=>{N.type===B.Source&&N.draw(x,N)})},[o,c,r,l,v,u]),C=i.useCallback((d,g)=>{if(!(d.button!==0||!l))if(!f)a.current=g,m.current={x:d.clientX,y:d.clientY},b.current={x:l.x,y:l.y,width:l.width,height:l.height};else{const x=rt(l,y.current,u,d.nativeEvent);x?n.emit("drawselect",x,d.nativeEvent):n.emit("mousedown",d.nativeEvent)}},[l,f,n,u]),z=i.useCallback(d=>{if(!a.current||!m.current||!b.current||!l)return;const g=nt(d,a.current,m.current,b.current);h.set(st(g[0],g[1],l,c,r,a.current))},[c,r,l,h]);return i.useLayoutEffect(()=>{if(!o||!l||!y.current){v.current=null;return}v.current||(v.current=y.current.getContext("2d")),S()},[o,l,S]),i.useEffect(()=>{const d=x=>{if(f)n.emit("mousemove",x);else{if(!a.current||!m.current||!b.current)return;z(x)}},g=x=>{if(f)n.emit("mouseup",x);else{if(!a.current||!m.current||!b.current)return;z(x),a.current=void 0,m.current=null,b.current=null}};return window.addEventListener("mousemove",d),window.addEventListener("mouseup",g),()=>{window.removeEventListener("mousemove",d),window.removeEventListener("mouseup",g)}},[z,f,n]),i.useImperativeHandle(s,()=>v.current),l?_.default.createElement("div",{className:"screenshots-canvas",style:{left:l.x,top:l.y,width:l.width,height:l.height},__self:this,__source:{fileName:ce,lineNumber:191,columnNumber:5}},_.default.createElement("canvas",{ref:y,width:l.width*pe,height:l.height*pe,style:{width:l.width,height:l.height},__self:this,__source:{fileName:ce,lineNumber:200,columnNumber:7}}),_.default.createElement("div",{className:"screenshots-canvas-body",style:{cursor:p},onMouseDown:d=>C(d,"move"),__self:this,__source:{fileName:ce,lineNumber:209,columnNumber:7}}),ot.map(d=>_.default.createElement("div",{key:d,className:`screenshots-canvas-border-${d}`,__self:this,__source:{fileName:ce,lineNumber:217,columnNumber:16}})),ct.map(d=>_.default.createElement("div",{key:d,className:`screenshots-canvas-point-${d}`,onMouseDown:g=>C(g,d),__self:this,__source:{fileName:ce,lineNumber:221,columnNumber:11}}))):null});function ve(){const e=oe();return i.useCallback((s,...o)=>{var c;(c=e.call)==null||c.call(e,s,...o)},[e])}function W(){const{canvasContextRef:e}=H();return e}function Ne(){const e=Z(),[,t]=G(),[,s]=A(),[,o]=Y(),[,c]=I();return i.useCallback(()=>{e.reset(),o.reset(),t.reset(),s.reset(),c.reset()},[e,o,t,s,c])}var Ce="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOption/index.tsx",q;(function(e){e.Bottom="bottom",e.Top="top"})(q||(q={}));function ut({open:e,content:t,children:s}){const o=i.useRef(null),c=i.useRef(null),r=i.useRef(null),n=i.useContext(Oe),[u,p]=i.useState(q.Bottom),[l,h]=i.useState(null),[f,a]=i.useState(0),m=()=>(c.current||(c.current=document.createElement("div")),c.current);return i.useEffect(()=>{const b=m();return e&&document.body.appendChild(b),()=>{b.remove()}},[e]),i.useEffect(()=>{if(!e||!n||!o.current||!r.current)return;const b=o.current.getBoundingClientRect(),y=r.current.getBoundingClientRect();let v=u,S=b.left+b.width/2,C=b.top+b.height,z=f;if(S+y.width/2>n.x+n.width){const d=S;S=n.x+n.width-y.width/2,z=d-S}if(S<n.x+y.width/2){const d=S;S=n.x+y.width/2,z=d-S}C>window.innerHeight-y.height&&(v===q.Bottom&&(v=q.Top),C=b.top-y.height),C<0&&(v===q.Top&&(v=q.Bottom),C=b.top+b.height),v!==u&&p(v),((l==null?void 0:l.x)!==S||l.y!==C)&&h({x:S,y:C}),z!==f&&a(z)}),_.default.createElement(_.default.Fragment,null,i.cloneElement(s,{ref:o}),e&&t&&$e.createPortal(_.default.createElement("div",{ref:r,className:"screenshots-option",style:{visibility:l?"visible":"hidden",left:l==null?void 0:l.x,top:l==null?void 0:l.y},"data-placement":u,__self:this,__source:{fileName:Ce,lineNumber:111,columnNumber:11}},_.default.createElement("div",{className:"screenshots-option-container",__self:this,__source:{fileName:Ce,lineNumber:121,columnNumber:13}},t),_.default.createElement("div",{className:"screenshots-option-arrow",style:{marginLeft:f},__self:this,__source:{fileName:Ce,lineNumber:122,columnNumber:13}})),m()))}var ke="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsButton/index.tsx";function F({title:e,icon:t,checked:s,disabled:o,option:c,onClick:r}){const n=["screenshots-button"],u=i.useCallback(p=>{o||!r||r(p)},[o,r]);return s&&n.push("screenshots-button-checked"),o&&n.push("screenshots-button-disabled"),_.default.createElement(ut,{open:s,content:c,__self:this,__source:{fileName:ke,lineNumber:42,columnNumber:5}},_.default.createElement("div",{className:n.join(" "),title:e,onClick:u,__self:this,__source:{fileName:ke,lineNumber:43,columnNumber:7}},_.default.createElement("span",{className:t,__self:this,__source:{fileName:ke,lineNumber:44,columnNumber:9}})))}var lt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ok/index.tsx";function at(){const e=X(),t=W(),[,s]=Y(),o=ve(),[c]=G(),r=Ne(),n=i.useCallback(()=>{s.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(u=>{o("onOk",u,c),r()},"image/png")})},[t,s,o,c,r]);return _.default.createElement(F,{title:e.operation_ok_title,icon:"icon-ok",onClick:n,__self:this,__source:{fileName:lt,lineNumber:31,columnNumber:10}})}var ft="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Cancel/index.tsx";function ht(){const e=ve(),t=Ne(),s=X(),o=i.useCallback(()=>{e("onCancel"),t()},[e,t]);return _.default.createElement(F,{title:s.operation_cancel_title,icon:"icon-cancel",onClick:o,__self:this,__source:{fileName:ft,lineNumber:17,columnNumber:10}})}var mt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Save/index.tsx";function dt(){const e=X(),t=W(),[,s]=Y(),[o]=G(),c=ve(),r=Ne(),n=i.useCallback(()=>{s.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(u=>{c("onSave",u,o),r()},"image/png")})},[t,s,o,c,r]);return _.default.createElement(F,{title:e.operation_save_title,icon:"icon-save",onClick:n,__self:this,__source:{fileName:mt,lineNumber:31,columnNumber:10}})}var pt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Redo/index.tsx";function bt(){const e=X(),[t,s]=Y(),o=i.useCallback(()=>{s.redo()},[s]);return _.default.createElement(F,{title:e.operation_redo_title,icon:"icon-redo",disabled:!t.stack.length||t.stack.length-1===t.index,onClick:o,__self:this,__source:{fileName:pt,lineNumber:15,columnNumber:5}})}var gt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Undo/index.tsx";function _t(){const e=X(),[t,s]=Y(),o=i.useCallback(()=>{s.undo()},[s]);return _.default.createElement(F,{title:e.operation_undo_title,icon:"icon-undo",disabled:t.index===-1,onClick:o,__self:this,__source:{fileName:gt,lineNumber:15,columnNumber:5}})}var Re="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSize/index.tsx";function Xe({value:e,onChange:t}){const s=[3,6,9];return _.default.createElement("div",{className:"screenshots-size",__self:this,__source:{fileName:Re,lineNumber:12,columnNumber:5}},s.map(o=>{const c=["screenshots-size-item"];return o===e&&c.push("screenshots-size-active"),_.default.createElement("div",{key:o,className:c.join(" "),onClick:()=>t&&t(o),__self:this,__source:{fileName:Re,lineNumber:21,columnNumber:11}},_.default.createElement("div",{className:"screenshots-size-pointer",style:{width:o*1.8,height:o*1.8},__self:this,__source:{fileName:Re,lineNumber:22,columnNumber:13}}))}))}function ee(e){const t=Z();i.useEffect(()=>(t.on("mousedown",e),()=>{t.off("mousedown",e)}),[e,t])}function te(e){const t=Z();i.useEffect(()=>(t.on("mousemove",e),()=>{t.off("mousemove",e)}),[e,t])}function ne(e){const t=Z();i.useEffect(()=>(t.on("mouseup",e),()=>{t.off("mouseup",e)}),[e,t])}var Ye="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Mosaic/index.tsx";function be(e,t,s){if(!s)return[0,0,0,0];const{data:o,width:c}=s,r=t*c*4+e*4;return Array.from(o.slice(r,r+4))}function yt(e,t){const{tiles:s,size:o}=t.data;s.forEach(c=>{const r=Math.round(c.color[0]),n=Math.round(c.color[1]),u=Math.round(c.color[2]),p=c.color[3]/255;e.fillStyle=`rgba(${r}, ${n}, ${u}, ${p})`,e.fillRect(c.x-o/2,c.y-o/2,o,o)})}function xt(){const e=X(),{image:t,width:s,height:o}=H(),[c,r]=I(),n=W(),[u,p]=Y(),[l]=G(),[,h]=A(),[f,a]=i.useState(3),m=i.useRef(null),b=i.useRef(null),y=c==="Mosaic",v=i.useCallback(()=>{r.set("Mosaic"),h.set("crosshair")},[r,h]),S=i.useCallback(()=>{y||(v(),p.clearSelect())},[y,v,p]),C=i.useCallback(g=>{if(!y||b.current||!m.current||!n.current)return;const x=n.current.canvas.getBoundingClientRect(),N=g.clientX-x.x,R=g.clientY-x.y,E=f*2;b.current={name:"Mosaic",type:B.Source,data:{size:E,tiles:[{x:N,y:R,color:be(N,R,m.current)}]},editHistory:[],draw:yt}},[y,f,n]),z=i.useCallback(g=>{if(!y||!b.current||!n.current||!m.current)return;const x=n.current.canvas.getBoundingClientRect(),N=g.clientX-x.x,R=g.clientY-x.y,E=b.current.data.size,w=b.current.data.tiles;let k=w[w.length-1];if(!k)w.push({x:N,y:R,color:be(N,R,m.current)});else{const V=k.x-N,D=k.y-R;let L=Math.sqrt(V**2+D**2);const _e=-D/L,ye=-V/L;for(;L>E;){const se=Math.floor(k.x+E*ye),re=Math.floor(k.y+E*_e);k={x:se,y:re,color:be(se,re,m.current)},w.push(k),L-=E}L>E/2&&w.push({x:N,y:R,color:be(N,R,m.current)})}u.top!==b.current?p.push(b.current):p.set(u)},[y,n,u,p]),d=i.useCallback(()=>{!y||(b.current=null)},[y]);return ee(C),te(z),ne(d),i.useEffect(()=>{if(!l||!t||!y)return;const g=document.createElement("canvas"),x=g.getContext("2d");if(!x)return;g.width=l.width,g.height=l.height;const N=t.naturalWidth/s,R=t.naturalHeight/o;x.drawImage(t,l.x*N,l.y*R,l.width*N,l.height*R,0,0,l.width,l.height),m.current=x.getImageData(0,0,l.width,l.height)},[s,o,l,t,y]),_.default.createElement(F,{title:e.operation_mosaic_title,icon:"icon-mosaic",checked:y,onClick:S,option:_.default.createElement(Xe,{value:f,onChange:a,__self:this,__source:{fileName:Ye,lineNumber:220,columnNumber:15}}),__self:this,__source:{fileName:Ye,lineNumber:215,columnNumber:5}})}var Fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsColor/index.tsx";function vt({value:e,onChange:t}){const s=["#ee5126","#fceb4d","#90e746","#51c0fa","#7a7a7a","#ffffff"];return _.default.createElement("div",{className:"screenshots-color",__self:this,__source:{fileName:Fe,lineNumber:12,columnNumber:5}},s.map(o=>{const c=["screenshots-color-item"];return o===e&&c.push("screenshots-color-active"),_.default.createElement("div",{key:o,className:c.join(" "),style:{backgroundColor:o},onClick:()=>t&&t(o),__self:this,__source:{fileName:Fe,lineNumber:19,columnNumber:11}})}))}var Se="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSizeColor/index.tsx";function ie({size:e,color:t,onSizeChange:s,onColorChange:o}){return _.default.createElement("div",{className:"screenshots-sizecolor",__self:this,__source:{fileName:Se,lineNumber:15,columnNumber:5}},_.default.createElement(Xe,{value:e,onChange:s,__self:this,__source:{fileName:Se,lineNumber:16,columnNumber:7}}),_.default.createElement(vt,{value:t,onChange:o,__self:this,__source:{fileName:Se,lineNumber:17,columnNumber:7}}))}const Nt=`
|
|
1
|
+
"use strict";var qe=Object.defineProperty,Je=Object.defineProperties;var Qe=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable;var De=(e,t,s)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,U=(e,t)=>{for(var s in t||(t={}))Ee.call(t,s)&&De(e,s,t[s]);if(he)for(var s of he(t))Be.call(t,s)&&De(e,s,t[s]);return e},me=(e,t)=>Je(e,Qe(t));var Me=(e,t)=>{var s={};for(var o in e)Ee.call(e,o)&&t.indexOf(o)<0&&(s[o]=e[o]);if(e!=null&&he)for(var o of he(e))t.indexOf(o)<0&&Be.call(e,o)&&(s[o]=e[o]);return s};var i=require("react"),$e=require("react-dom");function Ke(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var _=Ke(i);const Le={magnifier_position_label:"\u5750\u6807",operation_ok_title:"\u786E\u5B9A",operation_cancel_title:"\u53D6\u6D88",operation_save_title:"\u4FDD\u5B58",operation_redo_title:"\u91CD\u505A",operation_undo_title:"\u64A4\u9500",operation_mosaic_title:"\u9A6C\u8D5B\u514B",operation_text_title:"\u6587\u672C",operation_brush_title:"\u753B\u7B14",operation_arrow_title:"\u7BAD\u5934",operation_ellipse_title:"\u692D\u5706",operation_rectangle_title:"\u77E9\u5F62"};var xe=_.default.createContext({store:{url:void 0,image:null,width:0,height:0,lang:Le,emiterRef:{current:{}},canvasContextRef:{current:null},history:{index:-1,stack:[]},bounds:null,cursor:"move",operation:void 0},dispatcher:{call:void 0,setHistory:void 0,setBounds:void 0,setCursor:void 0,setOperation:void 0}});function oe(){const{dispatcher:e}=i.useContext(xe);return e}function H(){const{store:e}=i.useContext(xe);return e}function G(){const{bounds:e}=H(),{setBounds:t}=oe(),s=i.useCallback(c=>{t==null||t(c)},[t]),o=i.useCallback(()=>{t==null||t(null)},[t]);return[e,{set:s,reset:o}]}function X(){const{lang:e}=H();return e}var J="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsMagnifier/index.tsx";const Q=100,K=80;function Ze({x:e,y:t}){const{width:s,height:o,image:c}=H(),r=X(),[n,u]=i.useState(null),p=i.useRef(null),l=i.useRef(null),h=i.useRef(null),[a,f]=i.useState("000000");return i.useLayoutEffect(()=>{if(!p.current)return;const m=p.current.getBoundingClientRect();let g=e+20,y=t+20;g+m.width>s&&(g=e-m.width-20),y+m.height>o&&(y=t-m.height-20),g<0&&(g=0),y<0&&(y=0),u({x:g,y})},[s,o,e,t]),i.useEffect(()=>{if(!c||!l.current){h.current=null;return}if(h.current||(h.current=l.current.getContext("2d")),!h.current)return;const m=h.current;m.clearRect(0,0,Q,K);const g=c.naturalWidth/s,y=c.naturalHeight/o;m.drawImage(c,e*g-Q/2,t*y-K/2,Q,K,0,0,Q,K);const{data:v}=m.getImageData(Math.floor(Q/2),Math.floor(K/2),1,1),S=Array.from(v.slice(0,3)).map(C=>C>=16?C.toString(16):`0${C.toString(16)}`).join("").toUpperCase();f(S)},[s,o,c,e,t]),_.default.createElement("div",{ref:p,className:"screenshots-magnifier",style:{transform:`translate(${n==null?void 0:n.x}px, ${n==null?void 0:n.y}px)`},__self:this,__source:{fileName:J,lineNumber:89,columnNumber:5}},_.default.createElement("div",{className:"screenshots-magnifier-body",__self:this,__source:{fileName:J,lineNumber:96,columnNumber:7}},_.default.createElement("canvas",{ref:l,className:"screenshots-magnifier-body-canvas",width:Q,height:K,__self:this,__source:{fileName:J,lineNumber:97,columnNumber:9}})),_.default.createElement("div",{className:"screenshots-magnifier-footer",__self:this,__source:{fileName:J,lineNumber:104,columnNumber:7}},_.default.createElement("div",{className:"screenshots-magnifier-footer-item",__self:this,__source:{fileName:J,lineNumber:105,columnNumber:9}},r.magnifier_position_label,": (",e,",",t,")"),_.default.createElement("div",{className:"screenshots-magnifier-footer-item",__self:this,__source:{fileName:J,lineNumber:108,columnNumber:9}},"RGB: #",a)))}function et({x:e,y:t},{x:s,y:o},c,r){return e>s&&([e,s]=[s,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0),s>c&&(s=c),t<0&&(t=0),o>r&&(o=r),{x:e,y:t,width:s-e,height:o-t}}var de="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsBackground/index.tsx";function tt(){const{url:e,image:t,width:s,height:o}=H(),[c,r]=G(),n=i.useRef(null),u=i.useRef(null),p=i.useRef(!1),[l,h]=i.useState(null),a=i.useCallback((m,g)=>{if(!n.current)return;const{x:y,y:v}=n.current.getBoundingClientRect();r.set(et({x:m.x-y,y:m.y-v},{x:g.x-y,y:g.y-v},s,o))},[s,o,r]),f=i.useCallback(m=>{u.current||c||m.button!==0||(u.current={x:m.clientX,y:m.clientY},p.current=!1)},[c]);return i.useEffect(()=>{const m=y=>{if(n.current){const v=n.current.getBoundingClientRect();y.clientX<v.left||y.clientY<v.top||y.clientX>v.right||y.clientY>v.bottom?h(null):h({x:y.clientX-v.x,y:y.clientY-v.y})}!u.current||(a(u.current,{x:y.clientX,y:y.clientY}),p.current=!0)},g=y=>{!u.current||(p.current&&a(u.current,{x:y.clientX,y:y.clientY}),u.current=null,p.current=!1)};return window.addEventListener("mousemove",m),window.addEventListener("mouseup",g),()=>{window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",g)}},[a]),!e||!t?null:_.default.createElement("div",{ref:n,className:"screenshots-background",onMouseDown:f,__self:this,__source:{fileName:de,lineNumber:113,columnNumber:5}},_.default.createElement("img",{className:"screenshots-background-image",src:e,__self:this,__source:{fileName:de,lineNumber:114,columnNumber:7}}),_.default.createElement("div",{className:"screenshots-background-mask",__self:this,__source:{fileName:de,lineNumber:115,columnNumber:7}}),l&&!c&&_.default.createElement(Ze,{x:l==null?void 0:l.x,y:l==null?void 0:l.y,__self:this,__source:{fileName:de,lineNumber:116,columnNumber:31}}))}var Ve;const He=(Ve=window.devicePixelRatio)!=null?Ve:2;var pe=He<2?2:He;function nt(e,t,s,o){const c=e.clientX-s.x,r=e.clientY-s.y;let n=o.x,u=o.y,p=o.x+o.width,l=o.y+o.height;switch(t){case"top":u+=r;break;case"top-right":p+=c,u+=r;break;case"right":p+=c;break;case"right-bottom":p+=c,l+=r;break;case"bottom":l+=r;break;case"bottom-left":n+=c,l+=r;break;case"left":n+=c;break;case"left-top":n+=c,u+=r;break;case"move":n+=c,u+=r,p+=c,l+=r;break}return[{x:n,y:u},{x:p,y:l}]}function st({x:e,y:t},{x:s,y:o},c,r,n,u){return e>s&&([e,s]=[s,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0,u==="move"&&(s=c.width)),s>r&&(s=r,u==="move"&&(e=s-c.width)),t<0&&(t=0,u==="move"&&(o=c.height)),o>n&&(o=n,u==="move"&&(t=o-c.height)),{x:e,y:t,width:Math.max(s-e,1),height:Math.max(o-t,1)}}var B;(function(e){e[e.Edit=0]="Edit",e[e.Source=1]="Source"})(B||(B={}));function Z(){const{emiterRef:e}=H(),t=i.useCallback((r,n)=>{const u=e.current;Array.isArray(u[r])?u[r].push(n):u[r]=[n]},[e]),s=i.useCallback((r,n)=>{const u=e.current;if(Array.isArray(u[r])){const p=u[r].findIndex(l=>l===n);p!==-1&&u[r].splice(p,1)}},[e]),o=i.useCallback((r,...n)=>{const u=e.current;Array.isArray(u[r])&&u[r].forEach(p=>p(...n))},[e]),c=i.useCallback(()=>{e.current={}},[e]);return{on:t,off:s,emit:o,reset:c}}function Y(){const{history:e}=H(),{setHistory:t}=oe(),s=i.useCallback(h=>{const{index:a,stack:f}=e;f.forEach(m=>{m.type===B.Source&&(m.isSelected=!1)}),h.type===B.Source?h.isSelected=!0:h.type===B.Edit&&(h.source.isSelected=!0),f.splice(a+1),f.push(h),t==null||t({index:f.length-1,stack:f})},[e,t]),o=i.useCallback(()=>{const{stack:h}=e;h.pop(),t==null||t({index:h.length-1,stack:h})},[e,t]),c=i.useCallback(()=>{const{index:h,stack:a}=e,f=a[h];f&&(f.type===B.Source?f.isSelected=!1:f.type===B.Edit&&f.source.editHistory.pop()),t==null||t({index:h<=0?-1:h-1,stack:a})},[e,t]),r=i.useCallback(()=>{const{index:h,stack:a}=e,f=a[h+1];f&&(f.type===B.Source?f.isSelected=!1:f.type===B.Edit&&f.source.editHistory.push(f)),t==null||t({index:h>=a.length-1?a.length-1:h+1,stack:a})},[e,t]),n=i.useCallback(h=>{t==null||t(U({},h))},[t]),u=i.useCallback(h=>{e.stack.forEach(a=>{a.type===B.Source&&(a===h?a.isSelected=!0:a.isSelected=!1)}),t==null||t(U({},e))},[e,t]),p=i.useCallback(()=>{e.stack.forEach(h=>{h.type===B.Source&&(h.isSelected=!1)}),t==null||t(U({},e))},[e,t]),l=i.useCallback(()=>{t==null||t({index:-1,stack:[]})},[t]);return[{index:e.index,stack:e.stack,top:e.stack.slice(e.index,e.index+1)[0]},{push:s,pop:o,undo:c,redo:r,set:n,select:u,clearSelect:p,reset:l}]}function A(){const{cursor:e}=H(),{setCursor:t}=oe(),s=i.useCallback(c=>{t==null||t(c)},[t]),o=i.useCallback(()=>{t==null||t("move")},[t]);return[e,{set:s,reset:o}]}function I(){const{operation:e}=H(),{setOperation:t}=oe(),s=i.useCallback(c=>{t==null||t(c)},[t]),o=i.useCallback(()=>{t==null||t(void 0)},[t]);return[e,{set:s,reset:o}]}function rt(e,t,s,o){if(!t)return!1;const c=document.createElement("canvas");c.width=e.width,c.height=e.height;const r=c.getContext("2d");if(!r)return!1;const{left:n,top:u}=t.getBoundingClientRect(),p=o.clientX-n,l=o.clientY-u;return[...s.stack.slice(0,s.index+1)].reverse().find(a=>{var f;return a.type!==B.Source?!1:(r.clearRect(0,0,e.width,e.height),(f=a.isHit)==null?void 0:f.call(a,r,a,{x:p,y:l}))})}var ce="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsCanvas/index.tsx";const ot=["top","right","bottom","left"];var j;(function(e){e.ResizeTop="top",e.ResizetopRight="top-right",e.ResizeRight="right",e.ResizeRightBottom="right-bottom",e.ResizeBottom="bottom",e.ResizeBottomLeft="bottom-left",e.ResizeLeft="left",e.ResizeLeftTop="left-top",e.Move="move"})(j||(j={}));const ct=[j.ResizeTop,j.ResizetopRight,j.ResizeRight,j.ResizeRightBottom,j.ResizeBottom,j.ResizeBottomLeft,j.ResizeLeft,j.ResizeLeftTop];var it=i.forwardRef(function(t,s){const{image:o,width:c,height:r}=H(),n=Z(),[u]=Y(),[p]=A(),[l,h]=G(),[a]=I(),f=i.useRef(),m=i.useRef(null),g=i.useRef(null),y=i.useRef(null),v=i.useRef(null),S=i.useCallback(()=>{if(!o||!l||!v.current)return;const d=o.naturalWidth/c,b=o.naturalHeight/r,x=v.current;x.imageSmoothingEnabled=!0,x.imageSmoothingQuality="low",x.setTransform(pe,0,0,pe,0,0),x.clearRect(0,0,l.width,l.height),x.drawImage(o,l.x*d,l.y*b,l.width*d,l.height*b,0,0,l.width,l.height),u.stack.slice(0,u.index+1).forEach(N=>{N.type===B.Source&&N.draw(x,N)})},[o,c,r,l,v,u]),C=i.useCallback((d,b)=>{if(!(d.button!==0||!l))if(!a)f.current=b,m.current={x:d.clientX,y:d.clientY},g.current={x:l.x,y:l.y,width:l.width,height:l.height};else{const x=rt(l,y.current,u,d.nativeEvent);x?n.emit("drawselect",x,d.nativeEvent):n.emit("mousedown",d.nativeEvent)}},[l,a,n,u]),z=i.useCallback(d=>{if(!f.current||!m.current||!g.current||!l)return;const b=nt(d,f.current,m.current,g.current);h.set(st(b[0],b[1],l,c,r,f.current))},[c,r,l,h]);return i.useLayoutEffect(()=>{if(!o||!l||!y.current){v.current=null;return}v.current||(v.current=y.current.getContext("2d")),S()},[o,l,S]),i.useEffect(()=>{const d=x=>{if(a)n.emit("mousemove",x);else{if(!f.current||!m.current||!g.current)return;z(x)}},b=x=>{if(a)n.emit("mouseup",x);else{if(!f.current||!m.current||!g.current)return;z(x),f.current=void 0,m.current=null,g.current=null}};return window.addEventListener("mousemove",d),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",d),window.removeEventListener("mouseup",b)}},[z,a,n]),i.useImperativeHandle(s,()=>v.current),l?_.default.createElement("div",{className:"screenshots-canvas",style:{left:l.x,top:l.y,width:l.width,height:l.height},__self:this,__source:{fileName:ce,lineNumber:191,columnNumber:5}},_.default.createElement("canvas",{ref:y,width:l.width*pe,height:l.height*pe,style:{width:l.width,height:l.height},__self:this,__source:{fileName:ce,lineNumber:200,columnNumber:7}}),_.default.createElement("div",{className:"screenshots-canvas-body",style:{cursor:p},onMouseDown:d=>C(d,"move"),__self:this,__source:{fileName:ce,lineNumber:209,columnNumber:7}}),ot.map(d=>_.default.createElement("div",{key:d,className:`screenshots-canvas-border-${d}`,__self:this,__source:{fileName:ce,lineNumber:217,columnNumber:16}})),ct.map(d=>_.default.createElement("div",{key:d,className:`screenshots-canvas-point-${d}`,onMouseDown:b=>C(b,d),__self:this,__source:{fileName:ce,lineNumber:221,columnNumber:11}}))):null});function ve(){const e=oe();return i.useCallback((s,...o)=>{var c;(c=e.call)==null||c.call(e,s,...o)},[e])}function W(){const{canvasContextRef:e}=H();return e}function Ne(){const e=Z(),[,t]=G(),[,s]=A(),[,o]=Y(),[,c]=I();return i.useCallback(()=>{e.reset(),o.reset(),t.reset(),s.reset(),c.reset()},[e,o,t,s,c])}var Ce="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOption/index.tsx",q;(function(e){e.Bottom="bottom",e.Top="top"})(q||(q={}));function ut({open:e,content:t,children:s}){const o=i.useRef(null),c=i.useRef(null),r=i.useRef(null),n=i.useContext(Oe),[u,p]=i.useState(q.Bottom),[l,h]=i.useState(null),[a,f]=i.useState(0),m=()=>(c.current||(c.current=document.createElement("div")),c.current);return i.useEffect(()=>{const g=m();return e&&document.body.appendChild(g),()=>{g.remove()}},[e]),i.useEffect(()=>{if(!e||!n||!o.current||!r.current)return;const g=o.current.getBoundingClientRect(),y=r.current.getBoundingClientRect();let v=u,S=g.left+g.width/2,C=g.top+g.height,z=a;if(S+y.width/2>n.x+n.width){const d=S;S=n.x+n.width-y.width/2,z=d-S}if(S<n.x+y.width/2){const d=S;S=n.x+y.width/2,z=d-S}C>window.innerHeight-y.height&&(v===q.Bottom&&(v=q.Top),C=g.top-y.height),C<0&&(v===q.Top&&(v=q.Bottom),C=g.top+g.height),v!==u&&p(v),((l==null?void 0:l.x)!==S||l.y!==C)&&h({x:S,y:C}),z!==a&&f(z)}),_.default.createElement(_.default.Fragment,null,i.cloneElement(s,{ref:o}),e&&t&&$e.createPortal(_.default.createElement("div",{ref:r,className:"screenshots-option",style:{visibility:l?"visible":"hidden",left:l==null?void 0:l.x,top:l==null?void 0:l.y},"data-placement":u,__self:this,__source:{fileName:Ce,lineNumber:111,columnNumber:11}},_.default.createElement("div",{className:"screenshots-option-container",__self:this,__source:{fileName:Ce,lineNumber:121,columnNumber:13}},t),_.default.createElement("div",{className:"screenshots-option-arrow",style:{marginLeft:a},__self:this,__source:{fileName:Ce,lineNumber:122,columnNumber:13}})),m()))}var Re="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsButton/index.tsx";function F({title:e,icon:t,checked:s,disabled:o,option:c,onClick:r}){const n=["screenshots-button"],u=i.useCallback(p=>{o||!r||r(p)},[o,r]);return s&&n.push("screenshots-button-checked"),o&&n.push("screenshots-button-disabled"),_.default.createElement(ut,{open:s,content:c,__self:this,__source:{fileName:Re,lineNumber:42,columnNumber:5}},_.default.createElement("div",{className:n.join(" "),title:e,onClick:u,__self:this,__source:{fileName:Re,lineNumber:43,columnNumber:7}},_.default.createElement("span",{className:t,__self:this,__source:{fileName:Re,lineNumber:44,columnNumber:9}})))}var lt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ok/index.tsx";function at(){const e=X(),t=W(),[,s]=Y(),o=ve(),[c]=G(),r=Ne(),n=i.useCallback(()=>{s.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(u=>{o("onOk",u,c),r()},"image/png")})},[t,s,o,c,r]);return _.default.createElement(F,{title:e.operation_ok_title,icon:"icon-ok",onClick:n,__self:this,__source:{fileName:lt,lineNumber:31,columnNumber:10}})}var ft="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Cancel/index.tsx";function ht(){const e=ve(),t=Ne(),s=X(),o=i.useCallback(()=>{e("onCancel"),t()},[e,t]);return _.default.createElement(F,{title:s.operation_cancel_title,icon:"icon-cancel",onClick:o,__self:this,__source:{fileName:ft,lineNumber:17,columnNumber:10}})}var mt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Save/index.tsx";function dt(){const e=X(),t=W(),[,s]=Y(),[o]=G(),c=ve(),r=Ne(),n=i.useCallback(()=>{s.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(u=>{c("onSave",u,o),r()},"image/png")})},[t,s,o,c,r]);return _.default.createElement(F,{title:e.operation_save_title,icon:"icon-save",onClick:n,__self:this,__source:{fileName:mt,lineNumber:31,columnNumber:10}})}var pt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Redo/index.tsx";function bt(){const e=X(),[t,s]=Y(),o=i.useCallback(()=>{s.redo()},[s]);return _.default.createElement(F,{title:e.operation_redo_title,icon:"icon-redo",disabled:!t.stack.length||t.stack.length-1===t.index,onClick:o,__self:this,__source:{fileName:pt,lineNumber:15,columnNumber:5}})}var gt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Undo/index.tsx";function _t(){const e=X(),[t,s]=Y(),o=i.useCallback(()=>{s.undo()},[s]);return _.default.createElement(F,{title:e.operation_undo_title,icon:"icon-undo",disabled:t.index===-1,onClick:o,__self:this,__source:{fileName:gt,lineNumber:15,columnNumber:5}})}var ke="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSize/index.tsx";function Xe({value:e,onChange:t}){const s=[3,6,9];return _.default.createElement("div",{className:"screenshots-size",__self:this,__source:{fileName:ke,lineNumber:12,columnNumber:5}},s.map(o=>{const c=["screenshots-size-item"];return o===e&&c.push("screenshots-size-active"),_.default.createElement("div",{key:o,className:c.join(" "),onClick:()=>t&&t(o),__self:this,__source:{fileName:ke,lineNumber:21,columnNumber:11}},_.default.createElement("div",{className:"screenshots-size-pointer",style:{width:o*1.8,height:o*1.8},__self:this,__source:{fileName:ke,lineNumber:22,columnNumber:13}}))}))}function ee(e){const t=Z();i.useEffect(()=>(t.on("mousedown",e),()=>{t.off("mousedown",e)}),[e,t])}function te(e){const t=Z();i.useEffect(()=>(t.on("mousemove",e),()=>{t.off("mousemove",e)}),[e,t])}function ne(e){const t=Z();i.useEffect(()=>(t.on("mouseup",e),()=>{t.off("mouseup",e)}),[e,t])}var Ye="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Mosaic/index.tsx";function be(e,t,s){if(!s)return[0,0,0,0];const{data:o,width:c}=s,r=t*c*4+e*4;return Array.from(o.slice(r,r+4))}function yt(e,t){const{tiles:s,size:o}=t.data;s.forEach(c=>{const r=Math.round(c.color[0]),n=Math.round(c.color[1]),u=Math.round(c.color[2]),p=c.color[3]/255;e.fillStyle=`rgba(${r}, ${n}, ${u}, ${p})`,e.fillRect(c.x-o/2,c.y-o/2,o,o)})}function xt(){const e=X(),{image:t,width:s,height:o}=H(),[c,r]=I(),n=W(),[u,p]=Y(),[l]=G(),[,h]=A(),[a,f]=i.useState(3),m=i.useRef(null),g=i.useRef(null),y=c==="Mosaic",v=i.useCallback(()=>{r.set("Mosaic"),h.set("crosshair")},[r,h]),S=i.useCallback(()=>{y||(v(),p.clearSelect())},[y,v,p]),C=i.useCallback(b=>{if(!y||g.current||!m.current||!n.current)return;const x=n.current.canvas.getBoundingClientRect(),N=b.clientX-x.x,k=b.clientY-x.y,E=a*2;g.current={name:"Mosaic",type:B.Source,data:{size:E,tiles:[{x:N,y:k,color:be(N,k,m.current)}]},editHistory:[],draw:yt}},[y,a,n]),z=i.useCallback(b=>{if(!y||!g.current||!n.current||!m.current)return;const x=n.current.canvas.getBoundingClientRect(),N=b.clientX-x.x,k=b.clientY-x.y,E=g.current.data.size,w=g.current.data.tiles;let R=w[w.length-1];if(!R)w.push({x:N,y:k,color:be(N,k,m.current)});else{const V=R.x-N,D=R.y-k;let L=Math.sqrt(V**2+D**2);const _e=-D/L,ye=-V/L;for(;L>E;){const se=Math.floor(R.x+E*ye),re=Math.floor(R.y+E*_e);R={x:se,y:re,color:be(se,re,m.current)},w.push(R),L-=E}L>E/2&&w.push({x:N,y:k,color:be(N,k,m.current)})}u.top!==g.current?p.push(g.current):p.set(u)},[y,n,u,p]),d=i.useCallback(()=>{!y||(g.current=null)},[y]);return ee(C),te(z),ne(d),i.useEffect(()=>{if(!l||!t||!y)return;const b=document.createElement("canvas"),x=b.getContext("2d");if(!x)return;b.width=l.width,b.height=l.height;const N=t.naturalWidth/s,k=t.naturalHeight/o;x.drawImage(t,l.x*N,l.y*k,l.width*N,l.height*k,0,0,l.width,l.height),m.current=x.getImageData(0,0,l.width,l.height)},[s,o,l,t,y]),_.default.createElement(F,{title:e.operation_mosaic_title,icon:"icon-mosaic",checked:y,onClick:S,option:_.default.createElement(Xe,{value:a,onChange:f,__self:this,__source:{fileName:Ye,lineNumber:220,columnNumber:15}}),__self:this,__source:{fileName:Ye,lineNumber:215,columnNumber:5}})}var Fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsColor/index.tsx";function vt({value:e,onChange:t}){const s=["#ee5126","#fceb4d","#90e746","#51c0fa","#7a7a7a","#ffffff"];return _.default.createElement("div",{className:"screenshots-color",__self:this,__source:{fileName:Fe,lineNumber:12,columnNumber:5}},s.map(o=>{const c=["screenshots-color-item"];return o===e&&c.push("screenshots-color-active"),_.default.createElement("div",{key:o,className:c.join(" "),style:{backgroundColor:o},onClick:()=>t&&t(o),__self:this,__source:{fileName:Fe,lineNumber:19,columnNumber:11}})}))}var Se="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSizeColor/index.tsx";function ie({size:e,color:t,onSizeChange:s,onColorChange:o}){return _.default.createElement("div",{className:"screenshots-sizecolor",__self:this,__source:{fileName:Se,lineNumber:15,columnNumber:5}},_.default.createElement(Xe,{value:e,onChange:s,__self:this,__source:{fileName:Se,lineNumber:16,columnNumber:7}}),_.default.createElement(vt,{value:t,onChange:o,__self:this,__source:{fileName:Se,lineNumber:17,columnNumber:7}}))}const Nt=`
|
|
2
2
|
min-width: 0 !important;
|
|
3
3
|
width: 0 !important;
|
|
4
4
|
min-height: 0 !important;
|
|
@@ -9,6 +9,6 @@ position: absolute !important;
|
|
|
9
9
|
z-index: -1000 !important;
|
|
10
10
|
top:0 !important;
|
|
11
11
|
right:0 !important;
|
|
12
|
-
`,Ct=["letter-spacing","line-height","padding-top","padding-bottom","font-family","font-weight","font-size","font-variant","text-rendering","text-transform","text-indent","padding-left","padding-right","border-width","box-sizing","white-space","word-break"];let O;function
|
|
12
|
+
`,Ct=["letter-spacing","line-height","padding-top","padding-bottom","font-family","font-weight","font-size","font-variant","text-rendering","text-transform","text-indent","padding-left","padding-right","border-width","box-sizing","white-space","word-break"];let O;function Rt(e){const t=window.getComputedStyle(e),s=t.getPropertyValue("box-sizing")||t.getPropertyValue("-moz-box-sizing")||t.getPropertyValue("-webkit-box-sizing"),o=parseFloat(t.getPropertyValue("padding-bottom"))+parseFloat(t.getPropertyValue("padding-top")),c=parseFloat(t.getPropertyValue("border-bottom-width"))+parseFloat(t.getPropertyValue("border-top-width"));return{sizingStyle:Ct.map(n=>`${n}:${t.getPropertyValue(n)}`).join(";"),paddingSize:o,borderSize:c,boxSizing:s}}function kt(e,t,s,o){O||(O=document.createElement("textarea"),O.setAttribute("tab-index","-1"),document.body.appendChild(O));const{paddingSize:c,borderSize:r,boxSizing:n,sizingStyle:u}=Rt(e);O.setAttribute("style",`${u};${Nt};max-width:${s}px;max-height:${o}px`),O.value=t||" ";let p=O.scrollWidth,l=O.scrollHeight;return n==="border-box"?(p+=r,l+=r):n==="content-box"&&(p-=c,l-=c),{width:Math.min(p,s),height:Math.min(l,o)}}var St="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsTextarea/index.tsx";function wt({x:e,y:t,maxWidth:s,maxHeight:o,size:c,color:r,value:n,onChange:u,onBlur:p}){const l=i.useRef(null),h=i.useRef(null),[a,f]=i.useState(0),[m,g]=i.useState(0),y=()=>(l.current||(l.current=document.createElement("div")),l.current);return i.useLayoutEffect(()=>(l.current&&(document.body.appendChild(l.current),requestAnimationFrame(()=>{var v;(v=h.current)==null||v.focus()})),()=>{var v;(v=l.current)==null||v.remove()}),[]),i.useLayoutEffect(()=>{if(!h.current)return;const{width:v,height:S}=kt(h.current,n,s,o);f(v),g(S)},[n,s,o]),$e.createPortal(_.default.createElement("textarea",{ref:h,className:"screenshots-textarea",style:{left:e,top:t,color:r,width:a,height:m,maxWidth:s,maxHeight:o,fontSize:c,lineHeight:`${c}px`},value:n,onChange:v=>u&&u(v.target.value),onBlur:v=>p&&p(v),__self:this,__source:{fileName:St,lineNumber:65,columnNumber:5}}),y())}function ue(e){const t=Z();i.useEffect(()=>(t.on("drawselect",e),()=>{t.off("drawselect",e)}),[e,t])}var we="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Text/index.tsx";const ze={3:18,6:32,9:46};function zt(e,t){const{size:s,color:o,fontFamily:c,x:r,y:n,text:u}=t.data;e.fillStyle=o,e.textAlign="left",e.textBaseline="top",e.font=`${s}px ${c}`;const p=t.editHistory.reduce((l,{data:h})=>({x:l.x+h.x2-h.x1,y:l.y+h.y2-h.y1}),{x:0,y:0});u.split(`
|
|
13
13
|
`).forEach((l,h)=>{e.fillText(l,r+p.x,n+p.y+h*s)})}function Et(e,t,s){e.textAlign="left",e.textBaseline="top",e.font=`${t.data.size}px ${t.data.fontFamily}`;let o=0,c=0;t.data.text.split(`
|
|
14
|
-
`).forEach(f=>{const a=e.measureText(f);o<a.width&&(o=a.width),c+=t.data.size});const{x:r,y:n}=t.editHistory.reduce((f,{data:a})=>({x:f.x+a.x2-a.x1,y:f.y+a.y2-a.y1}),{x:0,y:0}),u=t.data.x+r,p=t.data.y+n,l=u+o,h=p+c;return s.x>=u&&s.x<=l&&s.y>=p&&s.y<=h}function Bt(){const e=X(),[t,s]=Y(),[o]=G(),[c,r]=I(),[,n]=A(),u=W(),[p,l]=i.useState(3),[h,f]=i.useState("#ee5126"),a=i.useRef(null),m=i.useRef(null),[b,y]=i.useState(null),[v,S]=i.useState(""),C=c==="Text",z=i.useCallback(()=>{r.set("Text"),n.set("default")},[r,n]),d=i.useCallback(()=>{C||(z(),s.clearSelect())},[C,z,s]),g=i.useCallback(D=>{a.current&&(a.current.data.size=ze[D]),l(D)},[]),x=i.useCallback(D=>{a.current&&(a.current.data.color=D),f(D)},[]),N=i.useCallback(D=>{S(D),C&&a.current&&(a.current.data.text=D)},[C]),R=i.useCallback(()=>{a.current&&a.current.data.text&&s.push(a.current),a.current=null,S(""),y(null)},[s]),E=i.useCallback((D,L)=>{D.name==="Text"&&(z(),m.current={type:B.Edit,data:{x1:L.clientX,y1:L.clientY,x2:L.clientX,y2:L.clientY},source:D},s.select(D))},[z,s]),w=i.useCallback(D=>{if(!C||!u.current||a.current||!o)return;const{left:L,top:_e}=u.current.canvas.getBoundingClientRect(),ye=window.getComputedStyle(u.current.canvas).fontFamily,se=D.clientX-L,re=D.clientY-_e;a.current={name:"Text",type:B.Source,data:{size:ze[p],color:h,fontFamily:ye,x:se,y:re,text:""},editHistory:[],draw:zt,isHit:Et},y({x:D.clientX,y:D.clientY,maxWidth:o.width-se,maxHeight:o.height-re})},[C,p,h,o,u]),k=i.useCallback(D=>{!C||m.current&&(m.current.data.x2=D.clientX,m.current.data.y2=D.clientY,t.top!==m.current?(m.current.source.editHistory.push(m.current),s.push(m.current)):s.set(t))},[C,t,s]),V=i.useCallback(()=>{!C||(m.current=null)},[C]);return ue(E),ee(w),te(k),ne(V),_.default.createElement(_.default.Fragment,null,_.default.createElement(F,{title:e.operation_text_title,icon:"icon-text",checked:C,onClick:d,option:_.default.createElement(ie,{size:p,color:h,onSizeChange:g,onColorChange:x,__self:this,__source:{fileName:we,lineNumber:261,columnNumber:11}}),__self:this,__source:{fileName:we,lineNumber:255,columnNumber:7}}),C&&b&&_.default.createElement(wt,{x:b.x,y:b.y,maxWidth:b.maxWidth,maxHeight:b.maxHeight,size:ze[p],color:h,value:v,onChange:N,onBlur:R,__self:this,__source:{fileName:we,lineNumber:265,columnNumber:9}}))}const Pe=4;function M(e,t,s){e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.arc(t,s,Pe,0,2*Math.PI),e.fill(),e.stroke()}function ge(e,t,s){t.draw(e,t);const{data:o}=e.getImageData(s.x,s.y,1,1);return o.some(c=>c!==0)}function $(e,t,s){if(!e)return!1;const{left:o,top:c}=e.getBoundingClientRect(),r=t.clientX-o,n=t.clientY-c;return(s.x-r)**2+(s.y-n)**2<Pe**2}function Dt(e,t){const{size:s,color:o,points:c}=t.data;e.lineCap="round",e.lineJoin="round",e.lineWidth=s,e.strokeStyle=o;const r=t.editHistory.reduce((n,{data:u})=>({x:n.x+u.x2-u.x1,y:n.y+u.y2-u.y1}),{x:0,y:0});e.beginPath(),c.forEach((n,u)=>{u===0?e.moveTo(n.x+r.x,n.y+r.y):e.lineTo(n.x+r.x,n.y+r.y)}),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.beginPath(),c.forEach((n,u)=>{u===0?e.moveTo(n.x+r.x,n.y+r.y):e.lineTo(n.x+r.x,n.y+r.y)}),e.stroke())}var Te="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Brush/index.tsx";function Mt(){const e=X(),[,t]=A(),[s,o]=I(),c=W(),[r,n]=Y(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),f=i.useRef(null),a=i.useRef(null),m=s==="Brush",b=i.useCallback(()=>{o.set("Brush"),t.set("default")},[o,t]),y=i.useCallback(()=>{m||(b(),n.clearSelect())},[m,b,n]),v=i.useCallback((d,g)=>{d.name==="Brush"&&(b(),a.current={type:B.Edit,data:{x1:g.clientX,y1:g.clientY,x2:g.clientX,y2:g.clientY},source:d},n.select(d))},[b,n]),S=i.useCallback(d=>{if(!m||f.current||!c.current)return;const{left:g,top:x}=c.current.canvas.getBoundingClientRect();f.current={name:"Brush",type:B.Source,data:{size:u,color:l,points:[{x:d.clientX-g,y:d.clientY-x}]},editHistory:[],draw:Dt,isHit:ge}},[m,c,u,l]),C=i.useCallback(d=>{if(!(!m||!c.current)){if(a.current)a.current.data.x2=d.clientX,a.current.data.y2=d.clientY,r.top!==a.current?(a.current.source.editHistory.push(a.current),n.push(a.current)):n.set(r);else if(f.current){const{left:g,top:x}=c.current.canvas.getBoundingClientRect();f.current.data.points.push({x:d.clientX-g,y:d.clientY-x}),r.top!==f.current?n.push(f.current):n.set(r)}}},[m,r,c,n]),z=i.useCallback(()=>{!m||(f.current&&n.clearSelect(),f.current=null,a.current=null)},[m,n]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_brush_title,icon:"icon-brush",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:Te,lineNumber:166,columnNumber:15}}),__self:this,__source:{fileName:Te,lineNumber:161,columnNumber:5}})}function je(e){let{x1:t,y1:s,x2:o,y2:c}=e.data;return e.editHistory.forEach(({data:r})=>{const n=r.x2-r.x1,u=r.y2-r.y1;r.type===le.Move?(t+=n,s+=u,o+=n,c+=u):r.type===le.MoveStart?(t+=n,s+=u):r.type===le.MoveEnd&&(o+=n,c+=u)}),me(U({},e.data),{x1:t,x2:o,y1:s,y2:c})}function $t(e,t){const{size:s,color:o,x1:c,x2:r,y1:n,y2:u}=je(t);e.lineCap="round",e.lineJoin="bevel",e.lineWidth=s,e.strokeStyle=o;const p=r-c,l=u-n,h=s*3,f=Math.atan2(l,p);e.beginPath(),e.moveTo(c,n),e.lineTo(r,u),e.lineTo(r-h*Math.cos(f-Math.PI/6),u-h*Math.sin(f-Math.PI/6)),e.moveTo(r,u),e.lineTo(r-h*Math.cos(f+Math.PI/6),u-h*Math.sin(f+Math.PI/6)),e.stroke(),t.isSelected&&(M(e,c,n),M(e,r,u))}var Ue="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Arrow/index.tsx",le;(function(e){e[e.Move=0]="Move",e[e.MoveStart=1]="MoveStart",e[e.MoveEnd=2]="MoveEnd"})(le||(le={}));function Lt(){const e=X(),[,t]=A(),[s,o]=I(),[c,r]=Y(),n=W(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),f=i.useRef(null),a=i.useRef(null),m=s==="Arrow",b=i.useCallback(()=>{o.set("Arrow"),t.set("default")},[o,t]),y=i.useCallback(()=>{m||(b(),r.clearSelect())},[m,b,r]),v=i.useCallback((d,g)=>{if(d.name!=="Arrow"||!n.current)return;const x=d;b();const{x1:N,y1:R,x2:E,y2:w}=je(x);let k=0;$(n.current.canvas,g,{x:N,y:R})?k=1:$(n.current.canvas,g,{x:E,y:w})&&(k=2),a.current={type:B.Edit,data:{type:k,x1:g.clientX,y1:g.clientY,x2:g.clientX,y2:g.clientY},source:x},r.select(d)},[n,b,r]),S=i.useCallback(d=>{if(!m||f.current||!n.current)return;const{left:g,top:x}=n.current.canvas.getBoundingClientRect();f.current={name:"Arrow",type:B.Source,data:{size:u,color:l,x1:d.clientX-g,y1:d.clientY-x,x2:d.clientX-g,y2:d.clientY-x},editHistory:[],draw:$t,isHit:ge}},[m,l,u,n]),C=i.useCallback(d=>{if(!(!m||!n.current)){if(a.current)a.current.data.x2=d.clientX,a.current.data.y2=d.clientY,c.top!==a.current?(a.current.source.editHistory.push(a.current),r.push(a.current)):r.set(c);else if(f.current){const{left:g,top:x}=n.current.canvas.getBoundingClientRect();f.current.data.x2=d.clientX-g,f.current.data.y2=d.clientY-x,c.top!==f.current?r.push(f.current):r.set(c)}}},[m,c,n,r]),z=i.useCallback(()=>{!m||(f.current&&r.clearSelect(),f.current=null,a.current=null)},[m,r]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_arrow_title,icon:"icon-arrow",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:Ue,lineNumber:190,columnNumber:15}}),__self:this,__source:{fileName:Ue,lineNumber:185,columnNumber:5}})}function Ge(e){let{x1:t,y1:s,x2:o,y2:c}=e.data;return e.editHistory.forEach(({data:r})=>{const n=r.x2-r.x1,u=r.y2-r.y1;r.type===P.Move?(t+=n,s+=u,o+=n,c+=u):r.type===P.ResizeTop?s+=u:r.type===P.ResizeRightTop?(o+=n,s+=u):r.type===P.ResizeRight?o+=n:r.type===P.ResizeRightBottom?(o+=n,c+=u):r.type===P.ResizeBottom?c+=u:r.type===P.ResizeLeftBottom?(t+=n,c+=u):r.type===P.ResizeLeft?t+=n:r.type===P.ResizeLeftTop&&(t+=n,s+=u)}),me(U({},e.data),{x1:t,x2:o,y1:s,y2:c})}function Ht(e,t){const{size:s,color:o,x1:c,y1:r,x2:n,y2:u}=Ge(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=s,e.strokeStyle=o;const p=(c+n)/2,l=(r+u)/2,h=Math.abs(n-c)/2,f=Math.abs(u-r)/2,a=.5522848,m=h*a,b=f*a;e.beginPath(),e.moveTo(p-h,l),e.bezierCurveTo(p-h,l-b,p-m,l-f,p,l-f),e.bezierCurveTo(p+m,l-f,p+h,l-b,p+h,l),e.bezierCurveTo(p+h,l+b,p+m,l+f,p,l+f),e.bezierCurveTo(p-m,l+f,p-h,l+b,p-h,l),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.moveTo(c,r),e.lineTo(n,r),e.lineTo(n,u),e.lineTo(c,u),e.closePath(),e.stroke(),M(e,(c+n)/2,r),M(e,n,r),M(e,n,(r+u)/2),M(e,n,u),M(e,(c+n)/2,u),M(e,c,u),M(e,c,(r+u)/2),M(e,c,r))}var Ae="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ellipse/index.tsx",P;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(P||(P={}));function Xt(){const e=X(),[t,s]=Y(),[o,c]=I(),[,r]=A(),n=W(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),f=i.useRef(null),a=i.useRef(null),m=o==="Ellipse",b=i.useCallback(()=>{c.set("Ellipse"),r.set("crosshair")},[c,r]),y=i.useCallback(()=>{m||(b(),s.clearSelect())},[m,b,s]),v=i.useCallback((d,g)=>{if(d.name!=="Ellipse"||!n.current)return;const x=d;b();const{x1:N,y1:R,x2:E,y2:w}=Ge(x);let k=0;$(n.current.canvas,g,{x:(N+E)/2,y:R})?k=1:$(n.current.canvas,g,{x:E,y:R})?k=2:$(n.current.canvas,g,{x:E,y:(R+w)/2})?k=3:$(n.current.canvas,g,{x:E,y:w})?k=4:$(n.current.canvas,g,{x:(N+E)/2,y:w})?k=5:$(n.current.canvas,g,{x:N,y:w})?k=6:$(n.current.canvas,g,{x:N,y:(R+w)/2})?k=7:$(n.current.canvas,g,{x:N,y:R})&&(k=8),a.current={type:B.Edit,data:{type:k,x1:g.clientX,y1:g.clientY,x2:g.clientX,y2:g.clientY},source:x},s.select(d)},[n,b,s]),S=i.useCallback(d=>{if(!m||!n.current||f.current)return;const{left:g,top:x}=n.current.canvas.getBoundingClientRect(),N=d.clientX-g,R=d.clientY-x;f.current={name:"Ellipse",type:B.Source,data:{size:u,color:l,x1:N,y1:R,x2:N,y2:R},editHistory:[],draw:Ht,isHit:ge}},[m,u,l,n]),C=i.useCallback(d=>{if(!(!m||!n.current)){if(a.current)a.current.data.x2=d.clientX,a.current.data.y2=d.clientY,t.top!==a.current?(a.current.source.editHistory.push(a.current),s.push(a.current)):s.set(t);else if(f.current){const{left:g,top:x}=n.current.canvas.getBoundingClientRect();f.current.data.x2=d.clientX-g,f.current.data.y2=d.clientY-x,t.top!==f.current?s.push(f.current):s.set(t)}}},[m,n,t,s]),z=i.useCallback(()=>{!m||(f.current&&s.clearSelect(),f.current=null,a.current=null)},[m,s]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_ellipse_title,icon:"icon-ellipse",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:Ae,lineNumber:242,columnNumber:15}}),__self:this,__source:{fileName:Ae,lineNumber:237,columnNumber:5}})}function Ie(e){let{x1:t,y1:s,x2:o,y2:c}=e.data;return e.editHistory.forEach(({data:r})=>{const n=r.x2-r.x1,u=r.y2-r.y1;r.type===T.Move?(t+=n,s+=u,o+=n,c+=u):r.type===T.ResizeTop?s+=u:r.type===T.ResizeRightTop?(o+=n,s+=u):r.type===T.ResizeRight?o+=n:r.type===T.ResizeRightBottom?(o+=n,c+=u):r.type===T.ResizeBottom?c+=u:r.type===T.ResizeLeftBottom?(t+=n,c+=u):r.type===T.ResizeLeft?t+=n:r.type===T.ResizeLeftTop&&(t+=n,s+=u)}),me(U({},e.data),{x1:t,x2:o,y1:s,y2:c})}function Yt(e,t){const{size:s,color:o,x1:c,y1:r,x2:n,y2:u}=Ie(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=s,e.strokeStyle=o,e.beginPath(),e.moveTo(c,r),e.lineTo(n,r),e.lineTo(n,u),e.lineTo(c,u),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",M(e,(c+n)/2,r),M(e,n,r),M(e,n,(r+u)/2),M(e,n,u),M(e,(c+n)/2,u),M(e,c,u),M(e,c,(r+u)/2),M(e,c,r))}var We="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Rectangle/index.tsx",T;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(T||(T={}));function Ft(){const e=X(),[t,s]=Y(),[o,c]=I(),[,r]=A(),n=W(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),f=i.useRef(null),a=i.useRef(null),m=o==="Rectangle",b=i.useCallback(()=>{c.set("Rectangle"),r.set("crosshair")},[c,r]),y=i.useCallback(()=>{m||(b(),s.clearSelect())},[m,b,s]),v=i.useCallback((d,g)=>{if(d.name!=="Rectangle"||!n.current)return;const x=d;b();const{x1:N,y1:R,x2:E,y2:w}=Ie(x);let k=0;$(n.current.canvas,g,{x:(N+E)/2,y:R})?k=1:$(n.current.canvas,g,{x:E,y:R})?k=2:$(n.current.canvas,g,{x:E,y:(R+w)/2})?k=3:$(n.current.canvas,g,{x:E,y:w})?k=4:$(n.current.canvas,g,{x:(N+E)/2,y:w})?k=5:$(n.current.canvas,g,{x:N,y:w})?k=6:$(n.current.canvas,g,{x:N,y:(R+w)/2})?k=7:$(n.current.canvas,g,{x:N,y:R})&&(k=8),a.current={type:B.Edit,data:{type:k,x1:g.clientX,y1:g.clientY,x2:g.clientX,y2:g.clientY},source:d},s.select(d)},[n,b,s]),S=i.useCallback(d=>{if(!m||!n.current||f.current)return;const{left:g,top:x}=n.current.canvas.getBoundingClientRect(),N=d.clientX-g,R=d.clientY-x;f.current={name:"Rectangle",type:B.Source,data:{size:u,color:l,x1:N,y1:R,x2:N,y2:R},editHistory:[],draw:Yt,isHit:ge}},[m,u,l,n]),C=i.useCallback(d=>{if(!(!m||!n.current)){if(a.current)a.current.data.x2=d.clientX,a.current.data.y2=d.clientY,t.top!==a.current?(a.current.source.editHistory.push(a.current),s.push(a.current)):s.set(t);else if(f.current){const{left:g,top:x}=n.current.canvas.getBoundingClientRect(),N=f.current.data;N.x2=d.clientX-g,N.y2=d.clientY-x,t.top!==f.current?s.push(f.current):s.set(t)}}},[m,n,t,s]),z=i.useCallback(()=>{!m||(f.current&&s.clearSelect(),f.current=null,a.current=null)},[m,s]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_rectangle_title,icon:"icon-rectangle",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:We,lineNumber:242,columnNumber:15}}),__self:this,__source:{fileName:We,lineNumber:237,columnNumber:5}})}var Pt=[Ft,Xt,Lt,Mt,Bt,xt,"|",_t,bt,"|",dt,ht,at];var ae="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOperations/index.tsx";const Oe=_.default.createContext(null);function Tt(){const{width:e,height:t}=H(),[s]=G(),[o,c]=i.useState(null),[r,n]=i.useState(null),u=i.useRef(null),p=i.useCallback(h=>{h.stopPropagation()},[]),l=i.useCallback(h=>{h.preventDefault(),h.stopPropagation()},[]);return i.useEffect(()=>{if(!s||!u.current)return;const h=u.current.getBoundingClientRect();let f=s.x+s.width-h.width,a=s.y+s.height+10;f<0&&(f=0),f>e-h.width&&(f=e-h.width),a>t-h.height&&(a=t-h.height-10),((r==null?void 0:r.x)!==f||r.y!==a)&&n({x:f,y:a}),((o==null?void 0:o.x)!==h.x||o.y!==h.y||o.width!==h.width||o.height!==h.height)&&c({x:h.x,y:h.y,width:h.width,height:h.height})}),s?_.default.createElement(Oe.Provider,{value:o,__self:this,__source:{fileName:ae,lineNumber:76,columnNumber:5}},_.default.createElement("div",{ref:u,className:"screenshots-operations",style:{visibility:r?"visible":"hidden",left:r==null?void 0:r.x,top:r==null?void 0:r.y},onDoubleClick:p,onContextMenu:l,__self:this,__source:{fileName:ae,lineNumber:77,columnNumber:7}},_.default.createElement("div",{className:"screenshots-operations-buttons",__self:this,__source:{fileName:ae,lineNumber:88,columnNumber:9}},Pt.map((h,f)=>h==="|"?_.default.createElement("div",{key:f,className:"screenshots-operations-divider",__self:this,__source:{fileName:ae,lineNumber:91,columnNumber:22}}):_.default.createElement(h,{key:f,__self:this,__source:{fileName:ae,lineNumber:93,columnNumber:22}}))))):null}function jt(e){const[t,s]=i.useState(null);return i.useEffect(()=>{if(s(null),e==null)return;const o=document.createElement("img"),c=()=>s(o),r=()=>s(null);return o.addEventListener("load",c),o.addEventListener("error",r),o.src=e,()=>{o.removeEventListener("load",c),o.removeEventListener("error",r)}},[e]),t}var fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/index.tsx";function Ut(n){var u=n,{url:e,width:t,height:s,lang:o,className:c}=u,r=Me(u,["url","width","height","lang","className"]);const p=jt(e),l=i.useRef(null),h=i.useRef({}),[f,a]=i.useState({index:-1,stack:[]}),[m,b]=i.useState(null),[y,v]=i.useState("move"),[S,C]=i.useState(void 0),z={url:e,width:t,height:s,image:p,lang:U(U({},Le),o),emiterRef:h,canvasContextRef:l,history:f,bounds:m,cursor:y,operation:S},d=i.useCallback((w,...k)=>{const V=r[w];typeof V=="function"&&V(...k)},[r]),g={call:d,setHistory:a,setBounds:b,setCursor:v,setOperation:C},x=["screenshots"];c&&x.push(c);const N=()=>{h.current={},a({index:-1,stack:[]}),b(null),v("move"),C(void 0)},R=i.useCallback(w=>{w.button!==0||!m||!l.current||l.current.canvas.toBlob(k=>{d("onOk",k,m),N()},"image/png")},[m,d]),E=i.useCallback(w=>{w.button===2&&(w.preventDefault(),d("onCancel"),N())},[d]);return i.useLayoutEffect(()=>{N()},[e]),_.default.createElement(xe.Provider,{value:{store:z,dispatcher:g},__self:this,__source:{fileName:fe,lineNumber:116,columnNumber:5}},_.default.createElement("div",{className:x.join(" "),style:{width:t,height:s},onDoubleClick:R,onContextMenu:E,__self:this,__source:{fileName:fe,lineNumber:117,columnNumber:7}},_.default.createElement(tt,{__self:this,__source:{fileName:fe,lineNumber:123,columnNumber:9}}),_.default.createElement(it,{ref:l,__self:this,__source:{fileName:fe,lineNumber:124,columnNumber:9}}),_.default.createElement(Tt,{__self:this,__source:{fileName:fe,lineNumber:125,columnNumber:9}})))}module.exports=Ut;
|
|
14
|
+
`).forEach(a=>{const f=e.measureText(a);o<f.width&&(o=f.width),c+=t.data.size});const{x:r,y:n}=t.editHistory.reduce((a,{data:f})=>({x:a.x+f.x2-f.x1,y:a.y+f.y2-f.y1}),{x:0,y:0}),u=t.data.x+r,p=t.data.y+n,l=u+o,h=p+c;return s.x>=u&&s.x<=l&&s.y>=p&&s.y<=h}function Bt(){const e=X(),[t,s]=Y(),[o]=G(),[c,r]=I(),[,n]=A(),u=W(),[p,l]=i.useState(3),[h,a]=i.useState("#ee5126"),f=i.useRef(null),m=i.useRef(null),[g,y]=i.useState(null),[v,S]=i.useState(""),C=c==="Text",z=i.useCallback(()=>{r.set("Text"),n.set("default")},[r,n]),d=i.useCallback(()=>{C||(z(),s.clearSelect())},[C,z,s]),b=i.useCallback(D=>{f.current&&(f.current.data.size=ze[D]),l(D)},[]),x=i.useCallback(D=>{f.current&&(f.current.data.color=D),a(D)},[]),N=i.useCallback(D=>{S(D),C&&f.current&&(f.current.data.text=D)},[C]),k=i.useCallback(()=>{f.current&&f.current.data.text&&s.push(f.current),f.current=null,S(""),y(null)},[s]),E=i.useCallback((D,L)=>{D.name==="Text"&&(z(),m.current={type:B.Edit,data:{x1:L.clientX,y1:L.clientY,x2:L.clientX,y2:L.clientY},source:D},s.select(D))},[z,s]),w=i.useCallback(D=>{if(!C||!u.current||f.current||!o)return;const{left:L,top:_e}=u.current.canvas.getBoundingClientRect(),ye=window.getComputedStyle(u.current.canvas).fontFamily,se=D.clientX-L,re=D.clientY-_e;f.current={name:"Text",type:B.Source,data:{size:ze[p],color:h,fontFamily:ye,x:se,y:re,text:""},editHistory:[],draw:zt,isHit:Et},y({x:D.clientX,y:D.clientY,maxWidth:o.width-se,maxHeight:o.height-re})},[C,p,h,o,u]),R=i.useCallback(D=>{!C||m.current&&(m.current.data.x2=D.clientX,m.current.data.y2=D.clientY,t.top!==m.current?(m.current.source.editHistory.push(m.current),s.push(m.current)):s.set(t))},[C,t,s]),V=i.useCallback(()=>{!C||(m.current=null)},[C]);return ue(E),ee(w),te(R),ne(V),_.default.createElement(_.default.Fragment,null,_.default.createElement(F,{title:e.operation_text_title,icon:"icon-text",checked:C,onClick:d,option:_.default.createElement(ie,{size:p,color:h,onSizeChange:b,onColorChange:x,__self:this,__source:{fileName:we,lineNumber:261,columnNumber:11}}),__self:this,__source:{fileName:we,lineNumber:255,columnNumber:7}}),C&&g&&_.default.createElement(wt,{x:g.x,y:g.y,maxWidth:g.maxWidth,maxHeight:g.maxHeight,size:ze[p],color:h,value:v,onChange:N,onBlur:k,__self:this,__source:{fileName:we,lineNumber:265,columnNumber:9}}))}const Pe=4;function M(e,t,s){e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.arc(t,s,Pe,0,2*Math.PI),e.fill(),e.stroke()}function ge(e,t,s){t.draw(e,t);const{data:o}=e.getImageData(s.x,s.y,1,1);return o.some(c=>c!==0)}function $(e,t,s){if(!e)return!1;const{left:o,top:c}=e.getBoundingClientRect(),r=t.clientX-o,n=t.clientY-c;return(s.x-r)**2+(s.y-n)**2<Pe**2}function Dt(e,t){const{size:s,color:o,points:c}=t.data;e.lineCap="round",e.lineJoin="round",e.lineWidth=s,e.strokeStyle=o;const r=t.editHistory.reduce((n,{data:u})=>({x:n.x+u.x2-u.x1,y:n.y+u.y2-u.y1}),{x:0,y:0});e.beginPath(),c.forEach((n,u)=>{u===0?e.moveTo(n.x+r.x,n.y+r.y):e.lineTo(n.x+r.x,n.y+r.y)}),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.beginPath(),c.forEach((n,u)=>{u===0?e.moveTo(n.x+r.x,n.y+r.y):e.lineTo(n.x+r.x,n.y+r.y)}),e.stroke())}var Te="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Brush/index.tsx";function Mt(){const e=X(),[,t]=A(),[s,o]=I(),c=W(),[r,n]=Y(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),a=i.useRef(null),f=i.useRef(null),m=s==="Brush",g=i.useCallback(()=>{o.set("Brush"),t.set("default")},[o,t]),y=i.useCallback(()=>{m||(g(),n.clearSelect())},[m,g,n]),v=i.useCallback((d,b)=>{d.name==="Brush"&&(g(),f.current={type:B.Edit,data:{x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:d},n.select(d))},[g,n]),S=i.useCallback(d=>{if(!m||a.current||!c.current)return;const{left:b,top:x}=c.current.canvas.getBoundingClientRect();a.current={name:"Brush",type:B.Source,data:{size:u,color:l,points:[{x:d.clientX-b,y:d.clientY-x}]},editHistory:[],draw:Dt,isHit:ge}},[m,c,u,l]),C=i.useCallback(d=>{if(!(!m||!c.current)){if(f.current)f.current.data.x2=d.clientX,f.current.data.y2=d.clientY,r.top!==f.current?(f.current.source.editHistory.push(f.current),n.push(f.current)):n.set(r);else if(a.current){const{left:b,top:x}=c.current.canvas.getBoundingClientRect();a.current.data.points.push({x:d.clientX-b,y:d.clientY-x}),r.top!==a.current?n.push(a.current):n.set(r)}}},[m,r,c,n]),z=i.useCallback(()=>{!m||(a.current&&n.clearSelect(),a.current=null,f.current=null)},[m,n]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_brush_title,icon:"icon-brush",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:Te,lineNumber:166,columnNumber:15}}),__self:this,__source:{fileName:Te,lineNumber:161,columnNumber:5}})}function je(e){let{x1:t,y1:s,x2:o,y2:c}=e.data;return e.editHistory.forEach(({data:r})=>{const n=r.x2-r.x1,u=r.y2-r.y1;r.type===le.Move?(t+=n,s+=u,o+=n,c+=u):r.type===le.MoveStart?(t+=n,s+=u):r.type===le.MoveEnd&&(o+=n,c+=u)}),me(U({},e.data),{x1:t,x2:o,y1:s,y2:c})}function $t(e,t){const{size:s,color:o,x1:c,x2:r,y1:n,y2:u}=je(t);e.lineCap="round",e.lineJoin="bevel",e.lineWidth=s,e.strokeStyle=o;const p=r-c,l=u-n,h=s*3,a=Math.atan2(l,p);e.beginPath(),e.moveTo(c,n),e.lineTo(r,u),e.lineTo(r-h*Math.cos(a-Math.PI/6),u-h*Math.sin(a-Math.PI/6)),e.moveTo(r,u),e.lineTo(r-h*Math.cos(a+Math.PI/6),u-h*Math.sin(a+Math.PI/6)),e.stroke(),t.isSelected&&(M(e,c,n),M(e,r,u))}var Ue="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Arrow/index.tsx",le;(function(e){e[e.Move=0]="Move",e[e.MoveStart=1]="MoveStart",e[e.MoveEnd=2]="MoveEnd"})(le||(le={}));function Lt(){const e=X(),[,t]=A(),[s,o]=I(),[c,r]=Y(),n=W(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),a=i.useRef(null),f=i.useRef(null),m=s==="Arrow",g=i.useCallback(()=>{o.set("Arrow"),t.set("default")},[o,t]),y=i.useCallback(()=>{m||(g(),r.clearSelect())},[m,g,r]),v=i.useCallback((d,b)=>{if(d.name!=="Arrow"||!n.current)return;const x=d;g();const{x1:N,y1:k,x2:E,y2:w}=je(x);let R=0;$(n.current.canvas,b,{x:N,y:k})?R=1:$(n.current.canvas,b,{x:E,y:w})&&(R=2),f.current={type:B.Edit,data:{type:R,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:x},r.select(d)},[n,g,r]),S=i.useCallback(d=>{if(!m||a.current||!n.current)return;const{left:b,top:x}=n.current.canvas.getBoundingClientRect();a.current={name:"Arrow",type:B.Source,data:{size:u,color:l,x1:d.clientX-b,y1:d.clientY-x,x2:d.clientX-b,y2:d.clientY-x},editHistory:[],draw:$t,isHit:ge}},[m,l,u,n]),C=i.useCallback(d=>{if(!(!m||!n.current)){if(f.current)f.current.data.x2=d.clientX,f.current.data.y2=d.clientY,c.top!==f.current?(f.current.source.editHistory.push(f.current),r.push(f.current)):r.set(c);else if(a.current){const{left:b,top:x}=n.current.canvas.getBoundingClientRect();a.current.data.x2=d.clientX-b,a.current.data.y2=d.clientY-x,c.top!==a.current?r.push(a.current):r.set(c)}}},[m,c,n,r]),z=i.useCallback(()=>{!m||(a.current&&r.clearSelect(),a.current=null,f.current=null)},[m,r]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_arrow_title,icon:"icon-arrow",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:Ue,lineNumber:190,columnNumber:15}}),__self:this,__source:{fileName:Ue,lineNumber:185,columnNumber:5}})}function Ge(e){let{x1:t,y1:s,x2:o,y2:c}=e.data;return e.editHistory.forEach(({data:r})=>{const n=r.x2-r.x1,u=r.y2-r.y1;r.type===P.Move?(t+=n,s+=u,o+=n,c+=u):r.type===P.ResizeTop?s+=u:r.type===P.ResizeRightTop?(o+=n,s+=u):r.type===P.ResizeRight?o+=n:r.type===P.ResizeRightBottom?(o+=n,c+=u):r.type===P.ResizeBottom?c+=u:r.type===P.ResizeLeftBottom?(t+=n,c+=u):r.type===P.ResizeLeft?t+=n:r.type===P.ResizeLeftTop&&(t+=n,s+=u)}),me(U({},e.data),{x1:t,x2:o,y1:s,y2:c})}function Ht(e,t){const{size:s,color:o,x1:c,y1:r,x2:n,y2:u}=Ge(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=s,e.strokeStyle=o;const p=(c+n)/2,l=(r+u)/2,h=Math.abs(n-c)/2,a=Math.abs(u-r)/2,f=.5522848,m=h*f,g=a*f;e.beginPath(),e.moveTo(p-h,l),e.bezierCurveTo(p-h,l-g,p-m,l-a,p,l-a),e.bezierCurveTo(p+m,l-a,p+h,l-g,p+h,l),e.bezierCurveTo(p+h,l+g,p+m,l+a,p,l+a),e.bezierCurveTo(p-m,l+a,p-h,l+g,p-h,l),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.moveTo(c,r),e.lineTo(n,r),e.lineTo(n,u),e.lineTo(c,u),e.closePath(),e.stroke(),M(e,(c+n)/2,r),M(e,n,r),M(e,n,(r+u)/2),M(e,n,u),M(e,(c+n)/2,u),M(e,c,u),M(e,c,(r+u)/2),M(e,c,r))}var Ae="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ellipse/index.tsx",P;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(P||(P={}));function Xt(){const e=X(),[t,s]=Y(),[o,c]=I(),[,r]=A(),n=W(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),a=i.useRef(null),f=i.useRef(null),m=o==="Ellipse",g=i.useCallback(()=>{c.set("Ellipse"),r.set("crosshair")},[c,r]),y=i.useCallback(()=>{m||(g(),s.clearSelect())},[m,g,s]),v=i.useCallback((d,b)=>{if(d.name!=="Ellipse"||!n.current)return;const x=d;g();const{x1:N,y1:k,x2:E,y2:w}=Ge(x);let R=0;$(n.current.canvas,b,{x:(N+E)/2,y:k})?R=1:$(n.current.canvas,b,{x:E,y:k})?R=2:$(n.current.canvas,b,{x:E,y:(k+w)/2})?R=3:$(n.current.canvas,b,{x:E,y:w})?R=4:$(n.current.canvas,b,{x:(N+E)/2,y:w})?R=5:$(n.current.canvas,b,{x:N,y:w})?R=6:$(n.current.canvas,b,{x:N,y:(k+w)/2})?R=7:$(n.current.canvas,b,{x:N,y:k})&&(R=8),f.current={type:B.Edit,data:{type:R,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:x},s.select(d)},[n,g,s]),S=i.useCallback(d=>{if(!m||!n.current||a.current)return;const{left:b,top:x}=n.current.canvas.getBoundingClientRect(),N=d.clientX-b,k=d.clientY-x;a.current={name:"Ellipse",type:B.Source,data:{size:u,color:l,x1:N,y1:k,x2:N,y2:k},editHistory:[],draw:Ht,isHit:ge}},[m,u,l,n]),C=i.useCallback(d=>{if(!(!m||!n.current)){if(f.current)f.current.data.x2=d.clientX,f.current.data.y2=d.clientY,t.top!==f.current?(f.current.source.editHistory.push(f.current),s.push(f.current)):s.set(t);else if(a.current){const{left:b,top:x}=n.current.canvas.getBoundingClientRect();a.current.data.x2=d.clientX-b,a.current.data.y2=d.clientY-x,t.top!==a.current?s.push(a.current):s.set(t)}}},[m,n,t,s]),z=i.useCallback(()=>{!m||(a.current&&s.clearSelect(),a.current=null,f.current=null)},[m,s]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_ellipse_title,icon:"icon-ellipse",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:Ae,lineNumber:242,columnNumber:15}}),__self:this,__source:{fileName:Ae,lineNumber:237,columnNumber:5}})}function Ie(e){let{x1:t,y1:s,x2:o,y2:c}=e.data;return e.editHistory.forEach(({data:r})=>{const n=r.x2-r.x1,u=r.y2-r.y1;r.type===T.Move?(t+=n,s+=u,o+=n,c+=u):r.type===T.ResizeTop?s+=u:r.type===T.ResizeRightTop?(o+=n,s+=u):r.type===T.ResizeRight?o+=n:r.type===T.ResizeRightBottom?(o+=n,c+=u):r.type===T.ResizeBottom?c+=u:r.type===T.ResizeLeftBottom?(t+=n,c+=u):r.type===T.ResizeLeft?t+=n:r.type===T.ResizeLeftTop&&(t+=n,s+=u)}),me(U({},e.data),{x1:t,x2:o,y1:s,y2:c})}function Yt(e,t){const{size:s,color:o,x1:c,y1:r,x2:n,y2:u}=Ie(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=s,e.strokeStyle=o,e.beginPath(),e.moveTo(c,r),e.lineTo(n,r),e.lineTo(n,u),e.lineTo(c,u),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",M(e,(c+n)/2,r),M(e,n,r),M(e,n,(r+u)/2),M(e,n,u),M(e,(c+n)/2,u),M(e,c,u),M(e,c,(r+u)/2),M(e,c,r))}var We="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Rectangle/index.tsx",T;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(T||(T={}));function Ft(){const e=X(),[t,s]=Y(),[o,c]=I(),[,r]=A(),n=W(),[u,p]=i.useState(3),[l,h]=i.useState("#ee5126"),a=i.useRef(null),f=i.useRef(null),m=o==="Rectangle",g=i.useCallback(()=>{c.set("Rectangle"),r.set("crosshair")},[c,r]),y=i.useCallback(()=>{m||(g(),s.clearSelect())},[m,g,s]),v=i.useCallback((d,b)=>{if(d.name!=="Rectangle"||!n.current)return;const x=d;g();const{x1:N,y1:k,x2:E,y2:w}=Ie(x);let R=0;$(n.current.canvas,b,{x:(N+E)/2,y:k})?R=1:$(n.current.canvas,b,{x:E,y:k})?R=2:$(n.current.canvas,b,{x:E,y:(k+w)/2})?R=3:$(n.current.canvas,b,{x:E,y:w})?R=4:$(n.current.canvas,b,{x:(N+E)/2,y:w})?R=5:$(n.current.canvas,b,{x:N,y:w})?R=6:$(n.current.canvas,b,{x:N,y:(k+w)/2})?R=7:$(n.current.canvas,b,{x:N,y:k})&&(R=8),f.current={type:B.Edit,data:{type:R,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:d},s.select(d)},[n,g,s]),S=i.useCallback(d=>{if(!m||!n.current||a.current)return;const{left:b,top:x}=n.current.canvas.getBoundingClientRect(),N=d.clientX-b,k=d.clientY-x;a.current={name:"Rectangle",type:B.Source,data:{size:u,color:l,x1:N,y1:k,x2:N,y2:k},editHistory:[],draw:Yt,isHit:ge}},[m,u,l,n]),C=i.useCallback(d=>{if(!(!m||!n.current)){if(f.current)f.current.data.x2=d.clientX,f.current.data.y2=d.clientY,t.top!==f.current?(f.current.source.editHistory.push(f.current),s.push(f.current)):s.set(t);else if(a.current){const{left:b,top:x}=n.current.canvas.getBoundingClientRect(),N=a.current.data;N.x2=d.clientX-b,N.y2=d.clientY-x,t.top!==a.current?s.push(a.current):s.set(t)}}},[m,n,t,s]),z=i.useCallback(()=>{!m||(a.current&&s.clearSelect(),a.current=null,f.current=null)},[m,s]);return ue(v),ee(S),te(C),ne(z),_.default.createElement(F,{title:e.operation_rectangle_title,icon:"icon-rectangle",checked:m,onClick:y,option:_.default.createElement(ie,{size:u,color:l,onSizeChange:p,onColorChange:h,__self:this,__source:{fileName:We,lineNumber:242,columnNumber:15}}),__self:this,__source:{fileName:We,lineNumber:237,columnNumber:5}})}var Pt=[Ft,Xt,Lt,Mt,Bt,xt,"|",_t,bt,"|",dt,ht,at];var ae="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOperations/index.tsx";const Oe=_.default.createContext(null);function Tt(){const{width:e,height:t}=H(),[s]=G(),[o,c]=i.useState(null),[r,n]=i.useState(null),u=i.useRef(null),p=i.useCallback(h=>{h.stopPropagation()},[]),l=i.useCallback(h=>{h.preventDefault(),h.stopPropagation()},[]);return i.useEffect(()=>{if(!s||!u.current)return;const h=u.current.getBoundingClientRect();let a=s.x+s.width-h.width,f=s.y+s.height+10;a<0&&(a=0),a>e-h.width&&(a=e-h.width),f>t-h.height&&(f=t-h.height-10),((r==null?void 0:r.x)!==a||r.y!==f)&&n({x:a,y:f}),((o==null?void 0:o.x)!==h.x||o.y!==h.y||o.width!==h.width||o.height!==h.height)&&c({x:h.x,y:h.y,width:h.width,height:h.height})}),s?_.default.createElement(Oe.Provider,{value:o,__self:this,__source:{fileName:ae,lineNumber:76,columnNumber:5}},_.default.createElement("div",{ref:u,className:"screenshots-operations",style:{visibility:r?"visible":"hidden",left:r==null?void 0:r.x,top:r==null?void 0:r.y},onDoubleClick:p,onContextMenu:l,__self:this,__source:{fileName:ae,lineNumber:77,columnNumber:7}},_.default.createElement("div",{className:"screenshots-operations-buttons",__self:this,__source:{fileName:ae,lineNumber:88,columnNumber:9}},Pt.map((h,a)=>h==="|"?_.default.createElement("div",{key:a,className:"screenshots-operations-divider",__self:this,__source:{fileName:ae,lineNumber:91,columnNumber:22}}):_.default.createElement(h,{key:a,__self:this,__source:{fileName:ae,lineNumber:93,columnNumber:22}}))))):null}function jt(e){const[t,s]=i.useState(null);return i.useEffect(()=>{if(s(null),e==null)return;const o=document.createElement("img"),c=()=>s(o),r=()=>s(null);return o.addEventListener("load",c),o.addEventListener("error",r),o.src=e,()=>{o.removeEventListener("load",c),o.removeEventListener("error",r)}},[e]),t}var fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/index.tsx";function Ut(n){var u=n,{url:e,width:t,height:s,lang:o,className:c}=u,r=Me(u,["url","width","height","lang","className"]);const p=jt(e),l=i.useRef(null),h=i.useRef({}),[a,f]=i.useState({index:-1,stack:[]}),[m,g]=i.useState(null),[y,v]=i.useState("move"),[S,C]=i.useState(void 0),z={url:e,width:t,height:s,image:p,lang:U(U({},Le),o),emiterRef:h,canvasContextRef:l,history:a,bounds:m,cursor:y,operation:S},d=i.useCallback((w,...R)=>{const V=r[w];typeof V=="function"&&V(...R)},[r]),b={call:d,setHistory:f,setBounds:g,setCursor:v,setOperation:C},x=["screenshots"];c&&x.push(c);const N=()=>{h.current={},f({index:-1,stack:[]}),g(null),v("move"),C(void 0)},k=i.useCallback(w=>{w.button!==0||!m||!l.current||l.current.canvas.toBlob(R=>{d("onOk",R,m),N()},"image/png")},[m,d]),E=i.useCallback(w=>{w.button===2&&(w.preventDefault(),d("onCancel"),N())},[d]);return i.useLayoutEffect(()=>{N()},[e]),_.default.createElement(xe.Provider,{value:{store:z,dispatcher:b},__self:this,__source:{fileName:fe,lineNumber:116,columnNumber:5}},_.default.createElement("div",{className:x.join(" "),style:{width:t,height:s},onDoubleClick:k,onContextMenu:E,__self:this,__source:{fileName:fe,lineNumber:117,columnNumber:7}},_.default.createElement(tt,{__self:this,__source:{fileName:fe,lineNumber:123,columnNumber:9}}),_.default.createElement(it,{ref:l,__self:this,__source:{fileName:fe,lineNumber:124,columnNumber:9}}),_.default.createElement(Tt,{__self:this,__source:{fileName:fe,lineNumber:125,columnNumber:9}})))}module.exports=Ut;
|
|
@@ -262,6 +262,7 @@ function ScreenshotsBackground() {
|
|
|
262
262
|
const [bounds, boundsDispatcher] = useBounds();
|
|
263
263
|
const elRef = useRef(null);
|
|
264
264
|
const pointRef = useRef(null);
|
|
265
|
+
const isMoveRef = useRef(false);
|
|
265
266
|
const [position, setPosition] = useState(null);
|
|
266
267
|
const updateBounds = useCallback((p1, p2) => {
|
|
267
268
|
if (!elRef.current) {
|
|
@@ -287,6 +288,7 @@ function ScreenshotsBackground() {
|
|
|
287
288
|
x: e.clientX,
|
|
288
289
|
y: e.clientY
|
|
289
290
|
};
|
|
291
|
+
isMoveRef.current = false;
|
|
290
292
|
}, [bounds]);
|
|
291
293
|
useEffect(() => {
|
|
292
294
|
const onMouseMove = (e) => {
|
|
@@ -308,16 +310,20 @@ function ScreenshotsBackground() {
|
|
|
308
310
|
x: e.clientX,
|
|
309
311
|
y: e.clientY
|
|
310
312
|
});
|
|
313
|
+
isMoveRef.current = true;
|
|
311
314
|
};
|
|
312
315
|
const onMouseUp = (e) => {
|
|
313
316
|
if (!pointRef.current) {
|
|
314
317
|
return;
|
|
315
318
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
319
|
+
if (isMoveRef.current) {
|
|
320
|
+
updateBounds(pointRef.current, {
|
|
321
|
+
x: e.clientX,
|
|
322
|
+
y: e.clientY
|
|
323
|
+
});
|
|
324
|
+
}
|
|
320
325
|
pointRef.current = null;
|
|
326
|
+
isMoveRef.current = false;
|
|
321
327
|
};
|
|
322
328
|
window.addEventListener("mousemove", onMouseMove);
|
|
323
329
|
window.addEventListener("mouseup", onMouseUp);
|
|
@@ -336,7 +342,7 @@ function ScreenshotsBackground() {
|
|
|
336
342
|
__self: this,
|
|
337
343
|
__source: {
|
|
338
344
|
fileName: _jsxFileName$k,
|
|
339
|
-
lineNumber:
|
|
345
|
+
lineNumber: 113,
|
|
340
346
|
columnNumber: 5
|
|
341
347
|
}
|
|
342
348
|
}, /* @__PURE__ */ React.createElement("img", {
|
|
@@ -345,7 +351,7 @@ function ScreenshotsBackground() {
|
|
|
345
351
|
__self: this,
|
|
346
352
|
__source: {
|
|
347
353
|
fileName: _jsxFileName$k,
|
|
348
|
-
lineNumber:
|
|
354
|
+
lineNumber: 114,
|
|
349
355
|
columnNumber: 7
|
|
350
356
|
}
|
|
351
357
|
}), /* @__PURE__ */ React.createElement("div", {
|
|
@@ -353,7 +359,7 @@ function ScreenshotsBackground() {
|
|
|
353
359
|
__self: this,
|
|
354
360
|
__source: {
|
|
355
361
|
fileName: _jsxFileName$k,
|
|
356
|
-
lineNumber:
|
|
362
|
+
lineNumber: 115,
|
|
357
363
|
columnNumber: 7
|
|
358
364
|
}
|
|
359
365
|
}), position && !bounds && /* @__PURE__ */ React.createElement(ScreenshotsMagnifier, {
|
|
@@ -362,7 +368,7 @@ function ScreenshotsBackground() {
|
|
|
362
368
|
__self: this,
|
|
363
369
|
__source: {
|
|
364
370
|
fileName: _jsxFileName$k,
|
|
365
|
-
lineNumber:
|
|
371
|
+
lineNumber: 116,
|
|
366
372
|
columnNumber: 31
|
|
367
373
|
}
|
|
368
374
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-screenshots",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "a screenshot cropper tool by react",
|
|
5
5
|
"main": "./lib/react-screenshots.cjs.js",
|
|
6
6
|
"module": "./lib/react-screenshots.es.js",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"typescript": "^4.5.5",
|
|
65
65
|
"vite": "^2.7.13"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "83c063ecd6b84c75cea303543e01949b352d148c"
|
|
68
68
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var Qe=Object.defineProperty,Ze=Object.defineProperties;var et=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var Be=(e,t,r)=>t in e?Qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,T=(e,t)=>{for(var r in t||(t={}))Ee.call(t,r)&&Be(e,r,t[r]);if(he)for(var r of he(t))je.call(t,r)&&Be(e,r,t[r]);return e},pe=(e,t)=>Ze(e,et(t));var Me=(e,t)=>{var r={};for(var o in e)Ee.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&he)for(var o of he(e))t.indexOf(o)<0&&je.call(e,o)&&(r[o]=e[o]);return r};import{R as Ve,r as c,j as g,a as _e,b as tt}from"./vendor.e3c417b2.js";const st=function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))o(i);new MutationObserver(i=>{for(const n of i)if(n.type==="childList")for(const s of n.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&o(s)}).observe(document,{childList:!0,subtree:!0});function r(i){const n={};return i.integrity&&(n.integrity=i.integrity),i.referrerpolicy&&(n.referrerPolicy=i.referrerpolicy),i.crossorigin==="use-credentials"?n.credentials="include":i.crossorigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function o(i){if(i.ep)return;i.ep=!0;const n=r(i);fetch(i.href,n)}};st();const $e={magnifier_position_label:"\u5750\u6807",operation_ok_title:"\u786E\u5B9A",operation_cancel_title:"\u53D6\u6D88",operation_save_title:"\u4FDD\u5B58",operation_redo_title:"\u91CD\u505A",operation_undo_title:"\u64A4\u9500",operation_mosaic_title:"\u9A6C\u8D5B\u514B",operation_text_title:"\u6587\u672C",operation_brush_title:"\u753B\u7B14",operation_arrow_title:"\u7BAD\u5934",operation_ellipse_title:"\u692D\u5706",operation_rectangle_title:"\u77E9\u5F62"};var ye=Ve.createContext({store:{url:void 0,image:null,width:0,height:0,lang:$e,emiterRef:{current:{}},canvasContextRef:{current:null},history:{index:-1,stack:[]},bounds:null,cursor:"move",operation:void 0},dispatcher:{call:void 0,setHistory:void 0,setBounds:void 0,setCursor:void 0,setOperation:void 0}});function oe(){const{dispatcher:e}=c.exports.useContext(ye);return e}function $(){const{store:e}=c.exports.useContext(ye);return e}function U(){const{bounds:e}=$(),{setBounds:t}=oe(),r=c.exports.useCallback(i=>{t==null||t(i)},[t]),o=c.exports.useCallback(()=>{t==null||t(null)},[t]);return[e,{set:r,reset:o}]}function L(){const{lang:e}=$();return e}var J="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsMagnifier/index.tsx";const K=100,Q=80;function nt({x:e,y:t}){const{width:r,height:o,image:i}=$(),n=L(),[s,a]=c.exports.useState(null),d=c.exports.useRef(null),u=c.exports.useRef(null),h=c.exports.useRef(null),[f,l]=c.exports.useState("000000");return c.exports.useLayoutEffect(()=>{if(!d.current)return;const p=d.current.getBoundingClientRect();let m=e+20,v=t+20;m+p.width>r&&(m=e-p.width-20),v+p.height>o&&(v=t-p.height-20),m<0&&(m=0),v<0&&(v=0),a({x:m,y:v})},[r,o,e,t]),c.exports.useEffect(()=>{if(!i||!u.current){h.current=null;return}if(h.current||(h.current=u.current.getContext("2d")),!h.current)return;const p=h.current;p.clearRect(0,0,K,Q);const m=i.naturalWidth/r,v=i.naturalHeight/o;p.drawImage(i,e*m-K/2,t*v-Q/2,K,Q,0,0,K,Q);const{data:N}=p.getImageData(Math.floor(K/2),Math.floor(Q/2),1,1),w=Array.from(N.slice(0,3)).map(S=>S>=16?S.toString(16):`0${S.toString(16)}`).join("").toUpperCase();l(w)},[r,o,i,e,t]),g.exports.jsxDEV("div",{ref:d,className:"screenshots-magnifier",style:{transform:`translate(${s==null?void 0:s.x}px, ${s==null?void 0:s.y}px)`},children:[g.exports.jsxDEV("div",{className:"screenshots-magnifier-body",children:g.exports.jsxDEV("canvas",{ref:u,className:"screenshots-magnifier-body-canvas",width:K,height:Q},void 0,!1,{fileName:J,lineNumber:97,columnNumber:9},this)},void 0,!1,{fileName:J,lineNumber:96,columnNumber:7},this),g.exports.jsxDEV("div",{className:"screenshots-magnifier-footer",children:[g.exports.jsxDEV("div",{className:"screenshots-magnifier-footer-item",children:[n.magnifier_position_label,": (",e,",",t,")"]},void 0,!0,{fileName:J,lineNumber:105,columnNumber:9},this),g.exports.jsxDEV("div",{className:"screenshots-magnifier-footer-item",children:["RGB: #",f]},void 0,!0,{fileName:J,lineNumber:108,columnNumber:9},this)]},void 0,!0,{fileName:J,lineNumber:104,columnNumber:7},this)]},void 0,!0,{fileName:J,lineNumber:89,columnNumber:5},this)}function rt({x:e,y:t},{x:r,y:o},i,n){return e>r&&([e,r]=[r,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0),r>i&&(r=i),t<0&&(t=0),o>n&&(o=n),{x:e,y:t,width:r-e,height:o-t}}var me="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsBackground/index.tsx";function ot(){const{url:e,image:t,width:r,height:o}=$(),[i,n]=U(),s=c.exports.useRef(null),a=c.exports.useRef(null),[d,u]=c.exports.useState(null),h=c.exports.useCallback((l,p)=>{if(!s.current)return;const{x:m,y:v}=s.current.getBoundingClientRect();n.set(rt({x:l.x-m,y:l.y-v},{x:p.x-m,y:p.y-v},r,o))},[r,o,n]),f=c.exports.useCallback(l=>{a.current||i||l.button!==0||(a.current={x:l.clientX,y:l.clientY})},[i]);return c.exports.useEffect(()=>{const l=m=>{if(s.current){const v=s.current.getBoundingClientRect();m.clientX<v.left||m.clientY<v.top||m.clientX>v.right||m.clientY>v.bottom?u(null):u({x:m.clientX-v.x,y:m.clientY-v.y})}!a.current||h(a.current,{x:m.clientX,y:m.clientY})},p=m=>{!a.current||(h(a.current,{x:m.clientX,y:m.clientY}),a.current=null)};return window.addEventListener("mousemove",l),window.addEventListener("mouseup",p),()=>{window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",p)}},[h]),!e||!t?null:g.exports.jsxDEV("div",{ref:s,className:"screenshots-background",onMouseDown:f,children:[g.exports.jsxDEV("img",{className:"screenshots-background-image",src:e},void 0,!1,{fileName:me,lineNumber:110,columnNumber:7},this),g.exports.jsxDEV("div",{className:"screenshots-background-mask"},void 0,!1,{fileName:me,lineNumber:111,columnNumber:7},this),d&&!i&&g.exports.jsxDEV(nt,{x:d==null?void 0:d.x,y:d==null?void 0:d.y},void 0,!1,{fileName:me,lineNumber:112,columnNumber:31},this)]},void 0,!0,{fileName:me,lineNumber:105,columnNumber:5},this)}var Ke;const Le=(Ke=window.devicePixelRatio)!=null?Ke:2;var de=Le<2?2:Le;function it(e,t,r,o){const i=e.clientX-r.x,n=e.clientY-r.y;let s=o.x,a=o.y,d=o.x+o.width,u=o.y+o.height;switch(t){case"top":a+=n;break;case"top-right":d+=i,a+=n;break;case"right":d+=i;break;case"right-bottom":d+=i,u+=n;break;case"bottom":u+=n;break;case"bottom-left":s+=i,u+=n;break;case"left":s+=i;break;case"left-top":s+=i,a+=n;break;case"move":s+=i,a+=n,d+=i,u+=n;break}return[{x:s,y:a},{x:d,y:u}]}function ct({x:e,y:t},{x:r,y:o},i,n,s,a){return e>r&&([e,r]=[r,e]),t>o&&([t,o]=[o,t]),e<0&&(e=0,a==="move"&&(r=i.width)),r>n&&(r=n,a==="move"&&(e=r-i.width)),t<0&&(t=0,a==="move"&&(o=i.height)),o>s&&(o=s,a==="move"&&(t=o-i.height)),{x:e,y:t,width:Math.max(r-e,1),height:Math.max(o-t,1)}}var j;(function(e){e[e.Edit=0]="Edit",e[e.Source=1]="Source"})(j||(j={}));function Z(){const{emiterRef:e}=$(),t=c.exports.useCallback((n,s)=>{const a=e.current;Array.isArray(a[n])?a[n].push(s):a[n]=[s]},[e]),r=c.exports.useCallback((n,s)=>{const a=e.current;if(Array.isArray(a[n])){const d=a[n].findIndex(u=>u===s);d!==-1&&a[n].splice(d,1)}},[e]),o=c.exports.useCallback((n,...s)=>{const a=e.current;Array.isArray(a[n])&&a[n].forEach(d=>d(...s))},[e]),i=c.exports.useCallback(()=>{e.current={}},[e]);return{on:t,off:r,emit:o,reset:i}}function H(){const{history:e}=$(),{setHistory:t}=oe(),r=c.exports.useCallback(h=>{const{index:f,stack:l}=e;l.forEach(p=>{p.type===j.Source&&(p.isSelected=!1)}),h.type===j.Source?h.isSelected=!0:h.type===j.Edit&&(h.source.isSelected=!0),l.splice(f+1),l.push(h),t==null||t({index:l.length-1,stack:l})},[e,t]),o=c.exports.useCallback(()=>{const{stack:h}=e;h.pop(),t==null||t({index:h.length-1,stack:h})},[e,t]),i=c.exports.useCallback(()=>{const{index:h,stack:f}=e,l=f[h];l&&(l.type===j.Source?l.isSelected=!1:l.type===j.Edit&&l.source.editHistory.pop()),t==null||t({index:h<=0?-1:h-1,stack:f})},[e,t]),n=c.exports.useCallback(()=>{const{index:h,stack:f}=e,l=f[h+1];l&&(l.type===j.Source?l.isSelected=!1:l.type===j.Edit&&l.source.editHistory.push(l)),t==null||t({index:h>=f.length-1?f.length-1:h+1,stack:f})},[e,t]),s=c.exports.useCallback(h=>{t==null||t(T({},h))},[t]),a=c.exports.useCallback(h=>{e.stack.forEach(f=>{f.type===j.Source&&(f===h?f.isSelected=!0:f.isSelected=!1)}),t==null||t(T({},e))},[e,t]),d=c.exports.useCallback(()=>{e.stack.forEach(h=>{h.type===j.Source&&(h.isSelected=!1)}),t==null||t(T({},e))},[e,t]),u=c.exports.useCallback(()=>{t==null||t({index:-1,stack:[]})},[t]);return[{index:e.index,stack:e.stack,top:e.stack.slice(e.index,e.index+1)[0]},{push:r,pop:o,undo:i,redo:n,set:s,select:a,clearSelect:d,reset:u}]}function A(){const{cursor:e}=$(),{setCursor:t}=oe(),r=c.exports.useCallback(i=>{t==null||t(i)},[t]),o=c.exports.useCallback(()=>{t==null||t("move")},[t]);return[e,{set:r,reset:o}]}function G(){const{operation:e}=$(),{setOperation:t}=oe(),r=c.exports.useCallback(i=>{t==null||t(i)},[t]),o=c.exports.useCallback(()=>{t==null||t(void 0)},[t]);return[e,{set:r,reset:o}]}function at(e,t,r,o){if(!t)return!1;const i=document.createElement("canvas");i.width=e.width,i.height=e.height;const n=i.getContext("2d");if(!n)return!1;const{left:s,top:a}=t.getBoundingClientRect(),d=o.clientX-s,u=o.clientY-a;return[...r.stack.slice(0,r.index+1)].reverse().find(f=>{var l;return f.type!==j.Source?!1:(n.clearRect(0,0,e.width,e.height),(l=f.isHit)==null?void 0:l.call(f,n,f,{x:d,y:u}))})}var ie="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsCanvas/index.tsx";const ut=["top","right","bottom","left"];var P;(function(e){e.ResizeTop="top",e.ResizetopRight="top-right",e.ResizeRight="right",e.ResizeRightBottom="right-bottom",e.ResizeBottom="bottom",e.ResizeBottomLeft="bottom-left",e.ResizeLeft="left",e.ResizeLeftTop="left-top",e.Move="move"})(P||(P={}));const lt=[P.ResizeTop,P.ResizetopRight,P.ResizeRight,P.ResizeRightBottom,P.ResizeBottom,P.ResizeBottomLeft,P.ResizeLeft,P.ResizeLeftTop];var ft=c.exports.forwardRef(function(t,r){const{image:o,width:i,height:n}=$(),s=Z(),[a]=H(),[d]=A(),[u,h]=U(),[f]=G(),l=c.exports.useRef(),p=c.exports.useRef(null),m=c.exports.useRef(null),v=c.exports.useRef(null),N=c.exports.useRef(null),w=c.exports.useCallback(()=>{if(!o||!u||!N.current)return;const x=o.naturalWidth/i,b=o.naturalHeight/n,y=N.current;y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="low",y.setTransform(de,0,0,de,0,0),y.clearRect(0,0,u.width,u.height),y.drawImage(o,u.x*x,u.y*b,u.width*x,u.height*b,0,0,u.width,u.height),a.stack.slice(0,a.index+1).forEach(C=>{C.type===j.Source&&C.draw(y,C)})},[o,i,n,u,N,a]),S=c.exports.useCallback((x,b)=>{if(!(x.button!==0||!u))if(!f)l.current=b,p.current={x:x.clientX,y:x.clientY},m.current={x:u.x,y:u.y,width:u.width,height:u.height};else{const y=at(u,v.current,a,x.nativeEvent);y?s.emit("drawselect",y,x.nativeEvent):s.emit("mousedown",x.nativeEvent)}},[u,f,s,a]),z=c.exports.useCallback(x=>{if(!l.current||!p.current||!m.current||!u)return;const b=it(x,l.current,p.current,m.current);h.set(ct(b[0],b[1],u,i,n,l.current))},[i,n,u,h]);return c.exports.useLayoutEffect(()=>{if(!o||!u||!v.current){N.current=null;return}N.current||(N.current=v.current.getContext("2d")),w()},[o,u,w]),c.exports.useEffect(()=>{const x=y=>{if(f)s.emit("mousemove",y);else{if(!l.current||!p.current||!m.current)return;z(y)}},b=y=>{if(f)s.emit("mouseup",y);else{if(!l.current||!p.current||!m.current)return;z(y),l.current=void 0,p.current=null,m.current=null}};return window.addEventListener("mousemove",x),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",b)}},[z,f,s]),c.exports.useImperativeHandle(r,()=>N.current),u?g.exports.jsxDEV("div",{className:"screenshots-canvas",style:{left:u.x,top:u.y,width:u.width,height:u.height},children:[g.exports.jsxDEV("canvas",{ref:v,width:u.width*de,height:u.height*de,style:{width:u.width,height:u.height}},void 0,!1,{fileName:ie,lineNumber:200,columnNumber:7},this),g.exports.jsxDEV("div",{className:"screenshots-canvas-body",style:{cursor:d},onMouseDown:x=>S(x,"move")},void 0,!1,{fileName:ie,lineNumber:209,columnNumber:7},this),ut.map(x=>g.exports.jsxDEV("div",{className:`screenshots-canvas-border-${x}`},x,!1,{fileName:ie,lineNumber:217,columnNumber:16},this)),lt.map(x=>g.exports.jsxDEV("div",{className:`screenshots-canvas-point-${x}`,onMouseDown:b=>S(b,x)},x,!1,{fileName:ie,lineNumber:221,columnNumber:11},this))]},void 0,!0,{fileName:ie,lineNumber:191,columnNumber:5},this):null});function Ne(){const e=oe();return c.exports.useCallback((r,...o)=>{var i;(i=e.call)==null||i.call(e,r,...o)},[e])}function I(){const{canvasContextRef:e}=$();return e}function Ce(){const e=Z(),[,t]=U(),[,r]=A(),[,o]=H(),[,i]=G();return c.exports.useCallback(()=>{e.reset(),o.reset(),t.reset(),r.reset(),i.reset()},[e,o,t,r,i])}var Se="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOption/index.tsx",q;(function(e){e.Bottom="bottom",e.Top="top"})(q||(q={}));function ht({open:e,content:t,children:r}){const o=c.exports.useRef(null),i=c.exports.useRef(null),n=c.exports.useRef(null),s=c.exports.useContext(Oe),[a,d]=c.exports.useState(q.Bottom),[u,h]=c.exports.useState(null),[f,l]=c.exports.useState(0),p=()=>(i.current||(i.current=document.createElement("div")),i.current);return c.exports.useEffect(()=>{const m=p();return e&&document.body.appendChild(m),()=>{m.remove()}},[e]),c.exports.useEffect(()=>{if(!e||!s||!o.current||!n.current)return;const m=o.current.getBoundingClientRect(),v=n.current.getBoundingClientRect();let N=a,w=m.left+m.width/2,S=m.top+m.height,z=f;if(w+v.width/2>s.x+s.width){const x=w;w=s.x+s.width-v.width/2,z=x-w}if(w<s.x+v.width/2){const x=w;w=s.x+v.width/2,z=x-w}S>window.innerHeight-v.height&&(N===q.Bottom&&(N=q.Top),S=m.top-v.height),S<0&&(N===q.Top&&(N=q.Bottom),S=m.top+m.height),N!==a&&d(N),((u==null?void 0:u.x)!==w||u.y!==S)&&h({x:w,y:S}),z!==f&&l(z)}),g.exports.jsxDEV(g.exports.Fragment,{children:[c.exports.cloneElement(r,{ref:o}),e&&t&&_e.exports.createPortal(g.exports.jsxDEV("div",{ref:n,className:"screenshots-option",style:{visibility:u?"visible":"hidden",left:u==null?void 0:u.x,top:u==null?void 0:u.y},"data-placement":a,children:[g.exports.jsxDEV("div",{className:"screenshots-option-container",children:t},void 0,!1,{fileName:Se,lineNumber:121,columnNumber:13},this),g.exports.jsxDEV("div",{className:"screenshots-option-arrow",style:{marginLeft:f}},void 0,!1,{fileName:Se,lineNumber:122,columnNumber:13},this)]},void 0,!0,{fileName:Se,lineNumber:111,columnNumber:11},this),p())]},void 0,!0)}var Re="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsButton/index.tsx";function X({title:e,icon:t,checked:r,disabled:o,option:i,onClick:n}){const s=["screenshots-button"],a=c.exports.useCallback(d=>{o||!n||n(d)},[o,n]);return r&&s.push("screenshots-button-checked"),o&&s.push("screenshots-button-disabled"),g.exports.jsxDEV(ht,{open:r,content:i,children:g.exports.jsxDEV("div",{className:s.join(" "),title:e,onClick:a,children:g.exports.jsxDEV("span",{className:t},void 0,!1,{fileName:Re,lineNumber:44,columnNumber:9},this)},void 0,!1,{fileName:Re,lineNumber:43,columnNumber:7},this)},void 0,!1,{fileName:Re,lineNumber:42,columnNumber:5},this)}var pt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ok/index.tsx";function mt(){const e=L(),t=I(),[,r]=H(),o=Ne(),[i]=U(),n=Ce(),s=c.exports.useCallback(()=>{r.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(a=>{o("onOk",a,i),n()},"image/png")})},[t,r,o,i,n]);return g.exports.jsxDEV(X,{title:e.operation_ok_title,icon:"icon-ok",onClick:s},void 0,!1,{fileName:pt,lineNumber:31,columnNumber:10},this)}var dt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Cancel/index.tsx";function xt(){const e=Ne(),t=Ce(),r=L(),o=c.exports.useCallback(()=>{e("onCancel"),t()},[e,t]);return g.exports.jsxDEV(X,{title:r.operation_cancel_title,icon:"icon-cancel",onClick:o},void 0,!1,{fileName:dt,lineNumber:17,columnNumber:10},this)}var bt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Save/index.tsx";function gt(){const e=L(),t=I(),[,r]=H(),[o]=U(),i=Ne(),n=Ce(),s=c.exports.useCallback(()=>{r.clearSelect(),setTimeout(()=>{!t.current||t.current.canvas.toBlob(a=>{i("onSave",a,o),n()},"image/png")})},[t,r,o,i,n]);return g.exports.jsxDEV(X,{title:e.operation_save_title,icon:"icon-save",onClick:s},void 0,!1,{fileName:bt,lineNumber:31,columnNumber:10},this)}var vt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Redo/index.tsx";function yt(){const e=L(),[t,r]=H(),o=c.exports.useCallback(()=>{r.redo()},[r]);return g.exports.jsxDEV(X,{title:e.operation_redo_title,icon:"icon-redo",disabled:!t.stack.length||t.stack.length-1===t.index,onClick:o},void 0,!1,{fileName:vt,lineNumber:15,columnNumber:5},this)}var Nt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Undo/index.tsx";function Ct(){const e=L(),[t,r]=H(),o=c.exports.useCallback(()=>{r.undo()},[r]);return g.exports.jsxDEV(X,{title:e.operation_undo_title,icon:"icon-undo",disabled:t.index===-1,onClick:o},void 0,!1,{fileName:Nt,lineNumber:15,columnNumber:5},this)}var ke="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSize/index.tsx";function He({value:e,onChange:t}){const r=[3,6,9];return g.exports.jsxDEV("div",{className:"screenshots-size",children:r.map(o=>{const i=["screenshots-size-item"];return o===e&&i.push("screenshots-size-active"),g.exports.jsxDEV("div",{className:i.join(" "),onClick:()=>t&&t(o),children:g.exports.jsxDEV("div",{className:"screenshots-size-pointer",style:{width:o*1.8,height:o*1.8}},void 0,!1,{fileName:ke,lineNumber:22,columnNumber:13},this)},o,!1,{fileName:ke,lineNumber:21,columnNumber:11},this)})},void 0,!1,{fileName:ke,lineNumber:12,columnNumber:5},this)}function ee(e){const t=Z();c.exports.useEffect(()=>(t.on("mousedown",e),()=>{t.off("mousedown",e)}),[e,t])}function te(e){const t=Z();c.exports.useEffect(()=>(t.on("mousemove",e),()=>{t.off("mousemove",e)}),[e,t])}function se(e){const t=Z();c.exports.useEffect(()=>(t.on("mouseup",e),()=>{t.off("mouseup",e)}),[e,t])}var Xe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Mosaic/index.tsx";function xe(e,t,r){if(!r)return[0,0,0,0];const{data:o,width:i}=r,n=t*i*4+e*4;return Array.from(o.slice(n,n+4))}function St(e,t){const{tiles:r,size:o}=t.data;r.forEach(i=>{const n=Math.round(i.color[0]),s=Math.round(i.color[1]),a=Math.round(i.color[2]),d=i.color[3]/255;e.fillStyle=`rgba(${n}, ${s}, ${a}, ${d})`,e.fillRect(i.x-o/2,i.y-o/2,o,o)})}function Rt(){const e=L(),{image:t,width:r,height:o}=$(),[i,n]=G(),s=I(),[a,d]=H(),[u]=U(),[,h]=A(),[f,l]=c.exports.useState(3),p=c.exports.useRef(null),m=c.exports.useRef(null),v=i==="Mosaic",N=c.exports.useCallback(()=>{n.set("Mosaic"),h.set("crosshair")},[n,h]),w=c.exports.useCallback(()=>{v||(N(),d.clearSelect())},[v,N,d]),S=c.exports.useCallback(b=>{if(!v||m.current||!p.current||!s.current)return;const y=s.current.canvas.getBoundingClientRect(),C=b.clientX-y.x,k=b.clientY-y.y,E=f*2;m.current={name:"Mosaic",type:j.Source,data:{size:E,tiles:[{x:C,y:k,color:xe(C,k,p.current)}]},editHistory:[],draw:St}},[v,f,s]),z=c.exports.useCallback(b=>{if(!v||!m.current||!s.current||!p.current)return;const y=s.current.canvas.getBoundingClientRect(),C=b.clientX-y.x,k=b.clientY-y.y,E=m.current.data.size,D=m.current.data.tiles;let R=D[D.length-1];if(!R)D.push({x:C,y:k,color:xe(C,k,p.current)});else{const O=R.x-C,B=R.y-k;let _=Math.sqrt(O**2+B**2);const ge=-B/_,ve=-O/_;for(;_>E;){const ne=Math.floor(R.x+E*ve),re=Math.floor(R.y+E*ge);R={x:ne,y:re,color:xe(ne,re,p.current)},D.push(R),_-=E}_>E/2&&D.push({x:C,y:k,color:xe(C,k,p.current)})}a.top!==m.current?d.push(m.current):d.set(a)},[v,s,a,d]),x=c.exports.useCallback(()=>{!v||(m.current=null)},[v]);return ee(S),te(z),se(x),c.exports.useEffect(()=>{if(!u||!t||!v)return;const b=document.createElement("canvas"),y=b.getContext("2d");if(!y)return;b.width=u.width,b.height=u.height;const C=t.naturalWidth/r,k=t.naturalHeight/o;y.drawImage(t,u.x*C,u.y*k,u.width*C,u.height*k,0,0,u.width,u.height),p.current=y.getImageData(0,0,u.width,u.height)},[r,o,u,t,v]),g.exports.jsxDEV(X,{title:e.operation_mosaic_title,icon:"icon-mosaic",checked:v,onClick:w,option:g.exports.jsxDEV(He,{value:f,onChange:l},void 0,!1,{fileName:Xe,lineNumber:220,columnNumber:15},this)},void 0,!1,{fileName:Xe,lineNumber:215,columnNumber:5},this)}var Fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsColor/index.tsx";function kt({value:e,onChange:t}){const r=["#ee5126","#fceb4d","#90e746","#51c0fa","#7a7a7a","#ffffff"];return g.exports.jsxDEV("div",{className:"screenshots-color",children:r.map(o=>{const i=["screenshots-color-item"];return o===e&&i.push("screenshots-color-active"),g.exports.jsxDEV("div",{className:i.join(" "),style:{backgroundColor:o},onClick:()=>t&&t(o)},o,!1,{fileName:Fe,lineNumber:19,columnNumber:11},this)})},void 0,!1,{fileName:Fe,lineNumber:12,columnNumber:5},this)}var we="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsSizeColor/index.tsx";function ce({size:e,color:t,onSizeChange:r,onColorChange:o}){return g.exports.jsxDEV("div",{className:"screenshots-sizecolor",children:[g.exports.jsxDEV(He,{value:e,onChange:r},void 0,!1,{fileName:we,lineNumber:16,columnNumber:7},this),g.exports.jsxDEV(kt,{value:t,onChange:o},void 0,!1,{fileName:we,lineNumber:17,columnNumber:7},this)]},void 0,!0,{fileName:we,lineNumber:15,columnNumber:5},this)}const wt=`
|
|
2
|
-
min-width: 0 !important;
|
|
3
|
-
width: 0 !important;
|
|
4
|
-
min-height: 0 !important;
|
|
5
|
-
height:0 !important;
|
|
6
|
-
visibility: hidden !important;
|
|
7
|
-
overflow: hidden !important;
|
|
8
|
-
position: absolute !important;
|
|
9
|
-
z-index: -1000 !important;
|
|
10
|
-
top:0 !important;
|
|
11
|
-
right:0 !important;
|
|
12
|
-
`,Dt=["letter-spacing","line-height","padding-top","padding-bottom","font-family","font-weight","font-size","font-variant","text-rendering","text-transform","text-indent","padding-left","padding-right","border-width","box-sizing","white-space","word-break"];let W;function zt(e){const t=window.getComputedStyle(e),r=t.getPropertyValue("box-sizing")||t.getPropertyValue("-moz-box-sizing")||t.getPropertyValue("-webkit-box-sizing"),o=parseFloat(t.getPropertyValue("padding-bottom"))+parseFloat(t.getPropertyValue("padding-top")),i=parseFloat(t.getPropertyValue("border-bottom-width"))+parseFloat(t.getPropertyValue("border-top-width"));return{sizingStyle:Dt.map(s=>`${s}:${t.getPropertyValue(s)}`).join(";"),paddingSize:o,borderSize:i,boxSizing:r}}function Et(e,t,r,o){W||(W=document.createElement("textarea"),W.setAttribute("tab-index","-1"),document.body.appendChild(W));const{paddingSize:i,borderSize:n,boxSizing:s,sizingStyle:a}=zt(e);W.setAttribute("style",`${a};${wt};max-width:${r}px;max-height:${o}px`),W.value=t||" ";let d=W.scrollWidth,u=W.scrollHeight;return s==="border-box"?(d+=n,u+=n):s==="content-box"&&(d-=i,u-=i),{width:Math.min(d,r),height:Math.min(u,o)}}var jt="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsTextarea/index.tsx";function Bt({x:e,y:t,maxWidth:r,maxHeight:o,size:i,color:n,value:s,onChange:a,onBlur:d}){const u=c.exports.useRef(null),h=c.exports.useRef(null),[f,l]=c.exports.useState(0),[p,m]=c.exports.useState(0),v=()=>(u.current||(u.current=document.createElement("div")),u.current);return c.exports.useLayoutEffect(()=>(u.current&&(document.body.appendChild(u.current),requestAnimationFrame(()=>{var N;(N=h.current)==null||N.focus()})),()=>{var N;(N=u.current)==null||N.remove()}),[]),c.exports.useLayoutEffect(()=>{if(!h.current)return;const{width:N,height:w}=Et(h.current,s,r,o);l(N),m(w)},[s,r,o]),_e.exports.createPortal(g.exports.jsxDEV("textarea",{ref:h,className:"screenshots-textarea",style:{left:e,top:t,color:n,width:f,height:p,maxWidth:r,maxHeight:o,fontSize:i,lineHeight:`${i}px`},value:s,onChange:N=>a&&a(N.target.value),onBlur:N=>d&&d(N)},void 0,!1,{fileName:jt,lineNumber:65,columnNumber:5},this),v())}function ae(e){const t=Z();c.exports.useEffect(()=>(t.on("drawselect",e),()=>{t.off("drawselect",e)}),[e,t])}var De="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Text/index.tsx";const ze={3:18,6:32,9:46};function Mt(e,t){const{size:r,color:o,fontFamily:i,x:n,y:s,text:a}=t.data;e.fillStyle=o,e.textAlign="left",e.textBaseline="top",e.font=`${r}px ${i}`;const d=t.editHistory.reduce((u,{data:h})=>({x:u.x+h.x2-h.x1,y:u.y+h.y2-h.y1}),{x:0,y:0});a.split(`
|
|
13
|
-
`).forEach((u,h)=>{e.fillText(u,n+d.x,s+d.y+h*r)})}function Vt(e,t,r){e.textAlign="left",e.textBaseline="top",e.font=`${t.data.size}px ${t.data.fontFamily}`;let o=0,i=0;t.data.text.split(`
|
|
14
|
-
`).forEach(f=>{const l=e.measureText(f);o<l.width&&(o=l.width),i+=t.data.size});const{x:n,y:s}=t.editHistory.reduce((f,{data:l})=>({x:f.x+l.x2-l.x1,y:f.y+l.y2-l.y1}),{x:0,y:0}),a=t.data.x+n,d=t.data.y+s,u=a+o,h=d+i;return r.x>=a&&r.x<=u&&r.y>=d&&r.y<=h}function _t(){const e=L(),[t,r]=H(),[o]=U(),[i,n]=G(),[,s]=A(),a=I(),[d,u]=c.exports.useState(3),[h,f]=c.exports.useState("#ee5126"),l=c.exports.useRef(null),p=c.exports.useRef(null),[m,v]=c.exports.useState(null),[N,w]=c.exports.useState(""),S=i==="Text",z=c.exports.useCallback(()=>{n.set("Text"),s.set("default")},[n,s]),x=c.exports.useCallback(()=>{S||(z(),r.clearSelect())},[S,z,r]),b=c.exports.useCallback(B=>{l.current&&(l.current.data.size=ze[B]),u(B)},[]),y=c.exports.useCallback(B=>{l.current&&(l.current.data.color=B),f(B)},[]),C=c.exports.useCallback(B=>{w(B),S&&l.current&&(l.current.data.text=B)},[S]),k=c.exports.useCallback(()=>{l.current&&l.current.data.text&&r.push(l.current),l.current=null,w(""),v(null)},[r]),E=c.exports.useCallback((B,_)=>{B.name==="Text"&&(z(),p.current={type:j.Edit,data:{x1:_.clientX,y1:_.clientY,x2:_.clientX,y2:_.clientY},source:B},r.select(B))},[z,r]),D=c.exports.useCallback(B=>{if(!S||!a.current||l.current||!o)return;const{left:_,top:ge}=a.current.canvas.getBoundingClientRect(),ve=window.getComputedStyle(a.current.canvas).fontFamily,ne=B.clientX-_,re=B.clientY-ge;l.current={name:"Text",type:j.Source,data:{size:ze[d],color:h,fontFamily:ve,x:ne,y:re,text:""},editHistory:[],draw:Mt,isHit:Vt},v({x:B.clientX,y:B.clientY,maxWidth:o.width-ne,maxHeight:o.height-re})},[S,d,h,o,a]),R=c.exports.useCallback(B=>{!S||p.current&&(p.current.data.x2=B.clientX,p.current.data.y2=B.clientY,t.top!==p.current?(p.current.source.editHistory.push(p.current),r.push(p.current)):r.set(t))},[S,t,r]),O=c.exports.useCallback(()=>{!S||(p.current=null)},[S]);return ae(E),ee(D),te(R),se(O),g.exports.jsxDEV(g.exports.Fragment,{children:[g.exports.jsxDEV(X,{title:e.operation_text_title,icon:"icon-text",checked:S,onClick:x,option:g.exports.jsxDEV(ce,{size:d,color:h,onSizeChange:b,onColorChange:y},void 0,!1,{fileName:De,lineNumber:261,columnNumber:11},this)},void 0,!1,{fileName:De,lineNumber:255,columnNumber:7},this),S&&m&&g.exports.jsxDEV(Bt,{x:m.x,y:m.y,maxWidth:m.maxWidth,maxHeight:m.maxHeight,size:ze[d],color:h,value:N,onChange:C,onBlur:k},void 0,!1,{fileName:De,lineNumber:265,columnNumber:9},this)]},void 0,!0)}const Ye=4;function M(e,t,r){e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.arc(t,r,Ye,0,2*Math.PI),e.fill(),e.stroke()}function be(e,t,r){t.draw(e,t);const{data:o}=e.getImageData(r.x,r.y,1,1);return o.some(i=>i!==0)}function V(e,t,r){if(!e)return!1;const{left:o,top:i}=e.getBoundingClientRect(),n=t.clientX-o,s=t.clientY-i;return(r.x-n)**2+(r.y-s)**2<Ye**2}function $t(e,t){const{size:r,color:o,points:i}=t.data;e.lineCap="round",e.lineJoin="round",e.lineWidth=r,e.strokeStyle=o;const n=t.editHistory.reduce((s,{data:a})=>({x:s.x+a.x2-a.x1,y:s.y+a.y2-a.y1}),{x:0,y:0});e.beginPath(),i.forEach((s,a)=>{a===0?e.moveTo(s.x+n.x,s.y+n.y):e.lineTo(s.x+n.x,s.y+n.y)}),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.beginPath(),i.forEach((s,a)=>{a===0?e.moveTo(s.x+n.x,s.y+n.y):e.lineTo(s.x+n.x,s.y+n.y)}),e.stroke())}var Pe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Brush/index.tsx";function Lt(){const e=L(),[,t]=A(),[r,o]=G(),i=I(),[n,s]=H(),[a,d]=c.exports.useState(3),[u,h]=c.exports.useState("#ee5126"),f=c.exports.useRef(null),l=c.exports.useRef(null),p=r==="Brush",m=c.exports.useCallback(()=>{o.set("Brush"),t.set("default")},[o,t]),v=c.exports.useCallback(()=>{p||(m(),s.clearSelect())},[p,m,s]),N=c.exports.useCallback((x,b)=>{x.name==="Brush"&&(m(),l.current={type:j.Edit,data:{x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:x},s.select(x))},[m,s]),w=c.exports.useCallback(x=>{if(!p||f.current||!i.current)return;const{left:b,top:y}=i.current.canvas.getBoundingClientRect();f.current={name:"Brush",type:j.Source,data:{size:a,color:u,points:[{x:x.clientX-b,y:x.clientY-y}]},editHistory:[],draw:$t,isHit:be}},[p,i,a,u]),S=c.exports.useCallback(x=>{if(!(!p||!i.current)){if(l.current)l.current.data.x2=x.clientX,l.current.data.y2=x.clientY,n.top!==l.current?(l.current.source.editHistory.push(l.current),s.push(l.current)):s.set(n);else if(f.current){const{left:b,top:y}=i.current.canvas.getBoundingClientRect();f.current.data.points.push({x:x.clientX-b,y:x.clientY-y}),n.top!==f.current?s.push(f.current):s.set(n)}}},[p,n,i,s]),z=c.exports.useCallback(()=>{!p||(f.current&&s.clearSelect(),f.current=null,l.current=null)},[p,s]);return ae(N),ee(w),te(S),se(z),g.exports.jsxDEV(X,{title:e.operation_brush_title,icon:"icon-brush",checked:p,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:h},void 0,!1,{fileName:Pe,lineNumber:166,columnNumber:15},this)},void 0,!1,{fileName:Pe,lineNumber:161,columnNumber:5},this)}function Te(e){let{x1:t,y1:r,x2:o,y2:i}=e.data;return e.editHistory.forEach(({data:n})=>{const s=n.x2-n.x1,a=n.y2-n.y1;n.type===ue.Move?(t+=s,r+=a,o+=s,i+=a):n.type===ue.MoveStart?(t+=s,r+=a):n.type===ue.MoveEnd&&(o+=s,i+=a)}),pe(T({},e.data),{x1:t,x2:o,y1:r,y2:i})}function Ht(e,t){const{size:r,color:o,x1:i,x2:n,y1:s,y2:a}=Te(t);e.lineCap="round",e.lineJoin="bevel",e.lineWidth=r,e.strokeStyle=o;const d=n-i,u=a-s,h=r*3,f=Math.atan2(u,d);e.beginPath(),e.moveTo(i,s),e.lineTo(n,a),e.lineTo(n-h*Math.cos(f-Math.PI/6),a-h*Math.sin(f-Math.PI/6)),e.moveTo(n,a),e.lineTo(n-h*Math.cos(f+Math.PI/6),a-h*Math.sin(f+Math.PI/6)),e.stroke(),t.isSelected&&(M(e,i,s),M(e,n,a))}var Ue="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Arrow/index.tsx",ue;(function(e){e[e.Move=0]="Move",e[e.MoveStart=1]="MoveStart",e[e.MoveEnd=2]="MoveEnd"})(ue||(ue={}));function Xt(){const e=L(),[,t]=A(),[r,o]=G(),[i,n]=H(),s=I(),[a,d]=c.exports.useState(3),[u,h]=c.exports.useState("#ee5126"),f=c.exports.useRef(null),l=c.exports.useRef(null),p=r==="Arrow",m=c.exports.useCallback(()=>{o.set("Arrow"),t.set("default")},[o,t]),v=c.exports.useCallback(()=>{p||(m(),n.clearSelect())},[p,m,n]),N=c.exports.useCallback((x,b)=>{if(x.name!=="Arrow"||!s.current)return;const y=x;m();const{x1:C,y1:k,x2:E,y2:D}=Te(y);let R=0;V(s.current.canvas,b,{x:C,y:k})?R=1:V(s.current.canvas,b,{x:E,y:D})&&(R=2),l.current={type:j.Edit,data:{type:R,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:y},n.select(x)},[s,m,n]),w=c.exports.useCallback(x=>{if(!p||f.current||!s.current)return;const{left:b,top:y}=s.current.canvas.getBoundingClientRect();f.current={name:"Arrow",type:j.Source,data:{size:a,color:u,x1:x.clientX-b,y1:x.clientY-y,x2:x.clientX-b,y2:x.clientY-y},editHistory:[],draw:Ht,isHit:be}},[p,u,a,s]),S=c.exports.useCallback(x=>{if(!(!p||!s.current)){if(l.current)l.current.data.x2=x.clientX,l.current.data.y2=x.clientY,i.top!==l.current?(l.current.source.editHistory.push(l.current),n.push(l.current)):n.set(i);else if(f.current){const{left:b,top:y}=s.current.canvas.getBoundingClientRect();f.current.data.x2=x.clientX-b,f.current.data.y2=x.clientY-y,i.top!==f.current?n.push(f.current):n.set(i)}}},[p,i,s,n]),z=c.exports.useCallback(()=>{!p||(f.current&&n.clearSelect(),f.current=null,l.current=null)},[p,n]);return ae(N),ee(w),te(S),se(z),g.exports.jsxDEV(X,{title:e.operation_arrow_title,icon:"icon-arrow",checked:p,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:h},void 0,!1,{fileName:Ue,lineNumber:190,columnNumber:15},this)},void 0,!1,{fileName:Ue,lineNumber:185,columnNumber:5},this)}function Ae(e){let{x1:t,y1:r,x2:o,y2:i}=e.data;return e.editHistory.forEach(({data:n})=>{const s=n.x2-n.x1,a=n.y2-n.y1;n.type===F.Move?(t+=s,r+=a,o+=s,i+=a):n.type===F.ResizeTop?r+=a:n.type===F.ResizeRightTop?(o+=s,r+=a):n.type===F.ResizeRight?o+=s:n.type===F.ResizeRightBottom?(o+=s,i+=a):n.type===F.ResizeBottom?i+=a:n.type===F.ResizeLeftBottom?(t+=s,i+=a):n.type===F.ResizeLeft?t+=s:n.type===F.ResizeLeftTop&&(t+=s,r+=a)}),pe(T({},e.data),{x1:t,x2:o,y1:r,y2:i})}function Ft(e,t){const{size:r,color:o,x1:i,y1:n,x2:s,y2:a}=Ae(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=r,e.strokeStyle=o;const d=(i+s)/2,u=(n+a)/2,h=Math.abs(s-i)/2,f=Math.abs(a-n)/2,l=.5522848,p=h*l,m=f*l;e.beginPath(),e.moveTo(d-h,u),e.bezierCurveTo(d-h,u-m,d-p,u-f,d,u-f),e.bezierCurveTo(d+p,u-f,d+h,u-m,d+h,u),e.bezierCurveTo(d+h,u+m,d+p,u+f,d,u+f),e.bezierCurveTo(d-p,u+f,d-h,u+m,d-h,u),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",e.beginPath(),e.moveTo(i,n),e.lineTo(s,n),e.lineTo(s,a),e.lineTo(i,a),e.closePath(),e.stroke(),M(e,(i+s)/2,n),M(e,s,n),M(e,s,(n+a)/2),M(e,s,a),M(e,(i+s)/2,a),M(e,i,a),M(e,i,(n+a)/2),M(e,i,n))}var Ge="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Ellipse/index.tsx",F;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(F||(F={}));function Yt(){const e=L(),[t,r]=H(),[o,i]=G(),[,n]=A(),s=I(),[a,d]=c.exports.useState(3),[u,h]=c.exports.useState("#ee5126"),f=c.exports.useRef(null),l=c.exports.useRef(null),p=o==="Ellipse",m=c.exports.useCallback(()=>{i.set("Ellipse"),n.set("crosshair")},[i,n]),v=c.exports.useCallback(()=>{p||(m(),r.clearSelect())},[p,m,r]),N=c.exports.useCallback((x,b)=>{if(x.name!=="Ellipse"||!s.current)return;const y=x;m();const{x1:C,y1:k,x2:E,y2:D}=Ae(y);let R=0;V(s.current.canvas,b,{x:(C+E)/2,y:k})?R=1:V(s.current.canvas,b,{x:E,y:k})?R=2:V(s.current.canvas,b,{x:E,y:(k+D)/2})?R=3:V(s.current.canvas,b,{x:E,y:D})?R=4:V(s.current.canvas,b,{x:(C+E)/2,y:D})?R=5:V(s.current.canvas,b,{x:C,y:D})?R=6:V(s.current.canvas,b,{x:C,y:(k+D)/2})?R=7:V(s.current.canvas,b,{x:C,y:k})&&(R=8),l.current={type:j.Edit,data:{type:R,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:y},r.select(x)},[s,m,r]),w=c.exports.useCallback(x=>{if(!p||!s.current||f.current)return;const{left:b,top:y}=s.current.canvas.getBoundingClientRect(),C=x.clientX-b,k=x.clientY-y;f.current={name:"Ellipse",type:j.Source,data:{size:a,color:u,x1:C,y1:k,x2:C,y2:k},editHistory:[],draw:Ft,isHit:be}},[p,a,u,s]),S=c.exports.useCallback(x=>{if(!(!p||!s.current)){if(l.current)l.current.data.x2=x.clientX,l.current.data.y2=x.clientY,t.top!==l.current?(l.current.source.editHistory.push(l.current),r.push(l.current)):r.set(t);else if(f.current){const{left:b,top:y}=s.current.canvas.getBoundingClientRect();f.current.data.x2=x.clientX-b,f.current.data.y2=x.clientY-y,t.top!==f.current?r.push(f.current):r.set(t)}}},[p,s,t,r]),z=c.exports.useCallback(()=>{!p||(f.current&&r.clearSelect(),f.current=null,l.current=null)},[p,r]);return ae(N),ee(w),te(S),se(z),g.exports.jsxDEV(X,{title:e.operation_ellipse_title,icon:"icon-ellipse",checked:p,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:h},void 0,!1,{fileName:Ge,lineNumber:242,columnNumber:15},this)},void 0,!1,{fileName:Ge,lineNumber:237,columnNumber:5},this)}function Ie(e){let{x1:t,y1:r,x2:o,y2:i}=e.data;return e.editHistory.forEach(({data:n})=>{const s=n.x2-n.x1,a=n.y2-n.y1;n.type===Y.Move?(t+=s,r+=a,o+=s,i+=a):n.type===Y.ResizeTop?r+=a:n.type===Y.ResizeRightTop?(o+=s,r+=a):n.type===Y.ResizeRight?o+=s:n.type===Y.ResizeRightBottom?(o+=s,i+=a):n.type===Y.ResizeBottom?i+=a:n.type===Y.ResizeLeftBottom?(t+=s,i+=a):n.type===Y.ResizeLeft?t+=s:n.type===Y.ResizeLeftTop&&(t+=s,r+=a)}),pe(T({},e.data),{x1:t,x2:o,y1:r,y2:i})}function Pt(e,t){const{size:r,color:o,x1:i,y1:n,x2:s,y2:a}=Ie(t);e.lineCap="butt",e.lineJoin="miter",e.lineWidth=r,e.strokeStyle=o,e.beginPath(),e.moveTo(i,n),e.lineTo(s,n),e.lineTo(s,a),e.lineTo(i,a),e.closePath(),e.stroke(),t.isSelected&&(e.lineWidth=1,e.strokeStyle="#000000",e.fillStyle="#ffffff",M(e,(i+s)/2,n),M(e,s,n),M(e,s,(n+a)/2),M(e,s,a),M(e,(i+s)/2,a),M(e,i,a),M(e,i,(n+a)/2),M(e,i,n))}var We="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/operations/Rectangle/index.tsx",Y;(function(e){e[e.Move=0]="Move",e[e.ResizeTop=1]="ResizeTop",e[e.ResizeRightTop=2]="ResizeRightTop",e[e.ResizeRight=3]="ResizeRight",e[e.ResizeRightBottom=4]="ResizeRightBottom",e[e.ResizeBottom=5]="ResizeBottom",e[e.ResizeLeftBottom=6]="ResizeLeftBottom",e[e.ResizeLeft=7]="ResizeLeft",e[e.ResizeLeftTop=8]="ResizeLeftTop"})(Y||(Y={}));function Tt(){const e=L(),[t,r]=H(),[o,i]=G(),[,n]=A(),s=I(),[a,d]=c.exports.useState(3),[u,h]=c.exports.useState("#ee5126"),f=c.exports.useRef(null),l=c.exports.useRef(null),p=o==="Rectangle",m=c.exports.useCallback(()=>{i.set("Rectangle"),n.set("crosshair")},[i,n]),v=c.exports.useCallback(()=>{p||(m(),r.clearSelect())},[p,m,r]),N=c.exports.useCallback((x,b)=>{if(x.name!=="Rectangle"||!s.current)return;const y=x;m();const{x1:C,y1:k,x2:E,y2:D}=Ie(y);let R=0;V(s.current.canvas,b,{x:(C+E)/2,y:k})?R=1:V(s.current.canvas,b,{x:E,y:k})?R=2:V(s.current.canvas,b,{x:E,y:(k+D)/2})?R=3:V(s.current.canvas,b,{x:E,y:D})?R=4:V(s.current.canvas,b,{x:(C+E)/2,y:D})?R=5:V(s.current.canvas,b,{x:C,y:D})?R=6:V(s.current.canvas,b,{x:C,y:(k+D)/2})?R=7:V(s.current.canvas,b,{x:C,y:k})&&(R=8),l.current={type:j.Edit,data:{type:R,x1:b.clientX,y1:b.clientY,x2:b.clientX,y2:b.clientY},source:x},r.select(x)},[s,m,r]),w=c.exports.useCallback(x=>{if(!p||!s.current||f.current)return;const{left:b,top:y}=s.current.canvas.getBoundingClientRect(),C=x.clientX-b,k=x.clientY-y;f.current={name:"Rectangle",type:j.Source,data:{size:a,color:u,x1:C,y1:k,x2:C,y2:k},editHistory:[],draw:Pt,isHit:be}},[p,a,u,s]),S=c.exports.useCallback(x=>{if(!(!p||!s.current)){if(l.current)l.current.data.x2=x.clientX,l.current.data.y2=x.clientY,t.top!==l.current?(l.current.source.editHistory.push(l.current),r.push(l.current)):r.set(t);else if(f.current){const{left:b,top:y}=s.current.canvas.getBoundingClientRect(),C=f.current.data;C.x2=x.clientX-b,C.y2=x.clientY-y,t.top!==f.current?r.push(f.current):r.set(t)}}},[p,s,t,r]),z=c.exports.useCallback(()=>{!p||(f.current&&r.clearSelect(),f.current=null,l.current=null)},[p,r]);return ae(N),ee(w),te(S),se(z),g.exports.jsxDEV(X,{title:e.operation_rectangle_title,icon:"icon-rectangle",checked:p,onClick:v,option:g.exports.jsxDEV(ce,{size:a,color:u,onSizeChange:d,onColorChange:h},void 0,!1,{fileName:We,lineNumber:242,columnNumber:15},this)},void 0,!1,{fileName:We,lineNumber:237,columnNumber:5},this)}var Ut=[Tt,Yt,Xt,Lt,_t,Rt,"|",Ct,yt,"|",gt,xt,mt];var le="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/ScreenshotsOperations/index.tsx";const Oe=Ve.createContext(null);function At(){const{width:e,height:t}=$(),[r]=U(),[o,i]=c.exports.useState(null),[n,s]=c.exports.useState(null),a=c.exports.useRef(null),d=c.exports.useCallback(h=>{h.stopPropagation()},[]),u=c.exports.useCallback(h=>{h.preventDefault(),h.stopPropagation()},[]);return c.exports.useEffect(()=>{if(!r||!a.current)return;const h=a.current.getBoundingClientRect();let f=r.x+r.width-h.width,l=r.y+r.height+10;f<0&&(f=0),f>e-h.width&&(f=e-h.width),l>t-h.height&&(l=t-h.height-10),((n==null?void 0:n.x)!==f||n.y!==l)&&s({x:f,y:l}),((o==null?void 0:o.x)!==h.x||o.y!==h.y||o.width!==h.width||o.height!==h.height)&&i({x:h.x,y:h.y,width:h.width,height:h.height})}),r?g.exports.jsxDEV(Oe.Provider,{value:o,children:g.exports.jsxDEV("div",{ref:a,className:"screenshots-operations",style:{visibility:n?"visible":"hidden",left:n==null?void 0:n.x,top:n==null?void 0:n.y},onDoubleClick:d,onContextMenu:u,children:g.exports.jsxDEV("div",{className:"screenshots-operations-buttons",children:Ut.map((h,f)=>h==="|"?g.exports.jsxDEV("div",{className:"screenshots-operations-divider"},f,!1,{fileName:le,lineNumber:91,columnNumber:22},this):g.exports.jsxDEV(h,{},f,!1,{fileName:le,lineNumber:93,columnNumber:22},this))},void 0,!1,{fileName:le,lineNumber:88,columnNumber:9},this)},void 0,!1,{fileName:le,lineNumber:77,columnNumber:7},this)},void 0,!1,{fileName:le,lineNumber:76,columnNumber:5},this):null}function Gt(e){const[t,r]=c.exports.useState(null);return c.exports.useEffect(()=>{if(r(null),e==null)return;const o=document.createElement("img"),i=()=>r(o),n=()=>r(null);return o.addEventListener("load",i),o.addEventListener("error",n),o.src=e,()=>{o.removeEventListener("load",i),o.removeEventListener("error",n)}},[e]),t}var fe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/Screenshots/index.tsx";function It(s){var a=s,{url:e,width:t,height:r,lang:o,className:i}=a,n=Me(a,["url","width","height","lang","className"]);const d=Gt(e),u=c.exports.useRef(null),h=c.exports.useRef({}),[f,l]=c.exports.useState({index:-1,stack:[]}),[p,m]=c.exports.useState(null),[v,N]=c.exports.useState("move"),[w,S]=c.exports.useState(void 0),z={url:e,width:t,height:r,image:d,lang:T(T({},$e),o),emiterRef:h,canvasContextRef:u,history:f,bounds:p,cursor:v,operation:w},x=c.exports.useCallback((D,...R)=>{const O=n[D];typeof O=="function"&&O(...R)},[n]),b={call:x,setHistory:l,setBounds:m,setCursor:N,setOperation:S},y=["screenshots"];i&&y.push(i);const C=()=>{h.current={},l({index:-1,stack:[]}),m(null),N("move"),S(void 0)},k=c.exports.useCallback(D=>{D.button!==0||!p||!u.current||u.current.canvas.toBlob(R=>{x("onOk",R,p),C()},"image/png")},[p,x]),E=c.exports.useCallback(D=>{D.button===2&&(D.preventDefault(),x("onCancel"),C())},[x]);return c.exports.useLayoutEffect(()=>{C()},[e]),g.exports.jsxDEV(ye.Provider,{value:{store:z,dispatcher:b},children:g.exports.jsxDEV("div",{className:y.join(" "),style:{width:t,height:r},onDoubleClick:k,onContextMenu:E,children:[g.exports.jsxDEV(ot,{},void 0,!1,{fileName:fe,lineNumber:123,columnNumber:9},this),g.exports.jsxDEV(ft,{ref:u},void 0,!1,{fileName:fe,lineNumber:124,columnNumber:9},this),g.exports.jsxDEV(At,{},void 0,!1,{fileName:fe,lineNumber:125,columnNumber:9},this)]},void 0,!0,{fileName:fe,lineNumber:117,columnNumber:7},this)},void 0,!1,{fileName:fe,lineNumber:116,columnNumber:5},this)}var qe="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/electron/app.tsx";function Wt(){const[e,t]=c.exports.useState(void 0),[r,o]=c.exports.useState(window.innerWidth),[i,n]=c.exports.useState(window.innerHeight),[s,a]=c.exports.useState(void 0),[d,u]=c.exports.useState(void 0),h=c.exports.useCallback(async(p,m)=>{!s||!p||window.screenshots.save(await p.arrayBuffer(),{bounds:m,display:s})},[s]),f=c.exports.useCallback(()=>{window.screenshots.cancel()},[]),l=c.exports.useCallback(async(p,m)=>{!s||!p||window.screenshots.ok(await p.arrayBuffer(),{bounds:m,display:s})},[s]);return c.exports.useEffect(()=>{const p=N=>{u(N)},m=(N,w)=>{a(N),t(w)},v=()=>{t(void 0),a(void 0),requestAnimationFrame(()=>window.screenshots.reset())};return window.screenshots.on("setLang",p),window.screenshots.on("capture",m),window.screenshots.on("reset",v),window.screenshots.ready(),()=>{window.screenshots.off("capture",m),window.screenshots.off("setLang",p),window.screenshots.off("reset",v)}},[]),c.exports.useEffect(()=>{const p=()=>{o(window.innerWidth),n(window.innerHeight)},m=({code:v})=>{v==="Escape"&&f()};return window.addEventListener("resize",p),window.addEventListener("keyup",m),()=>{window.removeEventListener("resize",p),window.removeEventListener("keyup",m)}},[f]),g.exports.jsxDEV("div",{className:"body",children:g.exports.jsxDEV(It,{url:e,width:r,height:i,lang:d,onSave:h,onCancel:f,onOk:l},void 0,!1,{fileName:qe,lineNumber:97,columnNumber:7},this)},void 0,!1,{fileName:qe,lineNumber:96,columnNumber:5},this)}var Je="/Users/nashaofu/Documents/GitHub/screenshots/packages/react-screenshots/src/electron/index.tsx";tt.render(g.exports.jsxDEV(c.exports.StrictMode,{children:g.exports.jsxDEV(Wt,{},void 0,!1,{fileName:Je,lineNumber:7,columnNumber:5},globalThis)},void 0,!1,{fileName:Je,lineNumber:6,columnNumber:3},globalThis),document.getElementById("app"));
|