@e-mc/image 0.11.7 → 0.12.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/image
2
2
 
3
- * NodeJS 16 LTS
4
- * ES2021
3
+ * NodeJS 18
4
+ * ES2022
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.11.7/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.0/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IHost, ModuleConstructor } from "./index";
@@ -34,18 +34,25 @@ interface IImage extends IClient<IHost, ImageModule> {
34
34
  parseRotate(value: string): RotateData | undefined;
35
35
  parseQuality(value: string): QualityData | undefined;
36
36
  parseOpacity(value: string): number;
37
+ parseWorker(command: string | CommandData, outputType?: string): CommandData | null;
37
38
  using?(data: IFileThread, command: string): Promise<unknown>;
38
39
  get outputAs(): string;
39
40
  }
40
41
 
41
42
  interface ImageConstructor extends ModuleConstructor {
42
- /** @deprecated */
43
- readonly REGEXP_SIZERANGE: RegExp;
43
+ readonly MIME_JPEG: string;
44
+ readonly MIME_PNG: string;
45
+ readonly MIME_WEBP: string;
46
+ readonly MIME_SVG: string;
47
+ readonly MIME_GIF: string;
48
+ readonly MIME_BMP: string;
49
+ readonly MIME_TIFF: string;
44
50
  transform(file: string, command: string, options: { tempFile: true }): Promise<string>;
45
51
  transform(file: string, command: string, options?: TransformOptions): Promise<Buffer | null>;
46
52
  clamp(value: unknown, min?: number, max?: number): number;
47
53
  isBinary(mime: unknown): mime is string;
48
54
  toABGR(buffer: Uint8Array | Buffer): Buffer;
55
+ asBuffer(data: Buffer | Uint8Array): Buffer;
49
56
  readonly prototype: IImage;
50
57
  new(module?: ImageModule, ...args: unknown[]): IImage;
51
58
  }
@@ -88,9 +95,9 @@ NOTE: Usage without a **Host** is conducted through static methods. The **using*
88
95
 
89
96
  ## References
90
97
 
91
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/asset.d.ts
92
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/image.d.ts
93
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/settings.d.ts
98
+ - https://www.unpkg.com/@e-mc/types@0.12.0/lib/asset.d.ts
99
+ - https://www.unpkg.com/@e-mc/types@0.12.0/lib/image.d.ts
100
+ - https://www.unpkg.com/@e-mc/types@0.12.0/lib/settings.d.ts
94
101
 
95
102
  ## LICENSE
96
103
 
package/index.js CHANGED
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var _a, _b;
3
2
  const core_1 = require("@e-mc/core");
4
- const kCommand = Symbol('command');
5
- const kOutputAs = Symbol('outputAs');
3
+ const kImage = Symbol.for('image:constructor');
6
4
  const REGEXP_CROP = /\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*\|\s*(\d+)\s*[xX]\s*(\d+)\s*\)/;
7
5
  const REGEXP_OPACITY = /\|\s*(\d*\.\d+)\s*\|/;
8
6
  const REGEXP_QUALITY = /\|\s*(\d+)?(?:\s*\[\s*(photo|picture|drawing|icon|text)\s*\])?(?:\s*\[\s*(\d+)\s*\])?(?:\s*m\[\s*(\d+)\s*\])?\s*\|/;
9
7
  const REGEXP_RESIZE = /\(\s*(\d+|auto)\s*x\s*(\d+|auto)(?:\s*\[\s*(bilinear|bicubic|hermite|bezier)\s*\])?(?:\s*\^\s*(contain|cover|scale)(?:\s*\[\s*(left|center|right)?(?:\s*\|?\s*(top|middle|bottom))?\s*\])?)?(?:\s*#\s*([a-f\d]{1,8}))?\s*\)/;
10
8
  const REGEXP_ROTATE = /\{((?:\s*-?\d+\s*,?)+)(?:\s*#\s*([a-f\d]{1,8}))?\s*\}/i;
11
9
  const REGEXP_METHOD = /!\s*([a-z$][\w$]*)(\()?/gi;
12
- const REGEXP_SIZERANGE = /(!\s*[\w$]+)?\(\s*(\d+)\s*(?:,\s*(\d+|\*)\s*)?\)/;
13
10
  function isEscaped(value, checkQuote) {
14
11
  if (!checkQuote || /["']/.test(value)) {
15
12
  let k = 0;
@@ -27,13 +24,27 @@ function isEscaped(value, checkQuote) {
27
24
  const isNumber = (ch) => ch >= '0' && ch <= '9';
28
25
  const parseHexDecimal = (value) => value ? +('0x' + value.toUpperCase().padEnd(8, 'F')) : NaN;
29
26
  class Image extends core_1.Client {
30
- constructor() {
31
- super(...arguments);
32
- this[_a] = '';
33
- this[_b] = '';
27
+ static [kImage] = true;
28
+ static get MIME_JPEG() {
29
+ return 'image/jpeg';
34
30
  }
35
- static get REGEXP_SIZERANGE() {
36
- return REGEXP_SIZERANGE;
31
+ static get MIME_PNG() {
32
+ return 'image/png';
33
+ }
34
+ static get MIME_WEBP() {
35
+ return 'image/webp';
36
+ }
37
+ static get MIME_SVG() {
38
+ return 'image/svg+xml';
39
+ }
40
+ static get MIME_GIF() {
41
+ return 'image/gif';
42
+ }
43
+ static get MIME_BMP() {
44
+ return 'image/bmp';
45
+ }
46
+ static get MIME_TIFF() {
47
+ return 'image/tiff';
37
48
  }
38
49
  static async transform(file, command, options) {
39
50
  return options?.tempFile ? '' : null;
@@ -51,7 +62,7 @@ class Image extends core_1.Client {
51
62
  return NaN;
52
63
  }
53
64
  static isBinary(mime) {
54
- return typeof mime === 'string' && mime.startsWith('image/') && mime !== 'image/svg+xml';
65
+ return typeof mime === 'string' && mime.startsWith('image/') && mime !== this.MIME_SVG;
55
66
  }
56
67
  static toABGR(buffer) {
57
68
  for (let i = 0, length = buffer.length; i < length; i += 4) {
@@ -63,6 +74,18 @@ class Image extends core_1.Client {
63
74
  }
64
75
  return Buffer.from(buffer);
65
76
  }
77
+ static asBuffer(data) {
78
+ return data instanceof Uint8Array ? Buffer.from(data.buffer, data.byteOffset, data.byteLength) : data;
79
+ }
80
+ resizeData;
81
+ cropData;
82
+ rotateData;
83
+ qualityData;
84
+ methodData;
85
+ opacityValue;
86
+ outputType;
87
+ #command = '';
88
+ #outputAs = '';
66
89
  reset() {
67
90
  super.reset();
68
91
  if (Object.hasOwn(this, 'resizeData')) {
@@ -83,8 +106,8 @@ class Image extends core_1.Client {
83
106
  if (Object.hasOwn(this, 'opacityValue')) {
84
107
  this.opacityValue = NaN;
85
108
  }
86
- this[kCommand] = '';
87
- this[kOutputAs] = '';
109
+ this.#command = '';
110
+ this.#outputAs = '';
88
111
  }
89
112
  setCommand(value, outputAs = '') {
90
113
  if (typeof value === 'string') {
@@ -94,7 +117,7 @@ class Image extends core_1.Client {
94
117
  this.qualityData = this.parseQuality(value);
95
118
  this.methodData = this.parseMethod(value);
96
119
  this.opacityValue = this.parseOpacity(value);
97
- this[kCommand] = value;
120
+ this.#command = value;
98
121
  }
99
122
  else {
100
123
  this.resizeData = value.resize;
@@ -103,15 +126,16 @@ class Image extends core_1.Client {
103
126
  this.qualityData = value.quality;
104
127
  this.methodData = value.method;
105
128
  this.opacityValue = value.opacity ?? NaN;
106
- this[kCommand] = '';
129
+ this.#command = '';
107
130
  }
108
- this[kOutputAs] = outputAs;
131
+ this.#outputAs = outputAs;
109
132
  }
110
133
  getCommand() {
111
- return this[kCommand];
134
+ return this.#command;
112
135
  }
113
136
  parseCommand(value) {
114
137
  return {
138
+ value,
115
139
  resize: this.parseResize(value),
116
140
  crop: this.parseCrop(value),
117
141
  rotate: this.parseRotate(value),
@@ -337,9 +361,11 @@ class Image extends core_1.Client {
337
361
  REGEXP_METHOD.lastIndex = 0;
338
362
  return result.length > 0 ? result : null;
339
363
  }
364
+ parseWorker(command, outputType) {
365
+ return null;
366
+ }
340
367
  get outputAs() {
341
- return this[kOutputAs];
368
+ return this.#outputAs;
342
369
  }
343
370
  }
344
- _a = kCommand, _b = kOutputAs;
345
371
  module.exports = Image;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/image",
3
- "version": "0.11.7",
3
+ "version": "0.12.0",
4
4
  "description": "Image constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,6 +20,6 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.11.7"
23
+ "@e-mc/core": "0.12.0"
24
24
  }
25
25
  }
package/types/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { Dimension, Point } from '@e-mc/types/lib/image';
2
2
 
3
- export interface ImageHandler<T, U, V, W = void> {
3
+ export interface ImageHandler<T, U, V, W = void, X = void> {
4
4
  readonly handler: T;
5
5
  host: U | null;
6
6
  instance: V;
7
- method(): void;
7
+ method(): X;
8
8
  resize(): void;
9
9
  crop(): void;
10
10
  opacity(): void;