Skip to content

Commit c1741ed

Browse files
committed
refactor: update ComponentsOptions and related functions for consistent parameter order and required fields
1 parent 33b956a commit c1741ed

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

src/types/components-options.type.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { LqipType } from './lqip.type'
22

33
export type ComponentsOptions = {
44
src: string | object
5-
lqip?: LqipType
6-
lqipSize?: number
7-
styleProps?: Record<string, any>
8-
forbiddenVars?: string[]
9-
isDevelopment?: boolean
10-
isPrerendered?: boolean | undefined
5+
lqip: LqipType
6+
lqipSize: number
7+
styleProps: Record<string, any>
8+
forbiddenVars: string[]
9+
isDevelopment: boolean | undefined
10+
isPrerendered: boolean | undefined
1111
}

src/utils/generateLqip.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { PREFIX } from '../constants'
66

77
import { getPlaiceholder } from 'plaiceholder'
88

9-
export async function generateLqip(imagePath: string, isDevelopment: boolean, lqipType: LqipType, lqipSize: number) {
9+
export async function generateLqip(
10+
imagePath: string,
11+
lqipType: LqipType,
12+
lqipSize: number,
13+
isDevelopment: boolean | undefined
14+
) {
1015
try {
1116
const buffer = await readFile(imagePath)
1217
const plaiceholderResult = await getPlaiceholder(buffer, { size: lqipSize })

src/utils/getLqip.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ async function ensureCacheDir() {
1818
}
1919
}
2020

21-
export async function getLqip(imagePath: { src: string }, isDevelopment: boolean, isPrerendered: boolean | undefined, lqipType: LqipType, lqipSize: number) {
21+
export async function getLqip(
22+
imagePath: { src: string },
23+
lqipType: LqipType,
24+
lqipSize: number,
25+
isDevelopment: boolean | undefined,
26+
isPrerendered: boolean | undefined
27+
) {
2228
if (!imagePath?.src) return undefined
2329

2430
if (isRemoteUrl(imagePath.src)) {
@@ -33,7 +39,7 @@ export async function getLqip(imagePath: { src: string }, isDevelopment: boolean
3339
await writeFile(tempPath, buffer)
3440

3541
try {
36-
const lqip = await generateLqip(tempPath, isDevelopment, lqipType, lqipSize)
42+
const lqip = await generateLqip(tempPath, lqipType, lqipSize, isDevelopment)
3743
return lqip
3844
} finally {
3945
await unlink(tempPath)
@@ -42,17 +48,17 @@ export async function getLqip(imagePath: { src: string }, isDevelopment: boolean
4248

4349
if (isDevelopment && imagePath.src.startsWith('/@fs/')) {
4450
const filePath = imagePath.src.replace(/^\/@fs/, '').split('?')[0]
45-
return await generateLqip(filePath, isDevelopment, lqipType, lqipSize)
51+
return await generateLqip(filePath, lqipType, lqipSize, isDevelopment)
4652
}
4753

4854
if (!isPrerendered && !isDevelopment) {
4955
const filePath = join(process.cwd(), 'dist', 'client', imagePath.src)
50-
return await generateLqip(filePath, isDevelopment, lqipType, lqipSize)
56+
return await generateLqip(filePath, lqipType, lqipSize, isDevelopment)
5157
}
5258

5359
if (!isDevelopment && imagePath.src.startsWith('/_astro/')) {
5460
const buildPath = join(process.cwd(), 'dist', imagePath.src)
55-
return await generateLqip(buildPath, isDevelopment, lqipType, lqipSize)
61+
return await generateLqip(buildPath, lqipType, lqipSize, isDevelopment)
5662
}
5763

5864
return undefined

src/utils/useLqipImage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function useLqipImage({
1313
lqipSize = 4,
1414
styleProps = {},
1515
forbiddenVars = ['--lqip-background', '--z-index', '--opacity'],
16-
isDevelopment = false,
16+
isDevelopment,
1717
isPrerendered
1818
}: ComponentsOptions) {
1919
let getImagePath: string | { src: string } | null
@@ -29,7 +29,7 @@ export async function useLqipImage({
2929
let lqipImage
3030
if (getImagePath) {
3131
const lqipInput = typeof getImagePath === 'string' ? { src: getImagePath } : getImagePath
32-
lqipImage = await getLqip(lqipInput, isDevelopment, isPrerendered, lqip, lqipSize)
32+
lqipImage = await getLqip(lqipInput, lqip, lqipSize, isDevelopment, isPrerendered)
3333
}
3434

3535
let svgHTML = ''

0 commit comments

Comments
 (0)