UNPKG

@minix-iot/ui

Version:

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

7 lines 10.8 kB
/*! * @minix-iot/ui v0.2.4 - sticky.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("sticky",["vue"],e):"object"==typeof exports?exports.sticky=e(require("vue")):t.sticky=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=133)}({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},133:function(t,e,n){"use strict";n.r(e);var r=n(5),o=n(1),i=n.n(o),u=n(3),s=n(18),a=u.a.Create("sticky"),l={name:a.name,props:{position:{type:String,default:"top"},zIndex:{type:Number|String,default:1060},offset:{type:Number,default:0},container:{type:Node}},data:function(){return{fixed:!1,width:0,height:0,transform:0,scrollParent:null}},computed:{rootStyle:function(){if(this.fixed)return{width:"".concat(this.width,"px"),height:"".concat(this.height,"px")}},cls:function(){return a.derive({fixed:this.fixed})},style:function(){if(this.fixed){var t=i()({zIndex:this.zIndex,width:"".concat(this.width,"px"),height:"".concat(this.height,"px")},this.position,"".concat(this.offset,"px"));return this.transform&&(t.transform="translate3d(0,".concat(this.transform,"px,0)")),t}}},mounted:function(){this.scrollParent=s.a.GetScrollParent(this.$el),s.a.AddEventListener(this.scrollParent,"scroll",this.onScroll)},beforeDestory:function(){s.a.RemoveEventListener(this.scrollParent,"scroll",this.onScroll)},methods:{onScroll:function(t){var e=this.$props,n=e.position,r=e.container,o=s.a.GetBoundingClientRect(this.$el);if(this.width=o.width,this.height=o.height,"top"===n)if(r){var i=s.a.GetBoundingClientRect(r);this.fixed=this.offset>o.top&&i.bottom>0;var u=i.bottom-this.offset-this.height;this.transform=u<0?u:0}else this.fixed=this.offset>o.top;else{var a=document.documentElement.clientHeight;if(r){var l=s.a.GetBoundingClientRect(r);this.fixed=a-this.offset<o.bottom&&a>l.top;var c=a-l.top-this.height-this.offset;this.transform=c<0?-c:0}else this.fixed=a-this.offset<o.bottom}this.$emit("scroll",{scrollTop:s.a.GetScrollTop(this.scrollParent),isFixed:this.fixed})}},render:function(){var t=arguments[0];return t("div",{style:this.rootStyle},[t("div",{class:this.cls,style:this.style},[this.$slots.default])])}};n(97);r.a.WithInstall(l);e.default=l},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},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},3: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),l=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()(l,"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),s=n(0),a=n.n(s),l=n(2),c=n.n(l),f=n(8),d=n.n(f);function p(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 h(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 h(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 h(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(){a()(this,t)}return c()(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=p(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},97:function(t,e,n){}})})); //# sourceMappingURL=sticky.js.map