UNPKG

string-remove-widows

Version:

Helps to prevent widow words in a text

103 lines (101 loc) 31.5 kB
/** * @name string-remove-widows * @fileoverview Helps to prevent widow words in a text * @version 4.0.26 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-remove-widows/} */ "use strict";var stringRemoveWidows=(()=>{var Pe=Object.create;var F=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames,de=Object.getOwnPropertySymbols,ke=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var q=(e,t,i)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,T=(e,t)=>{for(var i in t||(t={}))me.call(t,i)&&q(e,i,t[i]);if(de)for(var i of de(t))Ue.call(t,i)&&q(e,i,t[i]);return e};var qe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Qe=(e,t)=>{for(var i in t)F(e,i,{get:t[i],enumerable:!0})},he=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let g of Je(t))!me.call(e,g)&&g!==i&&F(e,g,{get:()=>t[g],enumerable:!(n=Be(t,g))||n.enumerable});return e};var pe=(e,t,i)=>(i=e!=null?Pe(ke(e)):{},he(t||!e||!e.__esModule?F(i,"default",{value:e,enumerable:!0}):i,e)),Ge=e=>he(F({},"__esModule",{value:!0}),e);var Q=(e,t,i)=>q(e,typeof t!="symbol"?t+"":t,i);var G=qe((ft,be)=>{"use strict";be.exports=Ke;function x(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function Ke(e){if(e=e||{},e.circles)return Ze(e);let t=new Map;if(t.set(Date,c=>new Date(c)),t.set(Map,(c,u)=>new Map(n(Array.from(c),u))),t.set(Set,(c,u)=>new Set(n(Array.from(c),u))),e.constructorHandlers)for(let c of e.constructorHandlers)t.set(c[0],c[1]);let i=null;return e.proto?r:g;function n(c,u){let l=Object.keys(c),o=new Array(l.length);for(let a=0;a<l.length;a++){let d=l[a],p=c[d];typeof p!="object"||p===null?o[d]=p:p.constructor!==Object&&(i=t.get(p.constructor))?o[d]=i(p,u):ArrayBuffer.isView(p)?o[d]=x(p):o[d]=u(p)}return o}function g(c){if(typeof c!="object"||c===null)return c;if(Array.isArray(c))return n(c,g);if(c.constructor!==Object&&(i=t.get(c.constructor)))return i(c,g);let u={};for(let l in c){if(Object.hasOwnProperty.call(c,l)===!1)continue;let o=c[l];typeof o!="object"||o===null?u[l]=o:o.constructor!==Object&&(i=t.get(o.constructor))?u[l]=i(o,g):ArrayBuffer.isView(o)?u[l]=x(o):u[l]=g(o)}return u}function r(c){if(typeof c!="object"||c===null)return c;if(Array.isArray(c))return n(c,r);if(c.constructor!==Object&&(i=t.get(c.constructor)))return i(c,r);let u={};for(let l in c){let o=c[l];typeof o!="object"||o===null?u[l]=o:o.constructor!==Object&&(i=t.get(o.constructor))?u[l]=i(o,r):ArrayBuffer.isView(o)?u[l]=x(o):u[l]=r(o)}return u}}function Ze(e){let t=[],i=[],n=new Map;if(n.set(Date,l=>new Date(l)),n.set(Map,(l,o)=>new Map(r(Array.from(l),o))),n.set(Set,(l,o)=>new Set(r(Array.from(l),o))),e.constructorHandlers)for(let l of e.constructorHandlers)n.set(l[0],l[1]);let g=null;return e.proto?u:c;function r(l,o){let a=Object.keys(l),d=new Array(a.length);for(let p=0;p<a.length;p++){let h=a[p],m=l[h];if(typeof m!="object"||m===null)d[h]=m;else if(m.constructor!==Object&&(g=n.get(m.constructor)))d[h]=g(m,o);else if(ArrayBuffer.isView(m))d[h]=x(m);else{let y=t.indexOf(m);y!==-1?d[h]=i[y]:d[h]=o(m)}}return d}function c(l){if(typeof l!="object"||l===null)return l;if(Array.isArray(l))return r(l,c);if(l.constructor!==Object&&(g=n.get(l.constructor)))return g(l,c);let o={};t.push(l),i.push(o);for(let a in l){if(Object.hasOwnProperty.call(l,a)===!1)continue;let d=l[a];if(typeof d!="object"||d===null)o[a]=d;else if(d.constructor!==Object&&(g=n.get(d.constructor)))o[a]=g(d,c);else if(ArrayBuffer.isView(d))o[a]=x(d);else{let p=t.indexOf(d);p!==-1?o[a]=i[p]:o[a]=c(d)}}return t.pop(),i.pop(),o}function u(l){if(typeof l!="object"||l===null)return l;if(Array.isArray(l))return r(l,u);if(l.constructor!==Object&&(g=n.get(l.constructor)))return g(l,u);let o={};t.push(l),i.push(o);for(let a in l){let d=l[a];if(typeof d!="object"||d===null)o[a]=d;else if(d.constructor!==Object&&(g=n.get(d.constructor)))o[a]=g(d,u);else if(ArrayBuffer.isView(d))o[a]=x(d);else{let p=t.indexOf(d);p!==-1?o[a]=i[p]:o[a]=u(d)}}return t.pop(),i.pop(),o}}});var ut={};Qe(ut,{defaults:()=>_e,removeWidows:()=>lt,version:()=>at});function $e(e){return typeof e!="string"?e:e.length?[e]:[]}var ye=pe(G(),1);var dt=(0,ye.default)();var we="\u2013",Ee="\u2014",I="\xA0";function H(e){if(e==null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function D(e){return typeof e=="string"}function C(e){return Number.isSafeInteger(e)&&e>=0}function R(e){return e!=null}function Ae(e,t){return H(e)&&D(t)&&t in e}var Te={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},ze=e=>e+1;function Ye(e,t,i,n,g=!1,r=ze){var w;let c=typeof i=="function"?i():i;if(+t<0&&g&&c==="EOL")return c;let u=T(T({},Te),n);if(t>=e.length&&!g)return!1;let l=g?1:i.length,o=0,a=!1,d=!1,p=!1,h=u.maxMismatches,m=t,y=!1,S=!1,E=!1;function A(){return o===1&&h<u.maxMismatches-1}for(;e[m];){let $=r(m);if(u.trimBeforeMatching&&e[m].trim()===""){if(!e[$]&&g&&i==="EOL")return!0;m=r(m);continue}if(u&&!u.i&&((w=u==null?void 0:u.trimCharsBeforeMatching)!=null&&w.includes(e[m]))||u!=null&&u.i&&u.trimCharsBeforeMatching&&u.trimCharsBeforeMatching.map(f=>f.toLowerCase()).includes(e[m].toLowerCase())){if(g&&i==="EOL"&&!e[$])return!0;m=r(m);continue}let O=$>m?i[i.length-l]:i[l-1];if(!u.i&&e[m]===O||u.i&&e[m].toLowerCase()===O.toLowerCase()){if(y||(y=!0),p||(p=!0),l===i.length){if(S=!0,h!==u.maxMismatches)return!1}else l===1&&(E=!0);if(l-=1,o++,A())return!1;if(!l)return o!==i.length||h===u.maxMismatches||!a?m:!1}else if(!a&&!o&&(a=!0),u.maxMismatches&&h&&m){h-=1;for(let f=0;f<=h;f++){let v=$>m?i[i.length-l+1+f]:i[l-2-f],M=e[r(m)];if(v&&(!u.i&&e[m]===v||u.i&&e[m].toLowerCase()===v.toLowerCase())&&(!u.firstMustMatch||l!==i.length)){if(o++,A())return!1;l-=2,y=!0;break}else if(M&&v&&(!u.i&&M===v||u.i&&M.toLowerCase()===v.toLowerCase())&&(!u.firstMustMatch||l!==i.length)){if(!o&&!u.hungry)return!1;l-=1,y=!0;break}else if(v===void 0&&h>=0&&y&&(!u.firstMustMatch||S)&&(!u.lastMustMatch||E))return m}y||(d=m)}else return m===0&&l===1&&!u.lastMustMatch&&p?0:!1;if(d!==!1&&d!==m&&(d=!1),l<1)return m;m=r(m)}if(l>0)return g&&c==="EOL"?!0:u&&u.maxMismatches>=l&&p?d||0:!1}function Xe(e,t,i,n,g){var a,d,p;if(H(g)&&Ae(g,"trimBeforeMatching")&&g&&typeof g.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${e}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(g.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let r=T(T({},Te),g);if(typeof r.trimCharsBeforeMatching=="string"&&(r.trimCharsBeforeMatching=$e(r.trimCharsBeforeMatching)),r.trimCharsBeforeMatching=r.trimCharsBeforeMatching.map(h=>D(h)?h:String(h)),!D(t)||!t.length)return!1;if(!Number.isInteger(i)||i<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof i}, equal to: ${JSON.stringify(i,null,4)}`);let c,u;if(D(n))c=[n];else if(Array.isArray(n))c=n;else if(!n)c=n;else if(typeof n=="function")c=[],c.push(n);else throw new Error(`string-match-left-right/${e}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof n}, equal to: ${JSON.stringify(n,null,4)}`);if(g&&!H(g))throw new Error(`string-match-left-right/${e}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof g}", and equal to: ${JSON.stringify(g,null,4)}`);let l=0,o="";if((a=r==null?void 0:r.trimCharsBeforeMatching)!=null&&a.some((h,m)=>h.length>1?(l=m,o=h,!0):!1))throw new Error(`string-match-left-right/${e}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${l} is longer than 1 character, ${o.length} (equals to ${o}). Please split it into separate characters and put into array as separate elements.`);if(!c||!Array.isArray(c)||Array.isArray(c)&&!c.length||Array.isArray(c)&&c.length===1&&D(c[0])&&!c[0].trim()){if(typeof r.cb=="function"){let m,y=i;if((e==="matchLeftIncl"||e==="matchRight")&&(y+=1),e[5]==="L")for(let w=y;w--;){let $=t[w];if((!r.trimBeforeMatching||r.trimBeforeMatching&&($!=null&&$.trim()))&&(!((d=r.trimCharsBeforeMatching)!=null&&d.length)||$!==void 0&&!r.trimCharsBeforeMatching.includes($))){m=w;break}}else if(e.startsWith("matchRight"))for(let w=y;w<t.length;w++){let $=t[w];if((!r.trimBeforeMatching||r.trimBeforeMatching&&$.trim())&&(!((p=r.trimCharsBeforeMatching)!=null&&p.length)||!r.trimCharsBeforeMatching.includes($))){m=w;break}}if(m===void 0)return!1;let S=t[m],E=m+1,A="";return E&&E>0&&(A=t.slice(0,E)),e[5]==="L"||m&&m>0&&(A=t.slice(m)),r.cb(S,A,m)}let h="";throw g||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${h}`)}for(let h=0,m=c.length;h<m;h++){u=typeof c[h]=="function";let y=c[h],S,E,A="",w=i;e==="matchRight"?w+=1:e==="matchLeft"&&(w-=1);let $=Ye(t,w,y,r,u,O=>e[5]==="L"?O-1:O+1);if($&&u&&typeof y=="function"&&y()==="EOL")return y()&&(!r.cb||r.cb(S,A,E))?y():!1;if(Number.isInteger($)&&(E=e.startsWith("matchLeft")?$-1:$+1,e[5]==="L"?A=t.slice(0,$):A=t.slice(E)),E<0&&(E=void 0),t[E]&&(S=t[E]),Number.isInteger($)&&(!r.cb||r.cb(S,A,E)))return y}return!1}function Se(e,t,i,n){return Xe("matchRightIncl",e,t,i,n)}var ve=pe(G(),1);var wt=(0,ve.default)();var L="\xA0";function et({str:e,idx:t=0,stopAtNewlines:i=!1,stopAtRawNbsp:n=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||i&&` \r`.includes(e[t+1])||n&&e[t+1]===L))return t+1;if(e[t+2]&&(e[t+2].trim()||i&&` \r`.includes(e[t+2])||n&&e[t+2]===L))return t+2;for(let g=t+1,r=e.length;g<r;g++)if(e[g].trim()||i&&` \r`.includes(e[g])||n&&e[g]===L)return g;return null}function j(e,t=0){return et({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function tt({str:e,idx:t,stopAtNewlines:i,stopAtRawNbsp:n}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||i&&` \r`.includes(e[~-t])||n&&e[~-t]===L))return~-t;if(e[t-2]&&(e[t-2].trim()||i&&` \r`.includes(e[t-2])||n&&e[t-2]===L))return t-2;for(let g=t;g--;)if(e[g]&&(e[g].trim()||i&&` \r`.includes(e[g])||n&&e[g]===L))return g;return null}function _(e,t=0){return tt({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function k(e,t=1){let i="\xA0";function n(r){return Array.from(r).reverse().join("")}function g(r,c,u){let l=u?` `:"\r",o=u?"\r":` `;if(!r)return r;let a=0,d=0,p="";for(let h=0,m=r.length;h<m;h++)(r[h]===l||r[h]===o&&r[h-1]!==l)&&d++,`\r `.includes(r[h])||r[h]===i?(a=0,r[h]===i?p+=r[h]:r[h]===l?d<=c&&(p+=r[h],r[h+1]===o&&(p+=r[h+1],h++)):r[h]===o&&(r==null?void 0:r[h-1])!==l&&d<=c&&(p+=r[h])):(a++,!r[h+1]&&!d&&(p+=" "));return p}if(typeof e=="string"&&e.length){let r=1;typeof+t=="number"&&Number.isInteger(+t)&&+t>=0&&(r=+t);let c="",u="";if(!e.trim())c=e;else if(!e[0].trim()){for(let l=0,o=e.length;l<o;l++)if(e[l].trim()){c=e.slice(0,l);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===i)){for(let l=e.length;l--;)if(e[l].trim()){u=e.slice(l+1);break}}return`${g(c,r,!1)}${e.trim()}${n(g(n(u),r,!0))}`}return e}var rt={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function V(e,t){if(!Array.isArray(e)||!e.length)return e;let i=T(T({},rt),t),n,g;if(i.strictlyTwoElementsInRangeArrays&&!e.every((u,l)=>!Array.isArray(u)||u.length!==2?(n=l,g=u.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, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${g} elements!`);if(!e.every((u,l)=>!Array.isArray(u)||!Number.isInteger(u[0])||u[0]<0||!Number.isInteger(u[1])||u[1]<0?(n=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, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let r=e.length**2,c=0;return Array.from(e).sort((u,l)=>(i.progressFn&&(c+=1,i.progressFn(Math.floor(c*100/r))),u[0]===l[0]?u[1]<l[1]?-1:u[1]>l[1]?1:0:u[0]<l[0]?-1:1))}var Ne={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function nt(e,t){var o;function i(a){return!!a&&typeof a=="object"&&!Array.isArray(a)}if(!Array.isArray(e)||!e.length)return null;let n;if(t)if(i(t)){if(n=T(T({},Ne),t),n.progressFn&&i(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(![1,2,"1","2"].includes(n.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`ranges-merge: [THROW_ID_03] the second input argument must be a plain object. It was given as: ${JSON.stringify(t,null,4)} (type ${typeof t})`);else n=T({},Ne);let g=e.filter(a=>Array.isArray(a)).map(a=>[...a]).filter(a=>a[2]!==void 0||a[0]!==a[1]),r,c,u;n.progressFn?r=V(g,{progressFn:a=>{u=Math.floor(a/5),u!==c&&(c=u,n.progressFn!=null&&n.progressFn(u))}}):r=V(g);let l=r.length-1;for(let a=l;a>0;a--)n.progressFn&&(u=Math.floor((1-a/l)*78)+21,u!==c&&u>c&&(c=u,n.progressFn(u))),(r[a][0]<=r[a-1][0]||!n.joinRangesThatTouchEdges&&r[a][0]<r[a-1][1]||n.joinRangesThatTouchEdges&&r[a][0]<=r[a-1][1])&&(r[a-1][0]=Math.min(r[a][0],r[a-1][0]),r[a-1][1]=Math.max(r[a][1],r[a-1][1]),r[a][2]!==void 0&&(r[a-1][0]>=r[a][0]||r[a-1][1]<=r[a][1])&&r[a-1][2]!==null&&(r[a][2]===null&&r[a-1][2]!==null?r[a-1][2]=null:r[a-1][2]!=null?+((o=n||{})==null?void 0:o.mergeType)==2&&r[a-1][0]===r[a][0]?r[a-1][2]=r[a][2]:r[a-1][2]+=r[a][2]:r[a-1][2]=r[a][2]),r.splice(a,1),a=r.length);return r.length?r:null}var st={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},De=class{constructor(e){Q(this,"ranges");Q(this,"opts");let t=T(T({},st),e);if(t.mergeType&&t.mergeType!==1&&t.mergeType!==2)if(D(t.mergeType)&&t.mergeType.trim()==="1")t.mergeType=1;else if(D(t.mergeType)&&t.mergeType.trim()==="2")t.mergeType=2;else throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof t.mergeType}", equal to ${JSON.stringify(t.mergeType,null,4)}`);this.opts=t,this.ranges=[]}add(e,t,i){var r;if(e==null&&t==null)return;if(R(e)&&!R(t)){if(Array.isArray(e)){if(e.length){if(e.some(c=>Array.isArray(c))){e.forEach(c=>{Array.isArray(c)&&this.add(...c)});return}e.length&&C(+e[0])&&C(+e[1])&&this.add(...e)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(e,null,0)}) but second-one, "to" is not (${JSON.stringify(t,null,0)})`)}else if(!R(e)&&R(t))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(t,null,0)}) but first-one, "from" is not (${JSON.stringify(e,null,0)})`);let n=+e,g=+t;if(C(i)&&(i=String(i)),C(n)&&C(g)){if(R(i)&&!D(i)&&!C(i))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof i}, equal to: ${JSON.stringify(i,null,4)}`);if(R(this.ranges)&&Array.isArray(this.last())&&n===this.last()[1]){if(this.last()[1]=g,this.last()[2],this.last()[2]!==null&&R(i)){let c=this.last()[2]&&this.last()[2].length&&(!((r=this.opts)!=null&&r.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${i}`:i;this.opts.limitToBeAddedWhitespace&&(c=k(c,this.opts.limitLinebreaksCount)),D(c)&&!c.length||(this.last()[2]=c)}}else{this.ranges||(this.ranges=[]);let c=i!==void 0&&!(D(i)&&!i.length)?[n,g,i&&this.opts.limitToBeAddedWhitespace?k(i,this.opts.limitLinebreaksCount):i]:[n,g];this.ranges.push(c)}}else throw C(n)&&n>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof g}" equal to: ${JSON.stringify(g,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof n}" equal to: ${JSON.stringify(n,null,4)}`)}push(e,t,i){this.add(e,t,i)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=nt(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>R(e[2])?[e[0],e[1],k(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&C(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var Oe={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function We(e,t){function i(o){return!!o&&typeof o=="object"&&!Array.isArray(o)}if(!Array.isArray(e)||!e.length)return null;let n;if(t)if(i(t)){if(n=T(T({},Oe),t),n.progressFn&&i(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(![1,2,"1","2"].includes(n.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: ${JSON.stringify(t,null,4)} (type ${typeof t})`);else n=T({},Oe);let g=e.filter(o=>Array.isArray(o)).map(o=>[...o]).filter(o=>o[2]!==void 0||o[0]!==o[1]),r,c,u;n.progressFn?r=V(g,{progressFn:o=>{u=Math.floor(o/5),u!==c&&(c=u,n.progressFn(u))}}):r=V(g);let l=r.length-1;for(let o=l;o>0;o--)n.progressFn&&(u=Math.floor((1-o/l)*78)+21,u!==c&&u>c&&(c=u,n.progressFn(u))),(r[o][0]<=r[o-1][0]||!n.joinRangesThatTouchEdges&&r[o][0]<r[o-1][1]||n.joinRangesThatTouchEdges&&r[o][0]<=r[o-1][1])&&(r[o-1][0]=Math.min(r[o][0],r[o-1][0]),r[o-1][1]=Math.max(r[o][1],r[o-1][1]),r[o][2]!==void 0&&(r[o-1][0]>=r[o][0]||r[o-1][1]<=r[o][1])&&r[o-1][2]!==null&&(r[o][2]===null&&r[o-1][2]!==null?r[o-1][2]=null:r[o-1][2]!=null?+n.mergeType==2&&r[o-1][0]===r[o][0]?r[o-1][2]=r[o][2]:r[o-1][2]+=r[o][2]:r[o-1][2]=r[o][2]),r.splice(o,1),o=r.length);return r.length?r:null}var ot=!0,K="Invariant failed";function Ce(e,t){if(!e){if(ot)throw new Error(K);var i=typeof t=="function"?t():t,n=i?"".concat(K,": ").concat(i):K;throw new Error(n)}}function Z(e,t,i){let n=0,g=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(i&&typeof i!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof i}, equal to: ${JSON.stringify(i,null,4)}`);if(!(t!=null&&t.filter(a=>a).length))return e;let r;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?r=[Array.from(t)]:r=Array.from(t);let c=r.length,u=0;r.filter(a=>a).forEach((a,d)=>{if(i&&(n=Math.floor(u/c*10),n!==g&&(g=n,i(n))),!Array.isArray(a))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${d}th element not an array: ${JSON.stringify(a,null,4)}, which is ${typeof a}`);if(!Number.isInteger(a[0])){if(!Number.isInteger(+a[0])||+a[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${d}th element, array ${JSON.stringify(a,null,0)}. Its first element is not an integer, string index, but ${typeof a[0]}, equal to: ${JSON.stringify(a[0],null,4)}.`);r[d][0]=+r[d][0]}if(!Number.isInteger(a[1])){if(!Number.isInteger(+a[1])||+a[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${d}th element, array ${JSON.stringify(a,null,0)}. Its second element is not an integer, string index, but ${typeof a[1]}, equal to: ${JSON.stringify(a[1],null,4)}.`);r[d][1]=+r[d][1]}u+=1});let l=We(r,{progressFn:a=>{i&&(n=10+Math.floor(a/10),n!==g&&(g=n,i(n)))}});Ce(l);let o=l.length;if(o>0){let a=e.slice(l[o-1][1]);e=l.reduce((d,p,h,m)=>{i&&(n=20+Math.floor(h/o*80),n!==g&&(g=n,i(n)));let y=h===0?0:m[h-1][1],S=m[h][0];return`${d}${e.slice(y,S)}${m[h][2]||""}`},""),e+=a}return e}var Re="4.0.26";var P="&nbsp;",B="\\00A0",J="\\u00A0",Me="&ndash;",xe="\\2013",Ie="\\u2013",Le="&mdash;",je="\\2014",Ve="\\u2014",z=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],Fe=[{heads:"{{",tails:"}}"}],Y=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],He=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var at=Re,_e={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function lt(e,t){var ee,te,re,ne,se,oe,ie,ae,le,ue;let i=Date.now();if(typeof e!="string")throw e===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof e}", equal to: ${JSON.stringify(e,null,4)}`);if(t&&typeof t!="object")throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof t}, equal to ${JSON.stringify(t,null,4)}`);let n=Array.isArray,g=e.length,r=new De({mergeType:2}),c=["."],u=/[A-Z]{1,2}[0-9][0-9A-Z]?$/,l=/^[0-9][A-Z]{2}/,o=.06,a,d=0,p=0,h=0,m,y,S,E,A,w,$,O,f=T(T({},_e),t),v={removeWidows:!1,convertEntities:!1};if(!f.ignore||!n(f.ignore)&&typeof f.ignore!="string")f.ignore=[];else if(typeof f.ignore=="string"&&(f.ignore=[f.ignore]),f.ignore.includes("all"))f.ignore=f.ignore.concat(z.concat(Y));else if(f.ignore.some(s=>typeof s=="string")){let s=[];f.ignore=f.ignore.filter(N=>typeof N=="string"&&N.length?(["nunjucks","jinja","liquid"].includes(N.trim().toLowerCase())?s=s.concat(z):["hugo"].includes(N.trim().toLowerCase())?s=s.concat(Fe):["hexo"].includes(N.trim().toLowerCase())&&(s=s.concat(Y)),!1):typeof N=="object"),s.length&&(f.ignore=f.ignore.concat(s))}let M;f.reportProgressFunc&&(M=Math.floor(f.reportProgressFuncTo-(f.reportProgressFuncTo-f.reportProgressFuncFrom)*o-f.reportProgressFuncFrom));function U(s,N){let b=I;f.removeWidowPreventionMeasures?b=" ":f.convertEntities&&(b=P,typeof f.targetLanguage=="string"&&(f.targetLanguage.trim().toLowerCase()==="css"?b=B:f.targetLanguage.trim().toLowerCase()==="js"&&(b=J))),e.slice(s,N)!==b&&r.push(s,N,b)}function X(){p=0,h=0,m=void 0,y=void 0,S=void 0,E=void 0,A=void 0,w=void 0}X();for(let s=0;s<=g;s++){if(!$&&n(f.ignore)&&f.ignore.length&&f.ignore.some((b,W)=>{if(n(b.heads)&&b.heads.some(ce=>e.startsWith(ce,s))||typeof b.heads=="string"&&e.startsWith(b.heads,s))return p+=1,$=f.ignore[W].tails,!0}),!$&&O&&O===s&&(p+=1,O=void 0),typeof f.reportProgressFunc=="function"&&(a=f.reportProgressFuncFrom+Math.floor(s/g*(M||1)),a!==d&&(d=a,f.reportProgressFunc(a))),!$&&s&&((ee=e[s])!=null&&ee.trim())&&(!e[s-1]||e[s-1]&&!e[s-1].trim())&&(E=s),!$&&((te=e[s])!=null&&te.trim())&&(h+=1),!$&&f.hyphens&&(`-${Ee}${we}`.includes(e[s])||e.startsWith(Me,s)||e.startsWith(xe,s)||e.startsWith(Ie,s)||e.startsWith(Le,s)||e.startsWith(je,s)||e.startsWith(Ve,s))&&e[s+1]&&(!e[s+1].trim()||e[s]==="&")&&e[s-1]&&!e[s-1].trim()&&e[_(e,s)]&&(U(_(e,s)+1,s),v.removeWidows=!0),!$&&(e.startsWith("&nbsp;",s)||e.startsWith("&#160;",s))&&(A=s,w=s+6,(re=e[s+6])!=null&&re.trim()&&(O=s+6),f.convertEntities?(f.targetLanguage==="css"||f.targetLanguage==="js")&&(r.push(s,s+6,f.targetLanguage==="css"?B:J),v.convertEntities=!0):(r.push(s,s+6,I),v.convertEntities=!0)),!$&&e[s+4]&&e[s]==="\\"&&e[s+1]==="0"&&e[s+2]==="0"&&e[s+3].toUpperCase()==="A"&&e[s+4]==="0"&&(A=s,w=s+5,(ne=e[s+5])!=null&&ne.trim()&&(O=s+5),f.convertEntities?(f.targetLanguage==="html"||f.targetLanguage==="js")&&(r.push(s,s+5,f.targetLanguage==="html"?P:J),v.convertEntities=!0):(r.push(s,s+5,I),v.convertEntities=!0)),!$&&e[s]==="\\"&&e[s+1]&&e[s+1].toLowerCase()==="u"&&e[s+2]==="0"&&e[s+3]==="0"&&e[s+4]&&e[s+4].toUpperCase()==="A"&&e[s+5]==="0"&&(A=s,w=s+6,(se=e[s+6])!=null&&se.trim()&&(O=s+6),f.convertEntities?(f.targetLanguage==="html"||f.targetLanguage==="css")&&r.push(s,s+6,f.targetLanguage==="html"?P:B):r.push(s,s+6,I)),!$&&e[s]===I&&(A=s,w=s+1,f.convertEntities&&r.push(s,s+1,f.targetLanguage==="css"?B:f.targetLanguage==="js"?J:P)),!$&&((oe=e[s])!=null&&oe.trim())&&!((ie=e[s-1])!=null&&ie.trim())&&(p+=1),!$&&(!e[s]||`\r `.includes(e[s])||(e[s]===` `||e[s]==="\r"||e[s]==="\r"&&e[s+1]===` `)&&_(e,s)&&c.includes(e[_(e,s)]))){if((!f.minWordCount||p>=f.minWordCount)&&(!f.minCharCount||h>=f.minCharCount)){let b,W;S!==void 0&&E!==void 0&&A!==void 0&&w!==void 0?S>A?(b=S,W=E):(b=A,W=w):S!==void 0&&E!==void 0?(b=S,W=E):A!==void 0&&w!==void 0&&(b=A,W=w),!(b&&W)&&m&&y&&(b=m,W=y),b&&W&&(U(b,W),v.removeWidows=!0)}X()}f.UKPostcodes&&e[s]&&!e[s].trim()&&((ae=e[s-1])!=null&&ae.trim())&&u.test(e.slice(0,s))&&e[j(e,s)]&&l.test(e.slice(j(e,s)))&&(U(s,j(e,s)),v.removeWidows=!0),!$&&e[s]&&!e[s].trim()&&((le=e[s-1])!=null&&le.trim())&&(S===void 0||(ue=e[S-1])!=null&&ue.trim())&&!"/>".includes(e[j(e,s)])&&!e.slice(0,s).trim().endsWith("br")&&!e.slice(0,s).trim().endsWith("hr")&&!(e.slice(0,s).endsWith("<")&&He.some(b=>e.startsWith(b,j(e,s))))&&(m=S,y=E,S=s,E=void 0,(A!==void 0||w!==void 0)&&(A=void 0,w=void 0));let N;$&&(typeof $=="string"&&(!$.length||e.startsWith($,s))?$=void 0:n($)&&(!$.length||$.some(b=>{if(e.startsWith(b,s))return N=b,!0}))&&($=void 0,s+=N.length,n(f.ignore)&&f.ignore.length&&e[s+1]&&f.ignore.some(b=>Se(e,s,b.tails,{trimBeforeMatching:!0,cb:(W,ce,ge)=>{var fe;return ge&&(s=ge-1,(fe=e[s+1])!=null&&fe.trim()&&(p+=1)),!0}})))),e[s]&&`\r `.includes(e[s])&&(p=0,h=0),n(f.tagRanges)&&f.tagRanges.length&&f.tagRanges.some(b=>{if(s>=b[0]&&s<=b[1]&&b[1]-1>s)return s=b[1]-1,!0})}return Z(e,r.current()).split("").forEach((s,N)=>{}),{res:Z(e,r.current(),f.reportProgressFunc?s=>{a=Math.floor((f.reportProgressFuncTo-f.reportProgressFuncFrom)*(1-o)+s/100*(f.reportProgressFuncTo-f.reportProgressFuncFrom)*o),a!==d&&(d=a,f.reportProgressFunc(a))}:void 0),ranges:r.current(),log:{timeTakenInMilliseconds:Date.now()-i},whatWasDone:v}}return Ge(ut);})(); /** * @name arrayiffy-if-string * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else. * @version 5.0.10 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/arrayiffy-if-string/} */ /** * @name codsen-utils * @fileoverview Various utility functions * @version 1.6.8 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/codsen-utils/} */ /** * @name string-match-left-right * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace * @version 9.0.23 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-match-left-right/} */ /** * @name string-left-right * @fileoverview Looks up the first non-whitespace character to the left/right of a given index * @version 6.0.21 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-left-right/} */ /** * @name string-collapse-leading-whitespace * @fileoverview Collapse the leading and trailing whitespace of a string * @version 7.0.9 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-collapse-leading-whitespace/} */ /** * @name ranges-sort * @fileoverview Sort string index ranges * @version 6.0.14 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-sort/} */ /** * @name ranges-push * @fileoverview Gather string index ranges * @version 7.0.19 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-push/} */ /** * @name ranges-merge * @fileoverview Merge and sort string index ranges * @version 9.0.19 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-merge/} */ /** * @name ranges-apply * @fileoverview Take an array of string index ranges, delete/replace the string according to them * @version 7.0.20 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-apply/} */