/**
 * @name ranges-merge
 * @fileoverview Merge and sort string index ranges
 * @version 9.1.3
 * @author Roy Revelt
 * @license MIT
 * {@link https://codsen.com/os/ranges-merge/}
 */

"use strict";var rangesMerge=(()=>{var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var y=(r,t,i)=>t in r?p(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,u=(r,t)=>{for(var i in t||(t={}))f.call(t,i)&&y(r,i,t[i]);if(m)for(var i of m(t))R.call(t,i)&&y(r,i,t[i]);return r};var T=(r,t)=>{for(var i in t)p(r,i,{get:t[i],enumerable:!0})},w=(r,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!f.call(r,a)&&a!==i&&p(r,a,{get:()=>t[a],enumerable:!(s=h(t,a))||s.enumerable});return r};var E=r=>w(p({},"__esModule",{value:!0}),r);var F={};T(F,{defaults:()=>c,rMerge:()=>D,version:()=>x});var j={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function d(r,t){if(!Array.isArray(r)||!r.length)return r;let i=u(u({},j),t),s,a;if(i.strictlyTwoElementsInRangeArrays&&!r.every((o,l)=>!Array.isArray(o)||o.length!==2?(s=l,a=o.length,!1):!0))throw new TypeError("ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ".concat(s,"th range (").concat(JSON.stringify(r[s],null,4),") has not two but ").concat(a," elements!"));if(!r.every((o,l)=>!Array.isArray(o)||!Number.isInteger(o[0])||o[0]<0||!Number.isInteger(o[1])||o[1]<0?(s=l,!1):!0))throw new TypeError("ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ".concat(s,"th range (").concat(JSON.stringify(r[s],null,4),") does not consist of only natural numbers!"));let n=r.length**2,g=0;return Array.from(r).sort((o,l)=>(i.progressFn&&(g+=1,i.progressFn(Math.floor(g*100/n))),o[0]===l[0]?o[1]<l[1]?-1:o[1]>l[1]?1:0:o[0]<l[0]?-1:1))}var $="9.1.3";var x=$,c={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function D(r,t){function i(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}if(!Array.isArray(r)||!r.length)return null;let s;if(t)if(i(t)){if(s=u(u({},c),t),s.progressFn&&i(s.progressFn)&&!Object.keys(s.progressFn).length)s.progressFn=null;else if(s.progressFn&&typeof s.progressFn!="function")throw new Error('ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "'.concat(typeof s.progressFn,'", equal to ').concat(JSON.stringify(s.progressFn,null,4)));if(![1,2,"1","2"].includes(s.mergeType))throw new Error('ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "'.concat(typeof s.mergeType,'", equal to ').concat(JSON.stringify(s.mergeType,null,4)));if(typeof s.joinRangesThatTouchEdges!="boolean")throw new Error('ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "'.concat(typeof s.joinRangesThatTouchEdges,'", equal to ').concat(JSON.stringify(s.joinRangesThatTouchEdges,null,4)))}else throw new Error("emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n".concat(JSON.stringify(t,null,4)," (type ").concat(typeof t,")"));else s=u({},c);let a=r.filter(e=>Array.isArray(e)).map(e=>[...e]).filter(e=>e[2]!==void 0||e[0]!==e[1]),n,g,o;s.progressFn?n=d(a,{progressFn:e=>{o=Math.floor(e/5),o!==g&&(g=o,s.progressFn(o))}}):n=d(a);let l=n.length-1;for(let e=l;e>0;e--)s.progressFn&&(o=Math.floor((1-e/l)*78)+21,o!==g&&o>g&&(g=o,s.progressFn(o))),(n[e][0]<=n[e-1][0]||!s.joinRangesThatTouchEdges&&n[e][0]<n[e-1][1]||s.joinRangesThatTouchEdges&&n[e][0]<=n[e-1][1])&&(n[e-1][0]=Math.min(n[e][0],n[e-1][0]),n[e-1][1]=Math.max(n[e][1],n[e-1][1]),n[e][2]!==void 0&&(n[e-1][0]>=n[e][0]||n[e-1][1]<=n[e][1])&&n[e-1][2]!==null&&(n[e][2]===null&&n[e-1][2]!==null?n[e-1][2]=null:n[e-1][2]!=null?+s.mergeType==2&&n[e-1][0]===n[e][0]?n[e-1][2]=n[e][2]:n[e-1][2]+=n[e][2]:n[e-1][2]=n[e][2]),n.splice(e,1),e=n.length);return n.length?n:null}return E(F);})();
/**
 * @name ranges-sort
 * @fileoverview Sort string index ranges
 * @version 6.1.3
 * @author Roy Revelt
 * @license MIT
 * {@link https://codsen.com/os/ranges-sort/}
 */
