@armco/imageeditor 0.0.3 → 0.0.4

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
- "use strict";const g=require("react/jsx-runtime"),s=require("react"),lt=require("react-dom"),ut=require("@armco/icon");var y=(t=>(t.POPOVER="popover",t.ANCHOR="anchor",t))(y||{}),F=(t=>(t.POPOVER="popover",t.ANCHOR="anchor",t))(F||{}),N=(t=>(t.FADEINOUT="fade",t.EXPANDSHRINK="expand-shrink",t))(N||{}),z=(t=>(t.TOPLEFT="top-left",t.TOPRIGHT="top-right",t.TOPCENTER="top-center",t.RIGHTTOP="right-top",t.RIGHTBOTTOM="right-bottom",t.RIGHTCENTER="right-center",t.BOTTOMLEFT="bottom-left",t.BOTTOMRIGHT="bottom-right",t.BOTTOMCENTER="bottom-center",t.LEFTTOP="left-top",t.LEFTBOTTOM="left-bottom",t.LEFTCENTER="left-center",t.BOTTOM="bottom",t.RIGHT="right",t.LEFT="left",t.TOP="top",t.AUTO="auto",t))(z||{}),w=(t=>(t.HOVER="hover",t.CLICK="click",t))(w||{}),d=(t=>(t.TOPLEFT="top-left",t.TOPRIGHT="top-right",t.TOPCENTER="top-center",t.RIGHTTOP="right-top",t.RIGHTBOTTOM="right-bottom",t.RIGHTCENTER="right-center",t.BOTTOMLEFT="bottom-left",t.BOTTOMRIGHT="bottom-right",t.BOTTOMCENTER="bottom-center",t.LEFTTOP="left-top",t.LEFTBOTTOM="left-bottom",t.LEFTCENTER="left-center",t.BOTTOM="bottom",t.RIGHT="right",t.LEFT="left",t.TOP="top",t.AUTO="auto",t))(d||{});const at=window.getComputedStyle(document.documentElement),C=parseFloat(at.fontSize),B=7;function ht(t){if(t){const e=document.querySelector(".ar-Editor__frame");if(e)return e.contentDocument}return document}function J(t){if(t){const e=document.querySelector(".ar-Editor__frame");if(e)return e.contentWindow}return window}function dt(t,e,o,c){const n=J(c)||window;if({bottom:e.top+e.height+o.height>n.innerHeight,right:e.left+e.width+o.width>n.innerWidth,left:e.left-o.width<0,top:e.top-o.height<0}[t])return!1;if(t==="left"||t==="right"){if(C>e.top||C>e.bottom)return!1}else if(C>e.left||C>e.right)return!1;return t}function ft(t,e,o,c,n){const l={[d.BOTTOM]:{top:e.top+e.height+(c?0:B)+(n||0),left:e.left+(e.width-o.width)/2},[d.RIGHT]:{top:e.top+(e.height-o.height)/2,left:e.left+e.width+(c?0:B)},[d.LEFT]:{top:e.top+(e.height-o.height)/2,left:e.left-o.width-(c?0:B)},[d.TOP]:{top:e.top-o.height-(c?0:B)-(n||0),left:e.left+(e.width-o.width)/2}};let{left:r,top:a}=l[t];return t===d.BOTTOM||t===d.TOP?(r<0&&(r=C),r+o.width>window.innerWidth&&(r=`calc(100% - ${o.width}px - ${C}px)`)):(a<0&&(a=C),a+o.height>window.innerHeight&&(a=`calc(100% - ${o.height}px - ${C}px)`)),{left:r,top:a}}function Tt(t,e,o,c){if(o&&o!==d.AUTO)return o;const n=[d.BOTTOM,d.RIGHT,d.LEFT,d.TOP];for(const l of n)if(dt(l,t,e,c))return l;return d.BOTTOM}function pt(t,e,o,c,n,l,r){const a=J(l)||window;t=n?{left:n[0],x:n[0],top:n[1],y:n[1],height:0,width:0,right:a.screen.width-n[0],bottom:a.screen.height-n[1],toJSON:()=>{}}:t;const h=Tt(t,e,o,l),{left:p,top:m}=ft(h,t,e,c,r);return{leftTop:{top:(""+m).startsWith("calc")?m:m+"px",left:(""+p).startsWith("calc")?p:p+"px"},position:h}}const Ot=t=>{const{children:e,classes:o,container:c,demo:n,styles:l}=t,[r,a]=s.useState();return s.useEffect(()=>(a(c||document.createElement("div")),()=>a(null)),[c]),s.useEffect(()=>{if(r){const h=ht(n);if(h){const p=h.getElementById("root");p&&p.appendChild(r)}return()=>{if(h){const p=h.getElementById("root");p&&p.removeChild(r)}}}},[r,n]),s.useEffect(()=>{r&&(o&&(r.className=o),r.classList.contains("ar-Portal")||r.classList.add("ar-Portal"),l&&Object.assign(r.style,l))},[o,l,r]),r?lt.createPortal(e,r):null};let mt=!1;const gt={left:"right",right:"left",top:"bottom",bottom:"top"},Et={left:"135",right:"-45",top:"-135",bottom:"45"},Rt=t=>{const{classes:e,children:o,closeOnSelfClick:c,contentClasses:n,contentMatchAnchorWidth:l,demo:r,disabled:a,hideMarker:h,invertBg:p,isOpen:m,isRaw:Q,onAnchorClick:G,onClose:P,popAtPointer:j,position:$=z.AUTO,preserveMarkerSpace:D,stretch:Z,topOffset:_,trigger:v=w.CLICK,animation:x,updateTriggers:tt,wrapText:et,...ot}=t,f=s.useMemo(()=>x&&!Array.isArray(x)?[x]:x,[x]),H=s.useRef(null),E=s.useRef(null),[R,I]=s.useState(),[rt,nt]=s.useState(),[L,it]=s.useState(),[K,V]=s.useState(),[M,S]=s.useState(),A=s.useRef(),q=s.useRef(0),W=s.useCallback(()=>{if(!H.current||!E.current)return;const i=H.current.getBoundingClientRect();l&&(E.current.style.width=i.width+"px");const u=E.current.getBoundingClientRect();f&&f.length>0&&f.indexOf(N.EXPANDSHRINK)>-1&&(u.width=Math.floor(u.width*1.25),u.height=Math.floor(u.height*1.25));const{leftTop:T,position:O}=pt(i,u,$,h&&!D,j&&v===w.CLICK?A.current:null,r,_);nt(T),it(O)},[l,r,h,j,$,D,_,v,f]);let k,U;return s.Children.forEach(o,i=>{var u,T;((u=i==null?void 0:i.props)==null?void 0:u.slot)===F.ANCHOR&&(U=i),((T=i==null?void 0:i.props)==null?void 0:T.slot)===F.POPOVER&&(k=i)}),s.useEffect(()=>{m!==void 0&&(I(m),m&&!M&&S(!0))},[m,M]),s.useEffect(()=>{var i;let u=T=>{H.current&&!H.current.contains(T.target)&&E.current&&!E.current.contains(T.target)&&(I(!1),P&&P())};if(v===w.CLICK&&R){document.addEventListener("mousedown",u);const T=document.querySelector("iframe");return T&&((i=T.contentWindow)==null||i.document.addEventListener("mousedown",u)),()=>{var O;document.removeEventListener("click",u);const b=document.querySelector("iframe");b&&((O=b.contentWindow)==null||O.document.removeEventListener("click",u))}}},[v,R,P]),s.useEffect(()=>{M&&R&&(W(),V(!0))},[R,M,W,...tt||[]]),s.useEffect(()=>{if(!h&&E.current&&K&&L){const i=E.current,u=H.current.getBoundingClientRect(),T=gt[L],O=i.getBoundingClientRect();f&&f.length>0&&f.indexOf(N.EXPANDSHRINK)>-1&&(O.width=Math.floor(O.width*1.25),O.height=Math.floor(O.height*1.25));const b=L==="top"||L==="bottom";let X=u[b?"width":"height"]/2-7;const st=u.left-O.left+X,ct=u.top-O.top+X;i.style.setProperty("--marker-transform",`rotate(${Et[L]}deg)`),i.style.setProperty(`--marker-${T}`,"-0.35rem"),i.style.setProperty(`--marker-${L}`,"initial"),i.style.setProperty(`--marker-${b?"left":"top"}`,(b?st:ct)+"px"),V(!1)}},[K,E,h,L,A,f]),g.jsxs(g.Fragment,{children:[g.jsx("span",{className:`ar-Popover__anchor${e?" "+e:""}${Z?" w-100":""}`,onMouseDown:i=>{A.current=[i.clientX,i.clientY],Date.now()-q.current<500||(q.current=Date.now(),v===w.CLICK&&!mt&&!a&&(!M&&S(!0),(m===void 0||m)&&setTimeout(()=>I(!R),0)),R&&P&&P(),G&&G(!R))},ref:H,onMouseEnter:()=>{v===w.HOVER&&!a&&(S(!0),setTimeout(()=>I(!0),0))},onMouseLeave:()=>{v===w.HOVER&&!a&&(setTimeout(()=>I(!1),0),P&&P())},...ot,children:U}),k&&M&&g.jsx(Ot,{classes:`position-fixed popover-container${R?" z-3000":" invisible"}`,demo:r,styles:rt||{},children:g.jsx("div",{className:`ar-Popover__content${p?" invert-bg":""}${et?" wrap":""}${$?" "+$:""} ${n}${f&&f.length>0?" transition "+(f==null?void 0:f.join(" ")):""} ${R?" show":""}${h?" hide-marker":""}${Q?"":" p-1 border-radius l2 f25"}`,onClick:()=>c&&I(!1),ref:E,children:k})})]})},Y=t=>{const{children:e,demo:o,...c}=t,[n,l]=s.useState();return g.jsx(Rt,{contentClasses:"overflow-auto",trigger:w.HOVER,onAnchorClick:()=>{l(!1),setTimeout(()=>l(void 0),10)},animation:[N.EXPANDSHRINK,N.FADEINOUT],demo:o,isOpen:n,hideMarker:!0,preserveMarkerSpace:!0,wrapText:!0,...c,children:e})},wt=({icon:t,handler:e,tooltip:o})=>g.jsxs(Y,{children:[g.jsx("span",{className:"mx-3 p-1 cursor-pointer",slot:y.ANCHOR,children:g.jsx(ut,{icon:t,attributes:{colors:{fillColor:"#ffffff99"},classes:"cursor-pointer",size:"2rem"},events:{onClick:e}})}),g.jsx("span",{slot:y.POPOVER,children:o})]});exports.Control=wt;exports.L=y;exports.v=Y;
1
+ "use strict";const s=require("react/jsx-runtime"),t=require("@armco/shared-components/Tooltip"),c=require("@armco/icon");var o=(r=>(r.POPOVER="popover",r.ANCHOR="anchor",r))(o||{});const i=({icon:r,handler:e,tooltip:n})=>s.jsxs(t,{children:[s.jsx("span",{className:"mx-3 p-1 cursor-pointer",slot:o.ANCHOR,children:s.jsx(c,{icon:r,attributes:{colors:{fillColor:"#ffffff99"},classes:"cursor-pointer",size:"2rem"},events:{onClick:e}})}),s.jsx("span",{slot:o.POPOVER,children:n})]});exports.Control=i;exports.L=o;
package/cjs/Control.js CHANGED
@@ -1 +1 @@
1
- "use strict";require("react/jsx-runtime");const r=require("./Control-chunk.js");require("@armco/icon");require("react");require("react-dom");module.exports=r.Control;
1
+ "use strict";require("react/jsx-runtime");const r=require("./Control-chunk.js");require("@armco/shared-components/Tooltip");require("@armco/icon");module.exports=r.Control;
@@ -1,7 +1,2 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode('.ar-Image{transition:all .3s}.ar-Image.fill{object-fit:cover}.ar-Image.fill.preserveAspectRatio{object-fit:contain}.ar-Slider input[type=range]{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;cursor:pointer}.ar-Slider input[type=range]:hover+.ar-Slider__bubble{opacity:1}.ar-Slider input[type=range]:focus{outline:none}.ar-Slider input[type=range]::-webkit-slider-runnable-track{background-color:#053a5f;border-radius:.2rem;height:.2rem}.ar-Slider input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin-top:-6.5px;transition:outline .5s;background-color:var(--ar-bg-slider-track);height:1rem;width:1rem;border-radius:50%}.ar-Slider input[type=range]::-webkit-slider-thumb:hover{border:5px solid var(--ar-bg-slider-track)}.ar-Slider input[type=range]:focus::-webkit-slider-thumb{border:1px solid #053a5f}.ar-Slider input[type=range]::-moz-range-track{background-color:#053a5f;border-radius:.2rem;height:.2rem}.ar-Slider input[type=range]::-moz-range-thumb{border:none;border-radius:0;background-color:var(--ar-bg-slider-track);height:1rem;width:1rem}.ar-Slider input[type=range]:focus::-moz-range-thumb{border:1px solid #053a5f}.ar-Slider .ar-Slider__bubble{background:#454545;color:#fff;padding:4px 12px;border-radius:4px;left:50%;bottom:-1.5rem;transform:translate(-50%);opacity:0;transition:opacity .3s}.ar-Slider .ar-Slider__bubble:after{content:"";position:absolute;width:4px;height:4px;transform:rotate(45deg);background:#454545;top:-2px;left:50%}.ar-Slider .ar-Slider__manual-input{width:2rem}.ar-ImageEditor .ar-ImageEditor__image-container{max-width:60vw;max-height:75vh}.ar-ImageEditor .ar-ImageEditor__editor-controls{transition:background-color .5s,box-shadow .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);border-radius:2rem}.ar-ImageEditor .ar-ImageEditor__editor-controls:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button.is-dirty:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__controls{bottom:0}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container{transition:background-color .5s,box-shadow .5s,max-height .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);max-height:3.2rem;overflow:hidden}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container.expanded{max-height:20rem}.ar-Portal{z-index:2001;white-space:nowrap}.ar-Popover__anchor:focus-visible{outline:none}:root{--marker-transform: rotate(45deg);--marker-top: -.4rem;--marker-left: 10%;--marker-right: unset;--marker-bottom: unset}:root .ar-Popover__content{box-shadow:0 4px 8px -2px #091e4240,0 0 1px #091e424f;z-index:2002;background-color:var(--ar-bg);white-space:nowrap;position:relative;border:1px solid var(--ar-color-border)}:root .ar-Popover__content>*{position:relative}:root .ar-Popover__content.invert-bg{background-color:var(--ar-bg-invert-1)}:root .ar-Popover__content.wrap{white-space:wrap}:root .ar-Popover__content:not(.hide-marker):before{content:"";background-color:var(--ar-bg);position:absolute;height:.7rem;width:.7rem;border-width:1px;border-style:solid;border-color:var(--ar-color-border) transparent transparent var(--ar-color-border);transform:var(--marker-transform);top:var(--marker-top);left:var(--marker-left);right:var(--marker-right);bottom:var(--marker-bottom)}:root .ar-Popover__content.invert-bg:not(.hide-marker):before{background-color:var(--ar-bg-invert-1)}:root .ar-Popover__content.transition{transition:width .15s ease-in-out,height .15s ease-in-out,opacity .3s ease-in-out,transform .15s ease-in-out}:root .ar-Popover__content.transition.expand-shrink{transform:scale(.8)}:root .ar-Popover__content.transition.show{transform:scale(1)}@media (min-width: 576px){:root .ar-Popover__content{max-width:25vw}}:root .ar-List__item{line-height:1.5rem}:root .ar-List__item:hover{background-color:var(--ar-color-font);color:var(--ar-color-font-invert);cursor:pointer}')),document.head.appendChild(r)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
2
- "use strict";const t=require("react/jsx-runtime"),p=require("react"),j=require("./Control-chunk.js"),O=require("@armco/icon"),z=require("./helper.js");require("react-dom");const F=s=>new URL(s).hostname,L=s=>{const d=F(s);return d==="localhost"||d==="armco.tech"?"use-credentials":"anonymous"},k=p.forwardRef((s,d)=>{const{alt:h,blur:c,brightness:g,classes:n,contrast:m,customBgZIndex:r,demo:N,fill:f,flipHorizontal:b,flipVertical:y,grayscale:C,image:i,isBackground:u,opacity:I,preserveAspectRatio:_,rotateBy:e,saturate:o,scale:l,sepia:x,style:v,title:R}=s,a={};l!==void 0&&(a.transform=`scale(${l})`),b&&(a.transform=`scaleX(-${l!==void 0?l:1})`),y&&(a.transform=(a.transform?a.transform+" ":"")+`scaleY(-${l!==void 0?l:1})`),e&&(a.transform=(a.transform?a.transform+" ":"")+`rotate(${e}deg)`),I&&(a.opacity=I),g&&(a.filter=`brightness(${g})`),m&&(a.filter=(a.filter?a.filter+" ":"")+`contrast(${m})`),o&&(a.filter=(a.filter?a.filter+" ":"")+`saturate(${o})`),c&&(a.filter=(a.filter?a.filter+" ":"")+`blur(${c}px)`),C&&(a.filter=(a.filter?a.filter+" ":"")+`grayscale(${C})`),x&&(a.filter=(a.filter?a.filter+" ":"")+`sepia(${x})`),u&&r&&(a.zIndex=`${r} !important`);const E=N?i||"https://picsum.photos/200/300":i;return t.jsx("img",{ref:d,className:`ar-Image
3
- ${f&&!u?" fill w-100 h-100":""}
4
- ${_&&!u?" preserveAspectRatio":""}
5
- ${u?" position-absolute top-0 start-0 h-100 w-100":""}
6
- ${n?" "+n:""}
7
- `,crossOrigin:L(E),src:E,alt:h||"ar-image-placeholder",title:R,style:{...a,...v||{}}})});function S(s,d){const h=+s.value,c=+(s.min?s.min:0),g=+(s.max?s.max:100),n=Number((h-c)*100/(g-c));d.innerHTML=""+h;const m=-(n/100*16)+8;d.style.left=`calc(${n}% + ${m}px)`}const A=s=>{const{assistiveContent:d,classes:h,containerClasses:c,focussed:g,id:n,label:m,name:r,size:N,onBlur:f,onChange:b,onFocus:y,precision:C,type:i,value:u,withManual:I,..._}=s,e=p.useRef(null),o=p.useRef(null),[l,x]=p.useState();return p.useEffect(()=>{e.current&&o.current&&S(e.current,o.current),e.current&&e.current.addEventListener("input",()=>{e.current&&o.current&&S(e.current,o.current)})},[]),p.useEffect(()=>{u!==l&&x(u)},[u]),t.jsx("div",{className:`ar-Slider w-100${c?" "+c:""}`,children:t.jsxs("div",{className:"ar-Slider__control flex-v-center position-relative justify-content-between",children:[m&&t.jsx("label",{className:"me-3",htmlFor:n,children:t.jsx("strong",{children:m})}),t.jsxs("div",{className:"ar-Slider__slider-bar flex-center",children:[t.jsx("div",{className:"d-inline-block me-2",children:_.min}),t.jsxs("div",{className:"position-relative",children:[t.jsx("input",{ref:e,id:n,name:r||n,type:"range",className:`ar-TextInput__input h-100 py-2${h?" "+h:""}`,onChange:v=>{x(v.target.value),b&&b(v)},onFocus:y,onBlur:f,value:l,step:C,..._}),l&&t.jsx("output",{ref:o,className:"ar-Slider__bubble position-absolute",htmlFor:n})]}),t.jsx("div",{className:"d-inline-block ms-2",children:_.max}),I&&t.jsx("input",{className:"ar-Slider__manual-input",type:"text",value:l,onChange:v=>{x(v.target.value),b&&b(v)},title:"Maunal Value"})]})]})})};let $={rotateBy:0,brightness:1,contrast:1,saturate:1,grayscale:0,blur:0,sepia:0,opacity:1,scale:1};const w=s=>(s%360+360)%360,B=22.5,H=s=>{const{image:d,imageState:h,onChange:c,onCommit:g,viewOnly:n}=s;$={...$,...h};const m=p.useRef(null),[r,N]=p.useState({...$}),[f,b]=p.useState(),[y,C]=p.useState(),i=(e,o)=>{const l={...r,[e]:o},{rotateBy:x,...v}=l,{rotateBy:R,...a}=$;x!==void 0&&R!==void 0&&C(JSON.stringify(v)!==JSON.stringify(a)||w(x)!==w(R)),N(l),c&&c(l)},u=[{icon:"tb.TbFlipHorizontal",handler:()=>i("flipHorizontal",!r.flipHorizontal),tooltip:"Flip Horizontal"},{icon:"tb.TbFlipVertical",handler:()=>i("flipVertical",!r.flipVertical),tooltip:"Flip Vertical"},{icon:"ai.AiOutlineRotateLeft",handler:()=>i("rotateBy",r.rotateBy-B),tooltip:"Rotate Left"},{icon:"ai.AiOutlineRotateRight",handler:()=>i("rotateBy",r.rotateBy+B),tooltip:"Rotate Right"},{icon:"fi.FiZoomIn",handler:()=>i("scale",(r.scale+1)%10),tooltip:"Zoom In"},{icon:"fi.FiZoomOut",handler:()=>i("scale",(r.scale-1<0?0:r.scale-1)%10),tooltip:"Zoom Out"},{icon:f?"md.MdOutlineExpandLess":"md.MdOutlineExpandMore",handler:()=>b(!f),tooltip:f?"Hide Advanced Controls":"Show Advanced Controls"}],I=[{icon:"fi.FiZoomIn",handler:()=>N({...r,scale:(r.scale+1)%10}),tooltip:"Zoom In"},{icon:"fi.FiZoomOut",handler:()=>N({...r,scale:(r.scale-1<0?0:r.scale-1)%10}),tooltip:"Zoom Out"}],_=[[{label:"Brightness",min:0,max:5,precision:.1,handler:e=>i("brightness",+e.target.value)},{label:"Contrast",min:0,max:5,precision:.1,handler:e=>i("contrast",+e.target.value)}],[{label:"Saturation",min:0,max:10,precision:.2,handler:e=>i("saturate",+e.target.value)},{label:"Grayscale",min:0,max:1,precision:.05,handler:e=>i("grayscale",+e.target.value)}],[{label:"Blur",min:0,max:20,handler:e=>i("blur",+e.target.value)},{label:"Sepia",min:0,max:1,precision:.05,handler:e=>i("sepia",+e.target.value)}],[{label:"Opacity",min:0,max:1,precision:.05,handler:e=>i("opacity",+e.target.value)},{label:"Scale",min:0,max:10,precision:.2,handler:e=>i("scale",+e.target.value)}]];return t.jsxs("div",{className:"ar-ImageEditor d-flex flex-column h-100 overflow-auto flex-center position-relative",children:[!n&&t.jsxs("div",{className:"ar-ImageEditor__editor-controls position-absolute p-1 top-0 end-0 hover-shadow-dark",children:[t.jsxs(j.v,{children:[t.jsx("span",{className:"ar-ImageEditor__download-button cursor-pointer border-radius-50 p-1 me-2",slot:j.L.ANCHOR,children:t.jsx(O,{icon:"md/MdDownload",attributes:{colors:{fillColor:"#232323cc"},size:"1.5rem"},events:{onClick:()=>z.downloadEditedImage(m.current)}})}),t.jsx("span",{slot:j.L.POPOVER,children:"Download"})]}),t.jsxs(j.v,{children:[t.jsx("span",{className:`ar-ImageEditor__commit-button border-radius-50 p-1${y?" cursor-pointer is-dirty":""}`,slot:j.L.ANCHOR,children:t.jsx(O,{icon:"io5.IoCheckmarkCircleSharp",slot:j.L.ANCHOR,attributes:{colors:{fillColor:y?"#008000":"#00800077"},size:"1.5rem"},events:{onClick:()=>y&&g&&g(r)}})}),t.jsx("span",{slot:j.L.POPOVER,children:y?"Save":"Edit image to save"})]})]}),t.jsx("div",{className:"ar-ImageEditor__image-container mb-4",children:t.jsx(k,{ref:m,image:d,fill:!0,preserveAspectRatio:!0,...r})}),t.jsx("div",{className:"ar-ImageEditor__controls py-3 flex-center z-1 position-absolute",children:t.jsxs("div",{className:`ar-ImageEditor__controls-container border-radius prominent hover-shadow-dark${f?" expanded":""}`,children:[t.jsx("div",{className:`ar-ImageEditor__basic-controls px-3 py-2 ${f?"border-bottom":""}`,children:(n?I:u).map(e=>t.jsx(j.Control,{...e}))}),!n&&t.jsx("div",{className:"ar-ImageEditor__advanced-controls mt-2 px-3",children:_.map(e=>t.jsx("div",{className:"row pb-3 border-bottom",children:e.map(o=>t.jsx("div",{className:"col-6",children:t.jsx(A,{label:o.label,min:o.min,max:o.max,onChange:o.handler,precision:o.precision})}))}))})]})})]})};module.exports=H;
1
+ (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(".ar-ImageEditor .ar-ImageEditor__image-container{max-width:60vw;max-height:75vh}.ar-ImageEditor .ar-ImageEditor__editor-controls{transition:background-color .5s,box-shadow .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);border-radius:2rem}.ar-ImageEditor .ar-ImageEditor__editor-controls:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button.is-dirty:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__controls{bottom:0}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container{transition:background-color .5s,box-shadow .5s,max-height .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);max-height:3.2rem;overflow:hidden}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container.expanded{max-height:20rem}")),document.head.appendChild(r)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
2
+ "use strict";const t=require("react/jsx-runtime"),s=require("react"),r=require("./Control-chunk.js"),f=require("@armco/icon"),q=require("@armco/shared-components/Image"),y=require("@armco/shared-components/Tooltip"),z=require("@armco/shared-components/Slider"),A=require("./helper.js");require("@armco/utils/domHelper");let c={rotateBy:0,brightness:1,contrast:1,saturate:1,grayscale:0,blur:0,sepia:0,opacity:1,scale:1};const C=d=>(d%360+360)%360,j=22.5,F=d=>{const{image:O,imageState:E,onChange:h,onCommit:x,viewOnly:m}=d;c={...c,...E};const g=s.useRef(null),[o,p]=s.useState({...c}),[n,I]=s.useState(),[l,R]=s.useState(),a=(e,i)=>{const u={...o,[e]:i},{rotateBy:b,...w}=u,{rotateBy:v,...B}=c;b!==void 0&&v!==void 0&&R(JSON.stringify(w)!==JSON.stringify(B)||C(b)!==C(v)),p(u),h&&h(u)},_=[{icon:"tb.TbFlipHorizontal",handler:()=>a("flipHorizontal",!o.flipHorizontal),tooltip:"Flip Horizontal"},{icon:"tb.TbFlipVertical",handler:()=>a("flipVertical",!o.flipVertical),tooltip:"Flip Vertical"},{icon:"ai.AiOutlineRotateLeft",handler:()=>a("rotateBy",o.rotateBy-j),tooltip:"Rotate Left"},{icon:"ai.AiOutlineRotateRight",handler:()=>a("rotateBy",o.rotateBy+j),tooltip:"Rotate Right"},{icon:"fi.FiZoomIn",handler:()=>a("scale",(o.scale+1)%10),tooltip:"Zoom In"},{icon:"fi.FiZoomOut",handler:()=>a("scale",(o.scale-1<0?0:o.scale-1)%10),tooltip:"Zoom Out"},{icon:n?"md.MdOutlineExpandLess":"md.MdOutlineExpandMore",handler:()=>I(!n),tooltip:n?"Hide Advanced Controls":"Show Advanced Controls"}],N=[{icon:"fi.FiZoomIn",handler:()=>p({...o,scale:(o.scale+1)%10}),tooltip:"Zoom In"},{icon:"fi.FiZoomOut",handler:()=>p({...o,scale:(o.scale-1<0?0:o.scale-1)%10}),tooltip:"Zoom Out"}],S=[[{label:"Brightness",min:0,max:5,precision:.1,handler:e=>a("brightness",+e.target.value)},{label:"Contrast",min:0,max:5,precision:.1,handler:e=>a("contrast",+e.target.value)}],[{label:"Saturation",min:0,max:10,precision:.2,handler:e=>a("saturate",+e.target.value)},{label:"Grayscale",min:0,max:1,precision:.05,handler:e=>a("grayscale",+e.target.value)}],[{label:"Blur",min:0,max:20,handler:e=>a("blur",+e.target.value)},{label:"Sepia",min:0,max:1,precision:.05,handler:e=>a("sepia",+e.target.value)}],[{label:"Opacity",min:0,max:1,precision:.05,handler:e=>a("opacity",+e.target.value)},{label:"Scale",min:0,max:10,precision:.2,handler:e=>a("scale",+e.target.value)}]];return t.jsxs("div",{className:"ar-ImageEditor d-flex flex-column h-100 overflow-auto flex-center position-relative",children:[!m&&t.jsxs("div",{className:"ar-ImageEditor__editor-controls position-absolute p-1 top-0 end-0 hover-shadow-dark",children:[t.jsxs(y,{children:[t.jsx("span",{className:"ar-ImageEditor__download-button cursor-pointer border-radius-50 p-1 me-2",slot:r.L.ANCHOR,children:t.jsx(f,{icon:"md/MdDownload",attributes:{colors:{fillColor:"#232323cc"},size:"1.5rem"},events:{onClick:()=>A.downloadEditedImage(g.current)}})}),t.jsx("span",{slot:r.L.POPOVER,children:"Download"})]}),t.jsxs(y,{children:[t.jsx("span",{className:`ar-ImageEditor__commit-button border-radius-50 p-1${l?" cursor-pointer is-dirty":""}`,slot:r.L.ANCHOR,children:t.jsx(f,{icon:"io5.IoCheckmarkCircleSharp",slot:r.L.ANCHOR,attributes:{colors:{fillColor:l?"#008000":"#00800077"},size:"1.5rem"},events:{onClick:()=>l&&x&&x(o)}})}),t.jsx("span",{slot:r.L.POPOVER,children:l?"Save":"Edit image to save"})]})]}),t.jsx("div",{className:"ar-ImageEditor__image-container mb-4",children:t.jsx(q,{ref:g,image:O,fill:!0,preserveAspectRatio:!0,...o})}),t.jsx("div",{className:"ar-ImageEditor__controls py-3 flex-center z-1 position-absolute",children:t.jsxs("div",{className:`ar-ImageEditor__controls-container border-radius prominent hover-shadow-dark${n?" expanded":""}`,children:[t.jsx("div",{className:`ar-ImageEditor__basic-controls px-3 py-2 ${n?"border-bottom":""}`,children:(m?N:_).map(e=>t.jsx(r.Control,{...e}))}),!m&&t.jsx("div",{className:"ar-ImageEditor__advanced-controls mt-2 px-3",children:S.map(e=>t.jsx("div",{className:"row pb-3 border-bottom",children:e.map(i=>t.jsx("div",{className:"col-6",children:t.jsx(z,{label:i.label,min:i.min,max:i.max,onChange:i.handler,precision:i.precision})}))}))})]})})]})};module.exports=F;
package/cjs/helper.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react");require("react/jsx-runtime");const r=window.getComputedStyle(document.documentElement);parseFloat(r.fontSize);function c(t,a){const e=document.createElement("a");e.href=typeof t=="string"?t:window.URL.createObjectURL(t),e.download=a||"edited-image.png",document.body.appendChild(e),e.click(),document.body.removeChild(e)}const i=t=>{if(t){const a=document.createElement("canvas");a.width=t.naturalWidth,a.height=t.naturalHeight;const e=a.getContext("2d");if(!e)return;const s=t.style.filter,o=t.style.opacity,n=t.style.transform;e.filter=s!==""?s:"",e.globalAlpha=o!==""?parseFloat(o):1,n&&n!=="none"&&h(e,n,a),e.drawImage(t,0,0),c(a.toDataURL())}},h=(t,a,e)=>{const s=a.match(/rotate\((\d+(?:\.\d+)?)deg\)/);if(s){const d=parseFloat(s[1])*(Math.PI/180);t.translate(e.width/2,e.height/2),t.rotate(d),t.translate(-e.width/2,-e.height/2)}const o=a.match(/scale\((\d+(?:\.\d+)?)(?:,\s*(\d+(?:\.\d+)?))?\)/);if(o){const l=parseFloat(o[1]),d=o[2]?parseFloat(o[2]):l;t.scale(l,d)}const n=a.match(/translate\((\d+px)(?:,\s*(\d+px))?\)/);if(n){const l=parseFloat(n[1]),d=n[2]?parseFloat(n[2]):0;t.translate(l,d)}};exports.downloadEditedImage=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@armco/utils/domHelper"),d=t=>{if(t){const e=document.createElement("canvas");e.width=t.naturalWidth,e.height=t.naturalHeight;const a=e.getContext("2d");if(!a)return;const n=t.style.filter,s=t.style.opacity,o=t.style.transform;a.filter=n!==""?n:"",a.globalAlpha=s!==""?parseFloat(s):1,o&&o!=="none"&&i(a,o,e),a.drawImage(t,0,0),c.download(e.toDataURL())}},i=(t,e,a)=>{const n=e.match(/rotate\((\d+(?:\.\d+)?)deg\)/);if(n){const r=parseFloat(n[1])*(Math.PI/180);t.translate(a.width/2,a.height/2),t.rotate(r),t.translate(-a.width/2,-a.height/2)}const s=e.match(/scale\((\d+(?:\.\d+)?)(?:,\s*(\d+(?:\.\d+)?))?\)/);if(s){const l=parseFloat(s[1]),r=s[2]?parseFloat(s[2]):l;t.scale(l,r)}const o=e.match(/translate\((\d+px)(?:,\s*(\d+px))?\)/);if(o){const l=parseFloat(o[1]),r=o[2]?parseFloat(o[2]):0;t.translate(l,r)}};exports.downloadEditedImage=d;
@@ -1,336 +1,27 @@
1
- import { jsxs as Y, Fragment as at, jsx as H } from "react/jsx-runtime";
2
- import { useState as v, useEffect as L, useMemo as dt, useRef as x, useCallback as ut, Children as Tt } from "react";
3
- import ft from "react-dom";
4
- import pt from "@armco/icon";
5
- var G = /* @__PURE__ */ ((t) => (t.POPOVER = "popover", t.ANCHOR = "anchor", t))(G || {}), D = /* @__PURE__ */ ((t) => (t.POPOVER = "popover", t.ANCHOR = "anchor", t))(D || {}), B = /* @__PURE__ */ ((t) => (t.FADEINOUT = "fade", t.EXPANDSHRINK = "expand-shrink", t))(B || {}), Q = /* @__PURE__ */ ((t) => (t.TOPLEFT = "top-left", t.TOPRIGHT = "top-right", t.TOPCENTER = "top-center", t.RIGHTTOP = "right-top", t.RIGHTBOTTOM = "right-bottom", t.RIGHTCENTER = "right-center", t.BOTTOMLEFT = "bottom-left", t.BOTTOMRIGHT = "bottom-right", t.BOTTOMCENTER = "bottom-center", t.LEFTTOP = "left-top", t.LEFTBOTTOM = "left-bottom", t.LEFTCENTER = "left-center", t.BOTTOM = "bottom", t.RIGHT = "right", t.LEFT = "left", t.TOP = "top", t.AUTO = "auto", t))(Q || {}), E = /* @__PURE__ */ ((t) => (t.HOVER = "hover", t.CLICK = "click", t))(E || {}), d = /* @__PURE__ */ ((t) => (t.TOPLEFT = "top-left", t.TOPRIGHT = "top-right", t.TOPCENTER = "top-center", t.RIGHTTOP = "right-top", t.RIGHTBOTTOM = "right-bottom", t.RIGHTCENTER = "right-center", t.BOTTOMLEFT = "bottom-left", t.BOTTOMRIGHT = "bottom-right", t.BOTTOMCENTER = "bottom-center", t.LEFTTOP = "left-top", t.LEFTBOTTOM = "left-bottom", t.LEFTCENTER = "left-center", t.BOTTOM = "bottom", t.RIGHT = "right", t.LEFT = "left", t.TOP = "top", t.AUTO = "auto", t))(d || {});
6
- const mt = window.getComputedStyle(document.documentElement), w = parseFloat(mt.fontSize), A = 7;
7
- function Ot(t) {
8
- if (t) {
9
- const e = document.querySelector(".ar-Editor__frame");
10
- if (e)
11
- return e.contentDocument;
12
- }
13
- return document;
14
- }
15
- function Z(t) {
16
- if (t) {
17
- const e = document.querySelector(".ar-Editor__frame");
18
- if (e)
19
- return e.contentWindow;
20
- }
21
- return window;
22
- }
23
- function gt(t, e, o, l) {
24
- const n = Z(l) || window;
25
- if ({
26
- bottom: e.top + e.height + o.height > n.innerHeight,
27
- right: e.left + e.width + o.width > n.innerWidth,
28
- left: e.left - o.width < 0,
29
- top: e.top - o.height < 0
30
- }[t])
31
- return !1;
32
- if (t === "left" || t === "right") {
33
- if (w > e.top || w > e.bottom)
34
- return !1;
35
- } else if (w > e.left || w > e.right)
36
- return !1;
37
- return t;
38
- }
39
- function Et(t, e, o, l, n) {
40
- const c = {
41
- [d.BOTTOM]: {
42
- top: e.top + e.height + (l ? 0 : A) + (n || 0),
43
- left: e.left + (e.width - o.width) / 2
44
- },
45
- [d.RIGHT]: {
46
- top: e.top + (e.height - o.height) / 2,
47
- left: e.left + e.width + (l ? 0 : A)
48
- },
49
- [d.LEFT]: {
50
- top: e.top + (e.height - o.height) / 2,
51
- left: e.left - o.width - (l ? 0 : A)
52
- },
53
- [d.TOP]: {
54
- top: e.top - o.height - (l ? 0 : A) - (n || 0),
55
- left: e.left + (e.width - o.width) / 2
56
- }
57
- };
58
- let { left: r, top: h } = c[t];
59
- return t === d.BOTTOM || t === d.TOP ? (r < 0 && (r = w), r + o.width > window.innerWidth && (r = `calc(100% - ${o.width}px - ${w}px)`)) : (h < 0 && (h = w), h + o.height > window.innerHeight && (h = `calc(100% - ${o.height}px - ${w}px)`)), { left: r, top: h };
60
- }
61
- function wt(t, e, o, l) {
62
- if (o && o !== d.AUTO)
63
- return o;
64
- const n = [
65
- d.BOTTOM,
66
- d.RIGHT,
67
- d.LEFT,
68
- d.TOP
69
- ];
70
- for (const c of n)
71
- if (gt(c, t, e, l))
72
- return c;
73
- return d.BOTTOM;
74
- }
75
- function Rt(t, e, o, l, n, c, r) {
76
- const h = Z(c) || window;
77
- t = n ? {
78
- left: n[0],
79
- x: n[0],
80
- top: n[1],
81
- y: n[1],
82
- height: 0,
83
- width: 0,
84
- right: h.screen.width - n[0],
85
- bottom: h.screen.height - n[1],
86
- toJSON: () => {
87
- }
88
- } : t;
89
- const a = wt(
90
- t,
91
- e,
92
- o,
93
- c
94
- ), { left: f, top: m } = Et(
95
- a,
96
- t,
97
- e,
98
- l,
99
- r
100
- );
101
- return {
102
- leftTop: {
103
- top: ("" + m).startsWith("calc") ? m : m + "px",
104
- left: ("" + f).startsWith("calc") ? f : f + "px"
105
- },
106
- position: a
107
- };
108
- }
109
- const Ct = (t) => {
110
- const { children: e, classes: o, container: l, demo: n, styles: c } = t, [r, h] = v();
111
- return L(() => (h(l || document.createElement("div")), () => h(null)), [l]), L(() => {
112
- if (r) {
113
- const a = Ot(n);
114
- if (a) {
115
- const f = a.getElementById("root");
116
- f && f.appendChild(r);
117
- }
118
- return () => {
119
- if (a) {
120
- const f = a.getElementById("root");
121
- f && f.removeChild(r);
122
- }
123
- };
124
- }
125
- }, [r, n]), L(() => {
126
- r && (o && (r.className = o), r.classList.contains("ar-Portal") || r.classList.add("ar-Portal"), c && Object.assign(r.style, c));
127
- }, [o, c, r]), r ? ft.createPortal(e, r) : null;
128
- };
129
- let Pt = !1;
130
- const vt = {
131
- left: "right",
132
- right: "left",
133
- top: "bottom",
134
- bottom: "top"
135
- }, Lt = {
136
- left: "135",
137
- right: "-45",
138
- top: "-135",
139
- bottom: "45"
140
- }, Ht = (t) => {
141
- const {
142
- classes: e,
143
- children: o,
144
- closeOnSelfClick: l,
145
- contentClasses: n,
146
- contentMatchAnchorWidth: c,
147
- demo: r,
148
- disabled: h,
149
- hideMarker: a,
150
- invertBg: f,
151
- isOpen: m,
152
- isRaw: tt,
153
- onAnchorClick: _,
154
- onClose: R,
155
- popAtPointer: K,
156
- position: y = Q.AUTO,
157
- preserveMarkerSpace: V,
158
- stretch: et,
159
- topOffset: W,
160
- trigger: C = E.CLICK,
161
- animation: $,
162
- updateTriggers: ot,
163
- wrapText: rt,
164
- ...nt
165
- } = t, u = dt(
166
- () => $ && !Array.isArray($) ? [$] : $,
167
- [$]
168
- ), I = x(null), O = x(null), [g, M] = v(), [it, lt] = v(), [P, ct] = v(), [U, X] = v(), [b, k] = v(), F = x(), q = x(0), j = ut(() => {
169
- if (!I.current || !O.current)
170
- return;
171
- const i = I.current.getBoundingClientRect();
172
- c && (O.current.style.width = i.width + "px");
173
- const s = O.current.getBoundingClientRect();
174
- u && u.length > 0 && u.indexOf(B.EXPANDSHRINK) > -1 && (s.width = Math.floor(s.width * 1.25), s.height = Math.floor(s.height * 1.25));
175
- const { leftTop: T, position: p } = Rt(
176
- i,
177
- s,
178
- y,
179
- a && !V,
180
- K && C === E.CLICK ? F.current : null,
181
- r,
182
- W
183
- );
184
- lt(T), ct(p);
185
- }, [
186
- c,
187
- r,
188
- a,
189
- K,
190
- y,
191
- V,
192
- W,
193
- C,
194
- u
195
- ]);
196
- let S, z;
197
- return Tt.forEach(o, (i) => {
198
- var s, T;
199
- ((s = i == null ? void 0 : i.props) == null ? void 0 : s.slot) === D.ANCHOR && (z = i), ((T = i == null ? void 0 : i.props) == null ? void 0 : T.slot) === D.POPOVER && (S = i);
200
- }), L(() => {
201
- m !== void 0 && (M(m), m && !b && k(!0));
202
- }, [m, b]), L(() => {
203
- var i;
204
- let s = (T) => {
205
- I.current && !I.current.contains(T.target) && O.current && !O.current.contains(T.target) && (M(!1), R && R());
206
- };
207
- if (C === E.CLICK && g) {
208
- document.addEventListener("mousedown", s);
209
- const T = document.querySelector("iframe");
210
- return T && ((i = T.contentWindow) == null || i.document.addEventListener("mousedown", s)), () => {
211
- var p;
212
- document.removeEventListener("click", s);
213
- const N = document.querySelector("iframe");
214
- N && ((p = N.contentWindow) == null || p.document.removeEventListener("click", s));
215
- };
216
- }
217
- }, [C, g, R]), L(() => {
218
- b && g && (j(), X(!0));
219
- }, [
220
- g,
221
- b,
222
- j,
223
- // eslint-disable-next-line react-hooks/exhaustive-deps
224
- ...ot || []
225
- ]), L(() => {
226
- if (!a && O.current && U && P) {
227
- const i = O.current, s = I.current.getBoundingClientRect(), T = vt[P], p = i.getBoundingClientRect();
228
- u && u.length > 0 && u.indexOf(B.EXPANDSHRINK) > -1 && (p.width = Math.floor(p.width * 1.25), p.height = Math.floor(p.height * 1.25));
229
- const N = P === "top" || P === "bottom";
230
- let J = s[N ? "width" : "height"] / 2 - 7;
231
- const st = s.left - p.left + J, ht = s.top - p.top + J;
232
- i.style.setProperty(
233
- "--marker-transform",
234
- `rotate(${Lt[P]}deg)`
235
- ), i.style.setProperty(
236
- `--marker-${T}`,
237
- "-0.35rem"
238
- ), i.style.setProperty(
239
- `--marker-${P}`,
240
- "initial"
241
- ), i.style.setProperty(
242
- `--marker-${N ? "left" : "top"}`,
243
- (N ? st : ht) + "px"
244
- ), X(!1);
245
- }
246
- }, [
247
- U,
248
- O,
249
- a,
250
- P,
251
- F,
252
- u
253
- ]), /* @__PURE__ */ Y(at, { children: [
254
- /* @__PURE__ */ H(
255
- "span",
256
- {
257
- className: `ar-Popover__anchor${e ? " " + e : ""}${et ? " w-100" : ""}`,
258
- onMouseDown: (i) => {
259
- F.current = [i.clientX, i.clientY], Date.now() - q.current < 500 || (q.current = Date.now(), C === E.CLICK && !Pt && !h && (!b && k(!0), (m === void 0 || m) && setTimeout(() => M(!g), 0)), g && R && R(), _ && _(!g));
260
- },
261
- ref: I,
262
- onMouseEnter: () => {
263
- C === E.HOVER && !h && (k(!0), setTimeout(() => M(!0), 0));
264
- },
265
- onMouseLeave: () => {
266
- C === E.HOVER && !h && (setTimeout(() => M(!1), 0), R && R());
267
- },
268
- ...nt,
269
- children: z
270
- }
271
- ),
272
- S && b && /* @__PURE__ */ H(
273
- Ct,
274
- {
275
- classes: `position-fixed popover-container${g ? " z-3000" : " invisible"}`,
276
- demo: r,
277
- styles: it || {},
278
- children: /* @__PURE__ */ H(
279
- "div",
280
- {
281
- className: `ar-Popover__content${f ? " invert-bg" : ""}${rt ? " wrap" : ""}${y ? " " + y : ""} ${n}${u && u.length > 0 ? " transition " + (u == null ? void 0 : u.join(" ")) : ""} ${g ? " show" : ""}${a ? " hide-marker" : ""}${tt ? "" : " p-1 border-radius l2 f25"}`,
282
- onClick: () => l && M(!1),
283
- ref: O,
284
- children: S
285
- }
286
- )
287
- }
288
- )
289
- ] });
290
- }, It = (t) => {
291
- const { children: e, demo: o, ...l } = t, [n, c] = v();
292
- return /* @__PURE__ */ H(
293
- Ht,
294
- {
295
- contentClasses: "overflow-auto",
296
- trigger: E.HOVER,
297
- onAnchorClick: () => {
298
- c(!1), setTimeout(() => c(void 0), 10);
299
- },
300
- animation: [
301
- B.EXPANDSHRINK,
302
- B.FADEINOUT
303
- ],
304
- demo: o,
305
- isOpen: n,
306
- hideMarker: !0,
307
- preserveMarkerSpace: !0,
308
- wrapText: !0,
309
- ...l,
310
- children: e
311
- }
312
- );
313
- }, Bt = ({
314
- icon: t,
315
- handler: e,
316
- tooltip: o
317
- }) => /* @__PURE__ */ Y(It, { children: [
318
- /* @__PURE__ */ H("span", { className: "mx-3 p-1 cursor-pointer", slot: G.ANCHOR, children: /* @__PURE__ */ H(
319
- pt,
1
+ import { jsxs as l, jsx as r } from "react/jsx-runtime";
2
+ import n from "@armco/shared-components/Tooltip";
3
+ import i from "@armco/icon";
4
+ var s = /* @__PURE__ */ ((o) => (o.POPOVER = "popover", o.ANCHOR = "anchor", o))(s || {});
5
+ const a = ({
6
+ icon: o,
7
+ handler: t,
8
+ tooltip: e
9
+ }) => /* @__PURE__ */ l(n, { children: [
10
+ /* @__PURE__ */ r("span", { className: "mx-3 p-1 cursor-pointer", slot: s.ANCHOR, children: /* @__PURE__ */ r(
11
+ i,
320
12
  {
321
- icon: t,
13
+ icon: o,
322
14
  attributes: {
323
15
  colors: { fillColor: "#ffffff99" },
324
16
  classes: "cursor-pointer",
325
17
  size: "2rem"
326
18
  },
327
- events: { onClick: e }
19
+ events: { onClick: t }
328
20
  }
329
21
  ) }),
330
- /* @__PURE__ */ H("span", { slot: G.POPOVER, children: o })
22
+ /* @__PURE__ */ r("span", { slot: s.POPOVER, children: e })
331
23
  ] });
332
24
  export {
333
- Bt as C,
334
- G as L,
335
- It as v
25
+ a as C,
26
+ s as L
336
27
  };
package/es/Control.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import "react/jsx-runtime";
2
- import { C as a } from "./Control-chunk.js";
2
+ import { C as i } from "./Control-chunk.js";
3
+ import "@armco/shared-components/Tooltip";
3
4
  import "@armco/icon";
4
- import "react";
5
- import "react-dom";
6
5
  export {
7
- a as default
6
+ i as default
8
7
  };
package/es/ImageEditor.js CHANGED
@@ -1,145 +1,14 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode('.ar-Image{transition:all .3s}.ar-Image.fill{object-fit:cover}.ar-Image.fill.preserveAspectRatio{object-fit:contain}.ar-Slider input[type=range]{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;cursor:pointer}.ar-Slider input[type=range]:hover+.ar-Slider__bubble{opacity:1}.ar-Slider input[type=range]:focus{outline:none}.ar-Slider input[type=range]::-webkit-slider-runnable-track{background-color:#053a5f;border-radius:.2rem;height:.2rem}.ar-Slider input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin-top:-6.5px;transition:outline .5s;background-color:var(--ar-bg-slider-track);height:1rem;width:1rem;border-radius:50%}.ar-Slider input[type=range]::-webkit-slider-thumb:hover{border:5px solid var(--ar-bg-slider-track)}.ar-Slider input[type=range]:focus::-webkit-slider-thumb{border:1px solid #053a5f}.ar-Slider input[type=range]::-moz-range-track{background-color:#053a5f;border-radius:.2rem;height:.2rem}.ar-Slider input[type=range]::-moz-range-thumb{border:none;border-radius:0;background-color:var(--ar-bg-slider-track);height:1rem;width:1rem}.ar-Slider input[type=range]:focus::-moz-range-thumb{border:1px solid #053a5f}.ar-Slider .ar-Slider__bubble{background:#454545;color:#fff;padding:4px 12px;border-radius:4px;left:50%;bottom:-1.5rem;transform:translate(-50%);opacity:0;transition:opacity .3s}.ar-Slider .ar-Slider__bubble:after{content:"";position:absolute;width:4px;height:4px;transform:rotate(45deg);background:#454545;top:-2px;left:50%}.ar-Slider .ar-Slider__manual-input{width:2rem}.ar-ImageEditor .ar-ImageEditor__image-container{max-width:60vw;max-height:75vh}.ar-ImageEditor .ar-ImageEditor__editor-controls{transition:background-color .5s,box-shadow .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);border-radius:2rem}.ar-ImageEditor .ar-ImageEditor__editor-controls:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button.is-dirty:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__controls{bottom:0}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container{transition:background-color .5s,box-shadow .5s,max-height .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);max-height:3.2rem;overflow:hidden}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container.expanded{max-height:20rem}.ar-Portal{z-index:2001;white-space:nowrap}.ar-Popover__anchor:focus-visible{outline:none}:root{--marker-transform: rotate(45deg);--marker-top: -.4rem;--marker-left: 10%;--marker-right: unset;--marker-bottom: unset}:root .ar-Popover__content{box-shadow:0 4px 8px -2px #091e4240,0 0 1px #091e424f;z-index:2002;background-color:var(--ar-bg);white-space:nowrap;position:relative;border:1px solid var(--ar-color-border)}:root .ar-Popover__content>*{position:relative}:root .ar-Popover__content.invert-bg{background-color:var(--ar-bg-invert-1)}:root .ar-Popover__content.wrap{white-space:wrap}:root .ar-Popover__content:not(.hide-marker):before{content:"";background-color:var(--ar-bg);position:absolute;height:.7rem;width:.7rem;border-width:1px;border-style:solid;border-color:var(--ar-color-border) transparent transparent var(--ar-color-border);transform:var(--marker-transform);top:var(--marker-top);left:var(--marker-left);right:var(--marker-right);bottom:var(--marker-bottom)}:root .ar-Popover__content.invert-bg:not(.hide-marker):before{background-color:var(--ar-bg-invert-1)}:root .ar-Popover__content.transition{transition:width .15s ease-in-out,height .15s ease-in-out,opacity .3s ease-in-out,transform .15s ease-in-out}:root .ar-Popover__content.transition.expand-shrink{transform:scale(.8)}:root .ar-Popover__content.transition.show{transform:scale(1)}@media (min-width: 576px){:root .ar-Popover__content{max-width:25vw}}:root .ar-List__item{line-height:1.5rem}:root .ar-List__item:hover{background-color:var(--ar-color-font);color:var(--ar-color-font-invert);cursor:pointer}')),document.head.appendChild(r)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
2
- import { jsx as a, jsxs as x } from "react/jsx-runtime";
3
- import { forwardRef as L, useRef as w, useState as R, useEffect as B } from "react";
4
- import { v as z, L as I, C as V } from "./Control-chunk.js";
5
- import F from "@armco/icon";
6
- import { downloadEditedImage as Z } from "./helper.js";
7
- import "react-dom";
8
- const M = (i) => new URL(i).hostname, D = (i) => {
9
- const d = M(i);
10
- return d === "localhost" || d === "armco.tech" ? "use-credentials" : "anonymous";
11
- }, P = L(
12
- (i, d) => {
13
- const {
14
- alt: u,
15
- blur: c,
16
- brightness: v,
17
- classes: s,
18
- contrast: m,
19
- customBgZIndex: r,
20
- demo: N,
21
- fill: h,
22
- flipHorizontal: b,
23
- flipVertical: y,
24
- grayscale: C,
25
- image: o,
26
- isBackground: p,
27
- opacity: $,
28
- preserveAspectRatio: _,
29
- rotateBy: e,
30
- saturate: l,
31
- scale: n,
32
- sepia: f,
33
- style: g,
34
- title: O
35
- } = i, t = {};
36
- n !== void 0 && (t.transform = `scale(${n})`), b && (t.transform = `scaleX(-${n !== void 0 ? n : 1})`), y && (t.transform = (t.transform ? t.transform + " " : "") + `scaleY(-${n !== void 0 ? n : 1})`), e && (t.transform = (t.transform ? t.transform + " " : "") + `rotate(${e}deg)`), $ && (t.opacity = $), v && (t.filter = `brightness(${v})`), m && (t.filter = (t.filter ? t.filter + " " : "") + `contrast(${m})`), l && (t.filter = (t.filter ? t.filter + " " : "") + `saturate(${l})`), c && (t.filter = (t.filter ? t.filter + " " : "") + `blur(${c}px)`), C && (t.filter = (t.filter ? t.filter + " " : "") + `grayscale(${C})`), f && (t.filter = (t.filter ? t.filter + " " : "") + `sepia(${f})`), p && r && (t.zIndex = `${r} !important`);
37
- const S = N ? o || "https://picsum.photos/200/300" : o;
38
- return /* @__PURE__ */ a(
39
- "img",
40
- {
41
- ref: d,
42
- className: `ar-Image
43
- ${h && !p ? " fill w-100 h-100" : ""}
44
- ${_ && !p ? " preserveAspectRatio" : ""}
45
- ${p ? " position-absolute top-0 start-0 h-100 w-100" : ""}
46
- ${s ? " " + s : ""}
47
- `,
48
- crossOrigin: D(S),
49
- src: S,
50
- alt: u || "ar-image-placeholder",
51
- title: O,
52
- style: { ...t, ...g || {} }
53
- }
54
- );
55
- }
56
- );
57
- function k(i, d) {
58
- const u = +i.value, c = +(i.min ? i.min : 0), v = +(i.max ? i.max : 100), s = Number((u - c) * 100 / (v - c));
59
- d.innerHTML = "" + u;
60
- const m = -(s / 100 * 16) + 8;
61
- d.style.left = `calc(${s}% + ${m}px)`;
62
- }
63
- const T = (i) => {
64
- const {
65
- assistiveContent: d,
66
- classes: u,
67
- containerClasses: c,
68
- focussed: v,
69
- id: s,
70
- label: m,
71
- name: r,
72
- size: N,
73
- onBlur: h,
74
- onChange: b,
75
- onFocus: y,
76
- precision: C,
77
- type: o,
78
- value: p,
79
- withManual: $,
80
- ..._
81
- } = i, e = w(null), l = w(null), [n, f] = R();
82
- return B(() => {
83
- e.current && l.current && k(e.current, l.current), e.current && e.current.addEventListener("input", () => {
84
- e.current && l.current && k(e.current, l.current);
85
- });
86
- }, []), B(() => {
87
- p !== n && f(p);
88
- }, [p]), /* @__PURE__ */ a(
89
- "div",
90
- {
91
- className: `ar-Slider w-100${c ? " " + c : ""}`,
92
- children: /* @__PURE__ */ x("div", { className: "ar-Slider__control flex-v-center position-relative justify-content-between", children: [
93
- m && /* @__PURE__ */ a("label", { className: "me-3", htmlFor: s, children: /* @__PURE__ */ a("strong", { children: m }) }),
94
- /* @__PURE__ */ x("div", { className: "ar-Slider__slider-bar flex-center", children: [
95
- /* @__PURE__ */ a("div", { className: "d-inline-block me-2", children: _.min }),
96
- /* @__PURE__ */ x("div", { className: "position-relative", children: [
97
- /* @__PURE__ */ a(
98
- "input",
99
- {
100
- ref: e,
101
- id: s,
102
- name: r || s,
103
- type: "range",
104
- className: `ar-TextInput__input h-100 py-2${u ? " " + u : ""}`,
105
- onChange: (g) => {
106
- f(g.target.value), b && b(g);
107
- },
108
- onFocus: y,
109
- onBlur: h,
110
- value: n,
111
- step: C,
112
- ..._
113
- }
114
- ),
115
- n && /* @__PURE__ */ a(
116
- "output",
117
- {
118
- ref: l,
119
- className: "ar-Slider__bubble position-absolute",
120
- htmlFor: s
121
- }
122
- )
123
- ] }),
124
- /* @__PURE__ */ a("div", { className: "d-inline-block ms-2", children: _.max }),
125
- $ && /* @__PURE__ */ a(
126
- "input",
127
- {
128
- className: "ar-Slider__manual-input",
129
- type: "text",
130
- value: n,
131
- onChange: (g) => {
132
- f(g.target.value), b && b(g);
133
- },
134
- title: "Maunal Value"
135
- }
136
- )
137
- ] })
138
- ] })
139
- }
140
- );
141
- };
142
- let E = {
1
+ (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(".ar-ImageEditor .ar-ImageEditor__image-container{max-width:60vw;max-height:75vh}.ar-ImageEditor .ar-ImageEditor__editor-controls{transition:background-color .5s,box-shadow .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);border-radius:2rem}.ar-ImageEditor .ar-ImageEditor__editor-controls:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__download-button:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button{width:2rem;height:2rem;display:inline-block}.ar-ImageEditor .ar-ImageEditor__editor-controls .ar-ImageEditor__commit-button.is-dirty:hover{background-color:var(--ar-bg-tertiary-faded-2)}.ar-ImageEditor .ar-ImageEditor__controls{bottom:0}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container{transition:background-color .5s,box-shadow .5s,max-height .5s ease-in-out;background-color:var(--ar-bg-tertiary-faded-2);max-height:3.2rem;overflow:hidden}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container:hover{background-color:var(--ar-bg-tertiary-faded)}.ar-ImageEditor .ar-ImageEditor__controls .ar-ImageEditor__controls-container.expanded{max-height:20rem}")),document.head.appendChild(r)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
2
+ import { jsxs as l, jsx as t } from "react/jsx-runtime";
3
+ import { useRef as F, useState as u } from "react";
4
+ import { L as n, C as H } from "./Control-chunk.js";
5
+ import y from "@armco/icon";
6
+ import Z from "@armco/shared-components/Image";
7
+ import C from "@armco/shared-components/Tooltip";
8
+ import k from "@armco/shared-components/Slider";
9
+ import { downloadEditedImage as V } from "./helper.js";
10
+ import "@armco/utils/domHelper";
11
+ let c = {
143
12
  rotateBy: 0,
144
13
  brightness: 1,
145
14
  contrast: 1,
@@ -150,85 +19,85 @@ let E = {
150
19
  opacity: 1,
151
20
  scale: 1
152
21
  };
153
- const A = (i) => (i % 360 + 360) % 360, H = 22.5, q = (i) => {
154
- const { image: d, imageState: u, onChange: c, onCommit: v, viewOnly: s } = i;
155
- E = {
156
- ...E,
157
- ...u
22
+ const O = (d) => (d % 360 + 360) % 360, E = 22.5, q = (d) => {
23
+ const { image: I, imageState: R, onChange: g, onCommit: b, viewOnly: m } = d;
24
+ c = {
25
+ ...c,
26
+ ...R
158
27
  };
159
- const m = w(null), [r, N] = R({ ...E }), [h, b] = R(), [y, C] = R(), o = (e, l) => {
160
- const n = { ...r, [e]: l }, { rotateBy: f, ...g } = n, { rotateBy: O, ...t } = E;
161
- f !== void 0 && O !== void 0 && C(
162
- JSON.stringify(g) !== JSON.stringify(t) || A(f) !== A(O)
163
- ), N(n), c && c(n);
164
- }, p = [
28
+ const v = F(null), [o, p] = u({ ...c }), [r, _] = u(), [s, N] = u(), a = (e, i) => {
29
+ const h = { ...o, [e]: i }, { rotateBy: f, ...z } = h, { rotateBy: x, ...A } = c;
30
+ f !== void 0 && x !== void 0 && N(
31
+ JSON.stringify(z) !== JSON.stringify(A) || O(f) !== O(x)
32
+ ), p(h), g && g(h);
33
+ }, S = [
165
34
  {
166
35
  icon: "tb.TbFlipHorizontal",
167
- handler: () => o("flipHorizontal", !r.flipHorizontal),
36
+ handler: () => a("flipHorizontal", !o.flipHorizontal),
168
37
  tooltip: "Flip Horizontal"
169
38
  },
170
39
  {
171
40
  icon: "tb.TbFlipVertical",
172
- handler: () => o("flipVertical", !r.flipVertical),
41
+ handler: () => a("flipVertical", !o.flipVertical),
173
42
  tooltip: "Flip Vertical"
174
43
  },
175
44
  {
176
45
  icon: "ai.AiOutlineRotateLeft",
177
- handler: () => o("rotateBy", r.rotateBy - H),
46
+ handler: () => a("rotateBy", o.rotateBy - E),
178
47
  tooltip: "Rotate Left"
179
48
  },
180
49
  {
181
50
  icon: "ai.AiOutlineRotateRight",
182
- handler: () => o("rotateBy", r.rotateBy + H),
51
+ handler: () => a("rotateBy", o.rotateBy + E),
183
52
  tooltip: "Rotate Right"
184
53
  },
185
54
  {
186
55
  icon: "fi.FiZoomIn",
187
- handler: () => o("scale", (r.scale + 1) % 10),
56
+ handler: () => a("scale", (o.scale + 1) % 10),
188
57
  tooltip: "Zoom In"
189
58
  },
190
59
  {
191
60
  icon: "fi.FiZoomOut",
192
- handler: () => o(
61
+ handler: () => a(
193
62
  "scale",
194
- (r.scale - 1 < 0 ? 0 : r.scale - 1) % 10
63
+ (o.scale - 1 < 0 ? 0 : o.scale - 1) % 10
195
64
  ),
196
65
  tooltip: "Zoom Out"
197
66
  },
198
67
  {
199
- icon: h ? "md.MdOutlineExpandLess" : "md.MdOutlineExpandMore",
200
- handler: () => b(!h),
201
- tooltip: h ? "Hide Advanced Controls" : "Show Advanced Controls"
68
+ icon: r ? "md.MdOutlineExpandLess" : "md.MdOutlineExpandMore",
69
+ handler: () => _(!r),
70
+ tooltip: r ? "Hide Advanced Controls" : "Show Advanced Controls"
202
71
  }
203
- ], $ = [
72
+ ], w = [
204
73
  {
205
74
  icon: "fi.FiZoomIn",
206
- handler: () => N({ ...r, scale: (r.scale + 1) % 10 }),
75
+ handler: () => p({ ...o, scale: (o.scale + 1) % 10 }),
207
76
  tooltip: "Zoom In"
208
77
  },
209
78
  {
210
79
  icon: "fi.FiZoomOut",
211
- handler: () => N({
212
- ...r,
213
- scale: (r.scale - 1 < 0 ? 0 : r.scale - 1) % 10
80
+ handler: () => p({
81
+ ...o,
82
+ scale: (o.scale - 1 < 0 ? 0 : o.scale - 1) % 10
214
83
  }),
215
84
  tooltip: "Zoom Out"
216
85
  }
217
- ], _ = [
86
+ ], B = [
218
87
  [
219
88
  {
220
89
  label: "Brightness",
221
90
  min: 0,
222
91
  max: 5,
223
92
  precision: 0.1,
224
- handler: (e) => o("brightness", +e.target.value)
93
+ handler: (e) => a("brightness", +e.target.value)
225
94
  },
226
95
  {
227
96
  label: "Contrast",
228
97
  min: 0,
229
98
  max: 5,
230
99
  precision: 0.1,
231
- handler: (e) => o("contrast", +e.target.value)
100
+ handler: (e) => a("contrast", +e.target.value)
232
101
  }
233
102
  ],
234
103
  [
@@ -237,14 +106,14 @@ const A = (i) => (i % 360 + 360) % 360, H = 22.5, q = (i) => {
237
106
  min: 0,
238
107
  max: 10,
239
108
  precision: 0.2,
240
- handler: (e) => o("saturate", +e.target.value)
109
+ handler: (e) => a("saturate", +e.target.value)
241
110
  },
242
111
  {
243
112
  label: "Grayscale",
244
113
  min: 0,
245
114
  max: 1,
246
115
  precision: 0.05,
247
- handler: (e) => o("grayscale", +e.target.value)
116
+ handler: (e) => a("grayscale", +e.target.value)
248
117
  }
249
118
  ],
250
119
  [
@@ -252,14 +121,14 @@ const A = (i) => (i % 360 + 360) % 360, H = 22.5, q = (i) => {
252
121
  label: "Blur",
253
122
  min: 0,
254
123
  max: 20,
255
- handler: (e) => o("blur", +e.target.value)
124
+ handler: (e) => a("blur", +e.target.value)
256
125
  },
257
126
  {
258
127
  label: "Sepia",
259
128
  min: 0,
260
129
  max: 1,
261
130
  precision: 0.05,
262
- handler: (e) => o("sepia", +e.target.value)
131
+ handler: (e) => a("sepia", +e.target.value)
263
132
  }
264
133
  ],
265
134
  [
@@ -268,27 +137,27 @@ const A = (i) => (i % 360 + 360) % 360, H = 22.5, q = (i) => {
268
137
  min: 0,
269
138
  max: 1,
270
139
  precision: 0.05,
271
- handler: (e) => o("opacity", +e.target.value)
140
+ handler: (e) => a("opacity", +e.target.value)
272
141
  },
273
142
  {
274
143
  label: "Scale",
275
144
  min: 0,
276
145
  max: 10,
277
146
  precision: 0.2,
278
- handler: (e) => o("scale", +e.target.value)
147
+ handler: (e) => a("scale", +e.target.value)
279
148
  }
280
149
  ]
281
150
  ];
282
- return /* @__PURE__ */ x("div", { className: "ar-ImageEditor d-flex flex-column h-100 overflow-auto flex-center position-relative", children: [
283
- !s && /* @__PURE__ */ x("div", { className: "ar-ImageEditor__editor-controls position-absolute p-1 top-0 end-0 hover-shadow-dark", children: [
284
- /* @__PURE__ */ x(z, { children: [
285
- /* @__PURE__ */ a(
151
+ return /* @__PURE__ */ l("div", { className: "ar-ImageEditor d-flex flex-column h-100 overflow-auto flex-center position-relative", children: [
152
+ !m && /* @__PURE__ */ l("div", { className: "ar-ImageEditor__editor-controls position-absolute p-1 top-0 end-0 hover-shadow-dark", children: [
153
+ /* @__PURE__ */ l(C, { children: [
154
+ /* @__PURE__ */ t(
286
155
  "span",
287
156
  {
288
157
  className: "ar-ImageEditor__download-button cursor-pointer border-radius-50 p-1 me-2",
289
- slot: I.ANCHOR,
290
- children: /* @__PURE__ */ a(
291
- F,
158
+ slot: n.ANCHOR,
159
+ children: /* @__PURE__ */ t(
160
+ y,
292
161
  {
293
162
  icon: "md/MdDownload",
294
163
  attributes: {
@@ -296,69 +165,69 @@ const A = (i) => (i % 360 + 360) % 360, H = 22.5, q = (i) => {
296
165
  size: "1.5rem"
297
166
  },
298
167
  events: {
299
- onClick: () => Z(m.current)
168
+ onClick: () => V(v.current)
300
169
  }
301
170
  }
302
171
  )
303
172
  }
304
173
  ),
305
- /* @__PURE__ */ a("span", { slot: I.POPOVER, children: "Download" })
174
+ /* @__PURE__ */ t("span", { slot: n.POPOVER, children: "Download" })
306
175
  ] }),
307
- /* @__PURE__ */ x(z, { children: [
308
- /* @__PURE__ */ a(
176
+ /* @__PURE__ */ l(C, { children: [
177
+ /* @__PURE__ */ t(
309
178
  "span",
310
179
  {
311
- className: `ar-ImageEditor__commit-button border-radius-50 p-1${y ? " cursor-pointer is-dirty" : ""}`,
312
- slot: I.ANCHOR,
313
- children: /* @__PURE__ */ a(
314
- F,
180
+ className: `ar-ImageEditor__commit-button border-radius-50 p-1${s ? " cursor-pointer is-dirty" : ""}`,
181
+ slot: n.ANCHOR,
182
+ children: /* @__PURE__ */ t(
183
+ y,
315
184
  {
316
185
  icon: "io5.IoCheckmarkCircleSharp",
317
- slot: I.ANCHOR,
186
+ slot: n.ANCHOR,
318
187
  attributes: {
319
- colors: { fillColor: y ? "#008000" : "#00800077" },
188
+ colors: { fillColor: s ? "#008000" : "#00800077" },
320
189
  size: "1.5rem"
321
190
  },
322
191
  events: {
323
- onClick: () => y && v && v(r)
192
+ onClick: () => s && b && b(o)
324
193
  }
325
194
  }
326
195
  )
327
196
  }
328
197
  ),
329
- /* @__PURE__ */ a("span", { slot: I.POPOVER, children: y ? "Save" : "Edit image to save" })
198
+ /* @__PURE__ */ t("span", { slot: n.POPOVER, children: s ? "Save" : "Edit image to save" })
330
199
  ] })
331
200
  ] }),
332
- /* @__PURE__ */ a("div", { className: "ar-ImageEditor__image-container mb-4", children: /* @__PURE__ */ a(
333
- P,
201
+ /* @__PURE__ */ t("div", { className: "ar-ImageEditor__image-container mb-4", children: /* @__PURE__ */ t(
202
+ Z,
334
203
  {
335
- ref: m,
336
- image: d,
204
+ ref: v,
205
+ image: I,
337
206
  fill: !0,
338
207
  preserveAspectRatio: !0,
339
- ...r
208
+ ...o
340
209
  }
341
210
  ) }),
342
- /* @__PURE__ */ a("div", { className: "ar-ImageEditor__controls py-3 flex-center z-1 position-absolute", children: /* @__PURE__ */ x(
211
+ /* @__PURE__ */ t("div", { className: "ar-ImageEditor__controls py-3 flex-center z-1 position-absolute", children: /* @__PURE__ */ l(
343
212
  "div",
344
213
  {
345
- className: `ar-ImageEditor__controls-container border-radius prominent hover-shadow-dark${h ? " expanded" : ""}`,
214
+ className: `ar-ImageEditor__controls-container border-radius prominent hover-shadow-dark${r ? " expanded" : ""}`,
346
215
  children: [
347
- /* @__PURE__ */ a(
216
+ /* @__PURE__ */ t(
348
217
  "div",
349
218
  {
350
- className: `ar-ImageEditor__basic-controls px-3 py-2 ${h ? "border-bottom" : ""}`,
351
- children: (s ? $ : p).map((e) => /* @__PURE__ */ a(V, { ...e }))
219
+ className: `ar-ImageEditor__basic-controls px-3 py-2 ${r ? "border-bottom" : ""}`,
220
+ children: (m ? w : S).map((e) => /* @__PURE__ */ t(H, { ...e }))
352
221
  }
353
222
  ),
354
- !s && /* @__PURE__ */ a("div", { className: "ar-ImageEditor__advanced-controls mt-2 px-3", children: _.map((e) => /* @__PURE__ */ a("div", { className: "row pb-3 border-bottom", children: e.map((l) => /* @__PURE__ */ a("div", { className: "col-6", children: /* @__PURE__ */ a(
355
- T,
223
+ !m && /* @__PURE__ */ t("div", { className: "ar-ImageEditor__advanced-controls mt-2 px-3", children: B.map((e) => /* @__PURE__ */ t("div", { className: "row pb-3 border-bottom", children: e.map((i) => /* @__PURE__ */ t("div", { className: "col-6", children: /* @__PURE__ */ t(
224
+ k,
356
225
  {
357
- label: l.label,
358
- min: l.min,
359
- max: l.max,
360
- onChange: l.handler,
361
- precision: l.precision
226
+ label: i.label,
227
+ min: i.min,
228
+ max: i.max,
229
+ onChange: i.handler,
230
+ precision: i.precision
362
231
  }
363
232
  ) })) })) })
364
233
  ]
package/es/helper.js CHANGED
@@ -1,40 +1,33 @@
1
- import "react";
2
- import "react/jsx-runtime";
3
- const d = window.getComputedStyle(document.documentElement);
4
- parseFloat(d.fontSize);
5
- function r(t, a) {
6
- const e = document.createElement("a");
7
- e.href = typeof t == "string" ? t : window.URL.createObjectURL(t), e.download = a || "edited-image.png", document.body.appendChild(e), e.click(), document.body.removeChild(e);
8
- }
9
- const f = (t) => {
1
+ import { download as c } from "@armco/utils/domHelper";
2
+ const i = (t) => {
10
3
  if (t) {
11
- const a = document.createElement("canvas");
12
- a.width = t.naturalWidth, a.height = t.naturalHeight;
13
- const e = a.getContext("2d");
14
- if (!e)
4
+ const e = document.createElement("canvas");
5
+ e.width = t.naturalWidth, e.height = t.naturalHeight;
6
+ const a = e.getContext("2d");
7
+ if (!a)
15
8
  return;
16
- const s = t.style.filter, o = t.style.opacity, n = t.style.transform;
17
- e.filter = s !== "" ? s : "", e.globalAlpha = o !== "" ? parseFloat(o) : 1, n && n !== "none" && i(e, n, a), e.drawImage(t, 0, 0), r(a.toDataURL());
9
+ const o = t.style.filter, n = t.style.opacity, s = t.style.transform;
10
+ a.filter = o !== "" ? o : "", a.globalAlpha = n !== "" ? parseFloat(n) : 1, s && s !== "none" && d(a, s, e), a.drawImage(t, 0, 0), c(e.toDataURL());
18
11
  }
19
- }, i = (t, a, e) => {
20
- const s = a.match(/rotate\((\d+(?:\.\d+)?)deg\)/);
21
- if (s) {
22
- const c = parseFloat(s[1]) * (Math.PI / 180);
23
- t.translate(e.width / 2, e.height / 2), t.rotate(c), t.translate(-e.width / 2, -e.height / 2);
12
+ }, d = (t, e, a) => {
13
+ const o = e.match(/rotate\((\d+(?:\.\d+)?)deg\)/);
14
+ if (o) {
15
+ const r = parseFloat(o[1]) * (Math.PI / 180);
16
+ t.translate(a.width / 2, a.height / 2), t.rotate(r), t.translate(-a.width / 2, -a.height / 2);
24
17
  }
25
- const o = a.match(
18
+ const n = e.match(
26
19
  /scale\((\d+(?:\.\d+)?)(?:,\s*(\d+(?:\.\d+)?))?\)/
27
20
  );
28
- if (o) {
29
- const l = parseFloat(o[1]), c = o[2] ? parseFloat(o[2]) : l;
30
- t.scale(l, c);
31
- }
32
- const n = a.match(/translate\((\d+px)(?:,\s*(\d+px))?\)/);
33
21
  if (n) {
34
- const l = parseFloat(n[1]), c = n[2] ? parseFloat(n[2]) : 0;
35
- t.translate(l, c);
22
+ const l = parseFloat(n[1]), r = n[2] ? parseFloat(n[2]) : l;
23
+ t.scale(l, r);
24
+ }
25
+ const s = e.match(/translate\((\d+px)(?:,\s*(\d+px))?\)/);
26
+ if (s) {
27
+ const l = parseFloat(s[1]), r = s[2] ? parseFloat(s[2]) : 0;
28
+ t.translate(l, r);
36
29
  }
37
30
  };
38
31
  export {
39
- f as downloadEditedImage
32
+ i as downloadEditedImage
40
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armco/imageeditor",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "cjs/ImageEditor.js",
6
6
  "module": "es/ImageEditor.js",
@@ -14,13 +14,12 @@
14
14
  "publish:local": "./publish-local.sh"
15
15
  },
16
16
  "dependencies": {
17
- "@armco/icon": "^0.0.3",
18
- "@armco/shared-components": "^0.0.50",
19
- "@armco/utils": "^0.0.16",
17
+ "@armco/icon": "^0.0.4",
18
+ "@armco/shared-components": "^0.0.52",
19
+ "@armco/utils": "^0.0.17",
20
20
  "@types/node": "^22.5.5",
21
21
  "react": ">16.8.0",
22
- "react-dom": ">16.8.0",
23
- "vite-plugin-dts": "^4.2.1"
22
+ "react-dom": ">16.8.0"
24
23
  },
25
24
  "devDependencies": {
26
25
  "@testing-library/dom": "^9.2.0",
@@ -41,6 +40,8 @@
41
40
  "typescript": "^5.0.2",
42
41
  "vite": "^4.0.0",
43
42
  "vite-plugin-css-injected-by-js": "^3.5.1",
43
+ "vite-plugin-dts": "^4.2.2",
44
+ "vite-plugin-externalize-deps": "^0.8.0",
44
45
  "vitest": "^0.30.1"
45
46
  },
46
47
  "peerDependencies": {