@remotion/preload 4.0.0-webhook.26 → 4.1.0-alpha1

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.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022 JonnyBurger
1
+ Copyright (c) 2023 JonnyBurger
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { preloadAudio } from './preload-audio';
2
+ export { preloadFont } from './preload-font';
3
+ export { preloadImage } from './preload-image';
2
4
  export { preloadVideo } from './preload-video';
3
5
  export { resolveRedirect } from './resolve-redirect';
package/dist/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRedirect = exports.preloadVideo = exports.preloadAudio = void 0;
3
+ exports.resolveRedirect = exports.preloadVideo = exports.preloadImage = exports.preloadFont = exports.preloadAudio = void 0;
4
4
  var preload_audio_1 = require("./preload-audio");
5
5
  Object.defineProperty(exports, "preloadAudio", { enumerable: true, get: function () { return preload_audio_1.preloadAudio; } });
6
+ var preload_font_1 = require("./preload-font");
7
+ Object.defineProperty(exports, "preloadFont", { enumerable: true, get: function () { return preload_font_1.preloadFont; } });
8
+ var preload_image_1 = require("./preload-image");
9
+ Object.defineProperty(exports, "preloadImage", { enumerable: true, get: function () { return preload_image_1.preloadImage; } });
6
10
  var preload_video_1 = require("./preload-video");
7
11
  Object.defineProperty(exports, "preloadVideo", { enumerable: true, get: function () { return preload_video_1.preloadVideo; } });
8
12
  var resolve_redirect_1 = require("./resolve-redirect");
@@ -0,0 +1,3 @@
1
+ declare const typesAllowed: readonly ["video", "audio", "image", "font"];
2
+ export declare const preloadAsset: (src: string, elemType: (typeof typesAllowed)[number]) => (() => void);
3
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preloadAsset = void 0;
4
+ const resolve_redirect_1 = require("./resolve-redirect");
5
+ const typesAllowed = ['video', 'audio', 'image', 'font'];
6
+ const preloadAsset = (src, elemType) => {
7
+ const apiName = `preload${elemType.charAt(0).toUpperCase() + elemType.slice(1)}`;
8
+ if (typeof document === 'undefined') {
9
+ console.warn(apiName + '() was called outside the browser. Doing nothing.');
10
+ return () => undefined;
11
+ }
12
+ if (!typesAllowed.includes(elemType)) {
13
+ console.warn(apiName + '() Error, elemType not supported. Doing nothing.', elemType);
14
+ return () => undefined;
15
+ }
16
+ const resolved = (0, resolve_redirect_1.resolveRedirect)(src);
17
+ let cancelled = false;
18
+ if (navigator.userAgent.match(/Firefox\//) ||
19
+ elemType === 'image' ||
20
+ elemType === 'font') {
21
+ const link = document.createElement('link');
22
+ link.rel = 'preload';
23
+ link.as = elemType;
24
+ resolved
25
+ .then((realUrl) => {
26
+ if (!cancelled) {
27
+ link.href = realUrl;
28
+ document.head.appendChild(link);
29
+ }
30
+ })
31
+ .catch((err) => {
32
+ console.log(`Failed to preload asset`, err);
33
+ });
34
+ return () => {
35
+ cancelled = true;
36
+ link.remove();
37
+ };
38
+ }
39
+ const elem = document.createElement(elemType);
40
+ elem.preload = 'auto';
41
+ elem.controls = true;
42
+ elem.style.display = 'none';
43
+ resolved
44
+ .then((realUrl) => {
45
+ if (!cancelled) {
46
+ elem.src = realUrl;
47
+ document.body.appendChild(elem);
48
+ }
49
+ })
50
+ .catch((err) => {
51
+ console.log('Failed to preload asset', err);
52
+ });
53
+ return () => {
54
+ cancelled = true;
55
+ elem.remove();
56
+ };
57
+ };
58
+ exports.preloadAsset = preloadAsset;
@@ -1 +1,5 @@
1
+ /**
2
+ * @description Preloads audio in the DOM so that when a audio tag is mounted, it can play immediately.
3
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-audio)
4
+ */
1
5
  export declare const preloadAudio: (src: string) => (() => void);
@@ -1,50 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.preloadAudio = void 0;
4
- const resolve_redirect_1 = require("./resolve-redirect");
4
+ const preload_asset_1 = require("./preload-asset");
5
+ /**
6
+ * @description Preloads audio in the DOM so that when a audio tag is mounted, it can play immediately.
7
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-audio)
8
+ */
5
9
  const preloadAudio = (src) => {
6
- if (typeof document === 'undefined') {
7
- console.warn('preloadAudio() was called outside the browser. Doing nothing.');
8
- return () => undefined;
9
- }
10
- const resolved = (0, resolve_redirect_1.resolveRedirect)(src);
11
- let cancelled = false;
12
- if (navigator.userAgent.match(/Firefox\//)) {
13
- const link = document.createElement('link');
14
- link.rel = 'preload';
15
- link.as = 'audio';
16
- resolved
17
- .then((realUrl) => {
18
- if (!cancelled) {
19
- link.href = realUrl;
20
- document.head.appendChild(link);
21
- }
22
- })
23
- .catch((err) => {
24
- console.log(`Failed to preload audio`, err);
25
- });
26
- return () => {
27
- cancelled = true;
28
- link.remove();
29
- };
30
- }
31
- const vid = document.createElement('audio');
32
- vid.preload = 'auto';
33
- vid.controls = true;
34
- vid.style.display = 'none';
35
- resolved
36
- .then((realUrl) => {
37
- if (!cancelled) {
38
- vid.src = realUrl;
39
- document.body.appendChild(vid);
40
- }
41
- })
42
- .catch((err) => {
43
- console.log('Failed to preload audio', err);
44
- });
45
- return () => {
46
- cancelled = true;
47
- vid.remove();
48
- };
10
+ return (0, preload_asset_1.preloadAsset)(src, 'audio');
49
11
  };
50
12
  exports.preloadAudio = preloadAudio;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description Preloads a font so that when an <Img> tag is mounted, it can display immediately.
3
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-font)
4
+ */
5
+ export declare const preloadFont: (src: string) => (() => void);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preloadFont = void 0;
4
+ const preload_asset_1 = require("./preload-asset");
5
+ /**
6
+ * @description Preloads a font so that when an <Img> tag is mounted, it can display immediately.
7
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-font)
8
+ */
9
+ const preloadFont = (src) => {
10
+ return (0, preload_asset_1.preloadAsset)(src, 'font');
11
+ };
12
+ exports.preloadFont = preloadFont;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description Preloads an image so that when an <Img> tag is mounted, it can display immediately.
3
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-image)
4
+ */
5
+ export declare const preloadImage: (src: string) => (() => void);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preloadImage = void 0;
4
+ const preload_asset_1 = require("./preload-asset");
5
+ /**
6
+ * @description Preloads an image so that when an <Img> tag is mounted, it can display immediately.
7
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-image)
8
+ */
9
+ const preloadImage = (src) => {
10
+ return (0, preload_asset_1.preloadAsset)(src, 'image');
11
+ };
12
+ exports.preloadImage = preloadImage;
@@ -1 +1,5 @@
1
+ /**
2
+ * @description Preloads a video in the DOM so that when a video tag is mounted, it can play immediately.
3
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-video)
4
+ */
1
5
  export declare const preloadVideo: (src: string) => (() => void);
@@ -1,50 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.preloadVideo = void 0;
4
- const resolve_redirect_1 = require("./resolve-redirect");
4
+ const preload_asset_1 = require("./preload-asset");
5
+ /**
6
+ * @description Preloads a video in the DOM so that when a video tag is mounted, it can play immediately.
7
+ * @see [Documentation](https://www.remotion.dev/docs/preload/preload-video)
8
+ */
5
9
  const preloadVideo = (src) => {
6
- if (typeof document === 'undefined') {
7
- console.warn('preloadVideo() was called outside the browser. Doing nothing.');
8
- return () => undefined;
9
- }
10
- const resolved = (0, resolve_redirect_1.resolveRedirect)(src);
11
- let cancelled = false;
12
- if (navigator.userAgent.match(/Firefox\//)) {
13
- const link = document.createElement('link');
14
- link.rel = 'preload';
15
- link.as = 'video';
16
- resolved
17
- .then((realUrl) => {
18
- if (!cancelled) {
19
- link.href = realUrl;
20
- document.head.appendChild(link);
21
- }
22
- })
23
- .catch((err) => {
24
- console.log(`Failed to preload video`, err);
25
- });
26
- return () => {
27
- cancelled = true;
28
- link.remove();
29
- };
30
- }
31
- const vid = document.createElement('video');
32
- vid.preload = 'auto';
33
- vid.controls = true;
34
- vid.style.display = 'none';
35
- resolved
36
- .then((realUrl) => {
37
- if (!cancelled) {
38
- vid.src = realUrl;
39
- document.body.appendChild(vid);
40
- }
41
- })
42
- .catch((err) => {
43
- console.log('Failed to preload video', err);
44
- });
45
- return () => {
46
- cancelled = true;
47
- vid.remove();
48
- };
10
+ return (0, preload_asset_1.preloadAsset)(src, 'video');
49
11
  };
50
12
  exports.preloadVideo = preloadVideo;
@@ -1 +1,5 @@
1
+ /**
2
+ * @description Follows the redirects of a URL (most commonly a remote video or audio) until the final URL is resolved and returns that.
3
+ * @see [Documentation](https://www.remotion.dev/docs/preload/resolve-redirect)
4
+ */
1
5
  export declare const resolveRedirect: (videoOrAudio: string) => Promise<string>;
@@ -1,4 +1,8 @@
1
1
  "use strict";
2
+ /**
3
+ * @description Follows the redirects of a URL (most commonly a remote video or audio) until the final URL is resolved and returns that.
4
+ * @see [Documentation](https://www.remotion.dev/docs/preload/resolve-redirect)
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.resolveRedirect = void 0;
4
8
  const resolveRedirect = async (videoOrAudio) => {
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
1
  {
2
- "name": "@remotion/preload",
3
- "version": "4.0.0-webhook.26+c8e41db11",
4
- "description": "Utility functions for preloading assets in HTML5",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "sideEffects": false,
8
- "scripts": {
9
- "lint": "eslint src --ext ts,tsx",
10
- "watch": "tsc -w",
11
- "build": "tsc -d"
12
- },
13
- "author": "Jonny Burger",
14
- "contributors": [],
15
- "license": "MIT",
16
- "repository": {
17
- "url": "https://github.com/remotion-dev/remotion"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/remotion-dev/remotion/issues"
21
- },
22
- "devDependencies": {
23
- "@jonny/eslint-config": "3.0.266",
24
- "eslint": "8.13.0",
25
- "prettier": "^2.0.5",
26
- "prettier-plugin-organize-imports": "^2.3.4",
27
- "typescript": "^4.5.5"
28
- },
29
- "keywords": [
30
- "remotion",
31
- "preload",
32
- "html5",
33
- "video"
34
- ],
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "gitHead": "c8e41db114d645c5183edbf016a22b733243dce2"
39
- }
2
+ "name": "@remotion/preload",
3
+ "version": "4.1.0-alpha1",
4
+ "description": "Utility functions for preloading assets in HTML5",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "sideEffects": false,
8
+ "author": "Jonny Burger",
9
+ "contributors": [],
10
+ "license": "MIT",
11
+ "repository": {
12
+ "url": "https://github.com/remotion-dev/remotion"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/remotion-dev/remotion/issues"
16
+ },
17
+ "devDependencies": {
18
+ "@jonny/eslint-config": "3.0.266",
19
+ "eslint": "8.42.0",
20
+ "prettier": "^2.7.1",
21
+ "prettier-plugin-organize-imports": "^2.3.4",
22
+ "typescript": "4.9.5"
23
+ },
24
+ "keywords": [
25
+ "remotion",
26
+ "preload",
27
+ "html5",
28
+ "video"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "formatting": "prettier src --check",
35
+ "lint": "eslint src --ext ts,tsx",
36
+ "watch": "tsc -w",
37
+ "build": "tsc -d"
38
+ }
39
+ }
package/.prettierrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- singleQuote: true,
3
- bracketSpacing: false,
4
- useTabs: true,
5
- overrides: [
6
- {
7
- files: ['*.yml'],
8
- options: {
9
- singleQuote: false,
10
- },
11
- },
12
- ],
13
- plugins: [require.resolve('prettier-plugin-organize-imports')],
14
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../tsconfig.settings.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "rootDir": "src",
6
- "outDir": "dist",
7
- "skipLibCheck": true
8
- },
9
- "references": [
10
- {
11
- "path": "../core"
12
- }
13
- ]
14
- }