Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
kImageFitModeContainValue,
kImageFitModeCoverValue,
} from "./canvasElementUtils";
import { getPersistedCanvasColor } from "./canvasColorUtils";
import { deselectVideoContainers } from "../../js/videoUtils";
import { CanvasElementKeyHints } from "./CanvasElementKeyHints";
import { ToolBox } from "../toolbox";
Expand Down Expand Up @@ -542,7 +543,7 @@ const CanvasToolControls: React.FunctionComponent = () => {

// We come into this from chooser change
const updateTextColor = (newColor: IColorInfo) => {
const color = newColor.colors[0]; // text color is always monochrome
const color = getPersistedCanvasColor(newColor);
const canvasElementManager = getCanvasElementManager();
if (canvasElementManager) {
// Update the toolbox controls
Expand All @@ -565,7 +566,7 @@ const CanvasToolControls: React.FunctionComponent = () => {

// We come into this from chooser change
const updateTextOutlineColor = (newColor: IColorInfo) => {
const color = newColor.colors[0];
const color = getPersistedCanvasColor(newColor);
const canvasElementManager = getCanvasElementManager();
if (canvasElementManager) {
setTextOutlineColorIsDefault(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, test } from "vitest";

import { getPersistedCanvasColor } from "./canvasColorUtils";

describe("getPersistedCanvasColor", () => {
test("keeps opaque colors unchanged", () => {
expect(
getPersistedCanvasColor({
colors: ["#123456"],
opacity: 1,
}),
).toBe("#123456");
});

test("converts partial opacity to rgba for persistence", () => {
expect(
getPersistedCanvasColor({
colors: ["#123456"],
opacity: 0.25,
}),
).toBe("rgba(18, 52, 86, 0.25)");
});
});
11 changes: 11 additions & 0 deletions src/BloomBrowserUI/bookEdit/toolbox/canvas/canvasColorUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IColorInfo } from "../../../react_components/color-picking/colorSwatch";
import { getRgbaColorStringFromColorAndOpacity } from "../../../utils/colorUtils";

export function getPersistedCanvasColor(colorInfo: IColorInfo): string {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Exported function getPersistedCanvasColor missing required comment per AGENTS.md

The repository's AGENTS.md mandates: "All public methods should have a comment. So should most private ones!" The new exported function getPersistedCanvasColor in canvasColorUtils.ts has no comment explaining its purpose or behavior.

Suggested change
export function getPersistedCanvasColor(colorInfo: IColorInfo): string {
// Returns a color string suitable for persistence. For opaque colors, returns the hex
// color directly. For partially transparent colors, bakes the opacity into an rgba() string.
export function getPersistedCanvasColor(colorInfo: IColorInfo): string {
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

const firstColor = colorInfo.colors[0];
if (colorInfo.opacity >= 1) {
return firstColor;
}

return getRgbaColorStringFromColorAndOpacity(firstColor, colorInfo.opacity);
}