Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,75 +1,5 @@
import {describe, expect, it} from 'vitest';
import {
// guessMaxImageWidth,
bytesToSize,
selectSrc,
fallbackParams,
} from '../components/helpers';

/*
describe('guessMaxImageWidth', () => {
it('Should calculate the maximum image width', () => {
const dimensions = {
width: 400,
height: 100,
}
const mockedWindow = {
screen: {
width: 100,
},
innerWidth: 1024,
innerHeight: 768,
}
const expected = dimensions.width
const result = guessMaxImageWidth(dimensions, mockedWindow)

expect(result).toEqual(expected)
})

it('Should calculate the maximum image width with screen changes', () => {
const dimensions = {
width: 400,
height: 100,
}
const mockedWindow = {
screen: {
width: 100,
},
innerWidth: 50,
innerHeight: 30,
}
const expected =
(dimensions.width / mockedWindow.innerWidth) * mockedWindow.screen.width
const result = guessMaxImageWidth(dimensions, mockedWindow)

expect(result).toEqual(expected)
})

it('Should calculate the maximum image width with screen changes and scroll', () => {
const body = document.getElementsByTagName('body')[0]
Object.defineProperty(body, 'clientHeight', {
get: () => {
return 400
},
})
const dimensions = {
width: 400,
height: 100,
}
const mockedWindow = {
screen: {
width: 100,
},
innerWidth: 50,
innerHeight: 100,
}
const expected = 450
const result = guessMaxImageWidth(dimensions, mockedWindow)

expect(result).toEqual(expected)
})
})
*/
import {bytesToSize, selectSrc} from '../components/helpers';

describe('bytesToSize', () => {
const bitsInKB = 1024;
Expand Down Expand Up @@ -169,18 +99,3 @@ describe('selectSrc', () => {
expect(result).toEqual(expected);
});
});

/*
describe('fallbackParams', () => {
it('Should return an empty object when run in the browser environment', () => {
const result = fallbackParams({
srcSet: [
{
format: 'webp',
},
],
});
expect(result).toEqual({});
});
});
*/

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ export const ssr =

export const nativeConnection = !ssr && !!window.navigator.connection;

// export const getScreenWidth = () => {
// if (ssr) return 0
// const devicePixelRatio = window.devicePixelRatio || 1
// const {screen} = window
// const {width} = screen
// // const angle = (screen.orientation && screen.orientation.angle) || 0
// // return Math.max(width, height)
// // const rotated = Math.floor(angle / 90) % 2 !== 0
// // return (rotated ? height : width) * devicePixelRatio
// return width * devicePixelRatio
// }
// export const screenWidth = getScreenWidth()

export const guessMaxImageWidth = (dimensions, w) => {
if (ssr) return 0;

Expand Down Expand Up @@ -64,25 +51,6 @@ export const bytesToSize = (bytes) => {
return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`;
};

// async function supportsWebp() {
// if (typeof createImageBitmap === 'undefined' || typeof fetch === 'undefined')
// return false
// return fetch(
// 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=',
// )
// .then(response => response.blob())
// .then(blob => createImageBitmap(blob).then(() => true, () => false))
// }
// let webp = undefined
// const webpPromise = supportsWebp()
// webpPromise.then(x => (webp = x))
// export default () => {
// if (webp === undefined) return webpPromise
// return {
// then: callback => callback(webp),
// }
// }

const detectWebpSupport = () => {
if (ssr) return false;
const elem = document.createElement('canvas');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,3 @@ export const xhrLoader = (url, options) => {
};
return result;
};

// Caveat: AbortController only supported in Chrome 66+
// Caveat: we still need imageLoader to do actual decoding,
// but if images are uncachable this will lead to two requests
// export const fetchLoader = (url, options) => {
// let controller = new AbortController()
// const signal = controller.signal
// const result = new Promise((resolve, reject) =>
// fetch(url, {...options, signal}).then(response => {
// if (response.ok) {
// options && options.onMeta && options.onMeta(response.headers)
// response
// .blob()
// .then(() => imageLoader(url))
// .then(resolve)
// } else {
// reject({status: response.status})
// }
// }, reject),
// )
// result.cancel = () => {
// if (!controller) throw new Error('Already canceled')
// controller.abort()
// controller = undefined
// }
// return result
// }
Loading