swiftwasm / WebAPIKit

Access the DOM and other Web APIs from Swift! (Very much a WIP)
MIT License
61 stars 8 forks source link

Add `(Offscreen)RenderingContext` protocols #45

Closed MaxDesiatov closed 2 years ago

MaxDesiatov commented 2 years ago

Previously, RenderingContext and OffscreenRenderingContext were enums, which required the (only) module containing these enum declarations to know all possible context types upfront. When these types are declared as protocols, separate modules can add new types and add conformances to this protocol on case-by-case basis.

In a future PR this allows us to split Canvas, WebGL1, WebGL2, and WebGPU APIs into separate modules.

I've also made getContext calls type safe, where users now pass the type of desired context instead of their IDs.