@webstudio-is/fonts 0.1.1 → 0.3.0

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.
Files changed (47) hide show
  1. package/lib/cjs/constants.cjs +40 -0
  2. package/lib/cjs/font-data.cjs +70 -0
  3. package/lib/cjs/font-weights.cjs +70 -0
  4. package/lib/cjs/get-font-faces.cjs +51 -0
  5. package/lib/cjs/index.cjs +21 -0
  6. package/lib/cjs/index.server.cjs +24 -0
  7. package/lib/cjs/schema.cjs +37 -0
  8. package/lib/constants.js +18 -17
  9. package/lib/font-data.js +42 -48
  10. package/lib/font-weights.js +49 -49
  11. package/lib/get-font-faces.js +25 -28
  12. package/lib/index.js +4 -20
  13. package/lib/index.server.js +3 -19
  14. package/lib/schema.js +16 -9
  15. package/package.json +20 -19
  16. package/src/__snapshots__/get-font-faces.test.ts.snap +51 -0
  17. package/src/constants.ts +21 -0
  18. package/src/font-data.test.ts +69 -0
  19. package/src/font-data.ts +74 -0
  20. package/src/font-weights.ts +52 -0
  21. package/src/get-font-faces.test.ts +75 -0
  22. package/src/get-font-faces.ts +53 -0
  23. package/src/index.server.ts +1 -0
  24. package/{lib/index.d.ts → src/index.ts} +1 -2
  25. package/src/schema.ts +17 -0
  26. package/lib/constants.d.ts +0 -6
  27. package/lib/constants.d.ts.map +0 -1
  28. package/lib/font-data.d.ts +0 -23
  29. package/lib/font-data.d.ts.map +0 -1
  30. package/lib/font-data.test.d.ts +0 -2
  31. package/lib/font-data.test.d.ts.map +0 -1
  32. package/lib/font-data.test.js +0 -67
  33. package/lib/font-weights.d.ts +0 -50
  34. package/lib/font-weights.d.ts.map +0 -1
  35. package/lib/get-font-faces.d.ts +0 -16
  36. package/lib/get-font-faces.d.ts.map +0 -1
  37. package/lib/get-font-faces.test.d.ts +0 -2
  38. package/lib/get-font-faces.test.d.ts.map +0 -1
  39. package/lib/get-font-faces.test.js +0 -74
  40. package/lib/index.d.ts.map +0 -1
  41. package/lib/index.server.d.ts +0 -3
  42. package/lib/index.server.d.ts.map +0 -1
  43. package/lib/schema.d.ts +0 -16
  44. package/lib/schema.d.ts.map +0 -1
  45. package/lib/types.d.ts +0 -2
  46. package/lib/types.d.ts.map +0 -1
  47. package/lib/types.js +0 -2
@@ -1,20 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1
+ import { getFontData } from "./font-data";
2
+ export {
3
+ getFontData
15
4
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getFontData = void 0;
18
- var font_data_1 = require("./font-data");
19
- Object.defineProperty(exports, "getFontData", { enumerable: true, get: function () { return font_data_1.getFontData; } });
20
- __exportStar(require("./schema"), exports);
package/lib/schema.js CHANGED
@@ -1,10 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FontMeta = void 0;
4
- const zod_1 = require("zod");
5
- const font_data_1 = require("./font-data");
6
- exports.FontMeta = zod_1.z.object({
7
- family: zod_1.z.string(),
8
- style: zod_1.z.enum(font_data_1.styles),
9
- weight: zod_1.z.number(),
1
+ import { z } from "zod";
2
+ import { styles } from "./font-data";
3
+ const FontFormat = z.union([
4
+ z.literal("ttf"),
5
+ z.literal("woff"),
6
+ z.literal("woff2"),
7
+ z.literal("otf")
8
+ ]);
9
+ const FontMeta = z.object({
10
+ family: z.string(),
11
+ style: z.enum(styles),
12
+ weight: z.number()
10
13
  });
14
+ export {
15
+ FontFormat,
16
+ FontMeta
17
+ };
package/package.json CHANGED
@@ -1,47 +1,48 @@
1
1
  {
2
2
  "name": "@webstudio-is/fonts",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Fonts utils",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
7
+ "type": "module",
7
8
  "scripts": {
8
9
  "typecheck": "tsc --noEmit",
9
- "test": "jest",
10
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
10
11
  "checks": "yarn typecheck && yarn lint && yarn test",
11
- "dev": "tsup --watch",
12
- "build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
13
- "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
12
+ "dev": "build-package --watch",
13
+ "build": "build-package",
14
+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
15
+ "publish-to-npm": "bash ../../bin/publish-to-npm.sh"
14
16
  },
15
17
  "dependencies": {
16
18
  "fontkit": "^2.0.2"
17
19
  },
18
20
  "devDependencies": {
21
+ "@types/fontkit": "^2.0.0",
19
22
  "@webstudio-is/design-system": "*",
20
23
  "@webstudio-is/jest-config": "*",
21
- "tsup": "^6.1.3",
24
+ "@webstudio-is/scripts": "*",
22
25
  "typescript": "4.7.4",
23
- "@types/fontkit": "^1.8.0",
24
26
  "zod": "^3.19.1"
25
27
  },
26
28
  "peerDependencies": {
27
29
  "zod": "^3.19.1"
28
30
  },
29
- "main": "lib/index.js",
30
- "types": "lib/index.d.ts",
31
+ "module": "./lib/index.js",
32
+ "exports": {
33
+ ".": {
34
+ "import": "./lib/index.js",
35
+ "require": "./lib/cjs/index.cjs"
36
+ },
37
+ "./server": "./server.js"
38
+ },
39
+ "types": "src/index.ts",
31
40
  "files": [
32
41
  "lib/*",
33
- "README.md",
42
+ "src/*",
34
43
  "!*.test.*"
35
44
  ],
36
45
  "license": "MIT",
37
46
  "private": false,
38
- "sideEffects": false,
39
- "tsup": {
40
- "entry": [
41
- "src/index.ts",
42
- "src/index.server.ts"
43
- ],
44
- "format": "cjs",
45
- "outDir": "lib"
46
- }
47
+ "sideEffects": false
47
48
  }
@@ -0,0 +1,51 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`getFontFaces() different formats 1`] = `
4
+ [
5
+ {
6
+ "fontDisplay": "swap",
7
+ "fontFamily": "Roboto",
8
+ "fontStyle": "normal",
9
+ "fontWeight": 400,
10
+ "src": "url('/fonts/roboto.woff') format('woff'), url('/fonts/roboto.ttf') format('truetype')",
11
+ },
12
+ ]
13
+ `;
14
+
15
+ exports[`getFontFaces() different style 1`] = `
16
+ [
17
+ {
18
+ "fontDisplay": "swap",
19
+ "fontFamily": "Roboto",
20
+ "fontStyle": "normal",
21
+ "fontWeight": 400,
22
+ "src": "url('/fonts/roboto.ttf') format('truetype')",
23
+ },
24
+ {
25
+ "fontDisplay": "swap",
26
+ "fontFamily": "Roboto",
27
+ "fontStyle": "italic",
28
+ "fontWeight": 400,
29
+ "src": "url('/fonts/roboto-italic.ttf') format('truetype')",
30
+ },
31
+ ]
32
+ `;
33
+
34
+ exports[`getFontFaces() different weight 1`] = `
35
+ [
36
+ {
37
+ "fontDisplay": "swap",
38
+ "fontFamily": "Roboto",
39
+ "fontStyle": "normal",
40
+ "fontWeight": 400,
41
+ "src": "url('/fonts/roboto.ttf') format('truetype')",
42
+ },
43
+ {
44
+ "fontDisplay": "swap",
45
+ "fontFamily": "Roboto",
46
+ "fontStyle": "normal",
47
+ "fontWeight": 500,
48
+ "src": "url('/fonts/roboto-bold.ttf') format('truetype')",
49
+ },
50
+ ]
51
+ `;
@@ -0,0 +1,21 @@
1
+ import type { FontFormat } from "./schema";
2
+
3
+ export const SYSTEM_FONTS = new Map([
4
+ ["Arial", ["sans-serif"]],
5
+ ["Times New Roman", ["sans"]],
6
+ ["Courier New", ["monospace"]],
7
+ ["system-ui", []],
8
+ ]);
9
+
10
+ export const DEFAULT_FONT_FALLBACK = "sans-serif";
11
+
12
+ export const FONT_FORMATS: Map<FontFormat, string> = new Map([
13
+ ["woff", "woff"],
14
+ ["woff2", "woff2"],
15
+ ["ttf", "truetype"],
16
+ ["otf", "opentype"],
17
+ ]);
18
+
19
+ export const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys())
20
+ .map((format) => `.${format}`)
21
+ .join(", ");
@@ -0,0 +1,69 @@
1
+ import { parseSubfamily, normalizeFamily } from "./font-data";
2
+
3
+ describe("font-data", () => {
4
+ describe("parseSubfamily()", () => {
5
+ test("Black Italic", () => {
6
+ expect(parseSubfamily("Black Italic")).toEqual({
7
+ style: "italic",
8
+ weight: 900,
9
+ });
10
+ });
11
+ test("Bold", () => {
12
+ expect(parseSubfamily("Bold")).toEqual({
13
+ style: "normal",
14
+ weight: 700,
15
+ });
16
+ });
17
+ test("Demi Bold Italic", () => {
18
+ expect(parseSubfamily("Demi Bold Italic")).toEqual({
19
+ style: "italic",
20
+ weight: 600,
21
+ });
22
+ });
23
+ test("Light", () => {
24
+ expect(parseSubfamily("Light")).toEqual({
25
+ style: "normal",
26
+ weight: 300,
27
+ });
28
+ });
29
+ test("Extra Light", () => {
30
+ expect(parseSubfamily("Extra Light")).toEqual({
31
+ style: "normal",
32
+ weight: 200,
33
+ });
34
+ });
35
+ test("Extra Light Italic", () => {
36
+ expect(parseSubfamily("Extra Light Italic")).toEqual({
37
+ style: "italic",
38
+ weight: 200,
39
+ });
40
+ });
41
+ test("Heavy Italic", () => {
42
+ expect(parseSubfamily("Heavy Italic")).toEqual({
43
+ style: "italic",
44
+ weight: 900,
45
+ });
46
+ });
47
+ test("Medium Italic", () => {
48
+ expect(parseSubfamily("Medium Italic")).toEqual({
49
+ style: "italic",
50
+ weight: 500,
51
+ });
52
+ });
53
+ });
54
+
55
+ describe("normalizeFamily()", () => {
56
+ test("basic", () => {
57
+ expect(normalizeFamily("Roboto Black", "Black")).toBe("Roboto");
58
+ expect(normalizeFamily("Roboto Light", "Light Italic")).toBe("Roboto");
59
+ expect(normalizeFamily("Robolder Bold", "Bold")).toBe("Robolder");
60
+ expect(normalizeFamily(" Roboto X Bold ", "Bold")).toBe("Roboto X");
61
+ expect(normalizeFamily(" 'Roboto X' Bold ", "Bold")).toBe("'Roboto X'");
62
+ expect(normalizeFamily(` "Roboto X" Bold `, "Bold")).toBe(`"Roboto X"`);
63
+ expect(normalizeFamily(`"Roboto Bold"`, "Bold")).toBe(`"Roboto Bold"`);
64
+ expect(normalizeFamily(`"Roboto Bold" Bold`, "Bold")).toBe(
65
+ `"Roboto Bold"`
66
+ );
67
+ });
68
+ });
69
+ });
@@ -0,0 +1,74 @@
1
+ import type { FontFormat } from "./schema";
2
+ import { create as createFontKit } from "fontkit";
3
+ import { FontWeight, fontWeights } from "./font-weights";
4
+
5
+ // @todo sumbit this to definitely typed, they are not up to date
6
+ declare module "fontkit" {
7
+ export interface Font {
8
+ type: string;
9
+ getName: (name: string) => string;
10
+ }
11
+ }
12
+
13
+ export const styles = ["normal", "italic", "oblique"] as const;
14
+ type Style = typeof styles[number];
15
+
16
+ export const parseSubfamily = (subfamily: string) => {
17
+ const subfamilyLow = subfamily.toLowerCase();
18
+ let style: Style = "normal";
19
+ for (const possibleStyle of styles) {
20
+ if (subfamilyLow.includes(possibleStyle)) {
21
+ style = possibleStyle;
22
+ break;
23
+ }
24
+ }
25
+
26
+ let weight: FontWeight = "400";
27
+ for (weight in fontWeights) {
28
+ const { name } = fontWeights[weight];
29
+ const { alt } = fontWeights[weight];
30
+ if (subfamilyLow.includes(name) || subfamilyLow.includes(alt)) {
31
+ break;
32
+ }
33
+ }
34
+ return { style, weight: Number(weight) };
35
+ };
36
+
37
+ const splitAndTrim = (string: string) =>
38
+ string
39
+ .split(" ")
40
+ .map((part) => part.trim())
41
+ .filter(Boolean);
42
+
43
+ // Family name can contain additional information like "Roboto Black" or "Roboto Bold", though we need pure family name "Roboto", because the rest is already encoded in weight and style.
44
+ // We need a name we can reference in CSS font-family property, while CSS matches it with the right font-face considering the weight and style.
45
+ export const normalizeFamily = (family: string, subfamily: string) => {
46
+ const familyParts = splitAndTrim(family);
47
+ const subfamilyParts = splitAndTrim(subfamily.toLowerCase());
48
+ const familyPartsNormalized = familyParts.filter(
49
+ (familyPart) => subfamilyParts.includes(familyPart.toLowerCase()) === false
50
+ );
51
+ return familyPartsNormalized.join(" ");
52
+ };
53
+
54
+ type FontData = {
55
+ format: FontFormat;
56
+ family: string;
57
+ style: Style;
58
+ weight: number;
59
+ };
60
+
61
+ export const getFontData = (data: Uint8Array): FontData => {
62
+ const font = createFontKit(data as Buffer);
63
+ const format = font.type.toLowerCase() as FontData["format"];
64
+ const originalFamily = font.getName("fontFamily");
65
+ const subfamily =
66
+ font.getName("preferredSubfamily") ?? font.getName("fontSubfamily");
67
+ const parsedSubfamily = parseSubfamily(subfamily);
68
+ const family = normalizeFamily(originalFamily, subfamily);
69
+ return {
70
+ format,
71
+ family,
72
+ ...parsedSubfamily,
73
+ };
74
+ };
@@ -0,0 +1,52 @@
1
+ export const fontWeights = {
2
+ "100": {
3
+ label: "Thin",
4
+ name: "thin",
5
+ alt: "hairline",
6
+ },
7
+ "200": {
8
+ label: "Extra Light",
9
+ name: "extra light",
10
+ alt: "ultra light",
11
+ },
12
+ "300": {
13
+ label: "Light",
14
+ name: "light",
15
+ alt: "light",
16
+ },
17
+ "400": {
18
+ label: "Normal",
19
+ name: "normal",
20
+ alt: "normal",
21
+ },
22
+ "500": {
23
+ label: "Medium",
24
+ name: "medium",
25
+ alt: "medium",
26
+ },
27
+ "600": {
28
+ label: "Semi Bold",
29
+ name: "semi bold",
30
+ alt: "demi bold",
31
+ },
32
+ "700": {
33
+ label: "Bold",
34
+ name: "bold",
35
+ alt: "bold",
36
+ },
37
+ "800": {
38
+ label: "Extra Bold",
39
+ name: "extra bold",
40
+ alt: "ultra bold",
41
+ },
42
+ "900": {
43
+ label: "Black",
44
+ name: "black",
45
+ alt: "heavy",
46
+ },
47
+ } as const;
48
+
49
+ export type FontWeight = keyof typeof fontWeights;
50
+ export type FontWeightKeyword =
51
+ | typeof fontWeights[FontWeight]["name"]
52
+ | typeof fontWeights[FontWeight]["alt"];
@@ -0,0 +1,75 @@
1
+ import { getFontFaces, type PartialFontAsset } from "./get-font-faces";
2
+
3
+ describe("getFontFaces()", () => {
4
+ test("different formats", () => {
5
+ const assets: Array<PartialFontAsset> = [
6
+ {
7
+ format: "woff",
8
+ meta: {
9
+ family: "Roboto",
10
+ style: "normal",
11
+ weight: 400,
12
+ },
13
+ path: "/fonts/roboto.woff",
14
+ },
15
+ {
16
+ format: "ttf",
17
+ meta: {
18
+ family: "Roboto",
19
+ style: "normal",
20
+ weight: 400,
21
+ },
22
+ path: "/fonts/roboto.ttf",
23
+ },
24
+ ];
25
+ expect(getFontFaces(assets)).toMatchSnapshot();
26
+ });
27
+
28
+ test("different style", () => {
29
+ const assets: Array<PartialFontAsset> = [
30
+ {
31
+ format: "ttf",
32
+ meta: {
33
+ family: "Roboto",
34
+ style: "normal",
35
+ weight: 400,
36
+ },
37
+ path: "/fonts/roboto.ttf",
38
+ },
39
+ {
40
+ format: "ttf",
41
+ meta: {
42
+ family: "Roboto",
43
+ style: "italic",
44
+ weight: 400,
45
+ },
46
+ path: "/fonts/roboto-italic.ttf",
47
+ },
48
+ ];
49
+ expect(getFontFaces(assets)).toMatchSnapshot();
50
+ });
51
+
52
+ test("different weight", () => {
53
+ const assets: Array<PartialFontAsset> = [
54
+ {
55
+ format: "ttf",
56
+ meta: {
57
+ family: "Roboto",
58
+ style: "normal",
59
+ weight: 400,
60
+ },
61
+ path: "/fonts/roboto.ttf",
62
+ },
63
+ {
64
+ format: "ttf",
65
+ meta: {
66
+ family: "Roboto",
67
+ style: "normal",
68
+ weight: 500,
69
+ },
70
+ path: "/fonts/roboto-bold.ttf",
71
+ },
72
+ ];
73
+ expect(getFontFaces(assets)).toMatchSnapshot();
74
+ });
75
+ });
@@ -0,0 +1,53 @@
1
+ import { FONT_FORMATS } from "./constants";
2
+ import type { FontMeta, FontFormat } from "./schema";
3
+
4
+ export type PartialFontAsset = {
5
+ format: FontFormat;
6
+ meta: FontMeta;
7
+ path: string;
8
+ };
9
+
10
+ export type FontFace = {
11
+ fontFamily: string;
12
+ fontStyle: FontMeta["style"];
13
+ fontWeight: number;
14
+ fontDisplay: "swap" | "auto" | "block" | "fallback" | "optional";
15
+ src: string;
16
+ };
17
+
18
+ const formatFace = (asset: PartialFontAsset, format: string) => {
19
+ return {
20
+ fontFamily: asset.meta.family,
21
+ fontStyle: asset.meta.style,
22
+ fontWeight: asset.meta.weight,
23
+ fontDisplay: "swap",
24
+ src: `url('${asset.path}') format('${format}')`,
25
+ };
26
+ };
27
+
28
+ const getKey = (asset: PartialFontAsset) =>
29
+ asset.meta.family + asset.meta.style + asset.meta.weight;
30
+
31
+ export const getFontFaces = (
32
+ assets: Array<PartialFontAsset>
33
+ ): Array<FontFace> => {
34
+ const faces = new Map();
35
+ for (const asset of assets) {
36
+ const face = faces.get(getKey(asset));
37
+ const format = FONT_FORMATS.get(asset.format);
38
+ if (format === undefined) {
39
+ // Should never happen since we allow only uploading formats we support
40
+ continue;
41
+ }
42
+
43
+ if (face === undefined) {
44
+ const face = formatFace(asset, format);
45
+ faces.set(getKey(asset), face);
46
+ continue;
47
+ }
48
+
49
+ // We already have that font face, so we need to add the new src
50
+ face.src += `, url('${asset.path}') format('${format}')`;
51
+ }
52
+ return Array.from(faces.values());
53
+ };
@@ -0,0 +1 @@
1
+ export { getFontData } from "./font-data";
@@ -1,5 +1,4 @@
1
1
  export * from "./constants";
2
2
  export * from "./get-font-faces";
3
- export * from "./types";
3
+ export * from "./schema";
4
4
  export * from "./font-weights";
5
- //# sourceMappingURL=index.d.ts.map
package/src/schema.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ import { styles } from "./font-data";
3
+
4
+ export const FontFormat = z.union([
5
+ z.literal("ttf"),
6
+ z.literal("woff"),
7
+ z.literal("woff2"),
8
+ z.literal("otf"),
9
+ ]);
10
+ export type FontFormat = z.infer<typeof FontFormat>;
11
+
12
+ export const FontMeta = z.object({
13
+ family: z.string(),
14
+ style: z.enum(styles),
15
+ weight: z.number(),
16
+ });
17
+ export type FontMeta = z.infer<typeof FontMeta>;
@@ -1,6 +0,0 @@
1
- import type { FontFormat } from "./types";
2
- export declare const SYSTEM_FONTS: Map<string, string[]>;
3
- export declare const DEFAULT_FONT_FALLBACK = "sans-serif";
4
- export declare const FONT_FORMATS: Map<FontFormat, string>;
5
- export declare const FONT_MIME_TYPES: string;
6
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,YAAY,uBAKvB,CAAC;AAEH,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD,eAAO,MAAM,YAAY,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAK/C,CAAC;AAEH,eAAO,MAAM,eAAe,QAEf,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { FontFormat } from "./types";
2
- declare module "fontkit" {
3
- interface Font {
4
- type: string;
5
- getName: (name: string) => string;
6
- }
7
- }
8
- export declare const styles: readonly ["normal", "italic", "oblique"];
9
- declare type Style = typeof styles[number];
10
- export declare const parseSubfamily: (subfamily: string) => {
11
- style: "normal" | "italic" | "oblique";
12
- weight: number;
13
- };
14
- export declare const normalizeFamily: (family: string, subfamily: string) => string;
15
- declare type FontData = {
16
- format: FontFormat;
17
- family: string;
18
- style: Style;
19
- weight: number;
20
- };
21
- export declare const getFontData: (data: Uint8Array) => FontData;
22
- export {};
23
- //# sourceMappingURL=font-data.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"font-data.d.ts","sourceRoot":"","sources":["../src/font-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAK1C,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,IAAI;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;KACnC;CACF;AAED,eAAO,MAAM,MAAM,0CAA2C,CAAC;AAC/D,aAAK,KAAK,GAAG,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAEnC,eAAO,MAAM,cAAc,cAAe,MAAM;;;CAmB/C,CAAC;AAUF,eAAO,MAAM,eAAe,WAAY,MAAM,aAAa,MAAM,WAOhE,CAAC;AAEF,aAAK,QAAQ,GAAG;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,WAAW,SAAU,UAAU,KAAG,QAa9C,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=font-data.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"font-data.test.d.ts","sourceRoot":"","sources":["../src/font-data.test.ts"],"names":[],"mappings":""}
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const font_data_1 = require("./font-data");
4
- describe("font-data", () => {
5
- describe("parseSubfamily()", () => {
6
- test("Black Italic", () => {
7
- expect((0, font_data_1.parseSubfamily)("Black Italic")).toEqual({
8
- style: "italic",
9
- weight: 900,
10
- });
11
- });
12
- test("Bold", () => {
13
- expect((0, font_data_1.parseSubfamily)("Bold")).toEqual({
14
- style: "normal",
15
- weight: 700,
16
- });
17
- });
18
- test("Demi Bold Italic", () => {
19
- expect((0, font_data_1.parseSubfamily)("Demi Bold Italic")).toEqual({
20
- style: "italic",
21
- weight: 600,
22
- });
23
- });
24
- test("Light", () => {
25
- expect((0, font_data_1.parseSubfamily)("Light")).toEqual({
26
- style: "normal",
27
- weight: 300,
28
- });
29
- });
30
- test("Extra Light", () => {
31
- expect((0, font_data_1.parseSubfamily)("Extra Light")).toEqual({
32
- style: "normal",
33
- weight: 200,
34
- });
35
- });
36
- test("Extra Light Italic", () => {
37
- expect((0, font_data_1.parseSubfamily)("Extra Light Italic")).toEqual({
38
- style: "italic",
39
- weight: 200,
40
- });
41
- });
42
- test("Heavy Italic", () => {
43
- expect((0, font_data_1.parseSubfamily)("Heavy Italic")).toEqual({
44
- style: "italic",
45
- weight: 900,
46
- });
47
- });
48
- test("Medium Italic", () => {
49
- expect((0, font_data_1.parseSubfamily)("Medium Italic")).toEqual({
50
- style: "italic",
51
- weight: 500,
52
- });
53
- });
54
- });
55
- describe("normalizeFamily()", () => {
56
- test("basic", () => {
57
- expect((0, font_data_1.normalizeFamily)("Roboto Black", "Black")).toBe("Roboto");
58
- expect((0, font_data_1.normalizeFamily)("Roboto Light", "Light Italic")).toBe("Roboto");
59
- expect((0, font_data_1.normalizeFamily)("Robolder Bold", "Bold")).toBe("Robolder");
60
- expect((0, font_data_1.normalizeFamily)(" Roboto X Bold ", "Bold")).toBe("Roboto X");
61
- expect((0, font_data_1.normalizeFamily)(" 'Roboto X' Bold ", "Bold")).toBe("'Roboto X'");
62
- expect((0, font_data_1.normalizeFamily)(` "Roboto X" Bold `, "Bold")).toBe(`"Roboto X"`);
63
- expect((0, font_data_1.normalizeFamily)(`"Roboto Bold"`, "Bold")).toBe(`"Roboto Bold"`);
64
- expect((0, font_data_1.normalizeFamily)(`"Roboto Bold" Bold`, "Bold")).toBe(`"Roboto Bold"`);
65
- });
66
- });
67
- });