UNPKG

13.9 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.Region=e():t.Region=e()}(this,function(){return function(t){function e(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){t.exports=i(7)},function(t){"use strict";function e(t,e){function i(n){function o(){var o=arguments.length,r=[].concat(n);return o&&r.push.apply(r,arguments),r.length<e?i(r):t.apply(this,r)}return o}return"number"!=typeof e&&(e=t.length),i([])}var i=Object.prototype.hasOwnProperty;t.exports=e(function(t,e){return i.call(t,e)})},function(t){"use strict";t.exports=function(t){var e=!0;return t.right<t.left&&(e=!1,t.right=t.left),t.bottom<t.top&&(e=!1,t.bottom=t.top),e}},function(t){t.exports=function(){"use strict";var t={};return function(e){if(!t[e]){for(var i=[],n=0;e>n;n++)i.push("a["+n+"]");t[e]=new Function("c","a","return new c("+i.join(",")+")")}return t[e]}}()},function(t,e,i){var n=i(3);t.exports=function(t,e){return n(e.length)(t,e)}},function(t){"use strict";function e(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}t.exports=Object.assign||function(t){for(var i,n,o=e(t),r=1;r<arguments.length;r++){i=arguments[r],n=Object.keys(Object(i));for(var s=0;s<n.length;s++)o[n[s]]=i[n[s]]}return o}},function(t){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(t){return"function"==typeof t}function n(t){return"number"==typeof t}function o(t){return"object"==typeof t&&null!==t}function r(t){return void 0===t}t.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(t){if(!n(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},e.prototype.emit=function(t){var e,n,s,h,f,u;if(this._events||(this._events={}),"error"===t&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[t],r(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(s=arguments.length,h=new Array(s-1),f=1;s>f;f++)h[f-1]=arguments[f];n.apply(this,h)}else if(o(n)){for(s=arguments.length,h=new Array(s-1),f=1;s>f;f++)h[f-1]=arguments[f];for(u=n.slice(),s=u.length,f=0;s>f;f++)u[f].apply(this,h)}return!0},e.prototype.addListener=function(t,n){var s;if(!i(n))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,i(n.listener)?n.listener:n),this._events[t]?o(this._events[t])?this._events[t].push(n):this._events[t]=[this._events[t],n]:this._events[t]=n,o(this._events[t])&&!this._events[t].warned){var s;s=r(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,s&&s>0&&this._events[t].length>s&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace())}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(t,e){function n(){this.removeListener(t,n),o||(o=!0,e.apply(this,arguments))}if(!i(e))throw TypeError("listener must be a function");var o=!1;return n.listener=e,this.on(t,n),this},e.prototype.removeListener=function(t,e){var n,r,s,h;if(!i(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,r=-1,n===e||i(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(o(n)){for(h=s;h-->0;)if(n[h]===e||n[h].listener&&n[h].listener===e){r=h;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},e.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],i(n))this.removeListener(t,n);else for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},e.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?i(this._events[t])?[this._events[t]]:this._events[t].slice():[]},e.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?i(t._events[e])?1:t._events[e].length:0}},function(t,e,i){"use strict";function n(t,e,i){return t&&i.forEach(function(i){e[i]=t[i]}),e}var o=i(1),r=i(4),s=i(5),h=i(6).EventEmitter,f=i(8),u=i(2),c=Object.prototype.toString,g=function(t){return"[object Object]"===c.apply(t)},l={cy:"YCenter",cx:"XCenter",t:"Top",tc:"TopCenter",tl:"TopLeft",tr:"TopRight",b:"Bottom",bc:"BottomCenter",bl:"BottomLeft",br:"BottomRight",l:"Left",lc:"LeftCenter",r:"Right",rc:"RightCenter",c:"Center"},a=function(t,e,i,o){return this instanceof a?(h.call(this),g(t)?(n(t,this,["top","right","bottom","left"]),null==t.bottom&&null!=t.height&&(this.bottom=this.top+t.height),null==t.right&&null!=t.width&&(this.right=this.left+t.width),t.emitChangeEvents&&(this.emitChangeEvents=t.emitChangeEvents)):(this.top=t,this.right=e,this.bottom=i,this.left=o),this[0]=this.left,this[1]=this.top,void u(this)):r(a,arguments)};f(a,h),s(a.prototype,{emitChangeEvents:!1,getRegion:function(t){return t?this.clone():this},setRegion:function(t){return this.set(t instanceof a?t.get():t),this},validate:function(){return a.validate(this)},_before:function(){return this.emitChangeEvents?n(this,{},["left","top","bottom","right"]):void 0},_after:function(t){this.emitChangeEvents&&((this.top!=t.top||this.left!=t.left)&&this.emitPositionChange(),(this.right!=t.right||this.bottom!=t.bottom)&&this.emitSizeChange())},notifyPositionChange:function(){this.emit("changeposition",this)},emitPositionChange:function(){this.notifyPositionChange()},notifySizeChange:function(){this.emit("changesize",this)},emitSizeChange:function(){this.notifySizeChange()},add:function(t){var e,i=this._before();for(e in t)o(t,e)&&(this[e]+=t[e]);return this[0]=this.left,this[1]=this.top,this._after(i),this},substract:function(t){var e,i=this._before();for(e in t)o(t,e)&&(this[e]-=t[e]);return this[0]=this.left,this[1]=this.top,this._after(i),this},getSize:function(){return{width:this.width,height:this.height}},setPosition:function(t){var e=this.width,i=this.height;return void 0!=t.left&&(t.right=t.left+e),void 0!=t.top&&(t.bottom=t.top+i),this.set(t)},setSize:function(t){return void 0!=t.height&&void 0!=t.width?this.set({right:this.left+t.width,bottom:this.top+t.height}):(void 0!=t.width&&this.setWidth(t.width),void 0!=t.height&&this.setHeight(t.height),this)},setWidth:function(t){return this.set({right:this.left+t})},setHeight:function(t){return this.set({bottom:this.top+t})},set:function(t){var e=this._before();return n(t,this,["left","top","bottom","right"]),null==t.bottom&&null!=t.height&&(this.bottom=this.top+t.height),null==t.right&&null!=t.width&&(this.right=this.left+t.width),this[0]=this.left,this[1]=this.top,this._after(e),this},get:function(t){return t?this[t]:n(this,{},["left","right","top","bottom"])},shift:function(t){var e=this._before();return t.top&&(this.top+=t.top,this.bottom+=t.top),t.left&&(this.left+=t.left,this.right+=t.left),this[0]=this.left,this[1]=this.top,this._after(e),this},unshift:function(t){return t.top&&(t.top*=-1),t.left&&(t.left*=-1),this.shift(t)},equals:function(t){return this.equalsPosition(t)&&this.equalsSize(t)},equalsSize:function(t){var e=t instanceof a,i={width:null==t.width&&e?t.getWidth():t.width,height:null==t.height&&e?t.getHeight():t.height};return this.getWidth()==i.width&&this.getHeight()==i.height},equalsPosition:function(t){return this.top==t.top&&this.left==t.left},addLeft:function(t){var e=this._before();return this.left=this[0]=this.left+t,this._after(e),this},addTop:function(t){var e=this._before();return this.top=this[1]=this.top+t,this._after(e),this},addBottom:function(t){var e=this._before();return this.bottom+=t,this._after(e),this},addRight:function(t){var e=this._before();return this.right+=t,this._after(e),this},minTop:function(){return this.expand({top:1})},maxBottom:function(){return this.expand({bottom:1})},minLeft:function(){return this.expand({left:1})},maxRight:function(){return this.expand({right:1})},expand:function(t,e){var i,r=e||a.getDocRegion(),s=[],h=this._before();for(i in t)o(t,i)&&s.push(i);return n(r,this,s),this[0]=this.left,this[1]=this.top,this._after(h),this},clone:function(){return new a({top:this.top,left:this.left,right:this.right,bottom:this.bottom})},containsPoint:function(t,e){return 1==arguments.length&&(e=t.y,t=t.x),this.left<=t&&t<=this.right&&this.top<=e&&e<=this.bottom},containsRegion:function(t){return this.containsPoint(t.left,t.top)&&this.containsPoint(t.right,t.bottom)},diffHeight:function(t){return this.diff(t,{top:!0,bottom:!0})},diffWidth:function(t){return this.diff(t,{left:!0,right:!0})},diff:function(t,e){var i,n={};for(i in e)o(e,i)&&(n[i]=this[i]-t[i]);return n},getPosition:function(){return{left:this.left,top:this.top}},getPoint:function(t,e){l[t]||console.warn("The position ",t," could not be found! Available options are tl, bl, tr, br, l, r, t, b.");var i="getPoint"+l[t],n=this[i]();return e?{left:n.x,top:n.y}:n},getPointYCenter:function(){return{x:null,y:this.top+this.getHeight()/2}},getPointXCenter:function(){return{x:this.left+this.getWidth()/2,y:null}},getPointTop:function(){return{x:null,y:this.top}},getPointTopCenter:function(){return{x:this.left+this.getWidth()/2,y:this.top}},getPointTopLeft:function(){return{x:this.left,y:this.top}},getPointTopRight:function(){return{x:this.right,y:this.top}},getPointBottom:function(){return{x:null,y:this.bottom}},getPointBottomCenter:function(){return{x:this.left+this.getWidth()/2,y:this.bottom}},getPointBottomLeft:function(){return{x:this.left,y:this.bottom}},getPointBottomRight:function(){return{x:this.right,y:this.bottom}},getPointLeft:function(){return{x:this.left,y:null}},getPointLeftCenter:function(){return{x:this.left,y:this.top+this.getHeight()/2}},getPointRight:function(){return{x:this.right,y:null}},getPointRightCenter:function(){return{x:this.right,y:this.top+this.getHeight()/2}},getPointCenter:function(){return{x:this.left+this.getWidth()/2,y:this.top+this.getHeight()/2}},getHeight:function(){return this.bottom-this.top},getWidth:function(){return this.right-this.left},getTop:function(){return this.top},getLeft:function(){return this.left},getBottom:function(){return this.bottom},getRight:function(){return this.right},getArea:function(){return this.getWidth()*this.getHeight()},constrainTo:function(t){var e,i=this.getIntersection(t);if(!i||!i.equals(this)){var n=t.getWidth(),o=t.getHeight();return this.getWidth()>n&&(this.left=t.left,this.setWidth(n)),this.getHeight()>o&&(this.top=t.top,this.setHeight(o)),e={},this.right>t.right&&(e.left=t.right-this.right),this.bottom>t.bottom&&(e.top=t.bottom-this.bottom),this.left<t.left&&(e.left=t.left-this.left),this.top<t.top&&(e.top=t.top-this.top),this.shift(e),!0}return!1},__IS_REGION:!0}),Object.defineProperties(a.prototype,{width:{get:function(){return this.getWidth()},set:function(t){return this.setWidth(t)}},height:{get:function(){return this.getHeight()},set:function(t){return this.setHeight(t)}}}),i(9)(a),t.exports=a},function(t){"use strict";t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}},function(t,e,i){"use strict";var n=i(1),o=i(2);t.exports=function(t){var e=Math.max,i=Math.min,r={init:function(){var e,i,o={getIntersection:!0,getIntersectionArea:!0,getIntersectionHeight:!0,getIntersectionWidth:!0,getUnion:!0},r=t.prototype,s=n(o);for(i in o)s(i)&&(e=o[i],"string"!=typeof e&&(e=i),function(e,i,n){e[i]=function(e){return t[n]||console.warn("cannot find method ",n," on ",t),t[n](this,e)}}(r,e,i))},validate:o,getDocRegion:function(){return t.fromDOM(document.documentElement)},from:function(e){if(e.__IS_REGION)return e;if("undefined"!=typeof document){if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return t.fromDOM(e);if(e.type&&"undefined"!=typeof e.pageX&&"undefined"!=typeof e.pageY)return t.fromEvent(e)}return t(e)},fromEvent:function(e){return t.fromPoint({x:e.pageX,y:e.pageY})},fromDOM:function(e){var i=e.getBoundingClientRect();return new t({top:i.top,left:i.left,bottom:i.bottom,right:i.right})},getIntersection:function(e,i){var n=this.getIntersectionArea(e,i);return n?new t(n):!1},getIntersectionWidth:function(t,n){var o=i(t.right,n.right),r=e(t.left,n.left);return o>r?o-r:0},getIntersectionHeight:function(t,n){var o=e(t.top,n.top),r=i(t.bottom,n.bottom);return r>o?r-o:0},getIntersectionArea:function(t,n){var o=e(t.top,n.top),r=i(t.right,n.right),s=i(t.bottom,n.bottom),h=e(t.left,n.left);return s>o&&r>h?{top:o,right:r,bottom:s,left:h,width:r-h,height:s-o}:!1},getUnion:function(n,o){var r=i(n.top,o.top),s=e(n.right,o.right),h=e(n.bottom,o.bottom),f=i(n.left,o.left);return new t(r,s,h,f)},getRegion:function(e){return t.from(e)},fromPoint:function(e){return new t({top:e.y,bottom:e.y,left:e.x,right:e.x})}};Object.keys(r).forEach(function(e){t[e]=r[e]}),t.init()}}])});
\No newline at end of file