From f5472a3b6cd53a06031d00896dcfff7a356b12c3 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Tue, 11 Jul 2023 20:10:27 -0300 Subject: [PATCH] Remove lib/WebPackage.ts --- src/js/lib/WebPackage.ts | 48 ---------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/js/lib/WebPackage.ts diff --git a/src/js/lib/WebPackage.ts b/src/js/lib/WebPackage.ts deleted file mode 100644 index df3b1d5..0000000 --- a/src/js/lib/WebPackage.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - WebPackage, - PackageSpec, - Package, -} from './WebPackage/types'; -import FontLoader from './WebPackage/FontLoader'; -import ImageLoader from './WebPackage/ImageLoader'; -import CSSLoader from './WebPackage/CSSLoader'; -import ScriptLoader from './WebPackage/ScriptLoader'; -import OtherLoader from './WebPackage/OtherLoader'; - -export default function (pkgspec: PackageSpec): WebPackage { - const self: WebPackage = Object.create(null); - const pkg: Package = { fonts: [], images: [], stylesheets: [], scripts: [], others: [] }; - const { fonts, images, stylesheets, scripts, others, onprogress } = Object.assign({}, pkg, pkgspec); - const total = [...fonts, ...images, ...stylesheets, ...scripts, ...others].length; - - let index = 0; - const reporter = (el: T) => { - index++; - if (onprogress && index <= total) { - onprogress(100 * (index / total)); - } - return el; - }; - - let fetcher: Promise | null = null; - self.fetch = () => { - if (fetcher) { - return fetcher; - } else { - fetcher = FontLoader(fonts, reporter) - .then((fonts: FontFace[]) => pkg.fonts.push(...fonts)) - .then(() => ImageLoader(images, reporter)) - .then((images: HTMLElement[]) => pkg.images.push(...images)) - .then(() => CSSLoader(stylesheets, reporter)) - .then((stylesheets: HTMLElement[]) => pkg.stylesheets.push(...stylesheets)) - .then(() => ScriptLoader(scripts, reporter)) - .then((scripts: HTMLElement[]) => pkg.scripts.push(...scripts)) - .then(() => OtherLoader(others, reporter)) - .then((others: HTMLElement[]) => pkg.others.push(...others)) - .then(() => pkg); - return fetcher; - } - }; - - return self; -}