Files
hyperframes/packages/studio/src/utils/authoredOpacity.ts
Miguel Angel Simon Sierra 5d1cafff82 fix(studio): address review findings on graded-element editing
Review follow-ups (both reviewers, all findings):

- resize captures scope to the resize group: convert-to-keyframes
  resolvedFromValues and the whole-offset backfill pass the group filter,
  so an opacity-touching intro tween can't ride into a converted scale
  tween (the rotation fix's contract, now uniform across intercepts)
- commitStaticSet resolves every group's target set BEFORE committing and
  coalesces groups landing on the same legacy mixed set into one commit —
  the second commit can no longer chase a stale group-derived id
- installAuthoredOpacityCapture also stamps an element the moment it GAINS
  data-color-grading at runtime (attributeFilter), not just at insertion
- both writer twins now share the same emitted-set dedupe shape
- applySoftReload's positional tail becomes a SoftReloadOptions object
- readAllAnimatedProperties builds the group-filtered key set immutably
  instead of deleting from the set mid-iteration
- applyAuthoredInlineOpacity documents the priority-lossy round-trip
- the marquee hit-test reads activeCompositionPathRef like its neighbors

New tests: resize intercept (scale route + group filter + non-uniform
longhands), after-write-HTML / stamp / empty-stamp opacity restore, the
no-op-commit-with-missed-instant-patch soft-reload contract, and the
runtime-gained-grading stamp.
2026-07-11 15:18:49 -04:00

36 lines
1.6 KiB
TypeScript

/**
* Authored-opacity contract, studio side. The runtime stamps every graded
* element's authored inline opacity at document parse time (see
* installAuthoredOpacityCapture in @hyperframes/core); studio code that makes
* GSAP re-initialize tweens (soft reload, in-place patches) restores it so
* re-captures never bake a runtime transient in as a tween bound.
*/
import { COLOR_GRADING_AUTHORED_OPACITY_ATTR } from "@hyperframes/core/color-grading";
interface AttributeReader {
getAttribute(name: string): string | null;
}
/**
* The stamped authored inline opacity. Three-state:
* "0.98" — the authored value; "" — captured, authored none;
* null — never captured (unknown).
* Duck-typed so iframe-realm elements (no shared HTMLElement) work.
*/
export function readStampedAuthoredOpacity(element: AttributeReader): string | null {
return element.getAttribute(COLOR_GRADING_AUTHORED_OPACITY_ATTR);
}
/**
* Write an authored inline opacity back: "" removes the property, a value sets
* it. Priority-lossy by design: the capture reads `style.opacity` (value only)
* and the write sets no priority, so an authored `opacity: X !important`
* round-trips as `opacity: X`. The only `!important` opacity in the pipeline
* is the color-grading runtime hide — a transient this contract exists to
* discard — and authored compositions don't `!important` their opacity.
*/
export function applyAuthoredInlineOpacity(style: CSSStyleDeclaration, authored: string): void {
if (authored === "") style.removeProperty("opacity");
else style.setProperty("opacity", authored);
}