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

[cssom-view] Element (or Node) should contain the properties offset... (offsetParent, offsetLeft, ...) #10514

Open
jogibear9988 opened this issue Jul 1, 2024 · 12 comments

Comments

@jogibear9988
Copy link

jogibear9988 commented Jul 1, 2024

Problem

I'm writing a Designer Application, where I show overlays for all Elements (like the Dev Tools). For this to work, I need to calculate the the corners of the rect of an Element. This works using getBoundingClientRect, but only if the Element is not transformed. If the Element for example is rotated, this will not return the points of the element, but the outer rect. And also a element could be inside of another transformed element (and so on).
I know calculate the combined transformation of the element, but for this I need the position of the element inside of it's container. This works on HTMLElements (cause they have offsetLeft and offsetTop), but not on SVG or MathML Elements.

As also MathML and SVG Elements could be aligned inside of HTMLElements, they should also contain these Properties. And also, as they also could be positioned absolutely, they should contain the "offsetParent", to get to wich they are positioned to.

Additional, as also a TextNode could be positioned inside of a container, I think it should also get the "offset..." Properties. So maybe it should be added to the "Node" Interface instead of the "Element" interface.

The spec is here:
https://www.w3.org/TR/cssom-view-1/#extensions-to-the-htmlelement-interface
I think it should be changed to "Element" instead of "HTMLElement"

@jogibear9988
Copy link
Author

@emilio
Copy link
Collaborator

emilio commented Jul 1, 2024

Does GeometryUtils.getBoxQuads give you what you want? Seems like it would do exactly what you want?

@jogibear9988
Copy link
Author

maybe, I do not find any browser wich implements this API: getBoxQuads

@jogibear9988
Copy link
Author

seems only firefox has an implementation behind a flag: https://caniuse.com/mdn-api_document_getboxquads

@jogibear9988
Copy link
Author

Polyfills for Geometry API:

https://github.com/trusktr/geometry-interfaces
https://github.com/maxmaximov/getBoxQuads

They do not work with transformed elements. (Cause that is the hard part) (My Designer Code could work with transformed HTMLElements (https://github.com/node-projects/web-component-designer/blob/92baadd12ebc6821e2bbaac6b4728a6baa49ef0b/packages/web-component-designer/src/elements/helper/TransformHelper.ts#L148C21-L148C49)
Problem is, I need the offset in the container wich I do not get for SVG and MathML (and textNodes)

@chrishtr
Copy link
Contributor

chrishtr commented Jul 1, 2024

I'm writing a Designer Application, where I show overlays for all Elements (like the Dev Tools).

"DevTools overlay" does seem like a use case for GeometryUtils.getBoxQuads that can't be done in other ways, because of transforms...otherwise anchor positioning would work it seems.

Right now the specification for GeometryUtils is inadequate, that'd have to be finished before shipping in a browser. @tabatkins you also mentioned previously you had use cases, were they the same has the one reported here?

@jogibear9988
Copy link
Author

@chrishtr Should I create an extra issue, that "getBoxQuads" should be implemented? (I didn't know of that API when I wrote this issue :-) )

These here is about "offset...." - Properties on non HTMLElements, wich is needed if you want to polyfill "getBoxQuads". (Wich I still think should exist on all Elements)

@jogibear9988
Copy link
Author

I've created a polyfill for the getBoxQuads API based on my designer https://github.com/jogibear9988/getBoxQuadsPolyfill
But cause of the missing elments... Properties, it lacks SVG support

@chrishtr
Copy link
Contributor

chrishtr commented Jul 2, 2024

@chrishtr Should I create an extra issue, that "getBoxQuads" should be implemented? (I didn't know of that API when I wrote this issue :-) )

No need to do that.

@SebastianZ SebastianZ changed the title [cssom] Element (or Node) should contain the properties offset... (offsetParent, offsetLeft, ...) Jul 3, 2024
@SebastianZ
Copy link
Contributor

For reference, here's the link to GeometryUtils.getBoxQuads in the spec.:
https://drafts.csswg.org/cssom-view/#dom-geometryutils-getboxquads

Sebastian

@jogibear9988
Copy link
Author

jogibear9988 commented Jul 3, 2024

And FF issues about the implementation and the remove of the flag: (of the getBoxQuads)

https://bugzilla.mozilla.org/show_bug.cgi?id=918189
https://bugzilla.mozilla.org/show_bug.cgi?id=1107559

@jogibear9988
Copy link
Author

The spec is here:
https://www.w3.org/TR/cssom-view-1/#extensions-to-the-htmlelement-interface
I think it should be changed to "Element" instead of "HTMLElement"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants