@ryuu-reinzz/haruka-lib 1.2.20 → 2.0.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.
Files changed (44) hide show
  1. package/main/index.js +4 -1
  2. package/main/socket.js +2 -2
  3. package/main/sticker-engine/java-script/Sticker.d.ts +130 -0
  4. package/main/sticker-engine/java-script/Sticker.js +187 -0
  5. package/main/sticker-engine/java-script/Types.d.ts +43 -0
  6. package/main/sticker-engine/java-script/Types.js +1 -0
  7. package/main/sticker-engine/java-script/Utils.d.ts +9 -0
  8. package/main/sticker-engine/java-script/Utils.js +11 -0
  9. package/main/sticker-engine/java-script/extractMetadata.d.ts +6 -0
  10. package/main/sticker-engine/java-script/extractMetadata.js +11 -0
  11. package/main/sticker-engine/java-script/index.d.ts +8 -0
  12. package/main/sticker-engine/java-script/index.js +8 -0
  13. package/main/sticker-engine/java-script/internal/Metadata/Exif.d.ts +9 -0
  14. package/main/sticker-engine/java-script/internal/Metadata/Exif.js +34 -0
  15. package/main/sticker-engine/java-script/internal/Metadata/RawMetadata.d.ts +8 -0
  16. package/main/sticker-engine/java-script/internal/Metadata/RawMetadata.js +9 -0
  17. package/main/sticker-engine/java-script/internal/Metadata/StickerMetadata.d.ts +18 -0
  18. package/main/sticker-engine/java-script/internal/Metadata/StickerMetadata.js +49 -0
  19. package/main/sticker-engine/java-script/internal/Metadata/StickerTypes.d.ts +7 -0
  20. package/main/sticker-engine/java-script/internal/Metadata/StickerTypes.js +8 -0
  21. package/main/sticker-engine/java-script/internal/convert.d.ts +3 -0
  22. package/main/sticker-engine/java-script/internal/convert.js +69 -0
  23. package/main/sticker-engine/java-script/internal/crop.d.ts +2 -0
  24. package/main/sticker-engine/java-script/internal/crop.js +30 -0
  25. package/main/sticker-engine/java-script/internal/imagesToWebp.d.ts +2 -0
  26. package/main/sticker-engine/java-script/internal/imagesToWebp.js +17 -0
  27. package/main/sticker-engine/java-script/internal/videoToGif.d.ts +3 -0
  28. package/main/sticker-engine/java-script/internal/videoToGif.js +16 -0
  29. package/main/sticker-engine/type-script/Sticker.ts +206 -0
  30. package/main/sticker-engine/type-script/Types.ts +189 -0
  31. package/main/sticker-engine/type-script/Utils.ts +12 -0
  32. package/main/sticker-engine/type-script/extractMetadata.ts +13 -0
  33. package/main/sticker-engine/type-script/index.ts +9 -0
  34. package/main/sticker-engine/type-script/internal/Metadata/Exif.ts +39 -0
  35. package/main/sticker-engine/type-script/internal/Metadata/RawMetadata.ts +15 -0
  36. package/main/sticker-engine/type-script/internal/Metadata/StickerMetadata.ts +60 -0
  37. package/main/sticker-engine/type-script/internal/Metadata/StickerTypes.ts +7 -0
  38. package/main/sticker-engine/type-script/internal/convert.ts +87 -0
  39. package/main/sticker-engine/type-script/internal/crop.ts +32 -0
  40. package/main/sticker-engine/type-script/internal/imagesToWebp.ts +19 -0
  41. package/main/sticker-engine/type-script/internal/node-webpmux.d.ts +8 -0
  42. package/main/sticker-engine/type-script/internal/videoToGif.ts +18 -0
  43. package/package.json +12 -3
  44. package/tsconfig.json +13 -0
package/main/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import addProperty from "./socket.js";
2
2
  import useSQLiteAuthState from "./sqliteAuth.js";
3
+ import Sticker from './sticker-engine/java-script/index.js';
3
4
 
4
5
  const haruka = {
5
6
  addProperty,
6
7
  useSQLiteAuthState
7
8
  };
8
9
 
9
- export default haruka;
10
+ export default haruka;
11
+
12
+ export { Sticker };
package/main/socket.js CHANGED
@@ -4,8 +4,7 @@ import fs from "fs";
4
4
  import path from "path";
5
5
  import { fileURLToPath } from 'url';
6
6
  import { dirname } from 'path';
7
- import stkPkg from 'wa-sticker-formatter';
8
- const { Sticker } = stkPkg;
7
+ import Sticker from './sticker-engine/java-script/index.js';
9
8
  const __filename = fileURLToPath(import.meta.url);
10
9
  const __dirname = dirname(__filename);
11
10
 
@@ -171,6 +170,7 @@ Object.assign(socket, {
171
170
  image = null,
172
171
  video = null,
173
172
  document = null,
173
+ fileName = null,
174
174
  mimetype = null,
175
175
  jpegThumbnail = null,
176
176
  location = null,
@@ -0,0 +1,130 @@
1
+ import { IStickerOptions } from './Types';
2
+ import { StickerTypes } from './internal/Metadata/StickerTypes';
3
+ import { Categories } from '.';
4
+ import { Color } from 'sharp';
5
+ /**
6
+ * Sticker class
7
+ */
8
+ export declare class Sticker {
9
+ private data;
10
+ metadata: Partial<IStickerOptions>;
11
+ /**
12
+ * Sticker Constructor
13
+ * @param {string|Buffer} [data] - File path, url or Buffer of the image/video to be converted
14
+ * @param {IStickerOptions} [options] - Sticker options
15
+ */
16
+ constructor(data: string | Buffer, metadata?: Partial<IStickerOptions>);
17
+ private _parse;
18
+ private _getMimeType;
19
+ /**
20
+ * Builds the sticker
21
+ * @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
22
+ * @example
23
+ * const sticker = new Sticker('./image.png')
24
+ * const buffer = sticker.build()
25
+ */
26
+ build: () => Promise<Buffer>;
27
+ /**
28
+ * Alias for `.build()`
29
+ * @param {string} [type] - How you want your sticker to look like
30
+ * @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
31
+ * @example
32
+ * const sticker = new Sticker('./image.png')
33
+ * const buffer = sticker.build()
34
+ */
35
+ toBuffer: () => Promise<Buffer>;
36
+ get defaultFilename(): string;
37
+ /**
38
+ * Saves the sticker to a file
39
+ * @param [filename] - Filename to save the sticker to
40
+ * @returns filename
41
+ * @example
42
+ * const sticker = new Sticker('./image.png')
43
+ * sticker.toFile('./image.webp')
44
+ */
45
+ toFile: (filename?: string) => Promise<string>;
46
+ /**
47
+ * Set the sticker pack title
48
+ * @param pack - Sticker Pack Title
49
+ * @returns {this}
50
+ * @example
51
+ * const sticker = new Sticker('./image.png')
52
+ * sticker.setPack('My Sticker Pack')
53
+ * sticker.build()
54
+ */
55
+ setPack: (pack: string) => this;
56
+ /**
57
+ * Set the sticker pack author
58
+ * @param author - Sticker Pack Author
59
+ * @returns
60
+ */
61
+ setAuthor: (author: string) => this;
62
+ /**
63
+ * Set the sticker pack ID
64
+ * @param id - Sticker Pack ID
65
+ * @returns {this}
66
+ * @example
67
+ * const sticker = new Sticker('./image.png')
68
+ * sticker.setID('my-sticker-pack')
69
+ * sticker.build()
70
+ */
71
+ setID: (id: string) => this;
72
+ /**
73
+ * Set the sticker category
74
+ * @param categories - Sticker Category
75
+ * @returns {this}
76
+ * @example
77
+ * const sticker = new Sticker('./image.png')
78
+ * sticker.setCategories(['🌹'])
79
+ */
80
+ setCategories: (categories: Categories[]) => this;
81
+ /**
82
+ * Set the sticker type
83
+ * @param {StickerTypes|string}[type] - Sticker Type
84
+ * @returns {this}
85
+ */
86
+ setType: (type: StickerTypes | string) => this;
87
+ /**
88
+ * Set the sticker quality
89
+ * @param {number}[quality] - Sticker Quality
90
+ * @returns {this}
91
+ */
92
+ setQuality: (quality: number) => this;
93
+ /**
94
+ * Set the background color for `full` images
95
+ * @param {Color}[background] - Background color
96
+ * @returns {this}
97
+ */
98
+ setBackground: (background: Color) => this;
99
+ /**
100
+ * @deprecated
101
+ * Use the `Sticker.build()` method instead
102
+ */
103
+ get: () => Promise<Buffer>;
104
+ /**
105
+ * Get BaileysMD-compatible message object
106
+ * @returns {{ sticker: Buffer }}
107
+ * @example
108
+ * import { create } from '@adiwajshing/baileys-md'
109
+ * const conn = create()
110
+ * ...
111
+ * const sticker = new Sticker('./image.png', { pack: 'My Sticker Pack', author: 'Me' })
112
+ * const message = await sticker.toMessage()
113
+ * conn.sendMessage(jid, message)
114
+ */
115
+ toMessage: () => Promise<{
116
+ sticker: Buffer;
117
+ }>;
118
+ /**
119
+ * Extracts metadata from a WebP image.
120
+ * @param {Buffer}image - The image buffer to extract metadata from
121
+ */
122
+ static extractMetadata: (image: Buffer) => Promise<Partial<import("./Types").IRawMetadata>>;
123
+ }
124
+ /**
125
+ *
126
+ * @param {string|Buffer} data - File path, url or Buffer of the image/video to be converted
127
+ * @param {IStickerOptions} [options] - Sticker options
128
+ * @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
129
+ */
130
+ export declare const createSticker: (...args: ConstructorParameters<typeof Sticker>) => Promise<Buffer>;
@@ -0,0 +1,187 @@
1
+ import { existsSync, readFile, writeFile } from 'fs-extra';
2
+ import axios from 'axios';
3
+ import Utils, { defaultBg } from './Utils';
4
+ import { fromBuffer } from 'file-type';
5
+ import convert from './internal/convert';
6
+ import Exif from './internal/Metadata/Exif';
7
+ import { StickerTypes } from './internal/Metadata/StickerTypes';
8
+ import { extractMetadata } from '.';
9
+ /**
10
+ * Sticker class
11
+ */
12
+ export class Sticker {
13
+ /**
14
+ * Sticker Constructor
15
+ * @param {string|Buffer} [data] - File path, url or Buffer of the image/video to be converted
16
+ * @param {IStickerOptions} [options] - Sticker options
17
+ */
18
+ constructor(data, metadata = {}) {
19
+ this.data = data;
20
+ this.metadata = metadata;
21
+ this._parse = async () => Buffer.isBuffer(this.data)
22
+ ? this.data
23
+ : this.data.trim().startsWith('<svg')
24
+ ? Buffer.from(this.data)
25
+ : (async () => existsSync(this.data)
26
+ ? readFile(this.data)
27
+ : axios.get(this.data, { responseType: 'arraybuffer' }).then(({ data }) => data))();
28
+ this._getMimeType = async (data) => {
29
+ const type = await fromBuffer(data);
30
+ if (!type) {
31
+ if (typeof this.data === 'string')
32
+ return 'image/svg+xml';
33
+ throw new Error('Invalid file type');
34
+ }
35
+ return type.mime;
36
+ };
37
+ /**
38
+ * Builds the sticker
39
+ * @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
40
+ * @example
41
+ * const sticker = new Sticker('./image.png')
42
+ * const buffer = sticker.build()
43
+ */
44
+ this.build = async () => {
45
+ const data = await this._parse();
46
+ const mime = await this._getMimeType(data);
47
+ return new Exif(this.metadata).add(await convert(data, mime, this.metadata));
48
+ };
49
+ /**
50
+ * Alias for `.build()`
51
+ * @param {string} [type] - How you want your sticker to look like
52
+ * @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
53
+ * @example
54
+ * const sticker = new Sticker('./image.png')
55
+ * const buffer = sticker.build()
56
+ */
57
+ this.toBuffer = this.build;
58
+ /**
59
+ * Saves the sticker to a file
60
+ * @param [filename] - Filename to save the sticker to
61
+ * @returns filename
62
+ * @example
63
+ * const sticker = new Sticker('./image.png')
64
+ * sticker.toFile('./image.webp')
65
+ */
66
+ this.toFile = async (filename = this.defaultFilename) => {
67
+ await writeFile(filename, await this.build());
68
+ return filename;
69
+ };
70
+ /**
71
+ * Set the sticker pack title
72
+ * @param pack - Sticker Pack Title
73
+ * @returns {this}
74
+ * @example
75
+ * const sticker = new Sticker('./image.png')
76
+ * sticker.setPack('My Sticker Pack')
77
+ * sticker.build()
78
+ */
79
+ this.setPack = (pack) => {
80
+ this.metadata.pack = pack;
81
+ return this;
82
+ };
83
+ /**
84
+ * Set the sticker pack author
85
+ * @param author - Sticker Pack Author
86
+ * @returns
87
+ */
88
+ this.setAuthor = (author) => {
89
+ this.metadata.author = author;
90
+ return this;
91
+ };
92
+ /**
93
+ * Set the sticker pack ID
94
+ * @param id - Sticker Pack ID
95
+ * @returns {this}
96
+ * @example
97
+ * const sticker = new Sticker('./image.png')
98
+ * sticker.setID('my-sticker-pack')
99
+ * sticker.build()
100
+ */
101
+ this.setID = (id) => {
102
+ this.metadata.id = id;
103
+ return this;
104
+ };
105
+ /**
106
+ * Set the sticker category
107
+ * @param categories - Sticker Category
108
+ * @returns {this}
109
+ * @example
110
+ * const sticker = new Sticker('./image.png')
111
+ * sticker.setCategories(['🌹'])
112
+ */
113
+ this.setCategories = (categories) => {
114
+ this.metadata.categories = categories;
115
+ return this;
116
+ };
117
+ /**
118
+ * Set the sticker type
119
+ * @param {StickerTypes|string}[type] - Sticker Type
120
+ * @returns {this}
121
+ */
122
+ this.setType = (type) => {
123
+ this.metadata.type = type;
124
+ return this;
125
+ };
126
+ /**
127
+ * Set the sticker quality
128
+ * @param {number}[quality] - Sticker Quality
129
+ * @returns {this}
130
+ */
131
+ this.setQuality = (quality) => {
132
+ this.metadata.quality = quality;
133
+ return this;
134
+ };
135
+ /**
136
+ * Set the background color for `full` images
137
+ * @param {Color}[background] - Background color
138
+ * @returns {this}
139
+ */
140
+ this.setBackground = (background) => {
141
+ this.metadata.background = background;
142
+ return this;
143
+ };
144
+ /**
145
+ * @deprecated
146
+ * Use the `Sticker.build()` method instead
147
+ */
148
+ this.get = this.build;
149
+ /**
150
+ * Get BaileysMD-compatible message object
151
+ * @returns {{ sticker: Buffer }}
152
+ * @example
153
+ * import { create } from '@adiwajshing/baileys-md'
154
+ * const conn = create()
155
+ * ...
156
+ * const sticker = new Sticker('./image.png', { pack: 'My Sticker Pack', author: 'Me' })
157
+ * const message = await sticker.toMessage()
158
+ * conn.sendMessage(jid, message)
159
+ */
160
+ this.toMessage = async () => ({ sticker: await this.build() });
161
+ this.metadata.author = this.metadata.author ?? '';
162
+ this.metadata.pack = this.metadata.pack ?? '';
163
+ this.metadata.id = this.metadata.id ?? Utils.generateStickerID();
164
+ this.metadata.quality = this.metadata.quality ?? 100;
165
+ this.metadata.type = Object.values(StickerTypes).includes(this.metadata.type)
166
+ ? this.metadata.type
167
+ : StickerTypes.DEFAULT;
168
+ this.metadata.background = this.metadata.background ?? defaultBg;
169
+ }
170
+ get defaultFilename() {
171
+ return `./${this.metadata.pack}-${this.metadata.author}.webp`;
172
+ }
173
+ }
174
+ /**
175
+ * Extracts metadata from a WebP image.
176
+ * @param {Buffer}image - The image buffer to extract metadata from
177
+ */
178
+ Sticker.extractMetadata = extractMetadata;
179
+ /**
180
+ *
181
+ * @param {string|Buffer} data - File path, url or Buffer of the image/video to be converted
182
+ * @param {IStickerOptions} [options] - Sticker options
183
+ * @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
184
+ */
185
+ export const createSticker = async (...args) => {
186
+ return new Sticker(...args).build();
187
+ };
@@ -0,0 +1,43 @@
1
+ import sharp, { Color } from 'sharp';
2
+ import { StickerTypes } from './internal/Metadata/StickerTypes';
3
+ /** Sticker metadata config */
4
+ export interface IStickerConfig {
5
+ /** Sticker Pack title*/
6
+ pack?: string;
7
+ /** Sticker Pack Author*/
8
+ author?: string;
9
+ /** Sticker Pack ID*/
10
+ id?: string;
11
+ /** Sticker Category*/
12
+ categories?: Categories[];
13
+ }
14
+ export interface IStickerOptions extends IStickerConfig {
15
+ /** How you want your sticker to look like
16
+ * Can be crop or full. Defaults to 'default' (no changes)
17
+ */
18
+ type?: StickerTypes | string;
19
+ /**
20
+ * Quality of the output webp image. Must be an integer from 0 to 100 (defaults to 100
21
+ */
22
+ quality?: sharp.WebpOptions['quality'];
23
+ /**
24
+ * Background Color of the sticker (only for type full)
25
+ */
26
+ background?: Color;
27
+ }
28
+ export interface IRawMetadata {
29
+ emojis: string[];
30
+ 'sticker-pack-id': string;
31
+ 'sticker-pack-name': string;
32
+ 'sticker-pack-publisher': string;
33
+ }
34
+ export type Metadata = IStickerConfig | IStickerOptions;
35
+ type Love = '❤' | '😍' | '😘' | '💕' | '😻' | '💑' | '👩‍❤‍👩' | '👨‍❤‍👨' | '💏' | '👩‍❤‍💋‍👩' | '👨‍❤‍💋‍👨' | '🧡' | '💛' | '💚' | '💙' | '💜' | '🖤' | '💔' | '❣' | '💞' | '💓' | '💗' | '💖' | '💘' | '💝' | '💟' | '♥' | '💌' | '💋' | '👩‍❤️‍💋‍👩' | '👨‍❤️‍💋‍👨' | '👩‍❤️‍👨' | '👩‍❤️‍👩' | '👨‍❤️‍👨' | '👩‍❤️‍💋‍👨' | '👬' | '👭' | '👫' | '🥰' | '😚' | '😙' | '👄' | '🌹' | '😽' | '❣️' | '❤️';
36
+ type Happy = '😀' | '😃' | '😄' | '😁' | '😆' | '😅' | '😂' | '🤣' | '🙂' | '😛' | '😝' | '😜' | '🤪' | '🤗' | '😺' | '😸' | '😹' | '☺' | '😌' | '😉' | '🤗' | '😊';
37
+ type Sad = '☹' | '😣' | '😖' | '😫' | '😩' | '😢' | '😭' | '😞' | '😔' | '😟' | '😕' | '😤' | '😠' | '😥' | '😰' | '😨' | '😿' | '😾' | '😓' | '🙍‍♂' | '🙍‍♀' | '💔' | '🙁' | '🥺' | '🤕' | '☔️' | '⛈' | '🌩' | '🌧';
38
+ type Angry = '😯' | '😦' | '😧' | '😮' | '😲' | '🙀' | '😱' | '🤯' | '😳' | '❗' | '❕' | '🤬' | '😡' | '😠' | '🙄' | '👿' | '😾' | '😤' | '💢' | '👺' | '🗯️' | '😒' | '🥵';
39
+ type Greet = '👋';
40
+ type Celebrate = '🎊' | '🎉' | '🎁' | '🎈' | '👯‍♂️' | '👯' | '👯‍♀️' | '💃' | '🕺' | '🔥' | '⭐️' | '✨' | '💫' | '🎇' | '🎆' | '🍻' | '🥂' | '🍾' | '🎂' | '🍰';
41
+ /** Sticker Category. Learn More: https://github.com/WhatsApp/stickers/wiki/Tag-your-stickers-with-Emojis*/
42
+ export type Categories = Love | Happy | Sad | Angry | Greet | Celebrate;
43
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export default abstract class Utils {
2
+ static generateStickerID: () => string;
3
+ }
4
+ export declare const defaultBg: {
5
+ r: number;
6
+ g: number;
7
+ b: number;
8
+ alpha: number;
9
+ };
@@ -0,0 +1,11 @@
1
+ import { randomBytes } from 'crypto';
2
+ class Utils {
3
+ }
4
+ Utils.generateStickerID = () => randomBytes(32).toString('hex');
5
+ export default Utils;
6
+ export const defaultBg = {
7
+ r: 0,
8
+ g: 0,
9
+ b: 0,
10
+ alpha: 0
11
+ };
@@ -0,0 +1,6 @@
1
+ import { IRawMetadata } from '.';
2
+ /**
3
+ * Extracts metadata from a WebP image.
4
+ * @param {Buffer}image - The image buffer to extract metadata from
5
+ */
6
+ export declare const extractMetadata: (image: Buffer) => Promise<Partial<IRawMetadata>>;
@@ -0,0 +1,11 @@
1
+ import { Image } from 'node-webpmux';
2
+ /**
3
+ * Extracts metadata from a WebP image.
4
+ * @param {Buffer}image - The image buffer to extract metadata from
5
+ */
6
+ export const extractMetadata = async (image) => {
7
+ const img = new Image();
8
+ await img.load(image);
9
+ const exif = img.exif?.toString('utf-8') ?? '{}';
10
+ return JSON.parse(exif.substring(exif.indexOf('{'), exif.lastIndexOf('}') + 1) ?? '{}');
11
+ };
@@ -0,0 +1,8 @@
1
+ import { Sticker } from './Sticker';
2
+ export * from './Sticker';
3
+ export * from './extractMetadata';
4
+ export * from './Types';
5
+ export { default as StickerMetadata } from './internal/Metadata/StickerMetadata';
6
+ export { default as Exif } from './internal/Metadata/Exif';
7
+ export * from './internal/Metadata/StickerTypes';
8
+ export default Sticker;
@@ -0,0 +1,8 @@
1
+ import { Sticker } from './Sticker';
2
+ export * from './Sticker';
3
+ export * from './extractMetadata';
4
+ export * from './Types';
5
+ export { default as StickerMetadata } from './internal/Metadata/StickerMetadata';
6
+ export { default as Exif } from './internal/Metadata/Exif';
7
+ export * from './internal/Metadata/StickerTypes';
8
+ export default Sticker;
@@ -0,0 +1,9 @@
1
+ import { Image } from 'node-webpmux';
2
+ import { Metadata } from '../../Types';
3
+ export default class Exif {
4
+ private data;
5
+ private exif;
6
+ constructor(options: Metadata);
7
+ build: () => Buffer;
8
+ add: (image: string | Buffer | Image) => Promise<Buffer>;
9
+ }
@@ -0,0 +1,34 @@
1
+ import { Image } from 'node-webpmux';
2
+ import { TextEncoder } from 'util';
3
+ import RawMetadata from './RawMetadata';
4
+ export default class Exif {
5
+ constructor(options) {
6
+ this.exif = null;
7
+ this.build = () => {
8
+ const data = JSON.stringify(this.data);
9
+ const exif = Buffer.concat([
10
+ Buffer.from([
11
+ 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00,
12
+ 0x00, 0x16, 0x00, 0x00, 0x00
13
+ ]),
14
+ Buffer.from(data, 'utf-8')
15
+ ]);
16
+ exif.writeUIntLE(new TextEncoder().encode(data).length, 14, 4);
17
+ return exif;
18
+ };
19
+ this.add = async (image) => {
20
+ const exif = this.exif || this.build();
21
+ image =
22
+ image instanceof Image
23
+ ? image
24
+ : await (async () => {
25
+ const img = new Image();
26
+ await img.load(image);
27
+ return img;
28
+ })();
29
+ image.exif = exif;
30
+ return await image.save(null);
31
+ };
32
+ this.data = new RawMetadata(options);
33
+ }
34
+ }
@@ -0,0 +1,8 @@
1
+ import { IRawMetadata, Metadata } from '../../Types';
2
+ export default class RawMetadata implements IRawMetadata {
3
+ emojis: string[];
4
+ 'sticker-pack-id': string;
5
+ 'sticker-pack-name': string;
6
+ 'sticker-pack-publisher': string;
7
+ constructor(options: Metadata);
8
+ }
@@ -0,0 +1,9 @@
1
+ import Utils from '../../Utils';
2
+ export default class RawMetadata {
3
+ constructor(options) {
4
+ this['sticker-pack-id'] = options.id || Utils.generateStickerID();
5
+ this['sticker-pack-name'] = options.pack || '';
6
+ this['sticker-pack-publisher'] = options.author || '';
7
+ this.emojis = options.categories || [];
8
+ }
9
+ }
@@ -0,0 +1,18 @@
1
+ import { Categories, IStickerConfig, IStickerOptions } from '../../Types';
2
+ export default class StickerMetadata implements IStickerOptions {
3
+ pack: string;
4
+ author: string;
5
+ categories: Categories[];
6
+ id: string;
7
+ crop: boolean;
8
+ full: boolean;
9
+ constructor(pack?: string, author?: string, categories?: Categories[], id?: string);
10
+ static from: (object: Partial<StickerMetadata>) => StickerMetadata;
11
+ setPack: (title: string) => this;
12
+ setAuthor: (author: string) => this;
13
+ setId: (id: string) => this;
14
+ setCrop: (value: boolean) => this;
15
+ setFull: (value: boolean) => this;
16
+ setCategories: (categories: string | string[]) => this;
17
+ toJSON: () => IStickerConfig;
18
+ }
@@ -0,0 +1,49 @@
1
+ import Utils from '../../Utils';
2
+ class StickerMetadata {
3
+ constructor(pack = '', author = '', categories = [], id = Utils.generateStickerID()) {
4
+ this.pack = pack;
5
+ this.author = author;
6
+ this.categories = categories;
7
+ this.id = id;
8
+ this.crop = false;
9
+ this.full = false;
10
+ this.setPack = (title) => {
11
+ this.pack = title;
12
+ return this;
13
+ };
14
+ this.setAuthor = (author) => {
15
+ this.author = author;
16
+ return this;
17
+ };
18
+ this.setId = (id) => {
19
+ this.id = id;
20
+ return this;
21
+ };
22
+ this.setCrop = (value) => {
23
+ this.crop = value;
24
+ this.full = !value;
25
+ return this;
26
+ };
27
+ this.setFull = (value) => {
28
+ this.crop = !value;
29
+ this.full = value;
30
+ return this;
31
+ };
32
+ this.setCategories = (categories) => {
33
+ this.categories = (typeof categories === 'string' ? categories.split(',').map((emoji) => emoji.trim()) : categories);
34
+ return this;
35
+ };
36
+ this.toJSON = () => {
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ const obj = {};
39
+ Object.keys(this)
40
+ .filter((key) => typeof this[key] !== 'function')
41
+ .forEach((key) => (obj[key] = this[key]));
42
+ return obj;
43
+ };
44
+ }
45
+ }
46
+ StickerMetadata.from = (object) => {
47
+ return new StickerMetadata(object.pack, object.author, object.categories, object.id);
48
+ };
49
+ export default StickerMetadata;
@@ -0,0 +1,7 @@
1
+ export declare enum StickerTypes {
2
+ DEFAULT = "default",
3
+ CROPPED = "crop",
4
+ FULL = "full",
5
+ CIRCLE = "circle",
6
+ ROUNDED = "rounded"
7
+ }
@@ -0,0 +1,8 @@
1
+ export var StickerTypes;
2
+ (function (StickerTypes) {
3
+ StickerTypes["DEFAULT"] = "default";
4
+ StickerTypes["CROPPED"] = "crop";
5
+ StickerTypes["FULL"] = "full";
6
+ StickerTypes["CIRCLE"] = "circle";
7
+ StickerTypes["ROUNDED"] = "rounded";
8
+ })(StickerTypes || (StickerTypes = {}));
@@ -0,0 +1,3 @@
1
+ import { IStickerOptions } from '..';
2
+ declare const convert: (data: Buffer, mime: string, { quality, background, type }: IStickerOptions) => Promise<Buffer>;
3
+ export default convert;