Skip to content
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

ImageData类型定义缺失 #2

Closed
DazeCake opened this issue Apr 26, 2023 · 2 comments
Closed

ImageData类型定义缺失 #2

DazeCake opened this issue Apr 26, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@DazeCake
Copy link

环境

node: v18.16.0
OS: win11

问题描述

在运行文档中给出的示例后,提示如下错误

PS C:\Users\DazeCake\Development\LittleHandy> node "c:\Users\DazeCake\Development\LittleHandy\app.js"
c:\Users\DazeCake\Development\LittleHandy\node_modules\@arkntools\depot-recognition\dist\index.js:380
  const imgData = new ImageData(new Uint8ClampedArray(img.bitmap.data), img.bitmap.width, img.bitmap.height);
                  ^

ReferenceError: ImageData is not defined
    at c:\Users\DazeCake\Development\LittleHandy\node_modules\@arkntools\depot-recognition\dist\index.js:380:19
    at Array.map (<anonymous>)
    at recognizeNumbers (c:\Users\DazeCake\Development\LittleHandy\node_modules\@arkntools\depot-recognition\dist\index.js:378:57)
    at DeportRecognizer.recognize (c:\Users\DazeCake\Development\LittleHandy\node_modules\@arkntools\depot-recognition\dist\index.js:546:30)
    at async c:\Users\DazeCake\Development\LittleHandy\app.js:29:22

Node.js v18.16.0

在vsc中尝试跳转可以跳转到位于本地路径~\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\lib.dom.d.ts中的此类型定义如下

/** The underlying pixel data of an area of a <canvas> element. It is created using the ImageData() constructor or creator methods on the CanvasRenderingContext2D object associated with a canvas: createImageData() and getImageData(). It can also be used to set a part of the canvas by using putImageData(). */
interface ImageData {
    readonly colorSpace: PredefinedColorSpace;
    /** Returns the one-dimensional array containing the data in RGBA order, as integers in the range 0 to 255. */
    readonly data: Uint8ClampedArray;
    /** Returns the actual dimensions of the data in the ImageData object, in pixels. */
    readonly height: number;
    /** Returns the actual dimensions of the data in the ImageData object, in pixels. */
    readonly width: number;
}

declare var ImageData: {
    prototype: ImageData;
    new(sw: number, sh: number, settings?: ImageDataSettings): ImageData;
    new(data: Uint8ClampedArray, sw: number, sh?: number, settings?: ImageDataSettings): ImageData;
};

可能的解决措施

或许可以手动实现此类型?

@Tsuk1ko Tsuk1ko added the bug Something isn't working label Apr 26, 2023
@Tsuk1ko
Copy link
Member

Tsuk1ko commented Apr 26, 2023

我的,不知道之前怎么想的 node 测试的时候直接造了一个 polyfill 但是没在代码里实现

Sq9NiJvx

@Tsuk1ko
Copy link
Member

Tsuk1ko commented Apr 26, 2023

fixed 2c11851

等 v1.6.3

@Tsuk1ko Tsuk1ko closed this as completed Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants