{
  "version": 3,
  "sources": ["../../src/shim/index.ts"],
  "sourcesContent": ["/**\n * [[include:src/shim/README.md]]\n *\n * @packageDocumentation\n * @module twind/shim\n */\n\nimport type { Configuration } from '../types'\n\nimport { setup as setupTW } from '../index'\nimport { createObserver } from '../observe/index'\n\n/**\n * Options for {@link setup}.\n */\nexport interface ShimConfiguration extends Configuration {\n  /**\n   * The root element to shim (default: `document.documentElement`).\n   */\n  target?: HTMLElement\n}\n\nif (typeof document !== 'undefined' && typeof addEventListener === 'function') {\n  // eslint-disable-next-line no-var\n  var onload = () => {\n    const script = document.querySelector('script[type=\"twind-config\"]')\n\n    setup(script ? JSON.parse(script.innerHTML) : {})\n  }\n\n  if (document.readyState === 'loading') {\n    // Loading hasn't finished yet\n    addEventListener('DOMContentLoaded', onload)\n  } else {\n    // `DOMContentLoaded` has already fired\n    // invoke on next tick to allow other setup methods to run\n    // eslint-disable-next-line no-var\n    var timeoutRef = setTimeout(onload)\n  }\n}\n\nconst observer = createObserver()\n\n/**\n * Stop shimming/observing all nodes.\n */\nexport const disconnect = (): void => {\n  if (onload) {\n    // Removing the callbacks ensures that the setup is called only once\n    // either programmatically from userland or by DOMContentLoaded/setTimeout\n    removeEventListener('DOMContentLoaded', onload)\n    clearTimeout(timeoutRef)\n  }\n\n  observer.disconnect()\n}\n\n/**\n * Configure the default {@link tw} and starts {@link observe | observing} the\n * {@link ShimConfiguration.target | target element} (default: `document.documentElement`).\n *\n * You do not need to call this method. As an alternativ you can provide a\n * `<script type=\"twind-config\">...</script>` element within the document.\n * The content must be valid JSON and all {@link twind.setup | twind setup options}\n * (including hash) are supported.\n */\nexport const setup = ({\n  target = document.documentElement,\n  ...config\n}: ShimConfiguration = {}): void => {\n  if (Object.keys(config).length) {\n    setupTW(config)\n  }\n\n  // Remove event listeners\n  disconnect()\n\n  observer.observe(target)\n\n  target.hidden = false\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,eAAiC;AACjC,qBAA+B;AAY/B,IAAI,OAAO,aAAa,eAAe,OAAO,qBAAqB;AAE7D,WAAS;AACX,UAAM,SAAS,SAAS,cAAc;AAEtC,UAAM,SAAS,KAAK,MAAM,OAAO,aAAa;AAAA;AAGhD,MAAI,SAAS,eAAe;AAE1B,qBAAiB,oBAAoB;AAAA;AAKjC,iBAAa,WAAW;AAAA;AAAA;AAb1B;AAaE;AAIR,IAAM,WAAW;AAKV,IAAM,aAAa;AACxB,MAAI;AAGF,wBAAoB,oBAAoB;AACxC,iBAAa;AAAA;AAGf,WAAS;AAAA;AAYJ,IAAM,QAAQ,CAAC;AAAA,EACpB,SAAS,SAAS;AAAA,KACf;AAAA,IACkB;AACrB,MAAI,OAAO,KAAK,QAAQ;AACtB,mBAAQ;AAAA;AAIV;AAEA,WAAS,QAAQ;AAEjB,SAAO,SAAS;AAAA;",
  "names": []
}
