@flighthq/font 0.5.1-next.799.62ef0c7 → 0.5.1-next.903.f434bc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/_fontFaceLoad.d.ts +5 -5
- package/dist/_fontFaceLoad.d.ts.map +1 -1
- package/dist/_fontFaceLoad.js +10 -11
- package/dist/_fontFaceLoad.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -1
- package/dist/contract.js.map +1 -1
- package/dist/fontResource.d.ts +2 -1
- package/dist/fontResource.d.ts.map +1 -1
- package/dist/fontResource.js +8 -2
- package/dist/fontResource.js.map +1 -1
- package/dist/fontResourceFrom.d.ts +5 -21
- package/dist/fontResourceFrom.d.ts.map +1 -1
- package/dist/fontResourceFrom.js +8 -24
- package/dist/fontResourceFrom.js.map +1 -1
- package/dist/fontStatus.d.ts +3 -2
- package/dist/fontStatus.d.ts.map +1 -1
- package/dist/fontStatus.js +4 -5
- package/dist/fontStatus.js.map +1 -1
- package/dist/glyphOutlineSource.d.ts +2 -1
- package/dist/glyphOutlineSource.d.ts.map +1 -1
- package/dist/glyphOutlineSource.js +21 -18
- package/dist/glyphOutlineSource.js.map +1 -1
- package/package.json +4 -4
- package/src/_fontFaceLoad.test.ts +11 -9
- package/src/fontResourceFrom.test.ts +22 -24
- package/src/fontStatus.test.ts +21 -23
- package/dist/fontLoading.d.ts +0 -8
- package/dist/fontLoading.d.ts.map +0 -1
- package/dist/fontLoading.js +0 -47
- package/dist/fontLoading.js.map +0 -1
- package/src/fontLoading.test.ts +0 -165
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/font`. The `@flighth
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/font@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/font@0.5.1-next.903.f434bc2](https://github.com/flighthq/flight/tree/f434bc233778d75aeea61995df3a8cfaec459a85/packages/font)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/f434bc233778d75aeea61995df3a8cfaec459a85/LICENSE.md)
|
package/dist/_fontFaceLoad.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FontUrl } from '@flighthq/types/contract';
|
|
2
|
-
export declare function _loadFontFaceFromBytes(family: string, bytes: Uint8Array): Promise<FontFace>;
|
|
3
|
-
export declare function _loadFontFaceFromUrl(family: string, url: string): Promise<FontFace>;
|
|
4
|
-
export declare function _loadFontFaceFromUrls(family: string, sources: readonly FontUrl[]): Promise<FontFace>;
|
|
5
|
-
export declare function _loadFontFacesFromName(family: string): Promise<FontFace[]>;
|
|
1
|
+
import type { FontLoadingBackend, FontUrl } from '@flighthq/types/contract';
|
|
2
|
+
export declare function _loadFontFaceFromBytes(backend: Readonly<FontLoadingBackend>, family: string, bytes: Uint8Array): Promise<FontFace>;
|
|
3
|
+
export declare function _loadFontFaceFromUrl(backend: Readonly<FontLoadingBackend>, family: string, url: string): Promise<FontFace>;
|
|
4
|
+
export declare function _loadFontFaceFromUrls(backend: Readonly<FontLoadingBackend>, family: string, sources: readonly FontUrl[]): Promise<FontFace>;
|
|
5
|
+
export declare function _loadFontFacesFromName(backend: Readonly<FontLoadingBackend>, family: string): Promise<FontFace[]>;
|
|
6
6
|
//# sourceMappingURL=_fontFaceLoad.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_fontFaceLoad.d.ts","sourceRoot":"","sources":["../src/_fontFaceLoad.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"_fontFaceLoad.d.ts","sourceRoot":"","sources":["../src/_fontFaceLoad.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAK5E,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,QAAQ,CAAC,CAGnB;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,QAAQ,CAAC,CAEnB;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,OAAO,EAAE,GAC1B,OAAO,CAAC,QAAQ,CAAC,CAQnB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAEjH"}
|
package/dist/_fontFaceLoad.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { inferFontFormatFromUrl } from './fontFormat';
|
|
2
|
-
import { getFontLoadingBackend } from './fontLoading';
|
|
3
2
|
import { getFontShorthand } from './fontShorthand';
|
|
4
|
-
export async function _loadFontFaceFromBytes(family, bytes) {
|
|
3
|
+
export async function _loadFontFaceFromBytes(backend, family, bytes) {
|
|
5
4
|
const source = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
6
|
-
return loadAndRegisterFontFace(family, source);
|
|
5
|
+
return loadAndRegisterFontFace(backend, family, source);
|
|
7
6
|
}
|
|
8
|
-
export function _loadFontFaceFromUrl(family, url) {
|
|
9
|
-
return loadAndRegisterFontFace(family, `url(${url})`);
|
|
7
|
+
export function _loadFontFaceFromUrl(backend, family, url) {
|
|
8
|
+
return loadAndRegisterFontFace(backend, family, `url(${url})`);
|
|
10
9
|
}
|
|
11
|
-
export function _loadFontFaceFromUrls(family, sources) {
|
|
10
|
+
export function _loadFontFaceFromUrls(backend, family, sources) {
|
|
12
11
|
const source = sources
|
|
13
12
|
.map(({ url, format }) => {
|
|
14
13
|
const resolvedFormat = format ?? inferFontFormatFromUrl(url);
|
|
15
14
|
return resolvedFormat !== null ? `url(${url}) format('${resolvedFormat}')` : `url(${url})`;
|
|
16
15
|
})
|
|
17
16
|
.join(', ');
|
|
18
|
-
return loadAndRegisterFontFace(family, source);
|
|
17
|
+
return loadAndRegisterFontFace(backend, family, source);
|
|
19
18
|
}
|
|
20
|
-
export function _loadFontFacesFromName(family) {
|
|
21
|
-
return
|
|
19
|
+
export function _loadFontFacesFromName(backend, family) {
|
|
20
|
+
return backend.loadFontFaces(getFontShorthand(family));
|
|
22
21
|
}
|
|
23
|
-
async function loadAndRegisterFontFace(family, source) {
|
|
22
|
+
async function loadAndRegisterFontFace(backend, family, source) {
|
|
24
23
|
const face = new FontFace(family, source);
|
|
25
24
|
await face.load();
|
|
26
|
-
|
|
25
|
+
backend.addFontFace(face);
|
|
27
26
|
return face;
|
|
28
27
|
}
|
|
29
28
|
//# sourceMappingURL=_fontFaceLoad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_fontFaceLoad.js","sourceRoot":"","sources":["../src/_fontFaceLoad.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"_fontFaceLoad.js","sourceRoot":"","sources":["../src/_fontFaceLoad.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,CA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EAAE,CAAC;IAClB,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './fontFormat';
|
|
2
|
-
export * from './fontLoading';
|
|
3
2
|
export * from './fontResource';
|
|
4
3
|
export * from './fontResourceFrom';
|
|
5
4
|
export * from './fontShorthand';
|
|
6
5
|
export * from './fontStatus';
|
|
7
6
|
export * from './glyphOutlineSource';
|
|
7
|
+
export { initializeGlyphRasterizerBackendFromGlyphOutlineSource } from './glyphOutlineSource';
|
|
8
|
+
export { initializeFontResource } from './fontResource';
|
|
8
9
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,sDAAsD,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './fontFormat';
|
|
2
|
-
export * from './fontLoading';
|
|
3
2
|
export * from './fontResource';
|
|
4
3
|
export * from './fontResourceFrom';
|
|
5
4
|
export * from './fontShorthand';
|
|
6
5
|
export * from './fontStatus';
|
|
7
6
|
export * from './glyphOutlineSource';
|
|
7
|
+
export { initializeGlyphRasterizerBackendFromGlyphOutlineSource } from './glyphOutlineSource';
|
|
8
|
+
export { initializeFontResource } from './fontResource';
|
|
8
9
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,sDAAsD,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/fontResource.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { FontResource } from '@flighthq/types/contract';
|
|
1
|
+
import type { FontResource, EntityConstruction } from '@flighthq/types/contract';
|
|
2
2
|
export declare function createFontResource(family: string): FontResource;
|
|
3
|
+
export declare function initializeFontResource(out: EntityConstruction<FontResource>, family: string): void;
|
|
3
4
|
//# sourceMappingURL=fontResource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontResource.d.ts","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"fontResource.d.ts","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEjF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAI/D;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,kBAAkB,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAGlG"}
|
package/dist/fontResource.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
export function createFontResource(family) {
|
|
3
|
-
|
|
3
|
+
const out = allocateEntity();
|
|
4
|
+
initializeFontResource(out, family);
|
|
5
|
+
return finishEntity(out);
|
|
6
|
+
}
|
|
7
|
+
export function initializeFontResource(out, family) {
|
|
8
|
+
out.family = family;
|
|
9
|
+
out.face = null;
|
|
4
10
|
}
|
|
5
11
|
//# sourceMappingURL=fontResource.js.map
|
package/dist/fontResource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontResource.js","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"fontResource.js","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzE,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,MAAM,GAAG,GAAG,cAAc,EAAgB,CAAC;IAC3C,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAqC,EAAE,MAAc;IAC1F,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;AAClB,CAAC"}
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
import type { FontResource, FontUrl } from '@flighthq/types/contract';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function loadFontResourceFromBytes(out: FontResource, bytes: Uint8Array): Promise<FontResource>;
|
|
7
|
-
/**
|
|
8
|
-
* Looks up an existing family and attaches its first face to `out`. If the lookup rejects or returns no
|
|
9
|
-
* faces, `out.face` retains its previous value.
|
|
10
|
-
*/
|
|
11
|
-
export declare function loadFontResourceFromName(out: FontResource): Promise<FontResource>;
|
|
12
|
-
/**
|
|
13
|
-
* Loads a face from one URL into `out`. If loading rejects, no face is registered and `out.face`
|
|
14
|
-
* retains its previous value, so a failed reload does not blank a working resource.
|
|
15
|
-
*/
|
|
16
|
-
export declare function loadFontResourceFromUrl(out: FontResource, url: string): Promise<FontResource>;
|
|
17
|
-
/**
|
|
18
|
-
* Loads a face from fallback URLs into `out`. If loading rejects, no face is registered and `out.face`
|
|
19
|
-
* retains its previous value, so a failed reload does not blank a working resource.
|
|
20
|
-
*/
|
|
21
|
-
export declare function loadFontResourceFromUrls(out: FontResource, sources: FontUrl[]): Promise<FontResource>;
|
|
1
|
+
import type { FontLoadingBackend, FontResource, FontUrl } from '@flighthq/types/contract';
|
|
2
|
+
export declare function loadFontResourceFromBytes(backend: Readonly<FontLoadingBackend>, out: FontResource, bytes: Uint8Array): Promise<FontResource>;
|
|
3
|
+
export declare function loadFontResourceFromName(backend: Readonly<FontLoadingBackend>, out: FontResource): Promise<FontResource>;
|
|
4
|
+
export declare function loadFontResourceFromUrl(backend: Readonly<FontLoadingBackend>, out: FontResource, url: string): Promise<FontResource>;
|
|
5
|
+
export declare function loadFontResourceFromUrls(backend: Readonly<FontLoadingBackend>, out: FontResource, sources: FontUrl[]): Promise<FontResource>;
|
|
22
6
|
//# sourceMappingURL=fontResourceFrom.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontResourceFrom.d.ts","sourceRoot":"","sources":["../src/fontResourceFrom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"fontResourceFrom.d.ts","sourceRoot":"","sources":["../src/fontResourceFrom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAS1F,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,YAAY,CAAC,CAIvB;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACrC,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,YAAY,CAAC,CAIvB"}
|
package/dist/fontResourceFrom.js
CHANGED
|
@@ -1,38 +1,22 @@
|
|
|
1
1
|
import { _loadFontFaceFromBytes, _loadFontFaceFromUrl, _loadFontFaceFromUrls, _loadFontFacesFromName, } from './_fontFaceLoad';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* its previous value, so a failed reload does not blank a working resource.
|
|
5
|
-
*/
|
|
6
|
-
export async function loadFontResourceFromBytes(out, bytes) {
|
|
7
|
-
const face = await _loadFontFaceFromBytes(out.family, bytes);
|
|
2
|
+
export async function loadFontResourceFromBytes(backend, out, bytes) {
|
|
3
|
+
const face = await _loadFontFaceFromBytes(backend, out.family, bytes);
|
|
8
4
|
out.face = face;
|
|
9
5
|
return out;
|
|
10
6
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* faces, `out.face` retains its previous value.
|
|
14
|
-
*/
|
|
15
|
-
export async function loadFontResourceFromName(out) {
|
|
16
|
-
const faces = await _loadFontFacesFromName(out.family);
|
|
7
|
+
export async function loadFontResourceFromName(backend, out) {
|
|
8
|
+
const faces = await _loadFontFacesFromName(backend, out.family);
|
|
17
9
|
if (faces.length > 0)
|
|
18
10
|
out.face = faces[0];
|
|
19
11
|
return out;
|
|
20
12
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* retains its previous value, so a failed reload does not blank a working resource.
|
|
24
|
-
*/
|
|
25
|
-
export async function loadFontResourceFromUrl(out, url) {
|
|
26
|
-
const face = await _loadFontFaceFromUrl(out.family, url);
|
|
13
|
+
export async function loadFontResourceFromUrl(backend, out, url) {
|
|
14
|
+
const face = await _loadFontFaceFromUrl(backend, out.family, url);
|
|
27
15
|
out.face = face;
|
|
28
16
|
return out;
|
|
29
17
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* retains its previous value, so a failed reload does not blank a working resource.
|
|
33
|
-
*/
|
|
34
|
-
export async function loadFontResourceFromUrls(out, sources) {
|
|
35
|
-
const face = await _loadFontFaceFromUrls(out.family, sources);
|
|
18
|
+
export async function loadFontResourceFromUrls(backend, out, sources) {
|
|
19
|
+
const face = await _loadFontFaceFromUrls(backend, out.family, sources);
|
|
36
20
|
out.face = face;
|
|
37
21
|
return out;
|
|
38
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontResourceFrom.js","sourceRoot":"","sources":["../src/fontResourceFrom.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB
|
|
1
|
+
{"version":3,"file":"fontResourceFrom.js","sourceRoot":"","sources":["../src/fontResourceFrom.ts"],"names":[],"mappings":"AAEA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
|
1
|
+
import type { FontLoadingBackend } from '@flighthq/types/contract';
|
|
2
|
+
export declare function isFontLoaded(backend: Readonly<FontLoadingBackend>, family: string, style?: string): boolean;
|
|
3
|
+
export declare function whenFontsReady(backend: Readonly<FontLoadingBackend>): Promise<void>;
|
|
3
4
|
//# sourceMappingURL=fontStatus.d.ts.map
|
package/dist/fontStatus.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontStatus.d.ts","sourceRoot":"","sources":["../src/fontStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fontStatus.d.ts","sourceRoot":"","sources":["../src/fontStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE,wBAAgB,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAE3G;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzF"}
|
package/dist/fontStatus.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getFontLoadingBackend } from './fontLoading';
|
|
2
1
|
import { getFontShorthand } from './fontShorthand';
|
|
3
|
-
export function isFontLoaded(family, style) {
|
|
4
|
-
return
|
|
2
|
+
export function isFontLoaded(backend, family, style) {
|
|
3
|
+
return backend.checkFontFace(getFontShorthand(family, style));
|
|
5
4
|
}
|
|
6
|
-
export async function whenFontsReady() {
|
|
7
|
-
await
|
|
5
|
+
export async function whenFontsReady(backend) {
|
|
6
|
+
await backend.whenReady();
|
|
8
7
|
}
|
|
9
8
|
//# sourceMappingURL=fontStatus.js.map
|
package/dist/fontStatus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontStatus.js","sourceRoot":"","sources":["../src/fontStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fontStatus.js","sourceRoot":"","sources":["../src/fontStatus.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,UAAU,YAAY,CAAC,OAAqC,EAAE,MAAc,EAAE,KAAc;IAChG,OAAO,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAqC;IACxE,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Entity, GlyphOutlineSource, GlyphRasterizerBackend } from '@flighthq/types/contract';
|
|
1
|
+
import type { Entity, EntityConstruction, GlyphOutlineSource, GlyphRasterizerBackend } from '@flighthq/types/contract';
|
|
2
2
|
export declare function createGlyphRasterizerBackendFromGlyphOutlineSource(source: GlyphOutlineSource): GlyphRasterizerBackend & Entity;
|
|
3
|
+
export declare function initializeGlyphRasterizerBackendFromGlyphOutlineSource(out: EntityConstruction<GlyphRasterizerBackend & Entity>, source: GlyphOutlineSource): void;
|
|
3
4
|
//# sourceMappingURL=glyphOutlineSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glyphOutlineSource.d.ts","sourceRoot":"","sources":["../src/glyphOutlineSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,
|
|
1
|
+
{"version":3,"file":"glyphOutlineSource.d.ts","sourceRoot":"","sources":["../src/glyphOutlineSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,kBAAkB,EAElB,kBAAkB,EAGlB,sBAAsB,EAEvB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,kDAAkD,CAChE,MAAM,EAAE,kBAAkB,GACzB,sBAAsB,GAAG,MAAM,CAIjC;AAOD,wBAAgB,sDAAsD,CACpE,GAAG,EAAE,kBAAkB,CAAC,sBAAsB,GAAG,MAAM,CAAC,EACxD,MAAM,EAAE,kBAAkB,GACzB,IAAI,CAcN"}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { createPath, flattenPath, getPathBounds } from '@flighthq/path/contract';
|
|
3
|
+
export function createGlyphRasterizerBackendFromGlyphOutlineSource(source) {
|
|
4
|
+
const out = allocateEntity();
|
|
5
|
+
initializeGlyphRasterizerBackendFromGlyphOutlineSource(out, source);
|
|
6
|
+
return finishEntity(out);
|
|
7
|
+
}
|
|
3
8
|
// Adapts an index-keyed vector font into the codepoint-keyed rasterizer consumed by glyphatlas. The
|
|
4
9
|
// adapter is bound to one source, so callers can install it on one GlyphAtlas through
|
|
5
10
|
// `GlyphAtlasOptions.rasterizerBackend` without changing the process-wide backend. Rasterization is a
|
|
6
11
|
// portable 4x4 coverage scan over flattened contours: it needs no DOM/canvas and therefore works for
|
|
7
12
|
// imported fonts in browser, worker, native-host, and headless environments alike.
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
});
|
|
13
|
+
export function initializeGlyphRasterizerBackendFromGlyphOutlineSource(out, source) {
|
|
14
|
+
out.measureMetrics = (options) => {
|
|
15
|
+
const metrics = source.getGlyphOutlineMetrics();
|
|
16
|
+
const scale = resolveGlyphOutlineScale(metrics.unitsPerEm, options.fontSize);
|
|
17
|
+
if (scale === null)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
ascent: metrics.ascent * scale,
|
|
21
|
+
descent: metrics.descent * scale,
|
|
22
|
+
lineGap: metrics.lineGap * scale,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
out.rasterize = (codePoint, options) => {
|
|
26
|
+
return rasterizeGlyphOutlineSource(source, codePoint, options);
|
|
27
|
+
};
|
|
25
28
|
}
|
|
26
29
|
function rasterizeGlyphOutlineSource(source, codePoint, options) {
|
|
27
30
|
const glyphIndex = source.getGlyphOutlineIndexForCodePoint(codePoint);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glyphOutlineSource.js","sourceRoot":"","sources":["../src/glyphOutlineSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"glyphOutlineSource.js","sourceRoot":"","sources":["../src/glyphOutlineSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAYjF,MAAM,UAAU,kDAAkD,CAChE,MAA0B;IAE1B,MAAM,GAAG,GAAG,cAAc,EAAmC,CAAC;IAC9D,sDAAsD,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,oGAAoG;AACpG,sFAAsF;AACtF,sGAAsG;AACtG,qGAAqG;AACrG,mFAAmF;AACnF,MAAM,UAAU,sDAAsD,CACpE,GAAwD,EACxD,MAA0B;IAE1B,GAAG,CAAC,cAAc,GAAG,CAAC,OAAO,EAAuB,EAAE;QACpD,MAAM,OAAO,GAAG,MAAM,CAAC,sBAAsB,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,wBAAwB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7E,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI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ACZ,KAAK,GAAG,GAAG,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,wBAAwB,CAAC,UAAkB,EAAE,QAAgB;IACpE,IAAI,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACpH,OAAO,QAAQ,GAAG,UAAU,CAAC;AAC/B,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,mBAAmB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/font",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.903.f434bc2",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/path": "0.5.1-next.
|
|
43
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.903.f434bc2",
|
|
42
|
+
"@flighthq/path": "0.5.1-next.903.f434bc2",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.903.f434bc2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
_loadFontFaceFromUrls,
|
|
7
7
|
_loadFontFacesFromName,
|
|
8
8
|
} from './_fontFaceLoad';
|
|
9
|
-
import { resetFontLoadingBackendForTest, setFontLoadingBackend } from './fontLoading';
|
|
10
9
|
|
|
11
10
|
interface FontFaceConstruction {
|
|
12
11
|
family: string;
|
|
@@ -17,6 +16,7 @@ interface FontFaceConstruction {
|
|
|
17
16
|
let constructions: FontFaceConstruction[];
|
|
18
17
|
let addMock = vi.fn<(face: FontFace) => void>();
|
|
19
18
|
let loadMock = vi.fn<(shorthand: string) => Promise<FontFace[]>>();
|
|
19
|
+
let backend: FontLoadingBackend;
|
|
20
20
|
|
|
21
21
|
class MockFontFace {
|
|
22
22
|
load = vi.fn().mockResolvedValue(undefined);
|
|
@@ -30,17 +30,15 @@ beforeEach(() => {
|
|
|
30
30
|
addMock = vi.fn<(face: FontFace) => void>();
|
|
31
31
|
loadMock = vi.fn<(shorthand: string) => Promise<FontFace[]>>().mockResolvedValue([]);
|
|
32
32
|
vi.stubGlobal('FontFace', MockFontFace);
|
|
33
|
-
|
|
33
|
+
backend = {
|
|
34
34
|
addFontFace: addMock,
|
|
35
35
|
checkFontFace: vi.fn<(shorthand: string) => boolean>().mockReturnValue(false),
|
|
36
36
|
loadFontFaces: loadMock,
|
|
37
37
|
whenReady: vi.fn<() => Promise<void>>().mockResolvedValue(undefined),
|
|
38
38
|
};
|
|
39
|
-
setFontLoadingBackend(backend);
|
|
40
39
|
});
|
|
41
40
|
|
|
42
41
|
afterEach(() => {
|
|
43
|
-
resetFontLoadingBackendForTest();
|
|
44
42
|
vi.unstubAllGlobals();
|
|
45
43
|
vi.restoreAllMocks();
|
|
46
44
|
});
|
|
@@ -48,7 +46,7 @@ afterEach(() => {
|
|
|
48
46
|
describe('_loadFontFaceFromBytes', () => {
|
|
49
47
|
it('loads and registers a face using only the bytes inside the supplied view', async () => {
|
|
50
48
|
const backing = new Uint8Array([1, 2, 3, 4, 5, 6]);
|
|
51
|
-
const face = await _loadFontFaceFromBytes('Family', backing.subarray(1, 5));
|
|
49
|
+
const face = await _loadFontFaceFromBytes(backend, 'Family', backing.subarray(1, 5));
|
|
52
50
|
|
|
53
51
|
expect(face).toBe(constructions[0].instance);
|
|
54
52
|
expect(new Uint8Array(constructions[0].source as ArrayBuffer)).toEqual(new Uint8Array([2, 3, 4, 5]));
|
|
@@ -59,7 +57,7 @@ describe('_loadFontFaceFromBytes', () => {
|
|
|
59
57
|
|
|
60
58
|
describe('_loadFontFaceFromUrl', () => {
|
|
61
59
|
it('loads and registers the single URL source', async () => {
|
|
62
|
-
await _loadFontFaceFromUrl('Family', 'font.woff2');
|
|
60
|
+
await _loadFontFaceFromUrl(backend, 'Family', 'font.woff2');
|
|
63
61
|
expect(constructions[0].source).toBe('url(font.woff2)');
|
|
64
62
|
expect(addMock).toHaveBeenCalledWith(constructions[0].instance);
|
|
65
63
|
});
|
|
@@ -67,7 +65,11 @@ describe('_loadFontFaceFromUrl', () => {
|
|
|
67
65
|
|
|
68
66
|
describe('_loadFontFaceFromUrls', () => {
|
|
69
67
|
it('composes explicit, inferred, and absent format hints once for both public loader families', async () => {
|
|
70
|
-
await _loadFontFaceFromUrls('Family', [
|
|
68
|
+
await _loadFontFaceFromUrls(backend, 'Family', [
|
|
69
|
+
{ url: 'a.woff2', format: 'woff2' },
|
|
70
|
+
{ url: 'b.ttf' },
|
|
71
|
+
{ url: 'c.bin' },
|
|
72
|
+
]);
|
|
71
73
|
|
|
72
74
|
expect(constructions[0].source).toBe("url(a.woff2) format('woff2'), url(b.ttf) format('truetype'), url(c.bin)");
|
|
73
75
|
});
|
|
@@ -82,7 +84,7 @@ describe('_loadFontFaceFromUrls', () => {
|
|
|
82
84
|
}),
|
|
83
85
|
);
|
|
84
86
|
|
|
85
|
-
await expect(_loadFontFaceFromUrls('Family', [{ url: 'font.woff2' }])).rejects.toThrow('bad font');
|
|
87
|
+
await expect(_loadFontFaceFromUrls(backend, 'Family', [{ url: 'font.woff2' }])).rejects.toThrow('bad font');
|
|
86
88
|
expect(addMock).not.toHaveBeenCalled();
|
|
87
89
|
});
|
|
88
90
|
});
|
|
@@ -92,7 +94,7 @@ describe('_loadFontFacesFromName', () => {
|
|
|
92
94
|
const faces = [{ family: 'Family' } as unknown as FontFace];
|
|
93
95
|
loadMock.mockResolvedValue(faces);
|
|
94
96
|
|
|
95
|
-
await expect(_loadFontFacesFromName("Family's Name")).resolves.toBe(faces);
|
|
97
|
+
await expect(_loadFontFacesFromName(backend, "Family's Name")).resolves.toBe(faces);
|
|
96
98
|
expect(loadMock).toHaveBeenCalledWith("1em 'Family\\'s Name'");
|
|
97
99
|
});
|
|
98
100
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { FontLoadingBackend } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
|
-
import { resetFontLoadingBackendForTest, setFontLoadingBackend } from './fontLoading';
|
|
4
3
|
import { createFontResource } from './fontResource';
|
|
5
4
|
import {
|
|
6
5
|
loadFontResourceFromBytes,
|
|
@@ -18,6 +17,7 @@ interface FontFaceConstruction {
|
|
|
18
17
|
let constructions: FontFaceConstruction[];
|
|
19
18
|
let addMock = vi.fn<(face: FontFace) => void>();
|
|
20
19
|
let loadMock = vi.fn<(shorthand: string) => Promise<FontFace[]>>();
|
|
20
|
+
let backend: FontLoadingBackend;
|
|
21
21
|
|
|
22
22
|
class MockFontFace {
|
|
23
23
|
load = vi.fn().mockResolvedValue(undefined);
|
|
@@ -31,17 +31,15 @@ beforeEach(() => {
|
|
|
31
31
|
addMock = vi.fn<(face: FontFace) => void>();
|
|
32
32
|
loadMock = vi.fn<(shorthand: string) => Promise<FontFace[]>>().mockResolvedValue([]);
|
|
33
33
|
vi.stubGlobal('FontFace', MockFontFace);
|
|
34
|
-
|
|
34
|
+
backend = {
|
|
35
35
|
addFontFace: addMock,
|
|
36
36
|
checkFontFace: vi.fn<(shorthand: string) => boolean>().mockReturnValue(false),
|
|
37
37
|
loadFontFaces: loadMock,
|
|
38
38
|
whenReady: vi.fn<() => Promise<void>>().mockResolvedValue(undefined),
|
|
39
39
|
};
|
|
40
|
-
setFontLoadingBackend(backend);
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
afterEach(() => {
|
|
44
|
-
resetFontLoadingBackendForTest();
|
|
45
43
|
vi.unstubAllGlobals();
|
|
46
44
|
vi.restoreAllMocks();
|
|
47
45
|
});
|
|
@@ -49,7 +47,7 @@ afterEach(() => {
|
|
|
49
47
|
describe('loadFontResourceFromBytes', () => {
|
|
50
48
|
it('constructs the face under the resource family, loads it, and registers it', async () => {
|
|
51
49
|
const resource = createFontResource('TestFont');
|
|
52
|
-
const result = await loadFontResourceFromBytes(resource, new Uint8Array(8));
|
|
50
|
+
const result = await loadFontResourceFromBytes(backend, resource, new Uint8Array(8));
|
|
53
51
|
expect(result).toBe(resource);
|
|
54
52
|
expect(constructions).toHaveLength(1);
|
|
55
53
|
expect(constructions[0].family).toBe('TestFont');
|
|
@@ -60,7 +58,7 @@ describe('loadFontResourceFromBytes', () => {
|
|
|
60
58
|
|
|
61
59
|
it('slices only the view bytes out of a larger backing buffer', async () => {
|
|
62
60
|
const backing = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
63
|
-
await loadFontResourceFromBytes(createFontResource('TestFont'), backing.subarray(2, 6));
|
|
61
|
+
await loadFontResourceFromBytes(backend, createFontResource('TestFont'), backing.subarray(2, 6));
|
|
64
62
|
expect(new Uint8Array(constructions[0].source as ArrayBuffer)).toEqual(new Uint8Array([3, 4, 5, 6]));
|
|
65
63
|
});
|
|
66
64
|
|
|
@@ -74,14 +72,14 @@ describe('loadFontResourceFromBytes', () => {
|
|
|
74
72
|
return failing;
|
|
75
73
|
}),
|
|
76
74
|
);
|
|
77
|
-
await expect(loadFontResourceFromBytes(resource, new Uint8Array(4))).rejects.toThrow('bad font');
|
|
75
|
+
await expect(loadFontResourceFromBytes(backend, resource, new Uint8Array(4))).rejects.toThrow('bad font');
|
|
78
76
|
expect(addMock).not.toHaveBeenCalled();
|
|
79
77
|
expect(resource.face).toBeNull();
|
|
80
78
|
});
|
|
81
79
|
|
|
82
80
|
it('leaves a previously loaded face attached when a reload fails', async () => {
|
|
83
81
|
const resource = createFontResource('TestFont');
|
|
84
|
-
await loadFontResourceFromBytes(resource, new Uint8Array(4));
|
|
82
|
+
await loadFontResourceFromBytes(backend, resource, new Uint8Array(4));
|
|
85
83
|
const loaded = resource.face;
|
|
86
84
|
expect(loaded).not.toBeNull();
|
|
87
85
|
|
|
@@ -93,7 +91,7 @@ describe('loadFontResourceFromBytes', () => {
|
|
|
93
91
|
return failing;
|
|
94
92
|
}),
|
|
95
93
|
);
|
|
96
|
-
await expect(loadFontResourceFromBytes(resource, new Uint8Array(4))).rejects.toThrow('boom');
|
|
94
|
+
await expect(loadFontResourceFromBytes(backend, resource, new Uint8Array(4))).rejects.toThrow('boom');
|
|
97
95
|
expect(resource.face).toBe(loaded);
|
|
98
96
|
expect(addMock).toHaveBeenCalledTimes(1);
|
|
99
97
|
});
|
|
@@ -101,12 +99,12 @@ describe('loadFontResourceFromBytes', () => {
|
|
|
101
99
|
|
|
102
100
|
describe('loadFontResourceFromName', () => {
|
|
103
101
|
it('queries the family via the escaped font shorthand', async () => {
|
|
104
|
-
await loadFontResourceFromName(createFontResource('MyFont'));
|
|
102
|
+
await loadFontResourceFromName(backend, createFontResource('MyFont'));
|
|
105
103
|
expect(loadMock).toHaveBeenCalledWith("1em 'MyFont'");
|
|
106
104
|
});
|
|
107
105
|
|
|
108
106
|
it('escapes a single quote in the family name so the shorthand stays valid', async () => {
|
|
109
|
-
await loadFontResourceFromName(createFontResource("Josh's Font"));
|
|
107
|
+
await loadFontResourceFromName(backend, createFontResource("Josh's Font"));
|
|
110
108
|
expect(loadMock).toHaveBeenCalledWith("1em 'Josh\\'s Font'");
|
|
111
109
|
});
|
|
112
110
|
|
|
@@ -115,34 +113,34 @@ describe('loadFontResourceFromName', () => {
|
|
|
115
113
|
const second = { family: 'second' } as unknown as FontFace;
|
|
116
114
|
loadMock.mockResolvedValue([first, second]);
|
|
117
115
|
const resource = createFontResource('TestFont');
|
|
118
|
-
const result = await loadFontResourceFromName(resource);
|
|
116
|
+
const result = await loadFontResourceFromName(backend, resource);
|
|
119
117
|
expect(result).toBe(resource);
|
|
120
118
|
expect(resource.face).toBe(first);
|
|
121
119
|
});
|
|
122
120
|
|
|
123
121
|
it('leaves face null when no registered faces are found', async () => {
|
|
124
122
|
const resource = createFontResource('UnknownFont');
|
|
125
|
-
await loadFontResourceFromName(resource);
|
|
123
|
+
await loadFontResourceFromName(backend, resource);
|
|
126
124
|
expect(resource.face).toBeNull();
|
|
127
125
|
});
|
|
128
126
|
|
|
129
127
|
it('registers nothing — a name lookup finds an existing face rather than adding one', async () => {
|
|
130
128
|
loadMock.mockResolvedValue([{ family: 'x' } as unknown as FontFace]);
|
|
131
|
-
await loadFontResourceFromName(createFontResource('TestFont'));
|
|
129
|
+
await loadFontResourceFromName(backend, createFontResource('TestFont'));
|
|
132
130
|
expect(addMock).not.toHaveBeenCalled();
|
|
133
131
|
expect(constructions).toHaveLength(0);
|
|
134
132
|
});
|
|
135
133
|
|
|
136
134
|
it('propagates a lookup failure', async () => {
|
|
137
135
|
loadMock.mockRejectedValue(new Error('no such font'));
|
|
138
|
-
await expect(loadFontResourceFromName(createFontResource('MyFont'))).rejects.toThrow('no such font');
|
|
136
|
+
await expect(loadFontResourceFromName(backend, createFontResource('MyFont'))).rejects.toThrow('no such font');
|
|
139
137
|
});
|
|
140
138
|
});
|
|
141
139
|
|
|
142
140
|
describe('loadFontResourceFromUrl', () => {
|
|
143
141
|
it('builds a url() source under the resource family and registers the face', async () => {
|
|
144
142
|
const resource = createFontResource('MyFont');
|
|
145
|
-
const result = await loadFontResourceFromUrl(resource, 'https://example.com/font.woff2');
|
|
143
|
+
const result = await loadFontResourceFromUrl(backend, resource, 'https://example.com/font.woff2');
|
|
146
144
|
expect(result).toBe(resource);
|
|
147
145
|
expect(constructions[0].family).toBe('MyFont');
|
|
148
146
|
expect(constructions[0].source).toBe('url(https://example.com/font.woff2)');
|
|
@@ -151,7 +149,7 @@ describe('loadFontResourceFromUrl', () => {
|
|
|
151
149
|
});
|
|
152
150
|
|
|
153
151
|
it('adds no format() hint — a single url carries none, unlike the multi-source form', async () => {
|
|
154
|
-
await loadFontResourceFromUrl(createFontResource('MyFont'), 'font.woff2');
|
|
152
|
+
await loadFontResourceFromUrl(backend, createFontResource('MyFont'), 'font.woff2');
|
|
155
153
|
expect(constructions[0].source).toBe('url(font.woff2)');
|
|
156
154
|
});
|
|
157
155
|
|
|
@@ -165,7 +163,7 @@ describe('loadFontResourceFromUrl', () => {
|
|
|
165
163
|
return failing;
|
|
166
164
|
}),
|
|
167
165
|
);
|
|
168
|
-
await expect(loadFontResourceFromUrl(resource, 'font.woff2')).rejects.toThrow('bad url');
|
|
166
|
+
await expect(loadFontResourceFromUrl(backend, resource, 'font.woff2')).rejects.toThrow('bad url');
|
|
169
167
|
expect(addMock).not.toHaveBeenCalled();
|
|
170
168
|
expect(resource.face).toBeNull();
|
|
171
169
|
});
|
|
@@ -174,7 +172,7 @@ describe('loadFontResourceFromUrl', () => {
|
|
|
174
172
|
describe('loadFontResourceFromUrls', () => {
|
|
175
173
|
it('composes a comma-joined src with explicit and inferred format() hints', async () => {
|
|
176
174
|
const resource = createFontResource('MyFont');
|
|
177
|
-
const result = await loadFontResourceFromUrls(resource, [
|
|
175
|
+
const result = await loadFontResourceFromUrls(backend, resource, [
|
|
178
176
|
{ url: 'font.woff2', format: 'woff2' },
|
|
179
177
|
{ url: 'font.ttf' },
|
|
180
178
|
]);
|
|
@@ -185,17 +183,17 @@ describe('loadFontResourceFromUrls', () => {
|
|
|
185
183
|
});
|
|
186
184
|
|
|
187
185
|
it('infers the format from the file extension when none is given', async () => {
|
|
188
|
-
await loadFontResourceFromUrls(createFontResource('MyFont'), [{ url: 'font.otf' }]);
|
|
186
|
+
await loadFontResourceFromUrls(backend, createFontResource('MyFont'), [{ url: 'font.otf' }]);
|
|
189
187
|
expect(constructions[0].source).toBe("url(font.otf) format('opentype')");
|
|
190
188
|
});
|
|
191
189
|
|
|
192
190
|
it('omits the format() hint when it cannot be inferred and none is given', async () => {
|
|
193
|
-
await loadFontResourceFromUrls(createFontResource('MyFont'), [{ url: 'font.bin' }]);
|
|
191
|
+
await loadFontResourceFromUrls(backend, createFontResource('MyFont'), [{ url: 'font.bin' }]);
|
|
194
192
|
expect(constructions[0].source).toBe('url(font.bin)');
|
|
195
193
|
});
|
|
196
194
|
|
|
197
195
|
it('mixes inferred, explicit, and absent hints across one src list', async () => {
|
|
198
|
-
await loadFontResourceFromUrls(createFontResource('MyFont'), [
|
|
196
|
+
await loadFontResourceFromUrls(backend, createFontResource('MyFont'), [
|
|
199
197
|
{ url: 'a.woff2', format: 'woff2' },
|
|
200
198
|
{ url: 'b.ttf' },
|
|
201
199
|
{ url: 'c.bin' },
|
|
@@ -204,7 +202,7 @@ describe('loadFontResourceFromUrls', () => {
|
|
|
204
202
|
});
|
|
205
203
|
|
|
206
204
|
it('builds an empty src for an empty source list rather than throwing', async () => {
|
|
207
|
-
await loadFontResourceFromUrls(createFontResource('MyFont'), []);
|
|
205
|
+
await loadFontResourceFromUrls(backend, createFontResource('MyFont'), []);
|
|
208
206
|
expect(constructions[0].source).toBe('');
|
|
209
207
|
});
|
|
210
208
|
|
|
@@ -218,7 +216,7 @@ describe('loadFontResourceFromUrls', () => {
|
|
|
218
216
|
return failing;
|
|
219
217
|
}),
|
|
220
218
|
);
|
|
221
|
-
await expect(loadFontResourceFromUrls(resource, [{ url: 'font.woff2' }])).rejects.toThrow('bad url');
|
|
219
|
+
await expect(loadFontResourceFromUrls(backend, resource, [{ url: 'font.woff2' }])).rejects.toThrow('bad url');
|
|
222
220
|
expect(addMock).not.toHaveBeenCalled();
|
|
223
221
|
expect(resource.face).toBeNull();
|
|
224
222
|
});
|
package/src/fontStatus.test.ts
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
import type { FontLoadingBackend } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
|
-
import { resetFontLoadingBackendForTest, setFontLoadingBackend } from './fontLoading';
|
|
4
3
|
import { isFontLoaded, whenFontsReady } from './fontStatus';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
checkMock = vi.fn<(shorthand: string) => boolean>().mockReturnValue(true);
|
|
11
|
-
whenReadyMock = vi.fn<() => Promise<void>>().mockResolvedValue(undefined);
|
|
12
|
-
const backend: FontLoadingBackend = {
|
|
13
|
-
addFontFace: vi.fn<(face: FontFace) => void>(),
|
|
14
|
-
checkFontFace: checkMock,
|
|
5
|
+
function createMockBackend(overrides: Partial<FontLoadingBackend> = {}): FontLoadingBackend {
|
|
6
|
+
return {
|
|
7
|
+
addFontFace: vi.fn(),
|
|
8
|
+
checkFontFace: vi.fn<(shorthand: string) => boolean>().mockReturnValue(true),
|
|
15
9
|
loadFontFaces: vi.fn<(shorthand: string) => Promise<FontFace[]>>().mockResolvedValue([]),
|
|
16
|
-
whenReady:
|
|
10
|
+
whenReady: vi.fn<() => Promise<void>>().mockResolvedValue(undefined),
|
|
11
|
+
...overrides,
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
resetFontLoadingBackendForTest();
|
|
23
|
-
});
|
|
13
|
+
}
|
|
24
14
|
|
|
25
15
|
describe('isFontLoaded', () => {
|
|
26
16
|
it('queries the backend with the family shorthand', () => {
|
|
27
|
-
|
|
17
|
+
const checkMock = vi.fn<(shorthand: string) => boolean>().mockReturnValue(true);
|
|
18
|
+
const backend = createMockBackend({ checkFontFace: checkMock });
|
|
19
|
+
expect(isFontLoaded(backend, 'MyFont')).toBe(true);
|
|
28
20
|
expect(checkMock).toHaveBeenCalledWith("1em 'MyFont'");
|
|
29
21
|
});
|
|
30
22
|
|
|
31
23
|
it('includes the style in the shorthand when provided', () => {
|
|
32
|
-
|
|
24
|
+
const checkMock = vi.fn<(shorthand: string) => boolean>().mockReturnValue(true);
|
|
25
|
+
const backend = createMockBackend({ checkFontFace: checkMock });
|
|
26
|
+
isFontLoaded(backend, 'MyFont', 'italic');
|
|
33
27
|
expect(checkMock).toHaveBeenCalledWith("italic 1em 'MyFont'");
|
|
34
28
|
});
|
|
35
29
|
|
|
36
30
|
it('escapes single quotes in the family name', () => {
|
|
37
|
-
|
|
31
|
+
const checkMock = vi.fn<(shorthand: string) => boolean>().mockReturnValue(true);
|
|
32
|
+
const backend = createMockBackend({ checkFontFace: checkMock });
|
|
33
|
+
isFontLoaded(backend, "Josh's Font");
|
|
38
34
|
expect(checkMock).toHaveBeenCalledWith("1em 'Josh\\'s Font'");
|
|
39
35
|
});
|
|
40
36
|
|
|
41
37
|
it('returns false when the font is not available', () => {
|
|
42
|
-
|
|
43
|
-
expect(isFontLoaded('Absent')).toBe(false);
|
|
38
|
+
const backend = createMockBackend({ checkFontFace: vi.fn().mockReturnValue(false) });
|
|
39
|
+
expect(isFontLoaded(backend, 'Absent')).toBe(false);
|
|
44
40
|
});
|
|
45
41
|
});
|
|
46
42
|
|
|
47
43
|
describe('whenFontsReady', () => {
|
|
48
44
|
it('resolves once the backend reports ready', async () => {
|
|
49
|
-
|
|
45
|
+
const whenReadyMock = vi.fn<() => Promise<void>>().mockResolvedValue(undefined);
|
|
46
|
+
const backend = createMockBackend({ whenReady: whenReadyMock });
|
|
47
|
+
await expect(whenFontsReady(backend)).resolves.toBeUndefined();
|
|
50
48
|
expect(whenReadyMock).toHaveBeenCalledOnce();
|
|
51
49
|
});
|
|
52
50
|
});
|
package/dist/fontLoading.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { BackendExplanation, FontLoadingBackend } from '@flighthq/types/contract';
|
|
2
|
-
export declare function explainFontLoadingBackend(): BackendExplanation;
|
|
3
|
-
export declare function getFontLoadingBackend(): FontLoadingBackend;
|
|
4
|
-
export declare function hasFontLoadingHostBackend(): boolean;
|
|
5
|
-
export declare function installFontLoadingHostBackend(backend: FontLoadingBackend): void;
|
|
6
|
-
export declare function resetFontLoadingBackendForTest(): void;
|
|
7
|
-
export declare function setFontLoadingBackend(backend: FontLoadingBackend | null): void;
|
|
8
|
-
//# sourceMappingURL=fontLoading.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fontLoading.d.ts","sourceRoot":"","sources":["../src/fontLoading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEvF,wBAAgB,yBAAyB,IAAI,kBAAkB,CAQ9D;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,CAE1D;AAED,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAM/E;AAED,wBAAgB,8BAA8B,IAAI,IAAI,CAIrD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAE9E"}
|
package/dist/fontLoading.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export function explainFontLoadingBackend() {
|
|
2
|
-
if (_custom !== null) {
|
|
3
|
-
return { conflict: _hostConflict, layer: 'custom', operation: null, viability: 'unobserved' };
|
|
4
|
-
}
|
|
5
|
-
if (_host !== null) {
|
|
6
|
-
return { conflict: _hostConflict, layer: 'host', operation: null, viability: 'unobserved' };
|
|
7
|
-
}
|
|
8
|
-
return { conflict: false, layer: 'host-not-enabled', operation: null, viability: 'unobserved' };
|
|
9
|
-
}
|
|
10
|
-
export function getFontLoadingBackend() {
|
|
11
|
-
return _custom ?? _host ?? _sentinel;
|
|
12
|
-
}
|
|
13
|
-
export function hasFontLoadingHostBackend() {
|
|
14
|
-
return _host !== null;
|
|
15
|
-
}
|
|
16
|
-
export function installFontLoadingHostBackend(backend) {
|
|
17
|
-
if (_host !== null) {
|
|
18
|
-
if (_host !== backend)
|
|
19
|
-
_hostConflict = true;
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
_host = backend;
|
|
23
|
-
}
|
|
24
|
-
export function resetFontLoadingBackendForTest() {
|
|
25
|
-
_custom = null;
|
|
26
|
-
_host = null;
|
|
27
|
-
_hostConflict = false;
|
|
28
|
-
}
|
|
29
|
-
export function setFontLoadingBackend(backend) {
|
|
30
|
-
_custom = backend;
|
|
31
|
-
}
|
|
32
|
-
let _custom = null;
|
|
33
|
-
let _host = null;
|
|
34
|
-
let _hostConflict = false;
|
|
35
|
-
const _sentinel = {
|
|
36
|
-
addFontFace() { },
|
|
37
|
-
checkFontFace() {
|
|
38
|
-
return false;
|
|
39
|
-
},
|
|
40
|
-
loadFontFaces() {
|
|
41
|
-
return Promise.resolve([]);
|
|
42
|
-
},
|
|
43
|
-
whenReady() {
|
|
44
|
-
return Promise.resolve();
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=fontLoading.js.map
|
package/dist/fontLoading.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fontLoading.js","sourceRoot":"","sources":["../src/fontLoading.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,yBAAyB;IACvC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAChG,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,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|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
explainFontLoadingBackend,
|
|
5
|
-
getFontLoadingBackend,
|
|
6
|
-
hasFontLoadingHostBackend,
|
|
7
|
-
installFontLoadingHostBackend,
|
|
8
|
-
resetFontLoadingBackendForTest,
|
|
9
|
-
setFontLoadingBackend,
|
|
10
|
-
} from './fontLoading';
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
resetFontLoadingBackendForTest();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
function createMockBackend(overrides: Partial<FontLoadingBackend> = {}): FontLoadingBackend {
|
|
17
|
-
return {
|
|
18
|
-
addFontFace: vi.fn(),
|
|
19
|
-
checkFontFace: vi.fn().mockReturnValue(true),
|
|
20
|
-
loadFontFaces: vi.fn().mockResolvedValue([]),
|
|
21
|
-
whenReady: vi.fn().mockResolvedValue(undefined),
|
|
22
|
-
...overrides,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('explainFontLoadingBackend', () => {
|
|
27
|
-
it('reports host-not-enabled when no backend is installed', () => {
|
|
28
|
-
expect(explainFontLoadingBackend()).toEqual({
|
|
29
|
-
conflict: false,
|
|
30
|
-
layer: 'host-not-enabled',
|
|
31
|
-
operation: null,
|
|
32
|
-
viability: 'unobserved',
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('reports host when a host backend is installed', () => {
|
|
37
|
-
installFontLoadingHostBackend(createMockBackend());
|
|
38
|
-
expect(explainFontLoadingBackend()).toEqual({
|
|
39
|
-
conflict: false,
|
|
40
|
-
layer: 'host',
|
|
41
|
-
operation: null,
|
|
42
|
-
viability: 'unobserved',
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('reports custom when a custom backend is set', () => {
|
|
47
|
-
setFontLoadingBackend(createMockBackend());
|
|
48
|
-
expect(explainFontLoadingBackend()).toEqual({
|
|
49
|
-
conflict: false,
|
|
50
|
-
layer: 'custom',
|
|
51
|
-
operation: null,
|
|
52
|
-
viability: 'unobserved',
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('reports custom over host when both are installed', () => {
|
|
57
|
-
installFontLoadingHostBackend(createMockBackend());
|
|
58
|
-
setFontLoadingBackend(createMockBackend());
|
|
59
|
-
expect(explainFontLoadingBackend().layer).toBe('custom');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('reports conflict when a different host backend is installed twice', () => {
|
|
63
|
-
installFontLoadingHostBackend(createMockBackend());
|
|
64
|
-
installFontLoadingHostBackend(createMockBackend());
|
|
65
|
-
expect(explainFontLoadingBackend().conflict).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('getFontLoadingBackend', () => {
|
|
70
|
-
it('returns the sentinel when no backend is installed', () => {
|
|
71
|
-
const backend = getFontLoadingBackend();
|
|
72
|
-
expect(backend.checkFontFace('1em serif')).toBe(false);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('returns the host backend when installed', () => {
|
|
76
|
-
const host = createMockBackend();
|
|
77
|
-
installFontLoadingHostBackend(host);
|
|
78
|
-
expect(getFontLoadingBackend()).toBe(host);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('returns the custom backend when set', () => {
|
|
82
|
-
const custom = createMockBackend();
|
|
83
|
-
setFontLoadingBackend(custom);
|
|
84
|
-
expect(getFontLoadingBackend()).toBe(custom);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('prefers custom over host', () => {
|
|
88
|
-
const host = createMockBackend();
|
|
89
|
-
const custom = createMockBackend();
|
|
90
|
-
installFontLoadingHostBackend(host);
|
|
91
|
-
setFontLoadingBackend(custom);
|
|
92
|
-
expect(getFontLoadingBackend()).toBe(custom);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('reveals host when custom is cleared', () => {
|
|
96
|
-
const host = createMockBackend();
|
|
97
|
-
installFontLoadingHostBackend(host);
|
|
98
|
-
setFontLoadingBackend(createMockBackend());
|
|
99
|
-
setFontLoadingBackend(null);
|
|
100
|
-
expect(getFontLoadingBackend()).toBe(host);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('hasFontLoadingHostBackend', () => {
|
|
105
|
-
it('returns false when no host is installed', () => {
|
|
106
|
-
expect(hasFontLoadingHostBackend()).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('returns true after installing a host backend', () => {
|
|
110
|
-
installFontLoadingHostBackend(createMockBackend());
|
|
111
|
-
expect(hasFontLoadingHostBackend()).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('installFontLoadingHostBackend', () => {
|
|
116
|
-
it('ignores a second install of the same instance', () => {
|
|
117
|
-
const host = createMockBackend();
|
|
118
|
-
installFontLoadingHostBackend(host);
|
|
119
|
-
installFontLoadingHostBackend(host);
|
|
120
|
-
expect(explainFontLoadingBackend().conflict).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('resetFontLoadingBackendForTest', () => {
|
|
125
|
-
it('clears all backend state', () => {
|
|
126
|
-
installFontLoadingHostBackend(createMockBackend());
|
|
127
|
-
setFontLoadingBackend(createMockBackend());
|
|
128
|
-
resetFontLoadingBackendForTest();
|
|
129
|
-
expect(hasFontLoadingHostBackend()).toBe(false);
|
|
130
|
-
expect(explainFontLoadingBackend().layer).toBe('host-not-enabled');
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('sentinel', () => {
|
|
135
|
-
it('addFontFace is a no-op', () => {
|
|
136
|
-
const backend = getFontLoadingBackend();
|
|
137
|
-
expect(() => backend.addFontFace({} as FontFace)).not.toThrow();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('checkFontFace returns false', () => {
|
|
141
|
-
expect(getFontLoadingBackend().checkFontFace('1em serif')).toBe(false);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('loadFontFaces resolves to an empty array', async () => {
|
|
145
|
-
await expect(getFontLoadingBackend().loadFontFaces('1em serif')).resolves.toEqual([]);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('whenReady resolves', async () => {
|
|
149
|
-
await expect(getFontLoadingBackend().whenReady()).resolves.toBeUndefined();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('setFontLoadingBackend', () => {
|
|
154
|
-
it('sets a custom backend', () => {
|
|
155
|
-
const custom = createMockBackend();
|
|
156
|
-
setFontLoadingBackend(custom);
|
|
157
|
-
expect(getFontLoadingBackend()).toBe(custom);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('clears the custom backend with null', () => {
|
|
161
|
-
setFontLoadingBackend(createMockBackend());
|
|
162
|
-
setFontLoadingBackend(null);
|
|
163
|
-
expect(getFontLoadingBackend().checkFontFace('1em serif')).toBe(false);
|
|
164
|
-
});
|
|
165
|
-
});
|