UNPKG

@minix-iot/ui

Version:

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

7 lines 13.1 kB
/*! * @minix-iot/ui v0.2.4 - pullrefresh.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("pullrefresh",["vue"],e):"object"==typeof exports?exports.pullrefresh=e(require("vue")):t.pullrefresh=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=111)}({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},111:function(t,e,n){"use strict";n.r(e);var r=n(5),o=n(3),i=n(24),u=n(18),s=o.a.Create("pull-refresh"),a={name:s.name,props:{distanceToRefresh:{type:Number,default:50},loading:{type:Boolean,default:!1},finished:{type:Boolean,default:!1}},data:function(){return{status:"normal",isReachTop:!1,touch:i.a.Create()}},computed:{cls:function(){return s.derive()},containerCls:function(){return s.derive("container")},infoCls:function(){return s.derive("info")},viewerCls:function(){return s.derive("viewer")},containerStyle:function(){var t=this.ease(this.touch.deltaY);return this.isLoading&&(t=this.distanceToRefresh),"transform:translateY(".concat(t,"px)")},infoStyle:function(){return"height:".concat(this.distanceToRefresh,"px")},isPulling:function(){return"pulling"===this.status},isLoosing:function(){return"loosing"===this.status},isLoading:function(){return this.loading},isFinished:function(){return this.finished},isTouchable:function(){return!this.isLoading}},methods:{onTouchStart:function(t){this.isTouchable&&this.isReachEdge()&&this.touch.start(t)},onTouchMove:function(t){this.isTouchable&&this.isReachEdge()&&(0===this.touch.startY?this.touch.start(t):(this.touch.move(t),this.touch.deltaY>0&&(u.a.PreventDefault(t),this.touch.deltaY<this.distanceToRefresh?this.status="pulling":this.status="loosing")))},onTouchEnd:function(t){this.touch.deltaY>this.distanceToRefresh&&this.$emit("refresh",t),this.touch.reset(),this.status="normal"},isReachEdge:function(){return 0===this.$refs.viewer.scrollTop},ease:function(t){var e=t<0?0:t;return e>this.distanceToRefresh&&(e=e<2*this.distanceToRefresh?this.distanceToRefresh+(e-this.distanceToRefresh)/2:1.5*this.distanceToRefresh+(e-2*this.distanceToRefresh)/4),Math.round(e)}},render:function(){var t=this,e=arguments[0],n=function(){return t.$slots.pull||e("div",["下拉刷新"])},r=function(){return t.$slots.loading||e("mx-loading",{attrs:{type:"spinner",size:18}})},o=function(){return t.$slots.loose||e("div",["释放刷新"])},i=function(){return t.$slots.finished||e("div",["- 没有更多内容了 -"])},u=function(){return e("div",{class:t.infoCls,style:t.infoStyle},[!t.isFinished&&t.isPulling&&n(),!t.isFinished&&t.isLoosing&&o(),!t.isFinished&&t.isLoading&&r(),t.isFinished&&i()])},s=function(){return e("div",{ref:"viewer",class:t.viewerCls},[t.$slots.default])};return e("div",{class:this.cls},[e("div",{class:this.containerCls,style:this.containerStyle,on:{touchstart:this.onTouchStart,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchEnd}},[u(),s()])])}};n(53);r.a.WithInstall(a);e.default=a},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),o=n.n(r),i=n(1),u=n.n(i),s=function t(){o()(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),o=n.n(r),i=n(2),u=n.n(i),s=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},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),s=n(1),a=n.n(s),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}();a()(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),s=n(1),a=n.n(s),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}();a()(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 v}));var r=n(4),o=n.n(r),i=n(6),u=n.n(i),s=n(0),a=n.n(s),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,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,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(s)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 v=function(){function t(){a()(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}()},53:function(t,e,n){},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}})})); //# sourceMappingURL=pullrefresh.js.map