preact-range-slider
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -39,3 +39,3 @@ import { Component } from 'preact'; | ||
protected calcOffset(value: number): number; | ||
protected abstract clampAlignValue<TProps>(value: number, nextProps?: Partial<TProps>): number; | ||
protected abstract clampAlignValue(value: number, nextProps?: Partial<TProps>): number; | ||
protected abstract onChange<TKey extends keyof TState>(state: Pick<TState, TKey>): void; | ||
@@ -42,0 +42,0 @@ protected abstract onStart(position: number): void; |
@@ -39,3 +39,3 @@ import { Component } from 'preact'; | ||
protected calcOffset(value: number): number; | ||
protected abstract clampAlignValue<TProps>(value: number, nextProps?: Partial<TProps>): number; | ||
protected abstract clampAlignValue(value: number, nextProps?: Partial<TProps>): number; | ||
protected abstract onChange<TKey extends keyof TState>(state: Pick<TState, TKey>): void; | ||
@@ -42,0 +42,0 @@ protected abstract onStart(position: number): void; |
@@ -159,21 +159,21 @@ import * as tslib_1 from "tslib"; | ||
}; | ||
AbstractSlider.defaultProps = { | ||
min: 0, | ||
max: 100, | ||
step: 1, | ||
marks: {}, | ||
dots: false, | ||
included: true, | ||
vertical: false, | ||
disabled: false, | ||
className: 'range-slider', | ||
classesPrefix: '', | ||
onBeforeChange: noop, | ||
onChange: noop, | ||
onAfterChange: noop, | ||
tipFormatter: String, | ||
}; | ||
return AbstractSlider; | ||
}(Component)); | ||
AbstractSlider.defaultProps = { | ||
min: 0, | ||
max: 100, | ||
step: 1, | ||
marks: {}, | ||
dots: false, | ||
included: true, | ||
vertical: false, | ||
disabled: false, | ||
className: 'range-slider', | ||
classesPrefix: '', | ||
onBeforeChange: noop, | ||
onChange: noop, | ||
onAfterChange: noop, | ||
tipFormatter: String, | ||
}; | ||
export { AbstractSlider as default, }; | ||
//# sourceMappingURL=AbstractSlider.js.map |
@@ -255,6 +255,6 @@ import * as tslib_1 from "tslib"; | ||
}; | ||
MultiSlider.defaultProps = tslib_1.__assign({}, AbstractSlider.defaultProps, { count: 1, allowCross: true, pushable: false }); | ||
return MultiSlider; | ||
}(AbstractSlider)); | ||
MultiSlider.defaultProps = tslib_1.__assign({}, AbstractSlider.defaultProps, { count: 1, allowCross: true, pushable: false }); | ||
export { MultiSlider as default, }; | ||
//# sourceMappingURL=MultiSlider.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('preact')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'preact'], factory) : | ||
(factory((global.PreactRangeSlider = global.PreactRangeSlider || {}),global.preact)); | ||
(factory((global.PreactRangeSlider = {}),global.preact)); | ||
}(this, (function (exports,preact) { 'use strict'; | ||
@@ -351,20 +351,20 @@ | ||
}; | ||
AbstractSlider.defaultProps = { | ||
min: 0, | ||
max: 100, | ||
step: 1, | ||
marks: {}, | ||
dots: false, | ||
included: true, | ||
vertical: false, | ||
disabled: false, | ||
className: 'range-slider', | ||
classesPrefix: '', | ||
onBeforeChange: noop, | ||
onChange: noop, | ||
onAfterChange: noop, | ||
tipFormatter: String, | ||
}; | ||
return AbstractSlider; | ||
}(preact.Component)); | ||
AbstractSlider.defaultProps = { | ||
min: 0, | ||
max: 100, | ||
step: 1, | ||
marks: {}, | ||
dots: false, | ||
included: true, | ||
vertical: false, | ||
disabled: false, | ||
className: 'range-slider', | ||
classesPrefix: '', | ||
onBeforeChange: noop, | ||
onChange: noop, | ||
onAfterChange: noop, | ||
tipFormatter: String, | ||
}; | ||
@@ -765,5 +765,5 @@ var Handle = (function (_super) { | ||
}; | ||
MultiSlider.defaultProps = __assign({}, AbstractSlider.defaultProps, { count: 1, allowCross: true, pushable: false }); | ||
return MultiSlider; | ||
}(AbstractSlider)); | ||
MultiSlider.defaultProps = __assign({}, AbstractSlider.defaultProps, { count: 1, allowCross: true, pushable: false }); | ||
@@ -770,0 +770,0 @@ exports.Slider = Slider; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t(e.PreactRangeSlider=e.PreactRangeSlider||{},e.preact)}(this,function(e,t){"use strict";function n(e,t){function n(){this.constructor=e}b(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function r(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}function o(e,t){var n=t.min,r=t.max;return e<=n?n:e>=r?r:e}function a(e,t){var n=t.min,r=t.max;return e<n||e>r}function i(e){var t=e.toString(),n=t.indexOf("."),r=0;return-1!==n&&(r=t.length-n-1),r}function s(e,t){var n=t.marks,r=t.step,o=t.min,a=Object.keys(n).map(Number);if(null!=r&&r>0){var i=Math.round((e-o)/r)*r+o;a.push(i)}var s=a.map(function(t){return Math.abs(e-t)});return a[s.indexOf(Math.min.apply(Math,s))]||o}function u(e,t){var n=t.step,r=s(e,t);return null==n||n<=0?r:Number(r.toFixed(i(n)))}function l(e,t){var n=t.getBoundingClientRect();return e?n.top+n.height/2:n.left+n.width/2}function c(e,t){return e?t.clientY:t.pageX}function d(e,t){return e?t.touches[0].clientY:t.touches[0].pageX}function p(e,t){return t.some(function(t){return e.target===t})}function h(e){return e.touches.length>1||"touchend"===e.type.toLowerCase()&&e.touches.length>0}function f(e){e.stopPropagation(),e.preventDefault()}function v(e,t){for(var n=[],r=Object.keys(e),o=0,a=r.length;o<a;o++){var i=r[o];e[i]&&n.push(i)}return t&&(n=t.concat(n)),n.join(" ")}function m(e){var n=e.min,r=e.max,o=e.lowerBound,a=e.upperBound,i=e.marks,s=e.included,u=e.vertical,l=e.classesPrefix,c=Object.keys(i),d=.9*(100/(c.length-1)),p=r-n,h=c.map(Number).sort(function(e,t){return e-t}).map(function(e){var r=!s&&e===a||s&&e<=a&&e>=o,c=v((m={},m[l+"active"]=r,m),[l+"text"]),h=u?{marginBottom:"-50%",bottom:(e-n)/p*100+"%"}:{width:d+"%",marginLeft:-d/2+"%",left:(e-n)/p*100+"%"},f=i[e];return t.h("span",{class:c,style:h,key:String(e)},f);var m});return t.h("div",{class:l+"marks"},h)}function g(e){var n=e.min,r=e.max,o=e.step,a=e.lowerBound,i=e.upperBound,s=e.marks,u=e.dots,l=e.included,c=e.vertical,d=e.classesPrefix,p=r-n,h=y(s,u,o,n,r).map(function(e){var r=Math.abs(e-n)/p*100+"%",o=c?{bottom:r}:{left:r},s=!l&&e===i||l&&e<=i&&e>=a,u=v((h={},h[d+"active"]=s,h),[d+"dot"]);return t.h("span",{class:u,style:o,key:String(e)});var h});return t.h("div",{class:d+"steps"},h)}function y(e,t,n,r,o){var a=Object.keys(e).map(Number);if(t&&n>0)for(var i=r;i<=o;i+=n)-1===a.indexOf(i)&&a.push(i);return a}var b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},x=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},S=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.dragOffset=0,t.handlesRefs=[],t.saveSlider=function(e){t.sliderRef=e},t.saveHandle=function(e,n){void 0===n&&(n=0),null==e?delete t.handlesRefs[n]:t.handlesRefs[n]=e.base},t.onMouseDown=function(e){if(0===e.button){var n=t.props.vertical,r=c(n,e);if(p(e,t.handlesRefs)){var o=l(n,e.target);t.dragOffset=r-o,r=o}else t.dragOffset=0;t.onStart(r),t.addDocumentMouseEvents(),f(e)}},t.onTouchStart=function(e){if(!h(e)){var n=t.props.vertical,r=d(n,e);if(p(e,t.handlesRefs)){var o=l(n,e.target);t.dragOffset=r-o,r=o}else t.dragOffset=0;t.onStart(r),t.addDocumentTouchEvents(),f(e)}},t.onMouseMove=function(e){if(t.sliderRef){var n=c(t.props.vertical,e);t.onMove(n-t.dragOffset),f(e)}else t.onEnd()},t.onTouchMove=function(e){if(t.sliderRef&&!h(e)){var n=d(t.props.vertical,e);t.onMove(n-t.dragOffset),f(e)}else t.onEnd()},t.onEventEnd=function(){t.removeDocumentEvents(),t.onEnd(),t.props.onAfterChange(t.getValue())},t}return n(o,e),o.prototype.componentWillUnmount=function(){this.removeDocumentEvents()},o.prototype.renderBase=function(e,n){var o=this.props,a=o.min,i=o.max,s=o.step,u=o.marks,l=o.dots,c=o.included,d=o.vertical,p=o.disabled,h=o.className,f=o.classesPrefix,y=o.children,b=this.getLowerBound(),x=this.getUpperBound(),S=v((P={},P[f+"with-marks"]=Object.keys(u).length,P[f+"vertical"]=d,P[f+"disabled"]=p,P),[h]);return t.h("div",{class:S,ref:this.saveSlider,onTouchStart:p?r:this.onTouchStart,onMouseDown:p?r:this.onMouseDown},t.h("div",{class:f+"rail"}),e,t.h(g,{vertical:d,marks:u,dots:l,step:s,included:c,lowerBound:b,upperBound:x,max:i,min:a,classesPrefix:f}),n,t.h(m,{vertical:d,marks:u,included:c,lowerBound:b,upperBound:x,max:i,min:a,classesPrefix:f}),y);var P},o.prototype.getSliderStart=function(){var e=this.sliderRef;if(!e)return 0;var t=e.getBoundingClientRect();return this.props.vertical?t.top:t.left},o.prototype.getSliderLength=function(){var e=this.sliderRef;return e?this.props.vertical?e.clientHeight:e.clientWidth:0},o.prototype.calcValue=function(e){var t=this.props,n=t.vertical,r=t.min,o=t.max,a=Math.abs(Math.max(e,0)/this.getSliderLength());return n?(1-a)*(o-r)+r:a*(o-r)+r},o.prototype.calcValueByPos=function(e){var t=e-this.getSliderStart();return this.clampAlignValue(this.calcValue(t))},o.prototype.calcOffset=function(e){var t=this.props,n=t.min;return 100*((e-n)/(t.max-n))},o.prototype.addDocumentMouseEvents=function(){document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onEventEnd)},o.prototype.addDocumentTouchEvents=function(){document.addEventListener("touchmove",this.onTouchMove),document.addEventListener("touchend",this.onEventEnd)},o.prototype.removeDocumentEvents=function(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onEventEnd),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onEventEnd)},o}(t.Component);S.defaultProps={min:0,max:100,step:1,marks:{},dots:!1,included:!0,vertical:!1,disabled:!1,className:"range-slider",classesPrefix:"",onBeforeChange:r,onChange:r,onAfterChange:r,tipFormatter:String};var P=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.saveElement=function(e){t.elementRef=e},t}return n(r,e),r.prototype.render=function(e){var n=e.min,r=e.max,o=e.value,a=e.vertical,i=e.disabled,s=e.dragging,u=e.index,l=e.offset,c=e.classesPrefix,d=e.children,p=a?{bottom:l+"%"}:{left:l+"%"};s&&this.elementRef&&this.elementRef.focus();var h=v((f={},f[c+"dragging"]=s,f),[c+"handle",c+"handle-"+u]);return t.h("div",{class:h,style:p,role:"slider",tabIndex:i?void 0:0,"aria-orientation":a?"vertical":"horizontal","aria-disabled":String(i),"aria-valuemin":n,"aria-valuemax":r,"aria-valuenow":o,ref:this.saveElement},t.h("span",{class:c+"tip"},d));var f},r}(t.Component),B=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return n(r,e),r.prototype.render=function(e){var n=e.vertical,r=e.included,o=e.index,a=e.offset,i=e.length,s=e.classesPrefix,u={};return r||(u.visibility="hidden"),n?(u.bottom=a+"%",u.height=i+"%"):(u.left=a+"%",u.width=i+"%"),t.h("div",{class:s+"track "+s+"track-"+o,style:u})},r}(t.Component),E=function(e){function r(t){var n=e.call(this,t)||this,r=null!=t.value?t.value:null!=t.defaultValue?t.defaultValue:t.min;return n.state={dragging:!1,value:n.clampAlignValue(r)},n}return n(r,e),r.prototype.componentWillReceiveProps=function(e){if("value"in e||"min"in e||"max"in e){var t=this.state.value,n=null==e.value?t:e.value,r=this.clampAlignValue(n,e);r!==t&&(this.setState({value:r}),a(n,e)&&this.props.onChange(r))}},r.prototype.render=function(e,n){var r=e.min,o=e.max,a=e.vertical,i=e.included,s=e.disabled,u=e.classesPrefix,l=e.tipFormatter,c=n.value,d=n.dragging,p=this.calcOffset(c),h=t.h(P,{vertical:a,disabled:s,dragging:d,min:r,max:o,value:c,index:1,offset:p,classesPrefix:u,ref:this.saveHandle,key:"handle-0"},l(c)),f=t.h(B,{vertical:a,included:i,index:1,offset:0,length:p,classesPrefix:u,key:"track-0"});return this.renderBase(f,h)},r.prototype.getValue=function(){return this.state.value},r.prototype.getLowerBound=function(){return this.props.min},r.prototype.getUpperBound=function(){return this.state.value},r.prototype.onChange=function(e){var t=this.props;!("value"in t)&&this.setState(e),t.onChange(e.value)},r.prototype.onStart=function(e){this.setState({dragging:!0});var t=this.getValue();this.props.onBeforeChange(t);var n=this.calcValueByPos(e);n!==t&&this.onChange({value:n})},r.prototype.onMove=function(e){var t=this.calcValueByPos(e);t!==this.state.value&&this.onChange({value:t})},r.prototype.onEnd=function(){this.setState({dragging:!1})},r.prototype.clampAlignValue=function(e,t){void 0===t&&(t={});var n=x({},this.props,t);return u(o(e,n),n)},r}(S),M=function(e){function r(t){var n=e.call(this,t)||this,r=t.count,o=t.min,a=t.max,i=Array(r+1).slice().map(function(){return o}),s=(null!=t.value?t.value:null!=t.defaultValue?t.defaultValue:i).map(function(e){return n.clampAlignValue(e)}),u=s[0]===a?0:s.length-1;return n.state={handle:null,recent:u,bounds:s},n}return n(r,e),r.prototype.componentWillReceiveProps=function(e){var t=this;if("value"in e||"min"in e||"max"in e){var n=this.state.bounds,r=(e.value||n).map(function(n){return t.clampAlignValue(n,e)});r.length===n.length&&r.every(function(e,t){return e===n[t]})||(this.setState({bounds:r}),n.some(function(t){return a(t,e)})&&this.props.onChange(r))}},r.prototype.render=function(e,n){var r=this,o=e.min,a=e.max,i=e.vertical,s=e.included,u=e.disabled,l=e.classesPrefix,c=e.tipFormatter,d=n.handle,p=n.bounds,h=p.map(function(e){return r.calcOffset(e)}),f=p.map(function(e,n){return t.h(P,{vertical:i,disabled:u,dragging:d===n,min:o,max:a,value:e,index:n+1,offset:h[n],classesPrefix:l,ref:function(e){return r.saveHandle(e,n)},key:"handle-"+n},c(e))}),v=p.slice(0,-1).map(function(e,n){var r=n+1;return t.h(B,{vertical:i,included:s,index:r,offset:h[n],length:h[r]-h[n],classesPrefix:l,key:"track-"+n})});return this.renderBase(v,f)},r.prototype.getValue=function(){return this.state.bounds},r.prototype.getLowerBound=function(){return this.state.bounds[0]},r.prototype.getUpperBound=function(){var e=this.state.bounds;return e[e.length-1]},r.prototype.onChange=function(e){var t=this.props;!("value"in t)?this.setState(e):void 0!==e.handle&&this.setState({handle:e.handle});var n=x({},this.state,e);t.onChange(n.bounds)},r.prototype.onStart=function(e){var t=this.props,n=this.state,r=this.getValue();t.onBeforeChange(r);var o=this.calcValueByPos(e),a=this.getClosestBound(o),i=this.getBoundNeedMoving(o,a);if(this.setState({handle:i,recent:i}),o!==r[i]){var s=n.bounds.slice();s[i]=o,this.onChange({bounds:s})}},r.prototype.onMove=function(e){var t=this.props,n=this.state;if(null!=n.handle){var r=this.calcValueByPos(e);if(r!==n.bounds[n.handle]){var o=n.bounds.slice();o[n.handle]=r;var a=n.handle;if(!1!==t.pushable){var i=n.bounds[a];this.pushSurroundingHandles(o,a,i)}else t.allowCross&&(o.sort(function(e,t){return e-t}),a=o.indexOf(r));this.onChange({handle:a,bounds:o})}}},r.prototype.onEnd=function(){this.setState({handle:null})},r.prototype.clampAlignValue=function(e,t){void 0===t&&(t={});var n=x({},this.props,t);return u(this.clampValueToSurroundingHandles(o(e,n),n),n)},r.prototype.getClosestBound=function(e){for(var t=this.state.bounds,n=0,r=1,o=t.length-1;r<o;r++)e>t[r]&&(n=r);return Math.abs(t[n+1]-e)<Math.abs(t[n]-e)&&(n+=1),n},r.prototype.getBoundNeedMoving=function(e,t){var n=this.state,r=n.bounds,o=n.recent,a=t,i=t+1;return r[i]===r[t]&&(a=r[o]===r[t]?o:i,e!==r[i]&&(a=e<r[i]?t:i)),a},r.prototype.pushSurroundingHandles=function(e,t,n){var r=Number(this.props.pushable),o=e[t],a=0;if(e[t+1]-o<r&&(a=1),o-e[t-1]<r&&(a=-1),0!==a){var i=t+a,s=a*(e[i]-o);this.pushHandle(e,i,a,r-s)||(e[t]=n)}},r.prototype.pushHandle=function(e,t,n,r){for(var o=e[t],a=e[t];n*(a-o)<r;){if(!this.pushHandleOnePoint(e,t,n))return e[t]=o,!1;a=e[t]}return!0},r.prototype.pushHandleOnePoint=function(e,t,n){var r=this.getPoints(),o=r.indexOf(e[t])+n;if(o>=r.length||o<0)return!1;var a=t+n,i=r[o],s=Number(this.props.pushable),u=n*(e[a]-i);return!!this.pushHandle(e,a,n,s-u)&&(e[t]=i,!0)},r.prototype.getPoints=function(){var e=this.props,t=e.marks,n=e.step,r=e.min,o=e.max,a=this.pointsCache;if(!a||a.marks!==t||a.step!==n){var i=x({},t);if(null!=n&&n>0)for(var s=r;s<=o;s+=n)i[s]=String(s);var u=Object.keys(i).map(Number);u.sort(function(e,t){return e-t}),this.pointsCache={marks:t,step:n,points:u}}return this.pointsCache.points},r.prototype.clampValueToSurroundingHandles=function(e,t){var n=t.allowCross,r=this.state,o=r.handle,a=r.bounds;if(!n&&null!=o){if(o>0&&e<=a[o-1])return a[o-1];if(o<a.length-1&&e>=a[o+1])return a[o+1]}return e},r}(S);M.defaultProps=x({},S.defaultProps,{count:1,allowCross:!0,pushable:!1}),e.Slider=E,e.MultiSlider=M,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t(e.PreactRangeSlider={},e.preact)}(this,function(e,t){"use strict";function n(e,t){function n(){this.constructor=e}b(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function r(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}function o(e,t){var n=t.min,r=t.max;return e<=n?n:e>=r?r:e}function a(e,t){var n=t.min,r=t.max;return e<n||e>r}function i(e){var t=e.toString(),n=t.indexOf("."),r=0;return-1!==n&&(r=t.length-n-1),r}function s(e,t){var n=t.marks,r=t.step,o=t.min,a=Object.keys(n).map(Number);if(null!=r&&r>0){var i=Math.round((e-o)/r)*r+o;a.push(i)}var s=a.map(function(t){return Math.abs(e-t)});return a[s.indexOf(Math.min.apply(Math,s))]||o}function u(e,t){var n=t.step,r=s(e,t);return null==n||n<=0?r:Number(r.toFixed(i(n)))}function l(e,t){var n=t.getBoundingClientRect();return e?n.top+n.height/2:n.left+n.width/2}function c(e,t){return e?t.clientY:t.pageX}function p(e,t){return e?t.touches[0].clientY:t.touches[0].pageX}function d(e,t){return t.some(function(t){return e.target===t})}function h(e){return e.touches.length>1||"touchend"===e.type.toLowerCase()&&e.touches.length>0}function f(e){e.stopPropagation(),e.preventDefault()}function v(e,t){for(var n=[],r=Object.keys(e),o=0,a=r.length;o<a;o++){var i=r[o];e[i]&&n.push(i)}return t&&(n=t.concat(n)),n.join(" ")}function m(e){var n=e.min,r=e.max,o=e.lowerBound,a=e.upperBound,i=e.marks,s=e.included,u=e.vertical,l=e.classesPrefix,c=Object.keys(i),p=.9*(100/(c.length-1)),d=r-n,h=c.map(Number).sort(function(e,t){return e-t}).map(function(e){var r=!s&&e===a||s&&e<=a&&e>=o,c=v((m={},m[l+"active"]=r,m),[l+"text"]),h=u?{marginBottom:"-50%",bottom:(e-n)/d*100+"%"}:{width:p+"%",marginLeft:-p/2+"%",left:(e-n)/d*100+"%"},f=i[e];return t.h("span",{class:c,style:h,key:String(e)},f);var m});return t.h("div",{class:l+"marks"},h)}function g(e){var n=e.min,r=e.max,o=e.step,a=e.lowerBound,i=e.upperBound,s=e.marks,u=e.dots,l=e.included,c=e.vertical,p=e.classesPrefix,d=r-n,h=y(s,u,o,n,r).map(function(e){var r=Math.abs(e-n)/d*100+"%",o=c?{bottom:r}:{left:r},s=!l&&e===i||l&&e<=i&&e>=a,u=v((h={},h[p+"active"]=s,h),[p+"dot"]);return t.h("span",{class:u,style:o,key:String(e)});var h});return t.h("div",{class:p+"steps"},h)}function y(e,t,n,r,o){var a=Object.keys(e).map(Number);if(t&&n>0)for(var i=r;i<=o;i+=n)-1===a.indexOf(i)&&a.push(i);return a}var b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},x=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},S=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.dragOffset=0,t.handlesRefs=[],t.saveSlider=function(e){t.sliderRef=e},t.saveHandle=function(e,n){void 0===n&&(n=0),null==e?delete t.handlesRefs[n]:t.handlesRefs[n]=e.base},t.onMouseDown=function(e){if(0===e.button){var n=t.props.vertical,r=c(n,e);if(d(e,t.handlesRefs)){var o=l(n,e.target);t.dragOffset=r-o,r=o}else t.dragOffset=0;t.onStart(r),t.addDocumentMouseEvents(),f(e)}},t.onTouchStart=function(e){if(!h(e)){var n=t.props.vertical,r=p(n,e);if(d(e,t.handlesRefs)){var o=l(n,e.target);t.dragOffset=r-o,r=o}else t.dragOffset=0;t.onStart(r),t.addDocumentTouchEvents(),f(e)}},t.onMouseMove=function(e){if(t.sliderRef){var n=c(t.props.vertical,e);t.onMove(n-t.dragOffset),f(e)}else t.onEnd()},t.onTouchMove=function(e){if(t.sliderRef&&!h(e)){var n=p(t.props.vertical,e);t.onMove(n-t.dragOffset),f(e)}else t.onEnd()},t.onEventEnd=function(){t.removeDocumentEvents(),t.onEnd(),t.props.onAfterChange(t.getValue())},t}return n(o,e),o.prototype.componentWillUnmount=function(){this.removeDocumentEvents()},o.prototype.renderBase=function(e,n){var o=this.props,a=o.min,i=o.max,s=o.step,u=o.marks,l=o.dots,c=o.included,p=o.vertical,d=o.disabled,h=o.className,f=o.classesPrefix,y=o.children,b=this.getLowerBound(),x=this.getUpperBound(),S=v((P={},P[f+"with-marks"]=Object.keys(u).length,P[f+"vertical"]=p,P[f+"disabled"]=d,P),[h]);return t.h("div",{class:S,ref:this.saveSlider,onTouchStart:d?r:this.onTouchStart,onMouseDown:d?r:this.onMouseDown},t.h("div",{class:f+"rail"}),e,t.h(g,{vertical:p,marks:u,dots:l,step:s,included:c,lowerBound:b,upperBound:x,max:i,min:a,classesPrefix:f}),n,t.h(m,{vertical:p,marks:u,included:c,lowerBound:b,upperBound:x,max:i,min:a,classesPrefix:f}),y);var P},o.prototype.getSliderStart=function(){var e=this.sliderRef;if(!e)return 0;var t=e.getBoundingClientRect();return this.props.vertical?t.top:t.left},o.prototype.getSliderLength=function(){var e=this.sliderRef;return e?this.props.vertical?e.clientHeight:e.clientWidth:0},o.prototype.calcValue=function(e){var t=this.props,n=t.vertical,r=t.min,o=t.max,a=Math.abs(Math.max(e,0)/this.getSliderLength());return n?(1-a)*(o-r)+r:a*(o-r)+r},o.prototype.calcValueByPos=function(e){var t=e-this.getSliderStart();return this.clampAlignValue(this.calcValue(t))},o.prototype.calcOffset=function(e){var t=this.props,n=t.min;return 100*((e-n)/(t.max-n))},o.prototype.addDocumentMouseEvents=function(){document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onEventEnd)},o.prototype.addDocumentTouchEvents=function(){document.addEventListener("touchmove",this.onTouchMove),document.addEventListener("touchend",this.onEventEnd)},o.prototype.removeDocumentEvents=function(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onEventEnd),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onEventEnd)},o.defaultProps={min:0,max:100,step:1,marks:{},dots:!1,included:!0,vertical:!1,disabled:!1,className:"range-slider",classesPrefix:"",onBeforeChange:r,onChange:r,onAfterChange:r,tipFormatter:String},o}(t.Component),P=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.saveElement=function(e){t.elementRef=e},t}return n(r,e),r.prototype.render=function(e){var n=e.min,r=e.max,o=e.value,a=e.vertical,i=e.disabled,s=e.dragging,u=e.index,l=e.offset,c=e.classesPrefix,p=e.children,d=a?{bottom:l+"%"}:{left:l+"%"};s&&this.elementRef&&this.elementRef.focus();var h=v((f={},f[c+"dragging"]=s,f),[c+"handle",c+"handle-"+u]);return t.h("div",{class:h,style:d,role:"slider",tabIndex:i?void 0:0,"aria-orientation":a?"vertical":"horizontal","aria-disabled":String(i),"aria-valuemin":n,"aria-valuemax":r,"aria-valuenow":o,ref:this.saveElement},t.h("span",{class:c+"tip"},p));var f},r}(t.Component),B=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return n(r,e),r.prototype.render=function(e){var n=e.vertical,r=e.included,o=e.index,a=e.offset,i=e.length,s=e.classesPrefix,u={};return r||(u.visibility="hidden"),n?(u.bottom=a+"%",u.height=i+"%"):(u.left=a+"%",u.width=i+"%"),t.h("div",{class:s+"track "+s+"track-"+o,style:u})},r}(t.Component),E=function(e){function r(t){var n=e.call(this,t)||this,r=null!=t.value?t.value:null!=t.defaultValue?t.defaultValue:t.min;return n.state={dragging:!1,value:n.clampAlignValue(r)},n}return n(r,e),r.prototype.componentWillReceiveProps=function(e){if("value"in e||"min"in e||"max"in e){var t=this.state.value,n=null==e.value?t:e.value,r=this.clampAlignValue(n,e);r!==t&&(this.setState({value:r}),a(n,e)&&this.props.onChange(r))}},r.prototype.render=function(e,n){var r=e.min,o=e.max,a=e.vertical,i=e.included,s=e.disabled,u=e.classesPrefix,l=e.tipFormatter,c=n.value,p=n.dragging,d=this.calcOffset(c),h=t.h(P,{vertical:a,disabled:s,dragging:p,min:r,max:o,value:c,index:1,offset:d,classesPrefix:u,ref:this.saveHandle,key:"handle-0"},l(c)),f=t.h(B,{vertical:a,included:i,index:1,offset:0,length:d,classesPrefix:u,key:"track-0"});return this.renderBase(f,h)},r.prototype.getValue=function(){return this.state.value},r.prototype.getLowerBound=function(){return this.props.min},r.prototype.getUpperBound=function(){return this.state.value},r.prototype.onChange=function(e){var t=this.props;!("value"in t)&&this.setState(e),t.onChange(e.value)},r.prototype.onStart=function(e){this.setState({dragging:!0});var t=this.getValue();this.props.onBeforeChange(t);var n=this.calcValueByPos(e);n!==t&&this.onChange({value:n})},r.prototype.onMove=function(e){var t=this.calcValueByPos(e);t!==this.state.value&&this.onChange({value:t})},r.prototype.onEnd=function(){this.setState({dragging:!1})},r.prototype.clampAlignValue=function(e,t){void 0===t&&(t={});var n=x({},this.props,t);return u(o(e,n),n)},r}(S),M=function(e){function r(t){var n=e.call(this,t)||this,r=t.count,o=t.min,a=t.max,i=Array(r+1).slice().map(function(){return o}),s=(null!=t.value?t.value:null!=t.defaultValue?t.defaultValue:i).map(function(e){return n.clampAlignValue(e)}),u=s[0]===a?0:s.length-1;return n.state={handle:null,recent:u,bounds:s},n}return n(r,e),r.prototype.componentWillReceiveProps=function(e){var t=this;if("value"in e||"min"in e||"max"in e){var n=this.state.bounds,r=(e.value||n).map(function(n){return t.clampAlignValue(n,e)});r.length===n.length&&r.every(function(e,t){return e===n[t]})||(this.setState({bounds:r}),n.some(function(t){return a(t,e)})&&this.props.onChange(r))}},r.prototype.render=function(e,n){var r=this,o=e.min,a=e.max,i=e.vertical,s=e.included,u=e.disabled,l=e.classesPrefix,c=e.tipFormatter,p=n.handle,d=n.bounds,h=d.map(function(e){return r.calcOffset(e)}),f=d.map(function(e,n){return t.h(P,{vertical:i,disabled:u,dragging:p===n,min:o,max:a,value:e,index:n+1,offset:h[n],classesPrefix:l,ref:function(e){return r.saveHandle(e,n)},key:"handle-"+n},c(e))}),v=d.slice(0,-1).map(function(e,n){var r=n+1;return t.h(B,{vertical:i,included:s,index:r,offset:h[n],length:h[r]-h[n],classesPrefix:l,key:"track-"+n})});return this.renderBase(v,f)},r.prototype.getValue=function(){return this.state.bounds},r.prototype.getLowerBound=function(){return this.state.bounds[0]},r.prototype.getUpperBound=function(){var e=this.state.bounds;return e[e.length-1]},r.prototype.onChange=function(e){var t=this.props;!("value"in t)?this.setState(e):void 0!==e.handle&&this.setState({handle:e.handle});var n=x({},this.state,e);t.onChange(n.bounds)},r.prototype.onStart=function(e){var t=this.props,n=this.state,r=this.getValue();t.onBeforeChange(r);var o=this.calcValueByPos(e),a=this.getClosestBound(o),i=this.getBoundNeedMoving(o,a);if(this.setState({handle:i,recent:i}),o!==r[i]){var s=n.bounds.slice();s[i]=o,this.onChange({bounds:s})}},r.prototype.onMove=function(e){var t=this.props,n=this.state;if(null!=n.handle){var r=this.calcValueByPos(e);if(r!==n.bounds[n.handle]){var o=n.bounds.slice();o[n.handle]=r;var a=n.handle;if(!1!==t.pushable){var i=n.bounds[a];this.pushSurroundingHandles(o,a,i)}else t.allowCross&&(o.sort(function(e,t){return e-t}),a=o.indexOf(r));this.onChange({handle:a,bounds:o})}}},r.prototype.onEnd=function(){this.setState({handle:null})},r.prototype.clampAlignValue=function(e,t){void 0===t&&(t={});var n=x({},this.props,t);return u(this.clampValueToSurroundingHandles(o(e,n),n),n)},r.prototype.getClosestBound=function(e){for(var t=this.state.bounds,n=0,r=1,o=t.length-1;r<o;r++)e>t[r]&&(n=r);return Math.abs(t[n+1]-e)<Math.abs(t[n]-e)&&(n+=1),n},r.prototype.getBoundNeedMoving=function(e,t){var n=this.state,r=n.bounds,o=n.recent,a=t,i=t+1;return r[i]===r[t]&&(a=r[o]===r[t]?o:i,e!==r[i]&&(a=e<r[i]?t:i)),a},r.prototype.pushSurroundingHandles=function(e,t,n){var r=Number(this.props.pushable),o=e[t],a=0;if(e[t+1]-o<r&&(a=1),o-e[t-1]<r&&(a=-1),0!==a){var i=t+a,s=a*(e[i]-o);this.pushHandle(e,i,a,r-s)||(e[t]=n)}},r.prototype.pushHandle=function(e,t,n,r){for(var o=e[t],a=e[t];n*(a-o)<r;){if(!this.pushHandleOnePoint(e,t,n))return e[t]=o,!1;a=e[t]}return!0},r.prototype.pushHandleOnePoint=function(e,t,n){var r=this.getPoints(),o=r.indexOf(e[t])+n;if(o>=r.length||o<0)return!1;var a=t+n,i=r[o],s=Number(this.props.pushable),u=n*(e[a]-i);return!!this.pushHandle(e,a,n,s-u)&&(e[t]=i,!0)},r.prototype.getPoints=function(){var e=this.props,t=e.marks,n=e.step,r=e.min,o=e.max,a=this.pointsCache;if(!a||a.marks!==t||a.step!==n){var i=x({},t);if(null!=n&&n>0)for(var s=r;s<=o;s+=n)i[s]=String(s);var u=Object.keys(i).map(Number);u.sort(function(e,t){return e-t}),this.pointsCache={marks:t,step:n,points:u}}return this.pointsCache.points},r.prototype.clampValueToSurroundingHandles=function(e,t){var n=t.allowCross,r=this.state,o=r.handle,a=r.bounds;if(!n&&null!=o){if(o>0&&e<=a[o-1])return a[o-1];if(o<a.length-1&&e>=a[o+1])return a[o+1]}return e},r.defaultProps=x({},S.defaultProps,{count:1,allowCross:!0,pushable:!1}),r}(S);e.Slider=E,e.MultiSlider=M,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "preact-range-slider", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Preact component for input values with range slider", | ||
@@ -40,15 +40,15 @@ "main": "es5/index.js", | ||
"peerDependencies": { | ||
"preact": "^8.1.0", | ||
"preact": "^8.2.1", | ||
"tslib": "^1.7.1" | ||
}, | ||
"devDependencies": { | ||
"dart-sass": "^1.0.0-beta.1", | ||
"preact": "^8.1.0", | ||
"rollup": "^0.43.0", | ||
"dart-sass": "^1.0.0-beta.2", | ||
"preact": "^8.2.1", | ||
"rollup": "^0.47.4", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"tslib": "^1.7.1", | ||
"tslint": "^5.4.3", | ||
"tslint-config-m18": "^1.4.0", | ||
"typescript": "^2.3.4", | ||
"uglify-js": "^3.0.18" | ||
"tslint": "^5.6.0", | ||
"tslint-config-m18": "^1.5.0", | ||
"typescript": "^2.4.2", | ||
"uglify-js": "^3.0.27" | ||
}, | ||
@@ -55,0 +55,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232074
4618