@minix-iot/ui
Version:
基于Vue的移动端轻量级UI组件库
7 lines • 19 kB
JavaScript
/*!
* @minix-iot/ui v0.2.4 - swiperitem.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("swiperitem",["vue"],e):"object"==typeof exports?exports.swiperitem=e(require("vue")):t.swiperitem=e(t.Vue)}("undefined"!=typeof self?self:this,(function(t){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},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 i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(i,o,function(e){return t[e]}.bind(null,o));return i},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=127)}({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 i=n(7);t.exports=function(t,e){if(t){if("string"==typeof t)return i(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)?i(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0},12:function(t,e,n){var i=n(7);t.exports=function(t){if(Array.isArray(t))return i(t)},t.exports.default=t.exports,t.exports.__esModule=!0},127:function(t,e,n){"use strict";n.r(e);var i=n(5),o=n(3),r=n(35),s=n(38),u=n(24),a=o.a.Create("swiper-item"),c={name:a.name,mixins:[Object(s.a)(r.b.name)],data:function(){return{offset:0,startTime:-1,touch:u.a.Create()}},props:{duration:{type:Number,default:200}},computed:{vertical:function(){return this.$parent.vertical},cls:function(){return a.derive()},style:function(){var t={},e=this.parent.vertical;return this.parent.size&&(t[e?"height":"width"]="".concat(this.parent.size,"px")),this.offset&&(t.transform="translate".concat(e?"Y":"X","(").concat(this.offset,"px)")),t},delta:function(){return this.$parent.delta}},methods:{setOffset:function(t){this.offset=t},onTouchStart:function(t){this.touch.start(t),this.startTime=t.timeStamp},onTouchMove:function(t){this.touch.move(t),t.preventDefault()},onTouchEnd:function(t){t.timeStamp-this.startTime<this.duration&&Math.abs(this.delta)<u.a.MIN_DISTANCE&&this.$emit("click",t)}},render:function(){var t=arguments[0];return t("div",{class:this.cls,style:this.style,on:{touchmove:this.onTouchMove,touchstart:this.onTouchStart,touchend:this.onTouchEnd}},[this.$slots.default])}};n(90);i.a.WithInstall(c);e.default=c},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 u}));var i=n(0),o=n.n(i),r=n(1),s=n.n(r),u=function t(){o()(this,t)};s()(u,"NONE",""),s()(u,"HOR","horizental"),s()(u,"VER","vertical")},18:function(t,e,n){"use strict";n.d(e,"a",(function(){return u}));var i=n(0),o=n.n(i),r=n(2),s=n.n(r),u=function(){function t(){o()(this,t)}return s()(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"),i=null===t.offsetParent&&"fixed"!==e.getPropertyValue("position");return n||i}},{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 i=window.getComputedStyle(n).getPropertyValue("overflow-y");if(/scroll|auto/i.test(i)&&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,i){t&&t instanceof EventTarget&&t.addEventListener(e,n,i)}},{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 i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}t.exports=function(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t},t.exports.default=t.exports,t.exports.__esModule=!0},22:function(t,e,n){"use strict";n.d(e,"a",(function(){return u}));var i=n(0),o=n.n(i),r=n(2),s=n.n(r),u=function(){function t(){o()(this,t)}return s()(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 i=n(0),o=n.n(i),r=n(2),s=n.n(r),u=n(1),a=n.n(u),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 s()(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()(l,"MIN_DISTANCE",10)},27:function(t,e,n){"use strict";n.d(e,"a",(function(){return r}));var i=n(1),o=n.n(i);function r(t){return{provide:function(){return o()({},t,this)},data:function(){return{children:[]}}}}},3:function(t,e,n){"use strict";n.d(e,"a",(function(){return c}));var i=n(0),o=n.n(i),r=n(2),s=n.n(r),u=n(1),a=n.n(u),c=function(){function t(e){o()(this,t),this._name=e}return s()(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,i){return e+n.mod(t,i)}),""):Object.keys(e).reduce((function(i,o){return i+(e[o]?n.mod(t,o):"")}),""):""}}],[{key:"Create",value:function(e){return new t(e)}}]),t}();a()(c,"ROOT","mx")},35:function(t,e,n){"use strict";n.d(e,"b",(function(){return h}));var i=n(3),o=n(27),r=n(24),s=n(16),u=n(22),a=n(18);function c(t){("undefined"!=typeof window?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}:function(t){setTimeout(t,1e3/60)})(t)}function l(t){c((function(){return c(t)}))}var h=i.a.Create("swiper");e.a={name:h.name,mixins:[Object(o.a)(h.name)],props:{autoplay:{type:String|Number},duration:{type:String|Number,default:500},defaultActive:{type:String|Number,default:0},loop:{type:Boolean,default:!0},showIndicator:{type:Boolean,default:!0},indicatorColor:{type:String},vertical:{type:Boolean,default:!1},swipeable:{type:Boolean,default:!0}},data:function(){return{rect:null,width:0,height:0,offset:0,active:0,swiping:!1,touch:r.a.Create(),touchStartTime:-1,autoplayTimer:-1}},computed:{cls:function(){return h.derive()},trackCls:function(){return h.derive("track",{vertical:this.vertical})},trackStyle:function(){var t={transitionDuration:"".concat(this.swiping?0:this.duration,"ms"),transform:"translate".concat(this.vertical?"Y":"X","(").concat(this.offset,"px)")};return this.size&&(t[this.vertical?"height":"width"]=this.trackSize),t},indicatorsCls:function(){return h.derive("indicators",{vertical:this.vertical})},activeIndicator:function(){return(this.active+this.count)%this.count},count:function(){return this.children.length},size:function(){return this[this.vertical?"height":"width"]},delta:function(){return this.vertical?this.touch.deltaY:this.touch.deltaX},minOffset:function(){return this.rect?(this.vertical?this.rect.height:this.rect.width)-this.size*this.count:0},maxCount:function(){return Math.ceil(Math.abs(this.minOffset)/this.size)},trackSize:function(){return this.size*this.count},isCorrectDirection:function(){return this.touch.direction===(this.vertical?s.a.VER:s.a.HOR)}},watch:{defaultActive:function(t){this.init(t)},count:function(){this.init(this.active)},autoPlay:function(){this.startAutoplay()}},onMounted:function(){this.init()},onActivated:function(){this.init(this.active)},onDeactivated:function(){this.stopAutoplay()},onBeforeUnmount:function(){this.stopAutoplay()},methods:{onTouchStart:function(t){this.swipeable&&(this.touch.start(t),this.touchStartTime=Date.now(),this.stopAutoplay(),this.correctPosition())},onTouchMove:function(t){this.swipeable&&this.swiping&&(this.touch.move(t),this.isCorrectDirection&&(a.a.PreventDefault(t,!0),this.move(0,this.delta)))},onTouchEnd:function(t){if(this.swipeable&&this.swiping){var e=Date.now()-this.touchStartTime,n=this.delta/e;if((Math.abs(n)>.25||Math.abs(this.delta)>this.size/2)&&this.isCorrectDirection){var i=this.vertical?this.touch.offsetY:this.touch.offsetX,o=0;o=this.loop?i>0?this.delta>0?-1:1:0:-Math[this.delta>0?"ceil":"floor"](this.delta/this.size),this.move(o,0,!0)}else this.delta&&this.move(0);this.swiping=!1,this.startAutoplay()}},stopAutoplay:function(){clearTimeout(this.autoplayTimer)},startAutoplay:function(){var t=this;this.stopAutoplay(),this.autoplay>0&&this.count>1&&(this.autoplayTimer=setTimeout((function(){t.next(),t.startAutoplay()}),+this.autoplay))},prev:function(){var t=this;this.correctPosition(),this.touch.reset(),l((function(){t.swiping=!1,t.move(-1,0,!0)}))},next:function(){var t=this;this.correctPosition(),this.touch.reset(),l((function(){t.swiping=!1,t.move(1,0,!0)}))},swipeTo:function(t,e){var n=this;this.correctPosition(),this.touch.reset(),l((function(){var i;i=n.loop&&t===n.count?0===n.active?0:t:t%n.count,e.immediate?l((function(){n.swiping=!1})):n.swiping=!1,n.move(i-n.active,0,!0)}))},move:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!(this.count<=1)){var i=this.$data.active,o=this.getTargetActive(t),r=this.getTargetOffset(o,e);this.loop&&(this.children[0]&&r!==this.minOffset&&this.children[0].setOffset(r<this.minOffset?this.trackSize:0),this.children[this.count-1]&&0!==r&&this.children[this.count-1].setOffset(r>0?-this.trackSize:0)),this.active=o,this.offset=r,n&&i!==o&&this.$emit("change",this.activeIndicator)}},correctPosition:function(){this.swiping=!0,this.active<=-1?this.move(this.count):this.active>=this.count&&this.move(-this.count)},getTargetActive:function(t){var e=this.$data.active;return t?this.loop?u.a.Clamp(e+t,-1,this.count):u.a.Clamp(e+t,0,this.maxCount):e},getTargetOffset:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=t*this.size;this.loop||(n=Math.min(n,this.minOffset));var i=e-n;return this.loop||(i=u.a.Clamp(i,this.minOffset,0)),i},isHide:function(t){if(!t)return!1;var e=window.getComputedStyle(t),n="none"===e.display,i=null===t.offsetParent&&"fixed"!==e.position;return n||i},init:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.defaultActive;if(this.$el){if(!this.isHide(this.$el)){var e={width:this.$el.offsetWidth,height:this.$el.offsetHeight};this.rect=e,this.width=e.width,this.height=e.height}this.count&&(t=Math.min(this.count-1,t)),this.active=t,this.swiping=!0,this.offset=this.getTargetOffset(t),this.children.forEach((function(t){return t.setOffset(0)})),this.startAutoplay()}},resize:function(){this.init(this.active)}},render:function(){var t=this,e=arguments[0],n=function(n,i){var o=i===t.activeIndicator,r={};return o&&(r.backgroundColor=t.indicatorColor),e("i",{style:r,class:h.derive("indicator",{active:o})})},i=function(){return t.$scopedSlots.indicator?t.$scopedSlots.indicator({active:t.activeIndicator}):t.showIndicator&&t.count>1?e("div",{class:t.indicatorsCls},[Array(t.count).fill(null).map(n)]):void 0};return e("div",{class:this.cls},[e("div",{class:this.trackCls,style:this.trackStyle,on:{touchstart:this.onTouchStart,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchEnd}},[this.$slots.default]),i()])}}},38:function(t,e,n){"use strict";n.d(e,"a",(function(){return a}));var i=n(4),o=n.n(i),r=n(1),s=n.n(r),u=n(5);function a(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.indexKey||"index";return{inject:s()({},t,{default:null}),computed:s()({parent:function(){return this.disableBindingRelation?null:this[t]}},n,(function(){return this.bindRelation(),this.parent?this.parent.children.indexOf(this):null})),watch:{disableBindingRelation:function(t){t||this.bindRelation()}},mounted:function(){this.bindRelation()},beforeDestroy:function(){var t=this;this.parent&&(this.parent.children=this.parent.children.filter((function(e){return e!==t})))},methods:{bindRelation:function(){this.parent&&-1===this.parent.children.indexOf(this)&&(this.parent.children=u.a.SortChildren([].concat(o()(this.parent.children),[this]),this.parent))}}}}},4:function(t,e,n){var i=n(12),o=n(13),r=n(10),s=n(14);t.exports=function(t){return i(t)||o(t)||r(t)||s()},t.exports.default=t.exports,t.exports.__esModule=!0},5:function(t,e,n){"use strict";n.d(e,"a",(function(){return v}));var i=n(4),o=n.n(i),r=n(6),s=n.n(r),u=n(0),a=n.n(u),c=n(2),l=n.n(c),h=n(8),f=n.n(h);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 i=0,o=function(){};return{s:o,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},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 r,s=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){u=!0,r=t},f:function(){try{s||null==n.return||n.return()}finally{if(u)throw r}}}}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}var v=function(){function t(){a()(this,t)}return l()(t,null,[{key:"WithInstall",value:function(t,e){if("object"!==s()(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 i=this.FlattenVNode(n.children);return t.sort((function(t,e){return i.indexOf(t.$vnode)-i.indexOf(e.$vnode)})),t}}},{key:"FlattenVNode",value:function(t){return this.TraverseVNode(t)}},{key:"TraverseVNode",value:function(t){var e,n=[],i=d(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n.push(r),r.componentInstance&&n.push.apply(n,o()(this.TraverseVNode(r.componentInstance.$children.map((function(t){return t.$vnode}))))),r.children&&n.push.apply(n,o()(this.TraverseVNode(r.children)))}}catch(t){i.e(t)}finally{i.f()}return n}},{key:"InvokeComponent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=[],i=function(){var e=t((function(){i.$destroy(),document.body.removeChild(i.$el),n=n.filter((function(t){return t!==i}))})),i=new f.a(e),o=document.createElement("div");return document.body.appendChild(o),i.$mount(o),i},o=function(){return n.length&&!e||n.push(i()),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,i=new Array(e);n<e;n++)i[n]=t[n];return i},t.exports.default=t.exports,t.exports.__esModule=!0},8:function(e,n){e.exports=t},90:function(t,e,n){}})}));
//# sourceMappingURL=swiperitem.js.map