{
  "version": 3,
  "sources": ["../src/hydration.ts"],
  "sourcesContent": ["/**\n * External dependencies\n */\nimport { hydrate, type ContainerNode, type ComponentChild } from 'preact';\n/**\n * Internal dependencies\n */\nimport { toVdom, hydratedIslands } from './vdom';\nimport { createRootFragment, splitTask } from './utils';\n\n// Keep the same root fragment for each interactive region node.\nconst regionRootFragments = new WeakMap();\nexport const getRegionRootFragment = (\n\tregions: Element | Element[]\n): ContainerNode => {\n\tconst region = Array.isArray( regions ) ? regions[ 0 ] : regions;\n\tif ( ! region.parentElement ) {\n\t\tthrow Error( 'The passed region should be an element with a parent.' );\n\t}\n\tif ( ! regionRootFragments.has( region ) ) {\n\t\tregionRootFragments.set(\n\t\t\tregion,\n\t\t\tcreateRootFragment( region.parentElement, regions )\n\t\t);\n\t}\n\treturn regionRootFragments.get( region );\n};\n\n// Initial vDOM regions associated with its DOM element.\nexport const initialVdom = new WeakMap< Element, ComponentChild >();\n\n// Promise that resolves with the populated initialVdom after hydration completes.\nlet resolveInitialVdom!: ( map: WeakMap< Element, ComponentChild > ) => void;\nexport const initialVdomPromise = new Promise<\n\tWeakMap< Element, ComponentChild >\n>( ( resolve ) => {\n\tresolveInitialVdom = resolve;\n} );\n\n// Initialize the router with the initial DOM.\nexport const hydrateRegions = async () => {\n\tconst nodes = document.querySelectorAll( `[data-wp-interactive]` );\n\n\tfor ( const node of nodes ) {\n\t\tif ( ! hydratedIslands.has( node ) ) {\n\t\t\tawait splitTask();\n\t\t\tconst fragment = getRegionRootFragment( node );\n\t\t\tconst vdom = toVdom( node );\n\t\t\tinitialVdom.set( node, vdom );\n\t\t\tawait splitTask();\n\t\t\thydrate( vdom, fragment );\n\t\t}\n\t}\n\n\t// Resolve the promise with the fully populated initialVdom after all regions are hydrated.\n\tresolveInitialVdom( initialVdom );\n};\n"],
  "mappings": ";AAGA,SAAS,eAAwD;AAIjE,SAAS,QAAQ,uBAAuB;AACxC,SAAS,oBAAoB,iBAAiB;AAG9C,IAAM,sBAAsB,oBAAI,QAAQ;AACjC,IAAM,wBAAwB,CACpC,YACmB;AACnB,QAAM,SAAS,MAAM,QAAS,OAAQ,IAAI,QAAS,CAAE,IAAI;AACzD,MAAK,CAAE,OAAO,eAAgB;AAC7B,UAAM,MAAO,uDAAwD;AAAA,EACtE;AACA,MAAK,CAAE,oBAAoB,IAAK,MAAO,GAAI;AAC1C,wBAAoB;AAAA,MACnB;AAAA,MACA,mBAAoB,OAAO,eAAe,OAAQ;AAAA,IACnD;AAAA,EACD;AACA,SAAO,oBAAoB,IAAK,MAAO;AACxC;AAGO,IAAM,cAAc,oBAAI,QAAmC;AAGlE,IAAI;AACG,IAAM,qBAAqB,IAAI,QAEnC,CAAE,YAAa;AACjB,uBAAqB;AACtB,CAAE;AAGK,IAAM,iBAAiB,YAAY;AACzC,QAAM,QAAQ,SAAS,iBAAkB,uBAAwB;AAEjE,aAAY,QAAQ,OAAQ;AAC3B,QAAK,CAAE,gBAAgB,IAAK,IAAK,GAAI;AACpC,YAAM,UAAU;AAChB,YAAM,WAAW,sBAAuB,IAAK;AAC7C,YAAM,OAAO,OAAQ,IAAK;AAC1B,kBAAY,IAAK,MAAM,IAAK;AAC5B,YAAM,UAAU;AAChB,cAAS,MAAM,QAAS;AAAA,IACzB;AAAA,EACD;AAGA,qBAAoB,WAAY;AACjC;",
  "names": []
}
