{
  "version": 3,
  "sources": ["../../src/assets/script-modules.ts"],
  "sourcesContent": ["/**\n * Internal dependencies\n */\nimport {\n\tinitialImportMap,\n\timportPreloadedModule,\n\tpreloadWithMap,\n\ttype ModuleLoad,\n} from './dynamic-importmap';\n\n/**\n * IDs of modules that should be resolved by the browser rather than\n * processed internally.\n */\nconst resolvedScriptModules = new Set< string >();\n\n/**\n * Marks the specified module as natively resolved.\n * @param url Script module URL.\n */\nexport const markScriptModuleAsResolved = ( url: string ) => {\n\tresolvedScriptModules.add( url );\n};\n\n/**\n * Resolves and fetches modules present in the passed document, using the\n * document's import map to resolve them.\n *\n * @param doc Document containing the modules to preload.\n * @return Array of promises that resolve to a `ScriptModuleLoad` instance.\n */\nexport const preloadScriptModules = ( doc: Document ) => {\n\t// Extract the import map from the document.\n\tconst importMapElement = doc.querySelector< HTMLScriptElement >(\n\t\t'script#wp-importmap[type=importmap]'\n\t);\n\tconst importMap = importMapElement\n\t\t? JSON.parse( importMapElement.text )\n\t\t: { imports: {}, scopes: {} };\n\n\t// Remove imports also in the initial page's import map.\n\t// Those should be handled natively.\n\tfor ( const key in initialImportMap.imports ) {\n\t\tdelete importMap.imports[ key ];\n\t}\n\n\t// Get the URL of all modules contained in the document.\n\tconst moduleUrls = [\n\t\t...doc.querySelectorAll< HTMLScriptElement >(\n\t\t\t'script[type=module][src][data-wp-router-options]'\n\t\t),\n\t]\n\t\t.filter( ( script ) => {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(\n\t\t\t\t\tscript.getAttribute( 'data-wp-router-options' )\n\t\t\t\t);\n\t\t\t\treturn parsed?.loadOnClientNavigation === true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} )\n\t\t.map( ( script ) => script.src );\n\n\t// Resolve and fetch those not resolved natively.\n\treturn moduleUrls\n\t\t.filter( ( url ) => ! resolvedScriptModules.has( url ) )\n\t\t.map( ( url ) => preloadWithMap( url, importMap ) );\n};\n\n/**\n * Imports modules respresented by the passed `ScriptModuleLoad` instances.\n *\n * @param modules Array of `MoudleLoad` instances.\n * @return Promise that resolves once all modules are imported.\n */\nexport const importScriptModules = ( modules: ScriptModuleLoad[] ) =>\n\tPromise.all( modules.map( ( m ) => importPreloadedModule( m ) ) );\n\nexport type ScriptModuleLoad = ModuleLoad;\n"],
  "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAMP,IAAM,wBAAwB,oBAAI,IAAc;AAMzC,IAAM,6BAA6B,CAAE,QAAiB;AAC5D,wBAAsB,IAAK,GAAI;AAChC;AASO,IAAM,uBAAuB,CAAE,QAAmB;AAExD,QAAM,mBAAmB,IAAI;AAAA,IAC5B;AAAA,EACD;AACA,QAAM,YAAY,mBACf,KAAK,MAAO,iBAAiB,IAAK,IAClC,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,EAAE;AAI7B,aAAY,OAAO,iBAAiB,SAAU;AAC7C,WAAO,UAAU,QAAS,GAAI;AAAA,EAC/B;AAGA,QAAM,aAAa;AAAA,IAClB,GAAG,IAAI;AAAA,MACN;AAAA,IACD;AAAA,EACD,EACE,OAAQ,CAAE,WAAY;AACtB,QAAI;AACH,YAAM,SAAS,KAAK;AAAA,QACnB,OAAO,aAAc,wBAAyB;AAAA,MAC/C;AACA,aAAO,QAAQ,2BAA2B;AAAA,IAC3C,QAAQ;AACP,aAAO;AAAA,IACR;AAAA,EACD,CAAE,EACD,IAAK,CAAE,WAAY,OAAO,GAAI;AAGhC,SAAO,WACL,OAAQ,CAAE,QAAS,CAAE,sBAAsB,IAAK,GAAI,CAAE,EACtD,IAAK,CAAE,QAAS,eAAgB,KAAK,SAAU,CAAE;AACpD;AAQO,IAAM,sBAAsB,CAAE,YACpC,QAAQ,IAAK,QAAQ,IAAK,CAAE,MAAO,sBAAuB,CAAE,CAAE,CAAE;",
  "names": []
}
