@webstudio-is/fonts 0.2.0 → 0.15.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.
- package/lib/cjs/constants.cjs +37 -16
- package/lib/cjs/font-data.cjs +61 -44
- package/lib/cjs/font-weights.cjs +68 -48
- package/lib/cjs/get-font-faces.cjs +44 -27
- package/lib/cjs/index.cjs +19 -18
- package/lib/cjs/index.server.cjs +22 -18
- package/lib/cjs/schema.cjs +35 -8
- package/lib/constants.js +18 -14
- package/lib/font-data.js +43 -40
- package/lib/font-weights.js +49 -46
- package/lib/get-font-faces.js +25 -24
- package/lib/index.js +1 -1
- package/lib/index.server.js +4 -2
- package/lib/schema.js +14 -4
- package/package.json +7 -16
- package/src/__snapshots__/get-font-faces.test.ts.snap +51 -0
- package/src/constants.ts +21 -0
- package/src/font-data.test.ts +69 -0
- package/src/font-data.ts +74 -0
- package/src/font-weights.ts +52 -0
- package/src/get-font-faces.test.ts +75 -0
- package/src/get-font-faces.ts +53 -0
- package/src/index.server.ts +1 -0
- package/{lib/cjs/index.d.ts → src/index.ts} +1 -2
- package/src/schema.ts +17 -0
- package/lib/cjs/constants.d.ts +0 -6
- package/lib/cjs/constants.d.ts.map +0 -1
- package/lib/cjs/font-data.d.ts +0 -23
- package/lib/cjs/font-data.d.ts.map +0 -1
- package/lib/cjs/font-data.test.cjs +0 -67
- package/lib/cjs/font-data.test.d.ts +0 -2
- package/lib/cjs/font-data.test.d.ts.map +0 -1
- package/lib/cjs/font-weights.d.ts +0 -50
- package/lib/cjs/font-weights.d.ts.map +0 -1
- package/lib/cjs/get-font-faces.d.ts +0 -16
- package/lib/cjs/get-font-faces.d.ts.map +0 -1
- package/lib/cjs/get-font-faces.test.cjs +0 -74
- package/lib/cjs/get-font-faces.test.d.ts +0 -2
- package/lib/cjs/get-font-faces.test.d.ts.map +0 -1
- package/lib/cjs/index.d.ts.map +0 -1
- package/lib/cjs/index.server.d.ts +0 -3
- package/lib/cjs/index.server.d.ts.map +0 -1
- package/lib/cjs/schema.d.ts +0 -16
- package/lib/cjs/schema.d.ts.map +0 -1
- package/lib/cjs/types.cjs +0 -2
- package/lib/cjs/types.d.ts +0 -2
- package/lib/cjs/types.d.ts.map +0 -1
- package/lib/constants.d.ts +0 -6
- package/lib/constants.d.ts.map +0 -1
- package/lib/font-data.d.ts +0 -23
- package/lib/font-data.d.ts.map +0 -1
- package/lib/font-data.test.d.ts +0 -2
- package/lib/font-data.test.d.ts.map +0 -1
- package/lib/font-data.test.js +0 -65
- package/lib/font-weights.d.ts +0 -50
- package/lib/font-weights.d.ts.map +0 -1
- package/lib/get-font-faces.d.ts +0 -16
- package/lib/get-font-faces.d.ts.map +0 -1
- package/lib/get-font-faces.test.d.ts +0 -2
- package/lib/get-font-faces.test.d.ts.map +0 -1
- package/lib/get-font-faces.test.js +0 -72
- package/lib/index.d.ts +0 -5
- package/lib/index.d.ts.map +0 -1
- package/lib/index.server.d.ts +0 -3
- package/lib/index.server.d.ts.map +0 -1
- package/lib/schema.d.ts +0 -16
- package/lib/schema.d.ts.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types.d.ts +0 -2
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -1
package/lib/cjs/constants.cjs
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
.map((format) => `.${format}`)
|
|
19
|
-
.join(", ");
|
|
40
|
+
const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys()).map((format) => `.${format}`).join(", ");
|
package/lib/cjs/font-data.cjs
CHANGED
|
@@ -1,53 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
46
|
+
}
|
|
47
|
+
return { style, weight: Number(weight) };
|
|
25
48
|
};
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
package/lib/cjs/font-weights.cjs
CHANGED
|
@@ -1,50 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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);
|
package/lib/cjs/index.server.cjs
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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");
|
package/lib/cjs/schema.cjs
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
20
|
+
}
|
|
21
|
+
return { style, weight: Number(weight) };
|
|
22
22
|
};
|
|
23
|
-
const splitAndTrim = (string) => string
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
};
|