@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.
- package/assets/fonts/Manrope/Manrope-Bold.ttf +0 -0
- package/assets/fonts/Manrope/Manrope-Regular.ttf +0 -0
- package/assets/fonts/Others/AbyssinicaSIL-Regular.ttf +0 -0
- package/assets/fonts/Others/ChirpRegular.ttf +0 -0
- package/assets/fonts/Poppins/Poppins-Bold.ttf +0 -0
- package/assets/fonts/Poppins/Poppins-Medium.ttf +0 -0
- package/assets/fonts/Poppins/Poppins-Regular.ttf +0 -0
- package/assets/placeholders/album_art.png +0 -0
- package/assets/placeholders/avatar.png +0 -0
- package/assets/placeholders/badge.jpg +0 -0
- package/assets/placeholders/badge.png +0 -0
- package/assets/placeholders/badge_2.jpg +0 -0
- package/assets/placeholders/badge_3.jpg +0 -0
- package/assets/placeholders/badge_4.jpg +0 -0
- package/assets/placeholders/badge_5.jpg +0 -0
- package/assets/placeholders/banner.jpeg +0 -0
- package/assets/placeholders/images.jpeg +0 -0
- package/index.js +153 -0
- package/package.json +34 -0
- package/src/animation-effects.js +631 -0
- package/src/cache-manager.js +258 -0
- package/src/community-banner.js +1536 -0
- package/src/constants.js +208 -0
- package/src/discord-profile.js +584 -0
- package/src/e-commerce-banner.js +1214 -0
- package/src/effects.js +355 -0
- package/src/error-handler.js +305 -0
- package/src/event-banner.js +1319 -0
- package/src/facebook-post.js +679 -0
- package/src/gradient-welcome.js +430 -0
- package/src/image-filters.js +1034 -0
- package/src/image-processor.js +1014 -0
- package/src/instagram-post.js +504 -0
- package/src/interactive-elements.js +1208 -0
- package/src/linkedin-post.js +658 -0
- package/src/marketing-banner.js +1089 -0
- package/src/minimalist-banner.js +892 -0
- package/src/modern-profile.js +755 -0
- package/src/performance-optimizer.js +216 -0
- package/src/telegram-header.js +544 -0
- package/src/test-runner.js +645 -0
- package/src/tiktok-post.js +713 -0
- package/src/twitter-header.js +604 -0
- package/src/validator.js +442 -0
- package/src/welcome-leave.js +445 -0
- package/src/whatsapp-status.js +386 -0
- package/src/youtube-thumbnail.js +681 -0
- package/utils.js +710 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Módulo de otimização de performance
|
|
5
|
+
*
|
|
6
|
+
* Este módulo fornece funções para otimizar a performance do módulo @cognima/banners.
|
|
7
|
+
*
|
|
8
|
+
* @module performance-optimizer
|
|
9
|
+
* @author Cognima Team (melhorado)
|
|
10
|
+
* @version 2.0.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Configuração padrão
|
|
14
|
+
let config = {
|
|
15
|
+
enabled: true,
|
|
16
|
+
imageResizeThreshold: 2000, // Tamanho máximo de imagem em pixels (largura ou altura)
|
|
17
|
+
imageQualityFactor: 0.9, // Fator de qualidade para compressão de imagens
|
|
18
|
+
useWebWorkers: true, // Se deve usar Web Workers para processamento paralelo
|
|
19
|
+
maxConcurrentOperations: 4, // Número máximo de operações concorrentes
|
|
20
|
+
useMemoryOptimization: true, // Se deve otimizar o uso de memória
|
|
21
|
+
garbageCollectionInterval: 10, // Intervalo para coleta de lixo (em operações)
|
|
22
|
+
operationCount: 0 // Contador de operações
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Otimiza uma imagem para melhor performance
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} image - Objeto de imagem
|
|
29
|
+
* @returns {Object} - Imagem otimizada
|
|
30
|
+
*/
|
|
31
|
+
function optimizeImage(image) {
|
|
32
|
+
if (!config.enabled) return image;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
// Verifica se a imagem precisa ser redimensionada
|
|
36
|
+
if (image.width > config.imageResizeThreshold || image.height > config.imageResizeThreshold) {
|
|
37
|
+
// Calcula as novas dimensões mantendo a proporção
|
|
38
|
+
let newWidth, newHeight;
|
|
39
|
+
|
|
40
|
+
if (image.width > image.height) {
|
|
41
|
+
newWidth = config.imageResizeThreshold;
|
|
42
|
+
newHeight = Math.round(image.height * (config.imageResizeThreshold / image.width));
|
|
43
|
+
} else {
|
|
44
|
+
newHeight = config.imageResizeThreshold;
|
|
45
|
+
newWidth = Math.round(image.width * (config.imageResizeThreshold / image.height));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Redimensiona a imagem
|
|
49
|
+
const PImage = require('pureimage');
|
|
50
|
+
const resizedImage = PImage.make(newWidth, newHeight);
|
|
51
|
+
const ctx = resizedImage.getContext('2d');
|
|
52
|
+
|
|
53
|
+
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, newWidth, newHeight);
|
|
54
|
+
|
|
55
|
+
return resizedImage;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return image;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error('Erro ao otimizar imagem:', error);
|
|
61
|
+
return image;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Otimiza o uso de memória
|
|
67
|
+
*/
|
|
68
|
+
function optimizeMemory() {
|
|
69
|
+
if (!config.enabled || !config.useMemoryOptimization) return;
|
|
70
|
+
|
|
71
|
+
config.operationCount++;
|
|
72
|
+
|
|
73
|
+
// Executa coleta de lixo a cada intervalo definido
|
|
74
|
+
if (config.operationCount % config.garbageCollectionInterval === 0) {
|
|
75
|
+
if (global.gc) {
|
|
76
|
+
try {
|
|
77
|
+
global.gc();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error('Erro ao executar coleta de lixo:', error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Otimiza uma operação assíncrona
|
|
87
|
+
*
|
|
88
|
+
* @param {Function} operation - Função de operação
|
|
89
|
+
* @param {Array} args - Argumentos para a operação
|
|
90
|
+
* @returns {Promise<any>} - Resultado da operação
|
|
91
|
+
*/
|
|
92
|
+
async function optimizeAsyncOperation(operation, args) {
|
|
93
|
+
if (!config.enabled) return operation(...args);
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
// Executa a operação
|
|
97
|
+
const result = await operation(...args);
|
|
98
|
+
|
|
99
|
+
// Otimiza o uso de memória
|
|
100
|
+
optimizeMemory();
|
|
101
|
+
|
|
102
|
+
return result;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('Erro ao executar operação assíncrona:', error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Otimiza múltiplas operações assíncronas
|
|
111
|
+
*
|
|
112
|
+
* @param {Array<Function>} operations - Array de funções de operação
|
|
113
|
+
* @param {Array<Array>} argsArray - Array de arrays de argumentos para cada operação
|
|
114
|
+
* @returns {Promise<Array<any>>} - Array de resultados das operações
|
|
115
|
+
*/
|
|
116
|
+
async function optimizeMultipleAsyncOperations(operations, argsArray) {
|
|
117
|
+
if (!config.enabled || !config.useWebWorkers) {
|
|
118
|
+
// Executa as operações sequencialmente
|
|
119
|
+
const results = [];
|
|
120
|
+
|
|
121
|
+
for (let i = 0; i < operations.length; i++) {
|
|
122
|
+
results.push(await operations[i](...argsArray[i]));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return results;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
// Executa as operações em lotes para limitar a concorrência
|
|
130
|
+
const results = [];
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < operations.length; i += config.maxConcurrentOperations) {
|
|
133
|
+
const batch = operations.slice(i, i + config.maxConcurrentOperations);
|
|
134
|
+
const batchArgs = argsArray.slice(i, i + config.maxConcurrentOperations);
|
|
135
|
+
|
|
136
|
+
const batchPromises = batch.map((operation, index) => {
|
|
137
|
+
return operation(...batchArgs[index]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const batchResults = await Promise.all(batchPromises);
|
|
141
|
+
results.push(...batchResults);
|
|
142
|
+
|
|
143
|
+
// Otimiza o uso de memória após cada lote
|
|
144
|
+
optimizeMemory();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return results;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error('Erro ao executar múltiplas operações assíncronas:', error);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Otimiza o buffer de uma imagem
|
|
156
|
+
*
|
|
157
|
+
* @param {Buffer} buffer - Buffer da imagem
|
|
158
|
+
* @returns {Buffer} - Buffer otimizado
|
|
159
|
+
*/
|
|
160
|
+
function optimizeBuffer(buffer) {
|
|
161
|
+
if (!config.enabled) return buffer;
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
// Implementação simplificada - em um cenário real, usaria bibliotecas como sharp ou imagemin
|
|
165
|
+
return buffer;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('Erro ao otimizar buffer:', error);
|
|
168
|
+
return buffer;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Define se a otimização está habilitada
|
|
174
|
+
*
|
|
175
|
+
* @param {boolean} enabled - Se a otimização está habilitada
|
|
176
|
+
*/
|
|
177
|
+
function setEnabled(enabled) {
|
|
178
|
+
config.enabled = enabled;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Configura as opções de otimização
|
|
183
|
+
*
|
|
184
|
+
* @param {Object} options - Opções de configuração
|
|
185
|
+
* @param {boolean} [options.enabled] - Se a otimização está habilitada
|
|
186
|
+
* @param {number} [options.imageResizeThreshold] - Tamanho máximo de imagem em pixels
|
|
187
|
+
* @param {number} [options.imageQualityFactor] - Fator de qualidade para compressão de imagens
|
|
188
|
+
* @param {boolean} [options.useWebWorkers] - Se deve usar Web Workers
|
|
189
|
+
* @param {number} [options.maxConcurrentOperations] - Número máximo de operações concorrentes
|
|
190
|
+
* @param {boolean} [options.useMemoryOptimization] - Se deve otimizar o uso de memória
|
|
191
|
+
* @param {number} [options.garbageCollectionInterval] - Intervalo para coleta de lixo
|
|
192
|
+
*/
|
|
193
|
+
function configure(options) {
|
|
194
|
+
config = { ...config, ...options };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Obtém a configuração atual
|
|
199
|
+
*
|
|
200
|
+
* @returns {Object} - Configuração atual
|
|
201
|
+
*/
|
|
202
|
+
function getConfig() {
|
|
203
|
+
return { ...config };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
module.exports = {
|
|
207
|
+
optimizeImage,
|
|
208
|
+
optimizeAsyncOperation,
|
|
209
|
+
optimizeMultipleAsyncOperations,
|
|
210
|
+
optimizeBuffer,
|
|
211
|
+
optimizeMemory,
|
|
212
|
+
setEnabled,
|
|
213
|
+
configure,
|
|
214
|
+
getConfig
|
|
215
|
+
};
|
|
216
|
+
|