Загрузка видео...

Не удалось загрузить видео

На главную

I've been playing around with Chrome's experimental HTML-in-Canvas API (I use it to create my videos), and I wanted to see if I could make text-selection work on a curved surface by moving the underlying element around on pointermove. It works pretty well!

118,152 просмотров • 7 месяцев назад •via X (Twitter)

Комментарии: 54

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Live demo: (needs Chrome Canary with the canvas-draw-element flag. Source:

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Of course, this means you can add shaders (again, Chrome Canary with canvas-draw-element flag)

Фото профиля Nick Siscoe
Nick Siscoe7 месяцев назад

Could make for a cool CRT style window effect

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

😁

Фото профиля Nick Siscoe
Nick Siscoe7 месяцев назад

Ope lol

Фото профиля Andy Hawkes
Andy Hawkes7 месяцев назад

The obvious next move is to put another canvas element within that HTML?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

You joke, but I already do this. In the videos I make, the frames of the video of me are pulled out using the VideoDecoder API and written to an inner canvas.

Фото профиля Una 🇺🇦
Una 🇺🇦7 месяцев назад

Nice, I've been playing around with this a little too in my spare time. I've noticed/reported an unfortunate quality difference between content within a canvas vs. a DOM overlay. Have you run into that as well?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Ohhh is it a resolution issue? I haven't experienced that in 2d canvas when creating my dev video things, but I've been running an old Chromium build since a bunch of stuff has broken since then and I haven't had time to investigate it.

Фото профиля Una 🇺🇦
Una 🇺🇦7 месяцев назад

I don't think so -- it's something I've noticed in most HTML in canvas demos, like a slight 1px blur but I can't unsee it.

Фото профиля Marko
Marko7 месяцев назад

That's awesome. I didn't even know HTML in canvas is a thing. woa

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Well, it isn't yet. This is an API in progress, in Canary, behind a flag.

Фото профиля Marko
Marko7 месяцев назад

Ok, then I'm one of the first, that's great, thanks.

Фото профиля EmaDev
EmaDev7 месяцев назад

What is html-in-canvas API??? 😵 I need it!

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

it's experimental, and the prototype is only in Chrome Canary behind a flag

Фото профиля EmaDev
EmaDev7 месяцев назад

Really happy for that! Il will unlock a lot of things 💣

Фото профиля Taylor Plewe
Taylor Plewe7 месяцев назад

Was literally just looking into how one would go about making a pixelated website. This is the exact API I was looking for

Фото профиля Jamie Birch
Jamie Birch7 месяцев назад

Is there anything like a measureText() API with it that would make the new pretext library redundant on Chrome?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

It's been in all browser engines over a decade That pretext library uses it.

Фото профиля Jamie Birch
Jamie Birch7 месяцев назад

I’m asking about something else – measureText() only handles ctx.font, and not line wrapping, etc., right? So does HTML-in-canvas offer anything more powerful on that front? Or do you still have to wait for the next animation frame, meaning it’s no better than HTML ex-canvas?

Фото профиля Jamie Birch
Jamie Birch7 месяцев назад

I mean, does HTML-in-canvas give any way to synchronously get the metrics of wrapping text, without having to wait for the next animation frame?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

You can already do this in HTML. You don't need to wait until the next frame to call getBoundingClientRect etc etc. It will give you current data. You should avoid interleaving layout reads & writes of course, because that's a slow path. You can always use an iframe.

Фото профиля Jamie Birch
Jamie Birch7 месяцев назад

Yeah, but getBoundingClientRect() forces a layout flush, doesn’t it? Or is that what you are referring to with the slow path? Iframe, huh… 🤔 I wonder if any prior art has explored that.

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Right, getBoundingClientRect will force a layout _if_ layout is stale. Otherwise it won't. But, measureText is performing layout work too, that's how it works. The key is to avoid interleaving layout reads & writes, or isolate their impact.

Фото профиля El Valiente
El Valiente7 месяцев назад

I am personally very excited about this. Like Christmas excited.

Фото профиля Paul Calcraft
Paul Calcraft7 месяцев назад

@itseieio you might like this!

Фото профиля 月球背面 🌑 Moonvy
月球背面 🌑 Moonvy7 месяцев назад

Finally can take screenshots in the browser

Фото профиля Tim Miller
Tim Miller7 месяцев назад

Woah! What an incredible tool this could be 😱

Фото профиля nofunsir
nofunsir7 месяцев назад

html-in-canvas smells an awful lot like another sneaky way to force ads on the user agent.

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

How?

Фото профиля nofunsir
nofunsir7 месяцев назад

Canvas-based rendering moves the web toward a "black box" model where the publisher has control over what is displayed and tracked, and the user agent has very little. Blocking moves from element- to pixel-based. See also: canvas fingerprinting.

Фото профиля Ebiko
Ebiko7 месяцев назад

does that mean I can wrap my whole website into an canvas using canvas html and then create a video stream based on that canvas using the canvas as a context? Thats interesting. That means I can literally build a remote controllable and viewable website using Jitsi :D

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

You can definitely record the canvas content to video. That's how I make these:

Фото профиля Andrew Wiseman
Andrew Wiseman7 месяцев назад

Haven't peeked behind the scenes at this, but the html page transformations reminded me of the new renderings available on xkcd...

Фото профиля Bora Turan
Bora Turan7 месяцев назад

cool, but need also webkit support to spend time on it

Фото профиля familiar horse cop
familiar horse cop7 месяцев назад

this will always be peak:

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Put it on a sphere, then I'm interested

Фото профиля Marko
Marko7 месяцев назад

Sorry again, but I didn't get how this feature helps with your video creation? Are you using css to do animation (above) and somehow coordinate timing wtih rendering of video, video drives animation?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Yep, it means I can use web tech to do things like syntax highlighting, and web animations for animations. It also means my demos of things like CSS shape() can be 'live' demos. I'm sure someone can do all this in a video editor, but the web is what I know best.

Фото профиля Marko
Marko7 месяцев назад

Nice stuff Thanks! I'll take a look at this. Ironically you made me install Chrome Canary lol

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Haha I won't show my boss this

Фото профиля Gustav ❖
Gustav ❖7 месяцев назад

Yooo

Фото профиля Faisal-Aldosari
Faisal-Aldosari7 месяцев назад

So other than just being able to do this, what purpose does it have?

Фото профиля Koolala
Koolala7 месяцев назад

It's warping the DOM inputs to match?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Nah, I just apply a simple x/y translate on the element so the bit under the pointer is correct

Фото профиля Tom Bielecki
Tom Bielecki7 месяцев назад

@TheRealKoolala Does that mean you could have an iOS Glass style of button ("element") where the text and pointer deform with diffraction effects?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

@TheRealKoolala Yep!

Фото профиля Anubhav Gupta
Anubhav Gupta7 месяцев назад

Does this mean that i can render half of my html normally and one or more portions of my html using canvas(perf intensive)?? This is awesome. Do you see any perf gains when rendering in canvas vs html ?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Rendering HTML in a canvas will be slower than rendering it normally, as the browser can't make particular optimisations

Фото профиля Anubhav Gupta
Anubhav Gupta7 месяцев назад

Wow, this is totally opposit from what i was assuming, can you also share an example of an optimization?

Фото профиля Jake Archibald
Jake Archibald7 месяцев назад

Not rendering things out of view, rendering only changed parts, optimising texture size

Фото профиля Anubhav Gupta
Anubhav Gupta7 месяцев назад

Thanks for this information.

Фото профиля Surya Dantuluri
Surya Dantuluri7 месяцев назад

super cool

Фото профиля Soham
Soham7 месяцев назад

Canvas being canvas

Похожие видео