-
Notifications
You must be signed in to change notification settings - Fork 0
/
input-range.min.js
2 lines (2 loc) · 5.32 KB
/
input-range.min.js
1
2
/*! input-range.js v1.0.0 for ES5CustomElements.js | (c) 2021, Emanuel Rojas Vásquez | BSD 3-Clause License | https://github.com/erovas/input-range.js */
!function(t,e){let r=e.createElement("template"),i="input",a=i+"-range",n=e.getElementsByTagName(a),u="value",o="name",c="min",s="max",l="step",f="disabled",p="isConnected",h="tabIndex",g=i+"-thumb",d=[o,u,s,c,l],m=HTMLInputElement,v=bt(m,u),b=bt(m,o),M=bt(m,c),E=bt(m,s),T=bt(m,l),y="-",w="-a",L="-b",C="-c",X="-d",Y="-e",H="-f",N="-g",O="-h",x="-i",k="-j",P="-k",A="-l",I="-m",S=new Event("change"),j=new Event(i),D="mousedown",F="mousemove",q="touchmove",B="mouseup",z="touchend",R={passive:!1},G,J,K,Q,U,V,W,Z,$,_,tt,et,nt={Extends:HTMLElement,Constructor:function(){var r=this;let t=r[L]=e.createElement("input");t.type="range",t.style.display="none",Object.defineProperties(t,{tagName:{get:function(){return r.tagName}},outerHTML:{get:function(){return r.outerHTML},set:function(t){r.outerHTML=t}},name:{get:function(){return b.get.call(t)},set:function(t){mt(r,o,t)}},value:{get:function(){return Et(v.get.call(t))},set:function(t){mt(r,u,t)}},min:{get:function(){return Et(M.get.call(t))||0},set:function(t){mt(r,c,t)}},max:{get:function(){return Et(E.get.call(t))||100},set:function(t){mt(r,s,t)}},step:{get:function(){return Et(T.get.call(t))||1},set:function(t){mt(r,l,t)}},disabled:{get:function(){return r[f]},set:function(t){r[f]=t}},addEventListener:{value:function(t,e,n){gt(r,t,e,n)}},removeEventListener:{value:function(t,e,n){dt(r,t,e,n)}}}),gt(r,D,ft),gt(r,"touchstart",ft,R),gt(r,"keydown",function(t){let e=t.which;36<e&&e<41&&!r[f]&&(t.preventDefault(),e=37<e&&e<40?r[u]+r[l]:r[u]-r[l],e<r[c]||e>r[s]||(r[u]=e,r.dispatchEvent(j),r.dispatchEvent(S)))})},Static:{get observedAttributes(){return d}},connectedCallback:function(){var n=this;if(!n[k]){if(n[k]=!0,r.content)n.appendChild(r.content.cloneNode(!0));else{let e=r.children;for(let t=0;t<e.length;t++)n.appendChild(e[t].cloneNode(!0))}n.appendChild(n[L]),n[C]=Mt(n,g),n[X]=Mt(n,i+"-lower"),n.hasAttribute(h)||(n[h]=0)}setTimeout(function(){at(n)},20)},attributeChangedCallback:function(t,e,n){e!==n&&(G=this,J=G[L],t!==o?(e=Et(n),(t===c?M:t===s?E:t===u?v:T).set.call(J,e),G[k]&&G[p]&&at(G)):b.set.call(J,n))},get innerHTML(){return""},set innerHTML(t){},get outerHTML(){var e=this.attributes;let n="<"+a+" ";for(let t=0;t<e.length;t++){var r=e[t];n+=r.name+'="'+r.value+'" '}return n+"></"+a+">"},get disabled(){return this.hasAttribute(f)},set disabled(t){t?mt(this,f,""):this.removeAttribute(f)}};function rt(t,e,n,r){t=getComputedStyle(t);r[e]=parseFloat(t.width),r[n]=parseFloat(t.height)}function it(t){rt(t,N,O,t),rt(t[C],Y,H,t)}function at(t){it(t),ut(t)}function ut(t){var e,n,r,i;t[y]=(e=t[u],n=t[N],r=t[c],i=t[s],e=(e-r)/(i-r)*n,isNaN(e)?0:e),t[X].style.width=Math.round(t[y])+"px",t[C].style.transform="translate("+vt(t[y]-t[Y]/2,0,t[N]-t[Y])+"px, -50%)"}function ot(t,e){return t[y]*Math.cos(e)+t[w]*Math.sin(e)}function ct(t,e){if(e.type===F||e.type===D){if(!e.pageY||!e.pageX)return;t[y]=e.pageX,t[w]=e.pageY}else t[y]=e.targetTouches[0].pageX,t[w]=e.targetTouches[0].pageY;it(t);var n=function(t){let e=getComputedStyle(t).transform;"none"===e&&(e="(1, 0, 0, 1, 0, 0)");return e=e.split("(")[1],e=e.split(")")[0],e=e.split(","),{c:Math.atan2(e[1],e[0]),a:Math.sqrt(e[0]*e[0]+e[1]*e[1]),b:Math.sqrt(e[2]*e[2]+e[3]*e[3])}}(t);K=n.c,Q=function(t){t<0&&(t+=2*Math.PI);return Math.round(t*(180/Math.PI))}(K),U=t.getBoundingClientRect(),V=U.left+pageXOffset,W=U.right+pageXOffset,Z=U.top+pageYOffset,$=U.bottom+pageYOffset;e=t[O]*n.b*Math.sin(K);0===Q||360===Q?t[y]-=V:90===Q?t[y]=t[w]-Z:180===Q?t[y]=W-t[y]:270===Q?t[y]=$-t[w]:(Q<90?(t[y]-=V+e,t[w]-=Z):Q<180?(t[y]-=W-e,t[w]-=Z):(Q<270?t[y]-=W+e:t[y]-=V-e,t[w]-=$),t[y]=ot(t,K)),t[y]/=n.a}function st(t){var e,n,r,i,a;_=t[u],tt=(e=t[y],n=t[N],r=t[c],i=t[s],function(t,e){return Number(t.toFixed((e+"").replace(".","").length-1))}((a=t[l])*Math.round(vt(e,0,n)/n*(i-r)/a)+r,a)),v.set.call(t[L],tt),_!==t[u]&&(ut(t),t.dispatchEvent(j))}function lt(t){dt(e,F,pt),dt(t,q,pt,R),dt(e,B,ht),dt(t,z,ht,R)}function ft(t){if(2!==t.which&&3!==t.which){if(G=this,G[x]=G[u],t.type===D)return ct(G,t),st(G),t.preventDefault(),gt(e,F,pt),void gt(e,B,ht);t.target.closest(g)!==G[C]&&(G[P]=!0,G[A]=t.pageX||t.targetTouches[0].pageX,G[I]=t.pageY||t.targetTouches[0].pageY,ct(G,t)),gt(G,q,pt,R),gt(G,z,ht,R)}}function pt(t){if(t.type===q&&(G=this),G[P]&&(G[A]!==(t.pageX||t.targetTouches[0].pageX)||G[I]!==(t.pageY||t.targetTouches[0].pageY)))return G[P]=!1,void lt(G);ct(G,t),st(G)}function ht(t){t.type===z&&(G=this),t.preventDefault(),G[P]&&st(G),G[x]!==G[u]&&G.dispatchEvent(S),G[P]=!1,lt(G)}function gt(t,e,n,r){t.addEventListener(e,n,r||!1)}function dt(t,e,n,r){t.removeEventListener(e,n,r||!1)}function mt(t,e,n){t.setAttribute(e,n)}function vt(t,e,n){return n<t?n:t<e?e:t}function bt(t,e){return Object.getOwnPropertyDescriptor(t.prototype,e)}function Mt(t,e){return t.querySelector(e)}function Et(t){return parseFloat((t+"").replace(",","."))}d.forEach(function(e){Object.defineProperty(nt,e,{get:function(){return this[L][e]},set:function(t){mt(this,e,t)}})}),r.innerHTML="<input-track><input-lower></input-lower><input-upper></input-upper></input-track><input-thumb></input-thumb>",ES5customElements.define(a,nt),gt(t,"resize",function(){et&&clearTimeout(et),et=setTimeout(function(){for(let t=0;t<n.length;t++)G=n[t],G[k]&&G[p]&&at(G)},100)})}(window,document);