vatts 1.1.2 → 1.1.4-alpha.1

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 (2) hide show
  1. package/dist/builder.js +13 -58
  2. package/package.json +1 -1
package/dist/builder.js CHANGED
@@ -20,14 +20,6 @@ const path = require('path');
20
20
  const Console = require("./api/console").default;
21
21
  const fs = require('fs');
22
22
  const { readdir, stat, rm } = require("node:fs/promises");
23
- // Tenta carregar o Sharp para otimização de imagens
24
- let sharp;
25
- try {
26
- sharp = require('sharp');
27
- }
28
- catch (e) {
29
- Console.warn("Sharp não encontrado. Otimização de imagem (resize) desativada. Instale com: npm install sharp");
30
- }
31
23
  // Plugins Oficiais do Rollup
32
24
  const nodeResolve = require('@rollup/plugin-node-resolve').default;
33
25
  const commonjs = require('@rollup/plugin-commonjs').default;
@@ -194,8 +186,9 @@ const customPostCssPlugin = (isProduction) => {
194
186
  });
195
187
  // Lógica unificada: Usa arquivo externo tanto em Dev quanto Prod.
196
188
  // Isso libera a memória que seria usada para stringificar o CSS dentro do JS.
189
+ // FIX: O Rollup pode retornar um objeto URL ao invés de string. String() força a conversão.
197
190
  return `
198
- const cssUrl = import.meta.ROLLUP_FILE_URL_${referenceId};
191
+ const cssUrl = String(import.meta.ROLLUP_FILE_URL_${referenceId});
199
192
  if (typeof document !== 'undefined') {
200
193
  const link = document.createElement('link');
201
194
  link.rel = 'stylesheet';
@@ -210,8 +203,8 @@ const customPostCssPlugin = (isProduction) => {
210
203
  };
211
204
  };
212
205
  /**
213
- * Plugin Inteligente para Assets (Otimizado para RAM e agora com Sharp)
214
- * - Suporta redimensionamento via query params: import img from './image.png?w=200&h=200'
206
+ * Plugin Inteligente para Assets (Otimizado para RAM)
207
+ * - Agora utiliza emissão de arquivos também em DEV para arquivos grandes.
215
208
  */
216
209
  const smartAssetPlugin = (isProduction) => {
217
210
  // 4KB - Arquivos maiores que isso viram referência externa.
@@ -220,8 +213,7 @@ const smartAssetPlugin = (isProduction) => {
220
213
  return {
221
214
  name: 'smart-asset-loader',
222
215
  async load(id) {
223
- // Separa o ID dos parâmetros de query
224
- const [cleanId, queryParams] = id.split('?');
216
+ const cleanId = id.split('?')[0];
225
217
  if (cleanId.startsWith('\0'))
226
218
  return null;
227
219
  const ext = path.extname(cleanId).slice(1).toLowerCase();
@@ -245,46 +237,6 @@ const smartAssetPlugin = (isProduction) => {
245
237
  return `export default ${JSON.stringify(content)};`;
246
238
  }
247
239
  let buffer = await fs.promises.readFile(cleanId);
248
- // --- VATTS IMAGE OPTIMIZATION (SHARP) ---
249
- // Verifica se tem sharp e se tem parâmetros de resize (w=, h=, q=)
250
- if (sharp && queryParams && ['png', 'jpg', 'jpeg', 'webp', 'avif'].includes(ext)) {
251
- try {
252
- const params = new URLSearchParams(queryParams);
253
- const width = params.get('w') || params.get('width');
254
- const height = params.get('h') || params.get('height');
255
- const quality = params.get('q') || params.get('quality');
256
- if (width || height || quality) {
257
- let transformer = sharp(buffer);
258
- if (width || height) {
259
- transformer = transformer.resize({
260
- width: width ? parseInt(width) : null,
261
- height: height ? parseInt(height) : null,
262
- fit: 'cover', // Padrão 'cover' para manter aspect ratio preenchendo
263
- withoutEnlargement: true // Não aumenta se a imagem original for menor
264
- });
265
- }
266
- // Aplica qualidade/compressão se solicitado
267
- if (quality) {
268
- const q = parseInt(quality);
269
- if (ext === 'jpeg' || ext === 'jpg')
270
- transformer.jpeg({ quality: q });
271
- if (ext === 'webp')
272
- transformer.webp({ quality: q });
273
- if (ext === 'avif')
274
- transformer.avif({ quality: q });
275
- if (ext === 'png')
276
- transformer.png({ quality: q });
277
- }
278
- buffer = await transformer.toBuffer();
279
- // Atualiza o tamanho para a decisão de inline/emit abaixo
280
- }
281
- }
282
- catch (e) {
283
- Console.warn(`Failed to optimize image ${path.basename(cleanId)}:`, e.message);
284
- // Falha silenciosa: usa o buffer original
285
- }
286
- }
287
- // ------------------------------------------
288
240
  const size = buffer.length;
289
241
  // Tratamento especial para SVG (inline SVG vs URL)
290
242
  if (type === 'svg') {
@@ -305,28 +257,31 @@ const smartAssetPlugin = (isProduction) => {
305
257
  });
306
258
  const content = buffer.toString('utf8');
307
259
  buffer = null; // GC Hint
260
+ // FIX: O Rollup pode retornar um objeto URL. String() resolve o erro de startsWith.
308
261
  return `
309
- export default import.meta.ROLLUP_FILE_URL_${referenceId};
262
+ export default String(import.meta.ROLLUP_FILE_URL_${referenceId});
310
263
  export const svgContent = ${JSON.stringify(content)};
311
264
  `;
312
265
  }
313
266
  }
314
267
  // Para outros assets:
315
- // Se for pequeno (ou ficou pequeno após resize), Base64
268
+ // Se for pequeno, Base64 (reduz requests HTTP)
269
+ // Se for grande, Arquivo (reduz uso de RAM e tamanho do bundle JS)
270
+ // Essa lógica agora aplica para DEV e PROD. Base64 em Dev para arquivos grandes era o vilão da RAM.
316
271
  if (size < INLINE_LIMIT) {
317
272
  const base64 = buffer.toString('base64');
318
273
  buffer = null; // Libera memória do buffer bruto imediatamente
319
274
  return `export default "data:${type};base64,${base64}";`;
320
275
  }
321
276
  else {
322
- // Se ainda for grande, emite arquivo
323
277
  const referenceId = this.emitFile({
324
278
  type: 'asset',
325
- name: path.basename(cleanId), // O nome será hasheado pelo Rollup output options
279
+ name: path.basename(cleanId),
326
280
  source: buffer
327
281
  });
328
282
  buffer = null; // Libera memória
329
- return `export default import.meta.ROLLUP_FILE_URL_${referenceId};`;
283
+ // FIX: O Rollup pode retornar um objeto URL. String() resolve o erro de startsWith.
284
+ return `export default String(import.meta.ROLLUP_FILE_URL_${referenceId});`;
330
285
  }
331
286
  }
332
287
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vatts",
3
- "version": "1.1.2",
3
+ "version": "1.1.4-alpha.1",
4
4
  "description": "Vatts.js is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "itsmuzin",