@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContentManager.js","sourceRoot":"","sources":["../../../src/ContentManager.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAe,GAAG,EAAQ,GAAG,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAQ,eAAe,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAWrC,SAAS,SAAS,CAAI,OAAwB,EAAE,GAA0B,EAAE,QAAW;IACrF,IAAI,GAAG,IAAI,OAAO,EAAE;QAClB,OAAO,OAAO,CAAC,GAAG,CAAQ,CAAA;KAC3B;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;GAEG;AACH;IA2DE;;OAEG;IACH,wBAAY,MAAc,EAAE,OAA4B;QAA5B,wBAAA,EAAA,YAA4B;QAxDxD;;;;;WAKG;QACI,eAAU,GAA4B,UAAC,EAAE,IAAK,OAAA,EAAE,EAAF,CAAE,CAAA;QAEvD;;;;;;WAMG;QACI,mBAAc,GAA0C,UAAC,EAAe,IAAK,OAAA,EAAE,EAAF,CAAE,CAAA;QAEtF;;WAEG;QACI,WAAM,GAAiC,UAAC,GAAG;YAChD,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,EAAT,CAAS,CAAC,CAAA;QACxC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;IAEO,0CAAiB,GAAzB,UAA0B,YAAgC;QACxD,IAAI,OAAO,GAAG,YAA2B,CAAA;QACzC,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;YACpC,OAAO,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,CAAA;SAChC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IACH,qBAAC;AAAD,CAAC,AAvUD,IAuUC","sourcesContent":["import { Device } from '@gglib/graphics'\nimport { DataUri, Http, HttpOptions, Log, Type, Uri } from '@gglib/utils'\nimport { ContentType } from './ContentType'\nimport { Data, dataFromElement, dataFromXhr } from './Data'\nimport { Pipeline } from './Pipeline'\nimport { LoaderOutput } from './Loader'\n\n/**\n * @public\n */\nexport interface IManagerOptions {\n enableDomAssets?: boolean\n pipeline?: Pipeline\n}\n\nfunction getOption<T>(options: IManagerOptions, key: keyof IManagerOptions, fallback: T): T {\n if (key in options) {\n return options[key] as any\n }\n return fallback\n}\n\n/**\n * @public\n */\nexport class ContentManager {\n /**\n * The instance of the graphics device\n */\n public device: Device\n\n /**\n * Allows to rewrite a url\n *\n * @remarks\n * Use this to remap a resource uri to another location.\n */\n public rewriteUrl: (url: string) => string = (it) => it\n\n /**\n * Allows to rewrite an http request\n *\n * @remarks\n * Use this to add authentication or header fields to the request.\n * Avoid changing the `url` string.\n */\n public rewriteRequest: (options: HttpOptions) => HttpOptions = (it: HttpOptions) => it\n\n /**\n * Encodes a string to an array buffer\n */\n public encode: (str: string) => ArrayBuffer = (str) => {\n const buf = new ArrayBuffer(str.length * 2)\n const bufView = new Uint8Array(buf)\n for (let i = 0; i < str.length; i++) {\n bufView[i] = str.charCodeAt(i)\n }\n return buf\n }\n\n /**\n * Indicates whether assets embedded in DOM elements are enabled\n */\n public enableDomAssets = true\n\n /**\n * The instance of the loader to use\n */\n public pipeline: Pipeline = Pipeline.default\n\n /**\n * Collection of all loaded assets\n */\n private loaded = new Map<string, any>()\n /**\n * Collection of all ongoing loading promises\n */\n private loading = new Map<string, Promise<any>>()\n\n /**\n * Collection of existing download requests\n */\n private downloads = new Map<string, Map<string, Promise<Data<any>>>>()\n\n /**\n *\n */\n constructor(device: Device, options: IManagerOptions= {}) {\n this.device = device\n this.setup(options)\n }\n\n public setup(options: IManagerOptions) {\n this.enableDomAssets = getOption(options, 'enableDomAssets', this.enableDomAssets)\n this.pipeline = getOption(options, 'pipeline', this.pipeline)\n }\n\n /**\n * Downloads a resource as json\n */\n public async downloadJSON(optionsOrUrl: HttpOptions|string): Promise<Data<{}>> {\n const options = this.createHttpOptions(optionsOrUrl)\n options.xhr = Http.createXMLHttpRequest('json')\n return this.download<{}>(options)\n }\n\n /**\n * Downloads a resource as xml document\n */\n public async downloadDocument(optionsOrUrl: HttpOptions|string): Promise<Data<Document>> {\n const options = this.createHttpOptions(optionsOrUrl)\n options.xhr = Http.createXMLHttpRequest('document')\n return this.download<Document>(options)\n }\n\n /**\n * Downloads a resource as text\n */\n public async downloadText(optionsOrUrl: HttpOptions|string): Promise<Data<string>> {\n const options = this.createHttpOptions(optionsOrUrl)\n options.xhr = Http.createXMLHttpRequest('text')\n return this.download<string>(options)\n }\n\n /**\n * Downloads a resource as `Blob`\n */\n public async downloadBlob(optionsOrUrl: HttpOptions|string): Promise<Data<Blob>> {\n const options = this.createHttpOptions(optionsOrUrl)\n options.xhr = Http.createXMLHttpRequest('blob')\n return this.download<Blob>(options)\n }\n\n /**\n * Downloads a resource as `ArrayBuffer`\n */\n public async downloadArrayBuffer(optionsOrUrl: HttpOptions|string): Promise<Data<ArrayBuffer>> {\n const options = this.createHttpOptions(optionsOrUrl)\n options.xhr = Http.createXMLHttpRequest('arraybuffer')\n return this.download<ArrayBuffer>(options)\n }\n\n /**\n * Downloads data from a remote location.\n *\n * @remarks\n * If dom assets are enabled then an attempt will be made to find a DOM Element matching the following criteria\n * - element has a `type` attribute\n * - element has an `id` attribute with the value of the given url\n *\n * If such DOM Element exists then its textContent is taken as a result\n */\n public async download<T = any>(optionsOrUrl: HttpOptions|string): Promise<Data<T>> {\n let options = this.createHttpOptions(optionsOrUrl)\n if (this.rewriteRequest) {\n options = this.rewriteRequest(options) || options\n }\n const path = options.url\n const type = options.xhr ? options.xhr.responseType || 'text' : 'text'\n\n if (this.downloads.has(type)) {\n if (this.downloads.get(type).has(path)) {\n return this.downloads.get(type).get(path)\n }\n } else {\n this.downloads.set(type, new Map())\n }\n\n return this.downloads\n .get(type)\n .set(path, (async () => {\n if (this.enableDomAssets) {\n const element = document.getElementById(path) || document.getElementById(path.replace(/^[\\/|#]/, ''))\n if (!element || !element.hasAttribute('type')) {\n //\n } else if (type === 'text') {\n return Promise.resolve(dataFromElement(path, element))\n } else if (type === 'json') {\n return Promise.resolve(dataFromElement(path, element, (text) => JSON.parse(text)))\n } else if (type === 'arraybuffer') {\n return Promise.resolve(dataFromElement(path, element, this.encode))\n } else {\n //\n }\n }\n if (this.enableDomAssets && type === 'text') {\n const element = document.getElementById(path) || document.getElementById(path.replace(/^[\\/|#]/, ''))\n if (element && element.hasAttribute('type')) {\n return Promise.resolve(dataFromElement(path, element))\n }\n }\n return Http.request(options)\n .catch((xhr: XMLHttpRequest) => {\n throw new Error(`${xhr.responseURL} ${xhr.statusText} (${xhr.status})`)\n })\n .then(dataFromXhr)\n })())\n .get(path)\n }\n\n /**\n * Loads and instantiates multiple assets\n *\n * @remarks\n * The given batch must be an object where each key identifies the target type e.g. `Model` or `Effect` etc.\n * The result has always the same structure as the given batch but all asset paths are replaced with an asset instance.\n *\n * If the batch value is a string, then that is used as an asset path where the asset is downloaded from.\n *\n * ```ts\n * load({ Model: 'path/to/model.obj' })\n * // => { Model: INSTANCE }\n * ```\n *\n * If the batch value is an array, then each entry is used as an asset path.\n *\n * ```ts\n * load({ Model: ['path/1.obj', 'path/2.obj'] })\n * // => { Model: [INSTANCE1, INSTANCE2] }\n * ```\n *\n * If the batch value is an object, then each entry is used as an asset path.\n *\n * ```ts\n * load({ Model: { foo: 'path/foo.obj' })\n * // => { Model: { foo: INSTANCE } }\n * ```\n *\n */\n public loadBatch(batch: { [key: string]: [string, any] }): Promise<{ [key: string]: any }> {\n let result = {}\n\n const promises: Array<Promise<any>> = []\n let counter = 0\n\n function enqueue(job: Promise<void>) {\n promises.push(job.then(() => {\n counter++\n // TODO: notify\n }))\n }\n\n Object.keys(batch).forEach((key) => {\n const [source, targetType] = batch[key]\n\n enqueue(this.load(source, targetType).then((res) => {\n result[key] = res\n }))\n })\n\n return Promise.all(promises).then(() => result)\n }\n\n /**\n * Checks whether loading from given source is supported.\n *\n * @param src - The source url to load from. This will be passed to `rewriteUrl`.\n * @param targetType - The target asset type or a symbol identifying the target type.\n */\n public canLoad<T = any>(src: string, targetType: LoaderOutput<T>) {\n const remapped = this.rewriteUrl(src)\n if (remapped) {\n src = remapped\n }\n\n if (DataUri.isDataUri(src)) {\n return this.pipeline.canLoad(ContentType.parse(DataUri.parse(src).contentType).mimeType, targetType)\n } else {\n return this.pipeline.canLoad(Uri.ext(src), targetType)\n }\n }\n\n /**\n * Loads and instantiates a single asset\n *\n * @param src - The source url to load from. This will be passed to `rewriteUrl`.\n * @param targetType - The target asset type or a symbol identifying the target type.\n * @param options - Options which will be available in the loading context.\n */\n public async load<T = unknown>(src: string, targetType: LoaderOutput<T>, options: { [key: string]: any } = {}): Promise<T> {\n const requested = Uri.merge(location.pathname, src)\n const remapped = this.rewriteUrl(requested)\n if (requested !== remapped) {\n Log.debug(`[Content.Manager] remap Url ${src} => ${remapped}`)\n src = remapped\n } else {\n src = requested\n }\n\n let key: string\n let group: string\n if (DataUri.isDataUri(src)) {\n const uri = DataUri.parse(src)\n const source = ContentType.parse(uri.contentType).mimeType\n const target = targetType['name'] || targetType.toString()\n key = `${source} => ${target}`\n group = `[Content.Manager] load ${key} (from DataUri '${uri.contentType}')`\n } else {\n const source = src\n const target = targetType['name'] || targetType.toString()\n key = `${source} => ${target}`\n group = `[Content.Manager] load ${key}`\n }\n\n if (this.loading.has(key)) {\n return this.loading.get(key)\n }\n\n if (this.loaded.has(key)) {\n return Promise.resolve(this.loaded.get(key))\n }\n\n Log.group(group)\n const loader = Log.groupEndAsync(() => Pipeline.run({\n manager: this,\n source: src,\n target: targetType,\n options: options,\n pipeline: this.pipeline,\n }))\n return this.loading.set(key, loader).get(key).then((result) => {\n this.loading.delete(key)\n this.loaded.set(key, result)\n return result\n })\n }\n\n /**\n * Unloads all currently loaded assets\n */\n public unload() {\n this.loaded.forEach((value, key) => {\n try {\n if (typeof value.unload === 'function') { value.unload() }\n } catch (e) {\n Log.warn(`[Content.Manager] failed to unload asset at '${key}'`, e)\n }\n })\n this.loaded.clear()\n this.loading.clear()\n // TODO: abort ongoing xhr requests\n this.downloads.forEach((v) => v.clear())\n this.downloads.clear()\n }\n\n private createHttpOptions(optionsOrUrl: HttpOptions|string): HttpOptions {\n let options = optionsOrUrl as HttpOptions\n if (typeof optionsOrUrl === 'string') {\n options = { url: optionsOrUrl }\n }\n return options\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContentType.spec.d.ts","sourceRoot":"","sources":["../../../src/ContentType.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ContentType } from './ContentType';
|
|
2
|
-
describe('ContentType', function () {
|
|
3
|
-
describe('parse', function () {
|
|
4
|
-
it('parses mime type', function () {
|
|
5
|
-
var res = ContentType.parse('text/plain');
|
|
6
|
-
expect(res.mimeType).toBe('text/plain');
|
|
7
|
-
expect(res.mediaType).toBe('text');
|
|
8
|
-
expect(res.subType).toBe('plain');
|
|
9
|
-
expect(res.params).toBe('');
|
|
10
|
-
});
|
|
11
|
-
it('parses params', function () {
|
|
12
|
-
var res = ContentType.parse('text/plain; charset=utf8');
|
|
13
|
-
expect(res.mimeType).toBe('text/plain');
|
|
14
|
-
expect(res.mediaType).toBe('text');
|
|
15
|
-
expect(res.subType).toBe('plain');
|
|
16
|
-
expect(res.params).toBe('; charset=utf8');
|
|
17
|
-
});
|
|
18
|
-
it('parses complex type', function () {
|
|
19
|
-
var res = ContentType.parse('text/plain; charset=utf8; foo="+-,.;:"');
|
|
20
|
-
expect(res.mimeType).toBe('text/plain');
|
|
21
|
-
expect(res.mediaType).toBe('text');
|
|
22
|
-
expect(res.subType).toBe('plain');
|
|
23
|
-
expect(res.params).toBe('; charset=utf8; foo="+-,.;:"');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=ContentType.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContentType.spec.js","sourceRoot":"","sources":["../../../src/ContentType.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,QAAQ,CAAC,aAAa,EAAE;IACtB,QAAQ,CAAC,OAAO,EAAE;QAChB,EAAE,CAAC,kBAAkB,EAAE;YACrB,IAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;YAC3C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YACvC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAClC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACjC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,eAAe,EAAE;YAClB,IAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;YACzD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YACvC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAClC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACjC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,qBAAqB,EAAE;YACxB,IAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAA;YACvE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YACvC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAClC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACjC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { ContentType } from './ContentType'\n\ndescribe('ContentType', () => {\n describe('parse', () => {\n it('parses mime type', () => {\n const res = ContentType.parse('text/plain')\n expect(res.mimeType).toBe('text/plain')\n expect(res.mediaType).toBe('text')\n expect(res.subType).toBe('plain')\n expect(res.params).toBe('')\n })\n\n it('parses params', () => {\n const res = ContentType.parse('text/plain; charset=utf8')\n expect(res.mimeType).toBe('text/plain')\n expect(res.mediaType).toBe('text')\n expect(res.subType).toBe('plain')\n expect(res.params).toBe('; charset=utf8')\n })\n\n it('parses complex type', () => {\n const res = ContentType.parse('text/plain; charset=utf8; foo=\"+-,.;:\"')\n expect(res.mimeType).toBe('text/plain')\n expect(res.mediaType).toBe('text')\n expect(res.subType).toBe('plain')\n expect(res.params).toBe('; charset=utf8; foo=\"+-,.;:\"')\n })\n })\n})\n"]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { DataUri } from '@gglib/utils';
|
|
2
|
-
import { ContentType } from './ContentType';
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface Data<T = string | ArrayBuffer | Blob | Document | any> {
|
|
7
|
-
/**
|
|
8
|
-
* The source url
|
|
9
|
-
*/
|
|
10
|
-
source: string;
|
|
11
|
-
/**
|
|
12
|
-
* The content
|
|
13
|
-
*/
|
|
14
|
-
content: T;
|
|
15
|
-
/**
|
|
16
|
-
* The content type (e.g. application/json)
|
|
17
|
-
*/
|
|
18
|
-
type?: ContentType;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
export declare function dataFromXhr(xhr: XMLHttpRequest): {
|
|
24
|
-
xhr: XMLHttpRequest;
|
|
25
|
-
source: string;
|
|
26
|
-
content: any;
|
|
27
|
-
type: ContentType;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export declare function dataFromUri(uri: DataUri): Data<string>;
|
|
33
|
-
/**
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export declare function dataFromElement<T = string>(path: string, el: Element, convert?: (it: string) => T): Data<T>;
|
|
37
|
-
//# sourceMappingURL=Data.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../../src/Data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE1C;;GAEG;AACJ,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,QAAQ,GAAG,GAAG;IACpE;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,OAAO,EAAE,CAAC,CAAA;IACV;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,cAAc;;;;;EAO9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAMtD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,QAAQ,MAAM,KAAG,CAAc,GAAG,IAAI,CAAC,CAAC,CAAC,CAMtH"}
|
package/dist/content/src/Data.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ContentType } from './ContentType';
|
|
2
|
-
/**
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export function dataFromXhr(xhr) {
|
|
6
|
-
return {
|
|
7
|
-
xhr: xhr,
|
|
8
|
-
source: xhr.responseURL,
|
|
9
|
-
content: xhr.response || xhr.responseText,
|
|
10
|
-
type: ContentType.parse(xhr.getResponseHeader('content-type')),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export function dataFromUri(uri) {
|
|
17
|
-
return {
|
|
18
|
-
source: uri.uri,
|
|
19
|
-
content: uri.data,
|
|
20
|
-
type: ContentType.parse(uri.contentType),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export function dataFromElement(path, el, convert) {
|
|
27
|
-
if (convert === void 0) { convert = function (it) { return it; }; }
|
|
28
|
-
return {
|
|
29
|
-
source: path,
|
|
30
|
-
type: ContentType.parse(el.getAttribute('type')),
|
|
31
|
-
content: convert(el.textContent),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Data.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Data.js","sourceRoot":"","sources":["../../../src/Data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAoB3C;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAmB;IAC7C,OAAO;QACL,GAAG,EAAE,GAAG;QACR,MAAM,EAAE,GAAG,CAAC,WAAW;QACvB,OAAO,EAAE,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,YAAY;QACzC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;KAC/D,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,GAAG;QACf,OAAO,EAAE,GAAG,CAAC,IAAI;QACjB,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;KACzC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAa,IAAY,EAAE,EAAW,EAAE,OAAsC;IAAtC,wBAAA,EAAA,oBAAW,EAAU,IAAQ,OAAA,EAAS,EAAT,CAAS;IAC3G,OAAO;QACL,MAAM,EAAE,IAAI;QACZ,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAChD,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC;KACjC,CAAA;AACH,CAAC","sourcesContent":["import { DataUri } from '@gglib/utils'\nimport { ContentType } from './ContentType'\n\n /**\n * @public\n */\nexport interface Data<T = string | ArrayBuffer | Blob | Document | any> {\n /**\n * The source url\n */\n source: string\n /**\n * The content\n */\n content: T\n /**\n * The content type (e.g. application/json)\n */\n type?: ContentType\n}\n\n/**\n * @public\n */\nexport function dataFromXhr(xhr: XMLHttpRequest) {\n return {\n xhr: xhr,\n source: xhr.responseURL,\n content: xhr.response || xhr.responseText,\n type: ContentType.parse(xhr.getResponseHeader('content-type')),\n }\n}\n\n/**\n * @public\n */\nexport function dataFromUri(uri: DataUri): Data<string> {\n return {\n source: uri.uri,\n content: uri.data,\n type: ContentType.parse(uri.contentType),\n }\n}\n\n/**\n * @public\n */\nexport function dataFromElement<T = string>(path: string, el: Element, convert = (it: string): T => it as any): Data<T> {\n return {\n source: path,\n type: ContentType.parse(el.getAttribute('type')),\n content: convert(el.textContent),\n }\n}\n"]}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Type, AbstractType, TypeToken } from '@gglib/utils';
|
|
2
|
-
import { PipelineContext } from './PipelineContext';
|
|
3
|
-
export declare type LoaderInput<T = unknown> = string | symbol | Type<T> | AbstractType<T> | TypeToken<T>;
|
|
4
|
-
export declare type LoaderOutput<T = unknown> = symbol | Type<T> | AbstractType<T> | TypeToken<T>;
|
|
5
|
-
export declare type LoaderInputs<T = unknown> = LoaderInput<T> | Array<LoaderInput<T>>;
|
|
6
|
-
export declare type LoaderInputType<I extends LoaderInputs> = I extends Type<infer T> ? T : I extends AbstractType<infer T> ? T : I extends TypeToken<infer T> ? T : unknown;
|
|
7
|
-
export declare type LoaderOutputType<O extends LoaderOutput> = O extends LoaderOutput<infer T> ? T : unknown;
|
|
8
|
-
/**
|
|
9
|
-
* A function that transforms an input of type `I` to output of type `O` using context with data type `D`
|
|
10
|
-
*
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export declare type LoaderHandle<I extends LoaderInputs, O extends LoaderOutput> = (input: LoaderInputType<I>, context: PipelineContext<unknown>) => Promise<LoaderOutputType<O>>;
|
|
14
|
-
/**
|
|
15
|
-
* A specification of a loader function declaring its input and output types
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export interface LoaderSpec<Input extends LoaderInputs = any, Output extends LoaderOutput = any> {
|
|
20
|
-
/**
|
|
21
|
-
* The input type or input types that the loader can load from
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* Use strings for file extensions or mime types
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* input: ['.jpg', 'image/jpeg']
|
|
28
|
-
* ```
|
|
29
|
-
* Use symbols for interface types that have no class type at runtime
|
|
30
|
-
* ```ts
|
|
31
|
-
* input: Texture.Options
|
|
32
|
-
* ```
|
|
33
|
-
* Use class types for everything that has an own runtime type
|
|
34
|
-
* ```ts
|
|
35
|
-
* input: HTMLImageElement
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
readonly input: Input;
|
|
39
|
-
/**
|
|
40
|
-
* The output type that the loader can load to
|
|
41
|
-
*
|
|
42
|
-
* @remarks
|
|
43
|
-
* Use symbols for interface types that have no class type at runtime
|
|
44
|
-
* ```ts
|
|
45
|
-
* output: Texture.Options
|
|
46
|
-
* ```
|
|
47
|
-
* Use class types for everything that has an own runtime type
|
|
48
|
-
* ```ts
|
|
49
|
-
* output: HTMLImageElement
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
readonly output: Output;
|
|
53
|
-
/**
|
|
54
|
-
* The loader function
|
|
55
|
-
*/
|
|
56
|
-
readonly handle: LoaderHandle<Input, Output>;
|
|
57
|
-
}
|
|
58
|
-
export declare type Loader<Input, Output> = LoaderSpec<LoaderInputs<Input>, LoaderOutput<Output>>;
|
|
59
|
-
/**
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
|
-
export declare class LoaderEntry<Input extends LoaderInput = any, Output extends LoaderOutput = any> {
|
|
63
|
-
input: Input;
|
|
64
|
-
output: Output;
|
|
65
|
-
handle: LoaderHandle<Input, Output>;
|
|
66
|
-
constructor(input: Input, output: Output, handle: LoaderHandle<Input, Output>);
|
|
67
|
-
toString(): string;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=Loader.d.ts.map
|
|
@@ -1 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C,CAAC,CAAC,CAAC,CAAA;AAEzK;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,KAAK,SAAS,YAAY,GAAG,GAAG,EAAE,MAAM,SAAS,YAAY,GAAG,GAAG;IAC7F;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;CAC7C;AAED,oBAAY,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;AAEzF;;GAEG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,WAAW,GAAG,GAAG,EAAE,MAAM,SAAS,YAAY,GAAG,GAAG;IAEhF,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC;gBAFnC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC;IAKrC,QAAQ;CAGhB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @public
|
|
3
|
-
*/
|
|
4
|
-
var LoaderEntry = /** @class */ (function () {
|
|
5
|
-
function LoaderEntry(input, output, handle) {
|
|
6
|
-
this.input = input;
|
|
7
|
-
this.output = output;
|
|
8
|
-
this.handle = handle;
|
|
9
|
-
}
|
|
10
|
-
LoaderEntry.prototype.toString = function () {
|
|
11
|
-
return this.input.toString() + " => " + this.output.toString();
|
|
12
|
-
};
|
|
13
|
-
return LoaderEntry;
|
|
14
|
-
}());
|
|
15
|
-
export { LoaderEntry };
|
|
16
|
-
//# sourceMappingURL=Loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Loader.js","sourceRoot":"","sources":["../../../src/Loader.ts"],"names":[],"mappings":"AAmEA;;GAEG;AACH;IACE,qBACS,KAAY,EACZ,MAAc,EACd,MAAmC;QAFnC,UAAK,GAAL,KAAK,CAAO;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAA6B;IAG5C,CAAC;IAEM,8BAAQ,GAAf;QACE,OAAU,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,YAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAI,CAAA;IAChE,CAAC;IACH,kBAAC;AAAD,CAAC,AAZD,IAYC","sourcesContent":["import { Type, AbstractType, TypeToken } from '@gglib/utils'\nimport { PipelineContext } from './PipelineContext'\n\nexport type LoaderInput<T = unknown> = string | symbol | Type<T> | AbstractType<T> | TypeToken<T>\nexport type LoaderOutput<T = unknown> = symbol | Type<T> | AbstractType<T> | TypeToken<T>\nexport type LoaderInputs<T = unknown> = LoaderInput<T> | Array<LoaderInput<T>>\n\nexport type LoaderInputType<I extends LoaderInputs> =\n I extends Type<infer T> ? T :\n I extends AbstractType<infer T> ? T :\n I extends TypeToken<infer T> ? T : unknown\nexport type LoaderOutputType<O extends LoaderOutput> = O extends LoaderOutput<infer T> ? T : unknown\n\n/**\n * A function that transforms an input of type `I` to output of type `O` using context with data type `D`\n *\n * @public\n */\nexport type LoaderHandle<I extends LoaderInputs, O extends LoaderOutput> = (input: LoaderInputType<I>, context: PipelineContext<unknown>) => Promise<LoaderOutputType<O>>\n\n/**\n * A specification of a loader function declaring its input and output types\n *\n * @public\n */\nexport interface LoaderSpec<Input extends LoaderInputs = any, Output extends LoaderOutput = any> {\n /**\n * The input type or input types that the loader can load from\n *\n * @remarks\n * Use strings for file extensions or mime types\n *\n * ```ts\n * input: ['.jpg', 'image/jpeg']\n * ```\n * Use symbols for interface types that have no class type at runtime\n * ```ts\n * input: Texture.Options\n * ```\n * Use class types for everything that has an own runtime type\n * ```ts\n * input: HTMLImageElement\n * ```\n */\n readonly input: Input\n /**\n * The output type that the loader can load to\n *\n * @remarks\n * Use symbols for interface types that have no class type at runtime\n * ```ts\n * output: Texture.Options\n * ```\n * Use class types for everything that has an own runtime type\n * ```ts\n * output: HTMLImageElement\n * ```\n */\n readonly output: Output\n /**\n * The loader function\n */\n readonly handle: LoaderHandle<Input, Output>\n}\n\nexport type Loader<Input, Output> = LoaderSpec<LoaderInputs<Input>, LoaderOutput<Output>>\n\n/**\n * @public\n */\nexport class LoaderEntry<Input extends LoaderInput = any, Output extends LoaderOutput = any> {\n public constructor(\n public input: Input,\n public output: Output,\n public handle: LoaderHandle<Input, Output>,\n ) {\n\n }\n\n public toString() {\n return `${this.input.toString()} => ${this.output.toString()}`\n }\n}\n"]}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { LoaderSpec, LoaderInput, LoaderOutput } from './Loader';
|
|
2
|
-
import { PipelineContext } from './PipelineContext';
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export declare class Pipeline {
|
|
7
|
-
/**
|
|
8
|
-
* Returns the default pipeline instance
|
|
9
|
-
*/
|
|
10
|
-
static get default(): Pipeline;
|
|
11
|
-
private loaders;
|
|
12
|
-
static run(context: PipelineContext): Promise<any>;
|
|
13
|
-
/**
|
|
14
|
-
* Registeres a loader function
|
|
15
|
-
*
|
|
16
|
-
* @param loader - The loader specification
|
|
17
|
-
*/
|
|
18
|
-
register(loader: LoaderSpec): void;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param source - The source type or symbol identifying the input type
|
|
22
|
-
* @param target - The target type or symbol identifying the target type
|
|
23
|
-
* @param input - The input value to import. Its type is identified by `source`
|
|
24
|
-
* @param context - The context to use during the import
|
|
25
|
-
*/
|
|
26
|
-
run<S = unknown, T = unknown>(source: LoaderInput<S>, target: LoaderOutput<T>, input: any, context: PipelineContext): Promise<T>;
|
|
27
|
-
graph(source: LoaderInput, target: LoaderOutput, input: any, context: PipelineContext): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Detects whether there is a loding path from `source` type to the `target` type
|
|
30
|
-
*
|
|
31
|
-
* @param source - The source type or symbol identifying the input type
|
|
32
|
-
* @param target - The target type or symbol identifying the target type
|
|
33
|
-
*/
|
|
34
|
-
canLoad(source: LoaderInput, target: LoaderOutput): boolean;
|
|
35
|
-
private resolve;
|
|
36
|
-
private walk;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=Pipeline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Pipeline.d.ts","sourceRoot":"","sources":["../../../src/Pipeline.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAuBnD;;GAEG;AACH,qBAAa,QAAQ;IACnB;;OAEG;IACH,WAAkB,OAAO,aAKxB;IAED,OAAO,CAAC,OAAO,CAAoB;WAEf,GAAG,CAAC,OAAO,EAAE,eAAe;IAIhD;;;;OAIG;IACI,QAAQ,CAAC,MAAM,EAAE,UAAU;IAalC;;;;;;OAMG;IACU,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;IAiBhI,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe;IAIlG;;;;;OAKG;IACI,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO;IAIlE,OAAO,CAAC,OAAO;YAwBD,IAAI;CAkBnB"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { __awaiter, __generator } from "tslib";
|
|
2
|
-
import { DataUri, Log, Uri } from '@gglib/utils';
|
|
3
|
-
import { ContentType } from './ContentType';
|
|
4
|
-
import { LoaderEntry } from './Loader';
|
|
5
|
-
function describeSym(sym) {
|
|
6
|
-
if (!sym) {
|
|
7
|
-
return "" + sym;
|
|
8
|
-
}
|
|
9
|
-
if (sym['name']) {
|
|
10
|
-
return sym['name'];
|
|
11
|
-
}
|
|
12
|
-
return sym.toString();
|
|
13
|
-
}
|
|
14
|
-
function warn(msg) {
|
|
15
|
-
Log.warn('[Content.Loader] ' + msg);
|
|
16
|
-
}
|
|
17
|
-
var defaultPipeline;
|
|
18
|
-
/**
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
var Pipeline = /** @class */ (function () {
|
|
22
|
-
function Pipeline() {
|
|
23
|
-
this.loaders = [];
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(Pipeline, "default", {
|
|
26
|
-
/**
|
|
27
|
-
* Returns the default pipeline instance
|
|
28
|
-
*/
|
|
29
|
-
get: function () {
|
|
30
|
-
if (defaultPipeline == null) {
|
|
31
|
-
defaultPipeline = new Pipeline();
|
|
32
|
-
}
|
|
33
|
-
return defaultPipeline;
|
|
34
|
-
},
|
|
35
|
-
enumerable: false,
|
|
36
|
-
configurable: true
|
|
37
|
-
});
|
|
38
|
-
Pipeline.run = function (context) {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
-
return __generator(this, function (_a) {
|
|
41
|
-
return [2 /*return*/, context.pipeline.run(context.source, context.target, null, context)];
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Registeres a loader function
|
|
47
|
-
*
|
|
48
|
-
* @param loader - The loader specification
|
|
49
|
-
*/
|
|
50
|
-
Pipeline.prototype.register = function (loader) {
|
|
51
|
-
var _this = this;
|
|
52
|
-
var inputs = Array.isArray(loader.input) ? loader.input : [loader.input];
|
|
53
|
-
inputs.forEach(function (input) {
|
|
54
|
-
for (var _i = 0, _a = _this.loaders; _i < _a.length; _i++) {
|
|
55
|
-
var entry = _a[_i];
|
|
56
|
-
if (entry.handle === loader.handle && entry.input === input && entry.output === loader.output) {
|
|
57
|
-
warn("same loader was registered twice... loader is skipped. " + entry.toString());
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
_this.loaders.push(new LoaderEntry(input, loader.output, loader.handle));
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @param source - The source type or symbol identifying the input type
|
|
67
|
-
* @param target - The target type or symbol identifying the target type
|
|
68
|
-
* @param input - The input value to import. Its type is identified by `source`
|
|
69
|
-
* @param context - The context to use during the import
|
|
70
|
-
*/
|
|
71
|
-
Pipeline.prototype.run = function (source, target, input, context) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
var pipeline;
|
|
74
|
-
return __generator(this, function (_a) {
|
|
75
|
-
if (typeof source === 'string') {
|
|
76
|
-
if (DataUri.isDataUri(source)) {
|
|
77
|
-
source = ContentType.parse(DataUri.parse(source).contentType).mimeType;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
source = Uri.ext(source);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
pipeline = this.resolve(source, target);
|
|
84
|
-
if (pipeline.length === 0) {
|
|
85
|
-
throw new Error("Loader is missing: " + describeSym(source) + " => " + describeSym(target));
|
|
86
|
-
}
|
|
87
|
-
return [2 /*return*/, this.walk(pipeline, input, context)];
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
Pipeline.prototype.graph = function (source, target, input, context) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Detects whether there is a loding path from `source` type to the `target` type
|
|
100
|
-
*
|
|
101
|
-
* @param source - The source type or symbol identifying the input type
|
|
102
|
-
* @param target - The target type or symbol identifying the target type
|
|
103
|
-
*/
|
|
104
|
-
Pipeline.prototype.canLoad = function (source, target) {
|
|
105
|
-
return this.resolve(source, target).length > 0;
|
|
106
|
-
};
|
|
107
|
-
Pipeline.prototype.resolve = function (source, target, exclude) {
|
|
108
|
-
var _this = this;
|
|
109
|
-
if (exclude === void 0) { exclude = []; }
|
|
110
|
-
var candidates = this.loaders.filter(function (it) { return exclude.indexOf(it) === -1 && it.input === source; });
|
|
111
|
-
exclude.push.apply(exclude, candidates);
|
|
112
|
-
return candidates.map(function (it) {
|
|
113
|
-
if (it.output === target) {
|
|
114
|
-
return {
|
|
115
|
-
entry: it,
|
|
116
|
-
next: [],
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
var next = _this.resolve(it.output, target, exclude);
|
|
120
|
-
return next && next.length ? {
|
|
121
|
-
entry: it,
|
|
122
|
-
next: next,
|
|
123
|
-
} : null;
|
|
124
|
-
})
|
|
125
|
-
.filter(function (it) { return it != null; })
|
|
126
|
-
.sort(function (a, b) { return a.next.length <= b.next.length ? -1 : 1; });
|
|
127
|
-
};
|
|
128
|
-
Pipeline.prototype.walk = function (nodes, input, context, depth) {
|
|
129
|
-
if (depth === void 0) { depth = 1; }
|
|
130
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
-
var _loop_1, this_1, i, state_1;
|
|
132
|
-
return __generator(this, function (_a) {
|
|
133
|
-
switch (_a.label) {
|
|
134
|
-
case 0:
|
|
135
|
-
if (nodes.length === 0) {
|
|
136
|
-
// finish recursion
|
|
137
|
-
return [2 /*return*/, input];
|
|
138
|
-
}
|
|
139
|
-
_loop_1 = function (i) {
|
|
140
|
-
var node, loaded, result;
|
|
141
|
-
return __generator(this, function (_b) {
|
|
142
|
-
switch (_b.label) {
|
|
143
|
-
case 0:
|
|
144
|
-
node = nodes[i];
|
|
145
|
-
context.pipeline = this_1;
|
|
146
|
-
Log.group("stage:" + depth + " (" + (i + 1) + ") " + describeSym(node.entry.input) + " => " + describeSym(node.entry.output));
|
|
147
|
-
return [4 /*yield*/, Log.groupEndAsync(function () { return node.entry.handle(input, context); })];
|
|
148
|
-
case 1:
|
|
149
|
-
loaded = _b.sent();
|
|
150
|
-
return [4 /*yield*/, this_1.walk(node.next, loaded, context, depth + 1)];
|
|
151
|
-
case 2:
|
|
152
|
-
result = _b.sent();
|
|
153
|
-
if (result) {
|
|
154
|
-
return [2 /*return*/, { value: result }];
|
|
155
|
-
}
|
|
156
|
-
return [2 /*return*/];
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
this_1 = this;
|
|
161
|
-
i = 0;
|
|
162
|
-
_a.label = 1;
|
|
163
|
-
case 1:
|
|
164
|
-
if (!(i < nodes.length)) return [3 /*break*/, 4];
|
|
165
|
-
return [5 /*yield**/, _loop_1(i)];
|
|
166
|
-
case 2:
|
|
167
|
-
state_1 = _a.sent();
|
|
168
|
-
if (typeof state_1 === "object")
|
|
169
|
-
return [2 /*return*/, state_1.value];
|
|
170
|
-
_a.label = 3;
|
|
171
|
-
case 3:
|
|
172
|
-
i++;
|
|
173
|
-
return [3 /*break*/, 1];
|
|
174
|
-
case 4: return [2 /*return*/, null];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
return Pipeline;
|
|
180
|
-
}());
|
|
181
|
-
export { Pipeline };
|
|
182
|
-
//# sourceMappingURL=Pipeline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Pipeline.js","sourceRoot":"","sources":["../../../src/Pipeline.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE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} from './Loader'\nimport { PipelineContext } from './PipelineContext'\n\ninterface Node {\n entry: LoaderEntry\n next: Node[]\n}\n\nfunction describeSym(sym: any) {\n if (!sym) {\n return `${sym}`\n }\n if (sym['name']) {\n return sym['name']\n }\n return sym.toString()\n}\n\nfunction warn(msg: string) {\n Log.warn('[Content.Loader] ' + msg)\n}\n\nlet defaultPipeline: Pipeline\n\n/**\n * @public\n */\nexport class Pipeline {\n /**\n * Returns the default pipeline instance\n */\n public static get default() {\n if (defaultPipeline == null) {\n defaultPipeline = new Pipeline()\n }\n return defaultPipeline\n }\n\n private loaders: LoaderEntry[] = []\n\n public static async run(context: PipelineContext) {\n return context.pipeline.run(context.source, context.target, null, context)\n }\n\n /**\n * Registeres a loader function\n *\n * @param loader - The loader specification\n */\n public register(loader: LoaderSpec) {\n const inputs = Array.isArray(loader.input) ? loader.input : [loader.input]\n inputs.forEach((input) => {\n for (const entry of this.loaders) {\n if (entry.handle === loader.handle && entry.input === input && entry.output === loader.output) {\n warn(`same loader was registered twice... loader is skipped. ${entry.toString()}`)\n return\n }\n }\n this.loaders.push(new LoaderEntry(input, loader.output, loader.handle))\n })\n }\n\n /**\n *\n * @param source - The source type or symbol identifying the input type\n * @param target - The target type or symbol identifying the target type\n * @param input - The input value to import. Its type is identified by `source`\n * @param context - The context to use during the import\n */\n public async run<S = unknown, T = unknown>(source: LoaderInput<S>, target: LoaderOutput<T>, input: any, context: PipelineContext): Promise<T> {\n\n if (typeof source === 'string') {\n if (DataUri.isDataUri(source)) {\n source = ContentType.parse(DataUri.parse(source).contentType).mimeType\n } else {\n source = Uri.ext(source)\n }\n }\n\n const pipeline = this.resolve(source, target)\n if (pipeline.length === 0) {\n throw new Error(`Loader is missing: ${describeSym(source)} => ${describeSym(target)}`)\n }\n return this.walk(pipeline, input, context)\n }\n\n public async graph(source: LoaderInput, target: LoaderOutput, input: any, context: PipelineContext) {\n\n }\n\n /**\n * Detects whether there is a loding path from `source` type to the `target` type\n *\n * @param source - The source type or symbol identifying the input type\n * @param target - The target type or symbol identifying the target type\n */\n public canLoad(source: LoaderInput, target: LoaderOutput): boolean {\n return this.resolve(source, target).length > 0\n }\n\n private resolve(\n source: LoaderInput,\n target: LoaderOutput,\n exclude: LoaderEntry[] = [],\n ): Node[] {\n const candidates = this.loaders.filter((it) => exclude.indexOf(it) === -1 && it.input === source)\n exclude.push(...candidates)\n return candidates.map((it) => {\n if (it.output === target) {\n return {\n entry: it,\n next: [],\n }\n }\n const next = this.resolve(it.output, target, exclude)\n return next && next.length ? {\n entry: it,\n next: next,\n } : null\n })\n .filter((it) => it != null)\n .sort((a, b) => a.next.length <= b.next.length ? -1 : 1)\n }\n\n private async walk<T>(nodes: Node[], input: any, context: PipelineContext<T>, depth: number = 1) {\n if (nodes.length === 0) {\n // finish recursion\n return input\n }\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i]\n context.pipeline = this\n\n Log.group(`stage:${depth} (${i + 1}) ${describeSym(node.entry.input)} => ${describeSym(node.entry.output)}`)\n const loaded = await Log.groupEndAsync(() => node.entry.handle(input, context))\n const result: T = await this.walk(node.next, loaded, context, depth + 1)\n if (result) {\n return result\n }\n }\n return null\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Pipeline.spec.d.ts","sourceRoot":"","sources":["../../../src/Pipeline.spec.ts"],"names":[],"mappings":""}
|