@twin.org/image 0.0.1-next.1
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 +201 -0
- package/README.md +24 -0
- package/dist/cjs/index.cjs +1900 -0
- package/dist/esm/index.mjs +1896 -0
- package/dist/types/color.d.ts +76 -0
- package/dist/types/encoders/jpegEncoder.d.ts +19 -0
- package/dist/types/encoders/png/frame.d.ts +1 -0
- package/dist/types/encoders/png/imageData.d.ts +1 -0
- package/dist/types/encoders/png/leaf.d.ts +1 -0
- package/dist/types/encoders/pngEncoder.d.ts +14 -0
- package/dist/types/index.d.ts +3 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/Color.md +217 -0
- package/docs/reference/classes/JpegEncoder.md +48 -0
- package/docs/reference/classes/PngEncoder.md +42 -0
- package/docs/reference/index.md +7 -0
- package/locales/en.json +7 -0
- package/package.json +63 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to represent a color.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Color {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new instance of color.
|
|
7
|
+
* @param alpha The alpha element of the color.
|
|
8
|
+
* @param red The red element of the color.
|
|
9
|
+
* @param green The green element of the color.
|
|
10
|
+
* @param blue The blue element of the color.
|
|
11
|
+
*/
|
|
12
|
+
constructor(alpha: number, red: number, green: number, blue: number);
|
|
13
|
+
/**
|
|
14
|
+
* Construct a color from a hex string.
|
|
15
|
+
* @param hex The hex string to parse.
|
|
16
|
+
* @returns The color.
|
|
17
|
+
* @throws Error if the format is incorrect.
|
|
18
|
+
*/
|
|
19
|
+
static fromHex(hex: string): Color;
|
|
20
|
+
/**
|
|
21
|
+
* Coerce an unknown type to a color.
|
|
22
|
+
* @param value The value to try and convert.
|
|
23
|
+
* @returns The color if one can be created.
|
|
24
|
+
*/
|
|
25
|
+
static coerce(value: unknown): Color | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Get the alpha element.
|
|
28
|
+
* @returns The alpha element.
|
|
29
|
+
*/
|
|
30
|
+
alpha(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Get the red element.
|
|
33
|
+
* @returns The red element.
|
|
34
|
+
*/
|
|
35
|
+
red(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Get the green element.
|
|
38
|
+
* @returns The green element.
|
|
39
|
+
*/
|
|
40
|
+
green(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Get the blue element.
|
|
43
|
+
* @returns The blue element.
|
|
44
|
+
*/
|
|
45
|
+
blue(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Get color as argb.
|
|
48
|
+
* @returns The color as argb.
|
|
49
|
+
*/
|
|
50
|
+
argb(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Get color as rgba.
|
|
53
|
+
* @returns The color as rgba.
|
|
54
|
+
*/
|
|
55
|
+
rgba(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Get color as rgb text.
|
|
58
|
+
* @returns The color as rgb.
|
|
59
|
+
*/
|
|
60
|
+
rgbText(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get color as rgba text.
|
|
63
|
+
* @returns The color as rgba.
|
|
64
|
+
*/
|
|
65
|
+
rgbaText(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Get color as hex no alpha.
|
|
68
|
+
* @returns The color as hex with no alpha component.
|
|
69
|
+
*/
|
|
70
|
+
hex(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Get color as hex with alpha.
|
|
73
|
+
* @returns The color as hex with with alpha component.
|
|
74
|
+
*/
|
|
75
|
+
hexWithAlpha(): string;
|
|
76
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JPEG Encoder.
|
|
3
|
+
* Based on JPEG encoder ported to JavaScript and optimized by Andreas Ritter.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JpegEncoder {
|
|
6
|
+
/**
|
|
7
|
+
* Create a new instance of JpegEncoder.
|
|
8
|
+
*/
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Encode the image with the given quality.
|
|
12
|
+
* @param width The width of the image to encode.
|
|
13
|
+
* @param height The height of the image to encode.
|
|
14
|
+
* @param imageData The data for the image.
|
|
15
|
+
* @param quality The quality to encode the image at.
|
|
16
|
+
* @returns The data for the encoded image.
|
|
17
|
+
*/
|
|
18
|
+
encode(width: number, height: number, imageData: Uint8Array, quality: number): Uint8Array;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PNG Encoder.
|
|
3
|
+
* Based on https://github.com/photopea/UPNG.js.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PngEncoder {
|
|
6
|
+
/**
|
|
7
|
+
* Encode the image frames to png.
|
|
8
|
+
* @param buffers The frame buffers to encode.
|
|
9
|
+
* @param w The image width.
|
|
10
|
+
* @param h The image height.
|
|
11
|
+
* @returns The data for the image.
|
|
12
|
+
*/
|
|
13
|
+
encode(buffers: ArrayBuffer[], w: number, h: number): Promise<Uint8Array>;
|
|
14
|
+
}
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @twin.org/image - Examples
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Class: Color
|
|
2
|
+
|
|
3
|
+
Class to represent a color.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new Color()
|
|
8
|
+
|
|
9
|
+
> **new Color**(`alpha`, `red`, `green`, `blue`): [`Color`](Color.md)
|
|
10
|
+
|
|
11
|
+
Create a new instance of color.
|
|
12
|
+
|
|
13
|
+
#### Parameters
|
|
14
|
+
|
|
15
|
+
• **alpha**: `number`
|
|
16
|
+
|
|
17
|
+
The alpha element of the color.
|
|
18
|
+
|
|
19
|
+
• **red**: `number`
|
|
20
|
+
|
|
21
|
+
The red element of the color.
|
|
22
|
+
|
|
23
|
+
• **green**: `number`
|
|
24
|
+
|
|
25
|
+
The green element of the color.
|
|
26
|
+
|
|
27
|
+
• **blue**: `number`
|
|
28
|
+
|
|
29
|
+
The blue element of the color.
|
|
30
|
+
|
|
31
|
+
#### Returns
|
|
32
|
+
|
|
33
|
+
[`Color`](Color.md)
|
|
34
|
+
|
|
35
|
+
## Methods
|
|
36
|
+
|
|
37
|
+
### fromHex()
|
|
38
|
+
|
|
39
|
+
> `static` **fromHex**(`hex`): [`Color`](Color.md)
|
|
40
|
+
|
|
41
|
+
Construct a color from a hex string.
|
|
42
|
+
|
|
43
|
+
#### Parameters
|
|
44
|
+
|
|
45
|
+
• **hex**: `string`
|
|
46
|
+
|
|
47
|
+
The hex string to parse.
|
|
48
|
+
|
|
49
|
+
#### Returns
|
|
50
|
+
|
|
51
|
+
[`Color`](Color.md)
|
|
52
|
+
|
|
53
|
+
The color.
|
|
54
|
+
|
|
55
|
+
#### Throws
|
|
56
|
+
|
|
57
|
+
Error if the format is incorrect.
|
|
58
|
+
|
|
59
|
+
***
|
|
60
|
+
|
|
61
|
+
### coerce()
|
|
62
|
+
|
|
63
|
+
> `static` **coerce**(`value`): `undefined` \| [`Color`](Color.md)
|
|
64
|
+
|
|
65
|
+
Coerce an unknown type to a color.
|
|
66
|
+
|
|
67
|
+
#### Parameters
|
|
68
|
+
|
|
69
|
+
• **value**: `unknown`
|
|
70
|
+
|
|
71
|
+
The value to try and convert.
|
|
72
|
+
|
|
73
|
+
#### Returns
|
|
74
|
+
|
|
75
|
+
`undefined` \| [`Color`](Color.md)
|
|
76
|
+
|
|
77
|
+
The color if one can be created.
|
|
78
|
+
|
|
79
|
+
***
|
|
80
|
+
|
|
81
|
+
### alpha()
|
|
82
|
+
|
|
83
|
+
> **alpha**(): `number`
|
|
84
|
+
|
|
85
|
+
Get the alpha element.
|
|
86
|
+
|
|
87
|
+
#### Returns
|
|
88
|
+
|
|
89
|
+
`number`
|
|
90
|
+
|
|
91
|
+
The alpha element.
|
|
92
|
+
|
|
93
|
+
***
|
|
94
|
+
|
|
95
|
+
### red()
|
|
96
|
+
|
|
97
|
+
> **red**(): `number`
|
|
98
|
+
|
|
99
|
+
Get the red element.
|
|
100
|
+
|
|
101
|
+
#### Returns
|
|
102
|
+
|
|
103
|
+
`number`
|
|
104
|
+
|
|
105
|
+
The red element.
|
|
106
|
+
|
|
107
|
+
***
|
|
108
|
+
|
|
109
|
+
### green()
|
|
110
|
+
|
|
111
|
+
> **green**(): `number`
|
|
112
|
+
|
|
113
|
+
Get the green element.
|
|
114
|
+
|
|
115
|
+
#### Returns
|
|
116
|
+
|
|
117
|
+
`number`
|
|
118
|
+
|
|
119
|
+
The green element.
|
|
120
|
+
|
|
121
|
+
***
|
|
122
|
+
|
|
123
|
+
### blue()
|
|
124
|
+
|
|
125
|
+
> **blue**(): `number`
|
|
126
|
+
|
|
127
|
+
Get the blue element.
|
|
128
|
+
|
|
129
|
+
#### Returns
|
|
130
|
+
|
|
131
|
+
`number`
|
|
132
|
+
|
|
133
|
+
The blue element.
|
|
134
|
+
|
|
135
|
+
***
|
|
136
|
+
|
|
137
|
+
### argb()
|
|
138
|
+
|
|
139
|
+
> **argb**(): `number`
|
|
140
|
+
|
|
141
|
+
Get color as argb.
|
|
142
|
+
|
|
143
|
+
#### Returns
|
|
144
|
+
|
|
145
|
+
`number`
|
|
146
|
+
|
|
147
|
+
The color as argb.
|
|
148
|
+
|
|
149
|
+
***
|
|
150
|
+
|
|
151
|
+
### rgba()
|
|
152
|
+
|
|
153
|
+
> **rgba**(): `number`
|
|
154
|
+
|
|
155
|
+
Get color as rgba.
|
|
156
|
+
|
|
157
|
+
#### Returns
|
|
158
|
+
|
|
159
|
+
`number`
|
|
160
|
+
|
|
161
|
+
The color as rgba.
|
|
162
|
+
|
|
163
|
+
***
|
|
164
|
+
|
|
165
|
+
### rgbText()
|
|
166
|
+
|
|
167
|
+
> **rgbText**(): `string`
|
|
168
|
+
|
|
169
|
+
Get color as rgb text.
|
|
170
|
+
|
|
171
|
+
#### Returns
|
|
172
|
+
|
|
173
|
+
`string`
|
|
174
|
+
|
|
175
|
+
The color as rgb.
|
|
176
|
+
|
|
177
|
+
***
|
|
178
|
+
|
|
179
|
+
### rgbaText()
|
|
180
|
+
|
|
181
|
+
> **rgbaText**(): `string`
|
|
182
|
+
|
|
183
|
+
Get color as rgba text.
|
|
184
|
+
|
|
185
|
+
#### Returns
|
|
186
|
+
|
|
187
|
+
`string`
|
|
188
|
+
|
|
189
|
+
The color as rgba.
|
|
190
|
+
|
|
191
|
+
***
|
|
192
|
+
|
|
193
|
+
### hex()
|
|
194
|
+
|
|
195
|
+
> **hex**(): `string`
|
|
196
|
+
|
|
197
|
+
Get color as hex no alpha.
|
|
198
|
+
|
|
199
|
+
#### Returns
|
|
200
|
+
|
|
201
|
+
`string`
|
|
202
|
+
|
|
203
|
+
The color as hex with no alpha component.
|
|
204
|
+
|
|
205
|
+
***
|
|
206
|
+
|
|
207
|
+
### hexWithAlpha()
|
|
208
|
+
|
|
209
|
+
> **hexWithAlpha**(): `string`
|
|
210
|
+
|
|
211
|
+
Get color as hex with alpha.
|
|
212
|
+
|
|
213
|
+
#### Returns
|
|
214
|
+
|
|
215
|
+
`string`
|
|
216
|
+
|
|
217
|
+
The color as hex with with alpha component.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Class: JpegEncoder
|
|
2
|
+
|
|
3
|
+
JPEG Encoder.
|
|
4
|
+
Based on JPEG encoder ported to JavaScript and optimized by Andreas Ritter.
|
|
5
|
+
|
|
6
|
+
## Constructors
|
|
7
|
+
|
|
8
|
+
### new JpegEncoder()
|
|
9
|
+
|
|
10
|
+
> **new JpegEncoder**(): [`JpegEncoder`](JpegEncoder.md)
|
|
11
|
+
|
|
12
|
+
Create a new instance of JpegEncoder.
|
|
13
|
+
|
|
14
|
+
#### Returns
|
|
15
|
+
|
|
16
|
+
[`JpegEncoder`](JpegEncoder.md)
|
|
17
|
+
|
|
18
|
+
## Methods
|
|
19
|
+
|
|
20
|
+
### encode()
|
|
21
|
+
|
|
22
|
+
> **encode**(`width`, `height`, `imageData`, `quality`): `Uint8Array`
|
|
23
|
+
|
|
24
|
+
Encode the image with the given quality.
|
|
25
|
+
|
|
26
|
+
#### Parameters
|
|
27
|
+
|
|
28
|
+
• **width**: `number`
|
|
29
|
+
|
|
30
|
+
The width of the image to encode.
|
|
31
|
+
|
|
32
|
+
• **height**: `number`
|
|
33
|
+
|
|
34
|
+
The height of the image to encode.
|
|
35
|
+
|
|
36
|
+
• **imageData**: `Uint8Array`
|
|
37
|
+
|
|
38
|
+
The data for the image.
|
|
39
|
+
|
|
40
|
+
• **quality**: `number`
|
|
41
|
+
|
|
42
|
+
The quality to encode the image at.
|
|
43
|
+
|
|
44
|
+
#### Returns
|
|
45
|
+
|
|
46
|
+
`Uint8Array`
|
|
47
|
+
|
|
48
|
+
The data for the encoded image.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Class: PngEncoder
|
|
2
|
+
|
|
3
|
+
PNG Encoder.
|
|
4
|
+
Based on https://github.com/photopea/UPNG.js.
|
|
5
|
+
|
|
6
|
+
## Constructors
|
|
7
|
+
|
|
8
|
+
### new PngEncoder()
|
|
9
|
+
|
|
10
|
+
> **new PngEncoder**(): [`PngEncoder`](PngEncoder.md)
|
|
11
|
+
|
|
12
|
+
#### Returns
|
|
13
|
+
|
|
14
|
+
[`PngEncoder`](PngEncoder.md)
|
|
15
|
+
|
|
16
|
+
## Methods
|
|
17
|
+
|
|
18
|
+
### encode()
|
|
19
|
+
|
|
20
|
+
> **encode**(`buffers`, `w`, `h`): `Promise`\<`Uint8Array`\>
|
|
21
|
+
|
|
22
|
+
Encode the image frames to png.
|
|
23
|
+
|
|
24
|
+
#### Parameters
|
|
25
|
+
|
|
26
|
+
• **buffers**: `ArrayBuffer`[]
|
|
27
|
+
|
|
28
|
+
The frame buffers to encode.
|
|
29
|
+
|
|
30
|
+
• **w**: `number`
|
|
31
|
+
|
|
32
|
+
The image width.
|
|
33
|
+
|
|
34
|
+
• **h**: `number`
|
|
35
|
+
|
|
36
|
+
The image height.
|
|
37
|
+
|
|
38
|
+
#### Returns
|
|
39
|
+
|
|
40
|
+
`Promise`\<`Uint8Array`\>
|
|
41
|
+
|
|
42
|
+
The data for the image.
|
package/locales/en.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/image",
|
|
3
|
+
"version": "0.0.1-next.1",
|
|
4
|
+
"description": "Classes for image manipulation",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/framework.git",
|
|
8
|
+
"directory": "packages/image"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rimraf dist coverage",
|
|
18
|
+
"build": "tspc",
|
|
19
|
+
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
+
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
+
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
+
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
+
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
+
"docs:clean": "rimraf docs/reference",
|
|
25
|
+
"docs:generate": "typedoc",
|
|
26
|
+
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
+
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@twin.org/core": "0.0.1-next.1",
|
|
31
|
+
"@twin.org/nameof": "next"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@twin.org/nameof-transformer": "next",
|
|
35
|
+
"@vitest/coverage-v8": "2.1.1",
|
|
36
|
+
"copyfiles": "2.4.1",
|
|
37
|
+
"rimraf": "6.0.1",
|
|
38
|
+
"rollup": "4.21.3",
|
|
39
|
+
"rollup-plugin-typescript2": "0.36.0",
|
|
40
|
+
"ts-patch": "3.2.1",
|
|
41
|
+
"typedoc": "0.26.7",
|
|
42
|
+
"typedoc-plugin-markdown": "4.2.7",
|
|
43
|
+
"typescript": "5.6.2",
|
|
44
|
+
"vitest": "2.1.1"
|
|
45
|
+
},
|
|
46
|
+
"main": "./dist/cjs/index.cjs",
|
|
47
|
+
"module": "./dist/esm/index.mjs",
|
|
48
|
+
"types": "./dist/types/index.d.ts",
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"require": "./dist/cjs/index.cjs",
|
|
52
|
+
"import": "./dist/esm/index.mjs",
|
|
53
|
+
"types": "./dist/types/index.d.ts"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist/cjs",
|
|
58
|
+
"dist/esm",
|
|
59
|
+
"dist/types",
|
|
60
|
+
"locales",
|
|
61
|
+
"docs"
|
|
62
|
+
]
|
|
63
|
+
}
|