Files
hyperframes/packages/studio/src/hooks/domStyleCommit.fonts.test.ts
T
Miguel Ángel d4756f597c fix(studio): edits on GSAP-animated layers keep their keyframes and file positions (#4869)
* fix(studio): resizing an element GSAP only positions saves its CSS width and height

* fix(studio): a resize never saves GSAP's scale mask as the element's CSS

* fix(studio): keep the resize size writer inside the file and comment budgets

* fix(studio): a GSAP-positioned resize saves its CSS size before the GSAP write renders

* fix(studio): undoing a crop leaves a GSAP-animated layer where its file puts it

* test(studio): an undo on a GSAP-parsed layer in a two-script file reloads the preview

* fix(studio): a move keeps an authored xPercent centring set in the saved file

* fix(studio): a drag on a centred element no longer flashes off-centre on release

* fix(studio): a font pick saves the edit and its @font-face in one write

* fix(studio): a focused combobox, switch or plain-text editor counts as an unsaved edit

* test(scripts): pin that a slash after i-- before a quoted slash is division

* fix(studio): an inspector edit saved while a preview reload loads stays on screen

* fix(studio-server): a font save accepts exactly one @font-face rule and nothing after it

* fix(studio-server): a font name or path with braces in quotes still saves its @font-face

* fix(studio-server): a CR or form feed in a quoted font name cannot end the @font-face rule

* test(studio): bank the 99 edit accuracy cases the GSAP fixes now pass
2026-10-01 17:24:35 -07:00

57 lines
2.2 KiB
TypeScript

// @vitest-environment jsdom
import { expect, it } from "vitest";
import type { DomEditSelection } from "../components/editor/domEditing";
import type { ImportedFontAsset } from "../components/editor/fontAssets";
import { importedFontFaceCssFor } from "../utils/studioFontHelpers";
import { commitDomStyles, type DomStyleCommitContext } from "./domStyleCommit";
const selection = (id: string): DomEditSelection =>
({
id,
selector: `#${id}`,
label: id,
tagName: "p",
sourceFile: "index.html",
compositionPath: "index.html",
textFields: [],
inlineStyles: {},
computedStyles: {},
dataAttributes: {},
capabilities: { canSelect: true, canEditStyles: true },
}) as unknown as DomEditSelection;
const poppins = (file: string, weight: string): ImportedFontAsset => ({
family: "Poppins",
path: `assets/fonts/Poppins/${file}`,
url: `/preview/assets/fonts/Poppins/${file}`,
weight,
style: "normal",
});
it("each font a host hands over is saved as its own face, with the weight and style it draws", async () => {
const faces: string[] = [];
let listed: ImportedFontAsset | null = null;
const context: DomStyleCommitContext = {
activeCompPath: "index.html",
previewIframeRef: { current: null },
showToast: () => undefined,
versions: new Map(),
resolveImportedFontAsset: () => listed,
persistDomEditOperations: (async (
_selection: DomEditSelection,
_operations: unknown,
options?: { importedFont?: ImportedFontAsset },
) => {
if (options?.importedFont)
faces.push(importedFontFaceCssFor(options.importedFont, "index.html"));
}) as unknown as DomStyleCommitContext["persistDomEditOperations"],
};
listed = poppins("Poppins-SemiBold.ttf", "600");
await commitDomStyles(context, selection("title"), { "font-family": "Poppins" });
listed = poppins("Poppins-Regular.ttf", "400");
await commitDomStyles(context, selection("subtitle"), { "font-family": "Poppins" });
expect(faces).toHaveLength(2);
expect(faces[0]).toContain('Poppins-SemiBold.ttf"); font-weight: 600; font-style: normal;');
expect(faces[1]).toContain('Poppins-Regular.ttf"); font-weight: 400; font-style: normal;');
});