Skip to content

Commit 50d058b

Browse files
committed
chore: enhance funding and fix lint
1 parent dd5587b commit 50d058b

File tree

8 files changed

+89
-77
lines changed

8 files changed

+89
-77
lines changed

.github/FUNDING.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github: [stacksjs, chrisbbreuer]
2-
open_collective: [stacksjs]
2+
open_collective: stacksjs

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ imgx serve ./public -p 3000
9898
### Library Usage
9999

100100
```ts
101-
import { process, generateSprite, analyzeImage } from '@stacksjs/imgx'
101+
import { analyzeImage, generateSprite, process } from '@stacksjs/imgx'
102102

103103
// Basic optimization
104104
await process({

bin/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ async function processFile(input: string, output: string, options: ProcessOption
332332
if (options.thumbhash) {
333333
try {
334334
const { hash, dataUrl } = await generateThumbHash(input)
335-
const [width, height] = options.thumbhashSize.split('x').map(Number)
335+
// const [width, height] = options.thumbhashSize.split('x').map(Number)
336336

337337
const thumbPath = `${output}.thumb.png`
338338
const hashPath = `${output}.thumb.hash`
@@ -342,7 +342,7 @@ async function processFile(input: string, output: string, options: ProcessOption
342342

343343
console.log(`Generated ThumbHash: ${thumbPath}`)
344344
}
345-
catch (error) {
345+
catch (error: any) {
346346
console.error(`Error generating ThumbHash: ${error.message}`)
347347
}
348348
}

bun.lock

+63-63
Large diffs are not rendered by default.

src/plugins.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Plugin } from 'vite'
22
import type { Compiler } from 'webpack'
33
import type { ProcessOptions } from './types'
4+
import { Buffer } from 'node:buffer'
45
import { process } from './core'
56
import { debugLog } from './utils'
67

src/processor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OptimizeResult, ProcessOptions } from './types'
2+
import { Buffer } from 'node:buffer'
23
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'
34
import { dirname } from 'node:path'
45
import sharp from 'sharp'

src/responsive.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ export async function generateResponsiveImages(
5555
const outputPath = join(outputDir, filename)
5656

5757
await sharp(inputBuffer)
58-
.resize(width)
59-
[format]({ quality })
58+
.resize(width)[format]({ quality })
6059
.toFile(outputPath)
6160

6261
const { size } = await sharp(outputPath).metadata()
@@ -122,8 +121,7 @@ export async function generateImageSet(options: ImageSetOptions) {
122121
const outputPath = join(outputDir, `${name}-${suffix}.${format}`)
123122

124123
await sharp(input)
125-
.resize(size.width, size.height)
126-
[format]({ quality })
124+
.resize(size.width, size.height)[format]({ quality })
127125
.toFile(outputPath)
128126

129127
results.push({

src/thumbhash.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export function rgbaToThumbHash(w: number, h: number, rgba: ArrayLike<number>):
1818
const { PI, round, max, cos, abs } = Math
1919

2020
// Determine the average color
21-
let avg_r = 0; let avg_g = 0; let avg_b = 0; let avg_a = 0
21+
let avg_r = 0
22+
let avg_g = 0
23+
let avg_b = 0
24+
let avg_a = 0
2225
for (let i = 0, j = 0; i < w * h; i++, j += 4) {
2326
const alpha = rgba[j + 3] / 255
2427
avg_r += alpha / 255 * rgba[j]
@@ -54,8 +57,11 @@ export function rgbaToThumbHash(w: number, h: number, rgba: ArrayLike<number>):
5457
}
5558

5659
// Encode using the DCT into DC (constant) and normalized AC (varying) terms
57-
const encodeChannel = (channel, nx, ny) => {
58-
let dc = 0; const ac = []; let scale = 0; const fx = []
60+
const encodeChannel = (channel: any, nx: any, ny: any) => {
61+
let dc = 0
62+
const ac = []
63+
let scale = 0
64+
const fx = []
5965
for (let cy = 0; cy < ny; cy++) {
6066
for (let cx = 0; cx * ny < nx * (ny - cy); cx++) {
6167
let f = 0
@@ -149,10 +155,15 @@ export function thumbHashToRGBA(hash: ArrayLike<number>): { w: number, h: number
149155
const ratio = thumbHashToApproximateAspectRatio(hash)
150156
const w = round(ratio > 1 ? 32 : 32 * ratio)
151157
const h = round(ratio > 1 ? 32 / ratio : 32)
152-
const rgba = new Uint8Array(w * h * 4); const fx = []; const fy = []
158+
const rgba = new Uint8Array(w * h * 4)
159+
const fx = []
160+
const fy = []
153161
for (let y = 0, i = 0; y < h; y++) {
154162
for (let x = 0; x < w; x++, i += 4) {
155-
let l = l_dc; let p = p_dc; let q = q_dc; let a = a_dc
163+
let l = l_dc
164+
let p = p_dc
165+
let q = q_dc
166+
let a = a_dc
156167

157168
// Precompute the coefficients
158169
for (let cx = 0, n = max(lx, hasAlpha ? 5 : 3); cx < n; cx++)
@@ -312,7 +323,8 @@ export function rgbaToDataURL(w: number, h: number, rgba: ArrayLike<number>): st
312323
-1609899400,
313324
-1111625188,
314325
]
315-
let a = 1; let b = 0
326+
let a = 1
327+
let b = 0
316328
for (let y = 0, i = 0, end = row - 1; y < h; y++, end += row - 1) {
317329
bytes.push(y + 1 < h ? 0 : 1, row & 255, row >> 8, ~row & 255, (row >> 8) ^ 255, 0)
318330
for (b = (b + a) % 65521; i < end; i++) {

0 commit comments

Comments
 (0)