mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(lint): every selector in a comma list counts as hidden by authored CSS (#7252)
* fix(lint): every selector in a comma list counts as hidden by authored CSS * fix(lint): keep gsap.ts's comment share where it was * fix(lint): the transform conflict check reads every selector of a comma list too
This commit is contained in:
@@ -671,6 +671,27 @@ describe("GSAP rules", () => {
|
||||
expect(finding?.fixHint).toMatch(/xPercent/);
|
||||
});
|
||||
|
||||
it("warns for every selector of a comma list with a CSS scale transform, not only the last", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
<div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
|
||||
<div id="hero"></div><div id="badge"></div>
|
||||
</div>
|
||||
<style>
|
||||
#hero, #badge { transform: scale(0.8); }
|
||||
</style>
|
||||
<script>
|
||||
window.__timelines = window.__timelines || {};
|
||||
const tl = gsap.timeline({ paused: true });
|
||||
tl.to("#hero", { scale: 1, duration: 0.5 }, 1.0);
|
||||
window.__timelines["c1"] = tl;
|
||||
</script>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html);
|
||||
const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
|
||||
expect(finding?.selector).toBe("#hero");
|
||||
});
|
||||
|
||||
it("warns when tl.to animates scale on an element with CSS scale transform", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
@@ -3174,6 +3195,26 @@ describe("SVG draw-on rules", () => {
|
||||
expect(finding).toBeUndefined();
|
||||
});
|
||||
|
||||
it("gsap_timeline_set_initial_hide: counts every selector of a comma list as hidden by authored CSS", async () => {
|
||||
const html = `
|
||||
<html><head><style>#stroke-a, #stroke-b { opacity: 0; }</style></head><body>
|
||||
<div data-composition-id="c1" data-width="1920" data-height="1080">
|
||||
<svg width="400" height="200"><path id="stroke-a" d="M0 0 L100 100" /><path id="stroke-b" d="M0 100 L100 0" /></svg>
|
||||
</div>
|
||||
<script>
|
||||
window.__timelines = window.__timelines || {};
|
||||
const tl = gsap.timeline({ paused: true });
|
||||
tl.set("#stroke-a", { opacity: 0 }, 0);
|
||||
tl.set("#stroke-b", { opacity: 0 }, 0);
|
||||
tl.to(["#stroke-a", "#stroke-b"], { opacity: 1, duration: 1 }, 0.5);
|
||||
window.__timelines["c1"] = tl;
|
||||
</script>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html);
|
||||
const findings = result.findings.filter((f) => f.code === "gsap_timeline_set_initial_hide");
|
||||
expect(findings).toEqual([]);
|
||||
});
|
||||
|
||||
it("gsap_timeline_set_initial_hide: does NOT warn when the target is already hidden by authored CSS", async () => {
|
||||
// Defensive re-assertion: frame 0 is hidden by CSS anyway.
|
||||
const html = `
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import postcss from "postcss";
|
||||
import { gsapCallOffset, containingCallOffset } from "../scriptPositions";
|
||||
interface LintParsedGsap {
|
||||
animations: Array<{
|
||||
@@ -1017,6 +1018,27 @@ function indexInsideNonIifeRange(
|
||||
// opacity to EXACTLY zero. The declaration regex is boundary-anchored so
|
||||
// `opacity: 0.98` never matches; it ends at `;` or end of input, which also
|
||||
// catches a final declaration without a trailing semicolon.
|
||||
function cssRuleSubjects(
|
||||
styles: LintContext["styles"],
|
||||
): Array<{ declarations: string[]; subjects: string[] }> {
|
||||
const rules: Array<{ declarations: string[]; subjects: string[] }> = [];
|
||||
for (const style of styles) {
|
||||
let root: postcss.Root;
|
||||
try {
|
||||
root = postcss.parse(style.content);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
root.walkRules((rule) => {
|
||||
const subjects = rule.selectors.flatMap(
|
||||
(selector) => /[#.][a-zA-Z0-9_-]+$/.exec(selector.trim())?.[0] ?? [],
|
||||
);
|
||||
if (subjects.length) rules.push({ declarations: rule.nodes.map(String), subjects });
|
||||
});
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
function collectCssOpacityZeroSelectors(
|
||||
styles: LintContext["styles"],
|
||||
tags: OpenTag[],
|
||||
@@ -1024,14 +1046,9 @@ function collectCssOpacityZeroSelectors(
|
||||
const selectors = new Set<string>();
|
||||
const opacityExactlyZero = /opacity\s*:\s*0(?:\.0+)?\s*(?:;|$)/;
|
||||
|
||||
for (const style of styles) {
|
||||
for (const [, selector, body] of style.content.matchAll(
|
||||
/([#.][a-zA-Z0-9_-]+)\s*\{([^}]+)\}/g,
|
||||
)) {
|
||||
if (body && opacityExactlyZero.test(body)) {
|
||||
selectors.add((selector ?? "").trim());
|
||||
}
|
||||
}
|
||||
for (const { declarations, subjects } of cssRuleSubjects(styles)) {
|
||||
if (!declarations.some((declaration) => opacityExactlyZero.test(declaration))) continue;
|
||||
for (const subject of subjects) selectors.add(subject);
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
@@ -1320,17 +1337,13 @@ export const gsapRules: LintRule<LintContext>[] = [
|
||||
const cssScaleSelectors = new Map<string, string>();
|
||||
|
||||
// Check <style> blocks for transform rules
|
||||
for (const style of styles) {
|
||||
for (const [, selector, body] of style.content.matchAll(
|
||||
/([#.][a-zA-Z0-9_-]+)\s*\{([^}]+)\}/g,
|
||||
)) {
|
||||
const tMatch = body?.match(/transform\s*:\s*([^;]+)/);
|
||||
if (!tMatch || !tMatch[1]) continue;
|
||||
const transformVal = tMatch[1].trim();
|
||||
if (/translate/i.test(transformVal))
|
||||
cssTranslateSelectors.set((selector ?? "").trim(), transformVal);
|
||||
if (/scale/i.test(transformVal))
|
||||
cssScaleSelectors.set((selector ?? "").trim(), transformVal);
|
||||
for (const { declarations, subjects } of cssRuleSubjects(styles)) {
|
||||
const tMatch = declarations.join(";").match(/transform\s*:\s*([^;]+)/);
|
||||
if (!tMatch || !tMatch[1]) continue;
|
||||
const transformVal = tMatch[1].trim();
|
||||
for (const subject of subjects) {
|
||||
if (/translate/i.test(transformVal)) cssTranslateSelectors.set(subject, transformVal);
|
||||
if (/scale/i.test(transformVal)) cssScaleSelectors.set(subject, transformVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user