├── test ├── data │ ├── hud.png │ ├── hud2.png │ ├── hud.json │ └── hud2.json ├── fixtures │ ├── data.js │ └── spritesheetMiddleware.js ├── karma.conf.js └── spec │ ├── Resource.test.js │ ├── Loader.test.js │ └── async.test.js ├── src ├── load_strategies │ ├── AudioLoadStrategy.ts │ ├── VideoLoadStrategy.ts │ ├── AbstractLoadStrategy.ts │ ├── ImageLoadStrategy.ts │ ├── MediaElementLoadStrategy.ts │ └── XhrLoadStrategy.ts ├── index.ts ├── resource_type.ts ├── async │ ├── eachSeries.ts │ └── AsyncQueue.ts ├── utilities.ts ├── bundle.ts ├── Resource.ts └── Loader.ts ├── .editorconfig ├── .gitignore ├── .travis.yml ├── types └── parse-uri.d.ts ├── tsconfig.json ├── LICENSE ├── package.json ├── rollup.config.js ├── CONTRIBUTING.md └── README.md /test/data/hud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/resource-loader/master/test/data/hud.png -------------------------------------------------------------------------------- /test/data/hud2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/resource-loader/master/test/data/hud2.png -------------------------------------------------------------------------------- /src/load_strategies/AudioLoadStrategy.ts: -------------------------------------------------------------------------------- 1 | import { MediaElementLoadStrategy, IMediaElementLoadConfig } from './MediaElementLoadStrategy'; 2 | 3 | export class AudioLoadStrategy extends MediaElementLoadStrategy 4 | { 5 | constructor(config: IMediaElementLoadConfig) 6 | { 7 | super(config, 'audio'); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/load_strategies/VideoLoadStrategy.ts: -------------------------------------------------------------------------------- 1 | import { MediaElementLoadStrategy, IMediaElementLoadConfig } from './MediaElementLoadStrategy'; 2 | 3 | export class VideoLoadStrategy extends MediaElementLoadStrategy 4 | { 5 | constructor(config: IMediaElementLoadConfig) 6 | { 7 | super(config, 'video'); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs. 2 | # More information at http://EditorConfig.org 3 | root = true 4 | 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | indent_style = space 10 | indent_size = 4 11 | 12 | [{package.json,bower.json,*.yml}] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # sublime text files 2 | *.sublime* 3 | *.*~*.TMP 4 | 5 | # temp files 6 | .DS_Store 7 | Thumbs.db 8 | Desktop.ini 9 | npm-debug.log 10 | 11 | # project files 12 | .project 13 | .idea 14 | 15 | # vim swap files 16 | *.sw* 17 | 18 | # emacs temp files 19 | *~ 20 | \#*# 21 | 22 | # project ignores 23 | !.gitkeep 24 | *__temp 25 | *.sqlite 26 | .snyk 27 | .commit 28 | entry-*.js 29 | node_modules/ 30 | dist/ 31 | lib/ 32 | docs/ 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | addons: 4 | firefox: "latest" 5 | 6 | language: node_js 7 | 8 | node_js: 9 | - '10' 10 | - '12' 11 | 12 | branches: 13 | only: 14 | - master 15 | 16 | cache: 17 | directories: 18 | - node_modules 19 | 20 | install: 21 | - npm install 22 | 23 | before_script: 24 | - export DISPLAY=':99.0' 25 | - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & 26 | 27 | script: 28 | - npm test 29 | -------------------------------------------------------------------------------- /test/fixtures/data.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | window.fixtureData = { 4 | url: 'http://localhost/file', 5 | baseUrl: '/base/test/data', 6 | dataUrlGif: 'data:image/gif;base64,R0lGODlhAQABAPAAAP8REf///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', 7 | dataUrlSvg: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPSczMCcgaGVpZ2h0PSczMCc+PGNpcmNsZSBjeD0nMTUnIGN5PScxNScgcj0nMTAnIC8+PC9zdmc+', // eslint-disable-line max-len 8 | dataJson: '[{ "id": 12, "comment": "Hey there" }]', 9 | dataJsonHeaders: { 'Content-Type': 'application/json' }, 10 | }; 11 | -------------------------------------------------------------------------------- /types/parse-uri.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'parse-uri' 2 | { 3 | interface ParsedUri 4 | { 5 | source?: string; 6 | protocol?: string; 7 | authority?: string; 8 | userInfo?: string; 9 | user?: string; 10 | password?: string; 11 | host?: string; 12 | port?: string; 13 | relative?: string; 14 | path?: string; 15 | directory?: string; 16 | file?: string; 17 | query?: string; 18 | anchor?: string; 19 | } 20 | 21 | interface Options 22 | { 23 | strictMode?: boolean; 24 | } 25 | 26 | function parseUri(uri: string, options?: Options): ParsedUri; 27 | export default parseUri; 28 | } 29 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { AbstractLoadStrategy, ILoadConfig } from './load_strategies/AbstractLoadStrategy'; 2 | export { AudioLoadStrategy } from './load_strategies/AudioLoadStrategy'; 3 | export { ImageLoadStrategy, IImageLoadConfig } from './load_strategies/ImageLoadStrategy'; 4 | export { MediaElementLoadStrategy, IMediaElementLoadConfig } from './load_strategies/MediaElementLoadStrategy'; 5 | export { VideoLoadStrategy } from './load_strategies/VideoLoadStrategy'; 6 | export { XhrLoadStrategy , XhrResponseType, IXhrLoadConfig } from './load_strategies/XhrLoadStrategy'; 7 | 8 | export { Loader, IAddOptions } from './Loader'; 9 | export { Resource, IResourceOptions } from './Resource'; 10 | export { ResourceType, ResourceState } from './resource_type'; 11 | -------------------------------------------------------------------------------- /src/resource_type.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Describes the type of data the Resource holds. 3 | */ 4 | export enum ResourceType 5 | { 6 | /** The resource data type is unknown. */ 7 | Unknown, 8 | /** The resource data is an ArrayBuffer. */ 9 | Buffer, 10 | /** The resource data is a Blob. */ 11 | Blob, 12 | /** The resource data is a parsed JSON Object. */ 13 | Json, 14 | /** The resource data is a Document or
element representing parsed XML. */ 15 | Xml, 16 | /** The resource data is an element. */ 17 | Image, 18 | /** The resource data is an