wux-weapp
Version:
一套组件化、可复用、易扩展的微信小程序 UI 组件库
1 lines • 3.52 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.useComputedStyle=exports.useScrollOffset=exports.useRectAll=exports.useRect=exports.useRefAll=exports.useRef=exports.useQuery=void 0;var _global=require("../internals/global"),_pxToNumber=require("../shared/pxToNumber");function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(e,r){var t=[],o=!0,n=!1,u=void 0;try{for(var i,l=e[Symbol.iterator]();!(o=(i=l.next()).done)&&(t.push(i.value),!r||t.length!==r);o=!0);}catch(e){n=!0,u=e}finally{try{o||null==l.return||l.return()}finally{if(n)throw u}}return t}function _arrayWithHoles(e){if(Array.isArray(e))return e}var useQuery=function(e){return e?_global.miniprogramThis.createSelectorQuery().in(e):_global.miniprogramThis.createSelectorQuery()};exports.useQuery=useQuery;var makeFields=function(){return{id:!0,dataset:!0,mark:!0,rect:!0,scrollOffset:!0,computedStyle:["width","height","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth"],node:!0}},makeNodeRef=function(e){var r=(0,_pxToNumber.pxToNumber)(e.borderRightWidth||0),t=(0,_pxToNumber.pxToNumber)(e.borderLeftWidth||0),o=(0,_pxToNumber.pxToNumber)(e.borderTopWidth||0),n=(0,_pxToNumber.pxToNumber)(e.borderBottomWidth||0),u=(0,_pxToNumber.pxToNumber)(e.width),i=(0,_pxToNumber.pxToNumber)(e.height),l=u+r+t,s=i+o+n;return{id:e.id,dataset:e.dataset,mark:e.mark,top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:l,height:s,x:e.left,y:e.top,offsetWidth:l,offsetHeight:s,clientLeft:t,clientTop:o,clientWidth:u,clientHeight:i,scrollHeight:e.scrollHeight,scrollLeft:e.scrollLeft,scrollTop:e.scrollTop,scrollWidth:e.scrollWidth,node:e.node}},useRef=function(e,n){return new Promise(function(r){var t=useQuery(n),o=Array.isArray(e);(o?e:[e]).forEach(function(e){t.select(e).fields(makeFields())}),t.exec(function(e){r(o?e.map(function(e){return makeNodeRef(e)}):makeNodeRef(e[0]))})})};exports.useRef=useRef;var useRefAll=function(e,n){return new Promise(function(r){var t=useQuery(n),o=Array.isArray(e);(o?e:[e]).forEach(function(e){t.selectAll(e).fields(makeFields())}),t.exec(function(e){r(o?e.map(function(e){return e.map(function(e){return makeNodeRef(e)})}):e[0].map(function(e){return makeNodeRef(e)}))})})};exports.useRefAll=useRefAll;var useRect=function(e,n){return new Promise(function(r){var t=useQuery(n),o=Array.isArray(e);(o?e:[e]).forEach(function(e){t.select(e).boundingClientRect()}),t.exec(function(e){r(o?e:e[0])})})};exports.useRect=useRect;var useRectAll=function(e,n){return new Promise(function(r){var t=useQuery(n),o=Array.isArray(e);(o?e:[e]).forEach(function(e){t.selectAll(e).boundingClientRect()}),t.exec(function(e){r(o?e:e[0])})})};exports.useRectAll=useRectAll;var useScrollOffset=function(r){return new Promise(function(t){var e=useQuery(r);e.selectViewport().scrollOffset(),e.exec(function(e){var r=_slicedToArray(e,1)[0];t(r)})})};exports.useScrollOffset=useScrollOffset;var useComputedStyle=function(r,e,t){var o=2==(arguments.length<=1?0:arguments.length-1)?arguments.length<=1?void 0:e:["width","height"],n=2==(arguments.length<=1?0:arguments.length-1)?arguments.length<=2?void 0:t:arguments.length<=1?void 0:e;return new Promise(function(t){var e=useQuery(n);e.select(r).fields({computedStyle:o}),e.exec(function(e){var r=_slicedToArray(e,1)[0];t(r)})})};exports.useComputedStyle=useComputedStyle;