@webstudio-is/fonts 0.2.0 → 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 (71) hide show
  1. package/lib/cjs/constants.cjs +37 -16
  2. package/lib/cjs/font-data.cjs +61 -44
  3. package/lib/cjs/font-weights.cjs +68 -48
  4. package/lib/cjs/get-font-faces.cjs +44 -27
  5. package/lib/cjs/index.cjs +19 -18
  6. package/lib/cjs/index.server.cjs +22 -18
  7. package/lib/cjs/schema.cjs +35 -8
  8. package/lib/constants.js +18 -14
  9. package/lib/font-data.js +43 -40
  10. package/lib/font-weights.js +49 -46
  11. package/lib/get-font-faces.js +25 -24
  12. package/lib/index.js +1 -1
  13. package/lib/index.server.js +4 -2
  14. package/lib/schema.js +14 -4
  15. package/package.json +7 -16
  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/cjs/index.d.ts → src/index.ts} +1 -2
  25. package/src/schema.ts +17 -0
  26. package/lib/cjs/constants.d.ts +0 -6
  27. package/lib/cjs/constants.d.ts.map +0 -1
  28. package/lib/cjs/font-data.d.ts +0 -23
  29. package/lib/cjs/font-data.d.ts.map +0 -1
  30. package/lib/cjs/font-data.test.cjs +0 -67
  31. package/lib/cjs/font-data.test.d.ts +0 -2
  32. package/lib/cjs/font-data.test.d.ts.map +0 -1
  33. package/lib/cjs/font-weights.d.ts +0 -50
  34. package/lib/cjs/font-weights.d.ts.map +0 -1
  35. package/lib/cjs/get-font-faces.d.ts +0 -16
  36. package/lib/cjs/get-font-faces.d.ts.map +0 -1
  37. package/lib/cjs/get-font-faces.test.cjs +0 -74
  38. package/lib/cjs/get-font-faces.test.d.ts +0 -2
  39. package/lib/cjs/get-font-faces.test.d.ts.map +0 -1
  40. package/lib/cjs/index.d.ts.map +0 -1
  41. package/lib/cjs/index.server.d.ts +0 -3
  42. package/lib/cjs/index.server.d.ts.map +0 -1
  43. package/lib/cjs/schema.d.ts +0 -16
  44. package/lib/cjs/schema.d.ts.map +0 -1
  45. package/lib/cjs/types.cjs +0 -2
  46. package/lib/cjs/types.d.ts +0 -2
  47. package/lib/cjs/types.d.ts.map +0 -1
  48. package/lib/constants.d.ts +0 -6
  49. package/lib/constants.d.ts.map +0 -1
  50. package/lib/font-data.d.ts +0 -23
  51. package/lib/font-data.d.ts.map +0 -1
  52. package/lib/font-data.test.d.ts +0 -2
  53. package/lib/font-data.test.d.ts.map +0 -1
  54. package/lib/font-data.test.js +0 -65
  55. package/lib/font-weights.d.ts +0 -50
  56. package/lib/font-weights.d.ts.map +0 -1
  57. package/lib/get-font-faces.d.ts +0 -16
  58. package/lib/get-font-faces.d.ts.map +0 -1
  59. package/lib/get-font-faces.test.d.ts +0 -2
  60. package/lib/get-font-faces.test.d.ts.map +0 -1
  61. package/lib/get-font-faces.test.js +0 -72
  62. package/lib/index.d.ts +0 -5
  63. package/lib/index.d.ts.map +0 -1
  64. package/lib/index.server.d.ts +0 -3
  65. package/lib/index.server.d.ts.map +0 -1
  66. package/lib/schema.d.ts +0 -16
  67. package/lib/schema.d.ts.map +0 -1
  68. package/lib/tsconfig.tsbuildinfo +0 -1
  69. package/lib/types.d.ts +0 -2
  70. package/lib/types.d.ts.map +0 -1
  71. package/lib/types.js +0 -1
@@ -1,19 +1,40 @@
1
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", []],
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", []]
9
32
  ]);
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"],
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"]
16
39
  ]);
17
- exports.FONT_MIME_TYPES = Array.from(exports.FONT_FORMATS.keys())
18
- .map((format) => `.${format}`)
19
- .join(", ");
40
+ const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys()).map((format) => `.${format}`).join(", ");
@@ -1,53 +1,70 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFontData = exports.normalizeFamily = exports.parseSubfamily = exports.styles = void 0;
4
- const fontkit_1 = require("fontkit");
5
- const font_weights_1 = require("./font-weights");
6
- exports.styles = ["normal", "italic", "oblique"];
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"];
7
30
  const parseSubfamily = (subfamily) => {
8
- const subfamilyLow = subfamily.toLowerCase();
9
- let style = "normal";
10
- for (const possibleStyle of exports.styles) {
11
- if (subfamilyLow.includes(possibleStyle)) {
12
- style = possibleStyle;
13
- break;
14
- }
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;
15
37
  }
16
- let weight = "400";
17
- for (weight in font_weights_1.fontWeights) {
18
- const { name } = font_weights_1.fontWeights[weight];
19
- const { alt } = font_weights_1.fontWeights[weight];
20
- if (subfamilyLow.includes(name) || subfamilyLow.includes(alt)) {
21
- break;
22
- }
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;
23
45
  }
24
- return { style, weight: Number(weight) };
46
+ }
47
+ return { style, weight: Number(weight) };
25
48
  };
26
- exports.parseSubfamily = parseSubfamily;
27
- const splitAndTrim = (string) => string
28
- .split(" ")
29
- .map((part) => part.trim())
30
- .filter(Boolean);
31
- // 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.
32
- // 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.
49
+ const splitAndTrim = (string) => string.split(" ").map((part) => part.trim()).filter(Boolean);
33
50
  const normalizeFamily = (family, subfamily) => {
34
- const familyParts = splitAndTrim(family);
35
- const subfamilyParts = splitAndTrim(subfamily.toLowerCase());
36
- const familyPartsNormalized = familyParts.filter((familyPart) => subfamilyParts.includes(familyPart.toLowerCase()) === false);
37
- return familyPartsNormalized.join(" ");
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(" ");
38
57
  };
39
- exports.normalizeFamily = normalizeFamily;
40
58
  const getFontData = (data) => {
41
- const font = (0, fontkit_1.create)(data);
42
- const format = font.type.toLowerCase();
43
- const originalFamily = font.getName("fontFamily");
44
- const subfamily = font.getName("preferredSubfamily") ?? font.getName("fontSubfamily");
45
- const parsedSubfamily = (0, exports.parseSubfamily)(subfamily);
46
- const family = (0, exports.normalizeFamily)(originalFamily, subfamily);
47
- return {
48
- format,
49
- family,
50
- ...parsedSubfamily,
51
- };
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
+ };
52
70
  };
53
- exports.getFontData = getFontData;
@@ -1,50 +1,70 @@
1
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
- },
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
+ }
50
70
  };
@@ -1,34 +1,51 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFontFaces = void 0;
4
- const constants_1 = require("./constants");
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");
5
25
  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
- };
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
+ };
13
33
  };
14
34
  const getKey = (asset) => asset.meta.family + asset.meta.style + asset.meta.weight;
15
35
  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}')`;
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;
31
47
  }
32
- return Array.from(faces.values());
48
+ face.src += `, url('${asset.path}') format('${format}')`;
49
+ }
50
+ return Array.from(faces.values());
33
51
  };
34
- exports.getFontFaces = getFontFaces;
package/lib/cjs/index.cjs CHANGED
@@ -1,20 +1,21 @@
1
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);
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;
15
13
  };
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);
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);
@@ -1,20 +1,24 @@
1
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);
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 });
15
9
  };
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);
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");
@@ -1,10 +1,37 @@
1
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(),
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()
10
37
  });
package/lib/constants.js CHANGED
@@ -1,16 +1,20 @@
1
- export const SYSTEM_FONTS = new Map([
2
- ["Arial", ["sans-serif"]],
3
- ["Times New Roman", ["sans"]],
4
- ["Courier New", ["monospace"]],
5
- ["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", []]
6
6
  ]);
7
- export const DEFAULT_FONT_FALLBACK = "sans-serif";
8
- export const FONT_FORMATS = new Map([
9
- ["woff", "woff"],
10
- ["woff2", "woff2"],
11
- ["ttf", "truetype"],
12
- ["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"]
13
13
  ]);
14
- export const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys())
15
- .map((format) => `.${format}`)
16
- .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,47 +1,50 @@
1
1
  import { create as createFontKit } from "fontkit";
2
2
  import { fontWeights } from "./font-weights";
3
- export const styles = ["normal", "italic", "oblique"];
4
- export const parseSubfamily = (subfamily) => {
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;
11
- }
3
+ const styles = ["normal", "italic", "oblique"];
4
+ const parseSubfamily = (subfamily) => {
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;
12
11
  }
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;
19
- }
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;
20
19
  }
21
- return { style, weight: Number(weight) };
20
+ }
21
+ return { style, weight: Number(weight) };
22
22
  };
23
- const splitAndTrim = (string) => string
24
- .split(" ")
25
- .map((part) => part.trim())
26
- .filter(Boolean);
27
- // 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.
28
- // 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.
29
- export const normalizeFamily = (family, subfamily) => {
30
- const familyParts = splitAndTrim(family);
31
- const subfamilyParts = splitAndTrim(subfamily.toLowerCase());
32
- const familyPartsNormalized = familyParts.filter((familyPart) => subfamilyParts.includes(familyPart.toLowerCase()) === false);
33
- return familyPartsNormalized.join(" ");
23
+ const splitAndTrim = (string) => string.split(" ").map((part) => part.trim()).filter(Boolean);
24
+ const normalizeFamily = (family, subfamily) => {
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(" ");
34
31
  };
35
- export const getFontData = (data) => {
36
- const font = createFontKit(data);
37
- const format = font.type.toLowerCase();
38
- const originalFamily = font.getName("fontFamily");
39
- const subfamily = font.getName("preferredSubfamily") ?? font.getName("fontSubfamily");
40
- const parsedSubfamily = parseSubfamily(subfamily);
41
- const family = normalizeFamily(originalFamily, subfamily);
42
- return {
43
- format,
44
- family,
45
- ...parsedSubfamily,
46
- };
32
+ const getFontData = (data) => {
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
47
50
  };