phaser3-rex-plugins
Version:
2 lines (1 loc) • 8.41 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexsliderplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(r=i.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?s:String(s)),i);}var r,s;}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function u(t){var e=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(t){return !1}}();return function(){var n,i=s(t);if(e){var r=s(this).constructor;n=Reflect.construct(i,arguments,r);}else n=i.apply(this,arguments);return a(this,n)}}var h={setEventEmitter:function(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},c=Phaser.Scene,l=function(t){return t instanceof c},v=Phaser.Game,f=function(t){return t instanceof v},y=Phaser.Utils.Objects.GetValue,p=function(){function n(t,i){e(this,n),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(y(i,"eventEmitter",!0)),this.parent&&(this.parent===this.scene?this.scene.sys.events.once("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.once("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.once("destroy",this.onParentDestroy,this));}return i(n,[{key:"shutdown",value:function(t){this.isShutdown||(this.parent&&(this.parent===this.scene?this.scene.sys.events.off("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.off("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.off("destroy",this.onParentDestroy,this)),this.destroyEventEmitter(),this.parent=void 0,this.scene=void 0,this.game=void 0,this.isShutdown=!0);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(e){var n;return this.parent=e,this.scene=null==(n=e)||"object"!==t(n)?null:l(n)?n:n.scene&&l(n.scene)?n.scene:n.parent&&n.parent.scene&&l(n.parent.scene)?n.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:f(e)?e:f(e.game)?e.game:l(e)?e.sys.game:l(e.scene)?e.scene.sys.game:void 0}(e),this}}]),n}();Object.assign(p.prototype,h);var m=Phaser.Math.Linear,d=Phaser.Math.Percent,E={setValue:function(t,e,n){return null==t||(void 0!==e&&(t=d(t,e,n)),this.value=t),this},addValue:function(t,e,n){return void 0!==e&&(t=d(t,e,n)),this.value+=t,this},getValue:function(t,e){var n=this.value;return void 0!==t&&(n=m(t,e,n)),n}},b=Phaser.Utils.Objects.GetValue,_=Phaser.Math.Angle.BetweenPoints,g=Phaser.Math.Distance.Between,P=Phaser.Math.RotateAroundDistance,x=Phaser.Math.Clamp,w=Phaser.Math.Linear,O=Phaser.Math.Percent,k=function(t){r(s,t);var n=u(s);function s(t,i){var r;e(this,s),(r=n.call(this,t,i))._enable=void 0,r._value=void 0,r.endPoints=[{x:0,y:0},{x:0,y:0}];var o=b(i,"valuechangeCallback",null);if(null!==o){var a=b(i,"valuechangeCallbackScope",void 0);r.on("valuechange",o,a);}return r.parent.setInteractive(b(i,"inputConfig",void 0)),r.resetFromJSON(i),r.boot(),r}return i(s,[{key:"resetFromJSON",value:function(t){this.setValue(b(t,"value",0));var e=b(t,"endPoints",void 0);return void 0!==e&&this.setEndPoints(e),this.setEnable(b(t,"enable",!0)),this}},{key:"toJSON",value:function(){return {value:this.value,endPoints:this.endPoints,enable:this.enable}}},{key:"boot",value:function(){this.parent.on("drag",this.onDragging,this);}},{key:"enable",get:function(){return this._enable},set:function(t){if(this._enable!==t)return this._enable=t,this.scene.input.setDraggable(this.parent,t),this}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),this.enable=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}},{key:"setEndPoints",value:function(t,e,n,i){var r=this.endPoints;return "number"==typeof t?(r[0].x=t,r[0].y=e,r[1].x=n,r[1].y=i):Array.isArray(t)?(r[0]=t[0],r[1]=t[1]):(r[0]=t,r[1]=e),this.axisRotation=_(r[0],r[1]),this.updatePos(),this}},{key:"value",get:function(){return this._value},set:function(t){if((t=x(t,0,1))!==this._value){var e=this._value;this._value=t,this.updatePos(this._value),this.emit("valuechange",this._value,e);}}},{key:"isDragging",get:function(){return this.parent.input.dragState>0}},{key:"onDragging",value:function(t,e,n){var i,r=this.endPoints;if(r[0].y===r[1].y){var s=Math.min(r[0].x,r[1].x),o=Math.max(r[0].x,r[1].x);i=O(e,s,o);}else if(r[0].x===r[1].x){s=Math.min(r[0].y,r[1].y),o=Math.max(r[0].y,r[1].y);i=O(n,s,o);}else {var a,u=this.parent,h={x:e,y:n};a=g(h.x,h.y,u.x,u.y),(h=P(h,u.x,u.y,-this.axisRotation,a)).y=u.y,a=g(h.x,h.y,u.x,u.y),h=P(h,u.x,u.y,this.axisRotation,a);s=Math.min(r[0].x,r[1].x),o=Math.max(r[0].x,r[1].x);i=O(h.x,s,o);}this.value=i;}},{key:"updatePos",value:function(){var t=this.parent,e=this.endPoints;return t.x=w(e[0].x,e[1].x,this._value),t.y=w(e[0].y,e[1].y,this._value),this}}]),s}(p);return Object.assign(k.prototype,E),function(t){r(s,Phaser.Plugins.BasePlugin);var n=u(s);function s(t){return e(this,s),n.call(this,t)}return i(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new k(t,e)}}]),s}()}));