-
Notifications
You must be signed in to change notification settings - Fork 0
COM-2479: Добавил возможность использовать csssr.images без изменения размера изображений #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8590f6b
wip support of different originalPixelRatios
Yankovsky 8fefff4
COM-2479: - добавил возможность использовать изображения без изменени…
vkosinov 49ed84a
make types more stricter
Yankovsky f2007a9
lint, refactor, rename, add example with background
Yankovsky 8031e58
fix typo
Yankovsky a0e2998
improve typings
Yankovsky 820d213
COM-2479:
vkosinov 03135e1
add type guard for number | undefined in imgproxyUrlBuilder
Yankovsky 8da663d
lint
Yankovsky 9c2a469
Fixed incorrect check that interpret 0 as falsy value
Yankovsky 8b2dfa4
COM-2479:
vkosinov 4760f22
Merge branch 'master' into COM-2479
vkosinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { getCompressionRatio } from '../index'; | ||
|
|
||
| test('Pixel ratios 1x', () => { | ||
| expect(getCompressionRatio(['1x'])).toStrictEqual({ '1x': 0 }); | ||
| }); | ||
|
|
||
| test('Pixel ratios 1x, 2x', () => { | ||
| expect(getCompressionRatio(['1x', '2x'])).toStrictEqual({ '1x': 0.5, '2x': 0 }); | ||
| }); | ||
|
|
||
| test('Pixel ratios 1x, 2x, 3x', () => { | ||
| expect(getCompressionRatio(['1x', '2x', '3x'])).toStrictEqual({ | ||
| '1x': 0.33333, | ||
| '2x': 0.66667, | ||
| '3x': 0, | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Dpr, CompressionRatio } from '../types'; | ||
|
|
||
| export const getCompressionRatio = (pixelRatios: Dpr[]): CompressionRatio => { | ||
| const length = pixelRatios.length; | ||
|
|
||
| return pixelRatios.reduce((acc, item, index) => { | ||
| if (index + 1 === length) { | ||
| acc[item] = 0; | ||
| return acc; | ||
| } | ||
|
|
||
| acc[item] = Number(((index + 1) / length).toFixed(5)); | ||
| return acc; | ||
| }, {} as CompressionRatio); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import { BreakpointSource } from '../types'; | ||
|
|
||
| export const getOriginal = (source: BreakpointSource): string => | ||
| source.srcSets[source.srcSets.length - 1].srcSet['3x']; | ||
| export const getOriginal = (source: BreakpointSource): string => { | ||
| const srcSet = source.srcSets[source.srcSets.length - 1].srcSet; | ||
|
|
||
| return srcSet['3x'] || srcSet['2x'] || srcSet['1x']; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Dpr } from '../types'; | ||
|
|
||
| export const getPixelRatios = (originalPixelRatio: Dpr): Dpr[] => { | ||
| switch (originalPixelRatio) { | ||
| case '1x': | ||
| return ['1x']; | ||
| case '2x': | ||
| return ['1x', '2x']; | ||
| case '3x': | ||
| return ['1x', '2x', '3x']; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,15 @@ | ||
| // https://stackoverflow.com/a/27232658 | ||
|
|
||
| const canUseWebp = (): boolean => { | ||
| const canvas = document.createElement('canvas') | ||
| canvas.width = canvas.height = 1 | ||
| return Boolean(canvas.toDataURL && | ||
| canvas.toDataURL('image/webp') && | ||
| canvas.toDataURL('image/webp').indexOf('image/webp') === 5) | ||
| } | ||
| const canvas = document.createElement('canvas'); | ||
| canvas.width = canvas.height = 1; | ||
| return Boolean( | ||
| canvas.toDataURL && | ||
| canvas.toDataURL('image/webp') && | ||
| canvas.toDataURL('image/webp').indexOf('image/webp') === 5, | ||
| ); | ||
| }; | ||
|
|
||
| if (canUseWebp()) { | ||
| document.documentElement.classList.add('webp') | ||
| document.documentElement.classList.add('webp'); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.