import{g as S}from"./_commonjsHelpers-de833af9.js";import{a as M}from"./index-ec1be37d.js";import{h as U,i as D,j as N,k as R,d as X}from"./axios_helper-aabbd1f9.js";import{f as P,c as j}from"./file-upload-33be919a.js";var y={exports:{}};(function(l){function r(a){return a.type.indexOf("mouse")!==-1?a.clientX:a.touches[0].clientX}function o(a){return a.type.indexOf("mouse")!==-1?a.clientY:a.touches[0].clientY}var u=function(){var a=!1;try{var s=Object.defineProperty({},"passive",{get:function(){a=!0}});window.addEventListener("test",null,s)}catch{}return a}(),p={install:function(a,s){var i=Object.assign({},{disableClick:!1,tapTolerance:10,swipeTolerance:30,touchHoldTolerance:400,longTapTimeInterval:400,touchClass:""},s);function d(t){var e=this.$$touchObj,n=t.type.indexOf("touch")>=0,f=t.type.indexOf("mouse")>=0,T=this;n&&(e.lastTouchStartTime=t.timeStamp),!(f&&e.lastTouchStartTime&&t.timeStamp-e.lastTouchStartTime<350)&&(e.touchStarted||(I(this),e.touchStarted=!0,e.touchMoved=!1,e.swipeOutBounded=!1,e.startX=r(t),e.startY=o(t),e.currentX=0,e.currentY=0,e.touchStartTime=t.timeStamp,e.touchHoldTimer=setTimeout(function(){v(t,T,"touchhold")},e.options.touchHoldTolerance),v(t,this,"start")))}function h(t){var e=this.$$touchObj;if(e.currentX=r(t),e.currentY=o(t),e.touchMoved){if(!e.swipeOutBounded){var f=e.options.swipeTolerance;e.swipeOutBounded=Math.abs(e.startX-e.currentX)>f&&Math.abs(e.startY-e.currentY)>f}}else{var n=e.options.tapTolerance;e.touchMoved=Math.abs(e.startX-e.currentX)>n||Math.abs(e.startY-e.currentY)>n,e.touchMoved&&(g(e),v(t,this,"moved"))}e.touchMoved&&v(t,this,"moving")}function L(){var t=this.$$touchObj;g(t),E(this),t.touchStarted=t.touchMoved=!1,t.startX=t.startY=0}function c(t){var e=this.$$touchObj,n=t.type.indexOf("touch")>=0,f=t.type.indexOf("mouse")>=0;if(n&&(e.lastTouchEndTime=t.timeStamp),g(e),e.touchStarted=!1,E(this),!(f&&e.lastTouchEndTime&&t.timeStamp-e.lastTouchEndTime<350)){if(v(t,this,"end"),!e.touchMoved)e.callbacks.longtap&&t.timeStamp-e.touchStartTime>e.options.longTapTimeInterval?(t.cancelable&&t.preventDefault(),v(t,this,"longtap")):v(t,this,"tap");else if(!e.swipeOutBounded){var T=e.options.swipeTolerance,m;Math.abs(e.startX-e.currentX)e.currentY?"top":"bottom":m=e.startX>e.currentX?"left":"right",e.callbacks["swipe."+m]?v(t,this,"swipe."+m,m):v(t,this,"swipe",m)}}}function O(){I(this)}function k(){E(this)}function v(t,e,n,f){var T=e.$$touchObj,m=T.callbacks[n]||[];if(m.length===0)return null;for(var C=0;C=0){var b="swipe."+C;n.callbacks[b]=n.callbacks[b]||[],n.callbacks[b].push(e)}}else n.callbacks.swipe=n.callbacks.swipe||[],n.callbacks.swipe.push(e);break;case"start":case"moving":e.modifiers.disablePassive&&(f=!1);default:n.callbacks[T]=n.callbacks[T]||[],n.callbacks[T].push(e)}n.hasBindTouchEvents||(t.addEventListener("touchstart",d,f),t.addEventListener("touchmove",h,f),t.addEventListener("touchcancel",L),t.addEventListener("touchend",c),n.options.disableClick||(t.addEventListener("mousedown",d),t.addEventListener("mousemove",h),t.addEventListener("mouseup",c),t.addEventListener("mouseenter",O),t.addEventListener("mouseleave",k)),n.hasBindTouchEvents=!0)},unbind:function(t){t.removeEventListener("touchstart",d),t.removeEventListener("touchmove",h),t.removeEventListener("touchcancel",L),t.removeEventListener("touchend",c),t.$$touchObj&&!t.$$touchObj.options.disableClick&&(t.removeEventListener("mousedown",d),t.removeEventListener("mousemove",h),t.removeEventListener("mouseup",c),t.removeEventListener("mouseenter",O),t.removeEventListener("mouseleave",k)),delete t.$$touchObj}}),a.directive("touch-class",{bind:function(t,e){w(t,{touchClass:e.value})}}),a.directive("touch-options",{bind:function(t,e){w(t,e.value)}})}};l.exports=p})(y);var x=y.exports;const B=S(x),A={uploadCount:0,s3UploadProcessing:!1},F={processFile({dispatch:l},{currentFile:r,restrictions:o,generatePreviews:u}){return new Promise((p,a)=>{P({file:r,generatePreviews:u}).then(s=>{j(s,o).then(()=>{u?l("processMediaFile",{file:s,restrictions:o}).then(i=>{p(i)}).catch(i=>{a(i)}):p(s)}).catch(i=>{a(i)})}).catch(s=>{a(s)})})},processMediaFile({dispatch:l},{file:r,restrictions:o}){const u=U(r.type);return new Promise((p,a)=>{u?l("getDataUrl",r).then(s=>{l("getElement",{file:r,elementType:u}).then(i=>{const d=i.src,h=D(i,u,o.dimensions);let L=u==="video"?"video":"image";N(r.type,s)&&(L="animation"),l("checkMediaFileRestrictions",{restrictions:o,dimensions:h,mediaType:L,elem:i}).then(()=>{const c={...r,preview:d,mediaType:L,dimensions:h};L==="animation"?l("getGifPreview",{elem:i,dimensions:h}).then(O=>{c.gifPreview=O,p(c)}).catch(O=>a(O)):p(c)}).catch(c=>a(c))}).catch(i=>a(i))}).catch(s=>a(s)):a("UNKNOWN")})},getDataUrl(l,r){const o=new FileReader;return new Promise((u,p)=>{o.onerror=()=>{o.abort(),p("FILE_CORRUPT")},o.onload=()=>{u(o.result)},o.readAsDataURL(r.data)})},getElement(l,{file:r,elementType:o}){const u=URL.createObjectURL(r.data),p=o==="video"?"canplaythrough":"load";return new Promise((s,i)=>{const d=document.createElement(o);if(p==="video"){const h=document.createElement("source");h.src=u,h.type=r.type,video.appendChild(source)}else d.src=u;d.addEventListener(p,()=>{s(d)}),d.addEventListener("error",()=>{URL.revokeObjectURL(u),i("UNKNOWN")})}).then(s=>s)},checkMediaFileRestrictions(l,{restrictions:r,dimensions:o,mediaType:u,elem:p}){return new Promise((a,s)=>{let i=null;const d=r.dimensions||null;if(d&&((d.minWidth>o.width||d.minHeight>o.height)&&(i="INVALID_MIN_DIMENSIONS"),(d.maxWidthh.duration&&(i="INVALID_MAX_FILE_DURATION")}i?s(i):a()})},getGifPreview(l,{elem:r,dimensions:o}){return new Promise((u,p)=>{const a=document.createElement("canvas");a.width=o.width,a.height=o.height,a.getContext("2d").drawImage(r,0,0,o.width,o.height),R(a,"image/png").then(s=>{u(URL.createObjectURL(s))}).catch(()=>p("UNKNOWN"))})},handleDirectUpload({state:l},{files:r,context:o,s3Url:u,formData:p,onInit:a=()=>{},onProgress:s=()=>{},onSuccess:i=()=>{},onSuccessAll:d=()=>{},onError:h=()=>{}}){const L=r.map(c=>{const k=M.CancelToken.source();a({context:o,id:c.id,uploadCancelTokenSource:k}),l.uploadCount++,s({context:o,id:c.id,progress:{uploadStarted:!0}});const v=()=>E=>{s({context:o,id:c.id,progress:{bytesTotal:E.total,bytesUploaded:E.loaded}})},I={headers:{"Content-Type":c.type},cancelToken:k.token,onUploadProgress:v(c.id),timeout:3e5};return l.s3UploadProcessing=!0,M.post(u,X(c.data,p),I).then(E=>{const g=document.createElement("textarea");g.innerHTML=E.data.match(/(.*?)<\/Key>/)[1];const w=g.innerText;l.uploadCount--,w!==void 0?(i({context:o,id:c.id,path:w}),s({context:o,id:c.id,progress:{uploadComplete:!0}})):(s({context:o,id:c.id,progress:{uploadComplete:!0,uploadFailed:!0}}),h({context:o,type:"UPLOAD_FAILED",id:c.id}))}).catch(E=>{M.isCancel(E)||(s({context:o,id:c.id,progress:{uploadComplete:!0,uploadFailed:!0}}),h({context:o,type:"UPLOAD_FAILED",id:c.id})),l.uploadCount--})});M.all(L).then(()=>{l.uploadCount===0&&(l.s3UploadProcessing=!1,d())})}},W={namespaced:!0,state:A,actions:F};export{B as V,W as f}; //# sourceMappingURL=index-2eb82686.js.map