diff --git a/bun.lock b/bun.lock index 7f5697e0f1..bd1fcd20bc 100644 --- a/bun.lock +++ b/bun.lock @@ -14,7 +14,7 @@ "@types/node": "^25.0.10", "esbuild": "^0.28.2", "fallow": "^3.34.1", - "happy-dom": "^20.9.0", + "happy-dom": "^21.0.4", "knip": "^6.0.3", "lefthook": "^2.1.4", "oxfmt": "^0.41.0", @@ -320,7 +320,7 @@ }, "devDependencies": { "@types/node": "^25.0.10", - "happy-dom": "^20.9.0", + "happy-dom": "^21.0.4", "typescript": "^5.0.0", "vitest": "^4.1.11", }, @@ -1401,6 +1401,8 @@ "buffer-from": ["buffer-from@1.1.2", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="], + "buffer-image-size": ["buffer-image-size@0.6.4", "", { "dependencies": { "@types/node": "*" } }, "sha512-nEh+kZOPY1w+gcCMobZ6ETUp9WfibndnosbpwB1iJk/8Gt5ZF2bhS6+B6bPYz424KtwsR6Rflc3tCz1/ghX2dQ=="], + "bun-types": ["bun-types@1.3.13", "", { "dependencies": { "@types/node": "*" } }, "sha512-QXKeHLlOLqQX9LgYaHJfzdBaV21T63HhFJnvuRCcjZiaUDpbs5ED1MgxbMra71CsryN/1dAoXuJJJwIv/2drVA=="], "bundle-name": ["bundle-name@4.1.0", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q=="], @@ -1683,7 +1685,7 @@ "gtoken": ["gtoken@7.1.0", "", { "dependencies": { "gaxios": "^6.0.0", "jws": "^4.0.0" } }, "sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw=="], - "happy-dom": ["happy-dom@20.9.0", "", { "dependencies": { "@types/node": ">=20.0.0", "@types/whatwg-mimetype": "^3.0.2", "@types/ws": "^8.18.1", "entities": "^7.0.1", "whatwg-mimetype": "^3.0.0", "ws": "^8.18.3" } }, "sha512-GZZ9mKe8r646NUAf/zemnGbjYh4Bt8/MqASJY+pSm5ZDtc3YQox+4gsLI7yi1hba6o+eCsGxpHn5+iEVn31/FQ=="], + "happy-dom": ["happy-dom@21.0.4", "", { "dependencies": { "@types/node": ">=20.0.0", "@types/whatwg-mimetype": "^3.0.2", "@types/ws": "^8.18.1", "buffer-image-size": "^0.6.4", "entities": "^7.0.1", "whatwg-mimetype": "^3.0.0", "ws": "^8.21.0" } }, "sha512-tFm+GaLBgo6o0awHnvHaNoraVo27qJ+2tZEtZ+cIa08hXbeitrxAJajLI05hsUy/2/YTKcUjQYzHe5mCcraLBw=="], "has-flag": ["has-flag@4.0.0", "", {}, "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="], @@ -2199,7 +2201,7 @@ "wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="], - "ws": ["ws@8.20.0", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA=="], + "ws": ["ws@8.21.3", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw=="], "wsl-utils": ["wsl-utils@0.1.0", "", { "dependencies": { "is-wsl": "^3.1.0" } }, "sha512-h3Fbisa2nKGPxCpm89Hk33lBLsnaGBvctQopaBSOW/uIs6FTe1ATyAnKFJrzVs9vpGdsTe73WF3V4lIsk4Gacw=="], @@ -2271,6 +2273,8 @@ "@google-cloud/storage/google-auth-library": ["google-auth-library@9.15.1", "", { "dependencies": { "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", "gaxios": "^6.1.1", "gcp-metadata": "^6.1.0", "gtoken": "^7.0.0", "jws": "^4.0.0" } }, "sha512-Jb6Z0+nvECVz+2lzSMt9u98UsoakXxA2HGHMCxh+so3n90XgYWkq5dur19JAJV7ONiJY22yBTyJB1TSkvPq9Ng=="], + "@google/genai/ws": ["ws@8.20.0", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA=="], + "@img/sharp-wasm32/@emnapi/runtime": ["@emnapi/runtime@1.11.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA=="], "@isaacs/cliui/string-width": ["string-width@5.1.2", "", { "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", "strip-ansi": "^7.0.1" } }, "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA=="], @@ -2357,8 +2361,6 @@ "path-scurry/minipass": ["minipass@7.1.3", "", {}, "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A=="], - "puppeteer-core/ws": ["ws@8.21.3", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw=="], - "recast/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="], "sharp/semver": ["semver@7.8.5", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA=="], diff --git a/package.json b/package.json index 95ecd58e72..82600e9601 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@types/node": "^25.0.10", "esbuild": "^0.28.2", "fallow": "^3.34.1", - "happy-dom": "^20.9.0", + "happy-dom": "^21.0.4", "knip": "^6.0.3", "lefthook": "^2.1.4", "oxfmt": "^0.41.0", diff --git a/packages/cli/src/commands/motion-signature.browser.test.ts b/packages/cli/src/commands/motion-signature.browser.test.ts index b3e905d5e1..913d89bfd8 100644 --- a/packages/cli/src/commands/motion-signature.browser.test.ts +++ b/packages/cli/src/commands/motion-signature.browser.test.ts @@ -771,7 +771,7 @@ describe("motion-signature.browser counter channel", () => { it("ignores a display:none decoy counter owner in a frozen composition", () => { document.body.innerHTML = `
-
+
`; @@ -799,7 +799,7 @@ describe("motion-signature.browser counter channel", () => { it("ignores a decoy counter owner nested inside a display:none subtree", () => { document.body.innerHTML = `
-
+
`; diff --git a/packages/player/vitest.config.ts b/packages/player/vitest.config.ts index 7878a1124c..a7d078f9a2 100644 --- a/packages/player/vitest.config.ts +++ b/packages/player/vitest.config.ts @@ -29,6 +29,7 @@ export default defineConfig({ happyDOM: { settings: { handleDisabledFileLoadingAsSuccess: true, + enableIframePageLoading: true, navigator: { userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 33d74d90ba..e75aa66d65 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -90,7 +90,7 @@ }, "devDependencies": { "@types/node": "^25.0.10", - "happy-dom": "^20.9.0", + "happy-dom": "^21.0.4", "typescript": "^5.0.0", "vitest": "^4.1.11" } diff --git a/packages/sdk/vitest.config.ts b/packages/sdk/vitest.config.ts index ce36a74267..285d4af4cb 100644 --- a/packages/sdk/vitest.config.ts +++ b/packages/sdk/vitest.config.ts @@ -4,5 +4,8 @@ export default defineConfig({ test: { include: ["src/**/*.test.ts"], environment: "node", + environmentOptions: { + happyDOM: { settings: { enableIframePageLoading: true } }, + }, }, }); diff --git a/packages/studio/src/components/editor/inlineTextStyleRange.fill.test.ts b/packages/studio/src/components/editor/inlineTextStyleRange.fill.test.ts new file mode 100644 index 0000000000..e2635168d1 --- /dev/null +++ b/packages/studio/src/components/editor/inlineTextStyleRange.fill.test.ts @@ -0,0 +1,129 @@ +// @vitest-environment jsdom +// happy-dom drops the vendor-prefixed fill property these tests assert on. + +import { afterEach, describe, expect, it, vi } from "vitest"; +import { applyInlineStyle } from "./inlineTextStyleRange"; + +afterEach(() => { + vi.restoreAllMocks(); + document.body.innerHTML = ""; +}); + +function mount(html: string): HTMLElement { + document.body.innerHTML = `

${html}

`; + return document.body.firstElementChild as HTMLElement; +} + +/** Every text node and line break in order, with the offset each one starts at. */ +function charSpans(host: HTMLElement): Array<{ node: Node; from: number; length: number }> { + const spans: Array<{ node: Node; from: number; length: number }> = []; + const walker = document.createTreeWalker(host, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT); + let seen = 0; + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + const isBreak = node.nodeType === 1 && (node as Element).tagName === "BR"; + if (node.nodeType === 1 && !isBreak) continue; + const length = isBreak ? 1 : (node.textContent?.length ?? 0); + spans.push({ node, from: seen, length }); + seen += length; + } + return spans; +} + +/** + * A range over the host's text, by character offsets across the whole element. + * + * A line break counts as one character, the same way the module does, but is + * never landed on: a boundary there belongs to the text beside it, which is + * where a real selection would put it too. + */ +function rangeOver(host: HTMLElement, start: number, end: number): Range { + const range = document.createRange(); + const text = charSpans(host).filter((span) => span.node.nodeType === 3); + const at = (offset: number) => text.find((span) => span.from + span.length >= offset); + const from = at(start); + const to = at(end); + if (from) range.setStart(from.node, start - from.from); + if (from && to) range.setEnd(to.node, end - to.from); + return range; +} + +/** + * A colour that does not paint is the same to the user as one that did not save. + * + * `-webkit-text-fill-color` inherits and paints the glyph fill, so a composition + * that sets it on a text element wins over any `color` the editor puts on a run + * inside it. The run saved correctly and rendered in someone else's colour, + * which reads as the colour picker being broken. + */ +describe("applyInlineStyle when something else is painting the glyphs", () => { + function stubFill(fill: string | null | ((element: HTMLElement) => string | null)) { + const real = window.getComputedStyle.bind(window); + vi.spyOn(window, "getComputedStyle").mockImplementation(((element: Element) => { + const computed = real(element as HTMLElement); + const resolvedFill = typeof fill === "function" ? fill(element as HTMLElement) : fill; + return new Proxy(computed, { + get: (target, key) => { + if (key === "webkitTextFillColor") return resolvedFill ?? undefined; + if (key === "color") return (element as HTMLElement).style.color || "rgb(0, 0, 0)"; + return Reflect.get(target, key); + }, + }); + }) as typeof window.getComputedStyle); + } + + it("mirrors the colour into the fill when an ancestor is overpainting", () => { + const host = mount("Hello world"); + stubFill("rgb(255, 255, 255)"); + applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" }); + + expect(host.innerHTML).toContain("-webkit-text-fill-color: rgb(255, 0, 149)"); + expect(host.innerHTML).toContain("color: rgb(255, 0, 149)"); + }); + + it("leaves the markup alone when nothing is overpainting", () => { + const host = mount("Hello world"); + stubFill("rgb(255, 0, 149)"); + applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" }); + + expect(host.innerHTML).not.toContain("-webkit-text-fill-color"); + expect(host.innerHTML).toContain("color: rgb(255, 0, 149)"); + }); + + it("says nothing about a run that carries no colour", () => { + const host = mount("Hello world"); + stubFill("rgb(255, 255, 255)"); + applyInlineStyle(rangeOver(host, 6, 11), { "font-weight": "700" }); + + expect(host.innerHTML).not.toContain("-webkit-text-fill-color"); + }); + + it("mirrors only the run whose own ancestor path is overpainting", () => { + const host = mount( + 'left' + + 'right', + ); + stubFill((element) => + element.textContent === "left" ? "rgb(255, 255, 255)" : element.style.color, + ); + + applyInlineStyle(rangeOver(host, 4, 9), { color: "red" }); + + const [left, right] = Array.from(host.querySelectorAll("span")); + expect(left?.style.getPropertyValue("-webkit-text-fill-color")).toBe("blue"); + expect(right?.style.getPropertyValue("-webkit-text-fill-color")).toBe(""); + }); + + it("drops a generated mirror when the ancestor stops overpainting", () => { + const host = mount("Hello world"); + let overpainted = true; + stubFill((element) => (overpainted ? "rgb(255, 255, 255)" : element.style.color)); + applyInlineStyle(rangeOver(host, 6, 11), { color: "red" }); + expect(host.innerHTML).toContain("-webkit-text-fill-color"); + + overpainted = false; + const live = document.getSelection()?.getRangeAt(0); + if (live) applyInlineStyle(live, { "font-weight": "700" }); + + expect(host.innerHTML).not.toContain("-webkit-text-fill-color"); + }); +}); diff --git a/packages/studio/src/components/editor/inlineTextStyleRange.test.ts b/packages/studio/src/components/editor/inlineTextStyleRange.test.ts index aaf24f78e4..6098242ce9 100644 --- a/packages/studio/src/components/editor/inlineTextStyleRange.test.ts +++ b/packages/studio/src/components/editor/inlineTextStyleRange.test.ts @@ -621,88 +621,6 @@ describe("applyInlineStyle survives a control that fires repeatedly", () => { expect(document.getSelection()?.toString()).toBe("cde"); }); }); - -/** - * A colour that does not paint is the same to the user as one that did not save. - * - * `-webkit-text-fill-color` inherits and paints the glyph fill, so a composition - * that sets it on a text element wins over any `color` the editor puts on a run - * inside it. The run saved correctly and rendered in someone else's colour, - * which reads as the colour picker being broken. - */ -describe("applyInlineStyle when something else is painting the glyphs", () => { - function stubFill(fill: string | null | ((element: HTMLElement) => string | null)) { - const real = window.getComputedStyle.bind(window); - vi.spyOn(window, "getComputedStyle").mockImplementation(((element: Element) => { - const computed = real(element as HTMLElement); - const resolvedFill = typeof fill === "function" ? fill(element as HTMLElement) : fill; - return new Proxy(computed, { - get: (target, key) => { - if (key === "webkitTextFillColor") return resolvedFill ?? undefined; - if (key === "color") return (element as HTMLElement).style.color || "rgb(0, 0, 0)"; - return Reflect.get(target, key); - }, - }); - }) as typeof window.getComputedStyle); - } - - it("mirrors the colour into the fill when an ancestor is overpainting", () => { - const host = mount("Hello world"); - stubFill("rgb(255, 255, 255)"); - applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" }); - - expect(host.innerHTML).toContain("-webkit-text-fill-color: rgb(255, 0, 149)"); - expect(host.innerHTML).toContain("color: rgb(255, 0, 149)"); - }); - - it("leaves the markup alone when nothing is overpainting", () => { - const host = mount("Hello world"); - stubFill("rgb(255, 0, 149)"); - applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" }); - - expect(host.innerHTML).not.toContain("-webkit-text-fill-color"); - expect(host.innerHTML).toContain("color: rgb(255, 0, 149)"); - }); - - it("says nothing about a run that carries no colour", () => { - const host = mount("Hello world"); - stubFill("rgb(255, 255, 255)"); - applyInlineStyle(rangeOver(host, 6, 11), { "font-weight": "700" }); - - expect(host.innerHTML).not.toContain("-webkit-text-fill-color"); - }); - - it("mirrors only the run whose own ancestor path is overpainting", () => { - const host = mount( - 'left' + - 'right', - ); - stubFill((element) => - element.textContent === "left" ? "rgb(255, 255, 255)" : element.style.color, - ); - - applyInlineStyle(rangeOver(host, 4, 9), { color: "red" }); - - const [left, right] = Array.from(host.querySelectorAll("span")); - expect(left?.style.getPropertyValue("-webkit-text-fill-color")).toBe("blue"); - expect(right?.style.getPropertyValue("-webkit-text-fill-color")).toBe(""); - }); - - it("drops a generated mirror when the ancestor stops overpainting", () => { - const host = mount("Hello world"); - let overpainted = true; - stubFill((element) => (overpainted ? "rgb(255, 255, 255)" : element.style.color)); - applyInlineStyle(rangeOver(host, 6, 11), { color: "red" }); - expect(host.innerHTML).toContain("-webkit-text-fill-color"); - - overpainted = false; - const live = document.getSelection()?.getRangeAt(0); - if (live) applyInlineStyle(live, { "font-weight": "700" }); - - expect(host.innerHTML).not.toContain("-webkit-text-fill-color"); - }); -}); - describe("readInlineStyleSpread", () => { it("reports every distinct colour in the selection, in order", () => { const host = mount( diff --git a/packages/studio/src/components/editor/manualOffsetDrag.test.ts b/packages/studio/src/components/editor/manualOffsetDrag.test.ts index 0ea1b5882f..83620c2964 100644 --- a/packages/studio/src/components/editor/manualOffsetDrag.test.ts +++ b/packages/studio/src/components/editor/manualOffsetDrag.test.ts @@ -128,7 +128,7 @@ describe("measureManualOffsetDragScreenToOffsetMatrix", () => { }); it("measures movement in parent viewport pixels when the element is inside a scaled iframe", () => { - const window = new Window(); + const window = new Window({ settings: { enableIframePageLoading: true } }); const iframe = window.document.createElement("iframe"); window.document.body.append(iframe); const iframeWindow = iframe.contentWindow; diff --git a/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts b/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts index f5d3e5524e..dd2fe32262 100644 --- a/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts +++ b/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts @@ -1,5 +1,4 @@ // @vitest-environment happy-dom -// @vitest-environment-options {"happyDOM":{"settings":{"disableIframePageLoading":true}}} import React, { act, createRef } from "react"; import { createRoot } from "react-dom/client"; diff --git a/packages/studio/src/test-setup.ts b/packages/studio/src/test-setup.ts index 101ae40f1c..8a53cb7394 100644 --- a/packages/studio/src/test-setup.ts +++ b/packages/studio/src/test-setup.ts @@ -12,3 +12,5 @@ if (typeof CSS.escape !== "function") { if (typeof globalThis.confirm !== "function") { (globalThis as Record).confirm = () => false; } + +(globalThis as Record).BASE_UI_ANIMATIONS_DISABLED = true; diff --git a/packages/studio/vite.config.ts b/packages/studio/vite.config.ts index 9367d0f172..0bb33f9f92 100644 --- a/packages/studio/vite.config.ts +++ b/packages/studio/vite.config.ts @@ -411,5 +411,8 @@ export default defineConfig({ test: { exclude: ["data/**", "node_modules/**"], setupFiles: ["src/test-setup.ts"], + environmentOptions: { + happyDOM: { settings: { enableIframePageLoading: true } }, + }, }, });