@gglib/content 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/Readme.md +1 -1
- package/dist/bundles/content.esm.js +1050 -0
- package/dist/bundles/content.esm.js.map +1 -0
- package/dist/content/src/AssetContainer.d.ts +18 -0
- package/dist/content/src/AssetContainer.d.ts.map +1 -0
- package/dist/content/src/AssetContainer.js +30 -0
- package/dist/content/src/AssetContainer.js.map +1 -0
- package/dist/content/src/AssetLoaderRegistry.d.ts +21 -0
- package/dist/content/src/AssetLoaderRegistry.d.ts.map +1 -0
- package/dist/content/src/AssetLoaderRegistry.js +28 -0
- package/dist/content/src/AssetLoaderRegistry.js.map +1 -0
- package/dist/content/src/AssetType.d.ts +13 -0
- package/dist/content/src/AssetType.d.ts.map +1 -0
- package/dist/content/src/AssetType.js +6 -0
- package/dist/content/src/AssetType.js.map +1 -0
- package/dist/content/src/AsyncExecutor.d.ts +63 -0
- package/dist/content/src/AsyncExecutor.d.ts.map +1 -0
- package/dist/content/src/AsyncExecutor.js +166 -0
- package/dist/content/src/AsyncExecutor.js.map +1 -0
- package/dist/content/src/ContentLoader.d.ts +266 -0
- package/dist/content/src/ContentLoader.d.ts.map +1 -0
- package/dist/content/src/ContentLoader.js +341 -0
- package/dist/content/src/ContentLoader.js.map +1 -0
- package/dist/content/src/ContentType.d.ts.map +1 -1
- package/dist/content/src/ContentType.js +6 -10
- package/dist/content/src/ContentType.js.map +1 -1
- package/dist/content/src/HttpClient.d.ts +48 -0
- package/dist/content/src/HttpClient.d.ts.map +1 -0
- package/dist/content/src/HttpClient.js +139 -0
- package/dist/content/src/HttpClient.js.map +1 -0
- package/dist/content/src/MaterialRegistry.d.ts +14 -0
- package/dist/content/src/MaterialRegistry.d.ts.map +1 -0
- package/dist/content/src/MaterialRegistry.js +24 -0
- package/dist/content/src/MaterialRegistry.js.map +1 -0
- package/dist/content/src/ResourceGraph.d.ts +54 -0
- package/dist/content/src/ResourceGraph.d.ts.map +1 -0
- package/dist/content/src/ResourceGraph.js +195 -0
- package/dist/content/src/ResourceGraph.js.map +1 -0
- package/dist/content/src/TextureLoader.d.ts +14 -0
- package/dist/content/src/TextureLoader.d.ts.map +1 -0
- package/dist/content/src/TextureLoader.js +70 -0
- package/dist/content/src/TextureLoader.js.map +1 -0
- package/dist/content/src/index.d.ts +8 -7
- package/dist/content/src/index.d.ts.map +1 -1
- package/dist/content/src/index.js +8 -7
- package/dist/content/src/index.js.map +1 -1
- package/dist/content/tsconfig.build.tsbuildinfo +1 -0
- package/dist/content/tsconfig.spec.tsbuildinfo +1 -0
- package/dist/stats.html +211 -170
- package/package.json +19 -8
- package/dist/bundles/content.umd.js +0 -713
- package/dist/bundles/content.umd.js.map +0 -1
- package/dist/content/src/ContentManager.d.ts +0 -153
- package/dist/content/src/ContentManager.d.ts.map +0 -1
- package/dist/content/src/ContentManager.js +0 -361
- package/dist/content/src/ContentManager.js.map +0 -1
- package/dist/content/src/ContentType.spec.d.ts +0 -2
- package/dist/content/src/ContentType.spec.d.ts.map +0 -1
- package/dist/content/src/ContentType.spec.js +0 -27
- package/dist/content/src/ContentType.spec.js.map +0 -1
- package/dist/content/src/Data.d.ts +0 -37
- package/dist/content/src/Data.d.ts.map +0 -1
- package/dist/content/src/Data.js +0 -34
- package/dist/content/src/Data.js.map +0 -1
- package/dist/content/src/Loader.d.ts +0 -69
- package/dist/content/src/Loader.d.ts.map +0 -1
- package/dist/content/src/Loader.js +0 -16
- package/dist/content/src/Loader.js.map +0 -1
- package/dist/content/src/Pipeline.d.ts +0 -38
- package/dist/content/src/Pipeline.d.ts.map +0 -1
- package/dist/content/src/Pipeline.js +0 -182
- package/dist/content/src/Pipeline.js.map +0 -1
- package/dist/content/src/Pipeline.spec.d.ts +0 -2
- package/dist/content/src/Pipeline.spec.d.ts.map +0 -1
- package/dist/content/src/Pipeline.spec.js +0 -121
- package/dist/content/src/Pipeline.spec.js.map +0 -1
- package/dist/content/src/PipelineContext.d.ts +0 -40
- package/dist/content/src/PipelineContext.d.ts.map +0 -1
- package/dist/content/src/PipelineContext.js +0 -2
- package/dist/content/src/PipelineContext.js.map +0 -1
- package/dist/content/src/symbols.d.ts +0 -2
- package/dist/content/src/symbols.d.ts.map +0 -1
- package/dist/content/src/symbols.js +0 -2
- package/dist/content/src/symbols.js.map +0 -1
- package/dist/content/src/utils.d.ts +0 -17
- package/dist/content/src/utils.d.ts.map +0 -1
- package/dist/content/src/utils.js +0 -42
- package/dist/content/src/utils.js.map +0 -1
- package/dist/content/tsconfig.tsbuildinfo +0 -2773
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentLoader.js","sourceRoot":"","sources":["../../../src/ContentLoader.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,yBAAyB,EACzB,SAAS,EACT,QAAQ,EACR,IAAI,GAKL,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,EAAgB,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,EAAe,mBAAmB,EAAiD,MAAM,uBAAuB,CAAA;AACvH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAiB,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,UAAU,EAA6B,MAAM,cAAc,CAAA;AAqEpE;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAkB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IACzE,OAAO,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAC,CAAC,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;AACzD,CAAC,CAAA;AA2BD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GA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\n Device,\n isAquirableTextureOptions,\n isOwnable,\n Material,\n Mesh,\n MaterialOptions,\n ResourceScope,\n Texture,\n TextureOptions,\n} from '@gglib/graphics'\nimport { Model, ModelOptions } from '@gglib/model'\nimport { extname, mergeUri } from '@gglib/utils'\nimport { AssetContainer } from './AssetContainer'\nimport { AssetLoader, AssetLoaderRegistry, LoaderByExtension, LoaderEntry, LoaderFactory } from './AssetLoaderRegistry'\nimport { AssetType } from './AssetType'\nimport { AsyncExecutor, NaiveAsyncExecutor } from './AsyncExecutor'\nimport { HttpClient, HttpOptions, HttpResponse } from './HttpClient'\n\nexport interface LoadContext {\n /**\n * The content loader instance that started the load request.\n */\n content: ContentLoader\n\n /**\n * The base URL to use to resolve asset URLs.\n */\n baseUrl?: string\n\n /**\n * Abort signal to cancel the load request.\n */\n signal?: AbortSignal\n\n /**\n * The type hint for the asset to load. This can be a file extension or a MIME type.\n *\n * @remarks\n * Use this if the type cannot be found from the URL.\n */\n type?: string\n\n /**\n * The intended color space for the currently loaded texture.\n *\n * @remarks\n * This tells the loader which color space to use for the currently loaded texture.\n *\n * Some loaders may ignore this.\n */\n color?: ColorSpace\n\n /**\n *\n */\n crossOrigin?: string\n}\n\nexport type ColorSpace = 'srgb' | 'linear'\nexport type LoadOptions = Omit<LoadContext, 'content'> & {\n /**\n * Index of the asset in the container, default is 0\n *\n * @remarks\n * Only used by {@link ContentLoader.load}, it is not passed on to the load context.\n */\n index?: number\n\n /**\n * The scope that should own the loaded instance\n *\n * @remarks\n * Only used by {@link ContentLoader.load}, it is not passed on to the load context.\n * Loading the same asset in multiple scopes returns the same instance, owned by all of them.\n * Once the instance is finalized, it is removed from the cache and the next load creates a new one.\n */\n scope?: ResourceScope | null\n}\nexport type AssetCreator<Options = any, Instance = any> = (content: ContentLoader, options: Options) => Instance\n\n/**\n * Returns the key under which {@link ContentLoader.load} caches an asset\n */\nexport type AssetCacheKey = (type: AssetType<any, any>, url: string, options?: LoadOptions) => string\n\n/**\n * The default {@link AssetCacheKey}: the url, and the asset index if it is not 0\n */\nexport const defaultAssetCacheKey: AssetCacheKey = (_type, url, options) => {\n return options?.index ? `${url}#${options.index}` : url\n}\n\nexport interface ResolveUriOptions {\n /**\n * The asset whose content references the URI (e.g. the .gltf referencing a texture), if any.\n *\n * @remarks\n * Acts like the document URL of an HTML page: relative URIs resolve against its directory,\n * unless a {@link ResolveUriOptions.baseUri} is given.\n */\n parentUri?: string\n /**\n * Acts like the `<base href>` of an HTML page.\n *\n * @remarks\n * When set, relative URIs resolve against it instead of the {@link ResolveUriOptions.parentUri}.\n * Like `<base href>`, it resolves against its directory (`/foo/` vs `/foo`), root-absolute URIs\n * keep only its origin, and a relative base itself resolves against the `parentUri`.\n */\n baseUri?: string\n}\n\n/**\n * Resolves an asset URI to the URL that is loaded\n */\nexport type UriResolver = (assetUri: string, options: ResolveUriOptions) => string\n\n/**\n * The default {@link UriResolver}: resolves `assetUri` like a browser resolves a link,\n * with `parentUri` as the document URL and `baseUri` as its `<base href>`\n */\nexport const defaultUriResolver: UriResolver = (assetUri, { parentUri, baseUri }) => {\n let base = parentUri || ''\n if (baseUri) {\n const isDirectory = baseUri.endsWith('/')\n base = mergeUri(base, baseUri)\n // mergeUri drops the trailing slash, but it decides which directory the base points to\n if (isDirectory && !base.endsWith('/')) {\n base += '/'\n }\n }\n return mergeUri(base, assetUri)\n}\n\nexport interface ContentLoaderOptions {\n http?: HttpClient\n executor?: AsyncExecutor\n registry?: AssetLoaderRegistry\n disableCache?: boolean\n /**\n * Custom cache key for assets, e.g. to share assets with the same content across urls.\n * Default is {@link defaultAssetCacheKey}\n */\n cacheKey?: AssetCacheKey\n /**\n * Custom URI resolver, e.g. to rewrite or redirect asset URLs.\n * Default is {@link defaultUriResolver}\n */\n resolveUri?: UriResolver\n}\n\nexport class ContentLoader {\n /**\n * Registry for loader types\n */\n public static loaders = new AssetLoaderRegistry()\n\n /**\n * Registers a loader type\n */\n public static registerLoader(descriptor: LoaderEntry | LoaderByExtension): void {\n this.loaders.register(descriptor)\n }\n\n /**\n * Registry for asset creators\n */\n public static creators = new Map<string, AssetCreator<any, any>>()\n\n /**\n * Registers a creator function for all content loaders\n */\n public static registerCreator<O, T>(type: AssetType<O, T>, factory: AssetCreator<O, T>): void {\n this.creators.set(type, factory)\n }\n\n /**\n * The graphics device instance\n */\n public device: Device\n\n /**\n * The http client instance\n */\n public http: HttpClient\n\n /**\n * Loader registry that take precedence over the static {@link ContentLoader.loaders}\n */\n public loaders: AssetLoaderRegistry\n\n /**\n * Async executor used only for leaf I/O tasks.\n *\n * @remarks\n * The default implementation is {@link NaiveAsyncExecutor}.\n * It runs all tasks immediately and does not limit concurrency.\n *\n * Use this executor only for leaf-level operations like\n * - network requests\n * - texture decoding or uploading\n * - GPU upload operations\n *\n * Do NOT use this executor for orchestration tasks like\n * - model loading\n * - material composition\n * - dependency resolution\n *\n * because nested dependency chains can cause deadlocks.\n */\n public executor: AsyncExecutor\n\n /**\n * Registers a loader type\n */\n public registerLoader(descriptor: LoaderEntry | LoaderByExtension): void {\n this.loaders.register(descriptor)\n }\n\n /**\n * Asset creator registry that takes precedence over the static {@link ContentLoader.creators}\n */\n public creators = new Map<string, AssetCreator<any, any>>()\n\n /**\n * Registeres a creator function\n */\n public registerCreator<O, T>(type: AssetType<O, T>, factory: AssetCreator<O, T>) {\n this.creators.set(type, factory)\n }\n\n /**\n * The URI resolver used by {@link ContentLoader.resolveUri}\n *\n * @remarks\n * Replace or wrap it to customize how asset URIs are resolved.\n * Default is {@link defaultUriResolver}\n */\n public uriResolver: UriResolver\n\n /**\n * Resolves an asset URI to the URL that is loaded\n */\n public resolveUri(assetUri: string, options?: ResolveUriOptions): string {\n return this.uriResolver(assetUri, options || {})\n }\n\n /**\n * Number of cached containers and asset instances\n */\n public get cacheStats(): { containers: number; assets: number } {\n let assets = 0\n for (const cache of this.assetCache.values()) {\n assets += cache.size\n }\n return { containers: this.containerCache.size, assets }\n }\n\n protected disableCache = false\n protected containerCache: Map<string, Promise<AssetContainer>> = new Map()\n protected assetCache: Map<string, Map<string, Promise<any>>> = new Map()\n protected cacheKey: AssetCacheKey\n\n public constructor(device: Device, options?: ContentLoaderOptions) {\n this.device = device\n this.http = options?.http || new HttpClient()\n this.loaders = options?.registry || new AssetLoaderRegistry()\n this.executor = options?.executor || new NaiveAsyncExecutor()\n this.disableCache = !!options?.disableCache\n this.cacheKey = options?.cacheKey || defaultAssetCacheKey\n this.uriResolver = options?.resolveUri || defaultUriResolver\n }\n\n public async fetch(url: string, options: HttpOptions<'blob'>): Promise<HttpResponse<Blob>>\n public async fetch(url: string, options: HttpOptions<'arraybuffer'>): Promise<HttpResponse<ArrayBuffer>>\n public async fetch<T = any>(url: string, options: HttpOptions<'json'>): Promise<HttpResponse<T>>\n public async fetch(url: string, options: HttpOptions<'text'>): Promise<HttpResponse<string>>\n public async fetch(url: string, options: HttpOptions<any>): Promise<unknown> {\n return this.executor.run(() => this.http.fetch(url, options), options?.signal)\n }\n\n /**\n * Loads an asset container from the given URL.\n *\n * @remarks\n * Loads asset data from URL. Uses the `url` as cache key.\n * First caller always populates the cache. Repeating calls with\n * different `options.type` don't change the result.\n */\n public async loadContainer(url: string, options?: LoadOptions): Promise<AssetContainer> {\n url = this.resolveUri(url, { baseUri: options?.baseUrl })\n\n if (!this.disableCache && this.containerCache.has(url)) {\n return this.containerCache.get(url)\n }\n\n const promise = this.resolveLoader(url, options?.type).then((loader) => {\n if (!loader) {\n throw new Error(`No loader found for URL: ${url}`)\n }\n\n return loader.load(url, {\n ...(options || {}),\n content: this,\n })\n })\n\n if (!this.disableCache) {\n this.containerCache.set(url, promise)\n }\n\n return promise\n }\n\n /**\n * Loads an asset from the container at the given URL and creates an instance.\n *\n * @remarks\n * Loads the asset at `options.index` (default 0) of the container. The instance is cached,\n * the key is given by the `cacheKey` option of the loader (url and index by default).\n * Repeating calls with the same key return the same instance.\n */\n public async load<T>(type: AssetType<any, T>, url: string, options?: LoadOptions): Promise<T> {\n if (!this.assetCache.has(type)) {\n this.assetCache.set(type, new Map())\n }\n\n const { index, scope, ...context } = options || {}\n const cache = this.assetCache.get(type)\n const key = this.cacheKey(type, url, options)\n if (!this.disableCache && cache.has(key)) {\n return cache.get(key).then((instance) => {\n if (isOwnable(instance) && instance.ownership.isFinalized) {\n // finalized while the request was pending, the entry is evicted by now\n return this.load(type, url, options)\n }\n return ownInstance(instance, scope, this.device)\n })\n }\n\n const promise = this.loadContainer(url, context)\n .then((container): Promise<T> => {\n return container.load(type, index ?? 0, {\n ...context,\n content: this,\n })\n })\n .then((options) => {\n const instance = this.create(type, options)\n if (!this.disableCache && isOwnable(instance)) {\n instance.ownership.onFinalize(() => {\n if (cache.get(key) === promise) {\n cache.delete(key)\n }\n // the container may have released its data after creating the instance, load the file again next time\n this.containerCache.delete(this.resolveUri(url, { baseUri: context.baseUrl }))\n })\n }\n return instance\n })\n\n if (!this.disableCache) {\n cache.set(key, promise)\n }\n\n return promise.then((instance) => ownInstance(instance, scope, this.device))\n }\n\n /**\n * Creates a new asset instance.\n *\n * @remarks\n *\n */\n public create<O, T>(type: AssetType<O, T>, options: O): T {\n const factory = this.findCreator(type)\n if (!factory) {\n throw new Error(`Factory not found for asset type: ${type}`)\n }\n return factory(this, options)\n }\n\n /**\n * Shorthand for `load(AssetType.Texture, options)`\n */\n public async loadTexture(url: string, options?: LoadOptions): Promise<Texture> {\n return this.load(AssetType.Texture, url, options)\n }\n\n /**\n * Shorthand for `load(AssetType.Material, options)`\n */\n public async loadMaterial(url: string, options?: LoadOptions): Promise<Material> {\n return this.load(AssetType.Material, url, options)\n }\n\n /**\n * Shorthand for `load(AssetType.Model, options)`\n */\n public async loadModel(url: string, options?: LoadOptions): Promise<Model> {\n return this.load(AssetType.Model, url, options)\n }\n\n /**\n * Shorthand for `create(AssetType.Model, options)`\n */\n public createModel = (data: ModelOptions): Model => {\n return this.create(AssetType.Model, data)\n }\n\n /**\n * Shorthand for `create(AssetType.Material, options)`\n */\n public createMaterial = (options: Material | MaterialOptions): Material => {\n return this.create(AssetType.Material, options)\n }\n\n /**\n * Shorthand for `create(AssetType.Texture, options)`\n */\n public createTexture = (options: TextureOptions): Texture => {\n return this.create(AssetType.Texture, options)\n }\n\n /**\n * Creates a loader for the given URL.\n *\n * @remarks\n * If no loader can be found from the URL or options, this method sends\n * a HEAD request to the URL. The method then uses the returned content type to try again.\n */\n public async resolveLoader(url: string, type?: string): Promise<AssetLoader> {\n let factory: LoaderFactory = null\n\n if (type) {\n factory = this.findLoader(type)\n }\n\n if (!factory) {\n const ext = extname(url).toLowerCase()\n factory = this.findLoader(ext)\n }\n\n if (!factory) {\n const res = await this.http.fetch(url, { method: 'HEAD' }).catch((err) => {\n // ignore as it's just unable to determine the content type\n // failed request is visible in the network tab\n })\n if (res) {\n factory = this.findLoader(res.contentType)\n }\n }\n\n if (factory) {\n return await factory(this)\n }\n\n throw new Error(`No loader found for URL: ${url} with type: ${type || 'unknown'}`)\n }\n\n protected findLoader(type: string) {\n if (!type) {\n return null\n }\n return this.loaders.find(type) || ContentLoader.loaders.find(type)\n }\n\n protected findCreator(type: AssetType): AssetCreator {\n if (this.creators.has(type)) {\n return this.creators.get(type)\n }\n if (ContentLoader.creators.has(type)) {\n return ContentLoader.creators.get(type)\n }\n switch (type) {\n case AssetType.Material: {\n return createMaterial\n }\n case AssetType.Texture: {\n return createTexture\n }\n case AssetType.Model: {\n return createModel\n }\n }\n return null\n }\n}\n\nexport const createModel: AssetCreator<ModelOptions, Model> = (content: ContentLoader, data: ModelOptions): Model => {\n return new Model(content.device, {\n ...data,\n meshes: data.meshes?.map((mesh) => {\n if (mesh instanceof Mesh) {\n return mesh\n }\n return {\n ...mesh,\n // meshes create (and own) their materials, routed through the creator registry of the content loader\n materials: mesh.materials?.map((it) => {\n if (it instanceof Material) {\n return it\n }\n // the wrapper replaces `factory` on the copy only, `it` keeps its original factory, so this does not recurse\n return { ...it, factory: () => content.create(AssetType.Material, it) }\n }),\n }\n }),\n })\n}\n\nfunction ownInstance<T>(instance: T, scope: ResourceScope | null | undefined, device: Device): T {\n if (!scope || !isOwnable(instance)) {\n return instance\n }\n if (scope.isDisposed) {\n // the scope was disposed while loading, an instance nobody claimed would stay alive with the cache\n if (!instance.ownership.isClaimed) {\n device.scope.drop(instance)\n }\n throw new Error(`scope '${scope.name}' was disposed while loading`)\n }\n return scope.adopt(instance)\n}\n\nexport const createMaterial: AssetCreator<MaterialOptions, Material> = (\n content: ContentLoader,\n options: Material | MaterialOptions,\n): Material => {\n if (!options) {\n throw new Error('Material options are required')\n }\n if (options instanceof Material) {\n return options\n }\n if (options.effect) {\n return new Material(null as any, options)\n }\n if (options.factory) {\n return options.factory(content.device, options)\n }\n return new BasicMaterial(content.device, options)\n}\n\nexport function createTexture(content: ContentLoader, options: TextureOptions): Texture {\n if (isAquirableTextureOptions(options)) {\n return content.device.acquireTexture(options)\n }\n return content.device.createTexture(options)\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentType.d.ts","sourceRoot":"","sources":["../../../src/ContentType.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACI,QAAQ,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACI,SAAS,EAAE,MAAM,CAAA;IAExB;;OAEG;IACI,OAAO,EAAE,MAAM,CAAA;IAEtB;;OAEG;IACI,MAAM,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"ContentType.d.ts","sourceRoot":"","sources":["../../../src/ContentType.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACI,QAAQ,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACI,SAAS,EAAE,MAAM,CAAA;IAExB;;OAEG;IACI,OAAO,EAAE,MAAM,CAAA;IAEtB;;OAEG;IACI,MAAM,CAAC,EAAE,MAAM,CAAA;IAEtB,OAAc,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAQ9C;CACF"}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
// for explanation see:
|
|
2
2
|
// https://www.debuggex.com/
|
|
3
|
-
|
|
3
|
+
const regex = /(([a-z0-9-]+)\/([a-z0-9+-]+))?((;\s*([a-z0-9-]+=)?(([a-z0-9]+)|("[^"]*")))+)?/;
|
|
4
4
|
/**
|
|
5
5
|
* Describes components of a mime type
|
|
6
6
|
*
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ContentType.parse = function (input) {
|
|
13
|
-
var match = regex.exec(input) || [];
|
|
9
|
+
export class ContentType {
|
|
10
|
+
static parse(input) {
|
|
11
|
+
const match = regex.exec(input) || [];
|
|
14
12
|
return match ? {
|
|
15
13
|
mimeType: match[1],
|
|
16
14
|
mediaType: match[2],
|
|
17
15
|
subType: match[3],
|
|
18
16
|
params: (match[4] || ''),
|
|
19
17
|
} : null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
23
|
-
export { ContentType };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
24
20
|
//# sourceMappingURL=ContentType.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentType.js","sourceRoot":"","sources":["../../../src/ContentType.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,4BAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"ContentType.js","sourceRoot":"","sources":["../../../src/ContentType.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,4BAA4B;AAC5B,MAAM,KAAK,GAAG,+EAA+E,CAAA;AAE7F;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAqBf,MAAM,CAAC,KAAK,CAAC,KAAa;QAC/B,MAAM,KAAK,GAAU,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;QAC5C,OAAO,KAAK,CAAC,CAAC,CAAC;YACb,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;YAClB,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;YACnB,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YACjB,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACzB,CAAC,CAAC,CAAC,IAAI,CAAA;IACV,CAAC;CACF","sourcesContent":["// for explanation see:\n// https://www.debuggex.com/\nconst regex = /(([a-z0-9-]+)\\/([a-z0-9+-]+))?((;\\s*([a-z0-9-]+=)?(([a-z0-9]+)|(\"[^\"]*\")))+)?/\n\n/**\n * Describes components of a mime type\n *\n * @public\n */\nexport class ContentType {\n /**\n * The mime type string e.g. text/json\n */\n public mimeType: string\n\n /**\n * The media type of a mime type e.g. 'text'\n */\n public mediaType: string\n\n /**\n * The sub type of a mime type e.g. 'json'\n */\n public subType: string\n\n /**\n * The params of a mime type\n */\n public params?: string\n\n public static parse(input: string): ContentType {\n const match: any[] = regex.exec(input) || []\n return match ? {\n mimeType: match[1],\n mediaType: match[2],\n subType: match[3],\n params: (match[4] || ''),\n } : null\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type ResponseType = 'text' | 'json' | 'arraybuffer' | 'blob';
|
|
2
|
+
export interface HttpOptions<R extends ResponseType = null> {
|
|
3
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
responseType?: R;
|
|
6
|
+
withCredentials?: boolean;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
export interface HttpResponse<T = any> {
|
|
10
|
+
body: T | null;
|
|
11
|
+
status: number;
|
|
12
|
+
statusText: string;
|
|
13
|
+
headers: Headers;
|
|
14
|
+
contentType: string;
|
|
15
|
+
content: Uint8Array | null;
|
|
16
|
+
}
|
|
17
|
+
export declare class HttpClient {
|
|
18
|
+
/**
|
|
19
|
+
* Default headers to be sent with each request
|
|
20
|
+
*/
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* If set, the client will use this cache for requests.
|
|
24
|
+
*/
|
|
25
|
+
cacheName: string;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
cacheOptions: CacheQueryOptions;
|
|
30
|
+
private disposed;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
fetch(url: string, options: HttpOptions<'blob'>): Promise<HttpResponse<Blob>>;
|
|
33
|
+
fetch(url: string, options: HttpOptions<'arraybuffer'>): Promise<HttpResponse<ArrayBuffer>>;
|
|
34
|
+
fetch<T = any>(url: string, options: HttpOptions<'json'>): Promise<HttpResponse<T>>;
|
|
35
|
+
fetch(url: string, options: HttpOptions<'text'>): Promise<HttpResponse<string>>;
|
|
36
|
+
fetch(url: string, options?: HttpOptions): Promise<HttpResponse<unknown>>;
|
|
37
|
+
private request;
|
|
38
|
+
sendRequest(request: Request): Promise<Response>;
|
|
39
|
+
isSuccess(response: Response): boolean;
|
|
40
|
+
createRequestInit(options: HttpOptions<any>): RequestInit;
|
|
41
|
+
read(response: Response, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
|
|
42
|
+
decode(type: ResponseType, content: Uint8Array<ArrayBuffer>, contentType: string): string | ArrayBuffer | Blob | object | null;
|
|
43
|
+
installCache(name: string): void;
|
|
44
|
+
}
|
|
45
|
+
export interface HttpResponse<T> {
|
|
46
|
+
body: T | null;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../src/HttpClient.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,MAAM,CAAA;AACnE,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,YAAY,GAAG,IAAI;IACxD,MAAM,CAAC,EA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E,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/E,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;YAwBxE,OAAO;IAgBd,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEtD;IAEM,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE5C;IAEM,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAsB/D;IAEY,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CA6B5F;IAEM,MAAM,CACX,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,EAChC,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAc7C;IAEM,YAAY,CAAC,IAAI,EAAE,MAAM,QAE/B;CACF;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;CACf"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
export class HttpClient {
|
|
3
|
+
constructor() {
|
|
4
|
+
/**
|
|
5
|
+
* Default headers to be sent with each request
|
|
6
|
+
*/
|
|
7
|
+
this.headers = {};
|
|
8
|
+
this.disposed = false;
|
|
9
|
+
}
|
|
10
|
+
dispose() {
|
|
11
|
+
this.disposed = true;
|
|
12
|
+
}
|
|
13
|
+
fetch(url, options) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
var _a;
|
|
16
|
+
const requestInit = this.createRequestInit(options);
|
|
17
|
+
const request = new Request(url, requestInit);
|
|
18
|
+
const response = yield this.request(request);
|
|
19
|
+
if (!this.isSuccess(response)) {
|
|
20
|
+
throw new Error(`HTTP request failed: ${response.status} ${response.statusText}`);
|
|
21
|
+
}
|
|
22
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
23
|
+
const content = yield this.read(response, options === null || options === void 0 ? void 0 : options.signal);
|
|
24
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
25
|
+
throw new Error('HTTP request was aborted');
|
|
26
|
+
}
|
|
27
|
+
const body = this.decode(options.responseType, content, contentType);
|
|
28
|
+
return {
|
|
29
|
+
body: body,
|
|
30
|
+
status: response.status,
|
|
31
|
+
statusText: response.statusText,
|
|
32
|
+
headers: response.headers,
|
|
33
|
+
contentType: contentType,
|
|
34
|
+
content: content,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
request(request) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!this.cacheName) {
|
|
41
|
+
return this.sendRequest(request);
|
|
42
|
+
}
|
|
43
|
+
const cache = yield caches.open(this.cacheName);
|
|
44
|
+
const cachedResponse = yield cache.match(request, this.cacheOptions);
|
|
45
|
+
if (cachedResponse) {
|
|
46
|
+
return cachedResponse;
|
|
47
|
+
}
|
|
48
|
+
const response = yield this.sendRequest(request);
|
|
49
|
+
if (this.isSuccess(response)) {
|
|
50
|
+
yield cache.put(request, response.clone());
|
|
51
|
+
}
|
|
52
|
+
return response;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
sendRequest(request) {
|
|
56
|
+
return fetch(request);
|
|
57
|
+
}
|
|
58
|
+
isSuccess(response) {
|
|
59
|
+
return response.status >= 200 && response.status < 300;
|
|
60
|
+
}
|
|
61
|
+
createRequestInit(options) {
|
|
62
|
+
const headers = {};
|
|
63
|
+
if (this.headers) {
|
|
64
|
+
for (const key in this.headers) {
|
|
65
|
+
headers[key] = this.headers[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (options.headers) {
|
|
69
|
+
for (const key in options.headers) {
|
|
70
|
+
headers[key] = options.headers[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!('Accept' in headers)) {
|
|
74
|
+
headers['Accept'] = `application/json, text/plain, */*`;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
method: options.method || 'GET',
|
|
78
|
+
headers: headers,
|
|
79
|
+
credentials: options.withCredentials ? 'include' : undefined,
|
|
80
|
+
signal: options.signal,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
read(response, signal) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (!response.body) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const chunks = [];
|
|
89
|
+
const reader = response.body.getReader();
|
|
90
|
+
let receivedLength = 0;
|
|
91
|
+
let canceled = false;
|
|
92
|
+
let done = false;
|
|
93
|
+
while (!done && !canceled) {
|
|
94
|
+
if (this.disposed || (signal === null || signal === void 0 ? void 0 : signal.aborted)) {
|
|
95
|
+
yield reader.cancel();
|
|
96
|
+
canceled = true;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
const chunk = yield reader.read();
|
|
100
|
+
if (chunk.done) {
|
|
101
|
+
done = true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
chunks.push(chunk.value);
|
|
105
|
+
receivedLength += chunk.value.length;
|
|
106
|
+
// TODO: report progress
|
|
107
|
+
}
|
|
108
|
+
return concatChunks(chunks, receivedLength);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
decode(type, content, contentType) {
|
|
112
|
+
switch (type) {
|
|
113
|
+
case 'json': {
|
|
114
|
+
const text = new TextDecoder().decode(content);
|
|
115
|
+
return text === '' ? null : JSON.parse(text);
|
|
116
|
+
}
|
|
117
|
+
case 'text':
|
|
118
|
+
return new TextDecoder().decode(content);
|
|
119
|
+
case 'blob':
|
|
120
|
+
return new Blob([content], { type: contentType });
|
|
121
|
+
case 'arraybuffer':
|
|
122
|
+
return content.buffer;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
installCache(name) {
|
|
127
|
+
caches.open(name);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function concatChunks(chunks, totalLength) {
|
|
131
|
+
const chunksAll = new Uint8Array(totalLength);
|
|
132
|
+
let position = 0;
|
|
133
|
+
for (const chunk of chunks) {
|
|
134
|
+
chunksAll.set(chunk, position);
|
|
135
|
+
position += chunk.length;
|
|
136
|
+
}
|
|
137
|
+
return chunksAll;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=HttpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../../src/HttpClient.ts"],"names":[],"mappings":";AAkBA,MAAM,OAAO,UAAU;IAAvB;QACE;;WAEG;QACI,YAAO,GAA2B,EAAE,CAAA;QAYnC,aAAQ,GAAG,KAAK,CAAA;IAwI1B,CAAC;IAtIQ,OAAO;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;IACtB,CAAC;IAOY,KAAK,CAAC,GAAW,EAAE,OAAyB;;;YACvD,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;YACnD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;YAC7C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAC5C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAA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,CAAC;YACD,KAAK,MAAM;gBACT,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;YAC1C,KAAK,MAAM;gBACT,OAAO,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;YACnD,KAAK,aAAa;gBAChB,OAAO,OAAO,CAAC,MAAM,CAAA;QACzB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,YAAY,CAAC,IAAY;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnB,CAAC;CACF;AAMD,SAAS,YAAY,CAAC,MAAoB,EAAE,WAAmB;IAC7D,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IAC7C,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9B,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAA;IAC1B,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["export type ResponseType = 'text' | 'json' | 'arraybuffer' | 'blob'\nexport interface HttpOptions<R extends ResponseType = null> {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'\n headers?: Record<string, string>\n responseType?: R\n withCredentials?: boolean\n signal?: AbortSignal\n}\n\nexport interface HttpResponse<T = any> {\n body: T | null\n status: number\n statusText: string\n headers: Headers\n contentType: string\n content: Uint8Array | null\n}\n\nexport class HttpClient {\n /**\n * Default headers to be sent with each request\n */\n public headers: Record<string, string> = {}\n\n /**\n * If set, the client will use this cache for requests.\n */\n public cacheName: string\n\n /**\n *\n */\n public cacheOptions: CacheQueryOptions\n\n private disposed = false\n\n public dispose() {\n this.disposed = true\n }\n\n public async fetch(url: string, options: HttpOptions<'blob'>): Promise<HttpResponse<Blob>>\n public async fetch(url: string, options: HttpOptions<'arraybuffer'>): Promise<HttpResponse<ArrayBuffer>>\n public async fetch<T = any>(url: string, options: HttpOptions<'json'>): Promise<HttpResponse<T>>\n public async fetch(url: string, options: HttpOptions<'text'>): Promise<HttpResponse<string>>\n public async fetch(url: string, options?: HttpOptions): Promise<HttpResponse<unknown>>\n public async fetch(url: string, options: HttpOptions<any>): Promise<HttpResponse<unknown>> {\n const requestInit = this.createRequestInit(options)\n const request = new Request(url, requestInit)\n const response = await this.request(request)\n if (!this.isSuccess(response)) {\n throw new Error(`HTTP request failed: ${response.status} ${response.statusText}`)\n }\n const contentType = response.headers.get('Content-Type') || ''\n const content = await this.read(response, options?.signal)\n if (options?.signal?.aborted) {\n throw new Error('HTTP request was aborted')\n }\n const body = this.decode(options.responseType, content, contentType)\n return {\n body: body,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n contentType: contentType,\n content: content,\n }\n }\n\n private async request(request: Request) {\n if (!this.cacheName) {\n return this.sendRequest(request)\n }\n const cache = await caches.open(this.cacheName)\n const cachedResponse = await cache.match(request, this.cacheOptions)\n if (cachedResponse) {\n return cachedResponse\n }\n const response = await this.sendRequest(request)\n if (this.isSuccess(response)) {\n await cache.put(request, response.clone())\n }\n return response\n }\n\n public sendRequest(request: Request): Promise<Response> {\n return fetch(request)\n }\n\n public isSuccess(response: Response): boolean {\n return response.status >= 200 && response.status < 300\n }\n\n public createRequestInit(options: HttpOptions<any>): RequestInit {\n const headers: Record<string, string> = {}\n if (this.headers) {\n for (const key in this.headers) {\n headers[key] = this.headers[key]\n }\n }\n if (options.headers) {\n for (const key in options.headers) {\n headers[key] = options.headers[key]\n }\n }\n if (!('Accept' in headers)) {\n headers['Accept'] = `application/json, text/plain, */*`\n }\n\n return {\n method: options.method || 'GET',\n headers: headers,\n credentials: options.withCredentials ? 'include' : undefined,\n signal: options.signal,\n }\n }\n\n public async read(response: Response, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>> {\n if (!response.body) {\n return null\n }\n const chunks: Uint8Array[] = []\n const reader = response.body.getReader()\n\n let receivedLength = 0\n let canceled = false\n let done = false\n while (!done && !canceled) {\n if (this.disposed || signal?.aborted) {\n await reader.cancel()\n canceled = true\n break\n }\n\n const chunk = await reader.read()\n if (chunk.done) {\n done = true\n break\n }\n\n chunks.push(chunk.value)\n receivedLength += chunk.value.length\n // TODO: report progress\n }\n\n return concatChunks(chunks, receivedLength)\n }\n\n public decode(\n type: ResponseType,\n content: Uint8Array<ArrayBuffer>,\n contentType: string,\n ): string | ArrayBuffer | Blob | object | null {\n switch (type) {\n case 'json': {\n const text = new TextDecoder().decode(content)\n return text === '' ? null : (JSON.parse(text) as object)\n }\n case 'text':\n return new TextDecoder().decode(content)\n case 'blob':\n return new Blob([content], { type: contentType })\n case 'arraybuffer':\n return content.buffer\n }\n return null\n }\n\n public installCache(name: string) {\n caches.open(name)\n }\n}\n\nexport interface HttpResponse<T> {\n body: T | null\n}\n\nfunction concatChunks(chunks: Uint8Array[], totalLength: number) {\n const chunksAll = new Uint8Array(totalLength)\n let position = 0\n for (const chunk of chunks) {\n chunksAll.set(chunk, position)\n position += chunk.length\n }\n return chunksAll\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Device, Material, MaterialOptions } from '@gglib/graphics';
|
|
2
|
+
export type MaterialType = new (device: Device, options: MaterialOptions) => Material;
|
|
3
|
+
export type MaterialMatcher = (asset: MaterialOptions) => boolean;
|
|
4
|
+
export declare class MaterialRegistry {
|
|
5
|
+
private index;
|
|
6
|
+
register(type: MaterialType, match: MaterialMatcher): void;
|
|
7
|
+
register(spec: MaterialFactory): void;
|
|
8
|
+
find(asset: MaterialOptions): MaterialFactory | null;
|
|
9
|
+
}
|
|
10
|
+
export interface MaterialFactory {
|
|
11
|
+
match: MaterialMatcher;
|
|
12
|
+
create: (device: Device, asset: MaterialOptions) => Material;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MaterialRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaterialRegistry.d.ts","sourceRoot":"","sources":["../../../src/MaterialRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEnE,MAAM,MAAM,YAAY,GAAG,KAAK,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,QAAQ,CAAA;AACrF,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAA;AACjE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAAwB;IAE9B,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAAA;IAC1D,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAAA;IAYrC,IAAI,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,GAAG,IAAI,CAO1D;CACF;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,eAAe,CAAA;IACtB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,QAAQ,CAAA;CAC7D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class MaterialRegistry {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.index = [];
|
|
4
|
+
}
|
|
5
|
+
register(spec, match) {
|
|
6
|
+
if (!match) {
|
|
7
|
+
this.index.push(spec);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
this.index.push({
|
|
11
|
+
match,
|
|
12
|
+
create: (device, asset) => new spec(device, asset),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
find(asset) {
|
|
16
|
+
for (const entry of this.index) {
|
|
17
|
+
if (entry.match(asset)) {
|
|
18
|
+
return entry;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=MaterialRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaterialRegistry.js","sourceRoot":"","sources":["../../../src/MaterialRegistry.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,gBAAgB;IAA7B;QACU,UAAK,GAAsB,EAAE,CAAA;IAuBvC,CAAC;IAnBQ,QAAQ,CAAC,IAAoC,EAAE,KAAuB;QAC3E,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAuB,CAAC,CAAA;YACxC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACd,KAAK;YACL,MAAM,EAAE,CAAC,MAAc,EAAE,KAAsB,EAAE,EAAE,CAAC,IAAK,IAAqB,CAAC,MAAM,EAAE,KAAK,CAAC;SAC9F,CAAC,CAAA;IACJ,CAAC;IAEM,IAAI,CAAC,KAAsB;QAChC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { Device, Material, MaterialOptions } from '@gglib/graphics'\n\nexport type MaterialType = new (device: Device, options: MaterialOptions) => Material\nexport type MaterialMatcher = (asset: MaterialOptions) => boolean\nexport class MaterialRegistry {\n private index: MaterialFactory[] = []\n\n public register(type: MaterialType, match: MaterialMatcher): void\n public register(spec: MaterialFactory): void\n public register(spec: MaterialFactory | MaterialType, match?: MaterialMatcher): void {\n if (!match) {\n this.index.push(spec as MaterialFactory)\n return\n }\n this.index.push({\n match,\n create: (device: Device, asset: MaterialOptions) => new (spec as MaterialType)(device, asset),\n })\n }\n\n public find(asset: MaterialOptions): MaterialFactory | null {\n for (const entry of this.index) {\n if (entry.match(asset)) {\n return entry\n }\n }\n return null\n }\n}\n\nexport interface MaterialFactory {\n match: MaterialMatcher\n create: (device: Device, asset: MaterialOptions) => Material\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LoadContext } from './ContentLoader';
|
|
2
|
+
export type ResourceKey = string;
|
|
3
|
+
export type ResourceRef<T> = ResourceKey & {
|
|
4
|
+
__type__: T;
|
|
5
|
+
};
|
|
6
|
+
export type ResourceGetter = <R>(key: ResourceRef<R>) => R;
|
|
7
|
+
export type NotPromise<T> = T extends Promise<any> ? never : T;
|
|
8
|
+
export type ResourceBuilder<T> = (context: LoadContext, node: ResourceNode<T>, get: ResourceGetter) => NotPromise<T>;
|
|
9
|
+
export type ResourceAsyncBuilder<T> = (context: LoadContext, node: ResourceNode<T>, get: ResourceGetter) => Promise<T>;
|
|
10
|
+
export type ResourceNode<T extends NotPromise<any> = {}> = {
|
|
11
|
+
key: ResourceKey;
|
|
12
|
+
data: T;
|
|
13
|
+
deps: ResourceDependency<T, any>[];
|
|
14
|
+
build?: ResourceBuilder<T>;
|
|
15
|
+
buildAsync?: ResourceAsyncBuilder<T>;
|
|
16
|
+
};
|
|
17
|
+
export type ResourceDependency<V = unknown, R = unknown> = {
|
|
18
|
+
ref: ResourceRef<R>;
|
|
19
|
+
assign?: (target: V, dependency: R) => void;
|
|
20
|
+
};
|
|
21
|
+
export declare class ResourceGraph {
|
|
22
|
+
protected readonly graph: Map<string, ResourceNode<any>>;
|
|
23
|
+
protected readonly results: Map<ResourceKey, any>;
|
|
24
|
+
protected readonly inflight: Map<ResourceKey, Promise<any>>;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a resource node with the given key exists in the graph
|
|
27
|
+
*/
|
|
28
|
+
has(key: ResourceKey): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the resource node associated with the given key, or undefined if it does not exist in the graph
|
|
31
|
+
*/
|
|
32
|
+
get<T = unknown>(key: ResourceKey): ResourceNode<T> | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a resource node with the given key and optional data to the graph.
|
|
35
|
+
* The key must be unique within the graph, otherwise an error will be thrown.
|
|
36
|
+
*/
|
|
37
|
+
node<T>(key: ResourceKey, data?: T): ResourceNode<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Adds a dependency from the given node to the given dependency node, with an optional assignment
|
|
40
|
+
* function that will be called with the resolved value of the dependency once it is available.
|
|
41
|
+
*
|
|
42
|
+
* @returns the key of the dependency node for convenience.
|
|
43
|
+
*/
|
|
44
|
+
assign<T, R>(node: ResourceNode<T>, dep: ResourceNode<R>, assign: (target: T, dependency: R) => void): ResourceRef<R>;
|
|
45
|
+
/**
|
|
46
|
+
* Adds a dependency from the given node to the given dependency node without an assignment function.
|
|
47
|
+
* This is useful when the target node will access the dependency's resolved value through the getResult
|
|
48
|
+
* function in its resolve method, rather than having it assigned directly.
|
|
49
|
+
*/
|
|
50
|
+
dependency<T, R>(node: ResourceNode<T>, dep: ResourceNode<R>): ResourceRef<R>;
|
|
51
|
+
getOrderedSubsetForNode<T>(node: ResourceNode<T>): ResourceNode[];
|
|
52
|
+
load<T>(target: ResourceNode<T>, context: LoadContext): Promise<T>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=ResourceGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceGraph.d.ts","sourceRoot":"","sources":["../../../src/ResourceGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAA;AAEhC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,WAAW,GAAG;IAAE,QAAQ,EAAE,CAAC,CAAA;CAAE,CAAA;AAE1D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,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AAG,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAY;IAEvE;;OAEG;IACI,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAEpC;IAED;;OAEG;IACI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAErE;IAED;;;OAGG;IACI,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAW1D;IAED;;;;;OAKG;IACI,MAAM,CAAC,CAAC,EAAE,CAAC,EAChB,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,KAAK,IAAI,GACzC,WAAW,CAAC,CAAC,CAAC,CAOhB;IAED;;;;OAIG;IACI,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAEnF;IAEM,uBAAuB,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,CAGvE;IAEY,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAiF9E;CACF"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
export class ResourceGraph {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.graph = new Map();
|
|
5
|
+
this.results = new Map();
|
|
6
|
+
this.inflight = new Map();
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a resource node with the given key exists in the graph
|
|
10
|
+
*/
|
|
11
|
+
has(key) {
|
|
12
|
+
return this.graph.has(key);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Gets the resource node associated with the given key, or undefined if it does not exist in the graph
|
|
16
|
+
*/
|
|
17
|
+
get(key) {
|
|
18
|
+
return this.graph.get(key);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds a resource node with the given key and optional data to the graph.
|
|
22
|
+
* The key must be unique within the graph, otherwise an error will be thrown.
|
|
23
|
+
*/
|
|
24
|
+
node(key, data) {
|
|
25
|
+
if (this.graph.has(key)) {
|
|
26
|
+
throw new Error(`Resource node with key ${key} already exists in the graph`);
|
|
27
|
+
}
|
|
28
|
+
const node = {
|
|
29
|
+
key,
|
|
30
|
+
data: data,
|
|
31
|
+
deps: [],
|
|
32
|
+
};
|
|
33
|
+
this.graph.set(node.key, node);
|
|
34
|
+
return node;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Adds a dependency from the given node to the given dependency node, with an optional assignment
|
|
38
|
+
* function that will be called with the resolved value of the dependency once it is available.
|
|
39
|
+
*
|
|
40
|
+
* @returns the key of the dependency node for convenience.
|
|
41
|
+
*/
|
|
42
|
+
assign(node, dep, assign) {
|
|
43
|
+
const ref = dep.key;
|
|
44
|
+
node.deps.push({
|
|
45
|
+
ref,
|
|
46
|
+
assign,
|
|
47
|
+
});
|
|
48
|
+
return ref;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adds a dependency from the given node to the given dependency node without an assignment function.
|
|
52
|
+
* This is useful when the target node will access the dependency's resolved value through the getResult
|
|
53
|
+
* function in its resolve method, rather than having it assigned directly.
|
|
54
|
+
*/
|
|
55
|
+
dependency(node, dep) {
|
|
56
|
+
return this.assign(node, dep, null);
|
|
57
|
+
}
|
|
58
|
+
getOrderedSubsetForNode(node) {
|
|
59
|
+
const subset = collectSubset(this.graph, node);
|
|
60
|
+
return toSortedSubset(this.graph, subset);
|
|
61
|
+
}
|
|
62
|
+
load(target, context) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
if (target == null) {
|
|
65
|
+
throw new Error('Target node is null or undefined');
|
|
66
|
+
}
|
|
67
|
+
if (!this.graph.has(target.key)) {
|
|
68
|
+
throw new Error(`Target node with key ${target.key} does not exist in the graph`);
|
|
69
|
+
}
|
|
70
|
+
const graph = this.graph;
|
|
71
|
+
const results = this.results;
|
|
72
|
+
const inflight = this.inflight;
|
|
73
|
+
const executor = context.content.executor;
|
|
74
|
+
const order = this.getOrderedSubsetForNode(target);
|
|
75
|
+
const getResult = (key) => {
|
|
76
|
+
if (results.has(key)) {
|
|
77
|
+
return results.get(key);
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`Dependency ${key} has not been resolved yet`);
|
|
80
|
+
};
|
|
81
|
+
const finalize = (node, value) => {
|
|
82
|
+
for (const dep of node.deps) {
|
|
83
|
+
if (dep.assign) {
|
|
84
|
+
dep.assign(value, results.get(dep.ref));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
results.set(node.key, value);
|
|
88
|
+
};
|
|
89
|
+
for (const node of order) {
|
|
90
|
+
if (results.has(node.key)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (inflight.has(node.key)) {
|
|
94
|
+
// wait for concurrent execution
|
|
95
|
+
yield inflight.get(node.key);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// sanity: all deps must exist in graph
|
|
99
|
+
for (const dep of node.deps) {
|
|
100
|
+
if (!graph.has(dep.ref)) {
|
|
101
|
+
throw new Error(`Node ${node.key} depends on missing ${dep.ref}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!node.build && !node.buildAsync) {
|
|
105
|
+
const result = node.data;
|
|
106
|
+
finalize(node, result);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (node.build) {
|
|
110
|
+
const result = node.build(context, node, getResult);
|
|
111
|
+
if (isThenable(result)) {
|
|
112
|
+
throw new Error(`build function for node ${node.key} returned a Promise, but should return synchronously`);
|
|
113
|
+
}
|
|
114
|
+
finalize(node, result);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// async result - defer assignment until resolution
|
|
118
|
+
const promise = executor.run(() => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const result = yield node.buildAsync(context, node, getResult);
|
|
120
|
+
finalize(node, result);
|
|
121
|
+
}), context.signal);
|
|
122
|
+
inflight.set(node.key, promise);
|
|
123
|
+
try {
|
|
124
|
+
yield promise;
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
inflight.delete(node.key);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return results.get(target.key);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function collectSubset(graph, node) {
|
|
135
|
+
const result = new Set();
|
|
136
|
+
const visit = (key) => {
|
|
137
|
+
if (result.has(key))
|
|
138
|
+
return;
|
|
139
|
+
const node = graph.get(key);
|
|
140
|
+
if (!node) {
|
|
141
|
+
throw new Error(`Missing node: ${key}`);
|
|
142
|
+
}
|
|
143
|
+
result.add(key);
|
|
144
|
+
for (const dep of node.deps) {
|
|
145
|
+
visit(dep.ref);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
visit(node.key);
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
function toSortedSubset(graph, subset) {
|
|
152
|
+
const inDegree = new Map();
|
|
153
|
+
for (const key of subset) {
|
|
154
|
+
inDegree.set(key, 0);
|
|
155
|
+
}
|
|
156
|
+
for (const key of subset) {
|
|
157
|
+
const node = graph.get(key);
|
|
158
|
+
for (const dep of node.deps) {
|
|
159
|
+
if (subset.has(dep.ref)) {
|
|
160
|
+
inDegree.set(key, inDegree.get(key) + 1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const queue = [];
|
|
165
|
+
for (const key of subset) {
|
|
166
|
+
if (inDegree.get(key) === 0) {
|
|
167
|
+
queue.push(graph.get(key));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const order = [];
|
|
171
|
+
while (queue.length) {
|
|
172
|
+
const n = queue.shift();
|
|
173
|
+
order.push(n);
|
|
174
|
+
for (const key of subset) {
|
|
175
|
+
const m = graph.get(key);
|
|
176
|
+
for (const dep of m.deps) {
|
|
177
|
+
if (dep.ref === n.key) {
|
|
178
|
+
const d = inDegree.get(key) - 1;
|
|
179
|
+
inDegree.set(key, d);
|
|
180
|
+
if (d === 0) {
|
|
181
|
+
queue.push(m);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (order.length !== subset.size) {
|
|
188
|
+
throw new Error('Cycle detected in resource graph');
|
|
189
|
+
}
|
|
190
|
+
return order;
|
|
191
|
+
}
|
|
192
|
+
function isThenable(x) {
|
|
193
|
+
return x && typeof x.then === 'function';
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=ResourceGraph.js.map
|