defuss-astro 1.3.5 → 1.4.0

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/dist/client.cjs CHANGED
@@ -50,7 +50,13 @@ const Img = ({
50
50
  const img = imgRef.current;
51
51
  if (!img) return;
52
52
  let loaded = false;
53
- const getTransformOptionsPath2 = ({ src: src2, height: height2, width: width2, quality: quality2, format: format2 }) => {
53
+ const getTransformOptionsPath2 = ({
54
+ src: src2,
55
+ height: height2,
56
+ width: width2,
57
+ quality: quality2,
58
+ format: format2
59
+ }) => {
54
60
  const transformOptions = new URLSearchParams({
55
61
  href: src2,
56
62
  h: height2.toString(),
@@ -77,14 +83,17 @@ const Img = ({
77
83
  loaded = true;
78
84
  };
79
85
  };
80
- const observer = new window.IntersectionObserver((entries, observer2) => {
81
- entries.forEach((entry) => {
82
- if (entry.isIntersecting) {
83
- lazyLoad();
84
- observer2.unobserve(entry.target);
85
- }
86
- });
87
- }, { threshold: 0.1 });
86
+ const observer = new window.IntersectionObserver(
87
+ (entries, observer2) => {
88
+ entries.forEach((entry) => {
89
+ if (entry.isIntersecting) {
90
+ lazyLoad();
91
+ observer2.unobserve(entry.target);
92
+ }
93
+ });
94
+ },
95
+ { threshold: 0.1 }
96
+ );
88
97
  observer.observe(imgRef.current);
89
98
  };
90
99
  return /* @__PURE__ */ jsxRuntime.jsx(
package/dist/client.d.cts CHANGED
@@ -14,6 +14,14 @@ interface ImgProps extends Props {
14
14
  previewQuality?: number;
15
15
  quality?: number;
16
16
  }
17
+ /**
18
+ * Image component for displaying responsive images with automatic format conversion.
19
+ *
20
+ * Default style: {
21
+ * filter: "blur(40px)",
22
+ * transition: "0.125s filter linear",
23
+ * }
24
+ */
17
25
  declare const Img: ({ id, src, alt, height, width, previewQuality, quality, className, class: _class, style, format, astroAssetsPath, }: ImgProps) => any;
18
26
 
19
27
  declare const _default: (element: HTMLElement) => (Component: any, props: Record<string, any>, { default: children, ...slotted }: Record<string, any>, { client }: Record<string, string>) => Promise<void>;
package/dist/client.d.mts CHANGED
@@ -14,6 +14,14 @@ interface ImgProps extends Props {
14
14
  previewQuality?: number;
15
15
  quality?: number;
16
16
  }
17
+ /**
18
+ * Image component for displaying responsive images with automatic format conversion.
19
+ *
20
+ * Default style: {
21
+ * filter: "blur(40px)",
22
+ * transition: "0.125s filter linear",
23
+ * }
24
+ */
17
25
  declare const Img: ({ id, src, alt, height, width, previewQuality, quality, className, class: _class, style, format, astroAssetsPath, }: ImgProps) => any;
18
26
 
19
27
  declare const _default: (element: HTMLElement) => (Component: any, props: Record<string, any>, { default: children, ...slotted }: Record<string, any>, { client }: Record<string, string>) => Promise<void>;
package/dist/client.mjs CHANGED
@@ -46,7 +46,13 @@ const Img = ({
46
46
  const img = imgRef.current;
47
47
  if (!img) return;
48
48
  let loaded = false;
49
- const getTransformOptionsPath2 = ({ src: src2, height: height2, width: width2, quality: quality2, format: format2 }) => {
49
+ const getTransformOptionsPath2 = ({
50
+ src: src2,
51
+ height: height2,
52
+ width: width2,
53
+ quality: quality2,
54
+ format: format2
55
+ }) => {
50
56
  const transformOptions = new URLSearchParams({
51
57
  href: src2,
52
58
  h: height2.toString(),
@@ -73,14 +79,17 @@ const Img = ({
73
79
  loaded = true;
74
80
  };
75
81
  };
76
- const observer = new window.IntersectionObserver((entries, observer2) => {
77
- entries.forEach((entry) => {
78
- if (entry.isIntersecting) {
79
- lazyLoad();
80
- observer2.unobserve(entry.target);
81
- }
82
- });
83
- }, { threshold: 0.1 });
82
+ const observer = new window.IntersectionObserver(
83
+ (entries, observer2) => {
84
+ entries.forEach((entry) => {
85
+ if (entry.isIntersecting) {
86
+ lazyLoad();
87
+ observer2.unobserve(entry.target);
88
+ }
89
+ });
90
+ },
91
+ { threshold: 0.1 }
92
+ );
84
93
  observer.observe(imgRef.current);
85
94
  };
86
95
  return /* @__PURE__ */ jsx(
@@ -1,11 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var fileType = require('file-type');
4
- var node_module = require('node:module');
4
+ var lightningimg = require('lightningimg');
5
5
 
6
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
- const nodeRequire = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('endpoint/image-endpoint.cjs', document.baseURI).href)));
8
- const { convertToWebp } = nodeRequire("lightningimg-node");
9
6
  const GET = async ({ url }) => {
10
7
  try {
11
8
  const imgHrefRelative = url.searchParams.get("href");
@@ -23,6 +20,7 @@ const GET = async ({ url }) => {
23
20
  return new Response("Error fetching image", { status: 500 });
24
21
  }
25
22
  const imageBuffer = Buffer.from(await response.arrayBuffer());
23
+ const imageDimensions = await lightningimg.getImageInfo(imageBuffer);
26
24
  const fileExtension = (await fileType.fileTypeFromBuffer(imageBuffer))?.ext;
27
25
  if (!fileExtension) {
28
26
  console.log("Error fetching fileExtension", { fileExtension, response });
@@ -38,16 +36,20 @@ const GET = async ({ url }) => {
38
36
  }
39
37
  let convertedImageBuffer;
40
38
  try {
41
- convertedImageBuffer = convertToWebp(imageBuffer, fileExtension, {
42
- height: height ? Number.parseInt(height) : void 0,
43
- width: width ? Number.parseInt(width) : void 0,
44
- quality: quality ? Number.parseInt(quality) : void 0
45
- });
39
+ convertedImageBuffer = await lightningimg.convertImageBuffer(
40
+ imageBuffer,
41
+ width ? Number.parseInt(width) : imageDimensions.width,
42
+ height ? Number.parseInt(height) : imageDimensions.height
43
+ );
46
44
  if (!convertedImageBuffer) {
47
45
  throw new Error("Error converting image: no buffer returned");
48
46
  }
49
47
  } catch (error) {
50
- console.log("Error converting image", { fileExtension, bufferLength: imageBuffer.byteLength, error });
48
+ console.log("Error converting image", {
49
+ fileExtension,
50
+ bufferLength: imageBuffer.byteLength,
51
+ error
52
+ });
51
53
  return new Response("Error converting image", { status: 500 });
52
54
  }
53
55
  const mimeType = `image/${fileExtension}`;
@@ -63,4 +65,3 @@ const GET = async ({ url }) => {
63
65
  };
64
66
 
65
67
  exports.GET = GET;
66
- exports.nodeRequire = nodeRequire;
@@ -1,6 +1,5 @@
1
1
  import { APIRoute } from 'astro';
2
2
 
3
- declare const nodeRequire: NodeJS.Require;
4
3
  declare const GET: APIRoute;
5
4
 
6
- export { GET, nodeRequire };
5
+ export { GET };
@@ -1,6 +1,5 @@
1
1
  import { APIRoute } from 'astro';
2
2
 
3
- declare const nodeRequire: NodeJS.Require;
4
3
  declare const GET: APIRoute;
5
4
 
6
- export { GET, nodeRequire };
5
+ export { GET };
@@ -1,8 +1,6 @@
1
1
  import { fileTypeFromBuffer } from 'file-type';
2
- import { createRequire } from 'node:module';
2
+ import { getImageInfo, convertImageBuffer } from 'lightningimg';
3
3
 
4
- const nodeRequire = createRequire(import.meta.url);
5
- const { convertToWebp } = nodeRequire("lightningimg-node");
6
4
  const GET = async ({ url }) => {
7
5
  try {
8
6
  const imgHrefRelative = url.searchParams.get("href");
@@ -20,6 +18,7 @@ const GET = async ({ url }) => {
20
18
  return new Response("Error fetching image", { status: 500 });
21
19
  }
22
20
  const imageBuffer = Buffer.from(await response.arrayBuffer());
21
+ const imageDimensions = await getImageInfo(imageBuffer);
23
22
  const fileExtension = (await fileTypeFromBuffer(imageBuffer))?.ext;
24
23
  if (!fileExtension) {
25
24
  console.log("Error fetching fileExtension", { fileExtension, response });
@@ -35,16 +34,20 @@ const GET = async ({ url }) => {
35
34
  }
36
35
  let convertedImageBuffer;
37
36
  try {
38
- convertedImageBuffer = convertToWebp(imageBuffer, fileExtension, {
39
- height: height ? Number.parseInt(height) : void 0,
40
- width: width ? Number.parseInt(width) : void 0,
41
- quality: quality ? Number.parseInt(quality) : void 0
42
- });
37
+ convertedImageBuffer = await convertImageBuffer(
38
+ imageBuffer,
39
+ width ? Number.parseInt(width) : imageDimensions.width,
40
+ height ? Number.parseInt(height) : imageDimensions.height
41
+ );
43
42
  if (!convertedImageBuffer) {
44
43
  throw new Error("Error converting image: no buffer returned");
45
44
  }
46
45
  } catch (error) {
47
- console.log("Error converting image", { fileExtension, bufferLength: imageBuffer.byteLength, error });
46
+ console.log("Error converting image", {
47
+ fileExtension,
48
+ bufferLength: imageBuffer.byteLength,
49
+ error
50
+ });
48
51
  return new Response("Error converting image", { status: 500 });
49
52
  }
50
53
  const mimeType = `image/${fileExtension}`;
@@ -59,4 +62,4 @@ const GET = async ({ url }) => {
59
62
  }
60
63
  };
61
64
 
62
- export { GET, nodeRequire };
65
+ export { GET };
package/dist/index.cjs CHANGED
@@ -11,16 +11,12 @@ var node_path = require('node:path');
11
11
  var promises = require('node:fs/promises');
12
12
  var purgecss = require('purgecss');
13
13
  var node_fs = require('node:fs');
14
- var node_module = require('node:module');
15
14
 
16
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
15
  const logMessage = (message) => {
18
16
  const date = (/* @__PURE__ */ new Date()).toLocaleTimeString();
19
17
  console.log(`${date} \x1B[32mdefuss-astro:\x1B[0m ${message}`);
20
18
  };
21
19
 
22
- const nodeRequire = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
23
- const { processDirectoryDestructive } = nodeRequire("lightningimg-node");
24
20
  const getRenderer = (development) => ({
25
21
  name: "defuss",
26
22
  clientEntrypoint: "defuss-astro/client.js",
@@ -66,24 +62,34 @@ const minifyAndWriteFile = async (cwd, filename, type) => {
66
62
  }
67
63
  }
68
64
  };
69
- function index({ include, exclude, devtools } = {}) {
65
+ function index({
66
+ include,
67
+ exclude,
68
+ devtools
69
+ } = {}) {
70
70
  return {
71
71
  name: "defuss",
72
72
  hooks: {
73
- "astro:config:setup": async ({ config, addRenderer, updateConfig, command, injectScript, injectRoute }) => {
73
+ "astro:config:setup": async ({
74
+ config,
75
+ addRenderer,
76
+ updateConfig,
77
+ command,
78
+ injectScript,
79
+ injectRoute
80
+ }) => {
74
81
  injectRoute({
75
82
  pattern: "/_defuss/image",
76
83
  prerender: false,
77
84
  entrypoint: "defuss-astro/image-endpoint.js"
78
85
  });
79
- const publicDirPath = node_url.fileURLToPath(config.publicDir);
86
+ node_url.fileURLToPath(config.publicDir);
80
87
  config.compressHTML = true;
81
88
  config.scopedStyleStrategy = "class";
82
89
  if (!config.vite.build) {
83
90
  config.vite.build = {};
84
91
  }
85
92
  config.vite.build.cssMinify = "lightningcss";
86
- processDirectoryDestructive(publicDirPath, false);
87
93
  addRenderer(getRenderer());
88
94
  updateConfig({
89
95
  vite: {
@@ -100,21 +106,18 @@ function index({ include, exclude, devtools } = {}) {
100
106
  "astro:build:done": async ({ dir }) => {
101
107
  const start = node_perf_hooks.performance.now();
102
108
  const cwd = node_url.fileURLToPath(dir);
103
- const [cssFiles, htmlFiles, imageFiles, svgFiles] = await Promise.all([
109
+ const [cssFiles, htmlFiles, svgFiles] = await Promise.all([
104
110
  glob("**/*.css", { cwd, ignore: ["**/*-min.css", "**/*.min.css"] }),
105
111
  glob("**/*.html", { cwd }),
106
- glob("**/*.(jpg|jpeg|png|tiff)", { cwd }),
107
112
  glob("**/*.svg", { cwd })
108
113
  ]);
109
- logMessage(`\u2734\uFE0F Optimizing ${imageFiles.length} images`);
110
- processDirectoryDestructive(cwd, true);
111
114
  if (htmlFiles.length === 0 && svgFiles.length === 0) return;
112
- logMessage(`\u2734\uFE0F Optimizing ${svgFiles.length} SVG vector graphics`);
113
115
  logMessage(`\u2734\uFE0F Optimizing ${cssFiles.length} CSS stylesheets`);
114
116
  const minifyAndWritePromises = [];
115
117
  for (const filename of cssFiles) {
116
118
  minifyAndWritePromises.push(minifyAndWriteFile(cwd, filename, "css"));
117
119
  }
120
+ logMessage(`\u2734\uFE0F Optimizing ${svgFiles.length} SVG vector graphics`);
118
121
  for (const filename of svgFiles) {
119
122
  minifyAndWritePromises.push(minifyAndWriteFile(cwd, filename, "svg"));
120
123
  }
@@ -130,4 +133,3 @@ function index({ include, exclude, devtools } = {}) {
130
133
 
131
134
  exports.default = index;
132
135
  exports.getContainerRenderer = getContainerRenderer;
133
- exports.nodeRequire = nodeRequire;
package/dist/index.d.cts CHANGED
@@ -5,8 +5,7 @@ interface Options extends Pick<DefussVitePluginOptions, "exclude" | "include"> {
5
5
  devtools?: boolean;
6
6
  }
7
7
 
8
- declare const nodeRequire: NodeJS.Require;
9
8
  declare const getContainerRenderer: () => ContainerRenderer;
10
- declare function export_default({ include, exclude, devtools }?: Options): AstroIntegration;
9
+ declare function export_default({ include, exclude, devtools, }?: Options): AstroIntegration;
11
10
 
12
- export { export_default as default, getContainerRenderer, nodeRequire };
11
+ export { export_default as default, getContainerRenderer };
package/dist/index.d.mts CHANGED
@@ -5,8 +5,7 @@ interface Options extends Pick<DefussVitePluginOptions, "exclude" | "include"> {
5
5
  devtools?: boolean;
6
6
  }
7
7
 
8
- declare const nodeRequire: NodeJS.Require;
9
8
  declare const getContainerRenderer: () => ContainerRenderer;
10
- declare function export_default({ include, exclude, devtools }?: Options): AstroIntegration;
9
+ declare function export_default({ include, exclude, devtools, }?: Options): AstroIntegration;
11
10
 
12
- export { export_default as default, getContainerRenderer, nodeRequire };
11
+ export { export_default as default, getContainerRenderer };
package/dist/index.mjs CHANGED
@@ -7,15 +7,12 @@ import { join } from 'node:path';
7
7
  import { readFile, writeFile } from 'node:fs/promises';
8
8
  import { PurgeCSS } from 'purgecss';
9
9
  import { existsSync } from 'node:fs';
10
- import { createRequire } from 'node:module';
11
10
 
12
11
  const logMessage = (message) => {
13
12
  const date = (/* @__PURE__ */ new Date()).toLocaleTimeString();
14
13
  console.log(`${date} \x1B[32mdefuss-astro:\x1B[0m ${message}`);
15
14
  };
16
15
 
17
- const nodeRequire = createRequire(import.meta.url);
18
- const { processDirectoryDestructive } = nodeRequire("lightningimg-node");
19
16
  const getRenderer = (development) => ({
20
17
  name: "defuss",
21
18
  clientEntrypoint: "defuss-astro/client.js",
@@ -61,24 +58,34 @@ const minifyAndWriteFile = async (cwd, filename, type) => {
61
58
  }
62
59
  }
63
60
  };
64
- function index({ include, exclude, devtools } = {}) {
61
+ function index({
62
+ include,
63
+ exclude,
64
+ devtools
65
+ } = {}) {
65
66
  return {
66
67
  name: "defuss",
67
68
  hooks: {
68
- "astro:config:setup": async ({ config, addRenderer, updateConfig, command, injectScript, injectRoute }) => {
69
+ "astro:config:setup": async ({
70
+ config,
71
+ addRenderer,
72
+ updateConfig,
73
+ command,
74
+ injectScript,
75
+ injectRoute
76
+ }) => {
69
77
  injectRoute({
70
78
  pattern: "/_defuss/image",
71
79
  prerender: false,
72
80
  entrypoint: "defuss-astro/image-endpoint.js"
73
81
  });
74
- const publicDirPath = fileURLToPath(config.publicDir);
82
+ fileURLToPath(config.publicDir);
75
83
  config.compressHTML = true;
76
84
  config.scopedStyleStrategy = "class";
77
85
  if (!config.vite.build) {
78
86
  config.vite.build = {};
79
87
  }
80
88
  config.vite.build.cssMinify = "lightningcss";
81
- processDirectoryDestructive(publicDirPath, false);
82
89
  addRenderer(getRenderer());
83
90
  updateConfig({
84
91
  vite: {
@@ -95,21 +102,18 @@ function index({ include, exclude, devtools } = {}) {
95
102
  "astro:build:done": async ({ dir }) => {
96
103
  const start = performance.now();
97
104
  const cwd = fileURLToPath(dir);
98
- const [cssFiles, htmlFiles, imageFiles, svgFiles] = await Promise.all([
105
+ const [cssFiles, htmlFiles, svgFiles] = await Promise.all([
99
106
  glob("**/*.css", { cwd, ignore: ["**/*-min.css", "**/*.min.css"] }),
100
107
  glob("**/*.html", { cwd }),
101
- glob("**/*.(jpg|jpeg|png|tiff)", { cwd }),
102
108
  glob("**/*.svg", { cwd })
103
109
  ]);
104
- logMessage(`\u2734\uFE0F Optimizing ${imageFiles.length} images`);
105
- processDirectoryDestructive(cwd, true);
106
110
  if (htmlFiles.length === 0 && svgFiles.length === 0) return;
107
- logMessage(`\u2734\uFE0F Optimizing ${svgFiles.length} SVG vector graphics`);
108
111
  logMessage(`\u2734\uFE0F Optimizing ${cssFiles.length} CSS stylesheets`);
109
112
  const minifyAndWritePromises = [];
110
113
  for (const filename of cssFiles) {
111
114
  minifyAndWritePromises.push(minifyAndWriteFile(cwd, filename, "css"));
112
115
  }
116
+ logMessage(`\u2734\uFE0F Optimizing ${svgFiles.length} SVG vector graphics`);
113
117
  for (const filename of svgFiles) {
114
118
  minifyAndWritePromises.push(minifyAndWriteFile(cwd, filename, "svg"));
115
119
  }
@@ -123,4 +127,4 @@ function index({ include, exclude, devtools } = {}) {
123
127
  };
124
128
  }
125
129
 
126
- export { index as default, getContainerRenderer, nodeRequire };
130
+ export { index as default, getContainerRenderer };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "defuss-astro",
3
- "version": "1.3.5",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "license": "MIT",
9
- "description": "Defuss Integration for Astro.",
9
+ "description": "Defuss Integration for Astro with WASM-based built-in image conversion support.",
10
10
  "keywords": [
11
11
  "jsx",
12
12
  "render",
@@ -71,19 +71,16 @@
71
71
  "node": "^18.17.1 || ^20.3.0 || >=21.0.0"
72
72
  },
73
73
  "dependencies": {
74
- "astro": "^5.8.0",
74
+ "astro": "^5.8.1",
75
75
  "vite": "^6.3.5",
76
76
  "fast-glob": "^3.3.2",
77
77
  "svgo": "^3.3.2",
78
- "lightningimg-node": "^0.3.3",
78
+ "lightningimg": "^1.0.0",
79
79
  "purgecss": "^7.0.2",
80
80
  "file-type": "^19.6.0",
81
81
  "defuss": "2.0.7",
82
82
  "defuss-vite": "1.1.3"
83
83
  },
84
- "peerDependencies": {
85
- "@minify-html/node": "^0.15.0"
86
- },
87
84
  "scripts": {
88
85
  "clean": "rm -rf ./dist && rm -rf ./node_modules/.pnpm",
89
86
  "prebuild": "pnpm run clean",