UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 37.1 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import t from"../core/Collection.js";import{assertIsSome as i}from"../core/maybe.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import{cast as s}from"../core/accessorSupport/decorators/cast.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as o}from"../core/accessorSupport/decorators/subclass.js";import r from"./Widget.js";import{css as a}from"./Slider/css.js";import l from"./Slider/SliderViewModel.js";import{globalCss as h}from"./support/globalCss.js";import{onResize as u}from"./support/widgetUtils.js";import{messageBundle as c}from"./support/decorators/messageBundle.js";import{tsx as d}from"./support/jsxFactory.js";import{substitute as m}from"../intl/substitute.js";const _={showInput:"Enter",hideInput1:"Enter",hideInput2:"Escape",hideInput3:"Tab",moveAnchorUp:"ArrowUp",moveAnchorDown:"ArrowDown",moveAnchorLeft:"ArrowLeft",moveAnchorRight:"ArrowRight",moveAnchorToMax:"End",moveAnchorToMin:"Home"},p={labels:!1,rangeLabels:!1};let v=class extends r{constructor(e,i){super(e,i),this._activeLabelInputIndex=null,this._anchorElements=[],this._dragged=!1,this._dragStartInfo=null,this._focusedAnchorIndex=null,this._isMinInputActive=!1,this._isMaxInputActive=!1,this._lastMovedHandleIndex=null,this._positionPrecision=5,this._segmentDragStartInfo=null,this._trackHeight=null,this._trackWidth=null,this._zIndices=[],this._zIndexOffset=3,this.disabled=!1,this.draggableSegmentsEnabled=!0,this.effectiveSegmentElements=new t,this.extraNodes=[],this.inputCreatedFunction=null,this.labelElements=new t,this.labelInputsEnabled=!1,this.maxLabelElement=null,this.messages=null,this.minLabelElement=null,this.rangeLabelInputsEnabled=!1,this.segmentElements=new t,this.snapOnClickEnabled=!0,this.steps=null,this.syncedSegmentsEnabled=!1,this.thumbCreatedFunction=null,this.thumbElements=new t,this.tickElements=new t,this.trackElement=null,this.viewModel=new l,this.visibleElements={...p},this._onAnchorPointerDown=this._onAnchorPointerDown.bind(this),this._onAnchorPointerMove=this._onAnchorPointerMove.bind(this),this._onAnchorPointerUp=this._onAnchorPointerUp.bind(this),this._onLabelPointerDown=this._onLabelPointerDown.bind(this),this._onLabelPointerUp=this._onLabelPointerUp.bind(this),this._onSegmentPointerDown=this._onSegmentPointerDown.bind(this),this._onSegmentPointerMove=this._onSegmentPointerMove.bind(this),this._onSegmentPointerUp=this._onSegmentPointerUp.bind(this),this._onTrackPointerDown=this._onTrackPointerDown.bind(this),this._onTrackPointerMove=this._onTrackPointerMove.bind(this),this._onTrackPointerUp=this._onTrackPointerUp.bind(this)}destroy(){document.removeEventListener("pointerup",this._onLabelPointerUp),document.removeEventListener("pointermove",this._onLabelPointerMove),document.removeEventListener("pointerup",this._onAnchorPointerUp),document.removeEventListener("pointermove",this._onAnchorPointerMove),this.labelElements.removeAll(),this.labelElements.destroy(),this.segmentElements.removeAll(),this.segmentElements.destroy(),this.effectiveSegmentElements.removeAll(),this.effectiveSegmentElements.destroy(),this.thumbElements.removeAll(),this.thumbElements.destroy(),this.tickElements.removeAll(),this.tickElements.destroy()}get _isDisabled(){return this.disabled||"disabled"===this.state}get effectiveMax(){return this.viewModel.effectiveMax}set effectiveMax(e){this.viewModel.effectiveMax=e}get effectiveMin(){return this.viewModel.effectiveMin}set effectiveMin(e){this.viewModel.effectiveMin=e}get inputFormatFunction(){return this.viewModel.inputFormatFunction}set inputFormatFunction(e){this.viewModel.inputFormatFunction=e}get inputParseFunction(){return this.viewModel.inputParseFunction}set inputParseFunction(e){this.viewModel.inputParseFunction=e}get icon(){return"caret-double-horizontal"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get labelFormatFunction(){return this.viewModel.labelFormatFunction}set labelFormatFunction(e){this.viewModel.labelFormatFunction=e}get labels(){return this.viewModel.labels}set layout(e){["vertical","vertical-reversed","horizontal","horizontal-reversed"].includes(e)||(e="horizontal"),this._set("layout",e)}get max(){return this.viewModel.max}set max(e){this.viewModel.max=e}get min(){return this.viewModel.min}set min(e){this.viewModel.min=e}get precision(){return this.viewModel.precision}set precision(e){this.viewModel.precision=e}get state(){const{_activeLabelInputIndex:e,_isMaxInputActive:t,_isMinInputActive:i,_dragStartInfo:n,_segmentDragStartInfo:s,disabled:o,viewModel:r}=this;return o?"disabled":!(null===e&&!t&&!i)?"editing":null!=n||null!=s?"dragging":r.state}get thumbsConstrained(){return this.viewModel.thumbsConstrained}set thumbsConstrained(e){this.viewModel.thumbsConstrained=e}set tickConfigs(e){this._set("tickConfigs",e),this.scheduleRender()}get values(){return this.viewModel.values}set values(e){this.viewModel.values=e}castVisibleElements(e){return{...p,...e}}render(){const{label:e}=this,t=this.classes(a.base,h.widget,this._isHorizontalLayout()?a.horizontalLayout:a.verticalLayout,this._isReversedLayout()?a.reversed:null,this._isDisabled?h.disabled:null);return this._storeTrackDimensions(),d("div",{afterCreate:this._afterContainerCreate,"aria-label":e,bind:this,class:t,"touch-action":"none"},this._renderContent())}toNextStep(e){this._toStep(e,1)}toPreviousStep(e){this._toStep(e,-1)}getCurrentPosition(){return this._positionFromValue(this.values?.[0]??0)}_renderContent(){const{max:e,min:t}=this;if(!(null==t||null==e||t>=e))return[this._renderMin(),this._renderSliderContainer(),this._renderMax()]}_renderSliderContainer(){return d("div",{bind:this,class:a.contentElement,key:"slider-container"},this._renderTrackElement(),this._renderTicksContainer(),this._renderExtraContentElements())}_renderTrackElement(){return d("div",{afterCreate:this._afterTrackCreate,afterRemoved:this._afterTrackRemoved,bind:this,class:a.trackElement,"touch-action":"none"},this._renderEffectiveSegmentElements(),this._renderSegmentElements(),this._renderAnchorElements())}_renderEffectiveSegmentElements(){if(!this.trackElement||!this.values?.length)return;const e=null!=this.effectiveMax,t=null!=this.effectiveMin;if(!e&&!t)return;const{max:i,min:n,viewModel:s}=this,o=s.getBounds(),r=[];return t&&r.push(this._renderEffectiveSegmentElement(n,o.min,!0)),e&&r.push(this._renderEffectiveSegmentElement(o.max,i,!1)),r}_renderSegmentElements(){if(!this.trackElement||!this.values?.length)return;const e=this.values.length,t=[];for(let i=0;i<=e;i++)t.push(this._renderSegmentElement(i));return t}_renderSegmentElement(e){const{_trackHeight:t,_trackWidth:i,draggableSegmentsEnabled:n,id:s,state:o}=this,r=this.values,l=this._isHorizontalLayout(),h=l?i:t,u=this.viewModel.getBounds(),c=this._positionFromValue(u.max),m=this._positionFromValue(u.min),_=e===r?.length?null:e,p=0===e?null:e-1,v=null!=_,g=null!=p;let f,b;const E=[...r].sort(((e,t)=>e-t));this._isReversedLayout()?(f=g?this._positionFromValue(E[p]):m,b=v?this._positionFromValue(E[_]):c):(f=v?this._positionFromValue(E[_]):c,b=g?this._positionFromValue(E[p]):m);const x=this._applyPrecisionToPosition(100*b/h),y=(f-b)/h,k=l?`transform: translate(${x}%, 0px) scale(${y}, 1);`:`transform: translate(0px, ${x}%) scale(1, ${y});`,P=this.classes(a.segmentElement,a.segmentElementIndexPrefix+e,n&&v&&g&&"disabled"!==o?a.segmentElementInteractive:null);return d("div",{afterCreate:this._afterSegmentCreate,afterRemoved:this._afterSegmentRemoved,bind:this,class:P,"data-max-thumb-index":_,"data-min-thumb-index":p,"data-segment-index":e,key:`${s}-segment-${e}`,style:k,"touch-action":"none"})}_renderEffectiveSegmentElement(e,t,i){const{_trackHeight:n,_trackWidth:s,layout:o}=this,r=this._positionFromValue(e),l=this._positionFromValue(t),h=this._isHorizontalLayout(),u=h?s:n,c=this._applyPrecisionToPosition(100*r/u);let m=null;if("horizontal"===o){const e=i?u-l:l,t=r===u?0:c;m=`clip-path: inset(0% ${l===u?0:this._applyPrecisionToPosition(e/u*100)}% 0% ${t}%);`}else{const e=(l-r)/u;m=h?`transform: translate(${c}%, 0px) scale(${e}, 1);`:`transform: translate(0px, ${c}%) scale(1, ${e});`}const _=i?a.effectiveMinSegmentElement:a.effectiveMaxSegmentElement,p=this.classes(a.segmentElement,a.effectiveSegmentElement,_);return d("div",{afterCreate:this._afterEffectiveSegmentCreate,afterRemoved:this._afterEffectiveSegmentRemoved,bind:this,class:p,style:m,"touch-action":"none"})}_renderAnchorElements(){const{trackElement:e,values:t}=this;if(t?.length)return this._zIndices=t.map(((e,i)=>{const n=this._positionFromValue(e),s=this._positionToPercent(n),o=(this._isHorizontalLayout()?s>50:s<50)?-1:1;return this._zIndexOffset+(t.length+o*i)})),e&&t&&t.length?t.map(((e,t)=>this._renderAnchorElement(e,t))):null}_renderAnchorElement(e,t){const i=this._positionFromValue(e),n=this._valueFromPosition(i);if(null==n||isNaN(n))return;const{_dragStartInfo:s,_lastMovedHandleIndex:o,id:r,layout:l,visibleElements:{labels:h}}=this,u=this.values,c=s&&s.index===t,_=o===t,p=this.classes(a.anchorElement,a.anchorElementIndexPrefix+t,c?a.movingAnchorElement:null,_?a.lastMovedAnchorElement:null),v=this.labels.values[t],g=this._getStyleForAnchor(e,t,c||_),{min:f,max:b}=this.viewModel.getBoundsForValueAtIndex(t),{disabled:E,messages:x}=this,y=2===u.length?m(0===t?x.rangeMinimum:x.rangeMaximum,{value:e}):v,k=1===u.length?null:0===t?`${r}-handle-${t+1}`:t===u.length-1?`${r}-handle-${t-1}`:`${r}-handle-${t-1} ${r}-handle-${t+1}`;return d("div",{afterCreate:this._afterAnchorCreate,afterRemoved:this._afterAnchorRemoved,afterUpdate:this._afterAnchorUpdate,"aria-controls":k,"aria-label":x.sliderValue,"aria-labelledby":h?`${r}-label-${t}`:null,"aria-orientation":l,"aria-valuemax":b?.toString(),"aria-valuemin":f?.toString(),"aria-valuenow":e.toString(),"aria-valuetext":y,bind:this,class:p,"data-thumb-index":t,"data-value":e,id:`${r}-handle-${t}`,key:`${r}-handle-${t}`,onkeydown:this._onAnchorKeyDown,role:"slider",style:g,tabIndex:E?-1:0,"touch-action":"none"},d("span",{afterCreate:this._afterThumbCreate,afterRemoved:this._afterThumbRemoved,bind:this,class:a.thumbElement,"data-thumb-index":t,"touch-action":"none"}),this.renderThumbLabel(t))}renderThumbLabel(e){const{id:t,labels:i,labelInputsEnabled:n,state:s}=this,o=this.visibleElements.labels,r=i.values[e],l=this.classes(a.labelElement,o?null:h.hidden,n&&"disabled"!==s?a.labelElementInteractive:null);return d("span",{afterCreate:this._afterLabelCreate,afterRemoved:this._afterLabelRemoved,"aria-hidden":(!o).toString(),bind:this,class:l,"data-thumb-index":e,id:`${t}-label-${e}`,key:`${t}-label-${e}`,role:n?"button":void 0,"touch-action":"none"},this._activeLabelInputIndex===e?this._renderValueInput(e):r)}_renderValueInput(e){const{disabled:t,values:i}=this;if(null==i)return;const n=i[e];return d("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.sliderValue,bind:this,class:a.labelInput,"data-input-index":e,"data-input-type":"thumb",key:`value-input-${e}`,onblur:this._onLabelInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:t?-1:0,type:"text",value:this._formatInputValue(n,"value",e)})}_renderMax(){const{_isMaxInputActive:e,labels:t,rangeLabelInputsEnabled:i,state:n}=this,s=this.visibleElements.rangeLabels,o=this.classes(a.maxElement,{[h.hidden]:!s,[a.maxElementInteractive]:i&&"disabled"!==n,[a.rangeElementActive]:e});return d("div",{afterCreate:this._afterMaxLabelCreate,"aria-hidden":(!s).toString(),bind:this,class:o,onclick:this._onMaxLabelClick,onkeydown:this._onMaxLabelKeyDown,role:i?"button":void 0,tabIndex:!this.disabled&&i?0:-1},e?this._renderMaxInput():t.max)}_renderMin(){const{_isMinInputActive:e,labels:t,rangeLabelInputsEnabled:i,state:n}=this,s=this.visibleElements.rangeLabels,o=this.classes(a.minElement,{[h.hidden]:!s,[a.minElementInteractive]:i&&"disabled"!==n,[a.rangeElementActive]:e});return d("div",{afterCreate:this._afterMinLabelCreate,"aria-hidden":(!s).toString(),bind:this,class:o,onclick:this._onMinLabelClick,onkeydown:this._onMinLabelKeyDown,role:i?"button":void 0,tabIndex:!this.disabled&&i?0:-1},e?this._renderMinInput():t.min)}_renderMaxInput(){return d("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.maximumValue,bind:this,class:a.rangeInput,"data-input-type":"max",onblur:this._onMaxInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:this.disabled?-1:0,type:"text",value:this._formatInputValue(this.max,"max")})}_renderMinInput(){return d("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.minimumValue,bind:this,class:a.rangeInput,"data-input-type":"min",onblur:this._onMinInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:this.disabled?-1:0,type:"text",value:this._formatInputValue(this.min,"min")})}_renderExtraContentElements(){return d("div",{bind:this,class:a.extraContentElement},this.extraNodes)}_renderTicksContainer(){if(this.tickConfigs&&this.trackElement&&(0!==this._trackHeight||0!==this._trackWidth))return this.tickConfigs.map(((e,t)=>d("div",{class:this.classes(a.ticksContainerElement),key:"ticks-container"},this._renderTicks(e,t))))}_renderTicks(e,i){const{mode:n,values:s}=e;if(this.tickElements.at(i)||this.tickElements.add(new t,i),"position"===n){const t=Array.isArray(s)?s:[s];return this._calculateTickPositions(t).map(((t,n)=>this._renderTickGroup(e,n,i,t)))}if("percent"===n&&Array.isArray(s)){const t=this.min??0,n=(this.max??0)-t,o=s.map((e=>this._applyPrecisionToPosition(e/100*n+t)));return this._calculateTickPositions(o).map(((t,n)=>this._renderTickGroup(e,n,i,t)))}const o=Array.isArray(s)&&s.length?s[0]:isNaN(s)?null:s,r=this._getTickCounts(o,e);return this._calculateEquidistantTickPositions(r).map(((t,n)=>this._renderTickGroup(e,n,i,t)))}_renderTickGroup(e,t,i,n){const s="position"===e.mode?Array.isArray(e.values)?e.values[t]:e.values:this._valueFromPosition(n);if(null!=s&&!isNaN(s))return d("div",{afterCreate:this._afterTickGroupCreate,afterRemoved:this._afterTickGroupRemoved,bind:this,"data-config":e,"data-position":n,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":s,key:`tick-group-${t}`,onclick:this._onTickGroupClick},this._renderTickLine(e,t,i,s),e.labelsVisible?this._renderTickLabel(e,t,i,s):null)}_renderTickLine(e,t,i,n){return d("div",{afterCreate:this._afterTickLineCreate,"aria-valuenow":n.toString(),bind:this,class:a.tickElement,"data-config":e,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":n,key:`tick-label-${t}`,style:this._getPositionStyleForElement(n)})}_renderTickLabel(e,t,i,n){const s=e.labelFormatFunction?e.labelFormatFunction(n,"tick",t):this.viewModel.getLabelForValue(n,"tick",t);return d("div",{afterCreate:this._afterTickLabelCreate,"aria-label":s,"aria-valuenow":n.toString(),"aria-valuetext":s,bind:this,class:a.tickLabelElement,"data-config":e,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":n,key:`tick-label-${t}`,style:`transform: translate(-50%); ${this._getPositionStyleForElement(n)}`},s)}_afterContainerCreate(e){this.addHandles(u(e,(()=>this.scheduleRender())))}_afterTrackCreate(e){this._set("trackElement",e),e.addEventListener("pointerdown",this._onTrackPointerDown),this.scheduleRender()}_afterTrackRemoved(e){e.removeEventListener("pointerdown",this._onTrackPointerDown),document.removeEventListener("pointermove",this._onTrackPointerMove),document.removeEventListener("pointerup",this._onTrackPointerUp)}_afterSegmentCreate(e){this.segmentElements.add(e),e.addEventListener("pointerdown",this._onSegmentPointerDown)}_afterSegmentRemoved(e){this.segmentElements.remove(e),e.removeEventListener("pointerdown",this._onSegmentPointerDown)}_afterEffectiveSegmentCreate(e){this.effectiveSegmentElements.add(e)}_afterEffectiveSegmentRemoved(e){this.effectiveSegmentElements.remove(e)}_afterAnchorCreate(e){if(this._anchorElements.push(e),e.addEventListener("pointerdown",this._onAnchorPointerDown),this.thumbCreatedFunction){const t=g(e),i=y(e),n=this.thumbElements.at(t),s=this.labelElements.at(t)||null;this.thumbCreatedFunction(t,i,n,s)}}_afterAnchorUpdate(e){if(null!=this._focusedAnchorIndex){g(e)===this._focusedAnchorIndex&&(e.focus(),this._focusedAnchorIndex=null)}}_afterAnchorRemoved(e){const t=this._anchorElements.indexOf(e,0);t>-1&&this._anchorElements.splice(t,1),e.removeEventListener("pointerdown",this._onAnchorPointerDown)}_afterThumbCreate(e){this.thumbElements.add(e)}_afterThumbRemoved(e){this.thumbElements.remove(e)}_afterLabelCreate(e){this.labelElements.add(e),e.addEventListener("pointerdown",this._onLabelPointerDown),e.addEventListener("pointerup",this._onLabelPointerUp)}_afterLabelRemoved(e){this.labelElements.remove(e),e.removeEventListener("pointerdown",this._onLabelPointerDown),e.removeEventListener("pointerup",this._onLabelPointerUp)}_afterInputCreate(e){if(e.focus(),e.select(),this.inputCreatedFunction){const t=e.getAttribute("data-input-type"),i="thumb"===t?f(e):null;this.inputCreatedFunction(e,t,i)}}_afterTickLineCreate(e){const t=k(e),i=P(e),n=this.tickElements.at(t),s=n.at(i);s?s.tickElement=e:n.add({groupElement:null,tickElement:e,labelElement:null},i)}_afterTickLabelCreate(e){const t=k(e),i=P(e),n=this.tickElements.at(t),s=n.at(i);s?s.labelElement=e:n.add({groupElement:null,labelElement:e,tickElement:null},i)}_afterTickGroupRemoved(e){const t=k(e),i=this.tickElements.items[t],n=i?.find((t=>t.groupElement===e));n&&i.remove(n)}_afterTickGroupCreate(e){const t=I(e);if(t?.tickCreatedFunction){const i=k(e),n=P(e),s=y(e),o=this.tickElements?.at(i)?.at(n);if(o){o.groupElement=e;const i=o.tickElement||null,n=o.labelElement||null;t.tickCreatedFunction(s,i,n)}}}_afterMaxLabelCreate(e){this._set("maxLabelElement",e)}_afterMinLabelCreate(e){this._set("minLabelElement",e)}_onAnchorKeyDown(e){if(this._isDisabled||"editing"===this.state)return;const{key:t,target:i}=e,n=this.values,s=g(i),o=this._anchorElements[s],r=n[s],a=[_.moveAnchorUp,_.moveAnchorDown,_.moveAnchorLeft,_.moveAnchorRight];if(t===_.showInput&&this.labelInputsEnabled)this._activeLabelInputIndex=s;else if(a.includes(t)){e.preventDefault();const{steps:i}=this,n=t===_.moveAnchorUp||t===_.moveAnchorRight?1:-1;if(null!=i)this._toStep(s,this._isReversedLayout()?-1*n:n);else{const{precision:e}=this,t=this._getPositionOfElement(o),i=this._valueFromPosition(t),r=this._isHorizontalLayout()?n:-1*n;let a;a=0===e?this._positionFromValue(i+r):1===e?this._positionFromValue(i+.1*r):t+r,this._toPosition(s,a)}const a=this.values[s];r!==a&&this._emitThumbChangeEvent({index:s,oldValue:r,value:a})}else if(t===_.moveAnchorToMax||t===_.moveAnchorToMin){e.preventDefault();const{min:i,max:n}=this._getAnchorBoundsInPixels(s),o=this._isPositionInverted()?t===_.moveAnchorToMax?i:n:t===_.moveAnchorToMin?i:n;this._toPosition(s,o);const a=this.values[s];r!==a&&this._emitThumbChangeEvent({index:s,oldValue:r,value:a})}}_onAnchorPointerDown(e){if(this._isDisabled)return;const{target:t,clientX:i,clientY:n}=e,s=g(t);null!=s&&(e.preventDefault(),this._anchorElements[s]&&this._anchorElements[s].focus(),this._storeTrackDimensions(),this._dragStartInfo={clientX:i,clientY:n,index:s,position:this._getPositionOfElement(this._anchorElements[s])},document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove))}_onAnchorPointerMove(e){if("editing"===this.state||!this._dragStartInfo)return;e.preventDefault();const{values:t,_anchorElements:i,_dragged:n,_dragStartInfo:s,_dragStartInfo:{index:o,position:r}}=this,{clientX:a,clientY:l}=e,h=n?"drag":"start",u=i[o],c=this._getPositionOfElement(u),d=this._applyPrecisionToPosition(this._isHorizontalLayout()?r+a-s.clientX:r+l-s.clientY);if(c===d)return;const m=t[o];this._dragged=!0,this._toPosition(o,d);const _=this.values[o];n?m!==_&&this._emitThumbDragEvent({index:o,state:h,value:_}):this._emitThumbDragEvent({index:o,state:h,value:m})}_onAnchorPointerUp(e){if(document.removeEventListener("pointerup",this._onAnchorPointerUp),document.removeEventListener("pointermove",this._onAnchorPointerMove),!this._dragStartInfo)return;e.preventDefault();const{index:t}=this._dragStartInfo,i=this._dragged,n=this.values[t];this._dragged=!1,this._dragStartInfo=null,this._lastMovedHandleIndex=t,i?this._emitThumbDragEvent({index:t,state:"stop",value:n}):(this.scheduleRender(),"editing"!==this.state&&this._emitThumbClickEvent({index:t,value:n}))}_onTrackPointerDown(e){const{_dragStartInfo:t,snapOnClickEnabled:i,state:n,values:s}=this;if(this._isDisabled||"editing"===n||t)return;if(document.addEventListener("pointermove",this._onTrackPointerMove),document.addEventListener("pointerup",this._onTrackPointerUp),!i||!s?.length)return;const{steps:o}=this,{clientX:r,clientY:a}=e,l=this._getCursorPositionFromEvent(e),h=this._valueFromPosition(l),u=this._getIndexOfNearestValue(h),c=s[u],d=s.some(((e,t)=>e===c&&t!==u))&&h>c?s.lastIndexOf(c):u;if(null==d)return;const m=s[d],_=null!=o?this._calculateNearestStepPosition(l):l;this._toPosition(d,_),this._dragged=!0,this._dragStartInfo={clientX:r,clientY:a,index:d,position:_},this._focusedAnchorIndex=d,this._emitThumbDragEvent({index:d,state:"start",value:m});const p=this.values[d];m!==p&&this._emitThumbDragEvent({index:d,state:"drag",value:p}),document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove)}_onTrackPointerMove(e){e.preventDefault(),this._dragged=!0}_onTrackPointerUp(e){if(e.preventDefault(),document.removeEventListener("pointermove",this._onTrackPointerMove),document.removeEventListener("pointerup",this._onTrackPointerUp),this.snapOnClickEnabled||(this._dragged=!1),!this._dragged){const t=this._getCursorPositionFromEvent(e),i=this._valueFromPosition(t);this._emitTrackClickEvent({value:i})}}_onSegmentPointerDown(e){e.preventDefault();const t=e.target,i=b(t),n=E(t),s=x(t);if(this._isDisabled||null==n||null==s)return;e.stopPropagation(),this._storeTrackDimensions(),document.addEventListener("pointerup",this._onSegmentPointerUp);const o=this._getAnchorDetails(n),r=this._getAnchorDetails(s);this.syncedSegmentsEnabled?(this.segmentElements.forEach((e=>e.classList.add(a.segmentElementActive))),this._anchorElements.forEach((e=>e.classList.add(a.anchorElementActive)))):(this.segmentElements.at(i).classList.add(a.segmentElementActive),this._anchorElements[o.index]?.classList.add(a.anchorElementActive),this._anchorElements[r.index]?.classList.add(a.anchorElementActive)),this._segmentDragStartInfo={cursorPosition:this._getCursorPositionFromEvent(e),index:i,details:this._normalizeSegmentDetails({min:o,max:r})},this.draggableSegmentsEnabled&&(document.addEventListener("pointermove",this._onSegmentPointerMove),this._emitSegmentDragEvent({index:i,state:"start",thumbIndices:[n,s]}))}_onSegmentPointerMove(e){if(!this._segmentDragStartInfo)return;e.preventDefault();const{_trackHeight:t,_trackWidth:i,_segmentDragStartInfo:{index:n,cursorPosition:s,details:{min:o,max:r}}}=this,{index:a,position:l,value:h}=o,{index:u,position:c,value:d}=r;this._dragged=!0;const m=this._getCursorPositionFromEvent(e);if(m===s)return;const _=this._positionToPercent(s),p=this._positionToPercent(m)-_,v=this._positionToPercent(l)+p,g=this._positionToPercent(c)+p,{min:f}=this._getAnchorBoundsAsPercents(a),{max:b}=this._getAnchorBoundsAsPercents(u);let E=!1,x=!1;if(v<f?E=!0:g>b&&(x=!0),E){const{min:e,max:t}=this.viewModel.getBoundsForValueAtIndex(a),i=this._isPositionInverted()?t:e,n=i,s=d+(i-h),o=s-this.values[u];return void(this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(o):this._updateAnchorValues([a,u],[n,s]))}if(x){const{min:e,max:t}=this.viewModel.getBoundsForValueAtIndex(u),i=this._isPositionInverted()?e:t,n=i,s=h+(i-d),o=s-this.values[a];return void(this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(o):this._updateAnchorValues([a,u],[s,n]))}const y=this._isHorizontalLayout()?i:t,k=g/100*y,P=v/100*y,I=this.values,A=[I[a],I[u]],M=this._getValueForAnchorAtPosition(a,P),L=this._getValueForAnchorAtPosition(u,k);this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(M-A[0]):this._updateAnchorValues([a,u],[M,L]);[this.values[a],this.values[u]].every(((e,t)=>e===A[t]))||this._emitSegmentDragEvent({index:n,state:"drag",thumbIndices:[a,u]})}_onSegmentPointerUp(e){if(e.preventDefault(),document.removeEventListener("pointerup",this._onSegmentPointerUp),document.removeEventListener("pointermove",this._onSegmentPointerMove),!this._segmentDragStartInfo)return;const{_dragged:t}=this,i=this.min,n=this.max,s=this.values,{index:o,details:{min:{index:r},max:{index:l}}}=this._segmentDragStartInfo;if(this.segmentElements.forEach((e=>e.classList.remove(a.segmentElementActive))),this._anchorElements.forEach((e=>e.classList.remove(a.anchorElementActive))),this.draggableSegmentsEnabled){const e=n-i,t=s[r],a=s[l];this._lastMovedHandleIndex=t===a?t>e/2?r:l:null,this._dragged=!1,this._segmentDragStartInfo=null,this._emitSegmentDragEvent({index:o,state:"stop",thumbIndices:[r,l]})}if(!t){const t=this._getCursorPositionFromEvent(e),i=this._valueFromPosition(t);this._emitSegmentClickEvent({index:o,value:i,thumbIndices:[r,l]})}}_onTickGroupClick(e){const t=e.target;if(I(t)){const e=k(t),i=P(t),n=y(t);this._emitTickClickEvent({configIndex:e,groupIndex:i,value:n})}}_storeTrackDimensions(){if(this.trackElement){const e=this._getDimensions(this.trackElement);this._trackHeight=this._applyPrecisionToPosition(e.height),this._trackWidth=this._applyPrecisionToPosition(e.width)}}_onLabelPointerDown(){this._isDisabled||(this._dragged=!1,document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove))}_onLabelPointerMove(){this._isDisabled||(this._dragged=!0)}_onLabelPointerUp(e){if(this._isDisabled)return;const t=g(e.target);this.labelInputsEnabled&&!this._dragged&&null!=t&&(this._activeLabelInputIndex=t),this._dragged=!1,document.removeEventListener("pointerup",this._onLabelPointerUp),document.removeEventListener("pointermove",this._onLabelPointerMove)}_onLabelInputBlur(e){const{_activeLabelInputIndex:t,values:i,viewModel:n}=this,s=e.target.value;if(this._activeLabelInputIndex=null,!s||null==t||null==i)return;const o=this._parseInputValue(s,"value",t),r=i[t],{min:a,max:l}=this.viewModel.getBoundsForValueAtIndex(t);if(o<a||o>l)return;n.setValue(t,o);const h=this.values[t];r!==h&&this._emitThumbChangeEvent({index:t,oldValue:r,value:h})}_onInputKeyDown(e){if(this._isDisabled)return;const{key:t,target:i}=e,{hideInput1:n,hideInput2:s,hideInput3:o}=_,{_activeLabelInputIndex:r,_anchorElements:a}=this,l=i;if(t===n||t===s||t===o){e.stopPropagation();const t=r;l.blur(),null!=t?a[t].focus():l.parentElement?.focus()}}_onMaxLabelClick(){this._isDisabled||(this._emitMaxRangeLabelClickEvent({type:"max-click",value:this.max}),this.rangeLabelInputsEnabled&&(this._isMaxInputActive=!0))}_onMaxLabelKeyDown({key:e}){this._isDisabled||e!==_.showInput||(this._isMaxInputActive=!0)}_onMaxInputBlur(e){const t=e.target.value;if(this._isMaxInputActive=!1,!t)return;const i=this.max,n=this._parseInputValue(t,"max");n<=this.min||(this.viewModel.set("max",n),this.max!==i&&this._emitMaxChangeEvent({oldValue:i,value:this.max}))}_onMinLabelClick(){this._isDisabled||(this._emitMinRangeLabelClickEvent({type:"min-click",value:this.min}),this.rangeLabelInputsEnabled&&(this._isMinInputActive=!0))}_onMinLabelKeyDown({key:e}){this._isDisabled||e!==_.showInput||(this._isMinInputActive=!0)}_onMinInputBlur(e){const t=e.target.value;if(this._isMinInputActive=!1,!t)return;const i=this.min,n=this._parseInputValue(t,"min");n>=this.max||(this.viewModel.set("min",n),this.min!==i&&this._emitMinChangeEvent({oldValue:i,value:this.min}))}_positionFromValue(e){const{_trackHeight:t,_trackWidth:i}=this,n=this.min??0,s=this.max??0,o=s-n;if(0===o||null==e)return 0;const r=this._isHorizontalLayout();let a=r?this._applyPrecisionToPosition(i*(e-n)/o):this._applyPrecisionToPosition(t*(s-e)/o);return this._isReversedLayout()&&(a=r?i-a:t-a),a}_valueFromPosition(e){const{_trackHeight:t,_trackWidth:i,precision:n}=this,s=this.min??0,o=this.max??0,r=o-s;let a=this._isHorizontalLayout()?e*r/i+s:r*(1e3-e/t*1e3)/1e3+s;return this._isReversedLayout()&&(a=o+s-a),parseFloat(a.toFixed(n))}_positionToPercent(e){const{_trackHeight:t,_trackWidth:i}=this,n=100*e/(this._isHorizontalLayout()?i:t);return this._applyPrecisionToPosition(n)}_applyPrecisionToPosition(e){return parseFloat(e.toFixed(this._positionPrecision))}_isPositionInverted(){const{layout:e}=this;return"horizontal-reversed"===e||"vertical"===e}_isHorizontalLayout(){return this.layout.includes("horizontal")}_isReversedLayout(){return this.layout.includes("reversed")}_normalizeSegmentDetails(e){if(this._isPositionInverted()){const{min:t,max:i}=e;return{min:i,max:t}}return e}_parseInputValue(e,t,i){return this.inputParseFunction?this.inputParseFunction(e,t,i):this.viewModel.defaultInputParseFunction(e)}_formatInputValue(e,t,i){return this.inputFormatFunction?this.inputFormatFunction(e,t,i):this.viewModel.defaultInputFormatFunction(e)}_getAnchorDetails(e){const t=this.values,i=[...t].sort(((e,t)=>e-t))[e],n=t.indexOf(i);return{index:n,position:this._getPositionOfElement(this._anchorElements[n]),value:i}}_updateAnchorStyle(e,t){const i=this._anchorElements[e];i&&(this._isHorizontalLayout()?i.style.left=`${t}`:i.style.top=`${t}`)}_getStyleForAnchor(e,t,i){const n=this._getPositionStyleForElement(e);if(1===this.values?.length)return`${n}`;const s=this._zIndices[t];return`${n}; z-index: ${i?this._zIndexOffset+s:s}`}_getPositionStyleForElement(e){const t=this._positionFromValue(e),i=this._positionToPercent(t);return`${this._isHorizontalLayout()?"left":"top"}: ${i}%`}_getPositionOfElement(e){const t=this._getDimensions(e.offsetParent),i=this._getDimensions(e);return this._isHorizontalLayout()?this._applyPrecisionToPosition(i.left-t.left):this._applyPrecisionToPosition(i.top-t.top)}_updateAnchorValues(e,t){e.forEach(((e,i)=>this._toValue(e,t[i])))}_updateAnchorValuesByDifference(e){const{min:t,max:i,values:n}=this;n?.forEach(((n,s)=>this._toValue(s,Math.max(Math.min(n+e,i),t))))}_toValue(e,t){if(null!=this.steps){t=this._getStepValues()[this._getIndexOfNearestStepValue(t)]}this._updateAnchorStyle(e,this._getPositionStyleForElement(t)),this.viewModel.setValue(e,t)}_toPosition(e,t){const i=null!=this.steps?this._getStepValueForAnchorAtPosition(e,t):this._getValueForAnchorAtPosition(e,t);this._updateAnchorStyle(e,this._getPositionStyleForElement(i)),this.viewModel.setValue(e,i)}_getValueForAnchorAtPosition(e,t){const{min:i,max:n}=this._getAnchorBoundsInPixels(e),{min:s,max:o}=this.viewModel.getBoundsForValueAtIndex(e);let r,a,l=null;return this._isPositionInverted()?(r=s,a=o):(r=o,a=s),l=t>n?r:t<i?a:this._valueFromPosition(t),l>o?l=o:l<s&&(l=s),l}_getStepValueForAnchorAtPosition(e,t){const i=this._getStepValues(),n=this._calculateNearestStepPosition(t),s=this._getValueForAnchorAtPosition(e,n);return i[this._getIndexOfNearestStepValue(s)]}_getAnchorBoundsAsPercents(e){const{min:t,max:i}=this._getAnchorBoundsInPixels(e);return{min:this._positionToPercent(t),max:this._positionToPercent(i)}}_getAnchorBoundsInPixels(e){const{_anchorElements:t,_trackHeight:i,_trackWidth:n,effectiveMax:s,effectiveMin:o,thumbsConstrained:r}=this,a=t[e-1],l=t[e+1],h=this._isHorizontalLayout()?n:i;let u,c;return this._isPositionInverted()?(u=null!=o?this._positionFromValue(o):h,c=null!=s?this._positionFromValue(s):0):(u=null!=s?this._positionFromValue(s):h,c=null!=o?this._positionFromValue(o):0),r?this._isPositionInverted()?{max:a?this._getPositionOfElement(a):u,min:l?this._getPositionOfElement(l):c}:{max:l?this._getPositionOfElement(l):u,min:a?this._getPositionOfElement(a):c}:{max:u,min:c}}_getIndexOfNearestValue(e){const t=this.values;return t.indexOf(t.reduce(((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t)))}_getCursorPositionFromEvent(e){const t=this._getDimensions(this.trackElement);return this._isHorizontalLayout()?this._applyPrecisionToPosition(e.clientX-t.left):this._applyPrecisionToPosition(e.clientY-t.top)}_getStepValues(){const{steps:e}=this;if(Array.isArray(e))return e;const{max:t,min:i}=this;if(null==i||null==t||null==e)return[];const n=Math.ceil((t-i)/e),s=[];for(let o=0;o<=n;o++){const n=i+e*o;s.push(n>t?t:n)}return s}_toStep(e,t){const i=this.values[e],n=this._getStepValues(),s=n.indexOf(i);let o=null;if(s>-1){let i=n[s+t];isNaN(i)&&(i=n[s]);const r=this._positionFromValue(i);o=this._getStepValueForAnchorAtPosition(e,r)}else{o=n[this._getIndexOfNearestStepValue(i)+t]}this.viewModel.setValue(e,o)}_getIndexOfNearestStepValue(e){const{steps:t}=this;if(null==t)return null;const i=this._getStepValues(),n=i.reduce(((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t));return i.indexOf(n)}_calculateNearestStepPosition(e){const t=this._valueFromPosition(e),i=this._getIndexOfNearestStepValue(t),n=this._getStepValues();return this._positionFromValue(n[i])}_getTickCounts(e,t){const{mode:i}=t;return"count"===i||"position"===i?e||0:"percent"===i&&100/e||0}_calculateTickPositions(e){return e.map((e=>this._positionFromValue(e)))}_calculateEquidistantTickPositions(e){const{_trackWidth:t,_trackHeight:i}=this,n=this._isHorizontalLayout()?t:i,s=n/(e-1),o=[];if(1===e)return[n/2];for(let r=0;r<e;r++){const e=r*s;e<=n&&o.push(e)}return o}_getDimensions(e){try{return i(e),e.getBoundingClientRect()}catch(t){if("object"==typeof t&&null!==t)return new DOMRect(0,0,0,0);throw t}}_emitTrackClickEvent(e){this.emit("track-click",{...e,type:"track-click"})}_emitTickClickEvent(e){this.emit("tick-click",{...e,type:"tick-click"})}_emitMaxChangeEvent(e){this.emit("max-change",{...e,type:"max-change"})}_emitMinChangeEvent(e){this.emit("min-change",{...e,type:"min-change"})}_emitThumbChangeEvent(e){this.emit("thumb-change",{...e,type:"thumb-change"})}_emitThumbClickEvent(e){this.emit("thumb-click",{...e,type:"thumb-click"})}_emitThumbDragEvent(e){this.emit("thumb-drag",{...e,type:"thumb-drag"})}_emitSegmentClickEvent(e){this.emit("segment-click",{...e,type:"segment-click"})}_emitSegmentDragEvent(e){this.emit("segment-drag",{...e,type:"segment-drag"})}_emitMinRangeLabelClickEvent(e){this.emit("min-click",e)}_emitMaxRangeLabelClickEvent(e){this.emit("min-click",e)}};function g(e){return e?.["data-thumb-index"]}function f(e){return e?.["data-input-index"]}function b(e){return e?.["data-segment-index"]}function E(e){return e?.["data-min-thumb-index"]}function x(e){return e?.["data-max-thumb-index"]}function y(e){return e?.["data-value"]}function k(e){return e?.["data-tick-config-index"]}function P(e){return e?.["data-tick-group-index"]}function I(e){return e?.["data-config"]}e([n()],v.prototype,"_activeLabelInputIndex",void 0),e([n()],v.prototype,"_dragStartInfo",void 0),e([n()],v.prototype,"_isMinInputActive",void 0),e([n()],v.prototype,"_isMaxInputActive",void 0),e([n()],v.prototype,"_segmentDragStartInfo",void 0),e([n({readOnly:!0})],v.prototype,"_isDisabled",null),e([n()],v.prototype,"disabled",void 0),e([n()],v.prototype,"draggableSegmentsEnabled",void 0),e([n()],v.prototype,"effectiveMax",null),e([n()],v.prototype,"effectiveMin",null),e([n({readOnly:!0})],v.prototype,"effectiveSegmentElements",void 0),e([n()],v.prototype,"extraNodes",void 0),e([n()],v.prototype,"inputCreatedFunction",void 0),e([n()],v.prototype,"inputFormatFunction",null),e([n()],v.prototype,"inputParseFunction",null),e([n()],v.prototype,"icon",null),e([n()],v.prototype,"label",null),e([n({readOnly:!0})],v.prototype,"labelElements",void 0),e([n()],v.prototype,"labelInputsEnabled",void 0),e([n()],v.prototype,"labelFormatFunction",null),e([n({readOnly:!0})],v.prototype,"labels",null),e([n({value:"horizontal"})],v.prototype,"layout",null),e([n()],v.prototype,"max",null),e([n({readOnly:!0})],v.prototype,"maxLabelElement",void 0),e([n(),c("esri/widgets/Slider/t9n/Slider")],v.prototype,"messages",void 0),e([n()],v.prototype,"min",null),e([n({readOnly:!0})],v.prototype,"minLabelElement",void 0),e([n()],v.prototype,"precision",null),e([n()],v.prototype,"rangeLabelInputsEnabled",void 0),e([n({readOnly:!0})],v.prototype,"segmentElements",void 0),e([n()],v.prototype,"snapOnClickEnabled",void 0),e([n({readOnly:!0})],v.prototype,"state",null),e([n()],v.prototype,"steps",void 0),e([n()],v.prototype,"syncedSegmentsEnabled",void 0),e([n()],v.prototype,"thumbsConstrained",null),e([n()],v.prototype,"thumbCreatedFunction",void 0),e([n({readOnly:!0})],v.prototype,"thumbElements",void 0),e([n()],v.prototype,"tickConfigs",null),e([n({readOnly:!0})],v.prototype,"tickElements",void 0),e([n({readOnly:!0})],v.prototype,"trackElement",void 0),e([n()],v.prototype,"values",null),e([n({type:l})],v.prototype,"viewModel",void 0),e([n()],v.prototype,"visibleElements",void 0),e([s("visibleElements")],v.prototype,"castVisibleElements",null),v=e([o("esri.widgets.Slider")],v);const A=v;export{A as default};