@thi.ng/dl-asset 2.0.7 → 2.2.2

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,69 +1,82 @@
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.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)
7
-
8
- **Note:** Version bump only for package @thi.ng/dl-asset
9
-
10
-
11
-
12
-
13
-
14
- # [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)
15
-
16
-
17
- ### Build System
18
-
19
- * major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea9fab2a645d6c5f2bf2591459b939c09b6))
3
+ - **Last updated**: 2021-11-21T17:09:28Z
4
+ - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
20
5
 
6
+ All notable changes to this project will be documented in this file.
7
+ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelines.
21
8
 
22
- ### BREAKING CHANGES
9
+ **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
+ and/or version bumps of transitive dependencies.
23
11
 
24
- * discontinue CommonJS & UMD versions
12
+ ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.2.0) (2021-11-17)
25
13
 
26
- - only ESM modules will be published from now on
27
- - CJS obsolete due to ESM support in recent versions of node:
28
- - i.e. launch NodeJS via:
29
- - `node --experimental-specifier-resolution=node --experimental-repl-await`
30
- - in the node REPL use `await import(...)` instead of `require()`
31
- - UMD obsolete due to widespread browser support for ESM
14
+ #### 🚀 Features
32
15
 
33
- Also:
34
- - normalize/restructure/reorg all package.json files
35
- - cleanup all build scripts, remove obsolete
36
- - switch from mocha to @thi.ng/testament for all tests
16
+ - Using workspaces for local tools ([bf7a404](https://github.com/thi-ng/umbrella/commit/bf7a404))
17
+ Improving the overall build ergonomics
18
+ - introduced a tools workspaces
19
+ - imported it in all needed packages/examples
20
+ - inclusive project root
37
21
 
22
+ #### ♻️ Refactoring
38
23
 
24
+ - testrunner to binary ([4ebbbb2](https://github.com/thi-ng/umbrella/commit/4ebbbb2))
25
+ this commit reverts (partly) changes made in:
26
+ ef346d7a8753590dc9094108a3d861a8dbd5dd2c
27
+ overall purpose is better testament ergonomics:
28
+ instead of having to pass NODE_OPTIONS with every invocation
29
+ having a binary to handle this for us.
39
30
 
31
+ ## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.1.0) (2021-11-10)
40
32
 
33
+ #### 🚀 Features
41
34
 
35
+ - add downloadCanvas() ([ca657d4](https://github.com/thi-ng/umbrella/commit/ca657d4))
42
36
 
43
- ## [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)
37
+ ### [2.0.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.0.1) (2021-10-13)
44
38
 
45
- **Note:** Version bump only for package @thi.ng/dl-asset
39
+ #### ♻️ Refactoring
46
40
 
47
- # [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)
41
+ - update imports in all tests/pkgs ([effd591](https://github.com/thi-ng/umbrella/commit/effd591))
42
+ - update imports in all pkgs ([5fa2b6f](https://github.com/thi-ng/umbrella/commit/5fa2b6f))
43
+ - add .js suffix for all relative imports
48
44
 
49
- ### Features
45
+ # [2.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@2.0.0) (2021-10-12)
50
46
 
51
- - **dl-asset:** split src, extract `downloadWithMime()` ([d749819](https://github.com/thi-ng/umbrella/commit/d74981963ce4bfbfe3465c71085995173826329c))
47
+ #### 🛑 Breaking changes
52
48
 
53
- # 0.3.0 (2020-02-26)
49
+ - major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea))
50
+ - BREAKING CHANGE: discontinue CommonJS & UMD versions
51
+ - only ESM modules will be published from now on
52
+ - CJS obsolete due to ESM support in recent versions of node:
53
+ - i.e. launch NodeJS via:
54
+ - `node --experimental-specifier-resolution=node --experimental-repl-await`
55
+ - in the node REPL use `await import(...)` instead of `require()`
56
+ - UMD obsolete due to widespread browser support for ESM
57
+ Also:
58
+ - normalize/restructure/reorg all package.json files
59
+ - cleanup all build scripts, remove obsolete
60
+ - switch from mocha to [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament) for all tests
54
61
 
55
- ### Features
62
+ #### ♻️ Refactoring
56
63
 
57
- - **dl-asset:** yet another npm forced pkg rename ([2cae33c](https://github.com/thi-ng/umbrella/commit/2cae33cabd379b3d449079edfc255d9cf56c34a5))
64
+ - update imports ([29a7681](https://github.com/thi-ng/umbrella/commit/29a7681))
65
+ - update all test stubs ([f2d6d53](https://github.com/thi-ng/umbrella/commit/f2d6d53))
66
+ - update all tests in _all_ pkgs ([8b582bc](https://github.com/thi-ng/umbrella/commit/8b582bc))
67
+ - update all to use [@thi.ng/testament](https://github.com/thi-ng/umbrella/tree/main/packages/testament)
58
68
 
59
- # 0.2.0 (2020-02-26)
69
+ ## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@0.4.0) (2020-07-08)
60
70
 
61
- ### Features
71
+ #### 🚀 Features
62
72
 
63
- - **download-asset:** rename pkg due to npm name conflict ([b490b46](https://github.com/thi-ng/umbrella/commit/b490b46994333103f653514c96531637d903202d))
73
+ - split src, extract `downloadWithMime()` ([d749819](https://github.com/thi-ng/umbrella/commit/d749819))
74
+ - new fn improves tree shaking and can avoid inclusion of [@thi.ng/mime](https://github.com/thi-ng/umbrella/tree/main/packages/mime)
75
+ if mime type is explicitly provided by user
64
76
 
65
- # 0.1.0 (2020-02-25)
77
+ ## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dl-asset@0.3.0) (2020-02-26)
66
78
 
67
- ### Features
79
+ #### 🚀 Features
68
80
 
69
- - **download:** import as new pkg ([26caaaa](https://github.com/thi-ng/umbrella/commit/26caaaadf6c3f7b6bb83e8a4160a91b7e2db8714))
81
+ - yet another npm forced pkg rename ([2cae33c](https://github.com/thi-ng/umbrella/commit/2cae33c))
82
+ - https://twitter.com/thing_umbrella/status/1232461386917257217
package/README.md CHANGED
@@ -16,6 +16,8 @@ This project is part of the
16
16
  - [Dependencies](#dependencies)
17
17
  - [Usage examples](#usage-examples)
18
18
  - [API](#api)
19
+ - [Basic usage](#basic-usage)
20
+ - [Simplified canvas downloads](#simplified-canvas-downloads)
19
21
  - [Authors](#authors)
20
22
  - [License](#license)
21
23
 
@@ -56,7 +58,7 @@ node --experimental-repl-await
56
58
  > const dlAsset = await import("@thi.ng/dl-asset");
57
59
  ```
58
60
 
59
- Package sizes (gzipped, pre-treeshake): ESM: 427 bytes
61
+ Package sizes (gzipped, pre-treeshake): ESM: 516 bytes
60
62
 
61
63
  ## Dependencies
62
64
 
@@ -87,6 +89,8 @@ A selection:
87
89
 
88
90
  [Generated API docs](https://docs.thi.ng/umbrella/dl-asset/)
89
91
 
92
+ ### Basic usage
93
+
90
94
  ```ts
91
95
  import { download } from "@thi.ng/dl-asset";
92
96
 
@@ -110,15 +114,33 @@ download("hello.txt", src, {
110
114
  [@thi.ng/mime](https://github.com/thi-ng/umbrella/tree/develop/packages/mime).
111
115
 
112
116
  ```ts
113
- import { MIME_TYPES } from "@thi.ng/mime";
117
+ import { preferredType } from "@thi.ng/mime";
114
118
 
115
- download("hello.txt", src, {
116
- mime: MIME_TYPES.text,
119
+ downloadWithMime("hello.txt", src, {
120
+ // here mandatory to provide MIME type
121
+ mime: preferredType("txt"), // text/plain
117
122
  utf8: true,
118
123
  expire: 1000
119
124
  });
120
125
  ```
121
126
 
127
+ ### Simplified canvas downloads
128
+
129
+ Since v2.1.0, HTML canvas downloads can be simplified using
130
+ [`downloadCanvas()`](https://docs.thi.ng/umbrella/dl-asset/modules.html#downloadCanvas):
131
+
132
+ ```ts
133
+ import { downloadCanvas } from "@thi.ng/dl-asset";
134
+
135
+ // download as PNG (default)
136
+ downloadCanvas(canvas, "file-name-without-ext");
137
+
138
+ // download as JPG or WebP with given quality
139
+ downloadCanvas(canvas, "file-name-without-ext", "jpeg", 0.9);
140
+
141
+ downloadCanvas(canvas, "file-name-without-ext", "webp", 0.9);
142
+ ```
143
+
122
144
  ## Authors
123
145
 
124
146
  Karsten Schmidt
package/canvas.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Triggers canvas-to-blob conversion for given file type (and opt. `quality`),
3
+ * then triggers download via {@link downloadWithMime}. Default file type is
4
+ * `png`. Default quality is 0.95 (only used for JPEG/WebP).
5
+ *
6
+ * @param canvas
7
+ * @param baseName
8
+ * @param type
9
+ * @param quality
10
+ */
11
+ export declare const downloadCanvas: (canvas: HTMLCanvasElement, baseName: string, type?: "png" | "jpeg" | "webp", quality?: number) => void;
12
+ //# sourceMappingURL=canvas.d.ts.map
package/canvas.js ADDED
@@ -0,0 +1,17 @@
1
+ import { downloadWithMime } from "./raw.js";
2
+ /**
3
+ * Triggers canvas-to-blob conversion for given file type (and opt. `quality`),
4
+ * then triggers download via {@link downloadWithMime}. Default file type is
5
+ * `png`. Default quality is 0.95 (only used for JPEG/WebP).
6
+ *
7
+ * @param canvas
8
+ * @param baseName
9
+ * @param type
10
+ * @param quality
11
+ */
12
+ export const downloadCanvas = (canvas, baseName, type = "png", quality = 0.95) => {
13
+ const mime = `image/${type}`;
14
+ canvas.toBlob((blob) => blob
15
+ ? downloadWithMime(`${baseName}.${type}`, blob, { mime })
16
+ : console.warn("can't download canvas"), mime, quality);
17
+ };
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./api.js";
2
+ export * from "./canvas.js";
2
3
  export * from "./download.js";
3
4
  export * from "./raw.js";
4
5
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./api.js";
2
+ export * from "./canvas.js";
2
3
  export * from "./download.js";
3
4
  export * from "./raw.js";
package/package.json CHANGED
@@ -1,81 +1,91 @@
1
1
  {
2
- "name": "@thi.ng/dl-asset",
3
- "version": "2.0.7",
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.2.2",
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"
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.1.0",
38
- "@thi.ng/checks": "^3.0.6",
39
- "@thi.ng/mime": "^2.0.7"
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.2",
38
+ "@thi.ng/checks": "^3.1.2",
39
+ "@thi.ng/mime": "^2.1.2"
40
+ },
41
+ "devDependencies": {
42
+ "@microsoft/api-extractor": "^7.18.19",
43
+ "@thi.ng/testament": "^0.2.2",
44
+ "rimraf": "^3.0.2",
45
+ "tools": "^0.0.1",
46
+ "typedoc": "^0.22.9",
47
+ "typescript": "^4.5.2"
48
+ },
49
+ "keywords": [
50
+ "browser",
51
+ "canvas",
52
+ "download",
53
+ "file",
54
+ "mime",
55
+ "typescript"
56
+ ],
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "engines": {
61
+ "node": ">=12.7"
62
+ },
63
+ "files": [
64
+ "*.js",
65
+ "*.d.ts"
66
+ ],
67
+ "exports": {
68
+ ".": {
69
+ "import": "./index.js"
40
70
  },
41
- "devDependencies": {
42
- "@thi.ng/testament": "^0.1.6"
71
+ "./api": {
72
+ "import": "./api.js"
43
73
  },
44
- "keywords": [
45
- "browser",
46
- "canvas",
47
- "file",
48
- "typescript"
49
- ],
50
- "publishConfig": {
51
- "access": "public"
74
+ "./canvas": {
75
+ "import": "./canvas.js"
52
76
  },
53
- "engines": {
54
- "node": ">=12.7"
77
+ "./download": {
78
+ "import": "./download.js"
55
79
  },
56
- "files": [
57
- "*.js",
58
- "*.d.ts"
80
+ "./raw": {
81
+ "import": "./raw.js"
82
+ }
83
+ },
84
+ "thi.ng": {
85
+ "related": [
86
+ "mime"
59
87
  ],
60
- "exports": {
61
- ".": {
62
- "import": "./index.js"
63
- },
64
- "./api": {
65
- "import": "./api.js"
66
- },
67
- "./download": {
68
- "import": "./download.js"
69
- },
70
- "./raw": {
71
- "import": "./raw.js"
72
- }
73
- },
74
- "thi.ng": {
75
- "related": [
76
- "mime"
77
- ],
78
- "year": 2020
79
- },
80
- "gitHead": "852cd2450617c86d15d18477dc634f17f04202eb"
81
- }
88
+ "year": 2020
89
+ },
90
+ "gitHead": "e8a7c2a40191b391cef182c2978e5a6c85987a87\n"
91
+ }