12345678910 |
- /*!
- * FilePondPluginFilePoster 2.5.1
- * Licensed under MIT, https://opensource.org/licenses/MIT/
- * Please visit https://pqina.nl/filepond/ for details.
- */
- /* eslint-disable */
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FilePondPluginFilePoster=t()}(this,function(){"use strict";var e={type:"spring",stiffness:.5,damping:.45,mass:10},t=function(e){return-.5*(Math.cos(Math.PI*e)-1)},r=function(e){var t=Math.min(10/e.width,10/e.height),r=document.createElement("canvas"),a=r.getContext("2d"),o=r.width=Math.ceil(e.width*t),n=r.height=Math.ceil(e.height*t);a.drawImage(e,0,0,o,n);var l=null;try{l=a.getImageData(0,0,o,n).data}catch(e){return null}for(var c=l.length,d=0,E=0,s=0,_=0;_<c;_+=4)d+=l[_]*l[_],E+=l[_+1]*l[_+1],s+=l[_+2]*l[_+2];return{r:d=i(d,c),g:E=i(E,c),b:s=i(s,c)}},i=function(e,t){return Math.floor(Math.sqrt(e/(t/4)))},a=function(e,r,i,a,o){e.width=r,e.height=i;var n=e.getContext("2d"),l=.5*r,c=n.createRadialGradient(l,i+110,i-100,l,i+110,i+100);!function(e,r){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:10,n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,l=1-n,c=r.join(","),d=0;d<=o;d++){var E=d/o,s=n+l*E;e.addColorStop(s,"rgba(".concat(c,", ").concat(a(E)*i,")"))}}(c,a,o,void 0,8,.4),n.save(),n.translate(.5*-r,0),n.scale(2,1),n.fillStyle=c,n.fillRect(0,0,r,i),n.restore()},o="undefined"!=typeof navigator,n=o&&document.createElement("canvas"),l=o&&document.createElement("canvas"),c=o&&document.createElement("canvas"),d=[40,40,40],E=[196,78,71],s=[54,151,99];o&&(a(n,500,200,d,.85),a(l,500,200,E,1),a(c,500,200,s,1));var _=function(t){var i=t.utils.createView({name:"file-poster-overlay",tag:"canvas",ignoreRect:!0,create:function(e){var t,r,i=e.root,a=e.props;t=a.template,(r=i.element).width=t.width,r.height=t.height,r.getContext("2d").drawImage(t,0,0)},mixins:{styles:["opacity"],animations:{opacity:{type:"spring",mass:25}}}}),o=function(e){var t=e.root;t.ref.overlayShadow.opacity=1,t.ref.overlayError.opacity=0,t.ref.overlaySuccess.opacity=0},_=function(e){var t=e.root;t.ref.overlayShadow.opacity=.25,t.ref.overlayError.opacity=1};return t.utils.createView({name:"file-poster-wrapper",create:function(r){var o=r.root,_=r.props,f=o.query("GET_FILE_POSTER_ITEM_OVERLAY_SHADOW_COLOR"),u=o.query("GET_FILE_POSTER_ITEM_OVERLAY_ERROR_COLOR"),I=o.query("GET_FILE_POSTER_ITEM_OVERLAY_SUCCESS_COLOR");f&&f!==d&&a(n,500,200,d=f,.85),u&&u!==E&&a(l,500,200,E=u,1),I&&I!==s&&a(c,500,200,s=I,1);var p=function(t){return t.utils.createView({name:"file-poster",tag:"div",ignoreRect:!0,create:function(e){var t=e.root;t.ref.image=document.createElement("img"),t.element.appendChild(t.ref.image)},write:t.utils.createRoute({DID_FILE_POSTER_LOAD:function(e){var t=e.root,r=e.props,i=r.id,a=t.query("GET_ITEM",{id:r.id});if(a){var o=a.getMetadata("poster");t.ref.image.src=o,t.dispatch("DID_FILE_POSTER_DRAW",{id:i})}}}),mixins:{styles:["scaleX","scaleY","opacity"],animations:{scaleX:e,scaleY:e,opacity:{type:"tween",duration:750}}}})}(t);o.ref.image=o.appendChildView(o.createChildView(p,{id:_.id,scaleX:1.25,scaleY:1.25,opacity:0})),o.ref.overlayShadow=o.appendChildView(o.createChildView(i,{template:n,opacity:0})),o.ref.overlaySuccess=o.appendChildView(o.createChildView(i,{template:c,opacity:0})),o.ref.overlayError=o.appendChildView(o.createChildView(i,{template:l,opacity:0}))},write:t.utils.createRoute({DID_FILE_POSTER_LOAD:function(e){e.root.ref.overlayShadow.opacity=1},DID_FILE_POSTER_DRAW:function(e){var t=e.root.ref.image;t.scaleX=1,t.scaleY=1,t.opacity=1},DID_FILE_POSTER_CONTAINER_CREATE:function(e){var t=e.root,i=e.props.id,a=t.query("GET_ITEM",i);if(a){var o,n,l,c=a.getMetadata("poster"),d=function(e){var o=t.query("GET_FILE_POSTER_CALCULATE_AVERAGE_IMAGE_COLOR")?r(e):null;a.setMetadata("color",o,!0),t.dispatch("DID_FILE_POSTER_LOAD",{id:i,data:e})};o=c,n=function(e,r){var a,o;t.dispatch("DID_FILE_POSTER_CALCULATE_SIZE",{id:i,width:e,height:r}),(a=c,o=t.query("GET_FILE_POSTER_CROSS_ORIGIN_ATTRIBUTE_VALUE"),new Promise(function(e,t){var r=new Image;"string"==typeof crossOrigin&&(r.crossOrigin=o),r.onload=function(){e(r)},r.onerror=function(e){t(e)},r.src=a})).then(d)},(l=new Image).onload=function(){var e=l.naturalWidth,t=l.naturalHeight;l=null,n(e,t)},l.src=o}},DID_THROW_ITEM_LOAD_ERROR:_,DID_THROW_ITEM_PROCESSING_ERROR:_,DID_THROW_ITEM_INVALID:_,DID_COMPLETE_ITEM_PROCESSING:function(e){var t=e.root;t.ref.overlayShadow.opacity=.25,t.ref.overlaySuccess.opacity=1},DID_START_ITEM_PROCESSING:o,DID_REVERT_ITEM_PROCESSING:o})})},f=function(e){var t=e.addFilter,r=e.utils,i=r.Type,a=r.createRoute,o=_(e);return t("CREATE_VIEW",function(e){var t=e.is,r=e.view,i=e.query;if(t("file")&&i("GET_ALLOW_FILE_POSTER")){var n=function(e,t){var a=t.id,n=i("GET_ITEM",a);n&&n.getMetadata("poster")&&!n.archived&&e.ref.previousPoster!==n.getMetadata("poster")&&(e.ref.previousPoster=n.getMetadata("poster"),i("GET_FILE_POSTER_FILTER_ITEM")(n)&&(e.ref.filePoster&&r.removeChildView(e.ref.filePoster),e.ref.filePoster=r.appendChildView(r.createChildView(o,{id:a})),e.dispatch("DID_FILE_POSTER_CONTAINER_CREATE",{id:a})))},l=function(e){var t=e.root,r=t.query("GET_FILE_POSTER_HEIGHT");if(r)return r;var i=t.query("GET_FILE_POSTER_MIN_HEIGHT"),a=t.query("GET_FILE_POSTER_MAX_HEIGHT");if(i&&t.ref.imageHeight<i)return i;var o=t.rect.element.width*(t.ref.imageHeight/t.ref.imageWidth);return i&&o<i?i:a&&o>a?a:o};r.registerWriter(a({DID_LOAD_ITEM:function(e){var t=e.root,r=e.props;n(t,r)},DID_FILE_POSTER_CALCULATE_SIZE:function(e){var t=e.root,r=e.action;t.ref.filePoster&&(t.ref.imageWidth=r.width,t.ref.imageHeight=r.height,t.ref.shouldUpdatePanelHeight=!0,t.dispatch("KICK"))},DID_UPDATE_ITEM_METADATA:function(e){var t=e.root,r=e.props,i=e.action;/poster/.test(i.change.key)&&n(t,r)}},function(e){var t=e.root,r=e.props;t.ref.filePoster&&(t.rect.element.hidden||t.ref.shouldUpdatePanelHeight&&(t.dispatch("DID_UPDATE_PANEL_HEIGHT",{id:r.id,height:l({root:t})}),t.ref.shouldUpdatePanelHeight=!1))}))}}),{options:{allowFilePoster:[!0,i.BOOLEAN],filePosterHeight:[null,i.INT],filePosterMinHeight:[null,i.INT],filePosterMaxHeight:[null,i.INT],filePosterFilterItem:[function(){return!0},i.FUNCTION],filePosterCalculateAverageImageColor:[!1,i.BOOLEAN],filePosterCrossOriginAttributeValue:["Anonymous",i.STRING],filePosterItemOverlayShadowColor:[null,i.ARRAY],filePosterItemOverlayErrorColor:[null,i.ARRAY],filePosterItemOverlaySuccessColor:[null,i.ARRAY]}}};return"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:f})),f});
|