@vinzsocket/baileys 3.3.2 → 3.3.13
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 +21 -0
- package/README.md +1337 -2685
- package/WAProto/WAProto.proto +916 -360
- package/WAProto/fix-imports.js +18 -22
- package/WAProto/index.d.ts +0 -14015
- package/WAProto/index.js +80576 -45941
- package/lib/Defaults/index.d.ts +14 -15
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +109 -98
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +17 -45
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +0 -4
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +0 -6
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +532 -213
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +401 -358
- package/lib/Socket/chats.d.ts +2 -15
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +40 -247
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +641 -269
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/dugong.d.ts +127 -315
- package/lib/Socket/dugong.d.ts.map +1 -0
- package/lib/Socket/dugong.js +749 -653
- package/lib/Socket/dugong.js.map +1 -0
- package/lib/Socket/groups.d.ts +2 -13
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +1 -21
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +631 -256
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +12 -9
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +58 -23
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +181 -645
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +575 -201
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +1552 -1185
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts.map +1 -1
- package/lib/Socket/mex.js +8 -2
- package/lib/Socket/mex.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +18 -11
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +440 -165
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +2 -6
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +25 -59
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Bussines.d.ts +34 -22
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Chat.d.ts +0 -1
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Contact.d.ts +0 -2
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +1 -20
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +1 -4
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +348 -294
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Signal.d.ts +1 -12
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Socket.d.ts +148 -126
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/State.d.ts +0 -58
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +0 -43
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/index.d.ts +52 -52
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +30 -23
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +0 -5
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +0 -12
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.js +0 -1
- package/lib/Utils/chat-utils.d.ts +4 -34
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +20 -80
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/crypto.d.ts +12 -12
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +0 -18
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +0 -34
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +0 -2
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +1 -49
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +2 -2
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +1 -10
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +0 -2
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +9 -12
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +0 -7
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js +0 -1
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +23 -23
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +1 -4
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.d.ts +2 -1
- package/lib/Utils/logger.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +0 -5
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +0 -40
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +13 -16
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +79 -85
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +6 -16
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +1160 -1021
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +1 -103
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/rich-messages.d.ts.map +1 -0
- package/lib/Utils/rich-messages.js.map +1 -0
- package/lib/Utils/signal.d.ts +0 -13
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js +0 -42
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js +0 -1
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +1 -26
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +5 -151
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +2 -12
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/VoIP/audio-feeder.js +8 -0
- package/lib/VoIP/relay-transport.js +15 -1
- package/lib/VoIP/worker-bootstrap.js +14 -2
- package/lib/WABinary/decode.d.ts +1 -1
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +78 -0
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAM/encode.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -26
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/index.d.ts +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +2 -6
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +0 -4
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +0 -8
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +24 -91
- package/engine-requirements.js +0 -27
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Mex.d.ts.map +0 -1
- package/lib/Types/Mex.js +0 -37
- package/lib/Types/Mex.js.map +0 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/companion-reg-client-utils.js.map +0 -1
- package/lib/Utils/mention.d.ts +0 -14
- package/lib/Utils/mention.js +0 -138
- package/lib/Utils/story-card.js +0 -107
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
package/lib/Utils/mention.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
// mention.js
|
|
2
|
-
// Mention helper utilities, used by Socket/dugong.js extended message builders.
|
|
3
|
-
// Ported from baileys-lily, adapted to ESM for Harps-Baileys.
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Normalize mentions to proper JID format
|
|
7
|
-
* @param {string|string[]|null|undefined} mentions
|
|
8
|
-
* @returns {string[]}
|
|
9
|
-
*/
|
|
10
|
-
const mentionCache = new Map();
|
|
11
|
-
|
|
12
|
-
export function normalizeMentions(mentions) {
|
|
13
|
-
const cacheKey = JSON.stringify(mentions);
|
|
14
|
-
if (mentionCache.has(cacheKey)) {
|
|
15
|
-
return mentionCache.get(cacheKey);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!mentions) return [];
|
|
19
|
-
if (!Array.isArray(mentions)) mentions = [mentions];
|
|
20
|
-
|
|
21
|
-
const result = mentions
|
|
22
|
-
.map(jid => {
|
|
23
|
-
if (typeof jid !== 'string') return null;
|
|
24
|
-
jid = jid.trim();
|
|
25
|
-
if (!jid) return null;
|
|
26
|
-
|
|
27
|
-
// Already has @s.whatsapp.net or @lid
|
|
28
|
-
if (jid.includes('@s.whatsapp.net') || jid.includes('@lid')) {
|
|
29
|
-
return jid;
|
|
30
|
-
}
|
|
31
|
-
// Has @ but not complete
|
|
32
|
-
if (jid.includes('@')) {
|
|
33
|
-
return jid;
|
|
34
|
-
}
|
|
35
|
-
// Plain number
|
|
36
|
-
return jid + '@s.whatsapp.net';
|
|
37
|
-
})
|
|
38
|
-
.filter(Boolean);
|
|
39
|
-
|
|
40
|
-
mentionCache.set(cacheKey, result);
|
|
41
|
-
// Simple cache size limit
|
|
42
|
-
if (mentionCache.size > 1000) mentionCache.clear();
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Apply mentions into a message object (used by Socket/dugong.js extended handlers)
|
|
48
|
-
* @param {object} msg - The message content object
|
|
49
|
-
* @param {string|string[]|null} mentions
|
|
50
|
-
* @param {object} contextInfo - Optional contextInfo to also update
|
|
51
|
-
* @returns {object} msg
|
|
52
|
-
*/
|
|
53
|
-
export function applyMentions(msg, mentions, contextInfo = {}) {
|
|
54
|
-
const normalized = normalizeMentions(mentions);
|
|
55
|
-
if (normalized.length === 0) return msg;
|
|
56
|
-
|
|
57
|
-
// messageContextInfo
|
|
58
|
-
if (!msg.messageContextInfo) msg.messageContextInfo = {};
|
|
59
|
-
if (!msg.messageContextInfo.mentionedJid) msg.messageContextInfo.mentionedJid = [];
|
|
60
|
-
|
|
61
|
-
const existing = new Set(msg.messageContextInfo.mentionedJid);
|
|
62
|
-
for (const jid of normalized) {
|
|
63
|
-
if (!existing.has(jid)) {
|
|
64
|
-
msg.messageContextInfo.mentionedJid.push(jid);
|
|
65
|
-
existing.add(jid);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// contextInfo
|
|
70
|
-
if (contextInfo && typeof contextInfo === 'object') {
|
|
71
|
-
if (!contextInfo.mentionedJid) contextInfo.mentionedJid = [];
|
|
72
|
-
for (const jid of normalized) {
|
|
73
|
-
if (!contextInfo.mentionedJid.includes(jid)) {
|
|
74
|
-
contextInfo.mentionedJid.push(jid);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Extra for interactiveMessage
|
|
80
|
-
if (msg.interactiveMessage?.contextInfo) {
|
|
81
|
-
if (!msg.interactiveMessage.contextInfo.mentionedJid) {
|
|
82
|
-
msg.interactiveMessage.contextInfo.mentionedJid = [];
|
|
83
|
-
}
|
|
84
|
-
for (const jid of normalized) {
|
|
85
|
-
if (!msg.interactiveMessage.contextInfo.mentionedJid.includes(jid)) {
|
|
86
|
-
msg.interactiveMessage.contextInfo.mentionedJid.push(jid);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return msg;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Build a "tag all" text block + mentionedJid list from a group's participants,
|
|
96
|
-
* the way you'd get from sock.groupMetadata(jid).participants
|
|
97
|
-
*
|
|
98
|
-
* Handles the WhatsApp "LID" privacy rollout correctly: when a participant's
|
|
99
|
-
* phone number was NOT disclosed by WhatsApp (group addressingMode = 'lid' and
|
|
100
|
-
* no phone_number attr came back), we do NOT print the raw LID digits as if
|
|
101
|
-
* they were a phone number (e.g. "@206244447002720") since that's meaningless
|
|
102
|
-
* to humans. Instead we fall back to the member's display name if you have one
|
|
103
|
-
* (e.g. from your contact store / pushName cache), or a generic label.
|
|
104
|
-
*
|
|
105
|
-
* @param {Array<object>} participants - group.participants from groupMetadata()
|
|
106
|
-
* @param {object} [options]
|
|
107
|
-
* @param {(jid: string) => string|undefined} [options.getDisplayName] - optional lookup (e.g. store.contacts[jid]?.notify)
|
|
108
|
-
* @param {string} [options.header] - text placed above the list
|
|
109
|
-
* @param {string} [options.footer] - text placed below the list
|
|
110
|
-
* @returns {{ text: string, mentions: string[] }}
|
|
111
|
-
*/
|
|
112
|
-
export function buildTagAllText(participants, options = {}) {
|
|
113
|
-
const { getDisplayName, header = '', footer = '' } = options;
|
|
114
|
-
const lines = [];
|
|
115
|
-
const mentions = [];
|
|
116
|
-
|
|
117
|
-
for (const p of participants || []) {
|
|
118
|
-
// Prefer a real phone-number JID when WhatsApp actually disclosed one.
|
|
119
|
-
const realJid = p.jid && p.jid.endsWith('@s.whatsapp.net')
|
|
120
|
-
? p.jid
|
|
121
|
-
: (p.phoneNumber ? (p.phoneNumber.includes('@') ? p.phoneNumber : `${p.phoneNumber}@s.whatsapp.net`) : null);
|
|
122
|
-
const mentionJid = realJid || p.id; // what we actually tag/ping (lid is fine for this)
|
|
123
|
-
|
|
124
|
-
mentions.push(mentionJid);
|
|
125
|
-
|
|
126
|
-
if (realJid) {
|
|
127
|
-
// We know the real phone number — safe & useful to show it.
|
|
128
|
-
lines.push(`@${realJid.split('@')[0]}`);
|
|
129
|
-
} else {
|
|
130
|
-
// LID-only participant: don't print fake-looking digits.
|
|
131
|
-
const name = typeof getDisplayName === 'function' ? getDisplayName(p.id) : null;
|
|
132
|
-
lines.push(name ? `@${name}` : '@Member');
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const body = [header, lines.join('\n'), footer].filter(Boolean).join('\n\n');
|
|
137
|
-
return { text: body, mentions };
|
|
138
|
-
}
|
package/lib/Utils/story-card.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Boom } from '@hapi/boom';
|
|
2
|
-
/**
|
|
3
|
-
* Canvas-rendered "story card" — generates a styled status/story image (gradient
|
|
4
|
-
* background, title, body text, optional footer/branding strip) entirely in JS
|
|
5
|
-
* via Jimp (already an optional peer dependency of this library, no native
|
|
6
|
-
* binary required). Useful for visually distinctive WhatsApp Status / group
|
|
7
|
-
* story (`groupStatusMessageV2`) posts without needing a design tool upstream.
|
|
8
|
-
*
|
|
9
|
-
* Lazily imports `jimp` so this module has zero cost / zero hard dependency
|
|
10
|
-
* for consumers who never call it.
|
|
11
|
-
*/
|
|
12
|
-
let _jimpLib;
|
|
13
|
-
const getJimp = async () => {
|
|
14
|
-
if (_jimpLib) return _jimpLib;
|
|
15
|
-
try {
|
|
16
|
-
// @ts-ignore - optional peer dependency
|
|
17
|
-
const [core, fonts] = await Promise.all([import('jimp'), import('jimp/fonts')]);
|
|
18
|
-
_jimpLib = { ...core, fonts };
|
|
19
|
-
return _jimpLib;
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
throw new Boom('renderStoryCard() requires the optional "jimp" peer dependency. Install it with: npm i jimp', { statusCode: 500 });
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const DEFAULT_GRADIENTS = {
|
|
26
|
-
sunset: [0xff7e5fff, 0xfeb47bff],
|
|
27
|
-
purple: [0x8e2de2ff, 0x4a00e0ff],
|
|
28
|
-
ocean: [0x2193b0ff, 0x6dd5edff],
|
|
29
|
-
forest: [0x134e5eff, 0x71b280ff],
|
|
30
|
-
midnight: [0x232526ff, 0x414345ff],
|
|
31
|
-
fire: [0xf12711ff, 0xf5af19ff]
|
|
32
|
-
};
|
|
33
|
-
const lerpChannel = (a, b, t) => Math.round(a + (b - a) * t);
|
|
34
|
-
const lerpColor = (c1, c2, t, jimpLib) => {
|
|
35
|
-
const { r: r1, g: g1, b: b1, a: a1 } = jimpLib.intToRGBA(c1);
|
|
36
|
-
const { r: r2, g: g2, b: b2, a: a2 } = jimpLib.intToRGBA(c2);
|
|
37
|
-
return jimpLib.rgbaToInt(lerpChannel(r1, r2, t), lerpChannel(g1, g2, t), lerpChannel(b1, b2, t), lerpChannel(a1, a2, t));
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Renders a styled story card and returns a PNG buffer.
|
|
41
|
-
*
|
|
42
|
-
* @param {object} opts
|
|
43
|
-
* @param {string} [opts.title] - large headline text
|
|
44
|
-
* @param {string} [opts.body] - smaller body/subtitle text below the title
|
|
45
|
-
* @param {string} [opts.footer] - small branding/footer line pinned to the bottom
|
|
46
|
-
* @param {'sunset'|'purple'|'ocean'|'forest'|'midnight'|'fire'} [opts.gradient='purple'] - preset background gradient
|
|
47
|
-
* @param {[string|number, string|number]} [opts.colors] - explicit [from, to] ARGB hex colors, overrides `gradient`
|
|
48
|
-
* @param {'vertical'|'diagonal'} [opts.direction='vertical'] - gradient direction
|
|
49
|
-
* @param {number} [opts.width=1080] - canvas width (WA status default is 1080x1920)
|
|
50
|
-
* @param {number} [opts.height=1920] - canvas height
|
|
51
|
-
* @returns {Promise<Buffer>} PNG image buffer, ready to pass as `{ image: buffer }`
|
|
52
|
-
*/
|
|
53
|
-
export const renderStoryCard = async (opts = {}) => {
|
|
54
|
-
const jimpLib = await getJimp();
|
|
55
|
-
const { Jimp, HorizontalAlign, VerticalAlign, loadFont, measureTextHeight, fonts } = jimpLib;
|
|
56
|
-
const width = opts.width || 1080;
|
|
57
|
-
const height = opts.height || 1920;
|
|
58
|
-
const direction = opts.direction || 'vertical';
|
|
59
|
-
const [from, to] = opts.colors || DEFAULT_GRADIENTS[opts.gradient] || DEFAULT_GRADIENTS.purple;
|
|
60
|
-
const colorFrom = typeof from === 'string' ? parseInt(from.replace('#', ''), 16) : from;
|
|
61
|
-
const colorTo = typeof to === 'string' ? parseInt(to.replace('#', ''), 16) : to;
|
|
62
|
-
const image = new Jimp({ width, height, color: colorFrom });
|
|
63
|
-
// Paint the gradient pixel-row-by-row (vertical) or via a diagonal blend factor (diagonal)
|
|
64
|
-
for (let y = 0; y < height; y++) {
|
|
65
|
-
for (let x = 0; x < width; x++) {
|
|
66
|
-
const t = direction === 'diagonal' ? (x / width + y / height) / 2 : y / height;
|
|
67
|
-
image.setPixelColor(lerpColor(colorFrom, colorTo, t, jimpLib), x, y);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const titleFont = await loadFont(fonts.SANS_64_WHITE);
|
|
71
|
-
const bodyFont = await loadFont(fonts.SANS_32_WHITE);
|
|
72
|
-
const footerFont = await loadFont(fonts.SANS_16_WHITE);
|
|
73
|
-
const padding = Math.round(width * 0.08);
|
|
74
|
-
const contentWidth = width - padding * 2;
|
|
75
|
-
let cursorY = Math.round(height * 0.38);
|
|
76
|
-
if (opts.title) {
|
|
77
|
-
const titleHeight = measureTextHeight(titleFont, opts.title, contentWidth);
|
|
78
|
-
image.print({
|
|
79
|
-
font: titleFont,
|
|
80
|
-
x: padding,
|
|
81
|
-
y: cursorY,
|
|
82
|
-
text: { text: opts.title, alignmentX: HorizontalAlign.LEFT, alignmentY: VerticalAlign.TOP },
|
|
83
|
-
maxWidth: contentWidth
|
|
84
|
-
});
|
|
85
|
-
cursorY += titleHeight + Math.round(height * 0.03);
|
|
86
|
-
}
|
|
87
|
-
if (opts.body) {
|
|
88
|
-
image.print({
|
|
89
|
-
font: bodyFont,
|
|
90
|
-
x: padding,
|
|
91
|
-
y: cursorY,
|
|
92
|
-
text: { text: opts.body, alignmentX: HorizontalAlign.LEFT, alignmentY: VerticalAlign.TOP },
|
|
93
|
-
maxWidth: contentWidth
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (opts.footer) {
|
|
97
|
-
image.print({
|
|
98
|
-
font: footerFont,
|
|
99
|
-
x: padding,
|
|
100
|
-
y: height - Math.round(height * 0.06),
|
|
101
|
-
text: { text: opts.footer, alignmentX: HorizontalAlign.LEFT, alignmentY: VerticalAlign.TOP },
|
|
102
|
-
maxWidth: contentWidth
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return image.getBuffer('image/png');
|
|
106
|
-
};
|
|
107
|
-
export const STORY_GRADIENTS = Object.keys(DEFAULT_GRADIENTS);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync.js';
|
|
2
|
-
import { type BinaryNode } from '../../WABinary/index.js';
|
|
3
|
-
import { USyncUser } from '../USyncUser.js';
|
|
4
|
-
export declare class USyncUsernameProtocol implements USyncQueryProtocol {
|
|
5
|
-
name: string;
|
|
6
|
-
getQueryElement(): BinaryNode;
|
|
7
|
-
getUserElement(user: USyncUser): BinaryNode | null;
|
|
8
|
-
parser(node: BinaryNode): string | null;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=USyncUsernameProtocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"USyncUsernameProtocol.d.ts","sourceRoot":"","sources":["../../../src/WAUSync/Protocols/USyncUsernameProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,qBAAa,qBAAsB,YAAW,kBAAkB;IAC/D,IAAI,SAAa;IAEjB,eAAe,IAAI,UAAU;IAO7B,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,IAAI;IAKlD,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI;CAQvC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
import { USyncUser } from '../USyncUser.js';
|
|
3
|
-
export class USyncUsernameProtocol {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.name = 'username';
|
|
6
|
-
}
|
|
7
|
-
getQueryElement() {
|
|
8
|
-
return {
|
|
9
|
-
tag: 'username',
|
|
10
|
-
attrs: {}
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
getUserElement(user) {
|
|
14
|
-
void user;
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
parser(node) {
|
|
18
|
-
if (node.tag === 'username') {
|
|
19
|
-
assertNodeErrorFree(node);
|
|
20
|
-
return typeof node.content === 'string' ? node.content : null;
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=USyncUsernameProtocol.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"USyncUsernameProtocol.js","sourceRoot":"","sources":["../../../src/WAUSync/Protocols/USyncUsernameProtocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAmB,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,OAAO,qBAAqB;IAAlC;QACC,SAAI,GAAG,UAAU,CAAA;IAsBlB,CAAC;IApBA,eAAe;QACd,OAAO;YACN,GAAG,EAAE,UAAU;YACf,KAAK,EAAE,EAAE;SACT,CAAA;IACF,CAAC;IAED,cAAc,CAAC,IAAe;QAC7B,KAAK,IAAI,CAAA;QACT,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,MAAM,CAAC,IAAgB;QACtB,IAAI,IAAI,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;YAC7B,mBAAmB,CAAC,IAAI,CAAC,CAAA;YACzB,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;QAC9D,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
|