import{__awaiter,__generator}from"tslib"; /*! * (C) Ionic http://ionicframework.com - MIT License */import{r as registerInstance,d as createEvent,h,H as Host,f as getElement}from"./index-73fa3fe8.js";import{f as findClosestIonContent,d as disableContentScrollY,r as resetContentScrollY}from"./index-f3946ac1.js";import{c as createLegacyFormController}from"./form-controller-21dd62b1.js";import{l as clamp,j as debounceEvent,i as inheritAriaAttributes,d as renderHiddenInput,e as getAriaLabel}from"./helpers-be245865.js";import{p as printIonWarning}from"./index-9b0d46f4.js";import{i as isRTL}from"./dir-babeabeb.js";import{c as createColorClasses,h as hostContext}from"./theme-01f3f29c.js";import{b as getIonMode}from"./ionic-global-d89a6ff6.js";function getDecimalPlaces(e){if(e%1===0)return 0;return e.toString().split(".")[1].length}function roundToMaxDecimalPlaces(e){var t=[];for(var r=1;r0?a:1;a=a/(t.max-t.min);if(!r){a*=-1}if(e==="A"){t.ratioA=clamp(0,t.ratioA+a,1)}else{t.ratioB=clamp(0,t.ratioB+a,1)}t.ionKnobMoveStart.emit({value:n(t.value)});t.updateValue();t.emitValueChange();t.ionKnobMoveEnd.emit({value:n(t.value)})};this.onBlur=function(){if(t.hasFocus){t.hasFocus=false;t.ionBlur.emit();t.emitStyle()}};this.onFocus=function(){if(!t.hasFocus){t.hasFocus=true;t.ionFocus.emit();t.emitStyle()}};this.ratioA=0;this.ratioB=0;this.pressedKnob=undefined;this.color=undefined;this.debounce=undefined;this.name=this.rangeId;this.label=undefined;this.dualKnobs=false;this.min=0;this.max=100;this.pin=false;this.pinFormatter=function(e){return Math.round(e)};this.snaps=false;this.step=1;this.ticks=true;this.activeBarStart=undefined;this.disabled=false;this.value=0;this.labelPlacement="start";this.legacy=undefined}e.prototype.debounceChanged=function(){var e=this,t=e.ionInput,r=e.debounce,n=e.originalIonInput;this.ionInput=r===undefined?n!==null&&n!==void 0?n:t:debounceEvent(t,r)};e.prototype.minChanged=function(){if(!this.noUpdate){this.updateRatio()}};e.prototype.maxChanged=function(){if(!this.noUpdate){this.updateRatio()}};e.prototype.activeBarStartChanged=function(){var e=this.activeBarStart;if(e!==undefined){if(e>this.max){printIonWarning("Range: The value of activeBarStart (".concat(e,") is greater than the max (").concat(this.max,"). Valid values are greater than or equal to the min value and less than or equal to the max value."),this.el);this.activeBarStart=this.max}else if(e
Volume
\nExample with aria-label: \n\nDevelopers can use the "legacy" property to continue using the legacy form markup. This property will be removed in an upcoming major release of Ionic where this form control will use the modern form markup.',this.el);if(this.legacy){printIonWarning('ion-range is being used with the "legacy" property enabled which will forcibly enable the legacy form markup. This property will be removed in an upcoming major release of Ionic where this form control will use the modern form markup.\n\nDevelopers can dismiss this warning by removing their usage of the "legacy" property and using the new range syntax.',this.el)}this.hasLoggedDeprecationWarning=true}var t=this,r=t.el,n=t.pressedKnob,a=t.disabled,i=t.pin,o=t.rangeId;var s=getIonMode(this);renderHiddenInput(true,r,this.name,JSON.stringify(this.getValue()),a);return h(Host,{onFocusin:this.onFocus,onFocusout:this.onBlur,id:o,class:createColorClasses(this.color,(e={},e[s]=true,e["in-item"]=hostContext("ion-item",r),e["range-disabled"]=a,e["range-pressed"]=n!==undefined,e["range-has-pin"]=i,e["legacy-range"]=true,e))},h("slot",{name:"start"}),this.renderRangeSlider(),h("slot",{name:"end"}))};Object.defineProperty(e.prototype,"hasStartSlotContent",{get:function(){return this.el.querySelector('[slot="start"]')!==null},enumerable:false,configurable:true});Object.defineProperty(e.prototype,"hasEndSlotContent",{get:function(){return this.el.querySelector('[slot="end"]')!==null},enumerable:false,configurable:true});e.prototype.renderRange=function(){var e;var t=this,r=t.disabled,n=t.el,a=t.hasLabel,i=t.rangeId,o=t.pin,s=t.pressedKnob,l=t.labelPlacement,d=t.label;var g=hostContext("ion-item",n);var b=a&&(l==="start"||l==="fixed")||this.hasStartSlotContent;var c=g&&!b;var p=a&&l==="end"||this.hasEndSlotContent;var u=g&&!p;var f=getIonMode(this);renderHiddenInput(true,n,this.name,JSON.stringify(this.getValue()),r);return h(Host,{onFocusin:this.onFocus,onFocusout:this.onBlur,id:i,class:createColorClasses(this.color,(e={},e[f]=true,e["in-item"]=g,e["range-disabled"]=r,e["range-pressed"]=s!==undefined,e["range-has-pin"]=o,e["range-label-placement-".concat(l)]=true,e["range-item-start-adjustment"]=c,e["range-item-end-adjustment"]=u,e))},h("label",{class:"range-wrapper",id:"range-label"},h("div",{class:{"label-text-wrapper":true,"label-text-wrapper-hidden":!a},part:"label"},d!==undefined?h("div",{class:"label-text"},d):h("slot",{name:"label"})),h("div",{class:"native-wrapper"},h("slot",{name:"start"}),this.renderRangeSlider(),h("slot",{name:"end"}))))};Object.defineProperty(e.prototype,"hasLabel",{get:function(){return this.label!==undefined||this.el.querySelector('[slot="label"]')!==null},enumerable:false,configurable:true});e.prototype.renderRangeSlider=function(){var e;var t=this;var r;var n=this,a=n.min,i=n.max,o=n.step,s=n.el,l=n.handleKeyboard,d=n.pressedKnob,g=n.disabled,b=n.pin,c=n.ratioLower,p=n.ratioUpper,u=n.inheritedAttributes,f=n.rangeId,m=n.pinFormatter;var k=getAriaLabel(s,f).labelText;if(k===undefined||k===null){k=u["aria-label"]}var v="".concat(c*100,"%");var x="".concat(100-p*100,"%");var w=isRTL(this.el);var y=w?"right":"left";var z=w?"left":"right";var C=function(e){var t;return t={},t[y]=e[y],t};if(this.dualKnobs===false){if(this.valA<((r=this.activeBarStart)!==null&&r!==void 0?r:this.min)){v="".concat(p*100,"%");x="".concat(100-c*100,"%")}else{v="".concat(c*100,"%");x="".concat(100-p*100,"%")}}var j=(e={},e[y]=v,e[z]=x,e);var I=[];if(this.snaps&&this.ticks){for(var M=a;M<=i;M+=o){var T=valueToRatio(M,a,i);var R=Math.min(c,p);var S=Math.max(c,p);var A={ratio:T,active:T>=R&&T<=S};A[y]="".concat(T*100,"%");I.push(A)}}var E;if(!this.legacyFormController.hasLegacyControl()&&this.hasLabel){E="range-label"}return h("div",{class:"range-slider",ref:function(e){return t.rangeSlider=e},onPointerUp:function(e){if(t.pressedKnob===undefined){t.onStart();t.onEnd(e)}}},I.map((function(e){return h("div",{style:C(e),role:"presentation",class:{"range-tick":true,"range-tick-active":e.active},part:e.active?"tick-active":"tick"})})),h("div",{class:"range-bar-container"},h("div",{class:"range-bar",role:"presentation",part:"bar"}),h("div",{class:{"range-bar":true,"range-bar-active":true,"has-ticks":I.length>0},role:"presentation",style:j,part:"bar-active"})),renderKnob(w,{knob:"A",pressed:d==="A",value:this.valA,ratio:this.ratioA,pin:b,pinFormatter:m,disabled:g,handleKeyboard:l,min:a,max:i,labelText:k,labelledBy:E}),this.dualKnobs&&renderKnob(w,{knob:"B",pressed:d==="B",value:this.valB,ratio:this.ratioB,pin:b,pinFormatter:m,disabled:g,handleKeyboard:l,min:a,max:i,labelText:k,labelledBy:E}))};e.prototype.render=function(){var e=this.legacyFormController;return e.hasLegacyControl()?this.renderLegacyRange():this.renderRange()};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{debounce:["debounceChanged"],min:["minChanged"],max:["maxChanged"],activeBarStart:["activeBarStartChanged"],disabled:["disabledChanged"],value:["valueChanged"]}},enumerable:false,configurable:true});return e}();var renderKnob=function(e,t){var r=t.knob,n=t.value,a=t.ratio,i=t.min,o=t.max,s=t.disabled,l=t.pressed,d=t.pin,g=t.handleKeyboard,b=t.labelText,c=t.labelledBy,p=t.pinFormatter;var u=e?"right":"left";var f=function(){var e={};e[u]="".concat(a*100,"%");return e};return h("div",{onKeyDown:function(e){var t=e.key;if(t==="ArrowLeft"||t==="ArrowDown"){g(r,false);e.preventDefault();e.stopPropagation()}else if(t==="ArrowRight"||t==="ArrowUp"){g(r,true);e.preventDefault();e.stopPropagation()}},class:{"range-knob-handle":true,"range-knob-a":r==="A","range-knob-b":r==="B","range-knob-pressed":l,"range-knob-min":n===i,"range-knob-max":n===o,"ion-activatable":true,"ion-focusable":true},style:f(),role:"slider",tabindex:s?-1:0,"aria-label":c===undefined?b:null,"aria-labelledby":c!==undefined?c:null,"aria-valuemin":i,"aria-valuemax":o,"aria-disabled":s?"true":null,"aria-valuenow":n},d&&h("div",{class:"range-pin",role:"presentation",part:"pin"},p(n)),h("div",{class:"range-knob",role:"presentation",part:"knob"}))};var ratioToValue=function(e,t,r,n){var a=(r-t)*e;if(n>0){a=Math.round(a/n)*n+t}var i=clamp(t,a,r);return roundToMaxDecimalPlaces(i,t,r,n)};var valueToRatio=function(e,t,r){return clamp(0,(e-t)/(r-t),1)};var rangeIds=0;Range.style={ios:IonRangeIosStyle0,md:IonRangeMdStyle0};export{Range as ion_range};