1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-03 09:39:16 +02:00

Remove GIF parser event boilerplate in favor of a @template solution using CustomEvent

This commit is contained in:
Jeff Schiller 2024-01-19 11:43:03 -08:00
parent 5aff47ccfd
commit c3a7b35fd5
13 changed files with 97 additions and 187 deletions

View file

@ -10,6 +10,7 @@
import { BitStream } from '../../io/bitstream.js'; import { BitStream } from '../../io/bitstream.js';
import { ByteStream } from '../../io/bytestream.js'; import { ByteStream } from '../../io/bytestream.js';
import { createEvent } from './parsers.js';
// https://www.w3.org/Graphics/GIF/spec-gif89a.txt // https://www.w3.org/Graphics/GIF/spec-gif89a.txt
@ -29,15 +30,6 @@ export const GifParseEventType = {
* @property {string} version * @property {string} version
*/ */
export class GifHeaderEvent extends Event {
/** @param {GifHeader} header */
constructor(header) {
super(GifParseEventType.HEADER);
/** @type {GifHeader} */
this.header = header;
}
}
/** /**
* @typedef GifColor * @typedef GifColor
* @property {number} red * @property {number} red
@ -58,15 +50,6 @@ export class GifHeaderEvent extends Event {
* @property {GifColor[]=} globalColorTable Only if globalColorTableFlag is true. * @property {GifColor[]=} globalColorTable Only if globalColorTableFlag is true.
*/ */
export class GifLogicalScreenEvent extends Event {
/** @param {GifLogicalScreen} */
constructor(logicalScreen) {
super(GifParseEventType.LOGICAL_SCREEN);
/** @type {GifLogicalScreen} */
this.logicalScreen = logicalScreen;
}
}
/** /**
* @typedef GifTableBasedImage * @typedef GifTableBasedImage
* @property {number} imageLeftPosition * @property {number} imageLeftPosition
@ -82,15 +65,6 @@ export class GifLogicalScreenEvent extends Event {
* @property {Uint8Array} imageData * @property {Uint8Array} imageData
*/ */
export class GifTableBasedImageEvent extends Event {
/** @param {GifTableBasedImage} img */
constructor(img) {
super(GifParseEventType.TABLE_BASED_IMAGE);
/** @type {GifTableBasedImage} */
this.tableBasedImage = img;
}
}
/** /**
* @typedef GifGraphicControlExtension * @typedef GifGraphicControlExtension
* @property {number} disposalMethod * @property {number} disposalMethod
@ -100,29 +74,11 @@ export class GifTableBasedImageEvent extends Event {
* @property {number} transparentColorIndex * @property {number} transparentColorIndex
*/ */
export class GifGraphicControlExtensionEvent extends Event {
/** @param {GifGraphicControlExtension} ext */
constructor(ext) {
super(GifParseEventType.GRAPHIC_CONTROL_EXTENSION);
/** @type {GifGraphicControlExtension} */
this.graphicControlExtension = ext;
}
}
/** /**
* @typedef GifCommentExtension * @typedef GifCommentExtension
* @property {string} comment * @property {string} comment
*/ */
export class GifCommentExtensionEvent extends Event {
/** @param {string} comment */
constructor(comment) {
super(GifParseEventType.COMMENT_EXTENSION);
/** @type {string} */
this.comment = comment;
}
}
/** /**
* @typedef GifPlainTextExtension * @typedef GifPlainTextExtension
* @property {number} textGridLeftPosition * @property {number} textGridLeftPosition
@ -136,15 +92,6 @@ export class GifCommentExtensionEvent extends Event {
* @property {string} plainText * @property {string} plainText
*/ */
export class GifPlainTextExtensionEvent extends Event {
/** @param {GifPlainTextExtension} ext */
constructor(ext) {
super(GifParseEventType.PLAIN_TEXT_EXTENSION);
/** @type {GifPlainTextExtension} */
this.plainTextExtension = ext;
}
}
/** /**
* @typedef GifApplicationExtension * @typedef GifApplicationExtension
* @property {string} applicationIdentifier * @property {string} applicationIdentifier
@ -152,21 +99,6 @@ export class GifPlainTextExtensionEvent extends Event {
* @property {Uint8Array} applicationData * @property {Uint8Array} applicationData
*/ */
export class GifApplicationExtensionEvent extends Event {
/** @param {GifApplicationExtension} ext */
constructor(ext) {
super(GifParseEventType.APPLICATION_EXTENSION);
/** @type {GifApplicationExtension} */
this.applicationExtension = ext;
}
}
export class GifTrailerEvent extends Event {
constructor() {
super(GifParseEventType.TRAILER);
}
}
/** /**
* The Grammar. * The Grammar.
* *
@ -204,8 +136,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifApplicationExtensionEvent. * Type-safe way to bind a listener for a GifApplicationExtension.
* @param {function(GifApplicationExtensionEvent): void} listener * @param {function(CustomEvent<GifApplicationExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onApplicationExtension(listener) { onApplicationExtension(listener) {
@ -214,8 +146,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifCommentExtensionEvent. * Type-safe way to bind a listener for a GifCommentExtension.
* @param {function(GifCommentExtensionEvent): void} listener * @param {function(CustomEvent<GifCommentExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onCommentExtension(listener) { onCommentExtension(listener) {
@ -224,8 +156,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifGraphicControlExtensionEvent. * Type-safe way to bind a listener for a GifGraphicControlExtension.
* @param {function(GifGraphicControlExtensionEvent): void} listener * @param {function(CustomEvent<GifGraphicControlExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onGraphicControlExtension(listener) { onGraphicControlExtension(listener) {
@ -234,8 +166,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifHeaderEvent. * Type-safe way to bind a listener for a GifHeader.
* @param {function(GifHeaderEvent): void} listener * @param {function(CustomEvent<GifHeader>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onHeader(listener) { onHeader(listener) {
@ -244,8 +176,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifLogicalScreenEvent. * Type-safe way to bind a listener for a GifLogicalScreen.
* @param {function(GifLogicalScreenEvent): void} listener * @param {function(CustomEvent<GifLogicalScreen>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onLogicalScreen(listener) { onLogicalScreen(listener) {
@ -254,8 +186,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifPlainTextExtensionEvent. * Type-safe way to bind a listener for a GifPlainTextExtension.
* @param {function(GifPlainTextExtensionEvent): void} listener * @param {function(CustomEvent<GifPlainTextExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onPlainTextExtension(listener) { onPlainTextExtension(listener) {
@ -264,8 +196,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifTableBasedImageEvent. * Type-safe way to bind a listener for a GifTableBasedImage.
* @param {function(GifTableBasedImageEvent): void} listener * @param {function(CustomEvent<GifTableBasedImage>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onTableBasedImage(listener) { onTableBasedImage(listener) {
@ -274,8 +206,8 @@ export class GifParser extends EventTarget {
} }
/** /**
* Type-safe way to bind a listener for a GifTrailerEvent. * Type-safe way to bind a listener for the GifTrailer.
* @param {function(GifTrailerEvent): void} listener * @param {function(CustomEvent): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onTrailer(listener) { onTrailer(listener) {
@ -294,9 +226,7 @@ export class GifParser extends EventTarget {
const version = this.version = this.bstream.readString(3); // "87a" or "89a" const version = this.version = this.bstream.readString(3); // "87a" or "89a"
if (!["87a", "89a"].includes(version)) throw `Bad version: ${version}`; if (!["87a", "89a"].includes(version)) throw `Bad version: ${version}`;
this.dispatchEvent(new GifHeaderEvent( this.dispatchEvent(createEvent(GifParseEventType.HEADER, {version}));
/** @type {GifHeader} */ ({ version })
));
// Logical Screen Descriptor. // Logical Screen Descriptor.
const logicalScreenWidth = this.bstream.readNumber(2); const logicalScreenWidth = this.bstream.readNumber(2);
@ -323,7 +253,7 @@ export class GifParser extends EventTarget {
})); }));
} }
} }
this.dispatchEvent(new GifLogicalScreenEvent( this.dispatchEvent(createEvent(GifParseEventType.LOGICAL_SCREEN,
/** @type {GifLogicalScreen} */ ({ /** @type {GifLogicalScreen} */ ({
logicalScreenWidth, logicalScreenWidth,
logicalScreenHeight, logicalScreenHeight,
@ -394,7 +324,7 @@ export class GifParser extends EventTarget {
ptr += arr.byteLength; ptr += arr.byteLength;
} }
this.dispatchEvent(new GifTableBasedImageEvent( this.dispatchEvent(createEvent(GifParseEventType.TABLE_BASED_IMAGE,
/** @type {GifTableBasedImage} */ ({ /** @type {GifTableBasedImage} */ ({
imageLeftPosition, imageLeftPosition,
imageTopPosition, imageTopPosition,
@ -437,7 +367,7 @@ export class GifParser extends EventTarget {
const blockTerminator = this.bstream.readNumber(1); const blockTerminator = this.bstream.readNumber(1);
if (blockTerminator !== 0) throw `GCE: Block terminator of ${blockTerminator}`; if (blockTerminator !== 0) throw `GCE: Block terminator of ${blockTerminator}`;
this.dispatchEvent(new GifGraphicControlExtensionEvent( this.dispatchEvent(createEvent(GifParseEventType.GRAPHIC_CONTROL_EXTENSION,
/** @type {GifGraphicControlExtension} */ ({ /** @type {GifGraphicControlExtension} */ ({
disposalMethod, disposalMethod,
userInputFlag, userInputFlag,
@ -456,7 +386,7 @@ export class GifParser extends EventTarget {
while ((bytes = this.readSubBlock())) { while ((bytes = this.readSubBlock())) {
comment += new TextDecoder().decode(bytes); comment += new TextDecoder().decode(bytes);
} }
this.dispatchEvent(new GifCommentExtensionEvent(comment)); this.dispatchEvent(createEvent(GifParseEventType.COMMENT_EXTENSION, comment));
return true; return true;
} }
@ -479,7 +409,7 @@ export class GifParser extends EventTarget {
plainText += new TextDecoder().decode(bytes); plainText += new TextDecoder().decode(bytes);
} }
this.dispatchEvent(new GifPlainTextExtensionEvent( this.dispatchEvent(createEvent(GifParseEventType.PLAIN_TEXT_EXTENSION,
/** @type {GifPlainTextExtension} */ ({ /** @type {GifPlainTextExtension} */ ({
textGridLeftPosition, textGridLeftPosition,
textGridTopPosition, textGridTopPosition,
@ -518,7 +448,7 @@ export class GifParser extends EventTarget {
ptr += arr.byteLength; ptr += arr.byteLength;
} }
this.dispatchEvent(new GifApplicationExtensionEvent( this.dispatchEvent(createEvent(GifParseEventType.APPLICATION_EXTENSION,
/** {@type GifApplicationExtension} */ ({ /** {@type GifApplicationExtension} */ ({
applicationIdentifier, applicationIdentifier,
applicationAuthenticationCode, applicationAuthenticationCode,
@ -534,7 +464,7 @@ export class GifParser extends EventTarget {
} }
} }
else if (nextByte === 0x3B) { else if (nextByte === 0x3B) {
this.dispatchEvent(new GifTrailerEvent()); this.dispatchEvent(createEvent(GifParseEventType.TRAILER));
// Read the trailer. // Read the trailer.
return false; return false;
} }

20
image/parsers/parsers.js Normal file
View file

@ -0,0 +1,20 @@
/*
* parsers.js
*
* Common functionality for all image parsers.
*
* Licensed under the MIT License
*
* Copyright(c) 2024 Google Inc.
*/
/**
* Creates a new event of the given type with the specified data.
* @template T
* @param {string} type The event type.
* @param {T} data The event data.
* @return {CustomEvent<T>} The new event.
*/
export function createEvent(type, data) {
return new CustomEvent(type, { detail: data });
}

View file

@ -34,9 +34,7 @@ export {
} from './archive/decompress.js'; } from './archive/decompress.js';
export { getFullMIMEString, getShortMIMEString } from './codecs/codecs.js'; export { getFullMIMEString, getShortMIMEString } from './codecs/codecs.js';
export { findMimeType } from './file/sniffer.js'; export { findMimeType } from './file/sniffer.js';
export { GifApplicationExtensionEvent, GifCommentExtensionEvent, GifGraphicControlExtensionEvent, export { GifParseEventType, GifParser } from './image/parsers/gif.js';
GifHeaderEvent, GifLogicalScreenEvent, GifParseEventType, GifParser,
GifPlainTextExtensionEvent, GifTableBasedImageEvent } from './image/parsers/gif.js';
export { JpegApp0ExtensionEvent, JpegApp0MarkerEvent, JpegApp1ExifEvent, JpegComponentType, export { JpegApp0ExtensionEvent, JpegApp0MarkerEvent, JpegApp1ExifEvent, JpegComponentType,
JpegDctType, JpegDefineHuffmanTableEvent, JpegDefineQuantizationTableEvent, JpegDctType, JpegDefineHuffmanTableEvent, JpegDefineQuantizationTableEvent,
JpegDensityUnits, JpegExtensionThumbnailFormat, JpegHuffmanTableType, JpegParseEventType, JpegDensityUnits, JpegExtensionThumbnailFormat, JpegHuffmanTableType, JpegParseEventType,

View file

@ -15,16 +15,16 @@ describe('bitjs.image.parsers.GifParser', () => {
let trailerFound = false; let trailerFound = false;
let comment; let comment;
parser.onLogicalScreen(evt => { parser.onLogicalScreen(evt => {
const {logicalScreenWidth, logicalScreenHeight} = evt.logicalScreen; const {logicalScreenWidth, logicalScreenHeight} = evt.detail;
expect(logicalScreenWidth).equals(32); expect(logicalScreenWidth).equals(32);
expect(logicalScreenHeight).equals(52); expect(logicalScreenHeight).equals(52);
}); });
parser.onTableBasedImage(evt => { parser.onTableBasedImage(evt => {
const {imageWidth, imageHeight} = evt.tableBasedImage; const {imageWidth, imageHeight} = evt.detail;
expect(imageWidth).equals(32); expect(imageWidth).equals(32);
expect(imageHeight).equals(52); expect(imageHeight).equals(52);
}); });
parser.onCommentExtension(evt => comment = evt.comment); parser.onCommentExtension(evt => comment = evt.detail);
parser.onTrailer(evt => trailerFound = true); parser.onTrailer(evt => trailerFound = true);
await parser.start(); await parser.start();
@ -42,10 +42,10 @@ describe('bitjs.image.parsers.GifParser', () => {
let appAuthCode; let appAuthCode;
let hasAppData = false; let hasAppData = false;
parser.onApplicationExtension(evt => { parser.onApplicationExtension(evt => {
appId = evt.applicationExtension.applicationIdentifier appId = evt.detail.applicationIdentifier
appAuthCode = new TextDecoder().decode( appAuthCode = new TextDecoder().decode(
evt.applicationExtension.applicationAuthenticationCode); evt.detail.applicationAuthenticationCode);
hasAppData = evt.applicationExtension.applicationData.byteLength > 0; hasAppData = evt.detail.applicationData.byteLength > 0;
}); });
await parser.start(); await parser.start();

View file

@ -5,6 +5,12 @@
* @returns {ExifValue} * @returns {ExifValue}
*/ */
export function getExifValue(stream: ByteStream, lookAheadStream: ByteStream, DEBUG?: boolean): ExifValue; export function getExifValue(stream: ByteStream, lookAheadStream: ByteStream, DEBUG?: boolean): ExifValue;
/**
* Reads the entire EXIF profile. The first 2 bytes in the stream must be the TIFF marker (II/MM).
* @param {ByteStream} stream
* @returns {Map<number, ExifValue} A map of all EXIF values found. The key is the EXIF tag number.
*/
export function getExifProfile(stream: ByteStream): Map<number, ExifValue>;
export type ExifTagNumber = number; export type ExifTagNumber = number;
export namespace ExifTagNumber { export namespace ExifTagNumber {
const IMAGE_DESCRIPTION: number; const IMAGE_DESCRIPTION: number;

View file

@ -1 +1 @@
{"version":3,"file":"exif.d.ts","sourceRoot":"","sources":["../../../image/parsers/exif.js"],"names":[],"mappings":"AAqHA;;;;;GAKG;AACH,qCALW,UAAU,mBACV,UAAU,oBAER,SAAS,CAsGrB;4BA7NU,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA2EN,MAAM;;;;;;;;;;;;;;;;;;;eAkBH,aAAa;;;;cACb,MAAM;;;;gBACN,cAAc;;;;qBACd,MAAM;;;;kBACN,MAAM;;;;qBACN,MAAM;;;;uBACN,MAAM;;;;oBACN,MAAM;;;;kBACN,MAAM"} {"version":3,"file":"exif.d.ts","sourceRoot":"","sources":["../../../image/parsers/exif.js"],"names":[],"mappings":"AA+HA;;;;;GAKG;AACH,qCALW,UAAU,mBACV,UAAU,oBAER,SAAS,CAsGrB;AA6BD;;;;GAIG;AACH,uCAHW,UAAU,0BAyCpB;4BArSU,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA2EN,MAAM;;;;;;;;;;;;;;;;;;;eAkBH,aAAa;;;;cACb,MAAM;;;;gBACN,cAAc;;;;qBACd,MAAM;;;;kBACN,MAAM;;;;qBACN,MAAM;;;;uBACN,MAAM;;;;oBACN,MAAM;;;;kBACN,MAAM"}

View file

@ -12,12 +12,6 @@ export namespace GifParseEventType {
* @typedef GifHeader * @typedef GifHeader
* @property {string} version * @property {string} version
*/ */
export class GifHeaderEvent extends Event {
/** @param {GifHeader} header */
constructor(header: GifHeader);
/** @type {GifHeader} */
header: GifHeader;
}
/** /**
* @typedef GifColor * @typedef GifColor
* @property {number} red * @property {number} red
@ -36,12 +30,6 @@ export class GifHeaderEvent extends Event {
* @property {number} pixelAspectRatio * @property {number} pixelAspectRatio
* @property {GifColor[]=} globalColorTable Only if globalColorTableFlag is true. * @property {GifColor[]=} globalColorTable Only if globalColorTableFlag is true.
*/ */
export class GifLogicalScreenEvent extends Event {
/** @param {GifLogicalScreen} */
constructor(logicalScreen: any);
/** @type {GifLogicalScreen} */
logicalScreen: GifLogicalScreen;
}
/** /**
* @typedef GifTableBasedImage * @typedef GifTableBasedImage
* @property {number} imageLeftPosition * @property {number} imageLeftPosition
@ -56,12 +44,6 @@ export class GifLogicalScreenEvent extends Event {
* @property {number} lzwMinimumCodeSize * @property {number} lzwMinimumCodeSize
* @property {Uint8Array} imageData * @property {Uint8Array} imageData
*/ */
export class GifTableBasedImageEvent extends Event {
/** @param {GifTableBasedImage} img */
constructor(img: GifTableBasedImage);
/** @type {GifTableBasedImage} */
tableBasedImage: GifTableBasedImage;
}
/** /**
* @typedef GifGraphicControlExtension * @typedef GifGraphicControlExtension
* @property {number} disposalMethod * @property {number} disposalMethod
@ -70,22 +52,10 @@ export class GifTableBasedImageEvent extends Event {
* @property {number} delayTime * @property {number} delayTime
* @property {number} transparentColorIndex * @property {number} transparentColorIndex
*/ */
export class GifGraphicControlExtensionEvent extends Event {
/** @param {GifGraphicControlExtension} ext */
constructor(ext: GifGraphicControlExtension);
/** @type {GifGraphicControlExtension} */
graphicControlExtension: GifGraphicControlExtension;
}
/** /**
* @typedef GifCommentExtension * @typedef GifCommentExtension
* @property {string} comment * @property {string} comment
*/ */
export class GifCommentExtensionEvent extends Event {
/** @param {string} comment */
constructor(comment: string);
/** @type {string} */
comment: string;
}
/** /**
* @typedef GifPlainTextExtension * @typedef GifPlainTextExtension
* @property {number} textGridLeftPosition * @property {number} textGridLeftPosition
@ -98,27 +68,12 @@ export class GifCommentExtensionEvent extends Event {
* @property {number} textBackgroundColorIndex * @property {number} textBackgroundColorIndex
* @property {string} plainText * @property {string} plainText
*/ */
export class GifPlainTextExtensionEvent extends Event {
/** @param {GifPlainTextExtension} ext */
constructor(ext: GifPlainTextExtension);
/** @type {GifPlainTextExtension} */
plainTextExtension: GifPlainTextExtension;
}
/** /**
* @typedef GifApplicationExtension * @typedef GifApplicationExtension
* @property {string} applicationIdentifier * @property {string} applicationIdentifier
* @property {Uint8Array} applicationAuthenticationCode * @property {Uint8Array} applicationAuthenticationCode
* @property {Uint8Array} applicationData * @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. * The Grammar.
* *
@ -147,53 +102,53 @@ export class GifParser extends EventTarget {
*/ */
private version; private version;
/** /**
* Type-safe way to bind a listener for a GifApplicationExtensionEvent. * Type-safe way to bind a listener for a GifApplicationExtension.
* @param {function(GifApplicationExtensionEvent): void} listener * @param {function(CustomEvent<GifApplicationExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onApplicationExtension(listener: (arg0: GifApplicationExtensionEvent) => void): GifParser; onApplicationExtension(listener: (arg0: CustomEvent<GifApplicationExtension>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifCommentExtensionEvent. * Type-safe way to bind a listener for a GifCommentExtension.
* @param {function(GifCommentExtensionEvent): void} listener * @param {function(CustomEvent<GifCommentExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onCommentExtension(listener: (arg0: GifCommentExtensionEvent) => void): GifParser; onCommentExtension(listener: (arg0: CustomEvent<GifCommentExtension>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifGraphicControlExtensionEvent. * Type-safe way to bind a listener for a GifGraphicControlExtension.
* @param {function(GifGraphicControlExtensionEvent): void} listener * @param {function(CustomEvent<GifGraphicControlExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onGraphicControlExtension(listener: (arg0: GifGraphicControlExtensionEvent) => void): GifParser; onGraphicControlExtension(listener: (arg0: CustomEvent<GifGraphicControlExtension>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifHeaderEvent. * Type-safe way to bind a listener for a GifHeader.
* @param {function(GifHeaderEvent): void} listener * @param {function(CustomEvent<GifHeader>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onHeader(listener: (arg0: GifHeaderEvent) => void): GifParser; onHeader(listener: (arg0: CustomEvent<GifHeader>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifLogicalScreenEvent. * Type-safe way to bind a listener for a GifLogicalScreen.
* @param {function(GifLogicalScreenEvent): void} listener * @param {function(CustomEvent<GifLogicalScreen>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onLogicalScreen(listener: (arg0: GifLogicalScreenEvent) => void): GifParser; onLogicalScreen(listener: (arg0: CustomEvent<GifLogicalScreen>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifPlainTextExtensionEvent. * Type-safe way to bind a listener for a GifPlainTextExtension.
* @param {function(GifPlainTextExtensionEvent): void} listener * @param {function(CustomEvent<GifPlainTextExtension>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onPlainTextExtension(listener: (arg0: GifPlainTextExtensionEvent) => void): GifParser; onPlainTextExtension(listener: (arg0: CustomEvent<GifPlainTextExtension>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifTableBasedImageEvent. * Type-safe way to bind a listener for a GifTableBasedImage.
* @param {function(GifTableBasedImageEvent): void} listener * @param {function(CustomEvent<GifTableBasedImage>): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onTableBasedImage(listener: (arg0: GifTableBasedImageEvent) => void): GifParser; onTableBasedImage(listener: (arg0: CustomEvent<GifTableBasedImage>) => void): GifParser;
/** /**
* Type-safe way to bind a listener for a GifTrailerEvent. * Type-safe way to bind a listener for the GifTrailer.
* @param {function(GifTrailerEvent): void} listener * @param {function(CustomEvent): void} listener
* @returns {GifParser} for chaining * @returns {GifParser} for chaining
*/ */
onTrailer(listener: (arg0: GifTrailerEvent) => void): GifParser; onTrailer(listener: (arg0: CustomEvent) => void): GifParser;
/** /**
* @returns {Promise<void>} A Promise that resolves when the parsing is complete. * @returns {Promise<void>} A Promise that resolves when the parsing is complete.
*/ */

View file

@ -1 +1 @@
{"version":3,"file":"gif.d.ts","sourceRoot":"","sources":["../../../image/parsers/gif.js"],"names":[],"mappings":";;;;;;;;;;AA0BA;;;GAGG;AAEH;IACE,gCAAgC;IAChC,oBADY,SAAS,EAKpB;IAFC,wBAAwB;IACxB,QADW,SAAS,CACA;CAEvB;AAED;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AAEH;IACE,gCAAgC;IAChC,gCAIC;IAFC,+BAA+B;IAC/B,eADW,gBAAgB,CACO;CAErC;AAED;;;;;;;;;;;;;GAaG;AAEH;IACE,sCAAsC;IACtC,iBADY,kBAAkB,EAK7B;IAFC,iCAAiC;IACjC,iBADW,kBAAkB,CACH;CAE7B;AAED;;;;;;;GAOG;AAEH;IACE,8CAA8C;IAC9C,iBADY,0BAA0B,EAKrC;IAFC,yCAAyC;IACzC,yBADW,0BAA0B,CACH;CAErC;AAED;;;GAGG;AAEH;IACE,8BAA8B;IAC9B,qBADY,MAAM,EAKjB;IAFC,qBAAqB;IACrB,SADW,MAAM,CACK;CAEzB;AAED;;;;;;;;;;;GAWG;AAEH;IACE,yCAAyC;IACzC,iBADY,qBAAqB,EAKhC;IAFC,oCAAoC;IACpC,oBADW,qBAAqB,CACH;CAEhC;AAED;;;;;GAKG;AAEH;IACE,2CAA2C;IAC3C,iBADY,uBAAuB,EAKlC;IAFC,sCAAsC;IACtC,sBADW,uBAAuB,CACH;CAElC;AAED;IACE,cAEC;CACF;AAED;;;;;;;;;;;;;GAaG;AAEH;IAaE,8BAA8B;IAC9B,gBADY,WAAW,EAMtB;IAlBD;;;OAGG;IACH,gBAAQ;IAER;;;OAGG;IACH,gBAAQ;IAUR;;;;OAIG;IACH,wCAHoB,4BAA4B,KAAG,IAAI,GAC1C,SAAS,CAKrB;IAED;;;;OAIG;IACH,oCAHoB,wBAAwB,KAAG,IAAI,GACtC,SAAS,CAKrB;IAED;;;;OAIG;IACH,2CAHoB,+BAA+B,KAAG,IAAI,GAC7C,SAAS,CAKrB;IAED;;;;OAIG;IACH,0BAHoB,cAAc,KAAG,IAAI,GAC5B,SAAS,CAKrB;IAED;;;;OAIG;IACH,iCAHoB,qBAAqB,KAAG,IAAI,GACnC,SAAS,CAKrB;IAED;;;;OAIG;IACH,sCAHoB,0BAA0B,KAAG,IAAI,GACxC,SAAS,CAKrB;IAED;;;;OAIG;IACH,mCAHoB,uBAAuB,KAAG,IAAI,GACrC,SAAS,CAKrB;IAED;;;;OAIG;IACH,2BAHoB,eAAe,KAAG,IAAI,GAC7B,SAAS,CAKrB;IAED;;OAEG;IACH,SAFa,QAAQ,IAAI,CAAC,CAwDzB;IAED;;;OAGG;IACH,yBAmMC;IAED;;;OAGG;IACH,qBAIC;CACF;;aA9gBa,MAAM;;;SAcN,MAAM;WACN,MAAM;UACN,MAAM;;;wBAKN,MAAM;yBACN,MAAM;0BACN,OAAO;qBACP,MAAM;cACN,OAAO;0BACP,MAAM;0BACN,MAAM;sBACN,MAAM;;;;uBACN,QAAQ,EAAE;;;uBAcV,MAAM;sBACN,MAAM;gBACN,MAAM;iBACN,MAAM;yBACN,OAAO;mBACP,OAAO;cACP,OAAO;yBACP,MAAM;;;;sBACN,QAAQ,EAAE;wBACV,MAAM;eACN,UAAU;;;oBAcV,MAAM;mBACN,OAAO;0BACP,OAAO;eACP,MAAM;2BACN,MAAM;;;aAcN,MAAM;;;0BAcN,MAAM;yBACN,MAAM;mBACN,MAAM;oBACN,MAAM;wBACN,MAAM;yBACN,MAAM;8BACN,MAAM;8BACN,MAAM;eACN,MAAM;;;2BAcN,MAAM;mCACN,UAAU;qBACV,UAAU"} {"version":3,"file":"gif.d.ts","sourceRoot":"","sources":["../../../image/parsers/gif.js"],"names":[],"mappings":";;;;;;;;;;AA2BA;;;GAGG;AA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;mBACP,OAAO;cACP,OAAO;yBACP,MAAM;;;;sBACN,QAAQ,EAAE;wBACV,MAAM;eACN,UAAU;;;oBAKV,MAAM;mBACN,OAAO;0BACP,OAAO;eACP,MAAM;2BACN,MAAM;;;aAKN,MAAM;;;0BAKN,MAAM;yBACN,MAAM;mBACN,MAAM;oBACN,MAAM;wBACN,MAAM;yBACN,MAAM;8BACN,MAAM;8BACN,MAAM;eACN,MAAM;;;2BAKN,MAAM;mCACN,UAAU;qBACV,UAAU"}

View file

@ -208,14 +208,6 @@ export class JpegParser extends EventTarget {
onStartOfScan(listener: (arg0: JpegStartOfScanEvent) => void): JpegParser; onStartOfScan(listener: (arg0: JpegStartOfScanEvent) => void): JpegParser;
/** @returns {Promise<void>} A Promise that resolves when the parsing is complete. */ /** @returns {Promise<void>} A Promise that resolves when the parsing is complete. */
start(): Promise<void>; start(): Promise<void>;
/**
* Reads an Image File Directory from stream.
* @param {ByteStream} stream The stream to extract the Exif value descriptor.
* @param {ByteStream} lookAheadStream The lookahead stream if the offset is used.
* @param {Map<number, ExifValue} exifValueMap This map to add the Exif values.
* @returns {number} The next IFD offset.
*/
readExifIfd(stream: ByteStream, lookAheadStream: ByteStream, exifValueMap: Map<number, import("./exif.js").ExifValue>): number;
} }
export type ExifValue = import('./exif.js').ExifValue; export type ExifValue = import('./exif.js').ExifValue;
export type JpegApp0Marker = { export type JpegApp0Marker = {
@ -299,5 +291,4 @@ export type JpegStartOfScan = {
successiveApproximationBitPosition: number; successiveApproximationBitPosition: number;
rawImageData: Uint8Array; rawImageData: Uint8Array;
}; };
import { ByteStream } from "../../io/bytestream.js";
//# sourceMappingURL=jpeg.d.ts.map //# sourceMappingURL=jpeg.d.ts.map

View file

@ -1 +1 @@
{"version":3,"file":"jpeg.d.ts","sourceRoot":"","sources":["../../../image/parsers/jpeg.js"],"names":[],"mappings":"iCAwBW,MAAM;;;;;;;;;;8BAWN,MAAM;;;;;;;;;;;;;+BAwBN,MAAM;;;;;;AAOjB;;;;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IACH,gCAHoB,qBAAqB,KAAG,IAAI,GACnC,UAAU,CAKtB;IAED;;;;OAIG;IACH,+BAHoB,oBAAoB,KAAG,IAAI,GAClC,UAAU,CAKtB;IAED,qFAAqF;IACrF,SADc,QAAQ,IAAI,CAAC,CAgR1B;IAED;;;;;;OAMG;IACH,oBALW,UAAU,mBACV,UAAU,6DAER,MAAM,CAoBlB;CACF;wBArlBY,OAAO,WAAW,EAAE,SAAS;;;;;iBAsD5B,MAAM;kBACN,gBAAgB;cAChB,MAAM;cACN,MAAM;gBACN,MAAM;gBACN,MAAM;;;;mBACN,UAAU;;;qBAqBV,4BAA4B;;;;mBAC5B,UAAU;;;;;;iBAuBV,MAAM;;;;eACN,MAAM;;;;iBACN,MAAM,EAAE;;;;;;iBAoBR,MAAM;;;;eACN,oBAAoB;;;;qBACpB,MAAM,EAAE;aACR,MAAM,EAAE;;;iBA8BR,iBAAiB;4BACjB,MAAM;8BACN,MAAM;6BACN,MAAM;;;aAKN,WAAW;mBACX,MAAM;iBACN,MAAM;gBACN,MAAM;;;;wBACN,MAAM;sBACN,mBAAmB,EAAE;;;sBAcrB,MAAM;wBACN,MAAM;2BACN,MAAM;yBACN,MAAM;4BACN,MAAM;yBACN,MAAM;4BACN,MAAM;8BACN,MAAM;4BACN,MAAM;wCACN,MAAM;kBACN,UAAU"} {"version":3,"file":"jpeg.d.ts","sourceRoot":"","sources":["../../../image/parsers/jpeg.js"],"names":[],"mappings":"iCAsBW,MAAM;;;;;;;;;;8BAWN,MAAM;;;;;;;;;;;;;+BAwBN,MAAM;;;;;;AAOjB;;;;;;;;;GASG;AAEH;IACE,8BAA8B;IAC9B,0BAIC;IAFC,6BAA6B;IAC7B,YADW,cAAc,CACA;CAE5B;2CAEU,MAAM;;;;;;AAOjB;;;;GAIG;AAEH;IACE,iCAAiC;IACjC,0BAIC;IAFC,gCAAgC;IAChC,eADW,iBAAiB,CACA;CAE/B;AAED;IACE,mDAAmD;IACnD,sEAIC;IAFC,qCAAqC;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B,MAAM;cACN,MAAM;gBACN,MAAM;gBACN,MAAM;;;;mBACN,UAAU;;;qBAqBV,4BAA4B;;;;mBAC5B,UAAU;;;;;;iBAuBV,MAAM;;;;eACN,MAAM;;;;iBACN,MAAM,EAAE;;;;;;iBAoBR,MAAM;;;;eACN,oBAAoB;;;;qBACpB,MAAM,EAAE;aACR,MAAM,EAAE;;;iBA8BR,iBAAiB;4BACjB,MAAM;8BACN,MAAM;6BACN,MAAM;;;aAKN,WAAW;mBACX,MAAM;iBACN,MAAM;gBACN,MAAM;;;;wBACN,MAAM;sBACN,mBAAmB,EAAE;;;sBAcrB,MAAM;wBACN,MAAM;2BACN,MAAM;yBACN,MAAM;4BACN,MAAM;yBACN,MAAM;4BACN,MAAM;8BACN,MAAM;4BACN,MAAM;wCACN,MAAM;kBACN,UAAU"}

9
types/image/parsers/parsers.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
/**
* Creates a new event of the given type with the specified data.
* @template T
* @param {string} type The event type.
* @param {T} data The event data.
* @return {CustomEvent<T>} The new event.
*/
export function createEvent<T>(type: string, data: T): CustomEvent<T>;
//# sourceMappingURL=parsers.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"parsers.d.ts","sourceRoot":"","sources":["../../../image/parsers/parsers.js"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,qCAJW,MAAM,2BAMhB"}

2
types/index.d.ts vendored
View file

@ -23,7 +23,7 @@ export type JpegStartOfFrame = import('./image/parsers/jpeg.js').JpegStartOfFram
export type JpegStartOfScan = import('./image/parsers/jpeg.js').JpegStartOfScan; export type JpegStartOfScan = import('./image/parsers/jpeg.js').JpegStartOfScan;
export { UnarchiveEvent, UnarchiveEventType, UnarchiveInfoEvent, UnarchiveErrorEvent, UnarchiveStartEvent, UnarchiveFinishEvent, UnarchiveProgressEvent, UnarchiveExtractEvent, Unarchiver, Unzipper, Unrarrer, Untarrer, getUnarchiver } from "./archive/decompress.js"; 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 { getFullMIMEString, getShortMIMEString } from "./codecs/codecs.js";
export { GifApplicationExtensionEvent, GifCommentExtensionEvent, GifGraphicControlExtensionEvent, GifHeaderEvent, GifLogicalScreenEvent, GifParseEventType, GifParser, GifPlainTextExtensionEvent, GifTableBasedImageEvent } from "./image/parsers/gif.js"; export { GifParseEventType, GifParser } from "./image/parsers/gif.js";
export { JpegApp0ExtensionEvent, JpegApp0MarkerEvent, JpegApp1ExifEvent, JpegComponentType, JpegDctType, JpegDefineHuffmanTableEvent, JpegDefineQuantizationTableEvent, JpegDensityUnits, JpegExtensionThumbnailFormat, JpegHuffmanTableType, JpegParseEventType, JpegParser, JpegSegmentType, JpegStartOfFrameEvent, JpegStartOfScanEvent } from "./image/parsers/jpeg.js"; export { JpegApp0ExtensionEvent, JpegApp0MarkerEvent, JpegApp1ExifEvent, JpegComponentType, JpegDctType, JpegDefineHuffmanTableEvent, JpegDefineQuantizationTableEvent, JpegDensityUnits, JpegExtensionThumbnailFormat, JpegHuffmanTableType, JpegParseEventType, JpegParser, JpegSegmentType, JpegStartOfFrameEvent, JpegStartOfScanEvent } from "./image/parsers/jpeg.js";
export { convertWebPtoPNG, convertWebPtoJPG } from "./image/webp-shim/webp-shim.js"; export { convertWebPtoPNG, convertWebPtoJPG } from "./image/webp-shim/webp-shim.js";
//# sourceMappingURL=index.d.ts.map //# sourceMappingURL=index.d.ts.map