mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[css-font-loading-module] Make FontFaceSet extend EventTarget and add FontFaceSetLoadEvent (#43396)
This commit is contained in:
parent
480921ca85
commit
2892d81ccb
@ -18,4 +18,12 @@ contexts.forEach(context => {
|
||||
const b: boolean = context.fonts.check("12px Example", "ß");
|
||||
const c: Promise<FontFace[]> = context.fonts.load("12px MyFont", "ß").then();
|
||||
const d: Promise<typeof context.fonts> = context.fonts.ready.then();
|
||||
const e: FontFaceSetLoadEvent = new FontFaceSetLoadEvent('loading', {fontfaces: []});
|
||||
context.fonts.addEventListener('loading', (evt) => {
|
||||
evt.fontfaces;
|
||||
});
|
||||
context.fonts.onloadingdone = (evt) => {
|
||||
evt.fontfaces;
|
||||
};
|
||||
context.fonts.dispatchEvent(e);
|
||||
});
|
||||
|
||||
30
types/css-font-loading-module/index.d.ts
vendored
30
types/css-font-loading-module/index.d.ts
vendored
@ -6,7 +6,6 @@
|
||||
export type FontFaceLoadStatus = 'unloaded' | 'loading' | 'loaded' | 'error';
|
||||
export type FontFaceSetLoadStatus = 'loading' | 'loaded';
|
||||
export type BinaryData = ArrayBuffer | ArrayBufferView;
|
||||
export type EventHandler = (event: Event) => void;
|
||||
|
||||
export interface FontFaceDescriptors {
|
||||
style?: string;
|
||||
@ -17,11 +16,27 @@ export interface FontFaceDescriptors {
|
||||
featureSettings?: string;
|
||||
}
|
||||
|
||||
export interface FontFaceSet extends Set<FontFace> {
|
||||
export interface FontFaceSetLoadEventInit extends EventInit {
|
||||
fontfaces?: FontFace[];
|
||||
}
|
||||
|
||||
export interface FontFaceSetEventMap {
|
||||
"loading": (this: FontFaceSet, event: FontFaceSetLoadEvent) => any;
|
||||
"loadingdone": (this: FontFaceSet, event: FontFaceSetLoadEvent) => any;
|
||||
"loadingerror": (this: FontFaceSet, event: FontFaceSetLoadEvent) => any;
|
||||
}
|
||||
|
||||
export interface FontFaceSet extends Set<FontFace>, EventTarget {
|
||||
// events for when loading state changes
|
||||
onloading: EventHandler;
|
||||
onloadingdone: EventHandler;
|
||||
onloadingerror: EventHandler;
|
||||
onloading: ((this: FontFaceSet, event: FontFaceSetLoadEvent) => any) | null;
|
||||
onloadingdone: ((this: FontFaceSet, event: FontFaceSetLoadEvent) => any) | null;
|
||||
onloadingerror: ((this: FontFaceSet, event: FontFaceSetLoadEvent) => any) | null;
|
||||
|
||||
// EventTarget
|
||||
addEventListener<K extends keyof FontFaceSetEventMap>(type: K, listener: FontFaceSetEventMap[K], options?: boolean | AddEventListenerOptions): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
removeEventListener<K extends keyof FontFaceSetEventMap>(type: K, listener: FontFaceSetEventMap[K], options?: boolean | EventListenerOptions): void;
|
||||
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
||||
|
||||
// check and start loads if appropriate
|
||||
// and fulfill promise when all loads complete
|
||||
@ -55,6 +70,11 @@ declare global {
|
||||
readonly loaded: Promise<FontFace>;
|
||||
}
|
||||
|
||||
class FontFaceSetLoadEvent extends Event {
|
||||
constructor(type: string, eventInitDict?: FontFaceSetLoadEventInit);
|
||||
readonly fontfaces: FontFace[];
|
||||
}
|
||||
|
||||
interface Document {
|
||||
fonts: FontFaceSet;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user