utils.d.ts.map 2.0 KB

1
  1. {"version":3,"sources":["../src/sticky/utils.ts"],"names":[],"mappings":";AAKA,aAAK,iBAAiB,GAAG,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC;AAClE,aAAK,QAAQ,GAAG,CACd,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,eAAe,EACjD,KAAK,CAAC,EAAE,iBAAiB,KACtB,IAAI,CAAC;AAeV,eAAO,MAAM,eAAe,aAAc,QAAQ,WAqB9C,CAAC;AAEL,eAAO,MAAM,OAAO,YAAsB,GAAG,YAAY,MAAM,gEAQ9D,CAAC","file":"utils.d.ts","sourcesContent":["const getCurrentPage = function <T>() {\n const pages = getCurrentPages();\n return pages[pages.length - 1] as T & WechatMiniprogram.Page.TrivialInstance;\n};\n\ntype IPageScrollOption = WechatMiniprogram.Page.IPageScrollOption;\ntype Scroller = (\n this: WechatMiniprogram.Component.TrivialInstance,\n event?: IPageScrollOption,\n) => void;\n\nconst onPageScroll = function (event?: IPageScrollOption) {\n const { pageScroller = [] } = getCurrentPage<{\n pageScroller: Scroller[];\n }>();\n\n pageScroller.forEach((scroller: Scroller) => {\n if (typeof scroller === 'function') {\n // @ts-ignore\n scroller(event);\n }\n });\n};\n\nexport const pageScrollMixin = (scroller: Scroller) =>\n Behavior({\n attached() {\n const page = getCurrentPage<{ pageScroller: Scroller[] }>();\n\n if (Array.isArray(page.pageScroller)) {\n page.pageScroller.push(scroller.bind(this));\n } else {\n page.pageScroller =\n typeof page.onPageScroll === 'function'\n ? [page.onPageScroll.bind(page), scroller.bind(this)]\n : [scroller.bind(this)];\n }\n\n page.onPageScroll = onPageScroll;\n },\n\n detached() {\n const page = getCurrentPage<{ pageScroller: Scroller[] }>();\n page.pageScroller = page.pageScroller?.filter((item) => item !== scroller) || [];\n },\n });\n\nexport const getRect = function (context: any, selector: string) {\n return new Promise<WechatMiniprogram.BoundingClientRectCallbackResult>((resolve) => {\n wx.createSelectorQuery()\n .in(context)\n .select(selector)\n .boundingClientRect()\n .exec((rect = []) => resolve(rect[0]));\n });\n};\n"]}