Files
hyperframes/packages/studio/src/noWindowBoundDomChecks.test.ts
T
Miguel Ángel b45818f69d fix(studio): the motion path draws on every load, not only when the layer's node is the frame's own (#4957)
* fix(studio): the motion path draws on every load, not only when the layer's node is the frame's own

useMotionPathData found the selected layer with `instanceof` against the preview
frame's HTMLElement. In the Studio preview the body's nodes often carry the editor
window's prototypes (see core's runtime/domRealm.ts), so the check failed, the path
never got its anchor and drew nothing. Core's realm-free isHtmlElement owns that
question; both motion-path call sites now use it.

* fix(studio): every preview node check asks what a node is, not which window built it

Studio checked preview nodes against their document window's own constructors in
seek reapply, studio motion, timeline z-order commits, the manual offset drag and
the z-order menu. On loads where body nodes carry the editor window's prototypes
those checks fail silently, as the motion path did. They now use core's realm-free
predicates, and a source test fails on a new window-bound check.

* fix(studio): the webmcp preview helper asks what a node is, and both realm tests stub the frame

* fix(studio): the last preview node checks ask what a node is, and the guard sees any constructor read

The selector walk read ancestor ids only from editor-realm nodes and the audio group
observer never saw a group the preview added. Both use core's predicates now. The guard
flags any DOM interface read off an object, the spellings it missed included, and the
window gates the old constructor needed are gone.

* test(studio): cover the main seek filter across windows and split member reads

* fix(studio): a press on the motion path's line inside the selected layer moves the layer

* fix(studio): a press inside the selected layer moves it, and path nodes sit where the layer is

* refactor(studio): one helper places a path point, for keyframes and the start

* fix(studio): a handle over a path node takes its press; nodes sit right on centred layers

* fix(studio): reading a layer's path anchor leaves its CSS translate alone

* chore(studio): keep the motion path home file under the comment share

* fix(studio): a new motion path ends where you click on a CSS-centred layer

* fix(studio): a path made on a transform-centred layer ends where you click

* style(studio): keep a motion path test comment within 120 columns
2026-10-04 22:08:29 +00:00

32 lines
1.4 KiB
TypeScript

import { readdirSync, readFileSync } from "node:fs";
import { dirname, join, relative } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
const SRC = dirname(fileURLToPath(import.meta.url));
const DOM_CTOR = String.raw`(?:HTML\w*Element|SVG\w*Element|Element|Node|Text|ShadowRoot|DocumentFragment)\b`;
// A DOM constructor read off any object, a window most of all, asks which window built a node.
const WINDOW_BOUND = [
new RegExp(String.raw`[\w$)\]!?]\??\.\s*${DOM_CTOR}`),
new RegExp(String.raw`^\s*\??\.\s*${DOM_CTOR}`),
new RegExp(String.raw`\[\s*["'](?:HTML|SVG)\w*Element["']`),
];
function sources(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true, recursive: true })
.filter((e) => e.isFile() && /\.tsx?$/.test(e.name) && !/\.test(-helpers)?\.tsx?$/.test(e.name))
.map((e) => join(e.parentPath, e.name));
}
it("no studio source checks a DOM node against a window's own constructor", () => {
const hits = sources(SRC).flatMap((file) =>
readFileSync(file, "utf8")
.split("\n")
.map((line, i) => ({ line, at: `${relative(SRC, file)}:${i + 1}` }))
.filter(({ line }) => !/^\s*(\/\/|\*|\/\*)/.test(line))
.filter(({ line }) => WINDOW_BOUND.some((re) => re.test(line)))
.map(({ at, line }) => `${at} ${line.trim()}`),
);
expect(hits, "use @hyperframes/core/runtime/dom-realm instead").toEqual([]);
});