-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add feature detection for WebKit #50
Merged
+435
−44
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
117b2a8
Detect whether polyfill is applicable
yhatt 52656d6
Add JSDoc to some public methods
yhatt 9585158
Merge branch 'main' into webkit-feature-detection
yhatt 3a69b4f
Fix typing error
yhatt 9dc1897
Clear buggy SVG debris in the first run of WebKit polyfill
yhatt 92e8eb7
Update README.md
yhatt 7727a1d
[ci skip] Update README.md
yhatt 26c5919
Update CHANGELOG.md
yhatt 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 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 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 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 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,27 @@ | ||
let _isRequiredPolyfill: boolean | undefined | ||
|
||
export const isRequiredPolyfill = async () => { | ||
if (_isRequiredPolyfill === undefined) { | ||
const canvas = document.createElement('canvas') | ||
canvas.width = 10 | ||
canvas.height = 10 | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const ctx = canvas.getContext('2d')! | ||
|
||
const svgImg = new Image(10, 10) | ||
const svgOnLoadPromise = new Promise<void>((resolve) => { | ||
svgImg.addEventListener('load', () => resolve()) | ||
}) | ||
|
||
svgImg.crossOrigin = 'anonymous' | ||
svgImg.src = | ||
'data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%2210%22%20viewBox%3D%220%200%201%201%22%3E%3CforeignObject%20width%3D%221%22%20height%3D%221%22%20requiredExtensions%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cdiv%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%20style%3D%22width%3A%201px%3B%20height%3A%201px%3B%20background%3A%20red%3B%20position%3A%20relative%22%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fsvg%3E' | ||
|
||
await svgOnLoadPromise | ||
ctx.drawImage(svgImg, 0, 0) | ||
|
||
_isRequiredPolyfill = ctx.getImageData(5, 5, 1, 1).data[3] < 128 | ||
} | ||
return _isRequiredPolyfill | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
"resolveJsonModule": true, | ||
"sourceMap": true | ||
}, | ||
"include": ["src", "test"] | ||
"include": ["src"] | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If non-polyfilled SVG had been rendered before applying polyfills, WebKit sometime leaves SVG debris. An updated feature detection is asynchronous so we have to deal with debris.
This snippet triggers repaint in the whole of HTML contents to clear SVG debris in everywhere.