-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add typescript definitions #1330
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
Conversation
This would be really nice! |
It seems good, and we should also specify |
After copy-pasting it into my node project, I see that the typings depend on
I think that reexports can be changed to something like: Edit: class IMG extends HTMLImageElement {
src: any;
}
type ImageMode = number & { __imageMode: true }
export class Image extends IMG {
/** Track image data */
static readonly MODE_IMAGE: ImageMode;
/** Track MIME data */
static readonly MODE_MIME: ImageMode;
src: string | Buffer;
/**
* Applies to JPEG images drawn to PDF canvases only. Setting
* `img.dataMode = Image.MODE_MIME` or `Image.MODE_MIME|Image.MODE_IMAGE`
* enables MIME data tracking of images. When MIME data is tracked, PDF
* canvases can embed JPEGs directly into the output, rather than
* re-encoding into PNG. This can drastically reduce filesize and speed up
* rendering.
*/
dataMode: ImageMode;
} |
Oh, and when I started to use your typings, I saw the need to export class MyCanvasWrapper {
private readonly canvas: Canvas;
private readonly context: NodeCanvasRenderingContext2D;
constructor(width: number, height: number) {
this.canvas = createCanvas(width, height);
this.context = this.canvas.getContext('2d');
}
} |
I think that this can be fixed by having |
Status of this? |
Got busy working on bugfixes -- will update this this weekend. |
2b9b4d2
to
e79a74b
Compare
Ready for another review/testing. Used the instructions in https://github.com/Microsoft/dtslint#add-types-for-a-library-not-on-definitelytyped for setup. |
c8417f7
to
c1f4e4b
Compare
@zbjornson Thank you for the great work. Wondering when this will be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
e3956c8
to
238e8b5
Compare
Just tested this in a module where I'm using node-canvas. I forgot the PNG constants, https://github.com/Automattic/node-canvas/pull/1330/files#diff-88bec6beae84369c0376b56b3bb88fe1R200 this is sort of ugly but I don't see a way around it aside from providing all of our own Context2D types. That might not be a bad idea since we don't have full support yet for the entire HTML Canvas API (see https://github.com/Automattic/node-canvas/wiki/Compatibility-Status). What do folks think we should do?
|
Hmm, seems like I think I'm leaning towards option |
Hey guys, anything I can do to get the ball rolling on this again? Any more updates to the typings that need to happen? Happy to help. Cheers. |
Will this be released soon? |
I'll finish up the last set of changes this weekend, sorry for the delay. |
Wow, nice work @zbjornson! I didn't notice that when I raised a PR for DefinitelyTyped repo (DefinitelyTyped/DefinitelyTyped#33555), so I will close the PR and wait for this one to get merged. |
* _Non-standard_. Defaults to 'good'. Like `patternQuality`, but applies to | ||
* transformations affecting more than just patterns. | ||
*/ | ||
quality: 'fast' | 'good' | 'best' | 'nearest' | 'bilinear' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quality and patternQuality share typing definition.
type Quality = 'fast' | 'good' | 'best' | 'nearest' | 'bilinear';
quality: Quality
patternQuality: Quality
Would it be possible to publish this PR and iterate? It's been pending for some time now. |
d432a05
to
1787d09
Compare
grumble a dependency of dtslint added an async function, which breaks our CI that runs with node 6. Thinking of better workarounds, but if I can't think of one today I'll remove dtslint (sadly; it's been critical to testing this) and merge. |
505c6a1
to
a4f257a
Compare
There we go. @LinusU since you have to do releases anyway, I'll let you merge. I just changed .travis.yml to only run dtslint with Node v10. |
types/index.d.ts
Outdated
*/ | ||
toBuffer(mimeType: 'raw'): Buffer | ||
|
||
createPNGStream(config?: PngConfig): PngStream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/Automattic/node-canvas/pull/1330/files#diff-c472f8ca9fb190272d5098f1ccd7bd41R32
requires definition pngStream , jpegStream , pdfStream method typing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I thought you were asking for those classes to be defined, now I see you meant the method aliases. Those method aliases are present for backwards compatibility; we standardized on Node.js core's idiom of create____
in #1152. I'd rather not type them since they're not otherwise documented, but can add them if you think it's important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be backwards compatible.
Maybe you can learn how to React.
Nice! I'm out and about at the moment but will try to merge and release this asap! Feel free to address my Yarn comment, otherwise I'll fix it myself before merging 👍 |
@zbjornson will this be ready soon? |
It's ready. @LinusU I forgot to post that I addressed your comment. |
Thanks @zbjornson, can't wait, I'm currently blocked by this :-) as I'm porting existing codebase to Typescript. |
Awesome work as always @zbjornson ❤️ |
@zbjornson @LinusU I'm getting error with tsc ERROR in ./node_modules/canvas/build/Release/canvas.node 1:0 Actually, still can't get it to transpile, webpack is still complaining. |
@zbjornson @LinusU hey guys, when do you think you'll be able to cut a new release to NPM? Thanks. |
was hoping to get #1255 in after @zbjornson have taken a look at it, but otherwise we can ship that later... Will try to cut a release tonight or tomorrow, regardless of if it's merged or not |
Good plan; I'll try to get to that tonight, but lots of people are waiting on typescript defs, so no need to delay it. @playground that means something (usually webpack) is trying to load the |
Thanks for contributing!
I'm not a typescript expert, so if anyone sees any better ways to do things, please speak up! :) @varHarrie @adamjking3
Note that typescript between 2.9ish and 3.1ish renamed
Canvas2DContextAttributes
toCanvasRenderingContext2DSettings
. People using older typescript won't have correct definitions.Fixes #1303