TP_JO2024/home/dist/component/range/range.module.min.js
2024-03-27 17:19:37 +01:00

3 lines
10 KiB
JavaScript

/*! DSFR v1.11.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
const t=window.dsfr,e={RANGE:t.internals.ns.selector("range"),RANGE_SM:t.internals.ns.selector("range--sm"),RANGE_STEP:t.internals.ns.selector("range--step"),RANGE_DOUBLE:t.internals.ns.selector("range--double"),RANGE_DOUBLE_STEP:t.internals.ns.selector("range--double")+t.internals.ns.selector("range--step"),RANGE_INPUT:t.internals.ns.selector("range input[type=range]:nth-of-type(1)"),RANGE_INPUT2:`${t.internals.ns.selector("range--double")} input[type=range]:nth-of-type(2)`,RANGE_OUTPUT:t.internals.ns.selector("range__output"),RANGE_MIN:t.internals.ns.selector("range__min"),RANGE_MAX:t.internals.ns.selector("range__max"),RANGE_PREFIX:t.internals.ns.attr("prefix"),RANGE_SUFFIX:t.internals.ns.attr("suffix")},s={VALUE:t.internals.ns.emission("range","value"),VALUE2:t.internals.ns.emission("range","value2"),OUTPUT:t.internals.ns.emission("range","output"),CONSTRAINTS:t.internals.ns.emission("range","constraints"),MIN:t.internals.ns.emission("range","min"),MAX:t.internals.ns.emission("range","max"),STEP:t.internals.ns.emission("range","step"),PREFIX:t.internals.ns.emission("range","prefix"),SUFFIX:t.internals.ns.emission("range","suffix"),DISABLED:t.internals.ns.emission("range","disabled"),ENABLE_POINTER:t.internals.ns.emission("range","enable_pointer")};class i{constructor(){this._width=0,this._min=0,this._max=0,this._value=0,this._thumbSize=24,this._innerWidth=0,this._prefix="",this._suffix="",this._background={}}configure(t){t&&(this._prefix=t._prefix,this._suffix=t._suffix,this._width=t.width,this.setConstraints(t._constraints),this.value=t.value,this.update())}setPrefix(t){this._prefix=null!==t?t:""}setSuffix(t){this._suffix=null!==t?t:""}_decorate(t){return`${this._prefix}${t}${this._suffix}`}get width(){return this._width}set width(t){this._width=t}get isSm(){return this._isSm}set isSm(t){this._isSm!==t&&(this._isSm=t,this.setThumbSize(t?16:24),this.update())}setThumbSize(t,e=1){this._thumbSize=t,this._innerPadding=t*e}get textValue(){return this._decorate(this._value)}get value(){return this._value}set value(t){this._value=t}get outputX(){return this._outputX}setConstraints(t){this._constraints=t,this._min=t.min,this._max=t.max,this._step=t.step,this._rangeWidth=t.rangeWidth}get min(){return this._min}get textMin(){return this._decorate(this._min)}get max(){return this._max}get textMax(){return this._decorate(this._max)}get step(){return this._step}get output(){return{text:this.textValue,transform:`translateX(${this._translateX}px) translateX(-${this._centerPercent}%)`}}_getRatio(t){return(t-this._min)/this._rangeWidth}get progress(){return this._progress}update(){this._update()}_update(){this._innerWidth=this._width-this._innerPadding;const t=this._getRatio(this._value);this._translateX=t*this._width,this._centerPercent=100*t,this._progress={right:`${(this._innerWidth*t+.5*this._innerPadding).toFixed(2)}px`}}}class n extends i{get stepWidth(){return`${this._stepWidth.toFixed(3)}px`}_update(){super._update();const t=this._rangeWidth/this._step;for(this._stepWidth=this._innerWidth/t;this._stepWidth<4;)this._stepWidth*=2}}class h extends i{get value2(){return this._value}set value2(t){this._value2!==t&&(this._value2=t,this.update())}get textValue(){return`${this._decorate(this._value)} - ${this._decorate(this._value2)}`}setThumbSize(t){super.setThumbSize(t,2)}_update(){super._update();const t=this._getRatio(.5*(this._value+this._value2));this._translateX=t*this._width,this._centerPercent=100*t;const e=this._getRatio(this._value),s=this._getRatio(this._value2);this._progress={left:`${(this._innerWidth*e+.25*this._innerPadding).toFixed(2)}px`,right:`${(this._innerWidth*s+.75*this._innerPadding).toFixed(2)}px`}}}class r extends h{get stepWidth(){return`${this._stepWidth.toFixed(3)}px`}_update(){super._update();const t=this._rangeWidth/this._step;this._stepWidth=this._innerWidth/t,this._stepWidth<4&&(this._stepWidth*=Math.ceil(4/this._stepWidth))}}const a="step",d="double",_="double-step",o="default";class l extends t.core.Instance{static get instanceClassName(){return"Range"}init(){this._retrieveType(),this._retrieveSize(),this.isLegacy?(this.isResizing=!0,this.isMouseMoving=!0):(this._observer=new ResizeObserver(this.resize.bind(this)),this._observer.observe(this.node)),this.addAscent(s.CONSTRAINTS,this.setConstraints.bind(this)),this.addAscent(s.VALUE,this.setValue.bind(this)),this.addAscent(s.VALUE2,this.setValue2.bind(this)),this.getAttribute(e.RANGE_PREFIX)&&this.setPrefix(this.getAttribute(e.RANGE_PREFIX)),this.getAttribute(e.RANGE_SUFFIX)&&this.setSuffix(this.getAttribute(e.RANGE_SUFFIX)),this.update()}_retrieveType(){switch(!0){case this.matches(e.RANGE_DOUBLE_STEP):case this.matches(e.RANGE_DOUBLE):this.type=d;break;case this.matches(e.RANGE_STEP):this.type=a;break;default:this.type=o}}set type(t){if(this._type===t)return;this._type=t;const e=this._model;switch(this._type){case _:this._model=new r;break;case d:this._model=new h;break;case a:this._model=new n;break;default:this._model=new i}this._model.configure(e)}get type(){return this._type}_retrieveSize(){this._model.isSm=this.matches(e.RANGE_SM)}resize(){this._retrieveWidth(),this.update()}_retrieveWidth(){this._model.width=this.getRect().width}setValue(t){switch(this._model.value=t,this._type){case _:case d:this.descend(s.VALUE,t)}this.update()}setValue2(t){this._model.value2=t,this.descend(s.VALUE2,t),this.update()}setConstraints(t){this._model.setConstraints(t),this.update(),this.descend(s.CONSTRAINTS,t)}setPrefix(t){this._model.setPrefix(t),this.update()}setSuffix(t){this._model.setSuffix(t),this.update()}mutate(t){switch(!0){case t.includes("class"):this._retrieveType(),this._retrieveSize();break;case t.includes(e.RANGE_PREFIX):case t.includes(e.RANGE_SUFFIX):this._model.setPrefix(this.getAttribute(e.RANGE_PREFIX)),this._model.setSuffix(this.getAttribute(e.RANGE_SUFFIX)),this.update()}}update(){this._model.update(),this.descend(s.OUTPUT,this._model.output),this.descend(s.MIN,this._model.textMin),this.descend(s.MAX,this._model.textMax);const t=this._model.progress;t.left?this.style.setProperty("--progress-left",t.left):this.style.removeProperty("--progress-left"),t.right?(this.style.setProperty("--progress-right",t.right),this.isLegacy&&t.left&&(this.style.setProperty("background-position-x",t.left),this.style.setProperty("background-size",`${parseFloat(t.right)-parseFloat(t.left)}px ${this._model.isSm?"8px":"12px"}`))):(this.style.removeProperty("--progress-right"),this.isLegacy&&(this.style.removeProperty("background-size"),this.style.removeProperty("background-position-x"))),this._model.stepWidth?this.style.setProperty("--step-width",this._model.stepWidth):this.style.removeProperty("--step-width")}mouseMove(t){if(this._type!==d&&this._type!==_)return;const e=t.x-this.getRect().left;this.descend(s.ENABLE_POINTER,(parseFloat(this._model.progress.right)-parseFloat(this._model.progress.left))/2+parseFloat(this._model.progress.left)<e?2:1)}dispose(){this._observer.disconnect()}}class u{constructor(t){this._min=isNaN(t.min)?0:t.min,this._max=isNaN(t.max)?100:t.max,this._step=isNaN(t.step)?1:t.step,this._rangeWidth=this._max-this._min}get min(){return this._min}get max(){return this._max}get step(){return this._step}get rangeWidth(){return this._rangeWidth}test(t,e,s){return this._min===t&&this._max===e&&this._step===s}}class g extends t.core.Instance{static get instanceClassName(){return"RangeInput"}init(){this._init(),this.node.value=this.getAttribute("value"),this._changing=this.change.bind(this),this._listenerType=this.isLegacy?"change":"input",this.listen(this._listenerType,this._changing),this.isLegacy&&this.addDescent(s.ENABLE_POINTER,this._enablePointer.bind(this)),this.change()}_init(){this._pointerId=1,this.request((()=>{this.hasAttribute("min")||this.setAttribute("min",0),this.ascend(s.CONSTRAINTS,new u(this.node)),this.ascend(s.DISABLED,this.node.disabled)})),this.addDescent(s.VALUE2,this.setValue.bind(this))}_enablePointer(t){const e=t===this._pointerId;this._isPointerEnabled!==e&&(this._isPointerEnabled=e,e?this.style.removeProperty("pointer-events"):this.style.setProperty("pointer-events","none"))}setValue(t){parseFloat(this.node.value)>t&&(this.node.value=t,this.change())}change(){this.ascend(s.VALUE,parseFloat(this.node.value))}mutate(t){t.includes("disabled")&&this.ascend(s.DISABLED,this.node.disabled),(t.includes("min")||t.includes("max")||t.includes("step"))&&(this.ascend(s.CONSTRAINTS,new u(this.node)),this.change())}dispose(){this._listenerType&&this.unlisten(this._listenerType,this._changing)}}class c extends t.core.Instance{static get instanceClassName(){return"RangeOutput"}init(){this.addDescent(s.OUTPUT,this.change.bind(this))}change(t){this.node.innerText=t.text,this.node.style.transform=t.transform}}class p extends t.core.Instance{static get instanceClassName(){return"RangeLimit"}init(){switch(!0){case this.matches(e.RANGE_MIN):this.addDescent(s.MIN,this.change.bind(this));break;case this.matches(e.RANGE_MAX):this.addDescent(s.MAX,this.change.bind(this))}}change(t){this.node.innerText=t}}t.range={Range:l,RangeInput:g,RangeInput2:class extends g{static get instanceClassName(){return"RangeInput2"}_init(){this._pointerId=2,this.addDescent(s.CONSTRAINTS,this.setConstraints.bind(this)),this.addDescent(s.VALUE,this.setValue.bind(this))}setValue(t){parseFloat(this.node.value)<t&&(this.node.value=t,this.change())}change(){this.ascend(s.VALUE2,parseFloat(this.node.value))}setConstraints(t){this.node.min=t.min,this.node.max=t.max,this.node.step=t.step,this.change()}mutate(t){}},RangeOutput:c,RangeLimit:p,RangeEmission:s,RangeSelector:e},t.internals.register(t.range.RangeSelector.RANGE,t.range.Range),t.internals.register(t.range.RangeSelector.RANGE_INPUT,t.range.RangeInput),t.internals.register(t.range.RangeSelector.RANGE_INPUT2,t.range.RangeInput2),t.internals.register(t.range.RangeSelector.RANGE_OUTPUT,t.range.RangeOutput),t.internals.register(t.range.RangeSelector.RANGE_MIN,t.range.RangeLimit),t.internals.register(t.range.RangeSelector.RANGE_MAX,t.range.RangeLimit);
//# sourceMappingURL=range.module.min.js.map