@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
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ DEFAULT_FONT_FALLBACK: () => DEFAULT_FONT_FALLBACK,
22
+ FONT_FORMATS: () => FONT_FORMATS,
23
+ FONT_MIME_TYPES: () => FONT_MIME_TYPES,
24
+ SYSTEM_FONTS: () => SYSTEM_FONTS
25
+ });
26
+ module.exports = __toCommonJS(constants_exports);
27
+ const SYSTEM_FONTS = /* @__PURE__ */ new Map([
28
+ ["Arial", ["sans-serif"]],
29
+ ["Times New Roman", ["sans"]],
30
+ ["Courier New", ["monospace"]],
31
+ ["system-ui", []]
32
+ ]);
33
+ const DEFAULT_FONT_FALLBACK = "sans-serif";
34
+ const FONT_FORMATS = /* @__PURE__ */ new Map([
35
+ ["woff", "woff"],
36
+ ["woff2", "woff2"],
37
+ ["ttf", "truetype"],
38
+ ["otf", "opentype"]
39
+ ]);
40
+ const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys()).map((format) => `.${format}`).join(", ");
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var font_data_exports = {};
20
+ __export(font_data_exports, {
21
+ getFontData: () => getFontData,
22
+ normalizeFamily: () => normalizeFamily,
23
+ parseSubfamily: () => parseSubfamily,
24
+ styles: () => styles
25
+ });
26
+ module.exports = __toCommonJS(font_data_exports);
27
+ var import_fontkit = require("fontkit");
28
+ var import_font_weights = require("./font-weights");
29
+ const styles = ["normal", "italic", "oblique"];
30
+ const parseSubfamily = (subfamily) => {
31
+ const subfamilyLow = subfamily.toLowerCase();
32
+ let style = "normal";
33
+ for (const possibleStyle of styles) {
34
+ if (subfamilyLow.includes(possibleStyle)) {
35
+ style = possibleStyle;
36
+ break;
37
+ }
38
+ }
39
+ let weight = "400";
40
+ for (weight in import_font_weights.fontWeights) {
41
+ const { name } = import_font_weights.fontWeights[weight];
42
+ const { alt } = import_font_weights.fontWeights[weight];
43
+ if (subfamilyLow.includes(name) || subfamilyLow.includes(alt)) {
44
+ break;
45
+ }
46
+ }
47
+ return { style, weight: Number(weight) };
48
+ };
49
+ const splitAndTrim = (string) => string.split(" ").map((part) => part.trim()).filter(Boolean);
50
+ const normalizeFamily = (family, subfamily) => {
51
+ const familyParts = splitAndTrim(family);
52
+ const subfamilyParts = splitAndTrim(subfamily.toLowerCase());
53
+ const familyPartsNormalized = familyParts.filter(
54
+ (familyPart) => subfamilyParts.includes(familyPart.toLowerCase()) === false
55
+ );
56
+ return familyPartsNormalized.join(" ");
57
+ };
58
+ const getFontData = (data) => {
59
+ const font = (0, import_fontkit.create)(data);
60
+ const format = font.type.toLowerCase();
61
+ const originalFamily = font.getName("fontFamily");
62
+ const subfamily = font.getName("preferredSubfamily") ?? font.getName("fontSubfamily");
63
+ const parsedSubfamily = parseSubfamily(subfamily);
64
+ const family = normalizeFamily(originalFamily, subfamily);
65
+ return {
66
+ format,
67
+ family,
68
+ ...parsedSubfamily
69
+ };
70
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var font_weights_exports = {};
20
+ __export(font_weights_exports, {
21
+ fontWeights: () => fontWeights
22
+ });
23
+ module.exports = __toCommonJS(font_weights_exports);
24
+ const fontWeights = {
25
+ "100": {
26
+ label: "Thin",
27
+ name: "thin",
28
+ alt: "hairline"
29
+ },
30
+ "200": {
31
+ label: "Extra Light",
32
+ name: "extra light",
33
+ alt: "ultra light"
34
+ },
35
+ "300": {
36
+ label: "Light",
37
+ name: "light",
38
+ alt: "light"
39
+ },
40
+ "400": {
41
+ label: "Normal",
42
+ name: "normal",
43
+ alt: "normal"
44
+ },
45
+ "500": {
46
+ label: "Medium",
47
+ name: "medium",
48
+ alt: "medium"
49
+ },
50
+ "600": {
51
+ label: "Semi Bold",
52
+ name: "semi bold",
53
+ alt: "demi bold"
54
+ },
55
+ "700": {
56
+ label: "Bold",
57
+ name: "bold",
58
+ alt: "bold"
59
+ },
60
+ "800": {
61
+ label: "Extra Bold",
62
+ name: "extra bold",
63
+ alt: "ultra bold"
64
+ },
65
+ "900": {
66
+ label: "Black",
67
+ name: "black",
68
+ alt: "heavy"
69
+ }
70
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var get_font_faces_exports = {};
20
+ __export(get_font_faces_exports, {
21
+ getFontFaces: () => getFontFaces
22
+ });
23
+ module.exports = __toCommonJS(get_font_faces_exports);
24
+ var import_constants = require("./constants");
25
+ const formatFace = (asset, format) => {
26
+ return {
27
+ fontFamily: asset.meta.family,
28
+ fontStyle: asset.meta.style,
29
+ fontWeight: asset.meta.weight,
30
+ fontDisplay: "swap",
31
+ src: `url('${asset.path}') format('${format}')`
32
+ };
33
+ };
34
+ const getKey = (asset) => asset.meta.family + asset.meta.style + asset.meta.weight;
35
+ const getFontFaces = (assets) => {
36
+ const faces = /* @__PURE__ */ new Map();
37
+ for (const asset of assets) {
38
+ const face = faces.get(getKey(asset));
39
+ const format = import_constants.FONT_FORMATS.get(asset.format);
40
+ if (format === void 0) {
41
+ continue;
42
+ }
43
+ if (face === void 0) {
44
+ const face2 = formatFace(asset, format);
45
+ faces.set(getKey(asset), face2);
46
+ continue;
47
+ }
48
+ face.src += `, url('${asset.path}') format('${format}')`;
49
+ }
50
+ return Array.from(faces.values());
51
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./constants"), module.exports);
19
+ __reExport(src_exports, require("./get-font-faces"), module.exports);
20
+ __reExport(src_exports, require("./schema"), module.exports);
21
+ __reExport(src_exports, require("./font-weights"), module.exports);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_server_exports = {};
20
+ __export(index_server_exports, {
21
+ getFontData: () => import_font_data.getFontData
22
+ });
23
+ module.exports = __toCommonJS(index_server_exports);
24
+ var import_font_data = require("./font-data");
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var schema_exports = {};
20
+ __export(schema_exports, {
21
+ FontFormat: () => FontFormat,
22
+ FontMeta: () => FontMeta
23
+ });
24
+ module.exports = __toCommonJS(schema_exports);
25
+ var import_zod = require("zod");
26
+ var import_font_data = require("./font-data");
27
+ const FontFormat = import_zod.z.union([
28
+ import_zod.z.literal("ttf"),
29
+ import_zod.z.literal("woff"),
30
+ import_zod.z.literal("woff2"),
31
+ import_zod.z.literal("otf")
32
+ ]);
33
+ const FontMeta = import_zod.z.object({
34
+ family: import_zod.z.string(),
35
+ style: import_zod.z.enum(import_font_data.styles),
36
+ weight: import_zod.z.number()
37
+ });
package/lib/constants.js CHANGED
@@ -1,19 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FONT_MIME_TYPES = exports.FONT_FORMATS = exports.DEFAULT_FONT_FALLBACK = exports.SYSTEM_FONTS = void 0;
4
- exports.SYSTEM_FONTS = new Map([
5
- ["Arial", ["sans-serif"]],
6
- ["Times New Roman", ["sans"]],
7
- ["Courier New", ["monospace"]],
8
- ["system-ui", []],
1
+ const SYSTEM_FONTS = /* @__PURE__ */ new Map([
2
+ ["Arial", ["sans-serif"]],
3
+ ["Times New Roman", ["sans"]],
4
+ ["Courier New", ["monospace"]],
5
+ ["system-ui", []]
9
6
  ]);
10
- exports.DEFAULT_FONT_FALLBACK = "sans-serif";
11
- exports.FONT_FORMATS = new Map([
12
- ["woff", "woff"],
13
- ["woff2", "woff2"],
14
- ["ttf", "truetype"],
15
- ["otf", "opentype"],
7
+ const DEFAULT_FONT_FALLBACK = "sans-serif";
8
+ const FONT_FORMATS = /* @__PURE__ */ new Map([
9
+ ["woff", "woff"],
10
+ ["woff2", "woff2"],
11
+ ["ttf", "truetype"],
12
+ ["otf", "opentype"]
16
13
  ]);
17
- exports.FONT_MIME_TYPES = Array.from(exports.FONT_FORMATS.keys())
18
- .map((format) => `.${format}`)
19
- .join(", ");
14
+ const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys()).map((format) => `.${format}`).join(", ");
15
+ export {
16
+ DEFAULT_FONT_FALLBACK,
17
+ FONT_FORMATS,
18
+ FONT_MIME_TYPES,
19
+ SYSTEM_FONTS
20
+ };
package/lib/font-data.js CHANGED
@@ -1,56 +1,50 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFontData = exports.normalizeFamily = exports.parseSubfamily = exports.styles = void 0;
7
- const fontkit_1 = __importDefault(require("fontkit"));
8
- const font_weights_1 = require("./font-weights");
9
- exports.styles = ["normal", "italic", "oblique"];
1
+ import { create as createFontKit } from "fontkit";
2
+ import { fontWeights } from "./font-weights";
3
+ const styles = ["normal", "italic", "oblique"];
10
4
  const parseSubfamily = (subfamily) => {
11
- const subfamilyLow = subfamily.toLowerCase();
12
- let style = "normal";
13
- for (const possibleStyle of exports.styles) {
14
- if (subfamilyLow.includes(possibleStyle)) {
15
- style = possibleStyle;
16
- break;
17
- }
5
+ const subfamilyLow = subfamily.toLowerCase();
6
+ let style = "normal";
7
+ for (const possibleStyle of styles) {
8
+ if (subfamilyLow.includes(possibleStyle)) {
9
+ style = possibleStyle;
10
+ break;
18
11
  }
19
- let weight = "400";
20
- for (weight in font_weights_1.fontWeights) {
21
- const { name } = font_weights_1.fontWeights[weight];
22
- const { alt } = font_weights_1.fontWeights[weight];
23
- if (subfamilyLow.includes(name) || subfamilyLow.includes(alt)) {
24
- break;
25
- }
12
+ }
13
+ let weight = "400";
14
+ for (weight in fontWeights) {
15
+ const { name } = fontWeights[weight];
16
+ const { alt } = fontWeights[weight];
17
+ if (subfamilyLow.includes(name) || subfamilyLow.includes(alt)) {
18
+ break;
26
19
  }
27
- return { style, weight: Number(weight) };
20
+ }
21
+ return { style, weight: Number(weight) };
28
22
  };
29
- exports.parseSubfamily = parseSubfamily;
30
- const splitAndTrim = (string) => string
31
- .split(" ")
32
- .map((part) => part.trim())
33
- .filter(Boolean);
34
- // 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.
35
- // 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.
23
+ const splitAndTrim = (string) => string.split(" ").map((part) => part.trim()).filter(Boolean);
36
24
  const normalizeFamily = (family, subfamily) => {
37
- const familyParts = splitAndTrim(family);
38
- const subfamilyParts = splitAndTrim(subfamily.toLowerCase());
39
- const familyPartsNormalized = familyParts.filter((familyPart) => subfamilyParts.includes(familyPart.toLowerCase()) === false);
40
- return familyPartsNormalized.join(" ");
25
+ const familyParts = splitAndTrim(family);
26
+ const subfamilyParts = splitAndTrim(subfamily.toLowerCase());
27
+ const familyPartsNormalized = familyParts.filter(
28
+ (familyPart) => subfamilyParts.includes(familyPart.toLowerCase()) === false
29
+ );
30
+ return familyPartsNormalized.join(" ");
41
31
  };
42
- exports.normalizeFamily = normalizeFamily;
43
32
  const getFontData = (data) => {
44
- const font = fontkit_1.default.create(data);
45
- const format = font.type.toLowerCase();
46
- const originalFamily = font.getName("fontFamily");
47
- const subfamily = font.getName("preferredSubfamily") ?? font.getName("fontSubfamily");
48
- const parsedSubfamily = (0, exports.parseSubfamily)(subfamily);
49
- const family = (0, exports.normalizeFamily)(originalFamily, subfamily);
50
- return {
51
- format,
52
- family,
53
- ...parsedSubfamily,
54
- };
33
+ const font = createFontKit(data);
34
+ const format = font.type.toLowerCase();
35
+ const originalFamily = font.getName("fontFamily");
36
+ const subfamily = font.getName("preferredSubfamily") ?? font.getName("fontSubfamily");
37
+ const parsedSubfamily = parseSubfamily(subfamily);
38
+ const family = normalizeFamily(originalFamily, subfamily);
39
+ return {
40
+ format,
41
+ family,
42
+ ...parsedSubfamily
43
+ };
44
+ };
45
+ export {
46
+ getFontData,
47
+ normalizeFamily,
48
+ parseSubfamily,
49
+ styles
55
50
  };
56
- exports.getFontData = getFontData;
@@ -1,50 +1,50 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fontWeights = void 0;
4
- exports.fontWeights = {
5
- "100": {
6
- label: "Thin",
7
- name: "thin",
8
- alt: "hairline",
9
- },
10
- "200": {
11
- label: "Extra Light",
12
- name: "extra light",
13
- alt: "ultra light",
14
- },
15
- "300": {
16
- label: "Light",
17
- name: "light",
18
- alt: "light",
19
- },
20
- "400": {
21
- label: "Normal",
22
- name: "normal",
23
- alt: "normal",
24
- },
25
- "500": {
26
- label: "Medium",
27
- name: "medium",
28
- alt: "medium",
29
- },
30
- "600": {
31
- label: "Semi Bold",
32
- name: "semi bold",
33
- alt: "demi bold",
34
- },
35
- "700": {
36
- label: "Bold",
37
- name: "bold",
38
- alt: "bold",
39
- },
40
- "800": {
41
- label: "Extra Bold",
42
- name: "extra bold",
43
- alt: "ultra bold",
44
- },
45
- "900": {
46
- label: "Black",
47
- name: "black",
48
- alt: "heavy",
49
- },
1
+ 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
+ };
48
+ export {
49
+ fontWeights
50
50
  };
@@ -1,34 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFontFaces = void 0;
4
- const constants_1 = require("./constants");
1
+ import { FONT_FORMATS } from "./constants";
5
2
  const formatFace = (asset, format) => {
6
- return {
7
- fontFamily: asset.meta.family,
8
- fontStyle: asset.meta.style,
9
- fontWeight: asset.meta.weight,
10
- fontDisplay: "swap",
11
- src: `url('${asset.path}') format('${format}')`,
12
- };
3
+ return {
4
+ fontFamily: asset.meta.family,
5
+ fontStyle: asset.meta.style,
6
+ fontWeight: asset.meta.weight,
7
+ fontDisplay: "swap",
8
+ src: `url('${asset.path}') format('${format}')`
9
+ };
13
10
  };
14
11
  const getKey = (asset) => asset.meta.family + asset.meta.style + asset.meta.weight;
15
12
  const getFontFaces = (assets) => {
16
- const faces = new Map();
17
- for (const asset of assets) {
18
- const face = faces.get(getKey(asset));
19
- const format = constants_1.FONT_FORMATS.get(asset.format);
20
- if (format === undefined) {
21
- // Should never happen since we allow only uploading formats we support
22
- continue;
23
- }
24
- if (face === undefined) {
25
- const face = formatFace(asset, format);
26
- faces.set(getKey(asset), face);
27
- continue;
28
- }
29
- // We already have that font face, so we need to add the new src
30
- face.src += `, url('${asset.path}') format('${format}')`;
13
+ const faces = /* @__PURE__ */ new Map();
14
+ for (const asset of assets) {
15
+ const face = faces.get(getKey(asset));
16
+ const format = FONT_FORMATS.get(asset.format);
17
+ if (format === void 0) {
18
+ continue;
31
19
  }
32
- return Array.from(faces.values());
20
+ if (face === void 0) {
21
+ const face2 = formatFace(asset, format);
22
+ faces.set(getKey(asset), face2);
23
+ continue;
24
+ }
25
+ face.src += `, url('${asset.path}') format('${format}')`;
26
+ }
27
+ return Array.from(faces.values());
28
+ };
29
+ export {
30
+ getFontFaces
33
31
  };
34
- exports.getFontFaces = getFontFaces;
package/lib/index.js CHANGED
@@ -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);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants"), exports);
18
- __exportStar(require("./get-font-faces"), exports);
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./font-weights"), exports);
1
+ export * from "./constants";
2
+ export * from "./get-font-faces";
3
+ export * from "./schema";
4
+ export * from "./font-weights";