@kittycad/react-shared 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
2
  import * as g$2 from 'react';
3
- import g__default, { createContext, forwardRef, createElement as createElement$1, useContext, useImperativeHandle, useEffect, Children, useRef, useState, useCallback, useMemo, useLayoutEffect } from 'react';
3
+ import g__default, { createContext, forwardRef, createElement as createElement$1, useContext, useImperativeHandle, useEffect, Children, useRef, useState, useCallback, useMemo, useLayoutEffect, cloneElement } from 'react';
4
4
 
5
5
  function styleInject(css, ref) {
6
6
  if ( ref === void 0 ) ref = {};
@@ -29,7 +29,7 @@ function styleInject(css, ref) {
29
29
  }
30
30
  }
31
31
 
32
- var css_248z = "*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:Inter,ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:Fira Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.relative{position:relative}.left-\\[-1px\\]{left:-1px}.top-\\[2px\\]{top:2px}.z-0{z-index:0}.col-span-1{grid-column:span 1/span 1}.mx-auto{margin-left:auto;margin-right:auto}.my-0{margin-bottom:0;margin-top:0}.\\!mb-0{margin-bottom:0!important}.block{display:block}.flex{display:flex}.inline-flex{display:inline-flex}.h-10{height:2.5rem}.h-11{height:2.75rem}.h-8{height:2rem}.h-\\[40px\\]{height:40px}.min-h-\\[calc\\(100vh-733px\\)\\]{min-height:calc(100vh - 733px)}.w-\\[120px\\]{width:120px}.max-w-2xl{max-width:42rem}.max-w-4xl{max-width:56rem}.flex-1{flex:1 1 0%}.translate-y-\\[0\\]{--tw-translate-y:0;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.cursor-pointer{cursor:pointer}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-baseline{align-items:baseline}.items-stretch{align-items:stretch}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-2{gap:.5rem}.gap-4{gap:1rem}.self-center{align-self:center}.rounded{border-radius:.25rem}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-none{border-style:none}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.\\!bg-transparent{background-color:transparent!important}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.bg-primary-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.bg-primary-700{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.bg-transparent{background-color:transparent}.p-4{padding:1rem}.px-0{padding-left:0;padding-right:0}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.py-2{padding-bottom:.5rem;padding-top:.5rem}.pb-0\\.5{padding-bottom:.125rem}.pb-1{padding-bottom:.25rem}.pb-\\[3px\\]{padding-bottom:3px}.pb-\\[5px\\]{padding-bottom:5px}.font-mono{font-family:Fira Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.uppercase{text-transform:uppercase}.normal-case{text-transform:none}.leading-normal{line-height:1.5}.text-current{color:currentColor}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.outline{outline-style:solid}.transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.before\\:absolute:before{content:var(--tw-content);position:absolute}.before\\:-inset-y-1\\/4:before{bottom:-25%;content:var(--tw-content);top:-25%}.before\\:left-1\\/2:before{content:var(--tw-content);left:50%}.before\\:z-\\[-1\\]:before{content:var(--tw-content);z-index:-1}.before\\:w-\\[1px\\]:before{content:var(--tw-content);width:1px}.before\\:origin-center:before{content:var(--tw-content);transform-origin:center}.before\\:rotate-45:before{--tw-rotate:45deg;content:var(--tw-content);transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.before\\:opacity-30:before{content:var(--tw-content);opacity:.3}.before\\:content-\\[\\'\\'\\]:before{--tw-content:\"\";content:var(--tw-content)}.hover\\:bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.hover\\:bg-gray-300:hover{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.hover\\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.hover\\:bg-primary-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:opacity-80:hover{opacity:.8}.focus-visible\\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:pointer-events-none:disabled{pointer-events:none}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}.group:hover .group-hover\\:\\!text-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}@media (min-width:640px){.sm\\:flex-row{flex-direction:row}}@media (min-width:768px){.md\\:col-span-2{grid-column:span 2/span 2}.md\\:flex{display:flex}.md\\:flex-nowrap{flex-wrap:nowrap}.md\\:gap-12{gap:3rem}.md\\:text-4xl{font-size:2.25rem;line-height:2.5rem}}@media (min-width:1024px){.lg\\:text-5xl{font-size:3rem;line-height:1}.lg\\:text-lg{font-size:1.125rem;line-height:1.75rem}}@media (min-width:1280px){.xl\\:text-6xl{font-size:3.75rem;line-height:1}}";
32
+ var css_248z = "@import \"./colors.css\";*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }\n/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.visible{visibility:visible}.static{position:static}.absolute{position:absolute}.relative{position:relative}.left-\\[-1px\\]{left:-1px}.top-\\[2px\\]{top:2px}.z-0{z-index:0}.col-span-1{grid-column:span 1/span 1}.mx-auto{margin-left:auto;margin-right:auto}.my-0{margin-bottom:0;margin-top:0}.\\!mb-0{margin-bottom:0!important}.block{display:block}.flex{display:flex}.inline-flex{display:inline-flex}.h-1\\.5{height:.375rem}.h-10{height:2.5rem}.h-11{height:2.75rem}.h-4{height:1rem}.h-5{height:1.25rem}.h-8{height:2rem}.h-\\[40px\\]{height:40px}.min-h-\\[calc\\(100vh-733px\\)\\]{min-height:calc(100vh - 733px)}.w-4{width:1rem}.w-5{width:1.25rem}.w-8{width:2rem}.w-9{width:2.25rem}.w-\\[120px\\]{width:120px}.w-full{width:100%}.max-w-2xl{max-width:42rem}.max-w-4xl{max-width:56rem}.flex-1{flex:1 1 0%}.flex-grow{flex-grow:1}.origin-center{transform-origin:center}.translate-y-\\[0\\]{--tw-translate-y:0;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-baseline{align-items:baseline}.items-stretch{align-items:stretch}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-2{gap:.5rem}.gap-4{gap:1rem}.self-center{align-self:center}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-none{border-style:none}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity,1))}.border-ml-black{border-color:var(--chalkboard-100)}.\\!bg-transparent{background-color:transparent!important}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity,1))}.bg-gray-300{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.bg-gray-50{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.bg-ml-black{background-color:var(--chalkboard-100)}.bg-ml-green{--tw-bg-opacity:1;background-color:rgb(41 255 164/var(--tw-bg-opacity,1))}.bg-primary{--tw-bg-opacity:1;background-color:oklch(var(--_primary)/var(--tw-bg-opacity,1))}.bg-transparent{background-color:transparent}.p-1{padding:.25rem}.p-4{padding:1rem}.px-0{padding-left:0;padding-right:0}.px-2{padding-left:.5rem;padding-right:.5rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.py-1{padding-bottom:.25rem;padding-top:.25rem}.py-2{padding-bottom:.5rem;padding-top:.5rem}.pb-0\\.5{padding-bottom:.125rem}.pb-1{padding-bottom:.25rem}.pb-\\[3px\\]{padding-bottom:3px}.pb-\\[5px\\]{padding-bottom:5px}.text-center{text-align:center}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.uppercase{text-transform:uppercase}.normal-case{text-transform:none}.leading-normal{line-height:1.5}.\\!text-chalkboard-100{--tw-text-opacity:1!important;color:oklch(var(--_chalkboard-100)/var(--tw-text-opacity,1))!important}.\\!text-ml-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}.text-current{color:currentColor}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity,1))}.text-inherit{color:inherit}.text-ml-black{color:var(--chalkboard-100)}.text-ml-grey{color:var(--chalkboard-80)}.text-ml-white,.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.\\!no-underline{text-decoration-line:none!important}.outline{outline-style:solid}.transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.before\\:absolute:before{content:var(--tw-content);position:absolute}.before\\:-inset-y-1\\/4:before{bottom:-25%;content:var(--tw-content);top:-25%}.before\\:left-1\\/2:before{content:var(--tw-content);left:50%}.before\\:z-\\[-1\\]:before{content:var(--tw-content);z-index:-1}.before\\:w-\\[1px\\]:before{content:var(--tw-content);width:1px}.before\\:origin-center:before{content:var(--tw-content);transform-origin:center}.before\\:rotate-45:before{--tw-rotate:45deg;content:var(--tw-content);transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.before\\:opacity-30:before{content:var(--tw-content);opacity:.3}.before\\:content-\\[\\'\\'\\]:before{--tw-content:\"\";content:var(--tw-content)}.hover\\:bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.hover\\:bg-gray-300:hover{--tw-bg-opacity:1;background-color:rgb(209 213 219/var(--tw-bg-opacity,1))}.hover\\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.hover\\:opacity-80:hover{opacity:.8}.focus-visible\\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:pointer-events-none:disabled{pointer-events:none}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}.group:hover .group-hover\\:\\!text-white{--tw-text-opacity:1!important;color:rgb(255 255 255/var(--tw-text-opacity,1))!important}.dark\\:bg-transparent:is(.dark *){background-color:transparent}.dark\\:\\!text-ml-green:is(.dark *){--tw-text-opacity:1!important;color:rgb(41 255 164/var(--tw-text-opacity,1))!important}@media (min-width:640px){.sm\\:flex-row{flex-direction:row}}@media (min-width:768px){.md\\:col-span-2{grid-column:span 2/span 2}.md\\:flex{display:flex}.md\\:flex-nowrap{flex-wrap:nowrap}.md\\:gap-12{gap:3rem}.md\\:text-4xl{font-size:2.25rem;line-height:2.5rem}}@media (min-width:1024px){.lg\\:text-5xl{font-size:3rem;line-height:1}.lg\\:text-lg{font-size:1.125rem;line-height:1.75rem}}@media (min-width:1280px){.xl\\:text-6xl{font-size:3.75rem;line-height:1}}";
33
33
  styleInject(css_248z,{"insertAt":"top"});
34
34
 
35
35
  function r$2(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r$2(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r$2(e))&&(n&&(n+=" "),n+=t);return n}
@@ -2707,11 +2707,11 @@ var S = {
2707
2707
  SECONDARY: "secondary"
2708
2708
  },
2709
2709
  P$1 = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone"];
2710
- var s$1 = "classic",
2710
+ var s$2 = "classic",
2711
2711
  t$1 = "duotone",
2712
- r = "sharp",
2713
- o$1 = "sharp-duotone",
2714
- L = [s$1, t$1, r, o$1];
2712
+ r$1 = "sharp",
2713
+ o$2 = "sharp-duotone",
2714
+ L = [s$2, t$1, r$1, o$2];
2715
2715
  var G = {
2716
2716
  classic: {
2717
2717
  900: "fas",
@@ -2865,7 +2865,7 @@ var t$1$1 = {
2865
2865
  PRIMARY: "primary",
2866
2866
  SECONDARY: "secondary"
2867
2867
  },
2868
- r$1 = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone"];
2868
+ r$1$1 = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone"];
2869
2869
  var bt$1 = ["fak", "fa-kit", "fakd", "fa-kit-duotone"];
2870
2870
  var Yt = {
2871
2871
  "Font Awesome Kit": {
@@ -2938,7 +2938,7 @@ var ua = {
2938
2938
  }
2939
2939
  },
2940
2940
  x$1 = ["fa-solid", "fa-regular", "fa-light", "fa-thin", "fa-duotone", "fa-brands"],
2941
- Ia = ["fa", "fas", "far", "fal", "fat", "fad", "fadr", "fadl", "fadt", "fab", "fass", "fasr", "fasl", "fast", "fasds", "fasdr", "fasdl", "fasdt", ...r$1, ...x$1],
2941
+ Ia = ["fa", "fas", "far", "fal", "fat", "fad", "fadr", "fadl", "fadt", "fab", "fass", "fasr", "fasl", "fast", "fasds", "fasdr", "fasdl", "fasdt", ...r$1$1, ...x$1],
2942
2942
  m$1 = ["solid", "regular", "light", "thin", "duotone", "brands"],
2943
2943
  c$1$1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
2944
2944
  F$1 = c$1$1.concat([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]),
@@ -2986,7 +2986,7 @@ function familyProxy(obj) {
2986
2986
  // Defaults to the classic family if family is not available
2987
2987
  return new Proxy(obj, {
2988
2988
  get(target, prop) {
2989
- return prop in target ? target[prop] : target[s$1];
2989
+ return prop in target ? target[prop] : target[s$2];
2990
2990
  }
2991
2991
  });
2992
2992
  }
@@ -2995,23 +2995,23 @@ const _PREFIX_TO_STYLE = _objectSpread2$1({}, S);
2995
2995
  // We changed FACSSClassesToStyleId in the icons repo to be canonical and as such, "classic" family does not have any
2996
2996
  // duotone styles. But we do still need duotone in _PREFIX_TO_STYLE below, so we are manually adding
2997
2997
  // {'fa-duotone': 'duotone'}
2998
- _PREFIX_TO_STYLE[s$1] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
2998
+ _PREFIX_TO_STYLE[s$2] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
2999
2999
  'fa-duotone': 'duotone'
3000
- }), S[s$1]), St['kit']), St['kit-duotone']);
3000
+ }), S[s$2]), St['kit']), St['kit-duotone']);
3001
3001
  const PREFIX_TO_STYLE = familyProxy(_PREFIX_TO_STYLE);
3002
3002
  const _STYLE_TO_PREFIX = _objectSpread2$1({}, xt);
3003
3003
 
3004
3004
  // We changed FAStyleIdToShortPrefixId in the icons repo to be canonical and as such, "classic" family does not have any
3005
3005
  // duotone styles. But we do still need duotone in _STYLE_TO_PREFIX below, so we are manually adding {duotone: 'fad'}
3006
- _STYLE_TO_PREFIX[s$1] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
3006
+ _STYLE_TO_PREFIX[s$2] = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, {
3007
3007
  duotone: 'fad'
3008
- }), _STYLE_TO_PREFIX[s$1]), Et['kit']), Et['kit-duotone']);
3008
+ }), _STYLE_TO_PREFIX[s$2]), Et['kit']), Et['kit-duotone']);
3009
3009
  const STYLE_TO_PREFIX = familyProxy(_STYLE_TO_PREFIX);
3010
3010
  const _PREFIX_TO_LONG_STYLE = _objectSpread2$1({}, ga);
3011
- _PREFIX_TO_LONG_STYLE[s$1] = _objectSpread2$1(_objectSpread2$1({}, _PREFIX_TO_LONG_STYLE[s$1]), Wt['kit']);
3011
+ _PREFIX_TO_LONG_STYLE[s$2] = _objectSpread2$1(_objectSpread2$1({}, _PREFIX_TO_LONG_STYLE[s$2]), Wt['kit']);
3012
3012
  const PREFIX_TO_LONG_STYLE = familyProxy(_PREFIX_TO_LONG_STYLE);
3013
3013
  const _LONG_STYLE_TO_PREFIX = _objectSpread2$1({}, ua);
3014
- _LONG_STYLE_TO_PREFIX[s$1] = _objectSpread2$1(_objectSpread2$1({}, _LONG_STYLE_TO_PREFIX[s$1]), Ct['kit']);
3014
+ _LONG_STYLE_TO_PREFIX[s$2] = _objectSpread2$1(_objectSpread2$1({}, _LONG_STYLE_TO_PREFIX[s$2]), Ct['kit']);
3015
3015
  familyProxy(_LONG_STYLE_TO_PREFIX);
3016
3016
  const ICON_SELECTION_SYNTAX_PATTERN = p$1; // eslint-disable-line no-useless-escape
3017
3017
 
@@ -3050,7 +3050,7 @@ if (DOCUMENT && typeof DOCUMENT.querySelector === 'function') {
3050
3050
  }
3051
3051
  const _default = {
3052
3052
  styleDefault: 'solid',
3053
- familyDefault: s$1,
3053
+ familyDefault: s$2,
3054
3054
  cssPrefix: DEFAULT_CSS_PREFIX,
3055
3055
  replacementClass: DEFAULT_REPLACEMENT_CLASS,
3056
3056
  autoReplaceSvg: true,
@@ -3581,7 +3581,7 @@ const emptyCanonicalIcon = () => {
3581
3581
  };
3582
3582
  };
3583
3583
  function getFamilyId(values) {
3584
- let family = s$1;
3584
+ let family = s$2;
3585
3585
  const famProps = FAMILY_NAMES.reduce((acc, familyId) => {
3586
3586
  acc[familyId] = "".concat(config.cssPrefix, "-").concat(familyId);
3587
3587
  return acc;
@@ -3596,7 +3596,7 @@ function getFamilyId(values) {
3596
3596
  function getCanonicalPrefix(styleOrPrefix) {
3597
3597
  let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3598
3598
  const {
3599
- family = s$1
3599
+ family = s$2
3600
3600
  } = params;
3601
3601
  const style = PREFIX_TO_STYLE[family][styleOrPrefix];
3602
3602
 
@@ -3685,9 +3685,9 @@ function applyShimAndAlias(skipLookups, givenPrefix, canonical) {
3685
3685
  };
3686
3686
  }
3687
3687
  const newCanonicalFamilies = L.filter(familyId => {
3688
- return familyId !== s$1 || familyId !== t$1;
3688
+ return familyId !== s$2 || familyId !== t$1;
3689
3689
  });
3690
- const newCanonicalStyles = Object.keys(ga).filter(key => key !== s$1).map(key => Object.keys(ga[key])).flat();
3690
+ const newCanonicalStyles = Object.keys(ga).filter(key => key !== s$2).map(key => Object.keys(ga[key])).flat();
3691
3691
  function getDefaultCanonicalPrefix(prefixOptions) {
3692
3692
  const {
3693
3693
  values,
@@ -3737,7 +3737,7 @@ class Library {
3737
3737
  defineIcons(key, additions[key]);
3738
3738
 
3739
3739
  // TODO can we stop doing this? We can't get the icons by 'fa-solid' any longer so this probably needs to change
3740
- const longPrefix = PREFIX_TO_LONG_STYLE[s$1][key];
3740
+ const longPrefix = PREFIX_TO_LONG_STYLE[s$2][key];
3741
3741
  if (longPrefix) defineIcons(longPrefix, additions[key]);
3742
3742
  build();
3743
3743
  });
@@ -3887,7 +3887,7 @@ const dom = {
3887
3887
  });
3888
3888
  }
3889
3889
  };
3890
- const parse = {
3890
+ const parse$1 = {
3891
3891
  icon: icon => {
3892
3892
  if (icon === null) {
3893
3893
  return null;
@@ -3928,7 +3928,7 @@ const api = {
3928
3928
  noAuto,
3929
3929
  config,
3930
3930
  dom,
3931
- parse,
3931
+ parse: parse$1,
3932
3932
  library,
3933
3933
  findIconDefinition,
3934
3934
  toHtml
@@ -5489,7 +5489,7 @@ api.noAuto;
5489
5489
  api.config;
5490
5490
  api.library;
5491
5491
  api.dom;
5492
- const parse$1 = api.parse;
5492
+ const parse$1$1 = api.parse;
5493
5493
  api.findIconDefinition;
5494
5494
  api.toHtml;
5495
5495
  const icon = api.icon;
@@ -7006,8 +7006,8 @@ function normalizeIconArgs(icon) {
7006
7006
  return icon;
7007
7007
  }
7008
7008
 
7009
- if (parse$1.icon) {
7010
- return parse$1.icon(icon);
7009
+ if (parse$1$1.icon) {
7010
+ return parse$1$1.icon(icon);
7011
7011
  } // if the icon is null, there's nothing to do
7012
7012
 
7013
7013
 
@@ -7049,7 +7049,7 @@ function objectWithKey(key, value) {
7049
7049
  return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty$1({}, key, value) : {};
7050
7050
  }
7051
7051
 
7052
- var defaultProps = {
7052
+ var defaultProps$1 = {
7053
7053
  border: false,
7054
7054
  className: '',
7055
7055
  mask: null,
@@ -7078,7 +7078,7 @@ var defaultProps = {
7078
7078
  swapOpacity: false
7079
7079
  };
7080
7080
  var FontAwesomeIcon = /*#__PURE__*/g__default.forwardRef(function (props, ref) {
7081
- var allProps = _objectSpread2(_objectSpread2({}, defaultProps), props);
7081
+ var allProps = _objectSpread2(_objectSpread2({}, defaultProps$1), props);
7082
7082
 
7083
7083
  var iconArgs = allProps.icon,
7084
7084
  maskArgs = allProps.mask,
@@ -7089,7 +7089,7 @@ var FontAwesomeIcon = /*#__PURE__*/g__default.forwardRef(function (props, ref) {
7089
7089
  maskId = allProps.maskId;
7090
7090
  var iconLookup = normalizeIconArgs(iconArgs);
7091
7091
  var classes = objectWithKey('classes', [].concat(_toConsumableArray(classList(allProps)), _toConsumableArray((className || '').split(' '))));
7092
- var transform = objectWithKey('transform', typeof allProps.transform === 'string' ? parse$1.transform(allProps.transform) : allProps.transform);
7092
+ var transform = objectWithKey('transform', typeof allProps.transform === 'string' ? parse$1$1.transform(allProps.transform) : allProps.transform);
7093
7093
  var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
7094
7094
  var renderedIcon = icon(iconLookup, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, classes), transform), mask), {}, {
7095
7095
  symbol: symbol,
@@ -7109,7 +7109,7 @@ var FontAwesomeIcon = /*#__PURE__*/g__default.forwardRef(function (props, ref) {
7109
7109
  };
7110
7110
  Object.keys(allProps).forEach(function (key) {
7111
7111
  // eslint-disable-next-line no-prototype-builtins
7112
- if (!defaultProps.hasOwnProperty(key)) {
7112
+ if (!defaultProps$1.hasOwnProperty(key)) {
7113
7113
  extraProps[key] = allProps[key];
7114
7114
  }
7115
7115
  });
@@ -8381,10 +8381,10 @@ var freeModule$2 = freeExports$2 && typeof module == 'object' && module && !modu
8381
8381
  var moduleExports$2 = freeModule$2 && freeModule$2.exports === freeExports$2;
8382
8382
 
8383
8383
  /** Built-in value references. */
8384
- var Buffer$1 = moduleExports$2 ? root.Buffer : undefined;
8384
+ var Buffer$2 = moduleExports$2 ? root.Buffer : undefined;
8385
8385
 
8386
8386
  /* Built-in method references for those with the same name as other `lodash` methods. */
8387
- var nativeIsBuffer = Buffer$1 ? Buffer$1.isBuffer : undefined;
8387
+ var nativeIsBuffer = Buffer$2 ? Buffer$2.isBuffer : undefined;
8388
8388
 
8389
8389
  /**
8390
8390
  * Checks if `value` is a buffer.
@@ -8838,8 +8838,8 @@ var freeModule = freeExports && typeof module == 'object' && module && !module.n
8838
8838
  var moduleExports = freeModule && freeModule.exports === freeExports;
8839
8839
 
8840
8840
  /** Built-in value references. */
8841
- var Buffer = moduleExports ? root.Buffer : undefined,
8842
- allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
8841
+ var Buffer$1 = moduleExports ? root.Buffer : undefined,
8842
+ allocUnsafe = Buffer$1 ? Buffer$1.allocUnsafe : undefined;
8843
8843
 
8844
8844
  /**
8845
8845
  * Creates a clone of `buffer`.
@@ -9141,7 +9141,7 @@ function initCloneArray(array) {
9141
9141
  }
9142
9142
 
9143
9143
  /** Built-in value references. */
9144
- var Uint8Array = root.Uint8Array;
9144
+ var Uint8Array$1 = root.Uint8Array;
9145
9145
 
9146
9146
  /**
9147
9147
  * Creates a clone of `arrayBuffer`.
@@ -9152,7 +9152,7 @@ var Uint8Array = root.Uint8Array;
9152
9152
  */
9153
9153
  function cloneArrayBuffer(arrayBuffer) {
9154
9154
  var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
9155
- new Uint8Array(result).set(new Uint8Array(arrayBuffer));
9155
+ new Uint8Array$1(result).set(new Uint8Array$1(arrayBuffer));
9156
9156
  return result;
9157
9157
  }
9158
9158
 
@@ -9357,7 +9357,7 @@ var nodeIsMap = nodeUtil && nodeUtil.isMap;
9357
9357
  * _.isMap(new WeakMap);
9358
9358
  * // => false
9359
9359
  */
9360
- var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
9360
+ var isMap$1 = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
9361
9361
 
9362
9362
  /** `Object#toString` result references. */
9363
9363
  var setTag$1 = '[object Set]';
@@ -9511,7 +9511,7 @@ function baseClone(value, bitmask, customizer, key, object, stack) {
9511
9511
  value.forEach(function(subValue) {
9512
9512
  result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
9513
9513
  });
9514
- } else if (isMap(value)) {
9514
+ } else if (isMap$1(value)) {
9515
9515
  value.forEach(function(subValue, key) {
9516
9516
  result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
9517
9517
  });
@@ -11654,9 +11654,9 @@ var Form = /*#__PURE__*/forwardRef(function (props, ref) {
11654
11654
  });
11655
11655
  Form.displayName = 'Form';
11656
11656
 
11657
- let e={data:""},t=t=>"object"==typeof window?((t?t.querySelector("#_goober"):window._goober)||Object.assign((t||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:t||e,l=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,a=/\/\*[^]*?\*\/| +/g,n=/\n+/g,o=(e,t)=>{let r="",l="",a="";for(let n in e){let c=e[n];"@"==n[0]?"i"==n[1]?r=n+" "+c+";":l+="f"==n[1]?o(c,n):n+"{"+o(c,"k"==n[1]?"":t)+"}":"object"==typeof c?l+=o(c,t?t.replace(/([^,])+/g,e=>n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+" "+t:t)):n):null!=c&&(n=/^--/.test(n)?n:n.replace(/[A-Z]/g,"-$&").toLowerCase(),a+=o.p?o.p(n,c):n+":"+c+";");}return r+(t&&a?t+"{"+a+"}":a)+l},c$1={},s=e=>{if("object"==typeof e){let t="";for(let r in e)t+=r+s(e[r]);return t}return e},i=(e,t,r,i,p)=>{let u=s(e),d=c$1[u]||(c$1[u]=(e=>{let t=0,r=11;for(;t<e.length;)r=101*r+e.charCodeAt(t++)>>>0;return "go"+r})(u));if(!c$1[d]){let t=u!==e?e:(e=>{let t,r,o=[{}];for(;t=l.exec(e.replace(a,""));)t[4]?o.shift():t[3]?(r=t[3].replace(n," ").trim(),o.unshift(o[0][r]=o[0][r]||{})):o[0][t[1]]=t[2].replace(n," ").trim();return o[0]})(e);c$1[d]=o(p?{["@keyframes "+d]:t}:t,r?"":"."+d);}let f=r&&c$1.g?c$1.g:null;return r&&(c$1.g=c$1[d]),((e,t,r,l)=>{l?t.data=t.data.replace(l,e):-1===t.data.indexOf(e)&&(t.data=r?e+t.data:t.data+e);})(c$1[d],t,i,f),d},p=(e,t,r)=>e.reduce((e,l,a)=>{let n=t[a];if(n&&n.call){let e=n(r),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;n=t?"."+t:e&&"object"==typeof e?e.props?"":o(e,""):false===e?"":e;}return e+l+(null==n?"":n)},"");function u$1(e){let r=this||{},l=e.call?e(r.p):e;return i(l.unshift?l.raw?p(l,[].slice.call(arguments,1),r.p):l.reduce((e,t)=>Object.assign(e,t&&t.call?t(r.p):t),{}):l,t(r.target),r.g,r.o,r.k)}let d,f$1,g;u$1.bind({g:1});let h=u$1.bind({k:1});function m(e,t,r,l){o.p=t,d=e,f$1=r,g=l;}function j(e,t){let r=this||{};return function(){let l=arguments;function a(n,o){let c=Object.assign({},n),s=c.className||a.className;r.p=Object.assign({theme:f$1&&f$1()},c),r.o=/ *go\d+/.test(s),c.className=u$1.apply(r,l)+(s?" "+s:"");let i=e;return e[0]&&(i=c.as||e,delete c.as),g&&i[0]&&g(c),d(i,c)}return a}}
11657
+ let e={data:""},t=t=>"object"==typeof window?((t?t.querySelector("#_goober"):window._goober)||Object.assign((t||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:t||e,l$1=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,a$1=/\/\*[^]*?\*\/| +/g,n=/\n+/g,o$1=(e,t)=>{let r="",l="",a="";for(let n in e){let c=e[n];"@"==n[0]?"i"==n[1]?r=n+" "+c+";":l+="f"==n[1]?o$1(c,n):n+"{"+o$1(c,"k"==n[1]?"":t)+"}":"object"==typeof c?l+=o$1(c,t?t.replace(/([^,])+/g,e=>n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+" "+t:t)):n):null!=c&&(n=/^--/.test(n)?n:n.replace(/[A-Z]/g,"-$&").toLowerCase(),a+=o$1.p?o$1.p(n,c):n+":"+c+";");}return r+(t&&a?t+"{"+a+"}":a)+l},c$2={},s$1=e=>{if("object"==typeof e){let t="";for(let r in e)t+=r+s$1(e[r]);return t}return e},i=(e,t,r,i,p)=>{let u=s$1(e),d=c$2[u]||(c$2[u]=(e=>{let t=0,r=11;for(;t<e.length;)r=101*r+e.charCodeAt(t++)>>>0;return "go"+r})(u));if(!c$2[d]){let t=u!==e?e:(e=>{let t,r,o=[{}];for(;t=l$1.exec(e.replace(a$1,""));)t[4]?o.shift():t[3]?(r=t[3].replace(n," ").trim(),o.unshift(o[0][r]=o[0][r]||{})):o[0][t[1]]=t[2].replace(n," ").trim();return o[0]})(e);c$2[d]=o$1(p?{["@keyframes "+d]:t}:t,r?"":"."+d);}let f=r&&c$2.g?c$2.g:null;return r&&(c$2.g=c$2[d]),((e,t,r,l)=>{l?t.data=t.data.replace(l,e):-1===t.data.indexOf(e)&&(t.data=r?e+t.data:t.data+e);})(c$2[d],t,i,f),d},p=(e,t,r)=>e.reduce((e,l,a)=>{let n=t[a];if(n&&n.call){let e=n(r),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;n=t?"."+t:e&&"object"==typeof e?e.props?"":o$1(e,""):false===e?"":e;}return e+l+(null==n?"":n)},"");function u$1(e){let r=this||{},l=e.call?e(r.p):e;return i(l.unshift?l.raw?p(l,[].slice.call(arguments,1),r.p):l.reduce((e,t)=>Object.assign(e,t&&t.call?t(r.p):t),{}):l,t(r.target),r.g,r.o,r.k)}let d,f$1,g;u$1.bind({g:1});let h=u$1.bind({k:1});function m(e,t,r,l){o$1.p=t,d=e,f$1=r,g=l;}function j(e,t){let r=this||{};return function(){let l=arguments;function a(n,o){let c=Object.assign({},n),s=c.className||a.className;r.p=Object.assign({theme:f$1&&f$1()},c),r.o=/ *go\d+/.test(s),c.className=u$1.apply(r,l)+(s?" "+s:"");let i=e;return e[0]&&(i=c.as||e,delete c.as),g&&i[0]&&g(c),d(i,c)}return a}}
11658
11658
 
11659
- var W=e=>typeof e=="function",f=(e,t)=>W(e)?e(t):e;var F=(()=>{let e=0;return ()=>(++e).toString()})(),A=(()=>{let e;return ()=>{if(e===void 0&&typeof window<"u"){let t=matchMedia("(prefers-reduced-motion: reduce)");e=!t||t.matches;}return e}})();var Y=20;var U=(e,t)=>{switch(t.type){case 0:return {...e,toasts:[t.toast,...e.toasts].slice(0,Y)};case 1:return {...e,toasts:e.toasts.map(o=>o.id===t.toast.id?{...o,...t.toast}:o)};case 2:let{toast:r}=t;return U(e,{type:e.toasts.find(o=>o.id===r.id)?1:0,toast:r});case 3:let{toastId:s}=t;return {...e,toasts:e.toasts.map(o=>o.id===s||s===void 0?{...o,dismissed:true,visible:false}:o)};case 4:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(o=>o.id!==t.toastId)};case 5:return {...e,pausedAt:t.time};case 6:let a=t.time-(e.pausedAt||0);return {...e,pausedAt:void 0,toasts:e.toasts.map(o=>({...o,pauseDuration:o.pauseDuration+a}))}}},P=[],y={toasts:[],pausedAt:void 0},u=e=>{y=U(y,e),P.forEach(t=>{t(y);});};var J=(e,t="blank",r)=>({createdAt:Date.now(),visible:true,dismissed:false,type:t,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...r,id:(r==null?void 0:r.id)||F()}),x=e=>(t,r)=>{let s=J(t,e,r);return u({type:2,toast:s}),s.id},c=(e,t)=>x("blank")(e,t);c.error=x("error");c.success=x("success");c.loading=x("loading");c.custom=x("custom");c.dismiss=e=>{u({type:3,toastId:e});};c.remove=e=>u({type:4,toastId:e});c.promise=(e,t,r)=>{let s=c.loading(t.loading,{...r,...r==null?void 0:r.loading});return typeof e=="function"&&(e=e()),e.then(a=>{let o=t.success?f(t.success,a):void 0;return o?c.success(o,{id:s,...r,...r==null?void 0:r.success}):c.dismiss(s),a}).catch(a=>{let o=t.error?f(t.error,a):void 0;o?c.error(o,{id:s,...r,...r==null?void 0:r.error}):c.dismiss(s);}),e};var oe=h`
11659
+ var W=e=>typeof e=="function",f=(e,t)=>W(e)?e(t):e;var F=(()=>{let e=0;return ()=>(++e).toString()})(),A=(()=>{let e;return ()=>{if(e===void 0&&typeof window<"u"){let t=matchMedia("(prefers-reduced-motion: reduce)");e=!t||t.matches;}return e}})();var Y=20;var U=(e,t)=>{switch(t.type){case 0:return {...e,toasts:[t.toast,...e.toasts].slice(0,Y)};case 1:return {...e,toasts:e.toasts.map(o=>o.id===t.toast.id?{...o,...t.toast}:o)};case 2:let{toast:r}=t;return U(e,{type:e.toasts.find(o=>o.id===r.id)?1:0,toast:r});case 3:let{toastId:s}=t;return {...e,toasts:e.toasts.map(o=>o.id===s||s===void 0?{...o,dismissed:true,visible:false}:o)};case 4:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(o=>o.id!==t.toastId)};case 5:return {...e,pausedAt:t.time};case 6:let a=t.time-(e.pausedAt||0);return {...e,pausedAt:void 0,toasts:e.toasts.map(o=>({...o,pauseDuration:o.pauseDuration+a}))}}},P=[],y$1={toasts:[],pausedAt:void 0},u=e=>{y$1=U(y$1,e),P.forEach(t=>{t(y$1);});};var J=(e,t="blank",r)=>({createdAt:Date.now(),visible:true,dismissed:false,type:t,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...r,id:(r==null?void 0:r.id)||F()}),x=e=>(t,r)=>{let s=J(t,e,r);return u({type:2,toast:s}),s.id},c$1=(e,t)=>x("blank")(e,t);c$1.error=x("error");c$1.success=x("success");c$1.loading=x("loading");c$1.custom=x("custom");c$1.dismiss=e=>{u({type:3,toastId:e});};c$1.remove=e=>u({type:4,toastId:e});c$1.promise=(e,t,r)=>{let s=c$1.loading(t.loading,{...r,...r==null?void 0:r.loading});return typeof e=="function"&&(e=e()),e.then(a=>{let o=t.success?f(t.success,a):void 0;return o?c$1.success(o,{id:s,...r,...r==null?void 0:r.success}):c$1.dismiss(s),a}).catch(a=>{let o=t.error?f(t.error,a):void 0;o?c$1.error(o,{id:s,...r,...r==null?void 0:r.error}):c$1.dismiss(s);}),e};var oe=h`
11660
11660
  from {
11661
11661
  transform: scale(0) rotate(45deg);
11662
11662
  opacity: 0;
@@ -11680,7 +11680,7 @@ from {
11680
11680
  to {
11681
11681
  transform: scale(1) rotate(90deg);
11682
11682
  opacity: 1;
11683
- }`,k=j("div")`
11683
+ }`,k$1=j("div")`
11684
11684
  width: 20px;
11685
11685
  opacity: 0;
11686
11686
  height: 20px;
@@ -11802,7 +11802,7 @@ to {
11802
11802
  min-width: 20px;
11803
11803
  animation: ${fe} 0.3s 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275)
11804
11804
  forwards;
11805
- `,M=({toast:e})=>{let{icon:t,type:r,iconTheme:s}=e;return t!==void 0?typeof t=="string"?g$2.createElement(Te,null,t):t:r==="blank"?null:g$2.createElement(le,null,g$2.createElement(V,{...s}),r!=="loading"&&g$2.createElement(ue,null,r==="error"?g$2.createElement(k,{...s}):g$2.createElement(_,{...s})))};var ye=e=>`
11805
+ `,M=({toast:e})=>{let{icon:t,type:r,iconTheme:s}=e;return t!==void 0?typeof t=="string"?g$2.createElement(Te,null,t):t:r==="blank"?null:g$2.createElement(le,null,g$2.createElement(V,{...s}),r!=="loading"&&g$2.createElement(ue,null,r==="error"?g$2.createElement(k$1,{...s}):g$2.createElement(_,{...s})))};var ye=e=>`
11806
11806
  0% {transform: translate3d(0,${e*-200}%,0) scale(.6); opacity:.5;}
11807
11807
  100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
11808
11808
  `,ge=e=>`
@@ -13529,13 +13529,13 @@ create$6$1.prototype = StringSchema$1.prototype;
13529
13529
  //
13530
13530
 
13531
13531
  let invalidDate$1 = new Date('');
13532
- let isDate$1 = obj => Object.prototype.toString.call(obj) === '[object Date]';
13532
+ let isDate$2 = obj => Object.prototype.toString.call(obj) === '[object Date]';
13533
13533
  let DateSchema$1 = class DateSchema extends Schema {
13534
13534
  constructor() {
13535
13535
  super({
13536
13536
  type: 'date',
13537
13537
  check(v) {
13538
- return isDate$1(v) && !isNaN(v.getTime());
13538
+ return isDate$2(v) && !isNaN(v.getTime());
13539
13539
  }
13540
13540
  });
13541
13541
  this.withMutation(() => {
@@ -19916,7 +19916,7 @@ function parseIsoDate(date) {
19916
19916
  // @ts-ignore
19917
19917
  let invalidDate = new Date('');
19918
19918
 
19919
- let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
19919
+ let isDate$1 = obj => Object.prototype.toString.call(obj) === '[object Date]';
19920
19920
 
19921
19921
  function create$3() {
19922
19922
  return new DateSchema();
@@ -19937,7 +19937,7 @@ class DateSchema extends BaseSchema {
19937
19937
  }
19938
19938
 
19939
19939
  _typeCheck(v) {
19940
- return isDate(v) && !isNaN(v.getTime());
19940
+ return isDate$1(v) && !isNaN(v.getTime());
19941
19941
  }
19942
19942
 
19943
19943
  prepareParam(ref, name) {
@@ -21722,13 +21722,13 @@ function EmailLoginForm({ theme = 'default', buttonClassName = '', className, id
21722
21722
  // Make sure the status code is in the 200 range.
21723
21723
  if (response.status >= 200 && response.status < 300) {
21724
21724
  // Create a success toast.
21725
- c.success('Email sent! Check your inbox.', {
21725
+ c$1.success('Email sent! Check your inbox.', {
21726
21726
  duration: 4000,
21727
21727
  className: 'email-toast-success',
21728
21728
  });
21729
21729
  }
21730
21730
  else {
21731
- c.error('Something went wrong in sending your email.', {
21731
+ c$1.error('Something went wrong in sending your email.', {
21732
21732
  duration: 4000,
21733
21733
  className: 'email-toast-error',
21734
21734
  });
@@ -21736,7 +21736,7 @@ function EmailLoginForm({ theme = 'default', buttonClassName = '', className, id
21736
21736
  }
21737
21737
  }
21738
21738
  catch (error) {
21739
- c.error('Something went wrong in sending your email.', {
21739
+ c$1.error('Something went wrong in sending your email.', {
21740
21740
  duration: 4000,
21741
21741
  className: 'email-toast-error',
21742
21742
  });
@@ -21828,5 +21828,3509 @@ function SignInPageContent({ shouldTrackConversions = false, trackingClasses = (
21828
21828
  return (jsxs("div", { className: `md:flex items-center gap-item-spacing md:gap-12 max-w-4xl mx-auto px-page-margin py-section-spacing min-h-[calc(100vh-733px)] ${className}`, children: [jsxs("div", { className: "flex-1", children: [jsx(LoginTitle, { color: titleColor }), jsx("p", { className: "text-xl my-item-spacing", children: "No password setup necessary. When you sign into Zoo for the first time we create your account automatically. You can use your preferred auth provider or receive a link via email." })] }), callbackUrl && callbackUrl.length > 0 && (jsxs("div", { className: "font-xs flex flex-col items-stretch max-w-2xl gap-item-spacing-sm flex-wrap md:flex-nowrap", children: [jsx("button", { type: "button", onClick: handleClick('github'), className: finalButtonClasses('github'), children: jsxs("span", { className: "group-hover:!text-white flex gap-2 items-center justify-center mono-button-title", children: [jsx(FontAwesomeIcon, { icon: faGithub, className: "pb-0.5" }), "GitHub"] }) }), jsx("button", { type: "button", onClick: handleClick('google'), className: finalButtonClasses('google'), children: jsxs("span", { className: "group-hover:!text-white flex gap-2 items-center justify-center mono-button-title", children: [jsx(FontAwesomeIcon, { icon: faGoogle, className: "pb-1" }), "Google"] }) }), jsx("button", { type: "button", onClick: handleClick('apple'), className: finalButtonClasses('apple'), children: jsxs("span", { className: "group-hover:!text-white flex gap-2 items-center justify-center mono-button-title", children: [jsx(FontAwesomeIcon, { icon: faApple, className: "pb-[5px]" }), "Apple"] }) }), jsx("button", { type: "button", onClick: handleClick('microsoft'), className: finalButtonClasses('microsoft'), children: jsxs("span", { className: "group-hover:!text-white flex gap-2 items-center justify-center mono-button-title", children: [jsx(FontAwesomeIcon, { icon: faMicrosoft, className: "pb-1" }), "Microsoft"] }) }), jsx("button", { type: "button", onClick: handleClick('discord'), className: finalButtonClasses('discord'), children: jsxs("span", { className: "group-hover:!text-white flex gap-2 items-center justify-center mono-button-title", children: [jsx(FontAwesomeIcon, { icon: faDiscord, className: "pb-[3px]" }), "Discord"] }) }), jsx(EmailLoginForm, { theme: "hue-shift-on-white", className: "col-span-1 md:col-span-2 mt-item-spacing-sm !mb-0", buttonClassName: finalTrackingClasses('email'), onSubmit: onEmailSubmit, callbackUrl: callbackUrl, baseUrl: baseUrl, getAPIBase: getAPIBase, idSuffix: "page" })] }))] }));
21829
21829
  }
21830
21830
 
21831
- export { Button, EmailLoginForm, LoginTitle, SignInPageContent, cn };
21831
+ const Spinner = (props) => {
21832
+ return (jsxs("svg", { "data-testid": "spinner", viewBox: "0 0 10 10", className: 'w-8 h-8', ...props, children: [jsx("title", { children: "spinner" }), jsx("circle", { cx: "5", cy: "5", r: "4", stroke: "currentColor", fill: "none", strokeDasharray: "4, 4", className: "animate-spin origin-center" })] }));
21833
+ };
21834
+
21835
+ // TODO: figure out where this should live v. modeling-app, for now this is only a subset
21836
+ const CustomIconMap = {
21837
+ exclamationMark: (jsxs("svg", { viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-label": "exclamation mark", children: [jsx("title", { children: "exclamation mark" }), jsx("path", { d: "M9.76391 11.6597L9.3633 7.91112V5.00671H10.6224V7.91112L10.2217 11.6597H9.76391ZM9.99283 15.1221C9.60176 15.1221 9.32515 15.041 9.163 14.8788C9.01039 14.7167 8.93408 14.5116 8.93408 14.2636V14.0061C8.93408 13.7581 9.01039 13.553 9.163 13.3909C9.32515 13.2287 9.60176 13.1476 9.99283 13.1476C10.3839 13.1476 10.6557 13.2287 10.8084 13.3909C10.9705 13.553 11.0516 13.7581 11.0516 14.0061V14.2636C11.0516 14.5116 10.9705 14.7167 10.8084 14.8788C10.6557 15.041 10.3839 15.1221 9.99283 15.1221Z", fill: "currentColor" })] })),
21838
+ infinity: (jsxs("svg", { viewBox: "0 0 13 6", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-label": "infinity", children: [jsx("title", { children: "infinity" }), jsx("path", { d: "M10 0C11.6567 0.000169571 12.9999 1.34331 13 3C13 4.65671 11.6567 5.99983 10 6C9.08871 6 8.27123 5.59359 7.72168 4.95312V4.95215L6.58398 3.64941L5.43262 4.95703L5.43164 4.95605C4.88213 5.59421 4.06758 6 3.1582 6C1.50144 5.99992 0.15825 4.65677 0.158203 3C0.158279 1.34326 1.50146 7.54041e-05 3.1582 0C4.06727 0 4.88213 0.405203 5.43164 1.04297H5.43262L6.58496 2.34961L7.72461 1.04492C8.27414 0.406002 9.08999 0 10 0ZM3.1582 0.857422C1.97485 0.857497 1.0157 1.81664 1.01562 3C1.01567 4.18338 1.97483 5.1425 3.1582 5.14258C3.80891 5.14258 4.3915 4.85326 4.78516 4.39453L4.78906 4.38965L6.01562 3L4.78906 1.61035L4.78516 1.60547C4.3915 1.1468 3.80885 0.857422 3.1582 0.857422ZM10 0.857422C9.34921 0.857422 8.76573 1.14664 8.37207 1.60547L8.37012 1.6084L7.15527 3L8.37012 4.3916L8.37305 4.39453H8.37207C8.76573 4.85333 9.34924 5.14258 10 5.14258C11.1833 5.14241 12.1425 4.18332 12.1426 3C12.1425 1.8167 11.1833 0.857591 10 0.857422Z", fill: "currentColor" })] })),
21839
+ star: (jsxs("svg", { viewBox: "0 0 14 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-label": "star", children: [jsx("title", { children: "star" }), jsx("path", { d: "M8.93445 5.33667H13.6571L13.951 6.24097L10.1298 9.01636L11.5897 13.5085L10.8202 14.0671L6.99988 11.2908L3.17957 14.0671L2.41003 13.5085L3.86902 9.01636L0.0487061 6.24097L0.342651 5.33667H5.06531L6.52429 0.845459H7.47546L8.93445 5.33667ZM5.90417 5.99097L5.42859 6.33667H1.88074L4.75085 8.42163L4.9325 8.98022L3.83582 12.3533L6.70593 10.2693H7.29382L10.163 12.3533L9.06726 8.98022L9.2489 8.42163L12.119 6.33667H8.57117L8.09558 5.99097L6.99988 2.61792L5.90417 5.99097Z", fill: "currentColor" })] })),
21840
+ };
21841
+ const CustomIcon = ({ name, ...props }) => cloneElement(CustomIconMap[name], props);
21842
+
21843
+ var BillingRemainingMode;
21844
+ (function (BillingRemainingMode) {
21845
+ BillingRemainingMode[BillingRemainingMode["ProgressBarFixed"] = 0] = "ProgressBarFixed";
21846
+ BillingRemainingMode[BillingRemainingMode["ProgressBarStretch"] = 1] = "ProgressBarStretch";
21847
+ })(BillingRemainingMode || (BillingRemainingMode = {}));
21848
+ const ErrorMsg = (props) => {
21849
+ const [showMessage, setShowMessage] = useState(false);
21850
+ const fadedBg = 'rgba(127, 127, 127, 1)';
21851
+ const fadedFg = 'rgba(255, 255, 255, 1)';
21852
+ const colors = {
21853
+ color: fadedFg,
21854
+ stroke: fadedFg,
21855
+ fill: fadedFg,
21856
+ backgroundColor: fadedBg,
21857
+ };
21858
+ return (jsxs("div", { onMouseEnter: () => setShowMessage(true), onMouseLeave: () => setShowMessage(false), children: [showMessage && (jsx("div", { style: {
21859
+ position: 'absolute',
21860
+ }, children: jsx("div", { className: "rounded p-1", style: { ...colors, position: 'relative', top: -32 }, children: props.error.toString() }) })), jsx("div", { className: "rounded", style: colors, children: jsx(CustomIcon, { name: "exclamationMark", className: "w-5 h-5" }) })] }));
21861
+ };
21862
+ const ProgressBar = (props) => {
21863
+ const ratio = props.value / props.max;
21864
+ return (jsx("div", { className: "h-1.5 rounded w-full border-ml-black bg-ml-black border", children: jsx("div", { "data-testid": "billing-remaining-progress-bar-inner", className: "bg-ml-green rounded-full", style: {
21865
+ width: `${Math.min(100, ratio * 100).toFixed(2)}%`,
21866
+ height: '100%',
21867
+ } }) }));
21868
+ };
21869
+ const BillingCredit = (props) => {
21870
+ return props.amount === Number.POSITIVE_INFINITY ? (jsx(CustomIcon, { "data-testid": "infinity", name: "infinity", className: "w-5 h-5" })) : Number.isNaN(props.amount) || props.amount === undefined ? (jsx(Spinner, { className: "text-inherit w-4 h-4" })) : (Math.max(0, Math.trunc(props.amount)));
21871
+ };
21872
+ const BillingRemaining = (props) => {
21873
+ const isFlex = props.mode === BillingRemainingMode.ProgressBarStretch;
21874
+ const cssWrapper = [
21875
+ 'bg-ml-green',
21876
+ 'dark:bg-transparent',
21877
+ 'select-none',
21878
+ 'cursor-pointer',
21879
+ '!no-underline',
21880
+ 'text-xs',
21881
+ '!text-chalkboard-100',
21882
+ 'dark:!text-ml-green',
21883
+ ];
21884
+ return (jsxs("div", { "data-testid": "billing-remaining", className: [isFlex ? 'flex flex-col gap-1' : 'px-2 flex items-stretch']
21885
+ .concat(cssWrapper)
21886
+ .join(' '), children: [jsxs("div", { className: "flex flex-row gap-2 items-center", children: [props.error && jsx(ErrorMsg, { error: props.error }), !isFlex &&
21887
+ (typeof props.credits === 'number' ? (jsx("div", { className: "font-mono", "data-testid": "billing-credits", children: jsx(BillingCredit, { amount: props.credits }) })) : (jsx(Spinner, { className: "text-inherit w-4 h-4" }))), props.credits !== Number.POSITIVE_INFINITY && (jsx("div", { className: [isFlex ? 'flex-grow' : 'w-9'].join(' '), children: jsx(ProgressBar, { max: props.allowance ?? 1, value: props.credits ?? 0 }) }))] }), isFlex && (jsx("div", { className: "flex flex-row gap-1", children: typeof props.credits === 'number' ? (props.credits !== Number.POSITIVE_INFINITY ? (jsxs(Fragment, { children: [props.credits, " credits remaining this month"] })) : null) : (jsxs(Fragment, { children: [jsx(Spinner, { className: "text-inherit w-4 h-4" }), ' ', jsx("span", { children: "Fetching remaining credits..." })] })) }))] }));
21888
+ };
21889
+
21890
+ const SITE = 'https://zoo.dev';
21891
+ const paths = {
21892
+ ZOO_UPGRADE: `${SITE}/design-studio-pricing`};
21893
+
21894
+ const defaultProps = {
21895
+ upgradeHref: paths.ZOO_UPGRADE,
21896
+ text: {
21897
+ heading: {
21898
+ unlimited: 'Unlimited Text-to-CAD',
21899
+ limited: 'Upgrade your plan',
21900
+ },
21901
+ paragraph: {
21902
+ unlimited: 'You have unlimited use on your paid plan.',
21903
+ limited: 'for unlimited usage of Text-to-CAD and more!',
21904
+ },
21905
+ button: {
21906
+ limited: 'Upgrade',
21907
+ },
21908
+ },
21909
+ };
21910
+ const BillingDialog = (props) => {
21911
+ const hasUnlimited = props.credits === Number.POSITIVE_INFINITY;
21912
+ return (jsxs("div", { className: `bg-ml-green fg-ml-black flex flex-row rounded-lg p-4 gap-2 text-xs ${props.className ?? ''}`, children: [jsx("div", { children: jsx("div", { className: "rounded bg-ml-black p-1", children: hasUnlimited ? (jsx(CustomIcon, { name: "infinity", className: "!text-ml-white w-5 h-5" })) : (jsx(CustomIcon, { name: "star", className: "!text-ml-white w-5 h-5" })) }) }), jsxs("div", { className: "flex flex-col gap-2", children: [jsx("div", { className: "font-bold text-ml-black h-5 py-1", children: hasUnlimited
21913
+ ? props.text?.heading?.unlimited ||
21914
+ defaultProps.text?.heading?.unlimited
21915
+ : props.text?.heading?.limited ||
21916
+ defaultProps.text?.heading?.limited }), jsx("div", { className: "text-ml-grey", children: hasUnlimited
21917
+ ? props.text?.paragraph?.unlimited ||
21918
+ defaultProps.text?.paragraph?.unlimited
21919
+ : props.text?.paragraph?.limited ||
21920
+ defaultProps.text?.paragraph?.limited }), jsx(BillingRemaining, { mode: BillingRemainingMode.ProgressBarStretch, error: props.error, credits: props.credits, allowance: props.allowance }), !hasUnlimited && (jsx("a", { className: "bg-ml-black text-ml-white rounded-lg text-center p-1 cursor-pointer", href: props.upgradeHref || defaultProps.upgradeHref, target: "_blank", rel: "noopener noreferrer", "data-testid": "billing-upgrade-button", onClick: props.upgradeClick, children: props.text?.button?.limited || defaultProps.text?.button?.limited }))] })] }));
21921
+ };
21922
+
21923
+ const TypedArrayPrototypeGetSymbolToStringTag = (() => {
21924
+ const g = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
21925
+ return (value) => g.call(value);
21926
+ })();
21927
+ function isUint8Array(value) {
21928
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === 'Uint8Array';
21929
+ }
21930
+ function isAnyArrayBuffer(value) {
21931
+ return (typeof value === 'object' &&
21932
+ value != null &&
21933
+ Symbol.toStringTag in value &&
21934
+ (value[Symbol.toStringTag] === 'ArrayBuffer' ||
21935
+ value[Symbol.toStringTag] === 'SharedArrayBuffer'));
21936
+ }
21937
+ function isRegExp(regexp) {
21938
+ return regexp instanceof RegExp || Object.prototype.toString.call(regexp) === '[object RegExp]';
21939
+ }
21940
+ function isMap(value) {
21941
+ return (typeof value === 'object' &&
21942
+ value != null &&
21943
+ Symbol.toStringTag in value &&
21944
+ value[Symbol.toStringTag] === 'Map');
21945
+ }
21946
+ function isDate(date) {
21947
+ return date instanceof Date || Object.prototype.toString.call(date) === '[object Date]';
21948
+ }
21949
+ function defaultInspect(x, _options) {
21950
+ return JSON.stringify(x, (k, v) => {
21951
+ if (typeof v === 'bigint') {
21952
+ return { $numberLong: `${v}` };
21953
+ }
21954
+ else if (isMap(v)) {
21955
+ return Object.fromEntries(v);
21956
+ }
21957
+ return v;
21958
+ });
21959
+ }
21960
+ function getStylizeFunction(options) {
21961
+ const stylizeExists = options != null &&
21962
+ typeof options === 'object' &&
21963
+ 'stylize' in options &&
21964
+ typeof options.stylize === 'function';
21965
+ if (stylizeExists) {
21966
+ return options.stylize;
21967
+ }
21968
+ }
21969
+
21970
+ const BSON_MAJOR_VERSION = 6;
21971
+ const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
21972
+ const BSON_INT32_MAX = 0x7fffffff;
21973
+ const BSON_INT32_MIN = -2147483648;
21974
+ const BSON_INT64_MAX = Math.pow(2, 63) - 1;
21975
+ const BSON_INT64_MIN = -Math.pow(2, 63);
21976
+ const JS_INT_MAX = Math.pow(2, 53);
21977
+ const JS_INT_MIN = -Math.pow(2, 53);
21978
+ const BSON_BINARY_SUBTYPE_UUID_NEW = 4;
21979
+
21980
+ class BSONError extends Error {
21981
+ get bsonError() {
21982
+ return true;
21983
+ }
21984
+ get name() {
21985
+ return 'BSONError';
21986
+ }
21987
+ constructor(message, options) {
21988
+ super(message, options);
21989
+ }
21990
+ static isBSONError(value) {
21991
+ return (value != null &&
21992
+ typeof value === 'object' &&
21993
+ 'bsonError' in value &&
21994
+ value.bsonError === true &&
21995
+ 'name' in value &&
21996
+ 'message' in value &&
21997
+ 'stack' in value);
21998
+ }
21999
+ }
22000
+ class BSONVersionError extends BSONError {
22001
+ get name() {
22002
+ return 'BSONVersionError';
22003
+ }
22004
+ constructor() {
22005
+ super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
22006
+ }
22007
+ }
22008
+ class BSONRuntimeError extends BSONError {
22009
+ get name() {
22010
+ return 'BSONRuntimeError';
22011
+ }
22012
+ constructor(message) {
22013
+ super(message);
22014
+ }
22015
+ }
22016
+ class BSONOffsetError extends BSONError {
22017
+ get name() {
22018
+ return 'BSONOffsetError';
22019
+ }
22020
+ constructor(message, offset, options) {
22021
+ super(`${message}. offset: ${offset}`, options);
22022
+ this.offset = offset;
22023
+ }
22024
+ }
22025
+
22026
+ let TextDecoderFatal;
22027
+ let TextDecoderNonFatal;
22028
+ function parseUtf8(buffer, start, end, fatal) {
22029
+ if (fatal) {
22030
+ TextDecoderFatal ??= new TextDecoder('utf8', { fatal: true });
22031
+ try {
22032
+ return TextDecoderFatal.decode(buffer.subarray(start, end));
22033
+ }
22034
+ catch (cause) {
22035
+ throw new BSONError('Invalid UTF-8 string in BSON document', { cause });
22036
+ }
22037
+ }
22038
+ TextDecoderNonFatal ??= new TextDecoder('utf8', { fatal: false });
22039
+ return TextDecoderNonFatal.decode(buffer.subarray(start, end));
22040
+ }
22041
+
22042
+ function tryReadBasicLatin(uint8array, start, end) {
22043
+ if (uint8array.length === 0) {
22044
+ return '';
22045
+ }
22046
+ const stringByteLength = end - start;
22047
+ if (stringByteLength === 0) {
22048
+ return '';
22049
+ }
22050
+ if (stringByteLength > 20) {
22051
+ return null;
22052
+ }
22053
+ if (stringByteLength === 1 && uint8array[start] < 128) {
22054
+ return String.fromCharCode(uint8array[start]);
22055
+ }
22056
+ if (stringByteLength === 2 && uint8array[start] < 128 && uint8array[start + 1] < 128) {
22057
+ return String.fromCharCode(uint8array[start]) + String.fromCharCode(uint8array[start + 1]);
22058
+ }
22059
+ if (stringByteLength === 3 &&
22060
+ uint8array[start] < 128 &&
22061
+ uint8array[start + 1] < 128 &&
22062
+ uint8array[start + 2] < 128) {
22063
+ return (String.fromCharCode(uint8array[start]) +
22064
+ String.fromCharCode(uint8array[start + 1]) +
22065
+ String.fromCharCode(uint8array[start + 2]));
22066
+ }
22067
+ const latinBytes = [];
22068
+ for (let i = start; i < end; i++) {
22069
+ const byte = uint8array[i];
22070
+ if (byte > 127) {
22071
+ return null;
22072
+ }
22073
+ latinBytes.push(byte);
22074
+ }
22075
+ return String.fromCharCode(...latinBytes);
22076
+ }
22077
+ function tryWriteBasicLatin(destination, source, offset) {
22078
+ if (source.length === 0)
22079
+ return 0;
22080
+ if (source.length > 25)
22081
+ return null;
22082
+ if (destination.length - offset < source.length)
22083
+ return null;
22084
+ for (let charOffset = 0, destinationOffset = offset; charOffset < source.length; charOffset++, destinationOffset++) {
22085
+ const char = source.charCodeAt(charOffset);
22086
+ if (char > 127)
22087
+ return null;
22088
+ destination[destinationOffset] = char;
22089
+ }
22090
+ return source.length;
22091
+ }
22092
+
22093
+ function nodejsMathRandomBytes(byteLength) {
22094
+ return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
22095
+ }
22096
+ const nodejsRandomBytes = nodejsMathRandomBytes;
22097
+ const nodeJsByteUtils = {
22098
+ toLocalBufferType(potentialBuffer) {
22099
+ if (Buffer.isBuffer(potentialBuffer)) {
22100
+ return potentialBuffer;
22101
+ }
22102
+ if (ArrayBuffer.isView(potentialBuffer)) {
22103
+ return Buffer.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
22104
+ }
22105
+ const stringTag = potentialBuffer?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialBuffer);
22106
+ if (stringTag === 'ArrayBuffer' ||
22107
+ stringTag === 'SharedArrayBuffer' ||
22108
+ stringTag === '[object ArrayBuffer]' ||
22109
+ stringTag === '[object SharedArrayBuffer]') {
22110
+ return Buffer.from(potentialBuffer);
22111
+ }
22112
+ throw new BSONError(`Cannot create Buffer from the passed potentialBuffer.`);
22113
+ },
22114
+ allocate(size) {
22115
+ return Buffer.alloc(size);
22116
+ },
22117
+ allocateUnsafe(size) {
22118
+ return Buffer.allocUnsafe(size);
22119
+ },
22120
+ equals(a, b) {
22121
+ return nodeJsByteUtils.toLocalBufferType(a).equals(b);
22122
+ },
22123
+ fromNumberArray(array) {
22124
+ return Buffer.from(array);
22125
+ },
22126
+ fromBase64(base64) {
22127
+ return Buffer.from(base64, 'base64');
22128
+ },
22129
+ toBase64(buffer) {
22130
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('base64');
22131
+ },
22132
+ fromISO88591(codePoints) {
22133
+ return Buffer.from(codePoints, 'binary');
22134
+ },
22135
+ toISO88591(buffer) {
22136
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('binary');
22137
+ },
22138
+ fromHex(hex) {
22139
+ return Buffer.from(hex, 'hex');
22140
+ },
22141
+ toHex(buffer) {
22142
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('hex');
22143
+ },
22144
+ toUTF8(buffer, start, end, fatal) {
22145
+ const basicLatin = end - start <= 20 ? tryReadBasicLatin(buffer, start, end) : null;
22146
+ if (basicLatin != null) {
22147
+ return basicLatin;
22148
+ }
22149
+ const string = nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
22150
+ if (fatal) {
22151
+ for (let i = 0; i < string.length; i++) {
22152
+ if (string.charCodeAt(i) === 0xfffd) {
22153
+ parseUtf8(buffer, start, end, true);
22154
+ break;
22155
+ }
22156
+ }
22157
+ }
22158
+ return string;
22159
+ },
22160
+ utf8ByteLength(input) {
22161
+ return Buffer.byteLength(input, 'utf8');
22162
+ },
22163
+ encodeUTF8Into(buffer, source, byteOffset) {
22164
+ const latinBytesWritten = tryWriteBasicLatin(buffer, source, byteOffset);
22165
+ if (latinBytesWritten != null) {
22166
+ return latinBytesWritten;
22167
+ }
22168
+ return nodeJsByteUtils.toLocalBufferType(buffer).write(source, byteOffset, undefined, 'utf8');
22169
+ },
22170
+ randomBytes: nodejsRandomBytes,
22171
+ swap32(buffer) {
22172
+ return nodeJsByteUtils.toLocalBufferType(buffer).swap32();
22173
+ }
22174
+ };
22175
+
22176
+ function isReactNative() {
22177
+ const { navigator } = globalThis;
22178
+ return typeof navigator === 'object' && navigator.product === 'ReactNative';
22179
+ }
22180
+ function webMathRandomBytes(byteLength) {
22181
+ if (byteLength < 0) {
22182
+ throw new RangeError(`The argument 'byteLength' is invalid. Received ${byteLength}`);
22183
+ }
22184
+ return webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
22185
+ }
22186
+ const webRandomBytes = (() => {
22187
+ const { crypto } = globalThis;
22188
+ if (crypto != null && typeof crypto.getRandomValues === 'function') {
22189
+ return (byteLength) => {
22190
+ return crypto.getRandomValues(webByteUtils.allocate(byteLength));
22191
+ };
22192
+ }
22193
+ else {
22194
+ if (isReactNative()) {
22195
+ const { console } = globalThis;
22196
+ console?.warn?.('BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.');
22197
+ }
22198
+ return webMathRandomBytes;
22199
+ }
22200
+ })();
22201
+ const HEX_DIGIT = /(\d|[a-f])/i;
22202
+ const webByteUtils = {
22203
+ toLocalBufferType(potentialUint8array) {
22204
+ const stringTag = potentialUint8array?.[Symbol.toStringTag] ??
22205
+ Object.prototype.toString.call(potentialUint8array);
22206
+ if (stringTag === 'Uint8Array') {
22207
+ return potentialUint8array;
22208
+ }
22209
+ if (ArrayBuffer.isView(potentialUint8array)) {
22210
+ return new Uint8Array(potentialUint8array.buffer.slice(potentialUint8array.byteOffset, potentialUint8array.byteOffset + potentialUint8array.byteLength));
22211
+ }
22212
+ if (stringTag === 'ArrayBuffer' ||
22213
+ stringTag === 'SharedArrayBuffer' ||
22214
+ stringTag === '[object ArrayBuffer]' ||
22215
+ stringTag === '[object SharedArrayBuffer]') {
22216
+ return new Uint8Array(potentialUint8array);
22217
+ }
22218
+ throw new BSONError(`Cannot make a Uint8Array from passed potentialBuffer.`);
22219
+ },
22220
+ allocate(size) {
22221
+ if (typeof size !== 'number') {
22222
+ throw new TypeError(`The "size" argument must be of type number. Received ${String(size)}`);
22223
+ }
22224
+ return new Uint8Array(size);
22225
+ },
22226
+ allocateUnsafe(size) {
22227
+ return webByteUtils.allocate(size);
22228
+ },
22229
+ equals(a, b) {
22230
+ if (a.byteLength !== b.byteLength) {
22231
+ return false;
22232
+ }
22233
+ for (let i = 0; i < a.byteLength; i++) {
22234
+ if (a[i] !== b[i]) {
22235
+ return false;
22236
+ }
22237
+ }
22238
+ return true;
22239
+ },
22240
+ fromNumberArray(array) {
22241
+ return Uint8Array.from(array);
22242
+ },
22243
+ fromBase64(base64) {
22244
+ return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
22245
+ },
22246
+ toBase64(uint8array) {
22247
+ return btoa(webByteUtils.toISO88591(uint8array));
22248
+ },
22249
+ fromISO88591(codePoints) {
22250
+ return Uint8Array.from(codePoints, c => c.charCodeAt(0) & 0xff);
22251
+ },
22252
+ toISO88591(uint8array) {
22253
+ return Array.from(Uint16Array.from(uint8array), b => String.fromCharCode(b)).join('');
22254
+ },
22255
+ fromHex(hex) {
22256
+ const evenLengthHex = hex.length % 2 === 0 ? hex : hex.slice(0, hex.length - 1);
22257
+ const buffer = [];
22258
+ for (let i = 0; i < evenLengthHex.length; i += 2) {
22259
+ const firstDigit = evenLengthHex[i];
22260
+ const secondDigit = evenLengthHex[i + 1];
22261
+ if (!HEX_DIGIT.test(firstDigit)) {
22262
+ break;
22263
+ }
22264
+ if (!HEX_DIGIT.test(secondDigit)) {
22265
+ break;
22266
+ }
22267
+ const hexDigit = Number.parseInt(`${firstDigit}${secondDigit}`, 16);
22268
+ buffer.push(hexDigit);
22269
+ }
22270
+ return Uint8Array.from(buffer);
22271
+ },
22272
+ toHex(uint8array) {
22273
+ return Array.from(uint8array, byte => byte.toString(16).padStart(2, '0')).join('');
22274
+ },
22275
+ toUTF8(uint8array, start, end, fatal) {
22276
+ const basicLatin = end - start <= 20 ? tryReadBasicLatin(uint8array, start, end) : null;
22277
+ if (basicLatin != null) {
22278
+ return basicLatin;
22279
+ }
22280
+ return parseUtf8(uint8array, start, end, fatal);
22281
+ },
22282
+ utf8ByteLength(input) {
22283
+ return new TextEncoder().encode(input).byteLength;
22284
+ },
22285
+ encodeUTF8Into(uint8array, source, byteOffset) {
22286
+ const bytes = new TextEncoder().encode(source);
22287
+ uint8array.set(bytes, byteOffset);
22288
+ return bytes.byteLength;
22289
+ },
22290
+ randomBytes: webRandomBytes,
22291
+ swap32(buffer) {
22292
+ if (buffer.length % 4 !== 0) {
22293
+ throw new RangeError('Buffer size must be a multiple of 32-bits');
22294
+ }
22295
+ for (let i = 0; i < buffer.length; i += 4) {
22296
+ const byte0 = buffer[i];
22297
+ const byte1 = buffer[i + 1];
22298
+ const byte2 = buffer[i + 2];
22299
+ const byte3 = buffer[i + 3];
22300
+ buffer[i] = byte3;
22301
+ buffer[i + 1] = byte2;
22302
+ buffer[i + 2] = byte1;
22303
+ buffer[i + 3] = byte0;
22304
+ }
22305
+ return buffer;
22306
+ }
22307
+ };
22308
+
22309
+ const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuffer !== true;
22310
+ const ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
22311
+
22312
+ class BSONValue {
22313
+ get [BSON_VERSION_SYMBOL]() {
22314
+ return BSON_MAJOR_VERSION;
22315
+ }
22316
+ [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
22317
+ return this.inspect(depth, options, inspect);
22318
+ }
22319
+ }
22320
+
22321
+ const FLOAT = new Float64Array(1);
22322
+ const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
22323
+ FLOAT[0] = -1;
22324
+ const isBigEndian = FLOAT_BYTES[7] === 0;
22325
+ const NumberUtils = {
22326
+ isBigEndian,
22327
+ getNonnegativeInt32LE(source, offset) {
22328
+ if (source[offset + 3] > 127) {
22329
+ throw new RangeError(`Size cannot be negative at offset: ${offset}`);
22330
+ }
22331
+ return (source[offset] |
22332
+ (source[offset + 1] << 8) |
22333
+ (source[offset + 2] << 16) |
22334
+ (source[offset + 3] << 24));
22335
+ },
22336
+ getInt32LE(source, offset) {
22337
+ return (source[offset] |
22338
+ (source[offset + 1] << 8) |
22339
+ (source[offset + 2] << 16) |
22340
+ (source[offset + 3] << 24));
22341
+ },
22342
+ getUint32LE(source, offset) {
22343
+ return (source[offset] +
22344
+ source[offset + 1] * 256 +
22345
+ source[offset + 2] * 65536 +
22346
+ source[offset + 3] * 16777216);
22347
+ },
22348
+ getUint32BE(source, offset) {
22349
+ return (source[offset + 3] +
22350
+ source[offset + 2] * 256 +
22351
+ source[offset + 1] * 65536 +
22352
+ source[offset] * 16777216);
22353
+ },
22354
+ getBigInt64LE(source, offset) {
22355
+ const hi = BigInt(source[offset + 4] +
22356
+ source[offset + 5] * 256 +
22357
+ source[offset + 6] * 65536 +
22358
+ (source[offset + 7] << 24));
22359
+ const lo = BigInt(source[offset] +
22360
+ source[offset + 1] * 256 +
22361
+ source[offset + 2] * 65536 +
22362
+ source[offset + 3] * 16777216);
22363
+ return (hi << BigInt(32)) + lo;
22364
+ },
22365
+ getFloat64LE: isBigEndian
22366
+ ? (source, offset) => {
22367
+ FLOAT_BYTES[7] = source[offset];
22368
+ FLOAT_BYTES[6] = source[offset + 1];
22369
+ FLOAT_BYTES[5] = source[offset + 2];
22370
+ FLOAT_BYTES[4] = source[offset + 3];
22371
+ FLOAT_BYTES[3] = source[offset + 4];
22372
+ FLOAT_BYTES[2] = source[offset + 5];
22373
+ FLOAT_BYTES[1] = source[offset + 6];
22374
+ FLOAT_BYTES[0] = source[offset + 7];
22375
+ return FLOAT[0];
22376
+ }
22377
+ : (source, offset) => {
22378
+ FLOAT_BYTES[0] = source[offset];
22379
+ FLOAT_BYTES[1] = source[offset + 1];
22380
+ FLOAT_BYTES[2] = source[offset + 2];
22381
+ FLOAT_BYTES[3] = source[offset + 3];
22382
+ FLOAT_BYTES[4] = source[offset + 4];
22383
+ FLOAT_BYTES[5] = source[offset + 5];
22384
+ FLOAT_BYTES[6] = source[offset + 6];
22385
+ FLOAT_BYTES[7] = source[offset + 7];
22386
+ return FLOAT[0];
22387
+ },
22388
+ setInt32BE(destination, offset, value) {
22389
+ destination[offset + 3] = value;
22390
+ value >>>= 8;
22391
+ destination[offset + 2] = value;
22392
+ value >>>= 8;
22393
+ destination[offset + 1] = value;
22394
+ value >>>= 8;
22395
+ destination[offset] = value;
22396
+ return 4;
22397
+ },
22398
+ setInt32LE(destination, offset, value) {
22399
+ destination[offset] = value;
22400
+ value >>>= 8;
22401
+ destination[offset + 1] = value;
22402
+ value >>>= 8;
22403
+ destination[offset + 2] = value;
22404
+ value >>>= 8;
22405
+ destination[offset + 3] = value;
22406
+ return 4;
22407
+ },
22408
+ setBigInt64LE(destination, offset, value) {
22409
+ const mask32bits = BigInt(0xffff_ffff);
22410
+ let lo = Number(value & mask32bits);
22411
+ destination[offset] = lo;
22412
+ lo >>= 8;
22413
+ destination[offset + 1] = lo;
22414
+ lo >>= 8;
22415
+ destination[offset + 2] = lo;
22416
+ lo >>= 8;
22417
+ destination[offset + 3] = lo;
22418
+ let hi = Number((value >> BigInt(32)) & mask32bits);
22419
+ destination[offset + 4] = hi;
22420
+ hi >>= 8;
22421
+ destination[offset + 5] = hi;
22422
+ hi >>= 8;
22423
+ destination[offset + 6] = hi;
22424
+ hi >>= 8;
22425
+ destination[offset + 7] = hi;
22426
+ return 8;
22427
+ },
22428
+ setFloat64LE: isBigEndian
22429
+ ? (destination, offset, value) => {
22430
+ FLOAT[0] = value;
22431
+ destination[offset] = FLOAT_BYTES[7];
22432
+ destination[offset + 1] = FLOAT_BYTES[6];
22433
+ destination[offset + 2] = FLOAT_BYTES[5];
22434
+ destination[offset + 3] = FLOAT_BYTES[4];
22435
+ destination[offset + 4] = FLOAT_BYTES[3];
22436
+ destination[offset + 5] = FLOAT_BYTES[2];
22437
+ destination[offset + 6] = FLOAT_BYTES[1];
22438
+ destination[offset + 7] = FLOAT_BYTES[0];
22439
+ return 8;
22440
+ }
22441
+ : (destination, offset, value) => {
22442
+ FLOAT[0] = value;
22443
+ destination[offset] = FLOAT_BYTES[0];
22444
+ destination[offset + 1] = FLOAT_BYTES[1];
22445
+ destination[offset + 2] = FLOAT_BYTES[2];
22446
+ destination[offset + 3] = FLOAT_BYTES[3];
22447
+ destination[offset + 4] = FLOAT_BYTES[4];
22448
+ destination[offset + 5] = FLOAT_BYTES[5];
22449
+ destination[offset + 6] = FLOAT_BYTES[6];
22450
+ destination[offset + 7] = FLOAT_BYTES[7];
22451
+ return 8;
22452
+ }
22453
+ };
22454
+
22455
+ class Binary extends BSONValue {
22456
+ get _bsontype() {
22457
+ return 'Binary';
22458
+ }
22459
+ constructor(buffer, subType) {
22460
+ super();
22461
+ if (!(buffer == null) &&
22462
+ typeof buffer === 'string' &&
22463
+ !ArrayBuffer.isView(buffer) &&
22464
+ !isAnyArrayBuffer(buffer) &&
22465
+ !Array.isArray(buffer)) {
22466
+ throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
22467
+ }
22468
+ this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
22469
+ if (buffer == null) {
22470
+ this.buffer = ByteUtils.allocate(Binary.BUFFER_SIZE);
22471
+ this.position = 0;
22472
+ }
22473
+ else {
22474
+ this.buffer = Array.isArray(buffer)
22475
+ ? ByteUtils.fromNumberArray(buffer)
22476
+ : ByteUtils.toLocalBufferType(buffer);
22477
+ this.position = this.buffer.byteLength;
22478
+ }
22479
+ }
22480
+ put(byteValue) {
22481
+ if (typeof byteValue === 'string' && byteValue.length !== 1) {
22482
+ throw new BSONError('only accepts single character String');
22483
+ }
22484
+ else if (typeof byteValue !== 'number' && byteValue.length !== 1)
22485
+ throw new BSONError('only accepts single character Uint8Array or Array');
22486
+ let decodedByte;
22487
+ if (typeof byteValue === 'string') {
22488
+ decodedByte = byteValue.charCodeAt(0);
22489
+ }
22490
+ else if (typeof byteValue === 'number') {
22491
+ decodedByte = byteValue;
22492
+ }
22493
+ else {
22494
+ decodedByte = byteValue[0];
22495
+ }
22496
+ if (decodedByte < 0 || decodedByte > 255) {
22497
+ throw new BSONError('only accepts number in a valid unsigned byte range 0-255');
22498
+ }
22499
+ if (this.buffer.byteLength > this.position) {
22500
+ this.buffer[this.position++] = decodedByte;
22501
+ }
22502
+ else {
22503
+ const newSpace = ByteUtils.allocate(Binary.BUFFER_SIZE + this.buffer.length);
22504
+ newSpace.set(this.buffer, 0);
22505
+ this.buffer = newSpace;
22506
+ this.buffer[this.position++] = decodedByte;
22507
+ }
22508
+ }
22509
+ write(sequence, offset) {
22510
+ offset = typeof offset === 'number' ? offset : this.position;
22511
+ if (this.buffer.byteLength < offset + sequence.length) {
22512
+ const newSpace = ByteUtils.allocate(this.buffer.byteLength + sequence.length);
22513
+ newSpace.set(this.buffer, 0);
22514
+ this.buffer = newSpace;
22515
+ }
22516
+ if (ArrayBuffer.isView(sequence)) {
22517
+ this.buffer.set(ByteUtils.toLocalBufferType(sequence), offset);
22518
+ this.position =
22519
+ offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
22520
+ }
22521
+ else if (typeof sequence === 'string') {
22522
+ throw new BSONError('input cannot be string');
22523
+ }
22524
+ }
22525
+ read(position, length) {
22526
+ length = length && length > 0 ? length : this.position;
22527
+ const end = position + length;
22528
+ return this.buffer.subarray(position, end > this.position ? this.position : end);
22529
+ }
22530
+ value() {
22531
+ return this.buffer.length === this.position
22532
+ ? this.buffer
22533
+ : this.buffer.subarray(0, this.position);
22534
+ }
22535
+ length() {
22536
+ return this.position;
22537
+ }
22538
+ toJSON() {
22539
+ return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
22540
+ }
22541
+ toString(encoding) {
22542
+ if (encoding === 'hex')
22543
+ return ByteUtils.toHex(this.buffer.subarray(0, this.position));
22544
+ if (encoding === 'base64')
22545
+ return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
22546
+ if (encoding === 'utf8' || encoding === 'utf-8')
22547
+ return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
22548
+ return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
22549
+ }
22550
+ toExtendedJSON(options) {
22551
+ options = options || {};
22552
+ if (this.sub_type === Binary.SUBTYPE_VECTOR) {
22553
+ validateBinaryVector(this);
22554
+ }
22555
+ const base64String = ByteUtils.toBase64(this.buffer);
22556
+ const subType = Number(this.sub_type).toString(16);
22557
+ if (options.legacy) {
22558
+ return {
22559
+ $binary: base64String,
22560
+ $type: subType.length === 1 ? '0' + subType : subType
22561
+ };
22562
+ }
22563
+ return {
22564
+ $binary: {
22565
+ base64: base64String,
22566
+ subType: subType.length === 1 ? '0' + subType : subType
22567
+ }
22568
+ };
22569
+ }
22570
+ toUUID() {
22571
+ if (this.sub_type === Binary.SUBTYPE_UUID) {
22572
+ return new UUID(this.buffer.subarray(0, this.position));
22573
+ }
22574
+ throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`);
22575
+ }
22576
+ static createFromHexString(hex, subType) {
22577
+ return new Binary(ByteUtils.fromHex(hex), subType);
22578
+ }
22579
+ static createFromBase64(base64, subType) {
22580
+ return new Binary(ByteUtils.fromBase64(base64), subType);
22581
+ }
22582
+ static fromExtendedJSON(doc, options) {
22583
+ options = options || {};
22584
+ let data;
22585
+ let type;
22586
+ if ('$binary' in doc) {
22587
+ if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) {
22588
+ type = doc.$type ? parseInt(doc.$type, 16) : 0;
22589
+ data = ByteUtils.fromBase64(doc.$binary);
22590
+ }
22591
+ else {
22592
+ if (typeof doc.$binary !== 'string') {
22593
+ type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
22594
+ data = ByteUtils.fromBase64(doc.$binary.base64);
22595
+ }
22596
+ }
22597
+ }
22598
+ else if ('$uuid' in doc) {
22599
+ type = 4;
22600
+ data = UUID.bytesFromString(doc.$uuid);
22601
+ }
22602
+ if (!data) {
22603
+ throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
22604
+ }
22605
+ return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
22606
+ }
22607
+ inspect(depth, options, inspect) {
22608
+ inspect ??= defaultInspect;
22609
+ const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
22610
+ const base64Arg = inspect(base64, options);
22611
+ const subTypeArg = inspect(this.sub_type, options);
22612
+ return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
22613
+ }
22614
+ toInt8Array() {
22615
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22616
+ throw new BSONError('Binary sub_type is not Vector');
22617
+ }
22618
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
22619
+ throw new BSONError('Binary datatype field is not Int8');
22620
+ }
22621
+ validateBinaryVector(this);
22622
+ return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
22623
+ }
22624
+ toFloat32Array() {
22625
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22626
+ throw new BSONError('Binary sub_type is not Vector');
22627
+ }
22628
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
22629
+ throw new BSONError('Binary datatype field is not Float32');
22630
+ }
22631
+ validateBinaryVector(this);
22632
+ const floatBytes = new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
22633
+ if (NumberUtils.isBigEndian)
22634
+ ByteUtils.swap32(floatBytes);
22635
+ return new Float32Array(floatBytes.buffer);
22636
+ }
22637
+ toPackedBits() {
22638
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22639
+ throw new BSONError('Binary sub_type is not Vector');
22640
+ }
22641
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
22642
+ throw new BSONError('Binary datatype field is not packed bit');
22643
+ }
22644
+ validateBinaryVector(this);
22645
+ return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
22646
+ }
22647
+ toBits() {
22648
+ if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
22649
+ throw new BSONError('Binary sub_type is not Vector');
22650
+ }
22651
+ if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
22652
+ throw new BSONError('Binary datatype field is not packed bit');
22653
+ }
22654
+ validateBinaryVector(this);
22655
+ const byteCount = this.length() - 2;
22656
+ const bitCount = byteCount * 8 - this.buffer[1];
22657
+ const bits = new Int8Array(bitCount);
22658
+ for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
22659
+ const byteOffset = (bitOffset / 8) | 0;
22660
+ const byte = this.buffer[byteOffset + 2];
22661
+ const shift = 7 - (bitOffset % 8);
22662
+ const bit = (byte >> shift) & 1;
22663
+ bits[bitOffset] = bit;
22664
+ }
22665
+ return bits;
22666
+ }
22667
+ static fromInt8Array(array) {
22668
+ const buffer = ByteUtils.allocate(array.byteLength + 2);
22669
+ buffer[0] = Binary.VECTOR_TYPE.Int8;
22670
+ buffer[1] = 0;
22671
+ const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
22672
+ buffer.set(intBytes, 2);
22673
+ const bin = new this(buffer, this.SUBTYPE_VECTOR);
22674
+ validateBinaryVector(bin);
22675
+ return bin;
22676
+ }
22677
+ static fromFloat32Array(array) {
22678
+ const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
22679
+ binaryBytes[0] = Binary.VECTOR_TYPE.Float32;
22680
+ binaryBytes[1] = 0;
22681
+ const floatBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
22682
+ binaryBytes.set(floatBytes, 2);
22683
+ if (NumberUtils.isBigEndian)
22684
+ ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
22685
+ const bin = new this(binaryBytes, this.SUBTYPE_VECTOR);
22686
+ validateBinaryVector(bin);
22687
+ return bin;
22688
+ }
22689
+ static fromPackedBits(array, padding = 0) {
22690
+ const buffer = ByteUtils.allocate(array.byteLength + 2);
22691
+ buffer[0] = Binary.VECTOR_TYPE.PackedBit;
22692
+ buffer[1] = padding;
22693
+ buffer.set(array, 2);
22694
+ const bin = new this(buffer, this.SUBTYPE_VECTOR);
22695
+ validateBinaryVector(bin);
22696
+ return bin;
22697
+ }
22698
+ static fromBits(bits) {
22699
+ const byteLength = (bits.length + 7) >>> 3;
22700
+ const bytes = new Uint8Array(byteLength + 2);
22701
+ bytes[0] = Binary.VECTOR_TYPE.PackedBit;
22702
+ const remainder = bits.length % 8;
22703
+ bytes[1] = remainder === 0 ? 0 : 8 - remainder;
22704
+ for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
22705
+ const byteOffset = bitOffset >>> 3;
22706
+ const bit = bits[bitOffset];
22707
+ if (bit !== 0 && bit !== 1) {
22708
+ throw new BSONError(`Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`);
22709
+ }
22710
+ if (bit === 0)
22711
+ continue;
22712
+ const shift = 7 - (bitOffset % 8);
22713
+ bytes[byteOffset + 2] |= bit << shift;
22714
+ }
22715
+ return new this(bytes, Binary.SUBTYPE_VECTOR);
22716
+ }
22717
+ }
22718
+ Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
22719
+ Binary.BUFFER_SIZE = 256;
22720
+ Binary.SUBTYPE_DEFAULT = 0;
22721
+ Binary.SUBTYPE_FUNCTION = 1;
22722
+ Binary.SUBTYPE_BYTE_ARRAY = 2;
22723
+ Binary.SUBTYPE_UUID_OLD = 3;
22724
+ Binary.SUBTYPE_UUID = 4;
22725
+ Binary.SUBTYPE_MD5 = 5;
22726
+ Binary.SUBTYPE_ENCRYPTED = 6;
22727
+ Binary.SUBTYPE_COLUMN = 7;
22728
+ Binary.SUBTYPE_SENSITIVE = 8;
22729
+ Binary.SUBTYPE_VECTOR = 9;
22730
+ Binary.SUBTYPE_USER_DEFINED = 128;
22731
+ Binary.VECTOR_TYPE = Object.freeze({
22732
+ Int8: 0x03,
22733
+ Float32: 0x27,
22734
+ PackedBit: 0x10
22735
+ });
22736
+ function validateBinaryVector(vector) {
22737
+ if (vector.sub_type !== Binary.SUBTYPE_VECTOR)
22738
+ return;
22739
+ const size = vector.position;
22740
+ const datatype = vector.buffer[0];
22741
+ const padding = vector.buffer[1];
22742
+ if ((datatype === Binary.VECTOR_TYPE.Float32 || datatype === Binary.VECTOR_TYPE.Int8) &&
22743
+ padding !== 0) {
22744
+ throw new BSONError('Invalid Vector: padding must be zero for int8 and float32 vectors');
22745
+ }
22746
+ if (datatype === Binary.VECTOR_TYPE.Float32) {
22747
+ if (size !== 0 && size - 2 !== 0 && (size - 2) % 4 !== 0) {
22748
+ throw new BSONError('Invalid Vector: Float32 vector must contain a multiple of 4 bytes');
22749
+ }
22750
+ }
22751
+ if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
22752
+ throw new BSONError('Invalid Vector: padding must be zero for packed bit vectors that are empty');
22753
+ }
22754
+ if (datatype === Binary.VECTOR_TYPE.PackedBit && padding > 7) {
22755
+ throw new BSONError(`Invalid Vector: padding must be a value between 0 and 7. found: ${padding}`);
22756
+ }
22757
+ }
22758
+ const UUID_BYTE_LENGTH = 16;
22759
+ const UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
22760
+ const UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
22761
+ class UUID extends Binary {
22762
+ constructor(input) {
22763
+ let bytes;
22764
+ if (input == null) {
22765
+ bytes = UUID.generate();
22766
+ }
22767
+ else if (input instanceof UUID) {
22768
+ bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer));
22769
+ }
22770
+ else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
22771
+ bytes = ByteUtils.toLocalBufferType(input);
22772
+ }
22773
+ else if (typeof input === 'string') {
22774
+ bytes = UUID.bytesFromString(input);
22775
+ }
22776
+ else {
22777
+ throw new BSONError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
22778
+ }
22779
+ super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW);
22780
+ }
22781
+ get id() {
22782
+ return this.buffer;
22783
+ }
22784
+ set id(value) {
22785
+ this.buffer = value;
22786
+ }
22787
+ toHexString(includeDashes = true) {
22788
+ if (includeDashes) {
22789
+ return [
22790
+ ByteUtils.toHex(this.buffer.subarray(0, 4)),
22791
+ ByteUtils.toHex(this.buffer.subarray(4, 6)),
22792
+ ByteUtils.toHex(this.buffer.subarray(6, 8)),
22793
+ ByteUtils.toHex(this.buffer.subarray(8, 10)),
22794
+ ByteUtils.toHex(this.buffer.subarray(10, 16))
22795
+ ].join('-');
22796
+ }
22797
+ return ByteUtils.toHex(this.buffer);
22798
+ }
22799
+ toString(encoding) {
22800
+ if (encoding === 'hex')
22801
+ return ByteUtils.toHex(this.id);
22802
+ if (encoding === 'base64')
22803
+ return ByteUtils.toBase64(this.id);
22804
+ return this.toHexString();
22805
+ }
22806
+ toJSON() {
22807
+ return this.toHexString();
22808
+ }
22809
+ equals(otherId) {
22810
+ if (!otherId) {
22811
+ return false;
22812
+ }
22813
+ if (otherId instanceof UUID) {
22814
+ return ByteUtils.equals(otherId.id, this.id);
22815
+ }
22816
+ try {
22817
+ return ByteUtils.equals(new UUID(otherId).id, this.id);
22818
+ }
22819
+ catch {
22820
+ return false;
22821
+ }
22822
+ }
22823
+ toBinary() {
22824
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
22825
+ }
22826
+ static generate() {
22827
+ const bytes = ByteUtils.randomBytes(UUID_BYTE_LENGTH);
22828
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
22829
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
22830
+ return bytes;
22831
+ }
22832
+ static isValid(input) {
22833
+ if (!input) {
22834
+ return false;
22835
+ }
22836
+ if (typeof input === 'string') {
22837
+ return UUID.isValidUUIDString(input);
22838
+ }
22839
+ if (isUint8Array(input)) {
22840
+ return input.byteLength === UUID_BYTE_LENGTH;
22841
+ }
22842
+ return (input._bsontype === 'Binary' &&
22843
+ input.sub_type === this.SUBTYPE_UUID &&
22844
+ input.buffer.byteLength === 16);
22845
+ }
22846
+ static createFromHexString(hexString) {
22847
+ const buffer = UUID.bytesFromString(hexString);
22848
+ return new UUID(buffer);
22849
+ }
22850
+ static createFromBase64(base64) {
22851
+ return new UUID(ByteUtils.fromBase64(base64));
22852
+ }
22853
+ static bytesFromString(representation) {
22854
+ if (!UUID.isValidUUIDString(representation)) {
22855
+ throw new BSONError('UUID string representation must be 32 hex digits or canonical hyphenated representation');
22856
+ }
22857
+ return ByteUtils.fromHex(representation.replace(/-/g, ''));
22858
+ }
22859
+ static isValidUUIDString(representation) {
22860
+ return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
22861
+ }
22862
+ inspect(depth, options, inspect) {
22863
+ inspect ??= defaultInspect;
22864
+ return `new UUID(${inspect(this.toHexString(), options)})`;
22865
+ }
22866
+ }
22867
+
22868
+ class Code extends BSONValue {
22869
+ get _bsontype() {
22870
+ return 'Code';
22871
+ }
22872
+ constructor(code, scope) {
22873
+ super();
22874
+ this.code = code.toString();
22875
+ this.scope = scope ?? null;
22876
+ }
22877
+ toJSON() {
22878
+ if (this.scope != null) {
22879
+ return { code: this.code, scope: this.scope };
22880
+ }
22881
+ return { code: this.code };
22882
+ }
22883
+ toExtendedJSON() {
22884
+ if (this.scope) {
22885
+ return { $code: this.code, $scope: this.scope };
22886
+ }
22887
+ return { $code: this.code };
22888
+ }
22889
+ static fromExtendedJSON(doc) {
22890
+ return new Code(doc.$code, doc.$scope);
22891
+ }
22892
+ inspect(depth, options, inspect) {
22893
+ inspect ??= defaultInspect;
22894
+ let parametersString = inspect(this.code, options);
22895
+ const multiLineFn = parametersString.includes('\n');
22896
+ if (this.scope != null) {
22897
+ parametersString += `,${multiLineFn ? '\n' : ' '}${inspect(this.scope, options)}`;
22898
+ }
22899
+ const endingNewline = multiLineFn && this.scope === null;
22900
+ return `new Code(${multiLineFn ? '\n' : ''}${parametersString}${endingNewline ? '\n' : ''})`;
22901
+ }
22902
+ }
22903
+
22904
+ function isDBRefLike(value) {
22905
+ return (value != null &&
22906
+ typeof value === 'object' &&
22907
+ '$id' in value &&
22908
+ value.$id != null &&
22909
+ '$ref' in value &&
22910
+ typeof value.$ref === 'string' &&
22911
+ (!('$db' in value) || ('$db' in value && typeof value.$db === 'string')));
22912
+ }
22913
+ class DBRef extends BSONValue {
22914
+ get _bsontype() {
22915
+ return 'DBRef';
22916
+ }
22917
+ constructor(collection, oid, db, fields) {
22918
+ super();
22919
+ const parts = collection.split('.');
22920
+ if (parts.length === 2) {
22921
+ db = parts.shift();
22922
+ collection = parts.shift();
22923
+ }
22924
+ this.collection = collection;
22925
+ this.oid = oid;
22926
+ this.db = db;
22927
+ this.fields = fields || {};
22928
+ }
22929
+ get namespace() {
22930
+ return this.collection;
22931
+ }
22932
+ set namespace(value) {
22933
+ this.collection = value;
22934
+ }
22935
+ toJSON() {
22936
+ const o = Object.assign({
22937
+ $ref: this.collection,
22938
+ $id: this.oid
22939
+ }, this.fields);
22940
+ if (this.db != null)
22941
+ o.$db = this.db;
22942
+ return o;
22943
+ }
22944
+ toExtendedJSON(options) {
22945
+ options = options || {};
22946
+ let o = {
22947
+ $ref: this.collection,
22948
+ $id: this.oid
22949
+ };
22950
+ if (options.legacy) {
22951
+ return o;
22952
+ }
22953
+ if (this.db)
22954
+ o.$db = this.db;
22955
+ o = Object.assign(o, this.fields);
22956
+ return o;
22957
+ }
22958
+ static fromExtendedJSON(doc) {
22959
+ const copy = Object.assign({}, doc);
22960
+ delete copy.$ref;
22961
+ delete copy.$id;
22962
+ delete copy.$db;
22963
+ return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
22964
+ }
22965
+ inspect(depth, options, inspect) {
22966
+ inspect ??= defaultInspect;
22967
+ const args = [
22968
+ inspect(this.namespace, options),
22969
+ inspect(this.oid, options),
22970
+ ...(this.db ? [inspect(this.db, options)] : []),
22971
+ ...(Object.keys(this.fields).length > 0 ? [inspect(this.fields, options)] : [])
22972
+ ];
22973
+ args[1] = inspect === defaultInspect ? `new ObjectId(${args[1]})` : args[1];
22974
+ return `new DBRef(${args.join(', ')})`;
22975
+ }
22976
+ }
22977
+
22978
+ function removeLeadingZerosAndExplicitPlus(str) {
22979
+ if (str === '') {
22980
+ return str;
22981
+ }
22982
+ let startIndex = 0;
22983
+ const isNegative = str[startIndex] === '-';
22984
+ const isExplicitlyPositive = str[startIndex] === '+';
22985
+ if (isExplicitlyPositive || isNegative) {
22986
+ startIndex += 1;
22987
+ }
22988
+ let foundInsignificantZero = false;
22989
+ for (; startIndex < str.length && str[startIndex] === '0'; ++startIndex) {
22990
+ foundInsignificantZero = true;
22991
+ }
22992
+ if (!foundInsignificantZero) {
22993
+ return isExplicitlyPositive ? str.slice(1) : str;
22994
+ }
22995
+ return `${isNegative ? '-' : ''}${str.length === startIndex ? '0' : str.slice(startIndex)}`;
22996
+ }
22997
+ function validateStringCharacters(str, radix) {
22998
+ radix = radix ?? 10;
22999
+ const validCharacters = '0123456789abcdefghijklmnopqrstuvwxyz'.slice(0, radix);
23000
+ const regex = new RegExp(`[^-+${validCharacters}]`, 'i');
23001
+ return regex.test(str) ? false : str;
23002
+ }
23003
+
23004
+ let wasm = undefined;
23005
+ try {
23006
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11])), {}).exports;
23007
+ }
23008
+ catch {
23009
+ }
23010
+ const TWO_PWR_16_DBL = 1 << 16;
23011
+ const TWO_PWR_24_DBL = 1 << 24;
23012
+ const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
23013
+ const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
23014
+ const TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
23015
+ const INT_CACHE = {};
23016
+ const UINT_CACHE = {};
23017
+ const MAX_INT64_STRING_LENGTH = 20;
23018
+ const DECIMAL_REG_EX = /^(\+?0|(\+|-)?[1-9][0-9]*)$/;
23019
+ class Long extends BSONValue {
23020
+ get _bsontype() {
23021
+ return 'Long';
23022
+ }
23023
+ get __isLong__() {
23024
+ return true;
23025
+ }
23026
+ constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
23027
+ super();
23028
+ const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
23029
+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0;
23030
+ const res = typeof lowOrValue === 'string'
23031
+ ? Long.fromString(lowOrValue, unsignedBool)
23032
+ : typeof lowOrValue === 'bigint'
23033
+ ? Long.fromBigInt(lowOrValue, unsignedBool)
23034
+ : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
23035
+ this.low = res.low;
23036
+ this.high = res.high;
23037
+ this.unsigned = res.unsigned;
23038
+ }
23039
+ static fromBits(lowBits, highBits, unsigned) {
23040
+ return new Long(lowBits, highBits, unsigned);
23041
+ }
23042
+ static fromInt(value, unsigned) {
23043
+ let obj, cachedObj, cache;
23044
+ if (unsigned) {
23045
+ value >>>= 0;
23046
+ if ((cache = 0 <= value && value < 256)) {
23047
+ cachedObj = UINT_CACHE[value];
23048
+ if (cachedObj)
23049
+ return cachedObj;
23050
+ }
23051
+ obj = Long.fromBits(value, (value | 0) < 0 ? -1 : 0, true);
23052
+ if (cache)
23053
+ UINT_CACHE[value] = obj;
23054
+ return obj;
23055
+ }
23056
+ else {
23057
+ value |= 0;
23058
+ if ((cache = -128 <= value && value < 128)) {
23059
+ cachedObj = INT_CACHE[value];
23060
+ if (cachedObj)
23061
+ return cachedObj;
23062
+ }
23063
+ obj = Long.fromBits(value, value < 0 ? -1 : 0, false);
23064
+ if (cache)
23065
+ INT_CACHE[value] = obj;
23066
+ return obj;
23067
+ }
23068
+ }
23069
+ static fromNumber(value, unsigned) {
23070
+ if (isNaN(value))
23071
+ return unsigned ? Long.UZERO : Long.ZERO;
23072
+ if (unsigned) {
23073
+ if (value < 0)
23074
+ return Long.UZERO;
23075
+ if (value >= TWO_PWR_64_DBL)
23076
+ return Long.MAX_UNSIGNED_VALUE;
23077
+ }
23078
+ else {
23079
+ if (value <= -9223372036854776e3)
23080
+ return Long.MIN_VALUE;
23081
+ if (value + 1 >= TWO_PWR_63_DBL)
23082
+ return Long.MAX_VALUE;
23083
+ }
23084
+ if (value < 0)
23085
+ return Long.fromNumber(-value, unsigned).neg();
23086
+ return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
23087
+ }
23088
+ static fromBigInt(value, unsigned) {
23089
+ const FROM_BIGINT_BIT_MASK = BigInt(0xffffffff);
23090
+ const FROM_BIGINT_BIT_SHIFT = BigInt(32);
23091
+ return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
23092
+ }
23093
+ static _fromString(str, unsigned, radix) {
23094
+ if (str.length === 0)
23095
+ throw new BSONError('empty string');
23096
+ if (radix < 2 || 36 < radix)
23097
+ throw new BSONError('radix');
23098
+ let p;
23099
+ if ((p = str.indexOf('-')) > 0)
23100
+ throw new BSONError('interior hyphen');
23101
+ else if (p === 0) {
23102
+ return Long._fromString(str.substring(1), unsigned, radix).neg();
23103
+ }
23104
+ const radixToPower = Long.fromNumber(Math.pow(radix, 8));
23105
+ let result = Long.ZERO;
23106
+ for (let i = 0; i < str.length; i += 8) {
23107
+ const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
23108
+ if (size < 8) {
23109
+ const power = Long.fromNumber(Math.pow(radix, size));
23110
+ result = result.mul(power).add(Long.fromNumber(value));
23111
+ }
23112
+ else {
23113
+ result = result.mul(radixToPower);
23114
+ result = result.add(Long.fromNumber(value));
23115
+ }
23116
+ }
23117
+ result.unsigned = unsigned;
23118
+ return result;
23119
+ }
23120
+ static fromStringStrict(str, unsignedOrRadix, radix) {
23121
+ let unsigned = false;
23122
+ if (typeof unsignedOrRadix === 'number') {
23123
+ (radix = unsignedOrRadix), (unsignedOrRadix = false);
23124
+ }
23125
+ else {
23126
+ unsigned = !!unsignedOrRadix;
23127
+ }
23128
+ radix ??= 10;
23129
+ if (str.trim() !== str) {
23130
+ throw new BSONError(`Input: '${str}' contains leading and/or trailing whitespace`);
23131
+ }
23132
+ if (!validateStringCharacters(str, radix)) {
23133
+ throw new BSONError(`Input: '${str}' contains invalid characters for radix: ${radix}`);
23134
+ }
23135
+ const cleanedStr = removeLeadingZerosAndExplicitPlus(str);
23136
+ const result = Long._fromString(cleanedStr, unsigned, radix);
23137
+ if (result.toString(radix).toLowerCase() !== cleanedStr.toLowerCase()) {
23138
+ throw new BSONError(`Input: ${str} is not representable as ${result.unsigned ? 'an unsigned' : 'a signed'} 64-bit Long ${radix != null ? `with radix: ${radix}` : ''}`);
23139
+ }
23140
+ return result;
23141
+ }
23142
+ static fromString(str, unsignedOrRadix, radix) {
23143
+ let unsigned = false;
23144
+ if (typeof unsignedOrRadix === 'number') {
23145
+ (radix = unsignedOrRadix), (unsignedOrRadix = false);
23146
+ }
23147
+ else {
23148
+ unsigned = !!unsignedOrRadix;
23149
+ }
23150
+ radix ??= 10;
23151
+ if (str === 'NaN' && radix < 24) {
23152
+ return Long.ZERO;
23153
+ }
23154
+ else if ((str === 'Infinity' || str === '+Infinity' || str === '-Infinity') && radix < 35) {
23155
+ return Long.ZERO;
23156
+ }
23157
+ return Long._fromString(str, unsigned, radix);
23158
+ }
23159
+ static fromBytes(bytes, unsigned, le) {
23160
+ return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
23161
+ }
23162
+ static fromBytesLE(bytes, unsigned) {
23163
+ return new Long(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24), bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24), unsigned);
23164
+ }
23165
+ static fromBytesBE(bytes, unsigned) {
23166
+ return new Long((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7], (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3], unsigned);
23167
+ }
23168
+ static isLong(value) {
23169
+ return (value != null &&
23170
+ typeof value === 'object' &&
23171
+ '__isLong__' in value &&
23172
+ value.__isLong__ === true);
23173
+ }
23174
+ static fromValue(val, unsigned) {
23175
+ if (typeof val === 'number')
23176
+ return Long.fromNumber(val, unsigned);
23177
+ if (typeof val === 'string')
23178
+ return Long.fromString(val, unsigned);
23179
+ return Long.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
23180
+ }
23181
+ add(addend) {
23182
+ if (!Long.isLong(addend))
23183
+ addend = Long.fromValue(addend);
23184
+ const a48 = this.high >>> 16;
23185
+ const a32 = this.high & 0xffff;
23186
+ const a16 = this.low >>> 16;
23187
+ const a00 = this.low & 0xffff;
23188
+ const b48 = addend.high >>> 16;
23189
+ const b32 = addend.high & 0xffff;
23190
+ const b16 = addend.low >>> 16;
23191
+ const b00 = addend.low & 0xffff;
23192
+ let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
23193
+ c00 += a00 + b00;
23194
+ c16 += c00 >>> 16;
23195
+ c00 &= 0xffff;
23196
+ c16 += a16 + b16;
23197
+ c32 += c16 >>> 16;
23198
+ c16 &= 0xffff;
23199
+ c32 += a32 + b32;
23200
+ c48 += c32 >>> 16;
23201
+ c32 &= 0xffff;
23202
+ c48 += a48 + b48;
23203
+ c48 &= 0xffff;
23204
+ return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
23205
+ }
23206
+ and(other) {
23207
+ if (!Long.isLong(other))
23208
+ other = Long.fromValue(other);
23209
+ return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
23210
+ }
23211
+ compare(other) {
23212
+ if (!Long.isLong(other))
23213
+ other = Long.fromValue(other);
23214
+ if (this.eq(other))
23215
+ return 0;
23216
+ const thisNeg = this.isNegative(), otherNeg = other.isNegative();
23217
+ if (thisNeg && !otherNeg)
23218
+ return -1;
23219
+ if (!thisNeg && otherNeg)
23220
+ return 1;
23221
+ if (!this.unsigned)
23222
+ return this.sub(other).isNegative() ? -1 : 1;
23223
+ return other.high >>> 0 > this.high >>> 0 ||
23224
+ (other.high === this.high && other.low >>> 0 > this.low >>> 0)
23225
+ ? -1
23226
+ : 1;
23227
+ }
23228
+ comp(other) {
23229
+ return this.compare(other);
23230
+ }
23231
+ divide(divisor) {
23232
+ if (!Long.isLong(divisor))
23233
+ divisor = Long.fromValue(divisor);
23234
+ if (divisor.isZero())
23235
+ throw new BSONError('division by zero');
23236
+ if (wasm) {
23237
+ if (!this.unsigned &&
23238
+ this.high === -2147483648 &&
23239
+ divisor.low === -1 &&
23240
+ divisor.high === -1) {
23241
+ return this;
23242
+ }
23243
+ const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
23244
+ return Long.fromBits(low, wasm.get_high(), this.unsigned);
23245
+ }
23246
+ if (this.isZero())
23247
+ return this.unsigned ? Long.UZERO : Long.ZERO;
23248
+ let approx, rem, res;
23249
+ if (!this.unsigned) {
23250
+ if (this.eq(Long.MIN_VALUE)) {
23251
+ if (divisor.eq(Long.ONE) || divisor.eq(Long.NEG_ONE))
23252
+ return Long.MIN_VALUE;
23253
+ else if (divisor.eq(Long.MIN_VALUE))
23254
+ return Long.ONE;
23255
+ else {
23256
+ const halfThis = this.shr(1);
23257
+ approx = halfThis.div(divisor).shl(1);
23258
+ if (approx.eq(Long.ZERO)) {
23259
+ return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
23260
+ }
23261
+ else {
23262
+ rem = this.sub(divisor.mul(approx));
23263
+ res = approx.add(rem.div(divisor));
23264
+ return res;
23265
+ }
23266
+ }
23267
+ }
23268
+ else if (divisor.eq(Long.MIN_VALUE))
23269
+ return this.unsigned ? Long.UZERO : Long.ZERO;
23270
+ if (this.isNegative()) {
23271
+ if (divisor.isNegative())
23272
+ return this.neg().div(divisor.neg());
23273
+ return this.neg().div(divisor).neg();
23274
+ }
23275
+ else if (divisor.isNegative())
23276
+ return this.div(divisor.neg()).neg();
23277
+ res = Long.ZERO;
23278
+ }
23279
+ else {
23280
+ if (!divisor.unsigned)
23281
+ divisor = divisor.toUnsigned();
23282
+ if (divisor.gt(this))
23283
+ return Long.UZERO;
23284
+ if (divisor.gt(this.shru(1)))
23285
+ return Long.UONE;
23286
+ res = Long.UZERO;
23287
+ }
23288
+ rem = this;
23289
+ while (rem.gte(divisor)) {
23290
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
23291
+ const log2 = Math.ceil(Math.log(approx) / Math.LN2);
23292
+ const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
23293
+ let approxRes = Long.fromNumber(approx);
23294
+ let approxRem = approxRes.mul(divisor);
23295
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
23296
+ approx -= delta;
23297
+ approxRes = Long.fromNumber(approx, this.unsigned);
23298
+ approxRem = approxRes.mul(divisor);
23299
+ }
23300
+ if (approxRes.isZero())
23301
+ approxRes = Long.ONE;
23302
+ res = res.add(approxRes);
23303
+ rem = rem.sub(approxRem);
23304
+ }
23305
+ return res;
23306
+ }
23307
+ div(divisor) {
23308
+ return this.divide(divisor);
23309
+ }
23310
+ equals(other) {
23311
+ if (!Long.isLong(other))
23312
+ other = Long.fromValue(other);
23313
+ if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
23314
+ return false;
23315
+ return this.high === other.high && this.low === other.low;
23316
+ }
23317
+ eq(other) {
23318
+ return this.equals(other);
23319
+ }
23320
+ getHighBits() {
23321
+ return this.high;
23322
+ }
23323
+ getHighBitsUnsigned() {
23324
+ return this.high >>> 0;
23325
+ }
23326
+ getLowBits() {
23327
+ return this.low;
23328
+ }
23329
+ getLowBitsUnsigned() {
23330
+ return this.low >>> 0;
23331
+ }
23332
+ getNumBitsAbs() {
23333
+ if (this.isNegative()) {
23334
+ return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
23335
+ }
23336
+ const val = this.high !== 0 ? this.high : this.low;
23337
+ let bit;
23338
+ for (bit = 31; bit > 0; bit--)
23339
+ if ((val & (1 << bit)) !== 0)
23340
+ break;
23341
+ return this.high !== 0 ? bit + 33 : bit + 1;
23342
+ }
23343
+ greaterThan(other) {
23344
+ return this.comp(other) > 0;
23345
+ }
23346
+ gt(other) {
23347
+ return this.greaterThan(other);
23348
+ }
23349
+ greaterThanOrEqual(other) {
23350
+ return this.comp(other) >= 0;
23351
+ }
23352
+ gte(other) {
23353
+ return this.greaterThanOrEqual(other);
23354
+ }
23355
+ ge(other) {
23356
+ return this.greaterThanOrEqual(other);
23357
+ }
23358
+ isEven() {
23359
+ return (this.low & 1) === 0;
23360
+ }
23361
+ isNegative() {
23362
+ return !this.unsigned && this.high < 0;
23363
+ }
23364
+ isOdd() {
23365
+ return (this.low & 1) === 1;
23366
+ }
23367
+ isPositive() {
23368
+ return this.unsigned || this.high >= 0;
23369
+ }
23370
+ isZero() {
23371
+ return this.high === 0 && this.low === 0;
23372
+ }
23373
+ lessThan(other) {
23374
+ return this.comp(other) < 0;
23375
+ }
23376
+ lt(other) {
23377
+ return this.lessThan(other);
23378
+ }
23379
+ lessThanOrEqual(other) {
23380
+ return this.comp(other) <= 0;
23381
+ }
23382
+ lte(other) {
23383
+ return this.lessThanOrEqual(other);
23384
+ }
23385
+ modulo(divisor) {
23386
+ if (!Long.isLong(divisor))
23387
+ divisor = Long.fromValue(divisor);
23388
+ if (wasm) {
23389
+ const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
23390
+ return Long.fromBits(low, wasm.get_high(), this.unsigned);
23391
+ }
23392
+ return this.sub(this.div(divisor).mul(divisor));
23393
+ }
23394
+ mod(divisor) {
23395
+ return this.modulo(divisor);
23396
+ }
23397
+ rem(divisor) {
23398
+ return this.modulo(divisor);
23399
+ }
23400
+ multiply(multiplier) {
23401
+ if (this.isZero())
23402
+ return Long.ZERO;
23403
+ if (!Long.isLong(multiplier))
23404
+ multiplier = Long.fromValue(multiplier);
23405
+ if (wasm) {
23406
+ const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
23407
+ return Long.fromBits(low, wasm.get_high(), this.unsigned);
23408
+ }
23409
+ if (multiplier.isZero())
23410
+ return Long.ZERO;
23411
+ if (this.eq(Long.MIN_VALUE))
23412
+ return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO;
23413
+ if (multiplier.eq(Long.MIN_VALUE))
23414
+ return this.isOdd() ? Long.MIN_VALUE : Long.ZERO;
23415
+ if (this.isNegative()) {
23416
+ if (multiplier.isNegative())
23417
+ return this.neg().mul(multiplier.neg());
23418
+ else
23419
+ return this.neg().mul(multiplier).neg();
23420
+ }
23421
+ else if (multiplier.isNegative())
23422
+ return this.mul(multiplier.neg()).neg();
23423
+ if (this.lt(Long.TWO_PWR_24) && multiplier.lt(Long.TWO_PWR_24))
23424
+ return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
23425
+ const a48 = this.high >>> 16;
23426
+ const a32 = this.high & 0xffff;
23427
+ const a16 = this.low >>> 16;
23428
+ const a00 = this.low & 0xffff;
23429
+ const b48 = multiplier.high >>> 16;
23430
+ const b32 = multiplier.high & 0xffff;
23431
+ const b16 = multiplier.low >>> 16;
23432
+ const b00 = multiplier.low & 0xffff;
23433
+ let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
23434
+ c00 += a00 * b00;
23435
+ c16 += c00 >>> 16;
23436
+ c00 &= 0xffff;
23437
+ c16 += a16 * b00;
23438
+ c32 += c16 >>> 16;
23439
+ c16 &= 0xffff;
23440
+ c16 += a00 * b16;
23441
+ c32 += c16 >>> 16;
23442
+ c16 &= 0xffff;
23443
+ c32 += a32 * b00;
23444
+ c48 += c32 >>> 16;
23445
+ c32 &= 0xffff;
23446
+ c32 += a16 * b16;
23447
+ c48 += c32 >>> 16;
23448
+ c32 &= 0xffff;
23449
+ c32 += a00 * b32;
23450
+ c48 += c32 >>> 16;
23451
+ c32 &= 0xffff;
23452
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
23453
+ c48 &= 0xffff;
23454
+ return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
23455
+ }
23456
+ mul(multiplier) {
23457
+ return this.multiply(multiplier);
23458
+ }
23459
+ negate() {
23460
+ if (!this.unsigned && this.eq(Long.MIN_VALUE))
23461
+ return Long.MIN_VALUE;
23462
+ return this.not().add(Long.ONE);
23463
+ }
23464
+ neg() {
23465
+ return this.negate();
23466
+ }
23467
+ not() {
23468
+ return Long.fromBits(~this.low, ~this.high, this.unsigned);
23469
+ }
23470
+ notEquals(other) {
23471
+ return !this.equals(other);
23472
+ }
23473
+ neq(other) {
23474
+ return this.notEquals(other);
23475
+ }
23476
+ ne(other) {
23477
+ return this.notEquals(other);
23478
+ }
23479
+ or(other) {
23480
+ if (!Long.isLong(other))
23481
+ other = Long.fromValue(other);
23482
+ return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
23483
+ }
23484
+ shiftLeft(numBits) {
23485
+ if (Long.isLong(numBits))
23486
+ numBits = numBits.toInt();
23487
+ if ((numBits &= 63) === 0)
23488
+ return this;
23489
+ else if (numBits < 32)
23490
+ return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
23491
+ else
23492
+ return Long.fromBits(0, this.low << (numBits - 32), this.unsigned);
23493
+ }
23494
+ shl(numBits) {
23495
+ return this.shiftLeft(numBits);
23496
+ }
23497
+ shiftRight(numBits) {
23498
+ if (Long.isLong(numBits))
23499
+ numBits = numBits.toInt();
23500
+ if ((numBits &= 63) === 0)
23501
+ return this;
23502
+ else if (numBits < 32)
23503
+ return Long.fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
23504
+ else
23505
+ return Long.fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
23506
+ }
23507
+ shr(numBits) {
23508
+ return this.shiftRight(numBits);
23509
+ }
23510
+ shiftRightUnsigned(numBits) {
23511
+ if (Long.isLong(numBits))
23512
+ numBits = numBits.toInt();
23513
+ numBits &= 63;
23514
+ if (numBits === 0)
23515
+ return this;
23516
+ else {
23517
+ const high = this.high;
23518
+ if (numBits < 32) {
23519
+ const low = this.low;
23520
+ return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
23521
+ }
23522
+ else if (numBits === 32)
23523
+ return Long.fromBits(high, 0, this.unsigned);
23524
+ else
23525
+ return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned);
23526
+ }
23527
+ }
23528
+ shr_u(numBits) {
23529
+ return this.shiftRightUnsigned(numBits);
23530
+ }
23531
+ shru(numBits) {
23532
+ return this.shiftRightUnsigned(numBits);
23533
+ }
23534
+ subtract(subtrahend) {
23535
+ if (!Long.isLong(subtrahend))
23536
+ subtrahend = Long.fromValue(subtrahend);
23537
+ return this.add(subtrahend.neg());
23538
+ }
23539
+ sub(subtrahend) {
23540
+ return this.subtract(subtrahend);
23541
+ }
23542
+ toInt() {
23543
+ return this.unsigned ? this.low >>> 0 : this.low;
23544
+ }
23545
+ toNumber() {
23546
+ if (this.unsigned)
23547
+ return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
23548
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
23549
+ }
23550
+ toBigInt() {
23551
+ return BigInt(this.toString());
23552
+ }
23553
+ toBytes(le) {
23554
+ return le ? this.toBytesLE() : this.toBytesBE();
23555
+ }
23556
+ toBytesLE() {
23557
+ const hi = this.high, lo = this.low;
23558
+ return [
23559
+ lo & 0xff,
23560
+ (lo >>> 8) & 0xff,
23561
+ (lo >>> 16) & 0xff,
23562
+ lo >>> 24,
23563
+ hi & 0xff,
23564
+ (hi >>> 8) & 0xff,
23565
+ (hi >>> 16) & 0xff,
23566
+ hi >>> 24
23567
+ ];
23568
+ }
23569
+ toBytesBE() {
23570
+ const hi = this.high, lo = this.low;
23571
+ return [
23572
+ hi >>> 24,
23573
+ (hi >>> 16) & 0xff,
23574
+ (hi >>> 8) & 0xff,
23575
+ hi & 0xff,
23576
+ lo >>> 24,
23577
+ (lo >>> 16) & 0xff,
23578
+ (lo >>> 8) & 0xff,
23579
+ lo & 0xff
23580
+ ];
23581
+ }
23582
+ toSigned() {
23583
+ if (!this.unsigned)
23584
+ return this;
23585
+ return Long.fromBits(this.low, this.high, false);
23586
+ }
23587
+ toString(radix) {
23588
+ radix = radix || 10;
23589
+ if (radix < 2 || 36 < radix)
23590
+ throw new BSONError('radix');
23591
+ if (this.isZero())
23592
+ return '0';
23593
+ if (this.isNegative()) {
23594
+ if (this.eq(Long.MIN_VALUE)) {
23595
+ const radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
23596
+ return div.toString(radix) + rem1.toInt().toString(radix);
23597
+ }
23598
+ else
23599
+ return '-' + this.neg().toString(radix);
23600
+ }
23601
+ const radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
23602
+ let rem = this;
23603
+ let result = '';
23604
+ while (true) {
23605
+ const remDiv = rem.div(radixToPower);
23606
+ const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
23607
+ let digits = intval.toString(radix);
23608
+ rem = remDiv;
23609
+ if (rem.isZero()) {
23610
+ return digits + result;
23611
+ }
23612
+ else {
23613
+ while (digits.length < 6)
23614
+ digits = '0' + digits;
23615
+ result = '' + digits + result;
23616
+ }
23617
+ }
23618
+ }
23619
+ toUnsigned() {
23620
+ if (this.unsigned)
23621
+ return this;
23622
+ return Long.fromBits(this.low, this.high, true);
23623
+ }
23624
+ xor(other) {
23625
+ if (!Long.isLong(other))
23626
+ other = Long.fromValue(other);
23627
+ return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
23628
+ }
23629
+ eqz() {
23630
+ return this.isZero();
23631
+ }
23632
+ le(other) {
23633
+ return this.lessThanOrEqual(other);
23634
+ }
23635
+ toExtendedJSON(options) {
23636
+ if (options && options.relaxed)
23637
+ return this.toNumber();
23638
+ return { $numberLong: this.toString() };
23639
+ }
23640
+ static fromExtendedJSON(doc, options) {
23641
+ const { useBigInt64 = false, relaxed = true } = { ...options };
23642
+ if (doc.$numberLong.length > MAX_INT64_STRING_LENGTH) {
23643
+ throw new BSONError('$numberLong string is too long');
23644
+ }
23645
+ if (!DECIMAL_REG_EX.test(doc.$numberLong)) {
23646
+ throw new BSONError(`$numberLong string "${doc.$numberLong}" is in an invalid format`);
23647
+ }
23648
+ if (useBigInt64) {
23649
+ const bigIntResult = BigInt(doc.$numberLong);
23650
+ return BigInt.asIntN(64, bigIntResult);
23651
+ }
23652
+ const longResult = Long.fromString(doc.$numberLong);
23653
+ if (relaxed) {
23654
+ return longResult.toNumber();
23655
+ }
23656
+ return longResult;
23657
+ }
23658
+ inspect(depth, options, inspect) {
23659
+ inspect ??= defaultInspect;
23660
+ const longVal = inspect(this.toString(), options);
23661
+ const unsignedVal = this.unsigned ? `, ${inspect(this.unsigned, options)}` : '';
23662
+ return `new Long(${longVal}${unsignedVal})`;
23663
+ }
23664
+ }
23665
+ Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
23666
+ Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
23667
+ Long.ZERO = Long.fromInt(0);
23668
+ Long.UZERO = Long.fromInt(0, true);
23669
+ Long.ONE = Long.fromInt(1);
23670
+ Long.UONE = Long.fromInt(1, true);
23671
+ Long.NEG_ONE = Long.fromInt(-1);
23672
+ Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
23673
+ Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
23674
+
23675
+ const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
23676
+ const PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
23677
+ const PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
23678
+ const EXPONENT_MAX = 6111;
23679
+ const EXPONENT_MIN = -6176;
23680
+ const EXPONENT_BIAS = 6176;
23681
+ const MAX_DIGITS = 34;
23682
+ const NAN_BUFFER = ByteUtils.fromNumberArray([
23683
+ 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
23684
+ ].reverse());
23685
+ const INF_NEGATIVE_BUFFER = ByteUtils.fromNumberArray([
23686
+ 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
23687
+ ].reverse());
23688
+ const INF_POSITIVE_BUFFER = ByteUtils.fromNumberArray([
23689
+ 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
23690
+ ].reverse());
23691
+ const EXPONENT_REGEX = /^([-+])?(\d+)?$/;
23692
+ const COMBINATION_MASK = 0x1f;
23693
+ const EXPONENT_MASK = 0x3fff;
23694
+ const COMBINATION_INFINITY = 30;
23695
+ const COMBINATION_NAN = 31;
23696
+ function isDigit(value) {
23697
+ return !isNaN(parseInt(value, 10));
23698
+ }
23699
+ function divideu128(value) {
23700
+ const DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
23701
+ let _rem = Long.fromNumber(0);
23702
+ if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
23703
+ return { quotient: value, rem: _rem };
23704
+ }
23705
+ for (let i = 0; i <= 3; i++) {
23706
+ _rem = _rem.shiftLeft(32);
23707
+ _rem = _rem.add(new Long(value.parts[i], 0));
23708
+ value.parts[i] = _rem.div(DIVISOR).low;
23709
+ _rem = _rem.modulo(DIVISOR);
23710
+ }
23711
+ return { quotient: value, rem: _rem };
23712
+ }
23713
+ function multiply64x2(left, right) {
23714
+ if (!left && !right) {
23715
+ return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
23716
+ }
23717
+ const leftHigh = left.shiftRightUnsigned(32);
23718
+ const leftLow = new Long(left.getLowBits(), 0);
23719
+ const rightHigh = right.shiftRightUnsigned(32);
23720
+ const rightLow = new Long(right.getLowBits(), 0);
23721
+ let productHigh = leftHigh.multiply(rightHigh);
23722
+ let productMid = leftHigh.multiply(rightLow);
23723
+ const productMid2 = leftLow.multiply(rightHigh);
23724
+ let productLow = leftLow.multiply(rightLow);
23725
+ productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
23726
+ productMid = new Long(productMid.getLowBits(), 0)
23727
+ .add(productMid2)
23728
+ .add(productLow.shiftRightUnsigned(32));
23729
+ productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
23730
+ productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
23731
+ return { high: productHigh, low: productLow };
23732
+ }
23733
+ function lessThan(left, right) {
23734
+ const uhleft = left.high >>> 0;
23735
+ const uhright = right.high >>> 0;
23736
+ if (uhleft < uhright) {
23737
+ return true;
23738
+ }
23739
+ else if (uhleft === uhright) {
23740
+ const ulleft = left.low >>> 0;
23741
+ const ulright = right.low >>> 0;
23742
+ if (ulleft < ulright)
23743
+ return true;
23744
+ }
23745
+ return false;
23746
+ }
23747
+ function invalidErr(string, message) {
23748
+ throw new BSONError(`"${string}" is not a valid Decimal128 string - ${message}`);
23749
+ }
23750
+ class Decimal128 extends BSONValue {
23751
+ get _bsontype() {
23752
+ return 'Decimal128';
23753
+ }
23754
+ constructor(bytes) {
23755
+ super();
23756
+ if (typeof bytes === 'string') {
23757
+ this.bytes = Decimal128.fromString(bytes).bytes;
23758
+ }
23759
+ else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
23760
+ if (bytes.byteLength !== 16) {
23761
+ throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
23762
+ }
23763
+ this.bytes = bytes;
23764
+ }
23765
+ else {
23766
+ throw new BSONError('Decimal128 must take a Buffer or string');
23767
+ }
23768
+ }
23769
+ static fromString(representation) {
23770
+ return Decimal128._fromString(representation, { allowRounding: false });
23771
+ }
23772
+ static fromStringWithRounding(representation) {
23773
+ return Decimal128._fromString(representation, { allowRounding: true });
23774
+ }
23775
+ static _fromString(representation, options) {
23776
+ let isNegative = false;
23777
+ let sawSign = false;
23778
+ let sawRadix = false;
23779
+ let foundNonZero = false;
23780
+ let significantDigits = 0;
23781
+ let nDigitsRead = 0;
23782
+ let nDigits = 0;
23783
+ let radixPosition = 0;
23784
+ let firstNonZero = 0;
23785
+ const digits = [0];
23786
+ let nDigitsStored = 0;
23787
+ let digitsInsert = 0;
23788
+ let lastDigit = 0;
23789
+ let exponent = 0;
23790
+ let significandHigh = new Long(0, 0);
23791
+ let significandLow = new Long(0, 0);
23792
+ let biasedExponent = 0;
23793
+ let index = 0;
23794
+ if (representation.length >= 7000) {
23795
+ throw new BSONError('' + representation + ' not a valid Decimal128 string');
23796
+ }
23797
+ const stringMatch = representation.match(PARSE_STRING_REGEXP);
23798
+ const infMatch = representation.match(PARSE_INF_REGEXP);
23799
+ const nanMatch = representation.match(PARSE_NAN_REGEXP);
23800
+ if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) {
23801
+ throw new BSONError('' + representation + ' not a valid Decimal128 string');
23802
+ }
23803
+ if (stringMatch) {
23804
+ const unsignedNumber = stringMatch[2];
23805
+ const e = stringMatch[4];
23806
+ const expSign = stringMatch[5];
23807
+ const expNumber = stringMatch[6];
23808
+ if (e && expNumber === undefined)
23809
+ invalidErr(representation, 'missing exponent power');
23810
+ if (e && unsignedNumber === undefined)
23811
+ invalidErr(representation, 'missing exponent base');
23812
+ if (e === undefined && (expSign || expNumber)) {
23813
+ invalidErr(representation, 'missing e before exponent');
23814
+ }
23815
+ }
23816
+ if (representation[index] === '+' || representation[index] === '-') {
23817
+ sawSign = true;
23818
+ isNegative = representation[index++] === '-';
23819
+ }
23820
+ if (!isDigit(representation[index]) && representation[index] !== '.') {
23821
+ if (representation[index] === 'i' || representation[index] === 'I') {
23822
+ return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
23823
+ }
23824
+ else if (representation[index] === 'N') {
23825
+ return new Decimal128(NAN_BUFFER);
23826
+ }
23827
+ }
23828
+ while (isDigit(representation[index]) || representation[index] === '.') {
23829
+ if (representation[index] === '.') {
23830
+ if (sawRadix)
23831
+ invalidErr(representation, 'contains multiple periods');
23832
+ sawRadix = true;
23833
+ index = index + 1;
23834
+ continue;
23835
+ }
23836
+ if (nDigitsStored < MAX_DIGITS) {
23837
+ if (representation[index] !== '0' || foundNonZero) {
23838
+ if (!foundNonZero) {
23839
+ firstNonZero = nDigitsRead;
23840
+ }
23841
+ foundNonZero = true;
23842
+ digits[digitsInsert++] = parseInt(representation[index], 10);
23843
+ nDigitsStored = nDigitsStored + 1;
23844
+ }
23845
+ }
23846
+ if (foundNonZero)
23847
+ nDigits = nDigits + 1;
23848
+ if (sawRadix)
23849
+ radixPosition = radixPosition + 1;
23850
+ nDigitsRead = nDigitsRead + 1;
23851
+ index = index + 1;
23852
+ }
23853
+ if (sawRadix && !nDigitsRead)
23854
+ throw new BSONError('' + representation + ' not a valid Decimal128 string');
23855
+ if (representation[index] === 'e' || representation[index] === 'E') {
23856
+ const match = representation.substr(++index).match(EXPONENT_REGEX);
23857
+ if (!match || !match[2])
23858
+ return new Decimal128(NAN_BUFFER);
23859
+ exponent = parseInt(match[0], 10);
23860
+ index = index + match[0].length;
23861
+ }
23862
+ if (representation[index])
23863
+ return new Decimal128(NAN_BUFFER);
23864
+ if (!nDigitsStored) {
23865
+ digits[0] = 0;
23866
+ nDigits = 1;
23867
+ nDigitsStored = 1;
23868
+ significantDigits = 0;
23869
+ }
23870
+ else {
23871
+ lastDigit = nDigitsStored - 1;
23872
+ significantDigits = nDigits;
23873
+ if (significantDigits !== 1) {
23874
+ while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === '0') {
23875
+ significantDigits = significantDigits - 1;
23876
+ }
23877
+ }
23878
+ }
23879
+ if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
23880
+ exponent = EXPONENT_MIN;
23881
+ }
23882
+ else {
23883
+ exponent = exponent - radixPosition;
23884
+ }
23885
+ while (exponent > EXPONENT_MAX) {
23886
+ lastDigit = lastDigit + 1;
23887
+ if (lastDigit >= MAX_DIGITS) {
23888
+ if (significantDigits === 0) {
23889
+ exponent = EXPONENT_MAX;
23890
+ break;
23891
+ }
23892
+ invalidErr(representation, 'overflow');
23893
+ }
23894
+ exponent = exponent - 1;
23895
+ }
23896
+ if (options.allowRounding) {
23897
+ while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
23898
+ if (lastDigit === 0 && significantDigits < nDigitsStored) {
23899
+ exponent = EXPONENT_MIN;
23900
+ significantDigits = 0;
23901
+ break;
23902
+ }
23903
+ if (nDigitsStored < nDigits) {
23904
+ nDigits = nDigits - 1;
23905
+ }
23906
+ else {
23907
+ lastDigit = lastDigit - 1;
23908
+ }
23909
+ if (exponent < EXPONENT_MAX) {
23910
+ exponent = exponent + 1;
23911
+ }
23912
+ else {
23913
+ const digitsString = digits.join('');
23914
+ if (digitsString.match(/^0+$/)) {
23915
+ exponent = EXPONENT_MAX;
23916
+ break;
23917
+ }
23918
+ invalidErr(representation, 'overflow');
23919
+ }
23920
+ }
23921
+ if (lastDigit + 1 < significantDigits) {
23922
+ let endOfString = nDigitsRead;
23923
+ if (sawRadix) {
23924
+ firstNonZero = firstNonZero + 1;
23925
+ endOfString = endOfString + 1;
23926
+ }
23927
+ if (sawSign) {
23928
+ firstNonZero = firstNonZero + 1;
23929
+ endOfString = endOfString + 1;
23930
+ }
23931
+ const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
23932
+ let roundBit = 0;
23933
+ if (roundDigit >= 5) {
23934
+ roundBit = 1;
23935
+ if (roundDigit === 5) {
23936
+ roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
23937
+ for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
23938
+ if (parseInt(representation[i], 10)) {
23939
+ roundBit = 1;
23940
+ break;
23941
+ }
23942
+ }
23943
+ }
23944
+ }
23945
+ if (roundBit) {
23946
+ let dIdx = lastDigit;
23947
+ for (; dIdx >= 0; dIdx--) {
23948
+ if (++digits[dIdx] > 9) {
23949
+ digits[dIdx] = 0;
23950
+ if (dIdx === 0) {
23951
+ if (exponent < EXPONENT_MAX) {
23952
+ exponent = exponent + 1;
23953
+ digits[dIdx] = 1;
23954
+ }
23955
+ else {
23956
+ return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
23957
+ }
23958
+ }
23959
+ }
23960
+ else {
23961
+ break;
23962
+ }
23963
+ }
23964
+ }
23965
+ }
23966
+ }
23967
+ else {
23968
+ while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
23969
+ if (lastDigit === 0) {
23970
+ if (significantDigits === 0) {
23971
+ exponent = EXPONENT_MIN;
23972
+ break;
23973
+ }
23974
+ invalidErr(representation, 'exponent underflow');
23975
+ }
23976
+ if (nDigitsStored < nDigits) {
23977
+ if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
23978
+ significantDigits !== 0) {
23979
+ invalidErr(representation, 'inexact rounding');
23980
+ }
23981
+ nDigits = nDigits - 1;
23982
+ }
23983
+ else {
23984
+ if (digits[lastDigit] !== 0) {
23985
+ invalidErr(representation, 'inexact rounding');
23986
+ }
23987
+ lastDigit = lastDigit - 1;
23988
+ }
23989
+ if (exponent < EXPONENT_MAX) {
23990
+ exponent = exponent + 1;
23991
+ }
23992
+ else {
23993
+ invalidErr(representation, 'overflow');
23994
+ }
23995
+ }
23996
+ if (lastDigit + 1 < significantDigits) {
23997
+ if (sawRadix) {
23998
+ firstNonZero = firstNonZero + 1;
23999
+ }
24000
+ if (sawSign) {
24001
+ firstNonZero = firstNonZero + 1;
24002
+ }
24003
+ const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
24004
+ if (roundDigit !== 0) {
24005
+ invalidErr(representation, 'inexact rounding');
24006
+ }
24007
+ }
24008
+ }
24009
+ significandHigh = Long.fromNumber(0);
24010
+ significandLow = Long.fromNumber(0);
24011
+ if (significantDigits === 0) {
24012
+ significandHigh = Long.fromNumber(0);
24013
+ significandLow = Long.fromNumber(0);
24014
+ }
24015
+ else if (lastDigit < 17) {
24016
+ let dIdx = 0;
24017
+ significandLow = Long.fromNumber(digits[dIdx++]);
24018
+ significandHigh = new Long(0, 0);
24019
+ for (; dIdx <= lastDigit; dIdx++) {
24020
+ significandLow = significandLow.multiply(Long.fromNumber(10));
24021
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
24022
+ }
24023
+ }
24024
+ else {
24025
+ let dIdx = 0;
24026
+ significandHigh = Long.fromNumber(digits[dIdx++]);
24027
+ for (; dIdx <= lastDigit - 17; dIdx++) {
24028
+ significandHigh = significandHigh.multiply(Long.fromNumber(10));
24029
+ significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
24030
+ }
24031
+ significandLow = Long.fromNumber(digits[dIdx++]);
24032
+ for (; dIdx <= lastDigit; dIdx++) {
24033
+ significandLow = significandLow.multiply(Long.fromNumber(10));
24034
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
24035
+ }
24036
+ }
24037
+ const significand = multiply64x2(significandHigh, Long.fromString('100000000000000000'));
24038
+ significand.low = significand.low.add(significandLow);
24039
+ if (lessThan(significand.low, significandLow)) {
24040
+ significand.high = significand.high.add(Long.fromNumber(1));
24041
+ }
24042
+ biasedExponent = exponent + EXPONENT_BIAS;
24043
+ const dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
24044
+ if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
24045
+ dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61));
24046
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47)));
24047
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff)));
24048
+ }
24049
+ else {
24050
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
24051
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff)));
24052
+ }
24053
+ dec.low = significand.low;
24054
+ if (isNegative) {
24055
+ dec.high = dec.high.or(Long.fromString('9223372036854775808'));
24056
+ }
24057
+ const buffer = ByteUtils.allocateUnsafe(16);
24058
+ index = 0;
24059
+ buffer[index++] = dec.low.low & 0xff;
24060
+ buffer[index++] = (dec.low.low >> 8) & 0xff;
24061
+ buffer[index++] = (dec.low.low >> 16) & 0xff;
24062
+ buffer[index++] = (dec.low.low >> 24) & 0xff;
24063
+ buffer[index++] = dec.low.high & 0xff;
24064
+ buffer[index++] = (dec.low.high >> 8) & 0xff;
24065
+ buffer[index++] = (dec.low.high >> 16) & 0xff;
24066
+ buffer[index++] = (dec.low.high >> 24) & 0xff;
24067
+ buffer[index++] = dec.high.low & 0xff;
24068
+ buffer[index++] = (dec.high.low >> 8) & 0xff;
24069
+ buffer[index++] = (dec.high.low >> 16) & 0xff;
24070
+ buffer[index++] = (dec.high.low >> 24) & 0xff;
24071
+ buffer[index++] = dec.high.high & 0xff;
24072
+ buffer[index++] = (dec.high.high >> 8) & 0xff;
24073
+ buffer[index++] = (dec.high.high >> 16) & 0xff;
24074
+ buffer[index++] = (dec.high.high >> 24) & 0xff;
24075
+ return new Decimal128(buffer);
24076
+ }
24077
+ toString() {
24078
+ let biased_exponent;
24079
+ let significand_digits = 0;
24080
+ const significand = new Array(36);
24081
+ for (let i = 0; i < significand.length; i++)
24082
+ significand[i] = 0;
24083
+ let index = 0;
24084
+ let is_zero = false;
24085
+ let significand_msb;
24086
+ let significand128 = { parts: [0, 0, 0, 0] };
24087
+ let j, k;
24088
+ const string = [];
24089
+ index = 0;
24090
+ const buffer = this.bytes;
24091
+ const low = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24092
+ const midl = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24093
+ const midh = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24094
+ const high = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
24095
+ index = 0;
24096
+ const dec = {
24097
+ low: new Long(low, midl),
24098
+ high: new Long(midh, high)
24099
+ };
24100
+ if (dec.high.lessThan(Long.ZERO)) {
24101
+ string.push('-');
24102
+ }
24103
+ const combination = (high >> 26) & COMBINATION_MASK;
24104
+ if (combination >> 3 === 3) {
24105
+ if (combination === COMBINATION_INFINITY) {
24106
+ return string.join('') + 'Infinity';
24107
+ }
24108
+ else if (combination === COMBINATION_NAN) {
24109
+ return 'NaN';
24110
+ }
24111
+ else {
24112
+ biased_exponent = (high >> 15) & EXPONENT_MASK;
24113
+ significand_msb = 0x08 + ((high >> 14) & 0x01);
24114
+ }
24115
+ }
24116
+ else {
24117
+ significand_msb = (high >> 14) & 0x07;
24118
+ biased_exponent = (high >> 17) & EXPONENT_MASK;
24119
+ }
24120
+ const exponent = biased_exponent - EXPONENT_BIAS;
24121
+ significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14);
24122
+ significand128.parts[1] = midh;
24123
+ significand128.parts[2] = midl;
24124
+ significand128.parts[3] = low;
24125
+ if (significand128.parts[0] === 0 &&
24126
+ significand128.parts[1] === 0 &&
24127
+ significand128.parts[2] === 0 &&
24128
+ significand128.parts[3] === 0) {
24129
+ is_zero = true;
24130
+ }
24131
+ else {
24132
+ for (k = 3; k >= 0; k--) {
24133
+ let least_digits = 0;
24134
+ const result = divideu128(significand128);
24135
+ significand128 = result.quotient;
24136
+ least_digits = result.rem.low;
24137
+ if (!least_digits)
24138
+ continue;
24139
+ for (j = 8; j >= 0; j--) {
24140
+ significand[k * 9 + j] = least_digits % 10;
24141
+ least_digits = Math.floor(least_digits / 10);
24142
+ }
24143
+ }
24144
+ }
24145
+ if (is_zero) {
24146
+ significand_digits = 1;
24147
+ significand[index] = 0;
24148
+ }
24149
+ else {
24150
+ significand_digits = 36;
24151
+ while (!significand[index]) {
24152
+ significand_digits = significand_digits - 1;
24153
+ index = index + 1;
24154
+ }
24155
+ }
24156
+ const scientific_exponent = significand_digits - 1 + exponent;
24157
+ if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
24158
+ if (significand_digits > 34) {
24159
+ string.push(`${0}`);
24160
+ if (exponent > 0)
24161
+ string.push(`E+${exponent}`);
24162
+ else if (exponent < 0)
24163
+ string.push(`E${exponent}`);
24164
+ return string.join('');
24165
+ }
24166
+ string.push(`${significand[index++]}`);
24167
+ significand_digits = significand_digits - 1;
24168
+ if (significand_digits) {
24169
+ string.push('.');
24170
+ }
24171
+ for (let i = 0; i < significand_digits; i++) {
24172
+ string.push(`${significand[index++]}`);
24173
+ }
24174
+ string.push('E');
24175
+ if (scientific_exponent > 0) {
24176
+ string.push(`+${scientific_exponent}`);
24177
+ }
24178
+ else {
24179
+ string.push(`${scientific_exponent}`);
24180
+ }
24181
+ }
24182
+ else {
24183
+ if (exponent >= 0) {
24184
+ for (let i = 0; i < significand_digits; i++) {
24185
+ string.push(`${significand[index++]}`);
24186
+ }
24187
+ }
24188
+ else {
24189
+ let radix_position = significand_digits + exponent;
24190
+ if (radix_position > 0) {
24191
+ for (let i = 0; i < radix_position; i++) {
24192
+ string.push(`${significand[index++]}`);
24193
+ }
24194
+ }
24195
+ else {
24196
+ string.push('0');
24197
+ }
24198
+ string.push('.');
24199
+ while (radix_position++ < 0) {
24200
+ string.push('0');
24201
+ }
24202
+ for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
24203
+ string.push(`${significand[index++]}`);
24204
+ }
24205
+ }
24206
+ }
24207
+ return string.join('');
24208
+ }
24209
+ toJSON() {
24210
+ return { $numberDecimal: this.toString() };
24211
+ }
24212
+ toExtendedJSON() {
24213
+ return { $numberDecimal: this.toString() };
24214
+ }
24215
+ static fromExtendedJSON(doc) {
24216
+ return Decimal128.fromString(doc.$numberDecimal);
24217
+ }
24218
+ inspect(depth, options, inspect) {
24219
+ inspect ??= defaultInspect;
24220
+ const d128string = inspect(this.toString(), options);
24221
+ return `new Decimal128(${d128string})`;
24222
+ }
24223
+ }
24224
+
24225
+ class Double extends BSONValue {
24226
+ get _bsontype() {
24227
+ return 'Double';
24228
+ }
24229
+ constructor(value) {
24230
+ super();
24231
+ if (value instanceof Number) {
24232
+ value = value.valueOf();
24233
+ }
24234
+ this.value = +value;
24235
+ }
24236
+ static fromString(value) {
24237
+ const coercedValue = Number(value);
24238
+ if (value === 'NaN')
24239
+ return new Double(NaN);
24240
+ if (value === 'Infinity')
24241
+ return new Double(Infinity);
24242
+ if (value === '-Infinity')
24243
+ return new Double(-Infinity);
24244
+ if (!Number.isFinite(coercedValue)) {
24245
+ throw new BSONError(`Input: ${value} is not representable as a Double`);
24246
+ }
24247
+ if (value.trim() !== value) {
24248
+ throw new BSONError(`Input: '${value}' contains whitespace`);
24249
+ }
24250
+ if (value === '') {
24251
+ throw new BSONError(`Input is an empty string`);
24252
+ }
24253
+ if (/[^-0-9.+eE]/.test(value)) {
24254
+ throw new BSONError(`Input: '${value}' is not in decimal or exponential notation`);
24255
+ }
24256
+ return new Double(coercedValue);
24257
+ }
24258
+ valueOf() {
24259
+ return this.value;
24260
+ }
24261
+ toJSON() {
24262
+ return this.value;
24263
+ }
24264
+ toString(radix) {
24265
+ return this.value.toString(radix);
24266
+ }
24267
+ toExtendedJSON(options) {
24268
+ if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
24269
+ return this.value;
24270
+ }
24271
+ if (Object.is(Math.sign(this.value), -0)) {
24272
+ return { $numberDouble: '-0.0' };
24273
+ }
24274
+ return {
24275
+ $numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
24276
+ };
24277
+ }
24278
+ static fromExtendedJSON(doc, options) {
24279
+ const doubleValue = parseFloat(doc.$numberDouble);
24280
+ return options && options.relaxed ? doubleValue : new Double(doubleValue);
24281
+ }
24282
+ inspect(depth, options, inspect) {
24283
+ inspect ??= defaultInspect;
24284
+ return `new Double(${inspect(this.value, options)})`;
24285
+ }
24286
+ }
24287
+
24288
+ class Int32 extends BSONValue {
24289
+ get _bsontype() {
24290
+ return 'Int32';
24291
+ }
24292
+ constructor(value) {
24293
+ super();
24294
+ if (value instanceof Number) {
24295
+ value = value.valueOf();
24296
+ }
24297
+ this.value = +value | 0;
24298
+ }
24299
+ static fromString(value) {
24300
+ const cleanedValue = removeLeadingZerosAndExplicitPlus(value);
24301
+ const coercedValue = Number(value);
24302
+ if (BSON_INT32_MAX < coercedValue) {
24303
+ throw new BSONError(`Input: '${value}' is larger than the maximum value for Int32`);
24304
+ }
24305
+ else if (BSON_INT32_MIN > coercedValue) {
24306
+ throw new BSONError(`Input: '${value}' is smaller than the minimum value for Int32`);
24307
+ }
24308
+ else if (!Number.isSafeInteger(coercedValue)) {
24309
+ throw new BSONError(`Input: '${value}' is not a safe integer`);
24310
+ }
24311
+ else if (coercedValue.toString() !== cleanedValue) {
24312
+ throw new BSONError(`Input: '${value}' is not a valid Int32 string`);
24313
+ }
24314
+ return new Int32(coercedValue);
24315
+ }
24316
+ valueOf() {
24317
+ return this.value;
24318
+ }
24319
+ toString(radix) {
24320
+ return this.value.toString(radix);
24321
+ }
24322
+ toJSON() {
24323
+ return this.value;
24324
+ }
24325
+ toExtendedJSON(options) {
24326
+ if (options && (options.relaxed || options.legacy))
24327
+ return this.value;
24328
+ return { $numberInt: this.value.toString() };
24329
+ }
24330
+ static fromExtendedJSON(doc, options) {
24331
+ return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
24332
+ }
24333
+ inspect(depth, options, inspect) {
24334
+ inspect ??= defaultInspect;
24335
+ return `new Int32(${inspect(this.value, options)})`;
24336
+ }
24337
+ }
24338
+
24339
+ class MaxKey extends BSONValue {
24340
+ get _bsontype() {
24341
+ return 'MaxKey';
24342
+ }
24343
+ toExtendedJSON() {
24344
+ return { $maxKey: 1 };
24345
+ }
24346
+ static fromExtendedJSON() {
24347
+ return new MaxKey();
24348
+ }
24349
+ inspect() {
24350
+ return 'new MaxKey()';
24351
+ }
24352
+ }
24353
+
24354
+ class MinKey extends BSONValue {
24355
+ get _bsontype() {
24356
+ return 'MinKey';
24357
+ }
24358
+ toExtendedJSON() {
24359
+ return { $minKey: 1 };
24360
+ }
24361
+ static fromExtendedJSON() {
24362
+ return new MinKey();
24363
+ }
24364
+ inspect() {
24365
+ return 'new MinKey()';
24366
+ }
24367
+ }
24368
+
24369
+ let PROCESS_UNIQUE = null;
24370
+ const __idCache = new WeakMap();
24371
+ class ObjectId extends BSONValue {
24372
+ get _bsontype() {
24373
+ return 'ObjectId';
24374
+ }
24375
+ constructor(inputId) {
24376
+ super();
24377
+ let workingId;
24378
+ if (typeof inputId === 'object' && inputId && 'id' in inputId) {
24379
+ if (typeof inputId.id !== 'string' && !ArrayBuffer.isView(inputId.id)) {
24380
+ throw new BSONError('Argument passed in must have an id that is of type string or Buffer');
24381
+ }
24382
+ if ('toHexString' in inputId && typeof inputId.toHexString === 'function') {
24383
+ workingId = ByteUtils.fromHex(inputId.toHexString());
24384
+ }
24385
+ else {
24386
+ workingId = inputId.id;
24387
+ }
24388
+ }
24389
+ else {
24390
+ workingId = inputId;
24391
+ }
24392
+ if (workingId == null || typeof workingId === 'number') {
24393
+ this.buffer = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
24394
+ }
24395
+ else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
24396
+ this.buffer = ByteUtils.toLocalBufferType(workingId);
24397
+ }
24398
+ else if (typeof workingId === 'string') {
24399
+ if (ObjectId.validateHexString(workingId)) {
24400
+ this.buffer = ByteUtils.fromHex(workingId);
24401
+ if (ObjectId.cacheHexString) {
24402
+ __idCache.set(this, workingId);
24403
+ }
24404
+ }
24405
+ else {
24406
+ throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an integer');
24407
+ }
24408
+ }
24409
+ else {
24410
+ throw new BSONError('Argument passed in does not match the accepted types');
24411
+ }
24412
+ }
24413
+ get id() {
24414
+ return this.buffer;
24415
+ }
24416
+ set id(value) {
24417
+ this.buffer = value;
24418
+ if (ObjectId.cacheHexString) {
24419
+ __idCache.set(this, ByteUtils.toHex(value));
24420
+ }
24421
+ }
24422
+ static validateHexString(string) {
24423
+ if (string?.length !== 24)
24424
+ return false;
24425
+ for (let i = 0; i < 24; i++) {
24426
+ const char = string.charCodeAt(i);
24427
+ if ((char >= 48 && char <= 57) ||
24428
+ (char >= 97 && char <= 102) ||
24429
+ (char >= 65 && char <= 70)) {
24430
+ continue;
24431
+ }
24432
+ return false;
24433
+ }
24434
+ return true;
24435
+ }
24436
+ toHexString() {
24437
+ if (ObjectId.cacheHexString) {
24438
+ const __id = __idCache.get(this);
24439
+ if (__id)
24440
+ return __id;
24441
+ }
24442
+ const hexString = ByteUtils.toHex(this.id);
24443
+ if (ObjectId.cacheHexString) {
24444
+ __idCache.set(this, hexString);
24445
+ }
24446
+ return hexString;
24447
+ }
24448
+ static getInc() {
24449
+ return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
24450
+ }
24451
+ static generate(time) {
24452
+ if ('number' !== typeof time) {
24453
+ time = Math.floor(Date.now() / 1000);
24454
+ }
24455
+ const inc = ObjectId.getInc();
24456
+ const buffer = ByteUtils.allocateUnsafe(12);
24457
+ NumberUtils.setInt32BE(buffer, 0, time);
24458
+ if (PROCESS_UNIQUE === null) {
24459
+ PROCESS_UNIQUE = ByteUtils.randomBytes(5);
24460
+ }
24461
+ buffer[4] = PROCESS_UNIQUE[0];
24462
+ buffer[5] = PROCESS_UNIQUE[1];
24463
+ buffer[6] = PROCESS_UNIQUE[2];
24464
+ buffer[7] = PROCESS_UNIQUE[3];
24465
+ buffer[8] = PROCESS_UNIQUE[4];
24466
+ buffer[11] = inc & 0xff;
24467
+ buffer[10] = (inc >> 8) & 0xff;
24468
+ buffer[9] = (inc >> 16) & 0xff;
24469
+ return buffer;
24470
+ }
24471
+ toString(encoding) {
24472
+ if (encoding === 'base64')
24473
+ return ByteUtils.toBase64(this.id);
24474
+ if (encoding === 'hex')
24475
+ return this.toHexString();
24476
+ return this.toHexString();
24477
+ }
24478
+ toJSON() {
24479
+ return this.toHexString();
24480
+ }
24481
+ static is(variable) {
24482
+ return (variable != null &&
24483
+ typeof variable === 'object' &&
24484
+ '_bsontype' in variable &&
24485
+ variable._bsontype === 'ObjectId');
24486
+ }
24487
+ equals(otherId) {
24488
+ if (otherId === undefined || otherId === null) {
24489
+ return false;
24490
+ }
24491
+ if (ObjectId.is(otherId)) {
24492
+ return (this.buffer[11] === otherId.buffer[11] && ByteUtils.equals(this.buffer, otherId.buffer));
24493
+ }
24494
+ if (typeof otherId === 'string') {
24495
+ return otherId.toLowerCase() === this.toHexString();
24496
+ }
24497
+ if (typeof otherId === 'object' && typeof otherId.toHexString === 'function') {
24498
+ const otherIdString = otherId.toHexString();
24499
+ const thisIdString = this.toHexString();
24500
+ return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
24501
+ }
24502
+ return false;
24503
+ }
24504
+ getTimestamp() {
24505
+ const timestamp = new Date();
24506
+ const time = NumberUtils.getUint32BE(this.buffer, 0);
24507
+ timestamp.setTime(Math.floor(time) * 1000);
24508
+ return timestamp;
24509
+ }
24510
+ static createPk() {
24511
+ return new ObjectId();
24512
+ }
24513
+ serializeInto(uint8array, index) {
24514
+ uint8array[index] = this.buffer[0];
24515
+ uint8array[index + 1] = this.buffer[1];
24516
+ uint8array[index + 2] = this.buffer[2];
24517
+ uint8array[index + 3] = this.buffer[3];
24518
+ uint8array[index + 4] = this.buffer[4];
24519
+ uint8array[index + 5] = this.buffer[5];
24520
+ uint8array[index + 6] = this.buffer[6];
24521
+ uint8array[index + 7] = this.buffer[7];
24522
+ uint8array[index + 8] = this.buffer[8];
24523
+ uint8array[index + 9] = this.buffer[9];
24524
+ uint8array[index + 10] = this.buffer[10];
24525
+ uint8array[index + 11] = this.buffer[11];
24526
+ return 12;
24527
+ }
24528
+ static createFromTime(time) {
24529
+ const buffer = ByteUtils.allocate(12);
24530
+ for (let i = 11; i >= 4; i--)
24531
+ buffer[i] = 0;
24532
+ NumberUtils.setInt32BE(buffer, 0, time);
24533
+ return new ObjectId(buffer);
24534
+ }
24535
+ static createFromHexString(hexString) {
24536
+ if (hexString?.length !== 24) {
24537
+ throw new BSONError('hex string must be 24 characters');
24538
+ }
24539
+ return new ObjectId(ByteUtils.fromHex(hexString));
24540
+ }
24541
+ static createFromBase64(base64) {
24542
+ if (base64?.length !== 16) {
24543
+ throw new BSONError('base64 string must be 16 characters');
24544
+ }
24545
+ return new ObjectId(ByteUtils.fromBase64(base64));
24546
+ }
24547
+ static isValid(id) {
24548
+ if (id == null)
24549
+ return false;
24550
+ if (typeof id === 'string')
24551
+ return ObjectId.validateHexString(id);
24552
+ try {
24553
+ new ObjectId(id);
24554
+ return true;
24555
+ }
24556
+ catch {
24557
+ return false;
24558
+ }
24559
+ }
24560
+ toExtendedJSON() {
24561
+ if (this.toHexString)
24562
+ return { $oid: this.toHexString() };
24563
+ return { $oid: this.toString('hex') };
24564
+ }
24565
+ static fromExtendedJSON(doc) {
24566
+ return new ObjectId(doc.$oid);
24567
+ }
24568
+ isCached() {
24569
+ return ObjectId.cacheHexString && __idCache.has(this);
24570
+ }
24571
+ inspect(depth, options, inspect) {
24572
+ inspect ??= defaultInspect;
24573
+ return `new ObjectId(${inspect(this.toHexString(), options)})`;
24574
+ }
24575
+ }
24576
+ ObjectId.index = Math.floor(Math.random() * 0xffffff);
24577
+
24578
+ function alphabetize(str) {
24579
+ return str.split('').sort().join('');
24580
+ }
24581
+ class BSONRegExp extends BSONValue {
24582
+ get _bsontype() {
24583
+ return 'BSONRegExp';
24584
+ }
24585
+ constructor(pattern, options) {
24586
+ super();
24587
+ this.pattern = pattern;
24588
+ this.options = alphabetize(options ?? '');
24589
+ if (this.pattern.indexOf('\x00') !== -1) {
24590
+ throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);
24591
+ }
24592
+ if (this.options.indexOf('\x00') !== -1) {
24593
+ throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);
24594
+ }
24595
+ for (let i = 0; i < this.options.length; i++) {
24596
+ if (!(this.options[i] === 'i' ||
24597
+ this.options[i] === 'm' ||
24598
+ this.options[i] === 'x' ||
24599
+ this.options[i] === 'l' ||
24600
+ this.options[i] === 's' ||
24601
+ this.options[i] === 'u')) {
24602
+ throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
24603
+ }
24604
+ }
24605
+ }
24606
+ static parseOptions(options) {
24607
+ return options ? options.split('').sort().join('') : '';
24608
+ }
24609
+ toExtendedJSON(options) {
24610
+ options = options || {};
24611
+ if (options.legacy) {
24612
+ return { $regex: this.pattern, $options: this.options };
24613
+ }
24614
+ return { $regularExpression: { pattern: this.pattern, options: this.options } };
24615
+ }
24616
+ static fromExtendedJSON(doc) {
24617
+ if ('$regex' in doc) {
24618
+ if (typeof doc.$regex !== 'string') {
24619
+ if (doc.$regex._bsontype === 'BSONRegExp') {
24620
+ return doc;
24621
+ }
24622
+ }
24623
+ else {
24624
+ return new BSONRegExp(doc.$regex, BSONRegExp.parseOptions(doc.$options));
24625
+ }
24626
+ }
24627
+ if ('$regularExpression' in doc) {
24628
+ return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
24629
+ }
24630
+ throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
24631
+ }
24632
+ inspect(depth, options, inspect) {
24633
+ const stylize = getStylizeFunction(options) ?? (v => v);
24634
+ inspect ??= defaultInspect;
24635
+ const pattern = stylize(inspect(this.pattern), 'regexp');
24636
+ const flags = stylize(inspect(this.options), 'regexp');
24637
+ return `new BSONRegExp(${pattern}, ${flags})`;
24638
+ }
24639
+ }
24640
+
24641
+ class BSONSymbol extends BSONValue {
24642
+ get _bsontype() {
24643
+ return 'BSONSymbol';
24644
+ }
24645
+ constructor(value) {
24646
+ super();
24647
+ this.value = value;
24648
+ }
24649
+ valueOf() {
24650
+ return this.value;
24651
+ }
24652
+ toString() {
24653
+ return this.value;
24654
+ }
24655
+ toJSON() {
24656
+ return this.value;
24657
+ }
24658
+ toExtendedJSON() {
24659
+ return { $symbol: this.value };
24660
+ }
24661
+ static fromExtendedJSON(doc) {
24662
+ return new BSONSymbol(doc.$symbol);
24663
+ }
24664
+ inspect(depth, options, inspect) {
24665
+ inspect ??= defaultInspect;
24666
+ return `new BSONSymbol(${inspect(this.value, options)})`;
24667
+ }
24668
+ }
24669
+
24670
+ const LongWithoutOverridesClass = Long;
24671
+ class Timestamp extends LongWithoutOverridesClass {
24672
+ get _bsontype() {
24673
+ return 'Timestamp';
24674
+ }
24675
+ get i() {
24676
+ return this.low >>> 0;
24677
+ }
24678
+ get t() {
24679
+ return this.high >>> 0;
24680
+ }
24681
+ constructor(low) {
24682
+ if (low == null) {
24683
+ super(0, 0, true);
24684
+ }
24685
+ else if (typeof low === 'bigint') {
24686
+ super(low, true);
24687
+ }
24688
+ else if (Long.isLong(low)) {
24689
+ super(low.low, low.high, true);
24690
+ }
24691
+ else if (typeof low === 'object' && 't' in low && 'i' in low) {
24692
+ if (typeof low.t !== 'number' && (typeof low.t !== 'object' || low.t._bsontype !== 'Int32')) {
24693
+ throw new BSONError('Timestamp constructed from { t, i } must provide t as a number');
24694
+ }
24695
+ if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
24696
+ throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
24697
+ }
24698
+ const t = Number(low.t);
24699
+ const i = Number(low.i);
24700
+ if (t < 0 || Number.isNaN(t)) {
24701
+ throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
24702
+ }
24703
+ if (i < 0 || Number.isNaN(i)) {
24704
+ throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
24705
+ }
24706
+ if (t > 0xffff_ffff) {
24707
+ throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
24708
+ }
24709
+ if (i > 0xffff_ffff) {
24710
+ throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
24711
+ }
24712
+ super(i, t, true);
24713
+ }
24714
+ else {
24715
+ throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
24716
+ }
24717
+ }
24718
+ toJSON() {
24719
+ return {
24720
+ $timestamp: this.toString()
24721
+ };
24722
+ }
24723
+ static fromInt(value) {
24724
+ return new Timestamp(Long.fromInt(value, true));
24725
+ }
24726
+ static fromNumber(value) {
24727
+ return new Timestamp(Long.fromNumber(value, true));
24728
+ }
24729
+ static fromBits(lowBits, highBits) {
24730
+ return new Timestamp({ i: lowBits, t: highBits });
24731
+ }
24732
+ static fromString(str, optRadix) {
24733
+ return new Timestamp(Long.fromString(str, true, optRadix));
24734
+ }
24735
+ toExtendedJSON() {
24736
+ return { $timestamp: { t: this.t, i: this.i } };
24737
+ }
24738
+ static fromExtendedJSON(doc) {
24739
+ const i = Long.isLong(doc.$timestamp.i)
24740
+ ? doc.$timestamp.i.getLowBitsUnsigned()
24741
+ : doc.$timestamp.i;
24742
+ const t = Long.isLong(doc.$timestamp.t)
24743
+ ? doc.$timestamp.t.getLowBitsUnsigned()
24744
+ : doc.$timestamp.t;
24745
+ return new Timestamp({ t, i });
24746
+ }
24747
+ inspect(depth, options, inspect) {
24748
+ inspect ??= defaultInspect;
24749
+ const t = inspect(this.t, options);
24750
+ const i = inspect(this.i, options);
24751
+ return `new Timestamp({ t: ${t}, i: ${i} })`;
24752
+ }
24753
+ }
24754
+ Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
24755
+
24756
+ Long.fromNumber(JS_INT_MAX);
24757
+ Long.fromNumber(JS_INT_MIN);
24758
+
24759
+ function isBSONType(value) {
24760
+ return (value != null &&
24761
+ typeof value === 'object' &&
24762
+ '_bsontype' in value &&
24763
+ typeof value._bsontype === 'string');
24764
+ }
24765
+ const keysToCodecs = {
24766
+ $oid: ObjectId,
24767
+ $binary: Binary,
24768
+ $uuid: Binary,
24769
+ $symbol: BSONSymbol,
24770
+ $numberInt: Int32,
24771
+ $numberDecimal: Decimal128,
24772
+ $numberDouble: Double,
24773
+ $numberLong: Long,
24774
+ $minKey: MinKey,
24775
+ $maxKey: MaxKey,
24776
+ $regex: BSONRegExp,
24777
+ $regularExpression: BSONRegExp,
24778
+ $timestamp: Timestamp
24779
+ };
24780
+ function deserializeValue(value, options = {}) {
24781
+ if (typeof value === 'number') {
24782
+ const in32BitRange = value <= BSON_INT32_MAX && value >= BSON_INT32_MIN;
24783
+ const in64BitRange = value <= BSON_INT64_MAX && value >= BSON_INT64_MIN;
24784
+ if (options.relaxed || options.legacy) {
24785
+ return value;
24786
+ }
24787
+ if (Number.isInteger(value) && !Object.is(value, -0)) {
24788
+ if (in32BitRange) {
24789
+ return new Int32(value);
24790
+ }
24791
+ if (in64BitRange) {
24792
+ if (options.useBigInt64) {
24793
+ return BigInt(value);
24794
+ }
24795
+ return Long.fromNumber(value);
24796
+ }
24797
+ }
24798
+ return new Double(value);
24799
+ }
24800
+ if (value == null || typeof value !== 'object')
24801
+ return value;
24802
+ if (value.$undefined)
24803
+ return null;
24804
+ const keys = Object.keys(value).filter(k => k.startsWith('$') && value[k] != null);
24805
+ for (let i = 0; i < keys.length; i++) {
24806
+ const c = keysToCodecs[keys[i]];
24807
+ if (c)
24808
+ return c.fromExtendedJSON(value, options);
24809
+ }
24810
+ if (value.$date != null) {
24811
+ const d = value.$date;
24812
+ const date = new Date();
24813
+ if (options.legacy) {
24814
+ if (typeof d === 'number')
24815
+ date.setTime(d);
24816
+ else if (typeof d === 'string')
24817
+ date.setTime(Date.parse(d));
24818
+ else if (typeof d === 'bigint')
24819
+ date.setTime(Number(d));
24820
+ else
24821
+ throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
24822
+ }
24823
+ else {
24824
+ if (typeof d === 'string')
24825
+ date.setTime(Date.parse(d));
24826
+ else if (Long.isLong(d))
24827
+ date.setTime(d.toNumber());
24828
+ else if (typeof d === 'number' && options.relaxed)
24829
+ date.setTime(d);
24830
+ else if (typeof d === 'bigint')
24831
+ date.setTime(Number(d));
24832
+ else
24833
+ throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
24834
+ }
24835
+ return date;
24836
+ }
24837
+ if (value.$code != null) {
24838
+ const copy = Object.assign({}, value);
24839
+ if (value.$scope) {
24840
+ copy.$scope = deserializeValue(value.$scope);
24841
+ }
24842
+ return Code.fromExtendedJSON(value);
24843
+ }
24844
+ if (isDBRefLike(value) || value.$dbPointer) {
24845
+ const v = value.$ref ? value : value.$dbPointer;
24846
+ if (v instanceof DBRef)
24847
+ return v;
24848
+ const dollarKeys = Object.keys(v).filter(k => k.startsWith('$'));
24849
+ let valid = true;
24850
+ dollarKeys.forEach(k => {
24851
+ if (['$ref', '$id', '$db'].indexOf(k) === -1)
24852
+ valid = false;
24853
+ });
24854
+ if (valid)
24855
+ return DBRef.fromExtendedJSON(v);
24856
+ }
24857
+ return value;
24858
+ }
24859
+ function serializeArray(array, options) {
24860
+ return array.map((v, index) => {
24861
+ options.seenObjects.push({ propertyName: `index ${index}`, obj: null });
24862
+ try {
24863
+ return serializeValue(v, options);
24864
+ }
24865
+ finally {
24866
+ options.seenObjects.pop();
24867
+ }
24868
+ });
24869
+ }
24870
+ function getISOString(date) {
24871
+ const isoStr = date.toISOString();
24872
+ return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z';
24873
+ }
24874
+ function serializeValue(value, options) {
24875
+ if (value instanceof Map || isMap(value)) {
24876
+ const obj = Object.create(null);
24877
+ for (const [k, v] of value) {
24878
+ if (typeof k !== 'string') {
24879
+ throw new BSONError('Can only serialize maps with string keys');
24880
+ }
24881
+ obj[k] = v;
24882
+ }
24883
+ return serializeValue(obj, options);
24884
+ }
24885
+ if ((typeof value === 'object' || typeof value === 'function') && value !== null) {
24886
+ const index = options.seenObjects.findIndex(entry => entry.obj === value);
24887
+ if (index !== -1) {
24888
+ const props = options.seenObjects.map(entry => entry.propertyName);
24889
+ const leadingPart = props
24890
+ .slice(0, index)
24891
+ .map(prop => `${prop} -> `)
24892
+ .join('');
24893
+ const alreadySeen = props[index];
24894
+ const circularPart = ' -> ' +
24895
+ props
24896
+ .slice(index + 1, props.length - 1)
24897
+ .map(prop => `${prop} -> `)
24898
+ .join('');
24899
+ const current = props[props.length - 1];
24900
+ const leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
24901
+ const dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
24902
+ throw new BSONError('Converting circular structure to EJSON:\n' +
24903
+ ` ${leadingPart}${alreadySeen}${circularPart}${current}\n` +
24904
+ ` ${leadingSpace}\\${dashes}/`);
24905
+ }
24906
+ options.seenObjects[options.seenObjects.length - 1].obj = value;
24907
+ }
24908
+ if (Array.isArray(value))
24909
+ return serializeArray(value, options);
24910
+ if (value === undefined)
24911
+ return null;
24912
+ if (value instanceof Date || isDate(value)) {
24913
+ const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 253402318800000;
24914
+ if (options.legacy) {
24915
+ return options.relaxed && inRange
24916
+ ? { $date: value.getTime() }
24917
+ : { $date: getISOString(value) };
24918
+ }
24919
+ return options.relaxed && inRange
24920
+ ? { $date: getISOString(value) }
24921
+ : { $date: { $numberLong: value.getTime().toString() } };
24922
+ }
24923
+ if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
24924
+ if (Number.isInteger(value) && !Object.is(value, -0)) {
24925
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
24926
+ return { $numberInt: value.toString() };
24927
+ }
24928
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) {
24929
+ return { $numberLong: value.toString() };
24930
+ }
24931
+ }
24932
+ return { $numberDouble: Object.is(value, -0) ? '-0.0' : value.toString() };
24933
+ }
24934
+ if (typeof value === 'bigint') {
24935
+ if (!options.relaxed) {
24936
+ return { $numberLong: BigInt.asIntN(64, value).toString() };
24937
+ }
24938
+ return Number(BigInt.asIntN(64, value));
24939
+ }
24940
+ if (value instanceof RegExp || isRegExp(value)) {
24941
+ let flags = value.flags;
24942
+ if (flags === undefined) {
24943
+ const match = value.toString().match(/[gimuy]*$/);
24944
+ if (match) {
24945
+ flags = match[0];
24946
+ }
24947
+ }
24948
+ const rx = new BSONRegExp(value.source, flags);
24949
+ return rx.toExtendedJSON(options);
24950
+ }
24951
+ if (value != null && typeof value === 'object')
24952
+ return serializeDocument(value, options);
24953
+ return value;
24954
+ }
24955
+ const BSON_TYPE_MAPPINGS = {
24956
+ Binary: (o) => new Binary(o.value(), o.sub_type),
24957
+ Code: (o) => new Code(o.code, o.scope),
24958
+ DBRef: (o) => new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields),
24959
+ Decimal128: (o) => new Decimal128(o.bytes),
24960
+ Double: (o) => new Double(o.value),
24961
+ Int32: (o) => new Int32(o.value),
24962
+ Long: (o) => Long.fromBits(o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_),
24963
+ MaxKey: () => new MaxKey(),
24964
+ MinKey: () => new MinKey(),
24965
+ ObjectId: (o) => new ObjectId(o),
24966
+ BSONRegExp: (o) => new BSONRegExp(o.pattern, o.options),
24967
+ BSONSymbol: (o) => new BSONSymbol(o.value),
24968
+ Timestamp: (o) => Timestamp.fromBits(o.low, o.high)
24969
+ };
24970
+ function serializeDocument(doc, options) {
24971
+ if (doc == null || typeof doc !== 'object')
24972
+ throw new BSONError('not an object instance');
24973
+ const bsontype = doc._bsontype;
24974
+ if (typeof bsontype === 'undefined') {
24975
+ const _doc = {};
24976
+ for (const name of Object.keys(doc)) {
24977
+ options.seenObjects.push({ propertyName: name, obj: null });
24978
+ try {
24979
+ const value = serializeValue(doc[name], options);
24980
+ if (name === '__proto__') {
24981
+ Object.defineProperty(_doc, name, {
24982
+ value,
24983
+ writable: true,
24984
+ enumerable: true,
24985
+ configurable: true
24986
+ });
24987
+ }
24988
+ else {
24989
+ _doc[name] = value;
24990
+ }
24991
+ }
24992
+ finally {
24993
+ options.seenObjects.pop();
24994
+ }
24995
+ }
24996
+ return _doc;
24997
+ }
24998
+ else if (doc != null &&
24999
+ typeof doc === 'object' &&
25000
+ typeof doc._bsontype === 'string' &&
25001
+ doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
25002
+ throw new BSONVersionError();
25003
+ }
25004
+ else if (isBSONType(doc)) {
25005
+ let outDoc = doc;
25006
+ if (typeof outDoc.toExtendedJSON !== 'function') {
25007
+ const mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
25008
+ if (!mapper) {
25009
+ throw new BSONError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
25010
+ }
25011
+ outDoc = mapper(outDoc);
25012
+ }
25013
+ if (bsontype === 'Code' && outDoc.scope) {
25014
+ outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
25015
+ }
25016
+ else if (bsontype === 'DBRef' && outDoc.oid) {
25017
+ outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
25018
+ }
25019
+ return outDoc.toExtendedJSON(options);
25020
+ }
25021
+ else {
25022
+ throw new BSONError('_bsontype must be a string, but was: ' + typeof bsontype);
25023
+ }
25024
+ }
25025
+ function parse(text, options) {
25026
+ const ejsonOptions = {
25027
+ useBigInt64: options?.useBigInt64 ?? false,
25028
+ relaxed: options?.relaxed ?? true,
25029
+ legacy: options?.legacy ?? false
25030
+ };
25031
+ return JSON.parse(text, (key, value) => {
25032
+ if (key.indexOf('\x00') !== -1) {
25033
+ throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`);
25034
+ }
25035
+ return deserializeValue(value, ejsonOptions);
25036
+ });
25037
+ }
25038
+ function stringify(value, replacer, space, options) {
25039
+ if (space != null && typeof space === 'object') {
25040
+ options = space;
25041
+ space = 0;
25042
+ }
25043
+ if (replacer != null && typeof replacer === 'object' && !Array.isArray(replacer)) {
25044
+ options = replacer;
25045
+ replacer = undefined;
25046
+ space = 0;
25047
+ }
25048
+ const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
25049
+ seenObjects: [{ propertyName: '(root)', obj: null }]
25050
+ });
25051
+ const doc = serializeValue(value, serializeOptions);
25052
+ return JSON.stringify(doc, replacer, space);
25053
+ }
25054
+ function EJSONserialize(value, options) {
25055
+ options = options || {};
25056
+ return JSON.parse(stringify(value, options));
25057
+ }
25058
+ function EJSONdeserialize(ejson, options) {
25059
+ options = options || {};
25060
+ return parse(JSON.stringify(ejson), options);
25061
+ }
25062
+ const EJSON = Object.create(null);
25063
+ EJSON.parse = parse;
25064
+ EJSON.stringify = stringify;
25065
+ EJSON.serialize = EJSONserialize;
25066
+ EJSON.deserialize = EJSONdeserialize;
25067
+ Object.freeze(EJSON);
25068
+
25069
+ const BSONElementType = {
25070
+ double: 1,
25071
+ string: 2,
25072
+ object: 3,
25073
+ array: 4,
25074
+ binData: 5,
25075
+ undefined: 6,
25076
+ objectId: 7,
25077
+ bool: 8,
25078
+ date: 9,
25079
+ null: 10,
25080
+ regex: 11,
25081
+ dbPointer: 12,
25082
+ javascript: 13,
25083
+ symbol: 14,
25084
+ javascriptWithScope: 15,
25085
+ int: 16,
25086
+ timestamp: 17,
25087
+ long: 18,
25088
+ decimal: 19,
25089
+ minKey: 255,
25090
+ maxKey: 127
25091
+ };
25092
+ function getSize(source, offset) {
25093
+ try {
25094
+ return NumberUtils.getNonnegativeInt32LE(source, offset);
25095
+ }
25096
+ catch (cause) {
25097
+ throw new BSONOffsetError('BSON size cannot be negative', offset, { cause });
25098
+ }
25099
+ }
25100
+ function findNull(bytes, offset) {
25101
+ let nullTerminatorOffset = offset;
25102
+ for (; bytes[nullTerminatorOffset] !== 0x00; nullTerminatorOffset++)
25103
+ ;
25104
+ if (nullTerminatorOffset === bytes.length - 1) {
25105
+ throw new BSONOffsetError('Null terminator not found', offset);
25106
+ }
25107
+ return nullTerminatorOffset;
25108
+ }
25109
+ function parseToElements(bytes, startOffset = 0) {
25110
+ startOffset ??= 0;
25111
+ if (bytes.length < 5) {
25112
+ throw new BSONOffsetError(`Input must be at least 5 bytes, got ${bytes.length} bytes`, startOffset);
25113
+ }
25114
+ const documentSize = getSize(bytes, startOffset);
25115
+ if (documentSize > bytes.length - startOffset) {
25116
+ throw new BSONOffsetError(`Parsed documentSize (${documentSize} bytes) does not match input length (${bytes.length} bytes)`, startOffset);
25117
+ }
25118
+ if (bytes[startOffset + documentSize - 1] !== 0x00) {
25119
+ throw new BSONOffsetError('BSON documents must end in 0x00', startOffset + documentSize);
25120
+ }
25121
+ const elements = [];
25122
+ let offset = startOffset + 4;
25123
+ while (offset <= documentSize + startOffset) {
25124
+ const type = bytes[offset];
25125
+ offset += 1;
25126
+ if (type === 0) {
25127
+ if (offset - startOffset !== documentSize) {
25128
+ throw new BSONOffsetError(`Invalid 0x00 type byte`, offset);
25129
+ }
25130
+ break;
25131
+ }
25132
+ const nameOffset = offset;
25133
+ const nameLength = findNull(bytes, offset) - nameOffset;
25134
+ offset += nameLength + 1;
25135
+ let length;
25136
+ if (type === BSONElementType.double ||
25137
+ type === BSONElementType.long ||
25138
+ type === BSONElementType.date ||
25139
+ type === BSONElementType.timestamp) {
25140
+ length = 8;
25141
+ }
25142
+ else if (type === BSONElementType.int) {
25143
+ length = 4;
25144
+ }
25145
+ else if (type === BSONElementType.objectId) {
25146
+ length = 12;
25147
+ }
25148
+ else if (type === BSONElementType.decimal) {
25149
+ length = 16;
25150
+ }
25151
+ else if (type === BSONElementType.bool) {
25152
+ length = 1;
25153
+ }
25154
+ else if (type === BSONElementType.null ||
25155
+ type === BSONElementType.undefined ||
25156
+ type === BSONElementType.maxKey ||
25157
+ type === BSONElementType.minKey) {
25158
+ length = 0;
25159
+ }
25160
+ else if (type === BSONElementType.regex) {
25161
+ length = findNull(bytes, findNull(bytes, offset) + 1) + 1 - offset;
25162
+ }
25163
+ else if (type === BSONElementType.object ||
25164
+ type === BSONElementType.array ||
25165
+ type === BSONElementType.javascriptWithScope) {
25166
+ length = getSize(bytes, offset);
25167
+ }
25168
+ else if (type === BSONElementType.string ||
25169
+ type === BSONElementType.binData ||
25170
+ type === BSONElementType.dbPointer ||
25171
+ type === BSONElementType.javascript ||
25172
+ type === BSONElementType.symbol) {
25173
+ length = getSize(bytes, offset) + 4;
25174
+ if (type === BSONElementType.binData) {
25175
+ length += 1;
25176
+ }
25177
+ if (type === BSONElementType.dbPointer) {
25178
+ length += 12;
25179
+ }
25180
+ }
25181
+ else {
25182
+ throw new BSONOffsetError(`Invalid 0x${type.toString(16).padStart(2, '0')} type byte`, offset);
25183
+ }
25184
+ if (length > documentSize) {
25185
+ throw new BSONOffsetError('value reports length larger than document', offset);
25186
+ }
25187
+ elements.push([type, nameOffset, nameLength, offset, length]);
25188
+ offset += length;
25189
+ }
25190
+ return elements;
25191
+ }
25192
+
25193
+ const onDemand = Object.create(null);
25194
+ onDemand.parseToElements = parseToElements;
25195
+ onDemand.ByteUtils = ByteUtils;
25196
+ onDemand.NumberUtils = NumberUtils;
25197
+ Object.freeze(onDemand);
25198
+
25199
+ const MAXSIZE = 1024 * 1024 * 17;
25200
+ ByteUtils.allocate(MAXSIZE);
25201
+
25202
+ try{if("undefined"==typeof fetch&&"undefined"!=typeof process&&process.versions?.node){new Function("m","return import(m)")("cross-fetch/polyfill").catch((()=>{}));}}catch{}function s(e){const t=new URLSearchParams;for(const[s,n]of Object.entries(e))if(void 0!==n)if(Array.isArray(n))for(const e of n)t.append(s,String(e));else t.append(s,String(n));const s=t.toString();return s?`?${s}`:""}try{if("undefined"!=typeof process&&process.versions?.node&&"win32"===process.platform){new Function("m","return import(m)")("win-ca");}}catch{}class o extends Error{constructor(e,t,s){super(s||t?.message||`HTTP ${e}`),this.name="ApiError",this.status=e,this.error_code=t?.error_code,this.request_id=t?.request_id,this.body=t;}}async function r(e){if(e.ok)return;let t;try{t=await e.json();}catch{try{const s=await e.text();t=s?{message:s}:void 0;}catch{t=void 0;}}throw new o(e.status,t)}class a{started=false;constructor(e,t,s="page_token"){this.fetchPage=e,this.baseParams={...t},this.tokenField=s;}hasNext(){return !this.started||!!this.nextToken}reset(){this.started=false,this.nextToken=void 0;}async next(){if(this.started&&!this.nextToken)return [];const e={...this.baseParams};this.started&&this.nextToken&&(e[this.tokenField]=this.nextToken);const t=await this.fetchPage(e);return this.started=true,this.nextToken=t?.next_page??null,t?.items??[]}}function c(e,t,s="page_token"){return new a(e,t,s)}async function l({client:e,limit:t,page_token:n,sort_by:o}){const a="/org/shortlinks"+s({limit:t,page_token:n,sort_by:o}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`);const p={method:"GET",headers:_},O=e?.fetch||fetch,T=await O(c,p);await r(T);return await T.json()}async function N({client:e,limit:t,page_token:n,sort_by:o,role:a}){const c="/org/members"+s({limit:t,page_token:n,sort_by:o,role:a}),i=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+c,_=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",p={};_&&(p.Authorization=`Bearer ${_}`);const O={method:"GET",headers:p},T=e?.fetch||fetch,v=await T(i,O);await r(v);return await v.json()}async function y({client:e,limit:t,page_token:n,sort_by:o}){const a="/orgs"+s({limit:t,page_token:n,sort_by:o}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`);const p={method:"GET",headers:_},O=e?.fetch||fetch,T=await O(c,p);await r(T);return await T.json()}const k={create_org:async function({client:e,body:t}){const n="/org"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_org_member:async function({client:e,body:t}){const n="/org/members"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_org_saml_idp:async function({client:e,body:t}){const n="/org/saml/idp"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},delete_org:async function({client:e}={}){const t="/org"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},delete_org_member:async function({client:e,user_id:t}){const n=`/org/members/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"DELETE",headers:c},_=e?.fetch||fetch,p=await _(o,i);await r(p);},delete_org_saml_idp:async function({client:e}={}){const t="/org/saml/idp"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},get_any_org:async function({client:e,id:t}){const n=`/orgs/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_org:async function({client:e}={}){const t="/org"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_org_member:async function({client:e,user_id:t}){const n=`/org/members/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_org_privacy_settings:async function({client:e}={}){const t="/org/privacy"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_org_saml_idp:async function({client:e}={}){const t="/org/saml/idp"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_org_shortlinks:l,get_org_shortlinks_pager:function(e){return c(l,e,"page_token")},get_user_org:async function({client:e}={}){const t="/user/org"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_org_members:N,list_org_members_pager:function(e){return c(N,e,"page_token")},list_orgs:y,list_orgs_pager:function(e){return c(y,e,"page_token")},update_enterprise_pricing_for_org:async function({client:e,id:t,body:n}){const o=`/orgs/${t}/enterprise/pricing`+s({}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`),i["Content-Type"]="application/json";const _={method:"PUT",headers:i,body:JSON.stringify(n)},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},update_org:async function({client:e,body:t}){const n="/org"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_org_member:async function({client:e,user_id:t,body:n}){const o=`/org/members/${t}`+s({}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`),i["Content-Type"]="application/json";const _={method:"PUT",headers:i,body:JSON.stringify(n)},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},update_org_privacy_settings:async function({client:e,body:t}){const n="/org/privacy"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_org_saml_idp:async function({client:e,body:t}){const n="/org/saml/idp"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()}},$={create_org_subscription:async function({client:e,body:t}){const n="/org/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_payment_information_for_org:async function({client:e,body:t}){const n="/org/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_payment_information_for_user:async function({client:e,body:t}){const n="/user/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},create_payment_intent_for_org:async function({client:e}={}){const t="/org/payment/intent"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"POST",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},create_payment_intent_for_user:async function({client:e}={}){const t="/user/payment/intent"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"POST",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},create_user_subscription:async function({client:e,body:t}){const n="/user/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"POST",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},delete_payment_information_for_org:async function({client:e}={}){const t="/org/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},delete_payment_information_for_user:async function({client:e}={}){const t="/user/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"DELETE",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},delete_payment_method_for_org:async function({client:e,id:t}){const n=`/org/payment/methods/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"DELETE",headers:c},_=e?.fetch||fetch,p=await _(o,i);await r(p);},delete_payment_method_for_user:async function({client:e,id:t}){const n=`/user/payment/methods/${t}`+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"DELETE",headers:c},_=e?.fetch||fetch,p=await _(o,i);await r(p);},get_org_subscription:async function({client:e}={}){const t="/org/payment/subscriptions"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_payment_balance_for_any_org:async function({client:e,include_total_due:t,id:n}){const o=`/orgs/${n}/payment/balance`+s({include_total_due:t}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`);const _={method:"GET",headers:i},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},get_payment_balance_for_any_user:async function({client:e,id:t,include_total_due:n}){const o=`/users/${t}/payment/balance`+s({include_total_due:n}),a=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+o,c=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",i={};c&&(i.Authorization=`Bearer ${c}`);const _={method:"GET",headers:i},p=e?.fetch||fetch,O=await p(a,_);return await r(O),await O.json()},get_payment_balance_for_org:async function({client:e,include_total_due:t}){const n="/org/payment/balance"+s({include_total_due:t}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_payment_balance_for_user:async function({client:e,include_total_due:t}){const n="/user/payment/balance"+s({include_total_due:t}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`);const i={method:"GET",headers:c},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},get_payment_information_for_org:async function({client:e}={}){const t="/org/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_payment_information_for_user:async function({client:e}={}){const t="/user/payment"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},get_user_subscription:async function({client:e}={}){const t="/user/payment/subscriptions"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_invoices_for_org:async function({client:e}={}){const t="/org/payment/invoices"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_invoices_for_user:async function({client:e}={}){const t="/user/payment/invoices"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_payment_methods_for_org:async function({client:e}={}){const t="/org/payment/methods"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},list_payment_methods_for_user:async function({client:e}={}){const t="/user/payment/methods"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);return await r(_),await _.json()},update_org_subscription:async function({client:e,body:t}){const n="/org/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_payment_balance_for_any_org:async function({client:e,id:t,include_total_due:n,body:o}){const a=`/orgs/${t}/payment/balance`+s({include_total_due:n}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`),_["Content-Type"]="application/json";const p={method:"PUT",headers:_,body:JSON.stringify(o)},O=e?.fetch||fetch,T=await O(c,p);return await r(T),await T.json()},update_payment_balance_for_any_user:async function({client:e,id:t,include_total_due:n,body:o}){const a=`/users/${t}/payment/balance`+s({include_total_due:n}),c=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+a,i=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",_={};i&&(_.Authorization=`Bearer ${i}`),_["Content-Type"]="application/json";const p={method:"PUT",headers:_,body:JSON.stringify(o)},O=e?.fetch||fetch,T=await O(c,p);return await r(T),await T.json()},update_payment_information_for_org:async function({client:e,body:t}){const n="/org/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_payment_information_for_user:async function({client:e,body:t}){const n="/user/payment"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},update_user_subscription:async function({client:e,body:t}){const n="/user/payment/subscriptions"+s({}),o=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+n,a=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",c={};a&&(c.Authorization=`Bearer ${a}`),c["Content-Type"]="application/json";const i={method:"PUT",headers:c,body:JSON.stringify(t)},_=e?.fetch||fetch,p=await _(o,i);return await r(p),await p.json()},validate_customer_tax_information_for_org:async function({client:e}={}){const t="/org/payment/tax"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);},validate_customer_tax_information_for_user:async function({client:e}={}){const t="/user/payment/tax"+s({}),n=(e?.baseUrl||process?.env?.ZOO_HOST||process?.env?.BASE_URL||"https://api.zoo.dev")+t,o=e?e.token||process.env.ZOO_API_TOKEN||"":process.env.KITTYCAD_TOKEN||process.env.KITTYCAD_API_TOKEN||process.env.ZOO_API_TOKEN||"",a={};o&&(a.Authorization=`Bearer ${o}`);const c={method:"GET",headers:a},i=e?.fetch||fetch,_=await i(n,c);await r(_);}};
25203
+
25204
+ /**
25205
+ * Adapted from https://github.com/KittyCAD/text-to-cad-ui/blob/309a2e756732b7b9a2b095d6a0f99bc23872d542/src/lib/billing.ts
25206
+ */
25207
+ var EBillingError;
25208
+ (function (EBillingError) {
25209
+ EBillingError[EBillingError["NotOk"] = 0] = "NotOk";
25210
+ EBillingError[EBillingError["UnexpectedStatus"] = 1] = "UnexpectedStatus";
25211
+ EBillingError[EBillingError["CatastrophicRequest"] = 2] = "CatastrophicRequest";
25212
+ EBillingError[EBillingError["JSONParse"] = 3] = "JSONParse";
25213
+ })(EBillingError || (EBillingError = {}));
25214
+ class BillingError {
25215
+ constructor(error) {
25216
+ Object.defineProperty(this, "error", {
25217
+ enumerable: true,
25218
+ configurable: true,
25219
+ writable: true,
25220
+ value: error
25221
+ });
25222
+ }
25223
+ static from(v) {
25224
+ return (typeof v === 'object' &&
25225
+ 'error' in v &&
25226
+ 'type' in v.error &&
25227
+ Object.values(EBillingError).some((x) => x === v.error.type));
25228
+ }
25229
+ }
25230
+ async function fetchBilling(fn, options) {
25231
+ try {
25232
+ const response = await fn(options);
25233
+ if (response === null) {
25234
+ return new BillingError({
25235
+ type: EBillingError.CatastrophicRequest,
25236
+ });
25237
+ }
25238
+ if (typeof response === 'number') {
25239
+ return new BillingError({
25240
+ type: EBillingError.UnexpectedStatus,
25241
+ code: Number(response),
25242
+ });
25243
+ }
25244
+ return response;
25245
+ }
25246
+ catch (e) {
25247
+ if (e && typeof e === 'object' && 'status' in e && 'body' in e) {
25248
+ const fallbackErrorMessage = `Failed to request endpoint: ${e.status}`;
25249
+ const data = e.body;
25250
+ const resolvedMessage = data instanceof Object && 'message' in data
25251
+ ? data.message
25252
+ : fallbackErrorMessage;
25253
+ return new BillingError({
25254
+ type: EBillingError.NotOk,
25255
+ response: e,
25256
+ data: JSON.stringify(data),
25257
+ message: resolvedMessage,
25258
+ });
25259
+ }
25260
+ if (e instanceof SyntaxError) {
25261
+ return new BillingError({
25262
+ type: EBillingError.JSONParse,
25263
+ error: e,
25264
+ });
25265
+ }
25266
+ return new BillingError({
25267
+ type: EBillingError.CatastrophicRequest,
25268
+ });
25269
+ }
25270
+ }
25271
+ async function getBillingInfo(client) {
25272
+ const billing = await fetchBilling($.get_payment_balance_for_user, { client, include_total_due: false });
25273
+ if (BillingError.from(billing)) {
25274
+ return billing;
25275
+ }
25276
+ const subscriptions = await fetchBilling($.get_user_subscription, { client });
25277
+ const org = await fetchBilling(k.get_user_org, { client });
25278
+ if (!BillingError.from(org)) {
25279
+ // Org override here. TODO for api: remove the need for this
25280
+ // If the user is part of an org, they get infinite credits.
25281
+ return {
25282
+ credits: Number.POSITIVE_INFINITY,
25283
+ isOrg: true,
25284
+ hasSubscription: true,
25285
+ };
25286
+ }
25287
+ if (BillingError.from(subscriptions)) {
25288
+ return subscriptions;
25289
+ }
25290
+ const tier = subscriptions.modeling_app.name;
25291
+ const computedAllowance = subscriptions.modeling_app.monthly_pay_as_you_go_api_credits;
25292
+ const computedCredits = Number(billing.monthly_api_credits_remaining) +
25293
+ Number(billing.stable_api_credits_remaining);
25294
+ let allowance;
25295
+ let credits;
25296
+ let hasSubscription;
25297
+ let isOrg;
25298
+ switch (tier) {
25299
+ case 'enterprise':
25300
+ case 'team':
25301
+ credits = Number.POSITIVE_INFINITY;
25302
+ hasSubscription = true;
25303
+ isOrg = true;
25304
+ break;
25305
+ case 'pro':
25306
+ credits = Number.POSITIVE_INFINITY;
25307
+ hasSubscription = true;
25308
+ isOrg = false;
25309
+ break;
25310
+ case 'plus':
25311
+ allowance = computedAllowance;
25312
+ credits = computedCredits;
25313
+ isOrg = false;
25314
+ hasSubscription = true;
25315
+ break;
25316
+ case 'free':
25317
+ allowance = computedAllowance;
25318
+ credits = computedCredits;
25319
+ isOrg = false;
25320
+ hasSubscription = false;
25321
+ break;
25322
+ default: {
25323
+ const _exh = tier;
25324
+ throw new Error(`Unhandled subscription tier: ${_exh}`);
25325
+ }
25326
+ }
25327
+ return {
25328
+ allowance,
25329
+ credits,
25330
+ hasSubscription,
25331
+ isOrg,
25332
+ };
25333
+ }
25334
+
25335
+ export { BillingDialog, BillingError, BillingRemaining, BillingRemainingMode, Button, CustomIcon, EmailLoginForm, LoginTitle, SignInPageContent, Spinner, cn, getBillingInfo };
21832
25336
  //# sourceMappingURL=index.esm.js.map