Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Move font parsing into asset uploader (#2242)
Bogdan Chadkinf506312a0d6d
diff --git a/packages/asset-uploader/package.json b/packages/asset-uploader/package.jsonindex 8da76e52ff..f82aabc12f 100644--- a/packages/asset-uploader/package.json+++ b/packages/asset-uploader/package.json@@ -20,6 +20,7 @@"@webstudio-is/prisma-client": "workspace:^","@webstudio-is/sdk": "workspace:^","@webstudio-is/trpc-interface": "workspace:^",+ "fontkit": "^2.0.2","immer": "^10.0.2","nanoid": "^4.0.2","sharp": "^0.30.7",@@ -27,6 +28,7 @@},"devDependencies": {"@jest/globals": "^29.6.4",+ "@types/fontkit": "^2.0.3","@types/node": "^18.11.18","@types/sharp": "^0.30.4","@webstudio-is/jest-config": "workspace:^",diff --git a/packages/fonts/src/font-data.test.ts b/packages/asset-uploader/src/utils/font-data.test.tssimilarity index 100%rename from packages/fonts/src/font-data.test.tsrename to packages/asset-uploader/src/utils/font-data.test.tsdiff --git a/packages/fonts/src/font-data.ts b/packages/asset-uploader/src/utils/font-data.tssimilarity index 88%rename from packages/fonts/src/font-data.tsrename to packages/asset-uploader/src/utils/font-data.tsindex de4ea2f7a9..0ced10e322 100644--- a/packages/fonts/src/font-data.ts+++ b/packages/asset-uploader/src/utils/font-data.ts@@ -1,6 +1,12 @@-import type { FontFormat, VariationAxes } from "./schema";import { create as createFontKit } from "fontkit";-import { type FontWeight, fontWeights } from "./font-weights";+import {+ fontWeights,+ FONT_STYLES,+ type FontFormat,+ type FontWeight,+ type VariationAxes,+ type FontStyle,+} from "@webstudio-is/fonts";// @todo sumbit this to definitely typed, they are not up to datedeclare module "fontkit" {@@ -11,13 +17,10 @@ declare module "fontkit" {}}-export const styles = ["normal", "italic", "oblique"] as const;-type Style = (typeof styles)[number];-export const parseSubfamily = (subfamily: string) => {const subfamilyLow = subfamily.toLowerCase();- let style: Style = "normal";- for (const possibleStyle of styles) {+ let style: FontStyle = "normal";+ for (const possibleStyle of FONT_STYLES) {if (subfamilyLow.includes(possibleStyle)) {style = possibleStyle;break;@@ -53,7 +56,7 @@ export const normalizeFamily = (family: string, subfamily: string) => {type FontDataStatic = {format: FontFormat;family: string;- style: Style;+ style: FontStyle;weight: number;};type FontDataVariable = {diff --git a/packages/asset-uploader/src/utils/get-asset-data.ts b/packages/asset-uploader/src/utils/get-asset-data.tsindex 5ca3c5e5a2..b383ef8bd6 100644--- a/packages/asset-uploader/src/utils/get-asset-data.ts+++ b/packages/asset-uploader/src/utils/get-asset-data.ts@@ -1,8 +1,8 @@import { z } from "zod";import sharp from "sharp";import { FontMeta } from "@webstudio-is/fonts";-import { getFontData } from "@webstudio-is/fonts/index.server";import { ImageMeta } from "@webstudio-is/sdk";+import { getFontData } from "./font-data";export const AssetData = z.object({size: z.number(),diff --git a/packages/fonts/package.json b/packages/fonts/package.jsonindex 139d4e2e57..7a11620bab 100644--- a/packages/fonts/package.json+++ b/packages/fonts/package.json@@ -13,13 +13,8 @@"build": "build-package","dts": "tsc --project tsconfig.dts.json"},- "dependencies": {- "fontkit": "^2.0.2"- },"devDependencies": {"@jest/globals": "^29.6.4",- "@types/fontkit": "^2.0.1",- "@webstudio-is/design-system": "workspace:^","@webstudio-is/jest-config": "workspace:^","@webstudio-is/scripts": "workspace:^","@webstudio-is/tsconfig": "workspace:^",@@ -31,17 +26,10 @@"zod": "^3.19.1"},"exports": {- ".": {- "source": "./src/index.ts",- "types": "./lib/types/index.d.ts",- "import": "./lib/index.js",- "require": "./lib/cjs/index.js"- },- "./index.server": {- "source": "./src/index.server.ts",- "types": "./lib/types/index.server.d.ts",- "import": "./lib/index.server.js"- }+ "source": "./src/index.ts",+ "types": "./lib/types/index.d.ts",+ "import": "./lib/index.js",+ "require": "./lib/cjs/index.js"},"files": ["lib/*",diff --git a/packages/fonts/src/constants.ts b/packages/fonts/src/constants.tsindex 3b851acd30..8d8421af68 100644--- a/packages/fonts/src/constants.ts+++ b/packages/fonts/src/constants.ts@@ -19,3 +19,6 @@ export const FONT_FORMATS: Map<FontFormat, string> = new Map([export const FONT_MIME_TYPES = Array.from(FONT_FORMATS.keys()).map((format) => `.${format}`).join(", ");++export const FONT_STYLES = ["normal", "italic", "oblique"] as const;+export type FontStyle = (typeof FONT_STYLES)[number];diff --git a/packages/fonts/src/index.server.ts b/packages/fonts/src/index.server.tsdeleted file mode 100644index 7393f18191..0000000000--- a/packages/fonts/src/index.server.ts+++ /dev/null@@ -1 +0,0 @@-export { getFontData } from "./font-data";diff --git a/packages/fonts/src/schema.ts b/packages/fonts/src/schema.tsindex 3d49a03f3e..d269a735ff 100644--- a/packages/fonts/src/schema.ts+++ b/packages/fonts/src/schema.ts@@ -1,5 +1,5 @@import { z } from "zod";-import { styles } from "./font-data";+import { FONT_STYLES } from "./constants";export const FontFormat = z.union([z.literal("ttf"),@@ -40,7 +40,7 @@ export type VariationAxes = z.infer<typeof VariationAxes>;export const FontMetaStatic = z.object({family: z.string(),- style: z.enum(styles),+ style: z.enum(FONT_STYLES),weight: z.number(),});diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex e8a67bd04e..e79a114918 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -379,6 +379,9 @@ importers:'@webstudio-is/trpc-interface':specifier: workspace:^version: link:../trpc-interface+ fontkit:+ specifier: ^2.0.2+ version: 2.0.2immer:specifier: ^10.0.2version: 10.0.2@@ -395,6 +398,9 @@ importers:'@jest/globals':specifier: ^29.6.4version: 29.6.4+ '@types/fontkit':+ specifier: ^2.0.3+ version: 2.0.3'@types/node':specifier: ^18.11.18version: 18.13.0@@ -881,20 +887,10 @@ importers:version: link:../tsconfigpackages/fonts:- dependencies:- fontkit:- specifier: ^2.0.2- version: 2.0.2devDependencies:'@jest/globals':specifier: ^29.6.4version: 29.6.4- '@types/fontkit':- specifier: ^2.0.1- version: 2.0.1- '@webstudio-is/design-system':- specifier: workspace:^- version: link:../design-system'@webstudio-is/jest-config':specifier: workspace:^version: link:../jest-config@@ -7250,6 +7246,13 @@ packages:tslib: 2.6.0dev: false+ /@swc/[email protected]:+ resolution: {integrity: sha512-5lxnyLEYFskErRPenYItLRSge5DjrJngYKdVjRSrWfza9G6KkgHEXi0vUZiyUeMU5JfXH1YnvXZzSp8ul88o2Q==}+ dependencies:+ legacy-swc-helpers: /@swc/[email protected]+ tslib: 2.6.0+ dev: false+/@swc/[email protected]:resolution: {integrity: sha512-sJ902EfIzn1Fa+qYmjdQqh8tPsoxyBz+8yBKC2HKUxyezKJFwPGOn7pv4WY6QuQW//ySQi5lJjA/ZT9sNWWNTg==}dependencies:@@ -7439,8 +7442,8 @@ packages:/@types/[email protected]:resolution: {integrity: sha512-frsJrz2t/CeGifcu/6uRo4b+SzAwT4NYCVPu1GN8IB9XTzrpPkGuV0tmh9mN+/L0PklAlsC3u5Fxt0ju00LXIw==}- /@types/[email protected]:- resolution: {integrity: sha512-B5Jk560iAlWJ56yV1yBUH8Ek9LykCzb3N0FwJHtbH/Vmd/E1QN/Isen4SAtBb2UEWpZid4GjLm1Fih1xM0MbXA==}+ /@types/[email protected]:+ resolution: {integrity: sha512-RA41XvRjS5M5h8XQDB0J6GDEijlGzWjPjiOQvlLEB2UJE4VWLMAyMRM8inrELYu9HHoddqm+/2VxG7o7ysHwVw==}dependencies:'@types/node': 18.17.1dev: true@@ -10321,7 +10324,7 @@ packages:resolution: {integrity: sha512-jc4k5Yr8iov8QfS6u8w2CnHWVmbOGtdBtOXMze5Y+QD966Rx6PEVWXSEGwXlsDlKtu1G12cJjcsybnqhSk/+LA==}dependencies:- '@swc/helpers': 0.4.14+ '@swc/helpers': 0.4.36brotli: 1.3.3clone: 2.1.2dfa: 1.2.0