Add definitions for fontfaceobserver (#9453)

This commit is contained in:
Rand Scullard 2016-06-02 09:05:18 -04:00 committed by Masahiro Wakame
parent 9161d4fca9
commit 8ef4d9a7db
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,46 @@
/// <reference path="fontfaceobserver.d.ts" />
function test1() {
var font = new FontFaceObserver('My Family', {
weight: 400
});
font.load().then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available');
});
}
function test2() {
var font = new FontFaceObserver('My Family');
font.load('中国').then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available');
});
}
function test3() {
var font = new FontFaceObserver('My Family');
font.load(null, 5000).then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available after waiting 5 seconds');
});
}
function test4() {
var fontA = new FontFaceObserver('Family A');
var fontB = new FontFaceObserver('Family B');
fontA.load().then(function () {
console.log('Family A is available');
});
fontB.load().then(function () {
console.log('Family B is available');
});
}

View File

@ -0,0 +1 @@
--target ES6

33
fontfaceobserver/fontfaceobserver.d.ts vendored Normal file
View File

@ -0,0 +1,33 @@
// Type definitions for fontfaceobserver
// Project: https://github.com/bramstein/fontfaceobserver
// Definitions by: Rand Scullard <https://github.com/RandScullard>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace FontFaceObserver {
interface FontVariant {
weight?: number | string;
style?: string;
stretch?: string;
}
}
declare class FontFaceObserver {
/**
* Creates a new FontFaceObserver.
* @param fontFamilyName Name of the font family to observe.
* @param variant Description of the font variant to observe. If a property is not present it will default to normal.
*/
constructor(fontFamilyName: string, variant?: FontFaceObserver.FontVariant);
/**
* Starts observing the loading of the specified font. Immediately returns a new Promise that resolves when the font is available and rejected when the font is not available.
* @param testString If your font doesn't contain latin characters you can pass a custom test string.
* @param timeout The default timeout for giving up on font loading is 3 seconds. You can increase or decrease this by passing a number of milliseconds.
*/
load(testString?: string, timeout?: number): Promise<void>;
}
declare module "fontfaceobserver" {
export = FontFaceObserver;
}