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
ES5 build, recursive node tree (#78), TypeScript typings, main module entry point, bugfixing #83
ES5 build, recursive node tree (#78), TypeScript typings, main module entry point, bugfixing #83
Conversation
Oh, I have some linting to do :-) |
9c53b86
to
259a338
Compare
Ok, Linter and Unit tests are happy now, but the E2E tests fail. I still have some homework to do :-) |
e4b3f23
to
3bb179b
Compare
.editorconfig
Outdated
insert_final_newline = true | ||
spaces_around_brackets = false | ||
spaces_around_operators = false | ||
trim_trailing_whitespace = true |
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.
as discussed - this file is automatically copied form https://github.com/brainly/frontend-tools-configs so we don't want it in the repo
package.json
Outdated
}, | ||
"dependencies": { | ||
"murmur2js": "^1.0.0", | ||
"normalize-css-color": "^1.0.2", | ||
"sketch-constants": "^1.1.0", | ||
"sketchapp-json-plugin": "^0.1.2" | ||
}, | ||
"files": ["asketch2sketch", "html2asketch", "build"], |
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.
let's exclue build/asketch2sketch.sketchplugin
right: groupBCR.right, | ||
bottom: groupBCR.bottom, | ||
width: groupBCR.right - groupBCR.left, | ||
height: groupBCR.bottom - groupBCR.top |
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.
use already calculated width and height
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.
Actually, the groupBCR does not have width and height properties, as the reduction produces top,left,bottom,right, only. So for the final result, those four properties are needed.
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.
You are right 👍
html2asketch/nodeToSketchLayers.js
Outdated
width: textBCR.width, | ||
height: textBCR.height, | ||
x: textBCR.left || 0, | ||
y: (textBCR.top || 0) + fixY, |
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.
let's skip || 0
@@ -181,8 +184,6 @@ export default function nodeToSketchLayers(node, options) { | |||
} | |||
} | |||
|
|||
style.addOpacity(opacity); |
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.
let's put that into options and make enabled by default
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.
While trying to fix this I was wondering if the former implementation was even correct.
Currently, the opacity is set to the shape-group only, but not to any other layer, like text or SVG. So we get a transparent background and an opaque text on it.
I think we should either add the opacity to all layers, or remove it entirely, documenting that it is the container's responsibility to set the opacity.
What do you think?
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.
Good point - it should be added to all layers, but feel free to skip this fact for the sake of this PR, I can handle it separately.
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.
I continued to think about this layers vs. group opacity thing, and I come to the conclusion that the problem is even worse. When adding opacity to each layer, the (outside coded) recursion will have to apply parent opacity to children as well, as the node children inside transparent parents will not issue any opacity value.
I think it is a better idea to leave out the opacity entirely in regards of the layers, and let the caller apply opacity to the container. Any other approach results in a complex API, as far as I can see.
Or do you have a good idea as alternative?
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.
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.
Yes, that was the approach we discussed in the call. My issue is that I can hardly find an intact use-case for the default option with opacity layers.
As long as your DOM node does not have any children, everything is fine. The shape group and text nodes get the opacity, and it looks great.
But what if the DOM node has children (resp. parents have opacity)?
An example:
We have two nested nodes, A and B (B inside A).
A has an opacity of 0.5, while B is opaque (no transparency).
The caller will be responsible for a recursion, and for A, nodeToSketchLayers will return layers with opacity 0.5, while for B, it will return opaque layers.
Now the caller wants to put all layers into one Sketch page.
If they flatten the layers, the node B layers will be opaque, which is wrong, as they are nested in the A node without opacity 0.5.
If he groups the nodes' layers hierarchically and puts the opacity into the grouping, they fail as well, as the node A layers' opacities are now in the way.
So basically my point is that setting a layer opacity does not work at all, unless the nodeToLayers function gets concise of its parents' opacity situation (which multipies up in the entire ancestry). This would have to be an API option, and I think this is not very clean.
Should we have a call? :-)
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.
As discussed in a call, we currently have three options:
- the current behavior, where only the current node's opacity is set into the layers
- not setting any layer opacity at all, which is required for the grouping function
- a solution where nodeToSketchLayers collects the parents' opacities and multiplies them, so it is responsible for the parent opacity situation.
For this PR, I will implement options 1 and 2 (with 1 being the default).
In the future, the 3rd option is the best one when not grouping and should be available as well (or maybe even be a fix for option 1).
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.
👍 I like the idea of making 3rd option a fix for option 1, so I went ahead and opened an issue for it - #84
html2asketch/nodeToSketchLayers.js
Outdated
@@ -195,8 +196,13 @@ export default function nodeToSketchLayers(node, options) { | |||
|
|||
const rectangle = new Rectange({width, height, cornerRadius}); | |||
|
|||
if (options && isNotEmpty(options.rectangleName)) { | |||
leaf.setName(options.rectangleName); |
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.
let's make it a callback (node) => string
|
||
function isNotEmpty(value) { | ||
return value !== undefined && value !== null && value !== ''; | ||
} |
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.
let's put this guy into helpers
|
||
// Collect layers for the node level itself | ||
const layers = nodeToSketchLayers(node, options) || []; | ||
|
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.
let's check here if node we are trying to process is visible to avoid empty groups
|
||
// Set the group name to the node name, but support a hint in the DOM | ||
|
||
const nodeName = node.getAttribute && node.getAttribute('data-sketch-name'); |
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.
let's make it more general by having a callback
html2asketch/group.d.ts
Outdated
|
||
export default class Group extends Base { | ||
constructor(props: GroupProps); | ||
} |
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.
let's see if we can validate these types - see if they match the classes they are discribing
} | ||
|
||
export default function nodeTreeToSketchGroup(node, options) { | ||
const bcr = node.getBoundingClientRect(); |
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 an element is display: contents
this will always return with all 0
s. For this particular feature, you might consider a check to see if that's the case then check the contents or the HTMLElement.shadowRoot
to see if you can't ensure there's an element.
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.
Oh, nice, I didn't know that! Fantastic that you figured it all out 👏 This PR is already massive though, so maybe lets add shadow DOM support in a separate one. WDYT?
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.
@calebdwilliams Thanks for the feedback, I am quite new to frontend technologies, at least the modern ones, so I don't know what the contents display type is, and I only heard of the shadow DOM so far, never used it. Can you please provide an example snippet of the function you have in mind?
1cbfece
to
abcec5b
Compare
abcec5b
to
979d821
Compare
By the way, I had to add two more things to the PR in the meantime, I hope you don't mind:
|
979d821
to
38e98ad
Compare
WDYT about making it optional? Also, WDYT about adding an E2E test for BTW Any news about type validation? |
38e98ad
to
1bc6302
Compare
Yes, I will make the artboard optional, good point. I don't know Sketch too well so I definitely need advices here. But an option is good for both sides. |
@kdzwinel The E2E again: Can you give me a hint where you would put the second test? Currently, you have one webpacked inject.js, with a default function that returns the JSON, and one expected.asketch.json. Should I duplicate these for the group and/or page sketch test? Where is the best place to split into separate tests? |
Otherwise, I have now reworked everything we discussed, from yesterday and today, all tests are green, and in our project, the result is good. From my point of view, the PR is complete, but I again changed a lot, so please review once again. Thanks! |
It boils down to this:
(BTW there is https://github.com/brainly/html-sketchapp/blob/master/test/run.js#L10 to accomodate for randomness in the produced file) Let me know if you'll run into any issues!
No worries, we can handle that separately 👌 #85 |
Everything looks great - fantastic work 👏 I'll give it a try locally tomorrow and merge it 💪 |
@kdzwinel I have now developed an E2E test by introducing a
I decided to test nodeTreeToSketchPage, with artboard, so the test covers all the functionality.
Using yarn, I have now managed to install. And the tests fail, I will fix this :-) |
@kdzwinel I am so proud, my first puppeteer E2E test :-) |
You rock 🎸 OK Tom, I'm merging this because it's a pure gold 🥇I did find some small issues, but I'll either fix them myself on master or create tickets for them. Thanks again for a great contribution 👏 |
No description provided.