scala-js / scala-js-dom

Statically typed DOM API for Scala.js
Other
315 stars 162 forks source link

Added missing constructors to ImageData facade. #829

Closed dragonfly-ai closed 6 months ago

dragonfly-ai commented 8 months ago

The ImageData spec references several constructors that scala-js-dom has omitted:

https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData

This PR means to include these features.

dragonfly-ai commented 8 months ago

Should we introduce an ImageSettings class?

The JS docs just supply them with anonymous arguments:


let imageData = new ImageData(200, 100, { colorSpace: "display-p3" });
armanbilge commented 8 months ago

Should we introduce an ImageSettings class?

Yes. Here's an example of how it should be defined.

https://github.com/scala-js/scala-js-dom/blob/efe1b87772b114c95a3d30fcdddc603f0ebb0b23/dom/src/main/scala/org/scalajs/dom/DOMRectInit.scala

dragonfly-ai commented 8 months ago

OK, I'll try to add that, too.

dragonfly-ai commented 8 months ago

What about adding a companion object to ImageSettings since its only field supports exactly two values: "srgb" and "display-p3"?

I mean to store static values for the two types of ImageSettings instances needed to encode the two supported color models.

zetashift commented 7 months ago

What about adding a companion object to ImageSettings since its only field supports exactly two values: "srgb" and "display-p3"?

Wouldn't these be better off as an enum then? E.g. ImageSettingsColorSpace? @dragonfly-ai This PR LGTM, if you want to add the enum or not, let me know, it can always be a separate ticket/PR

dragonfly-ai commented 7 months ago

Thanks for approving! I've never tried passing a Scala enum to a native JS function; do Scala enumerations interoperate well with plain JavaScript?

sjrd commented 7 months ago

No, they don't.

dragonfly-ai commented 7 months ago

Well, in that case, companion object with constants for display-p3 and srgb, or should we just leave it out?

dragonfly-ai commented 6 months ago

Added the ImageSettings object as discussed.