closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

setTransform(matrix) missing for CanvasRenderingContext2D and CanvasPattern

Open zbynek opened this issue 5 years ago • 4 comments

  • for CanvasRenderingContext2D the matrix variant is missing https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform
  • for CanvasPattern the method is missing https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform

Source: https://github.com/google/closure-compiler/blob/master/externs/browser/html5.js

upstream of https://github.com/google/elemental2/issues/145

zbynek avatar Sep 10 '20 13:09 zbynek

CanvasRenderingContext2D extends BaseRenderingContext2D

https://github.com/google/closure-compiler/blob/5f0ce35c6ccf72ffcda8bf28b8ab155b7de04b59/externs/browser/html5.js#L838-L843

From which it inherits setTransform

https://github.com/google/closure-compiler/blob/5f0ce35c6ccf72ffcda8bf28b8ab155b7de04b59/externs/browser/html5.js#L443-L444

However, we don't seem to have any prototype properties defined for CanvasPattern at all. https://github.com/google/closure-compiler/blob/5f0ce35c6ccf72ffcda8bf28b8ab155b7de04b59/externs/browser/html5.js#L873

@zbynek would you be interested in creating a pull request to add one?

brad4d avatar Sep 11 '20 23:09 brad4d

@brad4d thanks for the reply! The problem with BaseRenderingContext2D.prototype.setTransform is that it expects 6 number parameters, even though the standard also allows just one parameter of the DOMMatrixInit type.

I'm not sure what's the best way to describe both the old and the new syntax in the extern: maybe the first argument needs to be number|DOMMatrixInit and all the others marked as optional, but that seems to be sub-optimal for tools that process the externs. @jDramaix would that generate 12 different syntaxes for Elemental2 (two for each number of arguments)?

If the 5 optional arguments are the best we can do, I can create a PR for that.

zbynek avatar Sep 12 '20 14:09 zbynek

Looks like we need to also update the documentation links in html5.js

It currently points at https://www.w3.org/TR/2dcontext/#canvasrenderingcontext2d

But the current standard (found via MDN) seems to be at https://html.spec.whatwg.org/multipage/canvas.html

brad4d avatar Sep 12 '20 15:09 brad4d

Yes, I think 5 optional parameters is really the only way to declare the new single-argument version of setTransform in the externs.

brad4d avatar Sep 12 '20 15:09 brad4d