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AE,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAClC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;QAElD,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YAC7B,gBAAgB;gBACf,OAAO,aAAa,CAAC,SAAS,KAAK,UAAU;oBAC5C,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;oBACxF,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;YAE5C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,EAAO,IAAI,CAAC,CAAC,CAAC;QACzE,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEJ,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import Promise from '@dojo/shim/Promise';\nimport { isPlugin, useDefault } from './util';\n\ninterface ModuleIdMap {\n\t[path: string]: { id: number; lazy: boolean };\n}\n\ninterface BundleLoaderCallback<T> {\n\t(value: T): void;\n}\n\ninterface WebpackRequire<T> {\n\t(id: number): T | BundleLoaderCallback<T>;\n}\n\n/**\n * A global map (set by the build) of resolved module paths to webpack-specific module data.\n */\ndeclare const __modules__: ModuleIdMap;\n\n/**\n * The webpack-specific require function, set globally by webpack.\n */\ndeclare const __webpack_require__: WebpackRequire<any>;\n\n/**\n * @private\n * Resolves an absolute path from an absolute base path and relative module ID.\n *\n * @param base\n * The absolute base path.\n *\n * @param mid\n * The relative module ID\n *\n * @return\n * The resolved absolute module path.\n */\nfunction resolveRelative(base: string, mid: string): string {\n\tconst isRelative = mid.match(/^\\.+\\//);\n\tlet result = base;\n\n\tif (isRelative) {\n\t\tif (mid.match(/^\\.\\//)) {\n\t\t\tmid = mid.replace(/\\.\\//, '');\n\t\t}\n\n\t\tconst up = mid.match(/\\.\\.\\//g);\n\t\tif (up) {\n\t\t\tconst chunks = base.split('/');\n\n\t\t\tif (up.length > chunks.length) {\n\t\t\t\tthrow new Error('Path cannot go beyond root directory.');\n\t\t\t}\n\n\t\t\tchunks.splice(chunks.length - up.length);\n\t\t\tresult = chunks.join('/');\n\t\t\tmid = mid.replace(/\\.\\.\\//g, '');\n\t\t}\n\n\t\tmid = result + '/' + mid;\n\t}\n\n\treturn mid;\n}\n\n/**\n * @private\n * Returns the parent directory for the specified module ID.\n *\n * @param context\n * A function that returns the context module ID.\n *\n * @return\n * The parent directory of the path returned by the context function.\n */\nfunction getBasePath(context: () => string): string {\n\treturn context()\n\t\t.split('/')\n\t\t.slice(0, -1)\n\t\t.join('/');\n}\n\n/**\n * A webpack-specific function that replaces `@dojo/core/load` in its builds. In order for a module to be loaded,\n * it must first be included in a webpack chunk, whether that chunk is included in the main build, or lazy-loaded.\n * Note that this module is not intended for direct use, but rather is intended for use by a webpack plugin\n * that sets the module ID map used to translate resolved module paths to webpack module IDs.\n *\n * @param contextRequire\n * An optional function that returns the base path to use when resolving relative module IDs.\n *\n * @param ...mids\n * One or more IDs for modules to load.\n *\n * @return\n * A promise to the loaded module values.\n */\nexport default function load(contextRequire: () => string, ...mids: string[]): Promise<any[]>;\nexport default function load(...mids: string[]): Promise<any[]>;\nexport default function load(...args: any[]): Promise<any[]> {\n\tconst req = __webpack_require__;\n\tconst context =\n\t\ttypeof args[0] === 'function'\n\t\t\t? args[0]\n\t\t\t: function() {\n\t\t\t\t\treturn '';\n\t\t\t\t};\n\n\tconst modules = __modules__ || {};\n\tconst base = getBasePath(context);\n\n\tconst results = args\n\t\t.filter((mid: string | Function) => typeof mid === 'string')\n\t\t.map((mid: string) => resolveRelative(base, mid))\n\t\t.map((mid: string) => {\n\t\t\tlet [moduleId, pluginResourceId] = mid.split('!');\n\t\t\tconst moduleMeta = modules[mid] || modules[moduleId];\n\n\t\t\tif (!moduleMeta) {\n\t\t\t\treturn Promise.reject(new Error(`Missing module: ${mid}`));\n\t\t\t}\n\n\t\t\tif (moduleMeta.lazy) {\n\t\t\t\treturn new Promise((resolve) => req(moduleMeta.id)(resolve));\n\t\t\t}\n\n\t\t\tconst module = req(moduleMeta.id);\n\t\t\tconst defaultExport = module['default'] || module;\n\n\t\t\tif (isPlugin(defaultExport)) {\n\t\t\t\tpluginResourceId =\n\t\t\t\t\ttypeof defaultExport.normalize === 'function'\n\t\t\t\t\t\t? defaultExport.normalize(pluginResourceId, (mid: string) => resolveRelative(base, mid))\n\t\t\t\t\t\t: resolveRelative(base, pluginResourceId);\n\n\t\t\t\treturn Promise.resolve(defaultExport.load(pluginResourceId, <any>load));\n\t\t\t}\n\n\t\t\treturn Promise.resolve(module);\n\t\t});\n\n\treturn Promise.all(results);\n}\n\nexport { isPlugin, useDefault };\n"]}