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

Add type definitions for createImageBitmap #7483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions lib/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,3 +1476,123 @@ declare interface CredMgmtCredentialsContainer {
): Promise<?CredMgmtCredential>;
preventSilentAccess(): Promise<void>;
}

declare class DOMPointInit {
x: number;
y: number;
z: number;
w: number;
}

declare class DOMPointReadOnly {
constructor(x?: number, y?: number, z?: number, w?: number): void;
static fromPoint(other?: DOMPointInit): DOMPointReadOnly;
+x: number;
+y: number;
+z: number;
+w: number;
matrixTransform(DOMMatrixInit?: DOMMatrixInit): DOMPoint;
toJSON(): string;
}

declare class DOMPoint extends DOMPointReadOnly {
constructor(x?: number, y?: number, z?: number, w?: number): void;
static fromPoint(other?: DOMPointInit): DOMPoint;
}

declare class DOMMatrix2DInit {
a: number;
b: number;
c: number;
d: number;
e: number;
f: number;
m11: number;
m12: number;
m21: number;
m22: number;
m41: number;
m42: number;
}

declare class DOMMatrixInit extends DOMMatrix2DInit {
m13: number;
m14: number;
m23: number;
m24: number;
m31: number;
m32: number;
m33: number;
m34: number;
m43: number;
m44: number;
is2D: boolean;
}

declare class DOMMatrixReadOnly {
constructor(init?: string): void;
static fromMatrix(other?: DOMMatrixInit): DOMMatrixReadOnly;
static fromFloat32Array(array32: Float32Array): DOMMatrixReadOnly;
static fromFloat64Array(array64: Float64Array): DOMMatrixReadOnly;
+a: number;
+b: number;
+c: number;
+d: number;
+e: number;
+f: number;
+m11: number;
+m12: number;
+m13: number;
+m14: number;
+m21: number;
+m22: number;
+m23: number;
+m24: number;
+m31: number;
+m32: number;
+m33: number;
+m34: number;
+m41: number;
+m42: number;
+m43: number;
+m44: number;
+is2D: boolean;
+isIdentity: boolean;
translate(tx?: number, ty?: number, tz?: number): DOMMatrix;
scale(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scaleNonUniform(scaleX?: number, scaleY?: number): DOMMatrix;
scale3d(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
rotate(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
rotateFromVector(x?: number, y?: number): DOMMatrix;
rotateAxisAngle(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
skewX(sx?: number): DOMMatrix;
skewY(sy?: number): DOMMatrix;
multiply(other?: DOMMatrix): DOMMatrix;
flipX(): DOMMatrix;
flipY(): DOMMatrix;
invert(): DOMMatrix;
transformPoint(other?: DOMPointInit: DOMPoint;
toFloat32Array(): Float32Array;
toFloat64Array(): Float64Array;
toJSON(): string;
toString(): string;
}

declare class DOMMatrix extends DOMMatrixReadOnly {
constructor(init?: string): void;
static fromMatrix(other?: DOMMatrixInit): DOMMatrixReadOnly;
static fromFloat32Array(array32: Float32Array): DOMMatrixReadOnly;
static fromFloat64Array(array64: Float64Array): DOMMatrixReadOnly;
multiplySelf(other?: DOMMatrix): DOMMatrix;
preMultiplySelf(other?: DOMMatrix): DOMMatrix;
translateSelf(tx?: number, ty?: number, tz?: number): DOMMatrix;
scaleSelf(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scale3dSelf(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
rotateSelf(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
rotateFromVectorSelf(x?: number, y?: number): DOMMatrix;
rotateAxisAngleSelf(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
skewXSelf(sx?: number): DOMMatrix;
skewYSelf(sy?: number): DOMMatrix;
invertSelf(): DOMMatrix;
setMatrixValue(transformList: string): void;
}
184 changes: 184 additions & 0 deletions lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3973,3 +3973,187 @@ declare class Notification extends EventTarget {

close(): void;
}

declare class SVGElement extends Element {
+dataset: DOMStringMap;
+id: string;
+xmlbase: string;
+ownerSVGElement: SVGElement | null;
+viewportElement: SVGElement | null;
}

declare class SVGTransform {
+type: number;
+angle: number;
+matrix: SVGMatrix;
setMatrix(matrix: SVGMatrix): void;
setTranslate(tx: number, ty: number): void;
setScale(sx: number, sy: number): void;
setRotate(angle: number, cx: number, cy: number): void;
setSkewX(angle: number): void;
setSkewY(angle: number): void;
static SVG_TRANSFORM_UNKNOWN: 0;
static SVG_TRANSFORM_MATRIX: 1;
static SVG_TRANSFORM_TRANSLATE: 2;
static SVG_TRANSFORM_SCALE: 3;
static SVG_TRANSFORM_ROTATE: 4;
static SVG_TRANSFORM_SKEWX: 5;
static SVG_TRANSFORM_SKEWY: 6;
}

declare class SVGTransformList {
+numberOfItems: number;
+length: number;
clear(): void;
initialize(newItem: SVGTransform): SVGTransform;
getItem(index: number): SVGTransform;
insertItemBefore(newItem: SVGTransform, index: number): SVGTransform;
replaceItem(newItem: SVGTransform, index: number): SVGTransform;
removeItem(index: number): SVGTransform ;
appendItem(newItem: SVGTransform): SVGTransform;
createSVGTransformFromMatrix(matrix: SVGMatrix): SVGTransform;
consolidate(): SVGTransform;
}

declare class SVGAnimatedTransformList {
+baseVal: SVGTransformList;
+animVal: SVGTransformList;
}

declare class SVGGraphicsElement extends SVGElement {
+transform: SVGTransformList;
getBBox(): DOMRect;
getCTM(): DOMMatrix;
getScreenCTM(): DOMMatrix;
}

declare class SVGLength {
+unitType: number;
value: number;
valueInSpecifiedUnits: number;
valueAsString: string;
newValueSpecifiedUnits(unitType: number, valueInSpecifiedUnits: number): void;
convertToSpecifiedUnits(unitType: number): void;
static SVG_LENGTHTYPE_UNKNOWN: 0;
static SVG_LENGTHTYPE_NUMBER: 1;
static SVG_LENGTHTYPE_PERCENTAGE: 2;
static SVG_LENGTHTYPE_EMS: 3;
static SVG_LENGTHTYPE_EXS: 4;
static SVG_LENGTHTYPE_PX: 5;
static SVG_LENGTHTYPE_CM: 6;
static SVG_LENGTHTYPE_MM: 7;
static SVG_LENGTHTYPE_IN: 8;
static SVG_LENGTHTYPE_PT: 9;
static SVG_LENGTHTYPE_PC: 10;
}

declare class SVGAnimatedLength {
+baseVal: SVGLength;
+animVal: SVGLength;
}

declare class SVGPreserveAspectRatio {
align: number;
meetOrSlice: number;
static SVG_PRESERVEASPECTRATIO_UNKNOWN: 0;
static SVG_PRESERVEASPECTRATIO_NONE: 1;
static SVG_PRESERVEASPECTRATIO_XMINYMIN: 2;
static SVG_PRESERVEASPECTRATIO_XMIDYMIN: 3;
static SVG_PRESERVEASPECTRATIO_XMAXYMIN: 4;
static SVG_PRESERVEASPECTRATIO_XMINYMID: 5;
static SVG_PRESERVEASPECTRATIO_XMIDYMID: 6;
static SVG_PRESERVEASPECTRATIO_XMAXYMID: 7;
static SVG_PRESERVEASPECTRATIO_XMINYMAX: 8;
static SVG_PRESERVEASPECTRATIO_XMIDYMAX: 9;
static SVG_PRESERVEASPECTRATIO_XMAXYMAX: 10;
static SVG_MEETORSLICE_UNKNOWN: 0;
static SVG_MEETORSLICE_MEET: 1;
static SVG_MEETORSLICE_SLICE: 2;
}

declare class SVGAnimatedPreserveAspectRatio {
+baseVal: SVGPreserveAspectRatio;
+animVal: SVGPreserveAspectRatio;
}

declare class SVGImageElement extends SVGGraphicsElement {
crossOrigin: string;
decoding: string;
+height: SVGAnimatedLength;
+preserveAspectRatio: SVGAnimatedPreserveAspectRatio;
+width: SVGAnimatedLength;
+x: SVGAnimatedLength;
+y: SVGAnimatedLength;
decode(): Promise<void>;
}

type OffscreenCanvasContextId =
'2d' |
'webgl' |
'webgl2' |
'bitmaprenderer';

type ContextOptions2D = {
alpha: boolean,
willReadFrequently: boolean,
storage: string
}

type ContextOptionsWebGL = {
alpha: boolean,
depth: boolean,
stencil: boolean,
antialias: boolean,
premultipliedAlpha: boolean,
preserveDrawingBuffer: boolean,
failIfMajorPerformanceCaveat: boolean
}

type ContextOptions = ContextOptions2D | ContextOptionsWebGL;

type BlobOptions = {
type: string,
quality: number
}

declare class OffscreenCanvas {
constructor(width: number, height: number): void;
height: number;
width: number;
getContext(contextId: OffscreenCanvasContextId , options?: ContextOptions): RenderingContext;
convertToBlob(options?: BlobOptions): Promise<Blob>;
transferToImageBitmap(): ImageBitmap;
}

type CreateImageBitmapSource =
HTMLImageElement |
SVGImageElement |
HTMLVideoElement |
HTMLCanvasElement |
Blob |
ImageData |
ImageBitmap |
OffscreenCanvas;

type CreateImageBitmapOptions = {
imageOrientation: 'none' | 'flipY',
premultiplyAlpha: 'none' | 'default' | 'premultiply',
colorSpaceConversion: 'none' | 'default',
resizeWidth: number,
resizeHeight: number,
resizeQuality: 'pixelated' | 'low' | 'medium' | 'high'
}

declare function createImageBitmap(
image: CreateImageBitmapSource,
sx: number,
sy: number,
sw: number,
sh: number,
options?: CreateImageBitmapOptions
): Promise<ImageBitmap>;

declare function createImageBitmap(
image: CreateImageBitmapSource,
options?: CreateImageBitmapOptions
): Promise<ImageBitmap>;