UNPKG

bump-ts

Version:

![version](https://img.shields.io/npm/v/bump-ts) ![maintenance](https://img.shields.io/maintenance/yes/2021) ![open-issues](https://img.shields.io/github/issues-raw/hood/bump.ts)

3 lines (2 loc) 10.4 kB
"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function r(t,r){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,r){if(t){if("string"==typeof t)return e(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,void 0):void 0}}(t))||r&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(t,e){if(isNaN(t)||t<=0)throw new Error('"'+e+'" must be a positive integer, but was '+t+" ("+typeof t+")")}function i(t,e,r){return Math.abs(e-t)<Math.abs(r-t)?e:r}function o(t,e,r){return{x:i(e,t.x,t.x+t.w),y:i(r,t.y,t.y+t.h)}}function s(t,e,r,n,i,o,s){for(var u,l,a,h,c,f=isNaN(o)?0:o,y=isNaN(s)?1:s,v=n-e,m=i-r,x=0,w=0,d=0,p=0,g=1;g<5;g++)if(1===g?(u=-1,l=0,a=-v,h=e-t.x):2===g?(u=1,l=0,a=v,h=t.x+t.w-e):3===g?(u=0,l=-1,a=-m,h=r-t.y):(u=0,l=1,a=m,h=t.y+t.h-r),0===a){if(h<=0)return}else if(c=h/a,a<0){if(c>y)return;c>f&&(f=c,x=u,w=l)}else{if(c<f)return;c<y&&(y=c,d=u,p=l)}return[f,y,x,w,d,p]}function u(t,e){return{x:e.x-t.x-t.w,y:e.y-t.y-t.h,w:t.w+e.w,h:t.h+e.h}}function l(t,e,r){return e-t.x>1e-10&&r-t.y>1e-10&&t.x+t.w-e>1e-10&&t.y+t.h-r>1e-10}function a(t,e,r,n,i){return t<i.x+i.w&&i.x<t+r&&e<i.y+i.h&&i.y<e+n}function h(t,e){var r=t.x-e.x+(t.w-e.w)/2,n=t.y-e.y+(t.h-e.h)/2;return r*r+n*n}function c(t,e,r,n){var i,a,h,c,f=(null!=r?r:t.x)-t.x,y=(null!=n?n:t.y)-t.y,v=u(t,e);if(l(v,0,0)){var m=o(v,0,0),x=m.y;c=-Math.min(t.w,Math.abs(m.x))*Math.min(t.h,Math.abs(x)),i=!0}else{var w=s(v,0,0,f,y,-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER);if(w){var d=w[0],p=w[1],g=w[2],b=w[3];"number"==typeof d&&d<1&&Math.abs(d-(p||0))>=1e-10&&(0<d+1e-10||0===d&&(p||0)>0)&&(c=d,a=g,h=b,i=!1)}}if("number"==typeof c){var I,M;if(i)if(0===f&&0===y){var E=o(v,0,0),R=E.x,S=E.y;Math.abs(R)<Math.abs(S)?S=0:R=0,a=Math.sign(R),h=Math.sign(S),I=t.x+R,M=t.y+S}else{var N=s(v,0,0,f,y,-Number.MAX_SAFE_INTEGER,1);if(N){var C=N[0];if(a=N[2],h=N[3],!C)return;I=t.x+f*C,M=t.y+y*C}}else I=t.x+f*c,M=t.y+y*c;return{overlaps:i,ti:c,move:{x:f,y:y},normal:{x:a,y:h},touch:{x:I,y:M},itemRect:t,otherRect:e}}}function f(t,e,r){return[Math.floor(e/t)+1,Math.floor(r/t)+1]}function y(t,e,r,n){var i=n-r;return i>0?[1,t/i,((e+i)*t-r)/i]:i<0?[-1,-t/i,((e+i-1)*t-r)/i]:[0,Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER]}function v(t,e){var r=f(t,e.x,e.y),n=r[0],i=r[1];return{x:n,y:i,w:Math.ceil((e.x+e.w)/t)-n+1,h:Math.ceil((e.y+e.h)/t)-i+1}}function m(t,e,r){if(typeof e!==t)throw new Error('"'+r+'" must be a '+t+", but was a "+e+" ("+typeof e+")")}function x(t,e,r,i){m("number",t,"x"),m("number",e,"y"),n(r,"w"),n(i,"h")}function w(t,e,r,n,i,o){return{x:e.touch.x,y:e.touch.y,collisions:[]}}function d(t,e,r,n,i,o){return{x:n,y:i,collisions:t.project(e.item,r,n,i,o)}}function p(t,e,r,n,i,o){var s=null!=n?n:r.x,u=null!=i?i:r.y,l=e.touch,a=e.move;return 0===a.x&&0===a.y||(0!==e.normal.x?s=l.x:u=l.y),e.slide={x:s,y:u},{x:s,y:u,collisions:t.project(e.item,{x:l.x,y:l.y,w:r.w,h:r.h},s,u,o)}}function g(t,e,r,n,i,o){var s=e.touch,u=e.move,l=s.x,a=s.y;if(0!==u.x||0!==u.y){var h=(null!=n?n:r.x)-s.x,c=(null!=i?i:r.y)-s.y;0===e.normal.x?c=-c:h=-h,l=s.x+h,a=s.y+c}return e.bounce={x:l,y:a},{x:l,y:a,collisions:t.project(e.item,{x:s.x,y:s.y,w:r.w,h:r.h},l,a,o)}}function b(t,e){return t.ti===e.ti?h(t.itemRect,t.otherRect)-h(t.itemRect,e.otherRect):t.ti-e.ti}function I(){return"slide"}function M(t,e){return t.weight-e.weight}function E(t,e,r,n,i,o){for(var u,l,a,h=function(t,e,r,n,i){var o=[],s={};return function(t,e,r,n,i,o){var s=f(t,e,r),u=s[0],l=s[1],a=f(t,n,i),h=a[0],c=a[1],v=y(t,u,e,n),m=v[0],x=v[1],w=v[2],d=y(t,l,r,i),p=d[0],g=d[1],b=d[2],I=u,M=l;o(I,M);do{if(w<b){var E=[w+x,I+m];w=E[0],o(I=E[1],M)}else w==b&&o(I+m,M),b+=g,o(I,M+=p)}while(Math.abs(I-h)+Math.abs(M-c)>1);I==h&&M==c||o(h,c)}(t.cellSize,e,r,n,i,(function(e,r){var n=t.rows[r];if(n){var i=n[e];i&&!s[i.ID]&&(s[i.ID]=!0,o.push(i))}})),o}(t,e,r,n,i),c={},v=[],m=0;m<h.length;m++){var x=h[m];if(null!=x&&x.items)for(var w=0,d=Object.keys(x.items);w<d.length;w++){var p=d[w];if(!c[p]&&(c[p]=!0,!o||o(p))){var g=s(u=t.getRect(p),e,r,n,i,0,1);if(!g)continue;if(l=g[0],a=g[1],!isNaN(l)&&(0<l&&l<1||0<a&&a<1)){var b=s(u,e,r,n,i,-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER);if(!b)continue;v.push({item:p,ti1:l,ti2:a,weight:Math.min(b[0]||0,b[1]||0)})}}}}return v.sort(M)}Object.defineProperty(exports,"__esModule",{value:!0});var R=function(){function e(t){this.responses={},this.cellSize=0,this.rects=new Map,this.cellSize=t.cellSize,this.rects=new Map(Object.entries(t.rects)),this.rows=t.rows,this.nonEmptyCells=t.nonEmptyCells,this.responses=t.responses}var n=e.prototype;return n.addResponse=function(t,e){this.responses[t]=e},n.getResponseByName=function(t){var e=this.responses[t];if(!e)throw new Error("Unknown collision type: "+t+" ("+typeof t+")");return e},n.project=function(e,r,n,i,o){var s=null!=n?n:r.x,u=null!=i?i:r.y,l=o||I,a=[],h=new Set;e&&h.add(e);for(var f=s!==r.x?Math.min(s,r.x):s,y=u!==r.y?Math.min(u,r.y):u,m=s!==r.x?Math.max(s+r.w,r.x+r.w):s+r.w,x=u!==r.y?Math.max(u+r.h,r.y+r.h):u+r.h,w=v(this.cellSize,{x:f,y:y,w:m-f,h:x-y}),d=this.getItemsInCellRect(w),p=0;p<d.length;p++){var g=d[p];if(!h.has(g)){if(h.add(g),!this.hasItem(g))continue;var M=l(e,g);if(!1!==M){var E=c(r,this.getRect(g),s,u);E&&a.push(t({},E,{other:g,item:e,type:M}))}}}return a.sort(b)},n.countCells=function(){for(var t,e=0,n=r(this.rows.filter((function(t){return!!t})));!(t=n()).done;)for(var i,o=r(t.value);!(i=o()).done;)i.value&&e++;return e},n.hasItem=function(t){return this.rects.has(t)},n.getItems=function(){return Array.from(this.rects.values())},n.countItems=function(){return this.rects.size},n.addItemToCell=function(t,e,r){this.rows[r]=this.rows[r]||[];var n=this.rows[r];n[e]||(n[e]={ID:"Cell_"+e+":"+r,x:e,y:r,items:{}});var i=n[e];this.nonEmptyCells[i.ID]=!0,i.items[t]||(i.items[t]=!0)},n.getRect=function(t){var e=this.rects.get(t);if(!e)throw new Error('Item "'+t+'" must be added to the world before getting its rect. Use world:add(item, x,y,w,h) to add it first.');return e},n.getItemsInCellRect=function(t){for(var e=[],r=t.y;r<=t.y+t.h-1;r++){var n=this.rows[r];if(n)for(var i=t.x;i<=t.x+t.w-1;i++){var o,s=n[i];null!=s&&s.items&&(null==(o=Object.keys(s.items))?void 0:o.length)>0&&e.push(Object.keys(s.items))}}return e.flat()},n.getItemsInCellPoint=function(t,e){for(var r=[],n=e;n<=e;n++){var i=this.rows[n];if(i)for(var o=t;o<=t;o++){var s,u=i[o];null!=u&&u.items&&(null==(s=Object.keys(u.items))?void 0:s.length)>0&&r.push.apply(r,Object.keys(u.items))}}return r},n.removeItemFromCell=function(t,e,r){var n,i,o,s=this.rows[r];if(null==s||null==(n=s[e])||null==(i=n.items)||!i[t])return!1;var u=s[e];return delete u.items[t],0===(null==(o=Object.keys(u.items))?void 0:o.length)&&delete this.nonEmptyCells[u.ID],!0},n.toWorld=function(t,e){return function(t,e,r){return[(e-1)*t,(r-1)*t]}(this.cellSize,t,e)},n.toCell=function(t,e){return f(this.cellSize,t,e)},n.queryRect=function(t,e,n,i,o){x(t,e,n,i);for(var s,u=v(this.cellSize,{x:t,y:e,w:n,h:i}),l=[],h=r(this.getItemsInCellRect(u));!(s=h()).done;){var c=s.value;o&&!o(c)||!a(t,e,n,i,this.getRect(c))||l.push(c)}return[].concat(new Set(l))},n.queryPoint=function(t,e,r){for(var n=this.toCell(t,e),i=this.getItemsInCellPoint(n[0],n[1]),o=[],s=0;s<i.length;s++){var u=i[s];r&&!r(u)||!l(this.getRect(u),t,e)||o.push(u)}return o},n.querySegment=function(t,e,r,n,i){var o=E(this,t,e,r,n,i),s=[];if(o)for(var u=0;u<o.length;u++)s.push(o[u].item);return s},n.querySegmentWithCoords=function(t,e,n,i,o){for(var s,u,l,a,h=E(this,t,e,n,i,o),c=n-t,f=i-e,y=r(h);!(a=y()).done;)u=(s=a.value).ti1,l=s.ti2,s.weight=null,s.x1=t+c*u,s.y1=e+f*u,s.x2=t+c*l,s.y2=e+f*l;return h},n.add=function(t,e,r,n,i){if(this.rects.get(t))throw new Error('Item "'+t+'" added to the world twice.');x(e,r,n,i);var o={x:e,y:r,w:n,h:i};this.rects.set(t,o);for(var s=v(this.cellSize,o),u=s.y;u<s.y+s.h;u++)for(var l=s.x;l<s.x+s.w;l++)this.addItemToCell(t,l,u);return t},n.remove=function(t){var e=this.getRect(t),r={x:e.x,y:e.y,w:e.w,h:e.h};this.rects.delete(t);for(var n=v(this.cellSize,r),i=n.y;i<n.y+n.h;i++)for(var o=n.x;o<n.x+n.w;o++)this.removeItemFromCell(t,o,i)},n.update=function(t,e,r,n,i){var o=this.getRect(t);if(x(e,r,n=isNaN(n)?o.w:n,i=isNaN(i)?o.h:i),o.x!=e||o.y!=r||o.w!=n||o.h!=i){var s=v(this.cellSize,o),u=v(this.cellSize,{x:e,y:r,w:n,h:i});if(s.x!=u.x||s.y!=u.y||s.w!=u.w||s.h!=u.h){for(var l,a=s.x+s.w-1,h=s.y+s.h-1,c=u.x+u.w-1,f=u.y+u.h-1,y=s.y;y<=h;y++){l=Number(y)<u.y||y>f;for(var m=s.x;m<=a;m++)(l||m<u.x||m>c)&&this.removeItemFromCell(t,m,y)}for(var w=u.y;w<=f;w++){l=w<s.y||w>h;for(var d=u.x;d<=c;d++)(l||d<s.x||d>a)&&this.addItemToCell(t,d,w)}}this.rects.set(t,{x:e,y:r,w:n,h:i})}},n.move=function(t,e,r,n){var i=this.check(t,e,r,n),o=i.x,s=i.y,u=i.collisions;return this.update(t,o,s),{x:o,y:s,collisions:u}},n.check=function(t,e,r,n){var i,o=n||I,s={};s[t]=!0;for(var u=function(t,e){return!s[e]&&o(t,e)},l=[],a=this.getRect(t),h=this.project(t,a,e,r,u),c=(null==(i=h)?void 0:i.length)||0;c>0;){var f=h[0];l.push(f),s[f.other]=!0;var y=this.getResponseByName(f.type)(this,f,a,e,r,u),v=y.collisions;e=y.x,r=y.y,h=v,c=(null==v?void 0:v.length)||0}return{x:e,y:r,collisions:l}},e}(),S=Object.freeze({newWorld:function(t){n(t=t||64,"cellSize");var e=new R({cellSize:t,rects:{},rows:[],nonEmptyCells:{},responses:{}});return e.addResponse("touch",w),e.addResponse("cross",d),e.addResponse("slide",p),e.addResponse("bounce",g),e},rect:{getNearestCorner:o,getSegmentIntersectionIndices:s,getDiff:u,containsPoint:l,isIntersecting:a,getSquareDistance:h,detectCollision:c},responses:{touch:w,cross:d,slide:p,bounce:g}});exports.World=R,exports.default=S; //# sourceMappingURL=bump-ts.cjs.production.min.js.map