"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./observers.mjs.js"),t=require("../../../../../../motion-dom/dist/es/render/Feature.mjs.js");const r={some:0,all:1};class s extends t.Feature{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.stopObserver?.();const{viewport:t={}}=this.node.getProps(),{root:s,margin:i,amount:o="some",once:n}=t,a={root:s?s.current:void 0,rootMargin:i,threshold:"number"==typeof o?o:r[o]};this.stopObserver=e.observeIntersection(this.node.current,a,(e=>{const{isIntersecting:t}=e;if(this.isInView===t)return;if(this.isInView=t,n&&!t&&this.hasEnteredView)return;t&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",t);const{onViewportEnter:r,onViewportLeave:s}=this.node.getProps(),i=t?r:s;i&&i(e)}))}mount(){this.startObserver()}update(){if("undefined"==typeof IntersectionObserver)return;const{props:e,prevProps:t}=this.node,r=["amount","margin","root"].some(function(e){let{viewport:t={}}=e,{viewport:r={}}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e=>t[e]!==r[e]}(e,t));r&&this.startObserver()}unmount(){this.stopObserver?.(),this.hasEnteredView=!1,this.isInView=!1}}exports.InViewFeature=s;
//# sourceMappingURL=index.mjs.js.map
