@minix-iot/ui
Version:
基于Vue的移动端轻量级UI组件库
7 lines • 14.6 kB
JavaScript
/*!
* @minix-iot/ui v0.2.4 - slider.js, 2709badeb34a699cd765, Wed Nov 24 2021 14:21:12 GMT+0800 (中国标准时间)
* (c) 2017-2020 JDC
* Released under the MIT License.
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("vue")):"function"==typeof define&&define.amd?define("slider",["vue"],e):"object"==typeof exports?exports.slider=e(require("vue")):t.slider=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 o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return 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=125)}({0:function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0},1:function(t,e){t.exports=function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t},t.exports.default=t.exports,t.exports.__esModule=!0},10:function(t,e,n){var r=n(7);t.exports=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0},12:function(t,e,n){var r=n(7);t.exports=function(t){if(Array.isArray(t))return r(t)},t.exports.default=t.exports,t.exports.__esModule=!0},125:function(t,e,n){"use strict";n.r(e);var r=n(5),o=n(24),i=n(18),u=n(22),a=n(3).a.Create("slider"),s={name:a.name,props:{linear:{type:Array,default:function(){return[]}},value:{type:Number,default:0},min:{type:Number,default:0},max:{type:Number,default:100},step:{type:Number,default:1},trackHeight:{type:Number,default:-1},buttonSize:{type:Number,default:-1},trackColor:{type:String},barColor:{type:String},scaleColor:{type:String},buttonColor:{type:String},theme:{type:String,default:"brand"},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},model:{prop:"value",event:"input"},data:function(){return{touch:o.a.Create(),current:0,startValue:0,dragStatus:""}},computed:{wrapperCls:function(){return a.derive("wrapper",{disabled:this.disabled})},cls:function(){return a.derive()},trackCls:function(){return a.derive("track")},barCls:function(){return a.derive("bar",[this.theme])},buttonCls:function(){return a.derive("button",[this.theme])},scaleCls:function(){return a.derive("scale-wrapper")},scaleTextCls:function(){return a.derive("scale-text")},sliderStyle:function(){var t={};return this.buttonSize>0&&(t.height="".concat(this.buttonSize,"px")),t},trackStyle:function(){var t={};return this.trackColor&&(t.background=this.trackColor),this.trackHeight&&(t.height="".concat(this.trackHeight,"px")),t},barStyle:function(){var t={width:"".concat(100*(this.value-this.min)/this.scope,"%")};return this.dragStatus&&(t.transition="none"),this.linear.length>0&&(t.background="linear-gradient(to right, ".concat(this.linear.join(","),")")),this.barColor&&(t.background=this.barColor),t},buttonStyle:function(){var t={};return this.linear.length>0&&(t.background=this.linear[this.linear.length-1]),this.buttonColor&&(t.background=this.buttonColor),this.buttonSize>0&&(t.width="".concat(this.buttonSize,"px"),t.height="".concat(this.buttonSize,"px"),t.borderRadius="".concat(this.buttonSize/2," px")),t},scaleStyle:function(){var t={};return this.scaleColor&&(t.color=this.scaleColor),t},canInteract:function(){return!this.disabled&&!this.readonly},scope:function(){return this.max-this.min}},methods:{onClick:function(t){if(t.stopPropagation(),this.canInteract){var e=this.$refs.slider.getBoundingClientRect(),n=t.clientX-e.left,r=e.width,o=this.min+n/r*this.scope;this.update(o,!0)}},onTouchStart:function(t){this.canInteract&&(this.touch.start(t),this.current=this.value,this.startValue=this.format(this.current),this.dragStatus="start")},onTouchMove:function(t){if(this.canInteract){"start"===this.dragStatus&&this.$emit("dragstart",t),i.a.PreventDefault(t),this.touch.move(t),this.dragStatus="draging";var e=this.$refs.slider.getBoundingClientRect(),n=this.touch.deltaX/e.width*this.scope;this.current=this.startValue+n,this.update(this.current)}},onTouchEnd:function(t){this.canInteract&&("draging"===this.dragStatus&&(this.update(this.current,!0),this.$emit("dragend",t)),this.dragStatus="")},format:function(t){var e=+this.min,n=+this.max,r=+this.step,o=u.a.Clamp(t,e,n);return e+Math.round((o-e)/r)*r},update:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=this.format(t);n!==this.value&&this.$emit("input",n),e&&n!==this.startValue&&this.$emit("change",n)}},render:function(){var t=this,e=arguments[0],n=function(){return e("div",{ref:"slider",class:t.cls,style:t.sliderStyle,on:{click:t.onClick}},[e("div",{class:t.trackCls,style:t.trackStyle},[e("div",{class:t.barCls,style:t.barStyle},[e("div",{class:t.buttonCls,style:t.buttonStyle,on:{touchstart:t.onTouchStart,touchmove:t.onTouchMove,touchend:t.onTouchEnd,touchcancel:t.onTouchEnd,click:function(t){return t.stopPropagation()}}})])])])},r=function(){if(t.$slots.default)return e("div",{class:t.scaleCls,style:t.scaleStyle},[t.$slots.default])};return e("div",{class:this.wrapperCls},[n(),r()])}};n(84);r.a.WithInstall(s);e.default=s},13:function(t,e){t.exports=function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)},t.exports.default=t.exports,t.exports.__esModule=!0},14:function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0},16:function(t,e,n){"use strict";n.d(e,"a",(function(){return a}));var r=n(0),o=n.n(r),i=n(1),u=n.n(i),a=function t(){o()(this,t)};u()(a,"NONE",""),u()(a,"HOR","horizental"),u()(a,"VER","vertical")},18:function(t,e,n){"use strict";n.d(e,"a",(function(){return a}));var r=n(0),o=n.n(r),i=n(2),u=n.n(i),a=function(){function t(){o()(this,t)}return u()(t,null,[{key:"IsWindow",value:function(t){return t===window}},{key:"IsElement",value:function(t){return(null==t?void 0:t.nodeType)===Node.ELEMENT_NODE}},{key:"IsHidden",value:function(t){if(t)return!1;var e=widnow.getComputedStyle(t),n="none"===e.getPropertyValue("display"),r=null===t.offsetParent&&"fixed"!==e.getPropertyValue("position");return n||r}},{key:"GetScrollTop",value:function(t){return Math.max("scrollTop"in t?t.scrollTop:t.scrollY,0)}},{key:"GetBoundingClientRect",value:function(t){return null!=t&&t.getBoundingClientRect?t.getBoundingClientRect():this.IsWindow(t)?new DOMRect(0,0,t.innerWidth,t.innerHeight):new DOMRect(0,0,0,0)}},{key:"GetScrollParent",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window,n=t;n&&n!==e&&this.IsElement(n);){var r=window.getComputedStyle(n).getPropertyValue("overflow-y");if(/scroll|auto/i.test(r)&&n.scrollHeight>n.offsetHeight)return n;n=n.parentNode}return e}},{key:"stopPropagation",value:function(t){null==t||t.stopPropagation()}},{key:"PreventDefault",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];("boolean"!=typeof(null==t?void 0:t.cancelable)||null!=t&&t.cancelable)&&t.preventDefault(),e&&t.stopPropagation()}},{key:"AddEventListener",value:function(t,e,n,r){t&&t instanceof EventTarget&&t.addEventListener(e,n,r)}},{key:"RemoveEventListener",value:function(t,e,n){t&&t instanceof EventTarget&&t.removeEventListener(e,n)}}]),t}()},2:function(t,e){function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}t.exports=function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t},t.exports.default=t.exports,t.exports.__esModule=!0},22:function(t,e,n){"use strict";n.d(e,"a",(function(){return a}));var r=n(0),o=n.n(r),i=n(2),u=n.n(i),a=function(){function t(){o()(this,t)}return u()(t,null,[{key:"Clamp",value:function(t,e,n){return Math.min(Math.max(e,t),n)}}]),t}()},24:function(t,e,n){"use strict";n.d(e,"a",(function(){return l}));var r=n(0),o=n.n(r),i=n(2),u=n.n(i),a=n(1),s=n.n(a),c=n(16),l=function(){function t(){o()(this,t),this.startX=0,this.startY=0,this.deltaX=0,this.deltaY=0,this.direction=c.a.NONE}return u()(t,[{key:"offsetX",get:function(){return Math.abs(this.deltaX)}},{key:"offsetY",get:function(){return Math.abs(this.deltaY)}},{key:"isHorizental",get:function(){return this.direction===c.a.HOR}},{key:"isVertical",get:function(){return this.direction===c.a.VER}},{key:"isUndetermined",get:function(){return this.direction===c.a.NONE}},{key:"resolveDirection",value:function(e,n){return e>n&&e>t.MIN_DISTANCE?c.a.HOR:n>e&&n>t.MIN_DISTANCE?c.a.VER:c.a.NONE}},{key:"reset",value:function(){this.startX=0,this.startY=0,this.deltaX=0,this.deltaY=0,this.direction=c.a.NONE}},{key:"getTouchByEvent",value:function(t){return t.clientX?t:t.touches[0]}},{key:"start",value:function(t){var e=this.getTouchByEvent(t);this.reset(),this.startX=e.clientX,this.startY=e.clientY}},{key:"move",value:function(t){var e=this.getTouchByEvent(t);this.deltaX=e.clientX-this.startX,this.deltaY=e.clientY-this.startY,this.isUndetermined&&(this.direction=this.resolveDirection(this.offsetX,this.offsetY))}}],[{key:"IsTouchable",get:function(){return"ontouchstart"in window}},{key:"Create",value:function(){return new t}}]),t}();s()(l,"MIN_DISTANCE",10)},3:function(t,e,n){"use strict";n.d(e,"a",(function(){return c}));var r=n(0),o=n.n(r),i=n(2),u=n.n(i),a=n(1),s=n.n(a),c=function(){function t(e){o()(this,t),this._name=e}return u()(t,[{key:"name",get:function(){return"".concat(t.ROOT,"-").concat(this._name)}},{key:"derive",value:function(t,e){return t&&"string"!=typeof t&&(e=t,t=""),t=t?this.sub(t):this.name,"".concat(t).concat(this.mod(t,e))}},{key:"sub",value:function(t){var e=Array.isArray(t)?t:[t];return e.reduce((function(t,e){return"".concat(t,"-").concat(e)}),e.length?this.name:"")}},{key:"mod",value:function(t,e){var n=this;return e?"string"==typeof e?" ".concat(t,"--").concat(e):Array.isArray(e)?e.reduce((function(e,r){return e+n.mod(t,r)}),""):Object.keys(e).reduce((function(r,o){return r+(e[o]?n.mod(t,o):"")}),""):""}}],[{key:"Create",value:function(e){return new t(e)}}]),t}();s()(c,"ROOT","mx")},4:function(t,e,n){var r=n(12),o=n(13),i=n(10),u=n(14);t.exports=function(t){return r(t)||o(t)||i(t)||u()},t.exports.default=t.exports,t.exports.__esModule=!0},5:function(t,e,n){"use strict";n.d(e,"a",(function(){return y}));var r=n(4),o=n.n(r),i=n(6),u=n.n(i),a=n(0),s=n.n(a),c=n(2),l=n.n(c),f=n(8),d=n.n(f);function h(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return p(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return p(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return u=t.done,t},e:function(t){a=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw i}}}}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var y=function(){function t(){s()(this,t)}return l()(t,null,[{key:"WithInstall",value:function(t,e){if("object"!==u()(t)&&!t.name)throw new Error("could not install,because it is not a vue component!");t.install=function(n){n.component(t.name,t),e&&(n.prototype["$".concat(t.name.replace("mx-",""))]=e)}}},{key:"SortChildren",value:function(t,e){var n=e.$vnode.componentOptions;if(n&&n.children&&n.children.length){var r=this.FlattenVNode(n.children);return t.sort((function(t,e){return r.indexOf(t.$vnode)-r.indexOf(e.$vnode)})),t}}},{key:"FlattenVNode",value:function(t){return this.TraverseVNode(t)}},{key:"TraverseVNode",value:function(t){var e,n=[],r=h(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.push(i),i.componentInstance&&n.push.apply(n,o()(this.TraverseVNode(i.componentInstance.$children.map((function(t){return t.$vnode}))))),i.children&&n.push.apply(n,o()(this.TraverseVNode(i.children)))}}catch(t){r.e(t)}finally{r.f()}return n}},{key:"InvokeComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=[],r=function(){var e=t((function(){r.$destroy(),document.body.removeChild(r.$el),n=n.filter((function(t){return t!==r}))})),r=new d.a(e),o=document.createElement("div");return document.body.appendChild(o),r.$mount(o),r},o=function(){return n.length&&!e||n.push(r()),n[n.length-1]};return function(t){o().open(t)}}}]),t}()},6:function(t,e){function n(e){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=n=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=n=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),n(e)}t.exports=n,t.exports.default=t.exports,t.exports.__esModule=!0},7:function(t,e){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r},t.exports.default=t.exports,t.exports.__esModule=!0},8:function(e,n){e.exports=t},84:function(t,e,n){}})}));
//# sourceMappingURL=slider.js.map