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
11 changes: 7 additions & 4 deletions packages/studio/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3306,8 +3306,8 @@ export function StudioApp() {
attachErrorCapture();
syncPreviewHistoryHotkey(previewIframe);
void (async () => {
await applyStudioManualEditsToPreviewRef.current(previewIframe);
await applyStudioMotionToPreviewRef.current(previewIframe);
await applyStudioManualEditsToPreviewRef.current(previewIframe, { readFromDiskFirst: true });
await applyStudioMotionToPreviewRef.current(previewIframe, { readFromDiskFirst: true });
})();
syncSelectionFromDocument();
refreshPreviewDocumentVersion();
Expand All @@ -3318,8 +3318,10 @@ export function StudioApp() {
attachErrorCapture();
syncPreviewHistoryHotkey(previewIframe);
void (async () => {
await applyStudioManualEditsToPreviewRef.current(previewIframe);
await applyStudioMotionToPreviewRef.current(previewIframe);
await applyStudioManualEditsToPreviewRef.current(previewIframe, {
readFromDiskFirst: true,
});
await applyStudioMotionToPreviewRef.current(previewIframe, { readFromDiskFirst: true });
})();
syncSelectionFromDocument();
refreshPreviewDocumentVersion();
Expand Down Expand Up @@ -4188,6 +4190,7 @@ export function StudioApp() {
onSetStyle={handleDomStyleCommit}
onSetManualOffset={handleDomPathOffsetCommit}
onSetManualSize={handleDomBoxSizeCommit}
onSetManualRotation={handleDomRotationCommit}
onSetText={handleDomTextCommit}
onSetTextFieldStyle={handleDomTextFieldStyleCommit}
onAddTextField={handleDomAddTextField}
Expand Down
16 changes: 15 additions & 1 deletion packages/studio/src/components/editor/PropertyPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
type GradientModel,
} from "./gradientValue";
import { isTextEditableSelection, type DomEditSelection } from "./domEditing";
import { readStudioBoxSize, readStudioPathOffset } from "./manualEdits";
import { readStudioBoxSize, readStudioPathOffset, readStudioRotation } from "./manualEdits";
import {
COMMON_LOCAL_FONT_FAMILIES,
googleFontStylesheetUrl,
Expand All @@ -59,6 +59,7 @@ interface PropertyPanelProps {
onSetStyle: (prop: string, value: string) => void | Promise<void>;
onSetManualOffset: (element: DomEditSelection, next: { x: number; y: number }) => void;
onSetManualSize: (element: DomEditSelection, next: { width: number; height: number }) => void;
onSetManualRotation: (element: DomEditSelection, next: { angle: number }) => void;
onSetText: (value: string, fieldKey?: string) => void;
onSetTextFieldStyle: (fieldKey: string, property: string, value: string) => void;
onAddTextField: (afterFieldKey?: string) => string | Promise<string | null> | null;
Expand Down Expand Up @@ -2279,6 +2280,7 @@ export const PropertyPanel = memo(function PropertyPanel({
onSetStyle,
onSetManualOffset,
onSetManualSize,
onSetManualRotation,
onSetText,
onSetTextFieldStyle,
onAddTextField,
Expand Down Expand Up @@ -2416,6 +2418,13 @@ export const PropertyPanel = memo(function PropertyPanel({
});
};

const manualRotation = readStudioRotation(element.element);
const commitManualRotation = (nextValue: string) => {
const parsed = Number.parseFloat(nextValue);
if (!Number.isFinite(parsed)) return;
onSetManualRotation(element, { angle: parsed });
};

const handleFillModeChange = (nextMode: string) => {
setPreferredFillMode(nextMode);
if (nextMode === "Solid") {
Expand Down Expand Up @@ -2719,6 +2728,11 @@ export const PropertyPanel = memo(function PropertyPanel({
scrub
onCommit={(next) => commitManualSize("height", next)}
/>
<MetricField
label="R"
value={`${manualRotation.angle}°`}
onCommit={(next) => commitManualRotation(next.replace("°", ""))}
/>
</div>
</Section>

Expand Down
32 changes: 32 additions & 0 deletions packages/studio/src/components/editor/manualEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,33 @@ function styleMatchesStudioRotationDraft(element: HTMLElement, value: string): b
);
}

const STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR = "data-hf-studio-original-transform-display";

function promoteInlineForTransform(element: HTMLElement): void {
const computedDisplay = safeComputedStyleProperty(element, "display");
if (computedDisplay !== "inline") return;
if (!element.hasAttribute(STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR)) {
element.setAttribute(
STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR,
element.style.getPropertyValue("display"),
);
}
element.style.setProperty("display", "inline-block");
}

function restoreInlineDisplay(element: HTMLElement): void {
const original = element.getAttribute(STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR);
if (original == null) return;
if (original === "") element.style.removeProperty("display");
else element.style.setProperty("display", original);
element.removeAttribute(STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR);
}

export function applyStudioPathOffset(
element: HTMLElement,
offset: { x: number; y: number },
): void {
promoteInlineForTransform(element);
writeStudioPathOffsetVars(element, offset);
element.style.setProperty(
"translate",
Expand All @@ -672,6 +695,7 @@ export function applyStudioPathOffsetDraft(
element: HTMLElement,
offset: { x: number; y: number },
): void {
promoteInlineForTransform(element);
writeStudioPathOffsetVars(element, offset, { updateBase: false });
element.style.setProperty(
"translate",
Expand All @@ -683,17 +707,20 @@ export function applyStudioBoxSize(
element: HTMLElement,
size: { width: number; height: number },
): void {
promoteInlineForTransform(element);
applyStudioBoxSizeDimensions(element, size);
}

export function applyStudioBoxSizeDraft(
element: HTMLElement,
size: { width: number; height: number },
): void {
promoteInlineForTransform(element);
applyStudioBoxSizeDimensions(element, size);
}

export function applyStudioRotation(element: HTMLElement, rotation: { angle: number }): void {
promoteInlineForTransform(element);
writeStudioRotationVars(element, rotation);
element.removeAttribute(STUDIO_ROTATION_DRAFT_ATTR);
element.style.setProperty(
Expand All @@ -703,6 +730,7 @@ export function applyStudioRotation(element: HTMLElement, rotation: { angle: num
}

export function applyStudioRotationDraft(element: HTMLElement, rotation: { angle: number }): void {
promoteInlineForTransform(element);
writeStudioRotationVars(element, rotation, { updateBase: false });
element.setAttribute(STUDIO_ROTATION_DRAFT_ATTR, "true");
element.style.setProperty(
Expand All @@ -718,6 +746,7 @@ function clearStudioPathOffset(element: HTMLElement): void {
) {
restoreOriginalTranslateProperty(element);
}
restoreInlineDisplay(element);
element.style.removeProperty(STUDIO_OFFSET_X_PROP);
element.style.removeProperty(STUDIO_OFFSET_Y_PROP);
element.removeAttribute(STUDIO_PATH_OFFSET_ATTR);
Expand All @@ -732,6 +761,7 @@ function clearStudioRotation(element: HTMLElement): void {
) {
restoreOriginalRotationProperty(element);
}
restoreInlineDisplay(element);

element.style.removeProperty(STUDIO_ROTATION_PROP);
element.removeAttribute(STUDIO_ROTATION_ATTR);
Expand Down Expand Up @@ -816,6 +846,7 @@ function clearStudioBoxSize(element: HTMLElement): void {
restoreOriginalBoxSizeProperty(element, "display", STUDIO_ORIGINAL_DISPLAY_ATTR);
}

restoreInlineDisplay(element);
element.style.removeProperty(STUDIO_WIDTH_PROP);
element.style.removeProperty(STUDIO_HEIGHT_PROP);
element.removeAttribute(STUDIO_BOX_SIZE_ATTR);
Expand Down Expand Up @@ -1346,6 +1377,7 @@ function collectStudioManualEditElements(doc: Document): HTMLElement[] {
element.hasAttribute(STUDIO_ROTATION_DRAFT_ATTR) ||
element.hasAttribute(STUDIO_ORIGINAL_TRANSLATE_ATTR) ||
element.hasAttribute(STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR) ||
element.hasAttribute(STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR) ||
element.hasAttribute(STUDIO_ORIGINAL_MIN_WIDTH_ATTR) ||
element.hasAttribute(STUDIO_ORIGINAL_FLEX_BASIS_ATTR) ||
element.hasAttribute(STUDIO_ORIGINAL_SCALE_ATTR) ||
Expand Down
Loading