Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions docs/snippets/catalog-detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,27 @@ export const CatalogDetail = ({
*/
const urlKey = `vars-${compositionId}`;

// >>> preview values
/** JSON that is also inert inside an inline `<script>` and a single-quoted attribute. */
function scriptJson(value) {
return JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, function (c) {
return "\\u" + ("000" + c.charCodeAt(0).toString(16)).slice(-4);
});
}

/** The entries of a parsed query object that name a declared id and hold a primitive value. */
function declaredValues(parsed, ids) {
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
return Object.fromEntries(
Object.entries(parsed).filter(([id, value]) => {
if (!ids.has(id)) return false;
if (typeof value === "number") return Number.isFinite(value);
return typeof value === "string" || typeof value === "boolean";
}),
);
}
// <<< preview values

const readFromUrl = () => {
if (typeof window === "undefined") return {};
try {
Expand All @@ -1718,11 +1739,8 @@ export const CatalogDetail = ({
// `URLSearchParams` has already decoded this once. Decoding again turned
// a path full of percent-escapes into something that no longer parsed,
// and doubled the length of every link.
const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
// Only ids this item declares; a stale link must not inject stray keys.
const declared = new Set(variables.map((v) => v.id));
return Object.fromEntries(Object.entries(parsed).filter(([id]) => declared.has(id)));
return declaredValues(JSON.parse(raw), new Set(variables.map((v) => v.id)));
} catch {
return {};
}
Expand Down Expand Up @@ -1815,26 +1833,27 @@ export const CatalogDetail = ({
"script>",
"</head><body><script>",
"(function(){",
` var PAYLOAD = ${JSON.stringify(previewSrc)};`,
` var PAYLOAD = ${scriptJson(previewSrc)};`,
// The frame mounts with whatever a shared link asked for, not the bare
// defaults. Posting the values afterwards is too late for anything the
// composition reads once at init — a path arrives, the mark is already
// drawn from the default one, and only a later edit corrects it.
` var INITIAL = ${JSON.stringify({ ...defaults, ...readFromUrl() })};`,
` var INITIAL = ${scriptJson({ ...defaults, ...readFromUrl() })};`,
` var scriptJson = ${scriptJson.toString()};`,
" var html = null, player = null, poll = null;",
// Two ways in, because a composition can be either shape. A top-level one
// reads overrides off `window.__hfVariables`; one mounted through
// `data-composition-src` is fed from its host's `data-variable-values`,
// which the loader reads before the sub-composition runs — so that has to
// be in the markup, not assigned afterwards.
" function withValues(source, values) {",
" var json = JSON.stringify(values);",
" var json = scriptJson(values);",
" var attr = json.replace(/'/g, '&#39;');",
" var out = source.replace(/\\sdata-variable-values=(?:\"[^\"]*\"|'[^']*')/gi, '');",
" out = out.replace(/(data-composition-src=)/gi, \"data-variable-values='\" + attr + \"' $1\");",
" out = out.replace(/data-composition-src=/gi, function (m) { return \"data-variable-values='\" + attr + \"' \" + m; });",
" var tag = '<' + 'script>window.__hfVariables=' + json + ';<' + '/script>';",
" return /<head[^>]*>/i.test(out)",
" ? out.replace(/<head([^>]*)>/i, '<head$1>' + tag)",
" ? out.replace(/<head[^>]*>/i, function (m) { return m + tag; })",
" : tag + out;",
" }",
// The composition reads its variables once, at init, so a new value can
Expand Down Expand Up @@ -1870,6 +1889,7 @@ export const CatalogDetail = ({
" document.body.innerHTML = '<pre style=\"color:#f66;font:12px monospace;padding:12px\">preview unavailable: ' + e + '</pre>';",
" });",
" addEventListener('message', function (event) {",
" if (event.source !== parent || event.origin !== self.origin) return;",
" var values = event.data && event.data.hfVariables;",
" if (!values) return;",
" mount(values, player.currentTime || 0);",
Expand Down
28 changes: 22 additions & 6 deletions docs/snippets/install-command.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,30 @@ export const InstallCommand = ({ command, item }) => {
React.useEffect(() => {
if (!item) return;

// >>> vars argument
/**
* The ` --vars '<json>'` suffix for a query value, or "" when nothing usable is in it.
*
* Keeps variable-id keys with string, finite number or boolean values, and
* escapes `'` so the JSON stays one shell argument.
*/
function varsArgument(raw) {
if (!raw) return "";
const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return "";
const kept = Object.entries(parsed).filter(([id, value]) => {
if (!/^[A-Za-z_][\w-]*$/.test(id)) return false;
if (typeof value === "number") return Number.isFinite(value);
return typeof value === "string" || typeof value === "boolean";
});
if (kept.length === 0) return "";
return ` --vars '${JSON.stringify(Object.fromEntries(kept)).replace(/'/g, "'\\''")}'`;
}
// <<< vars argument

const read = () => {
try {
const raw = new URLSearchParams(window.location.search).get(`vars-${item}`);
if (!raw) return setTuned("");
const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return setTuned("");
if (Object.keys(parsed).length === 0) return setTuned("");
setTuned(` --vars '${JSON.stringify(parsed)}'`);
setTuned(varsArgument(new URLSearchParams(window.location.search).get(`vars-${item}`)));
} catch {
// A hand-edited link should leave the plain command, not break it.
setTuned("");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"player:perf": "bun run --filter @hyperframes/player perf",
"format:check": "oxfmt --check .",
"knip": "knip",
"test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-comment-citations.test.mjs scripts/comments-workflow.test.mjs scripts/comment-ratchet.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-svg-sanitize-parity.test.mjs scripts/check-media-use-svg-sanitize-generated.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-cli-lazy-deps.test.mjs scripts/file-url-paths.test.mjs scripts/check-studio-copy-dashes.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/clawhub-sync.test.mjs scripts/clawhub-unlist-retired.test.mjs scripts/publish-workflow.test.mjs scripts/pr-edit-concurrency.test.mjs scripts/merge-queue-workflows.test.mjs scripts/ci-cache-workflows.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/check-edit-accuracy-filter.test.mjs scripts/edit-accuracy-retry.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/backfill-block-previews.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/rewrite-relative-import-extensions.test.mjs scripts/lint-skills.test.mjs scripts/check-core-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-publication.test.mjs scripts/ci/resolve-workflow-pr.test.mjs scripts/lefthook-order.test.mjs scripts/inline-gsap.test.mjs scripts/ci/flake-gate.test.mjs scripts/ci/motion-blur-nightly-report.test.mjs scripts/ci/base-file.test.mjs scripts/ci/release-only-diff.test.mjs scripts/check-catalog-source-pr.test.mjs scripts/generate-registry-items.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-theme-fallbacks.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs registry/components/filmed-screen/filmed-screen.test.mjs registry/components/echo-smear/echo-smear.test.mjs registry/examples/path-traced-3d/source/path-traced-3d.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts",
"test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-comment-citations.test.mjs scripts/comments-workflow.test.mjs scripts/comment-ratchet.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-svg-sanitize-parity.test.mjs scripts/check-media-use-svg-sanitize-generated.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-cli-lazy-deps.test.mjs scripts/file-url-paths.test.mjs scripts/check-studio-copy-dashes.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/clawhub-sync.test.mjs scripts/clawhub-unlist-retired.test.mjs scripts/publish-workflow.test.mjs scripts/pr-edit-concurrency.test.mjs scripts/merge-queue-workflows.test.mjs scripts/ci-cache-workflows.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/check-edit-accuracy-filter.test.mjs scripts/edit-accuracy-retry.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/backfill-block-previews.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/registry-cdn-pins.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/rewrite-relative-import-extensions.test.mjs scripts/lint-skills.test.mjs scripts/check-core-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-publication.test.mjs scripts/ci/resolve-workflow-pr.test.mjs scripts/lefthook-order.test.mjs scripts/inline-gsap.test.mjs scripts/ci/flake-gate.test.mjs scripts/ci/motion-blur-nightly-report.test.mjs scripts/ci/base-file.test.mjs scripts/ci/release-only-diff.test.mjs scripts/check-catalog-source-pr.test.mjs scripts/generate-registry-items.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-theme-fallbacks.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs registry/components/filmed-screen/filmed-screen.test.mjs registry/components/echo-smear/echo-smear.test.mjs registry/examples/path-traced-3d/source/path-traced-3d.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts",
"typecheck:scripts": "tsc --noEmit -p scripts/tsconfig.json",
"test:skills": "HYPERFRAMES_MEDIA_HOME_REQUIRED=1 node --import ./packages/cli/scripts/test-home.mjs --test 'skills/**/*.test.mjs' 'packages/cli/src/media-use/**/*.test.mjs'",
"generate:previews": "tsx scripts/generate-template-previews.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/media-use/lib/svg-sanitize.mjs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions packages/core/src/figma/sanitizeSvg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const HOSTILE_CASES: Array<[label: string, input: string, mustNotContain: string
`<svg><style>svg{background-image:image-set("https://evil.example/b" 1x)}</style></svg>`,
["evil.example"],
],
[
"CSS-escaped image-set() followed by CR LF in a style element",
`<svg><style>.a{background:image-se\\74\r\n('https://evil.example/b' 1x)}</style></svg>`,
["evil.example"],
],
[
"CSS-escaped image-set() followed by CR LF in style=",
`<svg><rect style="background:image-se\\74\r\n('https://evil.example/b' 1x)"/></svg>`,
["evil.example"],
],
[
"CSS-escaped url() followed by a form feed in a presentation attribute (guards the line-ending fold, not a base bypass)",
`<svg><rect fill="\\75\frl(https://evil.example/b)"/></svg>`,
["evil.example"],
],
[
"CSS-escaped image-set() in style=",
String.raw`<svg><rect style="background:\69mage-set('https://evil.example/b' 1x)"/></svg>`,
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/figma/sanitizeSvg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,12 @@ function decodeCssEscape(hex: string | undefined, char: string | undefined): str
return invalid ? "�" : String.fromCodePoint(cp);
}

// A browser reads `\75 rl(` as `url(`, so every check runs on escape-decoded, lowercased text.
// Comments stay in: CSS never lets one join a function name or `@import`, only split tokens.
// A browser folds CR LF, CR and FF to one newline, then reads `\75 rl(` as `url(`, so every check
// runs on that decoded, lowercased text. Comments stay in: CSS never lets one join a function name.
function canonicalCss(text: string): string {
return text
.replace(/\\([0-9a-f]{1,6})[ \t\n\r\f]?|\\([\s\S])/gi, (_, hex, char) =>
decodeCssEscape(hex, char),
)
.replace(/\r\n?|\f/g, "\n")
.replace(/\\([0-9a-f]{1,6})[ \t\n]?|\\([\s\S])/gi, (_, hex, char) => decodeCssEscape(hex, char))
.toLowerCase();
}

Expand Down
8 changes: 4 additions & 4 deletions packages/lint/src/rules/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function climbsAboveRoot(fileDepth: number, path: string): boolean {
function extractCssSelectors(css: string): string[] {
const out: string[] = [];
const noComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
const ruleHeader = /([^{}]+)\{/g;
const ruleHeader = /(?<![^{}])([^{}]+)\{/g;
let m: RegExpExecArray | null;
while ((m = ruleHeader.exec(noComments)) !== null) {
const header = (m[1] ?? "").trim();
Expand Down Expand Up @@ -209,7 +209,7 @@ function collectHeavyOverlayHooks(styles: ExtractedBlock[]): {
const ids = new Set<string>();
for (const style of styles) {
const noComments = style.content.replace(/\/\*[\s\S]*?\*\//g, "");
const ruleWithBody = /([^{}]+)\{([^{}]*)\}/g;
const ruleWithBody = /(?<![^{}])([^{}]+)\{([^{}]*)\}/g;
let m: RegExpExecArray | null;
while ((m = ruleWithBody.exec(noComments)) !== null) {
const header = (m[1] ?? "").trim();
Expand Down Expand Up @@ -556,7 +556,7 @@ function stylesheetCanvasZoomHits(
): CanvasZoomHit[] {
const hits: CanvasZoomHit[] = [];
for (const style of styles) {
const ruleWithBody = /([^{}]+)\{([^{}]*)\}/g;
const ruleWithBody = /(?<![^{}])([^{}]+)\{([^{}]*)\}/g;
const content = stripCssComments(style.content);
// At-rules and style attributes can restrict selector applicability.
const allowNewHits = style.attrs.trim() === "" && !content.includes("@");
Expand Down Expand Up @@ -787,7 +787,7 @@ function stackingContextSelectors(styles: readonly ExtractedBlock[]): Set<string
const selectors = new Set<string>();
for (const style of styles) {
const content = stripCssComments(style.content);
const rule = /([^{}]+)\{([^{}]*)\}/g;
const rule = /(?<![^{}])([^{}]+)\{([^{}]*)\}/g;
let match: RegExpExecArray | null;
while ((match = rule.exec(content)) !== null) {
if (!STACKING_CONTEXT_DECLARATION.test(match[2] ?? "")) continue;
Expand Down
61 changes: 61 additions & 0 deletions packages/lint/src/rules/gsap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,67 @@ describe("SVG draw-on rules", () => {
expect(finding).toBeUndefined();
});

it("svg_drawon_css_dasharray_conflict: resolves a template id with a literal segment to the matching element", async () => {
const html = `
<html><body>
<style>.wire-b { stroke-dasharray: 10 10; }</style>
<div data-composition-id="b" data-width="1920" data-height="1080">
<svg><path id="line-b" class="wire-b" d="M 0 0 L 100 100"/></svg>
</div>
<script>
window.__timelines = window.__timelines || {};
const tl = gsap.timeline({ paused: true });
const name = "b";
const target = document.getElementById(\`line-\${name}\`);
tl.set(target, { strokeDasharray: 141.4, strokeDashoffset: 141.4 }, 0);
window.__timelines["b"] = tl;
</script>
</body></html>`;
const result = await lintHyperframeHtml(html);
const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
expect(finding).toBeDefined();
});

it("matches a many-placeholder template id against a long near-miss id in linear time", async () => {
const template = Array.from({ length: 40 }, () => "${x}").join("a") + "b";
const html = `
<html><body>
<div data-composition-id="c1" data-width="1920" data-height="1080">
<svg><path id="${"a".repeat(5000)}c" d="M 0 0 L 1 1"/></svg>
</div>
<script>
window.__timelines = window.__timelines || {};
const el = document.getElementById(\`${template}\`);
const tl = gsap.timeline({ paused: true });
tl.set(el, { strokeDasharray: 1 }, 0);
window.__timelines["c1"] = tl;
</script>
</body></html>`;
const started = performance.now();
await lintHyperframeHtml(html);
expect(performance.now() - started).toBeLessThan(2000);
});

it("scans a long style block with no braces in linear time", async () => {
const html = `<html><body>
<div data-composition-id="c1" data-width="1920" data-height="1080"></div>
<style>${"a ".repeat(40000)}</style>
</body></html>`;
const started = performance.now();
await lintHyperframeHtml(html);
expect(performance.now() - started).toBeLessThan(3000);
});

it("scans a closed style block of many unclosed rules in linear time", async () => {
const html = `<html><body>
<div data-composition-id="c1" data-width="1920" data-height="1080"></div>
<style>${"x{".repeat(40000)}</style>
</body></html>`;
const started = performance.now();
await lintHyperframeHtml(html);
expect(performance.now() - started).toBeLessThan(2000);
});

// ── gsap_timeline_set_initial_hide ─────────────────────────────────────────

it("gsap_timeline_set_initial_hide: warns on tl.set hidden state at position 0", async () => {
Expand Down
Loading
Loading