mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add CSS Font Loading Module draft spec types
This commit is contained in:
parent
14f8fb1b17
commit
90da0812c3
@ -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();
|
||||
63
types/css-font-loading-module/index.d.ts
vendored
Normal file
63
types/css-font-loading-module/index.d.ts
vendored
Normal 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 {}
|
||||
23
types/css-font-loading-module/tsconfig.json
Normal file
23
types/css-font-loading-module/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/css-font-loading-module/tslint.json
Normal file
3
types/css-font-loading-module/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user