forked from MicrosoftEdge/css-usage
-
Notifications
You must be signed in to change notification settings - Fork 0
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 new SVG CSS transform and preserve 3d recipe. #2
Open
jevery23
wants to merge
5
commits into
master
Choose a base branch
from
user/joevery/css-transform_preserve-3d
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
94b3a5e
Add new SVG CSS transform and preserve 3d recipe.
jevery23 0e04ba9
Update svg_css-transform_preserve-3d crawler recipe as a result of PR…
jevery23 a324070
Added the ability to record transform value in css transform script.
jevery23 118f356
Added the ability to differentiate count of transform values seen by …
jevery23 23240cc
Remove not needed Crawler recipes.
jevery23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
RECIPE: svg_css-transform_preserve-3d | ||
------------------------------------------------------------- | ||
Author: joevery | ||
Description: Get count of svg elements on page along with how many contain the transform CSS property and the transform-style CSS property with value preserve-3d in their namespace. | ||
*/ | ||
void function() { | ||
window.CSSUsage.StyleWalker.recipesToRun.push( | ||
function svg_css_transform_preserve_3d(element, results) | ||
{ | ||
var nodeName = element.nodeName; | ||
|
||
if (nodeName == "svg") | ||
{ | ||
var elementsToCheck = [element]; | ||
var elementHasTranform = false; | ||
var elementHas3DStyle = false; | ||
|
||
while (elementsToCheck.length > 0 && (!elementHas3DStyle || !elementHasTranform)) | ||
{ | ||
var children = []; | ||
|
||
for (var i = 0; i < elementsToCheck.length; ++i) | ||
{ | ||
var e = elementsToCheck[i]; | ||
|
||
// If no CSS on element, then don't do what is inside if statement, otherwise it will hit error. | ||
if (e.CSSUsage) | ||
{ | ||
if (e.CSSUsage["transform"]) { | ||
elementHasTranform = true; | ||
} | ||
|
||
// We have to check for the transform-style property first before checking its values, otherwise it will hit error. | ||
var transformStyle = e.CSSUsage["transform-style"]; | ||
if (transformStyle) | ||
{ | ||
if (transformStyle.valuesArray.includes("preserve-3d")) { | ||
elementHas3DStyle = true; | ||
} | ||
} | ||
} | ||
|
||
// Need to convert children HTML collection to array to combine with other children found. | ||
children = children.concat(Array.from(e.children)); | ||
} | ||
elementsToCheck = children; | ||
} | ||
|
||
results["svg"] = results["svg"] || { count: 0, }; | ||
results["svg"].count++; | ||
|
||
if (elementHasTranform) | ||
{ | ||
results["svg"]["transform"] = results["svg"]["transform"] || { count: 0, }; | ||
results["svg"]["transform"].count++; | ||
} | ||
|
||
if (elementHas3DStyle) | ||
{ | ||
results["svg"]["transform-style_preserve-3d"] = results["svg"]["transform-style_preserve-3d"] || { count: 0, }; | ||
results["svg"]["transform-style_preserve-3d"].count++; | ||
} | ||
} | ||
|
||
return results; | ||
}); | ||
}(); |
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,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>SVG CSS transform and preserve-3d test</title> | ||
<style> | ||
text { | ||
width: 70%; | ||
margin: 0 auto; | ||
display: block; | ||
transform: perspective(300px) rotateX(30deg); | ||
transform-style: preserve-3d; | ||
} | ||
</style> | ||
<script src="../../Recipe.min.js"></script> | ||
</head> | ||
<body> | ||
<svg viewBox="0 0 100 100"> | ||
<g> | ||
<circle cx="20" cy="20" r="20"/> | ||
<text x="0" y="20">YAY!!!!!!!!!!!</text> | ||
</g> | ||
</svg> | ||
</body> | ||
</html> |
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.
This will only allow
<svg>
to be looked at. What if the transform is on a different element. I'm trying to track down every possible element that it can be on but the spec doesn't seem clear here so I'll sync up with Bogdan on this.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.
Just noticed that you're adding children to the elementsToCheck array, not sure if we should do it this way since recipes will pass in every element. So you should be able to just check that the nodeName is contained within an array that contains various SVG elements (which I'll get to you after chatting with Bogdan) like this:
if (elementToCheck.includes(nodeName))