import*as text from"./textUtilities.js";const DEFAULT_THROTTLE_DELAY=100;let next=0,seed=(new Date).valueOf();const guid="5DDC9A38-AAAB-44C1-AD87-415160F43D75";function makeId(){return 2147483648<=next&&(seed=(new Date).valueOf(),next=0),`${guid}:${seed}:${next++}`}function indexOf(e,t){if(null!=e){e=e.index;return"number"==typeof e?e:t}}function compareIndex(e,t){return compareNumber(e.index,t.index)}function compareNumber(e,t){return e<t?-1:t<e?1:0}function sort(e,t){void 0===t&&(t=indexOf);const n={};if("object"!=typeof e||null===e)return n;let i=0;const r=[];for(const a in e){var s=e[a],o=t(s,i++);"number"==typeof o&&r.push({key:a,index:o,item:s})}for(const u of r.sort(compareIndex))n[u.key]=u.item;return n}function sortItems(e){let t=e.current;var n=e.value,i=sort(e.items,function(e,t){if(null!=e&&!1!==e.visible){e=e.index;return"number"==typeof e?e:t}});if(void 0!==t&&null!==t&&void 0!==i[t]||(t=void 0),void 0===t&&null!=n)for(const r in i){if(i[r].value===n)break;t=void 0}return void 0!==t?(e.current=t,e.label=i[t].label,e.value=i[t].value):(e.current=void 0,e.label=void 0,e.value=void 0),i}function stripClassName(e,t){return e.className.split(" ").filter(e=>0<e.length&&e!==t).join(" ")}function makeSafeClassName(e){return`gcx-forms-${e&&e.replace(/[\W]/g,"")||"element"}`}let idSuffix=0;function makeUniqueId(e){return`${makeSafeClassName(e)}-${++idSuffix}`}function addClass(e,t){void 0!==e.classList?e.classList.add(t):e.className=stripClassName(e,t)+" "+t}function removeClass(e,t){void 0!==e.classList?e.classList.remove(t):e.className=stripClassName(e,t)}function setClass(e,t,n){(n?addClass:removeClass)(e,t)}function isObjectType(e,t){return"object"==typeof e&&null!==e&&(!Array.isArray(e)&&e.refValueType===t)}function isBoolean(e){return"boolean"==typeof e}function isNumber(e){return"number"==typeof e}function isString(e){return"string"==typeof e}function isDataRef(e){return isObjectType(e,"data")}function isDateTimeRef(e){return isObjectType(e,"date")||isObjectType(e,"time")||isObjectType(e,"datetime")}function isFilesRef(e){return isObjectType(e,"files")}function isScanRef(e){return isObjectType(e,"scan")}function isGeometryRef(e){return isObjectType(e,"geometry")}function isItemsRef(e){return isObjectType(e,"items")}function isNumberRef(e){return isObjectType(e,"number")}function sanitizeGeometryRef(e){if(isGeometryRef(e)){var t=e.geometry;if(Array.isArray(t)&&0<t.length)switch(e.format){case"point":case"polygon":case"polyline":case"polygon-freehand":case"polyline-freehand":case"extent":case"line":return e}}}function createGeometryRef(e){return{refValueType:"geometry",format:e,geometry:[]}}function addStyleToDocument(e){const t=document.createElement("style");t.appendChild(document.createTextNode(e));const n=document.head;return n.insertBefore(t,n.firstChild),t}function throttle(r,s=DEFAULT_THROTTLE_DELAY){let o,a;return function(){const e=this,t=arguments;function n(){a=void 0,o=Date.now(),r.apply(e,t)}var i=Date.now();o&&i<o+s?(clearTimeout(a),a=setTimeout(n,s)):n()}}function isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}export{text,makeId,sort,sortItems,makeSafeClassName,makeUniqueId,addClass,removeClass,setClass,isBoolean,isNumber,isString,isDataRef,isDateTimeRef,isFilesRef,isScanRef,isGeometryRef,isItemsRef,isNumberRef,sanitizeGeometryRef,createGeometryRef,addStyleToDocument,throttle,isNumeric};