Skip to content

Commit 5e9bd4e

Browse files
committed
chore: fmt
1 parent c175d37 commit 5e9bd4e

27 files changed

+563
-610
lines changed

.oxfmtrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"semi": false,
4+
"singleQuote": true
5+
}

CHANGELOG.md

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,63 @@
11
## [0.3.4](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.3.3...v0.3.4) (2023-01-23)
22

3-
43
### Features
54

6-
* add the inferDimensions option ([#18](https://github.com/ElMassimo/vite-plugin-image-presets/issues/18)) ([a3269f9](https://github.com/ElMassimo/vite-plugin-image-presets/commit/a3269f9d820db3c6ebd947221927615bea30fcc4))
7-
8-
5+
- add the inferDimensions option ([#18](https://github.com/ElMassimo/vite-plugin-image-presets/issues/18)) ([a3269f9](https://github.com/ElMassimo/vite-plugin-image-presets/commit/a3269f9d820db3c6ebd947221927615bea30fcc4))
96

107
## [0.3.3](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.3.2...v0.3.3) (2022-10-27)
118

12-
139
### Bug Fixes
1410

15-
* update to sharp@0.30.5 ([#15](https://github.com/ElMassimo/vite-plugin-image-presets/issues/15)) ([42e658a](https://github.com/ElMassimo/vite-plugin-image-presets/commit/42e658a6b7e4c96e3dc5ddf8e1dea712cda83f60))
16-
17-
11+
- update to sharp@0.30.5 ([#15](https://github.com/ElMassimo/vite-plugin-image-presets/issues/15)) ([42e658a](https://github.com/ElMassimo/vite-plugin-image-presets/commit/42e658a6b7e4c96e3dc5ddf8e1dea712cda83f60))
1812

1913
## [0.3.2](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.3.1...v0.3.2) (2022-07-21)
2014

21-
2215
### Bug Fixes
2316

24-
* escape srcset ([#8](https://github.com/ElMassimo/vite-plugin-image-presets/issues/8)) ([3b2ac77](https://github.com/ElMassimo/vite-plugin-image-presets/commit/3b2ac773ba4a23ced47d7d07757b932b9bdb738f))
25-
17+
- escape srcset ([#8](https://github.com/ElMassimo/vite-plugin-image-presets/issues/8)) ([3b2ac77](https://github.com/ElMassimo/vite-plugin-image-presets/commit/3b2ac773ba4a23ced47d7d07757b932b9bdb738f))
2618

2719
### Features
2820

29-
* loosen deps to allow more recent versions of dependencies ([3e3e94a](https://github.com/ElMassimo/vite-plugin-image-presets/commit/3e3e94a58c9b1b06c2ba14806f028d12f518269f))
30-
31-
21+
- loosen deps to allow more recent versions of dependencies ([3e3e94a](https://github.com/ElMassimo/vite-plugin-image-presets/commit/3e3e94a58c9b1b06c2ba14806f028d12f518269f))
3222

3323
## [0.3.1](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.3.0...v0.3.1) (2022-01-16)
3424

35-
3625
### Bug Fixes
3726

38-
* ensure src is deterministic, always take the last ([6579611](https://github.com/ElMassimo/vite-plugin-image-presets/commit/65796117cd67f82241f7741343f8d21894fcb29b))
39-
* pass additional parameters as args to the generate fn ([053da5d](https://github.com/ElMassimo/vite-plugin-image-presets/commit/053da5dffbbaaf585adda954140a8466f9b23638))
40-
41-
27+
- ensure src is deterministic, always take the last ([6579611](https://github.com/ElMassimo/vite-plugin-image-presets/commit/65796117cd67f82241f7741343f8d21894fcb29b))
28+
- pass additional parameters as args to the generate fn ([053da5d](https://github.com/ElMassimo/vite-plugin-image-presets/commit/053da5dffbbaaf585adda954140a8466f9b23638))
4229

4330
# [0.3.0](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.2.0...v0.3.0) (2022-01-14)
4431

45-
4632
### Bug Fixes
4733

48-
* handle unexpected errors without crashing the vite server ([e174936](https://github.com/ElMassimo/vite-plugin-image-presets/commit/e1749363dbb4b5a984e48815f35ee5043f582f30))
49-
* remove undefined and null attrs ([e3cf8e7](https://github.com/ElMassimo/vite-plugin-image-presets/commit/e3cf8e71fbd431e84e6dc008f8e6bb8ca293b888))
50-
34+
- handle unexpected errors without crashing the vite server ([e174936](https://github.com/ElMassimo/vite-plugin-image-presets/commit/e1749363dbb4b5a984e48815f35ee5043f582f30))
35+
- remove undefined and null attrs ([e3cf8e7](https://github.com/ElMassimo/vite-plugin-image-presets/commit/e3cf8e71fbd431e84e6dc008f8e6bb8ca293b888))
5136

5237
### Features
5338

54-
* add `src` query param support and allow `srcset` to specify an index ([53396c6](https://github.com/ElMassimo/vite-plugin-image-presets/commit/53396c611dccdfe94e686da7b35c229fbec15022))
55-
* add `srcset` param for direct usage (close [#2](https://github.com/ElMassimo/vite-plugin-image-presets/issues/2)) ([7660af4](https://github.com/ElMassimo/vite-plugin-image-presets/commit/7660af402596e96b0679996b8831c7087a1a4106))
56-
57-
39+
- add `src` query param support and allow `srcset` to specify an index ([53396c6](https://github.com/ElMassimo/vite-plugin-image-presets/commit/53396c611dccdfe94e686da7b35c229fbec15022))
40+
- add `srcset` param for direct usage (close [#2](https://github.com/ElMassimo/vite-plugin-image-presets/issues/2)) ([7660af4](https://github.com/ElMassimo/vite-plugin-image-presets/commit/7660af402596e96b0679996b8831c7087a1a4106))
5841

5942
# [0.2.0](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.1.1...v0.2.0) (2022-01-12)
6043

61-
6244
### Bug Fixes
6345

64-
* use the .avif file extension ([5c35a2e](https://github.com/ElMassimo/vite-plugin-image-presets/commit/5c35a2ec219f3f80efa2c542a89434f37a81fc43))
65-
46+
- use the .avif file extension ([5c35a2e](https://github.com/ElMassimo/vite-plugin-image-presets/commit/5c35a2ec219f3f80efa2c542a89434f37a81fc43))
6647

6748
### Features
6849

69-
* add `hdPreset` based on the Jake Archibald article ([a02129a](https://github.com/ElMassimo/vite-plugin-image-presets/commit/a02129a0ac9de6a674b7d9258ae3593d1e1ac7f5))
70-
* add densityPreset that uses density condition descriptors ([9aa98a1](https://github.com/ElMassimo/vite-plugin-image-presets/commit/9aa98a17a66cc67153092ea739725c5cfcf80525))
71-
* add loading="lazy" by default to all presets ([24bf381](https://github.com/ElMassimo/vite-plugin-image-presets/commit/24bf3817907bd7753880038b5b06ed4bbd4413eb))
72-
* allow async `generate` functions to support reading metadata ([ad48252](https://github.com/ElMassimo/vite-plugin-image-presets/commit/ad482526e777c290d3c3a36b765a7fb95a02d68c))
73-
* **api:** add `writeImages` and `purgeCache` ([1c831d3](https://github.com/ElMassimo/vite-plugin-image-presets/commit/1c831d366a297dbbb411215e4036918cda161f57))
74-
* clean cached images that are no longer used ([d0879b3](https://github.com/ElMassimo/vite-plugin-image-presets/commit/d0879b300f7f8daab561d1cf6edf2262a0816862))
75-
* strongly typed options for format options ([7db1e03](https://github.com/ElMassimo/vite-plugin-image-presets/commit/7db1e03703dd20cf45583718ff80e5f84e7842a5))
76-
* support 'original' format and widths in presets ([822ffb1](https://github.com/ElMassimo/vite-plugin-image-presets/commit/822ffb1a8ae30b8a9f072c21119e6d6c3d807bdf))
77-
78-
50+
- add `hdPreset` based on the Jake Archibald article ([a02129a](https://github.com/ElMassimo/vite-plugin-image-presets/commit/a02129a0ac9de6a674b7d9258ae3593d1e1ac7f5))
51+
- add densityPreset that uses density condition descriptors ([9aa98a1](https://github.com/ElMassimo/vite-plugin-image-presets/commit/9aa98a17a66cc67153092ea739725c5cfcf80525))
52+
- add loading="lazy" by default to all presets ([24bf381](https://github.com/ElMassimo/vite-plugin-image-presets/commit/24bf3817907bd7753880038b5b06ed4bbd4413eb))
53+
- allow async `generate` functions to support reading metadata ([ad48252](https://github.com/ElMassimo/vite-plugin-image-presets/commit/ad482526e777c290d3c3a36b765a7fb95a02d68c))
54+
- **api:** add `writeImages` and `purgeCache` ([1c831d3](https://github.com/ElMassimo/vite-plugin-image-presets/commit/1c831d366a297dbbb411215e4036918cda161f57))
55+
- clean cached images that are no longer used ([d0879b3](https://github.com/ElMassimo/vite-plugin-image-presets/commit/d0879b300f7f8daab561d1cf6edf2262a0816862))
56+
- strongly typed options for format options ([7db1e03](https://github.com/ElMassimo/vite-plugin-image-presets/commit/7db1e03703dd20cf45583718ff80e5f84e7842a5))
57+
- support 'original' format and widths in presets ([822ffb1](https://github.com/ElMassimo/vite-plugin-image-presets/commit/822ffb1a8ae30b8a9f072c21119e6d6c3d807bdf))
7958

8059
## [0.1.1](https://github.com/ElMassimo/vite-plugin-image-presets/compare/v0.1.0...v0.1.1) (2022-01-11)
8160

82-
83-
8461
# 0.1.0
8562

8663
Initial Version, with `widthPreset`.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
This [Vite] plugin allows you to define presets for image processing using [Sharp],
2929
allowing you to optimize, resize, and process images consistently and with ease.
3030

31-
[__Demo__ 🖼][live]
31+
[**Demo** 🖼][live]
3232

3333
## Installation 💿
3434

e2e/images.spec.ts

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
import { expect, test } from "@playwright/test";
1+
import { expect, test } from '@playwright/test'
22

3-
test("images are rendered in the production build", async ({ page }) => {
4-
await page.goto("/");
3+
test('images are rendered in the production build', async ({ page }) => {
4+
await page.goto('/')
55

66
// Wait for the page to load
7-
await expect(page.locator("h1")).toBeVisible();
7+
await expect(page.locator('h1')).toBeVisible()
88

99
// Check all img elements have loaded (naturalWidth > 0 means the image loaded)
10-
const images = page.locator("img");
11-
const count = await images.count();
12-
expect(count).toBeGreaterThan(0);
10+
const images = page.locator('img')
11+
const count = await images.count()
12+
expect(count).toBeGreaterThan(0)
1313

1414
for (let i = 0; i < count; i++) {
15-
const img = images.nth(i);
16-
await expect(img).toBeVisible();
17-
const naturalWidth = await img.evaluate((el: HTMLImageElement) => el.naturalWidth);
15+
const img = images.nth(i)
16+
await expect(img).toBeVisible()
17+
const naturalWidth = await img.evaluate((el: HTMLImageElement) => el.naturalWidth)
1818
expect(
1919
naturalWidth,
20-
`img[${i}] (${await img.getAttribute("src")}) should have loaded`,
21-
).toBeGreaterThan(0);
20+
`img[${i}] (${await img.getAttribute('src')}) should have loaded`,
21+
).toBeGreaterThan(0)
2222
}
23-
});
23+
})
2424

25-
test("picture elements have source variants", async ({ page }) => {
26-
await page.goto("/");
25+
test('picture elements have source variants', async ({ page }) => {
26+
await page.goto('/')
2727

28-
const pictures = page.locator("picture");
29-
const count = await pictures.count();
30-
expect(count).toBeGreaterThan(0);
28+
const pictures = page.locator('picture')
29+
const count = await pictures.count()
30+
expect(count).toBeGreaterThan(0)
3131

3232
for (let i = 0; i < count; i++) {
33-
const sources = pictures.nth(i).locator("source");
34-
const sourceCount = await sources.count();
35-
expect(sourceCount, `picture[${i}] should have source elements`).toBeGreaterThan(0);
33+
const sources = pictures.nth(i).locator('source')
34+
const sourceCount = await sources.count()
35+
expect(sourceCount, `picture[${i}] should have source elements`).toBeGreaterThan(0)
3636

3737
// Verify source srcset attributes reference actual files (not virtual IDs)
3838
for (let j = 0; j < sourceCount; j++) {
39-
const srcset = await sources.nth(j).getAttribute("srcset");
40-
expect(srcset, `picture[${i}] source[${j}] should have srcset`).toBeTruthy();
41-
expect(srcset).not.toContain("/@imagepresets/");
39+
const srcset = await sources.nth(j).getAttribute('srcset')
40+
expect(srcset, `picture[${i}] source[${j}] should have srcset`).toBeTruthy()
41+
expect(srcset).not.toContain('/@imagepresets/')
4242
}
4343
}
44-
});
44+
})
4545

46-
test("processed image files are served correctly", async ({ page, request }) => {
47-
await page.goto("/");
46+
test('processed image files are served correctly', async ({ page, request }) => {
47+
await page.goto('/')
4848

4949
// Collect all image URLs from srcset and src attributes
5050
const imageUrls = await page.evaluate(() => {
51-
const urls = new Set<string>();
52-
for (const source of document.querySelectorAll("source[srcset]")) {
53-
const srcset = source.getAttribute("srcset")!;
54-
for (const entry of srcset.split(",")) {
55-
const url = entry.trim().split(/\s+/)[0];
56-
if (url) urls.add(url);
51+
const urls = new Set<string>()
52+
for (const source of document.querySelectorAll('source[srcset]')) {
53+
const srcset = source.getAttribute('srcset')!
54+
for (const entry of srcset.split(',')) {
55+
const url = entry.trim().split(/\s+/)[0]
56+
if (url) urls.add(url)
5757
}
5858
}
59-
for (const img of document.querySelectorAll("img[src]")) {
60-
const src = img.getAttribute("src")!;
61-
if (src && !src.startsWith("data:")) urls.add(src);
59+
for (const img of document.querySelectorAll('img[src]')) {
60+
const src = img.getAttribute('src')!
61+
if (src && !src.startsWith('data:')) urls.add(src)
6262
}
63-
return [...urls];
64-
});
63+
return [...urls]
64+
})
6565

66-
expect(imageUrls.length).toBeGreaterThan(0);
66+
expect(imageUrls.length).toBeGreaterThan(0)
6767

6868
// Verify each processed image URL returns 200
6969
for (const url of imageUrls) {
70-
const response = await request.get(url);
71-
expect(response.status(), `${url} should be served`).toBe(200);
72-
expect(response.headers()["content-type"]).toMatch(/^image\//);
70+
const response = await request.get(url)
71+
expect(response.status(), `${url} should be served`).toBe(200)
72+
expect(response.headers()['content-type']).toMatch(/^image\//)
7373
}
74-
});
74+
})

example/App.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ import fullImage from '@images/vite-ruby.png?preset=full'
1717
</ExternalLink>
1818
</h1>
1919
<ExternalLink href="https://vite-ruby.netlify.app">
20-
<img srcset="@images/vite-rails.png?preset=thumbnail&srcset" height="48"/>
20+
<img srcset="@images/vite-rails.png?preset=thumbnail&srcset" height="48" />
2121
<Caption>Optimized based on screen density, single-format</Caption>
2222
</ExternalLink>
2323
<ExternalLink href="https://iles-docs.netlify.app">
24-
<Image :src="roundImage"/>
24+
<Image :src="roundImage" />
2525
<Caption>A custom transform squares the image and rounds its borders</Caption>
2626
</ExternalLink>
27-
<ExternalLink href="https://jakearchibald.com/2021/serving-sharp-images-to-high-density-screens/">
28-
<Image :src="pandaImage"/>
27+
<ExternalLink
28+
href="https://jakearchibald.com/2021/serving-sharp-images-to-high-density-screens/"
29+
>
30+
<Image :src="pandaImage" />
2931
<Caption>Optimized based on screen density and size, multi-format</Caption>
3032
</ExternalLink>
3133
<ExternalLink href="https://vite-ruby.netlify.app">
32-
<Image :src="fullImage"/>
34+
<Image :src="fullImage" />
3335
<Caption>No resizing, multi-format</Caption>
3436
</ExternalLink>
3537
</main>
@@ -42,7 +44,9 @@ import fullImage from '@images/vite-ruby.png?preset=full'
4244
</ExternalLink>
4345
</li>
4446
<li>
45-
<ExternalLink href="https://jakearchibald.com/2021/serving-sharp-images-to-high-density-screens/">
47+
<ExternalLink
48+
href="https://jakearchibald.com/2021/serving-sharp-images-to-high-density-screens/"
49+
>
4650
Halve the size of images by optimising for high density displays
4751
</ExternalLink>
4852
</li>

example/Caption.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<p class="caption"><slot/></p>
2+
<p class="caption"><slot /></p>
33
</template>
44

55
<style scoped>

example/ExternalLink.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<template>
2-
<a target="_blank" rel="noreferrer"><slot/></a>
2+
<a target="_blank" rel="noreferrer"><slot /></a>
33
</template>

example/Image.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
import { computed } from 'vue'
33
const props = defineProps<{ src: string | any[] }>()
44
5-
const allSources = computed(() =>
6-
Array.isArray(props.src) ? props.src : [{ srcset: props.src }])
5+
const allSources = computed(() => (Array.isArray(props.src) ? props.src : [{ srcset: props.src }]))
76
87
const sources = computed(() => allSources.value.slice(0, -1))
98
const lastSource = computed(() => allSources.value[allSources.value.length - 1])
109
</script>
1110

1211
<script lang="ts">
1312
export default {
14-
inheritAttrs: false
13+
inheritAttrs: false,
1514
}
1615
</script>
1716

1817
<template>
1918
<picture>
20-
<source v-for="(attrs, index) in sources" :key="index" v-bind="attrs">
21-
<img v-bind="{ ...lastSource, ...$attrs }">
19+
<source v-for="(attrs, index) in sources" :key="index" v-bind="attrs" />
20+
<img v-bind="{ ...lastSource, ...$attrs }" />
2221
</picture>
2322
</template>

example/env.d.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
/// <reference types="vue/macros-global" />
33

44
// images
5-
declare module "*&srcset" {
6-
const src: string;
7-
export default src;
5+
declare module '*&srcset' {
6+
const src: string
7+
export default src
88
}
99

10-
declare module "*?preset=hd" {
11-
const src: import("vite-plugin-image-presets").ImageAttrs[];
12-
export default src;
10+
declare module '*?preset=hd' {
11+
const src: import('vite-plugin-image-presets').ImageAttrs[]
12+
export default src
1313
}
1414

15-
declare module "*?preset=full" {
16-
const src: import("vite-plugin-image-presets").ImageAttrs[];
17-
export default src;
15+
declare module '*?preset=full' {
16+
const src: import('vite-plugin-image-presets').ImageAttrs[]
17+
export default src
1818
}
1919

20-
declare module "*?preset=round" {
21-
const src: import("vite-plugin-image-presets").ImageAttrs[];
22-
export default src;
20+
declare module '*?preset=round' {
21+
const src: import('vite-plugin-image-presets').ImageAttrs[]
22+
export default src
2323
}
2424

25-
declare module "*?preset=thumbnail" {
26-
const src: import("vite-plugin-image-presets").ImageAttrs[];
27-
export default src;
25+
declare module '*?preset=thumbnail' {
26+
const src: import('vite-plugin-image-presets').ImageAttrs[]
27+
export default src
2828
}

0 commit comments

Comments
 (0)