Skip to content
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

[css-shapes-2] Add a shape() syntax, which accepts shape-segments equivalent to SVG path #5711

Merged
merged 10 commits into from
Jan 7, 2021

Conversation

noamr
Copy link
Collaborator

@noamr noamr commented Nov 10, 2020

Add a draw() shape syntax, which accepts shape-segments equivalent to SVG path segments.

Fixes #5674

@astearns
Copy link
Member

Thanks for writing up the proposal! It might be better to put this into css-shapes-2, as everything in css-shapes-1 is a bit further along (with an implementation and tests), and we should likely get that finished in the process and push new work to the next level.

@tabatkins can you take a look, since you have been responding in the issue?

@astearns astearns requested a review from tabatkins November 10, 2020 13:40
@noamr
Copy link
Collaborator Author

noamr commented Nov 10, 2020

Thanks for writing up the proposal! It might be better to put this into css-shapes-2, as everything in css-shapes-1 is a bit further along (with an implementation and tests), and we should likely get that finished in the process and push new work to the next level.

Of course, will move to css-shapes-2.

@noamr
Copy link
Collaborator Author

noamr commented Nov 10, 2020

@tabatkins this is an initial go at this, I'm sure it will require further examples and so, but wanted to align on the syntax.

@noamr noamr changed the title [css-shapes-1] WIP: Add a draw() shape syntax, which accepts shape-segments equivalent to [css-shapes-2] WIP: Add a draw() shape syntax, which accepts shape-segments equivalent to Nov 11, 2020
@tabatkins
Copy link
Member

Looks nice! I like the by/to distinction, seems like a reasonable way to handle the rel/abs distinction.

The only thing I don't like is the horizontal/vertical keywords, because they're so long; it's shorter to just type line 0 X instead of vertical X. I think we can get away with just shortening those to h and v.

@noamr
Copy link
Collaborator Author

noamr commented Nov 13, 2020

Looks nice! I like the by/to distinction, seems like a reasonable way to handle the rel/abs distinction.

The only thing I don't like is the horizontal/vertical keywords, because they're so long; it's shorter to just type line 0 X instead of vertical X. I think we can get away with just shortening those to h and v.

The thing is that with absolute coordinates, line to X 0 is not the same as horizontal to X.
I was thinking as an alternative to use the auto keyword (line to X auto and line to auto Y). WDYT?

Something about the one-character EBNF feels less readable to me, but maybe just for h/v it's OK.

@tabatkins
Copy link
Member

Yeah, the one-character bit bothered me too, since the other commands aren't doing it (and dont' need to).

What about hline and vline, then?

@noamr
Copy link
Collaborator Author

noamr commented Nov 13, 2020

Yeah, the one-character bit bothered me too, since the other commands aren't doing it (and dont' need to).

What about hline and vline, then?

LGTM!

@Crissov
Copy link
Contributor

Crissov commented Nov 14, 2020

I recently amended my last comment in #5674 to mention alternative keywords: horizontal level and vertical plummet.

l L h H v V
line by <length> <length> line to <length> <length> horizontal by <length> horizontal to <length> vertical by <length> vertical to <length>
line by <length> <length> line to <length> <length> level by <length> level to <length> plummet by <length> plummet to <length>
line by <length> <length> line to <length> <length> line by <length> 0 line to <length> auto line by 0 <length> line to auto <length>
line by <length> <length> line to <length> <length> [left|right] by <length> [left|right] to <length> [top|bottom] by <length> [top|bottom] to <length>
line by <length> <length> line to <length> <length> [left|right] by <length> [left|right] to <length> [up|down] by <length> [up|down] to <length>

@noamr
Copy link
Collaborator Author

noamr commented Nov 14, 2020

I recently amended my last comment in #5674 to mention alternative keywords: horizontal level and vertical plummet.

Oh, I missed that! Not sure I like level and plummet. But up/down/left/right sounds appealing.

@noamr
Copy link
Collaborator Author

noamr commented Nov 14, 2020

A couple of things I could use feedback about:

  • WDYT of my suggestion to use draw() as the function keyword? It corresponds with SVG's d and is more specific than shape() and differentiates from path().
  • Not sure about including an arc syntax at all. It's been a long outstanding issue in SVG to try to find a better syntax for it, I feel that maybe we're making that clunky syntax last longer than it should. Perhaps bezier curves are sufficient for the first version (bezier curves and arcs are interchangeable);
  • Thinking that we can do a better job with animations than how path() is animated: enable animating between lines/curves/arcs by converting all of them to bezier curves.

@noamr
Copy link
Collaborator Author

noamr commented Nov 14, 2020

I recently amended my last comment in #5674 to mention alternative keywords: horizontal level and vertical plummet.

Oh, I missed that! Not sure I like level and plummet. But up/down/left/right sounds appealing.

How about the algebra terms rise and run? I think they would be the most accurate but hline and vline still seem like the most understandable terms.

Or even x and y :)

@noamr
Copy link
Collaborator Author

noamr commented Nov 14, 2020

New revision uses hline / vline. I think they're the most straightforward.

As for arc, since arcs are complex-ish and there's lots of tutorials out there around the existing SVG syntax, I kept it consistent for now.

@ByteEater-pl
Copy link

Additional advantages of down and left are that they obviate the need to multiply by -1.

@noamr
Copy link
Collaborator Author

noamr commented Nov 16, 2020

Additional advantages of down and left are that they obviate the need to multiply by -1.

But they would be confusing in absolute coordinates... e.g. left to 100% would actually be going right.

@noamr
Copy link
Collaborator Author

noamr commented Nov 17, 2020

New PR based on @smfr's comments and others:

  • Using shape rather than draw
  • Allowing logical properties by defining a potentially-logical origin corner rather than an arbitrary starting point.

@noamr
Copy link
Collaborator Author

noamr commented Nov 29, 2020

@tabatkins I think it's ready for a review round.

Copy link
Member

@tabatkins tabatkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Lots of small editorial nits, but it's not worth going over in this review; I need to do an editorial pass over this entire spec.

@tabatkins
Copy link
Member

Wait, spoke too soon, didn't notice the "corner" design. We should discuss that separately and make sure we're happy with the design there; I suggest dropping it from the initial proposal and just defaulting to the "standard" physical coordinate system that paths already use.

@tabatkins
Copy link
Member

Anyway, Agenda+ to discuss this addition to the spec.

@noamr
Copy link
Collaborator Author

noamr commented Dec 2, 2020

Wait, spoke too soon, didn't notice the "corner" design. We should discuss that separately and make sure we're happy with the design there; I suggest dropping it from the initial proposal and just defaulting to the "standard" physical coordinate system that paths already use.

OK, I'll switch to physical - and will propose a separate discussion about logical coordinates in shapes.
Thanks!

@faceless2
Copy link

Won't make the call to discuss, but this LGTM too. I think a straight drop-in replacement for the existing SVG syntax is a good idea. For that reason I also agree with keeping logical coordinates well away is a good idea, at least or now. I'm also not sure about "corner" - given you can replace corner top right with move to 100% 0, I don't think it adds anything. Maybe it was more useful when logical coordinates were an option; I'd consider dropping it until they're readded.

Otherwise, great! It's definitely better than string concatenation :-)

(oh, a quick addendum re. one of your earlier comments - arcs are not directly replaceable with beziers, as they are treated differently when used with SVG markers: a 270° arc with end markers has just the two, but drawing the same curve with beziers would result in more. So the concept needs to remain in the grammar. Yes the syntax is awkward, but it's well established, and using small|large and cw|ccw will certainly help)

@noamr
Copy link
Collaborator Author

noamr commented Dec 2, 2020

Won't make the call to discuss, but this LGTM too. I think a straight drop-in replacement for the existing SVG syntax is a good idea. For that reason I also agree with keeping logical coordinates well away is a good idea, at least or now. I'm also not sure about "corner" - given you can replace corner top right with move to 100% 0, I don't think it adds anything. Maybe it was more useful when logical coordinates were an option; I'd consider dropping it until they're readded.

Yes, the corner thing makes sense only in the context of logical coordinates. Will wait with that.
As a Hebrew speaker I'd love to help out figure how shapes could become logical-property friendly (but no in this PR).

(oh, a quick addendum re. one of your earlier comments - arcs are not directly replaceable with beziers, as they are treated differently when used with SVG markers: a 270° arc with end markers has just the two, but drawing the same curve with beziers would result in more. So the concept needs to remain in the grammar. Yes the syntax is awkward, but it's well established, and using small|large and cw|ccw will certainly help)

Good point, I didn't knot at! Though SVG markers don't play a role in CSS shapes. Do they? In which case, arcs and curves are interchangeable.

@faceless2
Copy link

Good point, I didn't knot at! Though SVG markers don't play a role in CSS shapes. Do they? In which case, arcs and curves are interchangeable.

True, currently. But (from w3c/svgwg#119 and w3c/svgwg#320) the "d" property uses the path() function (see also PR w3c/svgwg#374). Although it doesn't yet reference css-shapes, it seems to me that where path() applies, shape() would always apply too. And this looks pretty good to me:

<svg>
 <style>
   path {
     d: shape(move to 0 0 arc to 100% 100% cw small 90deg);
     marker-start: url(#marker);
     marker-end: url(#marker);
   }
 </style>
 <marker id="marker" markerWidth="10" markerHeight="10" refX="5" refY="5">
  <circle cx="5" cy="5" r="5"/>
 </marker>
 <path></path>
</svg>

Actually, that's another point - ideally the grammar for "arc" would allow the radius, arc-sweep arc-large and angle to be reordered, as this can be done without ambiguity. I think that means it should look like arc <by-to> <coordinate-pair> [<radius> || <arc-sweep> || <arc-large> || <angle>], but don't quote me on that. No doubt these are some of the editorial nits Tab will be picking.

@noamr
Copy link
Collaborator Author

noamr commented Dec 2, 2020

Good point, I didn't knot at! Though SVG markers don't play a role in CSS shapes. Do they? In which case, arcs and curves are interchangeable.

True, currently. But (from w3c/svgwg#119 and w3c/svgwg#320) the "d" property uses the path() function (see also PR w3c/svgwg#374). Although it doesn't yet reference css-shapes, it seems to me that where path() applies, shape() would always apply too. And this looks pretty good to me:

<svg>
 <style>
   path {
     d: shape(move to 0 0 arc to 100% 100% cw small 90deg);
     marker-start: url(#marker);
     marker-end: url(#marker);
   }
 </style>
 <marker id="marker" markerWidth="10" markerHeight="10" refX="5" refY="5">
  <circle cx="5" cy="5" r="5"/>
 </marker>
 <path></path>
</svg>

Actually, that's another point - ideally the grammar for "arc" would allow the radius, arc-sweep arc-large and angle to be reordered, as this can be done without ambiguity. I think that means it should look like arc <by-to> <coordinate-pair> [<radius> || <arc-sweep> || <arc-large> || <angle>], but don't quote me on that. No doubt these are some of the editorial nits Tab will be picking.

Good point, I didn't knot at! Though SVG markers don't play a role in CSS shapes. Do they? In which case, arcs and curves are interchangeable.

True, currently. But (from w3c/svgwg#119 and w3c/svgwg#320) the "d" property uses the path() function (see also PR w3c/svgwg#374). Although it doesn't yet reference css-shapes, it seems to me that where path() applies, shape() would always apply too. And this looks pretty good to me:

<svg>
 <style>
   path {
     d: shape(move to 0 0 arc to 100% 100% cw small 90deg);
     marker-start: url(#marker);
     marker-end: url(#marker);
   }
 </style>
 <marker id="marker" markerWidth="10" markerHeight="10" refX="5" refY="5">
  <circle cx="5" cy="5" r="5"/>
 </marker>
 <path></path>
</svg>

Actually, that's another point - ideally the grammar for "arc" would allow the radius, arc-sweep arc-large and angle to be reordered, as this can be done without ambiguity. I think that means it should look like arc <by-to> <coordinate-pair> [<radius> || <arc-sweep> || <arc-large> || <angle>], but don't quote me on that. No doubt these are some of the editorial nits Tab will be picking.

Yes I think making arc parameters order-agnostic would be better. Let me revise.

@noamr noamr changed the title [css-shapes-2] WIP: Add a draw() shape syntax, which accepts shape-segments equivalent to [css-shapes-2] Add a shape() syntax, which accepts shape-segments equivalent to SVG path Dec 2, 2020
@noamr
Copy link
Collaborator Author

noamr commented Dec 3, 2020

Anyway, Agenda+ to discuss this addition to the spec.

Should I wait till it's discussed in the agenda or merge it in?

@astearns
Copy link
Member

astearns commented Dec 3, 2020

Anyway, Agenda+ to discuss this addition to the spec.

Should I wait till it's discussed in the agenda or merge it in?

Let’s wait for the discussion. There’s also the IPR commitment that needs to be made in some form or other. Are you talking to @svgeesus about that?

@svgeesus
Copy link
Contributor

svgeesus commented Dec 3, 2020

There’s also the IPR commitment that needs to be made in some form or other. Are you talking to @svgeesus about that?

I asked for the IPR commitment, and it has been made. I don't understand why the flag hasn't cleared. Ah! I had to press the "revalidate" button. All good now.

css-shapes-2/Overview.bs Outdated Show resolved Hide resolved
css-shapes-2/Overview.bs Outdated Show resolved Hide resolved
@fantasai
Copy link
Collaborator

fantasai commented Dec 9, 2020

Overall looks great!!!

You need to also add yourself to the acknowledgements, though. =)

@noamr
Copy link
Collaborator Author

noamr commented Dec 9, 2020

Overall looks great!!!

Thanks!

You need to also add yourself to the acknowledgements, though. =)

How do I do that?

@fantasai
Copy link
Collaborator

fantasai commented Dec 9, 2020

Good point. Seems there isn't one yet. Need to add one, and add you to it. :) I suppose we can make that a separate issue.

Copy link
Contributor

@grorg grorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo Corresponds.

@tabatkins tabatkins merged commit e8404d1 into w3c:master Jan 7, 2021
If it is not set, the automatic value is used.
<dt>close
<dd>
Corrsepponds to a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand">closepath</a> command.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. Corresponds.

<dt><dfn><<hv-line-command>></dfn> = [hline | vline] <<by-to>> <<length-percentage>>
<dd>
Corresponds to a horizontal or vertical <a href="https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands">lineto</a> command.
<dt><dfn><<curve-command>></dfn> = curve <<by-to>> <<coordinate-pair>> via <<coordinate-pair>>{1,2}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer using over via. The curve does not go via the control points.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I wonder if the end point should come after the control points.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lastly (hopefully), additional spec text should point out that an animation of the shape would work the same as SVG, but that curve is a bit different since the type of curve is defined by the number of parameters (rather than an identifier like SVG).

@grorg
Copy link
Contributor

grorg commented Jan 7, 2021

Ha. @tabatkins merged before I pressed the "Submit Review" button.

@tabatkins
Copy link
Member

No worries, I'm gonna do a comprehensive edit pass over the spec anyway, so I'll make sure your comments are addressed.

@noamr noamr deleted the draw-shape branch January 7, 2021 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[css-shapes] Allow CSS grammar for path shapes
9 participants