{"version":3,"file":"react-scroll-marker.mjs","sources":["../src/container.js","../src/link.js","../src/section.js"],"sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\n\nconst Context = React.createContext();\nconst { Provider } = Context;\n\nclass Container extends React.Component {\n  constructor(props) {\n    super(props);\n\n    this.state = {\n      activeId: null\n    };\n\n    this.setActive = this.setActive.bind(this);\n  }\n\n  componentDidMount() {\n    if (\n      // https://github.com/akiran/can-use-dom\n      typeof window !== \"undefined\" &&\n      window.document &&\n      window.document.createElement &&\n      // Check to see if there is a hash.\n      window.location &&\n      window.location.hash\n    ) {\n      this.setActive(window.location.hash.replace(\"#\", \"\"));\n    }\n  }\n\n  setActive(id) {\n    this.setState({\n      activeId: id\n    });\n  }\n\n  render() {\n    const { activeId } = this.state;\n    const { children } = this.props;\n\n    return (\n      <Provider value={{ activeId, setActive: this.setActive }}>\n        {children}\n      </Provider>\n    );\n  }\n}\n\nContainer.propTypes = {\n  children: PropTypes.node.isRequired\n};\n\nexport default Container;\nexport { Context };\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport { Context } from \"./container\";\n\nclass Link extends React.Component {\n  render() {\n    const { id, children } = this.props;\n    const { activeId, setActive } = this.context;\n\n    const isActive = id === activeId;\n\n    return children({\n      isActive,\n      onClick: () => {\n        setActive(id);\n      }\n    });\n  }\n}\n\nLink.contextType = Context;\n\nLink.propTypes = {\n  id: PropTypes.string.isRequired,\n  children: PropTypes.func.isRequired\n};\n\nexport default Link;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { Waypoint } from \"react-waypoint\";\n\nimport { Context } from \"./container\";\n\nconst Section = props => {\n  const { id, children } = props;\n\n  return (\n    <Context.Consumer>\n      {({ setActive }) => (\n        <React.Fragment>\n          <Waypoint\n            onEnter={({ event }) => {\n              // We only want to mark a section as active if the section is\n              // scrolled into view. `Waypoint`, by default, fires events on\n              // resize, mount, and re-render.\n              if (event) {\n                setActive(id);\n              }\n            }}\n          />\n\n          {children({ id })}\n        </React.Fragment>\n      )}\n    </Context.Consumer>\n  );\n};\n\nSection.propTypes = {\n  id: PropTypes.string.isRequired,\n  children: PropTypes.func.isRequired\n};\n\nexport default Section;\n"],"names":["Context","React","createContext","Provider","Container","props","state","activeId","setActive","_this","bind","Component","window","document","createElement","location","hash","replace","id","setState","value","this","children","propTypes","PropTypes","node","isRequired","Link","context","isActive","onClick","contextType","string","func","Section","Consumer","Fragment","Waypoint","onEnter","event"],"mappings":"6/BAGA,IAAMA,EAAUC,EAAMC,gBACdC,EAAaH,EAAbG,SAEFC,yBACQC,mDACJA,KAEDC,MAAQ,CACXC,SAAU,QAGPC,UAAYC,EAAKD,UAAUE,wBARZT,EAAMU,0DAcN,oBAAXC,QACPA,OAAOC,UACPD,OAAOC,SAASC,eAEhBF,OAAOG,UACPH,OAAOG,SAASC,WAEXR,UAAUI,OAAOG,SAASC,KAAKC,QAAQ,IAAK,uCAI3CC,QACHC,SAAS,CACZZ,SAAUW,4CASVjB,gBAACE,GAASiB,MAAO,CAAEb,SAJAc,KAAKf,MAAlBC,SAIuBC,UAAWa,KAAKb,YAH1Ba,KAAKhB,MAAlBiB,mBAUZlB,EAAUmB,UAAY,CACpBD,SAAUE,EAAUC,KAAKC,gBC7CrBC,0FAAa1B,EAAMU,qDAEIU,KAAKhB,MAAtBa,IAAAA,KACwBG,KAAKO,QAAnBpB,IAAAA,iBAIXc,IALKA,UAKI,CACdO,SAHeX,MAFTX,SAMNuB,QAAS,WACPtB,EAAUU,eAMlBS,EAAKI,YAAc/B,EAEnB2B,EAAKJ,UAAY,CACfL,GAAIM,EAAUQ,OAAON,WACrBJ,SAAUE,EAAUS,KAAKP,YCnB3B,IAAMQ,EAAU,SAAA7B,OACNa,EAAiBb,EAAjBa,GAAII,EAAajB,EAAbiB,gBAGVrB,gBAACD,EAAQmC,cACN,gBAAG3B,IAAAA,iBACFP,gBAACA,EAAMmC,cACLnC,gBAACoC,GACCC,QAAS,cAAGC,OAKR/B,EAAUU,MAKfI,EAAS,CAAEJ,GAAAA,QAOtBgB,EAAQX,UAAY,CAClBL,GAAIM,EAAUQ,OAAON,WACrBJ,SAAUE,EAAUS,KAAKP"}