UNPKG

@jood/appearer

Version:
2 lines 4.5 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("intersection-observer"),require("rxjs")):"function"==typeof define&&define.amd?define("@jood/appearer",["exports","intersection-observer","rxjs"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).jood=t.jood||{},t.jood.appearer={}),null,t.rxjs)}(this,(function(t,e,r){"use strict";var o,i=function(){function t(){}return t.prototype.init=function(t){void 0===t&&(t={}),this.observer||(this.actorMap=new Map,this.observer=new IntersectionObserver(this.onObserveEntries.bind(this),t))},t.prototype.observe=function(t){var e=t.element;this.actorMap&&!this.actorMap.has(e)&&(t.bind(this),this.actorMap.set(e,t),this.intersectionObserver.observe(e))},t.prototype.unobserve=function(t){var e=t.element;this.actorMap&&this.actorMap.has(e)&&(this.actorMap.delete(e),this.intersectionObserver.unobserve(e))},Object.defineProperty(t.prototype,"actorSize",{get:function(){return this.actorMap?this.actorMap.size:0},enumerable:!1,configurable:!0}),t.prototype.getActors=function(){return Array.from(this.actorMap?this.actorMap.values():[])},Object.defineProperty(t.prototype,"intersectionObserver",{get:function(){if(!this.observer)throw new Error("uninitialize");return this.observer},enumerable:!1,configurable:!0}),t.prototype.onObserveEntries=function(t){var e=this;t.forEach((function(t){if(e.actorMap){var r=t.isIntersecting,o=t.target,i=e.actorMap.get(o);i&&(r?i.appear(t):i.disappear(t))}}))},t.prototype.dispose=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.actorMap&&(this.actorMap.clear(),this.actorMap=null)},t}();t.AppearType=void 0,(o=t.AppearType||(t.AppearType={})).BASE="base",o.ONCE="once",o.LAZY="lazy";var n=function(t,e){var r=e.actor,o=e.entry;this.type=t,this.actor=r,this.entry=o};n.APPEAR="APPEAR",n.DISAPPEAR="DISAPPEAR";var p=function(){function t(t){this.events=new r.Subject,this.isAppear=null,this.element=t}return t.prototype.bind=function(t){this.stage=t},t.prototype.dispatch=function(t,e){this.events.next(new n(t,{actor:this,entry:e}))},t.prototype.appear=function(t){!0!==this.isAppear&&(this.isAppear=!0,this.dispatch(n.APPEAR,t))},t.prototype.disappear=function(t){!1!==this.isAppear&&(this.isAppear=!1,this.dispatch(n.DISAPPEAR,t))},t.prototype.dispose=function(){this.stage&&this.stage.unobserve(this)},t}(),s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},s(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}Object.create;function c(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,i,n=r.call(t),p=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)p.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(i)throw i.error}}return p}function h(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}Object.create;var u=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.appear=function(t){!0!==this.isAppear&&(this.isAppear=!0,this.dispatch(n.APPEAR,t),this.stage&&this.stage.unobserve(this))},e}(p),f=function(t){function e(){var e=t.apply(this,h(arguments))||this;return e.appearTimer=null,e.checkoutDelay=1e3,e.appearDelay=150,e}return a(e,t),e.prototype.setCheckoutDelay=function(t){void 0===t&&(t=1e3),this.checkoutDelay=t},e.prototype.setAppearDelay=function(t){void 0===t&&(t=150),this.appearDelay=t},e.prototype.clearAppearTimer=function(){this.appearTimer&&(clearTimeout(this.appearTimer),this.appearTimer=null)},e.prototype.appear=function(t){var e=this;this.clearAppearTimer(),!0!==this.isAppear&&(this.checkoutDelay<=t.time?this.appearTimer=setTimeout((function(){e.doAppear(t)}),this.appearDelay):this.doAppear(t))},e.prototype.doAppear=function(t){this.isAppear=!0,this.dispatch(n.APPEAR,t),this.stage&&this.stage.unobserve(this)},e.prototype.disappear=function(t){this.clearAppearTimer(),this.isAppear&&(this.isAppear=!1,this.dispatch(n.DISAPPEAR,t))},e}(p);t.AppearEvent=n,t.AppearStage=i,t.BaseActor=p,t.LazyActor=f,t.OnceActor=u,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=jood-appearer.umd.min.js.map