1 line
37 KiB
Plaintext
1 line
37 KiB
Plaintext
|
|
{"version":3,"file":"Resolver.mjs","sources":["../../src/resolver/Resolver.ts"],"sourcesContent":["import { utils } from '@pixi/core';\nimport { convertToList } from '../utils/convertToList';\nimport { createStringVariations } from '../utils/createStringVariations';\nimport { isSingleItem } from '../utils/isSingleItem';\n\nimport type {\n ArrayOr,\n AssetsBundle,\n AssetsManifest,\n AssetSrc,\n LoadParserName,\n ResolvedAsset,\n ResolvedSrc,\n UnresolvedAsset,\n UnresolvedAssetObject\n} from '../types';\nimport type { PreferOrder, ResolveURLParser } from './types';\n\nexport interface BundleIdentifierOptions\n{\n /** The character that is used to connect the bundleId and the assetId when generating a bundle asset id key */\n connector?: string;\n /**\n * A function that generates a bundle asset id key from a bundleId and an assetId\n * @param bundleId - the bundleId\n * @param assetId - the assetId\n * @returns the bundle asset id key\n */\n createBundleAssetId?: (bundleId: string, assetId: string) => string;\n /**\n * A function that generates an assetId from a bundle asset id key. This is the reverse of generateBundleAssetId\n * @param bundleId - the bundleId\n * @param assetBundleId - the bundle asset id key\n * @returns the assetId\n */\n extractAssetIdFromBundle?: (bundleId: string, assetBundleId: string) => string;\n}\n\n/**\n * A class that is responsible for resolving mapping asset URLs to keys.\n * At its most basic it can be used for Aliases:\n *\n * ```js\n * resolver.add('foo', 'bar');\n * resolver.resolveUrl('foo') // => 'bar'\n * ```\n *\n * It can also be used to resolve the most appropriate asset for a given URL:\n *\n * ```js\n * resolver.prefer({\n * params: {\n * format: 'webp',\n * resolution: 2,\n * }\n * });\n *\n * resolver.add('foo', ['bar@2x.webp', 'bar@2x.png', 'bar.webp', 'bar.png']);\n *\n * resolver.resolveUrl('foo') // => 'bar@2x.webp'\n * ```\n * Other features include:\n * - Ability to process a manifest file to get the correct understanding of how to resolve all assets\n * - Ability to add custom parsers for specific file types\n * - Ability to add custom prefer rules\n *\n * This class only cares about the URL, not the loading of the asset itself.\n *\n * It is not intended that this class is created by developers - its part of the Asset class\n * This is the third major system of PixiJS' main Assets class\n * @memberof PIXI\n */\nexport class Resolver\n{\n private _defaultBundleIdentifierOptions: Required<BundleIdentifierOptions> = {\n connector: '-',\n createBundleAssetId: (bundleId, assetId) =>\n `${bundleId}${this._bundleIdConnector}${assetId}`,\n extractAssetIdFromBundle: (bundleId, assetBundleId) =>\n assetBundleId.replace(`${bundleId}${this._bundleIdConnector}`, ''),\n };\n\n /** The character that is used to connect the bundleId and the assetId when generating a bundle asset id key */\n private _bundleIdConnector = this._defaultBundleIdentifierOptions.connector;\n\n /**\n * A function that generates a bundle asset id key from a bundleId and an assetId\n * @param bundleId - the bundleId\n * @param assetId - the assetId\n * @returns the bundle asset id key\n */\n private _createBundleAssetId: (\n bundleId: string,\n assetId: string\n ) => string = this._defaultBundleIdentifierOptions.createBundleAssetId;\n\n /**\n * A function that generates an assetId from a bundle asset id key. This is the reverse of generateBundleAssetId\n * @param bundleId - the bundleId\n * @param assetBundleId - the bundle asset id key\n * @returns the assetId\n */\n private _extractAssetIdFromBundle: (\n bundleId: string,\n assetBundleId: string\n ) => string = this._defaultBundleIdentifierOptions.extractAssetIdFromBundle;\n\n private _assetMap: Record<string, ResolvedAsset[]> = {};\n private _preferredOrder: PreferOrder[] = [];\n private _parsers: Re
|