/* esm.sh - fractional-indexing@3.2.0 */
var E="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function h(e,r,n){let t=n[0];if(r!=null&&e>=r)throw new Error(e+" >= "+r);if(e.slice(-1)===t||r&&r.slice(-1)===t)throw new Error("trailing zero");if(r){let o=0;for(;(e[o]||t)===r[o];)o++;if(o>0)return r.slice(0,o)+h(e.slice(o),r.slice(o),n)}let c=e?n.indexOf(e[0]):0,l=r!=null?n.indexOf(r[0]):n.length;if(l-c>1){let o=Math.round(.5*(c+l));return n[o]}else return r&&r.length>1?r.slice(0,1):n[c]+h(e.slice(1),null,n)}function C(e){if(e.length!==v(e[0]))throw new Error("invalid integer part of order key: "+e)}function v(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function w(e){let r=v(e[0]);if(r>e.length)throw new Error("invalid order key: "+e);return e.slice(0,r)}function p(e,r){if(e==="A"+r[0].repeat(26))throw new Error("invalid order key: "+e);let n=w(e);if(e.slice(n.length).slice(-1)===r[0])throw new Error("invalid order key: "+e)}function A(e,r){C(e);let[n,...t]=e.split(""),c=!0;for(let l=t.length-1;c&&l>=0;l--){let o=r.indexOf(t[l])+1;o===r.length?t[l]=r[0]:(t[l]=r[o],c=!1)}if(c){if(n==="Z")return"a"+r[0];if(n==="z")return null;let l=String.fromCharCode(n.charCodeAt(0)+1);return l>"a"?t.push(r[0]):t.pop(),l+t.join("")}else return n+t.join("")}function I(e,r){C(e);let[n,...t]=e.split(""),c=!0;for(let l=t.length-1;c&&l>=0;l--){let o=r.indexOf(t[l])-1;o===-1?t[l]=r.slice(-1):(t[l]=r[o],c=!1)}if(c){if(n==="a")return"Z"+r.slice(-1);if(n==="A")return null;let l=String.fromCharCode(n.charCodeAt(0)-1);return l<"Z"?t.push(r.slice(-1)):t.pop(),l+t.join("")}else return n+t.join("")}function i(e,r,n=E){if(e!=null&&p(e,n),r!=null&&p(r,n),e!=null&&r!=null&&e>=r)throw new Error(e+" >= "+r);if(e==null){if(r==null)return"a"+n[0];let f=w(r),a=r.slice(f.length);if(f==="A"+n[0].repeat(26))return f+h("",a,n);if(f<r)return f;let s=I(f,n);if(s==null)throw new Error("cannot decrement any more");return s}if(r==null){let f=w(e),a=e.slice(f.length),s=A(f,n);return s??f+h(a,null,n)}let t=w(e),c=e.slice(t.length),l=w(r),o=r.slice(l.length);if(t===l)return t+h(c,o,n);let u=A(t,n);if(u==null)throw new Error("cannot increment any more");return u<r?u:t+h(c,null,n)}function m(e,r,n,t=E){if(n===0)return[];if(n===1)return[i(e,r,t)];if(r==null){let o=i(e,r,t),u=[o];for(let f=0;f<n-1;f++)o=i(o,r,t),u.push(o);return u}if(e==null){let o=i(e,r,t),u=[o];for(let f=0;f<n-1;f++)o=i(e,o,t),u.push(o);return u.reverse(),u}let c=Math.floor(n/2),l=i(e,r,t);return[...m(e,l,c,t),l,...m(l,r,n-c-1,t)]}export{E as BASE_62_DIGITS,i as generateKeyBetween,m as generateNKeysBetween};
//# sourceMappingURL=fractional-indexing.mjs.map