@flighthq/font 0.5.1-next.704.19c91ec → 0.5.1-next.730.f29a5aa
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/contract.d.ts +0 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +0 -2
- package/dist/contract.js.map +1 -1
- package/dist/fontResource.d.ts.map +1 -1
- package/dist/fontResource.js +2 -1
- package/dist/fontResource.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/font.d.ts +0 -3
- package/dist/font.d.ts.map +0 -1
- package/dist/font.js +0 -5
- package/dist/font.js.map +0 -1
- package/dist/fontFrom.d.ts +0 -19
- package/dist/fontFrom.d.ts.map +0 -1
- package/dist/fontFrom.js +0 -32
- package/dist/fontFrom.js.map +0 -1
- package/src/font.test.ts +0 -12
- package/src/fontFrom.test.ts +0 -144
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.730.f29a5aa](https://github.com/flighthq/flight/tree/f29a5aab5db192284ce5cadf08ffae2649a598ea/packages/font)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/f29a5aab5db192284ce5cadf08ffae2649a598ea/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
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,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
package/dist/contract.js
CHANGED
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontResource.d.ts","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fontResource.d.ts","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAE/D"}
|
package/dist/fontResource.js
CHANGED
package/dist/fontResource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontResource.js","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fontResource.js","sourceRoot":"","sources":["../src/fontResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createFontResource, createGlyphRasterizerBackendFromGlyphOutlineSource, detectFontFormat, getFontShorthand, inferFontFormatFromUrl, isFontLoaded, loadFontResourceFromBytes, loadFontResourceFromName, loadFontResourceFromUrl, loadFontResourceFromUrls, whenFontsReady, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kDAAkD,EAClD,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createFontResource, createGlyphRasterizerBackendFromGlyphOutlineSource, detectFontFormat, getFontShorthand, inferFontFormatFromUrl, isFontLoaded, loadFontResourceFromBytes, loadFontResourceFromName, loadFontResourceFromUrl, loadFontResourceFromUrls, whenFontsReady, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kDAAkD,EAClD,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,cAAc,GACf,MAAM,YAAY,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.730.f29a5aa",
|
|
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.730.f29a5aa",
|
|
42
|
+
"@flighthq/path": "0.5.1-next.730.f29a5aa",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.730.f29a5aa"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
package/dist/font.d.ts
DELETED
package/dist/font.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../src/font.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE7C"}
|
package/dist/font.js
DELETED
package/dist/font.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"font.js","sourceRoot":"","sources":["../src/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/fontFrom.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Font, FontUrl } from '@flighthq/types/contract';
|
|
2
|
-
/**
|
|
3
|
-
* Loads a font face from bytes and returns its family handle. If loading rejects, the face is not
|
|
4
|
-
* registered and no `Font` is returned.
|
|
5
|
-
*/
|
|
6
|
-
export declare function loadFontFromBytes(bytes: Uint8Array, family: string): Promise<Font>;
|
|
7
|
-
/** Looks up a registered family and returns its handle. If the lookup rejects, no `Font` is returned. */
|
|
8
|
-
export declare function loadFontFromName(name: string): Promise<Font>;
|
|
9
|
-
/**
|
|
10
|
-
* Loads a font face from one URL and returns its family handle. If loading rejects, the face is not
|
|
11
|
-
* registered and no `Font` is returned.
|
|
12
|
-
*/
|
|
13
|
-
export declare function loadFontFromUrl(url: string, family: string): Promise<Font>;
|
|
14
|
-
/**
|
|
15
|
-
* Loads a font face from fallback URLs and returns its family handle. If loading rejects, the face is
|
|
16
|
-
* not registered and no `Font` is returned.
|
|
17
|
-
*/
|
|
18
|
-
export declare function loadFontFromUrls(sources: FontUrl[], family: string): Promise<Font>;
|
|
19
|
-
//# sourceMappingURL=fontFrom.d.ts.map
|
package/dist/fontFrom.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fontFrom.d.ts","sourceRoot":"","sources":["../src/fontFrom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAU9D;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGxF;AAED,yGAAyG;AACzG,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGxF"}
|
package/dist/fontFrom.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { _loadFontFaceFromBytes, _loadFontFaceFromUrl, _loadFontFaceFromUrls, _loadFontFacesFromName, } from './_fontFaceLoad';
|
|
2
|
-
import { createFont } from './font';
|
|
3
|
-
/**
|
|
4
|
-
* Loads a font face from bytes and returns its family handle. If loading rejects, the face is not
|
|
5
|
-
* registered and no `Font` is returned.
|
|
6
|
-
*/
|
|
7
|
-
export async function loadFontFromBytes(bytes, family) {
|
|
8
|
-
await _loadFontFaceFromBytes(family, bytes);
|
|
9
|
-
return createFont(family);
|
|
10
|
-
}
|
|
11
|
-
/** Looks up a registered family and returns its handle. If the lookup rejects, no `Font` is returned. */
|
|
12
|
-
export async function loadFontFromName(name) {
|
|
13
|
-
await _loadFontFacesFromName(name);
|
|
14
|
-
return createFont(name);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Loads a font face from one URL and returns its family handle. If loading rejects, the face is not
|
|
18
|
-
* registered and no `Font` is returned.
|
|
19
|
-
*/
|
|
20
|
-
export async function loadFontFromUrl(url, family) {
|
|
21
|
-
await _loadFontFaceFromUrl(family, url);
|
|
22
|
-
return createFont(family);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Loads a font face from fallback URLs and returns its family handle. If loading rejects, the face is
|
|
26
|
-
* not registered and no `Font` is returned.
|
|
27
|
-
*/
|
|
28
|
-
export async function loadFontFromUrls(sources, family) {
|
|
29
|
-
await _loadFontFaceFromUrls(family, sources);
|
|
30
|
-
return createFont(family);
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=fontFrom.js.map
|
package/dist/fontFrom.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fontFrom.js","sourceRoot":"","sources":["../src/fontFrom.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAiB,EAAE,MAAc;IACvE,MAAM,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY;IACjD,MAAM,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW,EAAE,MAAc;IAC/D,MAAM,oBAAoB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAkB,EAAE,MAAc;IACvE,MAAM,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
package/src/font.test.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createFont } from './font';
|
|
2
|
-
|
|
3
|
-
describe('createFont', () => {
|
|
4
|
-
it('returns a font with the given name', () => {
|
|
5
|
-
const font = createFont('Arial');
|
|
6
|
-
expect(font.name).toBe('Arial');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('returns a new object each call', () => {
|
|
10
|
-
expect(createFont('Arial')).not.toBe(createFont('Arial'));
|
|
11
|
-
});
|
|
12
|
-
});
|
package/src/fontFrom.test.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { FontLoadingBackend } from '@flighthq/types/contract';
|
|
2
|
-
|
|
3
|
-
import { loadFontFromBytes, loadFontFromName, loadFontFromUrl, loadFontFromUrls } from './fontFrom';
|
|
4
|
-
import { resetFontLoadingBackendForTest, setFontLoadingBackend } from './fontLoading';
|
|
5
|
-
|
|
6
|
-
interface FontFaceConstruction {
|
|
7
|
-
family: string;
|
|
8
|
-
source: string | ArrayBuffer;
|
|
9
|
-
instance: MockFontFace;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
let constructions: FontFaceConstruction[];
|
|
13
|
-
let addMock = vi.fn<(face: FontFace) => void>();
|
|
14
|
-
let loadMock = vi.fn<(shorthand: string) => Promise<FontFace[]>>();
|
|
15
|
-
|
|
16
|
-
class MockFontFace {
|
|
17
|
-
load = vi.fn().mockResolvedValue(undefined);
|
|
18
|
-
constructor(family: string, source: string | ArrayBuffer) {
|
|
19
|
-
constructions.push({ family, source, instance: this });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
constructions = [];
|
|
25
|
-
addMock = vi.fn<(face: FontFace) => void>();
|
|
26
|
-
loadMock = vi.fn<(shorthand: string) => Promise<FontFace[]>>().mockResolvedValue([]);
|
|
27
|
-
vi.stubGlobal('FontFace', MockFontFace);
|
|
28
|
-
const backend: FontLoadingBackend = {
|
|
29
|
-
addFontFace: addMock,
|
|
30
|
-
checkFontFace: vi.fn<(shorthand: string) => boolean>().mockReturnValue(false),
|
|
31
|
-
loadFontFaces: loadMock,
|
|
32
|
-
whenReady: vi.fn<() => Promise<void>>().mockResolvedValue(undefined),
|
|
33
|
-
};
|
|
34
|
-
setFontLoadingBackend(backend);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
afterEach(() => {
|
|
38
|
-
resetFontLoadingBackendForTest();
|
|
39
|
-
vi.unstubAllGlobals();
|
|
40
|
-
vi.restoreAllMocks();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('loadFontFromBytes', () => {
|
|
44
|
-
it('returns a font with the given family name', async () => {
|
|
45
|
-
const font = await loadFontFromBytes(new Uint8Array(0), 'TestFont');
|
|
46
|
-
expect(font.name).toBe('TestFont');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('loads the face and registers it via the backend', async () => {
|
|
50
|
-
await loadFontFromBytes(new Uint8Array(8), 'TestFont');
|
|
51
|
-
expect(constructions).toHaveLength(1);
|
|
52
|
-
expect(constructions[0].family).toBe('TestFont');
|
|
53
|
-
expect(constructions[0].instance.load).toHaveBeenCalledOnce();
|
|
54
|
-
expect(addMock).toHaveBeenCalledWith(constructions[0].instance);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('slices only the view bytes out of a larger backing buffer', async () => {
|
|
58
|
-
const backing = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
59
|
-
const view = backing.subarray(2, 6);
|
|
60
|
-
await loadFontFromBytes(view, 'TestFont');
|
|
61
|
-
const source = constructions[0].source as ArrayBuffer;
|
|
62
|
-
expect(new Uint8Array(source)).toEqual(new Uint8Array([3, 4, 5, 6]));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('propagates a load failure and does not register the face', async () => {
|
|
66
|
-
const failing = new MockFontFace('', new ArrayBuffer(0));
|
|
67
|
-
failing.load.mockRejectedValue(new Error('bad font'));
|
|
68
|
-
vi.stubGlobal(
|
|
69
|
-
'FontFace',
|
|
70
|
-
vi.fn(function () {
|
|
71
|
-
return failing;
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
await expect(loadFontFromBytes(new Uint8Array(4), 'TestFont')).rejects.toThrow('bad font');
|
|
75
|
-
expect(addMock).not.toHaveBeenCalled();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('loadFontFromName', () => {
|
|
80
|
-
it('returns a font with the given name', async () => {
|
|
81
|
-
const font = await loadFontFromName('MyFont');
|
|
82
|
-
expect(font.name).toBe('MyFont');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('loads the family via the escaped font shorthand', async () => {
|
|
86
|
-
await loadFontFromName('MyFont');
|
|
87
|
-
expect(loadMock).toHaveBeenCalledWith("1em 'MyFont'");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('escapes a single quote in the family name so the shorthand stays valid', async () => {
|
|
91
|
-
await loadFontFromName("Josh's Font");
|
|
92
|
-
expect(loadMock).toHaveBeenCalledWith("1em 'Josh\\'s Font'");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('propagates a load failure', async () => {
|
|
96
|
-
loadMock.mockRejectedValue(new Error('no such font'));
|
|
97
|
-
await expect(loadFontFromName('MyFont')).rejects.toThrow('no such font');
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('loadFontFromUrl', () => {
|
|
102
|
-
it('returns a font with the given family name', async () => {
|
|
103
|
-
const font = await loadFontFromUrl('font.woff2', 'MyFont');
|
|
104
|
-
expect(font.name).toBe('MyFont');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('builds a url() source and registers the face', async () => {
|
|
108
|
-
await loadFontFromUrl('font.woff2', 'MyFont');
|
|
109
|
-
expect(constructions[0].family).toBe('MyFont');
|
|
110
|
-
expect(constructions[0].source).toBe('url(font.woff2)');
|
|
111
|
-
expect(addMock).toHaveBeenCalledWith(constructions[0].instance);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('loadFontFromUrls', () => {
|
|
116
|
-
it('returns a font with the given family name from multiple sources', async () => {
|
|
117
|
-
const font = await loadFontFromUrls([{ url: 'font.woff2', format: 'woff2' }], 'MyFont');
|
|
118
|
-
expect(font.name).toBe('MyFont');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('composes a comma-joined src with explicit and inferred format() hints', async () => {
|
|
122
|
-
await loadFontFromUrls([{ url: 'font.woff2', format: 'woff2' }, { url: 'font.ttf' }], 'MyFont');
|
|
123
|
-
expect(constructions[0].source).toBe("url(font.woff2) format('woff2'), url(font.ttf) format('truetype')");
|
|
124
|
-
expect(addMock).toHaveBeenCalledWith(constructions[0].instance);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('omits the format() hint when it cannot be inferred and none is given', async () => {
|
|
128
|
-
await loadFontFromUrls([{ url: 'font.bin' }], 'MyFont');
|
|
129
|
-
expect(constructions[0].source).toBe('url(font.bin)');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('propagates a load failure and does not register the face', async () => {
|
|
133
|
-
const failing = new MockFontFace('', '');
|
|
134
|
-
failing.load.mockRejectedValue(new Error('bad url'));
|
|
135
|
-
vi.stubGlobal(
|
|
136
|
-
'FontFace',
|
|
137
|
-
vi.fn(function () {
|
|
138
|
-
return failing;
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
141
|
-
await expect(loadFontFromUrls([{ url: 'font.woff2' }], 'MyFont')).rejects.toThrow('bad url');
|
|
142
|
-
expect(addMock).not.toHaveBeenCalled();
|
|
143
|
-
});
|
|
144
|
-
});
|