Skip to content

Commit

Permalink
Update TS types for GifParser and related types.
Browse files Browse the repository at this point in the history
  • Loading branch information
codedread committed Dec 22, 2023
1 parent 13d8a16 commit 757a489
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export {
} from './archive/decompress.js';
export { getFullMIMEString, getShortMIMEString } from './codecs/codecs.js';
export { findMimeType } from './file/sniffer.js';
export { GifApplicationExtensionEvent, GifCommentExtensionEvent, GifGraphicControlExtensionEvent,
GifHeaderParseEvent, GifLogicalScreenParseEvent, GifParseEventType, GifParser,
GifPlainTextExtensionEvent, GifTableBasedImageEvent } from './image/parsers/gif.js';
export { convertWebPtoPNG, convertWebPtoJPG } from './image/webp-shim/webp-shim.js';
export { BitBuffer } from './io/bitbuffer.js';
export { BitStream } from './io/bitstream.js';
Expand Down
237 changes: 237 additions & 0 deletions types/image/parsers/gif.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
export namespace GifParseEventType {
const APPLICATION_EXTENSION: string;
const COMMENT_EXTENSION: string;
const GRAPHIC_CONTROL_EXTENSION: string;
const HEADER: string;
const LOGICAL_SCREEN: string;
const PLAIN_TEXT_EXTENSION: string;
const TABLE_BASED_IMAGE: string;
const TRAILER: string;
}
/**
* @typedef GifHeader
* @property {string} version
*/
export class GifHeaderParseEvent extends Event {
/** @param {GifHeader} header */
constructor(header: GifHeader);
/** @type {GifHeader} */
header: GifHeader;
}
/**
* @typedef GifColor
* @property {number} red
* @property {number} green
* @property {number} blue
*/
/**
* @typedef GifLogicalScreen
* @property {number} logicalScreenWidth
* @property {number} logicalScreenHeight
* @property {boolean} globalColorTableFlag
* @property {number} colorResolution
* @property {boolean} sortFlag
* @property {number} globalColorTableSize
* @property {number} backgroundColorIndex
* @property {number} pixelAspectRatio
* @property {GifColor[]=} globalColorTable Only if globalColorTableFlag is true.
*/
export class GifLogicalScreenParseEvent extends Event {
/** @param {GifLogicalScreen} */
constructor(logicalScreen: any);
/** @type {GifLogicalScreen} */
logicalScreen: GifLogicalScreen;
}
/**
* @typedef GifTableBasedImage
* @property {number} imageLeftPosition
* @property {number} imageTopPosition
* @property {number} imageWidth
* @property {number} imageHeight
* @property {boolean} localColorTableFlag
* @property {boolean} interlaceFlag
* @property {boolean} sortFlag
* @property {number} localColorTableSize
* @property {GifColor[]=} localColorTable Only if localColorTableFlag is true.
* @property {number} lzwMinimumCodeSize
* @property {Uint8Array} imageData
*/
export class GifTableBasedImageEvent extends Event {
/** @param {GifTableBasedImage} img */
constructor(img: GifTableBasedImage);
/** @type {GifTableBasedImage} */
tableBasedImage: GifTableBasedImage;
}
/**
* @typedef GifGraphicControlExtension
* @property {number} disposalMethod
* @property {boolean} userInputFlag
* @property {boolean} transparentColorFlag
* @property {number} delayTime
* @property {number} transparentColorIndex
*/
export class GifGraphicControlExtensionEvent extends Event {
/** @param {GifGraphicControlExtension} ext */
constructor(ext: GifGraphicControlExtension);
/** @type {GifGraphicControlExtension} */
graphicControlExtension: GifGraphicControlExtension;
}
/**
* @typedef GifCommentExtension
* @property {string} comment
*/
export class GifCommentExtensionEvent extends Event {
/** @param {string} comment */
constructor(comment: string);
/** @type {string} */
comment: string;
}
/**
* @typedef GifPlainTextExtension
* @property {number} textGridLeftPosition
* @property {number} textGridTopPosition
* @property {number} textGridWidth
* @property {number} textGridHeight
* @property {number} characterCellWidth
* @property {number} characterCellHeight
* @property {number} textForegroundColorIndex
* @property {number} textBackgroundColorIndex
* @property {string} plainText
*/
export class GifPlainTextExtensionEvent extends Event {
/** @param {GifPlainTextExtension} ext */
constructor(ext: GifPlainTextExtension);
/** @type {GifPlainTextExtension} */
plainTextExtension: GifPlainTextExtension;
}
/**
* @typedef GifApplicationExtension
* @property {string} applicationIdentifier
* @property {Uint8Array} applicationAuthenticationCode
* @property {Uint8Array} applicationData
*/
export class GifApplicationExtensionEvent extends Event {
/** @param {GifApplicationExtension} ext */
constructor(ext: GifApplicationExtension);
/** @type {GifApplicationExtension} */
applicationExtension: GifApplicationExtension;
}
export class GifTrailerEvent extends Event {
constructor();
}
/**
* The Grammar.
*
* <GIF Data Stream> ::= Header <Logical Screen> <Data>* Trailer
* <Logical Screen> ::= Logical Screen Descriptor [Global Color Table]
* <Data> ::= <Graphic Block> |
* <Special-Purpose Block>
* <Graphic Block> ::= [Graphic Control Extension] <Graphic-Rendering Block>
* <Graphic-Rendering Block> ::= <Table-Based Image> |
* Plain Text Extension
* <Table-Based Image> ::= Image Descriptor [Local Color Table] Image Data
* <Special-Purpose Block> ::= Application Extension |
* Comment Extension
*/
export class GifParser extends EventTarget {
/**
* @param {ArrayBuffer} ab
*/
constructor(ab: ArrayBuffer);
/**
* @type {ByteStream}
* @private
*/
private bstream;
/**
* @type {string}
* @private
*/
private version;
/**
* Overridden so that the type hints for eventType are specific.
* @param {'application_extension'|'comment_extension'|'graphical_control_extension'|'header'|'logical_screen'|'plain_text_extension'|'table_based_image'|'trailer'} eventType
* @param {EventListenerOrEventListenerObject} listener
* @override
*/
override addEventListener(eventType: 'application_extension' | 'comment_extension' | 'graphical_control_extension' | 'header' | 'logical_screen' | 'plain_text_extension' | 'table_based_image' | 'trailer', listener: EventListenerOrEventListenerObject): void;
/**
* @returns {Promise<void>} A Promise that resolves when the parsing is complete.
*/
start(): Promise<void>;
/**
* @private
* @returns {boolean} True if this was not the last block.
*/
private readGraphicBlock;
/**
* @private
* @returns {Uint8Array} Data from the sub-block, or null if this was the last, zero-length block.
*/
private readSubBlock;
}
export type GifHeader = {
version: string;
};
export type GifColor = {
red: number;
green: number;
blue: number;
};
export type GifLogicalScreen = {
logicalScreenWidth: number;
logicalScreenHeight: number;
globalColorTableFlag: boolean;
colorResolution: number;
sortFlag: boolean;
globalColorTableSize: number;
backgroundColorIndex: number;
pixelAspectRatio: number;
/**
* Only if globalColorTableFlag is true.
*/
globalColorTable?: GifColor[] | undefined;
};
export type GifTableBasedImage = {
imageLeftPosition: number;
imageTopPosition: number;
imageWidth: number;
imageHeight: number;
localColorTableFlag: boolean;
interlaceFlag: boolean;
sortFlag: boolean;
localColorTableSize: number;
/**
* Only if localColorTableFlag is true.
*/
localColorTable?: GifColor[] | undefined;
lzwMinimumCodeSize: number;
imageData: Uint8Array;
};
export type GifGraphicControlExtension = {
disposalMethod: number;
userInputFlag: boolean;
transparentColorFlag: boolean;
delayTime: number;
transparentColorIndex: number;
};
export type GifCommentExtension = {
comment: string;
};
export type GifPlainTextExtension = {
textGridLeftPosition: number;
textGridTopPosition: number;
textGridWidth: number;
textGridHeight: number;
characterCellWidth: number;
characterCellHeight: number;
textForegroundColorIndex: number;
textBackgroundColorIndex: number;
plainText: string;
};
export type GifApplicationExtension = {
applicationIdentifier: string;
applicationAuthenticationCode: Uint8Array;
applicationData: Uint8Array;
};
//# sourceMappingURL=gif.d.ts.map
1 change: 1 addition & 0 deletions types/image/parsers/gif.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export type ProbeFormat = import('./codecs/codecs.js').ProbeFormat;
export type ProbeInfo = import('./codecs/codecs.js').ProbeInfo;
export { UnarchiveEvent, UnarchiveEventType, UnarchiveInfoEvent, UnarchiveErrorEvent, UnarchiveStartEvent, UnarchiveFinishEvent, UnarchiveProgressEvent, UnarchiveExtractEvent, Unarchiver, Unzipper, Unrarrer, Untarrer, getUnarchiver } from "./archive/decompress.js";
export { getFullMIMEString, getShortMIMEString } from "./codecs/codecs.js";
export { GifApplicationExtensionEvent, GifCommentExtensionEvent, GifGraphicControlExtensionEvent, GifHeaderParseEvent, GifLogicalScreenParseEvent, GifParseEventType, GifParser, GifPlainTextExtensionEvent, GifTableBasedImageEvent } from "./image/parsers/gif.js";
export { convertWebPtoPNG, convertWebPtoJPG } from "./image/webp-shim/webp-shim.js";
//# sourceMappingURL=index.d.ts.map

0 comments on commit 757a489

Please sign in to comment.