diff --git a/types/index.d.ts b/types/index.d.ts index 827593c09..4a353a76a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -50,8 +50,6 @@ */ declare module "jspdf" { - import construct = Reflect.construct; - export interface Annotation { type: "text" | "freetext" | "link"; title?: string; @@ -633,6 +631,20 @@ declare module "jspdf" { yStep?: number; } + export interface PubSub { + subscribe( + topic: string, + callback: (...args: any[]) => void, + once?: boolean + ): string; + unsubscribe(token: string): boolean; + publish(topic: string, ...args: any[]): void; + getTopics(): Record< + string, + Record void, boolean]> + >; + } + export class jsPDF { constructor(options?: jsPDFOptions); constructor( @@ -844,6 +856,7 @@ declare module "jspdf" { getVerticalCoordinateString(value: number): number; internal: { + events: PubSub; scaleFactor: number; pageSize: { width: number; diff --git a/types/jspdf-tests-node.ts b/types/jspdf-tests-node.ts index 7764d6625..6fa251c11 100644 --- a/types/jspdf-tests-node.ts +++ b/types/jspdf-tests-node.ts @@ -18,6 +18,17 @@ const { TilingPattern } = jspdf; +function pubsub() { + const doc = new jsPDF(); + const token = doc.internal.events.subscribe("topic", (a, b) => {}, true); + doc.internal.events.unsubscribe(token); + doc.internal.events.publish("topic", 1, "foo"); + const topics = doc.internal.events.getTopics(); + if (topics["topic"][token][1]) { + topics["topic"][token][0](1, "foo"); + } +} + function classes() { new GState({}); new TilingPattern([], 0, 0); diff --git a/types/jspdf-tests.ts b/types/jspdf-tests.ts index bf5d480e3..c3519b356 100644 --- a/types/jspdf-tests.ts +++ b/types/jspdf-tests.ts @@ -17,6 +17,17 @@ import { AcroFormTextField } from "jspdf"; +function pubsub() { + const doc = new jsPDF(); + const token = doc.internal.events.subscribe("topic", (a, b) => {}, true); + doc.internal.events.unsubscribe(token); + doc.internal.events.publish("topic", 1, "foo"); + const topics = doc.internal.events.getTopics(); + if (topics["topic"][token][1]) { + topics["topic"][token][0](1, "foo"); + } +} + function classes() { new GState({}); new TilingPattern([], 0, 0); diff --git a/types/tsconfig.json b/types/tsconfig.json index 2e9820f50..d7c9b9f90 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -8,5 +8,5 @@ "noEmit": true, "forceConsistentCasingInFileNames": true }, - "files": ["index.d.ts", "jspdf-tests.ts", "jspdf-tests.ts"] + "files": ["index.d.ts", "jspdf-tests.ts"] }