@story-telling-reporter/react-embed-code-generator
Version:
## Installation `yarn install`
1 lines • 4.52 kB
JavaScript
"use strict";(self.webpackChunk_story_telling_reporter_react_embed_code_generator=self.webpackChunk_story_telling_reporter_react_embed_code_generator||[]).push([[900],{5900:(e,t,r)=>{var i,n=Object.create,o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,a=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,c=(e,t,r,i)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of l(t))h.call(e,n)||n===r||o(e,n,{get:()=>t[n],enumerable:!(i=s(t,n))||i.enumerable});return e},u=(e,t,r)=>(r=null!=e?n(a(e)):{},c(!t&&e&&e.__esModule?r:o(r,"default",{value:e,enumerable:!0}),e)),d=(e,t,r)=>((e,t,r)=>t in e?o(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r),p={};((e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})})(p,{InView:()=>k,defaultFallbackInView:()=>w,observe:()=>V,useInView:()=>m}),e.exports=(i=p,c(o({},"__esModule",{value:!0}),i));var b=u(r(4041)),g=new Map,f=new WeakMap,y=0,v=void 0;function w(e){v=e}function V(e,t,r={},i=v){if(void 0===window.IntersectionObserver&&void 0!==i){const n=e.getBoundingClientRect();return t(i,{isIntersecting:i,target:e,intersectionRatio:"number"==typeof r.threshold?r.threshold:0,time:0,boundingClientRect:n,intersectionRect:n,rootBounds:n}),()=>{}}const{id:n,observer:o,elements:s}=function(e){const t=function(e){return Object.keys(e).sort().filter((t=>void 0!==e[t])).map((t=>{return`${t}_${"root"===t?(r=e.root,r?(f.has(r)||(y+=1,f.set(r,y.toString())),f.get(r)):"0"):e[t]}`;var r})).toString()}(e);let r=g.get(t);if(!r){const i=new Map;let n;const o=new IntersectionObserver((t=>{t.forEach((t=>{var r;const o=t.isIntersecting&&n.some((e=>t.intersectionRatio>=e));e.trackVisibility&&void 0===t.isVisible&&(t.isVisible=o),null==(r=i.get(t.target))||r.forEach((e=>{e(o,t)}))}))}),e);n=o.thresholds||(Array.isArray(e.threshold)?e.threshold:[e.threshold||0]),r={id:t,observer:o,elements:i},g.set(t,r)}return r}(r),l=s.get(e)||[];return s.has(e)||s.set(e,l),l.push(t),o.observe(e),function(){l.splice(l.indexOf(t),1),0===l.length&&(s.delete(e),o.unobserve(e)),0===s.size&&(o.disconnect(),g.delete(n))}}var k=class extends b.Component{constructor(e){super(e),d(this,"node",null),d(this,"_unobserveCb",null),d(this,"handleNode",(e=>{this.node&&(this.unobserve(),e||this.props.triggerOnce||this.props.skip||this.setState({inView:!!this.props.initialInView,entry:void 0})),this.node=e||null,this.observeNode()})),d(this,"handleChange",((e,t)=>{e&&this.props.triggerOnce&&this.unobserve(),function(e){return"function"!=typeof e.children}(this.props)||this.setState({inView:e,entry:t}),this.props.onChange&&this.props.onChange(e,t)})),this.state={inView:!!e.initialInView,entry:void 0}}componentDidMount(){this.unobserve(),this.observeNode()}componentDidUpdate(e){e.rootMargin===this.props.rootMargin&&e.root===this.props.root&&e.threshold===this.props.threshold&&e.skip===this.props.skip&&e.trackVisibility===this.props.trackVisibility&&e.delay===this.props.delay||(this.unobserve(),this.observeNode())}componentWillUnmount(){this.unobserve()}observeNode(){if(!this.node||this.props.skip)return;const{threshold:e,root:t,rootMargin:r,trackVisibility:i,delay:n,fallbackInView:o}=this.props;this._unobserveCb=V(this.node,this.handleChange,{threshold:e,root:t,rootMargin:r,trackVisibility:i,delay:n},o)}unobserve(){this._unobserveCb&&(this._unobserveCb(),this._unobserveCb=null)}render(){const{children:e}=this.props;if("function"==typeof e){const{inView:t,entry:r}=this.state;return e({inView:t,entry:r,ref:this.handleNode})}const{as:t,triggerOnce:r,threshold:i,root:n,rootMargin:o,onChange:s,skip:l,trackVisibility:a,delay:h,initialInView:c,fallbackInView:u,...d}=this.props;return b.createElement(t||"div",{ref:this.handleNode,...d},e)}},_=u(r(4041));function m({threshold:e,delay:t,trackVisibility:r,rootMargin:i,root:n,triggerOnce:o,skip:s,initialInView:l,fallbackInView:a,onChange:h}={}){var c;const[u,d]=_.useState(null),p=_.useRef(h),[b,g]=_.useState({inView:!!l,entry:void 0});p.current=h,_.useEffect((()=>{if(s||!u)return;let l;return l=V(u,((e,t)=>{g({inView:e,entry:t}),p.current&&p.current(e,t),t.isIntersecting&&o&&l&&(l(),l=void 0)}),{root:n,rootMargin:i,threshold:e,trackVisibility:r,delay:t},a),()=>{l&&l()}}),[Array.isArray(e)?e.toString():e,u,n,i,o,s,r,a,t]);const f=null==(c=b.entry)?void 0:c.target,y=_.useRef(void 0);u||!f||o||s||y.current===f||(y.current=f,g({inView:!!l,entry:void 0}));const v=[d,b.inView,b.entry];return v.ref=v[0],v.inView=v[1],v.entry=v[2],v}}}]);