Add CSS Font Loading Module draft spec types

This commit is contained in:
slikts 2017-04-11 10:41:43 +03:00
parent 14f8fb1b17
commit 90da0812c3
4 changed files with 103 additions and 0 deletions

View File

@ -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<FontFace[]> = document.fonts.load("12px MyFont", "ß").then();
const d: Promise<typeof document.fonts> = document.fonts.ready.then();

View File

@ -0,0 +1,63 @@
// Type definitions for CSS Font Loading Module Level 3
// Project: https://drafts.csswg.org/css-font-loading/
// Definitions by: slikts <https://github.com/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<FontFace> {
// 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<FontFace[]>
// 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<FontFaceSet>
// 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<FontFace>
family: string
style: string
weight: string
stretch: string
unicodeRange: string
variant: string
featureSettings: string
readonly status: FontFaceLoadStatus
readonly loaded: Promise<FontFace>
}
interface Document {
fonts: FontFaceSet
}
var FontFace: FontFace
}
export {}

View File

@ -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"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}