@cognima/banners 0.0.1-beta

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 (48) hide show
  1. package/assets/fonts/Manrope/Manrope-Bold.ttf +0 -0
  2. package/assets/fonts/Manrope/Manrope-Regular.ttf +0 -0
  3. package/assets/fonts/Others/AbyssinicaSIL-Regular.ttf +0 -0
  4. package/assets/fonts/Others/ChirpRegular.ttf +0 -0
  5. package/assets/fonts/Poppins/Poppins-Bold.ttf +0 -0
  6. package/assets/fonts/Poppins/Poppins-Medium.ttf +0 -0
  7. package/assets/fonts/Poppins/Poppins-Regular.ttf +0 -0
  8. package/assets/placeholders/album_art.png +0 -0
  9. package/assets/placeholders/avatar.png +0 -0
  10. package/assets/placeholders/badge.jpg +0 -0
  11. package/assets/placeholders/badge.png +0 -0
  12. package/assets/placeholders/badge_2.jpg +0 -0
  13. package/assets/placeholders/badge_3.jpg +0 -0
  14. package/assets/placeholders/badge_4.jpg +0 -0
  15. package/assets/placeholders/badge_5.jpg +0 -0
  16. package/assets/placeholders/banner.jpeg +0 -0
  17. package/assets/placeholders/images.jpeg +0 -0
  18. package/index.js +153 -0
  19. package/package.json +34 -0
  20. package/src/animation-effects.js +631 -0
  21. package/src/cache-manager.js +258 -0
  22. package/src/community-banner.js +1536 -0
  23. package/src/constants.js +208 -0
  24. package/src/discord-profile.js +584 -0
  25. package/src/e-commerce-banner.js +1214 -0
  26. package/src/effects.js +355 -0
  27. package/src/error-handler.js +305 -0
  28. package/src/event-banner.js +1319 -0
  29. package/src/facebook-post.js +679 -0
  30. package/src/gradient-welcome.js +430 -0
  31. package/src/image-filters.js +1034 -0
  32. package/src/image-processor.js +1014 -0
  33. package/src/instagram-post.js +504 -0
  34. package/src/interactive-elements.js +1208 -0
  35. package/src/linkedin-post.js +658 -0
  36. package/src/marketing-banner.js +1089 -0
  37. package/src/minimalist-banner.js +892 -0
  38. package/src/modern-profile.js +755 -0
  39. package/src/performance-optimizer.js +216 -0
  40. package/src/telegram-header.js +544 -0
  41. package/src/test-runner.js +645 -0
  42. package/src/tiktok-post.js +713 -0
  43. package/src/twitter-header.js +604 -0
  44. package/src/validator.js +442 -0
  45. package/src/welcome-leave.js +445 -0
  46. package/src/whatsapp-status.js +386 -0
  47. package/src/youtube-thumbnail.js +681 -0
  48. package/utils.js +710 -0
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Módulo de gerenciamento de cache
5
+ *
6
+ * Este módulo fornece funções para gerenciar o cache do módulo @cognima/banners.
7
+ *
8
+ * @module cache-manager
9
+ * @author Cognima Team (melhorado)
10
+ * @version 2.0.0
11
+ */
12
+
13
+ // Cache de imagens
14
+ const imageCache = new Map();
15
+
16
+ // Cache de banners
17
+ const bannerCache = new Map();
18
+
19
+ // Configuração padrão
20
+ let config = {
21
+ enabled: true,
22
+ maxImageCacheSize: 50, // Número máximo de imagens em cache
23
+ maxBannerCacheSize: 20, // Número máximo de banners em cache
24
+ ttl: 3600000, // Tempo de vida do cache em milissegundos (1 hora)
25
+ useFingerprinting: true // Se deve usar fingerprinting para identificar itens de cache
26
+ };
27
+
28
+ /**
29
+ * Gera uma chave de cache para uma imagem
30
+ *
31
+ * @param {string} url - URL da imagem
32
+ * @returns {string} - Chave de cache
33
+ */
34
+ function generateImageCacheKey(url) {
35
+ if (!config.useFingerprinting) return url;
36
+
37
+ // Implementação simplificada de fingerprinting
38
+ const crypto = require('crypto');
39
+ return crypto.createHash('md5').update(url).digest('hex');
40
+ }
41
+
42
+ /**
43
+ * Gera uma chave de cache para um banner
44
+ *
45
+ * @param {string} type - Tipo do banner
46
+ * @param {Object} options - Opções do banner
47
+ * @returns {string} - Chave de cache
48
+ */
49
+ function generateBannerCacheKey(type, options) {
50
+ if (!config.useFingerprinting) return `${type}-${JSON.stringify(options)}`;
51
+
52
+ // Implementação simplificada de fingerprinting
53
+ const crypto = require('crypto');
54
+ return crypto.createHash('md5').update(`${type}-${JSON.stringify(options)}`).digest('hex');
55
+ }
56
+
57
+ /**
58
+ * Adiciona uma imagem ao cache
59
+ *
60
+ * @param {string} url - URL da imagem
61
+ * @param {Object} image - Objeto de imagem
62
+ */
63
+ function cacheImage(url, image) {
64
+ if (!config.enabled) return;
65
+
66
+ try {
67
+ // Verifica se o cache está cheio
68
+ if (imageCache.size >= config.maxImageCacheSize) {
69
+ // Remove o item mais antigo
70
+ const oldestKey = imageCache.keys().next().value;
71
+ imageCache.delete(oldestKey);
72
+ }
73
+
74
+ // Adiciona a imagem ao cache
75
+ const key = generateImageCacheKey(url);
76
+ imageCache.set(key, {
77
+ image,
78
+ timestamp: Date.now()
79
+ });
80
+ } catch (error) {
81
+ console.error('Erro ao adicionar imagem ao cache:', error);
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Obtém uma imagem do cache
87
+ *
88
+ * @param {string} url - URL da imagem
89
+ * @returns {Object|null} - Objeto de imagem ou null se não estiver em cache
90
+ */
91
+ function getCachedImage(url) {
92
+ if (!config.enabled) return null;
93
+
94
+ try {
95
+ const key = generateImageCacheKey(url);
96
+
97
+ if (imageCache.has(key)) {
98
+ const cachedItem = imageCache.get(key);
99
+
100
+ // Verifica se o item expirou
101
+ if (Date.now() - cachedItem.timestamp > config.ttl) {
102
+ imageCache.delete(key);
103
+ return null;
104
+ }
105
+
106
+ return cachedItem.image;
107
+ }
108
+
109
+ return null;
110
+ } catch (error) {
111
+ console.error('Erro ao obter imagem do cache:', error);
112
+ return null;
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Adiciona um banner ao cache
118
+ *
119
+ * @param {string} type - Tipo do banner
120
+ * @param {Object} options - Opções do banner
121
+ * @param {Buffer} buffer - Buffer do banner
122
+ */
123
+ function cacheBanner(type, options, buffer) {
124
+ if (!config.enabled) return;
125
+
126
+ try {
127
+ // Verifica se o cache está cheio
128
+ if (bannerCache.size >= config.maxBannerCacheSize) {
129
+ // Remove o item mais antigo
130
+ const oldestKey = bannerCache.keys().next().value;
131
+ bannerCache.delete(oldestKey);
132
+ }
133
+
134
+ // Adiciona o banner ao cache
135
+ const key = generateBannerCacheKey(type, options);
136
+ bannerCache.set(key, {
137
+ buffer,
138
+ timestamp: Date.now()
139
+ });
140
+ } catch (error) {
141
+ console.error('Erro ao adicionar banner ao cache:', error);
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Obtém um banner do cache
147
+ *
148
+ * @param {string} type - Tipo do banner
149
+ * @param {Object} options - Opções do banner
150
+ * @returns {Buffer|null} - Buffer do banner ou null se não estiver em cache
151
+ */
152
+ function getCachedBanner(type, options) {
153
+ if (!config.enabled) return null;
154
+
155
+ try {
156
+ const key = generateBannerCacheKey(type, options);
157
+
158
+ if (bannerCache.has(key)) {
159
+ const cachedItem = bannerCache.get(key);
160
+
161
+ // Verifica se o item expirou
162
+ if (Date.now() - cachedItem.timestamp > config.ttl) {
163
+ bannerCache.delete(key);
164
+ return null;
165
+ }
166
+
167
+ return cachedItem.buffer;
168
+ }
169
+
170
+ return null;
171
+ } catch (error) {
172
+ console.error('Erro ao obter banner do cache:', error);
173
+ return null;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Limpa o cache de imagens
179
+ */
180
+ function clearImageCache() {
181
+ imageCache.clear();
182
+ }
183
+
184
+ /**
185
+ * Limpa o cache de banners
186
+ */
187
+ function clearBannerCache() {
188
+ bannerCache.clear();
189
+ }
190
+
191
+ /**
192
+ * Limpa todo o cache
193
+ */
194
+ function clearCache() {
195
+ clearImageCache();
196
+ clearBannerCache();
197
+ }
198
+
199
+ /**
200
+ * Define se o cache está habilitado
201
+ *
202
+ * @param {boolean} enabled - Se o cache está habilitado
203
+ */
204
+ function setEnabled(enabled) {
205
+ config.enabled = enabled;
206
+ }
207
+
208
+ /**
209
+ * Configura as opções de cache
210
+ *
211
+ * @param {Object} options - Opções de configuração
212
+ * @param {boolean} [options.enabled] - Se o cache está habilitado
213
+ * @param {number} [options.maxImageCacheSize] - Número máximo de imagens em cache
214
+ * @param {number} [options.maxBannerCacheSize] - Número máximo de banners em cache
215
+ * @param {number} [options.ttl] - Tempo de vida do cache em milissegundos
216
+ * @param {boolean} [options.useFingerprinting] - Se deve usar fingerprinting
217
+ */
218
+ function configure(options) {
219
+ config = { ...config, ...options };
220
+ }
221
+
222
+ /**
223
+ * Obtém a configuração atual
224
+ *
225
+ * @returns {Object} - Configuração atual
226
+ */
227
+ function getConfig() {
228
+ return { ...config };
229
+ }
230
+
231
+ /**
232
+ * Obtém estatísticas do cache
233
+ *
234
+ * @returns {Object} - Estatísticas do cache
235
+ */
236
+ function getStats() {
237
+ return {
238
+ imageCacheSize: imageCache.size,
239
+ bannerCacheSize: bannerCache.size,
240
+ imageCacheKeys: Array.from(imageCache.keys()),
241
+ bannerCacheKeys: Array.from(bannerCache.keys())
242
+ };
243
+ }
244
+
245
+ module.exports = {
246
+ cacheImage,
247
+ getCachedImage,
248
+ cacheBanner,
249
+ getCachedBanner,
250
+ clearImageCache,
251
+ clearBannerCache,
252
+ clearCache,
253
+ setEnabled,
254
+ configure,
255
+ getConfig,
256
+ getStats
257
+ };
258
+