This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
function inserted(el, binding) {
const modifiers = binding.modifiers || {};
const value = binding.value;
const {
handler,
options
} = typeof value === 'object' ? value : {
handler: value,
options: {}
};
const observer = new IntersectionObserver((entries = [], observer) => {
/* istanbul ignore if */
if (!el._observe) return; // Just in case, should never fire
// If is not quiet or has already been
// initted, invoke the user callback
if (handler && (!modifiers.quiet || el._observe.init)) {
const isIntersecting = Boolean(entries.find(entry => entry.isIntersecting));
handler(entries, observer, isIntersecting);
} // If has already been initted and
// has the once modifier, unbind
if (el._observe.init && modifiers.once) unbind(el); // Otherwise, mark the observer as initted
else el._observe.init = true;
}, options);
el._observe = {
init: false,
observer
};
observer.observe(el);
}
function unbind(el) {
/* istanbul ignore if */
if (!el._observe) return;
el._observe.observer.unobserve(el);
delete el._observe;
}
export const Intersect = {
inserted,
unbind
};
export default Intersect;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/directives/intersect/index.ts"],"names":[],"mappings":"AAgBA,SAAS,QAAT,CAAmB,EAAnB,EAAoC,OAApC,EAAkE;AAChE,QAAM,SAAS,GAAG,OAAO,CAAC,SAAR,IAAqB,EAAvC;AACA,QAAM,KAAK,GAAG,OAAO,CAAC,KAAtB;AACA,QAAM;AAAE,IAAA,OAAF;AAAW,IAAA;AAAX,MAAuB,OAAO,KAAP,KAAiB,QAAjB,GACzB,KADyB,GAEzB;AAAE,IAAA,OAAO,EAAE,KAAX;AAAkB,IAAA,OAAO,EAAE;AAA3B,GAFJ;AAGA,QAAM,QAAQ,GAAG,IAAI,oBAAJ,CAAyB,CACxC,OAAA,GAAuC,EADC,EAExC,QAFwC,KAGtC;AACF;AACA,QAAI,CAAC,EAAE,CAAC,QAAR,EAAkB,OAFhB,CAEuB;AAEzB;AACA;;AACA,QACE,OAAO,KACL,CAAC,SAAS,CAAC,KAAX,IACA,EAAE,CAAC,QAAH,CAAY,IAFP,CADT,EAKE;AACA,YAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,IAAR,CAAa,KAAK,IAAI,KAAK,CAAC,cAA5B,CAAD,CAA9B;AAEA,MAAA,OAAO,CAAC,OAAD,EAAU,QAAV,EAAoB,cAApB,CAAP;AACD,KAfC,CAiBF;AACA;;;AACA,QAAI,EAAE,CAAC,QAAH,CAAY,IAAZ,IAAoB,SAAS,CAAC,IAAlC,EAAwC,MAAM,CAAC,EAAD,CAAN,CAAxC,CACA;AADA,SAEM,EAAE,CAAC,QAAH,CAAY,IAAZ,GAAmB,IAApB;AACN,GAzBgB,EAyBd,OAzBc,CAAjB;AA2BA,EAAA,EAAE,CAAC,QAAH,GAAc;AAAE,IAAA,IAAI,EAAE,KAAR;AAAe,IAAA;AAAf,GAAd;AAEA,EAAA,QAAQ,CAAC,OAAT,CAAiB,EAAjB;AACD;;AAED,SAAS,MAAT,CAAiB,EAAjB,EAAgC;AAC9B;AACA,MAAI,CAAC,EAAE,CAAC,QAAR,EAAkB;;AAElB,EAAA,EAAE,CAAC,QAAH,CAAY,QAAZ,CAAqB,SAArB,CAA+B,EAA/B;;AACA,SAAO,EAAE,CAAC,QAAV;AACD;;AAED,OAAO,MAAM,SAAS,GAAG;AACvB,EAAA,QADuB;AAEvB,EAAA;AAFuB,CAAlB;AAKP,eAAe,SAAf","sourcesContent":["import { VNodeDirective } from 'vue/types/vnode'\n\ntype ObserveHandler = (\n entries: IntersectionObserverEntry[],\n observer: IntersectionObserver,\n isIntersecting: boolean,\n) => void\n\ninterface ObserveVNodeDirective extends Omit<VNodeDirective, 'modifiers'> {\n value?: ObserveHandler | { handler: ObserveHandler, options?: IntersectionObserverInit }\n modifiers?: {\n once?: boolean\n quiet?: boolean\n }\n}\n\nfunction inserted (el: HTMLElement, binding: ObserveVNodeDirective) {\n const modifiers = binding.modifiers || {}\n const value = binding.value\n const { handler, options } = typeof value === 'object'\n ? value\n : { handler: value, options: {} }\n const observer = new IntersectionObserver((\n entries: IntersectionObserverEntry[] = [],\n observer: IntersectionObserver\n ) => {\n /* istanbul ignore if */\n if (!el._observe) return // Just in case, should never fire\n\n // If is not quiet or has already been\n // initted, invoke the user callback\n if (\n handler && (\n !modifiers.quiet ||\n el._observe.init\n )\n ) {\n const isIntersecting = Boolean(entries.find(entry => entry.isIntersecting))\n\n handler(entries, observer, isIntersecting)\n }\n\n // If has already been initted and\n // has the once modifier, unbind\n if (el._observe.init && modifiers.once) unbind(el)\n // Otherwise, mark the observer as initted\n else (el._observe.init = true)\n }, options)\n\n el._observe = { init: false, observer }\n\n observer.observe(el)\n}\n\nfunction unbind (el: HTMLElement) {\n /* istanbul ignore if */\n if (!el._observe) return\n\n el._observe.observer.unobserve(el)\n delete el._observe\n}\n\nexport const Intersect = {\n inserted,\n unbind,\n}\n\nexport default Intersect\n"],"sourceRoot":"","file":"index.js"}