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-paint-api] Any way to pass JS Object/Var to the paint class or Set property as return value? #881

Closed
samad-aghaei opened this issue May 2, 2019 · 4 comments

Comments

@samad-aghaei
Copy link

samad-aghaei commented May 2, 2019

Consider the following code:

paint(ctx, geom, styleMap) {
    const circle = new Path2D();
    circle.arc(150, 75, 50, 0, 2 * Math.PI);
    ctx.fillStyle = 'red';
     if(ctx.isPointInPath(circle, 105, 75)){

         /* Is there any way to let the global scope know that this is "TRUE"? */

     }
}

It seems that there is no relation between paint class inside of registerPaint and the globalScope, and also styleMap is readOnly.
How could we get the returned values?

@samad-aghaei samad-aghaei changed the title [css-paint-api] Any way to pass JS Object/Var or Set property as return value? [css-paint-api] Any way to pass JS Object/Var to the paint class or Set property as return value? May 2, 2019
@AmeliaBR
Copy link

AmeliaBR commented May 2, 2019

Can you explain what your use-case is?

In general, the idea of the Paint API is that it creates a static image efficiently, and independently of any other code on the webpage. If you need to get information back out of your drawing code, it might be better to do the drawing with a regular canvas.

@samad-aghaei
Copy link
Author

The use case could be creating components like listbox/combobox that can display options in pseudo (before, after) elements.
This would reduce so many of HTML elements with a nice visual effect in a performant way.
The code independency of the worklet is a great idea, but if we could’ve access to the dom, or receive a signal from worklet anyway, we can create components even better than customComponents which force browser to reflow and add unnecessary elements to document tree.

@samad-aghaei samad-aghaei changed the title [css-paint-api] Any way to pass JS Object/Var to the paint class or Set property as return value? [css-paint-api] Any way to pass JS Object/Var to the paint class or Set property as return value? May 7, 2019
@tabatkins
Copy link
Member

Unfortunately, using Paint API to replace the rendering of HTML elements (particularly text and interactive elements) is explicitly a non-goal for Paint API in its current form; doing it properly would require significant additional work in text rendering, layout, and accessibility to make the display remotely usable for users of the website.

We do have plans for allowing more custom control over the painting phases of an element, but that's a future spec, and there is currently no timeline for working on that.

@samad-aghaei
Copy link
Author

@tabatkins I think you went too far. I didn't want the Paint API to be a replacement for HTMLElement, at least at this point.
Regardless of Font/Text API, just I wanted to have a "two-way" communication with registered paint class and I think having such a feature is very normal.
Currently, there is almost no way to get [any kind of] data back from worklet. Event though the Atomics API are exposed, but there is no way to send sharedArrayBuffer to the worklet.
Dynamic modules in worklets are not dynamic even, they are static in fact, only accepting String as input argument and must be defined at the top root of the worklets and not working in eval().
I know you may are concern about cyclic events, but don't you think that preventing it is up to the developers? cyclic event can always happen anywhere but we have to be careful, as we did it for years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants