phaser3-rex-plugins
Version:
2 lines (1 loc) • 6.57 kB
JavaScript
!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).rexfiledropzoneplugin=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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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 n(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(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&&s(e,t);}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(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 r,n=o(e);if(t){var i=o(this).constructor;r=Reflect.construct(n,arguments,i);}else r=n.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 a(e)}(this,r)}}var c=Phaser.Game,f=function(e){return e instanceof c},l=Phaser.Scene,h=function(e){return e instanceof l},p=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:f(i)?i:f(i.game)?i.game:h(i)?i.sys.game:h(i.scene)?i.scene.sys.game:void 0,"textures"===n?t.textures:t.cache[n]},d=function(e){return e&&"function"==typeof e},v=function(e,t,r,n,i,o){if(null===i||!1===i);else if(d(i))i();else {var s=p(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);})),d(t))t();else {var u=window.URL.createObjectURL(t);a[r](n,u);}a.start();},y={loadFile:function(e,t,r,n,i){var o=this.scene;return v(o,e,t,r,n,i),this},loadFilePromise:function(e,t,r,n){var i=this.scene;return new Promise((function(o,s){v(i,e,t,r,n,(function(e){o(e);}));}))}},b={setDropEnable:function(e){return void 0===e&&(e=!0),this.dropEnable=e,this},toggleDropEnable:function(){return this.dropEnable=!this.dropEnable,this}},g={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(g,b,{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}},y);var m={dragenter:"dragenter",dragleave:"dragleave",dragover:"dragover",drop:"drop"},j=Phaser.Utils.Objects.GetValue,O=Phaser.GameObjects.DOMElement,w=Phaser.Utils.Objects.IsPlainObject,P=Phaser.Utils.Objects.GetValue,x=function(e){i(o,e);var r=u(o);function o(e,n,i,s,u,c){var f;t(this,o),w(n)?(n=P(c=n,"x",0),i=P(c,"y",0),s=P(c,"width",0),u=P(c,"height",0)):w(s)&&(s=P(c=s,"width",0),u=P(c,"height",0)),void 0===c&&(c={});var l=document.createElement("div"),h=P(c,"style",void 0);(f=r.call(this,e,n,i,l,h)).type="rexFileDropZone",f.resize(s,u),f._files=[],f.setDropEnable(P(c,"dropEnable",!0));var p=P(c,"filters");return p&&f.addFilters(p),function(e,t,r,n){var i=j(n,"preventDefault",!1),o=j(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);}(a(f),l,m,{preventDefault:!0,preTest:function(e){return e.dropEnable}}),f.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 u=r[s];i(u,r)&&o.push(u);}o.length>0&&this.emit("drop.".concat(n),o);}}),a(f)),f}return n(o,[{key:"files",get:function(){return this._files}}]),o}(O);function E(e,t,r,n,i){var o=new x(this.scene,e,t,r,n,i);return this.scene.add.existing(o),o}Object.assign(x.prototype,g);var S=Phaser.Utils.Objects.GetAdvancedValue,_=Phaser.GameObjects.BuildGameObject;function D(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var r=S(e,"width",void 0),n=S(e,"height",void 0),i=new x(this.scene,0,0,r,n,e);return _(this.scene,i,e),i}var T=function(e){return null==e||""===e||0===e.length},R=function(e){i(o,Phaser.Plugins.BasePlugin);var r=u(o);function o(e){var n;return t(this,o),n=r.call(this,e),e.registerGameObject("rexFileDropZone",E,D),n}return n(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}}]),o}();return function(t,r,n,i){if(void 0===i&&(i="."),"object"===e(t)){if(T(r)){if(null==n)return;"object"===e(n)&&(t=n);}else {"string"==typeof r&&(r=r.split(i));var o=r.pop(),s=function(t,r,n){var i=t;if(T(r));else {var o;"string"==typeof r&&(r=r.split("."));for(var s=0,a=r.length;s<a;s++){var u;null!=i[o=r[s]]&&"object"===e(i[o])||(u=s===a-1?void 0===n?{}:n:{},i[o]=u),i=i[o];}}return i}(t,r);s[o]=n;}}}(window,"RexPlugins.GameObjects.FileDropZone",x),R}));