wot-design-uni/demo/assets/wd-sticky-box.BwR4vTrH.js

2 lines
4.7 KiB
JavaScript

var t=Object.defineProperty,e=Object.defineProperties,o=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,n=(e,o,s)=>o in e?t(e,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[o]=s,l=(t,e)=>{for(var o in e||(e={}))i.call(e,o)&&n(t,o,e[o]);if(s)for(var o of s(e))a.call(e,o)&&n(t,o,e[o]);return t},r=(t,s)=>e(t,o(s));import{d as u,r as c,Y as d,an as h,J as p,c as b,H as f,G as v,b as y,g as m,w,h as g,i as x,E as $,q as k,D as _,N as C,L as S,aG as j,a7 as P}from"./index-ChV97F5w.js";import{w as O}from"./wd-resize.CYHa5EIT.js";import{m as z,b as I,_ as T}from"./base64.D3gEw_Hf.js";import{e as L}from"./page-wraper.D9WpzC1k.js";import{u as R}from"./useChildren.C_02WC2s.js";const N=r(l({},I),{zIndex:z(1),offsetTop:z(0)}),G=Symbol("wd-sticky-box"),E=T(u(r(l({},{name:"wd-sticky",options:{addGlobalClass:!0,virtualHost:!0,styleIsolation:"shared"}}),{props:N,setup(t,{expose:e}){const o=t,s=c(`wd-sticky${d()}`),i=c([]),a=h({position:"absolute",boxLeaved:!1,top:0,height:0,width:0,state:""}),{parent:n}=L(G),{proxy:l}=p(),r=b((()=>{const t={"z-index":o.zIndex,height:f(a.height),width:f(a.width)};return a.boxLeaved||(t.position="relative"),`${v(t)}${o.customStyle}`})),u=b((()=>{const t={"z-index":o.zIndex,height:f(a.height),width:f(a.width)};return a.boxLeaved||(t.position="relative"),`${v(t)}`})),P=b((()=>{const t={position:a.position,top:f(a.top)};return v(t)})),z=b((()=>{let t=0;return t=44,44+o.offsetTop}));function I(t){return e=this,o=null,r=function*(){a.width=t.width,a.height=t.height,yield C(),function(){if(0===a.height&&0===a.width)return;const t=z.value+a.height;(function(){for(;0!==i.value.length;)i.value.pop().disconnect()})(),function(){const t=j(l,{thresholds:[0,.5]});return i.value.push(t),t}().relativeToViewport({top:-t}).observe(`#${s.value}`,(t=>{T(t)})),S(`#${s.value}`,!1,l).then((e=>{e.bottom=Number(e.bottom)+44,Number(e.bottom)<=t&&T({boundingClientRect:e})}))}(),n&&n.observerForChild&&n.observerForChild(l)},new Promise(((t,s)=>{var i=t=>{try{n(r.next(t))}catch(e){s(e)}},a=t=>{try{n(r.throw(t))}catch(e){s(e)}},n=e=>e.done?t(e.value):Promise.resolve(e.value).then(i,a);n((r=r.apply(e,o)).next())}));var e,o,r}function T({boundingClientRect:t}){if(n&&n.boxStyle&&a.height>=n.boxStyle.height)return a.position="absolute",void(a.top=0);let e=t.top<=z.value;e=t.top<z.value,e?(a.state="sticky",a.boxLeaved=!1,a.position="fixed",a.top=z.value):(a.state="normal",a.boxLeaved=!1,a.position="absolute",a.top=0)}return e({setPosition:function(t,e,o){a.boxLeaved=t,a.position=e,a.top=o},stickyState:a,offsetTop:o.offsetTop}),(t,e)=>{const o=x;return m(),y(o,{style:$(`${r.value};display: inline-block;`)},{default:w((()=>[g(o,{class:k(`wd-sticky ${t.customClass}`),style:$(u.value),id:s.value},{default:w((()=>[g(o,{class:"wd-sticky__container",style:$(P.value)},{default:w((()=>[g(O,{onResize:I,"custom-style":"display: inline-block;"},{default:w((()=>[_(t.$slots,"default",{},void 0,!0)])),_:3})])),_:3},8,["style"])])),_:3},8,["class","style","id"])])),_:3},8,["style"])}}})),[["__scopeId","data-v-d63e4cbb"]]),F=T(u(r(l({},{name:"wd-sticky-box",options:{addGlobalClass:!0,styleIsolation:"shared"}}),{props:I,setup(t){const e=t,o=c(`wd-sticky-box${d()}`),s=c(new Map),i=h({height:0,width:0}),{proxy:a}=p(),{children:n,linkChildren:l}=R(G);function r(t){i.width=t.width,i.height=t.height;const e=s.value;s.value=new Map;for(const[o]of e){u(n.find((t=>t.$.uid===o)))}e.forEach((t=>{t.disconnect()})),e.clear()}function u(t){!function(t){const e=s.value.get(t.$.uid);e&&(e.disconnect(),s.value.delete(t.$.uid))}(t);const e=function(t){const e=j(a,{thresholds:[0,.5]});return s.value.set(t.$.uid,e),e}(t),n=t.$.exposed;let l=n.stickyState.height+n.offsetTop;l+=44,i.height<=n.stickyState.height&&n.setPosition(!1,"absolute",0),e.relativeToViewport({top:-l}).observe(`#${o.value}`,(t=>{b(n,t)})),S(`#${o.value}`,!1,a).then((t=>{t.bottom=Number(t.bottom)+44,Number(t.bottom)<=l&&b(n,{boundingClientRect:t})})).catch((t=>{console.log(t)}))}function b(t,{boundingClientRect:e}){let o=t.offsetTop;o+=44;const s=t.stickyState.height+o;let i=e.bottom<=s;if(i=e.bottom<s,i)t.setPosition(!0,"absolute",e.height-t.stickyState.height);else if(e.top<=s&&!i){if("normal"===t.stickyState.state)return;t.setPosition(!1,"fixed",o)}}return l({boxStyle:i,observerForChild:u}),P((()=>{s.value=new Map})),(t,s)=>{const i=x;return m(),y(i,{style:{position:"relative"}},{default:w((()=>[g(i,{class:k(`wd-sticky-box ${e.customClass}`),style:$(t.customStyle),id:o.value},{default:w((()=>[g(O,{onResize:r},{default:w((()=>[_(t.$slots,"default",{},void 0,!0)])),_:3})])),_:3},8,["class","style","id"])])),_:3})}}})),[["__scopeId","data-v-0a2cb98b"]]);export{F as a,E as w};