@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
package/src/effects.js ADDED
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Módulo de Efeitos Visuais para @cognima/banners
5
+ *
6
+ * Este módulo contém funções para aplicar efeitos visuais avançados aos banners,
7
+ * como gradientes, sombras, brilhos, padrões e outros efeitos decorativos.
8
+ *
9
+ * @author Cognima Team (melhorado)
10
+ * @version 2.0.0
11
+ */
12
+
13
+ const {
14
+ createLinearGradient,
15
+ hexToRgba,
16
+ roundRect
17
+ } = require("../utils");
18
+
19
+ /**
20
+ * Aplica um efeito de vidro fosco (glassmorphism)
21
+ * @param {Object} ctx - Contexto de renderização 2D
22
+ * @param {number} x - Posição X
23
+ * @param {number} y - Posição Y
24
+ * @param {number} width - Largura
25
+ * @param {number} height - Altura
26
+ * @param {number} radius - Raio dos cantos
27
+ * @param {number} opacity - Opacidade (0-1)
28
+ * @param {string} color - Cor base (hexadecimal)
29
+ */
30
+ function applyGlassmorphism(ctx, x, y, width, height, radius = 10, opacity = 0.2, color = "#FFFFFF") {
31
+ // Fundo semi-transparente
32
+ ctx.fillStyle = hexToRgba(color, opacity);
33
+ roundRect(ctx, x, y, width, height, radius, true, false);
34
+
35
+ // Borda sutil
36
+ ctx.strokeStyle = hexToRgba(color, opacity + 0.1);
37
+ ctx.lineWidth = 1;
38
+ roundRect(ctx, x, y, width, height, radius, false, true);
39
+
40
+ // Brilho superior (efeito de vidro)
41
+ const gradient = createLinearGradient(
42
+ ctx,
43
+ x,
44
+ y,
45
+ x,
46
+ y + height * 0.5,
47
+ hexToRgba(color, opacity + 0.1),
48
+ hexToRgba(color, 0),
49
+ "vertical"
50
+ );
51
+
52
+ ctx.fillStyle = gradient;
53
+ roundRect(ctx, x, y, width, height * 0.5, { tl: radius, tr: radius, br: 0, bl: 0 }, true, false);
54
+ }
55
+
56
+ /**
57
+ * Aplica um efeito de neomorfismo
58
+ * @param {Object} ctx - Contexto de renderização 2D
59
+ * @param {number} x - Posição X
60
+ * @param {number} y - Posição Y
61
+ * @param {number} width - Largura
62
+ * @param {number} height - Altura
63
+ * @param {number} radius - Raio dos cantos
64
+ * @param {string} baseColor - Cor base (hexadecimal)
65
+ * @param {boolean} pressed - Se o elemento está pressionado
66
+ */
67
+ function applyNeomorphism(ctx, x, y, width, height, radius = 10, baseColor = "#E0E0E0", pressed = false) {
68
+ // Salva o estado atual
69
+ ctx.save();
70
+
71
+ // Desenha o fundo base
72
+ ctx.fillStyle = baseColor;
73
+ roundRect(ctx, x, y, width, height, radius, true, false);
74
+
75
+ if (pressed) {
76
+ // Efeito pressionado (sombra interna)
77
+ ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
78
+ ctx.shadowBlur = 15;
79
+ ctx.shadowOffsetX = 5;
80
+ ctx.shadowOffsetY = 5;
81
+ roundRect(ctx, x + 2, y + 2, width - 4, height - 4, radius - 2, false, true);
82
+
83
+ ctx.shadowColor = "rgba(255, 255, 255, 0.7)";
84
+ ctx.shadowOffsetX = -5;
85
+ ctx.shadowOffsetY = -5;
86
+ roundRect(ctx, x + 2, y + 2, width - 4, height - 4, radius - 2, false, true);
87
+ } else {
88
+ // Efeito normal (sombra externa)
89
+ ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
90
+ ctx.shadowBlur = 15;
91
+ ctx.shadowOffsetX = 5;
92
+ ctx.shadowOffsetY = 5;
93
+ roundRect(ctx, x, y, width, height, radius, false, true);
94
+
95
+ ctx.shadowColor = "rgba(255, 255, 255, 0.7)";
96
+ ctx.shadowOffsetX = -5;
97
+ ctx.shadowOffsetY = -5;
98
+ roundRect(ctx, x, y, width, height, radius, false, true);
99
+ }
100
+
101
+ // Restaura o estado
102
+ ctx.restore();
103
+ }
104
+
105
+ /**
106
+ * Aplica um efeito de gradiente com várias cores
107
+ * @param {Object} ctx - Contexto de renderização 2D
108
+ * @param {number} x - Posição X
109
+ * @param {number} y - Posição Y
110
+ * @param {number} width - Largura
111
+ * @param {number} height - Altura
112
+ * @param {Array} colors - Array de cores (hexadecimal)
113
+ * @param {string} direction - Direção do gradiente ('horizontal', 'vertical', 'diagonal', 'radial')
114
+ */
115
+ function applyMultiColorGradient(ctx, x, y, width, height, colors, direction = 'horizontal') {
116
+ if (!colors || colors.length < 2) {
117
+ throw new Error("São necessárias pelo menos duas cores para criar um gradiente.");
118
+ }
119
+
120
+ let gradient;
121
+
122
+ if (direction === 'radial') {
123
+ // Gradiente radial
124
+ const centerX = x + width / 2;
125
+ const centerY = y + height / 2;
126
+ const radius = Math.max(width, height) / 2;
127
+
128
+ gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
129
+ } else {
130
+ // Gradiente linear
131
+ switch (direction) {
132
+ case 'horizontal':
133
+ gradient = ctx.createLinearGradient(x, y, x + width, y);
134
+ break;
135
+ case 'vertical':
136
+ gradient = ctx.createLinearGradient(x, y, x, y + height);
137
+ break;
138
+ case 'diagonal':
139
+ default:
140
+ gradient = ctx.createLinearGradient(x, y, x + width, y + height);
141
+ break;
142
+ }
143
+ }
144
+
145
+ // Adiciona as cores ao gradiente
146
+ const step = 1 / (colors.length - 1);
147
+ colors.forEach((color, index) => {
148
+ gradient.addColorStop(index * step, color);
149
+ });
150
+
151
+ return gradient;
152
+ }
153
+
154
+ /**
155
+ * Aplica um efeito de padrão de pontos
156
+ * @param {Object} ctx - Contexto de renderização 2D
157
+ * @param {number} x - Posição X
158
+ * @param {number} y - Posição Y
159
+ * @param {number} width - Largura
160
+ * @param {number} height - Altura
161
+ * @param {number} spacing - Espaçamento entre os pontos
162
+ * @param {number} radius - Raio dos pontos
163
+ * @param {string} color - Cor dos pontos (hexadecimal)
164
+ * @param {number} opacity - Opacidade dos pontos (0-1)
165
+ */
166
+ function applyDotPattern(ctx, x, y, width, height, spacing = 20, radius = 2, color = "#000000", opacity = 0.2) {
167
+ // Salva o estado atual
168
+ ctx.save();
169
+
170
+ // Define a cor e opacidade
171
+ ctx.fillStyle = hexToRgba(color, opacity);
172
+
173
+ // Desenha os pontos
174
+ for (let posX = x; posX < x + width; posX += spacing) {
175
+ for (let posY = y; posY < y + height; posY += spacing) {
176
+ ctx.beginPath();
177
+ ctx.arc(posX, posY, radius, 0, Math.PI * 2);
178
+ ctx.fill();
179
+ }
180
+ }
181
+
182
+ // Restaura o estado
183
+ ctx.restore();
184
+ }
185
+
186
+ /**
187
+ * Aplica um efeito de padrão de linhas
188
+ * @param {Object} ctx - Contexto de renderização 2D
189
+ * @param {number} x - Posição X
190
+ * @param {number} y - Posição Y
191
+ * @param {number} width - Largura
192
+ * @param {number} height - Altura
193
+ * @param {number} spacing - Espaçamento entre as linhas
194
+ * @param {number} lineWidth - Largura das linhas
195
+ * @param {string} color - Cor das linhas (hexadecimal)
196
+ * @param {number} opacity - Opacidade das linhas (0-1)
197
+ * @param {string} direction - Direção das linhas ('horizontal', 'vertical', 'diagonal')
198
+ */
199
+ function applyLinePattern(ctx, x, y, width, height, spacing = 20, lineWidth = 1, color = "#000000", opacity = 0.2, direction = 'horizontal') {
200
+ // Salva o estado atual
201
+ ctx.save();
202
+
203
+ // Define a cor, opacidade e largura da linha
204
+ ctx.strokeStyle = hexToRgba(color, opacity);
205
+ ctx.lineWidth = lineWidth;
206
+
207
+ // Desenha as linhas
208
+ switch (direction) {
209
+ case 'vertical':
210
+ for (let posX = x; posX < x + width; posX += spacing) {
211
+ ctx.beginPath();
212
+ ctx.moveTo(posX, y);
213
+ ctx.lineTo(posX, y + height);
214
+ ctx.stroke();
215
+ }
216
+ break;
217
+ case 'diagonal':
218
+ const diagonal = Math.sqrt(width * width + height * height);
219
+ const steps = diagonal / spacing;
220
+ const stepX = width / steps;
221
+ const stepY = height / steps;
222
+
223
+ for (let i = -steps; i <= steps * 2; i++) {
224
+ ctx.beginPath();
225
+ ctx.moveTo(x + i * stepX, y);
226
+ ctx.lineTo(x, y + i * stepY);
227
+ ctx.stroke();
228
+ }
229
+ break;
230
+ case 'horizontal':
231
+ default:
232
+ for (let posY = y; posY < y + height; posY += spacing) {
233
+ ctx.beginPath();
234
+ ctx.moveTo(x, posY);
235
+ ctx.lineTo(x + width, posY);
236
+ ctx.stroke();
237
+ }
238
+ break;
239
+ }
240
+
241
+ // Restaura o estado
242
+ ctx.restore();
243
+ }
244
+
245
+ /**
246
+ * Aplica um efeito de brilho (glow)
247
+ * @param {Object} ctx - Contexto de renderização 2D
248
+ * @param {number} x - Posição X
249
+ * @param {number} y - Posição Y
250
+ * @param {number} width - Largura
251
+ * @param {number} height - Altura
252
+ * @param {number} radius - Raio dos cantos
253
+ * @param {string} color - Cor do brilho (hexadecimal)
254
+ * @param {number} blurSize - Tamanho do desfoque
255
+ */
256
+ function applyGlow(ctx, x, y, width, height, radius = 10, color = "#3498DB", blurSize = 20) {
257
+ // Salva o estado atual
258
+ ctx.save();
259
+
260
+ // Aplica o efeito de brilho
261
+ ctx.shadowColor = color;
262
+ ctx.shadowBlur = blurSize;
263
+ ctx.shadowOffsetX = 0;
264
+ ctx.shadowOffsetY = 0;
265
+
266
+ // Desenha a forma com o brilho
267
+ ctx.fillStyle = color;
268
+ roundRect(ctx, x, y, width, height, radius, true, false);
269
+
270
+ // Restaura o estado
271
+ ctx.restore();
272
+ }
273
+
274
+ /**
275
+ * Aplica um efeito de textura de ruído
276
+ * @param {Object} ctx - Contexto de renderização 2D
277
+ * @param {number} x - Posição X
278
+ * @param {number} y - Posição Y
279
+ * @param {number} width - Largura
280
+ * @param {number} height - Altura
281
+ * @param {number} opacity - Opacidade do ruído (0-1)
282
+ * @param {string} color - Cor do ruído (hexadecimal)
283
+ */
284
+ function applyNoiseTexture(ctx, x, y, width, height, opacity = 0.1, color = "#000000") {
285
+ // Usa pureimage para criar um canvas temporário (compatível com Node.js)
286
+ const pureimage = require("pureimage");
287
+ const tempCanvas = pureimage.make(Math.ceil(width), Math.ceil(height));
288
+ const tempCtx = tempCanvas.getContext('2d');
289
+
290
+ // Obtém os dados da imagem do canvas temporário
291
+ const imageData = tempCtx.getImageData(0, 0, Math.ceil(width), Math.ceil(height));
292
+ const data = imageData.data;
293
+
294
+ // Preenche os dados com ruído
295
+ for (let i = 0; i < data.length; i += 4) {
296
+ const value = Math.random() * 255;
297
+ data[i] = value; // R
298
+ data[i + 1] = value; // G
299
+ data[i + 2] = value; // B
300
+ data[i + 3] = Math.floor(Math.random() * 255 * opacity); // A
301
+ }
302
+
303
+ // Aplica os dados da imagem
304
+ tempCtx.putImageData(imageData, 0, 0);
305
+
306
+ // Desenha o ruído no contexto principal
307
+ ctx.save();
308
+ ctx.globalAlpha = opacity;
309
+ ctx.drawImage(tempCanvas, x, y, width, height);
310
+ ctx.restore();
311
+ }
312
+
313
+ /**
314
+ * Aplica um efeito de recorte de imagem em forma de texto
315
+ * @param {Object} ctx - Contexto de renderização 2D
316
+ * @param {string} text - Texto a ser usado como máscara
317
+ * @param {number} x - Posição X
318
+ * @param {number} y - Posição Y
319
+ * @param {Object} image - Imagem a ser recortada
320
+ * @param {string} font - Fonte do texto
321
+ */
322
+ function applyTextClipping(ctx, text, x, y, image, font) {
323
+ // Salva o estado atual
324
+ ctx.save();
325
+
326
+ // Define a fonte
327
+ ctx.font = font;
328
+
329
+ // Cria o caminho do texto
330
+ ctx.fillStyle = "#000000";
331
+ ctx.textBaseline = "top";
332
+ ctx.fillText(text, x, y);
333
+
334
+ // Usa o texto como máscara de recorte
335
+ ctx.globalCompositeOperation = "source-in";
336
+
337
+ // Desenha a imagem
338
+ ctx.drawImage(image, x, y);
339
+
340
+ // Restaura o estado
341
+ ctx.restore();
342
+ }
343
+
344
+ // --- Exportações ---
345
+ module.exports = {
346
+ applyGlassmorphism,
347
+ applyNeomorphism,
348
+ applyMultiColorGradient,
349
+ applyDotPattern,
350
+ applyLinePattern,
351
+ applyGlow,
352
+ applyNoiseTexture,
353
+ applyTextClipping
354
+ };
355
+
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Módulo de tratamento de erros
5
+ *
6
+ * Este módulo fornece funções para tratar erros do módulo @cognima/banners.
7
+ *
8
+ * @module error-handler
9
+ * @author Cognima Team (melhorado)
10
+ * @version 2.0.0
11
+ */
12
+
13
+ // Configuração padrão
14
+ let config = {
15
+ debug: false, // Se deve mostrar mensagens de debug
16
+ logErrors: true, // Se deve registrar erros no console
17
+ throwErrors: true, // Se deve lançar erros
18
+ useErrorCodes: true, // Se deve usar códigos de erro
19
+ useErrorTranslation: true, // Se deve traduzir mensagens de erro
20
+ language: 'pt-BR' // Idioma padrão para mensagens de erro
21
+ };
22
+
23
+ // Códigos de erro
24
+ const errorCodes = {
25
+ INVALID_PARAMETER: 'ERR_INVALID_PARAMETER',
26
+ MISSING_PARAMETER: 'ERR_MISSING_PARAMETER',
27
+ IMAGE_LOAD_ERROR: 'ERR_IMAGE_LOAD',
28
+ IMAGE_PROCESS_ERROR: 'ERR_IMAGE_PROCESS',
29
+ BANNER_CREATION_ERROR: 'ERR_BANNER_CREATION',
30
+ INTERNAL_ERROR: 'ERR_INTERNAL',
31
+ FILE_SYSTEM_ERROR: 'ERR_FILE_SYSTEM',
32
+ NETWORK_ERROR: 'ERR_NETWORK',
33
+ CACHE_ERROR: 'ERR_CACHE',
34
+ OPTIMIZATION_ERROR: 'ERR_OPTIMIZATION'
35
+ };
36
+
37
+ // Traduções de mensagens de erro
38
+ const errorTranslations = {
39
+ 'pt-BR': {
40
+ [errorCodes.INVALID_PARAMETER]: 'Parâmetro inválido: {0}',
41
+ [errorCodes.MISSING_PARAMETER]: 'Parâmetro obrigatório ausente: {0}',
42
+ [errorCodes.IMAGE_LOAD_ERROR]: 'Erro ao carregar imagem: {0}',
43
+ [errorCodes.IMAGE_PROCESS_ERROR]: 'Erro ao processar imagem: {0}',
44
+ [errorCodes.BANNER_CREATION_ERROR]: 'Erro ao criar banner: {0}',
45
+ [errorCodes.INTERNAL_ERROR]: 'Erro interno: {0}',
46
+ [errorCodes.FILE_SYSTEM_ERROR]: 'Erro de sistema de arquivos: {0}',
47
+ [errorCodes.NETWORK_ERROR]: 'Erro de rede: {0}',
48
+ [errorCodes.CACHE_ERROR]: 'Erro de cache: {0}',
49
+ [errorCodes.OPTIMIZATION_ERROR]: 'Erro de otimização: {0}'
50
+ },
51
+ 'en-US': {
52
+ [errorCodes.INVALID_PARAMETER]: 'Invalid parameter: {0}',
53
+ [errorCodes.MISSING_PARAMETER]: 'Missing required parameter: {0}',
54
+ [errorCodes.IMAGE_LOAD_ERROR]: 'Error loading image: {0}',
55
+ [errorCodes.IMAGE_PROCESS_ERROR]: 'Error processing image: {0}',
56
+ [errorCodes.BANNER_CREATION_ERROR]: 'Error creating banner: {0}',
57
+ [errorCodes.INTERNAL_ERROR]: 'Internal error: {0}',
58
+ [errorCodes.FILE_SYSTEM_ERROR]: 'File system error: {0}',
59
+ [errorCodes.NETWORK_ERROR]: 'Network error: {0}',
60
+ [errorCodes.CACHE_ERROR]: 'Cache error: {0}',
61
+ [errorCodes.OPTIMIZATION_ERROR]: 'Optimization error: {0}'
62
+ }
63
+ };
64
+
65
+ /**
66
+ * Formata uma mensagem de erro
67
+ *
68
+ * @param {string} template - Template da mensagem
69
+ * @param {Array<string>} args - Argumentos para substituir no template
70
+ * @returns {string} - Mensagem formatada
71
+ */
72
+ function formatMessage(template, args) {
73
+ if (!args || !args.length) return template;
74
+
75
+ return template.replace(/\{(\d+)\}/g, (match, index) => {
76
+ const argIndex = parseInt(index, 10);
77
+ return argIndex < args.length ? args[argIndex] : match;
78
+ });
79
+ }
80
+
81
+ /**
82
+ * Traduz uma mensagem de erro
83
+ *
84
+ * @param {string} code - Código de erro
85
+ * @param {Array<string>} args - Argumentos para substituir no template
86
+ * @returns {string} - Mensagem traduzida
87
+ */
88
+ function translateError(code, args) {
89
+ if (!config.useErrorTranslation) return code;
90
+
91
+ const translations = errorTranslations[config.language] || errorTranslations['en-US'];
92
+ const template = translations[code] || code;
93
+
94
+ return formatMessage(template, args);
95
+ }
96
+
97
+ /**
98
+ * Cria um objeto de erro
99
+ *
100
+ * @param {string} code - Código de erro
101
+ * @param {string} message - Mensagem de erro
102
+ * @param {Error} [originalError] - Erro original
103
+ * @returns {Error} - Objeto de erro
104
+ */
105
+ function createError(code, message, originalError) {
106
+ const error = new Error(message);
107
+ error.code = code;
108
+ error.originalError = originalError;
109
+ return error;
110
+ }
111
+
112
+ /**
113
+ * Trata um erro
114
+ *
115
+ * @param {string} code - Código de erro
116
+ * @param {Array<string>} args - Argumentos para substituir no template
117
+ * @param {Error} [originalError] - Erro original
118
+ * @returns {Error} - Objeto de erro
119
+ */
120
+ function handleError(code, args, originalError) {
121
+ // Obtém a mensagem traduzida
122
+ const message = translateError(code, args);
123
+
124
+ // Cria o objeto de erro
125
+ const error = createError(config.useErrorCodes ? code : undefined, message, originalError);
126
+
127
+ // Registra o erro no console
128
+ if (config.logErrors) {
129
+ console.error(`[${code}] ${message}`);
130
+
131
+ if (config.debug && originalError) {
132
+ console.error('Erro original:', originalError);
133
+ }
134
+ }
135
+
136
+ // Lança o erro se necessário
137
+ if (config.throwErrors) {
138
+ throw error;
139
+ }
140
+
141
+ return error;
142
+ }
143
+
144
+ /**
145
+ * Trata um erro de parâmetro inválido
146
+ *
147
+ * @param {string} paramName - Nome do parâmetro
148
+ * @param {string} [reason] - Motivo da invalidação
149
+ * @returns {Error} - Objeto de erro
150
+ */
151
+ function handleInvalidParameter(paramName, reason) {
152
+ const args = [paramName];
153
+ if (reason) args.push(reason);
154
+ return handleError(errorCodes.INVALID_PARAMETER, args);
155
+ }
156
+
157
+ /**
158
+ * Trata um erro de parâmetro ausente
159
+ *
160
+ * @param {string} paramName - Nome do parâmetro
161
+ * @returns {Error} - Objeto de erro
162
+ */
163
+ function handleMissingParameter(paramName) {
164
+ return handleError(errorCodes.MISSING_PARAMETER, [paramName]);
165
+ }
166
+
167
+ /**
168
+ * Trata um erro de carregamento de imagem
169
+ *
170
+ * @param {string} url - URL da imagem
171
+ * @param {Error} [originalError] - Erro original
172
+ * @returns {Error} - Objeto de erro
173
+ */
174
+ function handleImageLoadError(url, originalError) {
175
+ return handleError(errorCodes.IMAGE_LOAD_ERROR, [url], originalError);
176
+ }
177
+
178
+ /**
179
+ * Trata um erro de processamento de imagem
180
+ *
181
+ * @param {string} operation - Operação de processamento
182
+ * @param {Error} [originalError] - Erro original
183
+ * @returns {Error} - Objeto de erro
184
+ */
185
+ function handleImageProcessError(operation, originalError) {
186
+ return handleError(errorCodes.IMAGE_PROCESS_ERROR, [operation], originalError);
187
+ }
188
+
189
+ /**
190
+ * Trata um erro de criação de banner
191
+ *
192
+ * @param {string} bannerType - Tipo de banner
193
+ * @param {Error} [originalError] - Erro original
194
+ * @returns {Error} - Objeto de erro
195
+ */
196
+ function handleBannerCreationError(bannerType, originalError) {
197
+ return handleError(errorCodes.BANNER_CREATION_ERROR, [bannerType], originalError);
198
+ }
199
+
200
+ /**
201
+ * Trata um erro interno
202
+ *
203
+ * @param {string} message - Mensagem de erro
204
+ * @param {Error} [originalError] - Erro original
205
+ * @returns {Error} - Objeto de erro
206
+ */
207
+ function handleInternalError(message, originalError) {
208
+ return handleError(errorCodes.INTERNAL_ERROR, [message], originalError);
209
+ }
210
+
211
+ /**
212
+ * Trata um erro de sistema de arquivos
213
+ *
214
+ * @param {string} operation - Operação de sistema de arquivos
215
+ * @param {Error} [originalError] - Erro original
216
+ * @returns {Error} - Objeto de erro
217
+ */
218
+ function handleFileSystemError(operation, originalError) {
219
+ return handleError(errorCodes.FILE_SYSTEM_ERROR, [operation], originalError);
220
+ }
221
+
222
+ /**
223
+ * Trata um erro de rede
224
+ *
225
+ * @param {string} url - URL da requisição
226
+ * @param {Error} [originalError] - Erro original
227
+ * @returns {Error} - Objeto de erro
228
+ */
229
+ function handleNetworkError(url, originalError) {
230
+ return handleError(errorCodes.NETWORK_ERROR, [url], originalError);
231
+ }
232
+
233
+ /**
234
+ * Trata um erro de cache
235
+ *
236
+ * @param {string} operation - Operação de cache
237
+ * @param {Error} [originalError] - Erro original
238
+ * @returns {Error} - Objeto de erro
239
+ */
240
+ function handleCacheError(operation, originalError) {
241
+ return handleError(errorCodes.CACHE_ERROR, [operation], originalError);
242
+ }
243
+
244
+ /**
245
+ * Trata um erro de otimização
246
+ *
247
+ * @param {string} operation - Operação de otimização
248
+ * @param {Error} [originalError] - Erro original
249
+ * @returns {Error} - Objeto de erro
250
+ */
251
+ function handleOptimizationError(operation, originalError) {
252
+ return handleError(errorCodes.OPTIMIZATION_ERROR, [operation], originalError);
253
+ }
254
+
255
+ /**
256
+ * Define se o modo de debug está habilitado
257
+ *
258
+ * @param {boolean} debug - Se o modo de debug está habilitado
259
+ */
260
+ function setDebug(debug) {
261
+ config.debug = debug;
262
+ }
263
+
264
+ /**
265
+ * Configura as opções de tratamento de erros
266
+ *
267
+ * @param {Object} options - Opções de configuração
268
+ * @param {boolean} [options.debug] - Se deve mostrar mensagens de debug
269
+ * @param {boolean} [options.logErrors] - Se deve registrar erros no console
270
+ * @param {boolean} [options.throwErrors] - Se deve lançar erros
271
+ * @param {boolean} [options.useErrorCodes] - Se deve usar códigos de erro
272
+ * @param {boolean} [options.useErrorTranslation] - Se deve traduzir mensagens de erro
273
+ * @param {string} [options.language] - Idioma para mensagens de erro
274
+ */
275
+ function configure(options) {
276
+ config = { ...config, ...options };
277
+ }
278
+
279
+ /**
280
+ * Obtém a configuração atual
281
+ *
282
+ * @returns {Object} - Configuração atual
283
+ */
284
+ function getConfig() {
285
+ return { ...config };
286
+ }
287
+
288
+ module.exports = {
289
+ errorCodes,
290
+ handleError,
291
+ handleInvalidParameter,
292
+ handleMissingParameter,
293
+ handleImageLoadError,
294
+ handleImageProcessError,
295
+ handleBannerCreationError,
296
+ handleInternalError,
297
+ handleFileSystemError,
298
+ handleNetworkError,
299
+ handleCacheError,
300
+ handleOptimizationError,
301
+ setDebug,
302
+ configure,
303
+ getConfig
304
+ };
305
+