Giter VIP home page Giter VIP logo

Comments (5)

WebReflection avatar WebReflection commented on June 23, 2024

your svg_test is broken ... it doesn't close the initial object.

would this work instead?

const svg_test=(id,path)=> html`
        <object
            type="image/svg+xml"
            .data=${path}
            onload=${dispatch(id)}
        />

from uhtml.

thipages avatar thipages commented on June 23, 2024

Sorry, bad copy/paste.
same behaviour with the code you propose.
I write a code pen

from uhtml.

thipages avatar thipages commented on June 23, 2024

here it is : https://codepen.io/thipages/pen/XWXKgBw

from uhtml.

WebReflection avatar WebReflection commented on June 23, 2024

OK, this is an expected behavior, see the following code that uses zero libraries:

document.body.innerHTML = `<object height="100px" type="image/svg+xml"></object>`;
const object = document.body.firstElementChild;
const m= {
  id: '_svg_',
  path: 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ruby.svg'
};
const update = () => {
  object.onload = () => {
    document.dispatchEvent(new CustomEvent(m.id, {detail: null}));
  };
  object.data = m.path;
};
document.addEventListener(m.id, () => {
  setTimeout(()=> {
    console.log("loaded");
    // do some work here like changing the svgs height/scale
    update();
  },1000);
});
update();

setting the .data over and over makes it flick, but admittedly there was no way to pass data as attribute, but nodes that have a special data meaning should have the ability to use that indeed.

So, latest version of uhtml allows you to use data=${...} instead of .data=${...} for nodes where data has a special meaning, so that the dataset helper is not triggered.

TL;DR this now works:

const svg_test=(id,path)=> html`
  <object
    type="image/svg+xml"
    data=${path}
    onload=${dispatch(id)}
  />
`;

from uhtml.

thipages avatar thipages commented on June 23, 2024

great! Thank you

from uhtml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.