From 230d0edc44f60ba2a00953e02c24591f491affc9 Mon Sep 17 00:00:00 2001 From: Marcel Mraz Date: Tue, 30 Jul 2024 10:34:40 +0200 Subject: [PATCH] feat: multiple fonts fallbacks (#8286) --- excalidraw-app/index.html | 58 ++---- .../components/FontPicker/FontPickerList.tsx | 10 +- packages/excalidraw/fonts/ExcalidrawFont.ts | 167 +++++++++++++----- packages/excalidraw/fonts/assets/fonts.css | 3 +- packages/excalidraw/fonts/index.ts | 23 ++- packages/excalidraw/fonts/metadata.ts | 3 + packages/excalidraw/global.d.ts | 2 +- packages/excalidraw/scene/export.ts | 34 ++-- scripts/woff2/woff2-vite-plugins.js | 86 +++++++++ setupTests.ts | 6 +- vercel.json | 28 ++- 11 files changed, 293 insertions(+), 127 deletions(-) diff --git a/excalidraw-app/index.html b/excalidraw-app/index.html index a2919e512..3a5c01e10 100644 --- a/excalidraw-app/index.html +++ b/excalidraw-app/index.html @@ -95,6 +95,11 @@ color: #fff; } + + + + + <% if (typeof PROD != 'undefined' && PROD == true) { %> + + + + <% } else { %> - <% } %> - - - - - - - - - - - - - <% if (typeof PROD != 'undefined' && PROD == true) { %> - - - - <% } else { %> <% } %> - + + + + + + + + <% if (typeof VITE_APP_DEV_DISABLE_LIVE_RELOAD != 'undefined' && VITE_APP_DEV_DISABLE_LIVE_RELOAD == true) { %> + + + + + + `, + ); + } }, }; }; diff --git a/setupTests.ts b/setupTests.ts index 0b331db08..3884fbd47 100644 --- a/setupTests.ts +++ b/setupTests.ts @@ -72,12 +72,14 @@ vi.mock( ...mod, ExcalidrawFont: class extends ExcalidrawFontImpl { public async getContent(): Promise { - if (this.url.protocol !== "file:") { + const url = this.urls[0]; + + if (url.protocol !== "file:") { return super.getContent(); } // read local assets directly, without running a server - const content = await fs.promises.readFile(this.url); + const content = await fs.promises.readFile(url); return `data:font/woff2;base64,${content.toString("base64")}`; } }, diff --git a/vercel.json b/vercel.json index dc077e41b..6949dfcef 100644 --- a/vercel.json +++ b/vercel.json @@ -6,7 +6,7 @@ "headers": [ { "key": "Access-Control-Allow-Origin", - "value": "*" + "value": "https://excalidraw.com" }, { "key": "X-Content-Type-Options", @@ -21,6 +21,32 @@ "value": "origin" } ] + }, + { + "source": "/:file*.woff2", + "headers": [ + { + "key": "Cache-Control", + "value": "public, max-age=31536000" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "https://excalidraw.com" + } + ] + }, + { + "source": "/(Virgil|Cascadia|Assistant-Regular).woff2", + "headers": [ + { + "key": "Cache-Control", + "value": "public, max-age=31536000" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*" + } + ] } ], "redirects": [