@thi.ng/dl-asset 2.1.0 → 2.3.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/CHANGELOG.md CHANGED
@@ -1,80 +1,88 @@
1
1
  # Change Log
2
2
 
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/dl-asset@2.0.7...@thi.ng/dl-asset@2.1.0) (2021-11-10)
7
-
8
-
9
- ### Features
10
-
11
- * **dl-asset:** add downloadCanvas() ([ca657d4](https://github.com/thi-ng/umbrella/commit/ca657d400d40a4b1fba9f60b62069945dc3cf333))
12
-
13
-
14
-
15
-
16
-
17
- ## [2.0.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/dl-asset@2.0.6...@thi.ng/dl-asset@2.0.7) (2021-11-03)
18
-
19
- **Note:** Version bump only for package @thi.ng/dl-asset
20
-
21
-
22
-
23
-
24
-
25
- # [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/dl-asset@1.0.5...@thi.ng/dl-asset@2.0.0) (2021-10-12)
3
+ - **Last updated**: 2021-12-13T10:26:00Z
4
+ - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
26
5
 
6
+ All notable changes to this project will be documented in this file.
7
+ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelines.
27
8
 
28
- ### Build System
9
+ **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
+ and/or version bumps of transitive dependencies.
29
11
 
30
- * major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea9fab2a645d6c5f2bf2591459b939c09b6))
12
+ ## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.3.0) (2021-12-13)
31
13
 
14
+ #### 🚀 Features
32
15
 
33
- ### BREAKING CHANGES
16
+ - add canvasVideoRecorder() ([6736463](https://github.com/thi-ng/umbrella/commit/6736463))
34
17
 
35
- * discontinue CommonJS & UMD versions
18
+ ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.2.0) (2021-11-17)
36
19
 
37
- - only ESM modules will be published from now on
38
- - CJS obsolete due to ESM support in recent versions of node:
39
- - i.e. launch NodeJS via:
40
- - `node --experimental-specifier-resolution=node --experimental-repl-await`
41
- - in the node REPL use `await import(...)` instead of `require()`
42
- - UMD obsolete due to widespread browser support for ESM
20
+ #### 🚀 Features
43
21
 
44
- Also:
45
- - normalize/restructure/reorg all package.json files
46
- - cleanup all build scripts, remove obsolete
47
- - switch from mocha to @thi.ng/testament for all tests
22
+ - Using workspaces for local tools ([bf7a404](https://github.com/thi-ng/umbrella/commit/bf7a404))
23
+ Improving the overall build ergonomics
24
+ - introduced a tools workspaces
25
+ - imported it in all needed packages/examples
26
+ - inclusive project root
48
27
 
28
+ #### ♻️ Refactoring
49
29
 
30
+ - testrunner to binary ([4ebbbb2](https://github.com/thi-ng/umbrella/commit/4ebbbb2))
31
+ this commit reverts (partly) changes made in:
32
+ ef346d7a8753590dc9094108a3d861a8dbd5dd2c
33
+ overall purpose is better testament ergonomics:
34
+ instead of having to pass NODE_OPTIONS with every invocation
35
+ having a binary to handle this for us.
50
36
 
37
+ ## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.1.0) (2021-11-10)
51
38
 
39
+ #### 🚀 Features
52
40
 
41
+ - add downloadCanvas() ([ca657d4](https://github.com/thi-ng/umbrella/commit/ca657d4))
53
42
 
54
- ## [1.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/dl-asset@1.0.4...@thi.ng/dl-asset@1.0.5) (2021-09-03)
43
+ ### [2.0.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.0.1) (2021-10-13)
55
44
 
56
- **Note:** Version bump only for package @thi.ng/dl-asset
45
+ #### ♻️ Refactoring
57
46
 
58
- # [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/dl-asset@0.3.14...@thi.ng/dl-asset@0.4.0) (2020-07-08)
47
+ - update imports in all tests/pkgs ([effd591](https://github.com/thi-ng/umbrella/commit/effd591))
48
+ - update imports in all pkgs ([5fa2b6f](https://github.com/thi-ng/umbrella/commit/5fa2b6f))
49
+ - add .js suffix for all relative imports
59
50
 
60
- ### Features
51
+ # [2.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.0.0) (2021-10-12)
61
52
 
62
- - **dl-asset:** split src, extract `downloadWithMime()` ([d749819](https://github.com/thi-ng/umbrella/commit/d74981963ce4bfbfe3465c71085995173826329c))
53
+ #### 🛑 Breaking changes
63
54
 
64
- # 0.3.0 (2020-02-26)
55
+ - major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea))
56
+ - BREAKING CHANGE: discontinue CommonJS & UMD versions
57
+ - only ESM modules will be published from now on
58
+ - CJS obsolete due to ESM support in recent versions of node:
59
+ - i.e. launch NodeJS via:
60
+ - `node --experimental-specifier-resolution=node --experimental-repl-await`
61
+ - in the node REPL use `await import(...)` instead of `require()`
62
+ - UMD obsolete due to widespread browser support for ESM
63
+ Also:
64
+ - normalize/restructure/reorg all package.json files
65
+ - cleanup all build scripts, remove obsolete
66
+ - switch from mocha to [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament) for all tests
65
67
 
66
- ### Features
68
+ #### ♻️ Refactoring
67
69
 
68
- - **dl-asset:** yet another npm forced pkg rename ([2cae33c](https://github.com/thi-ng/umbrella/commit/2cae33cabd379b3d449079edfc255d9cf56c34a5))
70
+ - update imports ([29a7681](https://github.com/thi-ng/umbrella/commit/29a7681))
71
+ - update all test stubs ([f2d6d53](https://github.com/thi-ng/umbrella/commit/f2d6d53))
72
+ - update all tests in _all_ pkgs ([8b582bc](https://github.com/thi-ng/umbrella/commit/8b582bc))
73
+ - update all to use [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament)
69
74
 
70
- # 0.2.0 (2020-02-26)
75
+ ## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@0.4.0) (2020-07-08)
71
76
 
72
- ### Features
77
+ #### 🚀 Features
73
78
 
74
- - **download-asset:** rename pkg due to npm name conflict ([b490b46](https://github.com/thi-ng/umbrella/commit/b490b46994333103f653514c96531637d903202d))
79
+ - split src, extract `downloadWithMime()` ([d749819](https://github.com/thi-ng/umbrella/commit/d749819))
80
+ - new fn improves tree shaking and can avoid inclusion of [@thi.ng/mime](https://github.com/thi-ng/umbrella/tree/main/packages/mime)
81
+ if mime type is explicitly provided by user
75
82
 
76
- # 0.1.0 (2020-02-25)
83
+ ## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@0.3.0) (2020-02-26)
77
84
 
78
- ### Features
85
+ #### 🚀 Features
79
86
 
80
- - **download:** import as new pkg ([26caaaa](https://github.com/thi-ng/umbrella/commit/26caaaadf6c3f7b6bb83e8a4160a91b7e2db8714))
87
+ - yet another npm forced pkg rename ([2cae33c](https://github.com/thi-ng/umbrella/commit/2cae33c))
88
+ - https://twitter.com/thing_umbrella/status/1232461386917257217
package/api.d.ts CHANGED
@@ -21,4 +21,15 @@ export interface DownloadOpts {
21
21
  */
22
22
  expire: number;
23
23
  }
24
+ /**
25
+ * User options for {@link canvasRecorder}.
26
+ */
27
+ export interface CanvasRecorderOpts extends Pick<MediaRecorderOptions, "mimeType" | "bitsPerSecond" | "videoBitsPerSecond"> {
28
+ /**
29
+ * Recording frame rate (fps)
30
+ *
31
+ * @defaultValue 60
32
+ */
33
+ fps: number;
34
+ }
24
35
  //# sourceMappingURL=api.d.ts.map
package/canvas.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { CanvasRecorderOpts } from "./api.js";
1
2
  /**
2
3
  * Triggers canvas-to-blob conversion for given file type (and opt. `quality`),
3
4
  * then triggers download via {@link downloadWithMime}. Default file type is
@@ -9,4 +10,19 @@
9
10
  * @param quality
10
11
  */
11
12
  export declare const downloadCanvas: (canvas: HTMLCanvasElement, baseName: string, type?: "png" | "jpeg" | "webp", quality?: number) => void;
13
+ /**
14
+ * Constructs, initializes and returns a `MediaRecorder` instance for the given
15
+ * canvas. The recording MUST be started & ended manually by the caller (via
16
+ * `.start()` and `.stop()`). The downloading starts only once sufficient frames
17
+ * were recorded, or latest when `.stop()` was called.
18
+ *
19
+ * @remarks
20
+ * The default recording format is WebM (VP9 codec) @ 60 fps, using the browser
21
+ * defined default bit rate.
22
+ *
23
+ * @param canvas
24
+ * @param fileName
25
+ * @param opts
26
+ */
27
+ export declare const canvasRecorder: (canvas: HTMLCanvasElement, fileName: string, opts?: Partial<CanvasRecorderOpts> | undefined) => MediaRecorder;
12
28
  //# sourceMappingURL=canvas.d.ts.map
package/canvas.js CHANGED
@@ -15,3 +15,35 @@ export const downloadCanvas = (canvas, baseName, type = "png", quality = 0.95) =
15
15
  ? downloadWithMime(`${baseName}.${type}`, blob, { mime })
16
16
  : console.warn("can't download canvas"), mime, quality);
17
17
  };
18
+ /**
19
+ * Constructs, initializes and returns a `MediaRecorder` instance for the given
20
+ * canvas. The recording MUST be started & ended manually by the caller (via
21
+ * `.start()` and `.stop()`). The downloading starts only once sufficient frames
22
+ * were recorded, or latest when `.stop()` was called.
23
+ *
24
+ * @remarks
25
+ * The default recording format is WebM (VP9 codec) @ 60 fps, using the browser
26
+ * defined default bit rate.
27
+ *
28
+ * @param canvas
29
+ * @param fileName
30
+ * @param opts
31
+ */
32
+ export const canvasRecorder = (canvas, fileName, opts) => {
33
+ opts = { fps: 60, mimeType: "video/webm; codecs=vp9", ...opts };
34
+ const stream = canvas.captureStream(opts.fps);
35
+ const recorder = new MediaRecorder(stream, {
36
+ mimeType: opts.mimeType,
37
+ });
38
+ let blobs = [];
39
+ recorder.ondataavailable = (e) => {
40
+ if (e.data.size > 0) {
41
+ blobs.push(e.data);
42
+ downloadWithMime(fileName, new Blob(blobs, { type: opts.mimeType }), {
43
+ mime: opts.mimeType,
44
+ });
45
+ blobs = [];
46
+ }
47
+ };
48
+ return recorder;
49
+ };
package/package.json CHANGED
@@ -1,86 +1,93 @@
1
1
  {
2
- "name": "@thi.ng/dl-asset",
3
- "version": "2.1.0",
4
- "description": "Local asset download for web apps, with automatic MIME type detection",
5
- "type": "module",
6
- "module": "./index.js",
7
- "typings": "./index.d.ts",
8
- "sideEffects": false,
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/thi-ng/umbrella.git"
2
+ "name": "@thi.ng/dl-asset",
3
+ "version": "2.3.0",
4
+ "description": "Canvas, video recording & file asset download helpers for web apps",
5
+ "type": "module",
6
+ "module": "./index.js",
7
+ "typings": "./index.d.ts",
8
+ "sideEffects": false,
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/thi-ng/umbrella.git"
12
+ },
13
+ "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/download#readme",
14
+ "funding": [
15
+ {
16
+ "type": "github",
17
+ "url": "https://github.com/sponsors/postspectacular"
12
18
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/download#readme",
14
- "funding": [
15
- {
16
- "type": "github",
17
- "url": "https://github.com/sponsors/postspectacular"
18
- },
19
- {
20
- "type": "patreon",
21
- "url": "https://patreon.com/thing_umbrella"
22
- }
23
- ],
24
- "author": "Karsten Schmidt <k+npm@thi.ng>",
25
- "license": "Apache-2.0",
26
- "scripts": {
27
- "build": "yarn clean && tsc --declaration",
28
- "clean": "rimraf *.js *.d.ts *.map doc",
29
- "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
- "doc:ae": "mkdir -p .ae/doc .ae/temp && node_modules/.bin/api-extractor run --local --verbose",
31
- "doc:readme": "yarn doc:stats && ../../scripts/node-esm ../../tools/src/readme.ts",
32
- "doc:stats": "../../scripts/node-esm ../../tools/src/module-stats.ts",
33
- "pub": "yarn build && yarn publish --access public",
34
- "test": "testament test"
35
- },
36
- "dependencies": {
37
- "@thi.ng/api": "^8.2.0",
38
- "@thi.ng/checks": "^3.0.7",
39
- "@thi.ng/mime": "^2.0.8"
19
+ {
20
+ "type": "patreon",
21
+ "url": "https://patreon.com/thing_umbrella"
22
+ }
23
+ ],
24
+ "author": "Karsten Schmidt <k+npm@thi.ng>",
25
+ "license": "Apache-2.0",
26
+ "scripts": {
27
+ "build": "yarn clean && tsc --declaration",
28
+ "clean": "rimraf '*.js' '*.d.ts' '*.map' doc",
29
+ "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
+ "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
31
+ "doc:readme": "yarn doc:stats && tools:readme",
32
+ "doc:stats": "tools:module-stats",
33
+ "pub": "yarn npm publish --access public",
34
+ "test": "testament test"
35
+ },
36
+ "dependencies": {
37
+ "@thi.ng/api": "^8.3.3",
38
+ "@thi.ng/checks": "^3.1.3",
39
+ "@thi.ng/mime": "^2.1.3"
40
+ },
41
+ "devDependencies": {
42
+ "@microsoft/api-extractor": "^7.19.2",
43
+ "@thi.ng/testament": "^0.2.3",
44
+ "rimraf": "^3.0.2",
45
+ "tools": "^0.0.1",
46
+ "typedoc": "^0.22.10",
47
+ "typescript": "^4.5.3"
48
+ },
49
+ "keywords": [
50
+ "browser",
51
+ "canvas",
52
+ "download",
53
+ "file",
54
+ "mime",
55
+ "mediarecorder",
56
+ "typescript",
57
+ "video"
58
+ ],
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "engines": {
63
+ "node": ">=12.7"
64
+ },
65
+ "files": [
66
+ "*.js",
67
+ "*.d.ts"
68
+ ],
69
+ "exports": {
70
+ ".": {
71
+ "import": "./index.js"
40
72
  },
41
- "devDependencies": {
42
- "@thi.ng/testament": "^0.1.6"
73
+ "./api": {
74
+ "import": "./api.js"
43
75
  },
44
- "keywords": [
45
- "browser",
46
- "canvas",
47
- "download",
48
- "file",
49
- "mime",
50
- "typescript"
51
- ],
52
- "publishConfig": {
53
- "access": "public"
76
+ "./canvas": {
77
+ "import": "./canvas.js"
54
78
  },
55
- "engines": {
56
- "node": ">=12.7"
79
+ "./download": {
80
+ "import": "./download.js"
57
81
  },
58
- "files": [
59
- "*.js",
60
- "*.d.ts"
82
+ "./raw": {
83
+ "import": "./raw.js"
84
+ }
85
+ },
86
+ "thi.ng": {
87
+ "related": [
88
+ "mime"
61
89
  ],
62
- "exports": {
63
- ".": {
64
- "import": "./index.js"
65
- },
66
- "./api": {
67
- "import": "./api.js"
68
- },
69
- "./canvas": {
70
- "import": "./canvas.js"
71
- },
72
- "./download": {
73
- "import": "./download.js"
74
- },
75
- "./raw": {
76
- "import": "./raw.js"
77
- }
78
- },
79
- "thi.ng": {
80
- "related": [
81
- "mime"
82
- ],
83
- "year": 2020
84
- },
85
- "gitHead": "5fe52419af63984ebe53032201b2a6174b9cb159"
86
- }
90
+ "year": 2020
91
+ },
92
+ "gitHead": "2db9dd34c0c2c60cbfde3dad0bca352b20292f5c\n"
93
+ }