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

Write <map-a> as a custom element #402

Closed
prushforth opened this issue Apr 15, 2021 · 11 comments
Closed

Write <map-a> as a custom element #402

prushforth opened this issue Apr 15, 2021 · 11 comments

Comments

@prushforth
Copy link
Member

  • so that it can contain its behaviour
  • be styled
@ahmadayubi
Copy link
Member

I found this: WICG/webcomponents#634

It seems as though it's not possible to wrap <path> with custom elements. You could use <a is="web-a"> but as @prushforth mentioned that wouldn't work on Safari.

@Malvoz
Copy link
Member

Malvoz commented Apr 19, 2021

It seems as though it's not possible to wrap <path> with custom elements.

I think it should be possible to work around that using <foreignObject>.

@Malvoz
Copy link
Member

Malvoz commented Apr 19, 2021

For example, the following should theoretically work:

<svg xmlns="http://www.w3.org/2000/svg">
  ...
  <foreignObject width="" height="">
    <div xmlns="http://www.w3.org/1999/xhtml">
      <map-a> <!-- or if it's fine to "pollute" this element, remove `<div>` and set the namespace attribute here. -->
        <svg xmlns="http://www.w3.org/2000/svg">
          <g>
            <path d=""/>
          </g>
        </svg>
      </map-a>
    </div>
  </foreignObject>

But perhaps that's not flexible enough?

@ahmadayubi
Copy link
Member

@Malvoz Does that allow nesting? For example:

<svg xmlns="http://www.w3.org/2000/svg">
  ...
  <foreignObject width="" height="">
    <div xmlns="http://www.w3.org/1999/xhtml">
      <map-a> <!-- or if it's fine to "pollute" this element, remove `<div>` and set the namespace attribute here. -->
        <svg xmlns="http://www.w3.org/2000/svg">
          <g>
            <map-a>
             <path d=""/>
            </map-a>
          </g>
        </svg>
      </map-a>
    </div>
  </foreignObject>

Or would you have to create another <foreignObject> within the nested <svg>?

@prushforth
Copy link
Member Author

<svg xmlns="http://www.w3.org/2000/svg">
  ...
  <foreignObject width="" height="">
      <map-a  xmlns="http://www.w3.org/1999/xhtml"> 
          <g xmlns="http://www.w3.org/2000/svg">
             <path d=""/>
          </g>
      </map-a>
  </foreignObject>

would be more like what we would need, since we're inside a leaflet map pane with css transforms happening, and I doubt the browser would be coded to look inside a foreignObject for more svg content.

@Malvoz
Copy link
Member

Malvoz commented Apr 20, 2021

@ahmadayubi re #402 (comment), yes the inner <map-a> would have to be wrapped in a new <foreignObject> or else it'd be treated as SVG (I believe dasherized elements are treated as unknown elements in SVG, which in turn is treated as <g> for the purpose of rendering).

@ahmadayubi
Copy link
Member

It's a lot of nesting in that, each <path> would also have to wrapped in it's own <svg>, it's doable but seems like a lot of DOM clutter. @prushforth thoughts?

@prushforth
Copy link
Member Author

The objective of the map-a would be

a) to provide encapsulation/modularity of code and
b) a CSS selector target that could be styled.

The major constraint would be (I believe) that the graphics inside the map-a would have to be accessible to the css transforms that leaflet applies to the ancestor map overlay pane div, without needing special replication or complexity, such as opening a new svg element. It would not be a big deal if foreignObject s could be nested, I think, as long as we keep the namespaces straight.

Nothing would beat interactive testing in devtools to see if it would work!

@Malvoz
Copy link
Member

Malvoz commented Apr 20, 2021

Is it possible to use regular (SVG) <a>? If nesting can be avoided in the output HTML/SVG? Are there other limitations? Using <a> would resolve #392. But I guess that's been considered already.

@ahmadayubi
Copy link
Member

You could use <a> but you'd need to prevent it's default behavior since the way they work in mapml is completely different for the most part. You'd sort of be hijacking what the <a> element does inside of the tag but if that's not an issue then it can probably be done.

@prushforth
Copy link
Member Author

I don't think using a regular element achieves everything we want especially regarding custom element modularization of code, so closing for now. We'll keep the branch as unresolved.

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

No branches or pull requests

3 participants