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
2 changes: 2 additions & 0 deletions packages/core/src/runtime/drawnBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const SIZE_PROPERTIES = [
"max-height",
] as const;

export const DRAFT_DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES] as const;

export const PROBE_PX = 100;
export const MIN_PROBE_RESPONSE = 0.01;
type Point = { x: number; y: number };
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/runtime/editingDraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import type { EditingDraftEnd, EditingDraftReply } from "./editingDraftEnd";
import type { EditingDraft, EditingDraftProps, EditingDraftRotate } from "./editingPort";
import { revealClip } from "./clipReveal";
import { clearDragChrome, drawDragChrome, type EditingDragChrome } from "./editing/dragChrome";
import { computedTranslateAxes, movedTranslate, SIZE_PROPERTIES, writeDrawnSize } from "./drawnBox";
import {
computedTranslateAxes,
DRAFT_DRAWN,
movedTranslate,
SIZE_PROPERTIES,
writeDrawnSize,
} from "./drawnBox";
import type { RuntimeTimelineLike } from "./types";

const DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES] as const;

interface Before {
draft: number;
inline: Array<[name: string, value: string, priority: string]>;
Expand Down Expand Up @@ -55,7 +59,7 @@ function beforeOf(element: Styled): Before {
const { style } = element;
saved = {
draft: ++lastDraft,
inline: DRAWN.map((name) => [
inline: DRAFT_DRAWN.map((name) => [
name,
style.getPropertyValue(name),
style.getPropertyPriority(name),
Expand Down Expand Up @@ -159,7 +163,7 @@ function drawProps(element: Styled, values: EditingDraftProps["values"]): void {
}

function clearProps(element: Styled, saved: Before): void {
restore(element, DRAWN);
restore(element, DRAFT_DRAWN);
saved.putMarkBack?.();
if (saved.propsSet?.length) frameGsap()?.set?.(element, { clearProps: saved.propsSet.join(",") });
const timeline = rootTimeline();
Expand All @@ -186,7 +190,7 @@ function end(element: Styled, ending: EditingDraftEnd): boolean {
liveDrafts.delete(element);
if (ending.end === "clear") clearProps(element, saved);
if (ending.end === "restore") {
restore(element, DRAWN);
restore(element, DRAFT_DRAWN);
restoreGsapPosition(element);
restoreGsapRotation(element);
}
Expand Down
26 changes: 25 additions & 1 deletion packages/studio/src/hooks/geometryCommits.sealed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
previewDraftsSent,
previewStandIn,
} from "../components/editor/previewDrafts";
import { captureStudioBoxSize, restoreStudioBoxSize } from "../components/editor/manualEdits";
import {
applyStudioBoxSizeDraft,
captureStudioBoxSize,
restoreStudioBoxSize,
} from "../components/editor/manualEdits";
import {
STUDIO_ORIGINAL_BOX_HEIGHT_ATTR,
STUDIO_ORIGINAL_BOX_WIDTH_ATTR,
Expand Down Expand Up @@ -251,6 +255,26 @@ it("rescales the crop with a sealed resize, the same as an open element", async
);
});

// fails without the fix: with the resize's draft still live, the commit drew nothing on the frame, so the frame kept
// the old crop on the new box until a reload.
it("draws the rescaled crop on the frame while the resize's draft is still live", async () => {
const { card, selection, commits } = await sealedCard(saved());
card.style.setProperty("clip-path", "inset(10px 20px 10px 20px)");
selection.element.style.setProperty("clip-path", "inset(10px 20px 10px 20px)");
const pressed = { width: 100, height: 50 };
const next = { width: 200, height: 100 };
drawPreviewDraft(selection.element, {
size: applyStudioBoxSizeDraft(selection.element, next, pressed),
});
await settle();

await commits.handleDomBoxSizeCommit(selection, next);
await settle();

expect(card.style.getPropertyValue("clip-path")).toBe("inset(20px 40px 20px 40px)");
expect([card.style.width, card.style.height]).toEqual(["200px", "100px"]);
});

it("rescales the crop with a size typed on an animated element, from the box the frame lays out", async () => {
const { card, selection } = await sealedCard(saved());
card.style.setProperty("clip-path", "inset(10px 20px 10px 20px)");
Expand Down
13 changes: 10 additions & 3 deletions packages/studio/src/hooks/useDomEditPositionPatchCommit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, type RefObject } from "react";
import { DRAFT_DRAWN } from "@hyperframes/core/drawn-box";
import type { DomEditSelection } from "../components/editor/domEditing";
import { previewDraftLive } from "../components/editor/previewDrafts";
import {
Expand Down Expand Up @@ -27,14 +28,20 @@ type PositionPatchOptions = {
deferRender?: boolean;
};

/** A sealed frame shows the patch's own styles and attributes, unless a gesture's draft already does. */
/** A sealed frame shows the patch's own styles and attributes, but for those a gesture's live draft draws. */
function drawOnSealedFrame(
iframe: HTMLIFrameElement | null,
selection: DomEditSelection,
patches: PatchOperation[],
) {
if (previewDraftLive(selection.element)) return null;
const own = patches.filter((p) => p.childSelector === undefined && p.childIndex === undefined);
const drafted: readonly string[] = previewDraftLive(selection.element) ? DRAFT_DRAWN : [];
const own = patches.filter(
(p) =>
p.childSelector === undefined &&
p.childIndex === undefined &&
!(p.type === "inline-style" && drafted.includes(p.property)),
);
if (drafted.length && own.length === 0) return null;
const entries = (type: PatchOperation["type"]) =>
own.filter((p) => p.type === type).map((p): [string, string | null] => [p.property, p.value]);
const styles = entries("inline-style");
Expand Down
7 changes: 5 additions & 2 deletions packages/studio/tests/e2e/edit-accuracy/case.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ export async function inStudio(
}
}

/** The saved crop's distance, in px, from the authored one scaled with the box: a crop follows a resize. Studio
/** A crop's distance, in px, from the authored one scaled with the box: a crop follows a resize. Studio
* shows a selected element uncropped, so the crop before the gesture is the fixture's. */
function cropDrift(authored, pre, now) {
const first = parseInset(authored);
Expand Down Expand Up @@ -1254,7 +1254,10 @@ async function measureCase(
spec.gesture,
(frames[0] ?? []).map((f) => (spec.crop ? { ...f, clip: undefined } : f)),
),
...(spec.crop && { crop: cropDrift(spec.crop, pre, reloaded) }),
// The crop shown right after the save too, not only once a reload redraws it.
...(spec.crop && {
crop: Math.max(cropDrift(spec.crop, pre, committed), cropDrift(spec.crop, pre, reloaded)),
}),
drop: quadDistance(drive.lastQuad, committed.visible),
// Also against the box the gesture left, so a write the file drops shows here and not only as drop.
reload: Math.max(
Expand Down
Loading