-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.next.min.js
1 lines (1 loc) · 5.1 KB
/
index.next.min.js
1
var A1=function(){"use strict";const t=t=>{let r,s="";for(;t>0;)r=(t-1)%26,s=String.fromCharCode(r+65)+s,t=(t-r-1)/26;return s},r=t=>parseInt(t,10),s=t=>String(t),e=t=>typeof t,i=t=>"string"===e(t),n=t=>"number"===e(t)&&Number.isInteger(t),o=t=>n(t)&&t>0,h=t=>i(t)&&/^[0-9]+$/.test(t)&&o(+t),a=t=>i(t)&&/^[a-z]+$/i.test(t),c=t=>i(t)&&/^[A-Z]+\d+(:[A-Z]+\d+)?$/i.test(t);class _ extends Error{constructor(t){const r=JSON.stringify(t);super(r),this.name="A1Error",this.message=r}s(){return this.message=`Invalid A1 notation: ${this.message}`,this}n(){return this.message=`Invalid A1 number(s): ${this.message}`,this}u(){return this.message=`Invalid A1 argument(s): ${this.message}`,this}}var l;!function(t){t.X="col",t.Y="row"}(l||(l={}));class d{static _reg=/^([A-Z]+)(\d+)(?::([A-Z]+)(\d+))?$/;_colStart=0;_rowStart=0;_colEnd=0;_rowEnd=0;_converter=1;static _parse(t,s){let[,e,i,n,o]=t.toUpperCase().match(this._reg)??[];n=n||e,o=o||i;const h=this._A1Col(e,s),a=this._A1Col(n,s),c=r(i),_=r(o);return{cs:a>h?h:a,rs:_>c?c:_,ce:a>h?a:h,re:_>c?_:c}}static _A1Col(t,r){return 1===r?(t=>{const r=t.length;let s=0;for(let e=0;e<r;e++)s+=(t.charCodeAt(e)-64)*Math.pow(26,r-e-1);return s})(t):(t=>{let r,s,e,i=0,n="A".charCodeAt(0),o="Z".charCodeAt(0)-n+1;for(r=0,s=t.length;r<s;r++)e=t.charCodeAt(r),i=i*o+e-n+1;return i})(t)}static isValid(t){return c(t)}static getCol(t,r=1){if(!c(t))throw new _(t).s();return this._parse(t,r).cs}static getLastCol(t,r=1){if(!c(t))throw new _(t).s();return this._parse(t,r).ce}static toCol(r){if(!o(r))throw new _(r).n();return t(r)}static getRow(t){if(!c(t))throw new _(t).s();return this._parse(t,1).rs}static getLastRow(t){if(!c(t))throw new _(t).s();return this._parse(t,1).re}static toRow(t){if(!o(t))throw new _(t).n();return s(t)}static getWidth(t,r=1){if(!c(t))throw new _(t).s();let{ce:s,cs:e}=this._parse(t,r);return s-e+1}static getHeight(t){if(!c(t))throw new _(t).s();let{re:r,rs:s}=this._parse(t,1);return r-s+1}_initObject(t){const{a1Start:r,a1End:s,colStart:e,colEnd:i,rowStart:n,rowEnd:l,nCols:w,nRows:u,converter:g}=t;this._converter=2===g?2:1;let f=0,S=0,E=0,m=0;const v=(t,r=!0)=>o(t)||h(t)?+t:r&&a(t)?d._A1Col(t,this._converter):0;if(c(r)){const t=d._parse(r,this._converter);f=t.cs,E=t.rs;const s=t.cs===t.ce,e=t.rs===t.re,i=s&&e;(!i||i&&r.includes(":"))&&(S=t.ce,m=t.re)}if(!f&&e&&(f=v(e)),!E&&n&&(E=v(n,!1)),!S&&!m&&c(s)){const t=d._parse(s,this._converter);S=t.ce,m=t.re}if(!S&&i&&(S=v(i)),!m&&l&&(m=v(l,!1)),!S&&f&&o(w)&&(S=f+w-1),!m&&E&&o(u)&&(m=E+u-1),f&&!S&&(S=f),!f&&S&&(f=S),E&&!m&&(m=E),!E&&m&&(E=m),!(f&&E&&S&&m))throw new _(t).u();this._colStart=f,this._rowStart=E,this._colEnd=S,this._rowEnd=m}_initNumber(...t){let[r,s,e,i]=t;e=e||1,i=i||1;let n=[r,s,e,i];if(!n.every((t=>o(t))))throw new _(n.join(", ")).n();this._colStart=r,this._rowStart=s,this._colEnd=r+i-1,this._rowEnd=s+e-1}_initString(...t){const[r,s]=t,e=s?`${r}:${s}`:r;if(!c(e))throw new _(e).s();const{cs:i,rs:n,ce:o,re:h}=d._parse(e,this._converter);this._colStart=i,this._rowStart=n,this._colEnd=o,this._rowEnd=h}constructor(t,r,s,o){if(!arguments.length)throw(new _).u();if(t&&"object"===e(t))this._initObject(t);else if(n(t))this._initNumber.apply(this,arguments);else{if(!i(t))throw new _(t).u();this._initString.apply(this,arguments)}}get(){const r=t(this._colStart)+s(this._rowStart),e=t(this._colEnd)+s(this._rowEnd);return r===e?r:`${r}:${e}`}toString(){return this.get()}toJSON(){return{colStart:this._colStart,rowStart:this._rowStart,colEnd:this._colEnd,rowEnd:this._rowEnd,a1:this.get(),rowsCount:this._rowEnd-this._rowStart+1,colsCount:this._colEnd-this._colStart+1}}getCol(){return this._colStart}getLastCol(){return this._colEnd}getRow(){return this._rowStart}getLastRow(){return this._rowEnd}getWidth(){return this._colEnd-this._colStart+1}getHeight(){return this._rowEnd-this._rowStart+1}copy(){return new d(this.get())}setCol(t){return this._setFields(t,"_colStart",l.X)}setLastCol(t){return this._setFields(t,"_colEnd",l.X)}setRow(t){return this._setFields(t,"_rowStart",l.Y,!1)}setLastRow(t){return this._setFields(t,"_rowEnd",l.Y,!1)}addX(t){return this._addFields(t,l.X)}addY(t){return this._addFields(t,l.Y)}add(t,r){return this.addX(t).addY(r)}removeX(t){return this._removeFields(t,l.X)}removeY(t){return this._removeFields(t,l.Y)}remove(t,r){return this.removeX(t).removeY(r)}shiftX(t){return this._shiftFields(t,l.X)}shiftY(t){return this._shiftFields(t,l.Y)}shift(t,r){return this.shiftX(t).shiftY(r)}_setFields(t,r,s,e=!0){if(o(t)||h(t))this[r]=+t;else{if(!e||!a(t))throw new _(t).u();this[r]=d._A1Col(t,this._converter)}if(this[`_${s}Start`]>this[`_${s}End`])throw new _(`The first column or row can't be bigger than the last, got: ${t}`);return this}_addFields(t,r){if(!n(t))throw new _(t).u();const s=`_${r}Start`;return t>=0?this[`_${r}End`]+=t:this[s]+=t,this[s]<=0&&(this[s]=1),this}_removeFields(t,r){if(!n(t))throw new _(t).u();const s=`_${r}Start`,e=`_${r}End`;return t>=0?(this[e]-=t,this[e]<this[s]&&(this[e]=this[s])):(this[s]-=t,this[s]>this[e]&&(this[s]=this[e])),this}_shiftFields(t,r){if(!n(t))throw new _(t).u();const s=`_${r}Start`,e=`_${r}End`,i=this[e]-this[s],o=this[s]+t,h=this[e]+t;return this[s]=o>0?o:1,this[e]=o>0?h:i+1,this}}return d}();