UNPKG

@minix-iot/ui

Version:

基于Vue的移动端轻量级UI组件库

7 lines 16.3 kB
/*! * @minix-iot/ui v0.2.4 - pickercolumn.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("pickercolumn",["vue"],e):"object"==typeof exports?exports.pickercolumn=e(require("vue")):t.pickercolumn=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 i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.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 i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));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=70)}({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},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 s}));var r=n(0),i=n.n(r),o=n(1),u=n.n(o),s=function t(){i()(this,t)};u()(s,"NONE",""),u()(s,"HOR","horizental"),u()(s,"VER","vertical")},18:function(t,e,n){"use strict";n.d(e,"a",(function(){return s}));var r=n(0),i=n.n(r),o=n(2),u=n.n(o),s=function(){function t(){i()(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 s}));var r=n(0),i=n.n(r),o=n(2),u=n.n(o),s=function(){function t(){i()(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 f}));var r=n(0),i=n.n(r),o=n(2),u=n.n(o),s=n(1),a=n.n(s),c=n(16),f=function(){function t(){i()(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}();a()(f,"MIN_DISTANCE",10)},28:function(t,e,n){"use strict";var r=n(6),i=n.n(r),o=n(3),u=n(24),s=n(0),a=n.n(s),c=n(2),f=n.n(c),l=n(1),h=n.n(l),d=function(){function t(){a()(this,t),this.startTime=0,this.startOffset=0,this.endTime=0,this.endOffset=0}return f()(t,[{key:"shouldActive",get:function(){return Math.abs(this.interval)<t.LIMIT_TIME&&Math.abs(this.distance)>t.LIMIT_DISTANCE}},{key:"interval",get:function(){return this.endTime-this.startTime}},{key:"distance",get:function(){return this.endOffset-this.startOffset}},{key:"speed",get:function(){return this.distance/this.interval}},{key:"start",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();this.startOffset=t,this.startTime=e}},{key:"end",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();this.endOffset=t,this.endTime=e}}],[{key:"Create",value:function(){return new t}}]),t}();h()(d,"LIMIT_TIME",300),h()(d,"LIMIT_DISTANCE",15);var p=n(18),v=n(22),y=o.a.Create("picker-column");e.a={name:y.name,props:{readonly:{type:Boolean,default:!1},itemHeight:{type:Number,required:!0},visibleItemCount:{type:Number|String,required:!0},defaultIndex:{type:Number,default:0},swipeDuration:{type:Number,required:!0},items:{type:Array,default:function(){return[]}},suffix:{type:String,default:""},formatter:{type:Function,default:null}},data:function(){return{selectedIndex:this.defaultIndex,offset:0,duration:0,moving:!1,startOffset:0,correctAfterTransition:null,inertia:d.Create(),touch:u.a.Create()}},computed:{wrapperCls:function(){return y.derive("wrapper")},itemWrapperCls:function(){return y.derive("item-wrapper")},cls:function(){return y.derive()},suffixWrapperCls:function(){return y.derive("suffix-wrapper")},suffixCls:function(){return y.derive("suffix")},itemCount:function(){return this.items.length},baseOffset:function(){return this.itemHeight*(this.visibleItemCount-1)/2},wrapperStyle:function(){return{transform:"translate3d(0, ".concat(this.offset+this.baseOffset,"px, 0)"),transitionDuration:"".concat(this.duration,"ms"),transitionProperty:this.duration?"all":"none"}},itemStyle:function(){return{height:"".concat(this.itemHeight,"px"),lineHeight:"".concat(this.itemHeight,"px")}},suffixStyle:function(){return{height:"".concat(this.itemHeight,"px"),lineHeight:"".concat(this.itemHeight,"px")}}},watch:{defaultIndex:function(t){this.setIndex(t)}},created:function(){this.setIndex(this.selectedIndex)},updated:function(){this.selectedIndex>=this.itemCount&&this.setIndex(this.itemCount-1)},methods:{getTouchInfo:function(t){return t.touches[0]},getValue:function(){return this.items[this.selectedIndex]},setIndex:function(t,e){var n=this,r=this.correctIndex(t)||0,i=-r*this.itemHeight,o=function(){r!==n.selectedIndex&&(n.selectedIndex=r,e&&n.emitChange(r))};this.moving&&i!==this.offset?this.correctAfterTransition=o:o(),this.offset=i},emitChange:function(t){this.$emit("change",t)},correctIndex:function(t){for(var e=v.a.Clamp(t,0,this.itemCount),n=e;n<this.itemCount;n++)if(!this.isOptionDisabled(this.items[n]))return n;for(var r=e-1;r>=0;r--)if(!this.isOptionDisabled(this.items[r]))return r},isOptionDisabled:function(t){return"object"===i()(t)&&t.disabeld},onTouchStart:function(t){if(!this.readonly){var e=this.getTouchInfo(t);this.touch.start(e),this.duration=0,this.startOffset=this.offset,this.correctAfterTransition=null,this.inertia.start(this.offset)}},onTouchMove:function(t){if(!this.readonly){p.a.PreventDefault(t);var e=this.getTouchInfo(t);if(this.touch.move(e),this.touch.isVertical){this.moving=!0,this.offset=v.a.Clamp(this.startOffset+this.touch.deltaY,-this.itemCount*this.itemHeight,this.itemHeight);var n=Date.now();n-this.touchStartTime>d.LIMIT_TIME&&this.inertia.start(this.offset,n)}}},onTouchEnd:function(t){var e=this;if(!this.readonly)if(this.inertia.end(this.offset),this.inertia.shouldActive)this.startInertia();else{var n=this.getIndexByOffset(this.offset);this.duration=200,this.setIndex(n,!0),setTimeout((function(){return e.moving=!1}),0)}},onTransitionEnd:function(){this.stopInertia()},getIndexByOffset:function(t){return v.a.Clamp(Math.round(-t/this.itemHeight),0,this.itemCount-1)},startInertia:function(){var t=Math.abs(this.inertia.speed),e=this.offset+t/.003*(this.inertia.distance<0?-1:1),n=this.getIndexByOffset(e);this.duration=this.swipeDuration,this.setIndex(n,!0)},stopInertia:function(){this.moving=!1,this.duration=0,this.correctAfterTransition&&(this.correctAfterTransition(),this.correctAfterTransition=null)},onItemClick:function(t,e){this.moving||this.readonly||(this.correctAfterTransition=null,this.duration=200,this.setIndex(e,!0))}},render:function(){var t=this,e=arguments[0],n=function(){return t.items.map((function(n,r){var i=y.derive("item",{selected:r===t.selectedIndex});return e("li",{class:i,key:r,style:t.itemStyle,on:{click:function(e){return e.stopPropagation(),n=e,t.onItemClick(n,r);var n}}},[t.formatter?t.formatter(n.text):n.text])}))},r=function(){if(t.suffix)return e("div",{class:t.suffixWrapperCls},[e("div",{class:t.suffixCls,style:t.suffixStyle},[t.suffix])])};return e("div",{class:this.wrapperCls},[e("div",{class:this.itemWrapperCls,on:{touchstart:this.onTouchStart,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchEnd}},[e("ul",{class:this.cls,style:this.wrapperStyle,on:{transitionend:this.onTransitionEnd}},[n()])]),r()])}}},3:function(t,e,n){"use strict";n.d(e,"a",(function(){return c}));var r=n(0),i=n.n(r),o=n(2),u=n.n(o),s=n(1),a=n.n(s),c=function(){function t(e){i()(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,i){return r+(e[i]?n.mod(t,i):"")}),""):""}}],[{key:"Create",value:function(e){return new t(e)}}]),t}();a()(c,"ROOT","mx")},4:function(t,e,n){var r=n(12),i=n(13),o=n(10),u=n(14);t.exports=function(t){return r(t)||i(t)||o(t)||u()},t.exports.default=t.exports,t.exports.__esModule=!0},5:function(t,e,n){"use strict";n.d(e,"a",(function(){return v}));var r=n(4),i=n.n(r),o=n(6),u=n.n(o),s=n(0),a=n.n(s),c=n(2),f=n.n(c),l=n(8),h=n.n(l);function d(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,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}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 o,u=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==n.return||n.return()}finally{if(s)throw o}}}}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 v=function(){function t(){a()(this,t)}return f()(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=d(t);try{for(r.s();!(e=r.n()).done;){var o=e.value;n.push(o),o.componentInstance&&n.push.apply(n,i()(this.TraverseVNode(o.componentInstance.$children.map((function(t){return t.$vnode}))))),o.children&&n.push.apply(n,i()(this.TraverseVNode(o.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 h.a(e),i=document.createElement("div");return document.body.appendChild(i),r.$mount(i),r},i=function(){return n.length&&!e||n.push(r()),n[n.length-1]};return function(t){i().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},70:function(t,e,n){"use strict";n.r(e);var r=n(5),i=n(28);n(71);r.a.WithInstall(i.a),e.default=i.a},71:function(t,e,n){},8:function(e,n){e.exports=t}})})); //# sourceMappingURL=pickercolumn.js.map