{
  "version": 3,
  "sources": ["../../../src/assets/dynamic-importmap/resolver.ts"],
  "sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction resolveIfNotPlainOrUrl( relUrl, parentUrl ) {\n\tconst hIdx = parentUrl.indexOf( '#' ),\n\t\tqIdx = parentUrl.indexOf( '?' );\n\tif ( hIdx + qIdx > -2 ) {\n\t\tparentUrl = parentUrl.slice(\n\t\t\t0,\n\t\t\t// eslint-disable-next-line no-nested-ternary\n\t\t\thIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx\n\t\t);\n\t}\n\tif ( relUrl.indexOf( '\\\\' ) !== -1 ) {\n\t\trelUrl = relUrl.replace( backslashRegEx, '/' );\n\t}\n\t// protocol-relative\n\tif ( relUrl[ 0 ] === '/' && relUrl[ 1 ] === '/' ) {\n\t\treturn parentUrl.slice( 0, parentUrl.indexOf( ':' ) + 1 ) + relUrl;\n\t}\n\t// relative-url\n\telse if (\n\t\t( relUrl[ 0 ] === '.' &&\n\t\t\t( relUrl[ 1 ] === '/' ||\n\t\t\t\t( relUrl[ 1 ] === '.' &&\n\t\t\t\t\t( relUrl[ 2 ] === '/' ||\n\t\t\t\t\t\t( relUrl.length === 2 && ( relUrl += '/' ) ) ) ) ||\n\t\t\t\t( relUrl.length === 1 && ( relUrl += '/' ) ) ) ) ||\n\t\trelUrl[ 0 ] === '/'\n\t) {\n\t\tconst parentProtocol = parentUrl.slice(\n\t\t\t0,\n\t\t\tparentUrl.indexOf( ':' ) + 1\n\t\t);\n\t\t// Disabled, but these cases will give inconsistent results for deep backtracking\n\t\t//if (parentUrl[parentProtocol.length] !== '/')\n\t\t//  throw new Error('Cannot resolve');\n\t\t// read pathname from parent URL\n\t\t// pathname taken to be part after leading \"/\"\n\t\tlet pathname;\n\t\tif ( parentUrl[ parentProtocol.length + 1 ] === '/' ) {\n\t\t\t// resolving to a :// so we need to read out the auth and host\n\t\t\tif ( parentProtocol !== 'file:' ) {\n\t\t\t\tpathname = parentUrl.slice( parentProtocol.length + 2 );\n\t\t\t\tpathname = pathname.slice( pathname.indexOf( '/' ) + 1 );\n\t\t\t} else {\n\t\t\t\tpathname = parentUrl.slice( 8 );\n\t\t\t}\n\t\t} else {\n\t\t\t// resolving to :/ so pathname is the /... part\n\t\t\tpathname = parentUrl.slice(\n\t\t\t\tparentProtocol.length +\n\t\t\t\t\t( parentUrl[ parentProtocol.length ] === '/' )\n\t\t\t);\n\t\t}\n\n\t\tif ( relUrl[ 0 ] === '/' ) {\n\t\t\treturn (\n\t\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length - 1 ) +\n\t\t\t\trelUrl\n\t\t\t);\n\t\t}\n\n\t\t// join together and split for removal of .. and . segments\n\t\t// looping the string instead of anything fancy for perf reasons\n\t\t// '../../../../../z' resolved to 'x/y' is just 'z'\n\t\tconst segmented =\n\t\t\tpathname.slice( 0, pathname.lastIndexOf( '/' ) + 1 ) + relUrl;\n\n\t\tconst output = [];\n\t\tlet segmentIndex = -1;\n\t\tfor ( let i = 0; i < segmented.length; i++ ) {\n\t\t\t// busy reading a segment - only terminate on '/'\n\t\t\tif ( segmentIndex !== -1 ) {\n\t\t\t\tif ( segmented[ i ] === '/' ) {\n\t\t\t\t\toutput.push( segmented.slice( segmentIndex, i + 1 ) );\n\t\t\t\t\tsegmentIndex = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// new segment - check if it is relative\n\t\t\telse if ( segmented[ i ] === '.' ) {\n\t\t\t\t// ../ segment\n\t\t\t\tif (\n\t\t\t\t\tsegmented[ i + 1 ] === '.' &&\n\t\t\t\t\t( segmented[ i + 2 ] === '/' || i + 2 === segmented.length )\n\t\t\t\t) {\n\t\t\t\t\toutput.pop();\n\t\t\t\t\ti += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// ./ segment\n\t\t\t\telse if (\n\t\t\t\t\tsegmented[ i + 1 ] === '/' ||\n\t\t\t\t\ti + 1 === segmented.length\n\t\t\t\t) {\n\t\t\t\t\ti += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// it is the start of a new segment\n\t\t\twhile ( segmented[ i ] === '/' ) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tsegmentIndex = i;\n\t\t}\n\t\t// finish reading out the last segment\n\t\tif ( segmentIndex !== -1 ) {\n\t\t\toutput.push( segmented.slice( segmentIndex ) );\n\t\t}\n\t\treturn (\n\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length ) +\n\t\t\toutput.join( '' )\n\t\t);\n\t}\n}\n\nfunction resolveUrl( relUrl, parentUrl ) {\n\treturn (\n\t\tresolveIfNotPlainOrUrl( relUrl, parentUrl ) ||\n\t\t( isURL( relUrl )\n\t\t\t? relUrl\n\t\t\t: resolveIfNotPlainOrUrl( './' + relUrl, parentUrl ) )\n\t);\n}\n\nfunction getMatch( path, matchObj ) {\n\tif ( matchObj[ path ] ) {\n\t\treturn path;\n\t}\n\tlet sepIndex = path.length;\n\tdo {\n\t\tconst segment = path.slice( 0, sepIndex + 1 );\n\t\tif ( segment in matchObj ) {\n\t\t\treturn segment;\n\t\t}\n\t} while ( ( sepIndex = path.lastIndexOf( '/', sepIndex - 1 ) ) !== -1 );\n}\n\nfunction applyPackages( id, packages ) {\n\tconst pkgName = getMatch( id, packages );\n\tif ( pkgName ) {\n\t\tconst pkg = packages[ pkgName ];\n\t\tif ( pkg === null ) {\n\t\t\treturn;\n\t\t}\n\t\treturn pkg + id.slice( pkgName.length );\n\t}\n}\n\nfunction resolveImportMap( importMap, resolvedOrPlain, parentUrl ) {\n\tlet scopeUrl = parentUrl && getMatch( parentUrl, importMap.scopes );\n\twhile ( scopeUrl ) {\n\t\tconst packageResolution = applyPackages(\n\t\t\tresolvedOrPlain,\n\t\t\timportMap.scopes[ scopeUrl ]\n\t\t);\n\t\tif ( packageResolution ) {\n\t\t\treturn packageResolution;\n\t\t}\n\t\tscopeUrl = getMatch(\n\t\t\tscopeUrl.slice( 0, scopeUrl.lastIndexOf( '/' ) ),\n\t\t\timportMap.scopes\n\t\t);\n\t}\n\treturn (\n\t\tapplyPackages( resolvedOrPlain, importMap.imports ) ||\n\t\t( resolvedOrPlain.indexOf( ':' ) !== -1 && resolvedOrPlain )\n\t);\n}\n\nfunction resolveAndComposePackages(\n\tpackages,\n\toutPackages,\n\tbaseUrl,\n\tparentMap\n) {\n\tfor ( const p in packages ) {\n\t\tconst resolvedLhs = resolveIfNotPlainOrUrl( p, baseUrl ) || p;\n\t\tconst target = packages[ p ];\n\t\tif ( typeof target !== 'string' ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst mapped = resolveImportMap(\n\t\t\tparentMap,\n\t\t\tresolveIfNotPlainOrUrl( target, baseUrl ) || target,\n\t\t\tbaseUrl\n\t\t);\n\t\tif ( mapped ) {\n\t\t\toutPackages[ resolvedLhs ] = mapped;\n\t\t\tcontinue;\n\t\t}\n\t\t// console.warn(\n\t\t// \t`Mapping \"${ p }\" -> \"${ packages[ p ] }\" does not resolve`\n\t\t// );\n\t}\n}\n\nfunction resolveAndComposeImportMap( json, baseUrl, parentMap ) {\n\tconst outMap = {\n\t\timports: Object.assign( {}, parentMap.imports ),\n\t\tscopes: Object.assign( {}, parentMap.scopes ),\n\t};\n\n\tif ( json.imports ) {\n\t\tresolveAndComposePackages(\n\t\t\tjson.imports,\n\t\t\toutMap.imports,\n\t\t\tbaseUrl,\n\t\t\tparentMap\n\t\t);\n\t}\n\n\tif ( json.scopes ) {\n\t\tfor ( const s in json.scopes ) {\n\t\t\tconst resolvedScope = resolveUrl( s, baseUrl );\n\t\t\tresolveAndComposePackages(\n\t\t\t\tjson.scopes[ s ],\n\t\t\t\toutMap.scopes[ resolvedScope ] ||\n\t\t\t\t\t( outMap.scopes[ resolvedScope ] = {} ),\n\t\t\t\tbaseUrl,\n\t\t\t\tparentMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn outMap;\n}\n\nlet importMap = { imports: {}, scopes: {} };\n\n// TODO: check if this baseURI should change per document, and so\n// it need to be passed as a parameter to methods like `resolve`.\nconst baseUrl = document.baseURI;\nconst pageBaseUrl = baseUrl;\n\n/**\n * Extends the internal dynamic import map with the passed one.\n *\n * @param importMapIn         Import map.\n * @param importMapIn.imports Imports declaration.\n * @param importMapIn.scopes  Scopes declaration.\n */\nexport function addImportMap( importMapIn: {\n\timports?: Record< string, string >;\n\tscopes?: Record< string, any >;\n} ) {\n\timportMap = resolveAndComposeImportMap(\n\t\timportMapIn,\n\t\tpageBaseUrl,\n\t\timportMap\n\t);\n}\n\n/**\n * Resolves the URL of the passed module ID against the current internal\n * dynamic import map.\n *\n * @param id        Module ID.\n * @param parentUrl Parent URL, in case the module ID is relative.\n * @return Resolved module URL.\n */\nexport function resolve( id: string, parentUrl: string ): string {\n\tconst urlResolved = resolveIfNotPlainOrUrl( id, parentUrl );\n\treturn resolveImportMap( importMap, urlResolved || id, parentUrl ) || id;\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,iBAAiB;AAEvB,SAAS,MAAO,KAAc;AAC7B,MAAK,IAAI,QAAS,GAAI,MAAM,IAAK;AAChC,WAAO;AAAA,EACR;AACA,MAAI;AACH,QAAI,IAAK,GAAI;AACb,WAAO;AAAA,EACR,QAAQ;AAC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