UNPKG

vue-component-ruler

Version:
2 lines 6.6 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("vue")):"function"==typeof define&&define.amd?define("ruler",["vue"],e):"object"==typeof exports?exports.ruler=e(require("vue")):t.ruler=e(t.Vue)}("undefined"!=typeof self?self:this,function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var a=e[r]={i:r,l:!1,exports:{}};return t[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/",n(n.s=2)}([function(t,e,n){"use strict";var r=n(6),a=n(7);e.a={props:{value:{type:Number,default:0},range:{default:function(){return[0,300]}},itemWidth:{type:Number,default:24},visibleItemCount:{type:Number,default:30}},methods:{initEvents:function(){var t=this,e=this.$refs.wrapper,n={},s=void 0,o=void 0;Object(r.a)(e,{start:function(r){cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null,n={range:t.dragRange,start:new Date,startLeft:r.pageX,startTop:r.pageY,startTranslateLeft:a.a.getElementTranslate(e).left}},drag:function(r){t.dragging=!0,n.left=r.pageX,n.top=r.pageY;var i=n.left-n.startLeft,u=n.startTranslateLeft+i;a.a.translateElement(e,u,null),s=u-o||u,o=u;var l=n.range,c=Math.max(Math.min(u,l[1]),l[0]);t.currentValue=t.translate2Value(c)},end:function(r){t.dragging=!1;var o=a.a.getElementTranslate(e).left,i=new Date-n.start;Math.abs(n.startTranslateLeft-o)<6&&console.log("distance<6",void 0,void 0);var u=void 0;i<300&&(u=o+7*s);var l=n.range;t.$nextTick(function(){var n;n=u?24*Math.round(u/24):24*Math.round(o/24),n=Math.max(Math.min(n,l[1]),l[0]),a.a.translateElement(e,n,null),t.currentValue=t.translate2Value(n)}),n={}}})},translate2Value:function(t){var e=this.itemWidth;return-((t=Math.round(t/e)*e)-Math.floor(this.visibleItemCount/2)*e)/e},value2Translate:function(t){var e=this.itemWidth;return-t*e+Math.floor(this.visibleItemCount/2)*e},doOnValueChange:function(t){var e=void 0!==t?t:this.currentValue,n=this.$refs.wrapper;a.a.translateElement(n,this.value2Translate(e),null)}},computed:{dragRange:function(){var t=this.sticks,e=this.visibleItemCount,n=this.itemWidth;return[-n*(t.length-Math.ceil(e/2)),n*Math.floor(e/2)]}},data:function(){var t=this.range,e=t[1]-t[0];return{sticks:new Array(e).fill(""),currentValue:this.value}},mounted:function(){this.initEvents(),this.doOnValueChange()},watch:{currentValue:function(t){this.$emit("onchange",t)}}}},function(e,n){e.exports=t},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(3);e.default=r.a},function(t,e,n){"use strict";var r=n(0),a=n(8);var s=function(t){n(4)},o=n(5)(r.a,a.a,!1,s,"data-v-784f41d5",null);e.a=o.exports},function(t,e){},function(t,e){t.exports=function(t,e,n,r,a,s){var o,i=t=t||{},u=typeof t.default;"object"!==u&&"function"!==u||(o=t,i=t.default);var l,c="function"==typeof i?i.options:i;if(e&&(c.render=e.render,c.staticRenderFns=e.staticRenderFns,c._compiled=!0),n&&(c.functional=!0),a&&(c._scopeId=a),s?(l=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},c._ssrRegister=l):r&&(l=r),l){var d=c.functional,f=d?c.render:c.beforeCreate;d?(c._injectStyles=l,c.render=function(t,e){return l.call(e),f(t,e)}):c.beforeCreate=f?[].concat(f,l):[l]}return{esModule:o,exports:i,options:c}}},function(t,e,n){"use strict";var r=n(1),a=!1,s=!n.n(r).a.prototype.$isServer&&"ontouchstart"in window;e.a=function(t,e){var n=function(t){e.drag&&e.drag(s?t.changedTouches[0]||t.touches[0]:t)},r=function t(r){s||(document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",t)),document.onselectstart=null,document.ondragstart=null,a=!1,e.end&&e.end(s?r.changedTouches[0]||r.touches[0]:r)};t.addEventListener(s?"touchstart":"mousedown",function(t){a||(document.onselectstart=function(){return!1},document.ondragstart=function(){return!1},s||(document.addEventListener("mousemove",n),document.addEventListener("mouseup",r)),a=!0,e.start&&(t.preventDefault(),e.start(s?t.changedTouches[0]||t.touches[0]:t)))}),s&&(t.addEventListener("touchmove",n),t.addEventListener("touchend",r),t.addEventListener("touchcancel",r))}},function(t,e,n){"use strict";var r=n(1),a={};if(!n.n(r).a.prototype.$isServer){var s,o=document.documentElement.style,i=!1;window.opera&&"[object Opera]"===Object.prototype.toString.call(opera)?s="presto":"MozAppearance"in o?s="gecko":"WebkitAppearance"in o?s="webkit":"string"==typeof navigator.cpuClass&&(s="trident");var u={trident:"-ms-",gecko:"-moz-",webkit:"-webkit-",presto:"-o-"}[s],l={trident:"ms",gecko:"Moz",webkit:"Webkit",presto:"O"}[s],c=document.createElement("div"),d=l+"Perspective",f=l+"Transform",p=u+"transform",v=l+"Transition",m=u+"transition",h=l.toLowerCase()+"TransitionEnd";void 0!==c.style[d]&&(i=!0);var g=function(t){var e={left:0,top:0};if(null===t||null===t.style)return e;var n=t.style[f],r=/translate\(\s*(-?\d+(\.?\d+?)?)px,\s*(-?\d+(\.\d+)?)px\)\s*translateZ\(0px\)/gi.exec(n);return r&&(e.left=+r[1],e.top=+r[3]),e},y=function(t){if(null!==t&&null!==t.style){var e=t.style[f];e&&(e=e.replace(/translate\(\s*(-?\d+(\.?\d+?)?)px,\s*(-?\d+(\.\d+)?)px\)\s*translateZ\(0px\)/g,""),t.style[f]=e)}};a={transformProperty:f,transformStyleName:p,transitionProperty:v,transitionStyleName:m,transitionEndProperty:h,getElementTranslate:g,translateElement:function(t,e,n){if((null!==e||null!==n)&&null!==t&&void 0!==t&&null!==t.style&&(t.style[f]||0!==e||0!==n)){if(null===e||null===n){var r=g(t);null===e&&(e=r.left),null===n&&(n=r.top)}y(t),t.style[f]+=i?" translate("+(e?e+"px":"0px")+","+(n?n+"px":"0px")+") translateZ(0px)":" translate("+(e?e+"px":"0px")+","+(n?n+"px":"0px")+")"}},cancelTranslateElement:y}}e.a=a},function(t,e,n){"use strict";var r={render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"slide"},[n("div",{ref:"wrapper",staticClass:"sticks"},t._l(t.sticks,function(e,r){return n("span",{key:e.sticks,staticClass:"singleStick"},[(r+10)%10==0?n("i",{staticClass:"tips"},[t._v(t._s(.1*r+".0"))]):t._e()])})),t._v(" "),n("span",{staticClass:"singleStick active"}),t._v(" "),n("i",{staticClass:"baseline"})])},staticRenderFns:[]};e.a=r}])}); //# sourceMappingURL=ruler.min.js.map