UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 5.43 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexfiledropzone=t();}(undefined,(function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(i=n.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(i,"string"))?o:String(o)),n);}var i,o;}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function i(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return !1}}();return function(){var n,o=r(e);if(t){var s=r(this).constructor;n=Reflect.construct(o,arguments,s);}else n=o.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return i(e)}(this,n)}}var s=Phaser.Game,a=function(e){return e instanceof s},f=Phaser.Scene,c=function(e){return e instanceof f},u=function(t,r,n){if(void 0===n)switch(r){case"image":case"svg":n="textures";break;case"animation":n="json";break;case"tilemapTiledJSON":case"tilemapCSV":n="tilemap";break;case"glsl":n="shader";break;default:n=r;}var i;return t=null==(i=t)||"object"!==e(i)?null:a(i)?i:a(i.game)?i.game:c(i)?i.sys.game:c(i.scene)?i.scene.sys.game:void 0,"textures"===n?t.textures:t.cache[n]},l=function(e){return e&&"function"==typeof e},p=function(e,t,r,n,i,o){if(null===i||!1===i);else if(l(i))i();else {var s=u(e,r,i);s.exists(n)&&s.remove(n);}var a=e.load;if(o&&a.once("filecomplete-".concat(r,"-").concat(n),(function(e,t,r){o(r);})),l(t))t();else {var f=window.URL.createObjectURL(t);a[r](n,f);}a.start();},h={loadFile:function(e,t,r,n,i){var o=this.scene;return p(o,e,t,r,n,i),this},loadFilePromise:function(e,t,r,n){var i=this.scene;return new Promise((function(o,s){p(i,e,t,r,n,(function(e){o(e);}));}))}},d={setDropEnable:function(e){return void 0===e&&(e=!0),this.dropEnable=e,this},toggleDropEnable:function(){return this.dropEnable=!this.dropEnable,this}},y={resize:function(e,t){if(this.scene.sys.scale.autoRound&&(e=Math.floor(e),t=Math.floor(t)),this.width===e&&this.height===t)return this;var r=this.node.style;return r.width="".concat(e,"px"),r.height="".concat(t,"px"),this.updateSize(),this},syncTo:function(e){return this.setOrigin(e.originX,e.originY),this.setPosition(e.x,e.y),this.resize(e.displayWidth,e.displayHeight),this}};Object.assign(y,d,{addFilter:function(e,t){return this.filters||(this.filters={}),this.filters[e]=t,this},addFilters:function(e){for(var t in this.filters||(this.filters={}),e)this.filters[t]=e[t];return this}},h);var b={dragenter:"dragenter",dragleave:"dragleave",dragover:"dragover",drop:"drop"},v=Phaser.Utils.Objects.GetValue,m=Phaser.GameObjects.DOMElement,g=Phaser.Utils.Objects.IsPlainObject,O=Phaser.Utils.Objects.GetValue,j=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&n(e,t);}(c,e);var r,s,f=o(c);function c(e,t,r,n,o,s){var a;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,c),g(t)?(t=O(s=t,"x",0),r=O(s,"y",0),n=O(s,"width",0),o=O(s,"height",0)):g(n)&&(n=O(s=n,"width",0),o=O(s,"height",0)),void 0===s&&(s={});var u=document.createElement("div"),l=O(s,"style",void 0);(a=f.call(this,e,t,r,u,l)).type="rexFileDropZone",a.resize(n,o),a._files=[],a.setDropEnable(O(s,"dropEnable",!0));var p=O(s,"filters");return p&&a.addFilters(p),function(e,t,r,n){var i=v(n,"preventDefault",!1),o=v(n,"preTest"),s=function(n){t.addEventListener(n,(function(t){o&&!o(e,n)||e.emit(r[n],e,t),i&&t.preventDefault();}));};for(var a in r)s(a);}(i(a),u,b,{preventDefault:!0,preTest:function(e){return e.dropEnable}}),a.on("drop",(function(e,t){this._files=t.dataTransfer.files;var r=this._files;if(r&&this.filters)for(var n in this.filters){for(var i=this.filters[n],o=[],s=0,a=r.length;s<a;s++){var f=r[s];i(f,r)&&o.push(f);}o.length>0&&this.emit("drop.".concat(n),o);}}),i(a)),a}return r=c,(s=[{key:"files",get:function(){return this._files}}])&&t(r.prototype,s),Object.defineProperty(r,"prototype",{writable:!1}),c}(m);return Object.assign(j.prototype,y),j}));