amotify 0.2.220 → 0.2.221

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.
@@ -1 +1 @@
1
- import{b as H,c as K,e as z}from"../chunk-C5N2D3ZX.js";import{jsx as i,jsxs as d}from"react/jsx-runtime";import S,{UUID as J,useStore as U}from"jmini";import{$$fromRoot as Z}from"../@utils";import{useState as N,useEffect as O}from"react";import{Box as L,FAI as M,Column as k}from"../atoms";import{Row as w,Literal as _}from"../mols";import{Button as P}from"./Button";import A from"./Sheet";import V from"./Loader";import $ from"./Input";import{faPalette as Q}from"@fortawesome/free-solid-svg-icons/faPalette";import{faBarsStaggered as ee}from"@fortawesome/free-solid-svg-icons/faBarsStaggered";import{faRotateLeft as te}from"@fortawesome/free-solid-svg-icons/faRotateLeft";import{faRotateRight as ae}from"@fortawesome/free-solid-svg-icons/faRotateRight";import{CropperClasses as X}from"../@styles/componentClasses";import Y from"./Tooltips";class re{constructor(a){this.set_scale=a.set_scale,this.val_file=a.val_file,this.develops=a.develops;{let[c,p]=S.is.array(a.use)&&a.use||a.use.split(":").map(o=>Number(o)),g=c/p;this.usage={w:c,h:p,aspect:g}}this.componentId=a.componentId,this.scale={current:a.scale.default,default:a.scale.default,min:a.scale.min,max:a.scale.max};let s=a.canvas;this.Canvas={elm:s,ctx:s.getContext("2d")};let e=a.picture.image,{width:r,height:t}=e,n=r/t;this.Picture={elm:e,originDataUrl:e.src,aspect:n,revisedAspect:1,rotate:a.picture.rotate,grayScale:a.picture.grayScale,tone:a.picture.tone},this.pst={frame:{x:0,y:0,w:0,h:0,aspect:1},outImage:{x:0,y:0,w:0,h:0},imageX:r/2,imageY:t/2,centerX:0,centerY:0},this.dragEffectInfo={origin:{x:0,y:0},frameExpandRate:{x:0,y:0}},this.pinchEffectInfo={origin:{x:0,y:0,scale:this.scale.current}},this.frameSizing(),this.modifyImage()}frameSizing(){let a=this.Canvas.elm,s=this.Picture.elm,e=0,r=0;if(this.usage.aspect==1){let o=a.width*.6666666666666666,l=a.height*(2/3);r=e=Math.min(o,l)}else this.usage.aspect>1?(e=a.width*(8/10),r=e/this.usage.aspect):(r=a.height*(8/10),e=r*this.usage.aspect);let{width:t,height:n}=s,c=(a.width-e)/2,p=(a.height-r)/2,g=e/r;this.pst={frame:{x:c,y:p,w:e,h:r,aspect:g},outImage:{x:0,y:0,w:0,h:0},imageX:t/2,imageY:n/2,centerX:a.width/2,centerY:a.height/2}}dragEffect(a){let{eventType:s,x:e,y:r}=a;if(s=="start"){let t=this.Canvas.elm.position();this.dragEffectInfo={origin:{x:e,y:r},frameExpandRate:{x:this.Canvas.elm.width/t.width,y:this.Canvas.elm.height/t.height}}}else{let{origin:t,frameExpandRate:n}=this.dragEffectInfo,c=t.x-e,p=t.y-r,g=this.scale.current*this.Picture.revisedAspect/100,o=c/g*n.x,l=p/g*n.y;s=="move"?this.drawImage(this.pst.imageX+o,this.pst.imageY+l):s=="end"&&this.drawImage(this.pst.imageX+=o,this.pst.imageY+=l)}}pinchEffect(a){let{eventType:s,event:e}=a,{x:r,y:t}=S.getCursor(e.touches[0]),{x:n,y:c}=S.getCursor(e.touches[1]),p=n-r,g=c-t;if(s=="start")this.pinchEffectInfo.origin={x:p,y:g,scale:this.scale.current};else if(s=="move"){let{origin:o}=this.pinchEffectInfo,l=Math.sqrt(Math.pow(o.x,2)+Math.pow(o.y,2)),v=Math.sqrt(Math.pow(p,2)+Math.pow(g,2))/l,C=Number(o.scale*v);this.set_scale(C)}}updateScale(a){let s=a;s=Math.max(s,this.scale.min),s=Math.min(s,this.scale.max),this.scale.current=s,this.drawImage()}updateFilter(a){this.Picture.grayScale=a.grayScale,this.Picture.tone=a.tone,this.Picture.rotate=a.rotate,this.modifyImage()}modifyImage(){return z(this,null,function*(){let{grayScale:a,tone:s,rotate:e}=this.Picture;const r=document.createElement("canvas");let t=r.getContext("2d"),n=yield S.ImageLoader(this.Picture.originDataUrl),c=n.width,p=n.height;(e==90||e==270)&&(c=n.height,p=n.width),r.width=c,r.height=p,a&&(t.filter="grayscale("+a+"%)"),e&&(t.translate(c/2,p/2),t.rotate(e*Math.PI/180),[90,270].includes(e)?t.translate(-p/2,-c/2):t.translate(-c/2,-p/2)),t.drawImage(n,0,0,n.width,n.height);let g=t.getImageData(0,0,r.width,r.height),o=g.data;{a/=100;let C=[[255,255,255],[255,200,100],[170,170,255],[240,200,145],[128,255,255],[255,128,255],[255,255,128],[128,158,169],[128,112,162],[50,192,87],[246,100,140]][s],x=C[0]/255,R=C[1]/255,m=C[2]/255;for(let h=0;h<p;h++)for(let u=0;u<c;u++){var l=(h*c+u)*4;if(a){let E=.3*o[l]+.59*o[l+1]+.11*o[l+2];for(var y=0;y<3;y++){let D=o[l+y];o[l+y]=D+(E-D)*a}}o[l]*=x,o[l+1]*=R,o[l+2]*=m}}t.putImageData(g,0,0);let v=r.toDataURL("image/jpeg");{let C=yield S.ImageLoader(v),{width:x,height:R}=C,m=x/R;this.Picture=K(H({},this.Picture),{elm:C,aspect:m,revisedAspect:this.pst.frame.aspect>m?this.pst.frame.w/x:this.pst.frame.h/R})}this.drawImage()})}drawImage(a,s){let{Canvas:{ctx:e,elm:r},pst:{frame:t}}=this,n=a||this.pst.imageX,c=s||this.pst.imageY;{let p=this.scale.current/100,g=this.Picture.revisedAspect*p,o=this.pst.centerX-n*g,l=this.pst.centerY-c*g,y=this.Picture.elm.width*g,v=this.Picture.elm.height*g;{let C=this.pst.frame.x+this.pst.frame.w-y,x=this.pst.frame.x,R=this.pst.frame.y+this.pst.frame.h-v,m=this.pst.frame.y,h=0;o<C&&(h=o-C),o>x&&(h=o-x);let u=0;l<R&&(u=l-R),l>m&&(u=l-m),this.dragEffectInfo.origin.x+=h/2/this.dragEffectInfo.frameExpandRate.x,this.dragEffectInfo.origin.y+=u/2/this.dragEffectInfo.frameExpandRate.y,o=Math.min(Math.max(o,C),x),l=Math.min(Math.max(l,R),m)}this.pst.outImage={x:o,y:l,w:y,h:v},e.clearRect(0,0,this.Canvas.elm.width,this.Canvas.elm.height),e.drawImage(this.Picture.elm,0,0,this.Picture.elm.width,this.Picture.elm.height,o,l,y,v)}{if(this.usage.aspect==1){e.fillStyle="rgba( 20,24,20,.3 )",e.beginPath();let o=r.width/3*2,l=r.height/3*2,y=Math.min(o,l),v=Math.max(o,l);e.arc(r.width/2,r.height/2,v*1.41,0,Math.PI*2,!0),e.arc(r.width/2,r.height/2,y/2,0,Math.PI*2,!1),e.closePath(),e.fill()}else e.fillStyle="rgba( 20,24,20,.3 )";e.beginPath(),e.moveTo(0,0),e.lineTo(r.width,0),e.lineTo(r.width,r.height),e.lineTo(0,r.height),e.lineTo(0,0),e.closePath(),e.lineTo(t.x,t.y),e.lineTo(t.x,t.y+t.h),e.lineTo(t.x+t.w,t.y+t.h),e.lineTo(t.x+t.w,t.y),e.lineTo(t.x,t.y),e.fill();let g=S(document.body).getStyleProperty("--color-theme-hsl");e.lineWidth=4,e.strokeStyle=`hsla( ${g},1 )`,e.strokeRect(t.x,t.y,t.w,t.h)}}export(){return z(this,null,function*(){let{Canvas:a,develops:s,Picture:e,pst:{outImage:r,frame:t}}=this,n=r.w/e.elm.width,c=r.h/e.elm.height,p=(t.x-r.x)/n,g=(t.x-r.x+t.w)/n,o=(t.y-r.y)/c,l=(t.y-r.y+t.h)/c,y=Array.from({length:s.length}),v="image/jpeg";for(let C=0;C<s.length;C++){let{size:x,maxSize:R}=s[C];R=R||{S:1024*20,R:1024*100,L:1024*350}[x];let m={S:140,R:600,L:1200}[x],h=m;this.usage.aspect>1?h=m/this.usage.aspect:m=h*this.usage.aspect;let u=document.createElement("canvas");u.width=m,u.height=h;let E=u.getContext("2d");if(!E)return;E.clearRect(0,0,m,h),E.drawImage(this.Picture.elm,p,o,g-p,l-o,0,0,m,h);let D=u.toDataURL(v),b=yield D.toBlob(v);if(!b)return;if(b.size>=R){let F=R/b.size;if(D=u.toDataURL(v,F*.92),b=yield D.toBlob(v),!b)return}let W=new File([b],this.val_file.name,{type:v});y[C]=W}return y})}}const q={Core:f=>{let{val_file:a,options:s,finishedCallback:e,abortCallback:r}=f,{use:t,develops:n=[]}=s,[c]=N(J());const p={scale:{default:120,min:100,max:400},rotate:0,grayScale:0,tone:0};let[g,o]=N(p.scale.default),[l,y]=N(p.rotate),[v,C]=N(p.grayScale),[x,R]=N(p.tone);return O(()=>{let m="CropperResize";return S(window).addEvent({eventType:"resize",eventID:m,callback:()=>{S.interval.once(()=>{var F;let h=Z("#Canvas-"+c)[0];if(!h)return;let u=(F=U.get(c))==null?void 0:F.Instance;if(!u)return;let E=h.position(),D=E.width/E.height;h.width=2048,h.height=2048/D;let{width:b,height:W}=h;u.pst.centerX=b/2,u.pst.centerY=W/2,u.frameSizing(),u.modifyImage()},250,"CropperResize")}}),()=>{S(window).removeEvent(m)}},[]),O(()=>{U.set({[c]:{}}),z(void 0,null,function*(){V.fn.corner.active(),yield S.pending(()=>{},400);let{target:m}=yield a.convert();if(!m)return;let h=m.result,u=Z("#Canvas-"+c)[0];if(!u)return;let E=u.position(),D=E.width/E.height;u.width=2048,u.height=2048/D;let b=new re({set_scale:o,val_file:a,develops:n,use:t,scale:p.scale,componentId:c,canvas:u,picture:{image:yield S.ImageLoader(h),grayScale:p.grayScale,tone:p.tone,rotate:p.rotate}});U.set({[c]:{Instance:b}});const W=function(I){if(I.preventDefault(),I.touches&&I.touches.length>1)b.pinchEffect({eventType:"start",event:I}),S(document).addEvent({eventType:"touchmove",eventID:"CropperEffectMove",options:{passive:!1},callback:T=>{T.preventDefault(),b.pinchEffect({eventType:"move",event:T})}}).addEvent({eventType:"touchend",eventID:"CropperEffectEnd",options:{passive:!1},callback:G});else{b.dragEffect(H({eventType:"start"},S.getCursor(I)));let{type:T}=I;S(document).addEvent({eventType:T=="touchstart"?"touchmove":"mousemove",eventID:"CropperEffectMove",options:{passive:!1},callback:B=>{F("move",B)}}).addEvent({eventType:T=="touchstart"?"touchend":"mouseup",eventID:"CropperEffectEnd",options:{passive:!1},callback:B=>{F("end",B),G(B)}})}},F=function(I,T){T.preventDefault(),b.dragEffect(H({eventType:I},S.getCursor(T)))},G=function(I){I.preventDefault(),S(document).removeEvent(["CropperEffectMove","CropperEffectEnd"])};S(u).removeEvent(["CropperMouseWheel","CropperTouchStart","CropperMouseDown"]).addEvent({eventID:"CropperMouseWheel",eventType:"wheel",callback:I=>{I.preventDefault();let T=Number(I.wheelDelta*.04),B=b.scale.current+T;B=Math.max(B,b.scale.min),B=Math.min(B,b.scale.max),o(B)},options:{passive:!1}}).addEvent({eventType:"touchstart",eventID:"CropperTouchStart",callback:W,options:{passive:!1}}).addEvent({eventType:"mousedown",eventID:"CropperMouseDown",callback:W,options:{passive:!1}}),setTimeout(()=>{V.fn.corner.stop()},1e3)})},[a.id]),O(()=>{var h;let m=(h=U.get(c))==null?void 0:h.Instance;m&&m.updateScale(g)},[g]),O(()=>{var h;let m=(h=U.get(c))==null?void 0:h.Instance;m&&m.updateFilter({grayScale:v,tone:x,rotate:l})},[v,x,l]),i(A.Body,{borderRadius:0,height:"viewHeight",width:"viewWidth",children:d(k,{className:[X("Wrap"),X("Use_"+t)].join(" "),gap:0,height:1,position:"relative",overflow:"hidden",borderRadius:"inherit",children:[d(L,{flexSizing:0,overflow:"hidden",position:"relative",backgroundColor:"black",flexCenter:!0,freeCSS:{zIndex:1},children:[i("canvas",{style:{width:"100%",height:"100%"},width:2048,height:2048,className:X("Canvas"),id:"Canvas-"+c}),i(_.Supplement,{position:"absolute",bottom:1,left:1,fontColor:"white",children:d(w.Left,{gap:"1/2",flexWrap:!0,children:[d(_,{children:["[",a.type,"]"]}),i(_,{children:a.name}),d(_,{children:[a.size.rank(),"B"]})]})})]}),d(w.Separate,{borderTop:!0,flexSizing:"none",backgroundColor:"layer.1",padding:1,verticalAlign:"unset",UnderBreakPointStyles:{flexType:"col"},children:[i(q.SettingRegion,{DefaultOptions:p,val_scale:g,set_scale:o,val_tone:x,set_tone:R,val_grayScale:v,set_grayScale:C,val_rotate:l,set_rotate:y}),d(w.Right,{flexSizing:"none",children:[i(P.Border,{isRounded:!0,onClick:()=>{r()},children:"\u9589\u3058\u308B"}),i(P,{isRounded:!0,boxShadow:"3.remark",onClick:()=>z(void 0,null,function*(){var u;let m=(u=U.get(c))==null?void 0:u.Instance;if(!m)return;V.fn.mini.active("CropperExportation");let h=yield m.export();setTimeout(()=>{V.fn.mini.stop("CropperExportation"),e(h)},3e3)}),children:d(w.Center,{gap:"1/2",children:[i(V.White.R,{loaderID:"CropperExportation"}),"\u6C7A\u5B9A"]})})]})]})]})})},SettingRegion:f=>{let a=["","\u6696\u8272","\u5BD2\u8272","\u30BB\u30D4\u30A2","\u30B7\u30A2\u30F3","\u30DE\u30BC\u30F3\u30BF","\u30A4\u30A8\u30ED\u30FC","\u30AA\u30EA\u30B8\u30CA\u30EB1","\u30AA\u30EA\u30B8\u30CA\u30EB2","\u30AA\u30EA\u30B8\u30CA\u30EB3","\u30AA\u30EA\u30B8\u30CA\u30EB4"],s=e=>a[e]||"\u306A\u3057";return d(w.Left,{verticalAlign:"unset",flexWrap:!0,children:[d(k,{gap:"1/3",children:[i(_.Supplement,{children:"Rotate"}),d(w.Left,{flexChilds:"even",gap:"1/6",children:[i(P.Border.S,{isRounded:!0,borderTopRightRadius:0,borderBottomRightRadius:0,onClick:()=>{let e=f.val_rotate-90;e<0&&(e+=360),f.set_rotate(e)},children:d(w.Center,{gap:"1/4",children:["90\xB0",i(M,{icon:te})]})}),i(P.Border.S,{isRounded:!0,borderTopLeftRadius:0,borderBottomLeftRadius:0,onClick:()=>{f.set_rotate((f.val_rotate+90)%360)},children:d(w.Center,{gap:"1/4",children:[i(M,{icon:ae}),"90\xB0"]})})]})]}),d(k,{gap:"1/3",freeCSS:{minWidth:12*6},children:[i(_.Supplement,{children:"Zoom"}),d(P.Border.S,{flexCenter:!0,isRounded:!0,flexSizing:0,onClick:e=>{let r="CropperZoomEdit";Y.open({tipsID:r,gravityPoint:3,event:e,closeAtParentBlur:!1,freeCSS:{minWidth:12*26},content:i(A.Body,{children:d(k,{padding:1.5,children:[d(w.Separate,{children:[i(_.Paragraph,{children:d(w.Center,{gap:"1/2",children:[i(M.Search,{fontColor:"5.translucent"}),"Zoom"]})}),i(P.Sub,{color:"cloud",ssSphere:2.5,onClick:()=>{Y.close(r)},children:i(M.X,{})})]}),i(L,{borderBottom:!0,opacity:"low"}),i($.Slider,{override:"force",value:f.val_scale-100,min:f.DefaultOptions.scale.min-100,max:f.DefaultOptions.scale.max-100,step:25,onUpdateValidValue:(t,n)=>{S.interval.once(()=>{f.set_scale(t+100)},250,"Cropper.UpdateScale")},legends:{enable:!0,custom:t=>"x"+Math.round(100+t)/100}})]})})})},children:[f.val_scale.rate(1,0),"%"]})]}),d(k,{gap:"1/3",freeCSS:{minWidth:12*6},children:[i(_.Supplement,{children:"GrayScale"}),d(P.Border.S,{flexCenter:!0,isRounded:!0,flexSizing:0,onClick:e=>{let r="CropperGrayScaleEdit";Y.open({tipsID:r,gravityPoint:3,event:e,closeAtParentBlur:!1,freeCSS:{minWidth:12*26},content:i(A.Body,{children:d(k,{padding:1.5,children:[d(w.Separate,{children:[i(_.Paragraph,{children:d(w.Center,{gap:"1/2",children:[i(M,{icon:Q,fontColor:"5.translucent"}),"Gray Scale"]})}),i(P.Sub,{color:"cloud",ssSphere:2.5,onClick:()=>{Y.close(r)},children:i(M.X,{})})]}),i(L,{borderBottom:!0,opacity:"low"}),i($.Slider,{value:f.val_grayScale,min:0,max:100,step:10,onUpdateValidValue:t=>{S.interval.once(()=>{f.set_grayScale(t)},250,"Cropper.GrayScale")},legends:{enable:!0,custom:t=>t+"%"}})]})})})},children:[f.val_grayScale.rate(1,0),"%"]})]}),d(k,{gap:"1/3",freeCSS:{minWidth:12*6},children:[i(_.Supplement,{children:"Tone"}),i(P.Border.S,{flexCenter:!0,isRounded:!0,flexSizing:0,onClick:e=>{let r="CropperToneEdit";Y.open({tipsID:r,gravityPoint:3,event:e,closeAtParentBlur:!1,freeCSS:{minWidth:12*26,maxWidth:12*24},content:()=>{let t=[];for(let n=1;n<=10;n++)t.push({value:n,label:d(w.Left,{gap:"1/3",children:[i(L,{ssSphere:1,className:[X("ToneBall"),X("ToneBall_"+n)].join(" ")}),i(L,{textAlign:"left",flexSizing:0,children:s(n)})]})});return i(A.Body,{children:d(k,{padding:1.5,children:[d(w.Separate,{children:[i(_.Paragraph,{children:d(w.Center,{gap:"1/2",children:[i(M,{icon:ee,fontColor:"5.translucent"}),"Tone"]})}),i(P.Sub,{color:"cloud",ssSphere:2.5,onClick:()=>{Y.close(r)},children:i(M.X,{})})]}),i(L,{borderBottom:!0,opacity:"low"}),i($.Radio.Normal,{value:f.val_tone,gap:"1/2",cellStyles:{fontColor:"3.blur"},options:[{value:0,label:i(L,{flexSizing:0,textAlign:"center",children:"\u306A\u3057"})},...t],onUpdateValidValue:n=>{f.set_tone(n)}})]})})}})},children:d(w.Center,{gap:"1/2",children:[i(L,{boxShadow:"2.remark",ssSphere:1,className:[X("ToneBall"),X("ToneBall_"+f.val_tone)].join(" ")}),s(f.val_tone)]})})]})]})}},j={openDialogNEdit:f=>{$.Filer.fn.openDialog({accept:"image",multiple:!1,onChange:a=>{j.openEditor(H({imageFile:a[0]},f))}})},openEditor:f=>z(void 0,null,function*(){let a="CropperImage";A.open("middleCenter",{sheetID:a,size:"MAX",padding:0,margin:0,freeCSS:{maxWidth:"100%"},content:i(q.Core,{val_file:f.imageFile,options:f,finishedCallback:s=>{A.close(a),f.onProcessFinished(s)},abortCallback:()=>{A.close(a)}}),closeAtEscapeKeyDown:!1})})};export{j as Cropper,j as default};
1
+ import{b as Z,c as ie,e as V}from"../chunk-C5N2D3ZX.js";import{jsx as i,jsxs as p}from"react/jsx-runtime";import C,{UUID as le,useStore as q}from"jmini";import{$$fromRoot as oe}from"../@utils";import{useState as Y,useEffect as Q}from"react";import{Box as A,FAI as X,Column as z}from"../atoms";import{Row as x,Literal as T}from"../mols";import{Button as k}from"./Button";import H from"./Sheet";import J from"./Loader";import ee from"./Input";import{faPalette as se}from"@fortawesome/free-solid-svg-icons/faPalette";import{faBarsStaggered as ce}from"@fortawesome/free-solid-svg-icons/faBarsStaggered";import{faRotateLeft as me}from"@fortawesome/free-solid-svg-icons/faRotateLeft";import{faRotateRight as pe}from"@fortawesome/free-solid-svg-icons/faRotateRight";import{CropperClasses as N}from"../@styles/componentClasses";import O from"./Tooltips";class he{constructor(a){this.set_scale=a.set_scale,this.val_file=a.val_file,this.develops=a.develops;{let[c,m]=C.is.array(a.use)&&a.use||a.use.split(":").map(o=>Number(o)),h=c/m;this.usage={w:c,h:m,aspect:h}}this.componentId=a.componentId,this.scale={current:a.scale.default,default:a.scale.default,min:a.scale.min,max:a.scale.max};let s=a.canvas;this.Canvas={elm:s,ctx:s.getContext("2d")};let e=a.picture.image,{width:r,height:t}=e,n=r/t;this.Picture={elm:e,originDataUrl:e.src,aspect:n,revisedAspect:1,rotate:a.picture.rotate,grayScale:a.picture.grayScale,tone:a.picture.tone},this.pst={frame:{x:0,y:0,w:0,h:0,aspect:1},outImage:{x:0,y:0,w:0,h:0},imageX:r/2,imageY:t/2,centerX:0,centerY:0},this.dragEffectInfo={origin:{x:0,y:0},frameExpandRate:{x:0,y:0}},this.pinchEffectInfo={origin:{x:0,y:0,scale:this.scale.current}},this.frameSizing(),this.modifyImage()}frameSizing(){let a=this.Canvas.elm,s=this.Picture.elm,e=0,r=0;if(this.usage.aspect==1){let o=a.width*.6666666666666666,l=a.height*(2/3);r=e=Math.min(o,l)}else this.usage.aspect>1?(e=a.width*(8/10),r=e/this.usage.aspect):(r=a.height*(8/10),e=r*this.usage.aspect);let{width:t,height:n}=s,c=(a.width-e)/2,m=(a.height-r)/2,h=e/r;this.pst={frame:{x:c,y:m,w:e,h:r,aspect:h},outImage:{x:0,y:0,w:0,h:0},imageX:t/2,imageY:n/2,centerX:a.width/2,centerY:a.height/2}}dragEffect(a){let{eventType:s,x:e,y:r}=a;if(s=="start"){let t=this.Canvas.elm.position();this.dragEffectInfo={origin:{x:e,y:r},frameExpandRate:{x:this.Canvas.elm.width/t.width,y:this.Canvas.elm.height/t.height}}}else{let{origin:t,frameExpandRate:n}=this.dragEffectInfo,c=t.x-e,m=t.y-r,h=this.scale.current*this.Picture.revisedAspect/100,o=c/h*n.x,l=m/h*n.y;s=="move"?this.drawImage(this.pst.imageX+o,this.pst.imageY+l):s=="end"&&this.drawImage(this.pst.imageX+=o,this.pst.imageY+=l)}}pinchEffect(a){let{eventType:s,event:e}=a,{x:r,y:t}=C.getCursor(e.touches[0]),{x:n,y:c}=C.getCursor(e.touches[1]),m=n-r,h=c-t;if(s=="start")this.pinchEffectInfo.origin={x:m,y:h,scale:this.scale.current};else if(s=="move"){let{origin:o}=this.pinchEffectInfo,l=Math.sqrt(Math.pow(o.x,2)+Math.pow(o.y,2)),g=Math.sqrt(Math.pow(m,2)+Math.pow(h,2))/l,f=Number(o.scale*g);this.set_scale(f)}}updateScale(a){let s=a;s=Math.max(s,this.scale.min),s=Math.min(s,this.scale.max),this.scale.current=s,this.drawImage()}updateFilter(a){this.Picture.grayScale=a.grayScale,this.Picture.tone=a.tone,this.Picture.rotate=a.rotate,this.modifyImage()}modifyImage(){return V(this,null,function*(){let{grayScale:a,tone:s,rotate:e}=this.Picture;const r=document.createElement("canvas");let t=r.getContext("2d"),n=yield C.ImageLoader(this.Picture.originDataUrl),c=n.width,m=n.height;(e==90||e==270)&&(c=n.height,m=n.width),r.width=c,r.height=m,a&&(t.filter="grayscale("+a+"%)"),e&&(t.translate(c/2,m/2),t.rotate(e*Math.PI/180),[90,270].includes(e)?t.translate(-m/2,-c/2):t.translate(-c/2,-m/2)),t.drawImage(n,0,0,n.width,n.height);let h=t.getImageData(0,0,r.width,r.height),o=h.data;{a/=100;let f=[[255,255,255],[255,200,100],[170,170,255],[240,200,145],[128,255,255],[255,128,255],[255,255,128],[128,158,169],[128,112,162],[50,192,87],[246,100,140]][s],w=f[0]/255,R=f[1]/255,v=f[2]/255;for(let I=0;I<m;I++)for(let _=0;_<c;_++){var l=(I*c+_)*4;if(a){let U=.3*o[l]+.59*o[l+1]+.11*o[l+2];for(var d=0;d<3;d++){let W=o[l+d];o[l+d]=W+(U-W)*a}}o[l]*=w,o[l+1]*=R,o[l+2]*=v}}t.putImageData(h,0,0);let g=r.toDataURL("image/jpeg");{let f=yield C.ImageLoader(g),{width:w,height:R}=f,v=w/R;this.Picture=ie(Z({},this.Picture),{elm:f,aspect:v,revisedAspect:this.pst.frame.aspect>v?this.pst.frame.w/w:this.pst.frame.h/R})}this.drawImage()})}drawImage(a,s){let{Canvas:{ctx:e,elm:r},pst:{frame:t}}=this,n=a||this.pst.imageX,c=s||this.pst.imageY;{let m=this.scale.current/100,h=this.Picture.revisedAspect*m,o=this.pst.centerX-n*h,l=this.pst.centerY-c*h,d=this.Picture.elm.width*h,g=this.Picture.elm.height*h;{let f=this.pst.frame.x+this.pst.frame.w-d,w=this.pst.frame.x,R=this.pst.frame.y+this.pst.frame.h-g,v=this.pst.frame.y,I=0;o<f&&(I=o-f),o>w&&(I=o-w);let _=0;l<R&&(_=l-R),l>v&&(_=l-v),this.dragEffectInfo.origin.x+=I/2/this.dragEffectInfo.frameExpandRate.x,this.dragEffectInfo.origin.y+=_/2/this.dragEffectInfo.frameExpandRate.y,o=Math.min(Math.max(o,f),w),l=Math.min(Math.max(l,R),v)}this.pst.outImage={x:o,y:l,w:d,h:g},e.clearRect(0,0,this.Canvas.elm.width,this.Canvas.elm.height),e.drawImage(this.Picture.elm,0,0,this.Picture.elm.width,this.Picture.elm.height,o,l,d,g)}{if(this.usage.aspect==1){e.fillStyle="rgba( 20,24,20,.3 )",e.beginPath();let o=r.width/3*2,l=r.height/3*2,d=Math.min(o,l),g=Math.max(o,l);e.arc(r.width/2,r.height/2,g*1.41,0,Math.PI*2,!0),e.arc(r.width/2,r.height/2,d/2,0,Math.PI*2,!1),e.closePath(),e.fill()}else e.fillStyle="rgba( 20,24,20,.3 )";e.beginPath(),e.moveTo(0,0),e.lineTo(r.width,0),e.lineTo(r.width,r.height),e.lineTo(0,r.height),e.lineTo(0,0),e.closePath(),e.lineTo(t.x,t.y),e.lineTo(t.x,t.y+t.h),e.lineTo(t.x+t.w,t.y+t.h),e.lineTo(t.x+t.w,t.y),e.lineTo(t.x,t.y),e.fill();let h=C(document.body).getStyleProperty("--color-theme-hsl");e.lineWidth=4,e.strokeStyle=`hsla( ${h},1 )`,e.strokeRect(t.x,t.y,t.w,t.h)}}export(){return V(this,null,function*(){let{Canvas:a,develops:s,Picture:e,pst:{outImage:r,frame:t}}=this,n=r.w/e.elm.width,c=r.h/e.elm.height,m=(t.x-r.x)/n,h=(t.x-r.x+t.w)/n,o=(t.y-r.y)/c,l=(t.y-r.y+t.h)/c,d=Array.from({length:s.length}),g="image/jpeg";for(let f=0;f<s.length;f++){let{size:w,maxSize:R}=s[f];R=R||{S:1024*20,R:1024*100,L:1024*350}[w];let v={S:140,R:600,L:1200}[w],I=v;this.usage.aspect>1?I=v/this.usage.aspect:v=I*this.usage.aspect;let _=document.createElement("canvas");_.width=v,_.height=I;let U=_.getContext("2d");if(!U)return;U.clearRect(0,0,v,I),U.drawImage(this.Picture.elm,m,o,h-m,l-o,0,0,v,I);let W=_.toDataURL(g),F=yield W.toBlob(g);if(!F)return;if(F.size>=R){let S=R/F.size;if(W=_.toDataURL(g,S*.92),F=yield W.toBlob(g),!F)return}let y=new File([F],this.val_file.name,{type:g});d[f]=y}return d})}}const ne={Core:u=>{let{val_file:a,options:s,finishedCallback:e,abortCallback:r}=u,{use:t,develops:n=[]}=s,[c]=Y(le());const m={scale:{default:120,min:100,max:400},rotate:0,grayScale:0,tone:0};let h=2048*2048,o=1024,[l,d]=Y(m.scale.default),[g,f]=Y(m.rotate),[w,R]=Y(m.grayScale),[v,I]=Y(m.tone),[_,U]=Y(0),[W,F]=Y(0);return Q(()=>{let y="CropperResize";return C(window).addEvent({eventType:"resize",eventID:y,callback:()=>{C.interval.once(()=>{var G;let S=oe("#Canvas-"+c)[0];if(!S)return;let E=(G=q.get(c))==null?void 0:G.Instance;if(!E)return;let $=S.position(),te=$.width/$.height,D=o,B=D/te;if(D*B>h){let K=D*B/h;D=Math.floor(D/Math.sqrt(K)),B=Math.floor(B/Math.sqrt(K))}S.width=o,S.height=B;let{width:j,height:P}=S;E.pst.centerX=j/2,E.pst.centerY=P/2,E.frameSizing(),E.modifyImage()},250,"CropperResize")}}),()=>{C(window).removeEvent(y)}},[]),Q(()=>{q.set({[c]:{}}),V(void 0,null,function*(){J.fn.corner.active(),yield C.pending(()=>{},400);let{target:y}=yield a.convert();if(!y)return;let S=y.result,E=oe("#Canvas-"+c)[0];if(!E)return;let $=E.position(),te=$.width/$.height,D=o,B=D/te;if(D*B>h){let b=D*B/h;D=Math.floor(D/Math.sqrt(b)),B=Math.floor(B/Math.sqrt(b))}E.width=D,E.height=B;let j=yield C.ImageLoader(S);U(j.width),F(j.height);let P=new he({set_scale:d,val_file:a,develops:n,use:t,scale:m.scale,componentId:c,canvas:E,picture:{image:j,grayScale:m.grayScale,tone:m.tone,rotate:m.rotate}});q.set({[c]:{Instance:P}});const G=function(b){if(b.preventDefault(),b.touches&&b.touches.length>1)P.pinchEffect({eventType:"start",event:b}),C(document).addEvent({eventType:"touchmove",eventID:"CropperEffectMove",options:{passive:!1},callback:M=>{M.preventDefault(),P.pinchEffect({eventType:"move",event:M})}}).addEvent({eventType:"touchend",eventID:"CropperEffectEnd",options:{passive:!1},callback:re});else{P.dragEffect(Z({eventType:"start"},C.getCursor(b)));let{type:M}=b;C(document).addEvent({eventType:M=="touchstart"?"touchmove":"mousemove",eventID:"CropperEffectMove",options:{passive:!1},callback:L=>{K("move",L)}}).addEvent({eventType:M=="touchstart"?"touchend":"mouseup",eventID:"CropperEffectEnd",options:{passive:!1},callback:L=>{K("end",L),re(L)}})}},K=function(b,M){M.preventDefault(),P.dragEffect(Z({eventType:b},C.getCursor(M)))},re=function(b){b.preventDefault(),C(document).removeEvent(["CropperEffectMove","CropperEffectEnd"])};C(E).removeEvent(["CropperMouseWheel","CropperTouchStart","CropperMouseDown"]).addEvent({eventID:"CropperMouseWheel",eventType:"wheel",callback:b=>{b.preventDefault();let M=Number(b.wheelDelta*.04),L=P.scale.current+M;L=Math.max(L,P.scale.min),L=Math.min(L,P.scale.max),d(L)},options:{passive:!1}}).addEvent({eventType:"touchstart",eventID:"CropperTouchStart",callback:G,options:{passive:!1}}).addEvent({eventType:"mousedown",eventID:"CropperMouseDown",callback:G,options:{passive:!1}}),setTimeout(()=>{J.fn.corner.stop()},1e3)})},[a.id]),Q(()=>{var S;let y=(S=q.get(c))==null?void 0:S.Instance;y&&y.updateScale(l)},[l]),Q(()=>{var S;let y=(S=q.get(c))==null?void 0:S.Instance;y&&y.updateFilter({grayScale:w,tone:v,rotate:g})},[w,v,g]),i(H.Body,{borderRadius:0,height:"viewHeight",width:"viewWidth",children:p(z,{className:[N("Wrap"),N("Use_"+t)].join(" "),gap:0,height:1,position:"relative",overflow:"hidden",borderRadius:"inherit",children:[p(A,{flexSizing:0,overflow:"hidden",position:"relative",backgroundColor:"black",flexCenter:!0,freeCSS:{zIndex:1},children:[i("canvas",{style:{width:"100%",height:"100%"},width:o,height:o,className:N("Canvas"),id:"Canvas-"+c}),i(T.Supplement,{position:"absolute",bottom:1,left:1,fontColor:"white",children:p(x.Left,{gap:"1/2",flexWrap:!0,children:[p(T,{children:["[",a.type,"]"]}),i(T,{children:a.name}),p(T,{children:[_,"px x ",W,"px"]}),p(T,{children:["[",a.size.rank(),"B]"]})]})})]}),p(x.Separate,{borderTop:!0,flexSizing:"none",backgroundColor:"layer.1",padding:1,verticalAlign:"unset",UnderBreakPointStyles:{flexType:"col"},children:[i(ne.SettingRegion,{DefaultOptions:m,val_scale:l,set_scale:d,val_tone:v,set_tone:I,val_grayScale:w,set_grayScale:R,val_rotate:g,set_rotate:f}),p(x.Right,{flexSizing:"none",children:[i(k.Border,{isRounded:!0,onClick:()=>{r()},children:"\u9589\u3058\u308B"}),i(k,{isRounded:!0,boxShadow:"3.remark",onClick:()=>V(void 0,null,function*(){var E;let y=(E=q.get(c))==null?void 0:E.Instance;if(!y)return;J.fn.mini.active("CropperExportation");let S=yield y.export();setTimeout(()=>{J.fn.mini.stop("CropperExportation"),e(S)},3e3)}),children:p(x.Center,{gap:"1/2",children:[i(J.White.R,{loaderID:"CropperExportation"}),"\u6C7A\u5B9A"]})})]})]})]})})},SettingRegion:u=>{let a=["","\u6696\u8272","\u5BD2\u8272","\u30BB\u30D4\u30A2","\u30B7\u30A2\u30F3","\u30DE\u30BC\u30F3\u30BF","\u30A4\u30A8\u30ED\u30FC","\u30AA\u30EA\u30B8\u30CA\u30EB1","\u30AA\u30EA\u30B8\u30CA\u30EB2","\u30AA\u30EA\u30B8\u30CA\u30EB3","\u30AA\u30EA\u30B8\u30CA\u30EB4"],s=e=>a[e]||"\u306A\u3057";return p(x.Left,{verticalAlign:"unset",flexWrap:!0,children:[p(z,{gap:"1/3",children:[i(T.Supplement,{children:"Rotate"}),p(x.Left,{flexChilds:"even",gap:"1/6",children:[i(k.Border.S,{isRounded:!0,borderTopRightRadius:0,borderBottomRightRadius:0,onClick:()=>{let e=u.val_rotate-90;e<0&&(e+=360),u.set_rotate(e)},children:p(x.Center,{gap:"1/4",children:["90\xB0",i(X,{icon:me})]})}),i(k.Border.S,{isRounded:!0,borderTopLeftRadius:0,borderBottomLeftRadius:0,onClick:()=>{u.set_rotate((u.val_rotate+90)%360)},children:p(x.Center,{gap:"1/4",children:[i(X,{icon:pe}),"90\xB0"]})})]})]}),p(z,{gap:"1/3",freeCSS:{minWidth:12*6},children:[i(T.Supplement,{children:"Zoom"}),p(k.Border.S,{flexCenter:!0,isRounded:!0,flexSizing:0,onClick:e=>{let r="CropperZoomEdit";O.open({tipsID:r,gravityPoint:3,event:e,closeAtParentBlur:!1,freeCSS:{minWidth:12*26},content:i(H.Body,{children:p(z,{padding:1.5,children:[p(x.Separate,{children:[i(T.Paragraph,{children:p(x.Center,{gap:"1/2",children:[i(X.Search,{fontColor:"5.translucent"}),"Zoom"]})}),i(k.Sub,{color:"cloud",ssSphere:2.5,onClick:()=>{O.close(r)},children:i(X.X,{})})]}),i(A,{borderBottom:!0,opacity:"low"}),i(ee.Slider,{override:"force",value:u.val_scale-100,min:u.DefaultOptions.scale.min-100,max:u.DefaultOptions.scale.max-100,step:25,onUpdateValidValue:(t,n)=>{C.interval.once(()=>{u.set_scale(t+100)},250,"Cropper.UpdateScale")},legends:{enable:!0,custom:t=>"x"+Math.round(100+t)/100}})]})})})},children:[u.val_scale.rate(1,0),"%"]})]}),p(z,{gap:"1/3",freeCSS:{minWidth:12*6},children:[i(T.Supplement,{children:"GrayScale"}),p(k.Border.S,{flexCenter:!0,isRounded:!0,flexSizing:0,onClick:e=>{let r="CropperGrayScaleEdit";O.open({tipsID:r,gravityPoint:3,event:e,closeAtParentBlur:!1,freeCSS:{minWidth:12*26},content:i(H.Body,{children:p(z,{padding:1.5,children:[p(x.Separate,{children:[i(T.Paragraph,{children:p(x.Center,{gap:"1/2",children:[i(X,{icon:se,fontColor:"5.translucent"}),"Gray Scale"]})}),i(k.Sub,{color:"cloud",ssSphere:2.5,onClick:()=>{O.close(r)},children:i(X.X,{})})]}),i(A,{borderBottom:!0,opacity:"low"}),i(ee.Slider,{value:u.val_grayScale,min:0,max:100,step:10,onUpdateValidValue:t=>{C.interval.once(()=>{u.set_grayScale(t)},250,"Cropper.GrayScale")},legends:{enable:!0,custom:t=>t+"%"}})]})})})},children:[u.val_grayScale.rate(1,0),"%"]})]}),p(z,{gap:"1/3",freeCSS:{minWidth:12*6},children:[i(T.Supplement,{children:"Tone"}),i(k.Border.S,{flexCenter:!0,isRounded:!0,flexSizing:0,onClick:e=>{let r="CropperToneEdit";O.open({tipsID:r,gravityPoint:3,event:e,closeAtParentBlur:!1,freeCSS:{minWidth:12*26,maxWidth:12*24},content:()=>{let t=[];for(let n=1;n<=10;n++)t.push({value:n,label:p(x.Left,{gap:"1/3",children:[i(A,{ssSphere:1,className:[N("ToneBall"),N("ToneBall_"+n)].join(" ")}),i(A,{textAlign:"left",flexSizing:0,children:s(n)})]})});return i(H.Body,{children:p(z,{padding:1.5,children:[p(x.Separate,{children:[i(T.Paragraph,{children:p(x.Center,{gap:"1/2",children:[i(X,{icon:ce,fontColor:"5.translucent"}),"Tone"]})}),i(k.Sub,{color:"cloud",ssSphere:2.5,onClick:()=>{O.close(r)},children:i(X.X,{})})]}),i(A,{borderBottom:!0,opacity:"low"}),i(ee.Radio.Normal,{value:u.val_tone,gap:"1/2",cellStyles:{fontColor:"3.blur"},options:[{value:0,label:i(A,{flexSizing:0,textAlign:"center",children:"\u306A\u3057"})},...t],onUpdateValidValue:n=>{u.set_tone(n)}})]})})}})},children:p(x.Center,{gap:"1/2",children:[i(A,{boxShadow:"2.remark",ssSphere:1,className:[N("ToneBall"),N("ToneBall_"+u.val_tone)].join(" ")}),s(u.val_tone)]})})]})]})}},ae={openDialogNEdit:u=>{ee.Filer.fn.openDialog({accept:"image",multiple:!1,onChange:a=>{ae.openEditor(Z({imageFile:a[0]},u))}})},openEditor:u=>V(void 0,null,function*(){let a="CropperImage";H.open("middleCenter",{sheetID:a,size:"MAX",padding:0,margin:0,freeCSS:{maxWidth:"100%"},content:i(ne.Core,{val_file:u.imageFile,options:u,finishedCallback:s=>{H.close(a),u.onProcessFinished(s)},abortCallback:()=>{H.close(a)}}),closeAtEscapeKeyDown:!1})})};export{ae as Cropper,ae as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amotify",
3
- "version": "0.2.220",
3
+ "version": "0.2.221",
4
4
  "description": "UI Component for React,NextJS,esbuild",
5
5
  "scripts": {
6
6
  "start": "run-p clean build:*",