mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: introduce font picker (#8012)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
parent
4c5408263c
commit
62228e0bbb
120 changed files with 3390 additions and 1106 deletions
|
@ -1,6 +1,7 @@
|
|||
// vitest.setup.ts
|
||||
import "vitest-canvas-mock";
|
||||
import "@testing-library/jest-dom";
|
||||
import fs from "fs";
|
||||
import { vi } from "vitest";
|
||||
import polyfill from "./packages/excalidraw/polyfill";
|
||||
import { testPolyfills } from "./packages/excalidraw/tests/helpers/polyfills";
|
||||
|
@ -25,6 +26,65 @@ Object.defineProperty(window, "matchMedia", {
|
|||
})),
|
||||
});
|
||||
|
||||
Object.defineProperty(window, "FontFace", {
|
||||
enumerable: true,
|
||||
value: class {
|
||||
private family: string;
|
||||
private source: string;
|
||||
private descriptors: any;
|
||||
private status: string;
|
||||
|
||||
constructor(family, source, descriptors) {
|
||||
this.family = family;
|
||||
this.source = source;
|
||||
this.descriptors = descriptors;
|
||||
this.status = "unloaded";
|
||||
}
|
||||
|
||||
load() {
|
||||
this.status = "loaded";
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(document, "fonts", {
|
||||
value: {
|
||||
load: vi.fn().mockResolvedValue([]),
|
||||
check: vi.fn().mockResolvedValue(true),
|
||||
has: vi.fn().mockResolvedValue(true),
|
||||
add: vi.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(window, "EXCALIDRAW_ASSET_PATH", {
|
||||
value: `file://${__dirname}/`,
|
||||
});
|
||||
|
||||
vi.mock(
|
||||
"./packages/excalidraw/fonts/ExcalidrawFont",
|
||||
async (importOriginal) => {
|
||||
const mod = await importOriginal<
|
||||
typeof import("./packages/excalidraw/fonts/ExcalidrawFont")
|
||||
>();
|
||||
const ExcalidrawFontImpl = mod.ExcalidrawFont;
|
||||
|
||||
return {
|
||||
...mod,
|
||||
ExcalidrawFont: class extends ExcalidrawFontImpl {
|
||||
public async getContent(): Promise<string> {
|
||||
if (this.url.protocol !== "file:") {
|
||||
return super.getContent();
|
||||
}
|
||||
|
||||
// read local assets directly, without running a server
|
||||
const content = await fs.promises.readFile(this.url);
|
||||
return `data:font/woff2;base64,${content.toString("base64")}`;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
vi.mock("nanoid", () => {
|
||||
return {
|
||||
nanoid: vi.fn(() => "test-id"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue