From 90da0812c37595aae5243e6712e70dcfef35f2c6 Mon Sep 17 00:00:00 2001 From: slikts Date: Tue, 11 Apr 2017 10:41:43 +0300 Subject: [PATCH] Add CSS Font Loading Module draft spec types --- .../css-font-loading-module-tests.ts | 14 +++++ types/css-font-loading-module/index.d.ts | 63 +++++++++++++++++++ types/css-font-loading-module/tsconfig.json | 23 +++++++ types/css-font-loading-module/tslint.json | 3 + 4 files changed, 103 insertions(+) create mode 100644 types/css-font-loading-module/css-font-loading-module-tests.ts create mode 100644 types/css-font-loading-module/index.d.ts create mode 100644 types/css-font-loading-module/tsconfig.json create mode 100644 types/css-font-loading-module/tslint.json diff --git a/types/css-font-loading-module/css-font-loading-module-tests.ts b/types/css-font-loading-module/css-font-loading-module-tests.ts new file mode 100644 index 0000000000..08fd976397 --- /dev/null +++ b/types/css-font-loading-module/css-font-loading-module-tests.ts @@ -0,0 +1,14 @@ +const font = new FontFace("Example", "url(...)", { + style: "normal", + weight: "400" +}); +font.load(); +font.loaded.then((fontFace: FontFace) => { + fontFace.status + fontFace.family +}, (fontFace: FontFace) => {}); + +const a: boolean = document.fonts.check("12px Example"); +const b: boolean = document.fonts.check("12px Example", "ß"); +const c: Promise = document.fonts.load("12px MyFont", "ß").then(); +const d: Promise = document.fonts.ready.then(); \ No newline at end of file diff --git a/types/css-font-loading-module/index.d.ts b/types/css-font-loading-module/index.d.ts new file mode 100644 index 0000000000..d458cfcd7b --- /dev/null +++ b/types/css-font-loading-module/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for CSS Font Loading Module Level 3 +// Project: https://drafts.csswg.org/css-font-loading/ +// Definitions by: slikts +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type FontFaceLoadStatus = 'unloaded' | 'loading' | 'loaded' | 'error' +type FontFaceSetLoadStatus = 'loading' | 'loaded' +type BinaryData = ArrayBuffer | ArrayBufferView +type EventHandler = (event: Event) => void + +interface FontFaceDescriptors { + style?: string + weight?: string + stretch?: string + unicodeRange?: string + variant?: string + featureSettings?: string +} + +interface FontFaceSet extends Set { + // events for when loading state changes + onloading: EventHandler + onloadingdone: EventHandler + onloadingerror: EventHandler + + // check and start loads if appropriate + // and fulfill promise when all loads complete + load(font: string, text?: string): Promise + // return whether all fonts in the fontlist are loaded + // (does not initiate load if not available) + check(font: string, text?: string): boolean + + // async notification that font loading and layout operations are done + readonly ready: Promise + + // loading state, "loading" while one or more fonts loading, "loaded" otherwise + readonly status: FontFaceSetLoadStatus +} + +declare global { + interface FontFace { + new (family: string, source: string | BinaryData, descriptors?: FontFaceDescriptors): FontFace + load(): Promise + + family: string + style: string + weight: string + stretch: string + unicodeRange: string + variant: string + featureSettings: string + readonly status: FontFaceLoadStatus + readonly loaded: Promise + } + + interface Document { + fonts: FontFaceSet + } + + var FontFace: FontFace +} + +export {} \ No newline at end of file diff --git a/types/css-font-loading-module/tsconfig.json b/types/css-font-loading-module/tsconfig.json new file mode 100644 index 0000000000..7037164a1f --- /dev/null +++ b/types/css-font-loading-module/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "css-font-loading-module-tests.ts" + ] +} \ No newline at end of file diff --git a/types/css-font-loading-module/tslint.json b/types/css-font-loading-module/tslint.json new file mode 100644 index 0000000000..f9e30021f4 --- /dev/null +++ b/types/css-font-loading-module/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +}